example/nfc-mfultralight: handle lock page writing
This commit is contained in:
parent
53c8917353
commit
1336c73e0c
1 changed files with 20 additions and 14 deletions
|
@ -104,30 +104,37 @@ static bool
|
||||||
write_card (void)
|
write_card (void)
|
||||||
{
|
{
|
||||||
uint32_t uiBlock = 0;
|
uint32_t uiBlock = 0;
|
||||||
int page = 0x4;
|
|
||||||
bool bFailure = false;
|
bool bFailure = false;
|
||||||
uint32_t uiWritenPages = 0;
|
uint32_t uiWritenPages = 0;
|
||||||
|
uint32_t uiSkippedPages;
|
||||||
|
|
||||||
char buffer[BUFSIZ];
|
char buffer[BUFSIZ];
|
||||||
bool write_otp;
|
bool write_otp;
|
||||||
|
bool write_lock;
|
||||||
|
|
||||||
printf ("Write OTP bytes ? [yN] ");
|
printf ("Write OTP bytes ? [yN] ");
|
||||||
fgets (buffer, BUFSIZ, stdin);
|
fgets (buffer, BUFSIZ, stdin);
|
||||||
write_otp = ((buffer[0] == 'y') || (buffer[0] == 'Y'));
|
write_otp = ((buffer[0] == 'y') || (buffer[0] == 'Y'));
|
||||||
|
printf ("Write Lock bytes ? [yN] ");
|
||||||
|
fgets (buffer, BUFSIZ, stdin);
|
||||||
|
write_lock = ((buffer[0] == 'y') || (buffer[0] == 'Y'));
|
||||||
|
|
||||||
/* We need to skip 3 first pages. */
|
|
||||||
printf ("Writing %d pages |", uiBlocks + 1);
|
printf ("Writing %d pages |", uiBlocks + 1);
|
||||||
printf ("sss");
|
/* We need to skip 2 first pages. */
|
||||||
|
printf ("ss");
|
||||||
|
uiSkippedPages = 2;
|
||||||
|
|
||||||
if (write_otp) {
|
for (int page = 0x2; page <= 0xF; page++) {
|
||||||
page = 0x3;
|
if ((page==0x2) && (!write_lock)) {
|
||||||
} else {
|
printf ("s");
|
||||||
/* If user don't want to write OTP, we skip 1 page more. */
|
uiSkippedPages++;
|
||||||
printf ("s");
|
continue;
|
||||||
page = 0x4;
|
}
|
||||||
}
|
if ((page==0x3) && (!write_otp)) {
|
||||||
|
printf ("s");
|
||||||
for (; page <= 0xF; page++) {
|
uiSkippedPages++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
// Show if the readout went well
|
// Show if the 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
|
||||||
|
@ -149,8 +156,7 @@ write_card (void)
|
||||||
print_success_or_failure (bFailure, &uiWritenPages);
|
print_success_or_failure (bFailure, &uiWritenPages);
|
||||||
}
|
}
|
||||||
printf ("|\n");
|
printf ("|\n");
|
||||||
printf ("Done, %d of %d pages written (%d first pages are skipped).\n", uiWritenPages, uiBlocks + 1,
|
printf ("Done, %d of %d pages written (%d pages skipped).\n", uiWritenPages, uiBlocks + 1, uiSkippedPages);
|
||||||
write_otp ? 3 : 4);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue