author | mickeyl <mickeyl> | 2005-05-19 11:59:32 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2005-05-19 11:59:32 (UTC) |
commit | ed7ba8b228d3d0ffae9c9b68900b7f723d7ade4a (patch) (unidiff) | |
tree | 83b59755f58747cdb7e543a4c237e9e217b03fbd /libopie2 | |
parent | cb243f00d12c5fc40de02e7f9f20009b52303a66 (diff) | |
download | opie-ed7ba8b228d3d0ffae9c9b68900b7f723d7ade4a.zip opie-ed7ba8b228d3d0ffae9c9b68900b7f723d7ade4a.tar.gz opie-ed7ba8b228d3d0ffae9c9b68900b7f723d7ade4a.tar.bz2 |
- add linux pcmcia subsystem wrapper: OPcmciaSystem and OPcmciaCard
- move linux-only subsystems in subdirectory linux
- minor header cleanups
-rw-r--r-- | libopie2/opiecore/linux/.cvsignore | 6 | ||||
-rw-r--r-- | libopie2/opiecore/linux/linux.pro | 10 | ||||
-rw-r--r-- | libopie2/opiecore/linux/ofilenotify.cpp (renamed from libopie2/opiecore/ofilenotify.cpp) | 0 | ||||
-rw-r--r-- | libopie2/opiecore/linux/ofilenotify.h (renamed from libopie2/opiecore/ofilenotify.h) | 0 | ||||
-rw-r--r-- | libopie2/opiecore/linux/oinputsystem.cpp (renamed from libopie2/opiecore/oinputsystem.cpp) | 4 | ||||
-rw-r--r-- | libopie2/opiecore/linux/oinputsystem.h (renamed from libopie2/opiecore/oinputsystem.h) | 10 | ||||
-rw-r--r-- | libopie2/opiecore/linux/oinputsystemenums.h | 405 | ||||
-rw-r--r-- | libopie2/opiecore/linux/opcmciasystem.cpp | 142 | ||||
-rw-r--r-- | libopie2/opiecore/linux/opcmciasystem.h | 129 | ||||
-rw-r--r-- | libopie2/opiecore/opiecore.pro | 16 | ||||
-rw-r--r-- | libopie2/opiemm/osoundsystem.cpp | 12 | ||||
-rw-r--r-- | libopie2/opiemm/osoundsystem.h | 13 | ||||
-rw-r--r-- | libopie2/opienet/opcap.cpp | 2 | ||||
-rw-r--r-- | libopie2/opienet/opcap.h | 1 |
14 files changed, 718 insertions, 32 deletions
diff --git a/libopie2/opiecore/linux/.cvsignore b/libopie2/opiecore/linux/.cvsignore new file mode 100644 index 0000000..972e959 --- a/dev/null +++ b/libopie2/opiecore/linux/.cvsignore | |||
@@ -0,0 +1,6 @@ | |||
1 | Makefile* | ||
2 | moc* | ||
3 | *moc | ||
4 | *.o | ||
5 | ~* | ||
6 | obj | ||
diff --git a/libopie2/opiecore/linux/linux.pro b/libopie2/opiecore/linux/linux.pro new file mode 100644 index 0000000..c396e59 --- a/dev/null +++ b/libopie2/opiecore/linux/linux.pro | |||
@@ -0,0 +1,10 @@ | |||
1 | HEADERS += \ | ||
2 | linux/ofilenotify.h \ | ||
3 | linux/oinputsystem.h \ | ||
4 | linux/opcmciasystem.h | ||
5 | |||
6 | SOURCES += \ | ||
7 | linux/ofilenotify.cpp \ | ||
8 | linux/oinputsystem.cpp \ | ||
9 | linux/opcmciasystem.cpp | ||
10 | |||
diff --git a/libopie2/opiecore/ofilenotify.cpp b/libopie2/opiecore/linux/ofilenotify.cpp index 36ec6bf..36ec6bf 100644 --- a/libopie2/opiecore/ofilenotify.cpp +++ b/libopie2/opiecore/linux/ofilenotify.cpp | |||
diff --git a/libopie2/opiecore/ofilenotify.h b/libopie2/opiecore/linux/ofilenotify.h index 05343b9..05343b9 100644 --- a/libopie2/opiecore/ofilenotify.h +++ b/libopie2/opiecore/linux/ofilenotify.h | |||
diff --git a/libopie2/opiecore/oinputsystem.cpp b/libopie2/opiecore/linux/oinputsystem.cpp index 7397814..bad27ed 100644 --- a/libopie2/opiecore/oinputsystem.cpp +++ b/libopie2/opiecore/linux/oinputsystem.cpp | |||
@@ -1,222 +1,222 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | .=l. | 4 | .=l. |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This program is free software; you can | 6 | _;:, .> :=|. This program is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; version 2 of the License. |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This program is distributed in the hope that | 13 | .i_,=:_. -<s. This program is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
18 | ..}^=.= = ; Library General Public License for more | 18 | ..}^=.= = ; Library General Public License for more |
19 | ++= -. .` .: details. | 19 | ++= -. .` .: details. |
20 | : = ...= . :.=- | 20 | : = ...= . :.=- |
21 | -. .:....=;==+<; You should have received a copy of the GNU | 21 | -. .:....=;==+<; You should have received a copy of the GNU |
22 | -_. . . )=. = Library General Public License along with | 22 | -_. . . )=. = Library General Public License along with |
23 | -- :-=` this library; see the file COPYING.LIB. | 23 | -- :-=` this library; see the file COPYING.LIB. |
24 | If not, write to the Free Software Foundation, | 24 | If not, write to the Free Software Foundation, |
25 | Inc., 59 Temple Place - Suite 330, | 25 | Inc., 59 Temple Place - Suite 330, |
26 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include "oinputsystem.h" | 29 | #include "oinputsystem.h" |
30 | using namespace Opie::Core; | 30 | using namespace Opie::Core; |
31 | 31 | ||
32 | /* QT */ | 32 | /* QT */ |
33 | #include <qdir.h> | 33 | #include <qdir.h> |
34 | #include <qfile.h> | 34 | #include <qfile.h> |
35 | 35 | ||
36 | /* STD */ | 36 | /* STD */ |
37 | #include <errno.h> | 37 | #include <errno.h> |
38 | #include <string.h> | 38 | #include <string.h> |
39 | #include <sys/fcntl.h> | 39 | #include <sys/fcntl.h> |
40 | #include <sys/ioctl.h> | 40 | #include <sys/ioctl.h> |
41 | #include <unistd.h> | 41 | #include <unistd.h> |
42 | 42 | ||
43 | #define BUFSIZE 256 | 43 | #define BUFSIZE 256 |
44 | #define BIT_MASK( name, numbits ) \ | 44 | #define BIT_MASK( name, numbits ) \ |
45 | unsigned short name[ ((numbits) - 1) / (sizeof( short ) * 8) + 1 ]; \ | 45 | unsigned short name[ ((numbits) - 1) / (sizeof( short ) * 8) + 1 ]; \ |
46 | memset( name, 0, sizeof( name ) ) | 46 | memset( name, 0, sizeof( name ) ) |
47 | #define BIT_TEST( bitmask, bit ) \ | 47 | #define BIT_TEST( bitmask, bit ) \ |
48 | ( bitmask[ (bit) / sizeof(short) / 8 ] & (1u << ( (bit) % (sizeof(short) * 8))) ) | 48 | ( bitmask[ (bit) / sizeof(short) / 8 ] & (1u << ( (bit) % (sizeof(short) * 8))) ) |
49 | 49 | ||
50 | /*====================================================================================== | 50 | /*====================================================================================== |
51 | * OInputSystem | 51 | * OInputSystem |
52 | *======================================================================================*/ | 52 | *======================================================================================*/ |
53 | 53 | ||
54 | OInputSystem* OInputSystem::_instance = 0; | 54 | OInputSystem* OInputSystem::_instance = 0; |
55 | 55 | ||
56 | OInputSystem::OInputSystem() : QObject() | 56 | OInputSystem::OInputSystem() : QObject() |
57 | { | 57 | { |
58 | qDebug( "OInputSystem::OInputSystem()" ); | 58 | qDebug( "OInputSystem::OInputSystem()" ); |
59 | synchronize(); | 59 | synchronize(); |
60 | } | 60 | } |
61 | 61 | ||
62 | 62 | ||
63 | void OInputSystem::synchronize() | 63 | void OInputSystem::synchronize() |
64 | { | 64 | { |
65 | qDebug( "OInputSystem::synchronize()" ); | 65 | qDebug( "OInputSystem::synchronize()" ); |
66 | QDir devInput( "/dev/input/" ); | 66 | QDir devInput( "/dev/input/" ); |
67 | if ( devInput.exists() ) | 67 | if ( devInput.exists() ) |
68 | { | 68 | { |
69 | QStringList devInputFiles = devInput.entryList( QDir::System, QDir::Name ); | 69 | QStringList devInputFiles = devInput.entryList( QDir::System, QDir::Name ); |
70 | for ( QStringList::Iterator it = devInputFiles.begin(); it != devInputFiles.end(); ++it ) | 70 | for ( QStringList::Iterator it = devInputFiles.begin(); it != devInputFiles.end(); ++it ) |
71 | { | 71 | { |
72 | QString absPath = devInput.absFilePath( *it ); | 72 | QString absPath = devInput.absFilePath( *it ); |
73 | bool isValid = OInputDevice::isValid( absPath ); | 73 | bool isValid = OInputDevice::isValid( absPath ); |
74 | qDebug( "OInputSystem::synchronize() - checking if '%s' is a valid input system node... '%s' [%s]", | 74 | qDebug( "OInputSystem::synchronize() - checking if '%s' is a valid input system node... '%s' [%s]", |
75 | (const char*) absPath, isValid ? "yes" : "no", isValid ? "(ok)" : strerror( errno ) ); | 75 | (const char*) absPath, isValid ? "yes" : "no", isValid ? "(ok)" : strerror( errno ) ); |
76 | if ( isValid ) _devices.insert( *it, new OInputDevice( this, absPath ) ); | 76 | if ( isValid ) _devices.insert( *it, new OInputDevice( this, absPath ) ); |
77 | } | 77 | } |
78 | } | 78 | } |
79 | qDebug( "OInputSystem::synchronize() done" ); | 79 | qDebug( "OInputSystem::synchronize() done" ); |
80 | if ( !_devices.count() ) | 80 | if ( !_devices.count() ) |
81 | qWarning( "OInputSystem::no devices found" ); | 81 | qWarning( "OInputSystem::no devices found" ); |
82 | } | 82 | } |
83 | 83 | ||
84 | 84 | ||
85 | OInputSystem::~OInputSystem() | 85 | OInputSystem::~OInputSystem() |
86 | { | 86 | { |
87 | qDebug( "OInputSystem::~OInputSystem()" ); | 87 | qDebug( "OInputSystem::~OInputSystem()" ); |
88 | } | 88 | } |
89 | 89 | ||
90 | 90 | ||
91 | int OInputSystem::count() const | 91 | int OInputSystem::count() const |
92 | { | 92 | { |
93 | return _devices.count(); | 93 | return _devices.count(); |
94 | } | 94 | } |
95 | 95 | ||
96 | 96 | ||
97 | OInputDevice* OInputSystem::device( const QString& device ) const | 97 | OInputDevice* OInputSystem::device( const QString& device ) const |
98 | { | 98 | { |
99 | return _devices[device]; | 99 | return _devices[device]; |
100 | } | 100 | } |
101 | 101 | ||
102 | 102 | ||
103 | OInputSystem* OInputSystem::instance() | 103 | OInputSystem* OInputSystem::instance() |
104 | { | 104 | { |
105 | if ( !_instance ) _instance = new OInputSystem(); | 105 | if ( !_instance ) _instance = new OInputSystem(); |
106 | return _instance; | 106 | return _instance; |
107 | } | 107 | } |
108 | 108 | ||
109 | 109 | ||
110 | OInputSystem::DeviceIterator OInputSystem::iterator() const | 110 | OInputSystem::DeviceIterator OInputSystem::iterator() const |
111 | { | 111 | { |
112 | return OInputSystem::DeviceIterator( _devices ); | 112 | return OInputSystem::DeviceIterator( _devices ); |
113 | } | 113 | } |
114 | 114 | ||
115 | /*====================================================================================== | 115 | /*====================================================================================== |
116 | * OInputDevice | 116 | * OInputDevice |
117 | *======================================================================================*/ | 117 | *======================================================================================*/ |
118 | 118 | ||
119 | OInputDevice::OInputDevice( QObject* parent, const char* name ) : QObject( parent, name ) | 119 | OInputDevice::OInputDevice( QObject* parent, const char* name ) : QObject( parent, name ) |
120 | { | 120 | { |
121 | qDebug( "OInputDevice::OInputDevice( '%s' )", name ); | 121 | qDebug( "OInputDevice::OInputDevice( '%s' )", name ); |
122 | 122 | ||
123 | _fd = ::open( name, O_RDONLY ); | 123 | _fd = ::open( name, O_RDONLY ); |
124 | if ( _fd == -1 ) | 124 | if ( _fd == -1 ) |
125 | { | 125 | { |
126 | qDebug( "OInputDevice::OInputDevice() - Warning: couldn't open %s (%s)", name, strerror( errno ) ); | 126 | qDebug( "OInputDevice::OInputDevice() - Warning: couldn't open %s (%s)", name, strerror( errno ) ); |
127 | } | 127 | } |
128 | } | 128 | } |
129 | 129 | ||
130 | 130 | ||
131 | OInputDevice::~OInputDevice() | 131 | OInputDevice::~OInputDevice() |
132 | { | 132 | { |
133 | qDebug( "OInputDevice::~OInputDevice()" ); | 133 | qDebug( "OInputDevice::~OInputDevice()" ); |
134 | } | 134 | } |
135 | 135 | ||
136 | 136 | ||
137 | QString OInputDevice::identity() const | 137 | QString OInputDevice::identity() const |
138 | { | 138 | { |
139 | char buf[BUFSIZE] = "<unknown>"; | 139 | char buf[BUFSIZE] = "<unknown>"; |
140 | ::ioctl( _fd, EVIOCGNAME(sizeof buf), buf ); | 140 | ::ioctl( _fd, EVIOCGNAME(sizeof buf), buf ); |
141 | return buf; | 141 | return buf; |
142 | } | 142 | } |
143 | 143 | ||
144 | 144 | ||
145 | QString OInputDevice::path() const | 145 | QString OInputDevice::path() const |
146 | { | 146 | { |
147 | char buf[BUFSIZE] = "<unknown>"; | 147 | char buf[BUFSIZE] = "<unknown>"; |
148 | ::ioctl( _fd, EVIOCGPHYS(sizeof buf), buf ); | 148 | ::ioctl( _fd, EVIOCGPHYS(sizeof buf), buf ); |
149 | return buf; | 149 | return buf; |
150 | } | 150 | } |
151 | 151 | ||
152 | 152 | ||
153 | QString OInputDevice::uniq() const | 153 | QString OInputDevice::uniq() const |
154 | { | 154 | { |
155 | char buf[BUFSIZE] = "<unknown>"; | 155 | char buf[BUFSIZE] = "<unknown>"; |
156 | ::ioctl( _fd, EVIOCGUNIQ(sizeof buf), buf ); | 156 | ::ioctl( _fd, EVIOCGUNIQ(sizeof buf), buf ); |
157 | return buf; | 157 | return buf; |
158 | } | 158 | } |
159 | 159 | ||
160 | 160 | ||
161 | bool OInputDevice::hasFeature( Feature bit ) const | 161 | bool OInputDevice::hasFeature( Feature bit ) const |
162 | { | 162 | { |
163 | BIT_MASK( features, EV_MAX ); | 163 | BIT_MASK( features, EV_MAX ); |
164 | 164 | ||
165 | if( ioctl( _fd, EVIOCGBIT( 0, EV_MAX ), features) < 0 ) | 165 | if( ioctl( _fd, EVIOCGBIT( 0, EV_MAX ), features) < 0 ) |
166 | { | 166 | { |
167 | perror( "EVIOCGBIT" ); | 167 | perror( "EVIOCGBIT" ); |
168 | return false; | 168 | return false; |
169 | } | 169 | } |
170 | else | 170 | else |
171 | return BIT_TEST( features, bit ); | 171 | return BIT_TEST( features, bit ); |
172 | } | 172 | } |
173 | 173 | ||
174 | 174 | ||
175 | bool OInputDevice::isHeld( Key bit ) const | 175 | bool OInputDevice::isHeld( Key bit ) const |
176 | { | 176 | { |
177 | BIT_MASK( keys, KEY_MAX ); | 177 | BIT_MASK( keys, KEY_MAX ); |
178 | 178 | ||
179 | if( ioctl( _fd, EVIOCGKEY( sizeof(keys) ), keys ) < 0 ) | 179 | if( ioctl( _fd, EVIOCGKEY( sizeof(keys) ), keys ) < 0 ) |
180 | { | 180 | { |
181 | perror( "EVIOCGKEY" ); | 181 | perror( "EVIOCGKEY" ); |
182 | return false; | 182 | return false; |
183 | } | 183 | } |
184 | else | 184 | else |
185 | { | 185 | { |
186 | return BIT_TEST( keys, bit ); | 186 | return BIT_TEST( keys, bit ); |
187 | } | 187 | } |
188 | } | 188 | } |
189 | 189 | ||
190 | 190 | ||
191 | QString OInputDevice::globalKeyMask() const | 191 | QString OInputDevice::globalKeyMask() const |
192 | { | 192 | { |
193 | BIT_MASK( keys, KEY_MAX ); | 193 | BIT_MASK( keys, KEY_MAX ); |
194 | 194 | ||
195 | if( ioctl( _fd, EVIOCGKEY( sizeof(keys) ), keys ) < 0 ) | 195 | if( ioctl( _fd, EVIOCGKEY( sizeof(keys) ), keys ) < 0 ) |
196 | { | 196 | { |
197 | perror( "EVIOCGKEY" ); | 197 | perror( "EVIOCGKEY" ); |
198 | return QString::null; | 198 | return QString::null; |
199 | } | 199 | } |
200 | else | 200 | else |
201 | { | 201 | { |
202 | QString keymask; | 202 | QString keymask; |
203 | for ( int i = 0; i < KEY_MAX; ++i ) | 203 | for ( int i = 0; i < KEY_MAX; ++i ) |
204 | { | 204 | { |
205 | if ( BIT_TEST( keys, i ) ) keymask.append( QString().sprintf( "%0d, ", i ) ); | 205 | if ( BIT_TEST( keys, i ) ) keymask.append( QString().sprintf( "%0d, ", i ) ); |
206 | } | 206 | } |
207 | return keymask; | 207 | return keymask; |
208 | 208 | ||
209 | } | 209 | } |
210 | } | 210 | } |
211 | 211 | ||
212 | 212 | ||
213 | bool OInputDevice::isValid( const QString& path ) | 213 | bool OInputDevice::isValid( const QString& path ) |
214 | { | 214 | { |
215 | char buf[BUFSIZE] = "<unknown>"; | 215 | char buf[BUFSIZE] = "<unknown>"; |
216 | int fd = ::open( (const char*) path, O_RDONLY ); | 216 | int fd = ::open( (const char*) path, O_RDONLY ); |
217 | if ( fd < 0 ) return false; | 217 | if ( fd < 0 ) return false; |
218 | int res = ::ioctl( fd, EVIOCGNAME(sizeof buf), buf ); | 218 | int res = ::ioctl( fd, EVIOCGNAME(sizeof buf), buf ); |
219 | ::close( fd ); | 219 | ::close( fd ); |
220 | return res >= 0; | 220 | return res >= 0; |
221 | } | 221 | } |
222 | 222 | ||
diff --git a/libopie2/opiecore/oinputsystem.h b/libopie2/opiecore/linux/oinputsystem.h index 6f822a1..9676e73 100644 --- a/libopie2/opiecore/oinputsystem.h +++ b/libopie2/opiecore/linux/oinputsystem.h | |||
@@ -1,142 +1,142 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | .=l. | 4 | .=l. |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This program is free software; you can | 6 | _;:, .> :=|. This program is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; version 2 of the License. |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This program is distributed in the hope that | 13 | .i_,=:_. -<s. This program is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
18 | ..}^=.= = ; Library General Public License for more | 18 | ..}^=.= = ; Library General Public License for more |
19 | ++= -. .` .: details. | 19 | ++= -. .` .: details. |
20 | : = ...= . :.=- | 20 | : = ...= . :.=- |
21 | -. .:....=;==+<; You should have received a copy of the GNU | 21 | -. .:....=;==+<; You should have received a copy of the GNU |
22 | -_. . . )=. = Library General Public License along with | 22 | -_. . . )=. = Library General Public License along with |
23 | -- :-=` this library; see the file COPYING.LIB. | 23 | -- :-=` this library; see the file COPYING.LIB. |
24 | If not, write to the Free Software Foundation, | 24 | If not, write to the Free Software Foundation, |
25 | Inc., 59 Temple Place - Suite 330, | 25 | Inc., 59 Temple Place - Suite 330, |
26 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
27 | */ | 27 | */ |
28 | 28 | ||
29 | #ifndef OINPUTSYSTEM_H | 29 | #ifndef OINPUTSYSTEM_H |
30 | #define OINPUTSYSTEM_H | 30 | #define OINPUTSYSTEM_H |
31 | 31 | ||
32 | #include "linux_input.h" | 32 | #include "linux_input.h" |
33 | 33 | ||
34 | /* QT */ | 34 | /* QT */ |
35 | #include <qobject.h> | 35 | #include <qobject.h> |
36 | #include <qdict.h> | 36 | #include <qdict.h> |
37 | 37 | ||
38 | namespace Opie { | 38 | namespace Opie { |
39 | namespace Core { | 39 | namespace Core { |
40 | 40 | ||
41 | class OInputDevice; | 41 | class OInputDevice; |
42 | 42 | ||
43 | /** | 43 | /** |
44 | * @brief A container class for all input devices | 44 | * @brief A container class for the Linux input device subsystem |
45 | * | 45 | * |
46 | * This class provides access to all available input system devices of your computer. | 46 | * This class provides access to all available input system devices of your device. |
47 | * | 47 | * |
48 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 48 | * @author Michael 'Mickey' Lauer <mickey@Vanille.de> |
49 | */ | 49 | */ |
50 | class OInputSystem : public QObject | 50 | class OInputSystem : public QObject |
51 | { | 51 | { |
52 | public: | 52 | public: |
53 | typedef QDict<OInputDevice> DeviceMap; | 53 | typedef QDict<OInputDevice> DeviceMap; |
54 | typedef QDictIterator<OInputDevice> DeviceIterator; | 54 | typedef QDictIterator<OInputDevice> DeviceIterator; |
55 | 55 | ||
56 | /** | 56 | /** |
57 | * @returns the number of available input devices | 57 | * @returns the number of available input devices |
58 | */ | 58 | */ |
59 | int count() const; | 59 | int count() const; |
60 | /** | 60 | /** |
61 | * @returns a pointer to the (one and only) @ref OInputSystem instance. | 61 | * @returns a pointer to the (one and only) @ref OInputSystem instance. |
62 | */ | 62 | */ |
63 | static OInputSystem* instance(); | 63 | static OInputSystem* instance(); |
64 | /** | 64 | /** |
65 | * @returns an iterator usable for iterating through all network interfaces. | 65 | * @returns an iterator usable for iterating through all network interfaces. |
66 | */ | 66 | */ |
67 | DeviceIterator iterator() const; | 67 | DeviceIterator iterator() const; |
68 | /** | 68 | /** |
69 | * @returns a pointer to the @ref OAudioInterface object for the specified @a interface or 0, if not found | 69 | * @returns a pointer to the @ref OAudioInterface object for the specified @a interface or 0, if not found |
70 | * @see OAudioInterface | 70 | * @see OAudioInterface |
71 | */ | 71 | */ |
72 | OInputDevice* device( const QString& interface ) const; | 72 | OInputDevice* device( const QString& interface ) const; |
73 | /** | 73 | /** |
74 | * @internal Rebuild the internal interface database | 74 | * @internal Rebuild the internal interface database |
75 | * @note Sometimes it might be useful to call this from client code, | 75 | * @note Sometimes it might be useful to call this from client code, |
76 | */ | 76 | */ |
77 | void synchronize(); | 77 | void synchronize(); |
78 | /** | 78 | /** |
79 | * @internal destructor | 79 | * @internal destructor |
80 | */ | 80 | */ |
81 | ~OInputSystem(); | 81 | ~OInputSystem(); |
82 | 82 | ||
83 | protected: | 83 | protected: |
84 | OInputSystem(); | 84 | OInputSystem(); |
85 | 85 | ||
86 | static OInputSystem* _instance; | 86 | static OInputSystem* _instance; |
87 | DeviceMap _devices; | 87 | DeviceMap _devices; |
88 | }; | 88 | }; |
89 | 89 | ||
90 | 90 | ||
91 | class OInputDevice : public QObject | 91 | class OInputDevice : public QObject |
92 | { | 92 | { |
93 | public: | 93 | public: |
94 | OInputDevice( QObject* parent, const char* name = 0 ); | 94 | OInputDevice( QObject* parent, const char* name = 0 ); |
95 | ~OInputDevice(); | 95 | ~OInputDevice(); |
96 | 96 | ||
97 | #include "oinputsystemenums.h" | 97 | #include "oinputsystemenums.h" |
98 | 98 | ||
99 | public: | 99 | public: |
100 | /** | 100 | /** |
101 | * @returns the identity string of this input device | 101 | * @returns the identity string of this input device |
102 | */ | 102 | */ |
103 | QString identity() const; | 103 | QString identity() const; |
104 | /** | 104 | /** |
105 | * @returns the path of this input device | 105 | * @returns the path of this input device |
106 | */ | 106 | */ |
107 | QString path() const; | 107 | QString path() const; |
108 | /** | 108 | /** |
109 | * @returns a unique identifier for this input device | 109 | * @returns a unique identifier for this input device |
110 | * @note Only a few devices support this | 110 | * @note Only a few devices support this |
111 | */ | 111 | */ |
112 | QString uniq() const; | 112 | QString uniq() const; |
113 | /** | 113 | /** |
114 | * @returns whether a certain @a Feature is being supported by this device | 114 | * @returns whether a certain @a Feature is being supported by this device |
115 | */ | 115 | */ |
116 | bool hasFeature( Feature ) const; | 116 | bool hasFeature( Feature ) const; |
117 | /** | 117 | /** |
118 | * @returns whether a given @a Key or Button is being held at the moment | 118 | * @returns whether a given @a Key or Button is being held at the moment |
119 | */ | 119 | */ |
120 | bool isHeld( Key ) const; | 120 | bool isHeld( Key ) const; |
121 | /** | 121 | /** |
122 | * @internal | 122 | * @internal |
123 | * @returns a string containing a printable form of the global keymask | 123 | * @returns a string containing a printable form of the global keymask |
124 | */ | 124 | */ |
125 | QString globalKeyMask() const; | 125 | QString globalKeyMask() const; |
126 | /** | 126 | /** |
127 | * @internal | 127 | * @internal |
128 | * @returns whether a certain @a path corresponds to an input device | 128 | * @returns whether a certain @a path corresponds to an input device |
129 | */ | 129 | */ |
130 | static bool isValid( const QString& path ); | 130 | static bool isValid( const QString& path ); |
131 | 131 | ||
132 | private: | 132 | private: |
133 | int _fd; | 133 | int _fd; |
134 | input_id _id; | 134 | input_id _id; |
135 | 135 | ||
136 | }; | 136 | }; |
137 | 137 | ||
138 | } | 138 | } |
139 | } | 139 | } |
140 | 140 | ||
141 | #endif // OINPUTSYSTEM_H | 141 | #endif // OINPUTSYSTEM_H |
142 | 142 | ||
diff --git a/libopie2/opiecore/linux/oinputsystemenums.h b/libopie2/opiecore/linux/oinputsystemenums.h new file mode 100644 index 0000000..3461e5a --- a/dev/null +++ b/libopie2/opiecore/linux/oinputsystemenums.h | |||
@@ -0,0 +1,405 @@ | |||
1 | |||
2 | enum Feature | ||
3 | { | ||
4 | Synchronous = EV_SYN, | ||
5 | Keys = EV_KEY, | ||
6 | Relative = EV_REL, | ||
7 | Absolute = EV_ABS, | ||
8 | Miscellaneous = EV_MSC, | ||
9 | Leds = EV_LED, | ||
10 | Sound = EV_SND, | ||
11 | AutoRepeat = EV_REP, | ||
12 | ForceFeedback = EV_FF, | ||
13 | PowerManagement = EV_PWR, | ||
14 | ForceFeedbackStatus = EV_FF_STATUS, | ||
15 | }; | ||
16 | |||
17 | enum Bus | ||
18 | { | ||
19 | PCI = BUS_PCI, | ||
20 | ISAPNP = BUS_ISAPNP, | ||
21 | HIL = BUS_HIL, | ||
22 | BLUETOOTH = BUS_BLUETOOTH, | ||
23 | ISA = BUS_ISA, | ||
24 | I8042 = BUS_I8042, | ||
25 | XTKBD = BUS_XTKBD, | ||
26 | RS232 = BUS_RS232, | ||
27 | GAMEPORT = BUS_GAMEPORT, | ||
28 | PARPORT = BUS_PARPORT, | ||
29 | AMIGA = BUS_AMIGA, | ||
30 | ADB = BUS_ADB, | ||
31 | I2C = BUS_I2C, | ||
32 | HOST = BUS_HOST, | ||
33 | }; | ||
34 | |||
35 | enum Key | ||
36 | { | ||
37 | Key_RESERVED = 0, | ||
38 | Key_ESC = 1, | ||
39 | Key_1 = 2, | ||
40 | Key_2 = 3, | ||
41 | Key_3 = 4, | ||
42 | Key_4 = 5, | ||
43 | Key_5 = 6, | ||
44 | Key_6 = 7, | ||
45 | Key_7 = 8, | ||
46 | Key_8 = 9, | ||
47 | Key_9 = 10, | ||
48 | Key_0 = 11, | ||
49 | Key_MINUS = 12, | ||
50 | Key_EQUAL = 13, | ||
51 | Key_BACKSPACE = 14, | ||
52 | Key_TAB = 15, | ||
53 | Key_Q = 16, | ||
54 | Key_W = 17, | ||
55 | Key_E = 18, | ||
56 | Key_R = 19, | ||
57 | Key_T = 20, | ||
58 | Key_Y = 21, | ||
59 | Key_U = 22, | ||
60 | Key_I = 23, | ||
61 | Key_O = 24, | ||
62 | Key_P = 25, | ||
63 | Key_LEFTBRACE = 26, | ||
64 | Key_RIGHTBRACE = 27, | ||
65 | Key_ENTER = 28, | ||
66 | Key_LEFTCTRL = 29, | ||
67 | Key_A = 30, | ||
68 | Key_S = 31, | ||
69 | Key_D = 32, | ||
70 | Key_F = 33, | ||
71 | Key_G = 34, | ||
72 | Key_H = 35, | ||
73 | Key_J = 36, | ||
74 | Key_K = 37, | ||
75 | Key_L = 38, | ||
76 | Key_SEMICOLON = 39, | ||
77 | Key_APOSTROPHE = 40, | ||
78 | Key_GRAVE = 41, | ||
79 | Key_LEFTSHIFT = 42, | ||
80 | Key_BACKSLASH = 43, | ||
81 | Key_Z = 44, | ||
82 | Key_X = 45, | ||
83 | Key_C = 46, | ||
84 | Key_V = 47, | ||
85 | Key_B = 48, | ||
86 | Key_N = 49, | ||
87 | Key_M = 50, | ||
88 | Key_COMMA = 51, | ||
89 | Key_DOT = 52, | ||
90 | Key_SLASH = 53, | ||
91 | Key_RIGHTSHIFT = 54, | ||
92 | Key_KPASTERISK = 55, | ||
93 | Key_LEFTALT = 56, | ||
94 | Key_SPACE = 57, | ||
95 | Key_CAPSLOCK = 58, | ||
96 | Key_F1 = 59, | ||
97 | Key_F2 = 60, | ||
98 | Key_F3 = 61, | ||
99 | Key_F4 = 62, | ||
100 | Key_F5 = 63, | ||
101 | Key_F6 = 64, | ||
102 | Key_F7 = 65, | ||
103 | Key_F8 = 66, | ||
104 | Key_F9 = 67, | ||
105 | Key_F10 = 68, | ||
106 | Key_NUMLOCK = 69, | ||
107 | Key_SCROLLLOCK = 70, | ||
108 | Key_KP7 = 71, | ||
109 | Key_KP8 = 72, | ||
110 | Key_KP9 = 73, | ||
111 | Key_KPMINUS = 74, | ||
112 | Key_KP4 = 75, | ||
113 | Key_KP5 = 76, | ||
114 | Key_KP6 = 77, | ||
115 | Key_KPPLUS = 78, | ||
116 | Key_KP1 = 79, | ||
117 | Key_KP2 = 80, | ||
118 | Key_KP3 = 81, | ||
119 | Key_KP0 = 82, | ||
120 | Key_KPDOT = 83, | ||
121 | |||
122 | Key_ZENKAKUHANKAKU= 85, | ||
123 | Key_102ND = 86, | ||
124 | Key_F11 = 87, | ||
125 | Key_F12 = 88, | ||
126 | Key_RO = 89, | ||
127 | Key_KATAKANA = 90, | ||
128 | Key_HIRAGANA = 91, | ||
129 | Key_HENKAN = 92, | ||
130 | Key_KATAKANAHIRAGANA= 93, | ||
131 | Key_MUHENKAN = 94, | ||
132 | Key_KPJPCOMMA = 95, | ||
133 | Key_KPENTER = 96, | ||
134 | Key_RIGHTCTRL = 97, | ||
135 | Key_KPSLASH = 98, | ||
136 | Key_SYSRQ = 99, | ||
137 | Key_RIGHTALT = 100, | ||
138 | Key_LINEFEED = 101, | ||
139 | Key_HOME = 102, | ||
140 | Key_UP = 103, | ||
141 | Key_PAGEUP = 104, | ||
142 | Key_LEFT = 105, | ||
143 | Key_RIGHT = 106, | ||
144 | Key_END = 107, | ||
145 | Key_DOWN = 108, | ||
146 | Key_PAGEDOWN = 109, | ||
147 | Key_INSERT = 110, | ||
148 | Key_DELETE = 111, | ||
149 | Key_MACRO = 112, | ||
150 | Key_MUTE = 113, | ||
151 | Key_VOLUMEDOWN = 114, | ||
152 | Key_VOLUMEUP = 115, | ||
153 | Key_POWER = 116, | ||
154 | Key_KPEQUAL = 117, | ||
155 | Key_KPPLUSMINUS = 118, | ||
156 | Key_PAUSE = 119, | ||
157 | |||
158 | Key_KPCOMMA = 121, | ||
159 | Key_HANGUEL = 122, | ||
160 | Key_HANJA = 123, | ||
161 | Key_YEN = 124, | ||
162 | Key_LEFTMETA = 125, | ||
163 | Key_RIGHTMETA = 126, | ||
164 | Key_COMPOSE = 127, | ||
165 | |||
166 | Key_STOP = 128, | ||
167 | Key_AGAIN = 129, | ||
168 | Key_PROPS = 130, | ||
169 | Key_UNDO = 131, | ||
170 | Key_FRONT = 132, | ||
171 | Key_COPY = 133, | ||
172 | Key_OPEN = 134, | ||
173 | Key_PASTE = 135, | ||
174 | Key_FIND = 136, | ||
175 | Key_CUT = 137, | ||
176 | Key_HELP = 138, | ||
177 | Key_MENU = 139, | ||
178 | Key_CALC = 140, | ||
179 | Key_SETUP = 141, | ||
180 | Key_SLEEP = 142, | ||
181 | Key_WAKEUP = 143, | ||
182 | Key_FILE = 144, | ||
183 | Key_SENDFILE = 145, | ||
184 | Key_DELETEFILE = 146, | ||
185 | Key_XFER = 147, | ||
186 | Key_PROG1 = 148, | ||
187 | Key_PROG2 = 149, | ||
188 | Key_WWW = 150, | ||
189 | Key_MSDOS = 151, | ||
190 | Key_COFFEE = 152, | ||
191 | Key_DIRECTION = 153, | ||
192 | Key_CYCLEWINDOWS= 154, | ||
193 | Key_MAIL = 155, | ||
194 | Key_BOOKMARKS = 156, | ||
195 | Key_COMPUTER = 157, | ||
196 | Key_BACK = 158, | ||
197 | Key_FORWARD = 159, | ||
198 | Key_CLOSECD = 160, | ||
199 | Key_EJECTCD = 161, | ||
200 | Key_EJECTCLOSECD= 162, | ||
201 | Key_NEXTSONG = 163, | ||
202 | Key_PLAYPAUSE = 164, | ||
203 | Key_PREVIOUSSONG= 165, | ||
204 | Key_STOPCD = 166, | ||
205 | Key_RECORD = 167, | ||
206 | Key_REWIND = 168, | ||
207 | Key_PHONE = 169, | ||
208 | Key_ISO = 170, | ||
209 | Key_CONFIG = 171, | ||
210 | Key_HOMEPAGE = 172, | ||
211 | Key_REFRESH = 173, | ||
212 | Key_EXIT = 174, | ||
213 | Key_MOVE = 175, | ||
214 | Key_EDIT = 176, | ||
215 | Key_SCROLLUP = 177, | ||
216 | Key_SCROLLDOWN = 178, | ||
217 | Key_KPLEFTPAREN = 179, | ||
218 | Key_KPRIGHTPAREN= 180, | ||
219 | |||
220 | Key_F13 = 183, | ||
221 | Key_F14 = 184, | ||
222 | Key_F15 = 185, | ||
223 | Key_F16 = 186, | ||
224 | Key_F17 = 187, | ||
225 | Key_F18 = 188, | ||
226 | Key_F19 = 189, | ||
227 | Key_F20 = 190, | ||
228 | Key_F21 = 191, | ||
229 | Key_F22 = 192, | ||
230 | Key_F23 = 193, | ||
231 | Key_F24 = 194, | ||
232 | |||
233 | Key_PLAYCD = 200, | ||
234 | Key_PAUSECD = 201, | ||
235 | Key_PROG3 = 202, | ||
236 | Key_PROG4 = 203, | ||
237 | Key_SUSPEND = 205, | ||
238 | Key_CLOSE = 206, | ||
239 | Key_PLAY = 207, | ||
240 | Key_FASTFORWARD = 208, | ||
241 | Key_BASSBOOST = 209, | ||
242 | Key_PRINT = 210, | ||
243 | Key_HP = 211, | ||
244 | Key_CAMERA = 212, | ||
245 | Key_SOUND = 213, | ||
246 | Key_QUESTION = 214, | ||
247 | Key_EMAIL = 215, | ||
248 | Key_CHAT = 216, | ||
249 | Key_SEARCH = 217, | ||
250 | Key_CONNECT = 218, | ||
251 | Key_FINANCE = 219, | ||
252 | Key_SPORT = 220, | ||
253 | Key_SHOP = 221, | ||
254 | Key_ALTERASE = 222, | ||
255 | Key_CANCEL = 223, | ||
256 | Key_BRIGHTNESSDOWN= 224, | ||
257 | Key_BRIGHTNESSUP= 225, | ||
258 | Key_MEDIA = 226, | ||
259 | |||
260 | Key_UNKNOWN = 240, | ||
261 | |||
262 | Button_MISC = 0x100, | ||
263 | Button_0 = 0x100, | ||
264 | Button_1 = 0x101, | ||
265 | Button_2 = 0x102, | ||
266 | Button_3 = 0x103, | ||
267 | Button_4 = 0x104, | ||
268 | Button_5 = 0x105, | ||
269 | Button_6 = 0x106, | ||
270 | Button_7 = 0x107, | ||
271 | Button_8 = 0x108, | ||
272 | Button_9 = 0x109, | ||
273 | |||
274 | Button_MOUSE = 0x110, | ||
275 | Button_LEFT = 0x110, | ||
276 | Button_RIGHT = 0x111, | ||
277 | Button_MIDDLE = 0x112, | ||
278 | Button_SIDE = 0x113, | ||
279 | Button_EXTRA = 0x114, | ||
280 | Button_FORWARD = 0x115, | ||
281 | Button_BACK = 0x116, | ||
282 | Button_TASK = 0x117, | ||
283 | |||
284 | Button_JOYSTICK = 0x120, | ||
285 | Button_TRIGGER = 0x120, | ||
286 | Button_THUMB = 0x121, | ||
287 | Button_THUMB2 = 0x122, | ||
288 | Button_TOP = 0x123, | ||
289 | Button_TOP2 = 0x124, | ||
290 | Button_PINKIE = 0x125, | ||
291 | Button_BASE = 0x126, | ||
292 | Button_BASE2 = 0x127, | ||
293 | Button_BASE3 = 0x128, | ||
294 | Button_BASE4 = 0x129, | ||
295 | Button_BASE5 = 0x12a, | ||
296 | Button_BASE6 = 0x12b, | ||
297 | Button_DEAD = 0x12f, | ||
298 | |||
299 | Button_GAMEPAD = 0x130, | ||
300 | Button_A = 0x130, | ||
301 | Button_B = 0x131, | ||
302 | Button_C = 0x132, | ||
303 | Button_X = 0x133, | ||
304 | Button_Y = 0x134, | ||
305 | Button_Z = 0x135, | ||
306 | Button_TL = 0x136, | ||
307 | Button_TR = 0x137, | ||
308 | Button_TL2 = 0x138, | ||
309 | Button_TR2 = 0x139, | ||
310 | Button_SELECT = 0x13a, | ||
311 | Button_START = 0x13b, | ||
312 | Button_MODE = 0x13c, | ||
313 | Button_THUMBL = 0x13d, | ||
314 | Button_THUMBR = 0x13e, | ||
315 | |||
316 | Button_DIGI = 0x140, | ||
317 | Button_TOOL_PEN = 0x140, | ||
318 | Button_TOOL_RUBBER = 0x141, | ||
319 | Button_TOOL_BRUSH = 0x142, | ||
320 | Button_TOOL_PENCIL = 0x143, | ||
321 | Button_TOOL_AIRBRUSH= 0x144, | ||
322 | Button_TOOL_FINGER = 0x145, | ||
323 | Button_TOOL_MOUSE = 0x146, | ||
324 | Button_TOOL_LENS = 0x147, | ||
325 | Button_TOUCH = 0x14a, | ||
326 | Button_STYLUS = 0x14b, | ||
327 | Button_STYLUS2 = 0x14c, | ||
328 | Button_TOOL_DOUBLETAP= 0x14d, | ||
329 | Button_TOOL_TRIPLETAP= 0x14e, | ||
330 | |||
331 | Button_WHEEL = 0x150, | ||
332 | Button_GEAR_DOWN = 0x150, | ||
333 | Button_GEAR_UP = 0x151, | ||
334 | |||
335 | Key_OK = 0x160, | ||
336 | Key_SELECT = 0x161, | ||
337 | Key_GOTO = 0x162, | ||
338 | Key_CLEAR = 0x163, | ||
339 | Key_POWER2 = 0x164, | ||
340 | Key_OPTION = 0x165, | ||
341 | Key_INFO = 0x166, | ||
342 | Key_TIME = 0x167, | ||
343 | Key_VENDOR = 0x168, | ||
344 | Key_ARCHIVE = 0x169, | ||
345 | Key_PROGRAM = 0x16a, | ||
346 | Key_CHANNEL = 0x16b, | ||
347 | Key_FAVORITES = 0x16c, | ||
348 | Key_EPG = 0x16d, | ||
349 | Key_PVR = 0x16e, | ||
350 | Key_MHP = 0x16f, | ||
351 | Key_LANGUAGE = 0x170, | ||
352 | Key_TITLE = 0x171, | ||
353 | Key_SUBTITLE = 0x172, | ||
354 | Key_ANGLE = 0x173, | ||
355 | Key_ZOOM = 0x174, | ||
356 | Key_MODE = 0x175, | ||
357 | Key_KEYBOARD = 0x176, | ||
358 | Key_SCREEN = 0x177, | ||
359 | Key_PC = 0x178, | ||
360 | Key_TV = 0x179, | ||
361 | Key_TV2 = 0x17a, | ||
362 | Key_VCR = 0x17b, | ||
363 | Key_VCR2 = 0x17c, | ||
364 | Key_SAT = 0x17d, | ||
365 | Key_SAT2 = 0x17e, | ||
366 | Key_CD = 0x17f, | ||
367 | Key_TAPE = 0x180, | ||
368 | Key_RADIO = 0x181, | ||
369 | Key_TUNER = 0x182, | ||
370 | Key_PLAYER = 0x183, | ||
371 | Key_TEXT = 0x184, | ||
372 | Key_DVD = 0x185, | ||
373 | Key_AUX = 0x186, | ||
374 | Key_MP3 = 0x187, | ||
375 | Key_AUDIO = 0x188, | ||
376 | Key_VIDEO = 0x189, | ||
377 | Key_DIRECTORY = 0x18a, | ||
378 | Key_LIST = 0x18b, | ||
379 | Key_MEMO = 0x18c, | ||
380 | Key_CALENDAR = 0x18d, | ||
381 | Key_RED = 0x18e, | ||
382 | Key_GREEN = 0x18f, | ||
383 | Key_YELLOW = 0x190, | ||
384 | Key_BLUE = 0x191, | ||
385 | Key_CHANNELUP = 0x192, | ||
386 | Key_CHANNELDOWN = 0x193, | ||
387 | Key_FIRST = 0x194, | ||
388 | Key_LAST = 0x195, | ||
389 | Key_AB = 0x196, | ||
390 | Key_NEXT = 0x197, | ||
391 | Key_RESTART = 0x198, | ||
392 | Key_SLOW = 0x199, | ||
393 | Key_SHUFFLE = 0x19a, | ||
394 | Key_BREAK = 0x19b, | ||
395 | Key_PREVIOUS = 0x19c, | ||
396 | Key_DIGITS = 0x19d, | ||
397 | Key_TEEN = 0x19e, | ||
398 | Key_TWEN = 0x19f, | ||
399 | |||
400 | Key_DEL_EOL = 0x1c0, | ||
401 | Key_DEL_EOS = 0x1c1, | ||
402 | Key_INS_LINE = 0x1c2, | ||
403 | Key_DEL_LINE = 0x1c3, | ||
404 | }; | ||
405 | |||
diff --git a/libopie2/opiecore/linux/opcmciasystem.cpp b/libopie2/opiecore/linux/opcmciasystem.cpp new file mode 100644 index 0000000..a924696 --- a/dev/null +++ b/libopie2/opiecore/linux/opcmciasystem.cpp | |||
@@ -0,0 +1,142 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de> | ||
4 | .=l. | ||
5 | .>+-= | ||
6 | _;:, .> :=|. This program is free software; you can | ||
7 | .> <`_, > . <= redistribute it and/or modify it under | ||
8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
9 | .="- .-=="i, .._ License as published by the Free Software | ||
10 | - . .-<_> .<> Foundation; version 2 of the License. | ||
11 | ._= =} : | ||
12 | .%`+i> _;_. | ||
13 | .i_,=:_. -<s. This program is distributed in the hope that | ||
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
15 | : .. .:, . . . without even the implied warranty of | ||
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
18 | ..}^=.= = ; Library General Public License for more | ||
19 | ++= -. .` .: details. | ||
20 | : = ...= . :.=- | ||
21 | -. .:....=;==+<; You should have received a copy of the GNU | ||
22 | -_. . . )=. = Library General Public License along with | ||
23 | -- :-=` this library; see the file COPYING.LIB. | ||
24 | If not, write to the Free Software Foundation, | ||
25 | Inc., 59 Temple Place - Suite 330, | ||
26 | Boston, MA 02111-1307, USA. | ||
27 | |||
28 | */ | ||
29 | |||
30 | #include "opcmciasystem.h" | ||
31 | using namespace Opie::Core; | ||
32 | |||
33 | /* OPIE */ | ||
34 | #include <opie2/odebug.h> | ||
35 | |||
36 | /* QT */ | ||
37 | #include <qfile.h> | ||
38 | #include <qtextstream.h> | ||
39 | |||
40 | /* STD */ | ||
41 | #include <errno.h> | ||
42 | #include <fcntl.h> | ||
43 | #include <string.h> | ||
44 | #include <sys/ioctl.h> | ||
45 | #include <sys/types.h> | ||
46 | #include <sys/stat.h> | ||
47 | |||
48 | /*====================================================================================== | ||
49 | * OPcmciaSystem | ||
50 | *======================================================================================*/ | ||
51 | |||
52 | OPcmciaSystem* OPcmciaSystem::_instance = 0; | ||
53 | |||
54 | OPcmciaSystem::OPcmciaSystem() | ||
55 | { | ||
56 | qDebug( "OPcmciaSystem::OPcmciaSystem()" ); | ||
57 | synchronize(); | ||
58 | } | ||
59 | |||
60 | void OPcmciaSystem::synchronize() | ||
61 | { | ||
62 | qDebug( "OPcmciaSystem::synchronize()" ); | ||
63 | _interfaces.clear(); | ||
64 | |||
65 | //FIXME: Use cardmgr subsystem ioctls | ||
66 | |||
67 | QString fileName; | ||
68 | if ( QFile::exists( "/var/run/stab" ) ) { fileName = "/var/run/stab"; } | ||
69 | else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) { fileName = "/var/state/pcmcia/stab"; } | ||
70 | else { fileName = "/var/lib/pcmcia/stab"; } | ||
71 | QFile cardinfofile( fileName ); | ||
72 | if ( !cardinfofile.exists() || !cardinfofile.open( IO_ReadOnly ) ) | ||
73 | { | ||
74 | qWarning( "pcmcia info file not found or unaccessible" ); | ||
75 | return; | ||
76 | } | ||
77 | QTextStream cardinfo( &cardinfofile ); | ||
78 | while ( !cardinfo.atEnd() ) | ||
79 | { | ||
80 | QString line = cardinfo.readLine(); | ||
81 | if ( line.startsWith( "Socket" ) ) | ||
82 | { | ||
83 | int mid = line.find( ':' ); | ||
84 | QString name = line.right( line.length() - mid - 1 ); | ||
85 | QString id = line.right( line.length() - mid + 1 ); | ||
86 | if ( mid ) _interfaces.insert( name, new OPcmciaCard( this, (const char*) id ) ); | ||
87 | } | ||
88 | else | ||
89 | { | ||
90 | continue; | ||
91 | } | ||
92 | } | ||
93 | } | ||
94 | |||
95 | |||
96 | int OPcmciaSystem::count() const | ||
97 | { | ||
98 | return _interfaces.count(); | ||
99 | } | ||
100 | |||
101 | |||
102 | OPcmciaCard* OPcmciaSystem::card( const QString& iface ) const | ||
103 | { | ||
104 | return _interfaces[iface]; | ||
105 | } | ||
106 | |||
107 | |||
108 | OPcmciaSystem* OPcmciaSystem::instance() | ||
109 | { | ||
110 | if ( !_instance ) _instance = new OPcmciaSystem(); | ||
111 | return _instance; | ||
112 | } | ||
113 | |||
114 | |||
115 | OPcmciaSystem::CardIterator OPcmciaSystem::iterator() const | ||
116 | { | ||
117 | return OPcmciaSystem::CardIterator( _interfaces ); | ||
118 | } | ||
119 | |||
120 | |||
121 | /*====================================================================================== | ||
122 | * OPcmciaCard | ||
123 | *======================================================================================*/ | ||
124 | |||
125 | OPcmciaCard::OPcmciaCard( QObject* parent, const char* name ) | ||
126 | :QObject( parent, name ) | ||
127 | { | ||
128 | odebug << "OPcmciaCard::OPcmciaCard()" << oendl; | ||
129 | init(); | ||
130 | } | ||
131 | |||
132 | |||
133 | OPcmciaCard::~OPcmciaCard() | ||
134 | { | ||
135 | } | ||
136 | |||
137 | |||
138 | void OPcmciaCard::init() | ||
139 | { | ||
140 | } | ||
141 | |||
142 | |||
diff --git a/libopie2/opiecore/linux/opcmciasystem.h b/libopie2/opiecore/linux/opcmciasystem.h new file mode 100644 index 0000000..694bf16 --- a/dev/null +++ b/libopie2/opiecore/linux/opcmciasystem.h | |||
@@ -0,0 +1,129 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de> | ||
4 | .=l. | ||
5 | .>+-= | ||
6 | _;:, .> :=|. This program is free software; you can | ||
7 | .> <`_, > . <= redistribute it and/or modify it under | ||
8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
9 | .="- .-=="i, .._ License as published by the Free Software | ||
10 | - . .-<_> .<> Foundation; version 2 of the License. | ||
11 | ._= =} : | ||
12 | .%`+i> _;_. | ||
13 | .i_,=:_. -<s. This program is distributed in the hope that | ||
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
15 | : .. .:, . . . without even the implied warranty of | ||
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
18 | ..}^=.= = ; Library General Public License for more | ||
19 | ++= -. .` .: details. | ||
20 | : = ...= . :.=- | ||
21 | -. .:....=;==+<; You should have received a copy of the GNU | ||
22 | -_. . . )=. = Library General Public License along with | ||
23 | -- :-=` this library; see the file COPYING.LIB. | ||
24 | If not, write to the Free Software Foundation, | ||
25 | Inc., 59 Temple Place - Suite 330, | ||
26 | Boston, MA 02111-1307, USA. | ||
27 | |||
28 | */ | ||
29 | |||
30 | #ifndef OPCMCIASYSTEM_H | ||
31 | #define OPCMCIASYSTEM_H | ||
32 | |||
33 | #include <qobject.h> | ||
34 | #include <qdict.h> | ||
35 | #include <qmap.h> | ||
36 | |||
37 | namespace Opie { | ||
38 | namespace Core { | ||
39 | |||
40 | class OPcmciaCard; | ||
41 | |||
42 | /*====================================================================================== | ||
43 | * OPcmciaSystem | ||
44 | *======================================================================================*/ | ||
45 | |||
46 | /** | ||
47 | * @brief A container class for the linux pcmcia subsystem | ||
48 | * | ||
49 | * This class provides access to all available pcmcia/cf cards on your device. | ||
50 | * | ||
51 | * @author Michael 'Mickey' Lauer <mickey@Vanille.de> | ||
52 | */ | ||
53 | class OPcmciaSystem : public QObject | ||
54 | { | ||
55 | Q_OBJECT | ||
56 | |||
57 | public: | ||
58 | typedef QDict<OPcmciaCard> CardMap; | ||
59 | typedef QDictIterator<OPcmciaCard> CardIterator; | ||
60 | |||
61 | public: | ||
62 | /** | ||
63 | * @returns the number of available interfaces | ||
64 | */ | ||
65 | int count() const; | ||
66 | /** | ||
67 | * @returns a pointer to the (one and only) @ref OSystem instance. | ||
68 | */ | ||
69 | static OPcmciaSystem* instance(); | ||
70 | /** | ||
71 | * @returns an iterator usable for iterating through all sound cards. | ||
72 | */ | ||
73 | CardIterator iterator() const; | ||
74 | /** | ||
75 | * @returns a pointer to the @ref OAudioInterface object for the specified @a interface or 0, if not found | ||
76 | * @see OAudioInterface | ||
77 | */ | ||
78 | OPcmciaCard* card( const QString& interface ) const; | ||
79 | /** | ||
80 | * @internal Rebuild the internal interface database | ||
81 | * @note Sometimes it might be useful to call this from client code, | ||
82 | * e.g. after issuing a cardctl insert | ||
83 | */ | ||
84 | void synchronize(); | ||
85 | |||
86 | protected: | ||
87 | OPcmciaSystem(); | ||
88 | |||
89 | private: | ||
90 | static OPcmciaSystem* _instance; | ||
91 | CardMap _interfaces; | ||
92 | class Private; | ||
93 | Private *d; | ||
94 | }; | ||
95 | |||
96 | |||
97 | /*====================================================================================== | ||
98 | * OPcmciaCard | ||
99 | *======================================================================================*/ | ||
100 | |||
101 | class OPcmciaCard : public QObject | ||
102 | { | ||
103 | Q_OBJECT | ||
104 | |||
105 | public: | ||
106 | /** | ||
107 | * Constructor. Normally you don't create @ref OPcmciaCard objects yourself, | ||
108 | * but access them via @ref OPcmciaSystem::card(). | ||
109 | */ | ||
110 | OPcmciaCard( QObject* parent, const char* name ); | ||
111 | /** | ||
112 | * Destructor. | ||
113 | */ | ||
114 | virtual ~OPcmciaCard(); | ||
115 | |||
116 | protected: | ||
117 | |||
118 | private: | ||
119 | void init(); | ||
120 | private: | ||
121 | class Private; | ||
122 | Private *d; | ||
123 | }; | ||
124 | |||
125 | |||
126 | } | ||
127 | } | ||
128 | |||
129 | #endif // OPCMCIASYSTEM_H | ||
diff --git a/libopie2/opiecore/opiecore.pro b/libopie2/opiecore/opiecore.pro index 84f3343..cbb7e04 100644 --- a/libopie2/opiecore/opiecore.pro +++ b/libopie2/opiecore/opiecore.pro | |||
@@ -1,65 +1,59 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = lib |
2 | CONFIG += qt warn_on | 2 | CONFIG += qt warn_on |
3 | DESTDIR = $(OPIEDIR)/lib | 3 | DESTDIR = $(OPIEDIR)/lib |
4 | HEADERS = oapplication.h \ | 4 | HEADERS = oapplication.h \ |
5 | oconfig.h \ | 5 | oconfig.h \ |
6 | odebug.h \ | 6 | odebug.h \ |
7 | oglobal.h \ | 7 | oglobal.h \ |
8 | oglobalsettings.h \ | 8 | oglobalsettings.h \ |
9 | oinputsystem.h \ | ||
10 | okeyconfigmanager.h \ | 9 | okeyconfigmanager.h \ |
11 | okeyfilter.h \ | 10 | okeyfilter.h \ |
12 | opluginloader.h \ | 11 | opluginloader.h \ |
13 | oprocess.h \ | 12 | oprocess.h \ |
14 | oprocctrl.h \ | 13 | oprocctrl.h \ |
15 | oresource.h \ | 14 | oresource.h \ |
16 | osharedpointer.h \ | 15 | osharedpointer.h \ |
17 | osmartpointer.h \ | 16 | osmartpointer.h \ |
18 | ostorageinfo.h \ | 17 | ostorageinfo.h \ |
19 | xmltree.h | 18 | xmltree.h |
20 | 19 | ||
21 | SOURCES = oapplication.cpp \ | 20 | SOURCES = oapplication.cpp \ |
22 | oconfig.cpp \ | 21 | oconfig.cpp \ |
23 | odebug.cpp \ | 22 | odebug.cpp \ |
24 | oglobal.cpp \ | 23 | oglobal.cpp \ |
25 | oglobalsettings.cpp \ | 24 | oglobalsettings.cpp \ |
26 | oinputsystem.cpp \ | ||
27 | okeyconfigmanager.cpp \ | 25 | okeyconfigmanager.cpp \ |
28 | okeyfilter.cpp \ | 26 | okeyfilter.cpp \ |
29 | opluginloader.cpp \ | 27 | opluginloader.cpp \ |
30 | oprocess.cpp \ | 28 | oprocess.cpp \ |
31 | oprocctrl.cpp \ | 29 | oprocctrl.cpp \ |
32 | oresource.cpp \ | 30 | oresource.cpp \ |
33 | osmartpointer.cpp \ | 31 | osmartpointer.cpp \ |
34 | ostorageinfo.cpp \ | 32 | ostorageinfo.cpp \ |
35 | xmltree.cpp | 33 | xmltree.cpp |
36 | 34 | ||
37 | 35 | ||
38 | # The following files are currently not compileable on mac ! | 36 | # Disable Linux-only subsystems for MAC build |
39 | # Therfore I removed them from the build .. (eilers) | 37 | !contains( CONFIG_TARGET_MACOSX, y ) { |
40 | 38 | include ( linux/linux.pro ) | |
41 | CONFTEST = $$system( echo $CONFIG_TARGET_MACOSX ) | ||
42 | !contains( CONFTEST, y ) { | ||
43 | HEADERS += ofilenotify.h | ||
44 | SOURCES += ofilenotify.cpp | ||
45 | } else { | 39 | } else { |
46 | message( "ofilenotify is not available in a mac build !" ) | 40 | message( "disabling linux-only subsystems for MAC build" ) |
47 | } | 41 | } |
48 | 42 | ||
49 | include( device/device.pro ) | 43 | include( device/device.pro ) |
50 | 44 | ||
51 | INTERFACES = | 45 | INTERFACES = |
52 | TARGET = opiecore2 | 46 | TARGET = opiecore2 |
53 | VERSION = 1.9.3 | 47 | VERSION = 1.9.4 |
54 | INCLUDEPATH += $(OPIEDIR)/include | 48 | INCLUDEPATH += $(OPIEDIR)/include |
55 | DEPENDPATH += $(OPIEDIR)/include | 49 | DEPENDPATH += $(OPIEDIR)/include |
56 | 50 | ||
57 | !contains( platform, x11 ) { | 51 | !contains( platform, x11 ) { |
58 | LIBS = -lqpe | 52 | LIBS = -lqpe |
59 | include( $(OPIEDIR)/include.pro ) | 53 | include( $(OPIEDIR)/include.pro ) |
60 | } | 54 | } |
61 | 55 | ||
62 | contains( platform, x11 ) { | 56 | contains( platform, x11 ) { |
63 | LIBS = -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib | 57 | LIBS = -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib |
64 | } | 58 | } |
65 | 59 | ||
diff --git a/libopie2/opiemm/osoundsystem.cpp b/libopie2/opiemm/osoundsystem.cpp index 2956682..6f849cd 100644 --- a/libopie2/opiemm/osoundsystem.cpp +++ b/libopie2/opiemm/osoundsystem.cpp | |||
@@ -1,315 +1,317 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | (C) 2003-2005 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | =. (C) 2003-2005 Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | =. | ||
5 | .=l. | 4 | .=l. |
6 | .>+-= | 5 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 6 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 12 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 13 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 18 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 19 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 20 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 21 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 22 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 23 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 24 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 25 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
28 | 27 | ||
29 | */ | 28 | */ |
30 | 29 | ||
31 | #include <opie2/osoundsystem.h> | 30 | #include "osoundsystem.h" |
31 | using namespace Opie::MM; | ||
32 | |||
33 | /* OPIE */ | ||
32 | #include <opie2/odebug.h> | 34 | #include <opie2/odebug.h> |
35 | using namespace Opie::Core; | ||
33 | 36 | ||
37 | /* STD */ | ||
34 | #include <errno.h> | 38 | #include <errno.h> |
35 | #include <fcntl.h> | 39 | #include <fcntl.h> |
36 | #include <string.h> | 40 | #include <string.h> |
37 | #include <sys/ioctl.h> | 41 | #include <sys/ioctl.h> |
38 | #include <sys/types.h> | 42 | #include <sys/types.h> |
39 | #include <sys/soundcard.h> | 43 | #include <sys/soundcard.h> |
40 | #include <sys/stat.h> | 44 | #include <sys/stat.h> |
41 | 45 | ||
42 | static const char* device_label[] = SOUND_DEVICE_LABELS; | 46 | static const char* device_label[] = SOUND_DEVICE_LABELS; |
43 | static int max_device_nr = sizeof device_label / sizeof (const char*); | 47 | static int max_device_nr = sizeof device_label / sizeof (const char*); |
44 | 48 | ||
45 | using namespace Opie::Core; | ||
46 | using namespace Opie::MM; | ||
47 | /*====================================================================================== | 49 | /*====================================================================================== |
48 | * OSoundSystem | 50 | * OSoundSystem |
49 | *======================================================================================*/ | 51 | *======================================================================================*/ |
50 | 52 | ||
51 | OSoundSystem* OSoundSystem::_instance = 0; | 53 | OSoundSystem* OSoundSystem::_instance = 0; |
52 | 54 | ||
53 | OSoundSystem::OSoundSystem() | 55 | OSoundSystem::OSoundSystem() |
54 | { | 56 | { |
55 | odebug << "OSoundSystem::OSoundSystem()" << oendl; | 57 | odebug << "OSoundSystem::OSoundSystem()" << oendl; |
56 | synchronize(); | 58 | synchronize(); |
57 | } | 59 | } |
58 | 60 | ||
59 | void OSoundSystem::synchronize() | 61 | void OSoundSystem::synchronize() |
60 | { | 62 | { |
61 | _interfaces.clear(); | 63 | _interfaces.clear(); |
62 | _interfaces.insert( "soundcard", new OSoundCard( this, "soundcard" ) ); | 64 | _interfaces.insert( "soundcard", new OSoundCard( this, "soundcard" ) ); |
63 | 65 | ||
64 | /* | 66 | /* |
65 | 67 | ||
66 | QString str; | 68 | QString str; |
67 | QFile f( "/dev/sound" ); | 69 | QFile f( "/dev/sound" ); |
68 | bool hasFile = f.open( IO_ReadOnly ); | 70 | bool hasFile = f.open( IO_ReadOnly ); |
69 | if ( !hasFile ) | 71 | if ( !hasFile ) |
70 | { | 72 | { |
71 | odebug << "OSoundSystem: /dev/sound not existing. No sound devices available" << oendl; | 73 | odebug << "OSoundSystem: /dev/sound not existing. No sound devices available" << oendl; |
72 | return; | 74 | return; |
73 | } | 75 | } |
74 | QTextStream s( &f ); | 76 | QTextStream s( &f ); |
75 | s.readLine(); | 77 | s.readLine(); |
76 | s.readLine(); | 78 | s.readLine(); |
77 | while ( !s.atEnd() ) | 79 | while ( !s.atEnd() ) |
78 | { | 80 | { |
79 | s >> str; | 81 | s >> str; |
80 | str.truncate( str.find( ':' ) ); | 82 | str.truncate( str.find( ':' ) ); |
81 | odebug << "OSoundSystem: found interface '" << str << "'" << oendl; | 83 | odebug << "OSoundSystem: found interface '" << str << "'" << oendl; |
82 | OAudioInterface* iface; | 84 | OAudioInterface* iface; |
83 | iface = new OAudioInterface( this, (const char*) str ); | 85 | iface = new OAudioInterface( this, (const char*) str ); |
84 | 86 | ||
85 | _interfaces.insert( str, iface ); | 87 | _interfaces.insert( str, iface ); |
86 | s.readLine(); | 88 | s.readLine(); |
87 | } | 89 | } |
88 | */ | 90 | */ |
89 | } | 91 | } |
90 | 92 | ||
91 | 93 | ||
92 | int OSoundSystem::count() const | 94 | int OSoundSystem::count() const |
93 | { | 95 | { |
94 | return _interfaces.count(); | 96 | return _interfaces.count(); |
95 | } | 97 | } |
96 | 98 | ||
97 | 99 | ||
98 | OSoundCard* OSoundSystem::card( const QString& iface ) const | 100 | OSoundCard* OSoundSystem::card( const QString& iface ) const |
99 | { | 101 | { |
100 | return _interfaces[iface]; | 102 | return _interfaces[iface]; |
101 | } | 103 | } |
102 | 104 | ||
103 | 105 | ||
104 | OSoundSystem* OSoundSystem::instance() | 106 | OSoundSystem* OSoundSystem::instance() |
105 | { | 107 | { |
106 | if ( !_instance ) _instance = new OSoundSystem(); | 108 | if ( !_instance ) _instance = new OSoundSystem(); |
107 | return _instance; | 109 | return _instance; |
108 | } | 110 | } |
109 | 111 | ||
110 | 112 | ||
111 | OSoundSystem::CardIterator OSoundSystem::iterator() const | 113 | OSoundSystem::CardIterator OSoundSystem::iterator() const |
112 | { | 114 | { |
113 | return OSoundSystem::CardIterator( _interfaces ); | 115 | return OSoundSystem::CardIterator( _interfaces ); |
114 | } | 116 | } |
115 | 117 | ||
116 | 118 | ||
117 | /*====================================================================================== | 119 | /*====================================================================================== |
118 | * OSoundCard | 120 | * OSoundCard |
119 | *======================================================================================*/ | 121 | *======================================================================================*/ |
120 | 122 | ||
121 | OSoundCard::OSoundCard( QObject* parent, const char* name ) | 123 | OSoundCard::OSoundCard( QObject* parent, const char* name ) |
122 | :QObject( parent, name ), _audio( 0 ), _mixer( 0 ) | 124 | :QObject( parent, name ), _audio( 0 ), _mixer( 0 ) |
123 | { | 125 | { |
124 | odebug << "OSoundCard::OSoundCard()" << oendl; | 126 | odebug << "OSoundCard::OSoundCard()" << oendl; |
125 | init(); | 127 | init(); |
126 | } | 128 | } |
127 | 129 | ||
128 | 130 | ||
129 | OSoundCard::~OSoundCard() | 131 | OSoundCard::~OSoundCard() |
130 | { | 132 | { |
131 | } | 133 | } |
132 | 134 | ||
133 | 135 | ||
134 | void OSoundCard::init() | 136 | void OSoundCard::init() |
135 | { | 137 | { |
136 | #ifdef QT_QWS_DEVFS | 138 | #ifdef QT_QWS_DEVFS |
137 | _audio = new OAudioInterface( this, "/dev/sound/dsp" ); | 139 | _audio = new OAudioInterface( this, "/dev/sound/dsp" ); |
138 | _mixer = new OMixerInterface( this, "/dev/sound/mixer" ); | 140 | _mixer = new OMixerInterface( this, "/dev/sound/mixer" ); |
139 | #else | 141 | #else |
140 | _audio = new OAudioInterface( this, "/dev/dsp" ); | 142 | _audio = new OAudioInterface( this, "/dev/dsp" ); |
141 | _mixer = new OMixerInterface( this, "/dev/mixer" ); | 143 | _mixer = new OMixerInterface( this, "/dev/mixer" ); |
142 | #endif | 144 | #endif |
143 | } | 145 | } |
144 | 146 | ||
145 | 147 | ||
146 | /*====================================================================================== | 148 | /*====================================================================================== |
147 | * OAudioInterface | 149 | * OAudioInterface |
148 | *======================================================================================*/ | 150 | *======================================================================================*/ |
149 | 151 | ||
150 | OAudioInterface::OAudioInterface( QObject* parent, const char* name ) | 152 | OAudioInterface::OAudioInterface( QObject* parent, const char* name ) |
151 | :QObject( parent, name ), _sfd(0) | 153 | :QObject( parent, name ), _sfd(0) |
152 | { | 154 | { |
153 | odebug << "OAudioInterface::OAudioInterface()" << oendl; | 155 | odebug << "OAudioInterface::OAudioInterface()" << oendl; |
154 | init(); | 156 | init(); |
155 | } | 157 | } |
156 | 158 | ||
157 | 159 | ||
158 | OAudioInterface::~OAudioInterface() | 160 | OAudioInterface::~OAudioInterface() |
159 | { | 161 | { |
160 | } | 162 | } |
161 | 163 | ||
162 | 164 | ||
163 | void OAudioInterface::init() | 165 | void OAudioInterface::init() |
164 | { | 166 | { |
165 | 167 | ||
166 | 168 | ||
167 | } | 169 | } |
168 | 170 | ||
169 | 171 | ||
170 | /*====================================================================================== | 172 | /*====================================================================================== |
171 | * OMixerInterface | 173 | * OMixerInterface |
172 | *======================================================================================*/ | 174 | *======================================================================================*/ |
173 | 175 | ||
174 | OMixerInterface::OMixerInterface( QObject* parent, const char* name ) | 176 | OMixerInterface::OMixerInterface( QObject* parent, const char* name ) |
175 | :QObject( parent, name ), _devmask( 0 ), _recmask( 0 ), _stmask( 0 ) | 177 | :QObject( parent, name ), _devmask( 0 ), _recmask( 0 ), _stmask( 0 ) |
176 | { | 178 | { |
177 | odebug << "OMixerInterface::OMixerInterface()" << oendl; | 179 | odebug << "OMixerInterface::OMixerInterface()" << oendl; |
178 | init(); | 180 | init(); |
179 | } | 181 | } |
180 | 182 | ||
181 | 183 | ||
182 | OMixerInterface::~OMixerInterface() | 184 | OMixerInterface::~OMixerInterface() |
183 | { | 185 | { |
184 | } | 186 | } |
185 | 187 | ||
186 | 188 | ||
187 | void OMixerInterface::init() | 189 | void OMixerInterface::init() |
188 | { | 190 | { |
189 | // open the device | 191 | // open the device |
190 | _fd = ::open( name(), O_RDWR ); | 192 | _fd = ::open( name(), O_RDWR ); |
191 | if ( _fd == -1 ) | 193 | if ( _fd == -1 ) |
192 | { | 194 | { |
193 | owarn << "OMixerInterface::init(): Can't open mixer " << name() << oendl; | 195 | owarn << "OMixerInterface::init(): Can't open mixer " << name() << oendl; |
194 | return; | 196 | return; |
195 | } | 197 | } |
196 | 198 | ||
197 | // construct the device capabilities | 199 | // construct the device capabilities |
198 | if ( ioctl( _fd, SOUND_MIXER_READ_CAPS, &_capmask ) != -1 ) | 200 | if ( ioctl( _fd, SOUND_MIXER_READ_CAPS, &_capmask ) != -1 ) |
199 | { | 201 | { |
200 | odebug << "OMixerInterface::init() - capmask = " << _capmask << oendl; | 202 | odebug << "OMixerInterface::init() - capmask = " << _capmask << oendl; |
201 | } | 203 | } |
202 | if ( ioctl( _fd, SOUND_MIXER_READ_DEVMASK, &_devmask ) != -1 ) | 204 | if ( ioctl( _fd, SOUND_MIXER_READ_DEVMASK, &_devmask ) != -1 ) |
203 | { | 205 | { |
204 | odebug << "OMixerInterface::init() - devmask = " << _devmask << oendl; | 206 | odebug << "OMixerInterface::init() - devmask = " << _devmask << oendl; |
205 | } | 207 | } |
206 | if ( ioctl( _fd, SOUND_MIXER_READ_RECMASK, &_recmask ) != -1 ) | 208 | if ( ioctl( _fd, SOUND_MIXER_READ_RECMASK, &_recmask ) != -1 ) |
207 | { | 209 | { |
208 | odebug << "OMixerInterface::init() - recmask = " << _recmask << oendl; | 210 | odebug << "OMixerInterface::init() - recmask = " << _recmask << oendl; |
209 | } | 211 | } |
210 | if ( ioctl( _fd, SOUND_MIXER_READ_STEREODEVS, &_stmask ) != -1 ) | 212 | if ( ioctl( _fd, SOUND_MIXER_READ_STEREODEVS, &_stmask ) != -1 ) |
211 | { | 213 | { |
212 | odebug << "OMixerInterface::init() - stereomask = " << _stmask << oendl; | 214 | odebug << "OMixerInterface::init() - stereomask = " << _stmask << oendl; |
213 | } | 215 | } |
214 | for ( int i = 0; i < max_device_nr; ++i ) | 216 | for ( int i = 0; i < max_device_nr; ++i ) |
215 | { | 217 | { |
216 | if ( _devmask & ( 1 << i ) ) | 218 | if ( _devmask & ( 1 << i ) ) |
217 | { | 219 | { |
218 | _channels.insert( QString( device_label[i] ).stripWhiteSpace(), i ); | 220 | _channels.insert( QString( device_label[i] ).stripWhiteSpace(), i ); |
219 | odebug << "OMixerInterface::init() - channel '" << device_label[i] << "'" << oendl; | 221 | odebug << "OMixerInterface::init() - channel '" << device_label[i] << "'" << oendl; |
220 | } | 222 | } |
221 | } | 223 | } |
222 | } | 224 | } |
223 | 225 | ||
224 | 226 | ||
225 | QStringList OMixerInterface::allChannels() const | 227 | QStringList OMixerInterface::allChannels() const |
226 | { | 228 | { |
227 | ChannelIterator it = _channels.begin(); | 229 | ChannelIterator it = _channels.begin(); |
228 | QStringList channels; | 230 | QStringList channels; |
229 | while ( it != _channels.end() ) | 231 | while ( it != _channels.end() ) |
230 | { | 232 | { |
231 | channels += it++.key(); | 233 | channels += it++.key(); |
232 | } | 234 | } |
233 | return channels; | 235 | return channels; |
234 | } | 236 | } |
235 | 237 | ||
236 | 238 | ||
237 | QStringList OMixerInterface::recChannels() const | 239 | QStringList OMixerInterface::recChannels() const |
238 | { | 240 | { |
239 | ChannelIterator it = _channels.begin(); | 241 | ChannelIterator it = _channels.begin(); |
240 | QStringList channels; | 242 | QStringList channels; |
241 | while ( it != _channels.end() ) | 243 | while ( it != _channels.end() ) |
242 | { | 244 | { |
243 | if ( _recmask & ( 1 << _channels[it.key()] ) ) channels += it++.key(); | 245 | if ( _recmask & ( 1 << _channels[it.key()] ) ) channels += it++.key(); |
244 | } | 246 | } |
245 | return channels; | 247 | return channels; |
246 | } | 248 | } |
247 | 249 | ||
248 | 250 | ||
249 | QStringList OMixerInterface::playChannels() const | 251 | QStringList OMixerInterface::playChannels() const |
250 | { | 252 | { |
251 | return allChannels(); | 253 | return allChannels(); |
252 | } | 254 | } |
253 | 255 | ||
254 | 256 | ||
255 | bool OMixerInterface::hasMultipleRecording() const | 257 | bool OMixerInterface::hasMultipleRecording() const |
256 | { | 258 | { |
257 | return !( _capmask & SOUND_CAP_EXCL_INPUT ); | 259 | return !( _capmask & SOUND_CAP_EXCL_INPUT ); |
258 | } | 260 | } |
259 | 261 | ||
260 | 262 | ||
261 | bool OMixerInterface::hasChannel( const QString& channel ) const | 263 | bool OMixerInterface::hasChannel( const QString& channel ) const |
262 | { | 264 | { |
263 | return _channels.contains( channel ); | 265 | return _channels.contains( channel ); |
264 | } | 266 | } |
265 | 267 | ||
266 | 268 | ||
267 | bool OMixerInterface::isStereo( const QString& channel ) const | 269 | bool OMixerInterface::isStereo( const QString& channel ) const |
268 | { | 270 | { |
269 | return _channels.contains( channel ) && ( _stmask & ( 1 << _channels[channel] ) ); | 271 | return _channels.contains( channel ) && ( _stmask & ( 1 << _channels[channel] ) ); |
270 | } | 272 | } |
271 | 273 | ||
272 | 274 | ||
273 | bool OMixerInterface::isRecordable( const QString& channel ) const | 275 | bool OMixerInterface::isRecordable( const QString& channel ) const |
274 | { | 276 | { |
275 | return _channels.contains( channel ) && ( _recmask & ( 1 << _channels[channel] ) ); | 277 | return _channels.contains( channel ) && ( _recmask & ( 1 << _channels[channel] ) ); |
276 | } | 278 | } |
277 | 279 | ||
278 | 280 | ||
279 | void OMixerInterface::setVolume( const QString& channel, int left, int right ) | 281 | void OMixerInterface::setVolume( const QString& channel, int left, int right ) |
280 | { | 282 | { |
281 | int volume = left; | 283 | int volume = left; |
282 | volume |= ( right == -1 ) ? left << 8 : right << 8; | 284 | volume |= ( right == -1 ) ? left << 8 : right << 8; |
283 | 285 | ||
284 | if ( _channels.contains( channel ) ) | 286 | if ( _channels.contains( channel ) ) |
285 | { | 287 | { |
286 | int result = ioctl( _fd, MIXER_WRITE( _channels[channel] ), &volume ); | 288 | int result = ioctl( _fd, MIXER_WRITE( _channels[channel] ), &volume ); |
287 | if ( result == -1 ) | 289 | if ( result == -1 ) |
288 | { | 290 | { |
289 | owarn << "Can't set volume: " << strerror( errno ) << oendl; | 291 | owarn << "Can't set volume: " << strerror( errno ) << oendl; |
290 | } | 292 | } |
291 | else | 293 | else |
292 | { | 294 | { |
293 | if ( result & 0xff != left ) | 295 | if ( result & 0xff != left ) |
294 | { | 296 | { |
295 | owarn << "Device adjusted volume from " << left << " to " << (result & 0xff) << oendl; | 297 | owarn << "Device adjusted volume from " << left << " to " << (result & 0xff) << oendl; |
296 | } | 298 | } |
297 | } | 299 | } |
298 | } | 300 | } |
299 | } | 301 | } |
300 | 302 | ||
301 | 303 | ||
302 | int OMixerInterface::volume( const QString& channel ) const | 304 | int OMixerInterface::volume( const QString& channel ) const |
303 | { | 305 | { |
304 | int volume; | 306 | int volume; |
305 | 307 | ||
306 | if ( _channels.contains( channel ) ) | 308 | if ( _channels.contains( channel ) ) |
307 | { | 309 | { |
308 | if ( ioctl( _fd, MIXER_READ( _channels[channel] ), &volume ) == -1 ) | 310 | if ( ioctl( _fd, MIXER_READ( _channels[channel] ), &volume ) == -1 ) |
309 | { | 311 | { |
310 | owarn << "Can't get volume: " << strerror( errno ) << oendl; | 312 | owarn << "Can't get volume: " << strerror( errno ) << oendl; |
311 | } | 313 | } |
312 | else return volume; | 314 | else return volume; |
313 | } | 315 | } |
314 | return -1; | 316 | return -1; |
315 | } | 317 | } |
diff --git a/libopie2/opiemm/osoundsystem.h b/libopie2/opiemm/osoundsystem.h index 5f6fb7a..1e48f5c 100644 --- a/libopie2/opiemm/osoundsystem.h +++ b/libopie2/opiemm/osoundsystem.h | |||
@@ -1,245 +1,244 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | (C) 2003-2005 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | =. (C) 2003-2005 Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | =. | ||
5 | .=l. | 4 | .=l. |
6 | .>+-= | 5 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 6 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; version 2 of the License. |
12 | ._= =} : or (at your option) any later version. | 11 | ._= =} : |
13 | .%`+i> _;_. | 12 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 13 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 18 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 19 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 20 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 21 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 22 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 23 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 24 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 25 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
28 | 27 | ||
29 | */ | 28 | */ |
30 | 29 | ||
31 | #ifndef OSOUNDSYSTEM_H | 30 | #ifndef OSOUNDSYSTEM_H |
32 | #define OSOUNDSYSTEM_H | 31 | #define OSOUNDSYSTEM_H |
33 | 32 | ||
34 | #include <qobject.h> | 33 | #include <qobject.h> |
35 | #include <qdict.h> | 34 | #include <qdict.h> |
36 | #include <qmap.h> | 35 | #include <qmap.h> |
37 | 36 | ||
38 | namespace Opie { | 37 | namespace Opie { |
39 | namespace MM { | 38 | namespace MM { |
40 | 39 | ||
41 | class OAudioInterface; | 40 | class OAudioInterface; |
42 | class OMixerInterface; | 41 | class OMixerInterface; |
43 | class OSoundCard; | 42 | class OSoundCard; |
44 | 43 | ||
45 | /*====================================================================================== | 44 | /*====================================================================================== |
46 | * OSoundSystem | 45 | * OSoundSystem |
47 | *======================================================================================*/ | 46 | *======================================================================================*/ |
48 | 47 | ||
49 | /** | 48 | /** |
50 | * @brief A container class for all audio interfaces | 49 | * @brief A container class for the Linux OSS/ALSA audio subsystem |
51 | * | 50 | * |
52 | * This class provides access to all available audio/midi/sequencer interfaces of your computer. | 51 | * This class provides access to all available audio/midi/sequencer interfaces of your device. |
53 | * | 52 | * |
54 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 53 | * @author Michael 'Mickey' Lauer <mickey@Vanille.de> |
55 | */ | 54 | */ |
56 | class OSoundSystem : public QObject | 55 | class OSoundSystem : public QObject |
57 | { | 56 | { |
58 | Q_OBJECT | 57 | Q_OBJECT |
59 | 58 | ||
60 | public: | 59 | public: |
61 | typedef QDict<OSoundCard> CardMap; | 60 | typedef QDict<OSoundCard> CardMap; |
62 | typedef QDictIterator<OSoundCard> CardIterator; | 61 | typedef QDictIterator<OSoundCard> CardIterator; |
63 | 62 | ||
64 | public: | 63 | public: |
65 | /** | 64 | /** |
66 | * @returns the number of available interfaces | 65 | * @returns the number of available interfaces |
67 | */ | 66 | */ |
68 | int count() const; | 67 | int count() const; |
69 | /** | 68 | /** |
70 | * @returns a pointer to the (one and only) @ref OSystem instance. | 69 | * @returns a pointer to the (one and only) @ref OSystem instance. |
71 | */ | 70 | */ |
72 | static OSoundSystem* instance(); | 71 | static OSoundSystem* instance(); |
73 | /** | 72 | /** |
74 | * @returns an iterator usable for iterating through all sound cards. | 73 | * @returns an iterator usable for iterating through all sound cards. |
75 | */ | 74 | */ |
76 | CardIterator iterator() const; | 75 | CardIterator iterator() const; |
77 | /** | 76 | /** |
78 | * @returns a pointer to the @ref OAudioInterface object for the specified @a interface or 0, if not found | 77 | * @returns a pointer to the @ref OAudioInterface object for the specified @a interface or 0, if not found |
79 | * @see OAudioInterface | 78 | * @see OAudioInterface |
80 | */ | 79 | */ |
81 | OSoundCard* card( const QString& interface ) const; | 80 | OSoundCard* card( const QString& interface ) const; |
82 | /** | 81 | /** |
83 | * @internal Rebuild the internal interface database | 82 | * @internal Rebuild the internal interface database |
84 | * @note Sometimes it might be useful to call this from client code, | 83 | * @note Sometimes it might be useful to call this from client code, |
85 | * e.g. after issuing a cardctl insert | 84 | * e.g. after issuing a cardctl insert |
86 | */ | 85 | */ |
87 | void synchronize(); | 86 | void synchronize(); |
88 | 87 | ||
89 | protected: | 88 | protected: |
90 | OSoundSystem(); | 89 | OSoundSystem(); |
91 | 90 | ||
92 | private: | 91 | private: |
93 | static OSoundSystem* _instance; | 92 | static OSoundSystem* _instance; |
94 | CardMap _interfaces; | 93 | CardMap _interfaces; |
95 | class Private; | 94 | class Private; |
96 | Private *d; | 95 | Private *d; |
97 | }; | 96 | }; |
98 | 97 | ||
99 | 98 | ||
100 | /*====================================================================================== | 99 | /*====================================================================================== |
101 | * OSoundCard | 100 | * OSoundCard |
102 | *======================================================================================*/ | 101 | *======================================================================================*/ |
103 | 102 | ||
104 | class OSoundCard : public QObject | 103 | class OSoundCard : public QObject |
105 | { | 104 | { |
106 | Q_OBJECT | 105 | Q_OBJECT |
107 | 106 | ||
108 | public: | 107 | public: |
109 | /** | 108 | /** |
110 | * Constructor. Normally you don't create @ref OSoundCard objects yourself, | 109 | * Constructor. Normally you don't create @ref OSoundCard objects yourself, |
111 | * but access them via @ref OSoundSystem::card(). | 110 | * but access them via @ref OSoundSystem::card(). |
112 | */ | 111 | */ |
113 | OSoundCard( QObject* parent, const char* name ); | 112 | OSoundCard( QObject* parent, const char* name ); |
114 | /** | 113 | /** |
115 | * Destructor. | 114 | * Destructor. |
116 | */ | 115 | */ |
117 | virtual ~OSoundCard(); | 116 | virtual ~OSoundCard(); |
118 | 117 | ||
119 | bool hasMixer() const { return _audio; }; | 118 | bool hasMixer() const { return _audio; }; |
120 | bool hasAudio() const { return _mixer; }; | 119 | bool hasAudio() const { return _mixer; }; |
121 | 120 | ||
122 | OAudioInterface* audio() const { return _audio; }; | 121 | OAudioInterface* audio() const { return _audio; }; |
123 | OMixerInterface* mixer() const { return _mixer; }; | 122 | OMixerInterface* mixer() const { return _mixer; }; |
124 | 123 | ||
125 | protected: | 124 | protected: |
126 | OAudioInterface* _audio; | 125 | OAudioInterface* _audio; |
127 | OMixerInterface* _mixer; | 126 | OMixerInterface* _mixer; |
128 | 127 | ||
129 | private: | 128 | private: |
130 | void init(); | 129 | void init(); |
131 | private: | 130 | private: |
132 | class Private; | 131 | class Private; |
133 | Private *d; | 132 | Private *d; |
134 | }; | 133 | }; |
135 | 134 | ||
136 | /*====================================================================================== | 135 | /*====================================================================================== |
137 | * OAudioInterface | 136 | * OAudioInterface |
138 | *======================================================================================*/ | 137 | *======================================================================================*/ |
139 | 138 | ||
140 | class OAudioInterface : public QObject | 139 | class OAudioInterface : public QObject |
141 | { | 140 | { |
142 | Q_OBJECT | 141 | Q_OBJECT |
143 | 142 | ||
144 | public: | 143 | public: |
145 | /** | 144 | /** |
146 | * Constructor. Normally you don't create @ref OAudioInterface objects yourself, | 145 | * Constructor. Normally you don't create @ref OAudioInterface objects yourself, |
147 | * but access them via the @ref OSoundCard interface. | 146 | * but access them via the @ref OSoundCard interface. |
148 | */ | 147 | */ |
149 | OAudioInterface( QObject* parent, const char* name ); | 148 | OAudioInterface( QObject* parent, const char* name ); |
150 | /** | 149 | /** |
151 | * Destructor. | 150 | * Destructor. |
152 | */ | 151 | */ |
153 | virtual ~OAudioInterface(); | 152 | virtual ~OAudioInterface(); |
154 | 153 | ||
155 | protected: | 154 | protected: |
156 | const int _sfd; | 155 | const int _sfd; |
157 | 156 | ||
158 | private: | 157 | private: |
159 | void init(); | 158 | void init(); |
160 | private: | 159 | private: |
161 | class Private; | 160 | class Private; |
162 | Private *d; | 161 | Private *d; |
163 | }; | 162 | }; |
164 | 163 | ||
165 | 164 | ||
166 | /*====================================================================================== | 165 | /*====================================================================================== |
167 | * OMixerInterface | 166 | * OMixerInterface |
168 | *======================================================================================*/ | 167 | *======================================================================================*/ |
169 | 168 | ||
170 | class OMixerInterface : public QObject | 169 | class OMixerInterface : public QObject |
171 | { | 170 | { |
172 | Q_OBJECT | 171 | Q_OBJECT |
173 | 172 | ||
174 | public: | 173 | public: |
175 | 174 | ||
176 | typedef QMap<QString,int>::ConstIterator ChannelIterator; | 175 | typedef QMap<QString,int>::ConstIterator ChannelIterator; |
177 | 176 | ||
178 | /** | 177 | /** |
179 | * Constructor. Normally you don't create @ref OMixerInterface objects yourself, | 178 | * Constructor. Normally you don't create @ref OMixerInterface objects yourself, |
180 | * but access them via the @ref OSoundCard interface. | 179 | * but access them via the @ref OSoundCard interface. |
181 | */ | 180 | */ |
182 | OMixerInterface( QObject* parent, const char* name ); | 181 | OMixerInterface( QObject* parent, const char* name ); |
183 | /** | 182 | /** |
184 | * Destructor. | 183 | * Destructor. |
185 | */ | 184 | */ |
186 | virtual ~OMixerInterface(); | 185 | virtual ~OMixerInterface(); |
187 | 186 | ||
188 | /** | 187 | /** |
189 | * @returns all available channels. | 188 | * @returns all available channels. |
190 | */ | 189 | */ |
191 | QStringList allChannels() const; | 190 | QStringList allChannels() const; |
192 | /** | 191 | /** |
193 | * @returns recordable channels. | 192 | * @returns recordable channels. |
194 | */ | 193 | */ |
195 | QStringList recChannels() const; | 194 | QStringList recChannels() const; |
196 | /** | 195 | /** |
197 | * @returns playable channels. | 196 | * @returns playable channels. |
198 | */ | 197 | */ |
199 | QStringList playChannels() const; | 198 | QStringList playChannels() const; |
200 | /** | 199 | /** |
201 | * @returns true, if the device features multiple recording sources. | 200 | * @returns true, if the device features multiple recording sources. |
202 | */ | 201 | */ |
203 | bool hasMultipleRecording() const; | 202 | bool hasMultipleRecording() const; |
204 | /** | 203 | /** |
205 | * @returns true, if @a channel exists. | 204 | * @returns true, if @a channel exists. |
206 | */ | 205 | */ |
207 | bool hasChannel( const QString& channel ) const; | 206 | bool hasChannel( const QString& channel ) const; |
208 | /** | 207 | /** |
209 | * @returns true, if @a channel is stereo. | 208 | * @returns true, if @a channel is stereo. |
210 | */ | 209 | */ |
211 | bool isStereo( const QString& channel ) const; | 210 | bool isStereo( const QString& channel ) const; |
212 | /** | 211 | /** |
213 | * @returns tru, if @a channel is a possible recording source. | 212 | * @returns tru, if @a channel is a possible recording source. |
214 | */ | 213 | */ |
215 | bool isRecordable( const QString& channel ) const; | 214 | bool isRecordable( const QString& channel ) const; |
216 | /** | 215 | /** |
217 | * Set the @a left and @a right volumes for @a channel. | 216 | * Set the @a left and @a right volumes for @a channel. |
218 | * If no value for right is given, the value for left is taken for that. | 217 | * If no value for right is given, the value for left is taken for that. |
219 | */ | 218 | */ |
220 | void setVolume( const QString& channel, int left, int right = -1 ); | 219 | void setVolume( const QString& channel, int left, int right = -1 ); |
221 | /** | 220 | /** |
222 | * @returns the volume of @a channel or -1, if the channel doesn't exist. | 221 | * @returns the volume of @a channel or -1, if the channel doesn't exist. |
223 | * @note You might want to use @ref hasChannel() to check if a channel exists. | 222 | * @note You might want to use @ref hasChannel() to check if a channel exists. |
224 | */ | 223 | */ |
225 | int volume( const QString& channel ) const; | 224 | int volume( const QString& channel ) const; |
226 | 225 | ||
227 | protected: | 226 | protected: |
228 | int _fd; | 227 | int _fd; |
229 | int _capmask; | 228 | int _capmask; |
230 | int _devmask; | 229 | int _devmask; |
231 | int _recmask; | 230 | int _recmask; |
232 | int _stmask; | 231 | int _stmask; |
233 | QMap<QString,int> _channels; | 232 | QMap<QString,int> _channels; |
234 | 233 | ||
235 | private: | 234 | private: |
236 | void init(); | 235 | void init(); |
237 | private: | 236 | private: |
238 | class Private; | 237 | class Private; |
239 | Private *d; | 238 | Private *d; |
240 | }; | 239 | }; |
241 | 240 | ||
242 | } | 241 | } |
243 | } | 242 | } |
244 | 243 | ||
245 | #endif // OSOUNDSYSTEM_H | 244 | #endif // OSOUNDSYSTEM_H |
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index eafbeea..c548356 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp | |||
@@ -1,1368 +1,1368 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003-2004 by Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | Copyright (C) 2003-2004 by Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; version 2 of the License. | 11 | - . .-<_> .<> Foundation; version 2 of the License. |
12 | ._= =} : | 12 | ._= =} : |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include "udp_ports.h" | 31 | #include "udp_ports.h" |
32 | #include "opcap.h" | 32 | #include "opcap.h" |
33 | 33 | ||
34 | /* OPIE */ | 34 | /* OPIE */ |
35 | #include <opie2/odebug.h> | 35 | #include <opie2/odebug.h> |
36 | using namespace Opie::Core; | 36 | using namespace Opie::Core; |
37 | 37 | ||
38 | /* QT */ | 38 | /* QT */ |
39 | #include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) | 39 | #include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) |
40 | #include <qsocketnotifier.h> | 40 | #include <qsocketnotifier.h> |
41 | #include <qobjectlist.h> | 41 | #include <qobjectlist.h> |
42 | 42 | ||
43 | /* STD */ | 43 | /* STD */ |
44 | #include <sys/time.h> | 44 | #include <sys/time.h> |
45 | #include <sys/types.h> | 45 | #include <sys/types.h> |
46 | #include <assert.h> | 46 | #include <assert.h> |
47 | #include <unistd.h> | 47 | #include <unistd.h> |
48 | #include <string.h> | 48 | #include <string.h> |
49 | 49 | ||
50 | namespace Opie { | 50 | namespace Opie { |
51 | namespace Net { | 51 | namespace Net { |
52 | 52 | ||
53 | /*====================================================================================== | 53 | /*====================================================================================== |
54 | * OPacket | 54 | * OPacket |
55 | *======================================================================================*/ | 55 | *======================================================================================*/ |
56 | 56 | ||
57 | OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) | 57 | OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) |
58 | :QObject( parent, "Generic" ), _hdr( header ), _data( 0 ) | 58 | :QObject( parent, "Generic" ), _hdr( header ), _data( 0 ) |
59 | { | 59 | { |
60 | 60 | ||
61 | _data = new unsigned char[ header.len ]; | 61 | _data = new unsigned char[ header.len ]; |
62 | assert( _data ); | 62 | assert( _data ); |
63 | memcpy( const_cast<unsigned char*>(_data), data, header.len ); | 63 | memcpy( const_cast<unsigned char*>(_data), data, header.len ); |
64 | // We have to copy the data structure here, because the 'data' pointer handed by libpcap | 64 | // We have to copy the data structure here, because the 'data' pointer handed by libpcap |
65 | // points to an internal region which is reused by lipcap. | 65 | // points to an internal region which is reused by lipcap. |
66 | odebug << "OPacket: Length = " << header.len << ", Caplen = " << header.caplen << oendl; | 66 | odebug << "OPacket: Length = " << header.len << ", Caplen = " << header.caplen << oendl; |
67 | _end = (unsigned char*) _data + header.len; | 67 | _end = (unsigned char*) _data + header.len; |
68 | 68 | ||
69 | switch ( datalink ) | 69 | switch ( datalink ) |
70 | { | 70 | { |
71 | case DLT_EN10MB: | 71 | case DLT_EN10MB: |
72 | odebug << "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" << oendl; | 72 | odebug << "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" << oendl; |
73 | new OEthernetPacket( _end, (const struct ether_header*) _data, this ); | 73 | new OEthernetPacket( _end, (const struct ether_header*) _data, this ); |
74 | break; | 74 | break; |
75 | 75 | ||
76 | case DLT_IEEE802_11: | 76 | case DLT_IEEE802_11: |
77 | odebug << "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" << oendl; | 77 | odebug << "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" << oendl; |
78 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) _data, this ); | 78 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) _data, this ); |
79 | break; | 79 | break; |
80 | 80 | ||
81 | case DLT_PRISM_HEADER: | 81 | case DLT_PRISM_HEADER: |
82 | odebug << "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" << oendl; | 82 | odebug << "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" << oendl; |
83 | new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) _data, this ); | 83 | new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) _data, this ); |
84 | break; | 84 | break; |
85 | 85 | ||
86 | default: | 86 | default: |
87 | owarn << "OPacket::OPacket(): Received Packet over unsupported datalink, type " << datalink << "!" << oendl; | 87 | owarn << "OPacket::OPacket(): Received Packet over unsupported datalink, type " << datalink << "!" << oendl; |
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
91 | 91 | ||
92 | OPacket::~OPacket() | 92 | OPacket::~OPacket() |
93 | { | 93 | { |
94 | odebug << "~OPacket( " << name() << " )" << oendl; | 94 | odebug << "~OPacket( " << name() << " )" << oendl; |
95 | delete [] _data; | 95 | delete [] _data; |
96 | } | 96 | } |
97 | 97 | ||
98 | 98 | ||
99 | timevalstruct OPacket::timeval() const | 99 | timevalstruct OPacket::timeval() const |
100 | { | 100 | { |
101 | return _hdr.ts; | 101 | return _hdr.ts; |
102 | } | 102 | } |
103 | 103 | ||
104 | 104 | ||
105 | int OPacket::caplen() const | 105 | int OPacket::caplen() const |
106 | { | 106 | { |
107 | return _hdr.caplen; | 107 | return _hdr.caplen; |
108 | } | 108 | } |
109 | 109 | ||
110 | 110 | ||
111 | void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) | 111 | void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) |
112 | { | 112 | { |
113 | if (!l) return; | 113 | if (!l) return; |
114 | QObject* o = l->first(); | 114 | QObject* o = l->first(); |
115 | while ( o ) | 115 | while ( o ) |
116 | { | 116 | { |
117 | stats[o->name()]++; | 117 | stats[o->name()]++; |
118 | updateStats( stats, const_cast<QObjectList*>( o->children() ) ); | 118 | updateStats( stats, const_cast<QObjectList*>( o->children() ) ); |
119 | o = l->next(); | 119 | o = l->next(); |
120 | } | 120 | } |
121 | } | 121 | } |
122 | 122 | ||
123 | 123 | ||
124 | QString OPacket::dumpStructure() const | 124 | QString OPacket::dumpStructure() const |
125 | { | 125 | { |
126 | return "[ |" + _dumpStructure( const_cast<QObjectList*>( this->children() ) ) + " ]"; | 126 | return "[ |" + _dumpStructure( const_cast<QObjectList*>( this->children() ) ) + " ]"; |
127 | } | 127 | } |
128 | 128 | ||
129 | 129 | ||
130 | QString OPacket::_dumpStructure( QObjectList* l ) const | 130 | QString OPacket::_dumpStructure( QObjectList* l ) const |
131 | { | 131 | { |
132 | if (!l) return QString::null; | 132 | if (!l) return QString::null; |
133 | QObject* o = l->first(); | 133 | QObject* o = l->first(); |
134 | QString str(" "); | 134 | QString str(" "); |
135 | 135 | ||
136 | while ( o ) | 136 | while ( o ) |
137 | { | 137 | { |
138 | str.append( o->name() ); | 138 | str.append( o->name() ); |
139 | str.append( " |" ); | 139 | str.append( " |" ); |
140 | str += _dumpStructure( const_cast<QObjectList*>( o->children() ) ); | 140 | str += _dumpStructure( const_cast<QObjectList*>( o->children() ) ); |
141 | o = l->next(); | 141 | o = l->next(); |
142 | } | 142 | } |
143 | return str; | 143 | return str; |
144 | } | 144 | } |
145 | 145 | ||
146 | QString OPacket::dump( int bpl ) const | 146 | QString OPacket::dump( int bpl ) const |
147 | { | 147 | { |
148 | static int index = 0; | 148 | static int index = 0; |
149 | index++; | 149 | index++; |
150 | int len = _hdr.caplen; | 150 | int len = _hdr.caplen; |
151 | QString str( "000:" ); | 151 | QString str( "000:" ); |
152 | QString tmp; | 152 | QString tmp; |
153 | QString bytes; | 153 | QString bytes; |
154 | QString chars; | 154 | QString chars; |
155 | 155 | ||
156 | for ( int i = 0; i < len; ++i ) | 156 | for ( int i = 0; i < len; ++i ) |
157 | { | 157 | { |
158 | tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); | 158 | tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); |
159 | if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); | 159 | if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); |
160 | else chars.append( '.' ); | 160 | else chars.append( '.' ); |
161 | 161 | ||
162 | if ( !((i+1) % bpl) ) | 162 | if ( !((i+1) % bpl) ) |
163 | { | 163 | { |
164 | str.append( bytes ); | 164 | str.append( bytes ); |
165 | str.append( ' ' ); | 165 | str.append( ' ' ); |
166 | str.append( chars ); | 166 | str.append( chars ); |
167 | str.append( '\n' ); | 167 | str.append( '\n' ); |
168 | tmp.sprintf( "%03X:", i+1 ); str.append( tmp ); | 168 | tmp.sprintf( "%03X:", i+1 ); str.append( tmp ); |
169 | bytes = ""; | 169 | bytes = ""; |
170 | chars = ""; | 170 | chars = ""; |
171 | } | 171 | } |
172 | 172 | ||
173 | } | 173 | } |
174 | if ( (len % bpl) ) | 174 | if ( (len % bpl) ) |
175 | { | 175 | { |
176 | str.append( bytes.leftJustify( 1 + 3*bpl ) ); | 176 | str.append( bytes.leftJustify( 1 + 3*bpl ) ); |
177 | str.append( chars ); | 177 | str.append( chars ); |
178 | } | 178 | } |
179 | str.append( '\n' ); | 179 | str.append( '\n' ); |
180 | return str; | 180 | return str; |
181 | } | 181 | } |
182 | 182 | ||
183 | 183 | ||
184 | int OPacket::len() const | 184 | int OPacket::len() const |
185 | { | 185 | { |
186 | return _hdr.len; | 186 | return _hdr.len; |
187 | } | 187 | } |
188 | 188 | ||
189 | 189 | ||
190 | QTextStream& operator<<( QTextStream& s, const OPacket& p ) | 190 | QTextStream& operator<<( QTextStream& s, const OPacket& p ) |
191 | { | 191 | { |
192 | s << p.dumpStructure(); | 192 | s << p.dumpStructure(); |
193 | return s; | 193 | return s; |
194 | } | 194 | } |
195 | 195 | ||
196 | 196 | ||
197 | /*====================================================================================== | 197 | /*====================================================================================== |
198 | * OEthernetPacket | 198 | * OEthernetPacket |
199 | *======================================================================================*/ | 199 | *======================================================================================*/ |
200 | 200 | ||
201 | OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) | 201 | OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) |
202 | :QObject( parent, "Ethernet" ), _ether( data ) | 202 | :QObject( parent, "Ethernet" ), _ether( data ) |
203 | { | 203 | { |
204 | 204 | ||
205 | odebug << "Source = " << sourceAddress().toString() << oendl; | 205 | odebug << "Source = " << sourceAddress().toString() << oendl; |
206 | odebug << "Destination = " << destinationAddress().toString() << oendl; | 206 | odebug << "Destination = " << destinationAddress().toString() << oendl; |
207 | 207 | ||
208 | if ( sourceAddress() == OMacAddress::broadcast ) | 208 | if ( sourceAddress() == OMacAddress::broadcast ) |
209 | odebug << "Source is broadcast address" << oendl; | 209 | odebug << "Source is broadcast address" << oendl; |
210 | if ( destinationAddress() == OMacAddress::broadcast ) | 210 | if ( destinationAddress() == OMacAddress::broadcast ) |
211 | odebug << "Destination is broadcast address" << oendl; | 211 | odebug << "Destination is broadcast address" << oendl; |
212 | 212 | ||
213 | switch ( type() ) | 213 | switch ( type() ) |
214 | { | 214 | { |
215 | case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; | 215 | case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; |
216 | case ETHERTYPE_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; | 216 | case ETHERTYPE_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; |
217 | case ETHERTYPE_REVARP: { odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" << oendl; break; } | 217 | case ETHERTYPE_REVARP: { odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" << oendl; break; } |
218 | default: odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" << oendl; | 218 | default: odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" << oendl; |
219 | } | 219 | } |
220 | 220 | ||
221 | } | 221 | } |
222 | 222 | ||
223 | 223 | ||
224 | OEthernetPacket::~OEthernetPacket() | 224 | OEthernetPacket::~OEthernetPacket() |
225 | { | 225 | { |
226 | } | 226 | } |
227 | 227 | ||
228 | 228 | ||
229 | OMacAddress OEthernetPacket::sourceAddress() const | 229 | OMacAddress OEthernetPacket::sourceAddress() const |
230 | { | 230 | { |
231 | return OMacAddress( _ether->ether_shost ); | 231 | return OMacAddress( _ether->ether_shost ); |
232 | } | 232 | } |
233 | 233 | ||
234 | 234 | ||
235 | OMacAddress OEthernetPacket::destinationAddress() const | 235 | OMacAddress OEthernetPacket::destinationAddress() const |
236 | { | 236 | { |
237 | return OMacAddress( _ether->ether_dhost ); | 237 | return OMacAddress( _ether->ether_dhost ); |
238 | } | 238 | } |
239 | 239 | ||
240 | int OEthernetPacket::type() const | 240 | int OEthernetPacket::type() const |
241 | { | 241 | { |
242 | return ntohs( _ether->ether_type ); | 242 | return ntohs( _ether->ether_type ); |
243 | } | 243 | } |
244 | 244 | ||
245 | 245 | ||
246 | /*====================================================================================== | 246 | /*====================================================================================== |
247 | * OIPPacket | 247 | * OIPPacket |
248 | *======================================================================================*/ | 248 | *======================================================================================*/ |
249 | 249 | ||
250 | 250 | ||
251 | OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) | 251 | OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) |
252 | :QObject( parent, "IP" ), _iphdr( data ) | 252 | :QObject( parent, "IP" ), _iphdr( data ) |
253 | { | 253 | { |
254 | odebug << "OIPPacket::OIPPacket(): decoding IP header..." << oendl; | 254 | odebug << "OIPPacket::OIPPacket(): decoding IP header..." << oendl; |
255 | 255 | ||
256 | odebug << "FromAddress = " << fromIPAddress().toString() << oendl; | 256 | odebug << "FromAddress = " << fromIPAddress().toString() << oendl; |
257 | odebug << " toAddress = " << toIPAddress().toString() << oendl; | 257 | odebug << " toAddress = " << toIPAddress().toString() << oendl; |
258 | 258 | ||
259 | switch ( protocol() ) | 259 | switch ( protocol() ) |
260 | { | 260 | { |
261 | case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; | 261 | case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; |
262 | case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; | 262 | case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; |
263 | default: odebug << "OIPPacket::OIPPacket(): unknown IP protocol, type = " << protocol() << oendl; | 263 | default: odebug << "OIPPacket::OIPPacket(): unknown IP protocol, type = " << protocol() << oendl; |
264 | } | 264 | } |
265 | 265 | ||
266 | } | 266 | } |
267 | 267 | ||
268 | OIPPacket::~OIPPacket() | 268 | OIPPacket::~OIPPacket() |
269 | { | 269 | { |
270 | } | 270 | } |
271 | 271 | ||
272 | 272 | ||
273 | QHostAddress OIPPacket::fromIPAddress() const | 273 | QHostAddress OIPPacket::fromIPAddress() const |
274 | { | 274 | { |
275 | return EXTRACT_32BITS( &_iphdr->saddr ); | 275 | return EXTRACT_32BITS( &_iphdr->saddr ); |
276 | } | 276 | } |
277 | 277 | ||
278 | 278 | ||
279 | QHostAddress OIPPacket::toIPAddress() const | 279 | QHostAddress OIPPacket::toIPAddress() const |
280 | { | 280 | { |
281 | return EXTRACT_32BITS( &_iphdr->saddr ); | 281 | return EXTRACT_32BITS( &_iphdr->saddr ); |
282 | } | 282 | } |
283 | 283 | ||
284 | 284 | ||
285 | int OIPPacket::tos() const | 285 | int OIPPacket::tos() const |
286 | { | 286 | { |
287 | return _iphdr->tos; | 287 | return _iphdr->tos; |
288 | } | 288 | } |
289 | 289 | ||
290 | 290 | ||
291 | int OIPPacket::len() const | 291 | int OIPPacket::len() const |
292 | { | 292 | { |
293 | return EXTRACT_16BITS( &_iphdr->tot_len ); | 293 | return EXTRACT_16BITS( &_iphdr->tot_len ); |
294 | } | 294 | } |
295 | 295 | ||
296 | 296 | ||
297 | int OIPPacket::id() const | 297 | int OIPPacket::id() const |
298 | { | 298 | { |
299 | return EXTRACT_16BITS( &_iphdr->id ); | 299 | return EXTRACT_16BITS( &_iphdr->id ); |
300 | } | 300 | } |
301 | 301 | ||
302 | 302 | ||
303 | int OIPPacket::offset() const | 303 | int OIPPacket::offset() const |
304 | { | 304 | { |
305 | return EXTRACT_16BITS( &_iphdr->frag_off ); | 305 | return EXTRACT_16BITS( &_iphdr->frag_off ); |
306 | } | 306 | } |
307 | 307 | ||
308 | 308 | ||
309 | int OIPPacket::ttl() const | 309 | int OIPPacket::ttl() const |
310 | { | 310 | { |
311 | return _iphdr->ttl; | 311 | return _iphdr->ttl; |
312 | } | 312 | } |
313 | 313 | ||
314 | 314 | ||
315 | int OIPPacket::protocol() const | 315 | int OIPPacket::protocol() const |
316 | { | 316 | { |
317 | return _iphdr->protocol; | 317 | return _iphdr->protocol; |
318 | } | 318 | } |
319 | 319 | ||
320 | 320 | ||
321 | int OIPPacket::checksum() const | 321 | int OIPPacket::checksum() const |
322 | { | 322 | { |
323 | return EXTRACT_16BITS( &_iphdr->check ); | 323 | return EXTRACT_16BITS( &_iphdr->check ); |
324 | } | 324 | } |
325 | 325 | ||
326 | /*====================================================================================== | 326 | /*====================================================================================== |
327 | * OARPPacket | 327 | * OARPPacket |
328 | *======================================================================================*/ | 328 | *======================================================================================*/ |
329 | 329 | ||
330 | 330 | ||
331 | OARPPacket::OARPPacket( const unsigned char* /*end*/, const struct myarphdr* data, QObject* parent ) | 331 | OARPPacket::OARPPacket( const unsigned char* /*end*/, const struct myarphdr* data, QObject* parent ) |
332 | :QObject( parent, "ARP" ), _arphdr( data ) | 332 | :QObject( parent, "ARP" ), _arphdr( data ) |
333 | { | 333 | { |
334 | odebug << "OARPPacket::OARPPacket(): decoding ARP header..." << oendl; | 334 | odebug << "OARPPacket::OARPPacket(): decoding ARP header..." << oendl; |
335 | odebug << "ARP type seems to be " << EXTRACT_16BITS( &_arphdr->ar_op ) << " = " << type() << oendl; | 335 | odebug << "ARP type seems to be " << EXTRACT_16BITS( &_arphdr->ar_op ) << " = " << type() << oendl; |
336 | odebug << "Sender: MAC " << senderMacAddress().toString() << " = IP " << senderIPV4Address().toString() << oendl; | 336 | odebug << "Sender: MAC " << senderMacAddress().toString() << " = IP " << senderIPV4Address().toString() << oendl; |
337 | odebug << "Target: MAC " << targetMacAddress().toString() << " = IP " << targetIPV4Address().toString() << oendl; | 337 | odebug << "Target: MAC " << targetMacAddress().toString() << " = IP " << targetIPV4Address().toString() << oendl; |
338 | } | 338 | } |
339 | 339 | ||
340 | 340 | ||
341 | OARPPacket::~OARPPacket() | 341 | OARPPacket::~OARPPacket() |
342 | { | 342 | { |
343 | } | 343 | } |
344 | 344 | ||
345 | 345 | ||
346 | QString OARPPacket::type() const | 346 | QString OARPPacket::type() const |
347 | { | 347 | { |
348 | switch ( EXTRACT_16BITS( &_arphdr->ar_op ) ) | 348 | switch ( EXTRACT_16BITS( &_arphdr->ar_op ) ) |
349 | { | 349 | { |
350 | case 1: return "REQUEST"; | 350 | case 1: return "REQUEST"; |
351 | case 2: return "REPLY"; | 351 | case 2: return "REPLY"; |
352 | case 3: return "RREQUEST"; | 352 | case 3: return "RREQUEST"; |
353 | case 4: return "RREPLY"; | 353 | case 4: return "RREPLY"; |
354 | case 8: return "InREQUEST"; | 354 | case 8: return "InREQUEST"; |
355 | case 9: return "InREPLY"; | 355 | case 9: return "InREPLY"; |
356 | case 10: return "NAK"; | 356 | case 10: return "NAK"; |
357 | default: owarn << "OARPPacket::type(): invalid ARP type!" << oendl; return "<unknown>"; | 357 | default: owarn << "OARPPacket::type(): invalid ARP type!" << oendl; return "<unknown>"; |
358 | } | 358 | } |
359 | } | 359 | } |
360 | 360 | ||
361 | 361 | ||
362 | QHostAddress OARPPacket::senderIPV4Address() const | 362 | QHostAddress OARPPacket::senderIPV4Address() const |
363 | { | 363 | { |
364 | return EXTRACT_32BITS( &_arphdr->ar_sip ); | 364 | return EXTRACT_32BITS( &_arphdr->ar_sip ); |
365 | } | 365 | } |
366 | 366 | ||
367 | 367 | ||
368 | QHostAddress OARPPacket::targetIPV4Address() const | 368 | QHostAddress OARPPacket::targetIPV4Address() const |
369 | { | 369 | { |
370 | return EXTRACT_32BITS( &_arphdr->ar_tip ); | 370 | return EXTRACT_32BITS( &_arphdr->ar_tip ); |
371 | } | 371 | } |
372 | 372 | ||
373 | 373 | ||
374 | OMacAddress OARPPacket::senderMacAddress() const | 374 | OMacAddress OARPPacket::senderMacAddress() const |
375 | { | 375 | { |
376 | return OMacAddress( _arphdr->ar_sha ); | 376 | return OMacAddress( _arphdr->ar_sha ); |
377 | } | 377 | } |
378 | 378 | ||
379 | 379 | ||
380 | OMacAddress OARPPacket::targetMacAddress() const | 380 | OMacAddress OARPPacket::targetMacAddress() const |
381 | { | 381 | { |
382 | return OMacAddress( _arphdr->ar_tha ); | 382 | return OMacAddress( _arphdr->ar_tha ); |
383 | } | 383 | } |
384 | 384 | ||
385 | 385 | ||
386 | /*====================================================================================== | 386 | /*====================================================================================== |
387 | * OUDPPacket | 387 | * OUDPPacket |
388 | *======================================================================================*/ | 388 | *======================================================================================*/ |
389 | 389 | ||
390 | 390 | ||
391 | OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) | 391 | OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) |
392 | :QObject( parent, "UDP" ), _udphdr( data ) | 392 | :QObject( parent, "UDP" ), _udphdr( data ) |
393 | 393 | ||
394 | { | 394 | { |
395 | odebug << "OUDPPacket::OUDPPacket(): decoding UDP header..." << oendl; | 395 | odebug << "OUDPPacket::OUDPPacket(): decoding UDP header..." << oendl; |
396 | odebug << "fromPort = " << fromPort() << oendl; | 396 | odebug << "fromPort = " << fromPort() << oendl; |
397 | odebug << " toPort = " << toPort() << oendl; | 397 | odebug << " toPort = " << toPort() << oendl; |
398 | 398 | ||
399 | // TODO: Make this a case or a hash if we know more udp protocols | 399 | // TODO: Make this a case or a hash if we know more udp protocols |
400 | 400 | ||
401 | if ( fromPort() == UDP_PORT_BOOTPS || fromPort() == UDP_PORT_BOOTPC || | 401 | if ( fromPort() == UDP_PORT_BOOTPS || fromPort() == UDP_PORT_BOOTPC || |
402 | toPort() == UDP_PORT_BOOTPS || toPort() == UDP_PORT_BOOTPC ) | 402 | toPort() == UDP_PORT_BOOTPS || toPort() == UDP_PORT_BOOTPC ) |
403 | { | 403 | { |
404 | odebug << "seems to be part of a DHCP conversation => creating DHCP packet." << oendl; | 404 | odebug << "seems to be part of a DHCP conversation => creating DHCP packet." << oendl; |
405 | new ODHCPPacket( end, (const struct dhcp_packet*) (data+1), this ); | 405 | new ODHCPPacket( end, (const struct dhcp_packet*) (data+1), this ); |
406 | } | 406 | } |
407 | } | 407 | } |
408 | 408 | ||
409 | 409 | ||
410 | OUDPPacket::~OUDPPacket() | 410 | OUDPPacket::~OUDPPacket() |
411 | { | 411 | { |
412 | } | 412 | } |
413 | 413 | ||
414 | 414 | ||
415 | int OUDPPacket::fromPort() const | 415 | int OUDPPacket::fromPort() const |
416 | { | 416 | { |
417 | return EXTRACT_16BITS( &_udphdr->source ); | 417 | return EXTRACT_16BITS( &_udphdr->source ); |
418 | } | 418 | } |
419 | 419 | ||
420 | 420 | ||
421 | int OUDPPacket::toPort() const | 421 | int OUDPPacket::toPort() const |
422 | { | 422 | { |
423 | return EXTRACT_16BITS( &_udphdr->dest ); | 423 | return EXTRACT_16BITS( &_udphdr->dest ); |
424 | } | 424 | } |
425 | 425 | ||
426 | 426 | ||
427 | int OUDPPacket::length() const | 427 | int OUDPPacket::length() const |
428 | { | 428 | { |
429 | return EXTRACT_16BITS( &_udphdr->len ); | 429 | return EXTRACT_16BITS( &_udphdr->len ); |
430 | } | 430 | } |
431 | 431 | ||
432 | 432 | ||
433 | int OUDPPacket::checksum() const | 433 | int OUDPPacket::checksum() const |
434 | { | 434 | { |
435 | return EXTRACT_16BITS( &_udphdr->check ); | 435 | return EXTRACT_16BITS( &_udphdr->check ); |
436 | } | 436 | } |
437 | 437 | ||
438 | 438 | ||
439 | /*====================================================================================== | 439 | /*====================================================================================== |
440 | * ODHCPPacket | 440 | * ODHCPPacket |
441 | *======================================================================================*/ | 441 | *======================================================================================*/ |
442 | 442 | ||
443 | 443 | ||
444 | ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* data, QObject* parent ) | 444 | ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* data, QObject* parent ) |
445 | :QObject( parent, "DHCP" ), _dhcphdr( data ) | 445 | :QObject( parent, "DHCP" ), _dhcphdr( data ) |
446 | 446 | ||
447 | { | 447 | { |
448 | odebug << "ODHCPPacket::ODHCPPacket(): decoding DHCP information..." << oendl; | 448 | odebug << "ODHCPPacket::ODHCPPacket(): decoding DHCP information..." << oendl; |
449 | odebug << "DHCP opcode seems to be " << _dhcphdr->op << ": " << ( isRequest() ? "REQUEST" : "REPLY" ) << oendl; | 449 | odebug << "DHCP opcode seems to be " << _dhcphdr->op << ": " << ( isRequest() ? "REQUEST" : "REPLY" ) << oendl; |
450 | odebug << "clientAddress = " << clientAddress().toString() << oendl; | 450 | odebug << "clientAddress = " << clientAddress().toString() << oendl; |
451 | odebug << " yourAddress = " << yourAddress().toString() << oendl; | 451 | odebug << " yourAddress = " << yourAddress().toString() << oendl; |
452 | odebug << "serverAddress = " << serverAddress().toString() << oendl; | 452 | odebug << "serverAddress = " << serverAddress().toString() << oendl; |
453 | odebug << " relayAddress = " << relayAddress().toString() << oendl; | 453 | odebug << " relayAddress = " << relayAddress().toString() << oendl; |
454 | odebug << "parsing DHCP options..." << oendl; | 454 | odebug << "parsing DHCP options..." << oendl; |
455 | 455 | ||
456 | _type = 0; | 456 | _type = 0; |
457 | 457 | ||
458 | const unsigned char* option = &_dhcphdr->options[4]; | 458 | const unsigned char* option = &_dhcphdr->options[4]; |
459 | char tag = -1; | 459 | char tag = -1; |
460 | char len = -1; | 460 | char len = -1; |
461 | 461 | ||
462 | while ( ( tag = *option++ ) != -1 /* end of option field */ ) | 462 | while ( ( tag = *option++ ) != -1 /* end of option field */ ) |
463 | { | 463 | { |
464 | len = *option++; | 464 | len = *option++; |
465 | odebug << "recognized DHCP option #" << tag << ", length " << len << oendl; | 465 | odebug << "recognized DHCP option #" << tag << ", length " << len << oendl; |
466 | 466 | ||
467 | if ( tag == DHO_DHCP_MESSAGE_TYPE ) | 467 | if ( tag == DHO_DHCP_MESSAGE_TYPE ) |
468 | _type = *option; | 468 | _type = *option; |
469 | 469 | ||
470 | option += len; | 470 | option += len; |
471 | if ( option >= end ) | 471 | if ( option >= end ) |
472 | { | 472 | { |
473 | owarn << "DHCP parsing ERROR: sanity check says the packet is at its end!" << oendl; | 473 | owarn << "DHCP parsing ERROR: sanity check says the packet is at its end!" << oendl; |
474 | break; | 474 | break; |
475 | } | 475 | } |
476 | } | 476 | } |
477 | 477 | ||
478 | odebug << "DHCP type seems to be << " << type() << oendl; | 478 | odebug << "DHCP type seems to be << " << type() << oendl; |
479 | } | 479 | } |
480 | 480 | ||
481 | 481 | ||
482 | ODHCPPacket::~ODHCPPacket() | 482 | ODHCPPacket::~ODHCPPacket() |
483 | { | 483 | { |
484 | } | 484 | } |
485 | 485 | ||
486 | 486 | ||
487 | bool ODHCPPacket::isRequest() const | 487 | bool ODHCPPacket::isRequest() const |
488 | { | 488 | { |
489 | return ( _dhcphdr->op == 01 ); | 489 | return ( _dhcphdr->op == 01 ); |
490 | } | 490 | } |
491 | 491 | ||
492 | 492 | ||
493 | bool ODHCPPacket::isReply() const | 493 | bool ODHCPPacket::isReply() const |
494 | { | 494 | { |
495 | return ( _dhcphdr->op == 02 ); | 495 | return ( _dhcphdr->op == 02 ); |
496 | } | 496 | } |
497 | 497 | ||
498 | 498 | ||
499 | QString ODHCPPacket::type() const | 499 | QString ODHCPPacket::type() const |
500 | { | 500 | { |
501 | switch ( _type ) | 501 | switch ( _type ) |
502 | { | 502 | { |
503 | case 1: return "DISCOVER"; | 503 | case 1: return "DISCOVER"; |
504 | case 2: return "OFFER"; | 504 | case 2: return "OFFER"; |
505 | case 3: return "REQUEST"; | 505 | case 3: return "REQUEST"; |
506 | case 4: return "DECLINE"; | 506 | case 4: return "DECLINE"; |
507 | case 5: return "ACK"; | 507 | case 5: return "ACK"; |
508 | case 6: return "NAK"; | 508 | case 6: return "NAK"; |
509 | case 7: return "RELEASE"; | 509 | case 7: return "RELEASE"; |
510 | case 8: return "INFORM"; | 510 | case 8: return "INFORM"; |
511 | default: owarn << "ODHCPPacket::type(): invalid DHCP type " << _dhcphdr->op << oendl; return "<unknown>"; | 511 | default: owarn << "ODHCPPacket::type(): invalid DHCP type " << _dhcphdr->op << oendl; return "<unknown>"; |
512 | } | 512 | } |
513 | } | 513 | } |
514 | 514 | ||
515 | 515 | ||
516 | QHostAddress ODHCPPacket::clientAddress() const | 516 | QHostAddress ODHCPPacket::clientAddress() const |
517 | { | 517 | { |
518 | return EXTRACT_32BITS( &_dhcphdr->ciaddr ); | 518 | return EXTRACT_32BITS( &_dhcphdr->ciaddr ); |
519 | } | 519 | } |
520 | 520 | ||
521 | 521 | ||
522 | QHostAddress ODHCPPacket::yourAddress() const | 522 | QHostAddress ODHCPPacket::yourAddress() const |
523 | { | 523 | { |
524 | return EXTRACT_32BITS( &_dhcphdr->yiaddr ); | 524 | return EXTRACT_32BITS( &_dhcphdr->yiaddr ); |
525 | } | 525 | } |
526 | 526 | ||
527 | 527 | ||
528 | QHostAddress ODHCPPacket::serverAddress() const | 528 | QHostAddress ODHCPPacket::serverAddress() const |
529 | { | 529 | { |
530 | return EXTRACT_32BITS( &_dhcphdr->siaddr ); | 530 | return EXTRACT_32BITS( &_dhcphdr->siaddr ); |
531 | } | 531 | } |
532 | 532 | ||
533 | 533 | ||
534 | QHostAddress ODHCPPacket::relayAddress() const | 534 | QHostAddress ODHCPPacket::relayAddress() const |
535 | { | 535 | { |
536 | return EXTRACT_32BITS( &_dhcphdr->giaddr ); | 536 | return EXTRACT_32BITS( &_dhcphdr->giaddr ); |
537 | } | 537 | } |
538 | 538 | ||
539 | 539 | ||
540 | OMacAddress ODHCPPacket::clientMacAddress() const | 540 | OMacAddress ODHCPPacket::clientMacAddress() const |
541 | { | 541 | { |
542 | return OMacAddress( _dhcphdr->chaddr ); | 542 | return OMacAddress( _dhcphdr->chaddr ); |
543 | } | 543 | } |
544 | 544 | ||
545 | 545 | ||
546 | /*====================================================================================== | 546 | /*====================================================================================== |
547 | * OTCPPacket | 547 | * OTCPPacket |
548 | *======================================================================================*/ | 548 | *======================================================================================*/ |
549 | 549 | ||
550 | 550 | ||
551 | OTCPPacket::OTCPPacket( const unsigned char* /*end*/, const struct tcphdr* data, QObject* parent ) | 551 | OTCPPacket::OTCPPacket( const unsigned char* /*end*/, const struct tcphdr* data, QObject* parent ) |
552 | :QObject( parent, "TCP" ), _tcphdr( data ) | 552 | :QObject( parent, "TCP" ), _tcphdr( data ) |
553 | 553 | ||
554 | { | 554 | { |
555 | odebug << "OTCPPacket::OTCPPacket(): decoding TCP header..." << oendl; | 555 | odebug << "OTCPPacket::OTCPPacket(): decoding TCP header..." << oendl; |
556 | } | 556 | } |
557 | 557 | ||
558 | 558 | ||
559 | OTCPPacket::~OTCPPacket() | 559 | OTCPPacket::~OTCPPacket() |
560 | { | 560 | { |
561 | } | 561 | } |
562 | 562 | ||
563 | 563 | ||
564 | int OTCPPacket::fromPort() const | 564 | int OTCPPacket::fromPort() const |
565 | { | 565 | { |
566 | return EXTRACT_16BITS( &_tcphdr->source ); | 566 | return EXTRACT_16BITS( &_tcphdr->source ); |
567 | } | 567 | } |
568 | 568 | ||
569 | 569 | ||
570 | int OTCPPacket::toPort() const | 570 | int OTCPPacket::toPort() const |
571 | { | 571 | { |
572 | return EXTRACT_16BITS( &_tcphdr->dest ); | 572 | return EXTRACT_16BITS( &_tcphdr->dest ); |
573 | } | 573 | } |
574 | 574 | ||
575 | 575 | ||
576 | int OTCPPacket::seq() const | 576 | int OTCPPacket::seq() const |
577 | { | 577 | { |
578 | return EXTRACT_16BITS( &_tcphdr->seq ); | 578 | return EXTRACT_16BITS( &_tcphdr->seq ); |
579 | } | 579 | } |
580 | 580 | ||
581 | 581 | ||
582 | int OTCPPacket::ack() const | 582 | int OTCPPacket::ack() const |
583 | { | 583 | { |
584 | return EXTRACT_16BITS( &_tcphdr->ack_seq ); | 584 | return EXTRACT_16BITS( &_tcphdr->ack_seq ); |
585 | } | 585 | } |
586 | 586 | ||
587 | 587 | ||
588 | int OTCPPacket::window() const | 588 | int OTCPPacket::window() const |
589 | { | 589 | { |
590 | return EXTRACT_16BITS( &_tcphdr->window ); | 590 | return EXTRACT_16BITS( &_tcphdr->window ); |
591 | } | 591 | } |
592 | 592 | ||
593 | 593 | ||
594 | int OTCPPacket::checksum() const | 594 | int OTCPPacket::checksum() const |
595 | { | 595 | { |
596 | return EXTRACT_16BITS( &_tcphdr->check ); | 596 | return EXTRACT_16BITS( &_tcphdr->check ); |
597 | } | 597 | } |
598 | 598 | ||
599 | /*====================================================================================== | 599 | /*====================================================================================== |
600 | * OPrismHeaderPacket | 600 | * OPrismHeaderPacket |
601 | *======================================================================================*/ | 601 | *======================================================================================*/ |
602 | 602 | ||
603 | 603 | ||
604 | OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent ) | 604 | OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent ) |
605 | :QObject( parent, "Prism" ), _header( data ) | 605 | :QObject( parent, "Prism" ), _header( data ) |
606 | 606 | ||
607 | { | 607 | { |
608 | odebug << "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." << oendl; | 608 | odebug << "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." << oendl; |
609 | 609 | ||
610 | odebug << "Signal Strength = " << data->signal.data << oendl; | 610 | odebug << "Signal Strength = " << data->signal.data << oendl; |
611 | 611 | ||
612 | new OWaveLanPacket( end, (const struct ieee_802_11_header*) (data+1), this ); | 612 | new OWaveLanPacket( end, (const struct ieee_802_11_header*) (data+1), this ); |
613 | } | 613 | } |
614 | 614 | ||
615 | OPrismHeaderPacket::~OPrismHeaderPacket() | 615 | OPrismHeaderPacket::~OPrismHeaderPacket() |
616 | { | 616 | { |
617 | } | 617 | } |
618 | 618 | ||
619 | 619 | ||
620 | unsigned int OPrismHeaderPacket::signalStrength() const | 620 | unsigned int OPrismHeaderPacket::signalStrength() const |
621 | { | 621 | { |
622 | return _header->signal.data; | 622 | return _header->signal.data; |
623 | } | 623 | } |
624 | 624 | ||
625 | /*====================================================================================== | 625 | /*====================================================================================== |
626 | * OWaveLanPacket | 626 | * OWaveLanPacket |
627 | *======================================================================================*/ | 627 | *======================================================================================*/ |
628 | 628 | ||
629 | 629 | ||
630 | OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) | 630 | OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) |
631 | :QObject( parent, "802.11" ), _wlanhdr( data ) | 631 | :QObject( parent, "802.11" ), _wlanhdr( data ) |
632 | 632 | ||
633 | { | 633 | { |
634 | odebug << "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." << oendl; | 634 | odebug << "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." << oendl; |
635 | odebug << "type = " << type() << oendl; | 635 | odebug << "type = " << type() << oendl; |
636 | odebug << "subType = " << subType() << oendl; | 636 | odebug << "subType = " << subType() << oendl; |
637 | odebug << "duration = " << duration() << oendl; | 637 | odebug << "duration = " << duration() << oendl; |
638 | odebug << "powermanagement = " << usesPowerManagement() << oendl; | 638 | odebug << "powermanagement = " << usesPowerManagement() << oendl; |
639 | odebug << "payload is encrypted = " << ( usesWep() ? "yes" : "no" ) << oendl; | 639 | odebug << "payload is encrypted = " << ( usesWep() ? "yes" : "no" ) << oendl; |
640 | odebug << "MAC1 = " << macAddress1().toString() << oendl; | 640 | odebug << "MAC1 = " << macAddress1().toString() << oendl; |
641 | odebug << "MAC2 = " << macAddress2().toString() << oendl; | 641 | odebug << "MAC2 = " << macAddress2().toString() << oendl; |
642 | odebug << "MAC3 = " << macAddress3().toString() << oendl; | 642 | odebug << "MAC3 = " << macAddress3().toString() << oendl; |
643 | odebug << "MAC4 = " << macAddress4().toString() << oendl; | 643 | odebug << "MAC4 = " << macAddress4().toString() << oendl; |
644 | 644 | ||
645 | switch ( type() ) | 645 | switch ( type() ) |
646 | { | 646 | { |
647 | case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; | 647 | case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; |
648 | case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; | 648 | case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; |
649 | case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; | 649 | case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; |
650 | default: odebug << "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type = " << type() << oendl; | 650 | default: odebug << "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type = " << type() << oendl; |
651 | } | 651 | } |
652 | } | 652 | } |
653 | 653 | ||
654 | OWaveLanPacket::~OWaveLanPacket() | 654 | OWaveLanPacket::~OWaveLanPacket() |
655 | { | 655 | { |
656 | } | 656 | } |
657 | 657 | ||
658 | 658 | ||
659 | int OWaveLanPacket::duration() const | 659 | int OWaveLanPacket::duration() const |
660 | { | 660 | { |
661 | return _wlanhdr->duration; | 661 | return _wlanhdr->duration; |
662 | } | 662 | } |
663 | 663 | ||
664 | 664 | ||
665 | OMacAddress OWaveLanPacket::macAddress1() const | 665 | OMacAddress OWaveLanPacket::macAddress1() const |
666 | { | 666 | { |
667 | return OMacAddress( _wlanhdr->mac1 ); | 667 | return OMacAddress( _wlanhdr->mac1 ); |
668 | } | 668 | } |
669 | 669 | ||
670 | 670 | ||
671 | OMacAddress OWaveLanPacket::macAddress2() const | 671 | OMacAddress OWaveLanPacket::macAddress2() const |
672 | { | 672 | { |
673 | return OMacAddress( _wlanhdr->mac2 ); | 673 | return OMacAddress( _wlanhdr->mac2 ); |
674 | } | 674 | } |
675 | 675 | ||
676 | 676 | ||
677 | OMacAddress OWaveLanPacket::macAddress3() const | 677 | OMacAddress OWaveLanPacket::macAddress3() const |
678 | { | 678 | { |
679 | return OMacAddress( _wlanhdr->mac3 ); | 679 | return OMacAddress( _wlanhdr->mac3 ); |
680 | } | 680 | } |
681 | 681 | ||
682 | 682 | ||
683 | OMacAddress OWaveLanPacket::macAddress4() const | 683 | OMacAddress OWaveLanPacket::macAddress4() const |
684 | { | 684 | { |
685 | return OMacAddress( _wlanhdr->mac4 ); | 685 | return OMacAddress( _wlanhdr->mac4 ); |
686 | } | 686 | } |
687 | 687 | ||
688 | 688 | ||
689 | int OWaveLanPacket::subType() const | 689 | int OWaveLanPacket::subType() const |
690 | { | 690 | { |
691 | return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 691 | return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
692 | } | 692 | } |
693 | 693 | ||
694 | 694 | ||
695 | int OWaveLanPacket::type() const | 695 | int OWaveLanPacket::type() const |
696 | { | 696 | { |
697 | return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 697 | return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
698 | } | 698 | } |
699 | 699 | ||
700 | 700 | ||
701 | int OWaveLanPacket::version() const | 701 | int OWaveLanPacket::version() const |
702 | { | 702 | { |
703 | return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 703 | return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
704 | } | 704 | } |
705 | 705 | ||
706 | 706 | ||
707 | bool OWaveLanPacket::fromDS() const | 707 | bool OWaveLanPacket::fromDS() const |
708 | { | 708 | { |
709 | return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 709 | return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
710 | } | 710 | } |
711 | 711 | ||
712 | 712 | ||
713 | bool OWaveLanPacket::toDS() const | 713 | bool OWaveLanPacket::toDS() const |
714 | { | 714 | { |
715 | return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 715 | return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
716 | } | 716 | } |
717 | 717 | ||
718 | 718 | ||
719 | bool OWaveLanPacket::usesPowerManagement() const | 719 | bool OWaveLanPacket::usesPowerManagement() const |
720 | { | 720 | { |
721 | return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 721 | return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
722 | } | 722 | } |
723 | 723 | ||
724 | 724 | ||
725 | bool OWaveLanPacket::usesWep() const | 725 | bool OWaveLanPacket::usesWep() const |
726 | { | 726 | { |
727 | return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 727 | return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
728 | } | 728 | } |
729 | 729 | ||
730 | 730 | ||
731 | /*====================================================================================== | 731 | /*====================================================================================== |
732 | * OWaveLanManagementPacket | 732 | * OWaveLanManagementPacket |
733 | *======================================================================================*/ | 733 | *======================================================================================*/ |
734 | 734 | ||
735 | OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) | 735 | OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) |
736 | :QObject( parent, "802.11 Management" ), _header( data ), | 736 | :QObject( parent, "802.11 Management" ), _header( data ), |
737 | _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) | 737 | _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) |
738 | { | 738 | { |
739 | odebug << "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." << oendl; | 739 | odebug << "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." << oendl; |
740 | odebug << "Detected subtype is " << managementType() << oendl; | 740 | odebug << "Detected subtype is " << managementType() << oendl; |
741 | 741 | ||
742 | // Grab tagged values. | 742 | // Grab tagged values. |
743 | // Beacons contain a 12 byte long fixed parameters set before the tagged parameters come, | 743 | // Beacons contain a 12 byte long fixed parameters set before the tagged parameters come, |
744 | // Other management frames don't - which is why we have to inspect the subtype here. | 744 | // Other management frames don't - which is why we have to inspect the subtype here. |
745 | 745 | ||
746 | const unsigned char* ptr = managementType() == "Beacon" ? (const unsigned char*) (_body+1) : (const unsigned char*) (_header+1); | 746 | const unsigned char* ptr = managementType() == "Beacon" ? (const unsigned char*) (_body+1) : (const unsigned char*) (_header+1); |
747 | 747 | ||
748 | while (ptr < end) | 748 | while (ptr < end) |
749 | { | 749 | { |
750 | switch ( *ptr ) | 750 | switch ( *ptr ) |
751 | { | 751 | { |
752 | case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; | 752 | case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; |
753 | case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; | 753 | case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; |
754 | case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; | 754 | case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; |
755 | case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; | 755 | case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; |
756 | case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; | 756 | case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; |
757 | case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; | 757 | case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; |
758 | case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; | 758 | case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; |
759 | case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; | 759 | case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; |
760 | } | 760 | } |
761 | ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value | 761 | ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value |
762 | ptr+= 2; // skip tag ID and length | 762 | ptr+= 2; // skip tag ID and length |
763 | } | 763 | } |
764 | } | 764 | } |
765 | 765 | ||
766 | 766 | ||
767 | OWaveLanManagementPacket::~OWaveLanManagementPacket() | 767 | OWaveLanManagementPacket::~OWaveLanManagementPacket() |
768 | { | 768 | { |
769 | } | 769 | } |
770 | 770 | ||
771 | 771 | ||
772 | QString OWaveLanManagementPacket::managementType() const | 772 | QString OWaveLanManagementPacket::managementType() const |
773 | { | 773 | { |
774 | switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) | 774 | switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) |
775 | { | 775 | { |
776 | case ST_ASSOC_REQUEST: return "AssociationRequest"; break; | 776 | case ST_ASSOC_REQUEST: return "AssociationRequest"; break; |
777 | case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; | 777 | case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; |
778 | case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; | 778 | case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; |
779 | case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; | 779 | case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; |
780 | case ST_PROBE_REQUEST: return "ProbeRequest"; break; | 780 | case ST_PROBE_REQUEST: return "ProbeRequest"; break; |
781 | case ST_PROBE_RESPONSE: return "ProbeResponse"; break; | 781 | case ST_PROBE_RESPONSE: return "ProbeResponse"; break; |
782 | case ST_BEACON: return "Beacon"; break; | 782 | case ST_BEACON: return "Beacon"; break; |
783 | case ST_ATIM: return "Atim"; break; | 783 | case ST_ATIM: return "Atim"; break; |
784 | case ST_DISASSOC: return "Disassociation"; break; | 784 | case ST_DISASSOC: return "Disassociation"; break; |
785 | case ST_AUTH: return "Authentication"; break; | 785 | case ST_AUTH: return "Authentication"; break; |
786 | case ST_DEAUTH: return "Deathentication"; break; | 786 | case ST_DEAUTH: return "Deathentication"; break; |
787 | default: owarn << "OWaveLanManagementPacket::managementType(): unhandled subtype " << FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) << oendl; return "Unknown"; | 787 | default: owarn << "OWaveLanManagementPacket::managementType(): unhandled subtype " << FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) << oendl; return "Unknown"; |
788 | } | 788 | } |
789 | } | 789 | } |
790 | 790 | ||
791 | 791 | ||
792 | int OWaveLanManagementPacket::beaconInterval() const | 792 | int OWaveLanManagementPacket::beaconInterval() const |
793 | { | 793 | { |
794 | return EXTRACT_LE_16BITS( &_body->beacon_interval ); | 794 | return EXTRACT_LE_16BITS( &_body->beacon_interval ); |
795 | } | 795 | } |
796 | 796 | ||
797 | 797 | ||
798 | int OWaveLanManagementPacket::capabilities() const | 798 | int OWaveLanManagementPacket::capabilities() const |
799 | { | 799 | { |
800 | return EXTRACT_LE_16BITS( &_body->capability_info ); | 800 | return EXTRACT_LE_16BITS( &_body->capability_info ); |
801 | } | 801 | } |
802 | 802 | ||
803 | 803 | ||
804 | bool OWaveLanManagementPacket::canESS() const | 804 | bool OWaveLanManagementPacket::canESS() const |
805 | { | 805 | { |
806 | return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 806 | return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
807 | } | 807 | } |
808 | 808 | ||
809 | 809 | ||
810 | bool OWaveLanManagementPacket::canIBSS() const | 810 | bool OWaveLanManagementPacket::canIBSS() const |
811 | { | 811 | { |
812 | return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 812 | return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
813 | } | 813 | } |
814 | 814 | ||
815 | 815 | ||
816 | bool OWaveLanManagementPacket::canCFP() const | 816 | bool OWaveLanManagementPacket::canCFP() const |
817 | { | 817 | { |
818 | return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 818 | return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
819 | } | 819 | } |
820 | 820 | ||
821 | 821 | ||
822 | bool OWaveLanManagementPacket::canCFP_REQ() const | 822 | bool OWaveLanManagementPacket::canCFP_REQ() const |
823 | { | 823 | { |
824 | return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 824 | return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
825 | } | 825 | } |
826 | 826 | ||
827 | 827 | ||
828 | bool OWaveLanManagementPacket::canPrivacy() const | 828 | bool OWaveLanManagementPacket::canPrivacy() const |
829 | { | 829 | { |
830 | return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 830 | return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
831 | } | 831 | } |
832 | 832 | ||
833 | 833 | ||
834 | /*====================================================================================== | 834 | /*====================================================================================== |
835 | * OWaveLanManagementSSID | 835 | * OWaveLanManagementSSID |
836 | *======================================================================================*/ | 836 | *======================================================================================*/ |
837 | 837 | ||
838 | OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* /*end*/, const struct ssid_t* data, QObject* parent ) | 838 | OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* /*end*/, const struct ssid_t* data, QObject* parent ) |
839 | :QObject( parent, "802.11 SSID" ), _data( data ) | 839 | :QObject( parent, "802.11 SSID" ), _data( data ) |
840 | { | 840 | { |
841 | odebug << "OWaveLanManagementSSID()" << oendl; | 841 | odebug << "OWaveLanManagementSSID()" << oendl; |
842 | } | 842 | } |
843 | 843 | ||
844 | 844 | ||
845 | OWaveLanManagementSSID::~OWaveLanManagementSSID() | 845 | OWaveLanManagementSSID::~OWaveLanManagementSSID() |
846 | { | 846 | { |
847 | } | 847 | } |
848 | 848 | ||
849 | 849 | ||
850 | QString OWaveLanManagementSSID::ID( bool decloak ) const | 850 | QString OWaveLanManagementSSID::ID( bool decloak ) const |
851 | { | 851 | { |
852 | int length = _data->length; | 852 | int length = _data->length; |
853 | if ( length > 32 ) length = 32; | 853 | if ( length > 32 ) length = 32; |
854 | char essid[length+1]; | 854 | char essid[length+1]; |
855 | memcpy( &essid, &_data->ssid, length ); | 855 | memcpy( &essid, &_data->ssid, length ); |
856 | essid[length] = 0x0; | 856 | essid[length] = 0x0; |
857 | if ( !decloak || length < 2 || essid[0] != '\0' ) return essid; | 857 | if ( !decloak || length < 2 || essid[0] != '\0' ) return essid; |
858 | odebug << "OWaveLanManagementSSID:ID(): SSID is cloaked - decloaking..." << oendl; | 858 | odebug << "OWaveLanManagementSSID:ID(): SSID is cloaked - decloaking..." << oendl; |
859 | 859 | ||
860 | QString decloakedID; | 860 | QString decloakedID; |
861 | for ( int i = 1; i < length; ++i ) | 861 | for ( int i = 1; i < length; ++i ) |
862 | { | 862 | { |
863 | if ( essid[i] >= 32 && essid[i] <= 126 ) decloakedID.append( essid[i] ); | 863 | if ( essid[i] >= 32 && essid[i] <= 126 ) decloakedID.append( essid[i] ); |
864 | else decloakedID.append( '.' ); | 864 | else decloakedID.append( '.' ); |
865 | } | 865 | } |
866 | return decloakedID; | 866 | return decloakedID; |
867 | } | 867 | } |
868 | 868 | ||
869 | 869 | ||
870 | /*====================================================================================== | 870 | /*====================================================================================== |
871 | * OWaveLanManagementRates | 871 | * OWaveLanManagementRates |
872 | *======================================================================================*/ | 872 | *======================================================================================*/ |
873 | 873 | ||
874 | OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* /*end*/, const struct rates_t* data, QObject* parent ) | 874 | OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* /*end*/, const struct rates_t* data, QObject* parent ) |
875 | :QObject( parent, "802.11 Rates" ), _data( data ) | 875 | :QObject( parent, "802.11 Rates" ), _data( data ) |
876 | { | 876 | { |
877 | odebug << "OWaveLanManagementRates()" << oendl; | 877 | odebug << "OWaveLanManagementRates()" << oendl; |
878 | } | 878 | } |
879 | 879 | ||
880 | 880 | ||
881 | OWaveLanManagementRates::~OWaveLanManagementRates() | 881 | OWaveLanManagementRates::~OWaveLanManagementRates() |
882 | { | 882 | { |
883 | } | 883 | } |
884 | 884 | ||
885 | /*====================================================================================== | 885 | /*====================================================================================== |
886 | * OWaveLanManagementCF | 886 | * OWaveLanManagementCF |
887 | *======================================================================================*/ | 887 | *======================================================================================*/ |
888 | 888 | ||
889 | OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* /*end*/, const struct cf_t* data, QObject* parent ) | 889 | OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* /*end*/, const struct cf_t* data, QObject* parent ) |
890 | :QObject( parent, "802.11 CF" ), _data( data ) | 890 | :QObject( parent, "802.11 CF" ), _data( data ) |
891 | { | 891 | { |
892 | odebug << "OWaveLanManagementCF()" << oendl; | 892 | odebug << "OWaveLanManagementCF()" << oendl; |
893 | } | 893 | } |
894 | 894 | ||
895 | 895 | ||
896 | OWaveLanManagementCF::~OWaveLanManagementCF() | 896 | OWaveLanManagementCF::~OWaveLanManagementCF() |
897 | { | 897 | { |
898 | } | 898 | } |
899 | 899 | ||
900 | /*====================================================================================== | 900 | /*====================================================================================== |
901 | * OWaveLanManagementFH | 901 | * OWaveLanManagementFH |
902 | *======================================================================================*/ | 902 | *======================================================================================*/ |
903 | 903 | ||
904 | OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* /*end*/, const struct fh_t* data, QObject* parent ) | 904 | OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* /*end*/, const struct fh_t* data, QObject* parent ) |
905 | :QObject( parent, "802.11 FH" ), _data( data ) | 905 | :QObject( parent, "802.11 FH" ), _data( data ) |
906 | { | 906 | { |
907 | odebug << "OWaveLanManagementFH()" << oendl; | 907 | odebug << "OWaveLanManagementFH()" << oendl; |
908 | } | 908 | } |
909 | 909 | ||
910 | 910 | ||
911 | OWaveLanManagementFH::~OWaveLanManagementFH() | 911 | OWaveLanManagementFH::~OWaveLanManagementFH() |
912 | { | 912 | { |
913 | } | 913 | } |
914 | 914 | ||
915 | /*====================================================================================== | 915 | /*====================================================================================== |
916 | * OWaveLanManagementDS | 916 | * OWaveLanManagementDS |
917 | *======================================================================================*/ | 917 | *======================================================================================*/ |
918 | 918 | ||
919 | OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* /*end*/, const struct ds_t* data, QObject* parent ) | 919 | OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* /*end*/, const struct ds_t* data, QObject* parent ) |
920 | :QObject( parent, "802.11 DS" ), _data( data ) | 920 | :QObject( parent, "802.11 DS" ), _data( data ) |
921 | { | 921 | { |
922 | odebug << "OWaveLanManagementDS()" << oendl; | 922 | odebug << "OWaveLanManagementDS()" << oendl; |
923 | } | 923 | } |
924 | 924 | ||
925 | 925 | ||
926 | OWaveLanManagementDS::~OWaveLanManagementDS() | 926 | OWaveLanManagementDS::~OWaveLanManagementDS() |
927 | { | 927 | { |
928 | } | 928 | } |
929 | 929 | ||
930 | 930 | ||
931 | int OWaveLanManagementDS::channel() const | 931 | int OWaveLanManagementDS::channel() const |
932 | { | 932 | { |
933 | return _data->channel; | 933 | return _data->channel; |
934 | } | 934 | } |
935 | 935 | ||
936 | /*====================================================================================== | 936 | /*====================================================================================== |
937 | * OWaveLanManagementTim | 937 | * OWaveLanManagementTim |
938 | *======================================================================================*/ | 938 | *======================================================================================*/ |
939 | 939 | ||
940 | OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* /*end*/, const struct tim_t* data, QObject* parent ) | 940 | OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* /*end*/, const struct tim_t* data, QObject* parent ) |
941 | :QObject( parent, "802.11 Tim" ), _data( data ) | 941 | :QObject( parent, "802.11 Tim" ), _data( data ) |
942 | { | 942 | { |
943 | odebug << "OWaveLanManagementTim()" << oendl; | 943 | odebug << "OWaveLanManagementTim()" << oendl; |
944 | } | 944 | } |
945 | 945 | ||
946 | 946 | ||
947 | OWaveLanManagementTim::~OWaveLanManagementTim() | 947 | OWaveLanManagementTim::~OWaveLanManagementTim() |
948 | { | 948 | { |
949 | } | 949 | } |
950 | 950 | ||
951 | /*====================================================================================== | 951 | /*====================================================================================== |
952 | * OWaveLanManagementIBSS | 952 | * OWaveLanManagementIBSS |
953 | *======================================================================================*/ | 953 | *======================================================================================*/ |
954 | 954 | ||
955 | OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* /*end*/, const struct ibss_t* data, QObject* parent ) | 955 | OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* /*end*/, const struct ibss_t* data, QObject* parent ) |
956 | :QObject( parent, "802.11 IBSS" ), _data( data ) | 956 | :QObject( parent, "802.11 IBSS" ), _data( data ) |
957 | { | 957 | { |
958 | odebug << "OWaveLanManagementIBSS()" << oendl; | 958 | odebug << "OWaveLanManagementIBSS()" << oendl; |
959 | } | 959 | } |
960 | 960 | ||
961 | 961 | ||
962 | OWaveLanManagementIBSS::~OWaveLanManagementIBSS() | 962 | OWaveLanManagementIBSS::~OWaveLanManagementIBSS() |
963 | { | 963 | { |
964 | } | 964 | } |
965 | 965 | ||
966 | /*====================================================================================== | 966 | /*====================================================================================== |
967 | * OWaveLanManagementChallenge | 967 | * OWaveLanManagementChallenge |
968 | *======================================================================================*/ | 968 | *======================================================================================*/ |
969 | 969 | ||
970 | OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* /*end*/, const struct challenge_t* data, QObject* parent ) | 970 | OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* /*end*/, const struct challenge_t* data, QObject* parent ) |
971 | :QObject( parent, "802.11 Challenge" ), _data( data ) | 971 | :QObject( parent, "802.11 Challenge" ), _data( data ) |
972 | { | 972 | { |
973 | odebug << "OWaveLanManagementChallenge()" << oendl; | 973 | odebug << "OWaveLanManagementChallenge()" << oendl; |
974 | } | 974 | } |
975 | 975 | ||
976 | 976 | ||
977 | OWaveLanManagementChallenge::~OWaveLanManagementChallenge() | 977 | OWaveLanManagementChallenge::~OWaveLanManagementChallenge() |
978 | { | 978 | { |
979 | } | 979 | } |
980 | 980 | ||
981 | /*====================================================================================== | 981 | /*====================================================================================== |
982 | * OWaveLanDataPacket | 982 | * OWaveLanDataPacket |
983 | *======================================================================================*/ | 983 | *======================================================================================*/ |
984 | 984 | ||
985 | OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) | 985 | OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) |
986 | :QObject( parent, "802.11 Data" ), _header( data ) | 986 | :QObject( parent, "802.11 Data" ), _header( data ) |
987 | { | 987 | { |
988 | odebug << "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." << oendl; | 988 | odebug << "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." << oendl; |
989 | 989 | ||
990 | const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); | 990 | const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); |
991 | 991 | ||
992 | #warning The next line works for most cases, but can not be correct generally! | 992 | #warning The next line works for most cases, but can not be correct generally! |
993 | if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address | 993 | if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address |
994 | 994 | ||
995 | new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); | 995 | new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); |
996 | } | 996 | } |
997 | 997 | ||
998 | 998 | ||
999 | OWaveLanDataPacket::~OWaveLanDataPacket() | 999 | OWaveLanDataPacket::~OWaveLanDataPacket() |
1000 | { | 1000 | { |
1001 | } | 1001 | } |
1002 | 1002 | ||
1003 | 1003 | ||
1004 | /*====================================================================================== | 1004 | /*====================================================================================== |
1005 | * OLLCPacket | 1005 | * OLLCPacket |
1006 | *======================================================================================*/ | 1006 | *======================================================================================*/ |
1007 | 1007 | ||
1008 | OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) | 1008 | OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) |
1009 | :QObject( parent, "802.11 LLC" ), _header( data ) | 1009 | :QObject( parent, "802.11 LLC" ), _header( data ) |
1010 | { | 1010 | { |
1011 | odebug << "OLLCPacket::OLLCPacket(): decoding frame..." << oendl; | 1011 | odebug << "OLLCPacket::OLLCPacket(): decoding frame..." << oendl; |
1012 | 1012 | ||
1013 | if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) | 1013 | if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) |
1014 | { | 1014 | { |
1015 | owarn << "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type = " << EXTRACT_16BITS( &_header->type ) << ")" << oendl; | 1015 | owarn << "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type = " << EXTRACT_16BITS( &_header->type ) << ")" << oendl; |
1016 | 1016 | ||
1017 | switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h | 1017 | switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h |
1018 | { | 1018 | { |
1019 | case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; | 1019 | case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; |
1020 | case ETH_P_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; | 1020 | case ETH_P_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; |
1021 | default: owarn << "OLLCPacket::OLLCPacket(): Unknown Encapsulation type = " << EXTRACT_16BITS( &_header->type ) << oendl; | 1021 | default: owarn << "OLLCPacket::OLLCPacket(): Unknown Encapsulation type = " << EXTRACT_16BITS( &_header->type ) << oendl; |
1022 | } | 1022 | } |
1023 | } | 1023 | } |
1024 | } | 1024 | } |
1025 | 1025 | ||
1026 | 1026 | ||
1027 | OLLCPacket::~OLLCPacket() | 1027 | OLLCPacket::~OLLCPacket() |
1028 | { | 1028 | { |
1029 | } | 1029 | } |
1030 | 1030 | ||
1031 | 1031 | ||
1032 | /*====================================================================================== | 1032 | /*====================================================================================== |
1033 | * OWaveLanControlPacket | 1033 | * OWaveLanControlPacket |
1034 | *======================================================================================*/ | 1034 | *======================================================================================*/ |
1035 | 1035 | ||
1036 | OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* /*end*/, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) | 1036 | OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* /*end*/, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) |
1037 | :QObject( parent, "802.11 Control" ), _header( data ) | 1037 | :QObject( parent, "802.11 Control" ), _header( data ) |
1038 | { | 1038 | { |
1039 | odebug << "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." << oendl; | 1039 | odebug << "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." << oendl; |
1040 | odebug << "Detected subtype is " << controlType() << oendl; | 1040 | odebug << "Detected subtype is " << controlType() << oendl; |
1041 | } | 1041 | } |
1042 | 1042 | ||
1043 | 1043 | ||
1044 | OWaveLanControlPacket::~OWaveLanControlPacket() | 1044 | OWaveLanControlPacket::~OWaveLanControlPacket() |
1045 | { | 1045 | { |
1046 | } | 1046 | } |
1047 | 1047 | ||
1048 | 1048 | ||
1049 | QString OWaveLanControlPacket::controlType() const | 1049 | QString OWaveLanControlPacket::controlType() const |
1050 | { | 1050 | { |
1051 | switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) | 1051 | switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) |
1052 | { | 1052 | { |
1053 | case CTRL_PS_POLL: return "PowerSavePoll"; break; | 1053 | case CTRL_PS_POLL: return "PowerSavePoll"; break; |
1054 | case CTRL_RTS: return "RequestToSend"; break; | 1054 | case CTRL_RTS: return "RequestToSend"; break; |
1055 | case CTRL_CTS: return "ClearToSend"; break; | 1055 | case CTRL_CTS: return "ClearToSend"; break; |
1056 | case CTRL_ACK: return "Acknowledge"; break; | 1056 | case CTRL_ACK: return "Acknowledge"; break; |
1057 | case CTRL_CF_END: return "ContentionFreeEnd"; break; | 1057 | case CTRL_CF_END: return "ContentionFreeEnd"; break; |
1058 | case CTRL_END_ACK: return "AcknowledgeEnd"; break; | 1058 | case CTRL_END_ACK: return "AcknowledgeEnd"; break; |
1059 | default: | 1059 | default: |
1060 | owarn << "OWaveLanControlPacket::managementType(): unhandled subtype " << FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) << oendl; | 1060 | owarn << "OWaveLanControlPacket::managementType(): unhandled subtype " << FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) << oendl; |
1061 | return "Unknown"; | 1061 | return "Unknown"; |
1062 | } | 1062 | } |
1063 | } | 1063 | } |
1064 | 1064 | ||
1065 | 1065 | ||
1066 | /*====================================================================================== | 1066 | /*====================================================================================== |
1067 | * OPacketCapturer | 1067 | * OPacketCapturer |
1068 | *======================================================================================*/ | 1068 | *======================================================================================*/ |
1069 | 1069 | ||
1070 | OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) | 1070 | OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) |
1071 | :QObject( parent, name ), _name( QString::null ), _open( false ), _pch( 0 ), _pcd( 0 ), _sn( 0 ), _autodelete( true ) | 1071 | :QObject( parent, name ), _name( QString::null ), _open( false ), _pch( 0 ), _pcd( 0 ), _sn( 0 ), _autodelete( true ) |
1072 | { | 1072 | { |
1073 | } | 1073 | } |
1074 | 1074 | ||
1075 | 1075 | ||
1076 | OPacketCapturer::~OPacketCapturer() | 1076 | OPacketCapturer::~OPacketCapturer() |
1077 | { | 1077 | { |
1078 | if ( _open ) | 1078 | if ( _open ) |
1079 | { | 1079 | { |
1080 | odebug << "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." << oendl; | 1080 | odebug << "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." << oendl; |
1081 | close(); | 1081 | close(); |
1082 | } | 1082 | } |
1083 | } | 1083 | } |
1084 | 1084 | ||
1085 | 1085 | ||
1086 | void OPacketCapturer::setAutoDelete( bool b ) | 1086 | void OPacketCapturer::setAutoDelete( bool b ) |
1087 | { | 1087 | { |
1088 | _autodelete = b; | 1088 | _autodelete = b; |
1089 | } | 1089 | } |
1090 | 1090 | ||
1091 | 1091 | ||
1092 | bool OPacketCapturer::autoDelete() const | 1092 | bool OPacketCapturer::autoDelete() const |
1093 | { | 1093 | { |
1094 | return _autodelete; | 1094 | return _autodelete; |
1095 | } | 1095 | } |
1096 | 1096 | ||
1097 | 1097 | ||
1098 | void OPacketCapturer::setBlocking( bool b ) | 1098 | void OPacketCapturer::setBlocking( bool b ) |
1099 | { | 1099 | { |
1100 | if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) | 1100 | if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) |
1101 | { | 1101 | { |
1102 | odebug << "OPacketCapturer::setBlocking(): blocking mode changed successfully." << oendl; | 1102 | odebug << "OPacketCapturer::setBlocking(): blocking mode changed successfully." << oendl; |
1103 | } | 1103 | } |
1104 | else | 1104 | else |
1105 | { | 1105 | { |
1106 | odebug << "OPacketCapturer::setBlocking(): can't change blocking mode: " << _errbuf << oendl; | 1106 | odebug << "OPacketCapturer::setBlocking(): can't change blocking mode: " << _errbuf << oendl; |
1107 | } | 1107 | } |
1108 | } | 1108 | } |
1109 | 1109 | ||
1110 | 1110 | ||
1111 | bool OPacketCapturer::blocking() const | 1111 | bool OPacketCapturer::blocking() const |
1112 | { | 1112 | { |
1113 | int b = pcap_getnonblock( _pch, _errbuf ); | 1113 | int b = pcap_getnonblock( _pch, _errbuf ); |
1114 | if ( b == -1 ) | 1114 | if ( b == -1 ) |
1115 | { | 1115 | { |
1116 | odebug << "OPacketCapturer::blocking(): can't get blocking mode: " << _errbuf << oendl; | 1116 | odebug << "OPacketCapturer::blocking(): can't get blocking mode: " << _errbuf << oendl; |
1117 | return -1; | 1117 | return -1; |
1118 | } | 1118 | } |
1119 | return !b; | 1119 | return !b; |
1120 | } | 1120 | } |
1121 | 1121 | ||
1122 | 1122 | ||
1123 | void OPacketCapturer::closeDumpFile() | 1123 | void OPacketCapturer::closeDumpFile() |
1124 | { | 1124 | { |
1125 | if ( _pcd ) | 1125 | if ( _pcd ) |
1126 | { | 1126 | { |
1127 | pcap_dump_close( _pcd ); | 1127 | pcap_dump_close( _pcd ); |
1128 | _pcd = 0; | 1128 | _pcd = 0; |
1129 | } | 1129 | } |
1130 | pcap_close( _pch ); | 1130 | pcap_close( _pch ); |
1131 | } | 1131 | } |
1132 | 1132 | ||
1133 | 1133 | ||
1134 | void OPacketCapturer::close() | 1134 | void OPacketCapturer::close() |
1135 | { | 1135 | { |
1136 | if ( _open ) | 1136 | if ( _open ) |
1137 | { | 1137 | { |
1138 | if ( _sn ) | 1138 | if ( _sn ) |
1139 | { | 1139 | { |
1140 | _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | 1140 | _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); |
1141 | delete _sn; | 1141 | delete _sn; |
1142 | } | 1142 | } |
1143 | closeDumpFile(); | 1143 | closeDumpFile(); |
1144 | _open = false; | 1144 | _open = false; |
1145 | } | 1145 | } |
1146 | 1146 | ||
1147 | odebug << "OPacketCapturer::close() --- dumping capturing statistics..." << oendl; | 1147 | odebug << "OPacketCapturer::close() --- dumping capturing statistics..." << oendl; |
1148 | odebug << "--------------------------------------------------" << oendl; | 1148 | odebug << "--------------------------------------------------" << oendl; |
1149 | for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) | 1149 | for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) |
1150 | odebug << it.key() << " = " << it.data() << oendl; | 1150 | odebug << it.key() << " = " << it.data() << oendl; |
1151 | odebug << "--------------------------------------------------" << oendl; | 1151 | odebug << "--------------------------------------------------" << oendl; |
1152 | 1152 | ||
1153 | } | 1153 | } |
1154 | 1154 | ||
1155 | 1155 | ||
1156 | int OPacketCapturer::dataLink() const | 1156 | int OPacketCapturer::dataLink() const |
1157 | { | 1157 | { |
1158 | return pcap_datalink( _pch ); | 1158 | return pcap_datalink( _pch ); |
1159 | } | 1159 | } |
1160 | 1160 | ||
1161 | 1161 | ||
1162 | void OPacketCapturer::dump( OPacket* p ) | 1162 | void OPacketCapturer::dump( OPacket* p ) |
1163 | { | 1163 | { |
1164 | if ( !_pcd ) | 1164 | if ( !_pcd ) |
1165 | { | 1165 | { |
1166 | owarn << "OPacketCapturer::dump() - cannot dump without open capture file!" << oendl; | 1166 | owarn << "OPacketCapturer::dump() - cannot dump without open capture file!" << oendl; |
1167 | return; | 1167 | return; |
1168 | } | 1168 | } |
1169 | pcap_dump( (u_char*) _pcd, &p->_hdr, p->_data ); | 1169 | pcap_dump( (u_char*) _pcd, &p->_hdr, p->_data ); |
1170 | } | 1170 | } |
1171 | 1171 | ||
1172 | 1172 | ||
1173 | int OPacketCapturer::fileno() const | 1173 | int OPacketCapturer::fileno() const |
1174 | { | 1174 | { |
1175 | if ( _open ) | 1175 | if ( _open ) |
1176 | { | 1176 | { |
1177 | return pcap_fileno( _pch ); | 1177 | return pcap_fileno( _pch ); |
1178 | } | 1178 | } |
1179 | else | 1179 | else |
1180 | { | 1180 | { |
1181 | return -1; | 1181 | return -1; |
1182 | } | 1182 | } |
1183 | } | 1183 | } |
1184 | 1184 | ||
1185 | 1185 | ||
1186 | OPacket* OPacketCapturer::next( int time ) | 1186 | OPacket* OPacketCapturer::next( int time ) |
1187 | { | 1187 | { |
1188 | fd_set fds; | 1188 | fd_set fds; |
1189 | struct timeval tv; | 1189 | struct timeval tv; |
1190 | FD_ZERO( &fds ); | 1190 | FD_ZERO( &fds ); |
1191 | FD_SET( pcap_fileno( _pch ), &fds ); | 1191 | FD_SET( pcap_fileno( _pch ), &fds ); |
1192 | tv.tv_sec = time / 1000; | 1192 | tv.tv_sec = time / 1000; |
1193 | tv.tv_usec = time % 1000; | 1193 | tv.tv_usec = time % 1000; |
1194 | int retval = select( pcap_fileno( _pch )+1, &fds, NULL, NULL, &tv); | 1194 | int retval = select( pcap_fileno( _pch )+1, &fds, NULL, NULL, &tv); |
1195 | if ( retval > 0 ) // clear to read! | 1195 | if ( retval > 0 ) // clear to read! |
1196 | return next(); | 1196 | return next(); |
1197 | else | 1197 | else |
1198 | return 0; | 1198 | return 0; |
1199 | } | 1199 | } |
1200 | 1200 | ||
1201 | 1201 | ||
1202 | OPacket* OPacketCapturer::next() | 1202 | OPacket* OPacketCapturer::next() |
1203 | { | 1203 | { |
1204 | packetheaderstruct header; | 1204 | packetheaderstruct header; |
1205 | odebug << "==> OPacketCapturer::next()" << oendl; | 1205 | odebug << "==> OPacketCapturer::next()" << oendl; |
1206 | const unsigned char* pdata = pcap_next( _pch, &header ); | 1206 | const unsigned char* pdata = pcap_next( _pch, &header ); |
1207 | odebug << "<== OPacketCapturer::next()" << oendl; | 1207 | odebug << "<== OPacketCapturer::next()" << oendl; |
1208 | 1208 | ||
1209 | if ( pdata && header.len ) | 1209 | if ( pdata && header.len ) |
1210 | { | 1210 | { |
1211 | OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); | 1211 | OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); |
1212 | // packets shouldn't be inserted in the QObject child-parent hierarchy, | 1212 | // packets shouldn't be inserted in the QObject child-parent hierarchy, |
1213 | // because due to memory constraints they will be deleted as soon | 1213 | // because due to memory constraints they will be deleted as soon |
1214 | // as possible - that is right after they have been processed | 1214 | // as possible - that is right after they have been processed |
1215 | // by emit() [ see below ] | 1215 | // by emit() [ see below ] |
1216 | //TODO: make gathering statistics optional, because it takes time | 1216 | //TODO: make gathering statistics optional, because it takes time |
1217 | p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); | 1217 | p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); |
1218 | odebug << "OPacket::dumpStructure: " << p->dumpStructure() << oendl; | 1218 | odebug << "OPacket::dumpStructure: " << p->dumpStructure() << oendl; |
1219 | return p; | 1219 | return p; |
1220 | } | 1220 | } |
1221 | else | 1221 | else |
1222 | { | 1222 | { |
1223 | owarn << "OPacketCapturer::next() - no packet received!" << oendl; | 1223 | owarn << "OPacketCapturer::next() - no packet received!" << oendl; |
1224 | return 0; | 1224 | return 0; |
1225 | } | 1225 | } |
1226 | } | 1226 | } |
1227 | 1227 | ||
1228 | 1228 | ||
1229 | bool OPacketCapturer::open( const QString& name ) | 1229 | bool OPacketCapturer::open( const QString& name ) |
1230 | { | 1230 | { |
1231 | if ( _open ) | 1231 | if ( _open ) |
1232 | { | 1232 | { |
1233 | if ( name == _name ) // ignore opening an already openend device | 1233 | if ( name == _name ) // ignore opening an already openend device |
1234 | { | 1234 | { |
1235 | return true; | 1235 | return true; |
1236 | } | 1236 | } |
1237 | else // close the last opened device | 1237 | else // close the last opened device |
1238 | { | 1238 | { |
1239 | close(); | 1239 | close(); |
1240 | } | 1240 | } |
1241 | } | 1241 | } |
1242 | 1242 | ||
1243 | _name = name; | 1243 | _name = name; |
1244 | 1244 | ||
1245 | // open libpcap | 1245 | // open libpcap |
1246 | pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); | 1246 | pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); |
1247 | 1247 | ||
1248 | if ( !handle ) | 1248 | if ( !handle ) |
1249 | { | 1249 | { |
1250 | owarn << "OPacketCapturer::open(): can't open libpcap with '" << name << "': " << _errbuf << oendl; | 1250 | owarn << "OPacketCapturer::open(): can't open libpcap with '" << name << "': " << _errbuf << oendl; |
1251 | return false; | 1251 | return false; |
1252 | } | 1252 | } |
1253 | 1253 | ||
1254 | odebug << "OPacketCapturer::open(): libpcap [" << name << "] opened successfully." << oendl; | 1254 | odebug << "OPacketCapturer::open(): libpcap [" << name << "] opened successfully." << oendl; |
1255 | _pch = handle; | 1255 | _pch = handle; |
1256 | _open = true; | 1256 | _open = true; |
1257 | _stats.clear(); | 1257 | _stats.clear(); |
1258 | 1258 | ||
1259 | // in case we have an application object, create a socket notifier | 1259 | // in case we have an application object, create a socket notifier |
1260 | if ( qApp ) //TODO: I don't like this here... | 1260 | if ( qApp ) //TODO: I don't like this here... |
1261 | { | 1261 | { |
1262 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); | 1262 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); |
1263 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | 1263 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); |
1264 | } | 1264 | } |
1265 | 1265 | ||
1266 | return true; | 1266 | return true; |
1267 | } | 1267 | } |
1268 | 1268 | ||
1269 | 1269 | ||
1270 | bool OPacketCapturer::openDumpFile( const QString& filename ) | 1270 | bool OPacketCapturer::openDumpFile( const QString& filename ) |
1271 | { | 1271 | { |
1272 | pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) ); | 1272 | pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) ); |
1273 | if ( !dump ) | 1273 | if ( !dump ) |
1274 | { | 1274 | { |
1275 | owarn << "OPacketCapturer::open(): can't open dump with '" << filename << "': " << _errbuf << oendl; | 1275 | owarn << "OPacketCapturer::open(): can't open dump with '" << filename << "': " << _errbuf << oendl; |
1276 | return false; | 1276 | return false; |
1277 | } | 1277 | } |
1278 | odebug << "OPacketCapturer::open(): dump [" << filename << "] opened successfully." << oendl; | 1278 | odebug << "OPacketCapturer::open(): dump [" << filename << "] opened successfully." << oendl; |
1279 | _pcd = dump; | 1279 | _pcd = dump; |
1280 | 1280 | ||
1281 | return true; | 1281 | return true; |
1282 | } | 1282 | } |
1283 | 1283 | ||
1284 | 1284 | ||
1285 | bool OPacketCapturer::openCaptureFile( const QString& name ) | 1285 | bool OPacketCapturer::openCaptureFile( const QString& name ) |
1286 | { | 1286 | { |
1287 | if ( _open ) | 1287 | if ( _open ) |
1288 | { | 1288 | { |
1289 | close(); | 1289 | close(); |
1290 | if ( name == _name ) // ignore opening an already openend device | 1290 | if ( name == _name ) // ignore opening an already openend device |
1291 | { | 1291 | { |
1292 | return true; | 1292 | return true; |
1293 | } | 1293 | } |
1294 | else // close the last opened device | 1294 | else // close the last opened device |
1295 | { | 1295 | { |
1296 | close(); | 1296 | close(); |
1297 | } | 1297 | } |
1298 | } | 1298 | } |
1299 | 1299 | ||
1300 | _name = name; | 1300 | _name = name; |
1301 | 1301 | ||
1302 | pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] ); | 1302 | pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] ); |
1303 | 1303 | ||
1304 | if ( handle ) | 1304 | if ( handle ) |
1305 | { | 1305 | { |
1306 | odebug << "OPacketCapturer::open(): libpcap opened successfully." << oendl; | 1306 | odebug << "OPacketCapturer::open(): libpcap opened successfully." << oendl; |
1307 | _pch = handle; | 1307 | _pch = handle; |
1308 | _open = true; | 1308 | _open = true; |
1309 | 1309 | ||
1310 | // in case we have an application object, create a socket notifier | 1310 | // in case we have an application object, create a socket notifier |
1311 | if ( qApp ) | 1311 | if ( qApp ) |
1312 | { | 1312 | { |
1313 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); | 1313 | _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); |
1314 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); | 1314 | connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); |
1315 | } | 1315 | } |
1316 | 1316 | ||
1317 | return true; | 1317 | return true; |
1318 | } | 1318 | } |
1319 | else | 1319 | else |
1320 | { | 1320 | { |
1321 | odebug << "OPacketCapturer::open(): can't open libpcap with '" << name << "': " << _errbuf << oendl; | 1321 | odebug << "OPacketCapturer::open(): can't open libpcap with '" << name << "': " << _errbuf << oendl; |
1322 | return false; | 1322 | return false; |
1323 | } | 1323 | } |
1324 | 1324 | ||
1325 | } | 1325 | } |
1326 | 1326 | ||
1327 | 1327 | ||
1328 | bool OPacketCapturer::isOpen() const | 1328 | bool OPacketCapturer::isOpen() const |
1329 | { | 1329 | { |
1330 | return _open; | 1330 | return _open; |
1331 | } | 1331 | } |
1332 | 1332 | ||
1333 | 1333 | ||
1334 | void OPacketCapturer::readyToReceive() | 1334 | void OPacketCapturer::readyToReceive() |
1335 | { | 1335 | { |
1336 | odebug << "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" << oendl; | 1336 | odebug << "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" << oendl; |
1337 | OPacket* p = next(); | 1337 | OPacket* p = next(); |
1338 | emit receivedPacket( p ); | 1338 | emit receivedPacket( p ); |
1339 | // emit is synchronous - packet has been dealt with, now it's safe to delete (if enabled) | 1339 | // emit is synchronous - packet has been dealt with, now it's safe to delete (if enabled) |
1340 | if ( _autodelete ) delete p; | 1340 | if ( _autodelete ) delete p; |
1341 | } | 1341 | } |
1342 | 1342 | ||
1343 | 1343 | ||
1344 | const QMap<QString,int>& OPacketCapturer::statistics() const | 1344 | const QMap<QString,int>& OPacketCapturer::statistics() const |
1345 | { | 1345 | { |
1346 | return _stats; | 1346 | return _stats; |
1347 | } | 1347 | } |
1348 | 1348 | ||
1349 | 1349 | ||
1350 | int OPacketCapturer::snapShot() const | 1350 | int OPacketCapturer::snapShot() const |
1351 | { | 1351 | { |
1352 | return pcap_snapshot( _pch ); | 1352 | return pcap_snapshot( _pch ); |
1353 | } | 1353 | } |
1354 | 1354 | ||
1355 | 1355 | ||
1356 | bool OPacketCapturer::swapped() const | 1356 | bool OPacketCapturer::swapped() const |
1357 | { | 1357 | { |
1358 | return pcap_is_swapped( _pch ); | 1358 | return pcap_is_swapped( _pch ); |
1359 | } | 1359 | } |
1360 | 1360 | ||
1361 | 1361 | ||
1362 | QString OPacketCapturer::version() const | 1362 | QString OPacketCapturer::version() const |
1363 | { | 1363 | { |
1364 | return QString().sprintf( "%d.%d", pcap_major_version( _pch ), pcap_minor_version( _pch ) ); | 1364 | return QString().sprintf( "%d.%d", pcap_major_version( _pch ), pcap_minor_version( _pch ) ); |
1365 | } | 1365 | } |
1366 | 1366 | ||
1367 | } | 1367 | } |
1368 | } | 1368 | } |
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h index 149e573..8b415a2 100644 --- a/libopie2/opienet/opcap.h +++ b/libopie2/opienet/opcap.h | |||
@@ -1,733 +1,732 @@ | |||
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 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | Copyright (C) 2003 by Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | =. | 4 | =. |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; version 2 of the License. | 11 | - . .-<_> .<> Foundation; version 2 of the License. |
12 | ._= =} : | 12 | ._= =} : |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | #ifndef OPCAP_H | 31 | #ifndef OPCAP_H |
32 | #define OPCAP_H | 32 | #define OPCAP_H |
33 | 33 | ||
34 | /* OPIE */ | 34 | /* OPIE */ |
35 | #include <opie2/onetutils.h> | 35 | #include <opie2/onetutils.h> |
36 | 36 | ||
37 | /* QT */ | 37 | /* QT */ |
38 | #include <qevent.h> | 38 | #include <qevent.h> |
39 | #include <qfile.h> | 39 | #include <qfile.h> |
40 | #include <qhostaddress.h> | 40 | #include <qhostaddress.h> |
41 | #include <qobject.h> | 41 | #include <qobject.h> |
42 | #include <qstring.h> | 42 | #include <qstring.h> |
43 | #include <qtextstream.h> | 43 | #include <qtextstream.h> |
44 | #include <qmap.h> | 44 | #include <qmap.h> |
45 | 45 | ||
46 | /* STD */ | 46 | /* STD */ |
47 | extern "C" // work around a bpf/pcap conflict in recent headers | 47 | extern "C" // work around a bpf/pcap conflict in recent headers |
48 | { | 48 | { |
49 | #include <pcap.h> | 49 | #include <pcap.h> |
50 | } | 50 | } |
51 | #include <netinet/ether.h> | 51 | #include <netinet/ether.h> |
52 | #include <netinet/ip.h> | 52 | #include <netinet/ip.h> |
53 | #include <netinet/udp.h> | 53 | #include <netinet/udp.h> |
54 | #include <netinet/tcp.h> | 54 | #include <netinet/tcp.h> |
55 | #include <time.h> | 55 | #include <time.h> |
56 | 56 | ||
57 | /* Custom Network Includes (must go here, don't reorder!) */ | 57 | /* Custom Network Includes (must go here, don't reorder!) */ |
58 | #include "802_11_user.h" | 58 | #include "802_11_user.h" |
59 | #include "dhcp.h" | 59 | #include "dhcp.h" |
60 | 60 | ||
61 | |||
62 | /* TYPEDEFS */ | 61 | /* TYPEDEFS */ |
63 | typedef struct timeval timevalstruct; | 62 | typedef struct timeval timevalstruct; |
64 | typedef struct pcap_pkthdr packetheaderstruct; | 63 | typedef struct pcap_pkthdr packetheaderstruct; |
65 | 64 | ||
66 | /* FORWARDS */ | 65 | /* FORWARDS */ |
67 | class QSocketNotifier; | 66 | class QSocketNotifier; |
68 | namespace Opie { | 67 | namespace Opie { |
69 | namespace Net { | 68 | namespace Net { |
70 | class OPacketCapturer; | 69 | class OPacketCapturer; |
71 | 70 | ||
72 | /*====================================================================================== | 71 | /*====================================================================================== |
73 | * OPacket - A frame on the wire | 72 | * OPacket - A frame on the wire |
74 | *======================================================================================*/ | 73 | *======================================================================================*/ |
75 | 74 | ||
76 | /** @brief A class representing a data frame on the wire. | 75 | /** @brief A class representing a data frame on the wire. |
77 | * | 76 | * |
78 | * The whole family of the packet classes are used when capturing frames from a network. | 77 | * The whole family of the packet classes are used when capturing frames from a network. |
79 | * Most standard network protocols in use share a common architecture, which mostly is | 78 | * Most standard network protocols in use share a common architecture, which mostly is |
80 | * a packet header and then the packet payload. In layered architectures, each lower layer | 79 | * a packet header and then the packet payload. In layered architectures, each lower layer |
81 | * encapsulates data from its upper layer - that is it | 80 | * encapsulates data from its upper layer - that is it |
82 | * treats the data from its upper layer as payload and prepends an own header to the packet, | 81 | * treats the data from its upper layer as payload and prepends an own header to the packet, |
83 | * which - again - is treated as the payload for the layer below. The figure below is an | 82 | * which - again - is treated as the payload for the layer below. The figure below is an |
84 | * example for how such a data frame is composed out of packets, e.g. when sending a mail. | 83 | * example for how such a data frame is composed out of packets, e.g. when sending a mail. |
85 | * | 84 | * |
86 | * <pre> | 85 | * <pre> |
87 | * | User Data | == Mail Data | 86 | * | User Data | == Mail Data |
88 | * | SMTP Header | User Data | == SMTP | 87 | * | SMTP Header | User Data | == SMTP |
89 | * | TCP Header | SMTP Header | User Data | == TCP | 88 | * | TCP Header | SMTP Header | User Data | == TCP |
90 | * | IP Header | TCP Header | SMTP Header | User Data | == IP | 89 | * | IP Header | TCP Header | SMTP Header | User Data | == IP |
91 | * | MAC Header | IP Header | TCP Header | SMTP Header | User Data | == MAC | 90 | * | MAC Header | IP Header | TCP Header | SMTP Header | User Data | == MAC |
92 | * | 91 | * |
93 | * </pre> | 92 | * </pre> |
94 | * | 93 | * |
95 | * The example is trimmed for simplicity, because the MAC (Medium Access Control) layer | 94 | * The example is trimmed for simplicity, because the MAC (Medium Access Control) layer |
96 | * also contains a few more levels of encapsulation. | 95 | * also contains a few more levels of encapsulation. |
97 | * Since the type of the payload is more or less independent from the encapsulating protocol, | 96 | * Since the type of the payload is more or less independent from the encapsulating protocol, |
98 | * the header must be inspected before attempting to decode the payload. Hence, the | 97 | * the header must be inspected before attempting to decode the payload. Hence, the |
99 | * encapsulation level varies and can't be deduced without actually looking into the packets. | 98 | * encapsulation level varies and can't be deduced without actually looking into the packets. |
100 | * | 99 | * |
101 | * For actually working with captured frames, it's useful to identify the packets via names and | 100 | * For actually working with captured frames, it's useful to identify the packets via names and |
102 | * insert them into a parent/child - relationship based on the encapsulation. This is why | 101 | * insert them into a parent/child - relationship based on the encapsulation. This is why |
103 | * all packet classes derive from QObject. The amount of overhead caused by the QObject is | 102 | * all packet classes derive from QObject. The amount of overhead caused by the QObject is |
104 | * not a problem in this case, because we're talking about a theoratical maximum of about | 103 | * not a problem in this case, because we're talking about a theoratical maximum of about |
105 | * 10 packets per captured frame. We need to stuff them into a searchable list anyway and the | 104 | * 10 packets per captured frame. We need to stuff them into a searchable list anyway and the |
106 | * QObject also cares about destroying the sub-, (child-) packets. | 105 | * QObject also cares about destroying the sub-, (child-) packets. |
107 | * | 106 | * |
108 | * This enables us to perform a simple look for packets of a certain type: | 107 | * This enables us to perform a simple look for packets of a certain type: |
109 | * @code | 108 | * @code |
110 | * OPacketCapturer* pcap = new OPacketCapturer(); | 109 | * OPacketCapturer* pcap = new OPacketCapturer(); |
111 | * pcap->open( "eth0" ); | 110 | * pcap->open( "eth0" ); |
112 | * OPacket* p = pcap->next(); | 111 | * OPacket* p = pcap->next(); |
113 | * OIPPacket* ip = (OIPPacket*) p->child( "IP" ); // returns 0, if no such child exists | 112 | * OIPPacket* ip = (OIPPacket*) p->child( "IP" ); // returns 0, if no such child exists |
114 | * odebug << "got ip packet from " << ip->fromIPAddress().toString() << " to " << ip->toIPAddress().toString() << oendl; | 113 | * odebug << "got ip packet from " << ip->fromIPAddress().toString() << " to " << ip->toIPAddress().toString() << oendl; |
115 | * | 114 | * |
116 | */ | 115 | */ |
117 | 116 | ||
118 | class OPacket : public QObject | 117 | class OPacket : public QObject |
119 | { | 118 | { |
120 | Q_OBJECT | 119 | Q_OBJECT |
121 | 120 | ||
122 | friend class OPacketCapturer; | 121 | friend class OPacketCapturer; |
123 | friend QTextStream& operator<<( QTextStream& s, const OPacket& p ); | 122 | friend QTextStream& operator<<( QTextStream& s, const OPacket& p ); |
124 | 123 | ||
125 | public: | 124 | public: |
126 | OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent ); | 125 | OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent ); |
127 | virtual ~OPacket(); | 126 | virtual ~OPacket(); |
128 | 127 | ||
129 | timevalstruct timeval() const; | 128 | timevalstruct timeval() const; |
130 | 129 | ||
131 | int caplen() const; | 130 | int caplen() const; |
132 | int len() const; | 131 | int len() const; |
133 | QString dump( int = 32 ) const; //FIXME: remove that | 132 | QString dump( int = 32 ) const; //FIXME: remove that |
134 | 133 | ||
135 | void updateStats( QMap<QString,int>&, QObjectList* ); //FIXME: Revise | 134 | void updateStats( QMap<QString,int>&, QObjectList* ); //FIXME: Revise |
136 | 135 | ||
137 | QString dumpStructure() const; //FIXME: Revise | 136 | QString dumpStructure() const; //FIXME: Revise |
138 | private: | 137 | private: |
139 | QString _dumpStructure( QObjectList* ) const; //FIXME: Revise | 138 | QString _dumpStructure( QObjectList* ) const; //FIXME: Revise |
140 | 139 | ||
141 | private: | 140 | private: |
142 | const packetheaderstruct _hdr; // pcap packet header | 141 | const packetheaderstruct _hdr; // pcap packet header |
143 | const unsigned char* _data; // pcap packet data | 142 | const unsigned char* _data; // pcap packet data |
144 | const unsigned char* _end; // end of pcap packet data | 143 | const unsigned char* _end; // end of pcap packet data |
145 | private: | 144 | private: |
146 | class Private; | 145 | class Private; |
147 | Private *d; | 146 | Private *d; |
148 | }; | 147 | }; |
149 | 148 | ||
150 | QTextStream& operator<<( QTextStream& s, const OPacket& p ); //FIXME: Revise | 149 | QTextStream& operator<<( QTextStream& s, const OPacket& p ); //FIXME: Revise |
151 | 150 | ||
152 | /*====================================================================================== | 151 | /*====================================================================================== |
153 | * OEthernetPacket - DLT_EN10MB frame | 152 | * OEthernetPacket - DLT_EN10MB frame |
154 | *======================================================================================*/ | 153 | *======================================================================================*/ |
155 | 154 | ||
156 | class OEthernetPacket : public QObject | 155 | class OEthernetPacket : public QObject |
157 | { | 156 | { |
158 | Q_OBJECT | 157 | Q_OBJECT |
159 | 158 | ||
160 | public: | 159 | public: |
161 | OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 ); | 160 | OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 ); |
162 | virtual ~OEthernetPacket(); | 161 | virtual ~OEthernetPacket(); |
163 | 162 | ||
164 | OMacAddress sourceAddress() const; | 163 | OMacAddress sourceAddress() const; |
165 | OMacAddress destinationAddress() const; | 164 | OMacAddress destinationAddress() const; |
166 | int type() const; | 165 | int type() const; |
167 | 166 | ||
168 | private: | 167 | private: |
169 | const struct ether_header* _ether; | 168 | const struct ether_header* _ether; |
170 | private: | 169 | private: |
171 | class Private; | 170 | class Private; |
172 | Private *d; | 171 | Private *d; |
173 | }; | 172 | }; |
174 | 173 | ||
175 | /*====================================================================================== | 174 | /*====================================================================================== |
176 | * OPrismHeaderPacket - DLT_PRISM_HEADER frame | 175 | * OPrismHeaderPacket - DLT_PRISM_HEADER frame |
177 | *======================================================================================*/ | 176 | *======================================================================================*/ |
178 | 177 | ||
179 | class OPrismHeaderPacket : public QObject | 178 | class OPrismHeaderPacket : public QObject |
180 | { | 179 | { |
181 | Q_OBJECT | 180 | Q_OBJECT |
182 | 181 | ||
183 | public: | 182 | public: |
184 | OPrismHeaderPacket( const unsigned char*, const struct prism_hdr*, QObject* parent = 0 ); | 183 | OPrismHeaderPacket( const unsigned char*, const struct prism_hdr*, QObject* parent = 0 ); |
185 | virtual ~OPrismHeaderPacket(); | 184 | virtual ~OPrismHeaderPacket(); |
186 | 185 | ||
187 | unsigned int signalStrength() const; | 186 | unsigned int signalStrength() const; |
188 | 187 | ||
189 | private: | 188 | private: |
190 | const struct prism_hdr* _header; | 189 | const struct prism_hdr* _header; |
191 | class Private; | 190 | class Private; |
192 | Private *d; | 191 | Private *d; |
193 | }; | 192 | }; |
194 | 193 | ||
195 | /*====================================================================================== | 194 | /*====================================================================================== |
196 | * OWaveLanPacket - DLT_IEEE802_11 frame | 195 | * OWaveLanPacket - DLT_IEEE802_11 frame |
197 | *======================================================================================*/ | 196 | *======================================================================================*/ |
198 | 197 | ||
199 | class OWaveLanPacket : public QObject | 198 | class OWaveLanPacket : public QObject |
200 | { | 199 | { |
201 | Q_OBJECT | 200 | Q_OBJECT |
202 | 201 | ||
203 | public: | 202 | public: |
204 | OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 ); | 203 | OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 ); |
205 | virtual ~OWaveLanPacket(); | 204 | virtual ~OWaveLanPacket(); |
206 | 205 | ||
207 | int duration() const; | 206 | int duration() const; |
208 | bool fromDS() const; | 207 | bool fromDS() const; |
209 | bool toDS() const; | 208 | bool toDS() const; |
210 | virtual OMacAddress macAddress1() const; | 209 | virtual OMacAddress macAddress1() const; |
211 | virtual OMacAddress macAddress2() const; | 210 | virtual OMacAddress macAddress2() const; |
212 | virtual OMacAddress macAddress3() const; | 211 | virtual OMacAddress macAddress3() const; |
213 | virtual OMacAddress macAddress4() const; | 212 | virtual OMacAddress macAddress4() const; |
214 | bool usesPowerManagement() const; | 213 | bool usesPowerManagement() const; |
215 | int type() const; | 214 | int type() const; |
216 | int subType() const; | 215 | int subType() const; |
217 | int version() const; | 216 | int version() const; |
218 | bool usesWep() const; | 217 | bool usesWep() const; |
219 | 218 | ||
220 | private: | 219 | private: |
221 | const struct ieee_802_11_header* _wlanhdr; | 220 | const struct ieee_802_11_header* _wlanhdr; |
222 | class Private; | 221 | class Private; |
223 | Private *d; | 222 | Private *d; |
224 | }; | 223 | }; |
225 | 224 | ||
226 | 225 | ||
227 | /*====================================================================================== | 226 | /*====================================================================================== |
228 | * OWaveLanManagementPacket - type: management (T_MGMT) | 227 | * OWaveLanManagementPacket - type: management (T_MGMT) |
229 | *======================================================================================*/ | 228 | *======================================================================================*/ |
230 | 229 | ||
231 | class OWaveLanManagementPacket : public QObject | 230 | class OWaveLanManagementPacket : public QObject |
232 | { | 231 | { |
233 | Q_OBJECT | 232 | Q_OBJECT |
234 | 233 | ||
235 | public: | 234 | public: |
236 | OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 ); | 235 | OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 ); |
237 | virtual ~OWaveLanManagementPacket(); | 236 | virtual ~OWaveLanManagementPacket(); |
238 | 237 | ||
239 | QString managementType() const; | 238 | QString managementType() const; |
240 | 239 | ||
241 | int beaconInterval() const; | 240 | int beaconInterval() const; |
242 | int capabilities() const; // generic | 241 | int capabilities() const; // generic |
243 | 242 | ||
244 | bool canESS() const; | 243 | bool canESS() const; |
245 | bool canIBSS() const; | 244 | bool canIBSS() const; |
246 | bool canCFP() const; | 245 | bool canCFP() const; |
247 | bool canCFP_REQ() const; | 246 | bool canCFP_REQ() const; |
248 | bool canPrivacy() const; | 247 | bool canPrivacy() const; |
249 | 248 | ||
250 | private: | 249 | private: |
251 | const struct ieee_802_11_mgmt_header* _header; | 250 | const struct ieee_802_11_mgmt_header* _header; |
252 | const struct ieee_802_11_mgmt_body* _body; | 251 | const struct ieee_802_11_mgmt_body* _body; |
253 | class Private; | 252 | class Private; |
254 | Private *d; | 253 | Private *d; |
255 | }; | 254 | }; |
256 | 255 | ||
257 | 256 | ||
258 | /*====================================================================================== | 257 | /*====================================================================================== |
259 | * OWaveLanManagementSSID | 258 | * OWaveLanManagementSSID |
260 | *======================================================================================*/ | 259 | *======================================================================================*/ |
261 | 260 | ||
262 | class OWaveLanManagementSSID : public QObject | 261 | class OWaveLanManagementSSID : public QObject |
263 | { | 262 | { |
264 | Q_OBJECT | 263 | Q_OBJECT |
265 | 264 | ||
266 | public: | 265 | public: |
267 | OWaveLanManagementSSID( const unsigned char*, const struct ssid_t*, QObject* parent = 0 ); | 266 | OWaveLanManagementSSID( const unsigned char*, const struct ssid_t*, QObject* parent = 0 ); |
268 | virtual ~OWaveLanManagementSSID(); | 267 | virtual ~OWaveLanManagementSSID(); |
269 | 268 | ||
270 | QString ID( bool decloak = false ) const; | 269 | QString ID( bool decloak = false ) const; |
271 | 270 | ||
272 | private: | 271 | private: |
273 | const struct ssid_t* _data; | 272 | const struct ssid_t* _data; |
274 | class Private; | 273 | class Private; |
275 | Private *d; | 274 | Private *d; |
276 | }; | 275 | }; |
277 | 276 | ||
278 | /*====================================================================================== | 277 | /*====================================================================================== |
279 | * OWaveLanManagementRates | 278 | * OWaveLanManagementRates |
280 | *======================================================================================*/ | 279 | *======================================================================================*/ |
281 | 280 | ||
282 | class OWaveLanManagementRates : public QObject | 281 | class OWaveLanManagementRates : public QObject |
283 | { | 282 | { |
284 | Q_OBJECT | 283 | Q_OBJECT |
285 | 284 | ||
286 | public: | 285 | public: |
287 | OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 ); | 286 | OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 ); |
288 | virtual ~OWaveLanManagementRates(); | 287 | virtual ~OWaveLanManagementRates(); |
289 | 288 | ||
290 | private: | 289 | private: |
291 | const struct rates_t* _data; | 290 | const struct rates_t* _data; |
292 | class Private; | 291 | class Private; |
293 | Private *d; | 292 | Private *d; |
294 | }; | 293 | }; |
295 | 294 | ||
296 | /*====================================================================================== | 295 | /*====================================================================================== |
297 | * OWaveLanManagementCF | 296 | * OWaveLanManagementCF |
298 | *======================================================================================*/ | 297 | *======================================================================================*/ |
299 | 298 | ||
300 | class OWaveLanManagementCF : public QObject | 299 | class OWaveLanManagementCF : public QObject |
301 | { | 300 | { |
302 | Q_OBJECT | 301 | Q_OBJECT |
303 | 302 | ||
304 | public: | 303 | public: |
305 | OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 ); | 304 | OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 ); |
306 | virtual ~OWaveLanManagementCF(); | 305 | virtual ~OWaveLanManagementCF(); |
307 | 306 | ||
308 | private: | 307 | private: |
309 | const struct cf_t* _data; | 308 | const struct cf_t* _data; |
310 | class Private; | 309 | class Private; |
311 | Private *d; | 310 | Private *d; |
312 | }; | 311 | }; |
313 | 312 | ||
314 | /*====================================================================================== | 313 | /*====================================================================================== |
315 | * OWaveLanManagementFH | 314 | * OWaveLanManagementFH |
316 | *======================================================================================*/ | 315 | *======================================================================================*/ |
317 | 316 | ||
318 | class OWaveLanManagementFH : public QObject | 317 | class OWaveLanManagementFH : public QObject |
319 | { | 318 | { |
320 | Q_OBJECT | 319 | Q_OBJECT |
321 | 320 | ||
322 | public: | 321 | public: |
323 | OWaveLanManagementFH( const unsigned char*, const struct fh_t*, QObject* parent = 0 ); | 322 | OWaveLanManagementFH( const unsigned char*, const struct fh_t*, QObject* parent = 0 ); |
324 | virtual ~OWaveLanManagementFH(); | 323 | virtual ~OWaveLanManagementFH(); |
325 | 324 | ||
326 | private: | 325 | private: |
327 | const struct fh_t* _data; | 326 | const struct fh_t* _data; |
328 | class Private; | 327 | class Private; |
329 | Private *d; | 328 | Private *d; |
330 | }; | 329 | }; |
331 | 330 | ||
332 | /*====================================================================================== | 331 | /*====================================================================================== |
333 | * OWaveLanManagementDS | 332 | * OWaveLanManagementDS |
334 | *======================================================================================*/ | 333 | *======================================================================================*/ |
335 | 334 | ||
336 | class OWaveLanManagementDS : public QObject | 335 | class OWaveLanManagementDS : public QObject |
337 | { | 336 | { |
338 | Q_OBJECT | 337 | Q_OBJECT |
339 | 338 | ||
340 | public: | 339 | public: |
341 | OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 ); | 340 | OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 ); |
342 | virtual ~OWaveLanManagementDS(); | 341 | virtual ~OWaveLanManagementDS(); |
343 | 342 | ||
344 | int channel() const; | 343 | int channel() const; |
345 | 344 | ||
346 | private: | 345 | private: |
347 | const struct ds_t* _data; | 346 | const struct ds_t* _data; |
348 | class Private; | 347 | class Private; |
349 | Private *d; | 348 | Private *d; |
350 | }; | 349 | }; |
351 | 350 | ||
352 | /*====================================================================================== | 351 | /*====================================================================================== |
353 | * OWaveLanManagementTim | 352 | * OWaveLanManagementTim |
354 | *======================================================================================*/ | 353 | *======================================================================================*/ |
355 | 354 | ||
356 | class OWaveLanManagementTim : public QObject | 355 | class OWaveLanManagementTim : public QObject |
357 | { | 356 | { |
358 | Q_OBJECT | 357 | Q_OBJECT |
359 | 358 | ||
360 | public: | 359 | public: |
361 | OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 ); | 360 | OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 ); |
362 | virtual ~OWaveLanManagementTim(); | 361 | virtual ~OWaveLanManagementTim(); |
363 | 362 | ||
364 | private: | 363 | private: |
365 | const struct tim_t* _data; | 364 | const struct tim_t* _data; |
366 | class Private; | 365 | class Private; |
367 | Private *d; | 366 | Private *d; |
368 | }; | 367 | }; |
369 | 368 | ||
370 | /*====================================================================================== | 369 | /*====================================================================================== |
371 | * OWaveLanManagementIBSS | 370 | * OWaveLanManagementIBSS |
372 | *======================================================================================*/ | 371 | *======================================================================================*/ |
373 | 372 | ||
374 | class OWaveLanManagementIBSS : public QObject | 373 | class OWaveLanManagementIBSS : public QObject |
375 | { | 374 | { |
376 | Q_OBJECT | 375 | Q_OBJECT |
377 | 376 | ||
378 | public: | 377 | public: |
379 | OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 ); | 378 | OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 ); |
380 | virtual ~OWaveLanManagementIBSS(); | 379 | virtual ~OWaveLanManagementIBSS(); |
381 | 380 | ||
382 | private: | 381 | private: |
383 | const struct ibss_t* _data; | 382 | const struct ibss_t* _data; |
384 | class Private; | 383 | class Private; |
385 | Private *d; | 384 | Private *d; |
386 | }; | 385 | }; |
387 | 386 | ||
388 | /*====================================================================================== | 387 | /*====================================================================================== |
389 | * OWaveLanManagementChallenge | 388 | * OWaveLanManagementChallenge |
390 | *======================================================================================*/ | 389 | *======================================================================================*/ |
391 | 390 | ||
392 | class OWaveLanManagementChallenge : public QObject | 391 | class OWaveLanManagementChallenge : public QObject |
393 | { | 392 | { |
394 | Q_OBJECT | 393 | Q_OBJECT |
395 | 394 | ||
396 | public: | 395 | public: |
397 | OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 ); | 396 | OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 ); |
398 | virtual ~OWaveLanManagementChallenge(); | 397 | virtual ~OWaveLanManagementChallenge(); |
399 | 398 | ||
400 | private: | 399 | private: |
401 | const struct challenge_t* _data; | 400 | const struct challenge_t* _data; |
402 | class Private; | 401 | class Private; |
403 | Private *d; | 402 | Private *d; |
404 | }; | 403 | }; |
405 | 404 | ||
406 | /*====================================================================================== | 405 | /*====================================================================================== |
407 | * OWaveLanDataPacket - type: data (T_DATA) | 406 | * OWaveLanDataPacket - type: data (T_DATA) |
408 | *======================================================================================*/ | 407 | *======================================================================================*/ |
409 | 408 | ||
410 | class OWaveLanDataPacket : public QObject | 409 | class OWaveLanDataPacket : public QObject |
411 | { | 410 | { |
412 | Q_OBJECT | 411 | Q_OBJECT |
413 | 412 | ||
414 | public: | 413 | public: |
415 | OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 ); | 414 | OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 ); |
416 | virtual ~OWaveLanDataPacket(); | 415 | virtual ~OWaveLanDataPacket(); |
417 | 416 | ||
418 | private: | 417 | private: |
419 | const struct ieee_802_11_data_header* _header; | 418 | const struct ieee_802_11_data_header* _header; |
420 | class Private; | 419 | class Private; |
421 | Private *d; | 420 | Private *d; |
422 | }; | 421 | }; |
423 | 422 | ||
424 | /*====================================================================================== | 423 | /*====================================================================================== |
425 | * OWaveLanControlPacket - type: control (T_CTRL) | 424 | * OWaveLanControlPacket - type: control (T_CTRL) |
426 | *======================================================================================*/ | 425 | *======================================================================================*/ |
427 | 426 | ||
428 | class OWaveLanControlPacket : public QObject | 427 | class OWaveLanControlPacket : public QObject |
429 | { | 428 | { |
430 | Q_OBJECT | 429 | Q_OBJECT |
431 | 430 | ||
432 | public: | 431 | public: |
433 | OWaveLanControlPacket( const unsigned char*, const struct ieee_802_11_control_header*, OWaveLanPacket* parent = 0 ); | 432 | OWaveLanControlPacket( const unsigned char*, const struct ieee_802_11_control_header*, OWaveLanPacket* parent = 0 ); |
434 | virtual ~OWaveLanControlPacket(); | 433 | virtual ~OWaveLanControlPacket(); |
435 | 434 | ||
436 | QString controlType() const; | 435 | QString controlType() const; |
437 | 436 | ||
438 | private: | 437 | private: |
439 | const struct ieee_802_11_control_header* _header; | 438 | const struct ieee_802_11_control_header* _header; |
440 | class Private; | 439 | class Private; |
441 | Private *d; | 440 | Private *d; |
442 | }; | 441 | }; |
443 | 442 | ||
444 | /*====================================================================================== | 443 | /*====================================================================================== |
445 | * OLLCPacket - IEEE 802.2 Link Level Control | 444 | * OLLCPacket - IEEE 802.2 Link Level Control |
446 | *======================================================================================*/ | 445 | *======================================================================================*/ |
447 | 446 | ||
448 | class OLLCPacket : public QObject | 447 | class OLLCPacket : public QObject |
449 | { | 448 | { |
450 | Q_OBJECT | 449 | Q_OBJECT |
451 | 450 | ||
452 | public: | 451 | public: |
453 | OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 ); | 452 | OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 ); |
454 | virtual ~OLLCPacket(); | 453 | virtual ~OLLCPacket(); |
455 | 454 | ||
456 | private: | 455 | private: |
457 | const struct ieee_802_11_802_2_header* _header; | 456 | const struct ieee_802_11_802_2_header* _header; |
458 | class Private; | 457 | class Private; |
459 | Private *d; | 458 | Private *d; |
460 | }; | 459 | }; |
461 | 460 | ||
462 | /*====================================================================================== | 461 | /*====================================================================================== |
463 | * OIPPacket | 462 | * OIPPacket |
464 | *======================================================================================*/ | 463 | *======================================================================================*/ |
465 | 464 | ||
466 | class OIPPacket : public QObject | 465 | class OIPPacket : public QObject |
467 | { | 466 | { |
468 | Q_OBJECT | 467 | Q_OBJECT |
469 | 468 | ||
470 | public: | 469 | public: |
471 | OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 ); | 470 | OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 ); |
472 | virtual ~OIPPacket(); | 471 | virtual ~OIPPacket(); |
473 | 472 | ||
474 | QHostAddress fromIPAddress() const; | 473 | QHostAddress fromIPAddress() const; |
475 | QHostAddress toIPAddress() const; | 474 | QHostAddress toIPAddress() const; |
476 | 475 | ||
477 | int tos() const; | 476 | int tos() const; |
478 | int len() const; | 477 | int len() const; |
479 | int id() const; | 478 | int id() const; |
480 | int offset() const; | 479 | int offset() const; |
481 | int ttl() const; | 480 | int ttl() const; |
482 | int protocol() const; | 481 | int protocol() const; |
483 | int checksum() const; | 482 | int checksum() const; |
484 | 483 | ||
485 | private: | 484 | private: |
486 | const struct iphdr* _iphdr; | 485 | const struct iphdr* _iphdr; |
487 | class Private; | 486 | class Private; |
488 | Private *d; | 487 | Private *d; |
489 | }; | 488 | }; |
490 | 489 | ||
491 | /*====================================================================================== | 490 | /*====================================================================================== |
492 | * OARPPacket | 491 | * OARPPacket |
493 | *======================================================================================*/ | 492 | *======================================================================================*/ |
494 | 493 | ||
495 | class OARPPacket : public QObject | 494 | class OARPPacket : public QObject |
496 | { | 495 | { |
497 | Q_OBJECT | 496 | Q_OBJECT |
498 | 497 | ||
499 | public: | 498 | public: |
500 | OARPPacket( const unsigned char*, const struct myarphdr*, QObject* parent = 0 ); | 499 | OARPPacket( const unsigned char*, const struct myarphdr*, QObject* parent = 0 ); |
501 | virtual ~OARPPacket(); | 500 | virtual ~OARPPacket(); |
502 | 501 | ||
503 | QHostAddress senderIPV4Address() const; | 502 | QHostAddress senderIPV4Address() const; |
504 | OMacAddress senderMacAddress() const; | 503 | OMacAddress senderMacAddress() const; |
505 | QHostAddress targetIPV4Address() const; | 504 | QHostAddress targetIPV4Address() const; |
506 | OMacAddress targetMacAddress() const; | 505 | OMacAddress targetMacAddress() const; |
507 | 506 | ||
508 | //int type() const; | 507 | //int type() const; |
509 | QString type() const; | 508 | QString type() const; |
510 | 509 | ||
511 | private: | 510 | private: |
512 | const struct myarphdr* _arphdr; | 511 | const struct myarphdr* _arphdr; |
513 | class Private; | 512 | class Private; |
514 | Private *d; | 513 | Private *d; |
515 | }; | 514 | }; |
516 | 515 | ||
517 | /*====================================================================================== | 516 | /*====================================================================================== |
518 | * OUDPPacket | 517 | * OUDPPacket |
519 | *======================================================================================*/ | 518 | *======================================================================================*/ |
520 | 519 | ||
521 | class OUDPPacket : public QObject | 520 | class OUDPPacket : public QObject |
522 | { | 521 | { |
523 | Q_OBJECT | 522 | Q_OBJECT |
524 | 523 | ||
525 | public: | 524 | public: |
526 | OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 ); | 525 | OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 ); |
527 | virtual ~OUDPPacket(); | 526 | virtual ~OUDPPacket(); |
528 | 527 | ||
529 | int fromPort() const; | 528 | int fromPort() const; |
530 | int toPort() const; | 529 | int toPort() const; |
531 | int length() const; | 530 | int length() const; |
532 | int checksum() const; | 531 | int checksum() const; |
533 | 532 | ||
534 | private: | 533 | private: |
535 | const struct udphdr* _udphdr; | 534 | const struct udphdr* _udphdr; |
536 | class Private; | 535 | class Private; |
537 | Private *d; | 536 | Private *d; |
538 | }; | 537 | }; |
539 | 538 | ||
540 | /*====================================================================================== | 539 | /*====================================================================================== |
541 | * ODHCPPacket | 540 | * ODHCPPacket |
542 | *======================================================================================*/ | 541 | *======================================================================================*/ |
543 | 542 | ||
544 | class ODHCPPacket : public QObject | 543 | class ODHCPPacket : public QObject |
545 | { | 544 | { |
546 | Q_OBJECT | 545 | Q_OBJECT |
547 | 546 | ||
548 | public: | 547 | public: |
549 | ODHCPPacket( const unsigned char*, const struct dhcp_packet*, QObject* parent = 0 ); | 548 | ODHCPPacket( const unsigned char*, const struct dhcp_packet*, QObject* parent = 0 ); |
550 | virtual ~ODHCPPacket(); | 549 | virtual ~ODHCPPacket(); |
551 | 550 | ||
552 | QHostAddress clientAddress() const; | 551 | QHostAddress clientAddress() const; |
553 | QHostAddress yourAddress() const; | 552 | QHostAddress yourAddress() const; |
554 | QHostAddress serverAddress() const; | 553 | QHostAddress serverAddress() const; |
555 | QHostAddress relayAddress() const; | 554 | QHostAddress relayAddress() const; |
556 | 555 | ||
557 | OMacAddress clientMacAddress() const; | 556 | OMacAddress clientMacAddress() const; |
558 | 557 | ||
559 | bool isRequest() const; | 558 | bool isRequest() const; |
560 | bool isReply() const; | 559 | bool isReply() const; |
561 | QString type() const; | 560 | QString type() const; |
562 | 561 | ||
563 | private: | 562 | private: |
564 | const struct dhcp_packet* _dhcphdr; | 563 | const struct dhcp_packet* _dhcphdr; |
565 | unsigned char _type; | 564 | unsigned char _type; |
566 | class Private; | 565 | class Private; |
567 | Private *d; | 566 | Private *d; |
568 | }; | 567 | }; |
569 | 568 | ||
570 | /*====================================================================================== | 569 | /*====================================================================================== |
571 | * OTCPPacket | 570 | * OTCPPacket |
572 | *======================================================================================*/ | 571 | *======================================================================================*/ |
573 | 572 | ||
574 | class OTCPPacket : public QObject | 573 | class OTCPPacket : public QObject |
575 | { | 574 | { |
576 | Q_OBJECT | 575 | Q_OBJECT |
577 | 576 | ||
578 | public: | 577 | public: |
579 | OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 ); | 578 | OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 ); |
580 | virtual ~OTCPPacket(); | 579 | virtual ~OTCPPacket(); |
581 | 580 | ||
582 | int fromPort() const; | 581 | int fromPort() const; |
583 | int toPort() const; | 582 | int toPort() const; |
584 | int seq() const; | 583 | int seq() const; |
585 | int ack() const; | 584 | int ack() const; |
586 | int window() const; | 585 | int window() const; |
587 | int checksum() const; | 586 | int checksum() const; |
588 | 587 | ||
589 | private: | 588 | private: |
590 | const struct tcphdr* _tcphdr; | 589 | const struct tcphdr* _tcphdr; |
591 | class Private; | 590 | class Private; |
592 | Private *d; | 591 | Private *d; |
593 | }; | 592 | }; |
594 | 593 | ||
595 | 594 | ||
596 | /*====================================================================================== | 595 | /*====================================================================================== |
597 | * OPacketCapturer | 596 | * OPacketCapturer |
598 | *======================================================================================*/ | 597 | *======================================================================================*/ |
599 | 598 | ||
600 | /** | 599 | /** |
601 | * @brief A class based wrapper for network packet capturing. | 600 | * @brief A class based wrapper for network packet capturing. |
602 | * | 601 | * |
603 | * This class is the base of a high-level interface to the well known packet capturing | 602 | * This class is the base of a high-level interface to the well known packet capturing |
604 | * library libpcap. | 603 | * library libpcap. |
605 | * @see http://tcpdump.org | 604 | * @see http://tcpdump.org |
606 | */ | 605 | */ |
607 | class OPacketCapturer : public QObject | 606 | class OPacketCapturer : public QObject |
608 | { | 607 | { |
609 | Q_OBJECT | 608 | Q_OBJECT |
610 | 609 | ||
611 | public: | 610 | public: |
612 | /** | 611 | /** |
613 | * Constructor. | 612 | * Constructor. |
614 | */ | 613 | */ |
615 | OPacketCapturer( QObject* parent = 0, const char* name = 0 ); | 614 | OPacketCapturer( QObject* parent = 0, const char* name = 0 ); |
616 | /** | 615 | /** |
617 | * Destructor. | 616 | * Destructor. |
618 | */ | 617 | */ |
619 | ~OPacketCapturer(); | 618 | ~OPacketCapturer(); |
620 | /** | 619 | /** |
621 | * Set the packet capturer to use blocking or non-blocking IO. This can be useful when | 620 | * Set the packet capturer to use blocking or non-blocking IO. This can be useful when |
622 | * not using the socket notifier, e.g. without an application object. | 621 | * not using the socket notifier, e.g. without an application object. |
623 | */ | 622 | */ |
624 | void setBlocking( bool ); | 623 | void setBlocking( bool ); |
625 | /** | 624 | /** |
626 | * @returns true if the packet capturer uses blocking IO calls. | 625 | * @returns true if the packet capturer uses blocking IO calls. |
627 | */ | 626 | */ |
628 | bool blocking() const; | 627 | bool blocking() const; |
629 | /** | 628 | /** |
630 | * Close the packet capturer. This is automatically done in the destructor. | 629 | * Close the packet capturer. This is automatically done in the destructor. |
631 | */ | 630 | */ |
632 | void close(); | 631 | void close(); |
633 | /** | 632 | /** |
634 | * Close the output capture file. | 633 | * Close the output capture file. |
635 | */ | 634 | */ |
636 | void closeDumpFile(); | 635 | void closeDumpFile(); |
637 | /** | 636 | /** |
638 | * @returns the data link type. | 637 | * @returns the data link type. |
639 | * @see <pcap.h> for possible values. | 638 | * @see <pcap.h> for possible values. |
640 | */ | 639 | */ |
641 | int dataLink() const; | 640 | int dataLink() const; |
642 | /** | 641 | /** |
643 | * Dump a packet to the output capture file. | 642 | * Dump a packet to the output capture file. |
644 | */ | 643 | */ |
645 | void dump( OPacket* ); | 644 | void dump( OPacket* ); |
646 | /** | 645 | /** |
647 | * @returns the file descriptor of the packet capturer. This is only useful, if | 646 | * @returns the file descriptor of the packet capturer. This is only useful, if |
648 | * not using the socket notifier, e.g. without an application object. | 647 | * not using the socket notifier, e.g. without an application object. |
649 | */ | 648 | */ |
650 | int fileno() const; | 649 | int fileno() const; |
651 | /** | 650 | /** |
652 | * @returns the next @ref OPacket from the packet capturer. | 651 | * @returns the next @ref OPacket from the packet capturer. |
653 | * @note If blocking mode is true then this call might block. | 652 | * @note If blocking mode is true then this call might block. |
654 | */ | 653 | */ |
655 | OPacket* next(); | 654 | OPacket* next(); |
656 | /** | 655 | /** |
657 | * @returns the next @ref OPacket from the packet capturer, if | 656 | * @returns the next @ref OPacket from the packet capturer, if |
658 | * one arrives within @a time milliseconds. | 657 | * one arrives within @a time milliseconds. |
659 | */ | 658 | */ |
660 | OPacket* next( int time ); | 659 | OPacket* next( int time ); |
661 | /** | 660 | /** |
662 | * Open the packet capturer to capture packets in live-mode from @a interface. | 661 | * Open the packet capturer to capture packets in live-mode from @a interface. |
663 | */ | 662 | */ |
664 | bool open( const QString& interface ); | 663 | bool open( const QString& interface ); |
665 | /** | 664 | /** |
666 | * Open the packet capturer to capture packets in offline-mode from @a filename. | 665 | * Open the packet capturer to capture packets in offline-mode from @a filename. |
667 | */ | 666 | */ |
668 | bool openCaptureFile( const QString& filename ); | 667 | bool openCaptureFile( const QString& filename ); |
669 | /** | 668 | /** |
670 | * Open a prerecorded tcpdump compatible capture file for use with @ref dump() | 669 | * Open a prerecorded tcpdump compatible capture file for use with @ref dump() |
671 | */ | 670 | */ |
672 | bool openDumpFile( const QString& filename ); | 671 | bool openDumpFile( const QString& filename ); |
673 | /** | 672 | /** |
674 | * @returns true if the packet capturer is open | 673 | * @returns true if the packet capturer is open |
675 | */ | 674 | */ |
676 | bool isOpen() const; | 675 | bool isOpen() const; |
677 | /** | 676 | /** |
678 | * @returns the snapshot length of this packet capturer | 677 | * @returns the snapshot length of this packet capturer |
679 | */ | 678 | */ |
680 | int snapShot() const; | 679 | int snapShot() const; |
681 | /** | 680 | /** |
682 | * @returns true if the input capture file has a different byte-order | 681 | * @returns true if the input capture file has a different byte-order |
683 | * than the byte-order of the running system. | 682 | * than the byte-order of the running system. |
684 | */ | 683 | */ |
685 | bool swapped() const; | 684 | bool swapped() const; |
686 | /** | 685 | /** |
687 | * @returns the libpcap version string used to write the input capture file. | 686 | * @returns the libpcap version string used to write the input capture file. |
688 | */ | 687 | */ |
689 | QString version() const; | 688 | QString version() const; |
690 | /** | 689 | /** |
691 | * @returns the packet statistic database. | 690 | * @returns the packet statistic database. |
692 | * @see QMap | 691 | * @see QMap |
693 | */ | 692 | */ |
694 | const QMap<QString,int>& statistics() const; | 693 | const QMap<QString,int>& statistics() const; |
695 | /** | 694 | /** |
696 | * Enable or disable the auto-delete option. | 695 | * Enable or disable the auto-delete option. |
697 | * If auto-delete is enabled, then the packet capturer will delete a packet right | 696 | * If auto-delete is enabled, then the packet capturer will delete a packet right |
698 | * after it has been emit'ted. This is the default, which is useful if the packet | 697 | * after it has been emit'ted. This is the default, which is useful if the packet |
699 | * capturer has the only reference to the packets. If you pass the packet for adding | 698 | * capturer has the only reference to the packets. If you pass the packet for adding |
700 | * into a collection or do processing after the SLOT, the auto delete must be disabled. | 699 | * into a collection or do processing after the SLOT, the auto delete must be disabled. |
701 | */ | 700 | */ |
702 | void setAutoDelete( bool enable ); | 701 | void setAutoDelete( bool enable ); |
703 | /** | 702 | /** |
704 | * @returns the auto-delete value. | 703 | * @returns the auto-delete value. |
705 | */ | 704 | */ |
706 | bool autoDelete() const; | 705 | bool autoDelete() const; |
707 | 706 | ||
708 | signals: | 707 | signals: |
709 | /** | 708 | /** |
710 | * This signal is emitted, when a packet has been received. | 709 | * This signal is emitted, when a packet has been received. |
711 | */ | 710 | */ |
712 | void receivedPacket( Opie::Net::OPacket* ); | 711 | void receivedPacket( Opie::Net::OPacket* ); |
713 | 712 | ||
714 | protected slots: | 713 | protected slots: |
715 | void readyToReceive(); | 714 | void readyToReceive(); |
716 | 715 | ||
717 | protected: | 716 | protected: |
718 | QString _name; // devicename | 717 | QString _name; // devicename |
719 | bool _open; // check this before doing pcap calls | 718 | bool _open; // check this before doing pcap calls |
720 | pcap_t* _pch; // pcap library handle | 719 | pcap_t* _pch; // pcap library handle |
721 | pcap_dumper_t* _pcd; // pcap dumper handle | 720 | pcap_dumper_t* _pcd; // pcap dumper handle |
722 | QSocketNotifier* _sn; // socket notifier for main loop | 721 | QSocketNotifier* _sn; // socket notifier for main loop |
723 | mutable char _errbuf[PCAP_ERRBUF_SIZE]; // holds error strings from libpcap | 722 | mutable char _errbuf[PCAP_ERRBUF_SIZE]; // holds error strings from libpcap |
724 | QMap<QString, int> _stats; // statistics; | 723 | QMap<QString, int> _stats; // statistics; |
725 | bool _autodelete; // if we auto delete packets after emit | 724 | bool _autodelete; // if we auto delete packets after emit |
726 | class Private; // Private Forward declaration | 725 | class Private; // Private Forward declaration |
727 | Private *d; // if we need to add data | 726 | Private *d; // if we need to add data |
728 | }; | 727 | }; |
729 | } | 728 | } |
730 | } | 729 | } |
731 | 730 | ||
732 | #endif // OPCAP_H | 731 | #endif // OPCAP_H |
733 | 732 | ||