NimBLE-Arduino 2.1.2
Loading...
Searching...
No Matches
cdb.h
1/*
2 * Copyright (c) 2019 Tobias Svehagen
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#ifndef _BLUETOOTH_MESH_CDB_H_
7#define _BLUETOOTH_MESH_CDB_H_
8
9#include "nimble/porting/nimble/include/syscfg/syscfg.h"
10
11#if MYNEWT_VAL(BLE_MESH_CDB)
12#define NODE_COUNT CONFIG_BT_MESH_NODE_COUNT
13#define SUBNET_COUNT CONFIG_BT_MESH_SUBNET_COUNT
14#define APP_KEY_COUNT CONFIG_BT_MESH_APP_KEY_COUNT
15#else
16#define NODE_COUNT 0
17#define SUBNET_COUNT 0
18#define APP_KEY_COUNT 0
19#endif
20
21#include "atomic.h"
22
23enum {
24 BT_MESH_CDB_NODE_CONFIGURED,
25
26 BT_MESH_CDB_NODE_FLAG_COUNT
27};
28
29struct bt_mesh_cdb_node {
30 uint8_t uuid[16];
31 uint16_t addr;
32 uint16_t net_idx;
33 uint8_t num_elem;
34 uint8_t dev_key[16];
35
36 ATOMIC_DEFINE(flags, BT_MESH_CDB_NODE_FLAG_COUNT);
37};
38
39struct bt_mesh_cdb_subnet {
40 uint16_t net_idx;
41
42 uint8_t kr_phase;
43
44 struct {
45 uint8_t net_key[16];
46 } keys[2];
47};
48
49struct bt_mesh_cdb_app_key {
50 uint16_t net_idx;
51 uint16_t app_idx;
52
53 struct {
54 uint8_t app_key[16];
55 } keys[2];
56};
57
58enum {
59 BT_MESH_CDB_VALID,
60 BT_MESH_CDB_SUBNET_PENDING,
61 BT_MESH_CDB_KEYS_PENDING,
62 BT_MESH_CDB_NODES_PENDING,
63 BT_MESH_CDB_IVU_IN_PROGRESS,
64
65 BT_MESH_CDB_FLAG_COUNT,
66};
67
68struct bt_mesh_cdb {
69 uint32_t iv_index;
70
71 ATOMIC_DEFINE(flags, BT_MESH_CDB_FLAG_COUNT);
72
73 struct bt_mesh_cdb_node nodes[NODE_COUNT];
74 struct bt_mesh_cdb_subnet subnets[SUBNET_COUNT];
75 struct bt_mesh_cdb_app_key app_keys[APP_KEY_COUNT];
76};
77
78extern struct bt_mesh_cdb bt_mesh_cdb;
79
90int bt_mesh_cdb_create(const uint8_t key[16]);
91
98void bt_mesh_cdb_clear(void);
99
111void bt_mesh_cdb_iv_update(uint32_t iv_index, bool iv_update);
112
125struct bt_mesh_cdb_node *bt_mesh_cdb_node_alloc(const uint8_t uuid[16], uint16_t addr,
126 uint8_t num_elem, uint16_t net_idx);
127
135void bt_mesh_cdb_node_del(struct bt_mesh_cdb_node *node, bool store);
136
147struct bt_mesh_cdb_node *bt_mesh_cdb_node_get(uint16_t addr);
148
153void bt_mesh_cdb_node_store(const struct bt_mesh_cdb_node *node);
154
155enum {
156 BT_MESH_CDB_ITER_STOP = 0,
157 BT_MESH_CDB_ITER_CONTINUE,
158};
159
169typedef uint8_t (*bt_mesh_cdb_node_func_t)(struct bt_mesh_cdb_node *node,
170 void *user_data);
171
180void bt_mesh_cdb_node_foreach(bt_mesh_cdb_node_func_t func, void *user_data);
181
190struct bt_mesh_cdb_subnet *bt_mesh_cdb_subnet_alloc(uint16_t net_idx);
191
199void bt_mesh_cdb_subnet_del(struct bt_mesh_cdb_subnet *sub, bool store);
200
210struct bt_mesh_cdb_subnet *bt_mesh_cdb_subnet_get(uint16_t net_idx);
211
216void bt_mesh_cdb_subnet_store(const struct bt_mesh_cdb_subnet *sub);
217
224uint8_t bt_mesh_cdb_subnet_flags(const struct bt_mesh_cdb_subnet *sub);
225
226
236struct bt_mesh_cdb_app_key *bt_mesh_cdb_app_key_alloc(uint16_t net_idx,
237 uint16_t app_idx);
238
246void bt_mesh_cdb_app_key_del(struct bt_mesh_cdb_app_key *key, bool store);
247
257struct bt_mesh_cdb_app_key *bt_mesh_cdb_app_key_get(uint16_t app_idx);
258
263void bt_mesh_cdb_app_key_store(const struct bt_mesh_cdb_app_key *key);
264
265#endif /* ZEPHYR_INCLUDE_BLUETOOTH_MESH_CDB_H_ */
#define ATOMIC_DEFINE(name, num_bits)
Define an array of atomic variables.
Definition atomic.h:274