nRF5 SDK for Mesh v5.0.0
access.h
1 /* Copyright (c) 2010 - 2020, 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 ACCESS_H__
39 #define ACCESS_H__
40 
41 #include <stdint.h>
42 #include "device_state_manager.h"
43 #include "nrf_mesh.h"
44 
72 #define ACCESS_HANDLE_INVALID (0xFFFF)
73 
74 #define ACCESS_COMPANY_ID_NONE (0xFFFF)
75 
76 #define ACCESS_COMPANY_ID_NORDIC (0x0059)
77 
79 #define ACCESS_ELEMENT_INDEX_INVALID (0xFFFF)
80 
87 #define ACCESS_OPCODE_SIG(opcode) { (opcode), ACCESS_COMPANY_ID_NONE }
88 
96 #define ACCESS_OPCODE_VENDOR(opcode, company) { (opcode), (company) }
97 
104 #define ACCESS_MODEL_SIG(id) {.company_id = ACCESS_COMPANY_ID_NONE, .model_id = (id)}
105 
113 #define ACCESS_MODEL_VENDOR(id, company) {.company_id = (company), .model_id = (id)}
114 
116 #define ACCESS_TTL_USE_DEFAULT (0xFF)
117 
123 #define ACCESS_MESSAGE_LENGTH_MAX (NRF_MESH_SEG_PAYLOAD_SIZE_MAX)
124 
126 #define ACCESS_PUBLISH_PERIOD_STEP_MAX (0x3F)
127 
129 #define ACCESS_PUBLISH_STEP_RES_BITS (2)
130 
131 #define ACCESS_PUBLISH_STEP_NUM_BITS (6)
132 
133 #define ACCESS_PUBLISH_RETRANSMIT_COUNT_BITS (3)
134 
135 #define ACCESS_PUBLISH_RETRANSMIT_INTERVAL_STEPS_BITS (5)
136 
138 #define ACCESS_PUBLISH_PERIOD_NONE { ACCESS_PUBLISH_RESOLUTION_100MS, 0 }
139 
148 /*lint -align_max(push) -align_max(1) */
149 
151 typedef struct __attribute((packed))
152 {
154  uint16_t company_id;
156  uint16_t model_id;
158 
159 /*lint -align_max(pop) */
160 
162 typedef uint16_t access_model_handle_t;
163 
170 typedef void (*access_publish_timeout_cb_t)(access_model_handle_t handle, void * p_args);
171 
187 typedef struct
188 {
190  uint16_t opcode;
192  uint16_t company_id;
194 
196 typedef struct
197 {
203  uint8_t ttl;
211 
213 typedef struct
214 {
218  const uint8_t * p_data;
220  uint16_t length;
224 
226 typedef struct
227 {
231  const uint8_t * p_buffer;
233  uint16_t length;
242 
251  const access_message_rx_t * p_message,
252  void * p_args);
253 
260 typedef struct
261 {
267 
271 typedef struct
272 {
276  uint16_t element_index;
283  uint32_t opcode_count;
288  void * p_args;
295 
299 typedef struct
300 {
306 
310 typedef struct
311 {
317 
321 typedef enum
322 {
334 
342 void access_init(void);
343 
347 void access_clear(void);
348 
367 uint32_t access_model_add(const access_model_add_params_t * p_model_params,
368  access_model_handle_t * p_model_handle);
369 
407 uint32_t access_model_publish(access_model_handle_t handle, const access_message_tx_t * p_message);
408 
439  const access_message_rx_t * p_message,
440  const access_message_tx_t * p_reply);
441 
456 uint32_t access_model_element_index_get(access_model_handle_t handle, uint16_t * p_element_index);
457 
459 #endif /* ACCESS_H__ */
Step resolution: 100ms / step.
Definition: access.h:324
uint32_t access_model_publish(access_model_handle_t handle, const access_message_tx_t *p_message)
Publishes an access layer message to the publish address of the model.
dsm_handle_t appkey_handle
Application key handle that decrypted the message.
Definition: access.h:205
uint16_t access_model_handle_t
Access layer handle type.
Definition: access.h:162
RX packet metadata.
Definition: nrf_mesh.h:161
access_opcode_t opcode
Opcode of the message.
Definition: access.h:216
uint32_t opcode_count
Number of opcode handles.
Definition: access.h:283
uint32_t access_model_element_index_get(access_model_handle_t handle, uint16_t *p_element_index)
Returns the element index for the model handle.
uint16_t company_id
Company ID.
Definition: access.h:154
dsm_handle_t subnet_handle
Network key handle that decrypted the message.
Definition: access.h:209
const access_opcode_handler_t * p_opcode_handlers
Pointer to list of opcode handler callbacks.
Definition: access.h:281
Maximum publish resolution.
Definition: access.h:332
void access_clear(void)
Clears the access layer states, and erases the persistent storage copy.
uint8_t step_res
Step resolution.
Definition: access.h:302
Model publish retransmit structure.
Definition: access.h:310
access_opcode_handler_cb_t handler
The opcode handler callback for the given opcode.
Definition: access.h:265
const nrf_mesh_rx_metadata_t * p_core_metadata
Core RX metadata attached to the packet.
Definition: access.h:207
#define ACCESS_PUBLISH_RETRANSMIT_INTERVAL_STEPS_BITS
Publish Retransmit Interval Steps, number of bits.
Definition: access.h:135
void access_init(void)
Initializes the access layer.
bool force_segmented
Forces the message to be sent out as a segmented message, if message is shorter than the size require...
Definition: access.h:236
void(* access_publish_timeout_cb_t)(access_model_handle_t handle, void *p_args)
Access layer publish timeout event callback.
Definition: access.h:170
uint8_t ttl
TTL value for the received message.
Definition: access.h:203
access_message_rx_meta_t meta_data
Meta data for the message.
Definition: access.h:222
uint16_t dsm_handle_t
DSM handle type, used for the handles returned for the each set of data added.
access_publish_resolution_t
Periodic publishing step resolution.
Definition: access.h:321
uint16_t opcode
14-bit or 7-bit Bluetooth SIG defined opcode or 6-bit vendor specific opcode.
Definition: access.h:190
uint8_t step_num
Number of steps.
Definition: access.h:304
access_publish_timeout_cb_t publish_timeout_cb
Timeout callback called when the publication timer expires.
Definition: access.h:293
uint16_t element_index
Element index to add the model to.
Definition: access.h:276
nrf_mesh_address_t src
Source address of the message.
Definition: access.h:199
#define ACCESS_PUBLISH_STEP_RES_BITS
Publish step resolution, number of bits.
Definition: access.h:129
void(* access_opcode_handler_cb_t)(access_model_handle_t handle, const access_message_rx_t *p_message, void *p_args)
Access layer opcode handler callback type.
Definition: access.h:250
nrf_mesh_tx_token_t access_token
Token that can be used as a reference in the TX complete callback.
Definition: access.h:240
access_model_id_t model_id
SIG or Vendor Model ID.
Definition: access.h:274
#define ACCESS_PUBLISH_STEP_NUM_BITS
Publish step number, number of bits.
Definition: access.h:131
uint16_t model_id
Model ID.
Definition: access.h:156
uint32_t access_model_reply(access_model_handle_t handle, const access_message_rx_t *p_message, const access_message_tx_t *p_reply)
Replies to an access layer message.
uint8_t interval_steps
Publish Retransmit Interval Steps.
Definition: access.h:315
nrf_mesh_transmic_size_t transmic_size
Select desired transport MIC size.
Definition: access.h:238
Metadata for received messages.
Definition: access.h:196
const uint8_t * p_buffer
Pointer to the message data.
Definition: access.h:231
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:105
access_opcode_t opcode
The model opcode.
Definition: access.h:263
Access layer opcode type.
Definition: access.h:187
uint16_t company_id
Company ID.
Definition: access.h:192
Opcode handler type.
Definition: access.h:260
Step resolution: 10s / step.
Definition: access.h:328
Step resolution: 1s / step.
Definition: access.h:326
Access layer TX parameter structure.
Definition: access.h:226
uint16_t length
Length of the data (excluding the opcode).
Definition: access.h:233
uint16_t length
Length of p_data.
Definition: access.h:220
nrf_mesh_transmic_size_t
Message MIC size selection.
Definition: nrf_mesh.h:385
Bluetooth Mesh address.
Definition: nrf_mesh.h:374
Access model allocation parameter structure.
Definition: access.h:271
#define ACCESS_PUBLISH_RETRANSMIT_COUNT_BITS
Publish Retransmit Count, number of bits.
Definition: access.h:133
Model publish period structure.
Definition: access.h:299
uint32_t access_model_add(const access_model_add_params_t *p_model_params, access_model_handle_t *p_model_handle)
Allocates, initializes and adds a model to the element at the given element index.
Access layer model ID.
Definition: access.h:151
void * p_args
Generic argument pointer.
Definition: access.h:288
access_opcode_t opcode
Opcode for the message.
Definition: access.h:229
Access layer RX event structure.
Definition: access.h:213
const uint8_t * p_data
Pointer to the first byte of message data (excludes the opcode).
Definition: access.h:218
uint8_t count
Publish Retransmit Count.
Definition: access.h:313
Step resolution: 10min / step.
Definition: access.h:330
nrf_mesh_address_t dst
Destination address of the message.
Definition: access.h:201

Documentation feedback | Developer Zone | Subscribe | Updated