From b24866225a6301d3a663f874725e83c012dc25d3 Mon Sep 17 00:00:00 2001 From: Florent Duchon Date: Wed, 26 Dec 2012 17:36:00 +0100 Subject: digital/beacon: add bitcloud stack into common directory digital/zigbit --- .../APS/include/private/apsAuthenticate.h | 162 ++++++++++ .../Components/APS/include/private/apsBinding.h | 186 +++++++++++ .../Components/APS/include/private/apsCommand.h | 185 +++++++++++ .../Components/APS/include/private/apsConfig.h | 44 +++ .../APS/include/private/apsDataManager.h | 164 ++++++++++ .../stack/Components/APS/include/private/apsDbg.h | 277 +++++++++++++++++ .../Components/APS/include/private/apsEndpoint.h | 47 +++ .../Components/APS/include/private/apsFrames.h | 188 ++++++++++++ .../Components/APS/include/private/apsGroup.h | 66 ++++ .../Components/APS/include/private/apsKeyPairSet.h | 116 +++++++ .../APS/include/private/apsMemoryManager.h | 340 +++++++++++++++++++++ .../APS/include/private/apsRejectDuplicate.h | 47 +++ .../APS/include/private/apsRemoveDevice.h | 61 ++++ .../Components/APS/include/private/apsRequestKey.h | 80 +++++ .../stack/Components/APS/include/private/apsSkke.h | 225 ++++++++++++++ .../APS/include/private/apsSkkeInitiator.h | 61 ++++ .../APS/include/private/apsSkkeResponder.h | 60 ++++ .../Components/APS/include/private/apsSmSsp.h | 80 +++++ .../Components/APS/include/private/apsState.h | 152 +++++++++ .../Components/APS/include/private/apsSwitchKey.h | 61 ++++ .../APS/include/private/apsTaskManager.h | 68 +++++ .../APS/include/private/apsTransportAppKey.h | 84 +++++ .../APS/include/private/apsTransportKey.h | 118 +++++++ .../APS/include/private/apsTransportNwkKey.h | 130 ++++++++ .../APS/include/private/apsTransportTrustKey.h | 83 +++++ .../APS/include/private/apsUpdateDevice.h | 64 ++++ 26 files changed, 3149 insertions(+) create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/private/apsAuthenticate.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/private/apsBinding.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/private/apsCommand.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/private/apsConfig.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/private/apsDataManager.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/private/apsDbg.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/private/apsEndpoint.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/private/apsFrames.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/private/apsGroup.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/private/apsKeyPairSet.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/private/apsMemoryManager.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/private/apsRejectDuplicate.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/private/apsRemoveDevice.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/private/apsRequestKey.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/private/apsSkke.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/private/apsSkkeInitiator.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/private/apsSkkeResponder.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/private/apsSmSsp.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/private/apsState.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/private/apsSwitchKey.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/private/apsTaskManager.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/private/apsTransportAppKey.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/private/apsTransportKey.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/private/apsTransportNwkKey.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/private/apsTransportTrustKey.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/private/apsUpdateDevice.h (limited to 'digital/zigbit/bitcloud/stack/Components/APS/include/private') diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsAuthenticate.h b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsAuthenticate.h new file mode 100644 index 00000000..2ca82e02 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsAuthenticate.h @@ -0,0 +1,162 @@ +/**************************************************************************//** + \file apsAuthenticate.h + + \brief Private interface of APS Authentication. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 2010-12-18 Max Gekk - Created. + Last change: + $Id: apsAuthenticate.h 17813 2011-07-04 14:11:12Z dloskutnikov $ + ******************************************************************************/ +#if !defined _APS_AUTHENTICATE_H +#define _APS_AUTHENTICATE_H + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include +#include +#if defined _SECURITY_ && defined _LINK_SECURITY_ +#include +#include + +/****************************************************************************** + Types section + ******************************************************************************/ +BEGIN_PACK +/** Type of entity authentication initiator or responder challenge frame. */ +typedef struct PACK _ApsAuthChallengeFrame_t +{ + ApduCommandHeader_t header; + /** The KeyType field is 1 octet in length and shall be set to one of + * the non-reserved values in Table 4.35. See ZigBee spec r19, 4.4.9.7.1.2.1, + * page 485 and 4.4.9.7.2.2.1, page 486. Valid values: + * \li 0x00 - Active network key. + * \li 0x01 - Link key shared between initiator and responder. + * \note Value 0x01 is not supported. */ + uint8_t keyType; + /** The KeySeqNumber sub-field shall be set to the key sequence number of + * the active network key. See ZigBee spec r19, 4.4.9.7.1.2.2, page 485 + * and 4.4.9.7.2.2.2, page 486. */ + uint8_t keySeqNumber; + /** The initiator field shall be set to the 64-bit extended address of + * the device that acts as the initiator of the scheme. See ZigBee spec r19, + * 4.4.9.7.1.3, page 485 and 4.4.9.7.2.3, page 486. */ + uint8_t initiator[sizeof(ExtAddr_t)]; + /** The responder field shall be set to the 64-bit extended address of + * the device that acts as the responder to the scheme. See ZigBee spec r19, + * 4.4.9.7.1.4, page 485 and 4.4.9.7.2.4, page 486. */ + uint8_t responder[sizeof(ExtAddr_t)]; + /** The challenge field shall be the octet representation of the challenge QEU + * generated by the initiator during action step 1 of sub-clause B.8.1. + * See ZigBee spec r19, 4.4.9.7.1.5, page 485 and 4.4.9.7.2.5, page 486. */ + uint8_t challenge[CHALLENGE_SEQUENCE_SIZE]; +} ApsAuthChallengeFrame_t; + +/** Type of entity authentication MAC and data frame. */ +typedef struct PACK _ApsAuthMACandDataFrame_t +{ + ApduCommandHeader_t header; + /** The MAC field shall be the octet representation of the string MacTag2 + * (MacTag1) generated by the initiator (responder) during action step 4 (8) + * of sub-clause B.8.1 (B.8.2). See ZigBee Specification r19, 4.4.9.7.3.2, + * page 487 and 4.4.9.7.4.2, page 488. */ + uint8_t mac[HASH_SIZE]; + /** The DataType field shall be set to 0x00 to indicate the frame counter + * associated with the active network key. ZigBee spec r19, 4.4.9.7.3.3. */ + uint8_t dataType; + /** The Data field shall be octet representation of the string Text2 or Text1, + * i.e. the frame counter associated with the active network key. See ZigBee + * Specification r19, 4.4.9.7.3.4, page 487 and 4.4.9.7.4.4, page 488. */ + uint32_t data; +} ApsAuthMACandDataFrame_t; +END_PACK + +/** Values of keyType subfield. See ZigBee spec r19, Table 4.35. */ +typedef enum _ApsAuthChallengeKeyType_t +{ + APS_AUTH_ACTIVE_NETWORK_KEY_TYPE = 0x00, + APS_AUTH_LINK_KEY_TYPE = 0x01 +} ApsAuthChallengeKeyType_t; + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/**************************************************************************//** + \brief Main task handler of the authentication component. + ******************************************************************************/ +APS_PRIVATE void apsAuthReqTaskHandler(void); + +#if defined _HI_SECURITY_ +/**************************************************************************//** + \brief Reset all internal queues and variables of authentication component. + ******************************************************************************/ +APS_PRIVATE void apsAuthReset(void); + +/**************************************************************************//** + \brief Entity authentication challenge was received from responder. + + Find original APSME-AUTHENTICATE.request and perform steps 4 and 5 + from ZigBee Specification r19, section B.8.1, page 540. + + \param[in] commandInd - parameters of the received command. + \return 'true' if memory for NWK_DataInd_t is unused by authentic component. + ******************************************************************************/ +APS_PRIVATE +bool apsAuthInitiatorChallengeInd(const ApsCommandInd_t *const commandInd); + +/**************************************************************************//** + \brief Entity authentication challenge was received from initiator. + + \param[in] commandInd - pointer to parameters of received authentication frame. + \return 'true' if memory for NWK_DataInd_t is unused by authentic component. + ******************************************************************************/ +APS_PRIVATE +bool apsAuthResponderChallengeInd(const ApsCommandInd_t *const commandInd); + +/**************************************************************************//** + \brief Entity authentication MAC and Data was received from initiator. + + \param[in] commandInd - pointer to parameters of received authentication frame. + \return 'true' if memory for NWK_DataInd_t is unused by authentic component. + ******************************************************************************/ +APS_PRIVATE +bool apsAuthResponderMACandDataInd(const ApsCommandInd_t *const commandInd); + +/**************************************************************************//** + \brief Entity authentication MAC and Data was received from responder. + + \param[in] commandInd - pointer to parameters of received authentication frame. + \return 'true' if memory for NWK_DataInd_t is unused by authentic component. + ******************************************************************************/ +APS_PRIVATE +bool apsAuthInitiatorMACandDataInd(const ApsCommandInd_t *const commandInd); + +#else /* not _HI_SECURITY_ */ + +#define apsAuthReset() (void)0 +#endif /* _HI_SECURITY_ */ + +#else +#define apsAuthReqTaskHandler NULL +#endif /* _SECURITY_ and _LINK_SECURITY_ */ + + +#if !defined _HI_SECURITY_ || !defined _SECURITY_ || !defined _LINK_SECURITY_ + +#define apsAuthInitiatorChallengeInd NULL +#define apsAuthResponderChallengeInd NULL +#define apsAuthResponderMACandDataInd NULL +#define apsAuthInitiatorMACandDataInd NULL +#endif +#endif /* _APS_AUTHENTICATE_H */ +/** eof apsAuthenticate.h */ + diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsBinding.h b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsBinding.h new file mode 100644 index 00000000..e89d02b0 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsBinding.h @@ -0,0 +1,186 @@ +/**************************************************************************//** + \file apsBinding.h + + \brief Private interface of APS binding. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 2010-10-05 Max Gekk - Created. + Last change: + $Id: apsBinding.h 17448 2011-06-09 13:53:59Z ataradov $ + ******************************************************************************/ +#if !defined _APS_BINDING_H +#define _APS_BINDING_H + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include +#include +#include +#include + +#if defined _BINDING_ +/****************************************************************************** + Define(s) section + ******************************************************************************/ +#define ACTIVE_BINDING_ENTRY_STATUS APS_INVALID_BINDING_STATUS +#define ACTIVATE_BINDING_ENTRY(entry) \ + (entry)->confirm.status = ACTIVE_BINDING_ENTRY_STATUS + +/****************************************************************************** + Types section + ******************************************************************************/ +/** Size of the binding table. */ +typedef uint8_t ApsBindingTableSize_t; +/** Type of a binding table index. */ +typedef ApsBindingTableSize_t ApsBindIndex_t; + +/** Type of the binding table. */ +typedef struct _ApsBindingTable_t +{ + /* Total amount of binding entries. */ + ApsBindingTableSize_t size; + /* Array of binding entries. */ + ApsBindingEntry_t *entry; +} ApsBindingTable_t; + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/**************************************************************************//** + \brief Reset the binding table and initialize it. + + \param[in] powerFailureControl - stack restoring after power failure control bitfield; + affects on initialization procedure. + \return None. + ******************************************************************************/ +APS_PRIVATE void apsResetBindingTable(const NWK_PowerFailureControl_t powerFailureControl); + +/**************************************************************************//** + \brief Allocate a place in the binding table for new entry. + + \param[in] req - pointer to request's parameters: source and destination + addresses, cluster identifier and etc. See APS_BindReq_t. + \return Pointer to new binding entry or NULL. + ******************************************************************************/ +APS_PRIVATE ApsBindingEntry_t* apsAllocBindingEntry(APS_BindReq_t *const req); + +/**************************************************************************//** + \brief Free allocated binding entry. + + \param[in] entry - pointer to valid entry in the binding table. + + \return None. + ******************************************************************************/ +APS_PRIVATE void apsFreeBindingEntry(ApsBindingEntry_t *const entry); + +/**************************************************************************//** + \brief Get pointer to next binding entry. + + \code Example: + ApsBindingEntry_t *entry = NULL; + + while (NULL != (entry = apsNextBind(entry, cluster, endpoint, addr))) + { + if (APS_GROUP_ADDRES == entry->dstAddrMode) + if (dstGroup == entry->dst.group) + // send message to group + ... + } + \endcode + + \param[in] entry - pointer to previous binding entry + or NULL if it's initial call. + \param[in] clusterId - cluster identifier of next bind link. + \param[in] endpoint - endpoint number of next binding entry. + \param[in] extAddr - pointer to source IEEE address of next entry. + + \return if next binding entry is found then return valid entry pointer + otherwise return NULL. + ******************************************************************************/ +APS_PRIVATE ApsBindingEntry_t* apsNextBind(ApsBindingEntry_t *entry, + const ClusterId_t clusterId, const Endpoint_t endpoint, + const ExtAddr_t *const extAddr); + +/**************************************************************************//** + \brief Find entry by bind request in the binding table. + + This function initializes the status field to APS_SUCCESS_STATUS + if entry is found otherwise it writes APS_INVALID_PAREMETER_STATUS. + + \param[in] req - bind or unbind request's parameters. + \parap[in] errorStatus - return this status if an entry is not found. + + \return Pointer to an entry in the binding table or NULL. + ******************************************************************************/ +APS_PRIVATE ApsBindingEntry_t* apsFindBindingEntry(APS_BindReq_t *const req, + const APS_Status_t errorStatus); + +/**************************************************************************//** + \brief Is APS already bound or not? + + It always writes APS_SUCCESS_STATUS to the status field + of APSME-BIND.confirm. + + \param[in] req - bind or unbind request's parameters. + + \return true is APS is not bound with given parameters otherwise false. + ******************************************************************************/ +APS_PRIVATE bool apsIsNotBound(APS_BindReq_t *const req); + +/**************************************************************************//** + \brief Copy binding information to the binding table. + + \param[in] entry - pointer to an entry in the binding table. + \param[in] req - pointer to bind request's parameters. + + \return None. + ******************************************************************************/ +APS_PRIVATE void apsCopyBindingInfo(ApsBindingEntry_t *const entry, + APS_BindReq_t *const req); + +/**************************************************************************//** + \brief Check binding to any group from given source endpoint. + + \param[in] clusterId - cluster identifier of group binding link + \param[in] srcEndpoint - source endpoint of group binding link. + + \return true if group bind link is found otherwise return false. + ******************************************************************************/ +APS_PRIVATE bool apsIsBoundToAnyGroup(const ClusterId_t clusterId, + const Endpoint_t srcEndpoint); + +/**************************************************************************//** + \brief Find bind link and try to send to bound devices. + + \param[in] apsDataReq - pointer to initial APSDE-DATA.request's parameters. + \param[in] buffer - allocated buffer for internal transmission parameters. + + \return APS_SUCCESS_STATUS if transmission is successfully. + ******************************************************************************/ +APS_PRIVATE APS_Status_t apsProcessIndirectDataReq(APS_DataReq_t *const apsDataReq, + ApsDataBuffer_t *const buffer); + +/**************************************************************************//** + \brief Find next bound device and try to send to it. + + \param[in] apsDataReq - pointer to initial APSDE-DATA.request's parameters. + \param[in] buffer - allocated buffer for internal transmission parameters. + + \return APS_SUCCESS_STATUS if transmission is successfully. + ******************************************************************************/ +APS_PRIVATE APS_Status_t apsSendToNextBoundDevice(APS_DataReq_t *const apsDataReq, + ApsDataBuffer_t *const buffer); + +#endif /* _BINDING_ */ +#endif /* _APS_BINDING_H */ +/** eof apsBinding.h */ + diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsCommand.h b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsCommand.h new file mode 100644 index 00000000..eb641c57 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsCommand.h @@ -0,0 +1,185 @@ +/**************************************************************************//** + \file apsCommand.h + + \brief Internal interface of APS command transmission. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 2011-02-19 Max Gekk - Created. + Last change: + $Id: apsCommand.h 17813 2011-07-04 14:11:12Z dloskutnikov $ + ******************************************************************************/ +#if !defined _APS_COMMAND_H +#define _APS_COMMAND_H + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include +#include +#include + +/****************************************************************************** + Definitions section + ******************************************************************************/ +/** Returns pointer to command payload */ +#define APS_GET_COMMAND_PAYLOAD(req) \ + ((req)->service.allocateReq.confirm.nwkDataReq->nsdu) +/** Returns pointer to NWK_DataReq, associated with command */ +#define APS_GET_ALLOCATED_COMMAND_BUFFER(req) \ + ((req)->service.allocateReq.confirm.nwkDataReq) +/** Returns command payload length */ +#define APS_GET_COMMAND_PAYLOAD_LENGTH(req) \ + ((req)->service.allocateReq.nsduLength) + +#ifdef _LINK_SECURITY_ +/** APS command auxiliary header length */ +#define APS_COMMAND_AUXILIARY_HEADER_LENGTH \ + (SSP_SECURITY_CONTROL_FIELD_LENGTH + SSP_FRAME_COUNTER_FIELD_LENGTH) +/** APS command security fields size */ +#define APS_COMMAND_SECURITY_FIELDS_SIZE \ + (APS_COMMAND_AUXILIARY_HEADER_LENGTH + APS_MAX_DATA_FRAME_FOOTER_LENGTH) +#endif /* _LINK_SECURITY_ */ + + +/****************************************************************************** + Types section + ******************************************************************************/ +/** Indicated command descriptor */ +typedef struct _ApsCommandInd_t +{ + /** Pointer to first octet of unaligned source extended address. */ + const ExtAddr_t *srcExtAddr; + /** Pointer to NLDE-DATA.indication parameters of the received command. */ + NWK_DataInd_t *nwkDataInd; + /* Type of key with the received command was secured. */ + APS_Status_t securityStatus; +} ApsCommandInd_t; + +/* Command identifier values are shown in Table 4.34 of ZigBee spec r19. */ +typedef enum _ApsCommandId_t +{ + APS_CMD_MIN_ID = 0x01, + APS_CMD_SKKE_1_ID = APS_CMD_MIN_ID, + APS_CMD_SKKE_2_ID = 0x02, + APS_CMD_SKKE_3_ID = 0x03, + APS_CMD_SKKE_4_ID = 0x04, + APS_CMD_TRANSPORT_KEY_ID = 0x05, + APS_CMD_UPDATE_DEVICE_ID = 0x06, + APS_CMD_REMOVE_DEVICE_ID = 0x07, + APS_CMD_REQUEST_KEY_ID = 0x08, + APS_CMD_SWITCH_KEY_ID = 0x09, + APS_CMD_EA_INIT_CHLNG_ID = 0x0a, + APS_CMD_EA_RSP_CHLNG_ID = 0x0b, + APS_CMD_EA_INIT_MAC_DATA_ID = 0x0c, + APS_CMD_EA_RSP_MAC_DATA_ID = 0x0d, + APS_CMD_TUNNEL_ID = 0x0e, + APS_CMD_MAX_ID = APS_CMD_TUNNEL_ID +} ApsCommandId_t; + +BEGIN_PACK +typedef struct PACK _ApduCommandBaseHeader_t +{ + ApduFrameControlField_t frameControl; + uint8_t apsCounter; +} ApduCommandBaseHeader_t; + +typedef struct PACK _ApduCommandHeader_t +{ + ApduFrameControlField_t frameControl; + uint8_t apsCounter; + uint8_t commandId; +} ApduCommandHeader_t; +END_PACK + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +#if defined _SECURITY_ +/**************************************************************************//** + \brief Initialization of ApsCommandReq_t structure by default values. + + Following fields will be initialized: + \li nwkSecurity and apsSecurity to true + \li keyIdentifier to SSP_DATA_KEY_ID + \li extendedNonce to false + \li other fields to zero. + + \param[in] commandReq - pointer to request's parameters to APS command trasmission. + \return None. + ******************************************************************************/ +APS_PRIVATE void apsSetCommandReqToDefault(ApsCommandReq_t *const commandReq); + +/**************************************************************************//** + \brief Module reset routine. + + \return None. + ******************************************************************************/ +APS_PRIVATE void apsCommandReset(void); + +/**************************************************************************//** + \brief Prepare command frame header. + + \param[out] header - pointer to memory to place header in. + \param[in] commandId - command identifier. + + \return None. + ******************************************************************************/ +APS_PRIVATE +void apsCommandMakeHeader(ApduCommandHeader_t *header, ApsCommandId_t commandId); + +/**************************************************************************//** + \brief APS Command task handler. + ******************************************************************************/ +APS_PRIVATE void apsCommandReqTaskHandler(void); + +/**************************************************************************//** + \brief Request to allocate memory for APS command and send it. + + \param[in] commandReq - pointer to request's parameters to APS command trasmission. + \return None. + ******************************************************************************/ +APS_PRIVATE void apsCommandReq(ApsCommandReq_t *const commandReq); + +/**************************************************************************//** + \brief Process an incoming command frame. + + \param[in] ind - pointer to NWK data indication structure. + + \return True, if memory buffer can be released; false - otherwise. + ******************************************************************************/ +APS_PRIVATE bool apsCommandInd(NWK_DataInd_t *ind); + +/**************************************************************************//** + \brief Handler of decrypted or unsecured incoming commands. + + \param[in] ind - pointer to data indication structure. + \param[in] securityStatus - type of key with the transport key command + was secured. + + \return True, if memory buffer can be released; false - otherwise. + ******************************************************************************/ +bool apsUnsecuredNwkDataIndHandler(NWK_DataInd_t *const ind, + const ExtAddr_t *srcExtAddr, const APS_Status_t securityStatus); + +/**************************************************************************//** + \brief Prepared command transmission routine. + + \param[in] req - command request pointer. + + \return None. + ******************************************************************************/ +APS_PRIVATE void apsCommandNwkDataReq(ApsCommandReq_t *const req); + +#else +#define apsCommandReqTaskHandler NULL +#endif /* _SECURITY_ */ +#endif /* _APS_COMMAND_H */ +/** eof apsCommand.h */ diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsConfig.h b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsConfig.h new file mode 100644 index 00000000..605ac055 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsConfig.h @@ -0,0 +1,44 @@ +/**************************************************************************//** + \file apsConfig.h + + \brief Configuration constants and definitions of APS layer. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 2011-07-03 Max Gekk - Created. + Last change: + $Id: apsConfig.h 17801 2011-07-04 08:55:01Z mgekk $ +******************************************************************************/ +#if !defined _APS_CONFIG_H +#define _APS_CONFIG_H + +/****************************************************************************** + Definitions section + ******************************************************************************/ +/* Rejection table timeouts counted in 500ms intervals. + * So we can use narrow data types. */ +#define APS_DUPLICATE_REJECTION_INTERVAL 512U + +#ifdef _APS_FRAGMENTATION_ + #if defined _CERTIFICATION_ + #define APS_INTERFRAME_DELAY (10*HAL_APPTIMERINTERVAL) + #else + #define APS_INTERFRAME_DELAY (HAL_APPTIMERINTERVAL) + #endif +#endif + +/* Random delay for retransmission to decrease amount of collisions */ +#define RETRANSMISSION_RANDOM_DELAY_RANGE 0x1ff + +#define RETRANSMISSION_DELAY_WITH_NO_PHY_ACK 1000U + +#endif /* _APS_CONFIG_H */ +/** eof apsConfig.h */ + diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsDataManager.h b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsDataManager.h new file mode 100644 index 00000000..510a55b0 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsDataManager.h @@ -0,0 +1,164 @@ +/*************************************************************************//** + \file apsDataManager.h + + \brief APS Data Manager header file + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 06/06/07 A. Potashov - Created. +*****************************************************************************/ + + +#ifndef _APS_DATAMANAGER_H +#define _APS_DATAMANAGER_H + +/****************************************************************************** + Includes section +******************************************************************************/ +#include +#include +#include +#include +#include +#include + +/****************************************************************************** + Types section +******************************************************************************/ +typedef enum _ApsFragmentationState_t +{ + APS_FRAG_WAITING_BLOCK_0, + APS_FRAG_WAITING_NEXT_BLOCK, + APS_FRAG_SENDING_ACK, + APS_FRAG_SENDING_LAST_ACK +} ApsFragmentationState_t; + +typedef enum _ApsTransmittedDataHandlerState_t +{ + START_DATA_HANDLING_STATE, + DATA_DECRYPTION_STATE, + SEND_DATA_TO_BOUND_DEVICES_STATE, + FINISH_DATA_HANDLING_STATE +} ApsTransmittedDataHandlerState_t; + +/****************************************************************************** + Prototypes section +******************************************************************************/ + +/***************************************************************************** + Make a reset of APS Data Manager + Parameters: fullReset - reset all internal variables of APS-layer or not. + Returns: None +*****************************************************************************/ +APS_PRIVATE void apsResetDataManager(const bool fullReset); + + +/***************************************************************************** + APS Stop Event Handler + Parameters: options - options field APS_StopReq value + Returns: None +******************************************************************************/ +APS_PRIVATE void apsStopDataManager(void); + +/***************************************************************************** + APS Data Manager Process function + Parameters: None + Returns: None +*****************************************************************************/ +APS_PRIVATE void apsDataTaskHandler(void); + +/***************************************************************************** + APS Data Manager apsCounter get function + Parameters: None + Returns: apsCounter value +*****************************************************************************/ +APS_PRIVATE uint8_t apsGetApsCounter(void); + +/***************************************************************************** + Routine for IEEE addressing. NWK address by Extended 64-bit address + mapping function. + Parameters: extAddr - extended 64-bit IEEE address pointer + Returns: valid unicast NWK short address pointer + NULL in other case +*****************************************************************************/ +APS_PRIVATE const ShortAddr_t *apsFindShortByExt(const ExtAddr_t *const extAddr); + +APS_PRIVATE void apsMakeNwkDataResp(NWK_DataInd_t *ind); + +APS_PRIVATE void apsDmHotReset(void); + +/**************************************************************************//*** + \brief Further processing of frame which have been indicated from NWK, + passed initial checkings and optionally was decrypted. + + \param nwkInd - NLDE-DATA.indication primitive pointer. + securityStatus - securityStatus field value should be used in + APS_DataInd primitive. + \return true - if the NWK Data Response needs to be executed for this + indication, false - in other case. +*******************************************************************************/ +APS_PRIVATE bool apsContinueNwkDataIndProcessing(NWK_DataInd_t *nwkDataInd, + APS_Status_t securityStatus); + +/***************************************************************************** + APSDE-DATA.request with Short Addressing Mode process function + Parameters: apsDataReq - APS_DataReq will be process + nwkDataReqMem - buffer for NWK_DataReq + Returns: APS_Status_t - status of operation +*****************************************************************************/ +APS_PRIVATE APS_Status_t apsProcessShortAddrModeDataReq(APS_DataReq_t *apsDataReq, + ApsDataBuffer_t *buffer); + +/***************************************************************************** + \brief Prepare and call NLDE-DATA.request primitive. + + \param[in] req - pointer to NLDE-DATA.request's parameters. + \return None. + *****************************************************************************/ +APS_PRIVATE void apsSendNwkDataReq(NWK_DataReq_t *req); + +/***************************************************************************** + \brief Main APS Handler of NLDE-DATA.confirm. + + \param[in] conf - pointer to NLDE-DATA.confirm's parameters. + \return None. + *****************************************************************************/ +APS_PRIVATE void apsDataManagerNwkDataConf(NWK_DataConf_t *conf); + +/**************************************************************************//** + \brief Recalculates transmission timeouts. + + \param transmission radius + \return APS Ack timeout + ******************************************************************************/ +APS_PRIVATE uint32_t apsCalculateApsAckTimeout(uint8_t radius); + +#if defined _SECURITY_ && defined _LINK_SECURITY_ +/*************************************************************************//** + \brief Frame encryption is finished + + \param buffer - buffer wich was encrypted + \param status - status of operation + \return none +*****************************************************************************/ +APS_PRIVATE void apsEncryptDataFrameConf(ApsDataBuffer_t *buffer, uint8_t* pdu, + uint8_t pduLength, uint8_t status); + +/***************************************************************************** + Indicates that sent frame which was previously encrypted is decrypted. + Parameters: buffer - APS memory buffer pointer. + Returns: None +*****************************************************************************/ +APS_PRIVATE void apsDecryptSentFrameConf(ApsDataBuffer_t *buffer); +#endif /* _SECURITY_ and _LINK_SECURITY_ */ + +#endif //#ifndef _APSDATAMANAGER_H +//eof apsDataManager.h + diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsDbg.h b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsDbg.h new file mode 100644 index 00000000..c37e86c3 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsDbg.h @@ -0,0 +1,277 @@ +/**************************************************************************//** + \file apsDbg.h + + \brief Constants for APS debugging and tracing. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 2007-11-09 A. Potashov - Created. + 2010-10-21 M. Gekk - Refactoring. + Last change: + $Id: apsDbg.h 18124 2011-08-02 13:20:14Z mgekk $ + ******************************************************************************/ +#if !defined _APS_DBG_H +#define _APS_DBG_H + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include + +/****************************************************************************** + Types section + ******************************************************************************/ +/** APS assert code. Range 0x4000 - 0x4FFF. */ +typedef enum _ApsDbgCode_t +{ + APSTASKMANAGER_TASKHANDLER_0 = 0x4400, + + APSBINDING_ISVALIDBINDINGPARAMETERS_0 = 0x4410, + APSBINDING_ISVALIDBINDINGPARAMETERS_1 = 0x4411, + APSBINDING_ISBOUNDTOANYGROUP_0 = 0x4412, + APSBINDING_PROCESSINDIRECTDATAREQ_0 = 0x4413, + APSBINDING_SENDTONEXTBOUNDDEVICE_0 = 0x4414, + + APSBINDINGTABLE_ALLOCBINDINGENTRY_0 = 0x4420, + APSBINDINGTABLE_FREEBINDINGENTRY_0 = 0x4421, + APSBINDINGTABLE_FREEBINDINGENTRY_1 = 0x4422, + APSBINDINGTABLE_NEXTBIND_0 = 0x4423, + APSBINDINGTABLE_NEXTBIND_1 = 0x4424, + APSBINDINGTABLE_FINDBINDINGENTRY_0 = 0x4425, + APSBINDINGTABLE_FINDBINDINGENTRY_1 = 0x4426, + APSBINDINGTABLE_COPYBINDINGINFO_0 = 0x4427, + APSBINDINGTABLE_COPYBINDINGINFO_1 = 0x4428, + APSBINDINGTABLE_RESETBINDINGTABLE_0 = 0x4429, + + APSGROUP_APSGROUPINDICATION_0 = 0x4430, + APSGROUP_APSGROUPINDICATION_1 = 0x4431, + APSGROUP_APSGROUPINDICATION_2 = 0x4432, + + APSDATAMANAGER_PROCESSFRAGMENTEDRECEIVE_0 = 0x4440, + APSDATAMANAGER_RESETDUPLICATEREJECTIONTABLE_0 = 0x4441, + APSDATAMANAGER_DMHOTRESET_0 = 0x4442, + APSDATAMANAGER_DMHOTRESET_1 = 0x4443, + APSDATAMANAGER_MAKENWKDATARESP_0 = 0x4444, + APSDATAMANAGER_APDUACKHANDLER_0 = 0x4445, + APSDATAMANAGER_APDUUNICASTHANDLER_0 = 0x4446, + APSDATAMANAGER_GETACKBYDATABUFFER_0 = 0x4447, + APSDATAMANAGER_GETACKBYDATABUFFER_1 = 0x4448, + APSDATAMANAGER_NWKDATACONFPROCESS_0 = 0x4449, + APSDATAMANAGER_NWKDATACONFPROCESS_1 = 0x444A, + APSDATAMANAGER_NWKDATACONFPROCESS_2 = 0x444B, + APSDATAMANAGER_NWKDATACONFPROCESS_3 = 0x444C, + APSDATAMANAGER_NWKDATACONFPROCESS_4 = 0x444D, + APSDATAMANAGER_NWKDATACONFPROCESS_5 = 0x444E, + APSDATAMANAGER_HANDLETRANSMITTEDDATA_0 = 0x444F, + APSDATAMANAGER_APSDATAREQPROCESS_0 = 0x4450, + APSDATAMANAGER_APSPROCESSSHORTADDRMODEDATAREQ_0 = 0x4451, + APSDATAMANAGER_ACKFORFRAGMENTEDRECEIVECONFIRMHANDLER_0 = 0x4452, + APSDATAMANAGER_PROCESSFRAGMENTEDRECEIVE_1 = 0x4453, + + APSSTATEMACHINE_RESETREQ_0 = 0x4460, + APSSTATEMACHINE_STARTREQ_0 = 0x4461, + APSSTATEMACHINE_STOPREQ_0 = 0x4462, + APSSTATEMACHINE_PROCESSEVENT_0 = 0x4463, + APSSTATEMACHINE_TASKHANDLER_0 = 0x4464, + APSSTATEMACHINE_TASKHANDLER_1 = 0x4465, + APSSTATEMACHINE_NWKRESETCONF_0 = 0x4466, + APSSTATEMACHINE_NWKRESETCONF_1 = 0x4467, + APSSTATEMACHINE_NWKRESETCONF_2 = 0x4468, + APSSTATEMACHINE_NWKRESETCONF_3 = 0x4469, + APSSTATEMACHINE_PROCESSSTARTEVENT_0 = 0x446A, + APSSTATEMACHINE_APSSTOPCONF_0 = 0x446B, + APSSTATEMACHINE_COMPLETESTOP_0 = 0x446C, + APSSTATEMACHINE_COMPLETESTOP_1 = 0x446D, + APSSTATEMACHINE_COMPLETESTOP_2 = 0x446E, + + APSGROUPTABLE_APSADDGROUPREQ0 = 0x4470, + APSGROUPTABLE_APSREMOVEGROUPREQ0 = 0x4471, + APSGROUPTABLE_APSREMOVEALLGROUPSREQ0 = 0x4472, + + APSMEMORYMANAGER_GETBUFFER_0 = 0x4480, + APSMEMORYMANAGER_GETBUFFER_1 = 0x4481, + APSMEMORYMANAGER_FREEBUFFER_0 = 0x4482, + APSMEMORYMANAGER_FREEBUFFER_1 = 0x4483, + APSMEMORYMANAGER_FREEBUFFER_2 = 0x4484, + APSMEMORYMANAGER_FREEBUFFER_3 = 0x4485, + APSMEMORYMANAGER_FREESECBUFFER_0 = 0x4486, + APSMEMORYMANAGER_APSFREEBUFFER_0 = 0x4487, + APSMEMORYMANAGER_APSGETSECBUFFER_0 = 0x4488, + + APSSECURITYMANAGER_DECRYPTEDCOMMANDRECEIVEPROCESS_0 = 0x4490, + APSSMEKREQ_SMEKREQNWKDATAIND_0 = 0x44A0, + + APSSMEKRESP_EKRESPSKKENWKCONF_0 = 0x44B0, + APSSMEKRESP_ESTABLISHKEYRESP_0 = 0x44B1, + + APSSMSKR_SENDSKC_0 = 0x44C0, + APSSMTKR_SENDTKC_0 = 0x44D0, + + APSSMSSP_SMSENDENCRYPTCONF_0 = 0x4500, + APSSMSSP_SMSSPPROCESS_0 = 0x4501, + APSSMSSP_SMSSPPROCESS_1 = 0x4502, + APSSMSSP_SMDECRYPTSENTFRAMECONF_0 = 0x4503, + APSSMSSP_DECRYPTANYFRAME_0 = 0x4504, + + APSTUNNEL_NWKDATAIND_0 = 0x4510, + APSTUNNEL_SENDEMBEDDEDCOMMANDCONF_0 = 0x4511, + APSTUNNEL_TRANSPORTKEYREQ_0 = 0x4512, + APSTUNNEL_TRANSPORTKEYREQ_1 = 0x4513, + + APSKEYPAIRSET_EXTRACTOUTSECCOUNTER_0 = 0x4520, + APSKEYPAIRSET_GETINFRAMECOUNTER_0 = 0x4521, + APSKEYPAIRSET_ALLOCKEYPAIR_0 = 0x4522, + APSKEYPAIRSET_SETOUTFRAMECOUNTER_0 = 0x4523, + APSKEYPAIRSET_SETINFRAMECOUNTER_0 = 0x4524, + APSKEYPAIRSET_GETKEYPAIRDEVICEADDRESS_0 = 0x4525, + + APSINTERPAN_INTRPDATAREQ_0 = 0x4540, + APSINTERPAN_INTRPDATAREQ_1 = 0x4541, + APSINTERPAN_INTRPDATAREQ_2 = 0x4542, + APSINTERPAN_INTERPANMACDATACONF_0 = 0x4543, + APSINTERPAN_INTERPANMACDATACONF_1 = 0x4544, + APSINTERPAN_NWKINTRPDATAIND_0 = 0x4545, + + APSAUTHENTICATE_AUTHENTICATEREQ_0 = 0x4550, + APSAUTHENTICATE_AUTHENTICATECONF_0 = 0x4551, + APSAUTHENTICATE_AUTHREQTASKHANDLER_0 = 0x4552, + APSAUTHENTICATE_APSAUTHREQTASKHANDLER_0 = 0x4552, + APSAUTHENTICATE_ALLOCNWKDATACONF_0 = 0x4553, + APSAUTHENTICATE_ALLOCNWKDATACONF_1 = 0x4554, + APSAUTHENTICATE_AUTHCHALLENGENWKCONF_0 = 0x4555, + APSAUTHENTICATE_AUTHINITIATORMACTAG2CONF_0 = 0x4556, + APSAUTHENTICATE_ALLOCMACANDDATAFRAMECONF_0 = 0x4557, + APSAUTHENTICATE_ALLOCMACANDDATAFRAMECONF_1 = 0x4558, + APSAUTHENTICATE_AUTHMACANDDATANWKCONF_0 = 0x4559, + APSAUTHENTICATE_APSAUTHRESPONDERMACTAG2CONF_0 = 0x455A, + APSAUTHENTICATE_STARTAUTHTIMER_0 = 0x455B, + APSAUTHENTICATE_AUTHENTICATEREQ_1 = 0x455C, + + APSCOMMAND_COMMANDREQ_0 = 0x4560, + APSCOMMAND_COMMANDREQTASKHANDLER_0 = 0x4561, + APSCOMMAND_COMMANDREQTASKHANDLER_2 = 0x4562, + APSCOMMAND_COMMANDALLOCDATACONF_0 = 0x4563, + APSCOMMAND_COMMANDALLOCDATACONF_1 = 0x4564, + APSCOMMAND_COMMANDENCRYPTCONF_0 = 0x4565, + APSCOMMAND_COMMANDENCRYPTCONF_1 = 0x4566, + APSCOMMAND_COMMANDENCRYPTCONF_2 = 0x4567, + APSCOMMAND_NWKDATAREQ_0 = 0x4568, + APSCOMMAND_NWKDATAREQ_1 = 0x4569, + APSCOMMAND_NWKDATACONF_0 = 0x456A, + APSCOMMAND_UNSECUREDNWKDATAINDHANDLER_0 = 0x456B, + + APSUPDATEDEVICE_UPDATEDEVICEREQ_0 = 0x4570, + APSUPDATEDEVICE_PREPAREUPDATEDEVICECOMMAND_0 = 0x4571, + APSUPDATEDEVICE_CONFIRMUPDATEDEVICECOMMAND_0 = 0x4572, + APSUPDATEDEVICE_UPDATEDEVICEIND_0 = 0x4573, + + APSREMOVEDEVICE_REMOVEDEVICEREQ_0 = 0x4580, + APSREMOVEDEVICE_REMOVEDEVICEPREPARE_0 = 0x4581, + APSREMOVEDEVICE_REMOVEDEVICECONF_0 = 0x4582, + APSREMOVEDEVICE_REMOVEDEVICEIND_0 = 0x4583, + + APSSWITCHKEY_SWITCHKEYREQ_0 = 0x4590, + APSSWITCHKEY_SWITCHKEYPREPARE_0 = 0x4591, + APSSWITCHKEY_SWITCHKEYCONF_0 = 0x4592, + APSSWITCHKEY_SWITCHKEYIND_0 = 0x4593, + + APSSKKE_SKKEIND_0 = 0x45A0, + APSSKKE_SKKEIND_1 = 0x45A1, + APSSKKE_FORWARDSKKECOMMAND_0 = 0x45A2, + APSSKKE_SKKEFORWARDCONF_0 = 0x45A3, + APSSKKE_INITSKKEELEM_0 = 0x45A4, + APSSKKE_SETSKKETTL_0 = 0x45A5, + APSSKKE_SETSKKESTATE_0 = 0x45A6, + APSSKKE_PREPARESKKECOMMAND_0 = 0x45A7, + APSSKKE_PREPARESKKECOMMAND_1 = 0x45A8, + APSSKKE_SKKENWKDATACONF_0 = 0x45A9, + APSSKKE_FINDSKKEELEMBYNWKIND_0 = 0x45AA, + + APSSKKEINITIATOR_ESTABLISHKEYREQ_0 = 0x45B0, + APSSKKEINITIATOR_ISKKECONF_0 = 0x45B1, + APSSKKEINITIATOR_SKKEINITIATORTASKHANDLER_0 = 0x45B2, + APSSKKEINITIATOR_ISKKETASKHANDLER_1 = 0x45B3, + APSSKKEINITIATOR_ISKKE1ALLOCFRAMECONF_0 = 0x45B4, + APSSKKEINITIATOR_ISKKE1NWKCONF_0 = 0x45B5, + APSSKKEINITIATOR_INITIATORSKKE2IND_1 = 0x45B6, + APSSKKEINITIATOR_ISKKECALCPARAMSCONF_0 = 0x45B7, + APSSKKEINITIATOR_ISKKE3ALLOCFRAMECONF_0 = 0x45B8, + APSSKKEINITIATOR_ISKKE3NWKCONF_0 = 0x45B9, + APSSKKEINITIATOR_ISKKE4IND_0 = 0x45BA, + + APSSKKERESPONDER_RSKKE1IND_0 = 0x45C0, + APSSKKERESPONDER_ESTABLISHKEYRESP_0 = 0x45C1, + APSSKKERESPONDER_SKKERESPONDERTASKHANDLER_0 = 0x45C2, + APSSKKERESPONDER_RSKKECALCPARAMSCONF_0 = 0x45C3, + APSSKKERESPONDER_RSKKE2ALLOCFRAMECONF_0 = 0x45C4, + APSSKKERESPONDER_RSKKE2NWKCONF_0 = 0x45C5, + APSSKKERESPONDER_RSKKE4ALLOCFRAMECONF_0 = 0x45C6, + APSSKKERESPONDER_RSKKE4NWKCONF_0 = 0x45C7, + APSSKKERESPONDER_RSKKECONF_0 = 0x45C8, + + APSREQUESTKEY_REQUESTKEYREQ_0 = 0x45F0, + APSREQUESTKEY_PREPAREREQUESTKEYCOMMAND_0 = 0x45F1, + APSREQUESTKEY_CONFIRMREQUESTKEYCOMMAND_0 = 0x45F2, + APSREQUESTKEY_REQUESTEDKEYRECEIVED_0 = 0x45F3, + APSREQUESTKEY_REQUESTKEYIND_0 = 0x45F4, + APSREQUESTKEY_REQUESTKEYCONF_0 = 0x45F5, + + APSTRANSPORTKEY_TRANSPORTKEYREQ_0 = 0x4600, + APSTRANSPORTKEY_TRANSPORTKEYTASKHANDLER_0 = 0x4601, + APSTRANSPORTKEY_TRANSPORTKEYTASKHANDLER_1 = 0x4602, + APSTRANSPORTKEY_TRANSPORTKEYTASKHANDLER_2 = 0x4603, + APSTRANSPORTKEY_TRANSPORTKEYTASKHANDLER_3 = 0x4604, + APSTRANSPORTKEY_TRANSPORTKEYTASKHANDLER_4 = 0x4605, + APSTRANSPORTKEY_TRANSPORTKEYCONF_0 = 0x4606, + APSTRANSPORTKEY_CONFIRMTRANSPORTKEYCOMMAND_0 = 0x4607, + APSTRANSPORTKEY_TRANSPORTKEYIND_0 = 0x4608, + APSTRANSPORTKEY_FORWARDKEYTOCHILD_0 = 0x4609, + + APSTRANSPORTAPPKEY_CHECKTRANSPORTAPPKEYREQ_0 = 0x4610, + APSTRANSPORTAPPKEY_CHECKTRANSPORTAPPKEYREQ_1 = 0x4611, + APSTRANSPORTAPPKEY_CHECKTRANSPORTAPPKEYREQ_2 = 0x4612, + APSTRANSPORTAPPKEY_TRANSPORTAPPKEYCOMMAND_0 = 0x4613, + APSTRANSPORTAPPKEY_PREPARETRANSPORTAPPKEYCOMMAND_0 = 0x4614, + + APSTRANSPORTNWKKEY_CHECKTRANSPORTNWKKEYREQ_0 = 0x4620, + APSTRANSPORTNWKKEY_CHECKTRANSPORTNWKKEYREQ_1 = 0x4621, + APSTRANSPORTNWKKEY_TRANSPORTNWKKEYCOMMAND_0 = 0x4622, + APSTRANSPORTNWKKEY_PREPARETRANSPORTNWKKEYCOMMAND_0 = 0x4623, + APSTRANSPORTNWKKEY_PREPARETUNNELCOMMAND_0 = 0x4624, + APSTRANSPORTNWKKEY_PREPARETUNNELCOMMAND_1 = 0x4625, + APSTRANSPORTNWKKEY_TUNNELIND_0 = 0x4626, + APSTRANSPORTNWKKEY_SENDEMBEDDEDCOMMANDCONF_0 = 0x4627, + + APSTRANSPORTTRUSTKEY_CHECKTRANSPORTTRUSTKEYREQ_0 = 0x4630, + APSTRANSPORTTRUSTKEY_CHECKTRANSPORTTRUSTKEYREQ_1 = 0x4631, + APSTRANSPORTTRUSTKEY_CHECKTRANSPORTTRUSTKEYREQ_2 = 0x4632, + APSTRANSPORTTRUSTKEY_TRANSPORTTRUSTKEYCOMMAND_0 = 0x4633, + APSTRANSPORTTRUSTKEY_PREPARETRANSPORTTRUSTKEYCOMMAND_0 = 0x4634, + APSTRANSPORTTRUSTKEY_TRANSPORTTRUSTKEYTOCHILDCONF_0 = 0x4635, + + APSREJECTDUPLICATE_RESETDUPLICATEREJECTIONTABLE_0 = 0x4640 + +} ApsDbgCode_t; + +/** Values of system log messages */ +typedef enum _ApsLogCodeId_t +{ + LOG_APS_RESET_REQ = 0x00, + LOG_APS_NWK_DATA_IND = 0x01, + LOG_APS_NWK_DATA_CONF_SUCCESS = 0x02, + LOG_APS_NWK_DATA_CONF_FAIL = 0x03, + LOG_APS_SEND_NWK_DATA_REQ = 0x04, + LOG_APS_SEND_ACK_REQ = 0x05, + LOG_APS_MAKE_RETRANSMISSION = 0x06 +} ApsLogCodeId_t; + +#endif /* _APS_DBG_H */ +/** eof apsDbg.h */ + diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsEndpoint.h b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsEndpoint.h new file mode 100644 index 00000000..a9c8ef64 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsEndpoint.h @@ -0,0 +1,47 @@ +/**************************************************************************//** + \file apsEndpoint.h + + \brief Private interface.of APS endpoints. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 2010-10-22 Max Gekk - Created. + Last change: + $Id: apsEndpoint.h 17448 2011-06-09 13:53:59Z ataradov $ + ******************************************************************************/ +#if !defined _APS_ENDPOINT_H +#define _APS_ENDPOINT_H + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/****************************************************************************** + \brief Search the registered endpoint descriptor. + + \param[in] endpoint - valid endpoint number. + + \return Valid endpoint descriptor pointer if one found NULL - at other case. + ******************************************************************************/ +APS_PRIVATE +APS_EndpointReg_t* apsFindEndpoint(const Endpoint_t endpoint); + +/****************************************************************************** + \brief Reset queue of endpoints. + ******************************************************************************/ +APS_PRIVATE void apsResetEndpoints(void); + +#endif /* _APS_ENDPOINT_H */ +/** eof apsEndpoint.h */ + diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsFrames.h b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsFrames.h new file mode 100644 index 00000000..ab19c903 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsFrames.h @@ -0,0 +1,188 @@ +/***************************************************************************** + \file apsFrames.h + + \brief + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 16.04.2010 I.Vagulin - Created +******************************************************************************/ + + +#ifndef _APSFRAMES_H_ +#define _APSFRAMES_H_ + +#include +#include +#include +#include + +/****************************************************************************** + Define(s) section +******************************************************************************/ +#define APS_SM_KEY_SIZE 16 + +#define APS_BROADCAST_MAC_RX_ON_SHORT_ADDRESS 0xfffd + +//APDU Frame Format + +//Frame control field - ApduFrameControlField_t + +//Frame Type subfield values +#define APDU_FRAME_CONTROL_FIELD_DATA_FRAME_TYPE 0x00 +#define APDU_FRAME_CONTROL_FIELD_COMMAND_FRAME_TYPE 0x01 +#define APDU_FRAME_CONTROL_FIELD_ACK_FRAME_TYPE 0x02 +#define APDU_FRAME_CONTROL_FIELD_RESERVED_FRAME_TYPE 0x03 + +//Delivery Mode subfield values +#define APDU_FRAME_CONTROL_FIELD_UNICAST_MODE 0x00 +#define APDU_FRAME_CONTROL_FIELD_RESERVED_MODE 0x01 +#define APDU_FRAME_CONTROL_FIELD_BROADCAST_MODE 0x02 +#define APDU_FRAME_CONTROL_FIELD_GROUP_ADDRESSING_MODE 0x03 + +//Ack Format subfiel values +#define APDU_FRAME_CONTROL_FIELD_DATA_ACK_FORMAT 0x00 +#define APDU_FRAME_CONTROL_FIELD_COMMAND_ACK_FORMAT 0x01 + +//Security subfield values +#define APDU_FRAME_CONTROL_FIELD_NOTSECURED 0x00 +#define APDU_FRAME_CONTROL_FIELD_SECURED 0x01 + +//Acknowledgement Request subfield values +#define APDU_FRAME_CONTROL_FIELD_NOACK 0x00 +#define APDU_FRAME_CONTROL_FIELD_ACK 0x01 + +//Extended Header Present subfield values +#define APDU_FRAME_CONTROL_FIELD_EXTENDED_HEADER_NOT_PRESENT 0x00 +#define APDU_FRAME_CONTROL_FIELD_EXTENDED_HEADER_PRESENT 0x01 + + +//Extended Frame Control field - ApduExtendedFrameControlField_t +//Fragmentation subfield values +#define APDU_EXT_FRAME_CONTROL_FIELD_FRAGMENTATION_NOT_FRAGMENTED 0x00 +#define APDU_EXT_FRAME_CONTROL_FIELD_FRAGMENTATION_FIRST_FRAGMENT 0x01 +#define APDU_EXT_FRAME_CONTROL_FIELD_FRAGMENTATION_FRAGMENT 0x02 +#define APDU_EXT_FRAME_CONTROL_FIELD_FRAGMENTATION_RESERVED 0x03 + +/* Maximum length of auxilary header for aps commands. */ +#define APS_MAX_AUXILIARY_HEADER_LENGTH 14U + +/****************************************************************************** + Types section +******************************************************************************/ +//APDU Frame Format +//Frame control field +BEGIN_PACK +typedef struct PACK +{ + LITTLE_ENDIAN_OCTET(6, ( + uint8_t frameType :2, + uint8_t deliveryMode :2, + uint8_t ackFormat :1, + uint8_t security :1, + uint8_t ackRequest :1, + uint8_t extendedHeaderPresent :1 + )) +} ApduFrameControlField_t; + +//Extended Frame Control field +typedef struct PACK +{ + LITTLE_ENDIAN_OCTET(2, ( + uint8_t fragmentation :2, + uint8_t reserved :6 + )) +} ApduExtendedFrameControlField_t; + +typedef struct PACK +{ + ApduExtendedFrameControlField_t extendedFrameControl; + uint8_t blockNumber; + uint8_t ackBitfield; +} ApduFragmentedAckExtendedHeaderSubframe_t; + +typedef struct PACK +{ + ApduExtendedFrameControlField_t extendedFrameControl; +} ApduNotFragmentedAckExtendedHeaderSubframe_t; + +typedef struct PACK +{ + ApduExtendedFrameControlField_t extendedFrameControl; + uint8_t blockNumber; +} ApduFragmentedDataExtendedHeaderSubframe_t; + +typedef struct PACK +{ + ApduExtendedFrameControlField_t extendedFrameControl; +} ApduNotFragmentedDataExtendedHeaderSubframe_t; + +typedef struct PACK +{ + ApduFrameControlField_t frameControl; + uint8_t dstEndpoint; + uint16_t clusterId; + uint16_t profileId; + uint8_t srcEndpoint; + uint8_t apsCounter; + union PACK + { + ApduNotFragmentedDataExtendedHeaderSubframe_t notFragmentedExtHeaderSubframe; + ApduFragmentedDataExtendedHeaderSubframe_t fragmentedExtHeaderSubframe; //Extended header subframe + }; +} ApduDataFrameNongroup_t; + +typedef struct PACK +{ + ApduFrameControlField_t frameControl; + uint16_t groupAddress; + uint16_t clusterId; + uint16_t profileId; + uint8_t srcEndpoint; + uint8_t apsCounter; +} ApduDataFrameGroup_t; + +typedef struct PACK +{ + ApduFrameControlField_t frameControl; //Frame Control field + uint8_t dstEndpoint; //Destination endpoint + uint16_t clusterId; //Cluster identifier + uint16_t profileId; //Profile identifier + uint8_t srcEndpoint; //Source endpoint + uint8_t apsCounter; //APS counter + union PACK + { + ApduNotFragmentedAckExtendedHeaderSubframe_t notFragmentedExtHeaderSubframe; + ApduFragmentedAckExtendedHeaderSubframe_t fragmentedExtHeaderSubframe; //Extended header subframe + }; +} ApduAcknowledgementFrame_t; + +typedef struct PACK +{ + ApduFrameControlField_t frameControl; //Frame Control field + uint8_t apsCounter; //APS counter +} ApduCommandAcknowledgementFrame_t; +END_PACK + +/****************************************************************************** + Prototypes section +******************************************************************************/ +#ifdef _LINK_SECURITY_ +/***************************************************************************//** + \brief Returns APS frame header size + + \param[in] apdu - pointer to frame + + \return size of APS frame header +*******************************************************************************/ +APS_PRIVATE uint8_t apsGetHeaderSize(uint8_t *apdu); +#endif /* _LINK_SECURITY_ */ + +#endif /* _APSFRAMES_H_ */ diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsGroup.h b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsGroup.h new file mode 100644 index 00000000..022e23c6 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsGroup.h @@ -0,0 +1,66 @@ +/**************************************************************************//** + \file apsGroup.h + + \brief Interface of APS Multicast Transmission. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 2010-10-12 Max Gekk - Created. + Last change: + $Id: apsGroup.h 17448 2011-06-09 13:53:59Z ataradov $ + ******************************************************************************/ +#if !defined _APS_GROUP_H +#define _APS_GROUP_H + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include +#include + +#if defined _APS_MULTICAST_ +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/***************************************************************************** + \brief Group indication (APSDE-DATA.indication) to all group members. + + \param[in] apsDataInd - pointer to APSDE-DATA.indication's parameters. + \return None. + *****************************************************************************/ +APS_PRIVATE void apsGroupIndication(APS_DataInd_t *const apsDataInd); + +/***************************************************************************** + \brief Process multicast packets from NWK layer. + + \param[in] nwkDataInd - pointer to NLDE-DATA.indication parameters. + \param[in] securityStatus - kind of used security. + + \return true - response for NWK_DataInd requered, + false - response for NWK_DataInd not required + and will be made in the future. + *****************************************************************************/ +APS_PRIVATE bool apsGroupPacketHandler(const NWK_DataInd_t *const nwkDataInd, + const APS_Status_t securityStatus); + +/***************************************************************************** + \brief Process APSDE-DATA.request with Group Addressing Mode + + \param[in] apsDataReq - pointer to APSDE-DATA.request's parameters + \param[in] apsBuffer - pointer to APS buffer with NLDE-DATA.request. + + \return APS_SUCCESS_STATUS + *****************************************************************************/ +APS_PRIVATE APS_Status_t apsProcessGroupAddrModeDataReq(APS_DataReq_t *apsDataReq, + ApsDataBuffer_t *apsBuffer); + +#endif /* _APS_MULTICAST_ */ +#endif /* _APS_GROUP_H */ +/** eof apsGroup.h */ diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsKeyPairSet.h b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsKeyPairSet.h new file mode 100644 index 00000000..dce1a337 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsKeyPairSet.h @@ -0,0 +1,116 @@ +/**************************************************************************//** + \file apsKeyPairSet.h + + \brief Private interface of APS Key-Pair Set. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 2010-11-01 Max Gekk - Created. + Last change: + $Id: apsKeyPairSet.h 17813 2011-07-04 14:11:12Z dloskutnikov $ + ******************************************************************************/ +#if !defined _APS_KEY_PAIR_SET_H +#define _APS_KEY_PAIR_SET_H + +#if defined _LINK_SECURITY_ +/****************************************************************************** + Includes section + ******************************************************************************/ +#include +#include + +/****************************************************************************** + Definitions section + ******************************************************************************/ +/* Size of APS security counter in bytes */ +#define APS_SECURITY_COUNTER_SIZE 4U + +/****************************************************************************** + Types section + ******************************************************************************/ +/* Type of outgoing frame counter higher bytes. */ +typedef uint16_t ApsOutFrameCounterTop_t; +/* Type of outgoing frame counter lower bytes. */ +typedef uint16_t ApsOutFrameCounterLow_t; + +/** Outgoing security frame counter handle type. */ +BEGIN_PACK +typedef union PACK +{ + ApsOutFrameCounter_t value; + struct + { + LITTLE_ENDIAN_OCTET(2, + (ApsOutFrameCounterLow_t low, + ApsOutFrameCounterTop_t top)) + } part; +} ApsOutFrameCounterHandle_t; +END_PACK + +/* Type of key-pair descriptor. */ +typedef struct _ApsKeyPairDescriptor_t +{ + /** A flag indicating that key-pair is used. */ + bool busy; + /** A flag indicating that key-pair is authorized. */ + bool auth; + /* Outgoing frame counter higher bytes. */ + ApsOutFrameCounterTop_t outCounterTop; + /* Identifies the address of the entity with which this key-pair is shared. */ + ExtAddr_t deviceAddress; + /* The actual value of the initial key: + master key for High Security and preinstalled link key for SE Security. */ + uint8_t initialKey[SECURITY_KEY_SIZE]; + /* The actual value of the link key. */ + uint8_t linkKey[SECURITY_KEY_SIZE]; +} ApsKeyPairDescriptor_t; + +/* Type of incoming and outgoing counters. */ +typedef struct _ApsKeyCounters_t +{ + /* Outgoing frame counter lower bytes. */ + ApsOutFrameCounterLow_t outCounterLow; + /* Incoming frame counter value corresponding to DeviceAddress. */ + ApsInFrameCounter_t in; +} ApsKeyCounters_t; + +/* Type of size of APS Key-Pair Set. */ +typedef uint8_t ApsKeyPairAmount_t; +/* Type of Key-Pair Index. */ +typedef ApsKeyPairAmount_t ApsKeyPairIndex_t; + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/**************************************************************************//** + \brief Get current value of outgoing frame counter and increment it. + + \param[in] keyHandle - valid key handle. + + \return Pointer to current value of outgoing frame counter. + ******************************************************************************/ +APS_PRIVATE +ApsOutFrameCounter_t apsGetUpdatedOutFrameCounter(const APS_KeyHandle_t keyHandle); + +/**************************************************************************//** + \brief Get current value of incoming frame counter. + + \param[in] handle - valid key handle. + + \return Pointer to current value of incoming frame counter. + ******************************************************************************/ +APS_PRIVATE +ApsInFrameCounter_t apsGetInFrameCounter(const APS_KeyHandle_t handle); + +#endif /* _LINK_SECURITY_ */ + +#endif /* _APS_KEY_PAIR_SET_H */ +/** eof apsKeyPairSet.h */ + diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsMemoryManager.h b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsMemoryManager.h new file mode 100644 index 00000000..6206ca22 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsMemoryManager.h @@ -0,0 +1,340 @@ +/*************************************************************************//** + \file apsMemoryManager.h + + \brief The header file describes APS memory manager primitive. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + +*****************************************************************************/ + +#ifndef APSMEMORYMANAGER_H_ +#define APSMEMORYMANAGER_H_ + +/****************************************************************************** + Includes section +******************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include + +/****************************************************************************** + Types section +******************************************************************************/ +typedef enum +{ + APS_DM_DATA_BUFFER_TYPE, + APS_DM_ACK_DATA_BUFFER_TYPE, + APS_SM_FREE_BUFFER_TYPE, + APS_SM_AUR_SSP_AUTH_BUFFER_TYPE, + APS_SM_AUR_CHALLENGE_COMMAND_BUFFER_TYPE, + APS_SM_AUR_MAC_DATA_COMMAND_TYPE, + APS_SM_AUI_SSP_AUTH_BUFFER_TYPE, + APS_SM_AUI_CHALLENGE_COMMAND_BUFFER_TYPE, + APS_SM_AUI_MAC_COMMAND_BUFFER_TYPE, + APS_SM_SSPD_BUFFER_TYPE, + APS_SM_UDR_COMMAND_BUFFER_TYPE, //UpdateDevice command + APS_SM_RDR_COMMAND_BUFFER_TYPE, //RemoveDevice command + APS_SM_RKR_COMMAND_BUFFER_TYPE, //RequestKey command + APS_SM_SKR_COMMAND_BUFFER_TYPE, //RequestKey command + APS_SM_TKR_COMMAND_BUFFER_TYPE, //TransportKey command + APS_SM_TKI_COMMAND_BUFFER_TYPE, + APS_SM_COMMAND_IND_BUFFER_TYPE, + APS_TUNNEL_COMMAND_BUFFER_TYPE +} ApsBufferType_t; + +typedef enum { + APS_DEFAULT_STATE, + APS_NLDE_DATA_CONF_WAIT_STATE, + APS_ACK_WAIT_STATE, + APS_ACK_RECEIVED_STATE, + APS_RETRANSMISSION_STATE, + APS_TIMEOUT_STATE, +} ApsDataDescriptorState_t ; + +typedef enum +{ + APS_NLDE_DATA_REQ_BUFFER_TYPE, //Request for data transmission without ack waiting + APS_NLDE_DATA_REQ_WITH_ACK_BUFFER_TYPE, //Request for data transmission with ack waiting + APS_NLDE_DATA_REQ_ACK_BUFFER_TYPE, //Request for APS ACK transmission + APS_NLDE_DATA_REQ_BLOCK_BUFFER_TYPE, //Request for part of fragmented data transmission +} ApsNldeDataReqType_t; + +typedef struct +{ +#ifdef _SECURITY_ +#ifdef _LINK_SECURITY_ + uint8_t headerLength; + QueueElement_t queueElement; + APS_Status_t securityStatus; + APS_KeyHandle_t keyHandle; +#endif // _LINK_SECURITY_ +#endif //_SECURITY_ + + uint8_t busy:1; + ApsNldeDataReqType_t entryType:7; + ApsDataDescriptorState_t state:4; + //if request with ack requested data frame then it is a retries counter + uint8_t retriesCounter:4; + + NWK_DataReq_t nwkDataReq; //NLDE-DATA.request primitive + +#ifdef _BINDING_ + ApsBindingEntry_t *bindEntry; +#endif +} ApsDataDescriptor_t; + +typedef struct +{ + APS_DataReq_t *link; // request pointer + ApsBufferType_t type; + uint32_t timeout; + ApsDataDescriptor_t dataDescriptor; +} ApsDataBuffer_t ; + +/* + APS Acknowledge buffer declaration +*/ +typedef struct +{ + /* Current buffer status */ + bool busy; + /* Determines type of encryption to be used for ack */ + APS_Status_t securityStatus; + /* Link to relative NWK_DataInd entity */ + NWK_DataInd_t *dataIndLink; + + BEGIN_PACK + TOP_GUARD + struct PACK + { + uint8_t lowLevelHeader[NWK_NSDU_OFFSET]; +#ifdef _LINK_SECURITY_ + uint8_t apsSecHeader[APS_AUXILIARY_HEADER_LENGTH]; +#endif /* _LINK_SECURITY_ */ + + union PACK + { + ApduAcknowledgementFrame_t dataAck; //Acknowledgement frame for data + ApduCommandAcknowledgementFrame_t commandAck; //Acknowledgement frame for command + } frame; +#ifdef _LINK_SECURITY_ + uint8_t apsSecFooter[APS_MAX_DATA_FRAME_FOOTER_LENGTH]; +#endif /* _LINK_SECURITY_ */ + +#if (NWK_AFFIX_LENGTH - NWK_NSDU_OFFSET) + uint8_t lowLevelFooter[NWK_AFFIX_LENGTH - NWK_NSDU_OFFSET]; +#endif + }; + BOTTOM_GUARD + END_PACK +} ApsAckBuffer_t; + +typedef struct +{ + uint8_t buffersAmount; + ApsAckBuffer_t *buffers; +} ApsAckBuffersPool_t; + +typedef struct +{ + uint8_t buffersAmount; + uint8_t maxAckCounter; + uint8_t maxReqCounter; + uint8_t ackCounter; + uint8_t reqCounter; + ApsDataBuffer_t *buffers; +} ApsDataReqBuffersPool_t; + +#ifdef _APS_FRAGMENTATION_ +typedef struct +{ + uint8_t state; + uint8_t *buffers; + uint8_t *bufferLengths; + uint8_t maxBlocksAmount; + uint16_t blockSize; + uint32_t timeout; + uint8_t blocksAmount; + uint8_t currentWindowStartBlockNumber; + uint8_t ackBitfield; + uint16_t srcAddress; + uint8_t dstEndpoint; + uint16_t clusterId; + uint16_t profileId; + uint8_t srcEndpoint; + uint8_t apsCounter; + ApsDataBuffer_t apsBuffer; + ApsAckBuffer_t apsAckBuffer; + APS_Status_t securityStatus; +} ApsFragmRxDescr_t; + +typedef struct +{ + uint8_t blockNumber; + uint8_t ackBlockNumber; // block number that expect ack, also it is first block number in the window + uint8_t blocksToTransmit; // block in window requires to transmit. 1 required transmission + uint8_t blocksCount; + uint8_t apsCounter; + uint8_t retryCounter; + HAL_AppTimer_t sendTimer; // timer that send frame per apsInterframeDelay + ApsDataBuffer_t *block; // memory for block + uint8_t *buffer; +} ApsFragmTxDescr_t; +#endif // _APS_FRAGMENTATION_ + +/* + * APS sublayer memory structure. + */ +typedef struct +{ + ApsDataReqBuffersPool_t dataReqBuffersPool; // Buffers to execute APS Data requests + ApsAckBuffersPool_t ackBuffersPool; // Buffers to generate APS acknowledgements +#ifdef _APS_FRAGMENTATION_ + ApsFragmRxDescr_t apsFragmRxDescr; + ApsFragmTxDescr_t apsFragmTxDescr; +#endif // _APS_FRAGMENTATION_ +} ApsMem_t; + + +/****************************************************************************** + Extern variables section +******************************************************************************/ +extern ApsMem_t apsMem; + +/****************************************************************************** + Prototypes section +******************************************************************************/ +/***************************************************************************** + \brief Make a reset of APS Memory Manager + + \param fullReset - reset all internal variables of APS-layer or not. + \retur none +*****************************************************************************/ +APS_PRIVATE void apsResetMemoryManager(void); + +/***************************************************************************//** + \brief Allocates memory buffer for NLDE-DATA.request primitive specified by + parameter primitiveType. + + \param primitiveType - type of buffer which will be allocated + APS_NLDE_DATA_REQ_BUFFER_TYPE - NLDE-DATA.request without frame + APS_NLDE_DATA_REQ_WITH_ACK_BUFFER_TYPE - NLDE-DATA.request with ack + required flag in APDU + APS_NLDE_DATA_REQ_ACK_BUFFER_TYPE - NLDE-DATA.request with ack frame + \return nonNULL buffer pointer if memory was allocated successfully + NULL - no free buffers available. +*******************************************************************************/ +APS_PRIVATE ApsDataBuffer_t *apsGetBuffer(uint8_t primitiveType); + +/***************************************************************************//** + \brief Deallocate memory buffer + + \param buffer - pointer to buffer to be freed. + \return None +*******************************************************************************/ +APS_PRIVATE void apsFreeBuffer(void *buffer); + +/***************************************************************************//** + \brief Check memory availability for NLDE-DATA.request primitive to generate + APS acknowledge. + + \param None + \return true - memory is available + false - in other case +*******************************************************************************/ +APS_PRIVATE bool apsIsBufferAvailableForAck(void); + +/****************************************************************************** + Inline functions section +******************************************************************************/ +/***************************************************************************** + \brief Gives pointer to APS layer memory pool. + + \param none + \retur pointer to APS memory pool. +*****************************************************************************/ +INLINE ApsDataReqBuffersPool_t *apsGetDataReqBuffersMem(void) +{ + return &apsMem.dataReqBuffersPool; +} + +/***************************************************************************** + \brief Gives pointer to APS layer acknowledgements memory pool. + + \param none + \retur pointer to APS acknowledgements memory pool. +*****************************************************************************/ +INLINE ApsAckBuffersPool_t *apsGetAckBuffersMem(void) +{ + return &apsMem.ackBuffersPool; +} + +#ifdef _APS_FRAGMENTATION_ +/***************************************************************************** + \brief Gives pointer to APS layer fragmentation feature memory (Rx). + + \param none + \retur pointer to fragmentation feature memory (Rx). +*****************************************************************************/ +INLINE ApsFragmRxDescr_t *apsGetFragmRxDescrMem(void) +{ + return &apsMem.apsFragmRxDescr; +} + +/***************************************************************************** + \brief Gives pointer to APS layer fragmentation feature memory (Tx). + + \param none + \retur pointer to fragmentation feature memory (Tx). +*****************************************************************************/ +INLINE ApsFragmTxDescr_t *apsGetFragmTxDescrMem(void) +{ + return &apsMem.apsFragmTxDescr; +} + +/***************************************************************************** + \brief Resets structure which controls fragmented data receiption procedure. + + \param none + \retur none +*****************************************************************************/ +INLINE void apsResetFragmRxDescr(void) +{ + ApsFragmRxDescr_t *apsFragmRxDescr = apsGetFragmRxDescrMem(); + + apsFragmRxDescr->ackBitfield = 0; + apsFragmRxDescr->apsCounter = 0; + apsFragmRxDescr->blocksAmount = 0; + apsFragmRxDescr->clusterId = 0; + apsFragmRxDescr->currentWindowStartBlockNumber = 0; + apsFragmRxDescr->dstEndpoint = 0; + apsFragmRxDescr->profileId = 0; + apsFragmRxDescr->srcAddress = 0; + apsFragmRxDescr->srcEndpoint = 0; + apsFragmRxDescr->state = 0; + apsFragmRxDescr->timeout = 0; + + memset(&apsFragmRxDescr->apsBuffer, 0, sizeof(apsFragmRxDescr->apsBuffer)); + memset(&apsFragmRxDescr->apsAckBuffer, 0, sizeof(apsFragmRxDescr->apsAckBuffer)); + memset(apsFragmRxDescr->buffers, 0, + apsFragmRxDescr->maxBlocksAmount * apsFragmRxDescr->blockSize + apsFragmRxDescr->maxBlocksAmount); + + apsFragmRxDescr->apsBuffer.dataDescriptor.nwkDataReq.nsdu = (uint8_t *)&apsFragmRxDescr->apsAckBuffer.frame; +} + +#endif // ifdef _APS_FRAGMENTATION_ +#endif /*APSMEMORYMANAGER_H_*/ + +//eof apsMemoryManager.h diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsRejectDuplicate.h b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsRejectDuplicate.h new file mode 100644 index 00000000..97b51223 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsRejectDuplicate.h @@ -0,0 +1,47 @@ +/**************************************************************************//** + \file apsRejectDuplicate.h + + \brief Private interface of the duplicate rejection table. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 2011-07-03 Max Gekk - Created. + Last change: + $Id: apsRejectDuplicate.h 17801 2011-07-04 08:55:01Z mgekk $ + ******************************************************************************/ +#if !defined _APS_REJECT_DUPLICATE_H +#define _APS_REJECT_DUPLICATE_H +/****************************************************************************** + Includes section + ******************************************************************************/ +#include + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/***************************************************************************** + \brief Is incoming packet is dublicate or not? Checks in the rejection table. + + \param[in] srcAddr - short address of source node. + \param[in] counter - APS counter of incoming packet. + + \return true - if incoming packet is duplicate otherwise return false. +*****************************************************************************/ +APS_PRIVATE bool apsIsDuplicatePacket(const ShortAddr_t srcAddr, + const uint8_t counter); + +/****************************************************************************** + \brief Reset the duplicate rejection table ana reinit timeouts. + ******************************************************************************/ +APS_PRIVATE void apsResetDuplicateRejectionTable(void); + +#endif /* _APS_REJECT_DUPLICATE_H */ +/** eof apsRejectDuplicate.h */ + diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsRemoveDevice.h b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsRemoveDevice.h new file mode 100644 index 00000000..7d9bf174 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsRemoveDevice.h @@ -0,0 +1,61 @@ +/**************************************************************************//** + \file apsRemoveDevice.h + + \brief Private interface of APS Remove Device. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 2011-03-18 A. Razinkov - Created. + Last change: + $Id: apsRemoveDevice.h 17470 2011-06-10 11:31:00Z mgekk $ + ******************************************************************************/ +#ifndef _APS_REMOVE_DEVICE_H +#define _APS_REMOVE_DEVICE_H + +#ifdef _SECURITY_ +/****************************************************************************** + Includes section + ******************************************************************************/ +#include +#include +#include +#include + +/****************************************************************************** + Types section + ******************************************************************************/ +BEGIN_PACK +/** Type of APS remove device command frame. */ +typedef struct PACK _ApsRemoveDeviceFrame_t +{ + /** An APS header, which comprises frame control and addressing information. */ + ApduCommandHeader_t header; + /** the 64-bit extended address of the device that is requested to be removed + * from the network. */ + ExtAddr_t childAddress; +} ApsRemoveDeviceFrame_t; +END_PACK + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/**************************************************************************//** + \brief Remove device indication handler. + + \param[in] commandInd - pointer to received command descriptor. + + \return 'true' if NWK buffer with the command frame must be freed + otherwise return 'false'. + ******************************************************************************/ +APS_PRIVATE bool apsRemoveDeviceInd(const ApsCommandInd_t *const commandInd); + +#endif /* _SECURITY_ */ +#endif /* _APS_REMOVE_DEVICE_H */ +/** eof apsRemoveDevice.h */ diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsRequestKey.h b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsRequestKey.h new file mode 100644 index 00000000..95ab7eba --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsRequestKey.h @@ -0,0 +1,80 @@ +/**************************************************************************//** + \file apsRequestKey.h + + \brief Private interface of APS Request Key. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008 , Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 2011-06-04 Max Gekk - Created. + Last change: + $Id: apsRequestKey.h 19032 2011-10-27 09:22:49Z mgekk $ + ******************************************************************************/ +#if !defined _APS_REQUEST_KEY_H +#define _APS_REQUEST_KEY_H + +#if defined _SECURITY_ && defined _LINK_SECURITY_ +/****************************************************************************** + Includes section + ******************************************************************************/ +#include +#include + +/****************************************************************************** + Types section + ******************************************************************************/ +BEGIN_PACK +/* Request-Key Command Frame Format. See ZigBee spec r19, Figure 4.14. */ +typedef struct PACK _ApsRequestKeyFrame_t +{ + /** An APS header, which comprises frame control and addressing information. */ + ApduCommandHeader_t header; + /* The key type field shall be set to 1 when the network key is being + * requested, shall be set to 2 when an application key is being requested. + * See ZigBee spec r19, 4.4.9.5.2, page 483. */ + uint8_t keyType; + /* When the key type field is 2 (that is, an application key), the partner + * address field shall contain the extended 64-bit address of the partner + * device that shall be sent the key. See ZigBee spec r19, 4.4.9.5.3 */ + uint8_t partnerAddress[sizeof(ExtAddr_t)]; +} ApsRequestKeyFrame_t; +END_PACK + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/**************************************************************************//** + \brief Reset the internal queue and variables of APS Request Key component. + ******************************************************************************/ +APS_PRIVATE void apsRequestKeyReset(void); + +/**************************************************************************//** + \brief Transport key has been received, indicate to the upper-layer. + + \param[in] transportKeyInd - pointer to parameters of received key. + \return None. + ******************************************************************************/ +APS_PRIVATE void apsRequestedKeyReceived(APS_TransportKeyInd_t *transportKeyInd); + +/**************************************************************************//** + \brief Request key indication handler. + + \param[in] commandInd - pointer to received command descriptor. + + \return 'true' if NWK buffer with the command frame must be freed + otherwise return 'false'. + ******************************************************************************/ +APS_PRIVATE bool apsRequestKeyInd(const ApsCommandInd_t *const commandInd); + +#else +#define apsRequestKeyInd NULL +#define apsRequestedKeyReceived(transportKeyInd) ((void)0) +#endif /* _SECURITY_ and _LINK_SECURITY_ */ + +#endif /* _APS_REQUEST_KEY_H */ diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsSkke.h b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsSkke.h new file mode 100644 index 00000000..0758c7e4 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsSkke.h @@ -0,0 +1,225 @@ +/**************************************************************************//** + \file apsSkke.h + + \brief Private interface of symmetric-key key establishment implementation. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 2011-04-23 Max Gekk - Created. + Last change: + $Id: apsSkke.h 17813 2011-07-04 14:11:12Z dloskutnikov $ + ******************************************************************************/ +#if !defined _APS_SKKE_H +#define _APS_SKKE_H + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include +#if defined _SECURITY_ && defined _LINK_SECURITY_ && defined _HI_SECURITY_ +#include + +/****************************************************************************** + Define(s) section + ******************************************************************************/ +/** Size of the data field in SKKE command frames. */ +#define APS_SKKE_DATA_SIZE 16U +/* Maximum value of SKKE TTL. */ +#define APS_SKKE_INFINITY_TTL UINT32_MAX + +/****************************************************************************** + Types section + ******************************************************************************/ +/* Type of internal state of SKKE responder or initiator. */ +typedef enum _ApsSkkeState_t +{ + APS_SKKE_REQ_STATE, + APS_WAIT_SKKE_2_STATE, + APS_WAIT_SKKE_4_STATE, + APS_SKKE_RESP_STATE, + APS_WAIT_SKKE_3_STATE +} ApsSkkeState_t; + +BEGIN_PACK +/** Type of generic SKKE command frame. See ZigBee spec r19, page 478. */ +typedef struct PACK _ApsSkkeFrame_t +{ + ApduCommandHeader_t header; + /** The 64-bit extended address of the device that acts as the initiator + * in the key-establishment protocol. See ZigBee spec r19, 4.4.9.1.2 */ + uint8_t initiator[sizeof(ExtAddr_t)]; + /** The 64-bit extended address of the device that acts as the responder + * in the key-establishment protocol. See ZigBee spec r19, 4.4.9.1.3 */ + uint8_t responder[sizeof(ExtAddr_t)]; + /** The content of the data field depends on the command identifier field: + * QEU for SKKE-1, QEV for SKKE-2, MacTag2 for SKKE-3, MacTag1 for SKKE-4. */ + uint8_t data[APS_SKKE_DATA_SIZE]; +} ApsSkkeFrame_t; +END_PACK + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/**************************************************************************//** + \brief Process an incoming SKKE command frame. + + \param[in] commandInd - pointer to parameters of the received command: + - secured or not, + - extended address of source node, + - pointer to NLDE-DATA.indication's parameters. + + \return 'true' - free NWK buffer for a SKKE command otherwise return 'false'. + ******************************************************************************/ +APS_PRIVATE bool apsSkkeInd(const ApsCommandInd_t *const commandInd); + +/**************************************************************************//** + \brief Initializes the common substructure of SKKE requests or response. + + \param[in, out] skkeElem - pointer to the common element of SKKE request + or SKKE response. \sa ApsSkkeElem_t + \param[in] state - initial state of the SKKE request. + \param[in] ttl - time to live of the SKKE request. + \param[in] apsSkkeConf - confirmation function of the SKKE request or response. + + \return None. + ******************************************************************************/ +APS_PRIVATE void apsInitSkkeElem(ApsSkkeElem_t *const skkeElem, + const ApsSkkeState_t state, const uint32_t ttl, + void (* apsSkkeConf)(struct _ApsSkkeElem_t*, APS_SkkeStatus_t)); + +/**************************************************************************//** + \brief Find a first SKKE element by state and remove it from internal queue. + + \param[in] state - state of the SKKE request or response. + + \return Pointer to SKKE element or NULL if element isn't found. + ******************************************************************************/ +APS_PRIVATE ApsSkkeElem_t* apsFetchSkkeElem(const ApsSkkeState_t state); + +/**************************************************************************//** + \brief Is there an SKKE element with the given state? + + \param[in] state - state of the SKKE request or response. + + \return 'true' if any element is found otherwise return 'false'. + ******************************************************************************/ +APS_PRIVATE bool apsIsThereSkkeElem(const ApsSkkeState_t state); + +/**************************************************************************//** + \brief Set new TTL of the SKKE element. + + \param[in, out] skkeElem - pointer to the common substructure of SKKE request + or SKKE response. \sa ApsSkkeElem_t + \param[in] ttl - time to live of the SKKE request or response. + \return None. + ******************************************************************************/ +APS_PRIVATE void apsSetSkkeTTL(ApsSkkeElem_t *const skkeElem, const uint32_t ttl); + +/**************************************************************************//** + \brief Set new state of the SKKE element. + + \param[in, out] skkeElem - pointer to the common substructure of SKKE request + or SKKE response. \sa ApsSkkeElem_t + \param[in] state - new state of the SKKE request or response. + \return None. + ******************************************************************************/ +APS_PRIVATE void apsSetSkkeState(ApsSkkeElem_t *const skkeElem, + const ApsSkkeState_t state); + +/**************************************************************************//** + \brief Allocate memory for SKKE frame and NWK_DataReq_t structure in NWK. + + \param[in] allocNwkDataReq - pointer to NWK DataReq allocation's parameters. + \param[in] nwkAllocDataConf - callback function. NWK-layer calls this function + when memory has been allocated. + \return None. + ******************************************************************************/ +APS_PRIVATE void apsSkkeAllocFrameReq(NWK_AllocDataReq_t *const allocNwkDataReq, + void (*nwkAllocDataConf)(NWK_AllocDataConf_t*)); + +/**************************************************************************//** + \brief Prepare and fill fields of APS SKKE command frame. + + \param[in] allocConf - pointer to confirmation structure with pointer to + allocated NWK_DataReq_t structure. + \param[in] commandId - identifier of APS security command frame. + \param[in] nwkDataReq - pointer to field in the SKKE request (reponse) + for saving pointer to allocated NWK_DataReq_t structure. + \param[in] data - pointer to value for the data field of APS SKKE frame. + \param[in] initiatorAddress - pointer to extended address of SKKE initiator. + \param[in] responderAddress - pointer to extended address of SKKE responser. + + \return None. + ******************************************************************************/ +APS_PRIVATE void apsPrepareSkkeCommand(NWK_AllocDataConf_t *const allocConf, + const ApsCommandId_t commandId, NWK_DataReq_t **const skkeNwkDataReq, + const uint8_t *const data, const ExtAddr_t *const initiatorAddress, + const ExtAddr_t *const responderAddress); + +/**************************************************************************//** + \brief Prepare NWK_DataReq_t structure and send SKKE command frame. + + \param[in] nwkDataReq - pointer to parameters of NLDE-DATA.request. + \param[in] nwkDataConf - NLDE-DATA confirm callback function's pointer. + \param[in] dstShortAddr - short address of partner (initiator or responder). + \param[in] secure - enable security on NWK layer. + + \return None. + ******************************************************************************/ +APS_PRIVATE void apsSkkeNwkDataReq(NWK_DataReq_t *const nwkDataReq, + void (* nwkDataConf)(NWK_DataConf_t*), const ShortAddr_t dstShortAddr, + const bool secure); + +/**************************************************************************//** + \brief Process confirmation from NWK layer of transmission SKKE command. + + \param[in] nwkDataConf - pointer to NLDE-DATA confirmation parameters. + \param[in] state - state of SKKE request or response for which SKKE command + was transmitted. + \param[in] apsSkkeCompareNwkReq - matching function of SKKE request + or response with NWK DataReq_t structure. + \param[in] txErrorStatus - return this SKKE status if transmission of SKKE + command is failure. + \return None. + ******************************************************************************/ +APS_PRIVATE void apsSkkeNwkDataConf(NWK_DataConf_t *const nwkDataConf, + const ApsSkkeState_t state, + bool (*apsSkkeCompareNwkReq)(const ApsSkkeElem_t*, NWK_DataReq_t*), + const APS_SkkeStatus_t txErrorStatus); + +/**************************************************************************//** + \brief Process indication from NWK layer about SKKE command. + + \param[in] nwkDataInd - pointer to NLDE-DATA indication parameters. + \param[in] state - state of SKKE request or response for which SKKE command + is expected. + \param[in] apsSkkeCompareNwkInd - matching function of SKKE request + or response with NWK DataInd_t structure. + \param[in, out] skkeFrame - pointer to pointer to SKKE raw frame. + \return Pointer to SKKE element or NULL if it insn't found. + ******************************************************************************/ +APS_PRIVATE ApsSkkeElem_t* apsFindSkkeElemByNwkInd(const NWK_DataInd_t *const nwkDataInd, + const ApsSkkeState_t state, + bool (*apsSkkeCompareNwkInd)(const ApsSkkeElem_t*, const ApsSkkeFrame_t*), + ApsSkkeFrame_t **skkeFrame); + +/**************************************************************************//** + \brief Reset the internal queue and variables of SKKE component. + ******************************************************************************/ +APS_PRIVATE void apsSkkeReset(void); + +#else /* not _HI_SECURITY_ */ + +#define apsSkkeInd NULL +#define apsSkkeReset() ((void)0) +#endif /* _HI_SECURITY_ */ + +#endif /* _APS_SKKE_H */ +/** eof apsSkke.h */ diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsSkkeInitiator.h b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsSkkeInitiator.h new file mode 100644 index 00000000..e533b58c --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsSkkeInitiator.h @@ -0,0 +1,61 @@ +/**************************************************************************//** + \file apsSkkeInitiator.h + + \brief Private interface of APS SKKE Initiator. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 2011-04-24 Max Gekk - Created. + Last change: + $Id: apsSkkeInitiator.h 17813 2011-07-04 14:11:12Z dloskutnikov $ + ******************************************************************************/ +#if !defined _APS_SKKE_INITIATOR_H +#define _APS_SKKE_INITIATOR_H + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include + +#if defined _HI_SECURITY_ +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/**************************************************************************//** + \brief Main task handler of SKKE initiator. + ******************************************************************************/ +APS_PRIVATE void apsSkkeInitiatorTaskHandler(void); + +/**************************************************************************//** + \brief Process SKKE-2 command frame from a responder. + + \param[in] ind - pointer to NWK parameters of received SKKE-2 frame. + \return None. + ******************************************************************************/ +APS_PRIVATE void apsISkke2Ind(NWK_DataInd_t *ind); + +/**************************************************************************//** + \brief Process SKKE-4 command frame from a responder. + + \param[in] ind - pointer to NWK parameters of received SKKE-4 frame. + \return None. + ******************************************************************************/ +APS_PRIVATE void apsISkke4Ind(NWK_DataInd_t *ind); + +#else /* no _HI_SECURITY_ */ + + +#define apsSkkeInitiatorTaskHandler NULL + +#endif /* _HI_SECURITY_ */ + +#endif /* _APS_SKKE_INITIATOR_H */ +/** eof apsSkkeInitiator.h */ + diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsSkkeResponder.h b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsSkkeResponder.h new file mode 100644 index 00000000..dab279db --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsSkkeResponder.h @@ -0,0 +1,60 @@ +/**************************************************************************//** + \file apsSkkeResponder.h + + \brief Private interface of APS SKKE Responder. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 2011-04-24 Max Gekk - Created. + Last change: + $Id: apsSkkeResponder.h 17813 2011-07-04 14:11:12Z dloskutnikov $ + ******************************************************************************/ +#if !defined _APS_SKKE_RESPONDER_H +#define _APS_SKKE_RESPONDER_H + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include + +#if defined _HI_SECURITY_ +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/**************************************************************************//** + \brief Main task handler of SKKE responder. + ******************************************************************************/ +APS_PRIVATE void apsSkkeResponderTaskHandler(void); + +/**************************************************************************//** + \brief Process SKKE-1 command frame from a initiator. + + \param[in] ind - pointer to NWK parameters of received SKKE-1 frame. + \return None. + ******************************************************************************/ +APS_PRIVATE void apsRSkke1Ind(NWK_DataInd_t *ind); + +/**************************************************************************//** + \brief Process SKKE-3 command frame from a initiator. + + \param[in] ind - pointer to NWK parameters of received SKKE-3 frame. + \return None. + ******************************************************************************/ +APS_PRIVATE void apsRSkke3Ind(NWK_DataInd_t *ind); + +#else /* _HI_SECURITY_ */ + + +#define apsSkkeResponderTaskHandler NULL + +#endif /* _HI_SECURITY_ */ + +#endif /* _APS_SKKE_RESPONDER_H */ +/** eof apsSkkeResponder.h */ diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsSmSsp.h b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsSmSsp.h new file mode 100644 index 00000000..11d82a9c --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsSmSsp.h @@ -0,0 +1,80 @@ +/*************************************************************************//** + \file apsSmSsp.c + + \brief APS SSP features header file + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 07/11/07 A. Potashov - Created. +*****************************************************************************/ + +#ifndef _APSSMSSP_H +#define _APSSMSSP_H + +/****************************************************************************** + Includes section +******************************************************************************/ +#include +#include + +/****************************************************************************** + Types section +******************************************************************************/ +typedef enum +{ + APS_SM_SSPE_SUCCESS_STATUS = 0x00, + APS_SM_SSPE_START_STATUS, + APS_SM_SSPE_FAIL_STATUS, +} ApsSspeStatus_t; + + +#if defined _SECURITY_ && defined _LINK_SECURITY_ +typedef enum +{ + APS_SM_SSPD_SUCCESS_STATUS = 0x00, + APS_SM_SSPD_START_STATUS, + APS_SM_SSPD_FAIL_STATUS, +} ApsSspdStatus_t; + +/****************************************************************************** + Prototypes section +******************************************************************************/ +/***************************************************************************** + APS Frame Encrypt Function + Parameters: buffer - APS Security Manager buffer pointer + dstExtAddr - destination extended address pointer + apduLength - APDU length + Returns: APS_SM_SSPE_START_STATUS - encryption process started + APS_SM_SSPE_FAIL_STATUS - encryption failed + APS_SM_SSPE_SUCCESS_STATUS - encryption not required + (not needed) +*****************************************************************************/ +/** + * \brief request for encryption of data buffer + */ +APS_PRIVATE void apsEncryptDataFrame(ApsDataBuffer_t *buffer, uint8_t headerLength); + +APS_PRIVATE void apsSecurityTaskHandler(void); +APS_PRIVATE void apsSecuredNwkDataIndHandler(NWK_DataInd_t *ind); + +/***************************************************************************** + Make a search of key-pair descriptor for extended address specified + Parameters: address - 64-bit IEEE device address pointer + Returns: NULL - key-pair descriptor not found + valid key-pair descriptor pointer - in other case +*****************************************************************************/ +APS_PRIVATE void apsDecryptSentFrame(ApsDataBuffer_t *buffer); + +APS_PRIVATE void apsResetSmSsp(void); +#else +#define apsSecurityTaskHandler NULL +#endif //_SECURITY_ and _LINK_SECURITY_ +#endif //#ifndef _APSSMSSP_H +//eof apsSmSsp.h diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsState.h b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsState.h new file mode 100644 index 00000000..f43aee2a --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsState.h @@ -0,0 +1,152 @@ +/**************************************************************************//** + \file apsState.h + + \brief Set and check APS state. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 2010-10-09 Max Gekk - Created. + Last change: + $Id: apsState.h 17448 2011-06-09 13:53:59Z ataradov $ + ******************************************************************************/ +#if !defined _APS_STATE_H +#define _APS_STATE_H + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include + +/****************************************************************************** + Types section + ******************************************************************************/ +/** Identifiers of APS states. */ +typedef uint16_t ApsStateId_t; + +#define APS_INITIAL_STATE_ID 0x100 +#define APS_RESETTING_STATE_ID 0x200 +#define APS_RESET_STATE_ID 0x300 +#define APS_START_STATE_ID 0x400 +#define APS_STOPPING_STATE_ID 0x500 +#define APS_STOP_STATE_ID 0x600 +#define APS_HOT_RESETTING_STATE_ID 0x700 + +/** Identifiers of APS components. */ +typedef uint8_t ApsComponentId_t; + +#define APS_CONTROL_MANAGER_ID 0x00 +#define APS_DATA_MANAGER_ID 0x01 +#define APS_SECURITY_MANAGER_ID 0x02 +#define APS_BIND_MANAGER_ID 0x03 +#define APS_AIB_MANAGER_ID 0x04 +#define APS_KEY_ESTABLISHMENT_ID 0x05 +#define APS_MAX_COMPONENT_ID 6 + +/** Identifier masks of APS components. */ +typedef ApsStateId_t ApsComponent_t; + +#define APS_DENIED_ACCESS 0U +#define APS_CONTROL_MANAGER (1U << APS_CONTROL_MANAGER_ID) +#define APS_DATA_MANAGER (1U << APS_DATA_MANAGER_ID) +#define APS_SECURITY_MANAGER (1U << APS_SECURITY_MANAGER_ID) +#define APS_BIND_MANAGER (1U << APS_BIND_MANAGER_ID) +#define APS_AIB_MANAGER (1U << APS_AIB_MANAGER_ID) +#define APS_KEY_ESTABLISHMENT (1U << APS_KEY_ESTABLISHMENT_ID) + +/** APS component's permitions. */ +typedef ApsComponent_t ApsPermitions_t; + +#define APS_INITIAL_STATE_PERM APS_AIB_MANAGER +#define APS_RESETING_STATE_PERM APS_DENIED_ACCESS +#define APS_RESET_STATE_PERM (APS_AIB_MANAGER | APS_KEY_ESTABLISHMENT) +#define APS_START_STATE_PERM \ + (APS_CONTROL_MANAGER | APS_AIB_MANAGER | APS_SECURITY_MANAGER \ + | APS_DATA_MANAGER | APS_BIND_MANAGER | APS_KEY_ESTABLISHMENT) +#define APS_STOPPING_STATE_PERM APS_DENIED_ACCESS +#define APS_STOP_STATE_PERM APS_AIB_MANAGER + + +/** Global states of APS layer. */ +typedef ApsStateId_t ApsState_t; + +#define APS_NO_INIT_STATE 0U +#define APS_INITIAL_STATE (APS_INITIAL_STATE_ID | APS_INITIAL_STATE_PERM) +#define APS_RESETTING_STATE (APS_RESETTING_STATE_ID | APS_RESETING_STATE_PERM) +#define APS_RESET_STATE (APS_RESET_STATE_ID | APS_RESET_STATE_PERM) +#define APS_START_STATE (APS_START_STATE_ID | APS_START_STATE_PERM) +#define APS_STOPPING_STATE (APS_STOPPING_STATE_ID | APS_STOPPING_STATE_PERM) +#define APS_STOP_STATE (APS_STOP_STATE_ID | APS_STOP_STATE_PERM) +#define APS_HOT_RESETTING_STATE \ + (APS_HOT_RESETTING_STATE_ID | APS_RESETING_STATE_PERM) +#define IS_VALID_APS_STATE(state) \ + ((APS_INITIAL_STATE <= (state)) && ((state) <= APS_HOT_RESETTING_STATE)) + +/****************************************************************************** + Global variables section + ******************************************************************************/ +/** Current state of APS layer. */ +extern ApsState_t apsState; + +/****************************************************************************** + Inline functions section + *****************************************************************************/ +/***************************************************************************** + \brief Peforms the setting of APS current state to specified state. + + \param[in] newState - state will be set. + \return None. + *****************************************************************************/ +INLINE void apsSetState(const ApsState_t newState) +{ + apsState = newState; +} + +/***************************************************************************** + \brief Returns the APS State Machine current state. + *****************************************************************************/ +INLINE ApsState_t apsGetState(void) +{ + return apsState; +} +/***************************************************************************** + \brief The function performs checking the certain layer component + availability in depending on the APS State Machine. + + \param[in] component - identifier mask of APS component. + \return true - component specified is available, + false - component specified is unavailable. + *****************************************************************************/ +INLINE bool apsCheckState(const ApsComponent_t component) +{ + return APS_DENIED_ACCESS != (apsState & component); +} + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/***************************************************************************** + \brief Main task handler of APS State Machine. + *****************************************************************************/ +APS_PRIVATE void apsStateMachineTaskHandler(void); + +/****************************************************************************** + \brief Check stop procedure complete. + + Checking all APS components are stopped and peform APS_StopConf if it is true. + + \param[in] component - already stopped APS component. + + \return None. + ******************************************************************************/ +APS_PRIVATE void apsCompleteStop(const ApsComponent_t component); + +#endif /* _APS_STATE_H */ +/** eof apsState.h */ + diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsSwitchKey.h b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsSwitchKey.h new file mode 100644 index 00000000..98a6e306 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsSwitchKey.h @@ -0,0 +1,61 @@ +/**************************************************************************//** + \file apsSwitchKey.h + + \brief Private interface of APS Switch Key. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 2011-03-21 A. Razinkov - Created. + Last change: + $Id: apsSwitchKey.h 17470 2011-06-10 11:31:00Z mgekk $ + ******************************************************************************/ +#ifndef _APS_SWITCH_KEY_H +#define _APS_SWITCH_KEY_H + +#ifdef _SECURITY_ +/****************************************************************************** + Includes section + ******************************************************************************/ +#include +#include +#include +#include + +/****************************************************************************** + Types section + ******************************************************************************/ +BEGIN_PACK +/** Type of APS remove device command frame. */ +typedef struct PACK _ApsSwitchKeyFrame_t +{ + /** An APS header, which comprises frame control and addressing information. */ + ApduCommandHeader_t header; + /** A sequence number assigned to a network key by the Trust Center and used to + * distinguish network keys. */ + uint8_t keySeqNumber; +} ApsSwitchKeyFrame_t; +END_PACK + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/**************************************************************************//** + \brief Switch key command indication handler. + + \param[in] commandInd - pointer to received command descriptor. + + \return 'true' if NWK buffer with the command frame must be freed + otherwise return 'false'. + ******************************************************************************/ +APS_PRIVATE bool apsSwitchKeyInd(const ApsCommandInd_t *const commandInd); + +#endif /* _SECURITY_ */ +#endif /* _APS_SWITCH_KEY_H */ +/** eof apsSwitchKey.h */ diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsTaskManager.h b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsTaskManager.h new file mode 100644 index 00000000..04035896 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsTaskManager.h @@ -0,0 +1,68 @@ +/**************************************************************************//** + \file apsTaskManager.h + + \brief Header file of APS task manager. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 2010-12-12 Max Gekk - Created. + Last change: + $Id: apsTaskManager.h 17470 2011-06-10 11:31:00Z mgekk $ + ******************************************************************************/ +#if !defined _APS_TASK_MANAGER_H +#define _APS_TASK_MANAGER_H + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include + +/****************************************************************************** + Types section + ******************************************************************************/ +/** Identifiers of APS task handlers. */ +typedef enum _ApsTaskID_t +{ + APS_TASK_STATE_MACHINE, + APS_TASK_DATA, + APS_TASK_SECURITY, + APS_TASK_COMMAND_REQ, + APS_TASK_AUTH_REQ, + APS_TASK_SKKE_REQ, + APS_TASK_SKKE_RESP, + APS_TASK_TRANSPORT_KEY, + APS_TASKS_SIZE +} ApsTaskID_t; + +/** Bit array of APS task. If bit is '1' the task is posted. */ +typedef uint8_t ApsTaskBitMask_t; + +/** Type of iterator for task identifiers. */ +typedef uint8_t ApsTaskIdIter_t; + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/****************************************************************************** + \brief post APS task. + + \param taskID - identifier of APS task. + \return None. + ******************************************************************************/ +APS_PRIVATE void apsPostTask(const ApsTaskID_t taskID); + +/****************************************************************************** + \brief Reset the APS task manager. + ******************************************************************************/ +APS_PRIVATE void apsResetTaskManager(void); + +#endif /* _APS_TASK_MANAGER_H */ +/** eof apsTaskManager.h */ + diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsTransportAppKey.h b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsTransportAppKey.h new file mode 100644 index 00000000..63cd87e0 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsTransportAppKey.h @@ -0,0 +1,84 @@ +/**************************************************************************//** + \file apsTransportAppKey.h + + \brief Interface of transport application key. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008 , Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 2011-05-05 Max Gekk - Created. + Last change: + $Id: apsTransportAppKey.h 17813 2011-07-04 14:11:12Z dloskutnikov $ + ******************************************************************************/ +#if !defined _APS_TRANSPORT_APP_KEY_H +#define _APS_TRANSPORT_APP_KEY_H + +/****************************************************************************** + Includes section + ******************************************************************************/ +#if defined _SECURITY_ && defined _LINK_SECURITY_ +#include + +/****************************************************************************** + Types section + ******************************************************************************/ +BEGIN_PACK +/** Type of Transport-Key Command Frame (see ZigBee spec r19, Figure 4.8 + * with application master or link key descriptor field (see Figure 4.11). */ +typedef struct PACK _ApsTransportAppKeyFrame_t +{ + /** Common part of APS transport key command frame. */ + ApsTransportKeyCommonFrame_t common; + /** The key sub-field shall contain a master or link key that is shared + * with the device identified in the partner address sub-field. See ZigBee + * Specification, 4.4.9.2.3.3, page 481. */ + uint8_t key[SECURITY_KEY_SIZE]; + /** The partner address sub-field shall contain the address of the other + * device that was sent this link or master key. */ + uint8_t partnerAddress[sizeof(ExtAddr_t)]; + /** The initiator flag sub-field shall be set to 1 if the device receiving + * this packet requested this key. Otherwise, this sub-field shall be set + * to 0. See ZigBee spec r19, 4.4.9.2.3.3, Figure 4.11, page 481. */ + uint8_t initiatorFlag; +} ApsTransportAppKeyFrame_t; +END_PACK + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +#if defined _TRUST_CENTRE_ +/**************************************************************************//** + \brief Checks specific parameters of Transport Application Key request. + + \param[in] req - pointer to parameters of APSME-TRANSPORT-KEY.request. + \return Pointer to function for preparing and sending APS Transport Key command. + ******************************************************************************/ +APS_PRIVATE ApsTransportKeyCommand_t +apsCheckTransportAppKeyReq(APS_TransportKeyReq_t *const req); +#endif /* _TRUST_CENTRE_ */ + +/**************************************************************************//** + \brief Process an incoming transport key command with application key. + + \param[in] commandInd - pointer to received command descriptor. + + \return 'false' if structure commandInd->nwkDataInd is used otherwise 'true'. + ******************************************************************************/ +APS_PRIVATE bool apsTransportAppKeyInd(const ApsCommandInd_t *const commandInd); + +#else +#define apsTransportAppKeyInd(commandInd) (true) +#endif /* _SECURITY_ and _LINK_SECURITY_ */ + +#if !(defined _SECURITY_ && defined _LINK_SECURITY_ && defined _TRUST_CENTRE_) + +#define apsCheckTransportAppKeyReq(req) NULL +#endif +#endif /* _APS_TRANSPORT_APP_KEY_H */ +/** eof apsTransportAppKey.h */ diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsTransportKey.h b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsTransportKey.h new file mode 100644 index 00000000..989f5dd6 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsTransportKey.h @@ -0,0 +1,118 @@ +/**************************************************************************//** + \file apsTransportKey.h + + \brief Private interface of transport key implementation. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008 , Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 2011-05-05 Max Gekk - Created. + Last change: + $Id: apsTransportKey.h 18405 2011-08-31 15:42:23Z mgekk $ + ******************************************************************************/ +#if !defined _APS_TRANSPORT_KEY_H +#define _APS_TRANSPORT_KEY_H + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include +#include + +#if defined _SECURITY_ +/****************************************************************************** + Definitions section + ******************************************************************************/ +/* The macro checks the source is trusted - himself or Trust Center. */ +#define IS_SOURCE_TRUSTED(commandInd) ((commandInd)->nwkDataInd->boomerang \ + || (APS_SECURED_HASH_OF_TRUST_CENTER_LINK_KEY_STATUS == (commandInd)->securityStatus) \ + || (APS_SECURED_TRUST_CENTER_LINK_KEY_STATUS == (commandInd)->securityStatus)) + +/****************************************************************************** + Types section + ******************************************************************************/ +/* Type of function for preparing and sending a transport key command. */ +typedef void (* ApsTransportKeyCommand_t)(APS_TransportKeyReq_t *const req); +BEGIN_PACK +/* Type of common part of APS Transport Key command. */ +typedef struct PACK _ApsTransportKeyCommonFrame_t +{ + /** An APS header, which comprises frame control and addressing information. */ + ApduCommandHeader_t header; + /** This field describes the type of key being transported. The different + * types of keys are enumerated in Table 4.12 of ZigBee spec r19. */ + uint8_t keyType; +} ApsTransportKeyCommonFrame_t; +END_PACK + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/**************************************************************************//** + \brief Main task handler of APS Transport Key component. + ******************************************************************************/ +APS_PRIVATE void apsTransportKeyTaskHandler(void); + +#if defined _TRUST_CENTRE_ +/**************************************************************************//** + \brief Process confirmation of APS transport key command transmission. + + \param[in] commandReq - pointer to APS command request. + \param[in] status - command transmission status. + + \return None. + ******************************************************************************/ +APS_PRIVATE void apsConfirmTransportKeyCommand(ApsCommandReq_t *const commandReq, + const APS_Status_t status); + +/**************************************************************************//** + \brief Initialization of common fields of APS Transport key command frame. + + \param[in] commonFields - common sub-frame of transport key frame. + \param[in] keyType - type of key in the transport key command frame. + + \return None. + ******************************************************************************/ +APS_PRIVATE void +apsInitCommonTransportKeyFields(ApsTransportKeyCommonFrame_t *const commonFields, + const APS_TransportKeyType_t keyType); +#endif /* _TRUST_CENTRE_ */ + +/**************************************************************************//** + \brief Process an incoming transport key command frame. + + \param[in] commandInd - pointer to received command descriptor. + \return 'true' if NWK_DataInd_t structure is not used otherwise return 'false'. + ******************************************************************************/ +APS_PRIVATE bool apsTransportKeyInd(const ApsCommandInd_t *const commandInd); + +/**************************************************************************//** + \brief Forward a transport key command to unauthenticated child. + + \param[in] commandInd - pointer to received command descriptor. + \param[in] dstExtAddr - pointer to raw extended address from received frame. + \param[in] apsSendKeyToChildConf - NLDE-DATA confirm callback function's pointer. + + \return 'true' if NWK_DataInd_t structure is not used otherwise return 'false'. + ******************************************************************************/ +APS_PRIVATE bool apsForwardKeyToChild(const ApsCommandInd_t *const commandInd, + const uint8_t *const dstExtAddr, + void (* apsSendKeyToChildConf)(NWK_DataConf_t *conf)); + +/**************************************************************************//** + \brief Reset the internal queue and variables of Transport Key component. + ******************************************************************************/ +APS_PRIVATE void apsTransportKeyReset(void); + +#else +#define apsTransportKeyTaskHandler NULL +#define apsTransportKeyReset() (void)0 +#endif /* _SECURITY_ */ +#endif /* _APS_TRANSPORT_KEY_H */ +/** eof apsTransportKey.h */ diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsTransportNwkKey.h b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsTransportNwkKey.h new file mode 100644 index 00000000..c1406631 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsTransportNwkKey.h @@ -0,0 +1,130 @@ +/**************************************************************************//** + \file apsTransportNwkKey.h + + \brief Interface of NWK key transport. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008 , Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 2011-05-15 Max Gekk - Created. + Last change: + $Id: apsTransportNwkKey.h 17549 2011-06-15 09:36:29Z mgekk $ + ******************************************************************************/ +#if !defined _APS_TRANSPORT_NWK_KEY_H +#define _APS_TRANSPORT_NWK_KEY_H + +#if defined _SECURITY_ +/****************************************************************************** + Includes section + ******************************************************************************/ +#include + +/****************************************************************************** + Define(s) section + ******************************************************************************/ +/* Tunneled auxiliary header consists of: + * - security control field (1 octet), + * - frame counter field (4 octets), + * - source address (8 octets) */ +#define APS_TUNNELED_AUXILIARY_HEADER_LEN 13 +/* See ZigBee spec. r18, page 493, Table 4.38. For security level = 0x05. */ +#define APS_TUNNELED_MIC_LEN 4 + +#define APS_TRANSPORT_NWK_KEY_PAYLOAD_LEN \ + (sizeof(ApsTransportNwkKeyFrame_t) - sizeof(ApduCommandHeader_t)) + +/****************************************************************************** + Types section + ******************************************************************************/ +BEGIN_PACK +/** Type of Transport-Key Command Frame (see ZigBee spec r19, Figure 4.8 + * with network key descriptor field (see Figure 4.10, page 480). */ +typedef struct PACK _ApsTransportNwkKeyFrame_t +{ + /** Common part of APS transport key command frame. */ + ApsTransportKeyCommonFrame_t common; + /** The key sub-field shall contain a network key. */ + uint8_t key[SECURITY_KEY_SIZE]; + /** The sequence number sub-field shall contain the sequence number associated + * with this network key. See ZigBee spec r19, 4.4.9.2.3.2 */ + NWK_KeySeqNum_t keySeqNumber; + /** The destination address sub-field shall contain the address of the device + * which should use this network key. See ZigBee spec r19, page 480. */ + uint8_t destinationAddress[sizeof(ExtAddr_t)]; + /** The source address field sub-shall contain the address of the device + * (for example, the Trust Center) which originally sent this network key. + * See ZigBee Specification r19, 4.4.9.2.3.2, page 480. */ + uint8_t sourceAddress[sizeof(ExtAddr_t)]; +} ApsTransportNwkKeyFrame_t; + +/** + * \brief Tunnel command frame payload. + * + * See ZigBee spec. r18, 4.4.9.8, page 490, Figure 4.22. + **/ +typedef struct PACK _ApsTunnelCommandFrame_t +{ + /** An APS header, which comprises frame control and addressing information. */ + ApduCommandHeader_t header; + /** The 64-bit extended address of the device that is to receive the tunnelled command. */ + uint8_t dstAddr[sizeof(ExtAddr_t)]; + /** APS base header of the tunneled command: frame control and APS counter. */ + ApduCommandBaseHeader_t tunneledHeader; + /** The tunneled auxiliary frame indicate that a link key was used + * and shall included the extended nonce field. ZigBee spec. r18, 4.4.9.8.3, page 491.*/ + uint8_t tunneledAuxHeader[APS_TUNNELED_AUXILIARY_HEADER_LEN]; + /** Identifier of the tunneled APS command. */ + uint8_t commandId; + /** The tunnelled command field shall be the APS command frame to be sent to the + * destination. See ZigBee spec. r18, 4.4.9.8.4 and Figure 4.22. */ + uint8_t tunneledPayload[APS_TRANSPORT_NWK_KEY_PAYLOAD_LEN]; + /** Tunneled APS MIC. See ZigBee spec. r18, page 490, Figure 4.22. */ + uint8_t mic[APS_TUNNELED_MIC_LEN]; +} ApsTunnelCommandFrame_t; +END_PACK + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +#if defined _TRUST_CENTRE_ +/**************************************************************************//** + \brief Checks specific parameters of Transport Nwk Key request. + + \param[in] req - pointer to parameters of APSME-TRANSPORT-KEY.request. + \return Pointer to function for preparing and sending APS Transport Key command. + ******************************************************************************/ +APS_PRIVATE ApsTransportKeyCommand_t +apsCheckTransportNwkKeyReq(APS_TransportKeyReq_t *const req); +#endif /* _TRUST_CENTRE_ */ + +/**************************************************************************//** + \brief Processing of a tunneling APS command. + + Extracting the embedded tunnel command and send it to destination. + + \param[in] commandInd - pointer to parameter's structure of received frame. + \return 'true' if NWK buffer should be released otherwise 'false'. + ******************************************************************************/ +APS_PRIVATE bool apsTunnelInd(const ApsCommandInd_t *const commandInd); + +/**************************************************************************//** + \brief Process an incoming transport key command with NWK key. + + \param[in] commandInd - pointer to received command descriptor. + + \return 'false' if structure commandInd->nwkDataInd is used otherwise 'true'. + ******************************************************************************/ +APS_PRIVATE bool apsTransportNwkKeyInd(const ApsCommandInd_t *const commandInd); + +#if !defined _TRUST_CENTRE_ +#define apsCheckTransportNwkKeyReq(req) NULL +#endif +#endif /* _SECURITY_ */ +#endif /* _APS_TRANSPORT_NWK_KEY_H */ +/** eof apsTransportNwkKey.h */ diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsTransportTrustKey.h b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsTransportTrustKey.h new file mode 100644 index 00000000..3a7c8626 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsTransportTrustKey.h @@ -0,0 +1,83 @@ +/**************************************************************************//** + \file apsTransportTrustKey.h + + \brief Interface of transport key from the trust center. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008 , Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 2011-05-08 Max Gekk - Created. + Last change: + $Id: apsTransportTrustKey.h 17813 2011-07-04 14:11:12Z dloskutnikov $ + ******************************************************************************/ +#if !defined _APS_TRANSPORT_TRUST_KEY_H +#define _APS_TRANSPORT_TRUST_KEY_H + +#if defined _SECURITY_ && defined _LINK_SECURITY_ +/****************************************************************************** + Includes section + ******************************************************************************/ +#include + +/****************************************************************************** + Types section + ******************************************************************************/ +BEGIN_PACK +/** Type of Transport-Key Command Frame (see ZigBee spec r19, Figure 4.8 + * with trust center master or link key descriptor field (see Figure 4.9). */ +typedef struct PACK _ApsTransportTrustKeyFrame_t +{ + /** Common part of APS transport key command frame. */ + ApsTransportKeyCommonFrame_t common; + /** The key sub-field shall contain the master key that should be used to set + * up link keys with the Trust Center or link key. */ + uint8_t key[SECURITY_KEY_SIZE]; + /** The destination address sub-field shall contain the address of the device + * which should use this master or link key. ZigBee spec r19, page 480. */ + uint8_t destinationAddress[sizeof(ExtAddr_t)]; + /** The source address sub-field shall contain the address of the device (for + * example, the Trust Center) which originally sent this master key. + * See ZigBee Specification r19, 4.4.9.2.3.1, page 480. */ + uint8_t sourceAddress[sizeof(ExtAddr_t)]; +} ApsTransportTrustKeyFrame_t; +END_PACK + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +#if defined _TRUST_CENTRE_ +/**************************************************************************//** + \brief Checks specific parameters of Transport Trust Key request. + + \param[in] req - pointer to parameters of APSME-TRANSPORT-KEY.request. + \return Pointer to function for preparing and sending APS Transport Key command. + ******************************************************************************/ +APS_PRIVATE ApsTransportKeyCommand_t +apsCheckTransportTrustKeyReq(APS_TransportKeyReq_t *const req); +#endif /* _TRUST_CENTRE_ */ + +/**************************************************************************//** + \brief Process an incoming trust link or master key. + + \param[in] commandInd - pointer to received command descriptor. + + \return 'false' if structure commandInd->nwkDataInd is used otherwise 'true'. + ******************************************************************************/ +APS_PRIVATE bool apsTransportTrustKeyInd(const ApsCommandInd_t *const commandInd); + +#else +#define apsTransportTrustKeyInd(commandInd) (true) +#endif /* _SECURITY_ and _LINK_SECURITY_ */ + +#if !(defined _SECURITY_ && defined _LINK_SECURITY_ && defined _TRUST_CENTRE_) + +#define apsCheckTransportTrustKeyReq(req) NULL +#endif +#endif /* _APS_TRANSPORT_TRUST_KEY_H */ +/* eof apsTransportTrustKey.h */ diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsUpdateDevice.h b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsUpdateDevice.h new file mode 100644 index 00000000..39765708 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/private/apsUpdateDevice.h @@ -0,0 +1,64 @@ +/**************************************************************************//** + \file apsUpdateDevice.h + + \brief Private interface of APS Update Device. + + \author + Atmel Corporation: http://www.atmel.com \n + Support email: avr@atmel.com + + Copyright (c) 2008-2011, Atmel Corporation. All rights reserved. + Licensed under Atmel's Limited License Agreement (BitCloudTM). + + \internal + History: + 2010-12-18 Max Gekk - Created. + Last change: + $Id: apsUpdateDevice.h 17470 2011-06-10 11:31:00Z mgekk $ + ******************************************************************************/ +#if !defined _APS_UPDATE_DEVICE_H +#define _APS_UPDATE_DEVICE_H + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include +#include +#include + +#if defined _SECURITY_ +/****************************************************************************** + Types section + ******************************************************************************/ +BEGIN_PACK +/** Type of APS update device command frame. */ +typedef struct PACK _ApsUpdateDeviceFrame_t +{ + /** An APS header, which comprises frame control and addressing information. */ + ApduCommandHeader_t header; + /** The 64-bit extended address of the device whose status is being updated.*/ + ExtAddr_t deviceAddress; + /** The 16-bit network address of the device whose status is being updated. */ + ShortAddr_t deviceShortAddress; + /** The status field shall be assigned a value as described for the Status + * parameter in ZigBee spec r19, Table 4.20. */ + uint8_t status; +} ApsUpdateDeviceFrame_t; +END_PACK + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/**************************************************************************//** + \brief Update device indication handler. + + \param[in] commandInd - pointer to received command descriptor. + + \return 'true' if NWK buffer with the command frame must be freed + otherwise return 'false'. + ******************************************************************************/ +APS_PRIVATE bool apsUpdateDeviceInd(const ApsCommandInd_t *const commandInd); + +#endif /* _SECURITY_ */ +#endif /* _APS_UPDATE_DEVICE_H */ +/** eof apsUpdateDevice.h */ -- cgit v1.2.3