uint32_t cuid, nt1, nt2, nttmp, nttest, ks1;\r
uint8_t par[1];\r
uint32_t target_nt[2], target_ks[2];\r
+ uint8_t target_nt_duplicate_count = 0;\r
\r
uint8_t par_array[4];\r
uint16_t ncount = 0;\r
\r
for (rtr = 0; rtr < 17; rtr++) {\r
\r
- // Test if the action was cancelled\r
- if(BUTTON_PRESS()) {\r
- isOK = -2;\r
- break;\r
- }\r
-\r
// prepare next select. No need to power down the card.\r
if(mifare_classic_halt(pcs, cuid)) {\r
if (MF_DBGLEVEL >= 1) Dbprintf("Nested: Halt error");\r
continue;\r
}\r
\r
+ // Test if the action was cancelled\r
+ if(BUTTON_PRESS()) {\r
+ isOK = -2;\r
+ break;\r
+ }\r
+\r
if(!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {\r
if (MF_DBGLEVEL >= 1) Dbprintf("Nested: Can't select card");\r
rtr--;\r
for(i=0; i < 2 && !isOK; i++) { // look for exactly two different nonces\r
\r
target_nt[i] = 0;\r
- while(target_nt[i] == 0) { // continue until we have an unambiguous nonce\r
+ while(target_nt[i] == 0 && !isOK) { // continue until we have an unambiguous nonce\r
\r
// prepare next select. No need to power down the card.\r
if(mifare_classic_halt(pcs, cuid)) {\r
continue;\r
}\r
\r
+ // break out of the loop on button press\r
+ if(BUTTON_PRESS()) {\r
+ isOK = -2;\r
+ break;\r
+ }\r
+\r
if(!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {\r
if (MF_DBGLEVEL >= 1) Dbprintf("Nested: Can't select card");\r
continue;\r
- };\r
+ }\r
\r
auth1_time = 0;\r
if(mifare_classic_authex(pcs, cuid, blockNo, keyType, ui64Key, AUTH_FIRST, &nt1, &auth1_time)) {\r
if (MF_DBGLEVEL >= 1) Dbprintf("Nested: Auth1 error");\r
continue;\r
- };\r
+ }\r
\r
// nested authentication\r
auth2_time = auth1_time + delta_time;\r
if (len != 4) {\r
if (MF_DBGLEVEL >= 1) Dbprintf("Nested: Auth2 error len=%d", len);\r
continue;\r
- };\r
+ }\r
\r
nt2 = bytes_to_num(receivedAnswer, 4);\r
if (MF_DBGLEVEL >= 3) Dbprintf("Nonce#%d: Testing nt1=%08x nt2enc=%08x nt2par=%02x", i+1, nt1, nt2, par[0]);\r
target_ks[i] = ks1;\r
ncount++;\r
if (i == 1 && target_nt[1] == target_nt[0]) { // we need two different nonces\r
- target_nt[i] = 0;\r
+ if( ++target_nt_duplicate_count >= NESTED_MAX_TRIES ) { // unable to get a 2nd nonce after NESTED_MAX_TRIES tries, probably a fixed nonce\r
+ if (MF_DBGLEVEL >= 2) Dbprintf("Nonce#2: cannot get nonce that != nonce#1, continuing anyway with single nonce! ntdist=%d", j);\r
+ break;\r
+ }\r
+\r
+ target_nt[1] = 0;\r
if (MF_DBGLEVEL >= 3) Dbprintf("Nonce#2: dismissed (= nonce#1), ntdist=%d", j);\r
break;\r
}\r
int res = MifareMultisectorChk(datain, keyCount, sectorCnt, keyType, OLD_MF_DBGLEVEL, &keyIndex);\r
\r
if (res >= 0) {\r
- cmd_send(CMD_ACK, 1, 0, 0, keyIndex, 80);\r
+ cmd_send(CMD_ACK, 1, res, 0, keyIndex, 80);\r
} else {\r
- cmd_send(CMD_ACK, 0, 0, 0, NULL, 0);\r
+ cmd_send(CMD_ACK, 0, res, 0, NULL, 0);\r
}\r
} else { \r
int res = MifareChkBlockKeys(datain, keyCount, blockNo, keyType, OLD_MF_DBGLEVEL);\r
\r
if (res > 0) {\r
- cmd_send(CMD_ACK, 1, 0, 0, datain + (res - 1) * 6, 6);\r
+ cmd_send(CMD_ACK, 1, res, 0, datain + (res - 1) * 6, 6);\r
} else {\r
- cmd_send(CMD_ACK, 0, 0, 0, NULL, 0);\r
+ cmd_send(CMD_ACK, 0, res, 0, NULL, 0);\r
}\r
}\r
\r