Diffstat (limited to 'libopie2/opienet/onetutils.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opienet/onetutils.cpp | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/libopie2/opienet/onetutils.cpp b/libopie2/opienet/onetutils.cpp index 3e11b53..fd8f9e9 100644 --- a/libopie2/opienet/onetutils.cpp +++ b/libopie2/opienet/onetutils.cpp | |||
@@ -1,160 +1,185 @@ | |||
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 | 34 | ||
34 | #include <net/if.h> | 35 | #include <net/if.h> |
35 | 36 | ||
36 | #include <cstdio> | 37 | #include <cstdio> |
37 | using namespace std; | 38 | using namespace std; |
38 | 39 | ||
39 | #define IW_PRIV_TYPE_MASK 0x7000 | 40 | #define IW_PRIV_TYPE_MASK 0x7000 |
40 | #define IW_PRIV_TYPE_NONE 0x0000 | 41 | #define IW_PRIV_TYPE_NONE 0x0000 |
41 | #define IW_PRIV_TYPE_BYTE 0x1000 | 42 | #define IW_PRIV_TYPE_BYTE 0x1000 |
42 | #define IW_PRIV_TYPE_CHAR 0x2000 | 43 | #define IW_PRIV_TYPE_CHAR 0x2000 |
43 | #define IW_PRIV_TYPE_INT 0x4000 | 44 | #define IW_PRIV_TYPE_INT 0x4000 |
44 | #define IW_PRIV_TYPE_FLOAT 0x5000 | 45 | #define IW_PRIV_TYPE_FLOAT 0x5000 |
45 | #define IW_PRIV_TYPE_ADDR 0x6000 | 46 | #define IW_PRIV_TYPE_ADDR 0x6000 |
46 | #define IW_PRIV_SIZE_FIXED 0x0800 | 47 | #define IW_PRIV_SIZE_FIXED 0x0800 |
47 | #define IW_PRIV_SIZE_MASK 0x07FF | 48 | #define IW_PRIV_SIZE_MASK 0x07FF |
48 | 49 | ||
49 | /*====================================================================================== | 50 | /*====================================================================================== |
50 | * OMacAddress | 51 | * OMacAddress |
51 | *======================================================================================*/ | 52 | *======================================================================================*/ |
52 | 53 | ||
53 | // static initializer for broadcast and unknown MAC Adresses | 54 | // static initializer for broadcast and unknown MAC Adresses |
54 | const unsigned char __broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | 55 | const unsigned char __broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
55 | const OMacAddress& OMacAddress::broadcast = OMacAddress( __broadcast ); | 56 | const OMacAddress& OMacAddress::broadcast = OMacAddress( __broadcast ); |
56 | const unsigned char __unknown[6] = { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 }; | 57 | const unsigned char __unknown[6] = { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 }; |
57 | const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown ); | 58 | const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown ); |
58 | 59 | ||
59 | 60 | ||
60 | //TODO: Incorporate Ethernet Manufacturer database here! | 61 | //TODO: Incorporate Ethernet Manufacturer database here! |
61 | 62 | ||
62 | OMacAddress::OMacAddress( unsigned char* p ) | 63 | OMacAddress::OMacAddress( unsigned char* p ) |
63 | { | 64 | { |
64 | memcpy( _bytes, p, 6 ); // D'OH! memcpy in my sources... eeek... | 65 | memcpy( _bytes, p, 6 ); // D'OH! memcpy in my sources... eeek... |
65 | } | 66 | } |
66 | 67 | ||
67 | 68 | ||
68 | OMacAddress::OMacAddress( const unsigned char* p ) | 69 | OMacAddress::OMacAddress( const unsigned char* p ) |
69 | { | 70 | { |
70 | memcpy( _bytes, p, 6 ); | 71 | memcpy( _bytes, p, 6 ); |
71 | } | 72 | } |
72 | 73 | ||
73 | 74 | ||
74 | OMacAddress::OMacAddress( struct ifreq& ifr ) | 75 | OMacAddress::OMacAddress( struct ifreq& ifr ) |
75 | { | 76 | { |
76 | memcpy( _bytes, ifr.ifr_hwaddr.sa_data, 6 ); | 77 | memcpy( _bytes, ifr.ifr_hwaddr.sa_data, 6 ); |
77 | } | 78 | } |
78 | 79 | ||
79 | 80 | ||
80 | OMacAddress::~OMacAddress() | 81 | OMacAddress::~OMacAddress() |
81 | { | 82 | { |
82 | } | 83 | } |
83 | 84 | ||
84 | 85 | ||
85 | QString OMacAddress::toString() const | 86 | QString OMacAddress::toString() const |
86 | { | 87 | { |
87 | QString s; | 88 | QString s; |
88 | s.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | 89 | s.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", |
89 | _bytes[0]&0xff, _bytes[1]&0xff, _bytes[2]&0xff, | 90 | _bytes[0]&0xff, _bytes[1]&0xff, _bytes[2]&0xff, |
90 | _bytes[3]&0xff, _bytes[4]&0xff, _bytes[5]&0xff ); | 91 | _bytes[3]&0xff, _bytes[4]&0xff, _bytes[5]&0xff ); |
91 | return s; | 92 | return s; |
92 | } | 93 | } |
93 | 94 | ||
94 | 95 | ||
95 | bool operator==( const OMacAddress &m1, const OMacAddress &m2 ) | 96 | bool operator==( const OMacAddress &m1, const OMacAddress &m2 ) |
96 | { | 97 | { |
97 | return memcmp( &m1._bytes, &m2._bytes, 6 ) == 0; | 98 | return memcmp( &m1._bytes, &m2._bytes, 6 ) == 0; |
98 | } | 99 | } |
99 | 100 | ||
100 | 101 | ||
101 | /*====================================================================================== | 102 | /*====================================================================================== |
102 | * OHostAddress | 103 | * OHostAddress |
103 | *======================================================================================*/ | 104 | *======================================================================================*/ |
104 | 105 | ||
105 | 106 | ||
106 | /*====================================================================================== | 107 | /*====================================================================================== |
107 | * OPrivateIOCTL | 108 | * OPrivateIOCTL |
108 | *======================================================================================*/ | 109 | *======================================================================================*/ |
109 | 110 | ||
110 | OPrivateIOCTL::OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs ) | 111 | OPrivateIOCTL::OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs ) |
111 | :QObject( parent, name ), _ioctl( cmd ), _getargs( getargs ), _setargs( setargs ) | 112 | :QObject( parent, name ), _ioctl( cmd ), _getargs( getargs ), _setargs( setargs ) |
112 | { | 113 | { |
113 | } | 114 | } |
114 | 115 | ||
115 | 116 | ||
116 | OPrivateIOCTL::~OPrivateIOCTL() | 117 | OPrivateIOCTL::~OPrivateIOCTL() |
117 | { | 118 | { |
118 | } | 119 | } |
119 | 120 | ||
120 | 121 | ||
121 | inline int OPrivateIOCTL::numberGetArgs() const | 122 | #ifdef QT_NO_DEBUG |
123 | inline | ||
124 | #endif | ||
125 | int OPrivateIOCTL::numberGetArgs() const | ||
122 | { | 126 | { |
123 | return _getargs & IW_PRIV_SIZE_MASK; | 127 | return _getargs & IW_PRIV_SIZE_MASK; |
124 | } | 128 | } |
125 | 129 | ||
126 | 130 | ||
127 | inline int OPrivateIOCTL::typeGetArgs() const | 131 | #ifdef QT_NO_DEBUG |
132 | inline | ||
133 | #endif | ||
134 | int OPrivateIOCTL::typeGetArgs() const | ||
128 | { | 135 | { |
129 | return _getargs & IW_PRIV_TYPE_MASK >> 12; | 136 | return _getargs & IW_PRIV_TYPE_MASK >> 12; |
130 | } | 137 | } |
131 | 138 | ||
132 | 139 | ||
133 | inline int OPrivateIOCTL::numberSetArgs() const | 140 | #ifdef QT_NO_DEBUG |
141 | inline | ||
142 | #endif | ||
143 | int OPrivateIOCTL::numberSetArgs() const | ||
134 | { | 144 | { |
135 | return _setargs & IW_PRIV_SIZE_MASK; | 145 | return _setargs & IW_PRIV_SIZE_MASK; |
136 | } | 146 | } |
137 | 147 | ||
138 | 148 | ||
139 | inline int OPrivateIOCTL::typeSetArgs() const | 149 | #ifdef QT_NO_DEBUG |
150 | inline | ||
151 | #endif | ||
152 | int OPrivateIOCTL::typeSetArgs() const | ||
140 | { | 153 | { |
141 | return _setargs & IW_PRIV_TYPE_MASK >> 12; | 154 | return _setargs & IW_PRIV_TYPE_MASK >> 12; |
142 | } | 155 | } |
143 | 156 | ||
144 | 157 | ||
158 | void OPrivateIOCTL::invoke() const | ||
159 | { | ||
160 | ( (OWirelessNetworkInterface*) parent() )->wioctl( _ioctl ); | ||
161 | } | ||
162 | |||
163 | |||
164 | void OPrivateIOCTL::setParameter( int num, u_int32_t value ) | ||
165 | { | ||
166 | u_int32_t* arglist = (u_int32_t*) &( (OWirelessNetworkInterface*) parent() )->_iwr.u.name; | ||
167 | arglist[num] = value; | ||
168 | } | ||
169 | |||
145 | /*====================================================================================== | 170 | /*====================================================================================== |
146 | * assorted functions | 171 | * assorted functions |
147 | *======================================================================================*/ | 172 | *======================================================================================*/ |
148 | 173 | ||
149 | void dumpBytes( const unsigned char* data, int num ) | 174 | void dumpBytes( const unsigned char* data, int num ) |
150 | { | 175 | { |
151 | printf( "Dumping %d bytes @ %0x", num, data ); | 176 | printf( "Dumping %d bytes @ %0x", num, data ); |
152 | printf( "-------------------------------------------\n" ); | 177 | printf( "-------------------------------------------\n" ); |
153 | 178 | ||
154 | for ( int i = 0; i < num; ++i ) | 179 | for ( int i = 0; i < num; ++i ) |
155 | { | 180 | { |
156 | printf( "%02x ", data[i] ); | 181 | printf( "%02x ", data[i] ); |
157 | if ( !((i+1) % 32) ) printf( "\n" ); | 182 | if ( !((i+1) % 32) ) printf( "\n" ); |
158 | } | 183 | } |
159 | printf( "\n\n" ); | 184 | printf( "\n\n" ); |
160 | } | 185 | } |