|
1 /* |
|
2 * Copyright (c) 2008 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "cstsconnection.h" |
|
19 // INCLUDE FILES |
|
20 #include "s60commonutils.h" |
|
21 #include "cstsconnection.h" |
|
22 #include "cstschannelmanager.h" |
|
23 #include "cstsslotmanager.h" |
|
24 #include "cstspinmanager.h" |
|
25 #include "cstsapduexchanger.h" |
|
26 #include "cstsaccesscontrol.h" |
|
27 #include "cstscardoperationsfacade.h" |
|
28 #include "cstscardappmanager.h" |
|
29 #include "cstsenvelope.h" |
|
30 #include "cstsresphandler.h" |
|
31 #include "cstsselectfile.h" |
|
32 #include "cstsrespapdu.h" |
|
33 #include "cstsmidletinfo.h" |
|
34 #include "cstsuri.h" |
|
35 #include "cstsbtsaplistener.h" |
|
36 #include "cstscardstatelistener.h" |
|
37 #include "fs_methodcall.h" |
|
38 #include "logger.h" |
|
39 #include "javasymbianoslayer.h" |
|
40 |
|
41 namespace java |
|
42 { |
|
43 namespace satsa |
|
44 { |
|
45 |
|
46 // CONSTANTS |
|
47 const TInt KSTSBasicChannel = 0; |
|
48 const TInt KATRMaxLength = 0xFF; |
|
49 |
|
50 // ============================ MEMBER FUNCTIONS =============================== |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CSTSConnection::CSTSConnection |
|
54 // C++ default constructor can NOT contain any code, that |
|
55 // might leave. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 CSTSConnection::CSTSConnection(MSTSRespHandler* aRespHandler, |
|
59 CSTSMidletInfo* aMidletInfo) : |
|
60 java::util::FunctionServer("MyAPDUServer"), iChannel(0) |
|
61 { |
|
62 LOG(ESATSA, EInfo, "+ CSTSConnection::CSTSConnection"); |
|
63 createServerToNewThread(); |
|
64 iState = EClosed; |
|
65 iRespHandler = aRespHandler; |
|
66 iMidletInfo = aMidletInfo; |
|
67 |
|
68 LOG(ESATSA, EInfo, "-- Returning from CSTSConnection::CSTSConnection "); |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CSTSConnection::ConstructL |
|
73 // Symbian 2nd phase constructor can leave. |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 void CSTSConnection::ConstructL() |
|
77 { |
|
78 LOG(ESATSA, EInfo, "+ CSTSConnection::ConstructL "); |
|
79 |
|
80 iCOFacade = CSTSCardOperationsFacade::NewL(); |
|
81 iApduExchanger = CSTSApduExchanger::NewL(mJniEnv, mJavaPeerObject, |
|
82 iCOFacade); |
|
83 iAccessControl = CSTSAccessControl::NewL(iMidletInfo); |
|
84 iPinManager = CSTSPinManager::NewL(mJniEnv, mJavaPeerObject, |
|
85 iApduExchanger, iAccessControl, iRespHandler); |
|
86 iSlotManager = CSTSSlotManager::NewL(iCOFacade); |
|
87 iChannelManager = CSTSChannelManager::NewL(iApduExchanger); |
|
88 iATR = HBufC8::NewL(KATRMaxLength); |
|
89 iBTSapListener = CSTSBTSapListener::NewL(this); |
|
90 iCardStateListener = CSTSCardStateListener::NewL(this); |
|
91 |
|
92 LOG(ESATSA, EInfo, "-- CSTSConnection::ConstructL "); |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CSTSConnection::NewL |
|
97 // Two-phased constructor. |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 CSTSConnection* CSTSConnection::NewL(JNIEnv& aJni, jobject aPeer, |
|
101 MSTSRespHandler* aRespHandler, CSTSMidletInfo* aMidletInfo) |
|
102 { |
|
103 LOG(ESATSA, EInfo, "+ CSTSConnection::NewL "); |
|
104 CSTSConnection* self = |
|
105 new(ELeave) CSTSConnection(aRespHandler, aMidletInfo); |
|
106 |
|
107 CleanupStack::PushL(self); |
|
108 self->attachToVm(aJni, aPeer); |
|
109 CallMethodL(self, &CSTSConnection::ConstructL, self); |
|
110 CleanupStack::Pop(self); |
|
111 LOG(ESATSA, EInfo, "-- CSTSConnection::NewL "); |
|
112 return self; |
|
113 } |
|
114 |
|
115 void CSTSConnection::vmAttached() |
|
116 { |
|
117 |
|
118 |
|
119 } |
|
120 |
|
121 // Destructor |
|
122 CSTSConnection::~CSTSConnection() |
|
123 { |
|
124 LOG(ESATSA, EInfo, "+ CSTSConnection::~CSTSConnection "); |
|
125 // for safety, close is called here |
|
126 Close(); |
|
127 |
|
128 delete iCardStateListener; |
|
129 delete iBTSapListener; |
|
130 delete iATR; |
|
131 delete iChannelManager; |
|
132 delete iSlotManager; |
|
133 delete iPinManager; |
|
134 delete iAccessControl; |
|
135 delete iApduExchanger; |
|
136 delete iCOFacade; |
|
137 |
|
138 delete iCardAppManager; |
|
139 delete iRespHandler; |
|
140 delete iMidletInfo; |
|
141 delete iCmdApdu; |
|
142 delete iURI; |
|
143 |
|
144 } |
|
145 |
|
146 void CSTSConnection::WrapOpenL(CSTSConnection* connection) |
|
147 { |
|
148 |
|
149 CallMethodL(connection, &CSTSConnection::OpenL, connection); |
|
150 } |
|
151 // ----------------------------------------------------------------------------- |
|
152 // CSTSConnection::OpenL |
|
153 // Checks does URI exist, checks is it AID or SAT connection, in AID |
|
154 // case checks Access Control related issues, opens connection to gived card |
|
155 // application or opens SAT connection |
|
156 // (other items were commented in a header). |
|
157 // ----------------------------------------------------------------------------- |
|
158 // |
|
159 void CSTSConnection::OpenL() |
|
160 { |
|
161 LOG(ESATSA, EInfo, "+ CSTSConnection::OpenL"); |
|
162 |
|
163 LOG(ESATSA, EInfo, "CSTSConnection::OpenL: Checking if BT SAP is ON"); |
|
164 //if BT Sap is in use, connection cannot be established |
|
165 if (iBTSapListener->IsInUse()) |
|
166 { |
|
167 ELOG(ESATSA, "CSTSConnection::OpenL:BT SAP is ON"); |
|
168 User::Leave(KSTSErrConnectionNotFound + KSTSErrCNTBtSapInUse); |
|
169 |
|
170 } |
|
171 LOG(ESATSA, EInfo, "CSTSConnection::OpenL: Checking if Card is available"); |
|
172 //if card is not available, connection cannot be established |
|
173 if (!iCardStateListener->CardIsAvailable()) |
|
174 { |
|
175 ELOG(ESATSA, "CSTSConnection::OpenL: Card is NOT available"); |
|
176 User::Leave(KSTSErrConnectionNotFound + KSTSErrCNTNoCard); |
|
177 } |
|
178 |
|
179 //start listening BTSap events |
|
180 if (!iBTSapListener->IsActive()) |
|
181 { |
|
182 LOG(ESATSA, EInfo, "CSTSConnection::OpenL: start bt sap listener"); |
|
183 iBTSapListener->Start(); |
|
184 } |
|
185 //is slot one of existing slots |
|
186 if (!iSlotManager->DoesExistL(iURI->Slot())) |
|
187 { |
|
188 ELOG(ESATSA, "CSTSConnection::OpenL: Slot does not exist!! "); |
|
189 //ConnectionNotFoundException |
|
190 User::Leave(KSTSErrConnectionNotFound + KSTSErrCNTNoSlot); |
|
191 } |
|
192 |
|
193 iApduExchanger->SetReader(iURI->Slot()); |
|
194 iURITarget = iURI->Type(); |
|
195 iApduExchanger->SetConnectionType(iURITarget == CSTSURI::ESAT); |
|
196 |
|
197 // if SAT we try to check if card GSM or UICC card |
|
198 if (iURITarget == CSTSURI::ESAT) |
|
199 { |
|
200 LOG(ESATSA, EInfo, "CSTSConnection::OpenL: connection type is SAT"); |
|
201 // check is phone running in GSM mode |
|
202 if (iCOFacade->IsGSMNetwork()) |
|
203 { |
|
204 iNetwork = ESTSTypeGSM; |
|
205 } |
|
206 else |
|
207 { |
|
208 iNetwork = ESTSTypeUMTS; |
|
209 } |
|
210 } |
|
211 |
|
212 // if AID then parse ACF and check domain. |
|
213 if (iURITarget == CSTSURI::EAID) |
|
214 { |
|
215 LOG(ESATSA, EInfo, "CSTSConnection::OpenL: connection type is AID"); |
|
216 CSTSCardAppManager* tmpAppManager = CSTSCardAppManager::NewL( |
|
217 iApduExchanger, iURI->AID()); |
|
218 delete iCardAppManager; |
|
219 iCardAppManager = tmpAppManager; |
|
220 // try to select card application to determine does it exist or not |
|
221 LOG(ESATSA, EInfo, "CSTSConnection::OpenL: going to select card application"); |
|
222 DoSelectApplicationL(); |
|
223 // close channel(closes also application) so that access control can |
|
224 // use it for reading access control files from card |
|
225 LOG(ESATSA, EInfo, "CSTSConnection::OpenL: closing channel"); |
|
226 iChannelManager->CloseChannel(iChannel); |
|
227 LOG(ESATSA, EInfo, "CSTSConnection::OpenL: setting basic channel"); |
|
228 iApduExchanger->SetChannel(0); //basic channel |
|
229 LOG(ESATSA, EInfo, "CSTSConnection::OpenL: going to set AID"); |
|
230 iAccessControl->SetAIDL(iURI->AID()); |
|
231 LOG(ESATSA, EInfo, "CSTSConnection::OpenL: going to read files"); |
|
232 iAccessControl->ReadFilesL(); |
|
233 if (!iAccessControl->IsAllowedDomain()) |
|
234 { |
|
235 ELOG(ESATSA, "CSTSConnection::OpenL: Domain is not allowed"); |
|
236 // SecurityException |
|
237 User::Leave(KSTSErrSecurity + KSTSErrSECAccessNotAllowed); |
|
238 } |
|
239 |
|
240 // if access control rights were ok we can select card application again |
|
241 // and leave it open |
|
242 LOG(ESATSA, EInfo, "CSTSConnection::OpenL: Select App if access is allowed"); |
|
243 DoSelectApplicationL(); |
|
244 } |
|
245 |
|
246 // if all was ok |
|
247 iState = EOpened; |
|
248 LOG(ESATSA, EInfo, "-- CSTSConnection::OpenL"); |
|
249 } |
|
250 |
|
251 void CSTSConnection::WrapCloseL(CSTSConnection* connection) |
|
252 { |
|
253 CallMethodL(connection, &CSTSConnection::CloseL, connection); |
|
254 } |
|
255 // ----------------------------------------------------------------------------- |
|
256 // CSTSConnection::CloseL |
|
257 // Cancels any pending operation, deselects card application if needed and |
|
258 // closes opened channel if needed. |
|
259 // (other items were commented in a header). |
|
260 // ----------------------------------------------------------------------------- |
|
261 // |
|
262 void CSTSConnection::CloseL() |
|
263 { |
|
264 LOG(ESATSA, EInfo, "+ CSTSConnection::CloseL"); |
|
265 iPinManager->CancelOperation(); |
|
266 iApduExchanger->CancelExchange(); |
|
267 |
|
268 if (iURITarget == CSTSURI::EAID) |
|
269 { |
|
270 if (iState == EOpened) |
|
271 { |
|
272 TInt appErr = iCardAppManager->DeselectApplication(); |
|
273 TInt channelErr = iChannelManager->CloseChannel(iChannel); |
|
274 |
|
275 if (channelErr == KErrNone) |
|
276 { |
|
277 iState = EClosed; |
|
278 } |
|
279 // if application deselection or channel closing fails |
|
280 // we can throw IOException in java side |
|
281 if (appErr != KErrNone || channelErr != KErrNone) |
|
282 { |
|
283 User::Leave(KSTSErrIO + KSTSErrIOErrorIO); |
|
284 } |
|
285 } |
|
286 else |
|
287 { |
|
288 // for safety, close access control also |
|
289 iAccessControl->Close(); |
|
290 iApduExchanger->SetChannel(KSTSBasicChannel); |
|
291 } |
|
292 } |
|
293 iState = EClosed; |
|
294 LOG(ESATSA, EInfo, "-- CSTSConnection::CloseL"); |
|
295 } |
|
296 |
|
297 // ----------------------------------------------------------------------------- |
|
298 // CSTSConnection::Close |
|
299 // WILL NOT LEAVE. For destructor use. Cancels any pending operation, deselects |
|
300 // card application if needed and closes opened channel if needed. |
|
301 // (other items were commented in a header). |
|
302 // ----------------------------------------------------------------------------- |
|
303 // |
|
304 inline void CSTSConnection::Close() |
|
305 { |
|
306 LOG(ESATSA, EInfo, "+ CSTSConnection::Close"); |
|
307 // Close is called in desctructor, so have to check in case |
|
308 // that contructor has leaved |
|
309 if (iPinManager) |
|
310 { |
|
311 iPinManager->CancelOperation(); |
|
312 } |
|
313 if (iApduExchanger) |
|
314 { |
|
315 iApduExchanger->CancelExchange(); |
|
316 } |
|
317 if (iURITarget == CSTSURI::EAID && iState == EOpened) |
|
318 { |
|
319 if (iCardAppManager) |
|
320 { |
|
321 iCardAppManager->DeselectApplication(); |
|
322 } |
|
323 if (iChannelManager) |
|
324 { |
|
325 iChannelManager->CloseChannel(iChannel); |
|
326 } |
|
327 } |
|
328 iState = EClosed; |
|
329 LOG(ESATSA, EInfo, "+ CSTSConnection::Close"); |
|
330 } |
|
331 |
|
332 void CSTSConnection::WrapChangePinL(CSTSConnection* connection, TInt aPinID) |
|
333 { |
|
334 CallMethodL(connection, &CSTSConnection::ChangePinL, aPinID, connection); |
|
335 } |
|
336 // ----------------------------------------------------------------------------- |
|
337 // CSTSConnection::ChangePinL |
|
338 // Delivers change pin call to pinmanager |
|
339 // (other items were commented in a header). |
|
340 // ----------------------------------------------------------------------------- |
|
341 // |
|
342 void CSTSConnection::ChangePinL(TInt aPinID) |
|
343 { |
|
344 LOG(ESATSA, EInfo, "+ CSTSConnection::ChangePinL"); |
|
345 CheckStateL(ETrue); //In SAT connection PIN method is not allowed |
|
346 iPinManager->ChangePinL(aPinID); |
|
347 LOG(ESATSA, EInfo, "-- CSTSConnection::ChangePinL"); |
|
348 } |
|
349 |
|
350 void CSTSConnection::WrapDisablePinL(CSTSConnection* connection, TInt aPinID) |
|
351 { |
|
352 CallMethodL(connection, &CSTSConnection::DisablePinL, aPinID, connection); |
|
353 } |
|
354 // ----------------------------------------------------------------------------- |
|
355 // CSTSConnection::DisablePinL |
|
356 // Delivers DisablePin call to pinmanager |
|
357 // (other items were commented in a header). |
|
358 // ----------------------------------------------------------------------------- |
|
359 // |
|
360 void CSTSConnection::DisablePinL(TInt aPinID) |
|
361 { |
|
362 LOG(ESATSA, EInfo, "+ CSTSConnection::DisablePinL"); |
|
363 CheckStateL(ETrue); //In SAT connection PIN method is not allowed |
|
364 iPinManager->DisablePinL(aPinID); |
|
365 LOG(ESATSA, EInfo, "-- CSTSConnection::DisablePinL"); |
|
366 } |
|
367 |
|
368 void CSTSConnection::WrapEnablePinL(CSTSConnection* connection, TInt aPinID) |
|
369 { |
|
370 CallMethodL(connection, &CSTSConnection::EnablePinL, aPinID, connection); |
|
371 } |
|
372 // ----------------------------------------------------------------------------- |
|
373 // CSTSConnection::EnablePinL |
|
374 // Delivers EnablePin call to pinmanager |
|
375 // (other items were commented in a header). |
|
376 // ----------------------------------------------------------------------------- |
|
377 // |
|
378 void CSTSConnection::EnablePinL(TInt aPinID) |
|
379 { |
|
380 LOG(ESATSA, EInfo, "+ CSTSConnection::EnablePinL"); |
|
381 CheckStateL(ETrue); //In SAT connection PIN method is not allowed |
|
382 iPinManager->EnablePinL(aPinID); |
|
383 LOG(ESATSA, EInfo, "-- CSTSConnection::EnablePinL"); |
|
384 } |
|
385 |
|
386 void CSTSConnection::WrapEnterPinL(CSTSConnection* connection, TInt aPinID) |
|
387 { |
|
388 CallMethodL(connection, &CSTSConnection::EnterPinL, aPinID, connection); |
|
389 } |
|
390 // ----------------------------------------------------------------------------- |
|
391 // CSTSConnection::EnterPinL |
|
392 // Delivers EnterPin call to pinmanager |
|
393 // (other items were commented in a header). |
|
394 // ----------------------------------------------------------------------------- |
|
395 // |
|
396 void CSTSConnection::EnterPinL(TInt aPinID) |
|
397 { |
|
398 LOG(ESATSA, EInfo, "+ CSTSConnection::EnterPinL"); |
|
399 CheckStateL(ETrue); //In SAT connection PIN method is not allowed |
|
400 iPinManager->EnterPinL(aPinID); |
|
401 LOG(ESATSA, EInfo, "-- CSTSConnection::EnterPinL"); |
|
402 } |
|
403 |
|
404 void CSTSConnection::WrapUnblockPinL(CSTSConnection* connection, |
|
405 TInt aBlockedPinID, TInt aUnblockingPinID) |
|
406 { |
|
407 CallMethodL(connection, &CSTSConnection::UnblockPinL, aBlockedPinID, |
|
408 aUnblockingPinID, connection); |
|
409 } |
|
410 // ----------------------------------------------------------------------------- |
|
411 // CSTSConnection::UnblockPinL |
|
412 // Delivers UnblockPin call to pinmanager |
|
413 // (other items were commented in a header). |
|
414 // ----------------------------------------------------------------------------- |
|
415 // |
|
416 void CSTSConnection::UnblockPinL(TInt aBlockedPinID, TInt aUnblockingPinID) |
|
417 { |
|
418 LOG(ESATSA, EInfo, "+ CSTSConnection::UnblockPinL"); |
|
419 CheckStateL(ETrue); //In SAT connection PIN method is not allowed |
|
420 iPinManager->UnblockPinL(aBlockedPinID, aUnblockingPinID); |
|
421 LOG(ESATSA, EInfo, "-- CSTSConnection::UnblockPinL"); |
|
422 } |
|
423 |
|
424 void CSTSConnection::WrapExchangeAPDUL(CSTSConnection* connection, |
|
425 TPtrC8 aCommandDes) |
|
426 { |
|
427 CallMethodL(connection, &CSTSConnection::ExchangeAPDUL, aCommandDes, |
|
428 connection); |
|
429 } |
|
430 // ----------------------------------------------------------------------------- |
|
431 // CSTSConnection::ExchangeAPDUL |
|
432 // Checks is apdu allowed and sends it to smart card. |
|
433 // (other items were commented in a header). |
|
434 // ----------------------------------------------------------------------------- |
|
435 // |
|
436 void CSTSConnection::ExchangeAPDUL(TPtrC8 aCommandAPDU) |
|
437 { |
|
438 LOG(ESATSA, EInfo, "+ CSTSConnection::ExchangeAPDUL"); |
|
439 CheckStateL(); |
|
440 |
|
441 LOG(ESATSA, EInfo, "CSTSConnection::ExchangeAPDUL:After the conversion"); |
|
442 if (iURITarget == CSTSURI::EAID) |
|
443 { |
|
444 LOG(ESATSA, EInfo, "CSTSConnection::ExchangeAPDUL: Type is AID"); |
|
445 CSTSCmdApdu* cmdApdu = NULL; |
|
446 cmdApdu = CSTSCmdApdu::NewL(aCommandAPDU, CSTSApdu::ESTSUICC); |
|
447 if (!cmdApdu) |
|
448 { |
|
449 ELOG(ESATSA, "CSTSConnection::ExchangeAPDUL: failed to create CSTSCmdApdu object!!"); |
|
450 } |
|
451 delete iCmdApdu; |
|
452 //must be saved to member variable for later use in asynchronous call |
|
453 iCmdApdu = cmdApdu; |
|
454 LOG(ESATSA, EInfo, "CSTSConnection::ExchangeAPDUL: check the channel"); |
|
455 iCmdApdu->CheckL(iChannel); |
|
456 } |
|
457 else |
|
458 { |
|
459 CSTSApdu::TSTSApduStandard standard = CSTSApdu::ESTSUICC; |
|
460 if (iNetwork == ESTSTypeGSM) |
|
461 { |
|
462 standard = CSTSApdu::ESTSGSM; |
|
463 } |
|
464 CSTSEnvelope* envelopeApdu = CSTSEnvelope::NewL(aCommandAPDU, standard); |
|
465 CleanupStack::PushL(envelopeApdu); |
|
466 envelopeApdu->CheckL(); |
|
467 envelopeApdu->SetClassByte(); |
|
468 delete iCmdApdu; |
|
469 //must be saved to member variable for later use in asynchronous call |
|
470 iCmdApdu = envelopeApdu; |
|
471 CleanupStack::Pop(envelopeApdu); |
|
472 } |
|
473 |
|
474 //only check in AID case |
|
475 if (iURITarget == CSTSURI::EAID) |
|
476 { |
|
477 LOG(ESATSA, EInfo, "CSTSConnection::ExchangeAPDUL:only check in AID case"); |
|
478 if (!iAccessControl->IsAllowedApduL(iCmdApdu->Header())) |
|
479 { |
|
480 //SecurityException |
|
481 User::Leave(KSTSErrSecurity + KSTSErrSECIllegalApdu); |
|
482 } |
|
483 } |
|
484 LOG(ESATSA, EInfo, "CSTSConnection::ExchangeAPDUL: Going to call ExchangeApduAsync "); |
|
485 iApduExchanger->ExchangeApduAsync(*iCmdApdu, iRespHandler); |
|
486 LOG(ESATSA, EInfo, "-- CSTSConnection::ExchangeAPDUL"); |
|
487 } |
|
488 |
|
489 std::wstring CSTSConnection::WrapGetATRL(CSTSConnection* connection) |
|
490 { |
|
491 LOG(ESATSA, EInfo, "+ CSTSConnection::WrapGetATRL"); |
|
492 std::wstring atrData; |
|
493 CallMethodL(atrData, connection, &CSTSConnection::GetATRL, connection); |
|
494 LOG(ESATSA, EInfo, "-- CSTSConnection::WrapGetATRL"); |
|
495 return atrData; |
|
496 } |
|
497 // ----------------------------------------------------------------------------- |
|
498 // CSTSConnection::GetATRL |
|
499 // Delivers GetATRL call to card operations facade |
|
500 // (other items were commented in a header). |
|
501 // ----------------------------------------------------------------------------- |
|
502 // |
|
503 std::wstring CSTSConnection::GetATRL() |
|
504 { |
|
505 LOG(ESATSA, EInfo, "+ CSTSConnection::GetATRL"); |
|
506 CheckStateL(); |
|
507 |
|
508 TPtr8 atrData(iATR->Des()); |
|
509 //aATR->Set( iATR->Des() ); |
|
510 iCOFacade->GetATR(atrData, iURI->Slot()); |
|
511 |
|
512 LOG(ESATSA, EInfo, "CSTSConnection::GetATRL: After iCOFacade->GetATR call "); |
|
513 |
|
514 HBufC16* tmp = HBufC16::NewL(KATRMaxLength); |
|
515 TPtr16 aTr(tmp->Des());// = NULL; // = (TPtr16*)(&atrData);//( NULL, 0 ); |
|
516 aTr.Copy(atrData); |
|
517 |
|
518 LOG(ESATSA, EInfo, "CSTSConnection::GetATRL: convert to wstring"); |
|
519 std::wstring atrResp = desToWstring(aTr); |
|
520 delete tmp; |
|
521 return atrResp; |
|
522 } |
|
523 |
|
524 std::wstring CSTSConnection::WrapGetSlotsL(CSTSConnection* connection) |
|
525 { |
|
526 LOG(ESATSA, EInfo, "+ CSTSConnection::WrapGetSlotsL"); |
|
527 std::wstring slotStr; |
|
528 CallMethodL(slotStr, connection, &CSTSConnection::GetSlotsL, connection); |
|
529 LOG(ESATSA, EInfo, "-- return CSTSConnection::WrapGetSlotsL"); |
|
530 return slotStr; |
|
531 |
|
532 } |
|
533 // ----------------------------------------------------------------------------- |
|
534 // CSTSConnection::GetSlotsL |
|
535 // Delivers GetSlots call to slot manager |
|
536 // (other items were commented in a header). |
|
537 // ----------------------------------------------------------------------------- |
|
538 // |
|
539 std::wstring CSTSConnection::GetSlotsL() |
|
540 { |
|
541 |
|
542 LOG(ESATSA, EInfo, "+ CSTSConnection::GetSlotsL"); |
|
543 //TPtr* respAPDU = reinterpret_cast<TPtr*>( aResponseAPDU ); |
|
544 std::wstring slotString = iSlotManager->GetSlotsL(); |
|
545 LOG(ESATSA, EInfo, "-- CSTSConnection::GetSlotsL"); |
|
546 return slotString; |
|
547 |
|
548 } |
|
549 |
|
550 void CSTSConnection::WrapSetURI(CSTSConnection* connection, CSTSURI* aURI) |
|
551 { |
|
552 LOG(ESATSA, EInfo, "+ CSTSConnection::WrapSetURI"); |
|
553 TInt connectionHandle = reinterpret_cast<TInt>(aURI); |
|
554 CallMethodL(connection, &CSTSConnection::SetURI, connectionHandle, |
|
555 connection); |
|
556 } |
|
557 // ----------------------------------------------------------------------------- |
|
558 // CSTSConnection::SetURIL |
|
559 // Sets URI member variable. Ownership transferred. |
|
560 // (other items were commented in a header). |
|
561 // ----------------------------------------------------------------------------- |
|
562 // |
|
563 void CSTSConnection::SetURI(TInt /* CSTSURI& */aURI) |
|
564 { |
|
565 LOG(ESATSA, EInfo, "+ CSTSConnection::SetURI"); |
|
566 CSTSURI* aUri = reinterpret_cast<CSTSURI *>(aURI); |
|
567 delete iURI; |
|
568 iURI = aUri; |
|
569 LOG(ESATSA, EInfo, "--CSTSConnection::SetURI"); |
|
570 } |
|
571 |
|
572 // ----------------------------------------------------------------------------- |
|
573 // CSTSConnection::CheckStateL |
|
574 // Leaves with correct leave code if state is not corret one |
|
575 // ----------------------------------------------------------------------------- |
|
576 // |
|
577 void CSTSConnection::CheckStateL(TBool aSATNotAllowed) |
|
578 { |
|
579 LOG(ESATSA, EInfo, "+ CSTSConnection::CheckStateL"); |
|
580 if (iURITarget == CSTSURI::ESAT && aSATNotAllowed) |
|
581 { |
|
582 ELOG(ESATSA, "+ CSTSConnection::CheckStateL:SAT not allowed"); |
|
583 User::Leave(KSTSErrSecurity); |
|
584 } |
|
585 |
|
586 //connection was closed before |
|
587 if (iState == EClosed) |
|
588 { |
|
589 User::Leave(KSTSErrIO + KSTSErrIOConnClosedBefore); |
|
590 } |
|
591 //card was removed |
|
592 else if (iState == ECardRemoved) |
|
593 { |
|
594 User::Leave(KSTSErrInterruptedIO + KSTSErrIICardRemoved); |
|
595 } |
|
596 //BT SAP was taken in use |
|
597 else if (iState == EBTSapInUse) |
|
598 { |
|
599 User::Leave(KSTSErrInterruptedIO + KSTSErrIIBTSapInUse); |
|
600 } |
|
601 LOG(ESATSA, EInfo, "-- CSTSConnection::CheckStateL"); |
|
602 } |
|
603 |
|
604 // ----------------------------------------------------------------------------- |
|
605 // CSTSConnection::NotifyClose |
|
606 // Resets apdumanager and pinmanager and saves state. |
|
607 // (other items were commented in a header). |
|
608 // ----------------------------------------------------------------------------- |
|
609 // |
|
610 void CSTSConnection::NotifyClose(TInt aReason) |
|
611 { |
|
612 LOG(ESATSA, EInfo, "+ CSTSConnection::NotifyClose"); |
|
613 iPinManager->CancelOperation(); |
|
614 iApduExchanger->CancelExchange(); |
|
615 |
|
616 //card was removed |
|
617 if (aReason == MSTSCloseObserver::ESTSCardNotAvailable) |
|
618 { |
|
619 iState = ECardRemoved; |
|
620 } |
|
621 //BT SAP was taken in use |
|
622 else |
|
623 { |
|
624 iState = EBTSapInUse; |
|
625 } |
|
626 } |
|
627 |
|
628 // ----------------------------------------------------------------------------- |
|
629 // CSTSConnection::DoSelectApplicationL |
|
630 // Opens channel and selects card application. If application selection fails |
|
631 // closes the channel and leaves with proper error code. |
|
632 // (other items were commented in a header). |
|
633 // ----------------------------------------------------------------------------- |
|
634 // |
|
635 void CSTSConnection::DoSelectApplicationL() |
|
636 { |
|
637 LOG(ESATSA, EInfo, "+ CSTSConnection::DoSelectApplicationL"); |
|
638 //in AID case we can try to open own channel |
|
639 LOG(ESATSA, EInfo, "CSTSConnection::DoSelectApplicationL: open own channel"); |
|
640 iApduExchanger->SetChannel(0); //basic channel |
|
641 LOG(ESATSA, EInfo, "CSTSConnection::DoSelectApplicationL: request channel"); |
|
642 iChannel = iChannelManager->RequestChannel(); |
|
643 |
|
644 // if there is no logical channel available, throw IOException |
|
645 if (iChannel < 0) |
|
646 { |
|
647 ELOG(ESATSA, "CSTSConnection::DoSelectApplicationL:no logical channel available, throw IOException "); |
|
648 User::Leave(KSTSErrIO + KSTSErrIONoFreeChannels); |
|
649 } |
|
650 |
|
651 iApduExchanger->SetChannel(iChannel); |
|
652 LOG(ESATSA, EInfo, "CSTSConnection::DoSelectApplicationL: going to select app "); |
|
653 TInt err = iCardAppManager->SelectApplication(); |
|
654 |
|
655 // if selection was not ok Close opened channel |
|
656 if (err != KErrNone) |
|
657 { |
|
658 ELOG(ESATSA, "CSTSConnection::DoSelectApplicationL: app selection was not ok Close opened channel"); |
|
659 // close channel error code not used because we will leave anyway |
|
660 iChannelManager->CloseChannel(iChannel); |
|
661 if (err == KErrNoMemory) |
|
662 { |
|
663 User::Leave(KErrNoMemory); |
|
664 } |
|
665 else |
|
666 { |
|
667 User::Leave(KSTSErrConnectionNotFound + KSTSErrCNTNoApplication); |
|
668 } |
|
669 } |
|
670 LOG(ESATSA, EInfo, "-- CSTSConnection::DoSelectApplicationL"); |
|
671 } |
|
672 |
|
673 void CSTSConnection::doServerSideInit() |
|
674 { |
|
675 |
|
676 FunctionServer::doServerSideInit(); |
|
677 |
|
678 } |
|
679 |
|
680 } // namespace satsa |
|
681 } // namespace java |
|
682 // End of File |