Index: scripts/run.sh =================================================================== diff -u -rd71990c79c75c613d781890c6f77505d409d6c64 -r54f11a67ea7b62c64e797d3947d0858530394467 --- scripts/run.sh (.../run.sh) (revision d71990c79c75c613d781890c6f77505d409d6c64) +++ scripts/run.sh (.../run.sh) (revision 54f11a67ea7b62c64e797d3947d0858530394467) @@ -82,12 +82,6 @@ # setup wifi killall wpa_supplicant > $HOME/filesystem.out 2> $HOME/filesystem.err -if [[ -f "/etc/wpa_supplicant.conf" ]]; then - ./wifi_start_wpa_supplicant.sh wlan0 /etc/wpa_supplicant.conf > $HOME/filesystem.out 2> $HOME/filesystem.err - if [[ -f "$HOME/AUTO_IP" ]]; then - ./wifi_request_auto_assigned_ip.sh wlan0 & disown > $HOME/filesystem.out 2> $HOME/filesystem.err - fi -fi #launching denali application, disable keep-alive $HOME/denali -u 2>> $HOME/filesystem.err & Index: scripts/wifi_request_auto_assigned_ip.sh =================================================================== diff -u -rd71990c79c75c613d781890c6f77505d409d6c64 -r54f11a67ea7b62c64e797d3947d0858530394467 --- scripts/wifi_request_auto_assigned_ip.sh (.../wifi_request_auto_assigned_ip.sh) (revision d71990c79c75c613d781890c6f77505d409d6c64) +++ scripts/wifi_request_auto_assigned_ip.sh (.../wifi_request_auto_assigned_ip.sh) (revision 54f11a67ea7b62c64e797d3947d0858530394467) @@ -7,6 +7,5 @@ fi iface=$1 -touch AUTO_IP killall udhcpc udhcpc --timeout=5 --retries=8 -n -i $iface Index: scripts/wifi_save_static_interface_assignments.sh =================================================================== diff -u -r0629dfe6bcc3e85047319284fa4c534efbf58594 -r54f11a67ea7b62c64e797d3947d0858530394467 --- scripts/wifi_save_static_interface_assignments.sh (.../wifi_save_static_interface_assignments.sh) (revision 0629dfe6bcc3e85047319284fa4c534efbf58594) +++ scripts/wifi_save_static_interface_assignments.sh (.../wifi_save_static_interface_assignments.sh) (revision 54f11a67ea7b62c64e797d3947d0858530394467) @@ -17,5 +17,4 @@ netmask $subnet_mask gateway $3" > /etc/network/interfaces -rm -f AUTO_IP ./wifi_set_gateway.sh $gateway Index: scripts/wifi_set_auto_assigned_ip.sh =================================================================== diff -u -r0629dfe6bcc3e85047319284fa4c534efbf58594 -r54f11a67ea7b62c64e797d3947d0858530394467 --- scripts/wifi_set_auto_assigned_ip.sh (.../wifi_set_auto_assigned_ip.sh) (revision 0629dfe6bcc3e85047319284fa4c534efbf58594) +++ scripts/wifi_set_auto_assigned_ip.sh (.../wifi_set_auto_assigned_ip.sh) (revision 54f11a67ea7b62c64e797d3947d0858530394467) @@ -10,4 +10,3 @@ echo "auto $iface iface $iface inet dhcp" >> /etc/network/interfaces -touch AUTO_IP Index: scripts/wifi_set_gateway.sh =================================================================== diff -u -r091bc0425b84f094cbd863865a5edac2477208eb -r54f11a67ea7b62c64e797d3947d0858530394467 --- scripts/wifi_set_gateway.sh (.../wifi_set_gateway.sh) (revision 091bc0425b84f094cbd863865a5edac2477208eb) +++ scripts/wifi_set_gateway.sh (.../wifi_set_gateway.sh) (revision 54f11a67ea7b62c64e797d3947d0858530394467) @@ -7,4 +7,4 @@ fi ip route del default -ip route add default via $1 +ip route add default via $1 Index: sources/storage/StorageGlobals.cpp =================================================================== diff -u -r091bc0425b84f094cbd863865a5edac2477208eb -r54f11a67ea7b62c64e797d3947d0858530394467 --- sources/storage/StorageGlobals.cpp (.../StorageGlobals.cpp) (revision 091bc0425b84f094cbd863865a5edac2477208eb) +++ sources/storage/StorageGlobals.cpp (.../StorageGlobals.cpp) (revision 54f11a67ea7b62c64e797d3947d0858530394467) @@ -70,4 +70,21 @@ const char *Wifi_Set_Gateway = "wifi_set_gateway.sh"; const char *Wifi_Set_SubnetMask = "wifi_set_subnetmask.sh"; const char *Wifi_Start_WPA_Supplicant = "wifi_start_wpa_supplicant.sh"; + + // Wifi - Settings +#ifdef BUILD_FOR_DESKTOP + QSettings WifiSettings("/home/denali/wifi.ini"); +#elif BUILD_FOR_TARGET + QSettings WifiSettings("/home/root/settings/wifi.ini", QSettings::IniFormat); +#endif + + const char *WifiSettings_SSID = "wifi/ssid"; + const char *WifiSettings_MacAddress = "wifi/macAddress"; + const char *WifiSettings_ConfPath = "wifi/confPath"; + const char *WifiSettings_Security_Types = "wifi/security"; + const char *WifiSettings_IPAddress = "wifi/ipAddress"; + const char *WifiSettings_Gateway = "wifi/gateway"; + const char *WifiSettings_SubnetMask = "wifi/subnetmask"; + const char *WifiSettings_DNS = "wifi/dns"; + const char *WifiSettings_UseDHCP = "wifi/useDHCP"; } Index: sources/storage/StorageGlobals.h =================================================================== diff -u -r091bc0425b84f094cbd863865a5edac2477208eb -r54f11a67ea7b62c64e797d3947d0858530394467 --- sources/storage/StorageGlobals.h (.../StorageGlobals.h) (revision 091bc0425b84f094cbd863865a5edac2477208eb) +++ sources/storage/StorageGlobals.h (.../StorageGlobals.h) (revision 54f11a67ea7b62c64e797d3947d0858530394467) @@ -14,6 +14,8 @@ */ #pragma once +#include + /*! * Contains the shared constants between storage classes. */ @@ -56,4 +58,16 @@ extern const char *Wifi_Set_Gateway; extern const char *Wifi_Set_SubnetMask; extern const char *Wifi_Start_WPA_Supplicant; + + // Wifi - Settings + extern QSettings WifiSettings; + extern const char *WifiSettings_SSID; + extern const char *WifiSettings_MacAddress; + extern const char *WifiSettings_ConfPath; + extern const char *WifiSettings_Security_Types; + extern const char *WifiSettings_IPAddress; + extern const char *WifiSettings_Gateway; + extern const char *WifiSettings_SubnetMask; + extern const char *WifiSettings_DNS; + extern const char *WifiSettings_UseDHCP; } Index: sources/view/VNetworkModel.cpp =================================================================== diff -u -r091bc0425b84f094cbd863865a5edac2477208eb -r54f11a67ea7b62c64e797d3947d0858530394467 --- sources/view/VNetworkModel.cpp (.../VNetworkModel.cpp) (revision 091bc0425b84f094cbd863865a5edac2477208eb) +++ sources/view/VNetworkModel.cpp (.../VNetworkModel.cpp) (revision 54f11a67ea7b62c64e797d3947d0858530394467) @@ -312,7 +312,7 @@ */ void VNetworkModel::doSetIPAddress(const QString &vIPAddress) { - emit didRequestSetIPAddress(vIPAddress); + emit didRequestSetIPAddress(vIPAddress.trimmed()); } /*! @@ -321,7 +321,7 @@ */ void VNetworkModel::doSetGateway(const QString &vGateway) { - emit didRequestSetGateway(vGateway); + emit didRequestSetGateway(vGateway.trimmed()); } /*! @@ -330,7 +330,7 @@ */ void VNetworkModel::doSetSubnetMask(const QString &vSubnetMask) { - emit didRequestSetSubnetMask(vSubnetMask); + emit didRequestSetSubnetMask(vSubnetMask.trimmed()); } /*! @@ -339,7 +339,7 @@ */ void VNetworkModel::doSetDNS(const QString &vDNS) { - emit didRequestSetDNS(vDNS); + emit didRequestSetDNS(vDNS.trimmed()); } /*! Index: sources/wifi/WifiInterface.cpp =================================================================== diff -u -r091bc0425b84f094cbd863865a5edac2477208eb -r54f11a67ea7b62c64e797d3947d0858530394467 --- sources/wifi/WifiInterface.cpp (.../WifiInterface.cpp) (revision 091bc0425b84f094cbd863865a5edac2477208eb) +++ sources/wifi/WifiInterface.cpp (.../WifiInterface.cpp) (revision 54f11a67ea7b62c64e797d3947d0858530394467) @@ -27,8 +27,63 @@ _processSetStaticGateway.setParent(this); _processSetStaticSubnetMask.setParent(this); _processSetDNS.setParent(this); + + if (hasConnectedToWifi()) + rejoinLastWifiNetwork(); } + +/*! + * \brief WifiInterface::hasConnectedToWifi + * Checks whether we have previously connected to a wifi network + * \return (bool) true if we have, false otherwise + */ +bool WifiInterface::hasConnectedToWifi() +{ + if (WifiSettings.value(WifiSettings_MacAddress).toString().isEmpty()) + return false; + + if (!QFile(_wpaSupplicantConfPath).exists()) + return false; + + return true; +} + +/*! + * \brief WifiInterface::getLastWifiNetworkConnectedTo + * Gets the last network we connected to from settings + * \return (Network) the network we last connected to + */ +Network WifiInterface::getLastWifiNetworkConnectedTo() +{ + QString macAddress = WifiSettings.value(WifiSettings_MacAddress).toString(); + QString ssid = WifiSettings.value(WifiSettings_SSID).toString(); + QList securityTypesVar = WifiSettings.value(WifiSettings_Security_Types).toList(); + Network::STATUS status = Network::STATUS::NOT_CONNECTED; + Network::SIGNAL_LEVEL signalLevel = Network::SIGNAL_LEVEL::NO_SIGNAL; + _useDHCP = WifiSettings.value(WifiSettings_UseDHCP).toBool(); + return Network(macAddress, ssid, variantListToSecurityTypes(securityTypesVar), status, signalLevel); +} + +/*! + * \brief WifiInterface::rejoinLastWifiNetwork + * Attemps to rejoin the network we last connected to + */ +void WifiInterface::rejoinLastWifiNetwork() +{ + _network = getLastWifiNetworkConnectedTo(); + if (_processStartWPASupplicant.state() != QProcess::NotRunning) + { + LOG_DEBUG(QString("Rejecting request for %1. %2 is already running.") + .arg(__FUNCTION__) + .arg(_processStartWPASupplicant.objectName())); + return; + } + _processStartWPASupplicant.start(Wifi_Start_WPA_Supplicant, + QStringList() << _iface + << _wpaSupplicantConfPath); +} + void WifiInterface::initConnections() { connect(this, SIGNAL(didStatusChanged(const QString)), @@ -334,6 +389,8 @@ { LOG_DEBUG(QString("WifiInterface::%1 %2").arg(__FUNCTION__).arg(QThread::currentThread()->objectName())); _network = vNetwork; + _useDHCP = true; + WifiSettings.setValue(WifiSettings_UseDHCP, _useDHCP); LOG_DEBUG(QString("Joining Network %1").arg(vNetwork.ssid())); if (_processGenerateWPASupplicant.state() != QProcess::NotRunning) { @@ -357,6 +414,10 @@ emit didError(QString("Network %1 has an unsupported security type.").arg(vNetwork.ssid())); } + WifiSettings.setValue(WifiSettings_SSID, vNetwork.ssid()); + WifiSettings.setValue(WifiSettings_MacAddress, vNetwork.macAddress()); + WifiSettings.setValue(WifiSettings_ConfPath, _wpaSupplicantConfPath); + WifiSettings.setValue(WifiSettings_Security_Types, securityTypesToStringList(vNetwork.securityTypes())); _processGenerateWPASupplicant.start(Wifi_Generate_WPA_Supplicant, QStringList() << vNetwork.ssid() << vPassword @@ -463,7 +524,6 @@ void WifiInterface::doRequestIPSettings() { LOG_DEBUG(QString("WifiInterface::%1 %2").arg(__FUNCTION__).arg(QThread::currentThread()->objectName())); - QString result = ""; if (_processReadIPSettings.state() != QProcess::NotRunning) { LOG_DEBUG(QString("Rejecting request for %1. %2 is already running.") @@ -535,6 +595,22 @@ Q_UNUSED(vExitCode); Q_UNUSED(vExitStatus); _network.mIPSettings.mDNS = parseDNS(_processReadDNS.readAllStandardOutput()); + if (!_useDHCP) + { + // Use current static IP settings + QString ipAddress = WifiSettings.value(WifiSettings_IPAddress).toString().trimmed(); + QString gateway = WifiSettings.value(WifiSettings_Gateway).toString().trimmed(); + QString subnetMask = WifiSettings.value(WifiSettings_SubnetMask).toString().trimmed(); + QString dns = WifiSettings.value(WifiSettings_DNS).toString().trimmed(); + if (!ipAddress.isEmpty()) + doRequestSetIPAddress(_network.mIPSettings.mIPAddress); + if (!gateway.isEmpty()) + doRequestSetGateway(_network.mIPSettings.mGateway); + if (!subnetMask.isEmpty()) + doRequestSetSubnetMask(_network.mIPSettings.mSubnetMask); + if (!dns.isEmpty()) + doRequestSetDNS(_network.mIPSettings.mDNS); + } emit didConnectToNetwork(_network); } @@ -658,8 +734,11 @@ .arg(_processSetStaticIPAddress.objectName())); return; } + WifiSettings.setValue(WifiSettings_IPAddress, vIPAddress); + _useDHCP = false; + WifiSettings.setValue(WifiSettings_UseDHCP, _useDHCP); _processSetStaticIPAddress.start(Wifi_Set_Static_IP, - QStringList() << _iface); + QStringList() << _iface << vIPAddress); } /*! @@ -673,7 +752,7 @@ Q_UNUSED(vExitStatus) if (vExitCode != 0) { - emit didError(tr("Failed to set static IP Address for %1").arg(_network.ssid())); + emit didError(tr("Failed to set static IP Address")); return; } emit didSetStaticIPAddress(); @@ -689,14 +768,18 @@ Q_UNUSED(vGateway) LOG_DEBUG(QString("WifiInterface::%1 %2").arg(__FUNCTION__).arg(QThread::currentThread()->objectName())); LOG_DEBUG(QString("Handling request to set static gateway: %1").arg(vGateway)); + if (_processSetStaticGateway.state() != QProcess::NotRunning) { LOG_DEBUG(QString("Rejecting request for %1. %2 is already running.") .arg(__FUNCTION__) .arg(_processSetStaticGateway.objectName())); return; } - _processSetStaticGateway.start(Wifi_Set_Static_IP, + WifiSettings.setValue(WifiSettings_Gateway, vGateway); + _useDHCP = false; + WifiSettings.setValue(WifiSettings_UseDHCP, _useDHCP); + _processSetStaticGateway.start(Wifi_Set_Gateway, QStringList() << vGateway); } @@ -711,7 +794,7 @@ Q_UNUSED(vExitStatus) if (vExitCode != 0) { - emit didError(tr("Failed to set gateway for %1").arg(_network.ssid())); + emit didError(tr("Failed to set gateway.")); return; } emit didSetGateway(); @@ -734,8 +817,11 @@ .arg(_processSetStaticSubnetMask.objectName())); return; } + WifiSettings.setValue(WifiSettings_SubnetMask, vSubnetMask); + _useDHCP = false; + WifiSettings.setValue(WifiSettings_UseDHCP, _useDHCP); _processSetStaticSubnetMask.start(Wifi_Set_SubnetMask, - QStringList() << vSubnetMask); + QStringList() << _iface << vSubnetMask); } /*! @@ -749,7 +835,7 @@ Q_UNUSED(vExitStatus) if (vExitCode != 0) { - emit didError(tr("Failed to set subnet mask for %1. Has the IP been set?").arg(_network.ssid())); + emit didError(tr("Failed to set subnet mask.")); return; } emit didSetSubnetMask(); @@ -771,6 +857,7 @@ .arg(_processSetDNS.objectName())); return; } + WifiSettings.setValue(WifiSettings_DNS, vDNS); _processSetDNS.start(Wifi_Set_DNS, QStringList() << vDNS); } @@ -786,8 +873,43 @@ Q_UNUSED(vExitStatus) if (vExitCode != 0) { - emit didError(tr("Failed to set DNS.").arg(_network.ssid())); + emit didError(tr("Failed to set DNS.")); return; } emit didSetDNS(); } + +/*! + * \brief WifiInterface::securityTypesToStringList + * Converts a QList of network security types to a QStringList + * \param securityTypes (QList) the list of security type + * \return (QStringList) the security types as a string list + */ +QStringList WifiInterface::securityTypesToStringList(const QList &securityTypes) +{ + QStringList securityTypesStrList; + for (const Network::SECURITY_TYPE &type : securityTypes) + { + securityTypesStrList.append(QString("%1").arg(type)); + } + return securityTypesStrList; +} + +/*! + * \brief variantListToSecurityTypes + * Converts a QVariantList of security types to a QList + * \param securityTypesVar (QVariantList) security types + * \return (QList) the list of network security types + */ +QList WifiInterface::variantListToSecurityTypes(const QList &securityTypesVar) +{ + QList securityTypes; + for (const QVariant &type : securityTypesVar) + { + bool ok = false; + Network::SECURITY_TYPE val = Network::SECURITY_TYPE(type.toInt(&ok)); + if (ok) + securityTypes.append(val); + } + return securityTypes; +} Index: sources/wifi/WifiInterface.h =================================================================== diff -u -r091bc0425b84f094cbd863865a5edac2477208eb -r54f11a67ea7b62c64e797d3947d0858530394467 --- sources/wifi/WifiInterface.h (.../WifiInterface.h) (revision 091bc0425b84f094cbd863865a5edac2477208eb) +++ sources/wifi/WifiInterface.h (.../WifiInterface.h) (revision 54f11a67ea7b62c64e797d3947d0858530394467) @@ -31,6 +31,7 @@ QThread *_thread = nullptr; bool _init = false; bool _scanRunning = false; + bool _useDHCP = true; int _defaultTimeout = 5000; int _dhcpTimeout = 10000; int _scanTimeout = 30000; @@ -53,7 +54,6 @@ const QString _iface = "wlan0"; const QString _wpaSupplicantConfPath = "/etc/wpa_supplicant.conf"; - // Singleton SINGLETON(WifiInterface) @@ -69,6 +69,11 @@ void timerEvent(QTimerEvent* event); void initThread(QThread &vThread); void quitThread(); + bool hasConnectedToWifi(); + Network getLastWifiNetworkConnectedTo(); + void rejoinLastWifiNetwork(); + QStringList securityTypesToStringList(const QList &securityTypes); + QList variantListToSecurityTypes(const QList &securityTypesVar); public slots: bool init(QThread &vThread);