NimBLE-Arduino 2.1.2
Loading...
Searching...
No Matches
ble_gattc_cache_priv.h
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#ifndef H_BLE_GATTC_CACHE_PRIV_
21#define H_BLE_GATTC_CACHE_PRIV_
22
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"
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#if MYNEWT_VAL(BLE_GATT_CACHING)
34#define BLE_GATTC_DATABASE_HASH_UUID128 0x2b2a
35enum {
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
40};
41typedef uint8_t ble_gatt_attr_type;
42
43typedef struct ble_gatt_nv_attr {
44 uint16_t s_handle;
45 uint16_t e_handle; /* used for service only */
46 ble_gatt_attr_type attr_type;
47 ble_uuid_any_t uuid;
48 uint8_t properties; /* used for characteristic only */
49 unsigned int is_primary : 1; /* used for service only */
50} ble_gatt_nv_attr;
51
52/* cache conn */
54struct ble_gattc_cache_conn_dsc {
55 SLIST_ENTRY(ble_gattc_cache_conn_dsc) next;
56 struct ble_gatt_dsc dsc;
57};
58SLIST_HEAD(ble_gattc_cache_conn_dsc_list, ble_gattc_cache_conn_dsc);
59
60struct ble_gattc_cache_conn_chr {
61 SLIST_ENTRY(ble_gattc_cache_conn_chr) next;
62 struct ble_gatt_chr chr;
63
64 struct ble_gattc_cache_conn_dsc_list dscs;
65};
66SLIST_HEAD(ble_gattc_cache_conn_chr_list, ble_gattc_cache_conn_chr);
67
68struct ble_gattc_cache_conn_svc {
69 SLIST_ENTRY(ble_gattc_cache_conn_svc) next;
75 uint8_t type;
76 struct ble_gatt_svc svc;
77
78 struct ble_gattc_cache_conn_chr_list chrs;
79};
80SLIST_HEAD(ble_gattc_cache_conn_svc_list, ble_gattc_cache_conn_svc);
81
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);
84enum {
85 CACHE_INVALID = 0,
86 CACHE_LOADED,
87 CACHE_VERIFIED,
88 SVC_DISC_IN_PROGRESS,
89 CHR_DISC_IN_PROGRESS,
90 INC_DISC_IN_PROGRESS,
91 DSC_DISC_IN_PROGRESS,
92 VERIFY_IN_PROGRESS
93};
94struct ble_gattc_cache_conn_op {
95 /* cb is used only when the gattc
96 request comes while the cache is building */
97 uint16_t start_handle;
98 uint16_t end_handle;
99 ble_uuid_t uuid;
100 void *cb;
101 void *cb_arg;
102 uint8_t cb_type;
103};
104struct ble_gattc_cache_conn {
105 SLIST_ENTRY(ble_gattc_cache_conn) next;
106
107 uint16_t conn_handle;
108 ble_addr_t ble_gattc_cache_conn_addr;
109
110 uint8_t database_hash[16];
111
113 struct ble_gattc_cache_conn_svc_list svcs;
114
115 uint8_t cache_state;
117 uint16_t disc_prev_chr_val;
118 struct ble_gattc_cache_conn_svc *cur_svc;
119
120 struct ble_gattc_cache_conn_op pending_op;
121 /* event to be posted to inform
122 the application about the discovery results */
123 struct ble_npl_event disc_ev;
124};
125/* apis from gatt service */
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();
130
131#if MYNEWT_VAL(BLE_DYNAMIC_SERVICE)
132void ble_svc_gatt_changed(uint16_t start_handle, uint16_t end_handle);
133#endif
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);
145
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);
149
150/* cache store */
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);
159
160/* cache search */
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,
166 uint16_t end_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,
170 void *cb_arg);
171int ble_gattc_cache_conn_search_chrs_by_uuid(uint16_t conn_handle, uint16_t start_handle,
172 uint16_t end_handle, const ble_uuid_t *uuid,
173 ble_gatt_chr_fn *cb, void *cb_arg);
174int
175ble_gattc_cache_conn_search_all_dscs(uint16_t conn_handle, uint16_t start_handle,
176 uint16_t end_handle,
177 ble_gatt_dsc_fn *cb, void *cb_arg);
178
179#ifdef __cplusplus
180}
181#endif
182
183#endif
184#endif
Definition ble_uuid.h:52
Definition os_mbuf.h:86
Definition ble_uuid.h:76