本文整理汇总了Java中android.nfc.tech.IsoDep.transceive方法的典型用法代码示例。如果您正苦于以下问题:Java IsoDep.transceive方法的具体用法?Java IsoDep.transceive怎么用?Java IsoDep.transceive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.nfc.tech.IsoDep
的用法示例。
在下文中一共展示了IsoDep.transceive方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: assembleFragment
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
private byte[] assembleFragment(IsoDep isoDep, byte[] derPayload, boolean needsSelectAidApdu) throws IOException {
int fragmentByte = 0;
byte[] derResponse = new byte[0];
while (fragmentByte < derPayload.length) {
byte[] fragment = new byte[0];
if (needsSelectAidApdu) {
Log.d(TAG, "transceiveDER - select Aid Apdu");
byte[] retval = isoDep.transceive(NFCUtils.createSelectAidApdu(NFCUtils.AID_ANDROID));
Log.d(TAG, "transceiveDER - select Aid Apdu OK! "+retval.length);
if(NFCUtils.isKeepAlive(retval)) {
needsSelectAidApdu = false;
}
}
int endLength = Math.min(derPayload.length, fragmentByte + NFCUtils.DEFAULT_MAX_FRAGMENT_SIZE);
byte[] fragmentPart = Arrays.copyOfRange(derPayload, fragmentByte, endLength);
fragment = ClientUtils.concatBytes(fragment, fragmentPart);
Log.d(TAG, "transceiveDER - about to send fragment size: " + fragment.length);
derResponse = isoDep.transceive(fragment);
Log.d(TAG, "transceiveDER - received payload: " + Arrays.toString(derResponse));
fragmentByte += fragment.length;
}
return derResponse;
}
示例2: doTransceiveUTF8
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
private String doTransceiveUTF8(IsoDep iso, byte[] command) throws IOException {
final byte[] ret = iso.transceive(command);
Log.d(TAG, "Sent: " + ByteArrayToHexString(command) + "\nRecv: " + ByteArrayToHexString(ret));
final StringBuffer buffer = new StringBuffer();
for(int i = 1; i < ret.length; i++) {
buffer.append((char)ret[i]);
}
final String retStr = buffer.toString();
Log.d(TAG, "UTF-8: " + retStr);
return retStr;
}
示例3: transceiveApdu
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
static byte[] transceiveApdu(IsoDep tag, byte[] cmd) {
if (tag != null) {
try {
if (!tag.isConnected()) {
tag.connect();
tag.setTimeout(10000);
}
return tag.transceive(cmd);
} catch (Exception e) {
}
}
return null;
}
示例4: onHandleIntent
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
if(BuildConfig.DEBUG) {
Log.i(this.getClass().getName(), "CardReaderService started");
}
// get an instance of the nfc tag to communicate
IsoDep isodep = IsoDep.get((Tag)intent.getParcelableExtra(NfcAdapter.EXTRA_TAG));
if(isodep != null) {
try {
// connect to the nfc tag
isodep.connect();
// select application which contains the credit and last transaction
resultOk = isodep.transceive(selectAid);
if (resultOk[0] == 0) {
// get the credit
creditBytes = isodep.transceive(creditPayload);
// get the last transaction
lastTransactionBytes = isodep.transceive(transactionPayload);
} else {
if (BuildConfig.DEBUG) {
Log.w(this.getClass().getName(), "Wrong result: " + arrayToString(resultOk));
}
}
isodep.close();
} catch (IOException e) {
// nfc-card wasn't properly connected and thus wasn't read
if (BuildConfig.DEBUG) {
Log.e(this.getClass().getName(), e.getMessage());
}
statusCode = STATUS_UNKNOWN_ERROR;
}
}else{
// i think this gets executed if an unsupported nfc-card gets connected
// however i'm unable to test this because i have no other card to test it
statusCode = STATUS_UNKNOWN_NFC_CARD_ERROR;
}
// send data back to the MainActivity
sendBroadcast();
}
示例5: writeNBlocks
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
/**
* Use 14443-4 block write to transfer the given number of blocks of the
* given source buffer to the given tag
*
* @param isodep
* Object representing IO access for a certain 14443-4 tag
* //@param blockBuffer
* the byte buffer to transmit
* //@param index
* How far we currently are indexed into that buffer
* @param numOfBlocks
* Number of blocks to send at a time
* @return Success or failure
*/
private byte[] writeNBlocks(IsoDep isodep, int numOfBlocks, int chunkIndex,
byte[] myImgBuffer, byte flags) {
byte[] response;
try {
byte write_multi_block_command[] = new byte[(4 * numOfBlocks) + 2];
write_multi_block_command[0] = flags;
write_multi_block_command[1] = (byte) (chunkIndex);
for (int curBlock = 0; curBlock < 4 * numOfBlocks; curBlock++) {
int index;
index = curBlock + chunkIndex * numOfBlocks * 4;
if(index>= myImgBuffer.length)index = myImgBuffer.length-1;
write_multi_block_command[curBlock + INF_DATA_START_INDEX] = myImgBuffer[index];
}
response = isodep.transceive(write_multi_block_command);
} catch (IOException e) {
// Throws an error anyway, even if correctly written a block
return null;
}// end catch
return response;
}
示例6: sendPowerBlocks
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
/**
* Use 14443-4 block write to transfer the given number of blocks of the
* given source buffer to the given tag
*
* @param isodep
* Object representing IO access for a certain 14443-4 tag
* //@param blockBuffer
* the byte buffer to transmit
* //@param index
* How far we currently are indexed into that buffer
* @param numOfBlocks
* Number of blocks to send at a time
* @return Success or failure
*/
private byte[] sendPowerBlocks(IsoDep isodep, int numOfBlocks, int chunkIndex,
byte[] myImgBuffer, byte flags) {
byte[] response;
try {
byte write_multi_block_command[] = new byte[(4 * numOfBlocks) + 2];
write_multi_block_command[0] = flags;
write_multi_block_command[1] = (byte) (chunkIndex);
for (int curBlock = 0; curBlock < 4 * numOfBlocks; curBlock++) {
int index;
index = curBlock + chunkIndex * numOfBlocks * 4;
if(index>= myImgBuffer.length)index = myImgBuffer.length-1;
write_multi_block_command[curBlock + INF_DATA_START_INDEX] = myImgBuffer[index];
}
response = isodep.transceive(write_multi_block_command);
} catch (IOException e) {
// Throws an error anyway, even if correctly written a block
return null;
}// end catch
return response;
}
示例7: doChallengeYubiKey
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
private void doChallengeYubiKey(IsoDep isoTag, int slot) throws IOException {
long time = System.currentTimeMillis() / 1000 / totp_step;
byte apdu[] = new byte[totpCommand.length + 4];
System.arraycopy(totpCommand, 0, apdu, 0, totpCommand.length);
switch(slot) {
case 1:
apdu[2] = SLOT_CHAL_HMAC1;
break;
case 2:
apdu[2] = SLOT_CHAL_HMAC2;
break;
}
apdu[totpCommand.length] = (byte) (time >> 24);
apdu[totpCommand.length + 1] = (byte) (time >> 16);
apdu[totpCommand.length + 2] = (byte) (time >> 8);
apdu[totpCommand.length + 3] = (byte) time;
byte[] totpApdu = isoTag.transceive(apdu);
if(totpApdu.length == 22 && totpApdu[20] == (byte)0x90 && totpApdu[21] == 0x00) {
int offset = totpApdu[19] & 0xf;
int code = ((totpApdu[offset++] & 0x7f) << 24) |
((totpApdu[offset++] & 0xff) << 16) |
((totpApdu[offset++] & 0xff) << 8) |
((totpApdu[offset++] & 0xff));
String totp = String.format("%06d", code % 1000000);
Intent data = getIntent();
data.putExtra("totp", totp);
setResult(RESULT_OK, data);
} else {
Toast.makeText(this, R.string.totp_failed, Toast.LENGTH_LONG).show();
}
}
示例8: doProgramYubiKey
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
private void doProgramYubiKey(IsoDep isoTag, int slot, String secret) throws IOException {
Base32 base32 = new Base32();
byte[] decoded = base32.decode(secret.toUpperCase());
byte[] key = new byte[20];
System.arraycopy(decoded, 0, key, 0, decoded.length);
byte[] apdu = new byte[64];
apdu[1] = 0x01;
apdu[2] = slot == 1 ? SLOT_CONFIG : SLOT_CONFIG2;
Configurator cfg = new Configurator();
cfg.setKey(Configurator.HMAC_SHA1_MODE, key);
cfg.setCfgFlags((byte) (Configurator.CFGFLAG_CHAL_HMAC | Configurator.CFGFLAG_HMAC_LT64));
cfg.setTktFlags(Configurator.TKTFLAG_CHAL_RESP);
cfg.setExtFlags((byte) (Configurator.EXTFLAG_SERIAL_API_VISIBLE | Configurator.EXTFLAG_ALLOW_UPDATE));
byte[] structure = cfg.getConfigStructure();
apdu[4] = (byte) structure.length;
System.arraycopy(structure, 0, apdu, 5, structure.length);
byte[] resp = isoTag.transceive(apdu);
if(resp[resp.length - 2] == (byte)0x90 && resp[resp.length - 1] == 0x00) {
setResult(RESULT_OK, getIntent());
} else {
Toast.makeText(this, R.string.prog_fail, Toast.LENGTH_LONG).show();
setResult(RESULT_CANCELED);
}
}
示例9: transceiveKeepAlive
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
private byte[] transceiveKeepAlive(IsoDep isoDep) throws IOException {
return isoDep.transceive(NFCUtils.KEEPALIVE);
}
示例10: onTagDiscovered
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
private void onTagDiscovered(Tag tag, IsoDep isoDep, boolean trySoftReset) {
Log.d(TAG, "onTagDiscovered: " + tag);
final long startTime = System.currentTimeMillis();
long duration;
try {
boolean done = false;
final AtomicReference<DERObject> outputPaymentRequestSend = new AtomicReference<>();
final AtomicReference<DERObject> outputPaymentResponseReceive = new AtomicReference<>();
final AtomicReference<DERObject> paymentAck = new AtomicReference<>();
Thread authorization = null;
Log.d(TAG, "first transmit: payment request, startTime(ms)=" + startTime);
PaymentRequestSendStep paymentRequestSendStep = new PaymentRequestSendStep(
getPaymentRequestUri(),
getWalletServiceBinder().getMultisigClientKey());
DERObject derPaymentRequest = paymentRequestSendStep.process(DERObject.NULLOBJECT);
outputPaymentRequestSend.set(derPaymentRequest);
Log.d(TAG, "transceive outputPaymentRequestSend");
final DERObject paymentRequestOutput = transceiveDER(isoDep, outputPaymentRequestSend.get(), true);
while (!done) {
if (paymentRequestOutput != null && authorization == null && outputPaymentResponseReceive.get() == null) {
duration = System.currentTimeMillis() - startTime;
Log.d(TAG, "got payment response ("+duration+" ms since startTime)");
Runnable runnable = new PaymentResponseReceiveRunnable(paymentRequestOutput, outputPaymentResponseReceive);
authorization = new Thread(runnable, "NFCServer.PaymentResponseReceive");
authorization.start();
continue;
}
if (outputPaymentResponseReceive.get() != null && paymentAck.get() == null) {
duration = System.currentTimeMillis() - startTime;
Log.d(TAG, "send server response ("+duration+" ms since startTime)");
DERObject toSend = outputPaymentResponseReceive.get();
DERObject ackResponse = transceiveDER(isoDep, toSend);
paymentAck.set(ackResponse);
continue;
}
if (paymentAck.get() != null) {
duration = System.currentTimeMillis() - startTime;
Log.d(TAG, "Send final ACK ("+duration+" ms since startTime)");
isoDep.transceive(DERObject.NULLOBJECT.serializeToDER());
done = true;
continue;
}
// default: keep alive loop
byte[] response = transceiveKeepAlive(isoDep);
Log.d(TAG, "transceive keep alive, response length=" + response.length);
}
trySoftReset = false;
isoDep.close();
getPaymentRequestDelegate().onPaymentSuccess();
duration = System.currentTimeMillis() - startTime;
Log.d(TAG, "Payment finished - total duration: " + duration + " ms");
} catch (TagLostException tle) {
Log.d(TAG, "Tag lost");
if(trySoftReset) {
softResetNFC(tag);
}
} catch (Throwable e) {
Log.e(TAG, "Exception in onTagDiscovered", e);
getPaymentRequestDelegate().onPaymentError(e.getMessage());
}
}
示例11: readTransactionLog
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
private void readTransactionLog(Tag tag) {
IsoDep card = IsoDep.get(tag);
if (card == null) {
Snackbar.make(findViewById(R.id.coordinatorLayout),
R.string.error_card_incompatible,
Snackbar.LENGTH_SHORT).show();
return;
}
try {
byte[] reset_card = new byte[]{(byte) 0x00, (byte) 0xA4, (byte) 0x00, (byte) 0x00, (byte) 0x00};
byte[] select_vdv = new byte[]{(byte) 0x00, (byte) 0xA4, (byte) 0x04,
(byte) 0x00, (byte) 0x0C, (byte) 0xD2, (byte) 0x76, (byte) 0x00, (byte) 0x01,
(byte) 0x35, (byte) 0x4B, (byte) 0x41, (byte) 0x4E, (byte) 0x4D, (byte) 0x30,
(byte) 0x31, (byte) 0x00, (byte) 0x00};
card.connect();
card.transceive(reset_card);
byte[] response = card.transceive(select_vdv);
if (response[response.length - 2] == (byte) 0x90 && response[response.length - 1] == (byte) 0x00) {
ArrayList<BaseCard> applicationLog = new ArrayList<>();
for (int i = 1; i < 11; i++) {
byte[] byteResponse = card.transceive(new byte[]{(byte) 0x00, (byte) 0xCA,
(byte) 0x01, (byte) 0xF0, (byte) 0x02, (byte) 0xE5, (byte) i, (byte) 0x00});
if (byteResponse.length > 2) {
if (byteResponse[0] == (byte) 0xF1) {
JourneyCard tc = new JourneyCard(byteResponse);
int stationID = tc.transactionData.location.getID().intValue();
stationProvider.getStation(stationID);
applicationLog.add(tc);
} else if (byteResponse[0] == (byte) 0xF6) {
TicketActivationCard ta = new TicketActivationCard(byteResponse);
applicationLog.add(ta);
} else if (byteResponse[0] == (byte) 0xF7) {
ApplicationActivationCard aa = new ApplicationActivationCard(byteResponse);
applicationLog.add(aa);
}
}
}
applicationLogFragment.setApplicationLog(applicationLog);
card.transceive(new byte[]{(byte) 0x00, (byte) 0xA4, (byte) 0x00, (byte) 0x00, (byte) 0x00});
card.transceive(new byte[]{(byte) 0x00, (byte) 0xA4, (byte) 0x04,
(byte) 0x00, (byte) 0x0C, (byte) 0xD2, (byte) 0x76, (byte) 0x00, (byte) 0x01,
(byte) 0x35, (byte) 0x4B, (byte) 0x41, (byte) 0x4E, (byte) 0x4D, (byte) 0x30,
(byte) 0x31, (byte) 0x00, (byte) 0x00});
ArrayList<BaseCard> applicationDetailEntries = new ArrayList<>();
applicationDetailEntries.add(new ApplicationDetailsCard(card.transceive(new byte[]{(byte) 0x00, (byte) 0xCA,
(byte) 0x01, (byte) 0xF0, (byte) 0x02, (byte) 0xE2, (byte) 0x00, (byte) 0x00})));
applicationDetailFragment.setApplicationDetails(applicationDetailEntries);
card.close();
Snackbar.make(findViewById(R.id.coordinatorLayout),
R.string.info_read_card_successful,
Snackbar.LENGTH_SHORT).show();
} else {
Snackbar.make(findViewById(R.id.coordinatorLayout),
R.string.error_card_no_eticket,
Snackbar.LENGTH_SHORT).show();
}
} catch (IOException e) {
Snackbar.make(findViewById(R.id.coordinatorLayout),
R.string.error_card_communication,
Snackbar.LENGTH_SHORT).show();
e.printStackTrace();
}
}
示例12: transceive
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
@TargetApi(10)
private static byte[] transceive(IsoDep paramIsoDep, byte[] paramArrayOfByte)
throws IOException, TagReadTimeoutException
{
long l = SystemClock.elapsedRealtime();
try
{
byte[] arrayOfByte = paramIsoDep.transceive(paramArrayOfByte);
return arrayOfByte;
}
catch (TagLostException localTagLostException)
{
if (SystemClock.elapsedRealtime() - l >= NFC_TIMEOUT_MS) {
throw new TagReadTimeoutException(localTagLostException);
}
throw localTagLostException;
}
}
示例13: doTransceive
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
private void doTransceive(IsoDep iso, byte[] command) throws IOException {
final byte[] ret = iso.transceive(command);
Log.d(TAG, "Sent: " + ByteArrayToHexString(command) + "\nRecv: " + ByteArrayToHexString(ret));
}
示例14: processMastercard
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
public void processMastercard(final IsoDep tag, final String selectppseresponse){
//SELECT AID
//new Thread(new Runnable() {
byte[] SELECT_MASTERCARD_AID = {(byte) 0x00, (byte) 0xA4, (byte) 0x04, (byte) 0x00, (byte) 0x07, (byte) 0xA0, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x10, (byte) 0x10, (byte) 0x00};
byte[] GET_PROCESSING_OPTIONS = {(byte) 0x80, (byte) 0xA8, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x83, (byte) 0x00, (byte) 0x00};
byte[] READ_RECORD_1_1 = {(byte) 0x00, (byte) 0xB2, (byte) 0x01, (byte) 0x0C, (byte) 0x00};
//byte[] COMPUTE_CRYPTOGRAPHIC_CHECKSUM = {};
String selectaidresponse;
//StringBuilder gporesponse;
//String rr1response;
//String responseString;
byte[] responseBytes;
String track2;
int[] unLengths = new int[2];
//public void run(){
try{
responseBytes = tag.transceive(SELECT_MASTERCARD_AID);
logFromTerminal(BERTLV.ByteArrayToHexString(SELECT_MASTERCARD_AID));
logToTerminal(BERTLV.ByteArrayToHexString(responseBytes));
selectaidresponse = BERTLV.ByteArrayToHexString(responseBytes);
//Log.i(TAG, "SELECT AID RESPONSE=" + responseString);
responseBytes = tag.transceive(GET_PROCESSING_OPTIONS);
logFromTerminal(BERTLV.ByteArrayToHexString(GET_PROCESSING_OPTIONS));
logToTerminal(BERTLV.ByteArrayToHexString(responseBytes));
responseBytes = tag.transceive(READ_RECORD_1_1);
unLengths = calculateUNLength(responseBytes);
logFromTerminal(BERTLV.ByteArrayToHexString(READ_RECORD_1_1));
logToTerminal(BERTLV.ByteArrayToHexString(responseBytes));
Log.i(TAG, "TRACK1 UN Length=" + unLengths[0]);
Log.i(TAG, "TRACK2 UN Length=" + unLengths[1]);
txtTrack1UNLength.setText(String.valueOf(unLengths[0])+" decimal places");
txtTrack2UNLength.setText(String.valueOf(unLengths[1])+" decimal places");
txtNumTransactions.setText(String.valueOf(Math.pow(10,unLengths[0])));
float timetoclone = ((150 * (float)Math.pow(10,unLengths[0])) / 1000) / 60;
txtTimeToClone.setText(String.valueOf(timetoclone) + " Minutes");
Log.i(TAG, "numCVVs=" + (Math.pow(10,unLengths[0])));
}
catch(IOException e){
Log.i(TAG, "ERROR=" + e.toString());
}
//}
//}).start();
return;
}
示例15: getRecordsFromAfl
import android.nfc.tech.IsoDep; //导入方法依赖的package包/类
/**
* Retrieve records specified in AFL and remove the contactless indicator from track 2 data.
*
* @param tagCommunicator IsoDep
* @param afl byte[]
* @return List<CardRecord>
*/
public static List<CardRecord> getRecordsFromAfl(IsoDep tagCommunicator, byte[] afl) {
// The AFL must be a multiple of 4 bytes.
if ((afl.length & 0x03) > 0) return null;
List<CardRecord> cardRecords = new ArrayList<CardRecord>();
// Get the number of files.
int numFiles = afl.length / 4;
// Read records for each SFI.
for (int i = 0; i < numFiles; i++) {
int shortFileIdentifier = afl[4 * i] >> 3;
int startRecord = afl[4 * i + 1];
int endRecord = afl[4 * i + 2];
for (; startRecord <= endRecord; startRecord++) {
// Initialize a CardRecord.
CardRecord cardRecord = new CardRecord();
cardRecord.setShortFileIdentifier(shortFileIdentifier);
cardRecord.setRecordNumber(startRecord);
// Generate read record command.
byte[] readRecordCommand = getReadRecordCommand(shortFileIdentifier, startRecord);
// Execute read record command and save to CardRecord.
try {
byte[] recordResponse = tagCommunicator.transceive(readRecordCommand);
recordResponse = stripContactlessIndicator(recordResponse);
cardRecord.setRawResponse(recordResponse);
Log.i(TAG, Helper.byteToHex(readRecordCommand) + " = " + Helper.byteToHex(recordResponse));
} catch (IOException e) {
e.printStackTrace();
}
// Append CardRecord to list.
cardRecords.add(cardRecord);
}
}
return cardRecords;
}