[WiFi] TCSACR-149 (#292)
authorchleun-moon <32117100+chleun-moon@users.noreply.github.com>
Thu, 21 Jun 2018 04:34:30 +0000 (13:34 +0900)
committertaesubkim <35015408+taesubkim@users.noreply.github.com>
Thu, 21 Jun 2018 04:34:30 +0000 (13:34 +0900)
* [WiFi] New APIs

[method]
public static void CancelWps()
static public IEnumerable<WiFiAP> GetFoundBssidAPs()
static public Task BssidScanAsync()
public IEnumerable<string> GetBssids()

[property]
public byte[] RawSsid
public string CountryCode

* Rename GetFoundBssidAPs to GetFoundBssids

src/Tizen.Network.WiFi/Interop/Interop.WiFi.cs
src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiAP.cs
src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManager.cs
src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManagerImpl.cs
src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiNetwork.cs

index a70c6b1..a019901 100755 (executable)
@@ -60,12 +60,16 @@ internal static partial class Interop
         internal static extern int Scan(SafeWiFiManagerHandle wifi, VoidCallback callback, IntPtr userData);
         [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_scan_specific_ap")]
         internal static extern int ScanSpecificAP(SafeWiFiManagerHandle wifi, string essid, VoidCallback callback, IntPtr userData);
+        [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_bssid_scan")]
+        internal static extern int BssidScan(SafeWiFiManagerHandle wifi, VoidCallback callback, IntPtr userData);
         [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_get_connected_ap")]
         internal static extern int GetConnectedAP(SafeWiFiManagerHandle wifi, out IntPtr ap);
         [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_foreach_found_ap")]
         internal static extern int GetForeachFoundAPs(SafeWiFiManagerHandle wifi, HandleCallback callback, IntPtr userData);
         [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_foreach_found_specific_ap")]
         internal static extern int GetForeachFoundSpecificAPs(SafeWiFiManagerHandle wifi, HandleCallback callback, IntPtr userData);
+        [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_foreach_found_bssid_ap")]
+        internal static extern int GetForeachFoundBssids(SafeWiFiManagerHandle wifi, HandleCallback callback, IntPtr userData);
         [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_connect")]
         internal static extern int Connect(SafeWiFiManagerHandle wifi, IntPtr ap, VoidCallback callback, IntPtr userData);
         [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_disconnect")]
@@ -78,6 +82,8 @@ internal static partial class Interop
         internal static extern int ConnectByWpsPbcWithoutSsid(SafeWiFiManagerHandle wifi, VoidCallback callback, IntPtr userData);
         [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_connect_by_wps_pin_without_ssid")]
         internal static extern int ConnectByWpsPinWithoutSsid(SafeWiFiManagerHandle wifi, string pin, VoidCallback callback, IntPtr userData);
+        [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_cancel_wps")]
+        internal static extern int CancelWps(SafeWiFiManagerHandle wifi);
         [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_forget_ap")]
         internal static extern int RemoveAP(SafeWiFiManagerHandle wifi, IntPtr ap);
         [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_update_ap")]
@@ -105,6 +111,9 @@ internal static partial class Interop
 
         internal static class AP
         {
+            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+            internal delegate bool FoundBssidCallback(string bssid, int rssi, int freq, IntPtr userData);
+
             [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_ap_create")]
             internal static extern int Create(SafeWiFiManagerHandle wifi, string essid, out IntPtr ap);
             [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_ap_hidden_create")]
@@ -119,8 +128,12 @@ internal static partial class Interop
             ////Network Information
             [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_ap_get_essid")]
             internal static extern int GetEssid(SafeWiFiAPHandle ap, out IntPtr essid);
+            [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_ap_get_raw_essid")]
+            internal static extern int GetRawSsid(SafeWiFiAPHandle ap, out IntPtr raw_ssid, out int length);
             [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_ap_get_bssid")]
             internal static extern int GetBssid(SafeWiFiAPHandle ap, out IntPtr bssid);
+            [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_foreach_found_bssid")]
+            internal static extern int GetBssids(SafeWiFiAPHandle ap, FoundBssidCallback callback, IntPtr userData);
             [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_ap_get_rssi")]
             internal static extern int GetRssi(SafeWiFiAPHandle ap, out int rssi);
             [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_ap_get_rssi_level")]
@@ -143,6 +156,8 @@ internal static partial class Interop
             internal static extern int GetIPAddress(SafeWiFiAPHandle ap, int addressFamily, out IntPtr ipAddress);
             [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_ap_foreach_ipv6_address")]
             internal static extern int GetAllIPv6Addresses(SafeWiFiAPHandle ap, HandleCallback callback, IntPtr userData);
+            [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_ap_get_countrycode")]
+            internal static extern int GetCountryCode(SafeWiFiAPHandle ap, out IntPtr code);
             [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_ap_set_ip_address")]
             internal static extern int SetIPAddress(SafeWiFiAPHandle ap, int addressFamily, string ipAddress);
             [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_ap_get_subnet_mask")]
index f458c14..6715646 100644 (file)
@@ -156,7 +156,6 @@ namespace Tizen.Network.WiFi
             {
                 ret = Interop.WiFi.AP.CreateHiddenAP(WiFiManagerImpl.Instance.GetSafeHandle(), id, out _apHandle);
             }
-
             else
             {
                 ret = Interop.WiFi.AP.Create(WiFiManagerImpl.Instance.GetSafeHandle(), id, out _apHandle);
@@ -459,6 +458,30 @@ namespace Tizen.Network.WiFi
         }
 
         /// <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="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 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());
+            }
+        }
+
+
+        /// <summary>
         /// Disconnects the access point asynchronously.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
index 5cbdad5..5d3ccf2 100755 (executable)
@@ -252,6 +252,22 @@ namespace Tizen.Network.WiFi
         }
 
         /// <summary>
+        /// Gets the result of the BssidScanAsync() API.
+        /// </summary>
+        /// <since_tizen> 5 </since_tizen>
+        /// <returns>A list of the WiFiAP objects.</returns>
+        /// <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 the permission is denied.</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>
+        static public IEnumerable<WiFiAP> GetFoundBssids()
+        {
+            return WiFiManagerImpl.Instance.GetFoundBssids();
+        }
+
+        /// <summary>
         /// Gets the list of Wi-Fi configurations.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
@@ -387,5 +403,24 @@ namespace Tizen.Network.WiFi
         {
             return WiFiManagerImpl.Instance.ScanSpecificAPAsync(essid);
         }
+
+        /// <summary>
+        /// Starts BSSID scan asynchronously.
+        /// </summary>
+        /// <remarks>
+        /// This method must be called from MainThread.
+        /// </remarks>
+        /// <since_tizen> 5 </since_tizen>
+        /// <returns>A task indicating whether the BssidScanAsync 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="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
+        static public Task BssidScanAsync()
+        {
+            return WiFiManagerImpl.Instance.BssidScanAsync();
+        }
     }
 }
index ee092aa..b4b23ac 100644 (file)
@@ -218,6 +218,33 @@ namespace Tizen.Network.WiFi
             return apList;
         }
 
+        internal IEnumerable<WiFiAP> GetFoundBssids()
+        {
+            Log.Info(Globals.LogTag, "GetFoundBssids");
+            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.GetForeachFoundBssids(GetSafeHandle(), callback, IntPtr.Zero);
+            if (ret != (int)WiFiError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to get bssid APs, Error - " + (WiFiError)ret);
+                WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle(), "http://tizen.org/privilege/network.get");
+            }
+
+            return apList;
+        }
+
         internal IEnumerable<WiFiConfiguration> GetWiFiConfigurations()
         {
             Log.Debug(Globals.LogTag, "GetWiFiConfigurations");
@@ -528,5 +555,54 @@ namespace Tizen.Network.WiFi
 
             return task.Task;
         }
+
+        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);
+                        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;
+        }
     }
 }
index e10206c..b9b3350 100755 (executable)
@@ -54,6 +54,7 @@ namespace Tizen.Network.WiFi
                     else
                     {
                         _essid = Marshal.PtrToStringAnsi(strPtr);
+                        Interop.Libc.Free(strPtr);
                     }
                 }
                 return _essid;
@@ -61,6 +62,34 @@ namespace Tizen.Network.WiFi
         }
 
         /// <summary>
+        /// The raw Service Set Identifier (SSID).
+        /// </summary>
+        /// <since_tizen> 5 </since_tizen>
+        /// <value>Raw SSID of the Wi-Fi.</value>
+        public byte[] RawSsid
+        {
+            get
+            {
+                IntPtr ptr;
+                byte[] rawSsid;
+                int length;
+                int ret = Interop.WiFi.AP.GetRawSsid(_apHandle, out ptr, out length);
+                if (ret != (int)WiFiError.None || length == 0)
+                {
+                    Log.Error(Globals.LogTag, "Failed to get raw essid, Error - " + (WiFiError)ret);
+                    rawSsid = null;
+                }
+                else
+                {
+                    rawSsid = new byte[length];
+                    Marshal.Copy(ptr, rawSsid, 0, length);
+                    Interop.Libc.Free(ptr);
+                }
+                return rawSsid;
+            }
+        }
+
+        /// <summary>
         /// The Basic Service Set Identifier (BSSID).
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
@@ -316,6 +345,32 @@ namespace Tizen.Network.WiFi
         }
 
         /// <summary>
+        /// The raw country code
+        /// </summary>
+        /// <since_tizen> 5 </since_tizen>
+        /// <value>Represents the raw country code of the Wi-Fi.</value>
+        public string CountryCode
+        {
+            get
+            {
+                string code;
+                IntPtr strPtr;
+                int ret = Interop.WiFi.AP.GetCountryCode(_apHandle, out strPtr);
+                if (ret != (int)WiFiError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to get country code, Error - " + (WiFiError)ret);
+                    code = "";
+                }
+                else
+                {
+                    code = Marshal.PtrToStringAnsi(strPtr);
+                    Interop.Libc.Free(strPtr);
+                }
+                return code;
+            }
+        }
+
+        /// <summary>
         /// Gets all IPv6 addresses of the access point.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
@@ -352,6 +407,39 @@ namespace Tizen.Network.WiFi
             return ipList;
         }
 
+        /// <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="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<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);
+                WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle());
+            }
+
+            return bssidList;
+        }
+
         internal WiFiNetwork(Interop.WiFi.SafeWiFiAPHandle apHandle)
         {
             _apHandle = apHandle;