Digi XBee(R) ANSI C Host Library
zcl_commissioning.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2012 Digi International Inc.,
3  * All rights not expressly granted are reserved.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
7  * You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
10  * =======================================================================
11  */
12 
22 #ifndef ZCL_COMMISSIONING_H
23 #define ZCL_COMMISSIONING_H
24 
25 #include "xbee/platform.h"
26 #include "wpan/types.h"
27 #include "zigbee/zcl.h"
28 #include "zigbee/zcl_types.h"
29 
31 
32 #define ZCL_CLUST_COMMISSIONING 0x0015
33 
34 #define ZCL_CLUST_ENTRY_COMMISSIONING_SERVER \
35  { ZCL_CLUST_COMMISSIONING, &zcl_comm_clust_handler, \
36  zcl_comm_startup_attribute_tree, WPAN_CLUST_FLAG_SERVER }
37 
38 // Global commissioning EPID for use in defining zcl_comm_default_sas
39 #define ZCL_COMM_GLOBAL_EPID ZCL64_INIT( 0x0050C277, 0x10000000 )
40 
41 extern const zcl64_t zcl_comm_global_epid;
42 
43 typedef struct zcl_comm_startup_param_t {
44  // Must start with short_address so cluster handler can use the attribute
45  // tree to find this structure.
46  uint16_t short_address;
47  zcl64_t extended_panid;
48  uint16_t panid;
49  uint32_t channel_mask;
50  uint8_t startup_control;
51  #define ZCL_COMM_STARTUP_JOINED 0x00
52  #define ZCL_COMM_STARTUP_COORDINATOR 0x01
53  #define ZCL_COMM_STARTUP_REJOIN 0x02
54  #define ZCL_COMM_STARTUP_FROM_SCRATCH 0x03
55 
56 /*
57  addr64 trust_ctr_addr;
58  uint8_t trust_ctr_master_key_le[16];
59 */
60  uint8_t network_key_le[16];
61  bool_t use_insecure_join;
62  uint8_t preconfig_link_key_le[16];
63  uint8_t network_key_seq_num;
64  uint8_t network_key_type;
65  #define ZCL_COMM_KEY_TYPE_STANDARD 0x01
66  #define ZCL_COMM_KEY_TYPE_HIGH_SECURITY 0x05
67  uint16_t network_mgr_addr;
68 
69  uint8_t scan_attempts;
70  #define ZCL_COMM_SCAN_ATTEMPTS_DEFAULT 0x05
71  uint16_t time_between_scans;
72  #define ZCL_COMM_TIME_BETWEEN_SCANS_DEFAULT 0x0064
73  uint16_t rejoin_interval;
74  #define ZCL_COMM_REJOIN_INTERVAL_DEFAULT 0x003c
75  uint16_t max_rejoin_interval;
76  #define ZCL_COMM_MAX_REJOIN_INTERVAL_DEFAULT 0x0e10
77 
78  struct {
79  bool_t flag;
80  uint8_t radius;
81  #define ZCL_COMM_CONCENTRATOR_RADIUS_DEFAULT 0x0F
82  uint8_t discovery_time;
83  } concentrator;
85 
86 typedef struct zcl_comm_state_t
87 {
89  uint8_t flags;
91  #define ZCL_COMM_FLAG_SAVE_ON_JOIN 0x01
92  #define ZCL_COMM_FLAG_DELAYED_RESTART 0x02
94  #define ZCL_COMM_FLAG_COORDINATOR_OK 0x04
96  #define ZCL_COMM_FLAG_ROUTER_OK 0x08
98  #define ZCL_COMM_FLAG_ENDDEV_OK 0x10
100  #define ZCL_COMM_FLAG_FACTORY_RESET 0x40
102  #define ZCL_COMM_FLAG_INSTALL 0x80
104  uint32_t restart_ms;
106 
107  uint8_t state;
109  #define ZCL_COMM_STATE_INIT 0x00
110  #define ZCL_COMM_STATE_LOADING 0x01
112  #define ZCL_COMM_STATE_STARTUP 0x02
114  #define ZCL_COMM_STATE_UNJOINED 0x03
116  #define ZCL_COMM_STATE_REFRESH 0x04
118  #define ZCL_COMM_STATE_JOINED 0x05
121 
122 // attribute list of startup parameters
123 typedef struct zcl_comm_startup_attr_t {
124  zcl_attribute_base_t short_address;
125  zcl_attribute_base_t extended_panid;
126  zcl_attribute_base_t panid;
127  zcl_attribute_base_t channel_mask;
128  zcl_attribute_full_t startup_control; // limited range of values
129  zcl_attribute_base_t trust_ctr_addr;
130  zcl_attribute_base_t trust_ctr_master_key;
131  zcl_attribute_base_t network_key;
132  zcl_attribute_base_t use_insecure_join;
133  zcl_attribute_base_t preconfig_link_key;
134  zcl_attribute_base_t network_key_seq_num;
135  zcl_attribute_base_t network_key_type;
136  zcl_attribute_base_t network_mgr_addr;
137  zcl_attribute_full_t scan_attempts;
138  zcl_attribute_full_t time_between_scans;
139  zcl_attribute_full_t rejoin_interval;
140  zcl_attribute_full_t max_rejoin_interval;
141  struct {
143  zcl_attribute_base_t radius;
144  zcl_attribute_base_t discovery_time;
145  } concentrator;
146  uint16_t end_of_list;
148 
149 // current startup attributes
150 extern zcl_comm_state_t zcl_comm_state;
151 
152 // defaults, provided by the application
153 extern const zcl_comm_startup_param_t zcl_comm_default_sas;
154 
155 // structures for the actual cluster
156 extern const zcl_comm_startup_attr_t zcl_comm_startup_attributes;
157 extern const zcl_attribute_tree_t zcl_comm_startup_attribute_tree[];
158 
159 // Startup Parameters
160 #define ZCL_COMM_ATTR_SHORT_ADDRESS 0x0000 // UINT16
161 #define ZCL_COMM_ATTR_EXTENDED_PANID 0x0001 // IEEE Addr
162 #define ZCL_COMM_ATTR_PANID 0x0002 // UINT16
163 #define ZCL_COMM_ATTR_CHANNEL_MASK 0x0003 // BITMAP32
164 #define ZCL_COMM_ATTR_PROTOCOL_VERSION 0x0004 // UINT8
165 #define ZCL_COMM_ATTR_STACK_PROFILE 0x0005 // UINT8
166 #define ZCL_COMM_ATTR_STARTUP_CONTROL 0x0006 // ENUM8
167 
168 // Startup Parameters (Security)
169 #define ZCL_COMM_ATTR_TRUST_CTR_ADDR 0x0010 // IEEE Addr
170 #define ZCL_COMM_ATTR_TRUST_CTR_MASTER_KEY 0x0011 // Security Key
171 #define ZCL_COMM_ATTR_NETWORK_KEY 0x0012 // Security Key
172 #define ZCL_COMM_ATTR_USE_INSECURE_JOIN 0x0013 // Boolean
173 #define ZCL_COMM_ATTR_PRECONFIG_LINK_KEY 0x0014 // Security Key
174 #define ZCL_COMM_ATTR_NETWORK_KEY_SEQ_NUM 0x0015 // UINT8
175 #define ZCL_COMM_ATTR_NETWORK_KEY_TYPE 0x0016 // ENUM8
176 #define ZCL_COMM_ATTR_NETWORK_MGR_ADDR 0x0017 // UINT16
177 
178 // Join Parameters
179 #define ZCL_COMM_ATTR_SCAN_ATTEMPTS 0x0020 // UINT8
180 #define ZCL_COMM_ATTR_TIME_BTWN_SCANS 0x0021 // UINT16
181 #define ZCL_COMM_ATTR_REJOIN_INTERVAL 0x0022 // UINT16
182 #define ZCL_COMM_ATTR_MAX_REJOIN_INTERVAL 0x0023 // UINT16
183 
184 // End Device Parameters
185 #define ZCL_COMM_ATTR_INDIRECT_POLL_RATE 0x0030 // UINT16
186 #define ZCL_COMM_ATTR_PARENT_RETRY_THRESHOLD 0x0031 // UINT8
187 
188 // Concentrator Parameters
189 #define ZCL_COMM_ATTR_CONCENTRATOR_FLAG 0x0040 // Boolean
190 #define ZCL_COMM_ATTR_CONCENTRATOR_RADIUS 0x0041 // UINT8
191 #define ZCL_COMM_ATTR_CONCENTRATOR_DISC_TIME 0x0042 // UINT8
192 
193 // Client-generated commands
194 #define ZCL_COMM_CMD_RESTART_DEVICE 0x00
195 typedef XBEE_PACKED(zcl_comm_restart_device_cmd_t,
196 {
197  uint8_t options;
198  #define ZCL_COMM_RESTART_OPT_MODE_MASK 0x07
199  #define ZCL_COMM_RESTART_OPT_MODE_SAVE_CHANGES 0x00
200  #define ZCL_COMM_RESTART_OPT_MODE_NO_CHANGES 0x01
201  #define ZCL_COMM_RESTART_OPT_IMMEDIATE 0x08
202  #define ZCL_COMM_RESTART_OPT_RESERVED_MASK 0xF0
203  uint8_t delay; // delay in seconds before restarting
204  uint8_t jitter; // add RAND(jitter * 80) ms to delay
206 
207 #define ZCL_COMM_CMD_SAVE_STARTUP_PARAM 0x01
208 typedef XBEE_PACKED(zcl_comm_save_startup_param_t,
209 {
210  uint8_t options;
211  uint8_t index;
213 
214 #define ZCL_COMM_CMD_RESTORE_STARTUP_PARAM 0x02
216 {
217  uint8_t options;
218  uint8_t index;
220 
221 #define ZCL_COMM_CMD_RESET_STARTUP_PARAM 0x03
222 typedef XBEE_PACKED(zcl_comm_reset_startup_param_t,
223 {
224  uint8_t options;
225  #define ZCL_COMM_RESET_OPT_CURRENT 0x01
226  #define ZCL_COMM_RESET_OPT_ALL 0x02
227  #define ZCL_COMM_RESET_OPT_ERASE_INDEX 0x04
228  uint8_t index;
230 
231 
232 // Server-generated commands
233 #define ZCL_COMM_CMD_RESTART_DEVICE_RESP 0x00
234 #define ZCL_COMM_CMD_SAVE_STARTUP_PARAM_RESP 0x01
235 #define ZCL_COMM_CMD_RESTORE_STARTUP_PARAM_RESP 0x02
236 #define ZCL_COMM_CMD_RESET_STARTUP_PARAM_RESP 0x03
237 
238 
239 int zcl_comm_response( const wpan_envelope_t FAR *envelope,
240  uint_fast8_t status);
241 
242 // Send commands from client to server
244  const zcl_comm_restart_device_cmd_t *parameters);
246  const zcl_comm_reset_startup_param_t *parameters);
247 
248 // Commissioning Server support functions
249 void zcl_comm_sas_init( zcl_comm_startup_param_t *parameters);
250 int zcl_comm_clust_handler( const wpan_envelope_t FAR *envelope,
251  void FAR *context);
252 
253 void zcl_comm_factory_reset( uint16_t ms_delay);
254 
256 
257 // If compiling in Dynamic C, automatically #use the appropriate C file.
258 #ifdef __DC__
259  #use "zcl_commissioning.c"
260 #endif
261 
262 #endif // ZCL_COMMISSIONING_H defined
263 
unsigned long uint32_t
32-bit unsigned integer
Definition: platform_config.h:43
Definition: zcl_commissioning.h:86
WPAN datatypes and support functions, valid for ZigBee and DigiMesh.
#define FAR
On platforms with "far" pointers, define to the proper keyword; empty definition if not required...
Definition: platform.h:396
int zcl_comm_response(const wpan_envelope_t FAR *envelope, uint_fast8_t status)
Send response to a Commissioning Server Cluster request.
Definition: zcl_commissioning.c:265
#define XBEE_BEGIN_DECLS
Macro defined to.
Definition: platform.h:41
Common header for Hardware Abstraction Layer.
void zcl_comm_factory_reset(uint16_t ms_delay)
Perform a locally-triggered factory reset to default SAS.
Definition: zcl_commissioning.c:723
int zcl_comm_reset_parameters(wpan_envelope_t FAR *envelope, const zcl_comm_reset_startup_param_t *parameters)
Send a "Reset Startup Parameters" command to the ZCL Commissioning Cluster.
Definition: zcl_commissioning.c:464
Header for implementation of ZigBee Cluster Library.
Basic structure for storing a list of attributes in a cluster.
Definition: zcl.h:735
unsigned short uint16_t
16-bit unsigned integer
Definition: platform_config.h:41
Definition: zcl_commissioning.h:208
int zcl_comm_restart_device(wpan_envelope_t FAR *envelope, const zcl_comm_restart_device_cmd_t *parameters)
Send a "Restart Device" command to the ZCL Commissioning Cluster.
Definition: zcl_commissioning.c:409
Definition: zcl_commissioning.h:43
Definition: zcl.h:854
Definition: jslong_glue.h:30
unsigned char uint8_t
8-bit unsigned integer
Definition: platform_config.h:39
Use this structure for attributes with min/max values or the need to have a read/write function...
Definition: zcl.h:779
Definition: zcl_commissioning.h:205
Definition: zcl_commissioning.h:123
Definition: zcl_commissioning.h:215
#define XBEE_END_DECLS
Macro defined to.
Definition: platform.h:42
int bool_t
Variable that can hold 0 or 1, may be an int for speed purporses or uint8_t for size optimization...
Definition: platform_config.h:51
The "envelope" is used to gather all necessary information about a given frame on the network...
Definition: aps.h:40
Definition: zcl_commissioning.h:222
Macros and structures related to the ZCL datatypes.