Digi XBee(R) ANSI C Host Library
|
Modules | |
64-bit integer support | |
Datatypes | |
Cluster Client support code | |
Clusters | |
Files | |
file | zcl.h |
Header for implementation of ZigBee Cluster Library. | |
file | zigbee_zcl.c |
Process General Commands for ZigBee Cluster Library and provide support functions to other layers of the stack. | |
Data Structures | |
struct | zcl_header_common_t |
Common portion of ZCL header (appears after optional Manufacturer Code) More... | |
struct | zcl_header_t |
General header for casting onto an incoming frame. More... | |
struct | zcl_header_response_t |
ZCL header structure used for building response frames that may or may not be manufacturer-specific. More... | |
struct | zcl_header_withmfg_t |
ZLC header structure used when building a manufacturer-specific response frame. More... | |
struct | zcl_header_nomfg_t |
ZLC header structure used when building a normal (non-manufacturer-specific response frame. More... | |
struct | zcl_attrib_t |
General format for an attribute, used for Write Attributes and Report Attributes commands. More... | |
struct | zcl_rec_read_attrib_resp_t |
Used for ZCL_CMD_READ_ATTRIB_RESP. More... | |
struct | zcl_rec_read_attrib_error_resp_t |
struct | zcl_rec_read_attrib_array_resp_t |
< one of ZCL_TYPE_ARRAY, ZCL_TYPE_SET, ZCL_TYPE_BAG More... | |
struct | zcl_rec_read_attrib_struct_resp_t |
< always ZCL_TYPE_STRUCT number of elements to follow mult. More... | |
struct | zcl_rec_write_attrib_status_t |
Used for ZCL_CMD_WRITE_ATTRIB_RESP. More... | |
struct | zcl_rec_report_send_t |
struct | zcl_rec_report_receive_t |
union | zcl_rec_reporting_config_t |
struct | zcl_rec_reporting_status_t |
struct | zcl_rec_read_report_cfg_t |
struct | zcl_rec_report_error_resp_t |
struct | zcl_rec_report_send_resp_t |
struct | zcl_rec_report_receive_resp_t |
struct | zcl_default_response_t |
Used for ZCL_CMD_DEFAULT_RESP. More... | |
struct | zcl_discover_attrib_t |
Used for ZCL_CMD_DISCOVER_ATTRIB. More... | |
struct | zcl_rec_attrib_report_t |
Used for ZCL_CMD_DISCOVER_ATTRIB_RESP. More... | |
struct | zcl_discover_attrib_resp_t |
Used for ZCL_CMD_DISCOVER_ATTRIB_RESP. More... | |
struct | zcl_selector_t |
struct | zcl_read_struct_attrib_t |
struct | zcl_rec_write_struct_attrib_t |
struct | zcl_rec_write_struct_attrib_resp_t |
union | zcl_attribute_minmax_t |
struct | zcl_attribute_write_rec_t |
struct | zcl_attribute_base_t |
Basic structure for storing a list of attributes in a cluster. More... | |
struct | zcl_attribute_full_t |
Use this structure for attributes with min/max values or the need to have a read/write function. More... | |
struct | zcl_array_t |
If a zcl_attribute_base_t has a type of ZCL_TYPE_ARRAY, its .value points to this structure. More... | |
struct | zcl_struct_element_t |
A zcl_struct_t contains an array of these elements, describing each element in the structure and its offset from the zcl_struct_t.base_address. More... | |
struct | zcl_struct_t |
If a zcl_attribute_base_t has a type of ZCL_TYPE_STRUCT, its .value points to this structure. More... | |
struct | zcl_attribute_tree_t |
struct | zcl_command_t |
Structure populated by zcl_command_build() with the ZCL header from a received ZCL command frame. More... | |
Macros | |
#define | ZCL_CMD_MATCH(p, mfg, dir, type) |
Macro for checking the frame control field of a ZCL command. More... | |
#define | ZCL_CMD_IS_PROFILE(p) (ZCL_FRAME_TYPE_PROFILE == (*(const uint8_t FAR *)(p) & ZCL_FRAME_TYPE_MASK)) |
Identify profile commands (as opposed to cluster commands) using the frame control field of a ZCL command. More... | |
#define | ZCL_CMD_IS_MFG_CLUSTER(p) |
Identify manufacturer-specific cluster commands using the frame control field of a ZCL command. More... | |
#define | ZCL_CMD_IS_CLUSTER(p) |
Identify cluster commands that are not manufacturer-specific, using the frame control field of a ZCL command. More... | |
#define | ZCL_DIRECTION_SEND 0x00 |
#define | ZCL_DIRECTION_RECEIVE 0x01 |
#define | ZCL_ATTRIBUTE_END_OF_LIST 0xFFFF |
Attribute ID for end of list marker. | |
#define | ZCL_MFG_NONE 0x0000 |
#define | zigbee_zcl_debug |
#define | ZCL_DISCOVER_ATTRIB_MAX 20 |
Typedefs | |
typedef 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 attribute. More... | |
typedef 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 process a Write Request for the attribute. More... | |
Functions | |
const char * | zcl_status_text (uint_fast8_t status) |
Converts a ZCL status byte (one of the ZCL_STATUS_* macros) into a string. More... | |
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 easier to use than the variable-length frame header). More... | |
void | zcl_command_dump (const zcl_command_t *cmd) |
Debugging routine that dumps contents of a parsed ZCL command structure to STDOUT. More... | |
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. More... | |
int | zcl_general_command (const wpan_envelope_t FAR *envelope, void FAR *context) |
Handler for ZCL General Commands. More... | |
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. More... | |
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. More... | |
int | zcl_build_header (zcl_header_response_t *rsp, zcl_command_t *cmd) |
Support function to fill in a ZCL response header. More... | |
int | zcl_parse_attribute_record (const zcl_attribute_base_t FAR *entry, zcl_attribute_write_rec_t *write_rec) |
Parse an attribute record from a Write Attributes Request or a Read Attributes Response and possibly store the new attribute value. More... | |
int | zcl_default_response (zcl_command_t *request, uint8_t status) |
Send a Default Response (ZCL_CMD_DEFAULT_RESP) to a given command. More... | |
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 attribute. More... | |
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. More... | |
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 optionally write to entry . More... | |
int | zcl_encode_attribute_value (uint8_t FAR *buffer, int16_t bufsize, const zcl_attribute_base_t FAR *entry) |
Format a ZCL attribute's value for a Read Attributes Response or a Write Attributes Request. More... | |
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. More... | |
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 . More... | |
int | zcl_send_response (zcl_command_t *request, const void FAR *response, uint16_t length) |
Send a response to a ZCL command. More... | |
int | _zcl_write_attributes (zcl_command_t *cmd) |
Process the three types of Write Attributes requests. More... | |
int | _zcl_encode_struct_value (uint8_t FAR *buffer, int16_t bufsize, const zcl_struct_t FAR *zcl_struct) |
Format a ZCL struct for a Read Attributes Response or a Write Attributes Request. More... | |
int | _zcl_encode_array_value (uint8_t FAR *buffer, int16_t bufsize, const zcl_array_t FAR *array) |
Format a ZCL array for a Read Attributes Response or a Write Attributes Request. More... | |
int | _zcl_read_attributes (zcl_command_t *cmd) |
Process the Read Attributes Command (ZCL_CMD_READ_ATTRIB). More... | |
int | _zcl_discover_attributes (zcl_command_t *cmd) |
Process the Discover Attributes Command (ZCL_CMD_DISCOVER_ATTRIB). More... | |
Variables | |
const zcl_attribute_tree_t FAR | zcl_attributes_none [1] |
If a cluster doesn't have attributes, use zcl_attributes_none (a single, empty attribute list) in the cluster definition. More... | |
const zcl_attribute_tree_t FAR | zcl_attributes_none [1] |
If a cluster doesn't have attributes, use zcl_attributes_none (a single, empty attribute list) in the cluster definition. More... | |
0x0100-0x01ff Closure Clusters | |
#define | ZCL_CLUST_SHADE_CONFIG 0x0100 |
0x0300-0x03ff Lighting Clusters | |
#define | ZCL_CLUST_COLOR_CONTROL 0x0300 |
#define | ZCL_CLUST_BALLAST_CONFIG 0x0301 |
0x0500-0x05ff Security and Safety Clusters | |
#define | ZCL_CLUST_IAS_ZONE 0x0500 |
#define | ZCL_CLUST_IAS_ACE 0x0501 |
#define | ZCL_CLUST_IAS_WD 0x0502 |
0x0600-0x06ff Protocol Interface Clusters | |
#define | ZCL_CLUST_GENERIC_TUNNEL 0x0600 |
#define | ZCL_CLUST_BACNET_TUNNEL 0x0601 |
#define | ZCL_CLUST_BACNET_REG_ANALOG_IN 0x0602 |
#define | ZCL_CLUST_BACNET_EXT_ANALOG_IN 0x0603 |
#define | ZCL_CLUST_BACNET_REG_ANALOG_OUT 0x0604 |
#define | ZCL_CLUST_BACNET_EXT_ANALOG_OUT 0x0605 |
#define | ZCL_CLUST_BACNET_REG_ANALOG_VALUE 0x0606 |
#define | ZCL_CLUST_BACNET_EXT_ANALOG_VALUE 0x0607 |
#define | ZCL_CLUST_BACNET_REG_BINARY_IN 0x0608 |
#define | ZCL_CLUST_BACNET_EXT_BINARY_IN 0x0609 |
#define | ZCL_CLUST_BACNET_REG_BINARY_OUT 0x060a |
#define | ZCL_CLUST_BACNET_EXT_BINARY_OUT 0x060b |
#define | ZCL_CLUST_BACNET_REG_BINARY_VALUE 0x060c |
#define | ZCL_CLUST_BACNET_EXT_BINARY_VALUE 0x060d |
#define | ZCL_CLUST_BACNET_REG_MULTI_IN 0x060e |
#define | ZCL_CLUST_BACNET_EXT_MULTI_IN 0x060f |
#define | ZCL_CLUST_BACNET_REG_MULTI_OUT 0x0610 |
#define | ZCL_CLUST_BACNET_EXT_MULTI_OUT 0x0611 |
#define | ZCL_CLUST_BACNET_REG_MULTI_VALUE 0x0612 |
#define | ZCL_CLUST_BACNET_EXT_MULTI_VALUE 0x0613 |
Bit masks for the frame_control field of a ZCL header (zcl_header_t, zcl_header_response_t, zcl_header_withmfg_t, or zcl_header_nomfg_t) | |
#define | ZCL_FRAME_TYPE_MASK 0x03 |
Bits of frame type. | |
#define | ZCL_FRAME_TYPE_PROFILE 0x00 |
cmd acts across entire profile | |
#define | ZCL_FRAME_TYPE_CLUSTER 0x01 |
cmd is specific to a cluster | |
#define | ZCL_FRAME_TYPE_RESERVED1 0x02 |
#define | ZCL_FRAME_TYPE_RESERVED2 0x03 |
#define | ZCL_FRAME_GENERAL 0x00 |
mfg code field not present | |
#define | ZCL_FRAME_MFG_SPECIFIC 0x04 |
mfg code field present | |
#define | ZCL_FRAME_DIRECTION 0x08 |
direction bit | |
#define | ZCL_FRAME_CLIENT_TO_SERVER 0 |
cmd sent from client to server | |
#define | ZCL_FRAME_SERVER_TO_CLIENT ZCL_FRAME_DIRECTION |
cmd sent from server to client | |
#define | ZCL_FRAME_DISABLE_DEF_RESP 0x10 |
default response only on error | |
#define | ZCL_FRAME_RESERVED_BITS 0xE0 |
should be set to 0 | |
ZCL General Command IDs | |
Used for the .command element of the ZCL header. Command IDs 0x11 to 0x7F (Standard ZigBee command) and 0x80 to 0xFF are reserved.
| |
#define | ZCL_CMD_READ_ATTRIB 0x00 |
Read Attributes Command, payload is 1 to n 2-byte attribute IDs. | |
#define | ZCL_CMD_READ_ATTRIB_RESP 0x01 |
Read Attributes Response Command, payload is 1 to n variable-length Read Attribute Status records (zcl_rec_read_attrib_status_t). More... | |
#define | ZCL_CMD_WRITE_ATTRIB 0x02 |
Write Attributes Command, payload is 1 to n variable-length Write Attribute Record fields (same as zcl_attrib_t). More... | |
#define | ZCL_CMD_WRITE_ATTRIB_UNDIV 0x03 |
Write Attributes Undivided Command, same payload as Write Attributes Command (zcl_attrib_t), but attributes are only written if all attributes can be written successfully. More... | |
#define | ZCL_CMD_WRITE_ATTRIB_RESP 0x04 |
Write Attributes Response Command, payload is a single byte (ZCL_STATUS_SUCCESS) if all writes were successful or 1 to n 3-byte Write Attribute Status records (zcl_rec_write_attrib_status_t) for each write that failed. | |
#define | ZCL_CMD_WRITE_ATTRIB_NORESP 0x05 |
Write Attributes No Response Command, same payload as Write Attributes Command (ZCL_CMD_WRITE_ATTRIB), handled as a Write Attributes Command except the response is not sent. More... | |
#define | ZCL_CMD_CONFIGURE_REPORT 0x06 |
#define | ZCL_CMD_CONFIGURE_REPORT_RESP 0x07 |
#define | ZCL_CMD_READ_REPORT_CFG 0x08 |
#define | ZCL_CMD_READ_REPORT_CFG_RESP 0x09 |
#define | ZCL_CMD_REPORT_ATTRIB 0x0a |
#define | ZCL_CMD_DEFAULT_RESP 0x0b |
Default Response Command, payload is 2 bytes; Command ID and Status Code (zcl_default_response_t). More... | |
#define | ZCL_CMD_DISCOVER_ATTRIB 0x0c |
Discover Attributes Command, payload is 3 bytes; start attribute ID and maximum number of attributes to return (zcl_discover_attrib_t). More... | |
#define | ZCL_CMD_DISCOVER_ATTRIB_RESP 0x0d |
Discover Attributes Response Command payload is a "discovery complete" byte (done = ZCL_BOOL_TRUE, more attributes = ZCL_BOOL_TRUE), followed by 1 to n 3-byte Attribute Report fields (zcl_rec_attrib_report_t). More... | |
#define | ZCL_CMD_READ_STRUCT_ATTRIB 0x0e |
#define | ZCL_CMD_WRITE_STRUCT_ATTRIB 0x0f |
#define | ZCL_CMD_WRITE_STRUCT_ATTRIB_RESP 0x10 |
#define ZCL_CMD_DEFAULT_RESP 0x0b |
Default Response Command, payload is 2 bytes; Command ID and Status Code (zcl_default_response_t).
Referenced by zcl_command_dump(), zcl_default_response(), and zcl_general_command().
#define ZCL_CMD_DISCOVER_ATTRIB 0x0c |
Discover Attributes Command, payload is 3 bytes; start attribute ID and maximum number of attributes to return (zcl_discover_attrib_t).
Referenced by zcl_general_command().
#define ZCL_CMD_DISCOVER_ATTRIB_RESP 0x0d |
Discover Attributes Response Command payload is a "discovery complete" byte (done = ZCL_BOOL_TRUE, more attributes = ZCL_BOOL_TRUE), followed by 1 to n 3-byte Attribute Report fields (zcl_rec_attrib_report_t).
Referenced by _zcl_discover_attributes(), and zcl_general_command().
#define ZCL_CMD_IS_CLUSTER | ( | p | ) |
Identify cluster commands that are not manufacturer-specific, using the frame control field of a ZCL command.
[in] | p | pointer to first byte of payload |
TRUE | ZCL command is manufacturer and cluster-specific |
FALSE | ZCL command doesn't have the manufacturer-specific bit set, or is a profile-wide command |
#define ZCL_CMD_IS_MFG_CLUSTER | ( | p | ) |
Identify manufacturer-specific cluster commands using the frame control field of a ZCL command.
[in] | p | pointer to first byte of payload |
TRUE | ZCL command is manufacturer and cluster-specific |
FALSE | ZCL command doesn't have the manufacturer-specific bit set, or is a profile-wide command |
#define ZCL_CMD_IS_PROFILE | ( | p | ) | (ZCL_FRAME_TYPE_PROFILE == (*(const uint8_t FAR *)(p) & ZCL_FRAME_TYPE_MASK)) |
Identify profile commands (as opposed to cluster commands) using the frame control field of a ZCL command.
Ignores the manufacturer-specific bit (which specifies use of manufacturer-specific attributes).
[in] | p | pointer to first byte of payload |
TRUE | ZCL command is not cluster-specific (profile command) |
FALSE | ZCL command is cluster-specific |
#define ZCL_CMD_MATCH | ( | p, | |
mfg, | |||
dir, | |||
type | |||
) |
Macro for checking the frame control field of a ZCL command.
Used to filter out commands that are (or are not) handled by the current function.
[in] | p | pointer to first byte of payload (typically envelope->payload when called from a standard ZCL command handler, or the address of frame_control from a zcl_command_t built with zcl_command_build) |
[in] | mfg | either MFG_SPECIFIC or GENERAL |
[in] | dir | either CLIENT_TO_SERVER or SERVER_TO_CLIENT |
[in] | type | either PROFILE (e.g., general commands) or CLUSTER (cluster-specific command) |
TRUE | ZCL command matches all three filters |
FALSE | ZCL command does not match |
Referenced by _zcl_basic_server(), _zcl_onoff_handler(), zcl_comm_sas_is_valid(), zcl_identify_command(), zcl_ota_upgrade_cluster_handler(), and zcl_time_client().
#define ZCL_CMD_READ_ATTRIB_RESP 0x01 |
Read Attributes Response Command, payload is 1 to n variable-length Read Attribute Status records (zcl_rec_read_attrib_status_t).
Referenced by _zcl_read_attributes(), zcl_general_command(), and zcl_time_client().
#define ZCL_CMD_WRITE_ATTRIB 0x02 |
Write Attributes Command, payload is 1 to n variable-length Write Attribute Record fields (same as zcl_attrib_t).
Referenced by zcl_general_command(), and zcl_send_write_attributes().
#define ZCL_CMD_WRITE_ATTRIB_NORESP 0x05 |
Write Attributes No Response Command, same payload as Write Attributes Command (ZCL_CMD_WRITE_ATTRIB), handled as a Write Attributes Command except the response is not sent.
Referenced by _zcl_write_attributes(), and zcl_general_command().
#define ZCL_CMD_WRITE_ATTRIB_UNDIV 0x03 |
Write Attributes Undivided Command, same payload as Write Attributes Command (zcl_attrib_t), but attributes are only written if all attributes can be written successfully.
Referenced by _zcl_write_attributes(), and zcl_general_command().
typedef 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 attribute.
Necessary for attributes that are tied to physical hardware (only updated when requested) or attributes that change over time (as with the ZCL Identify cluster).
If the return value is not ZCL_STATUS_SUCCESS, the ZCL Read Attributes handler will return that as an error in the response frame.
[in,out] | entry | attribute to update |
ZCL_STATUS_SUCCESS | successfully updated value |
ZCL_STATUS_HARDWARE_FAILURE | unable to update value due to hardware problem |
ZCL_STATUS_SOFTWARE_FAILURE | unable to update value due to software problem |
typedef 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 process a Write Request for the attribute.
This function typically calls zcl_decode_attribute() to convert the request to a temporary variable and then perform additional checks on it before assigning to the actual variable.
[in] | entry | attribute to update |
[in,out] | rec | record from Write Request with new value |
int _zcl_discover_attributes | ( | zcl_command_t * | cmd | ) |
Process the Discover Attributes Command (ZCL_CMD_DISCOVER_ATTRIB).
[in] | cmd | command to respond to |
0 | successfully sent response |
!0 | error on send |
References zcl_command_t::attributes, EINVAL, FAR, htole16, le16toh, ZCL_ATTRIBUTE_END_OF_LIST, zcl_attribute_get_next(), zcl_build_header(), ZCL_CMD_DISCOVER_ATTRIB_RESP, zcl_command_t::zcl_payload, and zcl_send_response().
Referenced by _zcl_read_attributes(), and zcl_general_command().
int _zcl_encode_array_value | ( | uint8_t FAR * | buffer, |
int16_t | bufsize, | ||
const zcl_array_t FAR * | array | ||
) |
Format a ZCL array for a Read Attributes Response or a Write Attributes Request.
[out] | buffer | buffer to store encoded attribute |
[in] | bufsize | number of bytes available in buffer |
[in] | array | array to encode into buffer |
Copies the value of attribute entry
to buffer
in little-endian byte order. Will not write more than bufsize
bytes. Used to build ZCL frames.
-ZCL_STATUS_INSUFFICIENT_SPACE | buffer too small to encode value |
-ZCL_STATUS_FAILURE | unknown/unsupported attribute type |
-ZCL_STATUS_HARDWARE_FAILURE | failure updating attribute value |
-ZCL_STATUS_SOFTWARE_FAILURE | failure updating attribute value |
>=0 | number of bytes written |
References FAR, and zcl_encode_attribute_value().
Referenced by zcl_encode_attribute_value().
int _zcl_encode_struct_value | ( | uint8_t FAR * | buffer, |
int16_t | bufsize, | ||
const zcl_struct_t FAR * | zcl_struct | ||
) |
Format a ZCL struct for a Read Attributes Response or a Write Attributes Request.
[out] | buffer | buffer to store encoded attribute |
[in] | bufsize | number of bytes available in buffer |
[in] | zcl_struct | struct to encode into buffer |
Copies the value of attribute entry
to buffer
in little-endian byte order. Will not write more than bufsize
bytes. Used to build ZCL frames.
-ZCL_STATUS_INSUFFICIENT_SPACE | buffer too small to encode value |
-ZCL_STATUS_FAILURE | unknown/unsupported attribute type |
-ZCL_STATUS_HARDWARE_FAILURE | failure updating attribute value |
-ZCL_STATUS_SOFTWARE_FAILURE | failure updating attribute value |
>=0 | number of bytes written |
References FAR, and zcl_encode_attribute_value().
Referenced by zcl_encode_attribute_value().
int _zcl_read_attributes | ( | zcl_command_t * | cmd | ) |
Process the Read Attributes Command (ZCL_CMD_READ_ATTRIB).
[in] | cmd | command to respond to |
0 | successfully sent response |
!0 | error on send |
-EINVAL | NULL cmd parameter |
References _zcl_discover_attributes(), zcl_command_t::attributes, EINVAL, FAR, le16toh, zcl_command_t::length, ZCL_ATTRIB_FLAG_WRITEONLY, zcl_build_header(), ZCL_CMD_READ_ATTRIB_RESP, zcl_default_response(), zcl_encode_attribute_value(), zcl_find_attribute(), zcl_command_t::zcl_payload, and zcl_send_response().
Referenced by zcl_encode_attribute_value(), and zcl_general_command().
int _zcl_write_attributes | ( | zcl_command_t * | cmd | ) |
Process the three types of Write Attributes requests.
Handles Write Attributes (ZCL_CMD_WRITE_ATTRIB), Write Attributes Undivided (ZCL_CMD_WRITE_ATTRIB_UNDIV) and Write Attributes No Response (ZCL_CMD_WRITE_ATTRIB_NORESP).
[in] | cmd | command to respond to |
0 | successfully sent response or "No Response" requested |
!0 | error on send |
References zcl_command_t::attributes, zcl_attribute_write_rec_t::buffer, zcl_attribute_write_rec_t::buflen, zcl_command_t::command, zcl_attribute_write_rec_t::flags, hex_dump(), HEX_DUMP_FLAG_TAB, zcl_command_t::length, zcl_attribute_write_rec_t::status, ZCL_ATTR_WRITE_FLAG_ASSIGN, zcl_build_header(), ZCL_CMD_WRITE_ATTRIB_NORESP, ZCL_CMD_WRITE_ATTRIB_RESP, ZCL_CMD_WRITE_ATTRIB_UNDIV, zcl_parse_attribute_record(), zcl_command_t::zcl_payload, and zcl_send_response().
Referenced by zcl_decode_attribute(), and zcl_general_command().
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.
[in] | entry | current entry from the table |
NULL | entry was NULL |
!NULL | pointer to next attribute record |
References FAR, ZCL_ATTRIB_FLAG_FULL, and ZCL_ATTRIBUTE_END_OF_LIST.
Referenced by _zcl_discover_attributes(), zcl_create_attribute_records(), and zcl_find_attribute().
int zcl_build_header | ( | zcl_header_response_t * | rsp, |
zcl_command_t * | cmd | ||
) |
Support function to fill in a ZCL response header.
Set the frame_control
, sequence
and optional mfg_code
fields of the ZCL response header, and return the offset to the actual start of the header (non-mfg specific skips the first two bytes).
[out] | rsp | buffer to store header of response |
[in] | cmd | command we're responding to |
0 | responding to manufacturer-specific command |
2 | responding to non-manufacturer-specific command |
-EINVAL | invalid parameter passed to function |
References EINVAL, zcl_command_t::frame_control, htole16, zcl_command_t::mfg_code, zcl_command_t::sequence, ZCL_FRAME_DIRECTION, ZCL_FRAME_DISABLE_DEF_RESP, ZCL_FRAME_MFG_SPECIFIC, and ZCL_FRAME_TYPE_MASK.
Referenced by _zcl_discover_attributes(), _zcl_read_attributes(), _zcl_write_attributes(), zcl_default_response(), and zcl_identify_command().
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 attribute.
[in] | entry | entry to use for min/max check |
[in] | buffer_le | buffer with new value (in little-endian byte order), from write attributes command |
0 | new value is within range (or attribute doesn't have a min/max) |
-EINVAL | invalid parameter passed to function |
!0 | value is out of range |
References EINVAL, FAR, memcpy_letoh, ZCL_ATTRIB_FLAG_HAS_MAX, ZCL_ATTRIB_FLAG_HAS_MIN, zcl_sizeof_type(), ZCL_T_FLOAT, ZCL_T_SIGNED, and zcl_type_info.
Referenced by zcl_parse_attribute_record().
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 easier to use than the variable-length frame header).
Also uses the direction bit and manufacturer ID to search the attribute tree for the correct list of attributes.
[out] | cmd | buffer to store parsed ZCL command |
[in] | envelope | envelope from received message |
[in] | tree | pointer to attribute tree for cluster or NULL if the cluster doesn't have any attributes (typically passed in via endpoint dispatcher) |
0 | parsed payload from envelope into cmd |
-EINVAL | invalid parameter passed to function |
-EBADMSG | frame is too small for ZCL header's frame_control value |
References zcl_command_t::attributes, zcl_command_t::command, EBADMSG, EINVAL, zcl_command_t::envelope, FAR, zcl_command_t::frame_control, le16toh, zcl_command_t::length, zcl_command_t::mfg_code, zcl_command_t::sequence, ZCL_FRAME_CLIENT_TO_SERVER, ZCL_FRAME_DIRECTION, ZCL_FRAME_MFG_SPECIFIC, and zcl_command_t::zcl_payload.
Referenced by _zcl_basic_server(), _zcl_onoff_handler(), zcl_envelope_payload_dump(), zcl_general_command(), zcl_identify_command(), zcl_invalid_cluster(), zcl_invalid_command(), zcl_ota_upgrade_cluster_handler(), and zcl_time_client().
void zcl_command_dump | ( | const zcl_command_t * | cmd | ) |
Debugging routine that dumps contents of a parsed ZCL command structure to STDOUT.
[in] | cmd | zcl_command_t structure populated by zcl_command_build() |
References _TABLE_ENTRIES, zcl_command_t::command, FAR, zcl_command_t::frame_control, hex_dump(), HEX_DUMP_FLAG_TAB, zcl_command_t::length, zcl_command_t::mfg_code, zcl_command_t::sequence, ZCL_CMD_DEFAULT_RESP, ZCL_CMD_WRITE_ATTRIB_RESP, ZCL_FRAME_CLIENT_TO_SERVER, ZCL_FRAME_DIRECTION, ZCL_FRAME_DISABLE_DEF_RESP, ZCL_FRAME_TYPE_MASK, ZCL_FRAME_TYPE_PROFILE, zcl_command_t::zcl_payload, and zcl_status_text().
Referenced by zcl_envelope_payload_dump().
Convert a 24-bit (3-byte) little-endian value to a 32-bit value in host byte order.
[in] | value_le | pointer to 3 bytes to convert |
[in] | extend_sign | if TRUE, set high byte of result to 0xFF if top bit of 24-bit value is set |
References FAR.
Referenced by zcl_decode_attribute().
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 optionally write to entry
.
[in] | entry | entry from attribute table |
[in,out] | rec | state information for parsing write request |
>=0 | number of bytes consumed from rec->buffer |
-EINVAL | invalid parameter passed to function |
References _zcl_write_attributes(), zcl_attribute_write_rec_t::buffer, zcl_attribute_write_rec_t::buflen, EINVAL, FAR, zcl_attribute_write_rec_t::flags, memcpy_letoh, PRIsFAR, PRIx32, zcl_attribute_write_rec_t::status, ZCL_ATTR_WRITE_FLAG_ASSIGN, ZCL_ATTRIB_FLAG_FULL, ZCL_ATTRIB_FLAG_RAW, zcl_convert_24bit(), zcl_sizeof_type(), ZCL_TYPE_IS_INVALID, ZCL_TYPE_STRING_CHAR, and ZCL_TYPE_UNKNOWN.
Referenced by _zcl_identify_time_set(), _zcl_time_time_set(), and zcl_parse_attribute_record().
int zcl_default_response | ( | zcl_command_t * | request, |
uint8_t | status | ||
) |
Send a Default Response (ZCL_CMD_DEFAULT_RESP) to a given command.
[in] | request | command we're responding to |
[in] | status | status to use in the response (see ZCL_STATUS_* macros under "ZCL Status Enumerations" in zigbee/zcl.h) |
0 | successfully sent response, or response not required (message was broadcast, sent to the broadcast endpoint, or sender set the disable default response bit) |
!0 | error on send |
-EINVAL | invalid parameter passed to function |
References zcl_command_t::command, EINVAL, zcl_command_t::envelope, zcl_command_t::frame_control, WPAN_ENVELOPE_BROADCAST_ADDR, WPAN_ENVELOPE_BROADCAST_EP, zcl_build_header(), ZCL_CMD_DEFAULT_RESP, ZCL_FRAME_DISABLE_DEF_RESP, ZCL_FRAME_TYPE_MASK, ZCL_FRAME_TYPE_PROFILE, and zcl_send_response().
Referenced by _zcl_basic_server(), _zcl_onoff_handler(), _zcl_read_attributes(), zcl_identify_command(), zcl_invalid_cluster(), zcl_invalid_command(), and zcl_time_client().
int zcl_encode_attribute_value | ( | uint8_t FAR * | buffer, |
int16_t | bufsize, | ||
const zcl_attribute_base_t FAR * | entry | ||
) |
Format a ZCL attribute's value for a Read Attributes Response or a Write Attributes Request.
Copies the value of attribute entry
to buffer
in little-endian byte order. Will not write more than bufsize
bytes. Used to build ZCL frames.
[out] | buffer | buffer to store encoded attribute |
[in] | bufsize | number of bytes available in buffer |
[in] | entry | attribute to encode into buffer |
-ZCL_STATUS_SOFTWARE_FAILURE | invalid parameter passed in |
-ZCL_STATUS_DEFINED_OUT_OF_BAND | ghost attribute with NULL value |
-ZCL_STATUS_INSUFFICIENT_SPACE | buffer too small to encode value |
-ZCL_STATUS_FAILURE | unknown/unsupported attribute type |
-ZCL_STATUS_HARDWARE_FAILURE | failure updating attribute value |
>=0 | number of bytes written |
References _zcl_encode_array_value(), _zcl_encode_struct_value(), _zcl_read_attributes(), FAR, memcpy_htole, ZCL_ATTRIB_FLAG_FULL, ZCL_ATTRIB_FLAG_RAW, zcl_sizeof_type(), ZCL_TYPE_ARRAY, ZCL_TYPE_BAG, ZCL_TYPE_IS_INVALID, ZCL_TYPE_SET, ZCL_TYPE_STRING_CHAR, and ZCL_TYPE_STRUCT.
Referenced by _zcl_encode_array_value(), _zcl_encode_struct_value(), _zcl_read_attributes(), and zcl_create_attribute_records().
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.
[in] | envelope | wpan_envelope_t structure with a ZCL command payload |
References hex_dump(), HEX_DUMP_FLAG_OFFSET, wpan_envelope_t::length, wpan_envelope_t::payload, zcl_command_build(), and zcl_command_dump().
Referenced by zcl_ota_upgrade_cluster_handler(), and zcl_ota_upgrade_image_notify().
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
.
[in] | entry | starting entry for search |
[in] | search_id | attribute ID to look for |
NULL | attribute id search_id not in list |
!NULL | pointer to attribute record |
References zcl_attribute_get_next().
Referenced by _zcl_read_attributes(), and zcl_parse_attribute_record().
int zcl_general_command | ( | const wpan_envelope_t FAR * | envelope, |
void FAR * | context | ||
) |
Handler for ZCL General Commands.
Used as the handler for attribute-only clusters (e.g., Basic Cluster), or called from a cluster's handler for commands it doesn't handle.
Will send a Default Response for commands it can't handle.
Currently does not support attribute reporting.
[in] | envelope | envelope from received message |
[in] | context | pointer to attribute tree for cluster or NULL if the cluster doesn't have any attributes (typically passed in via endpoint dispatcher) |
0 | command was processed, including sending a possible response |
!0 | error sending response or processing command |
References _zcl_discover_attributes(), _zcl_read_attributes(), _zcl_write_attributes(), zcl_command_t::command, FAR, zcl_command_t::frame_control, hex_dump(), HEX_DUMP_FLAG_TAB, zcl_command_t::sequence, wpan_conversation_response(), ZCL_CMD_DEFAULT_RESP, ZCL_CMD_DISCOVER_ATTRIB, ZCL_CMD_DISCOVER_ATTRIB_RESP, ZCL_CMD_READ_ATTRIB, ZCL_CMD_READ_ATTRIB_RESP, ZCL_CMD_WRITE_ATTRIB, ZCL_CMD_WRITE_ATTRIB_NORESP, ZCL_CMD_WRITE_ATTRIB_RESP, ZCL_CMD_WRITE_ATTRIB_UNDIV, zcl_command_build(), ZCL_FRAME_TYPE_MASK, ZCL_FRAME_TYPE_PROFILE, zcl_invalid_command(), zcl_command_t::zcl_payload, and zcl_status_text().
Referenced by _zcl_basic_server(), _zcl_onoff_handler(), zcl_comm_sas_is_valid(), zcl_identify_command(), zcl_ota_upgrade_cluster_handler(), and zcl_time_client().
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.
Sends a Default Response (ZCL_CMD_DEFAULT_RESP) of #ZCL_STATUS_FAILURE unless the received command was a Default Response or was broadcast.
[in] | envelope | envelope from received message |
[in] | ep_state | pointer to endpoint's wpan_ep_state_t |
0 | command was a default response (and therefore ignored), or a default response was successfully sent |
!0 | error sending response |
References XBEE_UNUSED_PARAMETER, zcl_command_build(), and zcl_default_response().
Referenced by _wpan_endpoint_dispatch().
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.
Sends a Default Response (ZCL_CMD_DEFAULT_RESP) unless the received command was a Default Response or was broadcast. Depending on the command received, the response will be one of:
[in] | envelope | envelope from received message |
0 | default response was successfully sent, or command did not require a default response |
!0 | error building or sending response |
References zcl_command_t::command, zcl_command_t::frame_control, zcl_command_build(), zcl_default_response(), ZCL_FRAME_MFG_SPECIFIC, ZCL_FRAME_TYPE_CLUSTER, and ZCL_FRAME_TYPE_MASK.
Referenced by zcl_general_command().
int zcl_parse_attribute_record | ( | const zcl_attribute_base_t FAR * | entry, |
zcl_attribute_write_rec_t * | write_rec | ||
) |
Parse an attribute record from a Write Attributes Request or a Read Attributes Response and possibly store the new attribute value.
If ZCL_ATTR_WRITE_FLAG_READ_RESP is set in write_rec->flags
, write_rec->buffer
will be parsed as a Read Attributes Response record. Otherwise, it's parsed as a Write Attributes Request record.
[in] | entry | attribute table to search or NULL if there aren't any attributes on this cluster |
[in,out] | write_rec | state information for parsing write request |
>=0 | number of bytes consumed from buffer |
-EINVAL | invalid parameter passed to function |
References zcl_attribute_write_rec_t::buffer, zcl_attribute_write_rec_t::buflen, EINVAL, FAR, zcl_attribute_write_rec_t::flags, le16toh, zcl_attribute_write_rec_t::status, zcl_attribute_base_t::type, ZCL_ATTR_WRITE_FLAG_ASSIGN, ZCL_ATTR_WRITE_FLAG_READ_RESP, ZCL_ATTRIB_FLAG_FULL, ZCL_ATTRIB_FLAG_READONLY, zcl_check_minmax(), zcl_decode_attribute(), zcl_find_attribute(), zcl_sizeof_type(), and ZCL_TYPE_IS_INVALID.
Referenced by _zcl_write_attributes(), and zcl_process_read_attr_response().
int zcl_send_response | ( | zcl_command_t * | request, |
const void FAR * | response, | ||
uint16_t | length | ||
) |
Send a response to a ZCL command.
Uses information from the command received to populate fields in the response.
[in] | request | command to respond to |
[in] | response | payload to send as response |
[in] | length | number of bytes in response |
0 | successfully sent response |
!0 | error on send |
References EINVAL, zcl_command_t::envelope, wpan_envelope_t::length, wpan_envelope_t::payload, wpan_envelope_dump(), wpan_envelope_reply(), and wpan_envelope_send().
Referenced by _zcl_discover_attributes(), _zcl_read_attributes(), _zcl_write_attributes(), zcl_default_response(), zcl_identify_command(), zcl_ota_image_block_resp(), zcl_ota_next_image_resp(), and zcl_ota_upgrade_end_resp().
const char * zcl_status_text | ( | uint_fast8_t | status | ) |
Converts a ZCL status byte (one of the ZCL_STATUS_* macros) into a string.
[in] | status | status byte to convert |
Referenced by zcl_command_dump(), and zcl_general_command().
const zcl_attribute_tree_t FAR zcl_attributes_none[1] |
If a cluster doesn't have attributes, use zcl_attributes_none (a single, empty attribute list) in the cluster definition.
Don't use NULL, since the APS dispatcher will use endpoint's context if the cluster's context is NULL.
const zcl_attribute_tree_t FAR zcl_attributes_none[1] |
If a cluster doesn't have attributes, use zcl_attributes_none (a single, empty attribute list) in the cluster definition.
Don't use NULL, since the APS dispatcher will use endpoint's context if the cluster's context is NULL.