-rw-r--r-- | libopie2/opienet/onetutils.cpp | 59 | ||||
-rw-r--r-- | libopie2/opienet/onetutils.h | 25 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 127 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.h | 21 |
4 files changed, 178 insertions, 54 deletions
diff --git a/libopie2/opienet/onetutils.cpp b/libopie2/opienet/onetutils.cpp index 8006f41..3e11b53 100644 --- a/libopie2/opienet/onetutils.cpp +++ b/libopie2/opienet/onetutils.cpp | |||
@@ -1,101 +1,160 @@ | |||
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 | 33 | ||
34 | #include <net/if.h> | 34 | #include <net/if.h> |
35 | 35 | ||
36 | #include <cstdio> | 36 | #include <cstdio> |
37 | using namespace std; | 37 | using namespace std; |
38 | 38 | ||
39 | #define IW_PRIV_TYPE_MASK 0x7000 | ||
40 | #define IW_PRIV_TYPE_NONE 0x0000 | ||
41 | #define IW_PRIV_TYPE_BYTE 0x1000 | ||
42 | #define IW_PRIV_TYPE_CHAR 0x2000 | ||
43 | #define IW_PRIV_TYPE_INT 0x4000 | ||
44 | #define IW_PRIV_TYPE_FLOAT 0x5000 | ||
45 | #define IW_PRIV_TYPE_ADDR 0x6000 | ||
46 | #define IW_PRIV_SIZE_FIXED 0x0800 | ||
47 | #define IW_PRIV_SIZE_MASK 0x07FF | ||
48 | |||
39 | /*====================================================================================== | 49 | /*====================================================================================== |
40 | * OMacAddress | 50 | * OMacAddress |
41 | *======================================================================================*/ | 51 | *======================================================================================*/ |
42 | 52 | ||
43 | // static initializer for broadcast and unknown MAC Adresses | 53 | // static initializer for broadcast and unknown MAC Adresses |
44 | const unsigned char __broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | 54 | const unsigned char __broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
45 | const OMacAddress& OMacAddress::broadcast = OMacAddress( __broadcast ); | 55 | const OMacAddress& OMacAddress::broadcast = OMacAddress( __broadcast ); |
46 | const unsigned char __unknown[6] = { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 }; | 56 | const unsigned char __unknown[6] = { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 }; |
47 | const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown ); | 57 | const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown ); |
48 | 58 | ||
49 | 59 | ||
50 | //TODO: Incorporate Ethernet Manufacturer database here! | 60 | //TODO: Incorporate Ethernet Manufacturer database here! |
51 | 61 | ||
52 | OMacAddress::OMacAddress( unsigned char* p ) | 62 | OMacAddress::OMacAddress( unsigned char* p ) |
53 | { | 63 | { |
54 | memcpy( _bytes, p, 6 ); // D'OH! memcpy in my sources... eeek... | 64 | memcpy( _bytes, p, 6 ); // D'OH! memcpy in my sources... eeek... |
55 | } | 65 | } |
56 | 66 | ||
57 | 67 | ||
58 | OMacAddress::OMacAddress( const unsigned char* p ) | 68 | OMacAddress::OMacAddress( const unsigned char* p ) |
59 | { | 69 | { |
60 | memcpy( _bytes, p, 6 ); | 70 | memcpy( _bytes, p, 6 ); |
61 | } | 71 | } |
62 | 72 | ||
63 | 73 | ||
64 | OMacAddress::OMacAddress( struct ifreq& ifr ) | 74 | OMacAddress::OMacAddress( struct ifreq& ifr ) |
65 | { | 75 | { |
66 | memcpy( _bytes, ifr.ifr_hwaddr.sa_data, 6 ); | 76 | memcpy( _bytes, ifr.ifr_hwaddr.sa_data, 6 ); |
67 | } | 77 | } |
68 | 78 | ||
69 | 79 | ||
70 | OMacAddress::~OMacAddress() | 80 | OMacAddress::~OMacAddress() |
71 | { | 81 | { |
72 | } | 82 | } |
73 | 83 | ||
74 | 84 | ||
75 | QString OMacAddress::toString() const | 85 | QString OMacAddress::toString() const |
76 | { | 86 | { |
77 | QString s; | 87 | QString s; |
78 | s.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | 88 | s.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", |
79 | _bytes[0]&0xff, _bytes[1]&0xff, _bytes[2]&0xff, | 89 | _bytes[0]&0xff, _bytes[1]&0xff, _bytes[2]&0xff, |
80 | _bytes[3]&0xff, _bytes[4]&0xff, _bytes[5]&0xff ); | 90 | _bytes[3]&0xff, _bytes[4]&0xff, _bytes[5]&0xff ); |
81 | return s; | 91 | return s; |
82 | } | 92 | } |
83 | 93 | ||
84 | 94 | ||
85 | bool operator==( const OMacAddress &m1, const OMacAddress &m2 ) | 95 | bool operator==( const OMacAddress &m1, const OMacAddress &m2 ) |
86 | { | 96 | { |
87 | return memcmp( &m1._bytes, &m2._bytes, 6 ) == 0; | 97 | return memcmp( &m1._bytes, &m2._bytes, 6 ) == 0; |
88 | } | 98 | } |
89 | 99 | ||
100 | |||
101 | /*====================================================================================== | ||
102 | * OHostAddress | ||
103 | *======================================================================================*/ | ||
104 | |||
105 | |||
106 | /*====================================================================================== | ||
107 | * OPrivateIOCTL | ||
108 | *======================================================================================*/ | ||
109 | |||
110 | OPrivateIOCTL::OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs ) | ||
111 | :QObject( parent, name ), _ioctl( cmd ), _getargs( getargs ), _setargs( setargs ) | ||
112 | { | ||
113 | } | ||
114 | |||
115 | |||
116 | OPrivateIOCTL::~OPrivateIOCTL() | ||
117 | { | ||
118 | } | ||
119 | |||
120 | |||
121 | inline int OPrivateIOCTL::numberGetArgs() const | ||
122 | { | ||
123 | return _getargs & IW_PRIV_SIZE_MASK; | ||
124 | } | ||
125 | |||
126 | |||
127 | inline int OPrivateIOCTL::typeGetArgs() const | ||
128 | { | ||
129 | return _getargs & IW_PRIV_TYPE_MASK >> 12; | ||
130 | } | ||
131 | |||
132 | |||
133 | inline int OPrivateIOCTL::numberSetArgs() const | ||
134 | { | ||
135 | return _setargs & IW_PRIV_SIZE_MASK; | ||
136 | } | ||
137 | |||
138 | |||
139 | inline int OPrivateIOCTL::typeSetArgs() const | ||
140 | { | ||
141 | return _setargs & IW_PRIV_TYPE_MASK >> 12; | ||
142 | } | ||
143 | |||
144 | |||
145 | /*====================================================================================== | ||
146 | * assorted functions | ||
147 | *======================================================================================*/ | ||
148 | |||
90 | void dumpBytes( const unsigned char* data, int num ) | 149 | void dumpBytes( const unsigned char* data, int num ) |
91 | { | 150 | { |
92 | printf( "Dumping %d bytes @ %0x", num, data ); | 151 | printf( "Dumping %d bytes @ %0x", num, data ); |
93 | printf( "-------------------------------------------\n" ); | 152 | printf( "-------------------------------------------\n" ); |
94 | 153 | ||
95 | for ( int i = 0; i < num; ++i ) | 154 | for ( int i = 0; i < num; ++i ) |
96 | { | 155 | { |
97 | printf( "%02x ", data[i] ); | 156 | printf( "%02x ", data[i] ); |
98 | if ( !((i+1) % 32) ) printf( "\n" ); | 157 | if ( !((i+1) % 32) ) printf( "\n" ); |
99 | } | 158 | } |
100 | printf( "\n\n" ); | 159 | printf( "\n\n" ); |
101 | } | 160 | } |
diff --git a/libopie2/opienet/onetutils.h b/libopie2/opienet/onetutils.h index 0dabe8d..6640515 100644 --- a/libopie2/opienet/onetutils.h +++ b/libopie2/opienet/onetutils.h | |||
@@ -1,125 +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> | ||
40 | |||
41 | #include <sys/types.h> | ||
39 | 42 | ||
40 | struct ifreq; | 43 | struct ifreq; |
44 | class OWirelessNetworkInterface; | ||
41 | 45 | ||
42 | /*====================================================================================== | 46 | /*====================================================================================== |
43 | * OMacAddress | 47 | * OMacAddress |
44 | *======================================================================================*/ | 48 | *======================================================================================*/ |
45 | 49 | ||
46 | class OMacAddress | 50 | class OMacAddress |
47 | { | 51 | { |
48 | public: | 52 | public: |
49 | OMacAddress( unsigned char* ); | 53 | OMacAddress( unsigned char* ); |
50 | OMacAddress( const unsigned char* ); | 54 | OMacAddress( const unsigned char* ); |
51 | OMacAddress( struct ifreq& ); | 55 | OMacAddress( struct ifreq& ); |
52 | ~OMacAddress(); | 56 | ~OMacAddress(); |
53 | 57 | ||
54 | QString toString() const; | 58 | QString toString() const; |
55 | 59 | ||
56 | public: | 60 | public: |
57 | static const OMacAddress& broadcast; // ff:ff:ff:ff:ff:ff | 61 | static const OMacAddress& broadcast; // ff:ff:ff:ff:ff:ff |
58 | static const OMacAddress& unknown; // 44:44:44:44:44:44 | 62 | static const OMacAddress& unknown; // 44:44:44:44:44:44 |
59 | 63 | ||
60 | private: | 64 | private: |
61 | unsigned char _bytes[6]; | 65 | unsigned char _bytes[6]; |
62 | 66 | ||
63 | friend bool operator==( const OMacAddress &m1, const OMacAddress &m2 ); | 67 | friend bool operator==( const OMacAddress &m1, const OMacAddress &m2 ); |
64 | 68 | ||
65 | }; | 69 | }; |
66 | 70 | ||
67 | bool operator==( const OMacAddress &m1, const OMacAddress &m2 ); | 71 | bool operator==( const OMacAddress &m1, const OMacAddress &m2 ); |
68 | 72 | ||
69 | 73 | ||
70 | /*====================================================================================== | 74 | /*====================================================================================== |
71 | * OHostAddress | 75 | * OHostAddress |
72 | *======================================================================================*/ | 76 | *======================================================================================*/ |
73 | 77 | ||
74 | class OHostAddress : public QHostAddress | 78 | class OHostAddress : public QHostAddress |
75 | { | 79 | { |
76 | public: | 80 | public: |
77 | OHostAddress(); | 81 | OHostAddress(); |
78 | ~OHostAddress(); | 82 | ~OHostAddress(); |
79 | }; | 83 | }; |
80 | 84 | ||
81 | 85 | ||
82 | /*====================================================================================== | 86 | /*====================================================================================== |
87 | * OPrivateIOCTL | ||
88 | *======================================================================================*/ | ||
89 | |||
90 | class OPrivateIOCTL : public QObject | ||
91 | { | ||
92 | public: | ||
93 | OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs ); | ||
94 | ~OPrivateIOCTL(); | ||
95 | |||
96 | int numberGetArgs() const; | ||
97 | int typeGetArgs() const; | ||
98 | int numberSetArgs() const; | ||
99 | int typeSetArgs() const; | ||
100 | |||
101 | private: | ||
102 | u_int32_t _ioctl; | ||
103 | u_int16_t _getargs; | ||
104 | u_int16_t _setargs; | ||
105 | }; | ||
106 | |||
107 | /*====================================================================================== | ||
83 | * Miscellaneous | 108 | * Miscellaneous |
84 | *======================================================================================*/ | 109 | *======================================================================================*/ |
85 | 110 | ||
86 | /* dump bytes */ | 111 | /* dump bytes */ |
87 | 112 | ||
88 | void dumpBytes( const unsigned char* data, int num ); | 113 | void dumpBytes( const unsigned char* data, int num ); |
89 | 114 | ||
90 | /* Network to host order macros */ | 115 | /* Network to host order macros */ |
91 | 116 | ||
92 | #ifdef LBL_ALIGN | 117 | #ifdef LBL_ALIGN |
93 | #define EXTRACT_16BITS(p) \ | 118 | #define EXTRACT_16BITS(p) \ |
94 | ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 0) << 8 | \ | 119 | ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 0) << 8 | \ |
95 | (u_int16_t)*((const u_int8_t *)(p) + 1))) | 120 | (u_int16_t)*((const u_int8_t *)(p) + 1))) |
96 | #define EXTRACT_32BITS(p) \ | 121 | #define EXTRACT_32BITS(p) \ |
97 | ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 24 | \ | 122 | ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 24 | \ |
98 | (u_int32_t)*((const u_int8_t *)(p) + 1) << 16 | \ | 123 | (u_int32_t)*((const u_int8_t *)(p) + 1) << 16 | \ |
99 | (u_int32_t)*((const u_int8_t *)(p) + 2) << 8 | \ | 124 | (u_int32_t)*((const u_int8_t *)(p) + 2) << 8 | \ |
100 | (u_int32_t)*((const u_int8_t *)(p) + 3))) | 125 | (u_int32_t)*((const u_int8_t *)(p) + 3))) |
101 | #else | 126 | #else |
102 | #define EXTRACT_16BITS(p) \ | 127 | #define EXTRACT_16BITS(p) \ |
103 | ((u_int16_t)ntohs(*(const u_int16_t *)(p))) | 128 | ((u_int16_t)ntohs(*(const u_int16_t *)(p))) |
104 | #define EXTRACT_32BITS(p) \ | 129 | #define EXTRACT_32BITS(p) \ |
105 | ((u_int32_t)ntohl(*(const u_int32_t *)(p))) | 130 | ((u_int32_t)ntohl(*(const u_int32_t *)(p))) |
106 | #endif | 131 | #endif |
107 | 132 | ||
108 | #define EXTRACT_24BITS(p) \ | 133 | #define EXTRACT_24BITS(p) \ |
109 | ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 16 | \ | 134 | ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 16 | \ |
110 | (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ | 135 | (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ |
111 | (u_int32_t)*((const u_int8_t *)(p) + 2))) | 136 | (u_int32_t)*((const u_int8_t *)(p) + 2))) |
112 | 137 | ||
113 | /* Little endian protocol host order macros */ | 138 | /* Little endian protocol host order macros */ |
114 | #define EXTRACT_LE_8BITS(p) (*(p)) | 139 | #define EXTRACT_LE_8BITS(p) (*(p)) |
115 | #define EXTRACT_LE_16BITS(p) \ | 140 | #define EXTRACT_LE_16BITS(p) \ |
116 | ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 1) << 8 | \ | 141 | ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 1) << 8 | \ |
117 | (u_int16_t)*((const u_int8_t *)(p) + 0))) | 142 | (u_int16_t)*((const u_int8_t *)(p) + 0))) |
118 | #define EXTRACT_LE_32BITS(p) \ | 143 | #define EXTRACT_LE_32BITS(p) \ |
119 | ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 3) << 24 | \ | 144 | ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 3) << 24 | \ |
120 | (u_int32_t)*((const u_int8_t *)(p) + 2) << 16 | \ | 145 | (u_int32_t)*((const u_int8_t *)(p) + 2) << 16 | \ |
121 | (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ | 146 | (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ |
122 | (u_int32_t)*((const u_int8_t *)(p) + 0))) | 147 | (u_int32_t)*((const u_int8_t *)(p) + 0))) |
123 | 148 | ||
124 | #endif // ONETUTILS_H | 149 | #endif // ONETUTILS_H |
125 | 150 | ||
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index ac2857a..2548a04 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp | |||
@@ -31,619 +31,656 @@ | |||
31 | 31 | ||
32 | */ | 32 | */ |
33 | 33 | ||
34 | /* OPIE */ | 34 | /* OPIE */ |
35 | 35 | ||
36 | #include <opie2/onetwork.h> | 36 | #include <opie2/onetwork.h> |
37 | 37 | ||
38 | /* QT */ | 38 | /* QT */ |
39 | 39 | ||
40 | #include <qfile.h> | 40 | #include <qfile.h> |
41 | #include <qtextstream.h> | 41 | #include <qtextstream.h> |
42 | 42 | ||
43 | /* UNIX */ | 43 | /* UNIX */ |
44 | 44 | ||
45 | #include <arpa/inet.h> | 45 | #include <arpa/inet.h> |
46 | #include <cerrno> | 46 | #include <cerrno> |
47 | #include <cstring> | 47 | #include <cstring> |
48 | #include <cstdlib> | 48 | #include <cstdlib> |
49 | #include <math.h> | 49 | #include <math.h> |
50 | #include <sys/ioctl.h> | 50 | #include <sys/ioctl.h> |
51 | #include <sys/socket.h> | 51 | #include <sys/socket.h> |
52 | #include <sys/types.h> | 52 | #include <sys/types.h> |
53 | #include <unistd.h> | 53 | #include <unistd.h> |
54 | #include <linux/sockios.h> | 54 | #include <linux/sockios.h> |
55 | 55 | ||
56 | using namespace std; | 56 | using namespace std; |
57 | 57 | ||
58 | /*====================================================================================== | 58 | /*====================================================================================== |
59 | * ONetwork | 59 | * ONetwork |
60 | *======================================================================================*/ | 60 | *======================================================================================*/ |
61 | 61 | ||
62 | ONetwork* ONetwork::_instance = 0; | 62 | ONetwork* ONetwork::_instance = 0; |
63 | 63 | ||
64 | ONetwork::ONetwork() | 64 | ONetwork::ONetwork() |
65 | { | 65 | { |
66 | qDebug( "ONetwork::ONetwork()" ); | 66 | qDebug( "ONetwork::ONetwork()" ); |
67 | synchronize(); | 67 | synchronize(); |
68 | } | 68 | } |
69 | 69 | ||
70 | void ONetwork::synchronize() | 70 | void ONetwork::synchronize() |
71 | { | 71 | { |
72 | // gather available interfaces by inspecting /proc/net/dev | 72 | // gather available interfaces by inspecting /proc/net/dev |
73 | // we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices | 73 | // we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices |
74 | 74 | ||
75 | _interfaces.clear(); | 75 | _interfaces.clear(); |
76 | QString str; | 76 | QString str; |
77 | QFile f( "/proc/net/dev" ); | 77 | QFile f( "/proc/net/dev" ); |
78 | bool hasFile = f.open( IO_ReadOnly ); | 78 | bool hasFile = f.open( IO_ReadOnly ); |
79 | if ( !hasFile ) | 79 | if ( !hasFile ) |
80 | { | 80 | { |
81 | qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); | 81 | qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); |
82 | return; | 82 | return; |
83 | } | 83 | } |
84 | QTextStream s( &f ); | 84 | QTextStream s( &f ); |
85 | s.readLine(); | 85 | s.readLine(); |
86 | s.readLine(); | 86 | s.readLine(); |
87 | while ( !s.atEnd() ) | 87 | while ( !s.atEnd() ) |
88 | { | 88 | { |
89 | s >> str; | 89 | s >> str; |
90 | str.truncate( str.find( ':' ) ); | 90 | str.truncate( str.find( ':' ) ); |
91 | qDebug( "ONetwork: found interface '%s'", (const char*) str ); | 91 | qDebug( "ONetwork: found interface '%s'", (const char*) str ); |
92 | ONetworkInterface* iface; | 92 | ONetworkInterface* iface; |
93 | if ( isWirelessInterface( str ) ) | 93 | if ( isWirelessInterface( str ) ) |
94 | { | 94 | { |
95 | iface = new OWirelessNetworkInterface( str ); | 95 | iface = new OWirelessNetworkInterface( this, str ); |
96 | qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); | 96 | qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); |
97 | } | 97 | } |
98 | else | 98 | else |
99 | { | 99 | { |
100 | iface = new ONetworkInterface( str ); | 100 | iface = new ONetworkInterface( this, str ); |
101 | } | 101 | } |
102 | _interfaces.insert( str, iface ); | 102 | _interfaces.insert( str, iface ); |
103 | s.readLine(); | 103 | s.readLine(); |
104 | } | 104 | } |
105 | } | 105 | } |
106 | 106 | ||
107 | 107 | ||
108 | ONetworkInterface* ONetwork::interface( QString iface ) const | 108 | ONetworkInterface* ONetwork::interface( QString iface ) const |
109 | { | 109 | { |
110 | return _interfaces[iface]; | 110 | return _interfaces[iface]; |
111 | } | 111 | } |
112 | 112 | ||
113 | 113 | ||
114 | ONetwork* ONetwork::instance() | 114 | ONetwork* ONetwork::instance() |
115 | { | 115 | { |
116 | if ( !_instance ) _instance = new ONetwork(); | 116 | if ( !_instance ) _instance = new ONetwork(); |
117 | return _instance; | 117 | return _instance; |
118 | } | 118 | } |
119 | 119 | ||
120 | 120 | ||
121 | ONetwork::InterfaceIterator ONetwork::iterator() const | 121 | ONetwork::InterfaceIterator ONetwork::iterator() const |
122 | { | 122 | { |
123 | return ONetwork::InterfaceIterator( _interfaces ); | 123 | return ONetwork::InterfaceIterator( _interfaces ); |
124 | } | 124 | } |
125 | 125 | ||
126 | 126 | ||
127 | bool ONetwork::isWirelessInterface( const char* name ) const | 127 | bool ONetwork::isWirelessInterface( const char* name ) const |
128 | { | 128 | { |
129 | int sfd = socket( AF_INET, SOCK_DGRAM, 0 ); | 129 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); |
130 | iwreqstruct iwr; | 130 | iwreqstruct iwr; |
131 | memset( &iwr, 0, sizeof( iwreqstruct ) ); | 131 | memset( &iwr, 0, sizeof( iwreqstruct ) ); |
132 | strcpy( (char*) &iwr.ifr_name, name ); | 132 | strcpy( (char*) &iwr.ifr_name, name ); |
133 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); | 133 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); |
134 | if ( result == -1 ) | 134 | if ( result == -1 ) |
135 | qDebug( "ONetwork::ioctl(): SIOCGIWNAME failed: %d (%s)", result, strerror( errno ) ); | 135 | qDebug( "ONetwork::ioctl(): SIOCGIWNAME failed: %d (%s)", result, strerror( errno ) ); |
136 | else | 136 | else |
137 | qDebug( "ONetwork::ioctl(): SIOCGIWNAME ok." ); | 137 | qDebug( "ONetwork::ioctl(): SIOCGIWNAME ok." ); |
138 | return ( result != -1 ); | 138 | return ( result != -1 ); |
139 | } | 139 | } |
140 | 140 | ||
141 | /*====================================================================================== | 141 | /*====================================================================================== |
142 | * ONetworkInterface | 142 | * ONetworkInterface |
143 | *======================================================================================*/ | 143 | *======================================================================================*/ |
144 | 144 | ||
145 | ONetworkInterface::ONetworkInterface( const QString& name ) | 145 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) |
146 | :_name( name ), _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) | 146 | :QObject( parent, name ), |
147 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) | ||
147 | { | 148 | { |
148 | qDebug( "ONetworkInterface::ONetworkInterface()" ); | 149 | qDebug( "ONetworkInterface::ONetworkInterface()" ); |
149 | init(); | 150 | init(); |
150 | } | 151 | } |
151 | 152 | ||
152 | 153 | ||
153 | ifreqstruct& ONetworkInterface::ifr() const | 154 | ifreqstruct& ONetworkInterface::ifr() const |
154 | { | 155 | { |
155 | return _ifr; | 156 | return _ifr; |
156 | } | 157 | } |
157 | 158 | ||
158 | 159 | ||
159 | void ONetworkInterface::init() | 160 | void ONetworkInterface::init() |
160 | { | 161 | { |
161 | qDebug( "ONetworkInterface::init()" ); | 162 | qDebug( "ONetworkInterface::init()" ); |
162 | 163 | ||
163 | memset( &_ifr, 0, sizeof( struct ifreq ) ); | 164 | memset( &_ifr, 0, sizeof( struct ifreq ) ); |
164 | 165 | ||
165 | if ( _sfd == -1 ) | 166 | if ( _sfd == -1 ) |
166 | { | 167 | { |
167 | qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", (const char*) _name ); | 168 | qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); |
168 | return; | 169 | return; |
169 | } | 170 | } |
170 | } | 171 | } |
171 | 172 | ||
172 | 173 | ||
173 | bool ONetworkInterface::ioctl( int call, ifreqstruct& ifreq ) const | 174 | bool ONetworkInterface::ioctl( int call, ifreqstruct& ifreq ) const |
174 | { | 175 | { |
175 | int result = ::ioctl( _sfd, call, &ifreq ); | 176 | int result = ::ioctl( _sfd, call, &ifreq ); |
176 | if ( result == -1 ) | 177 | if ( result == -1 ) |
177 | qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); | 178 | qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); |
178 | else | 179 | else |
179 | qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Ok.", call ); | 180 | qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Ok.", call ); |
180 | return ( result != -1 ); | 181 | return ( result != -1 ); |
181 | } | 182 | } |
182 | 183 | ||
183 | 184 | ||
184 | bool ONetworkInterface::ioctl( int call ) const | 185 | bool ONetworkInterface::ioctl( int call ) const |
185 | { | 186 | { |
186 | strcpy( _ifr.ifr_name, (const char*) _name ); | 187 | strcpy( _ifr.ifr_name, name() ); |
187 | return ioctl( call, _ifr ); | 188 | return ioctl( call, _ifr ); |
188 | } | 189 | } |
189 | 190 | ||
190 | 191 | ||
191 | bool ONetworkInterface::isLoopback() const | 192 | bool ONetworkInterface::isLoopback() const |
192 | { | 193 | { |
193 | ioctl( SIOCGIFFLAGS ); | 194 | ioctl( SIOCGIFFLAGS ); |
194 | return _ifr.ifr_flags & IFF_LOOPBACK; | 195 | return _ifr.ifr_flags & IFF_LOOPBACK; |
195 | } | 196 | } |
196 | 197 | ||
197 | 198 | ||
198 | bool ONetworkInterface::setUp( bool b ) | 199 | bool ONetworkInterface::setUp( bool b ) |
199 | { | 200 | { |
200 | ioctl( SIOCGIFFLAGS ); | 201 | ioctl( SIOCGIFFLAGS ); |
201 | if ( b ) _ifr.ifr_flags |= IFF_UP; | 202 | if ( b ) _ifr.ifr_flags |= IFF_UP; |
202 | else _ifr.ifr_flags &= (~IFF_UP); | 203 | else _ifr.ifr_flags &= (~IFF_UP); |
203 | return ioctl( SIOCSIFFLAGS ); | 204 | return ioctl( SIOCSIFFLAGS ); |
204 | } | 205 | } |
205 | 206 | ||
206 | 207 | ||
207 | bool ONetworkInterface::isUp() const | 208 | bool ONetworkInterface::isUp() const |
208 | { | 209 | { |
209 | ioctl( SIOCGIFFLAGS ); | 210 | ioctl( SIOCGIFFLAGS ); |
210 | return _ifr.ifr_flags & IFF_UP; | 211 | return _ifr.ifr_flags & IFF_UP; |
211 | } | 212 | } |
212 | 213 | ||
213 | 214 | ||
214 | QString ONetworkInterface::ipV4Address() const | 215 | QString ONetworkInterface::ipV4Address() const |
215 | { | 216 | { |
216 | if ( ioctl( SIOCGIFADDR ) ) | 217 | if ( ioctl( SIOCGIFADDR ) ) |
217 | { | 218 | { |
218 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 219 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
219 | //FIXME: Use QHostAddress here | 220 | //FIXME: Use QHostAddress here |
220 | return QString( inet_ntoa( sa->sin_addr ) ); | 221 | return QString( inet_ntoa( sa->sin_addr ) ); |
221 | } | 222 | } |
222 | else | 223 | else |
223 | return "<unknown>"; | 224 | return "<unknown>"; |
224 | } | 225 | } |
225 | 226 | ||
226 | 227 | ||
227 | OMacAddress ONetworkInterface::macAddress() const | 228 | OMacAddress ONetworkInterface::macAddress() const |
228 | { | 229 | { |
229 | if ( ioctl( SIOCGIFHWADDR ) ) | 230 | if ( ioctl( SIOCGIFHWADDR ) ) |
230 | { | 231 | { |
231 | return OMacAddress( _ifr ); | 232 | return OMacAddress( _ifr ); |
232 | } | 233 | } |
233 | else | 234 | else |
234 | { | 235 | { |
235 | return OMacAddress::unknown; | 236 | return OMacAddress::unknown; |
236 | } | 237 | } |
237 | } | 238 | } |
238 | 239 | ||
239 | 240 | ||
240 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) | 241 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) |
241 | { | 242 | { |
242 | _mon = m; | 243 | _mon = m; |
243 | qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), (const char*) _name ); | 244 | qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() ); |
244 | } | 245 | } |
245 | 246 | ||
246 | 247 | ||
247 | OMonitoringInterface* ONetworkInterface::monitoring() const | 248 | OMonitoringInterface* ONetworkInterface::monitoring() const |
248 | { | 249 | { |
249 | return _mon; | 250 | return _mon; |
250 | } | 251 | } |
251 | 252 | ||
252 | 253 | ||
253 | const QString& ONetworkInterface::name() const | ||
254 | { | ||
255 | return _name; | ||
256 | } | ||
257 | |||
258 | |||
259 | ONetworkInterface::~ONetworkInterface() | 254 | ONetworkInterface::~ONetworkInterface() |
260 | { | 255 | { |
261 | qDebug( "ONetworkInterface::~ONetworkInterface()" ); | 256 | qDebug( "ONetworkInterface::~ONetworkInterface()" ); |
262 | if ( _sfd != -1 ) ::close( _sfd ); | 257 | if ( _sfd != -1 ) ::close( _sfd ); |
263 | } | 258 | } |
264 | 259 | ||
265 | 260 | ||
266 | bool ONetworkInterface::setPromiscuousMode( bool b ) | 261 | bool ONetworkInterface::setPromiscuousMode( bool b ) |
267 | { | 262 | { |
268 | ioctl( SIOCGIFFLAGS ); | 263 | ioctl( SIOCGIFFLAGS ); |
269 | if ( b ) _ifr.ifr_flags |= IFF_PROMISC; | 264 | if ( b ) _ifr.ifr_flags |= IFF_PROMISC; |
270 | else _ifr.ifr_flags &= (~IFF_PROMISC); | 265 | else _ifr.ifr_flags &= (~IFF_PROMISC); |
271 | return ioctl( SIOCSIFFLAGS ); | 266 | return ioctl( SIOCSIFFLAGS ); |
272 | } | 267 | } |
273 | 268 | ||
274 | 269 | ||
275 | bool ONetworkInterface::promiscuousMode() const | 270 | bool ONetworkInterface::promiscuousMode() const |
276 | { | 271 | { |
277 | ioctl( SIOCGIFFLAGS ); | 272 | ioctl( SIOCGIFFLAGS ); |
278 | return _ifr.ifr_flags & IFF_PROMISC; | 273 | return _ifr.ifr_flags & IFF_PROMISC; |
279 | } | 274 | } |
280 | 275 | ||
281 | 276 | ||
282 | bool ONetworkInterface::isWireless() const | 277 | bool ONetworkInterface::isWireless() const |
283 | { | 278 | { |
284 | return ioctl( SIOCGIWNAME ); | 279 | return ioctl( SIOCGIWNAME ); |
285 | } | 280 | } |
286 | 281 | ||
287 | 282 | ||
288 | /*====================================================================================== | 283 | /*====================================================================================== |
289 | * OChannelHopper | 284 | * OChannelHopper |
290 | *======================================================================================*/ | 285 | *======================================================================================*/ |
291 | 286 | ||
292 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) | 287 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) |
293 | :QObject( 0, "Mickey's funky hopper" ), | 288 | :QObject( 0, "Mickey's funky hopper" ), |
294 | _iface( iface ), _interval( 0 ), _tid( 0 ) | 289 | _iface( iface ), _interval( 0 ), _tid( 0 ) |
295 | { | 290 | { |
296 | int _maxChannel = iface->channels()+1; | 291 | int _maxChannel = iface->channels()+1; |
297 | // generate fancy hopping sequence honoring the device capabilities | 292 | // generate fancy hopping sequence honoring the device capabilities |
298 | if ( _maxChannel >= 1 ) _channels.append( 1 ); | 293 | if ( _maxChannel >= 1 ) _channels.append( 1 ); |
299 | if ( _maxChannel >= 7 ) _channels.append( 7 ); | 294 | if ( _maxChannel >= 7 ) _channels.append( 7 ); |
300 | if ( _maxChannel >= 13 ) _channels.append( 13 ); | 295 | if ( _maxChannel >= 13 ) _channels.append( 13 ); |
301 | if ( _maxChannel >= 2 ) _channels.append( 2 ); | 296 | if ( _maxChannel >= 2 ) _channels.append( 2 ); |
302 | if ( _maxChannel >= 8 ) _channels.append( 8 ); | 297 | if ( _maxChannel >= 8 ) _channels.append( 8 ); |
303 | if ( _maxChannel >= 3 ) _channels.append( 3 ); | 298 | if ( _maxChannel >= 3 ) _channels.append( 3 ); |
304 | if ( _maxChannel >= 14 ) _channels.append( 14 ); | 299 | if ( _maxChannel >= 14 ) _channels.append( 14 ); |
305 | if ( _maxChannel >= 9 ) _channels.append( 9 ); | 300 | if ( _maxChannel >= 9 ) _channels.append( 9 ); |
306 | if ( _maxChannel >= 4 ) _channels.append( 4 ); | 301 | if ( _maxChannel >= 4 ) _channels.append( 4 ); |
307 | if ( _maxChannel >= 10 ) _channels.append( 10 ); | 302 | if ( _maxChannel >= 10 ) _channels.append( 10 ); |
308 | if ( _maxChannel >= 5 ) _channels.append( 5 ); | 303 | if ( _maxChannel >= 5 ) _channels.append( 5 ); |
309 | if ( _maxChannel >= 11 ) _channels.append( 11 ); | 304 | if ( _maxChannel >= 11 ) _channels.append( 11 ); |
310 | if ( _maxChannel >= 6 ) _channels.append( 6 ); | 305 | if ( _maxChannel >= 6 ) _channels.append( 6 ); |
311 | if ( _maxChannel >= 12 ) _channels.append( 12 ); | 306 | if ( _maxChannel >= 12 ) _channels.append( 12 ); |
312 | _channel = _channels.begin(); | 307 | _channel = _channels.begin(); |
313 | 308 | ||
314 | } | 309 | } |
315 | 310 | ||
316 | 311 | ||
317 | OChannelHopper::~OChannelHopper() | 312 | OChannelHopper::~OChannelHopper() |
318 | { | 313 | { |
319 | } | 314 | } |
320 | 315 | ||
321 | 316 | ||
322 | bool OChannelHopper::isActive() const | 317 | bool OChannelHopper::isActive() const |
323 | { | 318 | { |
324 | return _tid; | 319 | return _tid; |
325 | } | 320 | } |
326 | 321 | ||
327 | 322 | ||
328 | int OChannelHopper::channel() const | 323 | int OChannelHopper::channel() const |
329 | { | 324 | { |
330 | return *_channel; | 325 | return *_channel; |
331 | } | 326 | } |
332 | 327 | ||
333 | 328 | ||
334 | void OChannelHopper::timerEvent( QTimerEvent* ) | 329 | void OChannelHopper::timerEvent( QTimerEvent* ) |
335 | { | 330 | { |
336 | _iface->setChannel( *_channel ); | 331 | _iface->setChannel( *_channel ); |
337 | qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", | 332 | qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", |
338 | *_channel, (const char*) _iface->name() ); | 333 | *_channel, (const char*) _iface->name() ); |
339 | if ( ++_channel == _channels.end() ) _channel = _channels.begin(); | 334 | if ( ++_channel == _channels.end() ) _channel = _channels.begin(); |
340 | } | 335 | } |
341 | 336 | ||
342 | 337 | ||
343 | void OChannelHopper::setInterval( int interval ) | 338 | void OChannelHopper::setInterval( int interval ) |
344 | { | 339 | { |
345 | if ( interval == _interval ) | 340 | if ( interval == _interval ) |
346 | return; | 341 | return; |
347 | 342 | ||
348 | if ( _interval ) | 343 | if ( _interval ) |
349 | killTimer( _tid ); | 344 | killTimer( _tid ); |
350 | 345 | ||
351 | _tid = 0; | 346 | _tid = 0; |
352 | _interval = interval; | 347 | _interval = interval; |
353 | 348 | ||
354 | if ( _interval ) | 349 | if ( _interval ) |
355 | { | 350 | { |
356 | _tid = startTimer( interval ); | 351 | _tid = startTimer( interval ); |
357 | } | 352 | } |
358 | } | 353 | } |
359 | 354 | ||
360 | 355 | ||
361 | int OChannelHopper::interval() const | 356 | int OChannelHopper::interval() const |
362 | { | 357 | { |
363 | return _interval; | 358 | return _interval; |
364 | } | 359 | } |
365 | 360 | ||
366 | 361 | ||
367 | /*====================================================================================== | 362 | /*====================================================================================== |
368 | * OWirelessNetworkInterface | 363 | * OWirelessNetworkInterface |
369 | *======================================================================================*/ | 364 | *======================================================================================*/ |
370 | 365 | ||
371 | OWirelessNetworkInterface::OWirelessNetworkInterface( const QString& name ) | 366 | OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) |
372 | :ONetworkInterface( name ), _hopper( 0 ) | 367 | :ONetworkInterface( parent, name ), _hopper( 0 ) |
373 | { | 368 | { |
374 | qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); | 369 | qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); |
375 | init(); | 370 | init(); |
376 | } | 371 | } |
377 | 372 | ||
378 | 373 | ||
379 | OWirelessNetworkInterface::~OWirelessNetworkInterface() | 374 | OWirelessNetworkInterface::~OWirelessNetworkInterface() |
380 | { | 375 | { |
381 | } | 376 | } |
382 | 377 | ||
383 | 378 | ||
384 | iwreqstruct& OWirelessNetworkInterface::iwr() const | 379 | iwreqstruct& OWirelessNetworkInterface::iwr() const |
385 | { | 380 | { |
386 | return _iwr; | 381 | return _iwr; |
387 | } | 382 | } |
388 | 383 | ||
389 | 384 | ||
390 | void OWirelessNetworkInterface::init() | 385 | void OWirelessNetworkInterface::init() |
391 | { | 386 | { |
392 | qDebug( "OWirelessNetworkInterface::init()" ); | 387 | qDebug( "OWirelessNetworkInterface::init()" ); |
393 | |||
394 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 388 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
395 | 389 | buildChannelList(); | |
396 | // IEEE802.11(b) radio frequency channels | 390 | buildPrivateList(); |
397 | |||
398 | iwrangestruct range; | ||
399 | //ML: work around an ugly HostAP bug, which needs | ||
400 | //ML: extra space or will complain with "invalid argument length"... :-( | ||
401 | //ML: But don't allocate too much or prism2_usb will segfault *sigh* | ||
402 | char __extraBufferForBuggyDrivers[20]; | ||
403 | |||
404 | qDebug( "sizeof(iwrangestruct)=%d, sizeof range=%d, sizeof range*2=%d", sizeof(iwrangestruct), sizeof range, (sizeof range)*2 ); | ||
405 | |||
406 | _iwr.u.data.pointer = (char*) ⦥ | ||
407 | _iwr.u.data.length = sizeof(iwrangestruct)+20; | ||
408 | _iwr.u.data.flags = 0; | ||
409 | if ( !wioctl( SIOCGIWRANGE ) ) | ||
410 | { | ||
411 | qDebug( "OWirelessNetworkInterface::init(): SIOCGIWRANGE failed (%s)", strerror( errno ) ); | ||
412 | return; | ||
413 | } | ||
414 | |||
415 | qDebug( "OWirelessNetworkInterface::init(): Interface %s reported to have %d channels.", (const char*) _name, range.num_frequency ); | ||
416 | |||
417 | for ( int i = 0; i < range.num_frequency; ++i ) | ||
418 | { | ||
419 | int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); | ||
420 | _channels.insert( freq, i+1 ); | ||
421 | } | ||
422 | } | 391 | } |
423 | 392 | ||
424 | 393 | ||
425 | QString OWirelessNetworkInterface::associatedAP() const | 394 | QString OWirelessNetworkInterface::associatedAP() const |
426 | { | 395 | { |
427 | //FIXME: use OMacAddress | 396 | //FIXME: use OMacAddress |
428 | QString mac; | 397 | QString mac; |
429 | 398 | ||
430 | if ( ioctl( SIOCGIWAP ) ) | 399 | if ( ioctl( SIOCGIWAP ) ) |
431 | { | 400 | { |
432 | mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | 401 | mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", |
433 | _ifr.ifr_hwaddr.sa_data[0]&0xff, | 402 | _ifr.ifr_hwaddr.sa_data[0]&0xff, |
434 | _ifr.ifr_hwaddr.sa_data[1]&0xff, | 403 | _ifr.ifr_hwaddr.sa_data[1]&0xff, |
435 | _ifr.ifr_hwaddr.sa_data[2]&0xff, | 404 | _ifr.ifr_hwaddr.sa_data[2]&0xff, |
436 | _ifr.ifr_hwaddr.sa_data[3]&0xff, | 405 | _ifr.ifr_hwaddr.sa_data[3]&0xff, |
437 | _ifr.ifr_hwaddr.sa_data[4]&0xff, | 406 | _ifr.ifr_hwaddr.sa_data[4]&0xff, |
438 | _ifr.ifr_hwaddr.sa_data[5]&0xff ); | 407 | _ifr.ifr_hwaddr.sa_data[5]&0xff ); |
439 | } | 408 | } |
440 | else | 409 | else |
441 | { | 410 | { |
442 | mac = "<Unknown>"; | 411 | mac = "<Unknown>"; |
443 | } | 412 | } |
444 | return mac; | 413 | return mac; |
445 | } | 414 | } |
446 | 415 | ||
447 | 416 | ||
417 | void OWirelessNetworkInterface::buildChannelList() | ||
418 | { | ||
419 | // IEEE802.11(b) radio frequency channels | ||
420 | struct iw_range range; | ||
421 | |||
422 | //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck | ||
423 | //ML: The HostAP drivers need more than sizeof struct_iw range to complete | ||
424 | //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". | ||
425 | //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate | ||
426 | //ML: _too much_ space. This is damn shitty crap *sigh* | ||
427 | |||
428 | _iwr.u.data.pointer = (char*) ⦥ | ||
429 | _iwr.u.data.length = IW_MAX_FREQUENCIES; //sizeof range; | ||
430 | _iwr.u.data.flags = 0; | ||
431 | |||
432 | if ( !wioctl( SIOCGIWRANGE ) ) | ||
433 | { | ||
434 | qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) ); | ||
435 | _channels.insert( 2412, 1 ); // 2.412 GHz | ||
436 | _channels.insert( 2417, 2 ); // 2.417 GHz | ||
437 | _channels.insert( 2422, 3 ); // 2.422 GHz | ||
438 | _channels.insert( 2427, 4 ); // 2.427 GHz | ||
439 | _channels.insert( 2432, 5 ); // 2.432 GHz | ||
440 | _channels.insert( 2437, 6 ); // 2.437 GHz | ||
441 | _channels.insert( 2442, 7 ); // 2.442 GHz | ||
442 | _channels.insert( 2447, 8 ); // 2.447 GHz | ||
443 | _channels.insert( 2452, 9 ); // 2.452 GHz | ||
444 | _channels.insert( 2457, 10 ); // 2.457 GHz | ||
445 | _channels.insert( 2462, 11 ); // 2.462 GHz | ||
446 | } | ||
447 | else | ||
448 | { | ||
449 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency ); | ||
450 | for ( int i = 0; i < range.num_frequency; ++i ) | ||
451 | { | ||
452 | int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); | ||
453 | _channels.insert( freq, i+1 ); | ||
454 | } | ||
455 | } | ||
456 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." ); | ||
457 | } | ||
458 | |||
459 | |||
460 | void OWirelessNetworkInterface::buildPrivateList() | ||
461 | { | ||
462 | qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); | ||
463 | |||
464 | struct iw_priv_args priv[IW_MAX_PRIV_DEF]; | ||
465 | |||
466 | _iwr.u.data.pointer = (char*) &priv; | ||
467 | _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself | ||
468 | _iwr.u.data.flags = 0; | ||
469 | |||
470 | if ( !wioctl( SIOCGIWPRIV ) ) | ||
471 | { | ||
472 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) ); | ||
473 | return; | ||
474 | } | ||
475 | |||
476 | for ( int i = 0; i < _iwr.u.data.length; ++i ) | ||
477 | { | ||
478 | new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); | ||
479 | } | ||
480 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); | ||
481 | } | ||
482 | |||
483 | |||
448 | int OWirelessNetworkInterface::channel() const | 484 | int OWirelessNetworkInterface::channel() const |
449 | { | 485 | { |
450 | //FIXME: When monitoring enabled, then use it | 486 | //FIXME: When monitoring enabled, then use it |
451 | //FIXME: to gather the current RF channel | 487 | //FIXME: to gather the current RF channel |
452 | //FIXME: Until then, get active channel from hopper. | 488 | //FIXME: Until then, get active channel from hopper. |
453 | if ( _hopper && _hopper->isActive() ) | 489 | if ( _hopper && _hopper->isActive() ) |
454 | return _hopper->channel(); | 490 | return _hopper->channel(); |
455 | 491 | ||
456 | if ( !wioctl( SIOCGIWFREQ ) ) | 492 | if ( !wioctl( SIOCGIWFREQ ) ) |
457 | { | 493 | { |
458 | return -1; | 494 | return -1; |
459 | } | 495 | } |
460 | else | 496 | else |
461 | { | 497 | { |
462 | return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; | 498 | return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; |
463 | } | 499 | } |
464 | } | 500 | } |
465 | 501 | ||
466 | 502 | ||
467 | void OWirelessNetworkInterface::setChannel( int c ) const | 503 | void OWirelessNetworkInterface::setChannel( int c ) const |
468 | { | 504 | { |
469 | if ( !_mon ) | 505 | if ( !_mon ) |
470 | { | 506 | { |
471 | memset( &_iwr, 0, sizeof( iwreqstruct ) ); | 507 | memset( &_iwr, 0, sizeof( iwreqstruct ) ); |
472 | _iwr.u.freq.m = c; | 508 | _iwr.u.freq.m = c; |
473 | _iwr.u.freq.e = 0; | 509 | _iwr.u.freq.e = 0; |
474 | wioctl( SIOCSIWFREQ ); | 510 | wioctl( SIOCSIWFREQ ); |
475 | } | 511 | } |
476 | else | 512 | else |
477 | { | 513 | { |
478 | _mon->setChannel( c ); | 514 | _mon->setChannel( c ); |
479 | } | 515 | } |
480 | } | 516 | } |
481 | 517 | ||
482 | 518 | ||
483 | double OWirelessNetworkInterface::frequency() const | 519 | double OWirelessNetworkInterface::frequency() const |
484 | { | 520 | { |
485 | if ( !wioctl( SIOCGIWFREQ ) ) | 521 | if ( !wioctl( SIOCGIWFREQ ) ) |
486 | { | 522 | { |
487 | return -1.0; | 523 | return -1.0; |
488 | } | 524 | } |
489 | else | 525 | else |
490 | { | 526 | { |
491 | return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; | 527 | return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; |
492 | } | 528 | } |
493 | } | 529 | } |
494 | 530 | ||
495 | 531 | ||
496 | int OWirelessNetworkInterface::channels() const | 532 | int OWirelessNetworkInterface::channels() const |
497 | { | 533 | { |
498 | return _channels.count(); | 534 | return _channels.count(); |
499 | } | 535 | } |
500 | 536 | ||
501 | 537 | ||
502 | void OWirelessNetworkInterface::setChannelHopping( int interval ) | 538 | void OWirelessNetworkInterface::setChannelHopping( int interval ) |
503 | { | 539 | { |
504 | if ( !_hopper ) _hopper = new OChannelHopper( this ); | 540 | if ( !_hopper ) _hopper = new OChannelHopper( this ); |
505 | _hopper->setInterval( interval ); | 541 | _hopper->setInterval( interval ); |
506 | //FIXME: When and by whom will the channel hopper be deleted? | 542 | //FIXME: When and by whom will the channel hopper be deleted? |
543 | //TODO: rely on QObject hierarchy | ||
507 | } | 544 | } |
508 | 545 | ||
509 | 546 | ||
510 | int OWirelessNetworkInterface::channelHopping() const | 547 | int OWirelessNetworkInterface::channelHopping() const |
511 | { | 548 | { |
512 | return _hopper->interval(); | 549 | return _hopper->interval(); |
513 | } | 550 | } |
514 | 551 | ||
515 | 552 | ||
516 | void OWirelessNetworkInterface::setMonitorMode( bool b ) | 553 | void OWirelessNetworkInterface::setMonitorMode( bool b ) |
517 | { | 554 | { |
518 | if ( _mon ) | 555 | if ( _mon ) |
519 | _mon->setEnabled( b ); | 556 | _mon->setEnabled( b ); |
520 | else | 557 | else |
521 | qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); | 558 | qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); |
522 | } | 559 | } |
523 | 560 | ||
524 | 561 | ||
525 | bool OWirelessNetworkInterface::monitorMode() const | 562 | bool OWirelessNetworkInterface::monitorMode() const |
526 | { | 563 | { |
527 | return _mon ? _mon->enabled() : false; | 564 | return _mon ? _mon->enabled() : false; |
528 | } | 565 | } |
529 | 566 | ||
530 | 567 | ||
531 | QString OWirelessNetworkInterface::nickName() const | 568 | QString OWirelessNetworkInterface::nickName() const |
532 | { | 569 | { |
533 | char str[IW_ESSID_MAX_SIZE]; | 570 | char str[IW_ESSID_MAX_SIZE]; |
534 | _iwr.u.data.pointer = &str[0]; | 571 | _iwr.u.data.pointer = &str[0]; |
535 | _iwr.u.data.length = IW_ESSID_MAX_SIZE; | 572 | _iwr.u.data.length = IW_ESSID_MAX_SIZE; |
536 | if ( !wioctl( SIOCGIWNICKN ) ) | 573 | if ( !wioctl( SIOCGIWNICKN ) ) |
537 | { | 574 | { |
538 | return "<unknown>"; | 575 | return "<unknown>"; |
539 | } | 576 | } |
540 | else | 577 | else |
541 | { | 578 | { |
542 | str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string | 579 | str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string |
543 | return str; | 580 | return str; |
544 | } | 581 | } |
545 | } | 582 | } |
546 | 583 | ||
547 | 584 | ||
548 | QString OWirelessNetworkInterface::SSID() const | 585 | QString OWirelessNetworkInterface::SSID() const |
549 | { | 586 | { |
550 | char str[IW_ESSID_MAX_SIZE]; | 587 | char str[IW_ESSID_MAX_SIZE]; |
551 | _iwr.u.essid.pointer = &str[0]; | 588 | _iwr.u.essid.pointer = &str[0]; |
552 | _iwr.u.essid.length = IW_ESSID_MAX_SIZE; | 589 | _iwr.u.essid.length = IW_ESSID_MAX_SIZE; |
553 | if ( !wioctl( SIOCGIWESSID ) ) | 590 | if ( !wioctl( SIOCGIWESSID ) ) |
554 | { | 591 | { |
555 | return "<unknown>"; | 592 | return "<unknown>"; |
556 | } | 593 | } |
557 | else | 594 | else |
558 | { | 595 | { |
559 | return str; | 596 | return str; |
560 | } | 597 | } |
561 | } | 598 | } |
562 | 599 | ||
563 | 600 | ||
564 | void OWirelessNetworkInterface::setSSID( const QString& ssid ) | 601 | void OWirelessNetworkInterface::setSSID( const QString& ssid ) |
565 | { | 602 | { |
566 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); | 603 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); |
567 | _iwr.u.essid.length = ssid.length(); | 604 | _iwr.u.essid.length = ssid.length(); |
568 | wioctl( SIOCSIWESSID ); | 605 | wioctl( SIOCSIWESSID ); |
569 | } | 606 | } |
570 | 607 | ||
571 | 608 | ||
572 | bool OWirelessNetworkInterface::wioctl( int call, iwreqstruct& iwreq ) const | 609 | bool OWirelessNetworkInterface::wioctl( int call, iwreqstruct& iwreq ) const |
573 | { | 610 | { |
574 | int result = ::ioctl( _sfd, call, &iwreq ); | 611 | int result = ::ioctl( _sfd, call, &iwreq ); |
575 | if ( result == -1 ) | 612 | if ( result == -1 ) |
576 | qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); | 613 | qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); |
577 | else | 614 | else |
578 | qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Ok.", call ); | 615 | qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Ok.", call ); |
579 | return ( result != -1 ); | 616 | return ( result != -1 ); |
580 | } | 617 | } |
581 | 618 | ||
582 | 619 | ||
583 | bool OWirelessNetworkInterface::wioctl( int call ) const | 620 | bool OWirelessNetworkInterface::wioctl( int call ) const |
584 | { | 621 | { |
585 | strcpy( _iwr.ifr_name, (const char*) _name ); | 622 | strcpy( _iwr.ifr_name, name() ); |
586 | return wioctl( call, _iwr ); | 623 | return wioctl( call, _iwr ); |
587 | } | 624 | } |
588 | 625 | ||
589 | 626 | ||
590 | /*====================================================================================== | 627 | /*====================================================================================== |
591 | * OMonitoringInterface | 628 | * OMonitoringInterface |
592 | *======================================================================================*/ | 629 | *======================================================================================*/ |
593 | 630 | ||
594 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface ) | 631 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface ) |
595 | :_enabled( false ), _if( static_cast<OWirelessNetworkInterface*>( iface ) ) | 632 | :_enabled( false ), _if( static_cast<OWirelessNetworkInterface*>( iface ) ) |
596 | { | 633 | { |
597 | } | 634 | } |
598 | 635 | ||
599 | 636 | ||
600 | OMonitoringInterface::~OMonitoringInterface() | 637 | OMonitoringInterface::~OMonitoringInterface() |
601 | { | 638 | { |
602 | } | 639 | } |
603 | 640 | ||
604 | 641 | ||
605 | void OMonitoringInterface::setChannel( int c ) | 642 | void OMonitoringInterface::setChannel( int c ) |
606 | { | 643 | { |
607 | // use standard WE channel switching protocol | 644 | // use standard WE channel switching protocol |
608 | memset( &_if->_iwr, 0, sizeof( iwreqstruct ) ); | 645 | memset( &_if->_iwr, 0, sizeof( iwreqstruct ) ); |
609 | _if->_iwr.u.freq.m = c; | 646 | _if->_iwr.u.freq.m = c; |
610 | _if->_iwr.u.freq.e = 0; | 647 | _if->_iwr.u.freq.e = 0; |
611 | _if->wioctl( SIOCSIWFREQ ); | 648 | _if->wioctl( SIOCSIWFREQ ); |
612 | } | 649 | } |
613 | 650 | ||
614 | 651 | ||
615 | bool OMonitoringInterface::enabled() const | 652 | bool OMonitoringInterface::enabled() const |
616 | { | 653 | { |
617 | return _enabled; | 654 | return _enabled; |
618 | } | 655 | } |
619 | 656 | ||
620 | void OMonitoringInterface::setEnabled( bool b ) | 657 | void OMonitoringInterface::setEnabled( bool b ) |
621 | { | 658 | { |
622 | // open a packet capturer here or leave this to | 659 | // open a packet capturer here or leave this to |
623 | // the client code? | 660 | // the client code? |
624 | 661 | ||
625 | /* | 662 | /* |
626 | 663 | ||
627 | if ( b ) | 664 | if ( b ) |
628 | { | 665 | { |
629 | OPacketCapturer* opcap = new OPacketCapturer(); | 666 | OPacketCapturer* opcap = new OPacketCapturer(); |
630 | opcap->open( _if->name() ); | 667 | opcap->open( _if->name() ); |
631 | } | 668 | } |
632 | */ | 669 | */ |
633 | 670 | ||
634 | _enabled = b; | 671 | _enabled = b; |
635 | 672 | ||
636 | } | 673 | } |
637 | 674 | ||
638 | /*====================================================================================== | 675 | /*====================================================================================== |
639 | * OCiscoMonitoringInterface | 676 | * OCiscoMonitoringInterface |
640 | *======================================================================================*/ | 677 | *======================================================================================*/ |
641 | 678 | ||
642 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface ) | 679 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface ) |
643 | :OMonitoringInterface( iface ) | 680 | :OMonitoringInterface( iface ) |
644 | { | 681 | { |
645 | iface->setMonitoring( this ); | 682 | iface->setMonitoring( this ); |
646 | } | 683 | } |
647 | 684 | ||
648 | 685 | ||
649 | OCiscoMonitoringInterface::~OCiscoMonitoringInterface() | 686 | OCiscoMonitoringInterface::~OCiscoMonitoringInterface() |
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h index b57ac3f..acf2f69 100644 --- a/libopie2/opienet/onetwork.h +++ b/libopie2/opienet/onetwork.h | |||
@@ -1,288 +1,291 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003 by the Wellenreiter team: | 3 | Copyright (C) 2003 by the Wellenreiter team: |
4 | Martin J. Muench <mjm@remote-exploit.org> | 4 | Martin J. Muench <mjm@remote-exploit.org> |
5 | Max Moser <mmo@remote-exploit.org | 5 | Max Moser <mmo@remote-exploit.org |
6 | Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 6 | Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
7 | =. | 7 | =. |
8 | .=l. | 8 | .=l. |
9 | .>+-= | 9 | .>+-= |
10 | _;:, .> :=|. This program is free software; you can | 10 | _;:, .> :=|. This program is free software; you can |
11 | .> <`_, > . <= redistribute it and/or modify it under | 11 | .> <`_, > . <= redistribute it and/or modify it under |
12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
13 | .="- .-=="i, .._ License as published by the Free Software | 13 | .="- .-=="i, .._ License as published by the Free Software |
14 | - . .-<_> .<> Foundation; either version 2 of the License, | 14 | - . .-<_> .<> Foundation; either version 2 of the License, |
15 | ._= =} : or (at your option) any later version. | 15 | ._= =} : or (at your option) any later version. |
16 | .%`+i> _;_. | 16 | .%`+i> _;_. |
17 | .i_,=:_. -<s. This program is distributed in the hope that | 17 | .i_,=:_. -<s. This program is distributed in the hope that |
18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
19 | : .. .:, . . . without even the implied warranty of | 19 | : .. .:, . . . without even the implied warranty of |
20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
22 | ..}^=.= = ; Library General Public License for more | 22 | ..}^=.= = ; Library General Public License for more |
23 | ++= -. .` .: details. | 23 | ++= -. .` .: details. |
24 | : = ...= . :.=- | 24 | : = ...= . :.=- |
25 | -. .:....=;==+<; You should have received a copy of the GNU | 25 | -. .:....=;==+<; You should have received a copy of the GNU |
26 | -_. . . )=. = Library General Public License along with | 26 | -_. . . )=. = Library General Public License along with |
27 | -- :-=` this library; see the file COPYING.LIB. | 27 | -- :-=` this library; see the file COPYING.LIB. |
28 | If not, write to the Free Software Foundation, | 28 | If not, write to the Free Software Foundation, |
29 | Inc., 59 Temple Place - Suite 330, | 29 | Inc., 59 Temple Place - Suite 330, |
30 | Boston, MA 02111-1307, USA. | 30 | Boston, MA 02111-1307, USA. |
31 | 31 | ||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #ifndef ONETWORK_H | 34 | #ifndef ONETWORK_H |
35 | #define ONETWORK_H | 35 | #define ONETWORK_H |
36 | 36 | ||
37 | /* QT */ | 37 | /* QT */ |
38 | 38 | ||
39 | #include <qvaluelist.h> | 39 | #include <qvaluelist.h> |
40 | #include <qdict.h> | 40 | #include <qdict.h> |
41 | #include <qmap.h> | 41 | #include <qmap.h> |
42 | #include <qobject.h> | 42 | #include <qobject.h> |
43 | #include <qhostaddress.h> | 43 | #include <qhostaddress.h> |
44 | 44 | ||
45 | /* OPIE */ | 45 | /* OPIE */ |
46 | 46 | ||
47 | #include <opie2/onetutils.h> | 47 | #include <opie2/onetutils.h> |
48 | 48 | ||
49 | #ifndef IFNAMSIZ | 49 | #ifndef IFNAMSIZ |
50 | #define IFNAMSIZ 16 | 50 | #define IFNAMSIZ 16 |
51 | #endif | 51 | #endif |
52 | #ifndef IW_MAX_PRIV_DEF | ||
53 | #define IW_MAX_PRIV_DEF 128 | ||
54 | #endif | ||
52 | 55 | ||
53 | // ML: Yeah, I hate to include kernel headers, but it's necessary here | 56 | // ML: Yeah, I hate to include kernel headers, but it's necessary here |
54 | // ML: Here comes an ugly hack to prevent <linux/wireless.h> including <linux/if.h> | 57 | // ML: Here comes an ugly hack to prevent <linux/wireless.h> including <linux/if.h> |
55 | // ML: which conflicts with the user header <net/if.h> | 58 | // ML: which conflicts with the user header <net/if.h> |
56 | // ML: We really a user header for the Wireless Extensions, something like <net/wireless.h> | 59 | // ML: We really a user header for the Wireless Extensions, something like <net/wireless.h> |
57 | // ML: I will drop Jean an mail on that subject | 60 | // ML: I will drop Jean an mail on that subject |
58 | 61 | ||
59 | #include <net/if.h> | 62 | #include <net/if.h> |
60 | #define _LINUX_IF_H | 63 | #define _LINUX_IF_H |
61 | #include <linux/wireless.h> | 64 | #include <linux/wireless.h> |
62 | 65 | ||
63 | #ifndef SIOCIWFIRSTPRIV | 66 | #ifndef SIOCIWFIRSTPRIV |
64 | #define SIOCIWFIRSTPRIV SIOCDEVPRIVATE | 67 | #define SIOCIWFIRSTPRIV SIOCDEVPRIVATE |
65 | #endif | 68 | #endif |
66 | 69 | ||
67 | class ONetworkInterface; | 70 | class ONetworkInterface; |
68 | class OWirelessNetworkInterface; | 71 | class OWirelessNetworkInterface; |
69 | class OChannelHopper; | 72 | class OChannelHopper; |
70 | class OMonitoringInterface; | 73 | class OMonitoringInterface; |
71 | 74 | ||
72 | typedef struct ifreq ifreqstruct; | 75 | typedef struct ifreq ifreqstruct; |
73 | typedef struct iwreq iwreqstruct; | 76 | typedef struct iwreq iwreqstruct; |
74 | typedef struct iw_event iweventstruct; | 77 | typedef struct iw_event iweventstruct; |
75 | typedef struct iw_freq iwfreqstruct; | 78 | typedef struct iw_freq iwfreqstruct; |
76 | typedef struct iw_priv_args iwprivargsstruct; | 79 | typedef struct iw_priv_args iwprivargsstruct; |
77 | typedef struct iw_range iwrangestruct; | 80 | typedef struct iw_range iwrangestruct; |
78 | 81 | ||
79 | /*====================================================================================== | 82 | /*====================================================================================== |
80 | * ONetwork | 83 | * ONetwork |
81 | *======================================================================================*/ | 84 | *======================================================================================*/ |
82 | 85 | ||
83 | class ONetwork : public QObject | 86 | class ONetwork : public QObject |
84 | { | 87 | { |
85 | Q_OBJECT | 88 | Q_OBJECT |
86 | 89 | ||
87 | public: | 90 | public: |
88 | typedef QDict<ONetworkInterface> InterfaceMap; | 91 | typedef QDict<ONetworkInterface> InterfaceMap; |
89 | typedef QDictIterator<ONetworkInterface> InterfaceIterator; | 92 | typedef QDictIterator<ONetworkInterface> InterfaceIterator; |
90 | 93 | ||
91 | public: | 94 | public: |
92 | static ONetwork* instance(); | 95 | static ONetwork* instance(); |
93 | InterfaceIterator iterator() const; | 96 | InterfaceIterator iterator() const; |
94 | bool isWirelessInterface( const char* ) const; | 97 | bool isWirelessInterface( const char* ) const; |
95 | ONetworkInterface* interface( QString ) const; | 98 | ONetworkInterface* interface( QString ) const; |
96 | 99 | ||
97 | protected: | 100 | protected: |
98 | ONetwork(); | 101 | ONetwork(); |
99 | void synchronize(); | 102 | void synchronize(); |
100 | 103 | ||
101 | private: | 104 | private: |
102 | static ONetwork* _instance; | 105 | static ONetwork* _instance; |
103 | InterfaceMap _interfaces; | 106 | InterfaceMap _interfaces; |
104 | }; | 107 | }; |
105 | 108 | ||
106 | 109 | ||
107 | /*====================================================================================== | 110 | /*====================================================================================== |
108 | * ONetworkInterface | 111 | * ONetworkInterface |
109 | *======================================================================================*/ | 112 | *======================================================================================*/ |
110 | 113 | ||
111 | class ONetworkInterface | 114 | class ONetworkInterface : public QObject |
112 | { | 115 | { |
113 | friend class OMonitoringInterface; | 116 | friend class OMonitoringInterface; |
114 | friend class OCiscoMonitoringInterface; | 117 | friend class OCiscoMonitoringInterface; |
115 | friend class OWlanNGMonitoringInterface; | 118 | friend class OWlanNGMonitoringInterface; |
116 | friend class OHostAPMonitoringInterface; | 119 | friend class OHostAPMonitoringInterface; |
117 | friend class OOrinocoMonitoringInterface; | 120 | friend class OOrinocoMonitoringInterface; |
118 | 121 | ||
119 | public: | 122 | public: |
120 | ONetworkInterface( const QString& name ); | 123 | ONetworkInterface( QObject* parent, const char* name ); |
121 | virtual ~ONetworkInterface(); | 124 | virtual ~ONetworkInterface(); |
122 | 125 | ||
123 | const QString& name() const; | ||
124 | void setMonitoring( OMonitoringInterface* ); | 126 | void setMonitoring( OMonitoringInterface* ); |
125 | OMonitoringInterface* monitoring() const; | 127 | OMonitoringInterface* monitoring() const; |
126 | bool setPromiscuousMode( bool ); | 128 | bool setPromiscuousMode( bool ); |
127 | bool promiscuousMode() const; | 129 | bool promiscuousMode() const; |
128 | bool setUp( bool ); | 130 | bool setUp( bool ); |
129 | bool isUp() const; | 131 | bool isUp() const; |
130 | bool isLoopback() const; | 132 | bool isLoopback() const; |
131 | bool isWireless() const; | 133 | bool isWireless() const; |
132 | QString ipV4Address() const; | 134 | QString ipV4Address() const; |
133 | OMacAddress macAddress() const; | 135 | OMacAddress macAddress() const; |
134 | 136 | ||
135 | protected: | 137 | protected: |
136 | const QString _name; | ||
137 | const int _sfd; | 138 | const int _sfd; |
138 | mutable ifreqstruct _ifr; | 139 | mutable ifreqstruct _ifr; |
139 | OMonitoringInterface* _mon; | 140 | OMonitoringInterface* _mon; |
140 | 141 | ||
141 | protected: | 142 | protected: |
142 | ifreqstruct& ifr() const; | 143 | ifreqstruct& ifr() const; |
143 | virtual void init(); | 144 | virtual void init(); |
144 | bool ioctl( int call ) const; | 145 | bool ioctl( int call ) const; |
145 | bool ioctl( int call, ifreqstruct& ) const; | 146 | bool ioctl( int call, ifreqstruct& ) const; |
146 | }; | 147 | }; |
147 | 148 | ||
148 | /*====================================================================================== | 149 | /*====================================================================================== |
149 | * OChannelHopper | 150 | * OChannelHopper |
150 | *======================================================================================*/ | 151 | *======================================================================================*/ |
151 | 152 | ||
152 | class OChannelHopper : public QObject | 153 | class OChannelHopper : public QObject |
153 | { | 154 | { |
154 | public: | 155 | public: |
155 | OChannelHopper( OWirelessNetworkInterface* ); | 156 | OChannelHopper( OWirelessNetworkInterface* ); |
156 | virtual ~OChannelHopper(); | 157 | virtual ~OChannelHopper(); |
157 | bool isActive() const; | 158 | bool isActive() const; |
158 | int channel() const; | 159 | int channel() const; |
159 | virtual void timerEvent( QTimerEvent* ); | 160 | virtual void timerEvent( QTimerEvent* ); |
160 | void setInterval( int ); | 161 | void setInterval( int ); |
161 | int interval() const; | 162 | int interval() const; |
162 | 163 | ||
163 | private: | 164 | private: |
164 | OWirelessNetworkInterface* _iface; | 165 | OWirelessNetworkInterface* _iface; |
165 | int _interval; | 166 | int _interval; |
166 | int _tid; | 167 | int _tid; |
167 | QValueList<int> _channels; | 168 | QValueList<int> _channels; |
168 | QValueList<int>::Iterator _channel; | 169 | QValueList<int>::Iterator _channel; |
169 | 170 | ||
170 | }; | 171 | }; |
171 | 172 | ||
172 | 173 | ||
173 | /*====================================================================================== | 174 | /*====================================================================================== |
174 | * OWirelessNetworkInterface | 175 | * OWirelessNetworkInterface |
175 | *======================================================================================*/ | 176 | *======================================================================================*/ |
176 | 177 | ||
177 | class OWirelessNetworkInterface : public ONetworkInterface | 178 | class OWirelessNetworkInterface : public ONetworkInterface |
178 | { | 179 | { |
179 | friend class OMonitoringInterface; | 180 | friend class OMonitoringInterface; |
180 | friend class OCiscoMonitoringInterface; | 181 | friend class OCiscoMonitoringInterface; |
181 | friend class OWlanNGMonitoringInterface; | 182 | friend class OWlanNGMonitoringInterface; |
182 | friend class OHostAPMonitoringInterface; | 183 | friend class OHostAPMonitoringInterface; |
183 | friend class OOrinocoMonitoringInterface; | 184 | friend class OOrinocoMonitoringInterface; |
184 | 185 | ||
185 | public: | 186 | public: |
186 | enum Mode { AdHoc, Managed, Monitor }; | 187 | enum Mode { AdHoc, Managed, Monitor }; |
187 | 188 | ||
188 | OWirelessNetworkInterface( const QString& name ); | 189 | OWirelessNetworkInterface( QObject* parent, const char* name ); |
189 | virtual ~OWirelessNetworkInterface(); | 190 | virtual ~OWirelessNetworkInterface(); |
190 | 191 | ||
191 | virtual void setChannel( int ) const; | 192 | virtual void setChannel( int ) const; |
192 | virtual int channel() const; | 193 | virtual int channel() const; |
193 | virtual double frequency() const; | 194 | virtual double frequency() const; |
194 | virtual int channels() const; | 195 | virtual int channels() const; |
195 | //virtual double frequency(int) const; | 196 | //virtual double frequency(int) const; |
196 | 197 | ||
197 | virtual void setMode( Mode ) {}; | 198 | virtual void setMode( Mode ) {}; |
198 | virtual bool mode() const {}; | 199 | virtual bool mode() const {}; |
199 | 200 | ||
200 | virtual void setMonitorMode( bool ); | 201 | virtual void setMonitorMode( bool ); |
201 | virtual bool monitorMode() const; | 202 | virtual bool monitorMode() const; |
202 | 203 | ||
203 | virtual void setChannelHopping( int interval = 0 ); | 204 | virtual void setChannelHopping( int interval = 0 ); |
204 | virtual int channelHopping() const; | 205 | virtual int channelHopping() const; |
205 | 206 | ||
206 | virtual void setNickName( const QString& ) {}; | 207 | virtual void setNickName( const QString& ) {}; |
207 | virtual QString nickName() const; | 208 | virtual QString nickName() const; |
208 | 209 | ||
209 | virtual bool isAssociated() const {}; | 210 | virtual bool isAssociated() const {}; |
210 | virtual QString associatedAP() const; | 211 | virtual QString associatedAP() const; |
211 | 212 | ||
212 | virtual void setSSID( const QString& ); | 213 | virtual void setSSID( const QString& ); |
213 | virtual QString SSID() const; | 214 | virtual QString SSID() const; |
214 | 215 | ||
215 | protected: | 216 | protected: |
216 | mutable iwreqstruct _iwr; | 217 | void buildChannelList(); |
217 | QMap<int,int> _channels; | 218 | void buildPrivateList(); |
218 | |||
219 | protected: | ||
220 | virtual void init(); | 219 | virtual void init(); |
221 | iwreqstruct& iwr() const; | 220 | iwreqstruct& iwr() const; |
222 | bool wioctl( int call ) const; | 221 | bool wioctl( int call ) const; |
223 | bool wioctl( int call, iwreqstruct& ) const; | 222 | bool wioctl( int call, iwreqstruct& ) const; |
224 | 223 | ||
224 | protected: | ||
225 | mutable iwreqstruct _iwr; | ||
226 | QMap<int,int> _channels; | ||
227 | |||
225 | private: | 228 | private: |
226 | OChannelHopper* _hopper; | 229 | OChannelHopper* _hopper; |
227 | }; | 230 | }; |
228 | 231 | ||
229 | 232 | ||
230 | /*====================================================================================== | 233 | /*====================================================================================== |
231 | * OMonitoringInterface | 234 | * OMonitoringInterface |
232 | *======================================================================================*/ | 235 | *======================================================================================*/ |
233 | 236 | ||
234 | 237 | ||
235 | class OMonitoringInterface | 238 | class OMonitoringInterface |
236 | { | 239 | { |
237 | public: | 240 | public: |
238 | OMonitoringInterface(); | 241 | OMonitoringInterface(); |
239 | OMonitoringInterface( ONetworkInterface* ); | 242 | OMonitoringInterface( ONetworkInterface* ); |
240 | virtual ~OMonitoringInterface(); | 243 | virtual ~OMonitoringInterface(); |
241 | 244 | ||
242 | public: | 245 | public: |
243 | virtual void setEnabled( bool ); | 246 | virtual void setEnabled( bool ); |
244 | virtual bool enabled() const; | 247 | virtual bool enabled() const; |
245 | virtual void setChannel( int ); | 248 | virtual void setChannel( int ); |
246 | 249 | ||
247 | virtual QString name() const = 0; | 250 | virtual QString name() const = 0; |
248 | 251 | ||
249 | protected: | 252 | protected: |
250 | bool _enabled; | 253 | bool _enabled; |
251 | const OWirelessNetworkInterface* _if; | 254 | const OWirelessNetworkInterface* _if; |
252 | 255 | ||
253 | }; | 256 | }; |
254 | 257 | ||
255 | 258 | ||
256 | /*====================================================================================== | 259 | /*====================================================================================== |
257 | * OCiscoMonitoring | 260 | * OCiscoMonitoring |
258 | *======================================================================================*/ | 261 | *======================================================================================*/ |
259 | 262 | ||
260 | 263 | ||
261 | class OCiscoMonitoringInterface : public OMonitoringInterface | 264 | class OCiscoMonitoringInterface : public OMonitoringInterface |
262 | { | 265 | { |
263 | public: | 266 | public: |
264 | OCiscoMonitoringInterface( ONetworkInterface* ); | 267 | OCiscoMonitoringInterface( ONetworkInterface* ); |
265 | virtual ~OCiscoMonitoringInterface(); | 268 | virtual ~OCiscoMonitoringInterface(); |
266 | 269 | ||
267 | virtual void setEnabled( bool ); | 270 | virtual void setEnabled( bool ); |
268 | virtual QString name() const; | 271 | virtual QString name() const; |
269 | virtual void setChannel( int ); | 272 | virtual void setChannel( int ); |
270 | 273 | ||
271 | }; | 274 | }; |
272 | 275 | ||
273 | /*====================================================================================== | 276 | /*====================================================================================== |
274 | * OWlanNGMonitoringInterface | 277 | * OWlanNGMonitoringInterface |
275 | *======================================================================================*/ | 278 | *======================================================================================*/ |
276 | 279 | ||
277 | class OWlanNGMonitoringInterface : public OMonitoringInterface | 280 | class OWlanNGMonitoringInterface : public OMonitoringInterface |
278 | { | 281 | { |
279 | public: | 282 | public: |
280 | OWlanNGMonitoringInterface( ONetworkInterface* ); | 283 | OWlanNGMonitoringInterface( ONetworkInterface* ); |
281 | virtual ~OWlanNGMonitoringInterface(); | 284 | virtual ~OWlanNGMonitoringInterface(); |
282 | 285 | ||
283 | public: | 286 | public: |
284 | virtual void setEnabled( bool ); | 287 | virtual void setEnabled( bool ); |
285 | virtual QString name() const; | 288 | virtual QString name() const; |
286 | virtual void setChannel( int ); | 289 | virtual void setChannel( int ); |
287 | 290 | ||
288 | }; | 291 | }; |