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
+11 -11
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;
+2 -2
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);
+15 -15
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))) {
+2 -2
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__
+19 -19
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)))
+2 -2
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__
+12 -12
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;
}
+2 -2
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);