rx buffer size parameter of nfc_target_init() function is now a const size_t.
This commit is contained in:
parent
5e796e0a26
commit
00818e048c
14 changed files with 36 additions and 40 deletions
|
|
@ -62,8 +62,7 @@ int
|
|||
main (int argc, const char *argv[])
|
||||
{
|
||||
uint8_t abtRx[MAX_FRAME_LEN];
|
||||
int res = 0;
|
||||
size_t szRx = sizeof(abtRx);
|
||||
int szRx;
|
||||
size_t szDeviceFound;
|
||||
uint8_t abtTx[] = "Hello Mars!";
|
||||
#define MAX_DEVICE_COUNT 2
|
||||
|
|
@ -120,18 +119,17 @@ main (int argc, const char *argv[])
|
|||
print_nfc_target (nt, false);
|
||||
|
||||
printf ("Waiting for initiator request...\n");
|
||||
if(nfc_target_init (pnd, &nt, abtRx, &szRx, 0) < 0) {
|
||||
if ((szRx = nfc_target_init (pnd, &nt, abtRx, sizeof(abtRx), 0)) < 0) {
|
||||
nfc_perror(pnd, "nfc_target_init");
|
||||
goto error;
|
||||
}
|
||||
|
||||
printf("Initiator request received. Waiting for data...\n");
|
||||
if ((res = nfc_target_receive_bytes (pnd, abtRx, sizeof (abtRx), 0)) < 0) {
|
||||
if ((szRx = nfc_target_receive_bytes (pnd, abtRx, sizeof (abtRx), 0)) < 0) {
|
||||
nfc_perror(pnd, "nfc_target_receive_bytes");
|
||||
goto error;
|
||||
}
|
||||
szRx = (size_t) res;
|
||||
abtRx[szRx] = '\0';
|
||||
abtRx[(size_t) szRx] = '\0';
|
||||
printf ("Received: %s\n", abtRx);
|
||||
|
||||
printf ("Sending: %s\n", abtTx);
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@
|
|||
#define SAK_ISO14443_4_COMPLIANT 0x20
|
||||
|
||||
static uint8_t abtRx[MAX_FRAME_LEN];
|
||||
static size_t szRx = sizeof(abtRx);
|
||||
static int szRx;
|
||||
static nfc_device *pnd;
|
||||
static bool quiet_output = false;
|
||||
static bool init_mfc_auth = false;
|
||||
|
|
@ -137,17 +137,16 @@ bool
|
|||
nfc_target_emulate_tag(nfc_device *pnd, nfc_target *pnt)
|
||||
{
|
||||
size_t szTx;
|
||||
int res = 0;
|
||||
uint8_t abtTx[MAX_FRAME_LEN];
|
||||
bool loop = true;
|
||||
|
||||
if (nfc_target_init (pnd, pnt, abtRx, &szRx, 0) < 0) {
|
||||
if ((szRx = nfc_target_init (pnd, pnt, abtRx, sizeof(abtRx), 0)) < 0) {
|
||||
nfc_perror (pnd, "nfc_target_init");
|
||||
return false;
|
||||
}
|
||||
|
||||
while ( loop ) {
|
||||
loop = target_io( pnt, abtRx, szRx, abtTx, &szTx );
|
||||
loop = target_io( pnt, abtRx, (size_t) szRx, abtTx, &szTx );
|
||||
if (szTx) {
|
||||
if (nfc_target_send_bytes(pnd, abtTx, szTx, 0) < 0) {
|
||||
nfc_perror (pnd, "nfc_target_send_bytes");
|
||||
|
|
@ -159,11 +158,10 @@ 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 ((res = nfc_target_receive_bytes(pnd, abtRx, sizeof (abtRx), 0)) < 0) {
|
||||
if ((szRx = nfc_target_receive_bytes(pnd, abtRx, sizeof (abtRx), 0)) < 0) {
|
||||
nfc_perror (pnd, "nfc_target_receive_bytes");
|
||||
return false;
|
||||
}
|
||||
szRx = (size_t) res;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@
|
|||
#define MAX_FRAME_LEN 264
|
||||
|
||||
static uint8_t abtRecv[MAX_FRAME_LEN];
|
||||
static size_t szRecvBits;
|
||||
static int szRecvBits;
|
||||
static nfc_device *pnd;
|
||||
|
||||
// ISO14443A Anti-Collision response
|
||||
|
|
@ -155,13 +155,13 @@ main (int argc, char *argv[])
|
|||
},
|
||||
},
|
||||
};
|
||||
if (nfc_target_init (pnd, &nt, abtRecv, &szRecvBits, 0) < 0) {
|
||||
if ((szRecvBits = nfc_target_init (pnd, &nt, abtRecv, sizeof (abtRecv), 0)) < 0) {
|
||||
nfc_perror (pnd, "nfc_target_init");
|
||||
ERR ("Could not come out of auto-emulation, no command was received");
|
||||
goto error;
|
||||
}
|
||||
printf ("[+] Received initiator command: ");
|
||||
print_hex_bits (abtRecv, szRecvBits);
|
||||
print_hex_bits (abtRecv, (size_t) szRecvBits);
|
||||
printf ("[+] Configuring communication\n");
|
||||
if ((nfc_device_set_property_bool (pnd, NP_HANDLE_CRC, false) < 0) || (nfc_device_set_property_bool (pnd, NP_HANDLE_PARITY, true) < 0)) {
|
||||
nfc_perror (pnd, "nfc_device_set_property_bool");
|
||||
|
|
@ -200,7 +200,7 @@ main (int argc, char *argv[])
|
|||
|
||||
if (!quiet_output) {
|
||||
printf ("R: ");
|
||||
print_hex_bits (abtRecv, szRecvBits);
|
||||
print_hex_bits (abtRecv, (size_t) szRecvBits);
|
||||
}
|
||||
// Test if we know how to respond
|
||||
if (szTxBits) {
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@
|
|||
|
||||
static uint8_t abtReaderRx[MAX_FRAME_LEN];
|
||||
static uint8_t abtReaderRxPar[MAX_FRAME_LEN];
|
||||
static size_t szReaderRxBits;
|
||||
static int szReaderRxBits;
|
||||
static uint8_t abtTagRx[MAX_FRAME_LEN];
|
||||
static uint8_t abtTagRxPar[MAX_FRAME_LEN];
|
||||
static int szTagRxBits;
|
||||
|
|
@ -146,7 +146,7 @@ main (int argc, char *argv[])
|
|||
},
|
||||
};
|
||||
|
||||
if (nfc_target_init (pndTag, &nt, abtReaderRx, &szReaderRxBits, 0) < 0) {
|
||||
if ((szReaderRxBits = nfc_target_init (pndTag, &nt, abtReaderRx, sizeof (abtReaderRx), 0)) < 0) {
|
||||
ERR ("%s", "Initialization of NFC emulator failed");
|
||||
nfc_disconnect (pndTag);
|
||||
return EXIT_FAILURE;
|
||||
|
|
@ -197,11 +197,11 @@ main (int argc, char *argv[])
|
|||
// Print the reader frame to the screen
|
||||
if (!quiet_output) {
|
||||
printf ("R: ");
|
||||
print_hex_par (abtReaderRx, szReaderRxBits, abtReaderRxPar);
|
||||
print_hex_par (abtReaderRx, (size_t) szReaderRxBits, abtReaderRxPar);
|
||||
}
|
||||
// Forward the frame to the original tag
|
||||
if ((szTagRxBits = nfc_initiator_transceive_bits
|
||||
(pndReader, abtReaderRx, szReaderRxBits, abtReaderRxPar, abtTagRx, abtTagRxPar)) > 0) {
|
||||
(pndReader, abtReaderRx, (size_t) szReaderRxBits, abtReaderRxPar, abtTagRx, abtTagRxPar)) > 0) {
|
||||
// Redirect the answer back to the reader
|
||||
if (nfc_target_send_bits (pndTag, abtTagRx, szTagRxBits, abtTagRxPar) < 0) {
|
||||
nfc_perror (pndTag, "nfc_target_send_bits");
|
||||
|
|
|
|||
|
|
@ -157,7 +157,6 @@ main (int argc, const char *argv[])
|
|||
case PSM_DUAL_CARD:
|
||||
{
|
||||
uint8_t abtRx[MAX_FRAME_LEN];
|
||||
size_t szRx = sizeof(abtRx);
|
||||
|
||||
nfc_target nt = {
|
||||
.nm = {
|
||||
|
|
@ -176,7 +175,7 @@ main (int argc, const char *argv[])
|
|||
};
|
||||
printf ("Now both, NFC device (configured as target) and SAM are readables from an external NFC initiator.\n");
|
||||
printf ("Please note that NFC device (configured as target) stay in target mode until it receive RATS, ATR_REQ or proprietary command.\n");
|
||||
if (nfc_target_init (pnd, &nt, abtRx, &szRx, 0) < 0) {
|
||||
if (nfc_target_init (pnd, &nt, abtRx, sizeof(abtRx), 0) < 0) {
|
||||
nfc_perror(pnd, "nfc_target_init");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue