mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-10 06:40:23 +00:00
use single gatt_complete_event (handle, status)
This commit is contained in:
parent
253ec883b1
commit
a672584960
@ -335,9 +335,9 @@ static uint16_t get_last_result_handle(uint8_t * packet, uint16_t size){
|
||||
return READ_BT_16(packet, size - attr_length + handle_offset);
|
||||
}
|
||||
|
||||
static inline void send_gatt_complete_event(gatt_client_t * peripheral, uint8_t type, uint8_t status){
|
||||
static inline void send_gatt_complete_event(gatt_client_t * peripheral, uint8_t status){
|
||||
gatt_complete_event_t event;
|
||||
event.type = type;
|
||||
event.type = GATT_QUERY_COMPLETE;
|
||||
event.client = peripheral;
|
||||
event.status = status;
|
||||
(*gatt_client_callback)((le_event_t*)&event);
|
||||
@ -476,7 +476,7 @@ static void report_gatt_characteristic_value(gatt_client_t * peripheral, uint16_
|
||||
|
||||
static void report_gatt_characteristic_descriptor(gatt_client_t * peripheral, uint16_t handle, uint8_t *value, uint16_t value_length, uint16_t value_offset, uint8_t event_type){
|
||||
le_characteristic_descriptor_event_t event;
|
||||
event.type = event_type; // GATT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT;
|
||||
event.type = event_type;
|
||||
event.client = peripheral;
|
||||
|
||||
le_characteristic_descriptor_t descriptor;
|
||||
@ -517,7 +517,7 @@ static void report_gatt_all_characteristic_descriptors(gatt_client_t * periphera
|
||||
|
||||
}
|
||||
|
||||
static void trigger_next_query(gatt_client_t * peripheral, uint16_t last_result_handle, gatt_client_state_t next_query_state, uint8_t complete_event_type){
|
||||
static void trigger_next_query(gatt_client_t * peripheral, uint16_t last_result_handle, gatt_client_state_t next_query_state){
|
||||
if (last_result_handle < peripheral->end_group_handle){
|
||||
peripheral->start_group_handle = last_result_handle + 1;
|
||||
peripheral->gatt_client_state = next_query_state;
|
||||
@ -525,32 +525,28 @@ static void trigger_next_query(gatt_client_t * peripheral, uint16_t last_result_
|
||||
}
|
||||
// DONE
|
||||
peripheral->gatt_client_state = P_READY;
|
||||
send_gatt_complete_event(peripheral, complete_event_type, 0);
|
||||
send_gatt_complete_event(peripheral, 0);
|
||||
}
|
||||
|
||||
|
||||
static inline void trigger_next_included_service_query(gatt_client_t * peripheral, uint16_t last_result_handle){
|
||||
trigger_next_query(peripheral, last_result_handle, P_W2_SEND_INCLUDED_SERVICE_QUERY, GATT_INCLUDED_SERVICE_QUERY_COMPLETE);
|
||||
trigger_next_query(peripheral, last_result_handle, P_W2_SEND_INCLUDED_SERVICE_QUERY);
|
||||
}
|
||||
|
||||
static inline void trigger_next_service_query(gatt_client_t * peripheral, uint16_t last_result_handle){
|
||||
trigger_next_query(peripheral, last_result_handle, P_W2_SEND_SERVICE_QUERY, GATT_SERVICE_QUERY_COMPLETE);
|
||||
trigger_next_query(peripheral, last_result_handle, P_W2_SEND_SERVICE_QUERY);
|
||||
}
|
||||
|
||||
static inline void trigger_next_service_by_uuid_query(gatt_client_t * peripheral, uint16_t last_result_handle){
|
||||
trigger_next_query(peripheral, last_result_handle, P_W2_SEND_SERVICE_WITH_UUID_QUERY, GATT_SERVICE_QUERY_COMPLETE);
|
||||
trigger_next_query(peripheral, last_result_handle, P_W2_SEND_SERVICE_WITH_UUID_QUERY);
|
||||
}
|
||||
|
||||
static inline void trigger_next_characteristic_query(gatt_client_t * peripheral, uint16_t last_result_handle){
|
||||
trigger_next_query(peripheral, last_result_handle, P_W2_SEND_CHARACTERISTIC_QUERY, GATT_CHARACTERISTIC_QUERY_COMPLETE);
|
||||
trigger_next_query(peripheral, last_result_handle, P_W2_SEND_CHARACTERISTIC_QUERY);
|
||||
}
|
||||
|
||||
//static inline void trigger_next_characteristic_by_uuid_query(gatt_client_t * peripheral, uint16_t last_result_handle){
|
||||
// trigger_next_query(peripheral, last_result_handle, P_W2_SEND_INCLUDED_SERVICE_WITH_UUID_QUERY, GATT_CHARACTERISTIC_QUERY_COMPLETE);
|
||||
//}
|
||||
|
||||
static inline void trigger_next_characteristic_descriptor_query(gatt_client_t * peripheral, uint16_t last_result_handle){
|
||||
trigger_next_query(peripheral, last_result_handle, P_W2_SEND_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY, GATT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_COMPLETE);
|
||||
trigger_next_query(peripheral, last_result_handle, P_W2_SEND_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY);
|
||||
}
|
||||
|
||||
static inline void trigger_next_prepare_write_query(gatt_client_t * peripheral, gatt_client_state_t next_query_state, gatt_client_state_t done_state){
|
||||
@ -564,12 +560,12 @@ static inline void trigger_next_prepare_write_query(gatt_client_t * peripheral,
|
||||
peripheral->gatt_client_state = next_query_state;
|
||||
}
|
||||
|
||||
static inline void trigger_next_blob_query(gatt_client_t * peripheral, gatt_client_state_t next_query_state, uint8_t done_event, uint16_t received_blob_length){
|
||||
static inline void trigger_next_blob_query(gatt_client_t * peripheral, gatt_client_state_t next_query_state, uint16_t received_blob_length){
|
||||
|
||||
uint16_t max_blob_length = peripheral->mtu - 1;
|
||||
if (received_blob_length < max_blob_length){
|
||||
peripheral->gatt_client_state = P_READY;
|
||||
send_gatt_complete_event(peripheral, done_event, 0);
|
||||
send_gatt_complete_event(peripheral, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -926,15 +922,15 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle,
|
||||
switch (peripheral->gatt_client_state){
|
||||
case P_W4_WRITE_CHARACTERISTIC_VALUE_RESULT:
|
||||
peripheral->gatt_client_state = P_READY;
|
||||
send_gatt_complete_event(peripheral, GATT_CHARACTERISTIC_VALUE_WRITE_RESPONSE, 0);
|
||||
send_gatt_complete_event(peripheral, 0);
|
||||
break;
|
||||
case P_W4_CLIENT_CHARACTERISTIC_CONFIGURATION_RESULT:
|
||||
peripheral->gatt_client_state = P_READY;
|
||||
send_gatt_complete_event(peripheral, GATT_CLIENT_CHARACTERISTIC_CONFIGURATION_COMPLETE, 0);
|
||||
send_gatt_complete_event(peripheral, 0);
|
||||
break;
|
||||
case P_W4_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT:
|
||||
peripheral->gatt_client_state = P_READY;
|
||||
send_gatt_complete_event(peripheral, GATT_CHARACTERISTIC_DESCRIPTOR_WRITE_RESPONSE, 0);
|
||||
send_gatt_complete_event(peripheral, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -947,13 +943,13 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle,
|
||||
switch(peripheral->gatt_client_state){
|
||||
case P_W4_READ_BLOB_RESULT:
|
||||
report_gatt_long_characteristic_value_blob(peripheral, &packet[1], received_blob_length, peripheral->attribute_offset);
|
||||
trigger_next_blob_query(peripheral, P_W2_SEND_READ_BLOB_QUERY, GATT_LONG_CHARACTERISTIC_VALUE_QUERY_COMPLETE, received_blob_length);
|
||||
trigger_next_blob_query(peripheral, P_W2_SEND_READ_BLOB_QUERY, received_blob_length);
|
||||
break;
|
||||
case P_W4_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_RESULT:
|
||||
report_gatt_characteristic_descriptor(peripheral, peripheral->attribute_handle,
|
||||
&packet[1], received_blob_length,
|
||||
peripheral->attribute_offset, GATT_LONG_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT);
|
||||
trigger_next_blob_query(peripheral, P_W2_SEND_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_QUERY, GATT_LONG_CHARACTERISTIC_DESCRIPTOR_QUERY_COMPLETE, received_blob_length);
|
||||
trigger_next_blob_query(peripheral, P_W2_SEND_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_QUERY, received_blob_length);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -990,15 +986,15 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle,
|
||||
switch (peripheral->gatt_client_state){
|
||||
case P_W4_EXECUTE_PREPARED_WRITE_RESULT:
|
||||
peripheral->gatt_client_state = P_READY;
|
||||
send_gatt_complete_event(peripheral, GATT_LONG_CHARACTERISTIC_VALUE_WRITE_COMPLETE, 0);
|
||||
send_gatt_complete_event(peripheral, 0);
|
||||
break;
|
||||
case P_W4_CANCEL_PREPARED_WRITE_RESULT:
|
||||
peripheral->gatt_client_state = P_READY;
|
||||
send_gatt_complete_event(peripheral, GATT_LONG_CHARACTERISTIC_VALUE_WRITE_CANCELED, 1);
|
||||
send_gatt_complete_event(peripheral, 1);
|
||||
break;
|
||||
case P_W4_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT:
|
||||
peripheral->gatt_client_state = P_READY;
|
||||
send_gatt_complete_event(peripheral, GATT_LONG_CHARACTERISTIC_DESCRIPTOR_WRITE_COMPLETE, 0);
|
||||
send_gatt_complete_event(peripheral, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -1014,31 +1010,31 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle,
|
||||
case P_W4_SERVICE_QUERY_RESULT:
|
||||
case P_W4_SERVICE_WITH_UUID_RESULT:
|
||||
peripheral->gatt_client_state = P_READY;
|
||||
send_gatt_complete_event(peripheral, GATT_SERVICE_QUERY_COMPLETE, 0);
|
||||
send_gatt_complete_event(peripheral, 0);
|
||||
break;
|
||||
|
||||
case P_W4_CHARACTERISTIC_QUERY_RESULT:
|
||||
case P_W4_CHARACTERISTIC_WITH_UUID_QUERY_RESULT:
|
||||
characteristic_end_found(peripheral, peripheral->end_group_handle);
|
||||
peripheral->gatt_client_state = P_READY;
|
||||
send_gatt_complete_event(peripheral, GATT_CHARACTERISTIC_QUERY_COMPLETE, 0);
|
||||
send_gatt_complete_event(peripheral, 0);
|
||||
break;
|
||||
|
||||
case P_W4_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT:
|
||||
peripheral->gatt_client_state = P_READY;
|
||||
send_gatt_complete_event(peripheral, GATT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_COMPLETE, 0);
|
||||
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, GATT_INCLUDED_SERVICE_QUERY_COMPLETE, 0);
|
||||
send_gatt_complete_event(peripheral, 0);
|
||||
break;
|
||||
case P_W4_READ_BLOB_RESULT:
|
||||
peripheral->gatt_client_state = P_READY;
|
||||
send_gatt_complete_event(peripheral, GATT_LONG_CHARACTERISTIC_VALUE_QUERY_COMPLETE, 0);
|
||||
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, GATT_CLIENT_CHARACTERISTIC_CONFIGURATION_COMPLETE, 0);
|
||||
send_gatt_complete_event(peripheral, 0);
|
||||
break;
|
||||
default:
|
||||
printf("ATT_ERROR_ATTRIBUTE_NOT_FOUND in %d\n", peripheral->gatt_client_state);
|
||||
@ -1158,7 +1154,7 @@ le_command_status_t gatt_client_discover_characteristics_for_service_by_uuid128(
|
||||
le_command_status_t gatt_client_discover_characteristic_descriptors(gatt_client_t *peripheral, le_characteristic_t *characteristic){
|
||||
if (!gatt_client_is_ready(peripheral)) return BLE_PERIPHERAL_IN_WRONG_STATE;
|
||||
if (characteristic->value_handle == characteristic->end_handle){
|
||||
send_gatt_complete_event(peripheral, GATT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_COMPLETE, 0);
|
||||
send_gatt_complete_event(peripheral, 0);
|
||||
return BLE_PERIPHERAL_OK;
|
||||
}
|
||||
peripheral->start_group_handle = characteristic->value_handle + 1;
|
||||
|
@ -701,7 +701,7 @@ static void handle_gatt_client_event(le_event_t * event){
|
||||
service = ((le_service_event_t *) event)->service;
|
||||
dump_service(&service);
|
||||
break;
|
||||
case GATT_SERVICE_QUERY_COMPLETE:
|
||||
case GATT_QUERY_COMPLETE:
|
||||
tc_state = TC_W4_CHARACTERISTIC_RESULT;
|
||||
printf("\n test client - FIND ENABLE CHARACTERISTIC for SERVICE QUERY : \n");
|
||||
dump_service(&service);
|
||||
@ -718,7 +718,7 @@ static void handle_gatt_client_event(le_event_t * event){
|
||||
enable_characteristic = ((le_characteristic_event_t *) event)->characteristic;
|
||||
dump_characteristic(&enable_characteristic);
|
||||
break;
|
||||
case GATT_CHARACTERISTIC_QUERY_COMPLETE:
|
||||
case GATT_QUERY_COMPLETE:
|
||||
tc_state = TC_W4_CHARACTERISTIC_DESCRIPTOR_RESULT;
|
||||
printf("\n test client - ACC ENABLE\n");
|
||||
gatt_client_discover_characteristic_descriptors(&test_gatt_client_context, &enable_characteristic);
|
||||
@ -733,17 +733,8 @@ static void handle_gatt_client_event(le_event_t * event){
|
||||
case GATT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT:
|
||||
dump_descriptor(event);
|
||||
break;
|
||||
|
||||
case GATT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_COMPLETE:
|
||||
gatt_client_read_long_characteristic_descriptor(&test_gatt_client_context, &descriptor);
|
||||
break;
|
||||
case GATT_LONG_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT:{
|
||||
descriptor = ((le_characteristic_descriptor_event_t *) event)->characteristic_descriptor;
|
||||
dump_descriptor(&descriptor);
|
||||
break;
|
||||
}
|
||||
case GATT_LONG_CHARACTERISTIC_DESCRIPTOR_QUERY_COMPLETE:
|
||||
printf("DONE");
|
||||
|
||||
case GATT_QUERY_COMPLETE:
|
||||
tc_state = TC_W4_DISCONNECT;
|
||||
printf("\n\n test client - DISCONNECT ");
|
||||
gap_disconnect(test_gatt_client_handle);
|
||||
|
@ -246,19 +246,19 @@ extern "C" {
|
||||
// not provided by daemon, only used for internal testing
|
||||
#define SDP_QUERY_SERVICE_RECORD_HANDLE 0x94
|
||||
|
||||
/**
|
||||
* @format HX
|
||||
* @param handle
|
||||
* @param service
|
||||
*/
|
||||
#define GATT_SERVICE_QUERY_RESULT 0xA0
|
||||
|
||||
/**
|
||||
* @format H1
|
||||
* @param handle
|
||||
* @param status
|
||||
*/
|
||||
#define GATT_SERVICE_QUERY_COMPLETE 0xA1
|
||||
#define GATT_QUERY_COMPLETE 0xA0
|
||||
|
||||
/**
|
||||
* @format HX
|
||||
* @param handle
|
||||
* @param service
|
||||
*/
|
||||
#define GATT_SERVICE_QUERY_RESULT 0xA1
|
||||
|
||||
/**
|
||||
* @format HY
|
||||
@ -267,40 +267,19 @@ extern "C" {
|
||||
*/
|
||||
#define GATT_CHARACTERISTIC_QUERY_RESULT 0xA2
|
||||
|
||||
/**
|
||||
* @format H1
|
||||
* @param handle
|
||||
* @param status
|
||||
*/
|
||||
#define GATT_CHARACTERISTIC_QUERY_COMPLETE 0xA3
|
||||
|
||||
/**
|
||||
* @format HX
|
||||
* @param handle
|
||||
* @param service
|
||||
*/
|
||||
#define GATT_INCLUDED_SERVICE_QUERY_RESULT 0xA4
|
||||
|
||||
/**
|
||||
* @format H1
|
||||
* @param handle
|
||||
* @param status
|
||||
*/
|
||||
#define GATT_INCLUDED_SERVICE_QUERY_COMPLETE 0xA5
|
||||
#define GATT_INCLUDED_SERVICE_QUERY_RESULT 0xA3
|
||||
|
||||
/**
|
||||
* @format HY
|
||||
* @param handle
|
||||
* @param characteristic_descriptor
|
||||
*/
|
||||
#define GATT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT 0xA6
|
||||
|
||||
/**
|
||||
* @format H1
|
||||
* @param handle
|
||||
* @param status
|
||||
*/
|
||||
#define GATT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_COMPLETE 0xA7
|
||||
#define GATT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT 0xA4
|
||||
|
||||
/**
|
||||
* @format H2LV
|
||||
@ -309,66 +288,15 @@ extern "C" {
|
||||
* @param value_length
|
||||
* @param value
|
||||
*/
|
||||
#define GATT_CHARACTERISTIC_VALUE_QUERY_RESULT 0xA8
|
||||
#define GATT_CHARACTERISTIC_VALUE_QUERY_RESULT 0xA5
|
||||
|
||||
#define GATT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT 0xA9
|
||||
#define GATT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT 0xA6
|
||||
|
||||
/**
|
||||
* @format H1
|
||||
* @param handle
|
||||
* @param status
|
||||
*/
|
||||
#define GATT_LONG_CHARACTERISTIC_VALUE_QUERY_COMPLETE 0xAA
|
||||
#define GATT_NOTIFICATION 0xA7
|
||||
#define GATT_INDICATION 0xA8
|
||||
|
||||
/**
|
||||
* @format H1
|
||||
* @param handle
|
||||
* @param status
|
||||
*/
|
||||
#define GATT_CHARACTERISTIC_VALUE_WRITE_RESPONSE 0xAB
|
||||
|
||||
/**
|
||||
* @format H1
|
||||
* @param handle
|
||||
* @param status
|
||||
*/
|
||||
#define GATT_LONG_CHARACTERISTIC_VALUE_WRITE_COMPLETE 0xAC
|
||||
|
||||
/**
|
||||
* @format H1
|
||||
* @param handle
|
||||
* @param status
|
||||
*/
|
||||
#define GATT_LONG_CHARACTERISTIC_VALUE_WRITE_CANCELED 0xAD
|
||||
|
||||
#define GATT_NOTIFICATION 0xAE
|
||||
#define GATT_INDICATION 0xAF
|
||||
|
||||
/**
|
||||
* @format H1
|
||||
* @param handle
|
||||
* @param status
|
||||
*/
|
||||
#define GATT_CLIENT_CHARACTERISTIC_CONFIGURATION_COMPLETE 0xB0
|
||||
|
||||
#define GATT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT 0xB1
|
||||
#define GATT_LONG_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT 0xB2
|
||||
|
||||
/**
|
||||
* @format H1
|
||||
* @param handle
|
||||
* @param status
|
||||
*/
|
||||
#define GATT_LONG_CHARACTERISTIC_DESCRIPTOR_QUERY_COMPLETE 0xB3
|
||||
|
||||
#define GATT_CHARACTERISTIC_DESCRIPTOR_WRITE_RESPONSE 0xB4
|
||||
|
||||
/**
|
||||
* @format H1
|
||||
* @param handle
|
||||
* @param status
|
||||
*/
|
||||
#define GATT_LONG_CHARACTERISTIC_DESCRIPTOR_WRITE_COMPLETE 0xB5
|
||||
#define GATT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT 0xA9
|
||||
#define GATT_LONG_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT 0xAA
|
||||
|
||||
// data: event(8), len(8), status (8), hci_handle (16), attribute_handle (16)
|
||||
#define ATT_HANDLE_VALUE_INDICATION_COMPLETE 0xB6
|
||||
|
78
src/daemon.c
78
src/daemon.c
@ -192,27 +192,27 @@ uint8_t * daemon_get_data_buffer(gatt_client_t *context) {
|
||||
return ((uint8_t *) context) + sizeof(gatt_client_t) + sizeof(gatt_client_helper_t);
|
||||
}
|
||||
|
||||
static void send_gatt_query_complete(connection_t * connection, uint8_t event_type, uint16_t handle, uint8_t status){
|
||||
static void send_gatt_query_complete(connection_t * connection, uint16_t handle, uint8_t status){
|
||||
// @format H1
|
||||
uint8_t event[5];
|
||||
event[0] = event_type;
|
||||
event[0] = GATT_QUERY_COMPLETE;
|
||||
event[1] = 3;
|
||||
bt_store_16(event, 2, handle);
|
||||
event[4] = status;
|
||||
socket_connection_send_packet(connection, HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||
}
|
||||
|
||||
gatt_client_t * daemon_prepare_gatt_client_context(connection_t *connection, uint8_t *packet, uint8_t event_type) {
|
||||
gatt_client_t * daemon_prepare_gatt_client_context(connection_t *connection, uint8_t *packet) {
|
||||
hci_con_handle_t handle = READ_BT_16(packet, 3);
|
||||
|
||||
gatt_client_t *context = daemon_provide_gatt_client_context_for_handle(handle);
|
||||
if (!context) {
|
||||
send_gatt_query_complete(connection, event_type, handle, BTSTACK_MEMORY_ALLOC_FAILED);
|
||||
send_gatt_query_complete(connection, handle, BTSTACK_MEMORY_ALLOC_FAILED);
|
||||
return NULL;
|
||||
}
|
||||
// check state
|
||||
if (!gatt_client_is_ready(context)){
|
||||
send_gatt_query_complete(connection, event_type, handle, GATT_CLIENT_BUSY);
|
||||
send_gatt_query_complete(connection, handle, GATT_CLIENT_BUSY);
|
||||
return NULL;
|
||||
}
|
||||
context->context = connection;
|
||||
@ -542,63 +542,64 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui
|
||||
break;
|
||||
#if defined(HAVE_MALLOC) && defined(HAVE_BLE)
|
||||
case GATT_DISCOVER_ALL_PRIMARY_SERVICES:
|
||||
context = daemon_prepare_gatt_client_context(connection, packet, GATT_SERVICE_QUERY_COMPLETE);
|
||||
context = daemon_prepare_gatt_client_context(connection, packet);
|
||||
if (!context) break;
|
||||
gatt_client_discover_primary_services(context);
|
||||
break;
|
||||
case GATT_DISCOVER_PRIMARY_SERVICES_BY_UUID16:
|
||||
context = daemon_prepare_gatt_client_context(connection, packet, GATT_SERVICE_QUERY_COMPLETE);
|
||||
context = daemon_prepare_gatt_client_context(connection, packet);
|
||||
if (!context) break;
|
||||
gatt_client_discover_primary_services_by_uuid16(context, READ_BT_16(packet, 5));
|
||||
break;
|
||||
case GATT_DISCOVER_PRIMARY_SERVICES_BY_UUID128:
|
||||
context = daemon_prepare_gatt_client_context(connection, packet, GATT_SERVICE_QUERY_COMPLETE);
|
||||
context = daemon_prepare_gatt_client_context(connection, packet);
|
||||
if (!context) break;
|
||||
swap128(&packet[25], uuid128);
|
||||
gatt_client_discover_primary_services_by_uuid128(context, uuid128);
|
||||
break;
|
||||
case GATT_FIND_INCLUDED_SERVICES_FOR_SERVICE:
|
||||
context = daemon_prepare_gatt_client_context(connection, packet, GATT_INCLUDED_SERVICE_QUERY_COMPLETE);
|
||||
context = daemon_prepare_gatt_client_context(connection, packet);
|
||||
if (!context) break;
|
||||
daemon_gatt_deserialize_service(packet, 5, &service);
|
||||
gatt_client_find_included_services_for_service(context, &service);
|
||||
break;
|
||||
|
||||
case GATT_DISCOVER_CHARACTERISTICS_FOR_SERVICE:
|
||||
context = daemon_prepare_gatt_client_context(connection, packet, GATT_CHARACTERISTIC_QUERY_COMPLETE);
|
||||
context = daemon_prepare_gatt_client_context(connection, packet);
|
||||
if (!context) break;
|
||||
daemon_gatt_deserialize_service(packet, 5, &service);
|
||||
gatt_client_discover_characteristics_for_service(context, &service);
|
||||
break;
|
||||
case GATT_DISCOVER_CHARACTERISTICS_FOR_SERVICE_BY_UUID128:
|
||||
context = daemon_prepare_gatt_client_context(connection, packet, GATT_CHARACTERISTIC_QUERY_COMPLETE);
|
||||
context = daemon_prepare_gatt_client_context(connection, packet);
|
||||
if (!context) break;
|
||||
daemon_gatt_deserialize_service(packet, 5, &service);
|
||||
swap128(&packet[5 + SERVICE_LENGTH], uuid128);
|
||||
gatt_client_discover_characteristics_for_service_by_uuid128(context, &service, uuid128);
|
||||
break;
|
||||
case GATT_DISCOVER_CHARACTERISTIC_DESCRIPTOR:
|
||||
context = daemon_prepare_gatt_client_context(connection, packet, GATT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_COMPLETE);
|
||||
context = daemon_prepare_gatt_client_context(connection, packet);
|
||||
if (!context) break;
|
||||
daemon_gatt_deserialize_characteristic(packet, 5, &characteristic);
|
||||
gatt_client_discover_characteristic_descriptors(context, &characteristic);
|
||||
break;
|
||||
|
||||
case GATT_READ_VALUE_OF_CHARACTERISTIC:
|
||||
context = daemon_prepare_gatt_client_context(connection, packet, GATT_CHARACTERISTIC_VALUE_QUERY_RESULT);
|
||||
// context = daemon_prepare_gatt_client_context(connection, packet, GATT_CHARACTERISTIC_VALUE_QUERY_RESULT);
|
||||
context = daemon_prepare_gatt_client_context(connection, packet);
|
||||
if (!context) break;
|
||||
daemon_gatt_deserialize_characteristic(packet, 5, &characteristic);
|
||||
gatt_client_read_value_of_characteristic(context, &characteristic);
|
||||
break;
|
||||
case GATT_READ_LONG_VALUE_OF_CHARACTERISTIC:
|
||||
context = daemon_prepare_gatt_client_context(connection, packet, GATT_LONG_CHARACTERISTIC_VALUE_QUERY_COMPLETE);
|
||||
context = daemon_prepare_gatt_client_context(connection, packet);
|
||||
if (!context) break;
|
||||
daemon_gatt_deserialize_characteristic(packet, 5, &characteristic);
|
||||
gatt_client_read_long_value_of_characteristic(context, &characteristic);
|
||||
break;
|
||||
|
||||
case GATT_WRITE_VALUE_OF_CHARACTERISTIC_WITHOUT_RESPONSE:
|
||||
context = daemon_prepare_gatt_client_context(connection, packet, GATT_CHARACTERISTIC_VALUE_WRITE_RESPONSE);
|
||||
context = daemon_prepare_gatt_client_context(connection, packet);
|
||||
if (!context) break;
|
||||
daemon_gatt_deserialize_characteristic(packet, 5, &characteristic);
|
||||
data_length = READ_BT_16(packet, 5 + CHARACTERISTIC_LENGTH);
|
||||
@ -607,7 +608,7 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui
|
||||
gatt_client_write_value_of_characteristic_without_response(context, characteristic.value_handle, data_length, data);
|
||||
break;
|
||||
case GATT_WRITE_VALUE_OF_CHARACTERISTIC:
|
||||
context = daemon_prepare_gatt_client_context(connection, packet, GATT_CHARACTERISTIC_VALUE_WRITE_RESPONSE);
|
||||
context = daemon_prepare_gatt_client_context(connection, packet);
|
||||
if (!context) break;
|
||||
daemon_gatt_deserialize_characteristic(packet, 5, &characteristic);
|
||||
data_length = READ_BT_16(packet, 5 + CHARACTERISTIC_LENGTH);
|
||||
@ -616,7 +617,7 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui
|
||||
gatt_client_write_value_of_characteristic(context, characteristic.value_handle, data_length, data);
|
||||
break;
|
||||
case GATT_WRITE_LONG_VALUE_OF_CHARACTERISTIC:
|
||||
context = daemon_prepare_gatt_client_context(connection, packet, GATT_LONG_CHARACTERISTIC_VALUE_WRITE_COMPLETE);
|
||||
context = daemon_prepare_gatt_client_context(connection, packet);
|
||||
if (!context) break;
|
||||
daemon_gatt_deserialize_characteristic(packet, 5, &characteristic);
|
||||
data_length = READ_BT_16(packet, 5 + CHARACTERISTIC_LENGTH);
|
||||
@ -625,7 +626,7 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui
|
||||
gatt_client_write_long_value_of_characteristic(context, characteristic.value_handle, data_length, data);
|
||||
break;
|
||||
case GATT_RELIABLE_WRITE_LONG_VALUE_OF_CHARACTERISTIC:
|
||||
context = daemon_prepare_gatt_client_context(connection, packet, GATT_LONG_CHARACTERISTIC_VALUE_WRITE_COMPLETE);
|
||||
context = daemon_prepare_gatt_client_context(connection, packet);
|
||||
if (!context) break;
|
||||
daemon_gatt_deserialize_characteristic(packet, 5, &characteristic);
|
||||
data_length = READ_BT_16(packet, 5 + CHARACTERISTIC_LENGTH);
|
||||
@ -634,20 +635,21 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui
|
||||
gatt_client_write_long_value_of_characteristic(context, characteristic.value_handle, data_length, data);
|
||||
break;
|
||||
case GATT_READ_CHARACTERISTIC_DESCRIPTOR:
|
||||
context = daemon_prepare_gatt_client_context(connection, packet, GATT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT);
|
||||
// context = daemon_prepare_gatt_client_context(connection, packet, GATT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT);
|
||||
context = daemon_prepare_gatt_client_context(connection, packet);
|
||||
if (!context) break;
|
||||
daemon_gatt_deserialize_characteristic_descriptor(packet, 5, &descriptor);
|
||||
gatt_client_read_characteristic_descriptor(context, &descriptor);
|
||||
break;
|
||||
case GATT_READ_LONG_CHARACTERISTIC_DESCRIPTOR:
|
||||
context = daemon_prepare_gatt_client_context(connection, packet, GATT_LONG_CHARACTERISTIC_DESCRIPTOR_QUERY_COMPLETE);
|
||||
context = daemon_prepare_gatt_client_context(connection, packet);
|
||||
if (!context) break;
|
||||
daemon_gatt_deserialize_characteristic_descriptor(packet, 5, &descriptor);
|
||||
gatt_client_read_long_characteristic_descriptor(context, &descriptor);
|
||||
break;
|
||||
|
||||
case GATT_WRITE_CHARACTERISTIC_DESCRIPTOR:
|
||||
context = daemon_prepare_gatt_client_context(connection, packet, GATT_CHARACTERISTIC_DESCRIPTOR_WRITE_RESPONSE);
|
||||
context = daemon_prepare_gatt_client_context(connection, packet);
|
||||
if (!context) break;
|
||||
daemon_gatt_deserialize_characteristic_descriptor(packet, 5, &descriptor);
|
||||
data = daemon_get_data_buffer(context);
|
||||
@ -655,7 +657,7 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui
|
||||
gatt_client_write_characteristic_descriptor(context, &descriptor, data_length, data);
|
||||
break;
|
||||
case GATT_WRITE_LONG_CHARACTERISTIC_DESCRIPTOR:
|
||||
context = daemon_prepare_gatt_client_context(connection, packet, GATT_LONG_CHARACTERISTIC_DESCRIPTOR_WRITE_COMPLETE);
|
||||
context = daemon_prepare_gatt_client_context(connection, packet);
|
||||
if (!context) break;
|
||||
daemon_gatt_deserialize_characteristic_descriptor(packet, 5, &descriptor);
|
||||
data = daemon_get_data_buffer(context);
|
||||
@ -664,7 +666,7 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui
|
||||
break;
|
||||
case GATT_WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION:{
|
||||
uint16_t configuration = READ_BT_16(packet, 5 + CHARACTERISTIC_LENGTH);
|
||||
context = daemon_prepare_gatt_client_context(connection, packet, configuration);
|
||||
context = daemon_prepare_gatt_client_context(connection, packet);
|
||||
if (!context) break;
|
||||
daemon_gatt_deserialize_characteristic(packet, 5, &characteristic);
|
||||
gatt_client_write_client_characteristic_configuration(context, &characteristic, configuration);
|
||||
@ -1075,7 +1077,9 @@ static void * run_loop_thread(void *context){
|
||||
#ifdef HAVE_BLE
|
||||
|
||||
static void handle_gatt_client_event(le_event_t * le_event){
|
||||
|
||||
connection_t * context = (connection_t *)le_event->client->context;
|
||||
gatt_complete_event_t * complete_event = (gatt_complete_event_t *) le_event;
|
||||
|
||||
switch(le_event->type){
|
||||
|
||||
case GATT_SERVICE_QUERY_RESULT:
|
||||
@ -1083,14 +1087,14 @@ static void handle_gatt_client_event(le_event_t * le_event){
|
||||
uint8_t event[4 + SERVICE_LENGTH];
|
||||
daemon_setup_service_event(le_event, event);
|
||||
hci_dump_packet(HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||
socket_connection_send_packet((connection_t *)le_event->client->context, HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||
socket_connection_send_packet(context, HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||
break;
|
||||
}
|
||||
case GATT_CHARACTERISTIC_QUERY_RESULT:{
|
||||
uint8_t event[4 + CHARACTERISTIC_LENGTH];
|
||||
daemon_gatt_setup_characteristic_event(le_event, event);
|
||||
hci_dump_packet(HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||
socket_connection_send_packet((connection_t *)le_event->client->context, HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||
socket_connection_send_packet(context, HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1100,7 +1104,7 @@ static void handle_gatt_client_event(le_event_t * le_event){
|
||||
uint8_t event[4 + CHARACTERISTIC_DESCRIPTOR_LENGTH];
|
||||
daemon_setup_characteristic_descriptor_event(le_event, event);
|
||||
hci_dump_packet(HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||
socket_connection_send_packet((connection_t *)le_event->client->context, HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||
socket_connection_send_packet(context, HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1108,7 +1112,7 @@ static void handle_gatt_client_event(le_event_t * le_event){
|
||||
uint8_t event[4 + 2 + 1 + ATT_MAX_ATTRIBUTE_SIZE]; // (type, len, handle), handle, len, data
|
||||
daemon_setup_characteristic_value_event(le_event, event);
|
||||
hci_dump_packet(HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||
socket_connection_send_packet((connection_t *)le_event->client->context, HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||
socket_connection_send_packet(context, HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1122,22 +1126,10 @@ static void handle_gatt_client_event(le_event_t * le_event){
|
||||
// TODO
|
||||
break;
|
||||
|
||||
case GATT_SERVICE_QUERY_COMPLETE:
|
||||
case GATT_CHARACTERISTIC_QUERY_COMPLETE:
|
||||
case GATT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_COMPLETE:
|
||||
case GATT_LONG_CHARACTERISTIC_VALUE_QUERY_COMPLETE:
|
||||
case GATT_LONG_CHARACTERISTIC_VALUE_WRITE_COMPLETE:
|
||||
case GATT_CLIENT_CHARACTERISTIC_CONFIGURATION_COMPLETE:
|
||||
case GATT_LONG_CHARACTERISTIC_DESCRIPTOR_QUERY_COMPLETE:
|
||||
case GATT_LONG_CHARACTERISTIC_DESCRIPTOR_WRITE_COMPLETE:
|
||||
case GATT_CHARACTERISTIC_VALUE_WRITE_RESPONSE:
|
||||
case GATT_CHARACTERISTIC_DESCRIPTOR_WRITE_RESPONSE:
|
||||
send_gatt_query_complete((connection_t *) le_event->client->context, le_event->type, le_event->client->handle, 0);
|
||||
break;
|
||||
|
||||
case GATT_LONG_CHARACTERISTIC_VALUE_WRITE_CANCELED:
|
||||
send_gatt_query_complete((connection_t *) le_event->client->context, le_event->type, le_event->client->handle, 1);
|
||||
case GATT_QUERY_COMPLETE:
|
||||
send_gatt_query_complete(context, complete_event->client->handle, complete_event->status);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -1441,11 +1441,12 @@ void hci_run(){
|
||||
hci_send_cmd(&hci_accept_connection_request, connection->address, 1);
|
||||
return;
|
||||
|
||||
#ifdef HAVE_BLE
|
||||
case SEND_CANCEL_CONNECTION:
|
||||
connection->state = SENT_CANCEL_CONNECTION;
|
||||
hci_send_cmd(&hci_le_create_connection_cancel);
|
||||
return;
|
||||
|
||||
#endif
|
||||
case SEND_DISCONNECT:
|
||||
hci_send_cmd(&hci_disconnect, connection->con_handle, 0x13); // remote closed connection
|
||||
connection->state = SENT_DISCONNECT;
|
||||
@ -2234,10 +2235,10 @@ le_command_status_t le_central_connect_cancel(){
|
||||
hci_connection_t * conn = (hci_connection_t *) it;
|
||||
if (!hci_is_le_connection(conn)) continue;
|
||||
switch (conn->state){
|
||||
SEND_CREATE_CONNECTION:
|
||||
case SEND_CREATE_CONNECTION:
|
||||
hci_emit_le_connection_complete(conn, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER);
|
||||
break;
|
||||
SENT_CREATE_CONNECTION:
|
||||
case SENT_CREATE_CONNECTION:
|
||||
conn->state = SEND_CANCEL_CONNECTION;
|
||||
hci_run();
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user