using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Runtime.InteropServices;
using System.Text;
namespace Tango.WiFi.Win32.Interop
{
///
/// The header of an array of information about available networks.
///
[StructLayout(LayoutKind.Sequential)]
internal struct WlanAvailableNetworkListHeader
{
///
/// Contains the number of items following the header.
///
public uint numberOfItems;
///
/// The index of the current item. The index of the first item is 0.
///
public uint index;
}
///
/// Contains information about an available wireless network.
///
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct WlanAvailableNetwork
{
///
/// Contains the profile name associated with the network.
/// If the network doesn't have a profile, this member will be empty.
/// If multiple profiles are associated with the network, there will be multiple entries with the same SSID in the visible network list. Profile names are case-sensitive.
///
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string profileName;
///
/// Contains the SSID of the visible wireless network.
///
public Dot11Ssid dot11Ssid;
///
/// Specifies whether the network is infrastructure or ad hoc.
///
public Dot11BssType dot11BssType;
///
/// Indicates the number of BSSIDs in the network.
///
public uint numberOfBssids;
///
/// Indicates whether the network is connectable or not.
///
public bool networkConnectable;
///
/// Indicates why a network cannot be connected to. This member is only valid when is false.
///
public WlanReasonCode wlanNotConnectableReason;
///
/// The number of PHY types supported on available networks.
/// The maximum value of this field is 8. If more than 8 PHY types are supported, must be set to true.
///
private uint numberOfPhyTypes;
///
/// Contains an array of values that represent the PHY types supported by the available networks.
/// When is greater than 8, this array contains only the first 8 PHY types.
///
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
private Dot11PhyType[] dot11PhyTypes;
///
/// Gets the values that represent the PHY types supported by the available networks.
///
public Dot11PhyType[] Dot11PhyTypes
{
get
{
Dot11PhyType[] ret = new Dot11PhyType[numberOfPhyTypes];
Array.Copy(dot11PhyTypes, ret, numberOfPhyTypes);
return ret;
}
}
///
/// Specifies if there are more than 8 PHY types supported.
/// When this member is set to true, an application must call to get the complete list of PHY types.
/// contains the PHY type for an entry.
///
public bool morePhyTypes;
///
/// A percentage value that represents the signal quality of the network.
/// This field contains a value between 0 and 100.
/// A value of 0 implies an actual RSSI signal strength of -100 dbm.
/// A value of 100 implies an actual RSSI signal strength of -50 dbm.
/// You can calculate the RSSI signal strength value for values between 1 and 99 using linear interpolation.
///
public uint wlanSignalQuality;
///
/// Indicates whether security is enabled on the network.
///
public bool securityEnabled;
///
/// Indicates the default authentication algorithm used to join this network for the first time.
///
public Dot11AuthAlgorithm dot11DefaultAuthAlgorithm;
///
/// Indicates the default cipher algorithm to be used when joining this network.
///
public Dot11CipherAlgorithm dot11DefaultCipherAlgorithm;
///
/// Contains various flags for the network.
///
public WlanAvailableNetworkFlags flags;
///
/// Reserved for future use. Must be set to NULL.
///
uint reserved;
public bool Equals(WlanAvailableNetwork network)
{
// Compares the two SSID byte arrays
return this.dot11Ssid.SSIDLength == network.dot11Ssid.SSIDLength
&& this.dot11Ssid.SSID.SequenceEqual(network.dot11Ssid.SSID);
}
}
///
/// Contains information provided when registering for notifications.
///
///
/// Corresponds to the native WLAN_NOTIFICATION_DATA type.
///
[StructLayout(LayoutKind.Sequential)]
public struct WlanNotificationData
{
///
/// Specifies where the notification comes from.
///
///
/// On Windows XP SP2, this field must be set to , or .
///
public WlanNotificationSource notificationSource;
///
/// Indicates the type of notification. The value of this field indicates what type of associated data will be present in .
///
public int notificationCode;
///
/// Indicates which interface the notification is for.
///
public Guid interfaceGuid;
///
/// Specifies the size of , in bytes.
///
public int dataSize;
///
/// Pointer to additional data needed for the notification, as indicated by .
///
public IntPtr dataPtr;
///
/// Gets the notification code (in the correct enumeration type) according to the notification source.
///
public object NotificationCode
{
get
{
if (notificationSource == WlanNotificationSource.MSM)
return (WlanNotificationCodeMsm)notificationCode;
else if (notificationSource == WlanNotificationSource.ACM)
return (WlanNotificationCodeAcm)notificationCode;
else
return notificationCode;
}
}
}
///
/// Specifies the parameters used when using the function.
///
///
/// Corresponds to the native WLAN_CONNECTION_PARAMETERS type.
///
[StructLayout(LayoutKind.Sequential)]
public struct WlanConnectionParameters
{
///
/// Specifies the mode of connection.
///
public WlanConnectionMode wlanConnectionMode;
///
/// Specifies the profile being used for the connection.
/// The contents of the field depend on the :
///
///
/// Value of
/// Contents of the profile string
///
/// -
///
/// The name of the profile used for the connection.
///
/// -
///
/// The XML representation of the profile used for the connection.
///
/// -
/// , or
/// null
///
///
///
[MarshalAs(UnmanagedType.LPWStr)]
public string profile;
///
/// Pointer to a structure that specifies the SSID of the network to connect to.
/// This field is optional. When set to null, all SSIDs in the profile will be tried.
/// This field must not be null if is set to or .
///
public IntPtr dot11SsidPtr;
///
/// Pointer to a structure that contains the list of basic service set (BSS) identifiers desired for the connection.
///
///
/// On Windows XP SP2, must be set to null.
///
public IntPtr desiredBssidListPtr;
///
/// A value that indicates the BSS type of the network. If a profile is provided, this BSS type must be the same as the one in the profile.
///
public Dot11BssType dot11BssType;
///
/// Specifies ocnnection parameters.
///
///
/// On Windows XP SP2, must be set to 0.
///
public WlanConnectionFlags flags;
}
[StructLayout(LayoutKind.Sequential)]
internal struct WlanBssListHeader
{
internal uint totalSize;
internal uint numberOfItems;
}
///
/// Contains information about a basic service set (BSS).
///
[StructLayout(LayoutKind.Sequential)]
public struct WlanBssEntry
{
///
/// Contains the SSID of the access point (AP) associated with the BSS.
///
public Dot11Ssid dot11Ssid;
///
/// The identifier of the PHY on which the AP is operating.
///
public uint phyId;
///
/// Contains the BSS identifier.
///
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
public byte[] dot11Bssid;
///
/// Specifies whether the network is infrastructure or ad hoc.
///
public Dot11BssType dot11BssType;
public Dot11PhyType dot11BssPhyType;
///
/// The received signal strength in dBm.
///
public int rssi;
///
/// The link quality reported by the driver. Ranges from 0-100.
///
public uint linkQuality;
///
/// If 802.11d is not implemented, the network interface card (NIC) must set this field to TRUE. If 802.11d is implemented (but not necessarily enabled), the NIC must set this field to TRUE if the BSS operation complies with the configured regulatory domain.
///
public bool inRegDomain;
///
/// Contains the beacon interval value from the beacon packet or probe response.
///
public ushort beaconPeriod;
///
/// The timestamp from the beacon packet or probe response.
///
public ulong timestamp;
///
/// The host timestamp value when the beacon or probe response is received.
///
public ulong hostTimestamp;
///
/// The capability value from the beacon packet or probe response.
///
public ushort capabilityInformation;
///
/// The frequency of the center channel, in kHz.
///
public uint chCenterFrequency;
///
/// Contains the set of data transfer rates supported by the BSS.
///
public WlanRateSet wlanRateSet;
///
/// Offset of the information element (IE) data blob.
///
public uint ieOffset;
///
/// Size of the IE data blob, in bytes.
///
public uint ieSize;
}
///
/// Contains the set of supported data rates.
///
[StructLayout(LayoutKind.Sequential)]
public struct WlanRateSet
{
///
/// The length, in bytes, of .
///
private uint rateSetLength;
///
/// An array of supported data transfer rates.
/// If the rate is a basic rate, the first bit of the rate value is set to 1.
/// A basic rate is the data transfer rate that all stations in a basic service set (BSS) can use to receive frames from the wireless medium.
///
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 126)]
private ushort[] rateSet;
public ushort[] Rates
{
get
{
ushort[] rates = new ushort[rateSetLength / sizeof(ushort)];
Array.Copy(rateSet, rates, rates.Length);
return rates;
}
}
///
/// CalculateS the data transfer rate in Mbps for an arbitrary supported rate.
///
///
///
public double GetRateInMbps(int rate)
{
return (rateSet[rate] & 0x7FFF) * 0.5;
}
}
///
/// Contains information about connection related notifications.
///
///
/// Corresponds to the native WLAN_CONNECTION_NOTIFICATION_DATA type.
///
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct WlanConnectionNotificationData
{
///
/// On Windows XP SP 2, only is supported.
///
public WlanConnectionMode wlanConnectionMode;
///
/// The name of the profile used for the connection. Profile names are case-sensitive.
///
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string profileName;
///
/// The SSID of the association.
///
public Dot11Ssid dot11Ssid;
///
/// The BSS network type.
///
public Dot11BssType dot11BssType;
///
/// Indicates whether security is enabled for this connection.
///
public bool securityEnabled;
///
/// Indicates the reason for an operation failure.
/// This field has a value of for all connection-related notifications except .
/// If the connection fails, this field indicates the reason for the failure.
///
public WlanReasonCode wlanReasonCode;
///
/// This field contains the XML presentation of the profile used for discovery, if the connection succeeds.
///
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1)]
public string profileXml;
}
///
/// Contains the SSID of an interface.
///
public struct Dot11Ssid
{
///
/// The length, in bytes, of the array.
///
public uint SSIDLength;
///
/// The SSID.
///
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public byte[] SSID;
}
///
/// Contains association attributes for a connection
///
///
/// Corresponds to the native WLAN_ASSOCIATION_ATTRIBUTES type.
///
[StructLayout(LayoutKind.Sequential)]
public struct WlanAssociationAttributes
{
///
/// The SSID of the association.
///
public Dot11Ssid dot11Ssid;
///
/// Specifies whether the network is infrastructure or ad hoc.
///
public Dot11BssType dot11BssType;
///
/// The BSSID of the association.
///
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
public byte[] dot11Bssid;
///
/// The physical type of the association.
///
public Dot11PhyType dot11PhyType;
///
/// The position of the value in the structure containing the list of PHY types.
///
public uint dot11PhyIndex;
///
/// A percentage value that represents the signal quality of the network.
/// This field contains a value between 0 and 100.
/// A value of 0 implies an actual RSSI signal strength of -100 dbm.
/// A value of 100 implies an actual RSSI signal strength of -50 dbm.
/// You can calculate the RSSI signal strength value for values between 1 and 99 using linear interpolation.
///
public uint wlanSignalQuality;
///
/// The receiving rate of the association.
///
public uint rxRate;
///
/// The transmission rate of the association.
///
public uint txRate;
///
/// Gets the BSSID of the associated access point.
///
/// The BSSID.
public PhysicalAddress Dot11Bssid
{
get { return new PhysicalAddress(dot11Bssid); }
}
}
///
/// Defines the security attributes for a wireless connection.
///
///
/// Corresponds to the native WLAN_SECURITY_ATTRIBUTES type.
///
[StructLayout(LayoutKind.Sequential)]
public struct WlanSecurityAttributes
{
///
/// Indicates whether security is enabled for this connection.
///
[MarshalAs(UnmanagedType.Bool)]
public bool securityEnabled;
[MarshalAs(UnmanagedType.Bool)]
public bool oneXEnabled;
///
/// The authentication algorithm.
///
public Dot11AuthAlgorithm dot11AuthAlgorithm;
///
/// The cipher algorithm.
///
public Dot11CipherAlgorithm dot11CipherAlgorithm;
}
///
/// Defines the attributes of a wireless connection.
///
///
/// Corresponds to the native WLAN_CONNECTION_ATTRIBUTES type.
///
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct WlanConnectionAttributes
{
///
/// The state of the interface.
///
public WlanInterfaceState isState;
///
/// The mode of the connection.
///
public WlanConnectionMode wlanConnectionMode;
///
/// The name of the profile used for the connection. Profile names are case-sensitive.
///
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string profileName;
///
/// The attributes of the association.
///
public WlanAssociationAttributes wlanAssociationAttributes;
///
/// The security attributes of the connection.
///
public WlanSecurityAttributes wlanSecurityAttributes;
}
///
/// Contains information about a LAN interface.
///
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct WlanInterfaceInfo
{
///
/// The GUID of the interface.
///
public Guid interfaceGuid;
///
/// The description of the interface.
///
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string interfaceDescription;
///
/// The current state of the interface.
///
public WlanInterfaceState isState;
}
///
/// The header of the list returned by .
///
[StructLayout(LayoutKind.Sequential)]
internal struct WlanInterfaceInfoListHeader
{
public uint numberOfItems;
public uint index;
}
///
/// The header of the list returned by .
///
[StructLayout(LayoutKind.Sequential)]
internal struct WlanProfileInfoListHeader
{
public uint numberOfItems;
public uint index;
}
///
/// Contains basic information about a profile.
///
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct WlanProfileInfo
{
///
/// The name of the profile. This value may be the name of a domain if the profile is for provisioning. Profile names are case-sensitive.
///
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string profileName;
///
/// Profile flags.
///
public WlanProfileFlags profileFlags;
}
/*
///
/// The EAP_METHOD_TYPE structure contains type, identification, and author information about an EAP method.
///
[StructLayout(LayoutKind.Sequential)]
public struct EapMethodType
{
public EapType eapType; // EAP_TYPE structure that contains the ID for the EAP method as well as specific vendor information.
public uint dwAuthorId; // The numeric ID for the author of the EAP method.
}
///
/// The EAP_TYPE structure contains type and vendor identification information for an EAP method.
///
[StructLayout(LayoutKind.Sequential)]
public struct EapType
{
public byte type; // The numeric type code for this EAP method, Note For more information on the allocation of EAP method types, see section 6.2 of RFC 3748: http://go.microsoft.com/fwlink/p/?linkid=84016
public uint dwVendorId; // The vendor ID for the EAP method.
public uint dwVendorType; // The numeric type code for the vendor of this EAP method.
}*/
}