nwk_globals.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. /**************************************************************************************************
  2. Filename: nwk_globals.h
  3. Revised: $Date: 2012-03-07 01:04:58 -0800 (Wed, 07 Mar 2012) $
  4. Revision: $Revision: 29656 $
  5. Description: User definable Network Parameters.
  6. Copyright 2004-2011 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 NWK_GLOBALS_H
  34. #define NWK_GLOBALS_H
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. /*********************************************************************
  39. * INCLUDES
  40. */
  41. #include "ZComDef.h"
  42. #include "nwk_bufs.h"
  43. #include "AssocList.h"
  44. #include "BindingTable.h"
  45. #include "ZGlobals.h"
  46. /*********************************************************************
  47. * MACROS
  48. */
  49. /*********************************************************************
  50. * CONSTANTS
  51. */
  52. // If ZIGBEEPRO is defined - define all the features for Zigbee Pro
  53. //#define ZIGBEE_MULTICAST
  54. #if defined ( ZIGBEEPRO )
  55. #if !defined ( ZIGBEE_STOCHASTIC_ADDRESSING )
  56. #define ZIGBEE_STOCHASTIC_ADDRESSING
  57. #define ZIGBEE_NWK_UNIQUE_ADDR_CHECK
  58. #endif
  59. #if !defined ( NWK_LINK_STATUS_PERIOD )
  60. #define NWK_LINK_STATUS_PERIOD 15 // 15 seconds
  61. #endif
  62. #if !defined ( ZIGBEE_MULTICAST )
  63. #define ZIGBEE_MULTICAST
  64. #endif
  65. #if !defined ( ZIGBEE_MANY_TO_ONE )
  66. #define ZIGBEE_MANY_TO_ONE
  67. #endif
  68. #if !defined ( ZIGBEE_SOURCE_ROUTING )
  69. #define ZIGBEE_SOURCE_ROUTING
  70. #endif
  71. #if !defined ( ZIGBEE_COMMISSIONING )
  72. #define ZIGBEE_COMMISSIONING
  73. #endif
  74. #if !defined ( NWK_MANAGER )
  75. //#define NWK_MANAGER // WARNING: this should be enabled only for one device per network
  76. #endif
  77. #if !defined ( ZIGBEE_FRAGMENTATION )
  78. #define ZIGBEE_FRAGMENTATION
  79. #endif
  80. #else
  81. #define NWK_LINK_STATUS_PERIOD 0
  82. #endif
  83. #if ( RFD_RCVC_ALWAYS_ON==TRUE ) || ( ZG_BUILD_RTR_TYPE )
  84. // The PANID Conflict feature is mandatory for both 2007 and 2007 PRO.
  85. // So, it will be ON all the time (except sleeping end devices).
  86. #if !defined ( ZIGBEE_PANID_CONFLICT )
  87. #define ZIGBEE_PANID_CONFLICT
  88. #endif
  89. #endif
  90. #if ( ZG_BUILD_RTR_TYPE )
  91. // The Frequency Agility feature is mandatory for both 2007 and 2007 PRO.
  92. // So, it will be ON all the time for routers.
  93. #if !defined ( ZIGBEE_FREQ_AGILITY )
  94. #define ZIGBEE_FREQ_AGILITY
  95. #endif
  96. #endif
  97. #if defined ( ZIGBEE_FREQ_AGILITY )
  98. // Make Frequency Agility to look for all MAC errors for Certification test
  99. // by setting the following to TRUE. The default value is FALSE meaning
  100. // that only ZMacChannelAccessFailure error code will trigger a scan.
  101. #if !defined ( NWK_FREQ_AGILITY_ALL_MAC_ERRS )
  102. #define NWK_FREQ_AGILITY_ALL_MAC_ERRS FALSE
  103. #endif
  104. #endif
  105. // Controls the operational mode of network
  106. #define NWK_MODE_STAR 0
  107. #define NWK_MODE_TREE 1
  108. #define NWK_MODE_MESH 2
  109. // Controls various stack parameter settings
  110. #define NETWORK_SPECIFIC 0
  111. #define HOME_CONTROLS 1
  112. #define ZIGBEEPRO_PROFILE 2
  113. #define GENERIC_STAR 3
  114. #define GENERIC_TREE 4
  115. // Channel mask
  116. #define MAX_CHANNELS_868MHZ 0x00000001
  117. #define MAX_CHANNELS_915MHZ 0x000007FE
  118. #if !defined ( MAX_CHANNELS_24GHZ )
  119. #define MAX_CHANNELS_24GHZ 0x07FFF800
  120. #endif
  121. #if defined ( ZIGBEEPRO )
  122. #define STACK_PROFILE_ID ZIGBEEPRO_PROFILE
  123. #else
  124. #define STACK_PROFILE_ID HOME_CONTROLS
  125. #endif
  126. #if ( STACK_PROFILE_ID == ZIGBEEPRO_PROFILE )
  127. #define MAX_NODE_DEPTH 20
  128. #define NWK_MODE NWK_MODE_MESH
  129. #define SECURITY_MODE SECURITY_COMMERCIAL
  130. #if ( SECURE != 0 )
  131. #define USE_NWK_SECURITY 1 // true or false
  132. #define SECURITY_LEVEL 5
  133. #else
  134. #define USE_NWK_SECURITY 0 // true or false
  135. #define SECURITY_LEVEL 0
  136. #endif
  137. #elif ( STACK_PROFILE_ID == HOME_CONTROLS )
  138. #define MAX_NODE_DEPTH 5
  139. #define NWK_MODE NWK_MODE_MESH
  140. #define SECURITY_MODE SECURITY_COMMERCIAL
  141. #if ( SECURE != 0 )
  142. #define USE_NWK_SECURITY 1 // true or false
  143. #define SECURITY_LEVEL 5
  144. #else
  145. #define USE_NWK_SECURITY 0 // true or false
  146. #define SECURITY_LEVEL 0
  147. #endif
  148. #elif ( STACK_PROFILE_ID == GENERIC_STAR )
  149. #define MAX_NODE_DEPTH 5
  150. #define NWK_MODE NWK_MODE_STAR
  151. #define SECURITY_MODE SECURITY_RESIDENTIAL
  152. #if ( SECURE != 0 )
  153. #define USE_NWK_SECURITY 1 // true or false
  154. #define SECURITY_LEVEL 5
  155. #else
  156. #define USE_NWK_SECURITY 0 // true or false
  157. #define SECURITY_LEVEL 0
  158. #endif
  159. #elif ( STACK_PROFILE_ID == NETWORK_SPECIFIC )
  160. // define your own stack profile settings
  161. #define MAX_NODE_DEPTH 5
  162. #define NWK_MODE NWK_MODE_MESH
  163. #define SECURITY_MODE SECURITY_RESIDENTIAL
  164. #if ( SECURE != 0 )
  165. #define USE_NWK_SECURITY 1 // true or false
  166. #define SECURITY_LEVEL 5
  167. #else
  168. #define USE_NWK_SECURITY 0 // true or false
  169. #define SECURITY_LEVEL 0
  170. #endif
  171. #endif
  172. // Zigbee protocol version
  173. #define ZB_PROT_V1_0 1
  174. #define ZB_PROT_V1_1 2
  175. #define ZB_PROT_VERS ZB_PROT_V1_1
  176. #define ZIGBEE_PROT_ID 0x00
  177. // Status and error codes for extra information
  178. #define NWK_STATUS_PING_RCVD 0x0001
  179. #define NWK_STATUS_ASSOC_CNF 0x0002
  180. #define NWK_STATUS_ED_ADDR 0x0003
  181. #define NWK_STATUS_PARENT_ADDR 0x0004
  182. #define NWK_STATUS_COORD_ADDR 0x0005
  183. #define NWK_STATUS_ROUTER_ADDR 0x0006
  184. #define NWK_STATUS_ORPHAN_RSP 0x0007
  185. #define NWK_ERROR_ASSOC_RSP 0x1001
  186. #define NWK_ERROR_ASSOC_RSP_MF 0x1002
  187. #define NWK_ERROR_ASSOC_CNF_DENIED 0x1003
  188. #define NWK_ERROR_ENERGY_SCAN_FAILED 0x1004
  189. // Indicate whether incoming NWK frames must be all checked for freshness
  190. // when the memory for incoming frame counts is exceeded
  191. #if !defined( NWK_ALL_FRESH)
  192. #define NWK_ALL_FRESH TRUE // Default to TRUE - Check all frames
  193. #endif
  194. // Maximum number in tables
  195. #if !defined( NWK_MAX_DEVICE_LIST )
  196. #define NWK_MAX_DEVICE_LIST 20 // Maximum number of devices in the
  197. // Assoc/Device list.
  198. #endif
  199. // Don't change this value to set the number of devices. Change
  200. // NWK_MAX_DEVICE_LIST above
  201. #define NWK_MAX_DEVICES ( NWK_MAX_DEVICE_LIST + 1 ) // One extra space for parent
  202. #define NWK_MAX_ROUTERS 6
  203. // Number of reserved places for router and end device children, to be used in stochastic addressing.
  204. #if !defined ( NWK_MIN_ROUTER_CHILDREN )
  205. #define NWK_MIN_ROUTER_CHILDREN 0
  206. #endif
  207. #if !defined ( NWK_MIN_ENDDEVICE_CHILDREN )
  208. #define NWK_MIN_ENDDEVICE_CHILDREN 0
  209. #endif
  210. #if !defined ( MAX_NEIGHBOR_ENTRIES )
  211. #if ( ZG_BUILD_RTR_TYPE )
  212. #define MAX_NEIGHBOR_ENTRIES 16
  213. #else
  214. #define MAX_NEIGHBOR_ENTRIES 4
  215. #endif
  216. #endif
  217. #if !defined ( APS_MAX_GROUPS )
  218. #define APS_MAX_GROUPS 10
  219. #endif
  220. // Maxiumum number of REFLECTOR address entries
  221. #if defined ( REFLECTOR )
  222. #define NWK_MAX_REFLECTOR_ENTRIES ( NWK_MAX_BINDING_ENTRIES )
  223. #else
  224. #define NWK_MAX_REFLECTOR_ENTRIES 0
  225. #endif
  226. #if !defined( MAX_BCAST )
  227. #define MAX_BCAST 4
  228. #endif
  229. // Maxiumum number of secure partners(Commercial mode only).
  230. // Add 1 for the Trust Center(Coordinator) if it is not the parent.
  231. #define NWK_MAX_SECURE_PARTNERS 1
  232. // Maximum number of addresses managed by the Address Manager
  233. #define NWK_MAX_ADDRESSES (uint16) \
  234. ( ( NWK_MAX_DEVICES ) + \
  235. ( NWK_MAX_REFLECTOR_ENTRIES ) + \
  236. ( NWK_MAX_SECURE_PARTNERS ) )
  237. // Network PAN Coordinator Address
  238. #define NWK_PAN_COORD_ADDR 0x0000
  239. // Network Addressing modes
  240. #define NWK_ADDRESSING_DISTRIBUTED 0x00
  241. #define NWK_ADDRESSING_STOCHASTIC 0x02
  242. #if !defined ( NWK_LINK_STATUS_PERIOD )
  243. #define NWK_LINK_STATUS_PERIOD 15 // 15 seconds
  244. #endif
  245. #if !defined ( LINK_STATUS_JITTER_MASK )
  246. #define LINK_STATUS_JITTER_MASK 0x007F // 127 milliseconds
  247. #endif
  248. #if !defined ( NWK_ROUTE_AGE_LIMIT )
  249. #define NWK_ROUTE_AGE_LIMIT 3 // 3 missed link satus frames
  250. #endif
  251. #if !defined ( MAX_RTG_SRC_ENTRIES )
  252. #define MAX_RTG_SRC_ENTRIES 12
  253. #endif
  254. #if !defined ( SRC_RTG_EXPIRY_TIME )
  255. #define SRC_RTG_EXPIRY_TIME 10 // seconds before the source route entry expires
  256. #endif
  257. #if !defined ( MTO_RREQ_LIMIT_TIME )
  258. // in milliseconds. The time limited to one MTO RReq (Concentrator Announce)
  259. #define MTO_RREQ_LIMIT_TIME 1000
  260. #endif
  261. #if !defined ( MTO_ROUTE_EXPIRY_TIME )
  262. // The number of seconds a MTO routing entry will last. Default to not expiring.
  263. #define MTO_ROUTE_EXPIRY_TIME RTG_NO_EXPIRY_TIME
  264. #endif
  265. #if ( ZG_BUILD_ENDDEVICE_TYPE )
  266. #define APS_MAX_ENDDEVICE_BROADCAST_ENTRIES ( 2 * MAX_BCAST )
  267. #endif
  268. #if !defined( NWK_CONFLICTED_ADDR_EXPIRY_TIME )
  269. #define NWK_CONFLICTED_ADDR_EXPIRY_TIME 4 // number of link status period after the
  270. // last received address conflict
  271. // report (network status command)
  272. #endif
  273. #if !defined ( LINK_DOWN_TRIGGER )
  274. #define LINK_DOWN_TRIGGER 3 // Link is down if txCounter exceeds this
  275. #endif
  276. // This the size of the conflicted address table
  277. // Scale it up if the size of the network is over 100 nodes
  278. #if !defined( CONFLICTED_ADDR_TABLE_SIZE )
  279. #define CONFLICTED_ADDR_TABLE_SIZE 3
  280. #endif
  281. // Maximum number of relays in source routing
  282. #if !defined ( MAX_SOURCE_ROUTE )
  283. #define MAX_SOURCE_ROUTE 12
  284. #endif
  285. #if !defined ( MAX_BROADCAST_QUEUED )
  286. #define MAX_BROADCAST_QUEUED 10
  287. #endif
  288. #if !defined ( DEFAULT_ROUTE_REQUEST_RADIUS )
  289. #define DEFAULT_ROUTE_REQUEST_RADIUS DEF_NWK_RADIUS
  290. #endif
  291. #if !defined ( DEF_NWK_RADIUS )
  292. // the default network radius set twice the value of <nwkMaxDepth>
  293. #define DEF_NWK_RADIUS ( 2 * BEACON_MAX_DEPTH )
  294. #endif
  295. #if !defined ( MAX_PASSIVE_ACK_CNT )
  296. #define MAX_PASSIVE_ACK_CNT 8
  297. #endif
  298. // Statistic Types, used with nwk_UpdateStatistics()
  299. #define STAT_NWK_INVALID_PACKET 1
  300. #define STAT_NWK_SECURITY_FAILURE 2
  301. #define STAT_APS_INVALID_PACKET 3
  302. #define STAT_APS_SECURITY_FAILURE 4
  303. // ZigBee Alliance Pre-configured TC Link Key - 'ZigBeeAlliance09'
  304. #define DEFAULT_TC_LINK_KEY { 0x5a, 0x69, 0x67, 0x42, 0x65, 0x65, 0x41, 0x6c,\
  305. 0x6c, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x30, 0x39 }
  306. /*********************************************************************
  307. * TYPEDEFS
  308. */
  309. /*********************************************************************
  310. * NWK GLOBAL VARIABLES
  311. */
  312. // Variables for MAX data buffer levels
  313. extern CONST byte gNWK_MAX_DATABUFS_WAITING;
  314. extern CONST byte gNWK_MAX_DATABUFS_SCHEDULED;
  315. extern CONST byte gNWK_MAX_DATABUFS_CONFIRMED;
  316. extern CONST byte gNWK_MAX_DATABUFS_TOTAL;
  317. extern CONST byte gNWK_INDIRECT_CNT_RTG_TMR;
  318. extern CONST byte gNWK_INDIRECT_MSG_MAX_PER;
  319. extern CONST byte gNWK_INDIRECT_MSG_MAX_ALL;
  320. extern CONST byte gMAX_NEIGHBOR_ENTRIES;
  321. extern CONST uint16 gMAX_RTG_ENTRIES;
  322. extern CONST uint16 gMAX_RTG_SRC_ENTRIES;
  323. extern CONST uint8 gMAX_RREQ_ENTRIES;
  324. extern CONST uint16 gMTO_RREQ_LIMIT_TIME;
  325. extern CONST uint8 gMTO_ROUTE_EXPIRY_TIME;
  326. extern CONST uint8 gMAX_PASSIVE_ACK_CNT;
  327. // Variables for MAX list size
  328. extern CONST uint16 gNWK_MAX_DEVICE_LIST;
  329. // Variables for MAX Sleeping End Devices
  330. extern CONST uint8 gNWK_MAX_SLEEPING_END_DEVICES;
  331. extern CONST uint8 gNWK_TREE_ALLOCATE_ROUTERADDR_FOR_ENDDEVICE;
  332. extern CONST uint16 gNWK_MIN_ROUTER_CHILDREN;
  333. extern CONST uint16 gNWK_MIN_ENDDEVICE_CHILDREN;
  334. extern uint16 *Cskip;
  335. extern byte CskipRtrs[];
  336. extern byte CskipChldrn[];
  337. extern byte gMIN_TREE_LINK_COST;
  338. extern CONST byte defaultKey[];
  339. extern CONST byte defaultTCLinkKey[];
  340. extern CONST uint8 gMAX_SOURCE_ROUTE;
  341. extern uint16 rtgSrcRelayList[];
  342. extern CONST byte gMAX_BCAST;
  343. extern CONST byte gNWK_CONFLICTED_ADDR_EXPIRY_TIME;
  344. extern CONST uint8 gNWK_FREQ_AGILITY_ALL_MAC_ERRS;
  345. extern CONST uint8 gMAX_BROADCAST_QUEUED;
  346. extern CONST uint8 gLINK_DOWN_TRIGGER;
  347. extern CONST uint8 gDEFAULT_ROUTE_REQUEST_RADIUS;
  348. extern CONST uint8 gDEF_NWK_RADIUS;
  349. extern CONST uint16 gLINK_STATUS_JITTER_MASK;
  350. /*********************************************************************
  351. * APS GLOBAL VARIABLES
  352. */
  353. // Variables for Binding Table
  354. extern CONST uint16 gNWK_MAX_BINDING_ENTRIES;
  355. extern CONST uint8 gMAX_BINDING_CLUSTER_IDS;
  356. extern CONST uint16 gBIND_REC_SIZE;
  357. extern CONST uint8 gAPS_MAX_GROUPS;
  358. extern uint8 gAPS_MAX_ENDDEVICE_BROADCAST_ENTRIES;
  359. /*********************************************************************
  360. * GLOBAL VARIABLES - Statistics
  361. */
  362. #if defined ( PACKET_FILTER_STATS )
  363. extern uint32 apsInvalidPackets;
  364. extern uint32 apsSecurityFailures;
  365. extern uint32 nwkInvalidPackets;
  366. extern uint32 nwkSecurityFailures;
  367. #endif
  368. /*********************************************************************
  369. * FUNCTIONS
  370. */
  371. /*
  372. * Init Global Variables
  373. */
  374. extern void nwk_globals_init( void );
  375. extern void NIB_init( void );
  376. extern void nwk_Status( uint16 statusCode, uint16 statusValue );
  377. extern void nwk_UpdateStatistics( uint8 statisticCode );
  378. /*********************************************************************
  379. *********************************************************************/
  380. #ifdef __cplusplus
  381. }
  382. #endif
  383. #endif /* NWK_GLOBALS_H */