Convert by value passing of nfc_target to pointer for str_nfc_target and nfc_initiator_target_is_present

This becomes more consistent with all other pass by pointer of most structures.
Additionally, this should lessen stack memory usage, as building strings with str_nfc_target would push the target (283 bytes) plus then a copy of the info objects (up to 275) onto the stack as it dives into the sprintf functions.

Lastly, this makes my attempt at a .NET wrapper easier, as I can make passing by pointer work, but passing by value seems to bomb on the interop right now.
This commit is contained in:
Alex Lian 2013-03-03 23:40:07 -05:00 committed by Philippe Teuwen
parent a262be5633
commit c72846e3c6
16 changed files with 156 additions and 154 deletions

View file

@ -103,7 +103,7 @@ main(int argc, const char *argv[])
nfc_exit(context); nfc_exit(context);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
print_nfc_target(nt, false); print_nfc_target(&nt, false);
printf("Sending: %s\n", abtTx); printf("Sending: %s\n", abtTx);
int res; int res;

View file

@ -126,7 +126,7 @@ main(int argc, const char *argv[])
signal(SIGINT, stop_dep_communication); signal(SIGINT, stop_dep_communication);
printf("NFC device will now act as: "); printf("NFC device will now act as: ");
print_nfc_target(nt, false); print_nfc_target(&nt, false);
printf("Waiting for initiator request...\n"); printf("Waiting for initiator request...\n");
if ((szRx = nfc_target_init(pnd, &nt, abtRx, sizeof(abtRx), 0)) < 0) { if ((szRx = nfc_target_init(pnd, &nt, abtRx, sizeof(abtRx), 0)) < 0) {

View file

@ -266,7 +266,7 @@ main(int argc, char *argv[])
*/ */
printf("%s will emulate this ISO14443-A tag:\n", argv[0]); printf("%s will emulate this ISO14443-A tag:\n", argv[0]);
print_nfc_target(nt, true); print_nfc_target(&nt, true);
// Switch off NP_EASY_FRAMING if target is not ISO14443-4 // Switch off NP_EASY_FRAMING if target is not ISO14443-4
nfc_device_set_property_bool(pnd, NP_EASY_FRAMING, (nt.nti.nai.btSak & SAK_ISO14443_4_COMPLIANT)); nfc_device_set_property_bool(pnd, NP_EASY_FRAMING, (nt.nti.nai.btSak & SAK_ISO14443_4_COMPLIANT));

View file

@ -137,7 +137,7 @@ main(int argc, const char *argv[])
} }
if (res > 0) { if (res > 0) {
print_nfc_target(nt, verbose); print_nfc_target(&nt, verbose);
} else { } else {
printf("No target found.\n"); printf("No target found.\n");
} }

View file

@ -101,7 +101,7 @@ extern "C" {
NFC_EXPORT int nfc_initiator_transceive_bits(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, const size_t szRx, uint8_t *pbtRxPar); NFC_EXPORT int nfc_initiator_transceive_bits(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, const size_t szRx, uint8_t *pbtRxPar);
NFC_EXPORT int nfc_initiator_transceive_bytes_timed(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, const size_t szRx, uint32_t *cycles); NFC_EXPORT int nfc_initiator_transceive_bytes_timed(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, const size_t szRx, uint32_t *cycles);
NFC_EXPORT int nfc_initiator_transceive_bits_timed(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, const size_t szRx, uint8_t *pbtRxPar, uint32_t *cycles); NFC_EXPORT int nfc_initiator_transceive_bits_timed(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, const size_t szRx, uint8_t *pbtRxPar, uint32_t *cycles);
NFC_EXPORT int nfc_initiator_target_is_present(nfc_device *pnd, const nfc_target nt); NFC_EXPORT int nfc_initiator_target_is_present(nfc_device *pnd, const nfc_target *pnt);
/* NFC target: act as tag (i.e. MIFARE Classic) or NFC target device. */ /* NFC target: act as tag (i.e. MIFARE Classic) or NFC target device. */
NFC_EXPORT int nfc_target_init(nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t szRx, int timeout); NFC_EXPORT int nfc_target_init(nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t szRx, int timeout);
@ -138,7 +138,7 @@ extern "C" {
/* String converter functions */ /* String converter functions */
NFC_EXPORT const char *str_nfc_modulation_type(const nfc_modulation_type nmt); NFC_EXPORT const char *str_nfc_modulation_type(const nfc_modulation_type nmt);
NFC_EXPORT const char *str_nfc_baud_rate(const nfc_baud_rate nbr); NFC_EXPORT const char *str_nfc_baud_rate(const nfc_baud_rate nbr);
NFC_EXPORT int str_nfc_target(char **buf, const nfc_target nt, bool verbose); NFC_EXPORT int str_nfc_target(char **buf, const nfc_target *pnt, bool verbose);
/* Error codes */ /* Error codes */
/** @ingroup error /** @ingroup error

View file

@ -1668,10 +1668,10 @@ pn53x_initiator_deselect_target(struct nfc_device *pnd)
} }
int int
pn53x_initiator_target_is_present(struct nfc_device *pnd, const nfc_target nt) pn53x_initiator_target_is_present(struct nfc_device *pnd, const nfc_target *pnt)
{ {
// Check if the argument target nt is equals to current saved target // Check if the argument target nt is equals to current saved target
if (!pn53x_current_target_is(pnd, &nt)) { if (!pn53x_current_target_is(pnd, pnt)) {
return NFC_ETGRELEASED; return NFC_ETGRELEASED;
} }

View file

@ -337,7 +337,7 @@ int pn53x_initiator_transceive_bits_timed(struct nfc_device *pnd, const uint8
int pn53x_initiator_transceive_bytes_timed(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, int pn53x_initiator_transceive_bytes_timed(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx,
uint8_t *pbtRx, const size_t szRx, uint32_t *cycles); uint8_t *pbtRx, const size_t szRx, uint32_t *cycles);
int pn53x_initiator_deselect_target(struct nfc_device *pnd); int pn53x_initiator_deselect_target(struct nfc_device *pnd);
int pn53x_initiator_target_is_present(struct nfc_device *pnd, const nfc_target nt); int pn53x_initiator_target_is_present(struct nfc_device *pnd, const nfc_target *pnt);
// NFC device as Target functions // NFC device as Target functions
int pn53x_target_init(struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t szRxLen, int timeout); int pn53x_target_init(struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t szRxLen, int timeout);

View file

@ -131,7 +131,7 @@ struct nfc_driver {
int (*initiator_transceive_bits)(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar); int (*initiator_transceive_bits)(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar);
int (*initiator_transceive_bytes_timed)(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, const size_t szRx, uint32_t *cycles); int (*initiator_transceive_bytes_timed)(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, const size_t szRx, uint32_t *cycles);
int (*initiator_transceive_bits_timed)(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar, uint32_t *cycles); int (*initiator_transceive_bits_timed)(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar, uint32_t *cycles);
int (*initiator_target_is_present)(struct nfc_device *pnd, const nfc_target nt); int (*initiator_target_is_present)(struct nfc_device *pnd, const nfc_target *pnt);
int (*target_init)(struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t szRx, int timeout); int (*target_init)(struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t szRx, int timeout);
int (*target_send_bytes)(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, int timeout); int (*target_send_bytes)(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, int timeout);

View file

@ -821,9 +821,9 @@ nfc_initiator_transceive_bytes_timed(nfc_device *pnd,
* @warning To run the test, one or more commands will be sent to target * @warning To run the test, one or more commands will be sent to target
*/ */
int int
nfc_initiator_target_is_present(nfc_device *pnd, const nfc_target nt) nfc_initiator_target_is_present(nfc_device *pnd, const nfc_target *pnt)
{ {
HAL(initiator_target_is_present, pnd, nt); HAL(initiator_target_is_present, pnd, pnt);
} }
/** @ingroup initiator /** @ingroup initiator
@ -1287,12 +1287,12 @@ str_nfc_modulation_type(const nfc_modulation_type nmt)
* @warning *buf must be freed using nfc_free() * @warning *buf must be freed using nfc_free()
*/ */
int int
str_nfc_target(char **buf, const nfc_target nt, bool verbose) str_nfc_target(char **buf, const nfc_target *pnt, bool verbose)
{ {
*buf = malloc(4096); *buf = malloc(4096);
if (! *buf) if (! *buf)
return NFC_ESOFT; return NFC_ESOFT;
(*buf)[0] = '\0'; (*buf)[0] = '\0';
snprint_nfc_target(*buf, 4096, nt, verbose); snprint_nfc_target(*buf, 4096, pnt, verbose);
return strlen(*buf); return strlen(*buf);
} }

View file

@ -133,14 +133,14 @@ snprint_hex(char *dst, size_t size, const uint8_t *pbtData, const size_t szBytes
#define SAK_ISO18092_COMPLIANT 0x40 #define SAK_ISO18092_COMPLIANT 0x40
void void
snprint_nfc_iso14443a_info(char *dst, size_t size, const nfc_iso14443a_info nai, bool verbose) snprint_nfc_iso14443a_info(char *dst, size_t size, const nfc_iso14443a_info *pnai, bool verbose)
{ {
int off = 0; int off = 0;
off += snprintf(dst + off, size - off, " ATQA (SENS_RES): "); off += snprintf(dst + off, size - off, " ATQA (SENS_RES): ");
off += snprint_hex(dst + off, size - off, nai.abtAtqa, 2); off += snprint_hex(dst + off, size - off, pnai->abtAtqa, 2);
if (verbose) { if (verbose) {
off += snprintf(dst + off, size - off, "* UID size: "); off += snprintf(dst + off, size - off, "* UID size: ");
switch ((nai.abtAtqa[1] & 0xc0) >> 6) { switch ((pnai->abtAtqa[1] & 0xc0) >> 6) {
case 0: case 0:
off += snprintf(dst + off, size - off, "single\n"); off += snprintf(dst + off, size - off, "single\n");
break; break;
@ -155,7 +155,7 @@ snprint_nfc_iso14443a_info(char *dst, size_t size, const nfc_iso14443a_info nai,
break; break;
} }
off += snprintf(dst + off, size - off, "* bit frame anticollision "); off += snprintf(dst + off, size - off, "* bit frame anticollision ");
switch (nai.abtAtqa[1] & 0x1f) { switch (pnai->abtAtqa[1] & 0x1f) {
case 0x01: case 0x01:
case 0x02: case 0x02:
case 0x04: case 0x04:
@ -168,42 +168,42 @@ snprint_nfc_iso14443a_info(char *dst, size_t size, const nfc_iso14443a_info nai,
break; break;
} }
} }
off += snprintf(dst + off, size - off, " UID (NFCID%c): ", (nai.abtUid[0] == 0x08 ? '3' : '1')); off += snprintf(dst + off, size - off, " UID (NFCID%c): ", (pnai->abtUid[0] == 0x08 ? '3' : '1'));
off += snprint_hex(dst + off, size - off, nai.abtUid, nai.szUidLen); off += snprint_hex(dst + off, size - off, pnai->abtUid, pnai->szUidLen);
if (verbose) { if (verbose) {
if (nai.abtUid[0] == 0x08) { if (pnai->abtUid[0] == 0x08) {
off += snprintf(dst + off, size - off, "* Random UID\n"); off += snprintf(dst + off, size - off, "* Random UID\n");
} }
} }
off += snprintf(dst + off, size - off, " SAK (SEL_RES): "); off += snprintf(dst + off, size - off, " SAK (SEL_RES): ");
off += snprint_hex(dst + off, size - off, &nai.btSak, 1); off += snprint_hex(dst + off, size - off, &pnai->btSak, 1);
if (verbose) { if (verbose) {
if (nai.btSak & SAK_UID_NOT_COMPLETE) { if (pnai->btSak & SAK_UID_NOT_COMPLETE) {
off += snprintf(dst + off, size - off, "* Warning! Cascade bit set: UID not complete\n"); off += snprintf(dst + off, size - off, "* Warning! Cascade bit set: UID not complete\n");
} }
if (nai.btSak & SAK_ISO14443_4_COMPLIANT) { if (pnai->btSak & SAK_ISO14443_4_COMPLIANT) {
off += snprintf(dst + off, size - off, "* Compliant with ISO/IEC 14443-4\n"); off += snprintf(dst + off, size - off, "* Compliant with ISO/IEC 14443-4\n");
} else { } else {
off += snprintf(dst + off, size - off, "* Not compliant with ISO/IEC 14443-4\n"); off += snprintf(dst + off, size - off, "* Not compliant with ISO/IEC 14443-4\n");
} }
if (nai.btSak & SAK_ISO18092_COMPLIANT) { if (pnai->btSak & SAK_ISO18092_COMPLIANT) {
off += snprintf(dst + off, size - off, "* Compliant with ISO/IEC 18092\n"); off += snprintf(dst + off, size - off, "* Compliant with ISO/IEC 18092\n");
} else { } else {
off += snprintf(dst + off, size - off, "* Not compliant with ISO/IEC 18092\n"); off += snprintf(dst + off, size - off, "* Not compliant with ISO/IEC 18092\n");
} }
} }
if (nai.szAtsLen) { if (pnai->szAtsLen) {
off += snprintf(dst + off, size - off, " ATS: "); off += snprintf(dst + off, size - off, " ATS: ");
off += snprint_hex(dst + off, size - off, nai.abtAts, nai.szAtsLen); off += snprint_hex(dst + off, size - off, pnai->abtAts, pnai->szAtsLen);
} }
if (nai.szAtsLen && verbose) { if (pnai->szAtsLen && verbose) {
// Decode ATS according to ISO/IEC 14443-4 (5.2 Answer to select) // Decode ATS according to ISO/IEC 14443-4 (5.2 Answer to select)
const int iMaxFrameSizes[] = { 16, 24, 32, 40, 48, 64, 96, 128, 256 }; const int iMaxFrameSizes[] = { 16, 24, 32, 40, 48, 64, 96, 128, 256 };
off += snprintf(dst + off, size - off, "* Max Frame Size accepted by PICC: %d bytes\n", iMaxFrameSizes[nai.abtAts[0] & 0x0F]); off += snprintf(dst + off, size - off, "* Max Frame Size accepted by PICC: %d bytes\n", iMaxFrameSizes[pnai->abtAts[0] & 0x0F]);
size_t offset = 1; size_t offset = 1;
if (nai.abtAts[0] & 0x10) { // TA(1) present if (pnai->abtAts[0] & 0x10) { // TA(1) present
uint8_t TA = nai.abtAts[offset]; uint8_t TA = pnai->abtAts[offset];
offset++; offset++;
off += snprintf(dst + off, size - off, "* Bit Rate Capability:\n"); off += snprintf(dst + off, size - off, "* Bit Rate Capability:\n");
if (TA == 0) { if (TA == 0) {
@ -234,8 +234,8 @@ snprint_nfc_iso14443a_info(char *dst, size_t size, const nfc_iso14443a_info nai,
off += snprintf(dst + off, size - off, " * ERROR unknown value\n"); off += snprintf(dst + off, size - off, " * ERROR unknown value\n");
} }
} }
if (nai.abtAts[0] & 0x20) { // TB(1) present if (pnai->abtAts[0] & 0x20) { // TB(1) present
uint8_t TB = nai.abtAts[offset]; uint8_t TB = pnai->abtAts[offset];
offset++; offset++;
off += snprintf(dst + off, size - off, "* Frame Waiting Time: %.4g ms\n", 256.0 * 16.0 * (1 << ((TB & 0xf0) >> 4)) / 13560.0); off += snprintf(dst + off, size - off, "* Frame Waiting Time: %.4g ms\n", 256.0 * 16.0 * (1 << ((TB & 0xf0) >> 4)) / 13560.0);
if ((TB & 0x0f) == 0) { if ((TB & 0x0f) == 0) {
@ -244,8 +244,8 @@ snprint_nfc_iso14443a_info(char *dst, size_t size, const nfc_iso14443a_info nai,
off += snprintf(dst + off, size - off, "* Start-up Frame Guard Time: %.4g ms\n", 256.0 * 16.0 * (1 << (TB & 0x0f)) / 13560.0); off += snprintf(dst + off, size - off, "* Start-up Frame Guard Time: %.4g ms\n", 256.0 * 16.0 * (1 << (TB & 0x0f)) / 13560.0);
} }
} }
if (nai.abtAts[0] & 0x40) { // TC(1) present if (pnai->abtAts[0] & 0x40) { // TC(1) present
uint8_t TC = nai.abtAts[offset]; uint8_t TC = pnai->abtAts[offset];
offset++; offset++;
if (TC & 0x1) { if (TC & 0x1) {
off += snprintf(dst + off, size - off, "* Node ADdress supported\n"); off += snprintf(dst + off, size - off, "* Node ADdress supported\n");
@ -258,23 +258,23 @@ snprint_nfc_iso14443a_info(char *dst, size_t size, const nfc_iso14443a_info nai,
off += snprintf(dst + off, size - off, "* Card IDentifier not supported\n"); off += snprintf(dst + off, size - off, "* Card IDentifier not supported\n");
} }
} }
if (nai.szAtsLen > offset) { if (pnai->szAtsLen > offset) {
off += snprintf(dst + off, size - off, "* Historical bytes Tk: "); off += snprintf(dst + off, size - off, "* Historical bytes Tk: ");
off += snprint_hex(dst + off, size - off, nai.abtAts + offset, (nai.szAtsLen - offset)); off += snprint_hex(dst + off, size - off, pnai->abtAts + offset, (pnai->szAtsLen - offset));
uint8_t CIB = nai.abtAts[offset]; uint8_t CIB = pnai->abtAts[offset];
offset++; offset++;
if (CIB != 0x00 && CIB != 0x10 && (CIB & 0xf0) != 0x80) { if (CIB != 0x00 && CIB != 0x10 && (CIB & 0xf0) != 0x80) {
off += snprintf(dst + off, size - off, " * Proprietary format\n"); off += snprintf(dst + off, size - off, " * Proprietary format\n");
if (CIB == 0xc1) { if (CIB == 0xc1) {
off += snprintf(dst + off, size - off, " * Tag byte: Mifare or virtual cards of various types\n"); off += snprintf(dst + off, size - off, " * Tag byte: Mifare or virtual cards of various types\n");
uint8_t L = nai.abtAts[offset]; uint8_t L = pnai->abtAts[offset];
offset++; offset++;
if (L != (nai.szAtsLen - offset)) { if (L != (pnai->szAtsLen - offset)) {
off += snprintf(dst + off, size - off, " * Warning: Type Identification Coding length (%i)", L); off += snprintf(dst + off, size - off, " * Warning: Type Identification Coding length (%i)", L);
off += snprintf(dst + off, size - off, " not matching Tk length (%zi)\n", (nai.szAtsLen - offset)); off += snprintf(dst + off, size - off, " not matching Tk length (%zi)\n", (pnai->szAtsLen - offset));
} }
if ((nai.szAtsLen - offset - 2) > 0) { // Omit 2 CRC bytes if ((pnai->szAtsLen - offset - 2) > 0) { // Omit 2 CRC bytes
uint8_t CTC = nai.abtAts[offset]; uint8_t CTC = pnai->abtAts[offset];
offset++; offset++;
off += snprintf(dst + off, size - off, " * Chip Type: "); off += snprintf(dst + off, size - off, " * Chip Type: ");
switch (CTC & 0xf0) { switch (CTC & 0xf0) {
@ -316,8 +316,8 @@ snprint_nfc_iso14443a_info(char *dst, size_t size, const nfc_iso14443a_info nai,
break; break;
} }
} }
if ((nai.szAtsLen - offset) > 0) { // Omit 2 CRC bytes if ((pnai->szAtsLen - offset) > 0) { // Omit 2 CRC bytes
uint8_t CVC = nai.abtAts[offset]; uint8_t CVC = pnai->abtAts[offset];
offset++; offset++;
off += snprintf(dst + off, size - off, " * Chip Status: "); off += snprintf(dst + off, size - off, " * Chip Status: ");
switch (CVC & 0xf0) { switch (CVC & 0xf0) {
@ -350,8 +350,8 @@ snprint_nfc_iso14443a_info(char *dst, size_t size, const nfc_iso14443a_info nai,
break; break;
} }
} }
if ((nai.szAtsLen - offset) > 0) { // Omit 2 CRC bytes if ((pnai->szAtsLen - offset) > 0) { // Omit 2 CRC bytes
uint8_t VCS = nai.abtAts[offset]; uint8_t VCS = pnai->abtAts[offset];
offset++; offset++;
off += snprintf(dst + off, size - off, " * Specifics (Virtual Card Selection):\n"); off += snprintf(dst + off, size - off, " * Specifics (Virtual Card Selection):\n");
if ((VCS & 0x09) == 0x00) { if ((VCS & 0x09) == 0x00) {
@ -379,10 +379,10 @@ snprint_nfc_iso14443a_info(char *dst, size_t size, const nfc_iso14443a_info nai,
off += snprintf(dst + off, size - off, " See ISO/IEC 7816-4 8.1.1.3 for more info\n"); off += snprintf(dst + off, size - off, " See ISO/IEC 7816-4 8.1.1.3 for more info\n");
} }
if (CIB == 0x10) { if (CIB == 0x10) {
off += snprintf(dst + off, size - off, " * DIR data reference: %02x\n", nai.abtAts[offset]); off += snprintf(dst + off, size - off, " * DIR data reference: %02x\n", pnai->abtAts[offset]);
} }
if (CIB == 0x80) { if (CIB == 0x80) {
if (nai.szAtsLen == offset) { if (pnai->szAtsLen == offset) {
off += snprintf(dst + off, size - off, " * No COMPACT-TLV objects found, no status found\n"); off += snprintf(dst + off, size - off, " * No COMPACT-TLV objects found, no status found\n");
} else { } else {
off += snprintf(dst + off, size - off, " * Tk after 0x80 consist of optional consecutive COMPACT-TLV data objects;\n"); off += snprintf(dst + off, size - off, " * Tk after 0x80 consist of optional consecutive COMPACT-TLV data objects;\n");
@ -400,9 +400,9 @@ snprint_nfc_iso14443a_info(char *dst, size_t size, const nfc_iso14443a_info nai,
uint8_t i, j; uint8_t i, j;
bool found_possible_match = false; bool found_possible_match = false;
atqa = (((uint16_t)nai.abtAtqa[0] & 0xff) << 8); atqa = (((uint16_t)pnai->abtAtqa[0] & 0xff) << 8);
atqa += (((uint16_t)nai.abtAtqa[1] & 0xff)); atqa += (((uint16_t)pnai->abtAtqa[1] & 0xff));
sak = ((uint8_t)nai.btSak & 0xff); sak = ((uint8_t)pnai->btSak & 0xff);
for (i = 0; i < sizeof(const_ca) / sizeof(const_ca[0]); i++) { for (i = 0; i < sizeof(const_ca) / sizeof(const_ca[0]); i++) {
if ((atqa & const_ca[i].mask) == const_ca[i].atqa) { if ((atqa & const_ca[i].mask) == const_ca[i].atqa) {
@ -420,9 +420,9 @@ snprint_nfc_iso14443a_info(char *dst, size_t size, const nfc_iso14443a_info nai,
// but seen in the field: // but seen in the field:
off += snprintf(dst + off, size - off, "Other possible matches based on ATQA & SAK values:\n"); off += snprintf(dst + off, size - off, "Other possible matches based on ATQA & SAK values:\n");
uint32_t atqasak = 0; uint32_t atqasak = 0;
atqasak += (((uint32_t)nai.abtAtqa[0] & 0xff) << 16); atqasak += (((uint32_t)pnai->abtAtqa[0] & 0xff) << 16);
atqasak += (((uint32_t)nai.abtAtqa[1] & 0xff) << 8); atqasak += (((uint32_t)pnai->abtAtqa[1] & 0xff) << 8);
atqasak += ((uint32_t)nai.btSak & 0xff); atqasak += ((uint32_t)pnai->btSak & 0xff);
switch (atqasak) { switch (atqasak) {
case 0x000488: case 0x000488:
off += snprintf(dst + off, size - off, "* Mifare Classic 1K Infineon\n"); off += snprintf(dst + off, size - off, "* Mifare Classic 1K Infineon\n");
@ -469,96 +469,96 @@ snprint_nfc_iso14443a_info(char *dst, size_t size, const nfc_iso14443a_info nai,
} }
void void
snprint_nfc_felica_info(char *dst, size_t size, const nfc_felica_info nfi, bool verbose) snprint_nfc_felica_info(char *dst, size_t size, const nfc_felica_info *pnfi, bool verbose)
{ {
(void) verbose; (void) verbose;
int off = 0; int off = 0;
off += snprintf(dst + off, size - off, " ID (NFCID2): "); off += snprintf(dst + off, size - off, " ID (NFCID2): ");
off += snprint_hex(dst + off, size - off, nfi.abtId, 8); off += snprint_hex(dst + off, size - off, pnfi->abtId, 8);
off += snprintf(dst + off, size - off, " Parameter (PAD): "); off += snprintf(dst + off, size - off, " Parameter (PAD): ");
off += snprint_hex(dst + off, size - off, nfi.abtPad, 8); off += snprint_hex(dst + off, size - off, pnfi->abtPad, 8);
off += snprintf(dst + off, size - off, " System Code (SC): "); off += snprintf(dst + off, size - off, " System Code (SC): ");
snprint_hex(dst + off, size - off, nfi.abtSysCode, 2); snprint_hex(dst + off, size - off, pnfi->abtSysCode, 2);
} }
void void
snprint_nfc_jewel_info(char *dst, size_t size, const nfc_jewel_info nji, bool verbose) snprint_nfc_jewel_info(char *dst, size_t size, const nfc_jewel_info *pnji, bool verbose)
{ {
(void) verbose; (void) verbose;
int off = 0; int off = 0;
off += snprintf(dst + off, size - off, " ATQA (SENS_RES): "); off += snprintf(dst + off, size - off, " ATQA (SENS_RES): ");
off += snprint_hex(dst + off, size - off, nji.btSensRes, 2); off += snprint_hex(dst + off, size - off, pnji->btSensRes, 2);
off += snprintf(dst + off, size - off, " 4-LSB JEWELID: "); off += snprintf(dst + off, size - off, " 4-LSB JEWELID: ");
snprint_hex(dst + off, size - off, nji.btId, 4); snprint_hex(dst + off, size - off, pnji->btId, 4);
} }
#define PI_ISO14443_4_SUPPORTED 0x01 #define PI_ISO14443_4_SUPPORTED 0x01
#define PI_NAD_SUPPORTED 0x01 #define PI_NAD_SUPPORTED 0x01
#define PI_CID_SUPPORTED 0x02 #define PI_CID_SUPPORTED 0x02
void void
snprint_nfc_iso14443b_info(char *dst, size_t size, const nfc_iso14443b_info nbi, bool verbose) snprint_nfc_iso14443b_info(char *dst, size_t size, const nfc_iso14443b_info *pnbi, bool verbose)
{ {
int off = 0; int off = 0;
off += snprintf(dst + off, size - off, " PUPI: "); off += snprintf(dst + off, size - off, " PUPI: ");
off += snprint_hex(dst + off, size - off, nbi.abtPupi, 4); off += snprint_hex(dst + off, size - off, pnbi->abtPupi, 4);
off += snprintf(dst + off, size - off, " Application Data: "); off += snprintf(dst + off, size - off, " Application Data: ");
off += snprint_hex(dst + off, size - off, nbi.abtApplicationData, 4); off += snprint_hex(dst + off, size - off, pnbi->abtApplicationData, 4);
off += snprintf(dst + off, size - off, " Protocol Info: "); off += snprintf(dst + off, size - off, " Protocol Info: ");
off += snprint_hex(dst + off, size - off, nbi.abtProtocolInfo, 3); off += snprint_hex(dst + off, size - off, pnbi->abtProtocolInfo, 3);
if (verbose) { if (verbose) {
off += snprintf(dst + off, size - off, "* Bit Rate Capability:\n"); off += snprintf(dst + off, size - off, "* Bit Rate Capability:\n");
if (nbi.abtProtocolInfo[0] == 0) { if (pnbi->abtProtocolInfo[0] == 0) {
off += snprintf(dst + off, size - off, " * PICC supports only 106 kbits/s in both directions\n"); off += snprintf(dst + off, size - off, " * PICC supports only 106 kbits/s in both directions\n");
} }
if (nbi.abtProtocolInfo[0] & 1 << 7) { if (pnbi->abtProtocolInfo[0] & 1 << 7) {
off += snprintf(dst + off, size - off, " * Same bitrate in both directions mandatory\n"); off += snprintf(dst + off, size - off, " * Same bitrate in both directions mandatory\n");
} }
if (nbi.abtProtocolInfo[0] & 1 << 4) { if (pnbi->abtProtocolInfo[0] & 1 << 4) {
off += snprintf(dst + off, size - off, " * PICC to PCD, 1etu=64/fc, bitrate 212 kbits/s supported\n"); off += snprintf(dst + off, size - off, " * PICC to PCD, 1etu=64/fc, bitrate 212 kbits/s supported\n");
} }
if (nbi.abtProtocolInfo[0] & 1 << 5) { if (pnbi->abtProtocolInfo[0] & 1 << 5) {
off += snprintf(dst + off, size - off, " * PICC to PCD, 1etu=32/fc, bitrate 424 kbits/s supported\n"); off += snprintf(dst + off, size - off, " * PICC to PCD, 1etu=32/fc, bitrate 424 kbits/s supported\n");
} }
if (nbi.abtProtocolInfo[0] & 1 << 6) { if (pnbi->abtProtocolInfo[0] & 1 << 6) {
off += snprintf(dst + off, size - off, " * PICC to PCD, 1etu=16/fc, bitrate 847 kbits/s supported\n"); off += snprintf(dst + off, size - off, " * PICC to PCD, 1etu=16/fc, bitrate 847 kbits/s supported\n");
} }
if (nbi.abtProtocolInfo[0] & 1 << 0) { if (pnbi->abtProtocolInfo[0] & 1 << 0) {
off += snprintf(dst + off, size - off, " * PCD to PICC, 1etu=64/fc, bitrate 212 kbits/s supported\n"); off += snprintf(dst + off, size - off, " * PCD to PICC, 1etu=64/fc, bitrate 212 kbits/s supported\n");
} }
if (nbi.abtProtocolInfo[0] & 1 << 1) { if (pnbi->abtProtocolInfo[0] & 1 << 1) {
off += snprintf(dst + off, size - off, " * PCD to PICC, 1etu=32/fc, bitrate 424 kbits/s supported\n"); off += snprintf(dst + off, size - off, " * PCD to PICC, 1etu=32/fc, bitrate 424 kbits/s supported\n");
} }
if (nbi.abtProtocolInfo[0] & 1 << 2) { if (pnbi->abtProtocolInfo[0] & 1 << 2) {
off += snprintf(dst + off, size - off, " * PCD to PICC, 1etu=16/fc, bitrate 847 kbits/s supported\n"); off += snprintf(dst + off, size - off, " * PCD to PICC, 1etu=16/fc, bitrate 847 kbits/s supported\n");
} }
if (nbi.abtProtocolInfo[0] & 1 << 3) { if (pnbi->abtProtocolInfo[0] & 1 << 3) {
off += snprintf(dst + off, size - off, " * ERROR unknown value\n"); off += snprintf(dst + off, size - off, " * ERROR unknown value\n");
} }
if ((nbi.abtProtocolInfo[1] & 0xf0) <= 0x80) { if ((pnbi->abtProtocolInfo[1] & 0xf0) <= 0x80) {
const int iMaxFrameSizes[] = { 16, 24, 32, 40, 48, 64, 96, 128, 256 }; const int iMaxFrameSizes[] = { 16, 24, 32, 40, 48, 64, 96, 128, 256 };
off += snprintf(dst + off, size - off, "* Maximum frame sizes: %d bytes\n", iMaxFrameSizes[((nbi.abtProtocolInfo[1] & 0xf0) >> 4)]); off += snprintf(dst + off, size - off, "* Maximum frame sizes: %d bytes\n", iMaxFrameSizes[((pnbi->abtProtocolInfo[1] & 0xf0) >> 4)]);
} }
if ((nbi.abtProtocolInfo[1] & 0x0f) == PI_ISO14443_4_SUPPORTED) { if ((pnbi->abtProtocolInfo[1] & 0x0f) == PI_ISO14443_4_SUPPORTED) {
off += snprintf(dst + off, size - off, "* Protocol types supported: ISO/IEC 14443-4\n"); off += snprintf(dst + off, size - off, "* Protocol types supported: ISO/IEC 14443-4\n");
} }
off += snprintf(dst + off, size - off, "* Frame Waiting Time: %.4g ms\n", 256.0 * 16.0 * (1 << ((nbi.abtProtocolInfo[2] & 0xf0) >> 4)) / 13560.0); off += snprintf(dst + off, size - off, "* Frame Waiting Time: %.4g ms\n", 256.0 * 16.0 * (1 << ((pnbi->abtProtocolInfo[2] & 0xf0) >> 4)) / 13560.0);
if ((nbi.abtProtocolInfo[2] & (PI_NAD_SUPPORTED | PI_CID_SUPPORTED)) != 0) { if ((pnbi->abtProtocolInfo[2] & (PI_NAD_SUPPORTED | PI_CID_SUPPORTED)) != 0) {
off += snprintf(dst + off, size - off, "* Frame options supported: "); off += snprintf(dst + off, size - off, "* Frame options supported: ");
if ((nbi.abtProtocolInfo[2] & PI_NAD_SUPPORTED) != 0) off += snprintf(dst + off, size - off, "NAD "); if ((pnbi->abtProtocolInfo[2] & PI_NAD_SUPPORTED) != 0) off += snprintf(dst + off, size - off, "NAD ");
if ((nbi.abtProtocolInfo[2] & PI_CID_SUPPORTED) != 0) off += snprintf(dst + off, size - off, "CID "); if ((pnbi->abtProtocolInfo[2] & PI_CID_SUPPORTED) != 0) off += snprintf(dst + off, size - off, "CID ");
snprintf(dst + off, size - off, "\n"); snprintf(dst + off, size - off, "\n");
} }
} }
} }
void void
snprint_nfc_iso14443bi_info(char *dst, size_t size, const nfc_iso14443bi_info nii, bool verbose) snprint_nfc_iso14443bi_info(char *dst, size_t size, const nfc_iso14443bi_info *pnii, bool verbose)
{ {
int off = 0; int off = 0;
off += snprintf(dst + off, size - off, " DIV: "); off += snprintf(dst + off, size - off, " DIV: ");
off += snprint_hex(dst + off, size - off, nii.abtDIV, 4); off += snprint_hex(dst + off, size - off, pnii->abtDIV, 4);
if (verbose) { if (verbose) {
int version = (nii.btVerLog & 0x1e) >> 1; int version = (pnii->btVerLog & 0x1e) >> 1;
off += snprintf(dst + off, size - off, " Software Version: "); off += snprintf(dst + off, size - off, " Software Version: ");
if (version == 15) { if (version == 15) {
off += snprintf(dst + off, size - off, "Undefined\n"); off += snprintf(dst + off, size - off, "Undefined\n");
@ -566,86 +566,88 @@ snprint_nfc_iso14443bi_info(char *dst, size_t size, const nfc_iso14443bi_info ni
off += snprintf(dst + off, size - off, "%i\n", version); off += snprintf(dst + off, size - off, "%i\n", version);
} }
if ((nii.btVerLog & 0x80) && (nii.btConfig & 0x80)) { if ((pnii->btVerLog & 0x80) && (pnii->btConfig & 0x80)) {
off += snprintf(dst + off, size - off, " Wait Enable: yes"); off += snprintf(dst + off, size - off, " Wait Enable: yes");
} }
} }
if ((nii.btVerLog & 0x80) && (nii.btConfig & 0x40)) { if ((pnii->btVerLog & 0x80) && (pnii->btConfig & 0x40)) {
off += snprintf(dst + off, size - off, " ATS: "); off += snprintf(dst + off, size - off, " ATS: ");
snprint_hex(dst + off, size - off, nii.abtAtr, nii.szAtrLen); snprint_hex(dst + off, size - off, pnii->abtAtr, pnii->szAtrLen);
} }
} }
void void
snprint_nfc_iso14443b2sr_info(char *dst, size_t size, const nfc_iso14443b2sr_info nsi, bool verbose) snprint_nfc_iso14443b2sr_info(char *dst, size_t size, const nfc_iso14443b2sr_info *pnsi, bool verbose)
{ {
(void) verbose; (void) verbose;
int off = 0; int off = 0;
off += snprintf(dst + off, size - off, " UID: "); off += snprintf(dst + off, size - off, " UID: ");
snprint_hex(dst + off, size - off, nsi.abtUID, 8); snprint_hex(dst + off, size - off, pnsi->abtUID, 8);
} }
void void
snprint_nfc_iso14443b2ct_info(char *dst, size_t size, const nfc_iso14443b2ct_info nci, bool verbose) snprint_nfc_iso14443b2ct_info(char *dst, size_t size, const nfc_iso14443b2ct_info *pnci, bool verbose)
{ {
(void) verbose; (void) verbose;
int off = 0; int off = 0;
uint32_t uid; uint32_t uid;
uid = (nci.abtUID[3] << 24) + (nci.abtUID[2] << 16) + (nci.abtUID[1] << 8) + nci.abtUID[0]; uid = (pnci->abtUID[3] << 24) + (pnci->abtUID[2] << 16) + (pnci->abtUID[1] << 8) + pnci->abtUID[0];
off += snprintf(dst + off, size - off, " UID: "); off += snprintf(dst + off, size - off, " UID: ");
off += snprint_hex(dst + off, size - off, nci.abtUID, sizeof(nci.abtUID)); off += snprint_hex(dst + off, size - off, pnci->abtUID, sizeof(pnci->abtUID));
off += snprintf(dst + off, size - off, " UID (decimal): %010u\n", uid); off += snprintf(dst + off, size - off, " UID (decimal): %010u\n", uid);
off += snprintf(dst + off, size - off, " Product Code: %02X\n", nci.btProdCode); off += snprintf(dst + off, size - off, " Product Code: %02X\n", pnci->btProdCode);
snprintf(dst + off, size - off, " Fab Code: %02X\n", nci.btFabCode); snprintf(dst + off, size - off, " Fab Code: %02X\n", pnci->btFabCode);
} }
void void
snprint_nfc_dep_info(char *dst, size_t size, const nfc_dep_info ndi, bool verbose) snprint_nfc_dep_info(char *dst, size_t size, const nfc_dep_info *pndi, bool verbose)
{ {
(void) verbose; (void) verbose;
int off = 0; int off = 0;
off += snprintf(dst + off, size - off, " NFCID3: "); off += snprintf(dst + off, size - off, " NFCID3: ");
off += snprint_hex(dst + off, size - off, ndi.abtNFCID3, 10); off += snprint_hex(dst + off, size - off, pndi->abtNFCID3, 10);
off += snprintf(dst + off, size - off, " BS: %02x\n", ndi.btBS); off += snprintf(dst + off, size - off, " BS: %02x\n", pndi->btBS);
off += snprintf(dst + off, size - off, " BR: %02x\n", ndi.btBR); off += snprintf(dst + off, size - off, " BR: %02x\n", pndi->btBR);
off += snprintf(dst + off, size - off, " TO: %02x\n", ndi.btTO); off += snprintf(dst + off, size - off, " TO: %02x\n", pndi->btTO);
off += snprintf(dst + off, size - off, " PP: %02x\n", ndi.btPP); off += snprintf(dst + off, size - off, " PP: %02x\n", pndi->btPP);
if (ndi.szGB) { if (pndi->szGB) {
off += snprintf(dst + off, size - off, "General Bytes: "); off += snprintf(dst + off, size - off, "General Bytes: ");
snprint_hex(dst + off, size - off, ndi.abtGB, ndi.szGB); snprint_hex(dst + off, size - off, pndi->abtGB, pndi->szGB);
} }
} }
void void
snprint_nfc_target(char *dst, size_t size, const nfc_target nt, bool verbose) snprint_nfc_target(char *dst, size_t size, const nfc_target *pnt, bool verbose)
{ {
int off = 0; if (NULL != pnt) {
off += snprintf(dst + off, size - off, "%s (%s%s) target:\n", str_nfc_modulation_type(nt.nm.nmt), str_nfc_baud_rate(nt.nm.nbr), (nt.nm.nmt != NMT_DEP) ? "" : (nt.nti.ndi.ndm == NDM_ACTIVE) ? "active mode" : "passive mode"); int off = 0;
switch (nt.nm.nmt) { off += snprintf(dst + off, size - off, "%s (%s%s) target:\n", str_nfc_modulation_type(pnt->nm.nmt), str_nfc_baud_rate(pnt->nm.nbr), (pnt->nm.nmt != NMT_DEP) ? "" : (pnt->nti.ndi.ndm == NDM_ACTIVE) ? "active mode" : "passive mode");
case NMT_ISO14443A: switch (pnt->nm.nmt) {
snprint_nfc_iso14443a_info(dst + off, size - off, nt.nti.nai, verbose); case NMT_ISO14443A:
break; snprint_nfc_iso14443a_info(dst + off, size - off, &pnt->nti.nai, verbose);
case NMT_JEWEL: break;
snprint_nfc_jewel_info(dst + off, size - off, nt.nti.nji, verbose); case NMT_JEWEL:
break; snprint_nfc_jewel_info(dst + off, size - off, &pnt->nti.nji, verbose);
case NMT_FELICA: break;
snprint_nfc_felica_info(dst + off, size - off, nt.nti.nfi, verbose); case NMT_FELICA:
break; snprint_nfc_felica_info(dst + off, size - off, &pnt->nti.nfi, verbose);
case NMT_ISO14443B: break;
snprint_nfc_iso14443b_info(dst + off, size - off, nt.nti.nbi, verbose); case NMT_ISO14443B:
break; snprint_nfc_iso14443b_info(dst + off, size - off, &pnt->nti.nbi, verbose);
case NMT_ISO14443BI: break;
snprint_nfc_iso14443bi_info(dst + off, size - off, nt.nti.nii, verbose); case NMT_ISO14443BI:
break; snprint_nfc_iso14443bi_info(dst + off, size - off, &pnt->nti.nii, verbose);
case NMT_ISO14443B2SR: break;
snprint_nfc_iso14443b2sr_info(dst + off, size - off, nt.nti.nsi, verbose); case NMT_ISO14443B2SR:
break; snprint_nfc_iso14443b2sr_info(dst + off, size - off, &pnt->nti.nsi, verbose);
case NMT_ISO14443B2CT: break;
snprint_nfc_iso14443b2ct_info(dst + off, size - off, nt.nti.nci, verbose); case NMT_ISO14443B2CT:
break; snprint_nfc_iso14443b2ct_info(dst + off, size - off, &pnt->nti.nci, verbose);
case NMT_DEP: break;
snprint_nfc_dep_info(dst + off, size - off, nt.nti.ndi, verbose); case NMT_DEP:
break; snprint_nfc_dep_info(dst + off, size - off, &pnt->nti.ndi, verbose);
break;
}
} }
} }

View file

@ -28,14 +28,14 @@
#define _TARGET_SUBR_H_ #define _TARGET_SUBR_H_
int snprint_hex(char *dst, size_t size, const uint8_t *pbtData, const size_t szLen); int snprint_hex(char *dst, size_t size, const uint8_t *pbtData, const size_t szLen);
void snprint_nfc_iso14443a_info(char *dst, size_t size, const nfc_iso14443a_info nai, bool verbose); void snprint_nfc_iso14443a_info(char *dst, size_t size, const nfc_iso14443a_info *pnai, bool verbose);
void snprint_nfc_iso14443b_info(char *dst, size_t size, const nfc_iso14443b_info nbi, bool verbose); void snprint_nfc_iso14443b_info(char *dst, size_t size, const nfc_iso14443b_info *pnbi, bool verbose);
void snprint_nfc_iso14443bi_info(char *dst, size_t size, const nfc_iso14443bi_info nii, bool verbose); void snprint_nfc_iso14443bi_info(char *dst, size_t size, const nfc_iso14443bi_info *pnii, bool verbose);
void snprint_nfc_iso14443b2sr_info(char *dst, size_t size, const nfc_iso14443b2sr_info nsi, bool verbose); void snprint_nfc_iso14443b2sr_info(char *dst, size_t size, const nfc_iso14443b2sr_info *pnsi, bool verbose);
void snprint_nfc_iso14443b2ct_info(char *dst, size_t size, const nfc_iso14443b2ct_info nci, bool verbose); void snprint_nfc_iso14443b2ct_info(char *dst, size_t size, const nfc_iso14443b2ct_info *pnci, bool verbose);
void snprint_nfc_felica_info(char *dst, size_t size, const nfc_felica_info nfi, bool verbose); void snprint_nfc_felica_info(char *dst, size_t size, const nfc_felica_info *pnfi, bool verbose);
void snprint_nfc_jewel_info(char *dst, size_t size, const nfc_jewel_info nji, bool verbose); void snprint_nfc_jewel_info(char *dst, size_t size, const nfc_jewel_info *pnji, bool verbose);
void snprint_nfc_dep_info(char *dst, size_t size, const nfc_dep_info ndi, bool verbose); void snprint_nfc_dep_info(char *dst, size_t size, const nfc_dep_info *pndi, bool verbose);
void snprint_nfc_target(char *dst, size_t size, const nfc_target nt, bool verbose); void snprint_nfc_target(char *dst, size_t size, const nfc_target *pnt, bool verbose);
#endif #endif

View file

@ -143,7 +143,7 @@ main(int argc, const char *argv[])
printf("%d ISO14443A passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":"); printf("%d ISO14443A passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":");
} }
for (n = 0; n < res; n++) { for (n = 0; n < res; n++) {
print_nfc_target(ant[n], verbose); print_nfc_target(&ant[n], verbose);
printf("\n"); printf("\n");
} }
} }
@ -157,7 +157,7 @@ main(int argc, const char *argv[])
printf("%d Felica (212 kbps) passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":"); printf("%d Felica (212 kbps) passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":");
} }
for (n = 0; n < res; n++) { for (n = 0; n < res; n++) {
print_nfc_target(ant[n], verbose); print_nfc_target(&ant[n], verbose);
printf("\n"); printf("\n");
} }
} }
@ -169,7 +169,7 @@ main(int argc, const char *argv[])
printf("%d Felica (424 kbps) passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":"); printf("%d Felica (424 kbps) passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":");
} }
for (n = 0; n < res; n++) { for (n = 0; n < res; n++) {
print_nfc_target(ant[n], verbose); print_nfc_target(&ant[n], verbose);
printf("\n"); printf("\n");
} }
} }
@ -183,7 +183,7 @@ main(int argc, const char *argv[])
printf("%d ISO14443B passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":"); printf("%d ISO14443B passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":");
} }
for (n = 0; n < res; n++) { for (n = 0; n < res; n++) {
print_nfc_target(ant[n], verbose); print_nfc_target(&ant[n], verbose);
printf("\n"); printf("\n");
} }
} }
@ -197,7 +197,7 @@ main(int argc, const char *argv[])
printf("%d ISO14443B' passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":"); printf("%d ISO14443B' passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":");
} }
for (n = 0; n < res; n++) { for (n = 0; n < res; n++) {
print_nfc_target(ant[n], verbose); print_nfc_target(&ant[n], verbose);
printf("\n"); printf("\n");
} }
} }
@ -211,7 +211,7 @@ main(int argc, const char *argv[])
printf("%d ISO14443B-2 ST SRx passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":"); printf("%d ISO14443B-2 ST SRx passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":");
} }
for (n = 0; n < res; n++) { for (n = 0; n < res; n++) {
print_nfc_target(ant[n], verbose); print_nfc_target(&ant[n], verbose);
printf("\n"); printf("\n");
} }
} }
@ -225,7 +225,7 @@ main(int argc, const char *argv[])
printf("%d ISO14443B-2 ASK CTx passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":"); printf("%d ISO14443B-2 ASK CTx passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":");
} }
for (n = 0; n < res; n++) { for (n = 0; n < res; n++) {
print_nfc_target(ant[n], verbose); print_nfc_target(&ant[n], verbose);
printf("\n"); printf("\n");
} }
} }
@ -239,7 +239,7 @@ main(int argc, const char *argv[])
printf("%d Jewel passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":"); printf("%d Jewel passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":");
} }
for (n = 0; n < res; n++) { for (n = 0; n < res; n++) {
print_nfc_target(ant[n], verbose); print_nfc_target(&ant[n], verbose);
printf("\n"); printf("\n");
} }
} }

View file

@ -558,7 +558,7 @@ main(int argc, const char *argv[])
} }
} }
printf("Found MIFARE Classic card:\n"); printf("Found MIFARE Classic card:\n");
print_nfc_target(nt, false); print_nfc_target(&nt, false);
// Guessing size // Guessing size
if ((nt.nti.nai.abtAtqa[1] & 0x02) == 0x02) if ((nt.nti.nai.abtAtqa[1] & 0x02) == 0x02)

View file

@ -271,7 +271,7 @@ main(int argc, char *argv[])
} }
printf("Found tag:\n"); printf("Found tag:\n");
print_nfc_target(ntRealTarget, false); print_nfc_target(&ntRealTarget, false);
if (initiator_only_mode) { if (initiator_only_mode) {
if (print_hex_fd4(ntRealTarget.nti.nai.abtUid, ntRealTarget.nti.nai.szUidLen, "UID") < 0) { if (print_hex_fd4(ntRealTarget.nti.nai.abtUid, ntRealTarget.nti.nai.szUidLen, "UID") < 0) {
fprintf(stderr, "Error while printing UID to FD4\n"); fprintf(stderr, "Error while printing UID to FD4\n");
@ -372,7 +372,7 @@ main(int argc, char *argv[])
memcpy(&(ntEmulatedTarget.nti.nai.abtAts[4]), pbtTkt, szTk); memcpy(&(ntEmulatedTarget.nti.nai.abtAts[4]), pbtTkt, szTk);
printf("We will emulate:\n"); printf("We will emulate:\n");
print_nfc_target(ntEmulatedTarget, false); print_nfc_target(&ntEmulatedTarget, false);
// Try to open the NFC emulator device // Try to open the NFC emulator device
if (swap_devices) { if (swap_devices) {

View file

@ -115,10 +115,10 @@ print_hex_par(const uint8_t *pbtData, const size_t szBits, const uint8_t *pbtDat
} }
void void
print_nfc_target(const nfc_target nt, bool verbose) print_nfc_target(const nfc_target *pnt, bool verbose)
{ {
char *s; char *s;
str_nfc_target(&s, nt, verbose); str_nfc_target(&s, pnt, verbose);
printf("%s", s); printf("%s", s);
nfc_free(s); nfc_free(s);
} }

View file

@ -94,6 +94,6 @@ void print_hex(const uint8_t *pbtData, const size_t szLen);
void print_hex_bits(const uint8_t *pbtData, const size_t szBits); void print_hex_bits(const uint8_t *pbtData, const size_t szBits);
void print_hex_par(const uint8_t *pbtData, const size_t szBits, const uint8_t *pbtDataPar); void print_hex_par(const uint8_t *pbtData, const size_t szBits, const uint8_t *pbtDataPar);
void print_nfc_target(const nfc_target nt, bool verbose); void print_nfc_target(const nfc_target *pnt, bool verbose);
#endif #endif