Skip to content
Merged
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
2 changes: 1 addition & 1 deletion System.Device.Wifi/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

////////////////////////////////////////////////////////////////
// update this whenever the native assembly signature changes //
[assembly: AssemblyNativeVersion("100.0.6.4")]
[assembly: AssemblyNativeVersion("100.0.6.5")]
////////////////////////////////////////////////////////////////

// Setting ComVisible to false makes the types in this assembly not visible
Expand Down
32 changes: 29 additions & 3 deletions System.Device.Wifi/WifiAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ private WifiAvailableNetwork[] ParseNativeReports(byte[] nativeReport)

byte[] rawSsid = new byte[33];
Array.Copy(nativeReport, bytePos, rawSsid, 0, 33);

int ssidLength = Array.IndexOf(rawSsid, (byte)0);
if (ssidLength < 0)
if (ssidLength < 0)
{
ssidLength = 33;
}

WifiNetworks[index].Ssid = Encoding.UTF8.GetString(rawSsid, 0, ssidLength);
bytePos += 33;

Expand Down Expand Up @@ -191,6 +191,29 @@ public static WifiAdapter[] FindAllAdapters()
return adapters;
}

/// <summary>
/// Sets the device name advertised by this Wi-Fi adapter when connecting to a network.
/// </summary>
/// <param name="deviceName">The device name to assign to this adapter.</param>
/// <exception cref="ArgumentException">If <paramref name="deviceName"/> is <see langword="null"/>, empty or the length over 32 characters.</exception>
/// <exception cref="NotSupportedException">Thrown when the current firmware was built without Wi-Fi and setting the device name is not supported on this platform.</exception>
/// <exception cref="NotImplementedException">Thrown on platforms where setting the device name is not yet implemented.</exception>
/// <exception cref="InvalidOperationException">Thrown when the underlying Wi-Fi stack rejects to specify device name.</exception>
/// <remarks>
/// The device name is sent to the access point during connection and may appear in the router’s
/// client list or DHCP lease table.
/// This method must be called before initiating a connection to take effect.
/// </remarks>
public void SetDeviceName(string deviceName)
{
if (string.IsNullOrEmpty(deviceName) || deviceName.Length > 32)
{
throw new ArgumentException();
}

NativeSetDeviceName(deviceName);
}

/// <summary>
/// Directs this adapter to initiate an asynchronous network scan.
/// </summary>
Expand Down Expand Up @@ -276,6 +299,9 @@ public void Dispose()
[MethodImpl(MethodImplOptions.InternalCall)]
private extern byte[] GetNativeScanReport();

[MethodImpl(MethodImplOptions.InternalCall)]
private extern void NativeSetDeviceName(string deviceName);

#endregion

}
Expand Down