nRF5 SDK for Mesh v3.2.0  08c60f6
access.h
1 /* Copyright (c) 2010 - 2019, 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 
366 uint32_t access_model_add(const access_model_add_params_t * p_model_params,
367  access_model_handle_t * p_model_handle);
368 
405 uint32_t access_model_publish(access_model_handle_t handle, const access_message_tx_t * p_message);
406 
437  const access_message_rx_t * p_message,
438  const access_message_tx_t * p_reply);
439 
454 uint32_t access_model_element_index_get(access_model_handle_t handle, uint16_t * p_element_index);
455 
457 #endif /* ACCESS_H__ */
access_model_add_params_t
Access model allocation parameter structure.
Definition: access.h:271
access_opcode_handler_cb_t
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
access_message_rx_meta_t
Metadata for received messages.
Definition: access.h:196
access_opcode_t::company_id
uint16_t company_id
Company ID.
Definition: access.h:192
access_model_add_params_t::model_id
access_model_id_t model_id
SIG or Vendor Model ID.
Definition: access.h:274
ACCESS_PUBLISH_RETRANSMIT_INTERVAL_STEPS_BITS
#define ACCESS_PUBLISH_RETRANSMIT_INTERVAL_STEPS_BITS
Publish Retransmit Interval Steps, number of bits.
Definition: access.h:135
access_message_rx_meta_t::p_core_metadata
const nrf_mesh_rx_metadata_t * p_core_metadata
Core RX metadata attached to the packet.
Definition: access.h:207
ACCESS_PUBLISH_RESOLUTION_MAX
Maximum publish resolution.
Definition: access.h:332
access_opcode_handler_t
Opcode handler type.
Definition: access.h:260
access_message_rx_t
Access layer RX event structure.
Definition: access.h:213
access_message_rx_meta_t::appkey_handle
dsm_handle_t appkey_handle
Application key handle that decrypted the message.
Definition: access.h:205
access_opcode_handler_t::handler
access_opcode_handler_cb_t handler
The opcode handler callback for the given opcode.
Definition: access.h:265
access_message_tx_t::force_segmented
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
access_publish_period_t::step_res
uint8_t step_res
Step resolution.
Definition: access.h:302
access_message_rx_meta_t::src
nrf_mesh_address_t src
Source address of the message.
Definition: access.h:199
access_message_rx_meta_t::ttl
uint8_t ttl
TTL value for the received message.
Definition: access.h:203
access_publish_retransmit_t::count
uint8_t count
Publish Retransmit Count.
Definition: access.h:313
access_model_add_params_t::opcode_count
uint32_t opcode_count
Number of opcode handles.
Definition: access.h:283
access_publish_retransmit_t::interval_steps
uint8_t interval_steps
Publish Retransmit Interval Steps.
Definition: access.h:315
access_clear
void access_clear(void)
Clears the access layer states, and erases the persistent storage copy.
access_message_rx_t::meta_data
access_message_rx_meta_t meta_data
Meta data for the message.
Definition: access.h:222
access_model_add
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_PUBLISH_RETRANSMIT_COUNT_BITS
#define ACCESS_PUBLISH_RETRANSMIT_COUNT_BITS
Publish Retransmit Count, number of bits.
Definition: access.h:133
nrf_mesh_rx_metadata_t
RX packet metadata.
Definition: nrf_mesh.h:161
access_opcode_t
Access layer opcode type.
Definition: access.h:187
access_model_add_params_t::element_index
uint16_t element_index
Element index to add the model to.
Definition: access.h:276
access_model_handle_t
uint16_t access_model_handle_t
Access layer handle type.
Definition: access.h:162
access_publish_retransmit_t
Model publish retransmit structure.
Definition: access.h:310
ACCESS_PUBLISH_STEP_RES_BITS
#define ACCESS_PUBLISH_STEP_RES_BITS
Publish step resolution, number of bits.
Definition: access.h:129
ACCESS_PUBLISH_STEP_NUM_BITS
#define ACCESS_PUBLISH_STEP_NUM_BITS
Publish step number, number of bits.
Definition: access.h:131
access_message_tx_t::access_token
nrf_mesh_tx_token_t access_token
Token that can be used as a reference in the TX complete callback.
Definition: access.h:240
dsm_handle_t
uint16_t dsm_handle_t
DSM handle type, used for the handles returned for the each set of data added.
Definition: device_state_manager.h:85
access_opcode_t::opcode
uint16_t opcode
14-bit or 7-bit Bluetooth SIG defined opcode or 6-bit vendor specific opcode.
Definition: access.h:190
access_model_publish
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.
access_message_tx_t::length
uint16_t length
Length of the data (excluding the opcode).
Definition: access.h:233
ACCESS_PUBLISH_RESOLUTION_10S
Step resolution: 10s / step.
Definition: access.h:328
access_model_element_index_get
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.
nrf_mesh_tx_token_t
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_PUBLISH_RESOLUTION_1S
Step resolution: 1s / step.
Definition: access.h:326
access_publish_period_t
Model publish period structure.
Definition: access.h:299
access_model_id_t
Access layer model ID.
Definition: access.h:151
access_message_rx_t::length
uint16_t length
Length of p_data.
Definition: access.h:220
access_message_tx_t::transmic_size
nrf_mesh_transmic_size_t transmic_size
Select desired transport MIC size.
Definition: access.h:238
access_init
void access_init(void)
Initializes the access layer.
access_publish_timeout_cb_t
void(* access_publish_timeout_cb_t)(access_model_handle_t handle, void *p_args)
Access layer publish timeout event callback.
Definition: access.h:170
nrf_mesh_transmic_size_t
nrf_mesh_transmic_size_t
Message MIC size selection.
Definition: nrf_mesh.h:385
access_model_add_params_t::p_args
void * p_args
Generic argument pointer.
Definition: access.h:288
access_model_add_params_t::publish_timeout_cb
access_publish_timeout_cb_t publish_timeout_cb
Timeout callback called when the publication timer expires.
Definition: access.h:293
access_message_tx_t::p_buffer
const uint8_t * p_buffer
Pointer to the message data.
Definition: access.h:231
access_message_tx_t::opcode
access_opcode_t opcode
Opcode for the message.
Definition: access.h:229
nrf_mesh_address_t
Bluetooth Mesh address.
Definition: nrf_mesh.h:374
access_publish_resolution_t
access_publish_resolution_t
Periodic publishing step resolution.
Definition: access.h:321
access_model_add_params_t::p_opcode_handlers
const access_opcode_handler_t * p_opcode_handlers
Pointer to list of opcode handler callbacks.
Definition: access.h:281
ACCESS_PUBLISH_RESOLUTION_10MIN
Step resolution: 10min / step.
Definition: access.h:330
access_message_rx_t::p_data
const uint8_t * p_data
Pointer to the first byte of message data (excludes the opcode).
Definition: access.h:218
access_opcode_handler_t::opcode
access_opcode_t opcode
The model opcode.
Definition: access.h:263
access_model_id_t::model_id
uint16_t model_id
Model ID.
Definition: access.h:156
access_model_id_t::company_id
uint16_t company_id
Company ID.
Definition: access.h:154
access_message_rx_t::opcode
access_opcode_t opcode
Opcode of the message.
Definition: access.h:216
access_publish_period_t::step_num
uint8_t step_num
Number of steps.
Definition: access.h:304
access_message_rx_meta_t::subnet_handle
dsm_handle_t subnet_handle
Network key handle that decrypted the message.
Definition: access.h:209
access_message_rx_meta_t::dst
nrf_mesh_address_t dst
Destination address of the message.
Definition: access.h:201
access_message_tx_t
Access layer TX parameter structure.
Definition: access.h:226
ACCESS_PUBLISH_RESOLUTION_100MS
Step resolution: 100ms / step.
Definition: access.h:324
access_model_reply
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.