14a exchange apdu now uses defined return codes

This commit is contained in:
iceman1001 2021-04-30 08:51:38 +02:00
commit 550fa5aa8f
6 changed files with 65 additions and 67 deletions

View file

@ -855,34 +855,34 @@ static int SelectCard14443_4(bool disconnect, iso14a_card_select_t *card) {
// Anticollision + SELECT card // Anticollision + SELECT card
SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_NO_DISCONNECT, 0, 0, NULL, 0); SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_NO_DISCONNECT, 0, 0, NULL, 0);
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) {
PrintAndLogEx(ERR, "Proxmark3 connection timeout."); PrintAndLogEx(ERR, "Proxmark3 connection timeout");
return 1; return PM3_ETIMEOUT;
} }
// check result // check result
if (resp.oldarg[0] == 0) { if (resp.oldarg[0] == 0) {
PrintAndLogEx(ERR, "No card in field."); PrintAndLogEx(ERR, "No card in fiel.");
return 1; return PM3_ECARDEXCHANGE;
} }
if (resp.oldarg[0] != 1 && resp.oldarg[0] != 2) { if (resp.oldarg[0] != 1 && resp.oldarg[0] != 2) {
PrintAndLogEx(ERR, "Card not in iso14443-4. res=%" PRId64 ".", resp.oldarg[0]); PrintAndLogEx(ERR, "Card not in iso14443-4, res=%" PRId64 ".", resp.oldarg[0]);
return 1; return PM3_ECARDEXCHANGE;
} }
if (resp.oldarg[0] == 2) { // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS, 3: proprietary Anticollision if (resp.oldarg[0] == 2) { // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS, 3: proprietary Anticollision
// get ATS // get ATS
uint8_t rats[] = { 0xE0, 0x80 }; // FSDI=8 (FSD=256), CID=0 uint8_t rats[] = { 0xE0, 0x80 }; // FSDI=8 (FSD=256), CID=0
SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, sizeof(rats), 0, rats, sizeof(rats)); SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, sizeof(rats), 0, rats, sizeof(rats));
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) {
PrintAndLogEx(ERR, "Proxmark3 connection timeout."); PrintAndLogEx(ERR, "Proxmark3 connection timeout");
return 1; return PM3_ETIMEOUT;
} }
if (resp.oldarg[0] == 0) { // ats_len if (resp.oldarg[0] == 0) { // ats_len
PrintAndLogEx(ERR, "Can't get ATS."); PrintAndLogEx(ERR, "Can't get ATS");
return 1; return PM3_ECARDEXCHANGE;
} }
// get frame length from ATS in data field // get frame length from ATS in data field
@ -907,7 +907,7 @@ static int SelectCard14443_4(bool disconnect, iso14a_card_select_t *card) {
if (disconnect) if (disconnect)
DropField(); DropField();
return 0; return PM3_SUCCESS;
} }
static int CmdExchangeAPDU(bool chainingin, uint8_t *datain, int datainlen, bool activateField, uint8_t *dataout, int maxdataoutlen, int *dataoutlen, bool *chainingout) { static int CmdExchangeAPDU(bool chainingin, uint8_t *datain, int datainlen, bool activateField, uint8_t *dataout, int maxdataoutlen, int *dataoutlen, bool *chainingout) {
@ -916,7 +916,7 @@ static int CmdExchangeAPDU(bool chainingin, uint8_t *datain, int datainlen, bool
if (activateField) { if (activateField) {
// select with no disconnect and set frameLength // select with no disconnect and set frameLength
int selres = SelectCard14443_4(false, NULL); int selres = SelectCard14443_4(false, NULL);
if (selres) if (selres != PM3_SUCCESS)
return selres; return selres;
} }
@ -946,32 +946,32 @@ static int CmdExchangeAPDU(bool chainingin, uint8_t *datain, int datainlen, bool
*dataoutlen += dlen; *dataoutlen += dlen;
if (maxdataoutlen && *dataoutlen > maxdataoutlen) { if (maxdataoutlen && *dataoutlen > maxdataoutlen) {
PrintAndLogEx(ERR, "APDU: Buffer too small(%d). Needs %d bytes", *dataoutlen, maxdataoutlen); PrintAndLogEx(ERR, "APDU: Buffer too small(%d), needs %d bytes", *dataoutlen, maxdataoutlen);
return 2; return PM3_EAPDU_FAIL;
} }
// I-block ACK // I-block ACK
if ((res & 0xf2) == 0xa2) { if ((res & 0xf2) == 0xa2) {
*dataoutlen = 0; *dataoutlen = 0;
*chainingout = true; *chainingout = true;
return 0; return PM3_SUCCESS;
} }
if (!iLen) { if (!iLen) {
PrintAndLogEx(ERR, "APDU: No APDU response."); PrintAndLogEx(ERR, "APDU: No APDU response");
return 1; return PM3_EAPDU_FAIL;
} }
// check apdu length // check apdu length
if (iLen < 2 && iLen >= 0) { if (iLen < 2 && iLen >= 0) {
PrintAndLogEx(ERR, "APDU: Small APDU response. Len=%d", iLen); PrintAndLogEx(ERR, "APDU: Small APDU response, len %d", iLen);
return 2; return PM3_EAPDU_FAIL;
} }
// check block TODO // check block TODO
if (iLen == -2) { if (iLen == -2) {
PrintAndLogEx(ERR, "APDU: Block type mismatch."); PrintAndLogEx(ERR, "APDU: Block type mismatch");
return 2; return PM3_EAPDU_FAIL;
} }
memcpy(dataout, recv, dlen); memcpy(dataout, recv, dlen);
@ -983,12 +983,12 @@ static int CmdExchangeAPDU(bool chainingin, uint8_t *datain, int datainlen, bool
// CRC Check // CRC Check
if (iLen == -1) { if (iLen == -1) {
PrintAndLogEx(ERR, "APDU: ISO 14443A CRC error."); PrintAndLogEx(ERR, "APDU: ISO 14443A CRC error");
return 3; return PM3_EAPDU_FAIL;
} }
} else { } else {
PrintAndLogEx(ERR, "APDU: Reply timeout."); PrintAndLogEx(ERR, "APDU: Reply timeout");
return 4; return PM3_EAPDU_FAIL;
} }
return PM3_SUCCESS; return PM3_SUCCESS;
@ -1012,8 +1012,8 @@ int ExchangeAPDU14a(uint8_t *datain, int datainlen, bool activateField, bool lea
*dataoutlen = 0; *dataoutlen = 0;
res = CmdExchangeAPDU(chainBlockNotLast, &datain[clen], vlen, vActivateField, dataout, maxdataoutlen, dataoutlen, &chaining); res = CmdExchangeAPDU(chainBlockNotLast, &datain[clen], vlen, vActivateField, dataout, maxdataoutlen, dataoutlen, &chaining);
if (res) { if (res != PM3_SUCCESS) {
if (!leaveSignalON) if (leaveSignalON == false)
DropField(); DropField();
return 200; return 200;
@ -1022,7 +1022,7 @@ int ExchangeAPDU14a(uint8_t *datain, int datainlen, bool activateField, bool lea
// check R-block ACK // check R-block ACK
//TODO check this one... //TODO check this one...
if ((*dataoutlen == 0) && (*dataoutlen != 0 || chaining != chainBlockNotLast)) { // *dataoutlen!=0. 'A && (!A || B)' is equivalent to 'A && B' if ((*dataoutlen == 0) && (*dataoutlen != 0 || chaining != chainBlockNotLast)) { // *dataoutlen!=0. 'A && (!A || B)' is equivalent to 'A && B'
if (!leaveSignalON) if (leaveSignalON == false)
DropField(); DropField();
return 201; return 201;
@ -1038,8 +1038,8 @@ int ExchangeAPDU14a(uint8_t *datain, int datainlen, bool activateField, bool lea
} while (clen < datainlen); } while (clen < datainlen);
} else { } else {
res = CmdExchangeAPDU(false, datain, datainlen, activateField, dataout, maxdataoutlen, dataoutlen, &chaining); res = CmdExchangeAPDU(false, datain, datainlen, activateField, dataout, maxdataoutlen, dataoutlen, &chaining);
if (res) { if (res != PM3_SUCCESS) {
if (!leaveSignalON) if (leaveSignalON == false)
DropField(); DropField();
return res; return res;
@ -1049,9 +1049,8 @@ int ExchangeAPDU14a(uint8_t *datain, int datainlen, bool activateField, bool lea
while (chaining) { while (chaining) {
// I-block with chaining // I-block with chaining
res = CmdExchangeAPDU(false, NULL, 0, false, &dataout[*dataoutlen], maxdataoutlen, dataoutlen, &chaining); res = CmdExchangeAPDU(false, NULL, 0, false, &dataout[*dataoutlen], maxdataoutlen, dataoutlen, &chaining);
if (res == PM3_SUCCESS) {
if (res) { if (leaveSignalON == false)
if (!leaveSignalON)
DropField(); DropField();
return 100; return 100;
@ -1061,7 +1060,7 @@ int ExchangeAPDU14a(uint8_t *datain, int datainlen, bool activateField, bool lea
if (!leaveSignalON) if (!leaveSignalON)
DropField(); DropField();
return 0; return PM3_SUCCESS;
} }
// ISO14443-4. 7. Half-duplex block transmission protocol // ISO14443-4. 7. Half-duplex block transmission protocol
@ -1173,8 +1172,7 @@ static int CmdHF14AAPDU(const char *Cmd) {
} }
int res = ExchangeAPDU14a(data, datalen, activateField, leaveSignalON, data, PM3_CMD_DATA_SIZE, &datalen); int res = ExchangeAPDU14a(data, datalen, activateField, leaveSignalON, data, PM3_CMD_DATA_SIZE, &datalen);
if (res != PM3_SUCCESS)
if (res)
return res; return res;
PrintAndLogEx(SUCCESS, "<<< %s | %s", sprint_hex_inrow(data, datalen), sprint_ascii(data, datalen)); PrintAndLogEx(SUCCESS, "<<< %s | %s", sprint_hex_inrow(data, datalen), sprint_ascii(data, datalen));
@ -2211,8 +2209,8 @@ static int CmdHf14AFindapdu(const char *Cmd) {
PrintAndLogEx(INFO, "Sending a test APDU (select file command) to check if the tag is responding to APDU"); PrintAndLogEx(INFO, "Sending a test APDU (select file command) to check if the tag is responding to APDU");
param_gethex_to_eol("00a404000aa000000440000101000100", 0, aSELECT_AID, sizeof(aSELECT_AID), &aSELECT_AID_n); param_gethex_to_eol("00a404000aa000000440000101000100", 0, aSELECT_AID, sizeof(aSELECT_AID), &aSELECT_AID_n);
int res = ExchangeAPDU14a(aSELECT_AID, aSELECT_AID_n, true, false, response, sizeof(response), &response_n); int res = ExchangeAPDU14a(aSELECT_AID, aSELECT_AID_n, true, false, response, sizeof(response), &response_n);
if (res) { if (res != PM3_SUCCESS) {
PrintAndLogEx(FAILED, "Tag did not responde to a test APDU (select file command). Aborting"); PrintAndLogEx(FAILED, "Tag did not respond to a test APDU (select file command). Aborting");
return res; return res;
} }
PrintAndLogEx(SUCCESS, "Got response. Starting the APDU finder [ CLA " _GREEN_("%02X") " INS " _GREEN_("%02X") " P1 " _GREEN_("%02X") " P2 " _GREEN_("%02X") " ]", cla, ins, p1, p2); PrintAndLogEx(SUCCESS, "Got response. Starting the APDU finder [ CLA " _GREEN_("%02X") " INS " _GREEN_("%02X") " P1 " _GREEN_("%02X") " P2 " _GREEN_("%02X") " ]", cla, ins, p1, p2);
@ -2258,7 +2256,7 @@ retry_ins:
for (int i = 0; i < 1 + with_le; i++) { for (int i = 0; i < 1 + with_le; i++) {
// Send APDU. // Send APDU.
res = ExchangeAPDU14a(command, command_n + i, activate_field, keep_field_on, response, sizeof(response), &response_n); res = ExchangeAPDU14a(command, command_n + i, activate_field, keep_field_on, response, sizeof(response), &response_n);
if (res) { if (res != PM3_SUCCESS) {
DropField(); DropField();
activate_field = true; activate_field = true;
goto retry_ins; goto retry_ins;

View file

@ -201,7 +201,7 @@ static bool emrtd_exchange_commands(const char *cmd, uint8_t *dataout, int *data
} else { } else {
res = ExchangeAPDU14a(aCMD, aCMD_n, activate_field, keep_field_on, response, sizeof(response), &resplen); res = ExchangeAPDU14a(aCMD, aCMD_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
} }
if (res) { if (res != PM3_SUCCESS) {
DropField(); DropField();
return false; return false;
} }

View file

@ -3836,7 +3836,7 @@ int CmdHF14AMfELoad(const char *Cmd) {
datalen -= block_width; datalen -= block_width;
} }
free(data); free(data);
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(NORMAL, "");
if (block_width == 4) { if (block_width == 4) {
PrintAndLogEx(HINT, "You are ready to simulate. See " _YELLOW_("`hf mfu sim -h`")); PrintAndLogEx(HINT, "You are ready to simulate. See " _YELLOW_("`hf mfu sim -h`"));
@ -5674,7 +5674,7 @@ static int CmdHf14AMfSuperCard(const char *Cmd) {
// --------------- RESET CARD ---------------- // --------------- RESET CARD ----------------
uint8_t aRESET[] = { 0x00, 0xa6, 0xc0, 0x00 }; uint8_t aRESET[] = { 0x00, 0xa6, 0xc0, 0x00 };
res = ExchangeAPDU14a(aRESET, sizeof(aRESET), activate_field, keep_field_on, response, sizeof(response), &resplen); res = ExchangeAPDU14a(aRESET, sizeof(aRESET), activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) { if (res != PM3_SUCCESS) {
PrintAndLogEx(FAILED, "Super card reset [ " _RED_("fail") " ]"); PrintAndLogEx(FAILED, "Super card reset [ " _RED_("fail") " ]");
DropField(); DropField();
return res; return res;
@ -5692,7 +5692,7 @@ static int CmdHf14AMfSuperCard(const char *Cmd) {
// --------------- First ---------------- // --------------- First ----------------
uint8_t aFIRST[] = { 0x00, 0xa6, 0xb0, 0x00, 0x10 }; uint8_t aFIRST[] = { 0x00, 0xa6, 0xb0, 0x00, 0x10 };
res = ExchangeAPDU14a(aFIRST, sizeof(aFIRST), activate_field, keep_field_on, responseA, sizeof(responseA), &respAlen); res = ExchangeAPDU14a(aFIRST, sizeof(aFIRST), activate_field, keep_field_on, responseA, sizeof(responseA), &respAlen);
if (res) { if (res != PM3_SUCCESS) {
DropField(); DropField();
return res; return res;
} }
@ -5703,7 +5703,7 @@ static int CmdHf14AMfSuperCard(const char *Cmd) {
uint8_t aSECOND[] = { 0x00, 0xa6, 0xb0, 0x01, 0x10 }; uint8_t aSECOND[] = { 0x00, 0xa6, 0xb0, 0x01, 0x10 };
res = ExchangeAPDU14a(aSECOND, sizeof(aSECOND), activate_field, keep_field_on, responseB, sizeof(responseB), &respBlen); res = ExchangeAPDU14a(aSECOND, sizeof(aSECOND), activate_field, keep_field_on, responseB, sizeof(responseB), &respBlen);
if (res) { if (res != PM3_SUCCESS) {
DropField(); DropField();
return res; return res;
} }

View file

@ -473,7 +473,7 @@ static int DESFIRESendApdu(bool activate_field, bool leavefield_on, sAPDU apdu,
PrintAndLogEx(SUCCESS, ">>>> %s", sprint_hex(data, datalen)); PrintAndLogEx(SUCCESS, ">>>> %s", sprint_hex(data, datalen));
res = ExchangeAPDU14a(data, datalen, activate_field, leavefield_on, result, max_result_len, (int *)result_len); res = ExchangeAPDU14a(data, datalen, activate_field, leavefield_on, result, max_result_len, (int *)result_len);
if (res) { if (res != PM3_SUCCESS) {
return res; return res;
} }

View file

@ -215,7 +215,7 @@ int infoHFST(void) {
int aSELECT_AID_n = 0; int aSELECT_AID_n = 0;
param_gethex_to_eol("00a4040007d276000085010100", 0, aSELECT_AID, sizeof(aSELECT_AID), &aSELECT_AID_n); param_gethex_to_eol("00a4040007d276000085010100", 0, aSELECT_AID, sizeof(aSELECT_AID), &aSELECT_AID_n);
int res = ExchangeAPDU14a(aSELECT_AID, aSELECT_AID_n, activate_field, keep_field_on, response, sizeof(response), &resplen); int res = ExchangeAPDU14a(aSELECT_AID, aSELECT_AID_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) { if (res != PM3_SUCCESS) {
DropField(); DropField();
return res; return res;
} }
@ -240,7 +240,7 @@ int infoHFST(void) {
int aSELECT_FILE_CC_n = 0; int aSELECT_FILE_CC_n = 0;
param_gethex_to_eol("00a4000c02e103", 0, aSELECT_FILE_CC, sizeof(aSELECT_FILE_CC), &aSELECT_FILE_CC_n); param_gethex_to_eol("00a4000c02e103", 0, aSELECT_FILE_CC, sizeof(aSELECT_FILE_CC), &aSELECT_FILE_CC_n);
res = ExchangeAPDU14a(aSELECT_FILE_CC, aSELECT_FILE_CC_n, activate_field, keep_field_on, response, sizeof(response), &resplen); res = ExchangeAPDU14a(aSELECT_FILE_CC, aSELECT_FILE_CC_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) { if (res != PM3_SUCCESS) {
DropField(); DropField();
return res; return res;
} }
@ -256,7 +256,7 @@ int infoHFST(void) {
int aREAD_CC_n = 0; int aREAD_CC_n = 0;
param_gethex_to_eol("00b000000f", 0, aREAD_CC, sizeof(aREAD_CC), &aREAD_CC_n); param_gethex_to_eol("00b000000f", 0, aREAD_CC, sizeof(aREAD_CC), &aREAD_CC_n);
res = ExchangeAPDU14a(aREAD_CC, aREAD_CC_n, activate_field, keep_field_on, response, sizeof(response), &resplen); res = ExchangeAPDU14a(aREAD_CC, aREAD_CC_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) { if (res != PM3_SUCCESS) {
DropField(); DropField();
return res; return res;
} }
@ -276,7 +276,7 @@ int infoHFST(void) {
int aSELECT_FILE_SYS_n = 0; int aSELECT_FILE_SYS_n = 0;
param_gethex_to_eol("00a4000c02e101", 0, aSELECT_FILE_SYS, sizeof(aSELECT_FILE_SYS), &aSELECT_FILE_SYS_n); param_gethex_to_eol("00a4000c02e101", 0, aSELECT_FILE_SYS, sizeof(aSELECT_FILE_SYS), &aSELECT_FILE_SYS_n);
res = ExchangeAPDU14a(aSELECT_FILE_SYS, aSELECT_FILE_SYS_n, activate_field, keep_field_on, response, sizeof(response), &resplen); res = ExchangeAPDU14a(aSELECT_FILE_SYS, aSELECT_FILE_SYS_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) { if (res != PM3_SUCCESS) {
DropField(); DropField();
return res; return res;
} }
@ -294,7 +294,7 @@ int infoHFST(void) {
int aREAD_SYS_n = 0; int aREAD_SYS_n = 0;
param_gethex_to_eol("00b0000012", 0, aREAD_SYS, sizeof(aREAD_SYS), &aREAD_SYS_n); param_gethex_to_eol("00b0000012", 0, aREAD_SYS, sizeof(aREAD_SYS), &aREAD_SYS_n);
res = ExchangeAPDU14a(aREAD_SYS, aREAD_SYS_n, activate_field, keep_field_on, response, sizeof(response), &resplen); res = ExchangeAPDU14a(aREAD_SYS, aREAD_SYS_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) { if (res != PM3_SUCCESS) {
DropField(); DropField();
return res; return res;
} }
@ -400,7 +400,7 @@ static int CmdHFSTNdef(const char *Cmd) {
int aSELECT_AID_n = 0; int aSELECT_AID_n = 0;
param_gethex_to_eol("00a4040007d276000085010100", 0, aSELECT_AID, sizeof(aSELECT_AID), &aSELECT_AID_n); param_gethex_to_eol("00a4040007d276000085010100", 0, aSELECT_AID, sizeof(aSELECT_AID), &aSELECT_AID_n);
int res = ExchangeAPDU14a(aSELECT_AID, aSELECT_AID_n, activate_field, keep_field_on, response, sizeof(response), &resplen); int res = ExchangeAPDU14a(aSELECT_AID, aSELECT_AID_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) { if (res != PM3_SUCCESS) {
DropField(); DropField();
return res; return res;
} }
@ -425,7 +425,7 @@ static int CmdHFSTNdef(const char *Cmd) {
int aSELECT_FILE_NDEF_n = 0; int aSELECT_FILE_NDEF_n = 0;
param_gethex_to_eol("00a4000c020001", 0, aSELECT_FILE_NDEF, sizeof(aSELECT_FILE_NDEF), &aSELECT_FILE_NDEF_n); param_gethex_to_eol("00a4000c020001", 0, aSELECT_FILE_NDEF, sizeof(aSELECT_FILE_NDEF), &aSELECT_FILE_NDEF_n);
res = ExchangeAPDU14a(aSELECT_FILE_NDEF, aSELECT_FILE_NDEF_n, activate_field, keep_field_on, response, sizeof(response), &resplen); res = ExchangeAPDU14a(aSELECT_FILE_NDEF, aSELECT_FILE_NDEF_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) { if (res != PM3_SUCCESS) {
DropField(); DropField();
return res; return res;
} }
@ -443,7 +443,7 @@ static int CmdHFSTNdef(const char *Cmd) {
int aVERIFY_n = 0; int aVERIFY_n = 0;
param_gethex_to_eol("0020000100", 0, aVERIFY, sizeof(aVERIFY), &aVERIFY_n); param_gethex_to_eol("0020000100", 0, aVERIFY, sizeof(aVERIFY), &aVERIFY_n);
res = ExchangeAPDU14a(aVERIFY, aVERIFY_n, activate_field, keep_field_on, response, sizeof(response), &resplen); res = ExchangeAPDU14a(aVERIFY, aVERIFY_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) { if (res != PM3_SUCCESS) {
DropField(); DropField();
return res; return res;
} }
@ -454,7 +454,7 @@ static int CmdHFSTNdef(const char *Cmd) {
param_gethex_to_eol("0020000110", 0, aVERIFY, sizeof(aVERIFY), &aVERIFY_n); param_gethex_to_eol("0020000110", 0, aVERIFY, sizeof(aVERIFY), &aVERIFY_n);
memcpy(aVERIFY + aVERIFY_n, pwd, pwdlen); memcpy(aVERIFY + aVERIFY_n, pwd, pwdlen);
res = ExchangeAPDU14a(aVERIFY, aVERIFY_n + pwdlen, activate_field, keep_field_on, response, sizeof(response), &resplen); res = ExchangeAPDU14a(aVERIFY, aVERIFY_n + pwdlen, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) { if (res != PM3_SUCCESS) {
DropField(); DropField();
return res; return res;
} }
@ -473,7 +473,7 @@ static int CmdHFSTNdef(const char *Cmd) {
int aREAD_NDEF_n = 0; int aREAD_NDEF_n = 0;
param_gethex_to_eol("00b000001d", 0, aREAD_NDEF, sizeof(aREAD_NDEF), &aREAD_NDEF_n); param_gethex_to_eol("00b000001d", 0, aREAD_NDEF, sizeof(aREAD_NDEF), &aREAD_NDEF_n);
res = ExchangeAPDU14a(aREAD_NDEF, aREAD_NDEF_n, activate_field, keep_field_on, response, sizeof(response), &resplen); res = ExchangeAPDU14a(aREAD_NDEF, aREAD_NDEF_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) { if (res != PM3_SUCCESS) {
DropField(); DropField();
return res; return res;
} }
@ -563,7 +563,7 @@ static int CmdHFSTProtect(const char *Cmd) {
int aSELECT_AID_n = 0; int aSELECT_AID_n = 0;
param_gethex_to_eol("00a4040007d276000085010100", 0, aSELECT_AID, sizeof(aSELECT_AID), &aSELECT_AID_n); param_gethex_to_eol("00a4040007d276000085010100", 0, aSELECT_AID, sizeof(aSELECT_AID), &aSELECT_AID_n);
int res = ExchangeAPDU14a(aSELECT_AID, aSELECT_AID_n, activate_field, keep_field_on, response, sizeof(response), &resplen); int res = ExchangeAPDU14a(aSELECT_AID, aSELECT_AID_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) { if (res != PM3_SUCCESS) {
DropField(); DropField();
return res; return res;
} }
@ -588,7 +588,7 @@ static int CmdHFSTProtect(const char *Cmd) {
int aSELECT_FILE_NDEF_n = 0; int aSELECT_FILE_NDEF_n = 0;
param_gethex_to_eol("00a4000c020001", 0, aSELECT_FILE_NDEF, sizeof(aSELECT_FILE_NDEF), &aSELECT_FILE_NDEF_n); param_gethex_to_eol("00a4000c020001", 0, aSELECT_FILE_NDEF, sizeof(aSELECT_FILE_NDEF), &aSELECT_FILE_NDEF_n);
res = ExchangeAPDU14a(aSELECT_FILE_NDEF, aSELECT_FILE_NDEF_n, activate_field, keep_field_on, response, sizeof(response), &resplen); res = ExchangeAPDU14a(aSELECT_FILE_NDEF, aSELECT_FILE_NDEF_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) { if (res != PM3_SUCCESS) {
DropField(); DropField();
return res; return res;
} }
@ -607,7 +607,7 @@ static int CmdHFSTProtect(const char *Cmd) {
param_gethex_to_eol("0020000210", 0, aVERIFY, sizeof(aVERIFY), &aVERIFY_n); param_gethex_to_eol("0020000210", 0, aVERIFY, sizeof(aVERIFY), &aVERIFY_n);
memcpy(aVERIFY + aVERIFY_n, pwd, pwdlen); memcpy(aVERIFY + aVERIFY_n, pwd, pwdlen);
res = ExchangeAPDU14a(aVERIFY, aVERIFY_n + pwdlen, activate_field, keep_field_on, response, sizeof(response), &resplen); res = ExchangeAPDU14a(aVERIFY, aVERIFY_n + pwdlen, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) { if (res != PM3_SUCCESS) {
DropField(); DropField();
return res; return res;
} }
@ -626,7 +626,7 @@ static int CmdHFSTProtect(const char *Cmd) {
param_gethex_to_eol("00", 0, aPROTECT, sizeof(aPROTECT), &aPROTECT_n); param_gethex_to_eol("00", 0, aPROTECT, sizeof(aPROTECT), &aPROTECT_n);
memcpy(aPROTECT + aPROTECT_n, state, statelen); memcpy(aPROTECT + aPROTECT_n, state, statelen);
res = ExchangeAPDU14a(aPROTECT, aPROTECT_n + statelen, activate_field, keep_field_on, response, sizeof(response), &resplen); res = ExchangeAPDU14a(aPROTECT, aPROTECT_n + statelen, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) { if (res != PM3_SUCCESS) {
DropField(); DropField();
return res; return res;
} }
@ -707,7 +707,7 @@ static int CmdHFSTPwd(const char *Cmd) {
int aSELECT_AID_n = 0; int aSELECT_AID_n = 0;
param_gethex_to_eol("00a4040007d276000085010100", 0, aSELECT_AID, sizeof(aSELECT_AID), &aSELECT_AID_n); param_gethex_to_eol("00a4040007d276000085010100", 0, aSELECT_AID, sizeof(aSELECT_AID), &aSELECT_AID_n);
int res = ExchangeAPDU14a(aSELECT_AID, aSELECT_AID_n, activate_field, keep_field_on, response, sizeof(response), &resplen); int res = ExchangeAPDU14a(aSELECT_AID, aSELECT_AID_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) { if (res != PM3_SUCCESS) {
DropField(); DropField();
return res; return res;
} }
@ -732,7 +732,7 @@ static int CmdHFSTPwd(const char *Cmd) {
int aSELECT_FILE_NDEF_n = 0; int aSELECT_FILE_NDEF_n = 0;
param_gethex_to_eol("00a4000c020001", 0, aSELECT_FILE_NDEF, sizeof(aSELECT_FILE_NDEF), &aSELECT_FILE_NDEF_n); param_gethex_to_eol("00a4000c020001", 0, aSELECT_FILE_NDEF, sizeof(aSELECT_FILE_NDEF), &aSELECT_FILE_NDEF_n);
res = ExchangeAPDU14a(aSELECT_FILE_NDEF, aSELECT_FILE_NDEF_n, activate_field, keep_field_on, response, sizeof(response), &resplen); res = ExchangeAPDU14a(aSELECT_FILE_NDEF, aSELECT_FILE_NDEF_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) { if (res != PM3_SUCCESS) {
DropField(); DropField();
return res; return res;
} }
@ -751,7 +751,7 @@ static int CmdHFSTPwd(const char *Cmd) {
param_gethex_to_eol("0020000210", 0, aVERIFY, sizeof(aVERIFY), &aVERIFY_n); param_gethex_to_eol("0020000210", 0, aVERIFY, sizeof(aVERIFY), &aVERIFY_n);
memcpy(aVERIFY + aVERIFY_n, pwd, pwdlen); memcpy(aVERIFY + aVERIFY_n, pwd, pwdlen);
res = ExchangeAPDU14a(aVERIFY, aVERIFY_n + pwdlen, activate_field, keep_field_on, response, sizeof(response), &resplen); res = ExchangeAPDU14a(aVERIFY, aVERIFY_n + pwdlen, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) { if (res != PM3_SUCCESS) {
DropField(); DropField();
return res; return res;
} }
@ -772,7 +772,7 @@ static int CmdHFSTPwd(const char *Cmd) {
memcpy(aCHG_PWD + aCHG_PWD_n, changePwd, changePwdlen); memcpy(aCHG_PWD + aCHG_PWD_n, changePwd, changePwdlen);
memcpy(aCHG_PWD + aCHG_PWD_n + changePwdlen, newpwd, newpwdlen); memcpy(aCHG_PWD + aCHG_PWD_n + changePwdlen, newpwd, newpwdlen);
res = ExchangeAPDU14a(aCHG_PWD, aCHG_PWD_n + changePwdlen + newpwdlen, activate_field, keep_field_on, response, sizeof(response), &resplen); res = ExchangeAPDU14a(aCHG_PWD, aCHG_PWD_n + changePwdlen + newpwdlen, activate_field, keep_field_on, response, sizeof(response), &resplen);
if (res) { if (res != PM3_SUCCESS) {
DropField(); DropField();
return res; return res;
} }

View file

@ -301,9 +301,9 @@ static int EMVExchangeEx(EMVCommandChannel channel, bool ActivateField, bool Lea
switch (channel) { switch (channel) {
case ECC_CONTACTLESS: case ECC_CONTACTLESS:
res = ExchangeAPDU14a(data, datalen, ActivateField, LeaveFieldON, Result, (int)MaxResultLen, (int *)ResultLen); res = ExchangeAPDU14a(data, datalen, ActivateField, LeaveFieldON, Result, (int)MaxResultLen, (int *)ResultLen);
if (res) { if (res != PM3_SUCCESS) {
res = exchange_14b_apdu(data, datalen, ActivateField, LeaveFieldON, Result, (int)MaxResultLen, (int *)ResultLen, 4000); res = exchange_14b_apdu(data, datalen, ActivateField, LeaveFieldON, Result, (int)MaxResultLen, (int *)ResultLen, 4000);
if (res) if (res != PM3_SUCCESS)
return res; return res;
} }
break; break;