nfc_initiator_poll_target() function returns now libnfc error code.
This commit is contained in:
parent
42276ccd14
commit
0f5cc5683d
6 changed files with 22 additions and 20 deletions
|
@ -90,7 +90,7 @@ main (int argc, const char *argv[])
|
|||
const size_t szModulations = 5;
|
||||
|
||||
nfc_target nt;
|
||||
bool res;
|
||||
int res = 0;
|
||||
|
||||
pnd = nfc_connect (NULL);
|
||||
|
||||
|
@ -109,7 +109,7 @@ main (int argc, const char *argv[])
|
|||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (res > 0) {
|
||||
if (res == 0) {
|
||||
print_nfc_target ( nt, verbose );
|
||||
} else {
|
||||
printf ("No target found.\n");
|
||||
|
|
|
@ -74,7 +74,7 @@ extern "C" {
|
|||
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_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_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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
bool
|
||||
int
|
||||
pn53x_initiator_poll_target (struct nfc_device *pnd,
|
||||
const nfc_modulation *pnmModulations, const size_t szModulations,
|
||||
const uint8_t uiPollNr, const uint8_t uiPeriod,
|
||||
nfc_target *pnt)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
if (CHIP_DATA(pnd)->type == PN532) {
|
||||
size_t szTargetTypes = 0;
|
||||
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]);
|
||||
if (PTT_UNDEFINED == ptt) {
|
||||
pnd->last_error = NFC_EINVARG;
|
||||
return false;
|
||||
return pnd->last_error;
|
||||
}
|
||||
apttTargetTypes[szTargetTypes] = ptt;
|
||||
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;
|
||||
nfc_target ntTargets[2];
|
||||
if (pn53x_InAutoPoll (pnd, apttTargetTypes, szTargetTypes, uiPollNr, uiPeriod, ntTargets, &szTargetFound, 0) < 0)
|
||||
return false;
|
||||
if ((res = pn53x_InAutoPoll (pnd, apttTargetTypes, szTargetTypes, uiPollNr, uiPeriod, ntTargets, &szTargetFound, 0)) < 0)
|
||||
return res;
|
||||
switch (szTargetFound) {
|
||||
case 1:
|
||||
*pnt = ntTargets[0];
|
||||
return true;
|
||||
return NFC_SUCCESS;
|
||||
break;
|
||||
case 2:
|
||||
*pnt = ntTargets[1]; // We keep the selected one
|
||||
return true;
|
||||
return NFC_SUCCESS;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
return NFC_ECHIP;
|
||||
break;
|
||||
}
|
||||
} 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 (pnd->last_error != NFC_ETIMEOUT)
|
||||
return false;
|
||||
return pnd->last_error;
|
||||
} else {
|
||||
return true;
|
||||
return NFC_SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (uiPollNr==0xff); // uiPollNr==0xff means infinite polling
|
||||
}
|
||||
return false;
|
||||
return NFC_ECHIP;
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -285,12 +285,12 @@ bool pn53x_check_communication (struct nfc_device *pnd);
|
|||
bool pn53x_idle (struct nfc_device *pnd);
|
||||
|
||||
// NFC device as Initiator functions
|
||||
int pn53x_initiator_init (struct nfc_device *pnd);
|
||||
int pn53x_initiator_init (struct nfc_device *pnd);
|
||||
int pn53x_initiator_select_passive_target (struct nfc_device *pnd,
|
||||
const nfc_modulation nm,
|
||||
const uint8_t *pbtInitData, const size_t szInitData,
|
||||
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 uint8_t uiPollNr, const uint8_t uiPeriod,
|
||||
nfc_target *pnt);
|
||||
|
|
|
@ -132,12 +132,12 @@ struct nfc_driver_t {
|
|||
void (*disconnect) (struct nfc_device *pnd);
|
||||
const char *(*strerror) (const struct nfc_device *pnd);
|
||||
|
||||
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);
|
||||
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_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);
|
||||
bool (*initiator_transceive_bits) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar, uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar);
|
||||
bool (*initiator_transceive_bytes_timed) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, size_t * pszRx, uint32_t * cycles);
|
||||
bool (*initiator_transceive_bits_timed) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar, uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar, uint32_t * cycles);
|
||||
|
|
|
@ -410,7 +410,7 @@ nfc_initiator_list_passive_targets (nfc_device *pnd,
|
|||
|
||||
/**
|
||||
* @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 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
|
||||
* @param[out] pnt pointer on \a nfc_target (over)writable struct
|
||||
*/
|
||||
bool
|
||||
int
|
||||
nfc_initiator_poll_target (nfc_device *pnd,
|
||||
const nfc_modulation *pnmModulations, const size_t szModulations,
|
||||
const uint8_t uiPollNr, const uint8_t uiPeriod,
|
||||
|
|
Loading…
Reference in a new issue