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[])
|
main (int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
uint8_t abtRx[MAX_FRAME_LEN];
|
uint8_t abtRx[MAX_FRAME_LEN];
|
||||||
int res = 0;
|
int szRx;
|
||||||
size_t szRx = sizeof(abtRx);
|
|
||||||
size_t szDeviceFound;
|
size_t szDeviceFound;
|
||||||
uint8_t abtTx[] = "Hello Mars!";
|
uint8_t abtTx[] = "Hello Mars!";
|
||||||
#define MAX_DEVICE_COUNT 2
|
#define MAX_DEVICE_COUNT 2
|
||||||
|
@ -120,18 +119,17 @@ main (int argc, const char *argv[])
|
||||||
print_nfc_target (nt, false);
|
print_nfc_target (nt, false);
|
||||||
|
|
||||||
printf ("Waiting for initiator request...\n");
|
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");
|
nfc_perror(pnd, "nfc_target_init");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Initiator request received. Waiting for data...\n");
|
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");
|
nfc_perror(pnd, "nfc_target_receive_bytes");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
szRx = (size_t) res;
|
abtRx[(size_t) szRx] = '\0';
|
||||||
abtRx[szRx] = '\0';
|
|
||||||
printf ("Received: %s\n", abtRx);
|
printf ("Received: %s\n", abtRx);
|
||||||
|
|
||||||
printf ("Sending: %s\n", abtTx);
|
printf ("Sending: %s\n", abtTx);
|
||||||
|
|
|
@ -55,7 +55,7 @@
|
||||||
#define SAK_ISO14443_4_COMPLIANT 0x20
|
#define SAK_ISO14443_4_COMPLIANT 0x20
|
||||||
|
|
||||||
static uint8_t abtRx[MAX_FRAME_LEN];
|
static uint8_t abtRx[MAX_FRAME_LEN];
|
||||||
static size_t szRx = sizeof(abtRx);
|
static int szRx;
|
||||||
static nfc_device *pnd;
|
static nfc_device *pnd;
|
||||||
static bool quiet_output = false;
|
static bool quiet_output = false;
|
||||||
static bool init_mfc_auth = false;
|
static bool init_mfc_auth = false;
|
||||||
|
@ -137,17 +137,16 @@ bool
|
||||||
nfc_target_emulate_tag(nfc_device *pnd, nfc_target *pnt)
|
nfc_target_emulate_tag(nfc_device *pnd, nfc_target *pnt)
|
||||||
{
|
{
|
||||||
size_t szTx;
|
size_t szTx;
|
||||||
int res = 0;
|
|
||||||
uint8_t abtTx[MAX_FRAME_LEN];
|
uint8_t abtTx[MAX_FRAME_LEN];
|
||||||
bool loop = true;
|
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");
|
nfc_perror (pnd, "nfc_target_init");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ( loop ) {
|
while ( loop ) {
|
||||||
loop = target_io( pnt, abtRx, szRx, abtTx, &szTx );
|
loop = target_io( pnt, abtRx, (size_t) szRx, abtTx, &szTx );
|
||||||
if (szTx) {
|
if (szTx) {
|
||||||
if (nfc_target_send_bytes(pnd, abtTx, szTx, 0) < 0) {
|
if (nfc_target_send_bytes(pnd, abtTx, szTx, 0) < 0) {
|
||||||
nfc_perror (pnd, "nfc_target_send_bytes");
|
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);
|
nfc_device_set_property_bool (pnd, NP_HANDLE_CRC, false);
|
||||||
init_mfc_auth = 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");
|
nfc_perror (pnd, "nfc_target_receive_bytes");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
szRx = (size_t) res;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
#define MAX_FRAME_LEN 264
|
#define MAX_FRAME_LEN 264
|
||||||
|
|
||||||
static uint8_t abtRecv[MAX_FRAME_LEN];
|
static uint8_t abtRecv[MAX_FRAME_LEN];
|
||||||
static size_t szRecvBits;
|
static int szRecvBits;
|
||||||
static nfc_device *pnd;
|
static nfc_device *pnd;
|
||||||
|
|
||||||
// ISO14443A Anti-Collision response
|
// 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");
|
nfc_perror (pnd, "nfc_target_init");
|
||||||
ERR ("Could not come out of auto-emulation, no command was received");
|
ERR ("Could not come out of auto-emulation, no command was received");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
printf ("[+] Received initiator command: ");
|
printf ("[+] Received initiator command: ");
|
||||||
print_hex_bits (abtRecv, szRecvBits);
|
print_hex_bits (abtRecv, (size_t) szRecvBits);
|
||||||
printf ("[+] Configuring communication\n");
|
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)) {
|
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");
|
nfc_perror (pnd, "nfc_device_set_property_bool");
|
||||||
|
@ -200,7 +200,7 @@ main (int argc, char *argv[])
|
||||||
|
|
||||||
if (!quiet_output) {
|
if (!quiet_output) {
|
||||||
printf ("R: ");
|
printf ("R: ");
|
||||||
print_hex_bits (abtRecv, szRecvBits);
|
print_hex_bits (abtRecv, (size_t) szRecvBits);
|
||||||
}
|
}
|
||||||
// Test if we know how to respond
|
// Test if we know how to respond
|
||||||
if (szTxBits) {
|
if (szTxBits) {
|
||||||
|
|
|
@ -52,7 +52,7 @@
|
||||||
|
|
||||||
static uint8_t abtReaderRx[MAX_FRAME_LEN];
|
static uint8_t abtReaderRx[MAX_FRAME_LEN];
|
||||||
static uint8_t abtReaderRxPar[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 abtTagRx[MAX_FRAME_LEN];
|
||||||
static uint8_t abtTagRxPar[MAX_FRAME_LEN];
|
static uint8_t abtTagRxPar[MAX_FRAME_LEN];
|
||||||
static int szTagRxBits;
|
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");
|
ERR ("%s", "Initialization of NFC emulator failed");
|
||||||
nfc_disconnect (pndTag);
|
nfc_disconnect (pndTag);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
@ -197,11 +197,11 @@ main (int argc, char *argv[])
|
||||||
// Print the reader frame to the screen
|
// Print the reader frame to the screen
|
||||||
if (!quiet_output) {
|
if (!quiet_output) {
|
||||||
printf ("R: ");
|
printf ("R: ");
|
||||||
print_hex_par (abtReaderRx, szReaderRxBits, abtReaderRxPar);
|
print_hex_par (abtReaderRx, (size_t) szReaderRxBits, abtReaderRxPar);
|
||||||
}
|
}
|
||||||
// Forward the frame to the original tag
|
// Forward the frame to the original tag
|
||||||
if ((szTagRxBits = nfc_initiator_transceive_bits
|
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
|
// Redirect the answer back to the reader
|
||||||
if (nfc_target_send_bits (pndTag, abtTagRx, szTagRxBits, abtTagRxPar) < 0) {
|
if (nfc_target_send_bits (pndTag, abtTagRx, szTagRxBits, abtTagRxPar) < 0) {
|
||||||
nfc_perror (pndTag, "nfc_target_send_bits");
|
nfc_perror (pndTag, "nfc_target_send_bits");
|
||||||
|
|
|
@ -157,7 +157,6 @@ main (int argc, const char *argv[])
|
||||||
case PSM_DUAL_CARD:
|
case PSM_DUAL_CARD:
|
||||||
{
|
{
|
||||||
uint8_t abtRx[MAX_FRAME_LEN];
|
uint8_t abtRx[MAX_FRAME_LEN];
|
||||||
size_t szRx = sizeof(abtRx);
|
|
||||||
|
|
||||||
nfc_target nt = {
|
nfc_target nt = {
|
||||||
.nm = {
|
.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 ("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");
|
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");
|
nfc_perror(pnd, "nfc_target_init");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@ extern "C" {
|
||||||
NFC_EXPORT int nfc_initiator_transceive_bits_timed (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar, uint32_t *cycles);
|
NFC_EXPORT int nfc_initiator_transceive_bits_timed (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, uint8_t *pbtRxPar, uint32_t *cycles);
|
||||||
|
|
||||||
/* NFC target: act as tag (i.e. MIFARE Classic) or NFC target device. */
|
/* 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_init (nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t szRx, 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_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, const size_t szRx, int timeout);
|
NFC_EXPORT int nfc_target_receive_bytes (nfc_device *pnd, uint8_t *pbtRx, const size_t szRx, 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);
|
||||||
|
|
|
@ -1592,7 +1592,7 @@ pn53x_initiator_deselect_target (struct nfc_device *pnd)
|
||||||
#define SAK_ISO14443_4_COMPLIANT 0x20
|
#define SAK_ISO14443_4_COMPLIANT 0x20
|
||||||
#define SAK_ISO18092_COMPLIANT 0x40
|
#define SAK_ISO18092_COMPLIANT 0x40
|
||||||
int
|
int
|
||||||
pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size_t *pszRx, int timeout)
|
pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t szRxLen, int timeout)
|
||||||
{
|
{
|
||||||
pn53x_reset_settings(pnd);
|
pn53x_reset_settings(pnd);
|
||||||
|
|
||||||
|
@ -1742,13 +1742,14 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size
|
||||||
}
|
}
|
||||||
|
|
||||||
bool targetActivated = false;
|
bool targetActivated = false;
|
||||||
|
size_t szRx;
|
||||||
while (!targetActivated) {
|
while (!targetActivated) {
|
||||||
uint8_t btActivatedMode;
|
uint8_t btActivatedMode;
|
||||||
|
|
||||||
if((res = pn53x_TgInitAsTarget(pnd, ptm, pbtMifareParams, pbtTkt, szTkt, pbtFeliCaParams, pbtNFCID3t, pbtGBt, szGBt, pbtRx, *pszRx, &btActivatedMode, timeout)) < 0) {
|
if((res = pn53x_TgInitAsTarget(pnd, ptm, pbtMifareParams, pbtTkt, szTkt, pbtFeliCaParams, pbtNFCID3t, pbtGBt, szGBt, pbtRx, szRxLen, &btActivatedMode, timeout)) < 0) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
*pszRx = (size_t) res;
|
szRx = (size_t) res;
|
||||||
nfc_modulation nm = {
|
nfc_modulation nm = {
|
||||||
.nmt = NMT_DEP, // Silent compilation warnings
|
.nmt = NMT_DEP, // Silent compilation warnings
|
||||||
.nbr = NBR_UNDEFINED
|
.nbr = NBR_UNDEFINED
|
||||||
|
@ -1805,12 +1806,12 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size
|
||||||
if (ptm & PTM_ISO14443_4_PICC_ONLY) {
|
if (ptm & PTM_ISO14443_4_PICC_ONLY) {
|
||||||
// When PN532 is in PICC target mode, it automatically reply to RATS so
|
// When PN532 is in PICC target mode, it automatically reply to RATS so
|
||||||
// we don't need to forward this command
|
// we don't need to forward this command
|
||||||
*pszRx = 0;
|
szRx = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return *pszRx;
|
return szRx;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -308,7 +308,7 @@ int pn53x_initiator_transceive_bytes_timed (struct nfc_device *pnd, const uin
|
||||||
int pn53x_initiator_deselect_target (struct nfc_device *pnd);
|
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 timeout);
|
int pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t szRxLen, int timeout);
|
||||||
int pn53x_target_receive_bits (struct nfc_device *pnd, uint8_t *pbtRx, const size_t szRxLen, uint8_t *pbtRxPar);
|
int pn53x_target_receive_bits (struct nfc_device *pnd, uint8_t *pbtRx, const size_t szRxLen, uint8_t *pbtRxPar);
|
||||||
int pn53x_target_receive_bytes (struct nfc_device *pnd, uint8_t *pbtRx, const size_t szRxLen, int timeout);
|
int pn53x_target_receive_bytes (struct nfc_device *pnd, uint8_t *pbtRx, const size_t szRxLen, 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);
|
||||||
|
|
|
@ -31,23 +31,23 @@ int
|
||||||
nfc_emulate_target (nfc_device *pnd, struct nfc_emulator *emulator)
|
nfc_emulate_target (nfc_device *pnd, struct nfc_emulator *emulator)
|
||||||
{
|
{
|
||||||
uint8_t abtRx[ISO7816_SHORT_R_APDU_MAX_LEN];
|
uint8_t abtRx[ISO7816_SHORT_R_APDU_MAX_LEN];
|
||||||
size_t szRx = sizeof(abtRx);
|
int szRx;
|
||||||
uint8_t abtTx[ISO7816_SHORT_C_APDU_MAX_LEN];
|
uint8_t abtTx[ISO7816_SHORT_C_APDU_MAX_LEN];
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
if (nfc_target_init (pnd, emulator->target, abtRx, &szRx, 0) < 0) {
|
if ((szRx = nfc_target_init (pnd, emulator->target, abtRx, sizeof(abtRx), 0)) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (res >= 0) {
|
while (res >= 0) {
|
||||||
res = emulator->state_machine->io (emulator, abtRx, szRx, abtTx, sizeof (abtTx));
|
res = emulator->state_machine->io (emulator, abtRx, (size_t) szRx, abtTx, sizeof (abtTx));
|
||||||
if (res > 0) {
|
if (res > 0) {
|
||||||
if (nfc_target_send_bytes(pnd, abtTx, res, 0) < 0) {
|
if (nfc_target_send_bytes(pnd, abtTx, res, 0) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (res >= 0) {
|
if (res >= 0) {
|
||||||
if ((res = nfc_target_receive_bytes(pnd, abtRx, szRx, 0)) < 0) {
|
if ((res = nfc_target_receive_bytes(pnd, abtRx, (size_t) szRx, 0)) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,7 +142,7 @@ struct nfc_driver_t {
|
||||||
int (*initiator_transceive_bytes_timed) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, uint32_t * cycles);
|
int (*initiator_transceive_bytes_timed) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, uint32_t * cycles);
|
||||||
int (*initiator_transceive_bits_timed) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar, uint8_t * pbtRx, uint8_t * pbtRxPar, uint32_t * cycles);
|
int (*initiator_transceive_bits_timed) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar, uint8_t * pbtRx, uint8_t * pbtRxPar, uint32_t * cycles);
|
||||||
|
|
||||||
int (*target_init) (struct nfc_device *pnd, nfc_target * pnt, uint8_t * pbtRx, size_t * pszRx, int timeout);
|
int (*target_init) (struct nfc_device *pnd, nfc_target * pnt, uint8_t * pbtRx, const size_t szRx, int timeout);
|
||||||
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, const size_t szRxLen, int timeout);
|
int (*target_receive_bytes) (struct nfc_device *pnd, uint8_t * pbtRx, const size_t szRxLen, 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);
|
||||||
|
|
|
@ -609,7 +609,7 @@ nfc_initiator_transceive_bits_timed (nfc_device *pnd, const uint8_t *pbtTx, cons
|
||||||
* and/or NDM_UNDEFINED (ie. for DEP mode), these fields will be updated.
|
* and/or NDM_UNDEFINED (ie. for DEP mode), these fields will be updated.
|
||||||
*
|
*
|
||||||
* @param[out] pbtRx Rx buffer pointer
|
* @param[out] pbtRx Rx buffer pointer
|
||||||
* @param[out] pszRx received bytes count
|
* @param[out] szRx received bytes count
|
||||||
* @param timeout in milliseconds
|
* @param timeout in milliseconds
|
||||||
*
|
*
|
||||||
* This function initializes NFC device in \e target mode in order to emulate a
|
* This function initializes NFC device in \e target mode in order to emulate a
|
||||||
|
@ -629,7 +629,7 @@ nfc_initiator_transceive_bits_timed (nfc_device *pnd, const uint8_t *pbtTx, cons
|
||||||
* receive functions can be used.
|
* receive functions can be used.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
nfc_target_init (nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size_t * pszRx, int timeout)
|
nfc_target_init (nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t szRx, int timeout)
|
||||||
{
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
// Disallow invalid frame
|
// Disallow invalid frame
|
||||||
|
@ -656,7 +656,7 @@ nfc_target_init (nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size_t * pszR
|
||||||
if ((res = nfc_device_set_property_bool (pnd, NP_ACTIVATE_FIELD, false)) < 0)
|
if ((res = nfc_device_set_property_bool (pnd, NP_ACTIVATE_FIELD, false)) < 0)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
HAL (target_init, pnd, pnt, pbtRx, pszRx, timeout);
|
HAL (target_init, pnd, pnt, pbtRx, szRx, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -84,7 +84,7 @@ target_thread (void *arg)
|
||||||
|
|
||||||
uint8_t abtRx[1024];
|
uint8_t abtRx[1024];
|
||||||
size_t szRx = sizeof (abtRx);
|
size_t szRx = sizeof (abtRx);
|
||||||
int res = nfc_target_init (device, &nt, abtRx, &szRx, 0);
|
int res = nfc_target_init (device, &nt, abtRx, sizeof (abtRx), 0);
|
||||||
cut_assert_operator_int (res, >, 0, 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; }
|
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ target_thread (void *arg)
|
||||||
|
|
||||||
uint8_t abtRx[1024];
|
uint8_t abtRx[1024];
|
||||||
size_t szRx = sizeof (abtRx);
|
size_t szRx = sizeof (abtRx);
|
||||||
int res = nfc_target_init (device, &nt, abtRx, &szRx, 0);
|
int res = nfc_target_init (device, &nt, abtRx, szRx, 0);
|
||||||
cut_assert_operator_int (res, >, 0, 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; }
|
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||||
|
|
||||||
|
|
|
@ -355,7 +355,7 @@ main (int argc, char *argv[])
|
||||||
printf ("Connected to the NFC emulator device: %s\n", nfc_device_get_name (pndTarget));
|
printf ("Connected to the NFC emulator device: %s\n", nfc_device_get_name (pndTarget));
|
||||||
|
|
||||||
szCapduLen = sizeof (abtCapdu);
|
szCapduLen = sizeof (abtCapdu);
|
||||||
if (nfc_target_init (pndTarget, &ntEmulatedTarget, abtCapdu, &szCapduLen, 0) < 0) {
|
if (nfc_target_init (pndTarget, &ntEmulatedTarget, abtCapdu, szCapduLen, 0) < 0) {
|
||||||
ERR ("%s", "Initialization of NFC emulator failed");
|
ERR ("%s", "Initialization of NFC emulator failed");
|
||||||
if (!target_only_mode) {
|
if (!target_only_mode) {
|
||||||
nfc_disconnect (pndInitiator);
|
nfc_disconnect (pndInitiator);
|
||||||
|
|
Loading…
Reference in a new issue