Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Radio State of Wi-Fi Interface #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 52 additions & 4 deletions SimpleWifi/Win32/Interop/Enums.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace SimpleWifi.Win32.Interop
{
Expand Down Expand Up @@ -823,7 +821,57 @@ public enum Dot11OperationMode : uint
NetworkMonitor = 0x80000000
}


/// <summary>
/// Defines the radio state of a wireless connection.
/// </summary>
/// <remarks>
/// Corresponds to the native <c>DOT11_RADIO_STATE</c> enumeration.
/// </remarks>
public enum Dot11RadioState : uint
{
Unknown = 0,
On,
Off
}

/// <summary>
/// Defines the radio state attributes for a wireless connection.
/// </summary>
/// <remarks>
/// Corresponds to the native <c>WLAN_PHY_RADIO_STATE</c> structure.
/// </remarks>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct WlanPhyRadioState
{
public int dwPhyIndex;
public Dot11RadioState dot11SoftwareRadioState;
public Dot11RadioState dot11HardwareRadioState;
}

/// <summary>
/// Defines the radio state attributes for a wireless connection.
/// </summary>
/// <remarks>
/// Corresponds to the native <c>WLAN_RADIO_STATE</c> type.
/// </remarks>
[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;
}
}
}

/// <summary>
/// A set of flags that modify the behavior of the function: WlanSetProfileEapUserData
///
Expand Down
31 changes: 27 additions & 4 deletions SimpleWifi/Win32/WlanInterface.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -185,6 +183,31 @@ public int RSSI
}
}

/// <summary>
/// Gets the radio state.
/// </summary>
/// <value>The radio state.</value>
/// <remarks>Not supported on Windows XP.</remarks>
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);
}
}
}

/// <summary>
/// Gets the current operation mode.
/// </summary>
Expand Down