gatt_client: emit query complete event for gatt_client_discover_characteristic_descriptors in next run loop iteration

This commit is contained in:
Matthias Ringwald 2023-10-25 15:01:37 +02:00
parent 4c7c987f92
commit 544a5845c2
3 changed files with 28 additions and 8 deletions

View File

@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Changed
- HCI: simplified implicit SCO flow control
- AVRCP: shorten default SDP Service and Provider Names
- GATT Client: emit query complete event for gatt_client_discover_characteristic_descriptors in next run loop iteration
- HFP: report 1.9 in SDP record
- btstack_crypto: allow MBEDTLS config via MBEDTLS_CONFIG_FILE
- remove old Zephyr 1.9 port

View File

@ -68,6 +68,7 @@ static btstack_linked_list_t gatt_client_connections;
static btstack_linked_list_t gatt_client_value_listeners;
static btstack_packet_callback_registration_t hci_event_callback_registration;
static btstack_packet_callback_registration_t sm_event_callback_registration;
static btstack_context_callback_registration_t gatt_client_deferred_event_emit;
// GATT Client Configuration
static bool gatt_client_mtu_exchange_enabled;
@ -1454,6 +1455,19 @@ static void gatt_client_run(void){
}
}
// emit complete event, used to avoid emitting event from API call
static void gatt_client_emit_events(void * context){
UNUSED(context);
btstack_linked_item_t *it;
for (it = (btstack_linked_item_t *) gatt_client_connections; it != NULL; it = it->next) {
gatt_client_t *gatt_client = (gatt_client_t *) it;
if (gatt_client->state == P_W2_EMIT_QUERY_COMPLETE_EVENT){
gatt_client->state = P_READY;
emit_gatt_complete_event(gatt_client, ATT_ERROR_SUCCESS);
}
}
}
static void gatt_client_report_error_if_pending(gatt_client_t *gatt_client, uint8_t att_error_code) {
if (is_ready(gatt_client)) return;
gatt_client_handle_transaction_complete(gatt_client, att_error_code);
@ -2384,15 +2398,19 @@ uint8_t gatt_client_discover_characteristic_descriptors(btstack_packet_handler_t
return status;
}
if (characteristic->value_handle == characteristic->end_handle){
emit_gatt_complete_event(gatt_client, ATT_ERROR_SUCCESS);
return ERROR_CODE_SUCCESS;
// check if there is space for characteristics descriptors
if (characteristic->end_handle > characteristic->value_handle){
gatt_client->callback = callback;
gatt_client->start_group_handle = characteristic->value_handle + 1u;
gatt_client->end_group_handle = characteristic->end_handle;
gatt_client->state = P_W2_SEND_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY;
gatt_client_run();
} else {
// schedule gatt complete event on next run loop iteration otherwise
gatt_client->state = P_W2_EMIT_QUERY_COMPLETE_EVENT;
gatt_client_deferred_event_emit.callback = gatt_client_emit_events;
btstack_run_loop_execute_on_main_thread(&gatt_client_deferred_event_emit);
}
gatt_client->callback = callback;
gatt_client->start_group_handle = characteristic->value_handle + 1u;
gatt_client->end_group_handle = characteristic->end_handle;
gatt_client->state = P_W2_SEND_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY;
gatt_client_run();
return ERROR_CODE_SUCCESS;
}

View File

@ -53,6 +53,7 @@ extern "C" {
typedef enum {
P_READY,
P_W2_EMIT_QUERY_COMPLETE_EVENT,
P_W2_SEND_SERVICE_QUERY,
P_W4_SERVICE_QUERY_RESULT,
P_W2_SEND_SERVICE_WITH_UUID_QUERY,