2010-01-15 11:18:11 +01:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2010-09-07 19:51:03 +02:00
|
|
|
# include "config.h"
|
2010-01-15 11:18:11 +01:00
|
|
|
#endif // HAVE_CONFIG_H
|
|
|
|
|
2010-01-12 13:03:20 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <nfc/nfc.h>
|
2011-03-05 09:53:46 +01:00
|
|
|
|
2011-11-30 12:21:01 +01:00
|
|
|
#include "utils/nfc-utils.h"
|
|
|
|
#include "libnfc/chips/pn53x.h"
|
2010-01-12 13:03:20 +01:00
|
|
|
|
2010-09-07 19:51:03 +02:00
|
|
|
int
|
|
|
|
main (int argc, const char *argv[])
|
2010-01-12 13:03:20 +01:00
|
|
|
{
|
2011-11-23 16:55:40 +01:00
|
|
|
nfc_device *pnd;
|
2011-11-30 12:21:01 +01:00
|
|
|
nfc_target nt;
|
2010-01-12 13:03:20 +01:00
|
|
|
|
|
|
|
// Display libnfc version
|
2010-09-07 19:51:03 +02:00
|
|
|
const char *acLibnfcVersion = nfc_version ();
|
2011-05-25 21:53:45 +02:00
|
|
|
printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
|
2010-01-12 13:03:20 +01:00
|
|
|
|
|
|
|
// Connect using the first available NFC device
|
2010-09-07 19:51:03 +02:00
|
|
|
pnd = nfc_connect (NULL);
|
2010-01-12 13:03:20 +01:00
|
|
|
|
|
|
|
if (pnd == NULL) {
|
2010-09-07 19:51:03 +02:00
|
|
|
ERR ("%s", "Unable to connect to NFC device.");
|
|
|
|
return EXIT_FAILURE;
|
2010-01-12 13:03:20 +01:00
|
|
|
}
|
|
|
|
// Set connected NFC device to initiator mode
|
2010-09-07 19:51:03 +02:00
|
|
|
nfc_initiator_init (pnd);
|
2010-01-12 13:03:20 +01:00
|
|
|
|
2010-09-07 19:51:03 +02:00
|
|
|
printf ("Connected to NFC reader: %s\n", pnd->acName);
|
2010-01-12 13:03:20 +01:00
|
|
|
|
|
|
|
// Poll for a ISO14443A (MIFARE) tag
|
2011-11-23 16:55:40 +01:00
|
|
|
const nfc_modulation nmMifare = {
|
2010-10-14 13:12:23 +02:00
|
|
|
.nmt = NMT_ISO14443A,
|
|
|
|
.nbr = NBR_106,
|
|
|
|
};
|
2011-12-19 17:27:50 +01:00
|
|
|
if (nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt) == 0) {
|
2010-09-07 19:51:03 +02:00
|
|
|
printf ("The following (NFC) ISO14443A tag was found:\n");
|
|
|
|
printf (" ATQA (SENS_RES): ");
|
2011-11-30 12:21:01 +01:00
|
|
|
print_hex (nt.nti.nai.abtAtqa, 2);
|
|
|
|
printf (" UID (NFCID%c): ", (nt.nti.nai.abtUid[0] == 0x08 ? '3' : '1'));
|
|
|
|
print_hex (nt.nti.nai.abtUid, nt.nti.nai.szUidLen);
|
2010-09-07 19:51:03 +02:00
|
|
|
printf (" SAK (SEL_RES): ");
|
2011-11-30 12:21:01 +01:00
|
|
|
print_hex (&nt.nti.nai.btSak, 1);
|
|
|
|
if (nt.nti.nai.szAtsLen) {
|
2010-09-07 19:51:03 +02:00
|
|
|
printf (" ATS (ATR): ");
|
2011-11-30 12:21:01 +01:00
|
|
|
print_hex (nt.nti.nai.abtAts, nt.nti.nai.szAtsLen);
|
2010-09-07 19:51:03 +02:00
|
|
|
}
|
2010-01-12 13:03:20 +01:00
|
|
|
}
|
|
|
|
// Disconnect from NFC device
|
2010-09-07 19:51:03 +02:00
|
|
|
nfc_disconnect (pnd);
|
2010-01-12 13:03:20 +01:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|