Wirepas SDK
provisioning_int.h
Go to the documentation of this file.
1 /* Copyright 2019 Wirepas Ltd. All Rights Reserved.
2  *
3  * See file LICENSE.txt for full license details.
4  *
5  */
6 #ifndef _PROVISIONING_INT_H_
7 #define _PROVISIONING_INT_H_
8 
9 #include <stdint.h>
10 #include "api.h"
11 #include "aessw.h"
12 
13 
14 #if defined(MAC_PROFILE_ISM24) || defined(MAC_PROFILE_SUBG)
15 
16 /* Wirepas Provisioning Protocol endpoints for 2.4G and SubGHz
17  * - Downlink: Source: 255 ; Destination: 246
18  * - Uplink: Source: 246 ; Destination: 255
19  */
20 
22 #define PROV_DOWNLINK_SRC_EP 255
23 #define PROV_DOWNLINK_DST_EP 246
24 
25 #define PROV_UPLINK_SRC_EP 246
26 #define PROV_UPLINK_DST_EP 255
27 
28 #endif
29 
30 
32 #define PROV_PDU_SIZE 135
33 
35 #define PROV_CTR_SIZE 2
36 
38 #define PROV_MIC_SIZE 5
39 
41 #define ENC_KEY_OFFSET 16
42 
44 #define PROV_UID_TYPE_UUID_V4 0x01
45 
49 #define PROV_DATA_OFFSET (sizeof(pdu_prov_hdr_t) + 1 + PROV_CTR_SIZE)
50 
52 #define PROV_DATA_MIN_USER_ID 128
53 
55 #define PROV_DATA_MAX_USER_ID 255
56 
58 #define JOINING_NETWORK_ADDRESS 0x9E4ADC // "JBTX"
59 
61 #if defined(MAC_PROFILE_ISM24)
62 // For 2.4G MAC profiles, joining network channel is 36
63 #define JOINING_NETWORK_CHANNEL 36
64 #endif
65 
66 
67 #if defined(MAC_PROFILE_ISM24)
68 
72 #define JOINING_RX_TIMEOUT 600
73 #endif
74 
75 #if defined(MAC_PROFILE_ISM24)
76 
77 #define JOINING_TX_INTERVAL 500
78 #endif
79 
84 #if defined(MAC_PROFILE_ISM24) || defined(MAC_PROFILE_SUBG)
85 // SubG and 2.4G
86 #define JOINING_BEACON_TYPE 0x647650fb // "PROVIS"
87 
88 #endif
89 
93 #define PROV_START_FLAGS_NONE 0
94 
98 #define PROV_START_FLAGS_NW_PARAM_EQUAL_CHECK 1
99 
101 typedef enum {
113 
114 typedef enum
115 {
121 
122 typedef enum
123 {
129 
130 typedef struct __attribute__((__packed__))
131 {
132  uint8_t type;
134  uint8_t session_id;
136 
137 typedef struct __attribute__((__packed__))
138 {
140  uint8_t method;
142  uint8_t uid[PROV_PDU_SIZE -
145 
146 
147 typedef struct __attribute__((__packed__))
148 {
150  uint8_t key_index;
151  uint16_t counter;
153  /* Mic is added at the end of the data packet.
154  * uint8_t mic[PROV_MIC_SIZE];
155  */
157 
158 typedef struct __attribute__((__packed__))
159 {
162 
163 typedef struct __attribute__((__packed__))
164 {
166  uint8_t nack_type;
168 
169 typedef union __attribute__((__packed__))
170 {
171  union __attribute__((__packed__))
172  {
173  pdu_prov_hdr_t pdu_header;
174  uint8_t pld[PROV_PDU_SIZE - sizeof(pdu_prov_hdr_t)];
175  };
180 } pdu_prov_t;
181 
185 typedef struct
186 {
192  uint8_t * buffer;
194  uint8_t length;
196  uint8_t method;
198 
206 
210 typedef struct
211 {
217  uint8_t nb_retry;
219  uint8_t flags;
221 
227 
231 typedef struct
232 {
236  uint16_t timeout_sec;
238 
249  bool dry_run);
250 
265 
273 
283 
292  const provisioning_failsafe_conf_t * conf);
293 
301 
309 
310 #endif //_PROVISIONING_INT_H_
provisioning_joining_beacon_cb_f
const typedef app_lib_joining_received_beacon_t *(* provisioning_joining_beacon_cb_f)(const app_lib_joining_received_beacon_t *beacons)
Selects which joining beacon to connect to at the end of a scan.
Definition: provisioning.h:173
prov_nack_type_e
prov_nack_type_e
Definition: provisioning_int.h:122
PROV_DATA_ID_NET_KEY_SEQ
@ PROV_DATA_ID_NET_KEY_SEQ
Definition: provisioning_int.h:108
PROV_PACKET_TYPE_NACK
@ PROV_PACKET_TYPE_NACK
Definition: provisioning_int.h:119
pdu_prov_data_t::key_index
uint8_t key_index
Definition: provisioning_int.h:150
provisioning_res_e
provisioning_res_e
Provisioning result.
Definition: provisioning.h:48
pdu_prov_t
Definition: provisioning_int.h:169
PROV_DATA_OFFSET
#define PROV_DATA_OFFSET
Definition: provisioning_int.h:49
PROV_DATA_ID_MGMT_ENC_KEY
@ PROV_DATA_ID_MGMT_ENC_KEY
Definition: provisioning_int.h:109
provisioning_failsafe_conf_t
Structure to hold failsafe parameters.
Definition: provisioning_int.h:231
PROV_DATA_ID_NODE_ROLE
@ PROV_DATA_ID_NODE_ROLE
Definition: provisioning_int.h:107
provisioning_joining_end_cb_f
void(* provisioning_joining_end_cb_f)(provisioning_res_e result)
The end joining callback. This function is called at the end of the joining process.
Definition: provisioning_int.h:205
provisioning_joining_conf_t::joining_cb
provisioning_joining_beacon_cb_f joining_cb
Definition: provisioning_int.h:213
provisioning_joining_conf_t::nb_retry
uint8_t nb_retry
Definition: provisioning_int.h:217
provisioning_user_data_cb_f
void(* provisioning_user_data_cb_f)(uint32_t id, CborType type, uint8_t *data, uint8_t len)
Received User provisioning data callback. Provisioning data is received as a map of id:data....
Definition: provisioning.h:156
pdu_prov_data_t
Definition: provisioning_int.h:147
Provisioning_Joining_init
provisioning_ret_e Provisioning_Joining_init(provisioning_joining_conf_t *conf)
Initialize the Joining module.
pdu_prov_t::start
pdu_prov_start_t start
Definition: provisioning_int.h:176
pdu_prov_data_t::counter
uint16_t counter
Definition: provisioning_int.h:151
pdu_prov_hdr_t
Definition: provisioning_int.h:130
Provisioning_Failsafe_init
provisioning_ret_e Provisioning_Failsafe_init(const provisioning_failsafe_conf_t *conf)
Initialize the failsafe module.
pdu_prov_start_t::pdu_header
pdu_prov_hdr_t pdu_header
Definition: provisioning_int.h:139
pdu_prov_t::data
pdu_prov_data_t data
Definition: provisioning_int.h:177
PROV_NACK_TYPE_INVALID_DATA
@ PROV_NACK_TYPE_INVALID_DATA
Definition: provisioning_int.h:126
AES_128_KEY_BLOCK_SIZE
#define AES_128_KEY_BLOCK_SIZE
AES 128 block size in bytes.
Definition: aessw.h:13
pdu_prov_t::data_ack
pdu_prov_data_ack_t data_ack
Definition: provisioning_int.h:178
Provisioning_Failsafe_stop
provisioning_ret_e Provisioning_Failsafe_stop(void)
Stop failsafe.
PROV_PDU_SIZE
#define PROV_PDU_SIZE
Definition: provisioning_int.h:32
PROV_DATA_ID_AUTH_KEY
@ PROV_DATA_ID_AUTH_KEY
Definition: provisioning_int.h:103
pdu_prov_hdr_t::type
uint8_t type
Definition: provisioning_int.h:132
provisioning_start_cb_f
provisioning_ret_e(* provisioning_start_cb_f)(void)
Provisioning start callback.
Definition: provisioning_int.h:226
pdu_prov_start_t::method
uint8_t method
Definition: provisioning_int.h:140
pdu_prov_t::nack
pdu_prov_nack_t nack
Definition: provisioning_int.h:179
provisioning_data_conf_t::buffer
uint8_t * buffer
Definition: provisioning_int.h:192
PROV_MIC_SIZE
#define PROV_MIC_SIZE
Definition: provisioning_int.h:38
provisioning_data_ids_e
provisioning_data_ids_e
List of Wirepas Ids for CBOR encoded provisioning data.
Definition: provisioning_int.h:101
provisioning_data_conf_t::user_data_cb
provisioning_user_data_cb_f user_data_cb
Definition: provisioning_int.h:190
PROV_NACK_TYPE_METHOD_NOT_SUPPORTED
@ PROV_NACK_TYPE_METHOD_NOT_SUPPORTED
Definition: provisioning_int.h:125
provisioning_data_conf_t::end_cb
provisioning_end_cb_f end_cb
Definition: provisioning_int.h:188
pdu_prov_hdr_t::address
app_addr_t address
Definition: provisioning_int.h:133
provisioning_ret_e
provisioning_ret_e
Return codes of provisioning functions.
Definition: provisioning.h:37
pdu_prov_nack_t::nack_type
uint8_t nack_type
Definition: provisioning_int.h:166
pdu_prov_data_ack_t
Definition: provisioning_int.h:158
prov_packet_type_e
prov_packet_type_e
Definition: provisioning_int.h:114
provisioning_joining_conf_t::end_cb
provisioning_joining_end_cb_f end_cb
Definition: provisioning_int.h:215
provisioning_joining_conf_t::flags
uint8_t flags
Definition: provisioning_int.h:219
Provisioning_Joining_start
provisioning_ret_e Provisioning_Joining_start(void)
Start the joining process (listen to joining beacon and select a network to join).
PROV_DATA_ID_MGMT_KEY_SEQ
@ PROV_DATA_ID_MGMT_KEY_SEQ
Definition: provisioning_int.h:111
PROV_DATA_ID_NET_CHAN
@ PROV_DATA_ID_NET_CHAN
Definition: provisioning_int.h:105
PROV_NACK_TYPE_INVALID_KEY_IDX
@ PROV_NACK_TYPE_INVALID_KEY_IDX
Definition: provisioning_int.h:127
pdu_prov_start_t
Definition: provisioning_int.h:137
app_addr_t
uint32_t app_addr_t
Definition: wms_app.h:228
provisioning_end_cb_f
bool(* provisioning_end_cb_f)(provisioning_res_e result)
The end provisioning callback. This function is called at the end of the provisioning process.
Definition: provisioning.h:143
Provisioning_Failsafe_start
provisioning_ret_e Provisioning_Failsafe_start(void)
Start failsafe.
Provisioning_Joining_stop
provisioning_ret_e Provisioning_Joining_stop(void)
Stops the joining process.
PROV_PACKET_TYPE_DATA
@ PROV_PACKET_TYPE_DATA
Definition: provisioning_int.h:117
provisioning_joining_conf_t
This structure holds the joining node parameters.
Definition: provisioning_int.h:210
PROV_NACK_TYPE_NOT_AUTHORIZED
@ PROV_NACK_TYPE_NOT_AUTHORIZED
Definition: provisioning_int.h:124
PROV_PACKET_TYPE_START
@ PROV_PACKET_TYPE_START
Definition: provisioning_int.h:116
provisioning_data_conf_t::length
uint8_t length
Definition: provisioning_int.h:194
pdu_prov_hdr_t::session_id
uint8_t session_id
Definition: provisioning_int.h:134
pdu_prov_nack_t
Definition: provisioning_int.h:163
provisioning_failsafe_conf_t::start_cb
provisioning_start_cb_f start_cb
Definition: provisioning_int.h:234
aessw.h
provisioning_failsafe_conf_t::timeout_sec
uint16_t timeout_sec
Definition: provisioning_int.h:236
PROV_DATA_ID_NET_ADDR
@ PROV_DATA_ID_NET_ADDR
Definition: provisioning_int.h:104
PROV_DATA_ID_ENC_KEY
@ PROV_DATA_ID_ENC_KEY
Definition: provisioning_int.h:102
PROV_DATA_ID_NODE_ADDR
@ PROV_DATA_ID_NODE_ADDR
Definition: provisioning_int.h:106
Provisioning_Data_decode
provisioning_ret_e Provisioning_Data_decode(provisioning_data_conf_t *conf, bool dry_run)
Decode (and apply if valid) the received provisioning data.
provisioning_data_conf_t
This structure holds the provisioning data parameters.
Definition: provisioning_int.h:185
PROV_DATA_ID_MGMT_AUTH_KEY
@ PROV_DATA_ID_MGMT_AUTH_KEY
Definition: provisioning_int.h:110
PROV_PACKET_TYPE_DATA_ACK
@ PROV_PACKET_TYPE_DATA_ACK
Definition: provisioning_int.h:118
api.h