nfc_target_send_bits() function returns now sent bits count on success and libnfc error code on failure.
This commit is contained in:
parent
1c49329ffa
commit
951dde8143
7 changed files with 15 additions and 14 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue