20#ifndef H_BLE_GATTC_CACHE_PRIV_
21#define H_BLE_GATTC_CACHE_PRIV_
23#include "nimble/porting/nimble/include/modlog/modlog.h"
24#include "nimble/porting/nimble/include/os/queue.h"
25#include "nimble/nimble/host/include/host/ble_gatt.h"
26#include "nimble/nimble/include/nimble/ble.h"
27#include "nimble/nimble/host/services/gatt/include/services/gatt/ble_svc_gatt.h"
33#if MYNEWT_VAL(BLE_GATT_CACHING)
34#define BLE_GATTC_DATABASE_HASH_UUID128 0x2b2a
36 BLE_GATT_ATTR_TYPE_INCL_SRVC,
37 BLE_GATT_ATTR_TYPE_CHAR,
38 BLE_GATT_ATTR_TYPE_CHAR_DESCR,
39 BLE_GATT_ATTR_TYPE_SRVC
41typedef uint8_t ble_gatt_attr_type;
43typedef struct ble_gatt_nv_attr {
46 ble_gatt_attr_type attr_type;
49 unsigned int is_primary : 1;
54struct ble_gattc_cache_conn_dsc {
55 SLIST_ENTRY(ble_gattc_cache_conn_dsc) next;
56 struct ble_gatt_dsc dsc;
58SLIST_HEAD(ble_gattc_cache_conn_dsc_list, ble_gattc_cache_conn_dsc);
60struct ble_gattc_cache_conn_chr {
61 SLIST_ENTRY(ble_gattc_cache_conn_chr) next;
62 struct ble_gatt_chr chr;
64 struct ble_gattc_cache_conn_dsc_list dscs;
66SLIST_HEAD(ble_gattc_cache_conn_chr_list, ble_gattc_cache_conn_chr);
68struct ble_gattc_cache_conn_svc {
69 SLIST_ENTRY(ble_gattc_cache_conn_svc) next;
76 struct ble_gatt_svc svc;
78 struct ble_gattc_cache_conn_chr_list chrs;
80SLIST_HEAD(ble_gattc_cache_conn_svc_list, ble_gattc_cache_conn_svc);
82struct ble_gattc_cache_conn;
83typedef void ble_gattc_cache_conn_disc_fn(
const struct ble_gattc_cache_conn *ble_gattc_cache_conn,
int status,
void *arg);
94struct ble_gattc_cache_conn_op {
97 uint16_t start_handle;
104struct ble_gattc_cache_conn {
105 SLIST_ENTRY(ble_gattc_cache_conn) next;
107 uint16_t conn_handle;
108 ble_addr_t ble_gattc_cache_conn_addr;
110 uint8_t database_hash[16];
113 struct ble_gattc_cache_conn_svc_list svcs;
117 uint16_t disc_prev_chr_val;
118 struct ble_gattc_cache_conn_svc *cur_svc;
120 struct ble_gattc_cache_conn_op pending_op;
123 struct ble_npl_event disc_ev;
126uint16_t ble_svc_gatt_changed_handle();
127uint16_t ble_svc_gatt_hash_handle();
128uint16_t ble_svc_gatt_csf_handle();
129uint8_t ble_svc_gatt_get_csfs();
131#if MYNEWT_VAL(BLE_DYNAMIC_SERVICE)
132void ble_svc_gatt_changed(uint16_t start_handle, uint16_t end_handle);
134int ble_gattc_cache_conn_add(uint16_t conn_handle, ble_addr_t ble_gattc_cache_conn_addr);
135int ble_gattc_cache_conn_svc_add(ble_addr_t peer_addr,
const struct ble_gatt_svc *gatt_svc);
136int ble_gattc_cache_conn_inc_add(ble_addr_t peer_addr,
const struct ble_gatt_svc *gatt_svc);
137int ble_gattc_cache_conn_chr_add(ble_addr_t peer_addr, uint16_t svc_start_handle,
138 const struct ble_gatt_chr *gatt_chr);
139int ble_gattc_cache_conn_dsc_add(ble_addr_t peer_addr, uint16_t chr_val_handle,
140 const struct ble_gatt_dsc *gatt_dsc);
144int ble_gattc_cache_conn_create(uint16_t conn_handle, ble_addr_t ble_gattc_cache_conn_addr);
146void ble_gattc_cache_conn_load_hash(ble_addr_t peer_addr, uint8_t *hash_key);
147void ble_gattc_cache_conn_update(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle);
148uint16_t ble_gattc_cache_conn_get_svc_changed_handle(uint16_t conn_handle);
151void ble_gattc_cache_save(
struct ble_gattc_cache_conn *peer,
size_t num_attr);
152int ble_gattc_cache_init(
void *storage_cb);
153int ble_gattc_cache_load(ble_addr_t peer_addr);
154int ble_gattc_cache_check_hash(
struct ble_gattc_cache_conn *peer,
struct os_mbuf *om);
155void ble_gattc_cacheReset(ble_addr_t *addr);
156void ble_gattc_cache_conn_broken(uint16_t conn_handle);
157void ble_gattc_cache_conn_bonding_established(uint16_t conn_handle);
158void ble_gattc_cache_conn_bonding_restored(uint16_t conn_handle);
161int ble_gattc_cache_conn_search_all_svcs(uint16_t conn_handle,
162 ble_gatt_disc_svc_fn *cb,
void *cb_arg);
163int ble_gattc_cache_conn_search_svc_by_uuid(uint16_t conn_handle,
const ble_uuid_t *uuid,
164 ble_gatt_disc_svc_fn *cb,
void *cb_arg);
165int ble_gattc_cache_conn_search_inc_svcs(uint16_t conn_handle, uint16_t start_handle,
167 ble_gatt_disc_svc_fn *cb,
void *cb_arg);
168int ble_gattc_cache_conn_search_all_chrs(uint16_t conn_handle, uint16_t start_handle,
169 uint16_t end_handle, ble_gatt_chr_fn *cb,
171int ble_gattc_cache_conn_search_chrs_by_uuid(uint16_t conn_handle, uint16_t start_handle,
173 ble_gatt_chr_fn *cb,
void *cb_arg);
175ble_gattc_cache_conn_search_all_dscs(uint16_t conn_handle, uint16_t start_handle,
177 ble_gatt_dsc_fn *cb,
void *cb_arg);