Skip to content

Commit

Permalink
startscan ssid fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
cmuhammedrafi committed Dec 6, 2024
1 parent 969668b commit 645bb01
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 31 deletions.
10 changes: 6 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@ set_target_properties(${MODULE_NAME} PROPERTIES


if(ENABLE_GNOME_NETWORKMANAGER)
target_sources(${MODULE_NAME} PRIVATE NetworkManagerGnomeProxy.cpp
NetworkManagerGnomeWIFI.cpp
NetworkManagerGnomeEvents.cpp
NetworkManagerGnomeUtils.cpp )
target_sources(${MODULE_NAME} PRIVATE
gdbus/NetworkManagerGdbusProxy.cpp
gdbus/NetworkManagerGdbusMgr.cpp
gdbus/NetworkManagerGdbusClient.cpp
gdbus/NetworkManagerGdbusEvent.cpp
gdbus/NetworkManagerGdbusUtils.cpp )
target_include_directories(${MODULE_NAME} PRIVATE ${GLIB_INCLUDE_DIRS} ${LIBNM_INCLUDE_DIRS})
target_link_libraries(${MODULE_NAME} PRIVATE ${LIBNM_LIBRARIES})
else()
Expand Down
2 changes: 1 addition & 1 deletion Tests/raspberrypi/NetworkManagerGdbusTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ int main() {
std::cout << "Enter SSID to scan (leave blank for all): ";
std::cin.ignore();
std::getline(std::cin, ssid);
if (nmClient->startWifiScan(ssid)) {
nmEvents->setwifiScanOptions(true);
if (nmClient->startWifiScan(ssid)) {
NMLOG_INFO("WiFi scan started successfully");
} else {
NMLOG_ERROR("Failed to start WiFi scan");
Expand Down
49 changes: 24 additions & 25 deletions gdbus/NetworkManagerGdbusClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,41 +329,35 @@ namespace WPEFramework
g_warning("Unexpected variant type: %s", g_variant_get_type_string (timestampVariant));
}

GVariant *options = NULL;
if (!ssid.empty())
{
// TODO fix specific ssid scanning
NMLOG_INFO("staring wifi scanning .. %s", ssid.c_str());
GVariantBuilder settingsBuilder;
g_variant_builder_init (&settingsBuilder, G_VARIANT_TYPE ("a{sv}"));
GVariant *ssid_array = g_variant_new_fixed_array(G_VARIANT_TYPE_BYTE, (const guint8 *)ssid.c_str(), ssid.length(), 1);
g_variant_builder_add (&settingsBuilder, "{sv}", "ssids", ssid_array);

// GVariantBuilder builder, array_builder;
// g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
// g_variant_builder_init(&array_builder, G_VARIANT_TYPE("aay"));
// g_variant_builder_add(&array_builder, "@ay",
// g_variant_new_fixed_array(G_VARIANT_TYPE_BYTE, (const guint8 *) ssid.c_str(), ssid.length(), 1)
// );
// g_variant_builder_add(&builder, "{sv}", "ssids", g_variant_builder_end(&array_builder));
// g_variant_builder_add(&builder, "{sv}", "hidden", g_variant_new_boolean(TRUE));

options = g_variant_builder_end(&settingsBuilder);
g_dbus_proxy_call_sync(wProxy, "RequestScan", options, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
GVariantBuilder builder;
NMLOG_INFO("Starting WiFi scanning with SSID: %s", ssid.c_str());
GVariantBuilder ssid_array_builder;
g_variant_builder_init(&ssid_array_builder, G_VARIANT_TYPE("aay"));
g_variant_builder_add_value(&ssid_array_builder,
g_variant_new_fixed_array(G_VARIANT_TYPE_BYTE, (const guint8 *)ssid.c_str(), ssid.length(),1));
/* ssid GVariant = [['S', 'S', 'I', 'D']] */
g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}"));
g_variant_builder_add(&builder, "{sv}", "ssids", g_variant_builder_end(&ssid_array_builder));
g_dbus_proxy_call_sync(wProxy, "RequestScan", g_variant_new("(a{sv})", builder),
G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
}
else
g_dbus_proxy_call_sync(wProxy, "RequestScan", g_variant_new("(a{sv})", options), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
if (error) {

else {
g_dbus_proxy_call_sync(wProxy, "RequestScan", g_variant_new("(a{sv})", NULL),
G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
}

if (error)
{
NMLOG_ERROR("Error RequestScan: %s", error->message);
g_error_free(error);
g_object_unref(wProxy);
return false;
}

if(options)
g_variant_unref(options);
g_object_unref(wProxy);

return true;
}

Expand Down Expand Up @@ -939,5 +933,10 @@ namespace WPEFramework
return true;
}

bool NetworkManagerClient::startWPS()
{

}

} // WPEFramework
} // Plugin
2 changes: 1 addition & 1 deletion gdbus/NetworkManagerGdbusClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace WPEFramework
bool wifiDisconnect();
bool getWifiState(Exchange::INetworkManager::WiFiState &state);
bool getWiFiSignalStrength(std::string& ssid, std::string& signalStrength, Exchange::INetworkManager::WiFiSignalQuality& quality);
bool startWPS (const Exchange::INetworkManager::WiFiWPS& method , const string& wps_pin ) {return false;}
bool startWPS();
bool stopWPS() {return false;}
bool stopWiFiScan() {return false;}

Expand Down
4 changes: 4 additions & 0 deletions gdbus/NetworkManagerGdbusProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "NetworkManagerImplementation.h"
#include "NetworkManagerGdbusClient.h"
#include "NetworkManagerGdbusEvent.h"

using namespace WPEFramework;
using namespace WPEFramework::Plugin;
Expand All @@ -30,6 +31,7 @@ namespace WPEFramework
{
NetworkManagerImplementation* _instance = nullptr;
NetworkManagerClient* gnomeDbusClient = nullptr;
NetworkManagerEvents* nmEvents = NetworkManagerEvents::getInstance();
void NetworkManagerInternalEventHandler(const char *owner, int eventId, void *data, size_t len)
{
return;
Expand Down Expand Up @@ -79,6 +81,7 @@ namespace WPEFramework
uint32_t NetworkManagerImplementation::StartWiFiScan(const WiFiFrequency frequency /* @in */)
{
uint32_t rc = Core::ERROR_GENERAL;
nmEvents->setwifiScanOptions(true);
if(gnomeDbusClient->startWifiScan())
rc = Core::ERROR_NONE;
else
Expand All @@ -90,6 +93,7 @@ namespace WPEFramework
{
// TODO FIX
uint32_t rc = Core::ERROR_GENERAL;
nmEvents->setwifiScanOptions(false);
if(gnomeDbusClient->stopWiFiScan())
rc = Core::ERROR_NONE;
else
Expand Down

0 comments on commit 645bb01

Please sign in to comment.