From e12e7698b226c0547725c0282ccd843ebd0a6d17 Mon Sep 17 00:00:00 2001 From: Arman Uguray Date: Mon, 13 Oct 2014 14:09:59 -0700 Subject: [PATCH] shared/att: Fix not responding to some requests With this patch bt_att automatically responds with ERROR_REQUEST_NOT_SUPPORTED to an incoming request for which no handler has been registered via bt_att_register. --- src/shared/att.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/shared/att.c b/src/shared/att.c index 63cd19ba0..503e06ced 100644 --- a/src/shared/att.c +++ b/src/shared/att.c @@ -562,6 +562,7 @@ struct notify_data { uint8_t opcode; uint8_t *pdu; ssize_t pdu_len; + bool handler_found; }; static void notify_handler(void *data, void *user_data) @@ -575,11 +576,26 @@ static void notify_handler(void *data, void *user_data) if (notify->opcode != not_data->opcode) return; + not_data->handler_found = true; + if (notify->callback) notify->callback(not_data->opcode, not_data->pdu, not_data->pdu_len, notify->user_data); } +static void respond_not_supported(struct bt_att *att, uint8_t opcode) +{ + uint8_t pdu[4]; + + pdu[0] = opcode; + pdu[1] = 0; + pdu[2] = 0; + pdu[3] = BT_ATT_ERROR_REQUEST_NOT_SUPPORTED; + + bt_att_send(att, BT_ATT_OP_ERROR_RSP, pdu, sizeof(pdu), NULL, NULL, + NULL); +} + static void handle_notify(struct bt_att *att, uint8_t opcode, uint8_t *pdu, ssize_t pdu_len) { @@ -607,6 +623,13 @@ static void handle_notify(struct bt_att *att, uint8_t opcode, uint8_t *pdu, } bt_att_unref(att); + + /* + * If this was a request and no handler was registered for it, respond + * with "Not Supported" + */ + if (!data.handler_found && get_op_type(opcode) == ATT_OP_TYPE_REQ) + respond_not_supported(att, opcode); } static void disconn_handler(void *data, void *user_data) -- 2.47.3