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:
parent
2fd329e530
commit
74bc239a71
13 changed files with 378 additions and 282 deletions
|
|
@ -21,8 +21,8 @@
|
|||
#include <freefare.h>
|
||||
|
||||
static nfc_device_t *device = NULL;
|
||||
static MifareClassicTag *tags = NULL;
|
||||
MifareClassicTag tag = NULL;
|
||||
static MifareTag *tags = NULL;
|
||||
MifareTag tag = NULL;
|
||||
|
||||
void
|
||||
setup ()
|
||||
|
|
@ -32,12 +32,19 @@ setup ()
|
|||
device = nfc_connect (NULL);
|
||||
cut_assert_not_null (device, cut_message ("No device found"));
|
||||
|
||||
tags = mifare_classic_get_tags (device);
|
||||
cut_assert_not_null (tags, cut_message ("mifare_classic_get_tags() failed"));
|
||||
tags = freefare_get_tags (device);
|
||||
cut_assert_not_null (tags, cut_message ("freefare_get_tags() failed"));
|
||||
|
||||
cut_assert_not_null (tags[0], cut_message ("No MIFARE Classic tag on NFC device"));
|
||||
tag = NULL;
|
||||
for (int i=0; tags[i]; i++) {
|
||||
if ((freefare_get_tag_type(tags[i]) == CLASSIC_1K) ||
|
||||
(freefare_get_tag_type(tags[i]) == CLASSIC_4K)) {
|
||||
tag = tags[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
tag = tags[0];
|
||||
cut_assert_not_null (tag, cut_message ("No MIFARE Classic tag on NFC device"));
|
||||
|
||||
res = mifare_classic_connect (tag);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_classic_connect() failed"));
|
||||
|
|
@ -50,7 +57,7 @@ teardown ()
|
|||
mifare_classic_disconnect (tag);
|
||||
|
||||
if (tags)
|
||||
mifare_classic_free_tags (tags);
|
||||
freefare_free_tags (tags);
|
||||
|
||||
if (device)
|
||||
nfc_disconnect (device);
|
||||
|
|
|
|||
|
|
@ -17,4 +17,4 @@
|
|||
* $Id$
|
||||
*/
|
||||
|
||||
extern MifareClassicTag tag;
|
||||
extern MifareTag tag;
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@
|
|||
#include <freefare.h>
|
||||
|
||||
static nfc_device_t *device = NULL;
|
||||
static MifareUltralightTag *tags = NULL;
|
||||
MifareUltralightTag tag = NULL;
|
||||
static MifareTag *tags = NULL;
|
||||
MifareTag tag = NULL;
|
||||
|
||||
void
|
||||
setup ()
|
||||
|
|
@ -32,12 +32,18 @@ setup ()
|
|||
device = nfc_connect (NULL);
|
||||
cut_assert_not_null (device, cut_message ("No device found"));
|
||||
|
||||
tags = mifare_ultralight_get_tags (device);
|
||||
cut_assert_not_null (tags, cut_message ("Error enumerating NFC tags"));
|
||||
tags = freefare_get_tags (device);
|
||||
cut_assert_not_null (tags, cut_message ("freefare_get_tags() failed"));
|
||||
|
||||
cut_assert_not_null (tags[0], cut_message ("No MIFARE CLassic tag on NFC device"));
|
||||
tag = NULL;
|
||||
for (int i=0; tags[i]; i++) {
|
||||
if (freefare_get_tag_type(tags[i]) == ULTRALIGHT) {
|
||||
tag = tags[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
tag = tags[0];
|
||||
cut_assert_not_null (tag, cut_message ("No MIFARE UltraLight tag on NFC device"));
|
||||
|
||||
res = mifare_ultralight_connect (tag);
|
||||
cut_assert_equal_int (0, res, cut_message ("mifare_ultralight_connect() failed"));
|
||||
|
|
@ -50,7 +56,7 @@ teardown ()
|
|||
mifare_ultralight_disconnect (tag);
|
||||
|
||||
if (tags)
|
||||
mifare_ultralight_free_tags (tags);
|
||||
freefare_free_tags (tags);
|
||||
|
||||
if (device)
|
||||
nfc_disconnect (device);
|
||||
|
|
|
|||
|
|
@ -17,4 +17,4 @@
|
|||
* $Id$
|
||||
*/
|
||||
|
||||
extern MifareUltralightTag tag;
|
||||
extern MifareTag tag;
|
||||
|
|
|
|||
|
|
@ -98,10 +98,10 @@ test_mifare_ultralight_cache (void)
|
|||
|
||||
/* Check cached pages consistency */
|
||||
for (int i = 0; i <= 3; i++) {
|
||||
cut_assert_equal_int (1, tag->cached_pages[i], cut_message ("Wrong page cache value for tag->cached_pages[%d]", i));
|
||||
cut_assert_equal_int (1, MIFARE_ULTRALIGHT(tag)->cached_pages[i], cut_message ("Wrong page cache value for tag->cached_pages[%d]", i));
|
||||
}
|
||||
for (int i = 4; i < MIFARE_ULTRALIGHT_PAGE_COUNT; i++) {
|
||||
cut_assert_equal_int (0, tag->cached_pages[i], cut_message ("Wrong page cache value for tag->cached_pages[%d]", i));
|
||||
cut_assert_equal_int (0, MIFARE_ULTRALIGHT(tag)->cached_pages[i], cut_message ("Wrong page cache value for tag->cached_pages[%d]", i));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -133,13 +133,13 @@ test_mifare_ultralight_cache_wrap (void)
|
|||
|
||||
/* Check cached pages consistency */
|
||||
for (int i = 0; i <= 2; i++) {
|
||||
cut_assert_equal_int (1, tag->cached_pages[i], cut_message ("Wrong page cache value for tag->cached_pages[%d]", i));
|
||||
cut_assert_equal_int (1, MIFARE_ULTRALIGHT(tag)->cached_pages[i], cut_message ("Wrong page cache value for tag->cached_pages[%d]", i));
|
||||
}
|
||||
for (int i = 3; i <= 14; i++) {
|
||||
cut_assert_equal_int (0, tag->cached_pages[i], cut_message ("Wrong page cache value for tag->cached_pages[%d]", i));
|
||||
cut_assert_equal_int (0, MIFARE_ULTRALIGHT(tag)->cached_pages[i], cut_message ("Wrong page cache value for tag->cached_pages[%d]", i));
|
||||
}
|
||||
for (int i = 15; i < MIFARE_ULTRALIGHT_PAGE_COUNT; i++) {
|
||||
cut_assert_equal_int (1, tag->cached_pages[i], cut_message ("Wrong page cache value for tag->cached_pages[%d]", i));
|
||||
cut_assert_equal_int (1, MIFARE_ULTRALIGHT(tag)->cached_pages[i], cut_message ("Wrong page cache value for tag->cached_pages[%d]", i));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue