NimBLE-Arduino 2.1.2
Loading...
Searching...
No Matches
ble_att_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_ATT_PRIV_
21#define H_BLE_ATT_PRIV_
22
23#include <inttypes.h>
24#include "nimble/porting/nimble/include/stats/stats.h"
25#include "nimble/nimble/host/include/host/ble_att.h"
26#include "nimble/nimble/host/include/host/ble_uuid.h"
27#include "nimble/nimble/include/nimble/nimble_npl.h"
28#include "nimble/porting/nimble/include/syscfg/syscfg.h"
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34struct os_mbuf;
35struct ble_hs_conn;
36struct ble_l2cap_chan;
37struct ble_att_find_info_req;
38struct ble_att_error_rsp;
39struct ble_att_mtu_cmd;
40struct ble_att_read_req;
41struct ble_att_read_blob_req;
42struct ble_att_read_type_req;
43struct ble_att_read_group_type_req;
44struct ble_att_read_group_type_rsp;
45struct ble_att_find_type_value_req;
46struct ble_att_write_req;
47struct ble_att_prep_write_cmd;
48struct ble_att_exec_write_req;
49struct ble_att_notify_req;
50struct ble_att_indicate_req;
51
52STATS_SECT_START(ble_att_stats)
53 STATS_SECT_ENTRY(error_rsp_rx)
54 STATS_SECT_ENTRY(error_rsp_tx)
55 STATS_SECT_ENTRY(mtu_req_rx)
56 STATS_SECT_ENTRY(mtu_req_tx)
57 STATS_SECT_ENTRY(mtu_rsp_rx)
58 STATS_SECT_ENTRY(mtu_rsp_tx)
59 STATS_SECT_ENTRY(find_info_req_rx)
60 STATS_SECT_ENTRY(find_info_req_tx)
61 STATS_SECT_ENTRY(find_info_rsp_rx)
62 STATS_SECT_ENTRY(find_info_rsp_tx)
63 STATS_SECT_ENTRY(find_type_value_req_rx)
64 STATS_SECT_ENTRY(find_type_value_req_tx)
65 STATS_SECT_ENTRY(find_type_value_rsp_rx)
66 STATS_SECT_ENTRY(find_type_value_rsp_tx)
67 STATS_SECT_ENTRY(read_type_req_rx)
68 STATS_SECT_ENTRY(read_type_req_tx)
69 STATS_SECT_ENTRY(read_type_rsp_rx)
70 STATS_SECT_ENTRY(read_type_rsp_tx)
71 STATS_SECT_ENTRY(read_req_rx)
72 STATS_SECT_ENTRY(read_req_tx)
73 STATS_SECT_ENTRY(read_rsp_rx)
74 STATS_SECT_ENTRY(read_rsp_tx)
75 STATS_SECT_ENTRY(read_blob_req_rx)
76 STATS_SECT_ENTRY(read_blob_req_tx)
77 STATS_SECT_ENTRY(read_blob_rsp_rx)
78 STATS_SECT_ENTRY(read_blob_rsp_tx)
79 STATS_SECT_ENTRY(read_mult_req_rx)
80 STATS_SECT_ENTRY(read_mult_req_tx)
81 STATS_SECT_ENTRY(read_mult_rsp_rx)
82 STATS_SECT_ENTRY(read_mult_rsp_tx)
83 STATS_SECT_ENTRY(read_group_type_req_rx)
84 STATS_SECT_ENTRY(read_group_type_req_tx)
85 STATS_SECT_ENTRY(read_group_type_rsp_rx)
86 STATS_SECT_ENTRY(read_group_type_rsp_tx)
87 STATS_SECT_ENTRY(write_req_rx)
88 STATS_SECT_ENTRY(write_req_tx)
89 STATS_SECT_ENTRY(write_rsp_rx)
90 STATS_SECT_ENTRY(write_rsp_tx)
91 STATS_SECT_ENTRY(prep_write_req_rx)
92 STATS_SECT_ENTRY(prep_write_req_tx)
93 STATS_SECT_ENTRY(prep_write_rsp_rx)
94 STATS_SECT_ENTRY(prep_write_rsp_tx)
95 STATS_SECT_ENTRY(exec_write_req_rx)
96 STATS_SECT_ENTRY(exec_write_req_tx)
97 STATS_SECT_ENTRY(exec_write_rsp_rx)
98 STATS_SECT_ENTRY(exec_write_rsp_tx)
99 STATS_SECT_ENTRY(notify_req_rx)
100 STATS_SECT_ENTRY(notify_req_tx)
101 STATS_SECT_ENTRY(indicate_req_rx)
102 STATS_SECT_ENTRY(indicate_req_tx)
103 STATS_SECT_ENTRY(indicate_rsp_rx)
104 STATS_SECT_ENTRY(indicate_rsp_tx)
105 STATS_SECT_ENTRY(write_cmd_rx)
106 STATS_SECT_ENTRY(write_cmd_tx)
107STATS_SECT_END
108extern STATS_SECT_DECL(ble_att_stats) ble_att_stats;
109
110struct ble_att_prep_entry {
111 SLIST_ENTRY(ble_att_prep_entry) bape_next;
112 uint16_t bape_handle;
113 uint16_t bape_offset;
114
115 /* XXX: This is wasteful; we should use one mbuf chain for the entire
116 * prepared write, and compress the data into as few mbufs as possible.
117 */
118 struct os_mbuf *bape_value;
119};
120
121SLIST_HEAD(ble_att_prep_entry_list, ble_att_prep_entry);
122
123struct ble_att_svr_conn {
125 struct ble_att_prep_entry_list basc_prep_list;
126 ble_npl_time_t basc_prep_timeout_at;
127};
128
141typedef int ble_att_svr_access_fn(uint16_t conn_handle, uint16_t attr_handle,
142 uint8_t op, uint16_t offset,
143 struct os_mbuf **om, void *arg);
144
145int ble_att_svr_register(const ble_uuid_t *uuid, uint8_t flags,
146 uint8_t min_key_size, uint16_t *handle_id,
147 ble_att_svr_access_fn *cb, void *cb_arg);
148
149#if MYNEWT_VAL(BLE_DYNAMIC_SERVICE)
150int ble_att_svr_deregister(uint16_t start_handle, uint16_t end_group_handle);
151#endif
152#if MYNEWT_VAL(BLE_GATT_CACHING)
153int ble_att_get_database_size(int *out_size);
154int ble_att_fill_database_info(uint8_t *out_data);
155#endif
156
157
158struct ble_att_svr_entry {
159 STAILQ_ENTRY(ble_att_svr_entry) ha_next;
160
161 const ble_uuid_t *ha_uuid;
162 uint8_t ha_flags;
163 uint8_t ha_min_key_size;
164 uint16_t ha_handle_id;
165 ble_att_svr_access_fn *ha_cb;
166 void *ha_cb_arg;
167};
168
169SLIST_HEAD(ble_att_clt_entry_list, ble_att_clt_entry);
170
171/*** @gen */
172
173struct ble_l2cap_chan *ble_att_create_chan(uint16_t conn_handle);
174int ble_att_conn_chan_find(uint16_t conn_handle, struct ble_hs_conn **out_conn,
175 struct ble_l2cap_chan **out_chan);
176void ble_att_inc_tx_stat(uint8_t att_op);
177void ble_att_truncate_to_mtu(const struct ble_l2cap_chan *att_chan,
178 struct os_mbuf *txom);
179void ble_att_set_peer_mtu(struct ble_l2cap_chan *chan, uint16_t peer_mtu);
180uint16_t ble_att_chan_mtu(const struct ble_l2cap_chan *chan);
181int ble_att_init(void);
182
183/*** @svr */
184
185int ble_att_svr_start(void);
186void ble_att_svr_stop(void);
187
188struct ble_att_svr_entry *
189ble_att_svr_find_by_uuid(struct ble_att_svr_entry *start_at,
190 const ble_uuid_t *uuid,
191 uint16_t end_handle);
192uint16_t ble_att_svr_prev_handle(void);
193int ble_att_svr_rx_mtu(uint16_t conn_handle, struct os_mbuf **rxom);
194struct ble_att_svr_entry *ble_att_svr_find_by_handle(uint16_t handle_id);
195int32_t ble_att_svr_ticks_until_tmo(const struct ble_att_svr_conn *svr,
196 ble_npl_time_t now);
197int ble_att_svr_rx_find_info(uint16_t conn_handle, struct os_mbuf **rxom);
198int ble_att_svr_rx_find_type_value(uint16_t conn_handle,
199 struct os_mbuf **rxom);
200int ble_att_svr_rx_read_type(uint16_t conn_handle,
201 struct os_mbuf **rxom);
202int ble_att_svr_rx_read_group_type(uint16_t conn_handle,
203 struct os_mbuf **rxom);
204int ble_att_svr_rx_read(uint16_t conn_handle,
205 struct os_mbuf **rxom);
206int ble_att_svr_rx_read_blob(uint16_t conn_handle,
207 struct os_mbuf **rxom);
208int ble_att_svr_rx_read_mult_var(uint16_t conn_handle,
209 struct os_mbuf **rxom);
210int ble_att_svr_rx_read_mult(uint16_t conn_handle,
211 struct os_mbuf **rxom);
212int ble_att_svr_rx_write(uint16_t conn_handle,
213 struct os_mbuf **rxom);
214int ble_att_svr_rx_write_no_rsp(uint16_t conn_handle, struct os_mbuf **rxom);
215#ifdef ESP_PLATFORM
216int ble_att_svr_rx_signed_write(uint16_t conn_handle, struct os_mbuf **rxom);
217#endif
218int ble_att_svr_rx_prep_write(uint16_t conn_handle,
219 struct os_mbuf **rxom);
220int ble_att_svr_rx_exec_write(uint16_t conn_handle,
221 struct os_mbuf **rxom);
222int ble_att_svr_rx_notify(uint16_t conn_handle,
223 struct os_mbuf **rxom);
224int ble_att_svr_rx_indicate(uint16_t conn_handle,
225 struct os_mbuf **rxom);
226void ble_att_svr_prep_clear(struct ble_att_prep_entry_list *prep_list);
227int ble_att_svr_read_handle(uint16_t conn_handle, uint16_t attr_handle,
228 uint16_t offset, struct os_mbuf *om,
229 uint8_t *out_att_err);
230void ble_att_svr_reset(void);
231int ble_att_svr_init(void);
232
233void ble_att_svr_hide_range(uint16_t start_handle, uint16_t end_handle);
234void ble_att_svr_restore_range(uint16_t start_handle, uint16_t end_handle);
235
236int ble_att_svr_tx_error_rsp(uint16_t conn_handle, struct os_mbuf *txom,
237 uint8_t req_op, uint16_t handle,
238 uint8_t error_code);
239/*** $clt */
240
243 uint16_t attr_handle;
244 ble_uuid_any_t uuid;
245};
246
249 uint16_t attr_handle;
250 uint16_t group_end_handle;
251};
252
255 uint16_t att_handle;
256 int value_len;
257 uint8_t *value;
258
259};
260
263 uint16_t att_handle;
264 uint16_t end_group_handle;
265 int value_len;
266 uint8_t *value;
267};
268
269int ble_att_clt_rx_error(uint16_t conn_handle, struct os_mbuf **rxom);
270int ble_att_clt_tx_mtu(uint16_t conn_handle, uint16_t mtu);
271int ble_att_clt_rx_mtu(uint16_t conn_handle, struct os_mbuf **rxom);
272int ble_att_clt_tx_read(uint16_t conn_handle, uint16_t handle);
273int ble_att_clt_rx_read(uint16_t conn_handle, struct os_mbuf **rxom);
274int ble_att_clt_tx_read_blob(uint16_t conn_handle, uint16_t handle,
275 uint16_t offset);
276int ble_att_clt_rx_read_blob(uint16_t conn_handle, struct os_mbuf **rxom);
277int ble_att_clt_tx_read_mult(uint16_t conn_handle,
278 const uint16_t *handles, int num_handles, bool variable);
279int ble_att_clt_rx_read_mult(uint16_t conn_handle, struct os_mbuf **rxom);
280int ble_att_clt_rx_read_mult_var(uint16_t conn_handle, struct os_mbuf **rxom);
281int ble_att_clt_tx_read_type(uint16_t conn_handle, uint16_t start_handle,
282 uint16_t end_handle, const ble_uuid_t *uuid);
283int ble_att_clt_rx_read_type(uint16_t conn_handle, struct os_mbuf **rxom);
284int ble_att_clt_tx_read_group_type(uint16_t conn_handle,
285 uint16_t start_handle, uint16_t end_handle,
286 const ble_uuid_t *uuid128);
287int ble_att_clt_rx_read_group_type(uint16_t conn_handle,
288 struct os_mbuf **rxom);
289int ble_att_clt_tx_find_info(uint16_t conn_handle, uint16_t start_handle,
290 uint16_t end_handle);
291int ble_att_clt_rx_find_info(uint16_t conn_handle, struct os_mbuf **rxom);
292int ble_att_clt_tx_find_type_value(uint16_t conn_handle, uint16_t start_handle,
293 uint16_t end_handle, uint16_t attribute_type,
294 const void *attribute_value, int value_len);
295int ble_att_clt_rx_find_type_value(uint16_t conn_handle,
296 struct os_mbuf **rxom);
297int ble_att_clt_tx_write_req(uint16_t conn_handle, uint16_t handle,
298 struct os_mbuf *txom);
299int ble_att_clt_tx_write_cmd(uint16_t conn_handle, uint16_t handle,
300 struct os_mbuf *txom);
301int ble_att_clt_tx_prep_write(uint16_t conn_handle, uint16_t handle,
302 uint16_t offset, struct os_mbuf *txom);
303int ble_att_clt_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom);
304int ble_att_clt_tx_exec_write(uint16_t conn_handle, uint8_t flags);
305int ble_att_clt_tx_signed_write_cmd(uint16_t conn_handle, uint16_t handle,
306 uint8_t * csrk, uint32_t counter,
307 struct os_mbuf * txom);
308int ble_att_clt_rx_exec_write(uint16_t conn_handle, struct os_mbuf **rxom);
309int ble_att_clt_rx_write(uint16_t conn_handle, struct os_mbuf **rxom);
310int ble_att_clt_tx_notify(uint16_t conn_handle, uint16_t handle,
311 struct os_mbuf *txom);
312int ble_att_clt_tx_indicate(uint16_t conn_handle, uint16_t handle,
313 struct os_mbuf *txom);
314int ble_att_clt_rx_indicate(uint16_t conn_handle, struct os_mbuf **rxom);
315
316#ifdef __cplusplus
317}
318#endif
319
320#endif
Definition ble_att_priv.h:242
Definition ble_att_priv.h:248
Definition ble_att_priv.h:262
Definition ble_att_priv.h:254
Definition ble_uuid.h:52
Definition os_mbuf.h:86
Definition ble_uuid.h:76