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

@ -143,7 +143,7 @@ main(int argc, const char *argv[])
printf("%d ISO14443A passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":");
}
for (n = 0; n < res; n++) {
print_nfc_target(ant[n], verbose);
print_nfc_target(&ant[n], verbose);
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" : ":");
}
for (n = 0; n < res; n++) {
print_nfc_target(ant[n], verbose);
print_nfc_target(&ant[n], verbose);
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" : ":");
}
for (n = 0; n < res; n++) {
print_nfc_target(ant[n], verbose);
print_nfc_target(&ant[n], verbose);
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" : ":");
}
for (n = 0; n < res; n++) {
print_nfc_target(ant[n], verbose);
print_nfc_target(&ant[n], verbose);
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" : ":");
}
for (n = 0; n < res; n++) {
print_nfc_target(ant[n], verbose);
print_nfc_target(&ant[n], verbose);
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" : ":");
}
for (n = 0; n < res; n++) {
print_nfc_target(ant[n], verbose);
print_nfc_target(&ant[n], verbose);
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" : ":");
}
for (n = 0; n < res; n++) {
print_nfc_target(ant[n], verbose);
print_nfc_target(&ant[n], verbose);
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" : ":");
}
for (n = 0; n < res; n++) {
print_nfc_target(ant[n], verbose);
print_nfc_target(&ant[n], verbose);
printf("\n");
}
}

View file

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

View file

@ -271,7 +271,7 @@ main(int argc, char *argv[])
}
printf("Found tag:\n");
print_nfc_target(ntRealTarget, false);
print_nfc_target(&ntRealTarget, false);
if (initiator_only_mode) {
if (print_hex_fd4(ntRealTarget.nti.nai.abtUid, ntRealTarget.nti.nai.szUidLen, "UID") < 0) {
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);
printf("We will emulate:\n");
print_nfc_target(ntEmulatedTarget, false);
print_nfc_target(&ntEmulatedTarget, false);
// Try to open the NFC emulator device
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
print_nfc_target(const nfc_target nt, bool verbose)
print_nfc_target(const nfc_target *pnt, bool verbose)
{
char *s;
str_nfc_target(&s, nt, verbose);
str_nfc_target(&s, pnt, verbose);
printf("%s", 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_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