Permalink
Browse files

Wifi page is really working. It will connect to WPAPSK, OPEN, and Ad-…

…Hoc networks. Haven't tried WEP or Shared yet.
  • Loading branch information...
1 parent 9d1b18b commit 4c63cfc5083cf5604b0b3e9bd2e4cde4749be417 Matt Roman committed Apr 23, 2011
View
8 cbcui/cbcui.pro
@@ -47,7 +47,9 @@ HEADERS += src/MainWindow.h \
src/MotorTest.h \
src/Brightness.h \
src/Volume.h \
- src/Wireless.h \
+ src/Wireless/Wireless.h \
+ src/Wireless/WifiDialog.h \
+ src/Wireless/WifiItem.h \
src//Serial/SerialPort.h \
src/Serial/SerialServer.h \
src/Serial/SerialPage.h \
@@ -110,7 +112,9 @@ SOURCES += src/main.cpp \
src/MotorTest.cpp \
src/Brightness.cpp \
src/Volume.cpp \
- src/Wireless.cpp \
+ src/Wireless/Wireless.cpp \
+ src/Wireless/WifiDialog.cpp \
+ src/Wireless/WifiItem.cpp \
src/Serial/SerialPort.cpp \
src/Serial/SerialServer.cpp \
src/Serial/SerialPage.cpp \
View
1 cbcui/rc/images.qrc
@@ -44,5 +44,6 @@
<file>botguy_wifi1.png</file>
<file>botguy_wifi2.png</file>
<file>botguy_wifi3.png</file>
+ <file>lock.png</file>
</qresource>
</RCC>
View
BIN cbcui/rc/lock.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
2 cbcui/src/Utilities.h
@@ -26,7 +26,7 @@
#include "CreateStatus.h"
#include "Serial/SerialPage.h"
-#include "Wireless.h"
+#include "Wireless/Wireless.h"
class Utilities : public Page, private Ui::Utilities
{
View
492 cbcui/src/Wireless.cpp
@@ -1,492 +0,0 @@
-#include "Wireless.h"
-#include "MainWindow.h"
-#include <QFile>
-
-Wireless::Wireless(QWidget *parent) : Page(parent),m_cbcSSID(""),m_cbcIP("")
-{
- setupUi(this);
- connect(ui_refreshButton, SIGNAL(clicked()), this, SLOT(ssidScan()));
-
- m_ssidScan = new QProcess(this);
- connect(m_ssidScan, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(listRefresh(int)));
- m_netStart = new QProcess(this);
- connect(m_netStart, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(getWifiConfig(int)));
-
- m_commAnima = new QTimer(this);
- m_commAnima->setInterval(150);
- connect(m_commAnima, SIGNAL(timeout()), this, SLOT(blinky()));
-
- // have to wait for the system to load before calling getWifiConfig()
- QTimer::singleShot(5000,this, SLOT(getWifiConfig()));
-
- //m_refreshTimer = new QTimer(this);
- //connect(m_refreshTimer, SIGNAL(timeout()), this, SLOT(ssidScan()));
-}
-
-void Wireless::show()
-{
- this->ssidScan();
- //m_refreshTimer->start(6000);
- Page::show();
-}
-
-void Wireless::hide()
-{
- //m_refreshTimer->stop();
- Page::hide();
-}
-
-Wireless::~Wireless()
-{
- m_netStart->kill();
- delete m_netStart;
- m_ssidScan->kill();
- delete m_ssidScan;
- if(m_commAnima->isActive())
- m_commAnima->stop();
- delete m_commAnima;
-}
-
-void Wireless::getWifiConfig(int exitCode)
-{
- if(m_commAnima->isActive())
- m_commAnima->stop();
- ui_connectButton->setEnabled(true);
- ui_connectButton->setText("Connect");
- if(exitCode != 0){
- m_cbcIP = "";
- m_cbcSSID = "";
- ui_ipLabel->setText("Network\nerror");
- MainWindow::instance()->stopWifiCheck();
- this->listRefresh();
- return;
- }
-
- QFile netFile("/psp/cbc_net_config");
-
- if(!netFile.exists())
- return;
-
- if(!netFile.open(QIODevice::ReadOnly | QIODevice::Text)){
- qWarning("Open error on network_config file");
- return;
- }
-
- QString data(netFile.readAll());
- QStringList netConfigList = data.split('\n');
- netFile.close();
-
- for(int i=0; i<netConfigList.size(); i++)
- {
- QString x = netConfigList.at(i);
-
- if(x.isEmpty())
- continue;
- else if(x.contains("ssid"))
- m_connectedWifi.ssid = x.section('=',1,1);
- else if(x.contains("hwaddr"))
- m_connectedWifi.hwaddr = x.section('=',1,1);
- else if(x.contains("key"))
- m_connectedWifi.key = x.section('=',1,1);
- else if(x.contains("encryption"))
- m_connectedWifi.encryption = x.section('=',1,1);
- else if(x.contains("auth"))
- m_connectedWifi.authentication = x.section('=',1,1);
- else if(x.contains("allocation"))
- m_connectedWifi.allocation = x.section('=',1,1);
- else if(x.contains("encoding"))
- m_connectedWifi.encoding = x.section('=',1,1);
- else if(x.contains("gateway"))
- m_connectedWifi.gateway = x.section('=',1,1);
- else if(x.contains("netmask"))
- m_connectedWifi.netmask = x.section('=',1,1);
- else if(x.contains("ip"))
- m_connectedWifi.ip = x.section('=',1,1);
- else if(x.contains("nameserver1"))
- m_connectedWifi.nameserver1 = x.section('=',1,1);
- else if(x.contains("nameserver2"))
- m_connectedWifi.nameserver2 = x.section('=',1,1);
- else if(x.contains("txrate"))
- m_connectedWifi.txRate = x.section('=',1,1).toInt();
- }
- m_cbcIP = m_connectedWifi.ip;
- m_cbcSSID = m_connectedWifi.ssid;
-
- ui_ipLabel->setText(m_cbcSSID + "\n" + m_cbcIP);
- this->listRefresh();
-
- if(!m_cbcIP.isEmpty())
- MainWindow::instance()->checkWifiSignal();
-}
-
-void Wireless::ssidScan()
-{
- if(m_ssidScan->state() == QProcess::NotRunning){
- m_commAnima->start();
- ui_connectButton->setEnabled(false);
- ui_ssidListWidget->clear();
-
- QListWidgetItem *scanning = new QListWidgetItem("Scanning for Networks!!!");
- // format the list item
- QSize s = scanning->sizeHint();
- s.setHeight(172);
- scanning->setSizeHint(s);
- QFont f = scanning->font();
- f.setPointSize(20);
- f.setBold(true);
- scanning->setFont(f);
- scanning->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
- scanning->setTextColor(Qt::red);
-
- ui_ssidListWidget->addItem(scanning);
- m_ssidScan->start("/mnt/kiss/wifi/wifi_scan.pl");
- }else
- {
- ui_ssidListWidget->clear();
-
- QListWidgetItem *stillscanning = new QListWidgetItem("CHILL!\nI'm still scanning!!!");
- // format the list item
- QSize s = stillscanning->sizeHint();
- s.setHeight(172);
- stillscanning->setSizeHint(s);
- QFont f = stillscanning->font();
- f.setPointSize(20);
- f.setBold(true);
- stillscanning->setFont(f);
- stillscanning->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
- stillscanning->setTextColor(Qt::red);
-
- ui_ssidListWidget->addItem(stillscanning);
- }
-}
-
-void Wireless::listRefresh(int exitCode)
-{
- QFile fn("/mnt/kiss/wifi/ssids");
- if(m_commAnima->isActive())
- m_commAnima->stop();
- ui_connectButton->setEnabled(true);
- ui_connectButton->setText("Connect");
-
- if(exitCode == 0 && fn.exists()){
- QProcess check;
- check.start("/mnt/kiss/wifi/wifi_connected.pl");
- check.waitForFinished(100);
- if(check.exitCode())
- m_cbcSSID = "";
- else
- m_cbcSSID = QString(check.readAllStandardOutput());
-
- check.start("/mnt/kiss/wifi/wifi_ip.pl");
- check.waitForFinished(100);
- if(check.exitCode())
- m_cbcIP = "";
- else
- m_cbcIP = QString(check.readAllStandardOutput());
-
- ui_ssidListWidget->clear();
- fn.open(QIODevice::ReadOnly);
- while(!fn.atEnd()){
- QString net(fn.readLine());
- this->addSsidToList(net);
- }
- fn.close();
- }
- else{
- if(exitCode == 1)
- ui_ssidListWidget->item(0)->setText("No Networks Available");
- else if(exitCode == 2)
- ui_ssidListWidget->item(0)->setText("No WiFi card detected");
-
- ui_ipLabel->setText("");
- MainWindow::instance()->stopWifiCheck();
- }
-}
-
-void Wireless::addSsidToList(QString net)
-{
- // get the SSID name
- QString ssidName = net.section(" ",2,2);
- QString ssidAuth = net.section(" ",5,5);
- QString hwaddr = net.section(" ",3,3);
-
- // get the link quality
- int q = net.indexOf("Quality");
- q = net.indexOf(':',q) + 1;
- int eq = net.indexOf('/',q);
- int quality = net.mid(q,eq-q).toInt();
-
- QListWidgetItem *ssid = new QListWidgetItem(ssidName);
- ssid->setData(Qt::UserRole,hwaddr);
- // format the list item
- QSize s = ssid->sizeHint();
- s.setHeight(35);
- ssid->setSizeHint(s);
- QFont f = ssid->font();
- f.setPointSize(14);
- f.setBold(true);
- ssid->setFont(f);
-
- QIcon wifiIcon;
- if(quality > 75)
- wifiIcon.addFile(":/actions/botguy_wifi3.png");
- else if(quality > 50)
- wifiIcon.addFile(":/actions/botguy_wifi2.png");
- else if(quality > 25)
- wifiIcon.addFile(":/actions/botguy_wifi1.png");
- else
- wifiIcon.addFile(":/actions/botguy_wifi0.png");
- ssid->setIcon(wifiIcon);
-
- if(ssidName == m_cbcSSID){
- ssid->setBackgroundColor(Qt::green);
- }
-
- ui_ssidListWidget->addItem(ssid);
-}
-
-void Wireless::on_ui_connectButton_clicked()
-{
- if(ui_ssidListWidget->currentRow() < 0)
- return;
- m_connectedWifi.ssid = ui_ssidListWidget->currentItem()->text();
- m_connectedWifi.hwaddr = ui_ssidListWidget->currentItem()->data(Qt::UserRole).toString();
-
- wifiDialog wDialog(&m_connectedWifi,this);
- if(wDialog.exec() == QDialog::Accepted)
- {
- QFile netFile("/psp/cbc_net_config");
-
- if(netFile.exists()){
- QFile::remove("/psp/old_cbc_net_config");
- netFile.copy("/psp/old_cbc_net_config");
- }
-
- netFile.remove();
-
- if(!netFile.open(QIODevice::ReadWrite | QIODevice::Text)){
- qWarning("Open error on network_config file");
- return;
- }
-
- QTextStream netConfig(&netFile);
- netConfig << "type=wlan\n";
- netConfig << "ssid=" << m_connectedWifi.ssid << "\n";
- netConfig << "hwaddr=" << m_connectedWifi.hwaddr << "\n";
- netConfig << "key=" << m_connectedWifi.key << "\n";
- netConfig << "encryption=" << m_connectedWifi.encryption << "\n";
- netConfig << "auth=" << m_connectedWifi.authentication << "\n";
- netConfig << "allocation=" << m_connectedWifi.allocation << "\n";
- netConfig << "encoding=" << m_connectedWifi.encoding << "\n";
- netConfig << "gateway=" << m_connectedWifi.gateway << "\n";
- netConfig << "netmask=" << m_connectedWifi.netmask << "\n";
- netConfig << "ip=" << m_connectedWifi.ip << "\n";
- netConfig << "nameserver1=" << m_connectedWifi.nameserver1 << "\n";
- netConfig << "nameserver2=" << m_connectedWifi.nameserver2 << "\n";
- netConfig << "txrate=" << m_connectedWifi.txRate << "\n";
-
- netFile.close();
-
- if(m_netStart->state() == QProcess::NotRunning){
- m_netStart->start("/mnt/kiss/wifi/wifi_start.pl");
- ui_connectButton->setEnabled(false);
- m_commAnima->start();
- }
- }
-}
-
-void Wireless::blinky()
-{
- static int i=0;
-
- switch(i){
- case 0:
- ui_connectButton->setText("|");
- break;
- case 1:
- ui_connectButton->setText("( | )");
- break;
- case 2:
- ui_connectButton->setText("(( | ))");
- break;
- case 3:
- ui_connectButton->setText("((( | )))");
- break;
- case 4:
- ui_connectButton->setText("(( | ))");
- break;
- case 5:
- ui_connectButton->setText("( | )");
- break;
- }
- i++;
- if(i>5) i=0;
-}
-
-//////////////////////////////////////////////////////////////////////////
-// Wifi Network Config Dialog
-/////////////////////////////
-wifiDialog::wifiDialog(WifiPort *wp, QWidget *parent)
- : QDialog(parent), port(wp)
-{
- setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
- this->setStyleSheet("QDialog{border:3px solid blue; border-radius: 5px}");
-
- // Main Window Layout
- QVBoxLayout *mainLayout = new QVBoxLayout;
-
-// SSID
- QHBoxLayout *ssidBox = new QHBoxLayout;
- ssid.setText("SSID:");
- ssidBox->addWidget(&ssid);
- QLabel *ssidName = new QLabel(port->ssid);
- ssidBox->addWidget(ssidName);
- mainLayout->addLayout(ssidBox);
-
-// HWADDR
- QHBoxLayout *hwaddrBox = new QHBoxLayout;
- hwaddr.setText("Hwaddr:");
- hwaddrBox->addWidget(&hwaddr);
- QLabel *hwaddrName = new QLabel(port->hwaddr);
- hwaddrBox->addWidget(hwaddrName);
- mainLayout->addLayout(hwaddrBox);
-
-// Allocation
- QHBoxLayout *allocBox = new QHBoxLayout;
- alloc.setText("Allocation:");
- allocBox->addWidget(&alloc);
- allocCombo = new QComboBox(this);
- allocCombo->setMinimumSize(QSize(100,20));
- allocCombo->addItem("dhcp");
- allocCombo->addItem("static");
- if(port->allocation.isNull())
- allocCombo->setCurrentIndex(0);
- else
- allocCombo->setCurrentIndex(allocCombo->findText(port->allocation));
- allocBox->addWidget(allocCombo);
- mainLayout->addLayout(allocBox);
-
-// authentication
- QHBoxLayout *authBox = new QHBoxLayout;
- auth.setText("Authentication:");
- authBox->addWidget(&auth);
- authCombo = new QComboBox(this);
- authCombo->setMinimumSize(QSize(100,20));
- authCombo->addItem("NONE");
- authCombo->addItem("OPEN");
- authCombo->addItem("SHARED");
- authCombo->addItem("WPAPSK");
- authCombo->addItem("WPA2PSK");
- if(port->authentication.isNull())
- authCombo->setCurrentIndex(0);
- else{
- authCombo->setCurrentIndex(authCombo->findText(port->authentication));
- }
- authBox->addWidget(authCombo);
- mainLayout->addLayout(authBox);
-
-// Encryption
- QHBoxLayout *encrypBox = new QHBoxLayout;
- encryp.setText("Encryption:");
- encrypBox->addWidget(&encryp);
- encrypCombo = new QComboBox(this);
- encrypCombo->setMinimumSize(QSize(100,20));
- encrypCombo->addItem("NONE");
- encrypCombo->addItem("AES");
- encrypCombo->addItem("TKIP");
- encrypCombo->addItem("WEP");
- if(port->encryption.isNull())
- encrypCombo->setCurrentIndex(0);
- else{
- encrypCombo->setCurrentIndex(encrypCombo->findText(port->encryption));
- }
- encrypBox->addWidget(encrypCombo);
- mainLayout->addLayout(encrypBox);
-
-// Ascii and Hex check boxes
- m_encoding = port->encoding;
- QHBoxLayout *encodeBox = new QHBoxLayout;
- encodeBox->addStretch();
- AsciiCheck = new QCheckBox("Ascii");
- if(m_encoding == "ascii" || m_encoding.isNull()){
- AsciiCheck->setChecked(true);
- m_encoding = "ascii";
- }
- else
- AsciiCheck->setChecked(false);
- encodeBox->addWidget(AsciiCheck);
- HexCheck = new QCheckBox("Hex");
- if(m_encoding == "hex")
- HexCheck->setChecked(true);
- else
- HexCheck->setChecked(false);
- encodeBox->addWidget(HexCheck);
- mainLayout->addLayout(encodeBox);
-
-// Pass Key
- QHBoxLayout *keyBox = new QHBoxLayout;
- key.setText("Passkey:");
- keyBox->addWidget(&key);
- keyLineEdit = new QLineEdit(this);
- keyLineEdit->setMaximumWidth(150);
- keyBox->addWidget(keyLineEdit);
- mainLayout->addLayout(keyBox);
-
-// Dialog buttons
- QHBoxLayout *buttonBox = new QHBoxLayout;
- connectButton = new QPushButton("Connect");
- connectButton->setMinimumSize(QSize(80,30));
- connectButton->setMaximumSize(QSize(80,30));
- connectButton->setStyleSheet("QPushButton:default{border:0px;background-image:url(:/actions/rivet80x30L.png);color:black;} QPushButton:pressed{border:0px;background-image:url(:/actions/rivet80x30D.png);color:white;}");
- buttonBox->addWidget(connectButton);
- cancelButton = new QPushButton("Cancel");
- cancelButton->setMinimumSize(QSize(80,30));
- cancelButton->setMaximumSize(QSize(80,30));
- cancelButton->setStyleSheet("QPushButton{border:0px;background-image:url(:/actions/rivet80x30L.png);color:black;} QPushButton:pressed{border:0px;background-image:url(:/actions/rivet80x30D.png);color:white;}");
- buttonBox->addWidget(cancelButton);
- mainLayout->addLayout(buttonBox);
-
- this->setLayout(mainLayout);
-
- connect(keyLineEdit, SIGNAL(selectionChanged()), this, SLOT(keyInput()));
- connect(AsciiCheck, SIGNAL(clicked()), this, SLOT(encodingChanged()));
- connect(HexCheck, SIGNAL(clicked()), this, SLOT(encodingChanged()));
- connect(connectButton, SIGNAL(clicked()), this, SLOT(acceptData()));
- connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
-
- move(50,0);
-}
-
-void wifiDialog::encodingChanged()
-{
- if(m_encoding == "ascii"){
- AsciiCheck->setChecked(false);
- HexCheck->setChecked(true);
- m_encoding = "hex";
- }else{
- AsciiCheck->setChecked(true);
- HexCheck->setChecked(false);
- m_encoding = "ascii";
- }
-}
-
-void wifiDialog::acceptData()
-{
- port->allocation = allocCombo->currentText();
- port->authentication = authCombo->currentText();
- port->encryption = encrypCombo->currentText();
- port->encoding = m_encoding;
- port->key = keyLineEdit->text();
- port->txRate = 6;
- this->accept();
-}
-
-void wifiDialog::keyInput()
-{
- QwertyKeypad *user_keypad = QwertyKeypad::instance("");
- keyLineEdit->setStyleSheet("QLineEdit#ui_ServoPositionLine{background-color:red}");
- user_keypad->exec();
-
- keyLineEdit->setText(user_keypad->getString());
- keyLineEdit->setStyleSheet("QLineEdit#ui_ServoPositionLine{background-color:white}");
-}
View
91 cbcui/src/Wireless.h
@@ -1,91 +0,0 @@
-#ifndef __WIRELESS_H__
-#define __WIRELESS_H__
-
-#include "ui_Wireless.h"
-#include "Page.h"
-#include <QProcess>
-#include <QTimer>
-#include <QtGui>
-#include "Keyboard/QwertyKeypad.h"
-
-struct WifiPort{
- QString ssid;
- QString hwaddr;
- QString key;
- QString encryption;
- QString authentication;
- QString allocation;
- QString encoding;
- QString gateway;
- QString netmask;
- QString ip;
- QString nameserver1;
- QString nameserver2;
- int txRate;
-};
-
-class wifiDialog;
-
-class Wireless : public Page, private Ui::Wireless
-{
- Q_OBJECT
-public:
- Wireless(QWidget *parent = 0);
- ~Wireless();
-
-public slots:
- void show();
- void hide();
-
- void ssidScan();
- void getWifiConfig(int exitCode = 0);
- void listRefresh(int exitCode = 0);
- void on_ui_connectButton_clicked();
- void blinky();
-
-private:
- QString m_cbcSSID;
- QString m_cbcIP;
- QProcess *m_ssidScan;
- QProcess *m_netStart;
- struct WifiPort m_connectedWifi;
- QTimer *m_commAnima;
- //QTimer *m_refreshTimer;
-
- void addSsidToList(QString net);
-};
-
-class wifiDialog : public QDialog
-{
- Q_OBJECT
-
- public:
- wifiDialog(struct WifiPort *wp, QWidget *parent = 0);
-
- QComboBox *allocCombo;
- QComboBox *authCombo;
- QComboBox *encrypCombo;
- QCheckBox *AsciiCheck;
- QCheckBox *HexCheck;
- QLineEdit *keyLineEdit;
-
- QPushButton *connectButton;
- QPushButton *cancelButton;
-
- private:
- struct WifiPort *port;
- QString m_encoding;
- QLabel ssid;
- QLabel hwaddr;
- QLabel alloc;
- QLabel auth;
- QLabel encryp;
- QLabel key;
-
- public slots:
- void encodingChanged();
- void acceptData();
- void keyInput();
-};
-
-#endif // __WIRELESS_H__
View
81 cbcui/src/Wireless/WifiDialog.cpp
@@ -0,0 +1,81 @@
+#include "WifiDialog.h"
+
+WifiDialog::WifiDialog(WifiPort *wp, QWidget *parent)
+ : QDialog(parent), port(wp)
+{
+ setupUi(this);
+ move(50,0);
+ setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
+ this->setStyleSheet("QDialog{border:3px solid blue; border-radius: 5px}");
+
+ ui_ssidLabel->setText(port->ssid);
+ ui_macLabel->setText(port->ap);
+ ui_allocationCombo->setCurrentIndex(0);
+ ui_authLabel->setText(port->authentication);
+ ui_encrypLabel->setText(port->encryption);
+ ui_txRateCombo->addItems(port->rates);
+
+ if(port->encoding.isEmpty() || port->encoding == "ascii"){
+ m_encoding = "ascii";
+ ui_asciiCheck->setChecked(true);
+ }
+ else{
+ m_encoding = "hex";
+ ui_hexCheck->setChecked(true);
+ }
+
+ if(port->txRate.isEmpty()){
+ int defTx = ui_txRateCombo->findText("9Mb/s");
+ if(defTx < 0)
+ ui_txRateCombo->setCurrentIndex(0);
+ else
+ ui_txRateCombo->setCurrentIndex(defTx);
+ }
+ else
+ ui_txRateCombo->setCurrentIndex(ui_txRateCombo->findText(port->txRate));
+
+ if(port->authentication == "OPEN" && port->encryption == "NONE")
+ {
+ ui_asciiCheck->setEnabled(false);
+ ui_hexCheck->setEnabled(false);
+ ui_keyLineEdit->setEnabled(false);
+ }
+
+ connect(ui_keyLineEdit, SIGNAL(selectionChanged()), this, SLOT(keyInput()));
+ connect(ui_asciiCheck, SIGNAL(clicked()), this, SLOT(encodingChanged()));
+ connect(ui_hexCheck, SIGNAL(clicked()), this, SLOT(encodingChanged()));
+ connect(ui_connectButton, SIGNAL(clicked()), this, SLOT(acceptData()));
+ connect(ui_cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
+}
+
+void WifiDialog::encodingChanged()
+{
+ if(m_encoding == "ascii"){
+ ui_asciiCheck->setChecked(false);
+ ui_hexCheck->setChecked(true);
+ m_encoding = "hex";
+ }else{
+ ui_asciiCheck->setChecked(true);
+ ui_hexCheck->setChecked(false);
+ m_encoding = "ascii";
+ }
+}
+
+void WifiDialog::acceptData()
+{
+ port->allocation = ui_allocationCombo->currentText();
+ port->encoding = m_encoding;
+ port->key = ui_keyLineEdit->text();
+ port->txRate = ui_txRateCombo->currentText();
+ this->accept();
+}
+
+void WifiDialog::keyInput()
+{
+ QwertyKeypad *user_keypad = QwertyKeypad::instance("");
+ ui_keyLineEdit->setStyleSheet("QLineEdit#ui_ServoPositionLine{background-color:red}");
+ user_keypad->exec();
+
+ ui_keyLineEdit->setText(user_keypad->getString());
+ ui_keyLineEdit->setStyleSheet("QLineEdit#ui_ServoPositionLine{background-color:white}");
+}
View
42 cbcui/src/Wireless/WifiDialog.h
@@ -0,0 +1,42 @@
+#ifndef __WIFIDIALOG_H__
+#define __WIFIDIALOG_H__
+
+#include "ui_WifiDialog.h"
+#include "../Keyboard/QwertyKeypad.h"
+
+struct WifiPort{
+ QString ssid;
+ QString ap;
+ QString netType;
+ QString key;
+ QString encryption;
+ QString authentication;
+ QString allocation;
+ QString encoding;
+ QString gateway;
+ QString netmask;
+ QString ip;
+ QString nameserver1;
+ QString nameserver2;
+ QString txRate;
+ QStringList rates;
+};
+
+class WifiDialog : public QDialog, private Ui::WifiDialog
+{
+ Q_OBJECT
+
+public:
+ WifiDialog(struct WifiPort *wp, QWidget *parent = 0);
+
+private:
+ QString m_encoding;
+ struct WifiPort *port;
+
+public slots:
+ void encodingChanged();
+ void acceptData();
+ void keyInput();
+};
+
+#endif // __WIFIDIALOG_H__
View
41 cbcui/src/Wireless/WifiItem.cpp
@@ -0,0 +1,41 @@
+#include "WifiItem.h"
+
+WifiItem::WifiItem(QString text, QWidget *parent) : QWidget(parent)
+{
+ setupUi(this);
+ ui_ssidLabel->setText(text);
+ ui_lockWidget->setVisible(false);
+}
+
+WifiItem::~WifiItem()
+{
+}
+
+void WifiItem::setSsidText(QString ssid)
+{
+ ui_ssidLabel->setText(ssid);
+}
+
+void WifiItem::setAccessPoint(QString ap)
+{
+ ui_accessPointLabel->setText(ap);
+}
+
+void WifiItem::setLockEnabled(bool lk)
+{
+ ui_lockWidget->setVisible(lk);
+}
+
+void WifiItem::setSignalImage(int quality)
+{
+ QString style;
+ if(quality > 75)
+ style = "QFrame{border:0px;background-image:url(:/actions/botguy_wifi3.png);}";
+ else if(quality > 50)
+ style = "QFrame{border:0px;background-image:url(:/actions/botguy_wifi2.png);}";
+ else if(quality > 25)
+ style = "QFrame{border:0px;background-image:url(:/actions/botguy_wifi1.png);}";
+ else
+ style = "QFrame{border:0px;background-image:url(:/actions/botguy_wifi0.png);}";
+ ui_signalStrengthFrame->setStyleSheet(style);
+}
View
18 cbcui/src/Wireless/WifiItem.h
@@ -0,0 +1,18 @@
+#ifndef __WIFIITEM_H__
+#define __WIFIITEM_H__
+
+#include "ui_WifiItem.h"
+
+class WifiItem : public QWidget, private Ui::WifiItem
+{
+public:
+ WifiItem(QString ssid = 0, QWidget *parent = 0);
+ ~WifiItem();
+
+ void setSsidText(QString ssid);
+ void setAccessPoint(QString ap);
+ void setSignalImage(int quality);
+ void setLockEnabled(bool lk);
+};
+
+#endif // __WIFIITEM_H__
View
273 cbcui/src/Wireless/Wireless.cpp
@@ -0,0 +1,273 @@
+#include "Wireless.h"
+#include "WifiItem.h"
+#include "../MainWindow.h"
+#include <QFile>
+
+Wireless::Wireless(QWidget *parent) : Page(parent)
+{
+ setupUi(this);
+ connect(ui_refreshButton, SIGNAL(clicked()), this, SLOT(ssidScan()));
+
+ m_ssidScan = new QProcess(this);
+ connect(m_ssidScan, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(listRefresh(int)));
+ m_netStart = new QProcess(this);
+ connect(m_netStart, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(listRefresh(int)));
+
+ m_commAnima = new QTimer(this);
+ m_commAnima->setInterval(150);
+ connect(m_commAnima, SIGNAL(timeout()), this, SLOT(blinky()));
+
+ // have to wait for the system to load before calling getWifiConnection()
+ QTimer::singleShot(5000,this, SLOT(listRefresh()));
+
+ //m_refreshTimer = new QTimer(this);
+ //connect(m_refreshTimer, SIGNAL(timeout()), this, SLOT(ssidScan()));
+}
+
+void Wireless::show()
+{
+ this->ssidScan();
+ //m_refreshTimer->start(6000);
+ Page::show();}
+
+void Wireless::hide()
+{
+ //m_refreshTimer->stop();
+ Page::hide();
+}
+
+Wireless::~Wireless()
+{
+ m_netStart->kill();
+ delete m_netStart;
+ m_ssidScan->kill();
+ delete m_ssidScan;
+ if(m_commAnima->isActive())
+ m_commAnima->stop();
+ delete m_commAnima;
+}
+
+void Wireless::ssidScan()
+{
+ if(m_ssidScan->state() == QProcess::NotRunning)
+ {
+ m_commAnima->start();
+ ui_connectButton->setEnabled(false);
+
+ this->userMessage("Scanning for Networks!!!");
+ m_ssidScan->start("/mnt/kiss/wifi/wifi_scan.pl");
+ }
+ else
+ this->userMessage("CHILL!\nI'm still scanning!!!");
+}
+
+void Wireless::listRefresh(int exitCode)
+{
+ if(!m_netList.isEmpty())
+ m_netList.clear();
+
+ QProcess netStat;
+ netStat.start("/mnt/kiss/wifi/wifi_connected.pl");
+ netStat.waitForFinished(100);
+ m_connectedWifi.ssid = QString(netStat.readAllStandardOutput());
+
+ netStat.start("/mnt/kiss/wifi/wifi_ip.pl");
+ netStat.waitForFinished(100);
+ m_connectedWifi.ip = QString(netStat.readAllStandardOutput());
+
+ ui_ipLabel->setText(m_connectedWifi.ssid + "\n" + m_connectedWifi.ip);
+
+ if(m_connectedWifi.ip.isEmpty() || m_connectedWifi.ssid.isEmpty())
+ MainWindow::instance()->stopWifiCheck();
+ else
+ MainWindow::instance()->checkWifiSignal();
+
+ if(!this->isVisible())
+ return;
+
+ QFile fn("/mnt/kiss/wifi/ssids");
+ if(m_commAnima->isActive())
+ m_commAnima->stop();
+ ui_connectButton->setText("Connect");
+
+ if(exitCode == 0 && fn.exists()){
+ ui_ssidListWidget->clear();
+
+ fn.open(QIODevice::ReadOnly);
+
+ while(!fn.atEnd()){
+ QString net(fn.readLine());
+ this->addSsidToList(net);
+ }
+ fn.close();
+ ui_connectButton->setEnabled(true);
+ }
+ else{
+ if(exitCode == 1)
+ this->userMessage("No Networks Available");
+ else if(exitCode == 2)
+ this->userMessage("No WiFi card detected");
+ else if(exitCode == 3)
+ this->userMessage("Network Error\nCheck settings");
+
+ ui_connectButton->setEnabled(false);
+ }
+}
+
+void Wireless::addSsidToList(QString net)
+{
+ struct WifiPort wp;
+
+ // get the SSID name
+ wp.ssid = net.section(" ",2,2);
+ wp.ap = net.section(" ",3,3);
+ wp.encryption = net.section(" ",4,4);
+ wp.authentication = net.section(" ",5,5);
+ if(wp.authentication.contains('2'))
+ wp.authentication = "WPA2PSK";
+ else if(wp.authentication.contains('-'))
+ wp.authentication = "WPAPSK";
+ wp.netType = net.section(" ",6,6);
+
+ int quality = net.section(" ",7,7).toInt();
+ wp.rates = net.section(" ",8,8).split(";");
+
+ WifiItem *ssid = new WifiItem(wp.ssid);
+ ssid->setSignalImage(quality);
+ ssid->setAccessPoint(wp.ap);
+ if(wp.authentication == "OPEN" || wp.authentication == "SHARED")
+ ssid->setLockEnabled(false);
+ else
+ ssid->setLockEnabled(true);
+ QListWidgetItem *itm = new QListWidgetItem();
+
+// QListWidgetItem *ssid = new QListWidgetItem(wp.ssid);
+// ssid->setData(Qt::UserRole,wp.ap);
+// // format the list item
+// QSize s = ssid->sizeHint();
+// s.setHeight(35);
+// ssid->setSizeHint(s);
+// QFont f = ssid->font();
+// f.setPointSize(14);
+// f.setBold(true);
+// ssid->setFont(f);
+
+// QIcon wifiIcon;
+// if(quality > 75)
+// wifiIcon.addFile(":/actions/botguy_wifi3.png");
+// else if(quality > 50)
+// wifiIcon.addFile(":/actions/botguy_wifi2.png");
+// else if(quality > 25)
+// wifiIcon.addFile(":/actions/botguy_wifi1.png");
+// else
+// wifiIcon.addFile(":/actions/botguy_wifi0.png");
+// ssid->setIcon(wifiIcon);
+
+ if(wp.ssid == m_connectedWifi.ssid)
+ itm->setBackgroundColor(Qt::green);
+
+ //ui_ssidListWidget->addItem(ssid);
+ itm->setSizeHint(ssid->size());
+ ui_ssidListWidget->addItem(itm);
+ ui_ssidListWidget->setItemWidget(itm,ssid);
+ m_netList << wp;
+}
+
+void Wireless::on_ui_connectButton_clicked()
+{
+ int index = ui_ssidListWidget->currentRow();
+ if(index < 0)
+ return;
+
+ WifiDialog wDialog(&m_netList[index],this);
+ if(wDialog.exec() == QDialog::Accepted)
+ {
+ m_connectedWifi = m_netList[index];
+
+ if(m_connectedWifi.encryption.contains(','))
+ m_connectedWifi.encryption = "AES";
+
+ QFile netFile("/psp/cbc_net_config");
+ if(netFile.exists()){
+ QFile::remove("/psp/old_cbc_net_config");
+ netFile.copy("/psp/old_cbc_net_config");
+ }
+ netFile.remove();
+ if(!netFile.open(QIODevice::ReadWrite | QIODevice::Text)){
+ qWarning("Open error on network_config file");
+ return;
+ }
+
+ QTextStream netConfig(&netFile);
+ netConfig << "type=wlan\n";
+ netConfig << "ssid=" << m_connectedWifi.ssid << "\n";
+ netConfig << "ap=" << m_connectedWifi.ap << "\n";
+ netConfig << "netType=" << m_connectedWifi.netType << "\n";
+ netConfig << "key=" << m_connectedWifi.key << "\n";
+ netConfig << "encryption=" << m_connectedWifi.encryption << "\n";
+ netConfig << "auth=" << m_connectedWifi.authentication << "\n";
+ netConfig << "allocation=" << m_connectedWifi.allocation << "\n";
+ netConfig << "encoding=" << m_connectedWifi.encoding << "\n";
+ netConfig << "gateway=" << m_connectedWifi.gateway << "\n";
+ netConfig << "netmask=" << m_connectedWifi.netmask << "\n";
+ netConfig << "ip=" << m_connectedWifi.ip << "\n";
+ netConfig << "nameserver1=" << m_connectedWifi.nameserver1 << "\n";
+ netConfig << "nameserver2=" << m_connectedWifi.nameserver2 << "\n";
+ netConfig << "txrate=" << m_connectedWifi.txRate << "\n";
+
+ netFile.close();
+
+ if(m_netStart->state() == QProcess::NotRunning){
+ m_netStart->start("/mnt/kiss/wifi/wifi_start.pl");
+ ui_connectButton->setEnabled(false);
+ m_commAnima->start();
+ }
+ }
+}
+
+void Wireless::userMessage(QString msg)
+{
+ ui_ssidListWidget->clear();
+
+ QListWidgetItem *msgItem = new QListWidgetItem(msg);
+ // format the list item
+ QSize s = msgItem->sizeHint();
+ s.setHeight(172);
+ msgItem->setSizeHint(s);
+ QFont f = msgItem->font();
+ f.setPointSize(20);
+ f.setBold(true);
+ msgItem->setFont(f);
+ msgItem->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
+ msgItem->setTextColor(Qt::red);
+
+ ui_ssidListWidget->addItem(msgItem);
+}
+
+void Wireless::blinky()
+{
+ static int i=0;
+
+ switch(i){
+ case 0:
+ ui_connectButton->setText("|");
+ break;
+ case 1:
+ ui_connectButton->setText("( | )");
+ break;
+ case 2:
+ ui_connectButton->setText("(( | ))");
+ break;
+ case 3:
+ ui_connectButton->setText("((( | )))");
+ break;
+ case 4:
+ ui_connectButton->setText("(( | ))");
+ break;
+ case 5:
+ ui_connectButton->setText("( | )");
+ break;
+ }
+ i++;
+ if(i>5) i=0;
+}
View
41 cbcui/src/Wireless/Wireless.h
@@ -0,0 +1,41 @@
+#ifndef __WIRELESS_H__
+#define __WIRELESS_H__
+
+#include "ui_Wireless.h"
+#include "WifiDialog.h"
+#include "../Page.h"
+#include <QProcess>
+#include <QTimer>
+#include <QtGui>
+
+
+class Wireless : public Page, private Ui::Wireless
+{
+ Q_OBJECT
+public:
+ Wireless(QWidget *parent = 0);
+ ~Wireless();
+
+public slots:
+ void show();
+ void hide();
+
+ void ssidScan();
+ void listRefresh(int exitCode = 0);
+ void on_ui_connectButton_clicked();
+ void blinky();
+
+private:
+ QList<WifiPort> m_netList;
+ struct WifiPort m_connectedWifi;
+ QProcess *m_ssidScan;
+ QProcess *m_netStart;
+
+ QTimer *m_commAnima;
+ //QTimer *m_refreshTimer;
+
+ void addSsidToList(QString net);
+ void userMessage(QString msg);
+};
+
+#endif // __WIRELESS_H__
View
4 cbcui/test.sh
@@ -1,7 +1,7 @@
#Onurs address pass:RouterAdm1n
-CBC_IP=192.168.1.76
+#CBC_IP=192.168.1.76
#KIPR address
-#CBC_IP=192.168.123.56
+CBC_IP=192.168.123.56
make &&
ssh root@$CBC_IP killall cbcui
scp cbcui root@$CBC_IP:/mnt/kiss/gui/cbcui &&
View
135 cbcui/ui/WifiDialog.ui
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>220</width>
- <height>230</height>
+ <width>235</width>
+ <height>240</height>
</rect>
</property>
<property name="sizePolicy">
@@ -18,14 +18,14 @@
</property>
<property name="minimumSize">
<size>
- <width>100</width>
- <height>200</height>
+ <width>235</width>
+ <height>240</height>
</size>
</property>
<property name="maximumSize">
<size>
- <width>220</width>
- <height>230</height>
+ <width>241</width>
+ <height>240</height>
</size>
</property>
<property name="windowTitle">
@@ -42,27 +42,27 @@
<number>6</number>
</property>
<property name="topMargin">
- <number>0</number>
+ <number>6</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
- <number>0</number>
+ <number>9</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_2">
<property name="minimumSize">
<size>
- <width>80</width>
+ <width>100</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
- <width>80</width>
+ <width>100</width>
<height>16777215</height>
</size>
</property>
@@ -76,9 +76,19 @@
</item>
<item>
<widget class="QLabel" name="ui_ssidLabel">
+ <property name="font">
+ <font>
+ <pointsize>13</pointsize>
+ <weight>75</weight>
+ <bold>true</bold>
+ </font>
+ </property>
<property name="text">
<string>KIPR</string>
</property>
+ <property name="alignment">
+ <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
+ </property>
</widget>
</item>
</layout>
@@ -89,18 +99,18 @@
<widget class="QLabel" name="label_3">
<property name="minimumSize">
<size>
- <width>80</width>
+ <width>100</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
- <width>80</width>
+ <width>100</width>
<height>16777215</height>
</size>
</property>
<property name="text">
- <string>MacAddr:</string>
+ <string>Access Point:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -112,6 +122,9 @@
<property name="text">
<string>00:00:00:00:00:00</string>
</property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
</widget>
</item>
</layout>
@@ -122,13 +135,13 @@
<widget class="QLabel" name="label_4">
<property name="minimumSize">
<size>
- <width>80</width>
+ <width>100</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
- <width>80</width>
+ <width>100</width>
<height>16777215</height>
</size>
</property>
@@ -141,10 +154,29 @@
</widget>
</item>
<item>
+ <spacer name="horizontalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
<widget class="QComboBox" name="ui_allocationCombo">
+ <property name="minimumSize">
+ <size>
+ <width>80</width>
+ <height>0</height>
+ </size>
+ </property>
<property name="maximumSize">
<size>
- <width>16777215</width>
+ <width>80</width>
<height>20</height>
</size>
</property>
@@ -160,6 +192,19 @@
</item>
</widget>
</item>
+ <item>
+ <spacer name="horizontalSpacer_4">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
</layout>
</item>
<item>
@@ -168,18 +213,18 @@
<widget class="QLabel" name="label_5">
<property name="minimumSize">
<size>
- <width>80</width>
+ <width>100</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
- <width>80</width>
+ <width>100</width>
<height>16777215</height>
</size>
</property>
<property name="text">
- <string>Auth:</string>
+ <string>Authentication:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@@ -191,6 +236,9 @@
<property name="text">
<string>WPA2PSK</string>
</property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
</widget>
</item>
</layout>
@@ -201,13 +249,13 @@
<widget class="QLabel" name="label_6">
<property name="minimumSize">
<size>
- <width>80</width>
+ <width>100</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
- <width>80</width>
+ <width>100</width>
<height>16777215</height>
</size>
</property>
@@ -224,6 +272,9 @@
<property name="text">
<string>TKIP</string>
</property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
</widget>
</item>
</layout>
@@ -234,13 +285,13 @@
<widget class="QLabel" name="label_7">
<property name="minimumSize">
<size>
- <width>80</width>
+ <width>100</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
- <width>80</width>
+ <width>100</width>
<height>16777215</height>
</size>
</property>
@@ -253,15 +304,47 @@
</widget>
</item>
<item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
<widget class="QComboBox" name="ui_txRateCombo">
+ <property name="minimumSize">
+ <size>
+ <width>90</width>
+ <height>0</height>
+ </size>
+ </property>
<property name="maximumSize">
<size>
- <width>16777215</width>
+ <width>90</width>
<height>20</height>
</size>
</property>
</widget>
</item>
+ <item>
+ <spacer name="horizontalSpacer_3">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
</layout>
</item>
<item>
@@ -270,13 +353,13 @@
<widget class="QLabel" name="label_8">
<property name="minimumSize">
<size>
- <width>80</width>
+ <width>100</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
- <width>80</width>
+ <width>100</width>
<height>16777215</height>
</size>
</property>
View
50 cbcui/ui/WifiItem.ui
@@ -1,32 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
- <class>wifiWidgetItem</class>
- <widget class="QWidget" name="wifiWidgetItem">
+ <class>WifiItem</class>
+ <widget class="QWidget" name="WifiItem">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
- <width>320</width>
+ <width>316</width>
<height>35</height>
</rect>
</property>
<property name="minimumSize">
<size>
- <width>320</width>
+ <width>316</width>
<height>35</height>
</size>
</property>
<property name="maximumSize">
<size>
- <width>320</width>
+ <width>316</width>
<height>35</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="styleSheet">
- <string notr="true">background-color:white;</string>
+ <string notr="true"/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
@@ -75,13 +75,13 @@ background-image:url(:/actions/botguy_wifi3.png);
<widget class="QLabel" name="ui_ssidLabel">
<property name="minimumSize">
<size>
- <width>140</width>
+ <width>130</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
- <width>140</width>
+ <width>130</width>
<height>16777215</height>
</size>
</property>
@@ -103,30 +103,19 @@ background-image:url(:/actions/botguy_wifi3.png);
<property name="minimumSize">
<size>
<width>20</width>
- <height>30</height>
+ <height>22</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>20</width>
- <height>30</height>
+ <height>22</height>
</size>
</property>
<property name="styleSheet">
- <string notr="true"/>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLabel" name="ui_macLabel">
- <property name="maximumSize">
- <size>
- <width>130</width>
- <height>16777215</height>
- </size>
- </property>
- <property name="text">
- <string>00:00:00:00:00:00</string>
+ <string notr="true">QWidget{border:0px;
+background-image:url(:/actions/lock.png);
+}</string>
</property>
</widget>
</item>
@@ -143,6 +132,19 @@ background-image:url(:/actions/botguy_wifi3.png);
</property>
</spacer>
</item>
+ <item>
+ <widget class="QLabel" name="ui_accessPointLabel">
+ <property name="maximumSize">
+ <size>
+ <width>130</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>00:00:00:00:00:00</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
<resources/>
View
4 filesystem/ext2/files/wifi/wifi_connected.pl
@@ -6,7 +6,7 @@
my $auth = $ARGV[0] || "";
-my $timeout = 4;
+my $timeout = 1;
my $i = 0;
my $AccessPt = 0;
my $SSID = 0;
@@ -36,7 +36,7 @@
{ print $SSID; exit 0; }
}
++$i;
- sleep( 1 );
+# sleep( 1 );
}
exit 1;
View
13 filesystem/ext2/files/wifi/wifi_macAddr
@@ -0,0 +1,13 @@
+#!/usr/bin/perl
+
+my $iface = `cat /proc/net/wireless | sed -n 3p`;
+$iface = substr $iface, 0, index($iface,':');
+
+# parses ifconfig to spit out the Mac Address of the device
+my $ifconfig = `ifconfig $iface`;
+my $hwaddr = substr $ifconfig, (index($ifconfig,"HWaddr") + 7), 17;
+if( $hwaddr eq "" )
+{ exit 1; }
+
+print $hwaddr;
+exit 0;
View
50 filesystem/ext2/files/wifi/wifi_scan.pl
@@ -11,19 +11,59 @@
`ifconfig $iface up`;
# scan for local nets first
-`iwlist $iface scan`;
+my $scan = `iwlist $iface scan`;
+$scan =~ s/\n//g;
+$scan =~ s/\t/ /g;
+$scan =~ s/ */ /g;
+$scan =~ s/Cell/\n/g;
# survey the local net connections
-my $survey = `iwpriv $iface get_site_survey | awk 'FNR>2' | sed 's/\t/ /g' | sed 's/ */ /g'`;
+my @survey = split( '\n', `iwpriv $iface get_site_survey | awk 'FNR>2' | sed 's/\t/ /g' | sed 's/ */ /g'` );
+# remove the last blank element
+pop @survey;
# check for available connections
-if( $survey eq ""){ unlink $ssidFile; exit 1; }
+if( @survey == 0 ){ unlink $ssidFile; exit 1; }
+
+foreach my $val (@survey)
+{
+ my @data = split / /, $val;
+ push @data, getQuality( $data[2], $scan );
+ push @data, getTxRates( $data[2], $scan );
+ $val = join(" " ,@data);
+}
# write the list of ssids to a file
-chomp( $survey );
open( F, ">$ssidFile" );
-print F $survey;
+foreach my $ssid (@survey)
+{
+ print F $ssid,"\n";
+}
close( F );
exit 0;
+
+sub getTxRates
+{
+ my ( $ssid, $scanData ) = @_;
+
+ my $ssidPos = index($scanData, $ssid);
+ my $rateStartPos = index($scanData,"Rates",$ssidPos) + 6;
+ my $qualityPos = index($scanData,"Quality",$rateStartPos);
+ my $rates = substr $scanData, $rateStartPos, ($qualityPos - $rateStartPos);
+ $rates =~ s/ /; /g;
+ $rates =~ s/ //g;
+ return $rates;
+}
+
+sub getQuality
+{
+ my ( $ssid, $scanData ) = @_;
+
+ my $ssidPos = index($scanData, $ssid);
+ my $qualityStartPos = index($scanData, "Quality", $ssidPos) + 8;
+ my $slashPos = index($scanData, '/', $qualityStartPos);
+ my $quality = substr $scanData, $qualityStartPos, ($slashPos - $qualityStartPos);
+ return $quality;
+}
View
64 filesystem/ext2/files/wifi/wifi_start.pl
@@ -8,29 +8,35 @@
# check for network config file
if( ! -e $cbcNetConfig )
-{ print "Network config file not found\n"; exit 1; }
+{ print "Network config file not found\n"; exit 3; }
# check for a connected device
if( $iface eq "" )
-{ print "Network device not connected\n"; $netConfig{'ssid'}=""; errorExit(); }
+{ print "Network device not connected\n"; exit 2; }
# read in the network configuration file
%netConfig = split(/[=\n]/, `cat $cbcNetConfig`);
#foreach my $var (keys %netConfig)
#{ print "$var: $netConfig{$var}"; }
-if( $netConfig{'ssid'} eq `/mnt/kiss/wifi/wifi_connected.pl` )
-{ print "Already connected to:$netConfig{'ssid'}"; exit 0; }
+# bring down the wifi
+system( "ifconfig $iface down" );
+
+# kill the ssh daemon
+system( "killall ssh 2>&1" );
if( ! defined( $netConfig{'type'} ) )
{ $netConfig{'type'} = "wlan"; }
+sleep( 1 );
+
# bring up the network device
system( "ifconfig $iface up" );
-# kill the ssh daemon
-system( "killall ssh 2>&1" );
+# be sure to scan for new networks, apparently the wireless system
+# needs to do this before connecting to a new network
+system( "iwlist $iface scan 2>&1" );
if( $netConfig{'allocation'} eq "dhcp" )
{
@@ -49,13 +55,13 @@
#print "setup Static network\n";
# setup static allocation
if( ! defined( $netConfig{'ip'} ) )
- { print "Static IP not set\n"; errorExit(); }
+ { print "Static IP not set\n"; exit 3; }
if( ! defined( $netConfig{'netmask'} ) )
- { print "Static Netmask not set\n"; errorExit(); }
+ { print "Static Netmask not set\n"; exit 3; }
if( ! defined( $netConfig{'gateway'} ) )
- { print "Static Gateway not set\n"; errorExit(); }
+ { print "Static Gateway not set\n"; exit 3; }
system( "ifconfig $iface $netConfig{'ip'} netmask $netConfig{'netmask'}" );
@@ -78,20 +84,29 @@
}
}
-if( ! defined( $netConfig{'txrate'} ) )
-{ $netConfig{'txrate'} = 6; }
+# setup Adhoc or Managed Infra networks
+if( $netConfig{'netType'} eq "Adhoc" )
+{ system( "iwconfig $iface mode Ad-Hoc" ); }
+else
+{ system( "iwconfig $iface mode Managed" ); }
+
+# set the Bit rate transmission speed
+if( $netConfig{'txrate'} eq "" )
+{ $netConfig{'txrate'} = "9Mb/s"; }
+system( "iwconfig $iface rate $netConfig{'txrate'}" );
-system( "iwpriv $iface set TxRate=$netConfig{'txrate'}" );
system( "iwpriv $iface set AuthMode=$netConfig{'auth'}" );
system( "iwpriv $iface set SSID=$netConfig{'ssid'}" );
+sleep( 1 );
#print "check auth is WPA or WEP\n";
if( ( $netConfig{'auth'} eq "WPAPSK" ) || ( $netConfig{'auth'} eq "WPA2PSK" ) )
{
#print "auth is WPA\n";
system( "iwpriv $iface set WPAPSK=$netConfig{'key'}" );
system( "iwpriv $iface set SSID=$netConfig{'ssid'}" );
-
+ sleep( 1 );
+
#print "determine encryption type\n";
my $count = 1;
@@ -102,7 +117,8 @@
ENCRYP:
system( "iwpriv $iface set EncrypType=$netConfig{'encryption'}" );
system( "iwpriv $iface set SSID=$netConfig{'ssid'}" );
-
+ sleep( 1 );
+
if( $netConfig{'ssid'} ne `/mnt/kiss/wifi/wifi_connected.pl` )
{
#print "encryption failed\n";
@@ -116,8 +132,7 @@
goto ENCRYP;
}else{
print "Could not determine Encryption\n";
- $netConfig{'ssid'}="";
- errorExit();
+ exit 3;
}
}
}
@@ -130,6 +145,13 @@
{ determineWepKey( ); }
system( "iwpriv $iface set Key1=$netConfig{'key'}" );
system( "iwpriv $iface set SSID=$netConfig{'ssid'}" );
+ sleep( 1 );
+}
+else
+{
+ system( "iwpriv $iface set EncrypType=$netConfig{'encryption'}" );
+ system( "iwpriv $iface set SSID=$netConfig{'ssid'}" );
+ sleep( 1 );
}
if( $netConfig{'ssid'} eq `/mnt/kiss/wifi/wifi_connected.pl` )
@@ -138,7 +160,7 @@
{
system( "udhcpc -t 5 -n -p /var/run/udhcpc.$iface.pid -i $iface" );
my $IP = `/mnt/kiss/wifi/wifi_ip.pl $iface`;
- if( $IP eq "" ) { print "IP not allocated"; $netConfig{'ip'}=""; errorExit(); }
+ if( $IP eq "" ) { print "IP not allocated"; exit 3; }
$netConfig{'ip'} = $IP;
}
# start the ssh daemon
@@ -150,13 +172,7 @@
}
print "Not connected\n";
-errorExit();
-
-sub errorExit
-{
- writeConfigFile();
- exit 1;
-}
+exit 3;
sub writeConfigFile
{

0 comments on commit 4c63cfc

Please sign in to comment.