nfc_initiator_transceive_bytes_timed() function returns now received bytes count on success and libnfc error code on failure.

This commit is contained in:
Audrey Diacre 2012-01-04 11:54:55 +00:00
parent 61074f3497
commit d02da0db64
5 changed files with 14 additions and 13 deletions

View file

@ -79,7 +79,7 @@ extern "C" {
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, size_t *pszRxBits, uint8_t *pbtRxPar);
NFC_EXPORT bool 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 target: act as tag (i.e. MIFARE Classic) or NFC target device. */

View file

@ -1412,23 +1412,24 @@ pn53x_initiator_transceive_bits_timed (struct nfc_device *pnd, const uint8_t *pb
return true;
}
bool
int
pn53x_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)
{
uint16_t i;
uint8_t sz;
int res = 0;
// We can not just send bytes without parity while the PN53X expects we handled them
if (!pnd->bPar) {
pnd->last_error = NFC_EINVARG;
return false;
return pnd->last_error;
}
// Sorry, no easy framing support
// TODO to be changed once we'll provide easy framing support from libnfc itself...
if (pnd->bEasyFraming) {
pnd->last_error = NFC_ENOTIMPL;
return false;
return pnd->last_error;
}
__pn53x_init_timer(pnd, *cycles);
@ -1456,8 +1457,8 @@ pn53x_initiator_transceive_bytes_timed (struct nfc_device *pnd, const uint8_t *p
BUFFER_APPEND (abtWriteRegisterCmd, PN53X_REG_CIU_BitFraming & 0xff);
BUFFER_APPEND (abtWriteRegisterCmd, SYMBOL_START_SEND);
// Let's send the previously constructed WriteRegister command
if (pn53x_transceive (pnd, abtWriteRegisterCmd, BUFFER_SIZE (abtWriteRegisterCmd), NULL, NULL, -1) < 0) {
return false;
if ((res = pn53x_transceive (pnd, abtWriteRegisterCmd, BUFFER_SIZE (abtWriteRegisterCmd), NULL, NULL, -1)) < 0) {
return res;
}
// Recv data
@ -1488,8 +1489,8 @@ pn53x_initiator_transceive_bytes_timed (struct nfc_device *pnd, const uint8_t *p
uint8_t abtRes[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
size_t szRes = sizeof(abtRes);
// Let's send the previously constructed ReadRegister command
if (pn53x_transceive (pnd, abtReadRegisterCmd, BUFFER_SIZE (abtReadRegisterCmd), abtRes, &szRes, -1) < 0) {
return false;
if ((res = pn53x_transceive (pnd, abtReadRegisterCmd, BUFFER_SIZE (abtReadRegisterCmd), abtRes, &szRes, -1)) < 0) {
return res;
}
for (i = 0; i < sz; i++) {
pbtRx[i+*pszRx] = abtRes[i+off];
@ -1512,7 +1513,7 @@ pn53x_initiator_transceive_bytes_timed (struct nfc_device *pnd, const uint8_t *p
} else {
*cycles = __pn53x_get_timer (pnd, pbtTx[szTx -1]);
}
return true;
return *pszRx;
}
int

View file

@ -307,7 +307,7 @@ int pn53x_initiator_transceive_bytes (struct nfc_device *pnd, const uint8_t
bool 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);
bool 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,
uint8_t *pbtRx, size_t *pszRx, uint32_t *cycles);
int pn53x_initiator_deselect_target (struct nfc_device *pnd);

View file

@ -139,7 +139,7 @@ struct nfc_driver_t {
int (*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_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);
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 (*target_init) (struct nfc_device *pnd, nfc_target * pnt, uint8_t * pbtRx, size_t * pszRx);

View file

@ -546,7 +546,7 @@ nfc_initiator_transceive_bits (nfc_device *pnd, const uint8_t *pbtTx, const size
/**
* @brief Send data to target then retrieve data from target
* @return Returns \c true if action was successfully performed; otherwise returns \c false.
* @return Returns received bytes count on success, otherwise returns libnfc's error code.
*
* This function is similar to nfc_initiator_transceive_bytes() with the following differences:
* - A precise cycles counter will indicate the number of cycles between emission & reception of frames.
@ -564,7 +564,7 @@ nfc_initiator_transceive_bits (nfc_device *pnd, const uint8_t *pbtTx, const size
* @warning The configuration option \a NP_EASY_FRAMING must be set to \c false.
* @warning The configuration option \a NP_HANDLE_PARITY must be set to \c true (the default value).
*/
bool
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)
{