Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mifare_desfire_connect hangs when used after nfc_initiator_poll_target #44

Open
tomfrancart opened this issue Aug 23, 2015 · 0 comments
Labels

Comments

@tomfrancart
Copy link

I'm attempting to use nfc_initiator_poll_target to poll for a card, and then connect using the libfreefare function corresponding to the card type.

The following works fine for mifare_classic:

nfc_initiator_poll_target(..., candidate)
tag = freefare_tag_new(candidate)
mifare_classic_connect(tag)
mifare_classic_authenticate(tag)
mifare_classic_read(tag)

If I attempt the same for desfire, the call to mifare_desfire_connect hangs until I remove and replace the desfire card:

nfc_initiator_poll_target(..., candidate)
tag = freefare_tag_new(candidate)
mifare_desfire_connect(tag)    // hangs here

It actually hangs on line 298 in mifare_desfire.c:

if (nfc_initiator_select_passive_target (tag->device, modulation, tag->info.nti.nai.abtUid, tag->info.nti.nai.szUidLen, &pnti) >= 0) {

I tried setting all parameters in this call to the same ones as used for mifare_classic, but to no avail.

I made an example by editing examples/nfc-poll.c from libnfc, add the following after line 153:

printf("Attempting desfire_connect..\n");
FreefareTag tag = freefare_tag_new(pnd, nt);
if (!tag) {
    printf("freefare_tag_new failed");
}
res = mifare_desfire_connect(tag);
printf("Desfire_connect done.\n");

If you place a mifare classic card on the reader, the program will immediately continue until after printf("Desfire_connect done.\n")
If you place a desfire card on the reader, it will hang, and only continue after removing the card and replacing it.

What does work is the following:

nfc_initiator_poll_target(...)     // ignore result
tags = freefare_get_tags (device);
mifare_desfire_connect (tags[0]);
mifare_desfire_select_application
mifare_desfire_authenticate
mifare_desfire_read_data

But this is quite inefficient.

best regards,
Tom

PS: I originally reported this on the forum: http://forums.nfc-tools.org/post/5717/#p5717

tomfrancart added a commit to tomfrancart/libfreefare that referenced this issue Aug 23, 2015
@smortex smortex added the bug label Aug 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants