nRF5 SDK for Mesh v1.0.1
nrf_mesh.h
1 /* Copyright (c) 2010 - 2017, 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 
76 typedef void (*nrf_mesh_assertion_handler_t)(uint32_t pc);
77 
79 typedef uint32_t nrf_mesh_tx_token_t;
80 
82 typedef enum
83 {
90 
92 typedef struct
93 {
94  uint32_t timestamp;
95  uint32_t access_addr;
96  uint8_t channel;
97  int8_t rssi;
98  ble_gap_addr_t adv_addr;
99  uint8_t adv_type;
101 
102 typedef struct
103 {
104  uint16_t data_id;
105  uint8_t set_id;
107 
109 typedef struct
110 {
111  uint32_t timestamp;
112  uint8_t channel;
113  int8_t rssi;
114  struct
115  {
117  uint8_t packet_index;
118  bool is_last_in_chain;
119  } event;
121 
123 typedef struct
124 {
126  union
127  {
132  } params;
134 
156 typedef bool (*nrf_mesh_relay_check_cb_t)(uint16_t src, uint16_t dst, uint8_t ttl);
157 
159 typedef struct
160 {
161  uint8_t adv_type;
162  uint8_t length;
163  const uint8_t * p_payload;
166 
176 typedef void (*nrf_mesh_rx_cb_t)(const nrf_mesh_adv_packet_rx_data_t * p_rx_data);
177 
183 typedef enum
184 {
194 
202 typedef struct nrf_mesh_beacon_timer
203 {
205  uint32_t timestamp;
207  void (*callback)(uint32_t, void*);
209  uint32_t interval;
211  void * p_context;
213  struct nrf_mesh_beacon_timer * p_next;
215 
224 typedef struct
225 {
229  uint8_t aid;
231  uint8_t key[NRF_MESH_KEY_SIZE];
233 
240 typedef struct
241 {
243  uint8_t nid;
245  uint8_t encryption_key[NRF_MESH_KEY_SIZE];
247  uint8_t privacy_key[NRF_MESH_KEY_SIZE];
249 
257 typedef struct
258 {
260  uint8_t key[NRF_MESH_KEY_SIZE];
262  uint8_t net_id[NRF_MESH_NETID_SIZE];
264 
269 typedef struct
270 {
272  uint16_t rx_count;
276  uint32_t tx_timestamp;
278 
280 typedef struct __nrf_mesh_beacon_info_t nrf_mesh_beacon_info_t;
281 
297 typedef void (*nrf_mesh_net_beacon_cb_t)(const nrf_mesh_beacon_info_t * p_beacon,
298  const uint8_t * p_netid, uint32_t iv_index, bool iv_update, bool key_refresh);
299 
306 {
318 };
319 
328 typedef struct
329 {
335 
337 typedef enum
338 {
344 
353 typedef enum
354 {
364 
370 typedef struct
371 {
375  uint16_t value;
377  const uint8_t * p_virtual_uuid;
379 
386 typedef struct
387 {
391  uint16_t src;
393  uint8_t ttl;
395  bool reliable;
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(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
420  uint8_t irq_priority;
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_ble_evt(ble_evt_t * p_ble_evt);
545 
559 uint32_t nrf_mesh_on_sd_evt(uint32_t sd_evt);
560 
567 
571 void nrf_mesh_rx_cb_clear(void);
572 
575 #endif /* NRF_MESH_H__ */
Invalid address.
Definition: nrf_mesh.h:356
uint32_t nrf_mesh_init(const nrf_mesh_init_params_t *p_init_params)
Initializes the Bluetooth Mesh stack.
nrf_mesh_beacon_secmat_t secmat_updated
Beacon security material during key refresh.
Definition: nrf_mesh.h:315
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:276
uint32_t nrf_mesh_disable(void)
Disables the Mesh.
RX packet metadata.
Definition: nrf_mesh.h:123
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:377
nrf_mesh_rx_metadata_instaburst_t instaburst
Instaburst packet metadata.
Definition: nrf_mesh.h:131
uint32_t timestamp
Timestamp of the packet in microseconds.
Definition: nrf_mesh.h:111
#define NRF_MESH_KEY_SIZE
Size (in octets) of an encryption key.
uint16_t value
Address value.
Definition: nrf_mesh.h:375
bool reliable
See Section 3.7.5.2 in the Mesh Profile Specification v1.0.
Definition: nrf_mesh.h:395
nrf_mesh_assertion_handler_t assertion_handler
Assert callback function.
Definition: nrf_mesh.h:418
Network security material structure.
Definition: nrf_mesh.h:240
const nrf_mesh_application_secmat_t * p_app
Required for transport layer encryption.
Definition: nrf_mesh.h:333
int8_t rssi
RSSI value of the received packet.
Definition: nrf_mesh.h:113
nrf_mesh_net_beacon_cb_t callback
Callback function for received beacons.
Definition: nrf_mesh.h:317
uint16_t tx_interval_seconds
Current beacon interval in seconds.
Definition: nrf_mesh.h:274
uint32_t access_addr
Access address the packet was received on.
Definition: nrf_mesh.h:95
uint8_t adv_type
BLE GAP advertising type.
Definition: nrf_mesh.h:161
The packet came from the scanner.
Definition: nrf_mesh.h:84
Mesh packet transmission parameters.
Definition: nrf_mesh.h:386
Key refresh phase 2.
Definition: nrf_mesh.h:190
uint16_t data_len
Length of the payload being sent.
Definition: nrf_mesh.h:399
Bluetooth Mesh beacon timer structure.
Definition: nrf_mesh.h:202
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
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:156
uint8_t length
Length of the advertisement packet payload.
Definition: nrf_mesh.h:162
Application security material structure.
Definition: nrf_mesh.h:224
const uint8_t * p_data
Points to the payload to be sent.
Definition: nrf_mesh.h:397
nrf_mesh_beacon_secmat_t secmat
Beacon security material.
Definition: nrf_mesh.h:313
uint8_t channel
Channel the packet was received on.
Definition: nrf_mesh.h:112
The packet came from a friend node.
Definition: nrf_mesh.h:86
The packet came from an Instaburst event.
Definition: nrf_mesh.h:88
Arguments structure for the RX callback function.
Definition: nrf_mesh.h:159
uint32_t nrf_mesh_enable(void)
Enables the Mesh.
uint32_t timestamp
Timestamp of the packet in microseconds.
Definition: nrf_mesh.h:94
uint32_t timestamp
Timestamp at which the beacon is sent.
Definition: nrf_mesh.h:205
nrf_mesh_address_type_t
Bluetooth Mesh address types.
Definition: nrf_mesh.h:353
Run-time transmission information for individual beacons.
Definition: nrf_mesh.h:269
IV update procedure in progress.
Definition: nrf_mesh.h:342
uint32_t nrf_mesh_on_ble_evt(ble_evt_t *p_ble_evt)
Pass SoftDevice BLE events to the Mesh.
The packet came from a GATT connection.
Definition: nrf_mesh.h:85
uint16_t src
Address of the element the packet originates from (must be a unicast address).
Definition: nrf_mesh.h:391
Bluetooth Mesh security material structure.
Definition: nrf_mesh.h:328
nrf_mesh_address_type_t type
Address type.
Definition: nrf_mesh.h:373
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_THREAD if thread mode).
Definition: nrf_mesh.h:420
uint8_t channel
Channel the packet was received on.
Definition: nrf_mesh.h:96
uint32_t interval
Interval between each beacon packet.
Definition: nrf_mesh.h:209
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:176
Key refresh phase 1.
Definition: nrf_mesh.h:188
nrf_mesh_rx_source_t source
Source of the received packet.
Definition: nrf_mesh.h:125
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:79
nrf_mesh_relay_check_cb_t relay_cb
Application call back for relay decisions, can be NULL.
Definition: nrf_mesh.h:419
nrf_mesh_key_refresh_phase_t
Key refresh phase.
Definition: nrf_mesh.h:183
Metadata structure for packets received with Instaburst.
Definition: nrf_mesh.h:109
The packet came from a low power node.
Definition: nrf_mesh.h:87
nrf_mesh_rx_metadata_scanner_t scanner
Scanner packet metadata.
Definition: nrf_mesh.h:129
nrf_mesh_beacon_tx_info_t * p_tx_info
Pointer to a transmission info structure.
Definition: nrf_mesh.h:311
nrf_mesh_rx_source_t
RX packet type.
Definition: nrf_mesh.h:82
Initialization parameters structure.
Definition: nrf_mesh.h:409
uint16_t rx_count
Number of beacons received since this beacon was last transmitted.
Definition: nrf_mesh.h:272
uint8_t ttl
Time to live value for the packet, this is a 7 bit value.
Definition: nrf_mesh.h:393
bool iv_update_permitted
Flag indicating whether the given structure is allowed to initiate an IV update.
Definition: nrf_mesh.h:309
uint8_t adv_type
BLE GAP advertising type.
Definition: nrf_mesh.h:99
Information structure for the Bluetooth Mesh network beacons.
Definition: nrf_mesh.h:305
Metadata structure for packets received with the scanner.
Definition: nrf_mesh.h:92
struct nrf_mesh_beacon_timer * p_next
Pointer to next beacon in linked list.
Definition: nrf_mesh.h:213
nrf_mesh_address_t dst
Packet destination address.
Definition: nrf_mesh.h:389
In normal operation.
Definition: nrf_mesh.h:340
Key refresh phase 3.
Definition: nrf_mesh.h:192
Bluetooth Mesh address.
Definition: nrf_mesh.h:370
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:360
void * p_context
Beacon context pointer.
Definition: nrf_mesh.h:211
int8_t rssi
RSSI value of the received packet.
Definition: nrf_mesh.h:97
void(* nrf_mesh_assertion_handler_t)(uint32_t pc)
Mesh assertion handler type.
Definition: nrf_mesh.h:76
uint8_t nid
Network identifier.
Definition: nrf_mesh.h:243
uint8_t aid
Application ID.
Definition: nrf_mesh.h:229
const nrf_mesh_rx_metadata_t * p_metadata
Metadata structure for the given packet.
Definition: nrf_mesh.h:164
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:257
Key refresh phase 0.
Definition: nrf_mesh.h:186
#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:98
bool is_device_key
Indicates whether the device key or the application is used.
Definition: nrf_mesh.h:227
void(* nrf_mesh_net_beacon_cb_t)(const nrf_mesh_beacon_info_t *p_beacon, const uint8_t *p_netid, uint32_t iv_index, bool iv_update, bool key_refresh)
Callback function for incoming network beacons.
Definition: nrf_mesh.h:297
net_state_iv_update_t
State of IV update procedure.
Definition: nrf_mesh.h:337
const nrf_mesh_network_secmat_t * p_net
Required for network layer encryption.
Definition: nrf_mesh.h:331
nrf_mesh_secmat_t security_material
Required for encryption.
Definition: nrf_mesh.h:401
Unicast address.
Definition: nrf_mesh.h:358
const uint8_t * p_payload
Pointer to the raw advertisement packet payload.
Definition: nrf_mesh.h:163

Documentation feedback | Developer Zone | Subscribe | Updated