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")]
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")]
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")]
////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")]
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")]
{
ret = Interop.WiFi.AP.CreateHiddenAP(WiFiManagerImpl.Instance.GetSafeHandle(), id, out _apHandle);
}
-
else
{
ret = Interop.WiFi.AP.Create(WiFiManagerImpl.Instance.GetSafeHandle(), id, out _apHandle);
}
/// <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>
}
/// <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>
{
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();
+ }
}
}
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");
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;
+ }
}
}
else
{
_essid = Marshal.PtrToStringAnsi(strPtr);
+ Interop.Libc.Free(strPtr);
}
}
return _essid;
}
/// <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>
}
/// <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>
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;