nfc_initiator_transceive_bits_timed() function returns now received bits count on success and libnfc error code on failure.
This commit is contained in:
parent
d02da0db64
commit
1c49329ffa
5 changed files with 15 additions and 14 deletions
|
@ -80,7 +80,7 @@ extern "C" {
|
||||||
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);
|
||||||
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, size_t *pszRxBits, uint8_t *pbtRxPar);
|
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, size_t *pszRxBits, 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, size_t *pszRx, uint32_t *cycles);
|
NFC_EXPORT int nfc_initiator_transceive_bytes_timed (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, size_t *pszRx, uint32_t *cycles);
|
||||||
NFC_EXPORT bool nfc_initiator_transceive_bits_timed (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);
|
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, size_t *pszRxBits, uint8_t *pbtRxPar, uint32_t *cycles);
|
||||||
|
|
||||||
/* NFC target: act as tag (i.e. MIFARE Classic) or NFC target device. */
|
/* 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, size_t *pszRx);
|
NFC_EXPORT int nfc_target_init (nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size_t *pszRx);
|
||||||
|
|
|
@ -1310,7 +1310,7 @@ uint32_t __pn53x_get_timer(struct nfc_device *pnd, const uint8_t last_cmd_byte)
|
||||||
return u32cycles;
|
return u32cycles;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
int
|
||||||
pn53x_initiator_transceive_bits_timed (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits,
|
pn53x_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)
|
const uint8_t *pbtTxPar, uint8_t *pbtRx, size_t *pszRxBits, uint8_t *pbtRxPar, uint32_t *cycles)
|
||||||
{
|
{
|
||||||
|
@ -1319,21 +1319,22 @@ pn53x_initiator_transceive_bits_timed (struct nfc_device *pnd, const uint8_t *pb
|
||||||
(void) pbtRxPar;
|
(void) pbtRxPar;
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
uint8_t sz;
|
uint8_t sz;
|
||||||
|
int res = 0;
|
||||||
|
|
||||||
// Sorry, no arbitrary parity bits support for now
|
// Sorry, no arbitrary parity bits support for now
|
||||||
if (!pnd->bPar) {
|
if (!pnd->bPar) {
|
||||||
pnd->last_error = NFC_ENOTIMPL;
|
pnd->last_error = NFC_ENOTIMPL;
|
||||||
return false;
|
return pnd->last_error;
|
||||||
}
|
}
|
||||||
// Sorry, no easy framing support
|
// Sorry, no easy framing support
|
||||||
if (pnd->bEasyFraming) {
|
if (pnd->bEasyFraming) {
|
||||||
pnd->last_error = NFC_ENOTIMPL;
|
pnd->last_error = NFC_ENOTIMPL;
|
||||||
return false;
|
return pnd->last_error;
|
||||||
}
|
}
|
||||||
// TODO CRC support but it probably doesn't make sense for (szTxBits % 8 != 0) ...
|
// TODO CRC support but it probably doesn't make sense for (szTxBits % 8 != 0) ...
|
||||||
if (pnd->bCrc) {
|
if (pnd->bCrc) {
|
||||||
pnd->last_error = NFC_ENOTIMPL;
|
pnd->last_error = NFC_ENOTIMPL;
|
||||||
return false;
|
return pnd->last_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
__pn53x_init_timer(pnd, *cycles);
|
__pn53x_init_timer(pnd, *cycles);
|
||||||
|
@ -1361,8 +1362,8 @@ pn53x_initiator_transceive_bits_timed (struct nfc_device *pnd, const uint8_t *pb
|
||||||
BUFFER_APPEND (abtWriteRegisterCmd, PN53X_REG_CIU_BitFraming & 0xff);
|
BUFFER_APPEND (abtWriteRegisterCmd, PN53X_REG_CIU_BitFraming & 0xff);
|
||||||
BUFFER_APPEND (abtWriteRegisterCmd, SYMBOL_START_SEND | ((szTxBits % 8) & SYMBOL_TX_LAST_BITS));
|
BUFFER_APPEND (abtWriteRegisterCmd, SYMBOL_START_SEND | ((szTxBits % 8) & SYMBOL_TX_LAST_BITS));
|
||||||
// Let's send the previously constructed WriteRegister command
|
// Let's send the previously constructed WriteRegister command
|
||||||
if (pn53x_transceive (pnd, abtWriteRegisterCmd, BUFFER_SIZE (abtWriteRegisterCmd), NULL, NULL, -1) < 0) {
|
if ((res = pn53x_transceive (pnd, abtWriteRegisterCmd, BUFFER_SIZE (abtWriteRegisterCmd), NULL, NULL, -1)) < 0) {
|
||||||
return false;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recv data
|
// Recv data
|
||||||
|
@ -1393,8 +1394,8 @@ pn53x_initiator_transceive_bits_timed (struct nfc_device *pnd, const uint8_t *pb
|
||||||
uint8_t abtRes[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
uint8_t abtRes[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
||||||
size_t szRes = sizeof(abtRes);
|
size_t szRes = sizeof(abtRes);
|
||||||
// Let's send the previously constructed ReadRegister command
|
// Let's send the previously constructed ReadRegister command
|
||||||
if (pn53x_transceive (pnd, abtReadRegisterCmd, BUFFER_SIZE (abtReadRegisterCmd), abtRes, &szRes, -1) < 0) {
|
if ((res = pn53x_transceive (pnd, abtReadRegisterCmd, BUFFER_SIZE (abtReadRegisterCmd), abtRes, &szRes, -1)) < 0) {
|
||||||
return false;
|
return res;
|
||||||
}
|
}
|
||||||
for (i = 0; i < sz; i++) {
|
for (i = 0; i < sz; i++) {
|
||||||
pbtRx[i+*pszRxBits] = abtRes[i+off];
|
pbtRx[i+*pszRxBits] = abtRes[i+off];
|
||||||
|
@ -1409,7 +1410,7 @@ pn53x_initiator_transceive_bits_timed (struct nfc_device *pnd, const uint8_t *pb
|
||||||
// Recv corrected timer value
|
// Recv corrected timer value
|
||||||
*cycles = __pn53x_get_timer (pnd, pbtTx[szTxBits / 8]);
|
*cycles = __pn53x_get_timer (pnd, pbtTx[szTxBits / 8]);
|
||||||
|
|
||||||
return true;
|
return *pszRxBits;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -304,7 +304,7 @@ int pn53x_initiator_transceive_bits (struct nfc_device *pnd, const uint8_t *p
|
||||||
uint8_t *pbtRxPar);
|
uint8_t *pbtRxPar);
|
||||||
int pn53x_initiator_transceive_bytes (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx,
|
int pn53x_initiator_transceive_bytes (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx,
|
||||||
uint8_t *pbtRx, size_t *pszRx, int timeout);
|
uint8_t *pbtRx, size_t *pszRx, int timeout);
|
||||||
bool pn53x_initiator_transceive_bits_timed (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits,
|
int pn53x_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,
|
const uint8_t *pbtTxPar, uint8_t *pbtRx, size_t *pszRxBits,
|
||||||
uint8_t *pbtRxPar, uint32_t *cycles);
|
uint8_t *pbtRxPar, uint32_t *cycles);
|
||||||
int pn53x_initiator_transceive_bytes_timed (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx,
|
int pn53x_initiator_transceive_bytes_timed (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx,
|
||||||
|
|
|
@ -140,7 +140,7 @@ struct nfc_driver_t {
|
||||||
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);
|
||||||
int (*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);
|
int (*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);
|
||||||
int (*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);
|
int (*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);
|
int (*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);
|
||||||
|
|
||||||
int (*target_init) (struct nfc_device *pnd, nfc_target * pnt, uint8_t * pbtRx, size_t * pszRx);
|
int (*target_init) (struct nfc_device *pnd, nfc_target * pnt, uint8_t * pbtRx, size_t * pszRx);
|
||||||
int (*target_send_bytes) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTx, int timeout);
|
int (*target_send_bytes) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTx, int timeout);
|
||||||
|
|
|
@ -573,7 +573,7 @@ nfc_initiator_transceive_bytes_timed (nfc_device *pnd, const uint8_t *pbtTx, con
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Transceive raw bit-frames to a target
|
* @brief Transceive raw bit-frames to a target
|
||||||
* @return Returns \c true if action was successfully performed; otherwise returns \c false.
|
* @return Returns received bits count on success, otherwise returns libnfc's error code
|
||||||
*
|
*
|
||||||
* This function is similar to nfc_initiator_transceive_bits() with the following differences:
|
* This function is similar to nfc_initiator_transceive_bits() with the following differences:
|
||||||
* - A precise cycles counter will indicate the number of cycles between emission & reception of frames.
|
* - A precise cycles counter will indicate the number of cycles between emission & reception of frames.
|
||||||
|
@ -592,7 +592,7 @@ nfc_initiator_transceive_bytes_timed (nfc_device *pnd, const uint8_t *pbtTx, con
|
||||||
* @warning The configuration option \a NP_HANDLE_CRC must be set to \c false.
|
* @warning The configuration option \a NP_HANDLE_CRC must be set to \c false.
|
||||||
* @warning The configuration option \a NP_HANDLE_PARITY must be set to \c true (the default value).
|
* @warning The configuration option \a NP_HANDLE_PARITY must be set to \c true (the default value).
|
||||||
*/
|
*/
|
||||||
bool
|
int
|
||||||
nfc_initiator_transceive_bits_timed (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar,
|
nfc_initiator_transceive_bits_timed (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)
|
uint8_t *pbtRx, size_t *pszRxBits, uint8_t *pbtRxPar, uint32_t *cycles)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue