aboutsummaryrefslogtreecommitdiffstats
path: root/wpa_supplicant/wpa_gui-qt4
diff options
context:
space:
mode:
Diffstat (limited to 'wpa_supplicant/wpa_gui-qt4')
-rw-r--r--wpa_supplicant/wpa_gui-qt4/.gitignore5
-rw-r--r--wpa_supplicant/wpa_gui-qt4/eventhistory.cpp130
-rw-r--r--wpa_supplicant/wpa_gui-qt4/eventhistory.h63
-rw-r--r--wpa_supplicant/wpa_gui-qt4/eventhistory.ui61
-rw-r--r--wpa_supplicant/wpa_gui-qt4/main.cpp44
-rw-r--r--wpa_supplicant/wpa_gui-qt4/networkconfig.cpp639
-rw-r--r--wpa_supplicant/wpa_gui-qt4/networkconfig.h58
-rw-r--r--wpa_supplicant/wpa_gui-qt4/networkconfig.ui400
-rw-r--r--wpa_supplicant/wpa_gui-qt4/scanresults.cpp142
-rw-r--r--wpa_supplicant/wpa_gui-qt4/scanresults.h46
-rw-r--r--wpa_supplicant/wpa_gui-qt4/scanresults.ui94
-rwxr-xr-xwpa_supplicant/wpa_gui-qt4/setup-mingw-cross-compiling11
-rw-r--r--wpa_supplicant/wpa_gui-qt4/userdatarequest.cpp100
-rw-r--r--wpa_supplicant/wpa_gui-qt4/userdatarequest.h46
-rw-r--r--wpa_supplicant/wpa_gui-qt4/userdatarequest.ui109
-rw-r--r--wpa_supplicant/wpa_gui-qt4/wpa_gui.pro50
-rw-r--r--wpa_supplicant/wpa_gui-qt4/wpagui.cpp1094
-rw-r--r--wpa_supplicant/wpa_gui-qt4/wpagui.h92
-rw-r--r--wpa_supplicant/wpa_gui-qt4/wpagui.ui419
-rw-r--r--wpa_supplicant/wpa_gui-qt4/wpamsg.h41
20 files changed, 3644 insertions, 0 deletions
diff --git a/wpa_supplicant/wpa_gui-qt4/.gitignore b/wpa_supplicant/wpa_gui-qt4/.gitignore
new file mode 100644
index 0000000..11963c8
--- /dev/null
+++ b/wpa_supplicant/wpa_gui-qt4/.gitignore
@@ -0,0 +1,5 @@
+.moc
+.obj
+.ui
+Makefile
+wpa_gui
diff --git a/wpa_supplicant/wpa_gui-qt4/eventhistory.cpp b/wpa_supplicant/wpa_gui-qt4/eventhistory.cpp
new file mode 100644
index 0000000..46deb96
--- /dev/null
+++ b/wpa_supplicant/wpa_gui-qt4/eventhistory.cpp
@@ -0,0 +1,130 @@
+/*
+ * wpa_gui - EventHistory class
+ * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include <QHeaderView>
+#include <QScrollBar>
+
+#include "eventhistory.h"
+
+
+int EventListModel::rowCount(const QModelIndex &) const
+{
+ return msgList.count();
+}
+
+
+int EventListModel::columnCount(const QModelIndex &) const
+{
+ return 2;
+}
+
+
+QVariant EventListModel::data(const QModelIndex &index, int role) const
+{
+ if (!index.isValid())
+ return QVariant();
+
+ if (role == Qt::DisplayRole)
+ if (index.column() == 0) {
+ if (index.row() >= timeList.size())
+ return QVariant();
+ return timeList.at(index.row());
+ } else {
+ if (index.row() >= msgList.size())
+ return QVariant();
+ return msgList.at(index.row());
+ }
+ else
+ return QVariant();
+}
+
+
+QVariant EventListModel::headerData(int section, Qt::Orientation orientation,
+ int role) const
+{
+ if (role != Qt::DisplayRole)
+ return QVariant();
+
+ if (orientation == Qt::Horizontal) {
+ switch (section) {
+ case 0:
+ return QString("Timestamp");
+ case 1:
+ return QString("Message");
+ default:
+ return QVariant();
+ }
+ } else
+ return QString("%1").arg(section);
+}
+
+
+void EventListModel::addEvent(QString time, QString msg)
+{
+ beginInsertRows(QModelIndex(), msgList.size(), msgList.size() + 1);
+ timeList << time;
+ msgList << msg;
+ endInsertRows();
+}
+
+
+EventHistory::EventHistory(QWidget *parent, const char *, bool, Qt::WFlags)
+ : QDialog(parent)
+{
+ setupUi(this);
+
+ connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
+
+ eventListView->setItemsExpandable(FALSE);
+ eventListView->setRootIsDecorated(FALSE);
+ elm = new EventListModel(parent);
+ eventListView->setModel(elm);
+}
+
+
+EventHistory::~EventHistory()
+{
+ destroy();
+ delete elm;
+}
+
+
+void EventHistory::languageChange()
+{
+ retranslateUi(this);
+}
+
+
+void EventHistory::addEvents(WpaMsgList msgs)
+{
+ WpaMsgList::iterator it;
+ for (it = msgs.begin(); it != msgs.end(); it++)
+ addEvent(*it);
+}
+
+
+void EventHistory::addEvent(WpaMsg msg)
+{
+ bool scroll = true;
+
+ if (eventListView->verticalScrollBar()->value() <
+ eventListView->verticalScrollBar()->maximum())
+ scroll = false;
+
+ elm->addEvent(msg.getTimestamp().toString("yyyy-MM-dd hh:mm:ss.zzz"),
+ msg.getMsg());
+
+ if (scroll)
+ eventListView->scrollToBottom();
+}
diff --git a/wpa_supplicant/wpa_gui-qt4/eventhistory.h b/wpa_supplicant/wpa_gui-qt4/eventhistory.h
new file mode 100644
index 0000000..40dff6d
--- /dev/null
+++ b/wpa_supplicant/wpa_gui-qt4/eventhistory.h
@@ -0,0 +1,63 @@
+/*
+ * wpa_gui - EventHistory class
+ * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef EVENTHISTORY_H
+#define EVENTHISTORY_H
+
+#include <QObject>
+#include "ui_eventhistory.h"
+
+
+class EventListModel : public QAbstractTableModel
+{
+ Q_OBJECT
+
+public:
+ EventListModel(QObject *parent = 0)
+ : QAbstractTableModel(parent) {}
+
+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const;
+ QVariant data(const QModelIndex &index, int role) const;
+ QVariant headerData(int section, Qt::Orientation orientation,
+ int role = Qt::DisplayRole) const;
+ void addEvent(QString time, QString msg);
+
+private:
+ QStringList timeList;
+ QStringList msgList;
+};
+
+
+class EventHistory : public QDialog, public Ui::EventHistory
+{
+ Q_OBJECT
+
+public:
+ EventHistory(QWidget *parent = 0, const char *name = 0,
+ bool modal = false, Qt::WFlags fl = 0);
+ ~EventHistory();
+
+public slots:
+ virtual void addEvents(WpaMsgList msgs);
+ virtual void addEvent(WpaMsg msg);
+
+protected slots:
+ virtual void languageChange();
+
+private:
+ EventListModel *elm;
+};
+
+#endif /* EVENTHISTORY_H */
diff --git a/wpa_supplicant/wpa_gui-qt4/eventhistory.ui b/wpa_supplicant/wpa_gui-qt4/eventhistory.ui
new file mode 100644
index 0000000..427d830
--- /dev/null
+++ b/wpa_supplicant/wpa_gui-qt4/eventhistory.ui
@@ -0,0 +1,61 @@
+<ui version="4.0" >
+ <class>EventHistory</class>
+ <widget class="QDialog" name="EventHistory" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>533</width>
+ <height>285</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Event history</string>
+ </property>
+ <layout class="QGridLayout" >
+ <item row="0" column="0" colspan="2" >
+ <widget class="QTreeView" name="eventListView" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="verticalScrollBarPolicy" >
+ <enum>Qt::ScrollBarAlwaysOn</enum>
+ </property>
+ <property name="selectionMode" >
+ <enum>QAbstractItemView::NoSelection</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="1" column="1" >
+ <widget class="QPushButton" name="closeButton" >
+ <property name="text" >
+ <string>Close</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <layoutdefault spacing="6" margin="11" />
+ <pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
+ <includes>
+ <include location="local" >wpamsg.h</include>
+ </includes>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/wpa_supplicant/wpa_gui-qt4/main.cpp b/wpa_supplicant/wpa_gui-qt4/main.cpp
new file mode 100644
index 0000000..eeeda39
--- /dev/null
+++ b/wpa_supplicant/wpa_gui-qt4/main.cpp
@@ -0,0 +1,44 @@
+/*
+ * wpa_gui - Application startup
+ * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifdef CONFIG_NATIVE_WINDOWS
+#include <winsock.h>
+#endif /* CONFIG_NATIVE_WINDOWS */
+#include <QApplication>
+#include "wpagui.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ WpaGui w;
+ int ret;
+
+#ifdef CONFIG_NATIVE_WINDOWS
+ WSADATA wsaData;
+ if (WSAStartup(MAKEWORD(2, 0), &wsaData)) {
+ printf("Could not find a usable WinSock.dll\n");
+ return -1;
+ }
+#endif /* CONFIG_NATIVE_WINDOWS */
+
+ w.show();
+ app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
+ ret = app.exec();
+
+#ifdef CONFIG_NATIVE_WINDOWS
+ WSACleanup();
+#endif /* CONFIG_NATIVE_WINDOWS */
+
+ return ret;
+}
diff --git a/wpa_supplicant/wpa_gui-qt4/networkconfig.cpp b/wpa_supplicant/wpa_gui-qt4/networkconfig.cpp
new file mode 100644
index 0000000..e4f1096
--- /dev/null
+++ b/wpa_supplicant/wpa_gui-qt4/networkconfig.cpp
@@ -0,0 +1,639 @@
+/*
+ * wpa_gui - NetworkConfig class
+ * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include <QMessageBox>
+
+#include "networkconfig.h"
+#include "wpagui.h"
+
+enum {
+ AUTH_NONE = 0,
+ AUTH_IEEE8021X = 1,
+ AUTH_WPA_PSK = 2,
+ AUTH_WPA_EAP = 3,
+ AUTH_WPA2_PSK = 4,
+ AUTH_WPA2_EAP = 5
+};
+
+#define WPA_GUI_KEY_DATA "[key is configured]"
+
+
+NetworkConfig::NetworkConfig(QWidget *parent, const char *, bool, Qt::WFlags)
+ : QDialog(parent)
+{
+ setupUi(this);
+
+ connect(authSelect, SIGNAL(activated(int)), this,
+ SLOT(authChanged(int)));
+ connect(cancelButton, SIGNAL(clicked()), this, SLOT(close()));
+ connect(addButton, SIGNAL(clicked()), this, SLOT(addNetwork()));
+ connect(encrSelect, SIGNAL(activated(const QString &)), this,
+ SLOT(encrChanged(const QString &)));
+ connect(removeButton, SIGNAL(clicked()), this, SLOT(removeNetwork()));
+
+ wpagui = NULL;
+ new_network = false;
+}
+
+
+NetworkConfig::~NetworkConfig()
+{
+}
+
+
+void NetworkConfig::languageChange()
+{
+ retranslateUi(this);
+}
+
+
+void NetworkConfig::paramsFromScanResults(QTreeWidgetItem *sel)
+{
+ new_network = true;
+
+ /* SSID BSSID frequency signal flags */
+ setWindowTitle(sel->text(0));
+ ssidEdit->setText(sel->text(0));
+
+ QString flags = sel->text(4);
+ int auth, encr = 0;
+ if (flags.indexOf("[WPA2-EAP") >= 0)
+ auth = AUTH_WPA2_EAP;
+ else if (flags.indexOf("[WPA-EAP") >= 0)
+ auth = AUTH_WPA_EAP;
+ else if (flags.indexOf("[WPA2-PSK") >= 0)
+ auth = AUTH_WPA2_PSK;
+ else if (flags.indexOf("[WPA-PSK") >= 0)
+ auth = AUTH_WPA_PSK;
+ else
+ auth = AUTH_NONE;
+
+ if (flags.indexOf("-CCMP") >= 0)
+ encr = 1;
+ else if (flags.indexOf("-TKIP") >= 0)
+ encr = 0;
+ else if (flags.indexOf("WEP") >= 0)
+ encr = 1;
+ else
+ encr = 0;
+
+ authSelect->setCurrentIndex(auth);
+ authChanged(auth);
+ encrSelect->setCurrentIndex(encr);
+
+ wepEnabled(auth == AUTH_NONE && encr == 1);
+
+ getEapCapa();
+}
+
+
+void NetworkConfig::authChanged(int sel)
+{
+ pskEdit->setEnabled(sel == AUTH_WPA_PSK || sel == AUTH_WPA2_PSK);
+ bool eap = sel == AUTH_IEEE8021X || sel == AUTH_WPA_EAP ||
+ sel == AUTH_WPA2_EAP;
+ eapSelect->setEnabled(eap);
+ identityEdit->setEnabled(eap);
+ passwordEdit->setEnabled(eap);
+ cacertEdit->setEnabled(eap);
+
+ while (encrSelect->count())
+ encrSelect->removeItem(0);
+
+ if (sel == AUTH_NONE || sel == AUTH_IEEE8021X) {
+ encrSelect->addItem("None");
+ encrSelect->addItem("WEP");
+ encrSelect->setCurrentIndex(sel == AUTH_NONE ? 0 : 1);
+ } else {
+ encrSelect->addItem("TKIP");
+ encrSelect->addItem("CCMP");
+ encrSelect->setCurrentIndex((sel == AUTH_WPA2_PSK ||
+ sel == AUTH_WPA2_EAP) ? 1 : 0);
+ }
+
+ wepEnabled(sel == AUTH_IEEE8021X);
+}
+
+
+void NetworkConfig::addNetwork()
+{
+ char reply[10], cmd[256];
+ size_t reply_len;
+ int id;
+ int psklen = pskEdit->text().length();
+ int auth = authSelect->currentIndex();
+
+ if (auth == AUTH_WPA_PSK || auth == AUTH_WPA2_PSK) {
+ if (psklen < 8 || psklen > 64) {
+ QMessageBox::warning(this, "WPA Pre-Shared Key Error",
+ "WPA-PSK requires a passphrase "
+ "of 8 to 63 characters\n"
+ "or 64 hex digit PSK");
+ pskEdit->setFocus();
+ return;
+ }
+ }
+
+ if (idstrEdit->isEnabled() && !idstrEdit->text().isEmpty()) {
+ QRegExp rx("^(\\w|-)+$");
+ if (rx.indexIn(idstrEdit->text()) < 0) {
+ QMessageBox::warning(this, "Network ID Error",
+ "Network ID String contains "
+ "non-word characters.\n"
+ "It must be a simple string, "
+ "without spaces, containing\n"
+ "only characters in this range: "
+ "[A-Za-z0-9_-]\n");
+ idstrEdit->setFocus();
+ return;
+ }
+ }
+
+ if (wpagui == NULL)
+ return;
+
+ memset(reply, 0, sizeof(reply));
+ reply_len = sizeof(reply) - 1;
+
+ if (new_network) {
+ wpagui->ctrlRequest("ADD_NETWORK", reply, &reply_len);
+ if (reply[0] == 'F') {
+ QMessageBox::warning(this, "wpa_gui", "Failed to add "
+ "network to wpa_supplicant\n"
+ "configuration.");
+ return;
+ }
+ id = atoi(reply);
+ } else
+ id = edit_network_id;
+
+ setNetworkParam(id, "ssid", ssidEdit->text().toAscii().constData(),
+ true);
+
+ const char *key_mgmt = NULL, *proto = NULL, *pairwise = NULL;
+ switch (auth) {
+ case AUTH_NONE:
+ key_mgmt = "NONE";
+ break;
+ case AUTH_IEEE8021X:
+ key_mgmt = "IEEE8021X";
+ break;
+ case AUTH_WPA_PSK:
+ key_mgmt = "WPA-PSK";
+ proto = "WPA";
+ break;
+ case AUTH_WPA_EAP:
+ key_mgmt = "WPA-EAP";
+ proto = "WPA";
+ break;
+ case AUTH_WPA2_PSK:
+ key_mgmt = "WPA-PSK";
+ proto = "WPA2";
+ break;
+ case AUTH_WPA2_EAP:
+ key_mgmt = "WPA-EAP";
+ proto = "WPA2";
+ break;
+ }
+
+ if (auth == AUTH_WPA_PSK || auth == AUTH_WPA_EAP ||
+ auth == AUTH_WPA2_PSK || auth == AUTH_WPA2_EAP) {
+ int encr = encrSelect->currentIndex();
+ if (encr == 0)
+ pairwise = "TKIP";
+ else
+ pairwise = "CCMP";
+ }
+
+ if (proto)
+ setNetworkParam(id, "proto", proto, false);
+ if (key_mgmt)
+ setNetworkParam(id, "key_mgmt", key_mgmt, false);
+ if (pairwise) {
+ setNetworkParam(id, "pairwise", pairwise, false);
+ setNetworkParam(id, "group", "TKIP CCMP WEP104 WEP40", false);
+ }
+ if (pskEdit->isEnabled() &&
+ strcmp(passwordEdit->text().toAscii().constData(),
+ WPA_GUI_KEY_DATA) != 0)
+ setNetworkParam(id, "psk",
+ pskEdit->text().toAscii().constData(),
+ psklen != 64);
+ if (eapSelect->isEnabled())
+ setNetworkParam(id, "eap",
+ eapSelect->currentText().toAscii().constData(),
+ false);
+ if (identityEdit->isEnabled())
+ setNetworkParam(id, "identity",
+ identityEdit->text().toAscii().constData(),
+ true);
+ if (passwordEdit->isEnabled() &&
+ strcmp(passwordEdit->text().toAscii().constData(),
+ WPA_GUI_KEY_DATA) != 0)
+ setNetworkParam(id, "password",
+ passwordEdit->text().toAscii().constData(),
+ true);
+ if (cacertEdit->isEnabled())
+ setNetworkParam(id, "ca_cert",
+ cacertEdit->text().toAscii().constData(),
+ true);
+ writeWepKey(id, wep0Edit, 0);
+ writeWepKey(id, wep1Edit, 1);
+ writeWepKey(id, wep2Edit, 2);
+ writeWepKey(id, wep3Edit, 3);
+
+ if (wep0Radio->isEnabled() && wep0Radio->isChecked())
+ setNetworkParam(id, "wep_tx_keyidx", "0", false);
+ else if (wep1Radio->isEnabled() && wep1Radio->isChecked())
+ setNetworkParam(id, "wep_tx_keyidx", "1", false);
+ else if (wep2Radio->isEnabled() && wep2Radio->isChecked())
+ setNetworkParam(id, "wep_tx_keyidx", "2", false);
+ else if (wep3Radio->isEnabled() && wep3Radio->isChecked())
+ setNetworkParam(id, "wep_tx_keyidx", "3", false);
+
+ if (idstrEdit->isEnabled())
+ setNetworkParam(id, "id_str",
+ idstrEdit->text().toAscii().constData(),
+ true);
+
+ if (prioritySpinBox->isEnabled()) {
+ QString prio;
+ prio = prio.setNum(prioritySpinBox->value());
+ setNetworkParam(id, "priority", prio.toAscii().constData(),
+ false);
+ }
+
+ snprintf(cmd, sizeof(cmd), "ENABLE_NETWORK %d", id);
+ reply_len = sizeof(reply);
+ wpagui->ctrlRequest(cmd, reply, &reply_len);
+ if (strncmp(reply, "OK", 2) != 0) {
+ QMessageBox::warning(this, "wpa_gui", "Failed to enable "
+ "network in wpa_supplicant\n"
+ "configuration.");
+ /* Network was added, so continue anyway */
+ }
+ wpagui->triggerUpdate();
+ wpagui->ctrlRequest("SAVE_CONFIG", reply, &reply_len);
+
+ close();
+}
+
+
+void NetworkConfig::setWpaGui(WpaGui *_wpagui)
+{
+ wpagui = _wpagui;
+}
+
+
+int NetworkConfig::setNetworkParam(int id, const char *field,
+ const char *value, bool quote)
+{
+ char reply[10], cmd[256];
+ size_t reply_len;
+ snprintf(cmd, sizeof(cmd), "SET_NETWORK %d %s %s%s%s",
+ id, field, quote ? "\"" : "", value, quote ? "\"" : "");
+ reply_len = sizeof(reply);
+ wpagui->ctrlRequest(cmd, reply, &reply_len);
+ return strncmp(reply, "OK", 2) == 0 ? 0 : -1;
+}
+
+
+void NetworkConfig::encrChanged(const QString &sel)
+{
+ wepEnabled(sel.indexOf("WEP") == 0);
+}
+
+
+void NetworkConfig::wepEnabled(bool enabled)
+{
+ wep0Edit->setEnabled(enabled);
+ wep1Edit->setEnabled(enabled);
+ wep2Edit->setEnabled(enabled);
+ wep3Edit->setEnabled(enabled);
+ wep0Radio->setEnabled(enabled);
+ wep1Radio->setEnabled(enabled);
+ wep2Radio->setEnabled(enabled);
+ wep3Radio->setEnabled(enabled);
+}
+
+
+void NetworkConfig::writeWepKey(int network_id, QLineEdit *edit, int id)
+{
+ char buf[10];
+ bool hex;
+ const char *txt, *pos;
+ size_t len;
+
+ if (!edit->isEnabled() || edit->text().isEmpty())
+ return;
+
+ /*
+ * Assume hex key if only hex characters are present and length matches
+ * with 40, 104, or 128-bit key
+ */
+ txt = edit->text().toAscii().constData();
+ if (strcmp(txt, WPA_GUI_KEY_DATA) == 0)
+ return;
+ len = strlen(txt);
+ if (len == 0)
+ return;
+ pos = txt;
+ hex = true;
+ while (*pos) {
+ if (!((*pos >= '0' && *pos <= '9') ||
+ (*pos >= 'a' && *pos <= 'f') ||
+ (*pos >= 'A' && *pos <= 'F'))) {
+ hex = false;
+ break;
+ }
+ pos++;
+ }
+ if (hex && len != 10 && len != 26 && len != 32)
+ hex = false;
+ snprintf(buf, sizeof(buf), "wep_key%d", id);
+ setNetworkParam(network_id, buf, txt, !hex);
+}
+
+
+static int key_value_isset(const char *reply, size_t reply_len)
+{
+ return reply_len > 0 && (reply_len < 4 || memcmp(reply, "FAIL", 4) != 0);
+}
+
+
+void NetworkConfig::paramsFromConfig(int network_id)
+{
+ int i, res;
+
+ edit_network_id = network_id;
+ getEapCapa();
+
+ char reply[1024], cmd[256], *pos;
+ size_t reply_len;
+
+ snprintf(cmd, sizeof(cmd), "GET_NETWORK %d ssid", network_id);
+ reply_len = sizeof(reply) - 1;
+ if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 &&
+ reply_len >= 2 && reply[0] == '"') {
+ reply[reply_len] = '\0';
+ pos = strchr(reply + 1, '"');
+ if (pos)
+ *pos = '\0';
+ ssidEdit->setText(reply + 1);
+ }
+
+ snprintf(cmd, sizeof(cmd), "GET_NETWORK %d proto", network_id);
+ reply_len = sizeof(reply) - 1;
+ int wpa = 0;
+ if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0) {
+ reply[reply_len] = '\0';
+ if (strstr(reply, "RSN") || strstr(reply, "WPA2"))
+ wpa = 2;
+ else if (strstr(reply, "WPA"))
+ wpa = 1;
+ }
+
+ int auth = AUTH_NONE, encr = 0;
+ snprintf(cmd, sizeof(cmd), "GET_NETWORK %d key_mgmt", network_id);
+ reply_len = sizeof(reply) - 1;
+ if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0) {
+ reply[reply_len] = '\0';
+ if (strstr(reply, "WPA-EAP"))
+ auth = wpa & 2 ? AUTH_WPA2_EAP : AUTH_WPA_EAP;
+ else if (strstr(reply, "WPA-PSK"))
+ auth = wpa & 2 ? AUTH_WPA2_PSK : AUTH_WPA_PSK;
+ else if (strstr(reply, "IEEE8021X")) {
+ auth = AUTH_IEEE8021X;
+ encr = 1;
+ }
+ }
+
+ snprintf(cmd, sizeof(cmd), "GET_NETWORK %d pairwise", network_id);
+ reply_len = sizeof(reply) - 1;
+ if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0) {
+ reply[reply_len] = '\0';
+ if (strstr(reply, "CCMP") && auth != AUTH_NONE)
+ encr = 1;
+ else if (strstr(reply, "TKIP"))
+ encr = 0;
+ else if (strstr(reply, "WEP"))
+ encr = 1;
+ else
+ encr = 0;
+ }
+
+ snprintf(cmd, sizeof(cmd), "GET_NETWORK %d psk", network_id);
+ reply_len = sizeof(reply) - 1;
+ res = wpagui->ctrlRequest(cmd, reply, &reply_len);
+ if (res >= 0 && reply_len >= 2 && reply[0] == '"') {
+ reply[reply_len] = '\0';
+ pos = strchr(reply + 1, '"');
+ if (pos)
+ *pos = '\0';
+ pskEdit->setText(reply + 1);
+ } else if (res >= 0 && key_value_isset(reply, reply_len)) {
+ pskEdit->setText(WPA_GUI_KEY_DATA);
+ }
+
+ snprintf(cmd, sizeof(cmd), "GET_NETWORK %d identity", network_id);
+ reply_len = sizeof(reply) - 1;
+ if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 &&
+ reply_len >= 2 && reply[0] == '"') {
+ reply[reply_len] = '\0';
+ pos = strchr(reply + 1, '"');
+ if (pos)
+ *pos = '\0';
+ identityEdit->setText(reply + 1);
+ }
+
+ snprintf(cmd, sizeof(cmd), "GET_NETWORK %d password", network_id);
+ reply_len = sizeof(reply) - 1;
+ res = wpagui->ctrlRequest(cmd, reply, &reply_len);
+ if (res >= 0 && reply_len >= 2 && reply[0] == '"') {
+ reply[reply_len] = '\0';
+ pos = strchr(reply + 1, '"');
+ if (pos)
+ *pos = '\0';
+ passwordEdit->setText(reply + 1);
+ } else if (res >= 0 && key_value_isset(reply, reply_len)) {
+ passwordEdit->setText(WPA_GUI_KEY_DATA);
+ }
+
+ snprintf(cmd, sizeof(cmd), "GET_NETWORK %d ca_cert", network_id);
+ reply_len = sizeof(reply) - 1;
+ if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 &&
+ reply_len >= 2 && reply[0] == '"') {
+ reply[reply_len] = '\0';
+ pos = strchr(reply + 1, '"');
+ if (pos)
+ *pos = '\0';
+ cacertEdit->setText(reply + 1);
+ }
+
+ snprintf(cmd, sizeof(cmd), "GET_NETWORK %d eap", network_id);
+ reply_len = sizeof(reply) - 1;
+ if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 &&
+ reply_len >= 1) {
+ reply[reply_len] = '\0';
+ for (i = 0; i < eapSelect->count(); i++) {
+ if (eapSelect->itemText(i).compare(reply) == 0) {
+ eapSelect->setCurrentIndex(i);
+ break;
+ }
+ }
+ }
+
+ for (i = 0; i < 4; i++) {
+ QLineEdit *wepEdit;
+ switch (i) {
+ default:
+ case 0:
+ wepEdit = wep0Edit;
+ break;
+ case 1:
+ wepEdit = wep1Edit;
+ break;
+ case 2:
+ wepEdit = wep2Edit;
+ break;
+ case 3:
+ wepEdit = wep3Edit;
+ break;
+ }
+ snprintf(cmd, sizeof(cmd), "GET_NETWORK %d wep_key%d",
+ network_id, i);
+ reply_len = sizeof(reply) - 1;
+ res = wpagui->ctrlRequest(cmd, reply, &reply_len);
+ if (res >= 0 && reply_len >= 2 && reply[0] == '"') {
+ reply[reply_len] = '\0';
+ pos = strchr(reply + 1, '"');
+ if (pos)
+ *pos = '\0';
+ if (auth == AUTH_NONE || auth == AUTH_IEEE8021X)
+ encr = 1;
+
+ wepEdit->setText(reply + 1);
+ } else if (res >= 0 && key_value_isset(reply, reply_len)) {
+ if (auth == AUTH_NONE || auth == AUTH_IEEE8021X)
+ encr = 1;
+ wepEdit->setText(WPA_GUI_KEY_DATA);
+ }
+ }
+
+ snprintf(cmd, sizeof(cmd), "GET_NETWORK %d wep_tx_keyidx", network_id);
+ reply_len = sizeof(reply) - 1;
+ if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 && reply_len >= 1)
+ {
+ reply[reply_len] = '\0';
+ switch (atoi(reply)) {
+ case 0:
+ wep0Radio->setChecked(true);
+ break;
+ case 1:
+ wep1Radio->setChecked(true);
+ break;
+ case 2:
+ wep2Radio->setChecked(true);
+ break;
+ case 3:
+ wep3Radio->setChecked(true);
+ break;
+ }
+ }
+
+ snprintf(cmd, sizeof(cmd), "GET_NETWORK %d id_str", network_id);
+ reply_len = sizeof(reply) - 1;
+ if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 &&
+ reply_len >= 2 && reply[0] == '"') {
+ reply[reply_len] = '\0';
+ pos = strchr(reply + 1, '"');
+ if (pos)
+ *pos = '\0';
+ idstrEdit->setText(reply + 1);
+ }
+
+ snprintf(cmd, sizeof(cmd), "GET_NETWORK %d priority", network_id);
+ reply_len = sizeof(reply) - 1;
+ if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 && reply_len >= 1)
+ {
+ reply[reply_len] = '\0';
+ prioritySpinBox->setValue(atoi(reply));
+ }
+
+ authSelect->setCurrentIndex(auth);
+ authChanged(auth);
+ encrSelect->setCurrentIndex(encr);
+ if (auth == AUTH_NONE || auth == AUTH_IEEE8021X)
+ wepEnabled(encr == 1);
+
+ removeButton->setEnabled(true);
+ addButton->setText("Save");
+}
+
+
+void NetworkConfig::removeNetwork()
+{
+ char reply[10], cmd[256];
+ size_t reply_len;
+
+ if (QMessageBox::information(this, "wpa_gui",
+ "This will permanently remove the "
+ "network\n"
+ "from the configuration. Do you really "
+ "want\n"
+ "to remove this network?", "Yes", "No")
+ != 0)
+ return;
+
+ snprintf(cmd, sizeof(cmd), "REMOVE_NETWORK %d", edit_network_id);
+ reply_len = sizeof(reply);
+ wpagui->ctrlRequest(cmd, reply, &reply_len);
+ if (strncmp(reply, "OK", 2) != 0) {
+ QMessageBox::warning(this, "wpa_gui",
+ "Failed to remove network from "
+ "wpa_supplicant\n"
+ "configuration.");
+ } else {
+ wpagui->triggerUpdate();
+ wpagui->ctrlRequest("SAVE_CONFIG", reply, &reply_len);
+ }
+
+ close();
+}
+
+
+void NetworkConfig::newNetwork()
+{
+ new_network = true;
+ getEapCapa();
+}
+
+
+void NetworkConfig::getEapCapa()
+{
+ char reply[256];
+ size_t reply_len;
+
+ if (wpagui == NULL)
+ return;
+
+ reply_len = sizeof(reply) - 1;
+ if (wpagui->ctrlRequest("GET_CAPABILITY eap", reply, &reply_len) < 0)
+ return;
+ reply[reply_len] = '\0';
+
+ QString res(reply);
+ QStringList types = res.split(QChar(' '));
+ eapSelect->insertItems(-1, types);
+}
diff --git a/wpa_supplicant/wpa_gui-qt4/networkconfig.h b/wpa_supplicant/wpa_gui-qt4/networkconfig.h
new file mode 100644
index 0000000..140f5d7
--- /dev/null
+++ b/wpa_supplicant/wpa_gui-qt4/networkconfig.h
@@ -0,0 +1,58 @@
+/*
+ * wpa_gui - NetworkConfig class
+ * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef NETWORKCONFIG_H
+#define NETWORKCONFIG_H
+
+#include <QObject>
+#include "ui_networkconfig.h"
+
+class WpaGui;
+
+class NetworkConfig : public QDialog, public Ui::NetworkConfig
+{
+ Q_OBJECT
+
+public:
+ NetworkConfig(QWidget *parent = 0, const char *name = 0,
+ bool modal = false, Qt::WFlags fl = 0);
+ ~NetworkConfig();
+
+ virtual void paramsFromScanResults(QTreeWidgetItem *sel);
+ virtual void setWpaGui(WpaGui *_wpagui);
+ virtual int setNetworkParam(int id, const char *field,
+ const char *value, bool quote);
+ virtual void paramsFromConfig(int network_id);
+ virtual void newNetwork();
+
+public slots:
+ virtual void authChanged(int sel);
+ virtual void addNetwork();
+ virtual void encrChanged(const QString &sel);
+ virtual void writeWepKey(int network_id, QLineEdit *edit, int id);
+ virtual void removeNetwork();
+
+protected slots:
+ virtual void languageChange();
+
+private:
+ WpaGui *wpagui;
+ int edit_network_id;
+ bool new_network;
+
+ virtual void wepEnabled(bool enabled);
+ virtual void getEapCapa();
+};
+
+#endif /* NETWORKCONFIG_H */
diff --git a/wpa_supplicant/wpa_gui-qt4/networkconfig.ui b/wpa_supplicant/wpa_gui-qt4/networkconfig.ui
new file mode 100644
index 0000000..426ebf4
--- /dev/null
+++ b/wpa_supplicant/wpa_gui-qt4/networkconfig.ui
@@ -0,0 +1,400 @@
+<ui version="4.0" >
+ <class>NetworkConfig</class>
+ <widget class="QDialog" name="NetworkConfig" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>410</width>
+ <height>510</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>NetworkConfig</string>
+ </property>
+ <layout class="QGridLayout" >
+ <item row="1" column="3" >
+ <widget class="QPushButton" name="cancelButton" >
+ <property name="text" >
+ <string>Cancel</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0" colspan="4" >
+ <widget class="QFrame" name="frame9" >
+ <property name="frameShape" >
+ <enum>QFrame::NoFrame</enum>
+ </property>
+ <property name="frameShadow" >
+ <enum>QFrame::Plain</enum>
+ </property>
+ <layout class="QGridLayout" >
+ <item row="0" column="0" >
+ <widget class="QLabel" name="ssidLabel" >
+ <property name="text" >
+ <string>SSID</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" >
+ <widget class="QLineEdit" name="ssidEdit" >
+ <property name="toolTip" >
+ <string>Network name (Service Set IDentifier)</string>
+ </property>
+ <property name="text" >
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" >
+ <widget class="QLabel" name="authLabel" >
+ <property name="text" >
+ <string>Authentication</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" >
+ <widget class="QComboBox" name="authSelect" >
+ <item>
+ <property name="text" >
+ <string>Plaintext or static WEP</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>IEEE 802.1X</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>WPA-Personal (PSK)</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>WPA-Enterprise (EAP)</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>WPA2-Personal (PSK)</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>WPA2-Enterprise (EAP)</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="2" column="0" >
+ <widget class="QLabel" name="encrLabel" >
+ <property name="text" >
+ <string>Encryption</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1" >
+ <widget class="QComboBox" name="encrSelect" >
+ <item>
+ <property name="text" >
+ <string>None</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>WEP</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>TKIP</string>
+ </property>
+ </item>
+ <item>
+ <property name="text" >
+ <string>CCMP</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="3" column="0" >
+ <widget class="QLabel" name="pskLabel" >
+ <property name="text" >
+ <string>PSK</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1" >
+ <widget class="QLineEdit" name="pskEdit" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ <property name="toolTip" >
+ <string>WPA/WPA2 pre-shared key or passphrase</string>
+ </property>
+ <property name="whatsThis" >
+ <string/>
+ </property>
+ <property name="echoMode" >
+ <enum>QLineEdit::Password</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="0" >
+ <widget class="QLabel" name="eapLabel" >
+ <property name="text" >
+ <string>EAP method</string>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="1" >
+ <widget class="QComboBox" name="eapSelect" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="0" >
+ <widget class="QLabel" name="identityLabel" >
+ <property name="text" >
+ <string>Identity</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="1" >
+ <widget class="QLineEdit" name="identityEdit" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ <property name="toolTip" >
+ <string>Username/Identity for EAP methods</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="0" >
+ <widget class="QLabel" name="passwordLabel" >
+ <property name="text" >
+ <string>Password</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="1" >
+ <widget class="QLineEdit" name="passwordEdit" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ <property name="toolTip" >
+ <string>Password for EAP methods</string>
+ </property>
+ <property name="echoMode" >
+ <enum>QLineEdit::Password</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="7" column="0" >
+ <widget class="QLabel" name="cacertLabel" >
+ <property name="text" >
+ <string>CA certificate</string>
+ </property>
+ </widget>
+ </item>
+ <item row="7" column="1" >
+ <widget class="QLineEdit" name="cacertEdit" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="8" column="0" colspan="2" >
+ <widget class="QGroupBox" name="wepBox" >
+ <property name="enabled" >
+ <bool>true</bool>
+ </property>
+ <property name="title" >
+ <string>WEP keys</string>
+ </property>
+ <layout class="QGridLayout" >
+ <item row="0" column="0" >
+ <widget class="QRadioButton" name="wep0Radio" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ <property name="text" >
+ <string>key 0</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" >
+ <widget class="QRadioButton" name="wep1Radio" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ <property name="text" >
+ <string>key 1</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0" >
+ <widget class="QRadioButton" name="wep3Radio" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ <property name="text" >
+ <string>key 3</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0" >
+ <widget class="QRadioButton" name="wep2Radio" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ <property name="text" >
+ <string>key 2</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" >
+ <widget class="QLineEdit" name="wep0Edit" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" >
+ <widget class="QLineEdit" name="wep1Edit" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1" >
+ <widget class="QLineEdit" name="wep2Edit" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1" >
+ <widget class="QLineEdit" name="wep3Edit" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="9" column="0" colspan="2" >
+ <widget class="QGroupBox" name="optionalSettingsBox" >
+ <property name="enabled" >
+ <bool>true</bool>
+ </property>
+ <property name="title" >
+ <string>Optional Settings</string>
+ </property>
+ <layout class="QGridLayout" >
+ <item row="0" column="1" >
+ <widget class="QLineEdit" name="idstrEdit" >
+ <property name="toolTip" >
+ <string>Network Identification String</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="3" >
+ <widget class="QSpinBox" name="prioritySpinBox" >
+ <property name="toolTip" >
+ <string>Network Priority</string>
+ </property>
+ <property name="maximum" >
+ <number>10000</number>
+ </property>
+ <property name="singleStep" >
+ <number>10</number>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0" >
+ <widget class="QLabel" name="idstrLabel" >
+ <property name="text" >
+ <string>IDString</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2" >
+ <widget class="QLabel" name="priorityLabel" >
+ <property name="text" >
+ <string>Priority</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="1" column="1" >
+ <widget class="QPushButton" name="addButton" >
+ <property name="text" >
+ <string>Add</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="2" >
+ <widget class="QPushButton" name="removeButton" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ <property name="text" >
+ <string>Remove</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ <layoutdefault spacing="6" margin="11" />
+ <pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
+ <tabstops>
+ <tabstop>ssidEdit</tabstop>
+ <tabstop>authSelect</tabstop>
+ <tabstop>encrSelect</tabstop>
+ <tabstop>pskEdit</tabstop>
+ <tabstop>eapSelect</tabstop>
+ <tabstop>identityEdit</tabstop>
+ <tabstop>passwordEdit</tabstop>
+ <tabstop>cacertEdit</tabstop>
+ <tabstop>wep0Radio</tabstop>
+ <tabstop>wep0Edit</tabstop>
+ <tabstop>wep1Radio</tabstop>
+ <tabstop>wep1Edit</tabstop>
+ <tabstop>wep2Radio</tabstop>
+ <tabstop>wep2Edit</tabstop>
+ <tabstop>wep3Radio</tabstop>
+ <tabstop>wep3Edit</tabstop>
+ <tabstop>idstrEdit</tabstop>
+ <tabstop>prioritySpinBox</tabstop>
+ <tabstop>addButton</tabstop>
+ <tabstop>removeButton</tabstop>
+ <tabstop>cancelButton</tabstop>
+ </tabstops>
+ <includes>
+ <include location="global" >qtreewidget.h</include>
+ </includes>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/wpa_supplicant/wpa_gui-qt4/scanresults.cpp b/wpa_supplicant/wpa_gui-qt4/scanresults.cpp
new file mode 100644
index 0000000..bceef8a
--- /dev/null
+++ b/wpa_supplicant/wpa_gui-qt4/scanresults.cpp
@@ -0,0 +1,142 @@
+/*
+ * wpa_gui - ScanResults class
+ * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "scanresults.h"
+#include "wpagui.h"
+#include "networkconfig.h"
+
+
+ScanResults::ScanResults(QWidget *parent, const char *, bool, Qt::WFlags)
+ : QDialog(parent)
+{
+ setupUi(this);
+
+ connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
+ connect(scanButton, SIGNAL(clicked()), this, SLOT(scanRequest()));
+ connect(scanResultsWidget,
+ SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), this,
+ SLOT(bssSelected(QTreeWidgetItem *)));
+
+ wpagui = NULL;
+ scanResultsWidget->setItemsExpandable(FALSE);
+ scanResultsWidget->setRootIsDecorated(FALSE);
+}
+
+
+ScanResults::~ScanResults()
+{
+}
+
+
+void ScanResults::languageChange()
+{
+ retranslateUi(this);
+}
+
+
+void ScanResults::setWpaGui(WpaGui *_wpagui)
+{
+ wpagui = _wpagui;
+ updateResults();
+}
+
+
+void ScanResults::updateResults()
+{
+ char reply[2048];
+ size_t reply_len;
+ int index;
+ char cmd[20];
+
+ scanResultsWidget->clear();
+
+ index = 0;
+ while (wpagui) {
+ snprintf(cmd, sizeof(cmd), "BSS %d", index++);
+ if (index > 1000)
+ break;
+
+ reply_len = sizeof(reply) - 1;
+ if (wpagui->ctrlRequest(cmd, reply, &reply_len) < 0)
+ break;
+ reply[reply_len] = '\0';
+
+ QString bss(reply);
+ if (bss.isEmpty() || bss.startsWith("FAIL"))
+ break;
+
+ QString ssid, bssid, freq, signal, flags;
+
+ QStringList lines = bss.split(QRegExp("\\n"));
+ for (QStringList::Iterator it = lines.begin();
+ it != lines.end(); it++) {
+ int pos = (*it).indexOf('=') + 1;
+ if (pos < 1)
+ continue;
+
+ if ((*it).startsWith("bssid="))
+ bssid = (*it).mid(pos);
+ else if ((*it).startsWith("freq="))
+ freq = (*it).mid(pos);
+ else if ((*it).startsWith("qual="))
+ signal = (*it).mid(pos);
+ else if ((*it).startsWith("flags="))
+ flags = (*it).mid(pos);
+ else if ((*it).startsWith("ssid="))
+ ssid = (*it).mid(pos);
+ }
+
+ QTreeWidgetItem *item = new QTreeWidgetItem(scanResultsWidget);
+ if (item) {
+ item->setText(0, ssid);
+ item->setText(1, bssid);
+ item->setText(2, freq);
+ item->setText(3, signal);
+ item->setText(4, flags);
+ }
+
+ if (bssid.isEmpty())
+ break;
+ }
+}
+
+
+void ScanResults::scanRequest()
+{
+ char reply[10];
+ size_t reply_len = sizeof(reply);
+
+ if (wpagui == NULL)
+ return;
+
+ wpagui->ctrlRequest("SCAN", reply, &reply_len);
+}
+
+
+void ScanResults::getResults()
+{
+ updateResults();
+}
+
+
+void ScanResults::bssSelected(QTreeWidgetItem *sel)
+{
+ NetworkConfig *nc = new NetworkConfig();
+ if (nc == NULL)
+ return;
+ nc->setWpaGui(wpagui);
+ nc->paramsFromScanResults(sel);
+ nc->show();
+ nc->exec();
+}
diff --git a/wpa_supplicant/wpa_gui-qt4/scanresults.h b/wpa_supplicant/wpa_gui-qt4/scanresults.h
new file mode 100644
index 0000000..2c4a1b0
--- /dev/null
+++ b/wpa_supplicant/wpa_gui-qt4/scanresults.h
@@ -0,0 +1,46 @@
+/*
+ * wpa_gui - ScanResults class
+ * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef SCANRESULTS_H
+#define SCANRESULTS_H
+
+#include <QObject>
+#include "ui_scanresults.h"
+
+class WpaGui;
+
+class ScanResults : public QDialog, public Ui::ScanResults
+{
+ Q_OBJECT
+
+public:
+ ScanResults(QWidget *parent = 0, const char *name = 0,
+ bool modal = false, Qt::WFlags fl = 0);
+ ~ScanResults();
+
+public slots:
+ virtual void setWpaGui(WpaGui *_wpagui);
+ virtual void updateResults();
+ virtual void scanRequest();
+ virtual void getResults();
+ virtual void bssSelected(QTreeWidgetItem *sel);
+
+protected slots:
+ virtual void languageChange();
+
+private:
+ WpaGui *wpagui;
+};
+
+#endif /* SCANRESULTS_H */
diff --git a/wpa_supplicant/wpa_gui-qt4/scanresults.ui b/wpa_supplicant/wpa_gui-qt4/scanresults.ui
new file mode 100644
index 0000000..24ff280
--- /dev/null
+++ b/wpa_supplicant/wpa_gui-qt4/scanresults.ui
@@ -0,0 +1,94 @@
+<ui version="4.0" >
+ <class>ScanResults</class>
+ <widget class="QDialog" name="ScanResults" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>452</width>
+ <height>244</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Scan results</string>
+ </property>
+ <layout class="QVBoxLayout" >
+ <item>
+ <widget class="QTreeWidget" name="scanResultsWidget" >
+ <property name="editTriggers" >
+ <set>QAbstractItemView::NoEditTriggers</set>
+ </property>
+ <property name="uniformRowHeights" >
+ <bool>true</bool>
+ </property>
+ <property name="sortingEnabled" >
+ <bool>true</bool>
+ </property>
+ <property name="columnCount" >
+ <number>5</number>
+ </property>
+ <column>
+ <property name="text" >
+ <string>SSID</string>
+ </property>
+ </column>
+ <column>
+ <property name="text" >
+ <string>BSSID</string>
+ </property>
+ </column>
+ <column>
+ <property name="text" >
+ <string>frequency</string>
+ </property>
+ </column>
+ <column>
+ <property name="text" >
+ <string>signal</string>
+ </property>
+ </column>
+ <column>
+ <property name="text" >
+ <string>flags</string>
+ </property>
+ </column>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" >
+ <item>
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="scanButton" >
+ <property name="text" >
+ <string>Scan</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="closeButton" >
+ <property name="text" >
+ <string>Close</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <layoutdefault spacing="6" margin="11" />
+ <pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/wpa_supplicant/wpa_gui-qt4/setup-mingw-cross-compiling b/wpa_supplicant/wpa_gui-qt4/setup-mingw-cross-compiling
new file mode 100755
index 0000000..07e4a8f
--- /dev/null
+++ b/wpa_supplicant/wpa_gui-qt4/setup-mingw-cross-compiling
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+# qmake seems to be forcing include and lib paths from the original build
+# and I have no idea how to change these. For now, just override the
+# directories in the Makefile.Release file after qmake run.
+
+qmake -spec /q/jm/qt4-win/4.3.3/mkspecs/win32-g++ wpa_gui.pro -o Makefile
+cat Makefile.Release |
+ sed s%/usr/lib/qt4%/q/jm/qt4-win/4.3.3/lib%g |
+ sed s%/usr/include/qt4%/q/jm/qt4-win/4.3.3/include%g > tmp.Makefile.Release &&
+mv -f tmp.Makefile.Release Makefile.Release
diff --git a/wpa_supplicant/wpa_gui-qt4/userdatarequest.cpp b/wpa_supplicant/wpa_gui-qt4/userdatarequest.cpp
new file mode 100644
index 0000000..42fbdbc
--- /dev/null
+++ b/wpa_supplicant/wpa_gui-qt4/userdatarequest.cpp
@@ -0,0 +1,100 @@
+/*
+ * wpa_gui - UserDataRequest class
+ * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "userdatarequest.h"
+#include "wpagui.h"
+#include "wpa_ctrl.h"
+
+
+UserDataRequest::UserDataRequest(QWidget *parent, const char *, bool,
+ Qt::WFlags)
+ : QDialog(parent)
+{
+ setupUi(this);
+
+ connect(buttonOk, SIGNAL(clicked()), this, SLOT(sendReply()));
+ connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
+ connect(queryEdit, SIGNAL(returnPressed()), this, SLOT(sendReply()));
+}
+
+
+UserDataRequest::~UserDataRequest()
+{
+}
+
+
+void UserDataRequest::languageChange()
+{
+ retranslateUi(this);
+}
+
+
+int UserDataRequest::setParams(WpaGui *_wpagui, const char *reqMsg)
+{
+ char *tmp, *pos, *pos2;
+ wpagui = _wpagui;
+ tmp = strdup(reqMsg);
+ if (tmp == NULL)
+ return -1;
+ pos = strchr(tmp, '-');
+ if (pos == NULL) {
+ free(tmp);
+ return -1;
+ }
+ *pos++ = '\0';
+ field = tmp;
+ pos2 = strchr(pos, ':');
+ if (pos2 == NULL) {
+ free(tmp);
+ return -1;
+ }
+ *pos2++ = '\0';
+
+ networkid = atoi(pos);
+ queryInfo->setText(pos2);
+ if (strcmp(tmp, "PASSWORD") == 0) {
+ queryField->setText("Password: ");
+ queryEdit->setEchoMode(QLineEdit::Password);
+ } else if (strcmp(tmp, "NEW_PASSWORD") == 0) {
+ queryField->setText("New password: ");
+ queryEdit->setEchoMode(QLineEdit::Password);
+ } else if (strcmp(tmp, "IDENTITY") == 0)
+ queryField->setText("Identity: ");
+ else if (strcmp(tmp, "PASSPHRASE") == 0) {
+ queryField->setText("Private key passphrase: ");
+ queryEdit->setEchoMode(QLineEdit::Password);
+ } else
+ queryField->setText(field + ":");
+ free(tmp);
+
+ return 0;
+}
+
+
+void UserDataRequest::sendReply()
+{
+ char reply[10];
+ size_t reply_len = sizeof(reply);
+
+ if (wpagui == NULL) {
+ reject();
+ return;
+ }
+
+ QString cmd = QString(WPA_CTRL_RSP) + field + '-' +
+ QString::number(networkid) + ':' +
+ queryEdit->text();
+ wpagui->ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
+ accept();
+}
diff --git a/wpa_supplicant/wpa_gui-qt4/userdatarequest.h b/wpa_supplicant/wpa_gui-qt4/userdatarequest.h
new file mode 100644
index 0000000..2b6e837
--- /dev/null
+++ b/wpa_supplicant/wpa_gui-qt4/userdatarequest.h
@@ -0,0 +1,46 @@
+/*
+ * wpa_gui - UserDataRequest class
+ * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef USERDATAREQUEST_H
+#define USERDATAREQUEST_H
+
+#include <QObject>
+#include "ui_userdatarequest.h"
+
+class WpaGui;
+
+class UserDataRequest : public QDialog, public Ui::UserDataRequest
+{
+ Q_OBJECT
+
+public:
+ UserDataRequest(QWidget *parent = 0, const char *name = 0,
+ bool modal = false, Qt::WFlags fl = 0);
+ ~UserDataRequest();
+
+ int setParams(WpaGui *_wpagui, const char *reqMsg);
+
+public slots:
+ virtual void sendReply();
+
+protected slots:
+ virtual void languageChange();
+
+private:
+ WpaGui *wpagui;
+ int networkid;
+ QString field;
+};
+
+#endif /* USERDATAREQUEST_H */
diff --git a/wpa_supplicant/wpa_gui-qt4/userdatarequest.ui b/wpa_supplicant/wpa_gui-qt4/userdatarequest.ui
new file mode 100644
index 0000000..ea01721
--- /dev/null
+++ b/wpa_supplicant/wpa_gui-qt4/userdatarequest.ui
@@ -0,0 +1,109 @@
+<ui version="4.0" stdsetdef="1" >
+ <author></author>
+ <comment></comment>
+ <exportmacro></exportmacro>
+ <class>UserDataRequest</class>
+ <widget class="QDialog" name="UserDataRequest" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>216</width>
+ <height>103</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Authentication credentials required</string>
+ </property>
+ <property name="sizeGripEnabled" >
+ <bool>true</bool>
+ </property>
+ <layout class="QVBoxLayout" >
+ <item>
+ <widget class="QLabel" name="queryInfo" >
+ <property name="text" >
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QLabel" name="queryField" >
+ <property name="text" >
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="queryEdit" >
+ <property name="enabled" >
+ <bool>true</bool>
+ </property>
+ <property name="echoMode" >
+ <enum>QLineEdit::Password</enum>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <item>
+ <spacer name="spacer4" >
+ <property name="sizeHint" >
+ <size>
+ <width>20</width>
+ <height>20</height>
+ </size>
+ </property>
+ <property name="sizeType" >
+ <enum>Expanding</enum>
+ </property>
+ <property name="orientation" >
+ <enum>Horizontal</enum>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="buttonOk" >
+ <property name="text" >
+ <string>&amp;OK</string>
+ </property>
+ <property name="shortcut" >
+ <string/>
+ </property>
+ <property name="autoDefault" >
+ <bool>true</bool>
+ </property>
+ <property name="default" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="buttonCancel" >
+ <property name="text" >
+ <string>&amp;Cancel</string>
+ </property>
+ <property name="shortcut" >
+ <string/>
+ </property>
+ <property name="autoDefault" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <layoutdefault spacing="6" margin="11" />
+ <pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
+</ui>
diff --git a/wpa_supplicant/wpa_gui-qt4/wpa_gui.pro b/wpa_supplicant/wpa_gui-qt4/wpa_gui.pro
new file mode 100644
index 0000000..ac60701
--- /dev/null
+++ b/wpa_supplicant/wpa_gui-qt4/wpa_gui.pro
@@ -0,0 +1,50 @@
+TEMPLATE = app
+LANGUAGE = C++
+
+CONFIG += qt warn_on release
+
+DEFINES += CONFIG_CTRL_IFACE
+
+win32 {
+ LIBS += -lws2_32 -static
+ DEFINES += CONFIG_NATIVE_WINDOWS CONFIG_CTRL_IFACE_NAMED_PIPE
+ SOURCES += ../../src/utils/os_win32.c
+} else:win32-g++ {
+ # cross compilation to win32
+ LIBS += -lws2_32 -static
+ DEFINES += CONFIG_NATIVE_WINDOWS CONFIG_CTRL_IFACE_NAMED_PIPE
+ SOURCES += ../../src/utils/os_win32.c
+} else {
+ DEFINES += CONFIG_CTRL_IFACE_UNIX
+ SOURCES += ../../src/utils/os_unix.c
+}
+
+INCLUDEPATH += . .. ../../src/utils ../../src/common
+
+HEADERS += wpamsg.h \
+ wpagui.h \
+ eventhistory.h \
+ scanresults.h \
+ userdatarequest.h \
+ networkconfig.h
+
+SOURCES += main.cpp \
+ wpagui.cpp \
+ eventhistory.cpp \
+ scanresults.cpp \
+ userdatarequest.cpp \
+ networkconfig.cpp \
+ ../../src/common/wpa_ctrl.c
+
+FORMS = wpagui.ui \
+ eventhistory.ui \
+ scanresults.ui \
+ userdatarequest.ui \
+ networkconfig.ui
+
+
+unix {
+ UI_DIR = .ui
+ MOC_DIR = .moc
+ OBJECTS_DIR = .obj
+}
diff --git a/wpa_supplicant/wpa_gui-qt4/wpagui.cpp b/wpa_supplicant/wpa_gui-qt4/wpagui.cpp
new file mode 100644
index 0000000..ca3be73
--- /dev/null
+++ b/wpa_supplicant/wpa_gui-qt4/wpagui.cpp
@@ -0,0 +1,1094 @@
+/*
+ * wpa_gui - WpaGui class
+ * Copyright (c) 2005-2008, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifdef __MINGW32__
+/* Need to get getopt() */
+#include <unistd.h>
+#endif
+
+#include <QMessageBox>
+#include <QCloseEvent>
+
+#include "wpagui.h"
+#include "dirent.h"
+#include "wpa_ctrl.h"
+#include "userdatarequest.h"
+#include "networkconfig.h"
+
+WpaGui::WpaGui(QWidget *parent, const char *, Qt::WFlags)
+ : QMainWindow(parent)
+{
+ setupUi(this);
+
+ (void) statusBar();
+
+ connect(fileEventHistoryAction, SIGNAL(triggered()), this,
+ SLOT(eventHistory()));
+ connect(fileSaveConfigAction, SIGNAL(triggered()), this,
+ SLOT(saveConfig()));
+ connect(fileExitAction, SIGNAL(triggered()), this, SLOT(close()));
+ connect(networkAddAction, SIGNAL(triggered()), this,
+ SLOT(addNetwork()));
+ connect(networkEditAction, SIGNAL(triggered()), this,
+ SLOT(editSelectedNetwork()));
+ connect(networkRemoveAction, SIGNAL(triggered()), this,
+ SLOT(removeSelectedNetwork()));
+ connect(networkEnableAllAction, SIGNAL(triggered()), this,
+ SLOT(enableAllNetworks()));
+ connect(networkDisableAllAction, SIGNAL(triggered()), this,
+ SLOT(disableAllNetworks()));
+ connect(networkRemoveAllAction, SIGNAL(triggered()), this,
+ SLOT(removeAllNetworks()));
+ connect(helpIndexAction, SIGNAL(triggered()), this, SLOT(helpIndex()));
+ connect(helpContentsAction, SIGNAL(triggered()), this,
+ SLOT(helpContents()));
+ connect(helpAboutAction, SIGNAL(triggered()), this, SLOT(helpAbout()));
+ connect(disconnectButton, SIGNAL(clicked()), this, SLOT(disconnect()));
+ connect(scanButton, SIGNAL(clicked()), this, SLOT(scan()));
+ connect(connectButton, SIGNAL(clicked()), this, SLOT(connectB()));
+ connect(adapterSelect, SIGNAL(activated(const QString&)), this,
+ SLOT(selectAdapter(const QString&)));
+ connect(networkSelect, SIGNAL(activated(const QString&)), this,
+ SLOT(selectNetwork(const QString&)));
+ connect(addNetworkButton, SIGNAL(clicked()), this, SLOT(addNetwork()));
+ connect(editNetworkButton, SIGNAL(clicked()), this,
+ SLOT(editListedNetwork()));
+ connect(removeNetworkButton, SIGNAL(clicked()), this,
+ SLOT(removeListedNetwork()));
+ connect(networkList, SIGNAL(itemSelectionChanged()), this,
+ SLOT(updateNetworkDisabledStatus()));
+ connect(enableRadioButton, SIGNAL(toggled(bool)), this,
+ SLOT(enableListedNetwork(bool)));
+ connect(disableRadioButton, SIGNAL(toggled(bool)), this,
+ SLOT(disableListedNetwork(bool)));
+ connect(scanNetworkButton, SIGNAL(clicked()), this, SLOT(scan()));
+ connect(networkList, SIGNAL(itemDoubleClicked(QListWidgetItem *)),
+ this, SLOT(editListedNetwork()));
+
+ eh = NULL;
+ scanres = NULL;
+ udr = NULL;
+ ctrl_iface = NULL;
+ ctrl_conn = NULL;
+ monitor_conn = NULL;
+ msgNotifier = NULL;
+ ctrl_iface_dir = strdup("/var/run/wpa_supplicant");
+
+ parse_argv();
+
+ textStatus->setText("connecting to wpa_supplicant");
+ timer = new QTimer(this);
+ connect(timer, SIGNAL(timeout()), SLOT(ping()));
+ timer->setSingleShot(FALSE);
+ timer->start(1000);
+
+ if (openCtrlConnection(ctrl_iface) < 0) {
+ printf("Failed to open control connection to "
+ "wpa_supplicant.\n");
+ }
+
+ updateStatus();
+ networkMayHaveChanged = true;
+ updateNetworks();
+}
+
+
+WpaGui::~WpaGui()
+{
+ delete msgNotifier;
+
+ if (monitor_conn) {
+ wpa_ctrl_detach(monitor_conn);
+ wpa_ctrl_close(monitor_conn);
+ monitor_conn = NULL;
+ }
+ if (ctrl_conn) {
+ wpa_ctrl_close(ctrl_conn);
+ ctrl_conn = NULL;
+ }
+
+ if (eh) {
+ eh->close();
+ delete eh;
+ eh = NULL;
+ }
+
+ if (scanres) {
+ scanres->close();
+ delete scanres;
+ scanres = NULL;
+ }
+
+ if (udr) {
+ udr->close();
+ delete udr;
+ udr = NULL;
+ }
+
+ free(ctrl_iface);
+ ctrl_iface = NULL;
+
+ free(ctrl_iface_dir);
+ ctrl_iface_dir = NULL;
+}
+
+
+void WpaGui::languageChange()
+{
+ retranslateUi(this);
+}
+
+
+void WpaGui::parse_argv()
+{
+ int c;
+ for (;;) {
+ c = getopt(qApp->argc(), qApp->argv(), "i:p:");
+ if (c < 0)
+ break;
+ switch (c) {
+ case 'i':
+ free(ctrl_iface);
+ ctrl_iface = strdup(optarg);
+ break;
+ case 'p':
+ free(ctrl_iface_dir);
+ ctrl_iface_dir = strdup(optarg);
+ break;
+ }
+ }
+}
+
+
+int WpaGui::openCtrlConnection(const char *ifname)
+{
+ char *cfile;
+ int flen;
+ char buf[2048], *pos, *pos2;
+ size_t len;
+
+ if (ifname) {
+ if (ifname != ctrl_iface) {
+ free(ctrl_iface);
+ ctrl_iface = strdup(ifname);
+ }
+ } else {
+#ifdef CONFIG_CTRL_IFACE_UDP
+ free(ctrl_iface);
+ ctrl_iface = strdup("udp");
+#endif /* CONFIG_CTRL_IFACE_UDP */
+#ifdef CONFIG_CTRL_IFACE_UNIX
+ struct dirent *dent;
+ DIR *dir = opendir(ctrl_iface_dir);
+ free(ctrl_iface);
+ ctrl_iface = NULL;
+ if (dir) {
+ while ((dent = readdir(dir))) {
+#ifdef _DIRENT_HAVE_D_TYPE
+ /* Skip the file if it is not a socket.
+ * Also accept DT_UNKNOWN (0) in case
+ * the C library or underlying file
+ * system does not support d_type. */
+ if (dent->d_type != DT_SOCK &&
+ dent->d_type != DT_UNKNOWN)
+ continue;
+#endif /* _DIRENT_HAVE_D_TYPE */
+
+ if (strcmp(dent->d_name, ".") == 0 ||
+ strcmp(dent->d_name, "..") == 0)
+ continue;
+ printf("Selected interface '%s'\n",
+ dent->d_name);
+ ctrl_iface = strdup(dent->d_name);
+ break;
+ }
+ closedir(dir);
+ }
+#endif /* CONFIG_CTRL_IFACE_UNIX */
+#ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
+ struct wpa_ctrl *ctrl;
+ int ret;
+
+ free(ctrl_iface);
+ ctrl_iface = NULL;
+
+ ctrl = wpa_ctrl_open(NULL);
+ if (ctrl) {
+ len = sizeof(buf) - 1;
+ ret = wpa_ctrl_request(ctrl, "INTERFACES", 10, buf,
+ &len, NULL);
+ if (ret >= 0) {
+ buf[len] = '\0';
+ pos = strchr(buf, '\n');
+ if (pos)
+ *pos = '\0';
+ ctrl_iface = strdup(buf);
+ }
+ wpa_ctrl_close(ctrl);
+ }
+#endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
+ }
+
+ if (ctrl_iface == NULL)
+ return -1;
+
+#ifdef CONFIG_CTRL_IFACE_UNIX
+ flen = strlen(ctrl_iface_dir) + strlen(ctrl_iface) + 2;
+ cfile = (char *) malloc(flen);
+ if (cfile == NULL)
+ return -1;
+ snprintf(cfile, flen, "%s/%s", ctrl_iface_dir, ctrl_iface);
+#else /* CONFIG_CTRL_IFACE_UNIX */
+ flen = strlen(ctrl_iface) + 1;
+ cfile = (char *) malloc(flen);
+ if (cfile == NULL)
+ return -1;
+ snprintf(cfile, flen, "%s", ctrl_iface);
+#endif /* CONFIG_CTRL_IFACE_UNIX */
+
+ if (ctrl_conn) {
+ wpa_ctrl_close(ctrl_conn);
+ ctrl_conn = NULL;
+ }
+
+ if (monitor_conn) {
+ delete msgNotifier;
+ msgNotifier = NULL;
+ wpa_ctrl_detach(monitor_conn);
+ wpa_ctrl_close(monitor_conn);
+ monitor_conn = NULL;
+ }
+
+ printf("Trying to connect to '%s'\n", cfile);
+ ctrl_conn = wpa_ctrl_open(cfile);
+ if (ctrl_conn == NULL) {
+ free(cfile);
+ return -1;
+ }
+ monitor_conn = wpa_ctrl_open(cfile);
+ free(cfile);
+ if (monitor_conn == NULL) {
+ wpa_ctrl_close(ctrl_conn);
+ return -1;
+ }
+ if (wpa_ctrl_attach(monitor_conn)) {
+ printf("Failed to attach to wpa_supplicant\n");
+ wpa_ctrl_close(monitor_conn);
+ monitor_conn = NULL;
+ wpa_ctrl_close(ctrl_conn);
+ ctrl_conn = NULL;
+ return -1;
+ }
+
+#if defined(CONFIG_CTRL_IFACE_UNIX) || defined(CONFIG_CTRL_IFACE_UDP)
+ msgNotifier = new QSocketNotifier(wpa_ctrl_get_fd(monitor_conn),
+ QSocketNotifier::Read, this);
+ connect(msgNotifier, SIGNAL(activated(int)), SLOT(receiveMsgs()));
+#endif
+
+ adapterSelect->clear();
+ adapterSelect->addItem(ctrl_iface);
+ adapterSelect->setCurrentIndex(0);
+
+ len = sizeof(buf) - 1;
+ if (wpa_ctrl_request(ctrl_conn, "INTERFACES", 10, buf, &len, NULL) >=
+ 0) {
+ buf[len] = '\0';
+ pos = buf;
+ while (*pos) {
+ pos2 = strchr(pos, '\n');
+ if (pos2)
+ *pos2 = '\0';
+ if (strcmp(pos, ctrl_iface) != 0)
+ adapterSelect->addItem(pos);
+ if (pos2)
+ pos = pos2 + 1;
+ else
+ break;
+ }
+ }
+
+ return 0;
+}
+
+
+static void wpa_gui_msg_cb(char *msg, size_t)
+{
+ /* This should not happen anymore since two control connections are
+ * used. */
+ printf("missed message: %s\n", msg);
+}
+
+
+int WpaGui::ctrlRequest(const char *cmd, char *buf, size_t *buflen)
+{
+ int ret;
+
+ if (ctrl_conn == NULL)
+ return -3;
+ ret = wpa_ctrl_request(ctrl_conn, cmd, strlen(cmd), buf, buflen,
+ wpa_gui_msg_cb);
+ if (ret == -2)
+ printf("'%s' command timed out.\n", cmd);
+ else if (ret < 0)
+ printf("'%s' command failed.\n", cmd);
+
+ return ret;
+}
+
+
+void WpaGui::updateStatus()
+{
+ char buf[2048], *start, *end, *pos;
+ size_t len;
+
+ pingsToStatusUpdate = 10;
+
+ len = sizeof(buf) - 1;
+ if (ctrl_conn == NULL || ctrlRequest("STATUS", buf, &len) < 0) {
+ textStatus->setText("Could not get status from "
+ "wpa_supplicant");
+ textAuthentication->clear();
+ textEncryption->clear();
+ textSsid->clear();
+ textBssid->clear();
+ textIpAddress->clear();
+ return;
+ }
+
+ buf[len] = '\0';
+
+ bool auth_updated = false, ssid_updated = false;
+ bool bssid_updated = false, ipaddr_updated = false;
+ bool status_updated = false;
+ char *pairwise_cipher = NULL, *group_cipher = NULL;
+
+ start = buf;
+ while (*start) {
+ bool last = false;
+ end = strchr(start, '\n');
+ if (end == NULL) {
+ last = true;
+ end = start;
+ while (end[0] && end[1])
+ end++;
+ }
+ *end = '\0';
+
+ pos = strchr(start, '=');
+ if (pos) {
+ *pos++ = '\0';
+ if (strcmp(start, "bssid") == 0) {
+ bssid_updated = true;
+ textBssid->setText(pos);
+ } else if (strcmp(start, "ssid") == 0) {
+ ssid_updated = true;
+ textSsid->setText(pos);
+ } else if (strcmp(start, "ip_address") == 0) {
+ ipaddr_updated = true;
+ textIpAddress->setText(pos);
+ } else if (strcmp(start, "wpa_state") == 0) {
+ status_updated = true;
+ textStatus->setText(pos);
+ } else if (strcmp(start, "key_mgmt") == 0) {
+ auth_updated = true;
+ textAuthentication->setText(pos);
+ /* TODO: could add EAP status to this */
+ } else if (strcmp(start, "pairwise_cipher") == 0) {
+ pairwise_cipher = pos;
+ } else if (strcmp(start, "group_cipher") == 0) {
+ group_cipher = pos;
+ }
+ }
+
+ if (last)
+ break;
+ start = end + 1;
+ }
+
+ if (pairwise_cipher || group_cipher) {
+ QString encr;
+ if (pairwise_cipher && group_cipher &&
+ strcmp(pairwise_cipher, group_cipher) != 0) {
+ encr.append(pairwise_cipher);
+ encr.append(" + ");
+ encr.append(group_cipher);
+ } else if (pairwise_cipher) {
+ encr.append(pairwise_cipher);
+ } else {
+ encr.append(group_cipher);
+ encr.append(" [group key only]");
+ }
+ textEncryption->setText(encr);
+ } else
+ textEncryption->clear();
+
+ if (!status_updated)
+ textStatus->clear();
+ if (!auth_updated)
+ textAuthentication->clear();
+ if (!ssid_updated)
+ textSsid->clear();
+ if (!bssid_updated)
+ textBssid->clear();
+ if (!ipaddr_updated)
+ textIpAddress->clear();
+}
+
+
+void WpaGui::updateNetworks()
+{
+ char buf[2048], *start, *end, *id, *ssid, *bssid, *flags;
+ size_t len;
+ int first_active = -1;
+ int was_selected = -1;
+ bool current = false;
+
+ if (!networkMayHaveChanged)
+ return;
+
+ if (networkList->currentRow() >= 0)
+ was_selected = networkList->currentRow();
+
+ networkSelect->clear();
+ networkList->clear();
+
+ if (ctrl_conn == NULL)
+ return;
+
+ len = sizeof(buf) - 1;
+ if (ctrlRequest("LIST_NETWORKS", buf, &len) < 0)
+ return;
+
+ buf[len] = '\0';
+ start = strchr(buf, '\n');
+ if (start == NULL)
+ return;
+ start++;
+
+ while (*start) {
+ bool last = false;
+ end = strchr(start, '\n');
+ if (end == NULL) {
+ last = true;
+ end = start;
+ while (end[0] && end[1])
+ end++;
+ }
+ *end = '\0';
+
+ id = start;
+ ssid = strchr(id, '\t');
+ if (ssid == NULL)
+ break;
+ *ssid++ = '\0';
+ bssid = strchr(ssid, '\t');
+ if (bssid == NULL)
+ break;
+ *bssid++ = '\0';
+ flags = strchr(bssid, '\t');
+ if (flags == NULL)
+ break;
+ *flags++ = '\0';
+
+ QString network(id);
+ network.append(": ");
+ network.append(ssid);
+ networkSelect->addItem(network);
+ networkList->addItem(network);
+
+ if (strstr(flags, "[CURRENT]")) {
+ networkSelect->setCurrentIndex(networkSelect->count() -
+ 1);
+ current = true;
+ } else if (first_active < 0 &&
+ strstr(flags, "[DISABLED]") == NULL)
+ first_active = networkSelect->count() - 1;
+
+ if (last)
+ break;
+ start = end + 1;
+ }
+
+ if (networkSelect->count() > 1)
+ networkSelect->addItem("Select any network");
+
+ if (!current && first_active >= 0)
+ networkSelect->setCurrentIndex(first_active);
+
+ if (was_selected >= 0 && networkList->count() > 0) {
+ if (was_selected < networkList->count())
+ networkList->setCurrentRow(was_selected);
+ else
+ networkList->setCurrentRow(networkList->count() - 1);
+ }
+ else
+ networkList->setCurrentRow(networkSelect->currentIndex());
+
+ networkMayHaveChanged = false;
+}
+
+
+void WpaGui::helpIndex()
+{
+ printf("helpIndex\n");
+}
+
+
+void WpaGui::helpContents()
+{
+ printf("helpContents\n");
+}
+
+
+void WpaGui::helpAbout()
+{
+ QMessageBox::about(this, "wpa_gui for wpa_supplicant",
+ "Copyright (c) 2003-2008,\n"
+ "Jouni Malinen <j@w1.fi>\n"
+ "and contributors.\n"
+ "\n"
+ "This program is free software. You can\n"
+ "distribute it and/or modify it under the terms "
+ "of\n"
+ "the GNU General Public License version 2.\n"
+ "\n"
+ "Alternatively, this software may be distributed\n"
+ "under the terms of the BSD license.\n"
+ "\n"
+ "This product includes software developed\n"
+ "by the OpenSSL Project for use in the\n"
+ "OpenSSL Toolkit (http://www.openssl.org/)\n");
+}
+
+
+void WpaGui::disconnect()
+{
+ char reply[10];
+ size_t reply_len = sizeof(reply);
+ ctrlRequest("DISCONNECT", reply, &reply_len);
+}
+
+
+void WpaGui::scan()
+{
+ if (scanres) {
+ scanres->close();
+ delete scanres;
+ }
+
+ scanres = new ScanResults();
+ if (scanres == NULL)
+ return;
+ scanres->setWpaGui(this);
+ scanres->show();
+ scanres->exec();
+}
+
+
+void WpaGui::eventHistory()
+{
+ if (eh) {
+ eh->close();
+ delete eh;
+ }
+
+ eh = new EventHistory();
+ if (eh == NULL)
+ return;
+ eh->addEvents(msgs);
+ eh->show();
+ eh->exec();
+}
+
+
+void WpaGui::ping()
+{
+ char buf[10];
+ size_t len;
+
+#ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
+ /*
+ * QSocketNotifier cannot be used with Windows named pipes, so use a
+ * timer to check for received messages for now. This could be
+ * optimized be doing something specific to named pipes or Windows
+ * events, but it is not clear what would be the best way of doing that
+ * in Qt.
+ */
+ receiveMsgs();
+#endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
+
+ if (scanres && !scanres->isVisible()) {
+ delete scanres;
+ scanres = NULL;
+ }
+
+ if (eh && !eh->isVisible()) {
+ delete eh;
+ eh = NULL;
+ }
+
+ if (udr && !udr->isVisible()) {
+ delete udr;
+ udr = NULL;
+ }
+
+ len = sizeof(buf) - 1;
+ if (ctrlRequest("PING", buf, &len) < 0) {
+ printf("PING failed - trying to reconnect\n");
+ if (openCtrlConnection(ctrl_iface) >= 0) {
+ printf("Reconnected successfully\n");
+ pingsToStatusUpdate = 0;
+ }
+ }
+
+ pingsToStatusUpdate--;
+ if (pingsToStatusUpdate <= 0) {
+ updateStatus();
+ updateNetworks();
+ }
+}
+
+
+static int str_match(const char *a, const char *b)
+{
+ return strncmp(a, b, strlen(b)) == 0;
+}
+
+
+void WpaGui::processMsg(char *msg)
+{
+ char *pos = msg, *pos2;
+ int priority = 2;
+
+ if (*pos == '<') {
+ /* skip priority */
+ pos++;
+ priority = atoi(pos);
+ pos = strchr(pos, '>');
+ if (pos)
+ pos++;
+ else
+ pos = msg;
+ }
+
+ WpaMsg wm(pos, priority);
+ if (eh)
+ eh->addEvent(wm);
+ msgs.append(wm);
+ while (msgs.count() > 100)
+ msgs.pop_front();
+
+ /* Update last message with truncated version of the event */
+ if (strncmp(pos, "CTRL-", 5) == 0) {
+ pos2 = strchr(pos, str_match(pos, WPA_CTRL_REQ) ? ':' : ' ');
+ if (pos2)
+ pos2++;
+ else
+ pos2 = pos;
+ } else
+ pos2 = pos;
+ QString lastmsg = pos2;
+ lastmsg.truncate(40);
+ textLastMessage->setText(lastmsg);
+
+ pingsToStatusUpdate = 0;
+ networkMayHaveChanged = true;
+
+ if (str_match(pos, WPA_CTRL_REQ))
+ processCtrlReq(pos + strlen(WPA_CTRL_REQ));
+ else if (str_match(pos, WPA_EVENT_SCAN_RESULTS) && scanres)
+ scanres->updateResults();
+}
+
+
+void WpaGui::processCtrlReq(const char *req)
+{
+ if (udr) {
+ udr->close();
+ delete udr;
+ }
+ udr = new UserDataRequest();
+ if (udr == NULL)
+ return;
+ if (udr->setParams(this, req) < 0) {
+ delete udr;
+ udr = NULL;
+ return;
+ }
+ udr->show();
+ udr->exec();
+}
+
+
+void WpaGui::receiveMsgs()
+{
+ char buf[256];
+ size_t len;
+
+ while (monitor_conn && wpa_ctrl_pending(monitor_conn) > 0) {
+ len = sizeof(buf) - 1;
+ if (wpa_ctrl_recv(monitor_conn, buf, &len) == 0) {
+ buf[len] = '\0';
+ processMsg(buf);
+ }
+ }
+}
+
+
+void WpaGui::connectB()
+{
+ char reply[10];
+ size_t reply_len = sizeof(reply);
+ ctrlRequest("REASSOCIATE", reply, &reply_len);
+}
+
+
+void WpaGui::selectNetwork( const QString &sel )
+{
+ QString cmd(sel);
+ char reply[10];
+ size_t reply_len = sizeof(reply);
+
+ if (cmd.startsWith("Select any")) {
+ cmd = "any";
+ } else {
+ int pos = cmd.indexOf(':');
+ if (pos < 0) {
+ printf("Invalid selectNetwork '%s'\n",
+ cmd.toAscii().constData());
+ return;
+ }
+ cmd.truncate(pos);
+ }
+ cmd.prepend("SELECT_NETWORK ");
+ ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
+ triggerUpdate();
+}
+
+
+void WpaGui::enableNetwork(const QString &sel)
+{
+ QString cmd(sel);
+ char reply[10];
+ size_t reply_len = sizeof(reply);
+
+ if (!cmd.startsWith("all")) {
+ int pos = cmd.indexOf(':');
+ if (pos < 0) {
+ printf("Invalid enableNetwork '%s'\n",
+ cmd.toAscii().constData());
+ return;
+ }
+ cmd.truncate(pos);
+ }
+ cmd.prepend("ENABLE_NETWORK ");
+ ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
+ triggerUpdate();
+}
+
+
+void WpaGui::disableNetwork(const QString &sel)
+{
+ QString cmd(sel);
+ char reply[10];
+ size_t reply_len = sizeof(reply);
+
+ if (!cmd.startsWith("all")) {
+ int pos = cmd.indexOf(':');
+ if (pos < 0) {
+ printf("Invalid disableNetwork '%s'\n",
+ cmd.toAscii().constData());
+ return;
+ }
+ cmd.truncate(pos);
+ }
+ cmd.prepend("DISABLE_NETWORK ");
+ ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
+ triggerUpdate();
+}
+
+
+void WpaGui::editNetwork(const QString &sel)
+{
+ QString cmd(sel);
+ int id = -1;
+
+ if (!cmd.startsWith("Select any")) {
+ int pos = sel.indexOf(':');
+ if (pos < 0) {
+ printf("Invalid editNetwork '%s'\n",
+ cmd.toAscii().constData());
+ return;
+ }
+ cmd.truncate(pos);
+ id = cmd.toInt();
+ }
+
+ NetworkConfig *nc = new NetworkConfig();
+ if (nc == NULL)
+ return;
+ nc->setWpaGui(this);
+
+ if (id >= 0)
+ nc->paramsFromConfig(id);
+ else
+ nc->newNetwork();
+
+ nc->show();
+ nc->exec();
+}
+
+
+void WpaGui::editSelectedNetwork()
+{
+ if (networkSelect->count() < 1) {
+ QMessageBox::information(this, "No Networks",
+ "There are no networks to edit.\n");
+ return;
+ }
+ QString sel(networkSelect->currentText());
+ editNetwork(sel);
+}
+
+
+void WpaGui::editListedNetwork()
+{
+ if (networkList->currentRow() < 0) {
+ QMessageBox::information(this, "Select A Network",
+ "Select a network from the list to"
+ " edit it.\n");
+ return;
+ }
+ QString sel(networkList->currentItem()->text());
+ editNetwork(sel);
+}
+
+
+void WpaGui::triggerUpdate()
+{
+ updateStatus();
+ networkMayHaveChanged = true;
+ updateNetworks();
+}
+
+
+void WpaGui::addNetwork()
+{
+ NetworkConfig *nc = new NetworkConfig();
+ if (nc == NULL)
+ return;
+ nc->setWpaGui(this);
+ nc->newNetwork();
+ nc->show();
+ nc->exec();
+}
+
+
+void WpaGui::removeNetwork(const QString &sel)
+{
+ QString cmd(sel);
+ char reply[10];
+ size_t reply_len = sizeof(reply);
+
+ if (cmd.startsWith("Select any"))
+ return;
+
+ if (!cmd.startsWith("all")) {
+ int pos = cmd.indexOf(':');
+ if (pos < 0) {
+ printf("Invalid removeNetwork '%s'\n",
+ cmd.toAscii().constData());
+ return;
+ }
+ cmd.truncate(pos);
+ }
+ cmd.prepend("REMOVE_NETWORK ");
+ ctrlRequest(cmd.toAscii().constData(), reply, &reply_len);
+ triggerUpdate();
+}
+
+
+void WpaGui::removeSelectedNetwork()
+{
+ if (networkSelect->count() < 1) {
+ QMessageBox::information(this, "No Networks",
+ "There are no networks to remove.\n");
+ return;
+ }
+ QString sel(networkSelect->currentText());
+ removeNetwork(sel);
+}
+
+
+void WpaGui::removeListedNetwork()
+{
+ if (networkList->currentRow() < 0) {
+ QMessageBox::information(this, "Select A Network",
+ "Select a network from the list to"
+ " remove it.\n");
+ return;
+ }
+ QString sel(networkList->currentItem()->text());
+ removeNetwork(sel);
+}
+
+
+void WpaGui::enableAllNetworks()
+{
+ QString sel("all");
+ enableNetwork(sel);
+}
+
+
+void WpaGui::disableAllNetworks()
+{
+ QString sel("all");
+ disableNetwork(sel);
+}
+
+
+void WpaGui::removeAllNetworks()
+{
+ QString sel("all");
+ removeNetwork(sel);
+}
+
+
+int WpaGui::getNetworkDisabled(const QString &sel)
+{
+ QString cmd(sel);
+ char reply[10];
+ size_t reply_len = sizeof(reply) - 1;
+ int pos = cmd.indexOf(':');
+ if (pos < 0) {
+ printf("Invalid getNetworkDisabled '%s'\n",
+ cmd.toAscii().constData());
+ return -1;
+ }
+ cmd.truncate(pos);
+ cmd.prepend("GET_NETWORK ");
+ cmd.append(" disabled");
+
+ if (ctrlRequest(cmd.toAscii().constData(), reply, &reply_len) >= 0
+ && reply_len >= 1) {
+ reply[reply_len] = '\0';
+ if (!str_match(reply, "FAIL"))
+ return atoi(reply);
+ }
+
+ return -1;
+}
+
+
+void WpaGui::updateNetworkDisabledStatus()
+{
+ if (networkList->currentRow() < 0)
+ return;
+
+ QString sel(networkList->currentItem()->text());
+
+ switch (getNetworkDisabled(sel)) {
+ case 0:
+ if (!enableRadioButton->isChecked())
+ enableRadioButton->setChecked(true);
+ return;
+ case 1:
+ if (!disableRadioButton->isChecked())
+ disableRadioButton->setChecked(true);
+ return;
+ }
+}
+
+
+void WpaGui::enableListedNetwork(bool enabled)
+{
+ if (networkList->currentRow() < 0 || !enabled)
+ return;
+
+ QString sel(networkList->currentItem()->text());
+
+ if (getNetworkDisabled(sel) == 1)
+ enableNetwork(sel);
+}
+
+
+void WpaGui::disableListedNetwork(bool disabled)
+{
+ if (networkList->currentRow() < 0 || !disabled)
+ return;
+
+ QString sel(networkList->currentItem()->text());
+
+ if (getNetworkDisabled(sel) == 0)
+ disableNetwork(sel);
+}
+
+
+void WpaGui::saveConfig()
+{
+ char buf[10];
+ size_t len;
+
+ len = sizeof(buf) - 1;
+ ctrlRequest("SAVE_CONFIG", buf, &len);
+
+ buf[len] = '\0';
+
+ if (str_match(buf, "FAIL"))
+ QMessageBox::warning(this, "Failed to save configuration",
+ "The configuration could not be saved.\n"
+ "\n"
+ "The update_config=1 configuration option\n"
+ "must be used for configuration saving to\n"
+ "be permitted.\n");
+ else
+ QMessageBox::information(this, "Saved configuration",
+ "The current configuration was saved."
+ "\n");
+}
+
+
+void WpaGui::selectAdapter( const QString & sel )
+{
+ if (openCtrlConnection(sel.toAscii().constData()) < 0)
+ printf("Failed to open control connection to "
+ "wpa_supplicant.\n");
+ updateStatus();
+ updateNetworks();
+}
+
+
+void WpaGui::closeEvent(QCloseEvent *event)
+{
+ if (eh) {
+ eh->close();
+ delete eh;
+ eh = NULL;
+ }
+
+ if (scanres) {
+ scanres->close();
+ delete scanres;
+ scanres = NULL;
+ }
+
+ if (udr) {
+ udr->close();
+ delete udr;
+ udr = NULL;
+ }
+
+ event->accept();
+}
diff --git a/wpa_supplicant/wpa_gui-qt4/wpagui.h b/wpa_supplicant/wpa_gui-qt4/wpagui.h
new file mode 100644
index 0000000..338ba8b
--- /dev/null
+++ b/wpa_supplicant/wpa_gui-qt4/wpagui.h
@@ -0,0 +1,92 @@
+/*
+ * wpa_gui - WpaGui class
+ * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef WPAGUI_H
+#define WPAGUI_H
+
+#include <QObject>
+#include "ui_wpagui.h"
+
+class UserDataRequest;
+
+
+class WpaGui : public QMainWindow, public Ui::WpaGui
+{
+ Q_OBJECT
+
+public:
+ WpaGui(QWidget *parent = 0, const char *name = 0,
+ Qt::WFlags fl = 0);
+ ~WpaGui();
+
+ virtual int ctrlRequest(const char *cmd, char *buf, size_t *buflen);
+ virtual void triggerUpdate();
+ virtual void editNetwork(const QString &sel);
+ virtual void removeNetwork(const QString &sel);
+ virtual void enableNetwork(const QString &sel);
+ virtual void disableNetwork(const QString &sel);
+ virtual int getNetworkDisabled(const QString &sel);
+
+public slots:
+ virtual void parse_argv();
+ virtual void updateStatus();
+ virtual void updateNetworks();
+ virtual void helpIndex();
+ virtual void helpContents();
+ virtual void helpAbout();
+ virtual void disconnect();
+ virtual void scan();
+ virtual void eventHistory();
+ virtual void ping();
+ virtual void processMsg(char *msg);
+ virtual void processCtrlReq(const char *req);
+ virtual void receiveMsgs();
+ virtual void connectB();
+ virtual void selectNetwork(const QString &sel);
+ virtual void editSelectedNetwork();
+ virtual void editListedNetwork();
+ virtual void removeSelectedNetwork();
+ virtual void removeListedNetwork();
+ virtual void addNetwork();
+ virtual void enableAllNetworks();
+ virtual void disableAllNetworks();
+ virtual void removeAllNetworks();
+ virtual void saveConfig();
+ virtual void selectAdapter(const QString &sel);
+ virtual void updateNetworkDisabledStatus();
+ virtual void enableListedNetwork(bool);
+ virtual void disableListedNetwork(bool);
+
+protected slots:
+ virtual void languageChange();
+ virtual void closeEvent(QCloseEvent *event);
+
+private:
+ ScanResults *scanres;
+ bool networkMayHaveChanged;
+ char *ctrl_iface;
+ EventHistory *eh;
+ struct wpa_ctrl *ctrl_conn;
+ QSocketNotifier *msgNotifier;
+ QTimer *timer;
+ int pingsToStatusUpdate;
+ WpaMsgList msgs;
+ char *ctrl_iface_dir;
+ struct wpa_ctrl *monitor_conn;
+ UserDataRequest *udr;
+
+ int openCtrlConnection(const char *ifname);
+};
+
+#endif /* WPAGUI_H */
diff --git a/wpa_supplicant/wpa_gui-qt4/wpagui.ui b/wpa_supplicant/wpa_gui-qt4/wpagui.ui
new file mode 100644
index 0000000..2346912
--- /dev/null
+++ b/wpa_supplicant/wpa_gui-qt4/wpagui.ui
@@ -0,0 +1,419 @@
+<ui version="4.0" >
+ <class>WpaGui</class>
+ <widget class="QMainWindow" name="WpaGui" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>345</width>
+ <height>330</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>wpa_gui</string>
+ </property>
+ <widget class="QWidget" name="widget" >
+ <layout class="QGridLayout" >
+ <item row="0" column="0" >
+ <widget class="QLabel" name="adapterLabel" >
+ <property name="text" >
+ <string>Adapter:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" >
+ <widget class="QComboBox" name="adapterSelect" />
+ </item>
+ <item row="1" column="0" >
+ <widget class="QLabel" name="networkLabel" >
+ <property name="text" >
+ <string>Network:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" >
+ <widget class="QComboBox" name="networkSelect" />
+ </item>
+ <item row="2" column="0" colspan="2" >
+ <widget class="QTabWidget" name="wpaguiTab" >
+ <property name="currentIndex" >
+ <number>0</number>
+ </property>
+ <widget class="QWidget" name="statusTab" >
+ <attribute name="title" >
+ <string>Current Status</string>
+ </attribute>
+ <layout class="QGridLayout" >
+ <item row="0" column="0" colspan="5" >
+ <widget class="QFrame" name="frame3" >
+ <property name="frameShape" >
+ <enum>QFrame::NoFrame</enum>
+ </property>
+ <property name="frameShadow" >
+ <enum>QFrame::Plain</enum>
+ </property>
+ <layout class="QGridLayout" >
+ <item row="0" column="0" >
+ <widget class="QLabel" name="statusLabel" >
+ <property name="text" >
+ <string>Status:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" >
+ <widget class="QLabel" name="lastMessageLabel" >
+ <property name="text" >
+ <string>Last message:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0" >
+ <widget class="QLabel" name="authenticationLabel" >
+ <property name="text" >
+ <string>Authentication:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0" >
+ <widget class="QLabel" name="encryptionLabel" >
+ <property name="text" >
+ <string>Encryption:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="0" >
+ <widget class="QLabel" name="ssidLabel" >
+ <property name="text" >
+ <string>SSID:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="0" >
+ <widget class="QLabel" name="bssidLabel" >
+ <property name="text" >
+ <string>BSSID:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="0" >
+ <widget class="QLabel" name="ipAddressLabel" >
+ <property name="text" >
+ <string>IP address:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" >
+ <widget class="QLabel" name="textStatus" >
+ <property name="text" >
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" colspan="3" >
+ <widget class="QLabel" name="textLastMessage" >
+ <property name="text" >
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1" >
+ <widget class="QLabel" name="textAuthentication" >
+ <property name="text" >
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1" >
+ <widget class="QLabel" name="textEncryption" >
+ <property name="text" >
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="4" column="1" >
+ <widget class="QLabel" name="textSsid" >
+ <property name="text" >
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="1" >
+ <widget class="QLabel" name="textBssid" >
+ <property name="text" >
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="6" column="1" >
+ <widget class="QLabel" name="textIpAddress" >
+ <property name="text" >
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="1" column="0" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="1" column="1" >
+ <widget class="QPushButton" name="connectButton" >
+ <property name="text" >
+ <string>Connect</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="2" >
+ <widget class="QPushButton" name="disconnectButton" >
+ <property name="text" >
+ <string>Disconnect</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="3" >
+ <widget class="QPushButton" name="scanButton" >
+ <property name="text" >
+ <string>Scan</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="4" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="networkconfigTab" >
+ <attribute name="title" >
+ <string>Manage Networks</string>
+ </attribute>
+ <layout class="QGridLayout" >
+ <item row="0" column="0" colspan="5" >
+ <widget class="QListWidget" name="networkList" >
+ <property name="selectionRectVisible" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item rowspan="2" row="1" column="0" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>20</width>
+ <height>61</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="1" column="1" >
+ <widget class="QRadioButton" name="enableRadioButton" >
+ <property name="text" >
+ <string>Enabled</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="2" >
+ <widget class="QPushButton" name="editNetworkButton" >
+ <property name="text" >
+ <string>Edit</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="3" >
+ <widget class="QPushButton" name="removeNetworkButton" >
+ <property name="text" >
+ <string>Remove</string>
+ </property>
+ </widget>
+ </item>
+ <item rowspan="2" row="1" column="4" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>20</width>
+ <height>61</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="2" column="1" >
+ <widget class="QRadioButton" name="disableRadioButton" >
+ <property name="text" >
+ <string>Disabled</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="2" >
+ <widget class="QPushButton" name="addNetworkButton" >
+ <property name="text" >
+ <string>Add</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="3" >
+ <widget class="QPushButton" name="scanNetworkButton" >
+ <property name="text" >
+ <string>Scan</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="MenuBar" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>345</width>
+ <height>24</height>
+ </rect>
+ </property>
+ <widget class="QMenu" name="fileMenu" >
+ <property name="title" >
+ <string>&amp;File</string>
+ </property>
+ <addaction name="fileEventHistoryAction" />
+ <addaction name="fileSaveConfigAction" />
+ <addaction name="separator" />
+ <addaction name="fileExitAction" />
+ </widget>
+ <widget class="QMenu" name="networkMenu" >
+ <property name="title" >
+ <string>&amp;Network</string>
+ </property>
+ <addaction name="networkAddAction" />
+ <addaction name="networkEditAction" />
+ <addaction name="networkRemoveAction" />
+ <addaction name="separator" />
+ <addaction name="networkEnableAllAction" />
+ <addaction name="networkDisableAllAction" />
+ <addaction name="networkRemoveAllAction" />
+ </widget>
+ <widget class="QMenu" name="helpMenu" >
+ <property name="title" >
+ <string>&amp;Help</string>
+ </property>
+ <addaction name="helpContentsAction" />
+ <addaction name="helpIndexAction" />
+ <addaction name="separator" />
+ <addaction name="helpAboutAction" />
+ </widget>
+ <addaction name="fileMenu" />
+ <addaction name="networkMenu" />
+ <addaction name="helpMenu" />
+ </widget>
+ <action name="fileEventHistoryAction" >
+ <property name="text" >
+ <string>Event &amp;History</string>
+ </property>
+ </action>
+ <action name="fileSaveConfigAction" >
+ <property name="text" >
+ <string>&amp;Save Configuration</string>
+ </property>
+ <property name="shortcut" >
+ <string>Ctrl+S</string>
+ </property>
+ </action>
+ <action name="fileExitAction" >
+ <property name="text" >
+ <string>E&amp;xit</string>
+ </property>
+ <property name="shortcut" >
+ <string>Ctrl+Q</string>
+ </property>
+ </action>
+ <action name="networkAddAction" >
+ <property name="text" >
+ <string>&amp;Add</string>
+ </property>
+ </action>
+ <action name="networkEditAction" >
+ <property name="text" >
+ <string>&amp;Edit</string>
+ </property>
+ </action>
+ <action name="networkRemoveAction" >
+ <property name="text" >
+ <string>&amp;Remove</string>
+ </property>
+ </action>
+ <action name="networkEnableAllAction" >
+ <property name="text" >
+ <string>E&amp;nable All</string>
+ </property>
+ </action>
+ <action name="networkDisableAllAction" >
+ <property name="text" >
+ <string>&amp;Disable All</string>
+ </property>
+ </action>
+ <action name="networkRemoveAllAction" >
+ <property name="text" >
+ <string>Re&amp;move All</string>
+ </property>
+ </action>
+ <action name="helpContentsAction" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ <property name="text" >
+ <string>&amp;Contents...</string>
+ </property>
+ </action>
+ <action name="helpIndexAction" >
+ <property name="enabled" >
+ <bool>false</bool>
+ </property>
+ <property name="text" >
+ <string>&amp;Index...</string>
+ </property>
+ </action>
+ <action name="helpAboutAction" >
+ <property name="text" >
+ <string>&amp;About</string>
+ </property>
+ </action>
+ </widget>
+ <layoutdefault spacing="6" margin="11" />
+ <pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
+ <includes>
+ <include location="global" >qtimer.h</include>
+ <include location="global" >qsocketnotifier.h</include>
+ <include location="local" >wpamsg.h</include>
+ <include location="local" >eventhistory.h</include>
+ <include location="local" >scanresults.h</include>
+ </includes>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/wpa_supplicant/wpa_gui-qt4/wpamsg.h b/wpa_supplicant/wpa_gui-qt4/wpamsg.h
new file mode 100644
index 0000000..4950b21
--- /dev/null
+++ b/wpa_supplicant/wpa_gui-qt4/wpamsg.h
@@ -0,0 +1,41 @@
+/*
+ * wpa_gui - WpaMsg class for storing event messages
+ * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#ifndef WPAMSG_H
+#define WPAMSG_H
+
+#include <QDateTime>
+#include <QLinkedList>
+
+class WpaMsg {
+public:
+ WpaMsg(const QString &_msg, int _priority = 2)
+ : msg(_msg), priority(_priority)
+ {
+ timestamp = QDateTime::currentDateTime();
+ }
+
+ QString getMsg() const { return msg; }
+ int getPriority() const { return priority; }
+ QDateTime getTimestamp() const { return timestamp; }
+
+private:
+ QString msg;
+ int priority;
+ QDateTime timestamp;
+};
+
+typedef QLinkedList<WpaMsg> WpaMsgList;
+
+#endif /* WPAMSG_H */