summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2005-05-25 19:03:26 (UTC)
committer mickeyl <mickeyl>2005-05-25 19:03:26 (UTC)
commit8d2d91b9b6e590e474fe3acd92f71e40779a493b (patch) (unidiff)
tree877bf0b4c6a23892ed0d2d2a0a3e3aa7b82ee2a1
parent5fdc5b4cba7743947a23840ba09fadcc7414309b (diff)
downloadopie-8d2d91b9b6e590e474fe3acd92f71e40779a493b.zip
opie-8d2d91b9b6e590e474fe3acd92f71e40779a493b.tar.gz
opie-8d2d91b9b6e590e474fe3acd92f71e40779a493b.tar.bz2
be nice to gcc 3.3
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/linux/opcmciasystem.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/libopie2/opiecore/linux/opcmciasystem.cpp b/libopie2/opiecore/linux/opcmciasystem.cpp
index 7bd7178..0f7ff46 100644
--- a/libopie2/opiecore/linux/opcmciasystem.cpp
+++ b/libopie2/opiecore/linux/opcmciasystem.cpp
@@ -1,352 +1,352 @@
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"
31using namespace Opie::Core; 31using 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/*====================================================================================== 52/*======================================================================================
53 * OPcmciaSystem 53 * OPcmciaSystem
54 *======================================================================================*/ 54 *======================================================================================*/
55 55
56OPcmciaSystem* OPcmciaSystem::_instance = 0; 56OPcmciaSystem* OPcmciaSystem::_instance = 0;
57 57
58OPcmciaSystem::OPcmciaSystem() 58OPcmciaSystem::OPcmciaSystem()
59 :_major( 0 ) 59 :_major( 0 )
60{ 60{
61 qDebug( "OPcmciaSystem::OPcmciaSystem()" ); 61 qDebug( "OPcmciaSystem::OPcmciaSystem()" );
62 62
63 // get major node number out of /proc/devices 63 // get major node number out of /proc/devices
64 QFile procfile( PROC_DEVICES ); 64 QFile procfile( PROC_DEVICES );
65 if ( procfile.exists() && procfile.open( IO_ReadOnly ) ) 65 if ( procfile.exists() && procfile.open( IO_ReadOnly ) )
66 { 66 {
67 QTextStream devstream( &procfile ); 67 QTextStream devstream( &procfile );
68 devstream.readLine(); // skip header 68 devstream.readLine(); // skip header
69 while ( !devstream.atEnd() && !_major ) 69 while ( !devstream.atEnd() && !_major )
70 { 70 {
71 int nodenumber; 71 int nodenumber;
72 QString driver; 72 QString driver;
73 devstream >> nodenumber >> driver; 73 devstream >> nodenumber >> driver;
74 if ( driver == "pcmcia" ) 74 if ( driver == "pcmcia" )
75 { 75 {
76 qDebug( "OPcmciaSystem::OPcmciaSystem(): gotcha! pcmcia node number = %d", nodenumber ); 76 qDebug( "OPcmciaSystem::OPcmciaSystem(): gotcha! pcmcia node number = %d", nodenumber );
77 _major = nodenumber; 77 _major = nodenumber;
78 break; 78 break;
79 } 79 }
80 } 80 }
81 } 81 }
82 else 82 else
83 { 83 {
84 qWarning( "OPcmciaSystem::OPcmciaSystem() - can't open /proc/devices - continuing with limited functionality." ); 84 qWarning( "OPcmciaSystem::OPcmciaSystem() - can't open /proc/devices - continuing with limited functionality." );
85 } 85 }
86 86
87 synchronize(); 87 synchronize();
88} 88}
89 89
90void OPcmciaSystem::synchronize() 90void OPcmciaSystem::synchronize()
91{ 91{
92 qDebug( "OPcmciaSystem::synchronize()" ); 92 qDebug( "OPcmciaSystem::synchronize()" );
93 _interfaces.clear(); 93 _interfaces.clear();
94 94
95 //FIXME: Use cardmgr subsystem ioctls 95 //FIXME: Use cardmgr subsystem ioctls
96 96
97 QString fileName; 97 QString fileName;
98 if ( QFile::exists( "/var/run/stab" ) ) { fileName = "/var/run/stab"; } 98 if ( QFile::exists( "/var/run/stab" ) ) { fileName = "/var/run/stab"; }
99 else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) { fileName = "/var/state/pcmcia/stab"; } 99 else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) { fileName = "/var/state/pcmcia/stab"; }
100 else { fileName = "/var/lib/pcmcia/stab"; } 100 else { fileName = "/var/lib/pcmcia/stab"; }
101 QFile cardinfofile( fileName ); 101 QFile cardinfofile( fileName );
102 if ( !cardinfofile.exists() || !cardinfofile.open( IO_ReadOnly ) ) 102 if ( !cardinfofile.exists() || !cardinfofile.open( IO_ReadOnly ) )
103 { 103 {
104 qWarning( "pcmcia info file not found or unaccessible" ); 104 qWarning( "pcmcia info file not found or unaccessible" );
105 return; 105 return;
106 } 106 }
107 QTextStream cardinfo( &cardinfofile ); 107 QTextStream cardinfo( &cardinfofile );
108 while ( !cardinfo.atEnd() ) 108 while ( !cardinfo.atEnd() )
109 { 109 {
110 QString strSocket; 110 QString strSocket;
111 int numSocket; 111 int numSocket;
112 char colon; 112 char colon;
113 QString cardName; 113 QString cardName;
114 cardinfo >> strSocket >> numSocket >> colon; 114 cardinfo >> strSocket >> numSocket >> colon;
115 cardName = cardinfo.readLine().stripWhiteSpace(); 115 cardName = cardinfo.readLine().stripWhiteSpace();
116 qDebug( "strSocket = '%s', numSocket = '%d', colon = '%c', cardName = '%s'", (const char*) strSocket, numSocket, colon, ( const char*) cardName ); 116 qDebug( "strSocket = '%s', numSocket = '%d', colon = '%c', cardName = '%s'", (const char*) strSocket, numSocket, colon, ( const char*) cardName );
117 if ( strSocket == "Socket" && colon == ':' ) 117 if ( strSocket == "Socket" && colon == ':' )
118 { 118 {
119 _interfaces.append( new OPcmciaSocket( _major, numSocket, this, (const char*) cardName ) ); 119 _interfaces.append( new OPcmciaSocket( _major, numSocket, this, (const char*) cardName ) );
120 } 120 }
121 else 121 else
122 { 122 {
123 continue; 123 continue;
124 } 124 }
125 } 125 }
126} 126}
127 127
128 128
129int OPcmciaSystem::count() const 129int OPcmciaSystem::count() const
130{ 130{
131 return _interfaces.count(); 131 return _interfaces.count();
132} 132}
133 133
134 134
135int OPcmciaSystem::cardCount() const 135int OPcmciaSystem::cardCount() const
136{ 136{
137 int nonEmpty = 0; 137 int nonEmpty = 0;
138 OPcmciaSystem::CardIterator it = iterator(); 138 OPcmciaSystem::CardIterator it = iterator();
139 while ( it.current() ) 139 while ( it.current() )
140 { 140 {
141 if ( !it.current()->isEmpty() ) nonEmpty++; 141 if ( !it.current()->isEmpty() ) nonEmpty++;
142 ++it; 142 ++it;
143 } 143 }
144 return nonEmpty; 144 return nonEmpty;
145} 145}
146 146
147 147
148OPcmciaSocket* OPcmciaSystem::socket( unsigned int number ) 148OPcmciaSocket* OPcmciaSystem::socket( unsigned int number )
149{ 149{
150 return _interfaces.at( number ); 150 return _interfaces.at( number );
151} 151}
152 152
153 153
154OPcmciaSystem* OPcmciaSystem::instance() 154OPcmciaSystem* OPcmciaSystem::instance()
155{ 155{
156 if ( !_instance ) _instance = new OPcmciaSystem(); 156 if ( !_instance ) _instance = new OPcmciaSystem();
157 return _instance; 157 return _instance;
158} 158}
159 159
160 160
161OPcmciaSystem::CardIterator OPcmciaSystem::iterator() const 161OPcmciaSystem::CardIterator OPcmciaSystem::iterator() const
162{ 162{
163 return OPcmciaSystem::CardIterator( _interfaces ); 163 return OPcmciaSystem::CardIterator( _interfaces );
164} 164}
165 165
166 166
167/*====================================================================================== 167/*======================================================================================
168 * OPcmciaSocket 168 * OPcmciaSocket
169 *======================================================================================*/ 169 *======================================================================================*/
170 170
171OPcmciaSocket::OPcmciaSocket( int major, int socket, QObject* parent, const char* name ) 171OPcmciaSocket::OPcmciaSocket( int major, int socket, QObject* parent, const char* name )
172 :QObject( parent, name ), _major( major ), _socket( socket ) 172 :QObject( parent, name ), _major( major ), _socket( socket )
173{ 173{
174 qDebug( "OPcmciaSocket::OPcmciaSocket()" ); 174 qDebug( "OPcmciaSocket::OPcmciaSocket()" );
175 175
176 init(); 176 init();
177 buildInformation(); 177 buildInformation();
178} 178}
179 179
180 180
181OPcmciaSocket::~OPcmciaSocket() 181OPcmciaSocket::~OPcmciaSocket()
182{ 182{
183 qDebug( "OPcmciaSocket::~OPcmciaSocket()" ); 183 qDebug( "OPcmciaSocket::~OPcmciaSocket()" );
184 cleanup(); 184 cleanup();
185} 185}
186 186
187 187
188/* internal */ void OPcmciaSocket::init() 188/* internal */ void OPcmciaSocket::init()
189{ 189{
190 // open control socket and gather file descriptor 190 // open control socket and gather file descriptor
191 if ( _major ) 191 if ( _major )
192 { 192 {
193 dev_t dev = ::makedev( _major, _socket ); 193 dev_t dev = makedev( _major, _socket );
194 QString filename = QString().sprintf( "/tmp/opcmciasystem-%d", ::getpid() ); 194 QString filename = QString().sprintf( "/tmp/opcmciasystem-%d", ::getpid() );
195 if ( ::mknod( (const char*) filename, ( S_IFCHR|S_IREAD|S_IWRITE ), dev ) == 0 ) 195 if ( ::mknod( (const char*) filename, ( S_IFCHR|S_IREAD|S_IWRITE ), dev ) == 0 )
196 { 196 {
197 _fd = ::open( (const char*) filename, O_RDONLY); 197 _fd = ::open( (const char*) filename, O_RDONLY);
198 if ( !_fd ) 198 if ( !_fd )
199 { 199 {
200 qWarning( "OPcmciaSocket::init() - can't open control socket (%s)", strerror( errno ) ); 200 qWarning( "OPcmciaSocket::init() - can't open control socket (%s)", strerror( errno ) );
201 } 201 }
202 else 202 else
203 { 203 {
204 ::unlink( (const char*) filename ); 204 ::unlink( (const char*) filename );
205 } 205 }
206 } 206 }
207 else 207 else
208 { 208 {
209 qWarning( "OPcmciaSocket::init() - can't create device node (%s)", strerror( errno ) ); 209 qWarning( "OPcmciaSocket::init() - can't create device node (%s)", strerror( errno ) );
210 } 210 }
211 } 211 }
212} 212}
213 213
214/* internal */ void OPcmciaSocket::buildInformation() 214/* internal */ void OPcmciaSocket::buildInformation()
215{ 215{
216 cistpl_vers_1_t *vers = &_ioctlarg.tuple_parse.parse.version_1; 216 cistpl_vers_1_t *vers = &_ioctlarg.tuple_parse.parse.version_1;
217 cistpl_manfid_t *manfid = &_ioctlarg.tuple_parse.parse.manfid; 217 cistpl_manfid_t *manfid = &_ioctlarg.tuple_parse.parse.manfid;
218 cistpl_funcid_t *funcid = &_ioctlarg.tuple_parse.parse.funcid; 218 cistpl_funcid_t *funcid = &_ioctlarg.tuple_parse.parse.funcid;
219 config_info_t config; 219 config_info_t config;
220 220
221 if ( getTuple( CISTPL_VERS_1 ) ) 221 if ( getTuple( CISTPL_VERS_1 ) )
222 { 222 {
223 for ( int i = 0; i < CISTPL_VERS_1_MAX_PROD_STRINGS; ++i ) 223 for ( int i = 0; i < CISTPL_VERS_1_MAX_PROD_STRINGS; ++i )
224 { 224 {
225 qDebug( " PRODID = '%s'", vers->str+vers->ofs[i] ); 225 qDebug( " PRODID = '%s'", vers->str+vers->ofs[i] );
226 _productId += vers->str+vers->ofs[i]; 226 _productId += vers->str+vers->ofs[i];
227 } 227 }
228 } 228 }
229 /* 229 /*
230 for (i = 0; i < 4; i++) 230 for (i = 0; i < 4; i++)
231 printf("PRODID_%d=\"%s\"\n", i+1, 231 printf("PRODID_%d=\"%s\"\n", i+1,
232 (i < vers->ns) ? vers->str+vers->ofs[i] : ""); 232 (i < vers->ns) ? vers->str+vers->ofs[i] : "");
233 *manfid = (cistpl_manfid_t) { 0, 0 }; 233 *manfid = (cistpl_manfid_t) { 0, 0 };
234 get_tuple(fd, CISTPL_MANFID, &arg); 234 get_tuple(fd, CISTPL_MANFID, &arg);
235 printf("MANFID=%04x,%04x\n", manfid->manf, manfid->card); 235 printf("MANFID=%04x,%04x\n", manfid->manf, manfid->card);
236 *funcid = (cistpl_funcid_t) { 0xff, 0xff }; 236 *funcid = (cistpl_funcid_t) { 0xff, 0xff };
237 get_tuple(fd, CISTPL_FUNCID, &arg); 237 get_tuple(fd, CISTPL_FUNCID, &arg);
238 printf("FUNCID=%d\n", funcid->func); 238 printf("FUNCID=%d\n", funcid->func);
239 config.Function = config.ConfigBase = 0; 239 config.Function = config.ConfigBase = 0;
240 */ 240 */
241} 241}
242 242
243/* internal */ void OPcmciaSocket::cleanup() 243/* internal */ void OPcmciaSocket::cleanup()
244{ 244{
245 // close control socket 245 // close control socket
246} 246}
247 247
248/* internal */ bool OPcmciaSocket::getTuple( cisdata_t tuple ) 248/* internal */ bool OPcmciaSocket::getTuple( cisdata_t tuple )
249{ 249{
250 _ioctlarg.tuple.DesiredTuple = tuple; 250 _ioctlarg.tuple.DesiredTuple = tuple;
251 _ioctlarg.tuple.Attributes = TUPLE_RETURN_COMMON; 251 _ioctlarg.tuple.Attributes = TUPLE_RETURN_COMMON;
252 _ioctlarg.tuple.TupleOffset = 0; 252 _ioctlarg.tuple.TupleOffset = 0;
253 253
254 int result; 254 int result;
255 result = ::ioctl(_fd, DS_GET_FIRST_TUPLE, &_ioctlarg); 255 result = ::ioctl(_fd, DS_GET_FIRST_TUPLE, &_ioctlarg);
256 if ( result != 0 ) 256 if ( result != 0 )
257 { 257 {
258 qWarning( "OPcmciaSocket::getTuple() - DS_GET_FIRST_TUPLE failed (%s)", strerror( errno ) ); 258 qWarning( "OPcmciaSocket::getTuple() - DS_GET_FIRST_TUPLE failed (%s)", strerror( errno ) );
259 return false; 259 return false;
260 } 260 }
261 261
262 result = ::ioctl(_fd, DS_GET_TUPLE_DATA, &_ioctlarg); 262 result = ::ioctl(_fd, DS_GET_TUPLE_DATA, &_ioctlarg);
263 if ( result != 0 ) 263 if ( result != 0 )
264 { 264 {
265 qWarning( "OPcmciaSocket::getTuple() - DS_GET_TUPLE_DATA failed (%s)", strerror( errno ) ); 265 qWarning( "OPcmciaSocket::getTuple() - DS_GET_TUPLE_DATA failed (%s)", strerror( errno ) );
266 return false; 266 return false;
267 } 267 }
268 268
269 result = ::ioctl(_fd, DS_PARSE_TUPLE, &_ioctlarg); 269 result = ::ioctl(_fd, DS_PARSE_TUPLE, &_ioctlarg);
270 if ( result != 0 ) 270 if ( result != 0 )
271 { 271 {
272 qWarning( "OPcmciaSocket::getTuple() - DS_PARSE_TUPLE failed (%s)", strerror( errno ) ); 272 qWarning( "OPcmciaSocket::getTuple() - DS_PARSE_TUPLE failed (%s)", strerror( errno ) );
273 return false; 273 return false;
274 } 274 }
275 275
276 return true; 276 return true;
277} 277}
278 278
279 279
280/* internal */ bool OPcmciaSocket::command( const QString& cmd ) 280/* internal */ bool OPcmciaSocket::command( const QString& cmd )
281{ 281{
282 QString cmdline = QString().sprintf( "cardctl %s %d &", (const char*) cmd, _socket ); 282 QString cmdline = QString().sprintf( "cardctl %s %d &", (const char*) cmd, _socket );
283 ::system( (const char*) cmdline ); 283 ::system( (const char*) cmdline );
284} 284}
285 285
286int OPcmciaSocket::number() const 286int OPcmciaSocket::number() const
287{ 287{
288 return _socket; 288 return _socket;
289} 289}
290 290
291 291
292QString OPcmciaSocket::identity() const 292QString OPcmciaSocket::identity() const
293{ 293{
294 return ( strcmp( name(), "empty" ) == 0 ) ? "<Empty Socket>" : name(); 294 return ( strcmp( name(), "empty" ) == 0 ) ? "<Empty Socket>" : name();
295} 295}
296 296
297 297
298bool OPcmciaSocket::isUnsupported() const 298bool OPcmciaSocket::isUnsupported() const
299{ 299{
300 return ( strcmp( name(), "unsupported card" ) == 0 ); 300 return ( strcmp( name(), "unsupported card" ) == 0 );
301} 301}
302 302
303 303
304bool OPcmciaSocket::isEmpty() const 304bool OPcmciaSocket::isEmpty() const
305{ 305{
306 return ( strcmp( name(), "empty" ) == 0 ); 306 return ( strcmp( name(), "empty" ) == 0 );
307} 307}
308 308
309 309
310bool OPcmciaSocket::isSuspended() const 310bool OPcmciaSocket::isSuspended() const
311{ 311{
312 //FIXME 312 //FIXME
313 return false; 313 return false;
314} 314}
315 315
316bool OPcmciaSocket::eject() 316bool OPcmciaSocket::eject()
317{ 317{
318 return command( "eject" ); 318 return command( "eject" );
319} 319}
320 320
321bool OPcmciaSocket::insert() 321bool OPcmciaSocket::insert()
322{ 322{
323 return command( "insert" ); 323 return command( "insert" );
324} 324}
325 325
326bool OPcmciaSocket::suspend() 326bool OPcmciaSocket::suspend()
327{ 327{
328 return command( "suspend" ); 328 return command( "suspend" );
329} 329}
330 330
331bool OPcmciaSocket::resume() 331bool OPcmciaSocket::resume()
332{ 332{
333 return command( "resume"); 333 return command( "resume");
334} 334}
335 335
336bool OPcmciaSocket::reset() 336bool OPcmciaSocket::reset()
337{ 337{
338 return command( "reset"); 338 return command( "reset");
339} 339}
340 340
341const QStringList& OPcmciaSocket::productIdentity() const 341const QStringList& OPcmciaSocket::productIdentity() const
342{ 342{
343 return _productId; 343 return _productId;
344} 344}
345 345
346#if 0 346#if 0
347const QPair& OPcmciaSocket::manufacturerIdentity() const 347const QPair& OPcmciaSocket::manufacturerIdentity() const
348{ 348{
349 return _manufId; 349 return _manufId;
350} 350}
351#endif 351#endif
352 352