[Tizen.Network.WiFi] Add APIs for multi-scanning (#5872)
authorakash1-kumar <115205462+akash1-kumar@users.noreply.github.com>
Tue, 9 Jan 2024 07:20:21 +0000 (12:50 +0530)
committerGitHub <noreply@github.com>
Tue, 9 Jan 2024 07:20:21 +0000 (16:20 +0900)
Signed-off-by: Akash Kumar <akash1.kumar@samsung.com>
src/Tizen.Network.WiFi/Interop/Interop.WiFi.cs
src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiConfiguration.cs
src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManager.cs
src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManagerImpl.cs

index 2f46431eb2e215cb0ce9629700f21514e7e83433..8142099463f21f97051c8baaa787a224dcb7b930 100755 (executable)
@@ -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
index 1fd57bc05f8452eb93ebc8632a4e9238eff74d2d..49af0cf31744390c97f9abe4a7be832fc1e479f4 100755 (executable)
@@ -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
             }
         }
 
+        /// <summary>
+        /// The Frequency of the access point (AP).
+        /// </summary>
+        /// <since_tizen> 9 </since_tizen>
+        /// <value>Frequency assigned to AP in the Wi-Fi configuration.</value>
+        [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;
index 9e53676bf055abeb510db719693cfd45e19aafbc..190a2588156caf5b6a7376916cc01ebb0d176b9a 100755 (executable)
@@ -445,5 +445,60 @@ namespace Tizen.Network.WiFi
         {
             return WiFiManagerImpl.Instance.BssidScanAsync();
         }
+
+        /// <summary>
+        /// Create Specific scan handle.
+        /// </summary>
+        /// <since_tizen> 9 </since_tizen>
+        /// <feature>http://tizen.org/feature/network.wifi</feature>
+        /// <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 the permission is denied.</exception>
+        /// <exception cref="OutOfMemoryException">Thrown when system is out of memory.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        static public void CreateSpecificHandle()
+        {
+            WiFiManagerImpl.Instance.CreateSpecificScanHandle();
+        }
+
+        /// <summary>
+        /// Destroys Specific scan handle.
+        /// </summary>
+        /// <since_tizen> 9 </since_tizen>
+        /// <feature>http://tizen.org/feature/network.wifi</feature>
+        /// <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 the permission is denied.</exception>
+        /// <exception cref="OutOfMemoryException">Thrown when system is out of memory.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        static public void DestroySpecificHandle()
+        {
+            WiFiManagerImpl.Instance.DestroySpecificScanHandle();
+        }
+
+        /// <summary>
+        /// Starts Multi Scan.
+        /// </summary>
+        /// <remarks>
+        /// This method must be called from MainThread.
+        /// </remarks>
+        /// <since_tizen> 9 </since_tizen>
+        /// <param name="frequency">Frequency for which MultiScan is to be run.</param>
+        /// <returns>A task indicating whether the StartMultiScan  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 the permission is denied.</exception>
+        /// <exception cref="OutOfMemoryException">Thrown when system is out of memory.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        static public Task StartMultiScan(int frequency)
+        {
+            WiFiManagerImpl.Instance.SetSpecificScanFreq(frequency);
+            return WiFiManagerImpl.Instance.StartMultiScan();
+        }
     }
 }
index e150c368f19f460adef407fcb60d5480ec297ee9..f41de396ae20c397555ca240d718bbc08af33507 100644 (file)
@@ -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<bool> task = new TaskCompletionSource<bool>();
+            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)