diff --git a/examples/nfc-emulate-uid.c b/examples/nfc-emulate-uid.c index 0835034..80339bf 100644 --- a/examples/nfc-emulate-uid.c +++ b/examples/nfc-emulate-uid.c @@ -205,7 +205,7 @@ main (int argc, char *argv[]) // Test if we know how to respond if (szTxBits) { // Send and print the command to the screen - if (!nfc_target_send_bits (pnd, pbtTx, szTxBits, NULL)) { + if (nfc_target_send_bits (pnd, pbtTx, szTxBits, NULL) < 0) { nfc_perror (pnd, "nfc_target_send_bits"); goto error; } diff --git a/examples/nfc-relay.c b/examples/nfc-relay.c index 7f4597a..fc7230d 100644 --- a/examples/nfc-relay.c +++ b/examples/nfc-relay.c @@ -199,7 +199,7 @@ main (int argc, char *argv[]) if (nfc_initiator_transceive_bits (pndReader, abtReaderRx, szReaderRxBits, abtReaderRxPar, abtTagRx, &szTagRxBits, abtTagRxPar) > 0) { // Redirect the answer back to the reader - if (!nfc_target_send_bits (pndTag, abtTagRx, szTagRxBits, abtTagRxPar)) { + if (nfc_target_send_bits (pndTag, abtTagRx, szTagRxBits, abtTagRxPar) < 0) { nfc_perror (pndTag, "nfc_target_send_bits"); exit (EXIT_FAILURE); } diff --git a/include/nfc/nfc.h b/include/nfc/nfc.h index b471a38..29b3199 100644 --- a/include/nfc/nfc.h +++ b/include/nfc/nfc.h @@ -86,7 +86,7 @@ extern "C" { NFC_EXPORT int nfc_target_init (nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size_t *pszRx); NFC_EXPORT int nfc_target_send_bytes (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, int timeout); NFC_EXPORT int nfc_target_receive_bytes (nfc_device *pnd, uint8_t *pbtRx, size_t *pszRx, int timeout); - NFC_EXPORT bool nfc_target_send_bits (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar); + NFC_EXPORT int nfc_target_send_bits (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar); NFC_EXPORT bool nfc_target_receive_bits (nfc_device *pnd, uint8_t *pbtRx, size_t *pszRxBits, uint8_t *pbtRxPar); /* Error reporting */ diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index e232824..9267b03 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -1831,13 +1831,14 @@ pn53x_target_receive_bytes (struct nfc_device *pnd, uint8_t *pbtRx, size_t *pszR return *pszRx; } -bool +int pn53x_target_send_bits (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar) { size_t szFrameBits = 0; size_t szFrameBytes = 0; uint8_t ui8Bits = 0; uint8_t abtCmd[PN53x_EXTENDED_FRAME__DATA_MAX_LEN] = { TgResponseToInitiator }; + int res = 0; // Check if we should prepare the parity bits ourself if (!pnd->bPar) { @@ -1858,15 +1859,15 @@ pn53x_target_send_bits (struct nfc_device *pnd, const uint8_t *pbtTx, const size memcpy (abtCmd + 1, pbtTx, szFrameBytes); // Set the amount of transmission bits in the PN53X chip register - if (pn53x_set_tx_bits (pnd, ui8Bits) < 0) - return false; + if ((res = pn53x_set_tx_bits (pnd, ui8Bits)) < 0) + return res; // Try to send the bits to the reader - if (pn53x_transceive (pnd, abtCmd, szFrameBytes + 1, NULL, NULL, -1) < 0) - return false; + if ((res = pn53x_transceive (pnd, abtCmd, szFrameBytes + 1, NULL, NULL, -1)) < 0) + return res; - // Everyting seems ok, return true - return true; + // Everyting seems ok, return return sent bits count + return szTxBits; } int diff --git a/libnfc/chips/pn53x.h b/libnfc/chips/pn53x.h index be02599..42eeb9c 100644 --- a/libnfc/chips/pn53x.h +++ b/libnfc/chips/pn53x.h @@ -315,7 +315,7 @@ int pn53x_initiator_deselect_target (struct nfc_device *pnd); int pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size_t *pszRx); 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); +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); // Error handling functions diff --git a/libnfc/nfc-internal.h b/libnfc/nfc-internal.h index 0afbf2a..51ac12c 100644 --- a/libnfc/nfc-internal.h +++ b/libnfc/nfc-internal.h @@ -145,7 +145,7 @@ struct nfc_driver_t { 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_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); + int (*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); int (*device_set_property_bool) (struct nfc_device *pnd, const nfc_property property, const bool bEnable); diff --git a/libnfc/nfc.c b/libnfc/nfc.c index ee22f7a..439d795 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -736,12 +736,12 @@ nfc_target_receive_bytes (nfc_device *pnd, uint8_t *pbtRx, size_t *pszRx, int ti /** * @brief Send raw bit-frames - * @return Returns \c true if action was successfully performed; otherwise returns \c false. + * @return Returns sent bits count on success, otherwise returns libnfc's error code. * * This function can be used to transmit (raw) bit-frames to the \e initiator * using the specified NFC device (configured as \e target). */ -bool +int nfc_target_send_bits (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar) { HAL (target_send_bits, pnd, pbtTx, szTxBits, pbtTxPar);