37 #endif // HAVE_CONFIG_H
51 #define SAK_FLAG_ATS_SUPPORTED 0x20
53 #define MAX_FRAME_LEN 264
55 static byte_t abtRx[MAX_FRAME_LEN];
56 static size_t szRxBits;
58 static byte_t abtRawUid[12];
59 static byte_t abtAtqa[2];
61 static size_t szCL = 1;
64 bool quiet_output =
false;
67 byte_t abtReqa[1] = { 0x26 };
68 byte_t abtSelectAll[2] = { 0x93, 0x20 };
69 byte_t abtSelectTag[9] = { 0x93, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
70 byte_t abtRats[4] = { 0xe0, 0x50, 0x00, 0x00 };
71 byte_t abtHalt[4] = { 0x50, 0x00, 0x00, 0x00 };
72 #define CASCADE_BIT 0x04
75 transmit_bits (
const byte_t * pbtTx,
const size_t szTxBits)
79 printf (
"Sent bits: ");
80 print_hex_bits (pbtTx, szTxBits);
88 printf (
"Received bits: ");
89 print_hex_bits (abtRx, szRxBits);
97 transmit_bytes (
const byte_t * pbtTx,
const size_t szTx)
101 printf (
"Sent bits: ");
102 print_hex (pbtTx, szTx);
110 printf (
"Received bits: ");
111 print_hex (abtRx, szRx);
118 print_usage (
char *argv[])
120 printf (
"Usage: %s [OPTIONS]\n", argv[0]);
121 printf (
"Options:\n");
122 printf (
"\t-h\tHelp. Print this message.\n");
123 printf (
"\t-q\tQuiet mode. Suppress output of READER and EMULATOR data (improves timing).\n");
127 main (
int argc,
char *argv[])
132 for (arg = 1; arg < argc; arg++) {
133 if (0 == strcmp (argv[arg],
"-h")) {
136 }
else if (0 == strcmp (argv[arg],
"-q")) {
139 ERR (
"%s is not supported option.", argv[arg]);
149 printf (
"Error connecting NFC reader\n");
194 printf (
"Connected to NFC reader: %s\n\n", pnd->
acName);
197 if (!transmit_bits (abtReqa, 7)) {
198 printf (
"Error: No tag available\n");
202 memcpy (abtAtqa, abtRx, 2);
205 transmit_bytes (abtSelectAll, 2);
208 if ((abtRx[0] ^ abtRx[1] ^ abtRx[2] ^ abtRx[3] ^ abtRx[4]) != 0) {
209 printf(
"WARNING: BCC check failed!\n");
213 memcpy (abtRawUid, abtRx, 4);
216 memcpy (abtSelectTag + 2, abtRx, 5);
217 iso14443a_crc_append (abtSelectTag, 7);
218 transmit_bytes (abtSelectTag, 9);
222 if (abtSak & CASCADE_BIT) {
225 if (abtRawUid[0] != 0x88) {
226 printf(
"WARNING: Cascade bit set but CT != 0x88!\n");
234 abtSelectAll[0] = 0x95;
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 + 4, abtRx, 4);
248 abtSelectTag[0] = 0x95;
249 memcpy (abtSelectTag + 2, abtRx, 5);
250 iso14443a_crc_append (abtSelectTag, 7);
251 transmit_bytes (abtSelectTag, 9);
255 if (abtSak & CASCADE_BIT) {
258 if (abtRawUid[0] != 0x88) {
259 printf(
"WARNING: Cascade bit set but CT != 0x88!\n");
267 abtSelectAll[0] = 0x97;
268 transmit_bytes (abtSelectAll, 2);
271 if ((abtRx[0] ^ abtRx[1] ^ abtRx[2] ^ abtRx[3] ^ abtRx[4]) != 0) {
272 printf(
"WARNING: BCC check failed!\n");
276 memcpy (abtRawUid + 8, abtRx, 4);
279 abtSelectTag[0] = 0x97;
280 memcpy (abtSelectTag + 2, abtRx, 5);
281 iso14443a_crc_append (abtSelectTag, 7);
282 transmit_bytes (abtSelectTag, 9);
288 if (abtRx[0] & SAK_FLAG_ATS_SUPPORTED) {
289 iso14443a_crc_append(abtRats, 2);
290 transmit_bytes (abtRats, 4);
294 iso14443a_crc_append(abtHalt, 2);
295 transmit_bytes (abtHalt, 4);
297 printf (
"\nFound tag with\n UID: ");
300 printf (
"%02x%02x%02x%02x", abtRawUid[0], abtRawUid[1], abtRawUid[2], abtRawUid[3]);
303 printf (
"%02x%02x%02x", abtRawUid[1], abtRawUid[2], abtRawUid[3]);
304 printf (
"%02x%02x%02x%02x", abtRawUid[4], abtRawUid[5], abtRawUid[6], abtRawUid[7]);
307 printf (
"%02x%02x%02x", abtRawUid[1], abtRawUid[2], abtRawUid[3]);
308 printf (
"%02x%02x%02x", abtRawUid[5], abtRawUid[6], abtRawUid[7]);
309 printf (
"%02x%02x%02x%02x", abtRawUid[8], abtRawUid[9], abtRawUid[10], abtRawUid[11]);
313 printf(
"ATQA: %02x%02x\n SAK: %02x\n", abtAtqa[1], abtAtqa[0], abtSak);