diff --git a/libfreefare/freefare_internal.h b/libfreefare/freefare_internal.h index c8e1d6f..e26c3cb 100644 --- a/libfreefare/freefare_internal.h +++ b/libfreefare/freefare_internal.h @@ -328,6 +328,8 @@ struct mifare_ultralight_tag { #define BUFFER_SIZE(buffer_name) (__##buffer_name##_n) +#define BUFFER_MAXSIZE(buffer_name) (__##buffer_name##_size) + #define BUFFER_CLEAR(buffer_name) (__##buffer_name##_n = 0) /* * Append one byte of data to the buffer buffer_name. diff --git a/libfreefare/mifare_desfire.c b/libfreefare/mifare_desfire.c index 3083fea..44e0aa0 100644 --- a/libfreefare/mifare_desfire.c +++ b/libfreefare/mifare_desfire.c @@ -295,6 +295,21 @@ mifare_desfire_connect (MifareTag tag) .nbr = NBR_106 }; if (nfc_initiator_select_passive_target (tag->device, modulation, tag->info.abtUid, tag->info.szUidLen, &pnti) >= 0) { + // The registered ISO AID of DESFire D2760000850100 + // Selecting this AID selects the MF + BUFFER_INIT (cmd, 12); + BUFFER_INIT (res, 2); + BUFFER_APPEND (cmd, 0x00); + BUFFER_APPEND (cmd, 0xa4); + BUFFER_APPEND (cmd, 0x04); + BUFFER_APPEND (cmd, 0x00); + uint8_t AID[]={ 0xd2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x00}; + BUFFER_APPEND (cmd, sizeof (AID)); + BUFFER_APPEND_BYTES (cmd, AID, sizeof (AID)); + if ((nfc_initiator_transceive_bytes(tag->device, cmd, BUFFER_SIZE(cmd), res, BUFFER_MAXSIZE(cmd), 0) < 0) || (res[0] != 0x90 || res[1] != 0x00)) { + errno = EIO; + return -1; + } tag->active = 1; free (MIFARE_DESFIRE (tag)->session_key); MIFARE_DESFIRE (tag)->session_key = NULL;