summaryrefslogtreecommitdiff
path: root/libopie2/opienet
authormickeyl <mickeyl>2003-04-07 18:07:38 (UTC)
committer mickeyl <mickeyl>2003-04-07 18:07:38 (UTC)
commitcac6a08e456a057a19cc1fc56824fc98ff4f0bc1 (patch) (unidiff)
treeb17fa559629bcb9f49d685d3ec8b8dddc6a20f46 /libopie2/opienet
parent75f029f87d4c84b37ccfe1c81ef205a6cd5fca79 (diff)
downloadopie-cac6a08e456a057a19cc1fc56824fc98ff4f0bc1.zip
opie-cac6a08e456a057a19cc1fc56824fc98ff4f0bc1.tar.gz
opie-cac6a08e456a057a19cc1fc56824fc98ff4f0bc1.tar.bz2
- add OManufacturerDB
- API extensions for OMacAddress - add data packet recognition for miniwellenreiter
Diffstat (limited to 'libopie2/opienet') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/omanufacturerdb.cpp96
-rw-r--r--libopie2/opienet/omanufacturerdb.h37
-rw-r--r--libopie2/opienet/onetutils.cpp21
-rw-r--r--libopie2/opienet/onetutils.h3
-rw-r--r--libopie2/opienet/opcap.cpp8
-rw-r--r--libopie2/opienet/opienet.pro12
6 files changed, 162 insertions, 15 deletions
diff --git a/libopie2/opienet/omanufacturerdb.cpp b/libopie2/opienet/omanufacturerdb.cpp
new file mode 100644
index 0000000..ea15125
--- a/dev/null
+++ b/libopie2/opienet/omanufacturerdb.cpp
@@ -0,0 +1,96 @@
1/**********************************************************************
2** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved.
3**
4** This file is part of Opie Environment.
5**
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
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
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.
13**
14**********************************************************************/
15
16#include "omanufacturerdb.h"
17
18// Qt
19#include <qstring.h>
20#include <qfile.h>
21#include <qtextstream.h>
22
23OManufacturerDB* OManufacturerDB::_instance = 0;
24
25OManufacturerDB* OManufacturerDB::instance()
26{
27 if ( !OManufacturerDB::_instance )
28 {
29 qDebug( "OManufacturerDB::instance(): creating OManufacturerDB..." );
30 _instance = new OManufacturerDB();
31 }
32 return _instance;
33}
34
35
36OManufacturerDB::OManufacturerDB()
37{
38 QString filename( "/etc/manufacturers" );
39 qDebug( "OManufacturerDB: trying to read '%s'...", (const char*) filename );
40 if ( !QFile::exists( filename ) )
41 {
42 filename = "/opt/QtPalmtop/etc/manufacturers";
43 qDebug( "OManufacturerDB: trying to read '%s'...", (const char*) filename );
44 if ( !QFile::exists( filename ) )
45 {
46 filename = "/usr/share/wellenreiter/manufacturers";
47 qDebug( "OManufacturerDB: trying to read '%s'...", (const char*) filename );
48 }
49 }
50
51 QFile file( filename );
52 bool hasFile = file.open( IO_ReadOnly );
53 if (!hasFile)
54 {
55 qWarning( "OManufacturerDB: no valid manufacturer list found.", (const char*) filename );
56 }
57 else
58 {
59 qDebug( "OManufacturerDB: found manufacturer list in '%s'...", (const char*) filename );
60 QTextStream s( &file );
61 QString addr;
62 QString manu;
63 while (!s.atEnd())
64 {
65 s >> addr;
66 if ( !addr ) // read nothing!?
67 {
68 continue;
69 }
70 else
71 if ( addr[0] == '#' )
72 {
73 s.readLine();
74 continue;
75 }
76 s.skipWhiteSpace();
77 s >> manu;
78 s.readLine();
79 //qDebug( "ManufacturerDB: read pair %s, %s", (const char*) addr, (const char*) manu );
80 manufacturers.insert( addr, manu );
81
82 }
83 }
84
85}
86
87
88OManufacturerDB::~OManufacturerDB()
89{
90}
91
92
93const QString& OManufacturerDB::lookup( const QString& macaddr ) const
94{
95 return manufacturers[macaddr.upper().left(8)];
96}
diff --git a/libopie2/opienet/omanufacturerdb.h b/libopie2/opienet/omanufacturerdb.h
new file mode 100644
index 0000000..5e66c37
--- a/dev/null
+++ b/libopie2/opienet/omanufacturerdb.h
@@ -0,0 +1,37 @@
1/**********************************************************************
2** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved.
3**
4** This file is part of Opie Environment.
5**
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
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
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.
13**
14**********************************************************************/
15
16#ifndef OMANUFACTURERDB_H
17#define OMANUFACTURERDB_H
18
19#include <qmap.h>
20
21class OManufacturerDB
22{
23 public:
24 static OManufacturerDB* instance();
25 const QString& lookup( const QString& macaddr ) const;
26
27 protected:
28 OManufacturerDB();
29 virtual ~OManufacturerDB();
30
31 private:
32 QMap<QString, QString> manufacturers;
33 static OManufacturerDB* _instance;
34};
35
36#endif
37
diff --git a/libopie2/opienet/onetutils.cpp b/libopie2/opienet/onetutils.cpp
index 2485f30..236f108 100644
--- a/libopie2/opienet/onetutils.cpp
+++ b/libopie2/opienet/onetutils.cpp
@@ -1,212 +1,221 @@
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 35
35#include <net/if.h> 36#include <net/if.h>
36 37
37#include <cstdio> 38#include <cstdio>
38using namespace std; 39using namespace std;
39 40
40#define IW_PRIV_TYPE_MASK 0x7000 41#define IW_PRIV_TYPE_MASK 0x7000
41#define IW_PRIV_TYPE_NONE 0x0000 42#define IW_PRIV_TYPE_NONE 0x0000
42#define IW_PRIV_TYPE_BYTE 0x1000 43#define IW_PRIV_TYPE_BYTE 0x1000
43#define IW_PRIV_TYPE_CHAR 0x2000 44#define IW_PRIV_TYPE_CHAR 0x2000
44#define IW_PRIV_TYPE_INT 0x4000 45#define IW_PRIV_TYPE_INT 0x4000
45#define IW_PRIV_TYPE_FLOAT 0x5000 46#define IW_PRIV_TYPE_FLOAT 0x5000
46#define IW_PRIV_TYPE_ADDR 0x6000 47#define IW_PRIV_TYPE_ADDR 0x6000
47#define IW_PRIV_SIZE_FIXED 0x0800 48#define IW_PRIV_SIZE_FIXED 0x0800
48#define IW_PRIV_SIZE_MASK 0x07FF 49#define IW_PRIV_SIZE_MASK 0x07FF
49 50
50/*====================================================================================== 51/*======================================================================================
51 * OMacAddress 52 * OMacAddress
52 *======================================================================================*/ 53 *======================================================================================*/
53 54
54// static initializer for broadcast and unknown MAC Adresses 55// static initializer for broadcast and unknown MAC Adresses
55const unsigned char __broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; 56const unsigned char __broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
56const OMacAddress& OMacAddress::broadcast = OMacAddress( __broadcast ); 57const OMacAddress& OMacAddress::broadcast = OMacAddress( __broadcast );
57const unsigned char __unknown[6] = { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 }; 58const unsigned char __unknown[6] = { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 };
58const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown ); 59const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown );
59 60
60 61
61//TODO: Incorporate Ethernet Manufacturer database here! 62//TODO: Incorporate Ethernet Manufacturer database here!
62 63
63OMacAddress::OMacAddress( unsigned char* p ) 64OMacAddress::OMacAddress( unsigned char* p )
64{ 65{
65 memcpy( _bytes, p, 6 ); 66 memcpy( _bytes, p, 6 );
66} 67}
67 68
68 69
69OMacAddress::OMacAddress( const unsigned char* p ) 70OMacAddress::OMacAddress( const unsigned char* p )
70{ 71{
71 memcpy( _bytes, p, 6 ); 72 memcpy( _bytes, p, 6 );
72} 73}
73 74
74 75
75OMacAddress::OMacAddress( struct ifreq& ifr ) 76OMacAddress::OMacAddress( struct ifreq& ifr )
76{ 77{
77 memcpy( _bytes, ifr.ifr_hwaddr.sa_data, 6 ); 78 memcpy( _bytes, ifr.ifr_hwaddr.sa_data, 6 );
78} 79}
79 80
80 81
81OMacAddress::~OMacAddress() 82OMacAddress::~OMacAddress()
82{ 83{
83} 84}
84 85
85 86
86//#ifdef QT_NO_DEBUG 87//#ifdef QT_NO_DEBUG
87//inline 88//inline
88//#endif 89//#endif
89const unsigned char* OMacAddress::native() const 90const unsigned char* OMacAddress::native() const
90{ 91{
91 return (const unsigned char*) &_bytes; 92 return (const unsigned char*) &_bytes;
92} 93}
93 94
94 95
95OMacAddress OMacAddress::fromString( const QString& str ) 96OMacAddress OMacAddress::fromString( const QString& str )
96{ 97{
97 QString addr( str ); 98 QString addr( str );
98 unsigned char buf[6]; 99 unsigned char buf[6];
99 bool ok = true; 100 bool ok = true;
100 int index = 14; 101 int index = 14;
101 for ( int i = 5; i >= 0; --i ) 102 for ( int i = 5; i >= 0; --i )
102 { 103 {
103 buf[i] = addr.right( 2 ).toUShort( &ok, 16 ); 104 buf[i] = addr.right( 2 ).toUShort( &ok, 16 );
104 if ( !ok ) return OMacAddress::unknown; 105 if ( !ok ) return OMacAddress::unknown;
105 addr.truncate( index ); 106 addr.truncate( index );
106 index -= 3; 107 index -= 3;
107 } 108 }
108 return (const unsigned char*) &buf; 109 return (const unsigned char*) &buf;
109} 110}
110 111
111 112
112QString OMacAddress::toString() const 113QString OMacAddress::toString( bool substitute ) const
113{ 114{
114 QString s; 115 QString manu;
115 s.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", 116 manu.sprintf( "%.2X:%.2X:%.2X", _bytes[0]&0xff, _bytes[1]&0xff, _bytes[2]&0xff );
116 _bytes[0]&0xff, _bytes[1]&0xff, _bytes[2]&0xff, 117 QString serial;
117 _bytes[3]&0xff, _bytes[4]&0xff, _bytes[5]&0xff ); 118 serial.sprintf( ":%.2X:%.2X:%.2X", _bytes[3]&0xff, _bytes[4]&0xff, _bytes[5]&0xff );
118 return s; 119 if ( !substitute ) return manu+serial;
120 // fallback - if no vendor is found, just use the number
121 QString textmanu = OManufacturerDB::instance()->lookup( manu );
122 return textmanu.isNull() ? manu+serial : textmanu + serial;
119} 123}
120 124
121 125
126QString OMacAddress::manufacturer() const
127{
128 return OManufacturerDB::instance()->lookup( toString() );
129}
130
122bool operator==( const OMacAddress &m1, const OMacAddress &m2 ) 131bool operator==( const OMacAddress &m1, const OMacAddress &m2 )
123{ 132{
124 return memcmp( &m1._bytes, &m2._bytes, 6 ) == 0; 133 return memcmp( &m1._bytes, &m2._bytes, 6 ) == 0;
125} 134}
126 135
127 136
128/*====================================================================================== 137/*======================================================================================
129 * OHostAddress 138 * OHostAddress
130 *======================================================================================*/ 139 *======================================================================================*/
131 140
132 141
133/*====================================================================================== 142/*======================================================================================
134 * OPrivateIOCTL 143 * OPrivateIOCTL
135 *======================================================================================*/ 144 *======================================================================================*/
136 145
137OPrivateIOCTL::OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs ) 146OPrivateIOCTL::OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs )
138 :QObject( parent, name ), _ioctl( cmd ), _getargs( getargs ), _setargs( setargs ) 147 :QObject( parent, name ), _ioctl( cmd ), _getargs( getargs ), _setargs( setargs )
139{ 148{
140} 149}
141 150
142 151
143OPrivateIOCTL::~OPrivateIOCTL() 152OPrivateIOCTL::~OPrivateIOCTL()
144{ 153{
145} 154}
146 155
147 156
148#ifdef QT_NO_DEBUG 157#ifdef QT_NO_DEBUG
149inline 158inline
150#endif 159#endif
151int OPrivateIOCTL::numberGetArgs() const 160int OPrivateIOCTL::numberGetArgs() const
152{ 161{
153 return _getargs & IW_PRIV_SIZE_MASK; 162 return _getargs & IW_PRIV_SIZE_MASK;
154} 163}
155 164
156 165
157#ifdef QT_NO_DEBUG 166#ifdef QT_NO_DEBUG
158inline 167inline
159#endif 168#endif
160int OPrivateIOCTL::typeGetArgs() const 169int OPrivateIOCTL::typeGetArgs() const
161{ 170{
162 return _getargs & IW_PRIV_TYPE_MASK >> 12; 171 return _getargs & IW_PRIV_TYPE_MASK >> 12;
163} 172}
164 173
165 174
166#ifdef QT_NO_DEBUG 175#ifdef QT_NO_DEBUG
167inline 176inline
168#endif 177#endif
169int OPrivateIOCTL::numberSetArgs() const 178int OPrivateIOCTL::numberSetArgs() const
170{ 179{
171 return _setargs & IW_PRIV_SIZE_MASK; 180 return _setargs & IW_PRIV_SIZE_MASK;
172} 181}
173 182
174 183
175#ifdef QT_NO_DEBUG 184#ifdef QT_NO_DEBUG
176inline 185inline
177#endif 186#endif
178int OPrivateIOCTL::typeSetArgs() const 187int OPrivateIOCTL::typeSetArgs() const
179{ 188{
180 return _setargs & IW_PRIV_TYPE_MASK >> 12; 189 return _setargs & IW_PRIV_TYPE_MASK >> 12;
181} 190}
182 191
183 192
184void OPrivateIOCTL::invoke() const 193void OPrivateIOCTL::invoke() const
185{ 194{
186 ( (OWirelessNetworkInterface*) parent() )->wioctl( _ioctl ); 195 ( (OWirelessNetworkInterface*) parent() )->wioctl( _ioctl );
187} 196}
188 197
189 198
190void OPrivateIOCTL::setParameter( int num, u_int32_t value ) 199void OPrivateIOCTL::setParameter( int num, u_int32_t value )
191{ 200{
192 u_int32_t* arglist = (u_int32_t*) &( (OWirelessNetworkInterface*) parent() )->_iwr.u.name; 201 u_int32_t* arglist = (u_int32_t*) &( (OWirelessNetworkInterface*) parent() )->_iwr.u.name;
193 arglist[num] = value; 202 arglist[num] = value;
194} 203}
195 204
196/*====================================================================================== 205/*======================================================================================
197 * assorted functions 206 * assorted functions
198 *======================================================================================*/ 207 *======================================================================================*/
199 208
200void dumpBytes( const unsigned char* data, int num ) 209void dumpBytes( const unsigned char* data, int num )
201{ 210{
202 printf( "Dumping %d bytes @ %0x", num, data ); 211 printf( "Dumping %d bytes @ %0x", num, data );
203 printf( "-------------------------------------------\n" ); 212 printf( "-------------------------------------------\n" );
204 213
205 for ( int i = 0; i < num; ++i ) 214 for ( int i = 0; i < num; ++i )
206 { 215 {
207 printf( "%02x ", data[i] ); 216 printf( "%02x ", data[i] );
208 if ( !((i+1) % 32) ) printf( "\n" ); 217 if ( !((i+1) % 32) ) printf( "\n" );
209 } 218 }
210 printf( "\n\n" ); 219 printf( "\n\n" );
211} 220}
212 221
diff --git a/libopie2/opienet/onetutils.h b/libopie2/opienet/onetutils.h
index 73d52cc..bedea63 100644
--- a/libopie2/opienet/onetutils.h
+++ b/libopie2/opienet/onetutils.h
@@ -1,154 +1,155 @@
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 OMacAddress( unsigned char* ); 53 OMacAddress( unsigned char* );
54 OMacAddress( const unsigned char* ); 54 OMacAddress( const unsigned char* );
55 OMacAddress( struct ifreq& ); 55 OMacAddress( struct ifreq& );
56 ~OMacAddress(); 56 ~OMacAddress();
57 57
58 QString toString() const; 58 QString manufacturer() const;
59 QString toString( bool substitute = false ) const;
59 const unsigned char* native() const; 60 const unsigned char* native() const;
60 61
61 static OMacAddress fromString( const QString& ); 62 static OMacAddress fromString( const QString& );
62 63
63 public: 64 public:
64 static const OMacAddress& broadcast; // ff:ff:ff:ff:ff:ff 65 static const OMacAddress& broadcast; // ff:ff:ff:ff:ff:ff
65 static const OMacAddress& unknown; // 44:44:44:44:44:44 66 static const OMacAddress& unknown; // 44:44:44:44:44:44
66 67
67 private: 68 private:
68 unsigned char _bytes[6]; 69 unsigned char _bytes[6];
69 70
70 friend bool operator==( const OMacAddress &m1, const OMacAddress &m2 ); 71 friend bool operator==( const OMacAddress &m1, const OMacAddress &m2 );
71 72
72}; 73};
73 74
74bool operator==( const OMacAddress &m1, const OMacAddress &m2 ); 75bool operator==( const OMacAddress &m1, const OMacAddress &m2 );
75 76
76 77
77/*====================================================================================== 78/*======================================================================================
78 * OHostAddress 79 * OHostAddress
79 *======================================================================================*/ 80 *======================================================================================*/
80 81
81class OHostAddress : public QHostAddress 82class OHostAddress : public QHostAddress
82{ 83{
83 public: 84 public:
84 OHostAddress(); 85 OHostAddress();
85 ~OHostAddress(); 86 ~OHostAddress();
86}; 87};
87 88
88 89
89/*====================================================================================== 90/*======================================================================================
90 * OPrivateIOCTL 91 * OPrivateIOCTL
91 *======================================================================================*/ 92 *======================================================================================*/
92 93
93class OPrivateIOCTL : public QObject 94class OPrivateIOCTL : public QObject
94{ 95{
95 public: 96 public:
96 OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs ); 97 OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs );
97 ~OPrivateIOCTL(); 98 ~OPrivateIOCTL();
98 99
99 int numberGetArgs() const; 100 int numberGetArgs() const;
100 int typeGetArgs() const; 101 int typeGetArgs() const;
101 int numberSetArgs() const; 102 int numberSetArgs() const;
102 int typeSetArgs() const; 103 int typeSetArgs() const;
103 104
104 void invoke() const; 105 void invoke() const;
105 void setParameter( int, u_int32_t ); 106 void setParameter( int, u_int32_t );
106 107
107 private: 108 private:
108 u_int32_t _ioctl; 109 u_int32_t _ioctl;
109 u_int16_t _getargs; 110 u_int16_t _getargs;
110 u_int16_t _setargs; 111 u_int16_t _setargs;
111 112
112}; 113};
113 114
114 /*====================================================================================== 115 /*======================================================================================
115 * Miscellaneous 116 * Miscellaneous
116 *======================================================================================*/ 117 *======================================================================================*/
117 118
118/* dump bytes */ 119/* dump bytes */
119 120
120void dumpBytes( const unsigned char* data, int num ); 121void dumpBytes( const unsigned char* data, int num );
121 122
122/* Network to host order macros */ 123/* Network to host order macros */
123 124
124#ifdef LBL_ALIGN 125#ifdef LBL_ALIGN
125#define EXTRACT_16BITS(p) \ 126#define EXTRACT_16BITS(p) \
126 ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 0) << 8 | \ 127 ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 0) << 8 | \
127 (u_int16_t)*((const u_int8_t *)(p) + 1))) 128 (u_int16_t)*((const u_int8_t *)(p) + 1)))
128#define EXTRACT_32BITS(p) \ 129#define EXTRACT_32BITS(p) \
129 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 24 | \ 130 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 24 | \
130 (u_int32_t)*((const u_int8_t *)(p) + 1) << 16 | \ 131 (u_int32_t)*((const u_int8_t *)(p) + 1) << 16 | \
131 (u_int32_t)*((const u_int8_t *)(p) + 2) << 8 | \ 132 (u_int32_t)*((const u_int8_t *)(p) + 2) << 8 | \
132 (u_int32_t)*((const u_int8_t *)(p) + 3))) 133 (u_int32_t)*((const u_int8_t *)(p) + 3)))
133#else 134#else
134#define EXTRACT_16BITS(p) \ 135#define EXTRACT_16BITS(p) \
135 ((u_int16_t)ntohs(*(const u_int16_t *)(p))) 136 ((u_int16_t)ntohs(*(const u_int16_t *)(p)))
136#define EXTRACT_32BITS(p) \ 137#define EXTRACT_32BITS(p) \
137 ((u_int32_t)ntohl(*(const u_int32_t *)(p))) 138 ((u_int32_t)ntohl(*(const u_int32_t *)(p)))
138#endif 139#endif
139 140
140#define EXTRACT_24BITS(p) \ 141#define EXTRACT_24BITS(p) \
141 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 16 | \ 142 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 16 | \
142 (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ 143 (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \
143 (u_int32_t)*((const u_int8_t *)(p) + 2))) 144 (u_int32_t)*((const u_int8_t *)(p) + 2)))
144 145
145/* Little endian protocol host order macros */ 146/* Little endian protocol host order macros */
146#define EXTRACT_LE_8BITS(p) (*(p)) 147#define EXTRACT_LE_8BITS(p) (*(p))
147#define EXTRACT_LE_16BITS(p) \ 148#define EXTRACT_LE_16BITS(p) \
148 ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 1) << 8 | \ 149 ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 1) << 8 | \
149 (u_int16_t)*((const u_int8_t *)(p) + 0))) 150 (u_int16_t)*((const u_int8_t *)(p) + 0)))
150#define EXTRACT_LE_32BITS(p) \ 151#define EXTRACT_LE_32BITS(p) \
151 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 3) << 24 | \ 152 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 3) << 24 | \
152 (u_int32_t)*((const u_int8_t *)(p) + 2) << 16 | \ 153 (u_int32_t)*((const u_int8_t *)(p) + 2) << 16 | \
153 (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ 154 (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \
154 (u_int32_t)*((const u_int8_t *)(p) + 0))) 155 (u_int32_t)*((const u_int8_t *)(p) + 0)))
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index 6ddd457..40aac2c 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -546,214 +546,214 @@ OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const stru
546 qDebug( "OWaveLanManagementCF()" ); 546 qDebug( "OWaveLanManagementCF()" );
547} 547}
548 548
549 549
550OWaveLanManagementCF::~OWaveLanManagementCF() 550OWaveLanManagementCF::~OWaveLanManagementCF()
551{ 551{
552} 552}
553 553
554/*====================================================================================== 554/*======================================================================================
555 * OWaveLanManagementFH 555 * OWaveLanManagementFH
556 *======================================================================================*/ 556 *======================================================================================*/
557 557
558OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) 558OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent )
559 :QObject( parent, "802.11 FH" ), _data( data ) 559 :QObject( parent, "802.11 FH" ), _data( data )
560{ 560{
561 qDebug( "OWaveLanManagementFH()" ); 561 qDebug( "OWaveLanManagementFH()" );
562} 562}
563 563
564 564
565OWaveLanManagementFH::~OWaveLanManagementFH() 565OWaveLanManagementFH::~OWaveLanManagementFH()
566{ 566{
567} 567}
568 568
569/*====================================================================================== 569/*======================================================================================
570 * OWaveLanManagementDS 570 * OWaveLanManagementDS
571 *======================================================================================*/ 571 *======================================================================================*/
572 572
573OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) 573OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent )
574 :QObject( parent, "802.11 DS" ), _data( data ) 574 :QObject( parent, "802.11 DS" ), _data( data )
575{ 575{
576 qDebug( "OWaveLanManagementDS()" ); 576 qDebug( "OWaveLanManagementDS()" );
577} 577}
578 578
579 579
580OWaveLanManagementDS::~OWaveLanManagementDS() 580OWaveLanManagementDS::~OWaveLanManagementDS()
581{ 581{
582} 582}
583 583
584 584
585int OWaveLanManagementDS::channel() const 585int OWaveLanManagementDS::channel() const
586{ 586{
587 return _data->channel; 587 return _data->channel;
588} 588}
589 589
590/*====================================================================================== 590/*======================================================================================
591 * OWaveLanManagementTim 591 * OWaveLanManagementTim
592 *======================================================================================*/ 592 *======================================================================================*/
593 593
594OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) 594OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent )
595 :QObject( parent, "802.11 Tim" ), _data( data ) 595 :QObject( parent, "802.11 Tim" ), _data( data )
596{ 596{
597 qDebug( "OWaveLanManagementTim()" ); 597 qDebug( "OWaveLanManagementTim()" );
598} 598}
599 599
600 600
601OWaveLanManagementTim::~OWaveLanManagementTim() 601OWaveLanManagementTim::~OWaveLanManagementTim()
602{ 602{
603} 603}
604 604
605/*====================================================================================== 605/*======================================================================================
606 * OWaveLanManagementIBSS 606 * OWaveLanManagementIBSS
607 *======================================================================================*/ 607 *======================================================================================*/
608 608
609OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) 609OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent )
610 :QObject( parent, "802.11 IBSS" ), _data( data ) 610 :QObject( parent, "802.11 IBSS" ), _data( data )
611{ 611{
612 qDebug( "OWaveLanManagementIBSS()" ); 612 qDebug( "OWaveLanManagementIBSS()" );
613} 613}
614 614
615 615
616OWaveLanManagementIBSS::~OWaveLanManagementIBSS() 616OWaveLanManagementIBSS::~OWaveLanManagementIBSS()
617{ 617{
618} 618}
619 619
620/*====================================================================================== 620/*======================================================================================
621 * OWaveLanManagementChallenge 621 * OWaveLanManagementChallenge
622 *======================================================================================*/ 622 *======================================================================================*/
623 623
624OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) 624OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent )
625 :QObject( parent, "802.11 Challenge" ), _data( data ) 625 :QObject( parent, "802.11 Challenge" ), _data( data )
626{ 626{
627 qDebug( "OWaveLanManagementChallenge()" ); 627 qDebug( "OWaveLanManagementChallenge()" );
628} 628}
629 629
630 630
631OWaveLanManagementChallenge::~OWaveLanManagementChallenge() 631OWaveLanManagementChallenge::~OWaveLanManagementChallenge()
632{ 632{
633} 633}
634 634
635/*====================================================================================== 635/*======================================================================================
636 * OWaveLanDataPacket 636 * OWaveLanDataPacket
637 *======================================================================================*/ 637 *======================================================================================*/
638 638
639OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) 639OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent )
640 :QObject( parent, "802.11 Data" ), _header( data ) 640 :QObject( parent, "802.11 Data" ), _header( data )
641{ 641{
642 //qDebug( "size of header = %d", sizeof( struct ieee_802_11_data_header ) ); 642 qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." );
643 //qDebug( "header: %0x", data ); 643
644 const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); 644 const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header );
645 //qDebug( "payload: %0x", payload );
646 645
646 #warning The next line works for most cases, but can not be correct generally!
647 if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address 647 if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address
648 648
649 new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); 649 new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this );
650} 650}
651 651
652 652
653OWaveLanDataPacket::~OWaveLanDataPacket() 653OWaveLanDataPacket::~OWaveLanDataPacket()
654{ 654{
655} 655}
656 656
657 657
658/*====================================================================================== 658/*======================================================================================
659 * OLLCPacket 659 * OLLCPacket
660 *======================================================================================*/ 660 *======================================================================================*/
661 661
662OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) 662OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent )
663 :QObject( parent, "802.11 802_2" ), _header( data ) 663 :QObject( parent, "802.11 LLC" ), _header( data )
664{ 664{
665 qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." ); 665 qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." );
666 666
667 if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) 667 if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) )
668 { 668 {
669 qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) ); 669 qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) );
670 670
671 switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h 671 switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h
672 { 672 {
673 case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; 673 case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break;
674 default: qDebug( "OLLCPacket::OLLCPacket(): Unknown Encapsulation Type" ); 674 default: qDebug( "OLLCPacket::OLLCPacket(): Unknown Encapsulation Type" );
675 } 675 }
676 676
677 } 677 }
678} 678}
679 679
680 680
681OLLCPacket::~OLLCPacket() 681OLLCPacket::~OLLCPacket()
682{ 682{
683} 683}
684 684
685/*====================================================================================== 685/*======================================================================================
686 * OPacketCapturer 686 * OPacketCapturer
687 *======================================================================================*/ 687 *======================================================================================*/
688 688
689OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) 689OPacketCapturer::OPacketCapturer( QObject* parent, const char* name )
690 :QObject( parent, name ), _name( QString::null ), _open( false ), 690 :QObject( parent, name ), _name( QString::null ), _open( false ),
691 _pch( 0 ), _sn( 0 ) 691 _pch( 0 ), _sn( 0 )
692{ 692{
693} 693}
694 694
695 695
696OPacketCapturer::~OPacketCapturer() 696OPacketCapturer::~OPacketCapturer()
697{ 697{
698 if ( _open ) 698 if ( _open )
699 { 699 {
700 qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." ); 700 qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." );
701 close(); 701 close();
702 } 702 }
703} 703}
704 704
705 705
706void OPacketCapturer::setBlocking( bool b ) 706void OPacketCapturer::setBlocking( bool b )
707{ 707{
708 if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) 708 if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 )
709 { 709 {
710 qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." ); 710 qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." );
711 } 711 }
712 else 712 else
713 { 713 {
714 qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf ); 714 qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf );
715 } 715 }
716} 716}
717 717
718 718
719bool OPacketCapturer::blocking() const 719bool OPacketCapturer::blocking() const
720{ 720{
721 int b = pcap_getnonblock( _pch, _errbuf ); 721 int b = pcap_getnonblock( _pch, _errbuf );
722 if ( b == -1 ) 722 if ( b == -1 )
723 { 723 {
724 qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf ); 724 qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf );
725 return -1; 725 return -1;
726 } 726 }
727 return !b; 727 return !b;
728} 728}
729 729
730 730
731void OPacketCapturer::close() 731void OPacketCapturer::close()
732{ 732{
733 if ( _open ) 733 if ( _open )
734 { 734 {
735 if ( _sn ) 735 if ( _sn )
736 { 736 {
737 _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 737 _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
738 delete _sn; 738 delete _sn;
739 } 739 }
740 pcap_close( _pch ); 740 pcap_close( _pch );
741 _open = false; 741 _open = false;
742 } 742 }
743} 743}
744 744
745 745
746int OPacketCapturer::dataLink() const 746int OPacketCapturer::dataLink() const
747{ 747{
748 return pcap_datalink( _pch ); 748 return pcap_datalink( _pch );
749} 749}
750 750
751 751
752int OPacketCapturer::fileno() const 752int OPacketCapturer::fileno() const
753{ 753{
754 if ( _open ) 754 if ( _open )
755 { 755 {
756 return pcap_fileno( _pch ); 756 return pcap_fileno( _pch );
757 } 757 }
758 else 758 else
759 { 759 {
diff --git a/libopie2/opienet/opienet.pro b/libopie2/opienet/opienet.pro
index e73afbf..3f9166a 100644
--- a/libopie2/opienet/opienet.pro
+++ b/libopie2/opienet/opienet.pro
@@ -1,18 +1,22 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qt warn_on debug 2CONFIG += qt warn_on debug
3DESTDIR = $(OPIEDIR)/lib 3DESTDIR = $(OPIEDIR)/lib
4HEADERS = onetutils.cpp onetwork.h opcap.h 4HEADERS = omanufacturerdb.cpp \
5 5 onetutils.cpp \
6SOURCES = onetutils.cpp onetwork.cpp opcap.cpp 6 onetwork.h \
7 opcap.h
8SOURCES = omanufacturerdb.cpp \
9 onetutils.cpp \
10 onetwork.cpp \
11 opcap.cpp
7INTERFACES = 12INTERFACES =
8TARGET = opienet2 13TARGET = opienet2
9VERSION = 1.8.1 14VERSION = 1.8.1
10INCLUDEPATH += $(OPIEDIR)/include 15INCLUDEPATH += $(OPIEDIR)/include
11DEPENDPATH += $(OPIEDIR)/include 16DEPENDPATH += $(OPIEDIR)/include
12LIBS += -lpcap 17LIBS += -lpcap
13
14MOC_DIR = moc 18MOC_DIR = moc
15OBJECTS_DIR = obj 19OBJECTS_DIR = obj
16 20
17include ( $(OPIEDIR)/include.pro ) 21include ( $(OPIEDIR)/include.pro )
18 22