fixed bug in CmdHF14ACmdRaw: if we cant select we send command anyway...

This commit is contained in:
merlokk 2017-10-30 17:58:43 +02:00
commit f1a983a330
2 changed files with 28 additions and 9 deletions

View file

@ -1910,6 +1910,7 @@ void ReaderIso14443a(UsbCommand *c)
uint32_t arg0 = 0; uint32_t arg0 = 0;
byte_t buf[USB_CMD_DATA_SIZE]; byte_t buf[USB_CMD_DATA_SIZE];
uint8_t par[MAX_PARITY_SIZE]; uint8_t par[MAX_PARITY_SIZE];
bool cantSELECT = false;
if(param & ISO14A_CONNECT) { if(param & ISO14A_CONNECT) {
clear_trace(); clear_trace();
@ -1922,11 +1923,19 @@ void ReaderIso14443a(UsbCommand *c)
} }
if(param & ISO14A_CONNECT) { if(param & ISO14A_CONNECT) {
LED_A_ON();
clear_trace();
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN); iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
if(!(param & ISO14A_NO_SELECT)) { if(!(param & ISO14A_NO_SELECT)) {
iso14a_card_select_t *card = (iso14a_card_select_t*)buf; iso14a_card_select_t *card = (iso14a_card_select_t*)buf;
arg0 = iso14443a_select_card(NULL, card, NULL, true, 0, param & ISO14A_NO_RATS); arg0 = iso14443a_select_card(NULL, card, NULL, true, 0, param & ISO14A_NO_RATS);
// if we cant select then we cant send data
cantSELECT = (arg0 != 1);
LED_B_ON();
cmd_send(CMD_ACK,arg0,card->uidlen,0,buf,sizeof(iso14a_card_select_t)); cmd_send(CMD_ACK,arg0,card->uidlen,0,buf,sizeof(iso14a_card_select_t));
LED_B_OFF();
} }
} }
@ -1934,12 +1943,14 @@ void ReaderIso14443a(UsbCommand *c)
iso14a_set_timeout(timeout); iso14a_set_timeout(timeout);
} }
if(param & ISO14A_APDU) { if(param & ISO14A_APDU && !cantSELECT) {
arg0 = iso14_apdu(cmd, len, buf); arg0 = iso14_apdu(cmd, len, buf);
LED_B_ON();
cmd_send(CMD_ACK,arg0,0,0,buf,sizeof(buf)); cmd_send(CMD_ACK,arg0,0,0,buf,sizeof(buf));
LED_B_OFF();
} }
if(param & ISO14A_RAW) { if(param & ISO14A_RAW && !cantSELECT) {
if(param & ISO14A_APPEND_CRC) { if(param & ISO14A_APPEND_CRC) {
if(param & ISO14A_TOPAZMODE) { if(param & ISO14A_TOPAZMODE) {
AppendCrc14443b(cmd,len); AppendCrc14443b(cmd,len);
@ -1975,7 +1986,10 @@ void ReaderIso14443a(UsbCommand *c)
} }
} }
arg0 = ReaderReceive(buf, par); arg0 = ReaderReceive(buf, par);
LED_B_ON();
cmd_send(CMD_ACK,arg0,0,0,buf,sizeof(buf)); cmd_send(CMD_ACK,arg0,0,0,buf,sizeof(buf));
LED_B_OFF();
} }
if(param & ISO14A_REQUEST_TRIGGER) { if(param & ISO14A_REQUEST_TRIGGER) {

View file

@ -29,7 +29,7 @@
#include "mifarehost.h" #include "mifarehost.h"
static int CmdHelp(const char *Cmd); static int CmdHelp(const char *Cmd);
static void waitCmd(uint8_t iLen); static int waitCmd(uint8_t iLen);
// structure and database for uid -> tagtype lookups // structure and database for uid -> tagtype lookups
typedef struct { typedef struct {
@ -656,6 +656,8 @@ int CmdHF14AAPDU(const char *cmd) {
if (activateField) { if (activateField) {
if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500))
return 2; return 2;
if (resp.arg[0] != 1)
return 2;
} }
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
@ -845,17 +847,17 @@ int CmdHF14ACmdRaw(const char *cmd) {
SendCommand(&c); SendCommand(&c);
if (reply) { if (reply) {
if(active_select) int res = 0;
waitCmd(1); if (active_select)
if(datalen>0) res = waitCmd(1);
if (!res && datalen > 0)
waitCmd(0); waitCmd(0);
} // if reply } // if reply
return 0; return 0;
} }
static void waitCmd(uint8_t iSelect) static int waitCmd(uint8_t iSelect) {
{
uint8_t *recv; uint8_t *recv;
UsbCommand resp; UsbCommand resp;
char *hexout; char *hexout;
@ -865,7 +867,7 @@ static void waitCmd(uint8_t iSelect)
uint8_t iLen = iSelect ? resp.arg[1] : resp.arg[0]; uint8_t iLen = iSelect ? resp.arg[1] : resp.arg[0];
PrintAndLog("received %i octets", iLen); PrintAndLog("received %i octets", iLen);
if(!iLen) if(!iLen)
return; return 1;
hexout = (char *)malloc(iLen * 3 + 1); hexout = (char *)malloc(iLen * 3 + 1);
if (hexout != NULL) { if (hexout != NULL) {
for (int i = 0; i < iLen; i++) { // data in hex for (int i = 0; i < iLen; i++) { // data in hex
@ -875,10 +877,13 @@ static void waitCmd(uint8_t iSelect)
free(hexout); free(hexout);
} else { } else {
PrintAndLog("malloc failed your client has low memory?"); PrintAndLog("malloc failed your client has low memory?");
return 2;
} }
} else { } else {
PrintAndLog("timeout while waiting for reply."); PrintAndLog("timeout while waiting for reply.");
return 3;
} }
return 0;
} }
static command_t CommandTable[] = static command_t CommandTable[] =