36 static const byte_t OddParity[256] = {
37 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
38 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
39 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
40 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
41 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
42 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
43 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
44 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
45 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
46 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
47 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
48 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
49 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
50 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
51 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
52 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1
56 oddparity (
const byte_t bt)
62 oddparity_bytes_ts (
const byte_t * pbtData,
const size_t szLen, byte_t * pbtPar)
66 for (szByteNr = 0; szByteNr < szLen; szByteNr++) {
67 pbtPar[szByteNr] = OddParity[pbtData[szByteNr]];
72 print_hex (
const byte_t * pbtData,
const size_t szBytes)
76 for (szPos = 0; szPos < szBytes; szPos++) {
77 printf (
"%02x ", pbtData[szPos]);
83 print_hex_bits (
const byte_t * pbtData,
const size_t szBits)
87 size_t szBytes = szBits / 8;
89 for (szPos = 0; szPos < szBytes; szPos++) {
90 printf (
"%02x ", pbtData[szPos]);
93 uRemainder = szBits % 8;
95 if (uRemainder != 0) {
97 printf (
"%01x (%d bits)", pbtData[szBytes], uRemainder);
99 printf (
"%02x (%d bits)", pbtData[szBytes], uRemainder);
105 print_hex_par (
const byte_t * pbtData,
const size_t szBits,
const byte_t * pbtDataPar)
109 size_t szBytes = szBits / 8;
111 for (szPos = 0; szPos < szBytes; szPos++) {
112 printf (
"%02x", pbtData[szPos]);
113 if (OddParity[pbtData[szPos]] != pbtDataPar[szPos]) {
120 uRemainder = szBits % 8;
122 if (uRemainder != 0) {
124 printf (
"%01x (%d bits)", pbtData[szBytes], uRemainder);
126 printf (
"%02x (%d bits)", pbtData[szBytes], uRemainder);
131 #define SAK_UID_NOT_COMPLETE 0x04
132 #define SAK_ISO14443_4_COMPLIANT 0x20
133 #define SAK_ISO18092_COMPLIANT 0x40
138 printf (
" ATQA (SENS_RES): ");
139 print_hex (nai.abtAtqa, 2);
141 printf(
"* UID size: ");
142 switch ((nai.abtAtqa[1] & 0xc0)>>6) {
156 printf(
"* bit frame anticollision ");
157 switch (nai.abtAtqa[1] & 0x1f) {
163 printf(
"supported\n");
166 printf(
"not supported\n");
170 printf (
" UID (NFCID%c): ", (nai.abtUid[0] == 0x08 ?
'3' :
'1'));
171 print_hex (nai.abtUid, nai.szUidLen);
173 if (nai.abtUid[0] == 0x08) {
174 printf (
"* Random UID\n");
177 printf (
" SAK (SEL_RES): ");
178 print_hex (&nai.btSak, 1);
180 if (nai.btSak & SAK_UID_NOT_COMPLETE) {
181 printf (
"* Warning! Cascade bit set: UID not complete\n");
183 if (nai.btSak & SAK_ISO14443_4_COMPLIANT) {
184 printf (
"* Compliant with ISO/IEC 14443-4\n");
186 printf (
"* Not compliant with ISO/IEC 14443-4\n");
188 if (nai.btSak & SAK_ISO18092_COMPLIANT) {
189 printf (
"* Compliant with ISO/IEC 18092\n");
191 printf (
"* Not compliant with ISO/IEC 18092\n");
196 print_hex (nai.abtAts, nai.szAtsLen);
198 if (nai.szAtsLen && verbose) {
200 const int iMaxFrameSizes[] = { 16, 24, 32, 40, 48, 64, 96, 128, 256 };
201 printf (
"* Max Frame Size accepted by PICC: %d bytes\n", iMaxFrameSizes[nai.abtAts[0] & 0x0F]);
204 if (nai.abtAts[0] & 0x10) {
205 byte_t TA = nai.abtAts[offset];
207 printf (
"* Bit Rate Capability:\n");
209 printf (
" * PICC supports only 106 kbits/s in both directions\n");
212 printf (
" * Same bitrate in both directions mandatory\n");
215 printf (
" * PICC to PCD, DS=2, bitrate 212 kbits/s supported\n");
218 printf (
" * PICC to PCD, DS=4, bitrate 424 kbits/s supported\n");
221 printf (
" * PICC to PCD, DS=8, bitrate 847 kbits/s supported\n");
224 printf (
" * PCD to PICC, DR=2, bitrate 212 kbits/s supported\n");
227 printf (
" * PCD to PICC, DR=4, bitrate 424 kbits/s supported\n");
230 printf (
" * PCD to PICC, DR=8, bitrate 847 kbits/s supported\n");
233 printf (
" * ERROR unknown value\n");
236 if (nai.abtAts[0] & 0x20) {
237 byte_t TB= nai.abtAts[offset];
239 printf (
"* Frame Waiting Time: %.4g ms\n",256.0*16.0*(1<<((TB & 0xf0) >> 4))/13560.0);
240 if ((TB & 0x0f) == 0) {
241 printf (
"* No Start-up Frame Guard Time required\n");
243 printf (
"* Start-up Frame Guard Time: %.4g ms\n",256.0*16.0*(1<<(TB & 0x0f))/13560.0);
246 if (nai.abtAts[0] & 0x40) {
247 byte_t TC = nai.abtAts[offset];
250 printf(
"* Node ADdress supported\n");
252 printf(
"* Node ADdress not supported\n");
255 printf(
"* Card IDentifier supported\n");
257 printf(
"* Card IDentifier not supported\n");
260 if (nai.szAtsLen > offset) {
261 printf (
"* Historical bytes Tk: " );
262 print_hex (nai.abtAts + offset, (nai.szAtsLen - offset));
263 byte_t CIB = nai.abtAts[offset];
265 if (CIB != 0x00 && CIB != 0x10 && (CIB & 0xf0) != 0x80) {
266 printf(
" * Proprietary format\n");
268 printf(
" * Tag byte: Mifare or virtual cards of various types\n");
269 byte_t L = nai.abtAts[offset];
271 if (L != (nai.szAtsLen - offset)) {
272 printf(
" * Warning: Type Identification Coding length (%i)", L);
273 printf(
" not matching Tk length (%zi)\n", (nai.szAtsLen - offset));
275 if ((nai.szAtsLen - offset - 2) > 0) {
276 byte_t CTC = nai.abtAts[offset];
278 printf(
" * Chip Type: ");
279 switch (CTC & 0xf0) {
281 printf(
"(Multiple) Virtual Cards\n");
284 printf(
"Mifare DESFire\n");
287 printf(
"Mifare Plus\n");
293 printf(
" * Memory size: ");
294 switch (CTC & 0x0f) {
296 printf(
"<1 kbyte\n");
311 printf(
"Unspecified\n");
318 if ((nai.szAtsLen - offset) > 0) {
319 byte_t CVC = nai.abtAts[offset];
321 printf(
" * Chip Status: ");
322 switch (CVC & 0xf0) {
324 printf(
"Engineering sample\n");
327 printf(
"Released\n");
333 printf(
" * Chip Generation: ");
334 switch (CVC & 0x0f) {
336 printf(
"Generation 1\n");
339 printf(
"Generation 2\n");
342 printf(
"Generation 3\n");
345 printf(
"Unspecified\n");
352 if ((nai.szAtsLen - offset) > 0) {
353 byte_t VCS = nai.abtAts[offset];
355 printf(
" * Specifics (Virtual Card Selection):\n");
356 if ((VCS & 0x09) == 0x00) {
357 printf(
" * Only VCSL supported\n");
358 }
else if ((VCS & 0x09) == 0x01) {
359 printf(
" * VCS, VCSL and SVC supported\n");
361 if ((VCS & 0x0e) == 0x00) {
362 printf(
" * SL1, SL2(?), SL3 supported\n");
363 }
else if ((VCS & 0x0e) == 0x02) {
364 printf(
" * SL3 only card\n");
365 }
else if ((VCS & 0x0f) == 0x0e) {
366 printf(
" * No VCS command supported\n");
367 }
else if ((VCS & 0x0f) == 0x0f) {
368 printf(
" * Unspecified\n");
376 printf(
" * Tk after 0x00 consist of optional consecutive COMPACT-TLV data objects\n");
377 printf(
" followed by a mandatory status indicator (the last three bytes, not in TLV)\n");
378 printf(
" See ISO/IEC 7816-4 8.1.1.3 for more info\n");
381 printf(
" * DIR data reference: %02x\n", nai.abtAts[offset]);
384 if (nai.szAtsLen == offset) {
385 printf(
" * No COMPACT-TLV objects found, no status found\n");
387 printf(
" * Tk after 0x80 consist of optional consecutive COMPACT-TLV data objects;\n");
388 printf(
" the last data object may carry a status indicator of one, two or three bytes.\n");
389 printf(
" See ISO/IEC 7816-4 8.1.1.3 for more info\n");
396 printf(
"Fingerprinting based on ATQA & SAK values:\n");
397 uint32_t atqasak = 0;
398 atqasak += (((uint32_t)nai.abtAtqa[0] & 0xff)<<16);
399 atqasak += (((uint32_t)nai.abtAtqa[1] & 0xff)<<8);
400 atqasak += ((uint32_t)nai.btSak & 0xff);
401 bool found_possible_match =
false;
404 printf(
"* Mifare Classic 4K\n");
405 found_possible_match =
true;
408 printf(
"* Mifare Classic 1K\n");
409 printf(
"* Mifare Plus (4-byte UID) 2K SL1\n");
410 found_possible_match =
true;
413 printf(
"* Mifare MINI\n");
414 found_possible_match =
true;
417 printf(
"* Mifare Plus (4-byte UID) 2K SL2\n");
418 found_possible_match =
true;
421 printf(
"* Mifare Plus (4-byte UID) 4K SL2\n");
422 found_possible_match =
true;
425 printf(
"* Mifare Plus (4-byte UID) 4K SL1\n");
426 found_possible_match =
true;
429 printf(
"* Mifare Plus (4-byte UID) 2K/4K SL3\n");
430 found_possible_match =
true;
433 printf(
"* Mifare Ultralight\n");
434 printf(
"* Mifare UltralightC\n");
435 found_possible_match =
true;
439 printf(
"* Mifare Plus (7-byte UID) 2K SL1\n");
440 found_possible_match =
true;
444 printf(
"* Mifare Plus (7-byte UID) 4K SL1\n");
445 found_possible_match =
true;
449 printf(
"* Mifare Plus (7-byte UID) 2K SL2\n");
450 found_possible_match =
true;
454 printf(
"* Mifare Plus (7-byte UID) 4K SL2\n");
455 found_possible_match =
true;
459 printf(
"* Mifare Plus (7-byte UID) 2K/4K SL3\n");
460 found_possible_match =
true;
463 printf(
"* Mifare DESFire / Desfire EV1\n");
464 found_possible_match =
true;
473 printf(
"* Mifare Classic 1K Infineon\n");
474 found_possible_match =
true;
477 printf(
"* Gemplus MPCOS\n");
478 found_possible_match =
true;
481 printf(
"* JCOP31\n");
482 found_possible_match =
true;
485 printf(
"* JCOP31 v2.4.1\n");
486 printf(
"* JCOP31 v2.2\n");
487 found_possible_match =
true;
490 printf(
"* JCOP31 v2.3.1\n");
491 found_possible_match =
true;
494 printf(
"* Fudan FM1208SH01\n");
495 found_possible_match =
true;
498 printf(
"* Fudan FM1208\n");
499 found_possible_match =
true;
502 printf(
"* MFC 4K emulated by Nokia 6212 Classic\n");
503 found_possible_match =
true;
506 printf(
"* MFC 4K emulated by Nokia 6131 NFC\n");
507 found_possible_match =
true;
510 if ((nai.abtAtqa[0] & 0xf0) == 0) {
511 switch (nai.abtAtqa[1]) {
513 printf(
"* SmartMX with Mifare 4K emulation\n");
514 found_possible_match =
true;
517 printf(
"* SmartMX with Mifare 1K emulation\n");
518 found_possible_match =
true;
521 printf(
"* SmartMX with 7-byte UID\n");
522 found_possible_match =
true;
526 if (! found_possible_match) {
527 printf(
"* Unknown card, sorry\n");
535 printf (
" ID (NFCID2): ");
536 print_hex (nfi.abtId, 8);
537 printf (
" Parameter (PAD): ");
538 print_hex (nfi.abtPad, 8);
544 printf (
" ATQA (SENS_RES): ");
545 print_hex (nji.btSensRes, 2);
546 printf (
" 4-LSB JEWELID: ");
547 print_hex (nji.btId, 4);
550 #define PI_ISO14443_4_SUPPORTED 0x01
551 #define PI_NAD_SUPPORTED 0x01
552 #define PI_CID_SUPPORTED 0x02
556 const int iMaxFrameSizes[] = { 16, 24, 32, 40, 48, 64, 96, 128, 256 };
559 printf (
" Application Data: ");
561 printf (
" Protocol Info: ");
564 printf (
"* Bit Rate Capability:\n");
566 printf (
" * PICC supports only 106 kbits/s in both directions\n");
569 printf (
" * Same bitrate in both directions mandatory\n");
572 printf (
" * PICC to PCD, 1etu=64/fc, bitrate 212 kbits/s supported\n");
575 printf (
" * PICC to PCD, 1etu=32/fc, bitrate 424 kbits/s supported\n");
578 printf (
" * PICC to PCD, 1etu=16/fc, bitrate 847 kbits/s supported\n");
581 printf (
" * PCD to PICC, 1etu=64/fc, bitrate 212 kbits/s supported\n");
584 printf (
" * PCD to PICC, 1etu=32/fc, bitrate 424 kbits/s supported\n");
587 printf (
" * PCD to PICC, 1etu=16/fc, bitrate 847 kbits/s supported\n");
590 printf (
" * ERROR unknown value\n");
593 printf (
"* Maximum frame sizes: %d bytes\n", iMaxFrameSizes[((nbi.
abtProtocolInfo[1] & 0xf0) >> 4)]);
596 printf (
"* Protocol types supported: ISO/IEC 14443-4\n");
598 printf (
"* Frame Waiting Time: %.4g ms\n",256.0*16.0*(1<<((nbi.
abtProtocolInfo[2] & 0xf0) >> 4))/13560.0);
599 if((nbi.
abtProtocolInfo[2] & (PI_NAD_SUPPORTED|PI_CID_SUPPORTED)) != 0) {
600 printf (
"* Frame options supported: ");
611 printf (
" NFCID3: ");
613 printf (
" BS: %02x\n", ndi.
btBS);
614 printf (
" BR: %02x\n", ndi.
btBR);
615 printf (
" TO: %02x\n", ndi.
btTO);
616 printf (
" PP: %02x\n", ndi.
btPP);
618 printf (
"General Bytes: ");
619 print_hex (ndi.
abtGB, ndi.szGB);
628 parse_args (
int argc,
const char *argv[],
size_t * szFound,
bool * verbose)
635 for (arg = 1; arg < argc; arg++) {
637 if (0 == strcmp (argv[arg],
"--device")) {
639 if (argc > arg + 1) {
644 strncpy (buffer, argv[++arg], 256);
647 pndd->
pcDriver = (
char *) malloc (256);
648 strcpy (pndd->
pcDriver, strtok (buffer,
":"));
651 pndd->
pcPort = (
char *) malloc (256);
652 strcpy (pndd->
pcPort, strtok (NULL,
":"));
655 sscanf (strtok (NULL,
":"),
"%u", &pndd->
uiSpeed);
659 errx (1,
"usage: %s [--device driver:port:speed]", argv[0]);
662 if ((0 == strcmp (argv[arg],
"-v")) || (0 == strcmp (argv[arg],
"--verbose"))) {
674 return "undefined baud rate";
697 printf (
"ISO/IEC 14443A (%s) target:\n", str_nfc_baud_rate(nt.nm.nbr));
698 print_nfc_iso14443a_info (nt.nti.nai, verbose);
701 printf (
"Innovision Jewel (%s) target:\n", str_nfc_baud_rate(nt.nm.nbr));
702 print_nfc_jewel_info (nt.nti.nji, verbose);
705 printf (
"FeliCa (%s) target:\n", str_nfc_baud_rate(nt.nm.nbr));
706 print_nfc_felica_info (nt.nti.nfi, verbose);
709 printf (
"ISO/IEC 14443-4B (%s) target:\n", str_nfc_baud_rate(nt.nm.nbr));
710 print_nfc_iso14443b_info (nt.nti.nbi, verbose);
713 printf (
"D.E.P. (%s) target:\n", str_nfc_baud_rate(nt.nm.nbr));
714 print_nfc_dep_info (nt.nti.ndi, verbose);