summaryrefslogtreecommitdiffstats
path: root/src/imports/wifi
diff options
context:
space:
mode:
Diffstat (limited to 'src/imports/wifi')
-rw-r--r--src/imports/wifi/pluginmain.cpp30
-rw-r--r--src/imports/wifi/qmldir4
-rw-r--r--src/imports/wifi/qwifi_elinux.cpp264
-rw-r--r--src/imports/wifi/qwifi_elinux.h34
-rw-r--r--src/imports/wifi/qwifiinterface.cpp77
-rw-r--r--src/imports/wifi/qwifiinterface.h40
-rw-r--r--src/imports/wifi/qwifimanager.cpp818
-rw-r--r--src/imports/wifi/qwifimanager.h136
-rw-r--r--src/imports/wifi/qwifinetwork.cpp104
-rw-r--r--src/imports/wifi/qwifinetwork.h71
-rw-r--r--src/imports/wifi/qwifinetworklistmodel.cpp142
-rw-r--r--src/imports/wifi/qwifinetworklistmodel.h54
-rw-r--r--src/imports/wifi/wifi.pro34
13 files changed, 28 insertions, 1780 deletions
diff --git a/src/imports/wifi/pluginmain.cpp b/src/imports/wifi/pluginmain.cpp
index bc72906..f706023 100644
--- a/src/imports/wifi/pluginmain.cpp
+++ b/src/imports/wifi/pluginmain.cpp
@@ -16,15 +16,22 @@
** the contact form at http://www.qt.io
**
****************************************************************************/
-#include "qwifimanager.h"
-#include "qwifiinterface.h"
+#include <B2QtWifi/QWifiManager>
+#include <B2QtWifi/QWifiDevice>
+#include <B2QtWifi/QWifiConfiguration>
-#include <QtQml/QQmlExtensionPlugin>
-#include <QtQml/qqml.h>
+#include <QtQml>
-static QObject *global_object_wifi(QQmlEngine *, QJSEngine *)
+QT_BEGIN_NAMESPACE
+
+static QObject *globalWifiDevice(QQmlEngine *, QJSEngine *)
{
- return new QWifiInterface;
+ return new QWifiDevice;
+}
+
+static QObject *globalWifiManager(QQmlEngine *, QJSEngine *)
+{
+ return QWifiManager::instance();
}
class QWifiPlugin : public QQmlExtensionPlugin
@@ -35,12 +42,15 @@ class QWifiPlugin : public QQmlExtensionPlugin
public:
virtual void registerTypes(const char *uri)
{
- Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.labs.wifi"));
+ Q_ASSERT(QLatin1String(uri) == QLatin1String("B2Qt.Wifi"));
- qmlRegisterType<QWifiManager>(uri, 0, 1, "WifiManager");
- qmlRegisterType<QWifiNetworkListModel>();
- qmlRegisterSingletonType<QWifiInterface>(uri, 0, 1, "Interface", global_object_wifi);
+ qmlRegisterType<QAbstractListModel>();
+ qmlRegisterSingletonType<QWifiManager>(uri, 1, 0, "WifiManager", globalWifiManager);
+ qmlRegisterSingletonType<QWifiDevice>(uri, 1, 0, "WifiDevice", globalWifiDevice);
+ qmlRegisterType<QWifiConfiguration>(uri, 1, 0, "WifiConfiguration");
}
};
+QT_END_NAMESPACE
+
#include "pluginmain.moc"
diff --git a/src/imports/wifi/qmldir b/src/imports/wifi/qmldir
index d4f65d9..7e99b56 100644
--- a/src/imports/wifi/qmldir
+++ b/src/imports/wifi/qmldir
@@ -1,3 +1,3 @@
-module Qt.labs.wifi
-plugin qwifimodule
+module B2Qt.Wifi
+plugin b2qtwifiplugin
typeinfo plugins.qmltypes
diff --git a/src/imports/wifi/qwifi_elinux.cpp b/src/imports/wifi/qwifi_elinux.cpp
deleted file mode 100644
index 32e1aa3..0000000
--- a/src/imports/wifi/qwifi_elinux.cpp
+++ /dev/null
@@ -1,264 +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 "qwifi_elinux.h"
-
-#include <QtCore/QDebug>
-
-#include "wpa-supplicant/wpa_ctrl.h"
-
-#include <poll.h>
-#include <unistd.h>
-#include <sys/socket.h>
-
-static const char SUPP_CONFIG_FILE[] = "/etc/wpa_supplicant.conf";
-static const char IFACE_DIR[] = "/var/run/wpa_supplicant/";
-static const char WIFI[] = "wlan0";
-
-static struct wpa_ctrl *ctrl_conn;
-static struct wpa_ctrl *monitor_conn;
-// socket pair used to exit from a blocking read
-static int exit_sockets[2];
-
-static const char IFNAME[] = "IFNAME=";
-#define IFNAMELEN (sizeof(IFNAME) - 1)
-static const char WPA_EVENT_IGNORE[] = "CTRL-EVENT-IGNORE ";
-
-int wifi_connect_on_socket_path(const char *path);
-int wifi_ctrl_recv(char *reply, size_t *reply_len);
-int wifi_wait_on_socket(char *buf, size_t buflen);
-int wifi_send_command(const char *cmd, char *reply, size_t *reply_len);
-void wifi_close_sockets();
-
-int q_wifi_start_supplicant()
-{
- // NOTE: supplicant started when bringing up the wifi interface in
- // QWifiManager::connectToBackend() by:
- // QProcess::execute(QStringLiteral("ifup")
-
- /* Clear out any stale socket files that might be left over. */
- //wpa_ctrl_cleanup();
- /* Reset sockets used for exiting from hung state */
- exit_sockets[0] = exit_sockets[1] = -1;
- return 0;
-}
-
-int q_wifi_stop_supplicant()
-{
- // NOTE: supplicant stopped when bringing down the wifi
- // interface in QWifiManager::disconnectFromBackend() by:
- // QProcess::execute(QStringLiteral("ifdown")
- return 0;
-}
-
-int q_wifi_connect_to_supplicant(const char *ifname)
-{
- Q_UNUSED(ifname);
- static char path[4096];
- snprintf(path, sizeof(path), "%s/%s", IFACE_DIR, WIFI);
- return wifi_connect_on_socket_path(path);
-}
-
-int wifi_connect_on_socket_path(const char *path)
-{
- // establishes the control and monitor socket connections on the interface
- ctrl_conn = wpa_ctrl_open(path);
- if (ctrl_conn == NULL) {
- qWarning("Unable to open connection to supplicant on \"%s\": %s",
- path, strerror(errno));
- return -1;
- }
- monitor_conn = wpa_ctrl_open(path);
- if (monitor_conn == NULL) {
- wpa_ctrl_close(ctrl_conn);
- ctrl_conn = NULL;
- return -1;
- }
- if (wpa_ctrl_attach(monitor_conn) != 0) {
- wpa_ctrl_close(monitor_conn);
- wpa_ctrl_close(ctrl_conn);
- ctrl_conn = monitor_conn = NULL;
- return -1;
- }
-
- 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;
- return -1;
- }
-
- return 0;
-}
-
-int q_wifi_wait_for_event(const char *ifname, char *buf, size_t buflen)
-{
- Q_UNUSED(ifname);
- return wifi_wait_on_socket(buf, buflen);
-}
-
-int wifi_wait_on_socket(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 = wifi_ctrl_recv(buf, &nread);
-
- /* Terminate reception on exit socket */
- if (result == -2) {
- return snprintf(buf, buflen, WPA_EVENT_TERMINATING " - connection closed");
- }
-
- if (result < 0) {
- qWarning("wifi_ctrl_recv failed: %s\n", 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 */
- qWarning("Received EOF on supplicant socket\n");
- return snprintf(buf, buflen, WPA_EVENT_TERMINATING " - signal 0 received");
- }
- /*
- * Events strings are in the format
- *
- * IFNAME=iface <N>CTRL-EVENT-XXX
- * or
- * <N>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, IFNAMELEN) == 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", WPA_EVENT_IGNORE);
- }
- } else if (buf[0] == '<') {
- match = strchr(buf, '>');
- if (match != NULL) {
- nread -= (match + 1 - buf);
- memmove(buf, match + 1, nread + 1);
- //qWarning("supplicant generated event without interface - %s\n", buf);
- }
- } else {
- /* let the event go as is! */
- qWarning("supplicant generated event without interface and without message level - %s\n", buf);
- }
-
- return nread;
-}
-
-int wifi_ctrl_recv(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) {
- qWarning("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;
-}
-
-int wifi_send_command(const char *cmd, char *reply, size_t *reply_len)
-{
- int ret;
- if (ctrl_conn == NULL) {
- qWarning("Not connected to wpa_supplicant - \"%s\" command dropped.\n", cmd);
- return -1;
- }
- ret = wpa_ctrl_request(ctrl_conn, cmd, strlen(cmd), reply, reply_len, NULL);
- if (ret == -2) {
- qWarning("'%s' command timed out.\n", cmd);
- /* unblocks the monitor receive socket for termination */
- TEMP_FAILURE_RETRY(write(exit_sockets[0], "T", 1));
- return -2;
- } else if (ret < 0 || strncmp(reply, "FAIL", 4) == 0) {
- return -1;
- }
- if (strncmp(cmd, "PING", 4) == 0) {
- reply[*reply_len] = '\0';
- }
- return 0;
-}
-
-int q_wifi_command(const char *ifname, const char *command, char *reply, size_t *reply_len)
-{
- Q_UNUSED(ifname);
- return wifi_send_command(command, reply, reply_len);
-}
-
-void q_wifi_close_supplicant_connection(const char *ifname)
-{
- Q_UNUSED(ifname)
- wifi_close_sockets();
-}
-
-void wifi_close_sockets()
-{
- 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;
- }
-}
diff --git a/src/imports/wifi/qwifi_elinux.h b/src/imports/wifi/qwifi_elinux.h
deleted file mode 100644
index a89642f..0000000
--- a/src/imports/wifi/qwifi_elinux.h
+++ /dev/null
@@ -1,34 +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 LOCAL_WIFI_H
-#define LOCAL_WIFI_H
-
-#include <string.h>
-
-// This API mirrors Android's Wi-Fi libraries interface [1] and implementation, excluding Android OS specific parts.
-// [1] http://androidxref.com/4.4.2_r2/xref/hardware/libhardware_legacy/include/hardware_legacy/wifi.h
-
-int q_wifi_command(const char *ifname, const char *command, char *reply, size_t *reply_len);
-int q_wifi_wait_for_event(const char *ifname, char *buf, size_t buflen);
-int q_wifi_connect_to_supplicant(const char *ifname);
-void q_wifi_close_supplicant_connection(const char *ifname);
-int q_wifi_start_supplicant();
-int q_wifi_stop_supplicant();
-
-#endif // LOCAL_WIFI_H
diff --git a/src/imports/wifi/qwifiinterface.cpp b/src/imports/wifi/qwifiinterface.cpp
deleted file mode 100644
index acd7716..0000000
--- a/src/imports/wifi/qwifiinterface.cpp
+++ /dev/null
@@ -1,77 +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 "qwifiinterface.h"
-
-/*!
- \qmltype Interface
- \inqmlmodule Qt.labs.wifi
- \ingroup wifi-qmltypes
- \brief The Interface element provides the module API.
-
- This element cannot be directly created. It can only be accessed via a namespace import.
-
- \code
- import Qt.labs.wifi 0.1
- import Qt.labs.wifi 0.1 as Wifi
-
- Component.onCompleted: {
- if (Wifi.Interface.wifiSupported()) {
- var component = Qt.createComponent("WifiMenu.qml")
- } else {
- print("WiFi functionality not available on this device.")
- }
- }
- \endcode
-*/
-
-/*!
- \qmlmethod bool Interface::wifiSupported()
-
- Returns true if the device is WiFi capable (provides a WiFi driver), otherwise returns false.
-*/
-
-bool QWifiInterface::wifiSupported() const
-{
-#ifdef Q_OS_ANDROID
- const char *fwpath = 0;
- // reload wifi firmware
- fwpath = (char *)wifi_get_fw_path(WIFI_GET_FW_PATH_STA);
- if (!fwpath) {
- qWarning() << "QWifiInterface: failed to get firmware path";
- return false;
- }
- if (wifi_change_fw_path((const char *)fwpath)) {
- qWarning() << "QWifiInterface: failed to change firmware path";
- return false;
- }
-#endif
- const bool hasInterface = QDir().exists(QStringLiteral("/sys/class/net/wlan0"));
- if (!hasInterface)
- qWarning() << "QWifiInterface: could not find wifi interface in /sys/class/net/";
-#ifdef Q_OS_ANDROID
- if (hasInterface && wifi_load_driver() == 0 && wifi_start_supplicant(0) == 0) {
- return true;
- } else {
- qWarning() << "QWifiInterface: wifi driver is not available";
- return false;
- }
-#else
- return hasInterface;
-#endif
-}
diff --git a/src/imports/wifi/qwifiinterface.h b/src/imports/wifi/qwifiinterface.h
deleted file mode 100644
index 06abd79..0000000
--- a/src/imports/wifi/qwifiinterface.h
+++ /dev/null
@@ -1,40 +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 QWIFIINTERFACE_H
-#define QWIFIINTERFACE_H
-
-#include <QtCore/QDir>
-#include <QtCore/QDebug>
-#ifdef Q_OS_ANDROID
-#include <hardware_legacy/wifi.h>
-#include <cutils/properties.h>
-#endif
-
-class QWifiInterface : public QObject
-{
- Q_OBJECT
-public:
- explicit QWifiInterface(QObject *parent = 0)
- : QObject(parent) {}
- ~QWifiInterface() {}
-
- Q_INVOKABLE bool wifiSupported() const;
-};
-
-#endif // QWIFIHELPERS_H
diff --git a/src/imports/wifi/qwifimanager.cpp b/src/imports/wifi/qwifimanager.cpp
deleted file mode 100644
index 2574cd2..0000000
--- a/src/imports/wifi/qwifimanager.cpp
+++ /dev/null
@@ -1,818 +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 "qwifimanager.h"
-#include "qwifiinterface.h"
-
-#include <QtCore>
-#ifdef Q_OS_ANDROID
-#include <hardware_legacy/wifi.h>
-#include <cutils/sockets.h>
-#include <unistd.h>
-#else
-#include <qwifi_elinux.h>
-#endif
-
-static const char SUPPLICANT_SVC[] = "init.svc.wpa_supplicant";
-static const char WIFI_INTERFACE[] = "wifi.interface";
-static const char QT_WIFI_BACKEND[] = "qt.wifi";
-
-static bool QT_WIFI_DEBUG = !qgetenv("QT_WIFI_DEBUG").isEmpty();
-
-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);
-
-#ifdef Q_OS_ANDROID
-/*
- * Work around API differences between Android versions
- */
-
-static int q_wifi_start_supplicant()
-{
-#if Q_ANDROID_VERSION_MAJOR == 4 && Q_ANDROID_VERSION_MINOR < 1
- return wifi_start_supplicant();
-#else
- return wifi_start_supplicant(0);
-#endif
-}
-
-static int q_wifi_stop_supplicant()
-{
-#if Q_ANDROID_VERSION_MAJOR == 4 && Q_ANDROID_VERSION_MINOR < 1
- return wifi_stop_supplicant();
-#else
- return wifi_stop_supplicant(0);
-#endif
-}
-
-static int q_wifi_connect_to_supplicant(const char *ifname)
-{
-#if Q_ANDROID_VERSION_MAJOR == 4 && (Q_ANDROID_VERSION_MINOR < 4 && Q_ANDROID_VERSION_MINOR >= 1)
- return wifi_connect_to_supplicant(ifname);
-#else
- Q_UNUSED(ifname);
- return wifi_connect_to_supplicant();
-#endif
-}
-
-static void q_wifi_close_supplicant_connection(const char *ifname)
-{
-#if Q_ANDROID_VERSION_MAJOR == 4 && (Q_ANDROID_VERSION_MINOR < 4 && Q_ANDROID_VERSION_MINOR >= 1)
- wifi_close_supplicant_connection(ifname);
-#else
- Q_UNUSED(ifname);
- wifi_close_supplicant_connection();
-#endif
-}
-
-static int q_wifi_wait_for_event(const char *ifname, char *buf, size_t len)
-{
-#if Q_ANDROID_VERSION_MAJOR == 4 && (Q_ANDROID_VERSION_MINOR < 4 && Q_ANDROID_VERSION_MINOR >= 1)
- return wifi_wait_for_event(ifname, buf, len);
-#else
- Q_UNUSED(ifname);
- return wifi_wait_for_event(buf, len);
-#endif
-}
-
-static int q_wifi_command(const char *ifname, const char *command, char *reply, size_t *reply_len)
-{
-#if Q_ANDROID_VERSION_MAJOR == 4 && (Q_ANDROID_VERSION_MINOR < 4 && Q_ANDROID_VERSION_MINOR >= 1)
- return wifi_command(ifname, command, reply, reply_len);
-#else
- Q_UNUSED(ifname);
- return wifi_command(command, reply, reply_len);
-#endif
-}
-
-/*
- * This function is borrowed from /system/core/libnetutils/dhcp_utils.c
- *
- * Wait for a system property to be assigned a specified value.
- * If desired_value is NULL, then just wait for the property to
- * be created with any value. maxwait is the maximum amount of
- * time in seconds to wait before giving up.
- */
-static const int NAP_TIME = 200; // wait for 200ms at a time when polling for property values
-static int wait_for_property(const char *name, const char *desired_value, int maxwait)
-{
- char value[PROPERTY_VALUE_MAX] = {'\0'};
- int maxnaps = (maxwait * 1000) / NAP_TIME;
-
- if (maxnaps < 1) {
- maxnaps = 1;
- }
-
- while (maxnaps-- > 0) {
- usleep(NAP_TIME * 1000);
- if (property_get(name, value, NULL)) {
- if (desired_value == NULL ||
- strcmp(value, desired_value) == 0) {
- return 0;
- }
- }
- }
- return -1; /* failure */
-}
-#endif
-
-class QWifiManagerEvent : public QEvent
-{
-public:
- QWifiManagerEvent(QEvent::Type type, const QByteArray &data = QByteArray())
- : QEvent(type)
- , m_data(data)
- {
- }
-
- QByteArray data() const { return m_data; }
-
-private:
- QByteArray m_data;
-};
-
-class QWifiManagerEventThread : public QThread
-{
-public:
- QWifiManagerEventThread(QWifiManager *manager, const QByteArray &interface)
- : m_manager(manager)
- , m_if(interface)
- {
-
- }
-
- void run() {
- if (QT_WIFI_DEBUG) qDebug("WiFi event thread is running");
- QWifiManagerEvent *event = 0;
- char buffer[2048];
- while (1) {
- int size = q_wifi_wait_for_event(m_if.constData(), buffer, sizeof(buffer) - 1);
- if (size > 0) {
- buffer[size] = 0;
- event = 0;
- if (strstr(buffer, "SCAN-RESULTS")) {
- if (m_manager->exitingEventThread()) {
- if (QT_WIFI_DEBUG) qDebug() << "Exiting WiFi event thread";
- return;
- }
- event = new QWifiManagerEvent(WIFI_SCAN_RESULTS);
- } else if (strstr(buffer, "CONNECTED")) {
- event = new QWifiManagerEvent(WIFI_CONNECTED);
- } else if (strstr(buffer, "Handshake failed")) {
- event = new QWifiManagerEvent(WIFI_HANDSHAKE_FAILED);
- } else if (strstr(buffer, "TERMINATING")) {
- // stop monitoring for events when supplicant is terminating
- return;
- }
- if (event)
- QCoreApplication::postEvent(m_manager, event);
- }
- }
- }
-
- QWifiManager *m_manager;
- QByteArray m_if;
-};
-
-/*!
- \qmlmodule Qt.labs.wifi 0.1
- \title WiFi Module
- \ingroup qtee-qmlmodules
- \brief Controlling wireless network interfaces.
-
- Provides QML types for controlling and accessing information about wireless network interfaces.
-
- The import command for adding these QML types is:
-
- \code
- import Qt.labs.wifi 0.1
- \endcode
-
- If the module is imported into a namespace, some additional methods become available through the
- \l Interface element.
-
- \code
- import Qt.labs.wifi 0.1 as Wifi
- \endcode
-
- \section1 QML Types
-*/
-
-/*!
-
- \qmltype WifiManager
- \inqmlmodule Qt.labs.wifi
- \ingroup wifi-qmltypes
- \brief Provides information about the WiFi backend and available networks.
-
- This element is the main interface to the WiFi functionality.
-
- */
-
-/*!
- \qmlproperty enumeration WifiManager::networkState
-
- This property holds the current state of the network connection.
-
- \list
- \li \e WifiManager.Disconnected - Not connected to any network
- \li \e WifiManager.Authenticating - Verifying password with the network provider
- \li \e WifiManager.HandshakeFailed - Incorrect password provided
- \li \e WifiManager.ObtainingIPAddress - Requesting IP address from DHCP server
- \li \e WifiManager.DhcpRequestFailed - Could not retrieve IP address
- \li \e WifiManager.Connected - Ready to process network requests
- \endlist
-*/
-
-/*!
- \qmlproperty bool WifiManager::backendReady
-
- This property holds whether or not the backend has been successfully initialized.
-
- \code
- WifiManager {
- id: wifiManager
- scanning: backendReady
- }
-
- Button {
- id: wifiOnOffButton
- text: (wifiManager.backendReady) ? "Switch Off" : "Switch On"
- onClicked: {
- if (wifiManager.backendReady) {
- wifiManager.stop()
- } else {
- wifiManager.start()
- }
- }
- }
- \endcode
-*/
-
-/*!
- \qmlproperty bool WifiManager::scanning
-
- This property holds whether or not the backend is scanning for WiFi networks. To
- preserve battery energy, stop scanning for networks once you are done with configuring a network.
-
- Before starting to scan for networks, you need to initialize the WiFi backend.
-
- \sa start
-*/
-
-/*!
- \qmlproperty string WifiManager::connectedSSID
-
- This property holds the network name.
-*/
-
-/*!
- \qmlproperty WifiNetworkListModel WifiManager::networks
-
- This property holds a list of networks that can be sensed by a device. Use the returned
- model as data model in ListView, model is updated every 5 seconds.
-
- WifiNetworkListModel is a simple data model consisting of WifiNetwork objects, accessed with
- the "network" data role. Instances of WifiNetwork cannot be created directly from the QML system.
-
- \code
- WifiManager {
- id: wifiManager
- scanning: backendReady
- Component.onCompleted: start()
- }
-
- Component {
- id: listDelegate
- Rectangle {
- id: delegateBackground
- height: 60
- width: parent.width
- color: "#5C5C5C"
- border.color: "black"
- border.width: 1
-
- Text {
- id: ssidLabel
- anchors.top: parent.top
- anchors.left: parent.left
- anchors.margins: 10
- font.pixelSize: 20
- font.bold: true
- color: "#E6E6E6"
- text: network.ssid
- }
-
- Rectangle {
- width: Math.max(100 + network.signalStrength, 0) / 100 * parent.width;
- height: 20
- radius: 10
- antialiasing: true
- anchors.margins: 20
- anchors.right: parent.right
- anchors.top: parent.top
- color: "#BF8888"
- border.color: "#212126"
- }
- }
- }
-
-
- ListView {
- id: networkView
- anchors.fill: parent
- model: wifiManager.networks
- delegate: listDelegate
- }
- \endcode
-
-*/
-
-/*!
- \qmlmethod void WifiManager::start()
-
- Start an initialization of the WiFi backend.
-
- \sa stop
- */
-
-/*!
- \qmlmethod void WifiManager::stop()
-
- Stop the WiFi backend and shut down all network functionality.
-
- \sa start
- */
-
-/*!
- \qmlmethod void WifiManager::connect(WifiNetwork network, const string passphrase)
-
- Connect to network \a network and use passphrase \a passphrase for authentication.
-
- \sa disconnect, networkState
- */
-
-/*!
- \qmlmethod void WifiManager::disconnect()
-
- Disconnect from currently connected network connection.
-
- \sa connect, networkState
- */
-
-/*!
- \qmlsignal void WifiManager::scanningChanged(bool scanning)
-
- This signal is emitted when device starts or stops to scan for available wifi networks.
-
- \sa scanning
-
-*/
-
-/*!
- \qmlsignal void WifiManager::networkStateChanged(WifiNetwork network)
-
- This signal is emitted whenever changes in a network state occur. Network \a network is the
- the currently active network connection.
-
- \sa networkState
-*/
-
-/*!
- \qmlsignal void WifiManager::backendReadyChanged()
-
- This signal is emitted when backend has been successfully initialized or shut down.
-
- \sa start, stop
-*/
-
-/*!
- \qmlsignal void WifiManager::connectedSSIDChanged(string ssid)
-
- This signal is emitted when the device has connected to or disconnected from a network.
- \a ssid contains the name of the connected network, or an empty string if the network was disconnected.
-
- \sa connect, disconnect
-*/
-
-QWifiManager::QWifiManager()
- : m_networkListModel(this)
- , m_eventThread(0)
- , m_scanTimer(0)
- , m_scanning(false)
-#ifdef Q_OS_ANDROID
- , m_daemonClientSocket(0)
-#endif
- , m_exitingEventThread(false)
- , m_startingUp(true)
- , m_network(0)
-{
- if (!QWifiInterface().wifiSupported())
- // give a warning about API misuse
- qWarning() << "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 WifiManager!";
-#ifdef Q_OS_ANDROID
- char interface[PROPERTY_VALUE_MAX];
- property_get(WIFI_INTERFACE, interface, NULL);
- m_interface = interface;
-#else
- m_interface = "wlan0"; // use envvar for the interface name?
- m_dhcpRunner = new ProcessRunner(m_interface);
- QObject::connect(m_dhcpRunner, &ProcessRunner::processFinished, this, &QWifiManager::handleDhcpFinished);
-#endif
- qDebug("QWifiManager: using wifi interface: %s", m_interface.constData());
- m_eventThread = new QWifiManagerEventThread(this, m_interface);
-#ifdef Q_OS_ANDROID
- m_daemonClientSocket = new QLocalSocket;
- int qconnFd = socket_local_client("qconnectivity", ANDROID_SOCKET_NAMESPACE_RESERVED, SOCK_STREAM);
- if (qconnFd != -1) {
- m_daemonClientSocket->setSocketDescriptor(qconnFd);
- QObject::connect(m_daemonClientSocket, SIGNAL(readyRead()), this, SLOT(handleDhcpReply()));
- QObject::connect(m_daemonClientSocket, SIGNAL(connected()), this, SLOT(connectedToDaemon()));
- } else {
- qWarning() << "QWifiManager: failed to connect to qconnectivity socket";
- }
- // check if backend has already been initialized
- char backendStatus[PROPERTY_VALUE_MAX];
- if (property_get(QT_WIFI_BACKEND, backendStatus, NULL)) {
- if (strcmp(backendStatus, "running") == 0) {
- // let it re-connect, in most cases this will see that everything is working properly
- // and will do nothing. Special case is when process has crashed or was killed by a system
- // signal in previous execution, which results in broken connection to a supplicant,
- // connectToBackend will fix it..
- connectToBackend();
- } else if (strcmp(backendStatus, "stopped") == 0) {
- // same here, cleans up the state
- disconnectFromBackend();
- }
- } else {
-#endif
- m_backendReady = false;
- emit backendReadyChanged();
-#ifdef Q_OS_ANDROID
- }
-#endif
-}
-
-QWifiManager::~QWifiManager()
-{
- exitEventThread();
- delete m_eventThread;
-#ifdef Q_OS_ANDROID
- delete m_daemonClientSocket;
-#endif
-}
-
-#ifdef Q_OS_ANDROID
-void QWifiManager::handleDhcpReply()
-{
- if (m_daemonClientSocket->canReadLine()) {
- QByteArray receivedMessage;
- receivedMessage = m_daemonClientSocket->readLine(m_daemonClientSocket->bytesAvailable());
- if (QT_WIFI_DEBUG) qDebug() << "QWifiManager: reply from qconnectivity: " << receivedMessage;
- if (receivedMessage == "success") {
- updateNetworkState(Connected);
- emit connectedSSIDChanged(m_connectedSSID);
- // Store settings of a working wifi connection
- call("SAVE_CONFIG");
- } else if (receivedMessage == "failed") {
- updateNetworkState(DhcpRequestFailed);
- } else {
- qWarning() << "QWifiManager: unknown message: " << receivedMessage;
- }
- }
-}
-
-void QWifiManager::sendDhcpRequest(const QByteArray &request)
-{
- if (QT_WIFI_DEBUG) qDebug() << "QWifiManager: sending request - " << request;
- m_request = request;
- m_request.append("\n");
- m_daemonClientSocket->abort();
- // path where android stores "reserved" sockets
- m_daemonClientSocket->connectToServer(ANDROID_SOCKET_DIR "/qconnectivity");
-}
-
-void QWifiManager::connectedToDaemon()
-{
- m_daemonClientSocket->write(m_request.constData(), m_request.length());
- m_daemonClientSocket->flush();
-}
-#endif
-
-void QWifiManager::handleDhcpFinished()
-{
- // ### TODO - could be that dhcp request fails, how to determine?
- updateNetworkState(Connected);
- call("SAVE_CONFIG");
-}
-
-void QWifiManager::start()
-{
- if (QT_WIFI_DEBUG) qDebug("QWifiManager: connecting to the backend");
- if (m_backendReady)
- return;
- connectToBackend();
-}
-
-void QWifiManager::stop()
-{
- if (QT_WIFI_DEBUG) qDebug("QWifiManager: shutting down");
- if (!m_backendReady)
- return;
- disconnectFromBackend();
-}
-
-void QWifiManager::connectToBackend()
-{
- // ### TODO: maybe it makes sense to move this functions in non-gui thread
-#ifdef Q_OS_ANDROID
- if (!(is_wifi_driver_loaded() || wifi_load_driver() == 0)) {
- qWarning("QWifiManager: failed to load a driver");
- return;
- }
-#else
- QProcess::execute(QStringLiteral("ifup"), QStringList() << m_interface.constData());
-#endif
- if (q_wifi_start_supplicant() != 0) {
- qWarning("QWifiManager: failed to start a supplicant");
- return;
- }
-#ifdef Q_OS_ANDROID
- if (wait_for_property(SUPPLICANT_SVC, "running", 5) < 0) {
- qWarning("QWifiManager: Timed out waiting for supplicant to start");
- return;
- }
-#endif
- if (q_wifi_connect_to_supplicant(m_interface.constData()) == 0) {
- m_backendReady = true;
- emit backendReadyChanged();
-#ifdef Q_OS_ANDROID
- property_set(QT_WIFI_BACKEND, "running");
-#endif
- } else {
- qWarning("QWifiManager: failed to connect to a supplicant");
- return;
- }
- if (QT_WIFI_DEBUG) qDebug("QWifiManager: started successfully");
- m_exitingEventThread = false;
- m_eventThread->start();
- call("SCAN");
-}
-
-void QWifiManager::disconnectFromBackend()
-{
- exitEventThread();
- if (q_wifi_stop_supplicant() < 0)
- qWarning("QWifiManager: failed to stop supplicant");
- q_wifi_close_supplicant_connection(m_interface.constData());
- setScanning(false);
-#ifdef Q_OS_ANDROID
- property_set(QT_WIFI_BACKEND, "stopped");
-#else
- QProcess::execute(QStringLiteral("ifdown"), QStringList() << m_interface.constData());
-#endif
- m_backendReady = false;
- emit backendReadyChanged();
-}
-
-void QWifiManager::exitEventThread()
-{
- if (m_eventThread->isRunning()) {
- m_exitingEventThread = true;
- call("SCAN");
- m_eventThread->wait();
- }
-}
-
-void QWifiManager::setScanning(bool scanning)
-{
- if (!m_backendReady || m_scanning == scanning)
- return;
-
- m_scanning = scanning;
- emit scanningChanged(m_scanning);
-
- if (m_scanning) {
- if (QT_WIFI_DEBUG) qDebug("QWifiManager: scanning");
- call("SCAN");
- m_scanTimer = startTimer(5000); // ### todo - this could be a qml property
- } else {
- if (QT_WIFI_DEBUG) qDebug("QWifiManager: stop scanning");
- killTimer(m_scanTimer);
- }
-}
-
-QByteArray QWifiManager::call(const char *command) const
-{
- char data[2048];
- size_t len = sizeof(data) - 1; // -1: room to add a 0-terminator
- QByteArray cmd;
-#ifdef Q_OS_ANDROID
-#if !(Q_ANDROID_VERSION_MAJOR == 4 && Q_ANDROID_VERSION_MINOR < 4)
- cmd.append("IFNAME=").append(m_interface).append(" ");
-#endif
-#endif
- cmd.append(command);
- if (q_wifi_command(m_interface.constData(), cmd.constData(), data, &len) < 0) {
- qWarning("QWifiManager: call failed: %s", cmd.constData());
- return QByteArray();
- }
- if (len < sizeof(data))
- data[len] = 0;
- QByteArray result = QByteArray::fromRawData(data, len);
- if (QT_WIFI_DEBUG) qDebug("QWifiManager::call: %s ==>\n%s", cmd.constData(), result.constData());
- return result;
-}
-
-bool QWifiManager::checkedCall(const char *command) const
-{
- return call(command).trimmed().toUpper() == "OK";
-}
-
-void QWifiManager::updateNetworkState(NetworkState state)
-{
- m_state = state;
- if (m_network)
- emit networkStateChanged(m_network);
-}
-
-bool QWifiManager::event(QEvent *e)
-{
- switch ((int) e->type()) {
- case WIFI_SCAN_RESULTS:
- m_networkListModel.parseScanResults(call("SCAN_RESULTS"));
- if (m_startingUp)
- handleConnected();
- return true;
- case WIFI_CONNECTED:
- handleConnected();
- break;
- case WIFI_HANDSHAKE_FAILED:
- updateNetworkState(HandshakeFailed);
- break;
- case QEvent::Timer: {
- int tid = static_cast<QTimerEvent *>(e)->timerId();
- if (tid == m_scanTimer) {
- call("SCAN");
- return true;
- }
- break;
- }
- }
-
- return QObject::event(e);
-}
-
-void QWifiManager::connect(QWifiNetwork *network, const QString &passphrase)
-{
- m_network = network;
- if (network->ssid() == m_connectedSSID) {
- if (QT_WIFI_DEBUG)
- qDebug("QWifiManager::connect(), already connected to %s", network->ssid().constData());
- return;
- }
- updateNetworkState(Authenticating);
- call("DISABLE_NETWORK all");
- if (!m_connectedSSID.isEmpty()) {
- m_connectedSSID.clear();
- emit connectedSSIDChanged(m_connectedSSID);
- }
-
- bool networkKnown = false;
- QByteArray id;
- QByteArray listResult = call("LIST_NETWORKS");
- QList<QByteArray> lines = listResult.split('\n');
- foreach (const QByteArray &line, lines) {
- if (line.contains(network->ssid())) {
- id = line.split('\t').at(0);
- networkKnown = true;
- break;
- }
- }
-
- if (!networkKnown) {
- bool ok;
- id = call("ADD_NETWORK").trimmed();
- id.toInt(&ok);
- if (!ok) {
- qWarning("QWifiManager::connect(), failed to add network");
- return;
- }
- }
- QByteArray setNetworkCommand = QByteArray("SET_NETWORK ") + id;
-
- bool ok = true;
- if (!networkKnown)
- ok = ok && checkedCall(setNetworkCommand + QByteArray(" ssid ") + '"' + network->ssid() + '"');
-
- QByteArray key_mgmt;
- if (network->supportsWPA() || network->supportsWPA2()) {
- ok = ok && checkedCall(setNetworkCommand + QByteArray(" psk ") + '"' + passphrase.toLatin1() + '"');
- key_mgmt = "WPA-PSK";
- } else if (network->supportsWEP()) {
- ok = ok && checkedCall(setNetworkCommand + QByteArray(" wep_key0 ") + '"' + passphrase.toLatin1() + '"');
- ok = ok && checkedCall(setNetworkCommand + QByteArray(" auth_alg OPEN SHARED"));
- key_mgmt = "NONE";
- } else if (!network->supportsWPS() && passphrase.length() == 0) {
- // open network
- key_mgmt = "NONE";
- }
- ok = ok && checkedCall(setNetworkCommand + QByteArray(" key_mgmt ") + key_mgmt);
-
- if (!ok) {
- if (!networkKnown)
- call("REMOVE_NETWORK " + id);
- qWarning("QWifiManager::connect(), failed to set properties on network '%s'", id.constData());
- return;
- }
-
- call(QByteArray("SELECT_NETWORK ") + id);
- call("RECONNECT");
-}
-
-void QWifiManager::disconnect()
-{
- call("DISCONNECT");
-#ifdef Q_OS_ANDROID
- QByteArray req = m_interface;
- sendDhcpRequest(req.append(" disconnect"));
-#endif
- m_connectedSSID.clear();
- updateNetworkState(Disconnected);
- emit connectedSSIDChanged(m_connectedSSID);
-}
-
-void ProcessRunner::run()
-{
- // kill existing udhcpc instance
- QString filePath = QString("/var/run/udhcpc.").append(m_ifc).append(".pid");
- QFile pidFile(filePath);
- if (pidFile.open(QIODevice::ReadOnly)) {
- QByteArray pid = pidFile.readAll();
- pidFile.close();
- QProcess::execute(QStringLiteral("kill"), QStringList() << pid.trimmed().constData());
- } else {
- qWarning() << "QWifiManager - Failed to read" << filePath;
- }
- QStringList args;
- args << QStringLiteral("-R") << QStringLiteral("-n") << QStringLiteral("-p")
- << filePath << QStringLiteral("-i") << m_ifc;
- // start DHCP client
- QProcess::execute(QStringLiteral("udhcpc"), args);
- emit processFinished();
-}
-
-void QWifiManager::handleConnected()
-{
- QList<QByteArray> lists = call("LIST_NETWORKS").split('\n');
- QByteArray connectedNetwork;
- for (int i = 1; i < lists.size(); ++i) {
- if (lists.at(i).toUpper().contains("[CURRENT]")) {
- connectedNetwork = lists.at(i);
- break;
- }
- }
-
- if (connectedNetwork.isEmpty()) {
- if (QT_WIFI_DEBUG) qDebug("QWifiManager::handleConnected: not connected to a network...");
- return;
- }
-
- if (QT_WIFI_DEBUG) qDebug("QWifiManager::handleConnected: current is %s", connectedNetwork.constData());
-
- QList<QByteArray> info = connectedNetwork.split('\t');
- m_connectedSSID = info.at(1);
-
- if (m_startingUp) {
- m_startingUp = false;
- if (!m_network) {
- int pos = 0; // unused
- m_network = m_networkListModel.networkForSSID(info.at(1), &pos);
- }
- }
-
- updateNetworkState(ObtainingIPAddress);
-#ifdef Q_OS_ANDROID
- QByteArray req = m_interface;
- sendDhcpRequest(req.append(" connect"));
-#else
- m_dhcpRunner->start();
-#endif
-}
diff --git a/src/imports/wifi/qwifimanager.h b/src/imports/wifi/qwifimanager.h
deleted file mode 100644
index 7acc360..0000000
--- a/src/imports/wifi/qwifimanager.h
+++ /dev/null
@@ -1,136 +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 <QtCore/QObject>
-#include <QtCore/QThread>
-#include <QtCore/QByteArray>
-
-#ifdef Q_OS_ANDROID
-#include <QtNetwork/QLocalSocket>
-#include <cutils/properties.h>
-#endif
-
-#include "qwifinetworklistmodel.h"
-
-class QWifiManagerEventThread;
-
-class ProcessRunner : public QThread
-{
- Q_OBJECT
-public:
- ProcessRunner(const QByteArray &ifc) : m_ifc(ifc) {}
- void run();
-
-signals:
- void processFinished();
-
-private:
- QByteArray m_ifc;
-};
-
-class QWifiManager : public QObject
-{
- Q_OBJECT
- Q_ENUMS(NetworkState)
- Q_PROPERTY(NetworkState networkState READ networkState NOTIFY networkStateChanged)
- Q_PROPERTY(bool backendReady READ isbackendReady NOTIFY backendReadyChanged)
- Q_PROPERTY(bool scanning READ scanning WRITE setScanning NOTIFY scanningChanged)
- Q_PROPERTY(QString connectedSSID READ connectedSSID NOTIFY connectedSSIDChanged)
- Q_PROPERTY(QWifiNetworkListModel *networks READ networks CONSTANT)
-
-public:
- enum NetworkState {
- Disconnected,
- Authenticating,
- HandshakeFailed,
- ObtainingIPAddress,
- DhcpRequestFailed,
- Connected
- };
-
- QWifiManager();
- ~QWifiManager();
-
- QWifiNetworkListModel *networks() { return &m_networkListModel; }
- QString connectedSSID() const { return m_connectedSSID; }
- bool scanning() const { return m_scanning; }
- void setScanning(bool scanning);
- NetworkState networkState() const { return m_state; }
- bool isbackendReady() const { return m_backendReady; }
- bool exitingEventThread() const { return m_exitingEventThread; }
-
-public slots:
- void start();
- void stop();
- void connect(QWifiNetwork *network, const QString &passphrase);
- void disconnect();
-
-signals:
- void scanningChanged(bool scanning);
- void networkStateChanged(QWifiNetwork *network);
- void backendReadyChanged();
- void connectedSSIDChanged(const QString &ssid);
-
-protected:
- bool event(QEvent *);
- void handleConnected();
- void connectToBackend();
- void disconnectFromBackend();
- void exitEventThread();
-
- QByteArray call(const char *command) const;
- bool checkedCall(const char *command) const;
- void updateNetworkState(NetworkState state);
-
-protected slots:
-#if defined(FORCE_MOC)
- void sendDhcpRequest(const QByteArray &request);
- void connectedToDaemon();
- void handleDhcpReply();
-#endif
- void handleDhcpFinished();
-
-private:
- friend class QWifiManagerEventThread;
- friend class ProcessRunner;
-
- QString m_connectedSSID;
- QWifiNetworkListModel m_networkListModel;
- QWifiManagerEventThread *m_eventThread;
-
- int m_scanTimer;
- bool m_scanning;
- bool m_backendReady;
-
- QByteArray m_interface;
- NetworkState m_state;
-#ifdef Q_OS_ANDROID
- QLocalSocket *m_daemonClientSocket;
-#else
- ProcessRunner *m_dhcpRunner;
-#endif
- QByteArray m_request;
- bool m_exitingEventThread;
- bool m_startingUp;
- QWifiNetwork *m_network;
-};
-
-#endif // QWIFIMANAGER_H
diff --git a/src/imports/wifi/qwifinetwork.cpp b/src/imports/wifi/qwifinetwork.cpp
deleted file mode 100644
index 84e3b5b..0000000
--- a/src/imports/wifi/qwifinetwork.cpp
+++ /dev/null
@@ -1,104 +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.h"
-
-/*!
- \qmltype WifiNetwork
- \inqmlmodule Qt.labs.wifi
- \ingroup wifi-qmltypes
- \brief Represents a single WiFi network access point.
-
- Instances of WifiNetwork cannot be created directly from the QML system, use
- WifiManager::networks.
-*/
-
-/*!
- \qmlproperty string WifiNetwork::bssid
-
- This property holds basic service set identification of a network, used to uniquely
- identify BSS.
-
-*/
-
-/*!
- \qmlproperty string WifiNetwork::ssid
-
- This property holds a network name. The SSID is the informal (human) name of BSS.
-*/
-
-/*!
- \qmlproperty int WifiNetwork::signalStrength
-
- This property holds the current strength of a WiFi signal, measured in dBm. New readings are
- taken every 5 seconds.
-
- \sa signalStrengthChanged
-*/
-
-/*!
- \qmlproperty bool WifiNetwork::supportsWPA
-
- This property holds whether network access point supports WPA security protocol.
-*/
-
-/*!
- \qmlproperty bool WifiNetwork::supportsWPA2
-
- This property holds whether network access point supports WPA2 security protocol.
-*/
-
-/*!
- \qmlproperty bool WifiNetwork::supportsWEP
-
- This property holds whether network access point supports WEP security protocol.
-*/
-
-/*!
- \qmlproperty bool WifiNetwork::supportsWPS
-
- This property holds whether network access point supports WPS security protocol.
-*/
-
-/*!
- \qmlsignal void WifiNetwork::signalStrengthChanged(int strength)
-
- This signal is emitted whenever signal strength has changed comparing the the
- previous reading, the new signal's strength is \a strength.
-
-*/
-
-QWifiNetwork::QWifiNetwork() :
- m_outOfRange(false)
-{
-}
-
-void QWifiNetwork::setSignalStrength(int strength)
-{
- if (m_signalStrength == strength)
- return;
- m_signalStrength = strength;
- emit signalStrengthChanged(m_signalStrength);
-}
-
-void QWifiNetwork::setOutOfRange(bool outOfRange)
-{
- if (m_outOfRange == outOfRange)
- return;
- m_outOfRange = outOfRange;
-}
diff --git a/src/imports/wifi/qwifinetwork.h b/src/imports/wifi/qwifinetwork.h
deleted file mode 100644
index 5a92e17..0000000
--- a/src/imports/wifi/qwifinetwork.h
+++ /dev/null
@@ -1,71 +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 <QtCore/QByteArray>
-#include <QtCore/QObject>
-
-class QWifiNetwork : public QObject
-{
- Q_OBJECT
-
- Q_PROPERTY(QByteArray bssid READ bssid CONSTANT)
- Q_PROPERTY(QByteArray ssid READ ssid CONSTANT)
- Q_PROPERTY(int signalStrength READ signalStrength NOTIFY signalStrengthChanged)
- Q_PROPERTY(bool supportsWPA2 READ supportsWPA2 CONSTANT)
- Q_PROPERTY(bool supportsWPA READ supportsWPA CONSTANT)
- Q_PROPERTY(bool supportsWEP READ supportsWEP CONSTANT)
- Q_PROPERTY(bool supportsWPS READ supportsWPS CONSTANT)
-
-public:
- QWifiNetwork();
-
- QByteArray bssid() const { return m_bssid; }
- void setBssid(const QByteArray &id) { m_bssid = id; }
-
- QByteArray ssid() const { return m_ssid; }
- void setSsid(const QByteArray &id) { m_ssid = id; }
-
- int signalStrength() const { return m_signalStrength; }
- void setSignalStrength(int strength);
-
- void setOutOfRange(bool outOfRange);
- bool outOfRange() { return m_outOfRange; }
-
- QByteArray flags() const { return m_flags; }
- void setFlags(const QByteArray &f) { m_flags = f; }
- bool supportsWPA2() const { return m_flags.contains("WPA2"); }
- bool supportsWPA() const { return m_flags.contains("WPA"); }
- bool supportsWEP() const { return m_flags.contains("WEP"); }
- bool supportsWPS() const { return m_flags.contains("WPS"); }
-
-signals:
- void signalStrengthChanged(int strength);
-
-private:
- QByteArray m_bssid;
- QByteArray m_ssid;
- int m_signalStrength;
-
- QByteArray m_flags;
- bool m_outOfRange;
-};
-
-#endif // QWIFINETWORK_H
diff --git a/src/imports/wifi/qwifinetworklistmodel.cpp b/src/imports/wifi/qwifinetworklistmodel.cpp
deleted file mode 100644
index 1886413..0000000
--- a/src/imports/wifi/qwifinetworklistmodel.cpp
+++ /dev/null
@@ -1,142 +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.h"
-
-#include <QtCore>
-
-const int ID_NETWORK = (Qt::ItemDataRole) (Qt::UserRole + 1);
-
-QWifiNetworkListModel::QWifiNetworkListModel(QWifiManager *manager)
- : m_manager(manager)
-{
-}
-
-QWifiNetworkListModel::~QWifiNetworkListModel()
-{
- qDeleteAll(m_networks);
- qDeleteAll(m_outOfRangeNetworks);
- m_networks.clear();
- m_outOfRangeNetworks.clear();
-}
-
-QHash<int, QByteArray> QWifiNetworkListModel::roleNames() const
-{
- QHash<int, QByteArray> names;
- names.insert(ID_NETWORK, "network");
- return names;
-}
-
-QVariant QWifiNetworkListModel::data(const QModelIndex &index, int role) const
-{
- QWifiNetwork *n = m_networks.at(index.row());
- switch (role) {
- case ID_NETWORK: return QVariant::fromValue((QObject *) n);
- }
-
- qWarning("QWifiNetworkListModel::data(), undefined role: %d\n", role);
-
- return QVariant();
-}
-
-QWifiNetwork *QWifiNetworkListModel::networkForSSID(const QByteArray &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 QByteArray &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 QByteArray &results)
-{
- QList<QByteArray> lines = results.split('\n');
- QSet<QByteArray> sensibleNetworks;
-
- for (int i = 1; i < lines.size(); ++i) {
- QList<QByteArray> info = lines.at(i).split('\t');
- if (info.size() < 5 || info.at(4).isEmpty() || info.at(0).isEmpty())
- continue;
- int pos = 0;
- sensibleNetworks.insert(info.at(4));
- QWifiNetwork *knownNetwork = networkForSSID(info.at(4), &pos);
- if (!knownNetwork)
- knownNetwork = outOfRangeListContains(info.at(4));
- // signal strength is in dBm. Deprecated, but still widely used "wext"
- // wifi driver reports positive values for signal strength, we workaround that.
- int signalStrength = qAbs(info.at(2).trimmed().toInt()) * -1;
- if (!knownNetwork) {
- QWifiNetwork *network = new QWifiNetwork();
- network->setOutOfRange(false);
- network->setBssid(info.at(0));
- network->setFlags(info.at(3));
- network->setSignalStrength(signalStrength);
- network->setSsid(info.at(4));
- beginInsertRows(QModelIndex(), m_networks.size(), m_networks.size());
- m_networks << network;
- endInsertRows();
- } else {
- if (knownNetwork->outOfRange()) {
- // 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(info.at(4));
- 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;
- }
- }
-}
diff --git a/src/imports/wifi/qwifinetworklistmodel.h b/src/imports/wifi/qwifinetworklistmodel.h
deleted file mode 100644
index 0cb9846..0000000
--- a/src/imports/wifi/qwifinetworklistmodel.h
+++ /dev/null
@@ -1,54 +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 <QtCore/QAbstractListModel>
-#include <QtCore/QList>
-
-#include "qwifinetwork.h"
-
-class QWifiManager;
-
-class QWifiNetworkListModel : public QAbstractListModel
-{
- Q_OBJECT
-
-public:
-
- QWifiNetworkListModel(QWifiManager *manager);
- ~QWifiNetworkListModel();
-
- void parseScanResults(const QByteArray &data);
-
- QWifiNetwork *networkForSSID(const QByteArray &ssid, int *pos);
- QWifiNetwork *outOfRangeListContains(const QByteArray &ssid);
-
- int rowCount(const QModelIndex &) const { return m_networks.size(); }
- QVariant data(const QModelIndex &index, int role) const;
-
- QHash<int,QByteArray> roleNames() const;
-
-private:
- QWifiManager *m_manager;
- QList<QWifiNetwork *> m_networks;
- QList<QWifiNetwork *> m_outOfRangeNetworks;
-};
-
-#endif // QWIFINETWORKLISTMODEL_H
diff --git a/src/imports/wifi/wifi.pro b/src/imports/wifi/wifi.pro
index dabf8cb..b130587 100644
--- a/src/imports/wifi/wifi.pro
+++ b/src/imports/wifi/wifi.pro
@@ -1,34 +1,12 @@
CXX_MODULE = qml
-QT += qml quick network
-TARGET = qwifimodule
-TARGETPATH = Qt/labs/wifi
-IMPORT_VERSION = 0.1
+TARGET = b2qtwifiplugin
+TARGETPATH = B2Qt/Wifi
+IMPORT_VERSION = 1.0
-HEADERS += \
- qwifimanager.h \
- qwifinetwork.h \
- qwifinetworklistmodel.h \
- qwifiinterface.h
+QT += qml b2qtwifi
-SOURCES += \
- pluginmain.cpp \
- qwifimanager.cpp \
- qwifinetwork.cpp \
- qwifinetworklistmodel.cpp \
- qwifiinterface.cpp
+SOURCES += pluginmain.cpp
-android: {
- LIBS += -lhardware_legacy -lcutils
- DEFINES += FORCE_MOC
-} else {
- DEFINES += CONFIG_CTRL_IFACE \
- CONFIG_CTRL_IFACE_UNIX
-
- HEADERS += qwifi_elinux.h
- SOURCES += \
- qwifi_elinux.cpp \
- $$[QT_SYSROOT]/usr/include/wpa-supplicant/wpa_ctrl.c \
- $$[QT_SYSROOT]/usr/include/wpa-supplicant/os_unix.c
-}
+OTHER_FILES += qmldir
load(qml_plugin)