nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 1 | /* |
Puneet Mishra | 472a75e | 2015-11-11 11:57:26 +0000 | [diff] [blame] | 2 | * Copyright (c) 2015, The Linux Foundation. All rights reserved. |
| 3 | * Not a Contribution. |
| 4 | * |
| 5 | * Copyright (C) 2015 NXP Semiconductors |
| 6 | * The original Work has been changed by NXP Semiconductors. |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 7 | * Copyright (C) 2010 The Android Open Source Project |
| 8 | * |
| 9 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | * you may not use this file except in compliance with the License. |
| 11 | * You may obtain a copy of the License at |
| 12 | * |
| 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | * |
| 15 | * Unless required by applicable law or agreed to in writing, software |
| 16 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | * See the License for the specific language governing permissions and |
| 19 | * limitations under the License. |
| 20 | */ |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 21 | package com.android.nfc.dhimpl; |
| 22 | |
| 23 | import android.annotation.SdkConstant; |
| 24 | import android.annotation.SdkConstant.SdkConstantType; |
| 25 | import android.content.Context; |
| 26 | import android.content.SharedPreferences; |
| 27 | import android.nfc.ErrorCodes; |
| 28 | import android.nfc.tech.Ndef; |
| 29 | import android.nfc.tech.TagTechnology; |
| 30 | import android.util.Log; |
| 31 | import java.io.File; |
| 32 | |
| 33 | import java.util.HashMap; |
| 34 | import java.util.Map; |
| 35 | import com.android.nfc.DeviceHost; |
| 36 | import com.android.nfc.LlcpException; |
| 37 | import com.android.nfc.NfcDiscoveryParameters; |
| 38 | |
| 39 | /** |
| 40 | * Native interface to the NFC Manager functions |
| 41 | */ |
| 42 | public class NativeNfcManager implements DeviceHost { |
| 43 | private static final String TAG = "NativeNfcManager"; |
| 44 | private static final String PREF_FIRMWARE_MODTIME = "firmware_modtime"; |
| 45 | private static final long FIRMWARE_MODTIME_DEFAULT = -1; |
| 46 | static final String PREF = "NciDeviceHost"; |
| 47 | |
| 48 | static final int DEFAULT_LLCP_MIU = 1980; |
| 49 | static final int DEFAULT_LLCP_RWSIZE = 2; |
| 50 | static final int PN547C2_ID = 1; |
| 51 | static final int PN65T_ID = 2; |
| 52 | static final int PN548AD_ID = 3; |
| 53 | static final int PN66T_ID = 4; |
| 54 | |
| 55 | static final String DRIVER_NAME = "android-nci"; |
| 56 | |
| 57 | private static final byte[][] EE_WIPE_APDUS = {}; |
| 58 | |
| 59 | static { |
Puneet Mishra | 472a75e | 2015-11-11 11:57:26 +0000 | [diff] [blame] | 60 | System.loadLibrary("nqnfc_nci_jni"); |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 64 | public static final String INTERNAL_TARGET_DESELECTED_ACTION = "com.android.nfc.action.INTERNAL_TARGET_DESELECTED"; |
| 65 | |
| 66 | /* Native structure */ |
| 67 | private long mNative; |
| 68 | |
| 69 | private final DeviceHostListener mListener; |
| 70 | private final Context mContext; |
| 71 | private Map<String, Integer> mNfcid2ToHandle; |
| 72 | public NativeNfcManager(Context context, DeviceHostListener listener) { |
| 73 | mListener = listener; |
| 74 | initializeNativeStructure(); |
| 75 | mContext = context; |
| 76 | mNfcid2ToHandle = new HashMap<String, Integer>(); |
| 77 | } |
| 78 | |
| 79 | public native boolean initializeNativeStructure(); |
| 80 | |
| 81 | private native boolean doDownload(); |
| 82 | @Override |
| 83 | public boolean download() { |
| 84 | return doDownload(); |
| 85 | } |
| 86 | |
| 87 | public native int doGetLastError(); |
| 88 | |
| 89 | @Override |
| 90 | public void checkFirmware() { |
| 91 | // Check that the NFC controller firmware is up to date. This |
| 92 | // ensures that firmware updates are applied in a timely fashion, |
| 93 | // and makes it much less likely that the user will have to wait |
| 94 | // for a firmware download when they enable NFC in the settings |
| 95 | // app. Firmware download can take some time, so this should be |
| 96 | // run in a separate thread. |
| 97 | |
| 98 | // check the timestamp of the firmware file |
| 99 | File firmwareFile; |
| 100 | int nbRetry = 0; |
| 101 | try { |
| 102 | byte[] fwFileName; |
| 103 | String filePath="/system/vendor/firmware/"; |
| 104 | |
| 105 | //Read firmware file name from config file |
| 106 | fwFileName=getFwFileName(); |
| 107 | if(fwFileName == null) |
| 108 | { |
| 109 | Log.d(TAG,"FileName not found"); |
| 110 | int Ver = getChipVer(); |
| 111 | if( Ver == PN547C2_ID || Ver == PN65T_ID ) |
| 112 | filePath=filePath.concat("libpn547_fw.so"); |
| 113 | else if( Ver == PN548AD_ID || Ver == PN66T_ID ) |
| 114 | filePath=filePath.concat("libpn548ad_fw.so"); |
| 115 | else |
| 116 | filePath=null; |
| 117 | } |
| 118 | else |
| 119 | { |
| 120 | Log.d(TAG,"Firmware fileName found"); |
| 121 | String fileName = new String(fwFileName); |
| 122 | filePath=filePath.concat(fileName); |
| 123 | } |
| 124 | Log.d(TAG,"Firmware file path=" + filePath); |
| 125 | firmwareFile = new File(filePath); |
| 126 | } catch(NullPointerException npe) { |
| 127 | Log.e(TAG,"path to firmware file was null"); |
| 128 | return; |
| 129 | } |
| 130 | |
| 131 | long modtime = firmwareFile.lastModified(); |
| 132 | |
| 133 | SharedPreferences prefs = mContext.getSharedPreferences(PREF, Context.MODE_PRIVATE); |
| 134 | long prev_fw_modtime = prefs.getLong(PREF_FIRMWARE_MODTIME, FIRMWARE_MODTIME_DEFAULT); |
| 135 | Log.d(TAG,"prev modtime: " + prev_fw_modtime); |
| 136 | Log.d(TAG,"new modtime: " + modtime); |
| 137 | if (prev_fw_modtime == modtime) { |
| 138 | return; |
| 139 | } |
| 140 | |
| 141 | // FW download. |
| 142 | Log.d(TAG,"Perform Download"); |
| 143 | if(doDownload()) { |
| 144 | Log.d(TAG,"Download Success"); |
| 145 | // Now that we've finished updating the firmware, save the new modtime. |
| 146 | prefs.edit().putLong(PREF_FIRMWARE_MODTIME, modtime).apply(); |
| 147 | } |
| 148 | else { |
| 149 | Log.d(TAG,"Download Failed"); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | private native boolean doInitialize(); |
| 154 | |
| 155 | @Override |
| 156 | public boolean initialize() { |
| 157 | SharedPreferences prefs = mContext.getSharedPreferences(PREF, Context.MODE_PRIVATE); |
| 158 | SharedPreferences.Editor editor = prefs.edit(); |
| 159 | |
| 160 | if (prefs.getBoolean(NativeNfcSecureElement.PREF_SE_WIRED, false)) { |
| 161 | try { |
| 162 | Thread.sleep (12000); |
| 163 | editor.putBoolean(NativeNfcSecureElement.PREF_SE_WIRED, false); |
| 164 | editor.apply(); |
| 165 | } catch (InterruptedException e) { } |
| 166 | } |
| 167 | |
| 168 | return doInitialize(); |
| 169 | } |
| 170 | |
| 171 | private native void doEnableDtaMode(); |
| 172 | |
| 173 | @Override |
| 174 | public void enableDtaMode() { |
| 175 | Log.d(TAG,"enableDtaMode : entry"); |
| 176 | doEnableDtaMode(); |
| 177 | } |
| 178 | |
| 179 | private native void doDisableDtaMode(); |
| 180 | |
| 181 | @Override |
| 182 | public void disableDtaMode() { |
| 183 | Log.d(TAG,"disableDtaMode : entry"); |
| 184 | doDisableDtaMode(); |
| 185 | } |
| 186 | |
| 187 | private native boolean doDeinitialize(); |
| 188 | |
| 189 | @Override |
| 190 | public boolean deinitialize() { |
| 191 | SharedPreferences prefs = mContext.getSharedPreferences(PREF, Context.MODE_PRIVATE); |
| 192 | SharedPreferences.Editor editor = prefs.edit(); |
| 193 | |
| 194 | editor.putBoolean(NativeNfcSecureElement.PREF_SE_WIRED, false); |
| 195 | editor.apply(); |
| 196 | |
| 197 | return doDeinitialize(); |
| 198 | } |
| 199 | |
| 200 | @Override |
| 201 | public String getName() { |
| 202 | return DRIVER_NAME; |
| 203 | } |
| 204 | |
| 205 | @Override |
| 206 | public native boolean sendRawFrame(byte[] data); |
| 207 | |
| 208 | @Override |
| 209 | public boolean routeAid(byte[] aid, int route, int powerState, boolean isprefix) { |
| 210 | |
| 211 | boolean status = true; |
| 212 | //if(mIsAidFilterSupported) { |
| 213 | //Prepare a cache of AIDs, and only send when vzwSetFilterList is called. |
| 214 | // mAidFilter.addAppAidToCache(aid, route, powerState); |
| 215 | // } else { |
| 216 | |
| 217 | status = doRouteAid(aid, route, powerState, isprefix); |
| 218 | |
| 219 | //} |
| 220 | |
| 221 | return status; |
| 222 | } |
| 223 | |
| 224 | public native boolean doRouteAid(byte[] aid, int route, int powerState, boolean isprefix); |
| 225 | |
| 226 | @Override |
| 227 | public native boolean setDefaultRoute(int defaultRouteEntry, int defaultProtoRouteEntry, int defaultTechRouteEntry); |
| 228 | |
| 229 | @Override |
| 230 | public boolean unrouteAid(byte[] aid) { |
| 231 | // if(mIsAidFilterSupported) { |
| 232 | //Remove AID entry from cache. |
| 233 | // mAidFilter.removeAppAidToCache(aid); |
| 234 | // } |
| 235 | |
| 236 | return doUnrouteAid(aid); |
| 237 | } |
| 238 | |
| 239 | public native boolean doUnrouteAid(byte[] aid); |
| 240 | |
| 241 | @Override |
| 242 | public boolean routeNfcid2(byte[] nfcid2, byte[] syscode, byte[] optparam) { |
| 243 | Log.d(TAG,"routeNfcid2 NFCID2 : " + toHexString(nfcid2, 0, nfcid2.length) ); |
| 244 | |
| 245 | // if(mNfcid2ToHandle.get(toHexString(nfcid2, 0, nfcid2.length)) != null) { |
| 246 | // unrouteNfcid2(nfcid2); |
| 247 | //} |
| 248 | |
| 249 | Log.d(TAG,"routeNfcid2 syscode--- : " + toHexString(syscode, 0, syscode.length) ); |
| 250 | int handle = doRouteNfcid2(nfcid2,syscode,optparam); |
| 251 | if(handle != 0xFF) { |
| 252 | mNfcid2ToHandle.put(toHexString(nfcid2, 0, nfcid2.length), handle); |
| 253 | return true; |
| 254 | } else { |
| 255 | return false; |
| 256 | } |
| 257 | |
| 258 | } |
| 259 | |
| 260 | private native int doRouteNfcid2(byte[] nfcid2, byte[] syscode, byte[] optparam); |
| 261 | |
| 262 | @Override |
| 263 | public boolean unrouteNfcid2(byte[] nfcid2) { |
| 264 | Log.d(TAG,"unrouteNfcid2 NFCID2 : " + toHexString(nfcid2, 0, nfcid2.length) ); |
| 265 | int handle = mNfcid2ToHandle.get(toHexString(nfcid2, 0, nfcid2.length)); |
| 266 | if(mNfcid2ToHandle.get(toHexString(nfcid2, 0, nfcid2.length)) != null) { |
| 267 | mNfcid2ToHandle.remove(toHexString(nfcid2, 0, nfcid2.length)); |
| 268 | } |
| 269 | return doUnRouteNfcid2(nfcid2); |
| 270 | } |
| 271 | |
| 272 | private native boolean doUnRouteNfcid2(byte[] nfcid2); |
| 273 | |
| 274 | public native boolean clearAidTable(); |
| 275 | |
| 276 | @Override |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 277 | public native void doSetProvisionMode(boolean provisionMode); |
| 278 | |
| 279 | @Override |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 280 | public native int getRemainingAidTableSize(); |
| 281 | |
| 282 | @Override |
| 283 | public native int getAidTableSize(); |
| 284 | |
| 285 | @Override |
| 286 | public native int getDefaultAidRoute(); |
| 287 | |
| 288 | @Override |
| 289 | public native int getDefaultDesfireRoute(); |
| 290 | |
| 291 | @Override |
| 292 | public native int getDefaultMifareCLTRoute(); |
| 293 | |
| 294 | @Override |
| 295 | public native void doSetScreenOrPowerState(int state); |
| 296 | |
| 297 | @Override |
| 298 | public native void doSetScreenState(int mScreenState); |
| 299 | |
nxpandroid | 1153eb3 | 2015-11-06 18:46:58 +0530 | [diff] [blame] | 300 | @Override |
| 301 | public native void doEnablep2p(boolean p2pFlag); |
| 302 | |
nxpandroid | 64fd68c | 2015-09-23 16:45:15 +0530 | [diff] [blame] | 303 | public native boolean doSetRoutingEntry(int type, int value, int route, int power); |
| 304 | @Override |
| 305 | public boolean setRoutingEntry(int type, int value, int route, int power) { |
| 306 | return(doSetRoutingEntry(type, value, route, power)); |
| 307 | } |
| 308 | public native boolean doClearRoutingEntry(int type ); |
| 309 | |
| 310 | @Override |
| 311 | public boolean clearRoutingEntry( int type ) { |
| 312 | return(doClearRoutingEntry( type )); |
| 313 | } |
| 314 | |
| 315 | @Override |
| 316 | public native void doSetSecureElementListenTechMask(int tech_mask); |
| 317 | |
| 318 | |
| 319 | private native void doEnableDiscovery(int techMask, |
| 320 | boolean enableLowPowerPolling, |
| 321 | boolean enableReaderMode, |
| 322 | boolean enableHostRouting, |
| 323 | boolean enableP2p, |
| 324 | boolean restart); |
| 325 | |
| 326 | @Override |
| 327 | public void enableDiscovery(NfcDiscoveryParameters params, boolean restart) { |
| 328 | doEnableDiscovery(params.getTechMask(), params.shouldEnableLowPowerDiscovery(), |
| 329 | params.shouldEnableReaderMode(), params.shouldEnableHostRouting(), |
| 330 | params.shouldEnableP2p(), restart); |
| 331 | } |
| 332 | |
| 333 | @Override |
| 334 | public native void disableDiscovery(); |
| 335 | /* |
| 336 | @Override |
| 337 | public native void enableRoutingToHost(); |
| 338 | |
| 339 | @Override |
| 340 | public native void disableRoutingToHost(); |
| 341 | */ |
| 342 | @Override |
| 343 | public native int[] doGetSecureElementList(); |
| 344 | |
| 345 | @Override |
| 346 | public native void doSelectSecureElement(int seID); |
| 347 | |
| 348 | @Override |
| 349 | public native void doDeselectSecureElement(int seID); |
| 350 | |
| 351 | @Override |
| 352 | public native void doSetSEPowerOffState(int seID, boolean enable); |
| 353 | |
| 354 | @Override |
| 355 | public native void setDefaultTechRoute(int seID, int tech_switchon, int tech_switchoff); |
| 356 | |
| 357 | @Override |
| 358 | public native void setDefaultProtoRoute(int seID, int proto_switchon, int proto_switchoff); |
| 359 | |
| 360 | @Override |
| 361 | public native int getChipVer(); |
| 362 | |
| 363 | @Override |
| 364 | public native byte[] getFwFileName(); |
| 365 | |
| 366 | @Override |
| 367 | public native int getNfcInitTimeout(); |
| 368 | |
| 369 | @Override |
| 370 | public native int JCOSDownload(); |
| 371 | |
| 372 | @Override |
| 373 | public native void doSetVenConfigValue(int venconfig); |
| 374 | |
| 375 | @Override |
| 376 | public native int GetDefaultSE(); |
| 377 | |
| 378 | @Override |
| 379 | public native boolean isVzwFeatureEnabled(); |
| 380 | |
| 381 | @Override |
| 382 | public native void setEtsiReaederState(int newState); |
| 383 | |
| 384 | @Override |
| 385 | public native int getEtsiReaederState(); |
| 386 | |
| 387 | @Override |
| 388 | public native void etsiReaderConfig(int eeHandle); |
| 389 | |
| 390 | @Override |
| 391 | public native void notifyEEReaderEvent(int evt); |
| 392 | |
| 393 | @Override |
| 394 | public native void etsiInitConfig(); |
| 395 | |
| 396 | @Override |
| 397 | public native void etsiResetReaderConfig(); |
| 398 | |
| 399 | @Override |
| 400 | public native void updateScreenState(); |
| 401 | |
| 402 | private native NativeLlcpConnectionlessSocket doCreateLlcpConnectionlessSocket(int nSap, |
| 403 | String sn); |
| 404 | |
| 405 | @Override |
| 406 | public LlcpConnectionlessSocket createLlcpConnectionlessSocket(int nSap, String sn) |
| 407 | throws LlcpException { |
| 408 | LlcpConnectionlessSocket socket = doCreateLlcpConnectionlessSocket(nSap, sn); |
| 409 | if (socket != null) { |
| 410 | return socket; |
| 411 | } else { |
| 412 | /* Get Error Status */ |
| 413 | int error = doGetLastError(); |
| 414 | |
| 415 | Log.d(TAG, "failed to create llcp socket: " + ErrorCodes.asString(error)); |
| 416 | |
| 417 | switch (error) { |
| 418 | case ErrorCodes.ERROR_BUFFER_TO_SMALL: |
| 419 | case ErrorCodes.ERROR_INSUFFICIENT_RESOURCES: |
| 420 | throw new LlcpException(error); |
| 421 | default: |
| 422 | throw new LlcpException(ErrorCodes.ERROR_SOCKET_CREATION); |
| 423 | } |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | private native NativeLlcpServiceSocket doCreateLlcpServiceSocket(int nSap, String sn, int miu, |
| 428 | int rw, int linearBufferLength); |
| 429 | @Override |
| 430 | public LlcpServerSocket createLlcpServerSocket(int nSap, String sn, int miu, |
| 431 | int rw, int linearBufferLength) throws LlcpException { |
| 432 | LlcpServerSocket socket = doCreateLlcpServiceSocket(nSap, sn, miu, rw, linearBufferLength); |
| 433 | if (socket != null) { |
| 434 | return socket; |
| 435 | } else { |
| 436 | /* Get Error Status */ |
| 437 | int error = doGetLastError(); |
| 438 | |
| 439 | Log.d(TAG, "failed to create llcp socket: " + ErrorCodes.asString(error)); |
| 440 | |
| 441 | switch (error) { |
| 442 | case ErrorCodes.ERROR_BUFFER_TO_SMALL: |
| 443 | case ErrorCodes.ERROR_INSUFFICIENT_RESOURCES: |
| 444 | throw new LlcpException(error); |
| 445 | default: |
| 446 | throw new LlcpException(ErrorCodes.ERROR_SOCKET_CREATION); |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | private native NativeLlcpSocket doCreateLlcpSocket(int sap, int miu, int rw, |
| 452 | int linearBufferLength); |
| 453 | @Override |
| 454 | public LlcpSocket createLlcpSocket(int sap, int miu, int rw, |
| 455 | int linearBufferLength) throws LlcpException { |
| 456 | LlcpSocket socket = doCreateLlcpSocket(sap, miu, rw, linearBufferLength); |
| 457 | if (socket != null) { |
| 458 | return socket; |
| 459 | } else { |
| 460 | /* Get Error Status */ |
| 461 | int error = doGetLastError(); |
| 462 | |
| 463 | Log.d(TAG, "failed to create llcp socket: " + ErrorCodes.asString(error)); |
| 464 | |
| 465 | switch (error) { |
| 466 | case ErrorCodes.ERROR_BUFFER_TO_SMALL: |
| 467 | case ErrorCodes.ERROR_INSUFFICIENT_RESOURCES: |
| 468 | throw new LlcpException(error); |
| 469 | default: |
| 470 | throw new LlcpException(ErrorCodes.ERROR_SOCKET_CREATION); |
| 471 | } |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | @Override |
| 476 | public native boolean doCheckLlcp(); |
| 477 | |
| 478 | @Override |
| 479 | public native boolean doCheckJcopDlAtBoot(); |
| 480 | |
| 481 | @Override |
| 482 | public native boolean doActivateLlcp(); |
| 483 | |
| 484 | private native void doResetTimeouts(); |
| 485 | |
| 486 | @Override |
| 487 | public void resetTimeouts() { |
| 488 | doResetTimeouts(); |
| 489 | } |
| 490 | |
| 491 | @Override |
| 492 | public native void doAbort(); |
| 493 | |
| 494 | private native boolean doSetTimeout(int tech, int timeout); |
| 495 | @Override |
| 496 | public boolean setTimeout(int tech, int timeout) { |
| 497 | return doSetTimeout(tech, timeout); |
| 498 | } |
| 499 | |
| 500 | private native int doGetTimeout(int tech); |
| 501 | @Override |
| 502 | public int getTimeout(int tech) { |
| 503 | return doGetTimeout(tech); |
| 504 | } |
| 505 | |
| 506 | |
| 507 | @Override |
| 508 | public boolean canMakeReadOnly(int ndefType) { |
| 509 | return (ndefType == Ndef.TYPE_1 || ndefType == Ndef.TYPE_2 || |
| 510 | ndefType == Ndef.TYPE_MIFARE_CLASSIC); |
| 511 | } |
| 512 | |
| 513 | @Override |
| 514 | public int getMaxTransceiveLength(int technology) { |
| 515 | switch (technology) { |
| 516 | case (TagTechnology.NFC_A): |
| 517 | case (TagTechnology.MIFARE_CLASSIC): |
| 518 | case (TagTechnology.MIFARE_ULTRALIGHT): |
| 519 | return 253; // PN544 RF buffer = 255 bytes, subtract two for CRC |
| 520 | case (TagTechnology.NFC_B): |
| 521 | ///////////////////////////////////////////////////////////////// |
| 522 | // Broadcom: Since BCM2079x supports this, set NfcB max size. |
| 523 | //return 0; // PN544 does not support transceive of raw NfcB |
| 524 | return 253; // PN544 does not support transceive of raw NfcB |
| 525 | case (TagTechnology.NFC_V): |
| 526 | return 253; // PN544 RF buffer = 255 bytes, subtract two for CRC |
| 527 | case (TagTechnology.ISO_DEP): |
| 528 | /* The maximum length of a normal IsoDep frame consists of: |
| 529 | * CLA, INS, P1, P2, LC, LE + 255 payload bytes = 261 bytes |
| 530 | * such a frame is supported. Extended length frames however |
| 531 | * are not supported. |
| 532 | */ |
| 533 | return 0xFEFF; // Will be automatically split in two frames on the RF layer |
| 534 | case (TagTechnology.NFC_F): |
| 535 | return 252; // PN544 RF buffer = 255 bytes, subtract one for SoD, two for CRC |
| 536 | default: |
| 537 | return 0; |
| 538 | } |
| 539 | |
| 540 | } |
| 541 | |
| 542 | @Override |
| 543 | public native int setEmvCoPollProfile(boolean enable, int route); |
| 544 | |
| 545 | private native void doSetP2pInitiatorModes(int modes); |
| 546 | @Override |
| 547 | public void setP2pInitiatorModes(int modes) { |
| 548 | doSetP2pInitiatorModes(modes); |
| 549 | } |
| 550 | |
| 551 | private native void doSetP2pTargetModes(int modes); |
| 552 | @Override |
| 553 | public void setP2pTargetModes(int modes) { |
| 554 | doSetP2pTargetModes(modes); |
| 555 | } |
| 556 | |
| 557 | @Override |
| 558 | public boolean getExtendedLengthApdusSupported() { |
| 559 | return true; |
| 560 | } |
| 561 | |
| 562 | @Override |
| 563 | public byte[][] getWipeApdus() { |
| 564 | return EE_WIPE_APDUS; |
| 565 | } |
| 566 | |
| 567 | @Override |
| 568 | public int getDefaultLlcpMiu() { |
| 569 | return DEFAULT_LLCP_MIU; |
| 570 | } |
| 571 | |
| 572 | @Override |
| 573 | public int getDefaultLlcpRwSize() { |
| 574 | return DEFAULT_LLCP_RWSIZE; |
| 575 | } |
| 576 | |
| 577 | private native String doDump(); |
| 578 | @Override |
| 579 | public String dump() { |
| 580 | return doDump(); |
| 581 | } |
| 582 | |
| 583 | private native void doEnableScreenOffSuspend(); |
| 584 | @Override |
| 585 | public boolean enableScreenOffSuspend() { |
| 586 | doEnableScreenOffSuspend(); |
| 587 | return true; |
| 588 | } |
| 589 | |
| 590 | private native void doDisableScreenOffSuspend(); |
| 591 | @Override |
| 592 | public boolean disableScreenOffSuspend() { |
| 593 | doDisableScreenOffSuspend(); |
| 594 | return true; |
| 595 | } |
| 596 | |
| 597 | //private native void doEnableReaderMode(int technologies); |
| 598 | //@Override |
| 599 | //public boolean enableScreenOffSuspend() { |
| 600 | // doEnableScreenOffSuspend(); |
| 601 | //return true; |
| 602 | //} |
| 603 | |
| 604 | //private native void doDisableScreenOffSuspend(); |
| 605 | //@Override |
| 606 | //public boolean disableScreenOffSuspend() { |
| 607 | // doDisableScreenOffSuspend(); |
| 608 | // return true; |
| 609 | //} |
| 610 | |
| 611 | |
| 612 | private native void doCommitRouting(); |
| 613 | |
| 614 | @Override |
| 615 | public native int doGetSecureElementTechList(); |
| 616 | |
| 617 | @Override |
| 618 | public native int[] doGetActiveSecureElementList(); |
| 619 | |
| 620 | |
| 621 | public native byte[] doGetSecureElementUid(); |
| 622 | |
| 623 | @Override |
| 624 | public byte[] getSecureElementUid() |
| 625 | { |
| 626 | byte[] buff; |
| 627 | buff = doGetSecureElementUid(); |
| 628 | if(buff==null) |
| 629 | { |
| 630 | //Avoiding Null pointer Exception creating new byte array |
| 631 | buff = new byte[0]; |
| 632 | Log.d(TAG,"buff : " + buff); |
| 633 | } |
| 634 | return buff; |
| 635 | } |
| 636 | @Override |
| 637 | public void commitRouting() { |
| 638 | doCommitRouting(); |
| 639 | } |
| 640 | |
| 641 | @Override |
| 642 | public native void doPrbsOn(int prbs, int hw_prbs, int tech, int rate); |
| 643 | |
| 644 | @Override |
| 645 | public native void doPrbsOff(); |
| 646 | |
| 647 | @Override |
| 648 | public native int SWPSelfTest(int ch); |
| 649 | |
| 650 | @Override |
| 651 | public native int getFWVersion(); |
| 652 | |
| 653 | @Override |
| 654 | public native void doSetEEPROM(byte[] val); |
| 655 | |
| 656 | @Override |
| 657 | public native byte[] doGetRouting(); |
| 658 | |
| 659 | @Override |
| 660 | public native int doGetSeInterface(int type); |
| 661 | |
| 662 | /** |
| 663 | * Notifies Ndef Message (TODO: rename into notifyTargetDiscovered) |
| 664 | */ |
| 665 | private void notifyNdefMessageListeners(NativeNfcTag tag) { |
| 666 | mListener.onRemoteEndpointDiscovered(tag); |
| 667 | } |
| 668 | |
| 669 | /** |
| 670 | * Notifies transaction |
| 671 | */ |
| 672 | private void notifyTargetDeselected() { |
| 673 | mListener.onCardEmulationDeselected(); |
| 674 | } |
| 675 | |
| 676 | /** |
| 677 | * Notifies transaction |
| 678 | */ |
| 679 | private void notifyTransactionListeners(byte[] aid, byte[] data, int evtSrc) { |
| 680 | mListener.onCardEmulationAidSelected(aid,data,evtSrc); |
| 681 | } |
| 682 | |
| 683 | /** |
| 684 | * Notifies transaction |
| 685 | */ |
| 686 | private void notifyConnectivityListeners(int evtSrc) { |
| 687 | mListener.onConnectivityEvent(evtSrc); |
| 688 | } |
| 689 | |
| 690 | /** |
| 691 | * Notifies transaction |
| 692 | */ |
| 693 | private void notifyEmvcoMultiCardDetectedListeners() { |
| 694 | mListener.onEmvcoMultiCardDetectedEvent(); |
| 695 | } |
| 696 | |
| 697 | /** |
| 698 | * Notifies P2P Device detected, to activate LLCP link |
| 699 | */ |
| 700 | private void notifyLlcpLinkActivation(NativeP2pDevice device) { |
| 701 | mListener.onLlcpLinkActivated(device); |
| 702 | } |
| 703 | |
| 704 | /** |
| 705 | * Notifies P2P Device detected, to activate LLCP link |
| 706 | */ |
| 707 | private void notifyLlcpLinkDeactivated(NativeP2pDevice device) { |
| 708 | mListener.onLlcpLinkDeactivated(device); |
| 709 | } |
| 710 | |
| 711 | /** |
| 712 | * Notifies first packet received from remote LLCP |
| 713 | */ |
| 714 | private void notifyLlcpLinkFirstPacketReceived(NativeP2pDevice device) { |
| 715 | mListener.onLlcpFirstPacketReceived(device); |
| 716 | } |
| 717 | |
| 718 | private void notifySeFieldActivated() { |
| 719 | mListener.onRemoteFieldActivated(); |
| 720 | } |
| 721 | |
| 722 | private void notifySeFieldDeactivated() { |
| 723 | mListener.onRemoteFieldDeactivated(); |
| 724 | } |
| 725 | |
| 726 | /* Reader over SWP listeners*/ |
| 727 | private void notifySWPReaderRequested(boolean istechA, boolean istechB) { |
| 728 | mListener.onSWPReaderRequestedEvent(istechA, istechB); |
| 729 | } |
| 730 | |
| 731 | private void notifySWPReaderRequestedFail(int FailureCause) { |
| 732 | mListener.onSWPReaderRequestedFail(FailureCause); |
| 733 | } |
| 734 | |
| 735 | |
| 736 | private void notifySWPReaderActivated() { |
| 737 | mListener.onSWPReaderActivatedEvent(); |
| 738 | } |
| 739 | |
| 740 | |
| 741 | private void notifyonETSIReaderModeStartConfig(int eeHandle) { |
| 742 | mListener.onETSIReaderModeStartConfig(eeHandle); |
| 743 | } |
| 744 | |
| 745 | private void notifyonETSIReaderModeStopConfig(int disc_ntf_timeout) { |
| 746 | mListener.onETSIReaderModeStopConfig(disc_ntf_timeout); |
| 747 | } |
| 748 | |
| 749 | private void notifyonETSIReaderModeSwpTimeout(int disc_ntf_timeout) { |
| 750 | mListener.onETSIReaderModeSwpTimeout(disc_ntf_timeout); |
| 751 | } |
| 752 | |
| 753 | private void notifySeListenActivated() { |
| 754 | mListener.onSeListenActivated(); |
| 755 | } |
| 756 | |
| 757 | private void notifySeListenDeactivated() { |
| 758 | mListener.onSeListenDeactivated(); |
| 759 | } |
| 760 | |
| 761 | private void notifySeApduReceived(byte[] apdu) { |
| 762 | mListener.onSeApduReceived(apdu); |
| 763 | } |
| 764 | |
| 765 | private void notifySeEmvCardRemoval() { |
| 766 | mListener.onSeEmvCardRemoval(); |
| 767 | } |
| 768 | |
| 769 | private void notifySeMifareAccess(byte[] block) { |
| 770 | mListener.onSeMifareAccess(block); |
| 771 | } |
| 772 | |
| 773 | private void notifyHostEmuActivated() { |
| 774 | mListener.onHostCardEmulationActivated(); |
| 775 | } |
| 776 | |
| 777 | private void notifyHostEmuData(byte[] data) { |
| 778 | mListener.onHostCardEmulationData(data); |
| 779 | } |
| 780 | |
| 781 | private void notifyHostEmuDeactivated() { |
| 782 | mListener.onHostCardEmulationDeactivated(); |
| 783 | } |
| 784 | |
| 785 | private void notifyAidRoutingTableFull() { |
| 786 | mListener.onAidRoutingTableFull(); |
| 787 | } |
| 788 | |
| 789 | private void notifyRfFieldActivated() { |
| 790 | mListener.onRemoteFieldActivated(); |
| 791 | } |
| 792 | |
| 793 | private void notifyRfFieldDeactivated() { |
| 794 | mListener.onRemoteFieldDeactivated(); |
| 795 | } |
| 796 | |
| 797 | static String toHexString(byte[] buffer, int offset, int length) { |
| 798 | final char[] HEX_CHARS = "0123456789abcdef".toCharArray(); |
| 799 | char[] chars = new char[2 * length]; |
| 800 | for (int j = offset; j < offset + length; ++j) { |
| 801 | chars[2 * (j - offset)] = HEX_CHARS[(buffer[j] & 0xF0) >>> 4]; |
| 802 | chars[2 * (j - offset) + 1] = HEX_CHARS[buffer[j] & 0x0F]; |
| 803 | } |
| 804 | return new String(chars); |
| 805 | } |
| 806 | |
| 807 | } |