Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tizen.Network.WiFi] Add set auto scan mode and hidden connect apis #3

Merged
merged 3 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading