Skip to content
Merged
Changes from 1 commit
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
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>
Comment thread
zandiarash marked this conversation as resolved.
/// <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. On ESP32 this corresponds to a failure of the native <c>esp_netif_set_hostname</c> call.</exception>
Comment thread
josesimoes marked this conversation as resolved.
Outdated
/// <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