From 2a7b99ab1b0fa57fe9ac3ec712bd2a0641465113 Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Wed, 27 Oct 2021 14:17:44 -0700 Subject: [PATCH] [linux]:Enable extra dbus APIs for BSS management (#11067) --- .../Linux/ConnectivityManagerImpl.cpp | 45 +++++++++++++++++++ src/platform/Linux/ConnectivityManagerImpl.h | 3 ++ src/platform/Linux/dbus/wpa/BUILD.gn | 1 + src/platform/Linux/dbus/wpa/DBusWpaBss.xml | 10 +++++ 4 files changed, 59 insertions(+) create mode 100644 src/platform/Linux/dbus/wpa/DBusWpaBss.xml diff --git a/src/platform/Linux/ConnectivityManagerImpl.cpp b/src/platform/Linux/ConnectivityManagerImpl.cpp index 27ba37d5411692..3092695ccf1da9 100644 --- a/src/platform/Linux/ConnectivityManagerImpl.cpp +++ b/src/platform/Linux/ConnectivityManagerImpl.cpp @@ -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 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; @@ -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 { @@ -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 { @@ -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); } } @@ -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; } } @@ -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; diff --git a/src/platform/Linux/ConnectivityManagerImpl.h b/src/platform/Linux/ConnectivityManagerImpl.h index b483348023e39f..8f7706b425a7e9 100644 --- a/src/platform/Linux/ConnectivityManagerImpl.h +++ b/src/platform/Linux/ConnectivityManagerImpl.h @@ -38,6 +38,7 @@ #if CHIP_DEVICE_CONFIG_ENABLE_WPA #include +#include #include #include #endif @@ -73,6 +74,7 @@ struct GDBusWpaSupplicant WpaFiW1Wpa_supplicant1 * proxy; WpaFiW1Wpa_supplicant1Interface * iface; + WpaFiW1Wpa_supplicant1BSS * bss; gchar * interfacePath; gchar * networkPath; }; @@ -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 mConnectivityFlag; static struct GDBusWpaSupplicant mWpaSupplicant; diff --git a/src/platform/Linux/dbus/wpa/BUILD.gn b/src/platform/Linux/dbus/wpa/BUILD.gn index 9fdd7e58bd846c..5080622540339c 100644 --- a/src/platform/Linux/dbus/wpa/BUILD.gn +++ b/src/platform/Linux/dbus/wpa/BUILD.gn @@ -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", ] diff --git a/src/platform/Linux/dbus/wpa/DBusWpaBss.xml b/src/platform/Linux/dbus/wpa/DBusWpaBss.xml new file mode 100644 index 00000000000000..b6e8fee4633745 --- /dev/null +++ b/src/platform/Linux/dbus/wpa/DBusWpaBss.xml @@ -0,0 +1,10 @@ + + + + + + + + + +