fix emv search behavior

(taken from PRs 261 and 262 by @merlokk on https://github.com/RfidResearchGroup/proxmark3)
+ whitespace fixes
This commit is contained in:
pwpiwi 2019-08-01 10:58:22 -04:00 committed by GitHub
commit ca24170fd4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -290,7 +290,7 @@ struct tlvdb *GetdCVVRawFromTrack2(const struct tlv *track2) {
int EMVExchangeEx(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON, uint8_t *apdu, int apdu_len, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv)
{
*ResultLen = 0;
if (sw) *sw = 0;
if (sw) *sw = 0;
uint16_t isw = 0;
int res = 0;
@ -579,14 +579,16 @@ int EMVSearch(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON,
int retrycnt = 0;
for(int i = 0; i < AIDlistLen; i ++) {
param_gethex_to_eol(AIDlist[i].aid, 0, aidbuf, sizeof(aidbuf), &aidlen);
res = EMVSelect(channel, (i == 0) ? ActivateField : false, (i == AIDlistLen - 1) ? LeaveFieldON : true, aidbuf, aidlen, data, sizeof(data), &datalen, &sw, tlv);
res = EMVSelect(channel, (i == 0) ? ActivateField : false, true, aidbuf, aidlen, data, sizeof(data), &datalen, &sw, tlv);
// retry if error and not returned sw error
if (res && res != 5) {
if (++retrycnt < 3){
i--;
} else {
// (1) - card select error, proxmark error OR (200) - result length = 0
if (res == 1 || res == 200) {
// (1) - card select error, (4) reply timeout, (200) - result length = 0
if (res == 1 || res == 4 || res == 200) {
if (!LeaveFieldON)
DropFieldEx(channel);
PrintAndLogEx(WARNING, "Exit...");
return 1;
}
@ -610,6 +612,9 @@ int EMVSearch(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON,
}
}
if (!LeaveFieldON)
DropFieldEx(channel);
return 0;
}
@ -790,7 +795,7 @@ int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv) {
}
const struct tlv *sda_tlv = tlvdb_get(tlv, 0x21, NULL);
/* if (!sda_tlv || sda_tlv->len < 1) { it may be 0!!!!
/* if (!sda_tlv || sda_tlv->len < 1) { it may be 0!!!!
emv_pk_free(pk);
PrintAndLogEx(WARNING, "Error: Can't find input list for Offline Data Authentication. Exit.");
return 3;