nRF5 SDK for Mesh v3.0.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 "timer.h"
45 
46 #include "ble.h"
47 #include "ble_gap.h"
48 
49 #include "nrf_mesh_defines.h"
50 #include "nrf_mesh_config_core.h"
51 
52 #include "nrf.h"
53 #include "nrf_sdm.h"
54 
63 #define NRF_MESH_INITIAL_TOKEN 0x00000000ul
64 
65 #define NRF_MESH_SERVICE_BORDER_TOKEN 0xF0000000ul
66 
67 #define NRF_MESH_FRIEND_POLL_TOKEN 0xFFFFFFF8ul
68 #define NRF_MESH_FRIEND_REQUEST_TOKEN 0xFFFFFFF9ul
69 #define NRF_MESH_FRIEND_CLEAR_TOKEN 0xFFFFFFFAul
70 #define NRF_MESH_SUBMAN_ADD_TOKEN 0xFFFFFFFBul
71 #define NRF_MESH_SUBMAN_REMOVE_TOKEN 0xFFFFFFFCul
72 #define NRF_MESH_HEARTBEAT_TOKEN 0xFFFFFFFDul
73 #define NRF_MESH_SAR_TOKEN 0xFFFFFFFEul
74 #define NRF_MESH_RELAY_TOKEN 0xFFFFFFFFul
75 
92 typedef void (*nrf_mesh_assertion_handler_t)(uint32_t pc);
93 
95 typedef uint32_t nrf_mesh_tx_token_t;
96 
98 typedef enum
99 {
107 
109 typedef struct
110 {
111  timestamp_t timestamp;
112  uint32_t access_addr;
113  uint8_t channel;
114  int8_t rssi;
115  ble_gap_addr_t adv_addr;
116  uint8_t adv_type;
118 
120 typedef struct
121 {
122  uint16_t data_id;
123  uint8_t set_id;
125 
127 typedef struct
128 {
129  timestamp_t timestamp;
130  uint8_t channel;
131  int8_t rssi;
132  struct
133  {
135  uint8_t packet_index;
137  } event;
139 
140 typedef struct
141 {
142  timestamp_t timestamp;
143  uint16_t connection_index;
145 
147 typedef struct
148 {
151 
153 typedef struct
154 {
156  union
157  {
166  } params;
168 
190 typedef bool (*nrf_mesh_relay_check_cb_t)(uint16_t src, uint16_t dst, uint8_t ttl);
191 
193 typedef struct
194 {
195  uint8_t adv_type;
196  uint8_t length;
197  const uint8_t * p_payload;
200 
210 typedef void (*nrf_mesh_rx_cb_t)(const nrf_mesh_adv_packet_rx_data_t * p_rx_data);
211 
217 typedef enum
218 {
228 
237 typedef struct
238 {
242  uint8_t aid;
244  uint8_t key[NRF_MESH_KEY_SIZE];
246 
253 typedef struct
254 {
256  uint8_t nid;
258  uint8_t encryption_key[NRF_MESH_KEY_SIZE];
260  uint8_t privacy_key[NRF_MESH_KEY_SIZE];
262 
270 typedef struct
271 {
273  uint8_t key[NRF_MESH_KEY_SIZE];
275  uint8_t net_id[NRF_MESH_NETID_SIZE];
276 #if MESH_FEATURE_GATT_PROXY_ENABLED
277 
278  uint8_t identity_key[NRF_MESH_KEY_SIZE];
279 #endif
281 
286 typedef struct
287 {
291  timestamp_t tx_timestamp;
293 
299 typedef struct
300 {
311 
320 typedef struct
321 {
327 
329 typedef enum
330 {
336 
345 typedef enum
346 {
356 
362 typedef struct
363 {
367  uint16_t value;
369  const uint8_t * p_virtual_uuid;
371 
373 typedef enum
374 {
384 
391 typedef struct
392 {
396  uint16_t src;
398  uint8_t ttl;
404  const uint8_t * p_data;
406  uint16_t data_len;
412 
416 typedef struct
417 {
418 #if (defined(S140) || defined(S130) || defined(S132) || defined(S112) || defined(HOST))
419  nrf_clock_lf_cfg_t lfclksrc;
420 #elif defined(S110)
421  nrf_clock_lfclksrc_t lfclksrc;
422 #else
423  #error "Unknown target softdevice version"
424 #endif
426  uint8_t irq_priority;
427  const uint8_t * p_uuid;
429 
456 uint32_t nrf_mesh_init(const nrf_mesh_init_params_t * p_init_params);
457 
471 uint32_t nrf_mesh_enable(void);
472 
489 uint32_t nrf_mesh_disable(void);
490 
521 uint32_t nrf_mesh_packet_send(const nrf_mesh_tx_params_t * p_params,
522  uint32_t * const p_packet_reference);
523 
546 bool nrf_mesh_process(void);
547 
561 uint32_t nrf_mesh_on_sd_evt(uint32_t sd_evt);
562 
569 
573 void nrf_mesh_rx_cb_clear(void);
574 
581 void nrf_mesh_subnet_added(uint16_t net_key_index, const uint8_t * p_network_id);
582 
591 
594 #endif /* NRF_MESH_H__ */
Invalid address.
Definition: nrf_mesh.h:348
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 nrf_mesh_disable(void)
Starts disabling the Mesh.
RX packet metadata.
Definition: nrf_mesh.h:153
uint16_t data_id
ID for this particular event.
Definition: nrf_mesh.h:122
nrf_mesh_instaburst_event_id_t id
Event ID for the full advertising event.
Definition: nrf_mesh.h:134
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:369
nrf_mesh_rx_metadata_instaburst_t instaburst
Instaburst packet metadata.
Definition: nrf_mesh.h:161
bool force_segmented
See Section 3.7.5.2 in the Mesh Profile Specification v1.0.
Definition: nrf_mesh.h:400
#define NRF_MESH_KEY_SIZE
Size (in octets) of an encryption key.
uint16_t value
Address value.
Definition: nrf_mesh.h:367
timestamp_t timestamp
Device local timestamp of the packet preamble of the adv ext packet in microseconds.
Definition: nrf_mesh.h:129
Network security material structure.
Definition: nrf_mesh.h:253
Selects 4 byte MIC size for the transport PDU.
Definition: nrf_mesh.h:376
nrf_mesh_beacon_secmat_t secmat
Beacon security material.
Definition: nrf_mesh.h:307
const nrf_mesh_application_secmat_t * p_app
Required for transport layer encryption.
Definition: nrf_mesh.h:325
bool is_last_in_chain
Whether this packet is the last packet in the advertising event.
Definition: nrf_mesh.h:136
int8_t rssi
RSSI value of the received packet.
Definition: nrf_mesh.h:131
uint32_t access_addr
Access address the packet was received on.
Definition: nrf_mesh.h:112
Selects default stack configured MIC size for the transport PDU.
Definition: nrf_mesh.h:380
timestamp_t timestamp
Device local timestamp of the packet being processed in the stack in microseconds.
Definition: nrf_mesh.h:142
Information structure for the Bluetooth Mesh network beacons.
Definition: nrf_mesh.h:299
uint8_t adv_type
BLE GAP advertising type.
Definition: nrf_mesh.h:195
The packet came from the scanner.
Definition: nrf_mesh.h:100
#define NRF_MESH_BEACON_OBSERVATION_PERIODS
Number of periods to keep beacon observations of.
Mesh packet transmission parameters.
Definition: nrf_mesh.h:391
Key refresh phase 2.
Definition: nrf_mesh.h:224
uint16_t data_len
Length of the payload being sent.
Definition: nrf_mesh.h:406
nrf_mesh_tx_token_t tx_token
Token that can be used as a reference in the TX complete callback.
Definition: nrf_mesh.h:410
nrf_mesh_rx_metadata_gatt_t gatt
GATT packet metadata.
Definition: nrf_mesh.h:163
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:190
uint8_t length
Length of the advertisement packet payload.
Definition: nrf_mesh.h:196
Application security material structure.
Definition: nrf_mesh.h:237
const uint8_t * p_data
Points to the payload to be sent.
Definition: nrf_mesh.h:404
uint8_t channel
Channel the packet was received on.
Definition: nrf_mesh.h:130
The packet came from a friend node.
Definition: nrf_mesh.h:102
The packet came from an Instaburst event.
Definition: nrf_mesh.h:104
Arguments structure for the RX callback function.
Definition: nrf_mesh.h:193
uint32_t nrf_mesh_enable(void)
Enables the Mesh.
nrf_mesh_address_type_t
Bluetooth Mesh address types.
Definition: nrf_mesh.h:345
nrf_mesh_beacon_secmat_t secmat_updated
Beacon security material during key refresh.
Definition: nrf_mesh.h:309
Event ID for an extended advertising event with Instaburst.
Definition: nrf_mesh.h:120
Run-time transmission information for individual beacons.
Definition: nrf_mesh.h:286
IV update procedure in progress.
Definition: nrf_mesh.h:334
The packet came from a GATT connection.
Definition: nrf_mesh.h:101
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:396
Bluetooth Mesh security material structure.
Definition: nrf_mesh.h:320
nrf_mesh_address_type_t type
Address type.
Definition: nrf_mesh.h:365
bool iv_update_permitted
Flag indicating whether the given structure is allowed to initiate an IV update.
Definition: nrf_mesh.h:303
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:426
uint8_t channel
Channel the packet was received on.
Definition: nrf_mesh.h:113
Metadata structure for packets that originated on this device.
Definition: nrf_mesh.h:147
uint16_t connection_index
Proxy connection index the packet was received from.
Definition: nrf_mesh.h:143
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:210
Key refresh phase 1.
Definition: nrf_mesh.h:222
nrf_mesh_beacon_tx_info_t * p_tx_info
Pointer to a transmission info structure.
Definition: nrf_mesh.h:305
nrf_mesh_rx_source_t source
Source of the received packet.
Definition: nrf_mesh.h:155
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:95
nrf_mesh_relay_check_cb_t relay_cb
Application call back for relay decisions, can be NULL.
Definition: nrf_mesh.h:425
nrf_mesh_key_refresh_phase_t
Key refresh phase.
Definition: nrf_mesh.h:217
nrf_mesh_rx_metadata_loopback_t loopback
Loopback packet metadata.
Definition: nrf_mesh.h:165
uint8_t packet_index
Index of the packet in the advertising event.
Definition: nrf_mesh.h:135
Metadata structure for packets received with Instaburst.
Definition: nrf_mesh.h:127
The packet came from a low power node.
Definition: nrf_mesh.h:103
nrf_mesh_transmic_size_t transmic_size
Transport MIC Size selection.
Definition: nrf_mesh.h:402
nrf_mesh_rx_metadata_scanner_t scanner
Scanner packet metadata.
Definition: nrf_mesh.h:159
nrf_mesh_rx_source_t
RX packet type.
Definition: nrf_mesh.h:98
Initialization parameters structure.
Definition: nrf_mesh.h:416
uint8_t ttl
Time to live value for the packet, this is a 7 bit value.
Definition: nrf_mesh.h:398
uint8_t adv_type
BLE GAP advertising type.
Definition: nrf_mesh.h:116
Metadata structure for packets received with the scanner.
Definition: nrf_mesh.h:109
nrf_mesh_address_t dst
Packet destination address.
Definition: nrf_mesh.h:394
uint8_t set_id
ID for the set this event belongs in.
Definition: nrf_mesh.h:123
In normal operation.
Definition: nrf_mesh.h:332
Key refresh phase 3.
Definition: nrf_mesh.h:226
nrf_mesh_transmic_size_t
Message MIC size selection.
Definition: nrf_mesh.h:373
Bluetooth Mesh address.
Definition: nrf_mesh.h:362
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:352
int8_t rssi
RSSI value of the received packet.
Definition: nrf_mesh.h:114
Selects 8 byte MIC size for the transport PDU.
Definition: nrf_mesh.h:378
void(* nrf_mesh_assertion_handler_t)(uint32_t pc)
Mesh assertion handler type.
Definition: nrf_mesh.h:92
uint8_t nid
Network identifier.
Definition: nrf_mesh.h:256
timestamp_t timestamp
Device local timestamp of the start of the advertisement header of the packet in microseconds.
Definition: nrf_mesh.h:111
uint8_t aid
Application ID.
Definition: nrf_mesh.h:242
nrf_mesh_tx_token_t tx_token
TX Token attached to the loopback packet.
Definition: nrf_mesh.h:149
The packet came from this device.
Definition: nrf_mesh.h:105
const nrf_mesh_rx_metadata_t * p_metadata
Metadata structure for the given packet.
Definition: nrf_mesh.h:198
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:270
Key refresh phase 0.
Definition: nrf_mesh.h:220
#define NRF_MESH_NETID_SIZE
Size (in octets) of the network ID.
timestamp_t tx_timestamp
Last transmission time for this beacon.
Definition: nrf_mesh.h:291
ble_gap_addr_t adv_addr
Advertisement address in the packet.
Definition: nrf_mesh.h:115
bool is_device_key
Indicates whether the device key or the application is used.
Definition: nrf_mesh.h:240
net_state_iv_update_t
State of IV update procedure.
Definition: nrf_mesh.h:329
const nrf_mesh_network_secmat_t * p_net
Required for network layer encryption.
Definition: nrf_mesh.h:323
nrf_mesh_secmat_t security_material
Required for encryption.
Definition: nrf_mesh.h:408
Unicast address.
Definition: nrf_mesh.h:350
const uint8_t * p_payload
Pointer to the raw advertisement packet payload.
Definition: nrf_mesh.h:197

Documentation feedback | Developer Zone | Subscribe | Updated