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

[Network.WiFi] Implement API to get MAC of TDLS connected peer #6472

Merged
merged 1 commit into from
Dec 11, 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
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 @@ -374,4 +376,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
Loading