nRF5 SDK for Mesh v2.2.0
nrf_mesh.h
1 /* Copyright (c) 2010 - 2018, Nordic Semiconductor ASA
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form, except as embedded into a Nordic
11  * Semiconductor ASA integrated circuit in a product or a software update for
12  * such product, must reproduce the above copyright notice, this list of
13  * conditions and the following disclaimer in the documentation and/or other
14  * materials provided with the distribution.
15  *
16  * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
17  * contributors may be used to endorse or promote products derived from this
18  * software without specific prior written permission.
19  *
20  * 4. This software, with or without modification, must only be used with a
21  * Nordic Semiconductor ASA integrated circuit.
22  *
23  * 5. Any software provided in binary form under this license must not be reverse
24  * engineered, decompiled, modified and/or disassembled.
25  *
26  * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
27  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28  * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
29  * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
30  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
32  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
35  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #ifndef NRF_MESH_H__
39 #define NRF_MESH_H__
40 
41 #include <stdint.h>
42 #include <stdbool.h>
43 
44 #include "ble.h"
45 #include "ble_gap.h"
46 
47 #include "nrf_mesh_defines.h"
48 #include "nrf_mesh_config_core.h"
49 
50 #include "nrf.h"
51 #include "nrf_sdm.h"
52 
61 #define NRF_MESH_INITIAL_TOKEN 0x00000000ul
62 
63 #define NRF_MESH_SERVICE_BORDER_TOKEN 0xF0000000ul
64 
65 #define NRF_MESH_HEARTBEAT_TOKEN 0xFFFFFFFDul
66 #define NRF_MESH_SAR_TOKEN 0xFFFFFFFEul
67 #define NRF_MESH_RELAY_TOKEN 0xFFFFFFFFul
68 
85 typedef void (*nrf_mesh_assertion_handler_t)(uint32_t pc);
86 
88 typedef uint32_t nrf_mesh_tx_token_t;
89 
91 typedef enum
92 {
100 
102 typedef struct
103 {
104  uint32_t timestamp;
105  uint32_t access_addr;
106  uint8_t channel;
107  int8_t rssi;
108  ble_gap_addr_t adv_addr;
109  uint8_t adv_type;
111 
113 typedef struct
114 {
115  uint16_t data_id;
116  uint8_t set_id;
118 
120 typedef struct
121 {
122  uint32_t timestamp;
123  uint8_t channel;
124  int8_t rssi;
125  struct
126  {
128  uint8_t packet_index;
130  } event;
132 
133 typedef struct
134 {
135  uint32_t timestamp;
136  uint16_t connection_index;
138 
140 typedef struct
141 {
144 
146 typedef struct
147 {
149  union
150  {
159  } params;
161 
183 typedef bool (*nrf_mesh_relay_check_cb_t)(uint16_t src, uint16_t dst, uint8_t ttl);
184 
186 typedef struct
187 {
188  uint8_t adv_type;
189  uint8_t length;
190  const uint8_t * p_payload;
193 
203 typedef void (*nrf_mesh_rx_cb_t)(const nrf_mesh_adv_packet_rx_data_t * p_rx_data);
204 
210 typedef enum
211 {
221 
230 typedef struct
231 {
235  uint8_t aid;
237  uint8_t key[NRF_MESH_KEY_SIZE];
239 
246 typedef struct
247 {
249  uint8_t nid;
251  uint8_t encryption_key[NRF_MESH_KEY_SIZE];
253  uint8_t privacy_key[NRF_MESH_KEY_SIZE];
255 
263 typedef struct
264 {
266  uint8_t key[NRF_MESH_KEY_SIZE];
268  uint8_t net_id[NRF_MESH_NETID_SIZE];
269 #if GATT_PROXY
270 
271  uint8_t identity_key[NRF_MESH_KEY_SIZE];
272 #endif
274 
279 typedef struct
280 {
284  uint32_t tx_timestamp;
286 
292 typedef struct
293 {
304 
313 typedef struct
314 {
320 
322 typedef enum
323 {
329 
338 typedef enum
339 {
349 
355 typedef struct
356 {
360  uint16_t value;
362  const uint8_t * p_virtual_uuid;
364 
366 typedef enum
367 {
377 
384 typedef struct
385 {
389  uint16_t src;
391  uint8_t ttl;
397  const uint8_t * p_data;
399  uint16_t data_len;
405 
409 typedef struct
410 {
411 #if (defined(S140) || defined(S130) || defined(S132) || defined(S112) || defined(HOST))
412  nrf_clock_lf_cfg_t lfclksrc;
413 #elif defined(S110)
414  nrf_clock_lfclksrc_t lfclksrc;
415 #else
416  #error "Unknown target softdevice version"
417 #endif
419  uint8_t irq_priority;
420  const uint8_t * p_uuid;
422 
449 uint32_t nrf_mesh_init(const nrf_mesh_init_params_t * p_init_params);
450 
464 uint32_t nrf_mesh_enable(void);
465 
474 uint32_t nrf_mesh_disable(void);
475 
504 uint32_t nrf_mesh_packet_send(const nrf_mesh_tx_params_t * p_params,
505  uint32_t * const p_packet_reference);
506 
529 bool nrf_mesh_process(void);
530 
544 uint32_t nrf_mesh_on_sd_evt(uint32_t sd_evt);
545 
552 
556 void nrf_mesh_rx_cb_clear(void);
557 
564 void nrf_mesh_subnet_added(uint16_t net_key_index, const uint8_t * p_network_id);
565 
574 
577 #endif /* NRF_MESH_H__ */
Invalid address.
Definition: nrf_mesh.h:341
uint32_t nrf_mesh_init(const nrf_mesh_init_params_t *p_init_params)
Initializes the Bluetooth Mesh stack.
uint32_t nrf_mesh_packet_send(const nrf_mesh_tx_params_t *p_params, uint32_t *const p_packet_reference)
Queues a mesh packet for transmission.
uint32_t tx_timestamp
Last transmission time for this beacon.
Definition: nrf_mesh.h:284
uint32_t nrf_mesh_disable(void)
Disables the Mesh.
RX packet metadata.
Definition: nrf_mesh.h:146
uint16_t data_id
ID for this particular event.
Definition: nrf_mesh.h:115
nrf_mesh_instaburst_event_id_t id
Event ID for the full advertising event.
Definition: nrf_mesh.h:127
const uint8_t * p_virtual_uuid
128-bit virtual label UUID, will be NULL if type is not NRF_MESH_ADDRESS_VIRTUAL .
Definition: nrf_mesh.h:362
nrf_mesh_rx_metadata_instaburst_t instaburst
Instaburst packet metadata.
Definition: nrf_mesh.h:154
uint32_t timestamp
Device local timestamp of the packet preamble of the adv ext packet in microseconds.
Definition: nrf_mesh.h:122
bool force_segmented
See Section 3.7.5.2 in the Mesh Profile Specification v1.0.
Definition: nrf_mesh.h:393
#define NRF_MESH_KEY_SIZE
Size (in octets) of an encryption key.
uint16_t value
Address value.
Definition: nrf_mesh.h:360
Network security material structure.
Definition: nrf_mesh.h:246
Selects 4 byte MIC size for the transport PDU.
Definition: nrf_mesh.h:369
nrf_mesh_beacon_secmat_t secmat
Beacon security material.
Definition: nrf_mesh.h:300
const nrf_mesh_application_secmat_t * p_app
Required for transport layer encryption.
Definition: nrf_mesh.h:318
bool is_last_in_chain
Whether this packet is the last packet in the advertising event.
Definition: nrf_mesh.h:129
int8_t rssi
RSSI value of the received packet.
Definition: nrf_mesh.h:124
uint32_t access_addr
Access address the packet was received on.
Definition: nrf_mesh.h:105
Selects default stack configured MIC size for the transport PDU.
Definition: nrf_mesh.h:373
Information structure for the Bluetooth Mesh network beacons.
Definition: nrf_mesh.h:292
uint8_t adv_type
BLE GAP advertising type.
Definition: nrf_mesh.h:188
The packet came from the scanner.
Definition: nrf_mesh.h:93
#define NRF_MESH_BEACON_OBSERVATION_PERIODS
Number of periods to keep beacon observations of.
Mesh packet transmission parameters.
Definition: nrf_mesh.h:384
Key refresh phase 2.
Definition: nrf_mesh.h:217
uint16_t data_len
Length of the payload being sent.
Definition: nrf_mesh.h:399
nrf_mesh_tx_token_t tx_token
Token that can be used as a reference in the TX complete callback.
Definition: nrf_mesh.h:403
nrf_mesh_rx_metadata_gatt_t gatt
GATT packet metadata.
Definition: nrf_mesh.h:156
bool(* nrf_mesh_relay_check_cb_t)(uint16_t src, uint16_t dst, uint8_t ttl)
Callback function type for checking if a given packet should be relayed on to other nodes...
Definition: nrf_mesh.h:183
uint8_t length
Length of the advertisement packet payload.
Definition: nrf_mesh.h:189
Application security material structure.
Definition: nrf_mesh.h:230
const uint8_t * p_data
Points to the payload to be sent.
Definition: nrf_mesh.h:397
uint8_t channel
Channel the packet was received on.
Definition: nrf_mesh.h:123
The packet came from a friend node.
Definition: nrf_mesh.h:95
The packet came from an Instaburst event.
Definition: nrf_mesh.h:97
Arguments structure for the RX callback function.
Definition: nrf_mesh.h:186
uint32_t nrf_mesh_enable(void)
Enables the Mesh.
uint32_t timestamp
Device local timestamp of the start of the advertisement header of the packet in microseconds.
Definition: nrf_mesh.h:104
nrf_mesh_address_type_t
Bluetooth Mesh address types.
Definition: nrf_mesh.h:338
nrf_mesh_beacon_secmat_t secmat_updated
Beacon security material during key refresh.
Definition: nrf_mesh.h:302
Event ID for an extended advertising event with Instaburst.
Definition: nrf_mesh.h:113
Run-time transmission information for individual beacons.
Definition: nrf_mesh.h:279
IV update procedure in progress.
Definition: nrf_mesh.h:327
The packet came from a GATT connection.
Definition: nrf_mesh.h:94
void nrf_mesh_subnet_added(uint16_t net_key_index, const uint8_t *p_network_id)
Notify the core stack that a subnet was added to the device.
uint16_t src
Address of the element the packet originates from (must be a unicast address).
Definition: nrf_mesh.h:389
Bluetooth Mesh security material structure.
Definition: nrf_mesh.h:313
nrf_mesh_address_type_t type
Address type.
Definition: nrf_mesh.h:358
bool iv_update_permitted
Flag indicating whether the given structure is allowed to initiate an IV update.
Definition: nrf_mesh.h:296
bool nrf_mesh_process(void)
Runs the mesh packet processing process.
void nrf_mesh_rx_cb_clear(void)
Unregister the RX callback, if any.
uint8_t irq_priority
Application IRQ priority (NRF_MESH_IRQ_PRIORITY_LOWEST or NRF_MESH_IRQ_PRIORITY_THREAD).
Definition: nrf_mesh.h:419
uint8_t channel
Channel the packet was received on.
Definition: nrf_mesh.h:106
Metadata structure for packets that originated on this device.
Definition: nrf_mesh.h:140
uint16_t connection_index
Proxy connection index the packet was received from.
Definition: nrf_mesh.h:136
void(* nrf_mesh_rx_cb_t)(const nrf_mesh_adv_packet_rx_data_t *p_rx_data)
Advertisement received callback function type.
Definition: nrf_mesh.h:203
Key refresh phase 1.
Definition: nrf_mesh.h:215
nrf_mesh_beacon_tx_info_t * p_tx_info
Pointer to a transmission info structure.
Definition: nrf_mesh.h:298
nrf_mesh_rx_source_t source
Source of the received packet.
Definition: nrf_mesh.h:148
nrf_mesh_tx_token_t nrf_mesh_unique_token_get(void)
Get unique token to be able to recognize tx complete events.
uint32_t nrf_mesh_tx_token_t
TX Token type, used as a context parameter to notify the application of ended transmissions.
Definition: nrf_mesh.h:88
nrf_mesh_relay_check_cb_t relay_cb
Application call back for relay decisions, can be NULL.
Definition: nrf_mesh.h:418
nrf_mesh_key_refresh_phase_t
Key refresh phase.
Definition: nrf_mesh.h:210
nrf_mesh_rx_metadata_loopback_t loopback
Loopback packet metadata.
Definition: nrf_mesh.h:158
uint8_t packet_index
Index of the packet in the advertising event.
Definition: nrf_mesh.h:128
Metadata structure for packets received with Instaburst.
Definition: nrf_mesh.h:120
The packet came from a low power node.
Definition: nrf_mesh.h:96
nrf_mesh_transmic_size_t transmic_size
Transport MIC Size selection.
Definition: nrf_mesh.h:395
nrf_mesh_rx_metadata_scanner_t scanner
Scanner packet metadata.
Definition: nrf_mesh.h:152
nrf_mesh_rx_source_t
RX packet type.
Definition: nrf_mesh.h:91
Initialization parameters structure.
Definition: nrf_mesh.h:409
uint8_t ttl
Time to live value for the packet, this is a 7 bit value.
Definition: nrf_mesh.h:391
uint32_t timestamp
Device local timestamp of the packet being processed in the stack in microseconds.
Definition: nrf_mesh.h:135
uint8_t adv_type
BLE GAP advertising type.
Definition: nrf_mesh.h:109
Metadata structure for packets received with the scanner.
Definition: nrf_mesh.h:102
nrf_mesh_address_t dst
Packet destination address.
Definition: nrf_mesh.h:387
uint8_t set_id
ID for the set this event belongs in.
Definition: nrf_mesh.h:116
In normal operation.
Definition: nrf_mesh.h:325
Key refresh phase 3.
Definition: nrf_mesh.h:219
nrf_mesh_transmic_size_t
Message MIC size selection.
Definition: nrf_mesh.h:366
Bluetooth Mesh address.
Definition: nrf_mesh.h:355
void nrf_mesh_rx_cb_set(nrf_mesh_rx_cb_t rx_cb)
Set a callback which will be called for every packet being received.
Virtual address.
Definition: nrf_mesh.h:345
int8_t rssi
RSSI value of the received packet.
Definition: nrf_mesh.h:107
Selects 8 byte MIC size for the transport PDU.
Definition: nrf_mesh.h:371
void(* nrf_mesh_assertion_handler_t)(uint32_t pc)
Mesh assertion handler type.
Definition: nrf_mesh.h:85
uint8_t nid
Network identifier.
Definition: nrf_mesh.h:249
uint8_t aid
Application ID.
Definition: nrf_mesh.h:235
nrf_mesh_tx_token_t tx_token
TX Token attached to the loopback packet.
Definition: nrf_mesh.h:142
The packet came from this device.
Definition: nrf_mesh.h:98
const nrf_mesh_rx_metadata_t * p_metadata
Metadata structure for the given packet.
Definition: nrf_mesh.h:191
uint32_t nrf_mesh_on_sd_evt(uint32_t sd_evt)
Pass SoftDevice SoC events to the Mesh.
Security material for the Bluetooth Mesh network beacons.
Definition: nrf_mesh.h:263
Key refresh phase 0.
Definition: nrf_mesh.h:213
#define NRF_MESH_NETID_SIZE
Size (in octets) of the network ID.
ble_gap_addr_t adv_addr
Advertisement address in the packet.
Definition: nrf_mesh.h:108
bool is_device_key
Indicates whether the device key or the application is used.
Definition: nrf_mesh.h:233
net_state_iv_update_t
State of IV update procedure.
Definition: nrf_mesh.h:322
const nrf_mesh_network_secmat_t * p_net
Required for network layer encryption.
Definition: nrf_mesh.h:316
nrf_mesh_secmat_t security_material
Required for encryption.
Definition: nrf_mesh.h:401
Unicast address.
Definition: nrf_mesh.h:343
const uint8_t * p_payload
Pointer to the raw advertisement packet payload.
Definition: nrf_mesh.h:190

Documentation feedback | Developer Zone | Subscribe | Updated