nfc_target_receive_bytes() function does not now use pszRx as parameter because this function returns it.
This commit is contained in:
parent
7e7ee3299e
commit
642f9a38f7
11 changed files with 25 additions and 26 deletions
|
@ -125,7 +125,7 @@ main (int argc, const char *argv[])
|
|||
}
|
||||
|
||||
printf("Initiator request received. Waiting for data...\n");
|
||||
if (nfc_target_receive_bytes (pnd, abtRx, &szRx, 0) < 0) {
|
||||
if (((int) (szRx = (size_t) nfc_target_receive_bytes (pnd, abtRx, 0))) < 0) {
|
||||
nfc_perror(pnd, "nfc_target_receive_bytes");
|
||||
goto error;
|
||||
}
|
||||
|
|
|
@ -158,7 +158,7 @@ nfc_target_emulate_tag(nfc_device *pnd, nfc_target *pnt)
|
|||
nfc_device_set_property_bool (pnd, NP_HANDLE_CRC, false);
|
||||
init_mfc_auth = false;
|
||||
}
|
||||
if (nfc_target_receive_bytes(pnd, abtRx, &szRx, 0) < 0) {
|
||||
if ((int) ((szRx = (size_t) nfc_target_receive_bytes(pnd, abtRx, 0))) < 0) {
|
||||
nfc_perror (pnd, "nfc_target_receive_bytes");
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ extern "C" {
|
|||
/* NFC target: act as tag (i.e. MIFARE Classic) or NFC target device. */
|
||||
NFC_EXPORT int nfc_target_init (nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size_t *pszRx, 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, 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_receive_bits (nfc_device *pnd, uint8_t *pbtRx, uint8_t *pbtRxPar);
|
||||
|
||||
|
|
|
@ -1851,7 +1851,7 @@ pn53x_target_receive_bits (struct nfc_device *pnd, uint8_t *pbtRx, uint8_t *pbtR
|
|||
}
|
||||
|
||||
int
|
||||
pn53x_target_receive_bytes (struct nfc_device *pnd, uint8_t *pbtRx, size_t *pszRx, int timeout)
|
||||
pn53x_target_receive_bytes (struct nfc_device *pnd, uint8_t *pbtRx, int timeout)
|
||||
{
|
||||
uint8_t abtCmd[1];
|
||||
|
||||
|
@ -1890,13 +1890,13 @@ pn53x_target_receive_bytes (struct nfc_device *pnd, uint8_t *pbtRx, size_t *pszR
|
|||
return pnd->last_error;
|
||||
|
||||
// Save the received bytes count
|
||||
*pszRx = szRx - 1;
|
||||
szRx -= 1;
|
||||
|
||||
// Copy the received bytes
|
||||
memcpy (pbtRx, abtRx + 1, *pszRx);
|
||||
memcpy (pbtRx, abtRx + 1, szRx);
|
||||
|
||||
// Everyting seems ok, return received bytes count
|
||||
return *pszRx;
|
||||
return szRx;
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -310,7 +310,7 @@ int pn53x_initiator_deselect_target (struct nfc_device *pnd);
|
|||
// NFC device as Target functions
|
||||
int pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size_t *pszRx, int timeout);
|
||||
int pn53x_target_receive_bits (struct nfc_device *pnd, uint8_t *pbtRx, 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, 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_bytes (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, int timeout);
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ nfc_emulate_target (nfc_device *pnd, struct nfc_emulator *emulator)
|
|||
}
|
||||
}
|
||||
if (res >= 0) {
|
||||
if (nfc_target_receive_bytes(pnd, abtRx, &szRx, 0) < 0) {
|
||||
if ((int) ((szRx = (size_t) nfc_target_receive_bytes(pnd, abtRx, 0))) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -144,7 +144,7 @@ struct nfc_driver_t {
|
|||
|
||||
int (*target_init) (struct nfc_device *pnd, nfc_target * pnt, uint8_t * pbtRx, size_t * pszRx, 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, int timeout);
|
||||
int (*target_send_bits) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar);
|
||||
int (*target_receive_bits) (struct nfc_device *pnd, uint8_t * pbtRx, uint8_t * pbtRxPar);
|
||||
|
||||
|
|
|
@ -719,7 +719,6 @@ nfc_target_send_bytes (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx,
|
|||
*
|
||||
* @param pnd \a nfc_device struct pointer that represent currently used device
|
||||
* @param[out] pbtRx pointer to Rx buffer
|
||||
* @param[out] pszRx received byte count
|
||||
* @param timeout in milliseconds
|
||||
*
|
||||
* This function retrieves bytes frames (e.g. ADPU) sent by the \e initiator to the NFC device (configured as \e target).
|
||||
|
@ -728,9 +727,9 @@ nfc_target_send_bytes (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx,
|
|||
* If timeout is a null pointer, the function blocks indefinitely (until an error is raised or function is completed).
|
||||
*/
|
||||
int
|
||||
nfc_target_receive_bytes (nfc_device *pnd, uint8_t *pbtRx, size_t *pszRx, int timeout)
|
||||
nfc_target_receive_bytes (nfc_device *pnd, uint8_t *pbtRx, int timeout)
|
||||
{
|
||||
HAL (target_receive_bytes, pnd, pbtRx, pszRx, timeout);
|
||||
HAL (target_receive_bytes, pnd, pbtRx, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -85,11 +85,11 @@ target_thread (void *arg)
|
|||
uint8_t abtRx[1024];
|
||||
size_t szRx = sizeof (abtRx);
|
||||
int res = nfc_target_init (device, &nt, abtRx, &szRx, 0);
|
||||
cut_assert_equal_int (0, res, cut_message ("Can't initialize NFC device as target: %s", nfc_strerror (device)));
|
||||
cut_assert_operator_int (res, >, 0, cut_message ("Can't initialize NFC device as target: %s", nfc_strerror (device)));
|
||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
res = nfc_target_receive_bytes (device, abtRx, &szRx, 500);
|
||||
cut_assert_operator_int (res, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
|
||||
szRx = (size_t) nfc_target_receive_bytes (device, abtRx, 500);
|
||||
cut_assert_operator_int (szRx, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
|
||||
|
||||
const uint8_t abtAttRx[] = "Hello DEP target!";
|
||||
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
|
||||
|
|
|
@ -83,12 +83,12 @@ target_thread (void *arg)
|
|||
uint8_t abtRx[1024];
|
||||
size_t szRx = sizeof (abtRx);
|
||||
int res = nfc_target_init (device, &nt, abtRx, &szRx, 0);
|
||||
cut_assert_equal_int (0, res, cut_message ("Can't initialize NFC device as target: %s", nfc_strerror (device)));
|
||||
cut_assert_operator_int (res, >, 0, cut_message ("Can't initialize NFC device as target: %s", nfc_strerror (device)));
|
||||
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
// First pass
|
||||
res = nfc_target_receive_bytes (device, abtRx, &szRx, 500);
|
||||
cut_assert_operator_int (res, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
|
||||
szRx = (size_t) nfc_target_receive_bytes (device, abtRx, 500);
|
||||
cut_assert_operator_int ((int) szRx, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
|
||||
|
||||
const uint8_t abtAttRx[] = "Hello DEP target!";
|
||||
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
|
||||
|
@ -100,8 +100,8 @@ target_thread (void *arg)
|
|||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
// Second pass
|
||||
res = nfc_target_receive_bytes (device, abtRx, &szRx, 500);
|
||||
cut_assert_operator_int (res, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
|
||||
szRx = (size_t) nfc_target_receive_bytes (device, abtRx, 500);
|
||||
cut_assert_operator_int ((int) szRx, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
|
||||
|
||||
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
|
||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
@ -111,8 +111,8 @@ target_thread (void *arg)
|
|||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
// Third pass
|
||||
res = nfc_target_receive_bytes (device, abtRx, &szRx, 500);
|
||||
cut_assert_operator_int (res, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
|
||||
szRx = (size_t) nfc_target_receive_bytes (device, abtRx, 500);
|
||||
cut_assert_operator_int ((int) szRx, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
|
||||
|
||||
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
|
||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
@ -122,8 +122,8 @@ target_thread (void *arg)
|
|||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
||||
// Fourth pass
|
||||
res = nfc_target_receive_bytes (device, abtRx, &szRx, 500);
|
||||
cut_assert_operator_int (res, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
|
||||
szRx = (size_t) nfc_target_receive_bytes (device, abtRx, 500);
|
||||
cut_assert_operator_int ((int)szRx, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
|
||||
|
||||
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
|
||||
if (res <= 0) { thread_res = -1; return (void*) thread_res; }
|
||||
|
|
|
@ -370,7 +370,7 @@ main (int argc, char *argv[])
|
|||
bool ret;
|
||||
if (!initiator_only_mode) {
|
||||
// Receive external reader command through target
|
||||
if (nfc_target_receive_bytes(pndTarget,abtCapdu,&szCapduLen, 0) < 0) {
|
||||
if ((int) ((szCapduLen = (size_t) nfc_target_receive_bytes(pndTarget, abtCapdu, 0))) < 0) {
|
||||
nfc_perror (pndTarget, "nfc_target_receive_bytes");
|
||||
if (!target_only_mode) {
|
||||
nfc_disconnect (pndInitiator);
|
||||
|
|
Loading…
Reference in a new issue