From c7b8574e23607518512b673ff4b3f70b510ae709 Mon Sep 17 00:00:00 2001 From: Romain Tartiere Date: Mon, 21 Dec 2009 03:02:15 +0000 Subject: [PATCH] Make MAD Application Identifiers (AID) structure public as MadAid. - Changed mad_get_aid() and mad_set_aid() ABI; - Update unit test; --- mad.c | 29 ++++++++++++----------------- mad.h | 10 ++++++++-- test/test_mad.c | 24 +++++++++++++++--------- 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/mad.c b/mad.c index a8f764d..6384d9c 100644 --- a/mad.c +++ b/mad.c @@ -32,21 +32,16 @@ #include -struct aid { - uint8_t function_cluster_code; - uint8_t application_code; -}; - struct mad_sector_0x00 { uint8_t crc; uint8_t info; - struct aid aids[15]; + MadAid aids[15]; }; struct mad_sector_0x10 { uint8_t crc; uint8_t info; - struct aid aids[23]; + MadAid aids[23]; }; struct mad { @@ -289,7 +284,7 @@ mad_set_card_publisher_sector(Mad mad, MifareSectorNumber cps) * Get the provided sector's application identifier. */ int -mad_get_aid(Mad mad, MifareSectorNumber sector, uint8_t *function_cluster_code, uint8_t *application_code) +mad_get_aid(Mad mad, MifareSectorNumber sector, MadAid *aid) { if (sector > 0x27) { errno = EINVAL; @@ -302,11 +297,11 @@ mad_get_aid(Mad mad, MifareSectorNumber sector, uint8_t *function_cluster_code, return -1; } - *function_cluster_code = mad->sector_0x10.aids[sector - 0x0f - 1].function_cluster_code; - *application_code = mad->sector_0x10.aids[sector - 0x0f - 1].application_code; + aid->function_cluster_code = mad->sector_0x10.aids[sector - 0x0f - 1].function_cluster_code; + aid->application_code = mad->sector_0x10.aids[sector - 0x0f - 1].application_code; } else { - *function_cluster_code = mad->sector_0x00.aids[sector - 1].function_cluster_code; - *application_code = mad->sector_0x00.aids[sector - 1].application_code; + aid->function_cluster_code = mad->sector_0x00.aids[sector - 1].function_cluster_code; + aid->application_code = mad->sector_0x00.aids[sector - 1].application_code; } return 0; @@ -316,7 +311,7 @@ mad_get_aid(Mad mad, MifareSectorNumber sector, uint8_t *function_cluster_code, * Set the provided sector's application identifier. */ int -mad_set_aid(Mad mad, MifareSectorNumber sector, uint8_t function_cluster_code, uint8_t application_code) +mad_set_aid(Mad mad, MifareSectorNumber sector, MadAid aid) { if (sector > 0x27) { errno = EINVAL; @@ -328,11 +323,11 @@ mad_set_aid(Mad mad, MifareSectorNumber sector, uint8_t function_cluster_code, u errno = EINVAL; return -1; } - mad->sector_0x00.aids[sector - 0x0f - 1].function_cluster_code = function_cluster_code; - mad->sector_0x00.aids[sector - 0x0f - 1].application_code = application_code; + mad->sector_0x00.aids[sector - 0x0f - 1].function_cluster_code = aid.function_cluster_code; + mad->sector_0x00.aids[sector - 0x0f - 1].application_code = aid.application_code; } else { - mad->sector_0x00.aids[sector - 1].function_cluster_code = function_cluster_code; - mad->sector_0x00.aids[sector - 1].application_code = application_code; + mad->sector_0x00.aids[sector - 1].function_cluster_code = aid.function_cluster_code; + mad->sector_0x00.aids[sector - 1].application_code = aid.application_code; } return 0; diff --git a/mad.h b/mad.h index 3bf916a..cd7934d 100644 --- a/mad.h +++ b/mad.h @@ -23,6 +23,12 @@ typedef uint8_t MifareSectorNumber; +struct mad_aid { + uint8_t function_cluster_code; + uint8_t application_code; +}; +typedef struct mad_aid MadAid; + struct mad; typedef struct mad *Mad; @@ -33,8 +39,8 @@ int mad_get_version (Mad mad); void mad_set_version (Mad mad, uint8_t version); MifareSectorNumber mad_get_card_publisher_sector(Mad mad); int mad_set_card_publisher_sector(Mad mad, MifareSectorNumber cps); -int mad_get_aid(Mad mad, MifareSectorNumber sector, uint8_t *function_cluster_code, uint8_t *application_code); -int mad_set_aid(Mad mad, MifareSectorNumber sector, uint8_t function_cluster_code, uint8_t application_code); +int mad_get_aid(Mad mad, MifareSectorNumber sector, MadAid *aid); +int mad_set_aid(Mad mad, MifareSectorNumber sector, MadAid aid); void mad_free (Mad mad); #endif /* !__MIFARE_APPLICATION_DIRECTORY_H__ */ diff --git a/test/test_mad.c b/test/test_mad.c index b95d1fd..2548e7a 100644 --- a/test/test_mad.c +++ b/test/test_mad.c @@ -23,19 +23,25 @@ DEFINE_TEST(mad) assertEqualInt (res, -1); assertEqualInt (13, mad_get_card_publisher_sector (mad)); - uint8_t fcc, ac; - res = mad_get_aid (mad, 3, &fcc, &ac); - assertEqualInt (res, 0); - assertEqualInt (fcc, 0); - assertEqualInt (ac, 0); + MadAid aid = { + .function_cluster_code = 0, + .application_code = 0 + }; - res = mad_set_aid (mad, 3, 0xc0, 0x42); + res = mad_get_aid (mad, 3, &aid); + assertEqualInt (res, 0); + assertEqualInt (aid.function_cluster_code, 0); + assertEqualInt (aid.application_code, 0); + + aid.function_cluster_code = 0xc0; + aid.application_code = 0x42; + res = mad_set_aid (mad, 3, aid); assertEqualInt (res, 0); - res = mad_get_aid (mad, 3, &fcc, &ac); + res = mad_get_aid (mad, 3, &aid); assertEqualInt (res, 0); - assertEqualInt (fcc, 0xc0); - assertEqualInt (ac, 0x42); + assertEqualInt (aid.function_cluster_code, 0xc0); + assertEqualInt (aid.application_code, 0x42); mad_free (mad); }