summaryrefslogtreecommitdiff
authorskyhusker <skyhusker>2005-04-20 10:25:20 (UTC)
committer skyhusker <skyhusker>2005-04-20 10:25:20 (UTC)
commite439d0e6eaa6704a8b1b89ea32aa8a0520738a04 (patch) (unidiff)
tree18c8b1eba5e1836f757765e4204d638500aa79f2
parentf6b9c85c09692f298ffa5ee95e1f171a9e158502 (diff)
downloadopie-e439d0e6eaa6704a8b1b89ea32aa8a0520738a04.zip
opie-e439d0e6eaa6704a8b1b89ea32aa8a0520738a04.tar.gz
opie-e439d0e6eaa6704a8b1b89ea32aa8a0520738a04.tar.bz2
First commit of OpieStumbler, an application which performs wireless networks scanning using Wireless Extensions
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opiestumbler/config.in4
-rw-r--r--noncore/net/opiestumbler/main.cpp6
-rw-r--r--noncore/net/opiestumbler/opiestumbler.cpp348
-rw-r--r--noncore/net/opiestumbler/opiestumbler.h70
-rw-r--r--noncore/net/opiestumbler/opiestumbler.pro18
-rw-r--r--noncore/net/opiestumbler/stationinfo.cpp63
-rw-r--r--noncore/net/opiestumbler/stationinfo.h42
-rw-r--r--noncore/net/opiestumbler/stationviewitem.cpp52
-rw-r--r--noncore/net/opiestumbler/stationviewitem.h26
-rw-r--r--noncore/net/opiestumbler/stumbler.cpp80
-rw-r--r--noncore/net/opiestumbler/stumbler.h38
-rw-r--r--noncore/net/opiestumbler/stumblersettings.cpp35
-rw-r--r--noncore/net/opiestumbler/stumblersettings.h22
-rw-r--r--noncore/net/opiestumbler/stumblerstation.cpp21
-rw-r--r--noncore/net/opiestumbler/stumblerstation.h18
15 files changed, 843 insertions, 0 deletions
diff --git a/noncore/net/opiestumbler/config.in b/noncore/net/opiestumbler/config.in
new file mode 100644
index 0000000..88cdacf
--- a/dev/null
+++ b/noncore/net/opiestumbler/config.in
@@ -0,0 +1,4 @@
1 config OPIESTUMBLER
2 boolean "opie-stumbler (find wireless networks)"
3 default "y"
4 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBOPIE2NET && LIBOPIE2UI
diff --git a/noncore/net/opiestumbler/main.cpp b/noncore/net/opiestumbler/main.cpp
new file mode 100644
index 0000000..5b5770d
--- a/dev/null
+++ b/noncore/net/opiestumbler/main.cpp
@@ -0,0 +1,6 @@
1#include "opiestumbler.h"
2
3#include <opie2/oapplicationfactory.h>
4
5using namespace Opie::Core;
6OPIE_EXPORT_APP_V2( OApplicationFactory<OpieStumbler>, "OpieStumbler" )
diff --git a/noncore/net/opiestumbler/opiestumbler.cpp b/noncore/net/opiestumbler/opiestumbler.cpp
new file mode 100644
index 0000000..8dedd67
--- a/dev/null
+++ b/noncore/net/opiestumbler/opiestumbler.cpp
@@ -0,0 +1,348 @@
1#include <cstdlib>
2
3#include <qmenubar.h>
4#include <qaction.h>
5#include <qlistview.h>
6#include <qstring.h>
7//#include <qapplication.h>
8#include <qdatetime.h>
9#include <qpopupmenu.h>
10#include <qstatusbar.h>
11#include <qlayout.h>
12#include <qwhatsthis.h>
13#include <qtimer.h>
14
15#include <qpe/resource.h>
16#include <qpe/config.h>
17//#include <qpe/global.h>
18#include <qpe/qcopenvelope_qws.h>
19#include <qpe/qpeapplication.h>
20
21#include <opie2/odebug.h>
22#include <opie2/ostation.h>
23#include <opie2/omanufacturerdb.h>
24#include <opie2/onetwork.h>
25#include <opie2/oprocess.h>
26
27#include "stumbler.h"
28#include "opiestumbler.h"
29#include "stumblersettings.h"
30#include "stationviewitem.h"
31#include "stumblerstation.h"
32#include "stationinfo.h"
33
34
35using Opie::Net::OWirelessNetworkInterface;
36using Opie::Net::ONetwork;
37
38
39QString OpieStumbler::appCaption() {
40 return QObject::tr("OpieStumbler");
41}
42
43OpieStumbler::OpieStumbler(QWidget *parent, const char *name, WFlags)
44 :QMainWindow(parent, name, WStyle_ContextHelp),
45 m_listCurrent(new QListView(this)), m_listHistory(new QListView(this)),
46 m_stationsCurrent(new QList<Opie::Net::OStation>),
47 m_popupCurrent(new QPopupMenu(this)),
48 m_popupHistory(new QPopupMenu(this)),
49 m_db(NULL), m_proc(NULL)
50{
51
52 if ( QCopChannel::isRegistered("QPE/OpieStumbler") ) {
53 QCopEnvelope e("QPE/OpieStumbler", "show()");
54 exit(EXIT_SUCCESS);
55 }
56
57 QGridLayout *grid = new QGridLayout( this, 1, 1, 3, 0, "grid");
58 QVBoxLayout *lay = new QVBoxLayout( NULL, 0, 5, "lay" );
59 QSpacerItem *spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Fixed );
60 lay->addItem(spacer);
61 lay->addWidget(m_listCurrent);
62 lay->addWidget(m_listHistory);
63 grid->addLayout(lay, 0, 0);
64
65 m_stationsCurrent->setAutoDelete(TRUE);
66
67 m_channel = new QCopChannel( "QPE/OpieStumbler", this );
68 connect(m_channel, SIGNAL(received(const QCString &, const QByteArray &)),
69 this, SLOT(slotMessageReceived( const QCString &, const QByteArray &)) );
70
71 //setCaption(appCaption());
72 //setCentralWidget(grid);
73 setToolBarsMovable(FALSE);
74
75
76 QPopupMenu *fileMenu = new QPopupMenu(this);
77 QPopupMenu *configMenu = new QPopupMenu(this);
78 QPopupMenu *scanMenu = new QPopupMenu(this);
79
80 fileMenu->insertItem( tr("Exit"), this, SLOT(close()) );
81 configMenu->insertItem( tr("Configure"), this, SLOT(slotConfigure()) );
82 scanMenu->insertItem( tr("Start"), this, SLOT(slotStartScanning()) );
83 scanMenu->insertItem( tr("Stop"), this, SLOT(slotStopScanning()) );
84
85 m_popupCurrent->insertItem( tr("Show details"), this, SLOT(slotShowDetails()) );
86 m_popupCurrent->insertItem( tr("Join Network"), this, SLOT(slotJoinNetwork()) );
87
88 menuBar()->insertItem(tr("File"), fileMenu);
89 menuBar()->insertItem(tr("Settings"), configMenu);
90 menuBar()->insertItem(tr("Scanning"), scanMenu);
91
92 QPEApplication::setStylusOperation(m_listCurrent->viewport(), QPEApplication::RightOnHold);
93 QPEApplication::setStylusOperation(m_listHistory->viewport(), QPEApplication::RightOnHold);
94
95 m_listCurrent->addColumn(tr("SSID"));
96 m_listCurrent->addColumn(tr("Chan"));
97 m_listCurrent->addColumn(tr("Signal"));
98 m_listCurrent->addColumn(tr("Enc"));
99 m_listCurrent->setSelectionMode( QListView::Extended );
100
101 m_listHistory->addColumn(tr("SSID"));
102 m_listHistory->addColumn(tr("Chan"));
103 m_listHistory->addColumn(tr("Max Sig"));
104 m_listHistory->addColumn(tr("Enc"));
105 m_listHistory->addColumn(tr("Vendor"));
106
107 connect(m_listCurrent, SIGNAL(mouseButtonPressed (int, QListViewItem*, const QPoint&, int)),
108 this, SLOT(slotCurrentMousePressed (int, QListViewItem*, const QPoint&, int)));
109
110 connect(m_listHistory, SIGNAL(mouseButtonPressed (int, QListViewItem*, const QPoint&, int)),
111 this, SLOT(slotHistoryMousePressed (int, QListViewItem*, const QPoint&, int)));
112
113 for(int i = CURCHAN; i <= CURENC; ++i) {
114 m_listCurrent->setColumnAlignment( i, Qt::AlignHCenter );
115 m_listHistory->setColumnAlignment( i, Qt::AlignHCenter );
116 }
117
118 loadConfig();
119 m_stumbler = new Stumbler(m_interface, this);
120 connect(m_stumbler, SIGNAL(newdata()), this, SLOT(slotUpdateStations()));
121
122 QTimer::singleShot(1000, this, SLOT(slotLoadManufacturers()) );
123
124 slotStartScanning();
125}
126
127void OpieStumbler::slotConfigure()
128{
129 StumblerSettings settings(this, "Settings", TRUE);
130 if (settings.exec() == QDialog::Accepted)
131 loadConfig();
132}
133
134void OpieStumbler::loadConfig()
135{
136 Config cfg("OpieStumbler", Config::User);
137 cfg.setGroup("General");
138 m_interface = cfg.readEntry("interface", "wlan0");
139}
140
141void OpieStumbler::slotStartScanning()
142{
143 setCaption(appCaption() + " (" + tr("Scanning") + ")");
144 m_stumbler->start();
145}
146
147void OpieStumbler::slotStopScanning()
148{
149 setCaption(appCaption());
150 m_stumbler->stop();
151}
152
153void OpieStumbler::slotUpdateStations()
154{
155 m_stationsCurrent->clear();
156
157 m_stationsCurrent = m_stumbler->stations();
158 if (m_stationsCurrent) {
159 QListIterator<Opie::Net::OStation> it(*m_stationsCurrent);
160 for(; it.current(); ++it) {
161 Opie::Net::OStation *station = it.current();
162 QListIterator<StumblerStation> itr(m_stationsHistory);
163 for( ; itr.current(); ++itr) {
164 if (itr.current()->st->macAddress.toString() == station->macAddress.toString()) {
165 break;
166 }
167 }
168 if (!itr.current()) {
169 //We need to copy the date because m_statiosCurrent has autodelete enabled
170 m_stationsHistory.append(new StumblerStation(new Opie::Net::OStation, QDateTime::currentDateTime()));
171 *(m_stationsHistory.last()->st) = (*station);
172 }
173 else {
174 if ( itr.current()->st->level < station->level )
175 itr.current()->st->level = station->level;
176
177 itr.current()->lastTimeSeen = QDateTime::currentDateTime();
178 }
179 }
180 }
181 displayStations();
182}
183
184void OpieStumbler::displayStations()
185{
186 m_listCurrent->clear();
187 for(QListIterator<Opie::Net::OStation> it(*m_stationsCurrent); it.current(); ++it)
188 new StationViewItem( m_listCurrent, it.current()->ssid, QString::number(it.current()->channel),
189 QString::number(it.current()->level), it.current()->encrypted ? "Y": "N", it.current()->macAddress.toString() );
190
191 m_listHistory->clear();
192 for(QListIterator<StumblerStation> it(m_stationsHistory); it.current(); ++it)
193 new StationViewItem( m_listHistory, it.current()->st->ssid, QString::number(it.current()->st->channel),
194 QString::number(it.current()->st->level), it.current()->st->encrypted ? "Y": "N",
195 manufacturer(it.current()->st->macAddress.toString()), it.current()->st->macAddress.toString() );
196}
197
198void OpieStumbler::slotMessageReceived( const QCString &message, const QByteArray &parameters)
199{
200 Q_UNUSED(const_cast<QByteArray &>(parameters))
201
202 if ( message == "show()" )
203 show();
204}
205
206void OpieStumbler::slotCurrentMousePressed(int button, QListViewItem * item, const QPoint &point, int c)
207{
208 Q_UNUSED(c)
209
210 if ( 2 == button ) {
211 m_mac = item->text(CURENC + 1);
212 m_popupCurrent->popup(point);
213 }
214}
215
216
217void OpieStumbler::slotHistoryMousePressed(int button, QListViewItem * item, const QPoint &point, int c)
218{
219 Q_UNUSED(c)
220
221 if ( 2 == button ) {
222 m_mac = item->text(HISVENDOR + 1);
223 m_popupHistory->popup(point);
224 }
225}
226
227void OpieStumbler::slotShowDetails()
228{
229 QListIterator<StumblerStation> it(m_stationsHistory);
230 for(; it.current() && it.current()->st->macAddress.toString() != m_mac; ++it );
231
232 if( it.current() ) {
233 StationInfo info(it.current()->st->ssid, it.current()->st->type, QString::number(it.current()->st->channel),
234 QString::number(it.current()->st->rates.last()/1000000), QString::number(it.current()->st->level),
235 it.current()->st->encrypted ? "WEP": "No",
236 it.current()->st->macAddress.toString(), manufacturer(it.current()->st->macAddress.toString(), TRUE),
237 it.current()->lastTimeSeen.toString() ,this, "", TRUE);
238 info.exec();
239 }
240
241}
242
243void OpieStumbler::slotLoadManufacturers()
244{
245 m_db = Opie::Net::OManufacturerDB::instance();
246}
247
248QString OpieStumbler::manufacturer( const QString &mac, bool extended )
249{
250 QString retval;
251 if ( m_db )
252 if ( extended )
253 retval = m_db->lookupExt(mac);
254 else
255 retval = m_db->lookup(mac);
256
257 if ( retval.isEmpty() )
258 retval = tr("Unknown");
259
260 return retval;
261}
262
263void OpieStumbler::slotJoinNetwork()
264{
265 slotStopScanning();
266
267 OWirelessNetworkInterface *wiface = static_cast<OWirelessNetworkInterface*>(ONetwork::instance()->interface(m_interface));
268
269 if( !wiface )
270 return;
271
272 QListIterator<StumblerStation> it(m_stationsHistory);
273
274 for(; it.current() && it.current()->st->macAddress.toString() != m_mac; ++it );
275
276 if( !it.current() )
277 return;
278
279 Opie::Net::OStation *station = it.current()->st;
280
281 odebug << "Bringing interface down" << oendl;
282 wiface->setUp(FALSE);
283
284 odebug << "Setting mode to " << (station->type == "adhoc" ? "adhoc" : "managed") << oendl;
285 wiface->setMode(station->type == "adhoc" ? "adhoc" : "managed" );
286
287 odebug << "Setting channel to " << station->channel << oendl;
288 wiface->setChannel(station->channel);
289
290 odebug << "Setting SSID to " << station->ssid << oendl;
291 wiface->setSSID(station->ssid);
292
293 wiface->commit();
294
295 odebug << "Bringing interface up" << oendl;
296 wiface->setUp(TRUE);
297 //Wait 5 sec for association
298 QTimer::singleShot(5000, this, SLOT(slotAssociated()));
299}
300
301void OpieStumbler::slotAssociated()
302{
303 OWirelessNetworkInterface *wiface = static_cast<OWirelessNetworkInterface*>(ONetwork::instance()->interface(m_interface));
304
305 if( !wiface )
306 return;
307
308 if (!wiface->isAssociated()) {
309 Global::statusMessage(tr("Could not Join"));
310 return;
311 }
312
313 Global::statusMessage(tr("Joined"));
314
315 if(m_proc) {
316 m_proc->kill();
317 delete m_proc;
318 }
319
320 m_proc = new Opie::Core::OProcess(this);
321
322 *m_proc << "udhcpc" << "-f" << "-n" << "-i" << m_interface;
323 m_proc->start(Opie::Core::OProcess::DontCare);
324 QTimer::singleShot(5000, this, SLOT(slotCheckDHCP()));
325}
326
327void OpieStumbler::slotCheckDHCP()
328{
329 if(!m_proc->isRunning()) {
330 Global::statusMessage(tr("Could not Obtain an Address"));
331 delete m_proc;
332 m_proc = NULL;
333 return;
334 }
335 m_listCurrent->show();
336
337
338 OWirelessNetworkInterface *wiface = static_cast<OWirelessNetworkInterface*>(ONetwork::instance()->interface(m_interface));
339 Global::statusMessage(tr("Obtained IP ") + wiface->ipV4Address());
340}
341
342
343
344
345
346
347
348
diff --git a/noncore/net/opiestumbler/opiestumbler.h b/noncore/net/opiestumbler/opiestumbler.h
new file mode 100644
index 0000000..3f45a78
--- a/dev/null
+++ b/noncore/net/opiestumbler/opiestumbler.h
@@ -0,0 +1,70 @@
1#ifndef OPIESTUMBLER_H
2#define OPIESTUMBLER_H
3
4#include <qmainwindow.h>
5#include <qlist.h>
6
7#include "stumblerstation.h"
8
9class QString;
10class QPopupMenu;
11class Stumbler;
12class QCopChannel;
13class QListView;
14class QListViewItem;
15
16namespace Opie{
17 namespace Net {
18 class OMacAddress;
19 class OStation;
20 class OManufacturerDB;
21 }
22
23 namespace Core {
24 class OProcess;
25 }
26}
27
28
29class OpieStumbler: public QMainWindow {
30 Q_OBJECT
31public:
32
33 enum CurrentColumns { CURSSID, CURCHAN, CURSIGNAL, CURENC };
34 enum HistoryColumns { HISSSID, HISCHAN, HISSIGNAL, HISENC, HISVENDOR };
35 OpieStumbler(QWidget *parent = 0, const char *name = 0, WFlags f = 0);
36 static QString appName() { return QString::fromLatin1("opiestumbler"); }
37 static QString appCaption();
38 void displayStations();
39 QString manufacturer(const QString &mac, bool extended = FALSE );
40protected slots:
41 void slotConfigure();
42 void slotStartScanning();
43 void slotStopScanning();
44 void slotUpdateStations();
45 void slotMessageReceived( const QCString &, const QByteArray & );
46 void slotCurrentMousePressed(int button, QListViewItem *item, const QPoint &point, int c);
47 void slotHistoryMousePressed(int button, QListViewItem *item, const QPoint &point, int c);
48 void slotShowDetails();
49 void slotLoadManufacturers();
50 void slotJoinNetwork();
51 void slotAssociated();
52 void slotCheckDHCP();
53protected:
54 void loadConfig();
55 QListView *m_listCurrent;
56 QListView *m_listHistory;
57 QString m_interface;
58 Stumbler *m_stumbler;
59 QCopChannel *m_channel;
60 QList <Opie::Net::OStation> *m_stationsCurrent;
61 QList <StumblerStation> m_stationsHistory;
62 QPopupMenu *m_popupCurrent;
63 QPopupMenu *m_popupHistory;
64 Opie::Net::OManufacturerDB *m_db;
65 QString m_mac;
66 Opie::Core::OProcess *m_proc;
67
68};
69
70#endif /* OPIESTUMBLER_H */
diff --git a/noncore/net/opiestumbler/opiestumbler.pro b/noncore/net/opiestumbler/opiestumbler.pro
new file mode 100644
index 0000000..a23bd51
--- a/dev/null
+++ b/noncore/net/opiestumbler/opiestumbler.pro
@@ -0,0 +1,18 @@
1TEMPLATE = app
2CONFIG += qte warn_on quick-app debug
3HEADERS = opiestumbler.h stumblersettings.h stumbler.h \
4 stationviewitem.h stumblerstation.h stationinfo.h
5SOURCES = opiestumbler.cpp stumblersettings.cpp stumbler.cpp \
6 main.cpp stationviewitem.cpp stumblerstation.cpp \
7 stationinfo.cpp
8TARGET = opiestumbler
9INCLUDEPATH += $(OPIEDIR)/include
10DEPENDPATH += $(OPIEDIR)/include
11LIBS += -lqpe -lqte -lopiecore2 -lopieui2 -lopienet2
12
13!contains(CONFIG,quick-app) {
14 DESTDIR = $(OPIEDIR)/bin
15 DEFINES += NOQUICKLAUNCH
16}
17
18include( $(OPIEDIR)/include.pro )
diff --git a/noncore/net/opiestumbler/stationinfo.cpp b/noncore/net/opiestumbler/stationinfo.cpp
new file mode 100644
index 0000000..926610e
--- a/dev/null
+++ b/noncore/net/opiestumbler/stationinfo.cpp
@@ -0,0 +1,63 @@
1#include <qlayout.h>
2#include <qgroupbox.h>
3
4
5#include "stationinfo.h"
6
7
8StationInfo::StationInfo( const QString &ssid, const QString &type, const QString &channel,
9 const QString &maxrate, const QString &level, const QString &encryption, const QString &address,
10 const QString &vendor, const QString &time,
11 QWidget *parent, const char *name, bool modal, WFlags f)
12 : QDialog( parent, name, modal, f)
13{
14 setCaption(tr("Station Details"));
15
16 QGridLayout *grid = new QGridLayout( this, 1, 2, 5);
17 QVBoxLayout *layLeft = new QVBoxLayout(0, 0, 6);
18 QVBoxLayout *layRight = new QVBoxLayout(0, 0, 6);
19
20
21 m_ssidLabel = new QLabel( tr("SSID:"), this );
22 layLeft->addWidget(m_ssidLabel);
23 m_typeLabel = new QLabel( tr("Type:"), this );
24 layLeft->addWidget(m_typeLabel);
25 m_channelLabel = new QLabel( tr("Channel:"), this );
26 layLeft->addWidget(m_channelLabel);
27 m_maxRateLabel = new QLabel( tr("Max Rate"), this );
28 layLeft->addWidget(m_maxRateLabel);
29 m_levelLabel = new QLabel( tr("Max Signal:"), this );
30 layLeft->addWidget(m_levelLabel);
31 m_encLabel = new QLabel( tr("Encryption:"), this );
32 layLeft->addWidget(m_encLabel);
33 m_addrLabel = new QLabel( tr("Address:"), this );
34 layLeft->addWidget(m_addrLabel);
35 m_vendorLabel = new QLabel( tr("Vendor:"), this );
36 layLeft->addWidget(m_vendorLabel);
37 m_timeLabel = new QLabel( tr("Last Time Seen:"), this );
38 layLeft->addWidget(m_timeLabel);
39
40
41 m_ssid = new QLabel( ssid, this);
42 layRight->addWidget(m_ssid);
43 m_type = new QLabel( type, this);
44 layRight->addWidget(m_type);
45 m_channel = new QLabel( channel, this);
46 layRight->addWidget(m_channel);
47 m_maxRate = new QLabel( maxrate + " " + tr("Mb/s"), this );
48 layRight->addWidget( m_maxRate );
49 m_level = new QLabel( level, this);
50 layRight->addWidget(m_level);
51 m_encryption = new QLabel( encryption, this);
52 layRight->addWidget(m_encryption);
53 m_address = new QLabel( address, this);
54 layRight->addWidget(m_address);
55 m_vendor = new QLabel( vendor, this);
56 layRight->addWidget(m_vendor);
57 m_lastTime = new QLabel( time, this);
58 layRight->addWidget(m_lastTime);
59
60
61 grid->addLayout( layRight, 0, 1);
62 grid->addLayout( layLeft, 0, 0 );
63}
diff --git a/noncore/net/opiestumbler/stationinfo.h b/noncore/net/opiestumbler/stationinfo.h
new file mode 100644
index 0000000..f8798a6
--- a/dev/null
+++ b/noncore/net/opiestumbler/stationinfo.h
@@ -0,0 +1,42 @@
1#ifndef STATIONINFO_H
2#define STATIONINFO_H
3
4#include <qdialog.h>
5#include <qlabel.h>
6
7class QWidget;
8class QString;
9class QGroupBox;
10
11class StationInfo: public QDialog
12{
13 Q_OBJECT
14
15public:
16 StationInfo( const QString &essid, const QString &type, const QString &channel,
17 const QString &maxrate, const QString &level, const QString &encryption, const QString &address,
18 const QString &vendor, const QString &time,
19 QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
20
21protected:
22 QLabel *m_ssidLabel;
23 QLabel *m_typeLabel;
24 QLabel *m_channelLabel;
25 QLabel *m_maxRateLabel;
26 QLabel *m_levelLabel;
27 QLabel *m_encLabel;
28 QLabel *m_addrLabel;
29 QLabel *m_vendorLabel;
30 QLabel *m_timeLabel;
31 QLabel *m_ssid;
32 QLabel *m_type;
33 QLabel *m_channel;
34 QLabel *m_maxRate;
35 QLabel *m_level;
36 QLabel *m_encryption;
37 QLabel *m_address;
38 QLabel *m_vendor;
39 QLabel *m_lastTime;
40};
41
42#endif
diff --git a/noncore/net/opiestumbler/stationviewitem.cpp b/noncore/net/opiestumbler/stationviewitem.cpp
new file mode 100644
index 0000000..64223d7
--- a/dev/null
+++ b/noncore/net/opiestumbler/stationviewitem.cpp
@@ -0,0 +1,52 @@
1#include <qpalette.h>
2#include <qcolor.h>
3
4
5#include "stationviewitem.h"
6#include "opiestumbler.h"
7
8StationViewItem::StationViewItem( QListView *parent, const QString &ssid,
9 const QString &channel, const QString &level, const QString &enc,
10 const QString &mac )
11 : QListViewItem( parent, ssid, channel, level, enc, mac )
12{
13}
14
15StationViewItem::StationViewItem( QListView *parent, const QString &ssid,
16 const QString &channel, const QString &level, const QString &enc,
17 const QString &vendor, const QString &mac )
18
19: QListViewItem( parent, ssid, channel, level, enc, vendor, mac )
20{
21}
22
23void StationViewItem::paintCell( QPainter *p, const QColorGroup &cg,
24 int column, int width, int alignment )
25{
26 QColor c;
27 QColorGroup ch(cg);
28
29 if ( column == OpieStumbler::CURSIGNAL ) {
30 int value = text(column).toInt();
31 if ( value < 20 )
32 c.setRgb(255, 0, 0);
33 else if ( value < 35 )
34 c.setRgb(255, 255, 0);
35 else if ( value < 60 )
36 c.setRgb(0, 255, 0);
37 else
38 c.setRgb(0, 0, 255);
39 ch.setColor( QColorGroup::Text, c );
40 }
41
42 if ( column == OpieStumbler::CURSSID ) {
43 if ( text(OpieStumbler::CURENC) == "Y" )
44 c.setRgb(255, 0, 0);
45 else
46 c.setRgb(0, 255, 0);
47 ch.setColor( QColorGroup::Text, c );
48 }
49
50 QListViewItem::paintCell( p, ch, column, width, alignment );
51}
52
diff --git a/noncore/net/opiestumbler/stationviewitem.h b/noncore/net/opiestumbler/stationviewitem.h
new file mode 100644
index 0000000..48e74d5
--- a/dev/null
+++ b/noncore/net/opiestumbler/stationviewitem.h
@@ -0,0 +1,26 @@
1#ifndef STATIONVIEWITEM_H
2#define STATIONVIEWITEM_H
3
4#include <qlistview.h>
5
6
7class QString;
8class QPainter;
9class QColorGroup;
10class QColor;
11
12class StationViewItem: public QListViewItem
13{
14public:
15 StationViewItem( QListView *parent, const QString &ssid, const QString &channel,
16 const QString &level, const QString &enc, const QString &mac );
17 StationViewItem( QListView *parent, const QString &ssid, const QString &channel,
18 const QString &level, const QString &enc, const QString &vendor,
19 const QString &mac );
20
21 virtual void paintCell( QPainter *p, const QColorGroup &cg,
22 int column, int width, int alignment );
23};
24
25#endif
26
diff --git a/noncore/net/opiestumbler/stumbler.cpp b/noncore/net/opiestumbler/stumbler.cpp
new file mode 100644
index 0000000..cda6b99
--- a/dev/null
+++ b/noncore/net/opiestumbler/stumbler.cpp
@@ -0,0 +1,80 @@
1#include <qstring.h>
2#include <qtimer.h>
3#include <qapplication.h>
4
5//#include <opie2/onetutils.h>
6#include <opie2/onetwork.h>
7#include <opie2/odebug.h>
8
9#include "stumbler.h"
10
11using namespace Opie::Net;
12
13Stumbler::Stumbler(const QString &iface, QObject *parent, const char *name)
14 :QObject(parent, name), m_interval(5000),
15 m_wifaceName(iface),
16 m_timer(new QTimer(this))
17{
18 m_wiface = static_cast<OWirelessNetworkInterface*>(ONetwork::instance()->interface(m_wifaceName));
19 connect(m_timer, SIGNAL(timeout()), this, SLOT(slotRefresh()));
20}
21
22
23void Stumbler::start()
24{
25 if (!m_wiface) {
26 odebug << "Error, interface " << m_wifaceName << " does not exist" << oendl;
27 return;
28 }
29
30 if (!ONetwork::instance()->isWirelessInterface(m_wifaceName.ascii())) {
31 odebug << "Error, " << m_wifaceName << " is not a wireless interface" << oendl;
32 //FIXME: Tell the user about this
33 return;
34 }
35
36 if (!m_timer->isActive()) {
37 odebug << "Starting stumbler" << oendl;
38 m_wiface->setUp(FALSE);
39 m_wiface->setSSID("any");
40 m_wiface->setAssociatedAP( OMacAddress::broadcast );
41 m_wiface->setUp(TRUE);
42 m_timer->start(m_interval);
43 }
44}
45
46void Stumbler::stop()
47{
48 if (m_timer->isActive()) {
49 odebug << "Stoping stumbler" << oendl;
50 m_timer->stop();
51 }
52}
53
54void Stumbler::setInterval(int msec)
55{
56 m_interval = msec;
57 if (m_timer->isActive()) {
58 m_timer->stop();
59 m_timer->start(m_interval);
60 }
61}
62
63void Stumbler::setIface(const QString &iface)
64{
65 m_wifaceName = iface;
66 m_wiface = static_cast<OWirelessNetworkInterface*>(ONetwork::instance()->interface(m_wifaceName));
67}
68
69void Stumbler::slotRefresh()
70{
71 m_stationList = m_wiface->scanNetwork();
72 if ( qApp )
73 qApp->processEvents();
74 emit (newdata());
75}
76
77Opie::Net::OStationList * Stumbler::stations()
78{
79 return m_stationList;
80}
diff --git a/noncore/net/opiestumbler/stumbler.h b/noncore/net/opiestumbler/stumbler.h
new file mode 100644
index 0000000..de50d25
--- a/dev/null
+++ b/noncore/net/opiestumbler/stumbler.h
@@ -0,0 +1,38 @@
1#ifndef STUMBLER_H
2#define STUMBLER_H
3
4#include <opie2/ostation.h>
5
6#include <qobject.h>
7
8class QString;
9class QTimer;
10namespace Opie {
11 namespace Net {
12 class OWirelessNetworkInterface;
13 }
14}
15
16class Stumbler: public QObject {
17 Q_OBJECT
18
19public:
20 Stumbler(const QString &iface, QObject *parent = 0, const char *name = 0);
21 void start();
22 void stop();
23 void setInterval(int msec);
24 void setIface(const QString &iface);
25 Opie::Net::OStationList * stations();
26signals:
27 void newdata();
28protected slots:
29 void slotRefresh();
30protected:
31 int m_interval;
32 QString m_wifaceName;
33 QTimer *m_timer;
34 Opie::Net::OWirelessNetworkInterface *m_wiface;
35 Opie::Net::OStationList *m_stationList;
36};
37
38#endif
diff --git a/noncore/net/opiestumbler/stumblersettings.cpp b/noncore/net/opiestumbler/stumblersettings.cpp
new file mode 100644
index 0000000..f033e34
--- a/dev/null
+++ b/noncore/net/opiestumbler/stumblersettings.cpp
@@ -0,0 +1,35 @@
1#include <qlineedit.h>
2#include <qlabel.h>
3#include <qlayout.h>
4
5#include <qpe/config.h>
6
7#include "stumblersettings.h"
8
9StumblerSettings::StumblerSettings(QWidget* parent, const char* name, bool modal, WFlags f)
10 : QDialog(parent, name, modal, WStyle_ContextHelp), m_config(new Config("OpieStumbler"))
11{
12 setCaption(tr("Settings"));
13 m_config->setGroup("General");
14 QBoxLayout *l = new QHBoxLayout(this);
15 QLabel *lb = new QLabel(tr("Interface"), this);
16 m_interface = new QLineEdit(this);
17 m_interface->setText(m_config->readEntry("interface", "wlan0"));
18 connect(m_interface, SIGNAL(returnPressed()), this, SLOT(accept()));
19 l->addWidget(lb);
20 l->addWidget(m_interface);
21}
22
23StumblerSettings::~StumblerSettings()
24{
25 delete m_config;
26 delete m_interface;
27}
28
29void StumblerSettings::accept()
30{
31 m_config->writeEntry("interface", m_interface->text());
32 m_config->write();
33
34 QDialog::accept();
35}
diff --git a/noncore/net/opiestumbler/stumblersettings.h b/noncore/net/opiestumbler/stumblersettings.h
new file mode 100644
index 0000000..997fc85
--- a/dev/null
+++ b/noncore/net/opiestumbler/stumblersettings.h
@@ -0,0 +1,22 @@
1#ifndef STUMBLERSETTINGS_H
2#define STUMBLERSETTINGS_H
3
4#include <qdialog.h>
5
6class Config;
7class QLineEdit;
8
9class StumblerSettings: public QDialog {
10
11public:
12 StumblerSettings(QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags f = 0);
13 ~StumblerSettings();
14
15protected slots:
16 void accept();
17protected:
18 Config *m_config;
19 QLineEdit *m_interface;
20};
21
22#endif
diff --git a/noncore/net/opiestumbler/stumblerstation.cpp b/noncore/net/opiestumbler/stumblerstation.cpp
new file mode 100644
index 0000000..36bd669
--- a/dev/null
+++ b/noncore/net/opiestumbler/stumblerstation.cpp
@@ -0,0 +1,21 @@
1#include "stumblerstation.h"
2#include <opie2/odebug.h>
3
4StumblerStation::StumblerStation(Opie::Net::OStation *station, const QDateTime &tm)
5 : st(station), lastTimeSeen(tm)
6{
7 /*odebug << "RHS: " << station->macAddress.toString() << oendl;
8 odebug << "THIS: " << st->macAddress.toString() << oendl; */
9}
10
11StumblerStation::~StumblerStation()
12{
13 if (st)
14 delete st;
15}
16
17bool StumblerStation::operator<(const StumblerStation &rhs)
18{
19 return rhs.lastTimeSeen < lastTimeSeen;
20}
21
diff --git a/noncore/net/opiestumbler/stumblerstation.h b/noncore/net/opiestumbler/stumblerstation.h
new file mode 100644
index 0000000..1532193
--- a/dev/null
+++ b/noncore/net/opiestumbler/stumblerstation.h
@@ -0,0 +1,18 @@
1#ifndef STUMBLERSTATION_H
2#define STUMBLERSTATION_H
3
4#include <opie2/ostation.h>
5
6#include <qdatetime.h>
7
8class StumblerStation
9{
10public:
11 StumblerStation(Opie::Net::OStation *station, const QDateTime &tm);
12 ~StumblerStation();
13 bool operator<(const StumblerStation &rhs);
14 Opie::Net::OStation *st;
15 QDateTime lastTimeSeen;
16};
17
18#endif