Skip to content

Commit

Permalink
[Tizen.Network.WiFi] Add set auto scan mode and hidden connect apis (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
akash1-kumar authored Jun 12, 2024
1 parent 7b53ead commit 5a3bbca
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Tizen.Network.WiFi/Interop/Interop.WiFi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ internal static partial class WiFi
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")]
Expand Down
20 changes: 20 additions & 0 deletions src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiEnumerations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

using System;
using System.ComponentModel;

namespace Tizen.Network.WiFi
{
Expand Down Expand Up @@ -213,4 +214,23 @@ public enum WiFiScanState
/// <since_tizen> 6 </since_tizen>
Scanning = 1
}

/// <summary>
/// Enumeration for the Wi-Fi autoscan mode.
/// </summary>
/// <since_tizen> 10 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
public enum WiFiAutoScanMode
{
/// <summary>
/// Auto scan interval is increased exponentially like 4, 8, 16, ...128secs.
/// </summary>
/// <since_tizen> 10 </since_tizen>
Exponential = 0,
/// <summary>
/// Auto scan interval is fixed with 10secs(for mobile) / 15secs(for wearable).
/// </summary>
/// <since_tizen> 10 </since_tizen>
Periodic = 1
}
}
36 changes: 36 additions & 0 deletions src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,42 @@ static public Task BssidScanAsync()
return WiFiManagerImpl.Instance.BssidScanAsync();
}

/// <summary>
/// Set Auto Scan Mode.
/// </summary>
/// <since_tizen> 10 </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 the permission is denied.</exception>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
[EditorBrowsable(EditorBrowsableState.Never)]
static public void SetAutoScanMode(WiFiAutoScanMode scanMode)
{
WiFiManagerImpl.Instance.SetAutoScanMode((int)scanMode);
}

/// <summary>
/// Hidden Ap connect.
/// </summary>
/// <remarks>
/// This method must be called from MainThread.
/// </remarks>
/// <since_tizen> 10 </since_tizen>
/// <returns>A task indicating whether the HiddenAPConnectAsync 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>
[EditorBrowsable(EditorBrowsableState.Never)]
static public Task HiddenAPConnectAsync(string essid, int secType, string password)
{
return WiFiManagerImpl.Instance.HiddenAPConnectAsync(essid, secType, password);
}

/// <summary>
/// Create Specific scan handle.
/// </summary>
Expand Down
56 changes: 56 additions & 0 deletions src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManagerImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,62 @@ internal Task BssidScanAsync()
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<bool> task = new TaskCompletionSource<bool>();
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");
Expand Down

0 comments on commit 5a3bbca

Please sign in to comment.