From 8dac813e53428abe91dcf6a1c301f0193e54ed3b Mon Sep 17 00:00:00 2001 From: Romain Tartiere Date: Sun, 17 Oct 2010 20:21:06 +0000 Subject: [PATCH] New API function mifare_desfire_aid_get_aid(). --- NEWS | 1 + libfreefare/freefare.h | 1 + libfreefare/mifare_desfire_aid.3 | 13 +++++++++++-- libfreefare/mifare_desfire_aid.c | 7 ++++++- test/test_mifare_desfire_aid.c | 2 ++ 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 3916f34..f9240bc 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ Changes between 0.2.0 and 0.2.1 [xx XXX xxxx] functions were removed and replaced by the freefare_strerror(), freefare_strerror_r() and freefare_perror() functions. *) New function mifare_desfire_last_picc_error(). + *) New function mifare_desfire_aid_get_aid(). *) Blok numbers in ISO14443-4 blocks are incremented according to the specification. diff --git a/libfreefare/freefare.h b/libfreefare/freefare.h index 95bb605..8e7e11c 100644 --- a/libfreefare/freefare.h +++ b/libfreefare/freefare.h @@ -243,6 +243,7 @@ typedef struct mifare_desfire_aid *MifareDESFireAID; MifareDESFireAID mifare_desfire_aid_new (uint32_t aid); MifareDESFireAID mifare_desfire_aid_new_with_mad_aid (MadAid mad_aid, uint8_t n); +uint32_t mifare_desfire_aid_get_aid (MifareDESFireAID aid); uint8_t mifare_desfire_last_picc_error (MifareTag tag); diff --git a/libfreefare/mifare_desfire_aid.3 b/libfreefare/mifare_desfire_aid.3 index 69cf714..ad37041 100644 --- a/libfreefare/mifare_desfire_aid.3 +++ b/libfreefare/mifare_desfire_aid.3 @@ -26,7 +26,8 @@ .\" .Sh NAME .Nm mifare_desfire_aid_new , -.Nm mifare_desfire_aid_new_with_mad_aid +.Nm mifare_desfire_aid_new_with_mad_aid , +.Nm mifare_desfire_aid_get_aid .Nd Mifare DESFire AID Manipulation Functions .\" _ _ _ .\" | | (_) |__ _ __ __ _ _ __ _ _ @@ -48,6 +49,8 @@ Mifare card manipulation library (libfreefare, \-lfreefare) .Fn mifare_desfire_aid_new "uint32_t aid" .Ft MifareDESFireAID .Fn mifare_desfire_aid_new_with_mad_aid "MadAid mad_aid" "uint8_t n" +.Ft uint32_t +.Fn mifare_desfire_aid_get_aid "MifareDESFireAID aid" .\" ____ _ _ _ .\" | _ \ ___ ___ ___ _ __(_)_ __ | |_(_) ___ _ __ .\" | | | |/ _ \/ __|/ __| '__| | '_ \| __| |/ _ \| '_ \ @@ -78,6 +81,12 @@ and .Fn mifare_desfire_aid_new_with_mad_aid allocates memory that should be reclaimed using .Xr free 3 . +.Pp +The +.Fn mifare_desfire_aid_get_aid +function returns the +.Vt aid +of the provided Mifare DESFire AID. .\" ____ _ _ .\" | _ \ ___| |_ _ _ _ __ _ __ __ ____ _| |_ _ ___ ___ .\" | |_) / _ \ __| | | | '__| '_ \ \ \ / / _` | | | | |/ _ \/ __| @@ -85,7 +94,7 @@ allocates memory that should be reclaimed using .\" |_| \_\___|\__|\__,_|_| |_| |_| \_/ \__,_|_|\__,_|\___||___/ .\" .Sh RETURN VALUES -The functions returns the allocated AID on success, +The allocation functions returns the allocated AID on success, .Va NULL otherwise. .\" ____ _ diff --git a/libfreefare/mifare_desfire_aid.c b/libfreefare/mifare_desfire_aid.c index 31e22da..c99d02b 100644 --- a/libfreefare/mifare_desfire_aid.c +++ b/libfreefare/mifare_desfire_aid.c @@ -55,7 +55,7 @@ #include #include "freefare_internal.h" -// FIXME Theorically, it should be an uint24_t ... +// Theorically, it should be an uint24_t ... MifareDESFireAID mifare_desfire_aid_new (uint32_t aid) { @@ -82,3 +82,8 @@ mifare_desfire_aid_new_with_mad_aid (MadAid mad_aid, uint8_t n) return mifare_desfire_aid_new (0xf00000 | (mad_aid.function_cluster_code << 12) | (mad_aid.application_code << 4) | n); } +uint32_t +mifare_desfire_aid_get_aid (MifareDESFireAID aid) +{ + return aid->data[0] | (aid->data[1] << 8) | (aid->data[2] << 16); +} diff --git a/test/test_mifare_desfire_aid.c b/test/test_mifare_desfire_aid.c index 1e7e8b6..65cd15c 100644 --- a/test/test_mifare_desfire_aid.c +++ b/test/test_mifare_desfire_aid.c @@ -44,6 +44,8 @@ test_mifare_desfire_aid (void) cut_assert_equal_memory (desfire_aid->data,3, desfire_aid2->data, 3, cut_message ("wrong aid")); + cut_assert_equal_int (mifare_desfire_aid_get_aid (desfire_aid), 0x00f12ab8, cut_message ("wrong aid")); + free (desfire_aid); free (desfire_aid2); }