From e0ced9ff2d8a146e01a3dde6b9ecd1b24b2c6932 Mon Sep 17 00:00:00 2001 From: gururaajar Date: Wed, 7 May 2025 23:43:26 -0400 Subject: [PATCH 1/3] To test gdbus issue --- .../gnome/gdbus/NetworkManagerGdbusClient.cpp | 47 ++++++++++++++++++- .../gnome/gdbus/NetworkManagerGdbusClient.h | 3 +- .../gnome/gdbus/NetworkManagerGdbusProxy.cpp | 14 ++++-- 3 files changed, 58 insertions(+), 6 deletions(-) diff --git a/plugin/gnome/gdbus/NetworkManagerGdbusClient.cpp b/plugin/gnome/gdbus/NetworkManagerGdbusClient.cpp index de74f3f1..8d944e6d 100644 --- a/plugin/gnome/gdbus/NetworkManagerGdbusClient.cpp +++ b/plugin/gnome/gdbus/NetworkManagerGdbusClient.cpp @@ -541,11 +541,25 @@ namespace WPEFramework return true; } + bool NetworkManagerClient::getDefaultInterface(std::string& interface) + { + deviceInfo devInfo{}; + std::string wifiname = GnomeUtils::getWifiIfname(), ethname = GnomeUtils::getEthIfname(); + if(!GnomeUtils::getDeviceInfoByIfname(m_dbus, ethname.c_str(), devInfo)) + return false; + if(devInfo.state > NM_DEVICE_STATE_DISCONNECTED && devInfo.state < NM_DEVICE_STATE_DEACTIVATING) + interface = ethname; + else + interface = wifiname; // default is wifi + return true; + } + bool NetworkManagerClient::getPrimaryInterface(std::string& interface) { GError* error = nullptr; std::string primaryConnectionPath; GDBusProxy *nmProxy = nullptr; + nmProxy = m_dbus.getNetworkManagerPropertyProxy("/org/freedesktop/NetworkManager"); if(nmProxy == nullptr) return false; @@ -753,7 +767,7 @@ namespace WPEFramework return true; } - bool NetworkManagerClient::getIPSettings(const std::string& interface, const std::string& ipversion, Exchange::INetworkManager::IPAddress& result) + bool NetworkManagerClient::getIPSettings(std::string& interface, const std::string& ipversion, Exchange::INetworkManager::IPAddress& result) { std::string devicePath; std::string addressStr; @@ -772,6 +786,37 @@ namespace WPEFramework const gchar *IPv6Method = nullptr; deviceInfo devInfo{}; GError *error = nullptr; + + std::string wifiname = GnomeUtils::getWifiIfname(), ethname = GnomeUtils::getEthIfname(); + + if(interface.empty()) + { + if(Core::ERROR_NONE != getPrimaryInterface(interface)) + { + NMLOG_WARNING("default interface get failed"); + return Core::ERROR_NONE; + } + if(interface.empty()) + { + NMLOG_DEBUG("default interface return empty default is wlan0"); + interface = wifiname; + } + } + else if(wifiname != interface && ethname != interface) + { + NMLOG_ERROR("interface: %s; not valied", interface.c_str()); + return Core::ERROR_GENERAL; + } + + if(!GnomeUtils::getDeviceInfoByIfname(m_dbus, interface.c_str(), devInfo)) + return false; + + if(devInfo.state < NM_DEVICE_STATE_DISCONNECTED) + { + NMLOG_WARNING("Device state is not a valid state: (%d)", devInfo.state); + return Core::ERROR_GENERAL; + } + if(!GnomeUtils::getDeviceByIpIface(m_dbus, interface.c_str(), devicePath)) return false; GDBusProxy *deviceProxy = m_dbus.getNetworkManagerDeviceProxy(devicePath.c_str()); diff --git a/plugin/gnome/gdbus/NetworkManagerGdbusClient.h b/plugin/gnome/gdbus/NetworkManagerGdbusClient.h index 9a727b92..1cd9cf72 100644 --- a/plugin/gnome/gdbus/NetworkManagerGdbusClient.h +++ b/plugin/gnome/gdbus/NetworkManagerGdbusClient.h @@ -53,8 +53,9 @@ namespace WPEFramework bool setInterfaceState(const std::string& interface, bool enable); bool setIPSettings(const std::string& interface, const Exchange::INetworkManager::IPAddress& address); bool getPrimaryInterface(std::string& interface); + bool getDefaultInterface(std::string& interface); bool getInterfaceState(const std::string& interface, bool& isEnabled); - bool getIPSettings(const std::string& interface, const std::string& ipversion, Exchange::INetworkManager::IPAddress& result); + bool getIPSettings(std::string& interface, const std::string& ipversion, Exchange::INetworkManager::IPAddress& result); bool getKnownSSIDs(std::list& ssids); bool getConnectedSSID(Exchange::INetworkManager::WiFiSSIDInfo& ssidinfo); bool addToKnownSSIDs(const Exchange::INetworkManager::WiFiConnectTo& ssidinfo); diff --git a/plugin/gnome/gdbus/NetworkManagerGdbusProxy.cpp b/plugin/gnome/gdbus/NetworkManagerGdbusProxy.cpp index 9e34eb0f..5c499785 100644 --- a/plugin/gnome/gdbus/NetworkManagerGdbusProxy.cpp +++ b/plugin/gnome/gdbus/NetworkManagerGdbusProxy.cpp @@ -113,12 +113,18 @@ namespace WPEFramework uint32_t NetworkManagerImplementation::GetPrimaryInterface (string& interface /* @out */) { - uint32_t rc = Core::ERROR_GENERAL; if(_nmGdbusClient->getPrimaryInterface(interface)) - rc = Core::ERROR_NONE; + return Core::ERROR_NONE; else - NMLOG_ERROR("GetPrimaryInterface failed"); - return rc; + { + if(_nmGdbusClient->getDefaultInterface(interface)) + { + _instance->m_defaultInterface = interface; + return Core::ERROR_NONE; + } + else + return Core::ERROR_GENERAL; + } } uint32_t NetworkManagerImplementation::SetPrimaryInterface (const string& interface/* @in */) From e9e9d997447f9def14ad9f9899e83d6d656667d8 Mon Sep 17 00:00:00 2001 From: gururaajar Date: Wed, 7 May 2025 23:43:26 -0400 Subject: [PATCH 2/3] To test gdbus issue --- .../gnome/gdbus/NetworkManagerGdbusClient.cpp | 84 +++++++++++++++++-- .../gnome/gdbus/NetworkManagerGdbusClient.h | 3 +- .../gnome/gdbus/NetworkManagerGdbusProxy.cpp | 14 +++- 3 files changed, 87 insertions(+), 14 deletions(-) diff --git a/plugin/gnome/gdbus/NetworkManagerGdbusClient.cpp b/plugin/gnome/gdbus/NetworkManagerGdbusClient.cpp index de74f3f1..9e33a70f 100644 --- a/plugin/gnome/gdbus/NetworkManagerGdbusClient.cpp +++ b/plugin/gnome/gdbus/NetworkManagerGdbusClient.cpp @@ -33,7 +33,7 @@ namespace WPEFramework { namespace Plugin { - + extern NetworkManagerImplementation* _instance; NetworkManagerClient::NetworkManagerClient() { NMLOG_INFO("NetworkManagerClient"); } @@ -541,11 +541,25 @@ namespace WPEFramework return true; } + bool NetworkManagerClient::getDefaultInterface(std::string& interface) + { + deviceInfo devInfo{}; + std::string wifiname = GnomeUtils::getWifiIfname(), ethname = GnomeUtils::getEthIfname(); + if(!GnomeUtils::getDeviceInfoByIfname(m_dbus, ethname.c_str(), devInfo)) + return false; + if(devInfo.state > NM_DEVICE_STATE_DISCONNECTED && devInfo.state < NM_DEVICE_STATE_DEACTIVATING) + interface = ethname; + else + interface = wifiname; // default is wifi + return true; + } + bool NetworkManagerClient::getPrimaryInterface(std::string& interface) { GError* error = nullptr; std::string primaryConnectionPath; GDBusProxy *nmProxy = nullptr; + nmProxy = m_dbus.getNetworkManagerPropertyProxy("/org/freedesktop/NetworkManager"); if(nmProxy == nullptr) return false; @@ -753,7 +767,7 @@ namespace WPEFramework return true; } - bool NetworkManagerClient::getIPSettings(const std::string& interface, const std::string& ipversion, Exchange::INetworkManager::IPAddress& result) + bool NetworkManagerClient::getIPSettings(std::string& interface, const std::string& ipversion, Exchange::INetworkManager::IPAddress& result) { std::string devicePath; std::string addressStr; @@ -772,12 +786,52 @@ namespace WPEFramework const gchar *IPv6Method = nullptr; deviceInfo devInfo{}; GError *error = nullptr; + + std::string wifiname = GnomeUtils::getWifiIfname(), ethname = GnomeUtils::getEthIfname(); + + if(interface.empty()) + { + if(Core::ERROR_NONE != _instance->GetPrimaryInterface(interface)) + { + NMLOG_WARNING("default interface get failed"); + return true; + } + if(interface.empty()) + { + NMLOG_DEBUG("default interface return empty default is wlan0"); + interface = wifiname; + } + } + else if(wifiname != interface && ethname != interface) + { + NMLOG_ERROR("interface: %s; not valied", interface.c_str()); + return false; + } + + if(!GnomeUtils::getDeviceInfoByIfname(m_dbus, interface.c_str(), devInfo)) + { + return false; + } + + if(devInfo.state < NM_DEVICE_STATE_DISCONNECTED) + { + NMLOG_WARNING("Device state is not a valid state: (%d)", devInfo.state); + return false; + } + else if (devInfo.state >= NM_DEVICE_STATE_DISCONNECTED && devInfo.state < NM_DEVICE_STATE_ACTIVATED) + { + result.autoconfig = true; + result.ipversion = ipversion; + return true; + } + if(!GnomeUtils::getDeviceByIpIface(m_dbus, interface.c_str(), devicePath)) return false; GDBusProxy *deviceProxy = m_dbus.getNetworkManagerDeviceProxy(devicePath.c_str()); if(deviceProxy == nullptr) return false; - if (g_strcmp0(ipversion.c_str(), "IPv4") == 0) + if(ipversion.empty() || (g_strcmp0(ipversion.c_str(), "IPv4") == 0)) + //if (g_strcmp0(ipversion.c_str(), "IPv4") == 0) { GVariant *ip4Property = g_dbus_proxy_get_cached_property(deviceProxy, "Ip4Config"); if (ip4Property != nullptr) @@ -895,6 +949,7 @@ namespace WPEFramework if (dhcpServerIp) { NMLOG_DEBUG("DHCP server IP address: %s", dhcpServerIp); } else { + dhcpServerIp = nullptr; NMLOG_DEBUG("Failed to find DHCP server IP address"); } if (dnsAddresses) { @@ -920,8 +975,10 @@ namespace WPEFramework g_object_unref(dhcpv4Proxy); } } + result.ipversion = "IPv4"; } - else if (g_strcmp0(ipversion.c_str(), "IPv6") == 0) + if((addressStr.empty() && !(g_strcmp0(ipversion.c_str(), "IPv4"))) || g_strcmp0(ipversion.c_str(), "IPV6")) + //else if (g_strcmp0(ipversion.c_str(), "IPv6") == 0) { GVariant *ip6Property = g_dbus_proxy_get_cached_property(deviceProxy, "Ip6Config"); if (ip6Property != nullptr) { @@ -997,6 +1054,7 @@ namespace WPEFramework } else { + gatewayIp = nullptr; NMLOG_ERROR("Failed to get Gateway property for IPv6"); g_object_unref(ipv6Proxy); } @@ -1059,6 +1117,7 @@ namespace WPEFramework NMLOG_ERROR("Failed to parse DNS addresses"); } } else { + dnsList = nullptr; std::cerr << "Failed to find DNS addresses" << std::endl; } } @@ -1068,6 +1127,15 @@ namespace WPEFramework g_object_unref(dhcpv6Proxy); } } + result.ipversion = "IPv6"; + } + else + NMLOG_WARNING("ipversion error IPv4/IPv6"); + if(addressStr.empty()) + { + result.autoconfig = true; + if(ipversion.empty()) + result.ipversion = "IPv4"; } std::string connectionPath; if (!GnomeUtils::getSettingsConnectionPath(m_dbus, connectionPath, interface)) @@ -1076,13 +1144,12 @@ namespace WPEFramework return false; } - if(!GnomeUtils::getDeviceInfoByIfname(m_dbus, interface.c_str(), devInfo)) - return false; + /*if(!GnomeUtils::getDeviceInfoByIfname(m_dbus, interface.c_str(), devInfo)) + return false;*/ GDBusProxy *settingsProxy = m_dbus.getNetworkManagerSettingsConnectionProxy(connectionPath.c_str()); if (settingsProxy == nullptr) { - NMLOG_ERROR("Error creating connection settings proxy: %s",error->message); - g_error_free(error); + NMLOG_ERROR("Error creating connection settings proxy"); return false; } @@ -1129,7 +1196,6 @@ namespace WPEFramework } } - result.ipversion = ipversion; result.autoconfig = true; if(g_strcmp0(ipversion.c_str(), "IPv4") == 0) result.autoconfig = (g_strcmp0(IPv4Method, "auto") == 0); diff --git a/plugin/gnome/gdbus/NetworkManagerGdbusClient.h b/plugin/gnome/gdbus/NetworkManagerGdbusClient.h index 9a727b92..1cd9cf72 100644 --- a/plugin/gnome/gdbus/NetworkManagerGdbusClient.h +++ b/plugin/gnome/gdbus/NetworkManagerGdbusClient.h @@ -53,8 +53,9 @@ namespace WPEFramework bool setInterfaceState(const std::string& interface, bool enable); bool setIPSettings(const std::string& interface, const Exchange::INetworkManager::IPAddress& address); bool getPrimaryInterface(std::string& interface); + bool getDefaultInterface(std::string& interface); bool getInterfaceState(const std::string& interface, bool& isEnabled); - bool getIPSettings(const std::string& interface, const std::string& ipversion, Exchange::INetworkManager::IPAddress& result); + bool getIPSettings(std::string& interface, const std::string& ipversion, Exchange::INetworkManager::IPAddress& result); bool getKnownSSIDs(std::list& ssids); bool getConnectedSSID(Exchange::INetworkManager::WiFiSSIDInfo& ssidinfo); bool addToKnownSSIDs(const Exchange::INetworkManager::WiFiConnectTo& ssidinfo); diff --git a/plugin/gnome/gdbus/NetworkManagerGdbusProxy.cpp b/plugin/gnome/gdbus/NetworkManagerGdbusProxy.cpp index 9e34eb0f..5c499785 100644 --- a/plugin/gnome/gdbus/NetworkManagerGdbusProxy.cpp +++ b/plugin/gnome/gdbus/NetworkManagerGdbusProxy.cpp @@ -113,12 +113,18 @@ namespace WPEFramework uint32_t NetworkManagerImplementation::GetPrimaryInterface (string& interface /* @out */) { - uint32_t rc = Core::ERROR_GENERAL; if(_nmGdbusClient->getPrimaryInterface(interface)) - rc = Core::ERROR_NONE; + return Core::ERROR_NONE; else - NMLOG_ERROR("GetPrimaryInterface failed"); - return rc; + { + if(_nmGdbusClient->getDefaultInterface(interface)) + { + _instance->m_defaultInterface = interface; + return Core::ERROR_NONE; + } + else + return Core::ERROR_GENERAL; + } } uint32_t NetworkManagerImplementation::SetPrimaryInterface (const string& interface/* @in */) From 952b96b913f3e1c2a38f56e4f2fe35b6dc18b9d5 Mon Sep 17 00:00:00 2001 From: gururaajar <83449026+gururaajar@users.noreply.github.com> Date: Fri, 6 Jun 2025 14:29:58 -0400 Subject: [PATCH 3/3] Update NetworkManagerGdbusClient.cpp --- plugin/gnome/gdbus/NetworkManagerGdbusClient.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugin/gnome/gdbus/NetworkManagerGdbusClient.cpp b/plugin/gnome/gdbus/NetworkManagerGdbusClient.cpp index fb1e8ecd..48a0f53c 100644 --- a/plugin/gnome/gdbus/NetworkManagerGdbusClient.cpp +++ b/plugin/gnome/gdbus/NetworkManagerGdbusClient.cpp @@ -816,10 +816,13 @@ namespace WPEFramework NMLOG_WARNING("Device state is not a valid state: (%d)", devInfo.state); return false; } - else if (devInfo.state > NM_DEVICE_STATE_DISCONNECTED && devInfo.state < NM_DEVICE_STATE_ACTIVATED) + else if (devInfo.state > NM_DEVICE_STATE_DISCONNECTED && devInfo.state < NM_DEVICE_STATE_IP_CHECK) { result.autoconfig = true; - result.ipversion = ipversion; + if(ipversion.empty()) + result.ipversion = "IPv4"; + else + result.ipversion = ipversion; return true; } @@ -1125,8 +1128,6 @@ namespace WPEFramework } result.ipversion = "IPv6"; } - else - NMLOG_WARNING("ipversion error IPv4/IPv6"); if(addressStr.empty()) { result.autoconfig = true;