From 3c7a0336656856ec5f02bbedc44f55ae0fbdabe4 Mon Sep 17 00:00:00 2001 From: cmuhammedrafi Date: Sun, 13 Oct 2024 04:21:46 +0530 Subject: [PATCH] some correction --- GnomeProxy/NetworkManagerGnomeClient.cpp | 124 +++++------ GnomeProxy/NetworkManagerGnomeClient.h | 3 +- GnomeProxy/NetworkManagerGnomeUtils.cpp | 255 ++++++++++++++--------- GnomeProxy/NetworkManagerGnomeUtils.h | 16 ++ NetworkManagerLogger.cpp | 2 +- Tests/raspberrypi/rpiTest.cmake | 2 +- Tests/raspberrypi/rpiUnitTest.cpp | 41 ++-- 7 files changed, 266 insertions(+), 177 deletions(-) diff --git a/GnomeProxy/NetworkManagerGnomeClient.cpp b/GnomeProxy/NetworkManagerGnomeClient.cpp index 8976e9e6..feb0ecfd 100644 --- a/GnomeProxy/NetworkManagerGnomeClient.cpp +++ b/GnomeProxy/NetworkManagerGnomeClient.cpp @@ -91,8 +91,7 @@ namespace WPEFramework GError *error = NULL; GDBusProxy *ConnProxy = NULL; GVariant *settingsProxy= NULL, *connection= NULL, *sCon= NULL; - bool isFound; - const char *connId= NULL, *connTyp= NULL, *iface= NULL; + const char *connTyp= NULL, *iface= NULL; ConnProxy = g_dbus_proxy_new_sync(dbusConn, G_DBUS_PROXY_FLAGS_NONE, @@ -135,20 +134,18 @@ namespace WPEFramework if(strcmp(connTyp,"802-11-wireless") == 0) { G_VARIANT_LOOKUP(sCon, "interface-name", "&s", &iface); - if(strcmp(iface,"wlan0") != 0) + if(strcmp(iface, GnomeUtils::getWifiIfname()) == 0) { - NMLOG_ERROR("interafce-name connection not wlan0"); - if (sCon) - g_variant_unref(sCon); - } - - GVariant *setting = g_variant_lookup_value(connection, "802-11-wireless", NULL); - if (setting) - { - std::string bssid; - fetssidandbssid(setting, ssid, bssid); - g_variant_unref(setting); + GVariant *setting = g_variant_lookup_value(connection, "802-11-wireless", NULL); + if(setting) + { + std::string bssid; + fetssidandbssid(setting, ssid, bssid); + g_variant_unref(setting); + } } + else + NMLOG_DEBUG("iface name in connection not wlan0, %s", iface); } if (sCon) @@ -220,8 +217,7 @@ namespace WPEFramework for (const std::string& path : paths) { // NMLOG_DEBUG("connection path %s", path.c_str()); std::string ssid; - fetchSSIDFromConnection(dbusConnection.getConnection(), path, ssid); - if(!ssid.empty()) + if(fetchSSIDFromConnection(dbusConnection.getConnection(), path, ssid) && !ssid.empty()) ssids.push_back(ssid); } @@ -232,25 +228,22 @@ namespace WPEFramework bool NetworkManagerClient::getConnectedSSID(const Exchange::INetworkManager::WiFiSSIDInfo &ssidinfo) { - std::string wifiDevicePath; GError* error = NULL; GDBusProxy* wProxy = NULL; GVariant* result = NULL; gchar *activeApPath = NULL; bool ret = false; - NMDeviceState state; + deviceProperties properties; - if(!GnomeUtils::getDeviceByIpIface(dbusConnection.getConnection(),"wlan0", wifiDevicePath)) + if(!GnomeUtils::getDevicePropertiesByIfname(dbusConnection.getConnection(), GnomeUtils::getWifiIfname(), properties)) { NMLOG_ERROR("no wifi device found"); return false; } - if(GnomeUtils::getDeviceState(dbusConnection.getConnection(), "wlan0", state) && state < NM_DEVICE_STATE_DISCONNECTED) + if(properties.path.empty() || properties.state <= NM_DEVICE_STATE_DISCONNECTED) { - NMDeviceStateReason StateReason; - GnomeUtils::getDeviceStateReason(dbusConnection.getConnection(), "wlan0", StateReason); - NMLOG_ERROR("wifi device state is invallied"); + NMLOG_WARNING("access point not active"); return false; } @@ -258,14 +251,16 @@ namespace WPEFramework G_DBUS_PROXY_FLAGS_NONE, NULL, "org.freedesktop.NetworkManager", - wifiDevicePath.c_str(), + properties.path.c_str(), "org.freedesktop.NetworkManager.Device.Wireless", NULL, // GCancellable &error); - - if (error) { - NMLOG_ERROR("Error creating proxy: %s", error->message); - g_error_free(error); + if(wProxy == NULL) + { + if (error) { + NMLOG_ERROR("Error creating proxy: %s", error->message); + g_error_free(error); + } return false; } @@ -299,20 +294,17 @@ namespace WPEFramework { GError* error = nullptr; GDBusProxy* wProxy = nullptr; - std::string wifiDevicePath; - NMDeviceState state; + deviceProperties properties; - if(GnomeUtils::getDeviceState(dbusConnection.getConnection(), "wlan0", state) && state < NM_DEVICE_STATE_DISCONNECTED) + if(!GnomeUtils::getDevicePropertiesByIfname(dbusConnection.getConnection(), GnomeUtils::getWifiIfname(), properties)) { - NMDeviceStateReason StateReason; - GnomeUtils::getDeviceStateReason(dbusConnection.getConnection(), "wlan0", StateReason); - NMLOG_ERROR("wifi device state is invallied"); + NMLOG_ERROR("no wifi device found"); return false; } - if(!GnomeUtils::getDeviceByIpIface(dbusConnection.getConnection(),"wlan0", wifiDevicePath)) + if(properties.path.empty() || properties.state < NM_DEVICE_STATE_DISCONNECTED) { - NMLOG_ERROR("no wifi device found"); + NMLOG_WARNING("access point not active"); return false; } @@ -320,7 +312,7 @@ namespace WPEFramework G_DBUS_PROXY_FLAGS_NONE, NULL, "org.freedesktop.NetworkManager", - wifiDevicePath.c_str(), + properties.path.c_str(), "org.freedesktop.NetworkManager.Device.Wireless", NULL, &error); @@ -364,18 +356,25 @@ namespace WPEFramework { GError* error = NULL; GDBusProxy* wProxy = NULL; - std::string wifiDevicePath; - if(!GnomeUtils::getDeviceByIpIface(dbusConnection.getConnection(),"wlan0", wifiDevicePath)) + deviceProperties properties; + + if(!GnomeUtils::getDevicePropertiesByIfname(dbusConnection.getConnection(), GnomeUtils::getWifiIfname(), properties)) { NMLOG_ERROR("no wifi device found"); return false; } + if(properties.path.empty() || properties.state < NM_DEVICE_STATE_DISCONNECTED) + { + NMLOG_WARNING("access point not active"); + return false; + } + wProxy = g_dbus_proxy_new_sync(dbusConnection.getConnection(), G_DBUS_PROXY_FLAGS_NONE, NULL, "org.freedesktop.NetworkManager", - wifiDevicePath.c_str(), + properties.path.c_str(), "org.freedesktop.NetworkManager.Device.Wireless", NULL, &error); @@ -397,7 +396,7 @@ namespace WPEFramework if (g_variant_is_of_type (timestampVariant, G_VARIANT_TYPE_INT64)) { gint64 timestamp; timestamp = g_variant_get_int64 (timestampVariant); - NMLOG_DEBUG("Last scan timestamp: %lld", timestamp); + NMLOG_DEBUG("Last scan timestamp: %lld", static_cast(timestamp)); } else { g_warning("Unexpected variant type: %s", g_variant_get_type_string (timestampVariant)); } @@ -568,7 +567,7 @@ namespace WPEFramework g_variant_builder_add (&settingsBuilder, "{sv}", NM_SETTING_CONNECTION_INTERFACE_NAME, - g_variant_new_string ("wlan0")); + g_variant_new_string (GnomeUtils::getWifiIfname())); g_variant_builder_add (&settingsBuilder, "{sv}", NM_SETTING_CONNECTION_TYPE, @@ -728,20 +727,27 @@ namespace WPEFramework //TODO check if same connection is there and // verify ssid and password is same call read connection path and activate connection // if not same remove the connection + deviceProperties properties; - ret = gVariantConnectionBuilder(ssidinfo, connBuilder); - if(!ret) { - NMLOG_WARNING("connection builder failed"); + if(!GnomeUtils::getDevicePropertiesByIfname(dbusConnection.getConnection(), GnomeUtils::getWifiIfname(), properties)) + { + NMLOG_ERROR("no wifi device found"); return false; } - std::string wifiDevicePath; - if(!GnomeUtils::getDeviceByIpIface(dbusConnection.getConnection(),"wlan0", wifiDevicePath)) { - NMLOG_ERROR("no wifi device found"); + if(properties.path.empty() || properties.state == NM_DEVICE_STATE_UNKNOWN) + { + NMLOG_WARNING("access point not active"); return false; } - if(addNewConnctionAndactivate(dbusConnection.getConnection(), connBuilder, wifiDevicePath.c_str(), ssidinfo.m_persistSSIDInfo)) + ret = gVariantConnectionBuilder(ssidinfo, connBuilder); + if(!ret) { + NMLOG_WARNING("connection builder failed"); + return false; + } + + if(addNewConnctionAndactivate(dbusConnection.getConnection(), connBuilder, properties.path.c_str(), ssidinfo.m_persistSSIDInfo)) NMLOG_INFO("wifi connect request success"); else NMLOG_ERROR("wifi connect request Failed"); @@ -753,25 +759,25 @@ namespace WPEFramework { GError* error = NULL; GDBusProxy* wProxy = NULL; - std::string wifiDevicePath; - NMDeviceState state; - if(GnomeUtils::getDeviceState(dbusConnection.getConnection(), "wlan0", state) && state <= NM_DEVICE_STATE_DISCONNECTED) - { - NMLOG_ERROR("wifi device state is disconneted"); - return true; - } + deviceProperties properties; - if(!GnomeUtils::getDeviceByIpIface(dbusConnection.getConnection(),"wlan0", wifiDevicePath)) + if(!GnomeUtils::getDevicePropertiesByIfname(dbusConnection.getConnection(), GnomeUtils::getWifiIfname(), properties) || properties.path.empty()) { NMLOG_ERROR("no wifi device found"); return false; } + if(properties.state <= NM_DEVICE_STATE_DISCONNECTED) + { + NMLOG_WARNING("access point alreafy disconnected state"); + return true; + } + wProxy = g_dbus_proxy_new_sync(dbusConnection.getConnection(), G_DBUS_PROXY_FLAGS_NONE, NULL, "org.freedesktop.NetworkManager", - wifiDevicePath.c_str(), + properties.path.c_str(), "org.freedesktop.NetworkManager.Device", NULL, &error); @@ -782,7 +788,7 @@ namespace WPEFramework return false; } - GVariant* result = g_dbus_proxy_call_sync(wProxy, "Disconnect", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + g_dbus_proxy_call_sync(wProxy, "Disconnect", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (error) { NMLOG_ERROR("Error calling Disconnect method: %s", error->message); g_error_free(error); diff --git a/GnomeProxy/NetworkManagerGnomeClient.h b/GnomeProxy/NetworkManagerGnomeClient.h index 9ccdb3fd..cd151780 100644 --- a/GnomeProxy/NetworkManagerGnomeClient.h +++ b/GnomeProxy/NetworkManagerGnomeClient.h @@ -45,7 +45,7 @@ namespace WPEFramework bool getKnownSSIDs(std::list& ssids); bool getAvailableSSIDs(std::list& ssids); - bool getConnectedSSID(const Exchange::INetworkManager::WiFiSSIDInfo &ssidinfo); + bool getConnectedSSID(const Exchange::INetworkManager::WiFiSSIDInfo& ssidinfo); bool addToKnownSSIDs(const Exchange::INetworkManager::WiFiConnectTo& ssidinfo); bool removeKnownSSIDs(const std::string& ssid); bool startWifiScanning(const std::string ssid = ""); @@ -53,7 +53,6 @@ namespace WPEFramework bool wifiDisconnect(); private: - NetworkManagerClient(); ~NetworkManagerClient(); diff --git a/GnomeProxy/NetworkManagerGnomeUtils.cpp b/GnomeProxy/NetworkManagerGnomeUtils.cpp index 82c32453..91a39c30 100644 --- a/GnomeProxy/NetworkManagerGnomeUtils.cpp +++ b/GnomeProxy/NetworkManagerGnomeUtils.cpp @@ -31,7 +31,18 @@ namespace WPEFramework namespace Plugin { static const char* ifnameEth = "eth0"; - static const char* ifnameWlan = "wlan0"; + static const char* ifnameWlan = "wlp0s20f3"; + + std::string GnomeUtils::getCommaSeparatedSSIDs(const std::list& ssids) { + std::string result; + for (auto it = ssids.begin(); it != ssids.end(); ++it) { + result += *it; + if (std::next(it) != ssids.end()) { + result += ", "; + } + } + return result; + } void GnomeUtils::printKeyVariant(const char *setting_name, GVariant *setting) { @@ -51,7 +62,138 @@ namespace WPEFramework } } - bool GnomeUtils::getDeviceByIpIface(GDBusConnection *connection, const gchar *iface_name, std::string& path) + // TODO change this function + const char* GnomeUtils::getWifiIfname() { return ifnameWlan; } + const char* GnomeUtils::getEthIfname() { return ifnameEth; } + + bool GnomeUtils::getCachedPropertyU(GDBusProxy* proxy, const char* propertiy, uint32_t *value) + { + GVariant* result = NULL; + result = g_dbus_proxy_get_cached_property(proxy, propertiy); + if (!result) { + NMLOG_ERROR("Failed to get '%s' properties", propertiy); + g_object_unref(proxy); + return false; + } + + if (g_variant_is_of_type (result, G_VARIANT_TYPE_UINT32)) { + *value = g_variant_get_uint32(result); + NMLOG_DEBUG("%s: %d", propertiy, *value); + } + else + NMLOG_WARNING("Unexpected type returned property: %s", g_variant_get_type_string(result)); + g_variant_unref(result); + return true; + } + + bool GnomeUtils::getDevicePropertiesByPath(GDBusConnection *dbusConn, const char* devicePath, deviceProperties& properties) + { + GError *error = NULL; + GVariant *devicesVar = NULL; + GDBusProxy* nmProxy = NULL; + u_int32_t value; + + nmProxy = g_dbus_proxy_new_sync(dbusConn, + G_DBUS_PROXY_FLAGS_NONE, + NULL, // GDBusInterfaceInfo + "org.freedesktop.NetworkManager", // Bus name + devicePath, // Object path + "org.freedesktop.NetworkManager.Device", // Interface name + NULL, // GCancellable + &error); + + + if (error) { + NMLOG_ERROR("Error calling DBus.Properties method: %s", error->message); + g_error_free(error); + return false; + } + + + if(GnomeUtils::getCachedPropertyU(nmProxy, "DeviceType", &value)) + { + properties.deviceType = static_cast(value); + } + else + NMLOG_ERROR("'DeviceType' property failed"); + + devicesVar = g_dbus_proxy_get_cached_property(nmProxy, "Interface"); + if (devicesVar) { + const gchar *iface = g_variant_get_string(devicesVar, NULL); + if(iface != NULL) + properties.interface = iface; + NMLOG_DEBUG("Interface: %s", iface); + g_variant_unref(devicesVar); + } + else + NMLOG_ERROR("'Interface' property failed"); + + guint32 devState, stateReason; + devicesVar = g_dbus_proxy_get_cached_property(nmProxy, "StateReason"); + if (devicesVar) { + g_variant_get(devicesVar, "(uu)", &devState, &stateReason); + properties.state = static_cast(devState); + properties.stateReason = static_cast(stateReason); + g_variant_unref(devicesVar); + } + else + NMLOG_ERROR("'StateReason' property failed"); + + g_object_unref(nmProxy); + return true; + } + + bool GnomeUtils::getDevicePropertiesByIfname(GDBusConnection *dbusConn, const char* ifaceName, deviceProperties& properties) + { + GError *error = NULL; + GVariant *devicesVar = NULL; + bool ret = false; + + GDBusProxy* nmProxy = g_dbus_proxy_new_sync(dbusConn, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + "org.freedesktop.NetworkManager", + "/org/freedesktop/NetworkManager", + "org.freedesktop.NetworkManager", + NULL, + &error); + + devicesVar = g_dbus_proxy_call_sync(nmProxy, "GetDevices", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (error) { + NMLOG_ERROR("Error calling GetDevices method: %s", error->message); + g_error_free(error); + g_object_unref(nmProxy); + return false; + } + + GVariantIter* iter; + const gchar* devicePath; + g_variant_get(devicesVar, "(ao)", &iter); + while (g_variant_iter_loop(iter, "o", &devicePath)) + { + if(devicePath != NULL ) + { + if(getDevicePropertiesByPath(dbusConn, devicePath, properties) && properties.interface == ifaceName) + { + properties.path = devicePath; + ret = true; + break; + } + } + } + g_variant_iter_free(iter); + + if(!ret) + NMLOG_ERROR("'%s' interface not found", ifaceName); + + if(devicesVar) + g_variant_unref(devicesVar); + if(nmProxy) + g_object_unref(nmProxy); + return ret; + } + + bool GnomeUtils::getDeviceByIpIface(GDBusConnection *dbusConn, 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 @@ -62,7 +204,7 @@ namespace WPEFramework bool ret = false; result = g_dbus_connection_call_sync( - connection, + dbusConn, "org.freedesktop.NetworkManager", // D-Bus name "/org/freedesktop/NetworkManager", // Object path "org.freedesktop.NetworkManager", // Interface @@ -95,23 +237,6 @@ namespace WPEFramework return ret; } - static bool get_cached_property_u(GDBusProxy* proxy, const char* propertiy, uint32_t value) - { - GVariant* result = NULL; - result = g_dbus_proxy_get_cached_property(proxy, propertiy); - if (!result) { - NMLOG_ERROR("Failed to get AP properties"); - g_object_unref(proxy); - return false; - } - if (g_variant_is_of_type (result, G_VARIANT_TYPE_UINT32)) { - value = g_variant_get_uint32 (result); - NMLOG_DEBUG("%s: %d", propertiy, value); - } - g_variant_unref(result); - return true; - } - bool GnomeUtils::getApDetails(GDBusConnection *connection, const char* apPath, apProperties& apDetails) { char *bssid = NULL; @@ -172,11 +297,11 @@ namespace WPEFramework NMLOG_DEBUG("strength %d", strength); g_variant_unref(result); - get_cached_property_u(proxy, "Flags", apDetails.flags); - get_cached_property_u(proxy, "WpaFlags", apDetails.wpaFlags); - get_cached_property_u(proxy, "RsnFlags", apDetails.rsnFlags); - get_cached_property_u(proxy, "Mode", apDetails.mode); - get_cached_property_u(proxy, "Frequency", apDetails.frequency); + GnomeUtils::getCachedPropertyU(proxy, "Flags", &apDetails.flags); + GnomeUtils::getCachedPropertyU(proxy, "WpaFlags", &apDetails.wpaFlags); + GnomeUtils::getCachedPropertyU(proxy, "RsnFlags", &apDetails.rsnFlags); + GnomeUtils::getCachedPropertyU(proxy, "Mode", &apDetails.mode); + GnomeUtils::getCachedPropertyU(proxy, "Frequency", &apDetails.frequency); g_object_unref(proxy); @@ -251,91 +376,29 @@ namespace WPEFramework bool GnomeUtils::getDeviceState(GDBusConnection *dbusConn, const gchar *iface_name, NMDeviceState& state) { - GError *error = NULL; - GVariant *result; - std::string ifaceDevicePath; - - if(!GnomeUtils::getDeviceByIpIface(dbusConn, iface_name, ifaceDevicePath) && !ifaceDevicePath.empty()) + deviceProperties devProp; + if(!GnomeUtils::getDevicePropertiesByIfname(dbusConn, iface_name, devProp)) { NMLOG_ERROR("Interface unknow to NetworkManger Deamon"); return false; } - result = g_dbus_connection_call_sync( - dbusConn, - "org.freedesktop.NetworkManager", // D-Bus name - ifaceDevicePath.c_str(), // Object path - "org.freedesktop.DBus.Properties", // Interface for property access - "Get", // Method name for getting a property - g_variant_new("(ss)", // Input parameters (interface, property name) - "org.freedesktop.NetworkManager.Device", // Interface name - "State"), // Property name - G_VARIANT_TYPE("(v)"), // Expected return type (variant) - G_DBUS_CALL_FLAGS_NONE, - -1, // Default timeout - NULL, - &error - ); - if (error != NULL) { - NMLOG_ERROR("failed to DBus.Properties: %s", error->message); - g_error_free(error); - } else { - GVariant *variantValue; - g_variant_get(result, "(v)", &variantValue); - - state = static_cast(g_variant_get_uint32(variantValue)); - NMLOG_DEBUG("Device state: %u", state); - - g_variant_unref(variantValue); - g_variant_unref(result); - return true; - } - - return false; + state = devProp.state; + return true; } bool GnomeUtils::getDeviceStateReason(GDBusConnection *dbusConn, const gchar *iface_name, NMDeviceStateReason& StateReason) { - GError *error = NULL; - GVariant *resultReason; - std::string ifaceDevicePath; - - if(!GnomeUtils::getDeviceByIpIface(dbusConn, iface_name, ifaceDevicePath) && !ifaceDevicePath.empty()) + deviceProperties devProp; + if(!GnomeUtils::getDevicePropertiesByIfname(dbusConn, iface_name, devProp)) { NMLOG_ERROR("Interface unknow to NetworkManger Deamon"); return false; } - resultReason = g_dbus_connection_call_sync( dbusConn, - "org.freedesktop.NetworkManager", - ifaceDevicePath.c_str(), - "org.freedesktop.DBus.Properties", - "Get", - g_variant_new("(ss)", - "org.freedesktop.NetworkManager.Device", - "StateReason"), - G_VARIANT_TYPE("(v)"), - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - &error - ); - - if (error != NULL) { - NMLOG_ERROR("getting StateReason property: %s", error->message); - g_error_free(error); - } else if (resultReason != NULL) { - GVariant *variantReason; - g_variant_get(resultReason, "(v)", &variantReason); - - guint32 state_reason_code, state_reason_detail; - g_variant_get(variantReason, "(uu)", &state_reason_code, &state_reason_detail); - NMLOG_WARNING("Device state reason: %u (detail: %u)", state_reason_code, state_reason_detail); - g_variant_unref(variantReason); - g_variant_unref(resultReason); - return true; - } - return false; + StateReason = devProp.stateReason; + NMLOG_WARNING("Device state: %u (reason: %u)", devProp.state, devProp.stateReason); + return true; } } // Plugin diff --git a/GnomeProxy/NetworkManagerGnomeUtils.h b/GnomeProxy/NetworkManagerGnomeUtils.h index e0744c82..02db212d 100644 --- a/GnomeProxy/NetworkManagerGnomeUtils.h +++ b/GnomeProxy/NetworkManagerGnomeUtils.h @@ -39,18 +39,34 @@ struct apProperties uint8_t strength; }; +struct deviceProperties +{ + std::string interface; + std::string activeConnPath; + std::string path; + NMDeviceState state; + NMDeviceStateReason stateReason; + NMDeviceType deviceType; +}; + namespace WPEFramework { namespace Plugin { class GnomeUtils { public: + static std::string getCommaSeparatedSSIDs(const std::list& ssids); 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 *dbusConn, const char* apPath, apProperties& apDetails); static bool getConnectionPaths(GDBusConnection *dbusConn, std::list& pathsList); static bool getDeviceState(GDBusConnection *dbusConn, const gchar *iface_name, NMDeviceState& state); static bool getDeviceStateReason(GDBusConnection *dbusConn, const gchar *iface_name, NMDeviceStateReason& StateReason); + static bool getCachedPropertyU(GDBusProxy* proxy, const char* propertiy, uint32_t *value); + static bool getDevicePropertiesByPath(GDBusConnection *dbusConn, const char* devPath, deviceProperties& properties); + static bool getDevicePropertiesByIfname(GDBusConnection *dbusConn, const char* ifname, deviceProperties& properties); + static const char* getWifiIfname(); + static const char* getEthIfname(); }; } // Plugin diff --git a/NetworkManagerLogger.cpp b/NetworkManagerLogger.cpp index faeab4bf..80663cdc 100644 --- a/NetworkManagerLogger.cpp +++ b/NetworkManagerLogger.cpp @@ -34,7 +34,7 @@ #endif namespace NetworkManagerLogger { - static LogLevel gDefaultLogLevel = INFO_LEVEL; + static LogLevel gDefaultLogLevel = DEBUG_LEVEL; #ifdef USE_RDK_LOGGER diff --git a/Tests/raspberrypi/rpiTest.cmake b/Tests/raspberrypi/rpiTest.cmake index 2c867b00..163760b7 100644 --- a/Tests/raspberrypi/rpiTest.cmake +++ b/Tests/raspberrypi/rpiTest.cmake @@ -24,7 +24,7 @@ set_target_properties(${RPI_TEST} PROPERTIES ) # Add compiler options, such as forced include of a specific header -target_compile_options(${RPI_TEST} PRIVATE -include ${CMAKE_SOURCE_DIR}/INetworkManager.h) +target_compile_options(${RPI_TEST} PRIVATE -Wall -include ${CMAKE_SOURCE_DIR}/INetworkManager.h) target_include_directories(${RPI_TEST} PRIVATE ${GLIB_INCLUDE_DIRS} ${LIBNM_INCLUDE_DIRS} ${GIO_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}) target_include_directories(${RPI_TEST} PRIVATE GnomeProxy) diff --git a/Tests/raspberrypi/rpiUnitTest.cpp b/Tests/raspberrypi/rpiUnitTest.cpp index f8c3d4f8..ddd6a364 100644 --- a/Tests/raspberrypi/rpiUnitTest.cpp +++ b/Tests/raspberrypi/rpiUnitTest.cpp @@ -1,4 +1,5 @@ #include "NetworkManagerGnomeClient.h" +#include "NetworkManagerGnomeUtils.h" #include "../../NetworkManagerLogger.h" #include "INetworkManager.h" #include @@ -12,6 +13,7 @@ using namespace std; int main() { NetworkManagerClient* nmClient = NetworkManagerClient::getInstance(); + int i=1; while(i-- > 0) { @@ -20,25 +22,28 @@ int main() { if (ssids.empty()) { NMLOG_INFO("No SSID found"); } else { - NMLOG_INFO("SSID list available"); + // NMLOG_INFO("SSID list : %s", GnomeUtils::getCommaSeparatedSSIDs(ssids).c_str()); } - //std::this_thread::sleep_for(std::chrono::milliseconds(1)); - - //nmClient->getConnectedSSID(); - // nmClient->getAvailableSSIDs(ssids); - std::string ssid = "Mr13"; - std::string psk ="123454321"; - nmClient->startWifiScanning(); - - Exchange::INetworkManager::WiFiConnectTo ssidinfo = {.m_ssid = "Mi11", - .m_passphrase = "123454321", - .m_securityMode = WPEFramework::Exchange::INetworkManager::WIFI_SECURITY_WPA_PSK_AES, - .m_persistSSIDInfo = true - }; - nmClient->removeKnownSSIDs(ssidinfo.m_ssid); - nmClient->wifiConnect(ssidinfo); - sleep(50); - nmClient->wifiDisconnect(); + + Exchange::INetworkManager::WiFiSSIDInfo ssidinfo; + nmClient->getConnectedSSID(ssidinfo); + // //std::this_thread::sleep_for(std::chrono::milliseconds(1)); + + + // // nmClient->getAvailableSSIDs(ssids); + // std::string ssid = "Mr13"; + // std::string psk ="123454321"; + // nmClient->startWifiScanning(); + + // Exchange::INetworkManager::WiFiConnectTo ssidinfo = {.m_ssid = "Mi11", + // .m_passphrase = "123454321", + // .m_securityMode = WPEFramework::Exchange::INetworkManager::WIFI_SECURITY_WPA_PSK_AES, + // .m_persistSSIDInfo = true + // }; + // nmClient->removeKnownSSIDs(ssidinfo.m_ssid); + // nmClient->wifiConnect(ssidinfo); + sleep(50); + nmClient->wifiDisconnect(); } NMLOG_INFO("Program completed successfully"); return 0;