49 #endif // HAVE_CONFIG_H
62 #define MAX_FRAME_LEN 264
64 static uint8_t abtRecv[MAX_FRAME_LEN];
65 static int szRecvBits;
70 uint8_t abtAtqa[2] = { 0x04, 0x00 };
71 uint8_t abtUidBcc[5] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x22 };
72 uint8_t abtSak[9] = { 0x08, 0xb6, 0xdd };
79 printf(
"\nAborting current command...\n");
85 print_usage(
char *argv[])
87 printf(
"Usage: %s [OPTIONS] [UID]\n", argv[0]);
89 printf(
"\t-h\tHelp. Print this message.\n");
90 printf(
"\t-q\tQuiet mode. Silent output: received and sent frames will not be shown (improves timing).\n");
92 printf(
"\t[UID]\tUID to emulate, specified as 8 HEX digits (default is DEADBEEF).\n");
96 main(
int argc,
char *argv[])
98 uint8_t *pbtTx = NULL;
100 bool quiet_output =
false;
106 for (arg = 1; arg < argc; arg++) {
107 if (0 == strcmp(argv[arg],
"-h")) {
110 }
else if (0 == strcmp(argv[arg],
"-q")) {
111 printf(
"Quiet mode.\n");
113 }
else if ((arg == argc - 1) && (strlen(argv[arg]) == 8)) {
114 uint8_t abtTmp[3] = { 0x00, 0x00, 0x00 };
115 printf(
"[+] Using UID: %s\n", argv[arg]);
117 for (i = 0; i < 4; ++i) {
118 memcpy(abtTmp, argv[arg] + i * 2, 2);
119 abtUidBcc[i] = (uint8_t) strtol((
char *) abtTmp, NULL, 16);
120 abtUidBcc[4] ^= abtUidBcc[i];
123 ERR(
"%s is not supported option.", argv[arg]);
130 signal(SIGINT, (
void (__cdecl *)(
int)) intr_hdlr);
132 signal(SIGINT, intr_hdlr);
136 if (context == NULL) {
137 ERR(
"Unable to init libnfc (malloc)");
145 ERR(
"Unable to open NFC device");
152 printf(
"[+] Try to break out the auto-emulation, this requires a second NFC device!\n");
153 printf(
"[+] To do this, please send any command after the anti-collision\n");
154 printf(
"[+] For example, send a RATS command or use the \"nfc-anticol\" or \"nfc-list\" tool.\n");
159 .nmt = NMT_ISO14443A,
160 .nbr = NBR_UNDEFINED,
164 .abtAtqa = { 0x04, 0x00 },
165 .abtUid = { 0x08, 0xad, 0xbe, 0xef },
172 if ((szRecvBits =
nfc_target_init(pnd, &nt, abtRecv,
sizeof(abtRecv), 0)) < 0) {
174 ERR(
"Could not come out of auto-emulation, no command was received");
179 printf(
"[+] Received initiator command: ");
180 print_hex_bits(abtRecv, (
size_t) szRecvBits);
181 printf(
"[+] Configuring communication\n");
183 nfc_perror(pnd,
"nfc_device_set_property_bool");
188 printf(
"[+] Done, the emulated tag is initialized with UID: %02X%02X%02X%02X\n\n", abtUidBcc[0], abtUidBcc[1],
189 abtUidBcc[2], abtUidBcc[3]);
195 switch (szRecvBits) {
221 print_hex_bits(abtRecv, (
size_t) szRecvBits);
234 print_hex_bits(pbtTx, szTxBits);