Digi XBee(R) ANSI C Host Library
zcl_ota_upgrade.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 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., 9350 Excelsior Blvd., Suite 700, Hopkins, MN 55343
10  * ===========================================================================
11  */
12 
28 #ifndef ZCL_OTA_UPGRADE_H
29 #define ZCL_OTA_UPGRADE_H
30 
31 #include "xbee/platform.h"
32 #include "wpan/types.h"
33 #include "zigbee/zcl_types.h"
34 
36 
37 #define ZCL_CLUST_OTA_UPGRADE 0x0019
38 
40 typedef XBEE_PACKED(zcl_ota_image_id_t, {
41  uint16_t mfg_code_le;
42  uint16_t image_type_le;
43  uint32_t file_version_le;
45 
47 typedef XBEE_PACKED(zcl_ota_file_header_t, {
49  uint32_t file_id_le;
51  uint16_t header_ver_le;
53  uint16_t header_len_le;
55  uint16_t field_control_le;
59  uint16_t zigbee_stack_ver_le;
61  char ota_header_string[32];
63  uint32_t image_size_le;
65 
66 /*
67 // Optional fields after zcl_ota_file_header_t, based on field_control_le bits:
68  uint8_t security_cred_ver; ///< Security credential version
69  addr64 upgrade_dest_le; ///< Upgrade file destination
70  uint16_t min_hardware_ver_le; ///< Minimum hardware version
71  uint16_t max_hardware_ver_le; ///< Maximum hardware version
72 */
73 
75 #define ZCL_OTA_FILE_ID 0x0BEEF11E
76 
78 #define ZCL_OTA_HEADER_VER 0x0100
79 
80 // bitfields for field_control_le element of zcl_ota_file_header_t
81 #define ZCL_OTA_FIELD_CONTROL_SECURITY_CRED (1<<0)
82 #define ZCL_OTA_FIELD_CONTROL_DEVICE_SPECIFIC (1<<1)
83 #define ZCL_OTA_FIELD_CONTROL_HARDWARE_VERSIONS (1<<2)
84 
85 // values for image_type_le element of zcl_ota_file_header_t
86 #define ZCL_OTA_IMAGE_TYPE_CLIENT_SECURITY_CREDS 0xFFC0
87 #define ZCL_OTA_IMAGE_TYPE_CLIENT_CONFIG 0xFFC1
88 #define ZCL_OTA_IMAGE_TYPE_SERVER_LOG 0xFFC2
89 #define ZCL_OTA_IMAGE_TYPE_WILDCARD 0xFFFF
90 
91 // values for zigbee_stack_ver_le element of zcl_ota_file_header_t
92 #define ZCL_OTA_ZIGBEE_STACK_2006 0x0000
93 #define ZCL_OTA_ZIGBEE_STACK_2007 0x0001
94 #define ZCL_OTA_ZIGBEE_STACK_PRO 0x0002
95 #define ZCL_OTA_ZIGBEE_STACK_IP 0x0003
96 
97 // values for optional security_cred_ver
98 #define ZCL_OTA_SECURITY_CRED_SE_10 0x00
99 #define ZCL_OTA_SECURITY_CRED_SE_11 0x01
100 #define ZCL_OTA_SECURITY_CRED_SE_20 0x02
101 
103 typedef XBEE_PACKED(zcl_ota_element_t, {
105  uint16_t tag_id_le;
107  uint32_t length_le;
108  // followed by <length_le> bytes of data
110 
111 #define ZCL_OTA_TAG_ID_UPGRADE_IMAGE 0x0000
112 #define ZCL_OTA_TAG_ID_ECDSA_SIGNATURE 0x0001
113 #define ZCL_OTA_TAG_ID_ECDSA_CERTIFICATE 0x0002
114 #define ZCL_OTA_TAG_ID_IMAGE_INTEGRITY_CODE 0x0003
115 
117 typedef XBEE_PACKED(zcl_ota_element_ecdsa_signature_t, {
118  uint16_t tag_id_le;
119  uint32_t length_le;
120  addr64 signer_addr_le;
121  uint8_t signature[42];
123 
125 typedef XBEE_PACKED(zcl_ota_element_ecdsa_cert_t, {
126  uint16_t tag_id_le;
127  uint32_t length_le;
128  uint8_t cert[48];
130 
132 typedef XBEE_PACKED(zcl_ota_element_integrity_code_t, {
133  uint16_t tag_id_le;
134  uint32_t length_le;
135  uint8_t hash[16];
137 
138 // OTA Cluster Attributes (client side)
139 #define ZCL_OTA_ATTR_UPGRADE_SERVER_ID 0x0000 // IEEE Address
140 #define ZCL_OTA_ATTR_FILE_OFFSET 0x0001 // UINT32
141 #define ZCL_OTA_ATTR_CURRENT_FILE_VER 0x0002 // UINT32
142 #define ZCL_OTA_ATTR_CURRENT_ZIGBEE_STACK_VER 0x0003 // UINT16
143 #define ZCL_OTA_ATTR_DOWNLOAD_FILE_VER 0x0004 // UINT32
144 #define ZCL_OTA_ATTR_DOWNLOAD_ZIGBEE_STACK_VER 0x0005 // UINT16
145 #define ZCL_OTA_ATTR_IMAGE_UPGRADE_STATUS 0x0006 // ENUM8
146 #define ZCL_OTA_ATTR_MANUFACTURER_ID 0x0007 // UINT16
147 #define ZCL_OTA_ATTR_IMAGE_TYPE_ID 0x0008 // UINT16
148 #define ZCL_OTA_ATTR_MIN_BLOCK_REQUEST_DELAY 0x0009 // UINT16
149 #define ZCL_OTA_ATTR_IMAGE_STAMP 0x000A // UINT32
150 
151 // Server-generated commands
152 #define ZCL_OTA_CMD_IMAGE_NOTIFY 0x00
153 #define ZCL_OTA_CMD_QUERY_NEXT_IMAGE_RESP 0x02
154 #define ZCL_OTA_CMD_IMAGE_BLOCK_RESP 0x05
155 #define ZCL_OTA_CMD_UPGRADE_END_RESP 0x07
156 #define ZCL_OTA_CMD_QUERY_SPECIFIC_FILE_RESP 0x09
157 
158 // Client-generated commands
159 #define ZCL_OTA_CMD_QUERY_NEXT_IMAGE_REQ 0x01
160 #define ZCL_OTA_CMD_IMAGE_BLOCK_REQ 0x03
161 #define ZCL_OTA_CMD_IMAGE_PAGE_REQ 0x04
162 #define ZCL_OTA_CMD_UPGRADE_END_REQ 0x06
163 #define ZCL_OTA_CMD_QUERY_SPECIFIC_FILE_REQ 0x08
164 
165 typedef XBEE_PACKED(zcl_ota_image_notify_t, {
166  uint8_t payload_type;
167 #define ZCL_OTA_IMAGE_NOTIFY_PAYLOAD_JITTER_ONLY 0x00 // ends at .query_jitter
168 #define ZCL_OTA_IMAGE_NOTIFY_PAYLOAD_INC_MFG_CODE 0x01 // ends at .id.mfg_code_le
169 #define ZCL_OTA_IMAGE_NOTIFY_PAYLOAD_INC_IMAGE_TYPE 0x02 // ends at .id.image_type_le
170 #define ZCL_OTA_IMAGE_NOTIFY_PAYLOAD_INC_FILE_VERSION 0x03 // ends at .id.file_version_le
171  uint8_t query_jitter;
172  zcl_ota_image_id_t id;
174 
175 typedef XBEE_PACKED(zcl_ota_query_next_image_req_t, {
176  uint8_t field_control;
177 #define ZCL_OTA_QUERY_NEXT_IMAGE_FIELD_HARDWARE_VER (1<<0)
179  id;
180  uint16_t hardware_ver_le;
182 
183 typedef XBEE_PACKED(zcl_ota_query_next_image_resp_t, {
184  uint8_t status;
185  zcl_ota_image_id_t id;
186  uint32_t image_size_le;
188 
189 typedef XBEE_PACKED(zcl_ota_image_block_req_t, {
190  uint8_t field_control;
191 #define ZCL_OTA_IMAGE_BLOCK_FIELD_NODE_ADDR (1<<0)
192 #define ZCL_OTA_IMAGE_BLOCK_FIELD_BLOCK_DELAY (1<<1)
193  zcl_ota_image_id_t id;
194  uint32_t file_offset_le;
195  uint8_t max_data_size;
196  addr64 request_node_addr_le;
197  uint16_t block_request_delay_le; // in milliseconds
199 
200 typedef XBEE_PACKED(zcl_ota_image_page_req_t, {
201  uint8_t field_control;
202 #define ZCL_OTA_IMAGE_PAGE_FIELD_NODE_ADDR (1<<0)
203  zcl_ota_image_id_t id;
204  uint32_t file_offset_le;
205  uint8_t max_data_size;
206  uint16_t page_size_le;
207  uint16_t response_spacing_le;
208  addr64 request_node_addr_le;
210 
211 typedef XBEE_PACKED(zcl_ota_image_block_resp_t, {
212  union {
213  uint8_t status;
214  XBEE_PACKED(, {
215  uint8_t status; // set to ZCL_STATUS_SUCCESS
216  zcl_ota_image_id_t id;
217  uint32_t file_offset_le;
218  uint8_t data_size;
219  // followed by <data_size> bytes of image data
220  }) success;
221  XBEE_PACKED(, {
222  uint8_t status; // set to ZCL_STATUS_WAIT_FOR_DATA
223  zcl_utctime_t current_time_le;
224  zcl_utctime_t request_time_le;
225  uint16_t block_request_delay_le;
226  }) wait_for_data;
227  XBEE_PACKED(, {
228  uint8_t status; // set to ZCL_STATUS_ABORT
229  }) abort;
230  } u;
232 
233 typedef XBEE_PACKED(zcl_ota_upgrade_end_req_t, {
234  uint8_t status;
235  zcl_ota_image_id_t id;
237 
238 typedef XBEE_PACKED(zcl_ota_upgrade_end_resp_t, {
239  zcl_ota_image_id_t id;
240  zcl_utctime_t current_time_le;
241  zcl_utctime_t upgrade_time_le;
243 
244 
247 
250 
252 const char *zcl_ota_tag_identifier_str(uint16_t id);
253 
256 
258 
259 #endif // ZCL_OTA_UPGRADE_H defined
260 
unsigned long uint32_t
32-bit unsigned integer
Definition: platform_config.h:43
uint32_t zcl_ota_tag_identifier_length(uint16_t id)
The expected length (or 0 for variable) of an OTA file&#39;s Sub-Element Tag.
Definition: zcl_ota_upgrade.c:77
WPAN datatypes and support functions, valid for ZigBee and DigiMesh.
Sub-element with signature for the entire file, must be last in the file.
Definition: zcl_ota_upgrade.h:122
#define XBEE_BEGIN_DECLS
Macro defined to.
Definition: platform.h:41
Common header for Hardware Abstraction Layer.
OTA Upgrade File Header.
Definition: zcl_ota_upgrade.h:64
< upgrade image identification
Definition: zcl_ota_upgrade.h:236
< upgrade image identification
Definition: zcl_ota_upgrade.h:198
< upgrade image identification
Definition: zcl_ota_upgrade.h:242
Sub-element with a hash value to verify the integrity of the OTA file.
Definition: zcl_ota_upgrade.h:136
< new image identification
Definition: zcl_ota_upgrade.h:187
const char * zcl_ota_tag_identifier_str(uint16_t id)
Return a description for an OTA header&#39;s Sub-Element Tag.
Definition: zcl_ota_upgrade.c:52
unsigned short uint16_t
16-bit unsigned integer
Definition: platform_config.h:41
< upgrade image identification
Definition: zcl_ota_upgrade.h:231
unsigned char uint8_t
8-bit unsigned integer
Definition: platform_config.h:39
Common sequence of fields appearing in multiple frame formats.
Definition: zcl_ota_upgrade.h:44
< upgrade image identification
Definition: zcl_ota_upgrade.h:209
< new image identification
Definition: zcl_ota_upgrade.h:173
const char * zcl_ota_security_credential_ver_str(uint8_t v)
Return a description for an OTA header&#39;s Security Credential Version.
Definition: zcl_ota_upgrade.c:41
Header of sub-elements in OTA Upgrade File following zcl_ota_file_header_t.
Definition: zcl_ota_upgrade.h:109
Typedef used to hold a 64-bit IEEE address, represented as 8 bytes, 4 16-bit values or 2 32-bit value...
Definition: types.h:34
< current image identification
Definition: zcl_ota_upgrade.h:181
#define XBEE_END_DECLS
Macro defined to.
Definition: platform.h:42
const char * zcl_ota_zigbee_stack_ver_str(uint16_t v)
Return a description for an OTA header&#39;s Zigbee Stack Version.
Definition: zcl_ota_upgrade.c:29
Macros and structures related to the ZCL datatypes.
Sub-element with the certificate used to generate the OTA file&#39;s signature.
Definition: zcl_ota_upgrade.h:129