From fb78d28b6f5107ebe16193bfbd4778bb8627bd14 Mon Sep 17 00:00:00 2001 From: Teemu Holappa Date: Wed, 3 Feb 2016 14:23:24 +0200 Subject: Merge Boot2Qt Wifi module into Network Settings Plugin. Added wpasupplicant as alternative backend for the network settings. Change-Id: Ic05b3e87def2c9a143c30e4045a36db294ce8719 Reviewed-by: Risto Avila --- src/wifi/qwificonfiguration.cpp | 146 ---------- src/wifi/qwificonfiguration.h | 57 ---- src/wifi/qwificontroller.cpp | 284 -------------------- src/wifi/qwificontroller_p.h | 109 -------- src/wifi/qwifidevice.cpp | 94 ------- src/wifi/qwifidevice.h | 44 --- src/wifi/qwifimanager.cpp | 534 ------------------------------------- src/wifi/qwifimanager.h | 118 -------- src/wifi/qwifimanager_p.h | 68 ----- src/wifi/qwifinetwork.cpp | 48 ---- src/wifi/qwifinetwork_p.h | 66 ----- src/wifi/qwifinetworklistmodel.cpp | 195 -------------- src/wifi/qwifinetworklistmodel_p.h | 57 ---- src/wifi/qwifisupplicant.cpp | 444 ------------------------------ src/wifi/qwifisupplicant_p.h | 63 ----- src/wifi/wifi.pro | 36 --- 16 files changed, 2363 deletions(-) delete mode 100644 src/wifi/qwificonfiguration.cpp delete mode 100644 src/wifi/qwificonfiguration.h delete mode 100644 src/wifi/qwificontroller.cpp delete mode 100644 src/wifi/qwificontroller_p.h delete mode 100644 src/wifi/qwifidevice.cpp delete mode 100644 src/wifi/qwifidevice.h delete mode 100644 src/wifi/qwifimanager.cpp delete mode 100644 src/wifi/qwifimanager.h delete mode 100644 src/wifi/qwifimanager_p.h delete mode 100644 src/wifi/qwifinetwork.cpp delete mode 100644 src/wifi/qwifinetwork_p.h delete mode 100644 src/wifi/qwifinetworklistmodel.cpp delete mode 100644 src/wifi/qwifinetworklistmodel_p.h delete mode 100644 src/wifi/qwifisupplicant.cpp delete mode 100644 src/wifi/qwifisupplicant_p.h delete mode 100644 src/wifi/wifi.pro (limited to 'src/wifi') diff --git a/src/wifi/qwificonfiguration.cpp b/src/wifi/qwificonfiguration.cpp deleted file mode 100644 index b532620..0000000 --- a/src/wifi/qwificonfiguration.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#include "qwificonfiguration.h" - -QT_BEGIN_NAMESPACE - -class QWifiConfigurationPrivate -{ - Q_DECLARE_PUBLIC(QWifiConfiguration) -public: - QWifiConfigurationPrivate(QWifiConfiguration *config); - - // member variables - QWifiConfiguration *const q_ptr; - QString m_ssid; - QString m_psk; - QString m_protocol; - bool m_ssidHidden; -}; - -QWifiConfigurationPrivate::QWifiConfigurationPrivate(QWifiConfiguration *config) - : q_ptr(config) - , m_ssidHidden(false) -{ -} - -/*! - \class QWifiConfiguration - \inmodule B2Qt.Wifi.Cpp - \ingroup wifi-cppclasses - \brief Used to define a network configuration. - - QWifiConfiguration object represents a single network configuration. Use it - to configure properties of your network. For example, passphrase, security - protocol to use, and so on. QWifiManager::connect() function uses this - information to find a network that matches the provided configuration, before - establishing a connection. - */ - -/*! - Constructs a configuration object with parent \a parent. -*/ -QWifiConfiguration::QWifiConfiguration(QObject *parent) - : QObject(parent) - , d_ptr(new QWifiConfigurationPrivate(this)) -{ -} - -/*! - Destroys the configuration object. -*/ -QWifiConfiguration::~QWifiConfiguration() -{ - delete d_ptr; -} - -/*! - \property QWifiConfiguration::ssid - \brief a human-readable name of a Wifi network -*/ -QString QWifiConfiguration::ssid() const -{ - Q_D(const QWifiConfiguration); - return d->m_ssid; -} - -void QWifiConfiguration::setSsid(const QString &ssid) -{ - Q_D(QWifiConfiguration); - d->m_ssid = ssid; -} - -/*! - \property QWifiConfiguration::passphrase - \brief a passphrase to use for authenticating access to a network -*/ -QString QWifiConfiguration::passphrase() const -{ - Q_D(const QWifiConfiguration); - return d->m_psk; -} - -void QWifiConfiguration::setPassphrase(const QString &passphrase) -{ - Q_D(QWifiConfiguration); - d->m_psk = passphrase; -} - -/*! - \property QWifiConfiguration::protocol - \brief a security protocol to use for Wifi connection - - WPA is used by default if protocol is not explicitly set. - Supported values are: WPA, WPA2, WEP, WPS. -*/ -QString QWifiConfiguration::protocol() const -{ - Q_D(const QWifiConfiguration); - return d->m_protocol; -} - -void QWifiConfiguration::setProtocol(const QString &protocol) -{ - Q_D(QWifiConfiguration); - d->m_protocol = protocol; -} - -/*! - \property QWifiConfiguration::ssidHidden - \brief Holds whether a Wifi access point broadcasts its SSID - - If a Wifi access point does not broadcast its SSID, setting this - property to \c true ensures that the Wifi backend can detect the - specified network. - - By default this property is set to \c false. -*/ -bool QWifiConfiguration::isSsidHidden() const -{ - Q_D(const QWifiConfiguration); - return d->m_ssidHidden; -} - -void QWifiConfiguration::setSsidHidden(bool hidden) -{ - Q_D(QWifiConfiguration); - d->m_ssidHidden = hidden; -} - -QT_END_NAMESPACE diff --git a/src/wifi/qwificonfiguration.h b/src/wifi/qwificonfiguration.h deleted file mode 100644 index cdeb453..0000000 --- a/src/wifi/qwificonfiguration.h +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#ifndef QWIFICONFIGURATION_H -#define QWIFICONFIGURATION_H - -#include -#include - -class QWifiConfigurationPrivate; - -QT_BEGIN_NAMESPACE - -class Q_DECL_EXPORT QWifiConfiguration : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString ssid READ ssid WRITE setSsid) - Q_PROPERTY(QString passphrase READ passphrase WRITE setPassphrase) - Q_PROPERTY(QString protocol READ protocol WRITE setProtocol) - Q_PROPERTY(bool ssidHidden READ isSsidHidden WRITE setSsidHidden) -public: - explicit QWifiConfiguration(QObject *parent = 0); - virtual ~QWifiConfiguration(); - - void setSsid(const QString &ssid); - QString ssid() const; - void setPassphrase(const QString &passphrase); - QString passphrase() const; - void setProtocol(const QString &protocol); - QString protocol() const; - void setSsidHidden(bool hidden); - bool isSsidHidden() const; - -private: - Q_DISABLE_COPY(QWifiConfiguration) - Q_DECLARE_PRIVATE(QWifiConfiguration) - QWifiConfigurationPrivate *const d_ptr; -}; - -QT_END_NAMESPACE - -#endif // QWIFICONFIGURATION_H diff --git a/src/wifi/qwificontroller.cpp b/src/wifi/qwificontroller.cpp deleted file mode 100644 index f5ed741..0000000 --- a/src/wifi/qwificontroller.cpp +++ /dev/null @@ -1,284 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#include "qwificontroller_p.h" -#include "qwifimanager_p.h" -#include "qwifisupplicant_p.h" -#include "qwifidevice.h" - -#include -#include - -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -Q_LOGGING_CATEGORY(B2QT_WIFI, "qt.b2qt.wifi") - -class QWifiEventThread : public QThread -{ -public: - QWifiEventThread(QWifiController *controller) - : m_controller(controller) - { - } - - void run() { - qCDebug(B2QT_WIFI) << "running wifi event thread"; - QWifiEvent *event = 0; - char buffer[2048]; - forever { - int size = m_controller->supplicant()->waitForEvent(buffer, sizeof(buffer) - 1); - if (size > 0) { - buffer[size] = 0; - event = 0; - qCDebug(B2QT_WIFI) << "[event]: " << buffer; - - if (m_controller->isWifiThreadExitRequested()) { - qCDebug(B2QT_WIFI) << "exit wifi event thread"; - return; - } - - if (strstr(buffer, "SCAN-RESULTS")) { - event = new QWifiEvent(WIFI_SCAN_RESULTS); - } else if (strstr(buffer, "CTRL-EVENT-CONNECTED")) { - event = new QWifiEvent(WIFI_CONNECTED); - } else if (strstr(buffer, "CTRL-EVENT-DISCONNECTED")) { - event = new QWifiEvent(WIFI_DISCONNECTED); - } else if (strstr(buffer, "Trying to associate")) { - event = new QWifiEvent(WIFI_AUTHENTICATING, QLatin1String(buffer)); - } else if (strstr(buffer, "Handshake failed")) { - event = new QWifiEvent(WIFI_HANDSHAKE_FAILED); - } - - if (event) - QCoreApplication::postEvent(m_controller->wifiManager(), event); - } - } - } - -private: - QWifiController *m_controller; -}; - - -QWifiController::QWifiController(QWifiManager *manager, QWifiManagerPrivate *managerPrivate) : - m_manager(manager), - m_managerPrivate(managerPrivate), - m_exitEventThread(false), - m_interface(QWifiDevice::wifiInterfaceName()), - m_eventThread(new QWifiEventThread(this)), - m_supplicant(new QWifiSupplicant(this, m_managerPrivate)) -{ - qRegisterMetaType("QWifiManager::BackendState"); -} - -QWifiController::~QWifiController() -{ - exitWifiEventThread(); - delete m_eventThread; -} - -void QWifiController::run() -{ - qCDebug(B2QT_WIFI) << "running wifi backend controller thread"; - Method method; - forever { - m_methodsMutex.lock(); - if (m_methods.isEmpty()) - methodCallRequested.wait(&m_methodsMutex); - method = m_methods.takeFirst(); - m_methodsMutex.unlock(); - switch (method) { - case InitializeBackend: - initializeBackend(); - break; - case TerminateBackend: - terminateBackend(); - break; - case AcquireIPAddress: - acquireIPAddress(); - break; - case StopDhcp: - stopDhcp(); - break; - case ExitEventLoop: - qCDebug(B2QT_WIFI) << "exit wifi backend controller thread"; - return; - } - } -} - -void QWifiController::asyncCall(Method method) -{ - QMutexLocker locker(&m_methodsMutex); - m_methods.append(method); - methodCallRequested.wakeOne(); -} - -void QWifiController::initializeBackend() -{ - qCDebug(B2QT_WIFI) << "initializing wifi backend"; - emit backendStateChanged(QWifiManager::Initializing); - - QProcess rfkill; - rfkill.start(QStringLiteral("rfkill"), - QStringList() << QStringLiteral("unblock") << QStringLiteral("wifi")); - rfkill.waitForFinished(); - - QProcess ifconfig; - ifconfig.start(QStringLiteral("ifconfig"), - QStringList() << QLatin1String(m_interface) << QStringLiteral("up")); - if (!ifconfig.waitForStarted()) { - m_managerPrivate->updateLastError(ifconfig.program() + QLatin1String(": ") + ifconfig.errorString()); - return; - } - - ifconfig.waitForFinished(); - bool initFailed = false; - QByteArray error = ifconfig.readAllStandardError(); - if (!error.isEmpty()) { - m_managerPrivate->updateLastError(QLatin1String("failed to bring up wifi interface: " + error)); - initFailed = true; - } - if (!initFailed && resetSupplicantSocket()) - emit backendStateChanged(QWifiManager::Running); - else - emit backendStateChanged(QWifiManager::NotRunning); -} - -bool QWifiController::resetSupplicantSocket() -{ - qCDebug(B2QT_WIFI) << "reset supplicant socket"; - exitWifiEventThread(); - m_supplicant->stopSupplicant(); - m_supplicant->closeSupplicantConnection(); - if (!m_supplicant->startSupplicant()) - return false; - if (!m_supplicant->connectToSupplicant()) - return false; - - startWifiEventThread(); - return true; -} - -void QWifiController::terminateBackend() -{ - qCDebug(B2QT_WIFI) << "terminating wifi backend"; - emit backendStateChanged(QWifiManager::Terminating); - - exitWifiEventThread(); - m_supplicant->stopSupplicant(); - m_supplicant->closeSupplicantConnection(); - - QProcess ifconfig; - ifconfig.start(QStringLiteral("ifconfig"), - QStringList() << QLatin1String(m_interface) << QStringLiteral("down")); - if (!ifconfig.waitForStarted()) { - m_managerPrivate->updateLastError(ifconfig.program() + QLatin1String(": ") + ifconfig.errorString()); - return; - } - - ifconfig.waitForFinished(); - QByteArray error = ifconfig.readAllStandardError(); - if (!error.isEmpty()) - m_managerPrivate->updateLastError(QLatin1String("failed to bring down wifi interface: " + error)); - - stopDhcp(); - emit backendStateChanged(QWifiManager::NotRunning); -} - -void QWifiController::startWifiEventThread() -{ - m_exitEventThread = false; - m_eventThread->start(); -} - -void QWifiController::exitWifiEventThread() -{ - if (m_eventThread->isRunning()) { - m_exitEventThread = true; - m_managerPrivate->call(QStringLiteral("SCAN")); - if (!m_eventThread->wait(8000)) - qCWarning(B2QT_WIFI, "timed out waiting for wifi event thread to exit"); - } -} - -void QWifiController::killDhcpProcess(const QString &path) const -{ - QFile pidFile(path); - if (!pidFile.exists()) - return; - - if (!pidFile.open(QIODevice::ReadOnly)) { - qCWarning(B2QT_WIFI) << "could not open pid file: " << path; - return; - } - - bool ok; - int pid = pidFile.readAll().trimmed().toInt(&ok); - if (!ok) { - qCWarning(B2QT_WIFI) << "pid is not a number"; - return; - } - - kill(pid, 9); -} - -void QWifiController::acquireIPAddress() -{ - qCDebug(B2QT_WIFI, "acquireIPAddress"); - QString filePath = QLatin1String("/var/run/udhcpc." + m_interface + ".pid"); - killDhcpProcess(filePath); - QStringList args; - args << QStringLiteral("-R") << QStringLiteral("-n") << QStringLiteral("-p") - << filePath << QStringLiteral("-i") << QLatin1String(m_interface); - - QProcess udhcpc; - udhcpc.start(QStringLiteral("udhcpc"), args); - if (!udhcpc.waitForStarted()) { - m_managerPrivate->updateLastError(udhcpc.program() + QLatin1String(": ") + udhcpc.errorString()); - emit dhcpRequestFinished(QLatin1String("failed")); - return; - } - - udhcpc.waitForFinished(); - QByteArray error = udhcpc.readAllStandardError(); - QString status = QLatin1String("success"); - if (!error.isEmpty()) { - m_managerPrivate->updateLastError(QLatin1String("udhcpc failed: " + error)); - status = QLatin1String("failed"); - } else { - if (udhcpc.readAllStandardOutput().contains("No lease")) - status = QLatin1String("failed"); - } - - emit dhcpRequestFinished(status); -} - -void QWifiController::stopDhcp() const -{ - qCDebug(B2QT_WIFI, "stopDhcp"); - QString filePath = QLatin1String("/var/run/udhcpc." + m_interface + ".pid"); - killDhcpProcess(filePath); -} - -QT_END_NAMESPACE diff --git a/src/wifi/qwificontroller_p.h b/src/wifi/qwificontroller_p.h deleted file mode 100644 index 45751fa..0000000 --- a/src/wifi/qwificontroller_p.h +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#ifndef QWIFICONTROLLER_H -#define QWIFICONTROLLER_H - -#include "qwifimanager.h" - -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -Q_DECLARE_LOGGING_CATEGORY(B2QT_WIFI) - -const QEvent::Type WIFI_SCAN_RESULTS = (QEvent::Type) (QEvent::User + 2001); -const QEvent::Type WIFI_CONNECTED = (QEvent::Type) (QEvent::User + 2002); -const QEvent::Type WIFI_HANDSHAKE_FAILED = (QEvent::Type) (QEvent::User + 2003); -const QEvent::Type WIFI_AUTHENTICATING = (QEvent::Type) (QEvent::User + 2004); -const QEvent::Type WIFI_DISCONNECTED = (QEvent::Type) (QEvent::User + 2005); - -class QWifiManager; -class QWifiManagerPrivate; -class QWifiEventThread; -class QWifiSupplicant; - -class QWifiEvent : public QEvent -{ -public: - QWifiEvent(QEvent::Type type, const QString &data = QString()) - : QEvent(type) - , m_data(data) - { - } - QString data() const { return m_data; } - -private: - QString m_data; -}; - -class QWifiController : public QThread -{ - Q_OBJECT -public: - enum Method { - InitializeBackend, - TerminateBackend, - AcquireIPAddress, - StopDhcp, - ExitEventLoop - }; - - explicit QWifiController(QWifiManager *manager, QWifiManagerPrivate *managerPrivate); - ~QWifiController(); - - void asyncCall(Method method); - QWifiManager *wifiManager() const { return m_manager; } - bool isWifiThreadExitRequested() const { return m_exitEventThread; } - void startWifiEventThread(); - void acquireIPAddress(); - void stopDhcp() const; - bool resetSupplicantSocket(); - QWifiSupplicant *supplicant() const { return m_supplicant; } - -signals: - void backendStateChanged(QWifiManager::BackendState backendState); - void dhcpRequestFinished(const QString &status); - -protected: - void run(); - void initializeBackend(); - void terminateBackend(); - void exitWifiEventThread(); - void killDhcpProcess(const QString &path) const; - -private: - QWifiManager *m_manager; - QWifiManagerPrivate *const m_managerPrivate; - bool m_exitEventThread; - QByteArray m_interface; - QVector m_methods; - QWifiEventThread *m_eventThread; - QMutex m_methodsMutex; - QWaitCondition methodCallRequested; - QWifiSupplicant *m_supplicant; -}; - -QT_END_NAMESPACE - -#endif // QWIFICONTROLLER_H diff --git a/src/wifi/qwifidevice.cpp b/src/wifi/qwifidevice.cpp deleted file mode 100644 index a6812e7..0000000 --- a/src/wifi/qwifidevice.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#include "qwifidevice.h" - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -/*! - \class QWifiDevice - \inmodule B2Qt.Wifi.Cpp - \ingroup wifi-cppclasses - \brief Represents a physical device. - - Use this class to query if a device is Wifi capable, before attempting - to use the functionality of QWifiManager. - - \code - QWifiManager *m_wifiManager = 0; - if (QWifiDevice::wifiSupported()) - m_wifiManager = QWifiManager::instance(); - - if (m_wifiManager) { - m_wifiManager->start(); - // and other wifi related code - } - \endcode - */ - -QWifiDevice::QWifiDevice() -{ -} - -QWifiDevice::~QWifiDevice() -{ -} - -/*! - Returns \c true if a device is Wifi capable - Wifi driver and firmware has been - successfully loaded by the system, otherwise returns \c false. -*/ -bool QWifiDevice::wifiSupported() -{ - QByteArray ifc = wifiInterfaceName(); - bool hasInterface = QDir().exists(QString::fromLatin1("/sys/class/net/" + ifc)); - if (!hasInterface) - qCWarning(B2QT_WIFI) << "could not find wifi interface in \"/sys/class/net/\", " - "looking for interface named: " << ifc; - return hasInterface; -} - -/*! - Returns Wifi interface name. - - Interface name is read from the \c B2QT_WIFI_INTERFACE - environment variable if it is set, otherwise, the default interface - name ("\e{wlan0}") is used. - - \sa setWifiInterfaceName() - */ -QByteArray QWifiDevice::wifiInterfaceName() -{ - return qEnvironmentVariableIsSet("B2QT_WIFI_INTERFACE") ? qgetenv("B2QT_WIFI_INTERFACE") : "wlan0"; -} - -/*! - A conveniece method to set the Wifi interface \a name. - - \sa wifiInterfaceName() - */ -void QWifiDevice::setWifiInterfaceName(const QByteArray &name) -{ - qputenv("B2QT_WIFI_INTERFACE", name); -} - -QT_END_NAMESPACE diff --git a/src/wifi/qwifidevice.h b/src/wifi/qwifidevice.h deleted file mode 100644 index 80b4891..0000000 --- a/src/wifi/qwifidevice.h +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#ifndef QWIFIDEVICE_H -#define QWIFIDEVICE_H - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -Q_DECLARE_LOGGING_CATEGORY(B2QT_WIFI) - -class Q_DECL_EXPORT QWifiDevice : public QObject -{ - Q_OBJECT -public: - explicit QWifiDevice(); - virtual ~QWifiDevice(); - - Q_INVOKABLE static bool wifiSupported(); - static QByteArray wifiInterfaceName(); - static void setWifiInterfaceName(const QByteArray &name); -}; - -QT_END_NAMESPACE - -#endif // QWIFIDEVICE_H diff --git a/src/wifi/qwifimanager.cpp b/src/wifi/qwifimanager.cpp deleted file mode 100644 index 0448ec7..0000000 --- a/src/wifi/qwifimanager.cpp +++ /dev/null @@ -1,534 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#include "qwificontroller_p.h" -#include "qwifinetworklistmodel_p.h" -#include "qwifinetwork_p.h" -#include "qwifimanager_p.h" -#include "qwifisupplicant_p.h" - -#include "qwifidevice.h" - -#include -#include - -QT_BEGIN_NAMESPACE - -// must be in the same order as in enum {} definiton -const char *nsText[] = { "Disconnected", "Authenticating", "HandshakeFailed", - "ObtainingIPAddress", "DhcpRequestFailed", "Connected" }; -const char *bsText[] = { "Initializing", "Running", "Terminating", "NotRunning" }; - -QWifiManagerPrivate::QWifiManagerPrivate(QWifiManager *manager) - : q_ptr(manager) - , m_networkListModel(new QWifiNetworkListModel(manager)) - , m_scanTimer(0) - , m_scanning(false) - , m_interface(QWifiDevice::wifiInterfaceName()) - , m_backendState(QWifiManager::NotRunning) - , m_networkState(QWifiManager::Disconnected) -{ - qCDebug(B2QT_WIFI) << "using wifi interface: " << m_interface; -} - -QWifiManagerPrivate::~QWifiManagerPrivate() -{ - delete m_wifiController; -} - -void QWifiManagerPrivate::setCurrentSSID(const QString &ssid) -{ - Q_Q(QWifiManager); - qCDebug(B2QT_WIFI) << "current SSID: " << m_currentSSID << " -> " << ssid; - if (m_currentSSID == ssid) - return; - - m_currentSSID = ssid; - emit q->currentSSIDChanged(m_currentSSID); -} - -void QWifiManagerPrivate::handleAuthenticating(QWifiEvent *event) -{ - QString data = event->data().trimmed(); - QString ssid = data.mid(data.indexOf(QLatin1String("SSID")) + 6); - ssid = ssid.left(ssid.lastIndexOf(QLatin1Char('\''))); - - setCurrentSSID(QWifiSupplicant::decodeSsid(ssid)); - updateNetworkState(QWifiManager::Authenticating); -} - -void QWifiManagerPrivate::handleConnected() -{ - qCDebug(B2QT_WIFI) << "connected network: " << m_currentSSID; - updateNetworkState(QWifiManager::ObtainingIPAddress); - m_wifiController->asyncCall(QWifiController::AcquireIPAddress); -} - -void QWifiManagerPrivate::handleDisconneced() -{ - updateNetworkState(QWifiManager::Disconnected); -} - -void QWifiManagerPrivate::updateNetworkState(QWifiManager::NetworkState networkState) -{ - Q_Q(QWifiManager); - qCDebug(B2QT_WIFI, "network state: %s -> %s", nsText[m_networkState], nsText[networkState]); - if (m_networkState == networkState) - return; - - m_networkState = networkState; - emit q->networkStateChanged(m_networkState); -} - -void QWifiManagerPrivate::updateBackendState(QWifiManager::BackendState backendState) -{ - Q_Q(QWifiManager); - qCDebug(B2QT_WIFI, "backend state: %s -> %s", bsText[m_backendState], bsText[backendState]); - if (m_backendState == backendState) - return; - - m_backendState = backendState; - emit q->backendStateChanged(m_backendState); -} - -void QWifiManagerPrivate::updateWifiState() -{ - QProcess ps; - ps.start(QStringLiteral("ps")); - if (!ps.waitForStarted()) { - updateLastError(ps.program() + QLatin1String(": ") + ps.errorString()); - return; - } - - ps.waitForFinished(); - bool supplicantRunning = ps.readAll().contains("wpa_supplicant"); - if (supplicantRunning && m_wifiController->resetSupplicantSocket()) - m_backendState = QWifiManager::Running; -} - -QString QWifiManagerPrivate::call(const QString &command) -{ - if (m_backendState != QWifiManager::Running) - return QString(); - - QByteArray reply; - bool success = m_wifiController->supplicant()->sendCommand(command, &reply); - if (!success) { - qCDebug(B2QT_WIFI) << "call to supplicant failed"; - return QString(); - } - - return QLatin1String(reply.trimmed()); -} - -bool QWifiManagerPrivate::checkedCall(const QString &command) -{ - return call(command).toUpper() == QLatin1String("OK"); -} - -void QWifiManagerPrivate::updateLastError(const QString &error) -{ - Q_Q(QWifiManager); - qCWarning(B2QT_WIFI) << error; - m_lastError = error; - emit q->lastErrorChanged(m_lastError); -} - -/*! - \class QWifiManager - \inmodule B2Qt.Wifi.Cpp - \ingroup wifi-cppclasses - \brief Enables an application to be Wifi-capable. - - QWifiManager is a singleton class that handles Wifi-related tasks. You can - use QWifiManager to control the Wifi backend, scan for Wifi access points, - and connect to a wireless network. - - QWifiManager packs the scan results in a list-based data model, which can - be used with Qt's Model/View classes. Information about a Wifi network can - be accessed using the QWifiManager::Roles data roles. -*/ - -/*! - \enum QWifiManager::NetworkState - - Describes current state of the network connection. - - \value Disconnected Not connected to any network - \value Authenticating Verifying password with the network provider - \value HandshakeFailed Incorrect password provided - \value ObtainingIPAddress Requesting IP address from DHCP server - \value DhcpRequestFailed Could not retrieve IP address - \value Connected Ready to process network requests -*/ - -/*! - \enum QWifiManager::BackendState - - Describes current state of the Wifi backend. - - \value Initializing Wireless supplicant is starting up - \value Running Supplicant is initialized and ready to process commands - \value Terminating Shutting down wireless supplicant - \value NotRunning Wireless supplicant process is not running -*/ - -/*! - \enum QWifiManager::Roles - - Data roles supported by the data model returned from QWifiManager::networks() - - \value SSID informal (human) name of a Wifi network (QString) - \value BSSID basic service set identification of a network, used to uniquely identify BSS (QString) - \value SignalStrength strength of a Wifi signal represented as percentage (0-100) (int) - \value WPASupported holds whether network access point supports WPA security protocol (bool) - \value WPA2Supported holds whether network access point supports WPA2 security protocol (bool) - \value WEPSupported holds whether network access point supports WEP security protocol (bool) - \value WPSSupported holds whether network access point supports WPS security protocol (bool) -*/ - -QWifiManager* QWifiManager::m_instance = 0; - -/*! - Returns a singleton instance of QWifiManager. -*/ -QWifiManager* QWifiManager::instance() -{ - if (!m_instance) - m_instance = new QWifiManager(); - return m_instance; -} - -QWifiManager::QWifiManager() - : d_ptr(new QWifiManagerPrivate(this)) -{ - Q_D(QWifiManager); - - if (!QWifiDevice::wifiSupported()) - qCWarning(B2QT_WIFI) << "WifiManager may not work as expected on this device. Use the API provided by QtWifi " - "library to verify if device has support for Wi-Fi before creating an instance of wifi manager"; - - d->m_wifiController = new QWifiController(this, d_ptr); - QObject::connect(d->m_wifiController, &QWifiController::backendStateChanged, - this, &QWifiManager::handleBackendStateChanged); - QObject::connect(d->m_wifiController, &QWifiController::dhcpRequestFinished, - this, &QWifiManager::handleDhcpRequestFinished); - d->m_wifiController->start(); - - d->updateWifiState(); -} - -/*! - Destroys the QWifiManager singleton instance. - */ -QWifiManager::~QWifiManager() -{ - Q_D(QWifiManager); - d->m_wifiController->asyncCall(QWifiController::ExitEventLoop); - d->m_wifiController->wait(); - delete d_ptr; -} - -/*! - \property QWifiManager::networks - \brief a list-based data model of networks - - Returns a list-based data model of networks that can be sensed by a device. - Model can be used with Qt's Model/View classes such as QListView. Data in - the model is updated every 5 seconds if scanning is enabled. - - \sa isScanning() -*/ -QAbstractListModel *QWifiManager::networks() const -{ - Q_D(const QWifiManager); - return d->m_networkListModel; -} - -/*! - \property QWifiManager::currentSSID - \brief a network name of the last selected network - - The network for which the NetworkState change signals are emitted. - Property can contain an empty string when there is no active network - connection. -*/ -QString QWifiManager::currentSSID() const -{ - Q_D(const QWifiManager); - return d->m_currentSSID; -} - -/*! - \property QWifiManager::networkState - \brief the current network state - - Returns the current network state. -*/ -QWifiManager::NetworkState QWifiManager::networkState() const -{ - Q_D(const QWifiManager); - return d->m_networkState; -} - -/*! - \property QWifiManager::backendState - \brief the current backend state. - - Returns the current backend state. -*/ -QWifiManager::BackendState QWifiManager::backendState() const -{ - Q_D(const QWifiManager); - return d->m_backendState; -} - -/*! - Start the Wifi backend. This function returns immediately, the BackendState - change events are delivered asynchronously. - - \sa stop(), BackendState -*/ -void QWifiManager::start() -{ - Q_D(QWifiManager); - d->m_wifiController->asyncCall(QWifiController::InitializeBackend); -} - -/*! - Stop the Wifi backend. Closes the open network connection if any. - This function returns immediately, and the BackendState change events are - delivered asynchronously. - - \sa start(), BackendState -*/ -void QWifiManager::stop() -{ - Q_D(QWifiManager); - d->m_wifiController->asyncCall(QWifiController::TerminateBackend); -} - -/*! - \property QWifiManager::scanning - \brief whether the backend is scanning for Wifi networks. - - Sets whether to scan the environment for Wifi access points. - - To preserve battery energy, set this property to false when scanning is not required. - When enabled, new readings are taken every 5 seconds. - - \note You must initialize the Wifi backend to scan for networks. - - \sa start() -*/ -bool QWifiManager::isScanning() const -{ - Q_D(const QWifiManager); - return d->m_scanning; -} - -void QWifiManager::setScanning(bool scanning) -{ - Q_D(QWifiManager); - if (d->m_scanning == scanning) - return; - - d->m_scanning = scanning; - emit scanningChanged(d->m_scanning); - if (d->m_scanning) { - d->call(QStringLiteral("SCAN")); - // ### TODO expose this with a property - d->m_scanTimer = startTimer(5000); - } else { - killTimer(d->m_scanTimer); - } -} - -/*! - \property QWifiManager::lastError - \brief a QString containing the last error message set by QWifiManager. - - Returns a QString containing the last error message set by QWifiManager. - This helps in diagnosing the internal process failures. - - \sa connect() -*/ -QString QWifiManager::lastError() const -{ - Q_D(const QWifiManager); - return d->m_lastError; -} - -/*! \reimp */ -bool QWifiManager::event(QEvent *event) -{ - Q_D(QWifiManager); - switch ((int) event->type()) { - case WIFI_SCAN_RESULTS: - d->m_networkListModel->parseScanResults(d->call(QStringLiteral("SCAN_RESULTS"))); - return true; - case WIFI_CONNECTED: - d->handleConnected(); - return true; - case WIFI_DISCONNECTED: - d->handleDisconneced(); - return true; - case WIFI_AUTHENTICATING: - d->handleAuthenticating(static_cast(event)); - return true; - case WIFI_HANDSHAKE_FAILED: - d->updateNetworkState(QWifiManager::HandshakeFailed); - return true; - case QEvent::Timer: { - int tid = static_cast(event)->timerId(); - if (tid == d->m_scanTimer) { - d->call(QStringLiteral("SCAN")); - return true; - } - break; - } - } - return QObject::event(event); -} - -/*! - Connect a device to a network using the \a config network configuration. - This method returns \c true if the network with the provided configuration - could be successfully added by the backend or \c false on failure. - Use lastError() to obtain the error message on failure. - - \sa disconnect(), NetworkState, lastError() -*/ -bool QWifiManager::connect(QWifiConfiguration *config) -{ - Q_D(QWifiManager); - if (d->m_backendState != Running) { - qCWarning(B2QT_WIFI) << "start wifi backend before calling connect()"; - return false; - } - - d->call(QStringLiteral("DISABLE_NETWORK all")); - d->setCurrentSSID(config->ssid()); - - bool networkKnown = false; - QString id; - const QStringList configuredNetworks = d->call(QStringLiteral("LIST_NETWORKS")).split('\n'); - for (int i = 1; i < configuredNetworks.length(); ++i) { - const QStringList networkFields = configuredNetworks.at(i).split('\t'); - const QString ssid = QWifiSupplicant::decodeSsid(networkFields.at(1)); - if (ssid == d->m_currentSSID) { - id = networkFields.at(0); - networkKnown = true; - break; - } - } - - if (!networkKnown) { - bool ok; - id = d->call(QStringLiteral("ADD_NETWORK")); - id.toInt(&ok); - if (!ok) { - d->updateLastError(QStringLiteral("failed to add network")); - return false; - } - } - - bool ok = true; - QChar q = QLatin1Char('"'); - QString setNetworkCommand = QLatin1String("SET_NETWORK ") + id; - if (!networkKnown) { - ok = ok && d->checkedCall(setNetworkCommand + QLatin1String(" ssid ") + q + d->m_currentSSID + q); - } - - QString key_mgmt; - QString protocol = config->protocol().toUpper(); - QString psk = config->passphrase(); - - // --------------------- configure network ------------------------------ - // ref: http://w1.fi/cgit/hostap/plain/wpa_supplicant/wpa_supplicant.conf - // ref: https://www.freebsd.org/cgi/man.cgi?wpa_supplicant.conf - // ---------------------------------------------------------------------- - if (protocol.isEmpty() || protocol.contains(QStringLiteral("WPA"))) { - // ### TODO - password length has limits (see IEEE 802.11), we need to check - // for those limits here. Supplicant gives only a meaningless "fail" message. - ok = ok && d->checkedCall(setNetworkCommand + QLatin1String(" psk ") + q + psk + q); - key_mgmt = QLatin1String("WPA-PSK"); - } else if (protocol.contains(QStringLiteral("WEP"))) { - ok = ok && d->checkedCall(setNetworkCommand + QLatin1String(" wep_key0 ") + q + psk + q); - ok = ok && d->checkedCall(setNetworkCommand + QLatin1String(" auth_alg OPEN SHARED")); - key_mgmt = QLatin1String("NONE"); - } else if (protocol.contains(QStringLiteral("WPS")) && psk.length() == 0) { - // open network - key_mgmt = QLatin1String("NONE"); - } - - if (config->isSsidHidden()) - ok = ok && d->checkedCall(setNetworkCommand + QLatin1String(" scan_ssid 1")); - - ok = ok && d->checkedCall(setNetworkCommand + QLatin1String(" key_mgmt ") + key_mgmt); - if (!ok) { - if (!networkKnown) - d->call(QLatin1String("REMOVE_NETWORK ") + id); - d->updateLastError(QLatin1String("failed to set properties on network: ") + id); - return false; - } - - d->call(QLatin1String("SELECT_NETWORK ") + id); - d->call(QStringLiteral("RECONNECT")); - - return true; -} - -/*! - Disconnect from currently connected network connection. - - \sa connect(), networkState() -*/ -void QWifiManager::disconnect() -{ - Q_D(QWifiManager); - d->call(QStringLiteral("DISCONNECT")); - d->m_wifiController->asyncCall(QWifiController::StopDhcp); -} - -void QWifiManager::handleBackendStateChanged(BackendState backendState) -{ - Q_D(QWifiManager); - switch (backendState) { - case NotRunning: - d->updateNetworkState(Disconnected); - break; - default: - break; - } - d->updateBackendState(backendState); -} - -void QWifiManager::handleDhcpRequestFinished(const QString &status) -{ - Q_D(QWifiManager); - qCDebug(B2QT_WIFI) << "handleDhcpRequestFinished: " << status << " for " << d->m_currentSSID; - if (status == QLatin1String("success")) { - d->updateNetworkState(Connected); - d->call(QStringLiteral("SAVE_CONFIG")); - } else { - d->updateNetworkState(DhcpRequestFailed); - } -} - -QT_END_NAMESPACE diff --git a/src/wifi/qwifimanager.h b/src/wifi/qwifimanager.h deleted file mode 100644 index 7fc658c..0000000 --- a/src/wifi/qwifimanager.h +++ /dev/null @@ -1,118 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#ifndef QWIFIMANAGER_H -#define QWIFIMANAGER_H - -#include "qwificonfiguration.h" - -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -Q_DECLARE_LOGGING_CATEGORY(B2QT_WIFI) - -class QWifiManagerPrivate; -class QAbstractListModel; -class QWifiController; -class QWifiNetworkListModel; - -class Q_DECL_EXPORT QWifiManager : public QObject -{ - Q_OBJECT - Q_ENUMS(NetworkState) - Q_ENUMS(BackendState) - Q_PROPERTY(NetworkState networkState READ networkState NOTIFY networkStateChanged) - Q_PROPERTY(BackendState backendState READ backendState NOTIFY backendStateChanged) - Q_PROPERTY(bool scanning READ isScanning WRITE setScanning NOTIFY scanningChanged) - Q_PROPERTY(QString currentSSID READ currentSSID NOTIFY currentSSIDChanged) - Q_PROPERTY(QString lastError READ lastError NOTIFY lastErrorChanged) - Q_PROPERTY(QAbstractListModel *networks READ networks CONSTANT) -public: - enum NetworkState { - Disconnected, - Authenticating, - HandshakeFailed, - ObtainingIPAddress, - DhcpRequestFailed, - Connected - }; - - enum BackendState { - Initializing, - Running, - Terminating, - NotRunning - }; - - enum Roles { - SSID = Qt::UserRole + 1, - BSSID = Qt::UserRole + 2, - SignalStrength = Qt::UserRole + 3, - WPASupported = Qt::UserRole + 4, - WPA2Supported = Qt::UserRole + 5, - WEPSupported = Qt::UserRole + 6, - WPSSupported = Qt::UserRole + 7 - }; - - static QWifiManager *instance(); - virtual ~QWifiManager(); - - QAbstractListModel *networks() const; - QString currentSSID() const; - bool isScanning() const; - void setScanning(bool scanning); - NetworkState networkState() const; - BackendState backendState() const; - QString lastError() const; - -public slots: - void start(); - void stop(); - bool connect(QWifiConfiguration *config); - void disconnect(); - -signals: - void scanningChanged(bool scanning); - void networkStateChanged(NetworkState networkState); - void backendStateChanged(BackendState backendState); - void currentSSIDChanged(const QString ¤tSSID); - void lastErrorChanged(const QString &error); - -protected: - bool event(QEvent *event); - -private slots: - void handleBackendStateChanged(BackendState backendState); - void handleDhcpRequestFinished(const QString &status); - -private: - QWifiManager(); - static QWifiManager* m_instance; - friend class QWifiController; - Q_DISABLE_COPY(QWifiManager) - Q_DECLARE_PRIVATE(QWifiManager) - QWifiManagerPrivate *const d_ptr; -}; - -QT_END_NAMESPACE - -#endif // QWIFIMANAGER_H diff --git a/src/wifi/qwifimanager_p.h b/src/wifi/qwifimanager_p.h deleted file mode 100644 index 5449551..0000000 --- a/src/wifi/qwifimanager_p.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#ifndef QWIFIMANAGER_P_H -#define QWIFIMANAGER_P_H - -#include "qwifimanager.h" -#include "qwifidevice.h" - -#include - -QT_BEGIN_NAMESPACE - -class QWifiEvent; - -class QWifiManagerPrivate -{ - Q_DECLARE_PUBLIC(QWifiManager) -public: - QWifiManagerPrivate(QWifiManager *manager); - virtual ~QWifiManagerPrivate(); - - // methods - void setCurrentSSID(const QString &ssid); - void handleConnected(); - void handleDisconneced(); - void handleAuthenticating(QWifiEvent *event); - - void updateNetworkState(QWifiManager::NetworkState networkState); - void updateBackendState(QWifiManager::BackendState backendState); - void updateWifiState(); - - QString call(const QString &command); - bool checkedCall(const QString &command); - void updateLastError(const QString &error); - - // member variables - QWifiManager *const q_ptr; - QWifiController *m_wifiController; - QWifiNetworkListModel *m_networkListModel; - - int m_scanTimer; - bool m_scanning; - QByteArray m_interface; - QWifiManager::BackendState m_backendState; - QWifiManager::NetworkState m_networkState; - QString m_currentSSID; - QString m_lastError; -}; - -QT_END_NAMESPACE - -#endif // QWIFIMANAGER_P_H diff --git a/src/wifi/qwifinetwork.cpp b/src/wifi/qwifinetwork.cpp deleted file mode 100644 index eb2b669..0000000 --- a/src/wifi/qwifinetwork.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#include "qwifinetwork_p.h" - -QT_BEGIN_NAMESPACE - -QWifiNetwork::QWifiNetwork(QObject *parent) - : QObject(parent) - , m_isOutOfRange(false) -{ -} - -QWifiNetwork::~QWifiNetwork() -{ -} - -void QWifiNetwork::setSsid(const QString &ssid) -{ - m_ssid = ssid; -} - -void QWifiNetwork::setSignalStrength(int strength) -{ - m_signalStrength = strength; -} - -void QWifiNetwork::setOutOfRange(bool outOfRange) -{ - m_isOutOfRange = outOfRange; -} - -QT_END_NAMESPACE diff --git a/src/wifi/qwifinetwork_p.h b/src/wifi/qwifinetwork_p.h deleted file mode 100644 index db65e2d..0000000 --- a/src/wifi/qwifinetwork_p.h +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#ifndef QWIFINETWORK_H -#define QWIFINETWORK_H - -#include -#include - -QT_BEGIN_NAMESPACE - -class QWifiNetwork : public QObject -{ - Q_OBJECT -public: - explicit QWifiNetwork(QObject *parent = 0); - virtual ~QWifiNetwork(); - - void setBssid(const QString &bssid) { m_bssid = bssid; } - QString bssid() const { return m_bssid; } - void setSsid(const QString &ssid); - QString ssid() const { return m_ssid; } - - void setSignalStrength(int strength); - int signalStrength() const { return m_signalStrength; } - - void setOutOfRange(bool isOutOfRange); - // this could be exposed in QWifiManager::Roles, - // if there is a use case for it, this would require keeping - // the out of range networks in data model, currently they are - // removed from the model. - bool isOutOfRange() const { return m_isOutOfRange; } - - void setFlags(const QString &flags) { m_flags = flags; } - QString flags() const { return m_flags; } - bool supportsWPA2() const { return m_flags.contains(QStringLiteral("WPA2")); } - bool supportsWPA() const { return m_flags.contains(QStringLiteral("WPA")); } - bool supportsWEP() const { return m_flags.contains(QStringLiteral("WEP")); } - bool supportsWPS() const { return m_flags.contains(QStringLiteral("WPS")); } - -private: - QString m_bssid; - QString m_ssid; - int m_signalStrength; - QString m_flags; - bool m_isOutOfRange; -}; - -QT_END_NAMESPACE - -#endif // QWIFINETWORK_H diff --git a/src/wifi/qwifinetworklistmodel.cpp b/src/wifi/qwifinetworklistmodel.cpp deleted file mode 100644 index fa3f7dc..0000000 --- a/src/wifi/qwifinetworklistmodel.cpp +++ /dev/null @@ -1,195 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#include "qwifinetworklistmodel_p.h" -#include "qwifinetwork_p.h" -#include "qwifisupplicant_p.h" - -#include "qwifimanager.h" - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -QWifiNetworkListModel::QWifiNetworkListModel(QObject *parent) - : QAbstractListModel(parent) -{ -} - -QWifiNetworkListModel::~QWifiNetworkListModel() -{ - qDeleteAll(m_networks); - qDeleteAll(m_outOfRangeNetworks); - m_networks.clear(); - m_outOfRangeNetworks.clear(); -} - -QHash QWifiNetworkListModel::roleNames() const -{ - QHash names; - names.insert(QWifiManager::SSID, "ssid"); - names.insert(QWifiManager::BSSID, "bssid"); - names.insert(QWifiManager::SignalStrength, "signalStrength"); - names.insert(QWifiManager::WPASupported, "supportsWPA"); - names.insert(QWifiManager::WPA2Supported, "supportsWPA2"); - names.insert(QWifiManager::WEPSupported, "supportsWEP"); - names.insert(QWifiManager::WPSSupported, "supportsWPS"); - return names; -} - -QVariant QWifiNetworkListModel::data(const QModelIndex &index, int role) const -{ - QWifiNetwork *n = m_networks.at(index.row()); - - switch (role) { - case QWifiManager::SSID: - return n->ssid(); - break; - case QWifiManager::BSSID: - return n->bssid(); - break; - case QWifiManager::SignalStrength: - return n->signalStrength(); - break; - case QWifiManager::WPASupported: - return n->supportsWPA(); - break; - case QWifiManager::WPA2Supported: - return n->supportsWPA2(); - break; - case QWifiManager::WEPSupported: - return n->supportsWEP(); - break; - case QWifiManager::WPSSupported: - return n->supportsWPS(); - break; - default: - break; - } - - return QVariant(); -} - -QWifiNetwork *QWifiNetworkListModel::networkForSSID(const QString &ssid) -{ - int pos = 0; // unused - return networkForSSID(ssid, &pos); -} - -QWifiNetwork *QWifiNetworkListModel::networkForSSID(const QString &ssid, int *pos) -{ - for (int i = 0; i < m_networks.size(); ++i) { - if (m_networks.at(i)->ssid() == ssid) { - if (pos) - *pos = i; - return m_networks.at(i); - } - } - return 0; -} - -QWifiNetwork *QWifiNetworkListModel::outOfRangeListContains(const QString &ssid) -{ - for (int i = 0; i < m_outOfRangeNetworks.length(); ++i) - if (m_outOfRangeNetworks.at(i)->ssid() == ssid) - return m_outOfRangeNetworks.takeAt(i); - return 0; -} - -void QWifiNetworkListModel::parseScanResults(const QString &results) -{ - QStringList lines = results.split('\n'); - QSet sensibleNetworks; - - for (int i = 1; i < lines.size(); ++i) { - QStringList info = lines.at(i).split('\t'); - if (info.size() < 5 || info.at(4).isEmpty() || info.at(0).isEmpty()) - continue; - int pos = 0; - - QString ssid = QWifiSupplicant::decodeSsid(info.at(4)); - if (ssid.isEmpty()) - continue; - - sensibleNetworks.insert(ssid); - QWifiNetwork *knownNetwork = networkForSSID(ssid, &pos); - if (!knownNetwork) - knownNetwork = outOfRangeListContains(ssid); - - int signalStrength = info.at(2).trimmed().toInt(); - if (signalStrength < 0) { - // signal is reported in dBm, rough conversion: best = -40, worst = -100 - int val = qAbs(qMax(-100, qMin(signalStrength, -40)) + 40); // clamp and normalize to 0 - signalStrength = 100 - (int) ((100.0 * (double) val) / 60.0); - } else if (signalStrength > 100) { - qCWarning(B2QT_WIFI) << "unexpected value for a signal level: " << signalStrength; - } - - if (!knownNetwork) { - QWifiNetwork *network = new QWifiNetwork(); - network->setOutOfRange(false); - network->setBssid(info.at(0)); - network->setFlags(info.at(3)); - network->setSignalStrength(signalStrength); - network->setSsid(ssid); - beginInsertRows(QModelIndex(), m_networks.size(), m_networks.size()); - m_networks << network; - endInsertRows(); - } else { - if (knownNetwork->isOutOfRange()) { - // known network has come back into a range - knownNetwork->setOutOfRange(false); - beginInsertRows(QModelIndex(), m_networks.size(), m_networks.size()); - m_networks << knownNetwork; - endInsertRows(); - pos = m_networks.length() - 1; - } - // ssids are the same, compare bssids.. - if (knownNetwork->bssid() == info.at(0)) { - // same access point, simply update the signal strength - knownNetwork->setSignalStrength(signalStrength); - knownNetwork->setOutOfRange(false); - dataChanged(createIndex(pos, 0), createIndex(pos, 0)); - } else if (knownNetwork->signalStrength() < signalStrength) { - // replace with a stronger access point within the same network - m_networks.at(pos)->setOutOfRange(false); - m_networks.at(pos)->setBssid(info.at(0)); - m_networks.at(pos)->setFlags(info.at(3)); - m_networks.at(pos)->setSignalStrength(signalStrength); - m_networks.at(pos)->setSsid(ssid); - dataChanged(createIndex(pos, 0), createIndex(pos, 0)); - } - } - } - // remove out-of-range networks from the data model - for (int i = 0; i < m_networks.size();) { - if (!sensibleNetworks.contains(m_networks.at(i)->ssid())) { - beginRemoveRows(QModelIndex(), i, i); - QWifiNetwork *n = m_networks.takeAt(i); - n->setOutOfRange(true); - m_outOfRangeNetworks.append(n); - endRemoveRows(); - } else { - ++i; - } - } -} - -QT_END_NAMESPACE diff --git a/src/wifi/qwifinetworklistmodel_p.h b/src/wifi/qwifinetworklistmodel_p.h deleted file mode 100644 index 25a2b31..0000000 --- a/src/wifi/qwifinetworklistmodel_p.h +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#ifndef QWIFINETWORKLISTMODEL_H -#define QWIFINETWORKLISTMODEL_H - -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -Q_DECLARE_LOGGING_CATEGORY(B2QT_WIFI) - -class QWifiNetwork; - -class QWifiNetworkListModel : public QAbstractListModel -{ - Q_OBJECT -public: - explicit QWifiNetworkListModel(QObject *parent = 0); - virtual ~QWifiNetworkListModel(); - - int rowCount(const QModelIndex &) const { return m_networks.size(); } - QVariant data(const QModelIndex &index, int role) const; - QHash roleNames() const; - - void parseScanResults(const QString &data); - QWifiNetwork *networkForSSID(const QString &ssid); - QWifiNetwork *networkForSSID(const QString &ssid, int *pos); - QWifiNetwork *outOfRangeListContains(const QString &ssid); - -private: - QList m_networks; - QList m_outOfRangeNetworks; -}; - -QT_END_NAMESPACE - -#endif // QWIFINETWORKLISTMODEL_H diff --git a/src/wifi/qwifisupplicant.cpp b/src/wifi/qwifisupplicant.cpp deleted file mode 100644 index d87ac80..0000000 --- a/src/wifi/qwifisupplicant.cpp +++ /dev/null @@ -1,444 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#include "qwifisupplicant_p.h" -#include "qwifidevice.h" -#include "qwifimanager_p.h" - -#include -#include -#include - -#include -#include - -QT_BEGIN_NAMESPACE - -Q_LOGGING_CATEGORY(B2QT_WIFI_VERBOSE, "qt.b2qt.wifi.verbose") - -#define CONFIG_FILE "/etc/wpa_supplicant.qtwifi.conf" -#define CONTROL_INTERFACE_PATH "/var/run/wpa_supplicant/" - -QWifiSupplicant::QWifiSupplicant(QObject *parent, QWifiManagerPrivate *managerPrivate) : - QObject(parent), - ctrl_conn(0), - monitor_conn(0), - interface(QWifiDevice::wifiInterfaceName()), - m_managerPrivate(managerPrivate) -{ - createSupplicantConfig(); -} - -void QWifiSupplicant::createSupplicantConfig() const -{ - QFile supplicantConfig(QLatin1String(CONFIG_FILE)); - if (supplicantConfig.exists()) - return; - - if (supplicantConfig.open(QIODevice::WriteOnly)) { - supplicantConfig.write("ctrl_interface=" CONTROL_INTERFACE_PATH "\n" - "ctrl_interface_group=0\n" - "update_config=1\n"); - } else { - m_managerPrivate->updateLastError(QLatin1String("failed to create wpa_supplicant configuration file.")); - } -} - -bool QWifiSupplicant::startSupplicant() -{ - QString pidFile = QLatin1String("/var/run/wpa_supplicant." + interface + ".pid"); - QString driver(QStringLiteral("nl80211,wext")); - - QStringList arg; - arg << QStringLiteral("--start") << QStringLiteral("--quiet") << QStringLiteral("--name"); - arg << QStringLiteral("wpa_supplicant") << QStringLiteral("--startas"); - arg << QStringLiteral("/usr/sbin/wpa_supplicant") << QStringLiteral("--pidfile") << pidFile; - arg << QStringLiteral("--") << QStringLiteral("-B") << QStringLiteral("-P") << pidFile; - arg << QStringLiteral("-i") << QLatin1String(interface) << QStringLiteral("-c"); - arg << QLatin1String(CONFIG_FILE) << QStringLiteral("-D") << driver; - - QProcess startStopDaemon; - startStopDaemon.setProcessChannelMode(QProcess::MergedChannels); - startStopDaemon.start(QStringLiteral("start-stop-daemon"), arg); - if (!startStopDaemon.waitForStarted()) { - m_managerPrivate->updateLastError(startStopDaemon.program() + QLatin1String(": ") + startStopDaemon.errorString()); - return false; - } - startStopDaemon.waitForFinished(); - // if the interface socket exists then wpa-supplicant was invoked successfully - if (!QFile(QLatin1String(CONTROL_INTERFACE_PATH + interface)).exists()) { - m_managerPrivate->updateLastError(QLatin1String("failed to invoke wpa_supplicant: " - + startStopDaemon.readAll())); - return false; - } - // reset sockets used for exiting from hung state - exit_sockets[0] = exit_sockets[1] = -1; - return true; -} - -bool QWifiSupplicant::stopSupplicant() -{ - QString pidFile = QLatin1String("/var/run/wpa_supplicant." + interface + ".pid"); - - if (QFile(pidFile).exists()) { - QStringList arg; - arg << QStringLiteral("--stop") << QStringLiteral("--quiet") << QStringLiteral("--name"); - arg << QStringLiteral("wpa_supplicant") << QStringLiteral("--pidfile") << pidFile; - - QProcess startStopDaemon; - startStopDaemon.start(QStringLiteral("start-stop-daemon"), arg); - if (!startStopDaemon.waitForStarted()) { - m_managerPrivate->updateLastError(startStopDaemon.program() + QLatin1String(": ") + startStopDaemon.errorString()); - return false; - } - startStopDaemon.waitForFinished(); - QByteArray error = startStopDaemon.readAllStandardError(); - if (!error.isEmpty()) { - m_managerPrivate->updateLastError(QLatin1String("failed to stop a wpa_supplicant process" + error)); - return false; - } - - QFile::remove(pidFile); - } - - QFile::remove(QLatin1String(CONTROL_INTERFACE_PATH + interface)); - - // workaround for QTEE-957 - QProcess killall; - killall.start(QStringLiteral("killall"), QStringList() << QStringLiteral("-9") << QStringLiteral("wpa_supplicant")); - killall.waitForFinished(); - - return true; -} - -/*! \internal - * - wpa_supplicant socket communication code (Apache License 2.0) with few modifications - from https://android.googlesource.com/platform/hardware/libhardware_legacy/ - - */ -bool QWifiSupplicant::connectToSupplicant() -{ - static char path[4096]; - snprintf(path, sizeof(path), "%s/%s", CONTROL_INTERFACE_PATH, interface.constData()); - bool connected = true; - - ctrl_conn = wpa_ctrl_open(path); - if (ctrl_conn == NULL) { - qCWarning(B2QT_WIFI, "Unable to open connection to wpa_supplicant on \"%s\": %s", - path, strerror(errno)); - connected = false; - } - monitor_conn = wpa_ctrl_open(path); - if (monitor_conn == NULL) { - wpa_ctrl_close(ctrl_conn); - ctrl_conn = NULL; - connected = false; - } - if (wpa_ctrl_attach(monitor_conn) != 0) { - wpa_ctrl_close(monitor_conn); - wpa_ctrl_close(ctrl_conn); - ctrl_conn = monitor_conn = NULL; - connected = false; - } - - if (socketpair(AF_UNIX, SOCK_STREAM, 0, exit_sockets) == -1) { - wpa_ctrl_close(monitor_conn); - wpa_ctrl_close(ctrl_conn); - ctrl_conn = monitor_conn = NULL; - connected = false; - } - - if (!connected) - m_managerPrivate->updateLastError(QLatin1String("failed to connect to wpa_supplicant")); - return connected; -} - -void QWifiSupplicant::closeSupplicantConnection() -{ - if (ctrl_conn != NULL) { - wpa_ctrl_close(ctrl_conn); - ctrl_conn = NULL; - } - - if (monitor_conn != NULL) { - wpa_ctrl_close(monitor_conn); - monitor_conn = NULL; - } - - if (exit_sockets[0] >= 0) { - close(exit_sockets[0]); - exit_sockets[0] = -1; - } - - if (exit_sockets[1] >= 0) { - close(exit_sockets[1]); - exit_sockets[1] = -1; - } -} - -int QWifiSupplicant::waitForEvent(char *buf, size_t buflen) -{ - size_t nread = buflen - 1; - int result; - char *match, *match2; - - if (monitor_conn == NULL) - return snprintf(buf, buflen, WPA_EVENT_TERMINATING " - connection closed"); - - result = receiveEvent(buf, &nread); - - // Terminate reception on exit socket - if (result == -2) - return snprintf(buf, buflen, WPA_EVENT_TERMINATING " - connection closed"); - - if (result < 0) { - qCWarning(B2QT_WIFI, "receiveEvent failed: %s", strerror(errno)); - return snprintf(buf, buflen, WPA_EVENT_TERMINATING " - recv error"); - } - - buf[nread] = '\0'; - // Check for EOF on the socket - if (result == 0 && nread == 0) { - // Fabricate an event to pass up - qCWarning(B2QT_WIFI, "Received EOF on supplicant socket"); - return snprintf(buf, buflen, WPA_EVENT_TERMINATING " - signal 0 received"); - } - - /* - * Events strings are in the format - * - * IFNAME=iface CTRL-EVENT-XXX - * or - * CTRL-EVENT-XXX - * - * where N is the message level in numerical form (0=VERBOSE, 1=DEBUG, - * etc.) and XXX is the event name. The level information is not useful - * to us, so strip it off. - */ - - if (strncmp(buf, "IFNAME=", (sizeof("IFNAME=") - 1)) == 0) { - match = strchr(buf, ' '); - if (match != NULL) { - if (match[1] == '<') { - match2 = strchr(match + 2, '>'); - if (match2 != NULL) { - nread -= (match2 - match); - memmove(match + 1, match2 + 1, nread - (match - buf) + 1); - } - } - } else { - return snprintf(buf, buflen, "%s", "CTRL-EVENT-IGNORE "); - } - } else if (buf[0] == '<') { - match = strchr(buf, '>'); - if (match != NULL) { - nread -= (match + 1 - buf); - memmove(buf, match + 1, nread + 1); - //qCWarning(B2QT_WIFI, "supplicant generated event without interface - %s", buf); - } - } else { - // let the event go as is! - qCWarning(B2QT_WIFI, "supplicant generated event without interface and without message level - %s", buf); - } - - return nread; -} - -bool QWifiSupplicant::sendCommand(const QString &command, QByteArray *reply) -{ - QByteArray cmd = command.toLocal8Bit(); - qCDebug(B2QT_WIFI) << "[command]: " << cmd; - - if (ctrl_conn == NULL) { - qCWarning(B2QT_WIFI, "Not connected to wpa_supplicant"); - return false; - } - - char data[8192]; - size_t len = sizeof(data) - 1; // -1: room to add a 0-terminator - int ret = wpa_ctrl_request(ctrl_conn, cmd, strlen(cmd), data, &len, NULL); - if (ret == -2) { - qCWarning(B2QT_WIFI) << "command timed out"; - // unblocks the monitor receive socket for termination - TEMP_FAILURE_RETRY(write(exit_sockets[0], "T", 1)); - return false; - } else if (ret < 0 || strncmp(data, "FAIL", 4) == 0) { - return false; - } - - if (len == sizeof(data) - 1) { - qCWarning(B2QT_WIFI) << "possible buffer overflow detected"; - return false; - } - - data[len] = 0; - qCDebug(B2QT_WIFI_VERBOSE) << "[response]: " << data; - *reply = QByteArray(data, len); - - return true; -} - -int QWifiSupplicant::receiveEvent(char *reply, size_t *reply_len) -{ - int res = 0; - int ctrlfd = wpa_ctrl_get_fd(monitor_conn); - struct pollfd rfds[2]; - - memset(rfds, 0, 2 * sizeof(struct pollfd)); - rfds[0].fd = ctrlfd; - rfds[0].events |= POLLIN; - rfds[1].fd = exit_sockets[1]; - rfds[1].events |= POLLIN; - res = TEMP_FAILURE_RETRY(poll(rfds, 2, -1)); - if (res < 0) { - qCWarning(B2QT_WIFI, "Error poll = %d", res); - return res; - } - if (rfds[0].revents & POLLIN) { - return wpa_ctrl_recv(monitor_conn, reply, reply_len); - } - - /* it is not rfds[0], then it must be rfts[1] (i.e. the exit socket) - * or we timed out. In either case, this call has failed .. - */ - return -2; -} - -static inline int hex2num(char c) -{ - if (c >= '0' && c <= '9') - return c - '0'; - if (c >= 'a' && c <= 'f') - return c - 'a' + 10; - if (c >= 'A' && c <= 'F') - return c - 'A' + 10; - return -1; -} - -static inline int hex2byte(const char *hex) -{ - int a, b; - a = hex2num(*hex++); - if (a < 0) - return -1; - b = hex2num(*hex++); - if (b < 0) - return -1; - return (a << 4) | b; -} - -static inline int printf_decode(char *buf, int maxlen, const char *str) -{ - const char *pos = str; - int len = 0; - int val; - - while (*pos) { - if (len + 1 >= maxlen) - break; - switch (*pos) { - case '\\': - pos++; - switch (*pos) { - case '\\': - buf[len++] = '\\'; - pos++; - break; - case '"': - buf[len++] = '"'; - pos++; - break; - case 'n': - buf[len++] = '\n'; - pos++; - break; - case 'r': - buf[len++] = '\r'; - pos++; - break; - case 't': - buf[len++] = '\t'; - pos++; - break; - case 'e': - buf[len++] = '\033'; - pos++; - break; - case 'x': - pos++; - val = hex2byte(pos); - if (val < 0) { - val = hex2num(*pos); - if (val < 0) - break; - buf[len++] = val; - pos++; - } else { - buf[len++] = val; - pos += 2; - } - break; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - val = *pos++ - '0'; - if (*pos >= '0' && *pos <= '7') - val = val * 8 + (*pos++ - '0'); - if (*pos >= '0' && *pos <= '7') - val = val * 8 + (*pos++ - '0'); - buf[len++] = val; - break; - default: - break; - } - break; - default: - buf[len++] = *pos++; - break; - } - } - if (maxlen > len) - buf[len] = '\0'; - - return len; -} - -/*! \internal - * - Decode wpa_supplicant encoded string, see file hostapd/src/utils/common.c - in git://w1.fi/hostap.git repository. - - For Ascii encoded string, any octet < 32 or > 127 is encoded as a "\\x" - followed by the hex representation of the octet. Exception chars are ", - \\, \\e, \\n, \\r, \\t which are escaped by a backslash - - */ -QString QWifiSupplicant::decodeSsid(const QString &encoded) -{ - static char ssid[2048]; - printf_decode(ssid, sizeof(ssid), encoded.toLatin1().constData()); - return QString::fromUtf8(ssid); -} - -QT_END_NAMESPACE diff --git a/src/wifi/qwifisupplicant_p.h b/src/wifi/qwifisupplicant_p.h deleted file mode 100644 index 0a6a964..0000000 --- a/src/wifi/qwifisupplicant_p.h +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** This file is part of Qt Enterprise Embedded. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** the contact form at http://www.qt.io -** -****************************************************************************/ -#ifndef QWIFISUPPLICANT_H -#define QWIFISUPPLICANT_H - -#include -#include -#include - -#include "wpa-supplicant/wpa_ctrl.h" - -QT_BEGIN_NAMESPACE - -Q_DECLARE_LOGGING_CATEGORY(B2QT_WIFI) -Q_DECLARE_LOGGING_CATEGORY(B2QT_WIFI_VERBOSE) - -class QWifiManagerPrivate; - -class QWifiSupplicant : public QObject -{ - Q_OBJECT -public: - explicit QWifiSupplicant(QObject *parent, QWifiManagerPrivate *managerPrivate); - - void createSupplicantConfig() const; - bool startSupplicant(); - bool stopSupplicant(); - bool connectToSupplicant(); - void closeSupplicantConnection(); - int waitForEvent(char *buf, size_t buflen); - bool sendCommand(const QString &command, QByteArray *reply); - static QString decodeSsid(const QString &encoded); - -protected: - int receiveEvent(char *reply, size_t *reply_len); - -private: - wpa_ctrl *ctrl_conn; - wpa_ctrl *monitor_conn; - int exit_sockets[2]; - QByteArray interface; - QWifiManagerPrivate *const m_managerPrivate; -}; - -QT_END_NAMESPACE - -#endif // QWIFISUPPLICANT_H diff --git a/src/wifi/wifi.pro b/src/wifi/wifi.pro deleted file mode 100644 index faf15f2..0000000 --- a/src/wifi/wifi.pro +++ /dev/null @@ -1,36 +0,0 @@ -load(qt_build_config) - -TARGET = B2QtWifi -VERSION = 1.0 -CONFIG += dll warn_on - -QT += core network - -MODULE = b2qtwifi -load(qt_module) - -HEADERS += \ - $$PWD/qwifimanager.h \ - $$PWD/qwifimanager_p.h \ - $$PWD/qwifinetwork_p.h \ - $$PWD/qwifinetworklistmodel_p.h \ - $$PWD/qwificontroller_p.h \ - $$PWD/qwifidevice.h \ - $$PWD/qwificonfiguration.h \ - $$PWD/qwifisupplicant_p.h - -SOURCES += \ - $$PWD/qwifimanager.cpp \ - $$PWD/qwifinetwork.cpp \ - $$PWD/qwifinetworklistmodel.cpp \ - $$PWD/qwificontroller.cpp \ - $$PWD/qwifidevice.cpp \ - $$PWD/qwificonfiguration.cpp \ - $$PWD/qwifisupplicant.cpp \ - $$[QT_SYSROOT]/usr/include/wpa-supplicant/wpa_ctrl.c \ - $$[QT_SYSROOT]/usr/include/wpa-supplicant/os_unix.c - -DEFINES += \ - CONFIG_CTRL_IFACE \ - CONFIG_CTRL_IFACE_UNIX - -- cgit v1.2.3