BindingTable.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /**************************************************************************************************
  2. Filename: BindingTable.h
  3. Revised: $Date: 2007-10-28 18:41:49 -0700 (Sun, 28 Oct 2007) $
  4. Revision: $Revision: 15799 $
  5. Description: Device binding table.
  6. Copyright 2004-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. #ifndef BINDINGTABLE_H
  34. #define BINDINGTABLE_H
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. /*********************************************************************
  39. * INCLUDES
  40. */
  41. #include "ZComdef.h"
  42. #include "osal.h"
  43. #include "nwk.h"
  44. #include "AssocList.h"
  45. /*********************************************************************
  46. * MACROS
  47. */
  48. /*********************************************************************
  49. * CONSTANTS
  50. */
  51. #define MAX_DEVICE_PAIRS 255 // temp value
  52. #define DSTGROUPMODE_ADDR 0
  53. #define DSTGROUPMODE_GROUP 1
  54. /*********************************************************************
  55. * TYPEDEFS
  56. */
  57. typedef struct
  58. {
  59. uint16 numRecs;
  60. } nvBindingHdr_t;
  61. // Don't use sizeof( BindingEntry_t ) use gBIND_REC_SIZE when calculating
  62. // the size of each binding table entry. gBIND_REC_SIZE is defined in nwk_global.c.
  63. typedef struct
  64. {
  65. // No src address since the src is always the local device
  66. uint8 srcEP;
  67. uint8 dstGroupMode; // Destination address type; 0 - Normal address index, 1 - Group address
  68. uint16 dstIdx; // This field is used in both modes (group and non-group) to save NV and RAM space
  69. // dstGroupMode = 0 - Address Manager index
  70. // dstGroupMode = 1 - Group Address
  71. uint8 dstEP;
  72. uint8 numClusterIds;
  73. uint16 clusterIdList[MAX_BINDING_CLUSTER_IDS];
  74. // Don't use MAX_BINDING_CLUSTERS_ID when
  75. // using the clusterIdList field. Use
  76. // gMAX_BINDING_CLUSTER_IDS
  77. } BindingEntry_t;
  78. /*********************************************************************
  79. * GLOBAL VARIABLES
  80. */
  81. // BindingTable is defined in nwk_globals.c and NWK_MAX_BINDING_ENTRIES
  82. // is defined in f8wConfig.cfg. Don't use NWK_MAX_BINDING_ENTRIES as the
  83. // number of records - use gNWK_MAX_BINDING_ENTRIES.
  84. extern BindingEntry_t BindingTable[];
  85. /*********************************************************************
  86. * FUNCTIONS
  87. */
  88. /*
  89. * This function is used to initialise the binding table
  90. */
  91. extern void InitBindingTable( void );
  92. /*
  93. * Removes a binding table entry.
  94. */
  95. extern byte bindRemoveEntry( BindingEntry_t *pBind );
  96. /*
  97. * Is the clusterID in the clusterID list?
  98. */
  99. extern byte bindIsClusterIDinList( BindingEntry_t *entry, uint16 clusterId );
  100. /*
  101. * Removes a ClusterID from a list of ClusterIDs.
  102. */
  103. extern byte bindRemoveClusterIdFromList( BindingEntry_t *entry, uint16 clusterId );
  104. /*
  105. * Adds a ClusterID to a list of ClusterIDs.
  106. */
  107. extern byte bindAddClusterIdToList( BindingEntry_t *entry, uint16 clusterId );
  108. /*
  109. * Finds an existing src/epint to dst/epint bind record
  110. */
  111. extern BindingEntry_t *bindFindExisting( byte srcEpInt,
  112. zAddrType_t *dstShortAddr, byte dstEpInt );
  113. /*
  114. * Remove binds(s) associated to Source address, endpoint and cluster.
  115. */
  116. extern void nwk_remove_bindSrc( zAddrType_t *srcAddr, byte epInt,
  117. byte numClusterIds, uint16 *clusterIds );
  118. /*
  119. * Remove bind(s) associated to a address (source or destination)
  120. */
  121. extern void bindRemoveDev( zAddrType_t *shortAddr);
  122. /*
  123. * Remove bind(s) associated to a address (source)
  124. */
  125. extern void bindRemoveSrcDev( uint8 ep );
  126. /*
  127. * Calculate the number items this device is bound to.
  128. */
  129. extern byte bindNumBoundTo( zAddrType_t *devAddr, byte devEpInt, byte srcMode );
  130. /*
  131. * Count the number of reflections.
  132. */
  133. extern uint16 bindNumReflections( uint8 ep, uint16 clusterID );
  134. /*
  135. * Finds the binding entry for the source address,
  136. * endpoint and clusterID passed in as a parameter.
  137. */
  138. extern BindingEntry_t *bindFind( uint8 ep, uint16 clusterID, uint8 skipping );
  139. /*
  140. * Processes the Hand Binding Timeout.
  141. */
  142. extern void nwk_HandBindingTimeout( void );
  143. /*
  144. * Initialize Binding Table NV Item
  145. */
  146. extern byte BindInitNV( void );
  147. /*
  148. * Initialize Binding Table NV Item
  149. */
  150. extern void BindSetDefaultNV( void );
  151. /*
  152. * Restore Binding Table from NV
  153. */
  154. extern uint16 BindRestoreFromNV( void );
  155. /*
  156. * Write Binding Table out to NV
  157. */
  158. extern void BindWriteNV( void );
  159. /*
  160. * Update network address in binding table
  161. */
  162. extern void bindUpdateAddr( uint16 oldAddr, uint16 newAddr );
  163. /*
  164. * This function is used to Add an entry to the binding table
  165. */
  166. extern BindingEntry_t *bindAddEntry( byte srcEpInt,
  167. zAddrType_t *dstAddr, byte dstEpInt,
  168. byte numClusterIds, uint16 *clusterIds );
  169. /*
  170. * This function returns the number of binding table entries
  171. */
  172. extern uint16 bindNumOfEntries( void );
  173. /*
  174. * This function returns the number of binding entries
  175. * possible and used.
  176. */
  177. extern void bindCapacity( uint16 *maxEntries, uint16 *usedEntries );
  178. /*********************************************************************
  179. * FUNCTION POINTERS
  180. */
  181. /*
  182. * This function is used to Add an entry to the binding table
  183. */
  184. extern BindingEntry_t *(*pbindAddEntry)( byte srcEpInt,
  185. zAddrType_t *dstAddr, byte dstEpInt,
  186. byte numClusterIds, uint16 *clusterIds );
  187. /*
  188. * This function returns the number of binding table entries
  189. */
  190. extern uint16 (*pbindNumOfEntries)( void );
  191. /*
  192. * Remove bind(s) associated to a address (source or destination)
  193. */
  194. extern void (*pbindRemoveDev)( zAddrType_t *Addr );
  195. /*
  196. * Initialize Binding Table NV Item
  197. */
  198. extern byte (*pBindInitNV)( void );
  199. /*
  200. * Initialize Binding Table NV Item
  201. */
  202. extern void (*pBindSetDefaultNV)( void );
  203. /*
  204. * Restore binding table from NV
  205. */
  206. extern uint16 (*pBindRestoreFromNV)( void );
  207. /*
  208. * Write binding table to NV
  209. */
  210. extern void (*pBindWriteNV)( void );
  211. /*
  212. * Convert address manager index to zAddrType_t for an extended address
  213. */
  214. extern uint8 bindingAddrMgsHelperConvert( uint16 idx, zAddrType_t *addr );
  215. /*
  216. * Convert address manager index to short address
  217. */
  218. extern uint16 bindingAddrMgsHelperConvertShort( uint16 idx );
  219. /*
  220. * Get a pointer to the Nth valid binding table entry.
  221. */
  222. extern BindingEntry_t *GetBindingTableEntry( uint16 Nth );
  223. /*********************************************************************
  224. *********************************************************************/
  225. #ifdef __cplusplus
  226. }
  227. #endif
  228. #endif /* BINDINGTABLE_H */