44 #endif // HAVE_CONFIG_H 47 #if defined(HAVE_READLINE) 48 # include <readline/readline.h> 49 # include <readline/history.h> 50 #endif //HAVE_READLINE 59 # define msleep(x) do { \ 60 struct timespec xsleep; \ 61 xsleep.tv_sec = x / 1000; \ 62 xsleep.tv_nsec = (x - xsleep.tv_sec * 1000) * 1000 * 1000; \ 63 nanosleep(&xsleep, NULL); \ 74 #include "libnfc/chips/pn53x.h" 76 #define MAX_FRAME_LEN 264 78 int main(
int argc,
const char *argv[])
81 uint8_t abtRx[MAX_FRAME_LEN];
82 uint8_t abtTx[MAX_FRAME_LEN];
83 size_t szRx =
sizeof(abtRx);
88 if ((input = fopen(argv[1],
"r")) == NULL) {
89 ERR(
"%s",
"Cannot open file.");
96 if (context == NULL) {
97 ERR(
"Unable to init libnfc (malloc)");
105 ERR(
"%s",
"Unable to open NFC device.");
124 const char *prompt =
"> ";
128 #if defined(HAVE_READLINE) 130 cmd = readline(prompt);
138 #endif //HAVE_READLINE 142 printf(
"%s", prompt);
145 ret = fgets(cmd, n, input);
147 ret = fgets(cmd, n, stdin);
149 if (ret == NULL || strlen(cmd) <= 0) {
156 #if defined(HAVE_READLINE) 158 #endif //HAVE_READLINE 167 while (isspace(cmd[offset])) {
170 sscanf(cmd + offset,
"%10d", &ms);
171 printf(
"Pause for %i msecs\n", ms);
179 for (
int i = 0; i < MAX_FRAME_LEN; i++) {
182 while (isspace(cmd[offset])) {
185 size = sscanf(cmd + offset,
"%2x", &
byte);
191 if (cmd[offset + 1] == 0) {
202 print_hex(abtTx, szTx);
204 szRx =
sizeof(abtRx);
206 if ((res = pn53x_transceive(pnd, abtTx, szTx, abtRx, szRx, 0)) < 0) {
214 print_hex(abtRx, szRx);
void nfc_init(nfc_context **context)
Initialize libnfc. This function must be called before calling any other libnfc function.
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.
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.
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.