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
7.3 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: lanawait.cpp
  4. //
  5. // Module: CMDIAL32.DLL
  6. //
  7. // Synopsis: Implementation for the workaround to make CM wait for DUN to
  8. // register its LANA for an internet connection before beginning
  9. // the tunnel portion of a double dial connection.
  10. //
  11. // Copyright (c) 1996-1999 Microsoft Corporation
  12. //
  13. // Author: quintinb Created Header 08/17/99
  14. //
  15. //+----------------------------------------------------------------------------
  16. #include "cmmaster.h"
  17. const TCHAR* const c_pszCmEntryLanaTimeout = TEXT("LanaTimeout");
  18. //+---------------------------------------------------------------------------
  19. //
  20. // Function: LanaWait
  21. //
  22. // Synopsis: Peform the LANA wait/timeout.
  23. //
  24. // Arguments: pArgs [the ptr to ArgsStruct]
  25. // hwndMainDlg - hwnd of the main dlg
  26. //
  27. // Returns: BOOL TRUE=succes, FALSE=wait not performed.
  28. //
  29. //----------------------------------------------------------------------------
  30. BOOL LanaWait(
  31. ArgsStruct *pArgs,
  32. HWND hwndMainDlg
  33. )
  34. {
  35. BOOL fLanaDone = FALSE;
  36. BOOL fLanaAbort = FALSE;
  37. if (IsLanaWaitEnabled())
  38. {
  39. CMTRACE(TEXT("Performing Lana Wait!!"));
  40. WNDCLASSEX WndClass;
  41. HWND hWnd;
  42. ZeroMemory(&WndClass, sizeof(WNDCLASSEX));
  43. WndClass.cbSize = sizeof(WNDCLASSEX);
  44. WndClass.lpfnWndProc = (WNDPROC)LanaWaitWndProc;
  45. WndClass.hInstance = g_hInst;
  46. WndClass.hIcon = LoadIconU(NULL, IDI_APPLICATION);
  47. WndClass.hCursor = LoadCursorU(NULL, IDC_ARROW);
  48. WndClass.hbrBackground = (HBRUSH)GetStockObject (WHITE_BRUSH);
  49. WndClass.lpszClassName = LANAWAIT_CLASSNAME;
  50. MYVERIFY(RegisterClassExU(&WndClass));
  51. if (!(hWnd = CreateWindowExU(0,
  52. LANAWAIT_CLASSNAME,
  53. LANAWAIT_WNDNAME,
  54. WS_OVERLAPPEDWINDOW,
  55. CW_USEDEFAULT,
  56. CW_USEDEFAULT,
  57. CW_USEDEFAULT,
  58. CW_USEDEFAULT,
  59. (HWND)NULL,
  60. NULL,
  61. g_hInst,
  62. (LPVOID)pArgs)))
  63. {
  64. CMTRACE1(TEXT("CreateWindow LANA failed, LE=0x%x"), GetLastError());
  65. }
  66. else
  67. {
  68. MSG msg;
  69. ZeroMemory(&msg, sizeof(MSG));
  70. while (GetMessageU(&msg, NULL, 0, 0))
  71. {
  72. //
  73. // Since we have no accelerators, no need to call
  74. // TranslateAccelerator here.
  75. //
  76. TranslateMessage(&msg);
  77. DispatchMessageU(&msg);
  78. //
  79. // If we received a msg from the top-level
  80. // window, then the dial is being canceled
  81. //
  82. if (pArgs->uLanaMsgId == msg.message)
  83. {
  84. fLanaAbort = TRUE;
  85. DestroyWindow(hWnd); //break;
  86. }
  87. }
  88. UnregisterClassU(LANAWAIT_CLASSNAME, g_hInst);
  89. SetActiveWindow(hwndMainDlg);
  90. //
  91. // once we've run it once, we don't need to run it again
  92. // until after reboot or switch to a different domain.
  93. // it's safe to just run it every time.
  94. //
  95. if (!fLanaAbort)
  96. {
  97. fLanaDone = TRUE;
  98. }
  99. }
  100. }
  101. else
  102. {
  103. CMTRACE(TEXT("Lana Wait is disabled"));
  104. fLanaDone = TRUE;
  105. }
  106. return fLanaDone;
  107. }
  108. //+----------------------------------------------------------------------------
  109. // Function LanaWaitWndProc
  110. //
  111. // Synopsis Window function for the main app. Waits for device change
  112. // message. This funcion will time out if device change is
  113. // not recieived in LANA_TIMEOUT_DEFAULT secs.
  114. //
  115. //-----------------------------------------------------------------------------
  116. LRESULT APIENTRY LanaWaitWndProc(
  117. HWND hWnd,
  118. UINT message,
  119. WPARAM wParam,
  120. LPARAM lParam
  121. )
  122. {
  123. switch (message)
  124. {
  125. case WM_CREATE:
  126. {
  127. UINT uiTimeout = ((ArgsStruct *)((CREATESTRUCT *)lParam)->lpCreateParams)
  128. ->piniService->GPPI(c_pszCmSection, c_pszCmEntryLanaTimeout, LANA_TIMEOUT_DEFAULT);
  129. CMTRACE1(TEXT("Lana timeout time = %u ms"), uiTimeout*1000);
  130. //
  131. // set up the timer
  132. //
  133. SetTimer(hWnd, LANA_TIME_ID, uiTimeout*1000, (TIMERPROC)NULL);
  134. }
  135. break;
  136. //
  137. // This is the message we are waiting for the LANA is registered
  138. //
  139. case WM_DEVICECHANGE:
  140. {
  141. PDEV_BROADCAST_HDR pDev;
  142. PDEV_BROADCAST_NET pNetDev;
  143. CMTRACE(TEXT("Lana - WM_DEVICECHANGE"));
  144. if (wParam == DBT_DEVICEARRIVAL)
  145. {
  146. pDev = (PDEV_BROADCAST_HDR) lParam;
  147. if (pDev->dbch_devicetype != DBT_DEVTYP_NET)
  148. {
  149. break;
  150. }
  151. pNetDev = (PDEV_BROADCAST_NET) pDev;
  152. if (!(pNetDev->dbcn_flags & DBTF_SLOWNET))
  153. {
  154. break;
  155. }
  156. CMTRACE(TEXT("Got Lana registration!!!"));
  157. //
  158. // Must wait for Broadcast to propigate to all windows.
  159. //
  160. KillTimer(hWnd, LANA_TIME_ID);
  161. CMTRACE1(TEXT("Lana propagate time = %u ms"), LANA_PROPAGATE_TIME_DEFAULT*1000);
  162. SetTimer(hWnd, LANA_TIME_ID, LANA_PROPAGATE_TIME_DEFAULT*1000, (TIMERPROC)NULL);
  163. }
  164. }
  165. break;
  166. // If we get this message we timed out on the device change
  167. case WM_TIMER:
  168. if (wParam == LANA_TIME_ID)
  169. {
  170. CMTRACE(TEXT("Killing LANA window..."));
  171. DestroyWindow(hWnd);
  172. }
  173. break;
  174. case WM_DESTROY:
  175. KillTimer(hWnd, LANA_TIME_ID);
  176. PostQuitMessage(0);
  177. break;
  178. default:
  179. return DefWindowProcU(hWnd, message, wParam, lParam);
  180. }
  181. return 0;
  182. }
  183. //+----------------------------------------------------------------------------
  184. // Function IsLanaWaitEnabled
  185. //
  186. // Synopsis Check to see if the lana wait is enabled. It's enabled if
  187. // reg key value has a non-zero value.
  188. //
  189. // Arguments NONE
  190. //
  191. // Return TRUE - enabled
  192. // FALSE - disabled
  193. //
  194. //-----------------------------------------------------------------------------
  195. BOOL IsLanaWaitEnabled()
  196. {
  197. BOOL fLanaWaitEnabled = FALSE;
  198. HKEY hKeyCm;
  199. DWORD dwType;
  200. DWORD dwSize = sizeof(DWORD);
  201. if (RegOpenKeyExU(HKEY_LOCAL_MACHINE,
  202. c_pszRegCmRoot,
  203. 0,
  204. KEY_QUERY_VALUE ,
  205. &hKeyCm) == ERROR_SUCCESS)
  206. {
  207. LONG lResult = RegQueryValueExU(hKeyCm, ICM_REG_LANAWAIT, NULL, &dwType, (BYTE*)&fLanaWaitEnabled, &dwSize);
  208. if ((lResult == ERROR_SUCCESS) && (dwType == REG_DWORD) && (dwSize == sizeof(DWORD)) && fLanaWaitEnabled)
  209. {
  210. fLanaWaitEnabled = TRUE;
  211. }
  212. RegCloseKey(hKeyCm);
  213. }
  214. return fLanaWaitEnabled;
  215. }