diff --git a/LegacyPlugin_NetworkAPIs.cpp b/LegacyPlugin_NetworkAPIs.cpp index 6a86dc49..64a6c04f 100644 --- a/LegacyPlugin_NetworkAPIs.cpp +++ b/LegacyPlugin_NetworkAPIs.cpp @@ -1034,11 +1034,11 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = { if (parameters["isIPv6"].Boolean()) { - legacyParams["ip6Address"] = parameters["ipAddress"]; + legacyParams["ip6Address"] = parameters["ipaddress"]; } else { - legacyParams["ip4Address"] = parameters["ipAddress"]; + legacyParams["ip4Address"] = parameters["ipaddress"]; } legacyParams["status"] = parameters["status"]; diff --git a/NetworkManagerGnomeProxy.cpp b/NetworkManagerGnomeProxy.cpp index 6b1fbd31..bb32fc81 100644 --- a/NetworkManagerGnomeProxy.cpp +++ b/NetworkManagerGnomeProxy.cpp @@ -687,13 +687,21 @@ namespace WPEFramework uint32_t NetworkManagerImplementation::StartWPS(const WiFiWPS& method /* @in */, const string& wps_pin /* @in */) { - uint32_t rc = Core::ERROR_RPC_CALL_FAILED; + uint32_t rc = Core::ERROR_NONE; + if(wifi->initiateWPS()) + NMLOG_INFO ("startWPS success"); + else + rc = Core::ERROR_RPC_CALL_FAILED; return rc; } uint32_t NetworkManagerImplementation::StopWPS(void) { - uint32_t rc = Core::ERROR_RPC_CALL_FAILED; + uint32_t rc = Core::ERROR_NONE; + if(wifi->cancelWPS()) + NMLOG_INFO ("cancelWPS success"); + else + rc = Core::ERROR_RPC_CALL_FAILED; return rc; } diff --git a/NetworkManagerGnomeWIFI.cpp b/NetworkManagerGnomeWIFI.cpp index 12d8e49a..b2ae798b 100644 --- a/NetworkManagerGnomeWIFI.cpp +++ b/NetworkManagerGnomeWIFI.cpp @@ -29,8 +29,23 @@ #include "NetworkManagerGnomeWIFI.h" #include "NetworkManagerGnomeUtils.h" +using namespace std; namespace WPEFramework { + class Job : public Core::IDispatch { + public: + Job(function work) + : _work(work) + { + } + void Dispatch() override + { + _work(); + } + + private: + function _work; + }; namespace Plugin { @@ -508,7 +523,7 @@ namespace WPEFramework apRsnFlags = nm_access_point_get_rsn_flags(AccessPoint); // check ap flag ty securti we supporting - if(apFlags != NM_802_11_AP_FLAGS_NONE && strlen(password_in) < 1 ) + if(apFlags != NM_802_11_AP_FLAGS_NONE && strlen(password_in) < 1 && !(apFlags & NM_802_11_AP_FLAGS_WPS)) { NMLOG_ERROR("This ap(%s) security need password please add password!", ssid_in); return false; @@ -902,9 +917,57 @@ namespace WPEFramework return true; } NMLOG_DEBUG("Last Wi-Fi scan exceeded time limit."); - return false; - } + return false; + } + + bool wifiManager::initiateWPS() + { + Core::IWorkerPool::Instance().Submit(Core::ProxyType(Core::ProxyType::Create([&]() { + const GPtrArray *aps; + int count = 1, wpsConnected = 0; + if(!createClientNewConnection()) + return; + sleep(10); /* As we will get the ap info with NM_802_11_AP_FLAGS_WPS_PBC set after pressing the PBC button. + So we are waiting for 10 seconds here*/ + do{ + if(wifiScanRequest("")) + { + aps = nm_device_wifi_get_access_points(NM_DEVICE_WIFI(getNmDevice())); + for (guint i = 0; i < aps->len; i++) { + NMAccessPoint *ap = static_cast(g_ptr_array_index(aps, i)); + + guint32 flags = nm_access_point_get_flags(ap); + + NMLOG_INFO("AP Flags: 0x%x\n", flags); + + if (flags & NM_802_11_AP_FLAGS_WPS_PBC) { + Exchange::INetworkManager::WiFiConnectTo wifiData; + GBytes *ssid; + ssid = nm_access_point_get_ssid(ap); + gsize size; + const guint8 *ssidData = static_cast(g_bytes_get_data(ssid, &size)); + std::string ssidTmp(reinterpret_cast(ssidData), size); + wifiData.ssid = ssidTmp.c_str(); + NMLOG_INFO("connected ssid: %s", ssidTmp.c_str()); + if(wifiConnect(wifiData)) + wpsConnected = 1; + break; + } + } + } + sleep(3); /* Waiting time between successive scan */ + count++; + }while(count <= 3 && !wpsConnected); + NMLOG_INFO("Completed scanning and wpsconnect status = %d", wpsConnected); + }))); + return true; + } + + bool wifiManager::cancelWPS() + { + return true; + } } // namespace Plugin } // namespace WPEFramework diff --git a/NetworkManagerGnomeWIFI.h b/NetworkManagerGnomeWIFI.h index 8762f409..9ad556b8 100644 --- a/NetworkManagerGnomeWIFI.h +++ b/NetworkManagerGnomeWIFI.h @@ -53,6 +53,8 @@ namespace WPEFramework bool removeKnownSSID(const string& ssid); bool quit(NMDevice *wifiNMDevice); bool wait(GMainLoop *loop, int timeOutMs = 10000); // default maximium set as 10 sec + bool initiateWPS(); + bool cancelWPS(); private: NMDevice *getNmDevice(); diff --git a/NetworkManagerJsonRpc.cpp b/NetworkManagerJsonRpc.cpp index 1963a70a..9b0a8ed3 100644 --- a/NetworkManagerJsonRpc.cpp +++ b/NetworkManagerJsonRpc.cpp @@ -290,8 +290,14 @@ namespace WPEFramework uint32_t rc = Core::ERROR_GENERAL; Exchange::INetworkManager::IPAddress address{}; - string interface = parameters["interface"].String(); - string ipversion = parameters["ipversion"].String(); + string interface{}; + string ipversion{}; + + if (parameters.HasLabel("interface")) + interface = parameters["interface"].String(); + + if (parameters.HasLabel("ipversion")) + ipversion = parameters["ipversion"].String(); if (_networkManager) rc = _networkManager->GetIPSettings(interface, ipversion, address);