|
1 /* |
|
2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation of the CWimUtilityFuncs class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "WimUtilityFuncs.h" |
|
22 #include "Wimi.h" // WIMI definitions |
|
23 #include "WimDefs.h" |
|
24 #include "WimTrace.h" |
|
25 |
|
26 #include <e32property.h> // RProperty |
|
27 |
|
28 #ifdef RD_STARTUP_CHANGE |
|
29 #include <startupdomainpskeys.h> // Property values |
|
30 #else |
|
31 #include <PSVariables.h> // Property values |
|
32 #endif // RD_STARTUP_CHANGE |
|
33 |
|
34 #ifdef BT_SAP_TEST_BY_CHARGER |
|
35 #include <PSVariables.h> // Property values |
|
36 #else |
|
37 //#include <BTSapInternalPSKeys.h> // BT Sap property values |
|
38 #include <BTSapDomainPSKeys.h> |
|
39 #endif // BT_SAP_TEST_BY_CHARGER |
|
40 |
|
41 //If want to use emulator hw, uncomment this line |
|
42 #define __EMULATOR_HW__ |
|
43 |
|
44 // ============================ MEMBER FUNCTIONS =============================== |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CWimUtilityFuncs::CWimUtilityFuncs |
|
48 // C++ default constructor can NOT contain any code, that |
|
49 // might leave. |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 CWimUtilityFuncs::CWimUtilityFuncs() |
|
53 { |
|
54 _WIMTRACE(_L("WIM | WIMServer | CWimUtilityFuncs::CWimUtilityFuncs | Begin")); |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CWimUtilityFuncs::ConstructL |
|
59 // Symbian 2nd phase constructor can leave. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 void CWimUtilityFuncs::ConstructL() |
|
63 { |
|
64 _WIMTRACE(_L("WIM | WIMServer | CWimUtilityFuncs::ConstructL | Begin")); |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CWimUtilityFuncs::NewL |
|
69 // Two-phased constructor. |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 CWimUtilityFuncs* CWimUtilityFuncs::NewL() |
|
73 { |
|
74 _WIMTRACE(_L("WIM | WIMServer | CWimUtilityFuncs::NewL | Begin")); |
|
75 CWimUtilityFuncs* self = new( ELeave ) CWimUtilityFuncs; |
|
76 |
|
77 CleanupStack::PushL( self ); |
|
78 self->ConstructL(); |
|
79 CleanupStack::Pop( self ); |
|
80 |
|
81 return self; |
|
82 } |
|
83 |
|
84 |
|
85 // Destructor |
|
86 CWimUtilityFuncs::~CWimUtilityFuncs() |
|
87 { |
|
88 _WIMTRACE(_L("WIM | WIMServer | CWimUtilityFuncs::~CWimUtilityFuncs | Begin")); |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CWimUtilityFuncs::::MapWIMError |
|
93 // Map WIMI errors to WIM errors |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 TInt CWimUtilityFuncs::MapWIMError( WIMI_STAT aStatus ) |
|
97 { |
|
98 _WIMTRACE2(_L("WIM | WIMServer | CWimUtilityFuncs::MapWIMError aStatus=%d"), aStatus); |
|
99 TInt err = KErrUnknown; |
|
100 |
|
101 switch ( aStatus ) |
|
102 { |
|
103 case WIMI_Err: |
|
104 case WIMI_ERR_Internal: |
|
105 err = KErrCorrupt; |
|
106 break; |
|
107 case WIMI_ERR_OutOfMemory: |
|
108 err = KErrNoMemory; |
|
109 break; |
|
110 case WIMI_Ok: |
|
111 err = KErrNone; |
|
112 break; |
|
113 case WIMI_ERR_BadParameters: |
|
114 err = KErrArgument; |
|
115 break; |
|
116 case WIMI_ERR_ServerCertRejected: |
|
117 err = KErrCorrupt; |
|
118 break; |
|
119 case WIMI_ERR_CipherNotSupported: |
|
120 case WIMI_ERR_MACANotSupported: |
|
121 err = KErrNotSupported; |
|
122 break; |
|
123 case WIMI_ERR_UnsupportedCertificate: |
|
124 err = KErrNotSupported; |
|
125 break; |
|
126 case WIMI_ERR_SessionNotSet: |
|
127 err = KErrDisconnected; |
|
128 break; |
|
129 case WIMI_ERR_WrongKES: |
|
130 err = KErrCorrupt; |
|
131 break; |
|
132 case WIMI_ERR_DecodeError: |
|
133 err = KErrCorrupt; |
|
134 break; |
|
135 case WIMI_ERR_ExpiredReference: |
|
136 err = KErrArgument; |
|
137 break; |
|
138 case WIMI_ERR_NoKey: |
|
139 err = KErrNotFound; |
|
140 break; |
|
141 case WIMI_ERR_CertNotYetValid: |
|
142 err = KErrCorrupt; |
|
143 break; |
|
144 case WIMI_ERR_CertExpired: |
|
145 err = KErrTimedOut; |
|
146 break; |
|
147 case WIMI_ERR_UnknownCA: |
|
148 err = KErrArgument; |
|
149 break; |
|
150 case WIMI_ERR_CertParseError: |
|
151 err = KErrCorrupt; |
|
152 break; |
|
153 case WIMI_ERR_KeyStorageFull: |
|
154 err = KErrDirFull; |
|
155 break; |
|
156 case WIMI_ERR_BadKey: |
|
157 err = KErrArgument; |
|
158 break; |
|
159 case WIMI_ERR_CertStorageFull: |
|
160 err = KErrDirFull; |
|
161 break; |
|
162 case WIMI_ERR_BadCert: |
|
163 err = KErrArgument; |
|
164 break; |
|
165 case WIMI_ERR_PStorageError: |
|
166 err = KErrDirFull; |
|
167 break; |
|
168 case WIMI_ERR_CertNotFound: |
|
169 err = KErrNotFound; |
|
170 break; |
|
171 case WIMI_ERR_KeyNotFound: |
|
172 err = KErrNotFound; |
|
173 break; |
|
174 case WIMI_ERR_BadReference: |
|
175 err = KErrCorrupt; |
|
176 break; |
|
177 case WIMI_ERR_OperNotSupported: |
|
178 err = KErrNotSupported; |
|
179 break; |
|
180 case WIMI_ERR_BadPIN: |
|
181 err = KErrArgument; |
|
182 break; |
|
183 case WIMI_ERR_PINBlocked: |
|
184 err = KErrLocked; |
|
185 break; |
|
186 case WIMI_ERR_CardDriverInitError: |
|
187 err = KErrBadDriver; |
|
188 break; |
|
189 case WIMI_ERR_CardIOError: |
|
190 err = KErrHardwareNotAvailable; |
|
191 break; |
|
192 case WIMI_ERR_AlgorithmNotYetImplemented: |
|
193 err = KErrNotSupported; |
|
194 break; |
|
195 case WIMI_ERR_UserCancelled: |
|
196 err = KErrCancel; |
|
197 break; |
|
198 default: |
|
199 err = KErrUnknown; |
|
200 } |
|
201 return err; |
|
202 } |
|
203 |
|
204 // ----------------------------------------------------------------------------- |
|
205 // CWimUtilityFuncs::TrIdLC |
|
206 // Creates a new TWimReqTrId item. |
|
207 // ----------------------------------------------------------------------------- |
|
208 // |
|
209 TWimReqTrId* CWimUtilityFuncs::TrIdLC( TAny* aTrId, TWimReqType aReqType ) const |
|
210 { |
|
211 _WIMTRACE(_L("WIM | WIMServer | CWimUtilityFuncs::GetTrIdLC | Begin")); |
|
212 TWimReqTrId* reqTrId = new( ELeave ) TWimReqTrId; |
|
213 CleanupStack::PushL( reqTrId ); |
|
214 reqTrId->iReqType = aReqType; |
|
215 reqTrId->iReqTrId = aTrId; |
|
216 return reqTrId; |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // CWimUtilityFuncs::DesLC |
|
221 // Utility function that reads a descriptor from the clients address |
|
222 // space. The caller has to free the returned HBufC8. |
|
223 // ----------------------------------------------------------------------------- |
|
224 // |
|
225 HBufC8* CWimUtilityFuncs::DesLC( |
|
226 const TInt aIndex, |
|
227 const RMessage2& aMessage ) const |
|
228 { |
|
229 _WIMTRACE(_L("WIM | WIMServer | CWimUtilityFuncs::GetDesLC | Begin")); |
|
230 |
|
231 TInt len = aMessage.GetDesLength( aIndex ); |
|
232 |
|
233 //User might cancelled operation, so we need to leave before |
|
234 //HBufC panics. We do not want panic at this point. Leave is Trapped in |
|
235 //session |
|
236 if ( len < 0 ) |
|
237 { |
|
238 User::Leave( KErrArgument ); |
|
239 } |
|
240 |
|
241 HBufC8* buf = HBufC8::NewLC( len ); // free'd by caller |
|
242 TPtr8 ptr = buf->Des(); |
|
243 aMessage.ReadL( aIndex, ptr ); |
|
244 |
|
245 return buf; |
|
246 } |
|
247 |
|
248 // ----------------------------------------------------------------------------- |
|
249 // CWimUtilityFuncs::SimState |
|
250 // Get state of SIM/SWIM card. Uses system wide repository to get state. |
|
251 // If card is OK return KErrNone, otherwise some other system wide state. |
|
252 // ----------------------------------------------------------------------------- |
|
253 // |
|
254 TInt CWimUtilityFuncs::SimState() |
|
255 { |
|
256 TInt simState = KErrNotReady; |
|
257 TInt stateError = 0; |
|
258 |
|
259 // Get SIM state |
|
260 |
|
261 #ifdef RD_STARTUP_CHANGE |
|
262 stateError = RProperty::Get( KPSUidStartup, |
|
263 KPSSimStatus, |
|
264 simState ); |
|
265 #else |
|
266 stateError = RProperty::Get( KUidSystemCategory, |
|
267 KPSUidSIMStatusValue, |
|
268 simState ); |
|
269 #endif // RD_STARTUP_CHANGE |
|
270 |
|
271 // In WINS may not return real SIM state -> ignore |
|
272 #ifdef __WINS__ |
|
273 stateError = 0; |
|
274 #endif |
|
275 |
|
276 if ( stateError == KErrNone ) // Got SIM state succesfully |
|
277 { |
|
278 // In WINS may not return real SIM state -> ignore |
|
279 #ifdef __WINS__ |
|
280 |
|
281 #ifdef __EMULATOR_HW__ |
|
282 |
|
283 #ifdef RD_STARTUP_CHANGE |
|
284 simState = ESimUsable; |
|
285 #else |
|
286 simState = EPSSimOk; |
|
287 #endif // RD_STARTUP_CHANGE |
|
288 |
|
289 #else //__EMULATOR_HW__ |
|
290 |
|
291 #ifdef RD_STARTUP_CHANGE |
|
292 simState = ESimNotPresent; |
|
293 #else |
|
294 simState = EPSSimNotPresent; |
|
295 #endif // RD_STARTUP_CHANGE |
|
296 |
|
297 #endif //__EMULATOR_HW__ |
|
298 |
|
299 #endif // __WINS__ |
|
300 |
|
301 _WIMTRACE2(_L("WIM | WIMServer | CWimUtilityFuncs::SimState|simState=%d"),simState); |
|
302 |
|
303 #ifdef RD_STARTUP_CHANGE |
|
304 if ( simState == ESimUsable ) |
|
305 #else |
|
306 if ( simState == EPSSimOk ) |
|
307 #endif // RD_STARTUP_CHANGE |
|
308 { |
|
309 simState = KErrInUse; |
|
310 #ifdef BT_SAP_TEST_BY_CHARGER |
|
311 // Test of BT Sap by charger. To emulate connected BT Sap, charger must be |
|
312 // connected and charging. |
|
313 stateError = RProperty::Get( KUidSystemCategory, |
|
314 KPSUidChargerStatusValue, |
|
315 simState ); |
|
316 #else |
|
317 // Get state of BT Sap |
|
318 stateError = RProperty::Get( KPSUidBluetoothSapConnectionState, |
|
319 KBTSapConnectionState, |
|
320 simState ); |
|
321 #endif // BT_SAP_TEST_BY_CHARGER |
|
322 |
|
323 // In WINS may not return real SIM state -> ignore |
|
324 #ifdef __WINS__ |
|
325 stateError = 0; |
|
326 #endif |
|
327 |
|
328 if ( KErrNone == stateError ) // Got BT SAP state succesfully |
|
329 { |
|
330 // In WINS may not return real SIM state -> ignore |
|
331 #ifdef __WINS__ |
|
332 |
|
333 #ifdef BT_SAP_TEST_BY_CHARGER |
|
334 simState = EPSChargerDisconnected; |
|
335 #else |
|
336 simState = EBTSapNotConnected; |
|
337 #endif // BT_SAP_TEST_BY_CHARGER |
|
338 |
|
339 #endif // __WINS__ |
|
340 |
|
341 _WIMTRACE2(_L("WIM | WIMServer | CWimUtilityFuncs::SimState|simState=%d"),simState); |
|
342 |
|
343 #ifdef BT_SAP_TEST_BY_CHARGER |
|
344 if ( EPSChargerConnected != simState ) |
|
345 #else |
|
346 if ( EBTSapConnected != simState ) |
|
347 #endif // BT_SAP_TEST_BY_CHARGER |
|
348 { |
|
349 simState = KErrNone; |
|
350 } |
|
351 else |
|
352 { |
|
353 simState = KErrInUse; |
|
354 } |
|
355 } |
|
356 else if ( KErrNotFound == stateError ) |
|
357 { |
|
358 _WIMTRACE(_L("WIM | WIMServer | CWimUtilityFuncs::SimState|BTSap not found, WIM initialization continued")); |
|
359 simState = KErrNone; |
|
360 } |
|
361 else |
|
362 { |
|
363 _WIMTRACE2(_L("WIM | WIMServer | CWimUtilityFuncs::SimState|BTSap ERROR| stateError=%d"),stateError); |
|
364 } |
|
365 } |
|
366 else // simState != ESimUsable/EPSSimOk |
|
367 { |
|
368 simState = KErrNotReady; |
|
369 } |
|
370 } |
|
371 _WIMTRACE2(_L("WIM | WIMServer | CWimUtilityFuncs::SimState|End|simState=%d"),simState); |
|
372 return simState; |
|
373 } |
|
374 // ----------------------------------------------------------------------------- |
|
375 // CWimCertHandler::MapCertLocation |
|
376 // Map Wimlib certificate CDF to our own type |
|
377 // ----------------------------------------------------------------------------- |
|
378 // |
|
379 TUint8 CWimUtilityFuncs::MapCertLocation( const TUint8 aCertCDF ) const |
|
380 { |
|
381 TWimCertificateCDF certCDF; |
|
382 |
|
383 switch ( aCertCDF ) |
|
384 { |
|
385 case WIMLIB_CERTIFICATES_CDF: |
|
386 { |
|
387 certCDF = EWimCertificatesCDF; |
|
388 break; |
|
389 } |
|
390 case WIMLIB_TRUSTEDCERTS_CDF: |
|
391 { |
|
392 certCDF = EWimTrustedCertsCDF; |
|
393 break; |
|
394 } |
|
395 case WIMLIB_USEFULCERTS_CDF: |
|
396 { |
|
397 certCDF = EWimUsefulCertsCDF; |
|
398 break; |
|
399 } |
|
400 default: |
|
401 { |
|
402 certCDF = EWimUnknownCDF; |
|
403 break; |
|
404 } |
|
405 } |
|
406 return ( TUint8 )certCDF; |
|
407 } |
|
408 |
|
409 // End of File |