|
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 |
|
19 #include <memory> |
|
20 #include <errno.h> |
|
21 #include <f32file.h> |
|
22 #include <gsmuset.h> |
|
23 #include <charconv.h> |
|
24 |
|
25 #include "logger.h" |
|
26 #include "s60commonutils.h" |
|
27 #include "jstringutils.h" |
|
28 |
|
29 #include "javacommonutils.h" |
|
30 #include "javaapduconnectionimpl.h" |
|
31 #include "com_nokia_mj_impl_satsa_APDUConnectionImpl.h" |
|
32 #include "cstsconnection.h" |
|
33 #include "cstsresphandler.h" |
|
34 #include "cstsmidletinfo.h" |
|
35 |
|
36 #include "javajniutils.h" |
|
37 #include "com_nokia_mj_impl_satsa_APDUConnectionImpl.h" |
|
38 #include "fs_methodcall.h" |
|
39 |
|
40 namespace java |
|
41 { |
|
42 namespace satsa |
|
43 { |
|
44 |
|
45 const TInt KConnTypeIndex = 1; |
|
46 |
|
47 JavaApduConnectionImpl::JavaApduConnectionImpl() |
|
48 { |
|
49 //Initialize any member to 0 or Null |
|
50 } |
|
51 |
|
52 JavaApduConnectionImpl::~JavaApduConnectionImpl() |
|
53 { |
|
54 LOG(ESATSA, EInfo, "+ JavaApduConnectionImpl::~JavaApduConnectionImpl"); |
|
55 //Release resource here (delete pointer) |
|
56 if (iConnection) |
|
57 { |
|
58 delete iConnection; |
|
59 iConnection = NULL; |
|
60 } |
|
61 if (mSlotConn) |
|
62 { |
|
63 delete mSlotConn; |
|
64 mSlotConn = NULL; |
|
65 } |
|
66 |
|
67 } |
|
68 |
|
69 JavaApduConnectionBase* JavaApduConnectionBase::getInstance() |
|
70 { |
|
71 LOG(ESATSA, EInfo, "+ JavaApduConnectionImpl::getInstance "); |
|
72 JavaApduConnectionImpl* mesgConn = new JavaApduConnectionImpl(); |
|
73 if (mesgConn == NULL) |
|
74 { |
|
75 throw ENOMEM; |
|
76 } |
|
77 LOG(ESATSA, EInfo, "-- JavaApduConnectionImpl::getInstance "); |
|
78 return mesgConn; |
|
79 } |
|
80 |
|
81 int JavaApduConnectionImpl::CreateSlot(JNIEnv& aJni, jobject aPeer) |
|
82 { |
|
83 LOG(ESATSA, EInfo, "+ Entering JavaApduConnectionImpl::CreateSlot"); |
|
84 TInt err = 0; |
|
85 TRAP(err, CreateSlotConn(aJni, aPeer)); |
|
86 return err; |
|
87 } |
|
88 |
|
89 void JavaApduConnectionImpl::CreateSlotConn(JNIEnv& aJni, jobject aPeer) |
|
90 { |
|
91 LOG(ESATSA, EInfo, "+ JavaApduConnectionImpl::CreateSlotConn"); |
|
92 CSTSRespHandler* respHandler = NULL; |
|
93 CSTSMidletInfo* midletInfo = NULL; |
|
94 // Create connection object |
|
95 mSlotConn = CSTSConnection::NewL(aJni, aPeer, respHandler, midletInfo); |
|
96 LOG(ESATSA, EInfo, "-- JavaApduConnectionImpl::CreateSlotConn"); |
|
97 } |
|
98 |
|
99 int JavaApduConnectionImpl::CreateConn(JNIEnv& aJni, jobject aPeer, |
|
100 jmethodID aHandleEventMethod, jstring aUri, jstring aName, |
|
101 jstring aVendor, jstring aVersion, jstring aDomain, |
|
102 jstring aRootCertHash, jstring aSigningCertHash, |
|
103 TInt* aReturnValueArray) |
|
104 { |
|
105 LOG(ESATSA, EInfo, "+ Entering JavaApduConnectionImpl::CreateConn"); |
|
106 TInt err = 0; |
|
107 TRAP(err, Create(aJni, aPeer, aHandleEventMethod, aUri, aName, aVendor, |
|
108 aVersion, aDomain, aRootCertHash, aSigningCertHash, |
|
109 aReturnValueArray)); |
|
110 LOG(ESATSA, EInfo, "-- leaving JavaApduConnectionImpl::CreateConn"); |
|
111 return err; |
|
112 |
|
113 } |
|
114 |
|
115 void JavaApduConnectionImpl::Create(JNIEnv& aJni, jobject aNotifyObject, |
|
116 jmethodID aHandleEventMethod, jstring aUri, jstring aName, |
|
117 jstring aVendor, jstring aVersion, jstring aDomain, |
|
118 jstring aRootCertHash, jstring aSigningCertHash, |
|
119 TInt* aReturnValueArray) |
|
120 { |
|
121 LOG(ESATSA, EInfo, "+ Entering JavaApduConnectionImpl::Create"); |
|
122 |
|
123 // Set the URI string contents to Symbian descriptor. |
|
124 JStringUtils aMUri(aJni, aUri); |
|
125 // Set the name string contents to Symbian descriptor. |
|
126 JStringUtils aMName(aJni, aName); |
|
127 // Set the vendor string contents to Symbian descriptor. |
|
128 JStringUtils aMVendor(aJni, aVendor); |
|
129 // Set the version string contents to Symbian descriptor. |
|
130 JStringUtils aMVersion(aJni, aVersion); |
|
131 // Set the version string contents to Symbian descriptor. |
|
132 JStringUtils aMDomain(aJni, aDomain); |
|
133 // Set the version string contents to Symbian descriptor. |
|
134 JStringUtils aMRootCert(aJni, aRootCertHash); |
|
135 // Set the version string contents to Symbian descriptor. |
|
136 JStringUtils aMSignCert(aJni, aSigningCertHash); |
|
137 |
|
138 LOG(ESATSA, EInfo, "Initializing the URI"); |
|
139 CSTSURI* uri = CSTSURI::NewLC(aMUri); |
|
140 |
|
141 LOG(ESATSA, EInfo, "After initializing the URI"); |
|
142 //set type of connection for java side |
|
143 if (uri->Type() == CSTSURI::EAID) |
|
144 { |
|
145 LOG(ESATSA, EInfo, "the URI is AID type"); |
|
146 aReturnValueArray[KConnTypeIndex] |
|
147 = com_nokia_mj_impl_satsa_APDUConnectionImpl_ENUMERATION_AID; |
|
148 } |
|
149 else |
|
150 { |
|
151 LOG(ESATSA, EInfo, "the URI is SAT type"); |
|
152 aReturnValueArray[KConnTypeIndex] |
|
153 = com_nokia_mj_impl_satsa_APDUConnectionImpl_ENUMERATION_SAT; |
|
154 } |
|
155 |
|
156 LOG(ESATSA, EInfo, "initialize CSTSMidletInfo"); |
|
157 CSTSMidletInfo* midletInfo = CSTSMidletInfo::NewL(aMName, aMVendor, |
|
158 aMVersion, aMDomain, aMRootCert, aMSignCert); |
|
159 |
|
160 LOG(ESATSA, EInfo, "After initializing CSTSMidletInfo.."); |
|
161 CleanupStack::PushL(midletInfo); |
|
162 |
|
163 LOG(ESATSA, EInfo, "midletInfo created"); |
|
164 CSTSRespHandler* respHandler = CSTSRespHandler::NewL(aJni, aNotifyObject, |
|
165 aHandleEventMethod); |
|
166 |
|
167 LOG(ESATSA, EInfo, "respHandler created"); |
|
168 |
|
169 // Connection object will own the midletInfo object |
|
170 CleanupStack::Pop(midletInfo); |
|
171 |
|
172 // Create connection object. RespHandler and midletinfo ownership |
|
173 // transferred |
|
174 iConnection = CSTSConnection::NewL(aJni, aNotifyObject, respHandler, |
|
175 midletInfo); |
|
176 |
|
177 // Connection object will own the uri object |
|
178 CleanupStack::Pop(uri); |
|
179 |
|
180 CSTSConnection::WrapSetURI(iConnection, uri); |
|
181 |
|
182 LOG(ESATSA, EInfo, "JavaApduConnectionImpl::Create::connection created"); |
|
183 LOG(ESATSA, EInfo, "-- leaiving JavaApduConnectionImpl::Create"); |
|
184 |
|
185 } |
|
186 |
|
187 int JavaApduConnectionImpl::DoPinMethod(JNIEnv& /*aJni*/, jclass /*aPeer*/, |
|
188 int /*aHandle*/, int aPinMethodType, int aPinID) |
|
189 { |
|
190 LOG(ESATSA, EInfo, "+ JavaApduConnectionImpl::DoPinMethod "); |
|
191 //CSTSConnection* connection = reinterpret_cast< CSTSConnection* >( aHandle ); |
|
192 int error = 0; |
|
193 TRAP(error, DoPinMethodL(iConnection, aPinMethodType, aPinID)); |
|
194 |
|
195 LOG(ESATSA, EInfo, "-- JavaApduConnectionImpl::DoPinMethod "); |
|
196 return error; |
|
197 |
|
198 } |
|
199 |
|
200 void JavaApduConnectionImpl::DoPinMethodL(CSTSConnection* aConnection, |
|
201 TInt aPinMethodType, TInt aPinID) |
|
202 { |
|
203 LOG(ESATSA, EInfo, "+ JavaApduConnectionImpl::DoPinMethodL "); |
|
204 switch (aPinMethodType) |
|
205 { |
|
206 case com_nokia_mj_impl_satsa_APDUConnectionImpl_ENUMERATION_CHANGE_PIN: |
|
207 { |
|
208 CSTSConnection::WrapChangePinL(aConnection, aPinID); |
|
209 break; |
|
210 } |
|
211 case com_nokia_mj_impl_satsa_APDUConnectionImpl_ENUMERATION_DISABLE_PIN: |
|
212 { |
|
213 CSTSConnection::WrapDisablePinL(aConnection, aPinID); |
|
214 break; |
|
215 } |
|
216 case com_nokia_mj_impl_satsa_APDUConnectionImpl_ENUMERATION_ENABLE_PIN: |
|
217 { |
|
218 CSTSConnection::WrapEnablePinL(aConnection, aPinID); |
|
219 break; |
|
220 } |
|
221 case com_nokia_mj_impl_satsa_APDUConnectionImpl_ENUMERATION_ENTER_PIN: |
|
222 { |
|
223 CSTSConnection::WrapEnterPinL(aConnection, aPinID); |
|
224 break; |
|
225 } |
|
226 default: |
|
227 { |
|
228 ELOG(EWMA, "JavaApduConnectionImpl::DoPinMethodL: parameter error"); |
|
229 |
|
230 break; |
|
231 } |
|
232 } |
|
233 LOG(ESATSA, EInfo, "-- JavaApduConnectionImpl::DoPinMethodL "); |
|
234 } |
|
235 |
|
236 int JavaApduConnectionImpl::ExchangeAPDU(JNIEnv& aJni, jclass /*aPeer*/, |
|
237 int /*aHandle*/, jbyteArray aCommandAPDU) |
|
238 { |
|
239 LOG(ESATSA, EInfo, "+ JavaApduConnectionImpl::ExchangeAPDU "); |
|
240 TInt err = KErrNone; |
|
241 // Convert the command bytes into an 8-bit descriptor... |
|
242 jbyte* byteArray = (aJni).GetByteArrayElements(aCommandAPDU, NULL); |
|
243 TInt numComBytes = (aJni).GetArrayLength(aCommandAPDU); |
|
244 TPtrC8 commandDes(reinterpret_cast<TUint8*>(byteArray), numComBytes); |
|
245 |
|
246 TRAP(err, CSTSConnection::WrapExchangeAPDUL(iConnection, commandDes)); |
|
247 LOG(ESATSA, EInfo, "-- JavaApduConnectionImpl::ExchangeAPDU "); |
|
248 return err; |
|
249 |
|
250 } |
|
251 |
|
252 int JavaApduConnectionImpl::UnblockPin(JNIEnv& /*aJni*/, jclass /*aPeer*/, |
|
253 int /*aHandle*/, int aBlockedPinID, int aUnblockingPinID) |
|
254 { |
|
255 LOG(ESATSA, EInfo, "+ JavaApduConnectionImpl::UnblockPin "); |
|
256 TInt err = KErrNone; |
|
257 TRAP(err, CSTSConnection::WrapUnblockPinL(iConnection, aBlockedPinID, |
|
258 aUnblockingPinID)); |
|
259 LOG(ESATSA, EInfo, "-- JavaApduConnectionImpl::UnblockPin "); |
|
260 //return error code to caller |
|
261 return err; |
|
262 } |
|
263 |
|
264 std::wstring JavaApduConnectionImpl::GetATR() |
|
265 { |
|
266 LOG(ESATSA, EInfo, "+ JavaApduConnectionImpl::GetATR "); |
|
267 std::wstring aATR; |
|
268 TRAPD(err, aATR = CSTSConnection::WrapGetATRL(iConnection)); |
|
269 if (err != KErrNone) |
|
270 { |
|
271 return std::wstring(L""); |
|
272 } |
|
273 LOG(ESATSA, EInfo, "-- JavaApduConnectionImpl::GetATR "); |
|
274 return aATR; |
|
275 } |
|
276 |
|
277 int JavaApduConnectionImpl::Open(JNIEnv& /*aJni*/, jclass /*aPeer*/, int /*aHandle*/) |
|
278 { |
|
279 LOG(ESATSA, EInfo, "+ JavaApduConnectionImpl::Open "); |
|
280 TInt err = KErrNone; |
|
281 TRAP(err,CSTSConnection::WrapOpenL(iConnection)); |
|
282 LOG(ESATSA, EInfo, "-- JavaApduConnectionImpl::Open "); |
|
283 //return error code to caller |
|
284 return err; |
|
285 } |
|
286 |
|
287 std::wstring JavaApduConnectionImpl::GetSlot() |
|
288 { |
|
289 LOG(ESATSA, EInfo, "+ JavaApduConnectionImpl::GetSLot "); |
|
290 std::wstring slotInfo(L""); |
|
291 TInt err = KErrNone; |
|
292 TRAP(err, slotInfo = CSTSConnection::WrapGetSlotsL(mSlotConn)); |
|
293 LOG(ESATSA, EInfo, "-- JavaApduConnectionImpl::GetSlot"); |
|
294 if (KErrNone != err) |
|
295 { |
|
296 slotInfo = L""; |
|
297 } |
|
298 //return error code to caller |
|
299 return slotInfo; |
|
300 } |
|
301 |
|
302 int JavaApduConnectionImpl::Close(JNIEnv& /*aJni*/, jclass /*aPeer*/, int /*aHandle*/) |
|
303 { |
|
304 LOG(ESATSA, EInfo, "+ JavaApduConnectionImpl::Close "); |
|
305 TInt err = KErrNone; |
|
306 TRAP(err,CSTSConnection::WrapCloseL(iConnection)); |
|
307 |
|
308 LOG(ESATSA, EInfo, "-- JavaApduConnectionImpl::Close "); |
|
309 //return error code to caller |
|
310 return err; |
|
311 } |
|
312 |
|
313 } // namespace satsa |
|
314 } // namespace java |
|
315 |
|
316 |