57#define MAX_DEVICE_COUNT 16
58#define MAX_TARGET_COUNT 16
63print_usage(
const char *progname)
65 printf(
"usage: %s [-v] [-t X]\n", progname);
66 printf(
" -v\t verbose display\n");
67 printf(
" -t X\t poll only for types according to bitfield X:\n");
68 printf(
"\t 1: ISO14443A\n");
69 printf(
"\t 2: Felica (212 kbps)\n");
70 printf(
"\t 4: Felica (424 kbps)\n");
71 printf(
"\t 8: ISO14443B\n");
72 printf(
"\t 16: ISO14443B'\n");
73 printf(
"\t 32: ISO14443B-2 ST SRx\n");
74 printf(
"\t 64: ISO14443B-2 ASK CTx\n");
75 printf(
"\t 128: ISO14443B iClass\n");
76 printf(
"\t 256: ISO14443A-3 Jewel\n");
77 printf(
"\t 512: ISO14443A-2 NFC Barcode\n");
78 printf(
"\tSo 1023 (default) polls for all types.\n");
79 printf(
"\tNote that if 16, 32, 64 or 128 then 8 is selected too.\n");
83main(
int argc,
const char *argv[])
86 const char *acLibnfcVersion;
95 if (context == NULL) {
96 ERR(
"Unable to init libnfc (malloc)");
101 for (arg = 1; arg < argc; arg++) {
102 if (0 == strcmp(argv[arg],
"-h")) {
103 print_usage(argv[0]);
105 }
else if (0 == strcmp(argv[arg],
"-v")) {
107 }
else if ((0 == strcmp(argv[arg],
"-t")) && (arg + 1 < argc)) {
109 mask = atoi(argv[arg]);
110 if ((mask < 1) || (mask > 0x3ff)) {
111 ERR(
"%i is invalid value for type bitfield.", mask);
112 print_usage(argv[0]);
119 ERR(
"%s is not supported option.", argv[arg]);
120 print_usage(argv[0]);
128 printf(
"%s uses libnfc %s\n", argv[0], acLibnfcVersion);
140 pnd =
nfc_open(context,
"pn532_uart:/dev/ttyUSB1");
144 size_t szDeviceFound =
nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT);
146 if (szDeviceFound == 0) {
147 printf(
"No NFC device found.\n");
150 for (i = 0; i < szDeviceFound; i++) {
152 pnd =
nfc_open(context, connstrings[i]);
155 ERR(
"Unable to open NFC device: %s", connstrings[i]);
169 nm.nmt = NMT_ISO14443A;
174 if (verbose || (res > 0)) {
175 printf(
"%d ISO14443A passive target(s) found%s\n", res, (res == 0) ?
".\n" :
":");
177 for (n = 0; n < res; n++) {
178 print_nfc_target(&ant[n], verbose);
190 if (verbose || (res > 0)) {
191 printf(
"%d Felica (212 kbps) passive target(s) found%s\n", res, (res == 0) ?
".\n" :
":");
193 for (n = 0; n < res; n++) {
194 print_nfc_target(&ant[n], verbose);
205 if (verbose || (res > 0)) {
206 printf(
"%d Felica (424 kbps) passive target(s) found%s\n", res, (res == 0) ?
".\n" :
":");
208 for (n = 0; n < res; n++) {
209 print_nfc_target(&ant[n], verbose);
216 nm.nmt = NMT_ISO14443B;
221 if (verbose || (res > 0)) {
222 printf(
"%d ISO14443B passive target(s) found%s\n", res, (res == 0) ?
".\n" :
":");
224 for (n = 0; n < res; n++) {
225 print_nfc_target(&ant[n], verbose);
232 nm.nmt = NMT_ISO14443BI;
237 if (verbose || (res > 0)) {
238 printf(
"%d ISO14443B' passive target(s) found%s\n", res, (res == 0) ?
".\n" :
":");
240 for (n = 0; n < res; n++) {
241 print_nfc_target(&ant[n], verbose);
248 nm.nmt = NMT_ISO14443B2SR;
253 if (verbose || (res > 0)) {
254 printf(
"%d ISO14443B-2 ST SRx passive target(s) found%s\n", res, (res == 0) ?
".\n" :
":");
256 for (n = 0; n < res; n++) {
257 print_nfc_target(&ant[n], verbose);
264 nm.nmt = NMT_ISO14443B2CT;
269 if (verbose || (res > 0)) {
270 printf(
"%d ISO14443B-2 ASK CTx passive target(s) found%s\n", res, (res == 0) ?
".\n" :
":");
272 for (n = 0; n < res; n++) {
273 print_nfc_target(&ant[n], verbose);
280 nm.nmt = NMT_ISO14443BICLASS;
285 if (verbose || (res > 0)) {
286 printf(
"%d ISO14443B iClass passive target(s) found%s\n", res, (res == 0) ?
".\n" :
":");
288 for (n = 0; n < res; n++) {
289 print_nfc_target(&ant[n], verbose);
301 if (verbose || (res > 0)) {
302 printf(
"%d ISO14443A-3 Jewel passive target(s) found%s\n", res, (res == 0) ?
".\n" :
":");
304 for (n = 0; n < res; n++) {
305 print_nfc_target(&ant[n], verbose);
312 nm.nmt = NMT_BARCODE;
317 if (verbose || (res > 0)) {
318 printf(
"%d ISO14443A-2 NFC Barcode passive target(s) found%s\n", res, (res == 0) ?
".\n" :
":");
320 for (n = 0; n < res; n++) {
321 print_nfc_target(&ant[n], verbose);
const char * nfc_device_get_name(nfc_device *pnd)
Returns the device name.
void nfc_close(nfc_device *pnd)
Close from a NFC device.
nfc_device * nfc_open(nfc_context *context, const nfc_connstring connstring)
Open a NFC device.
size_t nfc_list_devices(nfc_context *context, nfc_connstring connstrings[], const size_t connstrings_len)
Scan for discoverable supported devices (ie. only available for some drivers)
void nfc_perror(const nfc_device *pnd, const char *pcString)
Display the last error occured on a nfc_device.
int nfc_initiator_init(nfc_device *pnd)
Initialize NFC device as initiator (reader)
int nfc_initiator_list_passive_targets(nfc_device *pnd, const nfc_modulation nm, nfc_target ant[], const size_t szTargets)
List passive or emulated tags.
void nfc_exit(nfc_context *context)
Deinitialize libnfc. Should be called after closing all open devices and before your application term...
void nfc_init(nfc_context **context)
Initialize libnfc. This function must be called before calling any other libnfc function.
const char * nfc_version(void)
Returns the library version.
char nfc_connstring[NFC_BUFSIZE_CONNSTRING]
Provide some examples shared functions like print, parity calculation, options parsing.
#define ERR(...)
Print a error message.
NFC library context Struct which contains internal options, references, pointers, etc....
NFC modulation structure.