56 #define MAX_FRAME_LEN 264
57 #define MAX_DEVICE_COUNT 2
59 static uint8_t abtReaderRx[MAX_FRAME_LEN];
60 static uint8_t abtReaderRxPar[MAX_FRAME_LEN];
61 static int szReaderRxBits;
62 static uint8_t abtTagRx[MAX_FRAME_LEN];
63 static uint8_t abtTagRxPar[MAX_FRAME_LEN];
64 static int szTagRxBits;
67 static bool quitting =
false;
73 printf(
"\nQuitting...\n");
79 print_usage(
char *argv[])
81 printf(
"Usage: %s [OPTIONS]\n", argv[0]);
83 printf(
"\t-h\tHelp. Print this message.\n");
84 printf(
"\t-q\tQuiet mode. Suppress output of READER and EMULATOR data (improves timing).\n");
88 main(
int argc,
char *argv[])
91 bool quiet_output =
false;
95 for (arg = 1; arg < argc; arg++) {
96 if (0 == strcmp(argv[arg],
"-h")) {
99 }
else if (0 == strcmp(argv[arg],
"-q")) {
102 ERR(
"%s is not supported option.", argv[arg]);
109 printf(
"%s uses libnfc %s\n", argv[0], acLibnfcVersion);
112 signal(SIGINT, (
void (__cdecl *)(
int)) intr_hdlr);
114 signal(SIGINT, intr_hdlr);
119 if (context == NULL) {
120 ERR(
"Unable to init libnfc (malloc)");
128 ERR(
"%" PRIdPTR
" device found but two opened devices are needed to relay NFC.", szFound);
134 pndTag =
nfc_open(context, connstrings[0]);
135 if (pndTag == NULL) {
136 ERR(
"Error opening NFC emulator device");
141 printf(
"Hint: tag <---> initiator (relay) <---> target (relay) <---> original reader\n\n");
144 printf(
"[+] Try to break out the auto-emulation, this requires a second reader!\n");
145 printf(
"[+] To do this, please send any command after the anti-collision\n");
146 printf(
"[+] For example, send a RATS command or use the \"nfc-anticol\" tool\n");
150 .nmt = NMT_ISO14443A,
151 .nbr = NBR_UNDEFINED,
155 .abtAtqa = { 0x04, 0x00 },
156 .abtUid = { 0x08, 0xad, 0xbe, 0xef },
164 if ((szReaderRxBits =
nfc_target_init(pndTag, &nt, abtReaderRx,
sizeof(abtReaderRx), 0)) < 0) {
165 ERR(
"%s",
"Initialization of NFC emulator failed");
170 printf(
"%s",
"Configuring emulator settings...");
173 nfc_perror(pndTag,
"nfc_device_set_property_bool");
178 printf(
"%s",
"Done, emulated tag is initialized");
181 pndReader =
nfc_open(context, connstrings[1]);
182 if (pndReader == NULL) {
183 printf(
"Error opening NFC reader device\n");
190 printf(
"%s",
"Configuring NFC reader settings...");
202 nfc_perror(pndReader,
"nfc_device_set_property_bool");
208 printf(
"%s",
"Done, relaying frames now!");
212 if ((szReaderRxBits =
nfc_target_receive_bits(pndTag, abtReaderRx,
sizeof(abtReaderRx), abtReaderRxPar)) > 0) {
214 if (szReaderRxBits == 7 && abtReaderRx[0] == 0x26) {
217 nfc_perror(pndReader,
"nfc_device_set_property_bool");
226 nfc_perror(pndReader,
"nfc_device_set_property_bool");
236 print_hex_par(abtReaderRx, (
size_t) szReaderRxBits, abtReaderRxPar);
240 (pndReader, abtReaderRx, (
size_t) szReaderRxBits, abtReaderRxPar, abtTagRx,
sizeof(abtTagRx), abtTagRxPar)) > 0) {
252 print_hex_par(abtTagRx, szTagRxBits, abtTagRxPar);