nfc_initiator_transceive_bytesfunction now returns libnfc error code on failure and received bytes count on success.

This commit is contained in:
Audrey Diacre 2011-12-19 14:37:22 +00:00
parent 31f67be83e
commit 145cc4b2ad
5 changed files with 11 additions and 11 deletions

View file

@ -105,7 +105,7 @@ transmit_bytes (const uint8_t *pbtTx, const size_t szTx)
print_hex (pbtTx, szTx); print_hex (pbtTx, szTx);
} }
// Transmit the command bytes // 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; return false;
// Show received answer // Show received answer

View file

@ -93,7 +93,7 @@ main (int argc, const char *argv[])
print_nfc_target (nt, false); print_nfc_target (nt, false);
printf ("Sending: %s\n", abtTx); 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"); nfc_perror(pnd, "nfc_initiator_transceive_bytes");
goto error; goto error;
} }

View file

@ -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_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_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_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_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_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); 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);

View file

@ -943,11 +943,11 @@ pn53x_initiator_select_passive_target_ext (struct nfc_device *pnd,
uint8_t abtRx[1]; uint8_t abtRx[1];
size_t szRxLen = 1; size_t szRxLen = 1;
// Getting random Chip_ID // 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; return false;
} }
abtSelect[1] = abtRx[0]; 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; return false;
} }
} }
@ -956,11 +956,11 @@ pn53x_initiator_select_passive_target_ext (struct nfc_device *pnd,
uint8_t abtReqt[]="\x10"; uint8_t abtReqt[]="\x10";
size_t szReqtLen = 1; size_t szReqtLen = 1;
// Getting product code / fab code & store it in output buffer after the serial nr we'll obtain later // 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; 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; return false;
} }
if (nm.nmt == NMT_ISO14443B2CT) { if (nm.nmt == NMT_ISO14443B2CT) {
@ -968,7 +968,7 @@ pn53x_initiator_select_passive_target_ext (struct nfc_device *pnd,
return false; return false;
uint8_t abtRead[]="\xC4"; // Reading UID_MSB (Read address 4) uint8_t abtRead[]="\xC4"; // Reading UID_MSB (Read address 4)
size_t szReadLen = 1; 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; return false;
} }
szTargetsData = 6; // u16 UID_LSB, u8 prod code, u8 fab code, u16 UID_MSB 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); size_t szAttribLen = sizeof(abtAttrib);
memcpy(abtAttrib, abtTargetsData, szAttribLen); memcpy(abtAttrib, abtTargetsData, szAttribLen);
abtAttrib[1] = 0x0f; // ATTRIB 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; return false;
} }
} }

View file

@ -474,7 +474,7 @@ nfc_initiator_deselect_target (nfc_device *pnd)
/** /**
* @brief Send data to target then retrieve data from target * @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 pbtTx contains a byte array of the frame that needs to be transmitted.
* @param szTx contains the length in bytes. * @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). * @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, nfc_initiator_transceive_bytes (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx,
size_t *pszRx, int timeout) size_t *pszRx, int timeout)
{ {