//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Module Name:
wzctool.cpp
Abstract:
Program to test WZC (wireless zero config) service.
wzctool.exe uses WZC APIs.
Environment:
Revision History:
05/04/2001 - Initial version
06/21/2002 - Added -c option
03/23/2004 - Correcting broken features, adding peap, and other general options
re-wrote for WINDOWS CE.
--*/
#include <windows.h>
#include <stdio.h>
#include <stdarg.h>
#include <eapol.h>
#include <wzcsapi.h>
#include <ntddndis.h>
// utility macro to convert a hexa digit into its value
#define HEX(c) ((c)<='9'?(c)-'0':(c)<='F'?(c)-'A'+0xA:(c)-'a'+0xA)
WCHAR* g_szAuthenticationMode[] =
{
L"Ndis802_11AuthModeOpen",
L"Ndis802_11AuthModeShared",
L"Ndis802_11AuthModeAutoSwitch",
L"Ndis802_11AuthModeWPA",
L"Ndis802_11AuthModeWPAPSK",
L"Ndis802_11AuthModeWPANone",
L"Ndis802_11AuthModeWPA2",
L"Ndis802_11AuthModeWPA2PSK"
};
WCHAR* g_szcPrivacyMode[] =
{
TEXT("Ndis802_11WEPEnabled"),
TEXT("Ndis802_11WEPDisabled"),
TEXT("Ndis802_11WEPKeyAbsent"),
TEXT("Ndis802_11WEPNotSupported"),
TEXT("Ndis802_11Encryption2Enabled"),
TEXT("Ndis802_11Encryption2KeyAbsent"),
TEXT("Ndis802_11Encryption3Enabled"),
TEXT("Ndis802_11Encryption3KeyAbsent")
};
WCHAR g_WirelessCard1[MAX_PATH] = L""; // 1st wireless card found by WZC query
int
WasOption
// look for argument like '-t' or '/t'.
// returns option index
// returns index of argv[] found, -1 if not found
(
IN int argc, // number of args
IN WCHAR* argv[], // arg array
IN WCHAR* szOption // to find ('t')
)
{
for(int i=0; i<argc; i++)
{
if( ((*argv[i] == L'-') || (*argv[i] == L'/')) &&
!wcscmp(argv[i]+1, szOption))
return i;
}
return -1;
} // WasOption()
int
GetOption
// look for argument like '-t 100' or '/t 100'.
// returns index of '100' if option ('t') is found
// returns -1 if not found
(
int argc, // number of args
IN WCHAR* argv[], // arg array
IN WCHAR* pszOption, // to find ('n')
OUT WCHAR** ppszArgument // option value ('100')
)
{
if(!ppszArgument)
return -1;
int i = WasOption(argc, argv, pszOption);
if((i < 0) || ((i+1) >= argc))
{
*ppszArgument = NULL;
return -1;
}
*ppszArgument = argv[i+1];
return i+1;
} // GetOption()
void
ShowTextMessages
(
IN WCHAR **szMsgBlock
)
{
for(WCHAR **sz1=szMsgBlock; *sz1; sz1++)
wprintf(L"%s", *sz1);
}
void
EnumWirelessNetworkCard
// enumerate wireless network cards detected by WZC
(
// arg none
)
{
INTFS_KEY_TABLE IntfsTable;
IntfsTable.dwNumIntfs = 0;
IntfsTable.pIntfs = NULL;
DWORD dwStatus = WZCEnumInterfaces(NULL, &IntfsTable);
if(dwStatus != ERROR_SUCCESS)
{
wprintf(L"WZCEnumInterfaces() error 0x%08X\n", dwStatus);
return;
}
// print the GUIDs
// note that in CE the GUIDs are simply the device instance name
// i.e XWIFI11B1, CISCO1, ISLP21, ...
//
if(!IntfsTable.dwNumIntfs)
{
wprintf(L"system has no wireless card.\n");
return;
}
for(unsigned int i=0; i < IntfsTable.dwNumIntfs; i++)
wprintf(L"wifi-card [%d] = %s\n", i, IntfsTable.pIntfs[i].wszGuid);
LocalFree(IntfsTable.pIntfs); // need to free memory allocated by WZC for us.
} // EnumWirelessNetworkCard
void
GetFirstWirelessNetworkCard
// find the first wireless network cards
// found card name goes to g_WirelessCard1
(
// arg none
)
{
g_WirelessCard1[0] = L'\0';
INTFS_KEY_TABLE IntfsTable;
IntfsTable.dwNumIntfs = 0;
IntfsTable.pIntfs = NULL;
DWORD dwStatus = WZCEnumInterfaces(NULL, &IntfsTable);
if(dwStatus != ERROR_SUCCESS)
{
wprintf(L"WZCEnumInterfaces() error 0x%08X\n", dwStatus);
return;
}
// print the GUIDs
// note that in CE the GUIDs are simply the device instance name
// i.e XWIFI11B1, CISCO1, ISLP2, ...
//
if(!IntfsTable.dwNumIntfs)
{
wprintf(L"system has no wireless card.\n");
return;
}
wcsncpy(g_WirelessCard1, IntfsTable.pIntfs[0].wszGuid, MAX_PATH-1);
wprintf(L"wireless card found: %s\n", g_WirelessCard1);
// need to free memory allocated by WZC for us.
LocalFree(IntfsTable.pIntfs);
} // GetFirstWirelessNetworkCard
void
PrintMacAddress
// some RAW_DATA is a MAC ADDRESS, this function is for printing MAC ADDRESS
(
IN PRAW_DATA prdMAC
)
{
if (prdMAC == NULL || prdMAC->dwDataLen == 0)
wprintf(L"<NULL>");
else if(prdMAC->dwDataLen != 6)
wprintf(L"<INVLID MAC>");
else
{
wprintf(L"%02X:%02X:%02X:%02X:%02X:%02X",
prdMAC->pData[0],
prdMAC->pData[1],
prdMAC->pData[2],
prdMAC->pData[3],
prdMAC->pData[4],
prdMAC->pData[5]);
}
} // PrintMacAddress()
void
PrintSSID
// some RAW_DATA is a SSID, this function is for printing SSID
(
PRAW_DATA prdSSID // RAW SSID data
)
{
if (prdSSID == NULL || prdSSID->dwDataLen == 0)
wprintf(L"<NULL>");
else
{
WCHAR szSsid[33];
for (UINT i = 0; i < prdSSID->dwDataLen; i++)
szSsid[i] = prdSSID->pData[i];
szSsid[i] = L'\0';
wprintf(L"%s", szSsid);
}
} // PrintSSID()
WCHAR g_szSupportedRate[32];// = { L"1", L"2", L"5.5", L"11", L"" }; // Mbit/s
WCHAR*
SupportedRate
// rate values in WCHAR string
(
IN BYTE ucbRawValue
)
{
double fRate = ((double)(ucbRawValue & 0x7F)) * 0.5;
swprintf(g_szSupportedRate, L"%.1f", fRate);
return g_szSupportedRate;
} // SupportedRate()
UINT
ChannelNumber
//
// calculate 802.11b channel number for given frequency
// return 1-14 based on the given ulFrequency_kHz
// return 0 for invalid frequency range
//
// 2412 MHz = ch-1
// 2417 MHz = ch-2
// 2422 MHz = ch-3
// 2427 MHz = ch-4
// 2432 MHz = ch-5
// 2437 MHz = ch-6
// 2442 MHz = ch-7
// 2447 MHz = ch-8
// 2452 MHz = ch-9
// 2457 MHz = ch-10
// 2462 MHz = ch-11
// 2467 MHz = ch-12
// 2472 MHz = ch-13
// 2484 MHz = ch-14
//
(
IN ULONG ulFrequency_kHz // frequency in kHz
)
{
ULONG ulFrequency_MHz = ulFrequency_kHz/1000;
if((2412<=ulFrequency_MHz) && (ulFrequency_MHz<2484))
return ((ulFrequency_MHz-2412)/5)+1;
else if(ulFrequency_MHz==2484)
return 14;
return 0; // invalid channel number
} // ChannelNumber()
void
PrintConfigList
// print WZC configuration list
// used when printing [Available Networks] and [Preferred Networks]
(
PRAW_DATA prdBSSIDList
)
{
if (prdBSSIDList == NULL || prdBSSIDList->dwDataLen == 0)
{
wprintf(L"<NULL> entry.");
}
else