forked from rdkcentral/networkmanager
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe43ec5
commit a69c19b
Showing
8 changed files
with
375 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 6 additions & 3 deletions
9
Tests/dbus-api-test/networkManagerClient.h → ...dbus-api-test/NetworkManagerGnomeClient.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
#pragma once | ||
|
||
#include "dbusConnectionManager.h" | ||
#include <string> | ||
#include <list> | ||
|
||
#include "dbusConnectionManager.h" | ||
#include "NetworkManagerGnomeUtils.h" | ||
|
||
|
||
class NetworkManagerClient { | ||
public: | ||
NetworkManagerClient(); | ||
~NetworkManagerClient(); | ||
|
||
bool getKnownSSIDs(std::list<std::string>& ssids); | ||
|
||
bool getavilableSSID(std::list<std::string>& ssids); | ||
bool getConnectedSSID(); | ||
private: | ||
DbusConnectionManager dbusConnection; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
|
||
#include <glib.h> | ||
#include <gio/gio.h> | ||
#include <stdio.h> | ||
#include <string> | ||
|
||
#include "NetworkManagerGnomeUtils.h" | ||
|
||
// Function to get device path by network interface name | ||
bool GnomeUtils::getDeviceByIpIface(GDBusConnection *connection, const gchar *iface_name, std::string& path) | ||
{ | ||
GError *error = NULL; | ||
GVariant *result; | ||
gchar *device_path = NULL; | ||
bool ret = false; | ||
|
||
// // Connect to the system bus | ||
// connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); | ||
// if (error != NULL) { | ||
// g_printerr("Error connecting to system bus: %s\n", error->message); | ||
// g_error_free(error); | ||
// return NULL; | ||
// } | ||
|
||
result = g_dbus_connection_call_sync( | ||
connection, | ||
"org.freedesktop.NetworkManager", // D-Bus name | ||
"/org/freedesktop/NetworkManager", // Object path | ||
"org.freedesktop.NetworkManager", // Interface | ||
"GetDeviceByIpIface", // Method name | ||
g_variant_new("(s)", iface_name), // Input parameter (the interface name) | ||
G_VARIANT_TYPE("(o)"), // Expected return type (object path) | ||
G_DBUS_CALL_FLAGS_NONE, | ||
-1, // Default timeout | ||
NULL, | ||
&error | ||
); | ||
|
||
if (error != NULL) { | ||
NMLOG_ERROR("calling GetDeviceByIpIface: %s", error->message); | ||
g_error_free(error); | ||
return ret; | ||
} | ||
|
||
g_variant_get(result, "(o)", &device_path); | ||
if(g_strdup(device_path) != NULL) | ||
{ | ||
path = std::string(g_strdup(device_path)); | ||
ret = true; | ||
} | ||
|
||
g_variant_unref(result); | ||
return ret; | ||
} | ||
|
||
static bool get_cached_property_u(GDBusProxy* proxy, const char* propertiy, uint32_t value) | ||
{ | ||
GVariant* result = NULL; | ||
result = g_dbus_proxy_get_cached_property(proxy, propertiy); | ||
if (!result) { | ||
NMLOG_ERROR("Failed to get AP properties"); | ||
g_object_unref(proxy); | ||
return false; | ||
} | ||
g_variant_get(result, "u", &value); | ||
NMLOG_TRACE("%s: %d", propertiy, value); | ||
g_variant_unref(result); | ||
return true; | ||
} | ||
|
||
/* | ||
Flags readable u | ||
WpaFlags readable u | ||
RsnFlags readable u | ||
Ssid readable ay | ||
Frequency readable u | ||
HwAddress readable s | ||
Mode readable u | ||
MaxBitrate readable u | ||
Bandwidth readable u | ||
Strength readable y | ||
LastSeen readable i | ||
*/ | ||
bool GnomeUtils::getApDetails(GDBusConnection *connection, const char* apPath, apProperties& apDetails) | ||
{ | ||
char *bssid = NULL; | ||
uint8_t strength = 0; | ||
GError* error = NULL; | ||
GVariant* result = NULL; | ||
|
||
GDBusProxy* proxy = g_dbus_proxy_new_sync(connection, | ||
G_DBUS_PROXY_FLAGS_NONE, | ||
NULL, | ||
"org.freedesktop.NetworkManager", | ||
apPath, | ||
"org.freedesktop.NetworkManager.AccessPoint", | ||
NULL, | ||
&error); | ||
|
||
if (error) { | ||
NMLOG_ERROR("creating proxy: %s", error->message); | ||
g_error_free(error); | ||
return false; | ||
} | ||
|
||
gsize ssid_length = 0; | ||
result = g_dbus_proxy_get_cached_property(proxy,"Ssid"); | ||
if (!result) { | ||
std::cerr << "Failed to get AP properties." << std::endl; | ||
g_object_unref(proxy); | ||
return false; | ||
} | ||
const guchar *ssid_data = static_cast<const guchar*>(g_variant_get_fixed_array(result, &ssid_length, sizeof(guchar))); | ||
if (ssid_data && ssid_length > 0 && ssid_length <= 32) { | ||
apDetails.ssid.assign(reinterpret_cast<const char*>(ssid_data), ssid_length); | ||
NMLOG_TRACE("SSID: %s", apDetails.ssid.c_str()); | ||
} else { | ||
NMLOG_ERROR("Invalid SSID length: %zu (maximum is 32)", ssid_length); | ||
apDetails.ssid="---"; | ||
} | ||
g_variant_unref(result); | ||
|
||
result = g_dbus_proxy_get_cached_property(proxy,"HwAddress"); | ||
if (!result) { | ||
std::cerr << "Failed to get AP properties." << std::endl; | ||
g_object_unref(proxy); | ||
return false; | ||
} | ||
g_variant_get(result, "s", &bssid); | ||
apDetails.bssid.assign(bssid); | ||
NMLOG_TRACE("bssid %s", apDetails.bssid.c_str()); | ||
g_variant_unref(result); | ||
|
||
result = g_dbus_proxy_get_cached_property(proxy,"Strength"); | ||
if (!result) { | ||
std::cerr << "Failed to get AP properties." << std::endl; | ||
g_object_unref(proxy); | ||
return false; | ||
} | ||
g_variant_get(result, "y", &strength); | ||
NMLOG_TRACE("strength %d", strength); | ||
g_variant_unref(result); | ||
|
||
get_cached_property_u(proxy, "Flags", apDetails.flags); | ||
get_cached_property_u(proxy, "WpaFlags", apDetails.wpaFlags); | ||
get_cached_property_u(proxy, "RsnFlags", apDetails.rsnFlags); | ||
get_cached_property_u(proxy, "Mode", apDetails.mode); | ||
get_cached_property_u(proxy, "Frequency", apDetails.frequency); | ||
|
||
g_object_unref(proxy); | ||
|
||
return true; | ||
} |
Oops, something went wrong.