nfc_initiator_select_passive_target() function returns now the selected passive targets count on success.

This commit is contained in:
Audrey Diacre 2011-12-21 11:33:21 +00:00
parent ff066e394d
commit f93bc59504
4 changed files with 24 additions and 21 deletions

View file

@ -35,7 +35,7 @@ main (int argc, const char *argv[])
.nmt = NMT_ISO14443A,
.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 (" ATQA (SENS_RES): ");
print_hex (nt.nti.nai.abtAtqa, 2);

View file

@ -980,31 +980,31 @@ pn53x_initiator_select_passive_target_ext (struct nfc_device *pnd,
return res;
}
}
return NFC_SUCCESS;
return abtTargetsData[0];
} // else:
const pn53x_modulation pm = pn53x_nm_to_pm(nm);
if (PM_UNDEFINED == pm) {
pnd->last_error = NFC_EINVARG;
return false;
return pnd->last_error;
}
if (pn53x_InListPassiveTarget (pnd, pm, 1, pbtInitData, szInitData, abtTargetsData, &szTargetsData, timeout) < 0)
return false;
if ((res = pn53x_InListPassiveTarget (pnd, pm, 1, pbtInitData, szInitData, abtTargetsData, &szTargetsData, timeout)) < 0)
return res;
// Make sure one tag has been found, the PN53X returns 0x00 if none was available
if (abtTargetsData[0] == 0)
return false;
if (res == 0)
return NFC_ECHIP;
// Is a tag info struct available
if (pnt) {
pnt->nm = nm;
// 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))) {
return false;
return NFC_ECHIP;
}
}
return true;
return abtTargetsData[0];
}
int
@ -2069,7 +2069,7 @@ pn53x_PowerDown (struct nfc_device *pnd)
/**
* @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 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).
if (pbtInitiatorData)
memcpy (abtCmd + 3, pbtInitiatorData, szInitiatorData);
return pn53x_transceive (pnd, abtCmd, 3 + szInitiatorData, pbtTargetsData, pszTargetsData, timeout);
int res = 0;
if ((res = pn53x_transceive (pnd, abtCmd, 3 + szInitiatorData, pbtTargetsData, pszTargetsData, timeout)) < 0) {
return res;
}
return pbtTargetsData[0];
}
int

View file

@ -304,7 +304,7 @@ nfc_initiator_init (nfc_device *pnd)
/**
* @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 nm desired modulation
@ -381,7 +381,7 @@ nfc_initiator_list_passive_targets (nfc_device *pnd,
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);
if (szTargets == szTargetFound) {
break;

View file

@ -138,7 +138,7 @@ 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, ant, MAX_TARGET_COUNT) >= 0) {
if ((res = nfc_initiator_list_passive_targets (pnd, nm, ant, MAX_TARGET_COUNT)) >= 0) {
int n;
if (verbose) {
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;
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;
if (verbose) {
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.nbr = NBR_106;
// 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;
if (verbose) {
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.nbr = NBR_106;
// 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;
if (verbose) {
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.nbr = NBR_106;
// 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;
if (verbose) {
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.nbr = NBR_106;
// 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;
if (verbose) {
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.nbr = NBR_106;
// 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;
if (verbose) {
printf("%d Jewel passive target(s) found%s\n", res, (res == 0)?".\n":":");