Replace nfc_target_info_t with nfc_target_t in API function, we now have a coherent struct to handle nfc_target_t, use it!

This commit is contained in:
Romuald Conty 2010-10-14 11:44:43 +00:00
parent 6f3fbcb6bf
commit af88da1a9c
10 changed files with 76 additions and 85 deletions

View file

@ -41,7 +41,7 @@ int
main (int argc, const char *argv[])
{
nfc_device_t *pnd;
nfc_target_info_t nti;
nfc_target_t nt;
byte_t abtRx[MAX_FRAME_LEN];
size_t szRx;
byte_t abtTx[] = "Hello World!";
@ -62,12 +62,11 @@ main (int argc, const char *argv[])
return EXIT_FAILURE;
}
if(!nfc_initiator_select_dep_target (pnd, NDM_PASSIVE, NULL, &nti)) {
if(!nfc_initiator_select_dep_target (pnd, NDM_PASSIVE, NULL, &nt)) {
nfc_perror(pnd, "nfc_initiator_select_dep_target");
return EXIT_FAILURE;
}
printf( "This D.E.P. target have been found:\n" );
print_nfc_dep_info (nti.ndi);
print_nfc_target (nt);
printf ("Sending: %s\n", abtTx);
if (!nfc_initiator_transceive_bytes (pnd, abtTx, sizeof(abtTx), abtRx, &szRx)) {

View file

@ -108,7 +108,7 @@ main (int argc, const char *argv[])
}
for (i = 0; i < szDeviceFound; i++) {
nfc_target_info_t anti[MAX_TARGET_COUNT];
nfc_target_t ant[MAX_TARGET_COUNT];
pnd = nfc_connect (&(pnddDevices[i]));
if (pnd == NULL) {
@ -146,11 +146,11 @@ main (int argc, const char *argv[])
.nmt = NMT_ISO14443A,
.nbr = NBR_106,
};
if (nfc_initiator_list_passive_targets (pnd, nm, anti, MAX_TARGET_COUNT, &szTargetFound)) {
if (nfc_initiator_list_passive_targets (pnd, nm, ant, MAX_TARGET_COUNT, &szTargetFound)) {
size_t n;
printf ("%d ISO14443A passive target(s) was found%s\n", (int) szTargetFound, (szTargetFound == 0) ? ".\n" : ":");
for (n = 0; n < szTargetFound; n++) {
print_nfc_iso14443a_info (anti[n].nai);
print_nfc_iso14443a_info (ant[n].nti.nai);
printf ("\n");
}
}
@ -158,23 +158,23 @@ main (int argc, const char *argv[])
nm.nmt = NMT_FELICA;
nm.nbr = NBR_212;
// List Felica tags
if (nfc_initiator_list_passive_targets (pnd, nm, anti, MAX_TARGET_COUNT, &szTargetFound)) {
if (nfc_initiator_list_passive_targets (pnd, nm, ant, MAX_TARGET_COUNT, &szTargetFound)) {
size_t n;
printf ("%d Felica (212 kbps) passive target(s) was found%s\n", (int) szTargetFound,
(szTargetFound == 0) ? ".\n" : ":");
for (n = 0; n < szTargetFound; n++) {
print_nfc_felica_info (anti[n].nfi);
print_nfc_felica_info (ant[n].nti.nfi);
printf ("\n");
}
}
nm.nbr = NBR_424;
if (nfc_initiator_list_passive_targets (pnd, nm, anti, MAX_TARGET_COUNT, &szTargetFound)) {
if (nfc_initiator_list_passive_targets (pnd, nm, ant, MAX_TARGET_COUNT, &szTargetFound)) {
size_t n;
printf ("%d Felica (424 kbps) passive target(s) was found%s\n", (int) szTargetFound,
(szTargetFound == 0) ? ".\n" : ":");
for (n = 0; n < szTargetFound; n++) {
print_nfc_felica_info (anti[n].nfi);
print_nfc_felica_info (ant[n].nti.nfi);
printf ("\n");
}
}
@ -182,11 +182,11 @@ main (int argc, const char *argv[])
nm.nmt = NMT_ISO14443B;
nm.nbr = NBR_106;
// List ISO14443B targets
if (nfc_initiator_list_passive_targets (pnd, nm, anti, MAX_TARGET_COUNT, &szTargetFound)) {
if (nfc_initiator_list_passive_targets (pnd, nm, ant, MAX_TARGET_COUNT, &szTargetFound)) {
size_t n;
printf ("%d ISO14443B passive target(s) was found%s\n", (int) szTargetFound, (szTargetFound == 0) ? ".\n" : ":");
for (n = 0; n < szTargetFound; n++) {
print_nfc_iso14443b_info (anti[n].nbi);
print_nfc_iso14443b_info (ant[n].nti.nbi);
printf ("\n");
}
}
@ -194,11 +194,11 @@ main (int argc, const char *argv[])
nm.nmt = NMT_JEWEL;
nm.nbr = NBR_106;
// List Jewel targets
if (nfc_initiator_list_passive_targets(pnd, nm, anti, MAX_TARGET_COUNT, &szTargetFound )) {
if (nfc_initiator_list_passive_targets(pnd, nm, ant, MAX_TARGET_COUNT, &szTargetFound )) {
size_t n;
printf("%d Jewel passive target(s) was found%s\n", (int)szTargetFound, (szTargetFound==0)?".\n":":");
for(n=0; n<szTargetFound; n++) {
print_nfc_jewel_info (anti[n].nji);
print_nfc_jewel_info (ant[n].nti.nji);
printf("\n");
}
}

View file

@ -41,7 +41,7 @@
#include "nfc-utils.h"
static nfc_device_t *pnd;
static nfc_target_info_t nti;
static nfc_target_t nt;
static mifare_param mp;
static mifare_classic_tag mtKeys;
static mifare_classic_tag mtDump;
@ -118,7 +118,7 @@ authenticate (uint32_t uiBlock)
// Key file authentication.
if (bUseKeyFile) {
// Set the authentication information (uid)
memcpy (mp.mpa.abtUid, nti.nai.abtUid, 4);
memcpy (mp.mpa.abtUid, nt.nti.nai.abtUid, 4);
// Locate the trailer (with the keys) used for this sector
uiTrailerBlock = get_trailer_block (uiBlock);
@ -142,7 +142,7 @@ authenticate (uint32_t uiBlock)
mc = (bUseKeyA) ? MC_AUTH_A : MC_AUTH_B;
// Set the authentication information (uid)
memcpy (mp.mpa.abtUid, nti.nai.abtUid, 4);
memcpy (mp.mpa.abtUid, nt.nti.nai.abtUid, 4);
for (key_index = 0; key_index < num_keys; key_index++) {
memcpy (mp.mpa.abtKey, keys + (key_index * 6), 6);
@ -182,7 +182,7 @@ read_card (void)
// Show if the readout went well
if (bFailure) {
// When a failure occured we need to redo the anti-collision
if (!nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nti)) {
if (!nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt)) {
printf ("!\nError: tag was removed\n");
return false;
}
@ -247,7 +247,7 @@ write_card (void)
// Show if the readout went well
if (bFailure) {
// When a failure occured we need to redo the anti-collision
if (!nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nti)) {
if (!nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt)) {
printf ("!\nError: tag was removed\n");
return false;
}
@ -447,13 +447,13 @@ main (int argc, const char *argv[])
printf ("Connected to NFC reader: %s\n", pnd->acName);
// Try to find a MIFARE Classic tag
if (!nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nti)) {
if (!nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt)) {
printf ("Error: no tag was found\n");
nfc_disconnect (pnd);
exit (EXIT_FAILURE);
}
// Test if we are dealing with a MIFARE compatible tag
if ((nti.nai.btSak & 0x08) == 0) {
if ((nt.nti.nai.btSak & 0x08) == 0) {
printf ("Error: tag is not a MIFARE Classic card\n");
nfc_disconnect (pnd);
exit (EXIT_FAILURE);
@ -465,14 +465,14 @@ main (int argc, const char *argv[])
pbtUID = mtKeys.amb[0].mbm.abtUID;
// Compare if key dump UID is the same as the current tag UID
if (memcmp (nti.nai.abtUid, pbtUID, 4) != 0) {
if (memcmp (nt.nti.nai.abtUid, pbtUID, 4) != 0) {
printf ("Expected MIFARE Classic %ck card with UID: %02x%02x%02x%02x\n", b4K ? '4' : '1', pbtUID[3], pbtUID[2],
pbtUID[1], pbtUID[0]);
}
}
// Get the info from the current tag
pbtUID = nti.nai.abtUid;
b4K = (nti.nai.abtAtqa[1] == 0x02);
pbtUID = nt.nti.nai.abtUid;
b4K = (nt.nti.nai.abtAtqa[1] == 0x02);
printf ("Found MIFARE Classic %ck card with UID: %02x%02x%02x%02x\n", b4K ? '4' : '1', pbtUID[3], pbtUID[2],
pbtUID[1], pbtUID[0]);

View file

@ -42,7 +42,7 @@
#include "nfc-utils.h"
static nfc_device_t *pnd;
static nfc_target_info_t nti;
static nfc_target_t nt;
static mifare_param mp;
static mifareul_tag mtDump;
static uint32_t uiBlocks = 0xF;
@ -121,7 +121,7 @@ write_card (void)
// Show if the readout went well
if (bFailure) {
// When a failure occured we need to redo the anti-collision
if (!nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nti)) {
if (!nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt)) {
ERR ("tag was removed");
return false;
}
@ -221,20 +221,20 @@ main (int argc, const char *argv[])
printf ("Connected to NFC device: %s\n", pnd->acName);
// Try to find a MIFARE Ultralight tag
if (!nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nti)) {
if (!nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt)) {
ERR ("no tag was found\n");
nfc_disconnect (pnd);
return 1;
}
// Test if we are dealing with a MIFARE compatible tag
if (nti.nai.abtAtqa[1] != 0x44) {
if (nt.nti.nai.abtAtqa[1] != 0x44) {
ERR ("tag is not a MIFARE Ultralight card\n");
nfc_disconnect (pnd);
return EXIT_FAILURE;
}
// Get the info from the current tag (UID is stored little-endian)
pbtUID = nti.nai.abtUid;
pbtUID = nt.nti.nai.abtUid;
printf ("Found MIFARE Ultralight card with UID: %02x%02x%02x%02x\n", pbtUID[3], pbtUID[2], pbtUID[1], pbtUID[0]);
if (bReadAction) {

View file

@ -160,7 +160,7 @@ main (int argc, const char *argv[])
case WIRED_CARD_MODE:
{
nfc_target_info_t nti;
nfc_target_t nt;
// Set connected NFC device to initiator mode
nfc_initiator_init (pnd);
@ -185,14 +185,14 @@ main (int argc, const char *argv[])
.nmt = NMT_ISO14443A,
.nbr = NBR_106,
};
if (!nfc_initiator_select_passive_target (pnd, nmSAM, NULL, 0, &nti)) {
if (!nfc_initiator_select_passive_target (pnd, nmSAM, NULL, 0, &nt)) {
nfc_perror (pnd, "nfc_initiator_select_passive_target");
ERR ("%s", "Reading of SAM info failed.");
return EXIT_FAILURE;
}
printf ("The following ISO14443A tag (SAM) was found:\n\n");
print_nfc_iso14443a_info (nti.nai);
print_nfc_iso14443a_info (nt.nti.nai);
}
break;