diff --git a/selfdrive/common/params.cc b/selfdrive/common/params.cc index b5b7941e5f..b261855b4e 100644 --- a/selfdrive/common/params.cc +++ b/selfdrive/common/params.cc @@ -150,6 +150,7 @@ std::unordered_map keys = { {"GitRemote", PERSISTENT}, {"GithubSshKeys", PERSISTENT}, {"GithubUsername", PERSISTENT}, + {"GsmRoaming", PERSISTENT}, {"HardwareSerial", PERSISTENT}, {"HasAcceptedTerms", PERSISTENT}, {"IsDriverViewEnabled", CLEAR_ON_MANAGER_START}, diff --git a/selfdrive/ui/qt/offroad/networking.cc b/selfdrive/ui/qt/offroad/networking.cc index cc4fc44f43..e317b25b9a 100644 --- a/selfdrive/ui/qt/offroad/networking.cc +++ b/selfdrive/ui/qt/offroad/networking.cc @@ -149,6 +149,17 @@ AdvancedNetworking::AdvancedNetworking(QWidget* parent, WifiManager* wifi): QWid main_layout->addWidget(new SshToggle()); main_layout->addWidget(horizontal_line(), 0); main_layout->addWidget(new SshControl()); + main_layout->addWidget(horizontal_line(), 0); + + // Roaming toggle + const bool roamingEnabled = params.getBool("GsmRoaming"); + wifi->setRoamingEnabled(roamingEnabled); + ToggleControl *roamingToggle = new ToggleControl("Enable Roaming", "", "", roamingEnabled); + QObject::connect(roamingToggle, &SshToggle::toggleFlipped, [=](bool state) { + params.putBool("GsmRoaming", state); + wifi->setRoamingEnabled(state); + }); + main_layout->addWidget(roamingToggle); main_layout->addStretch(1); } diff --git a/selfdrive/ui/qt/offroad/networking.h b/selfdrive/ui/qt/offroad/networking.h index ed544a27cf..b5a0c2ba2e 100644 --- a/selfdrive/ui/qt/offroad/networking.h +++ b/selfdrive/ui/qt/offroad/networking.h @@ -40,6 +40,7 @@ private: LabelControl* ipLabel; ToggleControl* tetheringToggle; WifiManager* wifi = nullptr; + Params params; signals: void backPress(); diff --git a/selfdrive/ui/qt/offroad/wifiManager.cc b/selfdrive/ui/qt/offroad/wifiManager.cc index cd3bdbd293..81da7bdb4d 100644 --- a/selfdrive/ui/qt/offroad/wifiManager.cc +++ b/selfdrive/ui/qt/offroad/wifiManager.cc @@ -341,7 +341,7 @@ void WifiManager::connectionRemoved(const QDBusObjectPath &path) { } void WifiManager::newConnection(const QDBusObjectPath &path) { - knownConnections[path] = getConnectionSsid(path); + knownConnections[path] = getConnectionSettings(path).value("802-11-wireless").value("ssid").toString(); if (knownConnections[path] != tethering_ssid) { activateWifiConnection(knownConnections[path]); } @@ -362,11 +362,10 @@ QDBusObjectPath WifiManager::getConnectionPath(const QString &ssid) { return QDBusObjectPath(); } -QString WifiManager::getConnectionSsid(const QDBusObjectPath &path) { +Connection WifiManager::getConnectionSettings(const QDBusObjectPath &path) { QDBusInterface nm(NM_DBUS_SERVICE, path.path(), NM_DBUS_INTERFACE_SETTINGS_CONNECTION, bus); nm.setTimeout(DBUS_TIMEOUT); - const QDBusReply result = nm.call("GetSettings"); - return result.value().value("802-11-wireless").value("ssid").toString(); + return QDBusReply(nm.call("GetSettings")).value(); } void WifiManager::initConnections() { @@ -375,7 +374,12 @@ void WifiManager::initConnections() { const QDBusReply> response = nm.call("ListConnections"); for (const QDBusObjectPath &path : response.value()) { - knownConnections[path] = getConnectionSsid(path); + const Connection &settings = getConnectionSettings(path); + if (settings.value("connection").value("type") == "802-11-wireless") { + knownConnections[path] = settings.value("802-11-wireless").value("ssid").toString(); + } else if (path.path() != "/") { + lteConnectionPath = path.path(); + } } } @@ -416,6 +420,19 @@ NetworkType WifiManager::currentNetworkType() { return NetworkType::NONE; } +void WifiManager::setRoamingEnabled(bool roaming) { + if (!lteConnectionPath.isEmpty()) { + QDBusInterface nm(NM_DBUS_SERVICE, lteConnectionPath, NM_DBUS_INTERFACE_SETTINGS_CONNECTION, bus); + nm.setTimeout(DBUS_TIMEOUT); + + Connection settings = QDBusReply(nm.call("GetSettings")).value(); + if (settings.value("gsm").value("home-only").toBool() == roaming) { + settings["gsm"]["home-only"] = !roaming; + nm.call("UpdateUnsaved", QVariant::fromValue(settings)); // update is temporary + } + } +} + // Functions for tethering void WifiManager::addTetheringConnection() { Connection connection; diff --git a/selfdrive/ui/qt/offroad/wifiManager.h b/selfdrive/ui/qt/offroad/wifiManager.h index 191a4c3008..2fb539260d 100644 --- a/selfdrive/ui/qt/offroad/wifiManager.h +++ b/selfdrive/ui/qt/offroad/wifiManager.h @@ -42,6 +42,7 @@ public: void requestScan(); QMap seenNetworks; QMap knownConnections; + QString lteConnectionPath; QString ipv4_address; void refreshNetworks(); @@ -49,6 +50,7 @@ public: bool isKnownConnection(const QString &ssid); void activateWifiConnection(const QString &ssid); NetworkType currentNetworkType(); + void setRoamingEnabled(bool roaming); void connect(const Network &ssid); void connect(const Network &ssid, const QString &password); @@ -84,8 +86,8 @@ private: unsigned int get_ap_strength(const QString &network_path); SecurityType getSecurityType(const QString &path); QDBusObjectPath getConnectionPath(const QString &ssid); + Connection getConnectionSettings(const QDBusObjectPath &path); void initConnections(); - QString getConnectionSsid(const QDBusObjectPath &path); void setup(); signals: