You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					493 lines
				
				19 KiB
			
		
		
			
		
	
	
					493 lines
				
				19 KiB
			| 
								 
											2 years ago
										 
									 | 
							
								#include "selfdrive/ui/qt/network/wifi_manager.h"
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								#include "selfdrive/ui/ui.h"
							 | 
						||
| 
								 | 
							
								#include "selfdrive/ui/qt/widgets/prime.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								#include "common/params.h"
							 | 
						||
| 
								 | 
							
								#include "common/swaglog.h"
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								#include "selfdrive/ui/qt/util.h"
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								bool compare_by_strength(const Network &a, const Network &b) {
							 | 
						||
| 
								 
											2 years ago
										 
									 | 
							
								  return std::tuple(a.connected, strengthLevel(a.strength), b.ssid) >
							 | 
						||
| 
								 | 
							
								         std::tuple(b.connected, strengthLevel(b.strength), a.ssid);
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								template <typename T = QDBusMessage, typename... Args>
							 | 
						||
| 
								 | 
							
								T call(const QString &path, const QString &interface, const QString &method, Args &&...args) {
							 | 
						||
| 
								 | 
							
								  QDBusInterface nm = QDBusInterface(NM_DBUS_SERVICE, path, interface, QDBusConnection::systemBus());
							 | 
						||
| 
								 | 
							
								  nm.setTimeout(DBUS_TIMEOUT);
							 | 
						||
| 
								 | 
							
								  QDBusMessage response = nm.call(method, args...);
							 | 
						||
| 
								 | 
							
								  if constexpr (std::is_same_v<T, QDBusMessage>) {
							 | 
						||
| 
								 | 
							
								    return response;
							 | 
						||
| 
								 | 
							
								  } else if (response.arguments().count() >= 1) {
							 | 
						||
| 
								 | 
							
								    QVariant vFirst = response.arguments().at(0).value<QDBusVariant>().variant();
							 | 
						||
| 
								 | 
							
								    if (vFirst.canConvert<T>()) {
							 | 
						||
| 
								 | 
							
								      return vFirst.value<T>();
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								    QDebug critical = qCritical();
							 | 
						||
| 
								 | 
							
								    critical << "Variant unpacking failure :" << method << ',';
							 | 
						||
| 
								 | 
							
								    (critical << ... << args);
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								  return T();
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								template <typename... Args>
							 | 
						||
| 
								 | 
							
								QDBusPendingCall asyncCall(const QString &path, const QString &interface, const QString &method, Args &&...args) {
							 | 
						||
| 
								 | 
							
								  QDBusInterface nm = QDBusInterface(NM_DBUS_SERVICE, path, interface, QDBusConnection::systemBus());
							 | 
						||
| 
								 | 
							
								  return nm.asyncCall(method, args...);
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											2 years ago
										 
									 | 
							
								bool emptyPath(const QString &path) {
							 | 
						||
| 
								 | 
							
								  return path == "" || path == "/";
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								WifiManager::WifiManager(QObject *parent) : QObject(parent) {
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  qDBusRegisterMetaType<Connection>();
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  qDBusRegisterMetaType<IpConfig>();
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  // Set tethering ssid as "weedle" + first 4 characters of a dongle id
							 | 
						||
| 
								 | 
							
								  tethering_ssid = "weedle";
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  if (auto dongle_id = getDongleId()) {
							 | 
						||
| 
								 | 
							
								    tethering_ssid += "-" + dongle_id->left(4);
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  }
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  adapter = getAdapter();
							 | 
						||
| 
								 | 
							
								  if (!adapter.isEmpty()) {
							 | 
						||
| 
								 | 
							
								    setup();
							 | 
						||
| 
								 | 
							
								  } else {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    QDBusConnection::systemBus().connect(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "DeviceAdded", this, SLOT(deviceAdded(QDBusObjectPath)));
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  timer.callOnTimeout(this, &WifiManager::requestScan);
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void WifiManager::setup() {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  auto bus = QDBusConnection::systemBus();
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  bus.connect(NM_DBUS_SERVICE, adapter, NM_DBUS_INTERFACE_DEVICE, "StateChanged", this, SLOT(stateChange(unsigned int, unsigned int, unsigned int)));
							 | 
						||
| 
								 | 
							
								  bus.connect(NM_DBUS_SERVICE, adapter, NM_DBUS_INTERFACE_PROPERTIES, "PropertiesChanged", this, SLOT(propertyChange(QString, QVariantMap, QStringList)));
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  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)));
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  raw_adapter_state = call<uint>(adapter, NM_DBUS_INTERFACE_PROPERTIES, "Get", NM_DBUS_INTERFACE_DEVICE, "State");
							 | 
						||
| 
								 | 
							
								  activeAp = call<QDBusObjectPath>(adapter, NM_DBUS_INTERFACE_PROPERTIES, "Get", NM_DBUS_INTERFACE_DEVICE_WIRELESS, "ActiveAccessPoint").path();
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								  initConnections();
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  requestScan();
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								void WifiManager::start() {
							 | 
						||
| 
								 | 
							
								  timer.start(5000);
							 | 
						||
| 
								 | 
							
								  refreshNetworks();
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void WifiManager::stop() {
							 | 
						||
| 
								 | 
							
								  timer.stop();
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								void WifiManager::refreshNetworks() {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  if (adapter.isEmpty() || !timer.isActive()) return;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  QDBusPendingCall pending_call = asyncCall(adapter, NM_DBUS_INTERFACE_DEVICE_WIRELESS, "GetAllAccessPoints");
							 | 
						||
| 
								 | 
							
								  QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pending_call);
							 | 
						||
| 
								 | 
							
								  QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, &WifiManager::refreshFinished);
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void WifiManager::refreshFinished(QDBusPendingCallWatcher *watcher) {
							 | 
						||
| 
								 | 
							
								  ipv4_address = getIp4Address();
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  seenNetworks.clear();
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  const QDBusReply<QList<QDBusObjectPath>> wather_reply = *watcher;
							 | 
						||
| 
								 | 
							
								  for (const QDBusObjectPath &path : wather_reply.value()) {
							 | 
						||
| 
								 | 
							
								    QDBusReply<QVariantMap> replay = call(path.path(), NM_DBUS_INTERFACE_PROPERTIES, "GetAll", NM_DBUS_INTERFACE_ACCESS_POINT);
							 | 
						||
| 
								 | 
							
								    auto properties = replay.value();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    const QByteArray ssid = properties["Ssid"].toByteArray();
							 | 
						||
| 
								 
											2 years ago
										 
									 | 
							
								    if (ssid.isEmpty()) continue;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    // May be multiple access points for each SSID.
							 | 
						||
| 
								 | 
							
								    // Use first for ssid and security type, then update connected status and strength using all
							 | 
						||
| 
								 | 
							
								    if (!seenNetworks.contains(ssid)) {
							 | 
						||
| 
								 | 
							
								      seenNetworks[ssid] = {ssid, 0U, ConnectedType::DISCONNECTED, getSecurityType(properties)};
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								    if (path.path() == activeAp) {
							 | 
						||
| 
								 
											2 years ago
										 
									 | 
							
								      seenNetworks[ssid].connected = (ssid == connecting_to_network) ? ConnectedType::CONNECTING : ConnectedType::CONNECTED;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    uint32_t strength = properties["Strength"].toUInt();
							 | 
						||
| 
								 | 
							
								    if (seenNetworks[ssid].strength < strength) {
							 | 
						||
| 
								 | 
							
								      seenNetworks[ssid].strength = strength;
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    }
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  }
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  emit refreshSignal();
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  watcher->deleteLater();
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								QString WifiManager::getIp4Address() {
							 | 
						||
| 
								 | 
							
								  if (raw_adapter_state != NM_DEVICE_STATE_ACTIVATED) return "";
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  for (const auto &p : getActiveConnections()) {
							 | 
						||
| 
								 | 
							
								    QString type = call<QString>(p.path(), NM_DBUS_INTERFACE_PROPERTIES, "Get", NM_DBUS_INTERFACE_ACTIVE_CONNECTION, "Type");
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								    if (type == "802-11-wireless") {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								      auto ip4config = call<QDBusObjectPath>(p.path(), NM_DBUS_INTERFACE_PROPERTIES, "Get", NM_DBUS_INTERFACE_ACTIVE_CONNECTION, "Ip4Config");
							 | 
						||
| 
								 | 
							
								      const auto &arr = call<QDBusArgument>(ip4config.path(), NM_DBUS_INTERFACE_PROPERTIES, "Get", NM_DBUS_INTERFACE_IP4_CONFIG, "AddressData");
							 | 
						||
| 
								 | 
							
								      QVariantMap path;
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								      arr.beginArray();
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								      while (!arr.atEnd()) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								        arr >> path;
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								        arr.endArray();
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								        return path.value("address").value<QString>();
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								      }
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								      arr.endArray();
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								  return "";
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								SecurityType WifiManager::getSecurityType(const QVariantMap &properties) {
							 | 
						||
| 
								 | 
							
								  int sflag = properties["Flags"].toUInt();
							 | 
						||
| 
								 | 
							
								  int wpaflag = properties["WpaFlags"].toUInt();
							 | 
						||
| 
								 | 
							
								  int rsnflag = properties["RsnFlags"].toUInt();
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  int wpa_props = wpaflag | rsnflag;
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  // obtained by looking at flags of networks in the office as reported by an Android phone
							 | 
						||
| 
								 | 
							
								  const int supports_wpa = NM_802_11_AP_SEC_PAIR_WEP40 | NM_802_11_AP_SEC_PAIR_WEP104 | NM_802_11_AP_SEC_GROUP_WEP40 | NM_802_11_AP_SEC_GROUP_WEP104 | NM_802_11_AP_SEC_KEY_MGMT_PSK;
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  if ((sflag == NM_802_11_AP_FLAGS_NONE) || ((sflag & NM_802_11_AP_FLAGS_WPS) && !(wpa_props & supports_wpa))) {
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								    return SecurityType::OPEN;
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  } else if ((sflag & NM_802_11_AP_FLAGS_PRIVACY) && (wpa_props & supports_wpa) && !(wpa_props & NM_802_11_AP_SEC_KEY_MGMT_802_1X)) {
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								    return SecurityType::WPA;
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  } else {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    LOGW("Unsupported network! sflag: %d, wpaflag: %d, rsnflag: %d", sflag, wpaflag, rsnflag);
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								    return SecurityType::UNSUPPORTED;
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								void WifiManager::connect(const Network &n, const QString &password, const QString &username) {
							 | 
						||
| 
								 
											2 years ago
										 
									 | 
							
								  setCurrentConnecting(n.ssid);
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  forgetConnection(n.ssid);  // Clear all connections that may already exist to the network we are connecting
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  Connection connection;
							 | 
						||
| 
								 | 
							
								  connection["connection"]["type"] = "802-11-wireless";
							 | 
						||
| 
								 | 
							
								  connection["connection"]["uuid"] = QUuid::createUuid().toString().remove('{').remove('}');
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  connection["connection"]["id"] = "openpilot connection " + QString::fromStdString(n.ssid.toStdString());
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  connection["connection"]["autoconnect-retries"] = 0;
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  connection["802-11-wireless"]["ssid"] = n.ssid;
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  connection["802-11-wireless"]["mode"] = "infrastructure";
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  if (n.security_type == SecurityType::WPA) {
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								    connection["802-11-wireless-security"]["key-mgmt"] = "wpa-psk";
							 | 
						||
| 
								 | 
							
								    connection["802-11-wireless-security"]["auth-alg"] = "open";
							 | 
						||
| 
								 | 
							
								    connection["802-11-wireless-security"]["psk"] = password;
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  connection["ipv4"]["method"] = "auto";
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  connection["ipv4"]["dns-priority"] = 600;
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  connection["ipv6"]["method"] = "ignore";
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  call(NM_DBUS_PATH_SETTINGS, NM_DBUS_INTERFACE_SETTINGS, "AddConnection", QVariant::fromValue(connection));
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								void WifiManager::deactivateConnectionBySsid(const QString &ssid) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  for (QDBusObjectPath active_connection : getActiveConnections()) {
							 | 
						||
| 
								 | 
							
								    auto pth = call<QDBusObjectPath>(active_connection.path(), NM_DBUS_INTERFACE_PROPERTIES, "Get", NM_DBUS_INTERFACE_ACTIVE_CONNECTION, "SpecificObject");
							 | 
						||
| 
								 
											2 years ago
										 
									 | 
							
								    if (!emptyPath(pth.path())) {
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								      QString Ssid = get_property(pth.path(), "Ssid");
							 | 
						||
| 
								 | 
							
								      if (Ssid == ssid) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								        deactivateConnection(active_connection);
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								        return;
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								      }
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								    }
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								void WifiManager::deactivateConnection(const QDBusObjectPath &path) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  asyncCall(NM_DBUS_PATH, NM_DBUS_INTERFACE, "DeactivateConnection", QVariant::fromValue(path));
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								QVector<QDBusObjectPath> WifiManager::getActiveConnections() {
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  QVector<QDBusObjectPath> conns;
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  QDBusObjectPath path;
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  const QDBusArgument &arr = call<QDBusArgument>(NM_DBUS_PATH, NM_DBUS_INTERFACE_PROPERTIES, "Get", NM_DBUS_INTERFACE, "ActiveConnections");
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  arr.beginArray();
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  while (!arr.atEnd()) {
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								    arr >> path;
							 | 
						||
| 
								 | 
							
								    conns.push_back(path);
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  }
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  arr.endArray();
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  return conns;
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								bool WifiManager::isKnownConnection(const QString &ssid) {
							 | 
						||
| 
								 | 
							
								  return !getConnectionPath(ssid).path().isEmpty();
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								void WifiManager::forgetConnection(const QString &ssid) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  const QDBusObjectPath &path = getConnectionPath(ssid);
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  if (!path.path().isEmpty()) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    call(path.path(), NM_DBUS_INTERFACE_SETTINGS_CONNECTION, "Delete");
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											2 years ago
										 
									 | 
							
								void WifiManager::setCurrentConnecting(const QString &ssid) {
							 | 
						||
| 
								 | 
							
								  connecting_to_network = ssid;
							 | 
						||
| 
								 
											2 years ago
										 
									 | 
							
								  for (auto &network : seenNetworks) {
							 | 
						||
| 
								 
											2 years ago
										 
									 | 
							
								    network.connected = (network.ssid == ssid) ? ConnectedType::CONNECTING : ConnectedType::DISCONNECTED;
							 | 
						||
| 
								 
											2 years ago
										 
									 | 
							
								  }
							 | 
						||
| 
								 | 
							
								  emit refreshSignal();
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								uint WifiManager::getAdapterType(const QDBusObjectPath &path) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  return call<uint>(path.path(), NM_DBUS_INTERFACE_PROPERTIES, "Get", NM_DBUS_INTERFACE_DEVICE, "DeviceType");
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								void WifiManager::requestScan() {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  if (!adapter.isEmpty()) {
							 | 
						||
| 
								 | 
							
								    asyncCall(adapter, NM_DBUS_INTERFACE_DEVICE_WIRELESS, "RequestScan", QVariantMap());
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								QByteArray WifiManager::get_property(const QString &network_path , const QString &property) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  return call<QByteArray>(network_path, NM_DBUS_INTERFACE_PROPERTIES, "Get", NM_DBUS_INTERFACE_ACCESS_POINT, property);
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								QString WifiManager::getAdapter(const uint adapter_type) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  QDBusReply<QList<QDBusObjectPath>> response = call(NM_DBUS_PATH, NM_DBUS_INTERFACE, "GetDevices");
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  for (const QDBusObjectPath &path : response.value()) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    if (getAdapterType(path) == adapter_type) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								      return path.path();
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								    }
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  return "";
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								void WifiManager::stateChange(unsigned int new_state, unsigned int previous_state, unsigned int change_reason) {
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  raw_adapter_state = new_state;
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  if (new_state == NM_DEVICE_STATE_NEED_AUTH && change_reason == NM_DEVICE_STATE_REASON_SUPPLICANT_DISCONNECT && !connecting_to_network.isEmpty()) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    forgetConnection(connecting_to_network);
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								    emit wrongPassword(connecting_to_network);
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  } else if (new_state == NM_DEVICE_STATE_ACTIVATED) {
							 | 
						||
| 
								 
											2 years ago
										 
									 | 
							
								    connecting_to_network = "";
							 | 
						||
| 
								 | 
							
								    refreshNetworks();
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								// 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) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  if (interface == NM_DBUS_INTERFACE_DEVICE_WIRELESS && props.contains("LastScan")) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    refreshNetworks();
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  } else if (interface == NM_DBUS_INTERFACE_DEVICE_WIRELESS && props.contains("ActiveAccessPoint")) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    activeAp = props.value("ActiveAccessPoint").value<QDBusObjectPath>().path();
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								void WifiManager::deviceAdded(const QDBusObjectPath &path) {
							 | 
						||
| 
								 
											2 years ago
										 
									 | 
							
								  if (getAdapterType(path) == NM_DEVICE_TYPE_WIFI && emptyPath(adapter)) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    adapter = path.path();
							 | 
						||
| 
								 | 
							
								    setup();
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								void WifiManager::connectionRemoved(const QDBusObjectPath &path) {
							 | 
						||
| 
								 | 
							
								  knownConnections.remove(path);
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								void WifiManager::newConnection(const QDBusObjectPath &path) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  Connection settings = getConnectionSettings(path);
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  if (settings.value("connection").value("type") == "802-11-wireless") {
							 | 
						||
| 
								 | 
							
								    knownConnections[path] = settings.value("802-11-wireless").value("ssid").toString();
							 | 
						||
| 
								 | 
							
								    if (knownConnections[path] != tethering_ssid) {
							 | 
						||
| 
								 | 
							
								      activateWifiConnection(knownConnections[path]);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  }
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								QDBusObjectPath WifiManager::getConnectionPath(const QString &ssid) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  return knownConnections.key(ssid);
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								Connection WifiManager::getConnectionSettings(const QDBusObjectPath &path) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  return QDBusReply<Connection>(call(path.path(), NM_DBUS_INTERFACE_SETTINGS_CONNECTION, "GetSettings")).value();
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								void WifiManager::initConnections() {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  const QDBusReply<QList<QDBusObjectPath>> response = call(NM_DBUS_PATH_SETTINGS, NM_DBUS_INTERFACE_SETTINGS, "ListConnections");
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  for (const QDBusObjectPath &path : response.value()) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    const Connection settings = getConnectionSettings(path);
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    if (settings.value("connection").value("type") == "802-11-wireless") {
							 | 
						||
| 
								 | 
							
								      knownConnections[path] = settings.value("802-11-wireless").value("ssid").toString();
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								    } else if (settings.value("connection").value("id") == "lte") {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								      lteConnectionPath = path;
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    }
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								std::optional<QDBusPendingCall> WifiManager::activateWifiConnection(const QString &ssid) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  const QDBusObjectPath &path = getConnectionPath(ssid);
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  if (!path.path().isEmpty()) {
							 | 
						||
| 
								 
											2 years ago
										 
									 | 
							
								    setCurrentConnecting(ssid);
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    return asyncCall(NM_DBUS_PATH, NM_DBUS_INTERFACE, "ActivateConnection", QVariant::fromValue(path), QVariant::fromValue(QDBusObjectPath(adapter)), QVariant::fromValue(QDBusObjectPath("/")));
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  }
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  return std::nullopt;
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								void WifiManager::activateModemConnection(const QDBusObjectPath &path) {
							 | 
						||
| 
								 | 
							
								  QString modem = getAdapter(NM_DEVICE_TYPE_MODEM);
							 | 
						||
| 
								 | 
							
								  if (!path.path().isEmpty() && !modem.isEmpty()) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    asyncCall(NM_DBUS_PATH, NM_DBUS_INTERFACE, "ActivateConnection", QVariant::fromValue(path), QVariant::fromValue(QDBusObjectPath(modem)), QVariant::fromValue(QDBusObjectPath("/")));
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								// function matches tici/hardware.py
							 | 
						||
| 
								 | 
							
								NetworkType WifiManager::currentNetworkType() {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  auto primary_conn = call<QDBusObjectPath>(NM_DBUS_PATH, NM_DBUS_INTERFACE_PROPERTIES, "Get", NM_DBUS_INTERFACE, "PrimaryConnection");
							 | 
						||
| 
								 | 
							
								  auto primary_type = call<QString>(primary_conn.path(), NM_DBUS_INTERFACE_PROPERTIES, "Get", NM_DBUS_INTERFACE_ACTIVE_CONNECTION, "Type");
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  if (primary_type == "802-3-ethernet") {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    return NetworkType::ETHERNET;
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  } else if (primary_type == "802-11-wireless" && !isTetheringEnabled()) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    return NetworkType::WIFI;
							 | 
						||
| 
								 | 
							
								  } else {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    for (const QDBusObjectPath &conn : getActiveConnections()) {
							 | 
						||
| 
								 | 
							
								      auto type = call<QString>(conn.path(), NM_DBUS_INTERFACE_PROPERTIES, "Get", NM_DBUS_INTERFACE_ACTIVE_CONNECTION, "Type");
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								      if (type == "gsm") {
							 | 
						||
| 
								 | 
							
								        return NetworkType::CELL;
							 | 
						||
| 
								 | 
							
								      }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								  return NetworkType::NONE;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								void WifiManager::updateGsmSettings(bool roaming, QString apn, bool metered) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  if (!lteConnectionPath.path().isEmpty()) {
							 | 
						||
| 
								 | 
							
								    bool changes = false;
							 | 
						||
| 
								 | 
							
								    bool auto_config = apn.isEmpty();
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    Connection settings = getConnectionSettings(lteConnectionPath);
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    if (settings.value("gsm").value("auto-config").toBool() != auto_config) {
							 | 
						||
| 
								 | 
							
								      qWarning() << "Changing gsm.auto-config to" << auto_config;
							 | 
						||
| 
								 | 
							
								      settings["gsm"]["auto-config"] = auto_config;
							 | 
						||
| 
								 | 
							
								      changes = true;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    if (settings.value("gsm").value("apn").toString() != apn) {
							 | 
						||
| 
								 | 
							
								      qWarning() << "Changing gsm.apn to" << apn;
							 | 
						||
| 
								 | 
							
								      settings["gsm"]["apn"] = apn;
							 | 
						||
| 
								 | 
							
								      changes = true;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    if (settings.value("gsm").value("home-only").toBool() == roaming) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								      qWarning() << "Changing gsm.home-only to" << !roaming;
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								      settings["gsm"]["home-only"] = !roaming;
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								      changes = true;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								    int meteredInt = metered ? NM_METERED_UNKNOWN : NM_METERED_NO;
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								    if (settings.value("connection").value("metered").toInt() != meteredInt) {
							 | 
						||
| 
								 | 
							
								      qWarning() << "Changing connection.metered to" << meteredInt;
							 | 
						||
| 
								 | 
							
								      settings["connection"]["metered"] = meteredInt;
							 | 
						||
| 
								 | 
							
								      changes = true;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    if (changes) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								      call(lteConnectionPath.path(), NM_DBUS_INTERFACE_SETTINGS_CONNECTION, "UpdateUnsaved", QVariant::fromValue(settings));  // update is temporary
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								      deactivateConnection(lteConnectionPath);
							 | 
						||
| 
								 | 
							
								      activateModemConnection(lteConnectionPath);
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    }
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								// Functions for tethering
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								void WifiManager::addTetheringConnection() {
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  Connection connection;
							 | 
						||
| 
								 | 
							
								  connection["connection"]["id"] = "Hotspot";
							 | 
						||
| 
								 | 
							
								  connection["connection"]["uuid"] = QUuid::createUuid().toString().remove('{').remove('}');
							 | 
						||
| 
								 | 
							
								  connection["connection"]["type"] = "802-11-wireless";
							 | 
						||
| 
								 | 
							
								  connection["connection"]["interface-name"] = "wlan0";
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  connection["connection"]["autoconnect"] = false;
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								  connection["802-11-wireless"]["band"] = "bg";
							 | 
						||
| 
								 | 
							
								  connection["802-11-wireless"]["mode"] = "ap";
							 | 
						||
| 
								 | 
							
								  connection["802-11-wireless"]["ssid"] = tethering_ssid.toUtf8();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  connection["802-11-wireless-security"]["group"] = QStringList("ccmp");
							 | 
						||
| 
								 | 
							
								  connection["802-11-wireless-security"]["key-mgmt"] = "wpa-psk";
							 | 
						||
| 
								 | 
							
								  connection["802-11-wireless-security"]["pairwise"] = QStringList("ccmp");
							 | 
						||
| 
								 | 
							
								  connection["802-11-wireless-security"]["proto"] = QStringList("rsn");
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  connection["802-11-wireless-security"]["psk"] = defaultTetheringPassword;
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								  connection["ipv4"]["method"] = "shared";
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  QVariantMap address;
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  address["address"] = "192.168.43.1";
							 | 
						||
| 
								 | 
							
								  address["prefix"] = 24u;
							 | 
						||
| 
								 | 
							
								  connection["ipv4"]["address-data"] = QVariant::fromValue(IpConfig() << address);
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  connection["ipv4"]["gateway"] = "192.168.43.1";
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  connection["ipv4"]["route-metric"] = 1100;
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  connection["ipv6"]["method"] = "ignore";
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  call(NM_DBUS_PATH_SETTINGS, NM_DBUS_INTERFACE_SETTINGS, "AddConnection", QVariant::fromValue(connection));
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								void WifiManager::tetheringActivated(QDBusPendingCallWatcher *call) {
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								  int prime_type = uiState()->primeType();
							 | 
						||
| 
								 
											3 years ago
										 
									 | 
							
								  int ipv4_forward = (prime_type == PrimeType::NONE || prime_type == PrimeType::LITE);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  if (!ipv4_forward) {
							 | 
						||
| 
								 | 
							
								    QTimer::singleShot(5000, this, [=] {
							 | 
						||
| 
								 | 
							
								      qWarning() << "net.ipv4.ip_forward = 0";
							 | 
						||
| 
								 | 
							
								      std::system("sudo sysctl net.ipv4.ip_forward=0");
							 | 
						||
| 
								 | 
							
								    });
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								  call->deleteLater();
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								void WifiManager::setTetheringEnabled(bool enabled) {
							 | 
						||
| 
								 | 
							
								  if (enabled) {
							 | 
						||
| 
								 | 
							
								    if (!isKnownConnection(tethering_ssid)) {
							 | 
						||
| 
								 | 
							
								      addTetheringConnection();
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								    auto pending_call = activateWifiConnection(tethering_ssid);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    if (pending_call) {
							 | 
						||
| 
								 | 
							
								      QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(*pending_call);
							 | 
						||
| 
								 | 
							
								      QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, &WifiManager::tetheringActivated);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  } else {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    deactivateConnectionBySsid(tethering_ssid);
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								  }
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								bool WifiManager::isTetheringEnabled() {
							 | 
						||
| 
								 
											2 years ago
										 
									 | 
							
								  if (!emptyPath(activeAp)) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    return get_property(activeAp, "Ssid") == tethering_ssid;
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  }
							 | 
						||
| 
								 | 
							
								  return false;
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								QString WifiManager::getTetheringPassword() {
							 | 
						||
| 
								 | 
							
								  if (!isKnownConnection(tethering_ssid)) {
							 | 
						||
| 
								 | 
							
								    addTetheringConnection();
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								  const QDBusObjectPath &path = getConnectionPath(tethering_ssid);
							 | 
						||
| 
								 | 
							
								  if (!path.path().isEmpty()) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    QDBusReply<QMap<QString, QVariantMap>> response = call(path.path(), NM_DBUS_INTERFACE_SETTINGS_CONNECTION, "GetSecrets", "802-11-wireless-security");
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    return response.value().value("802-11-wireless-security").value("psk").toString();
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								  return "";
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								void WifiManager::changeTetheringPassword(const QString &newPassword) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  const QDBusObjectPath &path = getConnectionPath(tethering_ssid);
							 | 
						||
| 
								 | 
							
								  if (!path.path().isEmpty()) {
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    Connection settings = getConnectionSettings(path);
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    settings["802-11-wireless-security"]["psk"] = newPassword;
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    call(path.path(), NM_DBUS_INTERFACE_SETTINGS_CONNECTION, "Update", QVariant::fromValue(settings));
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								    if (isTetheringEnabled()) {
							 | 
						||
| 
								 | 
							
								      activateWifiConnection(tethering_ssid);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 
											4 years ago
										 
									 | 
							
								  }
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								}
							 |