From b953002f8f917b96139f198a2628ba3d36d0a0db Mon Sep 17 00:00:00 2001 From: Olliver Schinagl Date: Thu, 20 Oct 2016 17:36:04 +0200 Subject: [PATCH 01/19] drivers: pn532_i2c: Clarify preamble and start byte The pn532 documentation differs slightly from the included ascii art documentation on how a packet looks like. The preamble was omitted however the postamble is mentioned. This patch adds the Preamble to the ascii frame documentation. The code later refers incorrectly to the start byte as the preamble. This variable was renamed to more descriptively state that it is the preambe and the start bytes. Signed-off-by: Olliver Schinagl --- libnfc/chips/pn53x-internal.h | 48 ++++++++++++++++++++--------------- libnfc/drivers/pn532_i2c.c | 11 +++++--- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/libnfc/chips/pn53x-internal.h b/libnfc/chips/pn53x-internal.h index c43934a..e4869cd 100644 --- a/libnfc/chips/pn53x-internal.h +++ b/libnfc/chips/pn53x-internal.h @@ -81,32 +81,38 @@ #define TgGetTargetStatus 0x8A /** @note PN53x's normal frame: + * See the PN532 (firmware) user manual, section 6.2.1.1: Normal information + * frame, figure 13. Normal information frame, page 28 rev. 02 - 2007-11-07. * - * .-- Start - * | .-- Packet length - * | | .-- Length checksum - * | | | .-- Direction (D4 Host to PN, D5 PN to Host) - * | | | | .-- Code - * | | | | | .-- Packet checksum - * | | | | | | .-- Postamble - * V | | | | | | - * ----- V V V V V V - * 00 FF 02 FE D4 02 2A 00 + * .-- Preamble + * | .-- Start + * | | .-- Packet length + * | | | .-- Length checksum + * | | | | .-- Direction (D4 Host to PN, D5 PN to Host) + * | | | | | .-- Code + * | | | | | | .-- Packet checksum + * | | | | | | | .-- Postamble + * | V | | | | | | + * V ----- V V V V V V + * 00 00 FF 02 FE D4 02 2A 00 */ /** @note PN53x's extended frame: + * See the PN532 (firmware) user manual, section 6.2.1.2: Extended information + * frame, figure 14. Normal information frame, page 29 rev. 02 - 2007-11-07. * - * .-- Start - * | .-- Fixed to FF to enable extended frame - * | | .-- Packet length - * | | | .-- Length checksum - * | | | | .-- Direction (D4 Host to PN, D5 PN to Host) - * | | | | | .-- Code - * | | | | | | .-- Packet checksum - * | | | | | | | .-- Postamble - * V V V | | | | | - * ----- ----- ----- V V V V V - * 00 FF FF FF 00 02 FE D4 02 2A 00 + * .-- Preamble + * | .-- Start + * | | .-- Fixed to FF to enable extended frame + * | | | .-- Packet length + * | | | | .-- Length checksum + * | | | | | .-- Direction (D4 Host to PN, D5 PN to Host) + * | | | | | | .-- Code + * | | | | | | | .-- Packet checksum + * | | | | | | | | .-- Postamble + * | V V V | | | | | + * V ----- ----- ----- V V V V V + * 00 00 FF FF FF 00 02 FE D4 02 2A 00 */ /** diff --git a/libnfc/drivers/pn532_i2c.c b/libnfc/drivers/pn532_i2c.c index b62c7de..fe3345c 100644 --- a/libnfc/drivers/pn532_i2c.c +++ b/libnfc/drivers/pn532_i2c.c @@ -75,6 +75,10 @@ const struct timespec rdyDelay = { .tv_nsec = PN532_RDY_LOOP_DELAY * 1000 * 1000 }; +/* preamble and start bytes, see pn532-internal.h for details */ +const uint8_t pn53x_preamble_and_start[] = { 0x00, 0x00, 0xff }; +#define PN53X_PREAMBLE_AND_START_LEN (sizeof(pn53x_preamble_and_start) / sizeof(pn53x_preamble_and_start[0])) + /* Private Functions Prototypes */ static nfc_device *pn532_i2c_open(const nfc_context *context, const nfc_connstring connstring); @@ -334,9 +338,10 @@ pn532_i2c_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int break; }; - uint8_t abtFrame[PN532_BUFFER_LEN] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff" + uint8_t abtFrame[PN532_BUFFER_LEN]; size_t szFrame = 0; + memcpy(abtFrame, pn53x_preamble_and_start, PN53X_PREAMBLE_AND_START_LEN); // Every packet must start with the preamble and start bytes. if ((res = pn53x_build_frame(abtFrame, &szFrame, pbtData, szData)) < 0) { pnd->last_error = res; return pnd->last_error; @@ -477,9 +482,7 @@ pn532_i2c_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int goto error; } - const uint8_t pn53x_preamble[3] = { 0x00, 0x00, 0xff }; - - if (0 != (memcmp(frameBuf, pn53x_preamble, 3))) { + if (0 != (memcmp(frameBuf, pn53x_preamble_and_start, PN53X_PREAMBLE_AND_START_LEN))) { log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Frame preamble+start code mismatch"); pnd->last_error = NFC_EIO; goto error; From 8f8f780c2bdd95b8609b43d37f9f4982825851d4 Mon Sep 17 00:00:00 2001 From: Olliver Schinagl Date: Fri, 21 Oct 2016 10:48:56 +0200 Subject: [PATCH 02/19] drivers: pn532_i2c: Respect proper timing specifications The pn532 user manual states that after a i2c stop condition and before a i2c start condition there should be a delay of minimally 1.3 milliseconds. This is probably a limitation of the i2c peripheral or the firmware. In any case, each i2c_read and i2c_write creates the packets which are complemented with start/stop markers. It is thus required to take care of timing in these two functions. We solve this by wrapping the lower i2c_read and i2c_write functions for the pn532, as this requirement is not for all chips. Currently, we keep time using local variable, and thus the code is not thread-safe. With libnfc being single threaded and only one instances of libnfc can open a bus anyway, this is not yet a problem. Signed-off-by: Olliver Schinagl --- libnfc/drivers/pn532_i2c.c | 81 +++++++++++++++++++++++++++++++------- 1 file changed, 67 insertions(+), 14 deletions(-) diff --git a/libnfc/drivers/pn532_i2c.c b/libnfc/drivers/pn532_i2c.c index fe3345c..6315954 100644 --- a/libnfc/drivers/pn532_i2c.c +++ b/libnfc/drivers/pn532_i2c.c @@ -67,14 +67,6 @@ struct pn532_i2c_data { volatile bool abort_flag; }; -/* Delay for the loop waiting for READY frame (in ms) */ -#define PN532_RDY_LOOP_DELAY 90 - -const struct timespec rdyDelay = { - .tv_sec = 0, - .tv_nsec = PN532_RDY_LOOP_DELAY * 1000 * 1000 -}; - /* preamble and start bytes, see pn532-internal.h for details */ const uint8_t pn53x_preamble_and_start[] = { 0x00, 0x00, 0xff }; #define PN53X_PREAMBLE_AND_START_LEN (sizeof(pn53x_preamble_and_start) / sizeof(pn53x_preamble_and_start[0])) @@ -100,6 +92,70 @@ static size_t pn532_i2c_scan(const nfc_context *context, nfc_connstring connstri #define DRIVER_DATA(pnd) ((struct pn532_i2c_data*)(pnd->driver_data)) +/* + * Bus free time (in ms) between a STOP condition and START condition. See + * tBuf in the PN532 data sheet, section 12.25: Timing for the I2C interface, + * table 320. I2C timing specification, page 211, rev. 3.2 - 2007-12-07. + */ +#define PN532_BUS_FREE_TIME 1.3 +static struct timespec __transaction_stop; + +/** + * @brief Wrapper around i2c_read to ensure proper timing by respecting the + * minimal free bus time between a STOP condition and a START condition. + * + * @note This is not thread safe, but since libnfc is single threaded + * this should be okay. + * + * @param id I2C device + * @param buf pointer on buffer used to store data + * @param len length of the buffer + * @return length (in bytes) of read data, or driver error code (negative value) + */ +static ssize_t pn532_i2c_read(const i2c_device id, + uint8_t *buf, const size_t len) +{ + struct timespec transaction_start, bus_free_time = { 0 }; + ssize_t ret; + + clock_gettime(CLOCK_MONOTONIC, &transaction_start); + bus_free_time.tv_nsec = (PN532_BUS_FREE_TIME * 1000 * 1000) - + (transaction_start.tv_nsec - __transaction_stop.tv_nsec); + nanosleep(&bus_free_time, NULL); + + ret = i2c_read(id, buf, len); + clock_gettime(CLOCK_MONOTONIC, &__transaction_stop); + return ret; +} + +/** + * @brief Wrapper around i2c_write to ensure proper timing by respecting the + * minimal free bus time between a STOP condition and a START condition. + * + * @note This is not thread safe, but since libnfc is single threaded + * this should be okay. + * + * @param id I2C device + * @param buf pointer on buffer containing data + * @param len length of the buffer + * @return NFC_SUCCESS on success, otherwise driver error code + */ +static ssize_t pn532_i2c_write(const i2c_device id, + const uint8_t *buf, const size_t len) +{ + struct timespec transaction_start, bus_free_time = { 0 }; + ssize_t ret; + + clock_gettime(CLOCK_MONOTONIC, &transaction_start); + bus_free_time.tv_nsec = (PN532_BUS_FREE_TIME * 1000 * 1000) - + (transaction_start.tv_nsec - __transaction_stop.tv_nsec); + nanosleep(&bus_free_time, NULL); + + ret = i2c_write(id, buf, len); + clock_gettime(CLOCK_MONOTONIC, &__transaction_stop); + return ret; +} + /** * @brief Scan all available I2C buses to find PN532 devices. * @@ -347,7 +403,7 @@ pn532_i2c_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int return pnd->last_error; } - res = i2c_write(DRIVER_DATA(pnd)->dev, abtFrame, szFrame); + res = pn532_i2c_write(DRIVER_DATA(pnd)->dev, abtFrame, szFrame); if (res < 0) { log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to transmit data. (TX)"); @@ -405,10 +461,7 @@ pn532_i2c_wait_rdyframe(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLe } do { - // Wait a little bit before reading - nanosleep(&rdyDelay, (struct timespec *) NULL); - - int recCount = i2c_read(DRIVER_DATA(pnd)->dev, i2cRx, szDataLen + 1); + int recCount = pn532_i2c_read(DRIVER_DATA(pnd)->dev, i2cRx, szDataLen + 1); if (DRIVER_DATA(pnd)->abort_flag) { // Reset abort flag @@ -575,7 +628,7 @@ error: int pn532_i2c_ack(nfc_device *pnd) { - return i2c_write(DRIVER_DATA(pnd)->dev, pn53x_ack_frame, sizeof(pn53x_ack_frame)); + return pn532_i2c_write(DRIVER_DATA(pnd)->dev, pn53x_ack_frame, sizeof(pn53x_ack_frame)); } /** From d960673681db074f99078a946c663d6d3e58c751 Mon Sep 17 00:00:00 2001 From: Olliver Schinagl Date: Mon, 24 Oct 2016 09:34:19 +0200 Subject: [PATCH 03/19] drivers: pn532_i2c: Add retry on error mechanism Currently, we very occasionally can EXNIO errors from pn532_i2c_write() -> i2c_write() -> write(). This may happen about once every 30 seconds. Based from the kernel sources, EXNIO happens if the chip no longer responds to its own address. To make sure we do not loose any sent packets, we retry to send PN532_SEND_RETRIES number of times. Since we miss 1 every 30 or so seconds, doing 1 retry should be fine. This might be considered a hack as the failure may be some other timing related issue. Signed-off-by: Olliver Schinagl --- libnfc/drivers/pn532_i2c.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libnfc/drivers/pn532_i2c.c b/libnfc/drivers/pn532_i2c.c index 6315954..6d9e3fd 100644 --- a/libnfc/drivers/pn532_i2c.c +++ b/libnfc/drivers/pn532_i2c.c @@ -59,6 +59,13 @@ // I2C address of the PN532 chip. #define PN532_I2C_ADDR 0x24 +/* + * When sending lots of data, the pn532 occasionally fails to respond in time. + * Since it happens so rarely, lets try to fix it by re-sending the data. This + * define allows for fine tuning the number of retries. + */ +#define PN532_SEND_RETRIES 3 + // Internal data structs const struct pn53x_io pn532_i2c_io; @@ -368,6 +375,7 @@ static int pn532_i2c_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout) { int res = 0; + uint8_t retries; // Discard any existing data ? @@ -403,7 +411,13 @@ pn532_i2c_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int return pnd->last_error; } - res = pn532_i2c_write(DRIVER_DATA(pnd)->dev, abtFrame, szFrame); + for (retries = PN532_SEND_RETRIES; retries > 0; retries--) { + res = pn532_i2c_write(DRIVER_DATA(pnd)->dev, abtFrame, szFrame); + if (res >= 0) + break; + + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Failed to transmit data. Retries left: %d.", retries - 1); + } if (res < 0) { log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to transmit data. (TX)"); From a625d6a02d19c89a0542cd0a2058218eb163f06d Mon Sep 17 00:00:00 2001 From: timzi Date: Sun, 20 Nov 2016 18:48:00 +0300 Subject: [PATCH 04/19] Fixed file name "README" in cmakelists.txt --- CMakeLists.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 21ee9e7..3e23c6c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -228,7 +228,14 @@ ENDIF(WIN32) SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Near Field Communication (NFC) library") SET(CPACK_PACKAGE_VENDOR "Roel Verdult") -SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README") + +#Readme file +IF(WIN32) + SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README-Windows.md") +ELSE(WIN32) + SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md") +ENDIF(WIN32) + SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING") SET(CPACK_PACKAGE_INSTALL_DIRECTORY "libnfc") SET(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR}) From 65477eea5e8de714b6992ed5ad363faf8f1f9391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Bourgeois?= Date: Mon, 5 Dec 2016 13:11:45 +0100 Subject: [PATCH 05/19] Match nfc.h Synchronized with nfc.h with all API functions --- contrib/win32/nfc.def | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/contrib/win32/nfc.def b/contrib/win32/nfc.def index 085b2f7..5ed4097 100644 --- a/contrib/win32/nfc.def +++ b/contrib/win32/nfc.def @@ -4,6 +4,7 @@ VERSION 1.7 EXPORTS nfc_init nfc_exit + nfc_register_driver nfc_open nfc_close nfc_abort_command @@ -17,7 +18,6 @@ EXPORTS nfc_initiator_select_dep_target nfc_initiator_poll_dep_target nfc_initiator_deselect_target - nfc_initiator_poll_targets nfc_initiator_transceive_bytes nfc_initiator_transceive_bits nfc_initiator_transceive_bytes_timed @@ -36,11 +36,15 @@ EXPORTS nfc_device_get_connstring nfc_device_get_supported_modulation nfc_device_get_supported_baud_rate + nfc_device_get_supported_baud_rate_target_mode nfc_device_set_property_int nfc_device_set_property_bool iso14443a_crc iso14443a_crc_append + iso14443b_crc + iso14443b_crc_append iso14443a_locate_historical_bytes + nfc_free nfc_version nfc_device_get_information_about str_nfc_modulation_type From e946f7a97a38eb3145cd3105f2343ca5716e7b4e Mon Sep 17 00:00:00 2001 From: Olliver Schinagl Date: Tue, 6 Dec 2016 11:40:54 +0100 Subject: [PATCH 06/19] drivers: pn532_i2c: Errata on i2c timing The datasheet is wrong for the pn532_i2c. After having constant issues with the device failing to respond on the bus and after contacting NXP about this, it turns out 1.3 ms is too tight. The official timing spec is unknown for now, but we tested 4 and 5 ms without problems. Thus we have choosen 5 ms as a safe delay. Signed-off-by: Olliver Schinagl --- libnfc/drivers/pn532_i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libnfc/drivers/pn532_i2c.c b/libnfc/drivers/pn532_i2c.c index 6d9e3fd..d242df9 100644 --- a/libnfc/drivers/pn532_i2c.c +++ b/libnfc/drivers/pn532_i2c.c @@ -104,7 +104,7 @@ static size_t pn532_i2c_scan(const nfc_context *context, nfc_connstring connstri * tBuf in the PN532 data sheet, section 12.25: Timing for the I2C interface, * table 320. I2C timing specification, page 211, rev. 3.2 - 2007-12-07. */ -#define PN532_BUS_FREE_TIME 1.3 +#define PN532_BUS_FREE_TIME 5 static struct timespec __transaction_stop; /** From b29332a3095de036b0f08b6f1cd526e8a441d384 Mon Sep 17 00:00:00 2001 From: Maxim Martyanov Date: Tue, 6 Dec 2016 20:43:08 +0400 Subject: [PATCH 07/19] Update Makefile.am README-Windows.txt -> README-Windows.md --- Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index a1604a3..413b6de 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,7 +10,7 @@ pkgconfig_DATA = libnfc.pc EXTRA_DIST = \ CMakeLists.txt \ Doxyfile \ - README-Windows.txt \ + README-Windows.md \ libnfc.conf.sample CLEANFILES = Doxygen.log coverage.info libnfc.pc From e32cc068ec55eb78b24b83b676d8366e5b013282 Mon Sep 17 00:00:00 2001 From: Maxim Martyanov Date: Tue, 6 Dec 2016 20:44:31 +0400 Subject: [PATCH 08/19] Update README.md README-Windows.txt => README-Windows.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b03551f..d68508f 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ The official forum site is: The official development site is: https://github.com/nfc-tools/libnfc -Important note: this file covers POSIX systems, for Windows please read README-Windows.txt +Important note: this file covers POSIX systems, for Windows please read README-Windows.md Requirements ============ From b38597f1e08a2dccd9f8fb80d2b84a0e15400191 Mon Sep 17 00:00:00 2001 From: John Galt Date: Wed, 7 Dec 2016 06:17:04 -0500 Subject: [PATCH 09/19] Fix typo in nfc.h --- include/nfc/nfc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/nfc/nfc.h b/include/nfc/nfc.h index 4ebc6ff..bbbde94 100644 --- a/include/nfc/nfc.h +++ b/include/nfc/nfc.h @@ -28,7 +28,7 @@ * @file nfc.h * @brief libnfc interface * - * Provide all usefull functions (API) to handle NFC devices. + * Provide all useful functions (API) to handle NFC devices. */ #ifndef _LIBNFC_H_ From 9c7b9eda8ca69b46cc6f039ff21e080881b24d93 Mon Sep 17 00:00:00 2001 From: John Galt Date: Wed, 7 Dec 2016 07:22:27 -0500 Subject: [PATCH 10/19] Fix typo in nfc.c --- libnfc/nfc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libnfc/nfc.c b/libnfc/nfc.c index 404786a..97451a1 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -972,7 +972,7 @@ nfc_target_init(nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t s * @param pnd \a nfc_device struct pointer that represent currently used device * * This function switch the device in idle mode. - * In initiator mode, the RF field is turned off and the device is set to low power mode (if avaible); + * In initiator mode, the RF field is turned off and the device is set to low power mode (if available); * In target mode, the emulation is stoped (no target available from external initiator) and the device is set to low power mode (if avaible). */ int From 295c70911a8f49725b78d6ef1018dda6d1836ca7 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 16 Feb 2017 22:31:10 +0100 Subject: [PATCH 11/19] Restrict MFC Mini detection according to AN10833 --- utils/nfc-mfclassic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/nfc-mfclassic.c b/utils/nfc-mfclassic.c index 56d5717..9a8f8b6 100644 --- a/utils/nfc-mfclassic.c +++ b/utils/nfc-mfclassic.c @@ -671,7 +671,7 @@ main(int argc, const char *argv[]) if ((nt.nti.nai.abtAtqa[1] & 0x02) == 0x02) // 4K uiBlocks = 0xff; - else if ((nt.nti.nai.btSak & 0x01) == 0x01) + else if (nt.nti.nai.btSak == 0x09) // 320b uiBlocks = 0x13; else From 372bf37eec1fa35c65cef57d5dcbdb9369134aa3 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 16 Feb 2017 22:32:16 +0100 Subject: [PATCH 12/19] Blacklist pn533_usb to fix issue #391 --- contrib/linux/blacklist-libnfc.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/linux/blacklist-libnfc.conf b/contrib/linux/blacklist-libnfc.conf index e9382b1..40f406f 100644 --- a/contrib/linux/blacklist-libnfc.conf +++ b/contrib/linux/blacklist-libnfc.conf @@ -1,2 +1,3 @@ blacklist nfc blacklist pn533 +blacklist pm533_usb From e50b18848fee8e079235602dd0701ca5567a49ac Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 16 Feb 2017 23:00:37 +0100 Subject: [PATCH 13/19] Remove spurious mirror_uint8_ts declaration, fix issue #375 --- libnfc/mirror-subr.h | 1 - 1 file changed, 1 deletion(-) diff --git a/libnfc/mirror-subr.h b/libnfc/mirror-subr.h index 2f53bc9..4410bde 100644 --- a/libnfc/mirror-subr.h +++ b/libnfc/mirror-subr.h @@ -39,6 +39,5 @@ uint8_t mirror(uint8_t bt); uint32_t mirror32(uint32_t ui32Bits); uint64_t mirror64(uint64_t ui64Bits); -void mirror_uint8_ts(uint8_t *pbts, size_t szLen); #endif // _LIBNFC_MIRROR_SUBR_H_ From 968f59a988323e9cc42c05ea9bf83ac168912375 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 16 Feb 2017 23:05:02 +0100 Subject: [PATCH 14/19] Remove unneeded test, fix issue #376 --- libnfc/nfc-internal.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libnfc/nfc-internal.c b/libnfc/nfc-internal.c index b0beae1..68ecd34 100644 --- a/libnfc/nfc-internal.c +++ b/libnfc/nfc-internal.c @@ -242,7 +242,6 @@ connstring_decode(const nfc_connstring connstring, const char *driver_name, cons int res = sscanf(connstring, format, param0, param1, param2); if (res < 1 || ((0 != strcmp(param0, driver_name)) && - (bus_name != NULL) && (0 != strcmp(param0, bus_name)))) { // Driver name does not match. res = 0; From 20a1b978f356c0601ee0151ec38cf589f0bd68ee Mon Sep 17 00:00:00 2001 From: Emmanuel Dreyfus Date: Tue, 20 Dec 2016 16:46:46 +0100 Subject: [PATCH 15/19] NetBSD definition for CCID ioctl --- libnfc/drivers/acr122_pcsc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libnfc/drivers/acr122_pcsc.c b/libnfc/drivers/acr122_pcsc.c index 6d7c9e6..93af3aa 100644 --- a/libnfc/drivers/acr122_pcsc.c +++ b/libnfc/drivers/acr122_pcsc.c @@ -59,7 +59,7 @@ # define IOCTL_CCID_ESCAPE_SCARD_CTL_CODE SCARD_CTL_CODE(3500) #elif defined(__APPLE__) # define IOCTL_CCID_ESCAPE_SCARD_CTL_CODE (((0x31) << 16) | ((3500) << 2)) -#elif defined (__FreeBSD__) || defined (__OpenBSD__) +#elif defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__NetBSD__) # define IOCTL_CCID_ESCAPE_SCARD_CTL_CODE (((0x31) << 16) | ((3500) << 2)) #elif defined (__linux__) # include From e26fe912fdef38064bd01228c91567466bc2f367 Mon Sep 17 00:00:00 2001 From: Emmanuel Dreyfus Date: Tue, 20 Dec 2016 16:48:06 +0100 Subject: [PATCH 16/19] NetBSD serial ports --- libnfc/buses/uart.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libnfc/buses/uart.c b/libnfc/buses/uart.c index 7f14532..b9b6121 100644 --- a/libnfc/buses/uart.c +++ b/libnfc/buses/uart.c @@ -77,6 +77,8 @@ const char *serial_ports_device_radix[] = { "tty.SLAB_USBtoUART", "tty.usbserial", "tty.usbmodem", NULL }; # elif defined (__FreeBSD__) || defined (__OpenBSD__) || defined(__FreeBSD_kernel__) const char *serial_ports_device_radix[] = { "cuaU", "cuau", NULL }; +# elif defined (__NetBSD__) +const char *serial_ports_device_radix[] = { "tty0", "ttyC", "ttyS", "ttyU", "ttyY" , NULL }; # elif defined (__linux__) || defined (__CYGWIN__) const char *serial_ports_device_radix[] = { "ttyUSB", "ttyS", "ttyACM", "ttyAMA", "ttyO", NULL }; # else From 11bcf05a75c5ff539dfd0ab008aed583f70c307f Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 16 Feb 2017 23:12:38 +0100 Subject: [PATCH 17/19] Fix typo. Fix issue #377 --- libnfc/nfc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libnfc/nfc.c b/libnfc/nfc.c index 97451a1..42d4ab7 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -645,7 +645,7 @@ nfc_initiator_poll_target(nfc_device *pnd, * @param pnd \a nfc_device struct pointer that represent currently used device * @param ndm desired D.E.P. mode (\a NDM_ACTIVE or \a NDM_PASSIVE for active, respectively passive mode) * @param nbr desired baud rate - * @param ndiInitiator pointer \a nfc_dep_info struct that contains \e NFCID3 and \e General \e Bytes to set to the initiator device (optionnal, can be \e NULL) + * @param pndiInitiator pointer \a nfc_dep_info struct that contains \e NFCID3 and \e General \e Bytes to set to the initiator device (optionnal, can be \e NULL) * @param[out] pnt is a \a nfc_target struct pointer where target information will be put. * @param timeout in milliseconds * @@ -673,7 +673,7 @@ nfc_initiator_select_dep_target(nfc_device *pnd, * @param pnd \a nfc_device struct pointer that represent currently used device * @param ndm desired D.E.P. mode (\a NDM_ACTIVE or \a NDM_PASSIVE for active, respectively passive mode) * @param nbr desired baud rate - * @param ndiInitiator pointer \a nfc_dep_info struct that contains \e NFCID3 and \e General \e Bytes to set to the initiator device (optionnal, can be \e NULL) + * @param pndiInitiator pointer \a nfc_dep_info struct that contains \e NFCID3 and \e General \e Bytes to set to the initiator device (optionnal, can be \e NULL) * @param[out] pnt is a \a nfc_target struct pointer where target information will be put. * @param timeout in milliseconds * From b86b7efb10273e4a53915c3c797757fbf53050ca Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 17 Feb 2017 09:56:31 +0100 Subject: [PATCH 18/19] Fix number of blocks written A strange move changed the way written pages are bound in commit ed62b01a. As a result the last 3 blocks weren't written anymore. --- utils/nfc-mfultralight.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/nfc-mfultralight.c b/utils/nfc-mfultralight.c index 4b9f39d..cfafad0 100644 --- a/utils/nfc-mfultralight.c +++ b/utils/nfc-mfultralight.c @@ -276,7 +276,7 @@ write_card(bool write_otp, bool write_lock, bool write_uid) } } - for (uint32_t page = uiSkippedPages; page <= ((uiBlocks / 4) * 4); page++) { + for (uint32_t page = uiSkippedPages; page <= uiBlocks; page++) { if ((page == 0x2) && (!write_lock)) { printf("s"); uiSkippedPages++; From d808802b16f476c3960ffa1b6f4d1cadb7bb389d Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 17 Feb 2017 10:11:34 +0100 Subject: [PATCH 19/19] typos --- utils/nfc-mfultralight.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/utils/nfc-mfultralight.c b/utils/nfc-mfultralight.c index cfafad0..63ea215 100644 --- a/utils/nfc-mfultralight.c +++ b/utils/nfc-mfultralight.c @@ -98,7 +98,7 @@ read_card(void) { uint32_t page; bool bFailure = false; - uint32_t uiReadedPages = 0; + uint32_t uiReadPages = 0; printf("Reading %d pages |", uiBlocks + 1); @@ -111,13 +111,13 @@ read_card(void) break; } - print_success_or_failure(bFailure, &uiReadedPages); - print_success_or_failure(bFailure, &uiReadedPages); - print_success_or_failure(bFailure, &uiReadedPages); - print_success_or_failure(bFailure, &uiReadedPages); + print_success_or_failure(bFailure, &uiReadPages); + print_success_or_failure(bFailure, &uiReadPages); + print_success_or_failure(bFailure, &uiReadPages); + print_success_or_failure(bFailure, &uiReadPages); } printf("|\n"); - printf("Done, %d of %d pages read.\n", uiReadedPages, uiBlocks + 1); + printf("Done, %d of %d pages read.\n", uiReadPages, uiBlocks + 1); fflush(stdout); return (!bFailure); @@ -234,7 +234,7 @@ write_card(bool write_otp, bool write_lock, bool write_uid) { uint32_t uiBlock = 0; bool bFailure = false; - uint32_t uiWritenPages = 0; + uint32_t uiWrittenPages = 0; uint32_t uiSkippedPages = 0; char buffer[BUFSIZ]; @@ -306,10 +306,10 @@ write_card(bool write_otp, bool write_lock, bool write_uid) if (!nfc_initiator_mifare_cmd(pnd, MC_WRITE, page, &mp)) bFailure = true; - print_success_or_failure(bFailure, &uiWritenPages); + print_success_or_failure(bFailure, &uiWrittenPages); } printf("|\n"); - printf("Done, %d of %d pages written (%d pages skipped).\n", uiWritenPages, uiBlocks + 1, uiSkippedPages); + printf("Done, %d of %d pages written (%d pages skipped).\n", uiWrittenPages, uiBlocks + 1, uiSkippedPages); return true; }