From 02d09e58f799e4e44dcd3bb35a46a68cffa4e99c Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Tue, 31 Aug 2010 16:03:08 +0000 Subject: [PATCH] Dirty patch to be able to create "real" MifareDESFareAID. --- examples/mifare-desfire-access.c | 3 ++- libfreefare/freefare.h | 2 +- libfreefare/mifare_desfire_aid.c | 15 ++++++++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/examples/mifare-desfire-access.c b/examples/mifare-desfire-access.c index ceb277a..f845918 100644 --- a/examples/mifare-desfire-access.c +++ b/examples/mifare-desfire-access.c @@ -80,7 +80,8 @@ main(int argc, char *argv[]) if (res < 0) errx (EXIT_FAILURE, "Authentication on master application failed"); - MifareDESFireAID aid = mifare_desfire_aid_new (0x12, 0x34, 0x5); + MadAid mad_aid = { 0x12, 0x34 }; + MifareDESFireAID aid = mifare_desfire_aid_new_with_mad_aid (mad_aid, 0x5); res = mifare_desfire_create_application (tags[i], aid, 0xFF, 0x1); if (res < 0) errx (EXIT_FAILURE, "Application creation failed"); diff --git a/libfreefare/freefare.h b/libfreefare/freefare.h index 0014faf..c8ced90 100644 --- a/libfreefare/freefare.h +++ b/libfreefare/freefare.h @@ -237,7 +237,7 @@ enum mifare_desfire_file_types { struct mifare_desfire_aid; typedef struct mifare_desfire_aid *MifareDESFireAID; -MifareDESFireAID mifare_desfire_aid_new (uint8_t application_code, uint8_t function_cluster_code, uint8_t n); +MifareDESFireAID mifare_desfire_aid_new (uint32_t aid); MifareDESFireAID mifare_desfire_aid_new_with_mad_aid (MadAid mad_aid, uint8_t n); struct mifare_desfire_key; diff --git a/libfreefare/mifare_desfire_aid.c b/libfreefare/mifare_desfire_aid.c index 62a7e7a..2bad706 100644 --- a/libfreefare/mifare_desfire_aid.c +++ b/libfreefare/mifare_desfire_aid.c @@ -19,17 +19,26 @@ #include #include +#include #include #include "freefare_internal.h" +// FIXME Theorically, it should be an uint24_t ... MifareDESFireAID -mifare_desfire_aid_new (uint8_t application_code, uint8_t function_cluster_code, uint8_t n) +mifare_desfire_aid_new (uint32_t aid) { - MadAid mad_aid = { application_code, function_cluster_code }; - return mifare_desfire_aid_new_with_mad_aid (mad_aid, n); + MifareDESFireAID res; + + if ((res = malloc (sizeof (*res)))) { + // XXX We may take care of endianess + memcpy(res->data, ((uint8_t*)&aid), 3); + } + + return res; } +// XXX This function ease the MifareDESFireAID creation using a Mifare Classic AID (see MIFARE Application Directory document - section 3.10 MAD and MIFARE DESFire) MifareDESFireAID mifare_desfire_aid_new_with_mad_aid (MadAid mad_aid, uint8_t n) {