simplify Iso7816Connect

This commit is contained in:
Philippe Teuwen 2021-06-02 23:38:43 +02:00
parent c5ba1d7a2d
commit af6ff40748
6 changed files with 16 additions and 31 deletions

View file

@ -846,7 +846,7 @@ int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leav
return 0;
}
int SelectCard14443_4(bool disconnect, iso14a_card_select_t *card) {
int SelectCard14443A_4(bool disconnect, iso14a_card_select_t *card) {
PacketResponseNG resp;
frameLength = 0;
@ -918,7 +918,7 @@ static int CmdExchangeAPDU(bool chainingin, uint8_t *datain, int datainlen, bool
if (activateField) {
// select with no disconnect and set frameLength
int selres = SelectCard14443_4(false, NULL);
int selres = SelectCard14443A_4(false, NULL);
if (selres != PM3_SUCCESS)
return selres;
}

View file

@ -35,5 +35,5 @@ int Hf14443_4aGetCardData(iso14a_card_select_t *card);
int ExchangeAPDU14a(uint8_t *datain, int datainlen, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen);
int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen, bool silentMode);
int SelectCard14443_4(bool disconnect, iso14a_card_select_t *card);
int SelectCard14443A_4(bool disconnect, iso14a_card_select_t *card);
#endif

View file

@ -1558,7 +1558,7 @@ static int srix4kValid(const char *Cmd) {
}
*/
static int select_card_14443b_4(bool disconnect, iso14b_card_select_t *card) {
int select_card_14443b_4(bool disconnect, iso14b_card_select_t *card) {
if (card)
memset(card, 0, sizeof(iso14b_card_select_t));

View file

@ -12,11 +12,13 @@
#define CMDHF14B_H__
#include "common.h"
#include "iso14b.h"
int CmdHF14B(const char *Cmd);
int CmdHF14BNdefRead(const char *Cmd);
int exchange_14b_apdu(uint8_t *datain, int datainlen, bool activate_field, bool leave_signal_on, uint8_t *dataout, int maxdataoutlen, int *dataoutlen, int user_timeout);
int select_card_14443b_4(bool disconnect, iso14b_card_select_t *card);
int infoHF14B(bool verbose, bool do_aid_search);
int readHF14B(bool loop, bool verbose);

View file

@ -3613,7 +3613,7 @@ static int CmdHF14ADesInfo(const char *Cmd) {
iso14a_card_select_t card;
res = SelectCard14443_4(true, &card);
res = SelectCard14443A_4(true, &card);
if (res == PM3_SUCCESS) {
static const char STANDALONE_DESFIRE[] = { 0x75, 0x77, 0x81, 0x02};
static const char JCOP_DESFIRE[] = { 0x75, 0xf7, 0xb1, 0x02 };

View file

@ -50,39 +50,22 @@ int Iso7816Connect(Iso7816CommandChannel channel) {
return PM3_ENOTIMPL;
}
// Try to 14a
SendCommandMIX(CMD_HF_ISO14443A_READER, ISO14A_CONNECT | ISO14A_NO_DISCONNECT, 0, 0, NULL, 0);
PacketResponseNG resp;
bool failed_14a = false;
if (WaitForResponseTimeout(CMD_ACK, &resp, 2000) == false) {
DropField();
failed_14a = true;
}
if ((!failed_14a) && resp.oldarg[0] != 0) {
// select with no disconnect and set frameLength
int selres = SelectCard14443A_4(false, NULL);
if (selres == PM3_SUCCESS) {
SetISODEPState(ISODEP_NFCA);
return PM3_SUCCESS;
}
PrintAndLogEx(DEBUG, "No 14a tag spotted, trying 14b");
// If not 14a, try to 14b
iso14b_raw_cmd_t packet = {
.flags = (ISO14B_CONNECT | ISO14B_SELECT_STD),
.timeout = 0,
.rawlen = 0,
};
clearCommandBuffer();
SendCommandNG(CMD_HF_ISO14443B_COMMAND, (uint8_t *)&packet, sizeof(iso14b_raw_cmd_t));
if (WaitForResponseTimeout(CMD_HF_ISO14443B_COMMAND, &resp, 2000) == false) {
PrintAndLogEx(DEBUG, "Timeout, no 14b tag spotted, exiting");
return PM3_ETIMEOUT;
selres = select_card_14443b_4(false, NULL);
if (selres == PM3_SUCCESS) {
SetISODEPState(ISODEP_NFCB);
return PM3_SUCCESS;
}
if (resp.oldarg[0] != 0) {
PrintAndLogEx(DEBUG, "No 14b tag spotted, failed to find any tag.");
return PM3_ENODATA;
}
SetISODEPState(ISODEP_NFCB);
return PM3_SUCCESS;
PrintAndLogEx(DEBUG, "No 14b tag spotted, failed to find any tag.");
return selres;
}
int Iso7816ExchangeEx(Iso7816CommandChannel channel, bool ActivateField, bool LeaveFieldON, sAPDU apdu, bool includeLe, uint16_t Le, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw) {