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");
89 print_usage(
char *argv[])
91 printf(
"Usage: %s [OPTIONS] [UID]\n", argv[0]);
93 printf(
"\t-h\tHelp. Print this message.\n");
94 printf(
"\t-q\tQuiet mode. Silent output: received and sent frames will not be shown (improves timing).\n");
96 printf(
"\t[UID]\tUID to emulate, specified as 8 HEX digits (default is DEADBEEF).\n");
100 main(
int argc,
char *argv[])
102 uint8_t *pbtTx = NULL;
104 bool quiet_output =
false;
110 for (arg = 1; arg < argc; arg++) {
111 if (0 == strcmp(argv[arg],
"-h")) {
114 }
else if (0 == strcmp(argv[arg],
"-q")) {
115 printf(
"Quiet mode.\n");
117 }
else if ((arg == argc - 1) && (strlen(argv[arg]) == 8)) {
118 uint8_t abtTmp[3] = { 0x00, 0x00, 0x00 };
119 printf(
"[+] Using UID: %s\n", argv[arg]);
121 for (i = 0; i < 4; ++i) {
122 memcpy(abtTmp, argv[arg] + i * 2, 2);
123 abtUidBcc[i] = (uint8_t) strtol((
char *) abtTmp, NULL, 16);
124 abtUidBcc[4] ^= abtUidBcc[i];
127 ERR(
"%s is not supported option.", argv[arg]);
134 signal(SIGINT, (
void (__cdecl *)(
int)) intr_hdlr);
136 signal(SIGINT, intr_hdlr);
140 if (context == NULL) {
141 ERR(
"Unable to init libnfc (malloc)");
149 ERR(
"Unable to open NFC device");
156 printf(
"[+] Try to break out the auto-emulation, this requires a second NFC device!\n");
157 printf(
"[+] To do this, please send any command after the anti-collision\n");
158 printf(
"[+] For example, send a RATS command or use the \"nfc-anticol\" or \"nfc-list\" tool.\n");
163 .nmt = NMT_ISO14443A,
164 .nbr = NBR_UNDEFINED,
168 .abtAtqa = { 0x04, 0x00 },
169 .abtUid = { 0x08, 0xad, 0xbe, 0xef },
176 if ((szRecvBits =
nfc_target_init(pnd, &nt, abtRecv,
sizeof(abtRecv), 0)) < 0) {
178 ERR(
"Could not come out of auto-emulation, no command was received");
183 printf(
"[+] Received initiator command: ");
184 print_hex_bits(abtRecv, (
size_t) szRecvBits);
185 printf(
"[+] Configuring communication\n");
187 nfc_perror(pnd,
"nfc_device_set_property_bool");
192 printf(
"[+] Done, the emulated tag is initialized with UID: %02X%02X%02X%02X\n\n", abtUidBcc[0], abtUidBcc[1],
193 abtUidBcc[2], abtUidBcc[3]);
199 switch (szRecvBits) {
225 print_hex_bits(abtRecv, (
size_t) szRecvBits);
238 print_hex_bits(pbtTx, szTxBits);
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.
int nfc_abort_command(nfc_device *pnd)
Abort current running command.
void nfc_perror(const nfc_device *pnd, const char *pcString)
Display the last error occured on a nfc_device.
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.
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.
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....