Skip to content

Commit

Permalink
set interface and sterngth fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cmuhammedrafi committed Nov 21, 2024
1 parent ad6e031 commit 70ef881
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 34 deletions.
10 changes: 3 additions & 7 deletions NetworkManagerGnomeEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,26 +629,22 @@ namespace WPEFramework
}

ssidList.ToString(ssidListJson);
if(_nmEventInstance->debugLogs) {
_nmEventInstance->debugLogs = false;
NMLOG_INFO("Number of Access Points Available = %d", static_cast<int>(accessPoints->len));
NMLOG_DEBUG("Scanned APIs are = %s",ssidListJson.c_str());
}
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);
}
}

void GnomeNetworkManagerEvents::setwifiScanOptions(bool doNotify, bool enableLogs)
void GnomeNetworkManagerEvents::setwifiScanOptions(bool doNotify)
{
doScanNotify.store(doNotify);
if(!doScanNotify)
{
NMLOG_DEBUG("stop periodic wifi scan result notify");
}
debugLogs = enableLogs;
}

} // Plugin
Expand Down
3 changes: 1 addition & 2 deletions NetworkManagerGnomeEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,14 @@ namespace WPEFramework
static GnomeNetworkManagerEvents* getInstance();
bool startNetworkMangerEventMonitor();
void stopNetworkMangerEventMonitor();
void setwifiScanOptions(bool doNotify, bool enableLogs = false);
void setwifiScanOptions(bool doNotify);

private:
static void* networkMangerEventMonitor(void *arg);
GnomeNetworkManagerEvents();
~GnomeNetworkManagerEvents();
std::atomic<bool>isEventThrdActive = {false};
std::atomic<bool>doScanNotify = {false};
std::atomic<bool>debugLogs = {false};
NMEvents nmEvents;
GThread *eventThrdID;
};
Expand Down
30 changes: 20 additions & 10 deletions NetworkManagerGnomeProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,16 +277,26 @@ namespace WPEFramework

NMDeviceState deviceState = NM_DEVICE_STATE_UNKNOWN;
deviceState = nm_device_get_state(device);
if(deviceState <= NM_DEVICE_STATE_UNMANAGED) // already disconnected state
return Core::ERROR_NONE;
else if(deviceState > NM_DEVICE_STATE_DISCONNECTED)

if(enabled) // do enable
{
GMainLoop *g_loop;
g_loop = g_main_loop_new(NULL, FALSE);
nm_device_disconnect_async(device, NULL, deviceDisconnectCb, g_loop);
g_main_loop_run(g_loop);
if(deviceState >= NM_DEVICE_STATE_DISCONNECTED) // already enabled
return Core::ERROR_NONE;
}

else // do disable
{
if(deviceState <= NM_DEVICE_STATE_UNMANAGED) // already disabled
return Core::ERROR_NONE;
else if(deviceState > NM_DEVICE_STATE_DISCONNECTED)
{
/* if inteface is connected then disconnect to flush the ip */
GMainLoop *g_loop;
g_loop = g_main_loop_new(NULL, FALSE);
nm_device_disconnect_async(device, NULL, deviceDisconnectCb, g_loop);
g_main_loop_run(g_loop);
}
}
// TODO fix depricated api
nm_device_set_managed(device, enabled);
NMLOG_INFO("interface %s state: %s", interface.c_str(), enabled ? "enabled" : "disabled");
return Core::ERROR_NONE;
Expand Down Expand Up @@ -696,7 +706,7 @@ namespace WPEFramework
uint32_t rc = Core::ERROR_RPC_CALL_FAILED;
(void) ssids;

nmEvent->setwifiScanOptions(true, true);
nmEvent->setwifiScanOptions(true);
if(wifi->wifiScanRequest(frequency))
rc = Core::ERROR_NONE;
return rc;
Expand Down Expand Up @@ -762,7 +772,7 @@ namespace WPEFramework
// Check the last scanning time and if it exceeds 5 sec do a rescanning
if(!wifi->isWifiScannedRecently())
{
nmEvent->setwifiScanOptions(false, false);
nmEvent->setwifiScanOptions(false);
if(!wifi->wifiScanRequest())
{
NMLOG_WARNING("scanning failed but try to connect");
Expand Down
24 changes: 12 additions & 12 deletions NetworkManagerGnomeUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,20 +216,20 @@ namespace WPEFramework
ssidStr = nm_utils_ssid_to_utf8((const guint8*)g_bytes_get_data(ssid, NULL), g_bytes_get_size(ssid));
string ssidString(ssidStr);
ssidObj["ssid"] = ssidString;
strength = nm_access_point_get_strength(ap);
apFreq = nm_access_point_get_frequency(ap);
flags = nm_access_point_get_flags(ap);
wpaFlags = nm_access_point_get_wpa_flags(ap);
rsnFlags = nm_access_point_get_rsn_flags(ap);
freq = nmUtils::wifiFrequencyFromAp(apFreq);
security = nmUtils::wifiSecurityModeFromAp(flags, wpaFlags, rsnFlags);

ssidObj["security"] = security;
ssidObj["strength"] = nmUtils::convertPercentageToSignalStrengtStr(strength);
ssidObj["frequency"] = freq;
}
else
ssidObj["ssid"] = "---"; // hidden ssid TODO modify
strength = nm_access_point_get_strength(ap);
apFreq = nm_access_point_get_frequency(ap);
flags = nm_access_point_get_flags(ap);
wpaFlags = nm_access_point_get_wpa_flags(ap);
rsnFlags = nm_access_point_get_rsn_flags(ap);
freq = nmUtils::wifiFrequencyFromAp(apFreq);
security = nmUtils::wifiSecurityModeFromAp(flags, wpaFlags, rsnFlags);

ssidObj["security"] = security;
ssidObj["signalStrength"] = strength;
ssidObj["frequency"] = freq;
NMLOG_DEBUG("hidden ssid found, bssid: %s", nm_access_point_get_bssid(ap));

return ssidObj;
}
Expand Down
6 changes: 3 additions & 3 deletions NetworkManagerGnomeWIFI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ namespace WPEFramework

NMAccessPoint *activeAP = nm_device_wifi_get_active_access_point(wifiDevice);
if(activeAP == NULL) {
NMLOG_DEBUG("No active access point found !");
NMLOG_INFO("No active access point found !");
return false;
}
else
Expand Down Expand Up @@ -316,8 +316,8 @@ namespace WPEFramework

NMDevice *wifiNMDevice = getNmDevice();
if(wifiNMDevice == NULL) {
NMLOG_ERROR("NMDeviceWifi NULL !");
return false;
NMLOG_WARNING("wifi state is unmanaged !");
return true;
}

nm_device_disconnect_async(wifiNMDevice, NULL, wifiDisconnectCb, this);
Expand Down

0 comments on commit 70ef881

Please sign in to comment.