nfc_target_receive_bits() function returns now received bits count on success and libnfc error code on failure.
This commit is contained in:
parent
951dde8143
commit
0de1136037
7 changed files with 18 additions and 16 deletions
|
@ -172,7 +172,7 @@ main (int argc, char *argv[])
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
// Test if we received a frame
|
// Test if we received a frame
|
||||||
if (nfc_target_receive_bits (pnd, abtRecv, &szRecvBits, NULL)) {
|
if (nfc_target_receive_bits (pnd, abtRecv, &szRecvBits, NULL) > 0) {
|
||||||
// Prepare the command to send back for the anti-collision request
|
// Prepare the command to send back for the anti-collision request
|
||||||
switch (szRecvBits) {
|
switch (szRecvBits) {
|
||||||
case 7: // Request or Wakeup
|
case 7: // Request or Wakeup
|
||||||
|
|
|
@ -175,7 +175,7 @@ main (int argc, char *argv[])
|
||||||
|
|
||||||
while (!quitting) {
|
while (!quitting) {
|
||||||
// Test if we received a frame from the reader
|
// Test if we received a frame from the reader
|
||||||
if (nfc_target_receive_bits (pndTag, abtReaderRx, &szReaderRxBits, abtReaderRxPar)) {
|
if (nfc_target_receive_bits (pndTag, abtReaderRx, &szReaderRxBits, abtReaderRxPar) > 0) {
|
||||||
// Drop down the field before sending a REQA command and start a new session
|
// Drop down the field before sending a REQA command and start a new session
|
||||||
if (szReaderRxBits == 7 && abtReaderRx[0] == 0x26) {
|
if (szReaderRxBits == 7 && abtReaderRx[0] == 0x26) {
|
||||||
// Drop down field for a very short time (original tag will reboot)
|
// Drop down field for a very short time (original tag will reboot)
|
||||||
|
|
|
@ -87,7 +87,7 @@ extern "C" {
|
||||||
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 int 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 int nfc_target_receive_bits (nfc_device *pnd, uint8_t *pbtRx, size_t *pszRxBits, uint8_t *pbtRxPar);
|
||||||
|
|
||||||
/* Error reporting */
|
/* Error reporting */
|
||||||
NFC_EXPORT const char *nfc_strerror (const nfc_device *pnd);
|
NFC_EXPORT const char *nfc_strerror (const nfc_device *pnd);
|
||||||
|
|
|
@ -1747,21 +1747,23 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size
|
||||||
return NFC_SUCCESS;
|
return NFC_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
int
|
||||||
pn53x_target_receive_bits (struct nfc_device *pnd, uint8_t *pbtRx, size_t *pszRxBits, uint8_t *pbtRxPar)
|
pn53x_target_receive_bits (struct nfc_device *pnd, uint8_t *pbtRx, size_t *pszRxBits, uint8_t *pbtRxPar)
|
||||||
{
|
{
|
||||||
uint8_t abtCmd[] = { TgGetInitiatorCommand };
|
uint8_t abtCmd[] = { TgGetInitiatorCommand };
|
||||||
|
|
||||||
uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
||||||
size_t szRx = sizeof (abtRx);
|
size_t szRx = sizeof (abtRx);
|
||||||
|
int res = 0;
|
||||||
|
|
||||||
// Try to gather a received frame from the reader
|
// Try to gather a received frame from the reader
|
||||||
if (pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRx, &szRx, -1) < 0)
|
if ((res = pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRx, &szRx, -1)) < 0)
|
||||||
return false;
|
return res;
|
||||||
|
|
||||||
// Get the last bit-count that is stored in the received byte
|
// Get the last bit-count that is stored in the received byte
|
||||||
uint8_t ui8rcc;
|
uint8_t ui8rcc;
|
||||||
if (pn53x_read_register (pnd, PN53X_REG_CIU_Control, &ui8rcc) < 0)
|
if ((res = pn53x_read_register (pnd, PN53X_REG_CIU_Control, &ui8rcc)) < 0)
|
||||||
return false;
|
return res;
|
||||||
uint8_t ui8Bits = ui8rcc & SYMBOL_RX_LAST_BITS;
|
uint8_t ui8Bits = ui8rcc & SYMBOL_RX_LAST_BITS;
|
||||||
|
|
||||||
// Recover the real frame length in bits
|
// Recover the real frame length in bits
|
||||||
|
@ -1778,8 +1780,8 @@ pn53x_target_receive_bits (struct nfc_device *pnd, uint8_t *pbtRx, size_t *pszRx
|
||||||
// Copy the received bytes
|
// Copy the received bytes
|
||||||
memcpy (pbtRx, abtRx + 1, szRx - 1);
|
memcpy (pbtRx, abtRx + 1, szRx - 1);
|
||||||
}
|
}
|
||||||
// Everyting seems ok, return true
|
// Everyting seems ok, return received bits count
|
||||||
return true;
|
return *pszRxBits;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -1821,13 +1823,13 @@ pn53x_target_receive_bytes (struct nfc_device *pnd, uint8_t *pbtRx, size_t *pszR
|
||||||
if (pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRx, &szRx, timeout) < 0)
|
if (pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRx, &szRx, timeout) < 0)
|
||||||
return pnd->last_error;
|
return pnd->last_error;
|
||||||
|
|
||||||
// Save the received byte count
|
// Save the received bytes count
|
||||||
*pszRx = szRx - 1;
|
*pszRx = szRx - 1;
|
||||||
|
|
||||||
// Copy the received bytes
|
// Copy the received bytes
|
||||||
memcpy (pbtRx, abtRx + 1, *pszRx);
|
memcpy (pbtRx, abtRx + 1, *pszRx);
|
||||||
|
|
||||||
// Everyting seems ok, return true
|
// Everyting seems ok, return received bytes count
|
||||||
return *pszRx;
|
return *pszRx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -313,7 +313,7 @@ int pn53x_initiator_deselect_target (struct nfc_device *pnd);
|
||||||
|
|
||||||
// NFC device as Target functions
|
// NFC device as Target functions
|
||||||
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);
|
int 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);
|
||||||
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_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);
|
||||||
|
|
|
@ -146,7 +146,7 @@ struct nfc_driver_t {
|
||||||
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);
|
||||||
int (*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 (*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);
|
||||||
int (*device_set_property_int) (struct nfc_device *pnd, const nfc_property property, const int value);
|
int (*device_set_property_int) (struct nfc_device *pnd, const nfc_property property, const int value);
|
||||||
|
|
|
@ -749,7 +749,7 @@ nfc_target_send_bits (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBi
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Receive bit-frames
|
* @brief Receive bit-frames
|
||||||
* @return Returns \c true if action was successfully performed; otherwise returns \c false.
|
* @return Returns received bits count on success, otherwise returns libnfc's error code
|
||||||
*
|
*
|
||||||
* This function makes it possible to receive (raw) bit-frames. It returns all
|
* This function makes it possible to receive (raw) bit-frames. It returns all
|
||||||
* the messages that are stored in the FIFO buffer of the \e PN53x chip. It
|
* the messages that are stored in the FIFO buffer of the \e PN53x chip. It
|
||||||
|
@ -758,7 +758,7 @@ nfc_target_send_bits (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBi
|
||||||
* NP_ACCEPT_MULTIPLE_FRAMES configuration option to avoid losing transmitted
|
* NP_ACCEPT_MULTIPLE_FRAMES configuration option to avoid losing transmitted
|
||||||
* frames.
|
* frames.
|
||||||
*/
|
*/
|
||||||
bool
|
int
|
||||||
nfc_target_receive_bits (nfc_device *pnd, uint8_t *pbtRx, size_t *pszRxBits, uint8_t *pbtRxPar)
|
nfc_target_receive_bits (nfc_device *pnd, uint8_t *pbtRx, size_t *pszRxBits, uint8_t *pbtRxPar)
|
||||||
{
|
{
|
||||||
HAL (target_receive_bits, pnd, pbtRx, pszRxBits, pbtRxPar);
|
HAL (target_receive_bits, pnd, pbtRx, pszRxBits, pbtRxPar);
|
||||||
|
|
Loading…
Reference in a new issue