author | mickeyl <mickeyl> | 2005-06-14 13:14:38 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2005-06-14 13:14:38 (UTC) |
commit | c1194d42d8456417452b125bd6c2c5048d7bbe02 (patch) (unidiff) | |
tree | dbc31e47615d840745eafd0635f724548ece6281 | |
parent | 9e210f138184f9cc93e28dd894243fc7bfea1b0f (diff) | |
download | opie-c1194d42d8456417452b125bd6c2c5048d7bbe02.zip opie-c1194d42d8456417452b125bd6c2c5048d7bbe02.tar.gz opie-c1194d42d8456417452b125bd6c2c5048d7bbe02.tar.bz2 |
enable OPcmciaSocket::manufacturer()
Did I mention Qt2 sucks? We don't even have a QPair :/
-rw-r--r-- | libopie2/opiecore/linux/opcmciasystem.cpp | 24 | ||||
-rw-r--r-- | libopie2/opiecore/linux/opcmciasystem.h | 6 |
2 files changed, 20 insertions, 10 deletions
diff --git a/libopie2/opiecore/linux/opcmciasystem.cpp b/libopie2/opiecore/linux/opcmciasystem.cpp index 929e289..2eece6b 100644 --- a/libopie2/opiecore/linux/opcmciasystem.cpp +++ b/libopie2/opiecore/linux/opcmciasystem.cpp | |||
@@ -1,379 +1,391 @@ | |||
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; version 2 of the License. | 10 | - . .-<_> .<> Foundation; version 2 of the License. |
11 | ._= =} : | 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 | 29 | ||
30 | #include "opcmciasystem.h" | 30 | #include "opcmciasystem.h" |
31 | using namespace Opie::Core; | 31 | using namespace Opie::Core; |
32 | 32 | ||
33 | /* OPIE */ | 33 | /* OPIE */ |
34 | #include <opie2/odebug.h> | 34 | #include <opie2/odebug.h> |
35 | 35 | ||
36 | /* QT */ | 36 | /* QT */ |
37 | #include <qfile.h> | 37 | #include <qfile.h> |
38 | #include <qtextstream.h> | 38 | #include <qtextstream.h> |
39 | 39 | ||
40 | /* STD */ | 40 | /* STD */ |
41 | #include <errno.h> | 41 | #include <errno.h> |
42 | #include <fcntl.h> | 42 | #include <fcntl.h> |
43 | #include <string.h> | 43 | #include <string.h> |
44 | #include <stdlib.h> | 44 | #include <stdlib.h> |
45 | #include <sys/ioctl.h> | 45 | #include <sys/ioctl.h> |
46 | #include <sys/types.h> | 46 | #include <sys/types.h> |
47 | #include <sys/stat.h> | 47 | #include <sys/stat.h> |
48 | #include <unistd.h> | 48 | #include <unistd.h> |
49 | 49 | ||
50 | #define PROC_DEVICES "/proc/devices" | 50 | #define PROC_DEVICES "/proc/devices" |
51 | 51 | ||
52 | #define OPCMCIA_DEBUG 1 | ||
53 | |||
52 | /*====================================================================================== | 54 | /*====================================================================================== |
53 | * OPcmciaSystem | 55 | * OPcmciaSystem |
54 | *======================================================================================*/ | 56 | *======================================================================================*/ |
55 | 57 | ||
56 | OPcmciaSystem* OPcmciaSystem::_instance = 0; | 58 | OPcmciaSystem* OPcmciaSystem::_instance = 0; |
57 | 59 | ||
58 | OPcmciaSystem::OPcmciaSystem() | 60 | OPcmciaSystem::OPcmciaSystem() |
59 | :_major( 0 ) | 61 | :_major( 0 ) |
60 | { | 62 | { |
61 | qDebug( "OPcmciaSystem::OPcmciaSystem()" ); | 63 | qDebug( "OPcmciaSystem::OPcmciaSystem()" ); |
62 | 64 | ||
63 | // get major node number out of /proc/devices | 65 | // get major node number out of /proc/devices |
64 | QFile procfile( PROC_DEVICES ); | 66 | QFile procfile( PROC_DEVICES ); |
65 | if ( procfile.exists() && procfile.open( IO_ReadOnly ) ) | 67 | if ( procfile.exists() && procfile.open( IO_ReadOnly ) ) |
66 | { | 68 | { |
67 | QTextStream devstream( &procfile ); | 69 | QTextStream devstream( &procfile ); |
68 | devstream.readLine(); // skip header | 70 | devstream.readLine(); // skip header |
69 | while ( !devstream.atEnd() && !_major ) | 71 | while ( !devstream.atEnd() && !_major ) |
70 | { | 72 | { |
71 | int nodenumber; | 73 | int nodenumber; |
72 | QString driver; | 74 | QString driver; |
73 | devstream >> nodenumber >> driver; | 75 | devstream >> nodenumber >> driver; |
74 | if ( driver == "pcmcia" ) | 76 | if ( driver == "pcmcia" ) |
75 | { | 77 | { |
76 | qDebug( "OPcmciaSystem::OPcmciaSystem(): gotcha! pcmcia node number = %d", nodenumber ); | 78 | qDebug( "OPcmciaSystem::OPcmciaSystem(): gotcha! pcmcia node number = %d", nodenumber ); |
77 | _major = nodenumber; | 79 | _major = nodenumber; |
78 | break; | 80 | break; |
79 | } | 81 | } |
80 | } | 82 | } |
81 | } | 83 | } |
82 | else | 84 | else |
83 | { | 85 | { |
84 | qWarning( "OPcmciaSystem::OPcmciaSystem() - can't open /proc/devices - continuing with limited functionality." ); | 86 | qWarning( "OPcmciaSystem::OPcmciaSystem() - can't open /proc/devices - continuing with limited functionality." ); |
85 | } | 87 | } |
86 | 88 | ||
87 | synchronize(); | 89 | synchronize(); |
88 | } | 90 | } |
89 | 91 | ||
90 | void OPcmciaSystem::synchronize() | 92 | void OPcmciaSystem::synchronize() |
91 | { | 93 | { |
92 | qDebug( "OPcmciaSystem::synchronize()" ); | 94 | qDebug( "OPcmciaSystem::synchronize()" ); |
93 | _interfaces.clear(); | 95 | _interfaces.clear(); |
94 | 96 | ||
95 | //FIXME: Use cardmgr subsystem ioctls | 97 | //FIXME: Use cardmgr subsystem ioctls |
96 | 98 | ||
97 | QString fileName; | 99 | QString fileName; |
98 | if ( QFile::exists( "/var/run/stab" ) ) { fileName = "/var/run/stab"; } | 100 | if ( QFile::exists( "/var/run/stab" ) ) { fileName = "/var/run/stab"; } |
99 | else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) { fileName = "/var/state/pcmcia/stab"; } | 101 | else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) { fileName = "/var/state/pcmcia/stab"; } |
100 | else { fileName = "/var/lib/pcmcia/stab"; } | 102 | else { fileName = "/var/lib/pcmcia/stab"; } |
101 | QFile cardinfofile( fileName ); | 103 | QFile cardinfofile( fileName ); |
102 | if ( !cardinfofile.exists() || !cardinfofile.open( IO_ReadOnly ) ) | 104 | if ( !cardinfofile.exists() || !cardinfofile.open( IO_ReadOnly ) ) |
103 | { | 105 | { |
104 | qWarning( "pcmcia info file not found or unaccessible" ); | 106 | qWarning( "pcmcia info file not found or unaccessible" ); |
105 | return; | 107 | return; |
106 | } | 108 | } |
107 | QTextStream cardinfo( &cardinfofile ); | 109 | QTextStream cardinfo( &cardinfofile ); |
108 | while ( !cardinfo.atEnd() ) | 110 | while ( !cardinfo.atEnd() ) |
109 | { | 111 | { |
110 | QString strSocket; | 112 | QString strSocket; |
111 | int numSocket; | 113 | int numSocket; |
112 | char colon; | 114 | char colon; |
113 | QString cardName; | 115 | QString cardName; |
114 | cardinfo >> strSocket >> numSocket >> colon; | 116 | cardinfo >> strSocket >> numSocket >> colon; |
115 | cardName = cardinfo.readLine().stripWhiteSpace(); | 117 | cardName = cardinfo.readLine().stripWhiteSpace(); |
116 | qDebug( "strSocket = '%s', numSocket = '%d', colon = '%c', cardName = '%s'", (const char*) strSocket, numSocket, colon, ( const char*) cardName ); | 118 | qDebug( "strSocket = '%s', numSocket = '%d', colon = '%c', cardName = '%s'", (const char*) strSocket, numSocket, colon, ( const char*) cardName ); |
117 | if ( strSocket == "Socket" && colon == ':' ) | 119 | if ( strSocket == "Socket" && colon == ':' ) |
118 | { | 120 | { |
119 | _interfaces.append( new OPcmciaSocket( _major, numSocket, this, (const char*) cardName ) ); | 121 | _interfaces.append( new OPcmciaSocket( _major, numSocket, this, (const char*) cardName ) ); |
120 | } | 122 | } |
121 | else | 123 | else |
122 | { | 124 | { |
123 | continue; | 125 | continue; |
124 | } | 126 | } |
125 | } | 127 | } |
126 | } | 128 | } |
127 | 129 | ||
128 | 130 | ||
129 | int OPcmciaSystem::count() const | 131 | int OPcmciaSystem::count() const |
130 | { | 132 | { |
131 | return _interfaces.count(); | 133 | return _interfaces.count(); |
132 | } | 134 | } |
133 | 135 | ||
134 | 136 | ||
135 | int OPcmciaSystem::cardCount() const | 137 | int OPcmciaSystem::cardCount() const |
136 | { | 138 | { |
137 | int nonEmpty = 0; | 139 | int nonEmpty = 0; |
138 | OPcmciaSystem::CardIterator it = iterator(); | 140 | OPcmciaSystem::CardIterator it = iterator(); |
139 | while ( it.current() ) | 141 | while ( it.current() ) |
140 | { | 142 | { |
141 | if ( !it.current()->isEmpty() ) nonEmpty++; | 143 | if ( !it.current()->isEmpty() ) nonEmpty++; |
142 | ++it; | 144 | ++it; |
143 | } | 145 | } |
144 | return nonEmpty; | 146 | return nonEmpty; |
145 | } | 147 | } |
146 | 148 | ||
147 | 149 | ||
148 | OPcmciaSocket* OPcmciaSystem::socket( unsigned int number ) | 150 | OPcmciaSocket* OPcmciaSystem::socket( unsigned int number ) |
149 | { | 151 | { |
150 | return _interfaces.at( number ); | 152 | return _interfaces.at( number ); |
151 | } | 153 | } |
152 | 154 | ||
153 | 155 | ||
154 | OPcmciaSystem* OPcmciaSystem::instance() | 156 | OPcmciaSystem* OPcmciaSystem::instance() |
155 | { | 157 | { |
156 | if ( !_instance ) _instance = new OPcmciaSystem(); | 158 | if ( !_instance ) _instance = new OPcmciaSystem(); |
157 | return _instance; | 159 | return _instance; |
158 | } | 160 | } |
159 | 161 | ||
160 | 162 | ||
161 | OPcmciaSystem::CardIterator OPcmciaSystem::iterator() const | 163 | OPcmciaSystem::CardIterator OPcmciaSystem::iterator() const |
162 | { | 164 | { |
163 | return OPcmciaSystem::CardIterator( _interfaces ); | 165 | return OPcmciaSystem::CardIterator( _interfaces ); |
164 | } | 166 | } |
165 | 167 | ||
166 | 168 | ||
167 | /*====================================================================================== | 169 | /*====================================================================================== |
168 | * OPcmciaSocket | 170 | * OPcmciaSocket |
169 | *======================================================================================*/ | 171 | *======================================================================================*/ |
170 | 172 | ||
171 | OPcmciaSocket::OPcmciaSocket( int major, int socket, QObject* parent, const char* name ) | 173 | OPcmciaSocket::OPcmciaSocket( int major, int socket, QObject* parent, const char* name ) |
172 | :QObject( parent, name ), _major( major ), _socket( socket ) | 174 | :QObject( parent, name ), _major( major ), _socket( socket ) |
173 | { | 175 | { |
174 | qDebug( "OPcmciaSocket::OPcmciaSocket()" ); | 176 | qDebug( "OPcmciaSocket::OPcmciaSocket()" ); |
175 | init(); | 177 | init(); |
176 | } | 178 | } |
177 | 179 | ||
178 | 180 | ||
179 | OPcmciaSocket::~OPcmciaSocket() | 181 | OPcmciaSocket::~OPcmciaSocket() |
180 | { | 182 | { |
181 | qDebug( "OPcmciaSocket::~OPcmciaSocket()" ); | 183 | qDebug( "OPcmciaSocket::~OPcmciaSocket()" ); |
182 | cleanup(); | 184 | cleanup(); |
183 | } | 185 | } |
184 | 186 | ||
185 | 187 | ||
186 | /* internal */ void OPcmciaSocket::init() | 188 | /* internal */ void OPcmciaSocket::init() |
187 | { | 189 | { |
188 | // open control socket and gather file descriptor | 190 | // open control socket and gather file descriptor |
189 | if ( _major ) | 191 | if ( _major ) |
190 | { | 192 | { |
191 | dev_t dev = makedev( _major, _socket ); | 193 | dev_t dev = makedev( _major, _socket ); |
194 | |||
195 | #ifdef OPCMCIA_DEBUG | ||
196 | QString filename = "/tmp/opcmciasystem-debug"; | ||
197 | if ( QFile::exists( filename ) ) | ||
198 | #else | ||
192 | QString filename = QString().sprintf( "/tmp/opcmciasystem-%d", ::getpid() ); | 199 | QString filename = QString().sprintf( "/tmp/opcmciasystem-%d", ::getpid() ); |
193 | if ( ::mknod( (const char*) filename, ( S_IFCHR|S_IREAD|S_IWRITE ), dev ) == 0 ) | 200 | if ( ::mknod( (const char*) filename, ( S_IFCHR|S_IREAD|S_IWRITE ), dev ) == 0 ) |
201 | #endif | ||
194 | { | 202 | { |
195 | _fd = ::open( (const char*) filename, O_RDONLY); | 203 | _fd = ::open( (const char*) filename, O_RDONLY); |
196 | if ( !_fd ) | 204 | if ( !_fd ) |
197 | { | 205 | { |
198 | qWarning( "OPcmciaSocket::init() - can't open control socket (%s)", strerror( errno ) ); | 206 | qWarning( "OPcmciaSocket::init() - can't open control socket (%s)", strerror( errno ) ); |
199 | } | 207 | } |
200 | else | 208 | else |
201 | { | 209 | { |
202 | ::unlink( (const char*) filename ); | 210 | ::unlink( (const char*) filename ); |
203 | } | 211 | } |
204 | } | 212 | } |
205 | else | 213 | else |
206 | { | 214 | { |
207 | qWarning( "OPcmciaSocket::init() - can't create device node (%s)", strerror( errno ) ); | 215 | qWarning( "OPcmciaSocket::init() - can't create device node '%s' (%s)", (const char*) filename, strerror( errno ) ); |
208 | } | 216 | } |
209 | } | 217 | } |
210 | } | 218 | } |
211 | 219 | ||
212 | /* internal */ void OPcmciaSocket::cleanup() | 220 | /* internal */ void OPcmciaSocket::cleanup() |
213 | { | 221 | { |
214 | // close control socket | 222 | // close control socket |
215 | } | 223 | } |
216 | 224 | ||
217 | /* internal */ bool OPcmciaSocket::getTuple( cisdata_t tuple ) const | 225 | /* internal */ bool OPcmciaSocket::getTuple( cisdata_t tuple ) const |
218 | { | 226 | { |
219 | _ioctlarg.tuple.DesiredTuple = tuple; | 227 | _ioctlarg.tuple.DesiredTuple = tuple; |
220 | _ioctlarg.tuple.Attributes = TUPLE_RETURN_COMMON; | 228 | _ioctlarg.tuple.Attributes = TUPLE_RETURN_COMMON; |
221 | _ioctlarg.tuple.TupleOffset = 0; | 229 | _ioctlarg.tuple.TupleOffset = 0; |
222 | 230 | ||
223 | int result; | 231 | int result; |
224 | result = ::ioctl(_fd, DS_GET_FIRST_TUPLE, &_ioctlarg); | 232 | result = ::ioctl(_fd, DS_GET_FIRST_TUPLE, &_ioctlarg); |
225 | if ( result != 0 ) | 233 | if ( result != 0 ) |
226 | { | 234 | { |
227 | qWarning( "OPcmciaSocket::getTuple() - DS_GET_FIRST_TUPLE failed (%s)", strerror( errno ) ); | 235 | qWarning( "OPcmciaSocket::getTuple() - DS_GET_FIRST_TUPLE failed (%s)", strerror( errno ) ); |
228 | return false; | 236 | return false; |
229 | } | 237 | } |
230 | 238 | ||
231 | result = ::ioctl(_fd, DS_GET_TUPLE_DATA, &_ioctlarg); | 239 | result = ::ioctl(_fd, DS_GET_TUPLE_DATA, &_ioctlarg); |
232 | if ( result != 0 ) | 240 | if ( result != 0 ) |
233 | { | 241 | { |
234 | qWarning( "OPcmciaSocket::getTuple() - DS_GET_TUPLE_DATA failed (%s)", strerror( errno ) ); | 242 | qWarning( "OPcmciaSocket::getTuple() - DS_GET_TUPLE_DATA failed (%s)", strerror( errno ) ); |
235 | return false; | 243 | return false; |
236 | } | 244 | } |
237 | 245 | ||
238 | result = ::ioctl( _fd, DS_PARSE_TUPLE, &_ioctlarg ); | 246 | result = ::ioctl( _fd, DS_PARSE_TUPLE, &_ioctlarg ); |
239 | if ( result != 0 ) | 247 | if ( result != 0 ) |
240 | { | 248 | { |
241 | qWarning( "OPcmciaSocket::getTuple() - DS_PARSE_TUPLE failed (%s)", strerror( errno ) ); | 249 | qWarning( "OPcmciaSocket::getTuple() - DS_PARSE_TUPLE failed (%s)", strerror( errno ) ); |
242 | return false; | 250 | return false; |
243 | } | 251 | } |
244 | 252 | ||
245 | return true; | 253 | return true; |
246 | } | 254 | } |
247 | 255 | ||
248 | 256 | ||
249 | int OPcmciaSocket::number() const | 257 | int OPcmciaSocket::number() const |
250 | { | 258 | { |
251 | return _socket; | 259 | return _socket; |
252 | } | 260 | } |
253 | 261 | ||
254 | 262 | ||
255 | QString OPcmciaSocket::identity() const | 263 | QString OPcmciaSocket::identity() const |
256 | { | 264 | { |
257 | return ( strcmp( name(), "empty" ) == 0 ) ? "<Empty Socket>" : name(); | 265 | return ( strcmp( name(), "empty" ) == 0 ) ? "<Empty Socket>" : name(); |
258 | } | 266 | } |
259 | 267 | ||
260 | 268 | ||
261 | const OPcmciaSocket::OPcmciaSocketCardStatus OPcmciaSocket::status() const | 269 | const OPcmciaSocket::OPcmciaSocketCardStatus OPcmciaSocket::status() const |
262 | { | 270 | { |
263 | cs_status_t cs_status; | 271 | cs_status_t cs_status; |
264 | cs_status.Function = 0; | 272 | cs_status.Function = 0; |
265 | int result = ::ioctl( _fd, DS_GET_STATUS, &cs_status ); | 273 | int result = ::ioctl( _fd, DS_GET_STATUS, &cs_status ); |
266 | if ( result != 0 ) | 274 | if ( result != 0 ) |
267 | { | 275 | { |
268 | qWarning( "OPcmciaSocket::status() - DS_GET_STATUS failed (%s)", strerror( errno ) ); | 276 | qWarning( "OPcmciaSocket::status() - DS_GET_STATUS failed (%s)", strerror( errno ) ); |
269 | return Unknown; | 277 | return Unknown; |
270 | } | 278 | } |
271 | else | 279 | else |
272 | { | 280 | { |
273 | qDebug( " card status = 0x%08x", cs_status.CardState ); | 281 | qDebug( " card status = 0x%08x", cs_status.CardState ); |
274 | qDebug( " socket status = 0x%08x", cs_status.SocketState ); | 282 | qDebug( " socket status = 0x%08x", cs_status.SocketState ); |
275 | return (OPcmciaSocket::OPcmciaSocketCardStatus) (cs_status.CardState + cs_status.SocketState); | 283 | return (OPcmciaSocket::OPcmciaSocketCardStatus) (cs_status.CardState + cs_status.SocketState); |
276 | } | 284 | } |
277 | } | 285 | } |
278 | 286 | ||
279 | 287 | ||
280 | bool OPcmciaSocket::isUnsupported() const | 288 | bool OPcmciaSocket::isUnsupported() const |
281 | { | 289 | { |
282 | return ( strcmp( name(), "unsupported card" ) == 0 ); | 290 | return ( strcmp( name(), "unsupported card" ) == 0 ); |
283 | } | 291 | } |
284 | 292 | ||
285 | 293 | ||
286 | bool OPcmciaSocket::isEmpty() const | 294 | bool OPcmciaSocket::isEmpty() const |
287 | { | 295 | { |
288 | return ! status() && ( Occupied || OccupiedCardBus ); | 296 | return ! status() && ( Occupied || OccupiedCardBus ); |
289 | } | 297 | } |
290 | 298 | ||
291 | 299 | ||
292 | bool OPcmciaSocket::isSuspended() const | 300 | bool OPcmciaSocket::isSuspended() const |
293 | { | 301 | { |
294 | return status() && Suspended; | 302 | return status() && Suspended; |
295 | } | 303 | } |
296 | 304 | ||
297 | 305 | ||
298 | bool OPcmciaSocket::eject() | 306 | bool OPcmciaSocket::eject() |
299 | { | 307 | { |
300 | return ::ioctl( _fd, DS_EJECT_CARD ); | 308 | return ::ioctl( _fd, DS_EJECT_CARD ); |
301 | } | 309 | } |
302 | 310 | ||
303 | 311 | ||
304 | bool OPcmciaSocket::insert() | 312 | bool OPcmciaSocket::insert() |
305 | { | 313 | { |
306 | return ::ioctl( _fd, DS_INSERT_CARD ); | 314 | return ::ioctl( _fd, DS_INSERT_CARD ); |
307 | } | 315 | } |
308 | 316 | ||
309 | 317 | ||
310 | bool OPcmciaSocket::suspend() | 318 | bool OPcmciaSocket::suspend() |
311 | { | 319 | { |
312 | return ::ioctl( _fd, DS_SUSPEND_CARD ); | 320 | return ::ioctl( _fd, DS_SUSPEND_CARD ); |
313 | } | 321 | } |
314 | 322 | ||
315 | 323 | ||
316 | bool OPcmciaSocket::resume() | 324 | bool OPcmciaSocket::resume() |
317 | { | 325 | { |
318 | return ::ioctl( _fd, DS_RESUME_CARD ); | 326 | return ::ioctl( _fd, DS_RESUME_CARD ); |
319 | } | 327 | } |
320 | 328 | ||
321 | 329 | ||
322 | bool OPcmciaSocket::reset() | 330 | bool OPcmciaSocket::reset() |
323 | { | 331 | { |
324 | return ::ioctl( _fd, DS_RESET_CARD ); | 332 | return ::ioctl( _fd, DS_RESET_CARD ); |
325 | } | 333 | } |
326 | 334 | ||
327 | 335 | ||
328 | QStringList OPcmciaSocket::productIdentity() const | 336 | QStringList OPcmciaSocket::productIdentity() const |
329 | { | 337 | { |
330 | QStringList list; | 338 | QStringList list; |
331 | cistpl_vers_1_t *vers = &_ioctlarg.tuple_parse.parse.version_1; | 339 | cistpl_vers_1_t *vers = &_ioctlarg.tuple_parse.parse.version_1; |
332 | if ( getTuple( CISTPL_VERS_1 ) ) | 340 | if ( getTuple( CISTPL_VERS_1 ) ) |
333 | { | 341 | { |
334 | for ( int i = 0; i < CISTPL_VERS_1_MAX_PROD_STRINGS; ++i ) | 342 | for ( int i = 0; i < CISTPL_VERS_1_MAX_PROD_STRINGS; ++i ) |
335 | { | 343 | { |
336 | qDebug( " PRODID = '%s'", vers->str+vers->ofs[i] ); | 344 | qDebug( " PRODID = '%s'", vers->str+vers->ofs[i] ); |
337 | list += vers->str+vers->ofs[i]; | 345 | list += vers->str+vers->ofs[i]; |
338 | } | 346 | } |
339 | } | 347 | } |
340 | else | 348 | else |
341 | { | 349 | { |
342 | list += "<unknown>"; | 350 | list += "<unknown>"; |
343 | } | 351 | } |
344 | return list; | 352 | return list; |
345 | } | 353 | } |
346 | 354 | ||
347 | 355 | ||
348 | #if 0 | 356 | QString OPcmciaSocket::manufacturerIdentity() const |
349 | const QPair& OPcmciaSocket::manufacturerIdentity() const | ||
350 | { | 357 | { |
351 | return _manufId; | 358 | cistpl_manfid_t *manfid = &_ioctlarg.tuple_parse.parse.manfid; |
359 | if ( getTuple( CISTPL_MANFID ) ) | ||
360 | { | ||
361 | return QString().sprintf( "0x%04x, 0x%04x", manfid->manf, manfid->card ); | ||
362 | } | ||
363 | else | ||
364 | return "<unknown>"; | ||
352 | } | 365 | } |
353 | #endif | ||
354 | 366 | ||
355 | 367 | ||
356 | QString OPcmciaSocket::function() const | 368 | QString OPcmciaSocket::function() const |
357 | { | 369 | { |
358 | cistpl_funcid_t *funcid = &_ioctlarg.tuple_parse.parse.funcid; | 370 | cistpl_funcid_t *funcid = &_ioctlarg.tuple_parse.parse.funcid; |
359 | if ( getTuple( CISTPL_FUNCID ) ) | 371 | if ( getTuple( CISTPL_FUNCID ) ) |
360 | { | 372 | { |
361 | switch ( funcid->func ) | 373 | switch ( funcid->func ) |
362 | { | 374 | { |
363 | case 0: return "Multifunction"; break; | 375 | case 0: return "Multifunction"; break; |
364 | case 1: return "Memory"; break; | 376 | case 1: return "Memory"; break; |
365 | case 2: return "Serial"; break; | 377 | case 2: return "Serial"; break; |
366 | case 3: return "Parallel"; break; | 378 | case 3: return "Parallel"; break; |
367 | case 4: return "Fixed Disk"; break; | 379 | case 4: return "Fixed Disk"; break; |
368 | case 5: return "Video"; break; | 380 | case 5: return "Video"; break; |
369 | case 6: return "Network"; break; | 381 | case 6: return "Network"; break; |
370 | case 7: return "AIMS"; break; | 382 | case 7: return "AIMS"; break; |
371 | case 8: return "SCSI"; break; | 383 | case 8: return "SCSI"; break; |
372 | default: return "<unknown>"; break; | 384 | default: return "<unknown>"; break; |
373 | } | 385 | } |
374 | } | 386 | } |
375 | else | 387 | else |
376 | { | 388 | { |
377 | return "<unknown>"; | 389 | return "<unknown>"; |
378 | } | 390 | } |
379 | } | 391 | } |
diff --git a/libopie2/opiecore/linux/opcmciasystem.h b/libopie2/opiecore/linux/opcmciasystem.h index ac6c1de..0fd43cf 100644 --- a/libopie2/opiecore/linux/opcmciasystem.h +++ b/libopie2/opiecore/linux/opcmciasystem.h | |||
@@ -3,221 +3,219 @@ | |||
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; version 2 of the License. | 10 | - . .-<_> .<> Foundation; version 2 of the License. |
11 | ._= =} : | 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 | 29 | ||
30 | #ifndef OPCMCIASYSTEM_H | 30 | #ifndef OPCMCIASYSTEM_H |
31 | #define OPCMCIASYSTEM_H | 31 | #define OPCMCIASYSTEM_H |
32 | 32 | ||
33 | #include "linux_pcmcia.h" | 33 | #include "linux_pcmcia.h" |
34 | 34 | ||
35 | #include <qobject.h> | 35 | #include <qobject.h> |
36 | #include <qlist.h> | 36 | #include <qlist.h> |
37 | 37 | ||
38 | namespace Opie { | 38 | namespace Opie { |
39 | namespace Core { | 39 | namespace Core { |
40 | 40 | ||
41 | class OPcmciaSocket; | 41 | class OPcmciaSocket; |
42 | 42 | ||
43 | /*====================================================================================== | 43 | /*====================================================================================== |
44 | * OPcmciaSystem | 44 | * OPcmciaSystem |
45 | *======================================================================================*/ | 45 | *======================================================================================*/ |
46 | 46 | ||
47 | /** | 47 | /** |
48 | * @brief A container class for the linux pcmcia subsystem | 48 | * @brief A container class for the linux pcmcia subsystem |
49 | * | 49 | * |
50 | * This class provides access to all available pcmcia/cf cards on your device. | 50 | * This class provides access to all available pcmcia/cf cards on your device. |
51 | * | 51 | * |
52 | * @author Michael 'Mickey' Lauer <mickey@Vanille.de> | 52 | * @author Michael 'Mickey' Lauer <mickey@Vanille.de> |
53 | */ | 53 | */ |
54 | class OPcmciaSystem : public QObject | 54 | class OPcmciaSystem : public QObject |
55 | { | 55 | { |
56 | Q_OBJECT | 56 | Q_OBJECT |
57 | 57 | ||
58 | public: | 58 | public: |
59 | typedef QList<OPcmciaSocket> CardList; | 59 | typedef QList<OPcmciaSocket> CardList; |
60 | typedef QListIterator<OPcmciaSocket> CardIterator; | 60 | typedef QListIterator<OPcmciaSocket> CardIterator; |
61 | 61 | ||
62 | public: | 62 | public: |
63 | /** | 63 | /** |
64 | * @returns the number of available sockets | 64 | * @returns the number of available sockets |
65 | */ | 65 | */ |
66 | int count() const; | 66 | int count() const; |
67 | /** | 67 | /** |
68 | * @returns the number of populated sockets | 68 | * @returns the number of populated sockets |
69 | */ | 69 | */ |
70 | int cardCount() const; | 70 | int cardCount() const; |
71 | /** | 71 | /** |
72 | * @returns a pointer to the (one and only) @ref OSystem instance. | 72 | * @returns a pointer to the (one and only) @ref OSystem instance. |
73 | */ | 73 | */ |
74 | static OPcmciaSystem* instance(); | 74 | static OPcmciaSystem* instance(); |
75 | /** | 75 | /** |
76 | * @returns an iterator usable for iterating through all sound cards. | 76 | * @returns an iterator usable for iterating through all sound cards. |
77 | */ | 77 | */ |
78 | CardIterator iterator() const; | 78 | CardIterator iterator() const; |
79 | /** | 79 | /** |
80 | * @returns a pointer to the @ref OPcmciaSocket object correspinding to socket number n, or 0, if not found | 80 | * @returns a pointer to the @ref OPcmciaSocket object correspinding to socket number n, or 0, if not found |
81 | * @see OPcmciaSocket | 81 | * @see OPcmciaSocket |
82 | */ | 82 | */ |
83 | OPcmciaSocket* socket( unsigned int number ); | 83 | OPcmciaSocket* socket( unsigned int number ); |
84 | /** | 84 | /** |
85 | * @internal Rebuild the internal database | 85 | * @internal Rebuild the internal database |
86 | * @note Sometimes it might be useful to call this from client code, | 86 | * @note Sometimes it might be useful to call this from client code, |
87 | * e.g. after issuing a cardctl insert | 87 | * e.g. after issuing a cardctl insert |
88 | */ | 88 | */ |
89 | void synchronize(); | 89 | void synchronize(); |
90 | 90 | ||
91 | protected: | 91 | protected: |
92 | OPcmciaSystem(); | 92 | OPcmciaSystem(); |
93 | 93 | ||
94 | private: | 94 | private: |
95 | static OPcmciaSystem* _instance; | 95 | static OPcmciaSystem* _instance; |
96 | CardList _interfaces; | 96 | CardList _interfaces; |
97 | int _major; | 97 | int _major; |
98 | 98 | ||
99 | private: | 99 | private: |
100 | class Private; | 100 | class Private; |
101 | Private *d; | 101 | Private *d; |
102 | }; | 102 | }; |
103 | 103 | ||
104 | 104 | ||
105 | /*====================================================================================== | 105 | /*====================================================================================== |
106 | * OPcmciaSocket | 106 | * OPcmciaSocket |
107 | *======================================================================================*/ | 107 | *======================================================================================*/ |
108 | 108 | ||
109 | class OPcmciaSocket : public QObject | 109 | class OPcmciaSocket : public QObject |
110 | { | 110 | { |
111 | Q_OBJECT | 111 | Q_OBJECT |
112 | public: | 112 | public: |
113 | 113 | ||
114 | enum OPcmciaSocketCardStatus | 114 | enum OPcmciaSocketCardStatus |
115 | { | 115 | { |
116 | Unknown = 0, | 116 | Unknown = 0, |
117 | Occupied = CS_EVENT_CARD_DETECT, | 117 | Occupied = CS_EVENT_CARD_DETECT, |
118 | OccupiedCardBus = CS_EVENT_CB_DETECT, | 118 | OccupiedCardBus = CS_EVENT_CB_DETECT, |
119 | WriteProtected = CS_EVENT_WRITE_PROTECT, | 119 | WriteProtected = CS_EVENT_WRITE_PROTECT, |
120 | BatteryLow = CS_EVENT_BATTERY_LOW, | 120 | BatteryLow = CS_EVENT_BATTERY_LOW, |
121 | BatteryDead = CS_EVENT_BATTERY_DEAD, | 121 | BatteryDead = CS_EVENT_BATTERY_DEAD, |
122 | Ready = CS_EVENT_READY_CHANGE, | 122 | Ready = CS_EVENT_READY_CHANGE, |
123 | Suspended = CS_EVENT_PM_SUSPEND, | 123 | Suspended = CS_EVENT_PM_SUSPEND, |
124 | Attention = CS_EVENT_REQUEST_ATTENTION, | 124 | Attention = CS_EVENT_REQUEST_ATTENTION, |
125 | InsertionInProgress = CS_EVENT_CARD_INSERTION, | 125 | InsertionInProgress = CS_EVENT_CARD_INSERTION, |
126 | RemovalInProgress = CS_EVENT_CARD_REMOVAL, | 126 | RemovalInProgress = CS_EVENT_CARD_REMOVAL, |
127 | ThreeVolts = CS_EVENT_3VCARD, | 127 | ThreeVolts = CS_EVENT_3VCARD, |
128 | SupportsVoltage = CS_EVENT_XVCARD, | 128 | SupportsVoltage = CS_EVENT_XVCARD, |
129 | }; | 129 | }; |
130 | 130 | ||
131 | public: | 131 | public: |
132 | /** | 132 | /** |
133 | * Constructor. Normally you don't create @ref OPcmciaSocket objects yourself, | 133 | * Constructor. Normally you don't create @ref OPcmciaSocket objects yourself, |
134 | * but access them via @ref OPcmciaSystem::socket(). | 134 | * but access them via @ref OPcmciaSystem::socket(). |
135 | */ | 135 | */ |
136 | OPcmciaSocket( int major, int socket, QObject* parent, const char* name ); | 136 | OPcmciaSocket( int major, int socket, QObject* parent, const char* name ); |
137 | /** | 137 | /** |
138 | * Destructor. | 138 | * Destructor. |
139 | */ | 139 | */ |
140 | virtual ~OPcmciaSocket(); | 140 | virtual ~OPcmciaSocket(); |
141 | /** | 141 | /** |
142 | * @returns the corresponding socket number | 142 | * @returns the corresponding socket number |
143 | */ | 143 | */ |
144 | int number() const; | 144 | int number() const; |
145 | /** | 145 | /** |
146 | * @returns the card managers idea of the cards' identy, or "<Empty Socket>" | 146 | * @returns the card managers idea of the cards' identy, or "<Empty Socket>" |
147 | */ | 147 | */ |
148 | QString identity() const; | 148 | QString identity() const; |
149 | /** | 149 | /** |
150 | * @returns the socket status | 150 | * @returns the socket status |
151 | */ | 151 | */ |
152 | const OPcmciaSocketCardStatus status() const; | 152 | const OPcmciaSocketCardStatus status() const; |
153 | /** | 153 | /** |
154 | * @returns true, if the card is unsupported by the cardmgr | 154 | * @returns true, if the card is unsupported by the cardmgr |
155 | */ | 155 | */ |
156 | bool isUnsupported() const; | 156 | bool isUnsupported() const; |
157 | /** | 157 | /** |
158 | * @returns true, if the socket is empty | 158 | * @returns true, if the socket is empty |
159 | */ | 159 | */ |
160 | bool isEmpty() const; | 160 | bool isEmpty() const; |
161 | /** | 161 | /** |
162 | * @returns true, if the socket is suspended | 162 | * @returns true, if the socket is suspended |
163 | */ | 163 | */ |
164 | bool isSuspended() const; | 164 | bool isSuspended() const; |
165 | /** | 165 | /** |
166 | * Eject card. @returns true, if operation succeeded | 166 | * Eject card. @returns true, if operation succeeded |
167 | * @note: This operation needs root privileges | 167 | * @note: This operation needs root privileges |
168 | */ | 168 | */ |
169 | bool eject(); | 169 | bool eject(); |
170 | /** | 170 | /** |
171 | * Insert card. @returns true, if operation succeeded | 171 | * Insert card. @returns true, if operation succeeded |
172 | * @note: This operation needs root privileges | 172 | * @note: This operation needs root privileges |
173 | */ | 173 | */ |
174 | bool insert(); | 174 | bool insert(); |
175 | /** | 175 | /** |
176 | * Suspend card. @returns true, if operation succeeded | 176 | * Suspend card. @returns true, if operation succeeded |
177 | * @note: This operation needs root privileges | 177 | * @note: This operation needs root privileges |
178 | */ | 178 | */ |
179 | bool suspend(); | 179 | bool suspend(); |
180 | /** | 180 | /** |
181 | * Resume card. @returns true, if operation succeeded | 181 | * Resume card. @returns true, if operation succeeded |
182 | * @note: This operation needs root privileges | 182 | * @note: This operation needs root privileges |
183 | */ | 183 | */ |
184 | bool resume(); | 184 | bool resume(); |
185 | /** | 185 | /** |
186 | * Reset card. @returns true, if operation succeeded | 186 | * Reset card. @returns true, if operation succeeded |
187 | * @note: This operation needs root privileges | 187 | * @note: This operation needs root privileges |
188 | */ | 188 | */ |
189 | bool reset(); | 189 | bool reset(); |
190 | /** | 190 | /** |
191 | * @returns a list of product IDs | 191 | * @returns a list of product IDs |
192 | */ | 192 | */ |
193 | QStringList productIdentity() const; | 193 | QStringList productIdentity() const; |
194 | /** | 194 | /** |
195 | * @returns the manufacturer ID pair | 195 | * @returns the manufacturer ID string |
196 | */ | 196 | */ |
197 | #if 0 | 197 | QString manufacturerIdentity() const; |
198 | const QPair& manufacturerIdentity() const; | ||
199 | #endif | ||
200 | /** | 198 | /** |
201 | * @returns the function string | 199 | * @returns the function string |
202 | */ | 200 | */ |
203 | QString function() const; | 201 | QString function() const; |
204 | 202 | ||
205 | private: | 203 | private: |
206 | void init(); | 204 | void init(); |
207 | void cleanup(); | 205 | void cleanup(); |
208 | bool getTuple( cisdata_t tuple ) const; | 206 | bool getTuple( cisdata_t tuple ) const; |
209 | int _major; | 207 | int _major; |
210 | int _socket; | 208 | int _socket; |
211 | int _fd; | 209 | int _fd; |
212 | mutable ds_ioctl_arg_t _ioctlarg; | 210 | mutable ds_ioctl_arg_t _ioctlarg; |
213 | 211 | ||
214 | private: | 212 | private: |
215 | class Private; | 213 | class Private; |
216 | Private *d; | 214 | Private *d; |
217 | }; | 215 | }; |
218 | 216 | ||
219 | 217 | ||
220 | } | 218 | } |
221 | } | 219 | } |
222 | 220 | ||
223 | #endif // OPCMCIASYSTEM_H | 221 | #endif // OPCMCIASYSTEM_H |