nfc_initiator_select_passive_target() function returns now the selected passive targets count on success.
This commit is contained in:
parent
ff066e394d
commit
f93bc59504
4 changed files with 24 additions and 21 deletions
|
@ -35,7 +35,7 @@ main (int argc, const char *argv[])
|
||||||
.nmt = NMT_ISO14443A,
|
.nmt = NMT_ISO14443A,
|
||||||
.nbr = NBR_106,
|
.nbr = NBR_106,
|
||||||
};
|
};
|
||||||
if (nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt) == 0) {
|
if (nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt) > 0) {
|
||||||
printf ("The following (NFC) ISO14443A tag was found:\n");
|
printf ("The following (NFC) ISO14443A tag was found:\n");
|
||||||
printf (" ATQA (SENS_RES): ");
|
printf (" ATQA (SENS_RES): ");
|
||||||
print_hex (nt.nti.nai.abtAtqa, 2);
|
print_hex (nt.nti.nai.abtAtqa, 2);
|
||||||
|
|
|
@ -980,31 +980,31 @@ pn53x_initiator_select_passive_target_ext (struct nfc_device *pnd,
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NFC_SUCCESS;
|
return abtTargetsData[0];
|
||||||
} // else:
|
} // else:
|
||||||
|
|
||||||
const pn53x_modulation pm = pn53x_nm_to_pm(nm);
|
const pn53x_modulation pm = pn53x_nm_to_pm(nm);
|
||||||
if (PM_UNDEFINED == pm) {
|
if (PM_UNDEFINED == pm) {
|
||||||
pnd->last_error = NFC_EINVARG;
|
pnd->last_error = NFC_EINVARG;
|
||||||
return false;
|
return pnd->last_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pn53x_InListPassiveTarget (pnd, pm, 1, pbtInitData, szInitData, abtTargetsData, &szTargetsData, timeout) < 0)
|
if ((res = pn53x_InListPassiveTarget (pnd, pm, 1, pbtInitData, szInitData, abtTargetsData, &szTargetsData, timeout)) < 0)
|
||||||
return false;
|
return res;
|
||||||
|
|
||||||
// Make sure one tag has been found, the PN53X returns 0x00 if none was available
|
// Make sure one tag has been found, the PN53X returns 0x00 if none was available
|
||||||
if (abtTargetsData[0] == 0)
|
if (res == 0)
|
||||||
return false;
|
return NFC_ECHIP;
|
||||||
|
|
||||||
// Is a tag info struct available
|
// Is a tag info struct available
|
||||||
if (pnt) {
|
if (pnt) {
|
||||||
pnt->nm = nm;
|
pnt->nm = nm;
|
||||||
// Fill the tag info struct with the values corresponding to this init modulation
|
// Fill the tag info struct with the values corresponding to this init modulation
|
||||||
if (!pn53x_decode_target_data (abtTargetsData + 1, szTargetsData - 1, CHIP_DATA(pnd)->type, nm.nmt, &(pnt->nti))) {
|
if (!pn53x_decode_target_data (abtTargetsData + 1, szTargetsData - 1, CHIP_DATA(pnd)->type, nm.nmt, &(pnt->nti))) {
|
||||||
return false;
|
return NFC_ECHIP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return abtTargetsData[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -2069,7 +2069,7 @@ pn53x_PowerDown (struct nfc_device *pnd)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief C wrapper to InListPassiveTarget command
|
* @brief C wrapper to InListPassiveTarget command
|
||||||
* @return true if command is successfully sent
|
* @return Returns selected targets count on success, otherwise returns libnfc's error code (negative value)
|
||||||
*
|
*
|
||||||
* @param pnd struct nfc_device struct pointer that represent currently used device
|
* @param pnd struct nfc_device struct pointer that represent currently used device
|
||||||
* @param pmInitModulation Desired modulation
|
* @param pmInitModulation Desired modulation
|
||||||
|
@ -2130,8 +2130,11 @@ pn53x_InListPassiveTarget (struct nfc_device *pnd,
|
||||||
// Set the optional initiator data (used for Felica, ISO14443B, Topaz Polling or for ISO14443A selecting a specific UID).
|
// Set the optional initiator data (used for Felica, ISO14443B, Topaz Polling or for ISO14443A selecting a specific UID).
|
||||||
if (pbtInitiatorData)
|
if (pbtInitiatorData)
|
||||||
memcpy (abtCmd + 3, pbtInitiatorData, szInitiatorData);
|
memcpy (abtCmd + 3, pbtInitiatorData, szInitiatorData);
|
||||||
|
int res = 0;
|
||||||
return pn53x_transceive (pnd, abtCmd, 3 + szInitiatorData, pbtTargetsData, pszTargetsData, timeout);
|
if ((res = pn53x_transceive (pnd, abtCmd, 3 + szInitiatorData, pbtTargetsData, pszTargetsData, timeout)) < 0) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
return pbtTargetsData[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -304,7 +304,7 @@ nfc_initiator_init (nfc_device *pnd)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Select a passive or emulated tag
|
* @brief Select a passive or emulated tag
|
||||||
* @return Returns 0 on success, otherwise returns libnfc's error code (negative value)
|
* @return Returns selected passive target count on success, otherwise returns libnfc's error code (negative value)
|
||||||
*
|
*
|
||||||
* @param pnd \a nfc_device struct pointer that represent currently used device
|
* @param pnd \a nfc_device struct pointer that represent currently used device
|
||||||
* @param nm desired modulation
|
* @param nm desired modulation
|
||||||
|
@ -381,7 +381,7 @@ nfc_initiator_list_passive_targets (nfc_device *pnd,
|
||||||
|
|
||||||
prepare_initiator_data (nm, &pbtInitData, &szInitDataLen);
|
prepare_initiator_data (nm, &pbtInitData, &szInitDataLen);
|
||||||
|
|
||||||
while (nfc_initiator_select_passive_target (pnd, nm, pbtInitData, szInitDataLen, &nt) == 0) {
|
while (nfc_initiator_select_passive_target (pnd, nm, pbtInitData, szInitDataLen, &nt) > 0) {
|
||||||
nfc_initiator_deselect_target (pnd);
|
nfc_initiator_deselect_target (pnd);
|
||||||
if (szTargets == szTargetFound) {
|
if (szTargets == szTargetFound) {
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -138,7 +138,7 @@ main (int argc, const char *argv[])
|
||||||
nm.nmt = NMT_FELICA;
|
nm.nmt = NMT_FELICA;
|
||||||
nm.nbr = NBR_212;
|
nm.nbr = NBR_212;
|
||||||
// List Felica tags
|
// List Felica tags
|
||||||
if (nfc_initiator_list_passive_targets (pnd, nm, ant, MAX_TARGET_COUNT) >= 0) {
|
if ((res = nfc_initiator_list_passive_targets (pnd, nm, ant, MAX_TARGET_COUNT)) >= 0) {
|
||||||
int n;
|
int n;
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
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" : ":");
|
||||||
|
@ -150,7 +150,7 @@ main (int argc, const char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
nm.nbr = NBR_424;
|
nm.nbr = NBR_424;
|
||||||
if (nfc_initiator_list_passive_targets (pnd, nm, ant, MAX_TARGET_COUNT) >= 0) {
|
if ((res = nfc_initiator_list_passive_targets (pnd, nm, ant, MAX_TARGET_COUNT)) >= 0) {
|
||||||
int n;
|
int n;
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
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" : ":");
|
||||||
|
@ -164,7 +164,7 @@ main (int argc, const char *argv[])
|
||||||
nm.nmt = NMT_ISO14443B;
|
nm.nmt = NMT_ISO14443B;
|
||||||
nm.nbr = NBR_106;
|
nm.nbr = NBR_106;
|
||||||
// List ISO14443B targets
|
// List ISO14443B targets
|
||||||
if (nfc_initiator_list_passive_targets (pnd, nm, ant, MAX_TARGET_COUNT) >= 0) {
|
if ((res = nfc_initiator_list_passive_targets (pnd, nm, ant, MAX_TARGET_COUNT)) >= 0) {
|
||||||
int n;
|
int n;
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
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" : ":");
|
||||||
|
@ -178,7 +178,7 @@ main (int argc, const char *argv[])
|
||||||
nm.nmt = NMT_ISO14443BI;
|
nm.nmt = NMT_ISO14443BI;
|
||||||
nm.nbr = NBR_106;
|
nm.nbr = NBR_106;
|
||||||
// List ISO14443B' targets
|
// List ISO14443B' targets
|
||||||
if (nfc_initiator_list_passive_targets (pnd, nm, ant, MAX_TARGET_COUNT) >= 0) {
|
if ((res = nfc_initiator_list_passive_targets (pnd, nm, ant, MAX_TARGET_COUNT)) >= 0) {
|
||||||
int n;
|
int n;
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
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" : ":");
|
||||||
|
@ -192,7 +192,7 @@ main (int argc, const char *argv[])
|
||||||
nm.nmt = NMT_ISO14443B2SR;
|
nm.nmt = NMT_ISO14443B2SR;
|
||||||
nm.nbr = NBR_106;
|
nm.nbr = NBR_106;
|
||||||
// List ISO14443B-2 ST SRx family targets
|
// List ISO14443B-2 ST SRx family targets
|
||||||
if (nfc_initiator_list_passive_targets (pnd, nm, ant, MAX_TARGET_COUNT) >= 0) {
|
if ((res = nfc_initiator_list_passive_targets (pnd, nm, ant, MAX_TARGET_COUNT)) >= 0) {
|
||||||
int n;
|
int n;
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
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" : ":");
|
||||||
|
@ -206,7 +206,7 @@ main (int argc, const char *argv[])
|
||||||
nm.nmt = NMT_ISO14443B2CT;
|
nm.nmt = NMT_ISO14443B2CT;
|
||||||
nm.nbr = NBR_106;
|
nm.nbr = NBR_106;
|
||||||
// List ISO14443B-2 ASK CTx family targets
|
// List ISO14443B-2 ASK CTx family targets
|
||||||
if (nfc_initiator_list_passive_targets (pnd, nm, ant, MAX_TARGET_COUNT) >= 0) {
|
if ((res = nfc_initiator_list_passive_targets (pnd, nm, ant, MAX_TARGET_COUNT)) >= 0) {
|
||||||
int n;
|
int n;
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
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" : ":");
|
||||||
|
@ -220,7 +220,7 @@ main (int argc, const char *argv[])
|
||||||
nm.nmt = NMT_JEWEL;
|
nm.nmt = NMT_JEWEL;
|
||||||
nm.nbr = NBR_106;
|
nm.nbr = NBR_106;
|
||||||
// List Jewel targets
|
// List Jewel targets
|
||||||
if (nfc_initiator_list_passive_targets(pnd, nm, ant, MAX_TARGET_COUNT) >= 0) {
|
if ((res = nfc_initiator_list_passive_targets(pnd, nm, ant, MAX_TARGET_COUNT)) >= 0) {
|
||||||
int n;
|
int n;
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
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":":");
|
||||||
|
|
Loading…
Reference in a new issue