43 #endif // HAVE_CONFIG_H
56 #define SAK_FLAG_ATS_SUPPORTED 0x20
58 #define MAX_FRAME_LEN 264
60 static uint8_t abtRx[MAX_FRAME_LEN];
62 static size_t szRx =
sizeof(abtRx);
63 static uint8_t abtRawUid[12];
64 static uint8_t abtAtqa[2];
65 static uint8_t abtSak;
66 static uint8_t abtAts[MAX_FRAME_LEN];
67 static uint8_t szAts = 0;
68 static size_t szCL = 1;
71 bool quiet_output =
false;
72 bool force_rats =
false;
74 bool iso_ats_supported =
false;
77 uint8_t abtReqa[1] = { 0x26 };
78 uint8_t abtSelectAll[2] = { 0x93, 0x20 };
79 uint8_t abtSelectTag[9] = { 0x93, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
80 uint8_t abtRats[4] = { 0xe0, 0x50, 0x00, 0x00 };
81 uint8_t abtHalt[4] = { 0x50, 0x00, 0x00, 0x00 };
82 #define CASCADE_BIT 0x04
85 transmit_bits(
const uint8_t *pbtTx,
const size_t szTxBits)
90 printf(
"Sent bits: ");
91 print_hex_bits(pbtTx, szTxBits);
97 if ((!quiet_output) && (szRxBits > 0)) {
98 printf(
"Response after %u cycles\n", cycles);
106 printf(
"Received bits: ");
107 print_hex_bits(abtRx, szRxBits);
115 transmit_bytes(
const uint8_t *pbtTx,
const size_t szTx)
120 printf(
"Sent bits: ");
121 print_hex(pbtTx, szTx);
128 if ((!quiet_output) && (res > 0)) {
129 printf(
"Response after %u cycles\n", cycles);
138 printf(
"Received bits: ");
139 print_hex(abtRx, szRx);
146 print_usage(
char *argv[])
148 printf(
"Usage: %s [OPTIONS]\n", argv[0]);
149 printf(
"Options:\n");
150 printf(
"\t-h\tHelp. Print this message.\n");
151 printf(
"\t-q\tQuiet mode. Suppress output of READER and EMULATOR data (improves timing).\n");
152 printf(
"\t-f\tForce RATS.\n");
153 printf(
"\t-t\tMeasure response time (in cycles).\n");
157 main(
int argc,
char *argv[])
162 for (arg = 1; arg < argc; arg++) {
163 if (0 == strcmp(argv[arg],
"-h")) {
166 }
else if (0 == strcmp(argv[arg],
"-q")) {
168 }
else if (0 == strcmp(argv[arg],
"-f")) {
170 }
else if (0 == strcmp(argv[arg],
"-t")) {
173 ERR(
"%s is not supported option.", argv[arg]);
181 if (context == NULL) {
182 ERR(
"Unable to init libnfc (malloc)");
190 ERR(
"Error opening NFC reader");
205 nfc_perror(pnd,
"nfc_device_set_property_bool");
212 nfc_perror(pnd,
"nfc_device_set_property_bool");
219 nfc_perror(pnd,
"nfc_device_set_property_bool");
228 if (!transmit_bits(abtReqa, 7)) {
229 printf(
"Error: No tag available\n");
234 memcpy(abtAtqa, abtRx, 2);
237 transmit_bytes(abtSelectAll, 2);
240 if ((abtRx[0] ^ abtRx[1] ^ abtRx[2] ^ abtRx[3] ^ abtRx[4]) != 0) {
241 printf(
"WARNING: BCC check failed!\n");
245 memcpy(abtRawUid, abtRx, 4);
248 memcpy(abtSelectTag + 2, abtRx, 5);
249 iso14443a_crc_append(abtSelectTag, 7);
250 transmit_bytes(abtSelectTag, 9);
254 if (abtSak & CASCADE_BIT) {
257 if (abtRawUid[0] != 0x88) {
258 printf(
"WARNING: Cascade bit set but CT != 0x88!\n");
266 abtSelectAll[0] = 0x95;
269 transmit_bytes(abtSelectAll, 2);
272 if ((abtRx[0] ^ abtRx[1] ^ abtRx[2] ^ abtRx[3] ^ abtRx[4]) != 0) {
273 printf(
"WARNING: BCC check failed!\n");
277 memcpy(abtRawUid + 4, abtRx, 4);
280 abtSelectTag[0] = 0x95;
281 memcpy(abtSelectTag + 2, abtRx, 5);
282 iso14443a_crc_append(abtSelectTag, 7);
283 transmit_bytes(abtSelectTag, 9);
287 if (abtSak & CASCADE_BIT) {
290 if (abtRawUid[0] != 0x88) {
291 printf(
"WARNING: Cascade bit set but CT != 0x88!\n");
299 abtSelectAll[0] = 0x97;
300 transmit_bytes(abtSelectAll, 2);
303 if ((abtRx[0] ^ abtRx[1] ^ abtRx[2] ^ abtRx[3] ^ abtRx[4]) != 0) {
304 printf(
"WARNING: BCC check failed!\n");
308 memcpy(abtRawUid + 8, abtRx, 4);
311 abtSelectTag[0] = 0x97;
312 memcpy(abtSelectTag + 2, abtRx, 5);
313 iso14443a_crc_append(abtSelectTag, 7);
314 transmit_bytes(abtSelectTag, 9);
321 iso_ats_supported =
true;
323 if ((abtRx[0] & SAK_FLAG_ATS_SUPPORTED) || force_rats) {
324 iso14443a_crc_append(abtRats, 2);
325 if (transmit_bytes(abtRats, 4)) {
326 memcpy(abtAts, abtRx, szRx);
332 iso14443a_crc_append(abtHalt, 2);
333 transmit_bytes(abtHalt, 4);
335 printf(
"\nFound tag with\n UID: ");
338 printf(
"%02x%02x%02x%02x", abtRawUid[0], abtRawUid[1], abtRawUid[2], abtRawUid[3]);
341 printf(
"%02x%02x%02x", abtRawUid[1], abtRawUid[2], abtRawUid[3]);
342 printf(
"%02x%02x%02x%02x", abtRawUid[4], abtRawUid[5], abtRawUid[6], abtRawUid[7]);
345 printf(
"%02x%02x%02x", abtRawUid[1], abtRawUid[2], abtRawUid[3]);
346 printf(
"%02x%02x%02x", abtRawUid[5], abtRawUid[6], abtRawUid[7]);
347 printf(
"%02x%02x%02x%02x", abtRawUid[8], abtRawUid[9], abtRawUid[10], abtRawUid[11]);
351 printf(
"ATQA: %02x%02x\n SAK: %02x\n", abtAtqa[1], abtAtqa[0], abtSak);
353 if (force_rats && ! iso_ats_supported) {
354 printf(
" RATS forced\n");
357 print_hex(abtAts, szAts);