nRF5 SDK for Mesh v1.0.1
access.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 ACCESS_H__
39 #define ACCESS_H__
40 
41 #include <stdint.h>
42 #include "device_state_manager.h"
43 
69 #define ACCESS_HANDLE_INVALID (0xFFFF)
70 
71 #define ACCESS_COMPANY_ID_NONE (0xFFFF)
72 
73 #define ACCESS_COMPANY_ID_NORDIC (0x0059)
74 
76 #define ACCESS_ELEMENT_INDEX_INVALID (0xFFFF)
77 
84 #define ACCESS_OPCODE_SIG(opcode) { (opcode), ACCESS_COMPANY_ID_NONE }
85 
93 #define ACCESS_OPCODE_VENDOR(opcode, company) { (opcode), (company) }
94 
101 #define ACCESS_MODEL_SIG(id) { (id), ACCESS_COMPANY_ID_NONE }
102 
110 #define ACCESS_MODEL_VENDOR(id, company) { (id), (company) }
111 
113 #define ACCESS_TTL_USE_DEFAULT (0xFF)
114 
120 #define ACCESS_MESSAGE_LENGTH_MAX (NRF_MESH_SEG_PAYLOAD_SIZE_MAX)
121 
123 #define ACCESS_PUBLISH_PERIOD_STEP_MAX (0x3F)
124 
126 #define ACCESS_PUBLISH_STEP_RES_BITS (2)
127 
128 #define ACCESS_PUBLISH_STEP_NUM_BITS (6)
129 
131 #define ACCESS_PUBLISH_PERIOD_NONE { ACCESS_PUBLISH_RESOLUTION_100MS, 0 }
132 
141 /*lint -align_max(push) -align_max(1) */
142 
144 typedef struct __attribute((packed))
145 {
147  uint16_t model_id;
149  uint16_t company_id;
151 
152 /*lint -align_max(pop) */
153 
155 typedef uint16_t access_model_handle_t;
156 
163 typedef void (*access_publish_timeout_cb_t)(access_model_handle_t handle, void * p_args);
164 
180 typedef struct
181 {
183  uint16_t opcode;
185  uint16_t company_id;
187 
189 typedef struct
190 {
196  uint32_t timestamp;
198  int8_t rssi;
200  uint8_t ttl;
204 
206 typedef struct
207 {
211  const uint8_t * p_data;
213  uint16_t length;
217 
219 typedef struct
220 {
224  const uint8_t * p_buffer;
226  uint16_t length;
230 
239  const access_message_rx_t * p_message,
240  void * p_args);
241 
248 typedef struct
249 {
255 
259 typedef struct
260 {
264  uint16_t element_index;
268  uint32_t opcode_count;
273  void * p_args;
280 
284 typedef struct
285 {
291 
295 typedef enum
296 {
308 
316 void access_init(void);
317 
321 void access_clear(void);
322 
338 uint32_t access_model_add(const access_model_add_params_t * p_model_params,
339  access_model_handle_t * p_model_handle);
340 
357 uint32_t access_model_publish(access_model_handle_t handle, const access_message_tx_t * p_message);
358 
379  const access_message_rx_t * p_message,
380  const access_message_tx_t * p_reply);
381 
383 #endif /* ACCESS_H__ */
Step resolution: 100ms / step.
Definition: access.h:298
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:202
uint16_t access_model_handle_t
Access layer handle type.
Definition: access.h:155
access_opcode_t opcode
Opcode of the message.
Definition: access.h:209
uint32_t opcode_count
Number of opcode handles.
Definition: access.h:268
uint16_t company_id
Company ID.
Definition: access.h:149
const access_opcode_handler_t * p_opcode_handlers
Pointer to list of opcode handler callbacks.
Definition: access.h:266
Maximum publish resolution.
Definition: access.h:306
void access_clear(void)
Clears the access layer states, and erases the persistent storage copy.
uint8_t step_res
Step resolution.
Definition: access.h:287
access_opcode_handler_cb_t handler
The opcode handler callback for the given opcode.
Definition: access.h:253
void access_init(void)
Initializes the access layer.
void(* access_publish_timeout_cb_t)(access_model_handle_t handle, void *p_args)
Access layer publish timeout event callback.
Definition: access.h:163
uint8_t ttl
TTL value for the received message.
Definition: access.h:200
access_message_rx_meta_t meta_data
Meta data for the message.
Definition: access.h:215
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:295
uint16_t opcode
14-bit or 7-bit Bluetooth SIG defined opcode or 6-bit vendor specific opcode.
Definition: access.h:183
uint8_t step_num
Number of steps.
Definition: access.h:289
access_publish_timeout_cb_t publish_timeout_cb
Timeout callback called when the publication timer expires.
Definition: access.h:278
uint16_t element_index
Element index to add the model to.
Definition: access.h:264
nrf_mesh_address_t src
Source address of the message.
Definition: access.h:192
#define ACCESS_PUBLISH_STEP_RES_BITS
Publish step resolution, number of bits.
Definition: access.h:126
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:238
nrf_mesh_tx_token_t access_token
Token that can be used as a reference in the TX complete callback.
Definition: access.h:228
access_model_id_t model_id
SIG or Vendor Model ID.
Definition: access.h:262
#define ACCESS_PUBLISH_STEP_NUM_BITS
Publish step number, number of bits.
Definition: access.h:128
uint16_t model_id
Model ID.
Definition: access.h:147
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.
Metadata for received messages.
Definition: access.h:189
const uint8_t * p_buffer
Pointer to the message data.
Definition: access.h:224
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
access_opcode_t opcode
The model opcode.
Definition: access.h:251
int8_t rssi
RSSI value for the received message.
Definition: access.h:198
Access layer opcode type.
Definition: access.h:180
uint16_t company_id
Company ID.
Definition: access.h:185
Opcode handler type.
Definition: access.h:248
Step resolution: 10s / step.
Definition: access.h:302
Step resolution: 1s / step.
Definition: access.h:300
Access layer TX parameter structure.
Definition: access.h:219
uint16_t length
Length of the data (excluding the opcode).
Definition: access.h:226
uint16_t length
Length of p_data.
Definition: access.h:213
Bluetooth Mesh address.
Definition: nrf_mesh.h:370
Access model allocation parameter structure.
Definition: access.h:259
Model publish period structure.
Definition: access.h:284
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:144
void * p_args
Generic argument pointer.
Definition: access.h:273
uint32_t timestamp
Timestamp of when the (last part of the) message was received in microseconds.
Definition: access.h:196
access_opcode_t opcode
Opcode for the message.
Definition: access.h:222
Access layer RX event structure.
Definition: access.h:206
const uint8_t * p_data
Pointer to the first byte of message data (excludes the opcode).
Definition: access.h:211
Step resolution: 10min / step.
Definition: access.h:304
nrf_mesh_address_t dst
Destination address of the message.
Definition: access.h:194

Documentation feedback | Developer Zone | Subscribe | Updated