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 --- .../bitcloud/stack/Components/APS/include/aps.h | 196 ++++++++++ .../bitcloud/stack/Components/APS/include/apsAIB.h | 177 +++++++++ .../stack/Components/APS/include/apsCommon.h | 412 ++++++++++++++++++++ .../stack/Components/APS/include/apsConfigServer.h | 37 ++ .../stack/Components/APS/include/apsCryptoKeys.h | 426 +++++++++++++++++++++ .../stack/Components/APS/include/apsTcSwapOut.h | 59 +++ .../stack/Components/APS/include/apsdeData.h | 319 +++++++++++++++ .../stack/Components/APS/include/apsdeEndpoint.h | 203 ++++++++++ .../Components/APS/include/apsmeAuthenticate.h | 195 ++++++++++ .../stack/Components/APS/include/apsmeBind.h | 189 +++++++++ .../Components/APS/include/apsmeEstablishKey.h | 317 +++++++++++++++ .../stack/Components/APS/include/apsmeGroup.h | 173 +++++++++ .../Components/APS/include/apsmeRemoveDevice.h | 145 +++++++ .../stack/Components/APS/include/apsmeRequestKey.h | 175 +++++++++ .../stack/Components/APS/include/apsmeSwitchKey.h | 155 ++++++++ .../Components/APS/include/apsmeTransportKey.h | 292 ++++++++++++++ .../Components/APS/include/apsmeUpdateDevice.h | 165 ++++++++ .../stack/Components/APS/include/intrpData.h | 194 ++++++++++ .../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 ++++ 44 files changed, 6978 insertions(+) create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/aps.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/apsAIB.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/apsCommon.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/apsConfigServer.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/apsCryptoKeys.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/apsTcSwapOut.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/apsdeData.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/apsdeEndpoint.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/apsmeAuthenticate.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/apsmeBind.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/apsmeEstablishKey.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/apsmeGroup.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/apsmeRemoveDevice.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/apsmeRequestKey.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/apsmeSwitchKey.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/apsmeTransportKey.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/apsmeUpdateDevice.h create mode 100644 digital/zigbit/bitcloud/stack/Components/APS/include/intrpData.h 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') diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/aps.h b/digital/zigbit/bitcloud/stack/Components/APS/include/aps.h new file mode 100644 index 00000000..a9933759 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/aps.h @@ -0,0 +1,196 @@ +/**************************************************************************//** + \file aps.h + + \brief Interface 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: + 2010-10-20 Max Gekk - Created. + Last change: + $Id: aps.h 17448 2011-06-09 13:53:59Z ataradov $ + ******************************************************************************/ +#if !defined _APS_H +#define _APS_H +/**//** + * \page Endian + * \note \b |LE| - parameter in little endian format. + * + * Use macroes CPU_TO_LE* and CCPU_TO_LE* from bcEndian.h to convert from + * CPU-endian to little-endian format. + **/ + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/****************************************************************************** + Types section + ******************************************************************************/ +/** External events identifiers. */ +typedef enum +{ + APS_EVENT_RESET_ID = 0x19, + APS_EVENT_START_ID = 0x8a, + APS_EVENT_STOP_ID = 0xc5 +} APS_EventId_t; + +/** Type of external APS event. */ +typedef struct +{ + void *next; /*!< Used for queue support. */ + APS_EventId_t id; /*!< Identifier of APS event. */ +} APS_Event_t; + +/** Confirmation parameters of APS Reset. */ +typedef struct +{ + APS_Status_t status; +} APS_ResetConf_t; + +/** Type of APS Reset parameters structure. */ +typedef struct +{ + /** \cond SERVICE_FIELDS **/ + struct + { + APS_Event_t event; + /** NLME-RESET request primitive's parameters structure. */ + NWK_ResetReq_t nwkResetReq; + } service; + /** \endcond **/ + + NWK_PowerFailureControl_t powerFailureControl; /*!< To restore or not the saved parameters? */ + /** This field shall contain the device capability information. + * See ZigBee spec r18, Table 3.44, page 345. */ + MAC_CapabilityInf_t capabilityInformation; + /** APS reset confirm callback function's pointer. */ + void (*APS_ResetConf)(APS_ResetConf_t *conf); + APS_ResetConf_t confirm; /*!< Parameters are passed to callback function. */ +} APS_ResetReq_t; + +/** Type of startup confirmation parameters. */ +typedef struct +{ + APS_Status_t status; /*!< Status code of APS startup. */ +} APS_StartConf_t; + +/** Parameters of APS start procedure. */ +typedef struct +{ + /** \cond SERVICE_FIELDS **/ + struct + { + APS_Event_t event; + } service; + /** \endcond **/ + + /** APS startup callback function. */ + void (*APS_StartConf)(APS_StartConf_t *conf); + APS_StartConf_t confirm; /*!< APS startup confirmation parameters. */ +} APS_StartReq_t; + +/** Type of APS stoping confirmation parameters. */ +typedef struct +{ + APS_Status_t status; /*!< Status code of APS stoping. */ +} APS_StopConf_t; + +/** Parameters of APS stoping primitive. */ +typedef struct +{ + /** \cond SERVICE_FIELDS **/ + struct + { + APS_Event_t event; + uint16_t waitMask; /*! Bit map of stopping components. */ + } service; + /** \endcond **/ + + /** Callback and APS stoping confirmation function. */ + void (*APS_StopConf)(APS_StopConf_t *conf); + APS_StopConf_t confirm; +} APS_StopReq_t; + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/**************************************************************************//** + \brief Initialization internal state and main variables of APS-layer. + + The function can be called only by ZDO. + It must be called before any operation with APS. + + \return None. + ******************************************************************************/ +void APS_Init(void); + +/**************************************************************************//** + \brief Resets APS to default state. + + The function can be called only by ZDO and only after APS_Init(). + + \param[in] req - pointer to reset parameters. + \return None. + *****************************************************************************/ +void APS_ResetReq(APS_ResetReq_t *const req); + +/**************************************************************************//** + \brief Makes APS allow processing of incoming packets. + + After this function is called, APS is ready to process incoming packets. + + \param[in] req - pointer to startup parameters. + \return None. + ******************************************************************************/ +void APS_StartReq(APS_StartReq_t *const req); + +/**************************************************************************//** + \brief Makes APS disallow processing of incoming packets. + + After this function is called, APS does not process incoming packets. + + \param[in] req - pointer to stopping parameters. + \return None. + ******************************************************************************/ +void APS_StopReq(APS_StopReq_t *const req); + +/**************************************************************************//** + \brief Check if APS is started. + + \return 'true' if APS is started otherwise return 'false' + ******************************************************************************/ +bool APS_IsStarted(void); + +/**************************************************************************//** + \brief Check if there are any active requests in progress. + + \return 'true' if there are any active requests in progress otherwise - 'false' + ******************************************************************************/ +bool APS_IsActiveTransaction(void); + +#endif /* _APS_H */ +/** eof aps.h */ + diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/apsAIB.h b/digital/zigbit/bitcloud/stack/Components/APS/include/apsAIB.h new file mode 100644 index 00000000..428c254d --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/apsAIB.h @@ -0,0 +1,177 @@ +/**************************************************************************//** + \file apsAIB.h + + \brief Interface of APS information base. + + \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-19 Max Gekk - Created. + Last change: + $Id: apsAIB.h 18613 2011-09-20 13:15:05Z mgekk $ + ******************************************************************************/ +/**//** + * + * The APS information base comprises the attributes required to manage the APS + * layer of a device. The attributes of the AIB are listed in ZigBee spec r19, + * Table 2.24, page 61. The securityrelated AIB attributes are described in + * sub-clause 4.4.10, page 489. + **/ +#if !defined _APS_AIB_H +#define _APS_AIB_H + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include +#include + +/****************************************************************************** + Definitions section +******************************************************************************/ +#define APS_AIB_NONMEMBER_RADIUS_DEFAULT_VALUE 2 + +/****************************************************************************** + Types section + ******************************************************************************/ +/**//** + * \struct AIB_t apsAIB.h "aps.h" + * + * \brief Attributes in APS Information Base. + **/ +typedef struct +{ + /** The value to be used for the NonmemberRadius parameter when using + * NWK layer multicast. Valid range: 0 - 7, default value - 2. */ + NwkRadius_t nonMemberRadius; +#if defined _SECURITY_ + /** \ref Endian "[LE]" Identifies the address of the device's Trust Center. */ + ExtAddr_t trustCenterAddress; +#endif /* _SECURITY_ */ +#ifdef _APS_FRAGMENTATION_ + uint8_t fragWindowSize; +#ifdef _CERTIFICATION_ + uint8_t fragDropMask; +#endif /* _CERTIFICATION_ */ +#endif /* _APS_FRAGMENTATION_ */ +} AIB_t; + +/**//** + * \struct APS_TcMode_t apsAIB.h "aps.h" + * + * \brief Mode indicate role of this device in the network as trust center. + **/ +typedef enum _APS_TcMode_t +{ + APS_NOT_TRUST_CENTER, + APS_CENTRALIZED_TRUST_CENTER, + /** Mode whereby routers in a ZigBee Pro network can each act like a trust + * center so that there is no need for a single centralized device. */ + APS_DISTRIBUTED_TRUST_CENTER +} APS_TcMode_t; + +/****************************************************************************** + Global variables section + ******************************************************************************/ +extern AIB_t csAIB; /*!< APS Information Base */ + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +#if defined _SECURITY_ +/**************************************************************************//** + \brief Check whether supplied address is a Trust Center address + + \param[in] addr - pointer to required address + + \return true, if required address is TC address, false - otherwise +******************************************************************************/ +INLINE bool APS_IsTcAddress(const ExtAddr_t *addr) +{ + return IS_EQ_EXT_ADDR(*addr, csAIB.trustCenterAddress); +} + +/**************************************************************************//** + \brief Get pointer to Trust Center address + + \return pointer to Trust Center extended address +******************************************************************************/ +INLINE ExtAddr_t* APS_GetTrustCenterAddress(void) +{ + return &csAIB.trustCenterAddress; +} + +/**************************************************************************//** + \brief Set Trust Center address + + \param[in] addr - pointer to address to set + + \return none +******************************************************************************/ +INLINE void APS_SetTrustCenterAddress(const ExtAddr_t *addr) +{ + memcpy(&csAIB.trustCenterAddress, addr, sizeof(ExtAddr_t)); +} + +/**************************************************************************//** + \brief Gets the trust center mode of the current device. + + \return Status of the device as Trust Center: + \li APS_NOT_TRUST_CENTER - this deive is not trust center, + \li APS_CENTRALIZED_TRUST_CENTER - single trust center in the network, + \li APS_DISTRIBUTED_TRUST_CENTER - each routers can be trust center. +******************************************************************************/ +INLINE APS_TcMode_t APS_GetOwnTcMode(void) +{ +#if defined _DISTRIBUTED_TRUST_CENTER_ + if (APS_DISTRIBUTED_TC_ADDRESS == csAIB.trustCenterAddress) + return APS_DISTRIBUTED_TRUST_CENTER; +#endif /* _DISTRIBUTED_TRUST_CENTER_ */ + + if (IS_EQ_EXT_ADDR(*MAC_GetExtAddr(), csAIB.trustCenterAddress)) + return APS_CENTRALIZED_TRUST_CENTER; + else + return APS_NOT_TRUST_CENTER; +} + +/**************************************************************************//** + \brief Check whether this node is the Trust Center or not. + + \return true, if this node is the Distributed or Centralized Trust Center, + otherwise return false. +******************************************************************************/ +INLINE bool APS_IsTrustCenter(void) +{ + return APS_NOT_TRUST_CENTER != APS_GetOwnTcMode(); +} + +/**************************************************************************//** + \brief Check whether given address is trusted address. + + \param[in] addr - pointer to required address + + \return true, if argument is the address of the centralized Trust Center + or we are in distributed TC mode, + otherwise return false. +******************************************************************************/ +INLINE bool APS_IsTrustedAddress(const ExtAddr_t *addr) +{ +#if defined _DISTRIBUTED_TRUST_CENTER_ + if (APS_DISTRIBUTED_TC_ADDRESS == csAIB.trustCenterAddress) + return true; +#endif /* _DISTRIBUTED_TRUST_CENTER_ */ + + return IS_EQ_EXT_ADDR(*addr, csAIB.trustCenterAddress); +} + +#endif /* _SECURITY_ */ + +#endif /* _APS_AIB_H */ +/** eof apsAIB.h */ + diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/apsCommon.h b/digital/zigbit/bitcloud/stack/Components/APS/include/apsCommon.h new file mode 100644 index 00000000..49164477 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/apsCommon.h @@ -0,0 +1,412 @@ +/**************************************************************************//** + \file apsCommon.h + + \brief Declarations of common APS layer's constants and types. + + \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-07-21 Max Gekk - Created. + 2010-10-18 Max Gekk - MAC and NWK status values are added. + Last change: + $Id: apsCommon.h 18682 2011-09-28 12:59:47Z mgekk $ + ******************************************************************************/ +#if !defined _APS_COMMON_H +#define _APS_COMMON_H + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include +#include +#include + +/****************************************************************************** + Definitions section + ******************************************************************************/ + +#ifndef _LINK_SECURITY_ +/** Max APS header size. */ +#define APS_MAX_DATA_FRAME_HEADER_LENGTH 12U + +/** Max APS footer size. */ +#define APS_MAX_DATA_FRAME_FOOTER_LENGTH 0U +#else /* _LINK_SECURITY_ */ + + +/**//** + * \brief APS auxiliary header size. + * + * See ZigBee spec. r18, 4.5.1.1, Security Control Field. + **/ +#define APS_AUXILIARY_HEADER_LENGTH (6U + 8U) + +/** Max APS header size. */ +#define APS_MAX_DATA_FRAME_HEADER_LENGTH (12U + APS_AUXILIARY_HEADER_LENGTH) + +/** Max APS footer size: 4 bytes - Message Integrity Code (MIC) */ +#define APS_MAX_DATA_FRAME_FOOTER_LENGTH 4U + +/** Universal extended address. */ +#ifdef _UNIVERSAL_EXTENDED_ADDRESS_ + #define APS_UNIVERSAL_EXTENDED_ADDRESS 0xFFFFFFFFFFFFFFFBULL +#endif /* _UNIVERSAL_EXTENDED_ADDRESS_ */ + +#endif /* _LINK_SECURITY_ */ + + +/** Max size of APS payload. */ +#define APS_MAX_ASDU_SIZE \ + (NWK_MAX_NSDU_SIZE - APS_MAX_DATA_FRAME_HEADER_LENGTH - APS_MAX_DATA_FRAME_FOOTER_LENGTH) + +/** Size of the reserved header in the data frame */ +#define APS_ASDU_OFFSET \ + (NWK_NSDU_OFFSET + APS_MAX_DATA_FRAME_HEADER_LENGTH) + +/** Size of the reserved part in the data frame. */ +#define APS_AFFIX_LENGTH \ + (NWK_AFFIX_LENGTH + APS_MAX_DATA_FRAME_HEADER_LENGTH + APS_MAX_DATA_FRAME_FOOTER_LENGTH) + +/** APS Broadcast Endpoint. */ +#define APS_BROADCAST_ENDPOINT 0xff + +/** Minimum value of user endpoint number. */ +#define APS_MIN_USER_ENDPOINT 0x01 + +/** Maximum value of user endpoint number */ +#define APS_MAX_USER_ENDPOINT 0xf0 + +/** ZDO Endpoint */ +#define APS_ZDO_ENDPOINT 0x00 + +/** Reserved endpoints */ +#define APS_MIN_RESERVED_ENDPOINT 0xf1 +#define APS_MAX_RESERVED_ENDPOINT 0xfe + +/** APS short address defines */ +#define APS_MAX_UNICAST_SHORT_ADDRESS 0xfff7 + +#define APS_SM_INVALID_FRAME_COUNTER_VALUE (0xffffffffUL) + +#define APS_SM_BROADCAST_EXT_ADDRESS 0xffffffffffffffffULL +#define APS_SM_BROADCAST_ALL_EXT_ADDRESS 0xffffffffffffffffULL +#define APS_SM_BROADCAST_RX_ON_WHEN_IDLE_EXT_ADDRESS 0xfffffffffffffffdULL +#define APS_SM_BROADCAST_ALL_ROUTERS_EXT_ADDRESS 0xfffffffffffffffcULL +#define APS_SM_BROADCAST_LOW_POWER_ROUTERS_EXT_ADDRESS 0xfffffffffffffffbULL +#define APS_SM_UNIVERSAL_TRUST_CENTER_EXT_ADDRESS 0xfffffffffffffffaULL /*!< Universal trust center address*/ +#define APS_LAST_UNICAST_ADDRESS 0xfffffffffffffff9ULL +#define APS_SM_INVALID_EXT_ADDRESS 0x0000000000000000ULL + +/* Special value of apsTrustCenterAddress indicates distrubuted trust center mode. */ +#define APS_DISTRIBUTED_TC_ADDRESS APS_SM_BROADCAST_EXT_ADDRESS + +/****************************************************************************** + Types section + ******************************************************************************/ +/**//** + * \struct APS_Address_t apsCommon.h "aps.h" + * + * \brief Common APS Address type. + * + * Used as the part of standard APS primitives + **/ +typedef struct +{ + union + { + ShortAddr_t shortAddress; /*!< 16-bit network address */ +#ifdef _APS_MULTICAST_ + GroupAddr_t groupAddress; /*!< 16-bit group (multicast) address */ +#endif + }; + ExtAddr_t extAddress; /*!< 64-bit extended IEEE address */ +} APS_Address_t; + +/**//** + * \brief APS addressing modes. + * + * Defines APS addressing modes used in some standard primitives. + **/ +typedef enum +{ + /** Indirect addressing mode via binding future. */ + APS_NO_ADDRESS = 0x00, + /** Group addressing mode via multicast. */ + APS_GROUP_ADDRESS = 0x01, + /** Unicast addressing mode by 16-bit network address. */ + APS_SHORT_ADDRESS = 0x02, + /** Unicast addressing mode by 64-bit IEEE address. */ + APS_EXT_ADDRESS = 0x03 +} APS_AddrMode_t; + +/***//** + * \brief APS status values. + * + * APS status values used in the most part of standard primives except for + * the security service primitives where APS_SecurityStatus_t is used instead. + **/ +typedef enum +{ + /** A request has been executed successfully. */ + APS_SUCCESS_STATUS = 0x00, + /** IEEE 802.15.4-2006, Table 83. */ + /** Valid values of the Association Status field. */ + APS_MAC_PAN_AT_CAPACITY_STATUS = 0x01, + APS_MAC_PAN_ACCESS_DENIED_STATUS = 0x02, + /** A transmit request failed since the ASDU is too large and fragmentation + * is not supported. */ + APS_ASDU_TOO_LONG_STATUS = 0xa0, + /** A received fragmented frame could not be defragmented + * at the current time. */ + APS_DEFRAG_DEFERRED_STATUS = 0xa1, + /** A received fragmented frame could not be defragmented since the device + * does not support fragmentation. */ + APS_DEFRAG_UNSUPPORTED_STATUS = 0xa2, + /** A parameter value was out of range. */ + APS_ILLEGAL_REQUEST_STATUS = 0xa3, + /** An APSME-UNBIND.request failed due to the requested binding link not + * existing in the binding table. */ + APS_INVALID_BINDING_STATUS = 0xa4, + /** An APSME-REMOVE-GROUP.request has been issued with a group identifier + * that does not appear in the group table. */ + APS_INVALID_GROUP_STATUS = 0xa5, + /** A parameter value was invalid or out of range. */ + APS_INVALID_PARAMETER_STATUS = 0xa6, + /** An APSDE-DATA.request requesting acknowledged transmission failed due + * to no acknowledgement being received. */ + APS_NO_ACK_STATUS = 0xa7, + /** An APSDE-DATA.request with a destination addressing mode set to 0x00 + * failed due to there being no devices bound to this device. */ + APS_NO_BOUND_DEVICE_STATUS = 0xa8, + /** An APSDE-DATA.request with a destination addressing mode + * set to 0x03 failed due to no corresponding short address found + * in the address map table. */ + APS_NO_SHORT_ADDRESS_STATUS = 0xa9, + /** An APSDE-DATA.request with a destination addressing mode set to 0x00 + * failed due to a binding table not being supported on the device. */ + APS_NOT_SUPPORTED_STATUS = 0xaa, + /** An ASDU was received that was secured using a link key. */ + APS_SECURED_LINK_KEY_STATUS = 0xab, + /** An ASDU was received that was secured using a network key. */ + APS_SECURED_NWK_KEY_STATUS = 0xac, + /** An APSDE-DATA.request requesting security has resulted in an error + * during the corresponding security processing. */ + APS_SECURITY_FAIL_STATUS = 0xad, + /** An APSME-BIND.request or APSME.ADDGROUP.request issued when the binding + * or group tables, respectively, were full. */ + APS_TABLE_FULL_STATUS = 0xae, + /** An ASDU was received without any security. */ + APS_UNSECURED_STATUS = 0xaf, + /** An APSME-GET.request or APSMESET.request has been issued with an + * unknown attribute identifier. */ + APS_UNSUPPORTED_ATTRIBUTE_STATUS = 0xb0, + /** An ASDU was received that was secured using the trust center link key. */ + APS_SECURED_TRUST_CENTER_LINK_KEY_STATUS = 0xb1, + /** An ASDU was received that was secured using + * hash ofthe trust center link key. */ + APS_SECURED_HASH_OF_TRUST_CENTER_LINK_KEY_STATUS = 0xb2, + /** An invalid or out-of-range parameter has been passed to a primitive from + * the next higher layer. */ + APS_NWK_INVALID_PARAMETERS_STATUS = 0xC1, + /** The next higher layer has issued a request that is invalid or cannot be + * executed given the current state of the NWK layer. */ + APS_NWK_INVALID_REQUEST_STATUS = 0xC2, + /** An NLME-JOIN.request has been disallowed. */ + APS_NWK_NOT_PERMITTED_STATUS = 0xC3, + /** An NLME-NETWORK-FORMATION.request has failed to start a network. */ + APS_NWK_STARTUP_FAILURE_STATUS = 0xC4, + /** A device with the address supplied to the NLMEDIRECT-JOIN.request is + * already present in the neighbor table of the device on which + * the NLME-DIRECT-JOIN.request was issued. */ + APS_NWK_ALREADY_PRESENT_STATUS = 0xC5, + /** Used to indicate that an NLME-SYNC.request has failed at the MAC layer. */ + APS_NWK_SYNC_FAILURE_STATUS = 0xC6, + /** An NLME-JOIN-DIRECTLY.request has failed because there is no more room in + * the neighbor table. */ + APS_NWK_NEIGHBOR_TABLE_FULL_STATUS = 0xC7, + /** An NLME-LEAVE.request has failed because the device addressed in + * the parameter list is not in the neighbor table of the issuing device. */ + APS_NWK_UNKNOWN_DEVICE_STATUS = 0xC8, + /** An NLME-GET.request or NLME-SET.request has been issued with + * an unknown attribute identifier. */ + APS_NWK_UNSUPPORTED_ATTRIBUTE_STATUS = 0xC9, + /** An NLME-JOIN.request has been issued in an environment + * where no networks are detectable. */ + APS_NWK_NO_NETWORKS_STATUS = 0xCA, + /** Security processing has been attempted on an outgoing frame, + * and has failed because the frame counter has reached its maximum value. */ + APS_NWK_MAX_FRM_COUNTER_STATUS = 0xCC, + /** Security processing has been attempted on an outgoing frame, + * and has failed because no key was available with which to process it. */ + APS_NWK_NO_KEY_STATUS = 0xCD, + /** Security processing has been attempted on an outgoing frame, + * and has failed because the security engine produced erroneous output. */ + APS_NWK_BAD_CCM_OUTPUT_STATUS = 0xCE, + /** An attempt to discover a route has failed due to a lack of routing table + * or discovery table capacity. */ + APS_NWK_NO_ROUTING_CAPACITY_STATUS = 0xCF, + /** An attempt to discover a route has failed due to a reason other + * than a lack of routing capacity. */ + APS_NWK_ROUTE_DISCOVERY_FAILED_STATUS = 0xD0, + /** An NLDE-DATA.request has failed due to a routing + * failure on the sending device. */ + APS_NWK_ROUTE_ERROR_STATUS = 0xD1, + /** An attempt to send a broadcast frame or member mode multicast has failed + * due to the fact that there is no room in the BTT. */ + APS_NWK_BT_TABLE_FULL_STATUS = 0xD2, + /** An NLDE-DATA.request has failed due to insufficient buffering available. + **/ + APS_NWK_FRAME_NOT_BUFFERED_STATUS = 0xD3, + /** IEEE 802.15.4-2006, Table 78 MAC enumerations description. */ + /** The frame counter purportedly applied by the originator of the + * received frame is invalid. */ + APS_MAC_COUNTER_ERROR_STATUS = 0xDB, + /** The key purportedly applied by the originator of the received frame is + * not allowed to be used with that frame type according to the key usage + * policy of the recipient. */ + APS_MAC_IMPROPER_KEY_TYPE_STATUS = 0xDC, + /** The security level purportedly applied by the originator of the received + * frame does not meet the minimum security level required/expected by + * the recipient for that frame type. */ + APS_MAC_IMPROPER_SECURITY_LEVEL_STATUS = 0xDD, + /** The received frame was purportedly secured using security based on + * IEEE Std 802.15.4-2003, and such security is not supported by this standard. + **/ + APS_MAC_UNSUPPORTED_LEGACY_STATUS = 0xDE, + /** The security purportedly applied by the originator of the received frame + * is not supported. */ + APS_MAC_UNSUPPORTED_SECURITY_STATUS = 0xDF, + /** The beacon was lost following a synchronization request. */ + APS_MAC_BEACON_LOSS_STATUS = 0xE0, + /** A transmission could not take place due to activity on the channel, + * i.e., the CSMA-CA mechanism has failed. */ + APS_MAC_CHANNEL_ACCESS_FAILURE_STATUS = 0xE1, + /** The GTS request has been denied by the PAN coordinator. */ + APS_MAC_DENIED_STATUS = 0xE2, + /** The attempt to disable the transceiver has failed. */ + APS_MAC_DISABLE_TRX_FAILURE_STATUS = 0xE3, + /** Either a frame resulting from processing has a length that is + * greater than aMaxPHYPacketSize or a requested transaction is + * too large to fit in the CAP or GTS. */ + APS_MAC_FRAME_TOO_LONG_STATUS = 0xE5, + /** The requested GTS transmission failed because the specified + * GTS either did not have a transmit GTS direction or was not defined. */ + APS_MAC_INVALID_GTS_STATUS = 0xE6, + /** A request to purge an MSDU from the transaction queue was made using + * an MSDU handle that was not found in the transaction table. */ + APS_MAC_INVALID_HANDLE_STATUS = 0xE7, + /** A parameter in the primitive is either not supported or is out of + * the valid range. */ + APS_MAC_INVALID_PARAMETER_STATUS = 0xE8, + /** No acknowledgment was received after macMaxFrameRetries. */ + APS_MAC_NO_ACK_STATUS = 0xE9, + /** A scan operation failed to find any network beacons. */ + APS_MAC_NO_BEACON_STATUS = 0xEA, + /** No response data were available following a request. */ + APS_MAC_NO_DATA_STATUS = 0xEB, + /** The operation failed because a 16-bit short address was not allocated. */ + APS_MAC_NO_SHORT_ADDRESS_STATUS = 0xEC, + /** A receiver enable request was unsuccessful because it could not be + * completed within the CAP. */ + APS_MAC_OUT_OF_CAP_STATUS = 0xED, + /** A PAN identifier conflict has been detected and communicated + * to the PAN coordinator. */ + APS_MAC_PAN_ID_CONFLICT_STATUS = 0xEE, + /** A coordinator realignment command has been received. */ + APS_MAC_REALIGNMENT_STATUS = 0xEF, + /** The transaction has expired and its information was discarded. */ + APS_MAC_TRANSACTION_EXPIRED_STATUS = 0xF0, + /** There is no capacity to store the transaction. */ + APS_MAC_TRANSACTION_OVERFLOW_STATUS = 0xF1, + /** The transceiver was in the transmitter enabled state when the receiver + * was requested to be enabled. */ + APS_MAC_TX_ACTIVE_STATUS = 0xF2, + /** The key purportedly used by the originator of the received frame is + * not available or, if available, the originating device is not known + * or is blacklisted with that particular key. */ + APS_MAC_UNAVAILABLE_KEY_STATUS = 0xF3, + /** A SET/GET request was issued with the identifier of a PIB + * attribute that is not supported. */ + APS_MAC_UNSUPPORTED_ATTRIBUTE_STATUS = 0xF4, + /** A request to send data was unsuccessful because neither the source address + * parameters nor the destination address parameters were present. */ + APS_MAC_INVALID_ADDRESS_STATUS = 0xF5, + /** A receiver enable request was unsuccessful because it specified a number + * of symbols that was longer than the beacon interval. */ + APS_MAC_ON_TIME_TOO_LONG_STATUS = 0xF6, + /** A receiver enable request was unsuccessful because it could not be + * completed within the current superframe and was not permitted to be + * deferred until the next superframe. */ + APS_MAC_PAST_TIME_STATUS = 0xF7, + /** The device was instructed to start sending beacons based on the + * timing of the beacon transmissions of its coordinator, but the device + * is not currently tracking the beacon of its coordinator. */ + APS_MAC_TRACKING_OFF_STATUS = 0xF8, + /** An attempt to write to a MAC PIB attribute that is in a table failed + * because the specified table index was out of range. */ + APS_MAC_INVALID_INDEX_STATUS = 0xF9, + /** There are some unscanned channels yet, but there is no memory */ + APS_MAC_LIMIT_REACHED_STATUS = 0xFA, + /** A SET/GET request was issued with the identifier of an attribute + * that is read only. */ + APS_MAC_READ_ONLY_STATUS = 0xFB, + /** A request to perform a scan operation failed because the MLME was + * in the process of performing a previously initiated scan operation. */ + APS_MAC_SCAN_IN_PROGRESS_STATUS = 0xFC, + /** The device was instructed to start sending beacons based on the timing of + * the beacon transmissions of its coordinator, but the instructed start time + * overlapped the transmission time of the beacon of its coordinator. */ + APS_MAC_SUPERFRAME_OVERLAP_STATUS = 0xFD +} APS_Status_t; + +#if defined _SECURITY_ +/** Type of request to transmit APS command. */ +typedef struct _ApsCommandReq_t +{ + /** \cond SERVICE_FIELDS **/ + struct + { + /** Service field, used for queue support */ + QueueElement_t next; + /** Partner device short address. */ + ShortAddr_t partnerShortAddr; + /** Service structure for memory allocation on NWK-layer */ + NWK_AllocDataReq_t allocateReq; + /** Callback function for preparing an NWK-DATA.request. */ + void (*prepareNwkDataReq)(struct _ApsCommandReq_t *const commandReq); +#if defined _LINK_SECURITY_ + /** Service structure for payload encryption */ + SSP_EncryptFrameReq_t encryptReq; +#endif /* _LINK_SECURITY_ */ + + } service; + /** Flag indicates the command frame encryption on NWK-layer. */ + bool nwkSecurity; + /** Flag indicates the command frame encryption on APS-layer. */ + bool apsSecurity; + /** Identifies the type of the key which is used to protect the frame. */ + uint8_t keyIdentifier; + /** If the extendedNonce field is equal to 1 then source address shall + * be present in Auxilary header. */ + bool extendedNonce; + /** Actual command frame lenght, APS header with payload */ + uint8_t frameLength; + /** Pointer to extended address of partner device. */ + ExtAddr_t *partnerExtAddr; + /** Callback function for preparing an APS command. */ + void (*prepareCommand)(struct _ApsCommandReq_t *const commandReq); + /** Callback function for confirmation of APS command transmission. */ + void (*confirmCommand)(struct _ApsCommandReq_t *const commandReq, + const APS_Status_t status); +} ApsCommandReq_t; +#endif /* _SECURITY_ */ + +#endif /* _APS_COMMON_H */ +/** eof apsCommon.h */ + diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/apsConfigServer.h b/digital/zigbit/bitcloud/stack/Components/APS/include/apsConfigServer.h new file mode 100644 index 00000000..0c673157 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/apsConfigServer.h @@ -0,0 +1,37 @@ +/**************************************************************************//** + \file apsConfigServer.h + + \brief The data types necessary for building of the ConfigServer. + + \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-16 Max Gekk - Created. + Last change: + $Id: apsConfigServer.h 17448 2011-06-09 13:53:59Z ataradov $ + ******************************************************************************/ +#if !defined _APS_CONFIG_SERVER_H +#define _APS_CONFIG_SERVER_H + +/****************************************************************************** + Definitions section + ******************************************************************************/ +#ifndef APS_PRIVATE + #define APS_PRIVATE +#endif /* APS_PRIVATE */ + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include +#include + +#endif /* _APS_CONFIG_SERVER_H */ +/** eof apsConfigServer.h */ + diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/apsCryptoKeys.h b/digital/zigbit/bitcloud/stack/Components/APS/include/apsCryptoKeys.h new file mode 100644 index 00000000..216cc70e --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/apsCryptoKeys.h @@ -0,0 +1,426 @@ +/**************************************************************************//** + \file apsCryptoKeys.h + + \brief Access interface to cryptographic keys. + + \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-31 Max Gekk - Created. + Last change: + $Id: apsCryptoKeys.h 18914 2011-10-18 09:13:36Z mgekk $ + ******************************************************************************/ +#if !defined _APS_CRYPTO_KEYS_H +#define _APS_CRYPTO_KEYS_H + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include + +/****************************************************************************** + Define(s) section + ******************************************************************************/ +/** Macro returns true if crypto key handle is valid. */ +#define APS_KEY_HANDLE_IS_VALID(handle) (0 <= (handle)) +/** Macro returns true if key-pair handle is successfully found. */ +#define APS_KEYS_FOUND(handle) APS_KEY_HANDLE_IS_VALID(handle) +/** Macro returns true if security status is related to any security with + * link key.*/ +#define APS_SECURED_WITH_ANY_LINK_KEY_STATUS(securityStatus) \ + ((APS_SECURED_LINK_KEY_STATUS == securityStatus) || \ + (APS_SECURED_TRUST_CENTER_LINK_KEY_STATUS == securityStatus) || \ + (APS_SECURED_HASH_OF_TRUST_CENTER_LINK_KEY_STATUS == securityStatus)) + + +/** List of invalid and service key handle values. */ +/** Initial and finish value of key-pair iterator. */ +#define APS_KEY_PAIR_INITIAL -1 +#define APS_KEY_PAIR_FINISH -2 +/** Memory for key-pair descriptor is out. */ +#define APS_KEY_PAIR_ALLOC_FAIL -3 +/** Key-pair is not found by device address. */ +#define APS_KEY_PAIR_NOT_FOUND -4 +/** Parameter is out of range. */ +#define APS_KEY_PAIR_INVALID_PARAMETER -5 +/** APS Key-Pair Set is not initialized. */ +#define APS_KEY_PAIR_NO_INIT -6 + +/** Values of reset flag. These request reset master, link keys or counters. + * Zero or more flags can be bitwise-or'd in argument of APS_ResetKeys. */ +#define APS_RESET_MASTER_KEY 0x01 /*!< Set default master key (zero key). */ +#define APS_RESET_LINK_KEY 0x02 /*!< Set default link key (zero key). */ +#define APS_RESET_COUNTERS 0x04 /*!< Set 0 to incoming and outgoing counters.*/ + +/****************************************************************************** + Types section + ******************************************************************************/ +/* Type of outgoing frame counter. See ZigBee spec r19, Table 4.37. */ +typedef uint32_t ApsOutFrameCounter_t; + +/* Type of incoming frame counter. See ZigBee spec r19, Table 4.37. */ +typedef uint32_t ApsInFrameCounter_t; + +/** Type of cryptographic key handle. */ +typedef int16_t APS_KeyHandle_t; + +/** Bit map of reset flags. */ +typedef uint8_t APS_KeyResetFlags_t; + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/**************************************************************************//** + \brief Sets a link key for the device with a given extended address + + This function inserts a new entry into the APS key-pair set containing provided + link key value and extended address. + + The function shall be called to specify the trust center link key before performing + network start if high security is used with ::CS_ZDO_SECURITY_STATUS set to 1 or + standard security with link keys is used. + + In high security, if the trust center link key is unavailable + ::CS_ZDO_SECURITY_STATUS can be set to 2 or 3; in this case a master key is used to authenticate + the joining device to launch link key establishment procedure with the trust center. + + For communication with a node different from the trust center a separate link key is also + needed (an application link key). If it is known to the application it shall be set with + the use of this function. Otherwise, the application shall either apply a master key to + launch link key establishment procedure (SKKE) with the partner node or request for a link + key from the trust center. + + A typical example of the function's usage is given below: +\code +APS_KeyHandle_t apsKeyHandle; //A variable to hold a key handle +//Set a link key variable to a 16-byte value +uint8_t linkKey[SECURITY_KEY_SIZE] = {0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa}; +//A variable for the trust center address predefined in ::CS_APS_TRUST_CENTER_ADDRESS. +ExtAddr_t trustCenterAddr; + +//Read the trust center address +CS_ReadParameter(CS_APS_TRUST_CENTER_ADDRESS_ID, &trustCenterAddr); +//Set the trust center link key +apsKeyHandle = APS_SetLinkKey(&trustCenterAddr, linkKey); + +//Check for errors +if (APS_KEY_HANDLE_IS_VALID(apsKeyHandle)) +{ + ... +} +\endcode + + \param[in] deviceAddress \ref Endian "[LE]" - pointer to + extended (IEEE) device address + \param[in] linkKey - pointer to a new link key + + \return A valid key handle if operation is successfully completed otherwise + invalid key handle (Use APS_KEY_HANDLE_IS_VALID to check it out). + ******************************************************************************/ +APS_KeyHandle_t APS_SetLinkKey(const ExtAddr_t *const deviceAddress, + const uint8_t *const linkKey); + +/**************************************************************************//** + \brief Sets a master key for the device with a given extended address + + This function inserts a new entry into the APS key-pair set containing provided + master key value and extended address. Thus it specifies a master key used to launch + link key establishment (SKKE) with the remote device with the corresponding extended address. + + The function is used in high security with ::CS_ZDO_SECURITY_STATUS set to 2 or 3. + If ::CS_ZDO_SECURITY_STATUS is set to 2, then before joining the network the device + shall specify a master key value corresponding to the trust center using this function. The + master key in pair with the joining device's extended address must be set on the trust + center via this function as well. If ::CS_ZDO_SECURITY_STATUS is set to 3, then the + master key must be set only on the trust center. In this case the trust center + trasfers the master key to the device at the beginning of the authentication procedure. + + The function can also be used to specify application master keys corresponding to devices + different from the trust center. The need for this occurs when a link key for a remote device + is unknown. The device shall set a master key value for a remote device with which it wishes to + communicate and initiate the SKKE procedure to establish the link key by calling the + APS_EstablishKeyReq() function before sending any data requests to the device. + + See the example of usage below: +\code +APS_KeyHandle_t apsKeyHandle; //A variable to hold a key handle +//Set a master key variable to a 16-byte value +uint8_t masterKey[16] = {0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa}; +//Assume the remote node extended address is held by APP_EXT_ADDR constant +ExtAddr_t partnerExtAddr = APP_EXT_ADDR; + +apsKeyHandle = APS_SetMasterKey(&partnerExtAddr, masterKey); //Set the master key + +//Check for errors +if (APS_KEY_HANDLE_IS_VALID(apsKeyHandle)) +{ + ... +} +\endcode +Note that the APP_EXT_ADDR constant shall contain a 64-bit value in the little endian +format. For this purpose in the definition of the constant convert a common value +to the little endian format using the CCPU_TO_LE64 format as follows: +\code +#define APP_EXT_ADDR CCPU_TO_LE64(0xAAAAAAAAAAAAAAAALL) +\endcode + +An extended address corresponding to a given short address can be obtained +through Device Discovery, while short addresses of devices supporting certain services can be +discovered using Service Discovery. + + \param[in] deviceAddress \ref Endian "[LE]" - pointer to extended + IEEE device address. + \param[in] masterKey - pointer to new cryptographic master key. + + \return Valid key handle if operation is successfully completed otherwise + invalid key handle (Use APS_KEY_HANDLE_IS_VALID to check it out). + ******************************************************************************/ +APS_KeyHandle_t APS_SetMasterKey(const ExtAddr_t *const deviceAddress, + const uint8_t *const masterKey); + +/**************************************************************************//** + \brief Find the master key or the link key corresponding to a given extended address + + The function is used to check whether the link key or the master key has been set for a given + device identified by its extended address and to retrieve a handle to it if one exists. To + check whether the key has been found use the APS_KEYS_FOUND macro. If the handle is + valid an access to a key value is got via APS_GetMasterKey() or APS_GetLinkKey(). + + See the example: +\code +//Assume that the extended address of interest is held by APP_EXT_ADDR constant +ExtAddr_t partnerExtAddr = APP_EXT_ADDR; + +if (!APS_KEYS_FOUND(APS_FindKeys(&partnerExtAddr))) +{ + ... //Perform required action, e.g. request for a link key, using APS_RequestKeyReq() +} +\endcode + + \param[in] deviceAddress \ref Endian "[LE]" - pointer to extended IEEE + device address. + + \return Valid key handle if any key is found otherwise + invalid key handle (Use APS_KEYS_FOUND to check it out). + ******************************************************************************/ +APS_KeyHandle_t APS_FindKeys(const ExtAddr_t *const deviceAddress); + +/**************************************************************************//** + \brief Get a pointer to the master key value by a given key handle + + The function returns a pointer to the section of memory containing the master key value + for a given key handle. A key handle points to a certain entry in the APS key-pair set + corresponding to a specific extended address. To obtain a key handle for a given + extended address use the APS_FindKeys() function. + + Note that the received pointer must be only used to read the value and not to + modify it. + + Consider the example: +\code +//Search for keys associated with the provided extended address +const APS_KeyHandle_t keyHandle = APS_FindKeys(&extAddr); + +uint8_t *masterKey; + +if (APS_KEYS_FOUND(keyHandle) && NULL != (masterKey = APS_GetMasterKey(keyHandle))) +{ + ... //A pointer to the master key value has been successfully captured +} +\endcode + + + \param[in] handle - valid key handle. + + \return A pointer to the master key or NULL if the key handle is invalid + ******************************************************************************/ +uint8_t* APS_GetMasterKey(const APS_KeyHandle_t handle); + +/**************************************************************************//** + \brief Get a pointer to the link key value by a given key handle + + The function returns a pointer to the section of memory containing the link key value + for a given key handle. A key handle points to a certain entry in the APS key-pair set + corresponding to a specific extended address. To obtain a key handle for a given + extended address use the APS_FindKeys() function. + + Note that the received pointer must be only used to read the value and not to + modify it. + + Consider the example: +\code +//Search for keys associated with the provided extended address +const APS_KeyHandle_t keyHandle = APS_FindKeys(&extAddr); + +uint8_t *linkKey; + +if (APS_KEYS_FOUND(keyHandle) && (linkKey = APS_GetLinkKey(keyHandle))) +{ + ... //A pointer to the link key value has been successfully captured +} +\endcode + + \param[in] handle - valid key handle. + + \return A pointer to the link key or NULL if the key handle is invalid + ******************************************************************************/ +uint8_t* APS_GetLinkKey(const APS_KeyHandle_t handle); + +/**************************************************************************//** + \brief Delete key-pair - master and link keys. + + \param[in] deviceAddress \ref Endian "[LE]" - pointer to extended + IEEE device address. + \param[in] notify - notify to upper layer or not. + + \return 'true' if the key-pair is removed otherwise false. + ******************************************************************************/ +bool APS_DeleteKeyPair(ExtAddr_t *const deviceAddress, const bool notify); + +/**************************************************************************//** + \brief Get next key handle. + + \code Example: + APS_KeyHandle_t handle = APS_KEY_PAIR_INITIAL; + + while (APS_KEYS_FOUND(handle = APS_NextKeys(handle))) + { + linkKey = APS_GetLinkKey(handle); + if (NULL != linkKey) + ... + ... + } + \endcode + + \param[in] handle - handle of previous key-pair or APS_KEY_PAIR_INITIAL + if it's initial call. + + \return if next key-pair is found then return valid key handle + otherwise return APS_KEY_PAIR_FINISH. + ******************************************************************************/ +APS_KeyHandle_t APS_NextKeys(const APS_KeyHandle_t handle); + +/**************************************************************************//** + \brief (Un)authorize cryptographic key-pair of given device. + + \param[in] deviceAddress \ref Endian "[LE]" - pointer to extended IEEE + device address. + \param[in] status - 'true' for authorized keys otherwise 'false'. + + \return None. + ******************************************************************************/ +void APS_SetAuthorizedStatus(const ExtAddr_t *const deviceAddress, + const bool status); + +/**************************************************************************//** + \brief Check authorization of crypthographic key-pair. + + \param[in] deviceAddress \ref Endian "[LE]" - pointer to extended + IEEE device address. + + \return 'true' if key-pair is authorized otherwise 'false'. + ******************************************************************************/ +bool APS_AreKeysAuthorized(const ExtAddr_t *const deviceAddress); + +/**************************************************************************//** + \brief Reset device's keys and counters to default values. + + \param[in] deviceAddress \ref Endian "[LE]" - pointer to extended IEEE + device address. + \param[in] flags - bit map of APS Key-Pair reset flags. Current implementation + supported only APS_RESET_LINK_KEY and APS_RESET_COUNTERS. + + \return APS Key Handle of reseting key-pair or invalid key handle if + key-pair is not found. + ******************************************************************************/ +APS_KeyHandle_t APS_ResetKeys(const ExtAddr_t *const deviceAddress, + const APS_KeyResetFlags_t flags); + +/**************************************************************************//** + \brief Init APS key-pair set. + + \param[in] powerFailureControl - stack restoring after power failure control bitfield; + affects on initialization procedure. + + \return None. + ******************************************************************************/ +void APS_InitKeyPairSet(const NWK_PowerFailureControl_t powerFailureControl); + +/**************************************************************************//** + \brief Get extended device address of key-pair. + + \param[in] handle - valid key handle. + + \return Pointer to device address or NULL if key-pair is not found.. + ******************************************************************************/ +ExtAddr_t* APS_GetKeyPairDeviceAddress(const APS_KeyHandle_t handle); + +/**************************************************************************//** + \brief Find key-pair with old address and set new address. + + \param[in] oldAddress \ref Endian "[LE]" - extended IEEE device + address of key-pair. + \param[in] newAddress \ref Endian "[LE]" - new device address of key-pair. + \return None. + ******************************************************************************/ +void APS_ChangeKeyPairDeviceAddress(const ExtAddr_t oldAddress, + const ExtAddr_t newAddress); + +#ifdef _TC_PROMISCUOUS_MODE_ +/**************************************************************************//** + \brief Get preinstalled link key. + + \param[in] handle - valid key handle. + + \return Pointer to preinstalled link key or NULL if handle is invalid. + ******************************************************************************/ +uint8_t* APS_GetPreinstalledLinkKey(const APS_KeyHandle_t handle); + +/**************************************************************************//** + \brief Set new preinstalled link key for given device. + + This function copies value of preinstalled link key to APS Key-Pair Set. + + \param[in] deviceAddress - pointer to extended IEEE device address. + \param[in] preinstalledLinkKey - pointer to new cryptographic preinstalled + link key. + + \return Valid key handle if operation is successfully completed otherwise + invalid key handle (Use APS_KEY_HANDLE_IS_VALID to check it out). + ******************************************************************************/ +APS_KeyHandle_t APS_SetPreinstalledLinkKey(const ExtAddr_t *const deviceAddress, + const uint8_t *const preinstalledLinkKey); + +/**************************************************************************//** + \brief Restores link key from preinstalled one. + Uses to accept TC reestablishing keys with previously joined device. + + \param[in] deviceAddress - pointer to extended IEEE device address. + + \return None. + ******************************************************************************/ +void APS_RestorePreinstalledLinkKey(const ExtAddr_t *const deviceAddress); + +#endif /* _TC_PROMISCUOUS_MODE_ */ + +#ifdef _LINK_SECURITY_ +/**************************************************************************//** + \brief Get current value of outgoing security frames counter. + + \param[in] keyHandle - valid key handle. + + \return Current value of outgoing frame counter. + ******************************************************************************/ +ApsOutFrameCounter_t APS_GetOutSecFrameCounter(const APS_KeyHandle_t keyHandle); +#endif /* _LINK_SECURITY_ */ + + +#endif /* _APS_CRYPTO_KEYS_H */ +/** eof apsCryptoKeys.h */ + diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/apsTcSwapOut.h b/digital/zigbit/bitcloud/stack/Components/APS/include/apsTcSwapOut.h new file mode 100644 index 00000000..a005ee69 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/apsTcSwapOut.h @@ -0,0 +1,59 @@ +/*************************************************************************//** + \file apsTcSwapOut.h + + \brief Interface of APS Trust Centre Swap Out. + + \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-28 Max Gekk - Created. + Last change: + $Id: apsTcSwapOut.h 17813 2011-07-04 14:11:12Z dloskutnikov $ + *****************************************************************************/ +#if !defined _APS_TC_SWAP_OUT_H +#define _APS_TC_SWAP_OUT_H +/**//** + * + * In order to protect the data that is being backed up, a hash on the TC + * link key will be performed and that will be the key stored externally. + * The actual link key used for operational networks never be transported + * out of the ESI. See ZigBee-095310r23ZB, page 82. + * + **/ + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include + +#if defined _SECURITY_ && defined _LINK_SECURITY_ && defined _TC_SWAPOUT_ + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/**************************************************************************//** + \brief Creates link key hash for the Trust Centre and store it inside. + ******************************************************************************/ +void APS_EnableLinkKeyHashChecking(void); + +/**************************************************************************//** + \brief Writes invalid value to link key hash for the Trust Centre. + ******************************************************************************/ +void APS_DisableLinkKeyHashChecking(void); + +/**************************************************************************//** + \brief Gets pointer to stored link key hash for the Trust Centre. + ******************************************************************************/ +uint8_t *APS_GetLinkKeyHash(void); + +#endif /* _SECURITY_ and _LINK_SECURITY_ and _TC_SWAPOUT_ */ + +#endif /* _APS_TC_SWAP_OUT_H */ +/** eof apsTcSwapOut.h */ + diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/apsdeData.h b/digital/zigbit/bitcloud/stack/Components/APS/include/apsdeData.h new file mode 100644 index 00000000..50f202ba --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/apsdeData.h @@ -0,0 +1,319 @@ +/**************************************************************************//** + \file apsdeData.h + + \brief The interface for sending data through the APS component + + \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-18 Max Gekk - Created. + Last change: + $Id: apsdeData.h 18132 2011-08-02 15:58:18Z ataradov $ + ******************************************************************************/ +#if !defined _APSDE_DATA_H +#define _APSDE_DATA_H + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include +#include + +/****************************************************************************** + Types section + ******************************************************************************/ +/**//** + * \struct APS_DataConf_t apsdeData.h "aps.h" + * + * \brief The structure for reporting the result of APS_DataReq() function + * + * A pointer to an instance of this type is received as an argument in a confirmation callback for APS_DataReq() + * request reporting the result of data transmission. + * The structure definition follows APSDE-DATA confirm primitive described in + * ZigBee Specification r18, 2.2.4.1.2 APSDE-DATA.confirm, page 27. + **/ +typedef struct +{ + /** The status of the corresponding request. */ + APS_Status_t status; + /** Timestamp for the transmitted packet based on the local clock, + * as provided by the NWK layer. */ + uint32_t txTime; +} APS_DataConf_t; + +/**//** + * \struct APS_TxOptions_t apsdeData.h "aps.h" + * + * \brief Describes additional options of data transmission. + * + * The structure is used to set additional parameters for a data request such as + * \li to request for acknowledgement assign acknowledgedTransmission to 1 + * \li to enable fragmentation assign fragmentationPermitted to 1 + * \li to enable security assign securityEnabledTransmission to 1 + * \li to use network key in the request assign useNwkKey to 1 + * \li to include extended nonce to the auxiliary header assign includeExtendedNonce to 1 + * + * This fields conform to the primitive defined in ZigBee Specification r20, Table 2.2, page 25. + * + * Few extensions to the specification are defined: + * \li to disable decryption of sent data (clobbers data pointed by the asdu field) assign doNotDecrypt to 1 + * \li to enable indications from broadcast transmissions assign indicateBroadcasts to 1 + * + */ +BEGIN_PACK +typedef struct PACK +{ + uint8_t securityEnabledTransmission :1; + uint8_t useNwkKey :1; + uint8_t acknowledgedTransmission :1; + uint8_t fragmentationPermitted :1; + uint8_t includeExtendedNonce :1; + uint8_t doNotDecrypt :1; + uint8_t indicateBroadcasts :1; + /** Reserved. Should always be zero. */ + uint8_t reserved :1; +} APS_TxOptions_t; +END_PACK + +/**//** + * \struct APS_DataReq_t apsdeData.h "aps.h" + * + * \brief The structure for request parameters of APS_DataReq() function + * + * The structure represents parameters of data request, i.e. the request for sending data across the network. A pointer + * to an instance of the structure should to be passed as an argument to APS_DataReq() function. + * The structure definition follows APSDE-DATA request primitive described in + * Zigbee Specification r18, 2.2.4.1.1 APSDE-DATA.request, page 23. + */ +typedef struct +{ + /** \cond SERVICE_FIELDS **/ + struct + { + void *next; /*!< Used for queue support */ + } service; + /** \endcond **/ + + /** The addressing mode for identifying the destination of a data request. + * May take any non-reserved value from the following list: + * \li APS_NO_ADDRESS (0x00) - used for binding; set dstAddress and dstEndpoint + * \li APS_GROUP_ADDRESS (0x01) - used for group transmission; 16-bit group address should be specified in dstAddress; dstEndpoint is not set + * \li APS_SHORT_ADDRESS (0x02) - identifying the destination (unicast or broadcast) with a 16-bit short address specified + * in dstAddress and the endpoint set in dstEndpoint + * \li APS_EXT_ADDRESS (0x03) - identifying the destination with a 64-bit extended address specified in dstAddress and the endpoint set in dstEndpoint + * \li 0x04..0xff - reserved values, must not be used by the application*/ + APS_AddrMode_t dstAddrMode; + /** + * \ref Endian "[LE]" The address of the individual device or group address + * of the entity to which the ASDU is being transferred. + **/ + APS_Address_t dstAddress; + /** This parameter shall be present if and only if the DstAddrMode parameter + * value is 0x02 or 0x03 and, if present, shall contain either the number of + * individual endpoints of the entity to which the ASDU is being transferred, + * or the broadcast endpoint (0xff). */ + Endpoint_t dstEndpoint; + /** \ref Endian "[LE]" The identifier of the profile for which + * this frame is intended. */ + ProfileId_t profileId; + /** \ref Endian "[LE]" The identifier of the cluster for which + * this frame is intended. */ + ClusterId_t clusterId; + /** The endpoint on the request originator node from + * which the data frame is being transferred. */ + Endpoint_t srcEndpoint; + /** The number of octets comprising the ASDU to be transferred. + * The maximum length of an individual APS frame payload is given + * as NsduLength-apscMinHeaderOverhead. Assuming the possibility + * of fragmentation, a maximum-sized single ASDU consists of 256 such blocks. + **/ + uint16_t asduLength; + /** The set of octets comprising the ASDU to be transferred. */ + uint8_t *asdu; + /** The transmission options for the ASDU to be transferred. + * See structure definition for details. + */ + APS_TxOptions_t txOptions; + /** The distance, in hops, that a transmitted frame will be allowed to + * travel via the network*/ + uint8_t radius; + /** A pointer to a callback function called upon request + * completion.*/ + void (*APS_DataConf)(APS_DataConf_t *conf); + /** Confirm primitive passed to the callback and containing the results of request execution*/ + APS_DataConf_t confirm; +} APS_DataReq_t; + +/**//** + * \struct APS_DataInd_t apsdeData.h "aps.h" + * + * \brief The structure for indication of data reception + * + * A pointer to an instance of this type is passed to a data indication callback registered for a given + * endpoint when the data is received destined to the endpoint. + * The structure definition follows APSDE-DATA indication primitive described in + * Zigbee Specification r18, 2.2.4.1.3 APSDE-DATA.indication, page 29. + */ +typedef struct +{ + /** \cond SERVICE_FIELDS **/ + struct + { + void *next; /*!< Service field for queue support */ + } service; + /** \endcond **/ + + /** The addressing mode used to identify the destination + * in the data frame that has been received. + * May take any non-reserved value from the following list: + * \li APS_NO_ADDRESS (0x00) - used for binding; set dstAddress and dstEndpoint + * \li APS_GROUP_ADDRESS (0x01) - used for group transmission; 16-bit group address should be specified in dstAddress; dstEndpoint is not set + * \li APS_SHORT_ADDRESS (0x02) - identifying the destination (unicast or broadcast) with a 16-bit short address specified + * in dstAddress and the endpoint set in dstEndpoint + * \li APS_EXT_ADDRESS (0x03) - identifying the destination with a 64-bit extended address specified in dstAddress and the endpoint set in dstEndpoint + * \li 0x04..0xff - reserved values, must not be used by the application*/ + APS_AddrMode_t dstAddrMode; + /** \ref Endian "[LE]" The individual device address or group addressto which + * the ASDU is directed. Value size depends on the dstAddrMode parameter. */ + APS_Address_t dstAddress; + /** The target endpoint on the local entity to which the ASDU is directed. */ + Endpoint_t dstEndpoint; + /** The addressing mode for the source address used in this primitive + * and of the APDU that has been received. May possess any non-reserved value + * from the following list: + * \li APS_SHORT_ADDRESS (0x02) - short address is used in srcAddress and srcEndpoint is specified + * \li APS_EXT_ADDRESS (0x03) - extended address is used in srcAddress and srcEndpoint is specified + * */ + APS_AddrMode_t srcAddrMode; + /** \ref Endian "[LE]" The individual device address of the entity from which + * the ASDU has been received. + * Value type and size is depend of the srcAddrMode parameter. */ + APS_Address_t srcAddress; + /** \ref Endian "[LE]" Network address of previous hop from which the packet + * received. */ + ShortAddr_t prevHopAddr; + /** The number of the individual endpoint of the entity from + * which the ASDU has been received. */ + Endpoint_t srcEndpoint; + /** \ref Endian "[LE]" The identifier of the profile from + * which this frame originates. */ + ProfileId_t profileId; + /** \ref Endian "[LE]" The identifier of the received object. */ + ClusterId_t clusterId; + /** The number of octets comprising the ASDU being indicated by the APSDE. */ + uint16_t asduLength; + /** The set of octets comprising the ASDU being indicated by the APSDE. */ + uint8_t *asdu; + /** The status of the incoming frame processing. */ + APS_Status_t status; + /** + * \li APS_UNSECURED_STATUS=0xaf if the ASDU was received without any security. + * \li APS_SECURED_NWK_KEY_STATUS=0xac if the received ASDU was secured + * with the NWK key, + * \li APS_SECURED_LINK_KEY_STATUS=0xab if the ASDU was secured with a link key, + * \li APS_SECURED_TRUST_CENTER_LINK_KEY_STATUS=0xb1 if the ASDU was secured + * with the trust center link key, + * \li APS_SECURED_HASH_OF_TRUST_CENTER_LINK_KEY_STATUS=0xb2 if secured + * with hash of the trust center link key. + **/ + APS_Status_t securityStatus; + /** The status of whether the NSDU is using security: TRUE = use, + * FALSE = doesn't use. */ + bool nwkSecurityStatus; + /** The link quality indication delivered by the NLDE. */ + uint8_t linkQuality; + /** Timestamp for the received packet based on the local clock, + * as provided by the NWK layer. */ + uint32_t rxTime; + int8_t rssi; +} APS_DataInd_t; + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/**************************************************************************//** + \brief Sends data to a node in the network. + +The function is used to transmit data across the network. The function is able to send a data frame to a single +node (unicast), an arbitrary group of nodes (multicast), or to all nodes in the network (broadcast). Sending data to devices +that support a specific cluster and to which the node has already bound is also possible. Specific actions performed by the +request depend on parameters configuration. A destination type is identified according the value +of APS_DataReq_t::dstAddrMode. + +To send a unicast message to a node with a known short address set ::APS_SHORT_ADDRESS as addressing mode, specify +the destination address, destination and source endpoints, profile and cluster IDs.Specified cluster should be supported +by both the destination and the originator enpoints. Both endpoints should also have the same profile ID. If the short address +is unknown ::APS_EXT_ADDRESS mode can be used to identify the destination with a help of extended address +(\c dstAddress.extAddress field). For broadcasting +exactly the same parameters should be set, but the destination address (\c dstAddress.shortAddress) should be assigned to +::BROADCAST_ADDRESS_ALL to send a message to all nodes in the network, ::BROADCAST_ADDR_RX_ON_WHEN_IDLE +to send a message to all nodes with \c rxOnWhenIdle parameter equal to 1, or ::BROADCAST_ADDR_ROUTERS to send data to +all routers. + +To send data to all members of a group set ::APS_GROUP_ADDRESS as addressing mode, and specify 16bit group address +(via \c dstAddress.groupAddress). Destination endpoint should be assigned to 0xFF value. The data will be delivered to all endpoints +associated to a given group address on each group member. To apply binding use ::APS_NO_ADDRESS mode and specify +source endpoint and cluster ID. Other parameters such as profile, destination address and endpoint are ignored. + +Actual data to be sent with a request is provided through APS_DataReq_t::asdu. The parameter takes as an argument a pointer +to a segment of memory within a specially defined structure. Consider the example: + +\code +// Application message buffer +BEGIN_PACK +typedef struct +{ + uint8_t header[APS_ASDU_OFFSET]; // Header + uint8_t data[APP_ASDU_SIZE]; // Application data + uint8_t footer[APS_AFFIX_LENGTH - APS_ASDU_OFFSET]; //Footer +} PACK AppMessageBuffer_t; END_PACK +static AppMessageBuffer_t appMessageBuffer; // A global variable for the message buffer +static APS_DataReq_t dataReq; // A global variable for the data request +... +dataReq.asdu = appMessageBuffer.data; +dataReq.asduLength = sizeof(appMessageBuffer.data); +\endcode + +Additional options are switched on and off with a help of APS_DataReq_t::txOptions parameter. For unicast messages the application can request +for acknowledgement and apply fragmentation if it needs to sends greater amounts of data within a single request. Security is also +may be turned and off. + +The result of the operation is reported via callback call with confirm (APS_DataConf_t) primitive pointer as an argument. In case +of acknowledged transmission the callback is called after the response from the destination node is received. When one of +destination nodes receives data, it fires data indication callback on the destination endpoint. + + + \param[in] req - The APSDE-DATA.request primitive pointer. + \sa APS_DataReq_t + + \return None. + ******************************************************************************/ +void APS_DataReq(APS_DataReq_t *const req); + +/**************************************************************************//** + \brief ZDO APSDE-DATA.indication handler. + + \param[in] ind - pointer to APSDE_DATA.indication parameters. + \return None. + ******************************************************************************/ +extern void APS_ZdoDataInd(APS_DataInd_t *ind); + +/**************************************************************************//** + \brief Recalculates transmission timeouts and duplicate rejection time. + Reads maximum frame transmission time, + indirect poll rate and other parameters from the config server and + updates ack time. + \param none + \return none + ******************************************************************************/ +void APS_CalculateTimes(void); + +#endif /* _APSDE_DATA_H */ +/** eof apsdeData.h */ + diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/apsdeEndpoint.h b/digital/zigbit/bitcloud/stack/Components/APS/include/apsdeEndpoint.h new file mode 100644 index 00000000..02bd43b2 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/apsdeEndpoint.h @@ -0,0 +1,203 @@ +/**************************************************************************//** + \file apsdeEndpoint.h + + \brief Interface of APS Endpoint SAP. + + \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-20 Max Gekk - Created. + Last change: + $Id: apsdeEndpoint.h 17448 2011-06-09 13:53:59Z ataradov $ + ******************************************************************************/ +/**//** + * + * The application framework in ZigBee is the environment in which application + * objects are hosted on ZigBee devices. Up to 254 distinct application objects + * can be defined, each identified by an endpoint address from 1 to 254. + * + * Two additional endpoints are defined for APSDE-SAP usage: endpoint 0 is + * reserved for the data interface to the ZDO, and endpoint 255 is reserved for + * the data interface function to broadcast data to all application objects. + * See ZigBee Specification r19, 2.1.2, page 18. + * + **/ +#if !defined _APSDE_ENDPOINT_H +#define _APSDE_ENDPOINT_H + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include +#include + +/****************************************************************************** + Types section + ******************************************************************************/ +/**//** + * \struct APS_RegisterEndpointReq_t apsdeEndpoint.h "aps.h" + * + * \brief Parameters of the APS_RegisterEndpointReq() function + * + * A pointer to an instance of this type shall be passed to APS_RegisterEndpointReq() function + * as an argument to register a new endpoint. The structure contains simple descriptor + * configuration, data indication callback pointer, and the status field. + **/ +typedef struct +{ + /** \cond SERVICE_FIELDS **/ + struct + { + void *next; /*!< Used for queue support. */ + bool noIndication; /*!< Disable indication to upper-layer. */ + } service; + /** \endcond **/ + + /** A pointer to a simple descriptor */ + SimpleDescriptor_t *simpleDescriptor; + /** A pointer to an indication callback function, which is called when data is received addressed to + * the endpoint; conforms to APSDE-DATA.indication handler defined in ZigBee spec r19, 2.2.4.1.3.1, page 30. */ + void (*APS_DataInd)(APS_DataInd_t *ind); + /** The status of endpoint registration; is written by the stack to report the result of the operation */ + APS_Status_t status; +} APS_RegisterEndpointReq_t; + +typedef APS_RegisterEndpointReq_t APS_EndpointReg_t; + +/**//** + * \struct APS_UnregisterEndpointReq_t apsdeEndpoint.h "aps.h" + * + * \brief Parameters of the APS_UnregisterEndpointReq() function + **/ +typedef struct +{ + /*! The endpoint which is to be unregistered. */ + Endpoint_t endpoint; + /*! The status of endpoint unregistration; is written by the stack to report the result + * of the operation execution. */ + APS_Status_t status; +} APS_UnregisterEndpointReq_t; + +typedef APS_UnregisterEndpointReq_t APS_EndpointUnreg_t; + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/**************************************************************************//** + \brief Registers a new endpoint in the APS layer + + The function is used to register an application endpoint. In order to take part in network + communication the application on the device must register at least one endpoint, since + data exchange on the application level occurs between two endpoints registered on + two nodes, which in fact can be a single node as well. + + The function call is done synchronously. The function simply writes an entry containing + endpoint information to a dedicated internal structure. The request parameters for + the funciton include simple descriptor configuration, a pointer to the indication callback + function, which is to be called upon data reception addressed to the endpoint, and a status + field, which is written by the stack. + + See the example of request parameters configuration and function usage: +\code +//Global definitions +static ClusterId_t clustersTable[] = {0}; //The list of clusters that the endpoint will support + +//Configure the simple descriptor of the endpoint +static SimpleDescriptor_t simpleDescriptor = +{ + .endpoint = APP_ENDPOINT, //Endpoint ID, an arbitrary number between 1 and 240 + .AppDeviceVersion = 1, + .AppInClustersCount = 1, //The number of suppoted input clusters + .AppInClustersList = clustersTable, //The list of supported input clusters + .AppOutClustersCount = 0, + .AppOutClustersList = NULL, //Suppose out clusters are not supported +}; + +//Configure parameters for endpoint registration request +static APS_RegisterEndpointReq_t endpointDesc = +{ + .simpleDescriptor = &simpleDescriptor, + .APS_DataInd = APS_DataInd, +}; + +//Data indication callback definition +static void APS_DataInd(APS_DataInd_t *ind) +{ + //Perform appropriate actions, for example, switch on the value of + //cluster specified in the received frame + switch (ind->clusterId) + { + case CPU_TO_LE16(APP_CLUSTER_ONE): + ... + case CPU_TO_LE16(APP_CLUSTER_TWO): + ... + } +} +... +simpleDescriptor.AppProfileId = CPU_TO_LE16(APP_PROFILE_ID); +simpleDescriptor.AppDeviceId = CPU_TO_LE16(1); + +APS_RegisterEndpointReq(&endpointDesc); +\endcode +Although it is not required that a variable for the simple descriptor is static or simply defined +in the global scope, it may be convenient to do so to keep track of the endpoint. Note the use +of the CPU_TO_LE16 macro which converts a 16-bit value to a 16-bit little-endian value. Backward +convertion is performed with the LE16_TO_CPU macro. + + \param[in] req - pointer to the endpoint registration request parameters + + \return APS_SUCCESS_STATUS in req->status if registration is a success, + otherwise, APS_INVALID_PARAMETER_STATUS. \sa APS_Status_t + ******************************************************************************/ +void APS_RegisterEndpointReq(APS_RegisterEndpointReq_t *const req); + +/**************************************************************************//** + \brief Unregisters an endpoint from the APS layer + + \param[in] req - pointer to the endpoint unregistering request parameters + + \return APS_SUCCESS_STATUS in req->status if unregistration is a success, + otherwise, APS_INVALID_PARAMETER_STATUS. \sa APS_Status_t + ******************************************************************************/ +void APS_UnregisterEndpointReq(APS_UnregisterEndpointReq_t *const req); + +/**************************************************************************//** + \brief Get next registered endpoint descriptor by previous. + + \param[in] prev - previous endpoint descriptor pointer.It is must be non NULL + sequential access required if. And it is must be NULL the + first descriptor as registered endpoints queue head element + access required if. + + \return Valid endpoint descriptor pointer descriptor found if, + NULL - other case. + ******************************************************************************/ +APS_RegisterEndpointReq_t* APS_NextEndpoint(const APS_RegisterEndpointReq_t *const prev); + +/**************************************************************************//** + \brief Stops APS Data indications of specific endpoint number. + + \param[in] endpoint - the registered endpoint number. The 0xff special value + means all registered endpoints. + \return None. + ******************************************************************************/ +void APS_StopEndpointIndication(const Endpoint_t endpoint); + +/**************************************************************************//** + \brief Resumes APS Data indications of specific endpoint number. + + \param[in] endpoint - the registered endpoint number. The 0xff special value + means all registered endpoints. + \return None. + ******************************************************************************/ +void APS_ResumeEndpointIndication(const Endpoint_t endpoint); + +#endif /* _APSDE_ENDPOINT_H */ +/** eof apsdeEndpoint.h */ + diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/apsmeAuthenticate.h b/digital/zigbit/bitcloud/stack/Components/APS/include/apsmeAuthenticate.h new file mode 100644 index 00000000..0812491a --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/apsmeAuthenticate.h @@ -0,0 +1,195 @@ +/**************************************************************************//** + \file apsmeAuthenticate.h + + \brief Interface of APS Entity Authentication Services. + + \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-24 Max Gekk - Created. + Last change: + $Id: apsmeAuthenticate.h 17813 2011-07-04 14:11:12Z dloskutnikov $ + ******************************************************************************/ +#if !defined _APSME_AUTHENTICATE_H +#define _APSME_AUTHENTICATE_H +/**//** + * + * The APS-layer provides services that allow two devices to mutually + * authenticate each other. The process authenticates the originator of the + * data by using a random challenge with a response based on a pre-shared + * secret, in this case, a key. It also allows optional authenticated data + * transfer. See ZigBee Specification r19, 4.4.8, page 470. + * + **/ + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include +#if defined _SECURITY_ && defined _LINK_SECURITY_ +#include +#include + +/****************************************************************************** + Types section + ******************************************************************************/ +/** Type of entity authentication status code. */ +typedef enum +{ + /** No errors occur. */ + APS_AUTH_SUCCESS_STATUS = 0x00, + /*! An invalid parameter was input to one of the key establishment primitives. + **/ + APS_AUTH_INVALID_PARAMETER_STATUS = 0x01, + /** No authentication key exists. */ + APS_AUTH_NO_KEY_STATUS = 0x02, + /** No authentication data exists. */ + APS_AUTH_NO_DATA_STATUS = 0x03, + /** Challenge is invalid: + * \li Initiator during action step 2 (sub-clause B.8.1 of ZigBee Spec r19), + * \li Responder during action step 1 (sub-clause B.8.2). */ + APS_AUTH_INVALID_CHALLENGE_STATUS = 0x04, + /** MAC transformation outputs invalid: + * \li Initiator during action step 4 (sub-clause B.8.1), + * \li Responder during action steps 4 and 7 (sub-clause B.8.2). */ + APS_AUTH_INVALID_MAC_STATUS = 0x05, + /** Tag checking transformation outputs invalid: + * \li Initiator during action step 3 (sub-clause B.8.1), + * \li Responder during action step 6 (sub-clause B.8.2). */ + APS_AUTH_INVALID_KEY_STATUS = 0x06, + /** The initiator or responder waits for an expected incoming + * message for time greater than apsSecurityTimeoutPeriod. */ + APS_AUTH_TIMEOUT_STATUS = 0x07, + /** Short address of authentic partner is not found. */ + APS_AUTH_NO_SHORT_ADDR_STATUS = 0x08 +} APS_AuthenticateStatus_t; + +/**//** + * \struct APS_AuthenticateConf_t apsmeAuthenticate.h "aps.h" + * + * \brief Parameters of APSME-AUTHENTICATE.confirm primitive. + * See ZigBee Specification r19, Table 4.30, page 472. + **/ +typedef struct +{ + /** \ref Endian "[LE]" The extended, 64-bit IEEE address of the device + * with which the entity authentication took place. */ + ExtAddr_t address; + /** The final status of the entity authentication. */ + APS_AuthenticateStatus_t status; +} APS_AuthenticateConf_t; + +/** Type of action. See ZigBee Specification r19, Table 4.29. */ +typedef enum +{ + /** Initiate the entity authentication. */ + APS_INITIATE_ACTION = 0x00, + /** Respond to the entity authentication request, accepting it. */ + APS_RESPOND_ACCEPT_ACTION = 0x01, + /** Respond to the entity authentication request, rejecting it. */ + APS_RESPOND_REJECT_ACTION = 0x02 +} APS_AuthenticateAction_t; + +/**//** + * \struct APS_AuthenticateReq_t apsmeAuthenticate.h "aps.h" + * + * \brief Parameters of APSME-AUTHENTICATE.request primitive. + * See ZigBee Specification r19, Table 4.28, page 471. + **/ +typedef struct +{ + /** \cond SERVICE_FIELDS **/ + struct + { + void *next; /*!< Service field, used for queue support. */ + uint8_t ttl; + /** Allocation request of memory for NWK_DataReq_t and APDU. */ + NWK_AllocDataReq_t allocNwkDataReq; + /** Request's parameters of authentic calculation - MacTag2 and MacTag1. */ + SSP_CalculateAuthenticParamsReq_t macTagReq; + /** Pointer to NWK_DataReq_t structure for challenge and macdata frames. */ + NWK_DataReq_t *challengeNwkDataReq; + NWK_DataReq_t *macdataNwkDataReq; + struct /** Information about authentic partner. */ + {/** Network address of the ounterpart device in the authentication request.*/ + ShortAddr_t shortAddr; + /** Received MacTag hash from authentic partner. */ + uint8_t macTag[HASH_SIZE]; + /** Frame counter received from partner in the Data field. */ + uint32_t frameCounter; + } partner; + /** The 16-octet random challenge generated by the responder. */ + uint8_t responderChallenge[CHALLENGE_SEQUENCE_SIZE]; + } service; + /** \endcond **/ + + /** \ref Endian "[LE]" The extended, 64-bit IEEE address of the counterpart + * device in the entity authentication request. */ + ExtAddr_t partnerAddress; + /** Indicates the action required. See APS_AuthenticateAction_t enumeration. + * \sa APS_AuthenticateAction_t */ + APS_AuthenticateAction_t action; + /** The 16-octet random challenge generated by the initiator. */ + uint8_t initiatorChallenge[CHALLENGE_SEQUENCE_SIZE]; + /** Callback confirmation function of entity authentication. */ + void (*APS_AuthenticateConf)(APS_AuthenticateConf_t *conf); + /** Confirm primitive as a parameter of the callback function */ + APS_AuthenticateConf_t confirm; +} APS_AuthenticateReq_t; + +/**//** + * \struct APS_AuthenticateInd_t apsmeAuthenticate.h "aps.h" + * + * \brief Parameters of APSME-AUTHENTICATE.indication primitive. + * See ZigBee Specification r19, Table 4.31, page 473. + **/ +typedef struct +{ + /** \ref Endian "[LE]" + * The extended, 64-bit IEEE address of the initiator device. */ + ExtAddr_t initiatorAddress; + /** The 16-octet random challenge received from the initiator. */ + uint8_t randomChallenge[CHALLENGE_SEQUENCE_SIZE]; +} APS_AuthenticateInd_t; + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/**************************************************************************//** + \brief Initiate or respond an entity authentication. + + This primitive can be used when there is a need to authenticate another + device without using frame security. The protocol confirms authenticity + based on the two devices sharing a pre-shared key. See ZigBee spec r19, + 4.4.8.1, page 470. + + \param[in] req - pointer to APSME-AUTHENTICATE.request's parameters. + \sa APS_AuthenticateReq_t + + \return None. + ******************************************************************************/ +void APS_AuthenticateReq(APS_AuthenticateReq_t *const req); + +/**************************************************************************//** + \brief A request to start an entity authentication is received. + + See ZigBee Specification r19, 4.4.8.3, page 473. + + \param[in] ind - pointer to APSME-AUTHENTICATE.indication's parameters. + \sa APS_AuthenticateInd_t + + \return None. + ******************************************************************************/ +void APS_AuthenticateInd(APS_AuthenticateInd_t *ind); + +#endif /* _SECURITY_ and _LINK_SECURITY_ */ + +#endif /* _APSME_AUTHENTICATE_H */ +/** eof apsmeAuthenticate.h */ + diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/apsmeBind.h b/digital/zigbit/bitcloud/stack/Components/APS/include/apsmeBind.h new file mode 100644 index 00000000..a55f3193 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/apsmeBind.h @@ -0,0 +1,189 @@ +/**************************************************************************//** + \file apsmeBind.h + + \brief 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-07 Max Gekk - Created. + Last change: + $Id: apsmeBind.h 17448 2011-06-09 13:53:59Z ataradov $ + ******************************************************************************/ +/**//** + * + * The APS binding table allows ZigBee devices to establish designated + * destination for frames from a given source endpoint and with a given + * cluster ID. See ZigBee spec. r18, 2.2.8.2, page 65. + * + **/ +#if !defined _APSME_BIND_H +#define _APSME_BIND_H + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include +#include + +#if defined _BINDING_ +/****************************************************************************** + Types section + ******************************************************************************/ +/**//** + * \union APS_DstBindAddr_t apsmeBind.h "aps.h" + * + * \brief Information about the destination address of a binding entry. + * + * \note A value of APS_DstBindAddr_t type should be in little-endian format. + **/ +typedef union +{ + GroupAddr_t group; + struct + { + ExtAddr_t extAddr; + Endpoint_t endpoint; + } unicast; +} APS_DstBindAddr_t; + +/**//** + * \struct APS_BindConf_t apsmeBind.h "aps.h" + * + * \brief The structure is used to report the result of a binding request. Conforms to APSME-BIND.confirm primitive. + **/ +typedef struct +{ + /** This parameter can take a value from the following list: + * \li APS_SUCCESS_STATUS - the binding link has been successfully created, + * \li APS_TABLE_FULL_STATUS - the binding table capacity has been exceeded, + * \li APS_NOT_SUPPORTED_STATUS - the device does not support the binding table, + * \li APS_ILLEGAL_REQUEST_STATUS - the device is not joined to + * a network, or one of the parameters has a value that is out of range. + **/ + APS_Status_t status; +} APS_BindConf_t; + +/**//** + * \struct APS_BindReq_t apsmeBind.h "aps.h" + * + * \brief The structure used to hold parameters for APS_BindReq() + * + * A pointer to an instance of this type should be passed to APS_BindReq() function. The structure conforms to the APSME-BIND.request + * primitive defined in ZigBee specification. + **/ +typedef struct +{ + /** \ref Endian "[LE]" The source IEEE address for the binding entry. */ + ExtAddr_t srcAddr; + /** The source endpoint for the binding entry. Valid range: 0x01-0xFE. */ + Endpoint_t srcEndpoint; + /** \ref Endian "[LE]" The identifier of the cluster on the source device + * that is to be bound to the destination device. */ + ClusterId_t clusterId; + /** The addressing mode for the destination address. This parameter can take + * a value from the following list: + * \li APS_GROUP_ADDRES - 16-bit dst.group is used to identify the destination group + * \li APS_EXT_ADDRESS - the destination node is identified with extended address; + * dst.unicast.extAddr holds the extended address, dst.unicast.endpoint holds the endpoint + **/ + APS_AddrMode_t dstAddrMode; + /** \ref Endian "[LE]" The destination address for the binding entry. */ + APS_DstBindAddr_t dst; + /** The field to keep the result of the request*/ + APS_BindConf_t confirm; +} APS_BindReq_t; + +/**//** + * \struct APS_UnbindReq_t apsmeBind.h "aps.h" + * + * \brief A type to hold parameters for APS_UnbindReq(); conforms to APSME-UNBIND.confirm primitive. + **/ +typedef APS_BindReq_t APS_UnbindReq_t; + +/**//** + * \struct ApsBindingEntry_t apsmeBind.h "aps.h" + * + * \brief A type for a binding table entry + **/ +typedef APS_BindReq_t ApsBindingEntry_t; + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/**************************************************************************//** + \brief Bind to a remote device or a group + + This function establishes binding of two devices, or binding of a device to a group, + by creating an entry in the lcoal binding table, if supported. The function follows the primitive defined in + ZigBee specification r18, 2.2.4.3.1, page 34. + + \param[in] req - pointer to request's parameters: source and destination + addresses, cluster identifier and etc. \sa APS_DataReq_t. + \return None. + ******************************************************************************/ +void APS_BindReq(APS_BindReq_t *const req); + +/**************************************************************************//** + \brief Unbind device from a group or from other device. + + This function performs unbinding of two devices, or unbinding of a device from a group, by removing an entry in + the local binding table, if supported. The function follows the primitive defined in ZigBee specification r18, 2.2.4.3.3, page 38. + + \param[in] req - pointer to request's parameters. + + \return None. + ******************************************************************************/ +void APS_UnbindReq(APS_UnbindReq_t *const req); + +/**************************************************************************//** + \brief Deactivates all records in the binding table that contain dstAddr as + the destination address in a binding entry + + \param[in] dstAddr - pointer to the target extended address + + \return None + ******************************************************************************/ +void APS_DeactivateBindRecords(const ExtAddr_t *const dstAddr); + +/**************************************************************************//** + \brief Activates all records in the binding table that contain dstAddr as + the destination address in a binding entry + + \param[in] dstAddr - pointer to the target extended address + + \return None + ******************************************************************************/ +void APS_ActivateBindRecords(const ExtAddr_t *const dstAddr); + +/**************************************************************************//** + \brief Get a next binding entry. + + \code Example: + ApsBindingEntry_t bindingEntry = NULL; + + while (NULL != (bindingEntry = APS_NextBindingEntry(bindingEntry))) + { + if (0x1234 == bindingEntry->clusterId) + ... + ... + } + \endcode + + \param[in] entry - pointer to binding entry or NULL if it's initial call. + + \return if next binding entry is found then return valid pointer + otherwise return NULL. + ******************************************************************************/ +ApsBindingEntry_t* APS_NextBindingEntry(ApsBindingEntry_t *entry); + +#endif /* _BINDING_ */ +#endif /* _APSME_BIND_H */ +/** eof apsmeBind.h */ + diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/apsmeEstablishKey.h b/digital/zigbit/bitcloud/stack/Components/APS/include/apsmeEstablishKey.h new file mode 100644 index 00000000..2065dc72 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/apsmeEstablishKey.h @@ -0,0 +1,317 @@ +/**************************************************************************//** + \file apsmeEstablishKey.h + + \brief Interface of APS Key-Establishment Services. + + \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-24 Max Gekk - Created. + Last change: + $Id: apsmeEstablishKey.h 18914 2011-10-18 09:13:36Z mgekk $ + ******************************************************************************/ +#if !defined _APSME_ESTABLISH_KEY_H +#define _APSME_ESTABLISH_KEY_H +/**//** + * + * The APS layer provides services that allow two devices to establish + * a mutual link key. Initial trust information (for example, a master key) must be + * installed on each device prior to running the key establishment procedure. + * See ZigBee Specification r19, 4.4.2, page 441. + * + **/ + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include +#if defined _SECURITY_ && defined _LINK_SECURITY_ +#include + +/****************************************************************************** + Types section + ******************************************************************************/ +/**//** + * \brief Status values as a result of the SKKE protocol. + * See ZigBee Specification r19, Table 4.10, page 448. + **/ +typedef enum +{ + /** No errors occured .*/ + APS_SKKE_SUCCESS_STATUS = 0x00, + /** An invalid parameter was input to one of the key establishment + * primitives. */ + APS_SKKE_INVALID_PARAMETER_STATUS = 0x01, + /** No master key is available. */ + APS_SKKE_NO_MASTER_KEY_STATUS = 0x02, + /** Challenge is invalid: + * \li Initiator during action step 3 (sub-clause B.7.1), + * \li Responder during action step 3 (sub-clause B.7.2). + **/ + APS_SKKE_INVALID_CHALLENGE_STATUS = 0x03, + /** SKG outputs invalid: + * \li Initiator during action step 4 (sub-clause B.7.1), + * \li Responder during action step 3 (sub-clause B.7.2). + **/ + APS_SKKE_INVALID_SKG_STATUS = 0x04, + /** MAC transformation outputs invalid: + * \li Initiator during action step 8 (sub-clause B.7.1), + * \li Responder during action step 10 (sub-clause B.7.2). + **/ + APS_SKKE_INVALID_MAC_STATUS = 0x05, + /** Tag checking transformation outputs invalid: + * \li Initiator during action step 12 (sub-clause B.7.1), + * \li Responder during action step 8 (sub-clause B.7.2). + **/ + APS_SKKE_INVALID_KEY_STATUS = 0x06, + /** Either the initiator or responder waits for the next expected incoming + * message for time greater than the apsSecurityTimeOutPeriod attribute + * of the AIB. */ + APS_SKKE_TIMEOUT_STATUS = 0x07, + /** Either the initiator or responder receives an SKKE frame out of order. */ + APS_SKKE_BAD_FRAME_STATUS = 0x08, + /** Invalid global state of APS layer. */ + APS_SKKE_NOT_PERMITTED_STATUS = 0x09, + /** Transmission of SKKE-1 command frame is failure. */ + APS_SKKE_1_TX_ERROR_STATUS = 0x0A, + /** Transmission of SKKE-2 command frame is failure. */ + APS_SKKE_2_TX_ERROR_STATUS = 0x0B, + /** Transmission of SKKE-3 command frame is failure. */ + APS_SKKE_3_TX_ERROR_STATUS = 0x0C, + /** Transmission of SKKE-4 command frame is failure. */ + APS_SKKE_4_TX_ERROR_STATUS = 0x0D, + /** Error saving new link key. */ + APS_SKKE_SET_LINK_KEY_ERROR_STATUS = 0x0E, + /** Short address of key establish partner is not found. */ + APS_SKKE_NO_SHORT_ADDR_STATUS = 0x0F +} APS_SkkeStatus_t; + +/**//** + * \brief The requested key-establishment method. + **/ +typedef enum +{ + APS_SKKE_KEY_ESTABLISHMENT_METHOD = 0x00 +} APS_KeyEstablishmentMethod_t; + +/**//** + * \struct APS_EstablishKeyConf_t apsmeEstablishKey.h "aps.h" + * + * \brief Parameters of a callback for the APS_EstablishKeyReq() function. + * + * The structure conforms to APSME-KEY-ESTABLISH.confirm primitive defined in + * ZigBee Specification r19, Table 4.6, page 443. + **/ +typedef struct +{ + /** \ref Endian "[LE]" The extended 64-bit address of the device with + * which the key-establishment protocol was executed. */ + ExtAddr_t address; + /** This parameter indicates the final status of the key-establishment + * protocol. */ + APS_SkkeStatus_t status; +} APS_EstablishKeyConf_t; + +/** Type of time-to-live of Establish Key request or response. */ +typedef uint16_t ApsSkkeTTL_t; + +typedef struct _ApsSkkeElem_t +{ + QueueElement_t qelem; /*!< Used for queue support. */ + uint8_t state; /*!< Internal state of Establish Key request (response). */ + ApsSkkeTTL_t ttl; /*!< Time to live of appropriate SKKE request. */ + /** Pointer to confirmation function of SKKE operations. */ + void (* apsSkkeConf)(struct _ApsSkkeElem_t *elem, APS_SkkeStatus_t skkeStatus); +} ApsSkkeElem_t; + +/**//** + * \struct APS_EstablishKeyReq_t apsmeEstablishKey.h "aps.h" + * + * \brief Parameters of the APS_EstablishKeyReq() function + * + * The structure conforms to APSME-KEY-ESTABLISH.request primitive + * defined in ZigBee Specification r19, Table 4.5, page 441. + **/ +typedef struct +{ + /** \cond SERVICE_FIELDS */ + struct + { + ApsSkkeElem_t elem; /*!< Common substructure of SKKE request. */ + ShortAddr_t dstShortAddr; /*!< Short address of SKKE responder. */ + /** Saved pointer to NWK_DataReq_t structure for SKKE-1 command frame. */ + NWK_DataReq_t *skke1NwkDataReq; + /** Saved pointer to NWK_DataReq_t structure for SKKE-3 command frame. */ + NWK_DataReq_t *skke3NwkDataReq; + /** Request to allocate memory for SKKE command in NWK layer. */ + NWK_AllocDataReq_t allocNwkDataReq; + /** Parameters of request for calculation of link key by master key. */ + SSP_CalculateSkkeParamsReq_t sspReq; + } service; + /** \endcond */ + + /** \ref Endian "[LE]" The extended 64-bit address of the responder device. */ + ExtAddr_t responderAddress; + /** This parameter indicates if the responder's parent shall be used to + * forward messages between the initiator and responder devices: + * \li TRUE - Use parent, + * \li FALSE - Do not use parent. + **/ + bool useParent; + /** \ref Endian "[LE]" + * If \c useParent is TRUE, then the \c responderParentAddress parameter shall + * contain the extended 64-bit address of the responder’s parent device. + * Otherwise, this parameter is not used and need not to be set. */ + ExtAddr_t responderParentAddress; + /** Requested key-establishment method. The valid value is SKKE. */ + APS_KeyEstablishmentMethod_t keyEstablishmentMethod; + /** Parameters that will be passed to the confirmation callback in the argument */ + APS_EstablishKeyConf_t confirm; + /** Confirmation callback function */ + void (*APS_EstablishKeyConf)(APS_EstablishKeyConf_t *conf); +} APS_EstablishKeyReq_t; + +/**//** + * \struct APS_EstablishKeyInd_t apsmeEstablishKey.h "aps.h" + * + * \brief Parameters of APSME-KEY-ESTABLISH.indication. + * See ZigBee Specification r19, Table 4.7, page 444. + **/ +typedef struct +{ + /** \ref Endian "[LE]" The extended 64-bit address of the initiator device. */ + ExtAddr_t initiatorAddress; + /** The requested key-establishment method shall be SKKE. */ + APS_KeyEstablishmentMethod_t keyEstablishmentMethod; + /** Data field from received SKKE-1 command frame. */ + uint8_t qeu[CHALLENGE_SEQUENCE_SIZE]; + /** An initial Establish Key command is received from parent or not. */ + bool fromParent; +} APS_EstablishKeyInd_t; + +/**//** + * \struct APS_EstablishKeyResp_t apsmeEstablishKey.h "aps.h" + * + * \brief Parameters of APSME-KEY-ESTABLISH.response. + * See ZigBee Specification r19, Table 4.8, page 445. + **/ +typedef struct +{ + /** \cond SERVICE_FIELDS */ + struct + { + ApsSkkeElem_t elem; /*!< Common substructure of SKKE request. */ + ShortAddr_t dstShortAddr; /*!< Short address of SKKE initiator. */ + /** Parameters of request for calculation of link key by master key. */ + SSP_CalculateSkkeParamsReq_t sspReq; + /** Request to allocate memory for SKKE command in NWK layer. */ + NWK_AllocDataReq_t allocNwkDataReq; + /** Saved pointer to NWK_DataReq_t structure for SKKE-2 command frame. */ + NWK_DataReq_t *skke2NwkDataReq; + /** Saved pointer to NWK_DataReq_t structure for SKKE-4 command frame. */ + NWK_DataReq_t *skke4NwkDataReq; + } service; + /** \endcond */ + + /** \ref Endian "[LE]" The extended 64-bit address of the device + * that initiated key establishment. */ + ExtAddr_t initiatorAddress; + /** This parameter indicates the response to an initiator's request to + * execute a keyestablishment protocol. The response shall be either: + * \li TRUE = Accept, + * \li FALSE = Reject. + **/ + bool accept; + /** This parameter indicates if the responder's parent shall be used to + * forward messages between the initiator and responder devices: + * \li TRUE - Use parent, + * \li FALSE - Do not use parent. + **/ + bool useParent; + /** Data field from received SKKE-1 command frame. */ + uint8_t qeu[CHALLENGE_SEQUENCE_SIZE]; + /** Confirm primitive as a parameter of the callback function. */ + APS_EstablishKeyConf_t confirm; + /** Callback function pointer as a handler of corresponding + * confirm primitive. */ + void (*APS_EstablishKeyConf)(APS_EstablishKeyConf_t *conf); +} APS_EstablishKeyResp_t; + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +#if defined _HI_SECURITY_ +/**************************************************************************//** + \brief Initiates the key establishment procedure + + The function is used in high security to initiate a link key + establishment procedure (currently, SKKE) between two device. The procedure requires + the master key, which must be known on both devices (set via the APS_SetMasterKey() + function). The stack uses this procedure during device authentication on the + trust center, while the application may use it to establish application link + keys between two common devices. + + If the function is used to establish an application link key, set the + \c useParent field to \c false and do not specify \c responderParentAddress. + + Currently only SKKE protocol is supported, and so set \c keyEstablishmentMethod + to ::APS_SKKE_KEY_ESTABLISHMENT_METHOD. + + The function conforms to APSME-ESTABLISH-KEY.request primitive. + See ZigBee Specification r19, 4.4.2.1, page 441. + + \param[in] req - pointer to request parameters of the APS_EstablishKeyReq_t type + + \return None + ******************************************************************************/ +void APS_EstablishKeyReq(APS_EstablishKeyReq_t *const req); + +/**************************************************************************//** + \brief Informs the upper layer when APS receives an initial + key-establishment message + + The APS layer on the responder device calls this function informing the ZDO layer + when a request to start the key-establishment procedure (for example, an SKKE-1 + frame) is received from the initiator device and the master key associated with + the initiator is present in the APS Key-pair set. + + The function conforms to APSME-ESTABLISH-KEY.indication primitive. + See ZigBee Specification r19, 4.4.2.3, page 444. + + \param[in] ind - pointer to parameters of the APS_EstablishKeyInd_t type + + \return None + ******************************************************************************/ +void APS_EstablishKeyInd(APS_EstablishKeyInd_t *ind); + +/**************************************************************************//** + \brief The responder device calls this function to respond + to an APSME-ESTABLISH-KEY.indication primitive. + + The ZDO layer calls this function to inform APS following a request from the + initiator device to start the key-establishment procedure. The function provides + the responder's ZDO with an opportunity to determine whether to accept or reject + the request to establish the key with a given initiator. + + The function conforms to APSME-ESTABLISH-KEY.response primitive. + See ZigBee Specification r19, 4.4.2.4, page 444. + + \param[in] resp - pointer to parameters of the APS_EstablishKeyResp_t type + + \return None + ******************************************************************************/ +void APS_EstablishKeyResp(APS_EstablishKeyResp_t *const resp); + +#endif /* _HI_SECURITY_ */ + +#endif /* _SECURITY_ and _LINK_SECURITY_ */ + +#endif /* _APSME_ESTABLISH_KEY_H */ +/** eof apsmeEstablishKey.h */ + diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/apsmeGroup.h b/digital/zigbit/bitcloud/stack/Components/APS/include/apsmeGroup.h new file mode 100644 index 00000000..c206f988 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/apsmeGroup.h @@ -0,0 +1,173 @@ +/**************************************************************************//** + \file apsmeGroup.h + + \brief Interface of APS Group 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: + 24/07/07 A. Potashov - Created. + 21/07/10 M. Gekk - Refactoring. + Last change: + $Id: apsmeGroup.h 17448 2011-06-09 13:53:59Z ataradov $ + ******************************************************************************/ +#if !defined _APSME_GROUP_H +#define _APSME_GROUP_H +/**//** + * + * This interface allows the next higher layer to manage group membership + * for endpoints on the current device by adding and removing entries in + * the group table. See ZigBee spec. r18, 2.2.4.5, page 45. + * + **/ + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include + +/****************************************************************************** + Types section + ******************************************************************************/ +/**//** + * \struct APS_AddGroupConf_t apsmeGroup.h "aps.h" + * + * \brief Parameters of the APSME-ADD-GROUP.confirm primitive. + **/ +typedef struct +{ + /** The status of the request to add a group. */ + APS_Status_t status; +} APS_AddGroupConf_t; + +/**//** + * \struct APS_AddGroupReq_t apsmeGroup.h "aps.h" + * + * \brief Parameters of the APS_AddGroupReq() function. + **/ +typedef struct +{ + /** \ref Endian "[LE]" The 16-bit address of the group being added. */ + GroupAddr_t groupAddress; + /** The endpoint to which the given group is being added. */ + Endpoint_t endpoint; + + /** The confirm primitive as transaction result. */ + APS_AddGroupConf_t confirm; +} APS_AddGroupReq_t; + +/**//** + * \struct APS_RemoveGroupConf_t apsmeGroup.h "aps.h" + * + * \brief The primitive presenting the result of APS_RemoveAllGroupReq() function. + **/ +typedef struct +{ + /** The status of the request to remove a group. */ + APS_Status_t status; +} APS_RemoveGroupConf_t; + +/**//** + * \struct APS_RemoveGroupReq_t apsmeGroup.h "aps.h" + * + * \brief Parameters of the APS_RemoveGroupReq() function. + **/ +typedef struct +{ + /** \ref Endian "[LE]" The 16-bit address of the group being removed. */ + GroupAddr_t groupAddress; + /** The endpoint at which the given group is being removed. */ + Endpoint_t endpoint; + + /** The confirm primitive containing the result of the function call. */ + APS_RemoveGroupConf_t confirm; +} APS_RemoveGroupReq_t; + +/**//** + * \struct APS_RemoveAllGroupsConf_t apsmeGroup.h "aps.h" + * + * \brief The structure presenting the result of APS_RemoveAllGroupReq() function. + **/ +typedef struct +{ + /** The status of the request to remove all groups. */ + APS_Status_t status; +} APS_RemoveAllGroupsConf_t; + +/**//** + * \struct APS_RemoveAllGroupsReq_t apsmeGroup.h "aps.h" + * + * \brief Parameters of the APS_RemoveAllGroupsReq() function. + **/ +typedef struct +{ + /** The endpoint from which the group is being removed. */ + Endpoint_t endpoint; + + /** The confirm primitive as transaction result. */ + APS_RemoveAllGroupsConf_t confirm; +} APS_RemoveAllGroupsReq_t; + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/**************************************************************************//** + \brief Adds the current device to the members of a certain group. + + The function makes the current device a member of the specified group. A call to the function is done + synchronously since no requests are sent to the network. Instead, the function simply adds a new entry + to the group table associating the group address and the endpoint ID specified within the parameters. + The function can be called several times with the same group address and different endpoints which will + cause inserting an entry for each distinct pair of the group address and an endpoint. When a data frame is + sent to a group each group member upon reception of the frame fires indication callbacks for all endpoints + associated with the group address specified in the request. + + The result of task execution is indicated by APS_AddGroupReq_t::confirm property inside the request + parameters. The status field reports + \li APS_SUCCESS_STATUS if the device has been added to the group + \li APS_TABLE_FULL_STATUS if the group table is full and a new entry can not be added. + + \param[in] req - pointer to parameters of the APSME-ADD-GROUP.request. + *****************************************************************************/ +void APS_AddGroupReq(APS_AddGroupReq_t *const req); + +/**************************************************************************//** + \brief Removes the current device from the members of a certain group. + + The function removes the node from a group. A call to the function is done synchronously. The function drops + all entries with the specified group and endpoint inside from the group table. + + The result of task execution is indicated by APS_AddGroupReq_t::confirm property inside the request + parameters. The status field reports + \li APS_SUCCESS_STATUS if the device has been removed from the group + \li APS_INVALID_PARAMETER_STATUS if requested entry has not been found in the group table + + \param[in] req - pointer to parameters of the APSME-REMOVE-GROUP.request. + ******************************************************************************/ +void APS_RemoveGroupReq(APS_RemoveGroupReq_t *const req); + +/**************************************************************************//** + \brief Removes the current device from the members of all groups for which a given + endpoint if registered + + The function unscribe the current device from the members of all groups for which + a given endpoint is registered. To fullfill the task the function deletes all entries with a given + endpoint inside from the group table. If 0xFF is specified for endpoint the node is removed + from all groups. + + The result of task execution is indicated by APS_AddGroupReq_t::confirm property inside the request + parameters. + + \param[in] req - pointer to parameters of the APSME-REMOVE-ALL-GROUPS.request. + ******************************************************************************/ +void APS_RemoveAllGroupsReq(APS_RemoveAllGroupsReq_t *const req); + +#endif /* _APSME_GROUP_H */ +/** eof apsmeGroup.h */ + diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/apsmeRemoveDevice.h b/digital/zigbit/bitcloud/stack/Components/APS/include/apsmeRemoveDevice.h new file mode 100644 index 00000000..209bbb27 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/apsmeRemoveDevice.h @@ -0,0 +1,145 @@ +/**************************************************************************//** + \file apsmeRemoveDevice.h + + \brief Interface of APS Remove Device Service. + + \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-24 Max Gekk - Created. + Last change: + $Id: apsmeRemoveDevice.h 17448 2011-06-09 13:53:59Z ataradov $ + ******************************************************************************/ +#if !defined _APSME_REMOVE_DEVICE_H +#define _APSME_REMOVE_DEVICE_H +/**//** + * + * The APS-layer provides services that allow a device (for example, + * a Trust Center) to inform another device (for example, a router) + * that one of its children should be removed from the network. + * See ZigBee Specification r19, 4.4.5, page 463. + * + **/ +/****************************************************************************** + Includes section + ******************************************************************************/ +#include + +#if defined _SECURITY_ +/****************************************************************************** + Types section + ******************************************************************************/ +/** Status of creating and sending a remove device command frame. */ +typedef enum +{ + APS_REMOVE_SUCCESS_STATUS = 0x00, + APS_REMOVE_NO_SHORT_ADDRESS_STATUS = 0x01, + APS_REMOVE_SECURITY_FAIL_STATUS = 0x02, + APS_REMOVE_NOT_SENT_STATUS = 0x03, + /* These names are deprecated and will be removed. */ + APS_RDR_SUCCESS_STATUS = APS_REMOVE_SUCCESS_STATUS, + APS_RDR_NO_SHORT_ADDRESS_STATUS = APS_REMOVE_NO_SHORT_ADDRESS_STATUS, + APS_RDR_SECURITY_FAIL_STATUS = APS_REMOVE_SECURITY_FAIL_STATUS, + APS_RDR_NOT_SENT_STATUS = APS_REMOVE_NOT_SENT_STATUS +} APS_RemoveStatus_t; + +/** This type is deprecated and will be removed. */ +typedef APS_RemoveStatus_t APS_RdrStatus_t; + +/**//** + * \struct APS_RemoveDeviceConf_t apsmeRemoveDevice.h "aps.h" + * + * \brief Confirmation parameters of APSME-REMOVE-DEVICE.request primitive. + **/ +typedef struct +{ + /** Status of device removing. */ + APS_RemoveStatus_t status; +} APS_RemoveDeviceConf_t; + +/**//** + * \struct APS_RemoveDeviceReq_t apsmeRemoveDevice.h "aps.h" + * + * \brief Parameters of APSME-REMOVE-DEVICE.request primitive. + * + * See ZigBee Specification r19, Table 4.22, page 463. + **/ +typedef struct +{ + /** \cond SERVICE_FIELDS **/ + struct + { + /** Request to send APS Remove Device command. */ + ApsCommandReq_t commandReq; + } service; + /** \endcond **/ + + /** \ref Endian "[LE]" The extended 64-bit address of the device that is + * the parent of the child device that is requested to be removed. */ + ExtAddr_t parentAddress; + /** \ref Endian "[LE]" The extended 64-bit address of the child device + * that is requested to be removed. */ + ExtAddr_t childAddress; + /** Confirm primitive as a parameter of the callback function */ + APS_RemoveDeviceConf_t confirm; + /** Callback function pointer as a handler of corresponding + * confirm primitive. */ + void (*APS_RemoveDeviceConf)(APS_RemoveDeviceConf_t *conf); +} APS_RemoveDeviceReq_t; + +/**//** + * \struct APS_RemoveDeviceInd_t apsmeRemoveDevice.h "aps.h" + * + * \brief Parameters of APSME-REMOVE-DEVICE.indication primitive. + * + * See ZigBee Specification r19, Table 4.23, page 464. + **/ +typedef struct +{ + /** \ref Endian "[LE]" The extended 64-bit address of the device requesting + * that a child device be removed. */ + ExtAddr_t srcAddress; + /** \ref Endian "[LE]" The extended 64-bit address of the child device + * that is requested to be removed. */ + ExtAddr_t childAddress; +} APS_RemoveDeviceInd_t; + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/**************************************************************************//** + \brief Request to remove one of children from the network. + + For example, a Trust Center can use this primitive to remove a child + device that fails to authenticate properly. See ZigBee Specification r19, + 4.4.5.1, page 463. + + \param[in] req - pointer to APSME-REMOVE-DEVICE.request's parameters. + + \return None. + ******************************************************************************/ +void APS_RemoveDeviceReq(APS_RemoveDeviceReq_t *req); + +/**************************************************************************//** + \brief Indication about device removing from the network. + + The APSME shall generate this primitive when it receives a remove-device + command frame that is successfully decrypted and authenticated, as specified + in sub-clause 4.4.1.2 of ZigBee Specification r19. + + \param[in] ind - pointer to APSME-REMOVE-DEVICE.indication's parameters. + + \return None. + ******************************************************************************/ +void APS_RemoveDeviceInd(APS_RemoveDeviceInd_t *ind); + +#endif /* _SECURITY_ */ +#endif /* _APSME_REMOVE_DEVICE_H */ +/** eof apsmeRemoveDevice.h } */ + diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/apsmeRequestKey.h b/digital/zigbit/bitcloud/stack/Components/APS/include/apsmeRequestKey.h new file mode 100644 index 00000000..fbb55e1c --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/apsmeRequestKey.h @@ -0,0 +1,175 @@ +/**************************************************************************//** + \file apsmeRequestKey.h + + \brief Interface of APS Request Key Service. + + \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-24 Max Gekk - Created. + Last change: + $Id: apsmeRequestKey.h 18914 2011-10-18 09:13:36Z mgekk $ + ******************************************************************************/ +#if !defined _APSME_REQUEST_KEY_H +#define _APSME_REQUEST_KEY_H +/**//** + * + * The APSME provides services that allow a device to request the active + * network key or a master key from another device (for example, its Trust + * Center). See ZigBee Specification r19, 4.4.6, page 465. + * + **/ + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include + +#if defined _SECURITY_ && defined _LINK_SECURITY_ +/****************************************************************************** + Types section + ******************************************************************************/ +/**//** + * The type of key being requested: + * \li Network (0x01) and Application (0x02) key, + * \li Trust Center Link Key (0x04 - it's not supported), + * \li 0x00 and 0x03-0xFF = Reserved. + **/ +typedef enum +{ + APS_NETWORK_KEY_TYPE = 0x01, + APS_APP_KEY_TYPE = 0x02, + APS_TC_LINK_KEY_TYPE = 0x04 +} APS_RequestKeyType_t; + +/** Status of creating and sending a request key command frame. */ +typedef enum +{ + APS_REQUEST_KEY_SUCCESS_STATUS = 0x00, + APS_REQUEST_KEY_NO_SHORT_ADDRESS_STATUS = 0x01, + APS_REQUEST_KEY_SECURITY_FAIL_STATUS = 0x02, + APS_REQUEST_KEY_NOT_SENT_STATUS = 0x03, + APS_REQUEST_KEY_TIMEOUT_STATUS = 0x04, + /* These names are deprecated and will be removed. */ + APS_RKR_SUCCESS_STATUS = APS_REQUEST_KEY_SUCCESS_STATUS, + APS_RKR_NO_SHORT_ADDRESS_STATUS = APS_REQUEST_KEY_NO_SHORT_ADDRESS_STATUS, + APS_RKR_SECURITY_FAIL_STATUS = APS_REQUEST_KEY_SECURITY_FAIL_STATUS, + APS_RKR_NOT_SENT_STATUS = APS_REQUEST_KEY_NOT_SENT_STATUS, + APS_RKR_TIMEOUT = APS_REQUEST_KEY_TIMEOUT_STATUS +} APS_RequestKeyStatus_t; + +/** This type is deprecated and will be removed. */ +typedef APS_RequestKeyStatus_t APS_RkrStatus_t; + +/**//** + * \struct APS_RequestKeyConf_t apsmeRequestKey.h "aps.h" + * + * \brief Parameters of APSME-REQUEST-KEY.confirm primitive. + **/ +typedef struct +{ + APS_RequestKeyStatus_t status; /*!< \sa APS_RequestKeyStatus_t */ +} APS_RequestKeyConf_t; + +/**//** + * \struct APS_RequestKeyReq_t apsmeRequestKey.h "aps.h" + * + * \brief Parameters of APSME-REQUEST-KEY.request primitive. + * + * See ZigBee Specification r19, Table 4.24, page 465. + **/ +typedef struct +{ + /** \cond SERVICE_FIELDS **/ + struct + { + /** Service field, used for queue support */ + QueueElement_t qelem; + /** Request to send APS Update Device command. */ + ApsCommandReq_t commandReq; + uint32_t ttl; + bool transportKeyReceived; + bool requestKeySent; + } service; + /** \endcond **/ + + /** \ref Endian "[LE]" The extended 64-bit address of the device to which + * the request-key command should be sent. */ + ExtAddr_t destAddress; + /** The type of key being requested: + * \li 0x01 = Network key, + * \li 0x02 = Application key, + * \li 0x04 = Trust Center Link Key. */ + APS_RequestKeyType_t keyType; + /** \ref Endian "[LE]" If the KeyType parameter indicates an application key, + * this parameter shall indicate an extended 64-bit address of a device that + * shall receive the same key as the device requesting the key. */ + ExtAddr_t partnerAddress; + /** Canfirmation parameters. \sa APS_RequestKeyConf_t */ + APS_RequestKeyConf_t confirm; + /** Callback function pointer as a handler of corresponding + * confirm primitive. */ + void (*APS_RequestKeyConf)(APS_RequestKeyConf_t *conf); +} APS_RequestKeyReq_t; + +/**//** + * \struct APS_RequestKeyInd_t apsmeRequestKey.h "aps.h" + * + * \brief Parameters of APSME-REQUEST-KEY.indication primitive. + * + * See ZigBee Specification r19, Table 4.25, page 466. + **/ +typedef struct +{ + /** \ref Endian "[LE]" The extended 64-bit address of the device that sent + * the request-key command. */ + ExtAddr_t srcAddress; + /** The type of key being requested. Valid values: + * \li APS_NETWORK_KEY_TYPE + * \li APS_APP_KEY_TYPE + **/ + APS_RequestKeyType_t keyType; + /** \ref Endian "[LE]" If the KeyType parameter indicates an application key, + * this parameter shall indicate an extended 64-bit address of a device that + * shall receive the same key as the device requesting the key. */ + ExtAddr_t partnerAddress; +} APS_RequestKeyInd_t; + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/**************************************************************************//** + \brief Request either the active network key or a new application link key + + See ZigBee Specification r19, 4.4.6.1, page 465. + + \param[in] req - pointer to APSME-REQUEST-KEY.request's parameters. + \sa APS_RequestKeyReq_t + \return None. + ******************************************************************************/ +void APS_RequestKeyReq(APS_RequestKeyReq_t *req); + +/**************************************************************************//** + \brief Generate this primitive when APS receives a request-key command frame + + Upon receipt of the APSME-REQUEST-KEY.indication primitive, the ZDO shall + be informed that the device referenced by the SrcAddress parameter is + requesting a key. See ZigBee Specification r19, 4.4.6.2, page 466. + + \param[in] indParams - pointer to APSME-REQUEST-KEY.indication's parameters. + \sa APS_RequestKeyInd_t + \return None. + ******************************************************************************/ +void APS_RequestKeyInd(APS_RequestKeyInd_t *indParams); + +#endif /* _SECURITY_ and _LINK_SECURITY_ */ + +#endif /* _APSME_REQUEST_KEY_H */ +/** eof apsmeRequestKey.h */ + diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/apsmeSwitchKey.h b/digital/zigbit/bitcloud/stack/Components/APS/include/apsmeSwitchKey.h new file mode 100644 index 00000000..6833adc6 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/apsmeSwitchKey.h @@ -0,0 +1,155 @@ +/**************************************************************************//** + \file apsmeSwitchKey.h + + \brief Interface of APS Switch Key Service. + + \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-24 Max Gekk - Created. + Last change: + $Id: apsmeSwitchKey.h 18914 2011-10-18 09:13:36Z mgekk $ + ******************************************************************************/ +#if !defined _APSME_SWITCH_KEY_H +#define _APSME_SWITCH_KEY_H +/**//** + * + * The APS layer provides services that allow a device (typically, + * the trust center) to inform another device that it should be switched to a new + * active network key. See ZigBee Specification r19, 4.4.7, page 467. + * + **/ + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include + +#if defined _SECURITY_ +/****************************************************************************** + Types section + ******************************************************************************/ +/** Status of creating and sending a switch key command frame. */ +typedef enum +{ + APS_SWITCH_SUCCESS_STATUS = 0x00, + APS_SWITCH_NO_SHORT_ADDRESS_STATUS = 0x01, + APS_SWITCH_SECURITY_FAIL_STATUS = 0x02, + APS_SWITCH_NOT_SENT_STATUS = 0x03, + /* These names are deprecated and will be removed. */ + APS_SKR_SUCCESS_STATUS = APS_SWITCH_SUCCESS_STATUS, + APS_SKR_NO_SHORT_ADDRESS_STATUS = APS_SWITCH_NO_SHORT_ADDRESS_STATUS, + APS_SKR_SECURITY_FAIL_STATUS = APS_SWITCH_SECURITY_FAIL_STATUS, + APS_SKR_NOT_SENT_STATUS = APS_SWITCH_NOT_SENT_STATUS +} APS_SwitchStatus_t; + +/** This type is deprecated and will be removed. */ +typedef APS_SwitchStatus_t APS_SkrStatus_t; + +/**//** + * \struct APS_SwitchKeyConf_t apsmeSwitchKey.h "aps.h" + * + * \brief Confirmation parameters of APSME-SWITCH-KEY.request primitive. + **/ +typedef struct +{ + /* Status of key switching. */ + APS_SwitchStatus_t status; +} APS_SwitchKeyConf_t; + +/**//** + * \struct APS_SwitchKeyReq_t apsmeSwitchKey.h "aps.h" + * + * \brief Parameters of APSME-SWITCH-KEY.request primitive. + * + * See ZigBee Specification r19, Table 4.26, page 468. + **/ +typedef struct +{ + /** \cond SERVICE_FIELDS **/ + struct + { + /** Request to send APS Remove Device command. */ + ApsCommandReq_t commandReq; + } service; + /** \endcond **/ + + /** \ref Endian "[LE]" The extended 64-bit address of the device to + * which the switch-key command is sent. */ + ExtAddr_t destAddress; + /** A sequence number assigned to a network key by the Trust Center + * and used to distinguish network keys. */ + uint8_t keySeqNumber; + /** Confirm primitive as a parameter of the callback function */ + APS_SwitchKeyConf_t confirm; + /** Callback function pointer as a handler of corresponding + * confirm primitive. */ + void (*APS_SwitchKeyConf)(APS_SwitchKeyConf_t *conf); +} APS_SwitchKeyReq_t; + +/**//** + * \struct APS_SwitchKeyInd_t apsmeSwitchKey.h "aps.h" + * + * \brief Parameters of APSME-SWITCH-KEY.indication primitive. + * + * See ZigBee Specification r19, Table 4.27, page 469. + **/ +typedef struct +{ + /** \ref Endian "[LE]" The extended 64-bit address of the device + * that sent the switch-key command. */ + ExtAddr_t srcAddress; + /** A sequence number assigned to a network key by the Trust Center + * and used to distinguish network keys. */ + NWK_KeySeqNum_t keySeqNumber; +} APS_SwitchKeyInd_t; + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/**************************************************************************//** + \brief Sends a command to a remote device to switch to another network key + + The command can be send by the trust center to force a specific device or all + devices in the network to make another network key active. If a single node is to be + affected the extended address of the node shall be specified in the \c destAddress field. + To send a switch key command to all devices in the network assign \c destAddress to + ::APS_SM_BROADCAST_RX_ON_WHEN_IDLE_EXT_ADDRESS. + + A single network key must be active on all devices in the network. Two network keys + may be active on different device, while the network is switching to the new network + key. In high security the command to switch the network key must be sent by the trust + center separately to each device in the network (unicast). In other security modes the + trust center should send a broadcast request. + + The function conforms to a primitive defined in ZigBee Specification r19, 4.4.7.1, page 467. + + \param[in] req - pointer to APSME-SWITCH-KEY.request's parameters. + \sa APS_SwitchKeyReq_t + \return None + ******************************************************************************/ +void APS_SwitchKeyReq(APS_SwitchKeyReq_t *req); + +/**************************************************************************//** + \brief Informs the upper layer that it received a switch key command frame. + + The APS layer shall generate this primitive when it receives a switch-key + command frame that is successfully decrypted and authenticated. + See ZigBee Specification r19, 4.4.7.2, page 468. + + \param[in] ind - pointer to APSME-SWITCH-KEY.indication's parameters. + \sa APS_SwitchKeyInd_t + \return None. + ******************************************************************************/ +void APS_SwitchKeyInd(APS_SwitchKeyInd_t *ind); + +#endif /* _SECURITY_ */ +#endif /* _APSME_SWITCH_KEY_H */ +/** eof apsmeSwitchKey.h */ + diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/apsmeTransportKey.h b/digital/zigbit/bitcloud/stack/Components/APS/include/apsmeTransportKey.h new file mode 100644 index 00000000..2c50ab5f --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/apsmeTransportKey.h @@ -0,0 +1,292 @@ +/**************************************************************************//** + \file apsmeTransportKey.h + + \brief Interface of APS Transport-Key Services. + + \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-24 Max Gekk - Created. + Last change: + $Id: apsmeTransportKey.h 17946 2011-07-13 09:26:59Z mgekk $ + ******************************************************************************/ +#if !defined _APSME_TRANSPORT_KEY_H +#define _APSME_TRANSPORT_KEY_H +/**//** + * + * The APS-layer provides this services that allow an initiator to transport + * keying material to a responder. The different types of keying material that + * can be transported are shown in Tables 4.12 to 4.15 of ZigBee Spec. r19. + * + **/ + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include +#if defined _SECURITY_ +#include + +/****************************************************************************** + Types section + ******************************************************************************/ +/**//** + * \brief KeyType Parameter of the Transport-Key Primitive. + * See ZigBee Specification r19, Table 4.12, page 452. + **/ +typedef enum +{ + /** Indicates the key is a master key used to set up link keys between + * the Trust Center and another device. */ + APS_TRUST_CENTER_MASTER_KEY_TYPE = 0x00, + /** Indicates that the key is a network key to be used in standard security + * mode and may be distributed using key-transport or a standard network key. + **/ + APS_STANDARD_NETWORK_KEY_TYPE = 0x01, + /** Indicates the key is a master key used to set up link keys between + * two devices. */ + APS_APP_MASTER_KEY_TYPE = 0x02, + /** Indicates the key is a link key used as a basis of security between + * two devices. */ + APS_APP_LINK_KEY_TYPE = 0x03, + /** Indicates that the key is a link key used as a basis for security + * between the Trust Center and another device. */ + APS_TRUST_CENTER_LINK_KEY_TYPE = 0x04, + /** Indicates that the key is a network key to be used in high security + * mode and may be distributed using key-transport only. */ + APS_HIGH_SECURITY_NETWORK_KEY_TYPE = 0x05 +} APS_TransportKeyType_t; + +/**//** + * \brief TransportKeyData Parameter for a Trust Center Master Key or Link Key + * See ZigBee Specification r19, Table 4.13, page 453. + **/ +typedef struct +{ + /** \ref Endian "[LE]" The extended 64-bit address of the parent of + * the destination device given by the DestAddress parameter. */ + ExtAddr_t parentAddress; + /** The Trust Center master or link key. */ + uint8_t key[SECURITY_KEY_SIZE]; +} APS_ReqTrustCenterMasterOrLinkKeyTransportData_t; + +/**//** + * \brief TransportKeyData Parameter for a Network Key. + * See ZigBee Specification r19, Table 4.14, page 453. + **/ +typedef struct +{ + /** A sequence number assigned to a network key by the Trust Center and used + * to distinguish network keys for purposes of key updates and incoming + * frame security operations. */ + uint8_t keySeqNumber; + uint8_t networkKey[SECURITY_KEY_SIZE]; + /** This parameter indicates if the destination device's parent shall be + * used to forward the key to the destination device: + * \li TRUE = Use parent, + * \li FALSE = Do not use parent. */ + bool useParent; + /** \ref Endian "[LE]" If the UseParent is TRUE, then ParentAddress parameter + * shall contain the extended 64-bit address of the destination device’s + * parent device; otherwise, this parameter is not used and need not be set.*/ + ExtAddr_t parentAddress; + /** Use tunneling for transport NWK key. */ + bool tunneling; +} APS_ReqNetworkKeyTransportData_t; + +/**//** + * \brief TransportKeyData Parameter for an Application Master or Link Key. + * See ZigBee Specification r19, Table 4.15, page 454. + **/ +typedef struct +{ + /** \ref Endian "[LE]" The extended 64-bit address of the device that was also + * sent this master key. */ + ExtAddr_t partnerAddress; + /** This parameter indicates if the destination device of this master + * key requested it: + * \li TRUE = If the destination requested the key, + * \li FALSE = Otherwise. */ + bool initiator; + /** The master or link key (as indicated by the KeyType parameter). */ + uint8_t key[SECURITY_KEY_SIZE]; +} APS_ReqApplicationMasterOrLinkKeyTransportData_t; + +typedef union +{ + APS_ReqTrustCenterMasterOrLinkKeyTransportData_t trustCenterKey; + APS_ReqNetworkKeyTransportData_t networkKey; + APS_ReqApplicationMasterOrLinkKeyTransportData_t applicationKey; +} APS_ReqTransportKeyData_t; + +/** Status of creating and sending a transport key command frame. */ +typedef enum +{ + APS_TRANSPORT_KEY_SUCCESS_STATUS = 0x00, + APS_TRANSPORT_KEY_NO_SHORT_ADDRESS_STATUS = 0x01, + APS_TRANSPORT_KEY_SECURITY_FAIL_STATUS = 0x02, + APS_TRANSPORT_KEY_NOT_SENT_STATUS = 0x03, + APS_TRANSPORT_KEY_INVALID_PARAMETER_STATUS = 0x04, + /* These names are deprecated and will be removed. */ + APS_TKR_SUCCESS_STATUS = APS_TRANSPORT_KEY_SUCCESS_STATUS, + APS_TKR_NO_SHORT_ADDRESS_STATUS = APS_TRANSPORT_KEY_NO_SHORT_ADDRESS_STATUS, + APS_TKR_SECURITY_FAIL_STATUS = APS_TRANSPORT_KEY_SECURITY_FAIL_STATUS, + APS_TKR_NOT_SENT_STATUS = APS_TRANSPORT_KEY_NOT_SENT_STATUS +} APS_TkrStatus_t; + +/**//** + * \struct APS_TransportKeyConf_t apsmeTransportKey.h "aps.h" + * + * \brief Confirmation parameters of APSME-TRANSPORT-KEY.request. + **/ +typedef struct +{ + APS_TkrStatus_t status; +} APS_TransportKeyConf_t; + +/**//** + * \struct APS_TransportKeyReq_t apsmeTransportKey.h "aps.h" + * + * \brief Parameters of APSME-TRANSPORT-KEY.request primitive. + * See ZigBee Specification r19, 4.4.3.1, page 451. + **/ +typedef struct +{ + /** \cond SERVICE_FIELDS **/ + struct + { + ApsCommandReq_t commandReq; + /** Global internal state of APS Transport Key component. */ + enum + { + APS_TRANSPORT_KEY_BEGIN_STATE, + APS_TRANSPORT_KEY_CONFIRM_STATE, + APS_TRANSPORT_KEY_PROCESS_STATE + } state; + } service; + /** \endcond **/ + + /** \ref Endian "[LE]" + * The extended 64-bit address of the destination device.*/ + ExtAddr_t destAddress; + /** Identifies the type of key material that should be transported; + * See ZigBee Specification r19, Table 4.12, page 452. */ + APS_TransportKeyType_t keyType; + /** The key being transported along with identification + * and usage parameters. */ + APS_ReqTransportKeyData_t transportKeyData; + /** Confirm primitive as a parameter of the callback function. */ + APS_TransportKeyConf_t confirm; + /** Callback function pointer as a handler of corresponding + * confirm primitive. */ + void (*APS_TransportKeyConf)(APS_TransportKeyConf_t *conf); +} APS_TransportKeyReq_t; + +/**//** + * \brief TransportKeyData Parameter for a Trust Center Master or Link Key. + * See ZigBee Specification r19, Table 4.17, page 457. + **/ +typedef struct +{ + uint8_t trustCenterMasterKey[SECURITY_KEY_SIZE]; +} APS_IndTrustCenterMasterOrLinkKeyTransportData_t; + +/**//** + * \brief TransportKeyData Parameter for a Network Key. + * See ZigBee Specification r19, Table 4.18, page 457. + **/ +typedef struct +{ + /** A sequence number assigned to a network key by the Trust Center and + * used to distinguish. */ + uint8_t keySeqNumber; + uint8_t networkKey[SECURITY_KEY_SIZE]; +} APS_IndNetworkKeyTransportData_t; + +/**//** + * \brief TransportKeyData Parameter for an Application Master or Link Key. + * See ZigBee Specification r19, Table 4.19, page 457. + **/ +typedef struct +{ + /** This parameter indicates this device was initiator or not. */ + bool initiatorFlag; + /** \ref Endian "[LE]" The extended 64-bit address of the device that was also + * sent this master key. */ + ExtAddr_t partnerAddress; + /** The master or link key (as indicated by the KeyType + * parameter). \sa APS_TransportKeyInd_t */ + uint8_t key[SECURITY_KEY_SIZE]; +} APS_IndApplicationMasterOrLinkKeyTransportData_t; + +typedef union +{ + APS_IndTrustCenterMasterOrLinkKeyTransportData_t trustCenterKey; + APS_IndNetworkKeyTransportData_t networkKey; + APS_IndApplicationMasterOrLinkKeyTransportData_t applicationKey; +} APS_IndTransportKeyData_t; + +//\cond internal +/**//** + * \struct APS_TransportKeyInd_t apsmeTransportKey.h "aps.h" + * + * \brief Parameters of APSME-TRANSPORT-KEY.indication primitive. + * See ZigBee Specification r19, 4.4.3.2, page 455. + **/ +typedef struct +{ + /** \ref Endian "[LE]" The extended 64-bit address of the device + * that is the original source of the transported key. */ + ExtAddr_t srcAddress; + /** Identifies the type of key material that was be transported; + * See Table 4.12 of ZigBee Specification r19. */ + APS_TransportKeyType_t keyType; + /** The key that was transported along with identification and usage + * parameters. The type of this parameter depends on the KeyType + * parameter. */ + APS_IndTransportKeyData_t transportKeyData; + /* Type of key with the transport key command was secured. */ + APS_Status_t securedWith; +} APS_TransportKeyInd_t; +//\endcond + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/**************************************************************************//** + \brief Transfers a security key to a specified node + + The function is used by the stack on the trust center to transfer security + keys during authentication procedures and upon receiving requests for a link + key. The application can also use it, for example, to distribute a new network + key. The function conforms to ZigBee Specification r19, 4.4.3.1, page 451. + + \param[in] req - a pointer to request parameters of type APS_TransportKeyReq_t + + \return None. + ******************************************************************************/ +void APS_TransportKeyReq(APS_TransportKeyReq_t *const req); + +/**************************************************************************//** + \cond internal + \brief Informs ZDO of security key reception + + See ZigBee Specification r19, 4.4.3.2, page 455. + + \param[in] ind - pointer to APSME-TRANSPORT-KEY.indication's parameters. + + \return None + \endcond + ******************************************************************************/ +void APS_TransportKeyInd(APS_TransportKeyInd_t *ind); + +#endif /* _SECURITY_ */ +#endif /* _APSME_TRANSPORT_KEY_H */ +/** eof apsmeTransportKey.h */ + diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/apsmeUpdateDevice.h b/digital/zigbit/bitcloud/stack/Components/APS/include/apsmeUpdateDevice.h new file mode 100644 index 00000000..748fc80f --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/apsmeUpdateDevice.h @@ -0,0 +1,165 @@ +/**************************************************************************//** + \file apsmeUpdateDevice.h + + \brief Interface of APS Update Device Service. + + \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-24 Max Gekk - Created. + Last change: + $Id: apsmeUpdateDevice.h 17448 2011-06-09 13:53:59Z ataradov $ + ******************************************************************************/ +#if !defined _APSME_UPDATE_DEVICE_H +#define _APSME_UPDATE_DEVICE_H +/**//** + * + * The APS-layer provides services that allow a device (for example, a router) + * to inform another device (for example, a Trust Center) that a third device + * has changed its status (for example, joined or left the network). See ZigBee + * Specification r19, 4.4.4, page 459. + * + **/ +/****************************************************************************** + Includes section + ******************************************************************************/ +#include + +#if defined _SECURITY_ +/****************************************************************************** + Types section + ******************************************************************************/ +/** Status of creating and sending a update device command frame. */ +typedef enum +{ + APS_UPDATE_SUCCESS_STATUS = 0x00, + APS_UPDATE_NO_SHORT_ADDRESS_STATUS = 0x01, + APS_UPDATE_SECURITY_FAIL_STATUS = 0x02, + APS_UPDATE_NOT_SENT_STATUS = 0x03, + /* These names are deprecated and will be removed. */ + APS_UDR_SUCCESS_STATUS = APS_UPDATE_SUCCESS_STATUS, + APS_UDR_NO_SHORT_ADDRESS_STATUS = APS_UPDATE_NO_SHORT_ADDRESS_STATUS, + APS_UDR_SECURITY_FAIL_STATUS = APS_UPDATE_SECURITY_FAIL_STATUS, + APS_UDR_NOT_SENT_STATUS = APS_UPDATE_NOT_SENT_STATUS +} APS_UpdateStatus_t; + +/** This type is deprecated and will be removed. */ +typedef APS_UpdateStatus_t APS_UdrStatus_t; + +/**//** + * \struct APS_UpdateDeviceConf_t apsmeUpdateDevice.h "aps.h" + * + * \brief Type of confirmation parameters of APSME-UPDATE-DEVICE.confirm. + **/ +typedef struct +{ + APS_UpdateStatus_t status; +} APS_UpdateDeviceConf_t; + +/** Type is used to indicate the updated status of the device + * given by the DeviceAddress parameter. See ZigBee Spec. r19, Table 4.20. */ +typedef enum +{ + APS_UPDATE_DEVICE_STATUS_STANDARD_SECURED_REJOIN = 0x00, + APS_UPDATE_DEVICE_STATUS_STANDARD_UNSECURED_JOIN = 0x01, + APS_UPDATE_DEVICE_STATUS_LEFT = 0x02, + APS_UPDATE_DEVICE_STATUS_STANDARD_UNSECURED_REJOIN = 0x03, + APS_UPDATE_DEVICE_STATUS_HIGH_SECURITY_SECURED_REJOIN = 0x04, + APS_UPDATE_DEVICE_STATUS_HIGH_SECURITY_UNSECURED_JOIN = 0x05, + APS_UPDATE_DEVICE_STATUS_RESERVED = 0x06, + APS_UPDATE_DEVICE_STATUS_HIGH_SECURITY_UNSECURED_REJOIN = 0x07 +} APS_UpdateDeviceStatus_t; + +/**//** + * \struct APS_UpdateDeviceReq_t apsmeUpdateDevice.h "aps.h" + * + * \brief Parameters of APSME-UPDATE-DEVICE.request primitive. + * See ZigBee Specification r19, 4.4.4.1, page 459. + **/ +typedef struct +{ + /** \cond SERVICE_FIELDS **/ + struct + { + /** Request to send APS Update Device command. */ + ApsCommandReq_t commandReq; + } service; + /** \endcond **/ + + /** \ref Endian "[LE]" The extended 64-bit address of the device that shall + * be sent the update information. */ + ExtAddr_t destAddress; + /** \ref Endian "[LE]" + * The extended 64-bit address of the device whose status is being updated. */ + ExtAddr_t deviceAddress; + /** This parameter Indicates the updated status of the device given + * by the deviceAddress parameter. */ + APS_UpdateDeviceStatus_t status; + /** \ref Endian "[LE]" + * The 16-bit network address of the device whose status is being updated. */ + ShortAddr_t deviceShortAddress; + /** Confirm primitive as a parameter of the callback function. */ + APS_UpdateDeviceConf_t confirm; + /** Callback function pointer as a handler of corresponding + * confirm primitive. */ + void (*APS_UpdateDeviceConf)(APS_UpdateDeviceConf_t *conf); +} APS_UpdateDeviceReq_t; + +/**//** + * \struct APS_UpdateDeviceInd_t apsmeUpdateDevice.h "aps.h" + * + * \brief Parameters of APSME-UPDATE-DEVICE.indication primitive. + * See ZigBee Specification r19, 4.4.4.2, page 461. + **/ +typedef struct +{ + /** \ref Endian "[LE]" The extended 64-bit address of the device originating + * the update-device command. */ + ExtAddr_t srcAddress; + /** \ref Endian "[LE]" + * The extended 64-bit address of the device whose status is being updated. */ + ExtAddr_t deviceAddress; + /** This parameter Indicates the updated status of the device given + * by the deviceAddress parameter. */ + APS_UpdateDeviceStatus_t status; + /** \ref Endian "[LE]" + * The 16-bit network address of the device whose status is being updated. */ + ShortAddr_t deviceShortAddress; +} APS_UpdateDeviceInd_t; + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/**************************************************************************//** + \brief Request to inform a device that another device has new status. + + The ZDO (for example, on a router or ZigBee coordinator) shall initiate + the APSME-UPDATE-DEVICE.request primitive when it wants to send updated + device information to another device (for example, the Trust Center). + See ZigBee Specification r15, 4.4.1, page 459. + + \param[in] req - pointer to APSME-UPDATE-DEVICE.request's parameters. + + \return None. + ******************************************************************************/ +void APS_UpdateDeviceReq(APS_UpdateDeviceReq_t *req); + +/**************************************************************************//** + \brief Inform the upper-layer that it received an update-device command frame. + + \param[in] ind - pointer to APSME-UPDATE-DEVICE.indication's parameters. + + \return None. + ******************************************************************************/ +void APS_UpdateDeviceInd(APS_UpdateDeviceInd_t *ind); + +#endif /* _SECURITY_ */ +#endif /* _APSME_UPDATE_DEVICE_H */ +/** eof apsmeUpdateDevice.h */ + diff --git a/digital/zigbit/bitcloud/stack/Components/APS/include/intrpData.h b/digital/zigbit/bitcloud/stack/Components/APS/include/intrpData.h new file mode 100644 index 00000000..4f46d490 --- /dev/null +++ b/digital/zigbit/bitcloud/stack/Components/APS/include/intrpData.h @@ -0,0 +1,194 @@ +/**************************************************************************//** + \file intrpData.h + + \brief Interface of inter-PAN 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-02-18 A. Kostyukov - Created. + 2010-11-20 Max Gekk - Refactoring. + Last change: + $Id: intrpData.h 18271 2011-08-18 12:07:56Z nfomin $ + ******************************************************************************/ +#if !defined _INTRP_DATA_H +#define _INTRP_DATA_H +/**//** + * + * Inter-PAN is a transmission mechanism whereby ZigBee devices can perform + * limited, insecure, and possibly anonymous exchanges of information with + * devices in their local neighborhood without having to form or join the same + * ZigBee network. See ZigBee SE Profile Spec r15, page 81. + * + **/ + +/****************************************************************************** + Includes section + ******************************************************************************/ +#include + +#if defined _INTERPAN_ + +/****************************************************************************** + Definitions section +******************************************************************************/ +#define INTRP_NO_PANID_COMPRESSION_TXOPTION 1u + +/****************************************************************************** + Types section + ******************************************************************************/ +/** Type of handle associated with the inter-PAN ASDU to be transmitted. */ +typedef uint8_t IntrpAsduHandle_t; +/** Type of inter-PAN frame length. */ +typedef uint8_t IntrpLength_t; + +/**//** + * \struct INTRP_DataConf_t intrpData.h "aps.h" + * + * \brief INTRP-DATA confirm primitive's parameters structure declaration. + * + * ZigBee Smart Energy profile specification r15, B.3.2. + * The INTRP-DATA.confirm Primitive, page 85. + **/ +typedef struct +{ + /** An integer handle associated with the transmitted frame. */ + IntrpAsduHandle_t asduHandle; + /** The status of the ASDU transmission corresponding to ASDUHandle as + * returned by the MAC.*/ + MAC_Status_t status; +} INTRP_DataConf_t; + +typedef uint8_t INTRP_TxOptions_t; + +/**//** + * \struct INTRP_DataReq_t intrpData.h "aps.h" + * + * \brief INTRP-DATA.request primitive's parameters structure declaration. + * + * ZigBee Smart Energy profile specification r15, B.3.1 + * The INTRP-DATA.request Primitive, page 83. + **/ +typedef struct +{ + /** \cond SERVICE_FIELDS **/ + struct + { + /** MCPS-DATA request primitive's parameters structure. */ + MAC_DataReq_t macDataReq; + } service; + /** \endcond **/ + + /** The addressing mode for the destination address used in this primitive. + * This parameter can take one of the values from the following list: + * \li 0x01 = 16-bit group address + * \li 0x02 = 16-bit NWK address, normally the broadcast address 0xffff + * \li 0x03 = 64-bit extended address + **/ + APS_AddrMode_t dstAddrMode; + /** \ref Endian "[LE]" The 16-bit PAN identifier of the entity or entities + * to which the ASDU is being transferred or the broadcast PANId 0xffff. */ + PanId_t dstPANID; + /** \ref Endian "[LE]" The address of the entity or entities to which + * the ASDU is being transferred. */ + MAC_Addr_t dstAddress; + /** \ref Endian "[LE]" The identifier of the profile for which this frame is + * intended. */ + ProfileId_t profileId; + /** \ref Endian "[LE]" The identifier of the cluster, within the profile + * specified by the ProfileId parameter, which defines the application + * semantics of the ASDU. **/ + ClusterId_t clusterId; + /** The number of octets in the ASDU to be transmitted. */ + IntrpLength_t asduLength; + /** The set of octets comprising the ASDU to be transferred. */ + uint8_t *asdu; + /** An integer handle associated with the ASDU to be transmitted. */ + IntrpAsduHandle_t asduHandle; + /** Callback function pointer as a handler of corresponding + * confirm primitive. + **/ + void (*INTRP_DataConf)(INTRP_DataConf_t *conf); + /** Confirm primitive as a parameter of the callback function. */ + INTRP_DataConf_t confirm; + /** Transmission options for this request **/ + INTRP_TxOptions_t txOptions; +} INTRP_DataReq_t; + +/**//** + * \struct INTRP_DataInd_t intrpData.h "aps.h" + * + * \brief INTRP-DATA indication primitive's parameters structure declaration. + * + * ZigBee Smart Energy profile specification r15, B.3.3. + * The INTRP-DATA.indication Primitive, page 86. + **/ +typedef struct +{ + /** \ref Endian "[LE]" The 16-bit PAN identifier of the entity from which + * the ASDU is being transferred. */ + PanId_t srcPANID; + /** \ref Endian "[LE]" The device address of the entity from which + * the ASDU is being transferred. */ + MAC_Addr_t srcAddress; + /** The addressing mode for the destination address used in this primitive. + * This parameter can take one of the values from the following list: + * \li 0x01 = 16-bit group address + * \li 0x02 = 16-bit NWK address, normally the broadcast address 0xffff + * \li 0x03 = 64-bit extended address. + **/ + APS_AddrMode_t dstAddrMode; + /** \ref Endian "[LE]" The 16-bit PAN identifier of the entity or entities + * to which the ASDU is being transferred or the broadcast PANId 0xffff. */ + PanId_t dstPANID; + /** \ref Endian "[LE]" The address of the entity or entities to which + * the ASDU is being transferred. */ + MAC_Addr_t dstAddress; + /** \ref Endian "[LE]" + * The identifier of the profile for which this frame is intended. */ + ProfileId_t profileId; + /** \ref Endian "[LE]" The identifier of the cluster, within the profile + * specified by the ProfileId parameter, which defines the application + * semantics of the ASDU. */ + ClusterId_t clusterId; + /** The number of octets in the ASDU to be transmitted. */ + IntrpLength_t asduLength; + /** The set of octets comprising the ASDU to be transferred. */ + uint8_t *asdu; + /** The link quality observed during the reception of the ASDU. */ + Lqi_t lqi; + /** RSSI observed during the reception of the ASDU. */ + Lqi_t rssi; +} INTRP_DataInd_t; + +/****************************************************************************** + Prototypes section + ******************************************************************************/ +/**************************************************************************//** + \brief INTRP-DATA request primitive's prototype. + + \param[in] req - INTRP-DATA request parameters' structure pointer. + + \return None. + ******************************************************************************/ +void INTRP_DataReq(INTRP_DataReq_t *const req); + +/**************************************************************************//** + \brief INTRP-DATA indication primitive's prototype. + + \param[in] ind - INTRP-DATA indication parameters' structure pointer. + + \return None. + ******************************************************************************/ +void INTRP_DataInd(INTRP_DataInd_t *ind); + +#endif /* _INTERPAN_ */ +#endif /* _INTRP_DATA_H */ +/** eof intrpData.h */ + 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