0

我试图在 Windows 10 下从 C# 桌面应用程序互操作 WlanGetNetworkBssList。在正确检索 WLAN_BSS_LIST 时遇到一些问题。不知道问题出在哪里,我得到的列表是错误的。第一项似乎是正确的,但所有其他的都不是。我希望有一个人可以帮助我。

这些是我使用的结构。我认为问题是错误的结构定义。

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
struct WLAN_BSS_LIST
{
    internal Int32 dwTotalSize;
    internal Int32 dwNumberOfItems;
    internal WLAN_BSS_ENTRY[] wlanBssEntries;
    internal WLAN_BSS_LIST(IntPtr ppWlanBssList)
    {
        dwTotalSize = (Int32)Marshal.ReadInt32(ppWlanBssList);
        dwNumberOfItems = (Int32)Marshal.ReadInt32(ppWlanBssList + 4);
        wlanBssEntries = new WLAN_BSS_ENTRY[dwNumberOfItems];
        int WLAN_BSS_ENTRY_SIZE = Marshal.SizeOf(typeof(WLAN_BSS_ENTRY));
        for (int i = 0; i < dwNumberOfItems; i++)
        {
            IntPtr pItemList = new IntPtr(ppWlanBssList.ToInt32() + i * Marshal.SizeOf(typeof(WLAN_BSS_ENTRY)) + 8);
            wlanBssEntries[i] = (WLAN_BSS_ENTRY)Marshal.PtrToStructure(pItemList, typeof(WLAN_BSS_ENTRY));
        }
    }
}
public struct WLAN_BSS_ENTRY
{
    public DOT11_SSID dot11Ssid;
    public ulong uPhyId;
    public DOT11_MAC_ADDRESS dot11Bssid;
    public DOT11_BSS_TYPE dot11BssType;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
    public DOT11_PHY_TYPE[] dot11BssPhyType;
    public long lRssi;
    public ulong uLinkQuality;
    public bool bInRegDomain;
    public ushort usBeaconPeriod;
    public ulong ullTimestamp;
    public ulong ullHostTimestamp;
    public ushort usCapabilityInformation;
    public ulong ulChCenterFrequency;
    public WLAN_RATE_SET wlanRateSet;
    public ulong ulIeOffset;
    public ulong ulIeSize;
}
public struct DOT11_SSID
{
    public uint uSSIDLength;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
    public string ucSSID;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct DOT11_MAC_ADDRESS
{
    public byte one;
    public byte two;
    public byte three;
    public byte four;
    public byte five;
    public byte six;
}
public enum DOT11_BSS_TYPE
{
    dot11_BSS_type_infrastructure = 1,
    dot11_BSS_type_independent = 2,
    dot11_BSS_type_any = 3,
}
public enum DOT11_PHY_TYPE
{
    dot11_phy_type_unknown,
    dot11_phy_type_any,
    dot11_phy_type_fhss,
    dot11_phy_type_dsss,
    dot11_phy_type_irbaseband,
    dot11_phy_type_ofdm,
    dot11_phy_type_hrdsss,
    dot11_phy_type_erp,
    dot11_phy_type_ht,
    dot11_phy_type_IHV_start,
    dot11_phy_type_IHV_end,
}
public struct WLAN_RATE_SET
{
    public ulong uRateSetLength;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 126)]
    public ushort[] usRateSet;
}
4

1 回答 1

0

快速解决方法是更改​​您的代码以使用 Ilya Konstantinov 的托管 Wifi API库。它在 MIT 许可下。我有一个使用 SafeHandles 进行所有资源管理的分支,但原始代码是可靠的。

于 2016-09-23T00:42:39.807 回答