internal IEnumerable <WiFiAP> GetFoundSpecificAPs() { Log.Debug(Globals.LogTag, "GetFoundSpecificAPs"); List <WiFiAP> apList = new List <WiFiAP>(); Interop.WiFi.HandleCallback callback = (IntPtr apHandle, IntPtr userData) => { if (apHandle != IntPtr.Zero) { IntPtr clonedHandle; Interop.WiFi.AP.Clone(out clonedHandle, apHandle); WiFiAP apItem = new WiFiAP(clonedHandle); apList.Add(apItem); return(true); } return(false); }; int ret = Interop.WiFi.GetForeachFoundSpecificAPs(GetSafeHandle(), callback, IntPtr.Zero); if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Failed to get specific APs, Error - " + (WiFiError)ret); WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle(), "http://tizen.org/privilege/network.get"); } return(apList); }
internal WiFiAP GetConnectedAP() { Log.Info(Globals.LogTag, "GetConnectedAP"); IntPtr apHandle; int ret = Interop.WiFi.GetConnectedAP(GetSafeHandle(), out apHandle); if (ret != (int)WiFiError.None) { if (ret == (int)WiFiError.NoConnectionError) { Log.Error(Globals.LogTag, "No connection " + (WiFiError)ret); return(null); } else if (ret == (int)WiFiError.InvalidParameterError) { throw new InvalidOperationException("Invalid handle"); } else { Log.Error(Globals.LogTag, "Failed to get connected AP, Error - " + (WiFiError)ret); WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle(), "http://tizen.org/privilege/network.get"); } } WiFiAP ap = new WiFiAP(apHandle); return(ap); }
/// <summary> /// Gets the Bssid list. /// </summary> /// <since_tizen> 5 </since_tizen> /// <returns>A list of BSSIDs of access points with the same SSID as that of this access point.</returns> /// <feature>http://tizen.org/feature/network.wifi</feature> /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception> /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception> public IEnumerable <string> GetBssids() { Log.Debug(Globals.LogTag, "GetBssids"); List <string> bssidList = new List <string>(); Interop.WiFi.AP.FoundBssidCallback callback = (string bssid, int rssi, int freq, IntPtr userData) => { if (string.IsNullOrEmpty(bssid)) { bssidList.Add(bssid); return(true); } return(false); }; int ret = Interop.WiFi.AP.GetBssids(_apHandle, callback, IntPtr.Zero); if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Failed to get BSSIDs, Error - " + (WiFiError)ret); if (ret == (int)WiFiError.InvalidParameterError) { throw new InvalidOperationException("Invalid handle"); } WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle()); } return(bssidList); }
private void createHandle(string id, bool hidden) { int ret = -1; if (id == null) { throw new ArgumentNullException("Essid is null"); } if (hidden) { ret = Interop.WiFi.AP.CreateHiddenAP(WiFiManagerImpl.Instance.GetSafeHandle(), id, out _apHandle); } else { ret = Interop.WiFi.AP.Create(WiFiManagerImpl.Instance.GetSafeHandle(), id, out _apHandle); } if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Failed to create handle, Error - " + (WiFiError)ret); WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle()); } }
/// <summary> /// Gets all IPv6 addresses of the access point. /// </summary> /// <since_tizen> 3 </since_tizen> /// <returns>A list of IPv6 addresses of the access point.</returns> /// <feature>http://tizen.org/feature/network.wifi</feature> /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception> /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception> /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception> public IEnumerable <System.Net.IPAddress> GetAllIPv6Addresses() { Log.Debug(Globals.LogTag, "GetAllIPv6Addresses"); List <System.Net.IPAddress> ipList = new List <System.Net.IPAddress>(); Interop.WiFi.HandleCallback callback = (IntPtr ipv6Address, IntPtr userData) => { if (ipv6Address != IntPtr.Zero) { string ipv6 = Marshal.PtrToStringAnsi(ipv6Address); if (ipv6.Length == 0) { ipList.Add(System.Net.IPAddress.Parse("::")); } else { ipList.Add(System.Net.IPAddress.Parse(ipv6)); } return(true); } return(false); }; int ret = Interop.WiFi.AP.GetAllIPv6Addresses(_apHandle, callback, IntPtr.Zero); if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Failed to get all IPv6 addresses, Error - " + (WiFiError)ret); WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle()); } return(ipList); }
internal IEnumerable <WiFiConfiguration> GetWiFiConfigurations() { Log.Debug(Globals.LogTag, "GetWiFiConfigurations"); List <WiFiConfiguration> configList = new List <WiFiConfiguration>(); Interop.WiFi.HandleCallback callback = (IntPtr configHandle, IntPtr userData) => { if (configHandle != IntPtr.Zero) { IntPtr clonedConfig; Interop.WiFi.Config.Clone(configHandle, out clonedConfig); WiFiConfiguration configItem = new WiFiConfiguration(clonedConfig); configList.Add(configItem); return(true); } return(false); }; int ret = Interop.WiFi.Config.GetForeachConfiguration(GetSafeHandle(), callback, IntPtr.Zero); if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Failed to get configurations, Error - " + (WiFiError)ret); WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle(), "http://tizen.org/privilege/network.profile"); } return(configList); }
/// <summary> /// Connects the access point with WPS without SSID asynchronously. /// </summary> /// <since_tizen> 3 </since_tizen> /// <param name="info">A WpsInfo instance which is of type WpsPbcInfo or WpsPinInfo.</param> /// <returns>A task which contains Connected access point information.</returns> /// <remarks> /// If WpsPinInfo is used, its object has to be constructed with a pin which must be 4 or 8 characters long. /// </remarks> /// <feature>http://tizen.org/feature/network.wifi</feature> /// <privilege>http://tizen.org/privilege/network.set</privilege> /// <privilege>http://tizen.org/privilege/network.get</privilege> /// <privilege>http://tizen.org/privilege/network.profile</privilege> /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception> /// <exception cref="ArgumentNullException">Thrown when the WpsPinInfo object is constructed with a null pin.</exception> /// <exception cref="ArgumentOutOfRangeException">Thrown when the WpsPinInfo object is constructed with a pin which is not of 4 or 8 characters long.</exception> /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception> /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception> /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception> public static Task <WiFiAP> ConnectWpsWithoutSsidAsync(WpsInfo info) { TaskCompletionSource <WiFiAP> task = new TaskCompletionSource <WiFiAP>(); IntPtr id; lock (s_callbackMap) { id = (IntPtr)s_requestId++; s_callbackMap[id] = (error, key) => { Log.Debug(Globals.LogTag, "Connecting by WPS finished"); if (error != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Error occurs during WiFi connecting, " + (WiFiError)error); task.SetException(new InvalidOperationException("Error occurs during WiFi connecting, " + (WiFiError)error)); } else { WiFiAP ap = WiFiManagerImpl.Instance.GetConnectedAP(); task.SetResult(ap); } lock (s_callbackMap) { s_callbackMap.Remove(key); } }; } int ret = -1; if (info.GetType() == typeof(WpsPbcInfo)) { ret = Interop.WiFi.ConnectByWpsPbcWithoutSsid(WiFiManagerImpl.Instance.GetSafeHandle(), s_callbackMap[id], id); } else if (info.GetType() == typeof(WpsPinInfo)) { WpsPinInfo pinInfo = (WpsPinInfo)info; if (pinInfo.GetWpsPin() == null) { throw new ArgumentNullException("Wps pin should not be null"); } if (pinInfo.GetWpsPin().Length != 4 && pinInfo.GetWpsPin().Length != 8) { throw new ArgumentOutOfRangeException("Wps pin should be of 4 or 8 characters long"); } ret = Interop.WiFi.ConnectByWpsPinWithoutSsid(WiFiManagerImpl.Instance.GetSafeHandle(), pinInfo.GetWpsPin(), s_callbackMap[id], id); } if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Failed to connect wifi, Error - " + (WiFiError)ret); WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle()); } return(task.Task); }
/// <summary> /// Deletes the information of a stored access point and disconnects it when the AP is connected asyncronously. /// If an AP is connected, then the connection information will be stored. This information is used when a connection to that AP is established automatically. /// </summary> /// <returns> A task indicating whether the disconnect method is done or not.</returns> /// <remarks> /// This method must be called from MainThread. /// </remarks> /// <since_tizen> 5 </since_tizen> /// <feature>http://tizen.org/feature/network.wifi</feature> /// <privilege>http://tizen.org/privilege/network.profile</privilege> /// <privilege>http://tizen.org/privilege/network.get</privilege> /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception> /// <exception cref="ObjectDisposedException">Thrown when the object instance is disposed or released.</exception> /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception> public Task ForgetAPAsync() { Log.Debug(Globals.LogTag, "ForgetAPAsync"); if (_disposed) { throw new ObjectDisposedException("Invalid AP instance (Object may have been disposed or released)"); } TaskCompletionSource <bool> task = new TaskCompletionSource <bool>(); IntPtr id; lock (_callback_map) { id = (IntPtr)_requestId++; _callback_map[id] = (error, key) => { Log.Info(Globals.LogTag, "ForgetAPAsync done"); if (error != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Error occurs during WiFi disconnecting, " + (WiFiError)error); task.SetException(new InvalidOperationException("Error occurs during WiFi disconnecting, " + (WiFiError)error)); } else { task.SetResult(true); } lock (_callback_map) { _callback_map.Remove(key); } }; } context.Post((x) => { Log.Info(Globals.LogTag, "Interop.WiFi.ForgetAP"); try { int ret = Interop.WiFi.ForgetAP(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, _callback_map[id], id); if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Failed to forget wifi, Error - " + (WiFiError)ret); if (ret == (int)WiFiError.InvalidParameterError) { throw new InvalidOperationException("Invalid handle"); } WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle); } } catch (Exception e) { Log.Error(Globals.LogTag, "Exception on ForgetAPAsync\n" + e); task.SetException(e); } }, null); return(task.Task); }
/// <summary> /// Sets the access point client certificate file to configuration. /// </summary> /// <since_tizen> 3 </since_tizen> /// <param name="privateKey">The private key file.</param> /// <param name="clientCert">The certification authority(CA) certifies the files of access points.</param> /// <feature>http://tizen.org/feature/network.wifi</feature> /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception> /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception> /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception> public void SetClientCertFile(string privateKey, string clientCert) { int ret = Interop.WiFi.Config.SetEapClientCertFile(_configHandle, privateKey, clientCert); if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Failed to set client cert file, Error - " + (WiFiError)ret); WiFiErrorFactory.ThrowWiFiException(ret, _configHandle.DangerousGetHandle()); } }
internal Task BssidScanAsync() { Log.Info(Globals.LogTag, "BssidScanAsync"); TaskCompletionSource <bool> task = new TaskCompletionSource <bool>(); IntPtr id; lock (_callback_map) { id = (IntPtr)_requestId++; _callback_map[id] = (error, key) => { Log.Info(Globals.LogTag, "BssidScanAsync done"); if (error != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Error occurs during bssid scanning, " + (WiFiError)error); task.SetException(new InvalidOperationException("Error occurs during bssid scanning, " + (WiFiError)error)); } else { task.SetResult(true); } lock (_callback_map) { _callback_map.Remove(key); } }; } context.Post((x) => { Log.Info(Globals.LogTag, "Interop.WiFi.BssidScan"); try { int ret = Interop.WiFi.BssidScan(GetSafeHandle(), _callback_map[id], id); if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Failed to scan Bssid AP, Error - " + (WiFiError)ret); if (ret == (int)WiFiError.InvalidParameterError) { throw new InvalidOperationException("Invalid handle"); } WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle()); } } catch (Exception e) { Log.Error(Globals.LogTag, "Exception on BssidScan\n" + e.ToString()); task.SetException(e); } }, null); return(task.Task); }
internal SafeWiFiManagerHandle Initialize() { SafeWiFiManagerHandle handle; int ret = Interop.WiFi.Initialize(out handle); if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Failed to initialize wifi, Error - " + (WiFiError)ret); WiFiErrorFactory.ThrowWiFiException(ret, "http://tizen.org/privilege/network.get"); } return(handle); }
private void CheckReturnValue(int ret, string method, string privilege) { if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, method + " Fail, Error - " + (WiFiError)ret); if (ret == (int)WiFiError.InvalidParameterError) { throw new InvalidOperationException("Invalid handle"); } WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle(), privilege); } }
/// <summary> /// Gets the access point client certificate file from the configuration. /// </summary> /// <since_tizen> 3 </since_tizen> /// <returns>The certification authority (CA) certificates file of the access point.</returns> /// <feature>http://tizen.org/feature/network.wifi</feature> /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception> /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception> /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception> public string GetClientCertFile() { IntPtr strPtr; int ret = Interop.WiFi.Config.GetEapClientCertFile(_configHandle, out strPtr); if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Failed to get client cert file, Error - " + (WiFiError)ret); WiFiErrorFactory.ThrowWiFiException(ret, _configHandle.DangerousGetHandle()); } return(Marshal.PtrToStringAnsi(strPtr)); }
/// <summary> /// Gets the private key file of EAP. /// </summary> /// <since_tizen> 3 </since_tizen> /// <returns>The file path of private key.</returns> /// <feature>http://tizen.org/feature/network.wifi</feature> /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception> /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception> /// <exception cref="ArgumentException">Thrown when the method fails due to an invalid parameter.</exception> /// <exception cref="InvalidOperationException">Thrown when the method fails due to an invalid operation.</exception> public string GetPrivateKeyFile() { IntPtr strPtr; int ret = Interop.WiFi.AP.GetEapPrivateKeyFile(_apHandle, out strPtr); if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Failed to get private key file, Error - " + (WiFiError)ret); WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle()); } return(Marshal.PtrToStringAnsi(strPtr)); }
/// <summary> /// Gets the username of EAP passphrase. /// </summary> /// <since_tizen> 3 </since_tizen> /// <returns>The user name</returns> /// <feature>http://tizen.org/feature/network.wifi</feature> /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception> /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception> /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception> /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception> public string GetUserName() { IntPtr strptr; bool passwordSet; int ret = Interop.WiFi.AP.GetEapPassphrase(_apHandle, out strptr, out passwordSet); if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Failed to get user name in eap passphrase, Error - " + (WiFiError)ret); WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle()); } return(Marshal.PtrToStringAnsi(strptr)); }
/// <summary> /// Returns whether the password is set or not. /// </summary> /// <since_tizen> 3 </since_tizen> /// <returns>True if password is set, false if password is not set.</returns> /// <feature>http://tizen.org/feature/network.wifi</feature> /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception> /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception> /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception> /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception> public bool IsPasswordSet() { IntPtr strptr; bool passwordSet; int ret = Interop.WiFi.AP.GetEapPassphrase(_apHandle, out strptr, out passwordSet); if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Failed to get IsPasswordSet in passphrase, Error - " + (WiFiError)ret); WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle()); } return(passwordSet); }
/// <summary> /// Sets the password of EAP. /// </summary> /// <since_tizen> 3 </since_tizen> /// <param name="password">The password</param> /// <feature>http://tizen.org/feature/network.wifi</feature> /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception> /// <exception cref="ArgumentNullException">Thrown when the password is passed as null.</exception> /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception> /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception> public void SetPassword(string password) { if (password == null) { throw new ArgumentNullException("Password is null"); } int ret = Interop.WiFi.AP.SetEapPassphrase(_apHandle, null, password); if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Failed to set password, Error - " + (WiFiError)ret); WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle()); } }
/// <summary> /// Sets the user name of EAP. /// </summary> /// <since_tizen> 3 </since_tizen> /// <param name="userName">The user name</param> /// <feature>http://tizen.org/feature/network.wifi</feature> /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception> /// <exception cref="ArgumentNullException">Thrown when the user name is passed as null.</exception> /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception> /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception> public void SetUserName(string userName) { if (userName == null) { throw new ArgumentNullException("User name is null"); } int ret = Interop.WiFi.AP.SetEapPassphrase(_apHandle, userName, null); if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Failed to set username, Error - " + (WiFiError)ret); WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle()); } }
/// <summary> /// Sets the private key information of EAP. /// </summary> /// <since_tizen> 3 </since_tizen> /// <param name="privateKeyFile">The file path of private key.</param> /// <param name="password">The password.</param> /// <feature>http://tizen.org/feature/network.wifi</feature> /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception> /// <exception cref="ArgumentNullException">Thrown when the file path of private key is null.</exception> /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception> /// <exception cref="InvalidOperationException">Thrown when the method failed due an to invalid operation.</exception> public void SetPrivateKeyFile(string privateKeyFile, string password) { if (privateKeyFile == null) { throw new ArgumentNullException("File path of private key is null"); } int ret = Interop.WiFi.AP.SetEapPrivateKeyFile(_apHandle, privateKeyFile, password); if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Failed to set private key file, Error - " + (WiFiError)ret); WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle()); } }
/// <summary> /// Sets the CA certificate of EAP. /// </summary> /// <since_tizen> 3 </since_tizen> /// <param name="clientCertFile">The file path of client certificate.</param> /// <feature>http://tizen.org/feature/network.wifi</feature> /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception> /// <exception cref="ArgumentNullException">Thrown when the file path of client certificate is null.</exception> /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception> /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception> public void SetClientCertFile(string clientCertFile) { if (clientCertFile == null) { throw new ArgumentNullException("File path of Client certificate is null"); } int ret = Interop.WiFi.AP.SetEapClientCertFile(_apHandle, clientCertFile); if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Failed to set client cert file, Error - " + (WiFiError)ret); WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle()); } }
internal Task ScanSpecificAPAsync(string essid) { Log.Info(Globals.LogTag, "ScanSpecificAPAsync " + essid); TaskCompletionSource <bool> task = new TaskCompletionSource <bool>(); IntPtr id; lock (_callback_map) { id = (IntPtr)_requestId++; _callback_map[id] = (error, key) => { Log.Info(Globals.LogTag, "ScanSpecificAPAsync Done " + essid); if (error != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Error occurs during WiFi scanning, " + (WiFiError)error); task.SetException(new InvalidOperationException("Error occurs during WiFi scanning, " + (WiFiError)error)); } else { task.SetResult(true); } lock (_callback_map) { _callback_map.Remove(key); } }; } context.Post((x) => { Log.Info(Globals.LogTag, "Interop.WiFi.ScanSpecificAPAsync"); try { int ret = Interop.WiFi.ScanSpecificAP(GetSafeHandle(), essid, _callback_map[id], id); if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Failed to scan with specific AP, Error - " + (WiFiError)ret); WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle()); } } catch (Exception e) { Log.Error(Globals.LogTag, "Exception on ScanSpecificAPAsync\n" + e.ToString()); task.SetException(e); } }, null); return(task.Task); }
/// <summary> /// Update the information of a stored access point. /// When a AP information is changed, the change will not be applied until this method is called. /// </summary> /// <since_tizen> 5 </since_tizen> /// <feature>http://tizen.org/feature/network.wifi</feature> /// <privilege>http://tizen.org/privilege/network.profile</privilege> /// <privilege>http://tizen.org/privilege/network.get</privilege> /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception> /// <exception cref="ObjectDisposedException">Thrown when the object instance is disposed or released.</exception> /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception> /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception> public void Update() { Log.Debug(Globals.LogTag, "Update"); if (_disposed) { throw new ObjectDisposedException("Invalid AP instance (Object may have been disposed or released)"); } int ret = Interop.WiFi.UpdateAP(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle); if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Failed to update AP, Error - " + (WiFiError)ret); WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle); } }
/// <summary> /// Refreshes the access point information. /// </summary> /// <since_tizen> 3 </since_tizen> /// <feature>http://tizen.org/feature/network.wifi</feature> /// <privilege>http://tizen.org/privilege/network.get</privilege> /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception> /// <exception cref="ObjectDisposedException">Thrown when the object instance is disposed or released.</exception> /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception> /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception> public void Refresh() { Log.Debug(Globals.LogTag, "Refresh"); if (_disposed) { throw new ObjectDisposedException("Invalid AP instance (Object may have been disposed or released)"); } int ret = Interop.WiFi.AP.Refresh(_apHandle); if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Failed to refresh ap handle, Error - " + (WiFiError)ret); WiFiErrorFactory.ThrowWiFiException(ret, _apHandle, "http://tizen.org/privilege/network.get"); } }
/// <summary> /// Gets the client certificate of EAP. /// </summary> /// <since_tizen> 3 </since_tizen> /// <returns>The file path of client certificate.</returns> /// <feature>http://tizen.org/feature/network.wifi</feature> /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception> /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception> /// <exception cref="InvalidOperationException">Thrown when the method failed due an to invalid operation.</exception> public string GetClientCertFile() { IntPtr strPtr; int ret = Interop.WiFi.AP.GetEapClientCertFile(_apHandle, out strPtr); if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Failed to get client cert file, Error - " + (WiFiError)ret); if (ret == (int)WiFiError.InvalidParameterError) { throw new InvalidOperationException("Invalid handle"); } WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle()); } return(Marshal.PtrToStringAnsi(strPtr)); }
internal SafeWiFiManagerHandle Initialize() { SafeWiFiManagerHandle handle; int tid = Thread.CurrentThread.ManagedThreadId; Log.Info(Globals.LogTag, "PInvoke wifi_manager_initialize"); int ret = Interop.WiFi.Initialize(tid, out handle); if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Failed to initialize wifi, Error - " + (WiFiError)ret); WiFiErrorFactory.ThrowWiFiException(ret, "http://tizen.org/privilege/network.get"); } handle.SetTID(tid); return(handle); }
internal void SaveWiFiNetworkConfiguration(WiFiConfiguration config) { Log.Debug(Globals.LogTag, "SaveWiFiNetworkConfiguration"); if (config == null) { throw new ArgumentNullException("WiFi configuration is null"); } IntPtr configHandle = config.GetHandle(); int ret = Interop.WiFi.Config.SaveConfiguration(GetSafeHandle(), configHandle); if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Failed to save configuration, Error - " + (WiFiError)ret); WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle(), "http://tizen.org/privilege/network.profile"); } }
/// <summary> /// Creates a WiFiConfiguration object with the given name, passphrase, and securetype. /// </summary> /// <since_tizen> 3 </since_tizen> /// <param name="name">Name of the Wi-Fi.</param> /// <param name="passPhrase">Password to access the Wi-Fi.</param> /// <param name="type">Security type of the Wi-Fi.</param> /// <feature>http://tizen.org/feature/network.wifi</feature> /// <privilege>http://tizen.org/privilege/network.get</privilege> /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception> /// <exception cref="ArgumentNullException">Thrown when the object is constructed with name as null.</exception> /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception> /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception> /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception> public WiFiConfiguration(string name, string passPhrase, WiFiSecurityType type) { if (name == null) { throw new ArgumentNullException("Name of the WiFi is null"); } int ret = Interop.WiFi.Config.Create(WiFiManagerImpl.Instance.GetSafeHandle(), name, passPhrase, (int)type, out _configHandle); if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Failed to create config handle, Error - " + (WiFiError)ret); WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle()); } Interop.WiFi.SafeWiFiConfigHandle configHandle = new Interop.WiFi.SafeWiFiConfigHandle(_configHandle); _eapConfig = new WiFiEapConfiguration(configHandle); }
/// <summary> /// Deletes the information of a stored access point and disconnects it when the AP is connected. /// If an AP is connected, then the connection information will be stored. This information is used when a connection to that AP is established automatically. /// </summary> /// <since_tizen> 3 </since_tizen> /// <feature>http://tizen.org/feature/network.wifi</feature> /// <privilege>http://tizen.org/privilege/network.profile</privilege> /// <privilege>http://tizen.org/privilege/network.get</privilege> /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception> /// <exception cref="ObjectDisposedException">Thrown when the object instance is disposed or released.</exception> /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception> /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception> public void ForgetAP() { Log.Debug(Globals.LogTag, "ForgetAP"); if (_disposed) { throw new ObjectDisposedException("Invalid AP instance (Object may have been disposed or released)"); } int ret = Interop.WiFi.RemoveAP(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle); if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Failed to forget AP, Error - " + (WiFiError)ret); if (ret == (int)WiFiError.InvalidParameterError) { throw new InvalidOperationException("Invalid handle"); } WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle); } }
/// <summary> /// Connects the access point asynchronously. /// </summary> /// <since_tizen> 3 </since_tizen> /// <returns> A task indicating whether the connect method is done or not.</returns> /// <feature>http://tizen.org/feature/network.wifi</feature> /// <privilege>http://tizen.org/privilege/network.set</privilege> /// <privilege>http://tizen.org/privilege/network.get</privilege> /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception> /// <exception cref="ObjectDisposedException">Thrown when the object instance is disposed or released.</exception> /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception> /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception> /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception> public Task ConnectAsync() { Log.Debug(Globals.LogTag, "ConnectAsync"); if (_disposed) { throw new ObjectDisposedException("Invalid AP instance (Object may have been disposed or released)"); } TaskCompletionSource <bool> task = new TaskCompletionSource <bool>(); IntPtr id; lock (_callback_map) { id = (IntPtr)_requestId++; _callback_map[id] = (error, key) => { Log.Debug(Globals.LogTag, "Connecting finished : " + (WiFiError)error); if (error != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Error occurs during WiFi connecting, " + (WiFiError)error); task.SetException(new InvalidOperationException("Error occurs during WiFi connecting, " + (WiFiError)error)); } else { task.SetResult(true); } lock (_callback_map) { _callback_map.Remove(key); } }; } int ret = Interop.WiFi.Connect(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, _callback_map[id], id); if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Failed to connect wifi, Error - " + (WiFiError)ret); WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle); } return(task.Task); }
/// <summary> /// Stops ongoing WPS provisioning /// </summary> /// <since_tizen> 5 </since_tizen> /// <feature>http://tizen.org/feature/network.wifi</feature> /// <privilege>http://tizen.org/privilege/network.set</privilege> /// <privilege>http://tizen.org/privilege/network.get</privilege> /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception> /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception> /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception> public static void CancelWps() { Log.Debug(Globals.LogTag, "CancelWps"); int ret = Interop.WiFi.CancelWps(WiFiManagerImpl.Instance.GetSafeHandle()); if (ret != (int)WiFiError.None) { Log.Error(Globals.LogTag, "Failed to cancel Wps, Error - " + (WiFiError)ret); WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle()); } // Cancel awaiting tasks if (wpsWithoutSsidTask != null) { Log.Info(Globals.LogTag, "Cancel ConnectWpsWithoutSsidAsync()"); wpsWithoutSsidTask.SetCanceled(); } foreach (var item in _wpsTaskMap) { Log.Info(Globals.LogTag, "Cancel ConnectWpsAsync() by " + item.Key.GetHashCode()); item.Value.SetCanceled(); } _wpsTaskMap.Clear(); }