Zigbee Protocol Controller 1.6.0
zigpc_common_zigbee.h
Go to the documentation of this file.
1/******************************************************************************
2 * # License
3 * <b>Copyright 2020 Silicon Laboratories Inc. www.silabs.com</b>
4 ******************************************************************************
5 * The licensor of this software is Silicon Laboratories Inc. Your use of this
6 * software is governed by the terms of Silicon Labs Master Software License
7 * Agreement (MSLA) available at
8 * www.silabs.com/about-us/legal/master-software-license-agreement. This
9 * software is distributed to you in Source Code format and is governed by the
10 * sections of the MSLA applicable to Source Code.
11 *
12 *****************************************************************************/
13
24#ifndef ZIGPC_COMMON_ZIGBEE_H
25#define ZIGPC_COMMON_ZIGBEE_H
26
27#include <stddef.h>
28#include <stdint.h>
29#include <stdbool.h>
30#include "sl_status.h"
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
39#define ZIGBEE_EUI64_SIZE 8
40
44#define ZIGBEE_NULL_EUI64 \
45 { \
46 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF \
47 }
48
52#define ZIGBEE_NULL_EUI64_UINT 0xFFFFFFFFFFFFFFFF
53
58#define ZIGBEE_EUI64_HEX_STR_LENGTH ((ZIGBEE_EUI64_SIZE * 2) + 1)
59
63#define ZIGBEE_EXTENDED_PAN_ID_SIZE 8
64
69#define ZIGBEE_INSTALL_CODE_LENGTH (16 + 2)
70
76#define ZIGBEE_MAX_ENDPOINT_COUNT 255
77
83#define ZIGBEE_INVALID_APP_ENDPOINT_ID 0
84#define ZIGBEE_DEFAULT_APP_ENDPOINT_ID 1
85
89#define ZCL_DEFAULT_STR_LENGTH 256
90
94#define ZCL_DEFAULT_ARR_LENGTH 16
95
100#define ZCL_GROUP_NAME_LENGTH 16
101
107#define ZCL_MIN_CLUSTER_ID 0x0000
108#define ZCL_MAX_CLUSTER_ID 0x7fff
109#define ZCL_MIN_MFCTR_ID 0xfc00
110#define ZCL_MAX_MFCTR_ID 0xffff
111
117#define ZCL_MIN_COMMAND_ID 0x00
118#define ZCL_MAX_COMMAND_ID 0x7f
119
125#define ZCL_MIN_STD_ATTR_ID 0x0000
126#define ZCL_MAX_STD_ATTR_ID 0x4fff
127#define ZCL_MIN_GLOB_ATTR_ID 0xf000
128#define ZCL_MAX_GLOB_ATTR_ID 0xfffe
129
136#define ZCL_INVALID_CLUSTER_ID (ZCL_MAX_CLUSTER_ID + 1)
137
148#define ZCL_INVALID_ATTR_ID (ZCL_MAX_STD_ATTR_ID + 1)
149#define ZCL_INVALID_COMMAND_ID 0x80
150
151#define ZCL_MIN_CLUSTER_ID 0x0000
152#define ZCL_MAX_CLUSTER_ID 0x7fff
153#define ZCL_MIN_MFCTR_ID 0xfc00
154#define ZCL_MAX_MFCTR_ID 0xffff
155#define ZCL_MIN_COMMAND_ID 0x00
156#define ZCL_MAX_COMMAND_ID 0x7f
157
162#define ZCL_FRAME_BUFFER_SIZE_MAX 255
163
168#define ZCL_FRAME_CONTROL_FRAME_TYPE_GLOBAL_COMMAND ((uint8_t)(0x0 << 0))
169
174#define ZCL_FRAME_CONTROL_FRAME_TYPE_CLUSTER ((uint8_t)(0x1 << 0))
175
180#define ZCL_FRAME_CONTROL_DIRECTION_CLIENT_TO_SERVER ((uint8_t)(0x0 << 3))
181
182#define ZCL_GLOBAL_COMMAND_ID_READ_ATTRIBUTES (0x00)
183#define ZCL_GLOBAL_COMMAND_ID_WRITE_ATTRIBUTES (0x02)
184
185#define ZCL_ATTRIBUTE_RESPONSE_RECORDS_MAX 20
186
194
199typedef uint64_t zigbee_eui64_uint_t;
200
207
212typedef uint16_t zigbee_panid_t;
213
219
225
230typedef uint16_t zigbee_group_id_t;
231
237
238/*
239 * @brief Zigbee Network Multicast identifier
240 *
241 */
242typedef uint16_t zigbee_multicast_id_t;
243
248typedef uint8_t zigbee_endpoint_id_t;
249
254typedef uint16_t zcl_cluster_id_t;
255
260typedef uint16_t zcl_attribute_id_t;
261
262static const bool ATTR_DIRECTION_REPORTED = true;
264
265typedef uint8_t zcl_command_id_t;
266
267typedef enum {
271
272typedef uint8_t zcl_command_field_t;
273
276};
277
291};
292
293typedef struct {
294 size_t size;
298
302typedef struct zcl_command {
303 uint16_t cluster_id;
307
315
320typedef enum e_zcl_cluster_side {
324
335
339typedef struct zcl_attribute {
348
353typedef struct {
357
362typedef struct {
365 unsigned int cluster_count;
369
370typedef struct zcl_profile {
373
375 unsigned int num_attributes;
376
378
379typedef struct
380{
387
389
396
403
410
417
424
431
438
441
442typedef enum {
447
453typedef struct {
456 unsigned int endpoint_count;
461
471
482
492 const zigbee_eui64_t src);
493
502void zigpc_common_switch_endian(uint8_t *source, uint8_t *dest, size_t size);
503
519 char *str_buf,
520 const size_t str_length);
521
537sl_status_t str_to_zigbee_eui64(const char *str_buf,
538 const size_t str_length,
539 zigbee_eui64_t eui64);
540
553 char *dest_unid,
554 const size_t dest_unid_length);
555
567bool is_valid_zcl_command(const zcl_command_t command);
568
582
591bool is_valid_zcl_attribute(const zcl_attribute_t attribute);
592
608 zcl_attribute_t *dest,
609 unsigned int list_size);
610
619bool is_valid_zcl_cluster(const zcl_cluster_type_t cluster);
620
635 zcl_cluster_type_t *dest,
636 unsigned int list_size);
637
648bool is_valid_zigbee_node(const zigbee_node_t node);
649
663
674
688 zigbee_endpoint_t *dest);
689
691 zigbee_endpoint_t *dest,
692 unsigned int list_size);
693
704 zcl_command_id_t command_id,
705 uint8_t frame_control);
706
719 enum zcl_frame_data_type type,
720 const void *data);
721
735 const uint8_t *const data,
736 unsigned int data_size);
737
738#ifdef __cplusplus
739}
740#endif
741
742#endif /* ZIGPC_COMMON_ZIGBEE_H */
743
#define data
Definition: ctimer.c:49
uint32_t sl_status_t
Definition: sl_status.h:139
uint16_t zcl_attribute_id_t
A representation of the endpoint cluster attribute ID used in ZCL.
Definition: zigpc_common_zigbee.h:260
uint8_t zcl_command_field_t
Definition: zigpc_common_zigbee.h:272
zigbee_node_network_status
The possible states that a Zigbee node can be in.
Definition: zigpc_common_zigbee.h:394
sl_status_t copy_command(const zcl_command_t source, zcl_command_t *dest)
Performs a deep copy of a ZCL Command. Does not require a "free"-ing of memory, as the zcl_command_t ...
Definition: zigpc_common_zigbee.c:235
bool is_valid_zcl_cluster(const zcl_cluster_type_t cluster)
checks if a given ZCL cluster is valid or not
Definition: zigpc_common_zigbee.c:210
#define ZCL_INVALID_COMMAND_ID
Definition: zigpc_common_zigbee.h:149
sl_status_t zigpc_common_zcl_frame_fill_data(zcl_frame_t *const frame, enum zcl_frame_data_type type, const void *data)
Populate the given ZCL frame with data. The data copied is dictated by the type passed in....
Definition: zigpc_common_zcl_frame.c:48
sl_status_t zigpc_common_zcl_frame_fill_raw(zcl_frame_t *const frame, const uint8_t *const data, unsigned int data_size)
Populate the given ZCL frame with data. Copies raw data from a buffer of a specified size.
Definition: zigpc_common_zcl_frame.c:96
uint16_t zigbee_panid_t
Zigbee Network PAN ID.
Definition: zigpc_common_zigbee.h:212
uint8_t zigbee_eui64_t[ZIGBEE_EUI64_SIZE]
Zigbee Device EUI64 ID.
Definition: zigpc_common_zigbee.h:193
sl_status_t str_to_zigbee_eui64(const char *str_buf, const size_t str_length, zigbee_eui64_t eui64)
Extract the Zigbee EUI64 from a UNID string. Only the last 8 bytes of the number are considered.
Definition: zigpc_common_zigbee.c:99
enum e_zcl_cluster_side zcl_cluster_side_t
An enum representing the role of the cluster on the network.
bool is_valid_zcl_command(const zcl_command_t command)
check if a given zcl command is valid or not
Definition: zigpc_common_zigbee.c:163
sl_status_t copy_cluster_list(const zcl_cluster_type_t *const source, zcl_cluster_type_t *dest, unsigned int list_size)
Allocates memory and performs a deep copy of a ZCL Cluster Type. Memory allocated here must be freed.
Definition: zigpc_common_zigbee.c:285
e_zcl_attribute_type
Definition: zigpc_common_zigbee.h:325
#define ZCL_FRAME_BUFFER_SIZE_MAX
Definition: zigpc_common_zigbee.h:162
#define ZIGBEE_EUI64_SIZE
Size of EUI64 (an IEEE address) in bytes (8)
Definition: zigpc_common_zigbee.h:39
zcl_frame_data_type
Definition: zigpc_common_zigbee.h:278
sl_status_t copy_attribute_list(const zcl_attribute_t *const source, zcl_attribute_t *dest, unsigned int list_size)
Performs a deep copy of a ZCL Attribute. Does not require a "free"-ing of memory, as the zcl_attribut...
Definition: zigpc_common_zigbee.c:250
static const zigbee_group_id_t ZIGBEE_NULL_GROUP_ID
ZIGBEE_NULL_GROUP_ID The NULL group id, usually used for unicast zigbee operations.
Definition: zigpc_common_zigbee.h:236
uint8_t zigbee_radio_channel_t
Zigbee Network Radio Channel.
Definition: zigpc_common_zigbee.h:224
bool is_valid_zcl_attribute(const zcl_attribute_t attribute)
checks if a given ZCL attribute is valid or not
Definition: zigpc_common_zigbee.c:183
uint8_t zigbee_install_code_t[ZIGBEE_INSTALL_CODE_LENGTH]
Zigbee 3.0 Install Code.
Definition: zigpc_common_zigbee.h:206
static const zcl_command_t null_command
a static data structure representing an NULL or INVALID value for ZCL commands
Definition: zigpc_common_zigbee.h:313
uint16_t zcl_cluster_id_t
A representation of the endpoint cluster id used in ZCL.
Definition: zigpc_common_zigbee.h:254
sl_status_t zigpc_common_zcl_frame_init_command(zcl_frame_t *const frame, zcl_command_id_t command_id, uint8_t frame_control)
Initialize the ZCL Frame for sending ZCL command.
Definition: zigpc_common_zcl_frame.c:23
bool is_valid_zigbee_endpoint(const zigbee_endpoint_t endpoint)
checks if a given zigbee endpoint is valid or not. For now all endpoints are considered valid
Definition: zigpc_common_zigbee.c:228
sl_status_t zigbee_uint_to_eui64(zigbee_eui64_uint_t src, zigbee_eui64_t dest)
Convert the 64-bit uint EUI64 representation into array representation.
Definition: zigpc_common_zigbee.c:43
zcl_command_type_t
Definition: zigpc_common_zigbee.h:267
zigbee_eui64_uint_t zigbee_eui64_to_uint(const zigbee_eui64_t eui64)
Convert the array EUI64 representation into 64-bit uint representation.
Definition: zigpc_common_zigbee.c:23
sl_status_t copy_node(const zigbee_node_t source, zigbee_node_t *dest)
Allocates memory and performs a deep copy of a Zigbee Node. Memory allocated here must be freed.
Definition: zigpc_common_zigbee.c:347
sl_status_t copy_endpoint(const zigbee_endpoint_t source, zigbee_endpoint_t *dest)
Allocates memory and performs a deep copy of a Zigbee Endpoint. Memory allocated here must be freed.
Definition: zigpc_common_zigbee.c:303
uint64_t zigbee_eui64_uint_t
Zigbee Device Identifier (stored as integer)
Definition: zigpc_common_zigbee.h:199
struct zcl_command zcl_command_t
sl_status_t zigpc_common_eui64_to_unid(const zigbee_eui64_t eui64, char *dest_unid, const size_t dest_unid_length)
Convert the Zigbee EUI64 to a UNID string with the UNID prefix configured.
Definition: zigpc_common_zigbee.c:141
void zigpc_common_switch_endian(uint8_t *source, uint8_t *dest, size_t size)
Copy a given buffer of data to another destination, inverting the endianness.
Definition: zigpc_common_zigbee.c:67
#define ZCL_DEFAULT_ARR_LENGTH
Default string length for strings used in ZCL.
Definition: zigpc_common_zigbee.h:94
uint16_t zigbee_multicast_id_t
Definition: zigpc_common_zigbee.h:242
zcl_status_type
Definition: zigpc_common_zigbee.h:274
bool is_valid_zigbee_node(const zigbee_node_t node)
checks if a given zigbee node is valid or not. A zigbee node is considered valid if it has a valid EU...
Definition: zigpc_common_zigbee.c:220
sl_status_t copy_endpoint_list(const zigbee_endpoint_t *const source, zigbee_endpoint_t *dest, unsigned int list_size)
Definition: zigpc_common_zigbee.c:324
uint8_t zigbee_ext_panid_t[ZIGBEE_EXTENDED_PAN_ID_SIZE]
Zigbee Network Extended PAN ID.
Definition: zigpc_common_zigbee.h:218
uint16_t zigbee_group_id_t
Zigbee Group Id The internal representation of a group_id.
Definition: zigpc_common_zigbee.h:230
static const zigbee_binding_t NULL_BINDING
Definition: zigpc_common_zigbee.h:388
struct zcl_profile zcl_profile_t
void zigbee_eui64_copy_switch_endian(zigbee_eui64_t dst, const zigbee_eui64_t src)
Copy EUI64 and switch endianness (BE<->LE) If the src EUI64 is LE, the populated dst EUI64 will be BE...
Definition: zigpc_common_zigbee.c:59
#define ZIGBEE_INSTALL_CODE_LENGTH
Definition: zigpc_common_zigbee.h:69
static const bool ATTR_DIRECTION_REPORTED
Definition: zigpc_common_zigbee.h:262
uint8_t zigbee_endpoint_id_t
A representation of the endpoint id used on the Zigbee protocol.
Definition: zigpc_common_zigbee.h:248
e_zcl_cluster_side
An enum representing the role of the cluster on the network.
Definition: zigpc_common_zigbee.h:320
#define ZCL_INVALID_CLUSTER_ID
Definition: zigpc_common_zigbee.h:136
zdo_status_t
Definition: zigpc_common_zigbee.h:442
#define ZIGBEE_EXTENDED_PAN_ID_SIZE
Size of an extended PAN identifier in bytes (8).
Definition: zigpc_common_zigbee.h:63
#define ZCL_DEFAULT_STR_LENGTH
Default string length for strings used in ZCL.
Definition: zigpc_common_zigbee.h:89
static const bool ATTR_DIRECTION_DESIRED
Definition: zigpc_common_zigbee.h:263
uint8_t zcl_command_id_t
Definition: zigpc_common_zigbee.h:265
sl_status_t zigbee_eui64_to_str(const zigbee_eui64_t eui64, char *str_buf, const size_t str_length)
Convert EUI64 (in BE) into string format based on the hex representation.
Definition: zigpc_common_zigbee.c:76
struct zcl_attribute zcl_attribute_t
enum zigbee_node_network_status zigbee_node_network_status_t
The possible states that a Zigbee node can be in.
@ ZIGBEE_NODE_STATUS_MAX_VAL
Definition: zigpc_common_zigbee.h:439
@ ZIGBEE_NODE_STATUS_NODEID_ASSIGNED
This state corresponds to when the node has completed joining the protocol controller network.
Definition: zigpc_common_zigbee.h:402
@ ZIGBEE_NODE_STATUS_INTERVIEW_FAIL
This state corresponds to when the node has timed out from the interview process.
Definition: zigpc_common_zigbee.h:416
@ ZIGBEE_NODE_STATUS_INCLUDED
This state corresponds to when the node has completed interviewing and ready to be serviced by the pr...
Definition: zigpc_common_zigbee.h:409
@ ZIGBEE_NODE_STATUS_INVALID
Definition: zigpc_common_zigbee.h:395
@ ZIGBEE_NODE_STATUS_UNAVAILABLE
This state corresponds to when the node is not accepting any commands from the protocol controller.
Definition: zigpc_common_zigbee.h:437
@ ZIGBEE_NODE_STATUS_OFFLINE
This state corresponds to when the node has not been reachable by the protocol controller for a long ...
Definition: zigpc_common_zigbee.h:430
@ ZIGBEE_NODE_STATUS_INTERVIEWING
This state corresponds to when the node is in the process of being interviewed by the protocol contro...
Definition: zigpc_common_zigbee.h:423
@ ZCL_ATTR_TYPE_UINT16
Definition: zigpc_common_zigbee.h:330
@ ZCL_ATTR_TYPE_BOOL
Definition: zigpc_common_zigbee.h:327
@ ZCL_ATTR_TYPE_FLOAT
Definition: zigpc_common_zigbee.h:333
@ ZCL_ATTR_TYPE_INT16
Definition: zigpc_common_zigbee.h:331
@ ZCL_ATTR_TYPE_ENUM8
Definition: zigpc_common_zigbee.h:332
@ ZCL_ATTR_TYPE_INVALID
Definition: zigpc_common_zigbee.h:326
@ ZCL_ATTR_TYPE_MAP8
Definition: zigpc_common_zigbee.h:328
@ ZCL_ATTR_TYPE_UINT8
Definition: zigpc_common_zigbee.h:329
@ ZCL_DATA_TYPE_INT8
Definition: zigpc_common_zigbee.h:285
@ ZCL_DATA_TYPE_INT32
Definition: zigpc_common_zigbee.h:287
@ ZCL_DATA_TYPE_UINT8
Definition: zigpc_common_zigbee.h:282
@ ZCL_DATA_TYPE_UNKNOWN
Definition: zigpc_common_zigbee.h:279
@ ZCL_DATA_TYPE_INT16
Definition: zigpc_common_zigbee.h:286
@ ZCL_DATA_TYPE_ENUM16
Definition: zigpc_common_zigbee.h:289
@ ZCL_DATA_TYPE_ENUM8
Definition: zigpc_common_zigbee.h:288
@ ZCL_DATA_TYPE_MAX_VAL
Definition: zigpc_common_zigbee.h:290
@ ZCL_DATA_TYPE_MAP8
Definition: zigpc_common_zigbee.h:281
@ ZCL_DATA_TYPE_UINT32
Definition: zigpc_common_zigbee.h:284
@ ZCL_DATA_TYPE_UINT16
Definition: zigpc_common_zigbee.h:283
@ ZCL_DATA_TYPE_BOOL
Definition: zigpc_common_zigbee.h:280
@ ZCL_CLUSTER_GENERATED_COMMAND
Definition: zigpc_common_zigbee.h:268
@ ZCL_CLUSTER_RECEIVED_COMMAND
Definition: zigpc_common_zigbee.h:269
@ ZCL_OP_STATUS_SUCCESS
Definition: zigpc_common_zigbee.h:275
@ ZCL_CLUSTER_SERVER_SIDE
Definition: zigpc_common_zigbee.h:321
@ ZCL_CLUSTER_CLIENT_SIDE
Definition: zigpc_common_zigbee.h:322
@ ZDO_TABLE_FULL
Definition: zigpc_common_zigbee.h:444
@ ZDO_DEVICE_BIND_TABLE_FULL
Definition: zigpc_common_zigbee.h:445
@ ZDO_SUCCESS
Definition: zigpc_common_zigbee.h:443
SL Status Codes.
Definition: zigpc_common_zigbee.h:339
bool is_reportable
Definition: zigpc_common_zigbee.h:343
char reported_payload[ZCL_DEFAULT_STR_LENGTH]
Definition: zigpc_common_zigbee.h:346
enum e_zcl_attribute_type type
Definition: zigpc_common_zigbee.h:342
zcl_attribute_id_t attribute_id
Definition: zigpc_common_zigbee.h:341
char desired_payload[ZCL_DEFAULT_STR_LENGTH]
Definition: zigpc_common_zigbee.h:345
char attribute_name[ZCL_DEFAULT_STR_LENGTH]
Definition: zigpc_common_zigbee.h:344
zcl_cluster_id_t cluster_id
Definition: zigpc_common_zigbee.h:340
Definition: zigpc_common_zigbee.h:353
zcl_cluster_id_t cluster_id
Definition: zigpc_common_zigbee.h:354
enum e_zcl_cluster_side role
Definition: zigpc_common_zigbee.h:355
Definition: zigpc_common_zigbee.h:302
zcl_command_id_t command_id
Definition: zigpc_common_zigbee.h:304
size_t field_count
Definition: zigpc_common_zigbee.h:305
uint16_t cluster_id
Definition: zigpc_common_zigbee.h:303
Definition: zigpc_common_zigbee.h:293
size_t offset_sequence_id
Definition: zigpc_common_zigbee.h:295
size_t size
Definition: zigpc_common_zigbee.h:294
Definition: zigpc_common_zigbee.h:370
unsigned int num_attributes
Definition: zigpc_common_zigbee.h:375
const zcl_attribute_t * attribute_list
Definition: zigpc_common_zigbee.h:374
char cluster_name[ZCL_DEFAULT_STR_LENGTH]
Definition: zigpc_common_zigbee.h:371
zcl_cluster_id_t cluster_id
Definition: zigpc_common_zigbee.h:372
Definition: zigpc_common_zigbee.h:380
zcl_cluster_id_t source_cluster
Definition: zigpc_common_zigbee.h:383
zigbee_eui64_uint_t dest_address
Definition: zigpc_common_zigbee.h:384
zigbee_endpoint_id_t dest_endpoint
Definition: zigpc_common_zigbee.h:385
zigbee_endpoint_id_t source_endpoint
Definition: zigpc_common_zigbee.h:382
zigbee_eui64_uint_t source_address
Definition: zigpc_common_zigbee.h:381
a model for a zigbee ZCL endpoint
Definition: zigpc_common_zigbee.h:362
unsigned int client_cluster_count
Definition: zigpc_common_zigbee.h:367
unsigned int cluster_count
Definition: zigpc_common_zigbee.h:365
zigbee_endpoint_id_t endpoint_id
Definition: zigpc_common_zigbee.h:363
A model for a Zigbee End Node.
Definition: zigpc_common_zigbee.h:453
bool is_sleepy
Definition: zigpc_common_zigbee.h:458
bool is_active
Definition: zigpc_common_zigbee.h:457
unsigned int endpoint_count
Definition: zigpc_common_zigbee.h:456
enum zigbee_node_network_status network_status
Definition: zigpc_common_zigbee.h:459
zigbee_eui64_t eui64
Definition: zigpc_common_zigbee.h:454