nwk.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. /**************************************************************************************************
  2. Filename: nwk.h
  3. Revised: $Date: 2008-03-10 16:19:41 -0700 (Mon, 10 Mar 2008) $
  4. Revision: $Revision: 16563 $
  5. Description: Network layer logic component interface.
  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 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. //NWK PACKET: FIELD IDENTIFIERS
  70. #define NWK_CMD_ID 0
  71. #define NWK_PARAMS_ID 1
  72. #define NWK_REQ_ATTR_ID 1
  73. #define NWK_REQ_ATTR 2
  74. #define NWK_CMD_PYLD_BEGIN NWK_HEADER_LEN
  75. #define NWK_DEVICE_LIST_LEN_FIELD NWK_HEADER_LEN + 1
  76. // This value needs to be set or read from somewhere
  77. #define ED_SCAN_MAXCHANNELS 27
  78. // Max length of packet that can be sent to the MAC
  79. #define MAX_DATA_PACKET_LEN MAC_MAX_FRAME_SIZE
  80. #define NWK_TASK_ID 0
  81. #define ASSOC_CAPABILITY_INFO 0
  82. #define ASSOC_SECURITY_EN 0
  83. #define DEF_DEST_EP 2
  84. #define DEVICE_APPLICATION 0
  85. #define MAC_ADDR_LEN 8
  86. #define NWK_TXOPTIONS_ACK 0x01
  87. #define NWK_TXOPTIONS_INDIRECT 0x04
  88. // TxOptions for a data request - Indirect data and ACK required
  89. #define NWK_TXOPTIONS_COORD (NWK_TXOPTIONS_ACK | NWK_TXOPTIONS_INDIRECT)
  90. // TxOptions for a data request - Direct data and ACK required
  91. //#define NWK_TXOPTIONS_COORD (NWK_TXOPTIONS_ACK)
  92. //Assume value until defined By SuperApp or design spec
  93. #define DEF_MAX_NUM_COORDINATORS 15 //Default value
  94. #define DEF_CHANNEL_SCAN_BITMAP MAX_CHANNELS_24GHZ
  95. #define SOFT_SCAN_DURATION 1 //in secs
  96. #define DEF_SCAN_DURATION 2
  97. #define NO_BEACONS 15
  98. #define DEF_BEACON_ORDER NO_BEACONS
  99. //#define DEF_BEACON_ORDER 10 // 15 seconds
  100. //#define DEF_BEACON_ORDER 9 // 7.5 seconds
  101. //#define DEF_BEACON_ORDER 8 // 3.75 seconds
  102. //#define DEF_BEACON_ORDER 6 // 1 second
  103. //#define DEF_BEACON_ORDER 1 // 30 millisecond
  104. //#define DEF_SUPERFRAMEORDER 2
  105. #define DEF_SUPERFRAMEORDER DEF_BEACON_ORDER
  106. #define NWK_SECURITY_ENABLE FALSE
  107. #define NWK_MAC_ASSOC_CNF_LEN 4
  108. #define FIXED_SIZ_MAC_DATA_CNF 4 //Length of all fixed params except data
  109. #define FIXED_SIZ_MAC_DATA_IND 26
  110. #define FIXED_SIZ_MAC_SCAN_CNF 7
  111. #define ALL_PAIRING_TABLE_ENTRIES 0
  112. #define SIZE_OF_PAIRING_TABLE_ENTRY 6 //Two short addr and two endpts
  113. #define SIZE_OF_DEVICE_LIST_ENTRY 2 //short addr in dev list is 2 bytes
  114. // the default network radius set twice the value of <nwkMaxDepth>
  115. #define DEF_NWK_RADIUS ( 2 * BEACON_MAX_DEPTH )
  116. #define NWK_SEND_TIMER_INTERVAL 2
  117. #define NWK_BCAST_TIMER_INTERVAL 100 // NWK_BCAST_TIMER_EVT duration
  118. #define INVALID_NODE_ADDR 0xFFFE
  119. #define INVALID_PAN_ID 0xFFFE
  120. // Link cost constants
  121. #define DEF_LINK_COST 1 // Default link cost
  122. #define MAX_LINK_COST 7 // max link cost
  123. #define LINK_DOWN_COST 0 // link is down if txCost is equal to LINK_DOWN_COST
  124. #define LINK_AGEOUT_COST 0 // Set link cost to zero if the neighbor age out
  125. // Link counter constants
  126. #define DEF_LINK_COUNTER 2 // Starting tx counter
  127. #define MAX_LINK_COUNTER 4 // max tx counter
  128. #define LINK_DOWN_TRIGGER 3 // Link is down if txCounter exceeds this
  129. #define LINK_ACTIVE_TRIGGER 2 // link is up if txCounter goes below this
  130. //NWK Callback subscription IDs
  131. #define CB_ID_APP_ANNOUNCE_CNF 0x00
  132. #define CB_ID_APP_ASSOCIATE_CNF 0x01
  133. #define CB_ID_APP_ASSOCIATE_IND 0x02
  134. #define CB_ID_APP_DATA_CNF 0x03
  135. #define CB_ID_APP_DATA_IND 0x04
  136. #define CB_ID_APP_DISASSOCIATE_CNF 0x05
  137. #define CB_ID_APP_DISASSOCIATE_IND 0x06
  138. #define CB_ID_APP_NETWORK_DETECT_CNF 0x07
  139. #define CB_ID_APP_REMOTE_GET_CNF 0x08
  140. #define SPI_CB_APP_REMOTE_SET_CNF 0x09
  141. #define CB_ID_APP_SERVICE_CNF 0x0a
  142. #define CB_ID_APP_SERVICE_IND 0x0b
  143. #define CB_ID_APP_START_CNF 0x0c
  144. #define NUM_PING_ROUTE_ADDRS 12
  145. #define PING_ROUTE_ADDRS_INDEX 8
  146. #define NWK_GetNodeDepth() (_NIB.nodeDepth)
  147. #define NWK_GetTreeDepth() (0)
  148. #define BEACON_MAX_DEPTH 0x0F
  149. /*********************************************************************
  150. * TYPEDEFS
  151. */
  152. typedef enum
  153. {
  154. NWK_INIT,
  155. NWK_JOINING_ORPHAN,
  156. NWK_DISC,
  157. NWK_JOINING,
  158. NWK_ENDDEVICE,
  159. PAN_CHNL_SELECTION,
  160. PAN_CHNL_VERIFY,
  161. PAN_STARTING,
  162. NWK_ROUTER,
  163. NWK_REJOINING
  164. } nwk_states_t;
  165. // MAC Command Buffer types
  166. typedef enum
  167. {
  168. MACCMDBUF_NONE,
  169. MACCMDBUF_ASSOC_REQ,
  170. MACCMDBUF_DISASSOC_REQ
  171. } nwkMacCmds_t;
  172. typedef struct
  173. {
  174. byte SequenceNum;
  175. byte PassiveAckTimeout;
  176. byte MaxBroadcastRetries;
  177. byte MaxChildren;
  178. byte MaxDepth;
  179. byte MaxRouters;
  180. //neighborEntry_t * pNeighborTable;
  181. byte dummyNeighborTable; // to make everything a byte!!
  182. byte BroadcastDeliveryTime;
  183. byte ReportConstantCost;
  184. byte RouteDiscRetries;
  185. //rtgEntry_t * pRoutingTable;
  186. byte dummyRoutingTable; // to make everything a byte!!
  187. byte SecureAllFrames;
  188. byte SecurityLevel;
  189. byte SymLink;
  190. byte CapabilityInfo;
  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. // Key information
  215. uint8 nwkKeyLoaded;
  216. nwkKeyDesc nwkActiveKey;
  217. nwkKeyDesc nwkAlternateKey;
  218. // Zigbee Pro extensions
  219. uint8 nwkAddrAlloc;
  220. uint8 nwkUniqueAddr;
  221. uint8 nwkLinkStatusPeriod; // The time in seconds betwee link status
  222. // command frames
  223. uint8 nwkRouterAgeLimit; // The number of missed link status
  224. // command frames before resetting the
  225. // link cost to zero
  226. uint8 nwkUseMultiCast;
  227. // ZigBee Pro extentions: MTO routing
  228. uint8 nwkIsConcentrator; // If set, then the device is concentrator
  229. uint8 nwkConcentratorDiscoveryTime; // Time period between two consecutive MTO route discovery
  230. uint8 nwkConcentratorRadius; // Broadcast radius of the MTO route discovery
  231. uint8 nwkMaxSourceRoute; // Maximum number of relays in source routing
  232. uint16 nwkManagerAddr; // Network Manager Address
  233. uint16 nwkTotalTransmissions;
  234. uint8 nwkUpdateId;
  235. } nwkIB_t;
  236. // Scanned PAN IDs to be used for Network Report command
  237. typedef struct
  238. {
  239. uint16 panId;
  240. void *next;
  241. } nwkPanId_t;
  242. /*********************************************************************
  243. * GLOBAL VARIABLES
  244. */
  245. extern nwkIB_t _NIB;
  246. extern byte NWK_TaskID;
  247. extern networkDesc_t *NwkDescList;
  248. extern byte nwkExpectingMsgs;
  249. extern byte nwk_beaconPayload[ZMAC_MAX_BEACON_PAYLOAD_LEN];
  250. extern byte nwk_beaconPayloadSize;
  251. /*********************************************************************
  252. * FUNCTIONS
  253. */
  254. /*
  255. * NWK Task Initialization
  256. */
  257. extern void nwk_init( byte task_id );
  258. /*
  259. * Calls mac_data_req then handles the buffering
  260. */
  261. extern ZStatus_t nwk_data_req_send( nwkDB_t* db );
  262. /*
  263. * NWK Event Loop
  264. */
  265. extern UINT16 nwk_event_loop( byte task_id, UINT16 events );
  266. /*
  267. * Process incoming command packet
  268. */
  269. //extern void CommandPktProcessing( NLDE_FrameFormat_t *ff );
  270. /*
  271. * Start a coordinator
  272. */
  273. extern ZStatus_t nwk_start_coord( void );
  274. /*
  275. * Free any network discovery data
  276. */
  277. extern void nwk_desc_list_free( void );
  278. networkDesc_t *nwk_getNetworkDesc( uint8 *ExtendedPANID, uint16 PanId, byte Channel );
  279. extern void nwk_BeaconFromNative(byte* buff, byte size, beaconPayload_t* beacon);
  280. extern void nwk_BeaconToNative(beaconPayload_t* beacon, byte* buff, byte size);
  281. /*
  282. * Set NWK task's state
  283. */
  284. extern void nwk_setStateIdle( uint8 idle );
  285. /*
  286. * Returns TRUE if NWK state is idle, FALSE otherwise.
  287. */
  288. extern uint8 nwk_stateIdle( void );
  289. /*********************************************************************
  290. * Functionality - not to be called directly.
  291. */
  292. extern void nwk_ScanJoiningOrphan( ZMacScanCnf_t *param );
  293. extern void nwk_ScanPANChanSelect( ZMacScanCnf_t *param );
  294. extern void nwk_ScanPANChanVerify( ZMacScanCnf_t *param );
  295. /*********************************************************************
  296. *********************************************************************/
  297. #ifdef __cplusplus
  298. }
  299. #endif
  300. #endif /* NWK_H */