nfc_initiator_poll_target() function returns now libnfc error code.

This commit is contained in:
Audrey Diacre 2011-12-20 15:46:35 +00:00
parent 42276ccd14
commit 0f5cc5683d
6 changed files with 22 additions and 20 deletions

View file

@ -90,7 +90,7 @@ main (int argc, const char *argv[])
const size_t szModulations = 5; const size_t szModulations = 5;
nfc_target nt; nfc_target nt;
bool res; int res = 0;
pnd = nfc_connect (NULL); pnd = nfc_connect (NULL);
@ -109,7 +109,7 @@ main (int argc, const char *argv[])
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
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

@ -74,7 +74,7 @@ extern "C" {
NFC_EXPORT int nfc_initiator_init (nfc_device *pnd); NFC_EXPORT int nfc_initiator_init (nfc_device *pnd);
NFC_EXPORT int nfc_initiator_select_passive_target (nfc_device *pnd, const nfc_modulation nm, const uint8_t *pbtInitData, const size_t szInitData, nfc_target *pnt); NFC_EXPORT int nfc_initiator_select_passive_target (nfc_device *pnd, const nfc_modulation nm, const uint8_t *pbtInitData, const size_t szInitData, nfc_target *pnt);
NFC_EXPORT int nfc_initiator_list_passive_targets (nfc_device *pnd, const nfc_modulation nm, nfc_target ant[], const size_t szTargets); NFC_EXPORT int nfc_initiator_list_passive_targets (nfc_device *pnd, const nfc_modulation nm, nfc_target ant[], const size_t szTargets);
NFC_EXPORT bool nfc_initiator_poll_target (nfc_device *pnd, const nfc_modulation *pnmTargetTypes, const size_t szTargetTypes, const uint8_t uiPollNr, const uint8_t uiPeriod, nfc_target *pnt); NFC_EXPORT int nfc_initiator_poll_target (nfc_device *pnd, const nfc_modulation *pnmTargetTypes, const size_t szTargetTypes, const uint8_t uiPollNr, const uint8_t uiPeriod, nfc_target *pnt);
NFC_EXPORT bool nfc_initiator_select_dep_target (nfc_device *pnd, const nfc_dep_mode ndm, const nfc_baud_rate nbr, const nfc_dep_info *pndiInitiator, nfc_target *pnt, const int timeout); NFC_EXPORT bool nfc_initiator_select_dep_target (nfc_device *pnd, const nfc_dep_mode ndm, const nfc_baud_rate nbr, const nfc_dep_info *pndiInitiator, nfc_target *pnt, const int timeout);
NFC_EXPORT bool nfc_initiator_deselect_target (nfc_device *pnd); NFC_EXPORT bool nfc_initiator_deselect_target (nfc_device *pnd);
NFC_EXPORT int nfc_initiator_transceive_bytes (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, size_t *pszRx, int timeout); NFC_EXPORT int nfc_initiator_transceive_bytes (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, size_t *pszRx, int timeout);

View file

@ -1016,12 +1016,14 @@ pn53x_initiator_select_passive_target (struct nfc_device *pnd,
return pn53x_initiator_select_passive_target_ext (pnd, nm, pbtInitData, szInitData, pnt, 0); return pn53x_initiator_select_passive_target_ext (pnd, nm, pbtInitData, szInitData, pnt, 0);
} }
bool int
pn53x_initiator_poll_target (struct nfc_device *pnd, pn53x_initiator_poll_target (struct nfc_device *pnd,
const nfc_modulation *pnmModulations, const size_t szModulations, const nfc_modulation *pnmModulations, const size_t szModulations,
const uint8_t uiPollNr, const uint8_t uiPeriod, const uint8_t uiPollNr, const uint8_t uiPeriod,
nfc_target *pnt) nfc_target *pnt)
{ {
int res = 0;
if (CHIP_DATA(pnd)->type == PN532) { if (CHIP_DATA(pnd)->type == PN532) {
size_t szTargetTypes = 0; size_t szTargetTypes = 0;
pn53x_target_type apttTargetTypes[32]; pn53x_target_type apttTargetTypes[32];
@ -1029,7 +1031,7 @@ pn53x_initiator_poll_target (struct nfc_device *pnd,
const pn53x_target_type ptt = pn53x_nm_to_ptt(pnmModulations[n]); const pn53x_target_type ptt = pn53x_nm_to_ptt(pnmModulations[n]);
if (PTT_UNDEFINED == ptt) { if (PTT_UNDEFINED == ptt) {
pnd->last_error = NFC_EINVARG; pnd->last_error = NFC_EINVARG;
return false; return pnd->last_error;
} }
apttTargetTypes[szTargetTypes] = ptt; apttTargetTypes[szTargetTypes] = ptt;
if ((pnd->bAutoIso14443_4) && (ptt == PTT_MIFARE)) { // Hack to have ATS if ((pnd->bAutoIso14443_4) && (ptt == PTT_MIFARE)) { // Hack to have ATS
@ -1041,19 +1043,19 @@ pn53x_initiator_poll_target (struct nfc_device *pnd,
} }
size_t szTargetFound = 0; size_t szTargetFound = 0;
nfc_target ntTargets[2]; nfc_target ntTargets[2];
if (pn53x_InAutoPoll (pnd, apttTargetTypes, szTargetTypes, uiPollNr, uiPeriod, ntTargets, &szTargetFound, 0) < 0) if ((res = pn53x_InAutoPoll (pnd, apttTargetTypes, szTargetTypes, uiPollNr, uiPeriod, ntTargets, &szTargetFound, 0)) < 0)
return false; return res;
switch (szTargetFound) { switch (szTargetFound) {
case 1: case 1:
*pnt = ntTargets[0]; *pnt = ntTargets[0];
return true; return NFC_SUCCESS;
break; break;
case 2: case 2:
*pnt = ntTargets[1]; // We keep the selected one *pnt = ntTargets[1]; // We keep the selected one
return true; return NFC_SUCCESS;
break; break;
default: default:
return false; return NFC_ECHIP;
break; break;
} }
} else { } else {
@ -1069,15 +1071,15 @@ pn53x_initiator_poll_target (struct nfc_device *pnd,
if (pn53x_initiator_select_passive_target_ext (pnd, pnmModulations[n], pbtInitiatorData, szInitiatorData, pnt, timeout_ms) < 0) { if (pn53x_initiator_select_passive_target_ext (pnd, pnmModulations[n], pbtInitiatorData, szInitiatorData, pnt, timeout_ms) < 0) {
if (pnd->last_error != NFC_ETIMEOUT) if (pnd->last_error != NFC_ETIMEOUT)
return false; return pnd->last_error;
} else { } else {
return true; return NFC_SUCCESS;
} }
} }
} }
} while (uiPollNr==0xff); // uiPollNr==0xff means infinite polling } while (uiPollNr==0xff); // uiPollNr==0xff means infinite polling
} }
return false; return NFC_ECHIP;
} }
bool bool

View file

@ -290,7 +290,7 @@ int pn53x_initiator_select_passive_target (struct nfc_device *pnd,
const nfc_modulation nm, const nfc_modulation nm,
const uint8_t *pbtInitData, const size_t szInitData, const uint8_t *pbtInitData, const size_t szInitData,
nfc_target *pnt); nfc_target *pnt);
bool pn53x_initiator_poll_target (struct nfc_device *pnd, int pn53x_initiator_poll_target (struct nfc_device *pnd,
const nfc_modulation *pnmModulations, const size_t szModulations, const nfc_modulation *pnmModulations, const size_t szModulations,
const uint8_t uiPollNr, const uint8_t uiPeriod, const uint8_t uiPollNr, const uint8_t uiPeriod,
nfc_target *pnt); nfc_target *pnt);

View file

@ -134,7 +134,7 @@ struct nfc_driver_t {
int (*initiator_init) (struct nfc_device *pnd); int (*initiator_init) (struct nfc_device *pnd);
int (*initiator_select_passive_target) (struct nfc_device *pnd, const nfc_modulation nm, const uint8_t * pbtInitData, const size_t szInitData, nfc_target * pnt); int (*initiator_select_passive_target) (struct nfc_device *pnd, const nfc_modulation nm, const uint8_t * pbtInitData, const size_t szInitData, nfc_target * pnt);
bool (*initiator_poll_target) (struct nfc_device *pnd, const nfc_modulation * pnmModulations, const size_t szModulations, const uint8_t uiPollNr, const uint8_t btPeriod, nfc_target * pnt); int (*initiator_poll_target) (struct nfc_device *pnd, const nfc_modulation * pnmModulations, const size_t szModulations, const uint8_t uiPollNr, const uint8_t btPeriod, nfc_target * pnt);
bool (*initiator_select_dep_target) (struct nfc_device *pnd, const nfc_dep_mode ndm, const nfc_baud_rate nbr, const nfc_dep_info * pndiInitiator, nfc_target * pnt, const int timeout); bool (*initiator_select_dep_target) (struct nfc_device *pnd, const nfc_dep_mode ndm, const nfc_baud_rate nbr, const nfc_dep_info * pndiInitiator, nfc_target * pnt, const int timeout);
bool (*initiator_deselect_target) (struct nfc_device *pnd); bool (*initiator_deselect_target) (struct nfc_device *pnd);
int (*initiator_transceive_bytes) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, size_t * pszRx, int timeout); int (*initiator_transceive_bytes) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, size_t * pszRx, int timeout);

View file

@ -410,7 +410,7 @@ nfc_initiator_list_passive_targets (nfc_device *pnd,
/** /**
* @brief Polling for NFC targets * @brief Polling for NFC targets
* @return Returns \c true if action was successfully performed; otherwise returns \c false. * @return Returns 0 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 ppttTargetTypes array of desired target types * @param ppttTargetTypes array of desired target types
@ -421,7 +421,7 @@ nfc_initiator_list_passive_targets (nfc_device *pnd,
* @note e.g. if uiPeriod=10, it will poll each desired target type during 1.5s * @note e.g. if uiPeriod=10, it will poll each desired target type during 1.5s
* @param[out] pnt pointer on \a nfc_target (over)writable struct * @param[out] pnt pointer on \a nfc_target (over)writable struct
*/ */
bool int
nfc_initiator_poll_target (nfc_device *pnd, nfc_initiator_poll_target (nfc_device *pnd,
const nfc_modulation *pnmModulations, const size_t szModulations, const nfc_modulation *pnmModulations, const size_t szModulations,
const uint8_t uiPollNr, const uint8_t uiPeriod, const uint8_t uiPollNr, const uint8_t uiPeriod,