nfc_target_receive_*() need to know rx buffer size

This commit is contained in:
Romuald Conty 2012-01-05 21:35:02 +00:00
parent 601105ef79
commit 22bea8d99b
11 changed files with 31 additions and 23 deletions

View file

@ -1811,7 +1811,7 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size
}
int
pn53x_target_receive_bits (struct nfc_device *pnd, uint8_t *pbtRx, uint8_t *pbtRxPar)
pn53x_target_receive_bits (struct nfc_device *pnd, uint8_t *pbtRx, const size_t szRxLen, uint8_t *pbtRxPar)
{
size_t szRxBits = 0;
uint8_t abtCmd[] = { TgGetInitiatorCommand };
@ -1851,7 +1851,7 @@ pn53x_target_receive_bits (struct nfc_device *pnd, uint8_t *pbtRx, uint8_t *pbtR
}
int
pn53x_target_receive_bytes (struct nfc_device *pnd, uint8_t *pbtRx, int timeout)
pn53x_target_receive_bytes (struct nfc_device *pnd, uint8_t *pbtRx, const size_t szRxLen, int timeout)
{
uint8_t abtCmd[1];
@ -1884,14 +1884,17 @@ pn53x_target_receive_bytes (struct nfc_device *pnd, uint8_t *pbtRx, int timeout)
}
// Try to gather a received frame from the reader
uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
size_t szRx = sizeof (abtRx);
uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
size_t szRx = sizeof (abtRx);
if (pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRx, &szRx, timeout) < 0)
return pnd->last_error;
// Save the received bytes count
szRx -= 1;
if (szRx > szRxLen)
return NFC_EOVFLOW;
// Copy the received bytes
memcpy (pbtRx, abtRx + 1, szRx);

View file

@ -309,8 +309,8 @@ int pn53x_initiator_deselect_target (struct nfc_device *pnd);
// NFC device as Target functions
int pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size_t *pszRx, int timeout);
int pn53x_target_receive_bits (struct nfc_device *pnd, uint8_t *pbtRx, uint8_t *pbtRxPar);
int pn53x_target_receive_bytes (struct nfc_device *pnd, uint8_t *pbtRx, int timeout);
int pn53x_target_receive_bits (struct nfc_device *pnd, uint8_t *pbtRx, const size_t szRxLen, uint8_t *pbtRxPar);
int pn53x_target_receive_bytes (struct nfc_device *pnd, uint8_t *pbtRx, const size_t szRxLen, int timeout);
int pn53x_target_send_bits (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar);
int pn53x_target_send_bytes (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, int timeout);