From 1c62fc83e6f18077ffb5f486f5d34ed28dfbad11 Mon Sep 17 00:00:00 2001 From: Romain Tartiere Date: Sat, 9 Jan 2010 01:37:36 +0000 Subject: [PATCH] Handle the special case of sector #0 when formatting (sector is read-only). --- libfreefare/mifare_classic.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libfreefare/mifare_classic.c b/libfreefare/mifare_classic.c index 99164e4..4a870cb 100644 --- a/libfreefare/mifare_classic.c +++ b/libfreefare/mifare_classic.c @@ -666,7 +666,7 @@ mifare_classic_format_sector (MifareClassicTag tag, const MifareSectorNumber sec /* * Check that the current key allow us to rewrite data and trailer blocks. */ - if ((mifare_classic_get_data_block_permission(tag, first_sector_block, MCAB_W, tag->last_authentication_key_type) != 1) || + if (((sector != 0) && (mifare_classic_get_data_block_permission(tag, first_sector_block, MCAB_W, tag->last_authentication_key_type) != 1)) || (mifare_classic_get_data_block_permission(tag, first_sector_block + 1, MCAB_W, tag->last_authentication_key_type) != 1) || (mifare_classic_get_data_block_permission(tag, first_sector_block + 2, MCAB_W, tag->last_authentication_key_type) != 1) || (mifare_classic_get_trailer_block_permission(tag, first_sector_block + 3, MCAB_WRITE_KEYA, tag->last_authentication_key_type) != 1) || @@ -686,7 +686,7 @@ mifare_classic_format_sector (MifareClassicTag tag, const MifareSectorNumber sec 0xff, 0xff, 0xff, 0xff, 0xff, 0xff /* Key B */ }; - if ((mifare_classic_write (tag, first_sector_block, empty_data_block) < 0) || + if (((sector != 0) && (mifare_classic_write (tag, first_sector_block, empty_data_block) < 0)) || (mifare_classic_write (tag, first_sector_block + 1, empty_data_block) < 0) || (mifare_classic_write (tag, first_sector_block + 2, empty_data_block) < 0) || (mifare_classic_write (tag, first_sector_block + 3, default_trailer_block) < 0)) {