123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- #ifndef ZCL_KEY_ESTABLISH_H
- #define ZCL_KEY_ESTABLISH_H
- #ifdef __cplusplus
- extern "C"
- {
- #endif
- #include "zcl.h"
- #include "eccapi.h"
- #define ZCL_KEY_ESTABLISHMENT_ENDPOINT 10 // Reserved endpoint for key establishment cluster
- #define KEY_ESTABLISHMENT_REC_AGING_EVT 0x01
- #define KEY_ESTABLISHMENT_CMD_PROCESS_EVT 0x02
- #define KEY_ESTABLISHMENT_RSP_PROCESS_EVT 0x04
- #define KEY_ESTABLISHMENT_REC_AGING_INTERVAL 1000 // in ms
- #define KEY_ESTABLISHMENT_WAIT_PERIOD 500
- #define ATTRID_KEY_ESTABLISH_SUITE 0x0000
- #define CERTIFICATE_BASED_KEY_ESTABLISHMENT 0x0000
- #define COMMAND_INITIATE_KEY_ESTABLISHMENT 0x00
- #define COMMAND_EPHEMERAL_DATA_REQUEST 0x01
- #define COMMAND_CONFIRM_KEY 0x02
- #define COMMAND_TERMINATE_KEY_ESTABLISHMENT 0x03
- #define COMMAND_INITIATE_KEY_ESTABLISHMENT_RESPONSE 0x00
- #define COMMAND_EPHEMERAL_DATA_RESPONSE 0x01
- #define COMMAND_CONFIRM_KEY_RESPONSE 0x02
- #define COMMAND_GET_LINK_KEY 0x04
- #define PACKET_LEN_INITIATE_KEY_EST_REQ (4+ZCL_KE_IMPLICIT_CERTIFICATE_LEN)
- #define PACKET_LEN_INITIATE_KEY_EST_RSP (4+ZCL_KE_IMPLICIT_CERTIFICATE_LEN)
- #define KEY_ESTABLISH_SHARED_SECRET_LENGTH 21
- #define KEY_ESTABLISH_KEY_DATA_LENGTH 16
- #define KEY_ESTABLISH_MAC_KEY_LENGTH 16
- #define KEY_ESTABLISH_MAC_LENGTH 16
- #define KEY_ESTABLISH_POINT_ORDER_SIZE 21
- #define KEY_ESTABLISH_AES_MMO_HASH_SIZE 16
- #define KEY_ESTABLISH_CERT_EXT_ADDR_IDX 22
- #define KEY_ESTABLISH_CERT_ISSUER_IDX 30
- #define KEY_ESTABLISH_CERT_IDX 4
- #define KEY_ESTABLISH_CERT_ISSUER_LENTGH Z_EXTADDR_LEN
- #define MAX_KEY_ESTABLISHMENT_REC_ENTRY 2
- #define INVALID_PARTNER_ADDR 0xFFFE
- #define KEY_ESTABLISHMENT_INITIATOR 0
- #define KEY_ESTABLISHMENT_RESPONDER 1
- #define KEY_ESTABLISHMENT_REC_EXPIRY_TIME 0xFF // In seconds
- #define KEY_ESTABLISHMENT_EPH_DATA_GEN_INVALID_TIME 0xFF // In seconds
- #define KEY_ESTABLISHMENT_CONF_KEY_GEN_INVALID_TIME 0xFF // In seconds
- #if !defined ( ZCL_KEY_ESTABLISHMENT_KEY_GENERATE_TIMEOUT )
- #define ZCL_KEY_ESTABLISHMENT_KEY_GENERATE_TIMEOUT 4
- #endif
- #if !defined ( ZCL_KEY_ESTABLISHMENT_MAC_GENERATE_TIMEOUT )
- #define ZCL_KEY_ESTABLISHMENT_MAC_GENERATE_TIMEOUT 1
- #endif
- #if !defined ( ZCL_KEY_ESTABLISHMENT_EKEY_GENERATE_TIMEOUT )
- #define ZCL_KEY_ESTABLISHMENT_EKEY_GENERATE_TIMEOUT 1
- #endif
- #if !defined (ZCL_KEY_ESTABLISH_POLL_RATE)
- #define ZCL_KEY_ESTABLISH_POLL_RATE 1000
- #endif
- typedef struct
- {
- afAddrType_t dstAddr;
- uint8 lastSeqNum;
- uint8 appTaskID;
- uint8 partnerExtAddr[Z_EXTADDR_LEN];
- uint8 role;
-
- uint8 age;
- uint8 state;
-
- uint8 *pLocalEPrivateKey;
- uint8 *pLocalEPublicKey;
- uint8 *pRemotePublicKey;
- uint8 *pRemoteCertificate;
- uint8 *pKey;
- uint8 *pMacKey;
- uint8 remoteEphDataGenTime;
- uint8 remoteConfKeyGenTime;
- } zclKeyEstablishRec_t;
- typedef enum
- {
- KeyEstablishState_Idle = 0,
- KeyEstablishState_InitiatePending,
- KeyEstablishState_EDataPending,
- KeyEstablishState_KeyCalculatePending,
- KeyEstablishState_ConfirmPending,
- KeyEstablishState_TerminationPending
- } KeyEstablishState_t;
- typedef enum
- {
- TermKeyStatus_Success = 0,
- TermKeyStatus_UnknowIssuer,
- TermKeyStatus_BadKeyConfirm,
- TermKeyStatus_BadMessage,
- TermKeyStatus_NoResources,
- TermKeyStatus_UnSupportedSuite
- } TermKeyStatus_t;
- typedef struct
- {
- osal_event_hdr_t hdr;
- uint8 waitTime;
- uint16 keyEstablishmentSuite;
- } keyEstablishmentInd_t;
- extern void zclGeneral_KeyEstablish_Init( uint8 task_id );
- extern uint16 zclKeyEstablish_event_loop( uint8 task_id, uint16 events );
- extern ZStatus_t zclGeneral_KeyEstablish_InitiateKeyEstablishment(uint8 appTaskID,
- afAddrType_t *partnerAddr,
- uint8 seqNum);
- extern ZStatus_t zclGeneral_KeyEstablish_Send_InitiateKeyEstablishment( uint8 srcEP, afAddrType_t *dstAddr,
- uint16 keyEstablishmentSuite,
- uint8 keyGenerateTime,
- uint8 macGenerateTime,
- uint8 *certificate,
- uint8 disableDefaultRsp, uint8 seqNum );
- extern ZStatus_t zclGeneral_KeyEstablish_Send_EphemeralDataReq( uint8 srcEP, afAddrType_t *dstAddr,
- uint8 *eData,
- uint8 disableDefaultRsp, uint8 seqNum );
- extern ZStatus_t zclGeneral_KeyEstablish_Send_ConfirmKey( uint8 srcEP, afAddrType_t *dstAddr,
- uint8 *mac,
- uint8 disableDefaultRsp, uint8 seqNum );
- extern ZStatus_t zclGeneral_KeyEstablish_Send_TerminateKeyEstablishment( uint8 srcEP,
- afAddrType_t *dstAddr,
- TermKeyStatus_t status,
- uint8 waitTime,
- uint16 keyEstablishmentSuite, uint8 direction,
- uint8 disableDefaultRsp, uint8 seqNum );
- extern ZStatus_t zclGeneral_KeyEstablish_Send_InitiateKeyEstablishmentRsp( uint8 srcEP, afAddrType_t *dstAddr,
- uint16 keyEstablishmentSuite,
- uint8 keyGenerateTime,
- uint8 macGenerateTime,
- uint8 *certificate,
- uint8 disableDefaultRsp, uint8 seqNum );
- extern ZStatus_t zclGeneral_KeyEstablish_Send_EphemeralDataRsp( uint8 srcEP, afAddrType_t *dstAddr,
- uint8 *eData,
- uint8 disableDefaultRsp, uint8 seqNum );
- extern ZStatus_t zclGeneral_KeyEstablish_Send_ConfirmKeyRsp( uint8 srcEP, afAddrType_t *dstAddr,
- uint8 *mac,
- uint8 disableDefaultRsp, uint8 seqNum );
- extern ZStatus_t zclGeneral_KeyEstablishment_ECDSASign( uint8 *input, uint8 inputLen,
- uint8 *output);
- extern ZStatus_t zclGeneral_KeyEstablishment_ECDSAVerify( uint8 *input, uint8 inputLen,
- uint8 *signature);
- extern void zclGeneral_KeyEstablishment_RegYieldCB( YieldFunc *pFnYield,
- uint8 yieldLevel );
- #ifdef __cplusplus
- }
- #endif
- #endif /* ZCL_KEY_ESTABLISH_H */
|