diff --git a/Tests/raspberrypi/NetworkManagerGdbusTest.cpp b/Tests/raspberrypi/NetworkManagerGdbusTest.cpp index 1c66afdc..3c827b37 100644 --- a/Tests/raspberrypi/NetworkManagerGdbusTest.cpp +++ b/Tests/raspberrypi/NetworkManagerGdbusTest.cpp @@ -100,7 +100,7 @@ int main() { case 3: { Exchange::INetworkManager::WiFiSSIDInfo ssidinfo; if (nmClient->getConnectedSSID(ssidinfo)) { - NMLOG_INFO("Connected SSID: %s", ssidinfo.m_ssid.c_str()); + NMLOG_INFO("Connected SSID: %s", ssidinfo.ssid.c_str()); } else { NMLOG_ERROR("Failed to get connected SSID"); } @@ -116,10 +116,10 @@ int main() { std::getline(std::cin, passphrase); WPEFramework::Exchange::INetworkManager::WIFISecurityMode securityType = getSecurityType(); Exchange::INetworkManager::WiFiConnectTo ssidinfo = { - .m_ssid = ssid, - .m_passphrase = passphrase, - .m_securityMode = securityType, - .m_persistSSIDInfo = true, + .ssid = ssid, + .passphrase = passphrase, + .security = securityType, + .persist = true, }; if (nmClient->addToKnownSSIDs(ssidinfo)) { NMLOG_INFO("SSID added to known list successfully"); @@ -172,10 +172,10 @@ int main() { std::cin >> persist; Exchange::INetworkManager::WiFiConnectTo ssidinfo = { - .m_ssid = ssid, - .m_passphrase = passphrase, - .m_securityMode = securityType, - .m_persistSSIDInfo = persist + .ssid = ssid, + .passphrase = passphrase, + .security = securityType, + .persist = persist }; if (nmClient->wifiConnect(ssidinfo)) { diff --git a/gdbus/NetworkManagerGdbusClient.cpp b/gdbus/NetworkManagerGdbusClient.cpp index 19546a47..80316b8a 100644 --- a/gdbus/NetworkManagerGdbusClient.cpp +++ b/gdbus/NetworkManagerGdbusClient.cpp @@ -79,14 +79,11 @@ namespace WPEFramework if(gVarConn) { - const char *connTyp= NULL; + const char *connTyp = NULL; + const char *interfaceName = NULL; G_VARIANT_LOOKUP(gVarConn, "type", "&s", &connTyp); - if(strcmp(connTyp, "802-11-wireless") != 0) - { - //NMLOG_DEBUG("ERROR: connection is not 802-11-wireless type"); - ret = false; - } - else + G_VARIANT_LOOKUP(gVarConn, "interface-name", "&s", &interfaceName); + if((strcmp(connTyp, "802-11-wireless") == 0) && strcmp(interfaceName, GnomeUtils::getWifiIfname()) != 0 ) { // 802-11-wireless.ssid: GVariant *setting = NULL; @@ -135,6 +132,8 @@ namespace WPEFramework ret = true; } } + else + ret = false; g_variant_unref(gVarConn); } @@ -208,7 +207,7 @@ namespace WPEFramework GVariant* result = NULL; gchar *activeApPath = NULL; bool ret = false; - deviceInfo devInfo; + deviceInfo devInfo{}; if(!GnomeUtils::getDeviceInfoByIfname(m_dbus, GnomeUtils::getWifiIfname(), devInfo)) return false; @@ -234,7 +233,7 @@ namespace WPEFramework if(g_strdup(activeApPath) != NULL && g_strcmp0(activeApPath, "/") != 0) { //NMLOG_DEBUG("ActiveAccessPoint property path %s", activeApPath); - if(GnomeUtils::getApDetails(m_dbus.getConnection(), g_strdup(activeApPath), ssidinfo)) + if(GnomeUtils::getApDetails(m_dbus, g_strdup(activeApPath), ssidinfo)) { ret = true; } @@ -251,7 +250,7 @@ namespace WPEFramework { GError* error = nullptr; GDBusProxy* wProxy = nullptr; - deviceInfo devProperty; + deviceInfo devProperty{}; if(!GnomeUtils::getDeviceInfoByIfname(m_dbus, GnomeUtils::getWifiIfname(), devProperty)) return false; @@ -274,17 +273,17 @@ namespace WPEFramework return false; } - GVariantIter* iter; - const gchar* apPath; + GVariantIter* iter = NULL; + const gchar* apPath = NULL; g_variant_get(result, "(ao)", &iter); while (g_variant_iter_loop(iter, "o", &apPath)) { - Exchange::INetworkManager::WiFiSSIDInfo wifiInfo; + Exchange::INetworkManager::WiFiSSIDInfo wifiInfo{}; NMLOG_DEBUG("Access Point Path: %s", apPath); - if(!GnomeUtils::getApDetails(m_dbus.getConnection(), apPath, wifiInfo)) + if(!GnomeUtils::getApDetails(m_dbus, apPath, wifiInfo)) NMLOG_WARNING("getApDetails failed"); else - ssids.push_back(wifiInfo.m_ssid); + ssids.push_back(wifiInfo.ssid); } g_variant_iter_free(iter); @@ -451,7 +450,7 @@ namespace WPEFramework g_variant_builder_init (&optionsBuilder, G_VARIANT_TYPE ("a{sv}")); if(!persist) // by default it will be in disk mode { - NMLOG_ERROR("wifi connection will not persist to the disk"); + NMLOG_WARNING("wifi connection will not persist to the disk"); g_variant_builder_add(&optionsBuilder, "{sv}", "persist", g_variant_new_string("volatile")); } //else @@ -478,27 +477,32 @@ namespace WPEFramework const char* newConnPath = g_variant_get_string(pathVariant, nullptr); const char* activeConnPath = g_variant_get_string(activeConnVariant, nullptr); - NMLOG_DEBUG("newconn %s; activeconn %s",newConnPath, activeConnPath); - g_variant_unref(pathVariant); - g_variant_unref(activeConnVariant); - g_variant_unref(resultDict); - g_variant_unref(result); - g_object_unref(proxy); - + NMLOG_INFO("newconn %s; activeconn %s",newConnPath, activeConnPath); + if(pathVariant) + g_variant_unref(pathVariant); + if(activeConnVariant) + g_variant_unref(activeConnVariant); + if(resultDict) + g_variant_unref(resultDict); + if(result) + g_variant_unref(result); + if(proxy) + g_object_unref(proxy); return true; } - static bool gVariantConnectionBuilder(const Exchange::INetworkManager::WiFiConnectTo& ssidinfo, GVariantBuilder& connBuilder, bool isWPSConn) + static bool gVariantConnectionBuilder(const Exchange::INetworkManager::WiFiConnectTo& ssidinfo, GVariantBuilder& connBuilder) { char *uuid = NULL; GVariantBuilder settingsBuilder; - if(ssidinfo.m_ssid.empty() || ssidinfo.m_ssid.length() > 32) + if(ssidinfo.ssid.empty() || ssidinfo.ssid.length() > 32) { NMLOG_WARNING("ssid name is missing or invalied"); return false; } + NMLOG_INFO("ssid %s, security %d, persist %d", ssidinfo.ssid.c_str(), (int)ssidinfo.security, (int)ssidinfo.persist); /* Build up the complete connection */ g_variant_builder_init (&connBuilder, G_VARIANT_TYPE ("a{sa{sv}}")); @@ -513,7 +517,7 @@ namespace WPEFramework g_variant_builder_add (&settingsBuilder, "{sv}", NM_SETTING_CONNECTION_ID, - g_variant_new_string (ssidinfo.m_ssid.c_str())); + g_variant_new_string (ssidinfo.ssid.c_str())); // connection id = ssid name g_variant_builder_add (&settingsBuilder, "{sv}", NM_SETTING_CONNECTION_INTERFACE_NAME, @@ -529,7 +533,7 @@ namespace WPEFramework /* Add the '802-11-wireless' Setting */ g_variant_builder_init (&settingsBuilder, G_VARIANT_TYPE ("a{sv}")); - GVariant *ssid_array = g_variant_new_fixed_array(G_VARIANT_TYPE_BYTE, (const guint8 *)ssidinfo.m_ssid.c_str(), ssidinfo.m_ssid.length(), 1); + GVariant *ssid_array = g_variant_new_fixed_array(G_VARIANT_TYPE_BYTE, (const guint8 *)ssidinfo.ssid.c_str(), ssidinfo.ssid.length(), 1); g_variant_builder_add (&settingsBuilder, "{sv}", NM_SETTING_WIRELESS_SSID, ssid_array); @@ -549,7 +553,7 @@ namespace WPEFramework /* Build up the '802-11-wireless-security' settings */ g_variant_builder_init (&settingsBuilder, G_VARIANT_TYPE ("a{sv}")); - switch(ssidinfo.m_securityMode) + switch(ssidinfo.security) { case Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA_PSK_TKIP: case Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA_PSK_AES: @@ -559,13 +563,13 @@ namespace WPEFramework case Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA3_PSK_AES: case Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA3_SAE: { - if(ssidinfo.m_passphrase.empty() || ssidinfo.m_passphrase.length() < 8) + if(ssidinfo.passphrase.empty() || ssidinfo.passphrase.length() < 8) { NMLOG_WARNING("wifi securtity type password erro length > 8"); return false; } - if(Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA3_SAE == ssidinfo.m_securityMode) + if(Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA3_SAE == ssidinfo.security) { NMLOG_DEBUG("802-11-wireless-security key-mgmt: 'sae'"); g_variant_builder_add (&settingsBuilder, "{sv}", NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, @@ -578,28 +582,20 @@ namespace WPEFramework g_variant_new_string("wpa-psk")); // WPA + WPA2 + WPA3 personal } g_variant_builder_add (&settingsBuilder, "{sv}", NM_SETTING_WIRELESS_SECURITY_PSK, - g_variant_new_string(ssidinfo.m_passphrase.c_str())); + g_variant_new_string(ssidinfo.passphrase.c_str())); break; } - case Exchange::INetworkManager::WIFI_SECURITY_WEP_64: - case Exchange::INetworkManager::WIFI_SECURITY_WEP_128: case Exchange::INetworkManager::WIFI_SECURITY_NONE: { NMLOG_DEBUG("802-11-wireless-security key-mgmt: 'none'"); g_variant_builder_add (&settingsBuilder, "{sv}", NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, - g_variant_new_string("none")); // WEP or no password protection - if(isWPSConn) - { - g_variant_builder_add (&settingsBuilder, "{sv}", - NM_SETTING_WIRELESS_SECURITY_WPS_METHOD, - g_variant_new_byte(NM_SETTING_WIRELESS_SECURITY_WPS_METHOD_AUTO)); - } + g_variant_new_string("none")); // no password protection break; } default: { - NMLOG_WARNING("connection wifi securtity type not supported %d", ssidinfo.m_securityMode); + NMLOG_WARNING("connection wifi securtity type not supported %d", ssidinfo.security); return false; } } @@ -651,13 +647,13 @@ namespace WPEFramework return false; } - std::list paths; - if(GnomeUtils::getwifiConnectionPaths(m_dbus, deviceProp.path.c_str(), paths)) + std::list paths{}; + if(GnomeUtils::getWifiConnectionPaths(m_dbus, deviceProp.path.c_str(), paths)) { for (const std::string& path : paths) { - std::string ssid; - if(getSSIDFromConnection(m_dbus, path, ssid) && ssid == ssidinfo.m_ssid) + std::string ssid{}; + if(getSSIDFromConnection(m_dbus, path, ssid) && ssid == ssidinfo.ssid) { exsistingConn = path; NMLOG_DEBUG("same connection exsist (%s) updating ...", exsistingConn.c_str()); @@ -667,7 +663,7 @@ namespace WPEFramework } } - if(!gVariantConnectionBuilder(ssidinfo, connBuilder, false)) + if(!gVariantConnectionBuilder(ssidinfo, connBuilder)) { NMLOG_WARNING("connection builder failed"); return false; @@ -778,8 +774,8 @@ namespace WPEFramework } else { - ssid = ssidInfo.m_ssid; - signalStrength = ssidInfo.m_signalStrength; + ssid = ssidInfo.ssid; + signalStrength = ssidInfo.strength; float signalStrengthFloat = 0.0f; if(!signalStrength.empty()) @@ -839,7 +835,6 @@ namespace WPEFramework bool NetworkManagerClient::wifiConnect(const Exchange::INetworkManager::WiFiConnectTo& ssidinfo) { - // TODO check argument length password min 8 and 32 // TODO check sudo nmcli device wifi connect HomeNet password rafi@123 // Error: Connection activation failed: Device disconnected by user or client error ? GVariantBuilder connBuilder; @@ -857,11 +852,11 @@ namespace WPEFramework } std::list paths; - if(GnomeUtils::getwifiConnectionPaths(m_dbus, deviceProp.path.c_str(), paths)) + if(GnomeUtils::getWifiConnectionPaths(m_dbus, deviceProp.path.c_str(), paths)) { for (const std::string& path : paths) { std::string ssid; - if(getSSIDFromConnection(m_dbus, path, ssid) && ssid == ssidinfo.m_ssid) + if(getSSIDFromConnection(m_dbus, path, ssid) && ssid == ssidinfo.ssid) { exsistingConn = path; NMLOG_WARNING("same connection exsist (%s)", exsistingConn.c_str()); @@ -874,7 +869,7 @@ namespace WPEFramework if(reuseConnection) { NMLOG_INFO("activating connection..."); - ret = gVariantConnectionBuilder(ssidinfo, connBuilder, true); + ret = gVariantConnectionBuilder(ssidinfo, connBuilder); if(!ret) { NMLOG_WARNING("connection builder failed"); return false; @@ -887,12 +882,12 @@ namespace WPEFramework } else { - ret = gVariantConnectionBuilder(ssidinfo, connBuilder, true); + ret = gVariantConnectionBuilder(ssidinfo, connBuilder); if(!ret) { NMLOG_WARNING("connection builder failed"); return false; } - if(addNewConnctionAndactivate(m_dbus, connBuilder, deviceProp.path.c_str(), ssidinfo.m_persistSSIDInfo)) + if(addNewConnctionAndactivate(m_dbus, connBuilder, deviceProp.path.c_str(), ssidinfo.persist)) NMLOG_INFO("wifi connect request success"); else NMLOG_ERROR("wifi connect request failed"); @@ -935,7 +930,12 @@ namespace WPEFramework bool NetworkManagerClient::startWPS() { - + return false; + } + + bool NetworkManagerClient::stopWPS() + { + return false; } } // WPEFramework diff --git a/gdbus/NetworkManagerGdbusClient.h b/gdbus/NetworkManagerGdbusClient.h index 3fc299ae..15b8eb11 100644 --- a/gdbus/NetworkManagerGdbusClient.h +++ b/gdbus/NetworkManagerGdbusClient.h @@ -55,8 +55,7 @@ namespace WPEFramework bool getWifiState(Exchange::INetworkManager::WiFiState &state); bool getWiFiSignalStrength(std::string& ssid, std::string& signalStrength, Exchange::INetworkManager::WiFiSignalQuality& quality); bool startWPS(); - bool stopWPS() {return false;} - bool stopWiFiScan() {return false;} + bool stopWPS(); private: NetworkManagerClient(); diff --git a/gdbus/NetworkManagerGdbusEvent.cpp b/gdbus/NetworkManagerGdbusEvent.cpp index ca8f36d7..8f7268be 100644 --- a/gdbus/NetworkManagerGdbusEvent.cpp +++ b/gdbus/NetworkManagerGdbusEvent.cpp @@ -725,7 +725,7 @@ namespace WPEFramework while (g_variant_iter_loop(iter, "o", &apPath)) { Exchange::INetworkManager::WiFiSSIDInfo wifiInfo; // NMLOG_DEBUG("Access Point Path: %s", apPath); - if(GnomeUtils::getApDetails(_NetworkManagerEvents->eventDbus.getConnection(), apPath, wifiInfo)) + if(GnomeUtils::getApDetails(_NetworkManagerEvents->eventDbus, apPath, wifiInfo)) { JsonObject ssidObj; if(GnomeUtils::convertSsidInfoToJsonObject(wifiInfo, ssidObj)) diff --git a/gdbus/NetworkManagerGdbusMgr.cpp b/gdbus/NetworkManagerGdbusMgr.cpp index f77d56ec..6aa242b3 100644 --- a/gdbus/NetworkManagerGdbusMgr.cpp +++ b/gdbus/NetworkManagerGdbusMgr.cpp @@ -29,9 +29,9 @@ namespace WPEFramework namespace Plugin { - DbusMgr::DbusMgr() : connection(nullptr) + DbusMgr::DbusMgr() : connection(NULL) { - GError* error = nullptr; + GError* error = NULL; NMLOG_INFO("DbusMgr"); connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); if (!connection) { @@ -44,7 +44,7 @@ namespace WPEFramework NMLOG_INFO("~DbusMgr"); if (connection) { g_object_unref(connection); - connection = nullptr; + connection = NULL; } } @@ -54,12 +54,12 @@ namespace WPEFramework return connection; } - GError* error = nullptr; + GError* error = NULL; connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); if (!connection && error) { NMLOG_FATAL("Error reconnecting to system bus: %s ", error->message); g_error_free(error); - return nullptr; + return NULL; } flags = static_cast(G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START); @@ -68,7 +68,7 @@ namespace WPEFramework GDBusProxy* DbusMgr::getNetworkManagerProxy() { - GError* error = nullptr; + GError* error = NULL; nmProxy = NULL; nmProxy = g_dbus_proxy_new_sync( getConnection(), G_DBUS_PROXY_FLAGS_NONE, NULL, "org.freedesktop.NetworkManager", @@ -82,7 +82,7 @@ namespace WPEFramework g_dbus_error_strip_remote_error(error); NMLOG_FATAL("Error creating D-Bus proxy: %s", error->message); g_error_free(error); - return nullptr; + return NULL; } return nmProxy; @@ -90,12 +90,12 @@ namespace WPEFramework GDBusProxy* DbusMgr::getNetworkManagerSettingsProxy() { - GError* error = nullptr; + GError* error = NULL; GDBusProxy* proxy = g_dbus_proxy_new_sync( - getConnection(), flags, nullptr, "org.freedesktop.NetworkManager", + getConnection(), flags, NULL, "org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager/Settings", "org.freedesktop.NetworkManager.Settings", - nullptr, + NULL, &error ); @@ -103,7 +103,7 @@ namespace WPEFramework g_dbus_error_strip_remote_error(error); NMLOG_FATAL("Error creating proxy: %s", error->message); g_clear_error(&error); - return nullptr; + return NULL; } return proxy; @@ -111,12 +111,12 @@ namespace WPEFramework GDBusProxy* DbusMgr::getNetworkManagerSettingsConnectionProxy(const char* connPath) { - GError* error = nullptr; + GError* error = NULL; GDBusProxy* proxy = g_dbus_proxy_new_sync( - getConnection(), flags, nullptr, "org.freedesktop.NetworkManager", + getConnection(), flags, NULL, "org.freedesktop.NetworkManager", connPath, "org.freedesktop.NetworkManager.Settings.Connection", - nullptr, + NULL, &error ); @@ -124,7 +124,7 @@ namespace WPEFramework g_dbus_error_strip_remote_error(error); NMLOG_FATAL("Error creating proxy: %s", error->message); g_clear_error(&error); - return nullptr; + return NULL; } return proxy; @@ -132,12 +132,12 @@ namespace WPEFramework GDBusProxy* DbusMgr::getNetworkManagerDeviceProxy(const char* devicePath) { - GError* error = nullptr; + GError* error = NULL; GDBusProxy* proxy = g_dbus_proxy_new_sync( - getConnection(), flags, nullptr, "org.freedesktop.NetworkManager", + getConnection(), flags, NULL, "org.freedesktop.NetworkManager", devicePath, "org.freedesktop.NetworkManager.Device", - nullptr, + NULL, &error ); @@ -145,7 +145,7 @@ namespace WPEFramework g_dbus_error_strip_remote_error(error); NMLOG_FATAL("Error creating proxy: %s", error->message); g_clear_error(&error); - return nullptr; + return NULL; } return proxy; @@ -153,12 +153,33 @@ namespace WPEFramework GDBusProxy* DbusMgr::getNetworkManagerActiveConnProxy(const char* activePath) { - GError* error = nullptr; + GError* error = NULL; GDBusProxy* proxy = g_dbus_proxy_new_sync( - getConnection(), flags, nullptr, "org.freedesktop.NetworkManager", + getConnection(), flags, NULL, "org.freedesktop.NetworkManager", activePath, "org.freedesktop.NetworkManager.Connection.Active", - nullptr, + NULL, + &error + ); + + if (error != NULL) { + g_dbus_error_strip_remote_error(error); + NMLOG_FATAL("Error creating proxy: %s", error->message); + g_clear_error(&error); + return NULL; + } + + return proxy; + } + + GDBusProxy* DbusMgr::getNetworkManagerAccessPointProxy(const char* apPath) + { + GError* error = NULL; + GDBusProxy* proxy = g_dbus_proxy_new_sync( + getConnection(), flags, NULL, "org.freedesktop.NetworkManager", + apPath, + "org.freedesktop.NetworkManager.AccessPoint", + NULL, &error ); @@ -166,7 +187,7 @@ namespace WPEFramework g_dbus_error_strip_remote_error(error); NMLOG_FATAL("Error creating proxy: %s", error->message); g_clear_error(&error); - return nullptr; + return NULL; } return proxy; @@ -174,12 +195,12 @@ namespace WPEFramework GDBusProxy* DbusMgr::getNetworkManagerWirelessProxy(const char* wirelessDevPath) { - GError* error = nullptr; + GError* error = NULL; GDBusProxy* proxy = g_dbus_proxy_new_sync( - getConnection(), flags, nullptr, "org.freedesktop.NetworkManager", + getConnection(), flags, NULL, "org.freedesktop.NetworkManager", wirelessDevPath, "org.freedesktop.NetworkManager.Device.Wireless", - nullptr, + NULL, &error ); @@ -187,7 +208,7 @@ namespace WPEFramework g_dbus_error_strip_remote_error(error); NMLOG_FATAL("Error creating proxy: %s", error->message); g_clear_error(&error); - return nullptr; + return NULL; } return proxy; @@ -195,12 +216,12 @@ namespace WPEFramework GDBusProxy* DbusMgr::getNetworkManagerIpv4Proxy(const char* ipConfigPath) { - GError* error = nullptr; + GError* error = NULL; GDBusProxy* proxy = g_dbus_proxy_new_sync( - getConnection(), flags, nullptr, "org.freedesktop.NetworkManager", + getConnection(), flags, NULL, "org.freedesktop.NetworkManager", ipConfigPath, "org.freedesktop.NetworkManager.IP4Config", - nullptr, + NULL, &error ); @@ -208,7 +229,7 @@ namespace WPEFramework g_dbus_error_strip_remote_error(error); NMLOG_FATAL("Error creating proxy: %s", error->message); g_clear_error(&error); - return nullptr; + return NULL; } return proxy; @@ -216,12 +237,12 @@ namespace WPEFramework GDBusProxy* DbusMgr::getNetworkManagerIpv6Proxy(const char* ipConfigPath) { - GError* error = nullptr; + GError* error = NULL; GDBusProxy* proxy = g_dbus_proxy_new_sync( - getConnection(), flags, nullptr, "org.freedesktop.NetworkManager", + getConnection(), flags, NULL, "org.freedesktop.NetworkManager", ipConfigPath, "org.freedesktop.NetworkManager.IP6Config", - nullptr, + NULL, &error ); @@ -229,7 +250,7 @@ namespace WPEFramework g_dbus_error_strip_remote_error(error); NMLOG_FATAL("Error creating proxy: %s", error->message); g_clear_error(&error); - return nullptr; + return NULL; } return proxy; diff --git a/gdbus/NetworkManagerGdbusMgr.h b/gdbus/NetworkManagerGdbusMgr.h index b6e73b5f..c75915fa 100644 --- a/gdbus/NetworkManagerGdbusMgr.h +++ b/gdbus/NetworkManagerGdbusMgr.h @@ -43,6 +43,7 @@ namespace WPEFramework GDBusProxy* getNetworkManagerIpv4Proxy(const char* ipConfigPath); GDBusProxy* getNetworkManagerIpv6Proxy(const char* ipConfigPath); GDBusProxy* getNetworkManagerActiveConnProxy(const char* activePath); + GDBusProxy* getNetworkManagerAccessPointProxy(const char* apPath); GDBusConnection* getConnection(); private: diff --git a/gdbus/NetworkManagerGdbusProxy.cpp b/gdbus/NetworkManagerGdbusProxy.cpp index d16838e0..2067d4bd 100644 --- a/gdbus/NetworkManagerGdbusProxy.cpp +++ b/gdbus/NetworkManagerGdbusProxy.cpp @@ -30,8 +30,8 @@ namespace WPEFramework namespace Plugin { NetworkManagerImplementation* _instance = nullptr; - NetworkManagerClient* gnomeDbusClient = nullptr; - NetworkManagerEvents* nmEvents = NetworkManagerEvents::getInstance(); + NetworkManagerClient* _nmGdbusClient = nullptr; + NetworkManagerEvents* _nmGdbusEvents = nullptr; void NetworkManagerInternalEventHandler(const char *owner, int eventId, void *data, size_t len) { return; @@ -40,7 +40,8 @@ namespace WPEFramework void NetworkManagerImplementation::platform_init() { ::_instance = this; - gnomeDbusClient = NetworkManagerClient::getInstance(); + _nmGdbusClient = NetworkManagerClient::getInstance(); + _nmGdbusEvents = NetworkManagerEvents::getInstance(); } uint32_t NetworkManagerImplementation::GetAvailableInterfaces (Exchange::INetworkManager::IInterfaceDetailsIterator*& interfacesItr/* @out */) @@ -57,8 +58,7 @@ namespace WPEFramework { return Core::ERROR_NONE; } - - uint32_t NetworkManagerImplementation::SetInterfaceState(const string& interface/* @in */, const bool& enabled /* @in */) + uint32_t NetworkManagerImplementation::SetInterfaceState(const string& interface/* @in */, const bool enabled /* @in */) { return Core::ERROR_NONE; } @@ -66,23 +66,25 @@ namespace WPEFramework uint32_t NetworkManagerImplementation::GetInterfaceState(const string& interface/* @in */, bool& isEnabled /* @out */) { return Core::ERROR_NONE; - } + } - uint32_t NetworkManagerImplementation::GetIPSettings(const string& interface /* @in */, const string& ipversion /* @in */, IPAddressInfo& result /* @out */) + /* @brief Get IP Address Of the Interface */ + uint32_t NetworkManagerImplementation::GetIPSettings(string& interface /* @inout */, const string &ipversion /* @in */, IPAddress& result /* @out */) { return Core::ERROR_NONE; } - uint32_t NetworkManagerImplementation::SetIPSettings(const string& interface /* @in */, const string &ipversion /* @in */, const IPAddressInfo& address /* @in */) + /* @brief Set IP Address Of the Interface */ + uint32_t NetworkManagerImplementation::SetIPSettings(const string& interface /* @in */, const IPAddress& address /* @in */) { return Core::ERROR_NONE; } - uint32_t NetworkManagerImplementation::StartWiFiScan(const WiFiFrequency frequency /* @in */) + uint32_t NetworkManagerImplementation::StartWiFiScan(const string& frequency /* @in */, IStringIterator* const ssids/* @in */) { uint32_t rc = Core::ERROR_GENERAL; - nmEvents->setwifiScanOptions(true); - if(gnomeDbusClient->startWifiScan()) + _nmGdbusEvents->setwifiScanOptions(true); /* Enable event posting */ + if(_nmGdbusClient->startWifiScan()) rc = Core::ERROR_NONE; else NMLOG_ERROR("StartWiFiScan failed"); @@ -91,13 +93,9 @@ namespace WPEFramework uint32_t NetworkManagerImplementation::StopWiFiScan(void) { - // TODO FIX uint32_t rc = Core::ERROR_GENERAL; - nmEvents->setwifiScanOptions(false); - if(gnomeDbusClient->stopWiFiScan()) - rc = Core::ERROR_NONE; - else - NMLOG_ERROR("stopWiFiScan failed"); + _nmGdbusEvents->setwifiScanOptions(false); /* disable event posting */ + rc = Core::ERROR_NONE; return rc; } @@ -105,7 +103,7 @@ namespace WPEFramework { uint32_t rc = Core::ERROR_GENERAL; std::list ssidList; - if(gnomeDbusClient->getKnownSSIDs(ssidList) && !ssidList.empty()) + if(_nmGdbusClient->getKnownSSIDs(ssidList) && !ssidList.empty()) { ssids = Core::Service::Create(ssidList); rc = Core::ERROR_NONE; @@ -119,7 +117,7 @@ namespace WPEFramework uint32_t NetworkManagerImplementation::AddToKnownSSIDs(const WiFiConnectTo& ssid /* @in */) { uint32_t rc = Core::ERROR_GENERAL; - if(gnomeDbusClient->addToKnownSSIDs(ssid)) + if(_nmGdbusClient->addToKnownSSIDs(ssid)) rc = Core::ERROR_NONE; else NMLOG_ERROR("addToKnownSSIDs failed"); @@ -129,7 +127,7 @@ namespace WPEFramework uint32_t NetworkManagerImplementation::RemoveKnownSSID(const string& ssid /* @in */) { uint32_t rc = Core::ERROR_GENERAL; - if(gnomeDbusClient->removeKnownSSIDs(ssid)) + if(_nmGdbusClient->removeKnownSSIDs(ssid)) rc = Core::ERROR_NONE; else NMLOG_ERROR("RemoveKnownSSID failed"); @@ -139,7 +137,7 @@ namespace WPEFramework uint32_t NetworkManagerImplementation::WiFiConnect(const WiFiConnectTo& ssid /* @in */) { uint32_t rc = Core::ERROR_GENERAL; - if(gnomeDbusClient->wifiConnect(ssid)) + if(_nmGdbusClient->wifiConnect(ssid)) rc = Core::ERROR_NONE; else NMLOG_ERROR("WiFiConnect failed"); @@ -149,7 +147,7 @@ namespace WPEFramework uint32_t NetworkManagerImplementation::WiFiDisconnect(void) { uint32_t rc = Core::ERROR_GENERAL; - if(gnomeDbusClient->wifiDisconnect()) + if(_nmGdbusClient->wifiDisconnect()) rc = Core::ERROR_NONE; else NMLOG_ERROR("WiFiDisconnect failed"); @@ -159,7 +157,7 @@ namespace WPEFramework uint32_t NetworkManagerImplementation::GetConnectedSSID(WiFiSSIDInfo& ssidInfo /* @out */) { uint32_t rc = Core::ERROR_GENERAL; - if(gnomeDbusClient->getConnectedSSID(ssidInfo)) + if(_nmGdbusClient->getConnectedSSID(ssidInfo)) rc = Core::ERROR_NONE; else NMLOG_ERROR("getConnectedSSID failed"); @@ -169,7 +167,7 @@ namespace WPEFramework uint32_t NetworkManagerImplementation::GetWiFiSignalStrength(string& ssid /* @out */, string& signalStrength /* @out */, WiFiSignalQuality& quality /* @out */) { uint32_t rc = Core::ERROR_GENERAL; - if(gnomeDbusClient->getWiFiSignalStrength(ssid, signalStrength, quality)) + if(_nmGdbusClient->getWiFiSignalStrength(ssid, signalStrength, quality)) rc = Core::ERROR_NONE; else NMLOG_ERROR("GetWiFiSignalStrength failed"); @@ -179,7 +177,7 @@ namespace WPEFramework uint32_t NetworkManagerImplementation::GetWifiState(WiFiState &state) { uint32_t rc = Core::ERROR_GENERAL; - if(gnomeDbusClient->getWifiState(state)) + if(_nmGdbusClient->getWifiState(state)) rc = Core::ERROR_NONE; else NMLOG_ERROR("GetWifiState failed"); @@ -196,4 +194,4 @@ namespace WPEFramework return Core::ERROR_NONE; } } -} +} \ No newline at end of file diff --git a/gdbus/NetworkManagerGdbusUtils.cpp b/gdbus/NetworkManagerGdbusUtils.cpp index 4c630ad5..8aee0074 100644 --- a/gdbus/NetworkManagerGdbusUtils.cpp +++ b/gdbus/NetworkManagerGdbusUtils.cpp @@ -79,13 +79,13 @@ namespace WPEFramework bool GnomeUtils::getIpv6AddrFromIP6ConfigProxy( GDBusProxy *ipProxy, std::string& ipAddr, uint32_t& prefix) { - GVariantIter *iter; - GVariantIter *dictIter; - const gchar *key; - GVariant *value; - gchar *address = nullptr; - std::string ipAddress; - if(ipProxy == nullptr) + GVariantIter *iter = NULL; + GVariantIter *dictIter = NULL; + const gchar *key = NULL; + GVariant *value = NULL; + gchar *address = NULL; + std::string ipAddress{}; + if(ipProxy == NULL) { NMLOG_ERROR("ipv6 ipProxy is null"); return false; @@ -130,20 +130,12 @@ namespace WPEFramework bool GnomeUtils::convertSsidInfoToJsonObject(Exchange::INetworkManager::WiFiSSIDInfo& wifiInfo, JsonObject& ssidObj) { - std::string freq; - ssidObj["ssid"] = wifiInfo.m_ssid; - if (wifiInfo.m_frequency >= 2400 && wifiInfo.m_frequency < 5000) - freq = "2.4"; - else if (wifiInfo.m_frequency >= 5000 && wifiInfo.m_frequency < 6000) - freq = "5"; - else if (wifiInfo.m_frequency >= 6000) - freq = "6"; - else - freq = "Not available"; + std::string freq{}; - ssidObj["security"] = static_cast(wifiInfo.m_securityMode); - ssidObj["signalStrength"] = wifiInfo.m_signalStrength; - ssidObj["frequency"] = freq; + ssidObj["ssid"] = wifiInfo.ssid; + ssidObj["security"] = static_cast(wifiInfo.security); + ssidObj["strength"] = wifiInfo.strength; + ssidObj["frequency"] = wifiInfo.frequency; return true; } @@ -322,7 +314,7 @@ namespace WPEFramework return ret; } - bool GnomeUtils::getDeviceByIpIface(GDBusConnection *dbusConn, const gchar *iface_name, std::string& path) + bool GnomeUtils::getDeviceByIpIface(DbusMgr& m_dbus, const gchar *iface_name, std::string& path) { // TODO Fix Error calling method: // GDBus.Error:org.freedesktop.NetworkManager.UnknownDevice: No device found for the requested iface @@ -333,7 +325,7 @@ namespace WPEFramework bool ret = false; result = g_dbus_connection_call_sync( - dbusConn, + m_dbus.getConnection(), "org.freedesktop.NetworkManager", // D-Bus name "/org/freedesktop/NetworkManager", // Object path "org.freedesktop.NetworkManager", // Interface @@ -366,28 +358,18 @@ namespace WPEFramework return ret; } - bool GnomeUtils::getApDetails(GDBusConnection *connection, const char* apPath, Exchange::INetworkManager::WiFiSSIDInfo& wifiInfo) + bool GnomeUtils::getApDetails(DbusMgr& m_dbus, const char* apPath, Exchange::INetworkManager::WiFiSSIDInfo& wifiInfo) { guint32 flags= 0, wpaFlags= 0, rsnFlags= 0, freq= 0, bitrate= 0; uint8_t strength = 0; NM80211Mode mode = NM_802_11_MODE_UNKNOWN; bool ret = false; char *_bssid = NULL; - GError* error = NULL; GVariant* result = NULL; - GDBusProxy* proxy = g_dbus_proxy_new_sync(connection, - G_DBUS_PROXY_FLAGS_NONE, - NULL, - "org.freedesktop.NetworkManager", - apPath, - "org.freedesktop.NetworkManager.AccessPoint", - NULL, - &error); + GDBusProxy* proxy = m_dbus.getNetworkManagerAccessPointProxy(apPath); - if (error) { - NMLOG_ERROR("creating proxy: %s", error->message); - g_error_free(error); + if (proxy == NULL) { return false; } @@ -402,7 +384,7 @@ namespace WPEFramework const guchar *ssid_data = static_cast(g_variant_get_fixed_array(result, &ssid_length, sizeof(guchar))); if (ssid_data && ssid_length > 0 && ssid_length <= 32) { - wifiInfo.m_ssid.assign(reinterpret_cast(ssid_data), ssid_length); + wifiInfo.ssid.assign(reinterpret_cast(ssid_data), ssid_length); g_variant_unref(result); result = g_dbus_proxy_get_cached_property(proxy,"HwAddress"); @@ -413,7 +395,7 @@ namespace WPEFramework } g_variant_get(result, "s", &_bssid); if(_bssid != NULL) { - wifiInfo.m_bssid.assign(_bssid); + wifiInfo.bssid.assign(_bssid); } g_variant_unref(result); @@ -424,7 +406,7 @@ namespace WPEFramework return false; } g_variant_get(result, "y", &strength); - wifiInfo.m_signalStrength = GnomeUtils::convertPercentageToSignalStrengtStr((int)strength); + wifiInfo.strength = GnomeUtils::convertPercentageToSignalStrengtStr((int)strength); g_variant_unref(result); GnomeUtils::getCachedPropertyU(proxy, "Flags", &flags); @@ -434,9 +416,9 @@ namespace WPEFramework GnomeUtils::getCachedPropertyU(proxy, "Frequency", &freq); GnomeUtils::getCachedPropertyU(proxy, "MaxBitrate", &bitrate); - wifiInfo.m_frequency = static_cast(freq); - wifiInfo.m_rate = std::to_string(bitrate); - wifiInfo.m_securityMode = static_cast(wifiSecurityModeFromApFlags(flags, wpaFlags, rsnFlags)); + wifiInfo.frequency = static_cast(freq); + wifiInfo.rate = std::to_string(bitrate); + wifiInfo.security = static_cast(wifiSecurityModeFromApFlags(flags, wpaFlags, rsnFlags)); // NMLOG_DEBUG("SSID: %s", wifiInfo.m_ssid.c_str()); // NMLOG_DEBUG("bssid %s", wifiInfo.m_bssid.c_str()); @@ -483,7 +465,7 @@ namespace WPEFramework return result; } - bool GnomeUtils::getwifiConnectionPaths(DbusMgr& m_dbus, const char* devicePath, std::list& paths) + bool GnomeUtils::getWifiConnectionPaths(DbusMgr& m_dbus, const char* devicePath, std::list& paths) { GDBusProxy* nmProxy = NULL; GVariant* result = NULL; diff --git a/gdbus/NetworkManagerGdbusUtils.h b/gdbus/NetworkManagerGdbusUtils.h index f7dd6f79..00a71212 100644 --- a/gdbus/NetworkManagerGdbusUtils.h +++ b/gdbus/NetworkManagerGdbusUtils.h @@ -53,6 +53,12 @@ struct deviceInfo NMDeviceType deviceType; }; +#define G_VARIANT_LOOKUP(dict, key, format, ...) \ + if (!g_variant_lookup(dict, key, format, __VA_ARGS__)) {\ + NMLOG_ERROR("g_variant Key '%s' not found", key); \ + return FALSE; \ + } + namespace WPEFramework { namespace Plugin @@ -60,10 +66,10 @@ namespace WPEFramework class GnomeUtils { public: static void printKeyVariant(const char *setting_name, GVariant *setting); - static bool getDeviceByIpIface(GDBusConnection *dbusConn, const gchar *iface_name, std::string& path); - static bool getApDetails(GDBusConnection *connection, const char* apPath, Exchange::INetworkManager::WiFiSSIDInfo& wifiInfo); + static bool getDeviceByIpIface(DbusMgr& m_dbus, const gchar *iface_name, std::string& path); + static bool getApDetails(DbusMgr& m_dbus, const char* apPath, Exchange::INetworkManager::WiFiSSIDInfo& wifiInfo); static bool getConnectionPaths(DbusMgr& m_dbus, std::list& pathsList); - static bool getwifiConnectionPaths(DbusMgr& m_dbus, const char* devicePath, std::list& paths); + static bool getWifiConnectionPaths(DbusMgr& m_dbus, const char* devicePath, std::list& paths); static bool getDevicePropertiesByPath(DbusMgr& m_dbus, const char* devPath, deviceInfo& properties); static bool getDeviceInfoByIfname(DbusMgr& m_dbus, const char* ifname, deviceInfo& properties); static bool getCachedPropertyU(GDBusProxy* proxy, const char* propertiy, uint32_t *value); @@ -80,8 +86,3 @@ namespace WPEFramework } // Plugin } // WPEFramework -#define G_VARIANT_LOOKUP(dict, key, format, ...) \ - if (!g_variant_lookup(dict, key, format, __VA_ARGS__)) {\ - NMLOG_ERROR("g_variant Key '%s' not found", key); \ - return FALSE; \ - }