From c10b473361ac42e8e7d00f7dcbfcf34672abf2c5 Mon Sep 17 00:00:00 2001 From: Audrey Diacre Date: Mon, 9 Jan 2012 10:24:00 +0000 Subject: [PATCH] rx buffer size parameter of pn53x_transceive() function is now a const size_t. --- examples/pn53x-diagnose.c | 15 +++--- examples/pn53x-tamashell.c | 4 +- libnfc/chips/pn53x.c | 102 ++++++++++++++++++++----------------- libnfc/chips/pn53x.h | 2 +- libnfc/drivers/pn53x_usb.c | 4 +- test/test_dep_active.c | 2 +- test/test_dep_passive.c | 8 +-- 7 files changed, 75 insertions(+), 62 deletions(-) diff --git a/examples/pn53x-diagnose.c b/examples/pn53x-diagnose.c index d12d6c4..49e9c3e 100644 --- a/examples/pn53x-diagnose.c +++ b/examples/pn53x-diagnose.c @@ -89,8 +89,9 @@ main (int argc, const char *argv[]) printf ("NFC device [%s] connected.\n", nfc_device_get_name (pnd)); - res = pn53x_transceive (pnd, pncmd_diagnose_communication_line_test, sizeof (pncmd_diagnose_communication_line_test), abtRx, &szRx, 0); - if (res == 0) { + res = pn53x_transceive (pnd, pncmd_diagnose_communication_line_test, sizeof (pncmd_diagnose_communication_line_test), abtRx, szRx, 0); + if (res > 0) { + szRx = (size_t) res; // Result of Diagnose ping for RC-S360 doesn't contain status byte so we've to handle both cases result = (memcmp (pncmd_diagnose_communication_line_test + 1, abtRx, sizeof (pncmd_diagnose_communication_line_test) - 1) == 0) || (memcmp (pncmd_diagnose_communication_line_test + 2, abtRx, sizeof (pncmd_diagnose_communication_line_test) - 2) == 0); @@ -99,16 +100,18 @@ main (int argc, const char *argv[]) } printf (" Communication line test: %s\n", result ? "OK" : "Failed"); - res = pn53x_transceive (pnd, pncmd_diagnose_rom_test, sizeof (pncmd_diagnose_rom_test), abtRx, &szRx, 0); - if (res == 0) { + res = pn53x_transceive (pnd, pncmd_diagnose_rom_test, sizeof (pncmd_diagnose_rom_test), abtRx, szRx, 0); + if (res > 0) { + szRx = (size_t) res; result = ((szRx == 1) && (abtRx[0] == 0x00)); } else { nfc_perror (pnd, "pn53x_transceive"); } printf (" ROM test: %s\n", result ? "OK" : "Failed"); - res = pn53x_transceive (pnd, pncmd_diagnose_ram_test, sizeof (pncmd_diagnose_ram_test), abtRx, &szRx, 0); - if (res == 0) { + res = pn53x_transceive (pnd, pncmd_diagnose_ram_test, sizeof (pncmd_diagnose_ram_test), abtRx, szRx, 0); + if (res > 0) { + szRx = (size_t) res; result = ((szRx == 1) && (abtRx[0] == 0x00)); } else { nfc_perror (pnd, "pn53x_transceive"); diff --git a/examples/pn53x-tamashell.c b/examples/pn53x-tamashell.c index e06e9a0..ac0bb8f 100644 --- a/examples/pn53x-tamashell.c +++ b/examples/pn53x-tamashell.c @@ -181,11 +181,13 @@ int main(int argc, const char* argv[]) print_hex((uint8_t*)abtTx,szTx); szRx = sizeof(abtRx); - if (pn53x_transceive (pnd, abtTx, szTx, abtRx, &szRx, 0) < 0) { + int res = 0; + if ((res = pn53x_transceive (pnd, abtTx, szTx, abtRx, szRx, 0)) < 0) { free(cmd); nfc_perror (pnd, "Rx"); continue; } + szRx = (size_t) res; printf("Rx: "); print_hex(abtRx, szRx); diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index e5bd058..d807f57 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -104,7 +104,7 @@ pn53x_reset_settings(struct nfc_device *pnd) } int -pn53x_transceive (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, size_t *pszRx, int timeout) +pn53x_transceive (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, const size_t szRxLen, int timeout) { int res = 0; if (CHIP_DATA (pnd)->wb_trigged) { @@ -128,9 +128,10 @@ pn53x_transceive (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szT size_t szRx = sizeof(abtRx); // Check if receiving buffers are available, if not, replace them - if (!pszRx || !pbtRx) { + if (szRxLen == 0 || !pbtRx) { pbtRx = abtRx; - pszRx = &szRx; + } else { + szRx = szRxLen; } // Call the send/receice callback functions of the current driver @@ -146,7 +147,7 @@ pn53x_transceive (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szT CHIP_DATA (pnd)->power_mode = POWERDOWN; } - if ((res = CHIP_DATA(pnd)->io->receive (pnd, pbtRx, *pszRx, timeout)) < 0) { + if ((res = CHIP_DATA(pnd)->io->receive (pnd, pbtRx, szRx, timeout)) < 0) { return res; } @@ -154,7 +155,7 @@ pn53x_transceive (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szT CHIP_DATA(pnd)->power_mode = NORMAL; // When TgInitAsTarget reply that means an external RF have waken up the chip } - *pszRx = (size_t) res; + szRx = (size_t) res; switch (pbtTx[0]) { case PowerDown: case InDataExchange: @@ -200,7 +201,7 @@ pn53x_transceive (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szT switch (CHIP_DATA(pnd)->last_status_byte) { case 0: - res = NFC_SUCCESS; + res = szRx; break; case ETIMEOUT: case ECRC: @@ -529,7 +530,7 @@ pn53x_ReadRegister (struct nfc_device *pnd, uint16_t ui16RegisterAddress, uint8_ int res = 0; PNREG_TRACE (ui16RegisterAddress); - if ((res = pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRegValue, &szRegValue, -1)) < 0) { + if ((res = pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRegValue, szRegValue, -1)) < 0) { return res; } if (CHIP_DATA(pnd)->type == PN533) { @@ -551,7 +552,7 @@ pn53x_WriteRegister (struct nfc_device *pnd, const uint16_t ui16RegisterAddress, { uint8_t abtCmd[] = { WriteRegister, ui16RegisterAddress >> 8, ui16RegisterAddress & 0xff, ui8Value }; PNREG_TRACE (ui16RegisterAddress); - return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, -1); + return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, 0, -1); } int @@ -605,7 +606,7 @@ pn53x_writeback_register (struct nfc_device *pnd) uint8_t abtRes[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; size_t szRes = sizeof(abtRes); // It transceives the previously constructed ReadRegister command - if ((res = pn53x_transceive (pnd, abtReadRegisterCmd, BUFFER_SIZE (abtReadRegisterCmd), abtRes, &szRes, -1)) < 0) { + if ((res = pn53x_transceive (pnd, abtReadRegisterCmd, BUFFER_SIZE (abtReadRegisterCmd), abtRes, szRes, -1)) < 0) { return res; } size_t i = 0; @@ -643,7 +644,7 @@ pn53x_writeback_register (struct nfc_device *pnd) if (BUFFER_SIZE (abtWriteRegisterCmd) > 1) { // We need to write some registers - if ((res = pn53x_transceive (pnd, abtWriteRegisterCmd, BUFFER_SIZE (abtWriteRegisterCmd), NULL, NULL, -1)) < 0) { + if ((res = pn53x_transceive (pnd, abtWriteRegisterCmd, BUFFER_SIZE (abtWriteRegisterCmd), NULL, 0, -1)) < 0) { return res; } } @@ -657,9 +658,10 @@ pn53x_get_firmware_version (struct nfc_device *pnd, char abtFirmwareText[22]) uint8_t abtFw[4]; size_t szFwLen = sizeof (abtFw); int res = 0; - if ((res = pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtFw, &szFwLen, -1)) < 0) { + if ((res = pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtFw, szFwLen, -1)) < 0) { return res; } + szFwLen = (size_t) res; // Determine which version of chip it is: PN531 will return only 2 bytes, while others return 4 bytes and have the first to tell the version IC if (szFwLen == 2) { CHIP_DATA(pnd)->type = PN531; @@ -930,9 +932,9 @@ pn53x_check_communication (struct nfc_device *pnd) size_t szRx = sizeof (abtRx); int res = 0; - if ((res = pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRx, &szRx, 500)) < 0) + if ((res = pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRx, szRx, 500)) < 0) return res; - + szRx = (size_t) res; if (((sizeof(abtExpectedRx) == szRx) && (0 == memcmp (abtRx, abtExpectedRx, sizeof(abtExpectedRx)))) == 0) return NFC_SUCCESS; @@ -1206,9 +1208,9 @@ pn53x_initiator_transceive_bits (struct nfc_device *pnd, const uint8_t *pbtTx, c // We have to give the amount of bytes + (the command byte 0x42) uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; size_t szRx = sizeof(abtRx); - if ((res = pn53x_transceive (pnd, abtCmd, szFrameBytes + 1, abtRx, &szRx, -1)) < 0) + if ((res = pn53x_transceive (pnd, abtCmd, szFrameBytes + 1, abtRx, szRx, -1)) < 0) return res; - + szRx = (size_t) res; // Get the last bit-count that is stored in the received byte if ((res = pn53x_read_register (pnd, PN53X_REG_CIU_Control, &ui8rcc)) < 0) return res; @@ -1271,7 +1273,8 @@ pn53x_initiator_transceive_bytes (struct nfc_device *pnd, const uint8_t *pbtTx, // We have to give the amount of bytes + (the two command bytes 0xD4, 0x42) uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; size_t szRx = sizeof(abtRx); - if (pn53x_transceive (pnd, abtCmd, szTx + szExtraTxLen, abtRx, &szRx, timeout) < 0) { + int res = 0; + if ((res = pn53x_transceive (pnd, abtCmd, szTx + szExtraTxLen, abtRx, szRx, timeout)) < 0) { // FIXME pn53x_transceive should return an integer if (CHIP_DATA (pnd)->last_status_byte == EINVRXFRAM) { pnd->last_error = NFC_ERFTRANS; @@ -1281,7 +1284,7 @@ pn53x_initiator_transceive_bytes (struct nfc_device *pnd, const uint8_t *pbtTx, return pnd->last_error; } } - + szRx = (size_t) res; if (pbtRx != NULL) { // Save the received byte count *pszRx = szRx - 1; @@ -1335,7 +1338,7 @@ uint32_t __pn53x_get_timer(struct nfc_device *pnd, const uint8_t last_cmd_byte) uint8_t abtRes[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; size_t szRes = sizeof(abtRes); // Let's send the previously constructed ReadRegister command - if (pn53x_transceive (pnd, abtReadRegisterCmd, BUFFER_SIZE (abtReadRegisterCmd), abtRes, &szRes, -1) < 0) { + if (pn53x_transceive (pnd, abtReadRegisterCmd, BUFFER_SIZE (abtReadRegisterCmd), abtRes, szRes, -1) < 0) { return false; } counter_hi = abtRes[off]; @@ -1427,7 +1430,7 @@ pn53x_initiator_transceive_bits_timed (struct nfc_device *pnd, const uint8_t *pb BUFFER_APPEND (abtWriteRegisterCmd, PN53X_REG_CIU_BitFraming & 0xff); BUFFER_APPEND (abtWriteRegisterCmd, SYMBOL_START_SEND | ((szTxBits % 8) & SYMBOL_TX_LAST_BITS)); // Let's send the previously constructed WriteRegister command - if ((res = pn53x_transceive (pnd, abtWriteRegisterCmd, BUFFER_SIZE (abtWriteRegisterCmd), NULL, NULL, -1)) < 0) { + if ((res = pn53x_transceive (pnd, abtWriteRegisterCmd, BUFFER_SIZE (abtWriteRegisterCmd), NULL, 0, -1)) < 0) { return res; } @@ -1458,7 +1461,7 @@ pn53x_initiator_transceive_bits_timed (struct nfc_device *pnd, const uint8_t *pb uint8_t abtRes[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; size_t szRes = sizeof(abtRes); // Let's send the previously constructed ReadRegister command - if ((res = pn53x_transceive (pnd, abtReadRegisterCmd, BUFFER_SIZE (abtReadRegisterCmd), abtRes, &szRes, -1)) < 0) { + if ((res = pn53x_transceive (pnd, abtReadRegisterCmd, BUFFER_SIZE (abtReadRegisterCmd), abtRes, szRes, -1)) < 0) { return res; } for (i = 0; i < sz; i++) { @@ -1521,7 +1524,7 @@ pn53x_initiator_transceive_bytes_timed (struct nfc_device *pnd, const uint8_t *p BUFFER_APPEND (abtWriteRegisterCmd, PN53X_REG_CIU_BitFraming & 0xff); BUFFER_APPEND (abtWriteRegisterCmd, SYMBOL_START_SEND); // Let's send the previously constructed WriteRegister command - if ((res = pn53x_transceive (pnd, abtWriteRegisterCmd, BUFFER_SIZE (abtWriteRegisterCmd), NULL, NULL, -1)) < 0) { + if ((res = pn53x_transceive (pnd, abtWriteRegisterCmd, BUFFER_SIZE (abtWriteRegisterCmd), NULL, 0, -1)) < 0) { return res; } @@ -1553,7 +1556,7 @@ pn53x_initiator_transceive_bytes_timed (struct nfc_device *pnd, const uint8_t *p uint8_t abtRes[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; size_t szRes = sizeof(abtRes); // Let's send the previously constructed ReadRegister command - if ((res = pn53x_transceive (pnd, abtReadRegisterCmd, BUFFER_SIZE (abtReadRegisterCmd), abtRes, &szRes, -1)) < 0) { + if ((res = pn53x_transceive (pnd, abtReadRegisterCmd, BUFFER_SIZE (abtReadRegisterCmd), abtRes, szRes, -1)) < 0) { return res; } for (i = 0; i < sz; i++) { @@ -1821,9 +1824,9 @@ pn53x_target_receive_bits (struct nfc_device *pnd, uint8_t *pbtRx, const size_t int res = 0; // Try to gather a received frame from the reader - if ((res = pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRx, &szRx, -1)) < 0) + if ((res = pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRx, szRx, -1)) < 0) return res; - + szRx = (size_t) res; // Get the last bit-count that is stored in the received byte uint8_t ui8rcc; if ((res = pn53x_read_register (pnd, PN53X_REG_CIU_Control, &ui8rcc)) < 0) @@ -1889,9 +1892,10 @@ pn53x_target_receive_bytes (struct nfc_device *pnd, uint8_t *pbtRx, const size_t // Try to gather a received frame from the reader uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; size_t szRx = sizeof (abtRx); - if (pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRx, &szRx, timeout) < 0) + int res = 0; + if ((res = pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRx, szRx, timeout)) < 0) return pnd->last_error; - + szRx = (size_t) res; // Save the received bytes count szRx -= 1; @@ -1939,7 +1943,7 @@ pn53x_target_send_bits (struct nfc_device *pnd, const uint8_t *pbtTx, const size return res; // Try to send the bits to the reader - if ((res = pn53x_transceive (pnd, abtCmd, szFrameBytes + 1, NULL, NULL, -1)) < 0) + if ((res = pn53x_transceive (pnd, abtCmd, szFrameBytes + 1, NULL, 0, -1)) < 0) return res; // Everyting seems ok, return return sent bits count @@ -1988,7 +1992,7 @@ pn53x_target_send_bytes (struct nfc_device *pnd, const uint8_t *pbtTx, const siz memcpy (abtCmd + 1, pbtTx, szTx); // Try to send the bits to the reader - if ((res = pn53x_transceive (pnd, abtCmd, szTx + 1, NULL, NULL, timeout)) < 0) + if ((res = pn53x_transceive (pnd, abtCmd, szTx + 1, NULL, 0, timeout)) < 0) return res; // Everyting seems ok, return sent byte count @@ -2053,7 +2057,7 @@ int pn53x_RFConfiguration__RF_field (struct nfc_device *pnd, bool bEnable) { uint8_t abtCmd[] = { RFConfiguration, RFCI_FIELD, (bEnable) ? 0x01 : 0x00 }; - return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, -1); + return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, 0, -1); } int @@ -2066,7 +2070,7 @@ pn53x_RFConfiguration__Various_timings (struct nfc_device *pnd, const uint8_t fA fATR_RES_Timeout, // ATR_RES timeout (default: 0x0B 102.4 ms) fRetryTimeout // TimeOut during non-DEP communications (default: 0x0A 51.2 ms) }; - return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, -1); + return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, 0, -1); } int @@ -2077,7 +2081,7 @@ pn53x_RFConfiguration__MaxRtyCOM (struct nfc_device *pnd, const uint8_t MaxRtyCO RFCI_RETRY_DATA, MaxRtyCOM // MaxRtyCOM, default: 0x00 (no retry, only one try), inifite: 0xff }; - return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, -1); + return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, 0, -1); } int @@ -2091,7 +2095,7 @@ pn53x_RFConfiguration__MaxRetries (struct nfc_device *pnd, const uint8_t MxRtyAT MxRtyPSL, // MxRtyPSL, default: 0x01 MxRtyPassiveActivation // MxRtyPassiveActivation, default: 0xff (0x00 leads to problems with PN531) }; - return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, -1); + return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, 0, -1); } int @@ -2100,7 +2104,7 @@ pn53x_SetParameters (struct nfc_device *pnd, const uint8_t ui8Value) uint8_t abtCmd[] = { SetParameters, ui8Value }; int res = 0; - if((res = pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, -1)) < 0) { + if((res = pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, 0, -1)) < 0) { return res; } // We save last parameters in register cache @@ -2134,14 +2138,14 @@ pn53x_SAMConfiguration (struct nfc_device *pnd, const pn532_sam_mode ui8Mode, in pnd->last_error = NFC_EINVARG; return pnd->last_error; } - return (pn53x_transceive (pnd, abtCmd, szCmd, NULL, NULL, timeout)); + return (pn53x_transceive (pnd, abtCmd, szCmd, NULL, 0, timeout)); } int pn53x_PowerDown (struct nfc_device *pnd) { uint8_t abtCmd[] = { PowerDown, 0xf0 }; - return (pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, -1)); + return (pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, 0, -1)); } /** @@ -2208,9 +2212,10 @@ pn53x_InListPassiveTarget (struct nfc_device *pnd, if (pbtInitiatorData) memcpy (abtCmd + 3, pbtInitiatorData, szInitiatorData); int res = 0; - if ((res = pn53x_transceive (pnd, abtCmd, 3 + szInitiatorData, pbtTargetsData, pszTargetsData, timeout)) < 0) { + if ((res = pn53x_transceive (pnd, abtCmd, 3 + szInitiatorData, pbtTargetsData, *pszTargetsData, timeout)) < 0) { return res; } + *pszTargetsData = (size_t) res; return pbtTargetsData[0]; } @@ -2223,18 +2228,19 @@ pn53x_InDeselect (struct nfc_device *pnd, const uint8_t ui8Target) size_t szStatus = sizeof(abtStatus); uint8_t abtCmdGetStatus[] = { GetGeneralStatus }; int res = 0; - if ((res = pn53x_transceive (pnd, abtCmdGetStatus, sizeof (abtCmdGetStatus), abtStatus, &szStatus, -1)) < 0) { + if ((res = pn53x_transceive (pnd, abtCmdGetStatus, sizeof (abtCmdGetStatus), abtStatus, szStatus, -1)) < 0) { return res; } + szStatus = (size_t) res; if ((szStatus < 3) || (abtStatus[2] == 0)) { return NFC_SUCCESS; } // No much choice what to deselect actually... uint8_t abtCmdRcs360[] = { InDeselect, 0x01, 0x01 }; - return (pn53x_transceive (pnd, abtCmdRcs360, sizeof (abtCmdRcs360), NULL, NULL, -1)); + return (pn53x_transceive (pnd, abtCmdRcs360, sizeof (abtCmdRcs360), NULL, 0, -1)); } uint8_t abtCmd[] = { InDeselect, ui8Target }; - return (pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, -1)); + return (pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, 0, -1)); } int @@ -2246,18 +2252,19 @@ pn53x_InRelease (struct nfc_device *pnd, const uint8_t ui8Target) size_t szStatus = sizeof(abtStatus); uint8_t abtCmdGetStatus[] = { GetGeneralStatus }; int res = 0; - if ((res = pn53x_transceive (pnd, abtCmdGetStatus, sizeof (abtCmdGetStatus), abtStatus, &szStatus, -1)) < 0) { + if ((res = pn53x_transceive (pnd, abtCmdGetStatus, sizeof (abtCmdGetStatus), abtStatus, szStatus, -1)) < 0) { return res; } + szStatus = (size_t) res; if ((szStatus < 3) || (abtStatus[2] == 0)) { return NFC_SUCCESS; } // No much choice what to release actually... uint8_t abtCmdRcs360[] = { InRelease, 0x01, 0x01 }; - return (pn53x_transceive (pnd, abtCmdRcs360, sizeof (abtCmdRcs360), NULL, NULL, -1)); + return (pn53x_transceive (pnd, abtCmdRcs360, sizeof (abtCmdRcs360), NULL, 0, -1)); } uint8_t abtCmd[] = { InRelease, ui8Target }; - return (pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, -1)); + return (pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, 0, -1)); } int @@ -2281,8 +2288,8 @@ pn53x_InAutoPoll (struct nfc_device *pnd, uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; size_t szRx = sizeof(abtRx); - int res = pn53x_transceive (pnd, abtCmd, szTxInAutoPoll, abtRx, &szRx, timeout); - + int res = pn53x_transceive (pnd, abtCmd, szTxInAutoPoll, abtRx, szRx, timeout); +szRx = (size_t) res; if (res < 0) { return res; } else if (szRx > 0) { @@ -2394,9 +2401,9 @@ pn53x_InJumpForDEP (struct nfc_device *pnd, size_t szRx = sizeof (abtRx); int res = 0; // Try to find a target, call the transceive callback function of the current device - if ((res = pn53x_transceive (pnd, abtCmd, offset, abtRx, &szRx, timeout)) < 0) + if ((res = pn53x_transceive (pnd, abtCmd, offset, abtRx, szRx, timeout)) < 0) return res; - + szRx = (size_t) res; // Make sure one target has been found, the PN53X returns 0x00 if none was available if (abtRx[1] >= 1) { // Is a target struct available @@ -2476,8 +2483,9 @@ pn53x_TgInitAsTarget (struct nfc_device *pnd, pn53x_target_mode ptm, // Request the initialization as a target uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; size_t szRx = sizeof (abtRx); - if ((res = pn53x_transceive (pnd, abtCmd, 36 + szOptionalBytes, abtRx, &szRx, timeout)) < 0) + if ((res = pn53x_transceive (pnd, abtCmd, 36 + szOptionalBytes, abtRx, szRx, timeout)) < 0) return res; + szRx = (size_t) res; // Note: the first byte is skip: // its the "mode" byte which contains baudrate, DEP and Framing type (Mifare, active or FeliCa) datas. diff --git a/libnfc/chips/pn53x.h b/libnfc/chips/pn53x.h index fc4cea7..fe701b9 100644 --- a/libnfc/chips/pn53x.h +++ b/libnfc/chips/pn53x.h @@ -264,7 +264,7 @@ extern const uint8_t pn53x_ack_frame[6]; extern const uint8_t pn53x_nack_frame[6]; int pn53x_init(struct nfc_device *pnd); -int pn53x_transceive (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, size_t *pszRx, int timeout); +int pn53x_transceive (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, const size_t szRxLen, int timeout); int pn53x_set_parameters (struct nfc_device *pnd, const uint8_t ui8Value, const bool bEnable); int pn53x_set_tx_bits (struct nfc_device *pnd, const uint8_t ui8Bits); diff --git a/libnfc/drivers/pn53x_usb.c b/libnfc/drivers/pn53x_usb.c index 205b670..3a6272c 100644 --- a/libnfc/drivers/pn53x_usb.c +++ b/libnfc/drivers/pn53x_usb.c @@ -701,13 +701,13 @@ pn53x_usb_init (nfc_device *pnd) // Sometimes PN53x USB doesn't reply ACK one the first frame, so we need to send a dummy one... //pn53x_check_communication (pnd); // Sony RC-S360 doesn't support this command for now so let's use a get_firmware_version instead: const uint8_t abtCmd[] = { GetFirmwareVersion }; - pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL, 0); + pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, 0, 0); // ...and we don't care about error pnd->last_error = 0; if (SONY_RCS360 == DRIVER_DATA (pnd)->model) { log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "SONY RC-S360 initialization."); const uint8_t abtCmd2[] = { 0x18, 0x01 }; - pn53x_transceive (pnd, abtCmd2, sizeof (abtCmd2), NULL, NULL, 0); + pn53x_transceive (pnd, abtCmd2, sizeof (abtCmd2), NULL, 0, 0); pn53x_usb_ack (pnd); } diff --git a/test/test_dep_active.c b/test/test_dep_active.c index 7fe577a..3715639 100644 --- a/test/test_dep_active.c +++ b/test/test_dep_active.c @@ -143,7 +143,7 @@ initiator_thread (void *arg) cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data")); if (res < 0) { thread_res = -1; return (void*) thread_res; } res = nfc_initiator_deselect_target (device); - cut_assert_equal_int (0, res, cut_message ("Can't deselect target: %s", nfc_strerror (device))); + cut_assert_operator_int (res, >=, 0, cut_message ("Can't deselect target: %s", nfc_strerror (device))); if (res < 0) { thread_res = -1; return (void*) thread_res; } return (void *) thread_res; diff --git a/test/test_dep_passive.c b/test/test_dep_passive.c index c7d9932..6bdd804 100644 --- a/test/test_dep_passive.c +++ b/test/test_dep_passive.c @@ -180,7 +180,7 @@ initiator_thread (void *arg) if (res < 0) { thread_res = -1; return (void*) thread_res; } res = nfc_initiator_deselect_target (device); - cut_assert_equal_int (0, res, cut_message ("Can't deselect target: %s", nfc_strerror (device))); + cut_assert_operator_int (res, >=, 0, cut_message ("Can't deselect target: %s", nfc_strerror (device))); if (res < 0) { thread_res = -1; return (void*) thread_res; } // Passive mode / 212Kbps (second pass) @@ -202,7 +202,7 @@ initiator_thread (void *arg) if (res < 0) { thread_res = -1; return (void*) thread_res; } res = nfc_initiator_deselect_target (device); - cut_assert_equal_int (0, res, cut_message ("Can't deselect target: %s", nfc_strerror (device))); + cut_assert_operator_int (res, >=, 0, cut_message ("Can't deselect target: %s", nfc_strerror (device))); if (res < 0) { thread_res = -1; return (void*) thread_res; } // Passive mode / 212Kbps @@ -224,7 +224,7 @@ initiator_thread (void *arg) if (res < 0) { thread_res = -1; return (void*) thread_res; } res = nfc_initiator_deselect_target (device); - cut_assert_equal_int (0, res, cut_message ("Can't deselect target: %s", nfc_strerror (device))); + cut_assert_operator_int (res, >=, 0, cut_message ("Can't deselect target: %s", nfc_strerror (device))); if (res < 0) { thread_res = -1; return (void*) thread_res; } // Passive mode / 424Kbps @@ -246,7 +246,7 @@ initiator_thread (void *arg) if (res < 0) { thread_res = -1; return (void*) thread_res; } res = nfc_initiator_deselect_target (device); - cut_assert_equal_int (0, res, cut_message ("Can't deselect target: %s", nfc_strerror (device))); + cut_assert_operator_int (res, >=, 0, cut_message ("Can't deselect target: %s", nfc_strerror (device))); if (res < 0) { thread_res = -1; return (void*) thread_res; } return (void *) thread_res;