Skip to content

Commit

Permalink
DELIA-66222,DELIA-66509: onAvailableSSIDs event not functioning corre…
Browse files Browse the repository at this point in the history
…ctly in the WiFi plugin (rdkcentral#44)

* DELIA-66222,DELIA-66509: onAvailableSSIDs event not functioning correctly in the WiFi plugin

Reason for change: Added the SsidList & frequency filter logic during WifiStartScan
Test Procedure: Verify in custom build
Risks: None
Signed-off-by: Thamim Razith [email protected]
Co-authored-by: Karunakaran A <[email protected]>
  • Loading branch information
tabbas651 authored Dec 5, 2024
1 parent 9233775 commit bf871b9
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 20 deletions.
25 changes: 23 additions & 2 deletions LegacyPlugin_WiFiManagerAPIs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,13 +544,31 @@ namespace WPEFramework
returnJson(rc);
}

uint32_t WiFiManager::startScan(const JsonObject& parameters, JsonObject& response)
uint32_t WiFiManager::startScan(const JsonObject& parameters, JsonObject& response)
{
LOG_INPARAM();
uint32_t rc = Core::ERROR_GENERAL;
string frequency = parameters["frequency"].String();
string frequency{};
Exchange::INetworkManager::IStringIterator* ssids = NULL;


if (parameters.HasLabel("frequency"))
frequency = parameters["frequency"].String();

if (parameters.HasLabel("ssid"))
{
string inputSSID = parameters["ssid"].String();
string ssid{};
vector<string> inputSSIDlist;
stringstream ssidStream(inputSSID);
while (getline(ssidStream, ssid, '|'))
{
inputSSIDlist.push_back(ssid);
}

ssids = (Core::Service<RPC::StringIterator>::Create<RPC::IStringIterator>(inputSSIDlist));
}

auto _nwmgr = m_service->QueryInterfaceByCallsign<Exchange::INetworkManager>(NETWORK_MANAGER_CALLSIGN);
if (_nwmgr)
{
Expand All @@ -560,6 +578,9 @@ namespace WPEFramework
else
rc = Core::ERROR_UNAVAILABLE;

if (ssids)
ssids->Release();

returnJson(rc);
}

Expand Down
5 changes: 1 addition & 4 deletions NetworkManagerGnomeEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,6 @@ namespace WPEFramework
return;
}
JsonArray ssidList = JsonArray();
string ssidListJson;
NMAccessPoint *ap = nullptr;
const GPtrArray *accessPoints = nm_device_wifi_get_access_points(wifiDevice);
for (guint i = 0; i < accessPoints->len; i++)
Expand All @@ -628,13 +627,11 @@ namespace WPEFramework
ssidList.Add(ssidObj);
}

ssidList.ToString(ssidListJson);
NMLOG_INFO("No of AP Available = %d", static_cast<int>(accessPoints->len));
//NMLOG_DEBUG("Scanned APIs are = %s",ssidListJson.c_str());

if(_nmEventInstance->doScanNotify) {
_nmEventInstance->doScanNotify = false;
_instance->ReportAvailableSSIDs(ssidListJson);
_instance->ReportAvailableSSIDs(ssidList);
}
}

Expand Down
23 changes: 21 additions & 2 deletions NetworkManagerGnomeProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,10 +528,29 @@ namespace WPEFramework
uint32_t NetworkManagerImplementation::StartWiFiScan(const string& frequency /* @in */, IStringIterator* const ssids/* @in */)
{
uint32_t rc = Core::ERROR_RPC_CALL_FAILED;
(void) ssids;

//Cleared the Existing Store filterred SSID list
m_filterSsidslist.clear();
m_filterfrequency.clear();

if(ssids)
{
string tmpssidlist{};
while (ssids->Next(tmpssidlist) == true)
{
m_filterSsidslist.push_back(tmpssidlist.c_str());
NMLOG_DEBUG("%s added to SSID filtering", tmpssidlist.c_str());
}
}

if (!frequency.empty())
{
m_filterfrequency = frequency;
NMLOG_DEBUG("Scan SSIDs of frequency %s", m_filterfrequency.c_str());
}

nmEvent->setwifiScanOptions(true);
if(wifi->wifiScanRequest(frequency))
if(wifi->wifiScanRequest(m_filterfrequency))
rc = Core::ERROR_NONE;
return rc;
}
Expand Down
66 changes: 63 additions & 3 deletions NetworkManagerImplementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,56 @@ namespace WPEFramework
return;
}


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

// If neither SSID list nor frequency is provided, exit
if (m_filterSsidslist.empty() && m_filterfrequency.empty())
{
NMLOG_DEBUG("Neither SSID nor Frequency is provided. Exiting function.");
return;
}

if (!m_filterfrequency.empty())
{
filterFreq = std::stod(m_filterfrequency);
NMLOG_DEBUG("Frequency provided: %lf\n", filterFreq);
}

for (int i = 0; i < ssids.Length(); i++)
{
JsonObject object = ssids[i].Object();
string ssid = object["ssid"].String();
string frequency = object["frequency"].String();

NMLOG_DEBUG("Processing SSID: %s, Frequency: %s\n", ssid.c_str(), frequency.c_str());

double frequencyValue = std::stod(frequency);

//Debug to print log
NMLOG_DEBUG("Processing Frequency after double conversion: %lf\n", frequencyValue);

bool ssidMatches = scanForSsidsSet.empty() || scanForSsidsSet.find(ssid) != scanForSsidsSet.end();
bool freqMatches = m_filterfrequency.empty() || (filterFreq == frequencyValue);

if (ssidMatches && freqMatches)
{
result.Add(object);
NMLOG_DEBUG("Match found: SSID = %s, Frequency = %lf\n", ssid.c_str(), frequencyValue);
}
else
{
NMLOG_DEBUG("No match: SSID = %s, Frequency = %lf\n", ssid.c_str(), frequencyValue);
}
}
ssids = result;
NMLOG_DEBUG("After filtering, found %d SSIDs.", ssids.Length());
}

// WiFi Specific Methods
/* @brief Initiate a WIFI Scan; This is Async method and returns the scan results as Event */
uint32_t NetworkManagerImplementation::GetSupportedSecurityModes(ISecurityModeIterator*& securityModes /* @out */) const
Expand Down Expand Up @@ -581,12 +631,22 @@ namespace WPEFramework
_notificationLock.Unlock();
}

void NetworkManagerImplementation::ReportAvailableSSIDs(const string jsonOfWiFiScanResults)
void NetworkManagerImplementation::ReportAvailableSSIDs(JsonArray &arrayofWiFiScanResults)
{
_notificationLock.Lock();
NMLOG_INFO("Posting onAvailableSSIDs result is, %s", jsonOfWiFiScanResults.c_str());
string jsonOfWiFiScanResults;
string jsonOfFilterScanResults;

arrayofWiFiScanResults.ToString(jsonOfWiFiScanResults);
NMLOG_DEBUG("Posting onAvailableSSIDs result before Filtering is, %s", jsonOfWiFiScanResults.c_str());

filterScanResults(arrayofWiFiScanResults);

arrayofWiFiScanResults.ToString(jsonOfFilterScanResults);

NMLOG_INFO("Posting onAvailableSSIDs result is, %s", jsonOfFilterScanResults.c_str());
for (const auto callback : _notificationCallbacks) {
callback->onAvailableSSIDs(jsonOfWiFiScanResults);
callback->onAvailableSSIDs(jsonOfFilterScanResults);
}
_notificationLock.Unlock();
}
Expand Down
8 changes: 6 additions & 2 deletions NetworkManagerImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ namespace WPEFramework
void ReportActiveInterfaceChange(const string prevActiveInterface, const string currentActiveinterface);
void ReportIPAddressChange(const string interface, const string ipversion, const string ipaddress, const Exchange::INetworkManager::IPStatus status);
void ReportInternetStatusChange(const Exchange::INetworkManager::InternetStatus prevState, const Exchange::INetworkManager::InternetStatus currState);
void ReportAvailableSSIDs(const string jsonOfScanResults);
void ReportAvailableSSIDs(JsonArray &arrayofWiFiScanResults);
void ReportWiFiStateChange(const Exchange::INetworkManager::WiFiState state);
void ReportWiFiSignalStrengthChange(const string ssid, const string strength, const Exchange::INetworkManager::WiFiSignalQuality quality);

Expand All @@ -233,6 +233,7 @@ namespace WPEFramework
void getInitialConnectionState();
void threadEventRegistration();
void executeExternally(NetworkEvents event, const string commandToExecute, string& response);
void filterScanResults(JsonArray &ssids);

private:
std::list<Exchange::INetworkManager::INotification *> _notificationCallbacks;
Expand All @@ -245,7 +246,10 @@ namespace WPEFramework
uint16_t m_stunBindTimeout;
uint16_t m_stunCacheTimeout;
std::thread m_registrationThread;
public:
string m_filterfrequency;
std::vector<std::string> m_filterSsidslist;

public:
WiFiSignalStrengthMonitor m_wifiSignalMonitor;
mutable ConnectivityMonitor connectivityMonitor;
};
Expand Down
32 changes: 30 additions & 2 deletions NetworkManagerJsonRpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,14 +667,42 @@ namespace WPEFramework
{
LOG_INPARAM();
uint32_t rc = Core::ERROR_GENERAL;
string frequency = parameters["frequency"].String();
Exchange::INetworkManager::IStringIterator* ssids = NULL;
string frequency{};
Exchange::INetworkManager::IStringIterator* ssids = NULL;

if (parameters.HasLabel("frequency"))
frequency = parameters["frequency"].String();

if (parameters.HasLabel("ssids"))
{
JsonArray array = parameters["ssids"].Array();
std::vector<std::string> ssidslist;
JsonArray::Iterator index(array.Elements());

while (index.Next() == true)
{
if (Core::JSON::Variant::type::STRING == index.Current().Content())
{
ssidslist.push_back(index.Current().String().c_str());
}
else
{
NMLOG_ERROR("Unexpected variant type in SSID array.");
returnJson(rc);
}
}
ssids = (Core::Service<RPC::StringIterator>::Create<RPC::IStringIterator>(ssidslist));
}

if (_networkManager)
rc = _networkManager->StartWiFiScan(frequency, ssids);
else
rc = Core::ERROR_UNAVAILABLE;

if (ssids)
ssids->Release();


returnJson(rc);
}

Expand Down
25 changes: 20 additions & 5 deletions NetworkManagerRDKProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,8 @@ namespace WPEFramework
}

JsonArray ssids = eventDocument["getAvailableSSIDs"].Array();
string json;
ssids.ToString(json);

::_instance->ReportAvailableSSIDs(json);
::_instance->ReportAvailableSSIDs(ssids);
break;
}
case IARM_BUS_WIFI_MGR_EVENT_onWIFIStateChanged:
Expand Down Expand Up @@ -1085,8 +1083,25 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = {
IARM_Bus_WiFiSrvMgr_SsidList_Param_t param{};
IARM_Result_t retVal = IARM_RESULT_SUCCESS;

(void)ssids;
(void) frequency;
//Cleared the Existing Store filterred SSID list
m_filterSsidslist.clear();
m_filterfrequency.clear();

if(ssids)
{
string ssidlist{};
while (ssids->Next(ssidlist) == true)
{
m_filterSsidslist.push_back(ssidlist.c_str());
NMLOG_DEBUG("%s added to SSID filtering", ssidlist.c_str());
}
}

if (!frequency.empty())
{
m_filterfrequency = frequency;
NMLOG_DEBUG("Scan SSIDs of frequency %s", m_filterfrequency.c_str());
}

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

Expand Down

0 comments on commit bf871b9

Please sign in to comment.