From a54ad9edce697133a024aff096e50f7e4f389d5b Mon Sep 17 00:00:00 2001 From: Florent Duchon Date: Sun, 18 Mar 2012 12:22:02 +0100 Subject: digital/beacon: import Zigbit stack (bitcloud) & avr sources --- .../Components/ZCL/include/zclOTAUCluster.h | 564 +++++++++++++++++++++ 1 file changed, 564 insertions(+) create mode 100644 digital/beacon/src/Bitcloud_stack/Components/ZCL/include/zclOTAUCluster.h (limited to 'digital/beacon/src/Bitcloud_stack/Components/ZCL/include/zclOTAUCluster.h') diff --git a/digital/beacon/src/Bitcloud_stack/Components/ZCL/include/zclOTAUCluster.h b/digital/beacon/src/Bitcloud_stack/Components/ZCL/include/zclOTAUCluster.h new file mode 100644 index 00000000..32b0b9d0 --- /dev/null +++ b/digital/beacon/src/Bitcloud_stack/Components/ZCL/include/zclOTAUCluster.h @@ -0,0 +1,564 @@ +/**************************************************************************//** + \file zclOTAUCluster.h + + \brief The header file describes the OTAU cluster interface. + ZigBee Document 095264r17. + Revision 17 Version 0.7 March 14, 2010 + + \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: + 15.01.10 A. Khromykh - Created. +*******************************************************************************/ +#ifndef _ZCLOTAUCLUSTER_H +#define _ZCLOTAUCLUSTER_H + +/****************************************************************************** + Includes section +******************************************************************************/ +#include +#include +#include + +/****************************************************************************** + Defines section +******************************************************************************/ +//#define _OTAU_DEBUG_ + +/***************************************************************************//** + \brief ZCL OTAU Cluster atrebutes +*******************************************************************************/ +#define ZCL_OTAU_CLUSTER_SERVER_ATTRIBUTES_AMOUNT 0 +#define ZCL_OTAU_CLUSTER_CLIENT_ATTRIBUTES_AMOUNT 2 + +/***************************************************************************//** + \brief ZCL OTAU Cluster commands amount +*******************************************************************************/ +#define ZCL_OTAU_CLUSTER_COMMANDS_AMOUNT 7 + +//!ZCL OTAU Cluster client side attributes id +#define ZCL_OTAU_CLUSTER_CLIENT_UPGRADE_SERVER_ID 0x0000 +#define ZCL_OTAU_CLUSTER_CLIENT_IMAGE_UPGRADE_STATUS_ID 0x0006 + +#define DEFINE_OTAU_CLIENT_ATTRIBUTES \ + DEFINE_ATTRIBUTE(upgradeServerIEEEAddr, ZCL_READONLY_ATTRIBUTE, ZCL_OTAU_CLUSTER_CLIENT_UPGRADE_SERVER_ID, ZCL_IEEE_ADDRESS_DATA_TYPE_ID), \ + DEFINE_ATTRIBUTE(imageUpgradeStatus, ZCL_READONLY_ATTRIBUTE, ZCL_OTAU_CLUSTER_CLIENT_IMAGE_UPGRADE_STATUS_ID, ZCL_8BIT_ENUM_DATA_TYPE_ID) + +#define OTAU_HEADER_STRING_SIZE 32 + +// OTAU commands +// list of commands id +#define QUERY_NEXT_IMAGE_REQUEST_ID 0x01 +#define QUERY_NEXT_IMAGE_RESPONSE_ID 0x02 +#define IMAGE_BLOCK_REQUEST_ID 0x03 +#define IMAGE_PAGE_REQUEST_ID 0x04 +#define IMAGE_BLOCK_RESPONSE_ID 0x05 +#define UPGRADE_END_REQUEST_ID 0x06 +#define UPGRADE_END_RESPONSE_ID 0x07 + +#define DEFINE_QUERY_NEXT_IMAGE_REQUEST(queryNextImageReqInd) \ + DEFINE_COMMAND(queryNextImageReq, QUERY_NEXT_IMAGE_REQUEST_ID, \ + COMMAND_OPTIONS(CLIENT_TO_SERVER, ZCL_THERE_IS_RELEVANT_RESPONSE, ZCL_COMMAND_ACK), \ + queryNextImageReqInd) + +#define DEFINE_QUERY_NEXT_IMAGE_RESPONSE(queryNextImageRespInd) \ + DEFINE_COMMAND(queryNextImageResp, QUERY_NEXT_IMAGE_RESPONSE_ID, \ + COMMAND_OPTIONS(SERVER_TO_CLIENT, ZCL_THERE_IS_NO_RELEVANT_RESPONSE, ZCL_COMMAND_ACK), \ + queryNextImageRespInd) + +#define DEFINE_IMAGE_BLOCK_REQUEST(imageBlockReqInd) \ + DEFINE_COMMAND(imageBlockReq, IMAGE_BLOCK_REQUEST_ID, \ + COMMAND_OPTIONS(CLIENT_TO_SERVER, ZCL_THERE_IS_RELEVANT_RESPONSE, ZCL_COMMAND_ACK), \ + imageBlockReqInd) + +#define DEFINE_IMAGE_PAGE_REQUEST(imagePageReqInd) \ + DEFINE_COMMAND(imagePageReq, IMAGE_PAGE_REQUEST_ID, \ + COMMAND_OPTIONS(CLIENT_TO_SERVER, ZCL_THERE_IS_RELEVANT_RESPONSE, ZCL_COMMAND_ACK), \ + imagePageReqInd) + +#define DEFINE_IMAGE_BLOCK_RESPONSE(imageBlockRespInd) \ + DEFINE_COMMAND(imageBlockResp, IMAGE_BLOCK_RESPONSE_ID, \ + COMMAND_OPTIONS(SERVER_TO_CLIENT, ZCL_THERE_IS_NO_RELEVANT_RESPONSE, ZCL_COMMAND_ACK), \ + imageBlockRespInd) + +#define DEFINE_UPGRADE_END_REQUEST(upgradeEndReqInd) \ + DEFINE_COMMAND(upgradeEndReq, UPGRADE_END_REQUEST_ID, \ + COMMAND_OPTIONS(CLIENT_TO_SERVER, ZCL_THERE_IS_RELEVANT_RESPONSE, ZCL_COMMAND_ACK), \ + upgradeEndReqInd) + +#define DEFINE_UPGRADE_END_RESPONSE(upgradeEndRespInd) \ + DEFINE_COMMAND(upgradeEndResp, UPGRADE_END_RESPONSE_ID, \ + COMMAND_OPTIONS(SERVER_TO_CLIENT, ZCL_THERE_IS_NO_RELEVANT_RESPONSE, ZCL_COMMAND_ACK), \ + upgradeEndRespInd) + +#define OTAU_COMMANDS(queryNextImageReqInd, queryNextImageRespInd, imageBlockReqInd, imagePageReqInd, \ + imageBlockRespInd, upgradeEndReqInd, upgradeEndRespInd) \ + DEFINE_QUERY_NEXT_IMAGE_REQUEST(queryNextImageReqInd), \ + DEFINE_QUERY_NEXT_IMAGE_RESPONSE(queryNextImageRespInd), \ + DEFINE_IMAGE_BLOCK_REQUEST(imageBlockReqInd), \ + DEFINE_IMAGE_PAGE_REQUEST(imagePageReqInd), \ + DEFINE_IMAGE_BLOCK_RESPONSE(imageBlockRespInd), \ + DEFINE_UPGRADE_END_REQUEST(upgradeEndReqInd), \ + DEFINE_UPGRADE_END_RESPONSE(upgradeEndRespInd) + +/***************************************************************************//** + \brief ZCL OTAU Cluster server side defining macros + + \param attributes - pointer to cluster server attributes (ZCL_OtauClusterClientAttributes_t) + or NULL if there are no attributes + \param clcommands - pointer to cluster server commands + or NULL if there are no commands + + \return None +*******************************************************************************/ +#define OTAU_CLUSTER_ZCL_SERVER_CLUSTER_TYPE(clattributes, clcommands) \ + { \ + .id = OTAU_CLUSTER_ID, \ + .options = { \ + .type = ZCL_SERVER_CLUSTER_TYPE, \ + .security = ZCL_DEFAULT_CLUSTER_SECURITY, \ + .reserved = 0}, \ + .attributesAmount = ZCL_OTAU_CLUSTER_SERVER_ATTRIBUTES_AMOUNT, \ + .attributes = (uint8_t *) clattributes, \ + .commandsAmount = ZCL_OTAU_CLUSTER_COMMANDS_AMOUNT, \ + .commands = (uint8_t *) clcommands \ + } + +/***************************************************************************//** + \brief ZCL OTAU Cluster client side defining macros + + \param attributes - pointer to cluster client attributes (ZCL_OtauClusterClientAttributes_t) + or NULL if there are no attributes + \param clcommands - pointer to cluster client commands + or NULL if there are no commands + + \return None +*******************************************************************************/ +#define OTAU_CLUSTER_ZCL_CLIENT_CLUSTER_TYPE(clattributes, clcommands) \ + { \ + .id = OTAU_CLUSTER_ID, \ + .options = { \ + .type = ZCL_CLIENT_CLUSTER_TYPE, \ + .security = ZCL_DEFAULT_CLUSTER_SECURITY, \ + .reserved = 0}, \ + .attributesAmount = ZCL_OTAU_CLUSTER_CLIENT_ATTRIBUTES_AMOUNT, \ + .attributes = (uint8_t *) clattributes, \ + .commandsAmount = ZCL_OTAU_CLUSTER_COMMANDS_AMOUNT, \ + .commands = (uint8_t *) clcommands \ + } + +#define DEFINE_OTAU_CLUSTER(cltype, clattributes, clcommands) OTAU_CLUSTER_##cltype(clattributes, clcommands) +/******************************************************************************* + Types section +*******************************************************************************/ +typedef uint8_t OtauHeaderString_t[OTAU_HEADER_STRING_SIZE]; + +typedef enum PACK +{ + OTAU_SERVER_HAS_BEEN_FOUND, + OTAU_SERVER_HAS_NOT_BEEN_FOUND, + OTAU_SERVER_HAS_BEEN_LOST, + OTAU_OFD_DRIVER_ERROR, + OTAU_SERVER_RECEIVED_MALFORMED_COMMAND, + OTAU_SERVER_NO_IMAGE_AVAILABLE, + OTAU_SERVER_RECEIVED_UNSUPPORTED_COMMAND, + OTAU_SERVER_RECEIVED_UNKNOWN_STATUS, + OTAU_SERVER_IS_NOT_AUTHORIZED_TO_UPDATE, + OTAU_DOWNLOAD_STARTED, + OTAU_DOWNLOAD_ABORTED, + OTAU_DOWNLOAD_FINISHED, + OTAU_DEVICE_SHALL_CHANGE_IMAGE, + OTAU_ISD_IMAGE_CACHE_IS_FOUND, + OTAU_ISD_HARDWARE_FAULT, + OTAU_ISD_COMMUNICATION_LOST, + OTAU_MAX_MESSAGE_NUMBER +} ZCL_OtauAction_t; + +typedef void (* ZCL_OtauStatInd_t)(ZCL_OtauAction_t action); + +typedef enum +{ + OTAU_ZB_STACK_VERSION_2006 = 0x0000, + OTAU_ZB_STACK_VERSION_2007 = 0x0001, + OTAU_ZB_STACK_VERSION_PRO = 0x0002, + OTAU_ZB_STACK_VERSION_IP = 0x0003, + OTAU_FAKE_VERSION = 0xFFFF +} ZCL_OtauZigbeeStackVersion_t; + +typedef enum +{ + OTAU_SPECIFIC_IMAGE_TYPE = 0x0000, + OTAU_SECURITY_CREDENTIAL_TYPE = 0xFFC0, + OTAU_CONFIGURATION_TYPE = 0xFFC1, + OTAU_LOG_TYPE = 0xFFC2, + OTAU_WILD_CARD_TYPE = 0xFFFF +} ZCL_OtauImageType_t; + +typedef enum +{ + OTAU_UPGRADE_IMAGE = 0x0000, + OTAU_ECDSA_SIGNATURE = 0x0001, + OTAU_ECDSA_SIGNING_CERTIFICATE = 0x0002, + OTAU_FAKE_NUMBER = 0xFFFF +} ZCL_OtauTagID_t; + +BEGIN_PACK +typedef enum PACK +{ + OTAU_NORMAL, + OTAU_DOWNLOAD_IN_PROGRESS, + OTAU_DOWNLOAD_COMPLETE, + OTAU_WAITING_TO_UPGRADE, + OTAU_COUNT_DOWN, + OTAU_WAIT_FOR_MORE +} ZCL_ImageUpdateStatus_t; + +typedef union PACK +{ + uint16_t memAlloc; + struct PACK + { + uint16_t securityCredentialVersionPresent : 1; + uint16_t deviceSpecificFile : 1; + uint16_t hardwareVersionPresent : 1; + uint16_t reserved : 13; + }; +} ZCL_OtauHeaderFieldControl_t; + +typedef struct PACK +{ + ZCL_OtauTagID_t tagID; + uint32_t lengthField; +} ZCL_OtauSubElementHeader_t; + +typedef union PACK +{ + uint32_t memAlloc; + struct PACK + { + uint8_t appRelease; + uint8_t appBuild; + uint8_t stackRelease; + uint8_t stackBuild; + }; +} ZCL_OtauFirmwareVersion_t; + +/***************************************************************************//** + \brief + ZCL OTAU upgrade image header +*******************************************************************************/ +typedef struct PACK +{ + uint32_t magicNumber; + uint16_t headerVersion; + uint16_t headerLength; + ZCL_OtauHeaderFieldControl_t fieldControl; + uint16_t manufacturerId; + uint16_t imageType; + ZCL_OtauFirmwareVersion_t firmwareVersion; + ZCL_OtauZigbeeStackVersion_t zigbeeStackVersion; + OtauHeaderString_t headerString; + uint32_t totalImageSize; +} ZCL_OtauUpgradeImageHeader_t; + +/***************************************************************************//** + \brief + ZCL OTAU Cluster attributes. + Currently, all attributes are client side attributes (only stored on the client). +*******************************************************************************/ +typedef struct PACK +{ + /*! + \brief The attribute is used to store the IEEE address of the upgrade server + resulted from the discovery of the upgrade server's identity. If the value is set + to a non-zero value and corresponds to an IEEE address of a device that is no longer + accessible, a device may choose to discover a new Upgrade Server depending on its own + security policies. The attribute is mandatory because it serves as a placeholder in a case + where the client is programmed, during manufacturing time, its upgrade server ID. + In addition, the attribute is used to identify the current upgrade server the client is using + in a case where there are multiple upgrade servers in the network. The attribute is also helpful + in a case when a client has temporarily lost connection to the network (for example, via a reset + or a rejoin), it shall try to rediscover the upgrade server via network address discovery using + the IEEE address stored in the attribute. By default the value is 0xffffffffffffffff, which is + an invalid IEEE address. The attribute is a client-side attribute and stored on the client. + */ + struct PACK + { + ZCL_AttributeId_t id; //!