diff --git a/selfdrive/ui/qt/offroad/wifiManager.cc b/selfdrive/ui/qt/offroad/wifiManager.cc index ba5715178..39fb4b69a 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 898a13659..e0ee86f10 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);