123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649 |
- /**************************************************************************************************
- Filename: zcl_cc.c
- Revised: $Date: 2011-04-13 10:27:39 -0700 (Wed, 13 Apr 2011) $
- Revision: $Revision: 25679 $
- Description: Zigbee Cluster Library - Commissioning Cluster
- Copyright 2011 Texas Instruments Incorporated. All rights reserved.
- IMPORTANT: Your use of this Software is limited to those specific rights
- granted under the terms of a software license agreement between the user
- who downloaded the software, his/her employer (which must be your employer)
- and Texas Instruments Incorporated (the "License"). You may not use this
- Software unless you agree to abide by the terms of the License. The License
- limits your use, and you acknowledge, that the Software may not be modified,
- copied or distributed unless embedded on a Texas Instruments microcontroller
- or used solely and exclusively in conjunction with a Texas Instruments radio
- frequency transceiver, which is integrated into your product. Other than for
- the foregoing purpose, you may not use, reproduce, copy, prepare derivative
- works of, modify, distribute, perform, display or sell this Software and/or
- its documentation for any purpose.
- YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
- PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
- INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
- NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
- TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
- NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
- LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
- INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
- OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
- OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
- (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
- Should you have any questions regarding your right to use this Software,
- contact Texas Instruments Incorporated at www.TI.com.
- **************************************************************************************************/
- /*********************************************************************
- * INCLUDES
- */
- #include "ZComDef.h"
- #include "OSAL.h"
- #include "zcl.h"
- #include "zcl_general.h"
- #include "zcl_cc.h"
- #if defined ( INTER_PAN )
- #include "stub_aps.h"
- #endif
- /*********************************************************************
- * MACROS
- */
- /*********************************************************************
- * CONSTANTS
- */
- /*********************************************************************
- * TYPEDEFS
- */
- typedef struct zclCCCBRec
- {
- struct zclCCCBRec *next;
- uint8 endpoint; // Used to link it into the endpoint descriptor
- zclCC_AppCallbacks_t *CBs; // Pointer to Callback function
- } zclCCCBRec_t;
- /*********************************************************************
- * GLOBAL VARIABLES
- */
- /*********************************************************************
- * GLOBAL FUNCTIONS
- */
- /*********************************************************************
- * LOCAL VARIABLES
- */
- static zclCCCBRec_t *zclCCCBs = (zclCCCBRec_t *)NULL;
- static uint8 zclCCPluginRegisted = FALSE;
- /*********************************************************************
- * LOCAL FUNCTIONS
- */
- /*
- * Callback from ZCL to process incoming Commands specific to this cluster library
- */
- static ZStatus_t zclCC_HdlIncoming( zclIncoming_t *pInMsg );
- /*
- * Function to process incoming Commands specific to this cluster library
- */
- static ZStatus_t zclCC_HdlInSpecificCommands( zclIncoming_t *pInMsg );
- /*
- * Process received Restart Device Command
- */
- static ZStatus_t zclCC_ProcessInCmd_RestartDevice( zclIncoming_t *pInMsg, zclCC_AppCallbacks_t *pCBs );
- /*
- * Process received Save Startup Parameters Command
- */
- static ZStatus_t zclCC_ProcessInCmd_SaveStartupParams( zclIncoming_t *pInMsg, zclCC_AppCallbacks_t *pCBs );
- /*
- * Process received Restore Startup Parameters Command
- */
- static ZStatus_t zclCC_ProcessInCmd_RestoreStartupParams( zclIncoming_t *pInMsg, zclCC_AppCallbacks_t *pCBs );
- /*
- * Process received Reset Startup Parameters Command
- */
- static ZStatus_t zclCC_ProcessInCmd_ResetStartupParams( zclIncoming_t *pInMsg, zclCC_AppCallbacks_t *pCBs );
- /*
- * Process received Restart Device Response
- */
- static ZStatus_t zclCC_ProcessInCmd_RestartDeviceRsp( zclIncoming_t *pInMsg, zclCC_AppCallbacks_t *pCBs );
- /*
- * Process received Save Startup Parameters Response
- */
- static ZStatus_t zclCC_ProcessInCmd_SaveStartupParamsRsp( zclIncoming_t *pInMsg, zclCC_AppCallbacks_t *pCBs );
- /*
- * Process received Restore Startup Parameters Response
- */
- static ZStatus_t zclCC_ProcessInCmd_RestoreStartupParamsRsp( zclIncoming_t *pInMsg, zclCC_AppCallbacks_t *pCBs );
- /*
- * Process received Reset Startup Parameters Response
- */
- static ZStatus_t zclCC_ProcessInCmd_ResetStartupParamsRsp( zclIncoming_t *pInMsg, zclCC_AppCallbacks_t *pCBs );
- /*********************************************************************
- * @fn zclCC_RegisterCmdCallbacks
- *
- * @brief Register an applications command callbacks
- *
- * @param endpoint - application's endpoint
- * @param callbacks - pointer to the callback record.
- *
- * @return ZSuccess if successful. ZMemError if not able to allocate
- */
- ZStatus_t zclCC_RegisterCmdCallbacks( uint8 endpoint, zclCC_AppCallbacks_t *callbacks )
- {
- zclCCCBRec_t *pNewItem;
- zclCCCBRec_t *pLoop;
- // Register as a ZCL Plugin
- if ( !zclCCPluginRegisted )
- {
- zcl_registerPlugin( ZCL_CLUSTER_ID_GEN_COMMISSIONING,
- ZCL_CLUSTER_ID_GEN_COMMISSIONING,
- zclCC_HdlIncoming );
- zclCCPluginRegisted = TRUE;
- }
- // Fill in the new profile list
- pNewItem = osal_mem_alloc( sizeof( zclCCCBRec_t ) );
- if ( pNewItem == NULL )
- {
- return ( ZMemError );
- }
- pNewItem->next = (zclCCCBRec_t *)NULL;
- pNewItem->endpoint = endpoint;
- pNewItem->CBs = callbacks;
- // Find spot in list
- if ( zclCCCBs == NULL )
- {
- zclCCCBs = pNewItem;
- }
- else
- {
- // Look for end of list
- pLoop = zclCCCBs;
- while ( pLoop->next != NULL )
- {
- pLoop = pLoop->next;
- }
- // Put new item at end of list
- pLoop->next = pNewItem;
- }
- return ( ZSuccess );
- }
- /*********************************************************************
- * @fn zclCC_FindCallbacks
- *
- * @brief Find the callbacks for an endpoint
- *
- * @param endpoint
- *
- * @return pointer to the callbacks
- */
- static zclCC_AppCallbacks_t *zclCC_FindCallbacks( uint8 endpoint )
- {
- zclCCCBRec_t *pCBs;
-
- pCBs = zclCCCBs;
- while ( pCBs != NULL )
- {
- if ( pCBs->endpoint == endpoint )
- {
- return ( pCBs->CBs );
- }
- pCBs = pCBs->next;
- }
- return ( (zclCC_AppCallbacks_t *)NULL );
- }
- /*********************************************************************
- * @fn zclCC_HdlIncoming
- *
- * @brief Callback from ZCL to process incoming Commands specific
- * to this cluster library or Profile commands for attributes
- * that aren't in the attribute list
- *
- * @param pInMsg - pointer to the incoming message
- *
- * @return ZStatus_t
- */
- static ZStatus_t zclCC_HdlIncoming( zclIncoming_t *pInMsg )
- {
- ZStatus_t stat = ZSuccess;
- #if defined ( INTER_PAN )
- if ( StubAPS_InterPan( pInMsg->msg->srcAddr.panId, pInMsg->msg->srcAddr.endPoint ) )
- {
- return ( stat ); // Cluster not supported thru Inter-PAN
- }
- #endif
- if ( zcl_ClusterCmd( pInMsg->hdr.fc.type ) )
- {
- // Is this a manufacturer specific command?
- if ( pInMsg->hdr.fc.manuSpecific == 0 )
- {
- stat = zclCC_HdlInSpecificCommands( pInMsg );
- }
- else
- {
- // We don't support any manufacturer specific command.
- stat = ZFailure;
- }
- }
- else
- {
- // Handle all the normal (Read, Write...) commands -- should never get here
- stat = ZFailure;
- }
- return ( stat );
- }
- /*********************************************************************
- * @fn zclCC_HdlInSpecificCommands
- *
- * @brief Function to process incoming Commands specific
- * to this cluster library
- * @param pInMsg - pointer to the incoming message
- *
- * @return ZStatus_t
- */
- static ZStatus_t zclCC_HdlInSpecificCommands( zclIncoming_t *pInMsg )
- {
- ZStatus_t stat;
- zclCC_AppCallbacks_t *pCBs;
-
- // Make sure endpoint exists
- pCBs = zclCC_FindCallbacks( pInMsg->msg->endPoint );
- if ( pCBs == NULL )
- {
- return ( ZFailure );
- }
- if ( zcl_ServerCmd( pInMsg->hdr.fc.direction ) )
- {
- // Process Client commands, received by server
- switch ( pInMsg->hdr.commandID )
- {
- case COMMAND_CC_RESTART_DEVICE:
- stat = zclCC_ProcessInCmd_RestartDevice( pInMsg, pCBs );
- break;
- case COMMAND_CC_SAVE_STARTUP_PARAMS:
- stat = zclCC_ProcessInCmd_SaveStartupParams( pInMsg, pCBs );
- break;
- case COMMAND_CC_RESTORE_STARTUP_PARAMS:
- stat = zclCC_ProcessInCmd_RestoreStartupParams( pInMsg, pCBs );
- break;
- case COMMAND_CC_RESET_STARTUP_PARAMS:
- stat = zclCC_ProcessInCmd_ResetStartupParams( pInMsg, pCBs );
- break;
- default:
- stat = ZFailure;
- break;
- }
- }
- else
- {
- switch ( pInMsg->hdr.commandID )
- {
- case COMMAND_CC_RESTART_DEVICE_RSP:
- stat = zclCC_ProcessInCmd_RestartDeviceRsp( pInMsg, pCBs );
- break;
- case COMMAND_CC_SAVE_STARTUP_PARAMS_RSP:
- stat = zclCC_ProcessInCmd_SaveStartupParamsRsp( pInMsg, pCBs );
- break;
- case COMMAND_CC_RESTORE_STARTUP_PARAMS_RSP:
- stat = zclCC_ProcessInCmd_RestoreStartupParamsRsp( pInMsg, pCBs );
- break;
- case COMMAND_CC_RESET_STARTUP_PARAMS_RSP:
- stat = zclCC_ProcessInCmd_ResetStartupParamsRsp( pInMsg, pCBs );
- break;
- default:
- stat = ZFailure;
- break;
- }
- }
-
- return ( stat );
- }
- /*********************************************************************
- * @fn zclCC_ProcessInCmd_RestartDevice
- *
- * @brief Process in the received Restart Device Command.
- *
- * @param pInMsg - pointer to the incoming message
- * @param pCBs - pointer to the Application callback
- *
- * @return ZStatus_t - status of the command processing
- */
- static ZStatus_t zclCC_ProcessInCmd_RestartDevice( zclIncoming_t *pInMsg,
- zclCC_AppCallbacks_t *pCBs )
- {
- if ( pCBs->pfnRestart_Device )
- {
- zclCCRestartDevice_t cmd;
- cmd.options = pInMsg->pData[0];
- cmd.delay = pInMsg->pData[1];
- cmd.jitter = pInMsg->pData[2];
- pCBs->pfnRestart_Device( &cmd, &(pInMsg->msg->srcAddr), pInMsg->hdr.transSeqNum );
- return ZCL_STATUS_CMD_HAS_RSP;
- }
- return ZFailure;
- }
- /*********************************************************************
- * @fn zclCC_ProcessInCmd_SaveStartupParams
- *
- * @brief Process in the received Save Startup Parameters Command.
- *
- * @param pInMsg - pointer to the incoming message
- * @param pCBs - pointer to the Application callback
- *
- * @return ZStatus_t - status of the command processing
- */
- static ZStatus_t zclCC_ProcessInCmd_SaveStartupParams( zclIncoming_t *pInMsg,
- zclCC_AppCallbacks_t *pCBs )
- {
- if ( pCBs->pfnSave_StartupParams )
- {
- zclCCStartupParams_t cmd;
- cmd.options = pInMsg->pData[0];
- cmd.index = pInMsg->pData[1];
- pCBs->pfnSave_StartupParams( &cmd, &(pInMsg->msg->srcAddr), pInMsg->hdr.transSeqNum );
- return ZCL_STATUS_CMD_HAS_RSP;
- }
- return ZFailure;
- }
- /*********************************************************************
- * @fn zclCC_ProcessInCmd_RestoreStartupParams
- *
- * @brief Process in the received Restore Startup Parameters Command.
- *
- * @param pInMsg - pointer to the incoming message
- * @param pCBs - pointer to the Application callback
- *
- * @return ZStatus_t - status of the command processing
- */
- static ZStatus_t zclCC_ProcessInCmd_RestoreStartupParams( zclIncoming_t *pInMsg,
- zclCC_AppCallbacks_t *pCBs )
- {
- if ( pCBs->pfnRestore_StartupParams )
- {
- zclCCStartupParams_t cmd;
- cmd.options = pInMsg->pData[0];
- cmd.index = pInMsg->pData[1];
- pCBs->pfnRestore_StartupParams( &cmd, &(pInMsg->msg->srcAddr), pInMsg->hdr.transSeqNum );
- return ZCL_STATUS_CMD_HAS_RSP;
- }
- return ZFailure;
- }
- /*********************************************************************
- * @fn zclCC_ProcessInCmd_ResetStartupParams
- *
- * @brief Process in the received Reset Startup Parameters Command.
- *
- * @param pInMsg - pointer to the incoming message
- * @param pCBs - pointer to the Application callback
- *
- * @return ZStatus_t - status of the command processing
- */
- static ZStatus_t zclCC_ProcessInCmd_ResetStartupParams( zclIncoming_t *pInMsg,
- zclCC_AppCallbacks_t *pCBs )
- {
- if ( pCBs->pfnReset_StartupParams )
- {
- zclCCStartupParams_t cmd;
- cmd.options = pInMsg->pData[0];
- cmd.index = pInMsg->pData[1];
- pCBs->pfnReset_StartupParams( &cmd, &(pInMsg->msg->srcAddr), pInMsg->hdr.transSeqNum );
- return ZCL_STATUS_CMD_HAS_RSP;
- }
- return ZFailure;
- }
- /*********************************************************************
- * @fn zclCC_ProcessInCmd_RestartDeviceRsp
- *
- * @brief Process in the received Restart Device Response
- *
- * @param pInMsg - pointer to the incoming message
- * @param pCBs - pointer to the Application callback
- *
- * @return ZStatus_t - status of the command processing
- */
- static ZStatus_t zclCC_ProcessInCmd_RestartDeviceRsp( zclIncoming_t *pInMsg,
- zclCC_AppCallbacks_t *pCBs )
- {
- if ( pCBs->pfnRestart_DeviceRsp )
- {
- zclCCServerParamsRsp_t rsp;
- rsp.status = pInMsg->pData[0];
- pCBs->pfnRestart_DeviceRsp( &rsp, &(pInMsg->msg->srcAddr), pInMsg->hdr.transSeqNum );
- return ZSuccess;
- }
- return ZFailure;
- }
- /*********************************************************************
- * @fn zclCC_ProcessInCmd_SaveStartupParamsRsp
- *
- * @brief Process in the received Save Startup Parameters Response
- *
- * @param pInMsg - pointer to the incoming message
- * @param pCBs - pointer to the Application callback
- *
- * @return ZStatus_t - status of the command processing
- */
- static ZStatus_t zclCC_ProcessInCmd_SaveStartupParamsRsp( zclIncoming_t *pInMsg,
- zclCC_AppCallbacks_t *pCBs )
- {
- if ( pCBs->pfnSave_StartupParamsRsp )
- {
- zclCCServerParamsRsp_t rsp;
- rsp.status = pInMsg->pData[0];
- pCBs->pfnSave_StartupParamsRsp( &rsp, &(pInMsg->msg->srcAddr), pInMsg->hdr.transSeqNum );
- return ZSuccess;
- }
- return ZFailure;
- }
- /*********************************************************************
- * @fn zclCC_ProcessInCmd_RestoreStartupParamsRsp
- *
- * @brief Process in the received Restore Startup Parameters Response
- *
- * @param pInMsg - pointer to the incoming message
- * @param pCBs - pointer to the Application callback
- *
- * @return ZStatus_t - status of the command processing
- */
- static ZStatus_t zclCC_ProcessInCmd_RestoreStartupParamsRsp( zclIncoming_t *pInMsg,
- zclCC_AppCallbacks_t *pCBs )
- {
- if ( pCBs->pfnRestore_StartupParamsRsp )
- {
- zclCCServerParamsRsp_t rsp;
- rsp.status = pInMsg->pData[0];
- pCBs->pfnRestore_StartupParamsRsp( &rsp, &(pInMsg->msg->srcAddr), pInMsg->hdr.transSeqNum );
- return ZSuccess;
- }
- return ZFailure;
- }
- /*********************************************************************
- * @fn zclCC_ProcessInCmd_ResetStartupParamsRsp
- *
- * @brief Process in the received Reset Startup Parameters Response
- *
- * @param pInMsg - pointer to the incoming message
- * @param pCBs - pointer to the Application callback
- *
- * @return ZStatus_t - status of the command processing
- */
- static ZStatus_t zclCC_ProcessInCmd_ResetStartupParamsRsp( zclIncoming_t *pInMsg,
- zclCC_AppCallbacks_t *pCBs )
- {
- if ( pCBs->pfnReset_StartupParamsRsp )
- {
- zclCCServerParamsRsp_t rsp;
- rsp.status = pInMsg->pData[0];
- pCBs->pfnReset_StartupParamsRsp( &rsp, &(pInMsg->msg->srcAddr), pInMsg->hdr.transSeqNum );
- return ZSuccess;
- }
- return ZFailure;
- }
-
- /*********************************************************************
- * @fn zclCC_Send_RestartDevice
- *
- * @brief Call to send out a Restart Device command
- *
- * @param srcEP - Sending application's endpoint
- * @param dstAddr - where you want the message to go
- * @param pCmd - pointer to Restart Command data structure
- * @param disableDefaultRsp - disable default response
- * @param seqNum - ZCL sequence number
- *
- * @return ZStatus_t
- */
- ZStatus_t zclCC_Send_RestartDevice( uint8 srcEP, afAddrType_t *dstAddr,
- zclCCRestartDevice_t *pCmd,
- uint8 disableDefaultRsp, uint8 seqNum )
- {
- uint8 buf[CC_PACKET_LEN_RESTART_DEVICE];
-
- buf[0] = pCmd->options;
- buf[1] = pCmd->delay;
- buf[2] = pCmd->jitter;
-
- return zcl_SendCommand( srcEP, dstAddr, ZCL_CLUSTER_ID_GEN_COMMISSIONING,
- COMMAND_CC_RESTART_DEVICE, TRUE,
- ZCL_FRAME_CLIENT_SERVER_DIR, disableDefaultRsp, 0,
- seqNum, CC_PACKET_LEN_RESTART_DEVICE, buf );
- }
- /*********************************************************************
- * @fn zclCC_Send_StartupParamsCmd
- *
- * @brief Call to send out a Startup parameter command (Restore, Save, Reset)
- *
- * @param srcEP - Sending application's endpoint
- * @param dstAddr - where you want the message to go
- * @param pCmd - pointer to Startup Parameter Command data structure
- * @param cmdId - Command type ( Restore, Save or Reset)
- * @param disableDefaultRsp - disable default response
- * @param seqNum - ZCL sequence number
- *
- * @return ZStatus_t
- */
- ZStatus_t zclCC_Send_StartupParamsCmd( uint8 srcEP, afAddrType_t *dstAddr,
- zclCCStartupParams_t *pCmd, uint8 cmdId,
- uint8 disableDefaultRsp, uint8 seqNum )
- {
- uint8 buf[CC_PACKET_LEN_STARTUP_PARAMS_CMD];
-
- buf[0] = pCmd->options;
- buf[1] = pCmd->index;
-
- return zcl_SendCommand( srcEP, dstAddr, ZCL_CLUSTER_ID_GEN_COMMISSIONING,
- cmdId, TRUE, ZCL_FRAME_CLIENT_SERVER_DIR,
- disableDefaultRsp, 0, seqNum,
- CC_PACKET_LEN_STARTUP_PARAMS_CMD, buf );
- }
- /*********************************************************************
- * @fn zclCC_Send_ServerParamsRsp
- *
- * @brief Call to send out a Server Parameters Response to a client request
- *
- * @param srcEP - Sending application's endpoint
- * @param dstAddr - where you want the message to go
- * @param pRsp - pointer to Startup Parameter Response data structure
- * @param cmdId - Command type ( Restore, Save or Reset)
- * @param disableDefaultRsp - disable default response
- * @param seqNum - ZCL sequence number
- *
- * @return ZStatus_t
- */
- ZStatus_t zclCC_Send_ServerParamsRsp( uint8 srcEP, afAddrType_t *dstAddr,
- zclCCServerParamsRsp_t *pRsp, uint8 cmdId,
- uint8 disableDefaultRsp, uint8 seqNum )
- {
- return zcl_SendCommand( srcEP, dstAddr, ZCL_CLUSTER_ID_GEN_COMMISSIONING,
- cmdId, TRUE, ZCL_FRAME_SERVER_CLIENT_DIR,
- disableDefaultRsp, 0, seqNum,
- CC_PACKET_LEN_SERVER_RSP, &(pRsp->status) );
- }
- /********************************************************************************************
- *********************************************************************************************/
|