Skip to content

Commit

Permalink
Merge pull request #8825 from s-hadinger/zigbee_ezsp_5
Browse files Browse the repository at this point in the history
Zigbee EZSP milestone 3
  • Loading branch information
arendst authored Jun 30, 2020
2 parents 074bef9 + fc40a09 commit a44f82d
Show file tree
Hide file tree
Showing 8 changed files with 652 additions and 170 deletions.
201 changes: 200 additions & 1 deletion tasmota/xdrv_23_zigbee_0_constants.ino
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,53 @@ enum ZnpSubsystem {

#ifdef USE_ZIGBEE_EZSP

enum EZSPCondigId {
enum EZSPNodeType {
EMBER_UNKNOWN_DEVICE = 0x00,
EMBER_COORDINATOR = 0x01,
EMBER_ROUTER = 0x02,
EMBER_END_DEVICE = 0x03,
EMBER_SLEEPY_END_DEVICE = 0x04
};

enum EZSPDeviceUpdate {
EMBER_STANDARD_SECURITY_SECURED_REJOIN = 0x00,
EMBER_STANDARD_SECURITY_UNSECURED_JOIN = 0x01,
EMBER_DEVICE_LEFT = 0x02,
EMBER_STANDARD_SECURITY_UNSECURED_REJOIN = 0x03,
};

enum EZSPJoinDecision {
EMBER_USE_PRECONFIGURED_KEY = 0x00,
EMBER_SEND_KEY_IN_THE_CLEAR = 0x01,
EMBER_DENY_JOIN = 0x02,
EMBER_NO_ACTION = 0x03
};

enum EZSPCurrentSecurytBitMask {
EMBER_STANDARD_SECURITY_MODE = 0x0000,
EMBER_DISTRIBUTED_TRUST_CENTER_MODE = 0x0002,
EMBER_GLOBAL_LINK_KEY = 0x0004,
EMBER_TRUST_CENTER_GLOBAL_LINK_KEY = 0x0004,
EMBER_PRECONFIGURED_NETWORK_KEY_MODE = 0x0008,
EMBER_HAVE_TRUST_CENTER_LINK_KEY = 0x0010,
EMBER_TRUST_CENTER_USES_HASHED_LINK_KEY = 0x0084,
EMBER_HAVE_PRECONFIGURED_KEY = 0x0100,
EMBER_HAVE_NETWORK_KEY = 0x0200,
EMBER_GET_LINK_KEY_WHEN_JOINING = 0x0400,
EMBER_REQUIRE_ENCRYPTED_KEY = 0x0800,
EMBER_NO_FRAME_COUNTER_RESET = 0x1000,
EMBER_GET_PRECONFIGURED_KEY_FROM_INSTALL_CODE = 0x2000,
EMBER_HAVE_TRUST_CENTER_EUI64 = 0x0040
};

enum EZSPJoinMethod {
EMBER_USE_MAC_ASSOCIATION = 0x0,
EMBER_USE_NWK_REJOIN = 0x1,
EMBER_USE_NWK_REJOIN_HAVE_NWK_KEY = 0x2,
EMBER_USE_CONFIGURED_NWK_STATE = 0x3
};

enum EZSPConfigId {
EZSP_CONFIG_PACKET_BUFFER_COUNT = 0x01,
EZSP_CONFIG_NEIGHBOR_TABLE_SIZE = 0x02,
EZSP_CONFIG_APS_UNICAST_MESSAGE_COUNT = 0x03,
Expand Down Expand Up @@ -301,6 +347,159 @@ enum EZSPStatusId {
EZSP_NO_ERROR = 0xFF
};

enum EZSPPolicyId {
EZSP_TRUST_CENTER_POLICY = 0x00,
EZSP_BINDING_MODIFICATION_POLICY = 0x01,
EZSP_UNICAST_REPLIES_POLICY = 0x02,
EZSP_POLL_HANDLER_POLICY = 0x03,
EZSP_MESSAGE_CONTENTS_IN_CALLBACK_POLICY = 0x04,
EZSP_TC_KEY_REQUEST_POLICY = 0x05,
EZSP_APP_KEY_REQUEST_POLICY = 0x06,
EZSP_PACKET_VALIDATE_LIBRARY_POLICY = 0x07,
EZSP_ZLL_POLICY = 0x08,
EZSP_TC_REJOINS_USING_WELL_KNOWN_KEY_POLICY = 0x09
};

enum EZSPDecisionBitmask {
EZSP_DECISION_BITMASK_DEFAULT_CONFIGURATION = 0x0000,
EZSP_DECISION_ALLOW_JOINS = 0x0001,
EZSP_DECISION_ALLOW_UNSECURED_REJOINS = 0x0002,
EZSP_DECISION_SEND_KEY_IN_CLEAR = 0x0004,
EZSP_DECISION_IGNORE_UNSECURED_REJOINS = 0x0008,
EZSP_DECISION_JOINS_USE_INSTALL_CODE_KEY = 0x0010,
EZSP_DECISION_DEFER_JOINS = 0x0020
};

enum EZSPDecisionId {
EZSP_DEFER_JOINS_REJOINS_HAVE_LINK_KEY = 0x07,
EZSP_DISALLOW_BINDING_MODIFICATION = 0x10,
EZSP_ALLOW_BINDING_MODIFICATION = 0x11,
EZSP_CHECK_BINDING_MODIFICATIONS_ARE_VALID_ENDPOINT_CLUSTERS = 0x12,
EZSP_HOST_WILL_NOT_SUPPLY_REPLY = 0x20,
EZSP_HOST_WILL_SUPPLY_REPLY = 0x21,
EZSP_POLL_HANDLER_IGNORE = 0x30,
EZSP_POLL_HANDLER_CALLBACK = 0x31,
EZSP_MESSAGE_TAG_ONLY_IN_CALLBACK = 0x40,
EZSP_MESSAGE_TAG_AND_CONTENTS_IN_CALLBACK = 0x41,
EZSP_DENY_TC_KEY_REQUESTS = 0x50,
EZSP_ALLOW_TC_KEY_REQUESTS_AND_SEND_CURRENT_KEY = 0x51,
EZSP_ALLOW_TC_KEY_REQUEST_AND_GENERATE_NEW_KEY = 0x52,
EZSP_DENY_APP_KEY_REQUESTS = 0x60,
EZSP_ALLOW_APP_KEY_REQUESTS = 0x61,
EZSP_PACKET_VALIDATE_LIBRARY_CHECKS_ENABLED = 0x62,
EZSP_PACKET_VALIDATE_LIBRARY_CHECKS_DISABLED = 0x63
};

enum EZSP_ZdoConfigurationFlags {
EMBER_APP_RECEIVES_SUPPORTED_ZDO_REQUESTS = 0x01,
EMBER_APP_HANDLES_UNSUPPORTED_ZDO_REQUESTS = 0x02,
EMBER_APP_HANDLES_ZDO_ENDPOINT_REQUESTS = 0x04,
EMBER_APP_HANDLES_ZDO_BINDING_REQUESTS = 0x08
};

enum EZSP_EmberIncomingMessageType {
EMBER_INCOMING_UNICAST = 0x00,
EMBER_INCOMING_UNICAST_REPLY = 0x01,
EMBER_INCOMING_MULTICAST = 0x02,
EMBER_INCOMING_MULTICAST_LOOPBACK = 0x03,
EMBER_INCOMING_BROADCAST = 0x04,
EMBER_INCOMING_BROADCAST_LOOPBACK = 0x05,
EMBER_INCOMING_MANY_TO_ONE_ROUTE_REQUEST = 0x06
};

enum EZSP_EmberApsOption {
EMBER_APS_OPTION_NONE = 0x0000,
EMBER_APS_OPTION_ENCRYPTION = 0x0020,
EMBER_APS_OPTION_RETRY = 0x0040,
EMBER_APS_OPTION_ENABLE_ROUTE_DISCOVERY = 0x0100,
EMBER_APS_OPTION_FORCE_ROUTE_DISCOVERY = 0x0200,
EMBER_APS_OPTION_SOURCE_EUI64 = 0x0400,
EMBER_APS_OPTION_DESTINATION_EUI64 = 0x0800,
EMBER_APS_OPTION_ENABLE_ADDRESS_DISCOVERY = 0x1000,
EMBER_APS_OPTION_POLL_RESPONSE = 0x2000,
EMBER_APS_OPTION_ZDO_RESPONSE_REQUIRED = 0x4000,
EMBER_APS_OPTION_FRAGMENT = 0x8000
};

enum EZSP_EmberOutgoingMessageType {
EMBER_OUTGOING_DIRECT = 0x00,
EMBER_OUTGOING_VIA_ADDRESS_TABLE = 0x01,
EMBER_OUTGOING_VIA_BINDING = 0x02,
EMBER_OUTGOING_MULTICAST = 0x03,
EMBER_OUTGOING_BROADCAST = 0x04
};

// inspired from https://github.com/zigpy/zigpy/blob/dev/zigpy/zdo/types.py
enum EZSP_ZDO {
ZDO_NWK_addr_req = 0x0000,
ZDO_IEEE_addr_req = 0x0001,
ZDO_Node_Desc_req = 0x0002,
ZDO_Power_Desc_req = 0x0003,
ZDO_Simple_Desc_req = 0x0004,
ZDO_Active_EP_req = 0x0005,
ZDO_Match_Desc_req = 0x0006,
ZDO_Complex_Desc_req = 0x0010,
ZDO_User_Desc_req = 0x0011,
ZDO_Discovery_Cache_req = 0x0012,
ZDO_Device_annce = 0x0013,
ZDO_User_Desc_set = 0x0014,
ZDO_System_Server_Discovery_req = 0x0015,
ZDO_Discovery_store_req = 0x0016,
ZDO_Node_Desc_store_req = 0x0017,
ZDO_Active_EP_store_req = 0x0019,
ZDO_Simple_Desc_store_req = 0x001A,
ZDO_Remove_node_cache_req = 0x001B,
ZDO_Find_node_cache_req = 0x001C,
ZDO_Extended_Simple_Desc_req = 0x001D,
ZDO_Extended_Active_EP_req = 0x001E,
ZDO_Parent_annce = 0x001F,
// Bind Management Server Services Responses
ZDO_End_Device_Bind_req = 0x0020,
ZDO_Bind_req = 0x0021,
ZDO_Unbind_req = 0x0022,
// Network Management Server Services Requests
ZDO_Mgmt_Lqi_req = 0x0031,
ZDO_Mgmt_Rtg_req = 0x0032,
ZDO_Mgmt_Leave_req = 0x0034,
ZDO_Mgmt_Permit_Joining_req = 0x0036,
ZDO_Mgmt_NWK_Update_req = 0x0038,

// Responses
// Device and Service Discovery Server Responses
ZDO_NWK_addr_rsp = 0x8000,
ZDO_IEEE_addr_rsp = 0x8001,
ZDO_Node_Desc_rsp = 0x8002,
ZDO_Power_Desc_rsp = 0x8003,
ZDO_Simple_Desc_rsp = 0x8004,
ZDO_Active_EP_rsp = 0x8005,
ZDO_Match_Desc_rsp = 0x8006,
ZDO_Complex_Desc_rsp = 0x8010,
ZDO_User_Desc_rsp = 0x8011,
ZDO_Discovery_Cache_rsp = 0x8012,
ZDO_User_Desc_conf = 0x8014,
ZDO_System_Server_Discovery_rsp = 0x8015,
ZDO_Discovery_Store_rsp = 0x8016,
ZDO_Node_Desc_store_rsp = 0x8017,
ZDO_Power_Desc_store_rsp = 0x8018,
ZDO_Active_EP_store_rsp = 0x8019,
ZDO_Simple_Desc_store_rsp = 0x801A,
ZDO_Remove_node_cache_rsp = 0x801B,
ZDO_Find_node_cache_rsp = 0x801C,
ZDO_Extended_Simple_Desc_rsp = 0x801D,
ZDO_Extended_Active_EP_rsp = 0x801E,
ZDO_Parent_annce_rsp = 0x801F,
// Bind Management Server Services Responses
ZDO_End_Device_Bind_rsp = 0x8020,
ZDO_Bind_rsp = 0x8021,
ZDO_Unbind_rsp = 0x8022,
// Network Management Server Services Responses
ZDO_Mgmt_Lqi_rsp = 0x8031,
ZDO_Mgmt_Rtg_rsp = 0x8032,
ZDO_Mgmt_Leave_rsp = 0x8034,
ZDO_Mgmt_Permit_Joining_rsp = 0x8036,
ZDO_Mgmt_NWK_Update_rsp = 0x8038,
};

enum EZSP_Commands {
EZSP_version = 0x0000,
EZSP_getLibraryStatus = 0x0001,
Expand Down
1 change: 1 addition & 0 deletions tasmota/xdrv_23_zigbee_2_devices.ino
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ Z_Devices zigbee_devices = Z_Devices();

// Local coordinator information
uint64_t localIEEEAddr = 0;
uint16_t localShortAddr = 0;

/*********************************************************************************************\
* Implementation
Expand Down
33 changes: 11 additions & 22 deletions tasmota/xdrv_23_zigbee_5_converters.ino
Original file line number Diff line number Diff line change
Expand Up @@ -595,14 +595,12 @@ public:
ZCLFrame(uint8_t frame_control, uint16_t manuf_code, uint8_t transact_seq, uint8_t cmd_id,
const char *buf, size_t buf_len, uint16_t clusterid, uint16_t groupaddr,
uint16_t srcaddr, uint8_t srcendpoint, uint8_t dstendpoint, uint8_t wasbroadcast,
uint8_t linkquality, uint8_t securityuse, uint8_t seqnumber,
uint32_t timestamp):
uint8_t linkquality, uint8_t securityuse, uint8_t seqnumber):
_manuf_code(manuf_code), _transact_seq(transact_seq), _cmd_id(cmd_id),
_payload(buf_len ? buf_len : 250), // allocate the data frame from source or preallocate big enough
_cluster_id(clusterid), _groupaddr(groupaddr),
_srcaddr(srcaddr), _srcendpoint(srcendpoint), _dstendpoint(dstendpoint), _wasbroadcast(wasbroadcast),
_linkquality(linkquality), _securityuse(securityuse), _seqnumber(seqnumber),
_timestamp(timestamp)
_linkquality(linkquality), _securityuse(securityuse), _seqnumber(seqnumber)
{
_frame_control.d8 = frame_control;
_payload.addBuffer(buf, buf_len);
Expand All @@ -616,13 +614,11 @@ public:
"\"groupid\":%d," "\"clusterid\":%d," "\"srcaddr\":\"0x%04X\","
"\"srcendpoint\":%d," "\"dstendpoint\":%d," "\"wasbroadcast\":%d,"
"\"" D_CMND_ZIGBEE_LINKQUALITY "\":%d," "\"securityuse\":%d," "\"seqnumber\":%d,"
"\"timestamp\":%d,"
"\"fc\":\"0x%02X\",\"manuf\":\"0x%04X\",\"transact\":%d,"
"\"cmdid\":\"0x%02X\",\"payload\":\"%s\"}}"),
_groupaddr, _cluster_id, _srcaddr,
_srcendpoint, _dstendpoint, _wasbroadcast,
_linkquality, _securityuse, _seqnumber,
_timestamp,
_frame_control, _manuf_code, _transact_seq, _cmd_id,
hex_char);
if (Settings.flag3.tuya_serial_mqtt_publish) {
Expand All @@ -635,8 +631,7 @@ public:

static ZCLFrame parseRawFrame(const SBuffer &buf, uint8_t offset, uint8_t len, uint16_t clusterid, uint16_t groupid,
uint16_t srcaddr, uint8_t srcendpoint, uint8_t dstendpoint, uint8_t wasbroadcast,
uint8_t linkquality, uint8_t securityuse, uint8_t seqnumber,
uint32_t timestamp) { // parse a raw frame and build the ZCL frame object
uint8_t linkquality, uint8_t securityuse, uint8_t seqnumber) { // parse a raw frame and build the ZCL frame object
uint32_t i = offset;
ZCLHeaderFrameControl_t frame_control;
uint16_t manuf_code = 0;
Expand All @@ -654,8 +649,7 @@ public:
(const char *)(buf.buf() + i), len + offset - i,
clusterid, groupid,
srcaddr, srcendpoint, dstendpoint, wasbroadcast,
linkquality, securityuse, seqnumber,
timestamp);
linkquality, securityuse, seqnumber);
return zcl_frame;
}

Expand All @@ -679,17 +673,12 @@ public:
_cluster_id = clusterid;
}

inline uint8_t getCmdId(void) const {
return _cmd_id;
}

inline uint16_t getClusterId(void) const {
return _cluster_id;
}

inline uint16_t getSrcEndpoint(void) const {
return _srcendpoint;
}
inline uint16_t getSrcAddr(void) const { return _srcaddr; }
inline uint16_t getGroupAddr(void) const { return _groupaddr; }
inline uint16_t getClusterId(void) const { return _cluster_id; }
inline uint8_t getLinkQuality(void) const { return _linkquality; }
inline uint8_t getCmdId(void) const { return _cmd_id; }
inline uint16_t getSrcEndpoint(void) const { return _srcendpoint; }

const SBuffer &getPayload(void) const {
return _payload;
Expand All @@ -699,6 +688,7 @@ public:
return _manuf_code;
}


private:
ZCLHeaderFrameControl_t _frame_control = { .d8 = 0 };
uint16_t _manuf_code = 0; // optional
Expand All @@ -715,7 +705,6 @@ private:
uint8_t _linkquality;
uint8_t _securityuse;
uint8_t _seqnumber;
uint32_t _timestamp;
};

// Zigbee ZCL converters
Expand Down
13 changes: 10 additions & 3 deletions tasmota/xdrv_23_zigbee_6_commands.ino
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,15 @@ ZF(HueSat) ZF(Color)
ZF(ShutterOpen) ZF(ShutterClose) ZF(ShutterStop) ZF(ShutterLift) ZF(ShutterTilt) ZF(Shutter)
//ZF(Occupancy)
ZF(DimmerMove) ZF(DimmerStep) ZF(DimmerStepUp) ZF(DimmerStepDown)
ZF(HueMove) ZF(HueStep) ZF(HueStepUp) ZF(HueStepDown) ZF(SatMove) ZF(SatStep) ZF(ColorMove) ZF(ColorStep) ZF(ColorTempStep) ZF(ColorTempStepUp) ZF(ColorTempStepDown)
ZF(HueMove) ZF(HueStep) ZF(HueStepUp) ZF(HueStepDown) ZF(SatMove) ZF(SatStep) ZF(ColorMove) ZF(ColorStep)
ZF(ColorTempMoveUp) ZF(ColorTempMoveDown) ZF(ColorTempMoveStop) ZF(ColorTempMove)
ZF(ColorTempStep) ZF(ColorTempStepUp) ZF(ColorTempStepDown)
ZF(ArrowClick) ZF(ArrowHold) ZF(ArrowRelease) ZF(ZoneStatusChange)

ZF(xxxx00) ZF(xxxx) ZF(01xxxx) ZF(03xxxx) ZF(00) ZF(01) ZF() ZF(xxxxyy) ZF(00190200) ZF(01190200) ZF(xxyyyy) ZF(xx)
ZF(xx000A00) ZF(xx0A00) ZF(xxyy0A00) ZF(xxxxyyyy0A00) ZF(xxxx0A00) ZF(xx0A)
ZF(xx190A00) ZF(xx19) ZF(xx190A) ZF(xxxxyyyy) ZF(xxxxyyzz) ZF(xxyyzzzz) ZF(xxyyyyzz)
ZF(01xxxx000000000000) ZF(03xxxx000000000000) ZF(00xxxx000000000000) ZF(xxyyyy000000000000)
ZF(00xx0A00) ZF(01xx0A00) ZF(03xx0A00) ZF(01xxxx0A0000000000) ZF(03xxxx0A0000000000) ZF(xxyyyy0A0000000000)

// Cluster specific commands
Expand Down Expand Up @@ -119,8 +122,12 @@ const Z_CommandConverter Z_Commands[] PROGMEM = {
{ Z(SatStep), 0x0300, 0x05, 0x01, Z(xx190A) },
{ Z(ColorMove), 0x0300, 0x08, 0x01, Z(xxxxyyyy) },
{ Z(ColorStep), 0x0300, 0x09, 0x01, Z(xxxxyyyy0A00) },
{ Z(ColorTempStepUp), 0x0300, 0x4C, 0x01, Z(01xxxx0A0000000000) }, //xxxx = step
{ Z(ColorTempStepDown),0x0300, 0x4C, 0x01, Z(03xxxx0A0000000000) }, //xxxx = step
{ Z(ColorTempMoveUp), 0x0300, 0x4B, 0x01, Z(01xxxx000000000000) },
{ Z(ColorTempMoveDown),0x0300, 0x4B, 0x01, Z(03xxxx000000000000) },
{ Z(ColorTempMoveStop),0x0300, 0x4B, 0x01, Z(00xxxx000000000000) },
{ Z(ColorTempMove), 0x0300, 0x4B, 0x01, Z(xxyyyy000000000000) },
{ Z(ColorTempStepUp), 0x0300, 0x4C, 0x01, Z(01xxxx0A0000000000) },
{ Z(ColorTempStepDown),0x0300, 0x4C, 0x01, Z(03xxxx0A0000000000) },
{ Z(ColorTempStep), 0x0300, 0x4C, 0x01, Z(xxyyyy0A0000000000) }, //xx = 0x01 up, 0x03 down, yyyy = step
// Tradfri
{ Z(ArrowClick), 0x0005, 0x07, 0x01, Z(xx) }, // xx == 0x01 = left, 0x00 = right
Expand Down
Loading

0 comments on commit a44f82d

Please sign in to comment.