summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-10-05 13:12:45 (UTC)
committer mickeyl <mickeyl>2003-10-05 13:12:45 (UTC)
commit634a68b636a0fa24232029b79ffa915a5621b2be (patch) (unidiff)
tree3e4c58bebfd624e841c314f1db68d985d81cdc6c
parentdc9510f788212a6be063349461540e4bea690f51 (diff)
downloadopie-634a68b636a0fa24232029b79ffa915a5621b2be.zip
opie-634a68b636a0fa24232029b79ffa915a5621b2be.tar.gz
opie-634a68b636a0fa24232029b79ffa915a5621b2be.tar.bz2
* start with preparations for scanning wired networks
* dhcp recognition now works nicely
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetutils.cpp7
-rw-r--r--libopie2/opienet/onetutils.h1
-rw-r--r--libopie2/opienet/opcap.cpp27
-rw-r--r--libopie2/opienet/opcap.h5
-rw-r--r--noncore/net/wellenreiter/gui/scanlist.cpp48
-rw-r--r--noncore/net/wellenreiter/gui/scanlist.h1
-rw-r--r--noncore/net/wellenreiter/gui/wellenreiter.cpp64
-rw-r--r--noncore/net/wellenreiter/gui/wellenreiter.h7
-rwxr-xr-xpics/wellenreiter/service.pngbin0 -> 863 bytes
9 files changed, 148 insertions, 12 deletions
diff --git a/libopie2/opienet/onetutils.cpp b/libopie2/opienet/onetutils.cpp
index 08c40b4..ad0e89d 100644
--- a/libopie2/opienet/onetutils.cpp
+++ b/libopie2/opienet/onetutils.cpp
@@ -1,158 +1,163 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3
4              (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 4              (C) 2003 Michael 'Mickey' 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 31
32#include <opie2/onetutils.h> 32#include <opie2/onetutils.h>
33#include <opie2/onetwork.h> 33#include <opie2/onetwork.h>
34#include <opie2/omanufacturerdb.h> 34#include <opie2/omanufacturerdb.h>
35 35
36#include <net/if.h> 36#include <net/if.h>
37 37
38#include <cstdio> 38#include <cstdio>
39using namespace std; 39using namespace std;
40 40
41#define IW_PRIV_TYPE_MASK 0x7000 41#define IW_PRIV_TYPE_MASK 0x7000
42#define IW_PRIV_TYPE_NONE 0x0000 42#define IW_PRIV_TYPE_NONE 0x0000
43#define IW_PRIV_TYPE_BYTE 0x1000 43#define IW_PRIV_TYPE_BYTE 0x1000
44#define IW_PRIV_TYPE_CHAR 0x2000 44#define IW_PRIV_TYPE_CHAR 0x2000
45#define IW_PRIV_TYPE_INT 0x4000 45#define IW_PRIV_TYPE_INT 0x4000
46#define IW_PRIV_TYPE_FLOAT 0x5000 46#define IW_PRIV_TYPE_FLOAT 0x5000
47#define IW_PRIV_TYPE_ADDR 0x6000 47#define IW_PRIV_TYPE_ADDR 0x6000
48#define IW_PRIV_SIZE_FIXED 0x0800 48#define IW_PRIV_SIZE_FIXED 0x0800
49#define IW_PRIV_SIZE_MASK 0x07FF 49#define IW_PRIV_SIZE_MASK 0x07FF
50 50
51/*====================================================================================== 51/*======================================================================================
52 * OMacAddress 52 * OMacAddress
53 *======================================================================================*/ 53 *======================================================================================*/
54 54
55// static initializer for broadcast and unknown MAC Adresses 55// static initializer for broadcast and unknown MAC Adresses
56const unsigned char __broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; 56const unsigned char __broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
57const OMacAddress& OMacAddress::broadcast = OMacAddress( __broadcast ); 57const OMacAddress& OMacAddress::broadcast = OMacAddress( __broadcast );
58const unsigned char __unknown[6] = { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 }; 58const unsigned char __unknown[6] = { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 };
59const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown ); 59const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown );
60 60
61//TODO: Incorporate Ethernet Manufacturer database here! (inline or so)
62
63OMacAddress::OMacAddress()
64{
65 memcpy( _bytes, __unknown, 6 );
66}
61 67
62//TODO: Incorporate Ethernet Manufacturer database here!
63 68
64OMacAddress::OMacAddress( unsigned char* p ) 69OMacAddress::OMacAddress( unsigned char* p )
65{ 70{
66 memcpy( _bytes, p, 6 ); 71 memcpy( _bytes, p, 6 );
67} 72}
68 73
69 74
70OMacAddress::OMacAddress( const unsigned char* p ) 75OMacAddress::OMacAddress( const unsigned char* p )
71{ 76{
72 memcpy( _bytes, p, 6 ); 77 memcpy( _bytes, p, 6 );
73} 78}
74 79
75 80
76OMacAddress::OMacAddress( struct ifreq& ifr ) 81OMacAddress::OMacAddress( struct ifreq& ifr )
77{ 82{
78 memcpy( _bytes, ifr.ifr_hwaddr.sa_data, 6 ); 83 memcpy( _bytes, ifr.ifr_hwaddr.sa_data, 6 );
79} 84}
80 85
81 86
82OMacAddress::~OMacAddress() 87OMacAddress::~OMacAddress()
83{ 88{
84} 89}
85 90
86 91
87//#ifdef QT_NO_DEBUG 92//#ifdef QT_NO_DEBUG
88//inline 93//inline
89//#endif 94//#endif
90const unsigned char* OMacAddress::native() const 95const unsigned char* OMacAddress::native() const
91{ 96{
92 return (const unsigned char*) &_bytes; 97 return (const unsigned char*) &_bytes;
93} 98}
94 99
95 100
96OMacAddress OMacAddress::fromString( const QString& str ) 101OMacAddress OMacAddress::fromString( const QString& str )
97{ 102{
98 QString addr( str ); 103 QString addr( str );
99 unsigned char buf[6]; 104 unsigned char buf[6];
100 bool ok = true; 105 bool ok = true;
101 int index = 14; 106 int index = 14;
102 for ( int i = 5; i >= 0; --i ) 107 for ( int i = 5; i >= 0; --i )
103 { 108 {
104 buf[i] = addr.right( 2 ).toUShort( &ok, 16 ); 109 buf[i] = addr.right( 2 ).toUShort( &ok, 16 );
105 if ( !ok ) return OMacAddress::unknown; 110 if ( !ok ) return OMacAddress::unknown;
106 addr.truncate( index ); 111 addr.truncate( index );
107 index -= 3; 112 index -= 3;
108 } 113 }
109 return (const unsigned char*) &buf; 114 return (const unsigned char*) &buf;
110} 115}
111 116
112 117
113QString OMacAddress::toString( bool substitute ) const 118QString OMacAddress::toString( bool substitute ) const
114{ 119{
115 QString manu; 120 QString manu;
116 manu.sprintf( "%.2X:%.2X:%.2X", _bytes[0]&0xff, _bytes[1]&0xff, _bytes[2]&0xff ); 121 manu.sprintf( "%.2X:%.2X:%.2X", _bytes[0]&0xff, _bytes[1]&0xff, _bytes[2]&0xff );
117 QString serial; 122 QString serial;
118 serial.sprintf( ":%.2X:%.2X:%.2X", _bytes[3]&0xff, _bytes[4]&0xff, _bytes[5]&0xff ); 123 serial.sprintf( ":%.2X:%.2X:%.2X", _bytes[3]&0xff, _bytes[4]&0xff, _bytes[5]&0xff );
119 if ( !substitute ) return manu+serial; 124 if ( !substitute ) return manu+serial;
120 // fallback - if no vendor is found, just use the number 125 // fallback - if no vendor is found, just use the number
121 QString textmanu = OManufacturerDB::instance()->lookup( manu ); 126 QString textmanu = OManufacturerDB::instance()->lookup( manu );
122 return textmanu.isNull() ? manu+serial : textmanu+serial; 127 return textmanu.isNull() ? manu+serial : textmanu+serial;
123} 128}
124 129
125 130
126QString OMacAddress::manufacturer() const 131QString OMacAddress::manufacturer() const
127{ 132{
128 return OManufacturerDB::instance()->lookupExt( toString() ); 133 return OManufacturerDB::instance()->lookupExt( toString() );
129} 134}
130 135
131 136
132bool operator==( const OMacAddress &m1, const OMacAddress &m2 ) 137bool operator==( const OMacAddress &m1, const OMacAddress &m2 )
133{ 138{
134 return memcmp( &m1._bytes, &m2._bytes, 6 ) == 0; 139 return memcmp( &m1._bytes, &m2._bytes, 6 ) == 0;
135} 140}
136 141
137 142
138/*====================================================================================== 143/*======================================================================================
139 * OHostAddress 144 * OHostAddress
140 *======================================================================================*/ 145 *======================================================================================*/
141 146
142 147
143/*====================================================================================== 148/*======================================================================================
144 * OPrivateIOCTL 149 * OPrivateIOCTL
145 *======================================================================================*/ 150 *======================================================================================*/
146 151
147OPrivateIOCTL::OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs ) 152OPrivateIOCTL::OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs )
148 :QObject( parent, name ), _ioctl( cmd ), _getargs( getargs ), _setargs( setargs ) 153 :QObject( parent, name ), _ioctl( cmd ), _getargs( getargs ), _setargs( setargs )
149{ 154{
150} 155}
151 156
152 157
153OPrivateIOCTL::~OPrivateIOCTL() 158OPrivateIOCTL::~OPrivateIOCTL()
154{ 159{
155} 160}
156 161
157 162
158int OPrivateIOCTL::numberGetArgs() const 163int OPrivateIOCTL::numberGetArgs() const
diff --git a/libopie2/opienet/onetutils.h b/libopie2/opienet/onetutils.h
index 9611518..18731ba 100644
--- a/libopie2/opienet/onetutils.h
+++ b/libopie2/opienet/onetutils.h
@@ -1,149 +1,150 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3
4              (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 4              (C) 2003 Michael 'Mickey' 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 31
32#ifndef ONETUTILS_H 32#ifndef ONETUTILS_H
33#define ONETUTILS_H 33#define ONETUTILS_H
34 34
35#include <qdict.h> 35#include <qdict.h>
36#include <qmap.h> 36#include <qmap.h>
37#include <qstring.h> 37#include <qstring.h>
38#include <qhostaddress.h> 38#include <qhostaddress.h>
39#include <qobject.h> 39#include <qobject.h>
40 40
41#include <sys/types.h> 41#include <sys/types.h>
42 42
43struct ifreq; 43struct ifreq;
44class OWirelessNetworkInterface; 44class OWirelessNetworkInterface;
45 45
46/*====================================================================================== 46/*======================================================================================
47 * OMacAddress 47 * OMacAddress
48 *======================================================================================*/ 48 *======================================================================================*/
49 49
50class OMacAddress 50class OMacAddress
51{ 51{
52 public: 52 public:
53 // QString c'tor? -zecke 53 // QString c'tor? -zecke
54 OMacAddress();
54 OMacAddress( unsigned char* ); 55 OMacAddress( unsigned char* );
55 OMacAddress( const unsigned char* ); 56 OMacAddress( const unsigned char* );
56 OMacAddress( struct ifreq& ); 57 OMacAddress( struct ifreq& );
57 ~OMacAddress(); 58 ~OMacAddress();
58 59
59 QString manufacturer() const; 60 QString manufacturer() const;
60 QString toString( bool substitute = false ) const; 61 QString toString( bool substitute = false ) const;
61 const unsigned char* native() const; 62 const unsigned char* native() const;
62 63
63 // no c'tor but this one why not make it a c'tor. it could also replace the others or is this the problem? 64 // no c'tor but this one why not make it a c'tor. it could also replace the others or is this the problem?
64 static OMacAddress fromString( const QString& ); 65 static OMacAddress fromString( const QString& );
65 66
66 public: 67 public:
67 static const OMacAddress& broadcast; // ff:ff:ff:ff:ff:ff 68 static const OMacAddress& broadcast; // ff:ff:ff:ff:ff:ff
68 static const OMacAddress& unknown; // 44:44:44:44:44:44 69 static const OMacAddress& unknown; // 44:44:44:44:44:44
69 70
70 private: 71 private:
71 unsigned char _bytes[6]; 72 unsigned char _bytes[6];
72 73
73 friend bool operator==( const OMacAddress &m1, const OMacAddress &m2 ); 74 friend bool operator==( const OMacAddress &m1, const OMacAddress &m2 );
74 75
75}; 76};
76 77
77bool operator==( const OMacAddress &m1, const OMacAddress &m2 ); 78bool operator==( const OMacAddress &m1, const OMacAddress &m2 );
78 79
79 80
80/*====================================================================================== 81/*======================================================================================
81 * OHostAddress 82 * OHostAddress
82 *======================================================================================*/ 83 *======================================================================================*/
83 84
84class OHostAddress : public QHostAddress 85class OHostAddress : public QHostAddress
85{ 86{
86 public: 87 public:
87 OHostAddress(); 88 OHostAddress();
88 ~OHostAddress(); 89 ~OHostAddress();
89}; 90};
90 91
91 92
92/*====================================================================================== 93/*======================================================================================
93 * OPrivateIOCTL 94 * OPrivateIOCTL
94 *======================================================================================*/ 95 *======================================================================================*/
95 96
96class OPrivateIOCTL : public QObject 97class OPrivateIOCTL : public QObject
97{ 98{
98 public: 99 public:
99 OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs ); 100 OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs );
100 ~OPrivateIOCTL(); 101 ~OPrivateIOCTL();
101 102
102 int numberGetArgs() const; 103 int numberGetArgs() const;
103 int typeGetArgs() const; 104 int typeGetArgs() const;
104 int numberSetArgs() const; 105 int numberSetArgs() const;
105 int typeSetArgs() const; 106 int typeSetArgs() const;
106 107
107 // FIXME return int? as ::ioctl does? -zecke 108 // FIXME return int? as ::ioctl does? -zecke
108 void invoke() const; 109 void invoke() const;
109 void setParameter( int, u_int32_t ); 110 void setParameter( int, u_int32_t );
110 111
111 private: 112 private:
112 u_int32_t _ioctl; 113 u_int32_t _ioctl;
113 u_int16_t _getargs; 114 u_int16_t _getargs;
114 u_int16_t _setargs; 115 u_int16_t _setargs;
115 116
116}; 117};
117 118
118 /*====================================================================================== 119 /*======================================================================================
119 * Miscellaneous 120 * Miscellaneous
120 *======================================================================================*/ 121 *======================================================================================*/
121 122
122/* dump bytes */ 123/* dump bytes */
123 124
124void dumpBytes( const unsigned char* data, int num ); 125void dumpBytes( const unsigned char* data, int num );
125 126
126/* Network to host order macros */ 127/* Network to host order macros */
127 128
128#ifdef LBL_ALIGN 129#ifdef LBL_ALIGN
129#define EXTRACT_16BITS(p) \ 130#define EXTRACT_16BITS(p) \
130 ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 0) << 8 | \ 131 ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 0) << 8 | \
131 (u_int16_t)*((const u_int8_t *)(p) + 1))) 132 (u_int16_t)*((const u_int8_t *)(p) + 1)))
132#define EXTRACT_32BITS(p) \ 133#define EXTRACT_32BITS(p) \
133 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 24 | \ 134 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 24 | \
134 (u_int32_t)*((const u_int8_t *)(p) + 1) << 16 | \ 135 (u_int32_t)*((const u_int8_t *)(p) + 1) << 16 | \
135 (u_int32_t)*((const u_int8_t *)(p) + 2) << 8 | \ 136 (u_int32_t)*((const u_int8_t *)(p) + 2) << 8 | \
136 (u_int32_t)*((const u_int8_t *)(p) + 3))) 137 (u_int32_t)*((const u_int8_t *)(p) + 3)))
137#else 138#else
138#define EXTRACT_16BITS(p) \ 139#define EXTRACT_16BITS(p) \
139 ((u_int16_t)ntohs(*(const u_int16_t *)(p))) 140 ((u_int16_t)ntohs(*(const u_int16_t *)(p)))
140#define EXTRACT_32BITS(p) \ 141#define EXTRACT_32BITS(p) \
141 ((u_int32_t)ntohl(*(const u_int32_t *)(p))) 142 ((u_int32_t)ntohl(*(const u_int32_t *)(p)))
142#endif 143#endif
143 144
144#define EXTRACT_24BITS(p) \ 145#define EXTRACT_24BITS(p) \
145 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 16 | \ 146 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 16 | \
146 (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ 147 (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \
147 (u_int32_t)*((const u_int8_t *)(p) + 2))) 148 (u_int32_t)*((const u_int8_t *)(p) + 2)))
148 149
149/* Little endian protocol host order macros */ 150/* Little endian protocol host order macros */
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index 7a6f61b..313f5bb 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -15,192 +15,215 @@
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#include <qobjectlist.h> 42#include <qobjectlist.h>
43 43
44#include "udp_ports.h" 44#include "udp_ports.h"
45 45
46/*====================================================================================== 46/*======================================================================================
47 * OPacket 47 * OPacket
48 *======================================================================================*/ 48 *======================================================================================*/
49 49
50OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) 50OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent )
51 :QObject( parent, "Generic" ), _hdr( header ), _data( data ) 51 :QObject( parent, "Generic" ), _hdr( header ), _data( data )
52{ 52{
53 //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); 53 //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen );
54 54
55 _end = (unsigned char*) data + header.len; 55 _end = (unsigned char*) data + header.len;
56 //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); 56 //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end );
57 57
58 switch ( datalink ) 58 switch ( datalink )
59 { 59 {
60 case DLT_EN10MB: 60 case DLT_EN10MB:
61 qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" ); 61 qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" );
62 new OEthernetPacket( _end, (const struct ether_header*) data, this ); 62 new OEthernetPacket( _end, (const struct ether_header*) data, this );
63 break; 63 break;
64 64
65 case DLT_IEEE802_11: 65 case DLT_IEEE802_11:
66 qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" ); 66 qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" );
67 new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); 67 new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this );
68 break; 68 break;
69 69
70 case DLT_PRISM_HEADER: 70 case DLT_PRISM_HEADER:
71 qDebug( "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" ); 71 qDebug( "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" );
72 new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) data, this ); 72 new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) data, this );
73 break; 73 break;
74 74
75 default: 75 default:
76 qWarning( "OPacket::OPacket(): Received Packet over unsupported datalink (type %d)!", datalink ); 76 qWarning( "OPacket::OPacket(): Received Packet over unsupported datalink (type %d)!", datalink );
77 } 77 }
78} 78}
79 79
80 80
81OPacket::~OPacket() 81OPacket::~OPacket()
82{ 82{
83} 83}
84 84
85 85
86timevalstruct OPacket::timeval() const 86timevalstruct OPacket::timeval() const
87{ 87{
88 return _hdr.ts; 88 return _hdr.ts;
89} 89}
90 90
91 91
92int OPacket::caplen() const 92int OPacket::caplen() const
93{ 93{
94 return _hdr.caplen; 94 return _hdr.caplen;
95} 95}
96 96
97 97
98void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) 98void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l )
99{ 99{
100 if (!l) return; 100 if (!l) return;
101 QObject* o = l->first(); 101 QObject* o = l->first();
102 while ( o ) 102 while ( o )
103 { 103 {
104 stats[o->name()]++; 104 stats[o->name()]++;
105 updateStats( stats, const_cast<QObjectList*>( o->children() ) ); 105 updateStats( stats, const_cast<QObjectList*>( o->children() ) );
106 o = l->next(); 106 o = l->next();
107 } 107 }
108} 108}
109 109
110 110
111void OPacket::dumpStructure( QObjectList* l )
112{
113 QString packetString( "[ |" + _dumpStructure( l ) + " ]" );
114 qDebug( "OPacket::dumpStructure: %s", (const char*) packetString );
115}
116
117
118QString OPacket::_dumpStructure( QObjectList* l )
119{
120 if (!l) return QString::null;
121 QObject* o = l->first();
122 QString str(" ");
123
124 while ( o )
125 {
126 str.append( o->name() );
127 str.append( " |" );
128 str += _dumpStructure( const_cast<QObjectList*>( o->children() ) );
129 o = l->next();
130 }
131 return str;
132}
133
111QString OPacket::dump( int bpl ) const 134QString OPacket::dump( int bpl ) const
112{ 135{
113 static int index = 0; 136 static int index = 0;
114 index++; 137 index++;
115 int len = _hdr.caplen; 138 int len = _hdr.caplen;
116 QString str; 139 QString str;
117 str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); 140 str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len );
118 str.append( "0000: " ); 141 str.append( "0000: " );
119 QString tmp; 142 QString tmp;
120 QString bytes; 143 QString bytes;
121 QString chars; 144 QString chars;
122 145
123 for ( int i = 0; i < len; ++i ) 146 for ( int i = 0; i < len; ++i )
124 { 147 {
125 tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); 148 tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp );
126 if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); 149 if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] );
127 else chars.append( '.' ); 150 else chars.append( '.' );
128 151
129 if ( !((i+1) % bpl) ) 152 if ( !((i+1) % bpl) )
130 { 153 {
131 str.append( bytes ); 154 str.append( bytes );
132 str.append( ' ' ); 155 str.append( ' ' );
133 str.append( chars ); 156 str.append( chars );
134 str.append( '\n' ); 157 str.append( '\n' );
135 tmp.sprintf( "%04X: ", i+1 ); str.append( tmp ); 158 tmp.sprintf( "%04X: ", i+1 ); str.append( tmp );
136 bytes = ""; 159 bytes = "";
137 chars = ""; 160 chars = "";
138 } 161 }
139 162
140 } 163 }
141 if ( (len % bpl) ) 164 if ( (len % bpl) )
142 { 165 {
143 str.append( bytes.leftJustify( 1 + 3*bpl ) ); 166 str.append( bytes.leftJustify( 1 + 3*bpl ) );
144 str.append( chars ); 167 str.append( chars );
145 } 168 }
146 str.append( '\n' ); 169 str.append( '\n' );
147 return str; 170 return str;
148} 171}
149 172
150 173
151int OPacket::len() const 174int OPacket::len() const
152{ 175{
153 return _hdr.len; 176 return _hdr.len;
154} 177}
155 178
156 179
157/*====================================================================================== 180/*======================================================================================
158 * OEthernetPacket 181 * OEthernetPacket
159 *======================================================================================*/ 182 *======================================================================================*/
160 183
161OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) 184OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent )
162 :QObject( parent, "Ethernet" ), _ether( data ) 185 :QObject( parent, "Ethernet" ), _ether( data )
163{ 186{
164 187
165 qDebug( "Source = %s", (const char*) sourceAddress().toString() ); 188 qDebug( "Source = %s", (const char*) sourceAddress().toString() );
166 qDebug( "Destination = %s", (const char*) destinationAddress().toString() ); 189 qDebug( "Destination = %s", (const char*) destinationAddress().toString() );
167 190
168 if ( sourceAddress() == OMacAddress::broadcast ) 191 if ( sourceAddress() == OMacAddress::broadcast )
169 qDebug( "Source is broadcast address" ); 192 qDebug( "Source is broadcast address" );
170 if ( destinationAddress() == OMacAddress::broadcast ) 193 if ( destinationAddress() == OMacAddress::broadcast )
171 qDebug( "Destination is broadcast address" ); 194 qDebug( "Destination is broadcast address" );
172 195
173 switch ( type() ) 196 switch ( type() )
174 { 197 {
175 case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; 198 case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break;
176 case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; } 199 case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; }
177 case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; } 200 case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; }
178 default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" ); 201 default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" );
179 } 202 }
180 203
181} 204}
182 205
183 206
184OEthernetPacket::~OEthernetPacket() 207OEthernetPacket::~OEthernetPacket()
185{ 208{
186} 209}
187 210
188 211
189OMacAddress OEthernetPacket::sourceAddress() const 212OMacAddress OEthernetPacket::sourceAddress() const
190{ 213{
191 return OMacAddress( _ether->ether_shost ); 214 return OMacAddress( _ether->ether_shost );
192} 215}
193 216
194 217
195OMacAddress OEthernetPacket::destinationAddress() const 218OMacAddress OEthernetPacket::destinationAddress() const
196{ 219{
197 return OMacAddress( _ether->ether_dhost ); 220 return OMacAddress( _ether->ether_dhost );
198} 221}
199 222
200int OEthernetPacket::type() const 223int OEthernetPacket::type() const
201{ 224{
202 return ntohs( _ether->ether_type ); 225 return ntohs( _ether->ether_type );
203} 226}
204 227
205 228
206/*====================================================================================== 229/*======================================================================================
@@ -1023,193 +1046,195 @@ void OPacketCapturer::setBlocking( bool b )
1023 { 1046 {
1024 qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf ); 1047 qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf );
1025 } 1048 }
1026} 1049}
1027 1050
1028 1051
1029bool OPacketCapturer::blocking() const 1052bool OPacketCapturer::blocking() const
1030{ 1053{
1031 int b = pcap_getnonblock( _pch, _errbuf ); 1054 int b = pcap_getnonblock( _pch, _errbuf );
1032 if ( b == -1 ) 1055 if ( b == -1 )
1033 { 1056 {
1034 qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf ); 1057 qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf );
1035 return -1; 1058 return -1;
1036 } 1059 }
1037 return !b; 1060 return !b;
1038} 1061}
1039 1062
1040 1063
1041void OPacketCapturer::closeDumpFile() 1064void OPacketCapturer::closeDumpFile()
1042{ 1065{
1043 if ( _pcd ) 1066 if ( _pcd )
1044 { 1067 {
1045 pcap_dump_close( _pcd ); 1068 pcap_dump_close( _pcd );
1046 _pcd = 0; 1069 _pcd = 0;
1047 } 1070 }
1048 pcap_close( _pch ); 1071 pcap_close( _pch );
1049} 1072}
1050 1073
1051 1074
1052void OPacketCapturer::close() 1075void OPacketCapturer::close()
1053{ 1076{
1054 if ( _open ) 1077 if ( _open )
1055 { 1078 {
1056 if ( _sn ) 1079 if ( _sn )
1057 { 1080 {
1058 _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 1081 _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
1059 delete _sn; 1082 delete _sn;
1060 } 1083 }
1061 closeDumpFile(); 1084 closeDumpFile();
1062 _open = false; 1085 _open = false;
1063 } 1086 }
1064 1087
1065 qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." ); 1088 qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." );
1066 qDebug( "--------------------------------------------------" ); 1089 qDebug( "--------------------------------------------------" );
1067 for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) 1090 for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it )
1068 qDebug( "%s : %d", (const char*) it.key(), it.data() ); 1091 qDebug( "%s : %d", (const char*) it.key(), it.data() );
1069 qDebug( "--------------------------------------------------" ); 1092 qDebug( "--------------------------------------------------" );
1070 1093
1071} 1094}
1072 1095
1073 1096
1074int OPacketCapturer::dataLink() const 1097int OPacketCapturer::dataLink() const
1075{ 1098{
1076 return pcap_datalink( _pch ); 1099 return pcap_datalink( _pch );
1077} 1100}
1078 1101
1079 1102
1080void OPacketCapturer::dump( OPacket* p ) 1103void OPacketCapturer::dump( OPacket* p )
1081{ 1104{
1082 if ( !_pcd ) 1105 if ( !_pcd )
1083 { 1106 {
1084 qWarning( "OPacketCapturer::dump() - cannot dump without open capture file!" ); 1107 qWarning( "OPacketCapturer::dump() - cannot dump without open capture file!" );
1085 return; 1108 return;
1086 } 1109 }
1087 pcap_dump( (u_char*) _pcd, &p->_hdr, p->_data ); 1110 pcap_dump( (u_char*) _pcd, &p->_hdr, p->_data );
1088} 1111}
1089 1112
1090 1113
1091int OPacketCapturer::fileno() const 1114int OPacketCapturer::fileno() const
1092{ 1115{
1093 if ( _open ) 1116 if ( _open )
1094 { 1117 {
1095 return pcap_fileno( _pch ); 1118 return pcap_fileno( _pch );
1096 } 1119 }
1097 else 1120 else
1098 { 1121 {
1099 return -1; 1122 return -1;
1100 } 1123 }
1101} 1124}
1102 1125
1103OPacket* OPacketCapturer::next() 1126OPacket* OPacketCapturer::next()
1104{ 1127{
1105 packetheaderstruct header; 1128 packetheaderstruct header;
1106 qDebug( "==> OPacketCapturer::next()" ); 1129 qDebug( "==> OPacketCapturer::next()" );
1107 const unsigned char* pdata = pcap_next( _pch, &header ); 1130 const unsigned char* pdata = pcap_next( _pch, &header );
1108 qDebug( "<== OPacketCapturer::next()" ); 1131 qDebug( "<== OPacketCapturer::next()" );
1109 1132
1110 if ( pdata && header.len ) 1133 if ( pdata && header.len )
1111 { 1134 {
1112 OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); 1135 OPacket* p = new OPacket( dataLink(), header, pdata, 0 );
1113 // packets shouldn't be inserted in the QObject child-parent hierarchy, 1136 // packets shouldn't be inserted in the QObject child-parent hierarchy,
1114 // because due to memory constraints they will be deleted as soon 1137 // because due to memory constraints they will be deleted as soon
1115 // as possible - that is right after they have been processed 1138 // as possible - that is right after they have been processed
1116 // by emit() [ see below ] 1139 // by emit() [ see below ]
1117 //TODO: make gathering statistics optional, because it takes time 1140 //TODO: make gathering statistics optional, because it takes time
1118 p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); 1141 p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) );
1119 1142 #ifndef NODEBUG
1143 p->dumpStructure( const_cast<QObjectList*>( p->children() ) );
1144 #endif
1120 return p; 1145 return p;
1121 } 1146 }
1122 else 1147 else
1123 { 1148 {
1124 qWarning( "OPacketCapturer::next() - no packet received!" ); 1149 qWarning( "OPacketCapturer::next() - no packet received!" );
1125 return 0; 1150 return 0;
1126 } 1151 }
1127} 1152}
1128 1153
1129 1154
1130bool OPacketCapturer::open( const QString& name ) 1155bool OPacketCapturer::open( const QString& name )
1131{ 1156{
1132 if ( _open ) 1157 if ( _open )
1133 { 1158 {
1134 if ( name == _name ) // ignore opening an already openend device 1159 if ( name == _name ) // ignore opening an already openend device
1135 { 1160 {
1136 return true; 1161 return true;
1137 } 1162 }
1138 else // close the last opened device 1163 else // close the last opened device
1139 { 1164 {
1140 close(); 1165 close();
1141 } 1166 }
1142 } 1167 }
1143 1168
1144 _name = name; 1169 _name = name;
1145 1170
1146 // open libpcap 1171 // open libpcap
1147 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); 1172 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] );
1148 1173
1149 if ( !handle ) 1174 if ( !handle )
1150 { 1175 {
1151 qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); 1176 qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf );
1152 return false; 1177 return false;
1153 } 1178 }
1154 1179
1155 qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name ); 1180 qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name );
1156 _pch = handle; 1181 _pch = handle;
1157 _open = true; 1182 _open = true;
1158 _stats.clear(); 1183 _stats.clear();
1159 1184
1160 // in case we have an application object, create a socket notifier 1185 // in case we have an application object, create a socket notifier
1161 if ( qApp ) //TODO: I don't like this here... 1186 if ( qApp ) //TODO: I don't like this here...
1162 { 1187 {
1163 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); 1188 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read );
1164 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 1189 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
1165 } 1190 }
1166 1191
1167 return true; 1192 return true;
1168} 1193}
1169 1194
1170 1195
1171bool OPacketCapturer::openDumpFile( const QString& filename ) 1196bool OPacketCapturer::openDumpFile( const QString& filename )
1172{ 1197{
1173 pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) ); 1198 pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) );
1174 if ( !dump ) 1199 if ( !dump )
1175 { 1200 {
1176 qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf ); 1201 qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf );
1177 return false; 1202 return false;
1178 } 1203 }
1179 qDebug( "OPacketCapturer::open(): dump [%s] opened successfully.", (const char*) filename ); 1204 qDebug( "OPacketCapturer::open(): dump [%s] opened successfully.", (const char*) filename );
1180 _pcd = dump; 1205 _pcd = dump;
1181 1206
1182 return true; 1207 return true;
1183} 1208}
1184 1209
1185 1210
1186bool OPacketCapturer::open( const QFile& file ) 1211bool OPacketCapturer::open( const QFile& file )
1187{ 1212{
1188 QString name = file.name(); 1213 QString name = file.name();
1189 1214
1190 if ( _open ) 1215 if ( _open )
1191 { 1216 {
1192 close(); 1217 close();
1193 if ( name == _name ) // ignore opening an already openend device 1218 if ( name == _name ) // ignore opening an already openend device
1194 { 1219 {
1195 return true; 1220 return true;
1196 } 1221 }
1197 else // close the last opened device 1222 else // close the last opened device
1198 { 1223 {
1199 close(); 1224 close();
1200 } 1225 }
1201 } 1226 }
1202 1227
1203 _name = name; 1228 _name = name;
1204 1229
1205 pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] ); 1230 pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] );
1206 1231
1207 if ( handle ) 1232 if ( handle )
1208 { 1233 {
1209 qDebug( "OPacketCapturer::open(): libpcap opened successfully." ); 1234 qDebug( "OPacketCapturer::open(): libpcap opened successfully." );
1210 _pch = handle; 1235 _pch = handle;
1211 _open = true; 1236 _open = true;
1212 1237
1213 // in case we have an application object, create a socket notifier 1238 // in case we have an application object, create a socket notifier
1214 if ( qApp ) 1239 if ( qApp )
1215 { 1240 {
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h
index a031dd1..f0d1d81 100644
--- a/libopie2/opienet/opcap.h
+++ b/libopie2/opienet/opcap.h
@@ -40,192 +40,197 @@ extern "C" // work around a bpf/pcap conflict in recent headers
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 <qevent.h> 49#include <qevent.h>
50#include <qfile.h> 50#include <qfile.h>
51#include <qhostaddress.h> 51#include <qhostaddress.h>
52#include <qobject.h> 52#include <qobject.h>
53#include <qstring.h> 53#include <qstring.h>
54#include <qmap.h> 54#include <qmap.h>
55 55
56/* OPIE */ 56/* OPIE */
57#include <opie2/onetutils.h> 57#include <opie2/onetutils.h>
58 58
59/* Custom Network Includes */ 59/* Custom Network Includes */
60#include "802_11_user.h" 60#include "802_11_user.h"
61#include "dhcp.h" 61#include "dhcp.h"
62 62
63/* TYPEDEFS */ 63/* TYPEDEFS */
64typedef struct timeval timevalstruct; 64typedef struct timeval timevalstruct;
65typedef struct pcap_pkthdr packetheaderstruct; 65typedef struct pcap_pkthdr packetheaderstruct;
66 66
67/* FORWARDS */ 67/* FORWARDS */
68class OPacketCapturer; 68class OPacketCapturer;
69class QSocketNotifier; 69class QSocketNotifier;
70 70
71/*====================================================================================== 71/*======================================================================================
72 * OPacket - A frame on the wire 72 * OPacket - A frame on the wire
73 *======================================================================================*/ 73 *======================================================================================*/
74 74
75/** @brief A class representing a data frame on the wire. 75/** @brief A class representing a data frame on the wire.
76 * 76 *
77 * The whole family of the packet classes are used when capturing frames from a network. 77 * The whole family of the packet classes are used when capturing frames from a network.
78 * Most standard network protocols in use share a common architecture, which mostly is 78 * Most standard network protocols in use share a common architecture, which mostly is
79 * a packet header and then the packet payload. In layered architectures, each lower layer 79 * a packet header and then the packet payload. In layered architectures, each lower layer
80 * encapsulates data from its upper layer - that is it 80 * encapsulates data from its upper layer - that is it
81 * treats the data from its upper layer as payload and prepends an own header to the packet, 81 * treats the data from its upper layer as payload and prepends an own header to the packet,
82 * which - again - is treated as the payload for the layer below. The figure below is an 82 * which - again - is treated as the payload for the layer below. The figure below is an
83 * example for how such a data frame is composed out of packets, e.g. when sending a mail. 83 * example for how such a data frame is composed out of packets, e.g. when sending a mail.
84 * 84 *
85 * <pre> 85 * <pre>
86 * | User Data | == Mail Data 86 * | User Data | == Mail Data
87 * | SMTP Header | User Data | == SMTP 87 * | SMTP Header | User Data | == SMTP
88 * | TCP Header | SMTP Header | User Data | == TCP 88 * | TCP Header | SMTP Header | User Data | == TCP
89 * | IP Header | TCP Header | SMTP Header | User Data | == IP 89 * | IP Header | TCP Header | SMTP Header | User Data | == IP
90 * | MAC Header | IP Header | TCP Header | SMTP Header | User Data | == MAC 90 * | MAC Header | IP Header | TCP Header | SMTP Header | User Data | == MAC
91 * 91 *
92 * </pre> 92 * </pre>
93 * 93 *
94 * The example is trimmed for simplicity, because the MAC (Medium Access Control) layer 94 * The example is trimmed for simplicity, because the MAC (Medium Access Control) layer
95 * also contains a few more levels of encapsulation. 95 * also contains a few more levels of encapsulation.
96 * Since the type of the payload is more or less independent from the encapsulating protocol, 96 * Since the type of the payload is more or less independent from the encapsulating protocol,
97 * the header must be inspected before attempting to decode the payload. Hence, the 97 * the header must be inspected before attempting to decode the payload. Hence, the
98 * encapsulation level varies and can't be deduced without actually looking into the packets. 98 * encapsulation level varies and can't be deduced without actually looking into the packets.
99 * 99 *
100 * For actually working with captured frames, it's useful to identify the packets via names and 100 * For actually working with captured frames, it's useful to identify the packets via names and
101 * insert them into a parent/child - relationship based on the encapsulation. This is why 101 * insert them into a parent/child - relationship based on the encapsulation. This is why
102 * all packet classes derive from QObject. The amount of overhead caused by the QObject is 102 * all packet classes derive from QObject. The amount of overhead caused by the QObject is
103 * not a problem in this case, because we're talking about a theoratical maximum of about 103 * not a problem in this case, because we're talking about a theoratical maximum of about
104 * 10 packets per captured frame. We need to stuff them into a searchable list anyway and the 104 * 10 packets per captured frame. We need to stuff them into a searchable list anyway and the
105 * QObject also cares about destroying the sub-, (child-) packets. 105 * QObject also cares about destroying the sub-, (child-) packets.
106 * 106 *
107 * This enables us to perform a simple look for packets of a certain type: 107 * This enables us to perform a simple look for packets of a certain type:
108 * @code 108 * @code
109 * OPacketCapturer* pcap = new OPacketCapturer(); 109 * OPacketCapturer* pcap = new OPacketCapturer();
110 * pcap->open( "eth0" ); 110 * pcap->open( "eth0" );
111 * OPacket* p = pcap->next(); 111 * OPacket* p = pcap->next();
112 * OIPPacket* ip = (OIPPacket*) p->child( "IP" ); // returns 0, if no such child exists 112 * OIPPacket* ip = (OIPPacket*) p->child( "IP" ); // returns 0, if no such child exists
113 * odebug << "got ip packet from " << ip->fromIPAddress().toString() << " to " << ip->toIPAddress().toString() << oendl; 113 * odebug << "got ip packet from " << ip->fromIPAddress().toString() << " to " << ip->toIPAddress().toString() << oendl;
114 * 114 *
115 */ 115 */
116 116
117class OPacket : public QObject 117class OPacket : public QObject
118{ 118{
119 Q_OBJECT 119 Q_OBJECT
120 120
121 friend class OPacketCapturer; 121 friend class OPacketCapturer;
122 122
123 public: 123 public:
124 OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent ); 124 OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent );
125 virtual ~OPacket(); 125 virtual ~OPacket();
126 126
127 timevalstruct timeval() const; 127 timevalstruct timeval() const;
128 128
129 int caplen() const; 129 int caplen() const;
130 int len() const; 130 int len() const;
131 QString dump( int = 32 ) const; 131 QString dump( int = 32 ) const;
132 132
133 void updateStats( QMap<QString,int>&, QObjectList* ); 133 void updateStats( QMap<QString,int>&, QObjectList* );
134 134
135 private: 135 private:
136
137 void dumpStructure( QObjectList* );
138 QString _dumpStructure( QObjectList* );
139
140 private:
136 const packetheaderstruct _hdr; // pcap packet header 141 const packetheaderstruct _hdr; // pcap packet header
137 const unsigned char* _data; // pcap packet data 142 const unsigned char* _data; // pcap packet data
138 const unsigned char* _end; // end of pcap packet data 143 const unsigned char* _end; // end of pcap packet data
139}; 144};
140 145
141/*====================================================================================== 146/*======================================================================================
142 * OEthernetPacket - DLT_EN10MB frame 147 * OEthernetPacket - DLT_EN10MB frame
143 *======================================================================================*/ 148 *======================================================================================*/
144 149
145class OEthernetPacket : public QObject 150class OEthernetPacket : public QObject
146{ 151{
147 Q_OBJECT 152 Q_OBJECT
148 153
149 public: 154 public:
150 OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 ); 155 OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 );
151 virtual ~OEthernetPacket(); 156 virtual ~OEthernetPacket();
152 157
153 OMacAddress sourceAddress() const; 158 OMacAddress sourceAddress() const;
154 OMacAddress destinationAddress() const; 159 OMacAddress destinationAddress() const;
155 int type() const; 160 int type() const;
156 161
157 private: 162 private:
158 const struct ether_header* _ether; 163 const struct ether_header* _ether;
159}; 164};
160 165
161/*====================================================================================== 166/*======================================================================================
162 * OPrismHeaderPacket - DLT_PRISM_HEADER frame 167 * OPrismHeaderPacket - DLT_PRISM_HEADER frame
163 *======================================================================================*/ 168 *======================================================================================*/
164 169
165class OPrismHeaderPacket : public QObject 170class OPrismHeaderPacket : public QObject
166{ 171{
167 Q_OBJECT 172 Q_OBJECT
168 173
169 public: 174 public:
170 OPrismHeaderPacket( const unsigned char*, const struct prism_hdr*, QObject* parent = 0 ); 175 OPrismHeaderPacket( const unsigned char*, const struct prism_hdr*, QObject* parent = 0 );
171 virtual ~OPrismHeaderPacket(); 176 virtual ~OPrismHeaderPacket();
172 177
173 unsigned int signalStrength() const; 178 unsigned int signalStrength() const;
174 179
175 private: 180 private:
176 const struct prism_hdr* _header; 181 const struct prism_hdr* _header;
177}; 182};
178 183
179/*====================================================================================== 184/*======================================================================================
180 * OWaveLanPacket - DLT_IEEE802_11 frame 185 * OWaveLanPacket - DLT_IEEE802_11 frame
181 *======================================================================================*/ 186 *======================================================================================*/
182 187
183class OWaveLanPacket : public QObject 188class OWaveLanPacket : public QObject
184{ 189{
185 Q_OBJECT 190 Q_OBJECT
186 191
187 public: 192 public:
188 OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 ); 193 OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 );
189 virtual ~OWaveLanPacket(); 194 virtual ~OWaveLanPacket();
190 195
191 int duration() const; 196 int duration() const;
192 bool fromDS() const; 197 bool fromDS() const;
193 bool toDS() const; 198 bool toDS() const;
194 virtual OMacAddress macAddress1() const; 199 virtual OMacAddress macAddress1() const;
195 virtual OMacAddress macAddress2() const; 200 virtual OMacAddress macAddress2() const;
196 virtual OMacAddress macAddress3() const; 201 virtual OMacAddress macAddress3() const;
197 virtual OMacAddress macAddress4() const; 202 virtual OMacAddress macAddress4() const;
198 bool usesPowerManagement() const; 203 bool usesPowerManagement() const;
199 int type() const; 204 int type() const;
200 int subType() const; 205 int subType() const;
201 int version() const; 206 int version() const;
202 bool usesWep() const; 207 bool usesWep() const;
203 208
204 private: 209 private:
205 const struct ieee_802_11_header* _wlanhdr; 210 const struct ieee_802_11_header* _wlanhdr;
206}; 211};
207 212
208 213
209/*====================================================================================== 214/*======================================================================================
210 * OWaveLanManagementPacket - type: management (T_MGMT) 215 * OWaveLanManagementPacket - type: management (T_MGMT)
211 *======================================================================================*/ 216 *======================================================================================*/
212 217
213class OWaveLanManagementPacket : public QObject 218class OWaveLanManagementPacket : public QObject
214{ 219{
215 Q_OBJECT 220 Q_OBJECT
216 221
217 public: 222 public:
218 OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 ); 223 OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 );
219 virtual ~OWaveLanManagementPacket(); 224 virtual ~OWaveLanManagementPacket();
220 225
221 QString managementType() const; 226 QString managementType() const;
222 227
223 int beaconInterval() const; 228 int beaconInterval() const;
224 int capabilities() const; // generic 229 int capabilities() const; // generic
225 230
226 bool canESS() const; 231 bool canESS() const;
227 bool canIBSS() const; 232 bool canIBSS() const;
228 bool canCFP() const; 233 bool canCFP() const;
229 bool canCFP_REQ() const; 234 bool canCFP_REQ() const;
230 bool canPrivacy() const; 235 bool canPrivacy() const;
231 236
diff --git a/noncore/net/wellenreiter/gui/scanlist.cpp b/noncore/net/wellenreiter/gui/scanlist.cpp
index 245290d..9d6ed6a 100644
--- a/noncore/net/wellenreiter/gui/scanlist.cpp
+++ b/noncore/net/wellenreiter/gui/scanlist.cpp
@@ -246,192 +246,240 @@ void MScanListView::addIfNotExisting( MScanListItem* network, const OMacAddress&
246void MScanListView::WDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& viaFrom, const OMacAddress& viaTo ) 246void MScanListView::WDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& viaFrom, const OMacAddress& viaTo )
247{ 247{
248 QString s; 248 QString s;
249 MScanListItem* network; 249 MScanListItem* network;
250 250
251 QListViewItemIterator it( this ); 251 QListViewItemIterator it( this );
252 while ( it.current() && 252 while ( it.current() &&
253 it.current()->text( col_ap ) != viaFrom.toString(true) && 253 it.current()->text( col_ap ) != viaFrom.toString(true) &&
254 it.current()->text( col_ap ) != viaTo.toString(true) ) ++it; 254 it.current()->text( col_ap ) != viaTo.toString(true) ) ++it;
255 255
256 MScanListItem* item = static_cast<MScanListItem*>( it.current() ); 256 MScanListItem* item = static_cast<MScanListItem*>( it.current() );
257 257
258 if ( item ) // Either viaFrom or viaTo AP has shown up yet, so just add our two new stations 258 if ( item ) // Either viaFrom or viaTo AP has shown up yet, so just add our two new stations
259 { 259 {
260 addIfNotExisting( static_cast<MScanListItem*>(item->parent()), from ); 260 addIfNotExisting( static_cast<MScanListItem*>(item->parent()), from );
261 addIfNotExisting( static_cast<MScanListItem*>(item->parent()), to ); 261 addIfNotExisting( static_cast<MScanListItem*>(item->parent()), to );
262 } 262 }
263 else 263 else
264 { 264 {
265 qDebug( "D'Oh! Stations without AP... ignoring for now... will handle this in 1.1 version :-D" ); 265 qDebug( "D'Oh! Stations without AP... ignoring for now... will handle this in 1.1 version :-D" );
266 MLogWindow::logwindow()->log( "WARNING: Unhandled WSD traffic!" ); 266 MLogWindow::logwindow()->log( "WARNING: Unhandled WSD traffic!" );
267 } 267 }
268} 268}
269 269
270 270
271void MScanListView::toDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via ) 271void MScanListView::toDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via )
272{ 272{
273 QString s; 273 QString s;
274 MScanListItem* network; 274 MScanListItem* network;
275 275
276 QListViewItemIterator it( this ); 276 QListViewItemIterator it( this );
277 while ( it.current() && it.current()->text( col_ap ) != via.toString(true) ) ++it; 277 while ( it.current() && it.current()->text( col_ap ) != via.toString(true) ) ++it;
278 278
279 MScanListItem* item = static_cast<MScanListItem*>( it.current() ); 279 MScanListItem* item = static_cast<MScanListItem*>( it.current() );
280 280
281 if ( item ) // AP has shown up yet, so just add our new "from" - station 281 if ( item ) // AP has shown up yet, so just add our new "from" - station
282 { 282 {
283 addIfNotExisting( static_cast<MScanListItem*>(item->parent()), from, "adhoc" ); 283 addIfNotExisting( static_cast<MScanListItem*>(item->parent()), from, "adhoc" );
284 } 284 }
285 else 285 else
286 { 286 {
287 qDebug( "D'Oh! Station without AP... ignoring for now... will handle this in 1.1 :-D" ); 287 qDebug( "D'Oh! Station without AP... ignoring for now... will handle this in 1.1 :-D" );
288 MLogWindow::logwindow()->log( "WARNING: Unhandled toDS traffic!" ); 288 MLogWindow::logwindow()->log( "WARNING: Unhandled toDS traffic!" );
289 289
290 } 290 }
291} 291}
292 292
293 293
294void MScanListView::fromDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via ) 294void MScanListView::fromDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via )
295{ 295{
296 QString s; 296 QString s;
297 MScanListItem* network; 297 MScanListItem* network;
298 298
299 QListViewItemIterator it( this ); 299 QListViewItemIterator it( this );
300 while ( it.current() && it.current()->text( col_ap ) != via.toString(true) ) ++it; 300 while ( it.current() && it.current()->text( col_ap ) != via.toString(true) ) ++it;
301 301
302 MScanListItem* item = static_cast<MScanListItem*>( it.current() ); 302 MScanListItem* item = static_cast<MScanListItem*>( it.current() );
303 303
304 if ( item ) // AP has shown up yet, so just add our new "from" - station 304 if ( item ) // AP has shown up yet, so just add our new "from" - station
305 { 305 {
306 addIfNotExisting( static_cast<MScanListItem*>(item->parent()), from, "station" ); 306 addIfNotExisting( static_cast<MScanListItem*>(item->parent()), from, "station" );
307 } 307 }
308 else 308 else
309 { 309 {
310 qDebug( "D'Oh! Station without AP... ignoring for now... will handle this in 1.1 :-D" ); 310 qDebug( "D'Oh! Station without AP... ignoring for now... will handle this in 1.1 :-D" );
311 MLogWindow::logwindow()->log( "WARNING: Unhandled fromDS traffic!" ); 311 MLogWindow::logwindow()->log( "WARNING: Unhandled fromDS traffic!" );
312 } 312 }
313} 313}
314 314
315 315
316void MScanListView::IBSStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via ) 316void MScanListView::IBSStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via )
317{ 317{
318 qWarning( "D'oh! Not yet implemented..." ); 318 qWarning( "D'oh! Not yet implemented..." );
319 MLogWindow::logwindow()->log( "WARNING: Unhandled IBSS traffic!" ); 319 MLogWindow::logwindow()->log( "WARNING: Unhandled IBSS traffic!" );
320} 320}
321 321
322 322
323void MScanListView::identify( const OMacAddress& macaddr, const QString& ip ) 323void MScanListView::identify( const OMacAddress& macaddr, const QString& ip )
324{ 324{
325 qDebug( "identify %s = %s", (const char*) macaddr.toString(), (const char*) ip ); 325 qDebug( "identify %s = %s", (const char*) macaddr.toString(), (const char*) ip );
326 326
327 QListViewItemIterator it( this ); 327 QListViewItemIterator it( this );
328 for ( ; it.current(); ++it ) 328 for ( ; it.current(); ++it )
329 { 329 {
330 if ( it.current()->text( col_ap ) == macaddr.toString(true) ) 330 if ( it.current()->text( col_ap ) == macaddr.toString(true) )
331 { 331 {
332 it.current()->setText( col_ip, ip ); 332 it.current()->setText( col_ip, ip );
333 return; 333 return;
334 } 334 }
335 } 335 }
336 qDebug( "D'oh! Received identification, but item not yet in list... ==> Handle this!" ); 336 qDebug( "D'oh! Received identification, but item not yet in list... ==> Handle this!" );
337 MLogWindow::logwindow()->log( QString().sprintf( "WARNING: Unhandled identification %s = %s!", 337 MLogWindow::logwindow()->log( QString().sprintf( "WARNING: Unhandled identification %s = %s!",
338 (const char*) macaddr.toString(), (const char*) ip ) ); 338 (const char*) macaddr.toString(), (const char*) ip ) );
339} 339}
340 340
341 341
342void MScanListView::addService( const QString& name, const OMacAddress& macaddr, const QString& ip )
343{
344 qDebug( "addService '%s', Server = %s = %s", (const char*) name, (const char*) macaddr.toString(), (const char*) ip );
345
346 //TODO: Refactor that out, we need it all over the place.
347 // Best to do it in a more comfortable abstraction in OListView
348 // (Hmm, didn't I already start something in this direction?)
349
350 QListViewItemIterator it( this );
351 for ( ; it.current(); ++it )
352 {
353 if ( it.current()->text( col_ap ) == macaddr.toString(true) )
354 {
355
356 MScanListItem* subitem = static_cast<MScanListItem*>( it.current()->firstChild() );
357
358 while ( subitem && ( subitem->text( col_essid ) != name ) )
359 {
360 #ifdef DEBUG
361 qDebug( "subitemtext: %s", (const char*) subitem->text( col_essid ) );
362 #endif
363 subitem = static_cast<MScanListItem*> ( subitem->nextSibling() );
364 }
365
366 if ( subitem )
367 {
368 // we have already seen this item, it's a dupe
369 #ifdef DEBUG
370 qDebug( "%s is a dupe - ignoring...", (const char*) name );
371 #endif
372 subitem->receivedBeacon(); //FIXME: sent data bit
373 return;
374 }
375
376 // never seen that - add new item
377
378 MScanListItem* item = new MScanListItem( it.current(), "service", "N/A", false, -1, -1 );
379 item->setText( col_essid, name );
380
381 return;
382 }
383 }
384 qDebug( "D'oh! Received identification, but item not yet in list... ==> Handle this!" );
385 MLogWindow::logwindow()->log( QString().sprintf( "WARNING: Unhandled service addition %s = %s!",
386 (const char*) macaddr.toString(), (const char*) ip ) );
387}
388
389
342void MScanListView::contextMenuRequested( QListViewItem* item, const QPoint&, int col ) 390void MScanListView::contextMenuRequested( QListViewItem* item, const QPoint&, int col )
343{ 391{
344 if ( !item ) return; 392 if ( !item ) return;
345 393
346 MScanListItem* itm = static_cast<MScanListItem*>( item ); 394 MScanListItem* itm = static_cast<MScanListItem*>( item );
347 395
348 qDebug( "contextMenuRequested on item '%s' (%s) in column: '%d'", 396 qDebug( "contextMenuRequested on item '%s' (%s) in column: '%d'",
349 (const char*) itm->text(0), (const char*) itm->type, col ); 397 (const char*) itm->text(0), (const char*) itm->type, col );
350 398
351 if ( itm->type == "adhoc" || itm->type == "managed" ) 399 if ( itm->type == "adhoc" || itm->type == "managed" )
352 { 400 {
353 QString entry = QString().sprintf( "&Join %s Net '%s'...", (const char*) itm->type, (const char*) itm->essid() ); 401 QString entry = QString().sprintf( "&Join %s Net '%s'...", (const char*) itm->type, (const char*) itm->essid() );
354 402
355 QPopupMenu m( this ); 403 QPopupMenu m( this );
356 m.insertItem( entry, 37773, 0 ); 404 m.insertItem( entry, 37773, 0 );
357 int result = m.exec( QCursor::pos() ); 405 int result = m.exec( QCursor::pos() );
358 if ( result == 37773 ) 406 if ( result == 37773 )
359 emit joinNetwork( itm->type, itm->essid(), itm->channel(), itm->macaddr() ); 407 emit joinNetwork( itm->type, itm->essid(), itm->channel(), itm->macaddr() );
360 } 408 }
361} 409}
362 410
363//============================================================ 411//============================================================
364// MScanListItem 412// MScanListItem
365//============================================================ 413//============================================================
366 414
367MScanListItem::MScanListItem( QListView* parent, QString type, QString essid, QString macaddr, 415MScanListItem::MScanListItem( QListView* parent, QString type, QString essid, QString macaddr,
368 bool wep, int channel, int signal ) 416 bool wep, int channel, int signal )
369 :OListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null ), 417 :OListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null ),
370 _type( type ), _essid( essid ), _macaddr( macaddr ), _wep( wep ), 418 _type( type ), _essid( essid ), _macaddr( macaddr ), _wep( wep ),
371 _channel( channel ), _signal( signal ), _beacons( 1 ) 419 _channel( channel ), _signal( signal ), _beacons( 1 )
372{ 420{
373 #ifdef DEBUG 421 #ifdef DEBUG
374 qDebug( "creating scanlist item" ); 422 qDebug( "creating scanlist item" );
375 #endif 423 #endif
376 if ( WellenreiterConfigWindow::instance() && type == "network" ) 424 if ( WellenreiterConfigWindow::instance() && type == "network" )
377 playSound( WellenreiterConfigWindow::instance()->soundOnNetwork() ); 425 playSound( WellenreiterConfigWindow::instance()->soundOnNetwork() );
378 decorateItem( type, essid, macaddr, wep, channel, signal ); 426 decorateItem( type, essid, macaddr, wep, channel, signal );
379} 427}
380 428
381MScanListItem::MScanListItem( QListViewItem* parent, QString type, QString essid, QString macaddr, 429MScanListItem::MScanListItem( QListViewItem* parent, QString type, QString essid, QString macaddr,
382 bool wep, int channel, int signal ) 430 bool wep, int channel, int signal )
383 :OListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null ) 431 :OListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null )
384{ 432{
385 #ifdef DEBUG 433 #ifdef DEBUG
386 qDebug( "creating scanlist item" ); 434 qDebug( "creating scanlist item" );
387 #endif 435 #endif
388 decorateItem( type, essid, macaddr, wep, channel, signal ); 436 decorateItem( type, essid, macaddr, wep, channel, signal );
389} 437}
390 438
391const QString& MScanListItem::essid() const 439const QString& MScanListItem::essid() const
392{ 440{
393 if ( type == "network" ) 441 if ( type == "network" )
394 return _essid; 442 return _essid;
395 else 443 else
396 return ( (MScanListItem*) parent() )->essid(); 444 return ( (MScanListItem*) parent() )->essid();
397} 445}
398 446
399OListViewItem* MScanListItem::childFactory() 447OListViewItem* MScanListItem::childFactory()
400{ 448{
401 return new MScanListItem( this ); 449 return new MScanListItem( this );
402} 450}
403 451
404void MScanListItem::serializeTo( QDataStream& s ) const 452void MScanListItem::serializeTo( QDataStream& s ) const
405{ 453{
406 #ifdef DEBUG 454 #ifdef DEBUG
407 qDebug( "serializing MScanListItem" ); 455 qDebug( "serializing MScanListItem" );
408 #endif 456 #endif
409 OListViewItem::serializeTo( s ); 457 OListViewItem::serializeTo( s );
410 458
411 s << _type; 459 s << _type;
412 s << (Q_UINT8) ( _wep ? 'y' : 'n' ); 460 s << (Q_UINT8) ( _wep ? 'y' : 'n' );
413} 461}
414 462
415void MScanListItem::serializeFrom( QDataStream& s ) 463void MScanListItem::serializeFrom( QDataStream& s )
416{ 464{
417 #ifdef DEBUG 465 #ifdef DEBUG
418 qDebug( "serializing MScanListItem" ); 466 qDebug( "serializing MScanListItem" );
419 #endif 467 #endif
420 OListViewItem::serializeFrom( s ); 468 OListViewItem::serializeFrom( s );
421 469
422 char wep; 470 char wep;
423 s >> _type; 471 s >> _type;
424 s >> (Q_UINT8) wep; 472 s >> (Q_UINT8) wep;
425 _wep = (wep == 'y'); 473 _wep = (wep == 'y');
426 474
427 QString name; 475 QString name;
428 name.sprintf( "wellenreiter/%s", (const char*) _type ); 476 name.sprintf( "wellenreiter/%s", (const char*) _type );
429 setPixmap( col_type, Resource::loadPixmap( name ) ); 477 setPixmap( col_type, Resource::loadPixmap( name ) );
430 if ( _wep ) 478 if ( _wep )
431 setPixmap( col_wep, Resource::loadPixmap( "wellenreiter/cracked" ) ); //FIXME: rename the pixmap! 479 setPixmap( col_wep, Resource::loadPixmap( "wellenreiter/cracked" ) ); //FIXME: rename the pixmap!
432 listView()->triggerUpdate(); 480 listView()->triggerUpdate();
433} 481}
434 482
435void MScanListItem::decorateItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal ) 483void MScanListItem::decorateItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal )
436{ 484{
437 #ifdef DEBUG 485 #ifdef DEBUG
diff --git a/noncore/net/wellenreiter/gui/scanlist.h b/noncore/net/wellenreiter/gui/scanlist.h
index 2703b6a..a9b74f1 100644
--- a/noncore/net/wellenreiter/gui/scanlist.h
+++ b/noncore/net/wellenreiter/gui/scanlist.h
@@ -1,140 +1,141 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved. 2** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved.
3** 3**
4** This file is part of Opie Environment. 4** This file is part of Opie Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14**********************************************************************/ 14**********************************************************************/
15 15
16#ifndef SCANLIST_H 16#ifndef SCANLIST_H
17#define SCANLIST_H 17#define SCANLIST_H
18 18
19#include "gps.h" 19#include "gps.h"
20 20
21/* OPIE */ 21/* OPIE */
22#include <opie2/olistview.h> 22#include <opie2/olistview.h>
23#include <opie2/onetutils.h> 23#include <opie2/onetutils.h>
24 24
25/* QT */ 25/* QT */
26#include <qtextstream.h> 26#include <qtextstream.h>
27 27
28class QString; 28class QString;
29class MScanListItem; 29class MScanListItem;
30 30
31class MScanListView: public OListView 31class MScanListView: public OListView
32{ 32{
33 Q_OBJECT 33 Q_OBJECT
34 34
35 public: 35 public:
36 MScanListView( QWidget* parent = 0, const char* name = 0 ); 36 MScanListView( QWidget* parent = 0, const char* name = 0 );
37 virtual ~MScanListView(); 37 virtual ~MScanListView();
38 38
39 virtual OListViewItem* childFactory(); 39 virtual OListViewItem* childFactory();
40 virtual void serializeTo( QDataStream& s ) const; 40 virtual void serializeTo( QDataStream& s ) const;
41 virtual void serializeFrom( QDataStream& s ); 41 virtual void serializeFrom( QDataStream& s );
42 42
43 public slots: 43 public slots:
44 void addNewItem( const QString& type, const QString& essid, const OMacAddress& macaddr, bool wep, int channel, int signal, const GpsLocation& location ); 44 void addNewItem( const QString& type, const QString& essid, const OMacAddress& macaddr, bool wep, int channel, int signal, const GpsLocation& location );
45 void addService( const QString& name, const OMacAddress& macaddr, const QString& ip );
45 46
46 void fromDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via ); 47 void fromDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via );
47 void toDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via ); 48 void toDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via );
48 void WDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& viaFrom, const OMacAddress& viaTo ); 49 void WDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& viaFrom, const OMacAddress& viaTo );
49 void IBSStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via ); 50 void IBSStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via );
50 51
51 void identify( const OMacAddress&, const QString& ipaddr ); 52 void identify( const OMacAddress&, const QString& ipaddr );
52 53
53 void contextMenuRequested( QListViewItem* item, const QPoint&, int ); 54 void contextMenuRequested( QListViewItem* item, const QPoint&, int );
54 55
55 signals: 56 signals:
56 void rightButtonClicked(QListViewItem*,const QPoint&,int); 57 void rightButtonClicked(QListViewItem*,const QPoint&,int);
57 void joinNetwork( const QString&, const QString&, int, const QString& ); 58 void joinNetwork( const QString&, const QString&, int, const QString& );
58 59
59 protected: 60 protected:
60 void addIfNotExisting( MScanListItem* parent, const OMacAddress& addr, const QString& type = "station" ); 61 void addIfNotExisting( MScanListItem* parent, const OMacAddress& addr, const QString& type = "station" );
61 62
62}; 63};
63 64
64//****************************** MScanListItem **************************************************************** 65//****************************** MScanListItem ****************************************************************
65 66
66class MScanListItem: public OListViewItem 67class MScanListItem: public OListViewItem
67{ 68{
68 public: 69 public:
69 MScanListItem::MScanListItem( QListView* parent, 70 MScanListItem::MScanListItem( QListView* parent,
70 QString type = "unknown", 71 QString type = "unknown",
71 QString essid = "unknown", 72 QString essid = "unknown",
72 QString macaddr = "unknown", 73 QString macaddr = "unknown",
73 bool wep = false, 74 bool wep = false,
74 int channel = 0, 75 int channel = 0,
75 int signal = 0 ); 76 int signal = 0 );
76 77
77 MScanListItem::MScanListItem( QListViewItem* parent, 78 MScanListItem::MScanListItem( QListViewItem* parent,
78 QString type = "unknown", 79 QString type = "unknown",
79 QString essid = "unknown", 80 QString essid = "unknown",
80 QString macaddr = "unknown", 81 QString macaddr = "unknown",
81 bool wep = false, 82 bool wep = false,
82 int channel = 0, 83 int channel = 0,
83 int signal = 0 ); 84 int signal = 0 );
84 85
85 86
86 protected: 87 protected:
87 virtual void decorateItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal ); 88 virtual void decorateItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal );
88 89
89 public: 90 public:
90 QString type; 91 QString type;
91 92
92 public: 93 public:
93 //const QString& type() { return _type; }; 94 //const QString& type() { return _type; };
94 const QString& essid() const; 95 const QString& essid() const;
95 const QString& macaddr() { return _macaddr; }; 96 const QString& macaddr() { return _macaddr; };
96 bool wep() { return _wep; }; 97 bool wep() { return _wep; };
97 int channel() { return _channel; }; 98 int channel() { return _channel; };
98 int signal() { return _signal; }; 99 int signal() { return _signal; };
99 int beacons() { return _beacons; }; 100 int beacons() { return _beacons; };
100 101
101 void setSignal( int signal ) { /* TODO */ }; 102 void setSignal( int signal ) { /* TODO */ };
102 void receivedBeacon(); 103 void receivedBeacon();
103 104
104 void setManufacturer( const QString& manufacturer ); 105 void setManufacturer( const QString& manufacturer );
105 void setLocation( const float& latitude, const float& longitude ); 106 void setLocation( const float& latitude, const float& longitude );
106 107
107 virtual OListViewItem* childFactory(); 108 virtual OListViewItem* childFactory();
108 virtual void serializeTo( QDataStream& s ) const; 109 virtual void serializeTo( QDataStream& s ) const;
109 virtual void serializeFrom( QDataStream& s ); 110 virtual void serializeFrom( QDataStream& s );
110 111
111 protected: 112 protected:
112 void playSound( const QString& ) const; 113 void playSound( const QString& ) const;
113 114
114 private: 115 private:
115 QString _type; 116 QString _type;
116 QString _essid; 117 QString _essid;
117 QString _macaddr; 118 QString _macaddr;
118 bool _wep; 119 bool _wep;
119 int _channel; 120 int _channel;
120 int _signal; 121 int _signal;
121 int _beacons; 122 int _beacons;
122 123
123}; 124};
124 125
125//****************************** MScanListViewFactory **************************************************************** 126//****************************** MScanListViewFactory ****************************************************************
126 127
127/* 128/*
128 129
129class MScanListViewFactory : public OListViewFactory 130class MScanListViewFactory : public OListViewFactory
130{ 131{
131public: 132public:
132 virtual QListView* listViewFactory(); 133 virtual QListView* listViewFactory();
133 virtual QListViewItem* listViewItemFactory( QListView* lv ); 134 virtual QListViewItem* listViewItemFactory( QListView* lv );
134 virtual QListViewItem* listViewItemFactory( QListViewItem* lvi ); 135 virtual QListViewItem* listViewItemFactory( QListViewItem* lvi );
135 virtual void setColumnText( int depth, QListViewItem* lvi, int column, const QString& text ); 136 virtual void setColumnText( int depth, QListViewItem* lvi, int column, const QString& text );
136 virtual void setCustomData( int depth, QListViewItem* lvi, const QString& text ); 137 virtual void setCustomData( int depth, QListViewItem* lvi, const QString& text );
137} 138}
138*/ 139*/
139 140
140#endif 141#endif
diff --git a/noncore/net/wellenreiter/gui/wellenreiter.cpp b/noncore/net/wellenreiter/gui/wellenreiter.cpp
index 405eda8..7394742 100644
--- a/noncore/net/wellenreiter/gui/wellenreiter.cpp
+++ b/noncore/net/wellenreiter/gui/wellenreiter.cpp
@@ -101,306 +101,352 @@ void Wellenreiter::setConfigWindow( WellenreiterConfigWindow* cw )
101{ 101{
102 configwindow = cw; 102 configwindow = cw;
103} 103}
104 104
105 105
106void Wellenreiter::channelHopped(int c) 106void Wellenreiter::channelHopped(int c)
107{ 107{
108 QString title = "Wellenreiter II -scan- ["; 108 QString title = "Wellenreiter II -scan- [";
109 QString left; 109 QString left;
110 if ( c > 1 ) left.fill( '.', c-1 ); 110 if ( c > 1 ) left.fill( '.', c-1 );
111 title.append( left ); 111 title.append( left );
112 title.append( '|' ); 112 title.append( '|' );
113 if ( c < iface->channels() ) 113 if ( c < iface->channels() )
114 { 114 {
115 QString right; 115 QString right;
116 right.fill( '.', iface->channels()-c ); 116 right.fill( '.', iface->channels()-c );
117 title.append( right ); 117 title.append( right );
118 } 118 }
119 title.append( "]" ); 119 title.append( "]" );
120 //title.append( QString().sprintf( " %02d", c ) ); 120 //title.append( QString().sprintf( " %02d", c ) );
121 assert( parent() ); 121 assert( parent() );
122 ( (QMainWindow*) parent() )->setCaption( title ); 122 ( (QMainWindow*) parent() )->setCaption( title );
123} 123}
124 124
125 125
126void Wellenreiter::handleNotification( OPacket* p ) 126void Wellenreiter::handleNotification( OPacket* p )
127{ 127{
128 QObjectList* l = p->queryList(); 128 QObjectList* l = p->queryList();
129 QObjectListIt it( *l ); 129 QObjectListIt it( *l );
130 QObject* o; 130 QObject* o;
131 131
132 while ( (o = it.current()) != 0 ) 132 while ( (o = it.current()) != 0 )
133 { 133 {
134 QString name = it.current()->name(); 134 QString name = it.current()->name();
135 if ( configwindow->parsePackets->isProtocolChecked( name ) ) 135 if ( configwindow->parsePackets->isProtocolChecked( name ) )
136 { 136 {
137 QString action = configwindow->parsePackets->protocolAction( name ); 137 QString action = configwindow->parsePackets->protocolAction( name );
138 qDebug( "parsePacket-action for '%s' seems to be '%s'", (const char*) name, (const char*) action ); 138 qDebug( "parsePacket-action for '%s' seems to be '%s'", (const char*) name, (const char*) action );
139 doAction( action, name, p ); 139 doAction( action, name, p );
140 } 140 }
141 else 141 else
142 { 142 {
143 qDebug( "protocol '%s' not checked in parsePackets.", (const char*) name ); 143 qDebug( "protocol '%s' not checked in parsePackets.", (const char*) name );
144 } 144 }
145 ++it; 145 ++it;
146 } 146 }
147} 147}
148 148
149 149
150void Wellenreiter::handleBeacon( OPacket* p, OWaveLanManagementPacket* beacon ) 150void Wellenreiter::handleBeacon( OPacket* p, OWaveLanManagementPacket* beacon )
151{ 151{
152 QString type; 152 QString type;
153 if ( beacon->canIBSS() ) 153 if ( beacon->canIBSS() )
154 { 154 {
155 type = "adhoc"; 155 type = "adhoc";
156 } 156 }
157 else if ( beacon->canESS() ) 157 else if ( beacon->canESS() )
158 { 158 {
159 type = "managed"; 159 type = "managed";
160 } 160 }
161 else 161 else
162 { 162 {
163 qWarning( "Wellenreiter::invalid frame [possibly noise] detected!" ); 163 qWarning( "Wellenreiter::invalid frame [possibly noise] detected!" );
164 return; 164 return;
165 } 165 }
166 166
167 OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) ); 167 OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) );
168 QString essid = ssid ? ssid->ID() : QString("<unknown>"); 168 QString essid = ssid ? ssid->ID() : QString("<unknown>");
169 OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) ); 169 OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) );
170 int channel = ds ? ds->channel() : -1; 170 int channel = ds ? ds->channel() : -1;
171 171
172 OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) ); 172 OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) );
173 173
174 GpsLocation loc( 0, 0 ); 174 GpsLocation loc( 0, 0 );
175 if ( configwindow->enableGPS->isChecked() ) 175 if ( configwindow->enableGPS->isChecked() )
176 { 176 {
177 // TODO: add check if GPS is working!? 177 // TODO: add check if GPS is working!?
178 qDebug( "Wellenreiter::gathering GPS data..." ); 178 qDebug( "Wellenreiter::gathering GPS data..." );
179 loc = gps->position(); 179 loc = gps->position();
180 qDebug( "Wellenreiter::GPS data received is ( %f , %f )", loc.latitude, loc.longitude ); 180 qDebug( "Wellenreiter::GPS data received is ( %f , %f )", loc.latitude, loc.longitude );
181 } 181 }
182 182
183 netView()->addNewItem( type, essid, header->macAddress2(), beacon->canPrivacy(), channel, 0, loc ); 183 netView()->addNewItem( type, essid, header->macAddress2(), beacon->canPrivacy(), channel, 0, loc );
184 184
185 // update graph window 185 // update graph window
186 if ( ds ) 186 if ( ds )
187 { 187 {
188 OPrismHeaderPacket* prism = static_cast<OPrismHeaderPacket*>( p->child( "Prism" ) ); 188 OPrismHeaderPacket* prism = static_cast<OPrismHeaderPacket*>( p->child( "Prism" ) );
189 if ( prism ) 189 if ( prism )
190 graphwindow->traffic( ds->channel(), prism->signalStrength() ); 190 graphwindow->traffic( ds->channel(), prism->signalStrength() );
191 else 191 else
192 graphwindow->traffic( ds->channel(), 95 ); 192 graphwindow->traffic( ds->channel(), 95 );
193 } 193 }
194} 194}
195 195
196 196
197void Wellenreiter::handleData( OPacket* p, OWaveLanDataPacket* data ) 197void Wellenreiter::handleWlanData( OPacket* p, OWaveLanDataPacket* data, OMacAddress& from, OMacAddress& to )
198{ 198{
199 OWaveLanPacket* wlan = (OWaveLanPacket*) p->child( "802.11" ); 199 OWaveLanPacket* wlan = (OWaveLanPacket*) p->child( "802.11" );
200 if ( wlan->fromDS() && !wlan->toDS() ) 200 if ( wlan->fromDS() && !wlan->toDS() )
201 { 201 {
202 netView()->fromDStraffic( wlan->macAddress3(), wlan->macAddress1(), wlan->macAddress2() ); 202 netView()->fromDStraffic( wlan->macAddress3(), wlan->macAddress1(), wlan->macAddress2() );
203 from = wlan->macAddress3();
204 to = wlan->macAddress2();
203 } 205 }
204 else if ( !wlan->fromDS() && wlan->toDS() ) 206 else if ( !wlan->fromDS() && wlan->toDS() )
205 { 207 {
206 netView()->toDStraffic( wlan->macAddress2(), wlan->macAddress3(), wlan->macAddress1() ); 208 netView()->toDStraffic( wlan->macAddress2(), wlan->macAddress3(), wlan->macAddress1() );
209 from = wlan->macAddress2();
210 to = wlan->macAddress3();
207 } 211 }
208 else if ( wlan->fromDS() && wlan->toDS() ) 212 else if ( wlan->fromDS() && wlan->toDS() )
209 { 213 {
210 netView()->WDStraffic( wlan->macAddress4(), wlan->macAddress3(), wlan->macAddress1(), wlan->macAddress2() ); 214 netView()->WDStraffic( wlan->macAddress4(), wlan->macAddress3(), wlan->macAddress1(), wlan->macAddress2() );
215 from = wlan->macAddress4();
216 to = wlan->macAddress3();
211 } 217 }
212 else 218 else
213 { 219 {
214 netView()->IBSStraffic( wlan->macAddress2(), wlan->macAddress1(), wlan->macAddress3() ); 220 netView()->IBSStraffic( wlan->macAddress2(), wlan->macAddress1(), wlan->macAddress3() );
221 from = wlan->macAddress2();
222 to = wlan->macAddress1();
215 } 223 }
224}
225
226
227void Wellenreiter::handleEthernetData( OPacket* p, OEthernetPacket* data, OMacAddress& from, OMacAddress& to )
228{
229 from = data->sourceAddress();
230 to = data->destinationAddress();
231
232 netView()->addNewItem( "station", "<wired>", from, false, -1, 0, GpsLocation( 0, 0 ) );
233}
234
216 235
236void Wellenreiter::handleIPData( OPacket* p, OIPPacket* ip, OMacAddress& source, OMacAddress& dest )
237{
217 OARPPacket* arp = (OARPPacket*) p->child( "ARP" ); 238 OARPPacket* arp = (OARPPacket*) p->child( "ARP" );
218 if ( arp ) 239 if ( arp )
219 { 240 {
220 qDebug( "Received ARP traffic (type '%s'): ", (const char*) arp->type() ); 241 qDebug( "Received ARP traffic (type '%s'): ", (const char*) arp->type() );
221 if ( arp->type() == "REQUEST" ) 242 if ( arp->type() == "REQUEST" )
222 { 243 {
223 netView()->identify( arp->senderMacAddress(), arp->senderIPV4Address().toString() ); 244 netView()->identify( arp->senderMacAddress(), arp->senderIPV4Address().toString() );
224 } 245 }
225 else if ( arp->type() == "REPLY" ) 246 else if ( arp->type() == "REPLY" )
226 { 247 {
227 netView()->identify( arp->senderMacAddress(), arp->senderIPV4Address().toString() ); 248 netView()->identify( arp->senderMacAddress(), arp->senderIPV4Address().toString() );
228 netView()->identify( arp->targetMacAddress(), arp->targetIPV4Address().toString() ); 249 netView()->identify( arp->targetMacAddress(), arp->targetIPV4Address().toString() );
229 } 250 }
230 } 251 }
231 252
232 OIPPacket* ip = (OIPPacket*) p->child( "IP" ); 253 ODHCPPacket* dhcp = (ODHCPPacket*) p->child( "DHCP" );
233 if ( ip ) 254 if ( dhcp )
234 { 255 {
235 qDebug( "Received IP packet." ); 256 qDebug( "Received DHCP '%s' packet", (const char*) dhcp->type() );
257 if ( dhcp->type() == "OFFER" )
258 {
259 qDebug( "ADDSERVICE: '%s' ('%s') seems to be a DHCP server.", (const char*) source.toString(), (const char*) dhcp->serverAddress().toString() );
260 //netView()->addNewItem( "station", "<wired>", from, false, -1, 0, GpsLocation( 0, 0 ) );
261
262 netView()->identify( source, dhcp->serverAddress().toString() );
263 netView()->addService( "DHCP", source, dhcp->serverAddress().toString() );
264 }
236 } 265 }
237} 266}
238 267
239 268
240QObject* Wellenreiter::childIfToParse( OPacket* p, const QString& protocol ) 269QObject* Wellenreiter::childIfToParse( OPacket* p, const QString& protocol )
241{ 270{
242 if ( configwindow->parsePackets->isProtocolChecked( protocol ) ) 271 if ( configwindow->parsePackets->isProtocolChecked( protocol ) )
243 if ( configwindow->parsePackets->protocolAction( protocol ) == "Discard!" ) 272 if ( configwindow->parsePackets->protocolAction( protocol ) == "Discard!" )
244 return 0; 273 return 0;
245 274
246 return p->child( protocol ); 275 return p->child( protocol );
247} 276}
248 277
249 278
250bool Wellenreiter::checkDumpPacket( OPacket* p ) 279bool Wellenreiter::checkDumpPacket( OPacket* p )
251{ 280{
252 // go through all child packets and see if one is inside the child hierarchy for p 281 // go through all child packets and see if one is inside the child hierarchy for p
253 // if so, do what the user requested (protocolAction), e.g. pass or discard 282 // if so, do what the user requested (protocolAction), e.g. pass or discard
254 if ( !configwindow->writeCaptureFile->isChecked() ) 283 if ( !configwindow->writeCaptureFile->isChecked() )
255 return false; 284 return false;
256 285
257 QObjectList* l = p->queryList(); 286 QObjectList* l = p->queryList();
258 QObjectListIt it( *l ); 287 QObjectListIt it( *l );
259 QObject* o; 288 QObject* o;
260 289
261 while ( (o = it.current()) != 0 ) 290 while ( (o = it.current()) != 0 )
262 { 291 {
263 QString name = it.current()->name(); 292 QString name = it.current()->name();
264 if ( configwindow->capturePackets->isProtocolChecked( name ) ) 293 if ( configwindow->capturePackets->isProtocolChecked( name ) )
265 { 294 {
266 QString action = configwindow->capturePackets->protocolAction( name ); 295 QString action = configwindow->capturePackets->protocolAction( name );
267 qDebug( "capturePackets-action for '%s' seems to be '%s'", (const char*) name, (const char*) action ); 296 qDebug( "capturePackets-action for '%s' seems to be '%s'", (const char*) name, (const char*) action );
268 if ( action == "Discard" ) 297 if ( action == "Discard" )
269 { 298 {
270 logwindow->log( QString().sprintf( "(i) dump-discarding of '%s' packet requested.", (const char*) name ) ); 299 logwindow->log( QString().sprintf( "(i) dump-discarding of '%s' packet requested.", (const char*) name ) );
271 return false; 300 return false;
272 } 301 }
273 } 302 }
274 else 303 else
275 { 304 {
276 qDebug( "protocol '%s' not checked in capturePackets.", (const char*) name ); 305 qDebug( "protocol '%s' not checked in capturePackets.", (const char*) name );
277 } 306 }
278 ++it; 307 ++it;
279 } 308 }
280 return true; 309 return true;
281} 310}
282 311
283 312
284void Wellenreiter::receivePacket( OPacket* p ) 313void Wellenreiter::receivePacket( OPacket* p )
285{ 314{
286 hexWindow()->log( p->dump( 8 ) ); 315 hexWindow()->log( p->dump( 8 ) );
287 316
288 if ( checkDumpPacket( p ) ) 317 if ( checkDumpPacket( p ) )
289 { 318 {
290 pcap->dump( p ); 319 pcap->dump( p );
291 } 320 }
292 321
293 // check if we received a beacon frame 322 // check if we received a beacon frame
294 OWaveLanManagementPacket* beacon = static_cast<OWaveLanManagementPacket*>( childIfToParse( p, "802.11 Management" ) ); 323 OWaveLanManagementPacket* beacon = static_cast<OWaveLanManagementPacket*>( childIfToParse( p, "802.11 Management" ) );
295 if ( beacon && beacon->managementType() == "Beacon" ) 324 if ( beacon && beacon->managementType() == "Beacon" )
296 { 325 {
297 handleBeacon( p, beacon ); 326 handleBeacon( p, beacon );
298 return; 327 return;
299 } 328 }
300 329
330 OMacAddress source;
331 OMacAddress dest;
332
301 //TODO: WEP check here 333 //TODO: WEP check here
302 334
303 // check for a data frame 335 // check for a wireless data frame
304 OWaveLanDataPacket* data = static_cast<OWaveLanDataPacket*>( childIfToParse( p, "802.11 Data" ) ); 336 OWaveLanDataPacket* wlan = static_cast<OWaveLanDataPacket*>( childIfToParse( p, "802.11 Data" ) );
305 if ( data ) 337 if ( wlan )
338 {
339 handleWlanData( p, wlan, source, dest );
340 }
341
342 // check for a wired data frame
343 OEthernetPacket* eth = static_cast<OEthernetPacket*>( childIfToParse( p, "Ethernet" ) );
344 if ( eth )
345 {
346 handleEthernetData( p, eth, source, dest );
347 }
348
349 // check for a ip frame
350 OIPPacket* ip = static_cast<OIPPacket*>( childIfToParse( p, "IP" ) );
351 if ( ip )
306 { 352 {
307 handleData( p, data ); 353 handleIPData( p, ip, source, dest );
308 } 354 }
309 355
310 handleNotification( p ); 356 //handleNotification( p );
311 357
312} 358}
313 359
314 360
315void Wellenreiter::stopClicked() 361void Wellenreiter::stopClicked()
316{ 362{
317 if ( iface ) 363 if ( iface )
318 { 364 {
319 disconnect( SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) ); 365 disconnect( SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) );
320 disconnect( SIGNAL( hopped(int) ), this, SLOT( channelHopped(int) ) ); 366 disconnect( SIGNAL( hopped(int) ), this, SLOT( channelHopped(int) ) );
321 iface->setChannelHopping(); // stop hopping channels 367 iface->setChannelHopping(); // stop hopping channels
322 } 368 }
323 else 369 else
324 killTimers(); 370 killTimers();
325 371
326 pcap->close(); 372 pcap->close();
327 sniffing = false; 373 sniffing = false;
328 374
329 if ( iface ) 375 if ( iface )
330 { 376 {
331 // switch off monitor mode 377 // switch off monitor mode
332 iface->setMonitorMode( false ); 378 iface->setMonitorMode( false );
333 // switch off promisc flag 379 // switch off promisc flag
334 iface->setPromiscuousMode( false ); 380 iface->setPromiscuousMode( false );
335 381
336 system( "cardctl reset; sleep 1" ); //FIXME: Use OProcess 382 system( "cardctl reset; sleep 1" ); //FIXME: Use OProcess
337 } 383 }
338 384
339 logwindow->log( "(i) Stopped Scanning." ); 385 logwindow->log( "(i) Stopped Scanning." );
340 assert( parent() ); 386 assert( parent() );
341 ( (QMainWindow*) parent() )->setCaption( "Wellenreiter II" ); 387 ( (QMainWindow*) parent() )->setCaption( "Wellenreiter II" );
342 388
343 // message the user 389 // message the user
344 QMessageBox::information( this, "Wellenreiter II", 390 QMessageBox::information( this, "Wellenreiter II",
345 tr( "Your wireless card\nshould now be usable again." ) ); 391 tr( "Your wireless card\nshould now be usable again." ) );
346 392
347 sniffing = false; 393 sniffing = false;
348 emit( stoppedSniffing() ); 394 emit( stoppedSniffing() );
349 395
350 #ifdef QWS 396 #ifdef QWS
351 if ( WellenreiterConfigWindow::instance()->disablePM->isChecked() ) 397 if ( WellenreiterConfigWindow::instance()->disablePM->isChecked() )
352 { 398 {
353 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 399 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
354 } 400 }
355 #else 401 #else
356 #warning FIXME: setScreenSaverMode is not operational on the X11 build 402 #warning FIXME: setScreenSaverMode is not operational on the X11 build
357 #endif 403 #endif
358 404
359 // print out statistics 405 // print out statistics
360 for( QMap<QString,int>::ConstIterator it = pcap->statistics().begin(); it != pcap->statistics().end(); ++it ) 406 for( QMap<QString,int>::ConstIterator it = pcap->statistics().begin(); it != pcap->statistics().end(); ++it )
361 statwindow->updateCounter( it.key(), it.data() ); 407 statwindow->updateCounter( it.key(), it.data() );
362} 408}
363 409
364 410
365void Wellenreiter::startClicked() 411void Wellenreiter::startClicked()
366{ 412{
367 // get configuration from config window 413 // get configuration from config window
368 414
369 const QString& interface = configwindow->interfaceName->currentText(); 415 const QString& interface = configwindow->interfaceName->currentText();
370 const int cardtype = configwindow->driverType(); 416 const int cardtype = configwindow->driverType();
371 const int interval = configwindow->hoppingInterval(); 417 const int interval = configwindow->hoppingInterval();
372 418
373 if ( ( interface == "" ) || ( cardtype == 0 ) ) 419 if ( ( interface == "" ) || ( cardtype == 0 ) )
374 { 420 {
375 QMessageBox::information( this, "Wellenreiter II", 421 QMessageBox::information( this, "Wellenreiter II",
376 tr( "Your device is not\nproperly configured. Please reconfigure!" ) ); 422 tr( "Your device is not\nproperly configured. Please reconfigure!" ) );
377 return; 423 return;
378 } 424 }
379 425
380 // configure device 426 // configure device
381 ONetwork* net = ONetwork::instance(); 427 ONetwork* net = ONetwork::instance();
382 428
383 // TODO: check if interface is wireless and support sniffing for non-wireless interfaces 429 // TODO: check if interface is wireless and support sniffing for non-wireless interfaces
384 430
385 iface = static_cast<OWirelessNetworkInterface*>(net->interface( interface )); // fails if network is not wireless! 431 iface = static_cast<OWirelessNetworkInterface*>(net->interface( interface )); // fails if network is not wireless!
386 432
387 // bring device UP 433 // bring device UP
388 if ( cardtype != DEVTYPE_FILE ) 434 if ( cardtype != DEVTYPE_FILE )
389 { 435 {
390 iface->setUp( true ); 436 iface->setUp( true );
391 if ( !iface->isUp() ) 437 if ( !iface->isUp() )
392 { 438 {
393 QMessageBox::warning( this, "Wellenreiter II", 439 QMessageBox::warning( this, "Wellenreiter II",
394 tr( "Can't bring interface '%1' up:\n" ).arg( iface->name() ) + strerror( errno ) ); 440 tr( "Can't bring interface '%1' up:\n" ).arg( iface->name() ) + strerror( errno ) );
395 return; 441 return;
396 } 442 }
397 } 443 }
398 // set monitor mode 444 // set monitor mode
399 bool usePrism = configwindow->usePrismHeader(); 445 bool usePrism = configwindow->usePrismHeader();
400 446
401 switch ( cardtype ) 447 switch ( cardtype )
402 { 448 {
403 case DEVTYPE_CISCO: iface->setMonitoring( new OCiscoMonitoringInterface( iface, usePrism ) ); break; 449 case DEVTYPE_CISCO: iface->setMonitoring( new OCiscoMonitoringInterface( iface, usePrism ) ); break;
404 case DEVTYPE_WLAN_NG: iface->setMonitoring( new OWlanNGMonitoringInterface( iface, usePrism ) ); break; 450 case DEVTYPE_WLAN_NG: iface->setMonitoring( new OWlanNGMonitoringInterface( iface, usePrism ) ); break;
405 case DEVTYPE_HOSTAP: iface->setMonitoring( new OHostAPMonitoringInterface( iface, usePrism ) ); break; 451 case DEVTYPE_HOSTAP: iface->setMonitoring( new OHostAPMonitoringInterface( iface, usePrism ) ); break;
406 case DEVTYPE_ORINOCO: iface->setMonitoring( new OOrinocoMonitoringInterface( iface, usePrism ) ); break; 452 case DEVTYPE_ORINOCO: iface->setMonitoring( new OOrinocoMonitoringInterface( iface, usePrism ) ); break;
diff --git a/noncore/net/wellenreiter/gui/wellenreiter.h b/noncore/net/wellenreiter/gui/wellenreiter.h
index 43f6f99..ed96375 100644
--- a/noncore/net/wellenreiter/gui/wellenreiter.h
+++ b/noncore/net/wellenreiter/gui/wellenreiter.h
@@ -1,93 +1,98 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved. 2** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved.
3** 3**
4** This file is part of Opie Environment. 4** This file is part of Opie Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14**********************************************************************/ 14**********************************************************************/
15 15
16#ifndef WELLENREITER_H 16#ifndef WELLENREITER_H
17#define WELLENREITER_H 17#define WELLENREITER_H
18 18
19#include "wellenreiterbase.h" 19#include "wellenreiterbase.h"
20 20
21#ifdef QWS 21#ifdef QWS
22#include <opie/odevice.h> 22#include <opie/odevice.h>
23using namespace Opie; 23using namespace Opie;
24#endif 24#endif
25 25
26class QTimerEvent; 26class QTimerEvent;
27class QPixmap; 27class QPixmap;
28class OPacket; 28class OPacket;
29class OWaveLanManagementPacket; 29class OWaveLanManagementPacket;
30class OWaveLanDataPacket; 30class OWaveLanDataPacket;
31class OEthernetPacket;
32class OMacAddress;
33class OIPPacket;
31class OPacketCapturer; 34class OPacketCapturer;
32class OWirelessNetworkInterface; 35class OWirelessNetworkInterface;
33class WellenreiterConfigWindow; 36class WellenreiterConfigWindow;
34class MLogWindow; 37class MLogWindow;
35class MHexWindow; 38class MHexWindow;
36class GPS; 39class GPS;
37 40
38class Wellenreiter : public WellenreiterBase { 41class Wellenreiter : public WellenreiterBase {
39 Q_OBJECT 42 Q_OBJECT
40 43
41 public: 44 public:
42 Wellenreiter( QWidget* parent = 0 ); 45 Wellenreiter( QWidget* parent = 0 );
43 ~Wellenreiter(); 46 ~Wellenreiter();
44 47
45 void setConfigWindow( WellenreiterConfigWindow* cw ); 48 void setConfigWindow( WellenreiterConfigWindow* cw );
46 MScanListView* netView() const { return netview; }; 49 MScanListView* netView() const { return netview; };
47 MLogWindow* logWindow() const { return logwindow; }; 50 MLogWindow* logWindow() const { return logwindow; };
48 MHexWindow* hexWindow() const { return hexwindow; }; 51 MHexWindow* hexWindow() const { return hexwindow; };
49 bool isDaemonRunning() const { return sniffing; }; 52 bool isDaemonRunning() const { return sniffing; };
50 53
51 public: 54 public:
52 bool sniffing; 55 bool sniffing;
53 56
54 protected: 57 protected:
55 virtual void timerEvent( QTimerEvent* ); 58 virtual void timerEvent( QTimerEvent* );
56 59
57 public slots: 60 public slots:
58 void channelHopped(int); 61 void channelHopped(int);
59 void receivePacket(OPacket*); 62 void receivePacket(OPacket*);
60 void startClicked(); 63 void startClicked();
61 void stopClicked(); 64 void stopClicked();
62 65
63 void joinNetwork(const QString&,const QString&,int,const QString&); 66 void joinNetwork(const QString&,const QString&,int,const QString&);
64 67
65 signals: 68 signals:
66 void startedSniffing(); 69 void startedSniffing();
67 void stoppedSniffing(); 70 void stoppedSniffing();
68 71
69 private: 72 private:
70 void handleBeacon( OPacket* p, OWaveLanManagementPacket* beacon ); 73 void handleBeacon( OPacket* p, OWaveLanManagementPacket* beacon );
71 void handleData( OPacket* p, OWaveLanDataPacket* data ); 74 void handleWlanData( OPacket* p, OWaveLanDataPacket* data, OMacAddress& from, OMacAddress& to );
75 void handleEthernetData( OPacket* p, OEthernetPacket* data, OMacAddress& from, OMacAddress& to );
76 void handleIPData( OPacket* p, OIPPacket* ip, OMacAddress& from, OMacAddress& to );
72 void handleNotification( OPacket* p ); 77 void handleNotification( OPacket* p );
73 void doAction( const QString& action, const QString& protocol, OPacket* p ); 78 void doAction( const QString& action, const QString& protocol, OPacket* p );
74 QObject* childIfToParse( OPacket* p, const QString& protocol ); 79 QObject* childIfToParse( OPacket* p, const QString& protocol );
75 bool checkDumpPacket( OPacket* p ); 80 bool checkDumpPacket( OPacket* p );
76 81
77 private: 82 private:
78 #ifdef QWS 83 #ifdef QWS
79 OSystem _system; // Opie Operating System identifier 84 OSystem _system; // Opie Operating System identifier
80 #endif 85 #endif
81 86
82 OWirelessNetworkInterface* iface; 87 OWirelessNetworkInterface* iface;
83 OPacketCapturer* pcap; 88 OPacketCapturer* pcap;
84 WellenreiterConfigWindow* configwindow; 89 WellenreiterConfigWindow* configwindow;
85 GPS* gps; 90 GPS* gps;
86 91
87 //void readConfig(); 92 //void readConfig();
88 //void writeConfig(); 93 //void writeConfig();
89}; 94};
90 95
91 96
92 97
93#endif 98#endif
diff --git a/pics/wellenreiter/service.png b/pics/wellenreiter/service.png
new file mode 100755
index 0000000..4e06a0a
--- a/dev/null
+++ b/pics/wellenreiter/service.png
Binary files differ