Skip to content

Commit

Permalink
new
Browse files Browse the repository at this point in the history
  • Loading branch information
parvathika authored and parvathinew committed Sep 3, 2024
1 parent 20a02ab commit 431f0c9
Showing 1 changed file with 25 additions and 76 deletions.
101 changes: 25 additions & 76 deletions NetworkManagerRDKProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#include "NetworkManagerConnectivity.h"
#include "WiFiSignalStrengthMonitor.h"
#include "libIBus.h"
#include <algorithm>
#include <string>

using namespace WPEFramework;
using namespace WPEFramework::Plugin;
Expand Down Expand Up @@ -365,11 +363,6 @@ namespace WPEFramework
const float signalStrengthThresholdFair = -67.0f;
NetworkManagerImplementation* _instance = nullptr;

Cache<Exchange::INetworkManager::WiFiState> WiFiStateCache;
Cache<Exchange::INetworkManager::IPAddressInfo> ipv4Cache;
Cache<Exchange::INetworkManager::IPAddressInfo> ipv6Cache;
Cache<std::string> activeIfaceCache;

Exchange::INetworkManager::WiFiState to_wifi_state(WiFiStatusCode_t code) {
switch (code)
{
Expand Down Expand Up @@ -406,8 +399,8 @@ namespace WPEFramework
return Exchange::INetworkManager::WIFI_STATE_INVALID_CREDENTIALS;
case WIFI_AUTH_FAILED:
return Exchange::INetworkManager::WIFI_STATE_AUTHENTICATION_FAILED;
case WIFI_NO_SSID:
return Exchange::INetworkManager::WIFI_STATE_SSID_NOT_FOUND;
case WIFI_NO_SSID:
return Exchange::INetworkManager::WIFI_STATE_SSID_NOT_FOUND;
case WIFI_UNKNOWN:
return Exchange::INetworkManager::WIFI_STATE_ERROR;
}
Expand Down Expand Up @@ -445,7 +438,6 @@ namespace WPEFramework
::_instance->ReportInterfaceStateChangedEvent(Exchange::INetworkManager::INTERFACE_ADDED, interface);
else
::_instance->ReportInterfaceStateChangedEvent(Exchange::INetworkManager::INTERFACE_REMOVED, interface);
activeIfaceCache.reset();
}
break;
}
Expand All @@ -459,7 +451,6 @@ namespace WPEFramework
::_instance->ReportInterfaceStateChangedEvent(Exchange::INetworkManager::INTERFACE_LINK_UP, interface);
else
::_instance->ReportInterfaceStateChangedEvent(Exchange::INetworkManager::INTERFACE_LINK_DOWN, interface);
activeIfaceCache.reset();
}
break;
}
Expand All @@ -471,10 +462,6 @@ namespace WPEFramework

if(interface == "eth0" || interface == "wlan0") {
::_instance->ReportIPAddressChangedEvent(interface, e->acquired, e->is_ipv6, string(e->ip_address));
if(e->is_ipv6)
ipv6Cache.reset();
else
ipv4Cache.reset();
}
break;
}
Expand All @@ -492,7 +479,6 @@ namespace WPEFramework
newInterface == ""; /* assigning "null" if the interface is not eth0 or wlan0 */

::_instance->ReportActiveInterfaceChangedEvent(oldInterface, newInterface);
activeIfaceCache.reset();
break;
}
case IARM_BUS_WIFI_MGR_EVENT_onAvailableSSIDs:
Expand Down Expand Up @@ -523,9 +509,7 @@ namespace WPEFramework
Exchange::INetworkManager::WiFiState state = Exchange::INetworkManager::WIFI_STATE_DISCONNECTED;
NMLOG_INFO("Event IARM_BUS_WIFI_MGR_EVENT_onWIFIStateChanged received; state=%d", e->data.wifiStateChange.state);
state = to_wifi_state(e->data.wifiStateChange.state);
WiFiStateCache = state;
::_instance->ReportWiFiStateChangedEvent(state);
activeIfaceCache.reset();
break;
}
case IARM_BUS_WIFI_MGR_EVENT_onError:
Expand All @@ -534,7 +518,6 @@ namespace WPEFramework
Exchange::INetworkManager::WiFiState state = errorcode_to_wifi_state(e->data.wifiError.code);
NMLOG_INFO("Event IARM_BUS_WIFI_MGR_EVENT_onError received; code=%d", e->data.wifiError.code);
::_instance->ReportWiFiStateChangedEvent(state);
WiFiStateCache = state;
break;
}
default:
Expand All @@ -555,6 +538,7 @@ namespace WPEFramework
}
void NetworkManagerImplementation::threadEventRegistration()
{
IARM_Result_t res = IARM_RESULT_SUCCESS;
IARM_Result_t retVal = IARM_RESULT_SUCCESS;
do
{
Expand Down Expand Up @@ -594,7 +578,6 @@ namespace WPEFramework
char c;

::_instance = this;
WiFiStateCache = Exchange::INetworkManager::WIFI_STATE_DISCONNECTED;

IARM_Result_t res = IARM_Bus_Init("netsrvmgr-thunder");
NMLOG_INFO("IARM_Bus_Init: %d", res);
Expand All @@ -616,7 +599,7 @@ namespace WPEFramework
usleep(500*1000);
retry++;
}
}while((retVal != IARM_RESULT_SUCCESS) && (retry < 3));
}while((retVal != IARM_RESULT_SUCCESS) && (retry < 10));

if(retVal != IARM_RESULT_SUCCESS)
{
Expand Down Expand Up @@ -681,20 +664,12 @@ namespace WPEFramework
uint32_t NetworkManagerImplementation::GetPrimaryInterface (string& interface /* @out */)
{
LOG_ENTRY_FUNCTION();
if(activeIfaceCache.isSet())
{
interface = activeIfaceCache.getValue();
NMLOG_INFO ("default interface cahched value = %s", interface.c_str());
return Core::ERROR_NONE;
}

uint32_t rc = Core::ERROR_RPC_CALL_FAILED;
IARM_BUS_NetSrvMgr_DefaultRoute_t defaultRoute = {0};
if (IARM_RESULT_SUCCESS == IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETSRVMGR_API_getDefaultInterface, (void*)&defaultRoute, sizeof(defaultRoute)))
{
NMLOG_INFO ("Call to %s for %s returned interface = %s, gateway = %s", IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETSRVMGR_API_getDefaultInterface, defaultRoute.interface, defaultRoute.gateway);
interface = m_defaultInterface = defaultRoute.interface;
activeIfaceCache = interface;
rc = Core::ERROR_NONE;
}
else
Expand Down Expand Up @@ -827,6 +802,7 @@ namespace WPEFramework
return prefix_len;
}


/* @brief Get IP Address Of the Interface */
uint32_t NetworkManagerImplementation::GetIPSettings(const string& interface /* @in */, const string& ipversion /* @in */, IPAddressInfo& result /* @out */)
{
Expand All @@ -835,62 +811,35 @@ namespace WPEFramework
IARM_BUS_NetSrvMgr_Iface_Settings_t iarmData = { 0 };
/* Netsrvmgr returns eth0 & wlan0 as primary interface but when we want to set., we must set ETHERNET or WIFI*/
//TODO: Fix netsrvmgr to accept eth0 & wlan0

// Convert the string to uppercase
std::string ipversionTmp = ipversion;
std::transform(ipversionTmp.begin(), ipversionTmp.end(), ipversionTmp.begin(), ::toupper);

if ("wlan0" == interface)
strncpy(iarmData.interface, "WIFI", INTERFACE_SIZE);
else if ("eth0" == interface)
strncpy(iarmData.interface, "ETHERNET", INTERFACE_SIZE);

strncpy(iarmData.ipversion, ipversionTmp.c_str(), 16);
strncpy(iarmData.ipversion, ipversion.c_str(), 16);
iarmData.isSupported = true;
if ("wlan0" == interface && WiFiStateCache.isSet() && WiFiStateCache.getValue() != Exchange::INetworkManager::WIFI_STATE_CONNECTED)
NMLOG_INFO("NetworkManagerImplementation::GetIPSettings - Before Calling IARM");
if (IARM_RESULT_SUCCESS == IARM_Bus_Call (IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETSRVMGR_API_getIPSettings, (void *)&iarmData, sizeof(iarmData)))
{
// TODO fix netsrvmgr will return ip even after wifi disconnected
NMLOG_WARNING("wifi not connected so address will be empty");
rc = Core::ERROR_NONE;
}
else if(ipversionTmp == "IPV4" && ipv4Cache.isSet() && interface == activeIfaceCache.getValue())
{
NMLOG_INFO("Reading ipv4 cached value");
result = ipv4Cache.getValue();
rc = Core::ERROR_NONE;
}
else if(ipversionTmp == "IPV6" && ipv6Cache.isSet() && interface == activeIfaceCache.getValue())
{
NMLOG_INFO("Reading ipv6 cached value");
result = ipv4Cache.getValue();
NMLOG_INFO("NetworkManagerImplementation::GetIPSettings - IARM Success.. Filling the data");
result.m_ipAddrType = string(iarmData.ipversion);
result.m_autoConfig = iarmData.autoconfig;
result.m_dhcpServer = string(iarmData.dhcpserver,MAX_IP_ADDRESS_LEN - 1);
result.m_v6LinkLocal = "";
result.m_ipAddress = string(iarmData.ipaddress,MAX_IP_ADDRESS_LEN - 1);
if (0 == strcasecmp("ipv4", iarmData.ipversion))
result.m_prefix = NetmaskToPrefix(iarmData.netmask);
else if (0 == strcasecmp("ipv6", iarmData.ipversion))
result.m_prefix = std::atoi(iarmData.netmask);
result.m_gateway = string(iarmData.gateway,MAX_IP_ADDRESS_LEN - 1);
result.m_primaryDns = string(iarmData.primarydns,MAX_IP_ADDRESS_LEN - 1);
result.m_secondaryDns = string(iarmData.secondarydns,MAX_IP_ADDRESS_LEN - 1);
NMLOG_INFO("NetworkManagerImplementation::GetIPSettings - IARM Success.. Filled the data");
rc = Core::ERROR_NONE;
}
else
{
if (IARM_RESULT_SUCCESS == IARM_Bus_Call (IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETSRVMGR_API_getIPSettings, (void *)&iarmData, sizeof(iarmData)))
{
NMLOG_INFO("GetIPSettings - IARM Success");
result.m_ipAddrType = string(iarmData.ipversion);
result.m_autoConfig = iarmData.autoconfig;
result.m_dhcpServer = string(iarmData.dhcpserver,MAX_IP_ADDRESS_LEN - 1);
result.m_v6LinkLocal = "";
result.m_ipAddress = string(iarmData.ipaddress,MAX_IP_ADDRESS_LEN - 1);
if (0 == strcasecmp("ipv4", iarmData.ipversion))
result.m_prefix = NetmaskToPrefix(iarmData.netmask);
else if (0 == strcasecmp("ipv6", iarmData.ipversion))
result.m_prefix = std::atoi(iarmData.netmask);
result.m_gateway = string(iarmData.gateway,MAX_IP_ADDRESS_LEN - 1);
result.m_primaryDns = string(iarmData.primarydns,MAX_IP_ADDRESS_LEN - 1);
result.m_secondaryDns = string(iarmData.secondarydns,MAX_IP_ADDRESS_LEN - 1);

if(ipversionTmp == "IPV4")
ipv4Cache = result;
else
ipv6Cache = result;
rc = Core::ERROR_NONE;
}
else
NMLOG_ERROR("GetIPSettings - Calling IARM Failed");
NMLOG_ERROR("NetworkManagerImplementation::GetIPSettings - Calling IARM Failed");
}

return rc;
Expand Down Expand Up @@ -1267,7 +1216,7 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = {
if (!signalStrength.empty())
{
signalStrengthOut = std::stof(signalStrength.c_str());
NMLOG_INFO ("WiFiSignalStrength in dB = %f",signalStrengthOut);
NMLOG_INFO ("WiFiSignalStrength in dB = %s",signalStrengthOut);
}

if (signalStrengthOut == 0)
Expand Down Expand Up @@ -1362,13 +1311,13 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = {
{
LOG_ENTRY_FUNCTION();
uint32_t rc = Core::ERROR_RPC_CALL_FAILED;
IARM_Result_t retVal = IARM_RESULT_SUCCESS;
IARM_Bus_WiFiSrvMgr_Param_t param;
memset(&param, 0, sizeof(param));

if(IARM_RESULT_SUCCESS == IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_getCurrentState, (void *)&param, sizeof(param)))
{
state = to_wifi_state(param.data.wifiStatus);
WiFiStateCache = state;
rc = Core::ERROR_NONE;
}
return rc;
Expand Down

0 comments on commit 431f0c9

Please sign in to comment.