diff --git a/examples/nfc-anticol.c b/examples/nfc-anticol.c index b5d82b2..6bcc4ed 100644 --- a/examples/nfc-anticol.c +++ b/examples/nfc-anticol.c @@ -105,7 +105,7 @@ transmit_bytes (const uint8_t *pbtTx, const size_t szTx) print_hex (pbtTx, szTx); } // Transmit the command bytes - if (!nfc_initiator_transceive_bytes (pnd, pbtTx, szTx, abtRx, &szRx, 0)) + if (nfc_initiator_transceive_bytes (pnd, pbtTx, szTx, abtRx, &szRx, 0) < 0) return false; // Show received answer diff --git a/examples/nfc-dep-initiator.c b/examples/nfc-dep-initiator.c index 85d836f..fd3d212 100644 --- a/examples/nfc-dep-initiator.c +++ b/examples/nfc-dep-initiator.c @@ -93,7 +93,7 @@ main (int argc, const char *argv[]) print_nfc_target (nt, false); printf ("Sending: %s\n", abtTx); - if (!nfc_initiator_transceive_bytes (pnd, abtTx, sizeof(abtTx), abtRx, &szRx, 0)) { + if (nfc_initiator_transceive_bytes (pnd, abtTx, sizeof(abtTx), abtRx, &szRx, 0) < 0) { nfc_perror(pnd, "nfc_initiator_transceive_bytes"); goto error; } diff --git a/include/nfc/nfc.h b/include/nfc/nfc.h index 4bca672..1fb5ca9 100644 --- a/include/nfc/nfc.h +++ b/include/nfc/nfc.h @@ -77,7 +77,7 @@ extern "C" { NFC_EXPORT bool nfc_initiator_poll_target (nfc_device *pnd, const nfc_modulation *pnmTargetTypes, const size_t szTargetTypes, const uint8_t uiPollNr, const uint8_t uiPeriod, nfc_target *pnt); NFC_EXPORT bool nfc_initiator_select_dep_target (nfc_device *pnd, const nfc_dep_mode ndm, const nfc_baud_rate nbr, const nfc_dep_info *pndiInitiator, nfc_target *pnt, const int timeout); NFC_EXPORT bool nfc_initiator_deselect_target (nfc_device *pnd); - NFC_EXPORT bool nfc_initiator_transceive_bytes (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, size_t *pszRx, int timeout); + NFC_EXPORT int nfc_initiator_transceive_bytes (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, size_t *pszRx, int timeout); NFC_EXPORT bool nfc_initiator_transceive_bits (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, size_t *pszRxBits, uint8_t *pbtRxPar); NFC_EXPORT bool nfc_initiator_transceive_bytes_timed (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, size_t *pszRx, uint32_t *cycles); NFC_EXPORT bool nfc_initiator_transceive_bits_timed (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); diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index 696f9b1..34933b0 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -943,11 +943,11 @@ pn53x_initiator_select_passive_target_ext (struct nfc_device *pnd, uint8_t abtRx[1]; size_t szRxLen = 1; // Getting random Chip_ID - if (!pn53x_initiator_transceive_bytes (pnd, abtInitiate, szInitiateLen, abtRx, &szRxLen, timeout)) { + if (pn53x_initiator_transceive_bytes (pnd, abtInitiate, szInitiateLen, abtRx, &szRxLen, timeout) < 0) { return false; } abtSelect[1] = abtRx[0]; - if (!pn53x_initiator_transceive_bytes (pnd, abtSelect, szSelectLen, abtRx, &szRxLen, timeout)) { + if (pn53x_initiator_transceive_bytes (pnd, abtSelect, szSelectLen, abtRx, &szRxLen, timeout) < 0) { return false; } } @@ -956,11 +956,11 @@ pn53x_initiator_select_passive_target_ext (struct nfc_device *pnd, uint8_t abtReqt[]="\x10"; size_t szReqtLen = 1; // Getting product code / fab code & store it in output buffer after the serial nr we'll obtain later - if (!pn53x_initiator_transceive_bytes (pnd, abtReqt, szReqtLen, abtTargetsData+2, &szTargetsData, timeout) || szTargetsData != 2) { + if ((pn53x_initiator_transceive_bytes (pnd, abtReqt, szReqtLen, abtTargetsData+2, &szTargetsData, timeout) < 0) || szTargetsData != 2) { return false; } } - if (!pn53x_initiator_transceive_bytes (pnd, pbtInitData, szInitData, abtTargetsData, &szTargetsData, timeout)) { + if (pn53x_initiator_transceive_bytes (pnd, pbtInitData, szInitData, abtTargetsData, &szTargetsData, timeout) < 0) { return false; } if (nm.nmt == NMT_ISO14443B2CT) { @@ -968,7 +968,7 @@ pn53x_initiator_select_passive_target_ext (struct nfc_device *pnd, return false; uint8_t abtRead[]="\xC4"; // Reading UID_MSB (Read address 4) size_t szReadLen = 1; - if (!pn53x_initiator_transceive_bytes (pnd, abtRead, szReadLen, abtTargetsData+4, &szTargetsData, timeout) || szTargetsData != 2) { + if ((pn53x_initiator_transceive_bytes (pnd, abtRead, szReadLen, abtTargetsData+4, &szTargetsData, timeout) < 0) || szTargetsData != 2) { return false; } szTargetsData = 6; // u16 UID_LSB, u8 prod code, u8 fab code, u16 UID_MSB @@ -986,7 +986,7 @@ pn53x_initiator_select_passive_target_ext (struct nfc_device *pnd, size_t szAttribLen = sizeof(abtAttrib); memcpy(abtAttrib, abtTargetsData, szAttribLen); abtAttrib[1] = 0x0f; // ATTRIB - if (!pn53x_initiator_transceive_bytes (pnd, abtAttrib, szAttribLen, NULL, NULL, timeout)) { + if (pn53x_initiator_transceive_bytes (pnd, abtAttrib, szAttribLen, NULL, NULL, timeout) < 0) { return false; } } diff --git a/libnfc/nfc.c b/libnfc/nfc.c index 3957509..6c5e0fc 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -474,7 +474,7 @@ nfc_initiator_deselect_target (nfc_device *pnd) /** * @brief Send data to target then retrieve data from target - * @return Returns \c true if action was successfully performed; otherwise returns \c false. + * @return Returns received bytes count on success, otherwise returns libnfc's error code * * @param pbtTx contains a byte array of the frame that needs to be transmitted. * @param szTx contains the length in bytes. @@ -495,7 +495,7 @@ nfc_initiator_deselect_target (nfc_device *pnd) * * @warning The configuration option \a NP_HANDLE_PARITY must be set to \c true (the default value). */ -bool +int nfc_initiator_transceive_bytes (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, size_t *pszRx, int timeout) {