英文:
How to get Wi-Fi Information Elements in Windows Native Wifi
问题
Windows的Native Wifi文档提到,可以通过WLAN_BSS_ENTRY结构的ulIeOffset和ulIeSize成员来获取来自Beacon或Probe Response帧的802.11信息元素(IEs),这两个成员定义了包含IE数据块的内存区域。但是,我尝试使用这两个变量来检索IEs时未成功。
我通过GetAvailableNetworkList()获得了多个有效的WLAN_BSS_ENTRY结构(正确填充了802.11网络信息 - SSID、BSSID等),ulIeOffset和ulIeSize的值也是有意义的,但是当尝试访问该内存区域时出现了读取异常。
我的测试平台是Windows 10,包括截至本帖日期的所有更新,最新的Visual Studio Community版本,并且我编写了一个简单的控制台应用程序,用于打印所有WLAN_BSS_ENTRY字段(成功),以及IE数据块(不成功)。与扫描相关的C++代码如下所示。感谢任何见解。
// 检索扫描到的网络
dwResult = WlanGetNetworkBssList(hClient, &pIfList->InterfaceInfo[0].InterfaceGuid,
NULL, dot11_BSS_type_any, false, NULL, &pBssList);
if (dwResult == ERROR_SUCCESS) {
for (DWORD i = 0; i < pBssList->dwNumberOfItems; i++) {
const WLAN_BSS_ENTRY bssEntry = pBssList->wlanBssEntries[i];
std::cout << "SSID: " << bssEntry.dot11Ssid.ucSSID << std::endl;
std::cout << "RSSI: " << bssEntry.lRssi << " dBm" << std::endl;
// 打印其他bssEntry字段,全部有效
std::cout << "IE缓冲区偏移量: " << bssEntry.ulIeOffset << std::endl;
std::cout << "IE缓冲区大小: " << bssEntry.ulIeSize << std::endl;
// --> 以下IE检索不起作用(引发读取异常) <--
const PBYTE ieBuffer = (const PBYTE)((PBYTE)(&bssEntry) + bssEntry.ulIeOffset);
for (DWORD j = 0; j < bssEntry.ulIeSize; j++) {
printf("%02X ", ieBuffer[j]);
}
std::cout << std::endl;
std::cout << std::endl;
}
WlanFreeMemory(pBssList);
}
希望这能帮助你解决IE数据检索的问题。
英文:
The Windows Native Wifi documentation mentions 802.11 Information Elements (IEs) from Beacon or Probe Response frames are available through the WLAN_BSS_ENTRY structure, specifically, through its ulIeOffset and ulIeSize members, which define an area of memory that contains the IE data blob. I've been unsuccessful with retrieving IEs using these two variables.
I get multiple valid WLAN_BSS_ENTRY structures through GetAvailableNetworkList() (correctly populated with 802.11 network information - SSID, BSSID, etc.) - ulIeOffset and ulIeSize values make sense too, but I get read exception when trying to access that memory area.
My test platform is Windows 10 with all updates as of this post date, latest Visual Studio Community edition, and I wrote a simple console application that prints all WLAN_BSS_ENTRY fields (successful), and the IE data blob (unsuccessful). C++ code related to scan is shown below. Any insight appreciated.
// retrieve scanned networks
dwResult = WlanGetNetworkBssList(hClient, &pIfList->InterfaceInfo[0].InterfaceGuid,
NULL, dot11_BSS_type_any, false, NULL, &pBssList);
if (dwResult == ERROR_SUCCESS) {
for (DWORD i = 0; i < pBssList->dwNumberOfItems; i++) {
const WLAN_BSS_ENTRY bssEntry = pBssList->wlanBssEntries[i];
std::cout << "SSID: " << bssEntry.dot11Ssid.ucSSID << std::endl;
std::cout << "RSSI: " << bssEntry.lRssi << " dBm" << std::endl;
// print bunch of other bssEntry fields, all valid
std::cout << "IE buffer offset: " << bssEntry.ulIeOffset << std::endl;
std::cout << "IE buffer size: " << bssEntry.ulIeSize << std::endl;
// --> IE retrieval below doesn't work (throws read exception) <--
const PBYTE ieBuffer = (const PBYTE)((PBYTE)(&bssEntry) + bssEntry.ulIeOffset);
for (DWORD j = 0; j < bssEntry.ulIeSize; j++) {
printf("%02X ", ieBuffer[j]);
}
std::cout << std::endl;
std::cout << std::endl;
}
WlanFreeMemory(pBssList);
}
答案1
得分: 1
问题在于这段代码:
const WLAN_BSS_ENTRY bssEntry = pBssList->wlanBssEntries[i];
它复制了WLAN_BSS_ENTRY结构,因此它的地址指向内存中的另一个位置。你想要保持所有内容都作为指针:
WlanGetNetworkBssList(hClient, &pIfList->InterfaceInfo[0].InterfaceGuid, NULL, dot11_BSS_type_any, false, NULL, &pBssList);
for (DWORD i = 0; i < pBssList->dwNumberOfItems; i++) {
// 使用原始指针
PWLAN_BSS_ENTRY bssEntry = &pBssList->wlanBssEntries[i];
std::cout << "SSID: " << bssEntry->dot11Ssid.ucSSID << std::endl;
std::cout << "RSSI: " << bssEntry->lRssi << " dBm" << std::endl;
std::cout << "IE buffer offset: " << bssEntry->ulIeOffset << std::endl;
std::cout << "IE buffer size: " << bssEntry->ulIeSize << std::endl;
PBYTE ieBuffer = (PBYTE)bssEntry + bssEntry->ulIeOffset;
for (DWORD j = 0; j < bssEntry->ulIeSize; j++) {
printf("%02X ", ieBuffer[j]);
}
std::cout << std::endl;
std::cout << std::endl;
}
WlanFreeMemory(pBssList);
英文:
The problem is this code:
const WLAN_BSS_ENTRY bssEntry = pBssList->wlanBssEntries[i];
makes a copy of the WLAN_BSS_ENTRY structure, so it's address points to another place in memory. You want to keep everything as pointers:
WlanGetNetworkBssList(hClient, &pIfList->InterfaceInfo[0].InterfaceGuid, NULL, dot11_BSS_type_any, false, NULL, &pBssList);
for (DWORD i = 0; i < pBssList->dwNumberOfItems; i++) {
// use the original pointer
PWLAN_BSS_ENTRY bssEntry = &pBssList->wlanBssEntries[i]
std::cout << "SSID: " << bssEntry->dot11Ssid.ucSSID << std::endl;
std::cout << "RSSI: " << bssEntry->lRssi << " dBm" << std::endl;
std::cout << "IE buffer offset: " << bssEntry->ulIeOffset << std::endl;
std::cout << "IE buffer size: " << bssEntry->ulIeSize << std::endl;
PBYTE ieBuffer = (PBYTE)bssEntry + bssEntry->ulIeOffset;
for (DWORD j = 0; j < bssEntry->ulIeSize; j++) {
printf("%02X ", ieBuffer[j]);
}
std::cout << std::endl;
std::cout << std::endl;
}
WlanFreeMemory(pBssList);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论