rtg.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /**************************************************************************************************
  2. Filename: rtg.h
  3. Revised: $Date: 2010-10-19 12:38:16 -0700 (Tue, 19 Oct 2010) $
  4. Revision: $Revision: 24150 $
  5. Description: Interface to mesh routing functions
  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 RTG_H
  34. #define RTG_H
  35. #ifdef __cplusplus
  36. extern "C"
  37. {
  38. #endif
  39. /*********************************************************************
  40. * INCLUDES
  41. */
  42. #include "ZComDef.h"
  43. #include "nwk_util.h"
  44. #include "nwk_bufs.h"
  45. #include "ZGlobals.h"
  46. /*********************************************************************
  47. * MACROS
  48. */
  49. /*********************************************************************
  50. * CONSTANTS
  51. */
  52. #define RTG_TIMER_INTERVAL 1000
  53. //Route request command option
  54. #define MTO_ROUTE 0x01 // Used in option of NLME_RouteDiscoveryRequest() and rtgTable[]
  55. #define NO_ROUTE_CACHE 0x02 // Used in option of NLME_RouteDiscoveryRequest() and rtgTable[]
  56. #define RTG_RECORD 0x04 // Used in option of rtgTable[]
  57. #define MTO_ROUTE_RC 0x08 // Sender has route cache. Used in option of rtgTable[]
  58. #define MTO_ROUTE_NRC 0x10 // Sender doesn't have route cache. Used in option of rtgTable[]
  59. #define DEST_IEEE_ADDR 0x20 // Used in option of route request command frame
  60. #define MULTICAST_ROUTE 0x40 // Ued in all three places
  61. #define RREQ_OPTIONS_MASK 0x78 // b'0111,1000 0-2, 7 are reserved bits
  62. #define RTG_MTO_DEST_ADDRESS NWK_BROADCAST_SHORTADDR_DEVZCZR //0xFFFC
  63. #define RREP_ORI_IEEE 0x10
  64. #define RREP_RES_IEEE 0x20
  65. #define RREP_MULTICAST 0x40
  66. #define RREP_OPTIONS_MASK (RREP_ORI_IEEE | RREP_RES_IEEE | RREP_MULTICAST)
  67. #define RTG_END_DEVICE_ADDR_TYPE 0
  68. #define RTG_ROUTER_ADDR_TYPE 1
  69. #define RTG_NO_EXPIRY_TIME 0xFF
  70. /*********************************************************************
  71. * TYPEDEFS
  72. */
  73. typedef enum
  74. {
  75. RTG_SUCCESS,
  76. RTG_FAIL,
  77. RTG_TBL_FULL,
  78. RTG_HIGHER_COST,
  79. RTG_NO_ENTRY,
  80. RTG_INVALID_PATH,
  81. RTG_INVALID_PARAM,
  82. RTG_SRC_TBL_FULL
  83. } RTG_Status_t;
  84. // status values for routing entries
  85. #define RT_INIT 0
  86. #define RT_ACTIVE 1
  87. #define RT_DISC 2
  88. #define RT_LINK_FAIL 3
  89. #define RT_REPAIR 4
  90. // Routing table entry
  91. // Notice, if you change this structure, you must also change
  92. // rtgItem_t in ZDProfile.h
  93. typedef struct
  94. {
  95. uint16 dstAddress;
  96. uint16 nextHopAddress;
  97. byte expiryTime;
  98. byte status;
  99. uint8 options;
  100. } rtgEntry_t;
  101. // Route discovery table entry
  102. typedef struct
  103. {
  104. byte rreqId;
  105. uint16 srcAddress;
  106. uint16 previousNode;
  107. byte forwardCost;
  108. byte residualCost;
  109. byte expiryTime;
  110. } rtDiscEntry_t;
  111. // Broadcast table entry.
  112. typedef struct
  113. {
  114. uint16 srcAddr;
  115. uint8 bdt; // broadcast delivery time
  116. uint8 pat; // passive ack timeout
  117. uint8 mbr; // max broadcast retries
  118. uint8 handle;
  119. // Count of non-sleeping neighbors and router children.
  120. uint8 ackCnt;
  121. uint8 id;
  122. } bcastEntry_t;
  123. // Source routing table
  124. typedef struct
  125. {
  126. uint8 expiryTime;
  127. uint8 relayCount;
  128. uint16 dstAddress;
  129. uint16* relayList;
  130. } rtgSrcEntry_t;
  131. /*********************************************************************
  132. * GLOBAL VARIABLES
  133. */
  134. extern rtgEntry_t rtgTable[];
  135. extern rtDiscEntry_t rtDiscTable[];
  136. extern rtgSrcEntry_t rtgSrcTable[];
  137. /*********************************************************************
  138. * FUNCTIONS
  139. */
  140. extern void RTG_Init( void );
  141. extern rtgEntry_t *RTG_GetRtgEntry( uint16 DstAddress, uint8 options);
  142. extern RTG_Status_t RTG_RemoveRtgEntry( uint16 DstAddress, uint8 options );
  143. extern uint16 RTG_GetNextHop( uint16 DstAddress, uint16 avoidAddr,
  144. uint16 avoidAddr2, uint16 avoidAddr3, uint8 options );
  145. extern byte RTG_ProcessRreq(
  146. NLDE_FrameFormat_t *ff, uint16 macSrcAddress, uint16 *nextHopAddr );
  147. extern void RTG_ProcessRrep( NLDE_FrameFormat_t *ff, uint16 macSrcAddress );
  148. extern void RTG_ProcessRrec( NLDE_FrameFormat_t *ff );
  149. extern uint8 RTG_ProcessRErr( NLDE_FrameFormat_t *ff );
  150. extern void RTG_TimerEvent( void );
  151. extern uint16 RTG_AllocNewAddress( byte deviceType );
  152. extern void RTG_DeAllocTreeAddress( uint16 shortAddr );
  153. extern void RTG_DeAllocStochasticAddress( uint16 shortAddr );
  154. extern void RTG_BcastTimerHandler( void );
  155. extern byte RTG_BcastChk( NLDE_FrameFormat_t *ff, uint16 macSrcAddr );
  156. extern byte RTG_BcastAdd(NLDE_FrameFormat_t*ff, uint16 macSrcAddr, byte handle);
  157. extern void RTG_BcastDel( byte handle );
  158. extern void RTG_DataReq( osal_event_hdr_t *inMsg );
  159. extern byte RTG_PoolAdd( NLDE_FrameFormat_t *ff );
  160. extern uint16 RTG_GetTreeRoute( uint16 dstAddress );
  161. extern uint16 RTG_SrcGetNextHop( uint8 rtgIndex, uint16* rtgList);
  162. extern uint8 RTG_ValidateSrcRtg(uint8 relayCnt, uint8 relayIdx, uint16* relayList );
  163. extern uint8 RTG_RtgRecordInitiation( uint16 DstAddress, uint16 SrcAddress, uint8 options);
  164. extern RTG_Status_t RTG_GetRtgSrcEntry( uint16 dstAddr, uint8* pRelayCnt, uint16** ppRelayList);
  165. extern RTG_Status_t RTG_CheckRtStatus( uint16 DstAddress, byte RtStatus, uint8 options );
  166. extern uint8 RTG_ProcessRtDiscBits( uint8 rtDiscFlag, uint16 dstAddress, uint8* pSrcRtgSet, uint8 options );
  167. extern uint8 RTG_RouteMaintanence( uint16 DstAddress, uint16 SrcAddress, uint8 options );
  168. extern void RTG_FillCSkipTable( byte *children, byte *routers,
  169. byte depth, uint16 *pTbl );
  170. extern uint8 RTG_IsAncestor( uint16 deviceAddress );
  171. extern void RTG_SendBrokenRoute( uint16 nwkSrcAddr, uint16 nwkDstAddr,
  172. uint8 srcRouteSet, uint16 macSrcAddr, uint16 macDstAddr );
  173. extern uint16 RTG_CalcTreeAddress( byte deviceType );
  174. extern uint16 RTG_GetStochastic( byte deviceType );
  175. extern uint16 RTG_GetNextTreeHop( uint16 dstAddress );
  176. extern uint16 RTG_ChildGetNextHop( uint16 DstAddr );
  177. extern uint8 RTG_GetAncestors( uint16 dstAddr, uint16 ancestorAddr, uint16 *pRtgDst );
  178. extern void RTG_nextHopIsBad( uint16 nextHop );
  179. extern ZStatus_t RTG_SendRErr( uint16 SrcAddress, uint16 DstAddress, byte ErrorCode );
  180. extern RTG_Status_t RTG_AddSrcRtgEntry_Guaranteed( uint16 srcAddr, uint8 relayCnt, uint16* pRelayList );
  181. // Functions pointers for addressing schemes
  182. extern uint16 (*pRTG_FinishGetNextHop)( uint16 DstAddress );
  183. extern uint16 (*pRTG_GetNextTreeHop)( uint16 dstAddress );
  184. extern uint16 (*pRTG_CalcAddress)( byte deviceType );
  185. extern uint16 (*pRTG_GetTreeRoute)(uint16 dstAddress );
  186. extern void (*pRTG_DeAllocAddress)( uint16 shortAddr );
  187. extern uint8 (*pRTG_GetAncestors)( uint16 dstAddr, uint16 ancestorAddr, uint16 *pRtgDst );
  188. extern void RTG_initRtgTable( void );
  189. extern void RTG_MTORouteReq(void);
  190. /*********************************************************************
  191. *********************************************************************/
  192. #ifdef __cplusplus
  193. }
  194. #endif
  195. #endif /* RTG_H */