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.

598 lines
21 KiB

  1. #include "pch.h"
  2. #pragma hdrstop
  3. #include "ncnetcon.h"
  4. #include "ncperms.h"
  5. #include "ncui.h"
  6. #include "lanui.h"
  7. #include "xpsp1res.h"
  8. #include "lanhelp.h"
  9. #include "eapolui.h"
  10. #include "wzcpage.h"
  11. #include "wzcui.h"
  12. #define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
  13. ////////////////////////////////////////////////////////////////////////
  14. // CWZCConfigPage related stuff
  15. //
  16. // g_wszHiddWebK is a string of 26 bullets (0x25cf - the hidden password char) and a NULL
  17. WCHAR g_wszHiddWepK[] = {0x25cf, 0x25cf, 0x25cf, 0x25cf, 0x25cf, 0x25cf, 0x25cf, 0x25cf, 0x25cf, 0x25cf, 0x25cf, 0x25cf, 0x25cf,
  18. 0x25cf, 0x25cf, 0x25cf, 0x25cf, 0x25cf, 0x25cf, 0x25cf, 0x25cf, 0x25cf, 0x25cf, 0x25cf, 0x25cf, 0x25cf, 0x0000};
  19. //+---------------------------------------------------------------------------
  20. // automatically enable/disable state for all the WepK related controls
  21. DWORD
  22. CWZCConfigPage::EnableWepKControls()
  23. {
  24. BOOL bEnable;
  25. // allow changing the Wep Key settings only if they are needed (i.e. privacy and/or shared auth)
  26. // It is so for several reasons:
  27. // - we allow all the params to change, but the SSID & the infra mode (these are
  28. // the key info for a configuration and determines the position of the configuration
  29. // in the preferred list - messing with these involves a whole work to readjust
  30. // the position of the configuration)
  31. // - for the long term future we could allow any params of a configuration to change
  32. // including the key info. This will involve changing the position of this configuration
  33. // in the preferred list, but we should do it some time.
  34. bEnable = (m_dwFlags & WZCDLG_PROPS_RWWEP);
  35. bEnable = bEnable && ((BST_CHECKED == ::SendMessage(m_hwndUsePW, BM_GETCHECK, 0, 0)) ||
  36. (BST_CHECKED == ::SendMessage(m_hwndChkShared, BM_GETCHECK, 0, 0)));
  37. ::EnableWindow(m_hwndUseHardwarePW, bEnable);
  38. bEnable = bEnable && (BST_UNCHECKED == IsDlgButtonChecked(IDC_USEHARDWAREPW));
  39. ::EnableWindow(m_hwndLblKMat, bEnable);
  40. ::EnableWindow(m_hwndEdKMat, bEnable);
  41. ::EnableWindow(m_hwndLblKMat2, bEnable && m_bKMatTouched);
  42. ::EnableWindow(m_hwndEdKMat2, bEnable && m_bKMatTouched);
  43. ::EnableWindow(m_hwndLblKIdx, bEnable);
  44. ::EnableWindow(m_hwndEdKIdx, bEnable);
  45. return ERROR_SUCCESS;
  46. }
  47. //+---------------------------------------------------------------------------
  48. // initializes WEP controls
  49. DWORD
  50. CWZCConfigPage::InitWepKControls()
  51. {
  52. UINT nWepKLen = 0;
  53. // check whether the key is provided automatically or not
  54. CheckDlgButton(IDC_USEHARDWAREPW,
  55. (m_wzcConfig.dwCtlFlags & WZCCTL_WEPK_PRESENT) ? BST_UNCHECKED : BST_CHECKED);
  56. if (m_wzcConfig.KeyLength == 0)
  57. {
  58. nWepKLen = 0;
  59. m_bKMatTouched = TRUE;
  60. }
  61. //--- when a password is to be displayed as hidden chars, don't put in
  62. //--- its actual length, but just 8 bulled chars.
  63. else
  64. {
  65. nWepKLen = 8;
  66. }
  67. g_wszHiddWepK[nWepKLen] = L'\0';
  68. ::SetWindowText(m_hwndEdKMat, g_wszHiddWepK);
  69. ::SetWindowText(m_hwndEdKMat2, g_wszHiddWepK);
  70. g_wszHiddWepK[nWepKLen] = 0x25cf; // Hidden password char (bullet)
  71. // the index edit control shouldn't accept more than exactly one char
  72. ::SendMessage(m_hwndEdKIdx, EM_LIMITTEXT, 1, 0);
  73. // show the current key index, if valid. Otherwise, default to the min valid value.
  74. if (m_wzcConfig.KeyIndex + 1 >= WZC_WEPKIDX_MIN &&
  75. m_wzcConfig.KeyIndex + 1 <= WZC_WEPKIDX_MAX)
  76. {
  77. CHAR szIdx[WZC_WEPKIDX_NDIGITS];
  78. ::SetWindowTextA(m_hwndEdKIdx, _itoa(m_wzcConfig.KeyIndex + 1, szIdx, 10));
  79. }
  80. else
  81. m_wzcConfig.KeyIndex = 0;
  82. return ERROR_SUCCESS;
  83. }
  84. //+---------------------------------------------------------------------------
  85. // checks the validity of the WEP Key material and selects the
  86. // material from the first invalid char (non hexa in hexa format or longer
  87. // than the specified length
  88. DWORD
  89. CWZCConfigPage::CheckWepKMaterial(LPSTR *ppszKMat, DWORD *pdwKeyFlags)
  90. {
  91. DWORD dwErr = ERROR_SUCCESS;
  92. DWORD dwKeyFlags = 0;
  93. UINT nMatLen = ::GetWindowTextLength(m_hwndEdKMat);
  94. LPSTR pszCrtMat = NULL;
  95. UINT nSelIdx = 0;
  96. switch(nMatLen)
  97. {
  98. case WZC_WEPKMAT_40_ASC: // 5 chars
  99. case WZC_WEPKMAT_104_ASC: // 13 chars
  100. case WZC_WEPKMAT_128_ASC: // 16 chars
  101. break;
  102. case WZC_WEPKMAT_40_HEX: // 10 hexadecimal digits
  103. case WZC_WEPKMAT_104_HEX: // 26 hexadecimal digits
  104. case WZC_WEPKMAT_128_HEX: // 32 hexadecimal digits
  105. dwKeyFlags |= WZCCTL_WEPK_XFORMAT;
  106. break;
  107. default:
  108. dwErr = ERROR_BAD_FORMAT;
  109. }
  110. // allocate space for the current key material
  111. if (dwErr == ERROR_SUCCESS)
  112. {
  113. pszCrtMat = new CHAR[nMatLen + 1];
  114. if (pszCrtMat == NULL)
  115. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  116. }
  117. // get the current key material from the edit control
  118. if (dwErr == ERROR_SUCCESS)
  119. {
  120. if (nMatLen != ::GetWindowTextA(m_hwndEdKMat, pszCrtMat, nMatLen+1))
  121. dwErr = GetLastError();
  122. }
  123. // we have now all the data. We should select the text in the Key material
  124. // edit control from the first one of the two:
  125. // - the nNewLen to the end (if the current content exceeds the specified length)
  126. // - the first non hexa digit to the end (if current format is hexa)
  127. if (dwErr == ERROR_SUCCESS && (dwKeyFlags & WZCCTL_WEPK_XFORMAT))
  128. {
  129. UINT nNonXIdx;
  130. for (nNonXIdx = 0; nNonXIdx < nMatLen; nNonXIdx++)
  131. {
  132. if (!isxdigit(pszCrtMat[nNonXIdx]))
  133. {
  134. dwErr = ERROR_BAD_FORMAT;
  135. break;
  136. }
  137. }
  138. }
  139. if (dwErr != ERROR_SUCCESS)
  140. {
  141. ::SetWindowText(m_hwndEdKMat2, L"");
  142. ::SendMessage(m_hwndEdKMat, EM_SETSEL, (WPARAM)0, (LPARAM)-1);
  143. // and set the focus on the key material edit control
  144. ::SetFocus(m_hwndEdKMat);
  145. // clean up whatever memory we allocated since we're not passing it up
  146. if (pszCrtMat != NULL)
  147. delete [] pszCrtMat;
  148. }
  149. else
  150. {
  151. *ppszKMat = pszCrtMat;
  152. *pdwKeyFlags = dwKeyFlags;
  153. }
  154. return dwErr;
  155. }
  156. //+---------------------------------------------------------------------------
  157. // parses & copies the WEP Key material from the parameter into the m_wzcConfig object
  158. // The length should be already the good one, the format is given by m_wzcConfig.dwCtlFlags
  159. // Since we assume a valid key material it means its length is non-zero and it is fitting in
  160. // the configurations key material buffer, and if the formatting is hexadecimal, it
  161. // contains an even number of hexa digits.
  162. DWORD
  163. CWZCConfigPage::CopyWepKMaterial(LPSTR szKMat)
  164. {
  165. BYTE chFakeKeyMaterial[] = {0x56, 0x09, 0x08, 0x98, 0x4D, 0x08, 0x11, 0x66, 0x42, 0x03, 0x01, 0x67, 0x66};
  166. if (m_wzcConfig.dwCtlFlags & WZCCTL_WEPK_XFORMAT)
  167. {
  168. UINT nKMatIdx = 0;
  169. // we know here we have a valid hexadecimal formatting
  170. // this implies the string has an even number of digits
  171. while(*szKMat != '\0')
  172. {
  173. m_wzcConfig.KeyMaterial[nKMatIdx] = HEX(*szKMat) << 4;
  174. szKMat++;
  175. m_wzcConfig.KeyMaterial[nKMatIdx] |= HEX(*szKMat);
  176. szKMat++;
  177. nKMatIdx++;
  178. }
  179. m_wzcConfig.KeyLength = nKMatIdx;
  180. }
  181. else
  182. {
  183. // the key is not in Hex format, so just copy over the bytes
  184. // we know the length is good so no worries about overwritting the buffer
  185. m_wzcConfig.KeyLength = strlen(szKMat);
  186. memcpy(m_wzcConfig.KeyMaterial, szKMat, m_wzcConfig.KeyLength);
  187. }
  188. return ERROR_SUCCESS;
  189. }
  190. //+---------------------------------------------------------------------------
  191. // sets the EAPOL Locked bit
  192. DWORD
  193. CWZCConfigPage::SetEapolAllowedState()
  194. {
  195. if (m_pEapolConfig != NULL)
  196. {
  197. // EAPOL shouldn't be even allowed on networks not requesting privacy or on
  198. // ad hoc networks.
  199. if (BST_UNCHECKED == ::SendMessage(m_hwndUsePW, BM_GETCHECK, 0, 0) ||
  200. BST_CHECKED == ::SendMessage(m_hwndChkAdhoc, BM_GETCHECK, 0, 0))
  201. {
  202. // lock the Eapol configuration page
  203. m_pEapolConfig->m_dwCtlFlags |= EAPOL_CTL_LOCKED;
  204. }
  205. else // for Infrastructure networks requiring privacy..
  206. {
  207. // unlock the Eapol configuration page (users are allowed to enable / disable 802.1X)
  208. m_pEapolConfig->m_dwCtlFlags &= ~EAPOL_CTL_LOCKED;
  209. // if asked to correlate onex state with the presence of an explicit key, fix this here
  210. if (m_dwFlags & WZCDLG_PROPS_ONEX_CHECK)
  211. {
  212. if (BST_CHECKED == ::SendMessage(m_hwndUseHardwarePW, BM_GETCHECK, 0, 0))
  213. m_pEapolConfig->m_EapolIntfParams.dwEapFlags |= EAPOL_ENABLED;
  214. else
  215. m_pEapolConfig->m_EapolIntfParams.dwEapFlags &= ~EAPOL_ENABLED;
  216. }
  217. }
  218. }
  219. return ERROR_SUCCESS;
  220. }
  221. //+---------------------------------------------------------------------------
  222. // class constructor
  223. CWZCConfigPage::CWZCConfigPage(DWORD dwFlags)
  224. {
  225. m_dwFlags = dwFlags;
  226. m_bKMatTouched = FALSE;
  227. m_pEapolConfig = NULL;
  228. ZeroMemory(&m_wzcConfig, sizeof(WZC_WLAN_CONFIG));
  229. m_wzcConfig.Length = sizeof(WZC_WLAN_CONFIG);
  230. m_wzcConfig.InfrastructureMode = Ndis802_11Infrastructure;
  231. m_wzcConfig.Privacy = 1;
  232. }
  233. //+---------------------------------------------------------------------------
  234. // Uploads the configuration into the dialog's internal data
  235. DWORD
  236. CWZCConfigPage::UploadWzcConfig(CWZCConfig *pwzcConfig)
  237. {
  238. // if the configuration being uploaded is already a preferred one, reset the
  239. // ONEX check flag (don't control the ONEX setting since it has already been
  240. // chosen by the user at the moment the configuration was first created)
  241. if (pwzcConfig->m_dwFlags & WZC_DESCR_PREFRD)
  242. m_dwFlags &= ~WZCDLG_PROPS_ONEX_CHECK;
  243. CopyMemory(&m_wzcConfig, &(pwzcConfig->m_wzcConfig), sizeof(WZC_WLAN_CONFIG));
  244. return ERROR_SUCCESS;
  245. }
  246. //+---------------------------------------------------------------------------
  247. // copy a reference to the EAPOL configuration object
  248. DWORD
  249. CWZCConfigPage::UploadEapolConfig(CEapolConfig *pEapolConfig)
  250. {
  251. // this member is never to be freed in this class
  252. m_pEapolConfig = pEapolConfig;
  253. return ERROR_SUCCESS;
  254. }
  255. //+---------------------------------------------------------------------------
  256. // Sets the dialog flags. Returns the entire current set of flags
  257. DWORD
  258. CWZCConfigPage::SetFlags(DWORD dwMask, DWORD dwNewFlags)
  259. {
  260. m_dwFlags &= ~dwMask;
  261. m_dwFlags |= (dwNewFlags & dwMask);
  262. return m_dwFlags;
  263. }
  264. //+---------------------------------------------------------------------------
  265. // INIT_DIALOG handler
  266. LRESULT
  267. CWZCConfigPage::OnInitDialog (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  268. {
  269. DWORD dwStyle;
  270. HRESULT hr = S_OK;
  271. // get all the controls handles
  272. m_hwndEdSSID = GetDlgItem(IDC_WZC_EDIT_SSID);
  273. m_hwndChkAdhoc = GetDlgItem(IDC_ADHOC);
  274. m_hwndChkShared = GetDlgItem(IDC_SHAREDMODE);
  275. m_hwndUsePW = GetDlgItem(IDC_USEPW);
  276. // wep key related controls
  277. m_hwndUseHardwarePW = GetDlgItem(IDC_USEHARDWAREPW);
  278. m_hwndLblKMat = GetDlgItem(IDC_WZC_LBL_KMat);
  279. m_hwndEdKMat = GetDlgItem(IDC_WZC_EDIT_KMat);
  280. m_hwndLblKMat2 = GetDlgItem(IDC_WZC_LBL_KMat2);
  281. m_hwndEdKMat2 = GetDlgItem(IDC_WZC_EDIT_KMat2);
  282. m_hwndLblKIdx = GetDlgItem(IDC_WZC_LBL_KIdx);
  283. m_hwndEdKIdx = GetDlgItem(IDC_WZC_EDIT_KIdx);
  284. // initialize the SSID field with the SSID, if one is given
  285. if (m_wzcConfig.Ssid.SsidLength != 0)
  286. {
  287. // ugly but this is life. In order to convert the SSID to LPWSTR we need a buffer.
  288. // We know an SSID can't exceed 32 chars (see NDIS_802_11_SSID from ntddndis.h) so
  289. // make room for the null terminator and that's it. We could do mem alloc but I'm
  290. // not sure it worth the effort (at runtime).
  291. WCHAR wszSSID[33];
  292. UINT nLenSSID = 0;
  293. // convert the LPSTR (original SSID format) to LPWSTR (needed in List Ctrl)
  294. nLenSSID = MultiByteToWideChar(
  295. CP_ACP,
  296. 0,
  297. (LPCSTR)m_wzcConfig.Ssid.Ssid,
  298. m_wzcConfig.Ssid.SsidLength,
  299. wszSSID,
  300. celems(wszSSID));
  301. if (nLenSSID != 0)
  302. {
  303. wszSSID[nLenSSID] = L'\0';
  304. ::SetWindowText(m_hwndEdSSID, wszSSID);
  305. }
  306. }
  307. // Check the "this network is adhoc" box if neccessary.
  308. ::SendMessage(m_hwndChkAdhoc, BM_SETCHECK, (m_wzcConfig.InfrastructureMode == Ndis802_11IBSS) ? BST_CHECKED : BST_UNCHECKED, 0);
  309. // Check the "Use the network key to access this network" checkbox if necessary
  310. // Checking this corresponds to "Shared" auth mode. Unchecked corresponds to "Open" (dsheldon)
  311. ::SendMessage(m_hwndChkShared, BM_SETCHECK, m_wzcConfig.AuthenticationMode ? BST_CHECKED : BST_UNCHECKED, 0);
  312. // the SSID can't be under any circumstances larger than 32 chars
  313. ::SendMessage(m_hwndEdSSID, EM_LIMITTEXT, 32, 0);
  314. // create the spin control
  315. CreateUpDownControl(
  316. WS_CHILD|WS_VISIBLE|WS_BORDER|UDS_SETBUDDYINT|UDS_ALIGNRIGHT|UDS_NOTHOUSANDS|UDS_ARROWKEYS,
  317. 0, 0, 0, 0,
  318. m_hWnd,
  319. -1,
  320. _Module.GetResourceInstance(),
  321. m_hwndEdKIdx,
  322. WZC_WEPKIDX_MAX,
  323. WZC_WEPKIDX_MIN,
  324. WZC_WEPKIDX_MIN);
  325. ::SendMessage(m_hwndUsePW, BM_SETCHECK, (m_wzcConfig.Privacy == 1) ? BST_CHECKED : BST_UNCHECKED, 0);
  326. // at this point we can say the WEP key is untouched
  327. m_bKMatTouched = FALSE;
  328. // fill in the WepK controls
  329. InitWepKControls();
  330. // enable or disable the controls based on how the dialog is called
  331. ::EnableWindow(m_hwndEdSSID, m_dwFlags & WZCDLG_PROPS_RWSSID);
  332. ::EnableWindow(m_hwndChkAdhoc, m_dwFlags & WZCDLG_PROPS_RWINFR);
  333. ::EnableWindow(m_hwndChkShared, m_dwFlags & WZCDLG_PROPS_RWAUTH);
  334. ::EnableWindow(m_hwndUsePW, m_dwFlags & WZCDLG_PROPS_RWWEP);
  335. // enable or disable all the wep key related controls
  336. EnableWepKControls();
  337. SetEapolAllowedState();
  338. return LresFromHr(hr);
  339. }
  340. //+---------------------------------------------------------------------------
  341. // OK button handler
  342. LRESULT
  343. CWZCConfigPage::OnOK(UINT idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  344. {
  345. UINT nSSIDLen;
  346. CHAR szSSID[33];
  347. DWORD dwKeyFlags = 0;
  348. UINT nKeyIdx;
  349. LPSTR szWepKMat = NULL;
  350. // variables used for prompting the user with warning/error messages
  351. UINT nWarnStringID = 0;
  352. WCHAR wszBuff[48];
  353. m_wzcConfig.Length = sizeof(WZC_WLAN_CONFIG);
  354. // get the basic 802.11 parameters
  355. m_wzcConfig.InfrastructureMode = (BST_CHECKED == ::SendMessage(m_hwndChkAdhoc, BM_GETCHECK, 0, 0)) ? Ndis802_11IBSS : Ndis802_11Infrastructure;
  356. m_wzcConfig.AuthenticationMode = (BST_CHECKED == ::SendMessage(m_hwndChkShared, BM_GETCHECK, 0, 0)) ? Ndis802_11AuthModeShared : Ndis802_11AuthModeOpen;
  357. m_wzcConfig.Privacy = (BYTE) (BST_CHECKED == ::SendMessage(m_hwndUsePW, BM_GETCHECK, 0, 0)) ? 1 : 0;
  358. // get the SSID (max 32 chars)
  359. nSSIDLen = ::GetWindowTextA(
  360. m_hwndEdSSID,
  361. szSSID,
  362. sizeof(szSSID));
  363. m_wzcConfig.Ssid.SsidLength = nSSIDLen;
  364. if (nSSIDLen > 0)
  365. CopyMemory(m_wzcConfig.Ssid.Ssid, szSSID, nSSIDLen);
  366. // mark whether a WEP key is provided (not defaulted) or not (defaulted to whatever the hdw might have)
  367. if (IsDlgButtonChecked(IDC_USEHARDWAREPW))
  368. m_wzcConfig.dwCtlFlags &= ~WZCCTL_WEPK_PRESENT;
  369. else
  370. m_wzcConfig.dwCtlFlags |= WZCCTL_WEPK_PRESENT;
  371. // get the key index in a local variable
  372. wszBuff[0] = L'\0';
  373. ::GetWindowText(m_hwndEdKIdx, wszBuff, sizeof(wszBuff)/sizeof(WCHAR));
  374. nKeyIdx = _wtoi(wszBuff) - 1;
  375. if (nKeyIdx + 1 < WZC_WEPKIDX_MIN || nKeyIdx + 1 > WZC_WEPKIDX_MAX)
  376. {
  377. nWarnStringID = IDS_WZC_KERR_IDX;
  378. nKeyIdx = m_wzcConfig.KeyIndex;
  379. ::SendMessage(m_hwndEdKIdx, EM_SETSEL, 0, -1);
  380. ::SetFocus(m_hwndEdKIdx);
  381. }
  382. // get the key material in a local variable.
  383. // If the key is incorrect, the local storage is not changed.
  384. if (m_bKMatTouched)
  385. {
  386. if (CheckWepKMaterial(&szWepKMat, &dwKeyFlags) != ERROR_SUCCESS)
  387. {
  388. nWarnStringID = IDS_WZC_KERR_MAT;
  389. }
  390. else
  391. {
  392. CHAR szBuff[WZC_WEPKMAT_128_HEX + 1]; // maximum key length
  393. // verify whether the key is confirmed correctly. We do this only if nWarnString is
  394. // 0, which means the key is formatted correctly, hence less than 32 chars.
  395. szBuff[0] = '\0';
  396. ::GetWindowTextA( m_hwndEdKMat2, szBuff, sizeof(szBuff));
  397. if (strcmp(szBuff, szWepKMat) != 0)
  398. {
  399. nWarnStringID = IDS_WZCERR_MISMATCHED_WEPK;
  400. // no wep key to be saved, hence delete whatever was read so far
  401. delete szWepKMat;
  402. szWepKMat = NULL;
  403. ::SetWindowText(m_hwndEdKMat2, L"");
  404. ::SetFocus(m_hwndEdKMat2);
  405. }
  406. }
  407. }
  408. // check whether we actually need the wep key settings entered by the user
  409. if ((m_wzcConfig.AuthenticationMode == Ndis802_11AuthModeOpen && !m_wzcConfig.Privacy) ||
  410. !(m_wzcConfig.dwCtlFlags & WZCCTL_WEPK_PRESENT))
  411. {
  412. // no, we don't actually need the key, so we won't prompt the user if he entered an incorrect
  413. // key material or index. In this case whatever the user entered is simply ignored.
  414. // However, if the user entered a correct index / material, they will be saved.
  415. nWarnStringID = 0;
  416. }
  417. // if there is no error to be prompted, just copy over the key settings (regardless they are needed
  418. // or not).
  419. if (nWarnStringID == 0)
  420. {
  421. m_wzcConfig.KeyIndex = nKeyIdx;
  422. if (szWepKMat != NULL)
  423. {
  424. m_wzcConfig.dwCtlFlags &= ~(WZCCTL_WEPK_XFORMAT);
  425. m_wzcConfig.dwCtlFlags |= dwKeyFlags;
  426. CopyWepKMaterial(szWepKMat);
  427. }
  428. }
  429. else
  430. {
  431. //NcMsgBox(
  432. // WZCGetSPResModule(),
  433. // m_hWnd,
  434. // IDS_LANUI_ERROR_CAPTION,
  435. // nWarnStringID,
  436. // MB_ICONSTOP|MB_OK);
  437. WCHAR pszCaption[256];
  438. WCHAR pszText[1024];
  439. LoadString(WZCGetSPResModule(), IDS_LANUI_ERROR_CAPTION, pszCaption, celems(pszCaption));
  440. LoadString(nWarnStringID == IDS_WZC_KERR_MAT ? WZCGetDlgResModule() : WZCGetSPResModule(),
  441. nWarnStringID == IDS_WZC_KERR_MAT ? 5002 : nWarnStringID,
  442. pszText,
  443. celems(pszText));
  444. ::MessageBox (m_hWnd, pszText, pszCaption, MB_ICONSTOP|MB_OK);
  445. }
  446. if (szWepKMat != NULL)
  447. delete szWepKMat;
  448. bHandled = TRUE;
  449. if (nWarnStringID == 0)
  450. {
  451. return PSNRET_NOERROR;
  452. }
  453. else
  454. {
  455. return PSNRET_INVALID_NOCHANGEPAGE;
  456. }
  457. }
  458. //+---------------------------------------------------------------------------
  459. // Context sensitive help handler
  460. extern const WCHAR c_szNetCfgHelpFile[];
  461. LRESULT
  462. CWZCConfigPage::OnContextMenu(
  463. UINT uMsg,
  464. WPARAM wParam,
  465. LPARAM lParam,
  466. BOOL& fHandled)
  467. {
  468. ::WinHelp(m_hWnd,
  469. c_szNetCfgHelpFile,
  470. HELP_CONTEXTMENU,
  471. (ULONG_PTR)g_aHelpIDs_IDC_WZC_DLG_PROPS);
  472. return 0;
  473. }
  474. LRESULT
  475. CWZCConfigPage::OnHelp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  476. {
  477. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  478. if (HELPINFO_WINDOW == lphi->iContextType)
  479. {
  480. ::WinHelp(static_cast<HWND>(lphi->hItemHandle),
  481. c_szNetCfgHelpFile,
  482. HELP_WM_HELP,
  483. (ULONG_PTR)g_aHelpIDs_IDC_WZC_DLG_PROPS);
  484. }
  485. return 0;
  486. }
  487. //+---------------------------------------------------------------------------
  488. // Handler for enabling/disabling WEP
  489. LRESULT
  490. CWZCConfigPage::OnUsePW(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  491. {
  492. EnableWepKControls();
  493. SetEapolAllowedState();
  494. return 0;
  495. }
  496. //+---------------------------------------------------------------------------
  497. // Handler for enabling controls if the user wants to specify key material (password) explicitly
  498. LRESULT
  499. CWZCConfigPage::OnUseHWPassword(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  500. {
  501. EnableWepKControls();
  502. SetEapolAllowedState();
  503. return 0;
  504. }
  505. //+---------------------------------------------------------------------------
  506. // Handler for detecting changes in the key material
  507. LRESULT
  508. CWZCConfigPage::OnWepKMatCmd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  509. {
  510. if (wNotifyCode == EN_SETFOCUS)
  511. {
  512. if (!m_bKMatTouched)
  513. {
  514. ::SetWindowText(m_hwndEdKMat, L"");
  515. ::SetWindowText(m_hwndEdKMat2, L"");
  516. ::EnableWindow(m_hwndLblKMat2, TRUE);
  517. ::EnableWindow(m_hwndEdKMat2, TRUE);
  518. m_bKMatTouched = TRUE;
  519. }
  520. }
  521. return 0;
  522. }
  523. //+---------------------------------------------------------------------------
  524. LRESULT
  525. CWZCConfigPage::OnCheckEapolAllowed(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  526. {
  527. return SetEapolAllowedState();
  528. }