2010-04-09 23:57:03 +02:00
|
|
|
#include <nfc/nfc.h>
|
|
|
|
|
|
|
|
#include "nfc-utils.h"
|
|
|
|
|
2010-04-16 18:38:57 +02:00
|
|
|
static const byte_t OddParity[256] = {
|
|
|
|
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
|
|
|
|
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
|
|
|
|
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
|
|
|
|
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
|
|
|
|
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
|
|
|
|
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
|
|
|
|
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
|
|
|
|
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
|
|
|
|
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
|
|
|
|
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
|
|
|
|
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
|
|
|
|
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
|
|
|
|
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
|
|
|
|
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
|
|
|
|
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
|
|
|
|
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1
|
|
|
|
};
|
|
|
|
|
2010-09-07 19:51:03 +02:00
|
|
|
byte_t
|
|
|
|
oddparity (const byte_t bt)
|
2010-09-06 12:02:19 +02:00
|
|
|
{
|
|
|
|
return OddParity[bt];
|
|
|
|
}
|
|
|
|
|
2010-09-07 19:51:03 +02:00
|
|
|
void
|
|
|
|
oddparity_bytes_ts (const byte_t * pbtData, const size_t szLen, byte_t * pbtPar)
|
2010-09-06 12:02:19 +02:00
|
|
|
{
|
2010-09-07 19:51:03 +02:00
|
|
|
size_t szByteNr;
|
2010-09-06 12:02:19 +02:00
|
|
|
// Calculate the parity bits for the command
|
2010-09-07 19:51:03 +02:00
|
|
|
for (szByteNr = 0; szByteNr < szLen; szByteNr++) {
|
2010-09-06 12:02:19 +02:00
|
|
|
pbtPar[szByteNr] = OddParity[pbtData[szByteNr]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-07 19:51:03 +02:00
|
|
|
void
|
|
|
|
print_hex (const byte_t * pbtData, const size_t szBytes)
|
2010-04-16 18:38:57 +02:00
|
|
|
{
|
2010-09-07 19:51:03 +02:00
|
|
|
size_t szPos;
|
2010-04-16 18:38:57 +02:00
|
|
|
|
2010-09-07 19:51:03 +02:00
|
|
|
for (szPos = 0; szPos < szBytes; szPos++) {
|
|
|
|
printf ("%02x ", pbtData[szPos]);
|
2010-04-16 18:38:57 +02:00
|
|
|
}
|
2010-09-07 19:51:03 +02:00
|
|
|
printf ("\n");
|
2010-04-16 18:38:57 +02:00
|
|
|
}
|
|
|
|
|
2010-09-07 19:51:03 +02:00
|
|
|
void
|
|
|
|
print_hex_bits (const byte_t * pbtData, const size_t szBits)
|
2010-04-16 18:38:57 +02:00
|
|
|
{
|
|
|
|
uint8_t uRemainder;
|
2010-09-07 19:51:03 +02:00
|
|
|
size_t szPos;
|
|
|
|
size_t szBytes = szBits / 8;
|
2010-04-16 18:38:57 +02:00
|
|
|
|
2010-09-07 19:51:03 +02:00
|
|
|
for (szPos = 0; szPos < szBytes; szPos++) {
|
|
|
|
printf ("%02x ", pbtData[szPos]);
|
2010-04-16 18:38:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uRemainder = szBits % 8;
|
|
|
|
// Print the rest bits
|
2010-09-07 19:51:03 +02:00
|
|
|
if (uRemainder != 0) {
|
2010-04-16 18:38:57 +02:00
|
|
|
if (uRemainder < 5)
|
2010-09-07 19:51:03 +02:00
|
|
|
printf ("%01x (%d bits)", pbtData[szBytes], uRemainder);
|
2010-04-16 18:38:57 +02:00
|
|
|
else
|
2010-09-07 19:51:03 +02:00
|
|
|
printf ("%02x (%d bits)", pbtData[szBytes], uRemainder);
|
2010-04-16 18:38:57 +02:00
|
|
|
}
|
2010-09-07 19:51:03 +02:00
|
|
|
printf ("\n");
|
2010-04-16 18:38:57 +02:00
|
|
|
}
|
|
|
|
|
2010-09-07 19:51:03 +02:00
|
|
|
void
|
|
|
|
print_hex_par (const byte_t * pbtData, const size_t szBits, const byte_t * pbtDataPar)
|
2010-04-16 18:38:57 +02:00
|
|
|
{
|
|
|
|
uint8_t uRemainder;
|
2010-09-07 19:51:03 +02:00
|
|
|
size_t szPos;
|
|
|
|
size_t szBytes = szBits / 8;
|
|
|
|
|
|
|
|
for (szPos = 0; szPos < szBytes; szPos++) {
|
|
|
|
printf ("%02x", pbtData[szPos]);
|
|
|
|
if (OddParity[pbtData[szPos]] != pbtDataPar[szPos]) {
|
|
|
|
printf ("! ");
|
2010-04-16 18:38:57 +02:00
|
|
|
} else {
|
2010-09-07 19:51:03 +02:00
|
|
|
printf (" ");
|
2010-04-16 18:38:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uRemainder = szBits % 8;
|
|
|
|
// Print the rest bits, these cannot have parity bit
|
2010-09-07 19:51:03 +02:00
|
|
|
if (uRemainder != 0) {
|
2010-04-16 18:38:57 +02:00
|
|
|
if (uRemainder < 5)
|
2010-09-07 19:51:03 +02:00
|
|
|
printf ("%01x (%d bits)", pbtData[szBytes], uRemainder);
|
2010-04-16 18:38:57 +02:00
|
|
|
else
|
2010-09-07 19:51:03 +02:00
|
|
|
printf ("%02x (%d bits)", pbtData[szBytes], uRemainder);
|
2010-04-16 18:38:57 +02:00
|
|
|
}
|
2010-09-07 19:51:03 +02:00
|
|
|
printf ("\n");
|
2010-04-16 18:38:57 +02:00
|
|
|
}
|
|
|
|
|
2010-08-17 17:24:37 +02:00
|
|
|
#define SAK_ISO14443_4_COMPLIANT 0x20
|
|
|
|
#define SAK_ISO18092_COMPLIANT 0x40
|
|
|
|
|
2010-09-07 19:51:03 +02:00
|
|
|
void
|
|
|
|
print_nfc_iso14443a_info (const nfc_iso14443a_info_t nai)
|
2010-04-09 23:57:03 +02:00
|
|
|
{
|
2010-09-07 19:51:03 +02:00
|
|
|
printf (" ATQA (SENS_RES): ");
|
|
|
|
print_hex (nai.abtAtqa, 2);
|
|
|
|
printf (" UID (NFCID%c): ", (nai.abtUid[0] == 0x08 ? '3' : '1'));
|
|
|
|
print_hex (nai.abtUid, nai.szUidLen);
|
|
|
|
printf (" SAK (SEL_RES): ");
|
|
|
|
print_hex (&nai.btSak, 1);
|
2010-10-15 10:33:46 +02:00
|
|
|
if ((nai.btSak & SAK_ISO14443_4_COMPLIANT) || (nai.btSak & SAK_ISO18092_COMPLIANT)) {
|
|
|
|
printf ("* Compliant with: ");
|
|
|
|
if (nai.btSak & SAK_ISO14443_4_COMPLIANT)
|
|
|
|
printf ("ISO/IEC 14443-4 ");
|
|
|
|
if (nai.btSak & SAK_ISO18092_COMPLIANT)
|
|
|
|
printf ("ISO/IEC 18092");
|
|
|
|
printf ("\n");
|
|
|
|
}
|
2010-04-09 23:57:03 +02:00
|
|
|
if (nai.szAtsLen) {
|
2010-10-15 10:33:46 +02:00
|
|
|
printf (" ATS: ");
|
2010-09-07 19:51:03 +02:00
|
|
|
print_hex (nai.abtAts, nai.szAtsLen);
|
2010-04-09 23:57:03 +02:00
|
|
|
}
|
2010-10-14 16:48:59 +02:00
|
|
|
if (nai.szAtsLen) {
|
|
|
|
// Decode ATS according to ISO/IEC 14443-4 (5.2 Answer to select)
|
2010-10-15 10:33:46 +02:00
|
|
|
const int iMaxFrameSizes[] = { 16, 24, 32, 40, 48, 64, 96, 128, 256 };
|
|
|
|
printf ("* Max Frame Size accepted by PICC: %d bytes\n", iMaxFrameSizes[nai.abtAts[0] & 0x0F]);
|
|
|
|
|
2010-10-14 16:48:59 +02:00
|
|
|
size_t offset = 1;
|
2010-10-15 10:33:46 +02:00
|
|
|
if (nai.abtAts[0] & 0x10) { // TA(1) present
|
|
|
|
byte_t TA = nai.abtAts[offset];
|
2010-10-14 16:48:59 +02:00
|
|
|
offset++;
|
2010-10-15 10:33:46 +02:00
|
|
|
printf ("* Bit Rate Capability:\n");
|
|
|
|
if (TA == 0) {
|
|
|
|
printf (" * PICC supports only 106 kbits/s in both directions\n");
|
|
|
|
}
|
|
|
|
if (TA & 1<<7) {
|
|
|
|
printf (" * Same bitrate in both directions mandatory\n");
|
|
|
|
}
|
|
|
|
if (TA & 1<<4) {
|
|
|
|
printf (" * PICC to PCD, DS=2, bitrate 212 kbits/s supported\n");
|
|
|
|
}
|
|
|
|
if (TA & 1<<5) {
|
|
|
|
printf (" * PICC to PCD, DS=4, bitrate 424 kbits/s supported\n");
|
|
|
|
}
|
|
|
|
if (TA & 1<<6) {
|
|
|
|
printf (" * PICC to PCD, DS=8, bitrate 847 kbits/s supported\n");
|
|
|
|
}
|
|
|
|
if (TA & 1<<0) {
|
|
|
|
printf (" * PCD to PICC, DR=2, bitrate 212 kbits/s supported\n");
|
|
|
|
}
|
|
|
|
if (TA & 1<<1) {
|
|
|
|
printf (" * PCD to PICC, DR=4, bitrate 424 kbits/s supported\n");
|
|
|
|
}
|
|
|
|
if (TA & 1<<2) {
|
|
|
|
printf (" * PCD to PICC, DR=8, bitrate 847 kbits/s supported\n");
|
|
|
|
}
|
|
|
|
if (TA & 1<<3) {
|
|
|
|
printf (" * ERROR unknown value\n");
|
|
|
|
}
|
2010-10-14 16:48:59 +02:00
|
|
|
}
|
2010-10-15 10:33:46 +02:00
|
|
|
if (nai.abtAts[0] & 0x20) { // TB(1) present
|
|
|
|
byte_t TB= nai.abtAts[offset];
|
2010-10-14 16:48:59 +02:00
|
|
|
offset++;
|
2010-10-15 10:33:46 +02:00
|
|
|
printf ("* Frame Waiting Time: %.4g ms\n",256.0*16.0*(1<<((TB & 0xf0) >> 4))/13560.0);
|
|
|
|
if ((TB & 0x0f) == 0) {
|
|
|
|
printf ("* No Start-up Frame Guard Time required\n");
|
|
|
|
} else {
|
|
|
|
printf ("* Start-up Frame Guard Time: %.4g ms\n",256.0*16.0*(1<<(TB & 0x0f))/13560.0);
|
|
|
|
}
|
2010-10-14 16:48:59 +02:00
|
|
|
}
|
2010-10-15 10:33:46 +02:00
|
|
|
if (nai.abtAts[0] & 0x40) { // TC(1) present
|
|
|
|
byte_t TC = nai.abtAts[offset];
|
2010-10-14 16:48:59 +02:00
|
|
|
offset++;
|
2010-10-15 10:33:46 +02:00
|
|
|
if (TC & 0x1) {
|
|
|
|
printf("* Node ADdress supported\n");
|
|
|
|
} else {
|
|
|
|
printf("* Node ADdress not supported\n");
|
|
|
|
}
|
|
|
|
if (TC & 0x2) {
|
|
|
|
printf("* Card IDentifier supported\n");
|
|
|
|
} else {
|
|
|
|
printf("* Card IDentifier not supported\n");
|
|
|
|
}
|
2010-10-14 16:48:59 +02:00
|
|
|
}
|
|
|
|
if (nai.szAtsLen > offset) {
|
2010-10-15 10:33:46 +02:00
|
|
|
printf ("* Historical bytes Tk: " );
|
2010-10-14 18:28:16 +02:00
|
|
|
print_hex (nai.abtAts + offset, (nai.szAtsLen - offset));
|
2010-10-15 10:57:58 +02:00
|
|
|
byte_t CIB = nai.abtAts[offset];
|
|
|
|
offset++;
|
|
|
|
if (CIB != 0x00 && CIB != 0x10 && (CIB & 0xf0) != 0x80) {
|
|
|
|
printf(" * Proprietary format\n");
|
|
|
|
} else {
|
|
|
|
if (CIB == 0x00) {
|
|
|
|
printf(" * Tk after 0x00 consist of optional consecutive COMPACT-TLV data objects\n");
|
|
|
|
printf(" followed by a mandatory status indicator (the last three bytes, not in TLV)\n");
|
|
|
|
printf(" See ISO/IEC 7816-4 8.1.1.3 for more info\n");
|
|
|
|
}
|
|
|
|
if (CIB == 0x10) {
|
|
|
|
printf(" * DIR data reference: %02x\n", nai.abtAts[offset]);
|
|
|
|
}
|
|
|
|
if (CIB == 0x80) {
|
|
|
|
if (nai.szAtsLen == offset) {
|
|
|
|
printf(" * No COMPACT-TLV objects found, no status found\n");
|
|
|
|
} else {
|
|
|
|
printf(" * Tk after 0x80 consist of optional consecutive COMPACT-TLV data objects;\n");
|
|
|
|
printf(" the last data object may carry a status indicator of one, two or three bytes.\n");
|
|
|
|
printf(" See ISO/IEC 7816-4 8.1.1.3 for more info\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-10-14 16:48:59 +02:00
|
|
|
}
|
|
|
|
}
|
2010-04-09 23:57:03 +02:00
|
|
|
}
|
2010-09-07 19:51:03 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
print_nfc_felica_info (const nfc_felica_info_t nfi)
|
2010-08-18 14:50:40 +02:00
|
|
|
{
|
2010-09-07 19:51:03 +02:00
|
|
|
printf (" ID (NFCID2): ");
|
|
|
|
print_hex (nfi.abtId, 8);
|
|
|
|
printf (" Parameter (PAD): ");
|
|
|
|
print_hex (nfi.abtPad, 8);
|
2010-08-18 14:50:40 +02:00
|
|
|
}
|
|
|
|
|
2010-09-28 17:31:31 +02:00
|
|
|
void
|
|
|
|
print_nfc_jewel_info (const nfc_jewel_info_t nji)
|
|
|
|
{
|
2010-10-15 10:33:46 +02:00
|
|
|
printf (" ATQA (SENS_RES): ");
|
|
|
|
print_hex (nji.btSensRes, 2);
|
2010-09-28 17:37:36 +02:00
|
|
|
printf (" 4-LSB JEWELID: ");
|
2010-09-28 17:31:31 +02:00
|
|
|
print_hex (nji.btId, 4);
|
|
|
|
}
|
|
|
|
|
2010-09-23 19:03:19 +02:00
|
|
|
#define PI_ISO14443_4_SUPPORTED 0x01
|
|
|
|
#define PI_NAD_SUPPORTED 0x01
|
|
|
|
#define PI_CID_SUPPORTED 0x02
|
2010-09-07 19:51:03 +02:00
|
|
|
void
|
|
|
|
print_nfc_iso14443b_info (const nfc_iso14443b_info_t nbi)
|
2010-08-18 14:50:40 +02:00
|
|
|
{
|
2010-09-23 19:03:19 +02:00
|
|
|
const int iMaxFrameSizes[] = { 16, 24, 32, 40, 48, 64, 96, 128, 256 };
|
2010-09-23 18:26:06 +02:00
|
|
|
printf (" PUPI: ");
|
|
|
|
print_hex (nbi.abtPupi, 4);
|
|
|
|
printf (" Application Data: ");
|
|
|
|
print_hex (nbi.abtApplicationData, 4);
|
|
|
|
printf (" Protocol Info: ");
|
|
|
|
print_hex (nbi.abtProtocolInfo, 3);
|
2010-10-15 10:33:46 +02:00
|
|
|
printf ("* Bit Rate Capability:\n");
|
2010-09-28 17:27:06 +02:00
|
|
|
if (nbi.abtProtocolInfo[0] == 0) {
|
2010-10-15 10:33:46 +02:00
|
|
|
printf (" * PICC supports only 106 kbits/s in both directions\n");
|
2010-09-28 17:27:06 +02:00
|
|
|
}
|
|
|
|
if (nbi.abtProtocolInfo[0] & 1<<7) {
|
2010-10-15 10:33:46 +02:00
|
|
|
printf (" * Same bitrate in both directions mandatory\n");
|
2010-09-28 17:27:06 +02:00
|
|
|
}
|
|
|
|
if (nbi.abtProtocolInfo[0] & 1<<4) {
|
2010-10-15 10:33:46 +02:00
|
|
|
printf (" * PICC to PCD, 1etu=64/fc, bitrate 212 kbits/s supported\n");
|
2010-09-28 17:27:06 +02:00
|
|
|
}
|
|
|
|
if (nbi.abtProtocolInfo[0] & 1<<5) {
|
2010-10-15 10:33:46 +02:00
|
|
|
printf (" * PICC to PCD, 1etu=32/fc, bitrate 424 kbits/s supported\n");
|
2010-09-28 17:27:06 +02:00
|
|
|
}
|
|
|
|
if (nbi.abtProtocolInfo[0] & 1<<6) {
|
2010-10-15 10:33:46 +02:00
|
|
|
printf (" * PICC to PCD, 1etu=16/fc, bitrate 847 kbits/s supported\n");
|
2010-09-28 17:27:06 +02:00
|
|
|
}
|
|
|
|
if (nbi.abtProtocolInfo[0] & 1<<0) {
|
2010-10-15 10:33:46 +02:00
|
|
|
printf (" * PCD to PICC, 1etu=64/fc, bitrate 212 kbits/s supported\n");
|
2010-09-28 17:27:06 +02:00
|
|
|
}
|
|
|
|
if (nbi.abtProtocolInfo[0] & 1<<1) {
|
2010-10-15 10:33:46 +02:00
|
|
|
printf (" * PCD to PICC, 1etu=32/fc, bitrate 424 kbits/s supported\n");
|
2010-09-28 17:27:06 +02:00
|
|
|
}
|
|
|
|
if (nbi.abtProtocolInfo[0] & 1<<2) {
|
2010-10-15 10:33:46 +02:00
|
|
|
printf (" * PCD to PICC, 1etu=16/fc, bitrate 847 kbits/s supported\n");
|
2010-09-28 17:27:06 +02:00
|
|
|
}
|
|
|
|
if (nbi.abtProtocolInfo[0] & 1<<3) {
|
2010-10-15 10:33:46 +02:00
|
|
|
printf (" * ERROR unknown value\n");
|
2010-09-28 17:27:06 +02:00
|
|
|
}
|
2010-09-23 19:03:19 +02:00
|
|
|
if( (nbi.abtProtocolInfo[1] & 0xf0) <= 0x80 ) {
|
2010-10-15 10:33:46 +02:00
|
|
|
printf ("* Maximum frame sizes: %d bytes\n", iMaxFrameSizes[((nbi.abtProtocolInfo[1] & 0xf0) >> 4)]);
|
2010-09-23 19:03:19 +02:00
|
|
|
}
|
|
|
|
if((nbi.abtProtocolInfo[1] & 0x0f) == PI_ISO14443_4_SUPPORTED) {
|
2010-10-15 10:33:46 +02:00
|
|
|
printf ("* Protocol types supported: ISO/IEC 14443-4\n");
|
2010-09-23 19:03:19 +02:00
|
|
|
}
|
2010-10-15 10:33:46 +02:00
|
|
|
printf ("* Frame Waiting Time: %.4g ms\n",256.0*16.0*(1<<((nbi.abtProtocolInfo[2] & 0xf0) >> 4))/13560.0);
|
2010-09-23 19:03:19 +02:00
|
|
|
if((nbi.abtProtocolInfo[2] & (PI_NAD_SUPPORTED|PI_CID_SUPPORTED)) != 0) {
|
2010-10-15 10:33:46 +02:00
|
|
|
printf ("* Frame options supported: ");
|
2010-09-23 19:03:19 +02:00
|
|
|
if ((nbi.abtProtocolInfo[2] & PI_NAD_SUPPORTED) != 0) printf ("NAD ");
|
|
|
|
if ((nbi.abtProtocolInfo[2] & PI_CID_SUPPORTED) != 0) printf ("CID ");
|
|
|
|
printf("\n");
|
|
|
|
}
|
2010-08-18 14:50:40 +02:00
|
|
|
}
|
2010-04-16 18:38:57 +02:00
|
|
|
|
2010-10-08 22:25:34 +02:00
|
|
|
void
|
|
|
|
print_nfc_dep_info (const nfc_dep_info_t ndi)
|
|
|
|
{
|
|
|
|
printf (" NFCID3: ");
|
|
|
|
print_hex (ndi.abtNFCID3, 10);
|
|
|
|
printf (" BS: %02x\n", ndi.btBS);
|
|
|
|
printf (" BR: %02x\n", ndi.btBR);
|
|
|
|
printf (" TO: %02x\n", ndi.btTO);
|
|
|
|
printf (" PP: %02x\n", ndi.btPP);
|
|
|
|
if (ndi.szGB) {
|
|
|
|
printf ("General Bytes: ");
|
|
|
|
print_hex (ndi.abtGB, ndi.szGB);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-22 18:13:02 +02:00
|
|
|
/**
|
|
|
|
* @brief Tries to parse arguments to find device descriptions.
|
|
|
|
* @return Returns the list of found device descriptions.
|
|
|
|
*/
|
2010-09-07 19:51:03 +02:00
|
|
|
nfc_device_desc_t *
|
|
|
|
parse_device_desc (int argc, const char *argv[], size_t * szFound)
|
2010-07-22 18:13:02 +02:00
|
|
|
{
|
2010-09-07 19:51:03 +02:00
|
|
|
nfc_device_desc_t *pndd = 0;
|
|
|
|
int arg;
|
2010-08-10 21:50:29 +02:00
|
|
|
*szFound = 0;
|
2010-07-22 18:13:02 +02:00
|
|
|
|
|
|
|
// Get commandline options
|
2010-09-07 19:51:03 +02:00
|
|
|
for (arg = 1; arg < argc; arg++) {
|
2010-07-22 18:13:02 +02:00
|
|
|
|
2010-09-07 19:51:03 +02:00
|
|
|
if (0 == strcmp (argv[arg], "--device")) {
|
2010-07-22 18:13:02 +02:00
|
|
|
|
2010-09-07 19:51:03 +02:00
|
|
|
if (argc > arg + 1) {
|
|
|
|
char buffer[256];
|
2010-07-22 18:13:02 +02:00
|
|
|
|
2010-09-07 19:51:03 +02:00
|
|
|
pndd = malloc (sizeof (nfc_device_desc_t));
|
2010-07-22 18:13:02 +02:00
|
|
|
|
2010-09-07 19:51:03 +02:00
|
|
|
strncpy (buffer, argv[++arg], 256);
|
2010-07-22 18:13:02 +02:00
|
|
|
|
|
|
|
// Driver.
|
2010-09-07 19:51:03 +02:00
|
|
|
pndd->pcDriver = (char *) malloc (256);
|
|
|
|
strcpy (pndd->pcDriver, strtok (buffer, ":"));
|
2010-07-22 18:13:02 +02:00
|
|
|
|
|
|
|
// Port.
|
2010-09-07 19:51:03 +02:00
|
|
|
pndd->pcPort = (char *) malloc (256);
|
|
|
|
strcpy (pndd->pcPort, strtok (NULL, ":"));
|
2010-07-22 18:13:02 +02:00
|
|
|
|
|
|
|
// Speed.
|
2010-09-07 19:51:03 +02:00
|
|
|
sscanf (strtok (NULL, ":"), "%u", &pndd->uiSpeed);
|
2010-07-22 18:13:02 +02:00
|
|
|
|
|
|
|
*szFound = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pndd;
|
|
|
|
}
|
2010-10-13 19:43:23 +02:00
|
|
|
|
2010-10-13 21:17:51 +02:00
|
|
|
const char *
|
|
|
|
str_nfc_baud_rate (const nfc_baud_rate_t nbr)
|
|
|
|
{
|
|
|
|
switch(nbr) {
|
|
|
|
case NBR_UNDEFINED:
|
|
|
|
return "undefined baud rate";
|
|
|
|
break;
|
|
|
|
case NBR_106:
|
|
|
|
return "106 kbps";
|
|
|
|
break;
|
|
|
|
case NBR_212:
|
|
|
|
return "212 kbps";
|
|
|
|
break;
|
|
|
|
case NBR_424:
|
|
|
|
return "424 kbps";
|
|
|
|
break;
|
|
|
|
}
|
2010-10-13 23:40:54 +02:00
|
|
|
return "";
|
2010-10-13 21:17:51 +02:00
|
|
|
}
|
|
|
|
|
2010-10-13 19:43:23 +02:00
|
|
|
void
|
|
|
|
print_nfc_target (const nfc_target_t nt)
|
|
|
|
{
|
2010-10-13 21:17:51 +02:00
|
|
|
switch(nt.nm.nmt) {
|
2010-10-13 19:43:23 +02:00
|
|
|
case NMT_ISO14443A:
|
2010-10-13 21:17:51 +02:00
|
|
|
printf ("ISO/IEC 14443A (%s) target:\n", str_nfc_baud_rate(nt.nm.nbr));
|
2010-10-13 19:43:23 +02:00
|
|
|
print_nfc_iso14443a_info (nt.nti.nai);
|
|
|
|
break;
|
|
|
|
case NMT_JEWEL:
|
2010-10-13 21:17:51 +02:00
|
|
|
printf ("Innovision Jewel (%s) target:\n", str_nfc_baud_rate(nt.nm.nbr));
|
2010-10-13 19:43:23 +02:00
|
|
|
print_nfc_jewel_info (nt.nti.nji);
|
|
|
|
break;
|
|
|
|
case NMT_FELICA:
|
2010-10-13 21:17:51 +02:00
|
|
|
printf ("FeliCa (%s) target:\n", str_nfc_baud_rate(nt.nm.nbr));
|
2010-10-13 19:43:23 +02:00
|
|
|
print_nfc_felica_info (nt.nti.nfi);
|
|
|
|
break;
|
|
|
|
case NMT_ISO14443B:
|
2010-10-13 21:17:51 +02:00
|
|
|
printf ("ISO/IEC 14443-4B (%s) target:\n", str_nfc_baud_rate(nt.nm.nbr));
|
2010-10-13 19:43:23 +02:00
|
|
|
print_nfc_iso14443b_info (nt.nti.nbi);
|
|
|
|
break;
|
|
|
|
case NMT_DEP:
|
2010-10-13 21:17:51 +02:00
|
|
|
printf ("D.E.P. (%s) target:\n", str_nfc_baud_rate(nt.nm.nbr));
|
2010-10-13 19:43:23 +02:00
|
|
|
print_nfc_dep_info (nt.nti.ndi);
|
|
|
|
break;
|
|
|
|
}
|
2010-10-13 23:40:54 +02:00
|
|
|
}
|
|
|
|
|