Skip to content

Commit

Permalink
[linux]:Enable extra dbus APIs for BSS management (#11067)
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca authored and pull[bot] committed Feb 21, 2022
1 parent 02c5855 commit 1191496
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/platform/Linux/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,35 @@ void ConnectivityManagerImpl::_OnWpaInterfaceProxyReady(GObject * source_object,
g_error_free(err);
}

void ConnectivityManagerImpl::_OnWpaBssProxyReady(GObject * source_object, GAsyncResult * res, gpointer user_data)
{
GError * err = nullptr;

std::lock_guard<std::mutex> lock(mWpaSupplicantMutex);

WpaFiW1Wpa_supplicant1BSS * bss = wpa_fi_w1_wpa_supplicant1_bss_proxy_new_for_bus_finish(res, &err);

if (mWpaSupplicant.bss)
{
g_object_unref(mWpaSupplicant.bss);
mWpaSupplicant.bss = nullptr;
}

if (bss != nullptr && err == nullptr)
{
mWpaSupplicant.bss = bss;
ChipLogProgress(DeviceLayer, "wpa_supplicant: connected to wpa_supplicant bss proxy");
}
else
{
ChipLogProgress(DeviceLayer, "wpa_supplicant: failed to create wpa_supplicant bss proxy %s: %s",
mWpaSupplicant.interfacePath, err ? err->message : "unknown error");
}

if (err != nullptr)
g_error_free(err);
}

void ConnectivityManagerImpl::_OnWpaInterfaceReady(GObject * source_object, GAsyncResult * res, gpointer user_data)
{
GError * err = nullptr;
Expand All @@ -526,6 +555,9 @@ void ConnectivityManagerImpl::_OnWpaInterfaceReady(GObject * source_object, GAsy
wpa_fi_w1_wpa_supplicant1_interface_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, kWpaSupplicantServiceName,
mWpaSupplicant.interfacePath, nullptr, _OnWpaInterfaceProxyReady,
nullptr);

wpa_fi_w1_wpa_supplicant1_bss_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, kWpaSupplicantServiceName,
mWpaSupplicant.interfacePath, nullptr, _OnWpaBssProxyReady, nullptr);
}
else
{
Expand Down Expand Up @@ -556,6 +588,9 @@ void ConnectivityManagerImpl::_OnWpaInterfaceReady(GObject * source_object, GAsy
wpa_fi_w1_wpa_supplicant1_interface_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE,
kWpaSupplicantServiceName, mWpaSupplicant.interfacePath, nullptr,
_OnWpaInterfaceProxyReady, nullptr);

wpa_fi_w1_wpa_supplicant1_bss_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, kWpaSupplicantServiceName,
mWpaSupplicant.interfacePath, nullptr, _OnWpaBssProxyReady, nullptr);
}
else
{
Expand Down Expand Up @@ -598,6 +633,9 @@ void ConnectivityManagerImpl::_OnWpaInterfaceAdded(WpaFiW1Wpa_supplicant1 * prox
wpa_fi_w1_wpa_supplicant1_interface_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, kWpaSupplicantServiceName,
mWpaSupplicant.interfacePath, nullptr, _OnWpaInterfaceProxyReady,
nullptr);

wpa_fi_w1_wpa_supplicant1_bss_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, kWpaSupplicantServiceName,
mWpaSupplicant.interfacePath, nullptr, _OnWpaBssProxyReady, nullptr);
}
}

Expand Down Expand Up @@ -629,6 +667,12 @@ void ConnectivityManagerImpl::_OnWpaInterfaceRemoved(WpaFiW1Wpa_supplicant1 * pr
mWpaSupplicant.iface = nullptr;
}

if (mWpaSupplicant.bss)
{
g_object_unref(mWpaSupplicant.bss);
mWpaSupplicant.bss = nullptr;
}

mWpaSupplicant.scanState = GDBusWpaSupplicant::WIFI_SCANNING_IDLE;
}
}
Expand Down Expand Up @@ -669,6 +713,7 @@ void ConnectivityManagerImpl::StartWiFiManagement()
mWpaSupplicant.scanState = GDBusWpaSupplicant::WIFI_SCANNING_IDLE;
mWpaSupplicant.proxy = nullptr;
mWpaSupplicant.iface = nullptr;
mWpaSupplicant.bss = nullptr;
mWpaSupplicant.interfacePath = nullptr;
mWpaSupplicant.networkPath = nullptr;

Expand Down
3 changes: 3 additions & 0 deletions src/platform/Linux/ConnectivityManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

#if CHIP_DEVICE_CONFIG_ENABLE_WPA
#include <platform/Linux/dbus/wpa/DBusWpa.h>
#include <platform/Linux/dbus/wpa/DBusWpaBss.h>
#include <platform/Linux/dbus/wpa/DBusWpaInterface.h>
#include <platform/Linux/dbus/wpa/DBusWpaNetwork.h>
#endif
Expand Down Expand Up @@ -73,6 +74,7 @@ struct GDBusWpaSupplicant

WpaFiW1Wpa_supplicant1 * proxy;
WpaFiW1Wpa_supplicant1Interface * iface;
WpaFiW1Wpa_supplicant1BSS * bss;
gchar * interfacePath;
gchar * networkPath;
};
Expand Down Expand Up @@ -148,6 +150,7 @@ class ConnectivityManagerImpl final : public ConnectivityManager,
static void _OnWpaInterfaceAdded(WpaFiW1Wpa_supplicant1 * proxy, const gchar * path, GVariant * properties, gpointer user_data);
static void _OnWpaInterfaceReady(GObject * source_object, GAsyncResult * res, gpointer user_data);
static void _OnWpaInterfaceProxyReady(GObject * source_object, GAsyncResult * res, gpointer user_data);
static void _OnWpaBssProxyReady(GObject * source_object, GAsyncResult * res, gpointer user_data);

static BitFlags<ConnectivityFlags> mConnectivityFlag;
static struct GDBusWpaSupplicant mWpaSupplicant;
Expand Down
1 change: 1 addition & 0 deletions src/platform/Linux/dbus/wpa/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import("${chip_root}/build/chip/linux/gdbus_library.gni")
gdbus_library("wpa") {
sources = [
"DBusWpa.xml",
"DBusWpaBss.xml",
"DBusWpaInterface.xml",
"DBusWpaNetwork.xml",
]
Expand Down
10 changes: 10 additions & 0 deletions src/platform/Linux/dbus/wpa/DBusWpaBss.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" ?>
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "https://raw.githubusercontent.com/freedesktop/dbus/master/doc/introspect.dtd">
<node>
<interface name="fi.w1.wpa_supplicant1.BSS">
<property name="SSID" type="ay" access="read" />
<property name="BSSID" type="ay" access="read" />
<property name="Signal" type="n" access="read" />
<property name="Frequency" type="q" access="read" />
</interface>
</node>

0 comments on commit 1191496

Please sign in to comment.