Microchip® Advanced Software Framework

gatt_client.c File Reference
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "btstack_config.h"
#include "att_dispatch.h"
#include "ad_parser.h"
#include "ble/att_db.h"
#include "ble/core.h"
#include "ble/gatt_client.h"
#include "ble/le_device_db.h"
#include "ble/sm.h"
#include "btstack_debug.h"
#include "btstack_event.h"
#include "btstack_memory.h"
#include "btstack_run_loop.h"
#include "btstack_util.h"
#include "classic/sdp_util.h"
#include "hci.h"
#include "hci_cmd.h"
#include "hci_dump.h"
#include "l2cap.h"

Macros

#define __BTSTACK_FILE__   "gatt_client.c"
 

Functions

static void att_confirmation (uint16_t peripheral_handle)
 
static void att_exchange_mtu_request (uint16_t peripheral_handle)
 
static void att_execute_write_request (uint16_t request_type, uint16_t peripheral_handle, uint8_t execute_write)
 
static void att_find_by_type_value_request (uint16_t request_type, uint16_t attribute_group_type, uint16_t peripheral_handle, uint16_t start_handle, uint16_t end_handle, uint8_t *value, uint16_t value_size)
 
static void att_find_information_request (uint16_t request_type, uint16_t peripheral_handle, uint16_t start_handle, uint16_t end_handle)
 
static void att_prepare_write_request (uint16_t request_type, uint16_t peripheral_handle, uint16_t attribute_handle, uint16_t value_offset, uint16_t blob_length, uint8_t *value)
 
static void att_read_blob_request (uint16_t request_type, uint16_t peripheral_handle, uint16_t attribute_handle, uint16_t value_offset)
 
static void att_read_by_type_or_group_request_for_uuid128 (uint16_t request_type, uint8_t *uuid128, uint16_t peripheral_handle, uint16_t start_handle, uint16_t end_handle)
 
static void att_read_by_type_or_group_request_for_uuid16 (uint16_t request_type, uint16_t uuid16, uint16_t peripheral_handle, uint16_t start_handle, uint16_t end_handle)
 
static void att_read_multiple_request (uint16_t peripheral_handle, uint16_t num_value_handles, uint16_t *value_handles)
 
static void att_read_request (uint16_t request_type, uint16_t peripheral_handle, uint16_t attribute_handle)
 
static void att_write_request (uint16_t request_type, uint16_t peripheral_handle, uint16_t attribute_handle, uint16_t value_length, uint8_t *value)
 
static void characteristic_end_found (gatt_client_t *peripheral, uint16_t end_handle)
 
static void characteristic_start_found (gatt_client_t *peripheral, uint16_t start_handle, uint8_t properties, uint16_t value_handle, uint8_t *uuid, uint16_t uuid_length)
 
static void emit_event_new (btstack_packet_handler_t callback, uint8_t *packet, uint16_t size)
 
static void emit_event_to_registered_listeners (hci_con_handle_t con_handle, uint16_t attribute_handle, uint8_t *packet, uint16_t size)
 
static void emit_gatt_all_characteristic_descriptors_result_event (gatt_client_t *peripheral, uint16_t descriptor_handle, uint8_t *uuid128)
 
static void emit_gatt_characteristic_query_result_event (gatt_client_t *peripheral, uint16_t start_handle, uint16_t value_handle, uint16_t end_handle, uint16_t properties, uint8_t *uuid128)
 
static void emit_gatt_complete_event (gatt_client_t *peripheral, uint8_t status)
 
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)
 
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)
 
static void gatt_client_att_packet_handler (uint8_t packet_type, uint16_t handle, uint8_t *packet, uint16_t size)
 
uint8_t gatt_client_cancel_write (btstack_packet_handler_t callback, hci_con_handle_t con_handle)
 -> gatt complete event More...
 
void gatt_client_deserialize_characteristic (const uint8_t *packet, int offset, gatt_client_characteristic_t *characteristic)
 
void gatt_client_deserialize_characteristic_descriptor (const uint8_t *packet, int offset, gatt_client_characteristic_descriptor_t *descriptor)
 
void gatt_client_deserialize_service (const uint8_t *packet, int offset, gatt_client_service_t *service)
 
uint8_t gatt_client_discover_characteristic_descriptors (btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t *characteristic)
 Discovers attribute handle and UUID of a characteristic descriptor within the specified characteristic. More...
 
uint8_t gatt_client_discover_characteristics_for_handle_range_by_uuid128 (btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t start_handle, uint16_t end_handle, uint8_t *uuid128)
 
uint8_t gatt_client_discover_characteristics_for_handle_range_by_uuid16 (btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t start_handle, uint16_t end_handle, uint16_t uuid16)
 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. More...
 
uint8_t gatt_client_discover_characteristics_for_service (btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_service_t *service)
 Discovers all characteristics within the specified service. More...
 
uint8_t gatt_client_discover_characteristics_for_service_by_uuid128 (btstack_packet_handler_t callback, uint16_t handle, gatt_client_service_t *service, uint8_t *uuid128)
 
uint8_t gatt_client_discover_characteristics_for_service_by_uuid16 (btstack_packet_handler_t callback, uint16_t handle, gatt_client_service_t *service, uint16_t uuid16)
 
uint8_t gatt_client_discover_primary_services (btstack_packet_handler_t callback, hci_con_handle_t con_handle)
 Discovers all primary services. More...
 
uint8_t gatt_client_discover_primary_services_by_uuid128 (btstack_packet_handler_t callback, hci_con_handle_t con_handle, const uint8_t *uuid128)
 
uint8_t gatt_client_discover_primary_services_by_uuid16 (btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t uuid16)
 Discovers a specific primary service given its UUID. More...
 
uint8_t gatt_client_execute_write (btstack_packet_handler_t callback, hci_con_handle_t con_handle)
 -> gatt complete event More...
 
uint8_t gatt_client_find_included_services_for_service (btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_service_t *service)
 Finds included services within the specified service. More...
 
static gatt_client_tgatt_client_for_timer (btstack_timer_source_t *ts)
 
uint8_t gatt_client_get_mtu (hci_con_handle_t con_handle, uint16_t *mtu)
 MTU is available after the first query has completed. More...
 
static void gatt_client_handle_transaction_complete (gatt_client_t *peripheral)
 
static void gatt_client_hci_event_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)
 
void gatt_client_init (void)
 Set up GATT client. More...
 
int gatt_client_is_ready (hci_con_handle_t con_handle)
 Returns if the GATT client is ready to receive a query. More...
 
void gatt_client_listen_for_characteristic_value_updates (gatt_client_notification_t *notification, btstack_packet_handler_t packet_handler, hci_con_handle_t con_handle, gatt_client_characteristic_t *characteristic)
 Register for notifications and indications of a characteristic enabled by gatt_client_write_client_characteristic_configuration. More...
 
uint8_t gatt_client_prepare_write (btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t attribute_handle, uint16_t offset, uint16_t length, uint8_t *data)
 -> gatt complete event More...
 
void gatt_client_pts_suppress_mtu_exchange (void)
 
uint8_t gatt_client_read_characteristic_descriptor (btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_descriptor_t *descriptor)
 Reads the characteristic descriptor using its handle. More...
 
uint8_t gatt_client_read_characteristic_descriptor_using_descriptor_handle (btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t descriptor_handle)
 
uint8_t gatt_client_read_long_characteristic_descriptor (btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_descriptor_t *descriptor)
 Reads the long characteristic descriptor using its handle. More...
 
uint8_t gatt_client_read_long_characteristic_descriptor_using_descriptor_handle (btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t descriptor_handle)
 
uint8_t gatt_client_read_long_characteristic_descriptor_using_descriptor_handle_with_offset (btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t descriptor_handle, uint16_t offset)
 
uint8_t gatt_client_read_long_value_of_characteristic (btstack_packet_handler_t callback, uint16_t handle, gatt_client_characteristic_t *characteristic)
 Reads the long characteristic value using the characteristic's value handle. More...
 
uint8_t gatt_client_read_long_value_of_characteristic_using_value_handle (btstack_packet_handler_t callback, hci_con_handle_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, hci_con_handle_t con_handle, uint16_t characteristic_value_handle, uint16_t offset)
 
uint8_t gatt_client_read_multiple_characteristic_values (btstack_packet_handler_t callback, hci_con_handle_t con_handle, int num_value_handles, uint16_t *value_handles)
 
uint8_t gatt_client_read_value_of_characteristic (btstack_packet_handler_t callback, uint16_t handle, gatt_client_characteristic_t *characteristic)
 Reads the characteristic value using the characteristic's value handle. More...
 
uint8_t gatt_client_read_value_of_characteristic_using_value_handle (btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle)
 
uint8_t gatt_client_read_value_of_characteristics_by_uuid128 (btstack_packet_handler_t callback, hci_con_handle_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, hci_con_handle_t con_handle, uint16_t start_handle, uint16_t end_handle, uint16_t uuid16)
 Reads the characteric value of all characteristics with the uuid. More...
 
uint8_t gatt_client_reliable_write_long_value_of_characteristic (btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t *value)
 Writes of the long characteristic value using the characteristic's value handle. More...
 
static void gatt_client_report_error_if_pending (gatt_client_t *peripheral, uint8_t error_code)
 
static void gatt_client_run (void)
 
void gatt_client_stop_listening_for_characteristic_value_updates (gatt_client_notification_t *notification)
 Stop listening to characteristic value updates registered with gatt_client_listen_for_characteristic_value_updates. More...
 
static void gatt_client_timeout_handler (btstack_timer_source_t *timer)
 
static void gatt_client_timeout_start (gatt_client_t *peripheral)
 
static void gatt_client_timeout_stop (gatt_client_t *peripheral)
 
uint8_t gatt_client_write_characteristic_descriptor (btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_descriptor_t *descriptor, uint16_t length, uint8_t *value)
 Writes the characteristic descriptor using its handle. More...
 
uint8_t gatt_client_write_characteristic_descriptor_using_descriptor_handle (btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t descriptor_handle, uint16_t length, uint8_t *data)
 
uint8_t gatt_client_write_client_characteristic_configuration (btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t *characteristic, uint16_t configuration)
 Writes the client characteristic configuration of the specified characteristic. More...
 
uint8_t gatt_client_write_long_characteristic_descriptor (btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_descriptor_t *descriptor, uint16_t length, uint8_t *value)
 
uint8_t gatt_client_write_long_characteristic_descriptor_using_descriptor_handle (btstack_packet_handler_t callback, hci_con_handle_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, hci_con_handle_t con_handle, uint16_t descriptor_handle, uint16_t offset, uint16_t length, uint8_t *data)
 
uint8_t gatt_client_write_long_value_of_characteristic (btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t *value)
 
uint8_t gatt_client_write_long_value_of_characteristic_with_offset (btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, uint16_t offset, uint16_t value_length, uint8_t *data)
 
uint8_t gatt_client_write_value_of_characteristic (btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t *data)
 Writes the characteristic value using the characteristic's value handle. More...
 
uint8_t gatt_client_write_value_of_characteristic_without_response (hci_con_handle_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t *value)
 Writes the characteristic value using the characteristic's value handle without an acknowledgment that the write was successfully performed. More...
 
static gatt_client_tget_gatt_client_context_for_handle (uint16_t handle)
 
static uint16_t get_last_result_handle_from_characteristics_list (uint8_t *packet, uint16_t size)
 
static uint16_t get_last_result_handle_from_included_services_list (uint8_t *packet, uint16_t size)
 
static uint16_t get_last_result_handle_from_service_list (uint8_t *packet, uint16_t size)
 
static int is_query_done (gatt_client_t *peripheral, uint16_t last_result_handle)
 
static int is_ready (gatt_client_t *context)
 
static int is_value_valid (gatt_client_t *peripheral, uint8_t *packet, uint16_t size)
 
static uint16_t peripheral_mtu (gatt_client_t *peripheral)
 
static gatt_client_tprovide_context_for_conn_handle (hci_con_handle_t con_handle)
 
static gatt_client_tprovide_context_for_conn_handle_and_start_timer (hci_con_handle_t con_handle)
 
static void report_gatt_all_characteristic_descriptors (gatt_client_t *peripheral, uint8_t *packet, uint16_t size, uint16_t pair_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)
 
static void report_gatt_characteristic_value (gatt_client_t *peripheral, uint16_t attribute_handle, uint8_t *value, uint16_t length)
 
static void report_gatt_characteristics (gatt_client_t *peripheral, uint8_t *packet, uint16_t size)
 
static void report_gatt_included_service_uuid128 (gatt_client_t *peripheral, uint16_t include_handle, uint8_t *uuid128)
 
static void report_gatt_included_service_uuid16 (gatt_client_t *peripheral, uint16_t include_handle, uint16_t uuid16)
 
static void report_gatt_indication (hci_con_handle_t con_handle, uint16_t value_handle, uint8_t *value, int length)
 
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)
 
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)
 
static void report_gatt_notification (hci_con_handle_t con_handle, uint16_t value_handle, uint8_t *value, int length)
 
static void report_gatt_services (gatt_client_t *peripheral, uint8_t *packet, uint16_t size)
 
static void send_gatt_by_uuid_request (gatt_client_t *peripheral, uint16_t attribute_group_type)
 
static void send_gatt_cancel_prepared_write_request (gatt_client_t *peripheral)
 
static void send_gatt_characteristic_descriptor_request (gatt_client_t *peripheral)
 
static void send_gatt_characteristic_request (gatt_client_t *peripheral)
 
static void send_gatt_execute_write_request (gatt_client_t *peripheral)
 
static void send_gatt_included_service_request (gatt_client_t *peripheral)
 
static void send_gatt_included_service_uuid_request (gatt_client_t *peripheral)
 
static void send_gatt_prepare_write_request (gatt_client_t *peripheral)
 
static void send_gatt_read_blob_request (gatt_client_t *peripheral)
 
static void send_gatt_read_by_type_request (gatt_client_t *peripheral)
 
static void send_gatt_read_characteristic_descriptor_request (gatt_client_t *peripheral)
 
static void send_gatt_read_characteristic_value_request (gatt_client_t *peripheral)
 
static void send_gatt_read_client_characteristic_configuration_request (gatt_client_t *peripheral)
 
static void send_gatt_read_multiple_request (gatt_client_t *peripheral)
 
static void send_gatt_services_by_uuid_request (gatt_client_t *peripheral)
 
static void send_gatt_services_request (gatt_client_t *peripheral)
 
static void send_gatt_write_attribute_value_request (gatt_client_t *peripheral)
 
static void send_gatt_write_client_characteristic_configuration_request (gatt_client_t *peripheral)
 
static uint8_t * setup_characteristic_value_packet (uint8_t type, hci_con_handle_t con_handle, uint16_t attribute_handle, uint8_t *value, uint16_t length)
 
static uint8_t * setup_long_characteristic_value_packet (uint8_t type, hci_con_handle_t con_handle, uint16_t attribute_handle, uint16_t offset, uint8_t *value, uint16_t length)
 
static void trigger_next_blob_query (gatt_client_t *peripheral, gatt_client_state_t next_query_state, uint16_t received_blob_length)
 
static void trigger_next_characteristic_descriptor_query (gatt_client_t *peripheral, uint16_t last_result_handle)
 
static void trigger_next_characteristic_query (gatt_client_t *peripheral, uint16_t last_result_handle)
 
static void trigger_next_included_service_query (gatt_client_t *peripheral, uint16_t last_result_handle)
 
static void trigger_next_prepare_write_query (gatt_client_t *peripheral, gatt_client_state_t next_query_state, gatt_client_state_t done_state)
 
static void trigger_next_query (gatt_client_t *peripheral, uint16_t last_result_handle, gatt_client_state_t next_query_state)
 
static void trigger_next_read_by_type_query (gatt_client_t *peripheral, uint16_t last_result_handle)
 
static void trigger_next_service_by_uuid_query (gatt_client_t *peripheral, uint16_t last_result_handle)
 
static void trigger_next_service_query (gatt_client_t *peripheral, uint16_t last_result_handle)
 
static uint16_t write_blob_length (gatt_client_t *peripheral)
 

Variables

static const int characteristic_value_event_header_size = 8
 
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 const int long_characteristic_value_event_header_size = 10
 
static uint8_t pts_suppress_mtu_exchange
 

#define __BTSTACK_FILE__   "gatt_client.c"

static void att_execute_write_request ( uint16_t  request_type,
uint16_t  peripheral_handle,
uint8_t  execute_write 
)
static
static void att_find_by_type_value_request ( uint16_t  request_type,
uint16_t  attribute_group_type,
uint16_t  peripheral_handle,
uint16_t  start_handle,
uint16_t  end_handle,
uint8_t *  value,
uint16_t  value_size 
)
static
static void att_find_information_request ( uint16_t  request_type,
uint16_t  peripheral_handle,
uint16_t  start_handle,
uint16_t  end_handle 
)
static
static void att_prepare_write_request ( uint16_t  request_type,
uint16_t  peripheral_handle,
uint16_t  attribute_handle,
uint16_t  value_offset,
uint16_t  blob_length,
uint8_t *  value 
)
static
static void att_read_blob_request ( uint16_t  request_type,
uint16_t  peripheral_handle,
uint16_t  attribute_handle,
uint16_t  value_offset 
)
static
static void att_read_by_type_or_group_request_for_uuid128 ( uint16_t  request_type,
uint8_t *  uuid128,
uint16_t  peripheral_handle,
uint16_t  start_handle,
uint16_t  end_handle 
)
static
static void att_read_by_type_or_group_request_for_uuid16 ( uint16_t  request_type,
uint16_t  uuid16,
uint16_t  peripheral_handle,
uint16_t  start_handle,
uint16_t  end_handle 
)
static
static void att_read_multiple_request ( uint16_t  peripheral_handle,
uint16_t  num_value_handles,
uint16_t *  value_handles 
)
static
static void att_write_request ( uint16_t  request_type,
uint16_t  peripheral_handle,
uint16_t  attribute_handle,
uint16_t  value_length,
uint8_t *  value 
)
static
static void characteristic_start_found ( gatt_client_t peripheral,
uint16_t  start_handle,
uint8_t  properties,
uint16_t  value_handle,
uint8_t *  uuid,
uint16_t  uuid_length 
)
static
static void emit_gatt_all_characteristic_descriptors_result_event ( gatt_client_t peripheral,
uint16_t  descriptor_handle,
uint8_t *  uuid128 
)
static
static void emit_gatt_characteristic_query_result_event ( gatt_client_t peripheral,
uint16_t  start_handle,
uint16_t  value_handle,
uint16_t  end_handle,
uint16_t  properties,
uint8_t *  uuid128 
)
static
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 
)
static
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 
)
static
static void gatt_client_att_packet_handler ( uint8_t  packet_type,
uint16_t  handle,
uint8_t *  packet,
uint16_t  size 
)
static

References ATT_DATA_PACKET, ATT_ERROR_ATTRIBUTE_NOT_FOUND, ATT_ERROR_DATA_MISMATCH, ATT_ERROR_RESPONSE, ATT_EXCHANGE_MTU_RESPONSE, ATT_EXECUTE_WRITE_RESPONSE, ATT_FIND_BY_TYPE_VALUE_RESPONSE, ATT_FIND_INFORMATION_REPLY, ATT_HANDLE_VALUE_INDICATION, ATT_HANDLE_VALUE_NOTIFICATION, ATT_PREPARE_WRITE_RESPONSE, ATT_READ_BLOB_RESPONSE, ATT_READ_BY_GROUP_TYPE_RESPONSE, ATT_READ_BY_TYPE_RESPONSE, ATT_READ_MULTIPLE_RESPONSE, ATT_READ_RESPONSE, ATT_WRITE_RESPONSE, gatt_client::attribute_handle, gatt_client::attribute_offset, characteristic_end_found(), gatt_client::client_characteristic_configuration_handle, emit_gatt_complete_event(), emit_gatt_service_query_result_event(), gatt_client::end_group_handle, gatt_client_handle_transaction_complete(), gatt_client_report_error_if_pending(), gatt_client_run(), gatt_client::gatt_client_state, get_gatt_client_context_for_handle(), get_last_result_handle_from_characteristics_list(), get_last_result_handle_from_included_services_list(), get_last_result_handle_from_service_list(), HCI_EVENT_PACKET, is_value_valid(), L2CAP_EVENT_CAN_SEND_NOW, l2cap_max_le_mtu(), little_endian_read_16(), log_info, gatt_client::mtu, MTU_EXCHANGED, gatt_client::mtu_state, P_W2_CANCEL_PREPARED_WRITE_DATA_MISMATCH, P_W2_EXECUTE_PREPARED_WRITE, P_W2_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR, P_W2_PREPARE_RELIABLE_WRITE, P_W2_PREPARE_WRITE, P_W2_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR, P_W2_SEND_INCLUDED_SERVICE_WITH_UUID_QUERY, P_W2_SEND_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_QUERY, P_W2_SEND_READ_BLOB_QUERY, P_W2_WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION, P_W4_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT, P_W4_ALL_CHARACTERISTICS_OF_SERVICE_QUERY_RESULT, P_W4_CANCEL_PREPARED_WRITE_DATA_MISMATCH_RESULT, P_W4_CANCEL_PREPARED_WRITE_RESULT, P_W4_CHARACTERISTIC_WITH_UUID_QUERY_RESULT, P_W4_CLIENT_CHARACTERISTIC_CONFIGURATION_RESULT, P_W4_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT, P_W4_EXECUTE_PREPARED_WRITE_RESULT, P_W4_INCLUDED_SERVICE_QUERY_RESULT, P_W4_INCLUDED_SERVICE_UUID_WITH_QUERY_RESULT, P_W4_PREPARE_RELIABLE_WRITE_RESULT, P_W4_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT, P_W4_PREPARE_WRITE_RESULT, P_W4_PREPARE_WRITE_SINGLE_RESULT, P_W4_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_RESULT, P_W4_READ_BLOB_RESULT, P_W4_READ_BY_TYPE_RESPONSE, P_W4_READ_CHARACTERISTIC_DESCRIPTOR_RESULT, P_W4_READ_CHARACTERISTIC_VALUE_RESULT, P_W4_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY_RESULT, P_W4_READ_MULTIPLE_RESPONSE, P_W4_SERVICE_QUERY_RESULT, P_W4_SERVICE_WITH_UUID_RESULT, P_W4_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT, P_W4_WRITE_CHARACTERISTIC_VALUE_RESULT, provide_context_for_conn_handle(), gatt_client::query_end_handle, gatt_client::query_start_handle, report_gatt_all_characteristic_descriptors(), report_gatt_characteristic_descriptor(), report_gatt_characteristic_value(), report_gatt_characteristics(), report_gatt_included_service_uuid128(), report_gatt_included_service_uuid16(), report_gatt_indication(), report_gatt_long_characteristic_descriptor(), report_gatt_long_characteristic_value_blob(), report_gatt_notification(), report_gatt_services(), reverse_128(), gatt_client::send_confirmation, gatt_client::start_group_handle, trigger_next_blob_query(), trigger_next_characteristic_descriptor_query(), trigger_next_characteristic_query(), trigger_next_included_service_query(), trigger_next_prepare_write_query(), trigger_next_read_by_type_query(), trigger_next_service_by_uuid_query(), trigger_next_service_query(), and gatt_client::uuid128.

Referenced by gatt_client_init().

void gatt_client_deserialize_characteristic_descriptor ( const uint8_t *  packet,
int  offset,
gatt_client_characteristic_descriptor_t descriptor 
)
uint8_t gatt_client_discover_characteristic_descriptors ( btstack_packet_handler_t  callback,
hci_con_handle_t  con_handle,
gatt_client_characteristic_t characteristic 
)

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.

References BTSTACK_MEMORY_ALLOC_FAILED, callback, gatt_client::callback, emit_gatt_complete_event(), gatt_client::end_group_handle, gatt_client_characteristic_t::end_handle, GATT_CLIENT_IN_WRONG_STATE, gatt_client_run(), gatt_client::gatt_client_state, is_ready(), P_W2_SEND_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY, provide_context_for_conn_handle_and_start_timer(), gatt_client::start_group_handle, and gatt_client_characteristic_t::value_handle.

uint8_t gatt_client_discover_characteristics_for_handle_range_by_uuid16 ( btstack_packet_handler_t  callback,
hci_con_handle_t  con_handle,
uint16_t  start_handle,
uint16_t  end_handle,
uint16_t  uuid16 
)

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.

References BTSTACK_MEMORY_ALLOC_FAILED, callback, gatt_client::callback, gatt_client::characteristic_start_handle, gatt_client::end_group_handle, gatt_client::filter_with_uuid, GATT_CLIENT_IN_WRONG_STATE, gatt_client_run(), gatt_client::gatt_client_state, is_ready(), P_W2_SEND_CHARACTERISTIC_WITH_UUID_QUERY, provide_context_for_conn_handle_and_start_timer(), gatt_client::start_group_handle, gatt_client::uuid128, gatt_client::uuid16, and uuid_add_bluetooth_prefix().

Referenced by gatt_client_discover_characteristics_for_service_by_uuid16().

uint8_t gatt_client_discover_characteristics_for_service ( btstack_packet_handler_t  callback,
hci_con_handle_t  con_handle,
gatt_client_service_t service 
)

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.

References BTSTACK_MEMORY_ALLOC_FAILED, callback, gatt_client::callback, gatt_client::characteristic_start_handle, gatt_client::end_group_handle, gatt_client_service_t::end_group_handle, gatt_client::filter_with_uuid, GATT_CLIENT_IN_WRONG_STATE, gatt_client_run(), gatt_client::gatt_client_state, is_ready(), P_W2_SEND_ALL_CHARACTERISTICS_OF_SERVICE_QUERY, provide_context_for_conn_handle_and_start_timer(), gatt_client::start_group_handle, and gatt_client_service_t::start_group_handle.

Referenced by handle_hci_event().

uint8_t gatt_client_discover_characteristics_for_service_by_uuid128 ( btstack_packet_handler_t  callback,
uint16_t  handle,
gatt_client_service_t service,
uint8_t *  uuid128 
)
uint8_t gatt_client_discover_characteristics_for_service_by_uuid16 ( btstack_packet_handler_t  callback,
uint16_t  handle,
gatt_client_service_t service,
uint16_t  uuid16 
)
uint8_t gatt_client_discover_primary_services ( btstack_packet_handler_t  callback,
hci_con_handle_t  con_handle 
)

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.

References BTSTACK_MEMORY_ALLOC_FAILED, callback, gatt_client::callback, gatt_client::end_group_handle, GATT_CLIENT_IN_WRONG_STATE, gatt_client_run(), gatt_client::gatt_client_state, is_ready(), P_W2_SEND_SERVICE_QUERY, provide_context_for_conn_handle_and_start_timer(), gatt_client::start_group_handle, and gatt_client::uuid16.

uint8_t gatt_client_discover_primary_services_by_uuid16 ( btstack_packet_handler_t  callback,
hci_con_handle_t  con_handle,
uint16_t  uuid16 
)

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.

References BTSTACK_MEMORY_ALLOC_FAILED, callback, gatt_client::callback, gatt_client::end_group_handle, GATT_CLIENT_IN_WRONG_STATE, gatt_client_run(), gatt_client::gatt_client_state, is_ready(), P_W2_SEND_SERVICE_WITH_UUID_QUERY, provide_context_for_conn_handle_and_start_timer(), gatt_client::start_group_handle, gatt_client::uuid128, gatt_client::uuid16, and uuid_add_bluetooth_prefix().

uint8_t gatt_client_find_included_services_for_service ( btstack_packet_handler_t  callback,
hci_con_handle_t  con_handle,
gatt_client_service_t service 
)

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.

References BTSTACK_MEMORY_ALLOC_FAILED, callback, gatt_client::callback, gatt_client::end_group_handle, gatt_client_service_t::end_group_handle, GATT_CLIENT_IN_WRONG_STATE, gatt_client_run(), gatt_client::gatt_client_state, is_ready(), P_W2_SEND_INCLUDED_SERVICE_QUERY, provide_context_for_conn_handle_and_start_timer(), gatt_client::start_group_handle, and gatt_client_service_t::start_group_handle.

uint8_t gatt_client_get_mtu ( hci_con_handle_t  con_handle,
uint16_t *  mtu 
)

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.

References ATT_DEFAULT_MTU, GATT_CLIENT_IN_WRONG_STATE, gatt_client::mtu, MTU_EXCHANGED, gatt_client::mtu_state, and provide_context_for_conn_handle().

static void gatt_client_hci_event_packet_handler ( uint8_t  packet_type,
uint16_t  channel,
uint8_t *  packet,
uint16_t  size 
)
static
int gatt_client_is_ready ( hci_con_handle_t  con_handle)

Returns if the GATT client is ready to receive a query.

It is used with daemon.

References is_ready(), and provide_context_for_conn_handle().

void gatt_client_listen_for_characteristic_value_updates ( gatt_client_notification_t notification,
btstack_packet_handler_t  packet_handler,
hci_con_handle_t  con_handle,
gatt_client_characteristic_t characteristic 
)

Register for notifications and indications of a characteristic enabled by gatt_client_write_client_characteristic_configuration.

Parameters
notificationstruct used to store registration
packet_handler
con_handle
characteristic

References gatt_client_notification::attribute_handle, btstack_linked_list_add(), gatt_client_notification::callback, con_handle, gatt_client_notification::con_handle, packet_handler, and gatt_client_characteristic_t::value_handle.

Referenced by handle_hci_event().

void gatt_client_pts_suppress_mtu_exchange ( void  )
uint8_t gatt_client_read_characteristic_descriptor ( btstack_packet_handler_t  callback,
hci_con_handle_t  con_handle,
gatt_client_characteristic_descriptor_t descriptor 
)

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.

References gatt_client_read_characteristic_descriptor_using_descriptor_handle(), and gatt_client_characteristic_descriptor_t::handle.

uint8_t gatt_client_read_long_characteristic_descriptor ( btstack_packet_handler_t  callback,
hci_con_handle_t  con_handle,
gatt_client_characteristic_descriptor_t descriptor 
)

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.

References gatt_client_read_long_characteristic_descriptor_using_descriptor_handle(), and gatt_client_characteristic_descriptor_t::handle.

uint8_t gatt_client_read_long_characteristic_descriptor_using_descriptor_handle ( btstack_packet_handler_t  callback,
hci_con_handle_t  con_handle,
uint16_t  descriptor_handle 
)
uint8_t gatt_client_read_long_value_of_characteristic ( btstack_packet_handler_t  callback,
hci_con_handle_t  con_handle,
gatt_client_characteristic_t characteristic 
)

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.

References gatt_client_read_long_value_of_characteristic_using_value_handle(), and gatt_client_characteristic_t::value_handle.

uint8_t gatt_client_read_long_value_of_characteristic_using_value_handle ( btstack_packet_handler_t  callback,
hci_con_handle_t  con_handle,
uint16_t  characteristic_value_handle 
)
uint8_t gatt_client_read_value_of_characteristic ( btstack_packet_handler_t  callback,
hci_con_handle_t  con_handle,
gatt_client_characteristic_t characteristic 
)

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.

References gatt_client_read_value_of_characteristic_using_value_handle(), and gatt_client_characteristic_t::value_handle.

uint8_t gatt_client_read_value_of_characteristics_by_uuid16 ( btstack_packet_handler_t  callback,
hci_con_handle_t  con_handle,
uint16_t  start_handle,
uint16_t  end_handle,
uint16_t  uuid16 
)

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.

References BTSTACK_MEMORY_ALLOC_FAILED, callback, gatt_client::callback, gatt_client::end_group_handle, GATT_CLIENT_IN_WRONG_STATE, gatt_client_run(), gatt_client::gatt_client_state, is_ready(), P_W2_SEND_READ_BY_TYPE_REQUEST, provide_context_for_conn_handle_and_start_timer(), gatt_client::query_end_handle, gatt_client::query_start_handle, gatt_client::start_group_handle, gatt_client::uuid128, gatt_client::uuid16, and uuid_add_bluetooth_prefix().

uint8_t gatt_client_reliable_write_long_value_of_characteristic ( btstack_packet_handler_t  callback,
hci_con_handle_t  con_handle,
uint16_t  characteristic_value_handle,
uint16_t  length,
uint8_t *  data 
)

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.

References gatt_client::attribute_handle, gatt_client::attribute_length, gatt_client::attribute_offset, gatt_client::attribute_value, BTSTACK_MEMORY_ALLOC_FAILED, callback, gatt_client::callback, GATT_CLIENT_IN_WRONG_STATE, gatt_client_run(), gatt_client::gatt_client_state, is_ready(), P_W2_PREPARE_RELIABLE_WRITE, and provide_context_for_conn_handle_and_start_timer().

static void gatt_client_report_error_if_pending ( gatt_client_t peripheral,
uint8_t  error_code 
)
static
static void gatt_client_run ( void  )
static

References att_confirmation(), att_dispatch_client_can_send_now(), att_dispatch_client_request_can_send_now_event(), ATT_ERROR_INVALID_ATTRIBUTE_VALUE_LENGTH, att_exchange_mtu_request(), ATT_SIGNED_WRITE_COMMAND, gatt_client::attribute_handle, gatt_client::attribute_length, gatt_client::attribute_value, gatt_client::con_handle, emit_gatt_complete_event(), gatt_client_handle_transaction_complete(), gatt_client::gatt_client_state, gatt_client::le_device_index, log_error, gatt_client::mtu_state, btstack_linked_item::next, P_READY, P_W2_CANCEL_PREPARED_WRITE, P_W2_CANCEL_PREPARED_WRITE_DATA_MISMATCH, P_W2_EXECUTE_PREPARED_WRITE, P_W2_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR, P_W2_PREPARE_RELIABLE_WRITE, P_W2_PREPARE_WRITE, P_W2_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR, P_W2_PREPARE_WRITE_SINGLE, P_W2_SEND_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY, P_W2_SEND_ALL_CHARACTERISTICS_OF_SERVICE_QUERY, P_W2_SEND_CHARACTERISTIC_WITH_UUID_QUERY, P_W2_SEND_INCLUDED_SERVICE_QUERY, P_W2_SEND_INCLUDED_SERVICE_WITH_UUID_QUERY, P_W2_SEND_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_QUERY, P_W2_SEND_READ_BLOB_QUERY, P_W2_SEND_READ_BY_TYPE_REQUEST, P_W2_SEND_READ_CHARACTERISTIC_DESCRIPTOR_QUERY, P_W2_SEND_READ_CHARACTERISTIC_VALUE_QUERY, P_W2_SEND_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY, P_W2_SEND_READ_MULTIPLE_REQUEST, P_W2_SEND_SERVICE_QUERY, P_W2_SEND_SERVICE_WITH_UUID_QUERY, P_W2_SEND_SIGNED_WRITE, P_W2_SEND_WRITE_CHARACTERISTIC_DESCRIPTOR, P_W2_SEND_WRITE_CHARACTERISTIC_VALUE, P_W2_WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION, P_W4_ALL_CHARACTERISTICS_OF_SERVICE_QUERY_RESULT, P_W4_CANCEL_PREPARED_WRITE_DATA_MISMATCH_RESULT, P_W4_CANCEL_PREPARED_WRITE_RESULT, P_W4_CHARACTERISTIC_WITH_UUID_QUERY_RESULT, P_W4_CLIENT_CHARACTERISTIC_CONFIGURATION_RESULT, P_W4_CMAC_READY, P_W4_CMAC_RESULT, P_W4_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT, P_W4_EXECUTE_PREPARED_WRITE_RESULT, P_W4_INCLUDED_SERVICE_QUERY_RESULT, P_W4_INCLUDED_SERVICE_UUID_WITH_QUERY_RESULT, P_W4_PREPARE_RELIABLE_WRITE_RESULT, P_W4_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT, P_W4_PREPARE_WRITE_RESULT, P_W4_PREPARE_WRITE_SINGLE_RESULT, P_W4_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_RESULT, P_W4_READ_BLOB_RESULT, P_W4_READ_BY_TYPE_RESPONSE, P_W4_READ_CHARACTERISTIC_DESCRIPTOR_RESULT, P_W4_READ_CHARACTERISTIC_VALUE_RESULT, P_W4_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY_RESULT, P_W4_READ_MULTIPLE_RESPONSE, P_W4_SEND_SINGED_WRITE_DONE, P_W4_SERVICE_QUERY_RESULT, P_W4_SERVICE_WITH_UUID_RESULT, P_W4_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT, P_W4_WRITE_CHARACTERISTIC_VALUE_RESULT, peripheral_mtu(), gatt_client::send_confirmation, send_gatt_cancel_prepared_write_request(), send_gatt_characteristic_descriptor_request(), send_gatt_characteristic_request(), send_gatt_execute_write_request(), send_gatt_included_service_request(), send_gatt_included_service_uuid_request(), send_gatt_prepare_write_request(), send_gatt_read_blob_request(), send_gatt_read_by_type_request(), send_gatt_read_characteristic_descriptor_request(), send_gatt_read_characteristic_value_request(), send_gatt_read_client_characteristic_configuration_request(), send_gatt_read_multiple_request(), send_gatt_services_by_uuid_request(), send_gatt_services_request(), send_gatt_write_attribute_value_request(), send_gatt_write_client_characteristic_configuration_request(), SEND_MTU_EXCHANGE, SENT_MTU_EXCHANGE, sm_cmac_ready(), and sm_cmac_signed_write_start().

Referenced by gatt_client_att_packet_handler(), gatt_client_cancel_write(), gatt_client_discover_characteristic_descriptors(), gatt_client_discover_characteristics_for_handle_range_by_uuid128(), gatt_client_discover_characteristics_for_handle_range_by_uuid16(), gatt_client_discover_characteristics_for_service(), gatt_client_discover_primary_services(), gatt_client_discover_primary_services_by_uuid128(), gatt_client_discover_primary_services_by_uuid16(), gatt_client_execute_write(), gatt_client_find_included_services_for_service(), gatt_client_hci_event_packet_handler(), gatt_client_prepare_write(), gatt_client_read_characteristic_descriptor_using_descriptor_handle(), gatt_client_read_long_characteristic_descriptor_using_descriptor_handle_with_offset(), gatt_client_read_long_value_of_characteristic_using_value_handle_with_offset(), gatt_client_read_multiple_characteristic_values(), gatt_client_read_value_of_characteristic_using_value_handle(), gatt_client_read_value_of_characteristics_by_uuid128(), gatt_client_read_value_of_characteristics_by_uuid16(), gatt_client_reliable_write_long_value_of_characteristic(), gatt_client_write_characteristic_descriptor_using_descriptor_handle(), gatt_client_write_client_characteristic_configuration(), gatt_client_write_long_characteristic_descriptor_using_descriptor_handle_with_offset(), gatt_client_write_long_value_of_characteristic_with_offset(), and gatt_client_write_value_of_characteristic().

void gatt_client_stop_listening_for_characteristic_value_updates ( gatt_client_notification_t notification)

Stop listening to characteristic value updates registered with gatt_client_listen_for_characteristic_value_updates.

Parameters
notificationstruct used in gatt_client_listen_for_characteristic_value_updates

References btstack_linked_list_remove().

static void gatt_client_timeout_stop ( gatt_client_t peripheral)
static
uint8_t gatt_client_write_characteristic_descriptor ( btstack_packet_handler_t  callback,
hci_con_handle_t  con_handle,
gatt_client_characteristic_descriptor_t descriptor,
uint16_t  length,
uint8_t *  data 
)

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.

References gatt_client_write_characteristic_descriptor_using_descriptor_handle(), and gatt_client_characteristic_descriptor_t::handle.

uint8_t gatt_client_write_client_characteristic_configuration ( btstack_packet_handler_t  callback,
hci_con_handle_t  con_handle,
gatt_client_characteristic_t characteristic,
uint16_t  configuration 
)
uint8_t gatt_client_write_long_characteristic_descriptor ( btstack_packet_handler_t  callback,
hci_con_handle_t  con_handle,
gatt_client_characteristic_descriptor_t descriptor,
uint16_t  length,
uint8_t *  value 
)
uint8_t gatt_client_write_long_characteristic_descriptor_using_descriptor_handle ( btstack_packet_handler_t  callback,
hci_con_handle_t  con_handle,
uint16_t  descriptor_handle,
uint16_t  length,
uint8_t *  data 
)
uint8_t gatt_client_write_long_value_of_characteristic ( btstack_packet_handler_t  callback,
hci_con_handle_t  con_handle,
uint16_t  value_handle,
uint16_t  value_length,
uint8_t *  value 
)
uint8_t gatt_client_write_value_of_characteristic ( btstack_packet_handler_t  callback,
hci_con_handle_t  con_handle,
uint16_t  characteristic_value_handle,
uint16_t  length,
uint8_t *  data 
)

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.

References gatt_client::attribute_handle, gatt_client::attribute_length, gatt_client::attribute_value, BTSTACK_MEMORY_ALLOC_FAILED, callback, gatt_client::callback, GATT_CLIENT_IN_WRONG_STATE, gatt_client_run(), gatt_client::gatt_client_state, is_ready(), P_W2_SEND_WRITE_CHARACTERISTIC_VALUE, and provide_context_for_conn_handle_and_start_timer().

Referenced by handle_hci_event().

uint8_t gatt_client_write_value_of_characteristic_without_response ( hci_con_handle_t  con_handle,
uint16_t  value_handle,
uint16_t  value_length,
uint8_t *  value 
)

Writes the characteristic value using the characteristic's value handle without an acknowledgment that the write was successfully performed.

References att_dispatch_client_can_send_now(), ATT_WRITE_COMMAND, att_write_request(), BTSTACK_MEMORY_ALLOC_FAILED, gatt_client::con_handle, GATT_CLIENT_BUSY, GATT_CLIENT_IN_WRONG_STATE, GATT_CLIENT_VALUE_TOO_LONG, is_ready(), peripheral_mtu(), and provide_context_for_conn_handle().

static gatt_client_t* get_gatt_client_context_for_handle ( uint16_t  handle)
static
static uint16_t get_last_result_handle_from_characteristics_list ( uint8_t *  packet,
uint16_t  size 
)
static
static uint16_t get_last_result_handle_from_included_services_list ( uint8_t *  packet,
uint16_t  size 
)
static
static uint16_t get_last_result_handle_from_service_list ( uint8_t *  packet,
uint16_t  size 
)
static
static int is_query_done ( gatt_client_t peripheral,
uint16_t  last_result_handle 
)
static
static int is_ready ( gatt_client_t context)
static

References gatt_client::gatt_client_state, and P_READY.

Referenced by gatt_client_cancel_write(), gatt_client_discover_characteristic_descriptors(), gatt_client_discover_characteristics_for_handle_range_by_uuid128(), gatt_client_discover_characteristics_for_handle_range_by_uuid16(), gatt_client_discover_characteristics_for_service(), gatt_client_discover_primary_services(), gatt_client_discover_primary_services_by_uuid128(), gatt_client_discover_primary_services_by_uuid16(), gatt_client_execute_write(), gatt_client_find_included_services_for_service(), gatt_client_is_ready(), gatt_client_prepare_write(), gatt_client_read_characteristic_descriptor_using_descriptor_handle(), gatt_client_read_long_characteristic_descriptor_using_descriptor_handle_with_offset(), gatt_client_read_long_value_of_characteristic_using_value_handle_with_offset(), gatt_client_read_multiple_characteristic_values(), gatt_client_read_value_of_characteristic_using_value_handle(), gatt_client_read_value_of_characteristics_by_uuid128(), gatt_client_read_value_of_characteristics_by_uuid16(), gatt_client_reliable_write_long_value_of_characteristic(), gatt_client_report_error_if_pending(), gatt_client_write_characteristic_descriptor_using_descriptor_handle(), gatt_client_write_client_characteristic_configuration(), gatt_client_write_long_characteristic_descriptor_using_descriptor_handle_with_offset(), gatt_client_write_long_value_of_characteristic_with_offset(), gatt_client_write_value_of_characteristic(), and gatt_client_write_value_of_characteristic_without_response().

static int is_value_valid ( gatt_client_t peripheral,
uint8_t *  packet,
uint16_t  size 
)
static
static gatt_client_t* provide_context_for_conn_handle_and_start_timer ( hci_con_handle_t  con_handle)
static
static void report_gatt_all_characteristic_descriptors ( gatt_client_t peripheral,
uint8_t *  packet,
uint16_t  size,
uint16_t  pair_size 
)
static
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 
)
static
static void report_gatt_characteristic_value ( gatt_client_t peripheral,
uint16_t  attribute_handle,
uint8_t *  value,
uint16_t  length 
)
static
static void report_gatt_characteristics ( gatt_client_t peripheral,
uint8_t *  packet,
uint16_t  size 
)
static
static void report_gatt_included_service_uuid128 ( gatt_client_t peripheral,
uint16_t  include_handle,
uint8_t *  uuid128 
)
static
static void report_gatt_included_service_uuid16 ( gatt_client_t peripheral,
uint16_t  include_handle,
uint16_t  uuid16 
)
static
static void report_gatt_indication ( hci_con_handle_t  con_handle,
uint16_t  value_handle,
uint8_t *  value,
int  length 
)
static
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 
)
static
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 
)
static
static void report_gatt_notification ( hci_con_handle_t  con_handle,
uint16_t  value_handle,
uint8_t *  value,
int  length 
)
static
static void report_gatt_services ( gatt_client_t peripheral,
uint8_t *  packet,
uint16_t  size 
)
static
static void send_gatt_cancel_prepared_write_request ( gatt_client_t peripheral)
static
static void send_gatt_characteristic_descriptor_request ( gatt_client_t peripheral)
static
static void send_gatt_execute_write_request ( gatt_client_t peripheral)
static
static void send_gatt_included_service_uuid_request ( gatt_client_t peripheral)
static
static void send_gatt_read_blob_request ( gatt_client_t peripheral)
static
static void send_gatt_read_characteristic_descriptor_request ( gatt_client_t peripheral)
static
static void send_gatt_read_characteristic_value_request ( gatt_client_t peripheral)
static
static void send_gatt_read_multiple_request ( gatt_client_t peripheral)
static
static void send_gatt_services_by_uuid_request ( gatt_client_t peripheral)
static
static void send_gatt_write_attribute_value_request ( gatt_client_t peripheral)
static
static void send_gatt_write_client_characteristic_configuration_request ( gatt_client_t peripheral)
static
static uint8_t* setup_characteristic_value_packet ( uint8_t  type,
hci_con_handle_t  con_handle,
uint16_t  attribute_handle,
uint8_t *  value,
uint16_t  length 
)
static
static uint8_t* setup_long_characteristic_value_packet ( uint8_t  type,
hci_con_handle_t  con_handle,
uint16_t  attribute_handle,
uint16_t  offset,
uint8_t *  value,
uint16_t  length 
)
static
static void trigger_next_blob_query ( gatt_client_t peripheral,
gatt_client_state_t  next_query_state,
uint16_t  received_blob_length 
)
inlinestatic
static void trigger_next_characteristic_descriptor_query ( gatt_client_t peripheral,
uint16_t  last_result_handle 
)
inlinestatic
static void trigger_next_characteristic_query ( gatt_client_t peripheral,
uint16_t  last_result_handle 
)
inlinestatic
static void trigger_next_included_service_query ( gatt_client_t peripheral,
uint16_t  last_result_handle 
)
inlinestatic
static void trigger_next_prepare_write_query ( gatt_client_t peripheral,
gatt_client_state_t  next_query_state,
gatt_client_state_t  done_state 
)
inlinestatic
static void trigger_next_read_by_type_query ( gatt_client_t peripheral,
uint16_t  last_result_handle 
)
inlinestatic
static void trigger_next_service_by_uuid_query ( gatt_client_t peripheral,
uint16_t  last_result_handle 
)
inlinestatic
static void trigger_next_service_query ( gatt_client_t peripheral,
uint16_t  last_result_handle 
)
inlinestatic
static uint16_t write_blob_length ( gatt_client_t peripheral)
static

const int characteristic_value_event_header_size = 8
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
const int long_characteristic_value_event_header_size = 10
static
uint8_t pts_suppress_mtu_exchange
static