nfc_target_send_bits() function returns now sent bits count on success and libnfc error code on failure.

This commit is contained in:
Audrey Diacre 2012-01-04 13:27:15 +00:00
parent 1c49329ffa
commit 951dde8143
7 changed files with 15 additions and 14 deletions

View file

@ -205,7 +205,7 @@ main (int argc, char *argv[])
// Test if we know how to respond // Test if we know how to respond
if (szTxBits) { if (szTxBits) {
// Send and print the command to the screen // 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"); nfc_perror (pnd, "nfc_target_send_bits");
goto error; goto error;
} }

View file

@ -199,7 +199,7 @@ main (int argc, char *argv[])
if (nfc_initiator_transceive_bits if (nfc_initiator_transceive_bits
(pndReader, abtReaderRx, szReaderRxBits, abtReaderRxPar, abtTagRx, &szTagRxBits, abtTagRxPar) > 0) { (pndReader, abtReaderRx, szReaderRxBits, abtReaderRxPar, abtTagRx, &szTagRxBits, abtTagRxPar) > 0) {
// Redirect the answer back to the reader // 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"); nfc_perror (pndTag, "nfc_target_send_bits");
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }

View file

@ -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_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_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 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); NFC_EXPORT bool nfc_target_receive_bits (nfc_device *pnd, uint8_t *pbtRx, size_t *pszRxBits, uint8_t *pbtRxPar);
/* Error reporting */ /* Error reporting */

View file

@ -1831,13 +1831,14 @@ pn53x_target_receive_bytes (struct nfc_device *pnd, uint8_t *pbtRx, size_t *pszR
return *pszRx; return *pszRx;
} }
bool int
pn53x_target_send_bits (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar) 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 szFrameBits = 0;
size_t szFrameBytes = 0; size_t szFrameBytes = 0;
uint8_t ui8Bits = 0; uint8_t ui8Bits = 0;
uint8_t abtCmd[PN53x_EXTENDED_FRAME__DATA_MAX_LEN] = { TgResponseToInitiator }; uint8_t abtCmd[PN53x_EXTENDED_FRAME__DATA_MAX_LEN] = { TgResponseToInitiator };
int res = 0;
// Check if we should prepare the parity bits ourself // Check if we should prepare the parity bits ourself
if (!pnd->bPar) { 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); memcpy (abtCmd + 1, pbtTx, szFrameBytes);
// Set the amount of transmission bits in the PN53X chip register // Set the amount of transmission bits in the PN53X chip register
if (pn53x_set_tx_bits (pnd, ui8Bits) < 0) if ((res = pn53x_set_tx_bits (pnd, ui8Bits)) < 0)
return false; return res;
// Try to send the bits to the reader // Try to send the bits to the reader
if (pn53x_transceive (pnd, abtCmd, szFrameBytes + 1, NULL, NULL, -1) < 0) if ((res = pn53x_transceive (pnd, abtCmd, szFrameBytes + 1, NULL, NULL, -1)) < 0)
return false; return res;
// Everyting seems ok, return true // Everyting seems ok, return return sent bits count
return true; return szTxBits;
} }
int int

View file

@ -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); 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); 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); 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); int pn53x_target_send_bytes (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, int timeout);
// Error handling functions // Error handling functions

View file

@ -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_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);
int (*target_receive_bytes) (struct nfc_device *pnd, uint8_t * pbtRx, size_t * pszRx, 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); 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); int (*device_set_property_bool) (struct nfc_device *pnd, const nfc_property property, const bool bEnable);

View file

@ -736,12 +736,12 @@ nfc_target_receive_bytes (nfc_device *pnd, uint8_t *pbtRx, size_t *pszRx, int ti
/** /**
* @brief Send raw bit-frames * @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 * This function can be used to transmit (raw) bit-frames to the \e initiator
* using the specified NFC device (configured as \e target). * 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) 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); HAL (target_send_bits, pnd, pbtTx, szTxBits, pbtTxPar);