Windows Embedded Compact 7获取WIFI热点
2012-05-02 10:53
351 查看
程序运行的环境为Windows embedded compact 7,VS2008
之前一直想采用WZC一类的函数来获得WINCE 7.0中的WIFI相关信息及热点,但一直都无果,后来在查看MSDN才知道Wlan一类的函数在WINCE7.0上可用来实现这些功能。目前暂时用来获取WIFI的相关信息及热点。
具体操作如下:
WlanOpenHandle:打开服务的连接;
WlanEnumInterfaces:枚举当前所有的有效无线网卡;
WlanGetAvailableNetworkList:获取当前可用的网络接口;
WlanFreeMemory:释放进行WlanEnumInterface和WlanGetAvailableNetworkList时分配的空间。
具体代码如下:
[cpp]
view plaincopyprint?
int CwlanwifiDlg::GetWifiAccessPoint()
{
// Declare and initialize variables.
// HANDLE hClient = NULL;
DWORD dwMaxClient = 2; //
DWORD dwCurVersion = 0;
DWORD dwResult = 0;
DWORD dwRetVal = 0;
int iRet = 0;
WCHAR GuidString[39] = {0};
unsigned int i, j, k;
/* variables used for WlanEnumInterfaces */
PWLAN_INTERFACE_INFO_LIST pIfList = NULL;
PWLAN_INTERFACE_INFO pIfInfo = NULL;
PWLAN_AVAILABLE_NETWORK_LIST pBssList = NULL;
PWLAN_AVAILABLE_NETWORK pBssEntry = NULL;
int iRSSI = 0;
dwResult = WlanOpenHandle(dwMaxClient, NULL, &dwCurVersion, &hClient);
if (dwResult != ERROR_SUCCESS) {
RETAILMSG(OUTPUT_LOGMSG,(L"WlanOpenHandle failed with error: %u\r\n", dwResult));
return 1;
// You can use FormatMessage here to find out why the function failed
}
dwResult = WlanEnumInterfaces(hClient, NULL, &pIfList);
if (dwResult != ERROR_SUCCESS)
{
RETAILMSG(OUTPUT_LOGMSG,(L"WlanEnumInterfaces failed with error: %u\r\n", dwResult));
return 1;
// You can use FormatMessage here to find out why the function failed
}
else
{
RETAILMSG(OUTPUT_LOGMSG,(L"Num Entries: %d\r\n", pIfList->dwNumberOfItems));
RETAILMSG(OUTPUT_LOGMSG,(L"Current Index: %d\r\n", pIfList->dwIndex));
for (i = 0; i < (int)pIfList->dwNumberOfItems; i++)
{
pIfInfo = (WLAN_INTERFACE_INFO *) &pIfList->InterfaceInfo[i];
RETAILMSG(OUTPUT_LOGMSG,(L" Interface Index[%u]:\t %lu\r\n", i, i));
iRet = StringFromGUID2(pIfInfo->InterfaceGuid, (LPOLESTR) &GuidString,
sizeof(GuidString)/sizeof(*GuidString));
// For c rather than C++ source code, the above line needs to be
// iRet = StringFromGUID2(&pIfInfo->InterfaceGuid, (LPOLESTR) &GuidString,
// sizeof(GuidString)/sizeof(*GuidString));
if (iRet == 0)
RETAILMSG(OUTPUT_LOGMSG,(L"StringFromGUID2 failed\r\n"));
else
RETAILMSG(OUTPUT_LOGMSG,(L" InterfaceGUID[%d]: %ws\r\n",i, GuidString));
RETAILMSG(OUTPUT_LOGMSG,(L" Interface Description[%d]: %s\r\n", i,
&pIfInfo->strInterfaceDescription));
RETAILMSG(OUTPUT_LOGMSG,(L" Interface State[%d]:\t ", i));
switch (pIfInfo->isState) {
case wlan_interface_state_not_ready:
RETAILMSG(OUTPUT_LOGMSG,(L"Not ready\r\n"));
break;
case wlan_interface_state_connected:
RETAILMSG(OUTPUT_LOGMSG,(L"Connected\r\n"));
break;
case wlan_interface_state_ad_hoc_network_formed:
RETAILMSG(OUTPUT_LOGMSG,(L"First node in a ad hoc network\r\n"));
break;
case wlan_interface_state_disconnecting:
RETAILMSG(OUTPUT_LOGMSG,(L"Disconnecting\r\n"));
break;
case wlan_interface_state_disconnected:
RETAILMSG(OUTPUT_LOGMSG,(L"Not connected\r\n"));
break;
case wlan_interface_state_associating:
RETAILMSG(OUTPUT_LOGMSG,(L"Attempting to associate with a network\r\n"));
break;
case wlan_interface_state_discovering:
RETAILMSG(OUTPUT_LOGMSG,(L"Auto configuration is discovering settings for the network\r\n"));
break;
case wlan_interface_state_authenticating:
RETAILMSG(OUTPUT_LOGMSG,(L"In process of authenticating\r\n"));
break;
default:
RETAILMSG(OUTPUT_LOGMSG,(L"Unknown state %ld\r\n", pIfInfo->isState));
break;
}
RETAILMSG(OUTPUT_LOGMSG,(L"\r\n"));
//获得可用的无线网列表
dwResult = WlanGetAvailableNetworkList(hClient,
&pIfInfo->InterfaceGuid,
0,
NULL,
&pBssList);
if (dwResult != ERROR_SUCCESS)
{
RETAILMSG(OUTPUT_LOGMSG,(L"WlanGetAvailableNetworkList failed with error: %u\r\n",
dwResult));
dwRetVal = 1;
// You can use FormatMessage to find out why the function failed
}
else
{
RETAILMSG(OUTPUT_LOGMSG, (L"WLAN_AVAILABLE_NETWORK_LIST for this interface\r\n"));
RETAILMSG(OUTPUT_LOGMSG,(L"Num Entries: %d\r\n", pBssList->dwNumberOfItems));
for (j = 0; j < pBssList->dwNumberOfItems; j++)
{
pBssEntry = (WLAN_AVAILABLE_NETWORK *)&pBssList->Network[j];
RETAILMSG(OUTPUT_LOGMSG,(L" Profile Name[%u]: %s\r\n", j, &pBssEntry->strProfileName));
RETAILMSG(OUTPUT_LOGMSG,(L" SSID[%u]:\t\t ", j));
if (pBssEntry->dot11Ssid.uSSIDLength == 0)
RETAILMSG(OUTPUT_LOGMSG,(L"\r\n"));
else
{
CString str = _T("");
str = pBssEntry->dot11Ssid.ucSSID;
RETAILMSG(OUTPUT_LOGMSG,(L"%s\r\n", str));
RETAILMSG(OUTPUT_LOGMSG,(L"%s\r\n", &pBssEntry->dot11Ssid.ucSSID));
}
RETAILMSG(OUTPUT_LOGMSG,(L"BSS Network type[%u]:\t ", j));
switch (pBssEntry->dot11BssType)
{
case dot11_BSS_type_infrastructure :
RETAILMSG(OUTPUT_LOGMSG,(L"Infrastructure (%u)\r\n", pBssEntry->dot11BssType));
break;
case dot11_BSS_type_independent:
RETAILMSG(OUTPUT_LOGMSG,(L"Infrastructure (%u)\r\n", pBssEntry->dot11BssType));
break;
default:
RETAILMSG(OUTPUT_LOGMSG,(L"Other (%lu)\r\n", pBssEntry->dot11BssType));
break;
}
RETAILMSG(OUTPUT_LOGMSG,(L" Number of BSSIDs[%u]:\t %u\r\n", j, pBssEntry->uNumberOfBssids));
RETAILMSG(OUTPUT_LOGMSG,(L" Connectable[%u]:\t ", j));
if (pBssEntry->bNetworkConnectable)
RETAILMSG(OUTPUT_LOGMSG,(L"Yes\r\n"));
else
{
RETAILMSG(OUTPUT_LOGMSG,(L"No\r\n"));
RETAILMSG(OUTPUT_LOGMSG,(L" Not connectable WLAN_REASON_CODE value[%u]:\t %u\r\n", j,
pBssEntry->wlanNotConnectableReason));
}
RETAILMSG(OUTPUT_LOGMSG,(L"Number of PHY types supported[%u]:\t %u\r\n", j, pBssEntry->uNumberOfPhyTypes));
if (pBssEntry->wlanSignalQuality == 0)
iRSSI = -100;
else if (pBssEntry->wlanSignalQuality == 100)
iRSSI = -50;
else
iRSSI = -100 + (pBssEntry->wlanSignalQuality/2);
RETAILMSG(OUTPUT_LOGMSG,(L" Signal Quality[%u]:\t %u (RSSI: %i dBm)\r\n", j,
pBssEntry->wlanSignalQuality, iRSSI));
RETAILMSG(OUTPUT_LOGMSG,(L" Security Enabled[%u]:\t ", j));
if (pBssEntry->bSecurityEnabled)
RETAILMSG(OUTPUT_LOGMSG,(L"Yes\r\n"));
else
RETAILMSG(OUTPUT_LOGMSG,(L"No\r\n"));
//身份验证类型
RETAILMSG(OUTPUT_LOGMSG,(L" Default AuthAlgorithm[%u]: ", j));
switch (pBssEntry->dot11DefaultAuthAlgorithm)
{
case DOT11_AUTH_ALGO_80211_OPEN:
RETAILMSG(OUTPUT_LOGMSG,(L"802.11 Open (%u)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
case DOT11_AUTH_ALGO_80211_SHARED_KEY:
RETAILMSG(OUTPUT_LOGMSG,(L"802.11 Shared (%u)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
case DOT11_AUTH_ALGO_WPA:
RETAILMSG(OUTPUT_LOGMSG,(L"WPA (%u)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
case DOT11_AUTH_ALGO_WPA_PSK:
RETAILMSG(OUTPUT_LOGMSG,(L"WPA-PSK (%u)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
case DOT11_AUTH_ALGO_WPA_NONE:
RETAILMSG(OUTPUT_LOGMSG,(L"WPA-None (%u)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
case DOT11_AUTH_ALGO_RSNA:
RETAILMSG(OUTPUT_LOGMSG,(L"RSNA (%u)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
case DOT11_AUTH_ALGO_RSNA_PSK:
RETAILMSG(OUTPUT_LOGMSG,(L"RSNA with PSK(%u)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
default:
RETAILMSG(OUTPUT_LOGMSG,(L"Other (%lu)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
}
//加密类型
RETAILMSG(OUTPUT_LOGMSG,(L" Default CipherAlgorithm[%u]: ", j));
switch (pBssEntry->dot11DefaultCipherAlgorithm)
{
case DOT11_CIPHER_ALGO_NONE:
RETAILMSG(OUTPUT_LOGMSG,(L"None (0x%x)\r\n", pBssEntry->dot11DefaultCipherAlgorithm));
break;
case DOT11_CIPHER_ALGO_WEP40:
RETAILMSG(OUTPUT_LOGMSG,(L"WEP-40 (0x%x)\r\n", pBssEntry->dot11DefaultCipherAlgorithm));
break;
case DOT11_CIPHER_ALGO_TKIP:
RETAILMSG(OUTPUT_LOGMSG,(L"TKIP (0x%x)\r\n", pBssEntry->dot11DefaultCipherAlgorithm));
break;
case DOT11_CIPHER_ALGO_CCMP:
RETAILMSG(OUTPUT_LOGMSG,(L"CCMP (0x%x)\r\n", pBssEntry->dot11DefaultCipherAlgorithm));
break;
case DOT11_CIPHER_ALGO_WEP104:
RETAILMSG(OUTPUT_LOGMSG,(L"WEP-104 (0x%x)\r\n", pBssEntry->dot11DefaultCipherAlgorithm));
break;
case DOT11_CIPHER_ALGO_WEP:
RETAILMSG(OUTPUT_LOGMSG,(L"WEP (0x%x)\r\n", pBssEntry->dot11DefaultCipherAlgorithm));
break;
default:
RETAILMSG(OUTPUT_LOGMSG,(L"Other (0x%x)\r\n", pBssEntry->dot11DefaultCipherAlgorithm));
break;
}
RETAILMSG(OUTPUT_LOGMSG,(L" Flags[%u]:\t 0x%x", j, pBssEntry->dwFlags));
if (pBssEntry->dwFlags)
{
if (pBssEntry->dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED)
RETAILMSG(OUTPUT_LOGMSG,(L" - Currently connected"));
if (pBssEntry->dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED)
RETAILMSG(OUTPUT_LOGMSG,(L" - Has profile"));
}
RETAILMSG(OUTPUT_LOGMSG,(L"\r\n"));
RETAILMSG(OUTPUT_LOGMSG,(L"\r\n"));
}//for (j = 0; j < pBssList->dwNumberOfItems; j++)
}//else 无线网个数
}//for (i = 0; i < (int)pIfList->dwNumberOfItems; i++)
}//else 无线适配器
// 释放空间
if (pBssList != NULL)
{
WlanFreeMemory(pBssList);
pBssList = NULL;
}
if (pIfList != NULL)
{
WlanFreeMemory(pIfList);
pIfList = NULL;
}
return dwRetVal;
}
int CwlanwifiDlg::GetWifiAccessPoint()
{
// Declare and initialize variables.
// HANDLE hClient = NULL;
DWORD dwMaxClient = 2; //
DWORD dwCurVersion = 0;
DWORD dwResult = 0;
DWORD dwRetVal = 0;
int iRet = 0;
WCHAR GuidString[39] = {0};
unsigned int i, j, k;
/* variables used for WlanEnumInterfaces */
PWLAN_INTERFACE_INFO_LIST pIfList = NULL;
PWLAN_INTERFACE_INFO pIfInfo = NULL;
PWLAN_AVAILABLE_NETWORK_LIST pBssList = NULL;
PWLAN_AVAILABLE_NETWORK pBssEntry = NULL;
int iRSSI = 0;
dwResult = WlanOpenHandle(dwMaxClient, NULL, &dwCurVersion, &hClient);
if (dwResult != ERROR_SUCCESS) {
RETAILMSG(OUTPUT_LOGMSG,(L"WlanOpenHandle failed with error: %u\r\n", dwResult));
return 1;
// You can use FormatMessage here to find out why the function failed
}
dwResult = WlanEnumInterfaces(hClient, NULL, &pIfList);
if (dwResult != ERROR_SUCCESS)
{
RETAILMSG(OUTPUT_LOGMSG,(L"WlanEnumInterfaces failed with error: %u\r\n", dwResult));
return 1;
// You can use FormatMessage here to find out why the function failed
}
else
{
RETAILMSG(OUTPUT_LOGMSG,(L"Num Entries: %d\r\n", pIfList->dwNumberOfItems));
RETAILMSG(OUTPUT_LOGMSG,(L"Current Index: %d\r\n", pIfList->dwIndex));
for (i = 0; i < (int)pIfList->dwNumberOfItems; i++)
{
pIfInfo = (WLAN_INTERFACE_INFO *) &pIfList->InterfaceInfo[i];
RETAILMSG(OUTPUT_LOGMSG,(L" Interface Index[%u]:\t %lu\r\n", i, i));
iRet = StringFromGUID2(pIfInfo->InterfaceGuid, (LPOLESTR) &GuidString,
sizeof(GuidString)/sizeof(*GuidString));
// For c rather than C++ source code, the above line needs to be
// iRet = StringFromGUID2(&pIfInfo->InterfaceGuid, (LPOLESTR) &GuidString,
// sizeof(GuidString)/sizeof(*GuidString));
if (iRet == 0)
RETAILMSG(OUTPUT_LOGMSG,(L"StringFromGUID2 failed\r\n"));
else
RETAILMSG(OUTPUT_LOGMSG,(L" InterfaceGUID[%d]: %ws\r\n",i, GuidString));
RETAILMSG(OUTPUT_LOGMSG,(L" Interface Description[%d]: %s\r\n", i,
&pIfInfo->strInterfaceDescription));
RETAILMSG(OUTPUT_LOGMSG,(L" Interface State[%d]:\t ", i));
switch (pIfInfo->isState) {
case wlan_interface_state_not_ready:
RETAILMSG(OUTPUT_LOGMSG,(L"Not ready\r\n"));
break;
case wlan_interface_state_connected:
RETAILMSG(OUTPUT_LOGMSG,(L"Connected\r\n"));
break;
case wlan_interface_state_ad_hoc_network_formed:
RETAILMSG(OUTPUT_LOGMSG,(L"First node in a ad hoc network\r\n"));
break;
case wlan_interface_state_disconnecting:
RETAILMSG(OUTPUT_LOGMSG,(L"Disconnecting\r\n"));
break;
case wlan_interface_state_disconnected:
RETAILMSG(OUTPUT_LOGMSG,(L"Not connected\r\n"));
break;
case wlan_interface_state_associating:
RETAILMSG(OUTPUT_LOGMSG,(L"Attempting to associate with a network\r\n"));
break;
case wlan_interface_state_discovering:
RETAILMSG(OUTPUT_LOGMSG,(L"Auto configuration is discovering settings for the network\r\n"));
break;
case wlan_interface_state_authenticating:
RETAILMSG(OUTPUT_LOGMSG,(L"In process of authenticating\r\n"));
break;
default:
RETAILMSG(OUTPUT_LOGMSG,(L"Unknown state %ld\r\n", pIfInfo->isState));
break;
}
RETAILMSG(OUTPUT_LOGMSG,(L"\r\n"));
//获得可用的无线网列表
dwResult = WlanGetAvailableNetworkList(hClient,
&pIfInfo->InterfaceGuid,
0,
NULL,
&pBssList);
if (dwResult != ERROR_SUCCESS)
{
RETAILMSG(OUTPUT_LOGMSG,(L"WlanGetAvailableNetworkList failed with error: %u\r\n",
dwResult));
dwRetVal = 1;
// You can use FormatMessage to find out why the function failed
}
else
{
RETAILMSG(OUTPUT_LOGMSG, (L"WLAN_AVAILABLE_NETWORK_LIST for this interface\r\n"));
RETAILMSG(OUTPUT_LOGMSG,(L"Num Entries: %d\r\n", pBssList->dwNumberOfItems));
for (j = 0; j < pBssList->dwNumberOfItems; j++)
{
pBssEntry = (WLAN_AVAILABLE_NETWORK *)&pBssList->Network[j];
RETAILMSG(OUTPUT_LOGMSG,(L" Profile Name[%u]: %s\r\n", j, &pBssEntry->strProfileName));
RETAILMSG(OUTPUT_LOGMSG,(L" SSID[%u]:\t\t ", j));
if (pBssEntry->dot11Ssid.uSSIDLength == 0)
RETAILMSG(OUTPUT_LOGMSG,(L"\r\n"));
else
{
CString str = _T("");
str = pBssEntry->dot11Ssid.ucSSID;
RETAILMSG(OUTPUT_LOGMSG,(L"%s\r\n", str));
RETAILMSG(OUTPUT_LOGMSG,(L"%s\r\n", &pBssEntry->dot11Ssid.ucSSID));
}
RETAILMSG(OUTPUT_LOGMSG,(L"BSS Network type[%u]:\t ", j));
switch (pBssEntry->dot11BssType)
{
case dot11_BSS_type_infrastructure :
RETAILMSG(OUTPUT_LOGMSG,(L"Infrastructure (%u)\r\n", pBssEntry->dot11BssType));
break;
case dot11_BSS_type_independent:
RETAILMSG(OUTPUT_LOGMSG,(L"Infrastructure (%u)\r\n", pBssEntry->dot11BssType));
break;
default:
RETAILMSG(OUTPUT_LOGMSG,(L"Other (%lu)\r\n", pBssEntry->dot11BssType));
break;
}
RETAILMSG(OUTPUT_LOGMSG,(L" Number of BSSIDs[%u]:\t %u\r\n", j, pBssEntry->uNumberOfBssids));
RETAILMSG(OUTPUT_LOGMSG,(L" Connectable[%u]:\t ", j));
if (pBssEntry->bNetworkConnectable)
RETAILMSG(OUTPUT_LOGMSG,(L"Yes\r\n"));
else
{
RETAILMSG(OUTPUT_LOGMSG,(L"No\r\n"));
RETAILMSG(OUTPUT_LOGMSG,(L" Not connectable WLAN_REASON_CODE value[%u]:\t %u\r\n", j,
pBssEntry->wlanNotConnectableReason));
}
RETAILMSG(OUTPUT_LOGMSG,(L"Number of PHY types supported[%u]:\t %u\r\n", j, pBssEntry->uNumberOfPhyTypes));
if (pBssEntry->wlanSignalQuality == 0)
iRSSI = -100;
else if (pBssEntry->wlanSignalQuality == 100)
iRSSI = -50;
else
iRSSI = -100 + (pBssEntry->wlanSignalQuality/2);
RETAILMSG(OUTPUT_LOGMSG,(L" Signal Quality[%u]:\t %u (RSSI: %i dBm)\r\n", j,
pBssEntry->wlanSignalQuality, iRSSI));
RETAILMSG(OUTPUT_LOGMSG,(L" Security Enabled[%u]:\t ", j));
if (pBssEntry->bSecurityEnabled)
RETAILMSG(OUTPUT_LOGMSG,(L"Yes\r\n"));
else
RETAILMSG(OUTPUT_LOGMSG,(L"No\r\n"));
//身份验证类型
RETAILMSG(OUTPUT_LOGMSG,(L" Default AuthAlgorithm[%u]: ", j));
switch (pBssEntry->dot11DefaultAuthAlgorithm)
{
case DOT11_AUTH_ALGO_80211_OPEN:
RETAILMSG(OUTPUT_LOGMSG,(L"802.11 Open (%u)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
case DOT11_AUTH_ALGO_80211_SHARED_KEY:
RETAILMSG(OUTPUT_LOGMSG,(L"802.11 Shared (%u)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
case DOT11_AUTH_ALGO_WPA:
RETAILMSG(OUTPUT_LOGMSG,(L"WPA (%u)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
case DOT11_AUTH_ALGO_WPA_PSK:
RETAILMSG(OUTPUT_LOGMSG,(L"WPA-PSK (%u)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
case DOT11_AUTH_ALGO_WPA_NONE:
RETAILMSG(OUTPUT_LOGMSG,(L"WPA-None (%u)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
case DOT11_AUTH_ALGO_RSNA:
RETAILMSG(OUTPUT_LOGMSG,(L"RSNA (%u)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
case DOT11_AUTH_ALGO_RSNA_PSK:
RETAILMSG(OUTPUT_LOGMSG,(L"RSNA with PSK(%u)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
default:
RETAILMSG(OUTPUT_LOGMSG,(L"Other (%lu)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
}
//加密类型
RETAILMSG(OUTPUT_LOGMSG,(L" Default CipherAlgorithm[%u]: ", j));
switch (pBssEntry->dot11DefaultCipherAlgorithm)
{
case DOT11_CIPHER_ALGO_NONE:
RETAILMSG(OUTPUT_LOGMSG,(L"None (0x%x)\r\n", pBssEntry->dot11DefaultCipherAlgorithm));
break;
case DOT11_CIPHER_ALGO_WEP40:
RETAILMSG(OUTPUT_LOGMSG,(L"WEP-40 (0x%x)\r\n", pBssEntry->dot11DefaultCipherAlgorithm));
break;
case DOT11_CIPHER_ALGO_TKIP:
RETAILMSG(OUTPUT_LOGMSG,(L"TKIP (0x%x)\r\n", pBssEntry->dot11DefaultCipherAlgorithm));
break;
case DOT11_CIPHER_ALGO_CCMP:
RETAILMSG(OUTPUT_LOGMSG,(L"CCMP (0x%x)\r\n", pBssEntry->dot11DefaultCipherAlgorithm));
break;
case DOT11_CIPHER_ALGO_WEP104:
RETAILMSG(OUTPUT_LOGMSG,(L"WEP-104 (0x%x)\r\n", pBssEntry->dot11DefaultCipherAlgorithm));
break;
case DOT11_CIPHER_ALGO_WEP:
RETAILMSG(OUTPUT_LOGMSG,(L"WEP (0x%x)\r\n", pBssEntry->dot11DefaultCipherAlgorithm));
break;
default:
RETAILMSG(OUTPUT_LOGMSG,(L"Other (0x%x)\r\n", pBssEntry->dot11DefaultCipherAlgorithm));
break;
}
RETAILMSG(OUTPUT_LOGMSG,(L" Flags[%u]:\t 0x%x", j, pBssEntry->dwFlags));
if (pBssEntry->dwFlags)
{
if (pBssEntry->dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED)
RETAILMSG(OUTPUT_LOGMSG,(L" - Currently connected"));
if (pBssEntry->dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED)
RETAILMSG(OUTPUT_LOGMSG,(L" - Has profile"));
}
RETAILMSG(OUTPUT_LOGMSG,(L"\r\n"));
RETAILMSG(OUTPUT_LOGMSG,(L"\r\n"));
}//for (j = 0; j < pBssList->dwNumberOfItems; j++)
}//else 无线网个数
}//for (i = 0; i < (int)pIfList->dwNumberOfItems; i++)
}//else 无线适配器
// 释放空间
if (pBssList != NULL)
{
WlanFreeMemory(pBssList);
pBssList = NULL;
}
if (pIfList != NULL)
{
WlanFreeMemory(pIfList);
pIfList = NULL;
}
return dwRetVal;
}
需要附加头文件:
#include <wlanapi.h>
#pragma comment(lib, "wlanapi.lib")
定义的宏
//定义输入LOG信息宏
#define OUTPUT_LOGMSG 1
编译时可能会出错,但我把其中出错的地方注释掉,就可以编译了,而且能够得到相应的结果。
修改文件 ntddndis.h 修改如下:
#define NDIS_IF_MAX_STRING_SIZE IF_MAX_STRING_SIZE
line 3958 //typedef IF_COUNTED_STRING NDIS_IF_COUNTED_STRING, *PNDIS_IF_COUNTED_STRING;
#define NDIS_MAX_PHYS_ADDRESS_LENGTH IF_MAX_PHYS_ADDRESS_LENGTH
line 3960 //typedef IF_PHYSICAL_ADDRESS NDIS_IF_PHYSICAL_ADDRESS, *PNDIS_IF_PHYSICAL_ADDRESS;
之前一直想采用WZC一类的函数来获得WINCE 7.0中的WIFI相关信息及热点,但一直都无果,后来在查看MSDN才知道Wlan一类的函数在WINCE7.0上可用来实现这些功能。目前暂时用来获取WIFI的相关信息及热点。
具体操作如下:
WlanOpenHandle:打开服务的连接;
WlanEnumInterfaces:枚举当前所有的有效无线网卡;
WlanGetAvailableNetworkList:获取当前可用的网络接口;
WlanFreeMemory:释放进行WlanEnumInterface和WlanGetAvailableNetworkList时分配的空间。
具体代码如下:
[cpp]
view plaincopyprint?
int CwlanwifiDlg::GetWifiAccessPoint()
{
// Declare and initialize variables.
// HANDLE hClient = NULL;
DWORD dwMaxClient = 2; //
DWORD dwCurVersion = 0;
DWORD dwResult = 0;
DWORD dwRetVal = 0;
int iRet = 0;
WCHAR GuidString[39] = {0};
unsigned int i, j, k;
/* variables used for WlanEnumInterfaces */
PWLAN_INTERFACE_INFO_LIST pIfList = NULL;
PWLAN_INTERFACE_INFO pIfInfo = NULL;
PWLAN_AVAILABLE_NETWORK_LIST pBssList = NULL;
PWLAN_AVAILABLE_NETWORK pBssEntry = NULL;
int iRSSI = 0;
dwResult = WlanOpenHandle(dwMaxClient, NULL, &dwCurVersion, &hClient);
if (dwResult != ERROR_SUCCESS) {
RETAILMSG(OUTPUT_LOGMSG,(L"WlanOpenHandle failed with error: %u\r\n", dwResult));
return 1;
// You can use FormatMessage here to find out why the function failed
}
dwResult = WlanEnumInterfaces(hClient, NULL, &pIfList);
if (dwResult != ERROR_SUCCESS)
{
RETAILMSG(OUTPUT_LOGMSG,(L"WlanEnumInterfaces failed with error: %u\r\n", dwResult));
return 1;
// You can use FormatMessage here to find out why the function failed
}
else
{
RETAILMSG(OUTPUT_LOGMSG,(L"Num Entries: %d\r\n", pIfList->dwNumberOfItems));
RETAILMSG(OUTPUT_LOGMSG,(L"Current Index: %d\r\n", pIfList->dwIndex));
for (i = 0; i < (int)pIfList->dwNumberOfItems; i++)
{
pIfInfo = (WLAN_INTERFACE_INFO *) &pIfList->InterfaceInfo[i];
RETAILMSG(OUTPUT_LOGMSG,(L" Interface Index[%u]:\t %lu\r\n", i, i));
iRet = StringFromGUID2(pIfInfo->InterfaceGuid, (LPOLESTR) &GuidString,
sizeof(GuidString)/sizeof(*GuidString));
// For c rather than C++ source code, the above line needs to be
// iRet = StringFromGUID2(&pIfInfo->InterfaceGuid, (LPOLESTR) &GuidString,
// sizeof(GuidString)/sizeof(*GuidString));
if (iRet == 0)
RETAILMSG(OUTPUT_LOGMSG,(L"StringFromGUID2 failed\r\n"));
else
RETAILMSG(OUTPUT_LOGMSG,(L" InterfaceGUID[%d]: %ws\r\n",i, GuidString));
RETAILMSG(OUTPUT_LOGMSG,(L" Interface Description[%d]: %s\r\n", i,
&pIfInfo->strInterfaceDescription));
RETAILMSG(OUTPUT_LOGMSG,(L" Interface State[%d]:\t ", i));
switch (pIfInfo->isState) {
case wlan_interface_state_not_ready:
RETAILMSG(OUTPUT_LOGMSG,(L"Not ready\r\n"));
break;
case wlan_interface_state_connected:
RETAILMSG(OUTPUT_LOGMSG,(L"Connected\r\n"));
break;
case wlan_interface_state_ad_hoc_network_formed:
RETAILMSG(OUTPUT_LOGMSG,(L"First node in a ad hoc network\r\n"));
break;
case wlan_interface_state_disconnecting:
RETAILMSG(OUTPUT_LOGMSG,(L"Disconnecting\r\n"));
break;
case wlan_interface_state_disconnected:
RETAILMSG(OUTPUT_LOGMSG,(L"Not connected\r\n"));
break;
case wlan_interface_state_associating:
RETAILMSG(OUTPUT_LOGMSG,(L"Attempting to associate with a network\r\n"));
break;
case wlan_interface_state_discovering:
RETAILMSG(OUTPUT_LOGMSG,(L"Auto configuration is discovering settings for the network\r\n"));
break;
case wlan_interface_state_authenticating:
RETAILMSG(OUTPUT_LOGMSG,(L"In process of authenticating\r\n"));
break;
default:
RETAILMSG(OUTPUT_LOGMSG,(L"Unknown state %ld\r\n", pIfInfo->isState));
break;
}
RETAILMSG(OUTPUT_LOGMSG,(L"\r\n"));
//获得可用的无线网列表
dwResult = WlanGetAvailableNetworkList(hClient,
&pIfInfo->InterfaceGuid,
0,
NULL,
&pBssList);
if (dwResult != ERROR_SUCCESS)
{
RETAILMSG(OUTPUT_LOGMSG,(L"WlanGetAvailableNetworkList failed with error: %u\r\n",
dwResult));
dwRetVal = 1;
// You can use FormatMessage to find out why the function failed
}
else
{
RETAILMSG(OUTPUT_LOGMSG, (L"WLAN_AVAILABLE_NETWORK_LIST for this interface\r\n"));
RETAILMSG(OUTPUT_LOGMSG,(L"Num Entries: %d\r\n", pBssList->dwNumberOfItems));
for (j = 0; j < pBssList->dwNumberOfItems; j++)
{
pBssEntry = (WLAN_AVAILABLE_NETWORK *)&pBssList->Network[j];
RETAILMSG(OUTPUT_LOGMSG,(L" Profile Name[%u]: %s\r\n", j, &pBssEntry->strProfileName));
RETAILMSG(OUTPUT_LOGMSG,(L" SSID[%u]:\t\t ", j));
if (pBssEntry->dot11Ssid.uSSIDLength == 0)
RETAILMSG(OUTPUT_LOGMSG,(L"\r\n"));
else
{
CString str = _T("");
str = pBssEntry->dot11Ssid.ucSSID;
RETAILMSG(OUTPUT_LOGMSG,(L"%s\r\n", str));
RETAILMSG(OUTPUT_LOGMSG,(L"%s\r\n", &pBssEntry->dot11Ssid.ucSSID));
}
RETAILMSG(OUTPUT_LOGMSG,(L"BSS Network type[%u]:\t ", j));
switch (pBssEntry->dot11BssType)
{
case dot11_BSS_type_infrastructure :
RETAILMSG(OUTPUT_LOGMSG,(L"Infrastructure (%u)\r\n", pBssEntry->dot11BssType));
break;
case dot11_BSS_type_independent:
RETAILMSG(OUTPUT_LOGMSG,(L"Infrastructure (%u)\r\n", pBssEntry->dot11BssType));
break;
default:
RETAILMSG(OUTPUT_LOGMSG,(L"Other (%lu)\r\n", pBssEntry->dot11BssType));
break;
}
RETAILMSG(OUTPUT_LOGMSG,(L" Number of BSSIDs[%u]:\t %u\r\n", j, pBssEntry->uNumberOfBssids));
RETAILMSG(OUTPUT_LOGMSG,(L" Connectable[%u]:\t ", j));
if (pBssEntry->bNetworkConnectable)
RETAILMSG(OUTPUT_LOGMSG,(L"Yes\r\n"));
else
{
RETAILMSG(OUTPUT_LOGMSG,(L"No\r\n"));
RETAILMSG(OUTPUT_LOGMSG,(L" Not connectable WLAN_REASON_CODE value[%u]:\t %u\r\n", j,
pBssEntry->wlanNotConnectableReason));
}
RETAILMSG(OUTPUT_LOGMSG,(L"Number of PHY types supported[%u]:\t %u\r\n", j, pBssEntry->uNumberOfPhyTypes));
if (pBssEntry->wlanSignalQuality == 0)
iRSSI = -100;
else if (pBssEntry->wlanSignalQuality == 100)
iRSSI = -50;
else
iRSSI = -100 + (pBssEntry->wlanSignalQuality/2);
RETAILMSG(OUTPUT_LOGMSG,(L" Signal Quality[%u]:\t %u (RSSI: %i dBm)\r\n", j,
pBssEntry->wlanSignalQuality, iRSSI));
RETAILMSG(OUTPUT_LOGMSG,(L" Security Enabled[%u]:\t ", j));
if (pBssEntry->bSecurityEnabled)
RETAILMSG(OUTPUT_LOGMSG,(L"Yes\r\n"));
else
RETAILMSG(OUTPUT_LOGMSG,(L"No\r\n"));
//身份验证类型
RETAILMSG(OUTPUT_LOGMSG,(L" Default AuthAlgorithm[%u]: ", j));
switch (pBssEntry->dot11DefaultAuthAlgorithm)
{
case DOT11_AUTH_ALGO_80211_OPEN:
RETAILMSG(OUTPUT_LOGMSG,(L"802.11 Open (%u)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
case DOT11_AUTH_ALGO_80211_SHARED_KEY:
RETAILMSG(OUTPUT_LOGMSG,(L"802.11 Shared (%u)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
case DOT11_AUTH_ALGO_WPA:
RETAILMSG(OUTPUT_LOGMSG,(L"WPA (%u)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
case DOT11_AUTH_ALGO_WPA_PSK:
RETAILMSG(OUTPUT_LOGMSG,(L"WPA-PSK (%u)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
case DOT11_AUTH_ALGO_WPA_NONE:
RETAILMSG(OUTPUT_LOGMSG,(L"WPA-None (%u)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
case DOT11_AUTH_ALGO_RSNA:
RETAILMSG(OUTPUT_LOGMSG,(L"RSNA (%u)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
case DOT11_AUTH_ALGO_RSNA_PSK:
RETAILMSG(OUTPUT_LOGMSG,(L"RSNA with PSK(%u)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
default:
RETAILMSG(OUTPUT_LOGMSG,(L"Other (%lu)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
}
//加密类型
RETAILMSG(OUTPUT_LOGMSG,(L" Default CipherAlgorithm[%u]: ", j));
switch (pBssEntry->dot11DefaultCipherAlgorithm)
{
case DOT11_CIPHER_ALGO_NONE:
RETAILMSG(OUTPUT_LOGMSG,(L"None (0x%x)\r\n", pBssEntry->dot11DefaultCipherAlgorithm));
break;
case DOT11_CIPHER_ALGO_WEP40:
RETAILMSG(OUTPUT_LOGMSG,(L"WEP-40 (0x%x)\r\n", pBssEntry->dot11DefaultCipherAlgorithm));
break;
case DOT11_CIPHER_ALGO_TKIP:
RETAILMSG(OUTPUT_LOGMSG,(L"TKIP (0x%x)\r\n", pBssEntry->dot11DefaultCipherAlgorithm));
break;
case DOT11_CIPHER_ALGO_CCMP:
RETAILMSG(OUTPUT_LOGMSG,(L"CCMP (0x%x)\r\n", pBssEntry->dot11DefaultCipherAlgorithm));
break;
case DOT11_CIPHER_ALGO_WEP104:
RETAILMSG(OUTPUT_LOGMSG,(L"WEP-104 (0x%x)\r\n", pBssEntry->dot11DefaultCipherAlgorithm));
break;
case DOT11_CIPHER_ALGO_WEP:
RETAILMSG(OUTPUT_LOGMSG,(L"WEP (0x%x)\r\n", pBssEntry->dot11DefaultCipherAlgorithm));
break;
default:
RETAILMSG(OUTPUT_LOGMSG,(L"Other (0x%x)\r\n", pBssEntry->dot11DefaultCipherAlgorithm));
break;
}
RETAILMSG(OUTPUT_LOGMSG,(L" Flags[%u]:\t 0x%x", j, pBssEntry->dwFlags));
if (pBssEntry->dwFlags)
{
if (pBssEntry->dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED)
RETAILMSG(OUTPUT_LOGMSG,(L" - Currently connected"));
if (pBssEntry->dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED)
RETAILMSG(OUTPUT_LOGMSG,(L" - Has profile"));
}
RETAILMSG(OUTPUT_LOGMSG,(L"\r\n"));
RETAILMSG(OUTPUT_LOGMSG,(L"\r\n"));
}//for (j = 0; j < pBssList->dwNumberOfItems; j++)
}//else 无线网个数
}//for (i = 0; i < (int)pIfList->dwNumberOfItems; i++)
}//else 无线适配器
// 释放空间
if (pBssList != NULL)
{
WlanFreeMemory(pBssList);
pBssList = NULL;
}
if (pIfList != NULL)
{
WlanFreeMemory(pIfList);
pIfList = NULL;
}
return dwRetVal;
}
int CwlanwifiDlg::GetWifiAccessPoint()
{
// Declare and initialize variables.
// HANDLE hClient = NULL;
DWORD dwMaxClient = 2; //
DWORD dwCurVersion = 0;
DWORD dwResult = 0;
DWORD dwRetVal = 0;
int iRet = 0;
WCHAR GuidString[39] = {0};
unsigned int i, j, k;
/* variables used for WlanEnumInterfaces */
PWLAN_INTERFACE_INFO_LIST pIfList = NULL;
PWLAN_INTERFACE_INFO pIfInfo = NULL;
PWLAN_AVAILABLE_NETWORK_LIST pBssList = NULL;
PWLAN_AVAILABLE_NETWORK pBssEntry = NULL;
int iRSSI = 0;
dwResult = WlanOpenHandle(dwMaxClient, NULL, &dwCurVersion, &hClient);
if (dwResult != ERROR_SUCCESS) {
RETAILMSG(OUTPUT_LOGMSG,(L"WlanOpenHandle failed with error: %u\r\n", dwResult));
return 1;
// You can use FormatMessage here to find out why the function failed
}
dwResult = WlanEnumInterfaces(hClient, NULL, &pIfList);
if (dwResult != ERROR_SUCCESS)
{
RETAILMSG(OUTPUT_LOGMSG,(L"WlanEnumInterfaces failed with error: %u\r\n", dwResult));
return 1;
// You can use FormatMessage here to find out why the function failed
}
else
{
RETAILMSG(OUTPUT_LOGMSG,(L"Num Entries: %d\r\n", pIfList->dwNumberOfItems));
RETAILMSG(OUTPUT_LOGMSG,(L"Current Index: %d\r\n", pIfList->dwIndex));
for (i = 0; i < (int)pIfList->dwNumberOfItems; i++)
{
pIfInfo = (WLAN_INTERFACE_INFO *) &pIfList->InterfaceInfo[i];
RETAILMSG(OUTPUT_LOGMSG,(L" Interface Index[%u]:\t %lu\r\n", i, i));
iRet = StringFromGUID2(pIfInfo->InterfaceGuid, (LPOLESTR) &GuidString,
sizeof(GuidString)/sizeof(*GuidString));
// For c rather than C++ source code, the above line needs to be
// iRet = StringFromGUID2(&pIfInfo->InterfaceGuid, (LPOLESTR) &GuidString,
// sizeof(GuidString)/sizeof(*GuidString));
if (iRet == 0)
RETAILMSG(OUTPUT_LOGMSG,(L"StringFromGUID2 failed\r\n"));
else
RETAILMSG(OUTPUT_LOGMSG,(L" InterfaceGUID[%d]: %ws\r\n",i, GuidString));
RETAILMSG(OUTPUT_LOGMSG,(L" Interface Description[%d]: %s\r\n", i,
&pIfInfo->strInterfaceDescription));
RETAILMSG(OUTPUT_LOGMSG,(L" Interface State[%d]:\t ", i));
switch (pIfInfo->isState) {
case wlan_interface_state_not_ready:
RETAILMSG(OUTPUT_LOGMSG,(L"Not ready\r\n"));
break;
case wlan_interface_state_connected:
RETAILMSG(OUTPUT_LOGMSG,(L"Connected\r\n"));
break;
case wlan_interface_state_ad_hoc_network_formed:
RETAILMSG(OUTPUT_LOGMSG,(L"First node in a ad hoc network\r\n"));
break;
case wlan_interface_state_disconnecting:
RETAILMSG(OUTPUT_LOGMSG,(L"Disconnecting\r\n"));
break;
case wlan_interface_state_disconnected:
RETAILMSG(OUTPUT_LOGMSG,(L"Not connected\r\n"));
break;
case wlan_interface_state_associating:
RETAILMSG(OUTPUT_LOGMSG,(L"Attempting to associate with a network\r\n"));
break;
case wlan_interface_state_discovering:
RETAILMSG(OUTPUT_LOGMSG,(L"Auto configuration is discovering settings for the network\r\n"));
break;
case wlan_interface_state_authenticating:
RETAILMSG(OUTPUT_LOGMSG,(L"In process of authenticating\r\n"));
break;
default:
RETAILMSG(OUTPUT_LOGMSG,(L"Unknown state %ld\r\n", pIfInfo->isState));
break;
}
RETAILMSG(OUTPUT_LOGMSG,(L"\r\n"));
//获得可用的无线网列表
dwResult = WlanGetAvailableNetworkList(hClient,
&pIfInfo->InterfaceGuid,
0,
NULL,
&pBssList);
if (dwResult != ERROR_SUCCESS)
{
RETAILMSG(OUTPUT_LOGMSG,(L"WlanGetAvailableNetworkList failed with error: %u\r\n",
dwResult));
dwRetVal = 1;
// You can use FormatMessage to find out why the function failed
}
else
{
RETAILMSG(OUTPUT_LOGMSG, (L"WLAN_AVAILABLE_NETWORK_LIST for this interface\r\n"));
RETAILMSG(OUTPUT_LOGMSG,(L"Num Entries: %d\r\n", pBssList->dwNumberOfItems));
for (j = 0; j < pBssList->dwNumberOfItems; j++)
{
pBssEntry = (WLAN_AVAILABLE_NETWORK *)&pBssList->Network[j];
RETAILMSG(OUTPUT_LOGMSG,(L" Profile Name[%u]: %s\r\n", j, &pBssEntry->strProfileName));
RETAILMSG(OUTPUT_LOGMSG,(L" SSID[%u]:\t\t ", j));
if (pBssEntry->dot11Ssid.uSSIDLength == 0)
RETAILMSG(OUTPUT_LOGMSG,(L"\r\n"));
else
{
CString str = _T("");
str = pBssEntry->dot11Ssid.ucSSID;
RETAILMSG(OUTPUT_LOGMSG,(L"%s\r\n", str));
RETAILMSG(OUTPUT_LOGMSG,(L"%s\r\n", &pBssEntry->dot11Ssid.ucSSID));
}
RETAILMSG(OUTPUT_LOGMSG,(L"BSS Network type[%u]:\t ", j));
switch (pBssEntry->dot11BssType)
{
case dot11_BSS_type_infrastructure :
RETAILMSG(OUTPUT_LOGMSG,(L"Infrastructure (%u)\r\n", pBssEntry->dot11BssType));
break;
case dot11_BSS_type_independent:
RETAILMSG(OUTPUT_LOGMSG,(L"Infrastructure (%u)\r\n", pBssEntry->dot11BssType));
break;
default:
RETAILMSG(OUTPUT_LOGMSG,(L"Other (%lu)\r\n", pBssEntry->dot11BssType));
break;
}
RETAILMSG(OUTPUT_LOGMSG,(L" Number of BSSIDs[%u]:\t %u\r\n", j, pBssEntry->uNumberOfBssids));
RETAILMSG(OUTPUT_LOGMSG,(L" Connectable[%u]:\t ", j));
if (pBssEntry->bNetworkConnectable)
RETAILMSG(OUTPUT_LOGMSG,(L"Yes\r\n"));
else
{
RETAILMSG(OUTPUT_LOGMSG,(L"No\r\n"));
RETAILMSG(OUTPUT_LOGMSG,(L" Not connectable WLAN_REASON_CODE value[%u]:\t %u\r\n", j,
pBssEntry->wlanNotConnectableReason));
}
RETAILMSG(OUTPUT_LOGMSG,(L"Number of PHY types supported[%u]:\t %u\r\n", j, pBssEntry->uNumberOfPhyTypes));
if (pBssEntry->wlanSignalQuality == 0)
iRSSI = -100;
else if (pBssEntry->wlanSignalQuality == 100)
iRSSI = -50;
else
iRSSI = -100 + (pBssEntry->wlanSignalQuality/2);
RETAILMSG(OUTPUT_LOGMSG,(L" Signal Quality[%u]:\t %u (RSSI: %i dBm)\r\n", j,
pBssEntry->wlanSignalQuality, iRSSI));
RETAILMSG(OUTPUT_LOGMSG,(L" Security Enabled[%u]:\t ", j));
if (pBssEntry->bSecurityEnabled)
RETAILMSG(OUTPUT_LOGMSG,(L"Yes\r\n"));
else
RETAILMSG(OUTPUT_LOGMSG,(L"No\r\n"));
//身份验证类型
RETAILMSG(OUTPUT_LOGMSG,(L" Default AuthAlgorithm[%u]: ", j));
switch (pBssEntry->dot11DefaultAuthAlgorithm)
{
case DOT11_AUTH_ALGO_80211_OPEN:
RETAILMSG(OUTPUT_LOGMSG,(L"802.11 Open (%u)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
case DOT11_AUTH_ALGO_80211_SHARED_KEY:
RETAILMSG(OUTPUT_LOGMSG,(L"802.11 Shared (%u)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
case DOT11_AUTH_ALGO_WPA:
RETAILMSG(OUTPUT_LOGMSG,(L"WPA (%u)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
case DOT11_AUTH_ALGO_WPA_PSK:
RETAILMSG(OUTPUT_LOGMSG,(L"WPA-PSK (%u)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
case DOT11_AUTH_ALGO_WPA_NONE:
RETAILMSG(OUTPUT_LOGMSG,(L"WPA-None (%u)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
case DOT11_AUTH_ALGO_RSNA:
RETAILMSG(OUTPUT_LOGMSG,(L"RSNA (%u)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
case DOT11_AUTH_ALGO_RSNA_PSK:
RETAILMSG(OUTPUT_LOGMSG,(L"RSNA with PSK(%u)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
default:
RETAILMSG(OUTPUT_LOGMSG,(L"Other (%lu)\r\n", pBssEntry->dot11DefaultAuthAlgorithm));
break;
}
//加密类型
RETAILMSG(OUTPUT_LOGMSG,(L" Default CipherAlgorithm[%u]: ", j));
switch (pBssEntry->dot11DefaultCipherAlgorithm)
{
case DOT11_CIPHER_ALGO_NONE:
RETAILMSG(OUTPUT_LOGMSG,(L"None (0x%x)\r\n", pBssEntry->dot11DefaultCipherAlgorithm));
break;
case DOT11_CIPHER_ALGO_WEP40:
RETAILMSG(OUTPUT_LOGMSG,(L"WEP-40 (0x%x)\r\n", pBssEntry->dot11DefaultCipherAlgorithm));
break;
case DOT11_CIPHER_ALGO_TKIP:
RETAILMSG(OUTPUT_LOGMSG,(L"TKIP (0x%x)\r\n", pBssEntry->dot11DefaultCipherAlgorithm));
break;
case DOT11_CIPHER_ALGO_CCMP:
RETAILMSG(OUTPUT_LOGMSG,(L"CCMP (0x%x)\r\n", pBssEntry->dot11DefaultCipherAlgorithm));
break;
case DOT11_CIPHER_ALGO_WEP104:
RETAILMSG(OUTPUT_LOGMSG,(L"WEP-104 (0x%x)\r\n", pBssEntry->dot11DefaultCipherAlgorithm));
break;
case DOT11_CIPHER_ALGO_WEP:
RETAILMSG(OUTPUT_LOGMSG,(L"WEP (0x%x)\r\n", pBssEntry->dot11DefaultCipherAlgorithm));
break;
default:
RETAILMSG(OUTPUT_LOGMSG,(L"Other (0x%x)\r\n", pBssEntry->dot11DefaultCipherAlgorithm));
break;
}
RETAILMSG(OUTPUT_LOGMSG,(L" Flags[%u]:\t 0x%x", j, pBssEntry->dwFlags));
if (pBssEntry->dwFlags)
{
if (pBssEntry->dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED)
RETAILMSG(OUTPUT_LOGMSG,(L" - Currently connected"));
if (pBssEntry->dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED)
RETAILMSG(OUTPUT_LOGMSG,(L" - Has profile"));
}
RETAILMSG(OUTPUT_LOGMSG,(L"\r\n"));
RETAILMSG(OUTPUT_LOGMSG,(L"\r\n"));
}//for (j = 0; j < pBssList->dwNumberOfItems; j++)
}//else 无线网个数
}//for (i = 0; i < (int)pIfList->dwNumberOfItems; i++)
}//else 无线适配器
// 释放空间
if (pBssList != NULL)
{
WlanFreeMemory(pBssList);
pBssList = NULL;
}
if (pIfList != NULL)
{
WlanFreeMemory(pIfList);
pIfList = NULL;
}
return dwRetVal;
}
需要附加头文件:
#include <wlanapi.h>
#pragma comment(lib, "wlanapi.lib")
定义的宏
//定义输入LOG信息宏
#define OUTPUT_LOGMSG 1
编译时可能会出错,但我把其中出错的地方注释掉,就可以编译了,而且能够得到相应的结果。
修改文件 ntddndis.h 修改如下:
#define NDIS_IF_MAX_STRING_SIZE IF_MAX_STRING_SIZE
line 3958 //typedef IF_COUNTED_STRING NDIS_IF_COUNTED_STRING, *PNDIS_IF_COUNTED_STRING;
#define NDIS_MAX_PHYS_ADDRESS_LENGTH IF_MAX_PHYS_ADDRESS_LENGTH
line 3960 //typedef IF_PHYSICAL_ADDRESS NDIS_IF_PHYSICAL_ADDRESS, *PNDIS_IF_PHYSICAL_ADDRESS;
相关文章推荐
- Windows 7笔记本创建wifi热点供手机上网教程
- Windows Moible, Wince 使用.NET Compact Framework的进行蓝牙(Bluetooth)开发 之 Windows Embedded Source Tools for Bluetooth
- windows笔记本设置wifi热点(win10篇)
- 在Windows Mobile和Wince(Windows Embedded CE)下使用.NET Compact Framework进行GPS NMEA data数据分析的开发
- Windows Embedded Compact 7 文件系统概要
- wince -- windows embedded compact 7 移植成功
- windows 热点wifi
- Windows Embedded Compact 7中的内存管理(下)
- Android获取当前所在位置的WiFi热点,并保存到本地文件中
- 搭建Windows Embedded Compact 7开发环境
- android通过反射获取wifi热点ap的ssid和password
- Windows Embedded Compact 7中的文件系统和注册表管理(上)
- Windows Embedded Compact 7新特性技术解析
- Windows Mobile和Wince(Windows Embedded CE )下使用.NET Compact Framework下注册表导出工具的开发
- 搭建Windows Embedded Compact 7开发环境
- Android获取周围WIFI热点服务
- Windows Embedded Compact 7中的 COM编程(上)
- ad-hoc,软ap(windows无线网卡制作WIFI热点)
- Windows Embedded Compact 7 使用COM编译错误解决
- 如何确保Windows Embedded Compact 7成本控制