/// 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.
/// Gets the <see cref="Dot11PhyType"/> values that represent the PHY types supported by the available networks.
/// </summary>
public Dot11PhyType[] Dot11PhyTypes
{
get
{
Dot11PhyType[] ret = new Dot11PhyType[numberOfPhyTypes];
Array.Copy(dot11PhyTypes, ret, numberOfPhyTypes);
return ret;
}
}
/// <summary>
/// Specifies if there are more than 8 PHY types supported.
/// When this member is set to <c>true</c>, an application must call <see cref="WlanClient.WlanInterface.GetNetworkBssList"/> to get the complete list of PHY types.
/// <see cref="WlanBssEntry.phyId"/> contains the PHY type for an entry.
/// </summary>
public bool morePhyTypes;
/// <summary>
/// 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.
/// </summary>
public uint wlanSignalQuality;
/// <summary>
/// Indicates whether security is enabled on the network.
/// </summary>
public bool securityEnabled;
/// <summary>
/// Indicates the default authentication algorithm used to join this network for the first time.
/// </summary>
public Dot11AuthAlgorithm dot11DefaultAuthAlgorithm;
/// <summary>
/// Indicates the default cipher algorithm to be used when joining this network.
/// </summary>
public Dot11CipherAlgorithm dot11DefaultCipherAlgorithm;
/// <summary>
/// Contains various flags specifying characteristics of the available network.
/// </summary>
public WlanAvailableNetworkFlags flags;
/// <summary>
/// Reserved for future use. Must be set to NULL.
/// </summary>
uint reserved;
}
[DllImport("wlanapi.dll")]
public static extern int WlanGetAvailableNetworkList(
public static extern void WlanFreeMemory(IntPtr pMemory);
[DllImport("wlanapi.dll")]
public static extern int WlanReasonCodeToString(
[In] WlanReasonCode reasonCode,
[In] int bufferSize,
[In, Out] StringBuilder stringBuffer,
IntPtr pReserved
);
/// <summary>
/// Defines the mask which specifies where a notification comes from.
/// </summary>
[Flags]
public enum WlanNotificationSource
{
None = 0,
/// <summary>
/// All notifications, including those generated by the 802.1X module.
/// </summary>
All = 0X0000FFFF,
/// <summary>
/// Notifications generated by the auto configuration module.
/// </summary>
ACM = 0X00000008,
/// <summary>
/// Notifications generated by MSM.
/// </summary>
MSM = 0X00000010,
/// <summary>
/// Notifications generated by the security module.
/// </summary>
Security = 0X00000020,
/// <summary>
/// Notifications generated by independent hardware vendors (IHV).
/// </summary>
IHV = 0X00000040
}
/// <summary>
/// Defines the types of ACM (<see cref="WlanNotificationSource.ACM"/>) notifications.
/// </summary>
/// <remarks>
/// The enumeration identifiers correspond to the native <c>wlan_notification_acm_</c> identifiers.
/// On Windows XP SP2, only the <c>ConnectionComplete</c> and <c>Disconnected</c> notifications are available.
/// </remarks>
public enum WlanNotificationCodeAcm
{
AutoconfEnabled = 1,
AutoconfDisabled,
BackgroundScanEnabled,
BackgroundScanDisabled,
BssTypeChange,
PowerSettingChange,
ScanComplete,
ScanFail,
ConnectionStart,
ConnectionComplete,
ConnectionAttemptFail,
FilterListChange,
InterfaceArrival,
InterfaceRemoval,
ProfileChange,
ProfileNameChange,
ProfilesExhausted,
NetworkNotAvailable,
NetworkAvailable,
Disconnecting,
Disconnected,
AdhocNetworkStateChange
}
/// <summary>
/// Defines the types of an MSM (<see cref="WlanNotificationSource.MSM"/>) notifications.
/// </summary>
/// <remarks>
/// The enumeration identifiers correspond to the native <c>wlan_notification_msm_</c> identifiers.
/// </remarks>
public enum WlanNotificationCodeMsm
{
Associating = 1,
Associated,
Authenticating,
Connected,
RoamingStart,
RoamingEnd,
RadioStateChange,
SignalQualityChange,
Disassociating,
Disconnected,
PeerJoin,
PeerLeave,
AdapterRemoval,
AdapterOperationModeChange
}
/// <summary>
/// Contains information provided when registering for WLAN notifications.
/// </summary>
/// <remarks>
/// Corresponds to the native <c>WLAN_NOTIFICATION_DATA</c> type.
/// </remarks>
[StructLayout(LayoutKind.Sequential)]
public struct WlanNotificationData
{
/// <summary>
/// Specifies where the notification comes from.
/// </summary>
/// <remarks>
/// On Windows XP SP2, this field must be set to <see cref="WlanNotificationSource.None"/>, <see cref="WlanNotificationSource.All"/> or <see cref="WlanNotificationSource.ACM"/>.
/// </remarks>
public WlanNotificationSource notificationSource;
/// <summary>
/// Indicates the type of notification. The value of this field indicates what type of associated data will be present in <see cref="dataPtr"/>.
/// </summary>
public int notificationCode;
/// <summary>
/// Indicates which interface the notification is for.
/// </summary>
public Guid interfaceGuid;
/// <summary>
/// Specifies the size of <see cref="dataPtr"/>, in bytes.
/// </summary>
public int dataSize;
/// <summary>
/// Pointer to additional data needed for the notification, as indicated by <see cref="notificationCode"/>.
/// </summary>
public IntPtr dataPtr;
/// <summary>
/// Gets the notification code (in the correct enumeration type) according to the notification source.
/// </summary>
public object NotificationCode
{
get
{
if (notificationSource == WlanNotificationSource.MSM)
return (WlanNotificationCodeMsm)notificationCode;
else if (notificationSource == WlanNotificationSource.ACM)
return (WlanNotificationCodeAcm)notificationCode;
else
return notificationCode;
}
}
}
/// <summary>
/// Defines the callback function which accepts WLAN notifications.
/// </summary>
public delegate void WlanNotificationCallbackDelegate(ref WlanNotificationData notificationData, IntPtr context);
[DllImport("wlanapi.dll")]
public static extern int WlanRegisterNotification(
[Out] out WlanNotificationSource prevNotifSource);
/// <summary>
/// Defines flags which affect connecting to a WLAN network.
/// </summary>
[Flags]
public enum WlanConnectionFlags
{
/// <summary>
/// Connect to the destination network even if the destination is a hidden network. A hidden network does not broadcast its SSID. Do not use this flag if the destination network is an ad-hoc network.
/// <para>If the profile specified by <see cref="WlanConnectionParameters.profile"/> is not <c>null</c>, then this flag is ignored and the nonBroadcast profile element determines whether to connect to a hidden network.</para>
/// </summary>
HiddenNetwork = 0x00000001,
/// <summary>
/// Do not form an ad-hoc network. Only join an ad-hoc network if the network already exists. Do not use this flag if the destination network is an infrastructure network.
/// </summary>
AdhocJoinOnly = 0x00000002,
/// <summary>
/// Ignore the privacy bit when connecting to the network. Ignoring the privacy bit has the effect of ignoring whether packets are encryption and ignoring the method of encryption used. Only use this flag when connecting to an infrastructure network using a temporary profile.
/// </summary>
IgnorePrivacyBit = 0x00000004,
/// <summary>
/// Exempt EAPOL traffic from encryption and decryption. This flag is used when an application must send EAPOL traffic over an infrastructure network that uses Open authentication and WEP encryption. This flag must not be used to connect to networks that require 802.1X authentication. This flag is only valid when <see cref="WlanConnectionParameters.wlanConnectionMode"/> is set to <see cref="WlanConnectionMode.TemporaryProfile"/>. Avoid using this flag whenever possible.
/// </summary>
EapolPassthrough = 0x00000008
}
/// <summary>
/// Specifies the parameters used when using the <see cref="WlanConnect"/> function.
/// </summary>
/// <remarks>
/// Corresponds to the native <c>WLAN_CONNECTION_PARAMETERS</c> type.
/// </remarks>
[StructLayout(LayoutKind.Sequential)]
public struct WlanConnectionParameters
{
/// <summary>
/// Specifies the mode of connection.
/// </summary>
public WlanConnectionMode wlanConnectionMode;
/// <summary>
/// Specifies the profile being used for the connection.
/// The contents of the field depend on the <see cref="wlanConnectionMode"/>:
/// <list type="table">
/// <listheader>
/// <term>Value of <see cref="wlanConnectionMode"/></term>
/// <description>Contents of the profile string</description>
/// <description>The XML representation of the profile used for the connection.</description>
/// </item>
/// <item>
/// <term><see cref="WlanConnectionMode.DiscoverySecure"/>, <see cref="WlanConnectionMode.DiscoveryUnsecure"/> or <see cref="WlanConnectionMode.Auto"/></term>
/// <description><c>null</c></description>
/// </item>
/// </list>
/// </summary>
[MarshalAs(UnmanagedType.LPWStr)]
public string profile;
/// <summary>
/// Pointer to a <see cref="Dot11Ssid"/> structure that specifies the SSID of the network to connect to.
/// This field is optional. When set to <c>null</c>, all SSIDs in the profile will be tried.
/// This field must not be <c>null</c> if <see cref="wlanConnectionMode"/> is set to <see cref="WlanConnectionMode.DiscoverySecure"/> or <see cref="WlanConnectionMode.DiscoveryUnsecure"/>.
/// </summary>
public IntPtr dot11SsidPtr;
/// <summary>
/// Pointer to a <see cref="Dot11BssidList"/> structure that contains the list of basic service set (BSS) identifiers desired for the connection.
/// </summary>
/// <remarks>
/// On Windows XP SP2, must be set to <c>null</c>.
/// </remarks>
public IntPtr desiredBssidListPtr;
/// <summary>
/// A <see cref="Dot11BssType"/> 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.
/// </summary>
public Dot11BssType dot11BssType;
/// <summary>
/// Specifies ocnnection parameters.
/// </summary>
/// <remarks>
/// On Windows XP SP2, must be set to 0.
/// </remarks>
public WlanConnectionFlags flags;
}
/// <summary>
/// The connection state of an ad hoc network.
/// </summary>
public enum WlanAdhocNetworkState
{
/// <summary>
/// The ad hoc network has been formed, but no client or host is connected to the network.
/// </summary>
Formed = 0,
/// <summary>
/// A client or host is connected to the ad hoc network.
/// Specifies whether the network is infrastructure or ad hoc.
/// </summary>
public Dot11BssType dot11BssType;
public Dot11PhyType dot11BssPhyType;
/// <summary>
/// The received signal strength in dBm.
/// </summary>
public int rssi;
/// <summary>
/// The link quality reported by the driver. Ranges from 0-100.
/// </summary>
public uint linkQuality;
/// <summary>
/// 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.
/// </summary>
public bool inRegDomain;
/// <summary>
/// Contains the beacon interval value from the beacon packet or probe response.
/// </summary>
public ushort beaconPeriod;
/// <summary>
/// The timestamp from the beacon packet or probe response.
/// </summary>
public ulong timestamp;
/// <summary>
/// The host timestamp value when the beacon or probe response is received.
/// </summary>
public ulong hostTimestamp;
/// <summary>
/// The capability value from the beacon packet or probe response.
/// </summary>
public ushort capabilityInformation;
/// <summary>
/// The frequency of the center channel, in kHz.
/// </summary>
public uint chCenterFrequency;
/// <summary>
/// Contains the set of data transfer rates supported by the BSS.
/// </summary>
public WlanRateSet wlanRateSet;
/// <summary>
/// The offset of the information element (IE) data blob.
/// </summary>
public uint ieOffset;
/// <summary>
/// The size of the IE data blob, in bytes.
/// </summary>
public uint ieSize;
}
/// <summary>
/// Contains the set of supported data rates.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct WlanRateSet
{
/// <summary>
/// The length, in bytes, of <see cref="rateSet"/>.
/// </summary>
private uint rateSetLength;
/// <summary>
/// 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.
/// Indicates whether security is enabled for this connection.
/// </summary>
public bool securityEnabled;
/// <summary>
/// Indicates the reason for an operation failure.
/// This field has a value of <see cref="WlanReasonCode.Success"/> for all connection-related notifications except <see cref="WlanNotificationCodeAcm.ConnectionComplete"/>.
/// If the connection fails, this field indicates the reason for the failure.
/// </summary>
public WlanReasonCode wlanReasonCode;
/// <summary>
/// This field contains the XML presentation of the profile used for discovery, if the connection succeeds.
/// The position of the <see cref="Dot11PhyType"/> value in the structure containing the list of PHY types.
/// </summary>
public uint dot11PhyIndex;
/// <summary>
/// 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.
/// </summary>
public uint wlanSignalQuality;
/// <summary>
/// The receiving rate of the association.
/// </summary>
public uint rxRate;
/// <summary>
/// The transmission rate of the association.
/// </summary>
public uint txRate;
/// <summary>
/// Gets the BSSID of the associated access point.
/// </summary>
/// <value>The BSSID.</value>
public PhysicalAddress Dot11Bssid
{
get { return new PhysicalAddress(dot11Bssid); }
}
}
/// <summary>
/// Defines the mode of connection.
/// </summary>
/// <remarks>
/// Corresponds to the native <c>WLAN_CONNECTION_MODE</c> type.
/// </remarks>
public enum WlanConnectionMode
{
/// <summary>
/// A profile will be used to make the connection.
/// </summary>
Profile = 0,
/// <summary>
/// A temporary profile will be used to make the connection.
/// </summary>
TemporaryProfile,
/// <summary>
/// Secure discovery will be used to make the connection.
/// </summary>
DiscoverySecure,
/// <summary>
/// Unsecure discovery will be used to make the connection.
/// </summary>
DiscoveryUnsecure,
/// <summary>
/// A connection will be made automatically, generally using a persistent profile.
/// </summary>
Auto,
/// <summary>
/// Not used.
/// </summary>
Invalid
}
/// <summary>
/// Defines a wireless LAN authentication algorithm.
/// </summary>
/// <remarks>
/// Corresponds to the native <c>DOT11_AUTH_ALGORITHM</c> type.
/// </remarks>
public enum Dot11AuthAlgorithm : uint
{
/// <summary>
/// Specifies an IEEE 802.11 Open System authentication algorithm.
/// </summary>
IEEE80211_Open = 1,
/// <summary>
/// Specifies an 802.11 Shared Key authentication algorithm that requires the use of a pre-shared Wired Equivalent Privacy (WEP) key for the 802.11 authentication.
/// </summary>
IEEE80211_SharedKey = 2,
/// <summary>
/// Specifies a Wi-Fi Protected Access (WPA) algorithm. IEEE 802.1X port authentication is performed by the supplicant, authenticator, and authentication server. Cipher keys are dynamically derived through the authentication process.
/// <para>This algorithm is valid only for BSS types of <see cref="Dot11BssType.Infrastructure"/>.</para>
/// <para>When the WPA algorithm is enabled, the 802.11 station will associate only with an access point whose beacon or probe responses contain the authentication suite of type 1 (802.1X) within the WPA information element (IE).</para>
/// </summary>
WPA = 3,
/// <summary>
/// Specifies a WPA algorithm that uses preshared keys (PSK). IEEE 802.1X port authentication is performed by the supplicant and authenticator. Cipher keys are dynamically derived through a preshared key that is used on both the supplicant and authenticator.
/// <para>This algorithm is valid only for BSS types of <see cref="Dot11BssType.Infrastructure"/>.</para>
/// <para>When the WPA PSK algorithm is enabled, the 802.11 station will associate only with an access point whose beacon or probe responses contain the authentication suite of type 2 (preshared key) within the WPA IE.</para>
/// </summary>
WPA_PSK = 4,
/// <summary>
/// This value is not supported.
/// </summary>
WPA_None = 5,
/// <summary>
/// Specifies an 802.11i Robust Security Network Association (RSNA) algorithm. WPA2 is one such algorithm. IEEE 802.1X port authentication is performed by the supplicant, authenticator, and authentication server. Cipher keys are dynamically derived through the authentication process.
/// <para>This algorithm is valid only for BSS types of <see cref="Dot11BssType.Infrastructure"/>.</para>
/// <para>When the RSNA algorithm is enabled, the 802.11 station will associate only with an access point whose beacon or probe responses contain the authentication suite of type 1 (802.1X) within the RSN IE.</para>
/// </summary>
RSNA = 6,
/// <summary>
/// Specifies an 802.11i RSNA algorithm that uses PSK. IEEE 802.1X port authentication is performed by the supplicant and authenticator. Cipher keys are dynamically derived through a preshared key that is used on both the supplicant and authenticator.
/// <para>This algorithm is valid only for BSS types of <see cref="Dot11BssType.Infrastructure"/>.</para>
/// <para>When the RSNA PSK algorithm is enabled, the 802.11 station will associate only with an access point whose beacon or probe responses contain the authentication suite of type 2(preshared key) within the RSN IE.</para>
/// </summary>
RSNA_PSK = 7,
/// <summary>
/// Indicates the start of the range that specifies proprietary authentication algorithms that are developed by an IHV.
/// </summary>
/// <remarks>
/// This enumerator is valid only when the miniport driver is operating in Extensible Station (ExtSTA) mode.
/// </remarks>
IHV_Start = 0x80000000,
/// <summary>
/// Indicates the end of the range that specifies proprietary authentication algorithms that are developed by an IHV.
/// </summary>
/// <remarks>
/// This enumerator is valid only when the miniport driver is operating in Extensible Station (ExtSTA) mode.
/// </remarks>
IHV_End = 0xffffffff
}
/// <summary>
/// Defines a cipher algorithm for data encryption and decryption.
/// </summary>
/// <remarks>
/// Corresponds to the native <c>DOT11_CIPHER_ALGORITHM</c> type.
/// </remarks>
public enum Dot11CipherAlgorithm : uint
{
/// <summary>
/// Specifies that no cipher algorithm is enabled or supported.
/// </summary>
None = 0x00,
/// <summary>
/// Specifies a Wired Equivalent Privacy (WEP) algorithm, which is the RC4-based algorithm that is specified in the 802.11-1999 standard. This enumerator specifies the WEP cipher algorithm with a 40-bit cipher key.
/// </summary>
WEP40 = 0x01,
/// <summary>
/// Specifies a Temporal Key Integrity Protocol (TKIP) algorithm, which is the RC4-based cipher suite that is based on the algorithms that are defined in the WPA specification and IEEE 802.11i-2004 standard. This cipher also uses the Michael Message Integrity Code (MIC) algorithm for forgery protection.
/// </summary>
TKIP = 0x02,
/// <summary>
/// Specifies an AES-CCMP algorithm, as specified in the IEEE 802.11i-2004 standard and RFC 3610. Advanced Encryption Standard (AES) is the encryption algorithm defined in FIPS PUB 197.
/// </summary>
CCMP = 0x04,
/// <summary>
/// Specifies a WEP cipher algorithm with a 104-bit cipher key.
/// </summary>
WEP104 = 0x05,
/// <summary>
/// Specifies a Robust Security Network (RSN) Use Group Key cipher suite. For more information about the Use Group Key cipher suite, refer to Clause 7.3.2.9.1 of the IEEE 802.11i-2004 standard.
/// </summary>
WPA_UseGroup = 0x100,
/// <summary>
/// Specifies a Wifi Protected Access (WPA) Use Group Key cipher suite. For more information about the Use Group Key cipher suite, refer to Clause 7.3.2.9.1 of the IEEE 802.11i-2004 standard.
/// </summary>
RSN_UseGroup = 0x100,
/// <summary>
/// Specifies a WEP cipher algorithm with a cipher key of any length.
/// </summary>
WEP = 0x101,
/// <summary>
/// Specifies the start of the range that is used to define proprietary cipher algorithms that are developed by an independent hardware vendor (IHV).
/// </summary>
IHV_Start = 0x80000000,
/// <summary>
/// Specifies the end of the range that is used to define proprietary cipher algorithms that are developed by an IHV.
/// </summary>
IHV_End = 0xffffffff
}
/// <summary>
/// Defines the security attributes for a wireless connection.
/// </summary>
/// <remarks>
/// Corresponds to the native <c>WLAN_SECURITY_ATTRIBUTES</c> type.
/// </remarks>
[StructLayout(LayoutKind.Sequential)]
public struct WlanSecurityAttributes
{
/// <summary>
/// Indicates whether security is enabled for this connection.
/// </summary>
[MarshalAs(UnmanagedType.Bool)]
public bool securityEnabled;
[MarshalAs(UnmanagedType.Bool)]
public bool oneXEnabled;
/// <summary>
/// The authentication algorithm.
/// </summary>
public Dot11AuthAlgorithm dot11AuthAlgorithm;
/// <summary>
/// The cipher algorithm.
/// </summary>
public Dot11CipherAlgorithm dot11CipherAlgorithm;
}
/// <summary>
/// Defines the attributes of a wireless connection.
/// </summary>
/// <remarks>
/// Corresponds to the native <c>WLAN_CONNECTION_ATTRIBUTES</c> type.