mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 21:03:48 -07:00
fix states and get rid of INS code in receive (that code checks by controller)
This commit is contained in:
parent
a759e94af0
commit
f32088e25c
2 changed files with 24 additions and 26 deletions
|
@ -306,7 +306,7 @@ static int smart_wait(uint8_t *data) {
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int smart_response(uint8_t apduINS, uint8_t *data) {
|
static int smart_response(uint8_t *data) {
|
||||||
|
|
||||||
int datalen = smart_wait(data);
|
int datalen = smart_wait(data);
|
||||||
bool needGetData = false;
|
bool needGetData = false;
|
||||||
|
@ -315,12 +315,6 @@ static int smart_response(uint8_t apduINS, uint8_t *data) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (datalen > 2 && data[0] != apduINS) {
|
|
||||||
PrintAndLogEx(ERR, "Card ACK error. len=0x%x data[0]=%02x", datalen, data[0]);
|
|
||||||
datalen = 0;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( data[datalen - 2] == 0x61 || data[datalen - 2] == 0x9F ) {
|
if ( data[datalen - 2] == 0x61 || data[datalen - 2] == 0x9F ) {
|
||||||
needGetData = true;
|
needGetData = true;
|
||||||
}
|
}
|
||||||
|
@ -340,21 +334,25 @@ static int smart_response(uint8_t apduINS, uint8_t *data) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (datalen > 2 && data[0] != ISO7816_GETSTATUS) {
|
// data wo ACK
|
||||||
|
if (datalen != len + 2) {
|
||||||
|
// data with ACK
|
||||||
|
if (datalen == len + 2 + 1) { // 2 - response, 1 - ACK
|
||||||
|
if (data[0] != ISO7816_GETSTATUS) {
|
||||||
PrintAndLogEx(ERR, "GetResponse ACK error. len=0x%x data[0]=%02x", len, data[0]);
|
PrintAndLogEx(ERR, "GetResponse ACK error. len=0x%x data[0]=%02x", len, data[0]);
|
||||||
datalen = 0;
|
datalen = 0;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (datalen != len + 2 + 1) { // 2 - response, 1 - ACK
|
datalen--;
|
||||||
|
memmove(data, &data[1], datalen);
|
||||||
|
} else {
|
||||||
|
// wrong length
|
||||||
PrintAndLogEx(WARNING, "GetResponse wrong length. Must be: 0x%02x but: 0x%02x", len, datalen - 3);
|
PrintAndLogEx(WARNING, "GetResponse wrong length. Must be: 0x%02x but: 0x%02x", len, datalen - 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (datalen > 2) {
|
|
||||||
datalen--;
|
|
||||||
memmove(data, &data[1], datalen);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
return datalen;
|
return datalen;
|
||||||
}
|
}
|
||||||
|
@ -441,7 +439,7 @@ int CmdSmartRaw(const char *Cmd) {
|
||||||
if ( !buf )
|
if ( !buf )
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
int len = smart_response(data[1], buf);
|
int len = smart_response(buf);
|
||||||
if ( len < 0 ) {
|
if ( len < 0 ) {
|
||||||
free(buf);
|
free(buf);
|
||||||
return 2;
|
return 2;
|
||||||
|
@ -453,7 +451,7 @@ int CmdSmartRaw(const char *Cmd) {
|
||||||
memcpy(c.d.asBytes, data, sizeof(data) );
|
memcpy(c.d.asBytes, data, sizeof(data) );
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
len = smart_response(data[1], buf);
|
len = smart_response(buf);
|
||||||
|
|
||||||
data[4] = 0;
|
data[4] = 0;
|
||||||
}
|
}
|
||||||
|
@ -481,7 +479,7 @@ int ExchangeAPDUSC(uint8_t *datain, int datainlen, bool activateCard, bool leave
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
int len = smart_response(datain[1], dataout);
|
int len = smart_response(dataout);
|
||||||
|
|
||||||
if ( len < 0 ) {
|
if ( len < 0 ) {
|
||||||
return 2;
|
return 2;
|
||||||
|
@ -501,7 +499,7 @@ int ExchangeAPDUSC(uint8_t *datain, int datainlen, bool activateCard, bool leave
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c2);
|
SendCommand(&c2);
|
||||||
|
|
||||||
len = smart_response(datain[1], dataout);
|
len = smart_response(dataout);
|
||||||
}
|
}
|
||||||
|
|
||||||
*dataoutlen = len;
|
*dataoutlen = len;
|
||||||
|
@ -822,7 +820,7 @@ int CmdSmartBruteforceSFI(const char *Cmd) {
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
smart_response(data[1], buf);
|
smart_response(buf);
|
||||||
|
|
||||||
// if 0x6C
|
// if 0x6C
|
||||||
if ( buf[0] == 0x6C ) {
|
if ( buf[0] == 0x6C ) {
|
||||||
|
@ -831,7 +829,7 @@ int CmdSmartBruteforceSFI(const char *Cmd) {
|
||||||
memcpy(c.d.asBytes, data, sizeof(data) );
|
memcpy(c.d.asBytes, data, sizeof(data) );
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
uint8_t len = smart_response(data[1], buf);
|
uint8_t len = smart_response(buf);
|
||||||
|
|
||||||
// TLV decoder
|
// TLV decoder
|
||||||
if (len > 4)
|
if (len > 4)
|
||||||
|
|
|
@ -109,7 +109,7 @@ typedef enum SMARTCARD_COMMAND {
|
||||||
SC_CONNECT = (1 << 0),
|
SC_CONNECT = (1 << 0),
|
||||||
SC_NO_DISCONNECT = (1 << 1),
|
SC_NO_DISCONNECT = (1 << 1),
|
||||||
SC_RAW = (1 << 2),
|
SC_RAW = (1 << 2),
|
||||||
SC_SELECT = (1 << 3)
|
SC_SELECT = (1 << 3),
|
||||||
SC_RAW_T0 = (1 << 4),
|
SC_RAW_T0 = (1 << 4),
|
||||||
} smartcard_command_t;
|
} smartcard_command_t;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue