rangeext.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. /**************************************************************************************************
  2. Filename: rangeext.c
  3. Revised: $Date: 2012-04-02 17:02:19 -0700 (Mon, 02 Apr 2012) $
  4. Revision: $Revision: 29996 $
  5. Description: This module implements the Range Extender functionality and
  6. contains the init and event loop functions
  7. Copyright 2009-2011 Texas Instruments Incorporated. All rights reserved.
  8. IMPORTANT: Your use of this Software is limited to those specific rights
  9. granted under the terms of a software license agreement between the user
  10. who downloaded the software, his/her employer (which must be your employer)
  11. and Texas Instruments Incorporated (the "License"). You may not use this
  12. Software unless you agree to abide by the terms of the License. The License
  13. limits your use, and you acknowledge, that the Software may not be modified,
  14. copied or distributed unless embedded on a Texas Instruments microcontroller
  15. or used solely and exclusively in conjunction with a Texas Instruments radio
  16. frequency transceiver, which is integrated into your product. Other than for
  17. the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  18. works of, modify, distribute, perform, display or sell this Software and/or
  19. its documentation for any purpose.
  20. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  21. PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  22. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  23. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  24. TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  25. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  26. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  27. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  28. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  29. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  30. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  31. Should you have any questions regarding your right to use this Software,
  32. contact Texas Instruments Incorporated at www.TI.com.
  33. **************************************************************************************************/
  34. /*********************************************************************
  35. This application is designed for the test purpose of the SE profile which
  36. exploits the following clusters for a Range Extender configuration:
  37. General Basic
  38. General Alarms
  39. General Time
  40. General Key Establishment
  41. Key control:
  42. SW1: Join Network
  43. SW2: Not Used
  44. SW3: Not Used
  45. SW4: Not Used
  46. *********************************************************************/
  47. /*********************************************************************
  48. * INCLUDES
  49. */
  50. #include "OSAL.h"
  51. #include "OSAL_Clock.h"
  52. #include "ZDApp.h"
  53. #include "ZDObject.h"
  54. #include "AddrMgr.h"
  55. #include "se.h"
  56. #include "rangeext.h"
  57. #include "zcl_general.h"
  58. #include "zcl_key_establish.h"
  59. #include "onboard.h"
  60. /* HAL */
  61. #include "hal_lcd.h"
  62. #include "hal_led.h"
  63. #include "hal_key.h"
  64. /*********************************************************************
  65. * MACROS
  66. */
  67. // There is no attribute in the Mandatory Reportable Attribute list for now
  68. #define zcl_MandatoryReportableAttribute( a ) ( a == NULL )
  69. /*********************************************************************
  70. * CONSTANTS
  71. */
  72. #define rangeExtNwkState devState
  73. /*********************************************************************
  74. * TYPEDEFS
  75. */
  76. /*********************************************************************
  77. * GLOBAL VARIABLES
  78. */
  79. /*********************************************************************
  80. * GLOBAL FUNCTIONS
  81. */
  82. /*********************************************************************
  83. * LOCAL VARIABLES
  84. */
  85. static uint8 rangeExtTaskID; // osal task id for range ext device
  86. static uint8 rangeExtTransID; // transaction id
  87. static afAddrType_t ESPAddr; // ESP destination address
  88. #if SECURE
  89. static uint8 linkKeyStatus; // status variable from get link key function
  90. #endif
  91. /*********************************************************************
  92. * LOCAL FUNCTIONS
  93. */
  94. static void rangeext_HandleKeys( uint8 shift, uint8 keys );
  95. #if SECURE
  96. static uint8 rangeext_KeyEstablish_ReturnLinkKey( uint16 shortAddr );
  97. #endif
  98. static void rangeext_ProcessIdentifyTimeChange( void );
  99. /*************************************************************************/
  100. /*** Application Callback Functions ***/
  101. /*************************************************************************/
  102. // Foundation Callback functions
  103. static uint8 rangeext_ValidateAttrDataCB( zclAttrRec_t *pAttr, zclWriteRec_t *pAttrInfo );
  104. // General Cluster Callback functions
  105. static void rangeext_BasicResetCB( void );
  106. static void rangeext_IdentifyCB( zclIdentify_t *pCmd );
  107. static void rangeext_IdentifyQueryRspCB( zclIdentifyQueryRsp_t *pRsp );
  108. static void rangeext_AlarmCB( zclAlarm_t *pAlarm );
  109. #ifdef SE_UK_EXT
  110. static void rangeext_GetEventLogCB( uint8 srcEP, afAddrType_t *srcAddr,
  111. zclGetEventLog_t *pEventLog, uint8 seqNum );
  112. static void rangeext_PublishEventLogCB( afAddrType_t *srcAddr, zclPublishEventLog_t *pEventLog );
  113. #endif // SE_UK_EXT
  114. // Function to process ZDO callback messages
  115. static void rangeext_ProcessZDOMsgs( zdoIncomingMsg_t *pMsg );
  116. /************************************************************************/
  117. /*** Functions to process ZCL Foundation ***/
  118. /*** incoming Command/Response messages ***/
  119. /************************************************************************/
  120. static void rangeext_ProcessZCLMsg( zclIncomingMsg_t *msg );
  121. #if defined ( ZCL_READ )
  122. static uint8 rangeext_ProcessInReadRspCmd( zclIncomingMsg_t *pInMsg );
  123. #endif // ZCL_READ
  124. #if defined ( ZCL_WRITE )
  125. static uint8 rangeext_ProcessInWriteRspCmd( zclIncomingMsg_t *pInMsg );
  126. #endif // ZCL_WRITE
  127. static uint8 rangeext_ProcessInDefaultRspCmd( zclIncomingMsg_t *pInMsg );
  128. #if defined ( ZCL_DISCOVER )
  129. static uint8 rangeext_ProcessInDiscRspCmd( zclIncomingMsg_t *pInMsg );
  130. #endif // ZCL_DISCOVER
  131. /*********************************************************************
  132. * ZCL General Clusters Callback table
  133. */
  134. static zclGeneral_AppCallbacks_t rangeext_GenCmdCallbacks =
  135. {
  136. rangeext_BasicResetCB, // Basic Cluster Reset command
  137. rangeext_IdentifyCB, // Identify command
  138. rangeext_IdentifyQueryRspCB, // Identify Query Response command
  139. NULL, // On/Off cluster commands
  140. NULL, // Level Control Move to Level command
  141. NULL, // Level Control Move command
  142. NULL, // Level Control Step command
  143. NULL, // Level Control Stop command
  144. NULL, // Group Response commands
  145. NULL, // Scene Store Request command
  146. NULL, // Scene Recall Request command
  147. NULL, // Scene Response command
  148. rangeext_AlarmCB, // Alarm (Response) command
  149. #ifdef SE_UK_EXT
  150. rangeext_GetEventLogCB, // Get Event Log command
  151. rangeext_PublishEventLogCB, // Publish Event Log command
  152. #endif
  153. NULL, // RSSI Location command
  154. NULL, // RSSI Location Response command
  155. };
  156. /*********************************************************************
  157. * @fn rangeext_Init
  158. *
  159. * @brief Initialization function for the ZCL App Application.
  160. *
  161. * @param uint8 task_id - range extender task id
  162. *
  163. * @return none
  164. */
  165. void rangeext_Init( uint8 task_id )
  166. {
  167. rangeExtTaskID = task_id;
  168. // setup ESP destination address
  169. ESPAddr.addrMode = (afAddrMode_t)Addr16Bit;
  170. ESPAddr.endPoint = RANGEEXT_ENDPOINT;
  171. ESPAddr.addr.shortAddr = 0;
  172. // register SE endpoint
  173. zclSE_Init( &rangeExtSimpleDesc );
  174. // Register the ZCL General Cluster Library callback functions
  175. zclGeneral_RegisterCmdCallbacks( RANGEEXT_ENDPOINT, &rangeext_GenCmdCallbacks );
  176. // Register the application's attribute list
  177. zcl_registerAttrList( RANGEEXT_ENDPOINT, RANGEEXT_MAX_ATTRIBUTES, rangeExtAttrs );
  178. // Register the application's cluster option list
  179. zcl_registerClusterOptionList( RANGEEXT_ENDPOINT, RANGEEXT_MAX_OPTIONS, rangeExtOptions );
  180. // Register the application's attribute data validation callback function
  181. zcl_registerValidateAttrData( rangeext_ValidateAttrDataCB );
  182. // Register the Application to receive the unprocessed Foundation command/response messages
  183. zcl_registerForMsg( rangeExtTaskID );
  184. // Register for all key events - This app will handle all key events
  185. RegisterForKeys( rangeExtTaskID );
  186. // Register with the ZDO to receive Match Descriptor Responses
  187. ZDO_RegisterForZDOMsg(task_id, Match_Desc_rsp);
  188. }
  189. /*********************************************************************
  190. * @fn rangeext_event_loop
  191. *
  192. * @brief Event Loop Processor for rangeext.
  193. *
  194. * @param uint8 task_id - the osal task id
  195. * @param uint16 events - the event bitmask
  196. *
  197. * @return none
  198. */
  199. uint16 rangeext_event_loop( uint8 task_id, uint16 events )
  200. {
  201. afIncomingMSGPacket_t *MSGpkt;
  202. if ( events & SYS_EVENT_MSG )
  203. {
  204. while ( (MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( rangeExtTaskID )) )
  205. {
  206. switch ( MSGpkt->hdr.event )
  207. {
  208. case ZDO_CB_MSG:
  209. rangeext_ProcessZDOMsgs( (zdoIncomingMsg_t *)MSGpkt );
  210. break;
  211. case ZCL_INCOMING_MSG:
  212. // Incoming ZCL foundation command/response messages
  213. rangeext_ProcessZCLMsg( (zclIncomingMsg_t *)MSGpkt );
  214. break;
  215. case KEY_CHANGE:
  216. rangeext_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
  217. break;
  218. case ZDO_STATE_CHANGE:
  219. if (DEV_ROUTER == (devStates_t)(MSGpkt->hdr.status))
  220. {
  221. #if SECURE
  222. {
  223. // check to see if link key had already been established
  224. linkKeyStatus = rangeext_KeyEstablish_ReturnLinkKey(ESPAddr.addr.shortAddr);
  225. if (linkKeyStatus != ZSuccess)
  226. {
  227. cId_t cbkeCluster = ZCL_CLUSTER_ID_GEN_KEY_ESTABLISHMENT;
  228. zAddrType_t dstAddr;
  229. // Send out a match for the key establishment
  230. dstAddr.addrMode = AddrBroadcast;
  231. dstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR;
  232. ZDP_MatchDescReq( &dstAddr, NWK_BROADCAST_SHORTADDR, ZCL_SE_PROFILE_ID,
  233. 1, &cbkeCluster, 0, NULL, FALSE );
  234. }
  235. }
  236. #endif
  237. }
  238. break;
  239. #if defined( ZCL_KEY_ESTABLISH )
  240. case ZCL_KEY_ESTABLISH_IND:
  241. if ((MSGpkt->hdr.status) == TermKeyStatus_Success)
  242. {
  243. ESPAddr.endPoint = RANGEEXT_ENDPOINT; // set destination endpoint back to application endpoint
  244. }
  245. break;
  246. #endif
  247. default:
  248. break;
  249. }
  250. // Release the memory
  251. osal_msg_deallocate( (uint8 *)MSGpkt );
  252. }
  253. // return unprocessed events
  254. return (events ^ SYS_EVENT_MSG);
  255. }
  256. // event to intiate key establishment request
  257. if ( events & RANGEEXT_KEY_ESTABLISHMENT_REQUEST_EVT )
  258. {
  259. zclGeneral_KeyEstablish_InitiateKeyEstablishment(rangeExtTaskID, &ESPAddr, rangeExtTransID);
  260. return ( events ^ RANGEEXT_KEY_ESTABLISHMENT_REQUEST_EVT );
  261. }
  262. // handle processing of identify timeout event triggered by an identify command
  263. if ( events & RANGEEXT_IDENTIFY_TIMEOUT_EVT )
  264. {
  265. if ( rangeExtIdentifyTime > 0 )
  266. {
  267. rangeExtIdentifyTime--;
  268. }
  269. rangeext_ProcessIdentifyTimeChange();
  270. return ( events ^ RANGEEXT_IDENTIFY_TIMEOUT_EVT );
  271. }
  272. // Discard unknown events
  273. return 0;
  274. }
  275. /*********************************************************************
  276. * @fn rangeext_ProcessZDOMsgs
  277. *
  278. * @brief Called to process callbacks from the ZDO.
  279. *
  280. * @param none
  281. *
  282. * @return none
  283. */
  284. static void rangeext_ProcessZDOMsgs( zdoIncomingMsg_t *pMsg )
  285. {
  286. if (pMsg->clusterID == Match_Desc_rsp)
  287. {
  288. ZDO_ActiveEndpointRsp_t *pRsp = ZDO_ParseEPListRsp( pMsg );
  289. if (pRsp)
  290. {
  291. if (pRsp->cnt)
  292. {
  293. // Record the trust center
  294. ESPAddr.endPoint = pRsp->epList[0];
  295. ESPAddr.addr.shortAddr = pMsg->srcAddr.addr.shortAddr;
  296. // send out key establishment request
  297. osal_set_event( rangeExtTaskID, RANGEEXT_KEY_ESTABLISHMENT_REQUEST_EVT);
  298. }
  299. osal_mem_free(pRsp);
  300. }
  301. }
  302. }
  303. /*********************************************************************
  304. * @fn rangeext_ProcessIdentifyTimeChange
  305. *
  306. * @brief Called to blink led for specified IdentifyTime attribute value
  307. *
  308. * @param none
  309. *
  310. * @return none
  311. */
  312. static void rangeext_ProcessIdentifyTimeChange( void )
  313. {
  314. if ( rangeExtIdentifyTime > 0 )
  315. {
  316. osal_start_timerEx( rangeExtTaskID, RANGEEXT_IDENTIFY_TIMEOUT_EVT, 1000 );
  317. HalLedBlink ( HAL_LED_4, 0xFF, HAL_LED_DEFAULT_DUTY_CYCLE, HAL_LED_DEFAULT_FLASH_TIME );
  318. }
  319. else
  320. {
  321. HalLedSet ( HAL_LED_4, HAL_LED_MODE_OFF );
  322. osal_stop_timerEx( rangeExtTaskID, RANGEEXT_IDENTIFY_TIMEOUT_EVT );
  323. }
  324. }
  325. #if SECURE
  326. /*********************************************************************
  327. * @fn rangeext_KeyEstablish_ReturnLinkKey
  328. *
  329. * @brief This function get the requested link key
  330. *
  331. * @param shortAddr - short address of the partner.
  332. *
  333. * @return none
  334. */
  335. static uint8 rangeext_KeyEstablish_ReturnLinkKey( uint16 shortAddr )
  336. {
  337. uint8 status = ZFailure;
  338. AddrMgrEntry_t entry;
  339. // Look up the long address of the device
  340. entry.user = ADDRMGR_USER_DEFAULT;
  341. entry.nwkAddr = shortAddr;
  342. if ( AddrMgrEntryLookupNwk( &entry ) )
  343. {
  344. // check if APS link key has been established
  345. if ( APSME_IsLinkKeyValid( entry.extAddr ) == TRUE )
  346. {
  347. status = ZSuccess;
  348. }
  349. }
  350. else
  351. {
  352. // It's an unknown device
  353. status = ZInvalidParameter;
  354. }
  355. return status;
  356. }
  357. #endif
  358. /*********************************************************************
  359. * @fn rangeext_HandleKeys
  360. *
  361. * @brief Handles all key events for this device.
  362. *
  363. * @param shift - true if in shift/alt.
  364. * @param keys - bit field for key events. Valid entries:
  365. * HAL_KEY_SW_4
  366. * HAL_KEY_SW_3
  367. * HAL_KEY_SW_2
  368. * HAL_KEY_SW_1
  369. *
  370. * @return none
  371. */
  372. static void rangeext_HandleKeys( uint8 shift, uint8 keys )
  373. {
  374. // Shift is used to make each button/switch dual purpose.
  375. if ( shift )
  376. {
  377. if ( keys & HAL_KEY_SW_1 )
  378. {
  379. }
  380. if ( keys & HAL_KEY_SW_2 )
  381. {
  382. }
  383. if ( keys & HAL_KEY_SW_3 )
  384. {
  385. }
  386. if ( keys & HAL_KEY_SW_4 )
  387. {
  388. }
  389. }
  390. else
  391. {
  392. if ( keys & HAL_KEY_SW_1 )
  393. {
  394. ZDOInitDevice(0); // join the network
  395. }
  396. if ( keys & HAL_KEY_SW_2 )
  397. {
  398. }
  399. if ( keys & HAL_KEY_SW_3 )
  400. {
  401. }
  402. if ( keys & HAL_KEY_SW_4 )
  403. {
  404. }
  405. }
  406. }
  407. /*********************************************************************
  408. * @fn rangeext_ValidateAttrDataCB
  409. *
  410. * @brief Check to see if the supplied value for the attribute data
  411. * is within the specified range of the attribute.
  412. *
  413. * @param pAttr - pointer to attribute
  414. * @param pAttrInfo - pointer to attribute info
  415. *
  416. * @return TRUE if data valid. FALSE otherwise.
  417. */
  418. static uint8 rangeext_ValidateAttrDataCB( zclAttrRec_t *pAttr, zclWriteRec_t *pAttrInfo )
  419. {
  420. uint8 valid = TRUE;
  421. switch ( pAttrInfo->dataType )
  422. {
  423. case ZCL_DATATYPE_BOOLEAN:
  424. if ( ( *(pAttrInfo->attrData) != 0 ) && ( *(pAttrInfo->attrData) != 1 ) )
  425. valid = FALSE;
  426. break;
  427. default:
  428. break;
  429. }
  430. return ( valid );
  431. }
  432. /*********************************************************************
  433. * @fn rangeext_BasicResetCB
  434. *
  435. * @brief Callback from the ZCL General Cluster Library to set all
  436. * the attributes of all the clusters to their factory defaults
  437. *
  438. * @param none
  439. *
  440. * @return none
  441. */
  442. static void rangeext_BasicResetCB( void )
  443. {
  444. // user should handle setting attributes to factory defaults here
  445. }
  446. /*********************************************************************
  447. * @fn rangeext_IdentifyCB
  448. *
  449. * @brief Callback from the ZCL General Cluster Library when
  450. * it received an Identity Command for this application.
  451. *
  452. * @param pCmd - pointer to structure for Identify command
  453. *
  454. * @return none
  455. */
  456. static void rangeext_IdentifyCB( zclIdentify_t *pCmd )
  457. {
  458. rangeExtIdentifyTime = pCmd->identifyTime;
  459. rangeext_ProcessIdentifyTimeChange();
  460. }
  461. /*********************************************************************
  462. * @fn rangeext_IdentifyQueryRspCB
  463. *
  464. * @brief Callback from the ZCL General Cluster Library when
  465. * it received an Identity Query Response Command for this application.
  466. *
  467. * @param pRsp - pointer to structure for Identity Query Response command
  468. *
  469. * @return none
  470. */
  471. static void rangeext_IdentifyQueryRspCB( zclIdentifyQueryRsp_t *pRsp )
  472. {
  473. // add user code here
  474. }
  475. /*********************************************************************
  476. * @fn rangeext_AlarmCB
  477. *
  478. * @brief Callback from the ZCL General Cluster Library when
  479. * it received an Alarm request or response command for
  480. * this application.
  481. *
  482. * @param pAlarm - pointer to structure for Alarm command
  483. *
  484. * @return none
  485. */
  486. static void rangeext_AlarmCB( zclAlarm_t *pAlarm )
  487. {
  488. // add user code here
  489. }
  490. #ifdef SE_UK_EXT
  491. /*********************************************************************
  492. * @fn rangeext_GetEventLogCB
  493. *
  494. * @brief Callback from the ZCL General Cluster Library when
  495. * it received a Get Event Log command for this
  496. * application.
  497. *
  498. * @param srcEP - source endpoint
  499. * @param srcAddr - pointer to source address
  500. * @param pEventLog - pointer to structure for Get Event Log command
  501. * @param seqNum - sequence number of this command
  502. *
  503. * @return none
  504. */
  505. static void rangeext_GetEventLogCB( uint8 srcEP, afAddrType_t *srcAddr,
  506. zclGetEventLog_t *pEventLog, uint8 seqNum )
  507. {
  508. // add user code here, which could fragment the event log payload if
  509. // the entire payload doesn't fit into one Publish Event Log Command.
  510. // Note: the Command Index starts at 0 and is incremented for each
  511. // fragment belonging to the same command.
  512. // There's no event log for now! The Metering Device will support
  513. // logging for all events configured to do so.
  514. }
  515. /*********************************************************************
  516. * @fn rangeext_PublishEventLogCB
  517. *
  518. * @brief Callback from the ZCL General Cluster Library when
  519. * it received a Publish Event Log command for this
  520. * application.
  521. *
  522. * @param srcAddr - pointer to source address
  523. * @param pEventLog - pointer to structure for Publish Event Log command
  524. *
  525. * @return none
  526. */
  527. static void rangeext_PublishEventLogCB( afAddrType_t *srcAddr, zclPublishEventLog_t *pEventLog )
  528. {
  529. // add user code here
  530. }
  531. #endif // SE_UK_EXT
  532. /******************************************************************************
  533. *
  534. * Functions for processing ZCL Foundation incoming Command/Response messages
  535. *
  536. *****************************************************************************/
  537. /*********************************************************************
  538. * @fn rangeext_ProcessZCLMsg
  539. *
  540. * @brief Process ZCL Foundation incoming message
  541. *
  542. * @param pInMsg - message to process
  543. *
  544. * @return none
  545. */
  546. static void rangeext_ProcessZCLMsg( zclIncomingMsg_t *pInMsg )
  547. {
  548. switch ( pInMsg->zclHdr.commandID )
  549. {
  550. #if defined ( ZCL_READ )
  551. case ZCL_CMD_READ_RSP:
  552. rangeext_ProcessInReadRspCmd( pInMsg );
  553. break;
  554. #endif // ZCL_READ
  555. #if defined ( ZCL_WRITE )
  556. case ZCL_CMD_WRITE_RSP:
  557. rangeext_ProcessInWriteRspCmd( pInMsg );
  558. break;
  559. #endif // ZCL_WRITE
  560. case ZCL_CMD_DEFAULT_RSP:
  561. rangeext_ProcessInDefaultRspCmd( pInMsg );
  562. break;
  563. #if defined ( ZCL_DISCOVER )
  564. case ZCL_CMD_DISCOVER_RSP:
  565. rangeext_ProcessInDiscRspCmd( pInMsg );
  566. break;
  567. #endif // ZCL_DISCOVER
  568. default:
  569. break;
  570. }
  571. if ( pInMsg->attrCmd != NULL )
  572. {
  573. // free the parsed command
  574. osal_mem_free( pInMsg->attrCmd );
  575. pInMsg->attrCmd = NULL;
  576. }
  577. }
  578. #if defined ( ZCL_READ )
  579. /*********************************************************************
  580. * @fn rangeext_ProcessInReadRspCmd
  581. *
  582. * @brief Process the "Profile" Read Response Command
  583. *
  584. * @param pInMsg - incoming message to process
  585. *
  586. * @return none
  587. */
  588. static uint8 rangeext_ProcessInReadRspCmd( zclIncomingMsg_t *pInMsg )
  589. {
  590. zclReadRspCmd_t *readRspCmd;
  591. uint8 i;
  592. readRspCmd = (zclReadRspCmd_t *)pInMsg->attrCmd;
  593. for (i = 0; i < readRspCmd->numAttr; i++)
  594. {
  595. // Notify the originator of the results of the original read attributes
  596. // attempt and, for each successfull request, the value of the requested
  597. // attribute
  598. }
  599. return TRUE;
  600. }
  601. #endif // ZCL_READ
  602. #if defined ( ZCL_WRITE )
  603. /*********************************************************************
  604. * @fn rangeext_ProcessInWriteRspCmd
  605. *
  606. * @brief Process the "Profile" Write Response Command
  607. *
  608. * @param pInMsg - incoming message to process
  609. *
  610. * @return none
  611. */
  612. static uint8 rangeext_ProcessInWriteRspCmd( zclIncomingMsg_t *pInMsg )
  613. {
  614. zclWriteRspCmd_t *writeRspCmd;
  615. uint8 i;
  616. writeRspCmd = (zclWriteRspCmd_t *)pInMsg->attrCmd;
  617. for (i = 0; i < writeRspCmd->numAttr; i++)
  618. {
  619. // Notify the device of the results of the its original write attributes
  620. // command.
  621. }
  622. return TRUE;
  623. }
  624. #endif // ZCL_WRITE
  625. /*********************************************************************
  626. * @fn rangeext_ProcessInDefaultRspCmd
  627. *
  628. * @brief Process the "Profile" Default Response Command
  629. *
  630. * @param pInMsg - incoming message to process
  631. *
  632. * @return none
  633. */
  634. static uint8 rangeext_ProcessInDefaultRspCmd( zclIncomingMsg_t *pInMsg )
  635. {
  636. // zclDefaultRspCmd_t *defaultRspCmd = (zclDefaultRspCmd_t *)pInMsg->attrCmd;
  637. // Device is notified of the Default Response command.
  638. return TRUE;
  639. }
  640. #if defined ( ZCL_DISCOVER )
  641. /*********************************************************************
  642. * @fn rangeext_ProcessInDiscRspCmd
  643. *
  644. * @brief Process the "Profile" Discover Response Command
  645. *
  646. * @param pInMsg - incoming message to process
  647. *
  648. * @return none
  649. */
  650. static uint8 rangeext_ProcessInDiscRspCmd( zclIncomingMsg_t *pInMsg )
  651. {
  652. zclDiscoverRspCmd_t *discoverRspCmd;
  653. uint8 i;
  654. discoverRspCmd = (zclDiscoverRspCmd_t *)pInMsg->attrCmd;
  655. for ( i = 0; i < discoverRspCmd->numAttr; i++ )
  656. {
  657. // Device is notified of the result of its attribute discovery command.
  658. }
  659. return TRUE;
  660. }
  661. #endif // ZCL_DISCOVER
  662. /****************************************************************************
  663. ****************************************************************************/