-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 | |||
@@ -20,64 +20,66 @@ | |||
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 | { |
@@ -160,80 +162,86 @@ OPcmciaSystem* OPcmciaSystem::instance() | |||
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 ) |
@@ -262,118 +270,122 @@ 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 | |||
@@ -163,61 +163,59 @@ class OPcmciaSocket : public QObject | |||
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 |