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.

210 lines
6.3 KiB

  1. #include <precomp.h>
  2. #include "ErrCtrl.h"
  3. #include "wzcutil.h"
  4. // "wzctool s"; args = "{guid} param value"
  5. // sets the value for any of the params
  6. void cmdS(int argc, char *argv[])
  7. {
  8. DWORD rpcStatus = RPC_S_OK;
  9. INTF_ENTRY Intf;
  10. DWORD dwFlags = 0;
  11. if (argc < 2 || (argc < 3 && _stricmp(argv[1], "sc")))
  12. {
  13. printf("usage: wzctool s guid {im|am|ws|ssid|bssid|cm|awk|rwk} value");
  14. return;
  15. }
  16. ZeroMemory(&Intf, sizeof(INTF_ENTRY));
  17. Intf.wszGuid = RpcCAlloc(sizeof(WCHAR)*strlen(argv[0])+1);
  18. wsprintf(Intf.wszGuid, L"%S", argv[0]);
  19. Intf.wszDescr = NULL;
  20. if (!_stricmp(argv[1],"im"))
  21. {
  22. Intf.nInfraMode = atoi(argv[2]);
  23. dwFlags |= INTF_INFRAMODE;
  24. printf("setting INFRASTRUCTURE_MODE %d.\n",
  25. Intf.nInfraMode);
  26. }
  27. else if (!_stricmp(argv[1],"am"))
  28. {
  29. Intf.nAuthMode = atoi(argv[2]);
  30. dwFlags |= INTF_AUTHMODE;
  31. printf("setting AUTHENTICATION_MODE %d.\n",
  32. Intf.nAuthMode);
  33. }
  34. else if (!_stricmp(argv[1], "ws"))
  35. {
  36. Intf.nWepStatus = atoi(argv[2]);
  37. dwFlags |= INTF_WEPSTATUS;
  38. printf("setting WEPSTATUS %d.\n",
  39. Intf.nWepStatus);
  40. }
  41. else if (!_stricmp(argv[1], "ssid"))
  42. {
  43. Intf.rdSSID.dwDataLen = strlen(argv[2]);
  44. Intf.rdSSID.pData = (LPBYTE)RpcCAlloc(Intf.rdSSID.dwDataLen);
  45. CopyMemory(Intf.rdSSID.pData, argv[2], Intf.rdSSID.dwDataLen);
  46. dwFlags |= INTF_SSID;
  47. }
  48. else if (!_stricmp(argv[1], "bssid"))
  49. {
  50. LPSTR pHdwByte, pHdwTerm;
  51. INT i = 0;
  52. Intf.rdBSSID.dwDataLen = 6;
  53. Intf.rdBSSID.pData = (LPBYTE)RpcCAlloc(Intf.rdBSSID.dwDataLen);
  54. pHdwByte = argv[2];
  55. do
  56. {
  57. pHdwTerm = strchr(pHdwByte, ':');
  58. if (pHdwTerm)
  59. *pHdwTerm = '\0';
  60. Intf.rdBSSID.pData[i++] = (BYTE)atoi(pHdwByte);
  61. if (pHdwTerm)
  62. *pHdwTerm = ':';
  63. pHdwByte = pHdwTerm+1;
  64. } while(i < 6 && pHdwTerm != NULL);
  65. dwFlags |= INTF_BSSID;
  66. }
  67. else if (!_stricmp(argv[1], "cm"))
  68. {
  69. Intf.dwCtlFlags = atoi(argv[2]);
  70. dwFlags |= INTF_ALL_FLAGS;
  71. printf("setting CONFIGURATION_MODE 0x%08x.\n",
  72. Intf.dwCtlFlags);
  73. }
  74. else if (!_stricmp(argv[1], "awk"))
  75. {
  76. BOOL bOk = TRUE;
  77. LPSTR pszTransmit = NULL, pszIndex, pszMaterial;
  78. DWORD dwKeyIndex = 0;
  79. pszMaterial = strrchr(argv[2], ':');
  80. if (pszMaterial != NULL)
  81. {
  82. *pszMaterial = '\0';
  83. pszMaterial++;
  84. pszIndex = strrchr(argv[2], ':');
  85. if (pszIndex != NULL)
  86. {
  87. *pszIndex = '\0';
  88. pszIndex++;
  89. pszTransmit = argv[2];
  90. }
  91. else
  92. {
  93. pszIndex = argv[2];
  94. }
  95. }
  96. else
  97. {
  98. pszMaterial = argv[2];
  99. }
  100. if (pszTransmit != NULL)
  101. dwKeyIndex = (_stricmp(pszTransmit,"t") == 0) ? 0x80000000 : 0;
  102. if (pszIndex != NULL)
  103. dwKeyIndex += atoi(pszIndex);
  104. if (*pszMaterial != '\0')
  105. {
  106. // we assume the key material is represented as hex digits, hence we need to allocate
  107. // as many bytes as half of its length. Also, keep in mind NDIS_802_11_WEP provides
  108. // one byte for the key material;
  109. Intf.rdCtrlData.dwDataLen = sizeof(NDIS_802_11_WEP) + (strlen(pszMaterial)+1)/2 - 1;
  110. Intf.rdCtrlData.pData = (LPBYTE)RpcCAlloc(Intf.rdCtrlData.dwDataLen);
  111. if (Intf.rdCtrlData.pData != NULL)
  112. {
  113. BYTE btKeyByte = 0;
  114. PNDIS_802_11_WEP pndWepKey = (PNDIS_802_11_WEP)Intf.rdCtrlData.pData;
  115. UINT i = 0;
  116. pndWepKey->Length = Intf.rdCtrlData.dwDataLen;
  117. pndWepKey->KeyLength = (strlen(pszMaterial)+1)/2;
  118. pndWepKey->KeyIndex = dwKeyIndex;
  119. while (isxdigit(*pszMaterial))
  120. {
  121. pndWepKey->KeyMaterial[i] = HEX(*pszMaterial) << 4;
  122. pszMaterial++;
  123. if (!isxdigit(*pszMaterial))
  124. break;
  125. pndWepKey->KeyMaterial[i++] |= HEX(*pszMaterial);
  126. pszMaterial++;
  127. }
  128. if (*pszMaterial == '\0')
  129. {
  130. printf("Adding WEP key Index:0x%08x Length:%d Material:",
  131. pndWepKey->KeyIndex,
  132. pndWepKey->KeyLength);
  133. for (i = 0; i < pndWepKey->KeyLength; i++)
  134. {
  135. printf("%02x", pndWepKey->KeyMaterial[i]);
  136. }
  137. printf("\n");
  138. dwFlags |= INTF_ADDWEPKEY;
  139. }
  140. else
  141. {
  142. printf("Incorrect key material. Use sequence of hexadecimal digits\n");
  143. }
  144. }
  145. else
  146. {
  147. printf("Out of memory!");
  148. }
  149. }
  150. else
  151. {
  152. printf("Missing key material. Use \"[[t:]key_index:]key_material\" syntax.\n");
  153. }
  154. }
  155. else if (!_stricmp(argv[1], "rwk"))
  156. {
  157. Intf.rdCtrlData.dwDataLen = sizeof(NDIS_802_11_WEP);
  158. Intf.rdCtrlData.pData = (LPBYTE)RpcCAlloc(Intf.rdCtrlData.dwDataLen);
  159. if (Intf.rdCtrlData.pData != NULL)
  160. {
  161. PNDIS_802_11_WEP pndWepKey = (PNDIS_802_11_WEP)Intf.rdCtrlData.pData;
  162. pndWepKey->Length = Intf.rdCtrlData.dwDataLen;
  163. pndWepKey->KeyIndex = atoi(argv[2]);
  164. printf("Removing WEP key %d.\n", pndWepKey->KeyIndex);
  165. dwFlags |= INTF_REMWEPKEY;
  166. }
  167. else
  168. {
  169. printf("Out of memory!");
  170. }
  171. }
  172. else
  173. {
  174. printf("Invalid interface setting \"%s\".\n", argv[1]);
  175. return;
  176. }
  177. rpcStatus = WZCSetInterface(
  178. NULL,
  179. dwFlags,
  180. &Intf,
  181. &dwFlags);
  182. printf("dwOutFlags = 0x%x\n", dwFlags);
  183. if (rpcStatus != RPC_S_OK)
  184. {
  185. printf("call failed with rpcStatus=%d\n", rpcStatus);
  186. }
  187. else
  188. {
  189. printf("call succeeded.\n");
  190. }
  191. WZCDeleteIntfObj(&Intf);
  192. }