56 #define MAX_DEVICE_COUNT 16
57 #define MAX_TARGET_COUNT 16
62 print_usage(
const char *argv[])
64 printf(
"Usage: %s [OPTIONS]\n", argv[0]);
66 printf(
"\t-h\tPrint this help message.\n");
67 printf(
"\t-v\tSet verbose display.\n");
68 printf(
"\t-i\tAllow intrusive scan.\n");
72 main(
int argc,
const char *argv[])
74 const char *acLibnfcVersion;
81 for (
int arg = 1; arg < argc; arg++) {
82 if (0 == strcmp(argv[arg],
"-h")) {
85 }
else if (0 == strcmp(argv[arg],
"-v")) {
87 }
else if (0 == strcmp(argv[arg],
"-i")) {
89 setenv(
"LIBNFC_INTRUSIVE_SCAN",
"yes", 1);
91 ERR(
"%s is not supported option.", argv[arg]);
98 if (context == NULL) {
99 ERR(
"Unable to init libnfc (malloc)\n");
105 printf(
"%s uses libnfc %s\n", argv[0], acLibnfcVersion);
108 size_t szDeviceFound =
nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT);
110 if (szDeviceFound == 0) {
111 printf(
"No NFC device found.\n");
116 printf(
"%d NFC device(s) found:\n", (
int)szDeviceFound);
117 char *strinfo = NULL;
118 for (i = 0; i < szDeviceFound; i++) {
119 pnd =
nfc_open(context, connstrings[i]);
124 printf(
"%s", strinfo);
130 printf(
"nfc_open failed for %s\n", connstrings[i]);
const char * nfc_device_get_connstring(nfc_device *pnd)
Returns the device connection string.
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_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.
void nfc_free(void *p)
Free buffer allocated by libnfc.
int nfc_device_get_information_about(nfc_device *pnd, char **buf)
Print information about NFC device.
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....