53 #include "libnfc/chips/pn53x.h"
55 #define MAX_DEVICE_COUNT 16
58 main(
int argc,
const char *argv[])
62 const char *acLibnfcVersion;
65 uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
66 size_t szRx =
sizeof(abtRx);
67 const uint8_t pncmd_diagnose_communication_line_test[] = { Diagnose, 0x00, 0x06,
'l',
'i',
'b',
'n',
'f',
'c' };
68 const uint8_t pncmd_diagnose_rom_test[] = { Diagnose, 0x01 };
69 const uint8_t pncmd_diagnose_ram_test[] = { Diagnose, 0x02 };
72 printf(
"Usage: %s", argv[0]);
78 if (context == NULL) {
79 ERR(
"Unable to init libnfc (malloc)");
85 printf(
"%s uses libnfc %s\n", argv[0], acLibnfcVersion);
91 printf(
"No NFC device found.\n");
94 for (i = 0; i < szFound; i++) {
96 pnd =
nfc_open(context, connstrings[i]);
99 ERR(
"%s",
"Unable to open NFC device.");
106 res = pn53x_transceive(pnd, pncmd_diagnose_communication_line_test,
sizeof(pncmd_diagnose_communication_line_test), abtRx, szRx, 0);
110 result = (memcmp(pncmd_diagnose_communication_line_test + 1, abtRx,
sizeof(pncmd_diagnose_communication_line_test) - 1) == 0) ||
111 (memcmp(pncmd_diagnose_communication_line_test + 2, abtRx,
sizeof(pncmd_diagnose_communication_line_test) - 2) == 0);
112 printf(
" Communication line test: %s\n", result ?
"OK" :
"Failed");
114 nfc_perror(pnd,
"pn53x_transceive: cannot diagnose communication line");
117 res = pn53x_transceive(pnd, pncmd_diagnose_rom_test,
sizeof(pncmd_diagnose_rom_test), abtRx, szRx, 0);
120 result = ((szRx == 1) && (abtRx[0] == 0x00));
121 printf(
" ROM test: %s\n", result ?
"OK" :
"Failed");
123 nfc_perror(pnd,
"pn53x_transceive: cannot diagnose ROM");
126 res = pn53x_transceive(pnd, pncmd_diagnose_ram_test,
sizeof(pncmd_diagnose_ram_test), abtRx, szRx, 0);
129 result = ((szRx == 1) && (abtRx[0] == 0x00));
130 printf(
" RAM test: %s\n", result ?
"OK" :
"Failed");
132 nfc_perror(pnd,
"pn53x_transceive: cannot diagnose RAM");
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.
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....