From 797b7a77a05ad108bbad3daa511d93238b53b548 Mon Sep 17 00:00:00 2001 From: sshane Date: Mon, 26 Jul 2021 23:42:29 -0700 Subject: [PATCH] networking: network type function (#21732) * debug known connections * print type * on mobile if no wifi and a sim card * clean up * debug primary connection * network type * not specifying current suggests you can pass it a path * debug debug Revert "debug" This reverts commit fe4748aa4df77449e1887685aa958ae2b89b88d0. hotspot check This reverts commit 5d2fc5f3bba45c87af8322766e426e8adee64ead. Revert "Revert "Revert "debug""" This reverts commit 6115204d5013ae5d613add92c1dded7a8f5cadbc. hotspot check * fixes old-commit-hash: 905138054b3e08103d8bd1ee9108697c0e281a0f --- selfdrive/ui/qt/offroad/wifiManager.cc | 30 ++++++++++++++++++++++++-- selfdrive/ui/qt/offroad/wifiManager.h | 9 +++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/selfdrive/ui/qt/offroad/wifiManager.cc b/selfdrive/ui/qt/offroad/wifiManager.cc index ba57151781..39fb4b69a6 100644 --- a/selfdrive/ui/qt/offroad/wifiManager.cc +++ b/selfdrive/ui/qt/offroad/wifiManager.cc @@ -117,8 +117,7 @@ QString WifiManager::get_ipv4_address() { } QVector conns = get_active_connections(); for (auto &p : conns) { - QString active_connection = p.path(); - QDBusInterface nm(NM_DBUS_SERVICE, active_connection, NM_DBUS_INTERFACE_PROPERTIES, bus); + QDBusInterface nm(NM_DBUS_SERVICE, p.path(), NM_DBUS_INTERFACE_PROPERTIES, bus); nm.setTimeout(DBUS_TIMEOUT); QDBusObjectPath pth = get_response(nm.call("Get", NM_DBUS_INTERFACE_ACTIVE_CONNECTION, "Ip4Config")); @@ -391,6 +390,33 @@ void WifiManager::activateWifiConnection(const QString &ssid) { } } +// function matches tici/hardware.py +NetworkType WifiManager::currentNetworkType() { + QDBusInterface nm(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE_PROPERTIES, bus); + nm.setTimeout(DBUS_TIMEOUT); + const QDBusObjectPath &path = get_response(nm.call("Get", NM_DBUS_INTERFACE, "PrimaryConnection")); + + QDBusInterface nm2(NM_DBUS_SERVICE, path.path(), NM_DBUS_INTERFACE_PROPERTIES, bus); + nm.setTimeout(DBUS_TIMEOUT); + const QString &type = get_response(nm2.call("Get", NM_DBUS_INTERFACE_ACTIVE_CONNECTION, "Type")); + + if (type == "802-3-ethernet") { + return NetworkType::ETHERNET; + } else if (type == "802-11-wireless" && !isTetheringEnabled()) { + return NetworkType::WIFI; + } else { + for (const QDBusObjectPath &path : get_active_connections()) { + QDBusInterface nm3(NM_DBUS_SERVICE, path.path(), NM_DBUS_INTERFACE_PROPERTIES, bus); + nm3.setTimeout(DBUS_TIMEOUT); + const QString &type = get_response(nm3.call("Get", NM_DBUS_INTERFACE_ACTIVE_CONNECTION, "Type")); + if (type == "gsm") { + return NetworkType::CELL; + } + } + } + return NetworkType::NONE; +} + // 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 898a13659d..e0ee86f109 100644 --- a/selfdrive/ui/qt/offroad/wifiManager.h +++ b/selfdrive/ui/qt/offroad/wifiManager.h @@ -10,11 +10,17 @@ enum class SecurityType { WPA, UNSUPPORTED }; -enum class ConnectedType{ +enum class ConnectedType { DISCONNECTED, CONNECTING, CONNECTED }; +enum class NetworkType { + NONE, + WIFI, + CELL, + ETHERNET +}; typedef QMap> Connection; typedef QVector> IpConfig; @@ -42,6 +48,7 @@ public: void forgetConnection(const QString &ssid); bool isKnownConnection(const QString &ssid); void activateWifiConnection(const QString &ssid); + NetworkType currentNetworkType(); void connect(const Network &ssid); void connect(const Network &ssid, const QString &password);