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);