Add support for MIFARE Classic 4K.

- New mifare_classic_first_sector_block(), mifare_classic_last_sector_block() functions to ease detection of sectors boundaries;
  - New unit tests for mifare_classic_first_sector_block() and mifare_classic_last_sector_block();
  - Start to update the API for consistently using blocks and not mixing blocks and sectors with mifare_classic_*() functions;
  - Update the mifare-classic-format(1) example to handle MIFARE Classic 1k and 4k.

Many thanks to Johann Dantant from SpringCard for giving me MIFARE Classic 4k cards.
This commit is contained in:
Romain Tartiere 2010-02-23 02:12:18 +00:00
parent 24a9198f41
commit 5f7f8ffe2a
5 changed files with 151 additions and 57 deletions

View file

@ -21,6 +21,7 @@
#include <string.h>
#include <freefare.h>
#include "freefare_internal.h"
#include "mifare_classic_fixture.h"
@ -337,3 +338,22 @@ test_mifare_classic_get_uid (void)
free (uid);
}
void
test_mifare_classic_sector_boundaries (void)
{
cut_notify ("No MIFARE Classic target is required for this test");
for (int i=0; i < 32; i++) {
for (int j=0; j < 4; j++) {
cut_assert_equal_int (4 * i, mifare_classic_first_sector_block (4 * i), cut_message ("Wrong first block number for block %d", i));
cut_assert_equal_int (4 * i + 3, mifare_classic_last_sector_block (4 * i + j), cut_message ("Wrong last block number for block %d", i));
}
}
for (int i=0; i < 8; i++) {
for (int j=0; j < 16; j++) {
cut_assert_equal_int (128 + 16 * i, mifare_classic_first_sector_block (128 + 16 * i), cut_message ("Wrong last block number for block %d", i));
cut_assert_equal_int (128 + 16 * i + 15, mifare_classic_last_sector_block (128 + 16 * i + j), cut_message ("Wrong last block number for block %d", i));
}
}
}