54 #define MAX_FRAME_LEN 264
59 static void stop_dep_communication(
int sig)
71 main(
int argc,
const char *argv[])
73 uint8_t abtRx[MAX_FRAME_LEN];
75 uint8_t abtTx[] =
"Hello Mars!";
78 printf(
"Usage: %s\n", argv[0]);
83 if (context == NULL) {
84 ERR(
"Unable to init libnfc (malloc)");
87 #define MAX_DEVICE_COUNT 2
89 size_t szDeviceFound =
nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT);
94 if (szDeviceFound == 1) {
95 pnd =
nfc_open(context, connstrings[0]);
96 }
else if (szDeviceFound > 1) {
97 pnd =
nfc_open(context, connstrings[1]);
99 printf(
"No device found.\n");
111 .abtNFCID3 = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xff, 0x00, 0x00 },
113 .abtGB = { 0x12, 0x34, 0x56, 0x78 },
114 .ndm = NDM_UNDEFINED,
126 printf(
"Unable to open NFC device.\n");
132 signal(SIGINT, stop_dep_communication);
134 printf(
"NFC device will now act as: ");
135 print_nfc_target(&nt,
false);
137 printf(
"Waiting for initiator request...\n");
145 printf(
"Initiator request received. Waiting for data...\n");
152 abtRx[(size_t) szRx] =
'\0';
153 printf(
"Received: %s\n", abtRx);
155 printf(
"Sending: %s\n", abtTx);
162 printf(
"Data sent.\n");
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.
int nfc_abort_command(nfc_device *pnd)
Abort current running command.
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.
int nfc_target_send_bytes(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, int timeout)
Send bytes and APDU frames.
int nfc_target_init(nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t szRx, int timeout)
Initialize NFC device as an emulated tag.
int nfc_target_receive_bytes(nfc_device *pnd, uint8_t *pbtRx, const size_t szRx, int timeout)
Receive bytes and APDU frames.
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....