byte[] SELECT = { (byte) 0x00, // CLA Class (byte) 0xA4, // INS Instruction (byte) 0x04, // P1 Parameter 1 (byte) 0x00, // P2 Parameter 2 (byte) 0x0A, // Length 0x63,0x64,0x63,0x00,0x00,0x00,0x00,0x32,0x32,0x31 // AID }; Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); IsoDep tag = IsoDep.get(tagFromIntent); tag.connect(); byte[] result = tag.transceive(SELECT); if (!(result[0] == (byte) 0x90 && result[1] == (byte) 0x00)) throw new IOException("could not select applet");
/** * Tag comm */ private IsoDep mTagCom; @Override public byte[] transceive(final byte[] pCommand) throws CommunicationException { [...] byte[] response = null; [...] // send command to emv card response = mTagCom.transceive(pCommand); [...] return response; }
byte[] response = card.transceive(apduBytes);
IsoDep iso = IsoDep.get(tag); iso.connect(); iso.setTimeOut(5000); // 5 sec time out iso.transceive(apduCommand); // now send your command
private byte[] sendRequest (byte command, byte[] parameters) throws Exception { ByteArrayOutputStream output = new ByteArrayOutputStream(); Log.d(TAG, "Request : " + toHexString(wrapCommand(command, parameters))); byte[] recvBuffer = isoDep.transceive(wrapCommand(command, parameters)); Log.d(TAG, "Response: " + toHexString(recvBuffer)); while (true) { output.write(recvBuffer, 1, recvBuffer.length - 1); byte status = recvBuffer[0]; if (status == STATUS_OPERATION_OK) { break; } else if (status == STATUS_ADDITIONAL_FRAME) { Log.d(TAG, "Request : " + toHexString(wrapCommand(command, parameters))); recvBuffer = isoDep.transceive(wrapCommand(GET_ADDITIONAL_FRAME, null)); Log.d(TAG, "Response: " + toHexString(recvBuffer)); } else if (status == STATUS_PERMISSION_ERROR) { throw new DesfireException(status, "Permission denied"); } else { throw new DesfireException(status, "Unknown status code: " + Integer.toHexString(status & 0xFF)); } } return output.toByteArray(); }
byte[] result = isoDep.transceive(command);
byte[] responseBytes = isoDep.transceive(command.getBytes());
protected ResponseApdu sendAndRcv(CommandApdu cmdApdu, boolean ascii) throws TagLostException, IOException { byte[] cmdBytes = cmdApdu.toBytes(); String cmdStr = CommandApdu.toString(cmdBytes, cmdApdu.getLc()); mUiCallbacks.onMessageSend(cmdStr, cmdApdu.getCommandName()); byte[] rsp = mIsoDep.transceive(cmdBytes); ResponseApdu rspApdu = new ResponseApdu(rsp); byte[] data = rspApdu.getData(); String parsed = null; String errMsg = "no error"; try { if (data.length > 0) { parsed = TLVUtil.prettyPrintAPDUResponse(data); } } catch (TLVException e) { parsed = null; errMsg = e.getMessage(); } mUiCallbacks.onMessageRcv(bytesToHexAndAscii(rsp, ascii), cmdApdu.getCommandName(), parsed); if (data.length > 0 && parsed == null) { mUiCallbacks.onError(errMsg); } /* Log.d(TAG, "response APDU: " + Util.bytesToHex(rsp)); if (data.length > 0) { Log.d(TAG, TLVUtil.prettyPrintAPDUResponse(data)); } */ return rspApdu; }