diff --git a/selfdrive/ui/qt/offroad/networking.cc b/selfdrive/ui/qt/offroad/networking.cc index c50fe5a20e8eb6..dc70a4ba378289 100644 --- a/selfdrive/ui/qt/offroad/networking.cc +++ b/selfdrive/ui/qt/offroad/networking.cc @@ -139,7 +139,7 @@ AdvancedNetworking::AdvancedNetworking(QWidget* parent, WifiManager* wifi): QWid list->addItem(editPasswordButton); // IP address - ipLabel = new LabelControl("IP Address", wifi->ipv4_address); + ipLabel = new LabelControl("IP Address"); list->addItem(ipLabel); // SSH keys diff --git a/selfdrive/ui/qt/offroad/networkmanager.h b/selfdrive/ui/qt/offroad/networkmanager.h index 52d85c16afffb6..b69a21fe5d1d7e 100644 --- a/selfdrive/ui/qt/offroad/networkmanager.h +++ b/selfdrive/ui/qt/offroad/networkmanager.h @@ -23,10 +23,11 @@ const QString NM_DBUS_INTERFACE_PROPERTIES = "org.freedesktop.DBus.Prop const QString NM_DBUS_INTERFACE_SETTINGS = "org.freedesktop.NetworkManager.Settings"; const QString NM_DBUS_INTERFACE_SETTINGS_CONNECTION = "org.freedesktop.NetworkManager.Settings.Connection"; const QString NM_DBUS_INTERFACE_DEVICE = "org.freedesktop.NetworkManager.Device"; +const QString NM_DBUS_INTERFACE_DEVICE_IP4_ADDRESS = "org.freedesktop.NetworkManager.Device.Ip4Address"; const QString NM_DBUS_INTERFACE_DEVICE_WIRELESS = "org.freedesktop.NetworkManager.Device.Wireless"; const QString NM_DBUS_INTERFACE_ACCESS_POINT = "org.freedesktop.NetworkManager.AccessPoint"; const QString NM_DBUS_INTERFACE_ACTIVE_CONNECTION = "org.freedesktop.NetworkManager.Connection.Active"; -const QString NM_DBUS_INTERFACE_IP4_CONFIG = "org.freedesktop.NetworkManager.IP4Config"; +const QString NM_DBUS_INTERFACE_IP4_CONFIG = "org.freedesktop.NetworkManager.Ip4Address"; const QString NM_DBUS_SERVICE = "org.freedesktop.NetworkManager"; diff --git a/selfdrive/ui/qt/offroad/wifiManager.cc b/selfdrive/ui/qt/offroad/wifiManager.cc index 9046efb7af86fa..c288a9757ae347 100644 --- a/selfdrive/ui/qt/offroad/wifiManager.cc +++ b/selfdrive/ui/qt/offroad/wifiManager.cc @@ -1,7 +1,9 @@ #include "selfdrive/ui/qt/offroad/wifiManager.h" +#include #include +#include #include "selfdrive/common/params.h" #include "selfdrive/ui/qt/util.h" @@ -31,9 +33,13 @@ void WifiManager::setup() { bus.connect(NM_DBUS_SERVICE, NM_DBUS_PATH_SETTINGS, NM_DBUS_INTERFACE_SETTINGS, "ConnectionRemoved", this, SLOT(connectionRemoved(QDBusObjectPath))); bus.connect(NM_DBUS_SERVICE, NM_DBUS_PATH_SETTINGS, NM_DBUS_INTERFACE_SETTINGS, "NewConnection", this, SLOT(newConnection(QDBusObjectPath))); - raw_adapter_state = call(adapter, NM_DBUS_INTERFACE_PROPERTIES, "Get", NM_DBUS_INTERFACE_DEVICE, "State"); activeAp = call(adapter, NM_DBUS_INTERFACE_PROPERTIES, "Get", NM_DBUS_INTERFACE_DEVICE_WIRELESS, "ActiveAccessPoint").path(); - + + QDBusReply> replay = call(adapter, NM_DBUS_INTERFACE_PROPERTIES, "GetAll", NM_DBUS_INTERFACE_DEVICE); + auto properties = replay.value(); + raw_adapter_state = properties["State"].toUInt(); + setIP4Address(properties["Ip4Address"].toUInt()); + initConnections(); requestScan(); } @@ -78,28 +84,13 @@ void WifiManager::activationFinished(QDBusPendingCallWatcher *watcher) { seenNetworks[ssid] = {ssid, strength, ctype, security}; } - ipv4_address = get_ipv4_address(); emit refreshSignal(); watcher->deleteLater(); } -QString WifiManager::get_ipv4_address() { - for (const auto &p : get_active_connections()) { - QString type = call(p.path(), NM_DBUS_INTERFACE_PROPERTIES, "Get", NM_DBUS_INTERFACE_ACTIVE_CONNECTION, "Type"); - if (type == "802-11-wireless") { - auto ip4config = call(p.path(), NM_DBUS_INTERFACE_PROPERTIES, "Get", NM_DBUS_INTERFACE_ACTIVE_CONNECTION, "Ip4Config"); - const auto &arr = call(ip4config.path(), NM_DBUS_INTERFACE_PROPERTIES, "Get", NM_DBUS_INTERFACE_IP4_CONFIG, "AddressData"); - QMap pth2; - arr.beginArray(); - while (!arr.atEnd()) { - arr >> pth2; - arr.endArray(); - return pth2.value("address").value(); - } - arr.endArray(); - } - } - return ""; +void WifiManager::setIP4Address(uint address) { + ipv4_address = QHostAddress(htonl(address)).toString(); + emit ipAddressChanged(ipv4_address); } SecurityType WifiManager::getSecurityType(const QMap &properties) { @@ -223,13 +214,17 @@ void WifiManager::stateChange(unsigned int new_state, unsigned int previous_stat // https://developer.gnome.org/NetworkManager/stable/gdbus-org.freedesktop.NetworkManager.Device.Wireless.html void WifiManager::propertyChange(const QString &interface, const QVariantMap &props, const QStringList &invalidated_props) { - if (interface == NM_DBUS_INTERFACE_DEVICE_WIRELESS && props.contains("LastScan")) { - if (!stop_ || firstScan) { - refreshNetworks(); - firstScan = false; + if (interface == NM_DBUS_INTERFACE_DEVICE_WIRELESS) { + if (props.contains("LastScan")) { + if (!stop_ || firstScan) { + refreshNetworks(); + firstScan = false; + } + } else if (props.contains("ActiveAccessPoint")) { + activeAp = props.value("ActiveAccessPoint").value().path(); } - } else if (interface == NM_DBUS_INTERFACE_DEVICE_WIRELESS && props.contains("ActiveAccessPoint")) { - activeAp = props.value("ActiveAccessPoint").value().path(); + } else if (props.contains("Ip4Address")) { + setIP4Address(props["Ip4Address"].toUInt()); } } diff --git a/selfdrive/ui/qt/offroad/wifiManager.h b/selfdrive/ui/qt/offroad/wifiManager.h index b4bce8153e5326..e087604e572987 100644 --- a/selfdrive/ui/qt/offroad/wifiManager.h +++ b/selfdrive/ui/qt/offroad/wifiManager.h @@ -81,7 +81,7 @@ class WifiManager : public QObject { QTimer timer; QString getAdapter(const uint = NM_DEVICE_TYPE_WIFI); uint getAdapterType(const QDBusObjectPath &path); - QString get_ipv4_address(); + void setIP4Address(uint address); QString activeAp; void deactivateConnectionBySsid(const QString &ssid); void deactivateConnection(const QDBusObjectPath &path); @@ -117,6 +117,7 @@ class WifiManager : public QObject { signals: void wrongPassword(const QString &ssid); void refreshSignal(); + void ipAddressChanged(const QString &ip4_address); private slots: void stateChange(unsigned int new_state, unsigned int previous_state, unsigned int change_reason);