57 #define MAX_DEVICE_COUNT 16
58 #define MAX_TARGET_COUNT 16
63 print_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");
83 main(
int argc,
const char *argv[])
86 const char *acLibnfcVersion;
95 if (context == NULL) {
96 ERR(
"Unable to init libnfc (malloc)");
102 printf(
"%s uses libnfc %s\n", argv[0], acLibnfcVersion);
105 for (arg = 1; arg < argc; arg++) {
106 if (0 == strcmp(argv[arg],
"-h")) {
107 print_usage(argv[0]);
109 }
else if (0 == strcmp(argv[arg],
"-v")) {
111 }
else if ((0 == strcmp(argv[arg],
"-t")) && (arg + 1 < argc)) {
113 mask = atoi(argv[arg]);
114 if ((mask < 1) || (mask > 0x3ff)) {
115 ERR(
"%i is invalid value for type bitfield.", mask);
116 print_usage(argv[0]);
123 ERR(
"%s is not supported option.", argv[arg]);
124 print_usage(argv[0]);
137 pnd =
nfc_open(context,
"pn532_uart:/dev/ttyUSB1");
141 size_t szDeviceFound =
nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT);
143 if (szDeviceFound == 0) {
144 printf(
"No NFC device found.\n");
147 for (i = 0; i < szDeviceFound; i++) {
149 pnd =
nfc_open(context, connstrings[i]);
152 ERR(
"Unable to open NFC device: %s", connstrings[i]);
166 nm.nmt = NMT_ISO14443A;
171 if (verbose || (res > 0)) {
172 printf(
"%d ISO14443A passive target(s) found%s\n", res, (res == 0) ?
".\n" :
":");
174 for (n = 0; n < res; n++) {
175 print_nfc_target(&ant[n], verbose);
187 if (verbose || (res > 0)) {
188 printf(
"%d Felica (212 kbps) passive target(s) found%s\n", res, (res == 0) ?
".\n" :
":");
190 for (n = 0; n < res; n++) {
191 print_nfc_target(&ant[n], verbose);
202 if (verbose || (res > 0)) {
203 printf(
"%d Felica (424 kbps) passive target(s) found%s\n", res, (res == 0) ?
".\n" :
":");
205 for (n = 0; n < res; n++) {
206 print_nfc_target(&ant[n], verbose);
213 nm.nmt = NMT_ISO14443B;
218 if (verbose || (res > 0)) {
219 printf(
"%d ISO14443B passive target(s) found%s\n", res, (res == 0) ?
".\n" :
":");
221 for (n = 0; n < res; n++) {
222 print_nfc_target(&ant[n], verbose);
229 nm.nmt = NMT_ISO14443BI;
234 if (verbose || (res > 0)) {
235 printf(
"%d ISO14443B' passive target(s) found%s\n", res, (res == 0) ?
".\n" :
":");
237 for (n = 0; n < res; n++) {
238 print_nfc_target(&ant[n], verbose);
245 nm.nmt = NMT_ISO14443B2SR;
250 if (verbose || (res > 0)) {
251 printf(
"%d ISO14443B-2 ST SRx passive target(s) found%s\n", res, (res == 0) ?
".\n" :
":");
253 for (n = 0; n < res; n++) {
254 print_nfc_target(&ant[n], verbose);
261 nm.nmt = NMT_ISO14443B2CT;
266 if (verbose || (res > 0)) {
267 printf(
"%d ISO14443B-2 ASK CTx passive target(s) found%s\n", res, (res == 0) ?
".\n" :
":");
269 for (n = 0; n < res; n++) {
270 print_nfc_target(&ant[n], verbose);
277 nm.nmt = NMT_ISO14443BICLASS;
282 if (verbose || (res > 0)) {
283 printf(
"%d ISO14443B iClass passive target(s) found%s\n", res, (res == 0) ?
".\n" :
":");
285 for (n = 0; n < res; n++) {
286 print_nfc_target(&ant[n], verbose);
298 if (verbose || (res > 0)) {
299 printf(
"%d ISO14443A-3 Jewel passive target(s) found%s\n", res, (res == 0) ?
".\n" :
":");
301 for (n = 0; n < res; n++) {
302 print_nfc_target(&ant[n], verbose);
309 nm.nmt = NMT_BARCODE;
314 if (verbose || (res > 0)) {
315 printf(
"%d ISO14443A-2 NFC Barcode passive target(s) found%s\n", res, (res == 0) ?
".\n" :
":");
317 for (n = 0; n < res; n++) {
318 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.