nwk.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. /**************************************************************************************************
  2. Filename: nwk.h
  3. Revised: $Date: 2010-05-11 18:37:17 -0700 (Tue, 11 May 2010) $
  4. Revision: $Revision: 22455 $
  5. Description: Network layer logic component interface.
  6. Copyright 2004-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. #ifndef NWK_H
  34. #define NWK_H
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. /*********************************************************************
  39. * INCLUDES
  40. */
  41. #include "ZComDef.h"
  42. #include "ZMAC.h"
  43. #include "nwk_bufs.h"
  44. #include "NLMEDE.h"
  45. #include "ssp.h"
  46. /*********************************************************************
  47. * MACROS
  48. */
  49. /*********************************************************************
  50. * CONSTANTS
  51. */
  52. //NWK event identifiers
  53. #define MAC_SCAN_REQ 0x01
  54. #define NWK_NETWORKSTART_REQ 0x02
  55. #define MAC_ASSOCIATE_REQ 0x03
  56. #define NWK_REMOTE_GET_REQ 0x04
  57. #define NWK_REMOTE_SET_REQ 0x05
  58. #define NWK_ASSOCIATE_RESP 0x06
  59. #define NWK_DISASSOCIATE_REQ 0x07
  60. #define NWK_AUTO_POLL_EVT 0x0001
  61. #define NWK_NOT_EXPECTING_EVT 0x0004
  62. #define RTG_TIMER_EVENT 0x0010
  63. #define NWK_DATABUF_SEND 0x0020
  64. #define NWK_BCAST_TIMER_EVT 0x0040
  65. #define NWK_PERMITJOIN_EVT 0x0080
  66. #define NWK_LINK_STATUS_EVT 0x0100
  67. #define NWK_PID_UPDATE_EVT 0x0200
  68. #define NWK_REJOIN_TIMEOUT_EVT 0x0400
  69. #define NWK_MTO_RTG_REQ_EVT 0x0800
  70. #define NWK_MTO_RTG_REQ_DELAY_EVT 0x1000
  71. #define NWK_BROADCAST_MSG_EVT 0x2000
  72. //NWK PACKET: FIELD IDENTIFIERS
  73. #define NWK_CMD_ID 0
  74. #define NWK_PARAMS_ID 1
  75. #define NWK_REQ_ATTR_ID 1
  76. #define NWK_REQ_ATTR 2
  77. #define NWK_CMD_PYLD_BEGIN NWK_HEADER_LEN
  78. #define NWK_DEVICE_LIST_LEN_FIELD NWK_HEADER_LEN + 1
  79. // This value needs to be set or read from somewhere
  80. #define ED_SCAN_MAXCHANNELS 27
  81. // Max length of packet that can be sent to the MAC
  82. #define MAX_DATA_PACKET_LEN MAC_MAX_FRAME_SIZE
  83. #define NWK_TASK_ID 0
  84. #define ASSOC_CAPABILITY_INFO 0
  85. #define ASSOC_SECURITY_EN 0
  86. #define DEF_DEST_EP 2
  87. #define DEVICE_APPLICATION 0
  88. #define MAC_ADDR_LEN 8
  89. #define NWK_TXOPTIONS_ACK 0x01
  90. #define NWK_TXOPTIONS_INDIRECT 0x04
  91. // TxOptions for a data request - Indirect data and ACK required
  92. #define NWK_TXOPTIONS_COORD (NWK_TXOPTIONS_ACK | NWK_TXOPTIONS_INDIRECT)
  93. // TxOptions for a data request - Direct data and ACK required
  94. //#define NWK_TXOPTIONS_COORD (NWK_TXOPTIONS_ACK)
  95. //Assume value until defined By SuperApp or design spec
  96. #define DEF_MAX_NUM_COORDINATORS 15 //Default value
  97. #define DEF_CHANNEL_SCAN_BITMAP MAX_CHANNELS_24GHZ
  98. #define SOFT_SCAN_DURATION 1 //in secs
  99. #define DEF_SCAN_DURATION 2
  100. #define NO_BEACONS 15
  101. #define DEF_BEACON_ORDER NO_BEACONS
  102. //#define DEF_BEACON_ORDER 10 // 15 seconds
  103. //#define DEF_BEACON_ORDER 9 // 7.5 seconds
  104. //#define DEF_BEACON_ORDER 8 // 3.75 seconds
  105. //#define DEF_BEACON_ORDER 6 // 1 second
  106. //#define DEF_BEACON_ORDER 1 // 30 millisecond
  107. //#define DEF_SUPERFRAMEORDER 2
  108. #define DEF_SUPERFRAMEORDER DEF_BEACON_ORDER
  109. #define NWK_SECURITY_ENABLE FALSE
  110. #define NWK_MAC_ASSOC_CNF_LEN 4
  111. #define FIXED_SIZ_MAC_DATA_CNF 4 //Length of all fixed params except data
  112. #define FIXED_SIZ_MAC_DATA_IND 26
  113. #define FIXED_SIZ_MAC_SCAN_CNF 7
  114. #define ALL_PAIRING_TABLE_ENTRIES 0
  115. #define SIZE_OF_PAIRING_TABLE_ENTRY 6 //Two short addr and two endpts
  116. #define SIZE_OF_DEVICE_LIST_ENTRY 2 //short addr in dev list is 2 bytes
  117. #define NWK_SEND_TIMER_INTERVAL 2
  118. #define NWK_BCAST_TIMER_INTERVAL 100 // NWK_BCAST_TIMER_EVT duration
  119. #define INVALID_NODE_ADDR 0xFFFE
  120. #define INVALID_PAN_ID 0xFFFE
  121. // Link cost constants
  122. #define DEF_LINK_COST 1 // Default link cost
  123. #define MAX_LINK_COST 7 // max link cost
  124. #define LINK_DOWN_COST 0 // link is down if txCost is equal to LINK_DOWN_COST
  125. #define LINK_AGEOUT_COST 0 // Set link cost to zero if the neighbor age out
  126. // Link counter constants
  127. #define DEF_LINK_COUNTER ((gLINK_DOWN_TRIGGER+1) / 2) // Starting tx counter
  128. #define LINK_ACTIVE_TRIGGER 2 // link is up if txCounter goes below this
  129. //NWK Callback subscription IDs
  130. #define CB_ID_APP_ANNOUNCE_CNF 0x00
  131. #define CB_ID_APP_ASSOCIATE_CNF 0x01
  132. #define CB_ID_APP_ASSOCIATE_IND 0x02
  133. #define CB_ID_APP_DATA_CNF 0x03
  134. #define CB_ID_APP_DATA_IND 0x04
  135. #define CB_ID_APP_DISASSOCIATE_CNF 0x05
  136. #define CB_ID_APP_DISASSOCIATE_IND 0x06
  137. #define CB_ID_APP_NETWORK_DETECT_CNF 0x07
  138. #define CB_ID_APP_REMOTE_GET_CNF 0x08
  139. #define SPI_CB_APP_REMOTE_SET_CNF 0x09
  140. #define CB_ID_APP_SERVICE_CNF 0x0a
  141. #define CB_ID_APP_SERVICE_IND 0x0b
  142. #define CB_ID_APP_START_CNF 0x0c
  143. #define NUM_PING_ROUTE_ADDRS 12
  144. #define PING_ROUTE_ADDRS_INDEX 8
  145. #define NWK_GetNodeDepth() (_NIB.nodeDepth)
  146. #define NWK_GetTreeDepth() (0)
  147. #define BEACON_MAX_DEPTH 0x0F
  148. /*********************************************************************
  149. * TYPEDEFS
  150. */
  151. typedef enum
  152. {
  153. NWK_INIT,
  154. NWK_JOINING_ORPHAN,
  155. NWK_DISC,
  156. NWK_JOINING,
  157. NWK_ENDDEVICE,
  158. PAN_CHNL_SELECTION,
  159. PAN_CHNL_VERIFY,
  160. PAN_STARTING,
  161. NWK_ROUTER,
  162. NWK_REJOINING
  163. } nwk_states_t;
  164. // MAC Command Buffer types
  165. typedef enum
  166. {
  167. MACCMDBUF_NONE,
  168. MACCMDBUF_ASSOC_REQ,
  169. MACCMDBUF_DISASSOC_REQ
  170. } nwkMacCmds_t;
  171. typedef struct
  172. {
  173. byte SequenceNum;
  174. byte PassiveAckTimeout;
  175. byte MaxBroadcastRetries;
  176. byte MaxChildren;
  177. byte MaxDepth;
  178. byte MaxRouters;
  179. byte dummyNeighborTable; // to make everything a byte!!
  180. byte BroadcastDeliveryTime;
  181. byte ReportConstantCost;
  182. byte RouteDiscRetries;
  183. byte dummyRoutingTable; // to make everything a byte!!
  184. byte SecureAllFrames;
  185. byte SecurityLevel;
  186. #if defined ( COMPATIBILITY_221 ) // Obsolete - do not use
  187. byte nwkAllFresh;
  188. #endif
  189. byte SymLink;
  190. byte CapabilityFlags;
  191. uint16 TransactionPersistenceTime;
  192. byte nwkProtocolVersion;
  193. // non-standard attributes
  194. byte RouteDiscoveryTime;
  195. byte RouteExpiryTime; // set to 0 to turn off expiration of routes
  196. // non-settable
  197. uint16 nwkDevAddress;
  198. byte nwkLogicalChannel;
  199. uint16 nwkCoordAddress;
  200. byte nwkCoordExtAddress[Z_EXTADDR_LEN];
  201. uint16 nwkPanId;
  202. // Other global items - non-settable
  203. nwk_states_t nwkState;
  204. uint32 channelList;
  205. byte beaconOrder;
  206. byte superFrameOrder;
  207. byte scanDuration;
  208. byte battLifeExt;
  209. uint32 allocatedRouterAddresses;
  210. uint32 allocatedEndDeviceAddresses;
  211. byte nodeDepth;
  212. // Version 1.1 - extended PAN ID
  213. uint8 extendedPANID[Z_EXTADDR_LEN];
  214. // Network key flag
  215. uint8 nwkKeyLoaded;
  216. // Key information - Moved to nwkKeyInfo_t after ZStack 2.3.0
  217. // If these elements are going to be reused make sure to consider the size
  218. // of the structures and padding specific to the target where the stack is
  219. // going to be running.
  220. nwkKeyDesc spare1; // Not used
  221. nwkKeyDesc spare2; // Not used
  222. // Zigbee Pro extensions
  223. uint8 nwkAddrAlloc;
  224. uint8 nwkUniqueAddr;
  225. uint8 nwkLinkStatusPeriod; // The time in seconds betwee link status
  226. // command frames
  227. uint8 nwkRouterAgeLimit; // The number of missed link status
  228. // command frames before resetting the
  229. // link cost to zero
  230. uint8 nwkUseMultiCast;
  231. // ZigBee Pro extentions: MTO routing
  232. uint8 nwkIsConcentrator; // If set, then the device is concentrator
  233. uint8 nwkConcentratorDiscoveryTime; // Time period between two consecutive MTO route discovery
  234. uint8 nwkConcentratorRadius; // Broadcast radius of the MTO route discovery
  235. #if defined ( COMPATIBILITY_221 ) // Obsolete - do not use
  236. uint8 nwkMaxSourceRoute;
  237. uint8 nwkSrcRtgExpiryTime;
  238. #else
  239. uint8 nwkAllFresh;
  240. #endif
  241. uint16 nwkManagerAddr; // Network Manager Address
  242. uint16 nwkTotalTransmissions;
  243. uint8 nwkUpdateId;
  244. } nwkIB_t;
  245. // Scanned PAN IDs to be used for Network Report command
  246. typedef struct
  247. {
  248. uint16 panId;
  249. void *next;
  250. } nwkPanId_t;
  251. /*********************************************************************
  252. * GLOBAL VARIABLES
  253. */
  254. extern nwkIB_t _NIB;
  255. extern byte NWK_TaskID;
  256. extern networkDesc_t *NwkDescList;
  257. extern byte nwkExpectingMsgs;
  258. extern byte nwk_beaconPayload[ZMAC_MAX_BEACON_PAYLOAD_LEN];
  259. extern byte nwk_beaconPayloadSize;
  260. extern uint8 nwkSendMTOReq;
  261. /*********************************************************************
  262. * FUNCTIONS
  263. */
  264. /*
  265. * NWK Task Initialization
  266. */
  267. extern void nwk_init( byte task_id );
  268. /*
  269. * Calls mac_data_req then handles the buffering
  270. */
  271. extern ZStatus_t nwk_data_req_send( nwkDB_t* db );
  272. /*
  273. * NWK Event Loop
  274. */
  275. extern UINT16 nwk_event_loop( byte task_id, UINT16 events );
  276. /*
  277. * Process incoming command packet
  278. */
  279. //extern void CommandPktProcessing( NLDE_FrameFormat_t *ff );
  280. /*
  281. * Start a coordinator
  282. */
  283. extern ZStatus_t nwk_start_coord( void );
  284. /*
  285. * Free any network discovery data
  286. */
  287. extern void nwk_desc_list_free( void );
  288. extern networkDesc_t *nwk_getNetworkDesc( uint8 *ExtendedPANID, uint16 PanId, byte Channel );
  289. extern networkDesc_t *nwk_getNwkDescList( void );
  290. extern void nwk_BeaconFromNative(byte* buff, byte size, beaconPayload_t* beacon);
  291. extern void nwk_BeaconToNative(beaconPayload_t* beacon, byte* buff, byte size);
  292. /*
  293. * Set NWK task's state
  294. */
  295. extern void nwk_setStateIdle( uint8 idle );
  296. /*
  297. * Returns TRUE if NWK state is idle, FALSE otherwise.
  298. */
  299. extern uint8 nwk_stateIdle( void );
  300. /*********************************************************************
  301. * Functionality - not to be called directly.
  302. */
  303. extern void nwk_ScanJoiningOrphan( ZMacScanCnf_t *param );
  304. extern void nwk_ScanPANChanSelect( ZMacScanCnf_t *param );
  305. extern void nwk_ScanPANChanVerify( ZMacScanCnf_t *param );
  306. /*********************************************************************
  307. *********************************************************************/
  308. #ifdef __cplusplus
  309. }
  310. #endif
  311. #endif /* NWK_H */