#pragma once // Qt #include #include // Project #include "main.h" #include "Network.h" // define #define _WifiInterface WifiInterface::I() /*! * \brief The WifiInterface class * Communicates with Access Points * \details * - Scans for Access Points * - Authenticates with Access Points * - Disconnects from Access Points */ class WifiInterface : public QObject { Q_OBJECT QThread *_thread = nullptr; bool _init = false; bool _scanRunning = false; int _defaultTimeout = 5000; int _dhcpTimeout = 10000; QProcess _processScan; QProcess _processJoinNetwork; QProcess _processGetIPAddress; Network _network; const QString _iface = "wlan0"; const QString _wpaSupplicantConfPath = "/etc/wpa_supplicant.conf"; // Singleton SINGLETON(WifiInterface) private: bool generateWPASupplicant(const Network &vNetwork, const QString &vPassword); bool startWPASupplicant(); bool requestAutoAssignedIP(); QString readIPSettings(); QString readGateway(); QString readDNS(); QString parseIP(const QString &vOutput); QString parseBroadcast(const QString &vOutput); QString parseSubnetMask(const QString &vOutput); QString parseGateway(const QString &vOutput); QString parseDNS(const QString &vOutput); void onInitConnections(); void onQuitThread(); void timerEvent(QTimerEvent* event); public slots: bool doInit(); void doScan(); void doJoinNetwork(const Network &vNetwork, const QString &vPassword); signals: void didAddNetwork(const Network); void didScanStatusChanged(const bool); void didConnectToNetwork(const Network); void didFailToConnect(const QString); private slots: void onQuit(); void onScanFinished(int, QProcess::ExitStatus); void onParseWifiScan(const QString &vOutput); void onLogFailure(const QString &vMessage); };