From d5df07d873e12f0eccd61558fb137420ecaf8123 Mon Sep 17 00:00:00 2001 From: akash1-kumar <115205462+akash1-kumar@users.noreply.github.com> Date: Wed, 12 Jun 2024 14:38:28 +0530 Subject: [PATCH] [Tizen.Network.WiFi] Add set auto scan mode and hidden connect apis (#6171) * Update WiFiEnumerations.cs * [Tizen.Network.WiFi] Add set auto scan mode and hidden connect apis --- src/Tizen.Network.WiFi/Interop/Interop.WiFi.cs | 4 ++ .../Tizen.Network.WiFi/WiFiEnumerations.cs | 20 ++++++++ .../Tizen.Network.WiFi/WiFiManager.cs | 36 ++++++++++++++ .../Tizen.Network.WiFi/WiFiManagerImpl.cs | 56 ++++++++++++++++++++++ 4 files changed, 116 insertions(+) diff --git a/src/Tizen.Network.WiFi/Interop/Interop.WiFi.cs b/src/Tizen.Network.WiFi/Interop/Interop.WiFi.cs index 8142099..434d5bd 100755 --- a/src/Tizen.Network.WiFi/Interop/Interop.WiFi.cs +++ b/src/Tizen.Network.WiFi/Interop/Interop.WiFi.cs @@ -92,6 +92,10 @@ internal static partial class Interop internal static extern int ForgetAP(SafeWiFiManagerHandle wifi, IntPtr ap, VoidCallback callback, IntPtr userData); [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_update_ap")] internal static extern int UpdateAP(SafeWiFiManagerHandle wifi, IntPtr ap); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_set_autoscan_mode")] + internal static extern int SetAutoScanMode(SafeWiFiManagerHandle wifi, int mode); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_connect_hidden_ap")] + internal static extern int ConnectHiddenAP(SafeWiFiManagerHandle wifi, string essid, int secType, string passphrase, VoidCallback callback, IntPtr userData); [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_specific_scan_create")] internal static extern int SpecificScanCreate(SafeWiFiManagerHandle wifi, out IntPtr specificScanHandle); [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_specific_scan_destroy")] diff --git a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiEnumerations.cs b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiEnumerations.cs index d110106..3b23c4f 100755 --- a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiEnumerations.cs +++ b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiEnumerations.cs @@ -15,6 +15,7 @@ */ using System; +using System.ComponentModel; namespace Tizen.Network.WiFi { @@ -213,4 +214,23 @@ namespace Tizen.Network.WiFi /// 6 Scanning = 1 } + + /// + /// Enumeration for the Wi-Fi autoscan mode. + /// + /// 10 + [EditorBrowsable(EditorBrowsableState.Never)] + public enum WiFiAutoScanMode + { + /// + /// Auto scan interval is increased exponentially like 4, 8, 16, ...128secs. + /// + /// 10 + Exponential = 0, + /// + /// Auto scan interval is fixed with 10secs(for mobile) / 15secs(for wearable). + /// + /// 10 + Periodic = 1 + } } diff --git a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManager.cs b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManager.cs index 190a258..d7dd257 100755 --- a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManager.cs +++ b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManager.cs @@ -447,6 +447,42 @@ namespace Tizen.Network.WiFi } /// + /// Set Auto Scan Mode. + /// + /// 10 + /// http://tizen.org/feature/network.wifi + /// http://tizen.org/privilege/network.set + /// http://tizen.org/privilege/network.get + /// Thrown when the Wi-Fi is not supported. + /// Thrown when the permission is denied. + /// Thrown when the method failed due to an invalid operation. + [EditorBrowsable(EditorBrowsableState.Never)] + static public void SetAutoScanMode(WiFiAutoScanMode scanMode) + { + WiFiManagerImpl.Instance.SetAutoScanMode((int)scanMode); + } + + /// + /// Hidden Ap connect. + /// + /// + /// This method must be called from MainThread. + /// + /// 10 + /// A task indicating whether the HiddenAPConnectAsync method is done or not. + /// http://tizen.org/feature/network.wifi + /// http://tizen.org/privilege/network.set + /// http://tizen.org/privilege/network.get + /// Thrown when the Wi-Fi is not supported. + /// Thrown when the permission is denied. + /// Thrown when the method failed due to an invalid operation. + [EditorBrowsable(EditorBrowsableState.Never)] + static public Task HiddenAPConnectAsync(string essid, int secType, string password) + { + return WiFiManagerImpl.Instance.HiddenAPConnectAsync(essid, secType, password); + } + + /// /// Create Specific scan handle. /// /// 9 diff --git a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManagerImpl.cs b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManagerImpl.cs index f41de39..64c2740 100644 --- a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManagerImpl.cs +++ b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManagerImpl.cs @@ -597,6 +597,62 @@ namespace Tizen.Network.WiFi return task.Task; } + internal void SetAutoScanMode(int scanMode) + { + Log.Info(Globals.LogTag, "SetAutoScanMode"); + int ret = Interop.WiFi.SetAutoScanMode(GetSafeHandle(), scanMode); + CheckReturnValue(ret, "GetSafeHandle", PrivilegeNetworkGet); + } + + internal Task HiddenAPConnectAsync(string essid, int secType, string passphrase) + { + Log.Info(Globals.LogTag, "HiddenAPConnect"); + TaskCompletionSource task = new TaskCompletionSource(); + IntPtr id; + lock (_callback_map) + { + id = (IntPtr)_requestId++; + _callback_map[id] = (error, key) => + { + Log.Info(Globals.LogTag, "HiddenAPConnect Done " + essid); + if (error != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Error occurs during HiddenAPConnect, " + (WiFiError)error); + task.SetException(new InvalidOperationException("Error occurs during HiddenAPConnect, " + (WiFiError)error)); + } + else + { + task.SetResult(true); + } + lock (_callback_map) + { + _callback_map.Remove(key); + } + }; + } + + context.Post((x) => + { + Log.Info(Globals.LogTag, "Interop.WiFi.HiddenAPConnect"); + try + { + int ret = (int)WiFiError.None; + lock (_callback_map) + { + ret = Interop.WiFi.ConnectHiddenAP(GetSafeHandle(), essid, secType, passphrase, _callback_map[id], id); + } + CheckReturnValue(ret, "HiddenAPConnect", ""); + } + catch (Exception e) + { + Log.Error(Globals.LogTag, "Exception on HiddenAPConnect\n" + e); + task.SetException(e); + } + }, null); + + return task.Task; + } + internal void CreateSpecificScanHandle() { Log.Debug(Globals.LogTag, "CreateSpecificScanHandle"); -- 2.7.4