blob: 8d015a705f29e748dec5e333b8842d50a6d69c8a [file] [log] [blame]
nxpandroid64fd68c2015-09-23 16:45:15 +05301/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16/******************************************************************************
17 *
18 * The original Work has been changed by NXP Semiconductors.
19 *
20 * Copyright (C) 2015 NXP Semiconductors
21 *
22 * Licensed under the Apache License, Version 2.0 (the "License");
23 * you may not use this file except in compliance with the License.
24 * You may obtain a copy of the License at
25 *
26 * http://www.apache.org/licenses/LICENSE-2.0
27 *
28 * Unless required by applicable law or agreed to in writing, software
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
33 *
34 ******************************************************************************/
35/*
36 * Communicate with secure elements that are attached to the NFC
37 * controller.
38 */
39#pragma once
40#include "SyncEvent.h"
41#include "DataQueue.h"
42#include "NfcJniUtil.h"
43#include "RouteDataSet.h"
44#include "IntervalTimer.h"
45extern "C"
46{
47 #include "nfa_ee_api.h"
48 #include "nfa_hci_api.h"
49 #include "nfa_hci_defs.h"
50 #include "nfa_ce_api.h"
51 #include "phNxpExtns.h"
nxpandroida9a68ba2016-01-14 21:12:17 +053052#if((NFC_NXP_ESE == TRUE)&&(NXP_EXTNS == TRUE))
nxpandroid64fd68c2015-09-23 16:45:15 +053053 #include "phNfcTypes.h"
54#endif
55}
nxpandroida9a68ba2016-01-14 21:12:17 +053056#if((NFC_NXP_ESE == TRUE)&&(NXP_EXTNS == TRUE))
nxpandroid64fd68c2015-09-23 16:45:15 +053057#define SIG_NFC 44
58#endif
59typedef enum dual_mode{
60 SPI_DWPCL_NOT_ACTIVE = 0x00,
61 CL_ACTIVE = 0x01,
62 SPI_ON = 0x02,
63 SPI_DWPCL_BOTH_ACTIVE = 0x03,
64}dual_mode_state;
65
nxpandroida9a68ba2016-01-14 21:12:17 +053066typedef enum reset_management{
67 TRANS_IDLE = 0x00,
68 TRANS_WIRED_ONGOING = 0x01,
69 TRANS_CL_ONGOING = 0x02,
70 RESET_BLOCKED = 0x04,
71}ese_reset_control;
nxpandroid64fd68c2015-09-23 16:45:15 +053072typedef struct {
73 tNFA_HANDLE src;
74 tNFA_TECHNOLOGY_MASK tech_mask;
75 bool reCfg;
76}rd_swp_req_t;
77
78typedef enum
79{
80 STATE_SE_RDR_MODE_INVALID =0x00,
81 STATE_SE_RDR_MODE_START_CONFIG,
82 STATE_SE_RDR_MODE_START_IN_PROGRESS,
83 STATE_SE_RDR_MODE_STARTED,
84 STATE_SE_RDR_MODE_ACTIVATED,
85 STATE_SE_RDR_MODE_STOP_CONFIG,
86 STATE_SE_RDR_MODE_STOP_IN_PROGRESS,
87 STATE_SE_RDR_MODE_STOPPED,
88
89}se_rd_req_state_t;
90
nxpandroid34627bd2016-05-27 15:52:30 +053091#if((NXP_EXTNS == TRUE) && (NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH == TRUE))
92
93typedef enum
94{
95 UICC_01_SELECTED_ENABLED = 0x01,
96 UICC_01_SELECTED_DISABLED,
97 UICC_01_REMOVED,
98 UICC_02_SELECTED_ENABLED,
99 UICC_02_SELECTED_DISABLED,
100 UICC_02_REMOVED,
101 UICC_STATUS_UNKNOWN
102}uicc_stat_t;
103#endif
nxpandroid64fd68c2015-09-23 16:45:15 +0530104typedef enum
105{ STATE_SE_RDR_FAILURE_NOT_SUPPORTED ,
106 STATE_SE_RDR_FAILURE_NOT_ALLOWED
107
108}se_rd_req_failures_t;
109
nxpandroid7d44e572016-08-01 19:11:04 +0530110#if (NFC_NXP_ESE == TRUE && (NFC_NXP_CHIP_TYPE != PN547C2))
nxpandroid64fd68c2015-09-23 16:45:15 +0530111typedef struct{
112 rd_swp_req_t swp_rd_req_info ;
113 rd_swp_req_t swp_rd_req_current_info ;
114 se_rd_req_state_t swp_rd_state;
115 se_rd_req_failures_t swp_rd_req_fail_cause;
116 Mutex mMutex;
117}Rdr_req_ntf_info_t;
nxpandroid34627bd2016-05-27 15:52:30 +0530118#endif
nxpandroid64fd68c2015-09-23 16:45:15 +0530119
nxpandroida9a68ba2016-01-14 21:12:17 +0530120#if((NFC_NXP_ESE == TRUE)&&(NXP_EXTNS == TRUE))
121typedef enum operation{
122 STANDBY_TIMER_START,
123 STANDBY_TIMER_STOP,
124 STANDBY_TIMER_TIMEOUT,
125 STANDBY_GPIO_HIGH,
nxpandroid7d44e572016-08-01 19:11:04 +0530126 STANDBY_GPIO_LOW,
127 STANDBY_MODE_ON,
128 STANDBY_MODE_OFF
nxpandroida9a68ba2016-01-14 21:12:17 +0530129}nfcc_standby_operation_t;
nxpandroid64fd68c2015-09-23 16:45:15 +0530130void spi_prio_signal_handler (int signum, siginfo_t *info, void *unused);
131#endif
132
133namespace android {
134extern SyncEvent sNfaEnableDisablePollingEvent;
135extern void startStopPolling (bool isStartPolling);
136
137} // namespace android
138
139class SecureElement
140{
141public:
142 tNFA_HANDLE mActiveEeHandle;
nxpandroid1153eb32015-11-06 18:46:58 +0530143#if(NXP_EXTNS == TRUE)
nxpandroid64fd68c2015-09-23 16:45:15 +0530144#define MAX_NFCEE 5
145
146 struct mNfceeData{
147 tNFA_HANDLE mNfceeHandle[MAX_NFCEE];
148 tNFA_EE_STATUS mNfceeStatus[MAX_NFCEE];
149 UINT8 mNfceePresent;
150 };
151 mNfceeData mNfceeData_t;
nxpandroid7d44e572016-08-01 19:11:04 +0530152 UINT8 mHostsPresent;
153 UINT8 mHostsId[MAX_NFCEE];
nxpandroid64fd68c2015-09-23 16:45:15 +0530154#endif
155
nxpandroid7d44e572016-08-01 19:11:04 +0530156#if(NFC_NXP_ESE == TRUE && (NFC_NXP_CHIP_TYPE != PN547C2))
nxpandroid64fd68c2015-09-23 16:45:15 +0530157 IntervalTimer sSwpReaderTimer; // timer swp reader timeout.
158#endif
159
160 static const int MAX_NUM_EE = 5; //max number of EE's
161
162 /*******************************************************************************
163 **
164 ** Function: getInstance
165 **
166 ** Description: Get the SecureElement singleton object.
167 **
168 ** Returns: SecureElement object.
169 **
170 *******************************************************************************/
171 static SecureElement& getInstance ();
172
173
174 /*******************************************************************************
175 **
176 ** Function: initialize
177 **
178 ** Description: Initialize all member variables.
179 ** native: Native data.
180 **
181 ** Returns: True if ok.
182 **
183 *******************************************************************************/
184 bool initialize (nfc_jni_native_data* native);
185
186
187 /*******************************************************************************
188 **
189 ** Function: finalize
190 **
191 ** Description: Release all resources.
192 **
193 ** Returns: None
194 **
195 *******************************************************************************/
196 void finalize ();
197
198
199 /*******************************************************************************
200 **
201 ** Function: getListOfEeHandles
202 **
203 ** Description: Get the list of handles of all execution environments.
204 ** e: Java Virtual Machine.
205 **
206 ** Returns: List of handles of all execution environments.
207 **
208 *******************************************************************************/
209 jintArray getListOfEeHandles (JNIEnv* e);
210
211 /*******************************************************************************
212 **
213 ** Function: getActiveSecureElementList
214 **
215 ** Description: Get the list of handles of all execution environments.
216 ** e: Java Virtual Machine.
217 **
218 ** Returns: List of handles of all execution environments.
219 **
220 *******************************************************************************/
221 jintArray getActiveSecureElementList (JNIEnv* e);
222
223
224 /*******************************************************************************
225 **
226 ** Function: activate
227 **
228 ** Description: Turn on the secure element.
229 ** seID: ID of secure element.
230 **
231 ** Returns: True if ok.
232 **
233 *******************************************************************************/
234 bool activate (jint seID);
235
236
237 /*******************************************************************************
238 **
239 ** Function: deactivate
240 **
241 ** Description: Turn off the secure element.
242 ** seID: ID of secure element.
243 **
244 ** Returns: True if ok.
245 **
246 *******************************************************************************/
247 bool deactivate (jint seID);
248
249
250 /*******************************************************************************
251 **
252 ** Function: connectEE
253 **
254 ** Description: Connect to the execution environment.
255 **
256 ** Returns: True if ok.
257 **
258 *******************************************************************************/
259 bool connectEE ();
260
261
262 /*******************************************************************************
263 **
264 ** Function: disconnectEE
265 **
266 ** Description: Disconnect from the execution environment.
267 ** seID: ID of secure element.
268 **
269 ** Returns: True if ok.
270 **
271 *******************************************************************************/
272 bool disconnectEE (jint seID);
273
274
275 /*******************************************************************************
276 **
277 ** Function: transceive
278 **
279 ** Description: Send data to the secure element; read it's response.
280 ** xmitBuffer: Data to transmit.
281 ** xmitBufferSize: Length of data.
282 ** recvBuffer: Buffer to receive response.
283 ** recvBufferMaxSize: Maximum size of buffer.
284 ** recvBufferActualSize: Actual length of response.
285 ** timeoutMillisec: timeout in millisecond
286 **
287 ** Returns: True if ok.
288 **
289 *******************************************************************************/
290 bool transceive (UINT8* xmitBuffer, INT32 xmitBufferSize, UINT8* recvBuffer,
291 INT32 recvBufferMaxSize, INT32& recvBufferActualSize, INT32 timeoutMillisec);
292
293 void notifyModeSet (tNFA_HANDLE eeHandle, bool success, tNFA_EE_STATUS eeStatus);
294
295 /*******************************************************************************
296 **
297 ** Function: notifyListenModeState
298 **
299 ** Description: Notify the NFC service about whether the SE was activated
300 ** in listen mode.
301 ** isActive: Whether the secure element is activated.
302 **
303 ** Returns: None
304 **
305 *******************************************************************************/
306 void notifyListenModeState (bool isActivated);
307
308 /*******************************************************************************
309 **
310 ** Function: notifyRfFieldEvent
311 **
312 ** Description: Notify the NFC service about RF field events from the stack.
313 ** isActive: Whether any secure element is activated.
314 **
315 ** Returns: None
316 **
317 *******************************************************************************/
318 void notifyRfFieldEvent (bool isActive);
319
nxpandroid1153eb32015-11-06 18:46:58 +0530320#if(NXP_EXTNS == TRUE)
nxpandroid64fd68c2015-09-23 16:45:15 +0530321 /*******************************************************************************
322 **
323 ** Function: notifyEEReaderEvent
324 **
325 ** Description: Notify the NFC service about Reader over SWP events from the stack.
326 **
327 ** Returns: None
328 **
329 *******************************************************************************/
330 void notifyEEReaderEvent (int evt, int data);
331
332#endif
333
334 /*******************************************************************************
335 **
336 ** Function: resetRfFieldStatus ();
337 **
338 ** Description: Resets the field status.
339 **
340 ** Returns: None
341 **
342 *******************************************************************************/
343 void resetRfFieldStatus ();
344
345 /*******************************************************************************
346 **
347 ** Function: storeUiccInfo
348 **
349 ** Description: Store a copy of the execution environment information from the stack.
350 ** info: execution environment information.
351 **
352 ** Returns: None
353 **
354 *******************************************************************************/
355 void storeUiccInfo (tNFA_EE_DISCOVER_REQ& info);
356
357
358 /*******************************************************************************
359 **
360 ** Function: getUiccId
361 **
362 ** Description: Get the ID of the secure element.
363 ** eeHandle: Handle to the secure element.
364 ** uid: Array to receive the ID.
365 **
366 ** Returns: True if ok.
367 **
368 *******************************************************************************/
369 bool getUiccId (tNFA_HANDLE eeHandle, jbyteArray& uid);
370
371 /*******************************************************************************
372 **
373 ** Function: notifyTransactionListenersOfAid
374 **
375 ** Description: Notify the NFC service about a transaction event from secure element.
376 ** aid: Buffer contains application ID.
377 ** aidLen: Length of application ID.
378 **
379 ** Returns: None
380 **
381 *******************************************************************************/
382 void notifyTransactionListenersOfAid (const UINT8* aid, UINT8 aidLen, const UINT8* data, UINT32 dataLen,UINT32 evtSrc);
383
384 /*******************************************************************************
385 **
386 ** Function: notifyConnectivityListeners
387 **
388 ** Description: Notify the NFC service about a connectivity event from secure element.
389 ** evtSrc: source of event UICC/eSE.
390 **
391 ** Returns: None
392 **
393 *******************************************************************************/
394 void notifyConnectivityListeners (UINT8 evtSrc);
395
396 /*******************************************************************************
397 **
398 ** Function: notifyEmvcoMultiCardDetectedListeners
399 **
400 ** Description: Notify the NFC service about a multiple card presented to
401 ** Emvco reader.
402 **
403 ** Returns: None
404 **
405 *******************************************************************************/
406 void notifyEmvcoMultiCardDetectedListeners ();
407
408 /*******************************************************************************
409 **
410 ** Function: notifyTransactionListenersOfTlv
411 **
412 ** Description: Notify the NFC service about a transaction event from secure element.
413 ** The type-length-value contains AID and parameter.
414 ** tlv: type-length-value encoded in Basic Encoding Rule.
415 ** tlvLen: Length tlv.
416 **
417 ** Returns: None
418 **
419 *******************************************************************************/
420 void notifyTransactionListenersOfTlv (const UINT8* tlv, UINT8 tlvLen);
421
422
423 /*******************************************************************************
424 **
425 ** Function: connectionEventHandler
426 **
427 ** Description: Receive card-emulation related events from stack.
428 ** event: Event code.
429 ** eventData: Event data.
430 **
431 ** Returns: None
432 **
433 *******************************************************************************/
434 void connectionEventHandler (UINT8 event, tNFA_CONN_EVT_DATA* eventData);
435
436
437 /*******************************************************************************
438 **
439 ** Function: applyRoutes
440 **
441 ** Description: Read route data from XML and apply them again
442 ** to every secure element.
443 **
444 ** Returns: None
445 **
446 *******************************************************************************/
447 void applyRoutes ();
448
449
450 /*******************************************************************************
451 **
452 ** Function: setActiveSeOverride
453 **
454 ** Description: Specify which secure element to turn on.
455 ** activeSeOverride: ID of secure element
456 **
457 ** Returns: None
458 **
459 *******************************************************************************/
460 void setActiveSeOverride (UINT8 activeSeOverride);
461
462 bool SecEle_Modeset(UINT8 type);
463 /*******************************************************************************
464 **
465 ** Function: routeToSecureElement
466 **
467 ** Description: Adjust controller's listen-mode routing table so transactions
468 ** are routed to the secure elements as specified in route.xml.
469 **
470 ** Returns: True if ok.
471 **
472 *******************************************************************************/
473 bool routeToSecureElement ();
474
475
476 /*******************************************************************************
477 **
478 ** Function: isBusy
479 **
480 ** Description: Whether NFC controller is routing listen-mode events or a pipe is connected.
481 **
482 ** Returns: True if either case is true.
483 **
484 *******************************************************************************/
485 bool isBusy ();
486
487
488 /*******************************************************************************
489 **
490 ** Function getActualNumEe
491 **
492 ** Description Returns number of secure elements we know about.
493 **
494 ** Returns Number of secure elements we know about.
495 **
496 *******************************************************************************/
497 UINT8 getActualNumEe();
498
499
500 /*******************************************************************************
501 **
502 ** Function getSeVerInfo
503 **
504 ** Description Gets version information and id for a secure element. The
505 ** seIndex parmeter is the zero based index of the secure
506 ** element to get verion info for. The version infommation
507 ** is returned as a string int the verInfo parameter.
508 **
509 ** Returns ture on success, false on failure
510 **
511 *******************************************************************************/
512 bool getSeVerInfo(int seIndex, char * verInfo, int verInfoSz, UINT8 * seid);
513
514
515 /*******************************************************************************
516 **
517 ** Function: isActivatedInListenMode
518 **
519 ** Description: Can be used to determine if the SE is activated in listen mode
520 **
521 ** Returns: True if the SE is activated in listen mode
522 **
523 *******************************************************************************/
524 bool isActivatedInListenMode();
525
526 /*******************************************************************************
527 **
528 ** Function: isRfFieldOn
529 **
530 ** Description: Can be used to determine if the SE is in an RF field
531 **
532 ** Returns: True if the SE is activated in an RF field
533 **
534 *******************************************************************************/
535 bool isRfFieldOn();
536
537 /*******************************************************************************
538 **
539 ** Function: setEseListenTechMask
540 **
541 ** Description: Can be used to force ESE to only listen the specific
542 ** Technologies.
543 ** NFA_TECHNOLOGY_MASK_A 0x01
544 ** NFA_TECHNOLOGY_MASK_B 0x02
545 **
546 ** Returns: True if listening is configured.
547 **
548 *******************************************************************************/
549 bool setEseListenTechMask(UINT8 tech_mask);
550
551 bool sendEvent(UINT8 event);
552 /*******************************************************************************
553 **
554 ** Function: getAtr
555 **
556 ** Description: Can be used to get the ATR response from connected eSE
557 **
558 ** Returns: True if ATR response is returned successfully
559 **
560 *******************************************************************************/
561 bool getAtr(jint seID, UINT8* recvBuffer, INT32 *recvBufferSize);
nxpandroid34627bd2016-05-27 15:52:30 +0530562#if(NXP_EXTNS == TRUE)
nxpandroid7d44e572016-08-01 19:11:04 +0530563 bool getNfceeHostTypeList (void);
564 bool configureNfceeETSI12 (UINT8 host_id);
565
nxpandroid34627bd2016-05-27 15:52:30 +0530566 /**********************************************************************************
567 **
568 ** Function: getEeStatus
569 **
570 ** Description: get the status of EE
571 **
572 ** Returns: EE status .
573 **
574 **********************************************************************************/
575 UINT16 getEeStatus(UINT16 eehandle);
576#if(NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH == TRUE)
577 /**********************************************************************************
578 **
579 ** Function: getUiccStatus
580 **
581 ** Description: get the status of EE
582 **
583 ** Returns: EE status .
584 **
585 **********************************************************************************/
586 uicc_stat_t getUiccStatus(UINT8 selected_uicc);
587
588 /*******************************************************************************
589 **
590 ** Function: updateEEStatus
591 **
592 ** Description: updateEEStatus
593 ** Reads EE related information from libnfc
594 ** and updates in JNI
595 **
596 ** Returns: True if ok.
597 **
598 *******************************************************************************/
599 bool updateEEStatus ();
nxpandroid7d44e572016-08-01 19:11:04 +0530600
601 /*******************************************************************************
602 **
603 ** Function: isTeckInfoReceived
604 **
605 ** Description: isTeckInfoReceived
606 ** Checks if discovery_req_ntf received
607 ** for a given EE
608 **
609 ** Returns: True if ok.
610 **
611 *******************************************************************************/
612 bool isTeckInfoReceived (UINT16 eeHandle);
nxpandroid34627bd2016-05-27 15:52:30 +0530613#endif
614#endif
nxpandroid7d44e572016-08-01 19:11:04 +0530615#if(NFC_NXP_ESE == TRUE && (NFC_NXP_CHIP_TYPE != PN547C2))
nxpandroid64fd68c2015-09-23 16:45:15 +0530616 void etsiInitConfig();
617 tNFC_STATUS etsiReaderConfig(int eeHandle);
618 tNFC_STATUS etsiResetReaderConfig();
619#endif
nxpandroid7d44e572016-08-01 19:11:04 +0530620
621#if((NFC_NXP_ESE == TRUE)&&(CONCURRENCY_PROTECTION == TRUE))
622 /*******************************************************************************
623 **
624 ** Function: enablePassiveListen
625 **
626 ** Description: Enable or disable listening to Passive A/B
627 **
628 ** Returns: True if ok.
629 **
630 *******************************************************************************/
631 UINT16 enablePassiveListen (UINT8 event);
632
633 UINT16 startThread(UINT8 thread_arg);
634
635 bool mPassiveListenEnabled;
636 bool meseUiccConcurrentAccess;
637 IntervalTimer mPassiveListenTimer;
638#endif
nxpandroid64fd68c2015-09-23 16:45:15 +0530639 jint getSETechnology(tNFA_HANDLE eeHandle);
640 static const UINT8 UICC_ID = 0x02;
nxpandroid7d44e572016-08-01 19:11:04 +0530641 static const UINT8 UICC2_ID = 0x04;
nxpandroid64fd68c2015-09-23 16:45:15 +0530642 static const UINT8 ESE_ID = 0x01;
643 static const UINT8 DH_ID = 0x00;
644
645 void getEeHandleList(tNFA_HANDLE *list, UINT8* count);
646
647 tNFA_HANDLE getEseHandleFromGenericId(jint eseId);
648
649 jint getGenericEseId(tNFA_HANDLE handle);
nxpandroid7d44e572016-08-01 19:11:04 +0530650#if (JCOP_WA_ENABLE == TRUE)
nxpandroid64fd68c2015-09-23 16:45:15 +0530651 tNFA_STATUS reconfigureEseHciInit();
nxpandroid7d44e572016-08-01 19:11:04 +0530652#endif
nxpandroida9a68ba2016-01-14 21:12:17 +0530653#if((NFC_NXP_ESE == TRUE)&&(NXP_EXTNS == TRUE))
nxpandroid64fd68c2015-09-23 16:45:15 +0530654 void setCPTimeout();
nxpandroida9a68ba2016-01-14 21:12:17 +0530655 void NfccStandByOperation(nfcc_standby_operation_t value);
nxpandroid7d44e572016-08-01 19:11:04 +0530656 void eSE_ISO_Reset(void);
657 tNFA_STATUS SecElem_sendEvt_Abort();
nxpandroid64fd68c2015-09-23 16:45:15 +0530658#endif
nxpandroid7d44e572016-08-01 19:11:04 +0530659 bool checkForWiredModeAccess();
660 bool isEtsi12ApduGatePresent();
nxpandroid64fd68c2015-09-23 16:45:15 +0530661 bool mRecvdTransEvt;
662 bool mAllowWiredMode;
nxpandroid7d44e572016-08-01 19:11:04 +0530663 UINT8 mPassiveListenCnt; //Retry cnt for passive listen enable timer
nxpandroid64fd68c2015-09-23 16:45:15 +0530664 SyncEvent mRoutingEvent;
665 SyncEvent mAidAddRemoveEvent;
666 SyncEvent mUiccListenEvent;
667 SyncEvent mEseListenEvent;
nxpandroid64fd68c2015-09-23 16:45:15 +0530668 SyncEvent mAllowWiredModeEvent;
nxpandroida9a68ba2016-01-14 21:12:17 +0530669 SyncEvent mEeSetModeEvent;
nxpandroid7d44e572016-08-01 19:11:04 +0530670 UINT32 mPassiveListenTimeout; //Retry timout value for passive listen enable timer
671#if((NFC_NXP_ESE == TRUE)&&(CONCURRENCY_PROTECTION == TRUE))
672 SyncEvent mPassiveListenEvt;
673 Mutex mPassiveListenMutex;
674#endif
675#if ((NXP_EXTNS == TRUE) && (NXP_WIRED_MODE_STANDBY == TRUE))
676 SyncEvent mPwrLinkCtrlEvent;
677#endif
nxpandroid64fd68c2015-09-23 16:45:15 +0530678
nxpandroid1153eb32015-11-06 18:46:58 +0530679#if(NXP_EXTNS == TRUE)
nxpandroid7d44e572016-08-01 19:11:04 +0530680 SyncEvent mNfceeInitCbEvent;
nxpandroidc39a74c2016-01-18 16:46:10 +0530681 tNFA_STATUS SecElem_EeModeSet(uint16_t handle, uint8_t mode);
nxpandroid7d44e572016-08-01 19:11:04 +0530682#if (JCOP_WA_ENABLE == TRUE)
nxpandroida9a68ba2016-01-14 21:12:17 +0530683 SyncEvent mEEdatapacketEvent;
nxpandroid7d44e572016-08-01 19:11:04 +0530684#endif
nxpandroid34627bd2016-05-27 15:52:30 +0530685 SyncEvent mTransceiveEvent;
nxpandroid64fd68c2015-09-23 16:45:15 +0530686 static const UINT8 EVT_END_OF_APDU_TRANSFER = 0x21; //NXP Propritory
nxpandroid7d44e572016-08-01 19:11:04 +0530687#if (NXP_WIRED_MODE_STANDBY == TRUE)
688 static const UINT8 EVT_SUSPEND_APDU_TRANSFER = 0x31;
689#endif
690 tNFA_HANDLE mActiveCeHandle;
691 bool mIsWiredModeOpen;
692 bool mlistenDisabled;
693 bool mIsExclusiveWiredMode;
694 bool mIsActionNtfReceived;
695 bool mIsDesfireMifareDisable;
696 bool mIsAllowWiredInDesfireMifareCE;
697 static const UINT8 EVT_ABORT = 0x11; //ETSI12
nxpandroid64fd68c2015-09-23 16:45:15 +0530698 void setCLState(bool mState);
699#endif
700
701private:
702 static const unsigned int MAX_RESPONSE_SIZE = 0x8800;//1024; //34K
703 enum RouteSelection {NoRoute, DefaultRoute, SecElemRoute};
704#ifdef GEMATO_SE_SUPPORT
705 static const UINT8 STATIC_PIPE_0x70 = 0x19; //PN54X Gemalto's proprietary static pipe
706#else
707 static const UINT8 STATIC_PIPE_0x70 = 0x70; //Broadcom's proprietary static pipe
708#endif
709 static const UINT8 STATIC_PIPE_0x71 = 0x71; //Broadcom's proprietary static pipe
710 static const UINT8 EVT_SEND_DATA = 0x10; //see specification ETSI TS 102 622 v9.0.0 (Host Controller Interface); section 9.3.3.3
nxpandroid1153eb32015-11-06 18:46:58 +0530711#if(NXP_EXTNS == TRUE)
nxpandroid7d44e572016-08-01 19:11:04 +0530712 static const UINT8 STATIC_PIPE_UICC = 0x20; //UICC's proprietary static pipe
713#if (NXP_WIRED_MODE_STANDBY == TRUE)
714 static const UINT8 NFCC_DECIDES = 0x00; //NFCC decides
715 static const UINT8 POWER_ALWAYS_ON = 0x01; //NFCEE Power Supply always On
716 static const UINT8 COMM_LINK_ACTIVE = 0x02; //NFCC to NFCEE Communication link always active when the NFCEE is powered on.
717#endif
nxpandroid64fd68c2015-09-23 16:45:15 +0530718 static const tNFA_HANDLE EE_HANDLE_0xF3 = 0x4C0;//0x401; //handle to secure element in slot 0
nxpandroid7d44e572016-08-01 19:11:04 +0530719 static const tNFA_HANDLE EE_HANDLE_0xF8 = 0x481; //handle to secure element in slot 2
nxpandroid64fd68c2015-09-23 16:45:15 +0530720#ifdef NXP_UICC_ENABLE
721 static const tNFA_HANDLE EE_HANDLE_0xF4 = 0x402; //handle to secure element in slot 1
722#else
723 static const tNFA_HANDLE EE_HANDLE_0xF4 = 0x0F4;//0x4C0; //handle to secure element in slot 1
724#endif
725#else
nxpandroida9a68ba2016-01-14 21:12:17 +0530726 static const tNFA_HANDLE EE_HANDLE_0xF3 = 0x4F3; //handle to secure element in slot 0
nxpandroid64fd68c2015-09-23 16:45:15 +0530727 static const tNFA_HANDLE EE_HANDLE_0xF4 = 0x4F4; //handle to secure element in slot 1
728#endif
729
730 static SecureElement sSecElem;
731 static const char* APP_NAME;
732
733 UINT8 mDestinationGate; //destination gate of the UICC
734 tNFA_HANDLE mNfaHciHandle; //NFA handle to NFA's HCI component
735 nfc_jni_native_data* mNativeData;
736 bool mIsInit; // whether EE is initialized
737 UINT8 mActualNumEe; // actual number of EE's reported by the stack
738 UINT8 mNumEePresent; // actual number of usable EE's
739 bool mbNewEE;
740 UINT8 mNewPipeId;
741 UINT8 mNewSourceGate;
742 UINT16 mActiveSeOverride; // active "enable" seid, 0 means activate all SEs
743 tNFA_STATUS mCommandStatus; //completion status of the last command
744 bool mIsPiping; //is a pipe connected to the controller?
745 RouteSelection mCurrentRouteSelection;
746 int mActualResponseSize; //number of bytes in the response received from secure element
747 int mAtrInfolen;
748 UINT8 mAtrStatus;
749 bool mUseOberthurWarmReset; //whether to use warm-reset command
750 bool mActivatedInListenMode; // whether we're activated in listen mode
751 UINT8 mOberthurWarmResetCommand; //warm-reset command byte
752 tNFA_EE_INFO mEeInfo [MAX_NUM_EE]; //actual size stored in mActualNumEe
753 tNFA_EE_DISCOVER_REQ mUiccInfo;
754 tNFA_HCI_GET_GATE_PIPE_LIST mHciCfg;
755 SyncEvent mEeRegisterEvent;
756 SyncEvent mHciRegisterEvent;
nxpandroid7d44e572016-08-01 19:11:04 +0530757#if (JCOP_WA_ENABLE == TRUE)
nxpandroida9a68ba2016-01-14 21:12:17 +0530758 SyncEvent mResetEvent;
759 SyncEvent mResetOngoingEvent;
nxpandroid7d44e572016-08-01 19:11:04 +0530760#endif
nxpandroid64fd68c2015-09-23 16:45:15 +0530761 SyncEvent mPipeListEvent;
762 SyncEvent mCreatePipeEvent;
763 SyncEvent mPipeOpenedEvent;
764 SyncEvent mAllocateGateEvent;
765 SyncEvent mDeallocateGateEvent;
766// SyncEvent mRoutingEvent;
767 SyncEvent mUiccInfoEvent;
768// SyncEvent mAidAddRemoveEvent;
nxpandroid64fd68c2015-09-23 16:45:15 +0530769 SyncEvent mGetRegisterEvent;
770 SyncEvent mVerInfoEvent;
771 SyncEvent mRegistryEvent;
772 SyncEvent mDiscMapEvent;
773 UINT8 mVerInfo [3];
774 UINT8 mAtrInfo[40];
775 bool mGetAtrRspwait;
776 UINT8 mResponseData [MAX_RESPONSE_SIZE];
777 RouteDataSet mRouteDataSet; //routing data
778 std::vector<std::string> mUsedAids; //AID's that are used in current routes
779 UINT8 mAidForEmptySelect[NCI_MAX_AID_LEN+1];
780 Mutex mMutex; // protects fields below
781 bool mRfFieldIsOn; // last known RF field state
782 struct timespec mLastRfFieldToggle; // last time RF field went off
783 IntervalTimer mTransceiveTimer;
784 bool mTransceiveWaitOk;
785 int mWiredModeRfFiledEnable;
nxpandroid7d44e572016-08-01 19:11:04 +0530786#if(NXP_EXTNS == TRUE)
787 SyncEvent mAbortEvent;
788 bool mAbortEventWaitOk;
789#endif
nxpandroid64fd68c2015-09-23 16:45:15 +0530790 /*******************************************************************************
791 **
792 ** Function: SecureElement
793 **
794 ** Description: Initialize member variables.
795 **
796 ** Returns: None
797 **
798 *******************************************************************************/
799 SecureElement ();
800
801
802 /*******************************************************************************
803 **
804 ** Function: ~SecureElement
805 **
806 ** Description: Release all resources.
807 **
808 ** Returns: None
809 **
810 *******************************************************************************/
811 ~SecureElement ();
812
813
814 /*******************************************************************************
815 **
816 ** Function: nfaEeCallback
817 **
818 ** Description: Receive execution environment-related events from stack.
819 ** event: Event code.
820 ** eventData: Event data.
821 **
822 ** Returns: None
823 **
824 *******************************************************************************/
825 static void nfaEeCallback (tNFA_EE_EVT event, tNFA_EE_CBACK_DATA* eventData);
826
827
828 /*******************************************************************************
829 **
830 ** Function: nfaHciCallback
831 **
832 ** Description: Receive Host Controller Interface-related events from stack.
833 ** event: Event code.
834 ** eventData: Event data.
835 **
836 ** Returns: None
837 **
838 *******************************************************************************/
839 static void nfaHciCallback (tNFA_HCI_EVT event, tNFA_HCI_EVT_DATA* eventData);
840
841
842 /*******************************************************************************
843 **
844 ** Function: findEeByHandle
845 **
846 ** Description: Find information about an execution environment.
847 ** eeHandle: Handle to execution environment.
848 **
849 ** Returns: Information about an execution environment.
850 **
851 *******************************************************************************/
852 tNFA_EE_INFO *findEeByHandle (tNFA_HANDLE eeHandle);
853
854
855 /*******************************************************************************
856 **
857 ** Function: findUiccByHandle
858 **
859 ** Description: Find information about an execution environment.
860 ** eeHandle: Handle of the execution environment.
861 **
862 ** Returns: Information about the execution environment.
863 **
864 *******************************************************************************/
865 tNFA_EE_DISCOVER_INFO *findUiccByHandle (tNFA_HANDLE eeHandle);
866
867
868 /*******************************************************************************
869 **
870 ** Function: getDefaultEeHandle
871 **
872 ** Description: Get the handle to the execution environment.
873 **
874 ** Returns: Handle to the execution environment.
875 **
876 *******************************************************************************/
877 tNFA_HANDLE getDefaultEeHandle ();
878
879
nxpandroid7d44e572016-08-01 19:11:04 +0530880#if(NXP_EXTNS == TRUE)
881 /*******************************************************************************
882 **
883 ** Function: getActiveEeHandle
884 **
885 ** Description: Get the handle of the active execution environment.
886 **
887 ** Returns: Handle to the execution environment.
888 **
889 *******************************************************************************/
890 tNFA_HANDLE getActiveEeHandle (tNFA_HANDLE eeHandle);
891#endif
nxpandroid64fd68c2015-09-23 16:45:15 +0530892 /*******************************************************************************
893 **
894 ** Function: adjustRoutes
895 **
896 ** Description: Adjust routes in the controller's listen-mode routing table.
897 ** selection: which set of routes to configure the controller.
898 **
899 ** Returns: None
900 **
901 *******************************************************************************/
902 void adjustRoutes (RouteSelection selection);
903
904
905 /*******************************************************************************
906 **
907 ** Function: adjustProtocolRoutes
908 **
909 ** Description: Adjust default routing based on protocol in NFC listen mode.
910 ** isRouteToEe: Whether routing to EE (true) or host (false).
911 **
912 ** Returns: None
913 **
914 *******************************************************************************/
915 void adjustProtocolRoutes (RouteDataSet::Database* db, RouteSelection routeSelection);
916
917
918 /*******************************************************************************
919 **
920 ** Function: adjustTechnologyRoutes
921 **
922 ** Description: Adjust default routing based on technology in NFC listen mode.
923 ** isRouteToEe: Whether routing to EE (true) or host (false).
924 **
925 ** Returns: None
926 **
927 *******************************************************************************/
928 void adjustTechnologyRoutes (RouteDataSet::Database* db, RouteSelection routeSelection);
929
930
931 /*******************************************************************************
932 **
933 ** Function: getEeInfo
934 **
935 ** Description: Get latest information about execution environments from stack.
936 **
937 ** Returns: True if at least 1 EE is available.
938 **
939 *******************************************************************************/
940 bool getEeInfo ();
941
942 /*******************************************************************************
943 **
944 ** Function: eeStatusToString
945 **
946 ** Description: Convert status code to status text.
947 ** status: Status code
948 **
949 ** Returns: None
950 **
951 *******************************************************************************/
952 static const char* eeStatusToString (UINT8 status);
953
954
955 /*******************************************************************************
956 **
957 ** Function: encodeAid
958 **
959 ** Description: Encode AID in type-length-value using Basic Encoding Rule.
960 ** tlv: Buffer to store TLV.
961 ** tlvMaxLen: TLV buffer's maximum length.
962 ** tlvActualLen: TLV buffer's actual length.
963 ** aid: Buffer of Application ID.
964 ** aidLen: Aid buffer's actual length.
965 **
966 ** Returns: True if ok.
967 **
968 *******************************************************************************/
969 bool encodeAid (UINT8* tlv, UINT16 tlvMaxLen, UINT16& tlvActualLen, const UINT8* aid, UINT8 aidLen);
970
971 static int decodeBerTlvLength(UINT8* data,int index, int data_length );
972
973 static void discovery_map_cb (tNFC_DISCOVER_EVT event, tNFC_DISCOVER *p_data);
974
975
976};