From 9730842cddf308764e43f915de0d2667a90c15c1 Mon Sep 17 00:00:00 2001 From: akash1-kumar <115205462+akash1-kumar@users.noreply.github.com> Date: Tue, 9 Jan 2024 12:50:21 +0530 Subject: [PATCH] [Tizen.Network.WiFi] Add APIs for multi-scanning (#5872) Signed-off-by: Akash Kumar --- src/Tizen.Network.WiFi/Interop/Interop.WiFi.cs | 12 ++++ .../Tizen.Network.WiFi/WiFiConfiguration.cs | 25 ++++++++ .../Tizen.Network.WiFi/WiFiManager.cs | 55 +++++++++++++++++ .../Tizen.Network.WiFi/WiFiManagerImpl.cs | 72 ++++++++++++++++++++++ 4 files changed, 164 insertions(+) diff --git a/src/Tizen.Network.WiFi/Interop/Interop.WiFi.cs b/src/Tizen.Network.WiFi/Interop/Interop.WiFi.cs index 2f46431..8142099 100755 --- a/src/Tizen.Network.WiFi/Interop/Interop.WiFi.cs +++ b/src/Tizen.Network.WiFi/Interop/Interop.WiFi.cs @@ -92,6 +92,16 @@ 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_specific_scan_create")] + internal static extern int SpecificScanCreate(SafeWiFiManagerHandle wifi, out IntPtr specificScanHandle); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_specific_scan_destroy")] + internal static extern int SpecificScanDestroy(SafeWiFiManagerHandle wifi, IntPtr specificScanHandle); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_specific_scan_set_ssid")] + internal static extern int SpecificScanSetSsid(IntPtr specificScanHandle, string essid); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_specific_scan_set_freq")] + internal static extern int SpecificScanSetFrequency(IntPtr specificScanHandle, int freq); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_specific_ap_start_multi_scan")] + internal static extern int SpecificApStartMultiScan(SafeWiFiManagerHandle wifi, IntPtr specificScanHandle, VoidCallback callback, IntPtr userData); //Wi-Fi Monitor [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_get_connection_state")] @@ -298,6 +308,8 @@ internal static partial class Interop internal static extern int GetEapSubjectMatch(SafeWiFiConfigHandle config, out IntPtr subjectMatch); [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_config_set_eap_subject_match")] internal static extern int SetEapSubjectMatch(SafeWiFiConfigHandle config, string subjectMatch); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_config_get_frequency")] + internal static extern int GetSavedConfigFrequency(IntPtr config, out int freq); } internal sealed class SafeWiFiAPHandle : SafeHandle diff --git a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiConfiguration.cs b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiConfiguration.cs index 1fd57bc..49af0cf 100755 --- a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiConfiguration.cs +++ b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiConfiguration.cs @@ -19,6 +19,7 @@ using System.Net; using System.Threading.Tasks; using System.Runtime.InteropServices; using Tizen.Network.Connection; +using System.ComponentModel; namespace Tizen.Network.WiFi { @@ -156,6 +157,30 @@ namespace Tizen.Network.WiFi } } + /// + /// The Frequency of the access point (AP). + /// + /// 9 + /// Frequency assigned to AP in the Wi-Fi configuration. + [EditorBrowsable(EditorBrowsableState.Never)] + public int Frequency + { + + get + { + Log.Debug(Globals.LogTag, "Frequency"); + int freq; + int ret = Interop.WiFi.Config.GetSavedConfigFrequency(_configHandle, out freq); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get Freq, Error - " + (WiFiError)ret); + return 0; + } + Log.Debug(Globals.LogTag, "Frequency is " + freq); + return freq; + } + } + internal WiFiConfiguration(IntPtr handle) { _configHandle = handle; diff --git a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManager.cs b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManager.cs index 9e53676..190a258 100755 --- a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManager.cs +++ b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManager.cs @@ -445,5 +445,60 @@ namespace Tizen.Network.WiFi { return WiFiManagerImpl.Instance.BssidScanAsync(); } + + /// + /// Create Specific scan handle. + /// + /// 9 + /// http://tizen.org/feature/network.wifi + /// http://tizen.org/privilege/network.profile + /// Thrown when the Wi-Fi is not supported. + /// Thrown when the permission is denied. + /// Thrown when system is out of memory. + /// Thrown when the method failed due to an invalid operation. + [EditorBrowsable(EditorBrowsableState.Never)] + static public void CreateSpecificHandle() + { + WiFiManagerImpl.Instance.CreateSpecificScanHandle(); + } + + /// + /// Destroys Specific scan handle. + /// + /// 9 + /// http://tizen.org/feature/network.wifi + /// http://tizen.org/privilege/network.profile + /// Thrown when the Wi-Fi is not supported. + /// Thrown when the permission is denied. + /// Thrown when system is out of memory. + /// Thrown when the method failed due to an invalid operation. + [EditorBrowsable(EditorBrowsableState.Never)] + static public void DestroySpecificHandle() + { + WiFiManagerImpl.Instance.DestroySpecificScanHandle(); + } + + /// + /// Starts Multi Scan. + /// + /// + /// This method must be called from MainThread. + /// + /// 9 + /// Frequency for which MultiScan is to be run. + /// A task indicating whether the StartMultiScan 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 system is out of memory. + /// Thrown when the method failed due to an invalid operation. + [EditorBrowsable(EditorBrowsableState.Never)] + static public Task StartMultiScan(int frequency) + { + WiFiManagerImpl.Instance.SetSpecificScanFreq(frequency); + return WiFiManagerImpl.Instance.StartMultiScan(); + } } } diff --git a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManagerImpl.cs b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManagerImpl.cs index e150c36..f41de39 100644 --- a/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManagerImpl.cs +++ b/src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManagerImpl.cs @@ -57,6 +57,7 @@ namespace Tizen.Network.WiFi private int _requestId = 0; private string _macAddress; + private IntPtr _specificScanHandle; //private string PrivilegeNetworkSet = "http://tizen.org/privilege/network.set"; private string PrivilegeNetworkGet = "http://tizen.org/privilege/network.get"; @@ -596,6 +597,77 @@ namespace Tizen.Network.WiFi return task.Task; } + internal void CreateSpecificScanHandle() + { + Log.Debug(Globals.LogTag, "CreateSpecificScanHandle"); + int ret = Interop.WiFi.SpecificScanCreate(GetSafeHandle(), out _specificScanHandle); + CheckReturnValue(ret, "CreateSpecificScanHandle", PrivilegeNetworkProfile); + } + + internal void DestroySpecificScanHandle() + { + Log.Debug(Globals.LogTag, "DestroySpecificScanHandle"); + int ret = Interop.WiFi.SpecificScanDestroy(GetSafeHandle(), _specificScanHandle); + CheckReturnValue(ret, "DestroySpecificScanHandle", PrivilegeNetworkProfile); + _specificScanHandle = IntPtr.Zero; + } + + internal void SetSpecificScanFreq(int freq) + { + Log.Debug(Globals.LogTag, "SetSpecificScanFreq"); + int ret = Interop.WiFi.SpecificScanSetFrequency(_specificScanHandle, freq); + CheckReturnValue(ret, "SetSpecificScanFreq", PrivilegeNetworkProfile); + } + + internal Task StartMultiScan() + { + Log.Debug(Globals.LogTag, "StartMultiScan"); + TaskCompletionSource task = new TaskCompletionSource(); + IntPtr id; + lock (_callback_map) + { + id = (IntPtr)_requestId++; + _callback_map[id] = (error, key) => + { + Log.Info(Globals.LogTag, "Multi Scan done"); + if (error != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Error occurs during multi scanning, " + (WiFiError)error); + task.SetException(new InvalidOperationException("Error occurs during multi scanning, " + (WiFiError)error)); + } + else + { + task.SetResult(true); + } + lock (_callback_map) + { + _callback_map.Remove(key); + } + }; + } + + context.Post((x) => + { + Log.Info(Globals.LogTag, "Interop.WiFi.SpecificApStartMultiScan"); + try + { + int ret = (int)WiFiError.None; + lock (_callback_map) + { + ret = Interop.WiFi.SpecificApStartMultiScan(GetSafeHandle(), _specificScanHandle, _callback_map[id], id); + } + CheckReturnValue(ret, "MultiScan", ""); + } + catch (Exception e) + { + Log.Error(Globals.LogTag, "Exception on Multi Scan\n" + e); + task.SetException(e); + } + }, null); + + return task.Task; + } + private void CheckReturnValue(int ret, string method, string privilege) { if (ret != (int)WiFiError.None) -- 2.7.4