Diffstat (limited to 'libopie2/opienet/onetutils.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opienet/onetutils.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/libopie2/opienet/onetutils.cpp b/libopie2/opienet/onetutils.cpp index 48cfa43..7794334 100644 --- a/libopie2/opienet/onetutils.cpp +++ b/libopie2/opienet/onetutils.cpp | |||
@@ -1,87 +1,90 @@ | |||
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@Vanille.de> | 4 | (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> |
5 | =. | 5 | =. |
6 | .=l. | 6 | .=l. |
7 | .>+-= | 7 | .>+-= |
8 | _;:, .> :=|. This program is free software; you can | 8 | _;:, .> :=|. This program is free software; you can |
9 | .> <`_, > . <= redistribute it and/or modify it under | 9 | .> <`_, > . <= redistribute it and/or modify it under |
10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
11 | .="- .-=="i, .._ License as published by the Free Software | 11 | .="- .-=="i, .._ License as published by the Free Software |
12 | - . .-<_> .<> Foundation; either version 2 of the License, | 12 | - . .-<_> .<> Foundation; either version 2 of the License, |
13 | ._= =} : or (at your option) any later version. | 13 | ._= =} : or (at your option) any later version. |
14 | .%`+i> _;_. | 14 | .%`+i> _;_. |
15 | .i_,=:_. -<s. This program is distributed in the hope that | 15 | .i_,=:_. -<s. This program is distributed in the hope that |
16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
17 | : .. .:, . . . without even the implied warranty of | 17 | : .. .:, . . . without even the implied warranty of |
18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
20 | ..}^=.= = ; Library General Public License for more | 20 | ..}^=.= = ; Library General Public License for more |
21 | ++= -. .` .: details. | 21 | ++= -. .` .: details. |
22 | : = ...= . :.=- | 22 | : = ...= . :.=- |
23 | -. .:....=;==+<; You should have received a copy of the GNU | 23 | -. .:....=;==+<; You should have received a copy of the GNU |
24 | -_. . . )=. = Library General Public License along with | 24 | -_. . . )=. = Library General Public License along with |
25 | -- :-=` this library; see the file COPYING.LIB. | 25 | -- :-=` this library; see the file COPYING.LIB. |
26 | If not, write to the Free Software Foundation, | 26 | If not, write to the Free Software Foundation, |
27 | Inc., 59 Temple Place - Suite 330, | 27 | Inc., 59 Temple Place - Suite 330, |
28 | Boston, MA 02111-1307, USA. | 28 | Boston, MA 02111-1307, USA. |
29 | 29 | ||
30 | */ | 30 | */ |
31 | 31 | ||
32 | #include <opie2/onetutils.h> | 32 | #include <opie2/onetutils.h> |
33 | #include <opie2/onetwork.h> | 33 | #include <opie2/onetwork.h> |
34 | #include <opie2/omanufacturerdb.h> | 34 | #include <opie2/omanufacturerdb.h> |
35 | 35 | ||
36 | #include <net/if.h> | 36 | #include <net/if.h> |
37 | #include <assert.h> | 37 | #include <assert.h> |
38 | #include <stdio.h> | 38 | #include <stdio.h> |
39 | 39 | ||
40 | namespace Opie { | ||
41 | namespace Net { | ||
42 | |||
40 | /*====================================================================================== | 43 | /*====================================================================================== |
41 | * OMacAddress | 44 | * OMacAddress |
42 | *======================================================================================*/ | 45 | *======================================================================================*/ |
43 | 46 | ||
44 | // static initializer for broadcast and unknown MAC Adresses | 47 | // static initializer for broadcast and unknown MAC Adresses |
45 | const unsigned char __broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | 48 | const unsigned char __broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
46 | const OMacAddress& OMacAddress::broadcast = OMacAddress( __broadcast ); | 49 | const OMacAddress& OMacAddress::broadcast = OMacAddress( __broadcast ); |
47 | const unsigned char __unknown[6] = { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 }; | 50 | const unsigned char __unknown[6] = { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 }; |
48 | const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown ); | 51 | const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown ); |
49 | 52 | ||
50 | //TODO: Incorporate Ethernet Manufacturer database here! (inline or so) | 53 | //TODO: Incorporate Ethernet Manufacturer database here! (inline or so) |
51 | 54 | ||
52 | OMacAddress::OMacAddress() | 55 | OMacAddress::OMacAddress() |
53 | { | 56 | { |
54 | memcpy( _bytes, __unknown, 6 ); | 57 | memcpy( _bytes, __unknown, 6 ); |
55 | } | 58 | } |
56 | 59 | ||
57 | 60 | ||
58 | OMacAddress::OMacAddress( unsigned char* p ) | 61 | OMacAddress::OMacAddress( unsigned char* p ) |
59 | { | 62 | { |
60 | memcpy( _bytes, p, 6 ); | 63 | memcpy( _bytes, p, 6 ); |
61 | } | 64 | } |
62 | 65 | ||
63 | 66 | ||
64 | OMacAddress::OMacAddress( const unsigned char* p ) | 67 | OMacAddress::OMacAddress( const unsigned char* p ) |
65 | { | 68 | { |
66 | memcpy( _bytes, p, 6 ); | 69 | memcpy( _bytes, p, 6 ); |
67 | } | 70 | } |
68 | 71 | ||
69 | 72 | ||
70 | OMacAddress::OMacAddress( struct ifreq& ifr ) | 73 | OMacAddress::OMacAddress( struct ifreq& ifr ) |
71 | { | 74 | { |
72 | memcpy( _bytes, ifr.ifr_hwaddr.sa_data, 6 ); | 75 | memcpy( _bytes, ifr.ifr_hwaddr.sa_data, 6 ); |
73 | } | 76 | } |
74 | 77 | ||
75 | 78 | ||
76 | OMacAddress::~OMacAddress() | 79 | OMacAddress::~OMacAddress() |
77 | { | 80 | { |
78 | } | 81 | } |
79 | 82 | ||
80 | 83 | ||
81 | //#ifdef QT_NO_DEBUG | 84 | //#ifdef QT_NO_DEBUG |
82 | //inline | 85 | //inline |
83 | //#endif | 86 | //#endif |
84 | const unsigned char* OMacAddress::native() const | 87 | const unsigned char* OMacAddress::native() const |
85 | { | 88 | { |
86 | return (const unsigned char*) &_bytes; | 89 | return (const unsigned char*) &_bytes; |
87 | } | 90 | } |
@@ -140,93 +143,99 @@ bool operator==( const OMacAddress &m1, const OMacAddress &m2 ) | |||
140 | 143 | ||
141 | OPrivateIOCTL::OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs ) | 144 | OPrivateIOCTL::OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs ) |
142 | :QObject( parent, name ), _ioctl( cmd ), _getargs( getargs ), _setargs( setargs ) | 145 | :QObject( parent, name ), _ioctl( cmd ), _getargs( getargs ), _setargs( setargs ) |
143 | { | 146 | { |
144 | } | 147 | } |
145 | 148 | ||
146 | 149 | ||
147 | OPrivateIOCTL::~OPrivateIOCTL() | 150 | OPrivateIOCTL::~OPrivateIOCTL() |
148 | { | 151 | { |
149 | } | 152 | } |
150 | 153 | ||
151 | 154 | ||
152 | int OPrivateIOCTL::numberGetArgs() const | 155 | int OPrivateIOCTL::numberGetArgs() const |
153 | { | 156 | { |
154 | return _getargs & IW_PRIV_SIZE_MASK; | 157 | return _getargs & IW_PRIV_SIZE_MASK; |
155 | } | 158 | } |
156 | 159 | ||
157 | 160 | ||
158 | int OPrivateIOCTL::typeGetArgs() const | 161 | int OPrivateIOCTL::typeGetArgs() const |
159 | { | 162 | { |
160 | return _getargs & IW_PRIV_TYPE_MASK >> 12; | 163 | return _getargs & IW_PRIV_TYPE_MASK >> 12; |
161 | } | 164 | } |
162 | 165 | ||
163 | 166 | ||
164 | int OPrivateIOCTL::numberSetArgs() const | 167 | int OPrivateIOCTL::numberSetArgs() const |
165 | { | 168 | { |
166 | return _setargs & IW_PRIV_SIZE_MASK; | 169 | return _setargs & IW_PRIV_SIZE_MASK; |
167 | } | 170 | } |
168 | 171 | ||
169 | 172 | ||
170 | int OPrivateIOCTL::typeSetArgs() const | 173 | int OPrivateIOCTL::typeSetArgs() const |
171 | { | 174 | { |
172 | return _setargs & IW_PRIV_TYPE_MASK >> 12; | 175 | return _setargs & IW_PRIV_TYPE_MASK >> 12; |
173 | } | 176 | } |
174 | 177 | ||
175 | 178 | ||
176 | void OPrivateIOCTL::invoke() const | 179 | void OPrivateIOCTL::invoke() const |
177 | { | 180 | { |
178 | ( (OWirelessNetworkInterface*) parent() )->wioctl( _ioctl ); | 181 | ( (OWirelessNetworkInterface*) parent() )->wioctl( _ioctl ); |
179 | } | 182 | } |
180 | 183 | ||
181 | 184 | ||
182 | void OPrivateIOCTL::setParameter( int num, u_int32_t value ) | 185 | void OPrivateIOCTL::setParameter( int num, u_int32_t value ) |
183 | { | 186 | { |
184 | u_int32_t* arglist = (u_int32_t*) &( (OWirelessNetworkInterface*) parent() )->_iwr.u.name; | 187 | u_int32_t* arglist = (u_int32_t*) &( (OWirelessNetworkInterface*) parent() )->_iwr.u.name; |
185 | arglist[num] = value; | 188 | arglist[num] = value; |
186 | } | 189 | } |
187 | 190 | ||
191 | |||
192 | |||
193 | namespace Private { | ||
188 | /*====================================================================================== | 194 | /*====================================================================================== |
189 | * assorted functions | 195 | * assorted functions |
190 | *======================================================================================*/ | 196 | *======================================================================================*/ |
191 | 197 | ||
192 | void dumpBytes( const unsigned char* data, int num ) | 198 | void dumpBytes( const unsigned char* data, int num ) |
193 | { | 199 | { |
194 | printf( "Dumping %d bytes @ %0x", num, data ); | 200 | printf( "Dumping %d bytes @ %0x", num, data ); |
195 | printf( "-------------------------------------------\n" ); | 201 | printf( "-------------------------------------------\n" ); |
196 | 202 | ||
197 | for ( int i = 0; i < num; ++i ) | 203 | for ( int i = 0; i < num; ++i ) |
198 | { | 204 | { |
199 | printf( "%02x ", data[i] ); | 205 | printf( "%02x ", data[i] ); |
200 | if ( !((i+1) % 32) ) printf( "\n" ); | 206 | if ( !((i+1) % 32) ) printf( "\n" ); |
201 | } | 207 | } |
202 | printf( "\n\n" ); | 208 | printf( "\n\n" ); |
203 | } | 209 | } |
204 | 210 | ||
205 | 211 | ||
206 | int stringToMode( const QString& mode ) | 212 | int stringToMode( const QString& mode ) |
207 | { | 213 | { |
208 | if ( mode == "auto" ) return IW_MODE_AUTO; | 214 | if ( mode == "auto" ) return IW_MODE_AUTO; |
209 | else if ( mode == "adhoc" ) return IW_MODE_ADHOC; | 215 | else if ( mode == "adhoc" ) return IW_MODE_ADHOC; |
210 | else if ( mode == "managed" ) return IW_MODE_INFRA; | 216 | else if ( mode == "managed" ) return IW_MODE_INFRA; |
211 | else if ( mode == "master" ) return IW_MODE_MASTER; | 217 | else if ( mode == "master" ) return IW_MODE_MASTER; |
212 | else if ( mode == "repeater" ) return IW_MODE_REPEAT; | 218 | else if ( mode == "repeater" ) return IW_MODE_REPEAT; |
213 | else if ( mode == "secondary" ) return IW_MODE_SECOND; | 219 | else if ( mode == "secondary" ) return IW_MODE_SECOND; |
214 | else if ( mode == "monitor" ) return IW_MODE_MONITOR; | 220 | else if ( mode == "monitor" ) return IW_MODE_MONITOR; |
215 | else assert( 0 ); | 221 | else assert( 0 ); |
216 | } | 222 | } |
217 | 223 | ||
218 | 224 | ||
219 | QString modeToString( int mode ) | 225 | QString modeToString( int mode ) |
220 | { | 226 | { |
221 | switch ( mode ) | 227 | switch ( mode ) |
222 | { | 228 | { |
223 | case IW_MODE_AUTO: return "auto"; | 229 | case IW_MODE_AUTO: return "auto"; |
224 | case IW_MODE_ADHOC: return "adhoc"; | 230 | case IW_MODE_ADHOC: return "adhoc"; |
225 | case IW_MODE_INFRA: return "managed"; | 231 | case IW_MODE_INFRA: return "managed"; |
226 | case IW_MODE_MASTER: return "master"; | 232 | case IW_MODE_MASTER: return "master"; |
227 | case IW_MODE_REPEAT: return "repeater"; | 233 | case IW_MODE_REPEAT: return "repeater"; |
228 | case IW_MODE_SECOND: return "second"; | 234 | case IW_MODE_SECOND: return "second"; |
229 | case IW_MODE_MONITOR: return "monitor"; | 235 | case IW_MODE_MONITOR: return "monitor"; |
230 | default: assert( 0 ); | 236 | default: assert( 0 ); |
231 | } | 237 | } |
232 | } | 238 | } |
239 | } | ||
240 | } | ||
241 | } | ||