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.

261 lines
6.0 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. loopmgr.c
  5. Abstract:
  6. This module contains all of the code to drive the
  7. Loop Manager of Wireless Policy .
  8. Author:
  9. abhisheV 30-September-1999
  10. Environment
  11. User Level: Win32
  12. Revision History:
  13. --*/
  14. #include "precomp.h"
  15. enum {
  16. //SERVICE_STOP_EVENT = 0,
  17. //INTERFACE_CHANGE_EVENT,
  18. //NEW_LOCAL_POLICY_EVENT,
  19. NEW_DS_POLICY_EVENT,
  20. FORCED_POLICY_RELOAD_EVENT,
  21. POLICY_ENGINE_STOP_EVENT,
  22. REAPPLY_POLICY_801X,
  23. WAIT_EVENT_COUNT
  24. };
  25. DWORD
  26. ServiceStart(LPVOID lparam
  27. )
  28. {
  29. DWORD dwError = 0;
  30. HANDLE hWaitForEvents[WAIT_EVENT_COUNT];
  31. BOOL bDoneWaiting = FALSE;
  32. DWORD dwWaitMilliseconds = 0;
  33. DWORD dwStatus = 0;
  34. time_t LastTimeOutTime = 0;
  35. /* Check for DS Policy Now */
  36. _WirelessDbg(TRC_TRACK, "Updating with DS Policy ");
  37. OnPolicyChanged(
  38. gpWirelessPolicyState
  39. );
  40. hWaitForEvents[NEW_DS_POLICY_EVENT] = ghNewDSPolicyEvent;
  41. hWaitForEvents[FORCED_POLICY_RELOAD_EVENT] = ghForcedPolicyReloadEvent;
  42. hWaitForEvents[POLICY_ENGINE_STOP_EVENT] = ghPolicyEngineStopEvent;
  43. hWaitForEvents[REAPPLY_POLICY_801X] = ghReApplyPolicy8021x;
  44. ComputeRelativePollingTime(
  45. LastTimeOutTime,
  46. TRUE,
  47. &dwWaitMilliseconds
  48. );
  49. time(&LastTimeOutTime);
  50. _WirelessDbg(TRC_TRACK, "Timeout period is %d ",dwWaitMilliseconds);
  51. while (!bDoneWaiting) {
  52. gdwPolicyLoopStarted = 1;
  53. dwStatus = WaitForMultipleObjects(
  54. WAIT_EVENT_COUNT,
  55. hWaitForEvents,
  56. FALSE,
  57. dwWaitMilliseconds
  58. );
  59. /*
  60. PADeleteInUsePolicies();
  61. */
  62. switch (dwStatus) {
  63. case POLICY_ENGINE_STOP_EVENT:
  64. dwError = ERROR_SUCCESS;
  65. bDoneWaiting = TRUE;
  66. _WirelessDbg(TRC_TRACK, "Policy Engine Stopping ");
  67. break;
  68. case REAPPLY_POLICY_801X:
  69. _WirelessDbg(TRC_TRACK, "ReApplying the 8021X Policy ");
  70. // Appropriate call for 8021x policy addition.
  71. if (gpWirelessPolicyState->dwCurrentState != POLL_STATE_INITIAL) {
  72. AddEapolPolicy(gpWirelessPolicyState->pWirelessPolicyData);
  73. }
  74. ResetEvent(ghReApplyPolicy8021x);
  75. break;
  76. case NEW_DS_POLICY_EVENT:
  77. _WirelessDbg(TRC_TRACK, "Got a new DS policy event ");
  78. _WirelessDbg(TRC_NOTIF, "DBASE:Wireless Policy - Group Policy indication from WinLogon ");
  79. ResetEvent(ghNewDSPolicyEvent);
  80. (VOID) OnPolicyChanged(
  81. gpWirelessPolicyState
  82. );
  83. break;
  84. case FORCED_POLICY_RELOAD_EVENT:
  85. ResetEvent(ghForcedPolicyReloadEvent);
  86. (VOID) OnPolicyChanged(
  87. gpWirelessPolicyState
  88. );
  89. break;
  90. case WAIT_TIMEOUT:
  91. time(&LastTimeOutTime);
  92. _WirelessDbg(TRC_TRACK, "Timed out ");
  93. (VOID) OnPolicyPoll(
  94. gpWirelessPolicyState
  95. );
  96. break;
  97. case WAIT_FAILED:
  98. dwError = GetLastError();
  99. bDoneWaiting = TRUE;
  100. break;
  101. default:
  102. dwError = ERROR_INVALID_EVENT_COUNT;
  103. bDoneWaiting = TRUE;
  104. break;
  105. }
  106. ComputeRelativePollingTime(
  107. LastTimeOutTime,
  108. FALSE,
  109. &dwWaitMilliseconds
  110. );
  111. }
  112. return (dwError);
  113. }
  114. VOID
  115. ComputeRelativePollingTime(
  116. time_t LastTimeOutTime,
  117. BOOL bInitialLoad,
  118. PDWORD pWaitMilliseconds
  119. )
  120. {
  121. DWORD WaitMilliseconds = 0;
  122. DWORD DSReconnectMilliseconds = 0;
  123. time_t NextTimeOutTime = 0;
  124. time_t PresentTime = 0;
  125. long WaitSeconds = gDefaultPollingInterval;
  126. WaitMilliseconds = gCurrentPollingInterval * 1000;
  127. if (!WaitMilliseconds) {
  128. WaitMilliseconds = INFINITE;
  129. }
  130. DSReconnectMilliseconds = gdwDSConnectivityCheck*60*1000;
  131. if ((gpWirelessPolicyState->dwCurrentState != POLL_STATE_DS_DOWNLOADED) &&
  132. (gpWirelessPolicyState->dwCurrentState != POLL_STATE_LOCAL_DOWNLOADED)) {
  133. if (WaitMilliseconds > DSReconnectMilliseconds) {
  134. WaitMilliseconds = DSReconnectMilliseconds;
  135. }
  136. }
  137. if (!bInitialLoad && WaitMilliseconds != INFINITE) {
  138. //
  139. // LastTimeOutTime is the snapshot time value in the past when
  140. // we timed out waiting for multiple events.
  141. // Ideally, the time for the next time out, NextTimeOutTime, is
  142. // the time value in future which is sum of the last time when
  143. // we timed out + the current waiting time value.
  144. //
  145. NextTimeOutTime = LastTimeOutTime + (WaitMilliseconds/1000);
  146. //
  147. // However, the last time we may not have timed out waiting
  148. // for multiple events but rather came out because one of the
  149. // events other than WAIT_TIMEOUT happened.
  150. // However, on that event we may not have done a policy
  151. // poll to figure out whether there was a policy change or
  152. // not. If we again wait for WaitMilliseconds, then we are
  153. // un-knowingly making our net time for policy poll greater
  154. // than the alloted time interval value = WaitMilliseconds.
  155. // So, we need to adjust the WaitMilliseconds to such a value
  156. // that no matter what happens, we always do a policy poll
  157. // atmost every WaitMilliseconds time interval value.
  158. // The current time is PresentTime.
  159. //
  160. time(&PresentTime);
  161. WaitSeconds = (long) (NextTimeOutTime - PresentTime);
  162. if (WaitSeconds < 0) {
  163. WaitMilliseconds = 0;
  164. }
  165. else {
  166. WaitMilliseconds = WaitSeconds * 1000;
  167. }
  168. }
  169. *pWaitMilliseconds = WaitMilliseconds;
  170. }