Skip to content

Commit 6c6d5cb

Browse files
committed
Wifi DeviceName added
1 parent a75ab03 commit 6c6d5cb

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

System.Device.Wifi/WifiAdapter.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ private WifiAvailableNetwork[] ParseNativeReports(byte[] nativeReport)
9494

9595
byte[] rawSsid = new byte[33];
9696
Array.Copy(nativeReport, bytePos, rawSsid, 0, 33);
97-
97+
9898
int ssidLength = Array.IndexOf(rawSsid, (byte)0);
99-
if (ssidLength < 0)
99+
if (ssidLength < 0)
100100
{
101101
ssidLength = 33;
102102
}
103-
103+
104104
WifiNetworks[index].Ssid = Encoding.UTF8.GetString(rawSsid, 0, ssidLength);
105105
bytePos += 33;
106106

@@ -191,6 +191,26 @@ public static WifiAdapter[] FindAllAdapters()
191191
return adapters;
192192
}
193193

194+
/// <summary>
195+
/// Sets the device name advertised by this Wi-Fi adapter when connecting to a network.
196+
/// </summary>
197+
/// <param name="deviceName">The device Name to assign to the adapter.</param>
198+
/// <exception cref="ArgumentException">If <paramref name="deviceName"/> is null or empty or the length more than 32 characters</exception>
199+
/// <remarks>
200+
/// The deviceName is sent to the access point during connection and may appear in the router’s
201+
/// client list or DHCP lease table.
202+
/// This method must be called before initiating a connection to take effect.
203+
/// </remarks>
204+
public void SetDeviceName(string deviceName)
205+
{
206+
if (string.IsNullOrEmpty(deviceName) || deviceName.Length > 32)
207+
{
208+
throw new ArgumentException();
209+
}
210+
211+
NativeSetDeviceName(deviceName);
212+
}
213+
194214
/// <summary>
195215
/// Directs this adapter to initiate an asynchronous network scan.
196216
/// </summary>
@@ -276,6 +296,9 @@ public void Dispose()
276296
[MethodImpl(MethodImplOptions.InternalCall)]
277297
private extern byte[] GetNativeScanReport();
278298

299+
[MethodImpl(MethodImplOptions.InternalCall)]
300+
private extern void NativeSetDeviceName(string deviceName);
301+
279302
#endregion
280303

281304
}

0 commit comments

Comments
 (0)