nfc-mfultralight: fix failed read reporting and add failed pages count
This commit is contained in:
parent
bf31594410
commit
c51caf424a
1 changed files with 18 additions and 16 deletions
|
@ -5,11 +5,11 @@
|
||||||
* Copyright (C) 2009 Roel Verdult
|
* Copyright (C) 2009 Roel Verdult
|
||||||
* Copyright (C) 2009-2013 Romuald Conty
|
* Copyright (C) 2009-2013 Romuald Conty
|
||||||
* Copyright (C) 2010-2012 Romain Tartière
|
* Copyright (C) 2010-2012 Romain Tartière
|
||||||
* Copyright (C) 2010-2013 Philippe Teuwen
|
* Copyright (C) 2010-2017 Philippe Teuwen
|
||||||
* Copyright (C) 2012-2013 Ludovic Rousseau
|
* Copyright (C) 2012-2013 Ludovic Rousseau
|
||||||
* See AUTHORS file for a more comprehensive list of contributors.
|
* See AUTHORS file for a more comprehensive list of contributors.
|
||||||
* Additional contributors of this file:
|
* Additional contributors of this file:
|
||||||
* Copyright (C) 2013 Adam Laurie
|
* Copyright (C) 2013-2017 Adam Laurie
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
@ -86,11 +86,13 @@ static const nfc_modulation nmMifare = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_success_or_failure(bool bFailure, uint32_t *uiCounter)
|
print_success_or_failure(bool bFailure, uint32_t *uiOkCounter, uint32_t *uiFailedCounter)
|
||||||
{
|
{
|
||||||
printf("%c", (bFailure) ? 'x' : '.');
|
printf("%c", (bFailure) ? 'f' : '.');
|
||||||
if (uiCounter)
|
if (uiOkCounter)
|
||||||
*uiCounter += (bFailure) ? 0 : 1;
|
*uiOkCounter += (bFailure) ? 0 : 1;
|
||||||
|
if (uiFailedCounter)
|
||||||
|
*uiFailedCounter += (bFailure) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
@ -99,6 +101,7 @@ read_card(void)
|
||||||
uint32_t page;
|
uint32_t page;
|
||||||
bool bFailure = false;
|
bool bFailure = false;
|
||||||
uint32_t uiReadPages = 0;
|
uint32_t uiReadPages = 0;
|
||||||
|
uint32_t uiFailedPages = 0;
|
||||||
|
|
||||||
printf("Reading %d pages |", uiBlocks + 1);
|
printf("Reading %d pages |", uiBlocks + 1);
|
||||||
|
|
||||||
|
@ -108,16 +111,15 @@ read_card(void)
|
||||||
memcpy(mtDump.amb[page / 4].mbd.abtData, mp.mpd.abtData, 16);
|
memcpy(mtDump.amb[page / 4].mbd.abtData, mp.mpd.abtData, 16);
|
||||||
} else {
|
} else {
|
||||||
bFailure = true;
|
bFailure = true;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print_success_or_failure(bFailure, &uiReadPages);
|
print_success_or_failure(bFailure, &uiReadPages, &uiFailedPages);
|
||||||
print_success_or_failure(bFailure, &uiReadPages);
|
print_success_or_failure(bFailure, &uiReadPages, &uiFailedPages);
|
||||||
print_success_or_failure(bFailure, &uiReadPages);
|
print_success_or_failure(bFailure, &uiReadPages, &uiFailedPages);
|
||||||
print_success_or_failure(bFailure, &uiReadPages);
|
print_success_or_failure(bFailure, &uiReadPages, &uiFailedPages);
|
||||||
}
|
}
|
||||||
printf("|\n");
|
printf("|\n");
|
||||||
printf("Done, %d of %d pages read.\n", uiReadPages, uiBlocks + 1);
|
printf("Done, %d of %d pages read (%d pages failed).\n", uiReadPages, uiBlocks + 1, uiFailedPages);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
return (!bFailure);
|
return (!bFailure);
|
||||||
|
@ -237,6 +239,7 @@ write_card(bool write_otp, bool write_lock, bool write_uid)
|
||||||
bool bFailure = false;
|
bool bFailure = false;
|
||||||
uint32_t uiWrittenPages = 0;
|
uint32_t uiWrittenPages = 0;
|
||||||
uint32_t uiSkippedPages = 0;
|
uint32_t uiSkippedPages = 0;
|
||||||
|
uint32_t uiFailedPages = 0;
|
||||||
|
|
||||||
char buffer[BUFSIZ];
|
char buffer[BUFSIZ];
|
||||||
|
|
||||||
|
@ -287,7 +290,7 @@ write_card(bool write_otp, bool write_lock, bool write_uid)
|
||||||
uiSkippedPages++;
|
uiSkippedPages++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Show if the readout went well
|
// Check if the previous readout went well
|
||||||
if (bFailure) {
|
if (bFailure) {
|
||||||
// When a failure occured we need to redo the anti-collision
|
// When a failure occured we need to redo the anti-collision
|
||||||
if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) <= 0) {
|
if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) <= 0) {
|
||||||
|
@ -305,11 +308,10 @@ write_card(bool write_otp, bool write_lock, bool write_uid)
|
||||||
memset(mp.mpd.abtData + 4, 0, 12);
|
memset(mp.mpd.abtData + 4, 0, 12);
|
||||||
if (!nfc_initiator_mifare_cmd(pnd, MC_WRITE, page, &mp))
|
if (!nfc_initiator_mifare_cmd(pnd, MC_WRITE, page, &mp))
|
||||||
bFailure = true;
|
bFailure = true;
|
||||||
|
print_success_or_failure(bFailure, &uiWrittenPages, &uiFailedPages);
|
||||||
print_success_or_failure(bFailure, &uiWrittenPages);
|
|
||||||
}
|
}
|
||||||
printf("|\n");
|
printf("|\n");
|
||||||
printf("Done, %d of %d pages written (%d pages skipped).\n", uiWrittenPages, uiBlocks + 1, uiSkippedPages);
|
printf("Done, %d of %d pages written (%d pages skipped, %d pages failed).\n", uiWrittenPages, uiBlocks + 1, uiSkippedPages, uiFailedPages);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue