diff --git a/LegacyPlugin_NetworkAPIs.cpp b/LegacyPlugin_NetworkAPIs.cpp index 64a6c04f..1919c3b1 100644 --- a/LegacyPlugin_NetworkAPIs.cpp +++ b/LegacyPlugin_NetworkAPIs.cpp @@ -1014,10 +1014,10 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = { { JsonObject legacyParams; - legacyParams["oldInterfaceName"] = getInterfaceNameToType(parameters["oldInterfaceName"].String()); - legacyParams["newInterfaceName"] = getInterfaceNameToType(parameters["newInterfaceName"].String()); + legacyParams["oldInterfaceName"] = getInterfaceNameToType(parameters["prevActiveInterface"].String()); + legacyParams["newInterfaceName"] = getInterfaceNameToType(parameters["currentActiveInterface"].String()); - m_defaultInterface = parameters["newInterfaceName"].String(); + m_defaultInterface = parameters["currentActiveInterface"].String(); string json; legacyParams.ToString(json); @@ -1032,7 +1032,7 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = { JsonObject legacyParams; legacyParams["interface"] = getInterfaceNameToType(parameters["interface"].String()); - if (parameters["isIPv6"].Boolean()) + if (parameters["ipversion"].String() == "IPv6") { legacyParams["ip6Address"] = parameters["ipaddress"]; } @@ -1049,8 +1049,8 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = { Notify("onIPAddressStatusChanged", legacyParams); - if ("ACQUIRED" == parameters["status"].String()) - m_defaultInterface = parameters["interface"].String(); + // if ("ACQUIRED" == parameters["status"].String()) + // m_defaultInterface = parameters["interface"].String(); return; } diff --git a/LegacyPlugin_WiFiManagerAPIs.cpp b/LegacyPlugin_WiFiManagerAPIs.cpp index ba0c6427..5dada6b2 100644 --- a/LegacyPlugin_WiFiManagerAPIs.cpp +++ b/LegacyPlugin_WiFiManagerAPIs.cpp @@ -697,7 +697,7 @@ namespace WPEFramework } } else - NMLOG_WARNING("Ignoring %s\n", __FUNCTION__); + NMLOG_WARNING("Ignoring %s", __FUNCTION__); return; } @@ -710,7 +710,7 @@ namespace WPEFramework if(_gWiFiInstance) _gWiFiInstance->Notify("onAvailableSSIDs", parameters); else - NMLOG_WARNING("Ignoring %s\n", __FUNCTION__); + NMLOG_WARNING("Ignoring %s", __FUNCTION__); return; } @@ -718,8 +718,8 @@ namespace WPEFramework void WiFiManager::onWiFiSignalStrengthChange(const JsonObject& parameters) { JsonObject legacyParams; - legacyParams["signalStrength"] = parameters["signalQuality"]; - legacyParams["strength"] = parameters["signalLevel"]; + legacyParams["signalStrength"] = parameters["strength"]; + legacyParams["strength"] = parameters["quality"]; string json; legacyParams.ToString(json); @@ -727,7 +727,7 @@ namespace WPEFramework if (_gWiFiInstance) _gWiFiInstance->Notify("onWifiSignalThresholdChanged", legacyParams); else - NMLOG_WARNING("Ignoring %s\n", __FUNCTION__); + NMLOG_WARNING("Ignoring %s", __FUNCTION__); return; } diff --git a/NetworkManagerGnomeEvents.cpp b/NetworkManagerGnomeEvents.cpp index 0e0321fd..2f0af5a3 100644 --- a/NetworkManagerGnomeEvents.cpp +++ b/NetworkManagerGnomeEvents.cpp @@ -72,10 +72,12 @@ namespace WPEFramework static void deviceStateChangeCb(NMDevice *device, GParamSpec *pspec, NMEvents *nmEvents) { + static bool isEthDisabled = false; + static bool isWlanDisabled = false; NMDeviceState deviceState; deviceState = nm_device_get_state(device); std::string ifname = nm_device_get_iface(device); - if(ifname == nmEvents->ifnameWlan0) + if(ifname == nmUtils::wlanIface()) { if(!NM_IS_DEVICE_WIFI(device)) { NMLOG_FATAL("not a wifi device !"); @@ -118,19 +120,24 @@ namespace WPEFramework case NM_DEVICE_STATE_UNKNOWN: wifiState = "WIFI_STATE_UNINSTALLED"; GnomeNetworkManagerEvents::onWIFIStateChanged(Exchange::INetworkManager::WIFI_STATE_UNINSTALLED); + GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_REMOVED, nmUtils::wlanIface()); break; case NM_DEVICE_STATE_UNMANAGED: wifiState = "WIFI_STATE_DISABLED"; GnomeNetworkManagerEvents::onWIFIStateChanged(Exchange::INetworkManager::WIFI_STATE_DISABLED); + GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_REMOVED, nmUtils::wlanIface()); + isEthDisabled = true; break; case NM_DEVICE_STATE_UNAVAILABLE: case NM_DEVICE_STATE_DISCONNECTED: wifiState = "WIFI_STATE_DISCONNECTED"; GnomeNetworkManagerEvents::onWIFIStateChanged(Exchange::INetworkManager::WIFI_STATE_DISCONNECTED); + GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_LINK_DOWN, nmUtils::wlanIface()); break; case NM_DEVICE_STATE_PREPARE: wifiState = "WIFI_STATE_PAIRING"; GnomeNetworkManagerEvents::onWIFIStateChanged(Exchange::INetworkManager::WIFI_STATE_PAIRING); + GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_LINK_UP, nmUtils::wlanIface()); break; case NM_DEVICE_STATE_CONFIG: wifiState = "WIFI_STATE_CONNECTING"; @@ -159,18 +166,27 @@ namespace WPEFramework wifiState = "Un handiled: " ; wifiState += std::to_string(deviceState); } + + if(isWlanDisabled & deviceState > NM_DEVICE_STATE_UNMANAGED) + { + isWlanDisabled = false; + GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_ADDED, nmUtils::wlanIface()); + } + + break; } } NMLOG_DEBUG("wifi state: %s", wifiState.c_str()); } - else if(ifname == nmEvents->ifnameEth0) + else if(ifname == nmUtils::ethIface()) { switch (deviceState) { case NM_DEVICE_STATE_UNKNOWN: case NM_DEVICE_STATE_UNMANAGED: - GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_DISABLED, nmUtils::ethIface()); - break; + GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_REMOVED, nmUtils::ethIface()); + isEthDisabled = true; + break; case NM_DEVICE_STATE_UNAVAILABLE: case NM_DEVICE_STATE_DISCONNECTED: GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_LINK_DOWN, nmUtils::ethIface()); @@ -187,10 +203,15 @@ namespace WPEFramework default: NMLOG_WARNING("Unhandiled state change %d", deviceState); } + + if(isEthDisabled & deviceState > NM_DEVICE_STATE_UNMANAGED) + { + isEthDisabled = false; + GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_ADDED, nmUtils::ethIface()); + } } NMLOG_DEBUG("%s state: (%d)", ifname.c_str(), deviceState); - } static void ip4ChangedCb(NMIPConfig *ipConfig, GParamSpec *pspec, gpointer userData) @@ -282,15 +303,15 @@ namespace WPEFramework if( ((device != NULL) && NM_IS_DEVICE(device)) ) { std::string ifname = nm_device_get_iface(device); - if(ifname == nmEvents->ifnameWlan0) { + if(ifname == nmUtils::wlanIface()) { GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_ADDED, nmUtils::wlanIface()); } - else if(ifname == nmEvents->ifnameEth0) { + else if(ifname == nmUtils::ethIface()) { GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_ADDED, nmUtils::ethIface()); } /* ip events added only for eth0 and wlan0 */ - if((ifname == nmEvents->ifnameEth0) || (ifname == nmEvents->ifnameWlan0)) + if(ifname == nmUtils::ethIface() || ifname == nmUtils::wlanIface()) { g_signal_connect(device, "notify::" NM_DEVICE_STATE, G_CALLBACK(deviceStateChangeCb), nmEvents); // TODO call notify::" NM_DEVICE_ACTIVE_CONNECTION if needed @@ -314,11 +335,11 @@ namespace WPEFramework if( ((device != NULL) && NM_IS_DEVICE(device)) ) { std::string ifname = nm_device_get_iface(device); - if(ifname == nmEvents->ifnameWlan0) { + if(ifname == nmUtils::wlanIface()) { GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_REMOVED, nmUtils::wlanIface()); g_signal_handlers_disconnect_by_func(device, (gpointer)deviceStateChangeCb, nmEvents); } - else if(ifname == nmEvents->ifnameEth0) { + else if(ifname == nmUtils::ethIface()) { GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_REMOVED, nmUtils::ethIface()); g_signal_handlers_disconnect_by_func(device, (gpointer)deviceStateChangeCb, nmEvents); } @@ -383,11 +404,11 @@ namespace WPEFramework NMDevice *device = NM_DEVICE(g_ptr_array_index(devices, count)); if( ((device != NULL) && NM_IS_DEVICE(device)) ) { - g_signal_connect(device, "notify::" NM_DEVICE_STATE, G_CALLBACK(deviceStateChangeCb), nmEvents); - //g_signal_connect(device, "notify::" NM_DEVICE_ACTIVE_CONNECTION, G_CALLBACK(deviceActiveConnChangeCb), NULL); std::string ifname = nm_device_get_iface(device); - if((ifname == nmEvents->ifnameEth0) || (ifname == nmEvents->ifnameWlan0)) /* ip events added only for eth0 and wlan0 */ + if((ifname == nmUtils::ethIface()) || (ifname == nmUtils::wlanIface())) { + deviceStateChangeCb(device, nullptr, nullptr); //posting event if interface already connected + g_signal_connect(device, "notify::" NM_DEVICE_STATE, G_CALLBACK(deviceStateChangeCb), nmEvents); NMIPConfig *ipv4Config = nm_device_get_ip4_config(device); NMIPConfig *ipv6Config = nm_device_get_ip6_config(device); if (ipv4Config) { @@ -485,8 +506,6 @@ namespace WPEFramework return; } _nmEventInstance = this; - nmEvents.ifnameEth0 = nmUtils::ethIface(); - nmEvents.ifnameWlan0 = nmUtils::wlanIface(); } /* Gnome networkmanger new events */ @@ -506,7 +525,7 @@ namespace WPEFramework void GnomeNetworkManagerEvents::onInterfaceStateChangeCb(uint8_t newState, std::string iface) { - std::string state = ""; + std::string state {}; switch (newState) { case Exchange::INetworkManager::INTERFACE_ADDED: @@ -530,8 +549,9 @@ namespace WPEFramework default: state = "Unknown"; } + NMLOG_DEBUG("%s interface state changed - %s", iface.c_str(), state.c_str()); - if(_instance != nullptr && (iface == _nmEventInstance->nmEvents.ifnameWlan0 || iface == _nmEventInstance->nmEvents.ifnameEth0)) + if(_instance != nullptr && (iface == nmUtils::wlanIface() || iface == nmUtils::ethIface())) _instance->ReportInterfaceStateChange(static_cast(newState), iface); } diff --git a/WiFiSignalStrengthMonitor.cpp b/WiFiSignalStrengthMonitor.cpp index 27243b3b..32aaa4c9 100644 --- a/WiFiSignalStrengthMonitor.cpp +++ b/WiFiSignalStrengthMonitor.cpp @@ -54,8 +54,8 @@ namespace WPEFramework ssid = retrieveValues(ssid_command, "ssid", buff, sizeof (buff)); if (ssid.empty()) { - NMLOG_ERROR("ssid is empty"); quality = Exchange::INetworkManager::WIFI_SIGNAL_DISCONNECTED; + strengthOut = "0.00"; return; } @@ -71,6 +71,7 @@ namespace WPEFramework if (signalStrengthOut == 0.0f) { quality = Exchange::INetworkManager::WIFI_SIGNAL_DISCONNECTED; + strengthOut = "0.00"; } else if (signalStrengthOut >= signalStrengthThresholdExcellent && signalStrengthOut < 0) { @@ -100,14 +101,12 @@ namespace WPEFramework isRunning = true; monitorThread = std::thread(&WiFiSignalStrengthMonitor::monitorThreadFunction, this, interval); monitorThread.detach(); - std::thread::id threadId = monitorThread.get_id(); - NMLOG_INFO("Thread started with interval: %d seconds", interval); } void WiFiSignalStrengthMonitor::monitorThreadFunction(int interval) { static Exchange::INetworkManager::WiFiSignalQuality oldSignalQuality = Exchange::INetworkManager::WIFI_SIGNAL_DISCONNECTED; - NMLOG_INFO("WiFiSignalStrengthMonitor thread started !"); + NMLOG_INFO("WiFiSignalStrengthMonitor thread started ! (%d)", interval); while (!stopThread) { string ssid = "";