Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
cmuhammedrafi committed Dec 6, 2024
1 parent 645bb01 commit 26daa4a
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 178 deletions.
18 changes: 9 additions & 9 deletions Tests/raspberrypi/NetworkManagerGdbusTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ int main() {
case 3: {
Exchange::INetworkManager::WiFiSSIDInfo ssidinfo;
if (nmClient->getConnectedSSID(ssidinfo)) {
NMLOG_INFO("Connected SSID: %s", ssidinfo.m_ssid.c_str());
NMLOG_INFO("Connected SSID: %s", ssidinfo.ssid.c_str());
} else {
NMLOG_ERROR("Failed to get connected SSID");
}
Expand All @@ -116,10 +116,10 @@ int main() {
std::getline(std::cin, passphrase);
WPEFramework::Exchange::INetworkManager::WIFISecurityMode securityType = getSecurityType();
Exchange::INetworkManager::WiFiConnectTo ssidinfo = {
.m_ssid = ssid,
.m_passphrase = passphrase,
.m_securityMode = securityType,
.m_persistSSIDInfo = true,
.ssid = ssid,
.passphrase = passphrase,
.security = securityType,
.persist = true,
};
if (nmClient->addToKnownSSIDs(ssidinfo)) {
NMLOG_INFO("SSID added to known list successfully");
Expand Down Expand Up @@ -172,10 +172,10 @@ int main() {
std::cin >> persist;

Exchange::INetworkManager::WiFiConnectTo ssidinfo = {
.m_ssid = ssid,
.m_passphrase = passphrase,
.m_securityMode = securityType,
.m_persistSSIDInfo = persist
.ssid = ssid,
.passphrase = passphrase,
.security = securityType,
.persist = persist
};

if (nmClient->wifiConnect(ssidinfo)) {
Expand Down
110 changes: 55 additions & 55 deletions gdbus/NetworkManagerGdbusClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,11 @@ namespace WPEFramework

if(gVarConn)
{
const char *connTyp= NULL;
const char *connTyp = NULL;
const char *interfaceName = NULL;
G_VARIANT_LOOKUP(gVarConn, "type", "&s", &connTyp);
if(strcmp(connTyp, "802-11-wireless") != 0)
{
//NMLOG_DEBUG("ERROR: connection is not 802-11-wireless type");
ret = false;
}
else
G_VARIANT_LOOKUP(gVarConn, "interface-name", "&s", &interfaceName);
if((strcmp(connTyp, "802-11-wireless") == 0) && strcmp(interfaceName, GnomeUtils::getWifiIfname()) != 0 )
{
// 802-11-wireless.ssid: <ssid>
GVariant *setting = NULL;
Expand Down Expand Up @@ -135,6 +132,8 @@ namespace WPEFramework
ret = true;
}
}
else
ret = false;
g_variant_unref(gVarConn);
}

Expand Down Expand Up @@ -208,7 +207,7 @@ namespace WPEFramework
GVariant* result = NULL;
gchar *activeApPath = NULL;
bool ret = false;
deviceInfo devInfo;
deviceInfo devInfo{};

if(!GnomeUtils::getDeviceInfoByIfname(m_dbus, GnomeUtils::getWifiIfname(), devInfo))
return false;
Expand All @@ -234,7 +233,7 @@ namespace WPEFramework
if(g_strdup(activeApPath) != NULL && g_strcmp0(activeApPath, "/") != 0)
{
//NMLOG_DEBUG("ActiveAccessPoint property path %s", activeApPath);
if(GnomeUtils::getApDetails(m_dbus.getConnection(), g_strdup(activeApPath), ssidinfo))
if(GnomeUtils::getApDetails(m_dbus, g_strdup(activeApPath), ssidinfo))
{
ret = true;
}
Expand All @@ -251,7 +250,7 @@ namespace WPEFramework
{
GError* error = nullptr;
GDBusProxy* wProxy = nullptr;
deviceInfo devProperty;
deviceInfo devProperty{};

if(!GnomeUtils::getDeviceInfoByIfname(m_dbus, GnomeUtils::getWifiIfname(), devProperty))
return false;
Expand All @@ -274,17 +273,17 @@ namespace WPEFramework
return false;
}

GVariantIter* iter;
const gchar* apPath;
GVariantIter* iter = NULL;
const gchar* apPath = NULL;
g_variant_get(result, "(ao)", &iter);

while (g_variant_iter_loop(iter, "o", &apPath)) {
Exchange::INetworkManager::WiFiSSIDInfo wifiInfo;
Exchange::INetworkManager::WiFiSSIDInfo wifiInfo{};
NMLOG_DEBUG("Access Point Path: %s", apPath);
if(!GnomeUtils::getApDetails(m_dbus.getConnection(), apPath, wifiInfo))
if(!GnomeUtils::getApDetails(m_dbus, apPath, wifiInfo))
NMLOG_WARNING("getApDetails failed");
else
ssids.push_back(wifiInfo.m_ssid);
ssids.push_back(wifiInfo.ssid);
}

g_variant_iter_free(iter);
Expand Down Expand Up @@ -451,7 +450,7 @@ namespace WPEFramework
g_variant_builder_init (&optionsBuilder, G_VARIANT_TYPE ("a{sv}"));
if(!persist) // by default it will be in disk mode
{
NMLOG_ERROR("wifi connection will not persist to the disk");
NMLOG_WARNING("wifi connection will not persist to the disk");
g_variant_builder_add(&optionsBuilder, "{sv}", "persist", g_variant_new_string("volatile"));
}
//else
Expand All @@ -478,27 +477,32 @@ namespace WPEFramework
const char* newConnPath = g_variant_get_string(pathVariant, nullptr);
const char* activeConnPath = g_variant_get_string(activeConnVariant, nullptr);

NMLOG_DEBUG("newconn %s; activeconn %s",newConnPath, activeConnPath);
g_variant_unref(pathVariant);
g_variant_unref(activeConnVariant);
g_variant_unref(resultDict);
g_variant_unref(result);
g_object_unref(proxy);

NMLOG_INFO("newconn %s; activeconn %s",newConnPath, activeConnPath);
if(pathVariant)
g_variant_unref(pathVariant);
if(activeConnVariant)
g_variant_unref(activeConnVariant);
if(resultDict)
g_variant_unref(resultDict);
if(result)
g_variant_unref(result);
if(proxy)
g_object_unref(proxy);
return true;
}

static bool gVariantConnectionBuilder(const Exchange::INetworkManager::WiFiConnectTo& ssidinfo, GVariantBuilder& connBuilder, bool isWPSConn)
static bool gVariantConnectionBuilder(const Exchange::INetworkManager::WiFiConnectTo& ssidinfo, GVariantBuilder& connBuilder)
{
char *uuid = NULL;
GVariantBuilder settingsBuilder;

if(ssidinfo.m_ssid.empty() || ssidinfo.m_ssid.length() > 32)
if(ssidinfo.ssid.empty() || ssidinfo.ssid.length() > 32)
{
NMLOG_WARNING("ssid name is missing or invalied");
return false;
}

NMLOG_INFO("ssid %s, security %d, persist %d", ssidinfo.ssid.c_str(), (int)ssidinfo.security, (int)ssidinfo.persist);
/* Build up the complete connection */
g_variant_builder_init (&connBuilder, G_VARIANT_TYPE ("a{sa{sv}}"));

Expand All @@ -513,7 +517,7 @@ namespace WPEFramework

g_variant_builder_add (&settingsBuilder, "{sv}",
NM_SETTING_CONNECTION_ID,
g_variant_new_string (ssidinfo.m_ssid.c_str()));
g_variant_new_string (ssidinfo.ssid.c_str())); // connection id = ssid name

g_variant_builder_add (&settingsBuilder, "{sv}",
NM_SETTING_CONNECTION_INTERFACE_NAME,
Expand All @@ -529,7 +533,7 @@ namespace WPEFramework

/* Add the '802-11-wireless' Setting */
g_variant_builder_init (&settingsBuilder, G_VARIANT_TYPE ("a{sv}"));
GVariant *ssid_array = g_variant_new_fixed_array(G_VARIANT_TYPE_BYTE, (const guint8 *)ssidinfo.m_ssid.c_str(), ssidinfo.m_ssid.length(), 1);
GVariant *ssid_array = g_variant_new_fixed_array(G_VARIANT_TYPE_BYTE, (const guint8 *)ssidinfo.ssid.c_str(), ssidinfo.ssid.length(), 1);
g_variant_builder_add (&settingsBuilder, "{sv}",
NM_SETTING_WIRELESS_SSID,
ssid_array);
Expand All @@ -549,7 +553,7 @@ namespace WPEFramework
/* Build up the '802-11-wireless-security' settings */
g_variant_builder_init (&settingsBuilder, G_VARIANT_TYPE ("a{sv}"));

switch(ssidinfo.m_securityMode)
switch(ssidinfo.security)
{
case Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA_PSK_TKIP:
case Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA_PSK_AES:
Expand All @@ -559,13 +563,13 @@ namespace WPEFramework
case Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA3_PSK_AES:
case Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA3_SAE:
{
if(ssidinfo.m_passphrase.empty() || ssidinfo.m_passphrase.length() < 8)
if(ssidinfo.passphrase.empty() || ssidinfo.passphrase.length() < 8)
{
NMLOG_WARNING("wifi securtity type password erro length > 8");
return false;
}

if(Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA3_SAE == ssidinfo.m_securityMode)
if(Exchange::INetworkManager::WIFISecurityMode::WIFI_SECURITY_WPA3_SAE == ssidinfo.security)
{
NMLOG_DEBUG("802-11-wireless-security key-mgmt: 'sae'");
g_variant_builder_add (&settingsBuilder, "{sv}", NM_SETTING_WIRELESS_SECURITY_KEY_MGMT,
Expand All @@ -578,28 +582,20 @@ namespace WPEFramework
g_variant_new_string("wpa-psk")); // WPA + WPA2 + WPA3 personal
}
g_variant_builder_add (&settingsBuilder, "{sv}", NM_SETTING_WIRELESS_SECURITY_PSK,
g_variant_new_string(ssidinfo.m_passphrase.c_str()));
g_variant_new_string(ssidinfo.passphrase.c_str()));
break;
}

case Exchange::INetworkManager::WIFI_SECURITY_WEP_64:
case Exchange::INetworkManager::WIFI_SECURITY_WEP_128:
case Exchange::INetworkManager::WIFI_SECURITY_NONE:
{
NMLOG_DEBUG("802-11-wireless-security key-mgmt: 'none'");
g_variant_builder_add (&settingsBuilder, "{sv}", NM_SETTING_WIRELESS_SECURITY_KEY_MGMT,
g_variant_new_string("none")); // WEP or no password protection
if(isWPSConn)
{
g_variant_builder_add (&settingsBuilder, "{sv}",
NM_SETTING_WIRELESS_SECURITY_WPS_METHOD,
g_variant_new_byte(NM_SETTING_WIRELESS_SECURITY_WPS_METHOD_AUTO));
}
g_variant_new_string("none")); // no password protection
break;
}
default:
{
NMLOG_WARNING("connection wifi securtity type not supported %d", ssidinfo.m_securityMode);
NMLOG_WARNING("connection wifi securtity type not supported %d", ssidinfo.security);
return false;
}
}
Expand Down Expand Up @@ -651,13 +647,13 @@ namespace WPEFramework
return false;
}

std::list<std::string> paths;
if(GnomeUtils::getwifiConnectionPaths(m_dbus, deviceProp.path.c_str(), paths))
std::list<std::string> paths{};
if(GnomeUtils::getWifiConnectionPaths(m_dbus, deviceProp.path.c_str(), paths))
{
for (const std::string& path : paths)
{
std::string ssid;
if(getSSIDFromConnection(m_dbus, path, ssid) && ssid == ssidinfo.m_ssid)
std::string ssid{};
if(getSSIDFromConnection(m_dbus, path, ssid) && ssid == ssidinfo.ssid)
{
exsistingConn = path;
NMLOG_DEBUG("same connection exsist (%s) updating ...", exsistingConn.c_str());
Expand All @@ -667,7 +663,7 @@ namespace WPEFramework
}
}

if(!gVariantConnectionBuilder(ssidinfo, connBuilder, false))
if(!gVariantConnectionBuilder(ssidinfo, connBuilder))
{
NMLOG_WARNING("connection builder failed");
return false;
Expand Down Expand Up @@ -778,8 +774,8 @@ namespace WPEFramework
}
else
{
ssid = ssidInfo.m_ssid;
signalStrength = ssidInfo.m_signalStrength;
ssid = ssidInfo.ssid;
signalStrength = ssidInfo.strength;

float signalStrengthFloat = 0.0f;
if(!signalStrength.empty())
Expand Down Expand Up @@ -839,7 +835,6 @@ namespace WPEFramework

bool NetworkManagerClient::wifiConnect(const Exchange::INetworkManager::WiFiConnectTo& ssidinfo)
{
// TODO check argument length password min 8 and 32
// TODO check sudo nmcli device wifi connect HomeNet password rafi@123
// Error: Connection activation failed: Device disconnected by user or client error ?
GVariantBuilder connBuilder;
Expand All @@ -857,11 +852,11 @@ namespace WPEFramework
}

std::list<std::string> paths;
if(GnomeUtils::getwifiConnectionPaths(m_dbus, deviceProp.path.c_str(), paths))
if(GnomeUtils::getWifiConnectionPaths(m_dbus, deviceProp.path.c_str(), paths))
{
for (const std::string& path : paths) {
std::string ssid;
if(getSSIDFromConnection(m_dbus, path, ssid) && ssid == ssidinfo.m_ssid)
if(getSSIDFromConnection(m_dbus, path, ssid) && ssid == ssidinfo.ssid)
{
exsistingConn = path;
NMLOG_WARNING("same connection exsist (%s)", exsistingConn.c_str());
Expand All @@ -874,7 +869,7 @@ namespace WPEFramework
if(reuseConnection)
{
NMLOG_INFO("activating connection...");
ret = gVariantConnectionBuilder(ssidinfo, connBuilder, true);
ret = gVariantConnectionBuilder(ssidinfo, connBuilder);
if(!ret) {
NMLOG_WARNING("connection builder failed");
return false;
Expand All @@ -887,12 +882,12 @@ namespace WPEFramework
}
else
{
ret = gVariantConnectionBuilder(ssidinfo, connBuilder, true);
ret = gVariantConnectionBuilder(ssidinfo, connBuilder);
if(!ret) {
NMLOG_WARNING("connection builder failed");
return false;
}
if(addNewConnctionAndactivate(m_dbus, connBuilder, deviceProp.path.c_str(), ssidinfo.m_persistSSIDInfo))
if(addNewConnctionAndactivate(m_dbus, connBuilder, deviceProp.path.c_str(), ssidinfo.persist))
NMLOG_INFO("wifi connect request success");
else
NMLOG_ERROR("wifi connect request failed");
Expand Down Expand Up @@ -935,7 +930,12 @@ namespace WPEFramework

bool NetworkManagerClient::startWPS()
{

return false;
}

bool NetworkManagerClient::stopWPS()
{
return false;
}

} // WPEFramework
Expand Down
3 changes: 1 addition & 2 deletions gdbus/NetworkManagerGdbusClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ namespace WPEFramework
bool getWifiState(Exchange::INetworkManager::WiFiState &state);
bool getWiFiSignalStrength(std::string& ssid, std::string& signalStrength, Exchange::INetworkManager::WiFiSignalQuality& quality);
bool startWPS();
bool stopWPS() {return false;}
bool stopWiFiScan() {return false;}
bool stopWPS();

private:
NetworkManagerClient();
Expand Down
2 changes: 1 addition & 1 deletion gdbus/NetworkManagerGdbusEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ namespace WPEFramework
while (g_variant_iter_loop(iter, "o", &apPath)) {
Exchange::INetworkManager::WiFiSSIDInfo wifiInfo;
// NMLOG_DEBUG("Access Point Path: %s", apPath);
if(GnomeUtils::getApDetails(_NetworkManagerEvents->eventDbus.getConnection(), apPath, wifiInfo))
if(GnomeUtils::getApDetails(_NetworkManagerEvents->eventDbus, apPath, wifiInfo))
{
JsonObject ssidObj;
if(GnomeUtils::convertSsidInfoToJsonObject(wifiInfo, ssidObj))
Expand Down
Loading

0 comments on commit 26daa4a

Please sign in to comment.