For the sake of consistency, rename all szRxLen to szRx and szTxLen to szTx
This commit is contained in:
parent
5d753827c1
commit
c34be50ef1
22 changed files with 195 additions and 195 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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__
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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__
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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))) {
|
||||
|
|
|
|||
|
|
@ -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__
|
||||
|
|
|
|||
|
|
@ -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)))
|
||||
|
|
|
|||
|
|
@ -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__
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
24
libnfc/nfc.c
24
libnfc/nfc.c
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue