Skip to content

Commit

Permalink
Update the required changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tabbas651 committed Oct 9, 2024
1 parent 2dddc5e commit ac6c41c
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 90 deletions.
2 changes: 1 addition & 1 deletion NetworkManagerGnomeEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ namespace WPEFramework

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

Expand Down
52 changes: 51 additions & 1 deletion NetworkManagerImplementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,49 @@ namespace WPEFramework
return;
}

void NetworkManagerImplementation::filterScanResults(JsonArray &ssids)
{
JsonArray result;

if (scanForFreq != WIFI_FREQUENCY_WHATEVER)
{
for(int i=0; i<ssids.Length(); i++)
{
JsonObject object = ssids[i].Object();
std::string filterValue;

switch (scanForFreq) {
case WIFI_FREQUENCY_2_4_GHZ:
filterValue = "2.4";
break;
case WIFI_FREQUENCY_5_GHZ:
filterValue = "5";
break;
case WIFI_FREQUENCY_6_GHZ:
filterValue = "6";
break;
default:
filterValue = "";
break;
}

NMLOG_INFO("filtervalue %s received", filterValue);

if(object["frequency"].String() != filterValue)
{
NMLOG_INFO("Frequency filter out %s != %s", object["frequency"].String().c_str(), filterValue.c_str());
continue;
}
result.Add(object);
}
ssids = result;
}
else
{
NMLOG_INFO("No frequency filter applied (UNKNOWN), returning all SSIDs.");
}
}

// 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 @@ -541,10 +584,17 @@ namespace WPEFramework
_notificationLock.Unlock();
}

void NetworkManagerImplementation::ReportAvailableSSIDsEvent(const string jsonOfWiFiScanResults)
void NetworkManagerImplementation::ReportAvailableSSIDsEvent(JsonArray &arrayofWiFiScanResults)
{
LOG_ENTRY_FUNCTION();
_notificationLock.Lock();

string jsonOfWiFiScanResults;

filterScanResults(arrayofWiFiScanResults);

arrayofWiFiScanResults.ToString(jsonOfWiFiScanResults);

NMLOG_INFO("Posting onAvailableSSIDs result is, %s", jsonOfWiFiScanResults.c_str());
for (const auto callback : _notificationCallbacks) {
callback->onAvailableSSIDs(jsonOfWiFiScanResults);
Expand Down
2 changes: 1 addition & 1 deletion NetworkManagerImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ namespace WPEFramework
void ReportIPAddressChangedEvent(const string& interface, bool isAcquired, bool isIPv6, const string& ipAddress);
void ReportActiveInterfaceChangedEvent(const string prevActiveInterface, const string currentActiveinterface);
void ReportInternetStatusChangedEvent(const InternetStatus oldState, const InternetStatus newstate);
void ReportAvailableSSIDsEvent(const string jsonOfWiFiScanResults);
void ReportAvailableSSIDsEvent(JsonArray &arrayofWiFiScanResults);
void ReportWiFiStateChangedEvent(const INetworkManager::WiFiState state);
void ReportWiFiSignalStrengthChangedEvent(const string ssid , const string signalLevel , const WiFiSignalQuality signalQuality);

Expand Down
68 changes: 30 additions & 38 deletions NetworkManagerJsonRpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -769,47 +769,39 @@ namespace WPEFramework
{
LOG_INPARAM();
uint32_t rc = Core::ERROR_GENERAL;
double frequencyValue = 0.0;
Exchange::INetworkManager::WiFiFrequency frequency = Exchange::INetworkManager::WiFiFrequency::WIFI_FREQUENCY_WHATEVER;

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

NMLOG_INFO("Received frequency string: %s", freqString.c_str());

if (freqString == "2.4") {
frequency = Exchange::INetworkManager::WiFiFrequency::WIFI_FREQUENCY_2_4_GHZ;
}
else if (freqString == "5") {
frequency = Exchange::INetworkManager::WiFiFrequency::WIFI_FREQUENCY_5_GHZ;
}
else if (freqString == "6") {
frequency = Exchange::INetworkManager::WiFiFrequency::WIFI_FREQUENCY_6_GHZ;
}
else {
NMLOG_ERROR("Invalid frequency value received: %s", freqString.c_str());
frequency = Exchange::INetworkManager::WiFiFrequency::WIFI_FREQUENCY_WHATEVER;
}

NMLOG_INFO("Frequency value mapped to enum: %d", frequency);

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

if (Core::ERROR_NONE == rc)
{
if (parameters["frequency"].Content() == Core::JSON::Variant::type::NUMBER)
frequencyValue = parameters["frequency"].Number();
else if (parameters["frequency"].Content() == Core::JSON::Variant::type::STRING)
frequencyValue = stod(parameters["frequency"].String()); // Use stod converts a string to double, handles decimals

NMLOG_INFO("Frequency value received: %f", frequencyValue);

//Map the double value to WiFiFrequency enum
if (frequencyValue == 2.4) {
frequency = Exchange::INetworkManager::WiFiFrequency::WIFI_FREQUENCY_2_4_GHZ;
}
else if (frequencyValue == 5.0) {
frequency = Exchange::INetworkManager::WiFiFrequency::WIFI_FREQUENCY_5_GHZ;
}
else if (frequencyValue == 6.0) {
frequency = Exchange::INetworkManager::WiFiFrequency::WIFI_FREQUENCY_6_GHZ;
}
else {
NMLOG_INFO("Invalid frequency value: %f\n", frequencyValue);
frequency = Exchange::INetworkManager::WiFiFrequency::WIFI_FREQUENCY_WHATEVER;
}
}

NMLOG_INFO("Mapped frequency to enum value: %d", static_cast<Exchange::INetworkManager::WiFiFrequency>(frequency));

if (_networkManager)
rc = _networkManager->StartWiFiScan(static_cast<Exchange::INetworkManager::WiFiFrequency>(frequency));
else
rc = Core::ERROR_UNAVAILABLE;

if (Core::ERROR_NONE == rc)
{
response["success"] = true;
}
LOG_OUTPARAM();
return rc;
response["success"] = true;
}
LOG_OUTPARAM();
return rc;
}

uint32_t NetworkManager::StopWiFiScan(const JsonObject& parameters, JsonObject& response)
Expand Down
50 changes: 1 addition & 49 deletions NetworkManagerRDKProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,6 @@ typedef struct _IARM_Bus_WiFiSrvMgr_SsidList_Param_t {
} IARM_Bus_WiFiSrvMgr_SsidList_Param_t;


uint32_t NetworkManagerImplementation::currentFrequency = 0;

#define IARM_BUS_NETSRVMGR_API_getInterfaceList "getInterfaceList"
#define IARM_BUS_NETSRVMGR_API_getDefaultInterface "getDefaultInterface"
#define IARM_BUS_NETSRVMGR_API_setDefaultInterface "setDefaultInterface"
Expand Down Expand Up @@ -500,11 +498,8 @@ namespace WPEFramework
}

JsonArray ssids = eventDocument["getAvailableSSIDs"].Array();
::_instance->FilterWiFiByFrequency(ssids);
string json;
ssids.ToString(json);

::_instance->ReportAvailableSSIDsEvent(json);
::_instance->ReportAvailableSSIDsEvent(ssids);
}
case IARM_BUS_WIFI_MGR_EVENT_onWIFIStateChanged:
{
Expand Down Expand Up @@ -534,49 +529,6 @@ namespace WPEFramework
NMLOG_WARNING("WARNING - cannot handle IARM events without a Network plugin instance!");
}

void NetworkManagerImplementation::FilterWiFiByFrequency(JsonArray &ssids)
{
JsonArray result;

if (NetworkManagerImplementation::currentFrequency != WIFI_FREQUENCY_WHATEVER)
{
for(int i=0; i<ssids.Length(); i++)
{
JsonObject object = ssids[i].Object();
std::string filterValue;

switch (NetworkManagerImplementation::currentFrequency) {
case WIFI_FREQUENCY_2_4_GHZ:
filterValue = "2.4";
break;
case WIFI_FREQUENCY_5_GHZ:
filterValue = "5";
break;
case WIFI_FREQUENCY_6_GHZ:
filterValue = "6";
break;
default:
filterValue = "";
break;
}

NMLOG_INFO("filtervalue %s received", filterValue);

if(object["frequency"].String() != filterValue)
{
NMLOG_INFO("Frequency filter out %s != %s", object["frequency"].String().c_str(), filterValue.c_str());
continue;
}
result.Add(object);
}
ssids = result;
}
else
{
NMLOG_INFO("No frequency filter applied (UNKNOWN), returning all SSIDs.");
}
}

void NetworkManagerImplementation::retryIarmEventRegistration()
{
m_registrationThread = thread(&NetworkManagerImplementation::threadEventRegistration, this);
Expand Down

0 comments on commit ac6c41c

Please sign in to comment.