NimBLE-Arduino 2.1.2
Loading...
Searching...
No Matches
subnet.h
1/*
2 * Copyright (c) 2020 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef _BLUETOOTH_MESH_SUBNET_H_
8#define _BLUETOOTH_MESH_SUBNET_H_
9
10#include <stdint.h>
11#include <sys/types.h>
12#include "../include/mesh/glue.h"
13#define BT_MESH_NET_FLAG_KR BIT(0)
14#define BT_MESH_NET_FLAG_IVU BIT(1)
15
16#define BT_MESH_KR_NORMAL 0x00
17#define BT_MESH_KR_PHASE_1 0x01
18#define BT_MESH_KR_PHASE_2 0x02
19#define BT_MESH_KR_PHASE_3 0x03
20
22#define SUBNET_KEY_TX_IDX(sub) ((sub)->kr_phase == BT_MESH_KR_PHASE_2)
23
24struct bt_mesh_net_rx;
25enum bt_mesh_key_evt;
26
29 uint8_t nid; /* NID */
30 uint8_t enc[16]; /* EncKey */
31 uint8_t privacy[16]; /* PrivacyKey */
32};
33
36 uint32_t beacon_sent; /* Timestamp of last sent beacon */
37 uint8_t beacons_last; /* Number of beacons during last
38 * observation window
39 */
40 uint8_t beacons_cur; /* Number of beacons observed during
41 * currently ongoing window.
42 */
43
44 uint8_t beacon_cache[21]; /* Cached last authenticated beacon */
45
46 uint16_t net_idx; /* NetKeyIndex */
47
48 uint8_t kr_phase; /* Key Refresh Phase */
49
50 uint8_t node_id; /* Node Identity State */
51 uint32_t node_id_start; /* Node Identity started timestamp */
52
53 uint8_t auth[8]; /* Beacon Authentication Value */
54
55 struct bt_mesh_subnet_keys {
56 bool valid;
57 uint8_t net[16]; /* NetKey */
58 struct bt_mesh_net_cred msg;
59 uint8_t net_id[8]; /* Network ID */
60 #if defined(CONFIG_BT_MESH_GATT_PROXY)
61 uint8_t identity[16]; /* IdentityKey */
62 #endif
63 uint8_t beacon[16]; /* BeaconKey */
64 } keys[2];
65};
66
67#ifdef CONFIG_BT_MESH_GATT_PROXY
68extern void (*bt_mesh_subnet_cb_list[5]) (struct bt_mesh_subnet *sub,
69 enum bt_mesh_key_evt evt);
70#else
71extern void (*bt_mesh_subnet_cb_list[4]) (struct bt_mesh_subnet *sub,
72 enum bt_mesh_key_evt evt);
73#endif
74
77 void (*evt_handler)(struct bt_mesh_subnet *subnet,
78 enum bt_mesh_key_evt evt);
79};
80
82void bt_mesh_net_keys_reset(void);
83
91struct bt_mesh_subnet *bt_mesh_subnet_find(int (*cb)(struct bt_mesh_subnet *sub,
92 void *cb_data),
93 void *cb_data);
94
101size_t bt_mesh_subnet_foreach(void (*cb)(struct bt_mesh_subnet *sub));
102
112struct bt_mesh_subnet *bt_mesh_subnet_next(struct bt_mesh_subnet *sub);
113
120struct bt_mesh_subnet *bt_mesh_subnet_get(uint16_t net_idx);
121
131int bt_mesh_subnet_set(uint16_t net_idx, uint8_t kr_phase,
132 const uint8_t key[16], const uint8_t new_key[16]);
133
145int bt_mesh_friend_cred_create(struct bt_mesh_net_cred *cred,
146 uint16_t lpn_addr, uint16_t frnd_addr,
147 uint16_t lpn_counter, uint16_t frnd_counter,
148 const uint8_t key[16]);
149
161bool bt_mesh_net_cred_find(struct bt_mesh_net_rx *rx, struct os_mbuf *in,
162 struct os_mbuf *out,
163 bool (*cb)(struct bt_mesh_net_rx *rx,
164 struct os_mbuf *in,
165 struct os_mbuf *out,
166 const struct bt_mesh_net_cred *cred));
167
174uint8_t bt_mesh_net_flags(struct bt_mesh_subnet *sub);
175
183void bt_mesh_kr_update(struct bt_mesh_subnet *sub, bool kr_flag, bool new_key);
184
191static inline bool
192bt_mesh_subnet_has_new_key(const struct bt_mesh_subnet *sub)
193{
194 return sub->kr_phase != BT_MESH_KR_NORMAL;
195}
196
201void bt_mesh_subnet_store(uint16_t net_idx);
202
204void bt_mesh_subnet_pending_store(void);
205void bt_mesh_net_key_init(void);
206#endif /* _BLUETOOTH_MESH_SUBNET_H_ */
Definition subnet.h:28
Definition subnet.h:76
Definition subnet.h:35
Definition os_mbuf.h:86