Networking: populate tethering password (#21455)

* populate password from hotspot connection

move to setup()

populate tethering password

fix password editing

setup tethering when editing password or enabling

fix

* fixes

* last fix, don't activate when adding

* check before

* if not
old-commit-hash: 146973da7f
commatwo_master
sshane 4 years ago committed by GitHub
parent 1226f91637
commit 6755365476
  1. 4
      selfdrive/ui/qt/offroad/networking.cc
  2. 33
      selfdrive/ui/qt/offroad/wifiManager.cc
  3. 3
      selfdrive/ui/qt/offroad/wifiManager.h
  4. 3
      selfdrive/ui/qt/widgets/input.cc
  5. 2
      selfdrive/ui/qt/widgets/input.h

@ -125,8 +125,8 @@ AdvancedNetworking::AdvancedNetworking(QWidget* parent, WifiManager* wifi): QWid
// Change tethering password // Change tethering password
editPasswordButton = new ButtonControl("Tethering Password", "EDIT"); editPasswordButton = new ButtonControl("Tethering Password", "EDIT");
connect(editPasswordButton, &ButtonControl::released, [=]() { connect(editPasswordButton, &ButtonControl::released, [=]() {
QString pass = InputDialog::getText("Enter new tethering password", 8); QString pass = InputDialog::getText("Enter new tethering password", 8, wifi->getTetheringPassword());
if (pass.size()) { if (!pass.isEmpty()) {
wifi->changeTetheringPassword(pass); wifi->changeTetheringPassword(pass);
} }
}); });

@ -365,8 +365,10 @@ void WifiManager::connectionRemoved(const QDBusObjectPath &path) {
void WifiManager::newConnection(const QDBusObjectPath &path) { void WifiManager::newConnection(const QDBusObjectPath &path) {
knownConnections[path] = getConnectionSsid(path); knownConnections[path] = getConnectionSsid(path);
if (knownConnections[path] != tethering_ssid) {
activateWifiConnection(knownConnections[path]); activateWifiConnection(knownConnections[path]);
} }
}
void WifiManager::disconnect() { void WifiManager::disconnect() {
QString active_ap = get_active_ap(); QString active_ap = get_active_ap();
@ -428,7 +430,7 @@ void WifiManager::addTetheringConnection() {
connection["802-11-wireless-security"]["key-mgmt"] = "wpa-psk"; connection["802-11-wireless-security"]["key-mgmt"] = "wpa-psk";
connection["802-11-wireless-security"]["pairwise"] = QStringList("ccmp"); connection["802-11-wireless-security"]["pairwise"] = QStringList("ccmp");
connection["802-11-wireless-security"]["proto"] = QStringList("rsn"); 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"; connection["ipv4"]["method"] = "shared";
QMap<QString,QVariant> address; QMap<QString,QVariant> address;
@ -445,7 +447,7 @@ void WifiManager::addTetheringConnection() {
} }
void WifiManager::enableTethering() { void WifiManager::enableTethering() {
if (!isKnownConnection(tethering_ssid.toUtf8())) { if (!isKnownConnection(tethering_ssid)) {
addTetheringConnection(); addTetheringConnection();
} }
activateWifiConnection(tethering_ssid.toUtf8()); activateWifiConnection(tethering_ssid.toUtf8());
@ -465,8 +467,29 @@ bool WifiManager::tetheringEnabled() {
return false; return false;
} }
void WifiManager::changeTetheringPassword(const QString &newPassword) { QString WifiManager::getTetheringPassword() {
tetheringPassword = newPassword; if (!isKnownConnection(tethering_ssid)) {
forgetConnection(tethering_ssid.toUtf8());
addTetheringConnection(); 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<QMap<QString, QMap<QString, QVariant>>> 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) {
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<Connection>(nm.call("GetSettings")).value();
settings["802-11-wireless-security"]["psk"] = newPassword;
nm.call("Update", QVariant::fromValue(settings));
}
}

@ -54,6 +54,7 @@ public:
void addTetheringConnection(); void addTetheringConnection();
void activateWifiConnection(const QString &ssid); void activateWifiConnection(const QString &ssid);
void changeTetheringPassword(const QString &newPassword); void changeTetheringPassword(const QString &newPassword);
QString getTetheringPassword();
private: private:
QVector<QByteArray> seen_ssids; QVector<QByteArray> 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 unsigned int raw_adapter_state; // Connection status https://developer.gnome.org/NetworkManager/1.26/nm-dbus-types.html#NMDeviceState
QString connecting_to_network; QString connecting_to_network;
QString tethering_ssid; QString tethering_ssid;
QString tetheringPassword = "swagswagcommma"; const QString defaultTetheringPassword = "swagswagcommma";
bool firstScan = true; bool firstScan = true;
QString getAdapter(); QString getAdapter();

@ -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); InputDialog d = InputDialog(prompt);
d.line->setText(defaultText);
d.setMinLength(minLength); d.setMinLength(minLength);
const int ret = d.exec(); const int ret = d.exec();
return ret ? d.text() : QString(); return ret ? d.text() : QString();

@ -14,7 +14,7 @@ class InputDialog : public QDialog {
public: public:
explicit InputDialog(const QString &prompt_text, QWidget* parent = 0); 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(); QString text();
void setMessage(const QString &message, bool clearInputField = true); void setMessage(const QString &message, bool clearInputField = true);
void setMinLength(int length); void setMinLength(int length);

Loading…
Cancel
Save