im trying to interop WlanGetNetworkBssList from a C# Desktop APP under Windows 10. Have some Problems to retrieve the WLAN_BSS_LIST correctly. Not sure where the Problem is, the list i get is wrong. First item seems correct, but all other ones arnt. I hope someone can help me.
These are the structures im using. i believe the Problem is a wrong structure definition.
[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;
}
The quick fix is to change your code to use Ilya Konstantinov's Managed Wifi API library. It is under the MIT license. I have a fork that uses SafeHandles for all resource management but the original code is solid.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.