gat_client: rename status to att_status in GATT_EVENT_QUERY_COMPLETE event, add and use ATT_ERROR_SUCCESS instead of 0 status code

This commit is contained in:
Milanka Ringwald 2019-09-25 09:21:08 +02:00
parent 3f78d90e4e
commit 9cb80b17e9
8 changed files with 31 additions and 30 deletions

View File

@ -184,7 +184,7 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
case TC_W4_ENABLE_NOTIFICATIONS_COMPLETE: case TC_W4_ENABLE_NOTIFICATIONS_COMPLETE:
switch(hci_event_packet_get_type(packet)){ switch(hci_event_packet_get_type(packet)){
case GATT_EVENT_QUERY_COMPLETE: case GATT_EVENT_QUERY_COMPLETE:
printf("Notifications enabled, status %02x\n", gatt_event_query_complete_get_status(packet)); printf("Notifications enabled, ATT status %02x\n", gatt_event_query_complete_get_att_status(packet));
state = TC_W4_SENSOR_LOCATION_CHARACTERISTIC; state = TC_W4_SENSOR_LOCATION_CHARACTERISTIC;
printf("Search for Sensor Location characteristic.\n"); printf("Search for Sensor Location characteristic.\n");

View File

@ -292,8 +292,8 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
case TC_W4_ENABLE_NOTIFICATIONS_COMPLETE: case TC_W4_ENABLE_NOTIFICATIONS_COMPLETE:
switch(hci_event_packet_get_type(packet)){ switch(hci_event_packet_get_type(packet)){
case GATT_EVENT_QUERY_COMPLETE: case GATT_EVENT_QUERY_COMPLETE:
printf("Notifications enabled, status %02x\n", gatt_event_query_complete_get_status(packet)); printf("Notifications enabled, ATT status %02x\n", gatt_event_query_complete_get_att_status(packet));
if ( gatt_event_query_complete_get_status(packet)) break; if (gatt_event_query_complete_get_att_status(packet) != ATT_ERROR_SUCCESS) break;
state = TC_W4_TEST_DATA; state = TC_W4_TEST_DATA;
#if (TEST_MODE & TEST_MODE_WRITE_WITHOUT_RESPONSE) #if (TEST_MODE & TEST_MODE_WRITE_WITHOUT_RESPONSE)
printf("Start streaming - request can send now.\n"); printf("Start streaming - request can send now.\n");

View File

@ -758,7 +758,7 @@ static int is_query_done(gatt_client_t * peripheral, uint16_t last_result_handle
static void trigger_next_query(gatt_client_t * peripheral, uint16_t last_result_handle, gatt_client_state_t next_query_state){ static void trigger_next_query(gatt_client_t * peripheral, uint16_t last_result_handle, gatt_client_state_t next_query_state){
if (is_query_done(peripheral, last_result_handle)){ if (is_query_done(peripheral, last_result_handle)){
gatt_client_handle_transaction_complete(peripheral); gatt_client_handle_transaction_complete(peripheral);
emit_gatt_complete_event(peripheral, 0); emit_gatt_complete_event(peripheral, ATT_ERROR_SUCCESS);
return; return;
} }
// next // next
@ -810,7 +810,7 @@ static void trigger_next_blob_query(gatt_client_t * peripheral, gatt_client_stat
uint16_t max_blob_length = peripheral_mtu(peripheral) - 1; uint16_t max_blob_length = peripheral_mtu(peripheral) - 1;
if (received_blob_length < max_blob_length){ if (received_blob_length < max_blob_length){
gatt_client_handle_transaction_complete(peripheral); gatt_client_handle_transaction_complete(peripheral);
emit_gatt_complete_event(peripheral, 0); emit_gatt_complete_event(peripheral, ATT_ERROR_SUCCESS);
return; return;
} }
@ -1042,7 +1042,7 @@ static int gatt_client_run_for_peripheral( gatt_client_t * peripheral){
send_gatt_signed_write_request(peripheral, sign_counter); send_gatt_signed_write_request(peripheral, sign_counter);
// finally, notifiy client that write is complete // finally, notifiy client that write is complete
gatt_client_handle_transaction_complete(peripheral); gatt_client_handle_transaction_complete(peripheral);
emit_gatt_complete_event(peripheral, 0); emit_gatt_complete_event(peripheral, ATT_ERROR_SUCCESS);
return 1; return 1;
} }
#endif #endif
@ -1284,13 +1284,13 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle,
case P_W4_READ_CHARACTERISTIC_VALUE_RESULT: case P_W4_READ_CHARACTERISTIC_VALUE_RESULT:
gatt_client_handle_transaction_complete(peripheral); gatt_client_handle_transaction_complete(peripheral);
report_gatt_characteristic_value(peripheral, peripheral->attribute_handle, &packet[1], size-1); report_gatt_characteristic_value(peripheral, peripheral->attribute_handle, &packet[1], size-1);
emit_gatt_complete_event(peripheral, 0); emit_gatt_complete_event(peripheral, ATT_ERROR_SUCCESS);
break; break;
case P_W4_READ_CHARACTERISTIC_DESCRIPTOR_RESULT:{ case P_W4_READ_CHARACTERISTIC_DESCRIPTOR_RESULT:{
gatt_client_handle_transaction_complete(peripheral); gatt_client_handle_transaction_complete(peripheral);
report_gatt_characteristic_descriptor(peripheral, peripheral->attribute_handle, &packet[1], size-1, 0); report_gatt_characteristic_descriptor(peripheral, peripheral->attribute_handle, &packet[1], size-1, 0);
emit_gatt_complete_event(peripheral, 0); emit_gatt_complete_event(peripheral, ATT_ERROR_SUCCESS);
break; break;
} }
default: default:
@ -1358,15 +1358,15 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle,
switch (peripheral->gatt_client_state){ switch (peripheral->gatt_client_state){
case P_W4_WRITE_CHARACTERISTIC_VALUE_RESULT: case P_W4_WRITE_CHARACTERISTIC_VALUE_RESULT:
gatt_client_handle_transaction_complete(peripheral); gatt_client_handle_transaction_complete(peripheral);
emit_gatt_complete_event(peripheral, 0); emit_gatt_complete_event(peripheral, ATT_ERROR_SUCCESS);
break; break;
case P_W4_CLIENT_CHARACTERISTIC_CONFIGURATION_RESULT: case P_W4_CLIENT_CHARACTERISTIC_CONFIGURATION_RESULT:
gatt_client_handle_transaction_complete(peripheral); gatt_client_handle_transaction_complete(peripheral);
emit_gatt_complete_event(peripheral, 0); emit_gatt_complete_event(peripheral, ATT_ERROR_SUCCESS);
break; break;
case P_W4_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT: case P_W4_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT:
gatt_client_handle_transaction_complete(peripheral); gatt_client_handle_transaction_complete(peripheral);
emit_gatt_complete_event(peripheral, 0); emit_gatt_complete_event(peripheral, ATT_ERROR_SUCCESS);
break; break;
default: default:
break; break;
@ -1398,7 +1398,7 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle,
case P_W4_PREPARE_WRITE_SINGLE_RESULT: case P_W4_PREPARE_WRITE_SINGLE_RESULT:
gatt_client_handle_transaction_complete(peripheral); gatt_client_handle_transaction_complete(peripheral);
if (is_value_valid(peripheral, packet, size)){ if (is_value_valid(peripheral, packet, size)){
emit_gatt_complete_event(peripheral, 0); emit_gatt_complete_event(peripheral, ATT_ERROR_SUCCESS);
} else { } else {
emit_gatt_complete_event(peripheral, ATT_ERROR_DATA_MISMATCH); emit_gatt_complete_event(peripheral, ATT_ERROR_DATA_MISMATCH);
} }
@ -1435,11 +1435,11 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle,
switch (peripheral->gatt_client_state){ switch (peripheral->gatt_client_state){
case P_W4_EXECUTE_PREPARED_WRITE_RESULT: case P_W4_EXECUTE_PREPARED_WRITE_RESULT:
gatt_client_handle_transaction_complete(peripheral); gatt_client_handle_transaction_complete(peripheral);
emit_gatt_complete_event(peripheral, 0); emit_gatt_complete_event(peripheral, ATT_ERROR_SUCCESS);
break; break;
case P_W4_CANCEL_PREPARED_WRITE_RESULT: case P_W4_CANCEL_PREPARED_WRITE_RESULT:
gatt_client_handle_transaction_complete(peripheral); gatt_client_handle_transaction_complete(peripheral);
emit_gatt_complete_event(peripheral, 0); emit_gatt_complete_event(peripheral, ATT_ERROR_SUCCESS);
break; break;
case P_W4_CANCEL_PREPARED_WRITE_DATA_MISMATCH_RESULT: case P_W4_CANCEL_PREPARED_WRITE_DATA_MISMATCH_RESULT:
gatt_client_handle_transaction_complete(peripheral); gatt_client_handle_transaction_complete(peripheral);
@ -1447,7 +1447,7 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle,
break; break;
case P_W4_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT: case P_W4_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT:
gatt_client_handle_transaction_complete(peripheral); gatt_client_handle_transaction_complete(peripheral);
emit_gatt_complete_event(peripheral, 0); emit_gatt_complete_event(peripheral, ATT_ERROR_SUCCESS);
break; break;
default: default:
break; break;
@ -1460,7 +1460,7 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle,
case P_W4_READ_MULTIPLE_RESPONSE: case P_W4_READ_MULTIPLE_RESPONSE:
report_gatt_characteristic_value(peripheral, 0, &packet[1], size-1); report_gatt_characteristic_value(peripheral, 0, &packet[1], size-1);
gatt_client_handle_transaction_complete(peripheral); gatt_client_handle_transaction_complete(peripheral);
emit_gatt_complete_event(peripheral, 0); emit_gatt_complete_event(peripheral, ATT_ERROR_SUCCESS);
break; break;
default: default:
break; break;
@ -1477,20 +1477,20 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle,
case P_W4_INCLUDED_SERVICE_QUERY_RESULT: case P_W4_INCLUDED_SERVICE_QUERY_RESULT:
case P_W4_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT: case P_W4_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT:
gatt_client_handle_transaction_complete(peripheral); gatt_client_handle_transaction_complete(peripheral);
emit_gatt_complete_event(peripheral, 0); emit_gatt_complete_event(peripheral, ATT_ERROR_SUCCESS);
break; break;
case P_W4_ALL_CHARACTERISTICS_OF_SERVICE_QUERY_RESULT: case P_W4_ALL_CHARACTERISTICS_OF_SERVICE_QUERY_RESULT:
case P_W4_CHARACTERISTIC_WITH_UUID_QUERY_RESULT: case P_W4_CHARACTERISTIC_WITH_UUID_QUERY_RESULT:
characteristic_end_found(peripheral, peripheral->end_group_handle); characteristic_end_found(peripheral, peripheral->end_group_handle);
gatt_client_handle_transaction_complete(peripheral); gatt_client_handle_transaction_complete(peripheral);
emit_gatt_complete_event(peripheral, 0); emit_gatt_complete_event(peripheral, ATT_ERROR_SUCCESS);
break; break;
case P_W4_READ_BY_TYPE_RESPONSE: case P_W4_READ_BY_TYPE_RESPONSE:
gatt_client_handle_transaction_complete(peripheral); gatt_client_handle_transaction_complete(peripheral);
if (peripheral->start_group_handle == peripheral->query_start_handle){ if (peripheral->start_group_handle == peripheral->query_start_handle){
emit_gatt_complete_event(peripheral, ATT_ERROR_ATTRIBUTE_NOT_FOUND); emit_gatt_complete_event(peripheral, ATT_ERROR_ATTRIBUTE_NOT_FOUND);
} else { } else {
emit_gatt_complete_event(peripheral, 0); emit_gatt_complete_event(peripheral, ATT_ERROR_SUCCESS);
} }
break; break;
default: default:
@ -1773,7 +1773,7 @@ uint8_t gatt_client_discover_characteristic_descriptors(btstack_packet_handler_t
if (!is_ready(peripheral)) return GATT_CLIENT_IN_WRONG_STATE; if (!is_ready(peripheral)) return GATT_CLIENT_IN_WRONG_STATE;
if (characteristic->value_handle == characteristic->end_handle){ if (characteristic->value_handle == characteristic->end_handle){
emit_gatt_complete_event(peripheral, 0); emit_gatt_complete_event(peripheral, ATT_ERROR_SUCCESS);
return 0; return 0;
} }
peripheral->callback = callback; peripheral->callback = callback;
@ -1967,7 +1967,7 @@ uint8_t gatt_client_write_client_characteristic_configuration(btstack_packet_han
peripheral->gatt_client_state = P_W2_SEND_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY; peripheral->gatt_client_state = P_W2_SEND_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY;
#endif #endif
gatt_client_run(); gatt_client_run();
return 0; return ERROR_CODE_SUCCESS;
} }
uint8_t gatt_client_read_characteristic_descriptor_using_descriptor_handle(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t descriptor_handle){ uint8_t gatt_client_read_characteristic_descriptor_using_descriptor_handle(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t descriptor_handle){

View File

@ -725,6 +725,7 @@ typedef enum {
#define ATT_SIGNED_WRITE_COMMAND 0xD2 #define ATT_SIGNED_WRITE_COMMAND 0xD2
// MARK: ATT Error Codes // MARK: ATT Error Codes
#define ATT_ERROR_SUCCESS 0x00
#define ATT_ERROR_INVALID_HANDLE 0x01 #define ATT_ERROR_INVALID_HANDLE 0x01
#define ATT_ERROR_READ_NOT_PERMITTED 0x02 #define ATT_ERROR_READ_NOT_PERMITTED 0x02
#define ATT_ERROR_WRITE_NOT_PERMITTED 0x03 #define ATT_ERROR_WRITE_NOT_PERMITTED 0x03

View File

@ -962,7 +962,7 @@ typedef uint8_t sm_key_t[16];
/** /**
* @format H1 * @format H1
* @param handle * @param handle
* @param status * @param att_status see ATT errors in bluetooth.h
*/ */
#define GATT_EVENT_QUERY_COMPLETE 0xA0 #define GATT_EVENT_QUERY_COMPLETE 0xA0

View File

@ -1835,12 +1835,12 @@ static inline hci_con_handle_t gatt_event_query_complete_get_handle(const uint8_
return little_endian_read_16(event, 2); return little_endian_read_16(event, 2);
} }
/** /**
* @brief Get field status from event GATT_EVENT_QUERY_COMPLETE * @brief Get field att_status from event GATT_EVENT_QUERY_COMPLETE
* @param event packet * @param event packet
* @return status * @return att_status
* @note: btstack_type 1 * @note: btstack_type 1
*/ */
static inline uint8_t gatt_event_query_complete_get_status(const uint8_t * event){ static inline uint8_t gatt_event_query_complete_get_att_status(const uint8_t * event){
return event[4]; return event[4];
} }
#endif #endif

View File

@ -316,7 +316,7 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
case TC_W4_ENABLE_NOTIFICATIONS_COMPLETE: case TC_W4_ENABLE_NOTIFICATIONS_COMPLETE:
switch(hci_event_packet_get_type(packet)){ switch(hci_event_packet_get_type(packet)){
case GATT_EVENT_QUERY_COMPLETE: case GATT_EVENT_QUERY_COMPLETE:
printf("Notifications enabled, status %02x\n", gatt_event_query_complete_get_status(packet)); printf("Notifications enabled, ATT status %02x\n", gatt_event_query_complete_get_att_status(packet));
state = TC_CONNECTED; state = TC_CONNECTED;
break; break;
default: default:
@ -326,7 +326,7 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
case TC_W4_ENABLE_INDICATIONS_COMPLETE: case TC_W4_ENABLE_INDICATIONS_COMPLETE:
switch(hci_event_packet_get_type(packet)){ switch(hci_event_packet_get_type(packet)){
case GATT_EVENT_QUERY_COMPLETE: case GATT_EVENT_QUERY_COMPLETE:
printf("Indications enabled, status %02x\n", gatt_event_query_complete_get_status(packet)); printf("Indications enabled, ATT status %02x\n", gatt_event_query_complete_get_att_status(packet));
state = TC_CONNECTED; state = TC_CONNECTED;
break; break;
default: default:
@ -337,8 +337,8 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
case TC_W4_WRITE_CHARACTERISTIC: case TC_W4_WRITE_CHARACTERISTIC:
switch(hci_event_packet_get_type(packet)){ switch(hci_event_packet_get_type(packet)){
case GATT_EVENT_QUERY_COMPLETE: case GATT_EVENT_QUERY_COMPLETE:
printf("Command done, status %02x\n", gatt_event_query_complete_get_status(packet)); printf("Command done, ATT status %02x\n", gatt_event_query_complete_get_att_status(packet));
if (gatt_event_query_complete_get_status(packet) == ERROR_CODE_SUCCESS){ if (gatt_event_query_complete_get_att_status(packet) == ATT_ERROR_SUCCESS){
csc_client_indication_timer_start(); csc_client_indication_timer_start();
} }
state = TC_CONNECTED; state = TC_CONNECTED;

View File

@ -244,7 +244,7 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
case TC_W4_ENABLE_NOTIFICATIONS_COMPLETE: case TC_W4_ENABLE_NOTIFICATIONS_COMPLETE:
switch(hci_event_packet_get_type(packet)){ switch(hci_event_packet_get_type(packet)){
case GATT_EVENT_QUERY_COMPLETE: case GATT_EVENT_QUERY_COMPLETE:
printf("Notifications enabled, status %02x\n", gatt_event_query_complete_get_status(packet)); printf("Notifications enabled, ATT status %02x\n", gatt_event_query_complete_get_att_status(packet));
state = TC_CONNECTED; state = TC_CONNECTED;
break; break;
default: default: