mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-17 02:42:33 +00:00
gatt_client: drop subclient struct and id. pass in callback for requests. new gatt_client_listen_for_characteristic_value_updates for notifications and indications with client provided storage
This commit is contained in:
parent
591423b2a5
commit
9c662c9bc0
@ -81,10 +81,12 @@ typedef enum {
|
||||
TC_W4_BATTERY_DATA
|
||||
} gc_state_t;
|
||||
|
||||
static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
||||
|
||||
static bd_addr_t cmdline_addr = { };
|
||||
static int cmdline_addr_found = 0;
|
||||
|
||||
uint16_t gc_id, gc_handle;
|
||||
uint16_t gc_handle;
|
||||
static uint16_t battery_service_uuid = 0x180F;
|
||||
static uint16_t battery_level_characteristic_uuid = 0x2a19;
|
||||
static le_service_t battery_service;
|
||||
@ -179,7 +181,7 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
|
||||
}
|
||||
state = TC_W4_CHARACTERISTIC_RESULT;
|
||||
printf("\nSearch for battery level characteristic in battery service. ");
|
||||
gatt_client_discover_characteristics_for_service_by_uuid16(gc_id, gc_handle, &battery_service, battery_level_characteristic_uuid);
|
||||
gatt_client_discover_characteristics_for_service_by_uuid16(handle_gatt_client_event, gc_handle, &battery_service, battery_level_characteristic_uuid);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -196,7 +198,7 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
|
||||
case GATT_EVENT_QUERY_COMPLETE:
|
||||
state = TC_W4_BATTERY_DATA;
|
||||
printf("\nConfigure battery level characteristic for notify.");
|
||||
gatt_client_write_client_characteristic_configuration(gc_id, gc_handle, &config_characteristic, GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION);
|
||||
gatt_client_write_client_characteristic_configuration(handle_gatt_client_event, gc_handle, &config_characteristic, GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -272,7 +274,7 @@ static void hci_event_handler(uint8_t packet_type, uint16_t channel, uint8_t *pa
|
||||
// query primary services
|
||||
printf("\nSearch for battery service. ");
|
||||
state = TC_W4_SERVICE_RESULT;
|
||||
gatt_client_discover_primary_services_by_uuid16(gc_id, gc_handle, battery_service_uuid);
|
||||
gatt_client_discover_primary_services_by_uuid16(handle_gatt_client_event, gc_handle, battery_service_uuid);
|
||||
break;
|
||||
case HCI_EVENT_DISCONNECTION_COMPLETE:
|
||||
printf("\nDISCONNECTED\n");
|
||||
@ -311,7 +313,6 @@ int btstack_main(int argc, const char * argv[]){
|
||||
l2cap_init();
|
||||
|
||||
gatt_client_init();
|
||||
gc_id = gatt_client_register_packet_handler(&handle_gatt_client_event);
|
||||
|
||||
sm_init();
|
||||
sm_set_io_capabilities(IO_CAPABILITY_NO_INPUT_NO_OUTPUT);
|
||||
|
@ -102,7 +102,6 @@ static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||
*/
|
||||
|
||||
/* LISTING_START(GATTClientSetup): Setting up GATT client */
|
||||
static uint16_t gc_id;
|
||||
|
||||
// Handles connect, disconnect, and advertising report events,
|
||||
// starts the GATT client, and sends the first query.
|
||||
@ -110,7 +109,7 @@ static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *pac
|
||||
|
||||
// Handles GATT client query results, sends queries and the
|
||||
// GAP disconnect command when the querying is done.
|
||||
void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
||||
static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
||||
|
||||
static void gatt_client_setup(void){
|
||||
|
||||
@ -123,8 +122,6 @@ static void gatt_client_setup(void){
|
||||
|
||||
// Initialize GATT client
|
||||
gatt_client_init();
|
||||
// Register handler for GATT client events
|
||||
gc_id = gatt_client_register_packet_handler(&handle_gatt_client_event);
|
||||
|
||||
// Optinoally, Setup security manager
|
||||
sm_init();
|
||||
@ -214,7 +211,7 @@ static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *pac
|
||||
if (packet[2] != HCI_SUBEVENT_LE_CONNECTION_COMPLETE) break;
|
||||
gc_handle = little_endian_read_16(packet, 4);
|
||||
// query primary services
|
||||
gatt_client_discover_primary_services(gc_id, gc_handle);
|
||||
gatt_client_discover_primary_services(handle_gatt_client_event, gc_handle);
|
||||
break;
|
||||
case HCI_EVENT_DISCONNECTION_COMPLETE:
|
||||
printf("\nGATT browser - DISCONNECTED\n");
|
||||
@ -262,7 +259,7 @@ static void extract_characteristic(le_characteristic_t * characteristic, uint8_t
|
||||
}
|
||||
}
|
||||
|
||||
void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||
static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||
le_service_t service;
|
||||
le_characteristic_t characteristic;
|
||||
switch(packet[0]){
|
||||
@ -281,14 +278,14 @@ void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint8_t *pa
|
||||
service_index = 0;
|
||||
printf("\nGATT browser - CHARACTERISTIC for SERVICE %s\n", uuid128_to_str(service.uuid128));
|
||||
search_services = 0;
|
||||
gatt_client_discover_characteristics_for_service(gc_id, gc_handle, &services[service_index]);
|
||||
gatt_client_discover_characteristics_for_service(handle_gatt_client_event, gc_handle, &services[service_index]);
|
||||
} else {
|
||||
// GATT_EVENT_QUERY_COMPLETE of search characteristics
|
||||
if (service_index < service_count) {
|
||||
service = services[service_index++];
|
||||
printf("\nGATT browser - CHARACTERISTIC for SERVICE %s, [0x%04x-0x%04x]\n",
|
||||
uuid128_to_str(service.uuid128), service.start_group_handle, service.end_group_handle);
|
||||
gatt_client_discover_characteristics_for_service(gc_id, gc_handle, &service);
|
||||
gatt_client_discover_characteristics_for_service(handle_gatt_client_event, gc_handle, &service);
|
||||
break;
|
||||
}
|
||||
service_index = 0;
|
||||
|
@ -87,7 +87,8 @@ static const uint8_t ancs_control_point_uuid[] = {0x69,0xD1,0xD8,0xF3,0x45
|
||||
static const uint8_t ancs_data_source_uuid[] = {0x22,0xEA,0xC6,0xE9,0x24,0xD6,0x4B,0xB5,0xBE,0x44,0xB3,0x6A,0xCE,0x7C,0x7B,0xFB};
|
||||
|
||||
static uint32_t ancs_notification_uid;
|
||||
static uint16_t gc_handle, gc_id;
|
||||
static uint16_t gc_handle;
|
||||
static gatt_client_notification_t client_notification;
|
||||
static int ancs_service_found;
|
||||
static le_service_t ancs_service;
|
||||
static le_characteristic_t ancs_notification_source_characteristic;
|
||||
@ -227,7 +228,7 @@ static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *pac
|
||||
// let's start
|
||||
printf("\nANCS Client - CONNECTED, discover ANCS service\n");
|
||||
tc_state = TC_W4_SERVICE_RESULT;
|
||||
gatt_client_discover_primary_services_by_uuid128(gc_id, gc_handle, ancs_service_uuid);
|
||||
gatt_client_discover_primary_services_by_uuid128(handle_hci_event, gc_handle, ancs_service_uuid);
|
||||
return;
|
||||
|
||||
case HCI_EVENT_DISCONNECTION_COMPLETE:
|
||||
@ -258,7 +259,7 @@ static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *pac
|
||||
}
|
||||
tc_state = TC_W4_CHARACTERISTIC_RESULT;
|
||||
printf("ANCS Client - Discover characteristics for ANCS SERVICE \n");
|
||||
gatt_client_discover_characteristics_for_service(gc_id, gc_handle, &ancs_service);
|
||||
gatt_client_discover_characteristics_for_service(handle_hci_event, gc_handle, &ancs_service);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -291,7 +292,7 @@ static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *pac
|
||||
case GATT_EVENT_QUERY_COMPLETE:
|
||||
printf("ANCS Characteristcs count %u\n", ancs_characteristcs);
|
||||
tc_state = TC_W4_NOTIFICATION_SOURCE_SUBSCRIBED;
|
||||
gatt_client_write_client_characteristic_configuration(gc_id, gc_handle, &ancs_notification_source_characteristic,
|
||||
gatt_client_write_client_characteristic_configuration(handle_hci_event, gc_handle, &ancs_notification_source_characteristic,
|
||||
GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION);
|
||||
break;
|
||||
default:
|
||||
@ -303,7 +304,8 @@ static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *pac
|
||||
case GATT_EVENT_QUERY_COMPLETE:
|
||||
printf("ANCS Notification Source subscribed\n");
|
||||
tc_state = TC_W4_DATA_SOURCE_SUBSCRIBED;
|
||||
gatt_client_write_client_characteristic_configuration(gc_id, gc_handle, &ancs_data_source_characteristic,
|
||||
gatt_client_listen_for_characteristic_value_updates(&client_notification, gc_handle, &ancs_data_source_characteristic);
|
||||
gatt_client_write_client_characteristic_configuration(handle_hci_event, gc_handle, &ancs_data_source_characteristic,
|
||||
GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION);
|
||||
break;
|
||||
default:
|
||||
@ -341,7 +343,7 @@ static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *pac
|
||||
little_endian_store_32(get_notification_attributes, 1, ancs_notification_uid);
|
||||
ancs_notification_uid = 0;
|
||||
ancs_chunk_parser_init();
|
||||
gatt_client_write_value_of_characteristic(gc_id, gc_handle, ancs_control_point_characteristic.value_handle,
|
||||
gatt_client_write_value_of_characteristic(handle_hci_event, gc_handle, ancs_control_point_characteristic.value_handle,
|
||||
sizeof(get_notification_attributes), get_notification_attributes);
|
||||
} else {
|
||||
printf("Unknown Source: ");
|
||||
@ -357,6 +359,4 @@ static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *pac
|
||||
void ancs_client_init(void){
|
||||
hci_event_callback_registration.callback = &handle_hci_event;
|
||||
hci_add_event_handler(&hci_event_callback_registration);
|
||||
|
||||
gc_id = gatt_client_register_packet_handler(&handle_hci_event);
|
||||
}
|
||||
|
@ -59,11 +59,10 @@
|
||||
#include "ble/sm.h"
|
||||
#include "ble/le_device_db.h"
|
||||
|
||||
static btstack_linked_list_t gatt_client_connections = NULL;
|
||||
static btstack_linked_list_t gatt_subclients = NULL;
|
||||
static uint16_t next_gatt_client_id = 0;
|
||||
static uint8_t pts_suppress_mtu_exchange;
|
||||
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 uint8_t pts_suppress_mtu_exchange;
|
||||
|
||||
static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle, uint8_t *packet, uint16_t size);
|
||||
static void gatt_client_hci_event_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
||||
@ -78,57 +77,6 @@ static uint16_t peripheral_mtu(gatt_client_t *peripheral){
|
||||
return peripheral->mtu;
|
||||
}
|
||||
|
||||
static uint16_t gatt_client_next_id(void){
|
||||
if (next_gatt_client_id < 0xFFFF) {
|
||||
next_gatt_client_id++;
|
||||
} else {
|
||||
next_gatt_client_id = 1;
|
||||
}
|
||||
return next_gatt_client_id;
|
||||
}
|
||||
|
||||
static btstack_packet_handler_t gatt_client_callback_for_id_new(uint16_t id){
|
||||
btstack_linked_list_iterator_t it;
|
||||
btstack_linked_list_iterator_init(&it, &gatt_subclients);
|
||||
while (btstack_linked_list_iterator_has_next(&it)){
|
||||
gatt_subclient_t * item = (gatt_subclient_t*) btstack_linked_list_iterator_next(&it);
|
||||
if ( item->id != id) continue;
|
||||
return item->callback;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint16_t gatt_client_register_packet_handler(btstack_packet_handler_t gatt_callback){
|
||||
if (gatt_callback == NULL){
|
||||
log_error("gatt_client_register_packet_handler called with NULL callback");
|
||||
return 0;
|
||||
}
|
||||
|
||||
gatt_subclient_t * subclient = btstack_memory_gatt_subclient_get();
|
||||
if (!subclient) {
|
||||
log_error("gatt_client_register_packet_handler failed (no memory)");
|
||||
return 0;
|
||||
}
|
||||
|
||||
subclient->id = gatt_client_next_id();
|
||||
subclient->callback = gatt_callback;
|
||||
btstack_linked_list_add(&gatt_subclients, (btstack_linked_item_t *) subclient);
|
||||
log_info("gatt_client_register_packet_handler with new id %u", subclient->id);
|
||||
|
||||
return subclient->id;
|
||||
}
|
||||
|
||||
void gatt_client_unregister_packet_handler(uint16_t gatt_client_id){
|
||||
btstack_linked_list_iterator_t it;
|
||||
btstack_linked_list_iterator_init(&it, &gatt_subclients);
|
||||
while (btstack_linked_list_iterator_has_next(&it)){
|
||||
gatt_subclient_t * subclient = (gatt_subclient_t*) btstack_linked_list_iterator_next(&it);
|
||||
if ( subclient->id != gatt_client_id) continue;
|
||||
btstack_linked_list_remove(&gatt_subclients, (btstack_linked_item_t *) subclient);
|
||||
btstack_memory_gatt_subclient_free(subclient);
|
||||
}
|
||||
}
|
||||
|
||||
void gatt_client_init(void){
|
||||
gatt_client_connections = NULL;
|
||||
pts_suppress_mtu_exchange = 0;
|
||||
@ -499,18 +447,31 @@ static void gatt_client_handle_transaction_complete(gatt_client_t * peripheral){
|
||||
gatt_client_timeout_stop(peripheral);
|
||||
}
|
||||
|
||||
static void emit_event_new(uint16_t gatt_client_id, uint8_t * packet, uint16_t size){
|
||||
btstack_packet_handler_t gatt_client_callback = gatt_client_callback_for_id_new(gatt_client_id);
|
||||
if (!gatt_client_callback) return;
|
||||
(*gatt_client_callback)(HCI_EVENT_PACKET, 0, packet, size);
|
||||
static void emit_event_new(btstack_packet_handler_t callback, uint8_t * packet, uint16_t size){
|
||||
if (!callback) return;
|
||||
(*callback)(HCI_EVENT_PACKET, 0, packet, size);
|
||||
}
|
||||
|
||||
static void emit_event_to_all_subclients_new(uint8_t * packet, uint16_t size){
|
||||
/**
|
||||
* @brief Register for notifications and indications of a characteristic enabled by gatt_client_write_client_characteristic_configuration
|
||||
* @param notification struct used to store registration
|
||||
* @param con_handle
|
||||
* @param characteristic
|
||||
*/
|
||||
void gatt_client_listen_for_characteristic_value_updates(gatt_client_notification_t * notification, uint16_t con_handle, le_characteristic_t * characteristic){
|
||||
notification->con_handle = con_handle;
|
||||
notification->attribute_handle = characteristic->value_handle;
|
||||
btstack_linked_list_add(&gatt_client_value_listeners, (btstack_linked_item_t*) notification);
|
||||
}
|
||||
|
||||
static void emit_event_to_registered_listeners(uint16_t con_handle, uint16_t attribute_handle, uint8_t * packet, uint16_t size){
|
||||
btstack_linked_list_iterator_t it;
|
||||
btstack_linked_list_iterator_init(&it, &gatt_subclients);
|
||||
btstack_linked_list_iterator_init(&it, &gatt_client_value_listeners);
|
||||
while (btstack_linked_list_iterator_has_next(&it)){
|
||||
gatt_subclient_t * subclient = (gatt_subclient_t*) btstack_linked_list_iterator_next(&it);
|
||||
(*subclient->callback)(HCI_EVENT_PACKET, 0, packet, size);
|
||||
gatt_client_notification_t * registration = (gatt_client_notification_t*) btstack_linked_list_iterator_next(&it);
|
||||
if (registration->con_handle != con_handle) continue;
|
||||
if (registration->attribute_handle != attribute_handle) continue;
|
||||
(*registration->callback)(HCI_EVENT_PACKET, 0, packet, size);
|
||||
}
|
||||
}
|
||||
|
||||
@ -521,7 +482,7 @@ static void emit_gatt_complete_event(gatt_client_t * peripheral, uint8_t status)
|
||||
packet[1] = 3;
|
||||
little_endian_store_16(packet, 2, peripheral->handle);
|
||||
packet[4] = status;
|
||||
emit_event_new(peripheral->subclient_id, packet, sizeof(packet));
|
||||
emit_event_new(peripheral->callback, packet, sizeof(packet));
|
||||
}
|
||||
|
||||
static void emit_gatt_service_query_result_event(gatt_client_t * peripheral, uint16_t start_group_handle, uint16_t end_group_handle, uint8_t * uuid128){
|
||||
@ -534,7 +495,7 @@ static void emit_gatt_service_query_result_event(gatt_client_t * peripheral, uin
|
||||
little_endian_store_16(packet, 4, start_group_handle);
|
||||
little_endian_store_16(packet, 6, end_group_handle);
|
||||
reverse_128(uuid128, &packet[8]);
|
||||
emit_event_new(peripheral->subclient_id, packet, sizeof(packet));
|
||||
emit_event_new(peripheral->callback, packet, sizeof(packet));
|
||||
}
|
||||
|
||||
static void emit_gatt_included_service_query_result_event(gatt_client_t * peripheral, uint16_t include_handle, uint16_t start_group_handle, uint16_t end_group_handle, uint8_t * uuid128){
|
||||
@ -549,7 +510,7 @@ static void emit_gatt_included_service_query_result_event(gatt_client_t * periph
|
||||
little_endian_store_16(packet, 6, start_group_handle);
|
||||
little_endian_store_16(packet, 8, end_group_handle);
|
||||
reverse_128(uuid128, &packet[10]);
|
||||
emit_event_new(peripheral->subclient_id, packet, sizeof(packet));
|
||||
emit_event_new(peripheral->callback, packet, sizeof(packet));
|
||||
}
|
||||
|
||||
static void emit_gatt_characteristic_query_result_event(gatt_client_t * peripheral, uint16_t start_handle, uint16_t value_handle, uint16_t end_handle,
|
||||
@ -565,7 +526,7 @@ static void emit_gatt_characteristic_query_result_event(gatt_client_t * peripher
|
||||
little_endian_store_16(packet, 8, end_handle);
|
||||
little_endian_store_16(packet, 10, properties);
|
||||
reverse_128(uuid128, &packet[12]);
|
||||
emit_event_new(peripheral->subclient_id, packet, sizeof(packet));
|
||||
emit_event_new(peripheral->callback, packet, sizeof(packet));
|
||||
}
|
||||
|
||||
static void emit_gatt_all_characteristic_descriptors_result_event(
|
||||
@ -578,7 +539,7 @@ static void emit_gatt_all_characteristic_descriptors_result_event(
|
||||
///
|
||||
little_endian_store_16(packet, 4, descriptor_handle);
|
||||
reverse_128(uuid128, &packet[6]);
|
||||
emit_event_new(peripheral->subclient_id, packet, sizeof(packet));
|
||||
emit_event_new(peripheral->callback, packet, sizeof(packet));
|
||||
}
|
||||
///
|
||||
|
||||
@ -701,37 +662,37 @@ static uint8_t * setup_long_characteristic_value_packet(uint8_t type, uint16_t c
|
||||
// @note assume that value is part of an l2cap buffer - overwrite parts of the HCI/L2CAP/ATT packet (4/4/3) bytes
|
||||
static void report_gatt_notification(uint16_t con_handle, uint16_t value_handle, uint8_t * value, int length){
|
||||
uint8_t * packet = setup_characteristic_value_packet(GATT_EVENT_NOTIFICATION, con_handle, value_handle, value, length);
|
||||
emit_event_to_all_subclients_new(packet, characteristic_value_event_header_size + length);
|
||||
emit_event_to_registered_listeners(con_handle, value_handle, packet, characteristic_value_event_header_size + length);
|
||||
}
|
||||
|
||||
// @note assume that value is part of an l2cap buffer - overwrite parts of the HCI/L2CAP/ATT packet (4/4/3) bytes
|
||||
static void report_gatt_indication(uint16_t con_handle, uint16_t value_handle, uint8_t * value, int length){
|
||||
uint8_t * packet = setup_characteristic_value_packet(GATT_EVENT_INDICATION, con_handle, value_handle, value, length);
|
||||
emit_event_to_all_subclients_new(packet, characteristic_value_event_header_size + length);
|
||||
emit_event_to_registered_listeners(con_handle, value_handle, packet, characteristic_value_event_header_size + length);
|
||||
}
|
||||
|
||||
// @note assume that value is part of an l2cap buffer - overwrite parts of the HCI/L2CAP/ATT packet (4/4/3) bytes
|
||||
static void report_gatt_characteristic_value(gatt_client_t * peripheral, uint16_t attribute_handle, uint8_t * value, uint16_t length){
|
||||
uint8_t * packet = setup_characteristic_value_packet(GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT, peripheral->handle, attribute_handle, value, length);
|
||||
emit_event_new(peripheral->subclient_id, packet, characteristic_value_event_header_size + length);
|
||||
emit_event_new(peripheral->callback, packet, characteristic_value_event_header_size + length);
|
||||
}
|
||||
|
||||
// @note assume that value is part of an l2cap buffer - overwrite parts of the HCI/L2CAP/ATT packet (4/4/3) bytes
|
||||
static void report_gatt_long_characteristic_value_blob(gatt_client_t * peripheral, uint16_t attribute_handle, uint8_t * blob, uint16_t blob_length, int value_offset){
|
||||
uint8_t * packet = setup_long_characteristic_value_packet(GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT, peripheral->handle, attribute_handle, value_offset, blob, blob_length);
|
||||
if (!packet) return;
|
||||
emit_event_new(peripheral->subclient_id, packet, blob_length + long_characteristic_value_event_header_size);
|
||||
emit_event_new(peripheral->callback, packet, blob_length + long_characteristic_value_event_header_size);
|
||||
}
|
||||
|
||||
static void report_gatt_characteristic_descriptor(gatt_client_t * peripheral, uint16_t descriptor_handle, uint8_t *value, uint16_t value_length, uint16_t value_offset){
|
||||
uint8_t * packet = setup_characteristic_value_packet(GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT, peripheral->handle, descriptor_handle, value, value_length);
|
||||
emit_event_new(peripheral->subclient_id, packet, value_length + 8);
|
||||
emit_event_new(peripheral->callback, packet, value_length + 8);
|
||||
}
|
||||
|
||||
static void report_gatt_long_characteristic_descriptor(gatt_client_t * peripheral, uint16_t descriptor_handle, uint8_t *blob, uint16_t blob_length, uint16_t value_offset){
|
||||
uint8_t * packet = setup_long_characteristic_value_packet(GATT_EVENT_LONG_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT, peripheral->handle, descriptor_handle, value_offset, blob, blob_length);
|
||||
if (!packet) return;
|
||||
emit_event_new(peripheral->subclient_id, packet, blob_length + long_characteristic_value_event_header_size);
|
||||
emit_event_new(peripheral->callback, packet, blob_length + long_characteristic_value_event_header_size);
|
||||
}
|
||||
|
||||
static void report_gatt_all_characteristic_descriptors(gatt_client_t * peripheral, uint8_t * packet, uint16_t size, uint16_t pair_size){
|
||||
@ -1393,13 +1354,13 @@ static void att_signed_write_handle_cmac_result(uint8_t hash[8]){
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t gatt_client_signed_write_without_response(uint16_t gatt_client_id, uint16_t con_handle, uint16_t handle, uint16_t message_len, uint8_t * message){
|
||||
uint8_t gatt_client_signed_write_without_response(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t handle, uint16_t message_len, uint8_t * message){
|
||||
gatt_client_t * peripheral = provide_context_for_conn_handle(con_handle);
|
||||
if (!is_ready(peripheral)) return GATT_CLIENT_IN_WRONG_STATE;
|
||||
peripheral->le_device_index = sm_le_device_index(con_handle);
|
||||
if (peripheral->le_device_index < 0) return GATT_CLIENT_IN_WRONG_STATE; // device lookup not done / no stored bonding information
|
||||
|
||||
peripheral->subclient_id = gatt_client_id;
|
||||
peripheral->callback = callback;
|
||||
peripheral->attribute_handle = handle;
|
||||
peripheral->attribute_length = message_len;
|
||||
peripheral->attribute_value = message;
|
||||
@ -1409,12 +1370,12 @@ uint8_t gatt_client_signed_write_without_response(uint16_t gatt_client_id, uint1
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t gatt_client_discover_primary_services(uint16_t gatt_client_id, uint16_t con_handle){
|
||||
uint8_t gatt_client_discover_primary_services(btstack_packet_handler_t callback, uint16_t con_handle){
|
||||
gatt_client_t * peripheral = provide_context_for_conn_handle_and_start_timer(con_handle);
|
||||
if (!peripheral) return BTSTACK_MEMORY_ALLOC_FAILED;
|
||||
if (!is_ready(peripheral)) return GATT_CLIENT_IN_WRONG_STATE;
|
||||
|
||||
peripheral->subclient_id = gatt_client_id;
|
||||
peripheral->callback = callback;
|
||||
peripheral->start_group_handle = 0x0001;
|
||||
peripheral->end_group_handle = 0xffff;
|
||||
peripheral->gatt_client_state = P_W2_SEND_SERVICE_QUERY;
|
||||
@ -1424,13 +1385,13 @@ uint8_t gatt_client_discover_primary_services(uint16_t gatt_client_id, uint16_t
|
||||
}
|
||||
|
||||
|
||||
uint8_t gatt_client_discover_primary_services_by_uuid16(uint16_t gatt_client_id, uint16_t con_handle, uint16_t uuid16){
|
||||
uint8_t gatt_client_discover_primary_services_by_uuid16(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t uuid16){
|
||||
gatt_client_t * peripheral = provide_context_for_conn_handle_and_start_timer(con_handle);
|
||||
|
||||
if (!peripheral) return BTSTACK_MEMORY_ALLOC_FAILED;
|
||||
if (!is_ready(peripheral)) return GATT_CLIENT_IN_WRONG_STATE;
|
||||
|
||||
peripheral->subclient_id = gatt_client_id;
|
||||
peripheral->callback = callback;
|
||||
peripheral->start_group_handle = 0x0001;
|
||||
peripheral->end_group_handle = 0xffff;
|
||||
peripheral->gatt_client_state = P_W2_SEND_SERVICE_WITH_UUID_QUERY;
|
||||
@ -1440,13 +1401,13 @@ uint8_t gatt_client_discover_primary_services_by_uuid16(uint16_t gatt_client_id,
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t gatt_client_discover_primary_services_by_uuid128(uint16_t gatt_client_id, uint16_t con_handle, const uint8_t * uuid128){
|
||||
uint8_t gatt_client_discover_primary_services_by_uuid128(btstack_packet_handler_t callback, uint16_t con_handle, const uint8_t * uuid128){
|
||||
gatt_client_t * peripheral = provide_context_for_conn_handle_and_start_timer(con_handle);
|
||||
|
||||
if (!peripheral) return BTSTACK_MEMORY_ALLOC_FAILED;
|
||||
if (!is_ready(peripheral)) return GATT_CLIENT_IN_WRONG_STATE;
|
||||
|
||||
peripheral->subclient_id = gatt_client_id;
|
||||
peripheral->callback = callback;
|
||||
peripheral->start_group_handle = 0x0001;
|
||||
peripheral->end_group_handle = 0xffff;
|
||||
peripheral->uuid16 = 0;
|
||||
@ -1456,13 +1417,13 @@ uint8_t gatt_client_discover_primary_services_by_uuid128(uint16_t gatt_client_id
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t gatt_client_discover_characteristics_for_service(uint16_t gatt_client_id, uint16_t con_handle, le_service_t *service){
|
||||
uint8_t gatt_client_discover_characteristics_for_service(btstack_packet_handler_t callback, uint16_t con_handle, le_service_t *service){
|
||||
gatt_client_t * peripheral = provide_context_for_conn_handle_and_start_timer(con_handle);
|
||||
|
||||
if (!peripheral) return BTSTACK_MEMORY_ALLOC_FAILED;
|
||||
if (!is_ready(peripheral)) return GATT_CLIENT_IN_WRONG_STATE;
|
||||
|
||||
peripheral->subclient_id = gatt_client_id;
|
||||
peripheral->callback = callback;
|
||||
peripheral->start_group_handle = service->start_group_handle;
|
||||
peripheral->end_group_handle = service->end_group_handle;
|
||||
peripheral->filter_with_uuid = 0;
|
||||
@ -1472,13 +1433,13 @@ uint8_t gatt_client_discover_characteristics_for_service(uint16_t gatt_client_id
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t gatt_client_find_included_services_for_service(uint16_t gatt_client_id, uint16_t con_handle, le_service_t *service){
|
||||
uint8_t gatt_client_find_included_services_for_service(btstack_packet_handler_t callback, uint16_t con_handle, le_service_t *service){
|
||||
gatt_client_t * peripheral = provide_context_for_conn_handle_and_start_timer(con_handle);
|
||||
|
||||
if (!peripheral) return BTSTACK_MEMORY_ALLOC_FAILED;
|
||||
if (!is_ready(peripheral)) return GATT_CLIENT_IN_WRONG_STATE;
|
||||
|
||||
peripheral->subclient_id = gatt_client_id;
|
||||
peripheral->callback = callback;
|
||||
peripheral->start_group_handle = service->start_group_handle;
|
||||
peripheral->end_group_handle = service->end_group_handle;
|
||||
peripheral->gatt_client_state = P_W2_SEND_INCLUDED_SERVICE_QUERY;
|
||||
@ -1487,13 +1448,13 @@ uint8_t gatt_client_find_included_services_for_service(uint16_t gatt_client_id,
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t gatt_client_discover_characteristics_for_handle_range_by_uuid16(uint16_t gatt_client_id, uint16_t con_handle, uint16_t start_handle, uint16_t end_handle, uint16_t uuid16){
|
||||
uint8_t gatt_client_discover_characteristics_for_handle_range_by_uuid16(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t start_handle, uint16_t end_handle, uint16_t uuid16){
|
||||
gatt_client_t * peripheral = provide_context_for_conn_handle_and_start_timer(con_handle);
|
||||
|
||||
if (!peripheral) return BTSTACK_MEMORY_ALLOC_FAILED;
|
||||
if (!is_ready(peripheral)) return GATT_CLIENT_IN_WRONG_STATE;
|
||||
|
||||
peripheral->subclient_id = gatt_client_id;
|
||||
peripheral->callback = callback;
|
||||
peripheral->start_group_handle = start_handle;
|
||||
peripheral->end_group_handle = end_handle;
|
||||
peripheral->filter_with_uuid = 1;
|
||||
@ -1506,13 +1467,13 @@ uint8_t gatt_client_discover_characteristics_for_handle_range_by_uuid16(uint16_t
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t gatt_client_discover_characteristics_for_handle_range_by_uuid128(uint16_t gatt_client_id, uint16_t con_handle, uint16_t start_handle, uint16_t end_handle, uint8_t * uuid128){
|
||||
uint8_t gatt_client_discover_characteristics_for_handle_range_by_uuid128(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t start_handle, uint16_t end_handle, uint8_t * uuid128){
|
||||
gatt_client_t * peripheral = provide_context_for_conn_handle_and_start_timer(con_handle);
|
||||
|
||||
if (!peripheral) return BTSTACK_MEMORY_ALLOC_FAILED;
|
||||
if (!is_ready(peripheral)) return GATT_CLIENT_IN_WRONG_STATE;
|
||||
|
||||
peripheral->subclient_id = gatt_client_id;
|
||||
peripheral->callback = callback;
|
||||
peripheral->start_group_handle = start_handle;
|
||||
peripheral->end_group_handle = end_handle;
|
||||
peripheral->filter_with_uuid = 1;
|
||||
@ -1526,15 +1487,15 @@ uint8_t gatt_client_discover_characteristics_for_handle_range_by_uuid128(uint16_
|
||||
}
|
||||
|
||||
|
||||
uint8_t gatt_client_discover_characteristics_for_service_by_uuid16(uint16_t gatt_client_id, uint16_t handle, le_service_t *service, uint16_t uuid16){
|
||||
return gatt_client_discover_characteristics_for_handle_range_by_uuid16(gatt_client_id, handle, service->start_group_handle, service->end_group_handle, uuid16);
|
||||
uint8_t gatt_client_discover_characteristics_for_service_by_uuid16(btstack_packet_handler_t callback, uint16_t handle, le_service_t *service, uint16_t uuid16){
|
||||
return gatt_client_discover_characteristics_for_handle_range_by_uuid16(callback, handle, service->start_group_handle, service->end_group_handle, uuid16);
|
||||
}
|
||||
|
||||
uint8_t gatt_client_discover_characteristics_for_service_by_uuid128(uint16_t gatt_client_id, uint16_t handle, le_service_t *service, uint8_t * uuid128){
|
||||
return gatt_client_discover_characteristics_for_handle_range_by_uuid128(gatt_client_id, handle, service->start_group_handle, service->end_group_handle, uuid128);
|
||||
uint8_t gatt_client_discover_characteristics_for_service_by_uuid128(btstack_packet_handler_t callback, uint16_t handle, le_service_t *service, uint8_t * uuid128){
|
||||
return gatt_client_discover_characteristics_for_handle_range_by_uuid128(callback, handle, service->start_group_handle, service->end_group_handle, uuid128);
|
||||
}
|
||||
|
||||
uint8_t gatt_client_discover_characteristic_descriptors(uint16_t gatt_client_id, uint16_t con_handle, le_characteristic_t *characteristic){
|
||||
uint8_t gatt_client_discover_characteristic_descriptors(btstack_packet_handler_t callback, uint16_t con_handle, le_characteristic_t *characteristic){
|
||||
gatt_client_t * peripheral = provide_context_for_conn_handle_and_start_timer(con_handle);
|
||||
|
||||
if (!peripheral) return BTSTACK_MEMORY_ALLOC_FAILED;
|
||||
@ -1544,7 +1505,7 @@ uint8_t gatt_client_discover_characteristic_descriptors(uint16_t gatt_client_id,
|
||||
emit_gatt_complete_event(peripheral, 0);
|
||||
return 0;
|
||||
}
|
||||
peripheral->subclient_id = gatt_client_id;
|
||||
peripheral->callback = callback;
|
||||
peripheral->start_group_handle = characteristic->value_handle + 1;
|
||||
peripheral->end_group_handle = characteristic->end_handle;
|
||||
peripheral->gatt_client_state = P_W2_SEND_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY;
|
||||
@ -1553,13 +1514,13 @@ uint8_t gatt_client_discover_characteristic_descriptors(uint16_t gatt_client_id,
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t gatt_client_read_value_of_characteristic_using_value_handle(uint16_t gatt_client_id, uint16_t con_handle, uint16_t value_handle){
|
||||
uint8_t gatt_client_read_value_of_characteristic_using_value_handle(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t value_handle){
|
||||
gatt_client_t * peripheral = provide_context_for_conn_handle_and_start_timer(con_handle);
|
||||
|
||||
if (!peripheral) return BTSTACK_MEMORY_ALLOC_FAILED;
|
||||
if (!is_ready(peripheral)) return GATT_CLIENT_IN_WRONG_STATE;
|
||||
|
||||
peripheral->subclient_id = gatt_client_id;
|
||||
peripheral->callback = callback;
|
||||
peripheral->attribute_handle = value_handle;
|
||||
peripheral->attribute_offset = 0;
|
||||
peripheral->gatt_client_state = P_W2_SEND_READ_CHARACTERISTIC_VALUE_QUERY;
|
||||
@ -1567,13 +1528,13 @@ uint8_t gatt_client_read_value_of_characteristic_using_value_handle(uint16_t gat
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t gatt_client_read_value_of_characteristics_by_uuid16(uint16_t gatt_client_id, uint16_t con_handle, uint16_t start_handle, uint16_t end_handle, uint16_t uuid16){
|
||||
uint8_t gatt_client_read_value_of_characteristics_by_uuid16(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t start_handle, uint16_t end_handle, uint16_t uuid16){
|
||||
gatt_client_t * peripheral = provide_context_for_conn_handle_and_start_timer(con_handle);
|
||||
|
||||
if (!peripheral) return BTSTACK_MEMORY_ALLOC_FAILED;
|
||||
if (!is_ready(peripheral)) return GATT_CLIENT_IN_WRONG_STATE;
|
||||
|
||||
peripheral->subclient_id = gatt_client_id;
|
||||
peripheral->callback = callback;
|
||||
peripheral->start_group_handle = start_handle;
|
||||
peripheral->end_group_handle = end_handle;
|
||||
peripheral->query_start_handle = start_handle;
|
||||
@ -1585,13 +1546,13 @@ uint8_t gatt_client_read_value_of_characteristics_by_uuid16(uint16_t gatt_client
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t gatt_client_read_value_of_characteristics_by_uuid128(uint16_t gatt_client_id, uint16_t con_handle, uint16_t start_handle, uint16_t end_handle, uint8_t * uuid128){
|
||||
uint8_t gatt_client_read_value_of_characteristics_by_uuid128(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t start_handle, uint16_t end_handle, uint8_t * uuid128){
|
||||
gatt_client_t * peripheral = provide_context_for_conn_handle_and_start_timer(con_handle);
|
||||
|
||||
if (!peripheral) return BTSTACK_MEMORY_ALLOC_FAILED;
|
||||
if (!is_ready(peripheral)) return GATT_CLIENT_IN_WRONG_STATE;
|
||||
|
||||
peripheral->subclient_id = gatt_client_id;
|
||||
peripheral->callback = callback;
|
||||
peripheral->start_group_handle = start_handle;
|
||||
peripheral->end_group_handle = end_handle;
|
||||
peripheral->query_start_handle = start_handle;
|
||||
@ -1604,17 +1565,17 @@ uint8_t gatt_client_read_value_of_characteristics_by_uuid128(uint16_t gatt_clien
|
||||
}
|
||||
|
||||
|
||||
uint8_t gatt_client_read_value_of_characteristic(uint16_t gatt_client_id, uint16_t handle, le_characteristic_t *characteristic){
|
||||
return gatt_client_read_value_of_characteristic_using_value_handle(gatt_client_id, handle, characteristic->value_handle);
|
||||
uint8_t gatt_client_read_value_of_characteristic(btstack_packet_handler_t callback, uint16_t handle, le_characteristic_t *characteristic){
|
||||
return gatt_client_read_value_of_characteristic_using_value_handle(callback, handle, characteristic->value_handle);
|
||||
}
|
||||
|
||||
uint8_t gatt_client_read_long_value_of_characteristic_using_value_handle_with_offset(uint16_t gatt_client_id, uint16_t con_handle, uint16_t characteristic_value_handle, uint16_t offset){
|
||||
uint8_t gatt_client_read_long_value_of_characteristic_using_value_handle_with_offset(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t characteristic_value_handle, uint16_t offset){
|
||||
gatt_client_t * peripheral = provide_context_for_conn_handle_and_start_timer(con_handle);
|
||||
|
||||
if (!peripheral) return BTSTACK_MEMORY_ALLOC_FAILED;
|
||||
if (!is_ready(peripheral)) return GATT_CLIENT_IN_WRONG_STATE;
|
||||
|
||||
peripheral->subclient_id = gatt_client_id;
|
||||
peripheral->callback = callback;
|
||||
peripheral->attribute_handle = characteristic_value_handle;
|
||||
peripheral->attribute_offset = offset;
|
||||
peripheral->gatt_client_state = P_W2_SEND_READ_BLOB_QUERY;
|
||||
@ -1622,21 +1583,21 @@ uint8_t gatt_client_read_long_value_of_characteristic_using_value_handle_with_of
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t gatt_client_read_long_value_of_characteristic_using_value_handle(uint16_t gatt_client_id, uint16_t con_handle, uint16_t characteristic_value_handle){
|
||||
return gatt_client_read_long_value_of_characteristic_using_value_handle_with_offset(gatt_client_id, con_handle, characteristic_value_handle, 0);
|
||||
uint8_t gatt_client_read_long_value_of_characteristic_using_value_handle(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t characteristic_value_handle){
|
||||
return gatt_client_read_long_value_of_characteristic_using_value_handle_with_offset(callback, con_handle, characteristic_value_handle, 0);
|
||||
}
|
||||
|
||||
uint8_t gatt_client_read_long_value_of_characteristic(uint16_t gatt_client_id, uint16_t handle, le_characteristic_t *characteristic){
|
||||
return gatt_client_read_long_value_of_characteristic_using_value_handle(gatt_client_id, handle, characteristic->value_handle);
|
||||
uint8_t gatt_client_read_long_value_of_characteristic(btstack_packet_handler_t callback, uint16_t handle, le_characteristic_t *characteristic){
|
||||
return gatt_client_read_long_value_of_characteristic_using_value_handle(callback, handle, characteristic->value_handle);
|
||||
}
|
||||
|
||||
uint8_t gatt_client_read_multiple_characteristic_values(uint16_t gatt_client_id, uint16_t con_handle, int num_value_handles, uint16_t * value_handles){
|
||||
uint8_t gatt_client_read_multiple_characteristic_values(btstack_packet_handler_t callback, uint16_t con_handle, int num_value_handles, uint16_t * value_handles){
|
||||
gatt_client_t * peripheral = provide_context_for_conn_handle_and_start_timer(con_handle);
|
||||
|
||||
if (!peripheral) return BTSTACK_MEMORY_ALLOC_FAILED;
|
||||
if (!is_ready(peripheral)) return GATT_CLIENT_IN_WRONG_STATE;
|
||||
|
||||
peripheral->subclient_id = gatt_client_id;
|
||||
peripheral->callback = callback;
|
||||
peripheral->read_multiple_handle_count = num_value_handles;
|
||||
peripheral->read_multiple_handles = value_handles;
|
||||
peripheral->gatt_client_state = P_W2_SEND_READ_MULTIPLE_REQUEST;
|
||||
@ -1644,7 +1605,7 @@ uint8_t gatt_client_read_multiple_characteristic_values(uint16_t gatt_client_id,
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t gatt_client_write_value_of_characteristic_without_response(uint16_t gatt_client_id, uint16_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t * value){
|
||||
uint8_t gatt_client_write_value_of_characteristic_without_response(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t * value){
|
||||
gatt_client_t * peripheral = provide_context_for_conn_handle(con_handle);
|
||||
|
||||
if (!peripheral) return BTSTACK_MEMORY_ALLOC_FAILED;
|
||||
@ -1653,18 +1614,18 @@ uint8_t gatt_client_write_value_of_characteristic_without_response(uint16_t gatt
|
||||
if (value_length > peripheral_mtu(peripheral) - 3) return GATT_CLIENT_VALUE_TOO_LONG;
|
||||
if (!att_dispatch_server_can_send_now(peripheral->handle)) return GATT_CLIENT_BUSY;
|
||||
|
||||
peripheral->subclient_id = gatt_client_id;
|
||||
peripheral->callback = callback;
|
||||
att_write_request(ATT_WRITE_COMMAND, peripheral->handle, value_handle, value_length, value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t gatt_client_write_value_of_characteristic(uint16_t gatt_client_id, uint16_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t * data){
|
||||
uint8_t gatt_client_write_value_of_characteristic(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t * data){
|
||||
gatt_client_t * peripheral = provide_context_for_conn_handle_and_start_timer(con_handle);
|
||||
|
||||
if (!peripheral) return BTSTACK_MEMORY_ALLOC_FAILED;
|
||||
if (!is_ready(peripheral)) return GATT_CLIENT_IN_WRONG_STATE;
|
||||
|
||||
peripheral->subclient_id = gatt_client_id;
|
||||
peripheral->callback = callback;
|
||||
peripheral->attribute_handle = value_handle;
|
||||
peripheral->attribute_length = value_length;
|
||||
peripheral->attribute_value = data;
|
||||
@ -1673,13 +1634,13 @@ uint8_t gatt_client_write_value_of_characteristic(uint16_t gatt_client_id, uint1
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t gatt_client_write_long_value_of_characteristic_with_offset(uint16_t gatt_client_id, uint16_t con_handle, uint16_t value_handle, uint16_t offset, uint16_t value_length, uint8_t * data){
|
||||
uint8_t gatt_client_write_long_value_of_characteristic_with_offset(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t value_handle, uint16_t offset, uint16_t value_length, uint8_t * data){
|
||||
gatt_client_t * peripheral = provide_context_for_conn_handle_and_start_timer(con_handle);
|
||||
|
||||
if (!peripheral) return BTSTACK_MEMORY_ALLOC_FAILED;
|
||||
if (!is_ready(peripheral)) return GATT_CLIENT_IN_WRONG_STATE;
|
||||
|
||||
peripheral->subclient_id = gatt_client_id;
|
||||
peripheral->callback = callback;
|
||||
peripheral->attribute_handle = value_handle;
|
||||
peripheral->attribute_length = value_length;
|
||||
peripheral->attribute_offset = offset;
|
||||
@ -1689,17 +1650,17 @@ uint8_t gatt_client_write_long_value_of_characteristic_with_offset(uint16_t gatt
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t gatt_client_write_long_value_of_characteristic(uint16_t gatt_client_id, uint16_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t * value){
|
||||
return gatt_client_write_long_value_of_characteristic_with_offset(gatt_client_id, con_handle, value_handle, 0, value_length, value);
|
||||
uint8_t gatt_client_write_long_value_of_characteristic(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t * value){
|
||||
return gatt_client_write_long_value_of_characteristic_with_offset(callback, con_handle, value_handle, 0, value_length, value);
|
||||
}
|
||||
|
||||
uint8_t gatt_client_reliable_write_long_value_of_characteristic(uint16_t gatt_client_id, uint16_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t * value){
|
||||
uint8_t gatt_client_reliable_write_long_value_of_characteristic(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t * value){
|
||||
gatt_client_t * peripheral = provide_context_for_conn_handle_and_start_timer(con_handle);
|
||||
|
||||
if (!peripheral) return BTSTACK_MEMORY_ALLOC_FAILED;
|
||||
if (!is_ready(peripheral)) return GATT_CLIENT_IN_WRONG_STATE;
|
||||
|
||||
peripheral->subclient_id = gatt_client_id;
|
||||
peripheral->callback = callback;
|
||||
peripheral->attribute_handle = value_handle;
|
||||
peripheral->attribute_length = value_length;
|
||||
peripheral->attribute_offset = 0;
|
||||
@ -1709,7 +1670,7 @@ uint8_t gatt_client_reliable_write_long_value_of_characteristic(uint16_t gatt_cl
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t gatt_client_write_client_characteristic_configuration(uint16_t gatt_client_id, uint16_t con_handle, le_characteristic_t * characteristic, uint16_t configuration){
|
||||
uint8_t gatt_client_write_client_characteristic_configuration(btstack_packet_handler_t callback, uint16_t con_handle, le_characteristic_t * characteristic, uint16_t configuration){
|
||||
gatt_client_t * peripheral = provide_context_for_conn_handle_and_start_timer(con_handle);
|
||||
|
||||
if (!peripheral) return BTSTACK_MEMORY_ALLOC_FAILED;
|
||||
@ -1725,7 +1686,7 @@ uint8_t gatt_client_write_client_characteristic_configuration(uint16_t gatt_clie
|
||||
return GATT_CLIENT_CHARACTERISTIC_INDICATION_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
peripheral->subclient_id = gatt_client_id;
|
||||
peripheral->callback = callback;
|
||||
peripheral->start_group_handle = characteristic->value_handle;
|
||||
peripheral->end_group_handle = characteristic->end_handle;
|
||||
little_endian_store_16(peripheral->client_characteristic_configuration_value, 0, configuration);
|
||||
@ -1735,13 +1696,13 @@ uint8_t gatt_client_write_client_characteristic_configuration(uint16_t gatt_clie
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t gatt_client_read_characteristic_descriptor_using_descriptor_handle(uint16_t gatt_client_id, uint16_t con_handle, uint16_t descriptor_handle){
|
||||
uint8_t gatt_client_read_characteristic_descriptor_using_descriptor_handle(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t descriptor_handle){
|
||||
gatt_client_t * peripheral = provide_context_for_conn_handle_and_start_timer(con_handle);
|
||||
|
||||
if (!peripheral) return BTSTACK_MEMORY_ALLOC_FAILED;
|
||||
if (!is_ready(peripheral)) return GATT_CLIENT_IN_WRONG_STATE;
|
||||
|
||||
peripheral->subclient_id = gatt_client_id;
|
||||
peripheral->callback = callback;
|
||||
peripheral->attribute_handle = descriptor_handle;
|
||||
|
||||
peripheral->gatt_client_state = P_W2_SEND_READ_CHARACTERISTIC_DESCRIPTOR_QUERY;
|
||||
@ -1749,17 +1710,17 @@ uint8_t gatt_client_read_characteristic_descriptor_using_descriptor_handle(uint1
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t gatt_client_read_characteristic_descriptor(uint16_t gatt_client_id, uint16_t con_handle, le_characteristic_descriptor_t * descriptor){
|
||||
return gatt_client_read_characteristic_descriptor_using_descriptor_handle(gatt_client_id, con_handle, descriptor->handle);
|
||||
uint8_t gatt_client_read_characteristic_descriptor(btstack_packet_handler_t callback, uint16_t con_handle, le_characteristic_descriptor_t * descriptor){
|
||||
return gatt_client_read_characteristic_descriptor_using_descriptor_handle(callback, con_handle, descriptor->handle);
|
||||
}
|
||||
|
||||
uint8_t gatt_client_read_long_characteristic_descriptor_using_descriptor_handle_with_offset(uint16_t gatt_client_id, uint16_t con_handle, uint16_t descriptor_handle, uint16_t offset){
|
||||
uint8_t gatt_client_read_long_characteristic_descriptor_using_descriptor_handle_with_offset(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t descriptor_handle, uint16_t offset){
|
||||
gatt_client_t * peripheral = provide_context_for_conn_handle_and_start_timer(con_handle);
|
||||
|
||||
if (!peripheral) return BTSTACK_MEMORY_ALLOC_FAILED;
|
||||
if (!is_ready(peripheral)) return GATT_CLIENT_IN_WRONG_STATE;
|
||||
|
||||
peripheral->subclient_id = gatt_client_id;
|
||||
peripheral->callback = callback;
|
||||
peripheral->attribute_handle = descriptor_handle;
|
||||
peripheral->attribute_offset = offset;
|
||||
peripheral->gatt_client_state = P_W2_SEND_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_QUERY;
|
||||
@ -1767,21 +1728,21 @@ uint8_t gatt_client_read_long_characteristic_descriptor_using_descriptor_handle_
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t gatt_client_read_long_characteristic_descriptor_using_descriptor_handle(uint16_t gatt_client_id, uint16_t con_handle, uint16_t descriptor_handle){
|
||||
return gatt_client_read_long_characteristic_descriptor_using_descriptor_handle_with_offset(gatt_client_id, con_handle, descriptor_handle, 0);
|
||||
uint8_t gatt_client_read_long_characteristic_descriptor_using_descriptor_handle(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t descriptor_handle){
|
||||
return gatt_client_read_long_characteristic_descriptor_using_descriptor_handle_with_offset(callback, con_handle, descriptor_handle, 0);
|
||||
}
|
||||
|
||||
uint8_t gatt_client_read_long_characteristic_descriptor(uint16_t gatt_client_id, uint16_t con_handle, le_characteristic_descriptor_t * descriptor){
|
||||
return gatt_client_read_long_characteristic_descriptor_using_descriptor_handle(gatt_client_id, con_handle, descriptor->handle);
|
||||
uint8_t gatt_client_read_long_characteristic_descriptor(btstack_packet_handler_t callback, uint16_t con_handle, le_characteristic_descriptor_t * descriptor){
|
||||
return gatt_client_read_long_characteristic_descriptor_using_descriptor_handle(callback, con_handle, descriptor->handle);
|
||||
}
|
||||
|
||||
uint8_t gatt_client_write_characteristic_descriptor_using_descriptor_handle(uint16_t gatt_client_id, uint16_t con_handle, uint16_t descriptor_handle, uint16_t length, uint8_t * data){
|
||||
uint8_t gatt_client_write_characteristic_descriptor_using_descriptor_handle(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t descriptor_handle, uint16_t length, uint8_t * data){
|
||||
gatt_client_t * peripheral = provide_context_for_conn_handle_and_start_timer(con_handle);
|
||||
|
||||
if (!peripheral) return BTSTACK_MEMORY_ALLOC_FAILED;
|
||||
if (!is_ready(peripheral)) return GATT_CLIENT_IN_WRONG_STATE;
|
||||
|
||||
peripheral->subclient_id = gatt_client_id;
|
||||
peripheral->callback = callback;
|
||||
peripheral->attribute_handle = descriptor_handle;
|
||||
peripheral->attribute_length = length;
|
||||
peripheral->attribute_offset = 0;
|
||||
@ -1791,17 +1752,17 @@ uint8_t gatt_client_write_characteristic_descriptor_using_descriptor_handle(uint
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t gatt_client_write_characteristic_descriptor(uint16_t gatt_client_id, uint16_t con_handle, le_characteristic_descriptor_t * descriptor, uint16_t length, uint8_t * value){
|
||||
return gatt_client_write_characteristic_descriptor_using_descriptor_handle(gatt_client_id, con_handle, descriptor->handle, length, value);
|
||||
uint8_t gatt_client_write_characteristic_descriptor(btstack_packet_handler_t callback, uint16_t con_handle, le_characteristic_descriptor_t * descriptor, uint16_t length, uint8_t * value){
|
||||
return gatt_client_write_characteristic_descriptor_using_descriptor_handle(callback, con_handle, descriptor->handle, length, value);
|
||||
}
|
||||
|
||||
uint8_t gatt_client_write_long_characteristic_descriptor_using_descriptor_handle_with_offset(uint16_t gatt_client_id, uint16_t con_handle, uint16_t descriptor_handle, uint16_t offset, uint16_t length, uint8_t * data){
|
||||
uint8_t gatt_client_write_long_characteristic_descriptor_using_descriptor_handle_with_offset(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t descriptor_handle, uint16_t offset, uint16_t length, uint8_t * data){
|
||||
gatt_client_t * peripheral = provide_context_for_conn_handle_and_start_timer(con_handle);
|
||||
|
||||
if (!peripheral) return BTSTACK_MEMORY_ALLOC_FAILED;
|
||||
if (!is_ready(peripheral)) return GATT_CLIENT_IN_WRONG_STATE;
|
||||
|
||||
peripheral->subclient_id = gatt_client_id;
|
||||
peripheral->callback = callback;
|
||||
peripheral->attribute_handle = descriptor_handle;
|
||||
peripheral->attribute_length = length;
|
||||
peripheral->attribute_offset = offset;
|
||||
@ -1811,24 +1772,24 @@ uint8_t gatt_client_write_long_characteristic_descriptor_using_descriptor_handle
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t gatt_client_write_long_characteristic_descriptor_using_descriptor_handle(uint16_t gatt_client_id, uint16_t con_handle, uint16_t descriptor_handle, uint16_t length, uint8_t * data){
|
||||
return gatt_client_write_long_characteristic_descriptor_using_descriptor_handle_with_offset(gatt_client_id, con_handle, descriptor_handle, 0, length, data );
|
||||
uint8_t gatt_client_write_long_characteristic_descriptor_using_descriptor_handle(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t descriptor_handle, uint16_t length, uint8_t * data){
|
||||
return gatt_client_write_long_characteristic_descriptor_using_descriptor_handle_with_offset(callback, con_handle, descriptor_handle, 0, length, data );
|
||||
}
|
||||
|
||||
uint8_t gatt_client_write_long_characteristic_descriptor(uint16_t gatt_client_id, uint16_t con_handle, le_characteristic_descriptor_t * descriptor, uint16_t length, uint8_t * value){
|
||||
return gatt_client_write_long_characteristic_descriptor_using_descriptor_handle(gatt_client_id, con_handle, descriptor->handle, length, value);
|
||||
uint8_t gatt_client_write_long_characteristic_descriptor(btstack_packet_handler_t callback, uint16_t con_handle, le_characteristic_descriptor_t * descriptor, uint16_t length, uint8_t * value){
|
||||
return gatt_client_write_long_characteristic_descriptor_using_descriptor_handle(callback, con_handle, descriptor->handle, length, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief -> gatt complete event
|
||||
*/
|
||||
uint8_t gatt_client_prepare_write(uint16_t gatt_client_id, uint16_t con_handle, uint16_t attribute_handle, uint16_t offset, uint16_t length, uint8_t * data){
|
||||
uint8_t gatt_client_prepare_write(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t attribute_handle, uint16_t offset, uint16_t length, uint8_t * data){
|
||||
gatt_client_t * peripheral = provide_context_for_conn_handle_and_start_timer(con_handle);
|
||||
|
||||
if (!peripheral) return BTSTACK_MEMORY_ALLOC_FAILED;
|
||||
if (!is_ready(peripheral)) return GATT_CLIENT_IN_WRONG_STATE;
|
||||
|
||||
peripheral->subclient_id = gatt_client_id;
|
||||
peripheral->callback = callback;
|
||||
peripheral->attribute_handle = attribute_handle;
|
||||
peripheral->attribute_length = length;
|
||||
peripheral->attribute_offset = offset;
|
||||
@ -1841,13 +1802,13 @@ uint8_t gatt_client_prepare_write(uint16_t gatt_client_id, uint16_t con_handle,
|
||||
/**
|
||||
* @brief -> gatt complete event
|
||||
*/
|
||||
uint8_t gatt_client_execute_write(uint16_t gatt_client_id, uint16_t con_handle){
|
||||
uint8_t gatt_client_execute_write(btstack_packet_handler_t callback, uint16_t con_handle){
|
||||
gatt_client_t * peripheral = provide_context_for_conn_handle_and_start_timer(con_handle);
|
||||
|
||||
if (!peripheral) return BTSTACK_MEMORY_ALLOC_FAILED;
|
||||
if (!is_ready(peripheral)) return GATT_CLIENT_IN_WRONG_STATE;
|
||||
|
||||
peripheral->subclient_id = gatt_client_id;
|
||||
peripheral->callback = callback;
|
||||
peripheral->gatt_client_state = P_W2_EXECUTE_PREPARED_WRITE;
|
||||
gatt_client_run();
|
||||
return 0;
|
||||
@ -1856,13 +1817,13 @@ uint8_t gatt_client_execute_write(uint16_t gatt_client_id, uint16_t con_handle){
|
||||
/**
|
||||
* @brief -> gatt complete event
|
||||
*/
|
||||
uint8_t gatt_client_cancel_write(uint16_t gatt_client_id, uint16_t con_handle){
|
||||
uint8_t gatt_client_cancel_write(btstack_packet_handler_t callback, uint16_t con_handle){
|
||||
gatt_client_t * peripheral = provide_context_for_conn_handle_and_start_timer(con_handle);
|
||||
|
||||
if (!peripheral) return BTSTACK_MEMORY_ALLOC_FAILED;
|
||||
if (!is_ready(peripheral)) return GATT_CLIENT_IN_WRONG_STATE;
|
||||
|
||||
peripheral->subclient_id = gatt_client_id;
|
||||
peripheral->callback = callback;
|
||||
peripheral->gatt_client_state = P_W2_CANCEL_PREPARED_WRITE;
|
||||
gatt_client_run();
|
||||
return 0;
|
||||
|
@ -45,11 +45,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct le_event {
|
||||
uint8_t type;
|
||||
uint16_t handle;
|
||||
} le_event_t;
|
||||
|
||||
typedef enum {
|
||||
P_READY,
|
||||
P_W2_SEND_SERVICE_QUERY,
|
||||
@ -139,8 +134,8 @@ typedef struct gatt_client{
|
||||
// TODO: rename gatt_client_state -> state
|
||||
gatt_client_state_t gatt_client_state;
|
||||
|
||||
// subclient
|
||||
uint16_t subclient_id;
|
||||
// user callback
|
||||
btstack_packet_handler_t callback;
|
||||
|
||||
uint16_t handle;
|
||||
|
||||
@ -182,11 +177,12 @@ typedef struct gatt_client{
|
||||
btstack_timer_source_t gc_timeout;
|
||||
} gatt_client_t;
|
||||
|
||||
typedef struct gatt_subclient {
|
||||
typedef struct gatt_client_notification {
|
||||
btstack_linked_item_t item;
|
||||
uint16_t id;
|
||||
btstack_packet_handler_t callback;
|
||||
} gatt_subclient_t;
|
||||
uint16_t con_handle;
|
||||
uint16_t attribute_handle;
|
||||
} gatt_client_notification_t;
|
||||
|
||||
/* API_START */
|
||||
|
||||
@ -217,16 +213,6 @@ typedef struct le_characteristic_descriptor{
|
||||
*/
|
||||
void gatt_client_init(void);
|
||||
|
||||
/**
|
||||
* @brief Register callback (packet handler) for GATT client. Returns GATT client ID.
|
||||
*/
|
||||
uint16_t gatt_client_register_packet_handler (btstack_packet_handler_t callback);
|
||||
|
||||
/**
|
||||
* @brief Unregister callback (packet handler) for GATT client.
|
||||
*/
|
||||
void gatt_client_unregister_packet_handler(uint16_t gatt_client_id);
|
||||
|
||||
/**
|
||||
* @brief MTU is available after the first query has completed. If status is equal to 0, it returns the real value, otherwise the default value of 23.
|
||||
*/
|
||||
@ -240,126 +226,134 @@ int gatt_client_is_ready(uint16_t handle);
|
||||
/**
|
||||
* @brief Discovers all primary services. For each found service, an le_service_event_t with type set to GATT_EVENT_SERVICE_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t, with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of discovery.
|
||||
*/
|
||||
uint8_t gatt_client_discover_primary_services(uint16_t gatt_client_id, uint16_t con_handle);
|
||||
uint8_t gatt_client_discover_primary_services(btstack_packet_handler_t callback, uint16_t con_handle);
|
||||
|
||||
/**
|
||||
* @brief Discovers a specific primary service given its UUID. This service may exist multiple times. For each found service, an le_service_event_t with type set to GATT_EVENT_SERVICE_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t, with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of discovery.
|
||||
*/
|
||||
uint8_t gatt_client_discover_primary_services_by_uuid16(uint16_t gatt_client_id, uint16_t con_handle, uint16_t uuid16);
|
||||
uint8_t gatt_client_discover_primary_services_by_uuid128(uint16_t gatt_client_id, uint16_t con_handle, const uint8_t * uuid);
|
||||
uint8_t gatt_client_discover_primary_services_by_uuid16(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t uuid16);
|
||||
uint8_t gatt_client_discover_primary_services_by_uuid128(btstack_packet_handler_t callback, uint16_t con_handle, const uint8_t * uuid);
|
||||
|
||||
/**
|
||||
* @brief Finds included services within the specified service. For each found included service, an le_service_event_t with type set to GATT_EVENT_INCLUDED_SERVICE_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of discovery. Information about included service type (primary/secondary) can be retrieved either by sending an ATT find information request for the returned start group handle (returning the handle and the UUID for primary or secondary service) or by comparing the service to the list of all primary services.
|
||||
*/
|
||||
uint8_t gatt_client_find_included_services_for_service(uint16_t gatt_client_id, uint16_t con_handle, le_service_t *service);
|
||||
uint8_t gatt_client_find_included_services_for_service(btstack_packet_handler_t callback, uint16_t con_handle, le_service_t *service);
|
||||
|
||||
/**
|
||||
* @brief Discovers all characteristics within the specified service. For each found characteristic, an le_characteristics_event_t with type set to GATT_EVENT_CHARACTERISTIC_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of discovery.
|
||||
*/
|
||||
uint8_t gatt_client_discover_characteristics_for_service(uint16_t gatt_client_id, uint16_t con_handle, le_service_t *service);
|
||||
uint8_t gatt_client_discover_characteristics_for_service(btstack_packet_handler_t callback, uint16_t con_handle, le_service_t *service);
|
||||
|
||||
/**
|
||||
* @brief The following four functions are used to discover all characteristics within the specified service or handle range, and return those that match the given UUID. For each found characteristic, an le_characteristic_event_t with type set to GATT_EVENT_CHARACTERISTIC_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of discovery.
|
||||
*/
|
||||
uint8_t gatt_client_discover_characteristics_for_handle_range_by_uuid16(uint16_t gatt_client_id, uint16_t con_handle, uint16_t start_handle, uint16_t end_handle, uint16_t uuid16);
|
||||
uint8_t gatt_client_discover_characteristics_for_handle_range_by_uuid128(uint16_t gatt_client_id, uint16_t con_handle, uint16_t start_handle, uint16_t end_handle, uint8_t * uuid);
|
||||
uint8_t gatt_client_discover_characteristics_for_service_by_uuid16 (uint16_t gatt_client_id, uint16_t con_handle, le_service_t *service, uint16_t uuid16);
|
||||
uint8_t gatt_client_discover_characteristics_for_service_by_uuid128(uint16_t gatt_client_id, uint16_t con_handle, le_service_t *service, uint8_t * uuid128);
|
||||
uint8_t gatt_client_discover_characteristics_for_handle_range_by_uuid16(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t start_handle, uint16_t end_handle, uint16_t uuid16);
|
||||
uint8_t gatt_client_discover_characteristics_for_handle_range_by_uuid128(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t start_handle, uint16_t end_handle, uint8_t * uuid);
|
||||
uint8_t gatt_client_discover_characteristics_for_service_by_uuid16 (btstack_packet_handler_t callback, uint16_t con_handle, le_service_t *service, uint16_t uuid16);
|
||||
uint8_t gatt_client_discover_characteristics_for_service_by_uuid128(btstack_packet_handler_t callback, uint16_t con_handle, le_service_t *service, uint8_t * uuid128);
|
||||
|
||||
/**
|
||||
* @brief Discovers attribute handle and UUID of a characteristic descriptor within the specified characteristic. For each found descriptor, an le_characteristic_descriptor_event_t with type set to GATT_EVENT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of discovery.
|
||||
*/
|
||||
uint8_t gatt_client_discover_characteristic_descriptors(uint16_t gatt_client_id, uint16_t con_handle, le_characteristic_t *characteristic);
|
||||
uint8_t gatt_client_discover_characteristic_descriptors(btstack_packet_handler_t callback, uint16_t con_handle, le_characteristic_t *characteristic);
|
||||
|
||||
/**
|
||||
* @brief Reads the characteristic value using the characteristic's value handle. If the characteristic value is found, an le_characteristic_value_event_t with type set to GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of read.
|
||||
*/
|
||||
uint8_t gatt_client_read_value_of_characteristic(uint16_t gatt_client_id, uint16_t con_handle, le_characteristic_t *characteristic);
|
||||
uint8_t gatt_client_read_value_of_characteristic_using_value_handle(uint16_t gatt_client_id, uint16_t con_handle, uint16_t characteristic_value_handle);
|
||||
uint8_t gatt_client_read_value_of_characteristic(btstack_packet_handler_t callback, uint16_t con_handle, le_characteristic_t *characteristic);
|
||||
uint8_t gatt_client_read_value_of_characteristic_using_value_handle(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t characteristic_value_handle);
|
||||
|
||||
/**
|
||||
* @brief Reads the characteric value of all characteristics with the uuid. For each found, an le_characteristic_value_event_t with type set to GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of read.
|
||||
*/
|
||||
uint8_t gatt_client_read_value_of_characteristics_by_uuid16(uint16_t gatt_client_id, uint16_t con_handle, uint16_t start_handle, uint16_t end_handle, uint16_t uuid16);
|
||||
uint8_t gatt_client_read_value_of_characteristics_by_uuid128(uint16_t gatt_client_id, uint16_t con_handle, uint16_t start_handle, uint16_t end_handle, uint8_t * uuid128);
|
||||
uint8_t gatt_client_read_value_of_characteristics_by_uuid16(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t start_handle, uint16_t end_handle, uint16_t uuid16);
|
||||
uint8_t gatt_client_read_value_of_characteristics_by_uuid128(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t start_handle, uint16_t end_handle, uint8_t * uuid128);
|
||||
|
||||
/**
|
||||
* @brief Reads the long characteristic value using the characteristic's value handle. The value will be returned in several blobs. For each blob, an le_characteristic_value_event_t with type set to GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT and updated value offset will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, mark the end of read.
|
||||
*/
|
||||
uint8_t gatt_client_read_long_value_of_characteristic(uint16_t gatt_client_id, uint16_t con_handle, le_characteristic_t *characteristic);
|
||||
uint8_t gatt_client_read_long_value_of_characteristic_using_value_handle(uint16_t gatt_client_id, uint16_t con_handle, uint16_t characteristic_value_handle);
|
||||
uint8_t gatt_client_read_long_value_of_characteristic_using_value_handle_with_offset(uint16_t gatt_client_id, uint16_t con_handle, uint16_t characteristic_value_handle, uint16_t offset);
|
||||
uint8_t gatt_client_read_long_value_of_characteristic(btstack_packet_handler_t callback, uint16_t con_handle, le_characteristic_t *characteristic);
|
||||
uint8_t gatt_client_read_long_value_of_characteristic_using_value_handle(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t characteristic_value_handle);
|
||||
uint8_t gatt_client_read_long_value_of_characteristic_using_value_handle_with_offset(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t characteristic_value_handle, uint16_t offset);
|
||||
|
||||
/*
|
||||
* @brief Read multiple characteristic values
|
||||
* @param number handles
|
||||
* @param list_of_handles list of handles
|
||||
*/
|
||||
uint8_t gatt_client_read_multiple_characteristic_values(uint16_t gatt_client_id, uint16_t con_handle, int num_value_handles, uint16_t * value_handles);
|
||||
uint8_t gatt_client_read_multiple_characteristic_values(btstack_packet_handler_t callback, uint16_t con_handle, int num_value_handles, uint16_t * value_handles);
|
||||
|
||||
/**
|
||||
* @brief Writes the characteristic value using the characteristic's value handle without an acknowledgment that the write was successfully performed.
|
||||
*/
|
||||
uint8_t gatt_client_write_value_of_characteristic_without_response(uint16_t gatt_client_id, uint16_t con_handle, uint16_t characteristic_value_handle, uint16_t length, uint8_t * data);
|
||||
uint8_t gatt_client_write_value_of_characteristic_without_response(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t characteristic_value_handle, uint16_t length, uint8_t * data);
|
||||
|
||||
/**
|
||||
* @brief Writes the authenticated characteristic value using the characteristic's value handle without an acknowledgment that the write was successfully performed.
|
||||
*/
|
||||
uint8_t gatt_client_signed_write_without_response(uint16_t gatt_client_id, uint16_t con_handle, uint16_t handle, uint16_t message_len, uint8_t * message);
|
||||
uint8_t gatt_client_signed_write_without_response(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t handle, uint16_t message_len, uint8_t * message);
|
||||
|
||||
/**
|
||||
* @brief Writes the characteristic value using the characteristic's value handle. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of write. The write is successfully performed, if the event's status field is set to 0.
|
||||
*/
|
||||
uint8_t gatt_client_write_value_of_characteristic(uint16_t gatt_client_id, uint16_t con_handle, uint16_t characteristic_value_handle, uint16_t length, uint8_t * data);
|
||||
uint8_t gatt_client_write_long_value_of_characteristic(uint16_t gatt_client_id, uint16_t con_handle, uint16_t characteristic_value_handle, uint16_t length, uint8_t * data);
|
||||
uint8_t gatt_client_write_long_value_of_characteristic_with_offset(uint16_t gatt_client_id, uint16_t con_handle, uint16_t characteristic_value_handle, uint16_t offset, uint16_t length, uint8_t * data);
|
||||
uint8_t gatt_client_write_value_of_characteristic(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t characteristic_value_handle, uint16_t length, uint8_t * data);
|
||||
uint8_t gatt_client_write_long_value_of_characteristic(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t characteristic_value_handle, uint16_t length, uint8_t * data);
|
||||
uint8_t gatt_client_write_long_value_of_characteristic_with_offset(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t characteristic_value_handle, uint16_t offset, uint16_t length, uint8_t * data);
|
||||
|
||||
/**
|
||||
* @brief Writes of the long characteristic value using the characteristic's value handle. It uses server response to validate that the write was correctly received. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE marks the end of write. The write is successfully performed, if the event's status field is set to 0.
|
||||
*/
|
||||
uint8_t gatt_client_reliable_write_long_value_of_characteristic(uint16_t gatt_client_id, uint16_t con_handle, uint16_t characteristic_value_handle, uint16_t length, uint8_t * data);
|
||||
uint8_t gatt_client_reliable_write_long_value_of_characteristic(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t characteristic_value_handle, uint16_t length, uint8_t * data);
|
||||
|
||||
/**
|
||||
* @brief Reads the characteristic descriptor using its handle. If the characteristic descriptor is found, an le_characteristic_descriptor_event_t with type set to GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of read.
|
||||
*/
|
||||
uint8_t gatt_client_read_characteristic_descriptor(uint16_t gatt_client_id, uint16_t con_handle, le_characteristic_descriptor_t * descriptor);
|
||||
uint8_t gatt_client_read_characteristic_descriptor_using_descriptor_handle(uint16_t gatt_client_id, uint16_t con_handle, uint16_t descriptor_handle);
|
||||
uint8_t gatt_client_read_characteristic_descriptor(btstack_packet_handler_t callback, uint16_t con_handle, le_characteristic_descriptor_t * descriptor);
|
||||
uint8_t gatt_client_read_characteristic_descriptor_using_descriptor_handle(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t descriptor_handle);
|
||||
|
||||
/**
|
||||
* @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs. For each blob, an le_characteristic_descriptor_event_t with type set to GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of read.
|
||||
*/
|
||||
uint8_t gatt_client_read_long_characteristic_descriptor(uint16_t gatt_client_id, uint16_t con_handle, le_characteristic_descriptor_t * descriptor);
|
||||
uint8_t gatt_client_read_long_characteristic_descriptor_using_descriptor_handle(uint16_t gatt_client_id, uint16_t con_handle, uint16_t descriptor_handle);
|
||||
uint8_t gatt_client_read_long_characteristic_descriptor_using_descriptor_handle_with_offset(uint16_t gatt_client_id, uint16_t con_handle, uint16_t descriptor_handle, uint16_t offset);
|
||||
uint8_t gatt_client_read_long_characteristic_descriptor(btstack_packet_handler_t callback, uint16_t con_handle, le_characteristic_descriptor_t * descriptor);
|
||||
uint8_t gatt_client_read_long_characteristic_descriptor_using_descriptor_handle(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t descriptor_handle);
|
||||
uint8_t gatt_client_read_long_characteristic_descriptor_using_descriptor_handle_with_offset(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t descriptor_handle, uint16_t offset);
|
||||
|
||||
/**
|
||||
* @brief Writes the characteristic descriptor using its handle. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of write. The write is successfully performed, if the event's status field is set to 0.
|
||||
*/
|
||||
uint8_t gatt_client_write_characteristic_descriptor(uint16_t gatt_client_id, uint16_t con_handle, le_characteristic_descriptor_t * descriptor, uint16_t length, uint8_t * data);
|
||||
uint8_t gatt_client_write_characteristic_descriptor_using_descriptor_handle(uint16_t gatt_client_id, uint16_t con_handle, uint16_t descriptor_handle, uint16_t length, uint8_t * data);
|
||||
uint8_t gatt_client_write_long_characteristic_descriptor(uint16_t gatt_client_id, uint16_t con_handle, le_characteristic_descriptor_t * descriptor, uint16_t length, uint8_t * data);
|
||||
uint8_t gatt_client_write_long_characteristic_descriptor_using_descriptor_handle(uint16_t gatt_client_id, uint16_t con_handle, uint16_t descriptor_handle, uint16_t length, uint8_t * data);
|
||||
uint8_t gatt_client_write_long_characteristic_descriptor_using_descriptor_handle_with_offset(uint16_t gatt_client_id, uint16_t con_handle, uint16_t descriptor_handle, uint16_t offset, uint16_t length, uint8_t * data);
|
||||
uint8_t gatt_client_write_characteristic_descriptor(btstack_packet_handler_t callback, uint16_t con_handle, le_characteristic_descriptor_t * descriptor, uint16_t length, uint8_t * data);
|
||||
uint8_t gatt_client_write_characteristic_descriptor_using_descriptor_handle(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t descriptor_handle, uint16_t length, uint8_t * data);
|
||||
uint8_t gatt_client_write_long_characteristic_descriptor(btstack_packet_handler_t callback, uint16_t con_handle, le_characteristic_descriptor_t * descriptor, uint16_t length, uint8_t * data);
|
||||
uint8_t gatt_client_write_long_characteristic_descriptor_using_descriptor_handle(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t descriptor_handle, uint16_t length, uint8_t * data);
|
||||
uint8_t gatt_client_write_long_characteristic_descriptor_using_descriptor_handle_with_offset(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t descriptor_handle, uint16_t offset, uint16_t length, uint8_t * data);
|
||||
|
||||
/**
|
||||
* @brief Writes the client characteristic configuration of the specified characteristic. It is used to subscribe for notifications or indications of the characteristic value. For notifications or indications specify: GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION resp. GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION as configuration value.
|
||||
*/
|
||||
uint8_t gatt_client_write_client_characteristic_configuration(uint16_t gatt_client_id, uint16_t con_handle, le_characteristic_t * characteristic, uint16_t configuration);
|
||||
uint8_t gatt_client_write_client_characteristic_configuration(btstack_packet_handler_t callback, uint16_t con_handle, le_characteristic_t * characteristic, uint16_t configuration);
|
||||
|
||||
/**
|
||||
* @brief Register for notifications and indications of a characteristic enabled by gatt_client_write_client_characteristic_configuration
|
||||
* @param notification struct used to store registration
|
||||
* @param con_handle
|
||||
* @param characteristic
|
||||
*/
|
||||
void gatt_client_listen_for_characteristic_value_updates(gatt_client_notification_t * notification, uint16_t con_handle, le_characteristic_t * characteristic);
|
||||
|
||||
/**
|
||||
* @brief -> gatt complete event
|
||||
*/
|
||||
uint8_t gatt_client_prepare_write(uint16_t gatt_client_id, uint16_t con_handle, uint16_t attribute_handle, uint16_t offset, uint16_t length, uint8_t * data);
|
||||
uint8_t gatt_client_prepare_write(btstack_packet_handler_t callback, uint16_t con_handle, uint16_t attribute_handle, uint16_t offset, uint16_t length, uint8_t * data);
|
||||
|
||||
/**
|
||||
* @brief -> gatt complete event
|
||||
*/
|
||||
uint8_t gatt_client_execute_write(uint16_t gatt_client_id, uint16_t con_handle);
|
||||
uint8_t gatt_client_execute_write(btstack_packet_handler_t callback, uint16_t con_handle);
|
||||
|
||||
/**
|
||||
* @brief -> gatt complete event
|
||||
*/
|
||||
uint8_t gatt_client_cancel_write(uint16_t gatt_client_id, uint16_t con_handle);
|
||||
uint8_t gatt_client_cancel_write(btstack_packet_handler_t callback, uint16_t con_handle);
|
||||
|
||||
|
||||
/* API_END */
|
||||
|
@ -444,38 +444,6 @@ void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
|
||||
#endif
|
||||
|
||||
|
||||
// MARK: gatt_subclient_t
|
||||
#ifdef MAX_NO_GATT_SUBCLIENTS
|
||||
#if MAX_NO_GATT_SUBCLIENTS > 0
|
||||
static gatt_subclient_t gatt_subclient_storage[MAX_NO_GATT_SUBCLIENTS];
|
||||
static btstack_memory_pool_t gatt_subclient_pool;
|
||||
gatt_subclient_t * btstack_memory_gatt_subclient_get(void){
|
||||
return (gatt_subclient_t *) btstack_memory_pool_get(&gatt_subclient_pool);
|
||||
}
|
||||
void btstack_memory_gatt_subclient_free(gatt_subclient_t *gatt_subclient){
|
||||
btstack_memory_pool_free(&gatt_subclient_pool, gatt_subclient);
|
||||
}
|
||||
#else
|
||||
gatt_subclient_t * btstack_memory_gatt_subclient_get(void){
|
||||
return NULL;
|
||||
}
|
||||
void btstack_memory_gatt_subclient_free(gatt_subclient_t *gatt_subclient){
|
||||
// silence compiler warning about unused parameter in a portable way
|
||||
(void) gatt_subclient;
|
||||
};
|
||||
#endif
|
||||
#elif defined(HAVE_MALLOC)
|
||||
gatt_subclient_t * btstack_memory_gatt_subclient_get(void){
|
||||
return (gatt_subclient_t*) malloc(sizeof(gatt_subclient_t));
|
||||
}
|
||||
void btstack_memory_gatt_subclient_free(gatt_subclient_t *gatt_subclient){
|
||||
free(gatt_subclient);
|
||||
}
|
||||
#else
|
||||
#error "Neither HAVE_MALLOC nor MAX_NO_GATT_SUBCLIENTS for struct gatt_subclient is defined. Please, edit the config file."
|
||||
#endif
|
||||
|
||||
|
||||
// MARK: whitelist_entry_t
|
||||
#ifdef MAX_NO_WHITELIST_ENTRIES
|
||||
#if MAX_NO_WHITELIST_ENTRIES > 0
|
||||
@ -580,9 +548,6 @@ void btstack_memory_init(void){
|
||||
#if MAX_NO_GATT_CLIENTS > 0
|
||||
btstack_memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NO_GATT_CLIENTS, sizeof(gatt_client_t));
|
||||
#endif
|
||||
#if MAX_NO_GATT_SUBCLIENTS > 0
|
||||
btstack_memory_pool_create(&gatt_subclient_pool, gatt_subclient_storage, MAX_NO_GATT_SUBCLIENTS, sizeof(gatt_subclient_t));
|
||||
#endif
|
||||
#if MAX_NO_WHITELIST_ENTRIES > 0
|
||||
btstack_memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NO_WHITELIST_ENTRIES, sizeof(whitelist_entry_t));
|
||||
#endif
|
||||
|
@ -117,11 +117,9 @@ service_record_item_t * btstack_memory_service_record_item_get(void);
|
||||
void btstack_memory_service_record_item_free(service_record_item_t *service_record_item);
|
||||
|
||||
#ifdef ENABLE_BLE
|
||||
// gatt_client, gatt_subclient, whitelist_entry, sm_lookup_entry
|
||||
// gatt_client, whitelist_entry, sm_lookup_entry
|
||||
gatt_client_t * btstack_memory_gatt_client_get(void);
|
||||
void btstack_memory_gatt_client_free(gatt_client_t *gatt_client);
|
||||
gatt_subclient_t * btstack_memory_gatt_subclient_get(void);
|
||||
void btstack_memory_gatt_subclient_free(gatt_subclient_t *gatt_subclient);
|
||||
whitelist_entry_t * btstack_memory_whitelist_entry_get(void);
|
||||
void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry);
|
||||
sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void);
|
||||
|
@ -171,7 +171,7 @@ list_of_structs = [
|
||||
["hfp_connection"],
|
||||
["service_record_item"]
|
||||
]
|
||||
list_of_le_structs = [["gatt_client", "gatt_subclient", "whitelist_entry", "sm_lookup_entry"]]
|
||||
list_of_le_structs = [["gatt_client", "whitelist_entry", "sm_lookup_entry"]]
|
||||
|
||||
file_name = "../src/btstack_memory"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user