-rw-r--r-- | libopie2/opiecore/linux/opcmciasystem.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/libopie2/opiecore/linux/opcmciasystem.cpp b/libopie2/opiecore/linux/opcmciasystem.cpp index 054d261..eae356e 100644 --- a/libopie2/opiecore/linux/opcmciasystem.cpp +++ b/libopie2/opiecore/linux/opcmciasystem.cpp | |||
@@ -1,289 +1,292 @@ | |||
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 | 52 | // #define OPCMCIA_DEBUG 1 |
53 | 53 | ||
54 | /*====================================================================================== | 54 | /*====================================================================================== |
55 | * OPcmciaSystem | 55 | * OPcmciaSystem |
56 | *======================================================================================*/ | 56 | *======================================================================================*/ |
57 | 57 | ||
58 | OPcmciaSystem* OPcmciaSystem::_instance = 0; | 58 | OPcmciaSystem* OPcmciaSystem::_instance = 0; |
59 | 59 | ||
60 | OPcmciaSystem::OPcmciaSystem() | 60 | OPcmciaSystem::OPcmciaSystem() |
61 | :_major( 0 ) | 61 | :_major( 0 ) |
62 | { | 62 | { |
63 | qDebug( "OPcmciaSystem::OPcmciaSystem()" ); | 63 | qDebug( "OPcmciaSystem::OPcmciaSystem()" ); |
64 | 64 | ||
65 | // get major node number out of /proc/devices | 65 | // get major node number out of /proc/devices |
66 | QFile procfile( PROC_DEVICES ); | 66 | QFile procfile( PROC_DEVICES ); |
67 | if ( procfile.exists() && procfile.open( IO_ReadOnly ) ) | 67 | if ( procfile.exists() && procfile.open( IO_ReadOnly ) ) |
68 | { | 68 | { |
69 | QTextStream devstream( &procfile ); | 69 | QTextStream devstream( &procfile ); |
70 | devstream.readLine(); // skip header | 70 | devstream.readLine(); // skip header |
71 | while ( !devstream.atEnd() && !_major ) | 71 | while ( !devstream.atEnd() && !_major ) |
72 | { | 72 | { |
73 | int nodenumber; | 73 | int nodenumber; |
74 | QString driver; | 74 | QString driver; |
75 | devstream >> nodenumber >> driver; | 75 | devstream >> nodenumber >> driver; |
76 | if ( driver == "pcmcia" ) | 76 | if ( driver == "pcmcia" ) |
77 | { | 77 | { |
78 | qDebug( "OPcmciaSystem::OPcmciaSystem(): gotcha! pcmcia node number = %d", nodenumber ); | 78 | qDebug( "OPcmciaSystem::OPcmciaSystem(): gotcha! pcmcia node number = %d", nodenumber ); |
79 | _major = nodenumber; | 79 | _major = nodenumber; |
80 | break; | 80 | break; |
81 | } | 81 | } |
82 | } | 82 | } |
83 | } | 83 | } |
84 | else | 84 | else |
85 | { | 85 | { |
86 | 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." ); |
87 | } | 87 | } |
88 | 88 | ||
89 | synchronize(); | 89 | synchronize(); |
90 | } | 90 | } |
91 | 91 | ||
92 | void OPcmciaSystem::synchronize() | 92 | void OPcmciaSystem::synchronize() |
93 | { | 93 | { |
94 | qDebug( "OPcmciaSystem::synchronize()" ); | 94 | qDebug( "OPcmciaSystem::synchronize()" ); |
95 | _interfaces.clear(); | 95 | _interfaces.clear(); |
96 | 96 | ||
97 | //FIXME: Use cardmgr subsystem ioctls | 97 | //NOTE: We _could_ use ioctl's here as well, however we want to know if |
98 | // the card is recognized by the cardmgr (hence has a valid binding) | ||
99 | // If it is not recognized yet, userland may want to provide a configuration dialog | ||
100 | //TODO: Revise for pcmciautils | ||
98 | 101 | ||
99 | QString fileName; | 102 | QString fileName; |
100 | if ( QFile::exists( "/var/run/stab" ) ) { fileName = "/var/run/stab"; } | 103 | if ( QFile::exists( "/var/run/stab" ) ) { fileName = "/var/run/stab"; } |
101 | else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) { fileName = "/var/state/pcmcia/stab"; } | 104 | else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) { fileName = "/var/state/pcmcia/stab"; } |
102 | else { fileName = "/var/lib/pcmcia/stab"; } | 105 | else { fileName = "/var/lib/pcmcia/stab"; } |
103 | QFile cardinfofile( fileName ); | 106 | QFile cardinfofile( fileName ); |
104 | if ( !cardinfofile.exists() || !cardinfofile.open( IO_ReadOnly ) ) | 107 | if ( !cardinfofile.exists() || !cardinfofile.open( IO_ReadOnly ) ) |
105 | { | 108 | { |
106 | qWarning( "pcmcia info file not found or unaccessible" ); | 109 | qWarning( "pcmcia info file not found or unaccessible" ); |
107 | return; | 110 | return; |
108 | } | 111 | } |
109 | QTextStream cardinfo( &cardinfofile ); | 112 | QTextStream cardinfo( &cardinfofile ); |
110 | while ( !cardinfo.atEnd() ) | 113 | while ( !cardinfo.atEnd() ) |
111 | { | 114 | { |
112 | QString strSocket; | 115 | QString strSocket; |
113 | int numSocket; | 116 | int numSocket; |
114 | char colon; | 117 | char colon; |
115 | QString cardName; | 118 | QString cardName; |
116 | cardinfo >> strSocket >> numSocket >> colon; | 119 | cardinfo >> strSocket >> numSocket >> colon; |
117 | cardName = cardinfo.readLine().stripWhiteSpace(); | 120 | cardName = cardinfo.readLine().stripWhiteSpace(); |
118 | qDebug( "strSocket = '%s', numSocket = '%d', colon = '%c', cardName = '%s'", (const char*) strSocket, numSocket, colon, ( const char*) cardName ); | 121 | qDebug( "strSocket = '%s', numSocket = '%d', colon = '%c', cardName = '%s'", (const char*) strSocket, numSocket, colon, ( const char*) cardName ); |
119 | if ( strSocket == "Socket" && colon == ':' ) | 122 | if ( strSocket == "Socket" && colon == ':' ) |
120 | { | 123 | { |
121 | _interfaces.append( new OPcmciaSocket( _major, numSocket, this, (const char*) cardName ) ); | 124 | _interfaces.append( new OPcmciaSocket( _major, numSocket, this, (const char*) cardName ) ); |
122 | } | 125 | } |
123 | else | 126 | else |
124 | { | 127 | { |
125 | continue; | 128 | continue; |
126 | } | 129 | } |
127 | } | 130 | } |
128 | } | 131 | } |
129 | 132 | ||
130 | 133 | ||
131 | int OPcmciaSystem::count() const | 134 | int OPcmciaSystem::count() const |
132 | { | 135 | { |
133 | return _interfaces.count(); | 136 | return _interfaces.count(); |
134 | } | 137 | } |
135 | 138 | ||
136 | 139 | ||
137 | int OPcmciaSystem::cardCount() const | 140 | int OPcmciaSystem::cardCount() const |
138 | { | 141 | { |
139 | int nonEmpty = 0; | 142 | int nonEmpty = 0; |
140 | OPcmciaSystem::CardIterator it = iterator(); | 143 | OPcmciaSystem::CardIterator it = iterator(); |
141 | while ( it.current() ) | 144 | while ( it.current() ) |
142 | { | 145 | { |
143 | if ( !it.current()->isEmpty() ) nonEmpty++; | 146 | if ( !it.current()->isEmpty() ) nonEmpty++; |
144 | ++it; | 147 | ++it; |
145 | } | 148 | } |
146 | return nonEmpty; | 149 | return nonEmpty; |
147 | } | 150 | } |
148 | 151 | ||
149 | 152 | ||
150 | OPcmciaSocket* OPcmciaSystem::socket( unsigned int number ) | 153 | OPcmciaSocket* OPcmciaSystem::socket( unsigned int number ) |
151 | { | 154 | { |
152 | return _interfaces.at( number ); | 155 | return _interfaces.at( number ); |
153 | } | 156 | } |
154 | 157 | ||
155 | 158 | ||
156 | OPcmciaSystem* OPcmciaSystem::instance() | 159 | OPcmciaSystem* OPcmciaSystem::instance() |
157 | { | 160 | { |
158 | if ( !_instance ) _instance = new OPcmciaSystem(); | 161 | if ( !_instance ) _instance = new OPcmciaSystem(); |
159 | return _instance; | 162 | return _instance; |
160 | } | 163 | } |
161 | 164 | ||
162 | 165 | ||
163 | OPcmciaSystem::CardIterator OPcmciaSystem::iterator() const | 166 | OPcmciaSystem::CardIterator OPcmciaSystem::iterator() const |
164 | { | 167 | { |
165 | return OPcmciaSystem::CardIterator( _interfaces ); | 168 | return OPcmciaSystem::CardIterator( _interfaces ); |
166 | } | 169 | } |
167 | 170 | ||
168 | 171 | ||
169 | /*====================================================================================== | 172 | /*====================================================================================== |
170 | * OPcmciaSocket | 173 | * OPcmciaSocket |
171 | *======================================================================================*/ | 174 | *======================================================================================*/ |
172 | 175 | ||
173 | OPcmciaSocket::OPcmciaSocket( int major, int socket, QObject* parent, const char* name ) | 176 | OPcmciaSocket::OPcmciaSocket( int major, int socket, QObject* parent, const char* name ) |
174 | :QObject( parent, name ), _major( major ), _socket( socket ) | 177 | :QObject( parent, name ), _major( major ), _socket( socket ) |
175 | { | 178 | { |
176 | qDebug( "OPcmciaSocket::OPcmciaSocket()" ); | 179 | qDebug( "OPcmciaSocket::OPcmciaSocket()" ); |
177 | init(); | 180 | init(); |
178 | } | 181 | } |
179 | 182 | ||
180 | 183 | ||
181 | OPcmciaSocket::~OPcmciaSocket() | 184 | OPcmciaSocket::~OPcmciaSocket() |
182 | { | 185 | { |
183 | qDebug( "OPcmciaSocket::~OPcmciaSocket()" ); | 186 | qDebug( "OPcmciaSocket::~OPcmciaSocket()" ); |
184 | cleanup(); | 187 | cleanup(); |
185 | } | 188 | } |
186 | 189 | ||
187 | 190 | ||
188 | /* internal */ void OPcmciaSocket::init() | 191 | /* internal */ void OPcmciaSocket::init() |
189 | { | 192 | { |
190 | // open control socket and gather file descriptor | 193 | // open control socket and gather file descriptor |
191 | if ( _major ) | 194 | if ( _major ) |
192 | { | 195 | { |
193 | dev_t dev = makedev( _major, _socket ); | 196 | dev_t dev = makedev( _major, _socket ); |
194 | 197 | ||
195 | #ifdef OPCMCIA_DEBUG | 198 | #ifdef OPCMCIA_DEBUG |
196 | QString filename = "/tmp/opcmciasystem-debug"; | 199 | QString filename = "/tmp/opcmciasystem-debug"; |
197 | if ( QFile::exists( filename ) ) | 200 | if ( QFile::exists( filename ) ) |
198 | #else | 201 | #else |
199 | QString filename = QString().sprintf( "/tmp/opcmciasystem-%d", ::getpid() ); | 202 | QString filename = QString().sprintf( "/tmp/opcmciasystem-%d", ::getpid() ); |
200 | if ( ::mknod( (const char*) filename, ( S_IFCHR|S_IREAD|S_IWRITE ), dev ) == 0 ) | 203 | if ( ::mknod( (const char*) filename, ( S_IFCHR|S_IREAD|S_IWRITE ), dev ) == 0 ) |
201 | #endif | 204 | #endif |
202 | { | 205 | { |
203 | _fd = ::open( (const char*) filename, O_RDONLY); | 206 | _fd = ::open( (const char*) filename, O_RDONLY); |
204 | if ( !_fd ) | 207 | if ( !_fd ) |
205 | { | 208 | { |
206 | qWarning( "OPcmciaSocket::init() - can't open control socket (%s)", strerror( errno ) ); | 209 | qWarning( "OPcmciaSocket::init() - can't open control socket (%s)", strerror( errno ) ); |
207 | } | 210 | } |
208 | else | 211 | else |
209 | { | 212 | { |
210 | ::unlink( (const char*) filename ); | 213 | ::unlink( (const char*) filename ); |
211 | } | 214 | } |
212 | } | 215 | } |
213 | else | 216 | else |
214 | { | 217 | { |
215 | qWarning( "OPcmciaSocket::init() - can't create device node '%s' (%s)", (const char*) filename, strerror( errno ) ); | 218 | qWarning( "OPcmciaSocket::init() - can't create device node '%s' (%s)", (const char*) filename, strerror( errno ) ); |
216 | } | 219 | } |
217 | } | 220 | } |
218 | } | 221 | } |
219 | 222 | ||
220 | /* internal */ void OPcmciaSocket::cleanup() | 223 | /* internal */ void OPcmciaSocket::cleanup() |
221 | { | 224 | { |
222 | // close control socket | 225 | // close control socket |
223 | } | 226 | } |
224 | 227 | ||
225 | /* internal */ bool OPcmciaSocket::getTuple( cisdata_t tuple ) const | 228 | /* internal */ bool OPcmciaSocket::getTuple( cisdata_t tuple ) const |
226 | { | 229 | { |
227 | _ioctlarg.tuple.DesiredTuple = tuple; | 230 | _ioctlarg.tuple.DesiredTuple = tuple; |
228 | _ioctlarg.tuple.Attributes = TUPLE_RETURN_COMMON; | 231 | _ioctlarg.tuple.Attributes = TUPLE_RETURN_COMMON; |
229 | _ioctlarg.tuple.TupleOffset = 0; | 232 | _ioctlarg.tuple.TupleOffset = 0; |
230 | 233 | ||
231 | int result; | 234 | int result; |
232 | result = ::ioctl(_fd, DS_GET_FIRST_TUPLE, &_ioctlarg); | 235 | result = ::ioctl(_fd, DS_GET_FIRST_TUPLE, &_ioctlarg); |
233 | if ( result != 0 ) | 236 | if ( result != 0 ) |
234 | { | 237 | { |
235 | qWarning( "OPcmciaSocket::getTuple() - DS_GET_FIRST_TUPLE failed (%s)", strerror( errno ) ); | 238 | qWarning( "OPcmciaSocket::getTuple() - DS_GET_FIRST_TUPLE failed (%s)", strerror( errno ) ); |
236 | return false; | 239 | return false; |
237 | } | 240 | } |
238 | 241 | ||
239 | result = ::ioctl(_fd, DS_GET_TUPLE_DATA, &_ioctlarg); | 242 | result = ::ioctl(_fd, DS_GET_TUPLE_DATA, &_ioctlarg); |
240 | if ( result != 0 ) | 243 | if ( result != 0 ) |
241 | { | 244 | { |
242 | qWarning( "OPcmciaSocket::getTuple() - DS_GET_TUPLE_DATA failed (%s)", strerror( errno ) ); | 245 | qWarning( "OPcmciaSocket::getTuple() - DS_GET_TUPLE_DATA failed (%s)", strerror( errno ) ); |
243 | return false; | 246 | return false; |
244 | } | 247 | } |
245 | 248 | ||
246 | result = ::ioctl( _fd, DS_PARSE_TUPLE, &_ioctlarg ); | 249 | result = ::ioctl( _fd, DS_PARSE_TUPLE, &_ioctlarg ); |
247 | if ( result != 0 ) | 250 | if ( result != 0 ) |
248 | { | 251 | { |
249 | qWarning( "OPcmciaSocket::getTuple() - DS_PARSE_TUPLE failed (%s)", strerror( errno ) ); | 252 | qWarning( "OPcmciaSocket::getTuple() - DS_PARSE_TUPLE failed (%s)", strerror( errno ) ); |
250 | return false; | 253 | return false; |
251 | } | 254 | } |
252 | 255 | ||
253 | return true; | 256 | return true; |
254 | } | 257 | } |
255 | 258 | ||
256 | 259 | ||
257 | int OPcmciaSocket::number() const | 260 | int OPcmciaSocket::number() const |
258 | { | 261 | { |
259 | return _socket; | 262 | return _socket; |
260 | } | 263 | } |
261 | 264 | ||
262 | 265 | ||
263 | QString OPcmciaSocket::identity() const | 266 | QString OPcmciaSocket::identity() const |
264 | { | 267 | { |
265 | return ( strcmp( name(), "empty" ) == 0 ) ? "<Empty Socket>" : name(); | 268 | return ( strcmp( name(), "empty" ) == 0 ) ? "<Empty Socket>" : name(); |
266 | } | 269 | } |
267 | 270 | ||
268 | 271 | ||
269 | const OPcmciaSocket::OPcmciaSocketCardStatus OPcmciaSocket::status() const | 272 | const OPcmciaSocket::OPcmciaSocketCardStatus OPcmciaSocket::status() const |
270 | { | 273 | { |
271 | cs_status_t cs_status; | 274 | cs_status_t cs_status; |
272 | cs_status.Function = 0; | 275 | cs_status.Function = 0; |
273 | int result = ::ioctl( _fd, DS_GET_STATUS, &cs_status ); | 276 | int result = ::ioctl( _fd, DS_GET_STATUS, &cs_status ); |
274 | if ( result != 0 ) | 277 | if ( result != 0 ) |
275 | { | 278 | { |
276 | qWarning( "OPcmciaSocket::status() - DS_GET_STATUS failed (%s)", strerror( errno ) ); | 279 | qWarning( "OPcmciaSocket::status() - DS_GET_STATUS failed (%s)", strerror( errno ) ); |
277 | return Unknown; | 280 | return Unknown; |
278 | } | 281 | } |
279 | else | 282 | else |
280 | { | 283 | { |
281 | qDebug( " card status = 0x%08x", cs_status.CardState ); | 284 | qDebug( " card status = 0x%08x", cs_status.CardState ); |
282 | qDebug( " socket status = 0x%08x", cs_status.SocketState ); | 285 | qDebug( " socket status = 0x%08x", cs_status.SocketState ); |
283 | return (OPcmciaSocket::OPcmciaSocketCardStatus) (cs_status.CardState + cs_status.SocketState); | 286 | return (OPcmciaSocket::OPcmciaSocketCardStatus) (cs_status.CardState + cs_status.SocketState); |
284 | } | 287 | } |
285 | } | 288 | } |
286 | 289 | ||
287 | 290 | ||
288 | bool OPcmciaSocket::isUnsupported() const | 291 | bool OPcmciaSocket::isUnsupported() const |
289 | { | 292 | { |