diff --git a/selfdrive/ui/qt/offroad/networking.cc b/selfdrive/ui/qt/offroad/networking.cc index 5f78d7c5e1..b9444666b5 100644 --- a/selfdrive/ui/qt/offroad/networking.cc +++ b/selfdrive/ui/qt/offroad/networking.cc @@ -125,8 +125,8 @@ AdvancedNetworking::AdvancedNetworking(QWidget* parent, WifiManager* wifi): QWid // Change tethering password editPasswordButton = new ButtonControl("Tethering Password", "EDIT"); connect(editPasswordButton, &ButtonControl::released, [=]() { - QString pass = InputDialog::getText("Enter new tethering password", 8); - if (pass.size()) { + QString pass = InputDialog::getText("Enter new tethering password", 8, wifi->getTetheringPassword()); + if (!pass.isEmpty()) { wifi->changeTetheringPassword(pass); } }); diff --git a/selfdrive/ui/qt/offroad/wifiManager.cc b/selfdrive/ui/qt/offroad/wifiManager.cc index c7af2f57f6..7747ce2d8e 100644 --- a/selfdrive/ui/qt/offroad/wifiManager.cc +++ b/selfdrive/ui/qt/offroad/wifiManager.cc @@ -277,7 +277,7 @@ bool WifiManager::isWirelessAdapter(const QDBusObjectPath &path) { void WifiManager::requestScan() { QDBusInterface nm(NM_DBUS_SERVICE, adapter, NM_DBUS_INTERFACE_DEVICE_WIRELESS, bus); nm.setTimeout(DBUS_TIMEOUT); - nm.call("RequestScan", QVariantMap()); + nm.call("RequestScan", QVariantMap()); } uint WifiManager::get_wifi_device_state() { @@ -365,7 +365,9 @@ void WifiManager::connectionRemoved(const QDBusObjectPath &path) { void WifiManager::newConnection(const QDBusObjectPath &path) { knownConnections[path] = getConnectionSsid(path); - activateWifiConnection(knownConnections[path]); + if (knownConnections[path] != tethering_ssid) { + activateWifiConnection(knownConnections[path]); + } } void WifiManager::disconnect() { @@ -428,7 +430,7 @@ void WifiManager::addTetheringConnection() { connection["802-11-wireless-security"]["key-mgmt"] = "wpa-psk"; connection["802-11-wireless-security"]["pairwise"] = QStringList("ccmp"); connection["802-11-wireless-security"]["proto"] = QStringList("rsn"); - connection["802-11-wireless-security"]["psk"] = tetheringPassword; + connection["802-11-wireless-security"]["psk"] = defaultTetheringPassword; connection["ipv4"]["method"] = "shared"; QMap address; @@ -445,7 +447,7 @@ void WifiManager::addTetheringConnection() { } void WifiManager::enableTethering() { - if (!isKnownConnection(tethering_ssid.toUtf8())) { + if (!isKnownConnection(tethering_ssid)) { addTetheringConnection(); } activateWifiConnection(tethering_ssid.toUtf8()); @@ -465,8 +467,29 @@ bool WifiManager::tetheringEnabled() { return false; } +QString WifiManager::getTetheringPassword() { + if (!isKnownConnection(tethering_ssid)) { + addTetheringConnection(); + } + const QDBusObjectPath &path = getConnectionPath(tethering_ssid); + if (!path.path().isEmpty()) { + QDBusInterface nm(NM_DBUS_INTERFACE, path.path(), NM_DBUS_INTERFACE_SETTINGS_CONNECTION, bus); + nm.setTimeout(DBUS_TIMEOUT); + + const QDBusReply>> response = nm.call("GetSecrets", "802-11-wireless-security"); + return response.value().value("802-11-wireless-security").value("psk").toString(); + } + return ""; +} + void WifiManager::changeTetheringPassword(const QString &newPassword) { - tetheringPassword = newPassword; - forgetConnection(tethering_ssid.toUtf8()); - addTetheringConnection(); + const QDBusObjectPath &path = getConnectionPath(tethering_ssid); + if (!path.path().isEmpty()) { + QDBusInterface nm(NM_DBUS_INTERFACE, path.path(), NM_DBUS_INTERFACE_SETTINGS_CONNECTION, bus); + nm.setTimeout(DBUS_TIMEOUT); + + Connection settings = QDBusReply(nm.call("GetSettings")).value(); + settings["802-11-wireless-security"]["psk"] = newPassword; + nm.call("Update", QVariant::fromValue(settings)); + } } diff --git a/selfdrive/ui/qt/offroad/wifiManager.h b/selfdrive/ui/qt/offroad/wifiManager.h index 23224b3db4..8a28859975 100644 --- a/selfdrive/ui/qt/offroad/wifiManager.h +++ b/selfdrive/ui/qt/offroad/wifiManager.h @@ -54,6 +54,7 @@ public: void addTetheringConnection(); void activateWifiConnection(const QString &ssid); void changeTetheringPassword(const QString &newPassword); + QString getTetheringPassword(); private: QVector seen_ssids; @@ -62,7 +63,7 @@ private: unsigned int raw_adapter_state; // Connection status https://developer.gnome.org/NetworkManager/1.26/nm-dbus-types.html#NMDeviceState QString connecting_to_network; QString tethering_ssid; - QString tetheringPassword = "swagswagcommma"; + const QString defaultTetheringPassword = "swagswagcommma"; bool firstScan = true; QString getAdapter(); diff --git a/selfdrive/ui/qt/widgets/input.cc b/selfdrive/ui/qt/widgets/input.cc index a58ad1116a..07bd0d31d4 100644 --- a/selfdrive/ui/qt/widgets/input.cc +++ b/selfdrive/ui/qt/widgets/input.cc @@ -57,8 +57,9 @@ InputDialog::InputDialog(const QString &prompt_text, QWidget *parent) : QDialog( } -QString InputDialog::getText(const QString &prompt, int minLength) { +QString InputDialog::getText(const QString &prompt, int minLength, const QString &defaultText) { InputDialog d = InputDialog(prompt); + d.line->setText(defaultText); d.setMinLength(minLength); const int ret = d.exec(); return ret ? d.text() : QString(); diff --git a/selfdrive/ui/qt/widgets/input.h b/selfdrive/ui/qt/widgets/input.h index 7b42595dc1..bf37b9181c 100644 --- a/selfdrive/ui/qt/widgets/input.h +++ b/selfdrive/ui/qt/widgets/input.h @@ -14,7 +14,7 @@ class InputDialog : public QDialog { public: explicit InputDialog(const QString &prompt_text, QWidget* parent = 0); - static QString getText(const QString &prompt, int minLength = -1); + static QString getText(const QString &prompt, int minLength = -1, const QString &defaultText = ""); QString text(); void setMessage(const QString &message, bool clearInputField = true); void setMinLength(int length);