zcl_ms.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. /**************************************************************************************************
  2. Filename: zcl_ms.c
  3. Revised: $Date: 2010-02-09 15:28:14 -0800 (Tue, 09 Feb 2010) $
  4. Revision: $Revision: 21679 $
  5. Description: Zigbee Cluster Library - Measurements and Sensing ( MS )
  6. Copyright 2006-2010 Texas Instruments Incorporated. All rights reserved.
  7. IMPORTANT: Your use of this Software is limited to those specific rights
  8. granted under the terms of a software license agreement between the user
  9. who downloaded the software, his/her employer (which must be your employer)
  10. and Texas Instruments Incorporated (the "License"). You may not use this
  11. Software unless you agree to abide by the terms of the License. The License
  12. limits your use, and you acknowledge, that the Software may not be modified,
  13. copied or distributed unless embedded on a Texas Instruments microcontroller
  14. or used solely and exclusively in conjunction with a Texas Instruments radio
  15. frequency transceiver, which is integrated into your product. Other than for
  16. the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  17. works of, modify, distribute, perform, display or sell this Software and/or
  18. its documentation for any purpose.
  19. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  20. PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  21. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  22. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  23. TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  24. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  25. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  26. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  27. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  28. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  29. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  30. Should you have any questions regarding your right to use this Software,
  31. contact Texas Instruments Incorporated at www.TI.com.
  32. **************************************************************************************************/
  33. /*********************************************************************
  34. * INCLUDES
  35. */
  36. #include "ZComDef.h"
  37. #include "OSAL.h"
  38. #include "zcl.h"
  39. #include "zcl_general.h"
  40. #include "zcl_ms.h"
  41. #if defined ( INTER_PAN )
  42. #include "stub_aps.h"
  43. #endif
  44. /*********************************************************************
  45. * MACROS
  46. */
  47. /*********************************************************************
  48. * CONSTANTS
  49. */
  50. /*********************************************************************
  51. * TYPEDEFS
  52. */
  53. typedef struct zclMSCBRec
  54. {
  55. struct zclMSCBRec *next;
  56. uint8 endpoint; // Used to link it into the endpoint descriptor
  57. zclMS_AppCallbacks_t *CBs; // Pointer to Callback function
  58. } zclMSCBRec_t;
  59. /*********************************************************************
  60. * GLOBAL VARIABLES
  61. */
  62. /*********************************************************************
  63. * GLOBAL FUNCTIONS
  64. */
  65. /*********************************************************************
  66. * LOCAL VARIABLES
  67. */
  68. static zclMSCBRec_t *zclMSCBs = (zclMSCBRec_t *)NULL;
  69. static uint8 zclMSPluginRegisted = FALSE;
  70. /*********************************************************************
  71. * LOCAL FUNCTIONS
  72. */
  73. static ZStatus_t zclMS_HdlIncoming( zclIncoming_t *pInMsg );
  74. static ZStatus_t zclMS_HdlInSpecificCommands( zclIncoming_t *pInMsg );
  75. static zclMS_AppCallbacks_t *zclMS_FindCallbacks( uint8 endpoint );
  76. static ZStatus_t zclMS_ProcessIn_IlluminanceMeasurementCmds( zclIncoming_t *pInMsg );
  77. static ZStatus_t zclMS_ProcessIn_IlluminanceLevelSensingCmds( zclIncoming_t *pInMsg );
  78. static ZStatus_t zclMS_ProcessIn_TemperatureMeasurementCmds( zclIncoming_t *pInMsg );
  79. static ZStatus_t zclMS_ProcessIn_PressureMeasurementCmds( zclIncoming_t *pInMsg );
  80. static ZStatus_t zclMS_ProcessIn_FlowMeasurementCmds( zclIncoming_t *pInMsg );
  81. static ZStatus_t zclMS_ProcessIn_RelativeHumidityCmds( zclIncoming_t *pInMsg );
  82. static ZStatus_t zclMS_ProcessIn_OccupancySensingCmds( zclIncoming_t *pInMsg );
  83. /*********************************************************************
  84. * @fn zclMS_RegisterCmdCallbacks
  85. *
  86. * @brief Register an applications command callbacks
  87. *
  88. * @param endpoint - application's endpoint
  89. * @param callbacks - pointer to the callback record.
  90. *
  91. * @return ZMemError if not able to allocate
  92. */
  93. ZStatus_t zclMS_RegisterCmdCallbacks( uint8 endpoint, zclMS_AppCallbacks_t *callbacks )
  94. {
  95. zclMSCBRec_t *pNewItem;
  96. zclMSCBRec_t *pLoop;
  97. // Register as a ZCL Plugin
  98. if ( !zclMSPluginRegisted )
  99. {
  100. zcl_registerPlugin( ZCL_CLUSTER_ID_MS_ILLUMINANCE_MEASUREMENT,
  101. ZCL_CLUSTER_ID_MS_OCCUPANCY_SENSING,
  102. zclMS_HdlIncoming );
  103. zclMSPluginRegisted = TRUE;
  104. }
  105. // Fill in the new profile list
  106. pNewItem = osal_mem_alloc( sizeof( zclMSCBRec_t ) );
  107. if ( pNewItem == NULL )
  108. return (ZMemError);
  109. pNewItem->next = (zclMSCBRec_t *)NULL;
  110. pNewItem->endpoint = endpoint;
  111. pNewItem->CBs = callbacks;
  112. // Find spot in list
  113. if ( zclMSCBs == NULL )
  114. {
  115. zclMSCBs = pNewItem;
  116. }
  117. else
  118. {
  119. // Look for end of list
  120. pLoop = zclMSCBs;
  121. while ( pLoop->next != NULL )
  122. pLoop = pLoop->next;
  123. // Put new item at end of list
  124. pLoop->next = pNewItem;
  125. }
  126. return ( ZSuccess );
  127. }
  128. /*********************************************************************
  129. * @fn zclMS_FindCallbacks
  130. *
  131. * @brief Find the callbacks for an endpoint
  132. *
  133. * @param endpoint
  134. *
  135. * @return pointer to the callbacks
  136. */
  137. static zclMS_AppCallbacks_t *zclMS_FindCallbacks( uint8 endpoint )
  138. {
  139. zclMSCBRec_t *pCBs;
  140. pCBs = zclMSCBs;
  141. while ( pCBs )
  142. {
  143. if ( pCBs->endpoint == endpoint )
  144. return ( pCBs->CBs );
  145. pCBs = pCBs->next;
  146. }
  147. return ( (zclMS_AppCallbacks_t *)NULL );
  148. }
  149. /*********************************************************************
  150. * @fn zclMS_HdlIncoming
  151. *
  152. * @brief Callback from ZCL to process incoming Commands specific
  153. * to this cluster library or Profile commands for attributes
  154. * that aren't in the attribute list
  155. *
  156. * @param pInMsg - pointer to the incoming message
  157. * @param logicalClusterID
  158. *
  159. * @return ZStatus_t
  160. */
  161. static ZStatus_t zclMS_HdlIncoming( zclIncoming_t *pInMsg )
  162. {
  163. ZStatus_t stat = ZSuccess;
  164. #if defined ( INTER_PAN )
  165. if ( StubAPS_InterPan( pInMsg->msg->srcAddr.panId, pInMsg->msg->srcAddr.endPoint ) )
  166. return ( stat ); // Cluster not supported thru Inter-PAN
  167. #endif
  168. if ( zcl_ClusterCmd( pInMsg->hdr.fc.type ) )
  169. {
  170. // Is this a manufacturer specific command?
  171. if ( pInMsg->hdr.fc.manuSpecific == 0 )
  172. {
  173. stat = zclMS_HdlInSpecificCommands( pInMsg );
  174. }
  175. else
  176. {
  177. // We don't support any manufacturer specific command -- ignore it.
  178. stat = ZFailure;
  179. }
  180. }
  181. else
  182. {
  183. // Handle all the normal (Read, Write...) commands
  184. stat = ZFailure;
  185. }
  186. return ( stat );
  187. }
  188. /*********************************************************************
  189. * @fn zclMS_HdlInSpecificCommands
  190. *
  191. * @brief Callback from ZCL to process incoming Commands specific
  192. * to this cluster library
  193. *
  194. * @param pInMsg - pointer to the incoming message
  195. *
  196. * @return ZStatus_t
  197. */
  198. static ZStatus_t zclMS_HdlInSpecificCommands( zclIncoming_t *pInMsg )
  199. {
  200. ZStatus_t stat = ZSuccess;
  201. zclMS_AppCallbacks_t *pCBs;
  202. // make sure endpoint exists
  203. pCBs = (void*)zclMS_FindCallbacks( pInMsg->msg->endPoint );
  204. if ( pCBs == NULL )
  205. return ( ZFailure );
  206. switch ( pInMsg->msg->clusterId )
  207. {
  208. case ZCL_CLUSTER_ID_MS_ILLUMINANCE_MEASUREMENT:
  209. stat = zclMS_ProcessIn_IlluminanceMeasurementCmds( pInMsg );
  210. break;
  211. case ZCL_CLUSTER_ID_MS_ILLUMINANCE_LEVEL_SENSING_CONFIG:
  212. stat = zclMS_ProcessIn_IlluminanceLevelSensingCmds( pInMsg );
  213. break;
  214. case ZCL_CLUSTER_ID_MS_TEMPERATURE_MEASUREMENT:
  215. stat = zclMS_ProcessIn_TemperatureMeasurementCmds( pInMsg );
  216. break;
  217. case ZCL_CLUSTER_ID_MS_PRESSURE_MEASUREMENT:
  218. stat = zclMS_ProcessIn_PressureMeasurementCmds( pInMsg );
  219. break;
  220. case ZCL_CLUSTER_ID_MS_FLOW_MEASUREMENT:
  221. stat = zclMS_ProcessIn_FlowMeasurementCmds( pInMsg );
  222. break;
  223. case ZCL_CLUSTER_ID_MS_RELATIVE_HUMIDITY:
  224. stat = zclMS_ProcessIn_RelativeHumidityCmds( pInMsg );
  225. break;
  226. case ZCL_CLUSTER_ID_MS_OCCUPANCY_SENSING:
  227. stat = zclMS_ProcessIn_OccupancySensingCmds( pInMsg );
  228. break;
  229. default:
  230. stat = ZFailure;
  231. break;
  232. }
  233. return ( stat );
  234. }
  235. /*********************************************************************
  236. * @fn zclMS_ProcessIn_IlluminanceMeasurementCmds
  237. *
  238. * @brief Callback from ZCL to process incoming Commands specific
  239. * to this cluster library on a command ID basis
  240. *
  241. * @param pInMsg - pointer to the incoming message
  242. *
  243. * @return ZStatus_t
  244. */
  245. static ZStatus_t zclMS_ProcessIn_IlluminanceMeasurementCmds( zclIncoming_t *pInMsg )
  246. {
  247. ZStatus_t stat = ZFailure;
  248. // there are no specific command for this cluster yet.
  249. // instead of suppressing a compiler warnings( for a code porting reasons )
  250. // fake unused call here and keep the code skeleton intact
  251. (void)pInMsg;
  252. if ( stat != ZFailure )
  253. zclMS_FindCallbacks( 0 );
  254. return ( stat );
  255. }
  256. /*********************************************************************
  257. * @fn zclMS_ProcessIn_IlluminanceLevelSensingCmds
  258. *
  259. * @brief Callback from ZCL to process incoming Commands specific
  260. * to this cluster library on a command ID basis
  261. *
  262. * @param pInMsg - pointer to the incoming message
  263. *
  264. * @return ZStatus_t
  265. */
  266. static ZStatus_t zclMS_ProcessIn_IlluminanceLevelSensingCmds( zclIncoming_t *pInMsg )
  267. {
  268. ZStatus_t stat = ZSuccess;
  269. uint8 cmdID;
  270. cmdID = pInMsg->hdr.commandID;
  271. switch ( cmdID )
  272. {
  273. default:
  274. stat = ZFailure;
  275. break;
  276. }
  277. return ( stat );
  278. }
  279. /*********************************************************************
  280. * @fn zclMS_ProcessIn_TemperatureMeasurementCmds
  281. *
  282. * @brief Callback from ZCL to process incoming Commands specific
  283. * to this cluster library on a command ID basis
  284. *
  285. * @param pInMsg - pointer to the incoming message
  286. *
  287. * @return ZStatus_t
  288. */
  289. static ZStatus_t zclMS_ProcessIn_TemperatureMeasurementCmds( zclIncoming_t *pInMsg )
  290. {
  291. ZStatus_t stat = ZSuccess;
  292. uint8 cmdID;
  293. cmdID = pInMsg->hdr.commandID;
  294. switch ( cmdID )
  295. {
  296. default:
  297. stat = ZFailure;
  298. break;
  299. }
  300. return ( stat );
  301. }
  302. /*********************************************************************
  303. * @fn zclMS_ProcessIn_PressureMeasurementCmds
  304. *
  305. * @brief Callback from ZCL to process incoming Commands specific
  306. * to this cluster library on a command ID basis
  307. *
  308. * @param pInMsg - pointer to the incoming message
  309. *
  310. * @return ZStatus_t
  311. */
  312. static ZStatus_t zclMS_ProcessIn_PressureMeasurementCmds( zclIncoming_t *pInMsg )
  313. {
  314. ZStatus_t stat = ZSuccess;
  315. uint8 cmdID;
  316. cmdID = pInMsg->hdr.commandID;
  317. switch ( cmdID )
  318. {
  319. default:
  320. stat = ZFailure;
  321. break;
  322. }
  323. return ( stat );
  324. }
  325. /*********************************************************************
  326. * @fn zclMS_ProcessIn_FlowMeasurementCmds
  327. *
  328. * @brief Callback from ZCL to process incoming Commands specific
  329. * to this cluster library on a command ID basis
  330. *
  331. * @param pInMsg - pointer to the incoming message
  332. *
  333. * @return ZStatus_t
  334. */
  335. static ZStatus_t zclMS_ProcessIn_FlowMeasurementCmds( zclIncoming_t *pInMsg )
  336. {
  337. ZStatus_t stat = ZSuccess;
  338. uint8 cmdID;
  339. cmdID = pInMsg->hdr.commandID;
  340. switch ( cmdID )
  341. {
  342. default:
  343. stat = ZFailure;
  344. break;
  345. }
  346. return ( stat );
  347. }
  348. /*********************************************************************
  349. * @fn zclMS_ProcessIn_RelativeHumidityCmds
  350. *
  351. * @brief Callback from ZCL to process incoming Commands specific
  352. * to this cluster library on a command ID basis
  353. *
  354. * @param pInMsg - pointer to the incoming message
  355. *
  356. * @return ZStatus_t
  357. */
  358. static ZStatus_t zclMS_ProcessIn_RelativeHumidityCmds( zclIncoming_t *pInMsg )
  359. {
  360. ZStatus_t stat = ZSuccess;
  361. uint8 cmdID;
  362. cmdID = pInMsg->hdr.commandID;
  363. switch ( cmdID )
  364. {
  365. default:
  366. stat = ZFailure;
  367. break;
  368. }
  369. return ( stat );
  370. }
  371. /*********************************************************************
  372. * @fn zclMS_ProcessIn_OccupancySensingCmds
  373. *
  374. * @brief Callback from ZCL to process incoming Commands specific
  375. * to this cluster library on a command ID basis
  376. *
  377. * @param pInMsg - pointer to the incoming message
  378. *
  379. * @return ZStatus_t
  380. */
  381. static ZStatus_t zclMS_ProcessIn_OccupancySensingCmds( zclIncoming_t *pInMsg )
  382. {
  383. ZStatus_t stat = ZSuccess;
  384. uint8 cmdID;
  385. cmdID = pInMsg->hdr.commandID;
  386. switch ( cmdID )
  387. {
  388. default:
  389. stat = ZFailure;
  390. break;
  391. }
  392. return ( stat );
  393. }
  394. /****************************************************************************
  395. ****************************************************************************/