diff --git a/.gitignore b/.gitignore index bdc3535..f96ea99 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,9 @@ TestResults ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. +# Visual Studio 2015 cache/options directory +.vs/ + # User-specific files *.suo *.user diff --git a/SimpleWifi/Win32/Interop/Enums.cs b/SimpleWifi/Win32/Interop/Enums.cs index 4e52f1b..4f4eb2c 100644 --- a/SimpleWifi/Win32/Interop/Enums.cs +++ b/SimpleWifi/Win32/Interop/Enums.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Runtime.InteropServices; namespace SimpleWifi.Win32.Interop { @@ -823,7 +821,57 @@ public enum Dot11OperationMode : uint NetworkMonitor = 0x80000000 } - + /// + /// Defines the radio state of a wireless connection. + /// + /// + /// Corresponds to the native DOT11_RADIO_STATE enumeration. + /// + public enum Dot11RadioState : uint + { + Unknown = 0, + On, + Off + } + + /// + /// Defines the radio state attributes for a wireless connection. + /// + /// + /// Corresponds to the native WLAN_PHY_RADIO_STATE structure. + /// + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + public struct WlanPhyRadioState + { + public int dwPhyIndex; + public Dot11RadioState dot11SoftwareRadioState; + public Dot11RadioState dot11HardwareRadioState; + } + + /// + /// Defines the radio state attributes for a wireless connection. + /// + /// + /// Corresponds to the native WLAN_RADIO_STATE type. + /// + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + public struct WlanRadioState + { + public int numberofItems; + + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] + private WlanPhyRadioState[] phyRadioState; + public WlanPhyRadioState[] PhyRadioState + { + get + { + WlanPhyRadioState[] ret = new WlanPhyRadioState[numberofItems]; + Array.Copy(phyRadioState, ret, numberofItems); + return ret; + } + } + } + /// /// A set of flags that modify the behavior of the function: WlanSetProfileEapUserData /// diff --git a/SimpleWifi/Win32/WlanInterface.cs b/SimpleWifi/Win32/WlanInterface.cs index 432228c..4c9e90e 100644 --- a/SimpleWifi/Win32/WlanInterface.cs +++ b/SimpleWifi/Win32/WlanInterface.cs @@ -1,11 +1,9 @@ -using SimpleWifi.Win32.Interop; -using System; +using System; using System.Collections.Generic; -using System.Linq; using System.Net.NetworkInformation; using System.Runtime.InteropServices; -using System.Text; using System.Threading; +using SimpleWifi.Win32.Interop; namespace SimpleWifi.Win32 { @@ -185,6 +183,31 @@ public int RSSI } } + /// + /// Gets the radio state. + /// + /// The radio state. + /// Not supported on Windows XP. + public WlanRadioState RadioState + { + get + { + int valueSize; + IntPtr valuePtr; + WlanOpcodeValueType opcodeValueType; + WlanInterop.ThrowIfError(WlanInterop.WlanQueryInterface(client.clientHandle, info.interfaceGuid, WlanIntfOpcode.RadioState, IntPtr.Zero, out valueSize, out valuePtr, out opcodeValueType)); + + try + { + return (WlanRadioState) Marshal.PtrToStructure(valuePtr, typeof(WlanRadioState)); + } + finally + { + WlanInterop.WlanFreeMemory(valuePtr); + } + } + } + /// /// Gets the current operation mode. ///