Skip to content

Commit 787382f

Browse files
authored
Merge pull request #394 from lab-401/master-4k-magic
Adding support for 4K magic cards
2 parents b7ae7cb + 6c44c20 commit 787382f

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

Diff for: examples/nfc-mfsetuid.c

+16-6
Original file line numberDiff line numberDiff line change
@@ -365,13 +365,23 @@ main(int argc, char *argv[])
365365
// now reset UID
366366
iso14443a_crc_append(abtHalt, 2);
367367
transmit_bytes(abtHalt, 4);
368-
transmit_bits(abtUnlock1, 7);
369-
if (format) {
370-
transmit_bytes(abtWipe, 1);
371-
transmit_bytes(abtHalt, 4);
372-
transmit_bits(abtUnlock1, 7);
368+
369+
if (!transmit_bits(abtUnlock1, 7)) {
370+
printf("Warning: Unlock command [1/2]: failed / not acknowledged.\n");
371+
} else {
372+
if (format) {
373+
transmit_bytes(abtWipe, 1);
374+
transmit_bytes(abtHalt, 4);
375+
transmit_bits(abtUnlock1, 7);
376+
}
377+
378+
if (transmit_bytes(abtUnlock2, 1)) {
379+
printf("Card unlocked\n");
380+
} else {
381+
printf("Warning: Unlock command [2/2]: failed / not acknowledged.\n");
382+
}
373383
}
374-
transmit_bytes(abtUnlock2, 1);
384+
375385
transmit_bytes(abtWrite, 4);
376386
transmit_bytes(abtData, 18);
377387
if (format) {

Diff for: utils/nfc-mfclassic.c

+10-7
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ static bool bForceKeyFile;
7070
static bool bTolerateFailures;
7171
static bool bFormatCard;
7272
static bool magic2 = false;
73+
static bool unlocked = false;
7374
static uint8_t uiBlocks;
7475
static uint8_t keys[] = {
7576
0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
@@ -248,12 +249,14 @@ unlock_card(void)
248249
transmit_bytes(abtHalt, 4);
249250
// now send unlock
250251
if (!transmit_bits(abtUnlock1, 7)) {
251-
printf("unlock failure!\n");
252-
return false;
253-
}
254-
if (!transmit_bytes(abtUnlock2, 1)) {
255-
printf("unlock failure!\n");
256-
return false;
252+
printf("Warning: Unlock command [1/2]: failed / not acknowledged.\n");
253+
} else {
254+
if (transmit_bytes(abtUnlock2, 1)) {
255+
printf("Card unlocked\n");
256+
unlocked = true;
257+
} else {
258+
printf("Warning: Unlock command [2/2]: failed / not acknowledged.\n");
259+
}
257260
}
258261

259262
// reset reader
@@ -668,7 +671,7 @@ main(int argc, const char *argv[])
668671
print_nfc_target(&nt, false);
669672

670673
// Guessing size
671-
if ((nt.nti.nai.abtAtqa[1] & 0x02) == 0x02)
674+
if ((nt.nti.nai.abtAtqa[1] & 0x02) == 0x02 || nt.nti.nai.btSak == 0x18)
672675
// 4K
673676
uiBlocks = 0xff;
674677
else if (nt.nti.nai.btSak == 0x09)

0 commit comments

Comments
 (0)