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 | ******************************************************************************/ |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 35 | #include "_OverrideLog.h" |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 36 | #include "SecureElement.h" |
| 37 | #include "JavaClassConstants.h" |
| 38 | #include "PowerSwitch.h" |
| 39 | #include "NfcTag.h" |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 40 | #include "RoutingManager.h" |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 41 | #include <ScopedPrimitiveArray.h> |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 42 | #include "phNxpConfig.h" |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 43 | |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 44 | #define ALOGV ALOGD |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 45 | extern bool hold_the_transceive; |
| 46 | extern int dual_mode_current_state; |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 47 | #if((NFC_NXP_ESE == TRUE)&&(NXP_NFCC_ESE_UICC_CONCURRENT_ACCESS_PROTECTION == true)) |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 48 | extern bool ceTransactionPending; |
| 49 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 50 | namespace android |
| 51 | { |
| 52 | |
| 53 | extern void startRfDiscovery (bool isStart); |
| 54 | extern bool isDiscoveryStarted(); |
nxpandroid | 5d64ce9 | 2016-11-18 19:48:53 +0530 | [diff] [blame] | 55 | extern bool isp2pActivated(); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 56 | extern void com_android_nfc_NfcManager_disableDiscovery (JNIEnv* e, jobject o); |
| 57 | extern void com_android_nfc_NfcManager_enableDiscovery (JNIEnv* e, jobject o, jint mode); |
nxpandroid | ebf53fb | 2016-12-22 18:48:59 +0530 | [diff] [blame] | 58 | #if (NXP_EXTNS == TRUE) |
| 59 | extern int gMaxEERecoveryTimeout; |
| 60 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 61 | static SyncEvent sNfaVSCResponseEvent; |
| 62 | //static bool sRfEnabled; /*commented to eliminate warning defined but not used*/ |
| 63 | |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 64 | static void nfaVSCCallback(uint8_t event, uint16_t param_len, uint8_t *p_param); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 65 | |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 66 | inline static void nfaVSCCallback(uint8_t event, uint16_t param_len, uint8_t *p_param) /*defined as inline to eliminate warning defined but not used*/ |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 67 | { |
| 68 | (void)event; |
| 69 | (void)param_len; |
| 70 | (void)p_param; |
| 71 | SyncEventGuard guard (sNfaVSCResponseEvent); |
| 72 | sNfaVSCResponseEvent.notifyOne (); |
| 73 | } |
| 74 | |
| 75 | // These must match the EE_ERROR_ types in NfcService.java |
| 76 | static const int EE_ERROR_IO = -1; |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 77 | static const int EE_ERROR_INIT = -3; |
| 78 | static const int EE_ERROR_LISTEN_MODE = -4; |
nxpandroid | 88c4d22 | 2017-05-12 16:10:28 +0530 | [diff] [blame] | 79 | static const int EE_ERROR_EXT_FIELD = -5; |
nxpandroid | ebf53fb | 2016-12-22 18:48:59 +0530 | [diff] [blame] | 80 | |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 81 | /******************************************************************************* |
| 82 | ** |
| 83 | ** Function: nativeNfcSecureElement_doOpenSecureElementConnection |
| 84 | ** |
| 85 | ** Description: Connect to the secure element. |
| 86 | ** e: JVM environment. |
| 87 | ** o: Java object. |
| 88 | ** |
| 89 | ** Returns: Handle of secure element. values < 0 represent failure. |
| 90 | ** |
| 91 | *******************************************************************************/ |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 92 | #if (NXP_EXTNS == TRUE) |
| 93 | static jint nativeNfcSecureElement_doOpenSecureElementConnection (JNIEnv*, jobject,jint seId) |
| 94 | #else |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 95 | static jint nativeNfcSecureElement_doOpenSecureElementConnection (JNIEnv*, jobject) |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 96 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 97 | { |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 98 | ALOGV("%s: enter", __func__); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 99 | bool stat = false; |
| 100 | jint secElemHandle = EE_ERROR_INIT; |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 101 | long ret_val = -1; |
nxpandroid | 875171a | 2017-02-24 16:10:40 +0530 | [diff] [blame] | 102 | #if((NFC_NXP_ESE == TRUE)&&(NXP_EXTNS == TRUE)) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 103 | NFCSTATUS status = NFCSTATUS_FAILED; |
| 104 | p61_access_state_t p61_current_state = P61_STATE_INVALID; |
nxpandroid | 5d64ce9 | 2016-11-18 19:48:53 +0530 | [diff] [blame] | 105 | se_apdu_gate_info gateInfo = NO_APDU_GATE; |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 106 | #endif |
| 107 | SecureElement &se = SecureElement::getInstance(); |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 108 | #if ((NFC_NXP_ESE == TRUE)&&(NXP_EXTNS == TRUE)) |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 109 | #if(NXP_ESE_WIRED_MODE_PRIO != true) |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 110 | if(se.isBusy()) { |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 111 | goto TheEnd; |
| 112 | } |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 113 | #endif |
| 114 | se.mIsExclusiveWiredMode = false; // to ctlr exclusive wired mode |
| 115 | if(seId == 0xF4) |
| 116 | { |
| 117 | if(se.mIsWiredModeOpen) |
| 118 | { |
| 119 | goto TheEnd; |
| 120 | } |
| 121 | #if (NXP_ESE_UICC_EXCLUSIVE_WIRED_MODE == true) |
| 122 | se.mIsExclusiveWiredMode = true; |
| 123 | #endif |
| 124 | stat = se.checkForWiredModeAccess(); |
| 125 | if(stat == false) |
| 126 | { |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 127 | ALOGV("Denying SE open due to SE listen mode active"); |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 128 | secElemHandle = EE_ERROR_LISTEN_MODE; |
| 129 | goto TheEnd; |
| 130 | } |
| 131 | |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 132 | ALOGV("%s: Activating UICC Wired Mode=0x%X", __func__, seId); |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 133 | stat = se.activate(seId); |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 134 | ALOGV("%s: Check UICC activation status stat=%X", __func__, stat); |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 135 | if (stat) |
| 136 | { |
| 137 | //establish a pipe to UICC |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 138 | ALOGV("%s: Creatting a pipe to UICC!", __func__); |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 139 | stat = se.connectEE(); |
| 140 | if (stat) |
| 141 | { |
| 142 | secElemHandle = se.mActiveEeHandle; |
| 143 | } |
| 144 | else |
| 145 | { |
| 146 | se.deactivate (0); |
| 147 | } |
| 148 | } |
| 149 | if ((!stat) && (! PowerSwitch::getInstance ().setModeOff (PowerSwitch::SE_CONNECTED))) |
| 150 | { |
| 151 | PowerSwitch::getInstance ().setLevel (PowerSwitch::LOW_POWER); |
| 152 | } |
| 153 | se.mIsWiredModeOpen = true; |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 154 | #if(NXP_ESE_UICC_EXCLUSIVE_WIRED_MODE == true) |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 155 | if (isDiscoveryStarted()) |
| 156 | { |
| 157 | // Stop RF Discovery if we were polling |
| 158 | startRfDiscovery (false); |
| 159 | status = NFA_DisableListening(); |
| 160 | if(status == NFCSTATUS_OK) |
| 161 | { |
| 162 | startRfDiscovery (true); |
| 163 | } |
| 164 | } |
| 165 | else |
| 166 | { |
| 167 | status = NFA_DisableListening(); |
| 168 | } |
| 169 | se.mlistenDisabled = true; |
| 170 | #endif |
| 171 | goto TheEnd; |
| 172 | } |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 173 | #if(NXP_ESE_WIRED_MODE_PRIO == true) |
| 174 | if((se.mIsWiredModeOpen)&&(se.mActiveEeHandle == (se.EE_HANDLE_0xF4 || SecureElement::EE_HANDLE_0xF8)) |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 175 | { |
| 176 | stat = SecureElement::getInstance().disconnectEE (se.mActiveEeHandle); |
| 177 | se.mActiveEeHandle = NFA_HANDLE_INVALID; |
| 178 | se.mIsWiredModeOpen = false; |
| 179 | } |
| 180 | #endif |
| 181 | |
| 182 | #if(NFC_NXP_CHIP_TYPE != PN547C2) |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 183 | #if (NXP_NFCEE_REMOVED_NTF_RECOVERY == true) |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 184 | if((RoutingManager::getInstance().is_ee_recovery_ongoing())) |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 185 | { |
nxpandroid | ebf53fb | 2016-12-22 18:48:59 +0530 | [diff] [blame] | 186 | SyncEventGuard guard (se.mEEdatapacketEvent); |
| 187 | if(se.mEEdatapacketEvent.wait(android::gMaxEERecoveryTimeout) == false) |
| 188 | { |
| 189 | goto TheEnd; |
| 190 | } |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 191 | } |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 192 | #endif |
| 193 | #if(NXP_ESE_DUAL_MODE_PRIO_SCHEME == NXP_ESE_EXCLUSIVE_WIRED_MODE) |
| 194 | se.mIsExclusiveWiredMode = true; |
| 195 | #endif |
| 196 | stat = se.checkForWiredModeAccess(); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 197 | if(stat == false) |
| 198 | { |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 199 | ALOGV("Denying SE open due to SE listen mode active"); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 200 | secElemHandle = EE_ERROR_LISTEN_MODE; |
| 201 | goto TheEnd; |
| 202 | } |
| 203 | #else |
| 204 | if (se.isActivatedInListenMode()) { |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 205 | ALOGV("Denying SE open due to SE listen mode active"); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 206 | secElemHandle = EE_ERROR_LISTEN_MODE; |
| 207 | goto TheEnd; |
| 208 | } |
| 209 | |
| 210 | if (se.isRfFieldOn()) { |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 211 | ALOGV("Denying SE open due to SE in active RF field"); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 212 | secElemHandle = EE_ERROR_EXT_FIELD; |
| 213 | goto TheEnd; |
| 214 | } |
| 215 | #endif |
| 216 | |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 217 | ret_val = NFC_GetP61Status ((void *)&p61_current_state); |
| 218 | if (ret_val < 0) |
| 219 | { |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 220 | ALOGV("NFC_GetP61Status failed"); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 221 | goto TheEnd; |
| 222 | } |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 223 | ALOGV("P61 Status is: %x", p61_current_state); |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 224 | |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 225 | #if (NXP_ESE_JCOP_DWNLD_PROTECTION == true && NXP_EXTNS == TRUE) |
nxpandroid | 5d64ce9 | 2016-11-18 19:48:53 +0530 | [diff] [blame] | 226 | if(p61_current_state & P61_STATE_JCP_DWNLD) |
| 227 | { |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 228 | ALOGV("Denying SE open due to JCOP OS Download is in progress"); |
nxpandroid | 5d64ce9 | 2016-11-18 19:48:53 +0530 | [diff] [blame] | 229 | secElemHandle = EE_ERROR_IO; |
| 230 | goto TheEnd; |
| 231 | } |
| 232 | #endif |
| 233 | |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 234 | #if(NFC_NXP_ESE_VER == JCOP_VER_3_1) |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame] | 235 | if (!(p61_current_state & P61_STATE_SPI) && !(p61_current_state & P61_STATE_SPI_PRIO)) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 236 | { |
| 237 | #endif |
| 238 | if(p61_current_state & (P61_STATE_SPI)||(p61_current_state & (P61_STATE_SPI_PRIO))) |
| 239 | { |
| 240 | dual_mode_current_state |= SPI_ON; |
| 241 | } |
| 242 | if(p61_current_state & (P61_STATE_SPI_PRIO)) |
| 243 | { |
| 244 | hold_the_transceive = true; |
| 245 | } |
| 246 | |
| 247 | secElemHandle = NFC_ReqWiredAccess ((void *)&status); |
| 248 | if (secElemHandle < 0) |
| 249 | { |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 250 | ALOGV("Denying SE open due to NFC_ReqWiredAccess failed"); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 251 | goto TheEnd; |
| 252 | } |
| 253 | else |
| 254 | { |
| 255 | if (status != NFCSTATUS_SUCCESS) |
| 256 | { |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 257 | ALOGV("Denying SE open due to SE is being used by SPI"); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 258 | secElemHandle = EE_ERROR_IO; |
| 259 | goto TheEnd; |
| 260 | } |
| 261 | else |
| 262 | { |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 263 | ALOGV("SE Access granted"); |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 264 | #if(NXP_ESE_DUAL_MODE_PRIO_SCHEME == NXP_ESE_EXCLUSIVE_WIRED_MODE) |
| 265 | if (isDiscoveryStarted()) |
| 266 | { |
| 267 | // Stop RF Discovery if we were polling |
| 268 | startRfDiscovery (false); |
| 269 | status = NFA_DisableListening(); |
| 270 | if(status == NFCSTATUS_OK) |
| 271 | { |
| 272 | startRfDiscovery (true); |
| 273 | } |
| 274 | } |
| 275 | else |
| 276 | { |
| 277 | status = NFA_DisableListening(); |
| 278 | } |
| 279 | se.mlistenDisabled = true; |
| 280 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | #if(NFC_NXP_ESE_VER == JCOP_VER_3_1) |
| 284 | } |
| 285 | else |
| 286 | { |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 287 | ALOGV("Denying SE open because SPI is already open"); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 288 | goto TheEnd; |
| 289 | |
| 290 | } |
| 291 | #endif |
| 292 | #endif |
nxpandroid | 5d64ce9 | 2016-11-18 19:48:53 +0530 | [diff] [blame] | 293 | /* Tell the controller to power up to get ready for sec elem operations */ |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 294 | PowerSwitch::getInstance ().setLevel (PowerSwitch::FULL_POWER); |
| 295 | PowerSwitch::getInstance ().setModeOn (PowerSwitch::SE_CONNECTED); |
nxpandroid | 5d64ce9 | 2016-11-18 19:48:53 +0530 | [diff] [blame] | 296 | /* If controller is not routing AND there is no pipe connected, |
| 297 | then turn on the sec elem */ |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 298 | #if((NXP_EXTNS == TRUE) && (NFC_NXP_ESE == TRUE)) |
nxpandroid | 5d64ce9 | 2016-11-18 19:48:53 +0530 | [diff] [blame] | 299 | if((!(p61_current_state & (P61_STATE_SPI | P61_STATE_SPI_PRIO))) && (!(dual_mode_current_state & CL_ACTIVE))) |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame] | 300 | stat = se.SecEle_Modeset(0x01); //Workaround |
| 301 | usleep(150000); /*provide enough delay if NFCC enter in recovery*/ |
| 302 | #endif |
| 303 | stat = se.activate(SecureElement::ESE_ID); // It is to get the current activated handle. |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 304 | |
| 305 | if (stat) |
| 306 | { |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 307 | //establish a pipe to sec elem |
| 308 | stat = se.connectEE(); |
| 309 | if (stat) |
| 310 | { |
| 311 | secElemHandle = se.mActiveEeHandle; |
| 312 | } |
| 313 | else |
| 314 | { |
| 315 | se.deactivate (0); |
| 316 | } |
| 317 | } |
nxpandroid | 5d64ce9 | 2016-11-18 19:48:53 +0530 | [diff] [blame] | 318 | #if((NXP_EXTNS == TRUE) && (NFC_NXP_ESE == TRUE)) |
| 319 | if(stat) |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 320 | { |
nxpandroid | 5d64ce9 | 2016-11-18 19:48:53 +0530 | [diff] [blame] | 321 | status = NFA_STATUS_OK; |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 322 | #if((NFC_NXP_ESE == TRUE)&&(NXP_NFCC_ESE_UICC_CONCURRENT_ACCESS_PROTECTION == true)) |
nxpandroid | 5d64ce9 | 2016-11-18 19:48:53 +0530 | [diff] [blame] | 323 | if(!(se.isActivatedInListenMode() || isp2pActivated() || NfcTag::getInstance ().isActivated ())) |
| 324 | { |
| 325 | se.enablePassiveListen(0x00); |
| 326 | } |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 327 | se.meseUiccConcurrentAccess = true; |
nxpandroid | 5d64ce9 | 2016-11-18 19:48:53 +0530 | [diff] [blame] | 328 | #endif |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 329 | #if (NXP_WIRED_MODE_STANDBY == true) |
nxpandroid | ebf53fb | 2016-12-22 18:48:59 +0530 | [diff] [blame] | 330 | if(se.mNfccPowerMode == 1) |
| 331 | { |
nxpandroid | 67bd712 | 2017-04-10 18:18:28 +0530 | [diff] [blame] | 332 | status = se.setNfccPwrConfig(se.POWER_ALWAYS_ON); |
nxpandroid | ebf53fb | 2016-12-22 18:48:59 +0530 | [diff] [blame] | 333 | if(status != NFA_STATUS_OK) |
| 334 | { |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 335 | ALOGV("%s: power link command failed", __func__); |
nxpandroid | ebf53fb | 2016-12-22 18:48:59 +0530 | [diff] [blame] | 336 | } |
nxpandroid | 875171a | 2017-02-24 16:10:40 +0530 | [diff] [blame] | 337 | else |
| 338 | { |
| 339 | se.SecEle_Modeset(0x01); |
nxpandroid | 875171a | 2017-02-24 16:10:40 +0530 | [diff] [blame] | 340 | } |
nxpandroid | ebf53fb | 2016-12-22 18:48:59 +0530 | [diff] [blame] | 341 | } |
| 342 | #endif |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 343 | |
nxpandroid | ebf53fb | 2016-12-22 18:48:59 +0530 | [diff] [blame] | 344 | if((status == NFA_STATUS_OK) && (se.mIsIntfRstEnabled)) |
nxpandroid | 5d64ce9 | 2016-11-18 19:48:53 +0530 | [diff] [blame] | 345 | { |
| 346 | gateInfo = se.getApduGateInfo(); |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 347 | ALOGV("%s: GateInfo %d", __func__, gateInfo); |
nxpandroid | 5d64ce9 | 2016-11-18 19:48:53 +0530 | [diff] [blame] | 348 | if(gateInfo == ETSI_12_APDU_GATE) |
| 349 | { |
| 350 | se.NfccStandByOperation(STANDBY_TIMER_STOP); |
| 351 | status = se.SecElem_sendEvt_Abort(); |
| 352 | if(status != NFA_STATUS_OK) |
| 353 | { |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 354 | ALOGV("%s: EVT_ABORT failed", __func__); |
nxpandroid | 875171a | 2017-02-24 16:10:40 +0530 | [diff] [blame] | 355 | se.sendEvent(SecureElement::EVT_END_OF_APDU_TRANSFER); |
nxpandroid | 5d64ce9 | 2016-11-18 19:48:53 +0530 | [diff] [blame] | 356 | } |
| 357 | } |
| 358 | } |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 359 | |
nxpandroid | 5d64ce9 | 2016-11-18 19:48:53 +0530 | [diff] [blame] | 360 | if(status != NFA_STATUS_OK) |
| 361 | { |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 362 | #if (NXP_WIRED_MODE_STANDBY == true) |
nxpandroid | 875171a | 2017-02-24 16:10:40 +0530 | [diff] [blame] | 363 | if(se.mNfccPowerMode == 1) |
| 364 | se.setNfccPwrConfig(se.NFCC_DECIDES); |
| 365 | #endif |
nxpandroid | 5d64ce9 | 2016-11-18 19:48:53 +0530 | [diff] [blame] | 366 | se.disconnectEE (secElemHandle); |
| 367 | secElemHandle = EE_ERROR_INIT; |
nxpandroid | 875171a | 2017-02-24 16:10:40 +0530 | [diff] [blame] | 368 | |
| 369 | ret_val = NFC_RelWiredAccess((void*)&status); |
| 370 | if(ret_val < 0) |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 371 | ALOGV("Denying SE release due to NFC_RelWiredAccess failure"); |
nxpandroid | 875171a | 2017-02-24 16:10:40 +0530 | [diff] [blame] | 372 | else if(status != NFCSTATUS_SUCCESS) |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 373 | ALOGV("Denying SE close, since SE is not released by PN54xx driver"); |
nxpandroid | 5d64ce9 | 2016-11-18 19:48:53 +0530 | [diff] [blame] | 374 | } |
| 375 | else |
| 376 | { |
| 377 | se.mIsWiredModeOpen = true; |
| 378 | } |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 379 | } |
| 380 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 381 | //if code fails to connect to the secure element, and nothing is active, then |
| 382 | //tell the controller to power down |
| 383 | if ((!stat) && (! PowerSwitch::getInstance ().setModeOff (PowerSwitch::SE_CONNECTED))) |
| 384 | { |
| 385 | PowerSwitch::getInstance ().setLevel (PowerSwitch::LOW_POWER); |
| 386 | } |
| 387 | |
| 388 | TheEnd: |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 389 | ALOGV("%s: exit; return handle=0x%X", __func__, secElemHandle); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 390 | return secElemHandle; |
| 391 | } |
| 392 | |
| 393 | |
| 394 | /******************************************************************************* |
| 395 | ** |
| 396 | ** Function: nativeNfcSecureElement_doDisconnectSecureElementConnection |
| 397 | ** |
| 398 | ** Description: Disconnect from the secure element. |
| 399 | ** e: JVM environment. |
| 400 | ** o: Java object. |
| 401 | ** handle: Handle of secure element. |
| 402 | ** |
| 403 | ** Returns: True if ok. |
| 404 | ** |
| 405 | *******************************************************************************/ |
| 406 | static jboolean nativeNfcSecureElement_doDisconnectSecureElementConnection (JNIEnv*, jobject, jint handle) |
| 407 | { |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 408 | ALOGV("%s: enter; handle=0x%04x", __func__, handle); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 409 | bool stat = false; |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 410 | #if((NFC_NXP_ESE == TRUE)&&(NXP_EXTNS == TRUE)) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 411 | long ret_val = -1; |
| 412 | NFCSTATUS status = NFCSTATUS_FAILED; |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 413 | |
nxpandroid | 34627bd | 2016-05-27 15:52:30 +0530 | [diff] [blame] | 414 | SecureElement &se = SecureElement::getInstance(); |
| 415 | se.NfccStandByOperation(STANDBY_TIMER_STOP); |
| 416 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 417 | |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 418 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 419 | if(handle == (SecureElement::EE_HANDLE_0xF8||se.EE_HANDLE_0xF4)) |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 420 | { |
| 421 | stat = SecureElement::getInstance().disconnectEE (handle); |
| 422 | #if((NFC_NXP_ESE == TRUE)&&(NXP_EXTNS == TRUE)) |
| 423 | se.mIsWiredModeOpen = false; |
| 424 | #endif |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 425 | #if( (NXP_ESE_UICC_EXCLUSIVE_WIRED_MODE == true) && (NFC_NXP_ESE == TRUE) && (NXP_EXTNS == TRUE) ) |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 426 | se.mIsExclusiveWiredMode = false; |
| 427 | if(se.mlistenDisabled) |
| 428 | { |
| 429 | if (isDiscoveryStarted()) |
| 430 | { |
| 431 | // Stop RF Discovery if we were polling |
| 432 | startRfDiscovery (false); |
| 433 | status = NFA_EnableListening(); |
| 434 | startRfDiscovery (true); |
| 435 | } |
| 436 | else |
| 437 | { |
| 438 | status = NFA_EnableListening(); |
| 439 | } |
| 440 | se.mlistenDisabled = false; |
| 441 | } |
| 442 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 443 | goto TheEnd; |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 444 | } |
| 445 | #endif |
| 446 | |
| 447 | #if((NFC_NXP_ESE == TRUE)&&(NXP_EXTNS == TRUE)) |
| 448 | //Send the EVT_END_OF_APDU_TRANSFER event at the end of wired mode session. |
| 449 | se.NfccStandByOperation(STANDBY_MODE_ON); |
| 450 | #endif |
| 451 | |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 452 | stat = SecureElement::getInstance().disconnectEE (handle); |
| 453 | |
nxpandroid | 5d64ce9 | 2016-11-18 19:48:53 +0530 | [diff] [blame] | 454 | /* if nothing is active after this, then tell the controller to power down */ |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 455 | if (! PowerSwitch::getInstance ().setModeOff (PowerSwitch::SE_CONNECTED)) |
| 456 | PowerSwitch::getInstance ().setLevel (PowerSwitch::LOW_POWER); |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 457 | #if((NFC_NXP_ESE == TRUE)&&(NXP_EXTNS == TRUE)) |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 458 | ret_val = NFC_RelWiredAccess ((void *)&status); |
| 459 | if (ret_val < 0) |
| 460 | { |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 461 | ALOGV("Denying SE Release due to NFC_RelWiredAccess failed"); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 462 | goto TheEnd; |
| 463 | } |
| 464 | else |
| 465 | { |
| 466 | if (status != NFCSTATUS_SUCCESS) |
| 467 | { |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 468 | ALOGV("Denying SE close due to SE is not being released by Pn54x driver"); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 469 | stat = false; |
| 470 | } |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 471 | #if((NFC_NXP_ESE == TRUE)&&(NXP_NFCC_ESE_UICC_CONCURRENT_ACCESS_PROTECTION == true)) |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 472 | se.enablePassiveListen(0x01); |
| 473 | SecureElement::getInstance().mPassiveListenTimer.kill(); |
| 474 | se.meseUiccConcurrentAccess = false; |
| 475 | #endif |
| 476 | se.mIsWiredModeOpen = false; |
| 477 | #if(NXP_ESE_DUAL_MODE_PRIO_SCHEME == NXP_ESE_EXCLUSIVE_WIRED_MODE) |
| 478 | if(se.mlistenDisabled) |
| 479 | { |
| 480 | if (isDiscoveryStarted()) |
| 481 | { |
| 482 | // Stop RF Discovery if we were polling |
| 483 | startRfDiscovery (false); |
| 484 | status = NFA_EnableListening(); |
| 485 | startRfDiscovery (true); |
| 486 | } |
| 487 | else |
| 488 | { |
| 489 | status = NFA_EnableListening(); |
| 490 | } |
| 491 | se.mlistenDisabled = false; |
| 492 | } |
| 493 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 494 | } |
| 495 | #endif |
| 496 | TheEnd: |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 497 | #if((NFC_NXP_ESE == TRUE)&&(NXP_EXTNS == TRUE)) |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 498 | ALOGV("%s: exit stat = %d", __func__, stat); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 499 | #else |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 500 | ALOGV("%s: exit", __func__); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 501 | #endif |
| 502 | return stat ? JNI_TRUE : JNI_FALSE; |
| 503 | } |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 504 | #if((NFC_NXP_ESE == TRUE)&&(NXP_EXTNS == TRUE)) |
| 505 | static int checkP61Status(void) |
| 506 | { |
| 507 | jint ret_val = -1; |
| 508 | p61_access_state_t p61_current_state = P61_STATE_INVALID; |
| 509 | ret_val = NFC_GetP61Status ((void *)&p61_current_state); |
| 510 | if (ret_val < 0) |
| 511 | { |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 512 | ALOGV("NFC_GetP61Status failed"); |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 513 | return -1; |
| 514 | } |
| 515 | if(p61_current_state & (P61_STATE_SPI)||(p61_current_state & (P61_STATE_SPI_PRIO))) |
| 516 | { |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 517 | ALOGV("No gpio change"); |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 518 | ret_val = 0; |
| 519 | } |
| 520 | else |
| 521 | { |
| 522 | ret_val = -1; |
| 523 | } |
| 524 | return ret_val; |
| 525 | } |
| 526 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 527 | /******************************************************************************* |
| 528 | ** |
| 529 | ** Function: nativeNfcSecureElement_doResetSecureElement |
| 530 | ** |
| 531 | ** Description: Reset the secure element. |
| 532 | ** e: JVM environment. |
| 533 | ** o: Java object. |
| 534 | ** handle: Handle of secure element. |
| 535 | ** |
| 536 | ** Returns: True if ok. |
| 537 | ** |
| 538 | *******************************************************************************/ |
| 539 | static jboolean nativeNfcSecureElement_doResetSecureElement (JNIEnv*, jobject, jint handle) |
| 540 | { |
| 541 | bool stat = false; |
| 542 | #if (NFC_NXP_ESE == TRUE) |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 543 | #if (NXP_WIRED_MODE_STANDBY == true) |
nxpandroid | 5d64ce9 | 2016-11-18 19:48:53 +0530 | [diff] [blame] | 544 | tNFA_STATUS nfaStat = NFA_STATUS_FAILED; |
nxpandroid | c98b4d5 | 2017-02-24 16:07:04 +0530 | [diff] [blame] | 545 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 546 | SecureElement &se = SecureElement::getInstance(); |
nxpandroid | ebf53fb | 2016-12-22 18:48:59 +0530 | [diff] [blame] | 547 | |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 548 | ALOGV("%s: enter; handle=0x%04x", __func__, handle); |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 549 | if(!se.mIsWiredModeOpen) |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 550 | { |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 551 | ALOGV("wired mode is not open"); |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 552 | return stat; |
| 553 | } |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 554 | #if ((NXP_ESE_DWP_SPI_SYNC_ENABLE == true) && (NXP_WIRED_MODE_STANDBY == true)) |
nxpandroid | ebf53fb | 2016-12-22 18:48:59 +0530 | [diff] [blame] | 555 | if(!checkP61Status()) |
| 556 | { |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 557 | ALOGV("Reset is not allowed while SPI ON"); |
nxpandroid | ebf53fb | 2016-12-22 18:48:59 +0530 | [diff] [blame] | 558 | return stat; |
| 559 | } |
| 560 | #endif |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 561 | #if (NXP_WIRED_MODE_STANDBY == true) |
nxpandroid | 5d64ce9 | 2016-11-18 19:48:53 +0530 | [diff] [blame] | 562 | if(se.mNfccPowerMode == 1) |
| 563 | { |
| 564 | nfaStat = se.setNfccPwrConfig(se.NFCC_DECIDES); |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 565 | ALOGV("%s Power Mode is Legacy", __func__); |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 566 | } |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 567 | #endif |
| 568 | { |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 569 | stat = se.SecEle_Modeset(0x00); |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 570 | if (handle == SecureElement::EE_HANDLE_0xF3) |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 571 | { |
| 572 | if(checkP61Status()) |
| 573 | se.NfccStandByOperation(STANDBY_GPIO_LOW); |
| 574 | } |
| 575 | usleep(100 * 1000); |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 576 | if (handle == SecureElement::EE_HANDLE_0xF3) |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 577 | { |
| 578 | if(checkP61Status() && (se.mIsWiredModeOpen == true)) |
| 579 | se.NfccStandByOperation(STANDBY_GPIO_HIGH); |
| 580 | } |
| 581 | stat = se.SecEle_Modeset(0x01); |
| 582 | usleep(2000 * 1000); |
nxpandroid | 6c999f0 | 2017-02-24 15:45:35 +0530 | [diff] [blame] | 583 | |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 584 | #if (NXP_WIRED_MODE_STANDBY == true) |
nxpandroid | 6c999f0 | 2017-02-24 15:45:35 +0530 | [diff] [blame] | 585 | if(se.mNfccPowerMode == 1) |
| 586 | { |
| 587 | nfaStat = se.setNfccPwrConfig(se.POWER_ALWAYS_ON); |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 588 | ALOGV("%s Power Mode is Legacy", __func__); |
nxpandroid | 6c999f0 | 2017-02-24 15:45:35 +0530 | [diff] [blame] | 589 | } |
| 590 | #endif |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 591 | } |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 592 | #endif |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 593 | ALOGV("%s: exit", __func__); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 594 | return stat ? JNI_TRUE : JNI_FALSE; |
| 595 | } |
| 596 | |
| 597 | /******************************************************************************* |
nxpandroid | 5d64ce9 | 2016-11-18 19:48:53 +0530 | [diff] [blame] | 598 | ** |
| 599 | ** Function: nativeNfcSecureElement_doeSEChipResetSecureElement |
| 600 | ** |
| 601 | ** Description: Reset the secure element. |
| 602 | ** e: JVM environment. |
| 603 | ** o: Java object. |
| 604 | ** handle: Handle of secure element. |
| 605 | ** |
| 606 | ** Returns: True if ok. |
| 607 | ** |
| 608 | *******************************************************************************/ |
| 609 | static jboolean nativeNfcSecureElement_doeSEChipResetSecureElement (JNIEnv*, jobject) |
| 610 | { |
| 611 | bool stat = false; |
| 612 | NFCSTATUS status = NFCSTATUS_FAILED; |
| 613 | unsigned long num = 0x01; |
| 614 | #if ((NFC_NXP_ESE == TRUE) && (NXP_EXTNS == TRUE)) |
| 615 | SecureElement &se = SecureElement::getInstance(); |
| 616 | if (GetNxpNumValue("NXP_ESE_POWER_DH_CONTROL", &num, sizeof(num))) |
| 617 | { |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 618 | ALOGV("Power schemes enabled in config file is %ld", num); |
nxpandroid | 5d64ce9 | 2016-11-18 19:48:53 +0530 | [diff] [blame] | 619 | } |
| 620 | if(num == 0x02) |
| 621 | { |
| 622 | status = se.eSE_Chip_Reset(); |
| 623 | if(status == NFCSTATUS_SUCCESS) |
| 624 | { |
| 625 | stat = true; |
| 626 | } |
| 627 | } |
| 628 | #endif |
| 629 | return stat ? JNI_TRUE : JNI_FALSE; |
| 630 | } |
| 631 | |
| 632 | |
| 633 | /******************************************************************************* |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 634 | ** |
| 635 | ** Function: nativeNfcSecureElement_doGetAtr |
| 636 | ** |
| 637 | ** Description: GetAtr from the connected eSE. |
| 638 | ** e: JVM environment. |
| 639 | ** o: Java object. |
| 640 | ** handle: Handle of secure element. |
| 641 | ** |
| 642 | ** Returns: Buffer of received data. |
| 643 | ** |
| 644 | *******************************************************************************/ |
| 645 | static jbyteArray nativeNfcSecureElement_doGetAtr (JNIEnv* e, jobject, jint handle) |
| 646 | { |
| 647 | bool stat = false; |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 648 | const int32_t recvBufferMaxSize = 1024; |
| 649 | uint8_t recvBuffer [recvBufferMaxSize]; |
| 650 | int32_t recvBufferActualSize = 0; |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 651 | #if (NFC_NXP_ESE == TRUE) |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 652 | ALOGV("%s: enter; handle=0x%04x", __func__, handle); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 653 | |
| 654 | stat = SecureElement::getInstance().getAtr(handle, recvBuffer, &recvBufferActualSize); |
| 655 | |
| 656 | //copy results back to java |
| 657 | #endif |
| 658 | jbyteArray result = e->NewByteArray(recvBufferActualSize); |
| 659 | if (result != NULL) { |
| 660 | e->SetByteArrayRegion(result, 0, recvBufferActualSize, (jbyte *) recvBuffer); |
| 661 | } |
| 662 | |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 663 | ALOGV("%s: exit: recv len=%ld", __func__, recvBufferActualSize); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 664 | |
| 665 | return result; |
| 666 | } |
| 667 | |
| 668 | /******************************************************************************* |
| 669 | ** |
| 670 | ** Function: nativeNfcSecureElement_doTransceive |
| 671 | ** |
| 672 | ** Description: Send data to the secure element; retrieve response. |
| 673 | ** e: JVM environment. |
| 674 | ** o: Java object. |
| 675 | ** handle: Secure element's handle. |
| 676 | ** data: Data to send. |
| 677 | ** |
| 678 | ** Returns: Buffer of received data. |
| 679 | ** |
| 680 | *******************************************************************************/ |
| 681 | static jbyteArray nativeNfcSecureElement_doTransceive (JNIEnv* e, jobject, jint handle, jbyteArray data) |
| 682 | { |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 683 | const int32_t recvBufferMaxSize = 0x8800;//1024; 34k |
| 684 | uint8_t recvBuffer [recvBufferMaxSize]; |
| 685 | int32_t recvBufferActualSize = 0; |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 686 | |
| 687 | ScopedByteArrayRW bytes(e, data); |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 688 | #if(NXP_EXTNS == TRUE) |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 689 | ALOGV("%s: enter; handle=0x%X; buf len=%zu", __func__, handle, bytes.size()); |
| 690 | SecureElement::getInstance().transceive(reinterpret_cast<uint8_t*>(&bytes[0]), bytes.size(), recvBuffer, recvBufferMaxSize, recvBufferActualSize, WIRED_MODE_TRANSCEIVE_TIMEOUT); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 691 | |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 692 | //copy results back to java |
| 693 | jbyteArray result = e->NewByteArray(recvBufferActualSize); |
| 694 | if (result != NULL) |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 695 | { |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 696 | e->SetByteArrayRegion(result, 0, recvBufferActualSize, (jbyte *) recvBuffer); |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 697 | } |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 698 | #if((NFC_NXP_ESE == TRUE)&&(NXP_NFCC_ESE_UICC_CONCURRENT_ACCESS_PROTECTION == true)) |
nxpandroid | 5d64ce9 | 2016-11-18 19:48:53 +0530 | [diff] [blame] | 699 | if (SecureElement::getInstance().mIsWiredModeBlocked == true) |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 700 | { |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 701 | ALOGV("APDU Transceive CE wait"); |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 702 | SecureElement::getInstance().startThread(0x01); |
| 703 | } |
| 704 | #endif |
nxpandroid | 6fd9cdb | 2017-07-12 18:25:41 +0530 | [diff] [blame^] | 705 | ALOGV("%s: exit: recv len=%ld", __func__, recvBufferActualSize); |
nxpandroid | a9a68ba | 2016-01-14 21:12:17 +0530 | [diff] [blame] | 706 | return result; |
| 707 | #else |
| 708 | jbyteArray result = e->NewByteArray(0); |
| 709 | return result; |
| 710 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | /***************************************************************************** |
| 714 | ** |
| 715 | ** Description: JNI functions |
| 716 | ** |
| 717 | *****************************************************************************/ |
| 718 | static JNINativeMethod gMethods[] = |
| 719 | { |
nxpandroid | 7d44e57 | 2016-08-01 19:11:04 +0530 | [diff] [blame] | 720 | #if(NXP_EXTNS == TRUE) |
| 721 | {"doNativeOpenSecureElementConnection", "(I)I", (void *) nativeNfcSecureElement_doOpenSecureElementConnection}, |
| 722 | #else |
| 723 | {"doNativeOpenSecureElementConnection", "()I", (void *) nativeNfcSecureElement_doOpenSecureElementConnection}, |
| 724 | #endif |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 725 | {"doNativeDisconnectSecureElementConnection", "(I)Z", (void *) nativeNfcSecureElement_doDisconnectSecureElementConnection}, |
| 726 | {"doNativeResetSecureElement", "(I)Z", (void *) nativeNfcSecureElement_doResetSecureElement}, |
nxpandroid | 5d64ce9 | 2016-11-18 19:48:53 +0530 | [diff] [blame] | 727 | {"doNativeeSEChipResetSecureElement", "()Z", (void *) nativeNfcSecureElement_doeSEChipResetSecureElement}, |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 728 | {"doTransceive", "(I[B)[B", (void *) nativeNfcSecureElement_doTransceive}, |
| 729 | {"doNativeGetAtr", "(I)[B", (void *) nativeNfcSecureElement_doGetAtr}, |
| 730 | }; |
| 731 | |
| 732 | |
| 733 | /******************************************************************************* |
| 734 | ** |
| 735 | ** Function: register_com_android_nfc_NativeNfcSecureElement |
| 736 | ** |
| 737 | ** Description: Regisgter JNI functions with Java Virtual Machine. |
| 738 | ** e: Environment of JVM. |
| 739 | ** |
| 740 | ** Returns: Status of registration. |
| 741 | ** |
| 742 | *******************************************************************************/ |
| 743 | int register_com_android_nfc_NativeNfcSecureElement(JNIEnv *e) |
| 744 | { |
| 745 | return jniRegisterNativeMethods(e, gNativeNfcSecureElementClassName, |
| 746 | gMethods, NELEM(gMethods)); |
| 747 | } |
| 748 | |
| 749 | |
| 750 | } // namespace android |