diff --git a/libfreefare/freefare.c b/libfreefare/freefare.c index 8aaa07a..13c1f1b 100644 --- a/libfreefare/freefare.c +++ b/libfreefare/freefare.c @@ -46,7 +46,7 @@ struct supported_tag supported_tags[] = { * Automagically allocate a FreefareTag given a device and target info. */ FreefareTag -freefare_tag_new (nfc_device *device, nfc_iso14443a_info nai) +freefare_tag_new (nfc_device *device, nfc_target target) { bool found = false; struct supported_tag *tag_info; @@ -54,12 +54,12 @@ freefare_tag_new (nfc_device *device, nfc_iso14443a_info nai) /* Ensure the target is supported */ for (size_t i = 0; i < sizeof (supported_tags) / sizeof (struct supported_tag); i++) { - if (((nai.szUidLen == 4) || (nai.abtUid[0] == NXP_MANUFACTURER_CODE)) && - (nai.btSak == supported_tags[i].SAK) && - (!supported_tags[i].ATS_min_length || ((nai.szAtsLen >= supported_tags[i].ATS_min_length) && - (0 == memcmp (nai.abtAts, supported_tags[i].ATS, supported_tags[i].ATS_compare_length)))) && + if ((target.nm.nmt == NMT_ISO14443A) && ((target.nti.nai.szUidLen == 4) || (target.nti.nai.abtUid[0] == NXP_MANUFACTURER_CODE)) && + (target.nti.nai.btSak == supported_tags[i].SAK) && + (!supported_tags[i].ATS_min_length || ((target.nti.nai.szAtsLen >= supported_tags[i].ATS_min_length) && + (0 == memcmp (target.nti.nai.abtAts, supported_tags[i].ATS, supported_tags[i].ATS_compare_length)))) && ((supported_tags[i].check_tag_on_reader == NULL) || - supported_tags[i].check_tag_on_reader(device, nai))) { + supported_tags[i].check_tag_on_reader(device, target.nti.nai))) { tag_info = &(supported_tags[i]); found = true; @@ -93,7 +93,7 @@ freefare_tag_new (nfc_device *device, nfc_iso14443a_info nai) * (Target specific fields are initialized in mifare_*_tag_new()) */ tag->device = device; - tag->info = nai; + tag->info = target; tag->active = 0; tag->tag_info = tag_info; @@ -149,7 +149,7 @@ freefare_get_tags (nfc_device *device) for (int c = 0; c < candidates_count; c++) { FreefareTag t; - if ((t = freefare_tag_new(device, candidates[c].nti.nai))) { + if ((t = freefare_tag_new(device, candidates[c]))) { /* (Re)Allocate memory for the found MIFARE targets array */ FreefareTag *p = realloc (tags, (tag_count + 2) * sizeof (FreefareTag)); if (p) @@ -189,9 +189,9 @@ char * freefare_get_tag_uid (FreefareTag tag) { char *res; - if ((res = malloc (2 * tag->info.szUidLen + 1))) { - for (size_t i =0; i < tag->info.szUidLen; i++) - snprintf (res + 2*i, 3, "%02x", tag->info.abtUid[i]); + if ((res = malloc (2 * tag->info.nti.nai.szUidLen + 1))) { + for (size_t i =0; i < tag->info.nti.nai.szUidLen; i++) + snprintf (res + 2*i, 3, "%02x", tag->info.nti.nai.abtUid[i]); } return res; } diff --git a/libfreefare/freefare.h b/libfreefare/freefare.h index f49a99a..2de91ec 100644 --- a/libfreefare/freefare.h +++ b/libfreefare/freefare.h @@ -56,7 +56,7 @@ typedef uint8_t MifareUltralightPageNumber; typedef unsigned char MifareUltralightPage[4]; FreefareTag *freefare_get_tags (nfc_device *device); -FreefareTag freefare_tag_new (nfc_device *device, nfc_iso14443a_info nai); +FreefareTag freefare_tag_new (nfc_device *device, nfc_target target); enum freefare_tag_type freefare_get_tag_type (FreefareTag tag); const char *freefare_get_tag_friendly_name (FreefareTag tag); char *freefare_get_tag_uid (FreefareTag tag); diff --git a/libfreefare/freefare_internal.h b/libfreefare/freefare_internal.h index 9e4d15a..329b396 100644 --- a/libfreefare/freefare_internal.h +++ b/libfreefare/freefare_internal.h @@ -185,7 +185,7 @@ struct supported_tag { */ struct freefare_tag { nfc_device *device; - nfc_iso14443a_info info; + nfc_target info; const struct supported_tag *tag_info; int active; }; diff --git a/libfreefare/mifare_classic.c b/libfreefare/mifare_classic.c index 6ce6e37..a27a897 100644 --- a/libfreefare/mifare_classic.c +++ b/libfreefare/mifare_classic.c @@ -237,7 +237,7 @@ mifare_classic_connect (FreefareTag tag) .nmt = NMT_ISO14443A, .nbr = NBR_106 }; - if (nfc_initiator_select_passive_target (tag->device, modulation, tag->info.abtUid, tag->info.szUidLen, &pnti) >= 0) { + if (nfc_initiator_select_passive_target (tag->device, modulation, tag->info.nti.nai.abtUid, tag->info.nti.nai.szUidLen, &pnti) >= 0) { tag->active = 1; } else { errno = EIO; @@ -292,7 +292,7 @@ mifare_classic_authenticate (FreefareTag tag, const MifareClassicBlockNumber blo BUFFER_APPEND(cmd, block); BUFFER_APPEND_BYTES (cmd, key, 6); // To support both 4-byte & 7-byte UID cards: - BUFFER_APPEND_BYTES (cmd, tag->info.abtUid + tag->info.szUidLen - 4, 4); + BUFFER_APPEND_BYTES (cmd, tag->info.nti.nai.abtUid + tag->info.nti.nai.szUidLen - 4, 4); CLASSIC_TRANSCEIVE_EX (tag, cmd, res, 1); diff --git a/libfreefare/mifare_desfire.c b/libfreefare/mifare_desfire.c index 6319ef8..dceefac 100644 --- a/libfreefare/mifare_desfire.c +++ b/libfreefare/mifare_desfire.c @@ -297,7 +297,7 @@ mifare_desfire_connect (FreefareTag tag) .nmt = NMT_ISO14443A, .nbr = NBR_424 }; - if (nfc_initiator_select_passive_target (tag->device, modulation, tag->info.abtUid, tag->info.szUidLen, &pnti) >= 0) { + if (nfc_initiator_select_passive_target (tag->device, modulation, tag->info.nti.nai.abtUid, tag->info.nti.nai.szUidLen, &pnti) >= 0) { // The registered ISO AID of DESFire D2760000850100 // Selecting this AID selects the MF BUFFER_INIT (cmd, 12); diff --git a/libfreefare/mifare_ultralight.c b/libfreefare/mifare_ultralight.c index 48090ef..0f71d56 100644 --- a/libfreefare/mifare_ultralight.c +++ b/libfreefare/mifare_ultralight.c @@ -138,7 +138,7 @@ mifare_ultralight_connect (FreefareTag tag) .nmt = NMT_ISO14443A, .nbr = NBR_106 }; - if (nfc_initiator_select_passive_target (tag->device, modulation, tag->info.abtUid, tag->info.szUidLen, &pnti) >= 0) { + if (nfc_initiator_select_passive_target (tag->device, modulation, tag->info.nti.nai.abtUid, tag->info.nti.nai.szUidLen, &pnti) >= 0) { tag->active = 1; for (int i = 0; i < MIFARE_ULTRALIGHT_MAX_PAGE_COUNT; i++) MIFARE_ULTRALIGHT(tag)->cached_pages[i] = 0;