NimBLE-Arduino 2.1.2
Loading...
Searching...
No Matches
ble_store.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_STORE_
21#define H_BLE_STORE_
22
23#include <inttypes.h>
24#include "nimble/nimble/include/nimble/ble.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#define BLE_STORE_OBJ_TYPE_OUR_SEC 1
31#define BLE_STORE_OBJ_TYPE_PEER_SEC 2
32#define BLE_STORE_OBJ_TYPE_CCCD 3
33#define BLE_STORE_OBJ_TYPE_PEER_DEV_REC 4
34
35#if MYNEWT_VAL(ENC_ADV_DATA)
36#define BLE_STORE_OBJ_TYPE_ENC_ADV_DATA 5
37#endif
38#define BLE_STORE_OBJ_TYPE_PEER_ADDR 6
39
40#define BLE_STORE_OBJ_TYPE_LOCAL_IRK 7
42#define BLE_STORE_EVENT_OVERFLOW 1
43
45#define BLE_STORE_EVENT_FULL 2
46
58 ble_addr_t peer_addr;
59
61 uint16_t ediv;
62
64 uint64_t rand_num;
65
66 unsigned ediv_rand_present:1;
67
69 uint8_t idx;
70};
71
79 ble_addr_t peer_addr;
80 uint16_t bond_count;
81
82 uint8_t key_size;
83 uint16_t ediv;
84 uint64_t rand_num;
85 uint8_t ltk[16];
86 uint8_t ltk_present:1;
87
88 uint8_t irk[16];
89 uint8_t irk_present:1;
90
91 uint8_t csrk[16];
92 uint8_t csrk_present:1;
93 uint32_t sign_counter;
94
95 unsigned authenticated:1;
96 uint8_t sc:1;
97};
98
109 ble_addr_t peer_addr;
110
116
118 uint8_t idx;
119};
120
126 ble_addr_t peer_addr;
127 uint16_t chr_val_handle;
128 uint16_t flags;
129 unsigned value_changed:1;
130};
131
132#if MYNEWT_VAL(ENC_ADV_DATA)
137struct ble_store_key_ead {
142 ble_addr_t peer_addr;
143
145 uint8_t idx;
146};
147
152struct ble_store_value_ead {
153 ble_addr_t peer_addr;
154 unsigned km_present:1;
155 struct key_material *km;
156};
157#endif
158
159struct ble_store_key_local_irk {
160 ble_addr_t addr;
161
162 uint8_t idx;
163};
164
165struct ble_store_value_local_irk {
166 ble_addr_t addr;
167
168 uint8_t irk[16];
169};
170
171struct ble_store_key_rpa_rec{
172 ble_addr_t peer_rpa_addr;
173 uint8_t idx;
174};
175struct ble_store_value_rpa_rec{
176 ble_addr_t peer_rpa_addr;
177 ble_addr_t peer_addr;
178};
179
185 struct ble_store_key_sec sec;
186 struct ble_store_key_cccd cccd;
187#if MYNEWT_VAL(ENC_ADV_DATA)
188 struct ble_store_key_ead ead;
189#endif
190 struct ble_store_key_rpa_rec rpa_rec;
191 struct ble_store_key_local_irk local_irk;
192};
193
199 struct ble_store_value_sec sec;
200 struct ble_store_value_cccd cccd;
201#if MYNEWT_VAL(ENC_ADV_DATA)
202 struct ble_store_value_ead ead;
203#endif
204 struct ble_store_value_rpa_rec rpa_rec;
205 struct ble_store_value_local_irk local_irk;
206};
207
208struct ble_store_status_event {
213 int event_code;
214
219 union {
225 struct {
227 int obj_type;
228
230 const union ble_store_value *value;
231 } overflow;
232
238 struct {
240 int obj_type;
241
243 uint16_t conn_handle;
244 } full;
245 };
246};
247
265typedef int ble_store_read_fn(int obj_type, const union ble_store_key *key,
266 union ble_store_value *dst);
267
281typedef int ble_store_write_fn(int obj_type, const union ble_store_value *val);
282
296typedef int ble_store_delete_fn(int obj_type, const union ble_store_key *key);
297
312typedef int ble_store_status_fn(struct ble_store_status_event *event,
313 void *arg);
314
315int ble_store_read(int obj_type, const union ble_store_key *key,
316 union ble_store_value *val);
317int ble_store_write(int obj_type, const union ble_store_value *val);
318int ble_store_delete(int obj_type, const union ble_store_key *key);
319int ble_store_overflow_event(int obj_type, const union ble_store_value *value);
320int ble_store_full_event(int obj_type, uint16_t conn_handle);
321
322int ble_store_read_our_sec(const struct ble_store_key_sec *key_sec,
323 struct ble_store_value_sec *value_sec);
324int ble_store_write_our_sec(const struct ble_store_value_sec *value_sec);
325int ble_store_delete_our_sec(const struct ble_store_key_sec *key_sec);
326int ble_store_read_peer_sec(const struct ble_store_key_sec *key_sec,
327 struct ble_store_value_sec *value_sec);
328int ble_store_write_peer_sec(const struct ble_store_value_sec *value_sec);
329int ble_store_delete_peer_sec(const struct ble_store_key_sec *key_sec);
330
331int ble_store_read_cccd(const struct ble_store_key_cccd *key,
332 struct ble_store_value_cccd *out_value);
333int ble_store_write_cccd(const struct ble_store_value_cccd *value);
334int ble_store_delete_cccd(const struct ble_store_key_cccd *key);
335
336void ble_store_key_from_value_sec(struct ble_store_key_sec *out_key,
337 const struct ble_store_value_sec *value);
338void ble_store_key_from_value_cccd(struct ble_store_key_cccd *out_key,
339 const struct ble_store_value_cccd *value);
340#if MYNEWT_VAL(ENC_ADV_DATA)
341int ble_store_read_ead(const struct ble_store_key_ead *key,
342 struct ble_store_value_ead *out_value);
343int ble_store_write_ead(const struct ble_store_value_ead *value);
344int ble_store_delete_ead(const struct ble_store_key_ead *key);
345void ble_store_key_from_value_ead(struct ble_store_key_ead *out_key,
346 const struct ble_store_value_ead *value);
347#endif
348/* irk store*/
349int ble_store_read_local_irk(const struct ble_store_key_local_irk *key,
350 struct ble_store_value_local_irk *out_value);
351int ble_store_write_local_irk(const struct ble_store_value_local_irk *value);
352int ble_store_delete_local_irk(const struct ble_store_key_local_irk *key);
353void ble_store_key_from_value_local_irk(struct ble_store_key_local_irk *out_key,
354 const struct ble_store_value_local_irk *value);
355
356/*irk store */
357/* rpa mapping*/
358int ble_store_read_rpa_rec(const struct ble_store_key_rpa_rec *key,
359 struct ble_store_value_rpa_rec *out_value);
360int ble_store_write_rpa_rec(const struct ble_store_value_rpa_rec *value);
361int ble_store_delete_rpa_rec(const struct ble_store_key_rpa_rec *key);
362void ble_store_key_from_value_rpa_rec(struct ble_store_key_rpa_rec *out_key,
363 const struct ble_store_value_rpa_rec *value);
364/* rpa mapping*/
365void ble_store_key_from_value(int obj_type,
366 union ble_store_key *out_key,
367 const union ble_store_value *value);
368
369typedef int ble_store_iterator_fn(int obj_type,
370 union ble_store_value *val,
371 void *cookie);
372
373int ble_store_iterate(int obj_type,
374 ble_store_iterator_fn *callback,
375 void *cookie);
376
377int ble_store_clear(void);
378
379/*** Utility functions. */
380
381int ble_store_util_bonded_peers(ble_addr_t *out_peer_id_addrs,
382 int *out_num_peers,
383 int max_peers);
384int ble_store_util_delete_all(int type, const union ble_store_key *key);
385int ble_store_util_delete_peer(const ble_addr_t *peer_id_addr);
386int ble_store_util_delete_oldest_peer(void);
387int ble_store_util_count(int type, int *out_count);
388int ble_store_util_status_rr(struct ble_store_status_event *event, void *arg);
389
390#ifdef __cplusplus
391}
392#endif
393
394#endif
Definition ble_store.h:104
ble_addr_t peer_addr
Definition ble_store.h:109
uint16_t chr_val_handle
Definition ble_store.h:115
uint8_t idx
Definition ble_store.h:118
Definition ble_store.h:53
uint16_t ediv
Definition ble_store.h:61
uint64_t rand_num
Definition ble_store.h:64
uint8_t idx
Definition ble_store.h:69
ble_addr_t peer_addr
Definition ble_store.h:58
Definition ble_store.h:125
Definition ble_store.h:78
Definition ble_store.h:184
Definition ble_store.h:198