57 #define MAX_FRAME_LEN 264
58 #define MAX_DEVICE_COUNT 2
60 static uint8_t abtReaderRx[MAX_FRAME_LEN];
61 static uint8_t abtReaderRxPar[MAX_FRAME_LEN];
62 static int szReaderRxBits;
63 static uint8_t abtTagRx[MAX_FRAME_LEN];
64 static uint8_t abtTagRxPar[MAX_FRAME_LEN];
65 static int szTagRxBits;
68 static bool quitting =
false;
74 printf(
"\nQuitting...\n");
80 print_usage(
char *argv[])
82 printf(
"Usage: %s [OPTIONS]\n", argv[0]);
84 printf(
"\t-h\tHelp. Print this message.\n");
85 printf(
"\t-q\tQuiet mode. Suppress output of READER and EMULATOR data (improves timing).\n");
89 main(
int argc,
char *argv[])
92 bool quiet_output =
false;
96 for (arg = 1; arg < argc; arg++) {
97 if (0 == strcmp(argv[arg],
"-h")) {
100 }
else if (0 == strcmp(argv[arg],
"-q")) {
103 ERR(
"%s is not supported option.", argv[arg]);
110 printf(
"%s uses libnfc %s\n", argv[0], acLibnfcVersion);
113 signal(SIGINT, (
void (__cdecl *)(
int)) intr_hdlr);
115 signal(SIGINT, intr_hdlr);
120 if (context == NULL) {
121 ERR(
"Unable to init libnfc (malloc)");
129 ERR(
"%" PRIdPTR
" device found but two opened devices are needed to relay NFC.", szFound);
135 pndTag =
nfc_open(context, connstrings[0]);
136 if (pndTag == NULL) {
137 ERR(
"Error opening NFC emulator device");
142 printf(
"Hint: tag <---> initiator (relay) <---> target (relay) <---> original reader\n\n");
145 printf(
"[+] Try to break out the auto-emulation, this requires a second reader!\n");
146 printf(
"[+] To do this, please send any command after the anti-collision\n");
147 printf(
"[+] For example, send a RATS command or use the \"nfc-anticol\" tool\n");
151 .nmt = NMT_ISO14443A,
152 .nbr = NBR_UNDEFINED,
156 .abtAtqa = { 0x04, 0x00 },
157 .abtUid = { 0x08, 0xad, 0xbe, 0xef },
165 if ((szReaderRxBits =
nfc_target_init(pndTag, &nt, abtReaderRx,
sizeof(abtReaderRx), 0)) < 0) {
166 ERR(
"%s",
"Initialization of NFC emulator failed");
171 printf(
"%s",
"Configuring emulator settings...");
174 nfc_perror(pndTag,
"nfc_device_set_property_bool");
179 printf(
"%s",
"Done, emulated tag is initialized");
182 pndReader =
nfc_open(context, connstrings[1]);
183 if (pndReader == NULL) {
184 printf(
"Error opening NFC reader device\n");
191 printf(
"%s",
"Configuring NFC reader settings...");
203 nfc_perror(pndReader,
"nfc_device_set_property_bool");
209 printf(
"%s",
"Done, relaying frames now!");
213 if ((szReaderRxBits =
nfc_target_receive_bits(pndTag, abtReaderRx,
sizeof(abtReaderRx), abtReaderRxPar)) > 0) {
215 if (szReaderRxBits == 7 && abtReaderRx[0] == 0x26) {
218 nfc_perror(pndReader,
"nfc_device_set_property_bool");
227 nfc_perror(pndReader,
"nfc_device_set_property_bool");
237 print_hex_par(abtReaderRx, (
size_t) szReaderRxBits, abtReaderRxPar);
241 (pndReader, abtReaderRx, (
size_t) szReaderRxBits, abtReaderRxPar, abtTagRx,
sizeof(abtTagRx), abtTagRxPar)) > 0) {
253 print_hex_par(abtTagRx, szTagRxBits, abtTagRxPar);
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.
int nfc_initiator_transceive_bits(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, const size_t szRx, uint8_t *pbtRxPar)
Transceive raw bit-frames to a target.
int nfc_initiator_init(nfc_device *pnd)
Initialize NFC device as initiator (reader)
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.
int nfc_device_set_property_bool(nfc_device *pnd, const nfc_property property, const bool bEnable)
Set a device's boolean-property value.
int nfc_target_send_bits(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar)
Send raw bit-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_bits(nfc_device *pnd, uint8_t *pbtRx, const size_t szRx, uint8_t *pbtRxPar)
Receive bit-frames.
@ NP_ACCEPT_INVALID_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....