summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-03-30 01:41:56 (UTC)
committer mickeyl <mickeyl>2003-03-30 01:41:56 (UTC)
commit99899abc80a8aa05044eeecd8a061b0a8efaa713 (patch) (unidiff)
tree45db7a60f17d00ae72d0e8d6b986d5be10232c6c
parent340cb7e64fb898966996b00b93c03ca05a347aa5 (diff)
downloadopie-99899abc80a8aa05044eeecd8a061b0a8efaa713.zip
opie-99899abc80a8aa05044eeecd8a061b0a8efaa713.tar.gz
opie-99899abc80a8aa05044eeecd8a061b0a8efaa713.tar.bz2
- add classes for 802.11 tagged values
- adjust miniwellenreiter accordingly
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp11
-rw-r--r--libopie2/opiecore/oapplication.cpp14
-rw-r--r--libopie2/opiecore/oapplication.h16
-rw-r--r--libopie2/opienet/802_11_user.h54
-rw-r--r--libopie2/opienet/onetwork.cpp40
-rw-r--r--libopie2/opienet/onetwork.h7
-rw-r--r--libopie2/opienet/opcap.cpp253
-rw-r--r--libopie2/opienet/opcap.h166
8 files changed, 481 insertions, 80 deletions
diff --git a/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp b/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp
index aec9cc7..7581888 100644
--- a/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp
+++ b/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp
@@ -1,199 +1,202 @@
1#include <qdict.h> 1#include <qdict.h>
2#include <qsocketnotifier.h> 2#include <qsocketnotifier.h>
3#include <qstring.h> 3#include <qstring.h>
4#include <opie2/onetwork.h> 4#include <opie2/onetwork.h>
5#include <qapplication.h> 5#include <qapplication.h>
6#include <opie2/opcap.h> 6#include <opie2/opcap.h>
7#include <cerrno> 7#include <cerrno>
8#include <cstdio> 8#include <cstdio>
9#include <cstdlib> 9#include <cstdlib>
10#include <cstring> 10#include <cstring>
11 11
12//======================== Station help class =============================== 12//======================== Station help class ===============================
13 13
14class Station 14class Station
15{ 15{
16 public: 16 public:
17 Station( QString t, int c, bool w ) : type(t), channel(c), wep(w), beacons(1) {}; 17 Station( QString t, int c, bool w ) : type(t), channel(c), wep(w), beacons(1) {};
18 ~Station() {}; 18 ~Station() {};
19 19
20 QString type; 20 QString type;
21 int channel; 21 int channel;
22 bool wep; 22 bool wep;
23 int beacons; 23 int beacons;
24}; 24};
25 25
26QDict<Station> stations; 26QDict<Station> stations;
27 27
28//======================== Application class =============================== 28//======================== Application class ===============================
29 29
30class Wellenreiter : public QApplication 30class Wellenreiter : public QApplication
31{ 31{
32Q_OBJECT 32Q_OBJECT
33public: 33public:
34 Wellenreiter( int argc, char** argv ) : QApplication( argc, argv ) 34 Wellenreiter( int argc, char** argv ) : QApplication( argc, argv )
35 { 35 {
36 36
37 ONetwork* net = ONetwork::instance(); 37 ONetwork* net = ONetwork::instance();
38 38
39 if ( argc < 3 ) 39 if ( argc < 3 )
40 { 40 {
41 printf( "Usage: ./%s <interface> <driver> <interval>\n", argv[0] ); 41 printf( "Usage: ./%s <interface> <driver> <interval>\n", argv[0] );
42 printf( "\n" ); 42 printf( "\n" );
43 printf( "Valid wireless interfaces (detected) are:\n" ); 43 printf( "Valid wireless interfaces (detected) are:\n" );
44 44
45 ONetwork::InterfaceIterator it = net->iterator(); 45 ONetwork::InterfaceIterator it = net->iterator();
46 while ( it.current() ) 46 while ( it.current() )
47 { 47 {
48 if ( it.current()->isWireless() ) 48 if ( it.current()->isWireless() )
49 { 49 {
50 printf( " - '%s' (MAC=%s) (IPv4=%s)\n", (const char*) it.current()->name(), 50 printf( " - '%s' (MAC=%s) (IPv4=%s)\n", (const char*) it.current()->name(),
51 (const char*) it.current()->macAddress().toString(), 51 (const char*) it.current()->macAddress().toString(),
52 (const char*) it.current()->ipV4Address() ); 52 (const char*) it.current()->ipV4Address() );
53 } 53 }
54 ++it; 54 ++it;
55 } 55 }
56 exit( -1 ); 56 exit( -1 );
57 } 57 }
58 58
59 printf( "****************************************************\n" ); 59 printf( "****************************************************\n" );
60 printf( "* Wellenreiter mini edition 1.0 (C) 2003 M-M-M *\n" ); 60 printf( "* Wellenreiter mini edition 1.0 (C) 2003 M-M-M *\n" );
61 printf( "****************************************************\n" ); 61 printf( "****************************************************\n" );
62 printf( "\n\n" ); 62 printf( "\n\n" );
63 63
64 QString interface( argv[1] ); 64 QString interface( argv[1] );
65 QString driver( argv[2] ); 65 QString driver( argv[2] );
66 66
67 printf( "Trying to use '%s' as %s-controlled device...\n", (const char*) interface, (const char*) driver ); 67 printf( "Trying to use '%s' as %s-controlled device...\n", (const char*) interface, (const char*) driver );
68 68
69 // sanity checks before downcasting 69 // sanity checks before downcasting
70 ONetworkInterface* iface = net->interface( interface ); 70 ONetworkInterface* iface = net->interface( interface );
71 if ( !iface ) 71 if ( !iface )
72 { 72 {
73 printf( "Interface '%s' doesn't exist. Exiting.\n", (const char*) interface ); 73 printf( "Interface '%s' doesn't exist. Exiting.\n", (const char*) interface );
74 exit( -1 ); 74 exit( -1 );
75 } 75 }
76 if ( !iface->isWireless() ) 76 if ( !iface->isWireless() )
77 { 77 {
78 printf( "Interface '%s' doesn't support wireless extensions. Exiting.\n", (const char*) interface ); 78 printf( "Interface '%s' doesn't support wireless extensions. Exiting.\n", (const char*) interface );
79 exit( -1 ); 79 exit( -1 );
80 } 80 }
81 81
82 // downcast should be safe now 82 // downcast should be safe now
83 wiface = (OWirelessNetworkInterface*) iface; 83 wiface = (OWirelessNetworkInterface*) iface;
84 printf( "Using wireless interface '%s' for scanning (current SSID is '%s')...\n", (const char*) interface, (const char*) wiface->SSID() ); 84 printf( "Using wireless interface '%s' for scanning (current SSID is '%s')...\n", (const char*) interface, (const char*) wiface->SSID() );
85 85
86 /* 86 /*
87 87
88 // ifconfig down the interface - this enable more crash-proof 88 // ifconfig down the interface - this enable more crash-proof
89 // scanning with drivers like spectrum_cs... 89 // scanning with drivers like spectrum_cs...
90 if ( wiface->isUp() ) 90 if ( wiface->isUp() )
91 { 91 {
92 printf( "Interface status is up... switching to down... " ); 92 printf( "Interface status is up... switching to down... " );
93 wiface->setUp( false ); 93 wiface->setUp( false );
94 if ( wiface->isUp() ) 94 if ( wiface->isUp() )
95 { 95 {
96 printf( "failed (%s). Exiting.\n", strerror( errno ) ); 96 printf( "failed (%s). Exiting.\n", strerror( errno ) );
97 exit( -1 ); 97 exit( -1 );
98 } 98 }
99 else 99 else
100 { 100 {
101 printf( "ok.\n" ); 101 printf( "ok.\n" );
102 } 102 }
103 } 103 }
104 else 104 else
105 printf( "Interface status is already down - good.\n" ); 105 printf( "Interface status is already down - good.\n" );
106 106
107 */ 107 */
108 108
109 // ifconfig +promisc the interface to receive all packets 109 // ifconfig +promisc the interface to receive all packets
110 if ( !wiface->promiscuousMode() ) 110 if ( !wiface->promiscuousMode() )
111 { 111 {
112 printf( "Interface status is not promisc... switching to promisc... " ); 112 printf( "Interface status is not promisc... switching to promisc... " );
113 wiface->setPromiscuousMode( true ); 113 wiface->setPromiscuousMode( true );
114 if ( !wiface->promiscuousMode() ) 114 if ( !wiface->promiscuousMode() )
115 { 115 {
116 printf( "failed (%s). Exiting.\n", strerror( errno ) ); 116 printf( "failed (%s). Exiting.\n", strerror( errno ) );
117 exit( -1 ); 117 exit( -1 );
118 } 118 }
119 else 119 else
120 { 120 {
121 printf( "ok.\n" ); 121 printf( "ok.\n" );
122 } 122 }
123 } 123 }
124 else 124 else
125 printf( "Interface status is already promisc - good.\n" ); 125 printf( "Interface status is already promisc - good.\n" );
126 126
127 // connect a monitoring strategy to the interface 127 // connect a monitoring strategy to the interface
128 if ( driver == "orinoco" ) 128 if ( driver == "orinoco" )
129 new OOrinocoMonitoringInterface( wiface ); 129 new OOrinocoMonitoringInterface( wiface );
130 else 130 else
131 { 131 {
132 printf( "Unknown driver. Exiting\n" ); 132 printf( "Unknown driver. Exiting\n" );
133 exit( -1 ); 133 exit( -1 );
134 } 134 }
135 135
136 // enable monitoring mode 136 // enable monitoring mode
137 printf( "Enabling monitor mode...\n" ); 137 printf( "Enabling monitor mode...\n" );
138 wiface->setMonitorMode( true ); 138 wiface->setMonitorMode( true );
139 139
140 // open a packet capturer 140 // open a packet capturer
141 cap = new OPacketCapturer(); 141 cap = new OPacketCapturer();
142 cap->open( interface ); 142 cap->open( interface );
143 if ( !cap->isOpen() ) 143 if ( !cap->isOpen() )
144 { 144 {
145 printf( "Unable to open libpcap (%s). Exiting.\n", strerror( errno ) ); 145 printf( "Unable to open libpcap (%s). Exiting.\n", strerror( errno ) );
146 exit( -1 ); 146 exit( -1 );
147 } 147 }
148 148
149 // set capturer to non-blocking mode 149 // set capturer to non-blocking mode
150 cap->setBlocking( false ); 150 cap->setBlocking( false );
151 151
152 // start channel hopper 152 // start channel hopper
153 wiface->setChannelHopping( 1000 ); 153 wiface->setChannelHopping( 1000 );
154 154
155 // connect 155 // connect
156 connect( cap, SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) ); 156 connect( cap, SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) );
157 157
158 } 158 }
159 159
160 ~Wellenreiter() {}; 160 ~Wellenreiter() {};
161 161
162public slots: 162public slots:
163 void receivePacket(OPacket* p) 163 void receivePacket(OPacket* p)
164 { 164 {
165 if (!p) 165 if (!p)
166 { 166 {
167 printf( "(empty packet received)\n" ); 167 printf( "(empty packet received)\n" );
168 return; 168 return;
169 } 169 }
170 170
171 OWaveLanManagementPacket* beacon = (OWaveLanManagementPacket*) p->child( "802.11 Management" ); 171 OWaveLanManagementPacket* beacon = (OWaveLanManagementPacket*) p->child( "802.11 Management" );
172 172
173 if ( beacon ) 173 if ( beacon )
174 { 174 {
175 if ( stations.find( beacon->SSID() ) ) 175 OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) );
176 stations[beacon->SSID()]->beacons++; 176 QString essid = ssid ? ssid->ID() : "<unknown>";
177
178 if ( stations.find( essid ) )
179 stations[essid]->beacons++;
177 else 180 else
178 { 181 {
179 printf( "found new network @ channel %d, SSID = '%s'\n", wiface->channel(), (const char*) beacon->SSID() ); 182 printf( "found new network @ channel %d, SSID = '%s'\n", wiface->channel(), (const char*) essid );
180 stations.insert( beacon->SSID(), new Station( "unknown", wiface->channel(), 183 stations.insert( essid, new Station( "unknown", wiface->channel(),
181 ((OWaveLanPacket*) beacon->parent())->usesWep() ) ); 184 ((OWaveLanPacket*) beacon->parent())->usesWep() ) );
182 } 185 }
183 } 186 }
184 } 187 }
185private: 188private:
186 OPacketCapturer* cap; 189 OPacketCapturer* cap;
187 OWirelessNetworkInterface* wiface; 190 OWirelessNetworkInterface* wiface;
188}; 191};
189 192
190 193
191int main( int argc, char** argv ) 194int main( int argc, char** argv )
192{ 195{
193 Wellenreiter w( argc, argv ); 196 Wellenreiter w( argc, argv );
194 w.exec(); 197 w.exec();
195 return 0; 198 return 0;
196} 199}
197 200
198#include "miniwellenreiter.moc" 201#include "miniwellenreiter.moc"
199 202
diff --git a/libopie2/opiecore/oapplication.cpp b/libopie2/opiecore/oapplication.cpp
index a0abcc2..12418d5 100644
--- a/libopie2/opiecore/oapplication.cpp
+++ b/libopie2/opiecore/oapplication.cpp
@@ -1,110 +1,124 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3
4              Copyright (C) 2003 Michael Lauer <mickey@tm.informatik.uni-frankfurt.de> 4              Copyright (C) 2003 Michael Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29*/ 29*/
30 30
31#include <opie2/oapplication.h> 31#include <opie2/oapplication.h>
32#include <opie2/oconfig.h> 32#include <opie2/oconfig.h>
33 33
34OApplication* OApplication::_instance = 0; 34OApplication* OApplication::_instance = 0;
35 35
36/**************************************************************************************************/ 36/**************************************************************************************************/
37/* OApplicationPrivate 37/* OApplicationPrivate
38/**************************************************************************************************/ 38/**************************************************************************************************/
39 39
40class OApplicationPrivate 40class OApplicationPrivate
41{ 41{
42 public: 42 public:
43 OApplicationPrivate() {}; 43 OApplicationPrivate() {};
44 ~OApplicationPrivate() {}; 44 ~OApplicationPrivate() {};
45}; 45};
46 46
47/**************************************************************************************************/ 47/**************************************************************************************************/
48/* OApplication 48/* OApplication
49/**************************************************************************************************/ 49/**************************************************************************************************/
50 50
51 51
52OApplication::OApplication( int& argc, char** argv, const QCString& rAppName ) 52OApplication::OApplication( int& argc, char** argv, const QCString& rAppName )
53 :OApplicationBaseClass( argc, argv ), 53 :OApplicationBaseClass( argc, argv ),
54 _appname( rAppName ), 54 _appname( rAppName ),
55 _config( 0 ) 55 _config( 0 )
56{ 56{
57 init(); 57 init();
58} 58}
59 59
60 60
61OApplication::~OApplication() 61OApplication::~OApplication()
62{ 62{
63 delete d; 63 delete d;
64 if ( _config ) 64 if ( _config )
65 delete _config; 65 delete _config;
66 OApplication::_instance = 0; 66 OApplication::_instance = 0;
67 // after deconstruction of the one-and-only application object, 67 // after deconstruction of the one-and-only application object,
68 // the construction of another object is allowed 68 // the construction of another object is allowed
69} 69}
70 70
71 71
72OConfig* OApplication::config() 72OConfig* OApplication::config()
73{ 73{
74 if ( not _config ) 74 if ( not _config )
75 { 75 {
76 _config = new OConfig( _appname ); 76 _config = new OConfig( _appname );
77 } 77 }
78 return _config; 78 return _config;
79} 79}
80 80
81 81
82void OApplication::init() 82void OApplication::init()
83{ 83{
84 d = new OApplicationPrivate(); 84 d = new OApplicationPrivate();
85 if ( !OApplication::_instance ) 85 if ( !OApplication::_instance )
86 { 86 {
87 OApplication::_instance = this; 87 OApplication::_instance = this;
88 } 88 }
89 else 89 else
90 { 90 {
91 qFatal( "OApplication: Can't create more than one OApplication object. Aborting." ); 91 qFatal( "OApplication: Can't create more than one OApplication object. Aborting." );
92 } 92 }
93} 93}
94 94
95
95void OApplication::setMainWidget( QWidget* widget ) 96void OApplication::setMainWidget( QWidget* widget )
96{ 97{
97 showMainWidget( widget ); 98 showMainWidget( widget );
98} 99}
99 100
101
100void OApplication::showMainWidget( QWidget* widget, bool nomax ) 102void OApplication::showMainWidget( QWidget* widget, bool nomax )
101{ 103{
102 #ifdef Q_WS_QWS 104 #ifdef Q_WS_QWS
103 QPEApplication::showMainWidget( widget, nomax ); 105 QPEApplication::showMainWidget( widget, nomax );
104 #else 106 #else
105 QApplication::setMainWidget( widget ); 107 QApplication::setMainWidget( widget );
106 widget->show(); 108 widget->show();
107 #endif 109 #endif
108 widget->setCaption( _appname ); 110 widget->setCaption( _appname );
111}
112
109 113
114void OApplication::setTitle( QString title ) const
115{
116 if ( mainWidget() )
117 {
118 if ( !title.isNull() )
119 mainWidget()->setCaption( QString(_appname) + QString( " - " ) + title );
120 else
121 mainWidget()->setCaption( _appname );
122 }
110} 123}
124
diff --git a/libopie2/opiecore/oapplication.h b/libopie2/opiecore/oapplication.h
index 736e786..4d25202 100644
--- a/libopie2/opiecore/oapplication.h
+++ b/libopie2/opiecore/oapplication.h
@@ -1,114 +1,130 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3
4              Copyright (C) 2003 Michael Lauer <mickey@tm.informatik.uni-frankfurt.de> 4              Copyright (C) 2003 Michael Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29*/ 29*/
30 30
31#ifndef OAPPLICATION_H 31#ifndef OAPPLICATION_H
32#define OAPPLICATION_H 32#define OAPPLICATION_H
33 33
34#define oApp OApplication::oApplication() 34#define oApp OApplication::oApplication()
35 35
36#ifdef QWS 36#ifdef QWS
37 #include <qpe/qpeapplication.h> 37 #include <qpe/qpeapplication.h>
38 #define OApplicationBaseClass QPEApplication 38 #define OApplicationBaseClass QPEApplication
39#else 39#else
40 #include <qapplication.h> 40 #include <qapplication.h>
41 #define OApplicationBaseClass QApplication 41 #define OApplicationBaseClass QApplication
42#endif 42#endif
43 43
44class OApplicationPrivate; 44class OApplicationPrivate;
45class OConfig; 45class OConfig;
46 46
47class OApplication: public OApplicationBaseClass 47class OApplication: public OApplicationBaseClass
48{ 48{
49 public: 49 public:
50 50
51 /** 51 /**
52 * Constructor. Parses command-line arguments and sets the window caption. 52 * Constructor. Parses command-line arguments and sets the window caption.
53 * 53 *
54 * @param rAppName application name. Will be used for finding the 54 * @param rAppName application name. Will be used for finding the
55 * associated message, icon and configuration files 55 * associated message, icon and configuration files
56 * 56 *
57 */ 57 */
58 OApplication( int& argc, char** argv, const QCString& rAppName ); 58 OApplication( int& argc, char** argv, const QCString& rAppName );
59 /** 59 /**
60 * Destructor. Destroys the application object and its children. 60 * Destructor. Destroys the application object and its children.
61 */ 61 */
62 virtual ~OApplication(); 62 virtual ~OApplication();
63 63
64 /** 64 /**
65 * Returns the current application object. 65 * Returns the current application object.
66 * 66 *
67 * This is similar to the global @ref QApplication pointer qApp. It 67 * This is similar to the global @ref QApplication pointer qApp. It
68 * allows access to the single global OApplication object, since 68 * allows access to the single global OApplication object, since
69 * more than one cannot be created in the same application. It 69 * more than one cannot be created in the same application. It
70 * saves you the trouble of having to pass the pointer explicitly 70 * saves you the trouble of having to pass the pointer explicitly
71 * to every function that may require it. 71 * to every function that may require it.
72 *
72 * @return the current application object 73 * @return the current application object
73 */ 74 */
74 static const OApplication* oApplication() { return _instance; }; 75 static const OApplication* oApplication() { return _instance; };
75 76
76 /** 77 /**
77 * Returns the application name as given during creation. 78 * Returns the application name as given during creation.
78 * 79 *
79 * @return A reference to the application name 80 * @return A reference to the application name
80 */ 81 */
81 const QCString& appName() const { return _appname; }; 82 const QCString& appName() const { return _appname; };
82 83
83 /** 84 /**
84 * Returns the application session config object. 85 * Returns the application session config object.
85 * 86 *
86 * @return A pointer to the application's instance specific 87 * @return A pointer to the application's instance specific
87 * @ref OConfig object. 88 * @ref OConfig object.
88 * @see OConfig 89 * @see OConfig
89 */ 90 */
90 OConfig* config(); 91 OConfig* config();
91 92
92 /** 93 /**
93 * Sets the main widget - reimplemented to call showMainWidget() 94 * Sets the main widget - reimplemented to call showMainWidget()
94 * on Qt/Embedded. 95 * on Qt/Embedded.
96 *
97 * @param mainWidget the widget to become the main widget
98 * @see QWidget object
95 */ 99 */
96 virtual void setMainWidget( QWidget *mainWidget ); 100 virtual void setMainWidget( QWidget *mainWidget );
97 101
98 /** 102 /**
99 * Shows the main widget - reimplemented to call setMainWidget() 103 * Shows the main widget - reimplemented to call setMainWidget()
100 * on platforms other than Qt/Embedded. 104 * on platforms other than Qt/Embedded.
105 *
106 * @param mainWidget the widget to become the main widget
107 * @see QWidget object
101 */ 108 */
102 virtual void showMainWidget( QWidget* widget, bool nomax = false ); 109 virtual void showMainWidget( QWidget* widget, bool nomax = false );
103 110
111 /**
112 * Set the application title. The application title will be concatenated
113 * to the application name given in the constructor.
114 *
115 * @param title the title. If not given, resets caption to appname
116 */
117 virtual void setTitle( QString title = QString::null ) const;
118 //virtual void setTitle() const;
119
104 protected: 120 protected:
105 void init(); 121 void init();
106 122
107 private: 123 private:
108 const QCString _appname; 124 const QCString _appname;
109 static OApplication* _instance; 125 static OApplication* _instance;
110 OConfig* _config; 126 OConfig* _config;
111 OApplicationPrivate* d; 127 OApplicationPrivate* d;
112}; 128};
113 129
114#endif // OAPPLICATION_H 130#endif // OAPPLICATION_H
diff --git a/libopie2/opienet/802_11_user.h b/libopie2/opienet/802_11_user.h
index 0b3f198..ffdcb93 100644
--- a/libopie2/opienet/802_11_user.h
+++ b/libopie2/opienet/802_11_user.h
@@ -1,419 +1,427 @@
1#ifndef IEEE_802_11 1#ifndef IEEE_802_11
2#define IEEE_802_11 2#define IEEE_802_11
3 3
4enum ieee_802_11_link_status_failure_reason { 4enum ieee_802_11_link_status_failure_reason {
5 reserved0, Unspecified=1, Previous_not_valid, 5 reserved0, Unspecified=1, Previous_not_valid,
6 Sender_Quits_ESS_or_IBSS, 6 Sender_Quits_ESS_or_IBSS,
7 Due_Inactivity, AP_Overload, 7 Due_Inactivity, AP_Overload,
8 Class_2_from_NonAuth, 8 Class_2_from_NonAuth,
9 Class_3_from_NonAuth, 9 Class_3_from_NonAuth,
10 Sender_Quits_BSS, 10 Sender_Quits_BSS,
11 Association_requester_not_authenticated, 11 Association_requester_not_authenticated,
12 Reserved10 12 Reserved10
13}; 13};
14 14
15 15
16#define IEEE_802_11_LINK_STATUS_FAILURE_REASON_STRINGS \ 16#define IEEE_802_11_LINK_STATUS_FAILURE_REASON_STRINGS \
17 {\ 17 {\
18 {reserved0, 0xff," Reserved reason "},\ 18 {reserved0, 0xff," Reserved reason "},\
19 {Unspecified, 0xff," Unspecified Reason "},\ 19 {Unspecified, 0xff," Unspecified Reason "},\
20 {Previous_not_valid,0xff," Previous Authentication no longer valid "},\ 20 {Previous_not_valid,0xff," Previous Authentication no longer valid "},\
21 {Sender_Quits_ESS_or_IBSS,0xff," Deauthenticated because sending station is leaving (has left) IBSS or ESS "},\ 21 {Sender_Quits_ESS_or_IBSS,0xff," Deauthenticated because sending station is leaving (has left) IBSS or ESS "},\
22 {Due_Inactivity,0xff," Disassociated due to inactivity "},\ 22 {Due_Inactivity,0xff," Disassociated due to inactivity "},\
23 {AP_Overload, 0xff," Disassociated because AP is unable to handle all currently associated stations "},\ 23 {AP_Overload, 0xff," Disassociated because AP is unable to handle all currently associated stations "},\
24 {Class_2_from_NonAuth,0xff," Class 2 frame received from non-Authenticated station"},\ 24 {Class_2_from_NonAuth,0xff," Class 2 frame received from non-Authenticated station"},\
25 {Class_3_from_NonAuth,0xff," Class 3 frame received from non­Associated station"},\ 25 {Class_3_from_NonAuth,0xff," Class 3 frame received from non­Associated station"},\
26 {Sender_Quits_BSS,0xff," Disassociated because sending station is leaving (has left) BSS"},\ 26 {Sender_Quits_BSS,0xff," Disassociated because sending station is leaving (has left) BSS"},\
27 {Association_requester_not_authenticated,0xff," Station requesting (Re)Association is not Authenticated with responding station"},\ 27 {Association_requester_not_authenticated,0xff," Station requesting (Re)Association is not Authenticated with responding station"},\
28 {Reserved10, 0xff," Reserved"},\ 28 {Reserved10, 0xff," Reserved"},\
29 {0,0,NULL}\ 29 {0,0,NULL}\
30}; 30};
31 31
32 32
33 33
34struct ieee_802_11_header { 34struct ieee_802_11_header {
35 u_int16_tframe_control;// needs to be subtyped 35 u_int16_tframe_control;// needs to be subtyped
36 u_int16_tduration; 36 u_int16_tduration;
37 u_int8_tmac1[6]; 37 u_int8_tmac1[6];
38 u_int8_tmac2[6]; 38 u_int8_tmac2[6];
39 u_int8_tmac3[6]; 39 u_int8_tmac3[6];
40 u_int16_tSeqCtl; 40 u_int16_tSeqCtl;
41 u_int8_tmac4[6]; 41 u_int8_tmac4[6];
42 // u_int16_tgapLen; 42 // u_int16_tgapLen;
43 // u_int8_tgap[8]; 43 // u_int8_tgap[8];
44}; 44};
45 45
46 46
47struct ieee_802_3_header { 47struct ieee_802_3_header {
48 48
49 u_int16_tstatus; 49 u_int16_tstatus;
50 u_int16_tpayload_length; 50 u_int16_tpayload_length;
51 u_int8_tdst_mac[6]; 51 u_int8_tdst_mac[6];
52 u_int8_tsrc_mac[6]; 52 u_int8_tsrc_mac[6];
53 53
54}; 54};
55 55
56#define P80211_OUI_LEN 3 56#define P80211_OUI_LEN 3
57 57
58struct ieee_802_11_snap_header { 58struct ieee_802_11_snap_header {
59 59
60 u_int8_t dsap; /* always 0xAA */ 60 u_int8_t dsap; /* always 0xAA */
61 u_int8_t ssap; /* always 0xAA */ 61 u_int8_t ssap; /* always 0xAA */
62 u_int8_t ctrl; /* always 0x03 */ 62 u_int8_t ctrl; /* always 0x03 */
63 u_int8_t oui[P80211_OUI_LEN]; /* organizational universal id */ 63 u_int8_t oui[P80211_OUI_LEN]; /* organizational universal id */
64 64
65} __attribute__ ((packed)); 65} __attribute__ ((packed));
66 66
67#define P80211_LLC_OUI_LEN 3 67#define P80211_LLC_OUI_LEN 3
68 68
69struct ieee_802_11_802_1H_header { 69struct ieee_802_11_802_1H_header {
70 70
71 u_int8_t dsap; 71 u_int8_t dsap;
72 u_int8_t ssap; /* always 0xAA */ 72 u_int8_t ssap; /* always 0xAA */
73 u_int8_t ctrl; /* always 0x03 */ 73 u_int8_t ctrl; /* always 0x03 */
74 u_int8_t oui[P80211_OUI_LEN]; /* organizational universal id */ 74 u_int8_t oui[P80211_OUI_LEN]; /* organizational universal id */
75 u_int16_t unknown1; /* packet type ID fields */ 75 u_int16_t unknown1; /* packet type ID fields */
76 u_int16_t unknown2; /* here is something like length in some cases */ 76 u_int16_t unknown2; /* here is something like length in some cases */
77} __attribute__ ((packed)); 77} __attribute__ ((packed));
78 78
79struct ieee_802_11_802_2_header { 79struct ieee_802_11_802_2_header {
80 80
81 u_int8_t dsap; 81 u_int8_t dsap;
82 u_int8_t ssap; /* always 0xAA */ 82 u_int8_t ssap; /* always 0xAA */
83 u_int8_t ctrl; /* always 0x03 */ 83 u_int8_t ctrl; /* always 0x03 */
84 u_int8_t oui[P80211_OUI_LEN]; /* organizational universal id */ 84 u_int8_t oui[P80211_OUI_LEN]; /* organizational universal id */
85 u_int16_t type; /* packet type ID field */ 85 u_int16_t type; /* packet type ID field */
86 86
87} __attribute__ ((packed)); 87} __attribute__ ((packed));
88 88
89 89
90 90
91// following is incoplete and may be incorrect and need reorganization 91// following is incoplete and may be incorrect and need reorganization
92 92
93 #define ieee_802_11_frame_type_Management0x00 93 #define ieee_802_11_frame_type_Management0x00
94 #define ieee_802_11_frame_type_Control 0x01 94 #define ieee_802_11_frame_type_Control 0x01
95 #define ieee_802_11_frame_type_Data 0x10 95 #define ieee_802_11_frame_type_Data 0x10
96 #define ieee_802_11_frame_type_Reserved 0x11 96 #define ieee_802_11_frame_type_Reserved 0x11
97 97
98 #define ieee_802_11_frame_subtype_Association_Req0x0 // Association Request 98 #define ieee_802_11_frame_subtype_Association_Req0x0 // Association Request
99 #define ieee_802_11_frame_subtype_Association_Resp0x1 // Association Response 99 #define ieee_802_11_frame_subtype_Association_Resp0x1 // Association Response
100 #define ieee_802_11_frame_subtype_Reassociation_Req0x2 // Reassociation Request 100 #define ieee_802_11_frame_subtype_Reassociation_Req0x2 // Reassociation Request
101 #define ieee_802_11_frame_subtype_Reassociation_Resp0x3 // Reassociation Response 101 #define ieee_802_11_frame_subtype_Reassociation_Resp0x3 // Reassociation Response
102 #define ieee_802_11_frame_subtype_Probe_Req 0x4 // Probe Request 102 #define ieee_802_11_frame_subtype_Probe_Req 0x4 // Probe Request
103 #define ieee_802_11_frame_subtype_Probe_Resp 0x5 // Probe Response 103 #define ieee_802_11_frame_subtype_Probe_Resp 0x5 // Probe Response
104 #define ieee_802_11_frame_subtype_Beacon 0x8 // Beacon 104 #define ieee_802_11_frame_subtype_Beacon 0x8 // Beacon
105 #define ieee_802_11_frame_subtype_ATIM 0x9 // ATIM 105 #define ieee_802_11_frame_subtype_ATIM 0x9 // ATIM
106 #define ieee_802_11_frame_subtype_Disassociation 0xA // Disassociation 106 #define ieee_802_11_frame_subtype_Disassociation 0xA // Disassociation
107 #define ieee_802_11_frame_subtype_Authentication 0xB // Authentication 107 #define ieee_802_11_frame_subtype_Authentication 0xB // Authentication
108 #define ieee_802_11_frame_subtype_Deauthentication 0xC // Deauthentication 108 #define ieee_802_11_frame_subtype_Deauthentication 0xC // Deauthentication
109 #define ieee_802_11_frame_subtype_PS_Poll 0xA // PS-Poll 109 #define ieee_802_11_frame_subtype_PS_Poll 0xA // PS-Poll
110 #define ieee_802_11_frame_subtype_RTS 0xB // RTS 110 #define ieee_802_11_frame_subtype_RTS 0xB // RTS
111 #define ieee_802_11_frame_subtype_CTS 0xC // CTS 111 #define ieee_802_11_frame_subtype_CTS 0xC // CTS
112 #define ieee_802_11_frame_subtype_ACK 0xD // ACK 112 #define ieee_802_11_frame_subtype_ACK 0xD // ACK
113 #define ieee_802_11_frame_subtype_CFEnd 0xE // CF-End 113 #define ieee_802_11_frame_subtype_CFEnd 0xE // CF-End
114 #define ieee_802_11_frame_subtype_CFEnd_CFAck 0xF // CF-End + CF-Ack 114 #define ieee_802_11_frame_subtype_CFEnd_CFAck 0xF // CF-End + CF-Ack
115 #define ieee_802_11_frame_subtype_Data 0x0 // Data 115 #define ieee_802_11_frame_subtype_Data 0x0 // Data
116 #define ieee_802_11_frame_subtype_Data_CFAck 0x1 // Data + CF-Ack 116 #define ieee_802_11_frame_subtype_Data_CFAck 0x1 // Data + CF-Ack
117 #define ieee_802_11_frame_subtype_Data_CF_Poll 0x2 // Data + CF-Poll 117 #define ieee_802_11_frame_subtype_Data_CF_Poll 0x2 // Data + CF-Poll
118 #define ieee_802_11_frame_subtype_Data_CF_AckCF_Poll 0x3 // Data + CF-Ack + CF-Poll 118 #define ieee_802_11_frame_subtype_Data_CF_AckCF_Poll 0x3 // Data + CF-Ack + CF-Poll
119 #define ieee_802_11_frame_subtype_NullFunction 0x4 // Null Function (no data) 119 #define ieee_802_11_frame_subtype_NullFunction 0x4 // Null Function (no data)
120 #define ieee_802_11_frame_subtype_CF_Ack 0x5 // CF-Ack (no data) 120 #define ieee_802_11_frame_subtype_CF_Ack 0x5 // CF-Ack (no data)
121 #define ieee_802_11_frame_subtype_CF_Poll 0x6 // CF-Poll (no data) 121 #define ieee_802_11_frame_subtype_CF_Poll 0x6 // CF-Poll (no data)
122 #define ieee_802_11_frame_subtype_CF_AckCF_Poll 0x7 // CF-Ack + CF-Poll (no data) 122 #define ieee_802_11_frame_subtype_CF_AckCF_Poll 0x7 // CF-Ack + CF-Poll (no data)
123 123
124 124
125#define ieee_802_11_frame_subtype_strings {\ 125#define ieee_802_11_frame_subtype_strings {\
126 { ieee_802_11_frame_subtype_Association_Req,0xF,"f Association Request"},\ 126 { ieee_802_11_frame_subtype_Association_Req,0xF,"f Association Request"},\
127 { ieee_802_11_frame_subtype_Association_Resp,0xF,"1 Association Response"},\ 127 { ieee_802_11_frame_subtype_Association_Resp,0xF,"1 Association Response"},\
128 { ieee_802_11_frame_subtype_Reassociation_Req,0xF,"2 Reassociation Request"},\ 128 { ieee_802_11_frame_subtype_Reassociation_Req,0xF,"2 Reassociation Request"},\
129 { ieee_802_11_frame_subtype_Reassociation_Resp,0xF,"3 Reassociation Response"},\ 129 { ieee_802_11_frame_subtype_Reassociation_Resp,0xF,"3 Reassociation Response"},\
130 { ieee_802_11_frame_subtype_Probe_Req ,0xF,"4 Probe Request"},\ 130 { ieee_802_11_frame_subtype_Probe_Req ,0xF,"4 Probe Request"},\
131 { ieee_802_11_frame_subtype_Probe_Resp ,0xF,"5 Probe Response"},\ 131 { ieee_802_11_frame_subtype_Probe_Resp ,0xF,"5 Probe Response"},\
132 { ieee_802_11_frame_subtype_Beacon ,0xF,"8 Beacon"},\ 132 { ieee_802_11_frame_subtype_Beacon ,0xF,"8 Beacon"},\
133 { ieee_802_11_frame_subtype_ATIM ,0xF,"9 ATIM"},\ 133 { ieee_802_11_frame_subtype_ATIM ,0xF,"9 ATIM"},\
134 { ieee_802_11_frame_subtype_Disassociation,0xF,"A Disassociation"},\ 134 { ieee_802_11_frame_subtype_Disassociation,0xF,"A Disassociation"},\
135 { ieee_802_11_frame_subtype_Authentication,0xF,"B Authentication"},\ 135 { ieee_802_11_frame_subtype_Authentication,0xF,"B Authentication"},\
136 { ieee_802_11_frame_subtype_Deauthentication,0xF,"C Deauthentication"},\ 136 { ieee_802_11_frame_subtype_Deauthentication,0xF,"C Deauthentication"},\
137 { ieee_802_11_frame_subtype_PS_Poll ,0xF,"A PS-Poll"},\ 137 { ieee_802_11_frame_subtype_PS_Poll ,0xF,"A PS-Poll"},\
138 { ieee_802_11_frame_subtype_RTS ,0xF,"B RTS"},\ 138 { ieee_802_11_frame_subtype_RTS ,0xF,"B RTS"},\
139 { ieee_802_11_frame_subtype_CTS ,0xF,"C CTS"},\ 139 { ieee_802_11_frame_subtype_CTS ,0xF,"C CTS"},\
140 { ieee_802_11_frame_subtype_ACK ,0xF,"D ACK"},\ 140 { ieee_802_11_frame_subtype_ACK ,0xF,"D ACK"},\
141 { ieee_802_11_frame_subtype_CFEnd ,0xF,"E CF-End"},\ 141 { ieee_802_11_frame_subtype_CFEnd ,0xF,"E CF-End"},\
142 { ieee_802_11_frame_subtype_CFEnd_CFAck ,0xF,"F CF-End + CF-Ack"},\ 142 { ieee_802_11_frame_subtype_CFEnd_CFAck ,0xF,"F CF-End + CF-Ack"},\
143 { ieee_802_11_frame_subtype_Data ,0xF,"0 Data"},\ 143 { ieee_802_11_frame_subtype_Data ,0xF,"0 Data"},\
144 { ieee_802_11_frame_subtype_Data_CFAck ,0xF,"1 Data + CF-Ack"},\ 144 { ieee_802_11_frame_subtype_Data_CFAck ,0xF,"1 Data + CF-Ack"},\
145 { ieee_802_11_frame_subtype_Data_CFPoll ,0xF,"2 Data + CF-Poll"},\ 145 { ieee_802_11_frame_subtype_Data_CFPoll ,0xF,"2 Data + CF-Poll"},\
146 { ieee_802_11_frame_subtype_Data_CFAck_CFPoll,0xF,"3 Data + CF-Ack + CF-Poll"},\ 146 { ieee_802_11_frame_subtype_Data_CFAck_CFPoll,0xF,"3 Data + CF-Ack + CF-Poll"},\
147 { ieee_802_11_frame_subtype_Null_Function ,0xF,"4 Null Function (no data)"},\ 147 { ieee_802_11_frame_subtype_Null_Function ,0xF,"4 Null Function (no data)"},\
148 { ieee_802_11_frame_subtype_CFAck , 0xF,"5 CF-Ack (no data)"},\ 148 { ieee_802_11_frame_subtype_CFAck , 0xF,"5 CF-Ack (no data)"},\
149 { ieee_802_11_frame_subtype_CFPoll , 0xF,"6 CF-Poll (no data)"},\ 149 { ieee_802_11_frame_subtype_CFPoll , 0xF,"6 CF-Poll (no data)"},\
150 { ieee_802_11_frame_subtype_CFAck_CFPoll,0xF,"y7 CF-Ack + CF-Poll (no data)"},\ 150 { ieee_802_11_frame_subtype_CFAck_CFPoll,0xF,"y7 CF-Ack + CF-Poll (no data)"},\
151 { 0,0,NULL}\ 151 { 0,0,NULL}\
152} 152}
153struct ieee_802_11_frame_subtype_class { 153struct ieee_802_11_frame_subtype_class {
154 u_int8_tsubtype; 154 u_int8_tsubtype;
155 u_int8_tmask; 155 u_int8_tmask;
156 u_int8_tklass; 156 u_int8_tklass;
157 u_int8_ttype; 157 u_int8_ttype;
158}; 158};
159#define ieee_802_11_frame_subtype_classes {\ 159#define ieee_802_11_frame_subtype_classes {\
160 { ieee_802_11_frame_subtype_Association_Req,0xF,2,ieee_802_11_frame_type_Management},\ 160 { ieee_802_11_frame_subtype_Association_Req,0xF,2,ieee_802_11_frame_type_Management},\
161 { ieee_802_11_frame_subtype_Association_Resp,0xF,2,ieee_802_11_frame_type_Management},\ 161 { ieee_802_11_frame_subtype_Association_Resp,0xF,2,ieee_802_11_frame_type_Management},\
162 { ieee_802_11_frame_subtype_Reassociation_Req,0xF,2,ieee_802_11_frame_type_Management},\ 162 { ieee_802_11_frame_subtype_Reassociation_Req,0xF,2,ieee_802_11_frame_type_Management},\
163 { ieee_802_11_frame_subtype_Reassociation_Resp,0xF,2,ieee_802_11_frame_type_Management},\ 163 { ieee_802_11_frame_subtype_Reassociation_Resp,0xF,2,ieee_802_11_frame_type_Management},\
164 { ieee_802_11_frame_subtype_Probe_Req ,0xF,1,ieee_802_11_frame_type_Management},\ 164 { ieee_802_11_frame_subtype_Probe_Req ,0xF,1,ieee_802_11_frame_type_Management},\
165 { ieee_802_11_frame_subtype_Probe_Resp ,0xF,1,ieee_802_11_frame_type_Management},\ 165 { ieee_802_11_frame_subtype_Probe_Resp ,0xF,1,ieee_802_11_frame_type_Management},\
166 { ieee_802_11_frame_subtype_Beacon ,0xF,1,ieee_802_11_frame_type_Management},\ 166 { ieee_802_11_frame_subtype_Beacon ,0xF,1,ieee_802_11_frame_type_Management},\
167 { ieee_802_11_frame_subtype_ATIM ,0xF,1,ieee_802_11_frame_type_Management},\ 167 { ieee_802_11_frame_subtype_ATIM ,0xF,1,ieee_802_11_frame_type_Management},\
168 { ieee_802_11_frame_subtype_Disassociation,0xF,2,ieee_802_11_frame_type_Management},\ 168 { ieee_802_11_frame_subtype_Disassociation,0xF,2,ieee_802_11_frame_type_Management},\
169 { ieee_802_11_frame_subtype_Authentication,0xF,1,ieee_802_11_frame_type_Management},\ 169 { ieee_802_11_frame_subtype_Authentication,0xF,1,ieee_802_11_frame_type_Management},\
170 { ieee_802_11_frame_subtype_Deauthentication,0xF,3,ieee_802_11_frame_type_Management},\ 170 { ieee_802_11_frame_subtype_Deauthentication,0xF,3,ieee_802_11_frame_type_Management},\
171 { ieee_802_11_frame_subtype_PS-Poll ,0xF,3,ieee_802_11_frame_type_Control},\ 171 { ieee_802_11_frame_subtype_PS-Poll ,0xF,3,ieee_802_11_frame_type_Control},\
172 { ieee_802_11_frame_subtype_RTS ,0xF,1,ieee_802_11_frame_type_Control},\ 172 { ieee_802_11_frame_subtype_RTS ,0xF,1,ieee_802_11_frame_type_Control},\
173 { ieee_802_11_frame_subtype_CTS ,0xF,1,ieee_802_11_frame_type_Control},\ 173 { ieee_802_11_frame_subtype_CTS ,0xF,1,ieee_802_11_frame_type_Control},\
174 { ieee_802_11_frame_subtype_ACK ,0xF,1,ieee_802_11_frame_type_Control},\ 174 { ieee_802_11_frame_subtype_ACK ,0xF,1,ieee_802_11_frame_type_Control},\
175 { ieee_802_11_frame_subtype_CFEnd ,0xF,1,ieee_802_11_frame_type_Control},\ 175 { ieee_802_11_frame_subtype_CFEnd ,0xF,1,ieee_802_11_frame_type_Control},\
176 { ieee_802_11_frame_subtype_CFEnd_CFAck ,0xF,1,ieee_802_11_frame_type_Control},\ 176 { ieee_802_11_frame_subtype_CFEnd_CFAck ,0xF,1,ieee_802_11_frame_type_Control},\
177 { ieee_802_11_frame_subtype_Data ,0xF,3,ieee_802_11_frame_type_Data},\ 177 { ieee_802_11_frame_subtype_Data ,0xF,3,ieee_802_11_frame_type_Data},\
178 { ieee_802_11_frame_subtype_Data_CFAck ,0xF,3,ieee_802_11_frame_type_Data},\ 178 { ieee_802_11_frame_subtype_Data_CFAck ,0xF,3,ieee_802_11_frame_type_Data},\
179 { ieee_802_11_frame_subtype_Data_CF_Poll 0xF,3,ieee_802_11_frame_type_Data},\ 179 { ieee_802_11_frame_subtype_Data_CF_Poll 0xF,3,ieee_802_11_frame_type_Data},\
180 { ieee_802_11_frame_subtype_Data_CF_AckCF_Poll,0xF,3,ieee_802_11_frame_type_Data},\ 180 { ieee_802_11_frame_subtype_Data_CF_AckCF_Poll,0xF,3,ieee_802_11_frame_type_Data},\
181 { ieee_802_11_frame_subtype_NullFunction 0xF,1,ieee_802_11_frame_type_Data},\ 181 { ieee_802_11_frame_subtype_NullFunction 0xF,1,ieee_802_11_frame_type_Data},\
182 { ieee_802_11_frame_subtype_CF_Ack , 0xF,1,ieee_802_11_frame_type_Data},\ 182 { ieee_802_11_frame_subtype_CF_Ack , 0xF,1,ieee_802_11_frame_type_Data},\
183 { ieee_802_11_frame_subtype_CF_Poll , 0xF,1,ieee_802_11_frame_type_Data},\ 183 { ieee_802_11_frame_subtype_CF_Poll , 0xF,1,ieee_802_11_frame_type_Data},\
184 { ieee_802_11_frame_subtype_CF_AckCF_Poll,0xF,1,ieee_802_11_frame_type_Data},\ 184 { ieee_802_11_frame_subtype_CF_AckCF_Poll,0xF,1,ieee_802_11_frame_type_Data},\
185 { 0,0,NULL}\ 185 { 0,0,NULL}\
186} 186}
187 187
188 #define IEEE802_11_FC_LEN2 188 #define IEEE802_11_FC_LEN2
189 189
190#define T_MGMT 0x0 /* management */ 190#define T_MGMT 0x0 /* management */
191#define T_CTRL 0x1 /* control */ 191#define T_CTRL 0x1 /* control */
192#define T_DATA 0x2 /* data */ 192#define T_DATA 0x2 /* data */
193#define T_RESV 0x3 /* reserved */ 193#define T_RESV 0x3 /* reserved */
194 194
195 #define ST_ASSOC_REQUEST 0x0 195 #define ST_ASSOC_REQUEST 0x0
196 #define ST_ASSOC_RESPONSE 0x1 196 #define ST_ASSOC_RESPONSE 0x1
197 #define ST_REASSOC_REQUEST 0x2 197 #define ST_REASSOC_REQUEST 0x2
198 #define ST_REASSOC_RESPONSE 0x3 198 #define ST_REASSOC_RESPONSE 0x3
199 #define ST_PROBE_REQUEST 0x4 199 #define ST_PROBE_REQUEST 0x4
200 #define ST_PROBE_RESPONSE 0x5 200 #define ST_PROBE_RESPONSE 0x5
201 /* RESERVED 0x6 */ 201 /* RESERVED 0x6 */
202 /* RESERVED 0x7 */ 202 /* RESERVED 0x7 */
203 #define ST_BEACON 0x8 203 #define ST_BEACON 0x8
204 #define ST_ATIM 0x9 204 #define ST_ATIM 0x9
205 #define ST_DISASSOC 0xA 205 #define ST_DISASSOC 0xA
206 #define ST_AUTH 0xB 206 #define ST_AUTH 0xB
207 #define ST_DEAUTH 0xC 207 #define ST_DEAUTH 0xC
208 /* RESERVED 0xD */ 208 /* RESERVED 0xD */
209 /* RESERVED 0xE */ 209 /* RESERVED 0xE */
210 /* RESERVED 0xF */ 210 /* RESERVED 0xF */
211 211
212 212
213 #define CTRL_PS_POLL0xA 213 #define CTRL_PS_POLL0xA
214 #define CTRL_RTS0xB 214 #define CTRL_RTS0xB
215 #define CTRL_CTS0xC 215 #define CTRL_CTS0xC
216 #define CTRL_ACK0xD 216 #define CTRL_ACK0xD
217 #define CTRL_CF_END0xE 217 #define CTRL_CF_END0xE
218 #define CTRL_END_ACK0xF 218 #define CTRL_END_ACK0xF
219 219
220/* 220/*
221 * Bits in the frame control field. 221 * Bits in the frame control field.
222 */ 222 */
223 #define FC_VERSION(fc) ((fc) & 0x3) 223 #define FC_VERSION(fc) ((fc) & 0x3)
224 #define FC_TYPE(fc) (((fc) >> 2) & 0x3) 224 #define FC_TYPE(fc) (((fc) >> 2) & 0x3)
225 #define FC_SUBTYPE(fc) (((fc) >> 4) & 0xF) 225 #define FC_SUBTYPE(fc) (((fc) >> 4) & 0xF)
226 #define FC_TO_DS(fc) ((fc) & 0x0100) 226 #define FC_TO_DS(fc) ((fc) & 0x0100)
227 #define FC_FROM_DS(fc) ((fc) & 0x0200) 227 #define FC_FROM_DS(fc) ((fc) & 0x0200)
228 #define FC_MORE_FLAG(fc)((fc) & 0x0400) 228 #define FC_MORE_FLAG(fc)((fc) & 0x0400)
229 #define FC_RETRY(fc) ((fc) & 0x0800) 229 #define FC_RETRY(fc) ((fc) & 0x0800)
230 #define FC_POWER_MGMT(fc)((fc) & 0x1000) 230 #define FC_POWER_MGMT(fc)((fc) & 0x1000)
231 #define FC_MORE_DATA(fc)((fc) & 0x2000) 231 #define FC_MORE_DATA(fc)((fc) & 0x2000)
232 #define FC_WEP(fc) ((fc) & 0x4000) 232 #define FC_WEP(fc) ((fc) & 0x4000)
233 #define FC_ORDER(fc) ((fc) & 0x8000) 233 #define FC_ORDER(fc) ((fc) & 0x8000)
234 234
235 235
236struct ieee_802_11_mgmt_header { 236struct ieee_802_11_mgmt_header {
237 u_int16_t fc; 237 u_int16_t fc;
238 u_int16_t duration; 238 u_int16_t duration;
239 u_int8_t da[6]; 239 u_int8_t da[6];
240 u_int8_t sa[6]; 240 u_int8_t sa[6];
241 u_int8_t bssid[6]; 241 u_int8_t bssid[6];
242 u_int16_t seq_ctrl; 242 u_int16_t seq_ctrl;
243}; 243};
244 244
245 245
246struct ieee_802_11_data_header { 246struct ieee_802_11_data_header {
247 u_int16_tframe_control; 247 u_int16_tframe_control;
248 u_int16_tduration; 248 u_int16_tduration;
249 u_int8_tmac1[6]; 249 u_int8_tmac1[6];
250 u_int8_tmac2[6]; 250 u_int8_tmac2[6];
251 u_int8_tmac3[6]; 251 u_int8_tmac3[6];
252 u_int16_tSeqCtl; 252 u_int16_tSeqCtl;
253 u_int8_tmac4[6]; 253 u_int8_tmac4[6];
254 // u_int16_tgapLen; 254 // u_int16_tgapLen;
255 // u_int8_tgap[8]; 255 // u_int8_tgap[8];
256}; 256};
257 257
258 #define CAPABILITY_ESS(cap)((cap) & 0x0001) 258#define CAPABILITY_ESS(cap) ((cap) & 0x0001)
259 #define CAPABILITY_IBSS(cap)((cap) & 0x0002) 259#define CAPABILITY_IBSS(cap) ((cap) & 0x0002)
260 #define CAPABILITY_CFP(cap)((cap) & 0x0004) 260#define CAPABILITY_CFP(cap) ((cap) & 0x0004)
261 #define CAPABILITY_CFP_REQ(cap)((cap) & 0x0008) 261#define CAPABILITY_CFP_REQ(cap) ((cap) & 0x0008)
262 #define CAPABILITY_PRIVACY(cap)((cap) & 0x0010) 262#define CAPABILITY_PRIVACY(cap) ((cap) & 0x0010)
263 263
264struct ssid_t { 264struct ssid_t {
265 u_int8_telement_id; 265 u_int8_telement_id;
266 u_int8_tlength; 266 u_int8_tlength;
267 u_char ssid[33]; /* 32 + 1 for null */ 267 u_char ssid[33]; /* 32 + 1 for null */
268}; 268};
269 269
270 270
271struct rates_t { 271struct rates_t {
272 u_int8_telement_id; 272 u_int8_telement_id;
273 u_int8_tlength; 273 u_int8_tlength;
274 u_int8_trate[8]; 274 u_int8_trate[8];
275}; 275};
276 276
277 277
278struct challenge_t { 278struct challenge_t {
279 u_int8_telement_id; 279 u_int8_telement_id;
280 u_int8_tlength; 280 u_int8_tlength;
281 u_int8_ttext[254]; /* 1-253 + 1 for null */ 281 u_int8_ttext[254]; /* 1-253 + 1 for null */
282}; 282};
283 283
284 284
285struct fh_t { 285struct fh_t {
286 u_int8_telement_id; 286 u_int8_telement_id;
287 u_int8_tlength; 287 u_int8_tlength;
288 u_int16_tdwell_time; 288 u_int16_tdwell_time;
289 u_int8_thop_set; 289 u_int8_thop_set;
290 u_int8_t hop_pattern; 290 u_int8_t hop_pattern;
291 u_int8_thop_index; 291 u_int8_thop_index;
292}; 292};
293 293
294 294
295struct ds_t { 295struct ds_t {
296 u_int8_telement_id; 296 u_int8_telement_id;
297 u_int8_tlength; 297 u_int8_tlength;
298 u_int8_tchannel; 298 u_int8_tchannel;
299}; 299};
300 300
301 301
302struct cf_t { 302struct cf_t {
303 u_int8_telement_id; 303 u_int8_telement_id;
304 u_int8_tlength; 304 u_int8_tlength;
305 u_int8_tcount; 305 u_int8_tcount;
306 u_int8_tperiod; 306 u_int8_tperiod;
307 u_int16_tmax_duration; 307 u_int16_tmax_duration;
308 u_int16_tdur_remaing; 308 u_int16_tdur_remaing;
309}; 309};
310 310
311 311
312struct tim_t { 312struct tim_t {
313 u_int8_telement_id; 313 u_int8_telement_id;
314 u_int8_tlength; 314 u_int8_tlength;
315 u_int8_tcount; 315 u_int8_tcount;
316 u_int8_tperiod; 316 u_int8_tperiod;
317 u_int8_tbitmap_control; 317 u_int8_tbitmap_control;
318 u_int8_tbitmap[251]; 318 u_int8_tbitmap[251];
319}; 319};
320 320
321 #define E_SSID 0 321
322 #define E_RATES 1 322struct ibss_t {
323 #define E_FH 2 323 u_int8_telement_id;
324 #define E_DS 3 324 u_int8_tlength;
325 #define E_CF 4 325 u_int16_tatim_window;
326 #define E_TIM 5 326};
327 #define E_IBSS 6 327
328 #define E_CHALLENGE 16 328
329 #define E_CISCO 133 329#define E_SSID 0
330#define E_RATES 1
331#define E_FH 2
332#define E_DS 3
333#define E_CF 4
334#define E_TIM 5
335#define E_IBSS 6
336#define E_CHALLENGE 16
337#define E_CISCO 133
330 338
331 339
332struct ieee_802_11_mgmt_body { 340struct ieee_802_11_mgmt_body {
333 u_int8_t timestamp[8]; 341 u_int8_t timestamp[8];
334 u_int16_t beacon_interval; 342 u_int16_t beacon_interval;
335 // u_int16_t listen_interval; 343 // u_int16_t listen_interval;
336 // u_int16_t status_code; 344 // u_int16_t status_code;
337 // u_int16_t aid; 345 // u_int16_t aid;
338 // u_char ap[6]; 346 // u_char ap[6];
339 // u_int16_treason_code; 347 // u_int16_treason_code;
340 // u_int16_tauth_alg; 348 // u_int16_tauth_alg;
341 // u_int16_tauth_trans_seq_num; 349 // u_int16_tauth_trans_seq_num;
342// struct challenge_t challenge; 350// struct challenge_t challenge;
343 u_int16_tcapability_info; 351 u_int16_t capability_info;
344 struct ssid_tssid; 352 // struct ssid_tssid;
345 struct rates_t rates; 353 // struct rates_t rates;
346 struct ds_tds; 354 // struct ds_tds;
347 struct cf_tcf; 355 // struct cf_tcf;
348 struct fh_tfh; 356 // struct fh_tfh;
349 struct tim_ttim; 357 // struct tim_ttim;
350}; 358};
351 359
352 360
353struct ieee_802_11_data_body { 361struct ieee_802_11_data_body {
354//FIXME 362//FIXME
355}; 363};
356 364
357struct ctrl_rts_t { 365struct ctrl_rts_t {
358 u_int16_tfc; 366 u_int16_tfc;
359 u_int16_tduration; 367 u_int16_tduration;
360 u_int8_tra[6]; 368 u_int8_tra[6];
361 u_int8_tta[6]; 369 u_int8_tta[6];
362 u_int8_tfcs[4]; 370 u_int8_tfcs[4];
363}; 371};
364 372
365 #define CTRL_RTS_LEN(2+2+6+6+4) 373 #define CTRL_RTS_LEN(2+2+6+6+4)
366 374
367struct ctrl_cts_t { 375struct ctrl_cts_t {
368 u_int16_tfc; 376 u_int16_tfc;
369 u_int16_tduration; 377 u_int16_tduration;
370 u_int8_tra[6]; 378 u_int8_tra[6];
371 u_int8_tfcs[4]; 379 u_int8_tfcs[4];
372}; 380};
373 381
374 #define CTRL_CTS_LEN(2+2+6+4) 382 #define CTRL_CTS_LEN(2+2+6+4)
375 383
376struct ctrl_ack_t { 384struct ctrl_ack_t {
377 u_int16_tfc; 385 u_int16_tfc;
378 u_int16_tduration; 386 u_int16_tduration;
379 u_int8_tra[6]; 387 u_int8_tra[6];
380 u_int8_tfcs[4]; 388 u_int8_tfcs[4];
381}; 389};
382 390
383 #define CTRL_ACK_LEN(2+2+6+4) 391 #define CTRL_ACK_LEN(2+2+6+4)
384 392
385struct ctrl_ps_poll_t { 393struct ctrl_ps_poll_t {
386 u_int16_tfc; 394 u_int16_tfc;
387 u_int16_taid; 395 u_int16_taid;
388 u_int8_tbssid[6]; 396 u_int8_tbssid[6];
389 u_int8_tta[6]; 397 u_int8_tta[6];
390 u_int8_tfcs[4]; 398 u_int8_tfcs[4];
391}; 399};
392 400
393 #define CTRL_PS_POLL_LEN(2+2+6+6+4) 401 #define CTRL_PS_POLL_LEN(2+2+6+6+4)
394 402
395struct ctrl_end_t { 403struct ctrl_end_t {
396 u_int16_tfc; 404 u_int16_tfc;
397 u_int16_tduration; 405 u_int16_tduration;
398 u_int8_tra[6]; 406 u_int8_tra[6];
399 u_int8_tbssid[6]; 407 u_int8_tbssid[6];
400 u_int8_tfcs[4]; 408 u_int8_tfcs[4];
401}; 409};
402 410
403 #define CTRL_END_LEN(2+2+6+6+4) 411 #define CTRL_END_LEN(2+2+6+6+4)
404 412
405struct ctrl_end_ack_t { 413struct ctrl_end_ack_t {
406 u_int16_tfc; 414 u_int16_tfc;
407 u_int16_tduration; 415 u_int16_tduration;
408 u_int8_tra[6]; 416 u_int8_tra[6];
409 u_int8_tbssid[6]; 417 u_int8_tbssid[6];
410 u_int8_tfcs[4]; 418 u_int8_tfcs[4];
411}; 419};
412 420
413 #define CTRL_END_ACK_LEN(2+2+6+6+4) 421 #define CTRL_END_ACK_LEN(2+2+6+6+4)
414 422
415 #define IV_IV(iv)((iv) & 0xFFFFFF) 423 #define IV_IV(iv)((iv) & 0xFFFFFF)
416 #define IV_PAD(iv)(((iv) >> 24) & 0x3F) 424 #define IV_PAD(iv)(((iv) >> 24) & 0x3F)
417 #define IV_KEYID(iv)(((iv) >> 30) & 0x03) 425 #define IV_KEYID(iv)(((iv) >> 30) & 0x03)
418 426
419#endif 427#endif
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index 1d3b9fe..25c70e0 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -1,774 +1,792 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2003 by the Wellenreiter team: 3              Copyright (C) 2003 by the Wellenreiter team:
4 Martin J. Muench <mjm@remote-exploit.org> 4 Martin J. Muench <mjm@remote-exploit.org>
5 Max Moser <mmo@remote-exploit.org 5 Max Moser <mmo@remote-exploit.org
6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34/* OPIE */ 34/* OPIE */
35 35
36#include <opie2/onetwork.h> 36#include <opie2/onetwork.h>
37 37
38/* QT */ 38/* QT */
39 39
40#include <qfile.h> 40#include <qfile.h>
41#include <qtextstream.h> 41#include <qtextstream.h>
42 42
43/* UNIX */ 43/* UNIX */
44 44
45#include <arpa/inet.h> 45#include <arpa/inet.h>
46#include <cerrno> 46#include <cerrno>
47#include <cstring> 47#include <cstring>
48#include <cstdlib> 48#include <cstdlib>
49#include <math.h> 49#include <math.h>
50#include <sys/ioctl.h> 50#include <sys/ioctl.h>
51#include <sys/socket.h> 51#include <sys/socket.h>
52#include <sys/types.h> 52#include <sys/types.h>
53#include <unistd.h> 53#include <unistd.h>
54#include <linux/wireless.h> 54#include <linux/wireless.h>
55 55
56using namespace std; 56using namespace std;
57 57
58/*====================================================================================== 58/*======================================================================================
59 * ONetwork 59 * ONetwork
60 *======================================================================================*/ 60 *======================================================================================*/
61 61
62ONetwork* ONetwork::_instance = 0; 62ONetwork* ONetwork::_instance = 0;
63 63
64ONetwork::ONetwork() 64ONetwork::ONetwork()
65{ 65{
66 qDebug( "ONetwork::ONetwork()" ); 66 qDebug( "ONetwork::ONetwork()" );
67 synchronize(); 67 synchronize();
68} 68}
69 69
70void ONetwork::synchronize() 70void ONetwork::synchronize()
71{ 71{
72 // gather available interfaces by inspecting /proc/net/dev 72 // gather available interfaces by inspecting /proc/net/dev
73 // we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices 73 // we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices
74 74
75 _interfaces.clear(); 75 _interfaces.clear();
76 QString str; 76 QString str;
77 QFile f( "/proc/net/dev" ); 77 QFile f( "/proc/net/dev" );
78 bool hasFile = f.open( IO_ReadOnly ); 78 bool hasFile = f.open( IO_ReadOnly );
79 if ( !hasFile ) 79 if ( !hasFile )
80 { 80 {
81 qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); 81 qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" );
82 return; 82 return;
83 } 83 }
84 QTextStream s( &f ); 84 QTextStream s( &f );
85 s.readLine(); 85 s.readLine();
86 s.readLine(); 86 s.readLine();
87 while ( !s.atEnd() ) 87 while ( !s.atEnd() )
88 { 88 {
89 s >> str; 89 s >> str;
90 str.truncate( str.find( ':' ) ); 90 str.truncate( str.find( ':' ) );
91 qDebug( "ONetwork: found interface '%s'", (const char*) str ); 91 qDebug( "ONetwork: found interface '%s'", (const char*) str );
92 ONetworkInterface* iface; 92 ONetworkInterface* iface;
93 if ( isWirelessInterface( str ) ) 93 if ( isWirelessInterface( str ) )
94 { 94 {
95 iface = new OWirelessNetworkInterface( str ); 95 iface = new OWirelessNetworkInterface( str );
96 qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); 96 qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str );
97 } 97 }
98 else 98 else
99 { 99 {
100 iface = new ONetworkInterface( str ); 100 iface = new ONetworkInterface( str );
101 } 101 }
102 _interfaces.insert( str, iface ); 102 _interfaces.insert( str, iface );
103 s.readLine(); 103 s.readLine();
104 } 104 }
105} 105}
106 106
107 107
108ONetworkInterface* ONetwork::interface( QString iface ) const 108ONetworkInterface* ONetwork::interface( QString iface ) const
109{ 109{
110 return _interfaces[iface]; 110 return _interfaces[iface];
111} 111}
112 112
113 113
114ONetwork* ONetwork::instance() 114ONetwork* ONetwork::instance()
115{ 115{
116 if ( !_instance ) _instance = new ONetwork(); 116 if ( !_instance ) _instance = new ONetwork();
117 return _instance; 117 return _instance;
118} 118}
119 119
120 120
121ONetwork::InterfaceIterator ONetwork::iterator() const 121ONetwork::InterfaceIterator ONetwork::iterator() const
122{ 122{
123 return ONetwork::InterfaceIterator( _interfaces ); 123 return ONetwork::InterfaceIterator( _interfaces );
124} 124}
125 125
126 126
127bool ONetwork::isWirelessInterface( const char* name ) const 127bool ONetwork::isWirelessInterface( const char* name ) const
128{ 128{
129 int sfd = socket( AF_INET, SOCK_DGRAM, 0 ); 129 int sfd = socket( AF_INET, SOCK_DGRAM, 0 );
130 iwreqstruct iwr; 130 iwreqstruct iwr;
131 memset( &iwr, 0, sizeof( iwreqstruct ) ); 131 memset( &iwr, 0, sizeof( iwreqstruct ) );
132 strcpy( (char*) &iwr.ifr_name, name ); 132 strcpy( (char*) &iwr.ifr_name, name );
133 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); 133 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr );
134 if ( result == -1 ) 134 if ( result == -1 )
135 qDebug( "ONetwork::ioctl(): SIOCGIWNAME failed: %d (%s)", result, strerror( errno ) ); 135 qDebug( "ONetwork::ioctl(): SIOCGIWNAME failed: %d (%s)", result, strerror( errno ) );
136 else 136 else
137 qDebug( "ONetwork::ioctl(): SIOCGIWNAME ok." ); 137 qDebug( "ONetwork::ioctl(): SIOCGIWNAME ok." );
138 return ( result != -1 ); 138 return ( result != -1 );
139} 139}
140 140
141/*====================================================================================== 141/*======================================================================================
142 * ONetworkInterface 142 * ONetworkInterface
143 *======================================================================================*/ 143 *======================================================================================*/
144 144
145ONetworkInterface::ONetworkInterface( const QString& name ) 145ONetworkInterface::ONetworkInterface( const QString& name )
146 :_name( name ), _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) 146 :_name( name ), _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 )
147{ 147{
148 qDebug( "ONetworkInterface::ONetworkInterface()" ); 148 qDebug( "ONetworkInterface::ONetworkInterface()" );
149 init(); 149 init();
150} 150}
151 151
152 152
153ifreqstruct& ONetworkInterface::ifr() const 153ifreqstruct& ONetworkInterface::ifr() const
154{ 154{
155 return _ifr; 155 return _ifr;
156} 156}
157 157
158 158
159void ONetworkInterface::init() 159void ONetworkInterface::init()
160{ 160{
161 qDebug( "ONetworkInterface::init()" ); 161 qDebug( "ONetworkInterface::init()" );
162 162
163 memset( &_ifr, 0, sizeof( struct ifreq ) ); 163 memset( &_ifr, 0, sizeof( struct ifreq ) );
164 164
165 if ( _sfd == -1 ) 165 if ( _sfd == -1 )
166 { 166 {
167 qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", (const char*) _name ); 167 qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", (const char*) _name );
168 return; 168 return;
169 } 169 }
170} 170}
171 171
172 172
173bool ONetworkInterface::ioctl( int call, ifreqstruct& ifreq ) const 173bool ONetworkInterface::ioctl( int call, ifreqstruct& ifreq ) const
174{ 174{
175 int result = ::ioctl( _sfd, call, &ifreq ); 175 int result = ::ioctl( _sfd, call, &ifreq );
176 if ( result == -1 ) 176 if ( result == -1 )
177 qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); 177 qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) );
178 else 178 else
179 qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Ok.", call ); 179 qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Ok.", call );
180 return ( result != -1 ); 180 return ( result != -1 );
181} 181}
182 182
183 183
184bool ONetworkInterface::ioctl( int call ) const 184bool ONetworkInterface::ioctl( int call ) const
185{ 185{
186 strcpy( _ifr.ifr_name, (const char*) _name ); 186 strcpy( _ifr.ifr_name, (const char*) _name );
187 return ioctl( call, _ifr ); 187 return ioctl( call, _ifr );
188} 188}
189 189
190 190
191bool ONetworkInterface::isLoopback() const 191bool ONetworkInterface::isLoopback() const
192{ 192{
193 ioctl( SIOCGIFFLAGS ); 193 ioctl( SIOCGIFFLAGS );
194 return _ifr.ifr_flags & IFF_LOOPBACK; 194 return _ifr.ifr_flags & IFF_LOOPBACK;
195} 195}
196 196
197 197
198bool ONetworkInterface::setUp( bool b ) 198bool ONetworkInterface::setUp( bool b )
199{ 199{
200 ioctl( SIOCGIFFLAGS ); 200 ioctl( SIOCGIFFLAGS );
201 if ( b ) _ifr.ifr_flags |= IFF_UP; 201 if ( b ) _ifr.ifr_flags |= IFF_UP;
202 else _ifr.ifr_flags &= (~IFF_UP); 202 else _ifr.ifr_flags &= (~IFF_UP);
203 return ioctl( SIOCSIFFLAGS ); 203 return ioctl( SIOCSIFFLAGS );
204} 204}
205 205
206 206
207bool ONetworkInterface::isUp() const 207bool ONetworkInterface::isUp() const
208{ 208{
209 ioctl( SIOCGIFFLAGS ); 209 ioctl( SIOCGIFFLAGS );
210 return _ifr.ifr_flags & IFF_UP; 210 return _ifr.ifr_flags & IFF_UP;
211} 211}
212 212
213 213
214QString ONetworkInterface::ipV4Address() const 214QString ONetworkInterface::ipV4Address() const
215{ 215{
216 if ( ioctl( SIOCGIFADDR ) ) 216 if ( ioctl( SIOCGIFADDR ) )
217 { 217 {
218 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; 218 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr;
219 //FIXME: Use QHostAddress here 219 //FIXME: Use QHostAddress here
220 return QString( inet_ntoa( sa->sin_addr ) ); 220 return QString( inet_ntoa( sa->sin_addr ) );
221 } 221 }
222 else 222 else
223 return "<unknown>"; 223 return "<unknown>";
224} 224}
225 225
226 226
227OMacAddress ONetworkInterface::macAddress() const 227OMacAddress ONetworkInterface::macAddress() const
228{ 228{
229 if ( ioctl( SIOCGIFHWADDR ) ) 229 if ( ioctl( SIOCGIFHWADDR ) )
230 { 230 {
231 return OMacAddress( _ifr ); 231 return OMacAddress( _ifr );
232 } 232 }
233 else 233 else
234 { 234 {
235 return OMacAddress::unknown; 235 return OMacAddress::unknown;
236 } 236 }
237} 237}
238 238
239 239
240void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) 240void ONetworkInterface::setMonitoring( OMonitoringInterface* m )
241{ 241{
242 _mon = m; 242 _mon = m;
243 qDebug( "ONetwork::setMonitoring(): Installed monitoring interface '%s'", (const char*) m->name() ); 243 qDebug( "ONetwork::setMonitoring(): Installed monitoring interface '%s'", (const char*) m->name() );
244} 244}
245 245
246 246
247OMonitoringInterface* ONetworkInterface::monitoring() const 247OMonitoringInterface* ONetworkInterface::monitoring() const
248{ 248{
249 return _mon; 249 return _mon;
250} 250}
251 251
252 252
253const QString& ONetworkInterface::name() const 253const QString& ONetworkInterface::name() const
254{ 254{
255 return _name; 255 return _name;
256} 256}
257 257
258 258
259ONetworkInterface::~ONetworkInterface() 259ONetworkInterface::~ONetworkInterface()
260{ 260{
261 qDebug( "ONetworkInterface::~ONetworkInterface()" ); 261 qDebug( "ONetworkInterface::~ONetworkInterface()" );
262 if ( _sfd != -1 ) ::close( _sfd ); 262 if ( _sfd != -1 ) ::close( _sfd );
263} 263}
264 264
265 265
266bool ONetworkInterface::setPromiscuousMode( bool b ) 266bool ONetworkInterface::setPromiscuousMode( bool b )
267{ 267{
268 ioctl( SIOCGIFFLAGS ); 268 ioctl( SIOCGIFFLAGS );
269 if ( b ) _ifr.ifr_flags |= IFF_PROMISC; 269 if ( b ) _ifr.ifr_flags |= IFF_PROMISC;
270 else _ifr.ifr_flags &= (~IFF_PROMISC); 270 else _ifr.ifr_flags &= (~IFF_PROMISC);
271 return ioctl( SIOCSIFFLAGS ); 271 return ioctl( SIOCSIFFLAGS );
272} 272}
273 273
274 274
275bool ONetworkInterface::promiscuousMode() const 275bool ONetworkInterface::promiscuousMode() const
276{ 276{
277 ioctl( SIOCGIFFLAGS ); 277 ioctl( SIOCGIFFLAGS );
278 return _ifr.ifr_flags & IFF_PROMISC; 278 return _ifr.ifr_flags & IFF_PROMISC;
279} 279}
280 280
281 281
282bool ONetworkInterface::isWireless() const 282bool ONetworkInterface::isWireless() const
283{ 283{
284 return ioctl( SIOCGIWNAME ); 284 return ioctl( SIOCGIWNAME );
285} 285}
286 286
287 287
288/*====================================================================================== 288/*======================================================================================
289 * OChannelHopper 289 * OChannelHopper
290 *======================================================================================*/ 290 *======================================================================================*/
291 291
292OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) 292OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface )
293 :QObject( 0, "Mickey's funky hopper" ), 293 :QObject( 0, "Mickey's funky hopper" ),
294 _iface( iface ), _interval( 0 ), _channel( 0 ), _tid( 0 ) 294 _iface( iface ), _interval( 0 ), _channel( 1 ), _tid( 0 ),
295 _maxChannel( iface->channels()+1 )
295{ 296{
296} 297}
297 298
298 299
299OChannelHopper::~OChannelHopper() 300OChannelHopper::~OChannelHopper()
300{ 301{
301} 302}
302 303
303 304
305bool OChannelHopper::isActive() const
306{
307 return _tid;
308}
309
310
311int OChannelHopper::channel() const
312{
313 return _channel;
314}
315
316
304void OChannelHopper::timerEvent( QTimerEvent* ) 317void OChannelHopper::timerEvent( QTimerEvent* )
305{ 318{
306 //FIXME: Get available channels from OWirelessNetworkInterface 319 if ( !--_channel ) _channel = _maxChannel;
307 if ( --_channel < 0 ) _channel = 13;
308 _iface->setChannel( _channel ); 320 _iface->setChannel( _channel );
309 qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", 321 qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'",
310 _channel, (const char*) _iface->name() ); 322 _channel, (const char*) _iface->name() );
311} 323}
312 324
313 325
314void OChannelHopper::setInterval( int interval ) 326void OChannelHopper::setInterval( int interval )
315{ 327{
316 if ( interval == _interval ) 328 if ( interval == _interval )
317 return; 329 return;
318 330
319 if ( _interval ) 331 if ( _interval )
320 killTimer( _tid ); 332 killTimer( _tid );
321 333
334 _tid = 0;
322 _interval = interval; 335 _interval = interval;
323 336
324 if ( _interval ) 337 if ( _interval )
325 { 338 {
326 _tid = startTimer( interval ); 339 _tid = startTimer( interval );
327 } 340 }
328} 341}
329 342
330 343
331int OChannelHopper::interval() const 344int OChannelHopper::interval() const
332{ 345{
333 return _interval; 346 return _interval;
334} 347}
335 348
336 349
337/*====================================================================================== 350/*======================================================================================
338 * OWirelessNetworkInterface 351 * OWirelessNetworkInterface
339 *======================================================================================*/ 352 *======================================================================================*/
340 353
341OWirelessNetworkInterface::OWirelessNetworkInterface( const QString& name ) 354OWirelessNetworkInterface::OWirelessNetworkInterface( const QString& name )
342 :ONetworkInterface( name ), _hopper( this ) 355 :ONetworkInterface( name ), _hopper( 0 )
343{ 356{
344 qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); 357 qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" );
345 init(); 358 init();
346} 359}
347 360
348 361
349OWirelessNetworkInterface::~OWirelessNetworkInterface() 362OWirelessNetworkInterface::~OWirelessNetworkInterface()
350{ 363{
351} 364}
352 365
353 366
354iwreqstruct& OWirelessNetworkInterface::iwr() const 367iwreqstruct& OWirelessNetworkInterface::iwr() const
355{ 368{
356 return _iwr; 369 return _iwr;
357} 370}
358 371
359 372
360void OWirelessNetworkInterface::init() 373void OWirelessNetworkInterface::init()
361{ 374{
362 qDebug( "OWirelessNetworkInterface::init()" ); 375 qDebug( "OWirelessNetworkInterface::init()" );
363 376
364 memset( &_iwr, 0, sizeof( struct iwreq ) ); 377 memset( &_iwr, 0, sizeof( struct iwreq ) );
365 378
366 // IEEE802.11(b) radio frequency channels 379 // IEEE802.11(b) radio frequency channels
367 //FIXME: get these directly from the interface 380 //FIXME: get these directly from the interface
368 //FIXME: check if these channels are off-by-one 381 //FIXME: check if these channels are off-by-one
369 382
370 iwrangestruct range; 383 iwrangestruct range;
371 _iwr.u.data.pointer = (char*) &range; 384 _iwr.u.data.pointer = (char*) &range;
372 _iwr.u.data.length = sizeof( iwrangestruct ); 385 _iwr.u.data.length = sizeof( iwrangestruct );
373 if ( !wioctl( SIOCGIWRANGE ) ) 386 if ( !wioctl( SIOCGIWRANGE ) )
374 { 387 {
375 qDebug( "OWirelessNetworkInterface::init(): SIOCGIWRANGE failed (%s)", strerror( errno ) ); 388 qDebug( "OWirelessNetworkInterface::init(): SIOCGIWRANGE failed (%s)", strerror( errno ) );
376 return; 389 return;
377 } 390 }
378 391
379 //TODO: Find out what the difference between num_channel and
380 // num_frequency is about.
381
382 for ( int i = 0; i < range.num_frequency; ++i ) 392 for ( int i = 0; i < range.num_frequency; ++i )
383 { 393 {
384 int freq = (int) ( double( range.freq[i].m ) * pow( 10, range.freq[i].e ) / 1000000.0 ); 394 int freq = (int) ( double( range.freq[i].m ) * pow( 10, range.freq[i].e ) / 1000000.0 );
385 _channels.insert( freq, i ); 395 _channels.insert( freq, i+1 );
386 } 396 }
387} 397}
388 398
389 399
390QString OWirelessNetworkInterface::associatedAP() const 400QString OWirelessNetworkInterface::associatedAP() const
391{ 401{
392 //FIXME: use OMacAddress 402 //FIXME: use OMacAddress
393 QString mac; 403 QString mac;
394 404
395 if ( ioctl( SIOCGIWAP ) ) 405 if ( ioctl( SIOCGIWAP ) )
396 { 406 {
397 mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", 407 mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
398 _ifr.ifr_hwaddr.sa_data[0]&0xff, 408 _ifr.ifr_hwaddr.sa_data[0]&0xff,
399 _ifr.ifr_hwaddr.sa_data[1]&0xff, 409 _ifr.ifr_hwaddr.sa_data[1]&0xff,
400 _ifr.ifr_hwaddr.sa_data[2]&0xff, 410 _ifr.ifr_hwaddr.sa_data[2]&0xff,
401 _ifr.ifr_hwaddr.sa_data[3]&0xff, 411 _ifr.ifr_hwaddr.sa_data[3]&0xff,
402 _ifr.ifr_hwaddr.sa_data[4]&0xff, 412 _ifr.ifr_hwaddr.sa_data[4]&0xff,
403 _ifr.ifr_hwaddr.sa_data[5]&0xff ); 413 _ifr.ifr_hwaddr.sa_data[5]&0xff );
404 } 414 }
405 else 415 else
406 { 416 {
407 mac = "<Unknown>"; 417 mac = "<Unknown>";
408 } 418 }
409 return mac; 419 return mac;
410} 420}
411 421
412 422
413int OWirelessNetworkInterface::channel() const 423int OWirelessNetworkInterface::channel() const
414{ 424{
425 //FIXME: When monitoring enabled, then use it
426 //FIXME: to gather the current RF channel
427 //FIXME: Until then, get active channel from hopper.
428 if ( _hopper && _hopper->isActive() )
429 return _hopper->channel();
430
415 if ( !wioctl( SIOCGIWFREQ ) ) 431 if ( !wioctl( SIOCGIWFREQ ) )
416 { 432 {
417 return -1; 433 return -1;
418 } 434 }
419 else 435 else
420 { 436 {
421 //FIXME: This is off-by-one !? Why?
422 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10, _iwr.u.freq.e ) / 1000000) ]; 437 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10, _iwr.u.freq.e ) / 1000000) ];
423 } 438 }
424} 439}
425 440
426 441
427void OWirelessNetworkInterface::setChannel( int c ) const 442void OWirelessNetworkInterface::setChannel( int c ) const
428{ 443{
429 if ( !_mon ) 444 if ( !_mon )
430 { 445 {
431 memset( &_iwr, 0, sizeof( iwreqstruct ) ); 446 memset( &_iwr, 0, sizeof( iwreqstruct ) );
432 _iwr.u.freq.m = c; 447 _iwr.u.freq.m = c;
433 _iwr.u.freq.e = 0; 448 _iwr.u.freq.e = 0;
434 wioctl( SIOCSIWFREQ ); 449 wioctl( SIOCSIWFREQ );
435 } 450 }
436 else 451 else
437 { 452 {
438 _mon->setChannel( c ); 453 _mon->setChannel( c );
439 } 454 }
440} 455}
441 456
442 457
443double OWirelessNetworkInterface::frequency() const 458double OWirelessNetworkInterface::frequency() const
444{ 459{
445 if ( !wioctl( SIOCGIWFREQ ) ) 460 if ( !wioctl( SIOCGIWFREQ ) )
446 { 461 {
447 return -1.0; 462 return -1.0;
448 } 463 }
449 else 464 else
450 { 465 {
451 return double( _iwr.u.freq.m ) * pow( 10, _iwr.u.freq.e ) / 1000000000.0; 466 return double( _iwr.u.freq.m ) * pow( 10, _iwr.u.freq.e ) / 1000000000.0;
452 } 467 }
453} 468}
454 469
455 470
456int OWirelessNetworkInterface::channels() const 471int OWirelessNetworkInterface::channels() const
457{ 472{
458 return _channels.count(); 473 return _channels.count();
459} 474}
460 475
461 476
462void OWirelessNetworkInterface::setChannelHopping( int interval ) 477void OWirelessNetworkInterface::setChannelHopping( int interval )
463{ 478{
464 _hopper.setInterval( interval ); 479 if ( !_hopper ) _hopper = new OChannelHopper( this );
480 _hopper->setInterval( interval );
481 //FIXME: When and by whom will the channel hopper be deleted?
465} 482}
466 483
467 484
468int OWirelessNetworkInterface::channelHopping() const 485int OWirelessNetworkInterface::channelHopping() const
469{ 486{
470 return _hopper.interval(); 487 return _hopper->interval();
471} 488}
472 489
473 490
474void OWirelessNetworkInterface::setMonitorMode( bool b ) 491void OWirelessNetworkInterface::setMonitorMode( bool b )
475{ 492{
476 if ( _mon ) 493 if ( _mon )
477 _mon->setEnabled( b ); 494 _mon->setEnabled( b );
478 else 495 else
479 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); 496 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" );
480} 497}
481 498
499
482bool OWirelessNetworkInterface::monitorMode() const 500bool OWirelessNetworkInterface::monitorMode() const
483{ 501{
484 return _mon ? _mon->enabled() : false; 502 return _mon ? _mon->enabled() : false;
485} 503}
486 504
487 505
488QString OWirelessNetworkInterface::nickName() const 506QString OWirelessNetworkInterface::nickName() const
489{ 507{
490 char str[IW_ESSID_MAX_SIZE]; 508 char str[IW_ESSID_MAX_SIZE];
491 _iwr.u.data.pointer = &str[0]; 509 _iwr.u.data.pointer = &str[0];
492 _iwr.u.data.length = IW_ESSID_MAX_SIZE; 510 _iwr.u.data.length = IW_ESSID_MAX_SIZE;
493 if ( !wioctl( SIOCGIWNICKN ) ) 511 if ( !wioctl( SIOCGIWNICKN ) )
494 { 512 {
495 return "<unknown>"; 513 return "<unknown>";
496 } 514 }
497 else 515 else
498 { 516 {
499 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string 517 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string
500 return str; 518 return str;
501 } 519 }
502} 520}
503 521
504 522
505QString OWirelessNetworkInterface::SSID() const 523QString OWirelessNetworkInterface::SSID() const
506{ 524{
507 char str[IW_ESSID_MAX_SIZE]; 525 char str[IW_ESSID_MAX_SIZE];
508 _iwr.u.essid.pointer = &str[0]; 526 _iwr.u.essid.pointer = &str[0];
509 _iwr.u.essid.length = IW_ESSID_MAX_SIZE; 527 _iwr.u.essid.length = IW_ESSID_MAX_SIZE;
510 if ( !wioctl( SIOCGIWESSID ) ) 528 if ( !wioctl( SIOCGIWESSID ) )
511 { 529 {
512 return "<unknown>"; 530 return "<unknown>";
513 } 531 }
514 else 532 else
515 { 533 {
516 return str; 534 return str;
517 } 535 }
518} 536}
519 537
520 538
521void OWirelessNetworkInterface::setSSID( const QString& ssid ) 539void OWirelessNetworkInterface::setSSID( const QString& ssid )
522{ 540{
523 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); 541 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid );
524 _iwr.u.essid.length = ssid.length(); 542 _iwr.u.essid.length = ssid.length();
525 wioctl( SIOCSIWESSID ); 543 wioctl( SIOCSIWESSID );
526} 544}
527 545
528 546
529bool OWirelessNetworkInterface::wioctl( int call, iwreqstruct& iwreq ) const 547bool OWirelessNetworkInterface::wioctl( int call, iwreqstruct& iwreq ) const
530{ 548{
531 int result = ::ioctl( _sfd, call, &iwreq ); 549 int result = ::ioctl( _sfd, call, &iwreq );
532 if ( result == -1 ) 550 if ( result == -1 )
533 qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); 551 qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) );
534 else 552 else
535 qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Ok.", call ); 553 qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Ok.", call );
536 return ( result != -1 ); 554 return ( result != -1 );
537} 555}
538 556
539 557
540bool OWirelessNetworkInterface::wioctl( int call ) const 558bool OWirelessNetworkInterface::wioctl( int call ) const
541{ 559{
542 strcpy( _iwr.ifr_name, (const char*) _name ); 560 strcpy( _iwr.ifr_name, (const char*) _name );
543 return wioctl( call, _iwr ); 561 return wioctl( call, _iwr );
544} 562}
545 563
546 564
547/*====================================================================================== 565/*======================================================================================
548 * OMonitoringInterface 566 * OMonitoringInterface
549 *======================================================================================*/ 567 *======================================================================================*/
550 568
551OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface ) 569OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface )
552 :_enabled( false ), _if( static_cast<OWirelessNetworkInterface*>( iface ) ) 570 :_enabled( false ), _if( static_cast<OWirelessNetworkInterface*>( iface ) )
553{ 571{
554} 572}
555 573
556 574
557OMonitoringInterface::~OMonitoringInterface() 575OMonitoringInterface::~OMonitoringInterface()
558{ 576{
559} 577}
560 578
561 579
562void OMonitoringInterface::setChannel( int c ) 580void OMonitoringInterface::setChannel( int c )
563{ 581{
564 // use standard WE channel switching protocol 582 // use standard WE channel switching protocol
565 memset( &_if->_iwr, 0, sizeof( iwreqstruct ) ); 583 memset( &_if->_iwr, 0, sizeof( iwreqstruct ) );
566 _if->_iwr.u.freq.m = c; 584 _if->_iwr.u.freq.m = c;
567 _if->_iwr.u.freq.e = 0; 585 _if->_iwr.u.freq.e = 0;
568 _if->wioctl( SIOCSIWFREQ ); 586 _if->wioctl( SIOCSIWFREQ );
569} 587}
570 588
571 589
572bool OMonitoringInterface::enabled() const 590bool OMonitoringInterface::enabled() const
573{ 591{
574 return _enabled; 592 return _enabled;
575} 593}
576 594
577void OMonitoringInterface::setEnabled( bool b ) 595void OMonitoringInterface::setEnabled( bool b )
578{ 596{
579 // open a packet capturer here or leave this to 597 // open a packet capturer here or leave this to
580 // the client code? 598 // the client code?
581 599
582 /* 600 /*
583 601
584 if ( b ) 602 if ( b )
585 { 603 {
586 OPacketCapturer* opcap = new OPacketCapturer(); 604 OPacketCapturer* opcap = new OPacketCapturer();
587 opcap->open( _if->name() ); 605 opcap->open( _if->name() );
588 } 606 }
589 */ 607 */
590 608
591 _enabled = b; 609 _enabled = b;
592 610
593} 611}
594 612
595/*====================================================================================== 613/*======================================================================================
596 * OCiscoMonitoringInterface 614 * OCiscoMonitoringInterface
597 *======================================================================================*/ 615 *======================================================================================*/
598 616
599OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface ) 617OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface )
600 :OMonitoringInterface( iface ) 618 :OMonitoringInterface( iface )
601{ 619{
602 iface->setMonitoring( this ); 620 iface->setMonitoring( this );
603} 621}
604 622
605 623
606OCiscoMonitoringInterface::~OCiscoMonitoringInterface() 624OCiscoMonitoringInterface::~OCiscoMonitoringInterface()
607{ 625{
608} 626}
609 627
610 628
611void OCiscoMonitoringInterface::setEnabled( bool b ) 629void OCiscoMonitoringInterface::setEnabled( bool b )
612{ 630{
613 QString fname; 631 QString fname;
614 fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); 632 fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() );
615 QFile f( fname ); 633 QFile f( fname );
616 if ( !f.exists() ) return; 634 if ( !f.exists() ) return;
617 635
618 if ( f.open( IO_WriteOnly ) ) 636 if ( f.open( IO_WriteOnly ) )
619 { 637 {
620 QTextStream s( &f ); 638 QTextStream s( &f );
621 s << "Mode: r"; 639 s << "Mode: r";
622 s << "Mode: y"; 640 s << "Mode: y";
623 s << "XmitPower: 1"; 641 s << "XmitPower: 1";
624 642
625 OMonitoringInterface::setEnabled( b ); 643 OMonitoringInterface::setEnabled( b );
626 644
627 } 645 }
628 646
629 // flushing and closing will be done automatically when f goes out of scope 647 // flushing and closing will be done automatically when f goes out of scope
630} 648}
631 649
632 650
633QString OCiscoMonitoringInterface::name() const 651QString OCiscoMonitoringInterface::name() const
634{ 652{
635 return "cisco"; 653 return "cisco";
636} 654}
637 655
638 656
639void OCiscoMonitoringInterface::setChannel( int ) 657void OCiscoMonitoringInterface::setChannel( int )
640{ 658{
641 // cisco devices automatically switch channels when in monitor mode 659 // cisco devices automatically switch channels when in monitor mode
642} 660}
643 661
644 662
645/*====================================================================================== 663/*======================================================================================
646 * OWlanNGMonitoringInterface 664 * OWlanNGMonitoringInterface
647 *======================================================================================*/ 665 *======================================================================================*/
648 666
649 667
650OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface ) 668OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface )
651 :OMonitoringInterface( iface ) 669 :OMonitoringInterface( iface )
652{ 670{
653 iface->setMonitoring( this ); 671 iface->setMonitoring( this );
654} 672}
655 673
656 674
657OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() 675OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface()
658{ 676{
659} 677}
660 678
661 679
662void OWlanNGMonitoringInterface::setEnabled( bool b ) 680void OWlanNGMonitoringInterface::setEnabled( bool b )
663{ 681{
664 //FIXME: do nothing if its already in the same mode 682 //FIXME: do nothing if its already in the same mode
665 683
666 QString enable = b ? "true" : "false"; 684 QString enable = b ? "true" : "false";
667 QString cmd; 685 QString cmd;
668 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s", (const char*) _if->name(), 1, (const char*) enable ); 686 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s", (const char*) _if->name(), 1, (const char*) enable );
669 system( cmd ); 687 system( cmd );
670 688
671 OMonitoringInterface::setEnabled( b ); 689 OMonitoringInterface::setEnabled( b );
672} 690}
673 691
674 692
675QString OWlanNGMonitoringInterface::name() const 693QString OWlanNGMonitoringInterface::name() const
676{ 694{
677 return "wlan-ng"; 695 return "wlan-ng";
678} 696}
679 697
680 698
681void OWlanNGMonitoringInterface::setChannel( int ) 699void OWlanNGMonitoringInterface::setChannel( int )
682{ 700{
683 // wlan-ng devices automatically switch channels when in monitor mode 701 // wlan-ng devices automatically switch channels when in monitor mode
684} 702}
685 703
686 704
687/*====================================================================================== 705/*======================================================================================
688 * OHostAPMonitoringInterface 706 * OHostAPMonitoringInterface
689 *======================================================================================*/ 707 *======================================================================================*/
690 708
691OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface ) 709OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface )
692 :OMonitoringInterface( iface ) 710 :OMonitoringInterface( iface )
693{ 711{
694 iface->setMonitoring( this ); 712 iface->setMonitoring( this );
695} 713}
696 714
697OHostAPMonitoringInterface::~OHostAPMonitoringInterface() 715OHostAPMonitoringInterface::~OHostAPMonitoringInterface()
698{ 716{
699} 717}
700 718
701void OHostAPMonitoringInterface::setEnabled( bool b ) 719void OHostAPMonitoringInterface::setEnabled( bool b )
702{ 720{
703 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 721 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15
704 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring 722 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring
705 723
706 #if WIRELESS_EXT > 14 724 #if WIRELESS_EXT > 14
707 _if->_iwr.u.mode = IW_MODE_MONITOR; 725 _if->_iwr.u.mode = IW_MODE_MONITOR;
708 _if->wioctl( SIOCSIWMODE ); 726 _if->wioctl( SIOCSIWMODE );
709 #else 727 #else
710 int* args = (int*) &_if._iwr.u.name; 728 int* args = (int*) &_if._iwr.u.name;
711 args[0] = 2; 729 args[0] = 2;
712 args[1] = 0; 730 args[1] = 0;
713 _if->wioctl( SIOCDEVPRIVATE ); 731 _if->wioctl( SIOCDEVPRIVATE );
714 #endif 732 #endif
715 733
716 OMonitoringInterface::setEnabled( b ); 734 OMonitoringInterface::setEnabled( b );
717} 735}
718 736
719 737
720QString OHostAPMonitoringInterface::name() const 738QString OHostAPMonitoringInterface::name() const
721{ 739{
722 return "hostap"; 740 return "hostap";
723} 741}
724 742
725 743
726/*====================================================================================== 744/*======================================================================================
727 * OOrinocoNetworkInterface 745 * OOrinocoNetworkInterface
728 *======================================================================================*/ 746 *======================================================================================*/
729 747
730OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface ) 748OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface )
731 :OMonitoringInterface( iface ) 749 :OMonitoringInterface( iface )
732{ 750{
733 iface->setMonitoring( this ); 751 iface->setMonitoring( this );
734} 752}
735 753
736 754
737OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() 755OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface()
738{ 756{
739} 757}
740 758
741 759
742void OOrinocoMonitoringInterface::setChannel( int c ) 760void OOrinocoMonitoringInterface::setChannel( int c )
743{ 761{
744 // call iwpriv <device> monitor 2 <channel> 762 // call iwpriv <device> monitor 2 <channel>
745 int* args = (int*) &_if->_iwr.u.name; 763 int* args = (int*) &_if->_iwr.u.name;
746 args[0] = 2; 764 args[0] = 2;
747 args[1] = c; 765 args[1] = c;
748 _if->wioctl( SIOCIWFIRSTPRIV + 0x8 ); 766 _if->wioctl( SIOCIWFIRSTPRIV + 0x8 );
749} 767}
750 768
751 769
752void OOrinocoMonitoringInterface::setEnabled( bool b ) 770void OOrinocoMonitoringInterface::setEnabled( bool b )
753{ 771{
754 if ( b ) 772 if ( b )
755 { 773 {
756 setChannel( 1 ); 774 setChannel( 1 );
757 } 775 }
758 else 776 else
759 { 777 {
760 // call iwpriv <device> monitor 0 0 778 // call iwpriv <device> monitor 0 0
761 int* args = (int*) &_if->_iwr.u.name; 779 int* args = (int*) &_if->_iwr.u.name;
762 args[0] = 0; 780 args[0] = 0;
763 args[1] = 0; 781 args[1] = 0;
764 _if->wioctl( SIOCIWFIRSTPRIV + 0x8 ); 782 _if->wioctl( SIOCIWFIRSTPRIV + 0x8 );
765 } 783 }
766 784
767 OMonitoringInterface::setEnabled( b ); 785 OMonitoringInterface::setEnabled( b );
768} 786}
769 787
770 788
771QString OOrinocoMonitoringInterface::name() const 789QString OOrinocoMonitoringInterface::name() const
772{ 790{
773 return "orinoco"; 791 return "orinoco";
774} 792}
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h
index 9a68a74..936ac85 100644
--- a/libopie2/opienet/onetwork.h
+++ b/libopie2/opienet/onetwork.h
@@ -1,307 +1,310 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2003 by the Wellenreiter team: 3              Copyright (C) 2003 by the Wellenreiter team:
4 Martin J. Muench <mjm@remote-exploit.org> 4 Martin J. Muench <mjm@remote-exploit.org>
5 Max Moser <mmo@remote-exploit.org 5 Max Moser <mmo@remote-exploit.org
6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34#ifndef ONETWORK_H 34#ifndef ONETWORK_H
35#define ONETWORK_H 35#define ONETWORK_H
36 36
37/* QT */ 37/* QT */
38 38
39#include <qdict.h> 39#include <qdict.h>
40#include <qmap.h> 40#include <qmap.h>
41#include <qobject.h> 41#include <qobject.h>
42#include <qhostaddress.h> 42#include <qhostaddress.h>
43 43
44/* OPIE */ 44/* OPIE */
45 45
46#include <opie2/onetutils.h> 46#include <opie2/onetutils.h>
47 47
48// ML: Yeah, I hate to include kernel headers, but it's necessary here 48// ML: Yeah, I hate to include kernel headers, but it's necessary here
49// ML: Recent RedHat and MandrakePatches to the Kernel and WE broke something 49// ML: Recent RedHat and MandrakePatches to the Kernel and WE broke something
50// ML: #include <net/if.h> e.g. conflicts with #include <linux/wireless.h> 50// ML: #include <net/if.h> e.g. conflicts with #include <linux/wireless.h>
51#define IFNAMSIZ 16 51#define IFNAMSIZ 16
52#include <linux/wireless.h> 52#include <linux/wireless.h>
53#include <net/if.h> 53#include <net/if.h>
54 54
55class ONetworkInterface; 55class ONetworkInterface;
56class OWirelessNetworkInterface; 56class OWirelessNetworkInterface;
57class OChannelHopper; 57class OChannelHopper;
58class OMonitoringInterface; 58class OMonitoringInterface;
59 59
60typedef struct ifreq ifreqstruct; 60typedef struct ifreq ifreqstruct;
61typedef struct iwreq iwreqstruct; 61typedef struct iwreq iwreqstruct;
62typedef struct iw_event iweventstruct; 62typedef struct iw_event iweventstruct;
63typedef struct iw_freq iwfreqstruct; 63typedef struct iw_freq iwfreqstruct;
64typedef struct iw_priv_args iwprivargsstruct; 64typedef struct iw_priv_args iwprivargsstruct;
65typedef struct iw_range iwrangestruct; 65typedef struct iw_range iwrangestruct;
66 66
67/*====================================================================================== 67/*======================================================================================
68 * ONetwork 68 * ONetwork
69 *======================================================================================*/ 69 *======================================================================================*/
70 70
71class ONetwork : public QObject 71class ONetwork : public QObject
72{ 72{
73 Q_OBJECT 73 Q_OBJECT
74 74
75 public: 75 public:
76 typedef QDict<ONetworkInterface> InterfaceMap; 76 typedef QDict<ONetworkInterface> InterfaceMap;
77 typedef QDictIterator<ONetworkInterface> InterfaceIterator; 77 typedef QDictIterator<ONetworkInterface> InterfaceIterator;
78 78
79 public: 79 public:
80 static ONetwork* instance(); 80 static ONetwork* instance();
81 InterfaceIterator iterator() const; 81 InterfaceIterator iterator() const;
82 bool isWirelessInterface( const char* ) const; 82 bool isWirelessInterface( const char* ) const;
83 ONetworkInterface* interface( QString ) const; 83 ONetworkInterface* interface( QString ) const;
84 84
85 protected: 85 protected:
86 ONetwork(); 86 ONetwork();
87 void synchronize(); 87 void synchronize();
88 88
89 private: 89 private:
90 static ONetwork* _instance; 90 static ONetwork* _instance;
91 InterfaceMap _interfaces; 91 InterfaceMap _interfaces;
92}; 92};
93 93
94 94
95/*====================================================================================== 95/*======================================================================================
96 * ONetworkInterface 96 * ONetworkInterface
97 *======================================================================================*/ 97 *======================================================================================*/
98 98
99class ONetworkInterface 99class ONetworkInterface
100{ 100{
101 friend class OMonitoringInterface; 101 friend class OMonitoringInterface;
102 friend class OCiscoMonitoringInterface; 102 friend class OCiscoMonitoringInterface;
103 friend class OWlanNGMonitoringInterface; 103 friend class OWlanNGMonitoringInterface;
104 friend class OHostAPMonitoringInterface; 104 friend class OHostAPMonitoringInterface;
105 friend class OOrinocoMonitoringInterface; 105 friend class OOrinocoMonitoringInterface;
106 106
107 public: 107 public:
108 ONetworkInterface( const QString& name ); 108 ONetworkInterface( const QString& name );
109 virtual ~ONetworkInterface(); 109 virtual ~ONetworkInterface();
110 110
111 const QString& name() const; 111 const QString& name() const;
112 void setMonitoring( OMonitoringInterface* ); 112 void setMonitoring( OMonitoringInterface* );
113 OMonitoringInterface* monitoring() const; 113 OMonitoringInterface* monitoring() const;
114 bool setPromiscuousMode( bool ); 114 bool setPromiscuousMode( bool );
115 bool promiscuousMode() const; 115 bool promiscuousMode() const;
116 bool setUp( bool ); 116 bool setUp( bool );
117 bool isUp() const; 117 bool isUp() const;
118 bool isLoopback() const; 118 bool isLoopback() const;
119 bool isWireless() const; 119 bool isWireless() const;
120 QString ipV4Address() const; 120 QString ipV4Address() const;
121 OMacAddress macAddress() const; 121 OMacAddress macAddress() const;
122 122
123 protected: 123 protected:
124 const QString _name; 124 const QString _name;
125 const int _sfd; 125 const int _sfd;
126 mutable ifreqstruct _ifr; 126 mutable ifreqstruct _ifr;
127 OMonitoringInterface* _mon; 127 OMonitoringInterface* _mon;
128 128
129 protected: 129 protected:
130 ifreqstruct& ifr() const; 130 ifreqstruct& ifr() const;
131 virtual void init(); 131 virtual void init();
132 bool ioctl( int call ) const; 132 bool ioctl( int call ) const;
133 bool ioctl( int call, ifreqstruct& ) const; 133 bool ioctl( int call, ifreqstruct& ) const;
134}; 134};
135 135
136/*====================================================================================== 136/*======================================================================================
137 * OChannelHopper 137 * OChannelHopper
138 *======================================================================================*/ 138 *======================================================================================*/
139 139
140class OChannelHopper : public QObject 140class OChannelHopper : public QObject
141{ 141{
142 public: 142 public:
143 OChannelHopper( OWirelessNetworkInterface* ); 143 OChannelHopper( OWirelessNetworkInterface* );
144 virtual ~OChannelHopper(); 144 virtual ~OChannelHopper();
145 bool isActive() const;
146 int channel() const;
145 virtual void timerEvent( QTimerEvent* ); 147 virtual void timerEvent( QTimerEvent* );
146 void setInterval( int ); 148 void setInterval( int );
147 int interval() const; 149 int interval() const;
148 150
149 private: 151 private:
150 OWirelessNetworkInterface* _iface; 152 OWirelessNetworkInterface* _iface;
151 int _interval; 153 int _interval;
152 int _channel; 154 int _channel;
153 int _tid; 155 int _tid;
156 int _maxChannel;
154}; 157};
155 158
156 159
157/*====================================================================================== 160/*======================================================================================
158 * OWirelessNetworkInterface 161 * OWirelessNetworkInterface
159 *======================================================================================*/ 162 *======================================================================================*/
160 163
161class OWirelessNetworkInterface : public ONetworkInterface 164class OWirelessNetworkInterface : public ONetworkInterface
162{ 165{
163 friend class OMonitoringInterface; 166 friend class OMonitoringInterface;
164 friend class OCiscoMonitoringInterface; 167 friend class OCiscoMonitoringInterface;
165 friend class OWlanNGMonitoringInterface; 168 friend class OWlanNGMonitoringInterface;
166 friend class OHostAPMonitoringInterface; 169 friend class OHostAPMonitoringInterface;
167 friend class OOrinocoMonitoringInterface; 170 friend class OOrinocoMonitoringInterface;
168 171
169 public: 172 public:
170 enum Mode { AdHoc, Managed, Monitor }; 173 enum Mode { AdHoc, Managed, Monitor };
171 174
172 OWirelessNetworkInterface( const QString& name ); 175 OWirelessNetworkInterface( const QString& name );
173 virtual ~OWirelessNetworkInterface(); 176 virtual ~OWirelessNetworkInterface();
174 177
175 virtual void setChannel( int ) const; 178 virtual void setChannel( int ) const;
176 virtual int channel() const; 179 virtual int channel() const;
177 virtual double frequency() const; 180 virtual double frequency() const;
178 virtual int channels() const; 181 virtual int channels() const;
179 //virtual double frequency(int) const; 182 //virtual double frequency(int) const;
180 183
181 virtual void setMode( Mode ) {}; 184 virtual void setMode( Mode ) {};
182 virtual bool mode() const {}; 185 virtual bool mode() const {};
183 186
184 virtual void setMonitorMode( bool ); 187 virtual void setMonitorMode( bool );
185 virtual bool monitorMode() const; 188 virtual bool monitorMode() const;
186 189
187 virtual void setChannelHopping( int interval ); 190 virtual void setChannelHopping( int interval = 0 );
188 virtual int channelHopping() const; 191 virtual int channelHopping() const;
189 192
190 virtual void setNickName( const QString& ) {}; 193 virtual void setNickName( const QString& ) {};
191 virtual QString nickName() const; 194 virtual QString nickName() const;
192 195
193 virtual bool isAssociated() const {}; 196 virtual bool isAssociated() const {};
194 virtual QString associatedAP() const; 197 virtual QString associatedAP() const;
195 198
196 virtual void setSSID( const QString& ); 199 virtual void setSSID( const QString& );
197 virtual QString SSID() const; 200 virtual QString SSID() const;
198 201
199 protected: 202 protected:
200 mutable iwreqstruct _iwr; 203 mutable iwreqstruct _iwr;
201 QMap<int,int> _channels; 204 QMap<int,int> _channels;
202 205
203 protected: 206 protected:
204 virtual void init(); 207 virtual void init();
205 iwreqstruct& iwr() const; 208 iwreqstruct& iwr() const;
206 bool wioctl( int call ) const; 209 bool wioctl( int call ) const;
207 bool wioctl( int call, iwreqstruct& ) const; 210 bool wioctl( int call, iwreqstruct& ) const;
208 211
209 private: 212 private:
210 OChannelHopper _hopper; 213 OChannelHopper* _hopper;
211}; 214};
212 215
213 216
214/*====================================================================================== 217/*======================================================================================
215 * OMonitoringInterface 218 * OMonitoringInterface
216 *======================================================================================*/ 219 *======================================================================================*/
217 220
218 221
219class OMonitoringInterface 222class OMonitoringInterface
220{ 223{
221 public: 224 public:
222 OMonitoringInterface(); 225 OMonitoringInterface();
223 OMonitoringInterface( ONetworkInterface* ); 226 OMonitoringInterface( ONetworkInterface* );
224 virtual ~OMonitoringInterface(); 227 virtual ~OMonitoringInterface();
225 228
226 public: 229 public:
227 virtual void setEnabled( bool ); 230 virtual void setEnabled( bool );
228 virtual bool enabled() const; 231 virtual bool enabled() const;
229 virtual void setChannel( int ); 232 virtual void setChannel( int );
230 233
231 virtual QString name() const = 0; 234 virtual QString name() const = 0;
232 235
233 protected: 236 protected:
234 bool _enabled; 237 bool _enabled;
235 const OWirelessNetworkInterface* _if; 238 const OWirelessNetworkInterface* _if;
236 239
237}; 240};
238 241
239 242
240/*====================================================================================== 243/*======================================================================================
241 * OCiscoMonitoring 244 * OCiscoMonitoring
242 *======================================================================================*/ 245 *======================================================================================*/
243 246
244 247
245class OCiscoMonitoringInterface : public OMonitoringInterface 248class OCiscoMonitoringInterface : public OMonitoringInterface
246{ 249{
247 public: 250 public:
248 OCiscoMonitoringInterface( ONetworkInterface* ); 251 OCiscoMonitoringInterface( ONetworkInterface* );
249 virtual ~OCiscoMonitoringInterface(); 252 virtual ~OCiscoMonitoringInterface();
250 253
251 virtual void setEnabled( bool ); 254 virtual void setEnabled( bool );
252 virtual QString name() const; 255 virtual QString name() const;
253 virtual void setChannel( int ); 256 virtual void setChannel( int );
254 257
255}; 258};
256 259
257/*====================================================================================== 260/*======================================================================================
258 * OWlanNGMonitoringInterface 261 * OWlanNGMonitoringInterface
259 *======================================================================================*/ 262 *======================================================================================*/
260 263
261class OWlanNGMonitoringInterface : public OMonitoringInterface 264class OWlanNGMonitoringInterface : public OMonitoringInterface
262{ 265{
263 public: 266 public:
264 OWlanNGMonitoringInterface( ONetworkInterface* ); 267 OWlanNGMonitoringInterface( ONetworkInterface* );
265 virtual ~OWlanNGMonitoringInterface(); 268 virtual ~OWlanNGMonitoringInterface();
266 269
267 public: 270 public:
268 virtual void setEnabled( bool ); 271 virtual void setEnabled( bool );
269 virtual QString name() const; 272 virtual QString name() const;
270 virtual void setChannel( int ); 273 virtual void setChannel( int );
271 274
272}; 275};
273 276
274/*====================================================================================== 277/*======================================================================================
275 * OHostAPMonitoringInterface 278 * OHostAPMonitoringInterface
276 *======================================================================================*/ 279 *======================================================================================*/
277 280
278class OHostAPMonitoringInterface : public OMonitoringInterface 281class OHostAPMonitoringInterface : public OMonitoringInterface
279{ 282{
280 public: 283 public:
281 OHostAPMonitoringInterface( ONetworkInterface* ); 284 OHostAPMonitoringInterface( ONetworkInterface* );
282 virtual ~OHostAPMonitoringInterface(); 285 virtual ~OHostAPMonitoringInterface();
283 286
284 public: 287 public:
285 virtual void setEnabled( bool ); 288 virtual void setEnabled( bool );
286 virtual QString name() const; 289 virtual QString name() const;
287 }; 290 };
288 291
289/*====================================================================================== 292/*======================================================================================
290 * OOrinocoMonitoringInterface 293 * OOrinocoMonitoringInterface
291 *======================================================================================*/ 294 *======================================================================================*/
292 295
293class OOrinocoMonitoringInterface : public OMonitoringInterface 296class OOrinocoMonitoringInterface : public OMonitoringInterface
294{ 297{
295 public: 298 public:
296 OOrinocoMonitoringInterface( ONetworkInterface* ); 299 OOrinocoMonitoringInterface( ONetworkInterface* );
297 virtual ~OOrinocoMonitoringInterface(); 300 virtual ~OOrinocoMonitoringInterface();
298 301
299 public: 302 public:
300 virtual void setChannel( int ); 303 virtual void setChannel( int );
301 virtual void setEnabled( bool ); 304 virtual void setEnabled( bool );
302 virtual QString name() const; 305 virtual QString name() const;
303 306
304}; 307};
305 308
306#endif // ONETWORK_H 309#endif // ONETWORK_H
307 310
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index 48f874f..913d42e 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -1,609 +1,806 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2003 by the Wellenreiter team: 3              Copyright (C) 2003 by the Wellenreiter team:
4 Martin J. Muench <mjm@remote-exploit.org> 4 Martin J. Muench <mjm@remote-exploit.org>
5 Max Moser <mmo@remote-exploit.org 5 Max Moser <mmo@remote-exploit.org
6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34/* OPIE */ 34/* OPIE */
35 35
36#include <opie2/opcap.h> 36#include <opie2/opcap.h>
37 37
38/* QT */ 38/* QT */
39 39
40#include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) 40#include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects)
41#include <qsocketnotifier.h> 41#include <qsocketnotifier.h>
42 42
43/*====================================================================================== 43/*======================================================================================
44 * OPacket 44 * OPacket
45 *======================================================================================*/ 45 *======================================================================================*/
46 46
47OPacket::OPacket( packetheaderstruct header, const unsigned char* data, QObject* parent ) 47OPacket::OPacket( packetheaderstruct header, const unsigned char* data, QObject* parent )
48 :QObject( parent, "Generic" ), _hdr( header ), _data( data ) 48 :QObject( parent, "Generic" ), _hdr( header ), _data( data )
49{ 49{
50 qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); 50 qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen );
51 51
52 _end = (unsigned char*) data + header.len;
53 qDebug( "OPacket::data @ %0x, end @ %0x", data, _end );
54
52 if ( packetCapturer()->dataLink() == DLT_EN10MB ) 55 if ( packetCapturer()->dataLink() == DLT_EN10MB )
53 { 56 {
54 qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" ); 57 qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" );
55 new OEthernetPacket( (const struct ether_header*) data, this ); 58 new OEthernetPacket( _end, (const struct ether_header*) data, this );
56 } 59 }
57 else 60 else
58 { 61 {
59 qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" ); 62 qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" );
60 new OWaveLanPacket( (const struct ieee_802_11_header*) data, this ); 63 new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this );
61 } 64 }
62} 65}
63 66
64 67
65OPacket::~OPacket() 68OPacket::~OPacket()
66{ 69{
67} 70}
68 71
69 72
70OPacketCapturer* OPacket::packetCapturer() const 73OPacketCapturer* OPacket::packetCapturer() const
71{ 74{
72 return parent()->inherits( "OPacketCapturer" ) ? static_cast<OPacketCapturer*>( parent() ) : 0; 75 return parent()->inherits( "OPacketCapturer" ) ? static_cast<OPacketCapturer*>( parent() ) : 0;
73} 76}
74 77
75 78
76timevalstruct OPacket::timeval() const 79timevalstruct OPacket::timeval() const
77{ 80{
78 return _hdr.ts; 81 return _hdr.ts;
79} 82}
80 83
81 84
82int OPacket::caplen() const 85int OPacket::caplen() const
83{ 86{
84 return _hdr.caplen; 87 return _hdr.caplen;
85} 88}
86 89
87 90
88void OPacket::dump() const 91void OPacket::dump() const
89{ 92{
90 printf( "OPacket::dump()\n" ); 93 printf( "OPacket::dump()\n" );
91 printf( "----------------\n" ); 94 printf( "----------------\n" );
92 95
93 for ( int i = 0; i < _hdr.caplen; ++i ) 96 for ( int i = 0; i < _hdr.caplen; ++i )
94 { 97 {
95 printf( "%02x ", _data[i] ); 98 printf( "%02x ", _data[i] );
96 if ( !((i+1) % 32) ) printf( "\n" ); 99 if ( !((i+1) % 32) ) printf( "\n" );
97 } 100 }
98 printf( "\n\n" ); 101 printf( "\n\n" );
99} 102}
100 103
101 104
102 105
103int OPacket::len() const 106int OPacket::len() const
104{ 107{
105 return _hdr.len; 108 return _hdr.len;
106} 109}
107 110
108/*====================================================================================== 111/*======================================================================================
109 * OEthernetPacket 112 * OEthernetPacket
110 *======================================================================================*/ 113 *======================================================================================*/
111 114
112OEthernetPacket::OEthernetPacket( const struct ether_header* data, QObject* parent ) 115OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent )
113 :QObject( parent, "Ethernet" ), _ether( data ) 116 :QObject( parent, "Ethernet" ), _ether( data )
114 117
115{ 118{
116 119
117 qDebug( "Source = %s", (const char*) sourceAddress().toString() ); 120 qDebug( "Source = %s", (const char*) sourceAddress().toString() );
118 qDebug( "Destination = %s", (const char*) destinationAddress().toString() ); 121 qDebug( "Destination = %s", (const char*) destinationAddress().toString() );
119 122
120 if ( sourceAddress() == OMacAddress::broadcast ) 123 if ( sourceAddress() == OMacAddress::broadcast )
121 qDebug( "Source is broadcast address" ); 124 qDebug( "Source is broadcast address" );
122 if ( destinationAddress() == OMacAddress::broadcast ) 125 if ( destinationAddress() == OMacAddress::broadcast )
123 qDebug( "Destination is broadcast address" ); 126 qDebug( "Destination is broadcast address" );
124 127
125 switch ( type() ) 128 switch ( type() )
126 { 129 {
127 case ETHERTYPE_IP: new OIPPacket( (const struct iphdr*) (data+1), this ); break; 130 case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break;
128 case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; } 131 case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; }
129 case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; } 132 case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; }
130 default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" ); 133 default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" );
131 } 134 }
132 135
133} 136}
134 137
135 138
136OEthernetPacket::~OEthernetPacket() 139OEthernetPacket::~OEthernetPacket()
137{ 140{
138} 141}
139 142
140 143
141OMacAddress OEthernetPacket::sourceAddress() const 144OMacAddress OEthernetPacket::sourceAddress() const
142{ 145{
143 return OMacAddress( _ether->ether_shost ); 146 return OMacAddress( _ether->ether_shost );
144} 147}
145 148
146 149
147OMacAddress OEthernetPacket::destinationAddress() const 150OMacAddress OEthernetPacket::destinationAddress() const
148{ 151{
149 return OMacAddress( _ether->ether_dhost ); 152 return OMacAddress( _ether->ether_dhost );
150} 153}
151 154
152int OEthernetPacket::type() const 155int OEthernetPacket::type() const
153{ 156{
154 return ntohs( _ether->ether_type ); 157 return ntohs( _ether->ether_type );
155} 158}
156 159
157 160
158/*====================================================================================== 161/*======================================================================================
159 * OIPPacket 162 * OIPPacket
160 *======================================================================================*/ 163 *======================================================================================*/
161 164
162 165
163OIPPacket::OIPPacket( const struct iphdr* data, QObject* parent ) 166OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent )
164 :QObject( parent, "IP" ), _iphdr( data ) 167 :QObject( parent, "IP" ), _iphdr( data )
165 168
166{ 169{
167 qDebug( "OIPPacket::OIPPacket(): decoding IP header..." ); 170 qDebug( "OIPPacket::OIPPacket(): decoding IP header..." );
168 171
169 //qDebug( "FromAddress: %s", (const char*) inet_ntoa( *src ) ); 172 //qDebug( "FromAddress: %s", (const char*) inet_ntoa( *src ) );
170 //qDebug( " ToAddress: %s", (const char*) inet_ntoa( *dst ) ); 173 //qDebug( " ToAddress: %s", (const char*) inet_ntoa( *dst ) );
171 174
172 qDebug( "FromAddress: %s", (const char*) fromIPAddress().toString() ); 175 qDebug( "FromAddress: %s", (const char*) fromIPAddress().toString() );
173 qDebug( " toAddress: %s", (const char*) toIPAddress().toString() ); 176 qDebug( " toAddress: %s", (const char*) toIPAddress().toString() );
174 177
175 switch ( protocol() ) 178 switch ( protocol() )
176 { 179 {
177 case IPPROTO_UDP: new OUDPPacket( (const struct udphdr*) (data+1), this ); break; 180 case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break;
178 case IPPROTO_TCP: new OTCPPacket( (const struct tcphdr*) (data+1), this ); break; 181 case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break;
179 default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() ); 182 default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() );
180 } 183 }
181 184
182} 185}
183 186
184OIPPacket::~OIPPacket() 187OIPPacket::~OIPPacket()
185{ 188{
186} 189}
187 190
188 191
189QHostAddress OIPPacket::fromIPAddress() const 192QHostAddress OIPPacket::fromIPAddress() const
190{ 193{
191 return EXTRACT_32BITS( &_iphdr->saddr ); 194 return EXTRACT_32BITS( &_iphdr->saddr );
192} 195}
193 196
194 197
195QHostAddress OIPPacket::toIPAddress() const 198QHostAddress OIPPacket::toIPAddress() const
196{ 199{
197 return EXTRACT_32BITS( &_iphdr->saddr ); 200 return EXTRACT_32BITS( &_iphdr->saddr );
198} 201}
199 202
200 203
201int OIPPacket::tos() const 204int OIPPacket::tos() const
202{ 205{
203 return _iphdr->tos; 206 return _iphdr->tos;
204} 207}
205 208
206 209
207int OIPPacket::len() const 210int OIPPacket::len() const
208{ 211{
209 return EXTRACT_16BITS( &_iphdr->tot_len ); 212 return EXTRACT_16BITS( &_iphdr->tot_len );
210} 213}
211 214
212 215
213int OIPPacket::id() const 216int OIPPacket::id() const
214{ 217{
215 return EXTRACT_16BITS( &_iphdr->id ); 218 return EXTRACT_16BITS( &_iphdr->id );
216} 219}
217 220
218 221
219int OIPPacket::offset() const 222int OIPPacket::offset() const
220{ 223{
221 return EXTRACT_16BITS( &_iphdr->frag_off ); 224 return EXTRACT_16BITS( &_iphdr->frag_off );
222} 225}
223 226
224 227
225int OIPPacket::ttl() const 228int OIPPacket::ttl() const
226{ 229{
227 return _iphdr->ttl; 230 return _iphdr->ttl;
228} 231}
229 232
230 233
231int OIPPacket::protocol() const 234int OIPPacket::protocol() const
232{ 235{
233 return _iphdr->protocol; 236 return _iphdr->protocol;
234} 237}
235 238
236 239
237int OIPPacket::checksum() const 240int OIPPacket::checksum() const
238{ 241{
239 return EXTRACT_16BITS( &_iphdr->check ); 242 return EXTRACT_16BITS( &_iphdr->check );
240} 243}
241 244
242/*====================================================================================== 245/*======================================================================================
243 * OUDPPacket 246 * OUDPPacket
244 *======================================================================================*/ 247 *======================================================================================*/
245 248
246 249
247OUDPPacket::OUDPPacket( const struct udphdr* data, QObject* parent ) 250OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent )
248 :QObject( parent, "UDP" ), _udphdr( data ) 251 :QObject( parent, "UDP" ), _udphdr( data )
249 252
250{ 253{
251 qDebug( "OUDPPacket::OUDPPacket(): decoding UDP header..." ); 254 qDebug( "OUDPPacket::OUDPPacket(): decoding UDP header..." );
252} 255}
253 256
254OUDPPacket::~OUDPPacket() 257OUDPPacket::~OUDPPacket()
255{ 258{
256} 259}
257 260
258 261
259/*====================================================================================== 262/*======================================================================================
260 * OTCPPacket 263 * OTCPPacket
261 *======================================================================================*/ 264 *======================================================================================*/
262 265
263 266
264OTCPPacket::OTCPPacket( const struct tcphdr* data, QObject* parent ) 267OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent )
265 :QObject( parent, "TCP" ), _tcphdr( data ) 268 :QObject( parent, "TCP" ), _tcphdr( data )
266 269
267{ 270{
268 qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." ); 271 qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." );
269} 272}
270 273
271OTCPPacket::~OTCPPacket() 274OTCPPacket::~OTCPPacket()
272{ 275{
273} 276}
274 277
275 278
276/*====================================================================================== 279/*======================================================================================
277 * OWaveLanPacket 280 * OWaveLanPacket
278 *======================================================================================*/ 281 *======================================================================================*/
279 282
280 283
281OWaveLanPacket::OWaveLanPacket( const struct ieee_802_11_header* data, QObject* parent ) 284OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent )
282 :QObject( parent, "802.11" ), _wlanhdr( data ) 285 :QObject( parent, "802.11" ), _wlanhdr( data )
283 286
284{ 287{
285 qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." ); 288 qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." );
286 qDebug( "type: %0X", type() ); 289 qDebug( "type: %0X", type() );
287 qDebug( "subType: %0X", subType() ); 290 qDebug( "subType: %0X", subType() );
288 qDebug( "duration: %d", duration() ); 291 qDebug( "duration: %d", duration() );
289 qDebug( "powermanagement: %d", usesPowerManagement() ); 292 qDebug( "powermanagement: %d", usesPowerManagement() );
290 qDebug( "wep: %d", usesWep() ); 293 qDebug( "wep: %d", usesWep() );
291 qDebug( "MAC1: %s", (const char*) macAddress1().toString() ); 294 qDebug( "MAC1: %s", (const char*) macAddress1().toString() );
292 qDebug( "MAC2: %s", (const char*) macAddress2().toString() ); 295 qDebug( "MAC2: %s", (const char*) macAddress2().toString() );
293 qDebug( "MAC3: %s", (const char*) macAddress3().toString() ); 296 qDebug( "MAC3: %s", (const char*) macAddress3().toString() );
294 qDebug( "MAC4: %s", (const char*) macAddress4().toString() ); 297 qDebug( "MAC4: %s", (const char*) macAddress4().toString() );
295 298
296 switch ( type() ) 299 switch ( type() )
297 { 300 {
298 case T_MGMT: new OWaveLanManagementPacket( (const struct ieee_802_11_mgmt_header*) data, this ); break; 301 case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break;
299 case T_DATA: new OWaveLanDataPacket( (const struct ieee_802_11_data_header*) data, this ); break; 302 case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break;
300 //case T_CTRL: new OWaveLanControlPacket( (const struct ieee_802_11_ctrl_header*) data, this ); break; 303 //case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_ctrl_header*) data, this ); break;
301 default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown type!" ); 304 default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown type!" );
302 } 305 }
303} 306}
304 307
305OWaveLanPacket::~OWaveLanPacket() 308OWaveLanPacket::~OWaveLanPacket()
306{ 309{
307} 310}
308 311
309 312
310int OWaveLanPacket::duration() const 313int OWaveLanPacket::duration() const
311{ 314{
312 return _wlanhdr->duration; 315 return _wlanhdr->duration;
313} 316}
314 317
315 318
316OMacAddress OWaveLanPacket::macAddress1() const 319OMacAddress OWaveLanPacket::macAddress1() const
317{ 320{
318 return OMacAddress( _wlanhdr->mac1 ); 321 return OMacAddress( _wlanhdr->mac1 );
319} 322}
320 323
321 324
322OMacAddress OWaveLanPacket::macAddress2() const 325OMacAddress OWaveLanPacket::macAddress2() const
323{ 326{
324 return OMacAddress( _wlanhdr->mac2 ); 327 return OMacAddress( _wlanhdr->mac2 );
325} 328}
326 329
327 330
328OMacAddress OWaveLanPacket::macAddress3() const 331OMacAddress OWaveLanPacket::macAddress3() const
329{ 332{
330 return OMacAddress( _wlanhdr->mac3 ); 333 return OMacAddress( _wlanhdr->mac3 );
331} 334}
332 335
333 336
334OMacAddress OWaveLanPacket::macAddress4() const 337OMacAddress OWaveLanPacket::macAddress4() const
335{ 338{
336 return OMacAddress( _wlanhdr->mac4 ); 339 return OMacAddress( _wlanhdr->mac4 );
337} 340}
338 341
339 342
340int OWaveLanPacket::subType() const 343int OWaveLanPacket::subType() const
341{ 344{
342 return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 345 return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
343} 346}
344 347
345 348
346int OWaveLanPacket::type() const 349int OWaveLanPacket::type() const
347{ 350{
348 return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 351 return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
349} 352}
350 353
351 354
352int OWaveLanPacket::version() const 355int OWaveLanPacket::version() const
353{ 356{
354 return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 357 return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
355} 358}
356 359
357 360
358bool OWaveLanPacket::fromDS() const 361bool OWaveLanPacket::fromDS() const
359{ 362{
360 return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 363 return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
361} 364}
362 365
363 366
364bool OWaveLanPacket::toDS() const 367bool OWaveLanPacket::toDS() const
365{ 368{
366 return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 369 return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
367} 370}
368 371
369 372
370bool OWaveLanPacket::usesPowerManagement() const 373bool OWaveLanPacket::usesPowerManagement() const
371{ 374{
372 return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 375 return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
373} 376}
374 377
375 378
376bool OWaveLanPacket::usesWep() const 379bool OWaveLanPacket::usesWep() const
377{ 380{
378 return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 381 return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
379} 382}
380 383
381 384
382/*====================================================================================== 385/*======================================================================================
383 * OWaveLanManagementPacket 386 * OWaveLanManagementPacket
384 *======================================================================================*/ 387 *======================================================================================*/
385 388
386OWaveLanManagementPacket::OWaveLanManagementPacket( const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) 389OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent )
387 :QObject( parent, "802.11 Management" ), _header( data ), 390 :QObject( parent, "802.11 Management" ), _header( data ),
388 _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) 391 _body( (const struct ieee_802_11_mgmt_body*) (data+1) )
389{ 392{
390 qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." ); 393 qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." );
391 394
392 switch ( ((OWaveLanPacket*) this->parent() )->subType() ) 395 switch ( ((OWaveLanPacket*) this->parent() )->subType() )
393 { 396 {
394 case ST_BEACON: 397 case ST_BEACON:
395 { 398 {
396 qDebug( "TYPE: BEACON FRAME" ); 399 // nice, received a beacon...
397 qDebug( "ESSID: %s", (const char*) SSID() ); 400 }
398 break; 401 }
402
403 // grab tagged values
404 const unsigned char* ptr = (const unsigned char*) (_body+1);
405 while (ptr < end)
406 {
407 switch ( *ptr )
408 {
409 case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break;
410 case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break;
411 case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break;
412 case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break;
413 case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break;
414 case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break;
415 case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break;
416 case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break;
399 } 417 }
418 ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value
419 ptr+= 2; // skip tag ID and length
400 } 420 }
401} 421}
402 422
403 423
404OWaveLanManagementPacket::~OWaveLanManagementPacket() 424OWaveLanManagementPacket::~OWaveLanManagementPacket()
405{ 425{
406} 426}
407 427
408 428
409QString OWaveLanManagementPacket::SSID() const 429int OWaveLanManagementPacket::beaconInterval() const
430{
431 return EXTRACT_LE_16BITS( &_body->beacon_interval );
432}
433
434
435int OWaveLanManagementPacket::capabilities() const
436{
437 return EXTRACT_LE_16BITS( &_body->capability_info );
438}
439
440
441bool OWaveLanManagementPacket::canESS() const
410{ 442{
411 int length = _body->ssid.length; 443 return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) );
444}
445
446
447bool OWaveLanManagementPacket::canIBSS() const
448{
449 return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) );
450}
451
452
453bool OWaveLanManagementPacket::canCFP() const
454{
455 return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) );
456}
457
458
459bool OWaveLanManagementPacket::canCFP_REQ() const
460{
461 return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) );
462}
463
464
465bool OWaveLanManagementPacket::canPrivacy() const
466{
467 return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) );
468}
469
470
471/*======================================================================================
472 * OWaveLanManagementSSID
473 *======================================================================================*/
474
475OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent )
476 :QObject( parent, "802.11 SSID" ), _data( data )
477{
478 qDebug( "OWaveLanManagementSSID()" );
479}
480
481
482OWaveLanManagementSSID::~OWaveLanManagementSSID()
483{
484}
485
486
487QString OWaveLanManagementSSID::ID() const
488{
489 int length = _data->length;
412 if ( length > 32 ) length = 32; 490 if ( length > 32 ) length = 32;
413 char essid[length+1]; 491 char essid[length+1];
414 memcpy( &essid, _body->ssid.ssid, length ); 492 memcpy( &essid, &_data->ssid, length );
415 essid[length] = 0x0; 493 essid[length] = 0x0;
416 return essid; 494 return essid;
417} 495}
418 496
419 497
420/*====================================================================================== 498/*======================================================================================
499 * OWaveLanManagementRates
500 *======================================================================================*/
501
502OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent )
503 :QObject( parent, "802.11 Rates" ), _data( data )
504{
505 qDebug( "OWaveLanManagementRates()" );
506}
507
508
509OWaveLanManagementRates::~OWaveLanManagementRates()
510{
511}
512
513/*======================================================================================
514 * OWaveLanManagementCF
515 *======================================================================================*/
516
517OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent )
518 :QObject( parent, "802.11 CF" ), _data( data )
519{
520 qDebug( "OWaveLanManagementCF()" );
521}
522
523
524OWaveLanManagementCF::~OWaveLanManagementCF()
525{
526}
527
528/*======================================================================================
529 * OWaveLanManagementFH
530 *======================================================================================*/
531
532OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent )
533 :QObject( parent, "802.11 FH" ), _data( data )
534{
535 qDebug( "OWaveLanManagementFH()" );
536}
537
538
539OWaveLanManagementFH::~OWaveLanManagementFH()
540{
541}
542
543/*======================================================================================
544 * OWaveLanManagementDS
545 *======================================================================================*/
546
547OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent )
548 :QObject( parent, "802.11 DS" ), _data( data )
549{
550 qDebug( "OWaveLanManagementDS()" );
551}
552
553
554OWaveLanManagementDS::~OWaveLanManagementDS()
555{
556}
557
558
559int OWaveLanManagementDS::channel() const
560{
561 return _data->channel;
562}
563
564/*======================================================================================
565 * OWaveLanManagementTim
566 *======================================================================================*/
567
568OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent )
569 :QObject( parent, "802.11 Tim" ), _data( data )
570{
571 qDebug( "OWaveLanManagementTim()" );
572}
573
574
575OWaveLanManagementTim::~OWaveLanManagementTim()
576{
577}
578
579/*======================================================================================
580 * OWaveLanManagementIBSS
581 *======================================================================================*/
582
583OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent )
584 :QObject( parent, "802.11 IBSS" ), _data( data )
585{
586 qDebug( "OWaveLanManagementIBSS()" );
587}
588
589
590OWaveLanManagementIBSS::~OWaveLanManagementIBSS()
591{
592}
593
594/*======================================================================================
595 * OWaveLanManagementChallenge
596 *======================================================================================*/
597
598OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent )
599 :QObject( parent, "802.11 Challenge" ), _data( data )
600{
601 qDebug( "OWaveLanManagementChallenge()" );
602}
603
604
605OWaveLanManagementChallenge::~OWaveLanManagementChallenge()
606{
607}
608
609/*======================================================================================
421 * OWaveLanDataPacket 610 * OWaveLanDataPacket
422 *======================================================================================*/ 611 *======================================================================================*/
423 612
424OWaveLanDataPacket::OWaveLanDataPacket( const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) 613OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent )
425 :QObject( parent, "802.11 Data" ), _header( data ) 614 :QObject( parent, "802.11 Data" ), _header( data )
426{ 615{
427 //qDebug( "size of header = %d", sizeof( struct ieee_802_11_data_header ) ); 616 //qDebug( "size of header = %d", sizeof( struct ieee_802_11_data_header ) );
428 //qDebug( "header: %0x", data ); 617 //qDebug( "header: %0x", data );
429 const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); 618 const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header );
430 //qDebug( "payload: %0x", payload ); 619 //qDebug( "payload: %0x", payload );
431 620
432 if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address 621 if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address
433 622
434 new OLLCPacket( (const struct ieee_802_11_802_2_header*) payload, this ); 623 new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this );
435} 624}
436 625
437 626
438OWaveLanDataPacket::~OWaveLanDataPacket() 627OWaveLanDataPacket::~OWaveLanDataPacket()
439{ 628{
440} 629}
441 630
442 631
443/*====================================================================================== 632/*======================================================================================
444 * OLLCPacket 633 * OLLCPacket
445 *======================================================================================*/ 634 *======================================================================================*/
446 635
447OLLCPacket::OLLCPacket( const struct ieee_802_11_802_2_header* data, QObject* parent ) 636OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent )
448 :QObject( parent, "802.11 802_2" ), _header( data ) 637 :QObject( parent, "802.11 802_2" ), _header( data )
449{ 638{
450 qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." ); 639 qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." );
451 640
452 if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) 641 if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) )
453 { 642 {
454 qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) ); 643 qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) );
455 644
456 switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h 645 switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h
457 { 646 {
458 case ETH_P_IP: new OIPPacket( (const struct iphdr*) (data+1), this ); break; 647 case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break;
459 default: qDebug( "OLLCPacket::OLLCPacket(): Unknown Encapsulation Type" ); 648 default: qDebug( "OLLCPacket::OLLCPacket(): Unknown Encapsulation Type" );
460 } 649 }
461 650
462 } 651 }
463} 652}
464 653
465 654
466OLLCPacket::~OLLCPacket() 655OLLCPacket::~OLLCPacket()
467{ 656{
468} 657}
469 658
470/*====================================================================================== 659/*======================================================================================
471 * OPacketCapturer 660 * OPacketCapturer
472 *======================================================================================*/ 661 *======================================================================================*/
473 662
474OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) 663OPacketCapturer::OPacketCapturer( QObject* parent, const char* name )
475 :QObject( parent, name ), _name( QString::null ), _open( false ), 664 :QObject( parent, name ), _name( QString::null ), _open( false ),
476 _pch( 0 ) 665 _pch( 0 ), _sn( 0 )
477{ 666{
478} 667}
479 668
480 669
481OPacketCapturer::~OPacketCapturer() 670OPacketCapturer::~OPacketCapturer()
482{ 671{
483 if ( _open ) 672 if ( _open )
484 { 673 {
485 qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." ); 674 qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." );
486 close(); 675 close();
487 } 676 }
488} 677}
489 678
490 679
491void OPacketCapturer::setBlocking( bool b ) 680void OPacketCapturer::setBlocking( bool b )
492{ 681{
493 if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) 682 if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 )
494 { 683 {
495 qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." ); 684 qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." );
496 } 685 }
497 else 686 else
498 { 687 {
499 qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf ); 688 qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf );
500 } 689 }
501} 690}
502 691
503 692
504bool OPacketCapturer::blocking() const 693bool OPacketCapturer::blocking() const
505{ 694{
506 int b = pcap_getnonblock( _pch, _errbuf ); 695 int b = pcap_getnonblock( _pch, _errbuf );
507 if ( b == -1 ) 696 if ( b == -1 )
508 { 697 {
509 qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf ); 698 qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf );
510 return -1; 699 return -1;
511 } 700 }
512 return !b; 701 return !b;
513} 702}
514 703
515 704
516void OPacketCapturer::close() 705void OPacketCapturer::close()
517{ 706{
518 if ( _open ) 707 if ( _open )
519 { 708 {
709 if ( _sn )
710 {
711 _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
712 delete _sn;
713 }
520 pcap_close( _pch ); 714 pcap_close( _pch );
521 _open = false; 715 _open = false;
522 } 716 }
523} 717}
524 718
525 719
526int OPacketCapturer::dataLink() const 720int OPacketCapturer::dataLink() const
527{ 721{
528 return pcap_datalink( _pch ); 722 return pcap_datalink( _pch );
529} 723}
530 724
531 725
532int OPacketCapturer::fileno() const 726int OPacketCapturer::fileno() const
533{ 727{
534 if ( _open ) 728 if ( _open )
535 { 729 {
536 return pcap_fileno( _pch ); 730 return pcap_fileno( _pch );
537 } 731 }
538 else 732 else
539 { 733 {
540 return -1; 734 return -1;
541 } 735 }
542} 736}
543 737
544 738
545OPacket* OPacketCapturer::next() 739OPacket* OPacketCapturer::next()
546{ 740{
547 packetheaderstruct header; 741 packetheaderstruct header;
742 qDebug( "==> OPacketCapturer::next()" );
548 const unsigned char* pdata = pcap_next( _pch, &header ); 743 const unsigned char* pdata = pcap_next( _pch, &header );
744 qDebug( "<== OPacketCapturer::next()" );
745
549 if ( header.len ) 746 if ( header.len )
550 return new OPacket( header, pdata, this ); 747 return new OPacket( header, pdata, this );
551 else 748 else
552 return 0; 749 return 0;
553} 750}
554 751
555 752
556bool OPacketCapturer::open( const QString& name ) 753bool OPacketCapturer::open( const QString& name )
557{ 754{
558 if ( _open ) 755 if ( _open )
559 { 756 {
560 if ( name == _name ) // ignore opening an already openend device 757 if ( name == _name ) // ignore opening an already openend device
561 { 758 {
562 return true; 759 return true;
563 } 760 }
564 else // close the last opened device 761 else // close the last opened device
565 { 762 {
566 close(); 763 close();
567 } 764 }
568 } 765 }
569 766
570 _name = name; 767 _name = name;
571 768
572 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); 769 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] );
573 770
574 if ( handle ) 771 if ( handle )
575 { 772 {
576 qDebug( "OPacketCapturer::open(): libpcap opened successfully." ); 773 qDebug( "OPacketCapturer::open(): libpcap opened successfully." );
577 _pch = handle; 774 _pch = handle;
578 _open = true; 775 _open = true;
579 776
580 // in case we have a qapp, create a socket notifier 777 // in case we have an application object, create a socket notifier
581 if ( qApp ) 778 if ( qApp )
582 { 779 {
583 QSocketNotifier* sn = new QSocketNotifier( fileno(), QSocketNotifier::Read, this ); 780 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read );
584 connect( sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 781 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
585 } 782 }
586 783
587 return true; 784 return true;
588 } 785 }
589 else 786 else
590 { 787 {
591 qDebug( "OPacketCapturer::open(): can't open libpcap: %s", _errbuf ); 788 qDebug( "OPacketCapturer::open(): can't open libpcap: %s", _errbuf );
592 return false; 789 return false;
593 } 790 }
594 791
595} 792}
596 793
597 794
598bool OPacketCapturer::isOpen() const 795bool OPacketCapturer::isOpen() const
599{ 796{
600 return _open; 797 return _open;
601} 798}
602 799
603 800
604void OPacketCapturer::readyToReceive() 801void OPacketCapturer::readyToReceive()
605{ 802{
606 qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(...)'" ); 803 qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(...)'" );
607 emit receivedPacket( next() ); 804 emit receivedPacket( next() );
608} 805}
609 806
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h
index 65c550c..0b06572 100644
--- a/libopie2/opienet/opcap.h
+++ b/libopie2/opienet/opcap.h
@@ -1,294 +1,436 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2003 by the Wellenreiter team: 3              Copyright (C) 2003 by the Wellenreiter team:
4 Martin J. Muench <mjm@remote-exploit.org> 4 Martin J. Muench <mjm@remote-exploit.org>
5 Max Moser <mmo@remote-exploit.org 5 Max Moser <mmo@remote-exploit.org
6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34#ifndef OPCAP_H 34#ifndef OPCAP_H
35#define OPCAP_H 35#define OPCAP_H
36 36
37/* LINUX */ 37/* LINUX */
38extern "C" // work around a bpf/pcap conflict in recent headers 38extern "C" // work around a bpf/pcap conflict in recent headers
39{ 39{
40 #include <pcap.h> 40 #include <pcap.h>
41} 41}
42#include <netinet/ether.h> 42#include <netinet/ether.h>
43#include <netinet/ip.h> 43#include <netinet/ip.h>
44#include <netinet/udp.h> 44#include <netinet/udp.h>
45#include <netinet/tcp.h> 45#include <netinet/tcp.h>
46#include <time.h> 46#include <time.h>
47 47
48/* QT */ 48/* QT */
49#include <qhostaddress.h> 49#include <qhostaddress.h>
50#include <qobject.h> 50#include <qobject.h>
51#include <qstring.h> 51#include <qstring.h>
52 52
53/* OPIE */ 53/* OPIE */
54#include <opie2/onetutils.h> 54#include <opie2/onetutils.h>
55#include "802_11_user.h" 55#include "802_11_user.h"
56 56
57/* TYPEDEFS */ 57/* TYPEDEFS */
58typedef struct timeval timevalstruct; 58typedef struct timeval timevalstruct;
59typedef struct pcap_pkthdr packetheaderstruct; 59typedef struct pcap_pkthdr packetheaderstruct;
60 60
61/* FORWARDS */ 61/* FORWARDS */
62class OPacketCapturer; 62class OPacketCapturer;
63class QSocketNotifier;
63 64
64/*====================================================================================== 65/*======================================================================================
65 * OPacket - A frame on the wire 66 * OPacket - A frame on the wire
66 *======================================================================================*/ 67 *======================================================================================*/
67 68
68class OPacket : public QObject 69class OPacket : public QObject
69{ 70{
70 Q_OBJECT 71 Q_OBJECT
71 72
72 public: 73 public:
73 OPacket( packetheaderstruct, const unsigned char*, QObject* parent ); 74 OPacket( packetheaderstruct, const unsigned char*, QObject* parent );
74 virtual ~OPacket(); 75 virtual ~OPacket();
75 76
76 timevalstruct timeval() const; 77 timevalstruct timeval() const;
77 78
78 OPacketCapturer* packetCapturer() const; 79 OPacketCapturer* packetCapturer() const;
79 80
80 int caplen() const; 81 int caplen() const;
81 int len() const; 82 int len() const;
82 void dump() const; 83 void dump() const;
83 84
84 private: 85 private:
85 const packetheaderstruct _hdr; // pcap packet header 86 const packetheaderstruct _hdr; // pcap packet header
86 const unsigned char* _data; // pcap packet data 87 const unsigned char* _data; // pcap packet data
88 const unsigned char* _end; // end of pcap packet data
87}; 89};
88 90
89/*====================================================================================== 91/*======================================================================================
90 * OEthernetPacket - DLT_EN10MB frame 92 * OEthernetPacket - DLT_EN10MB frame
91 *======================================================================================*/ 93 *======================================================================================*/
92 94
93class OEthernetPacket : public QObject 95class OEthernetPacket : public QObject
94{ 96{
95 Q_OBJECT 97 Q_OBJECT
96 98
97 public: 99 public:
98 OEthernetPacket( const struct ether_header*, QObject* parent = 0 ); 100 OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 );
99 virtual ~OEthernetPacket(); 101 virtual ~OEthernetPacket();
100 102
101 OMacAddress sourceAddress() const; 103 OMacAddress sourceAddress() const;
102 OMacAddress destinationAddress() const; 104 OMacAddress destinationAddress() const;
103 int type() const; 105 int type() const;
104 106
105 private: 107 private:
106 const struct ether_header* _ether; 108 const struct ether_header* _ether;
107}; 109};
108 110
109 111
110/*====================================================================================== 112/*======================================================================================
111 * OWaveLanPacket - DLT_IEEE802_11 frame 113 * OWaveLanPacket - DLT_IEEE802_11 frame
112 *======================================================================================*/ 114 *======================================================================================*/
113 115
114class OWaveLanPacket : public QObject 116class OWaveLanPacket : public QObject
115{ 117{
116 Q_OBJECT 118 Q_OBJECT
117 119
118 public: 120 public:
119 OWaveLanPacket( const struct ieee_802_11_header*, QObject* parent = 0 ); 121 OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 );
120 virtual ~OWaveLanPacket(); 122 virtual ~OWaveLanPacket();
121 123
122 int duration() const; 124 int duration() const;
123 bool fromDS() const; 125 bool fromDS() const;
124 bool toDS() const; 126 bool toDS() const;
125 virtual OMacAddress macAddress1() const; 127 virtual OMacAddress macAddress1() const;
126 virtual OMacAddress macAddress2() const; 128 virtual OMacAddress macAddress2() const;
127 virtual OMacAddress macAddress3() const; 129 virtual OMacAddress macAddress3() const;
128 virtual OMacAddress macAddress4() const; 130 virtual OMacAddress macAddress4() const;
129 bool usesPowerManagement() const; 131 bool usesPowerManagement() const;
130 int type() const; 132 int type() const;
131 int subType() const; 133 int subType() const;
132 int version() const; 134 int version() const;
133 bool usesWep() const; 135 bool usesWep() const;
134 136
135 private: 137 private:
136 const struct ieee_802_11_header* _wlanhdr; 138 const struct ieee_802_11_header* _wlanhdr;
137}; 139};
138 140
139 141
140/*====================================================================================== 142/*======================================================================================
141 * OWaveLanManagementPacket - type: management (T_MGMT) 143 * OWaveLanManagementPacket - type: management (T_MGMT)
142 *======================================================================================*/ 144 *======================================================================================*/
143 145
144class OWaveLanManagementPacket : public QObject 146class OWaveLanManagementPacket : public QObject
145{ 147{
146 Q_OBJECT 148 Q_OBJECT
147 149
148 public: 150 public:
149 OWaveLanManagementPacket( const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 ); 151 OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 );
150 virtual ~OWaveLanManagementPacket(); 152 virtual ~OWaveLanManagementPacket();
151 153
152 QString SSID() const; 154 int beaconInterval() const;
155 int capabilities() const; // generic
156
157 bool canESS() const;
158 bool canIBSS() const;
159 bool canCFP() const;
160 bool canCFP_REQ() const;
161 bool canPrivacy() const;
153 162
154 private: 163 private:
155 const struct ieee_802_11_mgmt_header* _header; 164 const struct ieee_802_11_mgmt_header* _header;
156 const struct ieee_802_11_mgmt_body* _body; 165 const struct ieee_802_11_mgmt_body* _body;
157}; 166};
158 167
159 168
160/*====================================================================================== 169/*======================================================================================
170 * OWaveLanManagementSSID
171 *======================================================================================*/
172
173class OWaveLanManagementSSID : public QObject
174{
175 Q_OBJECT
176
177 public:
178 OWaveLanManagementSSID( const unsigned char*, const struct ssid_t*, QObject* parent = 0 );
179 virtual ~OWaveLanManagementSSID();
180
181 QString ID() const;
182
183 private:
184 const struct ssid_t* _data;
185};
186
187/*======================================================================================
188 * OWaveLanManagementRates
189 *======================================================================================*/
190
191class OWaveLanManagementRates : public QObject
192{
193 Q_OBJECT
194
195 public:
196 OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 );
197 virtual ~OWaveLanManagementRates();
198
199 private:
200 const struct rates_t* _data;
201};
202
203/*======================================================================================
204 * OWaveLanManagementCF
205 *======================================================================================*/
206
207class OWaveLanManagementCF : public QObject
208{
209 Q_OBJECT
210
211 public:
212 OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 );
213 virtual ~OWaveLanManagementCF();
214
215 private:
216 const struct cf_t* _data;
217};
218
219/*======================================================================================
220 * OWaveLanManagementFH
221 *======================================================================================*/
222
223class OWaveLanManagementFH : public QObject
224{
225 Q_OBJECT
226
227 public:
228 OWaveLanManagementFH( const unsigned char*, const struct fh_t*, QObject* parent = 0 );
229 virtual ~OWaveLanManagementFH();
230
231 private:
232 const struct fh_t* _data;
233};
234
235/*======================================================================================
236 * OWaveLanManagementDS
237 *======================================================================================*/
238
239class OWaveLanManagementDS : public QObject
240{
241 Q_OBJECT
242
243 public:
244 OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 );
245 virtual ~OWaveLanManagementDS();
246
247 int channel() const;
248
249 private:
250 const struct ds_t* _data;
251};
252
253/*======================================================================================
254 * OWaveLanManagementTim
255 *======================================================================================*/
256
257class OWaveLanManagementTim : public QObject
258{
259 Q_OBJECT
260
261 public:
262 OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 );
263 virtual ~OWaveLanManagementTim();
264
265 private:
266 const struct tim_t* _data;
267};
268
269/*======================================================================================
270 * OWaveLanManagementIBSS
271 *======================================================================================*/
272
273class OWaveLanManagementIBSS : public QObject
274{
275 Q_OBJECT
276
277 public:
278 OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 );
279 virtual ~OWaveLanManagementIBSS();
280
281 private:
282 const struct ibss_t* _data;
283};
284
285/*======================================================================================
286 * OWaveLanManagementChallenge
287 *======================================================================================*/
288
289class OWaveLanManagementChallenge : public QObject
290{
291 Q_OBJECT
292
293 public:
294 OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 );
295 virtual ~OWaveLanManagementChallenge();
296
297 private:
298 const struct challenge_t* _data;
299};
300
301/*======================================================================================
161 * OWaveLanDataPacket - type: data (T_DATA) 302 * OWaveLanDataPacket - type: data (T_DATA)
162 *======================================================================================*/ 303 *======================================================================================*/
163 304
164class OWaveLanDataPacket : public QObject 305class OWaveLanDataPacket : public QObject
165{ 306{
166 Q_OBJECT 307 Q_OBJECT
167 308
168 public: 309 public:
169 OWaveLanDataPacket( const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 ); 310 OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 );
170 virtual ~OWaveLanDataPacket(); 311 virtual ~OWaveLanDataPacket();
171 312
172 private: 313 private:
173 const struct ieee_802_11_data_header* _header; 314 const struct ieee_802_11_data_header* _header;
174}; 315};
175 316
176/*====================================================================================== 317/*======================================================================================
177 * OLLCPacket - IEEE 802.2 Link Level Control 318 * OLLCPacket - IEEE 802.2 Link Level Control
178 *======================================================================================*/ 319 *======================================================================================*/
179 320
180class OLLCPacket : public QObject 321class OLLCPacket : public QObject
181{ 322{
182 Q_OBJECT 323 Q_OBJECT
183 324
184 public: 325 public:
185 OLLCPacket( const struct ieee_802_11_802_2_header* data, QObject* parent = 0 ); 326 OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 );
186 virtual ~OLLCPacket(); 327 virtual ~OLLCPacket();
187 328
188 private: 329 private:
189 const struct ieee_802_11_802_2_header* _header; 330 const struct ieee_802_11_802_2_header* _header;
190}; 331};
191 332
192/*====================================================================================== 333/*======================================================================================
193 * OIPPacket 334 * OIPPacket
194 *======================================================================================*/ 335 *======================================================================================*/
195 336
196class OIPPacket : public QObject 337class OIPPacket : public QObject
197{ 338{
198 Q_OBJECT 339 Q_OBJECT
199 340
200 public: 341 public:
201 OIPPacket( const struct iphdr*, QObject* parent = 0 ); 342 OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 );
202 virtual ~OIPPacket(); 343 virtual ~OIPPacket();
203 344
204 QHostAddress fromIPAddress() const; 345 QHostAddress fromIPAddress() const;
205 QHostAddress toIPAddress() const; 346 QHostAddress toIPAddress() const;
206 347
207 int tos() const; 348 int tos() const;
208 int len() const; 349 int len() const;
209 int id() const; 350 int id() const;
210 int offset() const; 351 int offset() const;
211 int ttl() const; 352 int ttl() const;
212 int protocol() const; 353 int protocol() const;
213 int checksum() const; 354 int checksum() const;
214 355
215 private: 356 private:
216 const struct iphdr* _iphdr; 357 const struct iphdr* _iphdr;
217}; 358};
218 359
219/*====================================================================================== 360/*======================================================================================
220 * OUDPPacket 361 * OUDPPacket
221 *======================================================================================*/ 362 *======================================================================================*/
222 363
223class OUDPPacket : public QObject 364class OUDPPacket : public QObject
224{ 365{
225 Q_OBJECT 366 Q_OBJECT
226 367
227 public: 368 public:
228 OUDPPacket( const struct udphdr*, QObject* parent = 0 ); 369 OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 );
229 virtual ~OUDPPacket(); 370 virtual ~OUDPPacket();
230 371
231 int fromPort() const; 372 int fromPort() const;
232 int toPort() const; 373 int toPort() const;
233 374
234 private: 375 private:
235 const struct udphdr* _udphdr; 376 const struct udphdr* _udphdr;
236}; 377};
237 378
238/*====================================================================================== 379/*======================================================================================
239 * OTCPPacket 380 * OTCPPacket
240 *======================================================================================*/ 381 *======================================================================================*/
241 382
242class OTCPPacket : public QObject 383class OTCPPacket : public QObject
243{ 384{
244 Q_OBJECT 385 Q_OBJECT
245 386
246 public: 387 public:
247 OTCPPacket( const struct tcphdr*, QObject* parent = 0 ); 388 OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 );
248 virtual ~OTCPPacket(); 389 virtual ~OTCPPacket();
249 390
250 int fromPort() const; 391 int fromPort() const;
251 int toPort() const; 392 int toPort() const;
252 393
253 private: 394 private:
254 const struct tcphdr* _tcphdr; 395 const struct tcphdr* _tcphdr;
255}; 396};
256 397
257 398
258/*====================================================================================== 399/*======================================================================================
259 * OPacketCapturer 400 * OPacketCapturer
260 *======================================================================================*/ 401 *======================================================================================*/
261 402
262class OPacketCapturer : public QObject 403class OPacketCapturer : public QObject
263{ 404{
264 Q_OBJECT 405 Q_OBJECT
265 406
266 public: 407 public:
267 OPacketCapturer( QObject* parent = 0, const char* name = 0 ); 408 OPacketCapturer( QObject* parent = 0, const char* name = 0 );
268 ~OPacketCapturer(); 409 ~OPacketCapturer();
269 410
270 void setBlocking( bool ); 411 void setBlocking( bool );
271 bool blocking() const; 412 bool blocking() const;
272 413
273 void close(); 414 void close();
274 int dataLink() const; 415 int dataLink() const;
275 int fileno() const; 416 int fileno() const;
276 OPacket* next(); 417 OPacket* next();
277 bool open( const QString& name ); 418 bool open( const QString& name );
278 bool isOpen() const; 419 bool isOpen() const;
279 420
280 signals: 421 signals:
281 void receivedPacket( OPacket* ); 422 void receivedPacket( OPacket* );
282 423
283 protected slots: 424 protected slots:
284 void readyToReceive(); 425 void readyToReceive();
285 426
286 protected: 427 protected:
287 QString _name; // devicename 428 QString _name; // devicename
288 bool _open; // check this before doing pcap calls 429 bool _open; // check this before doing pcap calls
289 pcap_t* _pch; // pcap library handle 430 pcap_t* _pch; // pcap library handle
431 QSocketNotifier* _sn; // socket notifier for main loop
290 mutable char _errbuf[PCAP_ERRBUF_SIZE]; 432 mutable char _errbuf[PCAP_ERRBUF_SIZE];
291}; 433};
292 434
293#endif // OPCAP_H 435#endif // OPCAP_H
294 436