Abstract tag manipulation functions.

- Factorize Mifare*Tag as MifareTag;
  - Factorize mifare_*_get_tags() / mifare_*_free_tags() as freefare_get_tags() and freefare_free_tags();
  - Add a new freefare_get_tag_type() function to get a tag type;
  - Update regression test suite;
  - Update example.

While this is a major change that basically change all the API, programs using libfreefare should be easily modified by replacing any Mifare*Tag variable by a generic MifareTag one, adding a few lines of code to check the target's type using freefare_get_tag_type(), and changing any call to mifare_*_get_tags() / mifare_*_free_tags() by the generic freefare_get_tags() and freefare_free_tags() functions.
This commit is contained in:
Romain Tartiere 2010-02-19 14:50:18 +00:00
parent 2fd329e530
commit 74bc239a71
13 changed files with 378 additions and 282 deletions

View file

@ -40,7 +40,7 @@ MifareClassicKey default_keys[] = {
};
int
try_format_sector (MifareClassicTag tag, MifareSectorNumber sector)
try_format_sector (MifareTag tag, MifareSectorNumber sector)
{
for (int i = 0; i < (sizeof (default_keys) / sizeof (MifareClassicKey)); i++) {
printf (" s=%d i=%d \n", sector, i);
@ -73,27 +73,32 @@ main(int argc, char *argv[])
{
int error = 0;
nfc_device_t *device = NULL;
MifareClassicTag *tags = NULL;
MifareClassicTag *tag = NULL;
MifareTag *tags = NULL;
MifareTag *tag = NULL;
device = nfc_connect (NULL);
if (!device)
errx (EXIT_FAILURE, "No NFC device found.");
tags = mifare_classic_get_tags (device);
tags = freefare_get_tags (device);
if (!tags) {
nfc_disconnect (device);
errx (EXIT_FAILURE, "Error listing MIFARE classic tag.");
}
if (!tags[0]) {
mifare_classic_free_tags (tags);
freefare_free_tags (tags);
nfc_disconnect (device);
errx (EXIT_FAILURE, "No MIFARE classic tag on NFC device.");
errx (EXIT_FAILURE, "No MIFARE tag on NFC device.");
}
tag = tags;
if ((freefare_get_tag_type (*tag) != CLASSIC_1K) &&
(freefare_get_tag_type (*tag) != CLASSIC_4K)) {
errx (EXIT_FAILURE, "Not a MIFARE Classic tag.");
}
while (*tag) {
char *tag_uid = mifare_classic_get_uid (*tag);
@ -111,7 +116,7 @@ main(int argc, char *argv[])
tag++;
}
mifare_classic_free_tags (tags);
freefare_free_tags (tags);
nfc_disconnect (device);
exit (error);