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

gatt client protocol core functions More...

#include "att.h"
#include "bluetooth.h"
#include "uuid.h"
#include "gatt-helpers.h"
#include "util.h"
#include "queue.h"
#include "gatt-db.h"
#include "gatt-client.h"
#include <assert.h>
#include <limits.h>
#include <sys/uio.h>

Go to the source code of this file.

Data Structures

struct  bt_gatt_client
 bluetooth GATT client structure More...
 
struct  request
 Request data structure. More...
 
struct  notify_chrc
 
struct  notify_data
 
struct  handle_range
 
struct  discovery_op
 
struct  chrc
 
struct  service_changed_op
 
struct  pdu_data
 
struct  read_op
 
struct  read_long_op
 
struct  write_op
 
struct  long_write_op
 
struct  prep_write_op
 

Macros

#define MAX(a, b)   ((a) > (b) ? (a) : (b))
 
#define MIN(a, b)   ((a) < (b) ? (a) : (b))
 
#define UUID_BYTES   (BT_GATT_UUID_SIZE * sizeof(uint8_t))
 
#define GATT_SVC_UUID   0x1801
 
#define SVC_CHNGD_UUID   0x2a05
 

Typedefs

typedef void(* discovery_op_complete_func_t )(struct discovery_op *op, bool success, uint8_t att_ecode)
 
typedef void(* discovery_op_fail_func_t )(struct discovery_op *op)
 

Functions

static struct requestrequest_ref (struct request *req)
 
static struct requestrequest_create (struct bt_gatt_client *client)
 
static void request_unref (void *data)
 
static struct notify_datanotify_data_ref (struct notify_data *notify_data)
 
static void notify_data_unref (void *data)
 
static void find_ccc (struct gatt_db_attribute *attr, void *user_data)
 
static struct notify_chrcnotify_chrc_create (struct bt_gatt_client *client, uint16_t value_handle)
 
static void notify_chrc_free (void *data)
 
static bool match_notify_data_id (const void *a, const void *b)
 
static bool match_notify_data_handle_range (const void *a, const void *b)
 
static bool match_notify_chrc_handle_range (const void *a, const void *b)
 
static void gatt_client_remove_all_notify_in_range (struct bt_gatt_client *client, uint16_t start_handle, uint16_t end_handle)
 
static void gatt_client_remove_notify_chrcs_in_range (struct bt_gatt_client *client, uint16_t start_handle, uint16_t end_handle)
 
static void discovery_op_free (struct discovery_op *op)
 
static struct discovery_opdiscovery_op_create (struct bt_gatt_client *client, uint16_t start, uint16_t end, discovery_op_complete_func_t complete_func, discovery_op_fail_func_t failure_func)
 
static struct discovery_opdiscovery_op_ref (struct discovery_op *op)
 
static void discovery_op_unref (void *data)
 
static void discovery_req_clear (struct bt_gatt_client *client)
 
static void discover_chrcs_cb (bool success, uint8_t att_ecode, struct bt_gatt_result *result, void *user_data)
 
static void discover_incl_cb (bool success, uint8_t att_ecode, struct bt_gatt_result *result, void *user_data)
 
static void discover_descs_cb (bool success, uint8_t att_ecode, struct bt_gatt_result *result, void *user_data)
 
static bool discover_descs (struct discovery_op *op, bool *discovering)
 
static void discover_secondary_cb (bool success, uint8_t att_ecode, struct bt_gatt_result *result, void *user_data)
 
static void discover_primary_cb (bool success, uint8_t att_ecode, struct bt_gatt_result *result, void *user_data)
 
static void notify_client_ready (struct bt_gatt_client *client, bool success, uint8_t att_ecode)
 
static void exchange_mtu_cb (bool success, uint8_t att_ecode, void *user_data)
 
static void process_service_changed (struct bt_gatt_client *client, uint16_t start_handle, uint16_t end_handle)
 
static void service_changed_cb (uint16_t value_handle, const uint8_t *value, uint16_t length, void *user_data)
 
static void complete_notify_request (void *data)
 
static bool notify_data_write_ccc (struct notify_data *notify_data, bool enable, bt_att_response_func_t callback)
 
static uint8_t process_error (const void *pdu, uint16_t length)
 
static void enable_ccc_callback (uint8_t opcode, const void *pdu, uint16_t length, void *user_data)
 
static bool match_notify_chrc_value_handle (const void *a, const void *b)
 
static unsigned int register_notify (struct bt_gatt_client *client, uint16_t handle, bt_gatt_client_register_callback_t callback, bt_gatt_client_notify_callback_t notify, void *user_data, bt_gatt_client_destroy_func_t destroy)
 
static void get_first_attribute (struct gatt_db_attribute *attrib, void *user_data)
 
static void service_changed_register_cb (uint16_t att_ecode, void *user_data)
 
static bool register_service_changed (struct bt_gatt_client *client)
 
static void service_changed_complete (struct discovery_op *op, bool success, uint8_t att_ecode)
 
static void service_changed_failure (struct discovery_op *op)
 
static void init_complete (struct discovery_op *op, bool success, uint8_t att_ecode)
 
static void init_fail (struct discovery_op *op)
 
static bool gatt_client_init (struct bt_gatt_client *client, uint16_t mtu)
 
static void disable_ccc_callback (uint8_t opcode, const void *pdu, uint16_t length, void *user_data)
 
static void complete_unregister_notify (void *data)
 
static void notify_handler (void *data, void *user_data)
 
static void notify_cb (uint8_t opcode, const void *pdu, uint16_t length, void *user_data)
 
static void notify_data_cleanup (void *data)
 
static void bt_gatt_client_free (struct bt_gatt_client *client)
 
static void att_disconnect_cb (int err, void *user_data)
 
struct bt_gatt_clientbt_gatt_client_new (struct gatt_db *db, struct bt_att *att, uint16_t mtu)
 
struct bt_gatt_clientbt_gatt_client_ref (struct bt_gatt_client *client)
 
void bt_gatt_client_unref (struct bt_gatt_client *client)
 
bool bt_gatt_client_is_ready (struct bt_gatt_client *client)
 
bool bt_gatt_client_set_ready_handler (struct bt_gatt_client *client, bt_gatt_client_callback_t callback, void *user_data, bt_gatt_client_destroy_func_t destroy)
 
bool bt_gatt_client_set_service_changed (struct bt_gatt_client *client, bt_gatt_client_service_changed_callback_t callback, void *user_data, bt_gatt_client_destroy_func_t destroy)
 
bool bt_gatt_client_set_debug (struct bt_gatt_client *client, bt_gatt_client_debug_func_t callback, void *user_data, bt_gatt_client_destroy_func_t destroy)
 
uint16_t bt_gatt_client_get_mtu (struct bt_gatt_client *client)
 
struct gatt_dbbt_gatt_client_get_db (struct bt_gatt_client *client)
 
static bool match_req_id (const void *a, const void *b)
 
static void cancel_long_write_cb (uint8_t opcode, const void *pdu, uint16_t len, void *user_data)
 
static bool cancel_long_write_req (struct bt_gatt_client *client, struct request *req)
 
static void cancel_prep_write_cb (uint8_t opcode, const void *pdu, uint16_t len, void *user_data)
 
static bool cancel_prep_write_session (struct bt_gatt_client *client, struct request *req)
 
static bool cancel_request (struct request *req)
 
bool bt_gatt_client_cancel (struct bt_gatt_client *client, unsigned int id)
 
bool bt_gatt_client_cancel_all (struct bt_gatt_client *client)
 
static void destroy_read_op (void *data)
 
static void read_cb (uint8_t opcode, const void *pdu, uint16_t length, void *user_data)
 
unsigned int bt_gatt_client_read_value (struct bt_gatt_client *client, uint16_t value_handle, bt_gatt_client_read_callback_t callback, void *user_data, bt_gatt_client_destroy_func_t destroy)
 
static void read_multiple_cb (uint8_t opcode, const void *pdu, uint16_t length, void *user_data)
 
unsigned int bt_gatt_client_read_multiple (struct bt_gatt_client *client, uint16_t *handles, uint8_t num_handles, bt_gatt_client_read_callback_t callback, void *user_data, bt_gatt_client_destroy_func_t destroy)
 
static void destroy_read_long_op (void *data)
 
static bool append_chunk (struct read_long_op *op, const uint8_t *data, uint16_t len)
 
static void read_long_cb (uint8_t opcode, const void *pdu, uint16_t length, void *user_data)
 
unsigned int bt_gatt_client_read_long_value (struct bt_gatt_client *client, uint16_t value_handle, uint16_t offset, bt_gatt_client_read_callback_t callback, void *user_data, bt_gatt_client_destroy_func_t destroy)
 
unsigned int bt_gatt_client_write_without_response (struct bt_gatt_client *client, uint16_t value_handle, bool signed_write, const uint8_t *value, uint16_t length)
 
static void destroy_write_op (void *data)
 
static void write_cb (uint8_t opcode, const void *pdu, uint16_t length, void *user_data)
 
unsigned int bt_gatt_client_write_value (struct bt_gatt_client *client, uint16_t value_handle, const uint8_t *value, uint16_t length, bt_gatt_client_callback_t callback, void *user_data, bt_gatt_client_destroy_func_t destroy)
 
static void long_write_op_free (void *data)
 
static void prepare_write_cb (uint8_t opcode, const void *pdu, uint16_t length, void *user_data)
 
static void complete_write_long_op (struct request *req, bool success, uint8_t att_ecode, bool reliable_error)
 
static void handle_next_prep_write (struct request *req)
 
static void start_next_long_write (struct bt_gatt_client *client)
 
static void execute_write_cb (uint8_t opcode, const void *pdu, uint16_t length, void *user_data)
 
unsigned int bt_gatt_client_write_long_value (struct bt_gatt_client *client, bool reliable, uint16_t value_handle, uint16_t offset, const uint8_t *value, uint16_t length, bt_gatt_client_write_long_callback_t callback, void *user_data, bt_gatt_client_destroy_func_t destroy)
 
static void destroy_prep_write_op (void *data)
 
static void prep_write_cb (uint8_t opcode, const void *pdu, uint16_t length, void *user_data)
 
static struct requestget_reliable_request (struct bt_gatt_client *client, unsigned int id)
 
unsigned int bt_gatt_client_prepare_write (struct bt_gatt_client *client, unsigned int id, uint16_t value_handle, uint16_t offset, const uint8_t *value, uint16_t length, bt_gatt_client_write_long_callback_t callback, void *user_data, bt_gatt_client_destroy_func_t destroy)
 
static void exec_write_cb (uint8_t opcode, const void *pdu, uint16_t length, void *user_data)
 
unsigned int bt_gatt_client_write_execute (struct bt_gatt_client *client, unsigned int id, bt_gatt_client_callback_t callback, void *user_data, bt_gatt_client_destroy_func_t destroy)
 
unsigned int bt_gatt_client_register_notify (struct bt_gatt_client *client, uint16_t chrc_value_handle, bt_gatt_client_register_callback_t callback, bt_gatt_client_notify_callback_t notify, void *user_data, bt_gatt_client_destroy_func_t destroy)
 
bool bt_gatt_client_unregister_notify (struct bt_gatt_client *client, unsigned int id)
 
bool bt_gatt_client_set_security (struct bt_gatt_client *client, int level)
 
int bt_gatt_client_get_security (struct bt_gatt_client *client)
 

Detailed Description

gatt client protocol core functions

Author
Gilbert Brault

Definition in file gatt-client.c.

Macro Definition Documentation

#define GATT_SVC_UUID   0x1801

Definition at line 56 of file gatt-client.c.

#define MAX (   a,
 
)    ((a) > (b) ? (a) : (b))

Definition at line 47 of file gatt-client.c.

Referenced by gatt_client_init().

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

Definition at line 51 of file gatt-client.c.

Referenced by bt_gatt_client_write_long_value(), and prepare_write_cb().

#define SVC_CHNGD_UUID   0x2a05

Definition at line 57 of file gatt-client.c.

Referenced by register_service_changed().

#define UUID_BYTES   (BT_GATT_UUID_SIZE * sizeof(uint8_t))

Definition at line 54 of file gatt-client.c.

Typedef Documentation

typedef void(* discovery_op_complete_func_t)(struct discovery_op *op, bool success, uint8_t att_ecode)

Definition at line 372 of file gatt-client.c.

typedef void(* discovery_op_fail_func_t)(struct discovery_op *op)

Definition at line 375 of file gatt-client.c.

Function Documentation

static bool append_chunk ( struct read_long_op op,
const uint8_t *  data,
uint16_t  len 
)
static

Definition at line 2197 of file gatt-client.c.

References BT_ATT_MAX_VALUE_LEN, read_long_op::iov, and read_long_op::offset.

Referenced by read_long_cb().

static void att_disconnect_cb ( int  err,
void *  user_data 
)
static
bool bt_gatt_client_cancel ( struct bt_gatt_client client,
unsigned int  id 
)
struct gatt_db* bt_gatt_client_get_db ( struct bt_gatt_client client)

Definition at line 1881 of file gatt-client.c.

References bt_gatt_client::db.

uint16_t bt_gatt_client_get_mtu ( struct bt_gatt_client client)

Definition at line 1873 of file gatt-client.c.

References bt_gatt_client::att, and bt_att_get_mtu().

int bt_gatt_client_get_security ( struct bt_gatt_client client)

Definition at line 3063 of file gatt-client.c.

References bt_gatt_client::att, and bt_att_get_security().

Referenced by cmd_get_security().

unsigned int bt_gatt_client_read_multiple ( struct bt_gatt_client client,
uint16_t *  handles,
uint8_t  num_handles,
bt_gatt_client_read_callback_t  callback,
void *  user_data,
bt_gatt_client_destroy_func_t  destroy 
)
unsigned int bt_gatt_client_read_value ( struct bt_gatt_client client,
uint16_t  value_handle,
bt_gatt_client_read_callback_t  callback,
void *  user_data,
bt_gatt_client_destroy_func_t  destroy 
)
struct bt_gatt_client* bt_gatt_client_ref ( struct bt_gatt_client client)
unsigned int bt_gatt_client_register_notify ( struct bt_gatt_client client,
uint16_t  chrc_value_handle,
bt_gatt_client_register_callback_t  callback,
bt_gatt_client_notify_callback_t  notify,
void *  user_data,
bt_gatt_client_destroy_func_t  destroy 
)
bool bt_gatt_client_set_debug ( struct bt_gatt_client client,
bt_gatt_client_debug_func_t  callback,
void *  user_data,
bt_gatt_client_destroy_func_t  destroy 
)
bool bt_gatt_client_set_ready_handler ( struct bt_gatt_client client,
bt_gatt_client_callback_t  callback,
void *  user_data,
bt_gatt_client_destroy_func_t  destroy 
)
bool bt_gatt_client_set_security ( struct bt_gatt_client client,
int  level 
)

Definition at line 3055 of file gatt-client.c.

References bt_gatt_client::att, and bt_att_set_security().

Referenced by cmd_set_security().

bool bt_gatt_client_set_service_changed ( struct bt_gatt_client client,
bt_gatt_client_service_changed_callback_t  callback,
void *  user_data,
bt_gatt_client_destroy_func_t  destroy 
)
void bt_gatt_client_unref ( struct bt_gatt_client client)
bool bt_gatt_client_unregister_notify ( struct bt_gatt_client client,
unsigned int  id 
)
unsigned int bt_gatt_client_write_value ( struct bt_gatt_client client,
uint16_t  value_handle,
const uint8_t *  value,
uint16_t  length,
bt_gatt_client_callback_t  callback,
void *  user_data,
bt_gatt_client_destroy_func_t  destroy 
)
unsigned int bt_gatt_client_write_without_response ( struct bt_gatt_client client,
uint16_t  value_handle,
bool  signed_write,
const uint8_t *  value,
uint16_t  length 
)
static void cancel_long_write_cb ( uint8_t  opcode,
const void *  pdu,
uint16_t  len,
void *  user_data 
)
static
static bool cancel_long_write_req ( struct bt_gatt_client client,
struct request req 
)
static
static void cancel_prep_write_cb ( uint8_t  opcode,
const void *  pdu,
uint16_t  len,
void *  user_data 
)
static
static bool cancel_prep_write_session ( struct bt_gatt_client client,
struct request req 
)
static
static void complete_notify_request ( void *  data)
static
static void destroy_prep_write_op ( void *  data)
static
static void destroy_read_long_op ( void *  data)
static
static void destroy_read_op ( void *  data)
static

Definition at line 2000 of file gatt-client.c.

References read_op::destroy, and read_op::user_data.

Referenced by bt_gatt_client_read_multiple(), and bt_gatt_client_read_value().

static void destroy_write_op ( void *  data)
static
static void disable_ccc_callback ( uint8_t  opcode,
const void *  pdu,
uint16_t  length,
void *  user_data 
)
static
static void discovery_req_clear ( struct bt_gatt_client client)
static
static void exec_write_cb ( uint8_t  opcode,
const void *  pdu,
uint16_t  length,
void *  user_data 
)
static
static void find_ccc ( struct gatt_db_attribute attr,
void *  user_data 
)
static
static void gatt_client_remove_all_notify_in_range ( struct bt_gatt_client client,
uint16_t  start_handle,
uint16_t  end_handle 
)
static
static void gatt_client_remove_notify_chrcs_in_range ( struct bt_gatt_client client,
uint16_t  start_handle,
uint16_t  end_handle 
)
static
static void get_first_attribute ( struct gatt_db_attribute attrib,
void *  user_data 
)
static

Definition at line 1331 of file gatt-client.c.

References gatt_db_attribute::user_data.

Referenced by register_service_changed().

static struct request* get_reliable_request ( struct bt_gatt_client client,
unsigned int  id 
)
static
static void init_complete ( struct discovery_op op,
bool  success,
uint8_t  att_ecode 
)
static
static void init_fail ( struct discovery_op op)
static

Definition at line 1546 of file gatt-client.c.

References discovery_op::client, bt_gatt_client::db, and gatt_db_clear().

Referenced by gatt_client_init().

static void long_write_op_free ( void *  data)
static
static bool match_notify_chrc_handle_range ( const void *  a,
const void *  b 
)
static
static bool match_notify_chrc_value_handle ( const void *  a,
const void *  b 
)
static

Definition at line 1247 of file gatt-client.c.

References PTR_TO_UINT, and notify_chrc::value_handle.

Referenced by register_notify().

static bool match_notify_data_handle_range ( const void *  a,
const void *  b 
)
static
static bool match_notify_data_id ( const void *  a,
const void *  b 
)
static

Definition at line 312 of file gatt-client.c.

References notify_data::id, and PTR_TO_UINT.

Referenced by bt_gatt_client_unregister_notify().

static bool match_req_id ( const void *  a,
const void *  b 
)
static
static void notify_cb ( uint8_t  opcode,
const void *  pdu,
uint16_t  length,
void *  user_data 
)
static
static void notify_chrc_free ( void *  data)
static
static void notify_client_ready ( struct bt_gatt_client client,
bool  success,
uint8_t  att_ecode 
)
static
static void notify_data_cleanup ( void *  data)
static
static struct notify_data* notify_data_ref ( struct notify_data notify_data)
static

Definition at line 219 of file gatt-client.c.

References notify_data::ref_count.

Referenced by notify_data_write_ccc().

static void notify_handler ( void *  data,
void *  user_data 
)
static
static void prep_write_cb ( uint8_t  opcode,
const void *  pdu,
uint16_t  length,
void *  user_data 
)
static
static uint8_t process_error ( const void *  pdu,
uint16_t  length 
)
static
static void read_cb ( uint8_t  opcode,
const void *  pdu,
uint16_t  length,
void *  user_data 
)
static
static void read_multiple_cb ( uint8_t  opcode,
const void *  pdu,
uint16_t  length,
void *  user_data 
)
static
static struct request* request_ref ( struct request req)
static
static void service_changed_cb ( uint16_t  value_handle,
const uint8_t *  value,
uint16_t  length,
void *  user_data 
)
static
static void service_changed_failure ( struct discovery_op op)
static
static void service_changed_register_cb ( uint16_t  att_ecode,
void *  user_data 
)
static
static void write_cb ( uint8_t  opcode,
const void *  pdu,
uint16_t  length,
void *  user_data 
)
static