44 #endif // HAVE_CONFIG_H
56 #define MAX_DEVICE_COUNT 16
57 #define MAX_TARGET_COUNT 16
62 print_usage(
const char *progname)
64 printf(
"usage: %s [-v]\n", progname);
65 printf(
" -v\t verbose display\n");
69 main(
int argc,
const char *argv[])
72 const char *acLibnfcVersion;
79 if (context == NULL) {
80 ERR(
"Unable to init libnfc (malloc)");
86 printf(
"%s uses libnfc %s\n", argv[0], acLibnfcVersion);
88 if ((argc == 2) && (0 == strcmp(
"-v", argv[1]))) {
104 pnd =
nfc_open(context,
"pn532_uart:/dev/ttyUSB1");
108 size_t szDeviceFound =
nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT);
110 if (szDeviceFound == 0) {
111 printf(
"No NFC device found.\n");
114 for (i = 0; i < szDeviceFound; i++) {
116 pnd =
nfc_open(context, connstrings[i]);
119 ERR(
"Unable to open NFC device: %s", connstrings[i]);
132 nm.nmt = NMT_ISO14443A;
137 if (verbose || (res > 0)) {
138 printf(
"%d ISO14443A passive target(s) found%s\n", res, (res == 0) ?
".\n" :
":");
140 for (n = 0; n < res; n++) {
141 print_nfc_target(&ant[n], verbose);
151 if (verbose || (res > 0)) {
152 printf(
"%d Felica (212 kbps) passive target(s) found%s\n", res, (res == 0) ?
".\n" :
":");
154 for (n = 0; n < res; n++) {
155 print_nfc_target(&ant[n], verbose);
163 if (verbose || (res > 0)) {
164 printf(
"%d Felica (424 kbps) passive target(s) found%s\n", res, (res == 0) ?
".\n" :
":");
166 for (n = 0; n < res; n++) {
167 print_nfc_target(&ant[n], verbose);
172 nm.nmt = NMT_ISO14443B;
177 if (verbose || (res > 0)) {
178 printf(
"%d ISO14443B passive target(s) found%s\n", res, (res == 0) ?
".\n" :
":");
180 for (n = 0; n < res; n++) {
181 print_nfc_target(&ant[n], verbose);
186 nm.nmt = NMT_ISO14443BI;
191 if (verbose || (res > 0)) {
192 printf(
"%d ISO14443B' passive target(s) found%s\n", res, (res == 0) ?
".\n" :
":");
194 for (n = 0; n < res; n++) {
195 print_nfc_target(&ant[n], verbose);
200 nm.nmt = NMT_ISO14443B2SR;
205 if (verbose || (res > 0)) {
206 printf(
"%d ISO14443B-2 ST SRx passive target(s) found%s\n", res, (res == 0) ?
".\n" :
":");
208 for (n = 0; n < res; n++) {
209 print_nfc_target(&ant[n], verbose);
214 nm.nmt = NMT_ISO14443B2CT;
219 if (verbose || (res > 0)) {
220 printf(
"%d ISO14443B-2 ASK CTx passive target(s) found%s\n", res, (res == 0) ?
".\n" :
":");
222 for (n = 0; n < res; n++) {
223 print_nfc_target(&ant[n], verbose);
233 if (verbose || (res > 0)) {
234 printf(
"%d Jewel passive target(s) found%s\n", res, (res == 0) ?
".\n" :
":");
236 for (n = 0; n < res; n++) {
237 print_nfc_target(&ant[n], verbose);
void nfc_init(nfc_context **context)
Initialize libnfc. This function must be called before calling any other libnfc function.
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.
const char * nfc_version(void)
Returns the library version.
int nfc_initiator_init(nfc_device *pnd)
Initialize NFC device as initiator (reader)
void nfc_perror(const nfc_device *pnd, const char *pcString)
Display the last error occured on 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_exit(nfc_context *context)
Deinitialize libnfc. Should be called after closing all open devices and before your application term...
nfc_device * nfc_open(nfc_context *context, const nfc_connstring connstring)
Open a NFC device.
NFC modulation structure.
char nfc_connstring[NFC_BUFSIZE_CONNSTRING]
const char * nfc_device_get_name(nfc_device *pnd)
Returns the device name.
#define ERR(...)
Print a error message.
void nfc_close(nfc_device *pnd)
Close from a NFC device.
NFC library context Struct which contains internal options, references, pointers, etc...
Provide some examples shared functions like print, parity calculation, options parsing.