nfc_target_send_bytes() function returns now sent bytes count on success and libnfc error code on failure.
This commit is contained in:
parent
ac6f652368
commit
9c1371dcca
11 changed files with 51 additions and 50 deletions
|
|
@ -1866,14 +1866,15 @@ pn53x_target_send_bits (struct nfc_device *pnd, const uint8_t *pbtTx, const size
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
int
|
||||
pn53x_target_send_bytes (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, int timeout)
|
||||
{
|
||||
uint8_t abtCmd[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
||||
int res = 0;
|
||||
|
||||
// We can not just send bytes without parity if while the PN53X expects we handled them
|
||||
if (!pnd->bPar)
|
||||
return false;
|
||||
return NFC_ECHIP;
|
||||
|
||||
// XXX I think this is not a clean way to provide some kind of "EasyFraming"
|
||||
// but at the moment I have no more better than this
|
||||
|
|
@ -1892,7 +1893,7 @@ pn53x_target_send_bytes (struct nfc_device *pnd, const uint8_t *pbtTx, const siz
|
|||
} else {
|
||||
// TODO Support EasyFraming for other cases by software
|
||||
pnd->last_error = NFC_ENOTIMPL;
|
||||
return false;
|
||||
return pnd->last_error;
|
||||
}
|
||||
}
|
||||
default:
|
||||
|
|
@ -1905,13 +1906,13 @@ pn53x_target_send_bytes (struct nfc_device *pnd, const uint8_t *pbtTx, const siz
|
|||
|
||||
// Copy the data into the command frame
|
||||
memcpy (abtCmd + 1, pbtTx, szTx);
|
||||
|
||||
|
||||
// Try to send the bits to the reader
|
||||
if (pn53x_transceive (pnd, abtCmd, szTx + 1, NULL, NULL, timeout) < 0)
|
||||
return false;
|
||||
if ((res = pn53x_transceive (pnd, abtCmd, szTx + 1, NULL, NULL, timeout)) < 0)
|
||||
return res;
|
||||
|
||||
// Everyting seems ok, return true
|
||||
return true;
|
||||
// Everyting seems ok, return sent byte count
|
||||
return szTx;
|
||||
}
|
||||
|
||||
static struct sErrorMessage {
|
||||
|
|
|
|||
|
|
@ -316,7 +316,7 @@ int pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtR
|
|||
bool pn53x_target_receive_bits (struct nfc_device *pnd, uint8_t *pbtRx, size_t *pszRxBits, uint8_t *pbtRxPar);
|
||||
int pn53x_target_receive_bytes (struct nfc_device *pnd, uint8_t *pbtRx, size_t *pszRx, int timeout);
|
||||
bool pn53x_target_send_bits (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar);
|
||||
bool pn53x_target_send_bytes (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, int timeout);
|
||||
int pn53x_target_send_bytes (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, int timeout);
|
||||
|
||||
// Error handling functions
|
||||
const char *pn53x_strerror (const struct nfc_device *pnd);
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ nfc_emulate_target (nfc_device *pnd, struct nfc_emulator *emulator)
|
|||
while (res >= 0) {
|
||||
res = emulator->state_machine->io (emulator, abtRx, szRx, abtTx, sizeof (abtTx));
|
||||
if (res > 0) {
|
||||
if (!nfc_target_send_bytes(pnd, abtTx, res, 0)) {
|
||||
if (nfc_target_send_bytes(pnd, abtTx, res, 0) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ struct nfc_driver_t {
|
|||
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);
|
||||
bool (*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);
|
||||
int (*target_receive_bytes) (struct nfc_device *pnd, uint8_t * pbtRx, size_t * pszRx, int timeout);
|
||||
bool (*target_send_bits) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar);
|
||||
bool (*target_receive_bits) (struct nfc_device *pnd, uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar);
|
||||
|
|
|
|||
|
|
@ -695,7 +695,7 @@ nfc_abort_command (nfc_device *pnd)
|
|||
|
||||
/**
|
||||
* @brief Send bytes and APDU frames
|
||||
* @return Returns \c true if action was successfully performed; otherwise returns \c false.
|
||||
* @return Returns sent bytes count on success, otherwise returns libnfc's error code
|
||||
*
|
||||
* @param pnd \a nfc_device struct pointer that represent currently used device
|
||||
* @param pbtTx pointer to Tx buffer
|
||||
|
|
@ -708,7 +708,7 @@ nfc_abort_command (nfc_device *pnd)
|
|||
* If timeout is not a null pointer, it specifies the maximum interval to wait for the function to be executed.
|
||||
* If timeout is a null pointer, the function blocks indefinitely (until an error is raised or function is completed).
|
||||
*/
|
||||
bool
|
||||
int
|
||||
nfc_target_send_bytes (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, int timeout)
|
||||
{
|
||||
HAL (target_send_bytes, pnd, pbtTx, szTx, timeout);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue