Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

217 lines
4.6 KiB

  1. /*++
  2. Copyright (c) 1997-2001 Microsoft Corporation
  3. Module Name:
  4. timer.h
  5. Abstract:
  6. Contains timer management structures.
  7. Author:
  8. Sanjay Anand (SanjayAn) 26-May-1997
  9. ChunYe
  10. Environment:
  11. Kernel mode
  12. Revision History:
  13. --*/
  14. #ifndef _TIMER_H
  15. #define _TIMER_H
  16. #if DBG
  17. #define atl_signature 'LTA '
  18. #endif // DBG
  19. /*++
  20. ULONG
  21. SECONDS_TO_LONG_TICKS(
  22. IN ULONG Seconds
  23. )
  24. Convert from seconds to "long duration timer ticks"
  25. --*/
  26. #define SECONDS_TO_SUPER_LONG_TICKS(Seconds) ((Seconds)/3600)
  27. /*++
  28. ULONG
  29. SECONDS_TO_LONG_TICKS(
  30. IN ULONG Seconds
  31. )
  32. Convert from seconds to "long duration timer ticks"
  33. --*/
  34. #define SECONDS_TO_LONG_TICKS(Seconds) ((Seconds)/60)
  35. /*++
  36. ULONG
  37. SECONDS_TO_SHORT_TICKS(
  38. IN ULONG Seconds
  39. )
  40. Convert from seconds to "short duration timer ticks"
  41. --*/
  42. #define SECONDS_TO_SHORT_TICKS(Seconds) (Seconds)
  43. /*++
  44. VOID
  45. IPSEC_INIT_SYSTEM_TIMER(
  46. IN PNDIS_TIMER pTimer,
  47. IN PNDIS_TIMER_FUNCTON pFunc,
  48. IN PVOID Context
  49. )
  50. --*/
  51. #define IPSEC_INIT_SYSTEM_TIMER(pTimer, pFunc, Context) \
  52. NdisInitializeTimer(pTimer, (PNDIS_TIMER_FUNCTION)(pFunc), (PVOID)Context)
  53. /*++
  54. VOID
  55. IPSEC_START_SYSTEM_TIMER(
  56. IN PNDIS_TIMER pTimer,
  57. IN UINT PeriodInSeconds
  58. )
  59. --*/
  60. #define IPSEC_START_SYSTEM_TIMER(pTimer, PeriodInSeconds) \
  61. NdisSetTimer(pTimer, (UINT)(PeriodInSeconds * 1000))
  62. /*++
  63. VOID
  64. IPSEC_STOP_SYSTEM_TIMER(
  65. IN PNDIS_TIMER pTimer
  66. )
  67. --*/
  68. #define IPSEC_STOP_SYSTEM_TIMER(pTimer) \
  69. { \
  70. BOOLEAN WasCancelled; \
  71. NdisCancelTimer(pTimer, &WasCancelled); \
  72. }
  73. /*++
  74. BOOLEAN
  75. IPSEC_IS_TIMER_ACTIVE(
  76. IN PIPSEC_TIMER pArpTimer
  77. )
  78. --*/
  79. #define IPSEC_IS_TIMER_ACTIVE(pTmr) ((pTmr)->pTimerList != (PIPSEC_TIMER_LIST)NULL)
  80. /*++
  81. ULONG
  82. IPSEC_GET_TIMER_DURATION(
  83. IN PIPSEC_TIMER pTimer
  84. )
  85. --*/
  86. #define IPSEC_GET_TIMER_DURATION(pTmr) ((pTmr)->Duration)
  87. //
  88. // Timer management using Timing Wheels (adapted from IPSEC)
  89. //
  90. struct _IPSEC_TIMER ;
  91. struct _IPSEC_TIMER_LIST ;
  92. //
  93. // Timeout Handler prototype
  94. //
  95. typedef
  96. VOID
  97. (*IPSEC_TIMEOUT_HANDLER) (
  98. IN struct _IPSEC_TIMER * pTimer,
  99. IN PVOID Context
  100. );
  101. //
  102. // An IPSEC_TIMER structure is used to keep track of each timer
  103. // in the IPSEC module.
  104. //
  105. typedef struct _IPSEC_TIMER {
  106. struct _IPSEC_TIMER * pNextTimer;
  107. struct _IPSEC_TIMER * pPrevTimer;
  108. struct _IPSEC_TIMER * pNextExpiredTimer; // Used to chain expired timers
  109. struct _IPSEC_TIMER_LIST * pTimerList; // NULL iff this timer is inactive
  110. ULONG Duration; // In seconds
  111. ULONG LastRefreshTime;
  112. IPSEC_TIMEOUT_HANDLER TimeoutHandler;
  113. PVOID Context; // To be passed to timeout handler
  114. } IPSEC_TIMER, *PIPSEC_TIMER;
  115. //
  116. // NULL pointer to IPSEC Timer
  117. //
  118. #define NULL_PIPSEC_TIMER ((PIPSEC_TIMER)NULL)
  119. //
  120. // Control structure for a timer wheel. This contains all information
  121. // about the class of timers that it implements.
  122. //
  123. typedef struct _IPSEC_TIMER_LIST {
  124. #if DBG
  125. ULONG atl_sig;
  126. #endif // DBG
  127. PIPSEC_TIMER pTimers; // List of timers
  128. ULONG TimerListSize; // Length of above
  129. ULONG CurrentTick; // Index into above
  130. ULONG TimerCount; // Number of running timers
  131. ULONG MaxTimer; // Max timeout value for this
  132. NDIS_TIMER NdisTimer; // System support
  133. UINT TimerPeriod; // Interval between ticks
  134. PVOID ListContext; // Used as a back pointer to the
  135. // Interface structure
  136. } IPSEC_TIMER_LIST, *PIPSEC_TIMER_LIST;
  137. //
  138. // Timer Classes
  139. //
  140. typedef enum {
  141. IPSEC_CLASS_SHORT_DURATION,
  142. IPSEC_CLASS_LONG_DURATION,
  143. IPSEC_CLASS_SUPER_LONG_DURATION,
  144. IPSEC_CLASS_MAX
  145. } IPSEC_TIMER_CLASS;
  146. //
  147. // Timer configuration.
  148. //
  149. #define IPSEC_MAX_TIMER_SHORT_DURATION (60) // 60 seconds
  150. #define IPSEC_MAX_TIMER_LONG_DURATION (60*60) // 1 hour in secs
  151. #define IPSEC_MAX_TIMER_SUPER_LONG_DURATION (48*3600) // 48 hours in secs
  152. #define IPSEC_SHORT_DURATION_TIMER_PERIOD (1) // 1 second
  153. #define IPSEC_LONG_DURATION_TIMER_PERIOD (1*60) // 1 minute
  154. #define IPSEC_SUPER_LONG_DURATION_TIMER_PERIOD (1*3600) // 1 hour
  155. #define IPSEC_SA_EXPIRY_TIME (1*60) // 1 minute in secs
  156. #define IPSEC_REAPER_TIME (60) // 60 secs
  157. BOOLEAN
  158. IPSecInitTimer(
  159. );
  160. VOID
  161. IPSecStartTimer(
  162. IN PIPSEC_TIMER pTimer,
  163. IN IPSEC_TIMEOUT_HANDLER TimeoutHandler,
  164. IN ULONG SecondsToGo,
  165. IN PVOID Context
  166. );
  167. BOOLEAN
  168. IPSecStopTimer(
  169. IN PIPSEC_TIMER pTimer
  170. );
  171. VOID
  172. IPSecTickHandler(
  173. IN PVOID SystemSpecific1,
  174. IN PVOID Context,
  175. IN PVOID SystemSpecific2,
  176. IN PVOID SystemSpecific3
  177. );
  178. #endif _TIMER_H