Another step in card type agnostism direction.
This commit is contained in:
parent
89e5344b91
commit
c388ba6b30
6 changed files with 17 additions and 17 deletions
|
@ -46,7 +46,7 @@ struct supported_tag supported_tags[] = {
|
||||||
* Automagically allocate a FreefareTag given a device and target info.
|
* Automagically allocate a FreefareTag given a device and target info.
|
||||||
*/
|
*/
|
||||||
FreefareTag
|
FreefareTag
|
||||||
freefare_tag_new (nfc_device *device, nfc_iso14443a_info nai)
|
freefare_tag_new (nfc_device *device, nfc_target target)
|
||||||
{
|
{
|
||||||
bool found = false;
|
bool found = false;
|
||||||
struct supported_tag *tag_info;
|
struct supported_tag *tag_info;
|
||||||
|
@ -54,12 +54,12 @@ freefare_tag_new (nfc_device *device, nfc_iso14443a_info nai)
|
||||||
|
|
||||||
/* Ensure the target is supported */
|
/* Ensure the target is supported */
|
||||||
for (size_t i = 0; i < sizeof (supported_tags) / sizeof (struct supported_tag); i++) {
|
for (size_t i = 0; i < sizeof (supported_tags) / sizeof (struct supported_tag); i++) {
|
||||||
if (((nai.szUidLen == 4) || (nai.abtUid[0] == NXP_MANUFACTURER_CODE)) &&
|
if ((target.nm.nmt == NMT_ISO14443A) && ((target.nti.nai.szUidLen == 4) || (target.nti.nai.abtUid[0] == NXP_MANUFACTURER_CODE)) &&
|
||||||
(nai.btSak == supported_tags[i].SAK) &&
|
(target.nti.nai.btSak == supported_tags[i].SAK) &&
|
||||||
(!supported_tags[i].ATS_min_length || ((nai.szAtsLen >= supported_tags[i].ATS_min_length) &&
|
(!supported_tags[i].ATS_min_length || ((target.nti.nai.szAtsLen >= supported_tags[i].ATS_min_length) &&
|
||||||
(0 == memcmp (nai.abtAts, supported_tags[i].ATS, supported_tags[i].ATS_compare_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 == 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]);
|
tag_info = &(supported_tags[i]);
|
||||||
found = true;
|
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())
|
* (Target specific fields are initialized in mifare_*_tag_new())
|
||||||
*/
|
*/
|
||||||
tag->device = device;
|
tag->device = device;
|
||||||
tag->info = nai;
|
tag->info = target;
|
||||||
tag->active = 0;
|
tag->active = 0;
|
||||||
tag->tag_info = tag_info;
|
tag->tag_info = tag_info;
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ freefare_get_tags (nfc_device *device)
|
||||||
|
|
||||||
for (int c = 0; c < candidates_count; c++) {
|
for (int c = 0; c < candidates_count; c++) {
|
||||||
FreefareTag t;
|
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 */
|
/* (Re)Allocate memory for the found MIFARE targets array */
|
||||||
FreefareTag *p = realloc (tags, (tag_count + 2) * sizeof (FreefareTag));
|
FreefareTag *p = realloc (tags, (tag_count + 2) * sizeof (FreefareTag));
|
||||||
if (p)
|
if (p)
|
||||||
|
@ -189,9 +189,9 @@ char *
|
||||||
freefare_get_tag_uid (FreefareTag tag)
|
freefare_get_tag_uid (FreefareTag tag)
|
||||||
{
|
{
|
||||||
char *res;
|
char *res;
|
||||||
if ((res = malloc (2 * tag->info.szUidLen + 1))) {
|
if ((res = malloc (2 * tag->info.nti.nai.szUidLen + 1))) {
|
||||||
for (size_t i =0; i < tag->info.szUidLen; i++)
|
for (size_t i =0; i < tag->info.nti.nai.szUidLen; i++)
|
||||||
snprintf (res + 2*i, 3, "%02x", tag->info.abtUid[i]);
|
snprintf (res + 2*i, 3, "%02x", tag->info.nti.nai.abtUid[i]);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ typedef uint8_t MifareUltralightPageNumber;
|
||||||
typedef unsigned char MifareUltralightPage[4];
|
typedef unsigned char MifareUltralightPage[4];
|
||||||
|
|
||||||
FreefareTag *freefare_get_tags (nfc_device *device);
|
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);
|
enum freefare_tag_type freefare_get_tag_type (FreefareTag tag);
|
||||||
const char *freefare_get_tag_friendly_name (FreefareTag tag);
|
const char *freefare_get_tag_friendly_name (FreefareTag tag);
|
||||||
char *freefare_get_tag_uid (FreefareTag tag);
|
char *freefare_get_tag_uid (FreefareTag tag);
|
||||||
|
|
|
@ -185,7 +185,7 @@ struct supported_tag {
|
||||||
*/
|
*/
|
||||||
struct freefare_tag {
|
struct freefare_tag {
|
||||||
nfc_device *device;
|
nfc_device *device;
|
||||||
nfc_iso14443a_info info;
|
nfc_target info;
|
||||||
const struct supported_tag *tag_info;
|
const struct supported_tag *tag_info;
|
||||||
int active;
|
int active;
|
||||||
};
|
};
|
||||||
|
|
|
@ -237,7 +237,7 @@ mifare_classic_connect (FreefareTag tag)
|
||||||
.nmt = NMT_ISO14443A,
|
.nmt = NMT_ISO14443A,
|
||||||
.nbr = NBR_106
|
.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;
|
tag->active = 1;
|
||||||
} else {
|
} else {
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
|
@ -292,7 +292,7 @@ mifare_classic_authenticate (FreefareTag tag, const MifareClassicBlockNumber blo
|
||||||
BUFFER_APPEND(cmd, block);
|
BUFFER_APPEND(cmd, block);
|
||||||
BUFFER_APPEND_BYTES (cmd, key, 6);
|
BUFFER_APPEND_BYTES (cmd, key, 6);
|
||||||
// To support both 4-byte & 7-byte UID cards:
|
// 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);
|
CLASSIC_TRANSCEIVE_EX (tag, cmd, res, 1);
|
||||||
|
|
||||||
|
|
|
@ -297,7 +297,7 @@ mifare_desfire_connect (FreefareTag tag)
|
||||||
.nmt = NMT_ISO14443A,
|
.nmt = NMT_ISO14443A,
|
||||||
.nbr = NBR_424
|
.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
|
// The registered ISO AID of DESFire D2760000850100
|
||||||
// Selecting this AID selects the MF
|
// Selecting this AID selects the MF
|
||||||
BUFFER_INIT (cmd, 12);
|
BUFFER_INIT (cmd, 12);
|
||||||
|
|
|
@ -138,7 +138,7 @@ mifare_ultralight_connect (FreefareTag tag)
|
||||||
.nmt = NMT_ISO14443A,
|
.nmt = NMT_ISO14443A,
|
||||||
.nbr = NBR_106
|
.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;
|
tag->active = 1;
|
||||||
for (int i = 0; i < MIFARE_ULTRALIGHT_MAX_PAGE_COUNT; i++)
|
for (int i = 0; i < MIFARE_ULTRALIGHT_MAX_PAGE_COUNT; i++)
|
||||||
MIFARE_ULTRALIGHT(tag)->cached_pages[i] = 0;
|
MIFARE_ULTRALIGHT(tag)->cached_pages[i] = 0;
|
||||||
|
|
Loading…
Reference in a new issue