Skip to content

Commit

Permalink
[Tizen.Network.WiFi] Add APIs for multi-scanning (Samsung#5872)
Browse files Browse the repository at this point in the history
Signed-off-by: Akash Kumar <[email protected]>
  • Loading branch information
akash1-kumar authored Jan 9, 2024
1 parent db8426f commit 9730842
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 0 deletions.
12 changes: 12 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,16 @@ 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_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")]
Expand Down Expand Up @@ -298,6 +308,8 @@ internal static class Config
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
Expand Down
25 changes: 25 additions & 0 deletions src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using Tizen.Network.Connection;
using System.ComponentModel;

namespace Tizen.Network.WiFi
{
Expand Down Expand Up @@ -156,6 +157,30 @@ public WiFiEapConfiguration EapConfiguration
}
}

/// <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;
Expand Down
55 changes: 55 additions & 0 deletions src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,5 +445,60 @@ static public Task BssidScanAsync()
{
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();
}
}
}
72 changes: 72 additions & 0 deletions src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManagerImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ internal partial class WiFiManagerImpl

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";
Expand Down Expand Up @@ -596,6 +597,77 @@ internal Task BssidScanAsync()
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)
Expand Down

0 comments on commit 9730842

Please sign in to comment.