diff options
author | Gatis Paeglis <gatis.paeglis@theqtcompany.com> | 2015-06-28 12:49:14 +0200 |
---|---|---|
committer | Gatis Paeglis <gatis.paeglis@theqtcompany.com> | 2015-06-29 11:10:08 +0300 |
commit | 4ef20296ae47d134fd76f5682dc0a9a4a4994f0b (patch) | |
tree | cf5251e0a8143720381e18e72ec0642ee64d5bdf | |
parent | 3e6d9c660931ffd06174784c71af30d7fbe40802 (diff) |
Use a custom supplicant configuration file
A default configuration file contains:
network={
key_mgmt=NONE
}
which means that supplicant will try to connect to
*any* network where key_mgmt is set to NONE. We don't
want that.
Change-Id: Ibde643dfa2371cffdec2bfc53f96957fda7ac452
Reviewed-by: Kalle Viironen <kalle.viironen@theqtcompany.com>
-rw-r--r-- | src/wifi/qwifidevice.cpp | 35 | ||||
-rw-r--r-- | src/wifi/qwifidevice.h | 7 | ||||
-rw-r--r-- | src/wifi/qwifielinux.cpp | 5 | ||||
-rw-r--r-- | src/wifi/qwifimanager.cpp | 2 | ||||
-rw-r--r-- | src/wifi/qwifimanager_p.h | 2 |
5 files changed, 50 insertions, 1 deletions
diff --git a/src/wifi/qwifidevice.cpp b/src/wifi/qwifidevice.cpp index 0e421b7..0b52780 100644 --- a/src/wifi/qwifidevice.cpp +++ b/src/wifi/qwifidevice.cpp @@ -27,6 +27,39 @@ QT_BEGIN_NAMESPACE +class QWifiDevicePrivate +{ + Q_DECLARE_PUBLIC(QWifiDevice) +public: + QWifiDevicePrivate(QWifiDevice *device); + + // methods + void createSupplicantConfig(); + // member variables + QWifiDevice *const q_ptr; +}; + +QWifiDevicePrivate::QWifiDevicePrivate(QWifiDevice *device) + : q_ptr(device) +{ +} + +void QWifiDevicePrivate::createSupplicantConfig() +{ + QFile supplicantConfig(QStringLiteral("/etc/wpa_supplicant.qtwifi.conf")); + if (supplicantConfig.exists()) + return; + + if (supplicantConfig.open(QIODevice::WriteOnly)) { + supplicantConfig.write("ctrl_interface=/var/run/wpa_supplicant\n" + "ctrl_interface_group=0\n" + "update_config=1\n"); + } else { + qCWarning(B2QT_WIFI) << "failed to create supplicant configuration file."; + } +} + + /*! \class QWifiDevice \inmodule B2Qt.Wifi.Cpp @@ -49,7 +82,9 @@ QT_BEGIN_NAMESPACE */ QWifiDevice::QWifiDevice() + : d_ptr(new QWifiDevicePrivate(this)) { + d_ptr->createSupplicantConfig(); } QWifiDevice::~QWifiDevice() diff --git a/src/wifi/qwifidevice.h b/src/wifi/qwifidevice.h index 80b4891..02724b4 100644 --- a/src/wifi/qwifidevice.h +++ b/src/wifi/qwifidevice.h @@ -23,6 +23,8 @@ #include <QtCore/QByteArray> #include <QtCore/QLoggingCategory> +class QWifiDevicePrivate; + QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(B2QT_WIFI) @@ -37,6 +39,11 @@ public: Q_INVOKABLE static bool wifiSupported(); static QByteArray wifiInterfaceName(); static void setWifiInterfaceName(const QByteArray &name); + +private: + Q_DISABLE_COPY(QWifiDevice) + Q_DECLARE_PRIVATE(QWifiDevice) + QWifiDevicePrivate *const d_ptr; }; QT_END_NAMESPACE diff --git a/src/wifi/qwifielinux.cpp b/src/wifi/qwifielinux.cpp index 7456173..5d1fb3e 100644 --- a/src/wifi/qwifielinux.cpp +++ b/src/wifi/qwifielinux.cpp @@ -30,7 +30,10 @@ QT_BEGIN_NAMESPACE -const char SUPP_CONFIG_FILE[] = "/etc/wpa_supplicant.conf"; +// TODO: When cleaning up the library from Android code move this into a proper class +// (QWifiDevice?) since we won't depend on C style API from Android anymore. + +const char SUPP_CONFIG_FILE[] = "/etc/wpa_supplicant.qtwifi.conf"; const char IFACE_DIR[] = "/var/run/wpa_supplicant/"; const char WPA_EVENT_IGNORE[] = "CTRL-EVENT-IGNORE "; diff --git a/src/wifi/qwifimanager.cpp b/src/wifi/qwifimanager.cpp index 2a5cfff..739b399 100644 --- a/src/wifi/qwifimanager.cpp +++ b/src/wifi/qwifimanager.cpp @@ -37,6 +37,7 @@ const char *bsText[] = { "Initializing", "Running", "Terminating", "NotRunning" QWifiManagerPrivate::QWifiManagerPrivate(QWifiManager *manager) : q_ptr(manager) , m_networkListModel(new QWifiNetworkListModel()) + , m_device(new QWifiDevice()) , m_scanTimer(0) , m_scanning(false) , m_interface(QWifiDevice::wifiInterfaceName()) @@ -50,6 +51,7 @@ QWifiManagerPrivate::~QWifiManagerPrivate() { delete m_wifiController; delete m_networkListModel; + delete m_device; } void QWifiManagerPrivate::setCurrentSSID(const QString &ssid) diff --git a/src/wifi/qwifimanager_p.h b/src/wifi/qwifimanager_p.h index 6142c83..1046880 100644 --- a/src/wifi/qwifimanager_p.h +++ b/src/wifi/qwifimanager_p.h @@ -20,6 +20,7 @@ #define QWIFIMANAGER_P_H #include "qwifimanager.h" +#include "qwifidevice.h" #include <QtCore/QString> @@ -52,6 +53,7 @@ public: QWifiManager *const q_ptr; QWifiController *m_wifiController; QWifiNetworkListModel *m_networkListModel; + QWifiDevice *m_device; int m_scanTimer; bool m_scanning; |