For the sake of consistency, rename all szRxLen to szRx and szTxLen to szTx

This commit is contained in:
Romuald Conty 2010-10-12 14:56:42 +00:00
parent 5d753827c1
commit c34be50ef1
22 changed files with 195 additions and 195 deletions

View file

@ -21,7 +21,7 @@ bool
nfc_initiator_mifare_cmd (nfc_device_t * pnd, const mifare_cmd mc, const uint8_t ui8Block, mifare_param * pmp)
{
byte_t abtRx[265];
size_t szRxLen;
size_t szRx;
size_t szParamLen;
byte_t abtCmd[265];
@ -68,14 +68,14 @@ nfc_initiator_mifare_cmd (nfc_device_t * pnd, const mifare_cmd mc, const uint8_t
memcpy (abtCmd + 2, (byte_t *) pmp, szParamLen);
// Fire the mifare command
if (!nfc_initiator_transceive_bytes (pnd, abtCmd, 2 + szParamLen, abtRx, &szRxLen)) {
if (!nfc_initiator_transceive_bytes (pnd, abtCmd, 2 + szParamLen, abtRx, &szRx)) {
if (pnd->iLastError != 0x14)
nfc_perror (pnd, "nfc_initiator_transceive_bytes");
return false;
}
// When we have executed a read command, copy the received bytes into the param
if (mc == MC_READ) {
if (szRxLen == 16) {
if (szRx == 16) {
memcpy (pmp->mpd.abtData, abtRx, 16);
} else {
return false;

View file

@ -44,7 +44,7 @@
static byte_t abtRx[MAX_FRAME_LEN];
static size_t szRxBits;
static size_t szRxLen;
static size_t szRx;
static byte_t abtUid[10];
static size_t szUidLen = 4;
static nfc_device_t *pnd;
@ -81,21 +81,21 @@ transmit_bits (const byte_t * pbtTx, const size_t szTxBits)
static bool
transmit_bytes (const byte_t * pbtTx, const size_t szTxLen)
transmit_bytes (const byte_t * pbtTx, const size_t szTx)
{
// Show transmitted command
if (!quiet_output) {
printf ("Sent bits: ");
print_hex (pbtTx, szTxLen);
print_hex (pbtTx, szTx);
}
// Transmit the command bytes
if (!nfc_initiator_transceive_bytes (pnd, pbtTx, szTxLen, abtRx, &szRxLen))
if (!nfc_initiator_transceive_bytes (pnd, pbtTx, szTx, abtRx, &szRx))
return false;
// Show received answer
if (!quiet_output) {
printf ("Received bits: ");
print_hex (abtRx, szRxLen);
print_hex (abtRx, szRx);
}
// Succesful transfer
return true;

View file

@ -58,22 +58,22 @@
#define MAX_FRAME_LEN 264
static byte_t abtRx[MAX_FRAME_LEN];
static size_t szRxLen;
static size_t szRx;
static nfc_device_t *pnd;
static bool quiet_output = false;
#define SYMBOL_PARAM_fISO14443_4_PICC 0x20
bool send_bytes (const byte_t * pbtTx, const size_t szTxLen)
bool send_bytes (const byte_t * pbtTx, const size_t szTx)
{
// Show transmitted command
if (!quiet_output) {
printf ("Sent data: ");
print_hex (pbtTx, szTxLen);
print_hex (pbtTx, szTx);
}
// Transmit the command bytes
if (!nfc_target_send_bytes(pnd, pbtTx, szTxLen)) {
if (!nfc_target_send_bytes(pnd, pbtTx, szTx)) {
nfc_perror (pnd, "nfc_target_send_bytes");
exit(EXIT_FAILURE);
}
@ -83,7 +83,7 @@ bool send_bytes (const byte_t * pbtTx, const size_t szTxLen)
bool receive_bytes (void)
{
if (!nfc_target_receive_bytes(pnd,abtRx,&szRxLen)) {
if (!nfc_target_receive_bytes(pnd,abtRx,&szRx)) {
nfc_perror (pnd, "nfc_target_receive_bytes");
exit(EXIT_FAILURE);
}
@ -91,7 +91,7 @@ bool receive_bytes (void)
// Show received answer
if (!quiet_output) {
printf ("Received data: ");
print_hex (abtRx, szRxLen);
print_hex (abtRx, szRx);
}
// Succesful transfer
return true;
@ -120,7 +120,7 @@ main (int argc, char *argv[])
.nti.nai.szAtsLen = 0,
};
if (!nfc_target_init (pnd, NTM_ISO14443_4_PICC, nt, abtRx, &szRxLen)) {
if (!nfc_target_init (pnd, NTM_ISO14443_4_PICC, nt, abtRx, &szRx)) {
nfc_perror (pnd, "nfc_target_init");
ERR("Could not come out of auto-emulation, no command was received");
return EXIT_FAILURE;
@ -128,7 +128,7 @@ main (int argc, char *argv[])
if (!quiet_output) {
printf ("Received data: ");
print_hex (abtRx, szRxLen);
print_hex (abtRx, szRx);
}
//Receiving data: e0 40

View file

@ -44,7 +44,7 @@
#define MAX_FRAME_LEN 264
static byte_t abtRx[MAX_FRAME_LEN];
static size_t szRxLen;
static size_t szRx;
static nfc_device_t *pnd;
static bool quiet_output = false;
static bool init_mfc_auth = false;
@ -107,13 +107,13 @@ nfc_target_emulate_tag(nfc_device_t* pnd, const nfc_target_t nt)
byte_t abtTx[MAX_FRAME_LEN];
bool loop = true;
if (!nfc_target_init (pnd, NTM_PASSIVE, nt, abtRx, &szRxLen)) {
if (!nfc_target_init (pnd, NTM_PASSIVE, nt, abtRx, &szRx)) {
nfc_perror (pnd, "nfc_target_init");
return false;
}
while ( loop ) {
loop = target_io( nt, abtRx, szRxLen, abtTx, &szTx );
loop = target_io( nt, abtRx, szRx, abtTx, &szTx );
if (szTx) {
if (!nfc_target_send_bytes(pnd, abtTx, szTx)) {
nfc_perror (pnd, "nfc_target_send_bytes");
@ -125,7 +125,7 @@ nfc_target_emulate_tag(nfc_device_t* pnd, const nfc_target_t nt)
nfc_configure (pnd, NDO_HANDLE_CRC, false);
init_mfc_auth = false;
}
if (!nfc_target_receive_bytes(pnd, abtRx, &szRxLen)) {
if (!nfc_target_receive_bytes(pnd, abtRx, &szRx)) {
nfc_perror (pnd, "nfc_target_receive_bytes");
return false;
}

View file

@ -45,7 +45,7 @@ main (int argc, const char *argv[])
bool result;
byte_t abtRx[MAX_FRAME_LEN];
size_t szRxLen;
size_t szRx;
const byte_t pncmd_diagnose_communication_line_test[] = { 0xD4, 0x00, 0x00, 0x06, 'l', 'i', 'b', 'n', 'f', 'c' };
const byte_t pncmd_diagnose_rom_test[] = { 0xD4, 0x00, 0x01 };
const byte_t pncmd_diagnose_ram_test[] = { 0xD4, 0x00, 0x02 };
@ -78,21 +78,21 @@ main (int argc, const char *argv[])
printf ("NFC device [%s] connected.\n", pnd->acName);
result = pn53x_transceive (pnd, pncmd_diagnose_communication_line_test, sizeof (pncmd_diagnose_communication_line_test), abtRx, &szRxLen);
result = pn53x_transceive (pnd, pncmd_diagnose_communication_line_test, sizeof (pncmd_diagnose_communication_line_test), abtRx, &szRx);
if (result) {
result = (memcmp (pncmd_diagnose_communication_line_test + 2, abtRx, sizeof (pncmd_diagnose_communication_line_test) - 2) == 0);
}
printf (" Communication line test: %s\n", result ? "OK" : "Failed");
result = pn53x_transceive (pnd, pncmd_diagnose_rom_test, sizeof (pncmd_diagnose_rom_test), abtRx, &szRxLen);
result = pn53x_transceive (pnd, pncmd_diagnose_rom_test, sizeof (pncmd_diagnose_rom_test), abtRx, &szRx);
if (result) {
result = ((szRxLen == 1) && (abtRx[0] == 0x00));
result = ((szRx == 1) && (abtRx[0] == 0x00));
}
printf (" ROM test: %s\n", result ? "OK" : "Failed");
result = pn53x_transceive (pnd, pncmd_diagnose_ram_test, sizeof (pncmd_diagnose_ram_test), abtRx, &szRxLen);
result = pn53x_transceive (pnd, pncmd_diagnose_ram_test, sizeof (pncmd_diagnose_ram_test), abtRx, &szRx);
if (result) {
result = ((szRxLen == 1) && (abtRx[0] == 0x00));
result = ((szRx == 1) && (abtRx[0] == 0x00));
}
printf (" RAM test: %s\n", result ? "OK" : "Failed");
}

View file

@ -63,7 +63,7 @@ sam_connection (nfc_device_t * pnd, int mode)
size_t szCmd = 0;
byte_t abtRx[MAX_FRAME_LEN];
size_t szRxLen;
size_t szRx;
pncmd_sam_config[2] = mode;
@ -82,7 +82,7 @@ sam_connection (nfc_device_t * pnd, int mode)
break;
}
if (!pn53x_transceive (pnd, pncmd_sam_config, szCmd, abtRx, &szRxLen)) {
if (!pn53x_transceive (pnd, pncmd_sam_config, szCmd, abtRx, &szRx)) {
nfc_perror(pnd, "pn53x_transceive");
ERR ("%s %d", "Unable to execute SAMConfiguration command with mode byte:", mode);
return false;
@ -195,7 +195,7 @@ main (int argc, const char *argv[])
case DUAL_CARD_MODE:
{
byte_t abtRx[MAX_FRAME_LEN];
size_t szRxLen;
size_t szRx;
nfc_target_t nt = {
.ntt = NTT_MIFARE,
@ -207,7 +207,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, NTM_NORMAL, nt, abtRx, &szRxLen)) {
if (!nfc_target_init (pnd, NTM_NORMAL, nt, abtRx, &szRx)) {
nfc_perror(pnd, "nfc_target_init");
return EXIT_FAILURE;
}

View file

@ -51,8 +51,8 @@ int main(int argc, const char* argv[])
nfc_device_t* pnd;
byte_t abtRx[MAX_FRAME_LEN];
byte_t abtTx[MAX_FRAME_LEN] = { 0xD4 };
size_t szRxLen;
size_t szTxLen;
size_t szRx;
size_t szTx;
// Try to open the NFC reader
pnd = nfc_connect(NULL);
@ -98,7 +98,7 @@ int main(int argc, const char* argv[])
free(cmd);
break;
}
szTxLen = 0;
szTx = 0;
for(int i = 0; i<MAX_FRAME_LEN-10; i++) {
int size;
byte_t byte;
@ -110,29 +110,29 @@ int main(int argc, const char* argv[])
break;
}
abtTx[i+1] = byte;
szTxLen++;
szTx++;
if (cmd[offset+1] == 0) { // if last hex was only 1 symbol
break;
}
offset += 2;
}
if ((int)szTxLen < 1) {
if ((int)szTx < 1) {
free(cmd);
continue;
}
szTxLen++;
szTx++;
printf("Tx: ");
print_hex((byte_t*)abtTx+1,szTxLen-1);
print_hex((byte_t*)abtTx+1,szTx-1);
if (!pn53x_transceive (pnd, abtTx, szTxLen, abtRx, &szRxLen)) {
if (!pn53x_transceive (pnd, abtTx, szTx, abtRx, &szRx)) {
free(cmd);
nfc_perror (pnd, "Rx");
continue;
}
printf("Rx: ");
print_hex(abtRx, szRxLen);
print_hex(abtRx, szRx);
free(cmd);
}

View file

@ -130,7 +130,7 @@ struct driver_callbacks {
/** Connect callback */
nfc_device_t *(*connect) (const nfc_device_desc_t * pndd);
/** Transceive callback */
bool (*transceive) (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLen, byte_t * pbtRx, size_t * pszRxLen);
bool (*transceive) (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx);
/** Disconnect callback */
void (*disconnect) (nfc_device_t * pnd);
};

View file

@ -81,16 +81,16 @@ extern "C" {
const nfc_dep_info_t * pndiInitiator,
nfc_target_info_t * pti);
NFC_EXPORT bool nfc_initiator_deselect_target (nfc_device_t * pnd);
NFC_EXPORT bool nfc_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLen,
byte_t * pbtRx, size_t * pszRxLen);
NFC_EXPORT bool nfc_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx,
byte_t * pbtRx, size_t * pszRx);
NFC_EXPORT bool nfc_initiator_transceive_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits,
const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits,
byte_t * pbtRxPar);
/* NFC target: act as tag (i.e. MIFARE Classic) or NFC target device. */
NFC_EXPORT bool nfc_target_init (nfc_device_t * pnd, const nfc_target_mode_t ntm, const nfc_target_t nt, byte_t * pbtRx, size_t * pszRxLen);
NFC_EXPORT bool nfc_target_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLen);
NFC_EXPORT bool nfc_target_receive_bytes (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRxLen);
NFC_EXPORT bool nfc_target_init (nfc_device_t * pnd, const nfc_target_mode_t ntm, const nfc_target_t nt, byte_t * pbtRx, size_t * pszRx);
NFC_EXPORT bool nfc_target_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx);
NFC_EXPORT bool nfc_target_receive_bytes (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRx);
NFC_EXPORT bool nfc_target_send_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits,
const byte_t * pbtTxPar);
NFC_EXPORT bool nfc_target_receive_bits (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar);

View file

@ -211,7 +211,7 @@ uart_close (const serial_port sp)
* @return 0 on success, otherwise driver error code
*/
int
uart_receive (serial_port sp, byte_t * pbtRx, size_t * pszRxLen)
uart_receive (serial_port sp, byte_t * pbtRx, size_t * pszRx)
{
int res;
int byteCount;
@ -219,7 +219,7 @@ uart_receive (serial_port sp, byte_t * pbtRx, size_t * pszRxLen)
struct timeval tv;
// Reset the output count
*pszRxLen = 0;
*pszRx = 0;
do {
// Reset file descriptor
@ -235,7 +235,7 @@ uart_receive (serial_port sp, byte_t * pbtRx, size_t * pszRxLen)
}
// Read time-out
if (res == 0) {
if (*pszRxLen == 0) {
if (*pszRx == 0) {
// Error, we received no data
DBG ("%s", "RX time-out, buffer empty.");
return DETIMEOUT;
@ -250,14 +250,14 @@ uart_receive (serial_port sp, byte_t * pbtRx, size_t * pszRxLen)
return DEIO;
}
// There is something available, read the data
res = read (((serial_port_unix *) sp)->fd, pbtRx + (*pszRxLen), byteCount);
res = read (((serial_port_unix *) sp)->fd, pbtRx + (*pszRx), byteCount);
// Stop if the OS has some troubles reading the data
if (res <= 0) {
return DEIO;
}
*pszRxLen += res;
*pszRx += res;
} while (byteCount);
@ -270,14 +270,14 @@ uart_receive (serial_port sp, byte_t * pbtRx, size_t * pszRxLen)
* @return 0 on success, otherwise a driver error is returned
*/
int
uart_send (serial_port sp, const byte_t * pbtTx, const size_t szTxLen)
uart_send (serial_port sp, const byte_t * pbtTx, const size_t szTx)
{
int32_t res;
size_t szPos = 0;
fd_set rfds;
struct timeval tv;
while (szPos < szTxLen) {
while (szPos < szTx) {
// Reset file descriptor
FD_ZERO (&rfds);
FD_SET (((serial_port_unix *) sp)->fd, &rfds);
@ -295,7 +295,7 @@ uart_send (serial_port sp, const byte_t * pbtTx, const size_t szTxLen)
return DETIMEOUT;
}
// Send away the bytes
res = write (((serial_port_unix *) sp)->fd, pbtTx + szPos, szTxLen - szPos);
res = write (((serial_port_unix *) sp)->fd, pbtTx + szPos, szTx - szPos);
// Stop if the OS has some troubles sending the data
if (res <= 0) {
@ -410,21 +410,21 @@ uart_get_speed (const serial_port sp)
}
int
uart_receive (serial_port sp, byte_t * pbtRx, size_t * pszRxLen)
uart_receive (serial_port sp, byte_t * pbtRx, size_t * pszRx)
{
if (!ReadFile (((serial_port_windows *) sp)->hPort, pbtRx, *pszRxLen, (LPDWORD) pszRxLen, NULL)) {
if (!ReadFile (((serial_port_windows *) sp)->hPort, pbtRx, *pszRx, (LPDWORD) pszRx, NULL)) {
return DEIO;
}
if (!*pszRxLen)
if (!*pszRx)
return DEIO;
return 0;
}
int
uart_send (serial_port sp, const byte_t * pbtTx, const size_t szTxLen)
uart_send (serial_port sp, const byte_t * pbtTx, const size_t szTx)
{
DWORD dwTxLen = 0;
if (!WriteFile (((serial_port_windows *) sp)->hPort, pbtTx, szTxLen, &dwTxLen, NULL)) {
if (!WriteFile (((serial_port_windows *) sp)->hPort, pbtTx, szTx, &dwTxLen, NULL)) {
return DEIO;
}
if (!dwTxLen)

View file

@ -84,7 +84,7 @@ void uart_close (const serial_port sp);
void uart_set_speed (serial_port sp, const uint32_t uiPortSpeed);
uint32_t uart_get_speed (const serial_port sp);
int uart_receive (serial_port sp, byte_t * pbtRx, size_t * pszRxLen);
int uart_send (serial_port sp, const byte_t * pbtTx, const size_t szTxLen);
int uart_receive (serial_port sp, byte_t * pbtRx, size_t * pszRx);
int uart_send (serial_port sp, const byte_t * pbtTx, const size_t szTx);
#endif // __NFC_BUS_UART_H__

View file

@ -144,20 +144,20 @@ pn53x_transceive_check_error_frame_callback (nfc_device_t * pnd, const byte_t *
}
bool
pn53x_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLen, byte_t * pbtRx, size_t * pszRxLen)
pn53x_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx)
{
byte_t abtRx[MAX_FRAME_LEN];
size_t szRxLen;
size_t szRx;
// Check if receiving buffers are available, if not, replace them
if (!pszRxLen || !pbtRx) {
if (!pszRx || !pbtRx) {
pbtRx = abtRx;
pszRxLen = &szRxLen;
pszRx = &szRx;
}
*pszRxLen = MAX_FRAME_LEN;
*pszRx = MAX_FRAME_LEN;
// Call the tranceive callback function of the current device
if (!pnd->pdc->transceive (pnd, pbtTx, szTxLen, pbtRx, pszRxLen))
if (!pnd->pdc->transceive (pnd, pbtTx, szTx, pbtRx, pszRx))
return false;
// XXX Should we put all these numbers behind a human-readable #define ?
switch (pbtTx[1]) {
@ -497,7 +497,7 @@ pn53x_InListPassiveTarget (nfc_device_t * pnd,
const byte_t * pbtInitiatorData, const size_t szInitiatorDataLen,
byte_t * pbtTargetsData, size_t * pszTargetsData)
{
size_t szRxLen;
size_t szRx;
byte_t abtCmd[sizeof (pncmd_initiator_list_passive)];
memcpy (abtCmd, pncmd_initiator_list_passive, sizeof (pncmd_initiator_list_passive));
@ -538,9 +538,9 @@ pn53x_InListPassiveTarget (nfc_device_t * pnd,
memcpy (abtCmd + 4, pbtInitiatorData, szInitiatorDataLen);
// Try to find a tag, call the tranceive callback function of the current device
szRxLen = MAX_FRAME_LEN;
if (pn53x_transceive (pnd, abtCmd, 4 + szInitiatorDataLen, pbtTargetsData, &szRxLen)) {
*pszTargetsData = szRxLen;
szRx = MAX_FRAME_LEN;
if (pn53x_transceive (pnd, abtCmd, 4 + szInitiatorDataLen, pbtTargetsData, &szRx)) {
*pszTargetsData = szRx;
return true;
} else {
return false;
@ -574,7 +574,7 @@ pn53x_InAutoPoll (nfc_device_t * pnd,
{
size_t szTxInAutoPoll,
n,
szRxLen;
szRx;
byte_t abtRx[MAX_FRAME_LEN];
bool res;
byte_t *pbtTxInAutoPoll;
@ -595,10 +595,10 @@ pn53x_InAutoPoll (nfc_device_t * pnd,
pbtTxInAutoPoll[4 + n] = pnttTargetTypes[n];
}
szRxLen = MAX_FRAME_LEN;
res = pnd->pdc->transceive (pnd, pbtTxInAutoPoll, szTxInAutoPoll, abtRx, &szRxLen);
szRx = MAX_FRAME_LEN;
res = pnd->pdc->transceive (pnd, pbtTxInAutoPoll, szTxInAutoPoll, abtRx, &szRx);
if ((szRxLen == 0) || (res == false)) {
if ((szRx == 0) || (res == false)) {
return false;
} else {
*pszTargetFound = abtRx[0];
@ -850,7 +850,7 @@ pn53x_InJumpForDEP (nfc_device_t * pnd, const nfc_modulation_t nmInitModulation,
nfc_target_info_t * pnti)
{
byte_t abtRx[MAX_FRAME_LEN];
size_t szRxLen;
size_t szRx;
size_t offset;
byte_t abtCmd[sizeof (pncmd_initiator_jump_for_dep)];
@ -881,7 +881,7 @@ pn53x_InJumpForDEP (nfc_device_t * pnd, const nfc_modulation_t nmInitModulation,
offset += szGB;
}
// Try to find a target, call the transceive callback function of the current device
if (!pn53x_transceive (pnd, abtCmd, 5 + szPassiveInitiatorData + 10 + szGB, abtRx, &szRxLen))
if (!pn53x_transceive (pnd, abtCmd, 5 + szPassiveInitiatorData + 10 + szGB, abtRx, &szRx))
return false;
// Make sure one target has been found, the PN53X returns 0x00 if none was available
@ -896,8 +896,8 @@ pn53x_InJumpForDEP (nfc_device_t * pnd, const nfc_modulation_t nmInitModulation,
pnti->ndi.btBR = abtRx[14];
pnti->ndi.btTO = abtRx[15];
pnti->ndi.btPP = abtRx[16];
if(szRxLen > 17) {
pnti->ndi.szGB = szRxLen - 17;
if(szRx > 17) {
pnti->ndi.szGB = szRx - 17;
memcpy (pnti->ndi.abtGB, abtRx + 17, pnti->ndi.szGB);
} else {
pnti->ndi.szGB = 0;
@ -911,7 +911,7 @@ pn53x_initiator_transceive_bits (nfc_device_t * pnd, const byte_t * pbtTx, const
const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar)
{
byte_t abtRx[MAX_FRAME_LEN];
size_t szRxLen;
size_t szRx;
size_t szFrameBits = 0;
size_t szFrameBytes = 0;
uint8_t ui8rcc;
@ -944,7 +944,7 @@ pn53x_initiator_transceive_bits (nfc_device_t * pnd, const byte_t * pbtTx, const
// Send the frame to the PN53X chip and get the answer
// We have to give the amount of bytes + (the two command bytes 0xD4, 0x42)
if (!pn53x_transceive (pnd, abtCmd, szFrameBytes + 2, abtRx, &szRxLen))
if (!pn53x_transceive (pnd, abtCmd, szFrameBytes + 2, abtRx, &szRx))
return false;
// Get the last bit-count that is stored in the received byte
@ -953,7 +953,7 @@ pn53x_initiator_transceive_bits (nfc_device_t * pnd, const byte_t * pbtTx, const
ui8Bits = ui8rcc & SYMBOL_RX_LAST_BITS;
// Recover the real frame length in bits
szFrameBits = ((szRxLen - 1 - ((ui8Bits == 0) ? 0 : 1)) * 8) + ui8Bits;
szFrameBits = ((szRx - 1 - ((ui8Bits == 0) ? 0 : 1)) * 8) + ui8Bits;
// Ignore the status byte from the PN53X here, it was checked earlier in pn53x_transceive()
// Check if we should recover the parity bits ourself
@ -964,7 +964,7 @@ pn53x_initiator_transceive_bits (nfc_device_t * pnd, const byte_t * pbtTx, const
// Save the received bits
*pszRxBits = szFrameBits;
// Copy the received bytes
memcpy (pbtRx, abtRx + 1, szRxLen - 1);
memcpy (pbtRx, abtRx + 1, szRx - 1);
}
// Everything went successful
@ -972,12 +972,12 @@ pn53x_initiator_transceive_bits (nfc_device_t * pnd, const byte_t * pbtTx, const
}
bool
pn53x_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLen, byte_t * pbtRx,
size_t * pszRxLen)
pn53x_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx,
size_t * pszRx)
{
byte_t abtRx[MAX_FRAME_LEN];
size_t szExtraTxLen,
szRxLen;
szRx;
byte_t abtCmd[sizeof (pncmd_initiator_exchange_raw_data)];
// We can not just send bytes without parity if while the PN53X expects we handled them
@ -988,11 +988,11 @@ pn53x_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, cons
if (pnd->bEasyFraming) {
memcpy (abtCmd, pncmd_initiator_exchange_data, sizeof (pncmd_initiator_exchange_data));
abtCmd[2] = 1; /* target number */
memcpy (abtCmd + 3, pbtTx, szTxLen);
memcpy (abtCmd + 3, pbtTx, szTx);
szExtraTxLen = 3;
} else {
memcpy (abtCmd, pncmd_initiator_exchange_raw_data, sizeof (pncmd_initiator_exchange_raw_data));
memcpy (abtCmd + 2, pbtTx, szTxLen);
memcpy (abtCmd + 2, pbtTx, szTx);
szExtraTxLen = 2;
}
@ -1002,21 +1002,21 @@ pn53x_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, cons
// Send the frame to the PN53X chip and get the answer
// We have to give the amount of bytes + (the two command bytes 0xD4, 0x42)
if (!pn53x_transceive (pnd, abtCmd, szTxLen + szExtraTxLen, abtRx, &szRxLen))
if (!pn53x_transceive (pnd, abtCmd, szTx + szExtraTxLen, abtRx, &szRx))
return false;
// Save the received byte count
*pszRxLen = szRxLen - 1;
*pszRx = szRx - 1;
// Copy the received bytes
memcpy (pbtRx, abtRx + 1, *pszRxLen);
memcpy (pbtRx, abtRx + 1, *pszRx);
// Everything went successful
return true;
}
bool
pn53x_target_init (nfc_device_t * pnd, const nfc_target_mode_t ntm, const nfc_target_t nt, byte_t * pbtRx, size_t * pszRxLen)
pn53x_target_init (nfc_device_t * pnd, const nfc_target_mode_t ntm, const nfc_target_t nt, byte_t * pbtRx, size_t * pszRx)
{
// Save the current configuration settings
bool bCrc = pnd->bCrc;
@ -1109,7 +1109,7 @@ pn53x_target_init (nfc_device_t * pnd, const nfc_target_mode_t ntm, const nfc_ta
break;
}
if(!pn53x_TgInitAsTarget(pnd, ntm, pbtMifareParams, pbtFeliCaParams, pbtNFCID3t, pbtGB, szGB, pbtRx, pszRxLen, NULL)) {
if(!pn53x_TgInitAsTarget(pnd, ntm, pbtMifareParams, pbtFeliCaParams, pbtNFCID3t, pbtGB, szGB, pbtRx, pszRx, NULL)) {
return false;
}
@ -1127,10 +1127,10 @@ pn53x_TgInitAsTarget (nfc_device_t * pnd, nfc_target_mode_t ntm,
const byte_t * pbtMifareParams,
const byte_t * pbtFeliCaParams,
const byte_t * pbtNFCID3t, const byte_t * pbtGB, const size_t szGB,
byte_t * pbtRx, size_t * pszRxLen, byte_t * pbtModeByte)
byte_t * pbtRx, size_t * pszRx, byte_t * pbtModeByte)
{
byte_t abtRx[MAX_FRAME_LEN];
size_t szRxLen;
size_t szRx;
byte_t abtCmd[sizeof (pncmd_target_init) + 48]; // 47 bytes max. for General Bytes and 1 for GB lenght
size_t szOptionalBytes = 0;
@ -1167,8 +1167,8 @@ pn53x_TgInitAsTarget (nfc_device_t * pnd, nfc_target_mode_t ntm,
// TODO Handle Tk (Historical bytes) length (only available on PN532, PN533)
// Request the initialization as a target
szRxLen = MAX_FRAME_LEN;
if (!pn53x_transceive (pnd, abtCmd, sizeof (pncmd_target_init) + szOptionalBytes, abtRx, &szRxLen))
szRx = MAX_FRAME_LEN;
if (!pn53x_transceive (pnd, abtCmd, sizeof (pncmd_target_init) + szOptionalBytes, abtRx, &szRx))
return false;
// Note: the first byte is skip:
@ -1178,9 +1178,9 @@ pn53x_TgInitAsTarget (nfc_device_t * pnd, nfc_target_mode_t ntm,
}
// Save the received byte count
*pszRxLen = szRxLen - 1;
*pszRx = szRx - 1;
// Copy the received bytes
memcpy (pbtRx, abtRx + 1, *pszRxLen);
memcpy (pbtRx, abtRx + 1, *pszRx);
return true;
}
@ -1189,13 +1189,13 @@ bool
pn53x_target_receive_bits (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar)
{
byte_t abtRx[MAX_FRAME_LEN];
size_t szRxLen;
size_t szRx;
size_t szFrameBits;
uint8_t ui8rcc;
uint8_t ui8Bits;
// Try to gather a received frame from the reader
if (!pn53x_transceive (pnd, pncmd_target_receive, 2, abtRx, &szRxLen))
if (!pn53x_transceive (pnd, pncmd_target_receive, 2, abtRx, &szRx))
return false;
// Get the last bit-count that is stored in the received byte
@ -1204,7 +1204,7 @@ pn53x_target_receive_bits (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRxBit
ui8Bits = ui8rcc & SYMBOL_RX_LAST_BITS;
// Recover the real frame length in bits
szFrameBits = ((szRxLen - 1 - ((ui8Bits == 0) ? 0 : 1)) * 8) + ui8Bits;
szFrameBits = ((szRx - 1 - ((ui8Bits == 0) ? 0 : 1)) * 8) + ui8Bits;
// Ignore the status byte from the PN53X here, it was checked earlier in pn53x_transceive()
// Check if we should recover the parity bits ourself
@ -1215,18 +1215,18 @@ pn53x_target_receive_bits (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRxBit
// Save the received bits
*pszRxBits = szFrameBits;
// Copy the received bytes
memcpy (pbtRx, abtRx + 1, szRxLen - 1);
memcpy (pbtRx, abtRx + 1, szRx - 1);
}
// Everyting seems ok, return true
return true;
}
bool
pn53x_target_receive_bytes (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRxLen)
pn53x_target_receive_bytes (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRx)
{
byte_t const *pbtTx;
byte_t abtRx[MAX_FRAME_LEN];
size_t szRxLen;
size_t szRx;
if (pnd->bEasyFraming) {
pbtTx = pncmd_target_get_data;
@ -1235,14 +1235,14 @@ pn53x_target_receive_bytes (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRxLe
}
// Try to gather a received frame from the reader
if (!pn53x_transceive (pnd, pbtTx, 2, abtRx, &szRxLen))
if (!pn53x_transceive (pnd, pbtTx, 2, abtRx, &szRx))
return false;
// Save the received byte count
*pszRxLen = szRxLen - 1;
*pszRx = szRx - 1;
// Copy the received bytes
memcpy (pbtRx, abtRx + 1, *pszRxLen);
memcpy (pbtRx, abtRx + 1, *pszRx);
// Everyting seems ok, return true
return true;
@ -1289,7 +1289,7 @@ pn53x_target_send_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t s
}
bool
pn53x_target_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLen)
pn53x_target_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx)
{
byte_t abtCmd[MAX (sizeof (pncmd_target_send), sizeof (pncmd_target_set_data))];
@ -1305,10 +1305,10 @@ pn53x_target_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t
}
// Copy the data into the command frame
memcpy (abtCmd + 2, pbtTx, szTxLen);
memcpy (abtCmd + 2, pbtTx, szTx);
// Try to send the bits to the reader
if (!pn53x_transceive (pnd, abtCmd, szTxLen + 2, NULL, NULL))
if (!pn53x_transceive (pnd, abtCmd, szTx + 2, NULL, NULL))
return false;
// Everyting seems ok, return true

View file

@ -95,8 +95,8 @@ bool pn53x_transceive_check_ack_frame_callback (nfc_device_t * pnd, const byt
const size_t szRxFrameLen);
bool pn53x_transceive_check_error_frame_callback (nfc_device_t * pnd, const byte_t * pbtRxFrame,
const size_t szRxFrameLen);
bool pn53x_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLen, byte_t * pbtRx,
size_t * pszRxLen);
bool pn53x_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx,
size_t * pszRx);
bool pn53x_get_reg (nfc_device_t * pnd, uint16_t ui16Reg, uint8_t * ui8Value);
bool pn53x_set_reg (nfc_device_t * pnd, uint16_t ui16Reg, uint8_t ui8SymbolMask, uint8_t ui8Value);
bool pn53x_set_parameter (nfc_device_t * pnd, const uint8_t ui8Value, const bool bEnable);
@ -118,15 +118,15 @@ bool pn53x_initiator_select_dep_target (nfc_device_t * pnd, const nfc_modulat
bool pn53x_initiator_transceive_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits,
const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits,
byte_t * pbtRxPar);
bool pn53x_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLen,
byte_t * pbtRx, size_t * pszRxLen);
bool pn53x_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx,
byte_t * pbtRx, size_t * pszRx);
// NFC device as Target functions
bool pn53x_target_init (nfc_device_t * pnd, const nfc_target_mode_t ntm, const nfc_target_t nt, byte_t * pbtRx, size_t * pszRxLen);
bool pn53x_target_init (nfc_device_t * pnd, const nfc_target_mode_t ntm, const nfc_target_t nt, byte_t * pbtRx, size_t * pszRx);
bool pn53x_target_receive_bits (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRxBits, byte_t * pbtRxPar);
bool pn53x_target_receive_bytes (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRxLen);
bool pn53x_target_receive_bytes (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRx);
bool pn53x_target_send_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits,
const byte_t * pbtTxPar);
bool pn53x_target_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLen);
bool pn53x_target_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx);
// Error handling functions
const char *pn53x_strerror (const nfc_device_t * pnd);
static const struct chip_callbacks pn53x_callbacks_list = {
@ -152,7 +152,7 @@ bool pn53x_TgInitAsTarget (nfc_device_t * pnd, nfc_target_mode_t ntm,
const byte_t * pbtMifareParams,
const byte_t * pbtFeliCaParams,
const byte_t * pbtNFCID3t, const byte_t * pbtGB, const size_t szGB,
byte_t * pbtRx, size_t * pszRxLen, byte_t * pbtModeByte);
byte_t * pbtRx, size_t * pszRx, byte_t * pbtModeByte);
#endif // __NFC_CHIPS_PN53X_H__

View file

@ -258,7 +258,7 @@ acr122_disconnect (nfc_device_t * pnd)
}
bool
acr122_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLen, byte_t * pbtRx, size_t * pszRxLen)
acr122_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx)
{
byte_t abtRxCmd[5] = { 0xFF, 0xC0, 0x00, 0x00 };
size_t szRxCmdLen = sizeof (abtRxCmd);
@ -269,29 +269,29 @@ acr122_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLe
// FIXME: Should be handled by the library.
// Make sure the command does not overflow the send buffer
if (szTxLen > ACR122_COMMAND_LEN) {
if (szTx > ACR122_COMMAND_LEN) {
pnd->iLastError = DEIO;
return false;
}
// Store the length of the command we are going to send
abtTxBuf[4] = szTxLen;
abtTxBuf[4] = szTx;
// Prepare and transmit the send buffer
memcpy (abtTxBuf + 5, pbtTx, szTxLen);
memcpy (abtTxBuf + 5, pbtTx, szTx);
szRxBufLen = sizeof (abtRxBuf);
#ifdef DEBUG
PRINT_HEX ("TX", abtTxBuf, szTxLen + 5);
PRINT_HEX ("TX", abtTxBuf, szTx + 5);
#endif
if (pas->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED) {
if (SCardControl
(pas->hCard, IOCTL_CCID_ESCAPE_SCARD_CTL_CODE, abtTxBuf, szTxLen + 5, abtRxBuf, szRxBufLen,
(pas->hCard, IOCTL_CCID_ESCAPE_SCARD_CTL_CODE, abtTxBuf, szTx + 5, abtRxBuf, szRxBufLen,
(void *) &szRxBufLen) != SCARD_S_SUCCESS) {
pnd->iLastError = DEIO;
return false;
}
} else {
if (SCardTransmit (pas->hCard, &(pas->ioCard), abtTxBuf, szTxLen + 5, NULL, abtRxBuf, (void *) &szRxBufLen) !=
if (SCardTransmit (pas->hCard, &(pas->ioCard), abtTxBuf, szTx + 5, NULL, abtRxBuf, (void *) &szRxBufLen) !=
SCARD_S_SUCCESS) {
pnd->iLastError = DEIO;
return false;
@ -323,17 +323,17 @@ acr122_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLe
#endif
// When the answer should be ignored, just return a succesful result
if (pbtRx == NULL || pszRxLen == NULL)
if (pbtRx == NULL || pszRx == NULL)
return true;
// Make sure we have an emulated answer that fits the return buffer
if (szRxBufLen < 4 || (szRxBufLen - 4) > *pszRxLen) {
if (szRxBufLen < 4 || (szRxBufLen - 4) > *pszRx) {
pnd->iLastError = DEIO;
return false;
}
// Wipe out the 4 APDU emulation bytes: D5 4B .. .. .. 90 00
*pszRxLen = ((size_t) szRxBufLen) - 4;
memcpy (pbtRx, abtRxBuf + 2, *pszRxLen);
*pszRx = ((size_t) szRxBufLen) - 4;
memcpy (pbtRx, abtRxBuf + 2, *pszRx);
// Transmission went successful
return true;

View file

@ -40,8 +40,8 @@ nfc_device_t *acr122_connect (const nfc_device_desc_t * pndd);
void acr122_disconnect (nfc_device_t * pnd);
// Callback function used by libnfc to transmit commands to the PN53X chip
bool acr122_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLen, byte_t * pbtRx,
size_t * pszRxLen);
bool acr122_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx,
size_t * pszRx);
// Various additional features this device supports
char *acr122_firmware (const nfc_device_spec_t nds);

View file

@ -206,7 +206,7 @@ arygon_disconnect (nfc_device_t * pnd)
}
bool
arygon_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLen, byte_t * pbtRx, size_t * pszRxLen)
arygon_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx)
{
byte_t abtTxBuf[BUFFER_LENGTH] = { DEV_ARYGON_PROTOCOL_TAMA, 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff"
byte_t abtRxBuf[BUFFER_LENGTH];
@ -215,25 +215,25 @@ arygon_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLe
int res;
// Packet length = data length (len) + checksum (1) + end of stream marker (1)
abtTxBuf[4] = szTxLen;
abtTxBuf[4] = szTx;
// Packet length checksum
abtTxBuf[5] = BUFFER_LENGTH - abtTxBuf[4];
// Copy the PN53X command into the packet buffer
memmove (abtTxBuf + 6, pbtTx, szTxLen);
memmove (abtTxBuf + 6, pbtTx, szTx);
// Calculate data payload checksum
abtTxBuf[szTxLen + 6] = 0;
for (szPos = 0; szPos < szTxLen; szPos++) {
abtTxBuf[szTxLen + 6] -= abtTxBuf[szPos + 6];
abtTxBuf[szTx + 6] = 0;
for (szPos = 0; szPos < szTx; szPos++) {
abtTxBuf[szTx + 6] -= abtTxBuf[szPos + 6];
}
// End of stream marker
abtTxBuf[szTxLen + 7] = 0;
abtTxBuf[szTx + 7] = 0;
#ifdef DEBUG
PRINT_HEX ("TX", abtTxBuf, szTxLen + 8);
PRINT_HEX ("TX", abtTxBuf, szTx + 8);
#endif
res = uart_send ((serial_port) pnd->nds, abtTxBuf, szTxLen + 8);
res = uart_send ((serial_port) pnd->nds, abtTxBuf, szTx + 8);
if (res != 0) {
ERR ("%s", "Unable to transmit data. (TX)");
pnd->iLastError = res;
@ -274,7 +274,7 @@ arygon_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLe
return false;
// When the answer should be ignored, just return a successful result
if (pbtRx == NULL || pszRxLen == NULL)
if (pbtRx == NULL || pszRx == NULL)
return true;
// Only succeed when the result is at least 00 00 FF xx Fx Dx xx .. .. .. xx 00 (x = variable)
@ -282,8 +282,8 @@ arygon_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLe
return false;
// Remove the preceding and appending bytes 00 00 ff 00 ff 00 00 00 FF xx Fx .. .. .. xx 00 (x = variable)
*pszRxLen = szRxBufLen - 9;
memcpy (pbtRx, abtRxBuf + 7, *pszRxLen);
*pszRx = szRxBufLen - 9;
memcpy (pbtRx, abtRxBuf + 7, *pszRx);
return true;
}
@ -301,7 +301,7 @@ bool
arygon_check_communication (const nfc_device_spec_t nds)
{
byte_t abtRx[BUFFER_LENGTH];
size_t szRxLen;
size_t szRx;
const byte_t attempted_result[] =
{ 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x09, 0xf7, 0xd5, 0x01, 0x00, 'l', 'i', 'b', 'n', 'f', 'c',
0xbc, 0x00 };
@ -321,13 +321,13 @@ arygon_check_communication (const nfc_device_spec_t nds)
return false;
}
res = uart_receive ((serial_port) nds, abtRx, &szRxLen);
res = uart_receive ((serial_port) nds, abtRx, &szRx);
if (res != 0) {
ERR ("%s", "Unable to receive data. (RX)");
return false;
}
#ifdef DEBUG
PRINT_HEX ("RX", abtRx, szRxLen);
PRINT_HEX ("RX", abtRx, szRx);
#endif
if (0 != memcmp (abtRx, attempted_result, sizeof (attempted_result))) {

View file

@ -36,7 +36,7 @@ nfc_device_t *arygon_connect (const nfc_device_desc_t * pndd);
void arygon_disconnect (nfc_device_t * pnd);
// Callback function used by libnfc to transmit commands to the PN53X chip
bool arygon_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLen, byte_t * pbtRx,
size_t * pszRxLen);
bool arygon_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx,
size_t * pszRx);
#endif // ! __NFC_DRIVER_ARYGON_H__

View file

@ -186,8 +186,8 @@ pn532_uart_disconnect (nfc_device_t * pnd)
}
bool
pn532_uart_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLen, byte_t * pbtRx,
size_t * pszRxLen)
pn532_uart_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx,
size_t * pszRx)
{
byte_t abtTxBuf[BUFFER_LENGTH] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff"
byte_t abtRxBuf[BUFFER_LENGTH];
@ -196,25 +196,25 @@ pn532_uart_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t sz
int res;
// Packet length = data length (len) + checksum (1) + end of stream marker (1)
abtTxBuf[3] = szTxLen;
abtTxBuf[3] = szTx;
// Packet length checksum
abtTxBuf[4] = BUFFER_LENGTH - abtTxBuf[3];
// Copy the PN53X command into the packet buffer
memmove (abtTxBuf + 5, pbtTx, szTxLen);
memmove (abtTxBuf + 5, pbtTx, szTx);
// Calculate data payload checksum
abtTxBuf[szTxLen + 5] = 0;
for (szPos = 0; szPos < szTxLen; szPos++) {
abtTxBuf[szTxLen + 5] -= abtTxBuf[szPos + 5];
abtTxBuf[szTx + 5] = 0;
for (szPos = 0; szPos < szTx; szPos++) {
abtTxBuf[szTx + 5] -= abtTxBuf[szPos + 5];
}
// End of stream marker
abtTxBuf[szTxLen + 6] = 0;
abtTxBuf[szTx + 6] = 0;
#ifdef DEBUG
PRINT_HEX ("TX", abtTxBuf, szTxLen + 7);
PRINT_HEX ("TX", abtTxBuf, szTx + 7);
#endif
res = uart_send ((serial_port) pnd->nds, abtTxBuf, szTxLen + 7);
res = uart_send ((serial_port) pnd->nds, abtTxBuf, szTx + 7);
if (res != 0) {
ERR ("%s", "Unable to transmit data. (TX)");
pnd->iLastError = res;
@ -262,7 +262,7 @@ pn532_uart_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t sz
return false;
// When the answer should be ignored, just return a successful result
if (pbtRx == NULL || pszRxLen == NULL)
if (pbtRx == NULL || pszRx == NULL)
return true;
// Only succeed when the result is at least 00 00 FF xx Fx Dx xx .. .. .. xx 00 (x = variable)
@ -271,8 +271,8 @@ pn532_uart_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t sz
return false;
}
// Remove the preceding and appending bytes 00 00 ff 00 ff 00 00 00 FF xx Fx .. .. .. xx 00 (x = variable)
*pszRxLen = szRxBufLen - 9;
memcpy (pbtRx, abtRxBuf + 7, *pszRxLen);
*pszRx = szRxBufLen - 9;
memcpy (pbtRx, abtRxBuf + 7, *pszRx);
return true;
}
@ -290,7 +290,7 @@ void
pn532_uart_wakeup (const nfc_device_spec_t nds)
{
byte_t abtRx[BUFFER_LENGTH];
size_t szRxLen;
size_t szRx;
/** PN532C106 wakeup. */
/** High Speed Unit (HSU) wake up consist to send 0x55 and wait a "long" delay for PN532 being wakeup. */
/** After the preamble we request the PN532C106 chip to switch to "normal" mode (SAM is not used) */
@ -301,9 +301,9 @@ pn532_uart_wakeup (const nfc_device_spec_t nds)
PRINT_HEX ("TX", pncmd_pn532c106_wakeup_preamble, sizeof (pncmd_pn532c106_wakeup_preamble));
#endif
uart_send ((serial_port) nds, pncmd_pn532c106_wakeup_preamble, sizeof (pncmd_pn532c106_wakeup_preamble));
if (0 == uart_receive ((serial_port) nds, abtRx, &szRxLen)) {
if (0 == uart_receive ((serial_port) nds, abtRx, &szRx)) {
#ifdef DEBUG
PRINT_HEX ("RX", abtRx, szRxLen);
PRINT_HEX ("RX", abtRx, szRx);
#endif
}
}
@ -312,7 +312,7 @@ bool
pn532_uart_check_communication (const nfc_device_spec_t nds, bool * success)
{
byte_t abtRx[BUFFER_LENGTH];
size_t szRxLen;
size_t szRx;
const byte_t attempted_result[] =
{ 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x09, 0xf7, 0xD5, 0x01, 0x00, 'l', 'i', 'b', 'n', 'f', 'c',
0xbc, 0x00 };
@ -333,13 +333,13 @@ pn532_uart_check_communication (const nfc_device_spec_t nds, bool * success)
return false;
}
res = uart_receive ((serial_port) nds, abtRx, &szRxLen);
res = uart_receive ((serial_port) nds, abtRx, &szRx);
if (res != 0) {
ERR ("%s", "Unable to receive data. (RX)");
return false;
}
#ifdef DEBUG
PRINT_HEX ("RX", abtRx, szRxLen);
PRINT_HEX ("RX", abtRx, szRx);
#endif
if (0 == memcmp (abtRx, attempted_result, sizeof (attempted_result)))

View file

@ -36,7 +36,7 @@ nfc_device_t *pn532_uart_connect (const nfc_device_desc_t * pndd);
void pn532_uart_disconnect (nfc_device_t * pnd);
// Callback function used by libnfc to transmit commands to the PN53X chip
bool pn532_uart_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLen, byte_t * pbtRx,
size_t * pszRxLen);
bool pn532_uart_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx,
size_t * pszRx);
#endif // ! __NFC_DRIVER_PN532_UART_H__

View file

@ -279,7 +279,7 @@ pn53x_usb_disconnect (nfc_device_t * pnd)
}
bool
pn53x_usb_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLen, byte_t * pbtRx, size_t * pszRxLen)
pn53x_usb_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx, size_t * pszRx)
{
size_t uiPos = 0;
int ret = 0;
@ -290,26 +290,26 @@ pn53x_usb_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szT
uint8_t ack_frame[] = { 0x00, 0x00, 0xff, 0x00, 0xff, 0x00 };
// Packet length = data length (len) + checksum (1) + end of stream marker (1)
abtTx[3] = szTxLen;
abtTx[3] = szTx;
// Packet length checksum
abtTx[4] = 0x0100 - abtTx[3];
// Copy the PN53X command into the packet abtTx
memmove (abtTx + 5, pbtTx, szTxLen);
memmove (abtTx + 5, pbtTx, szTx);
// Calculate data payload checksum
abtTx[szTxLen + 5] = 0;
for (uiPos = 0; uiPos < szTxLen; uiPos++) {
abtTx[szTxLen + 5] -= abtTx[uiPos + 5];
abtTx[szTx + 5] = 0;
for (uiPos = 0; uiPos < szTx; uiPos++) {
abtTx[szTx + 5] -= abtTx[uiPos + 5];
}
// End of stream marker
abtTx[szTxLen + 6] = 0;
abtTx[szTx + 6] = 0;
#ifdef DEBUG
PRINT_HEX ("TX", abtTx, szTxLen + 7);
PRINT_HEX ("TX", abtTx, szTx + 7);
#endif
ret = usb_bulk_write (pus->pudh, pus->uiEndPointOut, (char *) abtTx, szTxLen + 7, USB_TIMEOUT);
ret = usb_bulk_write (pus->pudh, pus->uiEndPointOut, (char *) abtTx, szTx + 7, USB_TIMEOUT);
// XXX This little hack is a well know problem of libusb, see http://www.libusb.org/ticket/6 for more details
if ((ret % pus->wMaxPacketSize) == 0) {
usb_bulk_write (pus->pudh, pus->uiEndPointOut, "\0", 0, USB_TIMEOUT);
@ -353,7 +353,7 @@ pn53x_usb_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szT
return false;
// When the answer should be ignored, just return a succesful result
if (pbtRx == NULL || pszRxLen == NULL)
if (pbtRx == NULL || pszRx == NULL)
return true;
// Only succeed when the result is at least 00 00 FF xx Fx Dx xx .. .. .. xx 00 (x = variable)
@ -363,9 +363,9 @@ pn53x_usb_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szT
return false;
}
// Remove the preceding and appending bytes 00 00 FF xx Fx .. .. .. xx 00 (x = variable)
*pszRxLen = ret - 7 - 2;
*pszRx = ret - 7 - 2;
memcpy (pbtRx, abtRx + 7, *pszRxLen);
memcpy (pbtRx, abtRx + 7, *pszRx);
return true;
}

View file

@ -38,7 +38,7 @@ typedef struct {
nfc_device_t *pn53x_usb_connect (const nfc_device_desc_t * pndd, const char *target_name, int target_chip);
void get_end_points (struct usb_device *dev, usb_spec_t * pus);
void pn53x_usb_disconnect (nfc_device_t * pnd);
bool pn53x_usb_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLen, byte_t * pbtRx,
size_t * pszRxLen);
bool pn53x_usb_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx,
size_t * pszRx);
bool pn53x_usb_list_devices (nfc_device_desc_t pnddDevices[], size_t szDevices, size_t * pszDeviceFound,
usb_candidate_t candidates[], int num_candidates, char *target_name);

View file

@ -510,12 +510,12 @@ nfc_initiator_deselect_target (nfc_device_t * pnd)
* @warning The configuration option \a NDO_HANDLE_PARITY must be set to \c true (the default value).
*/
bool
nfc_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLen, byte_t * pbtRx,
size_t * pszRxLen)
nfc_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, byte_t * pbtRx,
size_t * pszRx)
{
pnd->iLastError = 0;
return pn53x_initiator_transceive_bytes (pnd, pbtTx, szTxLen, pbtRx, pszRxLen);
return pn53x_initiator_transceive_bytes (pnd, pbtTx, szTx, pbtRx, pszRx);
}
/**
@ -548,18 +548,18 @@ nfc_initiator_transceive_bits (nfc_device_t * pnd, const byte_t * pbtTx, const s
* @param pnd \a nfc_device_t struct pointer that represent currently used device
* @param ntm the target mode that you want to emulate
* @param[out] pbtRx pointer to Rx buffer
* @param[out] pszRxLen received byte count
* @param[out] pszRx received byte count
*
* This function initialize NFC device in \e target mode in order to emulate a tag using the specified \a nfc_target_mode_t.
*
* @warning Be aware that this function will wait (hang) until a command is received that is not part of the anti-collision. The RATS command for example would wake up the emulator. After this is received, the send and receive functions can be used.
*/
bool
nfc_target_init (nfc_device_t * pnd, const nfc_target_mode_t ntm, const nfc_target_t nt, byte_t * pbtRx, size_t * pszRxLen)
nfc_target_init (nfc_device_t * pnd, const nfc_target_mode_t ntm, const nfc_target_t nt, byte_t * pbtRx, size_t * pszRx)
{
pnd->iLastError = 0;
return pn53x_target_init (pnd, ntm, nt, pbtRx, pszRxLen);
return pn53x_target_init (pnd, ntm, nt, pbtRx, pszRx);
}
/**
@ -568,16 +568,16 @@ nfc_target_init (nfc_device_t * pnd, const nfc_target_mode_t ntm, const nfc_targ
*
* @param pnd \a nfc_device_t struct pointer that represent currently used device
* @param pbtTx pointer to Tx buffer
* @param szTxLen size of Tx buffer
* @param szTx size of Tx buffer
*
* This function make the NFC device (configured as \e target) send byte frames (e.g. APDU responses) to the \e initiator.
*/
bool
nfc_target_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLen)
nfc_target_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx)
{
pnd->iLastError = 0;
return pn53x_target_send_bytes (pnd, pbtTx, szTxLen);
return pn53x_target_send_bytes (pnd, pbtTx, szTx);
}
/**
@ -585,16 +585,16 @@ nfc_target_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t sz
* @return Returns \c true if action was successfully performed; otherwise returns \c false.
* @param pnd \a nfc_device_t struct pointer that represent currently used device
* @param[out] pbtRx pointer to Rx buffer
* @param[out] pszRxLen received byte count
* @param[out] pszRx received byte count
*
* This function retrieves bytes frames (e.g. ADPU) sent by the \e initiator to the NFC device (configured as \e target).
*/
bool
nfc_target_receive_bytes (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRxLen)
nfc_target_receive_bytes (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRx)
{
pnd->iLastError = 0;
return pn53x_target_receive_bytes (pnd, pbtRx, pszRxLen);
return pn53x_target_receive_bytes (pnd, pbtRx, pszRx);
}
/**