mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-07 16:20:19 +00:00
Send complete event in case of disconnection
This commit is contained in:
parent
faab072e58
commit
95ecff4f84
@ -100,6 +100,9 @@ extern "C" {
|
|||||||
#define ATT_ERROR_UNSUPPORTED_GROUP_TYPE 0x10
|
#define ATT_ERROR_UNSUPPORTED_GROUP_TYPE 0x10
|
||||||
#define ATT_ERROR_INSUFFICIENT_RESOURCES 0x11
|
#define ATT_ERROR_INSUFFICIENT_RESOURCES 0x11
|
||||||
|
|
||||||
|
|
||||||
|
// custom BTstack error codes
|
||||||
|
#define ATT_ERROR_HCI_DISCONNECT_RECEIVED 0x1f
|
||||||
// MARK: Attribute Property Flags
|
// MARK: Attribute Property Flags
|
||||||
#define ATT_PROPERTY_BROADCAST 0x01
|
#define ATT_PROPERTY_BROADCAST 0x01
|
||||||
#define ATT_PROPERTY_READ 0x02
|
#define ATT_PROPERTY_READ 0x02
|
||||||
|
@ -311,14 +311,13 @@ static char * att_errors[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static void att_client_report_error(uint8_t * packet, uint16_t size){
|
static void att_client_report_error(uint8_t * packet, uint16_t size){
|
||||||
|
|
||||||
uint8_t error_code = packet[4];
|
uint8_t error_code = packet[4];
|
||||||
char * error = "Unknown";
|
char * error = "Unknown";
|
||||||
if (error_code <= 0x11){
|
if (error_code <= 0x11){
|
||||||
error = att_errors[error_code];
|
error = att_errors[error_code];
|
||||||
}
|
}
|
||||||
uint16_t handle = READ_BT_16(packet, 2);
|
uint16_t handle = READ_BT_16(packet, 2);
|
||||||
printf("ATT_ERROR_REPORT handle 0x%04x, error: %u - %s\n", handle, error_code, error);
|
log_info("ATT_ERROR_REPORT handle 0x%04x, error: %u - %s\n", handle, error_code, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint16_t get_last_result_handle(uint8_t * packet, uint16_t size){
|
static uint16_t get_last_result_handle(uint8_t * packet, uint16_t size){
|
||||||
@ -594,7 +593,7 @@ gatt_client_t * get_gatt_client_context_for_handle(uint16_t handle){
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gatt_client_handle_context_list(){
|
static void gatt_client_run(){
|
||||||
if (!hci_can_send_packet_now_using_packet_buffer(HCI_COMMAND_DATA_PACKET)) return;
|
if (!hci_can_send_packet_now_using_packet_buffer(HCI_COMMAND_DATA_PACKET)) return;
|
||||||
// printf("handle_peripheral_list 4\n");
|
// printf("handle_peripheral_list 4\n");
|
||||||
if (!l2cap_can_send_connectionless_packet_now()) return;
|
if (!l2cap_can_send_connectionless_packet_now()) return;
|
||||||
@ -757,10 +756,6 @@ static void gatt_client_handle_context_list(){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gatt_client_run(){
|
|
||||||
gatt_client_handle_context_list();
|
|
||||||
}
|
|
||||||
|
|
||||||
void gatt_packet_handler(void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
void gatt_packet_handler(void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||||
if (packet_type != HCI_EVENT_PACKET) return;
|
if (packet_type != HCI_EVENT_PACKET) return;
|
||||||
switch (packet[0]) {
|
switch (packet[0]) {
|
||||||
@ -769,9 +764,9 @@ void gatt_packet_handler(void * connection, uint8_t packet_type, uint16_t channe
|
|||||||
uint16_t handle = READ_BT_16(packet,3);
|
uint16_t handle = READ_BT_16(packet,3);
|
||||||
gatt_client_t * peripheral = get_gatt_client_context_for_handle(handle);
|
gatt_client_t * peripheral = get_gatt_client_context_for_handle(handle);
|
||||||
if (!peripheral) break;
|
if (!peripheral) break;
|
||||||
|
if (peripheral->gatt_client_state != P_READY){
|
||||||
peripheral->gatt_client_state = P_READY;
|
send_gatt_complete_event(peripheral, ATT_ERROR_HCI_DISCONNECT_RECEIVED);
|
||||||
send_gatt_complete_event(peripheral, 0);
|
}
|
||||||
linked_list_remove(&gatt_client_connections, (linked_item_t *) peripheral);
|
linked_list_remove(&gatt_client_connections, (linked_item_t *) peripheral);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -803,7 +798,6 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle,
|
|||||||
trigger_next_service_query(peripheral, get_last_result_handle(packet, size));
|
trigger_next_service_query(peripheral, get_last_result_handle(packet, size));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("ATT_READ_BY_GROUP_TYPE_RESPONSE\n");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1008,6 +1002,10 @@ 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_SERVICE_QUERY_RESULT:
|
case P_W4_SERVICE_QUERY_RESULT:
|
||||||
case P_W4_SERVICE_WITH_UUID_RESULT:
|
case P_W4_SERVICE_WITH_UUID_RESULT:
|
||||||
|
case P_W4_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT:
|
||||||
|
case P_W4_INCLUDED_SERVICE_QUERY_RESULT:
|
||||||
|
case P_W4_READ_BLOB_RESULT:
|
||||||
|
case P_W4_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY_RESULT:
|
||||||
peripheral->gatt_client_state = P_READY;
|
peripheral->gatt_client_state = P_READY;
|
||||||
send_gatt_complete_event(peripheral, 0);
|
send_gatt_complete_event(peripheral, 0);
|
||||||
break;
|
break;
|
||||||
@ -1018,25 +1016,7 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle,
|
|||||||
peripheral->gatt_client_state = P_READY;
|
peripheral->gatt_client_state = P_READY;
|
||||||
send_gatt_complete_event(peripheral, 0);
|
send_gatt_complete_event(peripheral, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case P_W4_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT:
|
|
||||||
peripheral->gatt_client_state = P_READY;
|
|
||||||
send_gatt_complete_event(peripheral, 0);
|
|
||||||
break;
|
|
||||||
case P_W4_INCLUDED_SERVICE_QUERY_RESULT:
|
|
||||||
peripheral->gatt_client_state = P_READY;
|
|
||||||
send_gatt_complete_event(peripheral, 0);
|
|
||||||
break;
|
|
||||||
case P_W4_READ_BLOB_RESULT:
|
|
||||||
peripheral->gatt_client_state = P_READY;
|
|
||||||
send_gatt_complete_event(peripheral, 0);
|
|
||||||
break;
|
|
||||||
case P_W4_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY_RESULT:
|
|
||||||
peripheral->gatt_client_state = P_READY;
|
|
||||||
send_gatt_complete_event(peripheral, 0);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
printf("ATT_ERROR_ATTRIBUTE_NOT_FOUND in %d\n", peripheral->gatt_client_state);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user