50 #endif // HAVE_CONFIG_H
63 #define MAX_FRAME_LEN 264
65 static uint8_t abtRecv[MAX_FRAME_LEN];
66 static int szRecvBits;
71 uint8_t abtAtqa[2] = { 0x04, 0x00 };
72 uint8_t abtUidBcc[5] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x22 };
73 uint8_t abtSak[9] = { 0x08, 0xb6, 0xdd };
80 printf(
"\nAborting current command...\n");
86 print_usage(
char *argv[])
88 printf(
"Usage: %s [OPTIONS] [UID]\n", argv[0]);
90 printf(
"\t-h\tHelp. Print this message.\n");
91 printf(
"\t-q\tQuiet mode. Silent output: received and sent frames will not be shown (improves timing).\n");
93 printf(
"\t[UID]\tUID to emulate, specified as 8 HEX digits (default is DEADBEEF).\n");
97 main(
int argc,
char *argv[])
99 uint8_t *pbtTx = NULL;
101 bool quiet_output =
false;
107 for (arg = 1; arg < argc; arg++) {
108 if (0 == strcmp(argv[arg],
"-h")) {
111 }
else if (0 == strcmp(argv[arg],
"-q")) {
112 printf(
"Quiet mode.\n");
114 }
else if ((arg == argc - 1) && (strlen(argv[arg]) == 8)) {
115 uint8_t abtTmp[3] = { 0x00, 0x00, 0x00 };
116 printf(
"[+] Using UID: %s\n", argv[arg]);
118 for (i = 0; i < 4; ++i) {
119 memcpy(abtTmp, argv[arg] + i * 2, 2);
120 abtUidBcc[i] = (uint8_t) strtol((
char *) abtTmp, NULL, 16);
121 abtUidBcc[4] ^= abtUidBcc[i];
124 ERR(
"%s is not supported option.", argv[arg]);
131 signal(SIGINT, (
void (__cdecl *)(
int)) intr_hdlr);
133 signal(SIGINT, intr_hdlr);
137 if (context == NULL) {
138 ERR(
"Unable to init libnfc (malloc)");
146 ERR(
"Unable to open NFC device");
153 printf(
"[+] Try to break out the auto-emulation, this requires a second NFC device!\n");
154 printf(
"[+] To do this, please send any command after the anti-collision\n");
155 printf(
"[+] For example, send a RATS command or use the \"nfc-anticol\" or \"nfc-list\" tool.\n");
160 .nmt = NMT_ISO14443A,
161 .nbr = NBR_UNDEFINED,
165 .abtAtqa = { 0x04, 0x00 },
166 .abtUid = { 0x08, 0xad, 0xbe, 0xef },
173 if ((szRecvBits =
nfc_target_init(pnd, &nt, abtRecv,
sizeof(abtRecv), 0)) < 0) {
175 ERR(
"Could not come out of auto-emulation, no command was received");
180 printf(
"[+] Received initiator command: ");
181 print_hex_bits(abtRecv, (
size_t) szRecvBits);
182 printf(
"[+] Configuring communication\n");
184 nfc_perror(pnd,
"nfc_device_set_property_bool");
189 printf(
"[+] Done, the emulated tag is initialized with UID: %02X%02X%02X%02X\n\n", abtUidBcc[0], abtUidBcc[1],
190 abtUidBcc[2], abtUidBcc[3]);
196 switch (szRecvBits) {
222 print_hex_bits(abtRecv, (
size_t) szRecvBits);
235 print_hex_bits(pbtTx, szTxBits);