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.
		
		
		
		
			
				
					103 lines
				
				3.2 KiB
			
		
		
			
		
	
	
					103 lines
				
				3.2 KiB
			| 
											5 years ago
										 | #pragma once
 | ||
| 
											5 years ago
										 | 
 | ||
| 
											4 years ago
										 | #include <optional>
 | ||
| 
											5 years ago
										 | #include <QtDBus>
 | ||
| 
											4 years ago
										 | #include <QTimer>
 | ||
| 
											5 years ago
										 | 
 | ||
| 
											2 years ago
										 | #include "selfdrive/ui/qt/network/networkmanager.h"
 | ||
| 
											4 years ago
										 | 
 | ||
| 
											5 years ago
										 | enum class SecurityType {
 | ||
|  |   OPEN,
 | ||
|  |   WPA,
 | ||
|  |   UNSUPPORTED
 | ||
|  | };
 | ||
| 
											4 years ago
										 | enum class ConnectedType {
 | ||
| 
											5 years ago
										 |   DISCONNECTED,
 | ||
|  |   CONNECTING,
 | ||
|  |   CONNECTED
 | ||
|  | };
 | ||
| 
											4 years ago
										 | enum class NetworkType {
 | ||
|  |   NONE,
 | ||
|  |   WIFI,
 | ||
|  |   CELL,
 | ||
|  |   ETHERNET
 | ||
|  | };
 | ||
| 
											5 years ago
										 | 
 | ||
| 
											4 years ago
										 | typedef QMap<QString, QVariantMap> Connection;
 | ||
|  | typedef QVector<QVariantMap> IpConfig;
 | ||
| 
											5 years ago
										 | 
 | ||
|  | struct Network {
 | ||
|  |   QByteArray ssid;
 | ||
|  |   unsigned int strength;
 | ||
| 
											5 years ago
										 |   ConnectedType connected;
 | ||
| 
											5 years ago
										 |   SecurityType security_type;
 | ||
|  | };
 | ||
| 
											4 years ago
										 | bool compare_by_strength(const Network &a, const Network &b);
 | ||
| 
											2 years ago
										 | inline int strengthLevel(unsigned int strength) { return std::clamp((int)round(strength / 33.), 0, 3); }
 | ||
| 
											5 years ago
										 | 
 | ||
| 
											4 years ago
										 | class WifiManager : public QObject {
 | ||
| 
											5 years ago
										 |   Q_OBJECT
 | ||
| 
											4 years ago
										 | 
 | ||
| 
											5 years ago
										 | public:
 | ||
| 
											4 years ago
										 |   QMap<QString, Network> seenNetworks;
 | ||
| 
											4 years ago
										 |   QMap<QDBusObjectPath, QString> knownConnections;
 | ||
| 
											5 years ago
										 |   QString ipv4_address;
 | ||
| 
											5 years ago
										 | 
 | ||
| 
											4 years ago
										 |   explicit WifiManager(QObject* parent);
 | ||
|  |   void start();
 | ||
|  |   void stop();
 | ||
|  |   void requestScan();
 | ||
| 
											4 years ago
										 |   void forgetConnection(const QString &ssid);
 | ||
| 
											4 years ago
										 |   bool isKnownConnection(const QString &ssid);
 | ||
| 
											4 years ago
										 |   std::optional<QDBusPendingCall> activateWifiConnection(const QString &ssid);
 | ||
| 
											4 years ago
										 |   NetworkType currentNetworkType();
 | ||
| 
											3 years ago
										 |   void updateGsmSettings(bool roaming, QString apn, bool metered);
 | ||
| 
											4 years ago
										 |   void connect(const Network &ssid, const QString &password = {}, const QString &username = {});
 | ||
| 
											5 years ago
										 | 
 | ||
| 
											5 years ago
										 |   // Tethering functions
 | ||
| 
											4 years ago
										 |   void setTetheringEnabled(bool enabled);
 | ||
|  |   bool isTetheringEnabled();
 | ||
| 
											4 years ago
										 |   void changeTetheringPassword(const QString &newPassword);
 | ||
| 
											4 years ago
										 |   QString getTetheringPassword();
 | ||
| 
											5 years ago
										 | 
 | ||
| 
											5 years ago
										 | private:
 | ||
| 
											4 years ago
										 |   QString adapter;  // Path to network manager wifi-device
 | ||
| 
											4 years ago
										 |   QTimer timer;
 | ||
| 
											4 years ago
										 |   unsigned int raw_adapter_state;  // Connection status https://developer.gnome.org/NetworkManager/1.26/nm-dbus-types.html#NMDeviceState
 | ||
| 
											5 years ago
										 |   QString connecting_to_network;
 | ||
| 
											5 years ago
										 |   QString tethering_ssid;
 | ||
| 
											4 years ago
										 |   const QString defaultTetheringPassword = "swagswagcomma";
 | ||
| 
											4 years ago
										 |   QString activeAp;
 | ||
|  |   QDBusObjectPath lteConnectionPath;
 | ||
| 
											5 years ago
										 | 
 | ||
| 
											4 years ago
										 |   QString getAdapter(const uint = NM_DEVICE_TYPE_WIFI);
 | ||
|  |   uint getAdapterType(const QDBusObjectPath &path);
 | ||
| 
											4 years ago
										 |   QString getIp4Address();
 | ||
| 
											4 years ago
										 |   void deactivateConnectionBySsid(const QString &ssid);
 | ||
|  |   void deactivateConnection(const QDBusObjectPath &path);
 | ||
| 
											4 years ago
										 |   QVector<QDBusObjectPath> getActiveConnections();
 | ||
| 
											4 years ago
										 |   QByteArray get_property(const QString &network_path, const QString &property);
 | ||
| 
											4 years ago
										 |   SecurityType getSecurityType(const QVariantMap &properties);
 | ||
| 
											4 years ago
										 |   QDBusObjectPath getConnectionPath(const QString &ssid);
 | ||
| 
											4 years ago
										 |   Connection getConnectionSettings(const QDBusObjectPath &path);
 | ||
| 
											4 years ago
										 |   void initConnections();
 | ||
| 
											4 years ago
										 |   void setup();
 | ||
| 
											4 years ago
										 |   void refreshNetworks();
 | ||
|  |   void activateModemConnection(const QDBusObjectPath &path);
 | ||
|  |   void addTetheringConnection();
 | ||
| 
											2 years ago
										 |   void setCurrentConnecting(const QString &ssid);
 | ||
| 
											5 years ago
										 | 
 | ||
|  | signals:
 | ||
| 
											4 years ago
										 |   void wrongPassword(const QString &ssid);
 | ||
| 
											4 years ago
										 |   void refreshSignal();
 | ||
|  | 
 | ||
|  | private slots:
 | ||
|  |   void stateChange(unsigned int new_state, unsigned int previous_state, unsigned int change_reason);
 | ||
|  |   void propertyChange(const QString &interface, const QVariantMap &props, const QStringList &invalidated_props);
 | ||
| 
											4 years ago
										 |   void deviceAdded(const QDBusObjectPath &path);
 | ||
| 
											4 years ago
										 |   void connectionRemoved(const QDBusObjectPath &path);
 | ||
|  |   void newConnection(const QDBusObjectPath &path);
 | ||
| 
											4 years ago
										 |   void refreshFinished(QDBusPendingCallWatcher *call);
 | ||
| 
											4 years ago
										 |   void tetheringActivated(QDBusPendingCallWatcher *call);
 | ||
| 
											5 years ago
										 | };
 |