ble_gatt_client
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
gatt-helpers.c File Reference

collection of functions to facilitate gatt implementation More...

#include "queue.h"
#include "att.h"
#include "bluetooth.h"
#include "uuid.h"
#include "gatt-helpers.h"
#include "util.h"

Go to the source code of this file.

Data Structures

struct  bt_gatt_result
 
struct  bt_gatt_request
 
struct  mtu_op
 
struct  read_incl_data
 

Macros

#define MIN(a, b)   ((a) < (b) ? (a) : (b))
 

Functions

static struct bt_gatt_resultresult_create (uint8_t opcode, const void *pdu, uint16_t pdu_len, uint16_t data_len, void *op)
 
static void result_destroy (struct bt_gatt_result *result)
 
static unsigned int result_element_count (struct bt_gatt_result *result)
 
unsigned int bt_gatt_result_service_count (struct bt_gatt_result *result)
 
unsigned int bt_gatt_result_characteristic_count (struct bt_gatt_result *result)
 
unsigned int bt_gatt_result_descriptor_count (struct bt_gatt_result *result)
 
unsigned int bt_gatt_result_included_count (struct bt_gatt_result *result)
 
bool bt_gatt_iter_init (struct bt_gatt_iter *iter, struct bt_gatt_result *result)
 
static bool convert_uuid_le (const uint8_t *src, size_t len, uint8_t dst[16])
 
static struct bt_gatt_resultresult_append (uint8_t opcode, const void *pdu, uint16_t pdu_len, uint16_t data_len, struct bt_gatt_request *op)
 
bool bt_gatt_iter_next_included_service (struct bt_gatt_iter *iter, uint16_t *handle, uint16_t *start_handle, uint16_t *end_handle, uint8_t uuid[16])
 
bool bt_gatt_iter_next_service (struct bt_gatt_iter *iter, uint16_t *start_handle, uint16_t *end_handle, uint8_t uuid[16])
 
bool bt_gatt_iter_next_characteristic (struct bt_gatt_iter *iter, uint16_t *start_handle, uint16_t *end_handle, uint16_t *value_handle, uint8_t *properties, uint8_t uuid[16])
 
bool bt_gatt_iter_next_descriptor (struct bt_gatt_iter *iter, uint16_t *handle, uint8_t uuid[16])
 
bool bt_gatt_iter_next_read_by_type (struct bt_gatt_iter *iter, uint16_t *handle, uint16_t *length, const uint8_t **value)
 
static void destroy_mtu_op (void *user_data)
 
static uint8_t process_error (const void *pdu, uint16_t length)
 
static void mtu_cb (uint8_t opcode, const void *pdu, uint16_t length, void *user_data)
 
unsigned int bt_gatt_exchange_mtu (struct bt_att *att, uint16_t client_rx_mtu, bt_gatt_result_callback_t callback, void *user_data, bt_gatt_destroy_func_t destroy)
 
static int get_uuid_len (const bt_uuid_t *uuid)
 
struct bt_gatt_requestbt_gatt_request_ref (struct bt_gatt_request *req)
 
void bt_gatt_request_unref (struct bt_gatt_request *req)
 
void bt_gatt_request_cancel (struct bt_gatt_request *req)
 
static void async_req_unref (void *data)
 
static void discovery_op_complete (struct bt_gatt_request *op, bool success, uint8_t ecode)
 
static void read_by_grp_type_cb (uint8_t opcode, const void *pdu, uint16_t length, void *user_data)
 
static void find_by_type_val_cb (uint8_t opcode, const void *pdu, uint16_t length, void *user_data)
 
static struct bt_gatt_requestdiscover_services (struct bt_att *att, bt_uuid_t *uuid, uint16_t start, uint16_t end, bt_gatt_request_callback_t callback, void *user_data, bt_gatt_destroy_func_t destroy, bool primary)
 
struct bt_gatt_requestbt_gatt_discover_all_primary_services (struct bt_att *att, bt_uuid_t *uuid, bt_gatt_request_callback_t callback, void *user_data, bt_gatt_destroy_func_t destroy)
 
struct bt_gatt_requestbt_gatt_discover_primary_services (struct bt_att *att, bt_uuid_t *uuid, uint16_t start, uint16_t end, bt_gatt_request_callback_t callback, void *user_data, bt_gatt_destroy_func_t destroy)
 
struct bt_gatt_requestbt_gatt_discover_secondary_services (struct bt_att *att, bt_uuid_t *uuid, uint16_t start, uint16_t end, bt_gatt_request_callback_t callback, void *user_data, bt_gatt_destroy_func_t destroy)
 
static struct read_incl_datanew_read_included (struct bt_gatt_result *res)
 
static struct read_incl_dataread_included_ref (struct read_incl_data *data)
 
static void read_included_unref (void *data)
 
static void discover_included_cb (uint8_t opcode, const void *pdu, uint16_t length, void *user_data)
 
static void read_included_cb (uint8_t opcode, const void *pdu, uint16_t length, void *user_data)
 
static void read_included (struct read_incl_data *data)
 
struct bt_gatt_requestbt_gatt_discover_included_services (struct bt_att *att, uint16_t start, uint16_t end, bt_gatt_request_callback_t callback, void *user_data, bt_gatt_destroy_func_t destroy)
 
static void discover_chrcs_cb (uint8_t opcode, const void *pdu, uint16_t length, void *user_data)
 
struct bt_gatt_requestbt_gatt_discover_characteristics (struct bt_att *att, uint16_t start, uint16_t end, bt_gatt_request_callback_t callback, void *user_data, bt_gatt_destroy_func_t destroy)
 
static void read_by_type_cb (uint8_t opcode, const void *pdu, uint16_t length, void *user_data)
 
bool bt_gatt_read_by_type (struct bt_att *att, uint16_t start, uint16_t end, const bt_uuid_t *uuid, bt_gatt_request_callback_t callback, void *user_data, bt_gatt_destroy_func_t destroy)
 
static void discover_descs_cb (uint8_t opcode, const void *pdu, uint16_t length, void *user_data)
 
struct bt_gatt_requestbt_gatt_discover_descriptors (struct bt_att *att, uint16_t start, uint16_t end, bt_gatt_request_callback_t callback, void *user_data, bt_gatt_destroy_func_t destroy)
 

Variables

static const uint8_t bt_base_uuid [16]
 

Detailed Description

collection of functions to facilitate gatt implementation

Author
Gilbert Brault

Definition in file gatt-helpers.c.

Macro Definition Documentation

#define MIN (   a,
 
)    ((a) < (b) ? (a) : (b))

Definition at line 46 of file gatt-helpers.c.

Referenced by mtu_cb().

Function Documentation

struct bt_gatt_request* bt_gatt_discover_all_primary_services ( struct bt_att att,
bt_uuid_t uuid,
bt_gatt_request_callback_t  callback,
void *  user_data,
bt_gatt_destroy_func_t  destroy 
)

Definition at line 925 of file gatt-helpers.c.

References bt_gatt_discover_primary_services().

Referenced by exchange_mtu_cb().

struct bt_gatt_request* bt_gatt_discover_primary_services ( struct bt_att att,
bt_uuid_t uuid,
uint16_t  start,
uint16_t  end,
bt_gatt_request_callback_t  callback,
void *  user_data,
bt_gatt_destroy_func_t  destroy 
)
struct bt_gatt_request* bt_gatt_discover_secondary_services ( struct bt_att att,
bt_uuid_t uuid,
uint16_t  start,
uint16_t  end,
bt_gatt_request_callback_t  callback,
void *  user_data,
bt_gatt_destroy_func_t  destroy 
)

Definition at line 947 of file gatt-helpers.c.

References discover_services().

Referenced by discover_primary_cb().

unsigned int bt_gatt_exchange_mtu ( struct bt_att att,
uint16_t  client_rx_mtu,
bt_gatt_result_callback_t  callback,
void *  user_data,
bt_gatt_destroy_func_t  destroy 
)

Exchange MTU trigger

msc_inline_mscgraph_1
  1. bt_gatt_exchange_mtu is called by a GATT Client with the thereafter Parameters building the mtu_op data structure (gatt_client_init in btgattclient.c case)
  2. bt_att_send is called with BT_ATT_OP_MTU_REQ op code and passing the mtu_op data structure
  3. after receiving the response message mtu_cb is called with the opcode and the mtu_op data structure
  4. mtu_cb call the user callback function (exchange_mtu_cb in the btgattclient.c case)
Parameters
attpointer to bt_att data structure
client_rx_mtumtu client size
callbackuser callback to call from mtu_cb (set in mtu_op internal data structure)
user_datapointer for user, set in the mtu_op internal data structure
destroyhousekeeping data management function set in the mtu_op internal data structure
Returns
sequence number or 0 if error

Definition at line 582 of file gatt-helpers.c.

References mtu_op::att, BT_ATT_OP_MTU_REQ, bt_att_send(), mtu_op::callback, mtu_op::client_rx_mtu, mtu_op::destroy, destroy_mtu_op(), mtu_cb(), new0, put_le16(), and mtu_op::user_data.

Referenced by gatt_client_init().

bool bt_gatt_iter_init ( struct bt_gatt_iter iter,
struct bt_gatt_result result 
)
bool bt_gatt_iter_next_characteristic ( struct bt_gatt_iter iter,
uint16_t *  start_handle,
uint16_t *  end_handle,
uint16_t *  value_handle,
uint8_t *  properties,
uint8_t  uuid[16] 
)
bool bt_gatt_iter_next_descriptor ( struct bt_gatt_iter iter,
uint16_t *  handle,
uint8_t  uuid[16] 
)
bool bt_gatt_iter_next_included_service ( struct bt_gatt_iter iter,
uint16_t *  handle,
uint16_t *  start_handle,
uint16_t *  end_handle,
uint8_t  uuid[16] 
)
bool bt_gatt_iter_next_read_by_type ( struct bt_gatt_iter iter,
uint16_t *  handle,
uint16_t *  length,
const uint8_t **  value 
)
void bt_gatt_request_cancel ( struct bt_gatt_request req)
unsigned int bt_gatt_result_characteristic_count ( struct bt_gatt_result result)
unsigned int bt_gatt_result_descriptor_count ( struct bt_gatt_result result)
unsigned int bt_gatt_result_included_count ( struct bt_gatt_result result)
unsigned int bt_gatt_result_service_count ( struct bt_gatt_result result)
static bool convert_uuid_le ( const uint8_t *  src,
size_t  len,
uint8_t  dst[16] 
)
static
static void destroy_mtu_op ( void *  user_data)
static

Definition at line 499 of file gatt-helpers.c.

References mtu_op::destroy, and mtu_op::user_data.

Referenced by bt_gatt_exchange_mtu().

static int get_uuid_len ( const bt_uuid_t uuid)
inlinestatic
static void mtu_cb ( uint8_t  opcode,
const void *  pdu,
uint16_t  length,
void *  user_data 
)
static
static struct read_incl_data* new_read_included ( struct bt_gatt_result res)
static
static uint8_t process_error ( const void *  pdu,
uint16_t  length 
)
static
static struct read_incl_data* read_included_ref ( struct read_incl_data data)
static

Definition at line 979 of file gatt-helpers.c.

References read_incl_data::ref_count.

Referenced by read_included(), and read_included_cb().

static void read_included_unref ( void *  data)
static

Definition at line 986 of file gatt-helpers.c.

References async_req_unref(), read_incl_data::op, and read_incl_data::ref_count.

Referenced by read_included(), and read_included_cb().

static struct bt_gatt_result* result_append ( uint8_t  opcode,
const void *  pdu,
uint16_t  pdu_len,
uint16_t  data_len,
struct bt_gatt_request op 
)
static
static struct bt_gatt_result* result_create ( uint8_t  opcode,
const void *  pdu,
uint16_t  pdu_len,
uint16_t  data_len,
void *  op 
)
static
static void result_destroy ( struct bt_gatt_result result)
static

Definition at line 87 of file gatt-helpers.c.

References bt_gatt_result::next, and bt_gatt_result::pdu.

Referenced by bt_gatt_request_unref().

static unsigned int result_element_count ( struct bt_gatt_result result)
static

Variable Documentation

const uint8_t bt_base_uuid[16]
static
Initial value:
= {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
}

Definition at line 199 of file gatt-helpers.c.

Referenced by convert_uuid_le().