diff --git a/HACKING b/HACKING deleted file mode 100644 index d732e4f..0000000 --- a/HACKING +++ /dev/null @@ -1,94 +0,0 @@ -Hello hackers! - -General remarks about contributing ----------------------------------- - -Contributions to the libfreefare are welcome! Here are some directions to get -you started: - - 1. Install Cutter - Cutter is a cool unit test framework for C code. You will need it to run - the regression tests suite (`make check') and ensure that your code does - not break other features. - http://cutter.sourceforge.net/ - To cover all tests you'll need several blank cards: - * MIFARE Classic 4k with default keys (FFFFFFFFFF) - * MIFARE DESFire EV1 4k with default PICC key (0000000000000000) - * MIFARE Ultralight - * MIFARE Ultralight C with default key (BREAKMEIFYOUCAN!) - After "make check", you can run sub-sets of tests directly with cutter: - $ cutter -n /ultralight/ test - $ cutter -n /classic/ test - $ cutter -n /desfire/ test - - - 2. Follow style conventions - The source code of the library trend to follow some conventions so that it - is consistent in style and thus easier to read. Basically, it follows - FreeBSD's style(9); adding 4-space indentation and 8-space tabs (which you - should configure in your editor, e.g. `:set sw=4 ts=8' in vim). You are - also advised to `:set cinoptions=t0(0:0` so that you don't have to care - about indentation anymore. For more details, please read the style(9) man - page from FreeBSD's website: - http://www.freebsd.org/cgi/man.cgi?query=style - - 3. Write tests - I told you cutter is lovely in #1 so you really should use it! If you - want to contribute code, write test: only code with appropriate tests will - be considered. And remember that TDD (Test Driven Development) is cool - and writing all tests at the end deeply depressing, so test early, test - often! - - -Adding support for a new type of card -------------------------------------- - -Adding a new supported card to the libfreefare requires a few modification in -multiple places. Here is a list of the things to do in order to have the -infrastructure ready for hacking the new card support: - - Edit libfreefare/freefare.h: - - Add your tag to the `freefare_tag_type' enum; - - Add a _connect() and a _disconnect() function prototype; - - Edit libfreefare/freefare.3: - - Add your tag to the `freefare_tag_type' enum documentation; - - Edit libfreefare/freefare_internal.h: - - Add a new _tag struct. It's very first member SHALL be `struct - freefare_tag __tag'; - - Add a _tag_new() and a _tag_free() function prototype; - - Add a ASSERT_() macro to check the tag's type; - - Add a () macro to cast a generic tag to your type. - - Edit libfreefare/freefare.c: - - Add your tag type to the supported_tags array; - - Edit the freefare_get_tags() function so that it calls _tag_new() - when it finds your tag; - - Edit the freefare_free_tags() function so that it calls - _tag_free() to free your tags; - - Create libfreefare/.c and implement all that's missing: - - _tag_new() MUST allocate all data-structure the tag may need to - use during it's lifetime. We do not want to have any function to fail - later because the running system is out of resources. Buffers for - cryptographic operations on random amount of data MAY however be - (re)allocated on demand, in such case refrain from shrinking - unnecessarily the buffer size. - - _connect() SHOULD initialise data allocated by _tag_new(). - Keep in mind that a single tag may be disconnected from and connected - to again, without being freed in the meantime. Since all memory - allocations are done in _tag_new(), your code SHOULD only care - about initialising these data structures; - - _disconnect() MAY do more that just send a disconnect command to - the tag. At time of writing I have no idea what it could be but who - knows... - - _tag_free() SHALL free all resources allocated for the tag - (surprising, isn't it?) - - -Various guidelines ------------------- - - - If a given card has different cryptographic modes, you SHOULD use - switch/cases to handle specific branches of code, even when applicable to - only one cypher. The idea is that if you don't provide support for all - cryptographic schemes, or if an evolution of the card provides more - cryptographic possibilities, when adding support for a new cypher, the - compiler can warn the developer about unhandled values in switch - statements. Please refer to the MIFARE DESFire code for an example. diff --git a/HACKING.md b/HACKING.md new file mode 100644 index 0000000..e35a047 --- /dev/null +++ b/HACKING.md @@ -0,0 +1,98 @@ +Hello hackers! + +# General remarks about contributing + +Contributions to the libfreefare are welcome! Here are some directions to get +you started: + +## Install Cutter + +[Cutter](http://cutter.sourceforge.net/) is a cool unit test framework for C +code. You will need it to run the regression tests suite (`make check`) and +ensure that your code does not break other features. + +To cover all tests you'll need several blank cards: + +* MIFARE Classic 4k with default keys (`FFFFFFFFFF`) +* MIFARE DESFire EV1 4k with default PICC key (`0000000000000000`) +* MIFARE Ultralight +* MIFARE Ultralight C with default key (`BREAKMEIFYOUCAN!`) + +After "make check", you can run sub-sets of tests directly with cutter: + +~~~ +$ cutter -n /ultralight/ test +$ cutter -n /classic/ test +$ cutter -n /desfire/ test +~~~ + +## Follow style conventions + +The source code of the library trend to follow some conventions so that it is +consistent in style and thus easier to read. Basically, it follows [FreeBSD's +style(9)](http://www.freebsd.org/cgi/man.cgi?query=style); adding 4-space +indentation and 8-space tabs (which you should configure in your editor, e.g. +`:set sw=4 ts=8` in vim). You are also advised to `:set cinoptions=t0(0:0` so +that you don't have to care about indentation anymore. For more details, please +read the [style(9) man page from FreeBSD's +website](http://www.freebsd.org/cgi/man.cgi?query=style). + +## Write tests + +I already told you cutter is lovely, so you really should use it! If you want +to contribute code, write test: only code with appropriate tests will be +considered. And remember that +[TDD](http://en.wikipedia.org/wiki/Test-driven_development) (Test Driven +Development) is cool and writing all tests at the end deeply depressing, so +test early, test often! + +# Adding support for a new type of card + +Adding a new supported card to the libfreefare requires a few modification in +multiple places. Here is a list of the things to do in order to have the +infrastructure ready for hacking the new card support: + + - Edit `libfreefare/freefare.h`: + - Add your tag to the `freefare_tag_type` enum; + - Add a `_connect()` and a `_disconnect()` function prototype; + - Edit `libfreefare/freefare.3`: + - Add your tag to the `freefare_tag_type' enum documentation; + - Edit `libfreefare/freefare_internal.h`: + - Add a new `_tag struct`. It's very first member SHALL be `struct + freefare_tag __tag`; + - Add a `_tag_new()` and a `_tag_free()` function prototype; + - Add a `ASSERT_()` macro to check the tag's type; + - Add a `()` macro to cast a generic tag to your type. + - Edit `libfreefare/freefare.c`: + - Add your tag type to the supported_tags array; + - Edit the `freefare_get_tags()` function so that it calls `_tag_new()` + when it finds your tag; + - Edit the `freefare_free_tags()` function so that it calls + `_tag_free()` to free your tags; + - Create `libfreefare/.c` and implement all that's missing: + - `_tag_new()` MUST allocate all data-structure the tag may need to + use during it's lifetime. We do not want to have any function to fail + later because the running system is out of resources. Buffers for + cryptographic operations on random amount of data MAY however be + (re)allocated on demand, in such case refrain from shrinking + unnecessarily the buffer size. + - `_connect()` SHOULD initialise data allocated by `_tag_new()`. + Keep in mind that a single tag may be disconnected from and connected + to again, without being freed in the meantime. Since all memory + allocations are done in `_tag_new()`, your code SHOULD only care + about initialising these data structures; + - `_disconnect()` MAY do more that just send a disconnect command to + the tag. At time of writing I have no idea what it could be but who + knows... + - `_tag_free()` SHALL free all resources allocated for the tag + (surprising, isn't it?) + +# Various guidelines + + - If a given card has different cryptographic modes, you SHOULD use + switch/cases to handle specific branches of code, even when applicable to + only one cypher. The idea is that if you don't provide support for all + cryptographic schemes, or if an evolution of the card provides more + cryptographic possibilities, when adding support for a new cypher, the + compiler can warn the developer about unhandled values in switch + statements. Please refer to the MIFARE DESFire code for an example. diff --git a/examples/mifare-classic-format.c b/examples/mifare-classic-format.c index ed0dbb6..bfd0059 100644 --- a/examples/mifare-classic-format.c +++ b/examples/mifare-classic-format.c @@ -215,8 +215,8 @@ main(int argc, char *argv[]) for (int i = 0; (!error) && tags[i]; i++) { switch (freefare_get_tag_type (tags[i])) { - case CLASSIC_1K: - case CLASSIC_4K: + case MIFARE_CLASSIC_1K: + case MIFARE_CLASSIC_4K: break; default: continue; @@ -240,11 +240,11 @@ main(int argc, char *argv[]) at_block = 0; if (format_options.fast) { - printf (START_FORMAT_N, (tt == CLASSIC_1K) ? 1 : 2); + printf (START_FORMAT_N, (tt == MIFARE_CLASSIC_1K) ? 1 : 2); if (!try_format_sector (tags[i], 0x00)) break; - if (tt == CLASSIC_4K) + if (tt == MIFARE_CLASSIC_4K) if (!try_format_sector (tags[i], 0x10)) break; @@ -252,12 +252,12 @@ main(int argc, char *argv[]) continue; } switch (tt) { - case CLASSIC_1K: + case MIFARE_CLASSIC_1K: mod_block = 4; if (!format_mifare_classic_1k (tags[i])) error = 1; break; - case CLASSIC_4K: + case MIFARE_CLASSIC_4K: mod_block = 10; if (!format_mifare_classic_4k (tags[i])) error = 1; diff --git a/examples/mifare-classic-read-ndef.c b/examples/mifare-classic-read-ndef.c index 17388b8..3c8b4ff 100644 --- a/examples/mifare-classic-read-ndef.c +++ b/examples/mifare-classic-read-ndef.c @@ -139,8 +139,8 @@ main(int argc, char *argv[]) for (int i = 0; (!error) && tags[i]; i++) { switch (freefare_get_tag_type (tags[i])) { - case CLASSIC_1K: - case CLASSIC_4K: + case MIFARE_CLASSIC_1K: + case MIFARE_CLASSIC_4K: break; default: continue; diff --git a/examples/mifare-classic-write-ndef.c b/examples/mifare-classic-write-ndef.c index 5482a94..2a9e483 100644 --- a/examples/mifare-classic-write-ndef.c +++ b/examples/mifare-classic-write-ndef.c @@ -229,8 +229,8 @@ main(int argc, char *argv[]) for (int i = 0; (!error) && tags[i]; i++) { switch (freefare_get_tag_type (tags[i])) { - case CLASSIC_1K: - case CLASSIC_4K: + case MIFARE_CLASSIC_1K: + case MIFARE_CLASSIC_4K: break; default: continue; @@ -257,13 +257,13 @@ main(int argc, char *argv[]) if (write_ndef) { switch (freefare_get_tag_type (tags[i])) { - case CLASSIC_4K: + case MIFARE_CLASSIC_4K: if (!search_sector_key (tags[i], 0x10, &(card_write_keys[0x10].key), &(card_write_keys[0x10].type))) { error = 1; goto error; } /* fallthrough */ - case CLASSIC_1K: + case MIFARE_CLASSIC_1K: if (!search_sector_key (tags[i], 0x00, &(card_write_keys[0x00].key), &(card_write_keys[0x00].type))) { error = 1; goto error; @@ -277,7 +277,7 @@ main(int argc, char *argv[]) if (!error) { /* Ensure the auth key is always a B one. If not, change it! */ switch (freefare_get_tag_type (tags[i])) { - case CLASSIC_4K: + case MIFARE_CLASSIC_4K: if (card_write_keys[0x10].type != MFC_KEY_B) { if( 0 != fix_mad_trailer_block (device, tags[i], 0x10, card_write_keys[0x10].key, card_write_keys[0x10].type)) { error = 1; @@ -287,7 +287,7 @@ main(int argc, char *argv[]) card_write_keys[0x10].type = MFC_KEY_B; } /* fallthrough */ - case CLASSIC_1K: + case MIFARE_CLASSIC_1K: if (card_write_keys[0x00].type != MFC_KEY_B) { if( 0 != fix_mad_trailer_block (device, tags[i], 0x00, card_write_keys[0x00].key, card_write_keys[0x00].type)) { error = 1; @@ -336,7 +336,7 @@ main(int argc, char *argv[]) } else { // Create a MAD and mark unaccessible sectors in the card - if (!(mad = mad_new ((freefare_get_tag_type (tags[i]) == CLASSIC_4K) ? 2 : 1))) { + if (!(mad = mad_new ((freefare_get_tag_type (tags[i]) == MIFARE_CLASSIC_4K) ? 2 : 1))) { perror ("mad_new"); error = 1; goto error; @@ -344,10 +344,10 @@ main(int argc, char *argv[]) MifareClassicSectorNumber max_s = 0; switch (freefare_get_tag_type (tags[i])) { - case CLASSIC_1K: + case MIFARE_CLASSIC_1K: max_s = 15; break; - case CLASSIC_4K: + case MIFARE_CLASSIC_4K: max_s = 39; break; default: diff --git a/examples/mifare-desfire-access.c b/examples/mifare-desfire-access.c index 72a2dca..f9fe89d 100644 --- a/examples/mifare-desfire-access.c +++ b/examples/mifare-desfire-access.c @@ -63,7 +63,7 @@ main(int argc, char *argv[]) } for (int i = 0; (!error) && tags[i]; i++) { - if (DESFIRE != freefare_get_tag_type (tags[i])) + if (MIFARE_DESFIRE != freefare_get_tag_type (tags[i])) continue; int res; diff --git a/examples/mifare-desfire-create-ndef.c b/examples/mifare-desfire-create-ndef.c index f1f00cd..32ceb22 100644 --- a/examples/mifare-desfire-create-ndef.c +++ b/examples/mifare-desfire-create-ndef.c @@ -119,7 +119,7 @@ main(int argc, char *argv[]) } for (int i = 0; (!error) && tags[i]; i++) { - if (DESFIRE != freefare_get_tag_type (tags[i])) + if (MIFARE_DESFIRE != freefare_get_tag_type (tags[i])) continue; char *tag_uid = freefare_get_tag_uid (tags[i]); diff --git a/examples/mifare-desfire-ev1-configure-ats.c b/examples/mifare-desfire-ev1-configure-ats.c index 6414544..08d374c 100644 --- a/examples/mifare-desfire-ev1-configure-ats.c +++ b/examples/mifare-desfire-ev1-configure-ats.c @@ -111,7 +111,7 @@ main(int argc, char *argv[]) } for (int i = 0; (!error) && tags[i]; i++) { - if (DESFIRE != freefare_get_tag_type (tags[i])) + if (MIFARE_DESFIRE != freefare_get_tag_type (tags[i])) continue; char *tag_uid = freefare_get_tag_uid (tags[i]); diff --git a/examples/mifare-desfire-ev1-configure-default-key.c b/examples/mifare-desfire-ev1-configure-default-key.c index 134a913..7c5423b 100644 --- a/examples/mifare-desfire-ev1-configure-default-key.c +++ b/examples/mifare-desfire-ev1-configure-default-key.c @@ -97,7 +97,7 @@ main(int argc, char *argv[]) } for (int i = 0; (!error) && tags[i]; i++) { - if (DESFIRE != freefare_get_tag_type (tags[i])) + if (MIFARE_DESFIRE != freefare_get_tag_type (tags[i])) continue; char *tag_uid = freefare_get_tag_uid (tags[i]); diff --git a/examples/mifare-desfire-ev1-configure-random-uid.c b/examples/mifare-desfire-ev1-configure-random-uid.c index d6a0045..05c90fe 100644 --- a/examples/mifare-desfire-ev1-configure-random-uid.c +++ b/examples/mifare-desfire-ev1-configure-random-uid.c @@ -107,7 +107,7 @@ main(int argc, char *argv[]) } for (int i = 0; (!error) && tags[i]; i++) { - if (DESFIRE != freefare_get_tag_type (tags[i])) + if (MIFARE_DESFIRE != freefare_get_tag_type (tags[i])) continue; char *tag_uid = freefare_get_tag_uid (tags[i]); diff --git a/examples/mifare-desfire-format.c b/examples/mifare-desfire-format.c index 9996930..e8342d3 100644 --- a/examples/mifare-desfire-format.c +++ b/examples/mifare-desfire-format.c @@ -107,7 +107,7 @@ main(int argc, char *argv[]) } for (int i = 0; (!error) && tags[i]; i++) { - if (DESFIRE != freefare_get_tag_type (tags[i])) + if (MIFARE_DESFIRE != freefare_get_tag_type (tags[i])) continue; char *tag_uid = freefare_get_tag_uid (tags[i]); diff --git a/examples/mifare-desfire-info.c b/examples/mifare-desfire-info.c index 9f55eaa..3ca2384 100644 --- a/examples/mifare-desfire-info.c +++ b/examples/mifare-desfire-info.c @@ -61,7 +61,7 @@ main(int argc, char *argv[]) } for (int i = 0; (!error) && tags[i]; i++) { - if (DESFIRE != freefare_get_tag_type (tags[i])) + if (MIFARE_DESFIRE != freefare_get_tag_type (tags[i])) continue; int res; diff --git a/examples/mifare-desfire-read-ndef.c b/examples/mifare-desfire-read-ndef.c index 687e230..c17cf6b 100644 --- a/examples/mifare-desfire-read-ndef.c +++ b/examples/mifare-desfire-read-ndef.c @@ -147,7 +147,7 @@ main(int argc, char *argv[]) } for (int i = 0; (!error) && tags[i]; i++) { - if (DESFIRE != freefare_get_tag_type (tags[i])) + if (MIFARE_DESFIRE != freefare_get_tag_type (tags[i])) continue; char *tag_uid = freefare_get_tag_uid (tags[i]); diff --git a/examples/mifare-desfire-write-ndef.c b/examples/mifare-desfire-write-ndef.c index 1b36af4..71a960e 100644 --- a/examples/mifare-desfire-write-ndef.c +++ b/examples/mifare-desfire-write-ndef.c @@ -176,7 +176,7 @@ main(int argc, char *argv[]) } for (int i = 0; (!error) && tags[i]; i++) { - if (DESFIRE != freefare_get_tag_type (tags[i])) + if (MIFARE_DESFIRE != freefare_get_tag_type (tags[i])) continue; char *tag_uid = freefare_get_tag_uid (tags[i]); diff --git a/examples/mifare-ultralight-info.c b/examples/mifare-ultralight-info.c index 96df7c1..e1b3a0f 100644 --- a/examples/mifare-ultralight-info.c +++ b/examples/mifare-ultralight-info.c @@ -57,8 +57,8 @@ main (int argc, char *argv[]) for (int i = 0; (!error) && tags[i]; i++) { switch (freefare_get_tag_type (tags[i])) { - case ULTRALIGHT: - case ULTRALIGHT_C: + case MIFARE_ULTRALIGHT: + case MIFARE_ULTRALIGHT_C: break; default: continue; @@ -66,7 +66,7 @@ main (int argc, char *argv[]) char *tag_uid = freefare_get_tag_uid (tags[i]); printf ("Tag with UID %s is a %s\n", tag_uid, freefare_get_tag_friendly_name (tags[i])); - if (freefare_get_tag_type (tags[i]) == ULTRALIGHT_C) { + if (freefare_get_tag_type (tags[i]) == MIFARE_ULTRALIGHT_C) { FreefareTag tag = tags[i]; int res; MifareDESFireKey key; diff --git a/libfreefare/freefare.3 b/libfreefare/freefare.3 index 948aa44..bea39a9 100644 --- a/libfreefare/freefare.3 +++ b/libfreefare/freefare.3 @@ -50,11 +50,11 @@ Mifare card manipulation library (libfreefare, \-lfreefare) .Fn freefare_get_tags "nfc_device_t *device" .Bd -literal enum freefare_tag_type { - CLASSIC_1K, - CLASSIC_4K, - DESFIRE, - ULTRALIGHT, - ULTRALIGHT_C, + MIFARE_CLASSIC_1K, + MIFARE_CLASSIC_4K, + MIFARE_DESFIRE, + MIFARE_ULTRALIGHT, + MIFARE_ULTRALIGHT_C, }; .Ed .Ft "enum freefare_tag_type" diff --git a/libfreefare/freefare.c b/libfreefare/freefare.c index 2b54f10..ed947f9 100644 --- a/libfreefare/freefare.c +++ b/libfreefare/freefare.c @@ -27,17 +27,17 @@ #define NXP_MANUFACTURER_CODE 0x04 struct supported_tag supported_tags[] = { - { CLASSIC_1K, "Mifare Classic 1k", NMT_ISO14443A, 0x08, 0, 0, { 0x00 }, NULL }, - { CLASSIC_1K, "Mifare Classic 1k (Emulated)", NMT_ISO14443A, 0x28, 0, 0, { 0x00 }, NULL }, - { CLASSIC_1K, "Mifare Classic 1k (Emulated)", NMT_ISO14443A, 0x68, 0, 0, { 0x00 }, NULL }, - { CLASSIC_1K, "Infineon Mifare Classic 1k", NMT_ISO14443A, 0x88, 0, 0, { 0x00 }, NULL }, - { CLASSIC_4K, "Mifare Classic 4k", NMT_ISO14443A, 0x18, 0, 0, { 0x00 }, NULL }, - { CLASSIC_4K, "Mifare Classic 4k (Emulated)", NMT_ISO14443A, 0x38, 0, 0, { 0x00 }, NULL }, - { DESFIRE, "Mifare DESFire", NMT_ISO14443A, 0x20, 5, 4, { 0x75, 0x77, 0x81, 0x02 /*, 0xXX */ }, NULL}, - { DESFIRE, "Cyanogenmod card emulation", NMT_ISO14443A, 0x60, 4, 3, { 0x78, 0x33, 0x88 /*, 0xXX */ }, NULL}, - { DESFIRE, "Android HCE", NMT_ISO14443A, 0x60, 4, 3, { 0x78, 0x80, 0x70 /*, 0xXX */ }, NULL}, - { ULTRALIGHT_C, "Mifare UltraLightC", NMT_ISO14443A, 0x00, 0, 0, { 0x00 }, is_mifare_ultralightc_on_reader }, - { ULTRALIGHT, "Mifare UltraLight", NMT_ISO14443A, 0x00, 0, 0, { 0x00 }, NULL }, + { MIFARE_CLASSIC_1K, "Mifare Classic 1k", NMT_ISO14443A, 0x08, 0, 0, { 0x00 }, NULL }, + { MIFARE_CLASSIC_1K, "Mifare Classic 1k (Emulated)", NMT_ISO14443A, 0x28, 0, 0, { 0x00 }, NULL }, + { MIFARE_CLASSIC_1K, "Mifare Classic 1k (Emulated)", NMT_ISO14443A, 0x68, 0, 0, { 0x00 }, NULL }, + { MIFARE_CLASSIC_1K, "Infineon Mifare Classic 1k", NMT_ISO14443A, 0x88, 0, 0, { 0x00 }, NULL }, + { MIFARE_CLASSIC_4K, "Mifare Classic 4k", NMT_ISO14443A, 0x18, 0, 0, { 0x00 }, NULL }, + { MIFARE_CLASSIC_4K, "Mifare Classic 4k (Emulated)", NMT_ISO14443A, 0x38, 0, 0, { 0x00 }, NULL }, + { MIFARE_DESFIRE, "Mifare DESFire", NMT_ISO14443A, 0x20, 5, 4, { 0x75, 0x77, 0x81, 0x02 /*, 0xXX */ }, NULL}, + { MIFARE_DESFIRE, "Cyanogenmod card emulation", NMT_ISO14443A, 0x60, 4, 3, { 0x78, 0x33, 0x88 /*, 0xXX */ }, NULL}, + { MIFARE_DESFIRE, "Android HCE", NMT_ISO14443A, 0x60, 4, 3, { 0x78, 0x80, 0x70 /*, 0xXX */ }, NULL}, + { MIFARE_ULTRALIGHT_C, "Mifare UltraLightC", NMT_ISO14443A, 0x00, 0, 0, { 0x00 }, is_mifare_ultralightc_on_reader }, + { MIFARE_ULTRALIGHT, "Mifare UltraLight", NMT_ISO14443A, 0x00, 0, 0, { 0x00 }, NULL }, }; /* @@ -73,15 +73,15 @@ freefare_tag_new (nfc_device *device, nfc_target target) /* Allocate memory for the found MIFARE target */ switch (tag_info->type) { - case CLASSIC_1K: - case CLASSIC_4K: + case MIFARE_CLASSIC_1K: + case MIFARE_CLASSIC_4K: tag = mifare_classic_tag_new (); break; - case DESFIRE: + case MIFARE_DESFIRE: tag = mifare_desfire_tag_new (); break; - case ULTRALIGHT: - case ULTRALIGHT_C: + case MIFARE_ULTRALIGHT: + case MIFARE_ULTRALIGHT_C: tag = mifare_ultralight_tag_new (); break; } @@ -213,15 +213,15 @@ freefare_free_tag (FreefareTag tag) { if (tag) { switch (tag->tag_info->type) { - case CLASSIC_1K: - case CLASSIC_4K: + case MIFARE_CLASSIC_1K: + case MIFARE_CLASSIC_4K: mifare_classic_tag_free (tag); break; - case DESFIRE: + case MIFARE_DESFIRE: mifare_desfire_tag_free (tag); break; - case ULTRALIGHT: - case ULTRALIGHT_C: + case MIFARE_ULTRALIGHT: + case MIFARE_ULTRALIGHT_C: mifare_ultralight_tag_free (tag); break; } @@ -235,7 +235,7 @@ freefare_strerror (FreefareTag tag) if (nfc_device_get_last_error (tag->device) < 0) { p = nfc_strerror (tag->device); } else { - if (tag->tag_info->type == DESFIRE) { + if (tag->tag_info->type == MIFARE_DESFIRE) { if (MIFARE_DESFIRE (tag)->last_pcd_error) { p = mifare_desfire_error_lookup (MIFARE_DESFIRE (tag)->last_pcd_error); } else if (MIFARE_DESFIRE (tag)->last_picc_error) { diff --git a/libfreefare/freefare.h b/libfreefare/freefare.h index 42569fc..6a6183c 100644 --- a/libfreefare/freefare.h +++ b/libfreefare/freefare.h @@ -29,16 +29,16 @@ #endif // __cplusplus enum freefare_tag_type { -// MINI, - CLASSIC_1K, - CLASSIC_4K, - DESFIRE, -// PLUS_S2K, -// PLUS_S4K, -// PLUS_X2K, -// PLUS_X4K, - ULTRALIGHT, - ULTRALIGHT_C, +// MIFARE_MINI, + MIFARE_CLASSIC_1K, + MIFARE_CLASSIC_4K, + MIFARE_DESFIRE, +// MIFARE_PLUS_S2K, +// MIFARE_PLUS_S4K, +// MIFARE_PLUS_X2K, +// MIFARE_PLUS_X4K, + MIFARE_ULTRALIGHT, + MIFARE_ULTRALIGHT_C, }; struct freefare_tag; diff --git a/libfreefare/freefare_internal.h b/libfreefare/freefare_internal.h index 5ad81e1..6df3f63 100644 --- a/libfreefare/freefare_internal.h +++ b/libfreefare/freefare_internal.h @@ -262,10 +262,10 @@ struct mifare_ultralight_tag { #define ASSERT_ACTIVE(tag) do { if (!tag->active) return errno = ENXIO, -1; } while (0) #define ASSERT_INACTIVE(tag) do { if (tag->active) return errno = ENXIO, -1; } while (0) -#define ASSERT_MIFARE_CLASSIC(tag) do { if ((tag->tag_info->type != CLASSIC_1K) && (tag->tag_info->type != CLASSIC_4K)) return errno = ENODEV, -1; } while (0) -#define ASSERT_MIFARE_DESFIRE(tag) do { if (tag->tag_info->type != DESFIRE) return errno = ENODEV, -1; } while (0) -#define IS_MIFARE_ULTRALIGHT_C(tag) (tag->tag_info->type == ULTRALIGHT_C) -#define ASSERT_MIFARE_ULTRALIGHT(tag) do { if ((tag->tag_info->type != ULTRALIGHT) && (! IS_MIFARE_ULTRALIGHT_C(tag))) return errno = ENODEV, -1; } while (0) +#define ASSERT_MIFARE_CLASSIC(tag) do { if ((tag->tag_info->type != MIFARE_CLASSIC_1K) && (tag->tag_info->type != MIFARE_CLASSIC_4K)) return errno = ENODEV, -1; } while (0) +#define ASSERT_MIFARE_DESFIRE(tag) do { if (tag->tag_info->type != MIFARE_DESFIRE) return errno = ENODEV, -1; } while (0) +#define IS_MIFARE_ULTRALIGHT_C(tag) (tag->tag_info->type == MIFARE_ULTRALIGHT_C) +#define ASSERT_MIFARE_ULTRALIGHT(tag) do { if ((tag->tag_info->type != MIFARE_ULTRALIGHT) && (! IS_MIFARE_ULTRALIGHT_C(tag))) return errno = ENODEV, -1; } while (0) #define ASSERT_MIFARE_ULTRALIGHT_C(tag) do { if (! IS_MIFARE_ULTRALIGHT_C(tag)) return errno = ENODEV, -1; } while (0) /* diff --git a/libfreefare/mifare_desfire_error.c b/libfreefare/mifare_desfire_error.c index 910c82e..ae53fa1 100644 --- a/libfreefare/mifare_desfire_error.c +++ b/libfreefare/mifare_desfire_error.c @@ -72,7 +72,7 @@ mifare_desfire_error_lookup (uint8_t code) uint8_t mifare_desfire_last_pcd_error (FreefareTag tag) { - if (tag->tag_info->type != DESFIRE) + if (tag->tag_info->type != MIFARE_DESFIRE) return 0; return MIFARE_DESFIRE (tag)->last_pcd_error; @@ -81,7 +81,7 @@ mifare_desfire_last_pcd_error (FreefareTag tag) uint8_t mifare_desfire_last_picc_error (FreefareTag tag) { - if (tag->tag_info->type != DESFIRE) + if (tag->tag_info->type != MIFARE_DESFIRE) return 0; return MIFARE_DESFIRE (tag)->last_picc_error; diff --git a/test/mifare_classic_fixture.c b/test/mifare_classic_fixture.c index c02238f..6c29c22 100644 --- a/test/mifare_classic_fixture.c +++ b/test/mifare_classic_fixture.c @@ -50,8 +50,8 @@ cut_setup (void) 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)) { + if ((freefare_get_tag_type(tags[i]) == MIFARE_CLASSIC_1K) || + (freefare_get_tag_type(tags[i]) == MIFARE_CLASSIC_4K)) { tag = tags[i]; res = mifare_classic_connect (tag); cut_assert_equal_int (0, res, cut_message ("mifare_classic_connect() failed")); diff --git a/test/mifare_desfire_ev1_fixture.c b/test/mifare_desfire_ev1_fixture.c index 6a96afe..044d550 100644 --- a/test/mifare_desfire_ev1_fixture.c +++ b/test/mifare_desfire_ev1_fixture.c @@ -51,7 +51,7 @@ cut_setup (void) tag = NULL; for (int i=0; tags[i]; i++) { - if (freefare_get_tag_type(tags[i]) == DESFIRE) { + if (freefare_get_tag_type(tags[i]) == MIFARE_DESFIRE) { tag = tags[i]; res = mifare_desfire_connect (tag); cut_assert_equal_int (0, res, cut_message ("mifare_desfire_connect() failed")); diff --git a/test/mifare_desfire_fixture.c b/test/mifare_desfire_fixture.c index 356ef3e..0075b45 100644 --- a/test/mifare_desfire_fixture.c +++ b/test/mifare_desfire_fixture.c @@ -51,7 +51,7 @@ cut_setup (void) tag = NULL; for (int i=0; tags[i]; i++) { - if (freefare_get_tag_type(tags[i]) == DESFIRE) { + if (freefare_get_tag_type(tags[i]) == MIFARE_DESFIRE) { tag = tags[i]; res = mifare_desfire_connect (tag); cut_assert_equal_int (0, res, cut_message ("mifare_desfire_connect() failed")); diff --git a/test/mifare_ultralight_fixture.c b/test/mifare_ultralight_fixture.c index 025417e..43b705c 100644 --- a/test/mifare_ultralight_fixture.c +++ b/test/mifare_ultralight_fixture.c @@ -51,8 +51,8 @@ cut_setup (void) tag = NULL; for (int i=0; tags[i]; i++) { - if ((freefare_get_tag_type(tags[i]) == ULTRALIGHT) || - (freefare_get_tag_type(tags[i]) == ULTRALIGHT_C)) { + if ((freefare_get_tag_type(tags[i]) == MIFARE_ULTRALIGHT) || + (freefare_get_tag_type(tags[i]) == MIFARE_ULTRALIGHT_C)) { tag = tags[i]; res = mifare_ultralight_connect (tag); cut_assert_equal_int (0, res, cut_message ("mifare_ultralight_connect() failed")); diff --git a/test/test_mifare_classic_mad.c b/test/test_mifare_classic_mad.c index 7c55b79..e0e72e5 100644 --- a/test/test_mifare_classic_mad.c +++ b/test/test_mifare_classic_mad.c @@ -124,7 +124,7 @@ test_mifare_classic_mad (void) * | |\/| |/ _ \| |) \ V // / * |_| |_/_/ \_\___/ \_//___| */ - if (freefare_get_tag_type (tag) != CLASSIC_4K) { + if (freefare_get_tag_type (tag) != MIFARE_CLASSIC_4K) { cut_omit ("MADv2 requires a MIFARE Classic 4K to be tested"); } diff --git a/test/test_mifare_ultralight.c b/test/test_mifare_ultralight.c index 9103f00..09d46f2 100644 --- a/test/test_mifare_ultralight.c +++ b/test/test_mifare_ultralight.c @@ -178,7 +178,7 @@ test_mifare_ultralightc_authenticate (void) int res; MifareDESFireKey key; - if (tag->tag_info->type == ULTRALIGHT_C) { + if (tag->tag_info->type == MIFARE_ULTRALIGHT_C) { uint8_t key1_3des_data[16] = { 0x49, 0x45, 0x4D, 0x4B, 0x41, 0x45, 0x52, 0x42, 0x21, 0x4E, 0x41, 0x43, 0x55, 0x4F, 0x59, 0x46 }; key = mifare_desfire_3des_key_new (key1_3des_data); res = mifare_ultralightc_authenticate (tag, key);