Skip to content

Commit

Permalink
[Network.WiFi] Implement API to get MAC of TDLS connected peer (#6481)
Browse files Browse the repository at this point in the history
Signed-off-by: Akash Kumar <[email protected]>
Co-authored-by: Seonah Moon <[email protected]>
  • Loading branch information
akash1-kumar and SeonahMoon authored Dec 11, 2024
1 parent 8f43a1a commit c2eded6
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Tizen.Network.WiFi/Interop/Interop.Libraries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ internal static partial class Libraries
{
public const string WiFi = "libcapi-network-wifi-manager.so.1";
public const string Glib = "libglib-2.0.so.0";
public const string Libc = "libc.so.6";
}
}
8 changes: 8 additions & 0 deletions src/Tizen.Network.WiFi/Interop/Interop.WiFi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ internal static partial class WiFi
internal static extern int SetScanStateChangedCallback(SafeWiFiManagerHandle wifi, ScanStateChangedCallback callback, IntPtr userData);
[DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_unset_scan_state_changed_cb")]
internal static extern int UnsetScanStateChangedCallback(SafeWiFiManagerHandle wifi);
[DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_tdls_get_connected_peer")]
internal static extern int GetTdlsConnectedPeer(SafeWiFiManagerHandle wifi, out IntPtr peerMacAddress);

internal static class AP
{
Expand Down Expand Up @@ -373,4 +375,10 @@ internal static partial class Glib
[DllImport(Libraries.Glib, EntryPoint = "g_free", CallingConvention = CallingConvention.Cdecl)]
public static extern void Free(IntPtr userData);
}

internal static partial class Libc
{
[DllImport(Libraries.Libc, EntryPoint = "free")]
public static extern void Free(IntPtr userData);
}
}
15 changes: 15 additions & 0 deletions src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -536,5 +536,20 @@ static public Task StartMultiScan(int frequency)
WiFiManagerImpl.Instance.SetSpecificScanFreq(frequency);
return WiFiManagerImpl.Instance.StartMultiScan();
}

/// <summary>
/// Gets MAC address of peer connected through TDLS.
/// </summary>
/// <since_tizen> 11 </since_tizen>
/// <returns>MAC address of the TDLS peer if connected on success or an empty string.</returns>
/// <privilege>http://tizen.org/privilege/network.get</privilege>
[EditorBrowsable(EditorBrowsableState.Never)]
static public string TDLSConnectedPeer
{
get
{
return WiFiManagerImpl.Instance.TDLSConnectedPeer;
}
}
}
}
23 changes: 23 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 string _tdlsMacAddress;
private IntPtr _specificScanHandle;

//private string PrivilegeNetworkSet = "http://tizen.org/privilege/network.set";
Expand Down Expand Up @@ -724,6 +725,28 @@ internal Task StartMultiScan()
return task.Task;
}

internal string TDLSConnectedPeer
{
get
{
IntPtr strPtr;
int ret = Interop.WiFi.GetTdlsConnectedPeer(GetSafeHandle(), out strPtr);
if (ret != (int)WiFiError.None)
{
_tdlsMacAddress = "";
Log.Error(Globals.LogTag, "Failed to get mac address, Error - " + (WiFiError)ret);
}
else
{
_tdlsMacAddress = Marshal.PtrToStringAnsi(strPtr);
Interop.Libc.Free(strPtr);
}

Log.Info(Globals.LogTag, "Tdls Mac address: " + _tdlsMacAddress);
return _tdlsMacAddress;
}
}

private void CheckReturnValue(int ret, string method, string privilege)
{
if (ret != (int)WiFiError.None)
Expand Down

0 comments on commit c2eded6

Please sign in to comment.