diff --git a/CHANGELOG.md b/CHANGELOG.md index a6d49e6ec..3b4207399 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - GAP: support reading RSSI for Classic+LE using gap_read_rssi. Emits GAP_EVENT_RSSI_MEASUREMENT - GAP: support setting Link Supervision Timetout for outgoing Classic connections using gap_set_link_supervision_timeout - Linked List: return if item was added for `btstack_linked_list_add[_tail]` +- ATT Server: return error if request to send now for Notification or Indication already registered ## Changed - Bluetooth and BTstack Error Codes and Events: collect status codes in bluetooth.h and events in btstack_defines.h diff --git a/src/ble/att_server.c b/src/ble/att_server.c index 62b480c01..03d288443 100644 --- a/src/ble/att_server.c +++ b/src/ble/att_server.c @@ -1139,17 +1139,25 @@ void att_server_request_can_send_now_event(hci_con_handle_t con_handle){ int att_server_request_to_send_notification(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle){ att_server_t * att_server = att_server_for_handle(con_handle); if (!att_server) return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER; - btstack_linked_list_add_tail(&att_server->notification_requests, (btstack_linked_item_t*) callback_registration); + bool added = btstack_linked_list_add_tail(&att_server->notification_requests, (btstack_linked_item_t*) callback_registration); att_server_request_can_send_now(att_server); - return ERROR_CODE_SUCCESS; + if (added){ + return ERROR_CODE_SUCCESS; + } else { + return ERROR_CODE_COMMAND_DISALLOWED; + } } int att_server_request_to_send_indication(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle){ att_server_t * att_server = att_server_for_handle(con_handle); if (!att_server) return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER; - btstack_linked_list_add_tail(&att_server->indication_requests, (btstack_linked_item_t*) callback_registration); + bool added = btstack_linked_list_add_tail(&att_server->indication_requests, (btstack_linked_item_t*) callback_registration); att_server_request_can_send_now(att_server); - return ERROR_CODE_SUCCESS; + if (added){ + return ERROR_CODE_SUCCESS; + } else { + return ERROR_CODE_COMMAND_DISALLOWED; + } } int att_server_notify(hci_con_handle_t con_handle, uint16_t attribute_handle, const uint8_t *value, uint16_t value_len){ diff --git a/src/ble/att_server.h b/src/ble/att_server.h index c7b6daa4f..beb8b68ef 100644 --- a/src/ble/att_server.h +++ b/src/ble/att_server.h @@ -91,7 +91,7 @@ uint16_t att_server_get_mtu(hci_con_handle_t con_handle); * @note callback might happend during call to this function * @param callback_registration to point to callback function and context information * @param con_handle - * @return 0 if ok, error otherwise + * @return ERROR_CODE_SUCCESS if ok, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if handle unknown, and ERROR_CODE_COMMAND_DISALLOWED if callback already registered */ int att_server_request_to_send_notification(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle); @@ -100,7 +100,7 @@ int att_server_request_to_send_notification(btstack_context_callback_registratio * @note callback might happend during call to this function * @param callback_registration to point to callback function and context information * @param con_handle - * @return 0 if ok, error otherwise + * @return ERROR_CODE_SUCCESS if ok, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if handle unknown, and ERROR_CODE_COMMAND_DISALLOWED if callback already registered */ int att_server_request_to_send_indication(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle);