Digi XBee(R) ANSI C Host Library
zcl.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009-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 
34 #ifndef __ZIGBEE_ZCL_H
35 #define __ZIGBEE_ZCL_H
36 
37 #include "xbee/platform.h" // platform-specific data types
38 #include "wpan/aps.h"
39 #include "zigbee/zcl_types.h"
40 
42 
46 #define ZCL_CLUST_BASIC 0x0000
47 #define ZCL_CLUST_POWER_CONFIG 0x0001
48 #define ZCL_CLUST_DEVICE_TEMP_CONFIG 0x0002
49 #define ZCL_CLUST_IDENTIFY 0x0003
50 #define ZCL_CLUST_GROUPS 0x0004
51 #define ZCL_CLUST_SCENES 0x0005
52 #define ZCL_CLUST_ONOFF 0x0006
53 #define ZCL_CLUST_ONOFF_SWITCH_CONFIG 0x0007
54 #define ZCL_CLUST_LEVEL_CONTROL 0x0008
55 #define ZCL_CLUST_ALARMS 0x0009
56 #define ZCL_CLUST_TIME 0x000a
57 #define ZCL_CLUST_RSSI_LOCATION 0x000b
58 #define ZCL_CLUST_ANALOG_IN 0x000c
59 #define ZCL_CLUST_ANALOG_OUT 0x000d
60 #define ZCL_CLUST_ANALOG_VALUE 0x000e
61 #define ZCL_CLUST_BINARY_IN 0x000f
62 #define ZCL_CLUST_BINARY_OUT 0x0010
63 #define ZCL_CLUST_BINARY_VALUE 0x0011
64 #define ZCL_CLUST_MULTI_IN 0x0012
65 #define ZCL_CLUST_MULTI_OUT 0x0013
66 #define ZCL_CLUST_MULTI_VALUE 0x0014
67 #define ZCL_CLUST_COMMISSIONING 0x0015
68 
73 #define ZCL_CLUST_SHADE_CONFIG 0x0100
74 
79 #define ZCL_CLUST_PUMP_CONFIG 0x0200
80 #define ZCL_CLUST_THERMOSTAT 0x0201
81 #define ZCL_CLUST_FAN_CONTROL 0x0202
82 #define ZCL_CLUST_DEHUMIDIFY_CONTROL 0x0203
83 #define ZCL_CLUST_THERMOSTAT_UI_CONFIG 0x0204
84 
89 #define ZCL_CLUST_COLOR_CONTROL 0x0300
90 #define ZCL_CLUST_BALLAST_CONFIG 0x0301
91 
96 #define ZCL_CLUST_ILLUM_MEASURE 0x0400
97 #define ZCL_CLUST_ILLUM_LEVEL_SENSING 0x0401
98 #define ZCL_CLUST_TEMP_MEASURE 0x0402
99 #define ZCL_CLUST_PRESSURE_MEASURE 0x0403
100 #define ZCL_CLUST_FLOW_MEASURE 0x0404
101 #define ZCL_CLUST_HUMIDITY_MEASURE 0x0405
102 #define ZCL_CLUST_OCCUPANCY_SENSING 0x0406
103 
108 #define ZCL_CLUST_IAS_ZONE 0x0500
109 #define ZCL_CLUST_IAS_ACE 0x0501
110 #define ZCL_CLUST_IAS_WD 0x0502
111 
116 #define ZCL_CLUST_GENERIC_TUNNEL 0x0600
117 #define ZCL_CLUST_BACNET_TUNNEL 0x0601
118 #define ZCL_CLUST_BACNET_REG_ANALOG_IN 0x0602
119 #define ZCL_CLUST_BACNET_EXT_ANALOG_IN 0x0603
120 #define ZCL_CLUST_BACNET_REG_ANALOG_OUT 0x0604
121 #define ZCL_CLUST_BACNET_EXT_ANALOG_OUT 0x0605
122 #define ZCL_CLUST_BACNET_REG_ANALOG_VALUE 0x0606
123 #define ZCL_CLUST_BACNET_EXT_ANALOG_VALUE 0x0607
124 #define ZCL_CLUST_BACNET_REG_BINARY_IN 0x0608
125 #define ZCL_CLUST_BACNET_EXT_BINARY_IN 0x0609
126 #define ZCL_CLUST_BACNET_REG_BINARY_OUT 0x060a
127 #define ZCL_CLUST_BACNET_EXT_BINARY_OUT 0x060b
128 #define ZCL_CLUST_BACNET_REG_BINARY_VALUE 0x060c
129 #define ZCL_CLUST_BACNET_EXT_BINARY_VALUE 0x060d
130 #define ZCL_CLUST_BACNET_REG_MULTI_IN 0x060e
131 #define ZCL_CLUST_BACNET_EXT_MULTI_IN 0x060f
132 #define ZCL_CLUST_BACNET_REG_MULTI_OUT 0x0610
133 #define ZCL_CLUST_BACNET_EXT_MULTI_OUT 0x0611
134 #define ZCL_CLUST_BACNET_REG_MULTI_VALUE 0x0612
135 #define ZCL_CLUST_BACNET_EXT_MULTI_VALUE 0x0613
136 
138 
140 //
141 // General ZCL Frame Format
142 // 3 or 5-byte ZCL header followed by variable-length payload
143 //
144 
146 typedef XBEE_PACKED(zcl_header_common_t, {
147  uint8_t sequence;
148  uint8_t command;
149  uint8_t payload[1];
151 
155 typedef XBEE_PACKED(zcl_header_t, {
156  uint8_t frame_control;
157  union {
158  XBEE_PACKED(, {
159  uint16_t mfg_code_le;
160  zcl_header_common_t common;
161  }) mfg;
162  XBEE_PACKED(, {
163  zcl_header_common_t common;
164  }) std;
165  } type;
167 
171 typedef XBEE_PACKED(zcl_header_response_t, {
172  union {
173  XBEE_PACKED(, {
174  uint8_t frame_control;
175  uint16_t mfg_code_le;
176  }) mfg;
177  XBEE_PACKED(, {
178  uint16_t dummy;
179  uint8_t frame_control;
180  }) std;
181  } u;
182  uint8_t sequence;
183  uint8_t command;
185 
188 typedef XBEE_PACKED(zcl_header_withmfg_t, {
189  uint8_t frame_control;
190  uint16_t mfg_code_le;
191  uint8_t sequence;
192  uint8_t command;
194 
197 typedef XBEE_PACKED(zcl_header_nomfg_t, {
198  uint8_t frame_control;
199  uint8_t sequence;
200  uint8_t command;
202 
208 #define ZCL_FRAME_TYPE_MASK 0x03
209 #define ZCL_FRAME_TYPE_PROFILE 0x00
211 #define ZCL_FRAME_TYPE_CLUSTER 0x01
213 #define ZCL_FRAME_TYPE_RESERVED1 0x02
215 #define ZCL_FRAME_TYPE_RESERVED2 0x03
216 
217 #define ZCL_FRAME_GENERAL 0x00
218 #define ZCL_FRAME_MFG_SPECIFIC 0x04
220 
222 #define ZCL_FRAME_DIRECTION 0x08
223 #define ZCL_FRAME_CLIENT_TO_SERVER 0
225 #define ZCL_FRAME_SERVER_TO_CLIENT ZCL_FRAME_DIRECTION
227 
229 #define ZCL_FRAME_DISABLE_DEF_RESP 0x10
230 #define ZCL_FRAME_RESERVED_BITS 0xE0
232 
254 #define ZCL_CMD_MATCH(p, mfg, dir, type) \
255  ((*(const uint8_t FAR *)(p) & \
256  (ZCL_FRAME_MFG_SPECIFIC | ZCL_FRAME_DIRECTION | ZCL_FRAME_TYPE_MASK)) == \
257  (ZCL_FRAME_ ## mfg | ZCL_FRAME_ ## dir | ZCL_FRAME_TYPE_ ## type))
258 
272 #define ZCL_CMD_IS_PROFILE(p) \
273  (ZCL_FRAME_TYPE_PROFILE == (*(const uint8_t FAR *)(p) & ZCL_FRAME_TYPE_MASK))
274 
286 #define ZCL_CMD_IS_MFG_CLUSTER(p) \
287  ((ZCL_FRAME_TYPE_CLUSTER | ZCL_FRAME_MFG_SPECIFIC) == \
288  ((const uint8_t FAR *)(p) & (ZCL_FRAME_TYPE_MASK | ZCL_FRAME_MFG_SPECIFIC)))
289 
301 #define ZCL_CMD_IS_CLUSTER(p) (ZCL_FRAME_TYPE_CLUSTER == \
302  (*(const uint8_t FAR *)(p) & (ZCL_FRAME_TYPE_MASK | ZCL_FRAME_MFG_SPECIFIC)))
303 
309 #define ZCL_STATUS_SUCCESS 0x00
310 #define ZCL_STATUS_FAILURE 0x01
311 #define ZCL_STATUS_NOT_AUTHORIZED 0x7e
312 #define ZCL_STATUS_RESERVED_FIELD_NOT_ZERO 0x7f
313 #define ZCL_STATUS_MALFORMED_COMMAND 0x80
314 #define ZCL_STATUS_UNSUP_CLUSTER_COMMAND 0x81
315 #define ZCL_STATUS_UNSUP_GENERAL_COMMAND 0x82
316 #define ZCL_STATUS_UNSUP_MANUF_CLUSTER_COMMAND 0x83
317 #define ZCL_STATUS_UNSUP_MANUF_GENERAL_COMMAND 0x84
318 #define ZCL_STATUS_INVALID_FIELD 0x85
319 #define ZCL_STATUS_UNSUPPORTED_ATTRIBUTE 0x86
320 #define ZCL_STATUS_INVALID_VALUE 0x87
321 #define ZCL_STATUS_READ_ONLY 0x88
322 #define ZCL_STATUS_INSUFFICIENT_SPACE 0x89
323 #define ZCL_STATUS_DUPLICATE_EXISTS 0x8a
324 #define ZCL_STATUS_NOT_FOUND 0x8b
325 #define ZCL_STATUS_UNREPORTABLE_ATTRIBUTE 0x8c
326 #define ZCL_STATUS_INVALID_DATA_TYPE 0x8d
327 #define ZCL_STATUS_INVALID_SELECTOR 0x8e
328 #define ZCL_STATUS_WRITE_ONLY 0x8f
329 #define ZCL_STATUS_INCONSISTENT_STARTUP_STATE 0x90
330 #define ZCL_STATUS_DEFINED_OUT_OF_BAND 0x91
331 #define ZCL_STATUS_ABORT 0x95
332 #define ZCL_STATUS_INVALID_IMAGE 0x96
333 #define ZCL_STATUS_WAIT_FOR_DATA 0x97
334 #define ZCL_STATUS_NO_IMAGE_AVAILABLE 0x98
335 #define ZCL_STATUS_REQUIRE_MORE_IMAGE 0x99
336 #define ZCL_STATUS_HARDWARE_FAILURE 0xc0
337 #define ZCL_STATUS_SOFTWARE_FAILURE 0xc1
338 #define ZCL_STATUS_CALIBRATION_ERROR 0xc2
339 
341 const char *zcl_status_text( uint_fast8_t status);
342 
351 #define ZCL_CMD_READ_ATTRIB 0x00
353 
356 #define ZCL_CMD_READ_ATTRIB_RESP 0x01
357 
360 #define ZCL_CMD_WRITE_ATTRIB 0x02
361 
365 #define ZCL_CMD_WRITE_ATTRIB_UNDIV 0x03
366 
371 #define ZCL_CMD_WRITE_ATTRIB_RESP 0x04
372 
376 #define ZCL_CMD_WRITE_ATTRIB_NORESP 0x05
377 
378 #define ZCL_CMD_CONFIGURE_REPORT 0x06
379 
380 #define ZCL_CMD_CONFIGURE_REPORT_RESP 0x07
381 
382 #define ZCL_CMD_READ_REPORT_CFG 0x08
383 
384 #define ZCL_CMD_READ_REPORT_CFG_RESP 0x09
385 
386 #define ZCL_CMD_REPORT_ATTRIB 0x0a
387 
390 #define ZCL_CMD_DEFAULT_RESP 0x0b
391 
395 #define ZCL_CMD_DISCOVER_ATTRIB 0x0c
396 
401 #define ZCL_CMD_DISCOVER_ATTRIB_RESP 0x0d
402 
403 #define ZCL_CMD_READ_STRUCT_ATTRIB 0x0e
404 
405 #define ZCL_CMD_WRITE_STRUCT_ATTRIB 0x0f
406 
407 #define ZCL_CMD_WRITE_STRUCT_ATTRIB_RESP 0x10
408 
410 
413 typedef XBEE_PACKED(zcl_attrib_t, {
414  uint16_t id_le;
415  uint8_t type;
416  uint8_t value[1];
418 
420 typedef XBEE_PACKED(zcl_rec_read_attrib_resp_t, {
421  uint16_t id_le;
422  uint8_t status;
423  uint8_t type;
424  uint8_t value[1];
426 
427 typedef XBEE_PACKED(zcl_rec_read_attrib_error_resp_t, {
428  uint16_t id_le;
429  uint8_t status;
431 
432 typedef XBEE_PACKED(zcl_rec_read_attrib_array_resp_t, {
433  uint16_t id_le;
434  uint8_t status;
435  uint8_t type;
436  uint8_t element_type;
437  uint16_t count_le;
438  uint8_t value[1];
440 
441 typedef XBEE_PACKED(zcl_rec_read_attrib_struct_resp_t, {
442  uint16_t id_le;
443  uint8_t status;
444  uint8_t type;
445  uint16_t count_le;
446  uint8_t elements[1];
448 
450 typedef XBEE_PACKED(zcl_rec_write_attrib_status_t, {
451  uint8_t status;
452  uint16_t id_le;
454 
455 
456 // Configure Reporting Command (ZCL_CMD_CONFIGURE_REPORT)
457 // payload is 1 to n variable-length Attribute Reporting Configuration records
458 // There are two different packet types, based on whether direction is SEND
459 // or RECEIVE.
460 #define ZCL_DIRECTION_SEND 0x00 // attributes sent (or reported)
461 #define ZCL_DIRECTION_RECEIVE 0x01 // attributes received
462 typedef XBEE_PACKED(zcl_rec_report_send_t, {
463  uint8_t direction; // 0x00 (ZCL_DIRECTION_SEND)
464  uint16_t attrib_id_le;
465  uint8_t attrib_type;
466  uint16_t min_interval_le; // minimum reporting interval (in seconds)
467  uint16_t max_interval_le; // maximum reporting interval (in seconds)
468  // Note: If max_interval is 0xffff, device shall not issue reports
469  // for the specified attribute.
471 
472 typedef XBEE_PACKED(zcl_rec_report_receive_t, {
473  uint8_t direction; // 0x01 (ZCL_DIRECTION_RECEIVE)
474  uint16_t attrib_id_le;
475  uint16_t timeout_period_le; // number of seconds, or 0 for no timeout
477 
478 typedef union zcl_rec_report_t {
479  XBEE_PACKED(, {
480  uint8_t direction; // ZCL_DIRECTION_SEND or ZCL_DIRECTION_RECEIVE
481  uint16_t attrib_id_le;
482  }) common;
484  zcl_rec_report_receive_t receive;
486 
487 // Configure Reporting Response Command (ZCL_CMD_WRITE_REPORT_CFG_RESP)
488 // payload is two bytes (ZCL_STATUS_SUCCESS followed by a direction) if all
489 // writes were successful or 1 to n 4-byte Attribute Status Records for each
490 // write that failed
491 // Note: this structure is identical to the one for Read Reporting Configuration
492 // Command (ZCL_CMD_READ_REPORT_CFG), with the addition of a 1-byte status.
493 typedef XBEE_PACKED(zcl_rec_reporting_status_t, {
494  uint8_t status;
495  uint8_t direction; // ZCL_DIRECTION_SEND or ZCL_DIRECTION_RECEIVE
496  uint16_t attrib_id_le;
498 
499 // Read Reporting Configuration Command (ZCL_CMD_READ_REPORT_CFG)
500 // payload is 1 to n 3-byte Attribute Records
501 typedef XBEE_PACKED(zcl_rec_read_report_cfg_t, {
502  uint8_t direction; // ZCL_DIRECTION_SEND or ZCL_DIRECTION_RECEIVE
503  uint16_t attrib_id_le;
505 
506 // Read Reporting Configuration Response Command (ZCL_CMD_READ_REPORT_CFG_RESP)
507 // payload is 1 to n variable-length records as follows:
508 // - for non-success status, the 4-byte record format used by Configure
509 // Reporting Response Command (status, direction, attrib_id).
510 // - for success status, a status byte followed by a zcl_rec_report_send_t
511 // record (if direction is ZCL_DIRECTION_SEND) or a zcl_rec_report_receive_t
512 // record (if direction is ZCL_DIRECTION_RECEIVE)
513 /* combined typedef?
514 typedef XBEE_PACKED(zcl_rec_report_resp_t, {
515  uint8_t status;
516  union {
517  struct {
518  uint8_t direction;
519  uint16_t attrib_id_le;
520  } error; // .status != ZCL_STATUS_SUCCESS
521  zcl_rec_report_send_t send_cfg;
522  zcl_rec_report_receive_t receive_cfg;
523  } u;
524 }) zcl_rec_report_resp_t;
525 */
526 
527 typedef XBEE_PACKED(zcl_rec_report_error_resp_t, {
528  uint8_t status; // Set to anything except ZCL_STATUS_SUCCESS (0x00)
529  uint8_t direction;
530  uint16_t attrib_id_le;
532 typedef XBEE_PACKED(zcl_rec_report_send_resp_t, {
533  uint8_t status; // Set to ZCL_STATUS_SUCCESS (0x00)
534  zcl_rec_report_send_t report_cfg;
535  // report_cfg.direction set to 0x00 (ZCL_DIRECTION_SEND)
537 typedef XBEE_PACKED(zcl_rec_report_receive_resp_t, {
538  uint8_t status; // Set to ZCL_STATUS_SUCCESS (0x00)
539  zcl_rec_report_receive_t report_cfg;
540  // report_cfg.direction set to 0x01 (ZCL_DIRECTION_RECEIVE)
542 
543 
544 /*
545  Logic for handling a Read Reporting Configuration Response Command frame:
546 
547  char *buffer;
548  zcl_rec_report_error_resp_t *resp_error;
549  zcl_rec_report_send_resp_t *resp_send;
550  zcl_rec_report_receive_resp_t *resp_receive;
551 
552  resp_error = (zcl_rec_report_error_resp_t *) buffer;
553  if (resp_error->status != ZCL_STATUS_SUCCESS) {
554  // process error in resp_error
555  buffer += sizeof (*resp_error);
556  } else if (resp_error->direction == ZCL_DIRECTION_SEND) {
557  resp_send = (zcl_rec_report_send_resp_t *) buffer;
558  // process record in resp_send
559  buffer += sizeof (*resp_send);
560  } else if (resp_error->direction == ZCL_DIRECTION_RECEIVE) {
561  resp_send = (zcl_rec_report_receive_resp_t *) buffer;
562  // process record in resp_receive
563  buffer += sizeof (*resp_receive);
564  } else {
565  // bad packet
566  }
567 */
568 
569 // Report Attributes Command (ZCL_CMD_REPORT_ATTRIB)
570 // payload is 1 to n variable-length Attribute Report Records
571 
572 // use zcl_attrib_t
573 
575 typedef XBEE_PACKED(zcl_default_response_t, {
576  uint8_t command;
577  uint8_t status;
579 
581 typedef XBEE_PACKED(zcl_discover_attrib_t, {
582  uint16_t start_attrib_id_le;
583  uint8_t max_return_count;
585 
587 typedef XBEE_PACKED(zcl_rec_attrib_report_t, {
588  uint16_t id_le;
589  uint8_t type;
592 typedef XBEE_PACKED(zcl_discover_attrib_resp_t, {
595  uint8_t discovery_complete;
596  zcl_rec_attrib_report_t attrib[1];
598 
599 // Read Attributes Structured Command (ZCL_CMD_READ_STRUCT_ATTRIB)
600 // payload is 1 to n variable-byte Attribute ID and Selector fields
601 typedef XBEE_PACKED(zcl_selector_t, {
602  uint8_t indicator;
603  #define ZCL_INDICATOR_INDICES_MASK 0x0F
604 
605  #define ZCL_INDICATOR_ACTION_MASK 0xF0
606  #define ZCL_INDICATOR_REPLACE 0x00
607  #define ZCL_INDICATOR_ADD_ELEMENT 0x10
608  #define ZCL_INDICATOR_REMOVE_ELEMENT 0x20
609  // indicator actions 0x30 to 0xF0 are reserved
610  uint16_t index_le[15];
612 typedef XBEE_PACKED(zcl_read_struct_attrib_t, {
613  uint16_t attrib_id_le;
614  zcl_selector_t selector;
616 
617 
618 // Write Attributes Structured Command (ZCL_CMD_WRITE_STRUCT_ATTRIB)
619 // payload is 1 to n variable-length Write Structured Attribute Record fields.
620 typedef XBEE_PACKED(zcl_rec_write_struct_attrib_t, {
621  uint16_t id_le;
622  zcl_selector_t selector;
623  uint8_t type;
624  uint8_t value[1]; // variable length, depending on type
626 
627 // Write Attributes Structured Response Cmd (ZCL_CMD_WRITE_STRUCT_ATTRIB_RESP)
628 // payload is 1 to n variable-length Write Structure Attribute Status Record
629 // fields.
631  uint8_t status;
632  uint16_t id;
633  zcl_selector_t selector;
635 
636 
637 
638 
639 /*
640  Some thoughts on these structures...
641 
642  One problem with the attrib status records is that for unknown data types,
643  you don't know how long the record is. Parsing a ZCL_CMD_READ_ATTRIB_RESP
644  will be difficult if an attribute has an unknown type (on the plus side,
645  a device should only be requesting attributes with types it already
646  understands).
647 
648 */
649 
650 typedef union zcl_attribute_minmax_t {
651  int32_t _signed;
652  uint32_t _unsigned;
653  float _float;
655 
656 struct zcl_attribute_base_t;
657 struct zcl_attribute_full_t;
680 typedef uint_fast8_t (*zcl_attribute_update_fn)(
681  const struct zcl_attribute_full_t FAR *entry);
682 
684 {
687 
690 
693  #define ZCL_ATTR_WRITE_FLAG_NONE 0x00
694  #define ZCL_ATTR_WRITE_FLAG_ASSIGN 0x01
697 
699  #define ZCL_ATTR_WRITE_FLAG_WRITE_REQ 0x00
700  #define ZCL_ATTR_WRITE_FLAG_READ_RESP 0x02
702 
707 
724 typedef int (*zcl_attribute_write_fn)(
725  const struct zcl_attribute_full_t FAR *entry,
727 
735 typedef struct zcl_attribute_base_t
736 {
737  uint16_t id;
738  uint8_t flags;
743  #define ZCL_ATTRIB_FLAG_NONE 0x00
744  #define ZCL_ATTRIB_FLAG_WRITEONLY 0x01
745  #define ZCL_ATTRIB_FLAG_READONLY 0x02
746  #define ZCL_ATTRIB_FLAG_HAS_MIN 0x04
747  #define ZCL_ATTRIB_FLAG_HAS_MAX 0x08
748  #define ZCL_ATTRIB_FLAG_REPORTABLE 0x10
749 
750  // flags available for future use
751  #define ZCL_ATTRIB_FLAG_UNUSED1 0x20
752 
753  #define ZCL_ATTRIB_FLAG_RAW 0x40
757 
759  #define ZCL_ATTRIB_FLAG_FULL 0x80
760 
765 
770  const void FAR *value;
771 
773 
779 typedef struct zcl_attribute_full_t
780 {
782 
786 
790 
795 
802 
809 // DEVNOTE: This isn't an extension of zcl_attribute_base_t (like
810 // zcl_attribute_full_t) because its size can change and therefore can't be
811 // stored in flash. It's also necessary to be separate to support arrays of
812 // arrays.
813 typedef struct zcl_array_t
814 {
819  const void FAR *value;
820 } zcl_array_t;
821 
826 typedef struct zcl_struct_element_t
827 {
831 
836 typedef struct zcl_struct_t
837 {
841  const void FAR *base_address;
844 } zcl_struct_t;
845 
846 // DEVNOTE: consider a flag in zcl_struct_element_t and zcl_array_t to
847 // indicate that underlying value should have ZCL_ATTRIB_FLAG_RAW, or to
848 // provide a maximum length if the element is a writeable string.
849 
851 #define ZCL_ATTRIBUTE_END_OF_LIST 0xFFFF
852 
853 #define ZCL_MFG_NONE 0x0000
854 typedef struct zcl_attribute_tree_t
855 {
858 
861 
865 
871 
876 typedef struct zcl_command_t {
894  const void FAR *zcl_payload;
897 } zcl_command_t;
898 
900  const wpan_envelope_t FAR *envelope, zcl_attribute_tree_t FAR *tree);
901 
902 void zcl_command_dump( const zcl_command_t *cmd);
903 void zcl_envelope_payload_dump( const wpan_envelope_t *envelope);
904 
905 int zcl_general_command( const wpan_envelope_t FAR *envelope,
906  void FAR *context);
907 
908 int zcl_invalid_cluster( const wpan_envelope_t FAR *envelope,
909  wpan_ep_state_t FAR *ep_state);
910 int zcl_invalid_command( const wpan_envelope_t FAR *envelope);
911 
915 int zcl_default_response( zcl_command_t *cmd, uint8_t status);
916 
917 int zcl_check_minmax( const zcl_attribute_base_t FAR *entry,
918  const uint8_t FAR *buffer_le);
919 
920 uint32_t zcl_convert_24bit( const void FAR *value_le, bool_t extend_sign);
921 
924 int zcl_encode_attribute_value( uint8_t FAR *buffer, int16_t bufsize,
925  const zcl_attribute_base_t FAR *entry);
926 
928  const zcl_attribute_base_t FAR *entry);
930  const zcl_attribute_base_t FAR *entry, uint16_t search_id);
931 int zcl_send_response( zcl_command_t *cmd, const void FAR *payload,
932  uint16_t length);
933 
935 
936 // If compiling in Dynamic C, automatically #use the appropriate C file.
937 #ifdef __DC__
938  #use "zigbee_zcl.c"
939 #endif
940 
941 #endif // __ZIGBEE_ZCL_H
942 
const zcl_attribute_base_t FAR * zcl_attribute_get_next(const zcl_attribute_base_t FAR *entry)
Return a pointer to the next attribute entry from an attribute table.
Definition: zigbee_zcl.c:118
unsigned long uint32_t
32-bit unsigned integer
Definition: platform_config.h:43
uint8_t type
type of data stored in array
Definition: zcl.h:818
Definition: zcl.h:612
int zcl_check_minmax(const zcl_attribute_base_t FAR *entry, const uint8_t FAR *buffer_le)
Checks whether a new value from a Write Attributes command is within the limits specified for a given...
Definition: zigbee_zcl.c:326
uint32_t zcl_convert_24bit(const void FAR *value_le, bool_t extend_sign)
Convert a 24-bit (3-byte) little-endian value to a 32-bit value in host byte order.
Definition: zigbee_zcl.c:613
void zcl_envelope_payload_dump(const wpan_envelope_t *envelope)
Debugging routine that parses an envelope payload as a ZCL command and dumps a parsed copy to STDOUT...
Definition: zigbee_zcl.c:1660
#define FAR
On platforms with "far" pointers, define to the proper keyword; empty definition if not required...
Definition: platform.h:396
int zcl_default_response(zcl_command_t *cmd, uint8_t status)
Send a Default Response (ZCL_CMD_DEFAULT_RESP) to a given command.
Definition: zigbee_zcl.c:248
zcl_attribute_minmax_t max
Maximum value for attribute, assumes 32-bit limit.
Definition: zcl.h:789
uint8_t status
Set to #ZCL_STATUS_SUCCESS if data is valid, or some other ZCL_STATUS_* macro if there's an error...
Definition: zcl.h:705
#define XBEE_BEGIN_DECLS
Macro defined to.
Definition: platform.h:41
Common header for Hardware Abstraction Layer.
const zcl_struct_element_t FAR * element
elements in the structure
Definition: zcl.h:843
uint16_t offset
offset into structure
Definition: zcl.h:829
uint16_t manufacturer_id
ID for manufacturer-specific attributes or ZCL_MFG_NONE if general.
Definition: zcl.h:857
uint_fast8_t(* zcl_attribute_update_fn)(const struct zcl_attribute_full_t FAR *entry)
Function pointer assigned to a ZCL attribute record, called to update the value of the given attribut...
Definition: zcl.h:680
int zcl_command_build(zcl_command_t *cmd, const wpan_envelope_t FAR *envelope, zcl_attribute_tree_t FAR *tree)
Parse a ZCL request and store in a zcl_command_t structure with fields in fixed locations (therefore ...
Definition: zigbee_zcl.c:1473
Definition: zcl.h:497
uint16_t current_count
current number of elements
Definition: zcl.h:816
Definition: zcl.h:476
ZLC header structure used when building a manufacturer-specific response frame.
Definition: zcl.h:188
Definition: zcl.h:683
Structure populated by zcl_command_build() with the ZCL header from a received ZCL command frame...
Definition: zcl.h:876
int zcl_decode_attribute(const zcl_attribute_base_t FAR *entry, zcl_attribute_write_rec_t *rec)
Decode attribute value from a Write Attribute Request or Read Attribute Response record and optionall...
Definition: zigbee_zcl.c:652
const void FAR * base_address
base address of structure
Definition: zcl.h:841
Volatile part of an endpoint record used to track conversations (requests waiting for responses)...
Definition: aps.h:529
const zcl_attribute_base_t FAR * client
List of attributes for the CLIENT cluster (or NULL if none).
Definition: zcl.h:863
Used for ZCL_CMD_DISCOVER_ATTRIB.
Definition: zcl.h:581
const zcl_attribute_base_t FAR * server
List of attributes for the SERVER cluster (or NULL if none).
Definition: zcl.h:860
Definition: zcl.h:478
Definition: zcl.h:531
General format for an attribute, used for Write Attributes and Report Attributes commands.
Definition: zcl.h:417
Definition: zcl.h:536
ZLC header structure used when building a normal (non-manufacturer-specific response frame...
Definition: zcl.h:197
const zcl_attribute_base_t FAR * zcl_find_attribute(const zcl_attribute_base_t FAR *entry, uint16_t search_id)
Search the attribute table starting at entry, for attribute ID search_id.
Definition: zigbee_zcl.c:159
Definition: zcl.h:504
Basic structure for storing a list of attributes in a cluster.
Definition: zcl.h:735
uint16_t element_count
number of elements in structure
Definition: zcl.h:839
A zcl_struct_t contains an array of these elements, describing each element in the structure and its ...
Definition: zcl.h:826
const uint8_t FAR * buffer
Source data to write to attribute.
Definition: zcl.h:686
If a zcl_attribute_base_t has a type of ZCL_TYPE_ARRAY, its .value points to this structure...
Definition: zcl.h:813
int zcl_parse_attribute_record(const zcl_attribute_base_t FAR *entry, zcl_attribute_write_rec_t *rec)
Parse an attribute record from a Write Attributes Request or a Read Attributes Response and possibly ...
Definition: zigbee_zcl.c:437
Used for ZCL_CMD_DEFAULT_RESP.
Definition: zcl.h:575
int zcl_general_command(const wpan_envelope_t FAR *envelope, void FAR *context)
Handler for ZCL General Commands.
Definition: zigbee_zcl.c:1802
uint8_t zcl_type
ZCL data type of element.
Definition: zcl.h:828
unsigned short uint16_t
16-bit unsigned integer
Definition: platform_config.h:41
uint8_t type
The ZCL Attribute Type, should be one of the ZCL_TYPE_* macros defined in zigbee/zcl_types.h.
Definition: zcl.h:764
uint16_t max_count
maximum number of elements to store
Definition: zcl.h:815
Definition: zcl.h:854
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
Used for ZCL_CMD_DISCOVER_ATTRIB_RESP.
Definition: zcl.h:587
int(* zcl_attribute_write_fn)(const struct zcl_attribute_full_t FAR *entry, zcl_attribute_write_rec_t *rec)
Function pointer assigned to a ZCL attribute record, called instead of zcl_decode_attribute() to proc...
Definition: zcl.h:724
If a zcl_attribute_base_t has a type of ZCL_TYPE_STRUCT, its .value points to this structure...
Definition: zcl.h:836
Used for ZCL_CMD_READ_ATTRIB_RESP.
Definition: zcl.h:425
uint16_t mfg_code
manufacturer code from the ZCL header, in host byte order, or 0x0000 if not mfg specific ...
Definition: zcl.h:884
Common portion of ZCL header (appears after optional Manufacturer Code)
Definition: zcl.h:150
Definition: zcl.h:625
uint8_t frame_control
frame control byte from the ZCL header
Definition: zcl.h:881
Cluster/Endpoint layer for WPAN networks (ZigBee and DigiMesh).
const wpan_envelope_t FAR * envelope
envelope for the received command, envelope's payload and length include the ZCL header ...
Definition: zcl.h:879
zcl_attribute_minmax_t min
Minimum value for attribute (currently unused until I pick a value to represent "none").
Definition: zcl.h:785
< always ZCL_TYPE_STRUCT number of elements to follow mult.
Definition: zcl.h:447
Definition: zcl.h:541
const void FAR * value
Pointer to global variable of correct type, set as const to allow for both const and non-const values...
Definition: zcl.h:770
int zcl_invalid_cluster(const wpan_envelope_t FAR *envelope, wpan_ep_state_t FAR *ep_state)
Called if a request comes in for an invalid endpoint/cluster combination.
Definition: zigbee_zcl.c:1701
uint16_t element_size
number of bytes in each element
Definition: zcl.h:817
int16_t buflen
Number of bytes in buffer.
Definition: zcl.h:689
Used for ZCL_CMD_WRITE_ATTRIB_RESP.
Definition: zcl.h:450
< one of ZCL_TYPE_ARRAY, ZCL_TYPE_SET, ZCL_TYPE_BAG
Definition: zcl.h:439
Definition: zcl.h:611
Definition: zcl.h:650
short int16_t
16-bit signed integer
Definition: platform_config.h:40
Definition: zcl.h:470
zcl_attribute_write_fn write
On an attribute write, the ZCL dispatcher will call the .write function with a structure containing i...
Definition: zcl.h:800
int zcl_encode_attribute_value(uint8_t FAR *buffer, int16_t bufsize, const zcl_attribute_base_t FAR *entry)
Format a ZCL attribute&#39;s value for a Read Attributes Response or a Write Attributes Request...
Definition: zigbee_zcl.c:1086
uint8_t command
command byte from the ZCL header
Definition: zcl.h:888
const char * zcl_status_text(uint_fast8_t status)
Converts a ZCL status byte (one of the ZCL_STATUS_* macros) into a string.
Definition: zigbee_zcl.c:1901
Used for ZCL_CMD_DISCOVER_ATTRIB_RESP.
Definition: zcl.h:597
#define XBEE_END_DECLS
Macro defined to.
Definition: platform.h:42
long int32_t
32-bit signed integer
Definition: platform_config.h:42
uint8_t sequence
sequence byte from the ZCL header
Definition: zcl.h:886
ZCL header structure used for building response frames that may or may not be manufacturer-specific.
Definition: zcl.h:171
const zcl_attribute_base_t FAR * attributes
Appropriate list of attributes on this device, related to the command.
Definition: zcl.h:892
int zcl_build_header(zcl_header_response_t *rsp, zcl_command_t *cmd)
Support function to fill in a ZCL response header.
Definition: zigbee_zcl.c:199
const void FAR * zcl_payload
pointer to the ZCL payload (first byte after ZCL header)
Definition: zcl.h:894
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
General header for casting onto an incoming frame.
Definition: zcl.h:166
The "envelope" is used to gather all necessary information about a given frame on the network...
Definition: aps.h:40
int zcl_send_response(zcl_command_t *cmd, const void FAR *payload, uint16_t length)
Send a response to a ZCL command.
Definition: zigbee_zcl.c:69
int16_t length
length of the ZCL payload
Definition: zcl.h:896
Macros and structures related to the ZCL datatypes.
const zcl_attribute_tree_t FAR zcl_attributes_none[1]
If a cluster doesn&#39;t have attributes, use zcl_attributes_none (a single, empty attribute list) in the...
Definition: zigbee_zcl.c:49
zcl_attribute_update_fn read
On an attribute read, the ZCL dispatcher will call the .read function to refresh the attribute&#39;s valu...
Definition: zcl.h:794
int zcl_invalid_command(const wpan_envelope_t FAR *envelope)
Called if a request comes in for an invalid command on a valid endpoint/cluster combination.
Definition: zigbee_zcl.c:1746
uint8_t flags
Parsing flags (see ZCL_ATTR_WRITE_FLAG_* macros for valid flags).
Definition: zcl.h:692
void zcl_command_dump(const zcl_command_t *cmd)
Debugging routine that dumps contents of a parsed ZCL command structure to STDOUT.
Definition: zigbee_zcl.c:1559