diff --git a/System.Device.Wifi/WifiAdapter.cs b/System.Device.Wifi/WifiAdapter.cs index a49c53f..23148fd 100644 --- a/System.Device.Wifi/WifiAdapter.cs +++ b/System.Device.Wifi/WifiAdapter.cs @@ -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; @@ -191,6 +191,29 @@ public static WifiAdapter[] FindAllAdapters() return adapters; } + /// + /// Sets the device name advertised by this Wi-Fi adapter when connecting to a network. + /// + /// The device name to assign to this adapter. + /// If is , empty or the length over 32 characters. + /// Thrown when the current firmware was built without Wi-Fi and setting the device name is not supported on this platform. + /// Thrown on platforms where setting the device name is not yet implemented. + /// Thrown when the underlying Wi-Fi stack rejects to specify device name. + /// + /// 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. + /// + public void SetDeviceName(string deviceName) + { + if (string.IsNullOrEmpty(deviceName) || deviceName.Length > 32) + { + throw new ArgumentException(); + } + + NativeSetDeviceName(deviceName); + } + /// /// Directs this adapter to initiate an asynchronous network scan. /// @@ -276,6 +299,9 @@ public void Dispose() [MethodImpl(MethodImplOptions.InternalCall)] private extern byte[] GetNativeScanReport(); + [MethodImpl(MethodImplOptions.InternalCall)] + private extern void NativeSetDeviceName(string deviceName); + #endregion }