nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1 | /* |
| 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" |
| 45 | extern "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" |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 52 | #if((NFC_NXP_ESE == TRUE)&&(NXP_EXTNS == TRUE)) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 53 | #include "phNfcTypes.h" |
| 54 | #endif |
| 55 | } |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 56 | #if((NFC_NXP_ESE == TRUE)&&(NXP_EXTNS == TRUE)) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 57 | #define SIG_NFC 44 |
| 58 | #endif |
| 59 | typedef 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 | |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 66 | typedef 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; |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 72 | typedef struct { |
| 73 | tNFA_HANDLE src; |
| 74 | tNFA_TECHNOLOGY_MASK tech_mask; |
| 75 | bool reCfg; |
| 76 | }rd_swp_req_t; |
| 77 | |
| 78 | typedef 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 | |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 91 | #if((NXP_EXTNS == TRUE) && (NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH == TRUE)) |
| 92 | |
| 93 | typedef 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 |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 104 | typedef enum |
| 105 | { STATE_SE_RDR_FAILURE_NOT_SUPPORTED , |
| 106 | STATE_SE_RDR_FAILURE_NOT_ALLOWED |
| 107 | |
| 108 | }se_rd_req_failures_t; |
| 109 | |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 110 | #if (NFC_NXP_ESE == TRUE && ((NFC_NXP_CHIP_TYPE == PN548C2) || (NFC_NXP_CHIP_TYPE == PN551))) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 111 | typedef 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; |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 118 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 119 | |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 120 | #if((NFC_NXP_ESE == TRUE)&&(NXP_EXTNS == TRUE)) |
| 121 | typedef enum operation{ |
| 122 | STANDBY_TIMER_START, |
| 123 | STANDBY_TIMER_STOP, |
| 124 | STANDBY_TIMER_TIMEOUT, |
| 125 | STANDBY_GPIO_HIGH, |
| 126 | STANDBY_GPIO_LOW |
| 127 | }nfcc_standby_operation_t; |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 128 | void spi_prio_signal_handler (int signum, siginfo_t *info, void *unused); |
| 129 | #endif |
| 130 | |
| 131 | namespace android { |
| 132 | extern SyncEvent sNfaEnableDisablePollingEvent; |
| 133 | extern void startStopPolling (bool isStartPolling); |
| 134 | |
| 135 | } // namespace android |
| 136 | |
| 137 | class SecureElement |
| 138 | { |
| 139 | public: |
| 140 | tNFA_HANDLE mActiveEeHandle; |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 141 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 142 | #define MAX_NFCEE 5 |
| 143 | |
| 144 | struct mNfceeData{ |
| 145 | tNFA_HANDLE mNfceeHandle[MAX_NFCEE]; |
| 146 | tNFA_EE_STATUS mNfceeStatus[MAX_NFCEE]; |
| 147 | UINT8 mNfceePresent; |
| 148 | }; |
| 149 | mNfceeData mNfceeData_t; |
| 150 | #endif |
| 151 | |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 152 | #if(NFC_NXP_ESE == TRUE && ((NFC_NXP_CHIP_TYPE == PN548C2) || (NFC_NXP_CHIP_TYPE == PN551))) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 153 | IntervalTimer sSwpReaderTimer; // timer swp reader timeout. |
| 154 | #endif |
| 155 | |
| 156 | static const int MAX_NUM_EE = 5; //max number of EE's |
| 157 | |
| 158 | /******************************************************************************* |
| 159 | ** |
| 160 | ** Function: getInstance |
| 161 | ** |
| 162 | ** Description: Get the SecureElement singleton object. |
| 163 | ** |
| 164 | ** Returns: SecureElement object. |
| 165 | ** |
| 166 | *******************************************************************************/ |
| 167 | static SecureElement& getInstance (); |
| 168 | |
| 169 | |
| 170 | /******************************************************************************* |
| 171 | ** |
| 172 | ** Function: initialize |
| 173 | ** |
| 174 | ** Description: Initialize all member variables. |
| 175 | ** native: Native data. |
| 176 | ** |
| 177 | ** Returns: True if ok. |
| 178 | ** |
| 179 | *******************************************************************************/ |
| 180 | bool initialize (nfc_jni_native_data* native); |
| 181 | |
| 182 | |
| 183 | /******************************************************************************* |
| 184 | ** |
| 185 | ** Function: finalize |
| 186 | ** |
| 187 | ** Description: Release all resources. |
| 188 | ** |
| 189 | ** Returns: None |
| 190 | ** |
| 191 | *******************************************************************************/ |
| 192 | void finalize (); |
| 193 | |
| 194 | |
| 195 | /******************************************************************************* |
| 196 | ** |
| 197 | ** Function: getListOfEeHandles |
| 198 | ** |
| 199 | ** Description: Get the list of handles of all execution environments. |
| 200 | ** e: Java Virtual Machine. |
| 201 | ** |
| 202 | ** Returns: List of handles of all execution environments. |
| 203 | ** |
| 204 | *******************************************************************************/ |
| 205 | jintArray getListOfEeHandles (JNIEnv* e); |
| 206 | |
| 207 | /******************************************************************************* |
| 208 | ** |
| 209 | ** Function: getActiveSecureElementList |
| 210 | ** |
| 211 | ** Description: Get the list of handles of all execution environments. |
| 212 | ** e: Java Virtual Machine. |
| 213 | ** |
| 214 | ** Returns: List of handles of all execution environments. |
| 215 | ** |
| 216 | *******************************************************************************/ |
| 217 | jintArray getActiveSecureElementList (JNIEnv* e); |
| 218 | |
| 219 | |
| 220 | /******************************************************************************* |
| 221 | ** |
| 222 | ** Function: activate |
| 223 | ** |
| 224 | ** Description: Turn on the secure element. |
| 225 | ** seID: ID of secure element. |
| 226 | ** |
| 227 | ** Returns: True if ok. |
| 228 | ** |
| 229 | *******************************************************************************/ |
| 230 | bool activate (jint seID); |
| 231 | |
| 232 | |
| 233 | /******************************************************************************* |
| 234 | ** |
| 235 | ** Function: deactivate |
| 236 | ** |
| 237 | ** Description: Turn off the secure element. |
| 238 | ** seID: ID of secure element. |
| 239 | ** |
| 240 | ** Returns: True if ok. |
| 241 | ** |
| 242 | *******************************************************************************/ |
| 243 | bool deactivate (jint seID); |
| 244 | |
| 245 | |
| 246 | /******************************************************************************* |
| 247 | ** |
| 248 | ** Function: connectEE |
| 249 | ** |
| 250 | ** Description: Connect to the execution environment. |
| 251 | ** |
| 252 | ** Returns: True if ok. |
| 253 | ** |
| 254 | *******************************************************************************/ |
| 255 | bool connectEE (); |
| 256 | |
| 257 | |
| 258 | /******************************************************************************* |
| 259 | ** |
| 260 | ** Function: disconnectEE |
| 261 | ** |
| 262 | ** Description: Disconnect from the execution environment. |
| 263 | ** seID: ID of secure element. |
| 264 | ** |
| 265 | ** Returns: True if ok. |
| 266 | ** |
| 267 | *******************************************************************************/ |
| 268 | bool disconnectEE (jint seID); |
| 269 | |
| 270 | |
| 271 | /******************************************************************************* |
| 272 | ** |
| 273 | ** Function: transceive |
| 274 | ** |
| 275 | ** Description: Send data to the secure element; read it's response. |
| 276 | ** xmitBuffer: Data to transmit. |
| 277 | ** xmitBufferSize: Length of data. |
| 278 | ** recvBuffer: Buffer to receive response. |
| 279 | ** recvBufferMaxSize: Maximum size of buffer. |
| 280 | ** recvBufferActualSize: Actual length of response. |
| 281 | ** timeoutMillisec: timeout in millisecond |
| 282 | ** |
| 283 | ** Returns: True if ok. |
| 284 | ** |
| 285 | *******************************************************************************/ |
| 286 | bool transceive (UINT8* xmitBuffer, INT32 xmitBufferSize, UINT8* recvBuffer, |
| 287 | INT32 recvBufferMaxSize, INT32& recvBufferActualSize, INT32 timeoutMillisec); |
| 288 | |
| 289 | void notifyModeSet (tNFA_HANDLE eeHandle, bool success, tNFA_EE_STATUS eeStatus); |
| 290 | |
| 291 | /******************************************************************************* |
| 292 | ** |
| 293 | ** Function: notifyListenModeState |
| 294 | ** |
| 295 | ** Description: Notify the NFC service about whether the SE was activated |
| 296 | ** in listen mode. |
| 297 | ** isActive: Whether the secure element is activated. |
| 298 | ** |
| 299 | ** Returns: None |
| 300 | ** |
| 301 | *******************************************************************************/ |
| 302 | void notifyListenModeState (bool isActivated); |
| 303 | |
| 304 | /******************************************************************************* |
| 305 | ** |
| 306 | ** Function: notifyRfFieldEvent |
| 307 | ** |
| 308 | ** Description: Notify the NFC service about RF field events from the stack. |
| 309 | ** isActive: Whether any secure element is activated. |
| 310 | ** |
| 311 | ** Returns: None |
| 312 | ** |
| 313 | *******************************************************************************/ |
| 314 | void notifyRfFieldEvent (bool isActive); |
| 315 | |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 316 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 317 | /******************************************************************************* |
| 318 | ** |
| 319 | ** Function: notifyEEReaderEvent |
| 320 | ** |
| 321 | ** Description: Notify the NFC service about Reader over SWP events from the stack. |
| 322 | ** |
| 323 | ** Returns: None |
| 324 | ** |
| 325 | *******************************************************************************/ |
| 326 | void notifyEEReaderEvent (int evt, int data); |
| 327 | |
| 328 | #endif |
| 329 | |
| 330 | /******************************************************************************* |
| 331 | ** |
| 332 | ** Function: resetRfFieldStatus (); |
| 333 | ** |
| 334 | ** Description: Resets the field status. |
| 335 | ** |
| 336 | ** Returns: None |
| 337 | ** |
| 338 | *******************************************************************************/ |
| 339 | void resetRfFieldStatus (); |
| 340 | |
| 341 | /******************************************************************************* |
| 342 | ** |
| 343 | ** Function: storeUiccInfo |
| 344 | ** |
| 345 | ** Description: Store a copy of the execution environment information from the stack. |
| 346 | ** info: execution environment information. |
| 347 | ** |
| 348 | ** Returns: None |
| 349 | ** |
| 350 | *******************************************************************************/ |
| 351 | void storeUiccInfo (tNFA_EE_DISCOVER_REQ& info); |
| 352 | |
| 353 | |
| 354 | /******************************************************************************* |
| 355 | ** |
| 356 | ** Function: getUiccId |
| 357 | ** |
| 358 | ** Description: Get the ID of the secure element. |
| 359 | ** eeHandle: Handle to the secure element. |
| 360 | ** uid: Array to receive the ID. |
| 361 | ** |
| 362 | ** Returns: True if ok. |
| 363 | ** |
| 364 | *******************************************************************************/ |
| 365 | bool getUiccId (tNFA_HANDLE eeHandle, jbyteArray& uid); |
| 366 | |
| 367 | /******************************************************************************* |
| 368 | ** |
| 369 | ** Function: notifyTransactionListenersOfAid |
| 370 | ** |
| 371 | ** Description: Notify the NFC service about a transaction event from secure element. |
| 372 | ** aid: Buffer contains application ID. |
| 373 | ** aidLen: Length of application ID. |
| 374 | ** |
| 375 | ** Returns: None |
| 376 | ** |
| 377 | *******************************************************************************/ |
| 378 | void notifyTransactionListenersOfAid (const UINT8* aid, UINT8 aidLen, const UINT8* data, UINT32 dataLen,UINT32 evtSrc); |
| 379 | |
| 380 | /******************************************************************************* |
| 381 | ** |
| 382 | ** Function: notifyConnectivityListeners |
| 383 | ** |
| 384 | ** Description: Notify the NFC service about a connectivity event from secure element. |
| 385 | ** evtSrc: source of event UICC/eSE. |
| 386 | ** |
| 387 | ** Returns: None |
| 388 | ** |
| 389 | *******************************************************************************/ |
| 390 | void notifyConnectivityListeners (UINT8 evtSrc); |
| 391 | |
| 392 | /******************************************************************************* |
| 393 | ** |
| 394 | ** Function: notifyEmvcoMultiCardDetectedListeners |
| 395 | ** |
| 396 | ** Description: Notify the NFC service about a multiple card presented to |
| 397 | ** Emvco reader. |
| 398 | ** |
| 399 | ** Returns: None |
| 400 | ** |
| 401 | *******************************************************************************/ |
| 402 | void notifyEmvcoMultiCardDetectedListeners (); |
| 403 | |
| 404 | /******************************************************************************* |
| 405 | ** |
| 406 | ** Function: notifyTransactionListenersOfTlv |
| 407 | ** |
| 408 | ** Description: Notify the NFC service about a transaction event from secure element. |
| 409 | ** The type-length-value contains AID and parameter. |
| 410 | ** tlv: type-length-value encoded in Basic Encoding Rule. |
| 411 | ** tlvLen: Length tlv. |
| 412 | ** |
| 413 | ** Returns: None |
| 414 | ** |
| 415 | *******************************************************************************/ |
| 416 | void notifyTransactionListenersOfTlv (const UINT8* tlv, UINT8 tlvLen); |
| 417 | |
| 418 | |
| 419 | /******************************************************************************* |
| 420 | ** |
| 421 | ** Function: connectionEventHandler |
| 422 | ** |
| 423 | ** Description: Receive card-emulation related events from stack. |
| 424 | ** event: Event code. |
| 425 | ** eventData: Event data. |
| 426 | ** |
| 427 | ** Returns: None |
| 428 | ** |
| 429 | *******************************************************************************/ |
| 430 | void connectionEventHandler (UINT8 event, tNFA_CONN_EVT_DATA* eventData); |
| 431 | |
| 432 | |
| 433 | /******************************************************************************* |
| 434 | ** |
| 435 | ** Function: applyRoutes |
| 436 | ** |
| 437 | ** Description: Read route data from XML and apply them again |
| 438 | ** to every secure element. |
| 439 | ** |
| 440 | ** Returns: None |
| 441 | ** |
| 442 | *******************************************************************************/ |
| 443 | void applyRoutes (); |
| 444 | |
| 445 | |
| 446 | /******************************************************************************* |
| 447 | ** |
| 448 | ** Function: setActiveSeOverride |
| 449 | ** |
| 450 | ** Description: Specify which secure element to turn on. |
| 451 | ** activeSeOverride: ID of secure element |
| 452 | ** |
| 453 | ** Returns: None |
| 454 | ** |
| 455 | *******************************************************************************/ |
| 456 | void setActiveSeOverride (UINT8 activeSeOverride); |
| 457 | |
| 458 | bool SecEle_Modeset(UINT8 type); |
| 459 | /******************************************************************************* |
| 460 | ** |
| 461 | ** Function: routeToSecureElement |
| 462 | ** |
| 463 | ** Description: Adjust controller's listen-mode routing table so transactions |
| 464 | ** are routed to the secure elements as specified in route.xml. |
| 465 | ** |
| 466 | ** Returns: True if ok. |
| 467 | ** |
| 468 | *******************************************************************************/ |
| 469 | bool routeToSecureElement (); |
| 470 | |
| 471 | |
| 472 | /******************************************************************************* |
| 473 | ** |
| 474 | ** Function: isBusy |
| 475 | ** |
| 476 | ** Description: Whether NFC controller is routing listen-mode events or a pipe is connected. |
| 477 | ** |
| 478 | ** Returns: True if either case is true. |
| 479 | ** |
| 480 | *******************************************************************************/ |
| 481 | bool isBusy (); |
| 482 | |
| 483 | |
| 484 | /******************************************************************************* |
| 485 | ** |
| 486 | ** Function getActualNumEe |
| 487 | ** |
| 488 | ** Description Returns number of secure elements we know about. |
| 489 | ** |
| 490 | ** Returns Number of secure elements we know about. |
| 491 | ** |
| 492 | *******************************************************************************/ |
| 493 | UINT8 getActualNumEe(); |
| 494 | |
| 495 | |
| 496 | /******************************************************************************* |
| 497 | ** |
| 498 | ** Function getSeVerInfo |
| 499 | ** |
| 500 | ** Description Gets version information and id for a secure element. The |
| 501 | ** seIndex parmeter is the zero based index of the secure |
| 502 | ** element to get verion info for. The version infommation |
| 503 | ** is returned as a string int the verInfo parameter. |
| 504 | ** |
| 505 | ** Returns ture on success, false on failure |
| 506 | ** |
| 507 | *******************************************************************************/ |
| 508 | bool getSeVerInfo(int seIndex, char * verInfo, int verInfoSz, UINT8 * seid); |
| 509 | |
| 510 | |
| 511 | /******************************************************************************* |
| 512 | ** |
| 513 | ** Function: isActivatedInListenMode |
| 514 | ** |
| 515 | ** Description: Can be used to determine if the SE is activated in listen mode |
| 516 | ** |
| 517 | ** Returns: True if the SE is activated in listen mode |
| 518 | ** |
| 519 | *******************************************************************************/ |
| 520 | bool isActivatedInListenMode(); |
| 521 | |
| 522 | /******************************************************************************* |
| 523 | ** |
| 524 | ** Function: isRfFieldOn |
| 525 | ** |
| 526 | ** Description: Can be used to determine if the SE is in an RF field |
| 527 | ** |
| 528 | ** Returns: True if the SE is activated in an RF field |
| 529 | ** |
| 530 | *******************************************************************************/ |
| 531 | bool isRfFieldOn(); |
| 532 | |
| 533 | /******************************************************************************* |
| 534 | ** |
| 535 | ** Function: setEseListenTechMask |
| 536 | ** |
| 537 | ** Description: Can be used to force ESE to only listen the specific |
| 538 | ** Technologies. |
| 539 | ** NFA_TECHNOLOGY_MASK_A 0x01 |
| 540 | ** NFA_TECHNOLOGY_MASK_B 0x02 |
| 541 | ** |
| 542 | ** Returns: True if listening is configured. |
| 543 | ** |
| 544 | *******************************************************************************/ |
| 545 | bool setEseListenTechMask(UINT8 tech_mask); |
| 546 | |
| 547 | bool sendEvent(UINT8 event); |
| 548 | /******************************************************************************* |
| 549 | ** |
| 550 | ** Function: getAtr |
| 551 | ** |
| 552 | ** Description: Can be used to get the ATR response from connected eSE |
| 553 | ** |
| 554 | ** Returns: True if ATR response is returned successfully |
| 555 | ** |
| 556 | *******************************************************************************/ |
| 557 | bool getAtr(jint seID, UINT8* recvBuffer, INT32 *recvBufferSize); |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 558 | #if(NXP_EXTNS == TRUE) |
| 559 | /********************************************************************************** |
| 560 | ** |
| 561 | ** Function: getEeStatus |
| 562 | ** |
| 563 | ** Description: get the status of EE |
| 564 | ** |
| 565 | ** Returns: EE status . |
| 566 | ** |
| 567 | **********************************************************************************/ |
| 568 | UINT16 getEeStatus(UINT16 eehandle); |
| 569 | #if(NFC_NXP_STAT_DUAL_UICC_EXT_SWITCH == TRUE) |
| 570 | /********************************************************************************** |
| 571 | ** |
| 572 | ** Function: getUiccStatus |
| 573 | ** |
| 574 | ** Description: get the status of EE |
| 575 | ** |
| 576 | ** Returns: EE status . |
| 577 | ** |
| 578 | **********************************************************************************/ |
| 579 | uicc_stat_t getUiccStatus(UINT8 selected_uicc); |
| 580 | |
| 581 | /******************************************************************************* |
| 582 | ** |
| 583 | ** Function: updateEEStatus |
| 584 | ** |
| 585 | ** Description: updateEEStatus |
| 586 | ** Reads EE related information from libnfc |
| 587 | ** and updates in JNI |
| 588 | ** |
| 589 | ** Returns: True if ok. |
| 590 | ** |
| 591 | *******************************************************************************/ |
| 592 | bool updateEEStatus (); |
| 593 | #endif |
| 594 | #endif |
| 595 | #if(NFC_NXP_ESE == TRUE && ((NFC_NXP_CHIP_TYPE == PN548C2) || (NFC_NXP_CHIP_TYPE == PN551))) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 596 | void etsiInitConfig(); |
| 597 | tNFC_STATUS etsiReaderConfig(int eeHandle); |
| 598 | tNFC_STATUS etsiResetReaderConfig(); |
| 599 | #endif |
| 600 | jint getSETechnology(tNFA_HANDLE eeHandle); |
| 601 | static const UINT8 UICC_ID = 0x02; |
| 602 | static const UINT8 ESE_ID = 0x01; |
| 603 | static const UINT8 DH_ID = 0x00; |
| 604 | |
| 605 | void getEeHandleList(tNFA_HANDLE *list, UINT8* count); |
| 606 | |
| 607 | tNFA_HANDLE getEseHandleFromGenericId(jint eseId); |
| 608 | |
| 609 | jint getGenericEseId(tNFA_HANDLE handle); |
| 610 | |
| 611 | tNFA_STATUS reconfigureEseHciInit(); |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 612 | #if((NFC_NXP_ESE == TRUE)&&(NXP_EXTNS == TRUE)) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 613 | void setCPTimeout(); |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 614 | void NfccStandByOperation(nfcc_standby_operation_t value); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 615 | #endif |
| 616 | bool isWiredModeAllowedInRfState(); |
| 617 | bool mRecvdTransEvt; |
| 618 | bool mAllowWiredMode; |
| 619 | |
| 620 | SyncEvent mRoutingEvent; |
| 621 | SyncEvent mAidAddRemoveEvent; |
| 622 | SyncEvent mUiccListenEvent; |
| 623 | SyncEvent mEseListenEvent; |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 624 | SyncEvent mAllowWiredModeEvent; |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 625 | SyncEvent mEeSetModeEvent; |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 626 | |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 627 | #if(NXP_EXTNS == TRUE) |
nxpandroid | c39a74c | 2016-01-18 16:46:10 +0530 | [diff] [blame] | 628 | tNFA_STATUS SecElem_EeModeSet(uint16_t handle, uint8_t mode); |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 629 | SyncEvent mEEdatapacketEvent; |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame^] | 630 | SyncEvent mTransceiveEvent; |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 631 | static const UINT8 EVT_END_OF_APDU_TRANSFER = 0x21; //NXP Propritory |
| 632 | void setCLState(bool mState); |
| 633 | #endif |
| 634 | |
| 635 | private: |
| 636 | static const unsigned int MAX_RESPONSE_SIZE = 0x8800;//1024; //34K |
| 637 | enum RouteSelection {NoRoute, DefaultRoute, SecElemRoute}; |
| 638 | #ifdef GEMATO_SE_SUPPORT |
| 639 | static const UINT8 STATIC_PIPE_0x70 = 0x19; //PN54X Gemalto's proprietary static pipe |
| 640 | #else |
| 641 | static const UINT8 STATIC_PIPE_0x70 = 0x70; //Broadcom's proprietary static pipe |
| 642 | #endif |
| 643 | static const UINT8 STATIC_PIPE_0x71 = 0x71; //Broadcom's proprietary static pipe |
| 644 | static const UINT8 EVT_SEND_DATA = 0x10; //see specification ETSI TS 102 622 v9.0.0 (Host Controller Interface); section 9.3.3.3 |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 645 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 646 | static const tNFA_HANDLE EE_HANDLE_0xF3 = 0x4C0;//0x401; //handle to secure element in slot 0 |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 647 | #ifdef NXP_UICC_ENABLE |
| 648 | static const tNFA_HANDLE EE_HANDLE_0xF4 = 0x402; //handle to secure element in slot 1 |
| 649 | #else |
| 650 | static const tNFA_HANDLE EE_HANDLE_0xF4 = 0x0F4;//0x4C0; //handle to secure element in slot 1 |
| 651 | #endif |
| 652 | #else |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 653 | static const tNFA_HANDLE EE_HANDLE_0xF3 = 0x4F3; //handle to secure element in slot 0 |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 654 | static const tNFA_HANDLE EE_HANDLE_0xF4 = 0x4F4; //handle to secure element in slot 1 |
| 655 | #endif |
| 656 | |
| 657 | static SecureElement sSecElem; |
| 658 | static const char* APP_NAME; |
| 659 | |
| 660 | UINT8 mDestinationGate; //destination gate of the UICC |
| 661 | tNFA_HANDLE mNfaHciHandle; //NFA handle to NFA's HCI component |
| 662 | nfc_jni_native_data* mNativeData; |
| 663 | bool mIsInit; // whether EE is initialized |
| 664 | UINT8 mActualNumEe; // actual number of EE's reported by the stack |
| 665 | UINT8 mNumEePresent; // actual number of usable EE's |
| 666 | bool mbNewEE; |
| 667 | UINT8 mNewPipeId; |
| 668 | UINT8 mNewSourceGate; |
| 669 | UINT16 mActiveSeOverride; // active "enable" seid, 0 means activate all SEs |
| 670 | tNFA_STATUS mCommandStatus; //completion status of the last command |
| 671 | bool mIsPiping; //is a pipe connected to the controller? |
| 672 | RouteSelection mCurrentRouteSelection; |
| 673 | int mActualResponseSize; //number of bytes in the response received from secure element |
| 674 | int mAtrInfolen; |
| 675 | UINT8 mAtrStatus; |
| 676 | bool mUseOberthurWarmReset; //whether to use warm-reset command |
| 677 | bool mActivatedInListenMode; // whether we're activated in listen mode |
| 678 | UINT8 mOberthurWarmResetCommand; //warm-reset command byte |
| 679 | tNFA_EE_INFO mEeInfo [MAX_NUM_EE]; //actual size stored in mActualNumEe |
| 680 | tNFA_EE_DISCOVER_REQ mUiccInfo; |
| 681 | tNFA_HCI_GET_GATE_PIPE_LIST mHciCfg; |
| 682 | SyncEvent mEeRegisterEvent; |
| 683 | SyncEvent mHciRegisterEvent; |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 684 | |
| 685 | SyncEvent mResetEvent; |
| 686 | SyncEvent mResetOngoingEvent; |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 687 | SyncEvent mPipeListEvent; |
| 688 | SyncEvent mCreatePipeEvent; |
| 689 | SyncEvent mPipeOpenedEvent; |
| 690 | SyncEvent mAllocateGateEvent; |
| 691 | SyncEvent mDeallocateGateEvent; |
| 692 | // SyncEvent mRoutingEvent; |
| 693 | SyncEvent mUiccInfoEvent; |
| 694 | // SyncEvent mAidAddRemoveEvent; |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 695 | SyncEvent mGetRegisterEvent; |
| 696 | SyncEvent mVerInfoEvent; |
| 697 | SyncEvent mRegistryEvent; |
| 698 | SyncEvent mDiscMapEvent; |
| 699 | UINT8 mVerInfo [3]; |
| 700 | UINT8 mAtrInfo[40]; |
| 701 | bool mGetAtrRspwait; |
| 702 | UINT8 mResponseData [MAX_RESPONSE_SIZE]; |
| 703 | RouteDataSet mRouteDataSet; //routing data |
| 704 | std::vector<std::string> mUsedAids; //AID's that are used in current routes |
| 705 | UINT8 mAidForEmptySelect[NCI_MAX_AID_LEN+1]; |
| 706 | Mutex mMutex; // protects fields below |
| 707 | bool mRfFieldIsOn; // last known RF field state |
| 708 | struct timespec mLastRfFieldToggle; // last time RF field went off |
| 709 | IntervalTimer mTransceiveTimer; |
| 710 | bool mTransceiveWaitOk; |
| 711 | int mWiredModeRfFiledEnable; |
| 712 | /******************************************************************************* |
| 713 | ** |
| 714 | ** Function: SecureElement |
| 715 | ** |
| 716 | ** Description: Initialize member variables. |
| 717 | ** |
| 718 | ** Returns: None |
| 719 | ** |
| 720 | *******************************************************************************/ |
| 721 | SecureElement (); |
| 722 | |
| 723 | |
| 724 | /******************************************************************************* |
| 725 | ** |
| 726 | ** Function: ~SecureElement |
| 727 | ** |
| 728 | ** Description: Release all resources. |
| 729 | ** |
| 730 | ** Returns: None |
| 731 | ** |
| 732 | *******************************************************************************/ |
| 733 | ~SecureElement (); |
| 734 | |
| 735 | |
| 736 | /******************************************************************************* |
| 737 | ** |
| 738 | ** Function: nfaEeCallback |
| 739 | ** |
| 740 | ** Description: Receive execution environment-related events from stack. |
| 741 | ** event: Event code. |
| 742 | ** eventData: Event data. |
| 743 | ** |
| 744 | ** Returns: None |
| 745 | ** |
| 746 | *******************************************************************************/ |
| 747 | static void nfaEeCallback (tNFA_EE_EVT event, tNFA_EE_CBACK_DATA* eventData); |
| 748 | |
| 749 | |
| 750 | /******************************************************************************* |
| 751 | ** |
| 752 | ** Function: nfaHciCallback |
| 753 | ** |
| 754 | ** Description: Receive Host Controller Interface-related events from stack. |
| 755 | ** event: Event code. |
| 756 | ** eventData: Event data. |
| 757 | ** |
| 758 | ** Returns: None |
| 759 | ** |
| 760 | *******************************************************************************/ |
| 761 | static void nfaHciCallback (tNFA_HCI_EVT event, tNFA_HCI_EVT_DATA* eventData); |
| 762 | |
| 763 | |
| 764 | /******************************************************************************* |
| 765 | ** |
| 766 | ** Function: findEeByHandle |
| 767 | ** |
| 768 | ** Description: Find information about an execution environment. |
| 769 | ** eeHandle: Handle to execution environment. |
| 770 | ** |
| 771 | ** Returns: Information about an execution environment. |
| 772 | ** |
| 773 | *******************************************************************************/ |
| 774 | tNFA_EE_INFO *findEeByHandle (tNFA_HANDLE eeHandle); |
| 775 | |
| 776 | |
| 777 | /******************************************************************************* |
| 778 | ** |
| 779 | ** Function: findUiccByHandle |
| 780 | ** |
| 781 | ** Description: Find information about an execution environment. |
| 782 | ** eeHandle: Handle of the execution environment. |
| 783 | ** |
| 784 | ** Returns: Information about the execution environment. |
| 785 | ** |
| 786 | *******************************************************************************/ |
| 787 | tNFA_EE_DISCOVER_INFO *findUiccByHandle (tNFA_HANDLE eeHandle); |
| 788 | |
| 789 | |
| 790 | /******************************************************************************* |
| 791 | ** |
| 792 | ** Function: getDefaultEeHandle |
| 793 | ** |
| 794 | ** Description: Get the handle to the execution environment. |
| 795 | ** |
| 796 | ** Returns: Handle to the execution environment. |
| 797 | ** |
| 798 | *******************************************************************************/ |
| 799 | tNFA_HANDLE getDefaultEeHandle (); |
| 800 | |
| 801 | |
| 802 | /******************************************************************************* |
| 803 | ** |
| 804 | ** Function: adjustRoutes |
| 805 | ** |
| 806 | ** Description: Adjust routes in the controller's listen-mode routing table. |
| 807 | ** selection: which set of routes to configure the controller. |
| 808 | ** |
| 809 | ** Returns: None |
| 810 | ** |
| 811 | *******************************************************************************/ |
| 812 | void adjustRoutes (RouteSelection selection); |
| 813 | |
| 814 | |
| 815 | /******************************************************************************* |
| 816 | ** |
| 817 | ** Function: adjustProtocolRoutes |
| 818 | ** |
| 819 | ** Description: Adjust default routing based on protocol in NFC listen mode. |
| 820 | ** isRouteToEe: Whether routing to EE (true) or host (false). |
| 821 | ** |
| 822 | ** Returns: None |
| 823 | ** |
| 824 | *******************************************************************************/ |
| 825 | void adjustProtocolRoutes (RouteDataSet::Database* db, RouteSelection routeSelection); |
| 826 | |
| 827 | |
| 828 | /******************************************************************************* |
| 829 | ** |
| 830 | ** Function: adjustTechnologyRoutes |
| 831 | ** |
| 832 | ** Description: Adjust default routing based on technology in NFC listen mode. |
| 833 | ** isRouteToEe: Whether routing to EE (true) or host (false). |
| 834 | ** |
| 835 | ** Returns: None |
| 836 | ** |
| 837 | *******************************************************************************/ |
| 838 | void adjustTechnologyRoutes (RouteDataSet::Database* db, RouteSelection routeSelection); |
| 839 | |
| 840 | |
| 841 | /******************************************************************************* |
| 842 | ** |
| 843 | ** Function: getEeInfo |
| 844 | ** |
| 845 | ** Description: Get latest information about execution environments from stack. |
| 846 | ** |
| 847 | ** Returns: True if at least 1 EE is available. |
| 848 | ** |
| 849 | *******************************************************************************/ |
| 850 | bool getEeInfo (); |
| 851 | |
| 852 | /******************************************************************************* |
| 853 | ** |
| 854 | ** Function: eeStatusToString |
| 855 | ** |
| 856 | ** Description: Convert status code to status text. |
| 857 | ** status: Status code |
| 858 | ** |
| 859 | ** Returns: None |
| 860 | ** |
| 861 | *******************************************************************************/ |
| 862 | static const char* eeStatusToString (UINT8 status); |
| 863 | |
| 864 | |
| 865 | /******************************************************************************* |
| 866 | ** |
| 867 | ** Function: encodeAid |
| 868 | ** |
| 869 | ** Description: Encode AID in type-length-value using Basic Encoding Rule. |
| 870 | ** tlv: Buffer to store TLV. |
| 871 | ** tlvMaxLen: TLV buffer's maximum length. |
| 872 | ** tlvActualLen: TLV buffer's actual length. |
| 873 | ** aid: Buffer of Application ID. |
| 874 | ** aidLen: Aid buffer's actual length. |
| 875 | ** |
| 876 | ** Returns: True if ok. |
| 877 | ** |
| 878 | *******************************************************************************/ |
| 879 | bool encodeAid (UINT8* tlv, UINT16 tlvMaxLen, UINT16& tlvActualLen, const UINT8* aid, UINT8 aidLen); |
| 880 | |
| 881 | static int decodeBerTlvLength(UINT8* data,int index, int data_length ); |
| 882 | |
| 883 | static void discovery_map_cb (tNFC_DISCOVER_EVT event, tNFC_DISCOVER *p_data); |
| 884 | |
| 885 | |
| 886 | }; |