New function nfc_initiator_target_is_present() to test is a previously selected target is in the field.
This commit is contained in:
parent
2c9275adde
commit
8f08431ddf
12 changed files with 49 additions and 1 deletions
2
NEWS
2
NEWS
|
@ -12,6 +12,8 @@ API Changes:
|
|||
information
|
||||
- No more in/out function parameter: nfc_initiator_transceive_bytes() now
|
||||
take a constant size for Rx buffer
|
||||
- New nfc_initiator_target_is_present() to test is the previously selected
|
||||
target is available in the field
|
||||
|
||||
New in 1.6.0-rc1:
|
||||
|
||||
|
|
|
@ -86,6 +86,7 @@ extern "C" {
|
|||
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);
|
||||
NFC_EXPORT int nfc_initiator_transceive_bytes_timed (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, uint32_t *cycles);
|
||||
NFC_EXPORT int nfc_initiator_transceive_bits_timed (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar, uint32_t *cycles);
|
||||
NFC_EXPORT int nfc_initiator_target_is_present (nfc_device *pnd, const nfc_target nt);
|
||||
|
||||
/* NFC target: act as tag (i.e. MIFARE Classic) or NFC target device. */
|
||||
NFC_EXPORT int nfc_target_init (nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t szRx, int timeout);
|
||||
|
|
|
@ -199,6 +199,13 @@ pn53x_transceive (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szT
|
|||
if (pbtRx[0] & 0x40) { abort(); } // MI detected
|
||||
CHIP_DATA(pnd)->last_status_byte = pbtRx[0] & 0x3f;
|
||||
break;
|
||||
case Diagnose:
|
||||
if (pbtTx[1] == 0x06) { // Diagnose: Card presence detection
|
||||
CHIP_DATA(pnd)->last_status_byte = pbtRx[0] & 0x3f;
|
||||
} else {
|
||||
CHIP_DATA(pnd)->last_status_byte = 0;
|
||||
};
|
||||
break;
|
||||
case InDeselect:
|
||||
case InRelease:
|
||||
if (CHIP_DATA(pnd)->type == RCS360) {
|
||||
|
@ -1624,6 +1631,22 @@ pn53x_initiator_deselect_target (struct nfc_device *pnd)
|
|||
return pn53x_InDeselect (pnd, 0); // 0 mean deselect all selected targets
|
||||
}
|
||||
|
||||
int
|
||||
pn53x_initiator_target_is_present (struct nfc_device *pnd, const nfc_target nt)
|
||||
{
|
||||
// TODO Check if nt is equal to current target
|
||||
const uint8_t abtCmd[] = { Diagnose, 0x06 };
|
||||
uint8_t abtRx[1];
|
||||
int res = 0;
|
||||
|
||||
if ((res = pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRx, sizeof (abtRx), -1)) < 0)
|
||||
return res;
|
||||
if (res==1) {
|
||||
return NFC_SUCCESS;
|
||||
}
|
||||
return NFC_ETGRELEASED;
|
||||
}
|
||||
|
||||
#define SAK_ISO14443_4_COMPLIANT 0x20
|
||||
#define SAK_ISO18092_COMPLIANT 0x40
|
||||
int
|
||||
|
|
|
@ -334,6 +334,7 @@ int pn53x_initiator_transceive_bits_timed (struct nfc_device *pnd, const uint
|
|||
int pn53x_initiator_transceive_bytes_timed (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx,
|
||||
uint8_t *pbtRx, uint32_t *cycles);
|
||||
int pn53x_initiator_deselect_target (struct nfc_device *pnd);
|
||||
int pn53x_initiator_target_is_present (struct nfc_device *pnd, const nfc_target nt);
|
||||
|
||||
// NFC device as Target functions
|
||||
int pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t szRxLen, int timeout);
|
||||
|
|
|
@ -502,6 +502,7 @@ const struct nfc_driver acr122_pcsc_driver = {
|
|||
.initiator_transceive_bits = pn53x_initiator_transceive_bits,
|
||||
.initiator_transceive_bytes_timed = pn53x_initiator_transceive_bytes_timed,
|
||||
.initiator_transceive_bits_timed = pn53x_initiator_transceive_bits_timed,
|
||||
.initiator_target_is_present = pn53x_initiator_target_is_present,
|
||||
|
||||
.target_init = pn53x_target_init,
|
||||
.target_send_bytes = pn53x_target_send_bytes,
|
||||
|
|
|
@ -759,6 +759,7 @@ const struct nfc_driver acr122_usb_driver = {
|
|||
.initiator_transceive_bits = pn53x_initiator_transceive_bits,
|
||||
.initiator_transceive_bytes_timed = pn53x_initiator_transceive_bytes_timed,
|
||||
.initiator_transceive_bits_timed = pn53x_initiator_transceive_bits_timed,
|
||||
.initiator_target_is_present = pn53x_initiator_target_is_present,
|
||||
|
||||
.target_init = pn53x_target_init,
|
||||
.target_send_bytes = pn53x_target_send_bytes,
|
||||
|
|
|
@ -737,6 +737,7 @@ const struct nfc_driver acr122s_driver = {
|
|||
.initiator_transceive_bits = pn53x_initiator_transceive_bits,
|
||||
.initiator_transceive_bytes_timed = pn53x_initiator_transceive_bytes_timed,
|
||||
.initiator_transceive_bits_timed = pn53x_initiator_transceive_bits_timed,
|
||||
.initiator_target_is_present = pn53x_initiator_target_is_present,
|
||||
|
||||
.target_init = pn53x_target_init,
|
||||
.target_send_bytes = pn53x_target_send_bytes,
|
||||
|
|
|
@ -579,6 +579,7 @@ const struct nfc_driver arygon_driver = {
|
|||
.initiator_transceive_bits = pn53x_initiator_transceive_bits,
|
||||
.initiator_transceive_bytes_timed = pn53x_initiator_transceive_bytes_timed,
|
||||
.initiator_transceive_bits_timed = pn53x_initiator_transceive_bits_timed,
|
||||
.initiator_target_is_present = pn53x_initiator_target_is_present,
|
||||
|
||||
.target_init = pn53x_target_init,
|
||||
.target_send_bytes = pn53x_target_send_bytes,
|
||||
|
|
|
@ -521,6 +521,7 @@ const struct nfc_driver pn532_uart_driver = {
|
|||
.initiator_transceive_bits = pn53x_initiator_transceive_bits,
|
||||
.initiator_transceive_bytes_timed = pn53x_initiator_transceive_bytes_timed,
|
||||
.initiator_transceive_bits_timed = pn53x_initiator_transceive_bits_timed,
|
||||
.initiator_target_is_present = pn53x_initiator_target_is_present,
|
||||
|
||||
.target_init = pn53x_target_init,
|
||||
.target_send_bytes = pn53x_target_send_bytes,
|
||||
|
|
|
@ -772,6 +772,7 @@ const struct nfc_driver pn53x_usb_driver = {
|
|||
.initiator_transceive_bits = pn53x_initiator_transceive_bits,
|
||||
.initiator_transceive_bytes_timed = pn53x_initiator_transceive_bytes_timed,
|
||||
.initiator_transceive_bits_timed = pn53x_initiator_transceive_bits_timed,
|
||||
.initiator_target_is_present = pn53x_initiator_target_is_present,
|
||||
|
||||
.target_init = pn53x_target_init,
|
||||
.target_send_bytes = pn53x_target_send_bytes,
|
||||
|
|
|
@ -149,6 +149,7 @@ struct nfc_driver {
|
|||
int (*initiator_transceive_bits) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar, uint8_t * pbtRx, uint8_t * pbtRxPar);
|
||||
int (*initiator_transceive_bytes_timed) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, uint32_t * cycles);
|
||||
int (*initiator_transceive_bits_timed) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar, uint8_t * pbtRx, uint8_t * pbtRxPar, uint32_t * cycles);
|
||||
int (*initiator_target_is_present) (struct nfc_device *pnd, const nfc_target nt);
|
||||
|
||||
int (*target_init) (struct nfc_device *pnd, nfc_target * pnt, uint8_t * pbtRx, const size_t szRx, int timeout);
|
||||
int (*target_send_bytes) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTx, int timeout);
|
||||
|
|
16
libnfc/nfc.c
16
libnfc/nfc.c
|
@ -687,7 +687,21 @@ nfc_initiator_transceive_bits (nfc_device *pnd, const uint8_t *pbtTx, const size
|
|||
int
|
||||
nfc_initiator_transceive_bytes_timed (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, uint32_t *cycles)
|
||||
{
|
||||
HAL (initiator_transceive_bytes_timed, pnd, pbtTx, szTx, pbtRx, cycles)
|
||||
HAL (initiator_transceive_bytes_timed, pnd, pbtTx, szTx, pbtRx, cycles);
|
||||
}
|
||||
|
||||
/** @ingroup initiator
|
||||
* @brief Check target presence
|
||||
* @return Returns 0 on success, otherwise returns libnfc's error code.
|
||||
*
|
||||
* This function tests if \a nfc_target is currently present on NFC device.
|
||||
* @warning The target have to be selected before check its presence
|
||||
* @warning To run the test, one or more commands will be sent to target
|
||||
*/
|
||||
int
|
||||
nfc_initiator_target_is_present (nfc_device *pnd, const nfc_target nt)
|
||||
{
|
||||
HAL (initiator_target_is_present, pnd, nt);
|
||||
}
|
||||
|
||||
/** @ingroup initiator
|
||||
|
|
Loading…
Reference in a new issue