Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 27 additions & 14 deletions plugin/NetworkManagerImplementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,14 +597,16 @@ namespace WPEFramework
return;
}

void NetworkManagerImplementation::filterScanResults(JsonArray &ssids)
void NetworkManagerImplementation::filterScanResults(JsonArray &ssids,
const std::vector<std::string>& filterSsidslist,
const std::vector<std::string>& filterFrequencies)
{
JsonArray result;
double filterFreq = 0.0;
std::unordered_set<std::string> scanForSsidsSet(m_filterSsidslist.begin(), m_filterSsidslist.end());
std::unordered_set<std::string> scanForSsidsSet(filterSsidslist.begin(), filterSsidslist.end());

// If neither SSID list nor frequency is provided, exit
if (m_filterSsidslist.empty() && m_filterFrequencies.empty())
if (filterSsidslist.empty() && filterFrequencies.empty())
{
NMLOG_DEBUG("Neither SSID nor Frequency is provided. Exiting function.");
return;
Expand All @@ -618,10 +620,10 @@ namespace WPEFramework

double frequencyValue = std::stod(frequency);
bool ssidMatches = scanForSsidsSet.empty() || scanForSsidsSet.find(ssid) != scanForSsidsSet.end();
bool freqMatches = m_filterFrequencies.empty();
bool freqMatches = filterFrequencies.empty();
if (!freqMatches)
{
for (const auto& selectedFrequency : m_filterFrequencies)
for (const auto& selectedFrequency : filterFrequencies)
{
if (selectedFrequency == "ALL")
{
Comment on lines +623 to 629
Expand Down Expand Up @@ -738,7 +740,6 @@ namespace WPEFramework

void NetworkManagerImplementation::ReportActiveInterfaceChange(const string prevActiveInterface, const string currentActiveinterface)
{
_notificationLock.Lock();
NMLOG_INFO("Posting onActiveInterfaceChange %s", currentActiveinterface.c_str());

if(currentActiveinterface == "eth0")
Expand All @@ -754,15 +755,15 @@ namespace WPEFramework

// FIXME : This could be the place to define `m_defaultInterface` to incoming `currentActiveinterface`.
// m_defaultInterface = currentActiveinterface;

_notificationLock.Lock();
for (const auto callback : _notificationCallbacks) {
callback->onActiveInterfaceChange(prevActiveInterface, currentActiveinterface);
}
_notificationLock.Unlock();
#if USE_TELEMETRY
NMLOG_INFO("NM_INTERFACE_STATUS = Interface changed to %s", currentActiveinterface.c_str());
logTelemetry("NM_INTERFACE_STATUS", "Interface changed to " + currentActiveinterface);
#endif
_notificationLock.Unlock();
#endif
}

void NetworkManagerImplementation::ReportIPAddressChange(const string interface, const string ipversion, const string ipaddress, const Exchange::INetworkManager::IPStatus status)
Expand Down Expand Up @@ -810,7 +811,6 @@ namespace WPEFramework

void NetworkManagerImplementation::ReportInternetStatusChange(const Exchange::INetworkManager::InternetStatus prevState, const Exchange::INetworkManager::InternetStatus currState, const string interface)
{
_notificationLock.Lock();
NMLOG_INFO("Posting onInternetStatusChange with current state as %u", (unsigned)currState);
#if USE_TELEMETRY
// Log error only when ethernet is up and there's no internet
Expand All @@ -823,15 +823,16 @@ namespace WPEFramework
logTelemetry("NM_ETHERNET_CONNECTIVITY", "Ethernet connectivity failed");
}
#endif
_notificationLock.Lock();
for (const auto callback : _notificationCallbacks) {
callback->onInternetStatusChange(prevState, currState, interface);
}
_notificationLock.Unlock();
#if USE_TELEMETRY
string stateStr = Core::EnumerateType<Exchange::INetworkManager::InternetStatus>(currState).Data();
NMLOG_INFO("NM_INTERNET_STATUS = %s", stateStr.c_str());
logTelemetry("NM_INTERNET_STATUS", stateStr);
#endif
_notificationLock.Unlock();
}

int32_t NetworkManagerImplementation::logSSIDs(Logging level, const JsonArray &ssids)
Expand All @@ -855,7 +856,6 @@ namespace WPEFramework

void NetworkManagerImplementation::ReportAvailableSSIDs(const JsonArray &arrayofWiFiScanResults)
{
_notificationLock.Lock();
string jsonOfWiFiScanResults;
string jsonOfFilterScanResults;
JsonArray filterResult = arrayofWiFiScanResults;
Expand All @@ -864,12 +864,25 @@ namespace WPEFramework
NMLOG_DEBUG("Discovered %d SSIDs before filtering as,", filterResult.Length());
logSSIDs(LOG_LEVEL_DEBUG, filterResult);

filterScanResults(filterResult);
// Snapshot filter vectors under lock, then release before calling filterScanResults
// to ensure exception-safety (std::stod can throw).
std::vector<std::string> ssidsSnapshot;
std::vector<std::string> frequenciesSnapshot;
{
_filterVectorsLock.Lock();
ssidsSnapshot = m_filterSsidslist;
frequenciesSnapshot = m_filterFrequencies;
_filterVectorsLock.Unlock();
}

// Call filterScanResults outside the lock with snapshots (exception-safe)
filterScanResults(filterResult, ssidsSnapshot, frequenciesSnapshot);
filterResult.ToString(jsonOfFilterScanResults);

NMLOG_INFO("Posting onAvailableSSIDs event with %d SSIDs as,", filterResult.Length());
logSSIDs(LOG_LEVEL_INFO, filterResult);

_notificationLock.Lock();
for (const auto callback : _notificationCallbacks) {
callback->onAvailableSSIDs(jsonOfFilterScanResults);
}
Expand Down Expand Up @@ -1177,13 +1190,13 @@ namespace WPEFramework
m_wlanConnected.store(false); /* Any other state is considered as WiFi not connected. */
}

_notificationLock.Lock();
NMLOG_INFO("Posting onWiFiStateChange (%d)", state);
#if USE_TELEMETRY
string stateStr = Core::EnumerateType<Exchange::INetworkManager::WiFiState>(state).Data();
NMLOG_INFO("NM_WIFI_STATUS = %s", stateStr.c_str());
logTelemetry("NM_WIFI_STATUS", stateStr);
#endif
_notificationLock.Lock();
for (const auto callback : _notificationCallbacks) {
callback->onWiFiStateChange(state);
}
Expand Down
3 changes: 2 additions & 1 deletion plugin/NetworkManagerImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ namespace WPEFramework
void getInitialConnectionState(void);
void executeExternally(NetworkEvents event, const string commandToExecute, string& response);
void threadEventRegistration(bool iarmInit, bool iarmConnect);
void filterScanResults(JsonArray &ssids);
void filterScanResults(JsonArray &ssids, const std::vector<std::string>& filterSsidslist, const std::vector<std::string>& filterFrequencies);
void startWiFiSignalQualityMonitor(int interval);
void stopWiFiSignalQualityMonitor();
void monitorThreadFunction(int interval);
Expand All @@ -348,6 +348,7 @@ namespace WPEFramework
private:
std::list<Exchange::INetworkManager::INotification *> _notificationCallbacks;
Core::CriticalSection _notificationLock;
Core::CriticalSection _filterVectorsLock;
string m_publicIP;
stun::client stunClient;
string m_stunEndpoint;
Expand Down
2 changes: 1 addition & 1 deletion plugin/NetworkManagerLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void logPrint(LogLevel level, const char* file, const char* func, int line, cons
#define NMLOG_ERROR(FMT, ...) logPrint(NetworkManagerLogger::ERROR_LEVEL, __FILE__, __func__, __LINE__, FMT, ##__VA_ARGS__)
#define NMLOG_FATAL(FMT, ...) logPrint(NetworkManagerLogger::FATAL_LEVEL, __FILE__,__func__, __LINE__, FMT, ##__VA_ARGS__)

#define LOG_ENTRY_FUNCTION() { NMLOG_DEBUG("Entering"); }
#define LOG_ENTRY_FUNCTION() { NMLOG_INFO("Entering"); }

} // namespace NetworkManagerLogger

Expand Down
8 changes: 7 additions & 1 deletion plugin/gnome/NetworkManagerGnomeProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,9 @@ namespace WPEFramework
{
uint32_t rc = Core::ERROR_RPC_CALL_FAILED;

std::vector<std::string> ssidsSnapshot;

_filterVectorsLock.Lock();
//Cleared the Existing Store filterred SSID list
m_filterSsidslist.clear();
m_filterFrequencies.clear();
Expand Down Expand Up @@ -801,6 +804,7 @@ namespace WPEFramework
else
{
NMLOG_ERROR("Invalid frequency value: %s", frequency.c_str());
_filterVectorsLock.Unlock();
return Core::ERROR_BAD_REQUEST;
}
}
Expand All @@ -810,9 +814,11 @@ namespace WPEFramework
}
}
}
ssidsSnapshot = m_filterSsidslist;
_filterVectorsLock.Unlock();

nmEvent->setwifiScanOptions(true);
if(wifi->wifiScanRequest(m_filterSsidslist))
if(wifi->wifiScanRequest(ssidsSnapshot))
rc = Core::ERROR_NONE;
return rc;
}
Expand Down
2 changes: 2 additions & 0 deletions plugin/rdk/NetworkManagerRDKProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = {
IARM_Result_t retVal = IARM_RESULT_SUCCESS;

//Cleared the Existing Store filterred SSID list
_filterVectorsLock.Lock();
m_filterSsidslist.clear();
m_filterFrequencies.clear();
if(ssids)
Expand All @@ -994,6 +995,7 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = {
NMLOG_DEBUG("%s added to Frequency filtering", frequencyList.c_str());
}
}
_filterVectorsLock.Unlock();

memset(&param, 0, sizeof(param));

Expand Down
Loading