zcl_closures.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /**************************************************************************************************
  2. Filename: zcl_closures.c
  3. Revised: $Date: 2007-07-31 09:16:11 -0700 (Tue, 31 Jul 2007) $
  4. Revision: $Revision: 14985 $
  5. Description: Zigbee Cluster Library - Closures.
  6. Copyright 2006-2007 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_closures.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 zclClosuresCBRec
  54. {
  55. struct zclClosuresCBRec *next;
  56. uint8 endpoint; // Used to link it into the endpoint descriptor
  57. zclClosures_AppCallbacks_t *CBs; // Pointer to Callback function
  58. } zclClosuresCBRec_t;
  59. /*********************************************************************
  60. * GLOBAL VARIABLES
  61. */
  62. /*********************************************************************
  63. * GLOBAL FUNCTIONS
  64. */
  65. /*********************************************************************
  66. * LOCAL VARIABLES
  67. */
  68. static zclClosuresCBRec_t *zclClosuresCBs = (zclClosuresCBRec_t *)NULL;
  69. static uint8 zclClosuresPluginRegisted = FALSE;
  70. /*********************************************************************
  71. * LOCAL FUNCTIONS
  72. */
  73. static ZStatus_t zclClosures_HdlIncoming( zclIncoming_t *pInMsg );
  74. static ZStatus_t zclClosures_HdlInSpecificCommands( zclIncoming_t *pInMsg );
  75. static zclClosures_AppCallbacks_t *zclClosures_FindCallbacks( uint8 endpoint );
  76. static ZStatus_t zclClosures_ProcessInClosuresCmds( zclIncoming_t *pInMsg );
  77. /*********************************************************************
  78. * @fn zclClosures_RegisterCmdCallbacks
  79. *
  80. * @brief Register an applications command callbacks
  81. *
  82. * @param endpoint - application's endpoint
  83. * @param callbacks - pointer to the callback record.
  84. *
  85. * @return ZMemError if not able to allocate
  86. */
  87. ZStatus_t zclClosures_RegisterCmdCallbacks( uint8 endpoint, zclClosures_AppCallbacks_t *callbacks )
  88. {
  89. zclClosuresCBRec_t *pNewItem;
  90. zclClosuresCBRec_t *pLoop;
  91. // Register as a ZCL Plugin
  92. if ( !zclClosuresPluginRegisted )
  93. {
  94. zcl_registerPlugin( ZCL_CLOSURES_LOGICAL_CLUSTER_ID_SHADE_CONFIG,
  95. ZCL_CLOSURES_LOGICAL_CLUSTER_ID_SHADE_CONFIG,
  96. zclClosures_HdlIncoming );
  97. zclClosuresPluginRegisted = TRUE;
  98. }
  99. // Fill in the new profile list
  100. pNewItem = osal_mem_alloc( sizeof( zclClosuresCBRec_t ) );
  101. if ( pNewItem == NULL )
  102. return (ZMemError);
  103. pNewItem->next = (zclClosuresCBRec_t *)NULL;
  104. pNewItem->endpoint = endpoint;
  105. pNewItem->CBs = callbacks;
  106. // Find spot in list
  107. if ( zclClosuresCBs == NULL )
  108. {
  109. zclClosuresCBs = pNewItem;
  110. }
  111. else
  112. {
  113. // Look for end of list
  114. pLoop = zclClosuresCBs;
  115. while ( pLoop->next != NULL )
  116. pLoop = pLoop->next;
  117. // Put new item at end of list
  118. pLoop->next = pNewItem;
  119. }
  120. return ( ZSuccess );
  121. }
  122. /*********************************************************************
  123. * @fn zclClosures_FindCallbacks
  124. *
  125. * @brief Find the callbacks for an endpoint
  126. *
  127. * @param endpoint
  128. *
  129. * @return pointer to the callbacks
  130. */
  131. static zclClosures_AppCallbacks_t *zclClosures_FindCallbacks( uint8 endpoint )
  132. {
  133. zclClosuresCBRec_t *pCBs;
  134. pCBs = zclClosuresCBs;
  135. while ( pCBs )
  136. {
  137. if ( pCBs->endpoint == endpoint )
  138. return ( pCBs->CBs );
  139. pCBs = pCBs->next;
  140. }
  141. return ( (zclClosures_AppCallbacks_t *)NULL );
  142. }
  143. /*********************************************************************
  144. * @fn zclClosures_HdlIncoming
  145. *
  146. * @brief Callback from ZCL to process incoming Commands specific
  147. * to this cluster library or Profile commands for attributes
  148. * that aren't in the attribute list
  149. *
  150. * @param pInMsg - pointer to the incoming message
  151. * @param logicalClusterID
  152. *
  153. * @return ZStatus_t
  154. */
  155. static ZStatus_t zclClosures_HdlIncoming( zclIncoming_t *pInMsg )
  156. {
  157. ZStatus_t stat = ZSuccess;
  158. #if defined ( INTER_PAN )
  159. if ( StubAPS_InterPan( pInMsg->msg->srcAddr.panId, pInMsg->msg->srcAddr.endPoint ) )
  160. return ( stat ); // Cluster not supported thru Inter-PAN
  161. #endif
  162. if ( zcl_ClusterCmd( pInMsg->hdr.fc.type ) )
  163. {
  164. // Is this a manufacturer specific command?
  165. if ( pInMsg->hdr.fc.manuSpecific == 0 )
  166. {
  167. stat = zclClosures_HdlInSpecificCommands( pInMsg );
  168. }
  169. else
  170. {
  171. // We don't support any manufacturer specific command.
  172. stat = ZFailure;
  173. }
  174. }
  175. else
  176. {
  177. // Handle all the normal (Read, Write...) commands -- should never get here
  178. stat = ZFailure;
  179. }
  180. return ( stat );
  181. }
  182. /*********************************************************************
  183. * @fn zclClosures_HdlInSpecificCommands
  184. *
  185. * @brief Callback from ZCL to process incoming Commands specific
  186. * to this cluster library
  187. * @param pInMsg - pointer to the incoming message
  188. *
  189. * @return ZStatus_t
  190. */
  191. static ZStatus_t zclClosures_HdlInSpecificCommands( zclIncoming_t *pInMsg )
  192. {
  193. ZStatus_t stat;
  194. zclClosures_AppCallbacks_t *pCBs;
  195. // make sure endpoint exists
  196. pCBs = zclClosures_FindCallbacks( pInMsg->msg->endPoint );
  197. if ( pCBs == NULL )
  198. return ( ZFailure );
  199. switch ( pInMsg->msg->clusterId )
  200. {
  201. case ZCL_CLOSURES_LOGICAL_CLUSTER_ID_SHADE_CONFIG:
  202. stat = zclClosures_ProcessInClosuresCmds( pInMsg );
  203. break;
  204. default:
  205. stat = ZFailure;
  206. break;
  207. }
  208. return ( stat );
  209. }
  210. /*********************************************************************
  211. * @fn zclSS_ProcessInClosuresCmds
  212. *
  213. * @brief Callback from ZCL to process incoming Commands specific
  214. * to this cluster library on a command ID basis
  215. * @param pInMsg - pointer to the incoming message
  216. *
  217. * @return ZStatus_t
  218. */
  219. static ZStatus_t zclClosures_ProcessInClosuresCmds( zclIncoming_t *pInMsg )
  220. {
  221. ZStatus_t stat = ZFailure;
  222. // there are no specific command for this cluster yet.
  223. // instead of suppressing a compiler warnings( for a code porting reasons )
  224. // fake unused call here and keep the code skeleton intact
  225. (void)pInMsg;
  226. if ( stat != ZFailure )
  227. zclClosures_FindCallbacks( 0 );
  228. return ( stat );
  229. }
  230. /********************************************************************************************
  231. *********************************************************************************************/