From 7a68e0f6ce8d03f47e6a413e2c241fcd038684a9 Mon Sep 17 00:00:00 2001 From: Romain Tartiere Date: Fri, 8 Jan 2010 22:44:33 +0000 Subject: [PATCH] Fix MadAid field orders (transfer bytes order is big endian). --- libfreefare/freefare.h | 2 +- test/test_mad.c | 29 ++++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/libfreefare/freefare.h b/libfreefare/freefare.h index 2c26766..e1fb5d3 100644 --- a/libfreefare/freefare.h +++ b/libfreefare/freefare.h @@ -79,8 +79,8 @@ void mifare_classic_trailer_block (MifareClassicBlock *block, const MifareClas #define MCAB_WRITE_KEYB 0x001 struct mad_aid { - uint8_t function_cluster_code; uint8_t application_code; + uint8_t function_cluster_code; }; typedef struct mad_aid MadAid; diff --git a/test/test_mad.c b/test/test_mad.c index f9d7d12..0d21f3e 100644 --- a/test/test_mad.c +++ b/test/test_mad.c @@ -268,7 +268,7 @@ DEFINE_TEST (test_mad_sector_0x00_crc8) res = mad_set_card_publisher_sector (mad, 0x01); /* Block 1 */ - MadAid aid1 = { 0x08, 0x01 }; + MadAid aid1 = { 0x01, 0x08 }; mad_set_aid (mad, 1, aid1); mad_set_aid (mad, 2, aid1); mad_set_aid (mad, 3, aid1); @@ -278,21 +278,21 @@ DEFINE_TEST (test_mad_sector_0x00_crc8) mad_set_aid (mad, 4, empty_aid); mad_set_aid (mad, 5, empty_aid); mad_set_aid (mad, 6, empty_aid); - MadAid aid2 = { 0x00, 0x04 }; + MadAid aid2 = { 0x04, 0x00 }; mad_set_aid (mad, 7, aid2); /* Block 3 */ - MadAid aid3 = { 0x10, 0x03 }; + MadAid aid3 = { 0x03, 0x10 }; mad_set_aid (mad, 8, aid3); mad_set_aid (mad, 9, aid3); - MadAid aid4 = { 0x10, 0x02 }; + MadAid aid4 = { 0x02, 0x10 }; mad_set_aid (mad, 10, aid4); mad_set_aid (mad, 11, aid4); mad_set_aid (mad, 12, empty_aid); mad_set_aid (mad, 13, empty_aid); mad_set_aid (mad, 14, empty_aid); - MadAid aid5 = { 0x30, 0x11 }; + MadAid aid5 = { 0x11, 0x30 }; mad_set_aid (mad, 15, aid5); res = sector_0x00_crc8 (mad); @@ -303,3 +303,22 @@ DEFINE_TEST (test_mad_sector_0x00_crc8) } while (0); } + +DEFINE_TEST (test_mad_read) +{ + int res; + MifareClassicTag tag; + do + { + res = mifare_classic_test_setup (&tag); + assertEqualInt (res, 0); + + Mad mad = mad_read (tag); + if (!mad) { + assertEqualInt (0, 1); + } + + } while (0); + + mifare_classic_test_teardown (tag); +}