From d17b10fcc93407050d5d775fe1dcd0b411dc744f Mon Sep 17 00:00:00 2001 From: Erin Date: Mon, 25 Nov 2024 14:56:20 -0600 Subject: [PATCH 1/4] More robust output catching --- src/NetworkSettingsWidget.cpp | 36 +++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/NetworkSettingsWidget.cpp b/src/NetworkSettingsWidget.cpp index 26c23353..432ef910 100644 --- a/src/NetworkSettingsWidget.cpp +++ b/src/NetworkSettingsWidget.cpp @@ -340,22 +340,30 @@ void NetworkSettingsWidget::rebootBox() } void NetworkSettingsWidget::editWifiConnectionMode(int newMode) { - QProcess process; - QString command = QString("sed -i 's/^MODE.*/MODE %1/' /home/kipr/wombat-os/configFiles/wifiConnectionMode.txt").arg(newMode); - - process.start("bash", QStringList() << "-c" << command); - process.waitForFinished(); - - if (process.exitStatus() == QProcess::NormalExit) - { - qDebug() << "Successfully set MODE to:" << newMode; - } - else - { - qDebug() << "Failed to set MODE."; - } + QProcess process; + QString command = QString("sudo sed -i 's/^MODE.*/MODE %1/' /home/kipr/wombat-os/configFiles/wifiConnectionMode.txt").arg(newMode); + + // Start the process + process.start("bash", QStringList() << "-c" << command); + process.waitForFinished(); + + // Debug: Capture outputs + qDebug() << "Standard Output:" << process.readAllStandardOutput(); + qDebug() << "Error Output:" << process.readAllStandardError(); + + // Check for success + if (process.exitCode() == 0 && process.exitStatus() == QProcess::NormalExit) + { + qDebug() << "Successfully set MODE to:" << newMode; + } + else + { + qDebug() << "Failed to set MODE. Exit code:" << process.exitCode() + << "Exit status:" << process.exitStatus(); + } } + void NetworkSettingsWidget::indexChanged(int index) { NetworkManager::ref().turnOn(); From 3f6905b5cb8ed96bae97a9646e97b5e5424c7d96 Mon Sep 17 00:00:00 2001 From: Erin Date: Mon, 25 Nov 2024 14:59:39 -0600 Subject: [PATCH 2/4] Checks wifiConnectionMode.txt on bootup to determine last Network Manager state (AP, Client Mode or Off) and sets current state Added method comments --- include/botui/NetworkManager.h | 1 + src/NetworkManager.cpp | 132 +++++++++++++++++++++++++++------ 2 files changed, 112 insertions(+), 21 deletions(-) diff --git a/include/botui/NetworkManager.h b/include/botui/NetworkManager.h index ff6e6629..bb8234f6 100644 --- a/include/botui/NetworkManager.h +++ b/include/botui/NetworkManager.h @@ -51,6 +51,7 @@ class NetworkManager : public QObject, public Singleton void requestScan(); void deactivateAP(); void getRaspberryPiType(); + int getBootUpNetworkMode(); bool isOn() const; diff --git a/src/NetworkManager.cpp b/src/NetworkManager.cpp index cd694f37..ec2f0ce5 100644 --- a/src/NetworkManager.cpp +++ b/src/NetworkManager.cpp @@ -47,23 +47,26 @@ QDBusObjectPath AP_PATH; Connection DEFAULT_AP; QString RASPBERRYPI_TYPE; #ifdef WOMBAT - #define WIFI_DEVICE "wlan0" // always wlan0 for raspberry pi - #else - #define WIFI_DEVICE "wlo1" // wlo1 for dev machine - #endif +#define WIFI_DEVICE "wlan0" // always wlan0 for raspberry pi +#else +#define WIFI_DEVICE "wlo1" // wlo1 for dev machine +#endif #define AP_NAME m_dev->serial() + "-wombat" #define AP_SSID (AP_NAME).toUtf8() #define AP_PASSWORD SystemUtils::sha256(m_dev->id()).left(6) + "00" -NetworkManager::~NetworkManager() -{ -} +#define NETWORK_MANAGER_GROUP "NetworkManager" +#define ON_KEY "on" #define NM_802_11_WIRELESS_KEY ("802-11-wireless") #define NM_802_11_SECURITY_KEY ("802-11-wireless-security") +NetworkManager::~NetworkManager() +{ +} + OrgFreedesktopNetworkManagerInterface *NetworkManager::networkManagerInterface() { static OrgFreedesktopNetworkManagerInterface nmInterface( @@ -74,6 +77,7 @@ OrgFreedesktopNetworkManagerInterface *NetworkManager::networkManagerInterface() return &nmInterface; } +// Adds a new connection to the NetworkManager void NetworkManager::addNetwork(const Network &network) { // Yes, yes... this is a hard coded mess. @@ -149,6 +153,7 @@ void NetworkManager::addNetwork(const Network &network) emit networkAdded(network); } +// Forgets the given network void NetworkManager::forgetNetwork(const Network &network) { Q_FOREACH (const QDBusObjectPath &connectionPath, getAllConnectionPaths()) @@ -173,11 +178,13 @@ void NetworkManager::forgetNetwork(const Network &network) emit networkForgotten(network); } +// Get the name of the AP connection QString NetworkManager::getAPName() { return AP_NAME; } +// Returns list of all networks NetworkList NetworkManager::networks() const { NetworkList networks; @@ -190,6 +197,7 @@ NetworkList NetworkManager::networks() const return networks; } +// Scans for available networks void NetworkManager::requestScan() { if (!m_wifi) @@ -202,9 +210,8 @@ void NetworkManager::requestScan() qWarning() << "NetworkManager::requestScan" << reply.error().message(); } -#define NETWORK_MANAGER_GROUP "NetworkManager" -#define ON_KEY "on" +// Turns on the network manager bool NetworkManager::turnOn() { m_nm->Enable(true); @@ -215,6 +222,7 @@ bool NetworkManager::turnOn() return true; // TODO: This is a bad assumption } +// Turns off the network manager void NetworkManager::turnOff() { m_nm->Enable(false); @@ -224,6 +232,7 @@ void NetworkManager::turnOff() settings.endGroup(); } +// Returns the AP connection configuration QString NetworkManager::getAPConnectionConfig() { QString command = QString("cat /etc/NetworkManager/system-connections/%1.nmconnection").arg(AP_NAME); @@ -236,6 +245,7 @@ QString NetworkManager::getAPConnectionConfig() return QString(output).trimmed(); } +// Changes the WiFi band and channel void NetworkManager::changeWifiBands(QString band, int channel) { @@ -262,6 +272,8 @@ void NetworkManager::changeWifiBands(QString band, int channel) QList activeConnections = nm.activeConnections(); QDBusObjectPath correctConnectionPath; + + // Loop through active connection paths to find the correct one foreach (const QDBusObjectPath &activeConnectionPath, activeConnections) { OrgFreedesktopNetworkManagerConnectionActiveInterface activeConn(NM_SERVICE, activeConnectionPath.path(), QDBusConnection::systemBus()); @@ -275,6 +287,7 @@ void NetworkManager::changeWifiBands(QString band, int channel) qDebug() << "Correct connection ssid " << connectionSettings[NM_802_11_WIRELESS_KEY]["ssid"].toString(); QPair correctConnectionPair = getConnection(connectionSettings[NM_802_11_WIRELESS_KEY]["ssid"].toString()); + // Activate found connection QDBusPendingReply reply = m_nm->ActivateConnection(correctConnectionPair.second, devicePath, QDBusObjectPath("/")); reply.waitForFinished(); getReply(reply); @@ -305,6 +318,7 @@ void NetworkManager::changeWifiBands(QString band, int channel) emit stateChangedBandBouncer(oldBand, newBand, oldChannel, newChannel); }); } +// Enables AP connection bool NetworkManager::enableAP() { @@ -323,27 +337,22 @@ bool NetworkManager::enableAP() qDebug() << "AP Path: " << apPath.path(); qDebug() << "AP Path Connection already exists"; qDebug() << "AP Strength: " << active().strength(); - qDebug() << "State: " << m_device->state(); OrgFreedesktopNetworkManagerSettingsConnectionInterface connection(NM_SERVICE, apPath.path(), QDBusConnection::systemBus()); Connection settings = connection.GetSettings().value(); QMap wirelessSettings = settings.value("802-11-wireless"); - qDebug() << "Settings before anything: " << settings; bool containsBand = wirelessSettings.contains("band"); bool containsChannel = wirelessSettings.contains("channel"); - qDebug() << "AP settings: " << settings; - qDebug() << "Contains band? : " << containsBand; - qDebug() << "Contains channel? : " << containsChannel; - - // Check if the settings contain "band" and "channel" + // Check if the current settings contain "band" and "channel" if (!containsBand || !containsChannel) { qDebug() << "Missing 'band' or 'channel' in AP settings. Recreating AP configuration."; bool activeConnectionOn = NetworkManager::ref().isActiveConnectionOn(); + // If there is a current connection active, deactivate it if (activeConnectionOn == true) { qDebug() << "Current active connection: " << m_device->activeConnection().path(); @@ -361,6 +370,7 @@ bool NetworkManager::enableAP() } } + // Assign the default band and channel based on the Raspberry Pi type if (RASPBERRYPI_TYPE == "3B+") { settings[NM_802_11_WIRELESS_KEY]["band"] = "a"; @@ -374,6 +384,7 @@ bool NetworkManager::enableAP() qDebug() << "Modified AP settings: band and channel added."; + // Update the connection settings QDBusPendingReply reply = connection.Update(settings); reply.waitForFinished(); @@ -389,6 +400,7 @@ bool NetworkManager::enableAP() qDebug() << "Connection after update: " << connection.GetSettings().value(); } + // Activate updated connection QDBusPendingReply activateReply = m_nm->ActivateConnection(apPath, devicePath, QDBusObjectPath("/")); activateReply.waitForFinished(); @@ -401,7 +413,7 @@ bool NetworkManager::enableAP() { qDebug() << "Connection activated successfully."; } - + qDebug() << "Device is now active. Proceeding to reapply settings."; QDBusPendingReply reapplyReply = m_device->Reapply(settings, 0, 0); @@ -426,14 +438,16 @@ bool NetworkManager::enableAP() } else if (NetworkManager::ref().isActiveConnectionOn() == false) { - + turnOn(); uint stateReply; while (true) { stateReply = m_device->state(); - if (stateReply == 30) + if (stateReply == 30)NetworkManager::~NetworkManager() +{ +} { qDebug() << "Reached Disconnected state"; break; @@ -456,6 +470,7 @@ bool NetworkManager::enableAP() return true; } +// Returns AP settings object path QDBusObjectPath NetworkManager::getAPSettingsObjectPath() const { QDBusObjectPath settingsPath = getConnection(AP_NAME).second; @@ -463,6 +478,7 @@ QDBusObjectPath NetworkManager::getAPSettingsObjectPath() const return settingsPath; } +// Turns off the AP connection void NetworkManager::deactivateAP() { qDebug() << "inside deactivateAP()"; @@ -473,6 +489,7 @@ void NetworkManager::deactivateAP() m_nm->DeactivateConnection(activePath); } +// Deletes the AP connection bool NetworkManager::disableAP() { foreach (const QDBusObjectPath &settingPath, getAllConnectionPaths()) @@ -493,7 +510,8 @@ bool NetworkManager::disableAP() return true; } -Connection NetworkManager::createAPConfig() const // Creates a default AP_SSID configuration for settings +// Creates a default AP_SSID configuration for settings +Connection NetworkManager::createAPConfig() const { qDebug() << "Creating AP Config..."; @@ -517,6 +535,7 @@ Connection NetworkManager::createAPConfig() const // Creates a default AP_SSID c DEFAULT_AP["ipv4"]["method"] = "shared"; DEFAULT_AP["ipv6"]["method"] = "auto"; + // Assign the default band and channel based on the Raspberry Pi type if (RASPBERRYPI_TYPE == "3B+") { DEFAULT_AP[NM_802_11_WIRELESS_KEY]["band"] = "a"; @@ -535,6 +554,7 @@ Connection NetworkManager::createAPConfig() const // Creates a default AP_SSID c QDBusObjectPath defaultPath = settings.AddConnection(DEFAULT_AP); qDebug() << "settings.AddConnection(DEFAULT_AP): " << defaultPath.path(); + // Hardcode WiFi IP address QString str = tr("nmcli connection modify %1 ipv4.address 192.168.125.1/24").arg(AP_NAME); QByteArray ba = str.toLocal8Bit(); const char *csys = ba.data(); @@ -543,11 +563,13 @@ Connection NetworkManager::createAPConfig() const // Creates a default AP_SSID c return DEFAULT_AP; } +// Returns if the network manager is on bool NetworkManager::isOn() const { return m_nm->networkingEnabled(); } +// Returns if the network manager is persistent bool NetworkManager::isPersistentOn() const { QSettings settings; @@ -557,11 +579,13 @@ bool NetworkManager::isPersistentOn() const return ret; } +// Returns the current state of the network manager NetworkManager::State NetworkManager::state() const { return (NetworkManager::State)m_device->state(); } + Network NetworkManager::active() const { if (!m_wifi) @@ -569,6 +593,7 @@ Network NetworkManager::active() const return createAccessPoint(m_wifi->activeAccessPoint()); } +// Returns active connection password QString NetworkManager::activeConnectionPassword() const { if (!isActiveConnectionOn()) @@ -578,6 +603,7 @@ QString NetworkManager::activeConnectionPassword() const return getPassword(active().ssid()); } +// Returns if the active connection is on bool NetworkManager::isActiveConnectionOn() const { bool activeConnOn; @@ -592,6 +618,7 @@ bool NetworkManager::isActiveConnectionOn() const return activeConnOn; } +// Returns the current active connection name QString NetworkManager::currentActiveConnectionName() const { QDBusObjectPath activePath = m_device->activeConnection(); // Device's current active connection @@ -604,6 +631,7 @@ QString NetworkManager::currentActiveConnectionName() const return activeConnObj.id(); } +// Returns NetworkList of all access points NetworkList NetworkManager::accessPoints() const { if (!m_wifi) @@ -634,6 +662,7 @@ NetworkList NetworkManager::accessPoints() const return networks; } +// Returns network IP address QString NetworkManager::ipAddress() const { int fd = socket(AF_INET, SOCK_DGRAM, 0); @@ -649,6 +678,7 @@ QString NetworkManager::ipAddress() const return ret; } +// Returns if event mode is on or off bool NetworkManager::eventModeState() { QProcess eventModeProcess; @@ -677,6 +707,7 @@ bool NetworkManager::eventModeState() } } +// Returns the network's IPv4 address QString NetworkManager::ip4Address() const { QString ipAddr; @@ -694,15 +725,31 @@ QString NetworkManager::ip4Address() const return ipAddr; } +// Initilization function void NetworkManager::init(const Device *device) { + qDebug() << "Init"; m_dev = device; bool checkEventState = eventModeState(); + int checkNetworkMode = getBootUpNetworkMode(); - if (!checkEventState) // Event Mode enabled + if (!checkEventState && (checkNetworkMode != 1 && checkNetworkMode != 2)) // Event Mode enabled { + enableAP(); } + else if (checkNetworkMode == 1) // Client Mode + { + + if(currentActiveConnectionName() == AP_NAME) + { + disableAP(); + } + } + else if (checkNetworkMode == 2) //Wifi off + { + turnOff(); + } } NetworkManager::NetworkManager() @@ -774,9 +821,43 @@ NetworkManager::NetworkManager() turnOn(); requestScan(); + qDebug() << "Active strength: " << active().strength(); + +} + +// Returns the network mode on boot up +int NetworkManager::getBootUpNetworkMode() +{ + QProcess networkModeProcess; + QString command = "grep '^MODE' /home/kipr/wombat-os/configFiles/wifiConnectionMode.txt | awk '{print $2}'"; + + networkModeProcess.start("bash", QStringList() << "-c" << command); + networkModeProcess.waitForFinished(); + + QString output = networkModeProcess.readAllStandardOutput().trimmed(); + qDebug() << "getBootUpNetworkMode: " << output.toInt(); + if (!output.isEmpty()) + { + switch (output.toInt()) + { + case 0: // AP Mode + return 0; + case 1: // Client Mode + return 1; + case 2: // Wifi Off + return 2; + default: + qDebug() << "Unknown MODE."; + } + } + else + { + qDebug() << "Failed to read MODE."; + } } +// Returns the Raspberry Pi type inside Wombat void NetworkManager::getRaspberryPiType() { QStringList arguments; @@ -804,6 +885,7 @@ void NetworkManager::getRaspberryPiType() qDebug() << "RASPBERRYPI_TYPE: " << RASPBERRYPI_TYPE; } +// NetworkManager AP added signal void NetworkManager::nmAccessPointAdded(const QDBusObjectPath &accessPoint) { Network network = createAccessPoint(accessPoint); @@ -812,6 +894,7 @@ void NetworkManager::nmAccessPointAdded(const QDBusObjectPath &accessPoint) emit accessPointAdded(network); } +// NetworkManager AP removed signal void NetworkManager::nmAccessPointRemoved(const QDBusObjectPath &accessPoint) { Network network = createAccessPoint(accessPoint); @@ -820,6 +903,7 @@ void NetworkManager::nmAccessPointRemoved(const QDBusObjectPath &accessPoint) m_accessPoints.removeAll(network); } +// Signal for when the network state changes void NetworkManager::stateChangedBouncer(uint newState, uint oldState) { NetworkManager::State networkStateNew = (NetworkManager::State)newState; @@ -827,6 +911,7 @@ void NetworkManager::stateChangedBouncer(uint newState, uint oldState) emit stateChanged(networkStateNew, networkStateOld); } +// Returns Network config from connection Network NetworkManager::networkFromConnection(const Connection &connection) const { // TODO: It would be nice to make this static somewhere @@ -855,6 +940,7 @@ Network NetworkManager::networkFromConnection(const Connection &connection) cons return network; } +// Creates a network from an access point Network NetworkManager::createAccessPoint(const QDBusObjectPath &accessPoint) const { OrgFreedesktopNetworkManagerAccessPointInterface accessPointObject( @@ -931,6 +1017,7 @@ Network NetworkManager::createAccessPoint(const QDBusObjectPath &accessPoint) co return newNetwork; } +// Returns a list of all connections QList NetworkManager::getAllConnectionPaths() const { // initialize settings provider to get all dbus path connections @@ -962,6 +1049,7 @@ NetworkManager::getAllConnections() const return ret; } +// Returns the connection and path for a given ssid QPair NetworkManager::getConnection(QString ssid) const { @@ -982,6 +1070,7 @@ NetworkManager::getConnection(QString ssid) const return qMakePair(Connection(), QDBusObjectPath()); } +// Returns the password for a given ssid QString NetworkManager::getPassword(QString ssid) const { // get connection and path @@ -1010,6 +1099,7 @@ QString NetworkManager::getPassword(QString ssid) const } } +// Returns the reply from a given query void NetworkManager::getReply(QDBusPendingReply<> &reply, const QString where, const bool throwError) const { reply.waitForFinished(); From a653d9b572d0013062b2d8611818c172f142c6a2 Mon Sep 17 00:00:00 2001 From: Erin Date: Mon, 25 Nov 2024 15:20:31 -0600 Subject: [PATCH 3/4] Fixed bug --- src/NetworkManager.cpp | 132 +++++++---------------------------------- 1 file changed, 21 insertions(+), 111 deletions(-) diff --git a/src/NetworkManager.cpp b/src/NetworkManager.cpp index ec2f0ce5..cd694f37 100644 --- a/src/NetworkManager.cpp +++ b/src/NetworkManager.cpp @@ -47,26 +47,23 @@ QDBusObjectPath AP_PATH; Connection DEFAULT_AP; QString RASPBERRYPI_TYPE; #ifdef WOMBAT -#define WIFI_DEVICE "wlan0" // always wlan0 for raspberry pi -#else -#define WIFI_DEVICE "wlo1" // wlo1 for dev machine -#endif + #define WIFI_DEVICE "wlan0" // always wlan0 for raspberry pi + #else + #define WIFI_DEVICE "wlo1" // wlo1 for dev machine + #endif #define AP_NAME m_dev->serial() + "-wombat" #define AP_SSID (AP_NAME).toUtf8() #define AP_PASSWORD SystemUtils::sha256(m_dev->id()).left(6) + "00" -#define NETWORK_MANAGER_GROUP "NetworkManager" -#define ON_KEY "on" - -#define NM_802_11_WIRELESS_KEY ("802-11-wireless") -#define NM_802_11_SECURITY_KEY ("802-11-wireless-security") - NetworkManager::~NetworkManager() { } +#define NM_802_11_WIRELESS_KEY ("802-11-wireless") +#define NM_802_11_SECURITY_KEY ("802-11-wireless-security") + OrgFreedesktopNetworkManagerInterface *NetworkManager::networkManagerInterface() { static OrgFreedesktopNetworkManagerInterface nmInterface( @@ -77,7 +74,6 @@ OrgFreedesktopNetworkManagerInterface *NetworkManager::networkManagerInterface() return &nmInterface; } -// Adds a new connection to the NetworkManager void NetworkManager::addNetwork(const Network &network) { // Yes, yes... this is a hard coded mess. @@ -153,7 +149,6 @@ void NetworkManager::addNetwork(const Network &network) emit networkAdded(network); } -// Forgets the given network void NetworkManager::forgetNetwork(const Network &network) { Q_FOREACH (const QDBusObjectPath &connectionPath, getAllConnectionPaths()) @@ -178,13 +173,11 @@ void NetworkManager::forgetNetwork(const Network &network) emit networkForgotten(network); } -// Get the name of the AP connection QString NetworkManager::getAPName() { return AP_NAME; } -// Returns list of all networks NetworkList NetworkManager::networks() const { NetworkList networks; @@ -197,7 +190,6 @@ NetworkList NetworkManager::networks() const return networks; } -// Scans for available networks void NetworkManager::requestScan() { if (!m_wifi) @@ -210,8 +202,9 @@ void NetworkManager::requestScan() qWarning() << "NetworkManager::requestScan" << reply.error().message(); } +#define NETWORK_MANAGER_GROUP "NetworkManager" +#define ON_KEY "on" -// Turns on the network manager bool NetworkManager::turnOn() { m_nm->Enable(true); @@ -222,7 +215,6 @@ bool NetworkManager::turnOn() return true; // TODO: This is a bad assumption } -// Turns off the network manager void NetworkManager::turnOff() { m_nm->Enable(false); @@ -232,7 +224,6 @@ void NetworkManager::turnOff() settings.endGroup(); } -// Returns the AP connection configuration QString NetworkManager::getAPConnectionConfig() { QString command = QString("cat /etc/NetworkManager/system-connections/%1.nmconnection").arg(AP_NAME); @@ -245,7 +236,6 @@ QString NetworkManager::getAPConnectionConfig() return QString(output).trimmed(); } -// Changes the WiFi band and channel void NetworkManager::changeWifiBands(QString band, int channel) { @@ -272,8 +262,6 @@ void NetworkManager::changeWifiBands(QString band, int channel) QList activeConnections = nm.activeConnections(); QDBusObjectPath correctConnectionPath; - - // Loop through active connection paths to find the correct one foreach (const QDBusObjectPath &activeConnectionPath, activeConnections) { OrgFreedesktopNetworkManagerConnectionActiveInterface activeConn(NM_SERVICE, activeConnectionPath.path(), QDBusConnection::systemBus()); @@ -287,7 +275,6 @@ void NetworkManager::changeWifiBands(QString band, int channel) qDebug() << "Correct connection ssid " << connectionSettings[NM_802_11_WIRELESS_KEY]["ssid"].toString(); QPair correctConnectionPair = getConnection(connectionSettings[NM_802_11_WIRELESS_KEY]["ssid"].toString()); - // Activate found connection QDBusPendingReply reply = m_nm->ActivateConnection(correctConnectionPair.second, devicePath, QDBusObjectPath("/")); reply.waitForFinished(); getReply(reply); @@ -318,7 +305,6 @@ void NetworkManager::changeWifiBands(QString band, int channel) emit stateChangedBandBouncer(oldBand, newBand, oldChannel, newChannel); }); } -// Enables AP connection bool NetworkManager::enableAP() { @@ -337,22 +323,27 @@ bool NetworkManager::enableAP() qDebug() << "AP Path: " << apPath.path(); qDebug() << "AP Path Connection already exists"; qDebug() << "AP Strength: " << active().strength(); + qDebug() << "State: " << m_device->state(); OrgFreedesktopNetworkManagerSettingsConnectionInterface connection(NM_SERVICE, apPath.path(), QDBusConnection::systemBus()); Connection settings = connection.GetSettings().value(); QMap wirelessSettings = settings.value("802-11-wireless"); + qDebug() << "Settings before anything: " << settings; bool containsBand = wirelessSettings.contains("band"); bool containsChannel = wirelessSettings.contains("channel"); - // Check if the current settings contain "band" and "channel" + qDebug() << "AP settings: " << settings; + qDebug() << "Contains band? : " << containsBand; + qDebug() << "Contains channel? : " << containsChannel; + + // Check if the settings contain "band" and "channel" if (!containsBand || !containsChannel) { qDebug() << "Missing 'band' or 'channel' in AP settings. Recreating AP configuration."; bool activeConnectionOn = NetworkManager::ref().isActiveConnectionOn(); - // If there is a current connection active, deactivate it if (activeConnectionOn == true) { qDebug() << "Current active connection: " << m_device->activeConnection().path(); @@ -370,7 +361,6 @@ bool NetworkManager::enableAP() } } - // Assign the default band and channel based on the Raspberry Pi type if (RASPBERRYPI_TYPE == "3B+") { settings[NM_802_11_WIRELESS_KEY]["band"] = "a"; @@ -384,7 +374,6 @@ bool NetworkManager::enableAP() qDebug() << "Modified AP settings: band and channel added."; - // Update the connection settings QDBusPendingReply reply = connection.Update(settings); reply.waitForFinished(); @@ -400,7 +389,6 @@ bool NetworkManager::enableAP() qDebug() << "Connection after update: " << connection.GetSettings().value(); } - // Activate updated connection QDBusPendingReply activateReply = m_nm->ActivateConnection(apPath, devicePath, QDBusObjectPath("/")); activateReply.waitForFinished(); @@ -413,7 +401,7 @@ bool NetworkManager::enableAP() { qDebug() << "Connection activated successfully."; } - + qDebug() << "Device is now active. Proceeding to reapply settings."; QDBusPendingReply reapplyReply = m_device->Reapply(settings, 0, 0); @@ -438,16 +426,14 @@ bool NetworkManager::enableAP() } else if (NetworkManager::ref().isActiveConnectionOn() == false) { - + turnOn(); uint stateReply; while (true) { stateReply = m_device->state(); - if (stateReply == 30)NetworkManager::~NetworkManager() -{ -} + if (stateReply == 30) { qDebug() << "Reached Disconnected state"; break; @@ -470,7 +456,6 @@ bool NetworkManager::enableAP() return true; } -// Returns AP settings object path QDBusObjectPath NetworkManager::getAPSettingsObjectPath() const { QDBusObjectPath settingsPath = getConnection(AP_NAME).second; @@ -478,7 +463,6 @@ QDBusObjectPath NetworkManager::getAPSettingsObjectPath() const return settingsPath; } -// Turns off the AP connection void NetworkManager::deactivateAP() { qDebug() << "inside deactivateAP()"; @@ -489,7 +473,6 @@ void NetworkManager::deactivateAP() m_nm->DeactivateConnection(activePath); } -// Deletes the AP connection bool NetworkManager::disableAP() { foreach (const QDBusObjectPath &settingPath, getAllConnectionPaths()) @@ -510,8 +493,7 @@ bool NetworkManager::disableAP() return true; } -// Creates a default AP_SSID configuration for settings -Connection NetworkManager::createAPConfig() const +Connection NetworkManager::createAPConfig() const // Creates a default AP_SSID configuration for settings { qDebug() << "Creating AP Config..."; @@ -535,7 +517,6 @@ Connection NetworkManager::createAPConfig() const DEFAULT_AP["ipv4"]["method"] = "shared"; DEFAULT_AP["ipv6"]["method"] = "auto"; - // Assign the default band and channel based on the Raspberry Pi type if (RASPBERRYPI_TYPE == "3B+") { DEFAULT_AP[NM_802_11_WIRELESS_KEY]["band"] = "a"; @@ -554,7 +535,6 @@ Connection NetworkManager::createAPConfig() const QDBusObjectPath defaultPath = settings.AddConnection(DEFAULT_AP); qDebug() << "settings.AddConnection(DEFAULT_AP): " << defaultPath.path(); - // Hardcode WiFi IP address QString str = tr("nmcli connection modify %1 ipv4.address 192.168.125.1/24").arg(AP_NAME); QByteArray ba = str.toLocal8Bit(); const char *csys = ba.data(); @@ -563,13 +543,11 @@ Connection NetworkManager::createAPConfig() const return DEFAULT_AP; } -// Returns if the network manager is on bool NetworkManager::isOn() const { return m_nm->networkingEnabled(); } -// Returns if the network manager is persistent bool NetworkManager::isPersistentOn() const { QSettings settings; @@ -579,13 +557,11 @@ bool NetworkManager::isPersistentOn() const return ret; } -// Returns the current state of the network manager NetworkManager::State NetworkManager::state() const { return (NetworkManager::State)m_device->state(); } - Network NetworkManager::active() const { if (!m_wifi) @@ -593,7 +569,6 @@ Network NetworkManager::active() const return createAccessPoint(m_wifi->activeAccessPoint()); } -// Returns active connection password QString NetworkManager::activeConnectionPassword() const { if (!isActiveConnectionOn()) @@ -603,7 +578,6 @@ QString NetworkManager::activeConnectionPassword() const return getPassword(active().ssid()); } -// Returns if the active connection is on bool NetworkManager::isActiveConnectionOn() const { bool activeConnOn; @@ -618,7 +592,6 @@ bool NetworkManager::isActiveConnectionOn() const return activeConnOn; } -// Returns the current active connection name QString NetworkManager::currentActiveConnectionName() const { QDBusObjectPath activePath = m_device->activeConnection(); // Device's current active connection @@ -631,7 +604,6 @@ QString NetworkManager::currentActiveConnectionName() const return activeConnObj.id(); } -// Returns NetworkList of all access points NetworkList NetworkManager::accessPoints() const { if (!m_wifi) @@ -662,7 +634,6 @@ NetworkList NetworkManager::accessPoints() const return networks; } -// Returns network IP address QString NetworkManager::ipAddress() const { int fd = socket(AF_INET, SOCK_DGRAM, 0); @@ -678,7 +649,6 @@ QString NetworkManager::ipAddress() const return ret; } -// Returns if event mode is on or off bool NetworkManager::eventModeState() { QProcess eventModeProcess; @@ -707,7 +677,6 @@ bool NetworkManager::eventModeState() } } -// Returns the network's IPv4 address QString NetworkManager::ip4Address() const { QString ipAddr; @@ -725,31 +694,15 @@ QString NetworkManager::ip4Address() const return ipAddr; } -// Initilization function void NetworkManager::init(const Device *device) { - qDebug() << "Init"; m_dev = device; bool checkEventState = eventModeState(); - int checkNetworkMode = getBootUpNetworkMode(); - if (!checkEventState && (checkNetworkMode != 1 && checkNetworkMode != 2)) // Event Mode enabled + if (!checkEventState) // Event Mode enabled { - enableAP(); } - else if (checkNetworkMode == 1) // Client Mode - { - - if(currentActiveConnectionName() == AP_NAME) - { - disableAP(); - } - } - else if (checkNetworkMode == 2) //Wifi off - { - turnOff(); - } } NetworkManager::NetworkManager() @@ -821,43 +774,9 @@ NetworkManager::NetworkManager() turnOn(); requestScan(); - qDebug() << "Active strength: " << active().strength(); - -} - -// Returns the network mode on boot up -int NetworkManager::getBootUpNetworkMode() -{ - QProcess networkModeProcess; - QString command = "grep '^MODE' /home/kipr/wombat-os/configFiles/wifiConnectionMode.txt | awk '{print $2}'"; - - networkModeProcess.start("bash", QStringList() << "-c" << command); - networkModeProcess.waitForFinished(); - - QString output = networkModeProcess.readAllStandardOutput().trimmed(); - qDebug() << "getBootUpNetworkMode: " << output.toInt(); - if (!output.isEmpty()) - { - switch (output.toInt()) - { - case 0: // AP Mode - return 0; - case 1: // Client Mode - return 1; - case 2: // Wifi Off - return 2; - default: - qDebug() << "Unknown MODE."; - } - } - else - { - qDebug() << "Failed to read MODE."; - } } -// Returns the Raspberry Pi type inside Wombat void NetworkManager::getRaspberryPiType() { QStringList arguments; @@ -885,7 +804,6 @@ void NetworkManager::getRaspberryPiType() qDebug() << "RASPBERRYPI_TYPE: " << RASPBERRYPI_TYPE; } -// NetworkManager AP added signal void NetworkManager::nmAccessPointAdded(const QDBusObjectPath &accessPoint) { Network network = createAccessPoint(accessPoint); @@ -894,7 +812,6 @@ void NetworkManager::nmAccessPointAdded(const QDBusObjectPath &accessPoint) emit accessPointAdded(network); } -// NetworkManager AP removed signal void NetworkManager::nmAccessPointRemoved(const QDBusObjectPath &accessPoint) { Network network = createAccessPoint(accessPoint); @@ -903,7 +820,6 @@ void NetworkManager::nmAccessPointRemoved(const QDBusObjectPath &accessPoint) m_accessPoints.removeAll(network); } -// Signal for when the network state changes void NetworkManager::stateChangedBouncer(uint newState, uint oldState) { NetworkManager::State networkStateNew = (NetworkManager::State)newState; @@ -911,7 +827,6 @@ void NetworkManager::stateChangedBouncer(uint newState, uint oldState) emit stateChanged(networkStateNew, networkStateOld); } -// Returns Network config from connection Network NetworkManager::networkFromConnection(const Connection &connection) const { // TODO: It would be nice to make this static somewhere @@ -940,7 +855,6 @@ Network NetworkManager::networkFromConnection(const Connection &connection) cons return network; } -// Creates a network from an access point Network NetworkManager::createAccessPoint(const QDBusObjectPath &accessPoint) const { OrgFreedesktopNetworkManagerAccessPointInterface accessPointObject( @@ -1017,7 +931,6 @@ Network NetworkManager::createAccessPoint(const QDBusObjectPath &accessPoint) co return newNetwork; } -// Returns a list of all connections QList NetworkManager::getAllConnectionPaths() const { // initialize settings provider to get all dbus path connections @@ -1049,7 +962,6 @@ NetworkManager::getAllConnections() const return ret; } -// Returns the connection and path for a given ssid QPair NetworkManager::getConnection(QString ssid) const { @@ -1070,7 +982,6 @@ NetworkManager::getConnection(QString ssid) const return qMakePair(Connection(), QDBusObjectPath()); } -// Returns the password for a given ssid QString NetworkManager::getPassword(QString ssid) const { // get connection and path @@ -1099,7 +1010,6 @@ QString NetworkManager::getPassword(QString ssid) const } } -// Returns the reply from a given query void NetworkManager::getReply(QDBusPendingReply<> &reply, const QString where, const bool throwError) const { reply.waitForFinished(); From de5a76f5ffcac16f3163fc346b1a144b63ce0289 Mon Sep 17 00:00:00 2001 From: Erin Date: Mon, 25 Nov 2024 15:32:26 -0600 Subject: [PATCH 4/4] Removal of accidental paste --- src/NetworkManager.cpp | 128 ++++++++++++++++++++++++++++++++++------- 1 file changed, 108 insertions(+), 20 deletions(-) diff --git a/src/NetworkManager.cpp b/src/NetworkManager.cpp index cd694f37..8cdcdf13 100644 --- a/src/NetworkManager.cpp +++ b/src/NetworkManager.cpp @@ -47,23 +47,26 @@ QDBusObjectPath AP_PATH; Connection DEFAULT_AP; QString RASPBERRYPI_TYPE; #ifdef WOMBAT - #define WIFI_DEVICE "wlan0" // always wlan0 for raspberry pi - #else - #define WIFI_DEVICE "wlo1" // wlo1 for dev machine - #endif +#define WIFI_DEVICE "wlan0" // always wlan0 for raspberry pi +#else +#define WIFI_DEVICE "wlo1" // wlo1 for dev machine +#endif #define AP_NAME m_dev->serial() + "-wombat" #define AP_SSID (AP_NAME).toUtf8() #define AP_PASSWORD SystemUtils::sha256(m_dev->id()).left(6) + "00" -NetworkManager::~NetworkManager() -{ -} +#define NETWORK_MANAGER_GROUP "NetworkManager" +#define ON_KEY "on" #define NM_802_11_WIRELESS_KEY ("802-11-wireless") #define NM_802_11_SECURITY_KEY ("802-11-wireless-security") +NetworkManager::~NetworkManager() +{ +} + OrgFreedesktopNetworkManagerInterface *NetworkManager::networkManagerInterface() { static OrgFreedesktopNetworkManagerInterface nmInterface( @@ -74,6 +77,7 @@ OrgFreedesktopNetworkManagerInterface *NetworkManager::networkManagerInterface() return &nmInterface; } +// Adds a new connection to the NetworkManager void NetworkManager::addNetwork(const Network &network) { // Yes, yes... this is a hard coded mess. @@ -149,6 +153,7 @@ void NetworkManager::addNetwork(const Network &network) emit networkAdded(network); } +// Forgets the given network void NetworkManager::forgetNetwork(const Network &network) { Q_FOREACH (const QDBusObjectPath &connectionPath, getAllConnectionPaths()) @@ -173,11 +178,13 @@ void NetworkManager::forgetNetwork(const Network &network) emit networkForgotten(network); } +// Get the name of the AP connection QString NetworkManager::getAPName() { return AP_NAME; } +// Returns list of all networks NetworkList NetworkManager::networks() const { NetworkList networks; @@ -190,6 +197,7 @@ NetworkList NetworkManager::networks() const return networks; } +// Scans for available networks void NetworkManager::requestScan() { if (!m_wifi) @@ -202,9 +210,8 @@ void NetworkManager::requestScan() qWarning() << "NetworkManager::requestScan" << reply.error().message(); } -#define NETWORK_MANAGER_GROUP "NetworkManager" -#define ON_KEY "on" +// Turns on the network manager bool NetworkManager::turnOn() { m_nm->Enable(true); @@ -215,6 +222,7 @@ bool NetworkManager::turnOn() return true; // TODO: This is a bad assumption } +// Turns off the network manager void NetworkManager::turnOff() { m_nm->Enable(false); @@ -224,6 +232,7 @@ void NetworkManager::turnOff() settings.endGroup(); } +// Returns the AP connection configuration QString NetworkManager::getAPConnectionConfig() { QString command = QString("cat /etc/NetworkManager/system-connections/%1.nmconnection").arg(AP_NAME); @@ -236,6 +245,7 @@ QString NetworkManager::getAPConnectionConfig() return QString(output).trimmed(); } +// Changes the WiFi band and channel void NetworkManager::changeWifiBands(QString band, int channel) { @@ -262,6 +272,8 @@ void NetworkManager::changeWifiBands(QString band, int channel) QList activeConnections = nm.activeConnections(); QDBusObjectPath correctConnectionPath; + + // Loop through active connection paths to find the correct one foreach (const QDBusObjectPath &activeConnectionPath, activeConnections) { OrgFreedesktopNetworkManagerConnectionActiveInterface activeConn(NM_SERVICE, activeConnectionPath.path(), QDBusConnection::systemBus()); @@ -275,6 +287,7 @@ void NetworkManager::changeWifiBands(QString band, int channel) qDebug() << "Correct connection ssid " << connectionSettings[NM_802_11_WIRELESS_KEY]["ssid"].toString(); QPair correctConnectionPair = getConnection(connectionSettings[NM_802_11_WIRELESS_KEY]["ssid"].toString()); + // Activate found connection QDBusPendingReply reply = m_nm->ActivateConnection(correctConnectionPair.second, devicePath, QDBusObjectPath("/")); reply.waitForFinished(); getReply(reply); @@ -305,6 +318,7 @@ void NetworkManager::changeWifiBands(QString band, int channel) emit stateChangedBandBouncer(oldBand, newBand, oldChannel, newChannel); }); } +// Enables AP connection bool NetworkManager::enableAP() { @@ -323,27 +337,22 @@ bool NetworkManager::enableAP() qDebug() << "AP Path: " << apPath.path(); qDebug() << "AP Path Connection already exists"; qDebug() << "AP Strength: " << active().strength(); - qDebug() << "State: " << m_device->state(); OrgFreedesktopNetworkManagerSettingsConnectionInterface connection(NM_SERVICE, apPath.path(), QDBusConnection::systemBus()); Connection settings = connection.GetSettings().value(); QMap wirelessSettings = settings.value("802-11-wireless"); - qDebug() << "Settings before anything: " << settings; bool containsBand = wirelessSettings.contains("band"); bool containsChannel = wirelessSettings.contains("channel"); - qDebug() << "AP settings: " << settings; - qDebug() << "Contains band? : " << containsBand; - qDebug() << "Contains channel? : " << containsChannel; - - // Check if the settings contain "band" and "channel" + // Check if the current settings contain "band" and "channel" if (!containsBand || !containsChannel) { qDebug() << "Missing 'band' or 'channel' in AP settings. Recreating AP configuration."; bool activeConnectionOn = NetworkManager::ref().isActiveConnectionOn(); + // If there is a current connection active, deactivate it if (activeConnectionOn == true) { qDebug() << "Current active connection: " << m_device->activeConnection().path(); @@ -361,6 +370,7 @@ bool NetworkManager::enableAP() } } + // Assign the default band and channel based on the Raspberry Pi type if (RASPBERRYPI_TYPE == "3B+") { settings[NM_802_11_WIRELESS_KEY]["band"] = "a"; @@ -374,6 +384,7 @@ bool NetworkManager::enableAP() qDebug() << "Modified AP settings: band and channel added."; + // Update the connection settings QDBusPendingReply reply = connection.Update(settings); reply.waitForFinished(); @@ -389,6 +400,7 @@ bool NetworkManager::enableAP() qDebug() << "Connection after update: " << connection.GetSettings().value(); } + // Activate updated connection QDBusPendingReply activateReply = m_nm->ActivateConnection(apPath, devicePath, QDBusObjectPath("/")); activateReply.waitForFinished(); @@ -401,7 +413,7 @@ bool NetworkManager::enableAP() { qDebug() << "Connection activated successfully."; } - + qDebug() << "Device is now active. Proceeding to reapply settings."; QDBusPendingReply reapplyReply = m_device->Reapply(settings, 0, 0); @@ -426,7 +438,7 @@ bool NetworkManager::enableAP() } else if (NetworkManager::ref().isActiveConnectionOn() == false) { - + turnOn(); uint stateReply; while (true) @@ -456,6 +468,7 @@ bool NetworkManager::enableAP() return true; } +// Returns AP settings object path QDBusObjectPath NetworkManager::getAPSettingsObjectPath() const { QDBusObjectPath settingsPath = getConnection(AP_NAME).second; @@ -463,6 +476,7 @@ QDBusObjectPath NetworkManager::getAPSettingsObjectPath() const return settingsPath; } +// Turns off the AP connection void NetworkManager::deactivateAP() { qDebug() << "inside deactivateAP()"; @@ -473,6 +487,7 @@ void NetworkManager::deactivateAP() m_nm->DeactivateConnection(activePath); } +// Deletes the AP connection bool NetworkManager::disableAP() { foreach (const QDBusObjectPath &settingPath, getAllConnectionPaths()) @@ -493,7 +508,8 @@ bool NetworkManager::disableAP() return true; } -Connection NetworkManager::createAPConfig() const // Creates a default AP_SSID configuration for settings +// Creates a default AP_SSID configuration for settings +Connection NetworkManager::createAPConfig() const { qDebug() << "Creating AP Config..."; @@ -517,6 +533,7 @@ Connection NetworkManager::createAPConfig() const // Creates a default AP_SSID c DEFAULT_AP["ipv4"]["method"] = "shared"; DEFAULT_AP["ipv6"]["method"] = "auto"; + // Assign the default band and channel based on the Raspberry Pi type if (RASPBERRYPI_TYPE == "3B+") { DEFAULT_AP[NM_802_11_WIRELESS_KEY]["band"] = "a"; @@ -535,6 +552,7 @@ Connection NetworkManager::createAPConfig() const // Creates a default AP_SSID c QDBusObjectPath defaultPath = settings.AddConnection(DEFAULT_AP); qDebug() << "settings.AddConnection(DEFAULT_AP): " << defaultPath.path(); + // Hardcode WiFi IP address QString str = tr("nmcli connection modify %1 ipv4.address 192.168.125.1/24").arg(AP_NAME); QByteArray ba = str.toLocal8Bit(); const char *csys = ba.data(); @@ -543,11 +561,13 @@ Connection NetworkManager::createAPConfig() const // Creates a default AP_SSID c return DEFAULT_AP; } +// Returns if the network manager is on bool NetworkManager::isOn() const { return m_nm->networkingEnabled(); } +// Returns if the network manager is persistent bool NetworkManager::isPersistentOn() const { QSettings settings; @@ -557,11 +577,13 @@ bool NetworkManager::isPersistentOn() const return ret; } +// Returns the current state of the network manager NetworkManager::State NetworkManager::state() const { return (NetworkManager::State)m_device->state(); } + Network NetworkManager::active() const { if (!m_wifi) @@ -569,6 +591,7 @@ Network NetworkManager::active() const return createAccessPoint(m_wifi->activeAccessPoint()); } +// Returns active connection password QString NetworkManager::activeConnectionPassword() const { if (!isActiveConnectionOn()) @@ -578,6 +601,7 @@ QString NetworkManager::activeConnectionPassword() const return getPassword(active().ssid()); } +// Returns if the active connection is on bool NetworkManager::isActiveConnectionOn() const { bool activeConnOn; @@ -592,6 +616,7 @@ bool NetworkManager::isActiveConnectionOn() const return activeConnOn; } +// Returns the current active connection name QString NetworkManager::currentActiveConnectionName() const { QDBusObjectPath activePath = m_device->activeConnection(); // Device's current active connection @@ -604,6 +629,7 @@ QString NetworkManager::currentActiveConnectionName() const return activeConnObj.id(); } +// Returns NetworkList of all access points NetworkList NetworkManager::accessPoints() const { if (!m_wifi) @@ -634,6 +660,7 @@ NetworkList NetworkManager::accessPoints() const return networks; } +// Returns network IP address QString NetworkManager::ipAddress() const { int fd = socket(AF_INET, SOCK_DGRAM, 0); @@ -649,6 +676,7 @@ QString NetworkManager::ipAddress() const return ret; } +// Returns if event mode is on or off bool NetworkManager::eventModeState() { QProcess eventModeProcess; @@ -677,6 +705,7 @@ bool NetworkManager::eventModeState() } } +// Returns the network's IPv4 address QString NetworkManager::ip4Address() const { QString ipAddr; @@ -694,15 +723,31 @@ QString NetworkManager::ip4Address() const return ipAddr; } +// Initilization function void NetworkManager::init(const Device *device) { + qDebug() << "Init"; m_dev = device; bool checkEventState = eventModeState(); + int checkNetworkMode = getBootUpNetworkMode(); - if (!checkEventState) // Event Mode enabled + if (!checkEventState && (checkNetworkMode != 1 && checkNetworkMode != 2)) // Event Mode enabled { + enableAP(); } + else if (checkNetworkMode == 1) // Client Mode + { + + if(currentActiveConnectionName() == AP_NAME) + { + disableAP(); + } + } + else if (checkNetworkMode == 2) //Wifi off + { + turnOff(); + } } NetworkManager::NetworkManager() @@ -774,9 +819,43 @@ NetworkManager::NetworkManager() turnOn(); requestScan(); + qDebug() << "Active strength: " << active().strength(); + +} + +// Returns the network mode on boot up +int NetworkManager::getBootUpNetworkMode() +{ + QProcess networkModeProcess; + QString command = "grep '^MODE' /home/kipr/wombat-os/configFiles/wifiConnectionMode.txt | awk '{print $2}'"; + + networkModeProcess.start("bash", QStringList() << "-c" << command); + networkModeProcess.waitForFinished(); + + QString output = networkModeProcess.readAllStandardOutput().trimmed(); + qDebug() << "getBootUpNetworkMode: " << output.toInt(); + if (!output.isEmpty()) + { + switch (output.toInt()) + { + case 0: // AP Mode + return 0; + case 1: // Client Mode + return 1; + case 2: // Wifi Off + return 2; + default: + qDebug() << "Unknown MODE."; + } + } + else + { + qDebug() << "Failed to read MODE."; + } } +// Returns the Raspberry Pi type inside Wombat void NetworkManager::getRaspberryPiType() { QStringList arguments; @@ -804,6 +883,7 @@ void NetworkManager::getRaspberryPiType() qDebug() << "RASPBERRYPI_TYPE: " << RASPBERRYPI_TYPE; } +// NetworkManager AP added signal void NetworkManager::nmAccessPointAdded(const QDBusObjectPath &accessPoint) { Network network = createAccessPoint(accessPoint); @@ -812,6 +892,7 @@ void NetworkManager::nmAccessPointAdded(const QDBusObjectPath &accessPoint) emit accessPointAdded(network); } +// NetworkManager AP removed signal void NetworkManager::nmAccessPointRemoved(const QDBusObjectPath &accessPoint) { Network network = createAccessPoint(accessPoint); @@ -820,6 +901,7 @@ void NetworkManager::nmAccessPointRemoved(const QDBusObjectPath &accessPoint) m_accessPoints.removeAll(network); } +// Signal for when the network state changes void NetworkManager::stateChangedBouncer(uint newState, uint oldState) { NetworkManager::State networkStateNew = (NetworkManager::State)newState; @@ -827,6 +909,7 @@ void NetworkManager::stateChangedBouncer(uint newState, uint oldState) emit stateChanged(networkStateNew, networkStateOld); } +// Returns Network config from connection Network NetworkManager::networkFromConnection(const Connection &connection) const { // TODO: It would be nice to make this static somewhere @@ -855,6 +938,7 @@ Network NetworkManager::networkFromConnection(const Connection &connection) cons return network; } +// Creates a network from an access point Network NetworkManager::createAccessPoint(const QDBusObjectPath &accessPoint) const { OrgFreedesktopNetworkManagerAccessPointInterface accessPointObject( @@ -931,6 +1015,7 @@ Network NetworkManager::createAccessPoint(const QDBusObjectPath &accessPoint) co return newNetwork; } +// Returns a list of all connections QList NetworkManager::getAllConnectionPaths() const { // initialize settings provider to get all dbus path connections @@ -962,6 +1047,7 @@ NetworkManager::getAllConnections() const return ret; } +// Returns the connection and path for a given ssid QPair NetworkManager::getConnection(QString ssid) const { @@ -982,6 +1068,7 @@ NetworkManager::getConnection(QString ssid) const return qMakePair(Connection(), QDBusObjectPath()); } +// Returns the password for a given ssid QString NetworkManager::getPassword(QString ssid) const { // get connection and path @@ -1010,6 +1097,7 @@ QString NetworkManager::getPassword(QString ssid) const } } +// Returns the reply from a given query void NetworkManager::getReply(QDBusPendingReply<> &reply, const QString where, const bool throwError) const { reply.waitForFinished();