123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949 |
- /**************************************************************************************************
- Filename: OTA_Dongle.c
- Revised: $Date: 2011-07-15 18:32:43 -0700 (Fri, 15 Jul 2011) $
- Revision: $Revision: 26809 $
- Description: Zigbee Cluster Library - sample device application.
- Copyright 2010-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.
- **************************************************************************************************/
- /*********************************************************************
- This device will be like a Light device. This application is not
- intended to be a Light device, but will use the device description
- to implement this sample code.
- *********************************************************************/
- /*********************************************************************
- * INCLUDES
- */
- #include "ZComDef.h"
- #include "OSAL.h"
- #include "AF.h"
- #include "ZDApp.h"
- #include "ZDProfile.h"
- #include "ZDObject.h"
- #include "AddrMgr.h"
- #include "zcl.h"
- #include "zcl_general.h"
- #include "zcl_ota.h"
- #include "OTA_Dongle.h"
- #include "ota_common.h"
- #include "onboard.h"
- /* HAL */
- #include "hal_lcd.h"
- #include "hal_led.h"
- #include "hal_key.h"
- #include "MT.h"
- #include "MT_APP.h"
- #include "MT_NWK.h"
- /*********************************************************************
- * MACROS
- */
- /*********************************************************************
- * CONSTANTS
- */
- /*********************************************************************
- * TYPEDEFS
- */
- /*********************************************************************
- * GLOBAL VARIABLES
- */
- uint8 OTA_Dongle_TaskID;
- uint8 OTA_Dongle_SeqNo;
- devStates_t OTA_Dongle_devState;
- /*********************************************************************
- * GLOBAL FUNCTIONS
- */
- /*********************************************************************
- * LOCAL VARIABLES
- */
- #define OTA_DONGLE_BINDINGLIST 2
- // Endpoint to allow SYS_APP_MSGs
- static endPointDesc_t ota_SysAppEp =
- {
- OTA_SYSAPP_ENDPOINT, // Sys App endpoint
- &OTA_Dongle_TaskID,
- (SimpleDescriptionFormat_t *) &OTA_Dongle_SimpleDesc,
- (afNetworkLatencyReq_t)0 // No Network Latency req
- };
- static endPointDesc_t ota_DongleEp =
- {
- OTA_DONGLE_ENDPOINT, // Sys App endpoint
- &zcl_TaskID,
- (SimpleDescriptionFormat_t*) &OTA_Dongle_SimpleDesc,
- (afNetworkLatencyReq_t)0 // No Network Latency req
- };
- /*********************************************************************
- * LOCAL FUNCTIONS
- */
- static void OTA_Dongle_HandleKeys( byte shift, byte keys );
- static void OTA_Dongle_BasicResetCB( void );
- static void OTA_Dongle_IdentifyCB( zclIdentify_t *pCmd );
- static void OTA_Dongle_IdentifyQueryRspCB( zclIdentifyQueryRsp_t *pRsp );
- static void OTA_Dongle_ProcessIdentifyTimeChange( void );
- static void OTA_ProcessZDOMsgs(zdoIncomingMsg_t * pMsg);
- static void OTA_ProcSysAppMsg(mtSysAppMsg_t *pMsg);
- static void OTA_ProcessSysApp_ImageNotifyReq(uint8 *pData);
- static void OTA_ProcessSysApp_ReadAttrReq(uint8 *pData);
- static void OTA_ProcessSysApp_DiscoveryReq(uint8 *pData);
- static void OTA_ProcessSysApp_JoinReq(uint8 *pData);
- static void OTA_Send_DeviceInd(uint16 shortAddr);
- static void OTA_Send_JoinInd(void);
- static void OTA_Send_ReadAttrInd(uint16 cluster, uint16 shortAddr, zclReadRspStatus_t *pAttr);
- static void OTA_Send_EndpointInd(uint16 addr, uint8 endpoint);
- static void OTA_Send_DongleInd(void);
- // Functions to process ZCL Foundation incoming Command/Response messages
- static void OTA_Dongle_ProcessIncomingMsg( zclIncomingMsg_t *msg );
- #ifdef ZCL_READ
- static uint8 OTA_Dongle_ProcessInReadRspCmd( zclIncomingMsg_t *pInMsg );
- #endif
- #ifdef ZCL_WRITE
- static uint8 OTA_Dongle_ProcessInWriteRspCmd( zclIncomingMsg_t *pInMsg );
- #endif
- static uint8 OTA_Dongle_ProcessInDefaultRspCmd( zclIncomingMsg_t *pInMsg );
- #ifdef ZCL_DISCOVER
- static uint8 OTA_Dongle_ProcessInDiscRspCmd( zclIncomingMsg_t *pInMsg );
- #endif
- /*********************************************************************
- * ZCL General Profile Callback table
- */
- static zclGeneral_AppCallbacks_t OTA_Dongle_CmdCallbacks =
- {
- OTA_Dongle_BasicResetCB, // Basic Cluster Reset command
- OTA_Dongle_IdentifyCB, // Identify command
- OTA_Dongle_IdentifyQueryRspCB, // Identify Query Response command
- NULL, // On/Off cluster command
- NULL, // Level Control Move to Level command
- NULL, // Level Control Move command
- NULL, // Level Control Step command
- NULL, // Group Response commands
- NULL, // Scene Store Request command
- NULL, // Scene Recall Request command
- NULL, // Scene Response command
- NULL, // Alarm (Response) command
- NULL, // RSSI Location commands
- NULL, // RSSI Location Response commands
- };
- /*********************************************************************
- * @fn OTA_Dongle_Init
- *
- * @brief Initialization function for the zclGeneral layer.
- *
- * @param none
- *
- * @return none
- */
- void OTA_Dongle_Init( byte task_id )
- {
- OTA_Dongle_TaskID = task_id;
- uint8 RxOnIdle = TRUE;
- OTA_Dongle_SeqNo = 0;
- ZMacSetReq( ZMacRxOnIdle, &RxOnIdle );
- // Register the ZCL General Cluster Library callback functions
- zclGeneral_RegisterCmdCallbacks( OTA_DONGLE_ENDPOINT, &OTA_Dongle_CmdCallbacks );
- // Register the application's attribute list
- zcl_registerAttrList( OTA_DONGLE_ENDPOINT, OTA_DONGLE_MAX_ATTRIBUTES, OTA_Dongle_Attrs );
- // Register the application's cluster option list
- zcl_registerClusterOptionList( OTA_DONGLE_ENDPOINT, OTA_DONGLE_MAX_OPTIONS, OTA_Dongle_Options );
- // Register the Application to receive the unprocessed Foundation command/response messages
- zcl_registerForMsg( OTA_Dongle_TaskID );
- // Register for all key events - This app will handle all key events
- RegisterForKeys( OTA_Dongle_TaskID );
- // Register endpoints
- afRegister( &ota_DongleEp );
- afRegister( &ota_SysAppEp );
- // Register with the ZDO to receive Match Descriptor Responses
- ZDO_RegisterForZDOMsg(task_id, Match_Desc_rsp);
- ZDO_RegisterForZDOMsg(task_id, Device_annce);
- // Start a timer to notify the console about the dongle
- osal_start_timerEx( OTA_Dongle_TaskID, OTA_DONGLE_DONGLE_NOTIFY_EVT, 4000 );
- }
- /*********************************************************************
- * @fn OTA_Dongle_event_loop
- *
- * @brief Event Loop Processor for zclGeneral.
- *
- * @param none
- *
- * @return none
- */
- uint16 OTA_Dongle_event_loop( uint8 task_id, uint16 events )
- {
- afIncomingMSGPacket_t *MSGpkt;
- (void)task_id; // Intentionally unreferenced parameter
- if ( events & SYS_EVENT_MSG )
- {
- while ( (MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( OTA_Dongle_TaskID )) )
- {
- switch ( MSGpkt->hdr.event )
- {
- case ZDO_CB_MSG:
- OTA_ProcessZDOMsgs( (zdoIncomingMsg_t *)MSGpkt );
- break;
- case MT_SYS_APP_MSG:
- case MT_SYS_APP_RSP_MSG:
- OTA_ProcSysAppMsg((mtSysAppMsg_t *)MSGpkt);
- break;
- case ZCL_INCOMING_MSG:
- // Incoming ZCL Foundation command/response messages
- OTA_Dongle_ProcessIncomingMsg( (zclIncomingMsg_t *)MSGpkt );
- break;
- case KEY_CHANGE:
- OTA_Dongle_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
- break;
- case ZDO_STATE_CHANGE:
- OTA_Dongle_devState = (devStates_t)(MSGpkt->hdr.status);
- if ((OTA_Dongle_devState == DEV_END_DEVICE) || (OTA_Dongle_devState == DEV_ROUTER) || (OTA_Dongle_devState == DEV_ZB_COORD))
- OTA_Send_JoinInd();
- break;
- default:
- break;
- }
- // Release the memory
- osal_msg_deallocate( (uint8 *)MSGpkt );
- }
- // return unprocessed events
- return (events ^ SYS_EVENT_MSG);
- }
- if ( events & OTA_DONGLE_DONGLE_NOTIFY_EVT )
- {
- OTA_Send_DongleInd();
- osal_start_timerEx( OTA_Dongle_TaskID, OTA_DONGLE_DONGLE_NOTIFY_EVT, 4000 );
- return ( events ^ OTA_DONGLE_DONGLE_NOTIFY_EVT );
- }
- if ( events & OTA_DONGLE_IDENTIFY_TIMEOUT_EVT )
- {
- if ( OTA_Dongle_IdentifyTime > 0 )
- {
- OTA_Dongle_IdentifyTime--;
- }
- OTA_Dongle_ProcessIdentifyTimeChange();
- return ( events ^ OTA_DONGLE_IDENTIFY_TIMEOUT_EVT );
- }
- // Discard unknown events
- return 0;
- }
- /*********************************************************************
- * @fn OTA_ProcessSysApp_ImageNotifyReq
- *
- * @brief Handles app messages from the console application.
- *
- * @param pData - The data from the server.
- *
- * @return none
- */
- void OTA_ProcessSysApp_ImageNotifyReq(uint8 *pData)
- {
- zclOTA_ImageNotifyParams_t imgNotifyParams;
- afAddrType_t dstAddr;
- // Setup the destination address
- dstAddr.addr.shortAddr = BUILD_UINT16(pData[0], pData[1]);
- dstAddr.endPoint = pData[2];
- dstAddr.addrMode = afAddr16Bit;
- dstAddr.panId = _NIB.nwkPanId;
- // Fill the Send Image Notify Parameters
- imgNotifyParams.payloadType = pData[3];
- imgNotifyParams.queryJitter = pData[4];
- imgNotifyParams.fileId.manufacturer = BUILD_UINT16(pData[5], pData[6]);
- imgNotifyParams.fileId.type = BUILD_UINT16(pData[7], pData[8]);
- imgNotifyParams.fileId.version = BUILD_UINT32(pData[9], pData[10], pData[11], pData[12]);
- // Send the command
- zclOTA_SendImageNotify(&dstAddr, &imgNotifyParams);
- }
- /*********************************************************************
- * @fn OTA_ProcessSysApp_ReadAttrReq
- *
- * @brief Handles app messages from the console application.
- *
- * @param pData - The data from the server.
- *
- * @return none
- */
- void OTA_ProcessSysApp_ReadAttrReq(uint8 *pData)
- {
- uint8 readCmd[sizeof(zclReadCmd_t) + sizeof(uint16) * OTA_APP_MAX_ATTRIBUTES];
- zclReadCmd_t *pReadCmd = (zclReadCmd_t*) readCmd;
- afAddrType_t dstAddr;
- uint16 cluster;
- int8 i;
- // Setup the destination address
- dstAddr.addr.shortAddr = BUILD_UINT16(pData[0], pData[1]);
- dstAddr.endPoint = pData[2];
- dstAddr.addrMode = afAddr16Bit;
- dstAddr.panId = _NIB.nwkPanId;
- // Fill the Send Image Notify Parameters
- cluster = BUILD_UINT16(pData[3], pData[4]);
- pReadCmd->numAttr = pData[5];
- if (pReadCmd->numAttr > OTA_APP_MAX_ATTRIBUTES)
- pReadCmd->numAttr = OTA_APP_MAX_ATTRIBUTES;
- pData += 6;
- for (i=0; i<pReadCmd->numAttr; i++)
- {
- pReadCmd->attrID[i] = BUILD_UINT16(pData[i*2], pData[i*2+1]);
- }
- // Send the command
- zcl_SendRead(OTA_DONGLE_ENDPOINT, &dstAddr, cluster, pReadCmd,
- ZCL_FRAME_SERVER_CLIENT_DIR, TRUE, OTA_Dongle_SeqNo++);
- }
- /*********************************************************************
- * @fn OTA_ProcessSysApp_DiscoveryReq
- *
- * @brief Handles app messages from the console application.
- *
- * @param pData - The data from the server.
- *
- * @return none
- */
- void OTA_ProcessSysApp_DiscoveryReq(uint8 *pData)
- {
- cId_t otaCluster = ZCL_CLUSTER_ID_OTA;
- zAddrType_t dstAddr;
- // Send out a match for the key establishment
- dstAddr.addrMode = AddrBroadcast;
- dstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR;
- ZDP_MatchDescReq( &dstAddr, NWK_BROADCAST_SHORTADDR, ZCL_OTA_SAMPLE_PROFILE_ID,
- 0, NULL, 1, &otaCluster, FALSE );
- }
- /*********************************************************************
- * @fn OTA_ProcessSysApp_JoinReq
- *
- * @brief Handles app messages from the console application.
- *
- * @param pData - The data from the server.
- *
- * @return none
- */
- void OTA_ProcessSysApp_JoinReq(uint8 *pData)
- {
- // Setup Z-Stack global configuration
- zgConfigPANID = BUILD_UINT16(pData[0], pData[1]);
- zgDefaultChannelList = 0x00000800;
- zgDefaultChannelList <<= (pData[2] - 11);
- zgDefaultStartingScanDuration = 0;
- // Make sure all NWK layer callbacks go to the stack
- _nwkCallbackSub = 0;
- // Start the stack. This will join the PAN specified above
- ZDOInitDevice(0);
- }
- /*********************************************************************
- * @fn OTA_Send_DeviceInd
- *
- * @brief Notifies the console about the existance of a device on the network.
- *
- * @param none.
- *
- * @return none
- */
- void OTA_Send_DeviceInd(uint16 shortAddr)
- {
- uint8 buffer[OTA_APP_DEVICE_IND_LEN];
- uint8 *pBuf = buffer;
- uint16 pan = _NIB.nwkPanId;
- *pBuf++ = OTA_SYSAPP_ENDPOINT;
- *pBuf++ = OTA_APP_DEVICE_IND;
- *pBuf++ = LO_UINT16(pan);
- *pBuf++ = HI_UINT16(pan);
- *pBuf++ = LO_UINT16(shortAddr);
- *pBuf++ = HI_UINT16(shortAddr);
- // Send the indication
- MT_BuildAndSendZToolResponse(MT_RPC_SYS_APP, MT_APP_MSG, OTA_APP_DEVICE_IND_LEN, buffer);
- }
- /*********************************************************************
- * @fn OTA_Send_ReadAttrInd
- *
- * @brief Notifies the console about attribute values for a device.
- *
- * @param none.
- *
- * @return none
- */
- void OTA_Send_ReadAttrInd(uint16 cluster, uint16 shortAddr, zclReadRspStatus_t *pAttr)
- {
- uint8 buffer[OTA_APP_READ_ATTRIBUTE_IND_LEN];
- uint8 *pBuf = buffer;
- uint8 len;
- *pBuf++ = OTA_SYSAPP_ENDPOINT;
- *pBuf++ = OTA_APP_READ_ATTRIBUTE_IND;
- *pBuf++ = LO_UINT16(_NIB.nwkPanId);
- *pBuf++ = HI_UINT16(_NIB.nwkPanId);
- *pBuf++ = LO_UINT16(cluster);
- *pBuf++ = HI_UINT16(cluster);
- *pBuf++ = LO_UINT16(shortAddr);
- *pBuf++ = HI_UINT16(shortAddr);
- *pBuf++ = LO_UINT16(pAttr->attrID);
- *pBuf++ = HI_UINT16(pAttr->attrID);
- *pBuf++ = pAttr->status;
- *pBuf++ = pAttr->dataType;
- len = zclGetDataTypeLength(pAttr->dataType);
- // We should not be reading attributes greater than 8 bytes in length
- if (len <= 8)
- {
- *pBuf++ = len;
- if (len)
- {
- uint8 *pStr;
- switch ( pAttr->dataType )
- {
- case ZCL_DATATYPE_UINT8:
- *pBuf = *((uint8 *)pAttr->data);
- break;
- case ZCL_DATATYPE_UINT16:
- *pBuf++ = LO_UINT16( *((uint16*)pAttr->data) );
- *pBuf++ = HI_UINT16( *((uint16*)pAttr->data) );
- break;
- case ZCL_DATATYPE_UINT32:
- pBuf = osal_buffer_uint32( pBuf, *((uint32*)pAttr->data) );
- break;
- case ZCL_DATATYPE_IEEE_ADDR:
- pStr = (uint8*)pAttr->data;
- osal_memcpy( pBuf, pStr, 8 );
- break;
- default:
- break;
- }
- }
- }
- else
- *pBuf = 0;
- // Send the indication
- MT_BuildAndSendZToolResponse(MT_RPC_SYS_APP, MT_APP_MSG, OTA_APP_READ_ATTRIBUTE_IND_LEN, buffer);
- }
- /*********************************************************************
- * @fn OTA_ProcessSysApp_JoinReq
- *
- * @brief Notifies the console that the dognle has joined a network.
- *
- * @param none.
- *
- * @return none
- */
- void OTA_Send_JoinInd()
- {
- uint8 buffer[OTA_APP_JOIN_IND_LEN];
- uint8 *pBuf = buffer;
- uint16 pan = _NIB.nwkPanId;
- *pBuf++ = OTA_SYSAPP_ENDPOINT;
- *pBuf++ = OTA_APP_JOIN_IND;
- *pBuf++ = LO_UINT16(pan);
- *pBuf = HI_UINT16(pan);
- // Send the indication
- MT_BuildAndSendZToolResponse(MT_RPC_SYS_APP, MT_APP_MSG, OTA_APP_JOIN_IND_LEN, buffer);
- }
- /*********************************************************************
- * @fn OTA_ProcessSysApp_JoinReq
- *
- * @brief Notifies the console about the OTA endpoint on a device.
- *
- * @param none.
- *
- * @return none
- */
- void OTA_Send_EndpointInd(uint16 addr, uint8 endpoint)
- {
- uint8 buffer[OTA_APP_ENDPOINT_IND_LEN];
- uint8 *pBuf = buffer;
- *pBuf++ = OTA_SYSAPP_ENDPOINT;
- *pBuf++ = OTA_APP_ENDPOINT_IND;
- *pBuf++ = LO_UINT16(_NIB.nwkPanId);
- *pBuf++ = HI_UINT16(_NIB.nwkPanId);
- *pBuf++ = LO_UINT16(addr);
- *pBuf++ = HI_UINT16(addr);
- *pBuf = endpoint;
- // Send the indication
- MT_BuildAndSendZToolResponse(MT_RPC_SYS_APP, MT_APP_MSG, OTA_APP_ENDPOINT_IND_LEN, buffer);
- }
- /*********************************************************************
- * @fn OTA_Send_DongleInd
- *
- * @brief Notifies the console about the Dongle.
- *
- * @param none.
- *
- * @return none
- */
- void OTA_Send_DongleInd()
- {
- uint8 buffer[128];
- uint8 *pBuf = buffer;
- *pBuf++ = OTA_SYSAPP_ENDPOINT;
- *pBuf++ = OTA_APP_DONGLE_IND;
- *pBuf++ = zgDeviceLogicalType;
- *pBuf++ = LO_UINT16(_NIB.nwkPanId);
- *pBuf++ = HI_UINT16(_NIB.nwkPanId);
- *pBuf++ = LO_UINT16(_NIB.nwkDevAddress);
- *pBuf++ = HI_UINT16(_NIB.nwkDevAddress);
- *pBuf++ = ZCL_OTA_ENDPOINT;
- *pBuf++ = _NIB.nwkLogicalChannel;
- *pBuf = OTA_Dongle_devState;
- // Send the indication
- MT_BuildAndSendZToolResponse(MT_RPC_SYS_APP, MT_APP_MSG, pBuf - buffer, buffer);
- }
- /*********************************************************************
- * @fn OTA_ProcSysAppMsg
- *
- * @brief Handles sys app messages from the server application.
- *
- * @param pMsg - The message from the server.
- *
- * @return none
- */
- void OTA_ProcSysAppMsg(mtSysAppMsg_t *pMsg)
- {
- uint8 cmd;
- if (pMsg == NULL)
- return;
- cmd = *pMsg->appData++;
- switch(cmd)
- {
- case OTA_APP_READ_ATTRIBUTE_REQ:
- OTA_ProcessSysApp_ReadAttrReq(pMsg->appData);
- break;
- case OTA_APP_IMAGE_NOTIFY_REQ:
- OTA_ProcessSysApp_ImageNotifyReq(pMsg->appData);
- break;
- case OTA_APP_DISCOVERY_REQ:
- OTA_ProcessSysApp_DiscoveryReq(pMsg->appData);
- break;
- case OTA_APP_JOIN_REQ:
- OTA_ProcessSysApp_JoinReq(pMsg->appData);
- break;
- case OTA_APP_LEAVE_REQ:
- // Simulate a leave by rebooting the dongle
- SystemReset();
- default:
- break;
- }
- }
- /*********************************************************************
- * @fn OTA_ProcessZDOMsgs
- *
- * @brief Process messages from the ZDO layer.
- *
- * @param pMsg - The message from the server.
- *
- * @return none
- */
- void OTA_ProcessZDOMsgs(zdoIncomingMsg_t * pMsg)
- {
- if (pMsg)
- {
- if (pMsg->clusterID == Match_Desc_rsp)
- {
- ZDO_ActiveEndpointRsp_t *pRsp = ZDO_ParseEPListRsp( pMsg );
- if (pRsp)
- {
- // Notify the console application of the client device's OTA endpoint
- if (pRsp->cnt)
- OTA_Send_EndpointInd(pRsp->nwkAddr, pRsp->epList[0]);
- osal_mem_free(pRsp);
- }
- }
- else if (pMsg->clusterID == Device_annce)
- {
- cId_t otaCluster = ZCL_CLUSTER_ID_OTA;
- zAddrType_t dstAddr;
- ZDO_DeviceAnnce_t devAnnce;
- ZDO_ParseDeviceAnnce(pMsg, &devAnnce);
- OTA_Send_DeviceInd(devAnnce.nwkAddr);
- // Send out a match for the OTA cluster ID
- dstAddr.addrMode = Addr16Bit;
- dstAddr.addr.shortAddr = devAnnce.nwkAddr;
- ZDP_MatchDescReq( &dstAddr, devAnnce.nwkAddr, ZCL_OTA_SAMPLE_PROFILE_ID,
- 0, NULL, 1, &otaCluster, FALSE );
- }
- }
- }
- /*********************************************************************
- * @fn OTA_Dongle_HandleKeys
- *
- * @brief Handles all key events for this device.
- *
- * @param shift - true if in shift/alt.
- * @param keys - bit field for key events. Valid entries:
- * HAL_KEY_SW_4
- * HAL_KEY_SW_3
- * HAL_KEY_SW_2
- * HAL_KEY_SW_1
- *
- * @return none
- */
- static void OTA_Dongle_HandleKeys( byte shift, byte keys )
- {
- (void)shift; // Intentionally unreferenced parameter
- if ( keys & HAL_KEY_SW_1 )
- {
- ZDOInitDevice(0);
- }
- if ( keys & HAL_KEY_SW_2 )
- {
- }
- if ( keys & HAL_KEY_SW_3 )
- {
- }
- if ( keys & HAL_KEY_SW_4 )
- {
- }
- }
- /*********************************************************************
- * @fn OTA_Dongle_ProcessIdentifyTimeChange
- *
- * @brief Called to process any change to the IdentifyTime attribute.
- *
- * @param none
- *
- * @return none
- */
- static void OTA_Dongle_ProcessIdentifyTimeChange( void )
- {
- if ( OTA_Dongle_IdentifyTime > 0 )
- {
- osal_start_timerEx( OTA_Dongle_TaskID, OTA_DONGLE_IDENTIFY_TIMEOUT_EVT, 1000 );
- HalLedBlink ( HAL_LED_4, 0xFF, HAL_LED_DEFAULT_DUTY_CYCLE, HAL_LED_DEFAULT_FLASH_TIME );
- }
- else
- {
- osal_stop_timerEx( OTA_Dongle_TaskID, OTA_DONGLE_IDENTIFY_TIMEOUT_EVT );
- }
- }
- /*********************************************************************
- * @fn OTA_Dongle_BasicResetCB
- *
- * @brief Callback from the ZCL General Cluster Library
- * to set all the Basic Cluster attributes to default values.
- *
- * @param none
- *
- * @return none
- */
- static void OTA_Dongle_BasicResetCB( void )
- {
- // Reset all attributes to default values
- }
- /*********************************************************************
- * @fn OTA_Dongle_IdentifyCB
- *
- * @brief Callback from the ZCL General Cluster Library when
- * it received an Identity Command for this application.
- *
- * @param srcAddr - source address and endpoint of the response message
- * @param identifyTime - the number of seconds to identify yourself
- *
- * @return none
- */
- static void OTA_Dongle_IdentifyCB( zclIdentify_t *pCmd )
- {
- OTA_Dongle_IdentifyTime = pCmd->identifyTime;
- OTA_Dongle_ProcessIdentifyTimeChange();
- }
- /*********************************************************************
- * @fn OTA_Dongle_IdentifyQueryRspCB
- *
- * @brief Callback from the ZCL General Cluster Library when
- * it received an Identity Query Response Command for this application.
- *
- * @param srcAddr - requestor's address
- * @param timeout - number of seconds to identify yourself (valid for query response)
- *
- * @return none
- */
- static void OTA_Dongle_IdentifyQueryRspCB( zclIdentifyQueryRsp_t *pRsp )
- {
- // Query Response (with timeout value)
- (void)pRsp;
- }
- /******************************************************************************
- *
- * Functions for processing ZCL Foundation incoming Command/Response messages
- *
- *****************************************************************************/
- /*********************************************************************
- * @fn OTA_Dongle_ProcessIncomingMsg
- *
- * @brief Process ZCL Foundation incoming message
- *
- * @param pInMsg - pointer to the received message
- *
- * @return none
- */
- static void OTA_Dongle_ProcessIncomingMsg( zclIncomingMsg_t *pInMsg)
- {
- switch ( pInMsg->zclHdr.commandID )
- {
- #ifdef ZCL_READ
- case ZCL_CMD_READ_RSP:
- OTA_Dongle_ProcessInReadRspCmd( pInMsg );
- break;
- #endif
- #ifdef ZCL_WRITE
- case ZCL_CMD_WRITE_RSP:
- OTA_Dongle_ProcessInWriteRspCmd( pInMsg );
- break;
- #endif
- case ZCL_CMD_DEFAULT_RSP:
- OTA_Dongle_ProcessInDefaultRspCmd( pInMsg );
- break;
- #ifdef ZCL_DISCOVER
- case ZCL_CMD_DISCOVER_RSP:
- OTA_Dongle_ProcessInDiscRspCmd( pInMsg );
- break;
- #endif
- default:
- break;
- }
- if ( pInMsg->attrCmd )
- osal_mem_free( pInMsg->attrCmd );
- }
- #ifdef ZCL_READ
- /*********************************************************************
- * @fn OTA_Dongle_ProcessInReadRspCmd
- *
- * @brief Process the "Profile" Read Response Command
- *
- * @param pInMsg - incoming message to process
- *
- * @return none
- */
- static uint8 OTA_Dongle_ProcessInReadRspCmd( zclIncomingMsg_t *pInMsg )
- {
- zclReadRspCmd_t *readRspCmd;
- uint8 i;
- readRspCmd = (zclReadRspCmd_t *)pInMsg->attrCmd;
- for (i = 0; i < readRspCmd->numAttr; i++)
- {
- OTA_Send_ReadAttrInd(pInMsg->clusterId, pInMsg->srcAddr.addr.shortAddr, &readRspCmd->attrList[i]);
- }
- return TRUE;
- }
- #endif // ZCL_READ
- #ifdef ZCL_WRITE
- /*********************************************************************
- * @fn OTA_Dongle_ProcessInWriteRspCmd
- *
- * @brief Process the "Profile" Write Response Command
- *
- * @param pInMsg - incoming message to process
- *
- * @return none
- */
- static uint8 OTA_Dongle_ProcessInWriteRspCmd( zclIncomingMsg_t *pInMsg )
- {
- zclWriteRspCmd_t *writeRspCmd;
- uint8 i;
- writeRspCmd = (zclWriteRspCmd_t *)pInMsg->attrCmd;
- for (i = 0; i < writeRspCmd->numAttr; i++)
- {
- // Notify the device of the results of the its original write attributes
- // command.
- }
- return TRUE;
- }
- #endif // ZCL_WRITE
- /*********************************************************************
- * @fn OTA_Dongle_ProcessInDefaultRspCmd
- *
- * @brief Process the "Profile" Default Response Command
- *
- * @param pInMsg - incoming message to process
- *
- * @return none
- */
- static uint8 OTA_Dongle_ProcessInDefaultRspCmd( zclIncomingMsg_t *pInMsg )
- {
- // zclDefaultRspCmd_t *defaultRspCmd = (zclDefaultRspCmd_t *)pInMsg->attrCmd;
- // Device is notified of the Default Response command.
- (void)pInMsg;
- return TRUE;
- }
- #ifdef ZCL_DISCOVER
- /*********************************************************************
- * @fn OTA_Dongle_ProcessInDiscRspCmd
- *
- * @brief Process the "Profile" Discover Response Command
- *
- * @param pInMsg - incoming message to process
- *
- * @return none
- */
- static uint8 OTA_Dongle_ProcessInDiscRspCmd( zclIncomingMsg_t *pInMsg )
- {
- zclDiscoverRspCmd_t *discoverRspCmd;
- uint8 i;
- discoverRspCmd = (zclDiscoverRspCmd_t *)pInMsg->attrCmd;
- for ( i = 0; i < discoverRspCmd->numAttr; i++ )
- {
- // Device is notified of the result of its attribute discovery command.
- }
- return TRUE;
- }
- #endif // ZCL_DISCOVER
- /****************************************************************************
- ****************************************************************************/
|