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

Added usage of passwords with invalid XML characters #25

Open
wants to merge 7 commits 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
4 changes: 2 additions & 2 deletions SimpleWifi/AccessPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public string Name
{
get
{
return Encoding.ASCII.GetString(_network.dot11Ssid.SSID, 0, (int)_network.dot11Ssid.SSIDLength);
return Encoding.UTF8.GetString(_network.dot11Ssid.SSID, 0, (int)_network.dot11Ssid.SSIDLength);
}
}

Expand Down Expand Up @@ -70,7 +70,7 @@ public bool IsConnected
try
{
var a = _interface.CurrentConnection; // This prop throws exception if not connected, which forces me to this try catch. Refactor plix.
return a.profileName == _network.profileName;
return a.profileName == _network.profileName && a.isState == WlanInterfaceState.Connected;
}
catch
{
Expand Down
2 changes: 2 additions & 0 deletions SimpleWifi/ProfileFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ internal static string Generate(WlanAvailableNetwork network, string password)
string name = Encoding.ASCII.GetString(network.dot11Ssid.SSID, 0, (int)network.dot11Ssid.SSIDLength);
string hex = GetHexString(network.dot11Ssid.SSID);

password = System.Security.SecurityElement.Escape(password);

var authAlgo = network.dot11DefaultAuthAlgorithm;

switch (network.dot11DefaultCipherAlgorithm)
Expand Down
29 changes: 21 additions & 8 deletions SimpleWifi/Win32/Interop/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -823,14 +823,27 @@ public enum Dot11OperationMode : uint
NetworkMonitor = 0x80000000
}


/// <summary>
/// A set of flags that modify the behavior of the function: WlanSetProfileEapUserData
///
/// On Windows Vista and Windows Server 2008, this parameter is reserved and should be set to zero.
/// On Windows 7, Windows Server 2008 R2, and later, this parameter can be one of the following values.
/// </summary>
[Flags]
/// <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>
/// A set of flags that modify the behavior of the function: WlanSetProfileEapUserData
///
/// On Windows Vista and Windows Server 2008, this parameter is reserved and should be set to zero.
/// On Windows 7, Windows Server 2008 R2, and later, this parameter can be one of the following values.
/// </summary>
[Flags]
public enum SetEapUserDataMode : uint
{
None = 0x00000000,
Expand Down
40 changes: 39 additions & 1 deletion SimpleWifi/Win32/Interop/Structs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,45 @@ public struct WlanProfileInfo
public WlanProfileFlags profileFlags;
}

/*
/// <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>
/// The EAP_METHOD_TYPE structure contains type, identification, and author information about an EAP method.
/// </summary>
Expand Down
70 changes: 68 additions & 2 deletions SimpleWifi/Win32/WlanInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -633,5 +633,71 @@ private int GetInterfaceInt(WlanIntfOpcode opCode)
WlanInterop.WlanFreeMemory(valuePtr);
}
}
}
}

/// <summary>
/// Turn on WiFi.
/// </summary>
public void TurnOnWiFi()
{
IntPtr radioStatePtr = IntPtr.Zero;

try
{
WlanPhyRadioState radioState = new WlanPhyRadioState
{
dwPhyIndex = 0,
dot11HardwareRadioState = Dot11RadioState.On,
dot11SoftwareRadioState = Dot11RadioState.On
};

radioStatePtr = Marshal.AllocHGlobal(Marshal.SizeOf(radioState));
Marshal.StructureToPtr(radioState, radioStatePtr, false);

WlanInterop.ThrowIfError(WlanInterop.WlanSetInterface(
client.clientHandle,
info.interfaceGuid,
WlanIntfOpcode.RadioState,
(uint)Marshal.SizeOf(typeof(WlanPhyRadioState)),
radioStatePtr,
IntPtr.Zero));
}
finally
{
Marshal.FreeHGlobal(radioStatePtr);
}
}

/// <summary>
/// Turn off WiFi.
/// </summary>
public void TurnOffWiFi()
{
IntPtr radioStatePtr = IntPtr.Zero;

try
{
WlanPhyRadioState radioState = new WlanPhyRadioState
{
dwPhyIndex = 0,
dot11HardwareRadioState = Dot11RadioState.Off,
dot11SoftwareRadioState = Dot11RadioState.Off
};

radioStatePtr = Marshal.AllocHGlobal(Marshal.SizeOf(radioState));
Marshal.StructureToPtr(radioState, radioStatePtr, false);

WlanInterop.ThrowIfError(WlanInterop.WlanSetInterface(
client.clientHandle,
info.interfaceGuid,
WlanIntfOpcode.RadioState,
(uint)Marshal.SizeOf(typeof(WlanPhyRadioState)),
radioStatePtr,
IntPtr.Zero));
}
finally
{
Marshal.FreeHGlobal(radioStatePtr);
}
}
}
}