add nfc_initiator_poll_dep_target()
This commit is contained in:
parent
efa86f0e35
commit
e86d08218b
2 changed files with 40 additions and 0 deletions
|
@ -76,6 +76,7 @@ extern "C" {
|
|||
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_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_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 int nfc_initiator_poll_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 int 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_bits (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar);
|
||||
|
|
39
libnfc/nfc.c
39
libnfc/nfc.c
|
@ -455,6 +455,45 @@ nfc_initiator_select_dep_target (nfc_device *pnd,
|
|||
HAL (initiator_select_dep_target, pnd, ndm, nbr, pndiInitiator, pnt, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Poll a target and request active or passive mode for D.E.P. (Data Exchange Protocol)
|
||||
* @return Returns selected D.E.P targets count on success, otherwise returns libnfc's error code (negative value).
|
||||
*
|
||||
* @param pnd \a nfc_device struct pointer that represent currently used device
|
||||
* @param ndm desired D.E.P. mode (\a NDM_ACTIVE or \a NDM_PASSIVE for active, respectively passive mode)
|
||||
* @param ndiInitiator pointer \a nfc_dep_info struct that contains \e NFCID3 and \e General \e Bytes to set to the initiator device (optionnal, can be \e NULL)
|
||||
* @param[out] pnt is a \a nfc_target struct pointer where target information will be put.
|
||||
*
|
||||
* The NFC device will try to find an available D.E.P. target. The standards
|
||||
* (ISO18092 and ECMA-340) describe the modulation that can be used for reader
|
||||
* to passive communications.
|
||||
*
|
||||
* @note \a nfc_dep_info will be returned when the target was acquired successfully.
|
||||
*/
|
||||
int
|
||||
nfc_initiator_poll_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)
|
||||
{
|
||||
const int period = 300;
|
||||
int remaining_time = timeout;
|
||||
int res;
|
||||
if ((res = nfc_device_set_property_bool (pnd, NP_INFINITE_SELECT, true)) < 0)
|
||||
return res;
|
||||
while (remaining_time > 0) {
|
||||
if ((res = nfc_initiator_select_dep_target (pnd, ndm, nbr, pndiInitiator, pnt, period)) < 0) {
|
||||
if (res != NFC_ETIMEOUT)
|
||||
return res;
|
||||
}
|
||||
if (res == 1)
|
||||
return res;
|
||||
remaining_time -= period;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deselect a selected passive or emulated tag
|
||||
* @return Returns 0 on success, otherwise returns libnfc's error code (negative value).
|
||||
|
|
Loading…
Reference in a new issue