Leaked source code of windows server 2003
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.

676 lines
24 KiB

  1. #include <precomp.h>
  2. #include "ErrCtrl.h"
  3. #include "Utils.h"
  4. #include "PrmDescr.h"
  5. #include "CmdFn.h"
  6. #include "Output.h"
  7. //----------------------------------------------------
  8. // Sub command multiplier. If the GUID argument is "*", it
  9. // will apply the command from within pPDData for each of
  10. // the existent NICs. Otherwise, this is a pass through to
  11. // the respective sub command;
  12. DWORD
  13. FnSubCmdMultiplier(PPARAM_DESCR_DATA pPDData)
  14. {
  15. DWORD dwErr = ERROR_SUCCESS;
  16. if (wcscmp(pPDData->wzcIntfEntry.wszGuid, L"*") == 0)
  17. {
  18. UINT i;
  19. INTFS_KEY_TABLE wzcIntfKeyTable = {0, NULL};
  20. dwErr = WZCEnumInterfaces(NULL, &wzcIntfKeyTable);
  21. if (dwErr == ERROR_SUCCESS)
  22. {
  23. for (i = 0; i < wzcIntfKeyTable.dwNumIntfs; i++)
  24. {
  25. MemFree(pPDData->wzcIntfEntry.wszGuid);
  26. pPDData->wzcIntfEntry.wszGuid = wzcIntfKeyTable.pIntfs[i].wszGuid;
  27. OutIntfsHeader(pPDData);
  28. dwErr = pPDData->pfnCommand(pPDData);
  29. OutIntfsTrailer(pPDData, dwErr);
  30. }
  31. RpcFree(wzcIntfKeyTable.pIntfs);
  32. }
  33. }
  34. else
  35. {
  36. dwErr = pPDData->pfnCommand(pPDData);
  37. }
  38. SetLastError(dwErr);
  39. return dwErr;
  40. }
  41. //----------------------------------------------------
  42. // Sub command handler for the "show" the list of wireless NICs command
  43. DWORD
  44. FnSubCmdShowIntfs(PPARAM_DESCR_DATA pPDData)
  45. {
  46. DWORD dwErr = ERROR_SUCCESS;
  47. INTFS_KEY_TABLE wzcIntfKeyTable = {0, NULL};
  48. dwErr = WZCEnumInterfaces(NULL, &wzcIntfKeyTable);
  49. if (dwErr == ERROR_SUCCESS)
  50. {
  51. UINT i;
  52. dwErr = OutNetworkIntfs(pPDData, &wzcIntfKeyTable);
  53. for (i = 0; i < wzcIntfKeyTable.dwNumIntfs; i++)
  54. RpcFree(wzcIntfKeyTable.pIntfs[i].wszGuid);
  55. RpcFree(wzcIntfKeyTable.pIntfs);
  56. }
  57. SetLastError(dwErr);
  58. return dwErr;
  59. }
  60. //----------------------------------------------------
  61. // Sub command handler for the "show=Guid visible|preferred" command
  62. DWORD
  63. FnSubCmdShowNetworks(PPARAM_DESCR_DATA pPDData)
  64. {
  65. DWORD dwErr = ERROR_SUCCESS;
  66. DWORD dwInFlags;
  67. dwInFlags = (pPDData->dwExistingParams & PRM_VISIBLE) ? INTF_BSSIDLIST : INTF_PREFLIST;
  68. dwErr = WZCQueryInterface(
  69. NULL,
  70. _Os(dwInFlags),
  71. &pPDData->wzcIntfEntry,
  72. NULL);
  73. if (dwErr == ERROR_SUCCESS)
  74. {
  75. UINT nRetrieved = 0, nFiltered = 0;
  76. PWZC_802_11_CONFIG_LIST pwzcCfgList;
  77. if (pPDData->dwExistingParams & PRM_VISIBLE)
  78. pwzcCfgList = (PWZC_802_11_CONFIG_LIST)pPDData->wzcIntfEntry.rdBSSIDList.pData;
  79. else
  80. pwzcCfgList = (PWZC_802_11_CONFIG_LIST)pPDData->wzcIntfEntry.rdStSSIDList.pData;
  81. if (pwzcCfgList != NULL)
  82. {
  83. nRetrieved = pwzcCfgList->NumberOfItems;
  84. dwErr = WzcFilterList(
  85. TRUE, // retain the matching configurations
  86. pPDData,
  87. pwzcCfgList);
  88. if (dwErr == ERROR_SUCCESS)
  89. nFiltered = pwzcCfgList->NumberOfItems;
  90. }
  91. if (dwErr == ERROR_SUCCESS)
  92. dwErr = OutNetworkCfgList(pPDData, nRetrieved, nFiltered);
  93. // cleanup data
  94. if (dwErr == ERROR_SUCCESS)
  95. {
  96. RpcFree(pPDData->wzcIntfEntry.rdBSSIDList.pData);
  97. pPDData->wzcIntfEntry.rdBSSIDList.dwDataLen = 0;
  98. pPDData->wzcIntfEntry.rdBSSIDList.pData = NULL;
  99. RpcFree(pPDData->wzcIntfEntry.rdStSSIDList.pData);
  100. pPDData->wzcIntfEntry.rdStSSIDList.dwDataLen = 0;
  101. pPDData->wzcIntfEntry.rdStSSIDList.pData = NULL;
  102. }
  103. }
  104. SetLastError(dwErr);
  105. return dwErr;
  106. }
  107. //----------------------------------------------------
  108. // Sub command handler for the "show=Guid" service settings command
  109. DWORD
  110. FnSubCmdShowSvcParams(PPARAM_DESCR_DATA pPDData)
  111. {
  112. DWORD dwErr = ERROR_SUCCESS;
  113. DWORD dwInFlags = 0;
  114. DWORD dwOutFlags = 0;
  115. // if there is anything specific requested from us
  116. if ((pPDData->dwExistingParams & ~(PRM_SHOW|PRM_FILE)) != 0)
  117. {
  118. if (pPDData->dwExistingParams & PRM_MASK)
  119. dwInFlags |= INTF_CM_MASK;
  120. if (pPDData->dwExistingParams & PRM_ENABLED)
  121. dwInFlags |= INTF_ENABLED;
  122. if (pPDData->dwExistingParams & PRM_SSID)
  123. dwInFlags |= INTF_SSID;
  124. if (pPDData->dwExistingParams & PRM_IM)
  125. dwInFlags |= INTF_INFRAMODE;
  126. if (pPDData->dwExistingParams & PRM_AM)
  127. dwInFlags |= INTF_AUTHMODE;
  128. if (pPDData->dwExistingParams & PRM_PRIV)
  129. dwInFlags |= INTF_WEPSTATUS;
  130. if (pPDData->dwExistingParams & PRM_BSSID)
  131. dwInFlags |= INTF_BSSID;
  132. }
  133. else
  134. {
  135. dwInFlags |= INTF_CM_MASK|INTF_ENABLED|INTF_SSID|INTF_INFRAMODE|INTF_AUTHMODE|INTF_WEPSTATUS|INTF_BSSID;
  136. }
  137. dwErr = WZCQueryInterface(
  138. NULL,
  139. _Os(dwInFlags),
  140. &pPDData->wzcIntfEntry,
  141. &dwOutFlags);
  142. if (dwErr == ERROR_SUCCESS)
  143. {
  144. dwErr = OutSvcParams(pPDData, _Os(dwInFlags), dwOutFlags);
  145. }
  146. SetLastError(dwErr);
  147. return dwErr;
  148. }
  149. //----------------------------------------------------
  150. // Sub command handler for the "add=Guid .." preferred network command
  151. DWORD
  152. FnSubCmdAddPreferred(PPARAM_DESCR_DATA pPDData)
  153. {
  154. DWORD dwErr = ERROR_SUCCESS;
  155. DWORD dwInFlags;
  156. UINT iNew = 0; // index where to place the new network
  157. PWZC_802_11_CONFIG_LIST pwzcCfgList;
  158. UINT nNewCount=1; // gives the new number of preferred networks (if 0=>don't alloc)
  159. dwInFlags = INTF_PREFLIST;
  160. dwErr = WZCQueryInterface(
  161. NULL,
  162. _Os(dwInFlags),
  163. &pPDData->wzcIntfEntry,
  164. NULL);
  165. // if anything went wrong, print out a warning and return with error
  166. if (dwErr != ERROR_SUCCESS)
  167. {
  168. _Wrn(dwErr, L"Failed to retrieve the list of preferred networks.\n");
  169. }
  170. if (dwErr == ERROR_SUCCESS)
  171. {
  172. // if we got a non-null list of preferred networks back, look into it
  173. if (pPDData->wzcIntfEntry.rdStSSIDList.pData != NULL)
  174. {
  175. UINT iAdhocHead;
  176. DWORD dwOrigArgPrmFlags;
  177. pwzcCfgList = (PWZC_802_11_CONFIG_LIST)pPDData->wzcIntfEntry.rdStSSIDList.pData;
  178. iAdhocHead = pwzcCfgList->NumberOfItems;
  179. // trick the flags for WzcConfigHit!
  180. dwOrigArgPrmFlags = pPDData->dwArgumentedParams;
  181. pPDData->dwArgumentedParams = PRM_SSID | PRM_IM;
  182. for (iNew = 0; iNew < pwzcCfgList->NumberOfItems; iNew++)
  183. {
  184. PWZC_WLAN_CONFIG pwzcConfig = &pwzcCfgList->Config[iNew];
  185. // determine the index of the first adhoc network
  186. if (iAdhocHead > iNew && pwzcConfig->InfrastructureMode == Ndis802_11IBSS)
  187. iAdhocHead = iNew;
  188. // look for the indicated network
  189. if (WzcConfigHit(pPDData, pwzcConfig))
  190. break;
  191. }
  192. // restore the flags
  193. pPDData->dwArgumentedParams = dwOrigArgPrmFlags;
  194. // if we didn't go through the whole list, we found a hit.
  195. if (iNew < pwzcCfgList->NumberOfItems)
  196. nNewCount = 0;
  197. else
  198. {
  199. nNewCount = pwzcCfgList->NumberOfItems + 1;
  200. if (pPDData->wzcIntfEntry.nInfraMode == Ndis802_11IBSS)
  201. iNew = iAdhocHead; // if adding an adhoc, insert it as the first adhoc
  202. else
  203. iNew = 0; // if adding an infrastructure, insert it as the very first one
  204. }
  205. }
  206. // if we need to enlarge the list => allocate a new one
  207. if (nNewCount != 0)
  208. {
  209. pwzcCfgList = MemCAlloc(
  210. FIELD_OFFSET(WZC_802_11_CONFIG_LIST, Config) +
  211. nNewCount * sizeof(WZC_WLAN_CONFIG));
  212. if (pwzcCfgList == NULL)
  213. dwErr = GetLastError();
  214. else
  215. {
  216. PWZC_WLAN_CONFIG pwzcNewCfg = &pwzcCfgList->Config[iNew];
  217. pwzcCfgList->NumberOfItems = nNewCount;
  218. pwzcCfgList->Index = nNewCount;
  219. // initialize the new entry with default values
  220. pwzcNewCfg->Length = sizeof(WZC_WLAN_CONFIG);
  221. pwzcNewCfg->InfrastructureMode = Ndis802_11Infrastructure;
  222. pwzcNewCfg->AuthenticationMode = Ndis802_11AuthModeOpen;
  223. // for XPSP, this is a boolean
  224. pwzcNewCfg->Privacy = 1;
  225. }
  226. }
  227. }
  228. // at this point, if everything is good, we should have the new list
  229. // in pwzcCfgList with the new entry initialized already. Should this be
  230. // newly allocated memory, then original entries need to be copied over
  231. if (dwErr == ERROR_SUCCESS)
  232. {
  233. PWZC_802_11_CONFIG_LIST pwzcOrigCfgList;
  234. PWZC_WLAN_CONFIG pwzcNewCfg = &pwzcCfgList->Config[iNew];
  235. pwzcOrigCfgList = (PWZC_802_11_CONFIG_LIST)pPDData->wzcIntfEntry.rdStSSIDList.pData;
  236. if (pwzcOrigCfgList != pwzcCfgList)
  237. {
  238. if (pwzcOrigCfgList != NULL)
  239. {
  240. if (iNew > 0)
  241. {
  242. memcpy(
  243. &pwzcCfgList->Config[0],
  244. &pwzcOrigCfgList->Config[0],
  245. iNew * sizeof(WZC_WLAN_CONFIG));
  246. }
  247. if (iNew < pwzcOrigCfgList->NumberOfItems)
  248. {
  249. memcpy(
  250. &pwzcCfgList->Config[iNew+1],
  251. &pwzcOrigCfgList->Config[iNew],
  252. (pwzcOrigCfgList->NumberOfItems - iNew)*sizeof(WZC_WLAN_CONFIG));
  253. }
  254. // cleanup the original list
  255. MemFree(pwzcOrigCfgList);
  256. }
  257. // place the new one in the INTF_ENTRY
  258. pPDData->wzcIntfEntry.rdStSSIDList.dwDataLen =
  259. FIELD_OFFSET(WZC_802_11_CONFIG_LIST, Config) +
  260. pwzcCfgList->NumberOfItems * sizeof(WZC_WLAN_CONFIG);
  261. pPDData->wzcIntfEntry.rdStSSIDList.pData = (LPBYTE)pwzcCfgList;
  262. }
  263. // if "one time connect" is also required, set it up here
  264. if (pPDData->dwExistingParams & PRM_ONETIME)
  265. pwzcCfgList->Index = iNew;
  266. // the only thing required is to overwrite now the user settings
  267. // copy first the mandatory infrastructure mode
  268. pwzcNewCfg->InfrastructureMode = pPDData->wzcIntfEntry.nInfraMode;
  269. // copy then the mandatory ssid
  270. pwzcNewCfg->Ssid.SsidLength = pPDData->wzcIntfEntry.rdSSID.dwDataLen;
  271. memcpy(&pwzcNewCfg->Ssid.Ssid,
  272. pPDData->wzcIntfEntry.rdSSID.pData,
  273. pwzcNewCfg->Ssid.SsidLength);
  274. if (pPDData->dwArgumentedParams & PRM_IM)
  275. pwzcNewCfg->InfrastructureMode = pPDData->wzcIntfEntry.nInfraMode;
  276. if (pPDData->dwArgumentedParams & PRM_AM)
  277. pwzcNewCfg->AuthenticationMode = pPDData->wzcIntfEntry.nAuthMode;
  278. if (pPDData->dwArgumentedParams & PRM_PRIV)
  279. pwzcNewCfg->Privacy = pPDData->wzcIntfEntry.nWepStatus;
  280. if (pPDData->dwArgumentedParams & PRM_KEY)
  281. {
  282. PNDIS_802_11_WEP pndKey = (PNDIS_802_11_WEP)pPDData->wzcIntfEntry.rdCtrlData.pData;
  283. pwzcNewCfg->KeyIndex = pndKey->KeyIndex;
  284. pwzcNewCfg->KeyLength = pndKey->KeyLength;
  285. memcpy(pwzcNewCfg->KeyMaterial, pndKey->KeyMaterial, pwzcNewCfg->KeyLength);
  286. pwzcNewCfg->dwCtlFlags |= WZCCTL_WEPK_PRESENT;
  287. // on XP RTM we have to scramble the WEP key at this point!
  288. if (IsXPRTM())
  289. {
  290. BYTE chFakeKeyMaterial[] = {0x56, 0x09, 0x08, 0x98, 0x4D, 0x08, 0x11, 0x66, 0x42, 0x03, 0x01, 0x67, 0x66};
  291. UINT i;
  292. for (i = 0; i < WZCCTL_MAX_WEPK_MATERIAL; i++)
  293. pwzcNewCfg->KeyMaterial[i] ^= chFakeKeyMaterial[(7*i)%13];
  294. }
  295. }
  296. else
  297. {
  298. pwzcNewCfg->dwCtlFlags &= ~WZCCTL_WEPK_PRESENT;
  299. }
  300. // if OneX is explictly required, set it here (it has been checked for consistency already)
  301. if (pPDData->dwArgumentedParams & PRM_ONEX)
  302. dwErr = WzcSetOneX(pPDData, pPDData->bOneX);
  303. // if OneX is not explicitly specified and this is a brand new network..
  304. else if (nNewCount != 0)
  305. // disable OneX by default
  306. dwErr = WzcSetOneX(pPDData, FALSE);
  307. // in the case some existing preferred network is being modified and the change doesn't involve
  308. // the "onex" param, then the OneX state is left untouched.
  309. if (dwErr == ERROR_SUCCESS)
  310. {
  311. // all is set, now push this to the service
  312. dwErr = WZCSetInterface(
  313. NULL,
  314. _Os(dwInFlags),
  315. &pPDData->wzcIntfEntry,
  316. NULL);
  317. }
  318. }
  319. if (dwErr == ERROR_SUCCESS)
  320. {
  321. fprintf(pPDData->pfOut, "Done.\n");
  322. }
  323. // cleanup data
  324. if (dwErr == ERROR_SUCCESS)
  325. {
  326. RpcFree(pPDData->wzcIntfEntry.rdStSSIDList.pData);
  327. pPDData->wzcIntfEntry.rdStSSIDList.dwDataLen = 0;
  328. pPDData->wzcIntfEntry.rdStSSIDList.pData = NULL;
  329. }
  330. SetLastError(dwErr);
  331. return dwErr;
  332. }
  333. //----------------------------------------------------
  334. // Sub command handler for the "delete=Guid .." preferred network command
  335. DWORD
  336. FnSubCmdDeletePreferred(PPARAM_DESCR_DATA pPDData)
  337. {
  338. DWORD dwErr = ERROR_SUCCESS;
  339. DWORD dwInFlags;
  340. dwInFlags = INTF_PREFLIST;
  341. dwErr = WZCQueryInterface(
  342. NULL,
  343. _Os(dwInFlags),
  344. &pPDData->wzcIntfEntry,
  345. NULL);
  346. if (dwErr != ERROR_SUCCESS)
  347. {
  348. _Wrn(dwErr, L"Failed to retreive the list of preferred networks.\n");
  349. }
  350. else
  351. {
  352. PWZC_802_11_CONFIG_LIST pwzcCfgList = (PWZC_802_11_CONFIG_LIST)pPDData->wzcIntfEntry.rdStSSIDList.pData;
  353. if (pwzcCfgList == NULL)
  354. fprintf(pPDData->pfOut, "Done: deleted 0 - remaining 0\n");
  355. else
  356. {
  357. UINT nNets = pwzcCfgList->NumberOfItems;
  358. dwErr = WzcFilterList(
  359. FALSE, // retain the non-matching configurations
  360. pPDData,
  361. pwzcCfgList);
  362. if (dwErr == ERROR_SUCCESS)
  363. {
  364. // make final adjustments to the list
  365. pPDData->wzcIntfEntry.rdStSSIDList.dwDataLen =
  366. FIELD_OFFSET(WZC_802_11_CONFIG_LIST, Config) +
  367. pwzcCfgList->NumberOfItems * sizeof(WZC_WLAN_CONFIG);
  368. pwzcCfgList->Index = pwzcCfgList->NumberOfItems;
  369. dwErr = WZCSetInterface(
  370. NULL,
  371. _Os(dwInFlags),
  372. &pPDData->wzcIntfEntry,
  373. NULL);
  374. }
  375. if (dwErr == ERROR_SUCCESS)
  376. {
  377. fprintf(pPDData->pfOut, "Done: deleted %d - remaining %d\n",
  378. nNets - pwzcCfgList->NumberOfItems,
  379. pwzcCfgList->NumberOfItems);
  380. }
  381. }
  382. }
  383. // cleanup data
  384. if (dwErr == ERROR_SUCCESS)
  385. {
  386. RpcFree(pPDData->wzcIntfEntry.rdStSSIDList.pData);
  387. pPDData->wzcIntfEntry.rdStSSIDList.dwDataLen = 0;
  388. pPDData->wzcIntfEntry.rdStSSIDList.pData = NULL;
  389. }
  390. SetLastError(dwErr);
  391. return dwErr;
  392. }
  393. //----------------------------------------------------
  394. // Sub command handler for the "set=Guid .." service settings command
  395. DWORD
  396. FnSubCmdSetSvcParams(PPARAM_DESCR_DATA pPDData)
  397. {
  398. DWORD dwErr = ERROR_SUCCESS;
  399. DWORD dwInFlags;
  400. dwInFlags = 0;
  401. if (pPDData->dwArgumentedParams & PRM_MASK)
  402. dwInFlags |= INTF_CM_MASK;
  403. if (pPDData->dwArgumentedParams & PRM_ENABLED)
  404. dwInFlags |= INTF_ENABLED;
  405. if (dwInFlags != 0)
  406. {
  407. // for RTM, all the control flags are set in one shot. So we need to
  408. // make sure we don't alter anything else but what we're asked for.
  409. if (IsXPRTM())
  410. {
  411. DWORD dwNewFlags;
  412. dwNewFlags = pPDData->wzcIntfEntry.dwCtlFlags;
  413. dwErr = WZCQueryInterface(
  414. NULL,
  415. _Os(INTF_CM_MASK),
  416. &pPDData->wzcIntfEntry,
  417. NULL);
  418. SetLastError(dwErr);
  419. _Asrt(dwErr == ERROR_SUCCESS, L"Backing up current control flags failed with error %d.\n", dwErr);
  420. if (dwInFlags & INTF_CM_MASK)
  421. {
  422. pPDData->wzcIntfEntry.dwCtlFlags &= ~INTFCTL_CM_MASK;
  423. pPDData->wzcIntfEntry.dwCtlFlags |= (dwNewFlags & INTFCTL_CM_MASK);
  424. }
  425. if (dwInFlags & INTF_ENABLED)
  426. {
  427. pPDData->wzcIntfEntry.dwCtlFlags &= ~INTFCTL_ENABLED;
  428. pPDData->wzcIntfEntry.dwCtlFlags |= (dwNewFlags & INTFCTL_ENABLED);
  429. }
  430. }
  431. dwErr = WZCSetInterface(
  432. NULL,
  433. _Os(dwInFlags),
  434. &pPDData->wzcIntfEntry,
  435. NULL);
  436. if (dwErr != ERROR_SUCCESS)
  437. _Wrn(dwErr, L"Failed to set all parameters - %08x <> %08x\n");
  438. }
  439. if (pPDData->dwExistingParams & PRM_REFRESH)
  440. {
  441. DWORD dwLErr;
  442. dwInFlags = INTF_LIST_SCAN;
  443. dwLErr = WZCRefreshInterface(
  444. NULL,
  445. _Os(dwInFlags),
  446. &pPDData->wzcIntfEntry,
  447. NULL);
  448. if (dwLErr != ERROR_SUCCESS)
  449. _Wrn(dwLErr,L"Failed to initiate wireless scan.\n");
  450. if (dwErr == ERROR_SUCCESS)
  451. dwErr = dwLErr;
  452. }
  453. if (dwErr == ERROR_SUCCESS)
  454. fprintf(pPDData->pfOut, "Done.\n");
  455. SetLastError(dwErr);
  456. return dwErr;
  457. }
  458. //=====================================================
  459. //----------------------------------------------------
  460. // Handler for the "show" command
  461. DWORD
  462. FnCmdShow(PPARAM_DESCR_DATA pPDData)
  463. {
  464. DWORD dwErr = ERROR_SUCCESS;
  465. DWORD dwAllowed, dwArgumented;
  466. // The command "show" has two different semantics when used with and without
  467. // argument (Guid).
  468. // If the command has been provided with argument...
  469. if (pPDData->dwArgumentedParams & PRM_SHOW)
  470. {
  471. //.. we need to retrieve the configuration of some NIC
  472. //
  473. // Check whether the request is for global svc parameters or for visible/preferred lists
  474. if ((pPDData->dwExistingParams & (PRM_VISIBLE|PRM_PREFERRED)) == 0)
  475. {
  476. dwArgumented = PRM_SHOW|PRM_FILE;
  477. dwAllowed = dwArgumented|PRM_MASK|PRM_ENABLED|PRM_SSID|PRM_IM|PRM_AM|PRM_PRIV|PRM_BSSID;
  478. // Request is for one the global svc parameters
  479. if ((pPDData->dwExistingParams & ~dwAllowed) != 0)
  480. dwErr = _Err(ERROR_TOO_MANY_NAMES,L"Inconsistent phrase. Some parameters are not service settings.\n");
  481. else if ((pPDData->dwArgumentedParams & ~dwArgumented) != 0)
  482. dwErr = _Err(ERROR_BAD_ARGUMENTS,L"The service settings don't require any value in this context.\n");
  483. else
  484. {
  485. pPDData->pfnCommand = FnSubCmdShowSvcParams;
  486. dwErr = FnSubCmdMultiplier(pPDData);
  487. }
  488. }
  489. else
  490. {
  491. dwArgumented = PRM_SHOW|PRM_SSID|PRM_IM|PRM_AM|PRM_PRIV|PRM_FILE;
  492. // Request is for one of the visible/preferred lists
  493. if (pPDData->dwExistingParams & PRM_VISIBLE)
  494. {
  495. dwArgumented |= PRM_BSSID;
  496. dwAllowed = dwArgumented | PRM_VISIBLE;
  497. }
  498. else
  499. {
  500. dwAllowed = dwArgumented | PRM_PREFERRED;
  501. }
  502. if ((pPDData->dwExistingParams & ~dwAllowed) != 0)
  503. dwErr = _Err(ERROR_TOO_MANY_NAMES,L"Inconsistent phrase. Some of the parameters are not expected for this command.\n");
  504. else if ((pPDData->dwExistingParams & dwArgumented) != (pPDData->dwArgumentedParams & dwArgumented))
  505. dwErr = _Err(ERROR_BAD_ARGUMENTS,L"Value missing for some of the wireless network settings.\n");
  506. else
  507. {
  508. pPDData->pfnCommand = FnSubCmdShowNetworks;
  509. dwErr = FnSubCmdMultiplier(pPDData);
  510. }
  511. }
  512. }
  513. else
  514. {
  515. //.. we need to list the NICs available under WZC control
  516. // This command is incompatible with any other parameters
  517. if ((pPDData->dwExistingParams & ~(PRM_SHOW|PRM_FILE)) != 0)
  518. dwErr = _Err(ERROR_TOO_MANY_NAMES,L"Too many parameters for the generic \"show\" command.\n");
  519. else
  520. dwErr = FnSubCmdShowIntfs(pPDData);
  521. }
  522. SetLastError(dwErr);
  523. return dwErr;
  524. }
  525. //----------------------------------------------------
  526. // Handler for the "add" command
  527. DWORD
  528. FnCmdAdd(PPARAM_DESCR_DATA pPDData)
  529. {
  530. DWORD dwErr = ERROR_SUCCESS;
  531. DWORD dwRequired = PRM_ADD | PRM_SSID | PRM_IM;
  532. DWORD dwArgumented = dwRequired | PRM_AM | PRM_PRIV | PRM_KEY | PRM_ONEX | PRM_FILE;
  533. DWORD dwAllowed = dwArgumented | PRM_ONETIME;
  534. if ((pPDData->dwExistingParams & dwRequired) != dwRequired)
  535. dwErr = _Err(ERROR_NO_DATA,L"Wireless network defined incompletely.\n");
  536. else if ((pPDData->dwExistingParams & dwArgumented) != (pPDData->dwArgumentedParams & dwArgumented))
  537. dwErr = _Err(ERROR_BAD_ARGUMENTS,L"No value provided for some of the wireless network settings.\n");
  538. else if ((pPDData->dwExistingParams & ~dwAllowed) != 0)
  539. dwErr = _Err(ERROR_TOO_MANY_NAMES,L"Inconsistent phrase. Some of the parameters are not expected for this command.\n");
  540. else if ((pPDData->dwArgumentedParams & PRM_ONEX) && (pPDData->bOneX) &&
  541. ((pPDData->wzcIntfEntry.nInfraMode == Ndis802_11IBSS) ||
  542. ((pPDData->dwArgumentedParams & PRM_PRIV) && (pPDData->wzcIntfEntry.nWepStatus == 0))))
  543. dwErr = _Err(ERROR_INVALID_DATA, L"Invalid \"onex\" parameter for the given \"im\" and/or \"priv\".\n");
  544. else
  545. {
  546. pPDData->pfnCommand = FnSubCmdAddPreferred;
  547. dwErr = FnSubCmdMultiplier(pPDData);
  548. }
  549. SetLastError(dwErr);
  550. return dwErr;
  551. }
  552. //----------------------------------------------------
  553. // Handler for the "delete" command
  554. DWORD
  555. FnCmdDelete(PPARAM_DESCR_DATA pPDData)
  556. {
  557. DWORD dwErr = ERROR_SUCCESS;
  558. DWORD dwAllowed = PRM_DELETE | PRM_SSID | PRM_IM | PRM_AM | PRM_PRIV | PRM_FILE;
  559. if ((pPDData->dwExistingParams & ~dwAllowed) != 0)
  560. dwErr = _Err(ERROR_TOO_MANY_NAMES,L"Inconsistent phrase. Some of the parameters are not expected for this command.\n");
  561. else if ((pPDData->dwExistingParams & dwAllowed) != (pPDData->dwArgumentedParams & dwAllowed))
  562. dwErr = _Err(ERROR_BAD_ARGUMENTS,L"Value missing for some of the wireless network settings.\n");
  563. else
  564. {
  565. pPDData->pfnCommand = FnSubCmdDeletePreferred;
  566. dwErr = FnSubCmdMultiplier(pPDData);
  567. }
  568. SetLastError(dwErr);
  569. return dwErr;
  570. }
  571. //----------------------------------------------------
  572. // Handler for the "set" command
  573. DWORD
  574. FnCmdSet(PPARAM_DESCR_DATA pPDData)
  575. {
  576. DWORD dwErr = ERROR_SUCCESS;
  577. DWORD dwArgumented = PRM_SET | PRM_MASK | PRM_ENABLED | PRM_FILE;
  578. DWORD dwAllowed = dwArgumented | PRM_REFRESH;
  579. if ((pPDData->dwExistingParams & ~dwAllowed) != 0)
  580. dwErr = _Err(ERROR_TOO_MANY_NAMES,L"Inconsistent phrase. Some of the parameters are not expected for this command.\n");
  581. else if ((pPDData->dwExistingParams & dwArgumented) != (pPDData->dwArgumentedParams & dwArgumented))
  582. dwErr = _Err(ERROR_BAD_ARGUMENTS,L"Value missing for some of the wireless network settings.\n");
  583. else if ((pPDData->dwExistingParams & dwAllowed) == PRM_SET)
  584. dwErr = _Err(ERROR_NO_DATA,L"Noop: No service parameter provided.\n");
  585. else
  586. {
  587. pPDData->pfnCommand = FnSubCmdSetSvcParams;
  588. dwErr = FnSubCmdMultiplier(pPDData);
  589. }
  590. SetLastError(dwErr);
  591. return dwErr;
  592. }