From fabdf4214a74134fe26e6980018fa59e5f0f9d14 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Mon, 9 Nov 2009 09:39:38 +0000 Subject: [PATCH] Fix Issue 46 and Issue 47. Many thanks to ud. --- src/examples/nfc-mfclassic.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/examples/nfc-mfclassic.c b/src/examples/nfc-mfclassic.c index 91910a2..eda3a64 100644 --- a/src/examples/nfc-mfclassic.c +++ b/src/examples/nfc-mfclassic.c @@ -70,7 +70,13 @@ bool is_trailer_block(uint32_t uiBlock) uint32_t get_trailer_block(uint32_t uiFirstBlock) { // Test if we are in the small or big sectors - if (uiFirstBlock<128) return uiFirstBlock+3; else return uiFirstBlock+15; + uint32_t trailer_block = 0; + if (uiFirstBlock < 128) { + trailer_block = uiFirstBlock + (3 - (uiFirstBlock % 4)); + } else { + trailer_block = uiFirstBlock + (15 - (uiFirstBlock % 16)); + } + return trailer_block; } bool authenticate(uint32_t uiBlock) @@ -252,7 +258,10 @@ bool write_card() memcpy(mp.mpd.abtData+10,mtDump.amb[uiBlock].mbt.abtKeyB,6); // Try to write the trailer - nfc_initiator_mifare_cmd(pdi,MC_WRITE,uiBlock,&mp); + if (nfc_initiator_mifare_cmd(pdi,MC_WRITE,uiBlock,&mp) == false) { + printf("failed to write trailer block %d \n", uiBlock); + bFailure = true; + } } else {