From 4b97700352bc5195c5fce1752ba8c534739d9f16 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Mon, 28 Jan 2013 13:57:40 +0100 Subject: [PATCH 01/32] Removes exit() calls Fixes issue 220 exit() was used to run abort-driven development while API changed, I forgot to remove them, sorry for that :-) --- libnfc/nfc.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/libnfc/nfc.c b/libnfc/nfc.c index 82e1ea7..272f8e0 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -114,10 +114,6 @@ const struct nfc_driver *nfc_drivers[] = { void nfc_init(nfc_context **context) { - if (!context) { - printf("Error: NULL context is not supported anymore, please fix your code.\n"); - exit(EXIT_FAILURE); - } *context = nfc_context_new(); } @@ -236,11 +232,6 @@ nfc_list_devices(nfc_context *context, nfc_connstring connstrings[], const size_ const struct nfc_driver *ndr; const struct nfc_driver **pndr = nfc_drivers; - if (!context) { - printf("NULL context is not supported anymore! Please fix your code.\n"); - exit(EXIT_FAILURE); - } - // Load manually configured devices (from config file and env variables) // TODO From env var... for (uint32_t i = 0; i < context->user_defined_device_count; i++) { @@ -251,8 +242,10 @@ nfc_list_devices(nfc_context *context, nfc_connstring connstrings[], const size_ char *old_env_log_level = NULL; // do it silently if (env_log_level) { - if ((old_env_log_level = malloc(strlen(env_log_level) + 1)) == NULL) - exit(EXIT_FAILURE); + if ((old_env_log_level = malloc(strlen(env_log_level) + 1)) == NULL) { + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to malloc()"); + return 0; + } strcpy(old_env_log_level, env_log_level); } setenv("LIBNFC_LOG_LEVEL", "0", 1); From b675db73beafcd7caff6a8ad1c0145155e5791fb Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 29 Jan 2013 13:52:53 +0100 Subject: [PATCH 02/32] nfc-scan-device: fix option -i --- utils/nfc-scan-device.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/utils/nfc-scan-device.c b/utils/nfc-scan-device.c index 39d5c2b..0ff6393 100644 --- a/utils/nfc-scan-device.c +++ b/utils/nfc-scan-device.c @@ -77,11 +77,6 @@ main(int argc, const char *argv[]) bool verbose = false; nfc_context *context; - nfc_init(&context); - - // Display libnfc version - acLibnfcVersion = nfc_version(); - printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion); // Get commandline options for (int arg = 1; arg < argc; arg++) { @@ -91,6 +86,7 @@ main(int argc, const char *argv[]) } else if (0 == strcmp(argv[arg], "-v")) { verbose = true; } else if (0 == strcmp(argv[arg], "-i")) { + // This has to be done before the call to nfc_init() setenv("LIBNFC_INTRUSIVE_SCAN", "yes", 1); } else { ERR("%s is not supported option.", argv[arg]); @@ -99,6 +95,12 @@ main(int argc, const char *argv[]) } } + nfc_init(&context); + + // Display libnfc version + acLibnfcVersion = nfc_version(); + printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion); + #ifdef HAVE_LIBUSB # ifdef DEBUG usb_set_debug(4); From cd2b03a08a4f73004c32031b358b48e99044af5f Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Wed, 30 Jan 2013 00:10:24 +0100 Subject: [PATCH 03/32] Add timeout parameter to nfc_emulate_target() function. Fixes issue 219. Thanks to raidolinja. --- ChangeLog | 6 ++++++ NEWS | 7 +++++++ examples/nfc-emulate-forum-tag2.c | 2 +- include/nfc/nfc-emulation.h | 2 +- libnfc/nfc-emulation.c | 25 ++++++++++++++++++------- utils/nfc-emulate-forum-tag4.c | 2 +- 6 files changed, 34 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index da1a693..0c837f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Jan TBD, 2013 - 1.7.0-rc3 (release candidate) +-------------------------------------------- + +Changes: + - nfc_emulate_target() now takes timeout parameter + Jan 20, 2013 - 1.7.0-rc2 (release candidate) -------------------------------------------- diff --git a/NEWS b/NEWS index 62f7aa0..055aa98 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,10 @@ +New in 1.7.0-rc3: + +API Changes: + + * Functions + - Add timeout param to nfc_emulate_target() + New in 1.7.0-rc2: Configuration: diff --git a/examples/nfc-emulate-forum-tag2.c b/examples/nfc-emulate-forum-tag2.c index 325e256..8240a4e 100644 --- a/examples/nfc-emulate-forum-tag2.c +++ b/examples/nfc-emulate-forum-tag2.c @@ -197,7 +197,7 @@ main(int argc, char *argv[]) printf("NFC device: %s opened\n", nfc_device_get_name(pnd)); printf("Emulating NDEF tag now, please touch it with a second NFC device\n"); - if (nfc_emulate_target(pnd, &emulator) < 0) { + if (nfc_emulate_target(pnd, &emulator, 0) < 0) { goto error; } diff --git a/include/nfc/nfc-emulation.h b/include/nfc/nfc-emulation.h index 1a8576f..430f5b1 100644 --- a/include/nfc/nfc-emulation.h +++ b/include/nfc/nfc-emulation.h @@ -55,7 +55,7 @@ extern "C" { void *data; }; - NFC_EXPORT int nfc_emulate_target(nfc_device *pnd, struct nfc_emulator *emulator); + NFC_EXPORT int nfc_emulate_target(nfc_device *pnd, struct nfc_emulator *emulator, const int timeout); #ifdef __cplusplus } diff --git a/libnfc/nfc-emulation.c b/libnfc/nfc-emulation.c index 1085e32..e98d625 100644 --- a/libnfc/nfc-emulation.c +++ b/libnfc/nfc-emulation.c @@ -19,23 +19,33 @@ */ /** -* @file nfc-emulation.c -* @brief Provide a small API to ease emulation in libnfc -*/ + * @file nfc-emulation.c + * @brief Provide a small API to ease emulation in libnfc + */ #include #include #include "iso7816.h" +/** @ingroup emulation + * @brief Emulate a target + * @return Returns 0 on success, otherwise returns libnfc's error code (negative value). + * + * @param pnd \a nfc_device struct pointer that represents currently used device + * @param emulator \nfc_emulator struct point that handles input/output functions + * + * If timeout equals to 0, the function blocks indefinitely (until an error is raised or function is completed) + * If timeout equals to -1, the default timeout will be used + */ int -nfc_emulate_target(nfc_device *pnd, struct nfc_emulator *emulator) +nfc_emulate_target(nfc_device *pnd, struct nfc_emulator *emulator, const int timeout) { uint8_t abtRx[ISO7816_SHORT_R_APDU_MAX_LEN]; uint8_t abtTx[ISO7816_SHORT_C_APDU_MAX_LEN]; int res; - if ((res = nfc_target_init(pnd, emulator->target, abtRx, sizeof(abtRx), 0)) < 0) { + if ((res = nfc_target_init(pnd, emulator->target, abtRx, sizeof(abtRx), timeout)) < 0) { return res; } @@ -44,12 +54,12 @@ nfc_emulate_target(nfc_device *pnd, struct nfc_emulator *emulator) while (io_res >= 0) { io_res = emulator->state_machine->io(emulator, abtRx, szRx, abtTx, sizeof(abtTx)); if (io_res > 0) { - if ((res = nfc_target_send_bytes(pnd, abtTx, io_res, 0)) < 0) { + if ((res = nfc_target_send_bytes(pnd, abtTx, io_res, timeout)) < 0) { return res; } } if (io_res >= 0) { - if ((res = nfc_target_receive_bytes(pnd, abtRx, sizeof(abtRx), 0)) < 0) { + if ((res = nfc_target_receive_bytes(pnd, abtRx, sizeof(abtRx), timeout)) < 0) { return res; } szRx = res; @@ -57,3 +67,4 @@ nfc_emulate_target(nfc_device *pnd, struct nfc_emulator *emulator) } return (io_res < 0) ? io_res : 0; } + diff --git a/utils/nfc-emulate-forum-tag4.c b/utils/nfc-emulate-forum-tag4.c index 8404cfb..e17f090 100644 --- a/utils/nfc-emulate-forum-tag4.c +++ b/utils/nfc-emulate-forum-tag4.c @@ -382,7 +382,7 @@ main(int argc, char *argv[]) printf("NFC device: %s opened\n", nfc_device_get_name(pnd)); printf("Emulating NDEF tag now, please touch it with a second NFC device\n"); - if (0 != nfc_emulate_target(pnd, &emulator)) { // contains already nfc_target_init() call + if (0 != nfc_emulate_target(pnd, &emulator, 0)) { // contains already nfc_target_init() call nfc_perror(pnd, "nfc_emulate_target"); } From 98948172b40e831c3235f2677e77d37c1fa26799 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Wed, 30 Jan 2013 00:56:47 +0100 Subject: [PATCH 04/32] Fixes pn53x_usb timeout while bulk write. Thanks to Tredger for reporting. Fixes issue 223. --- ChangeLog | 3 +++ libnfc/drivers/pn53x_usb.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 0c837f1..c5de480 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,9 @@ Jan TBD, 2013 - 1.7.0-rc3 (release candidate) -------------------------------------------- +Fixes: + - Fix pn53x_usb bulk write timeout + Changes: - nfc_emulate_target() now takes timeout parameter diff --git a/libnfc/drivers/pn53x_usb.c b/libnfc/drivers/pn53x_usb.c index 11f3164..7440c80 100644 --- a/libnfc/drivers/pn53x_usb.c +++ b/libnfc/drivers/pn53x_usb.c @@ -652,7 +652,7 @@ read: int pn53x_usb_ack(nfc_device *pnd) { - return pn53x_usb_bulk_write(DRIVER_DATA(pnd), (uint8_t *) pn53x_ack_frame, sizeof(pn53x_ack_frame), -1); + return pn53x_usb_bulk_write(DRIVER_DATA(pnd), (uint8_t *) pn53x_ack_frame, sizeof(pn53x_ack_frame), 1000); } int From a303b9e33c573416aa389fcef12e107d154b585a Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Wed, 30 Jan 2013 01:15:41 +0100 Subject: [PATCH 05/32] Updates ChangeLog --- ChangeLog | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index c5de480..c3a7d95 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,12 @@ Jan TBD, 2013 - 1.7.0-rc3 (release candidate) Fixes: - Fix pn53x_usb bulk write timeout + - Fix BCC in nfc-emulate-uid example + - Fix nfc-relay-picc example + - Fix a miss returned value within some internal functions (user program could + be affected) + - Fix nfc-scan-device -i option + - Remove wrong exit() calls in library Changes: - nfc_emulate_target() now takes timeout parameter From 5446242094ab31d9e42d531ec863d21324f5939f Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 30 Jan 2013 01:27:18 +0100 Subject: [PATCH 06/32] acr122_usb: remove pn53x_idle support. Fixes issue #217 --- libnfc/drivers/acr122_usb.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libnfc/drivers/acr122_usb.c b/libnfc/drivers/acr122_usb.c index e469aba..020a6b9 100644 --- a/libnfc/drivers/acr122_usb.c +++ b/libnfc/drivers/acr122_usb.c @@ -552,8 +552,6 @@ acr122_usb_close(nfc_device *pnd) { acr122_usb_ack(pnd); - pn53x_idle(pnd); - int res; if ((res = usb_release_interface(DRIVER_DATA(pnd)->pudh, 0)) < 0) { log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to release USB interface (%s)", _usb_strerror(res)); @@ -895,5 +893,5 @@ const struct nfc_driver acr122_usb_driver = { .device_get_information_about = pn53x_get_information_about, .abort_command = acr122_usb_abort_command, - .idle = pn53x_idle, + .idle = NULL, // Even with a PN532, PowerDown doesn't seem a good idea here }; From f7010faf18d53073d163a1fbe3d1968baa4fd29c Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 31 Jan 2013 01:05:28 +0100 Subject: [PATCH 07/32] Changelog --- ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog b/ChangeLog index c3a7d95..3575187 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,7 @@ Fixes: be affected) - Fix nfc-scan-device -i option - Remove wrong exit() calls in library + - Fix issue in driver acr122_usb affecting Touchatag Changes: - nfc_emulate_target() now takes timeout parameter From db8033622a0aeb118c7f007818d8c840ce6a86db Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 31 Jan 2013 01:08:23 +0100 Subject: [PATCH 08/32] acr122_pcsc: fix log category --- 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 f189167..a0f6629 100644 --- a/libnfc/drivers/acr122_pcsc.c +++ b/libnfc/drivers/acr122_pcsc.c @@ -80,7 +80,7 @@ #define ACR122_PCSC_RESPONSE_LEN 268 #define LOG_GROUP NFC_LOG_GROUP_DRIVER -#define LOG_CATEGORY "libnfc.driver.acr122" +#define LOG_CATEGORY "libnfc.driver.acr122_pcsc" // Internal data struct const struct pn53x_io acr122_pcsc_io; From 1682a861668aee5a1cf0a58007648eb84f138a40 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 31 Jan 2013 01:15:03 +0100 Subject: [PATCH 09/32] Add driver-dependent PowerDown --- libnfc/drivers/acr122_pcsc.c | 4 +++- libnfc/drivers/acr122_usb.c | 4 +++- libnfc/drivers/acr122s.c | 4 +++- libnfc/drivers/arygon.c | 4 +++- libnfc/drivers/pn532_uart.c | 3 ++- libnfc/drivers/pn53x_usb.c | 3 ++- libnfc/nfc-internal.h | 1 + 7 files changed, 17 insertions(+), 6 deletions(-) diff --git a/libnfc/drivers/acr122_pcsc.c b/libnfc/drivers/acr122_pcsc.c index a0f6629..b87cd2b 100644 --- a/libnfc/drivers/acr122_pcsc.c +++ b/libnfc/drivers/acr122_pcsc.c @@ -516,6 +516,8 @@ const struct nfc_driver acr122_pcsc_driver = { .device_get_information_about = pn53x_get_information_about, .abort_command = NULL, // Abort is not supported in this driver - .idle = NULL, // Idle is not supported in this driver + .idle = pn53x_idle, + /* Even if PN532, PowerDown is not recommended on those devices */ + .powerdown = NULL, }; diff --git a/libnfc/drivers/acr122_usb.c b/libnfc/drivers/acr122_usb.c index 020a6b9..533a3ed 100644 --- a/libnfc/drivers/acr122_usb.c +++ b/libnfc/drivers/acr122_usb.c @@ -893,5 +893,7 @@ const struct nfc_driver acr122_usb_driver = { .device_get_information_about = pn53x_get_information_about, .abort_command = acr122_usb_abort_command, - .idle = NULL, // Even with a PN532, PowerDown doesn't seem a good idea here + .idle = pn53x_idle, + /* Even if PN532, PowerDown is not recommended on those devices */ + .powerdown = NULL, }; diff --git a/libnfc/drivers/acr122s.c b/libnfc/drivers/acr122s.c index a2f4fa3..2c018d2 100644 --- a/libnfc/drivers/acr122s.c +++ b/libnfc/drivers/acr122s.c @@ -726,5 +726,7 @@ const struct nfc_driver acr122s_driver = { .device_get_information_about = pn53x_get_information_about, .abort_command = acr122s_abort_command, - .idle = NULL, + .idle = pn53x_idle, + /* Even if PN532, PowerDown is not recommended on those devices */ + .powerdown = NULL, }; diff --git a/libnfc/drivers/arygon.c b/libnfc/drivers/arygon.c index 94fcda0..315f36e 100644 --- a/libnfc/drivers/arygon.c +++ b/libnfc/drivers/arygon.c @@ -587,6 +587,8 @@ const struct nfc_driver arygon_driver = { .device_get_information_about = pn53x_get_information_about, .abort_command = arygon_abort_command, - .idle = NULL, // FIXME arygon driver does not support idle() + .idle = pn53x_idle, + /* Even if PN532, PowerDown is not recommended on those devices */ + .powerdown = NULL, }; diff --git a/libnfc/drivers/pn532_uart.c b/libnfc/drivers/pn532_uart.c index 3c9f2d6..10d71bd 100644 --- a/libnfc/drivers/pn532_uart.c +++ b/libnfc/drivers/pn532_uart.c @@ -528,6 +528,7 @@ const struct nfc_driver pn532_uart_driver = { .device_get_information_about = pn53x_get_information_about, .abort_command = pn532_uart_abort_command, - .idle = pn53x_idle, + .idle = pn53x_idle, + .powerdown = pn53x_PowerDown, }; diff --git a/libnfc/drivers/pn53x_usb.c b/libnfc/drivers/pn53x_usb.c index 7440c80..f0580ff 100644 --- a/libnfc/drivers/pn53x_usb.c +++ b/libnfc/drivers/pn53x_usb.c @@ -791,5 +791,6 @@ const struct nfc_driver pn53x_usb_driver = { .device_get_information_about = pn53x_get_information_about, .abort_command = pn53x_usb_abort_command, - .idle = pn53x_idle, + .idle = pn53x_idle, + .powerdown = pn53x_PowerDown, }; diff --git a/libnfc/nfc-internal.h b/libnfc/nfc-internal.h index 5d1ff03..30e4947 100644 --- a/libnfc/nfc-internal.h +++ b/libnfc/nfc-internal.h @@ -147,6 +147,7 @@ struct nfc_driver { int (*abort_command)(struct nfc_device *pnd); int (*idle)(struct nfc_device *pnd); + int (*powerdown)(struct nfc_device *pnd); }; # define DEVICE_NAME_LENGTH 256 From 683505f39b0c4b738e96286edc0a33ae969f9507 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 31 Jan 2013 01:16:37 +0100 Subject: [PATCH 10/32] pn53x_idle: call driver-dependent PowerDown & do InRelease first, skip redundant InDeselect --- libnfc/chips/pn53x.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index cd7c9d5..92ce658 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -947,30 +947,25 @@ pn53x_idle(struct nfc_device *pnd) if ((res = pn53x_InRelease(pnd, 0)) < 0) { return res; } - if (CHIP_DATA(pnd)->type == PN532) { + if ((CHIP_DATA(pnd)->type == PN532) && (pnd->driver->powerdown)) { // Use PowerDown to go in "Low VBat" power mode - if ((res = pn53x_PowerDown(pnd)) < 0) { + if ((res = pnd->driver->powerdown(pnd)) < 0) { return res; } } break; case INITIATOR: - // Deselect all active communications - if ((res = pn53x_InDeselect(pnd, 0)) < 0) { + // Use InRelease to go in "Standby mode" + if ((res = pn53x_InRelease(pnd, 0)) < 0) { return res; } // Disable RF field to avoid heating if ((res = nfc_device_set_property_bool(pnd, NP_ACTIVATE_FIELD, false)) < 0) { return res; } - if (CHIP_DATA(pnd)->type == PN532) { + if ((CHIP_DATA(pnd)->type == PN532) && (pnd->driver->powerdown)) { // Use PowerDown to go in "Low VBat" power mode - if ((res = pn53x_PowerDown(pnd)) < 0) { - return res; - } - } else { - // Use InRelease to go in "Standby mode" - if ((res = pn53x_InRelease(pnd, 0)) < 0) { + if ((res = pnd->driver->powerdown(pnd)) < 0) { return res; } } From 8bc7a1c2918ceb1cb9afc87d3649a75f25654cab Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 31 Jan 2013 01:18:23 +0100 Subject: [PATCH 11/32] call idle() from driver-dependent close() rather than from nfc_close() as some driver still need to do an ack() before --- ChangeLog | 1 + libnfc/drivers/acr122_pcsc.c | 2 ++ libnfc/drivers/acr122_usb.c | 1 + libnfc/drivers/acr122s.c | 2 ++ libnfc/drivers/arygon.c | 2 ++ libnfc/drivers/pn532_uart.c | 2 ++ libnfc/drivers/pn53x_usb.c | 4 ++-- libnfc/nfc.c | 3 --- 8 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3575187..e7b104b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,7 @@ Fixes: - Fix nfc-scan-device -i option - Remove wrong exit() calls in library - Fix issue in driver acr122_usb affecting Touchatag + - Reenable some idle in all drivers, add selectively PowerDown when possible Changes: - nfc_emulate_target() now takes timeout parameter diff --git a/libnfc/drivers/acr122_pcsc.c b/libnfc/drivers/acr122_pcsc.c index b87cd2b..105a392 100644 --- a/libnfc/drivers/acr122_pcsc.c +++ b/libnfc/drivers/acr122_pcsc.c @@ -324,6 +324,8 @@ error: static void acr122_pcsc_close(nfc_device *pnd) { + pn53x_idle(pnd); + SCardDisconnect(DRIVER_DATA(pnd)->hCard, SCARD_LEAVE_CARD); acr122_pcsc_free_scardcontext(); diff --git a/libnfc/drivers/acr122_usb.c b/libnfc/drivers/acr122_usb.c index 533a3ed..da14a60 100644 --- a/libnfc/drivers/acr122_usb.c +++ b/libnfc/drivers/acr122_usb.c @@ -551,6 +551,7 @@ static void acr122_usb_close(nfc_device *pnd) { acr122_usb_ack(pnd); + pn53x_idle(pnd); int res; if ((res = usb_release_interface(DRIVER_DATA(pnd)->pudh, 0)) < 0) { diff --git a/libnfc/drivers/acr122s.c b/libnfc/drivers/acr122s.c index 2c018d2..932d7c0 100644 --- a/libnfc/drivers/acr122s.c +++ b/libnfc/drivers/acr122s.c @@ -520,6 +520,8 @@ static void acr122s_close(nfc_device *pnd) { acr122s_deactivate_sam(pnd); + pn53x_idle(pnd); + uart_close(DRIVER_DATA(pnd)->port); #ifndef WIN32 diff --git a/libnfc/drivers/arygon.c b/libnfc/drivers/arygon.c index 315f36e..e713d4e 100644 --- a/libnfc/drivers/arygon.c +++ b/libnfc/drivers/arygon.c @@ -211,6 +211,8 @@ arygon_connstring_decode(const nfc_connstring connstring, struct arygon_descript static void arygon_close(nfc_device *pnd) { + pn53x_idle(pnd); + // Release UART port uart_close(DRIVER_DATA(pnd)->port); diff --git a/libnfc/drivers/pn532_uart.c b/libnfc/drivers/pn532_uart.c index 10d71bd..c3bcd9d 100644 --- a/libnfc/drivers/pn532_uart.c +++ b/libnfc/drivers/pn532_uart.c @@ -188,6 +188,8 @@ pn532_connstring_decode(const nfc_connstring connstring, struct pn532_uart_descr static void pn532_uart_close(nfc_device *pnd) { + pn53x_idle(pnd); + // Release UART port uart_close(DRIVER_DATA(pnd)->port); diff --git a/libnfc/drivers/pn53x_usb.c b/libnfc/drivers/pn53x_usb.c index f0580ff..6340cb7 100644 --- a/libnfc/drivers/pn53x_usb.c +++ b/libnfc/drivers/pn53x_usb.c @@ -447,14 +447,14 @@ pn53x_usb_close(nfc_device *pnd) { pn53x_usb_ack(pnd); - pn53x_idle(pnd); - if (DRIVER_DATA(pnd)->model == ASK_LOGO) { /* Set P30, P31, P32, P33, P35 to logic 1 and P34 to 0 logic */ /* ie. Switch all LEDs off and turn off progressive field */ pn53x_write_register(pnd, PN53X_SFR_P3, 0xFF, _BV(P30) | _BV(P31) | _BV(P32) | _BV(P33) | _BV(P35)); } + pn53x_idle(pnd); + int res; if ((res = usb_release_interface(DRIVER_DATA(pnd)->pudh, 0)) < 0) { log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to release USB interface (%s)", _usb_strerror(res)); diff --git a/libnfc/nfc.c b/libnfc/nfc.c index 272f8e0..b1dc537 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -209,11 +209,8 @@ void nfc_close(nfc_device *pnd) { if (pnd) { - // Go in idle mode - nfc_idle(pnd); // Close, clean up and release the device pnd->driver->close(pnd); - } } From ef82a1e4d4ced0d74261abc6cef4fab17f6bff42 Mon Sep 17 00:00:00 2001 From: Alex Lian Date: Sat, 26 Jan 2013 18:42:56 -0500 Subject: [PATCH 12/32] For Windows MinGW address the "ISO C99 requires rest arguments to be used" error --- contrib/windows.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/contrib/windows.h b/contrib/windows.h index c54e5a5..c0d213f 100644 --- a/contrib/windows.h +++ b/contrib/windows.h @@ -30,7 +30,12 @@ # include # include "win32/err.h" # if defined (__MINGW32__) -# define snprintf(S, n, F, ...) sprintf(S, F, __VA_ARGS__) +/* + * Cheating here on the snprintf to incorporate the format argument + * into the VA_ARGS. Else we get MinGW errors regarding number of arguments + * if doing a fixed string with no arguments. +*/ +# define snprintf(S, n, ...) sprintf(S, __VA_ARGS__) # define pipe(fds) _pipe(fds, 5000, _O_BINARY) # define ETIMEDOUT WSAETIMEDOUT # define ENOTSUP WSAEOPNOTSUPP From eb90c5a8db4153232dc502453c12f2fdb425b26e Mon Sep 17 00:00:00 2001 From: Alex Lian Date: Sat, 26 Jan 2013 18:43:58 -0500 Subject: [PATCH 13/32] Add CMake options for Win32 to require PCRE --- CMakeLists.txt | 9 ++++++++ cmake/modules/FindPCRE.cmake | 40 ++++++++++++++++++++++++++++++++++++ cmake/modules/Makefile.am | 1 + libnfc/CMakeLists.txt | 14 +++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 cmake/modules/FindPCRE.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 1bce778..8e3aa50 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,15 @@ IF(NOT WIN32) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libnfc.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) ENDIF(NOT WIN32) +# Require PCRE for Win32 +IF (WIN32) + FIND_PACKAGE(PCRE REQUIRED) + IF(PCRE_INCLUDE_DIRS) + INCLUDE_DIRECTORIES(${PCRE_INCLUDE_DIRS}) + LINK_DIRECTORIES(${PCRE_LIBRARY_DIRS}) + ENDIF(PCRE_INCLUDE_DIRS) +ENDIF(WIN32) + IF(PCSC_INCLUDE_DIRS) INCLUDE_DIRECTORIES(${PCSC_INCLUDE_DIRS}) LINK_DIRECTORIES(${PCSC_LIBRARY_DIRS}) diff --git a/cmake/modules/FindPCRE.cmake b/cmake/modules/FindPCRE.cmake new file mode 100644 index 0000000..0b83def --- /dev/null +++ b/cmake/modules/FindPCRE.cmake @@ -0,0 +1,40 @@ +# This CMake script wants to use pcre functionality needed for windows +# compilation. However, since PCRE isn't really a default install location +# there isn't much to search. +# +# Operating Systems Supported: +# - Windows (requires MinGW) +# Tested with Windows XP/Windows 7 +# +# This should work for both 32 bit and 64 bit systems. +# +# Author: A. Lian +# + +IF(WIN32) + IF(NOT PCRE_FOUND) + FIND_PATH(PCRE_INCLUDE_DIRS regex.h) + FIND_LIBRARY(PCRE_LIBRARIES NAMES PCRE pcre) + + IF(PCRE_INCLUDE_DIRS AND PCRE_LIBRARIES) + SET(PCRE_FOUND TRUE) + ENDIF(PCRE_INCLUDE_DIRS AND PCRE_LIBRARIES) + ENDIF(NOT PCRE_FOUND) + + IF(PCRE_FOUND) + IF(NOT PCRE_FIND_QUIETLY) + MESSAGE(STATUS "Found PCRE: ${PCRE_LIBRARIES} ${PCRE_INCLUDE_DIRS}") + ENDIF (NOT PCRE_FIND_QUIETLY) + ELSE(PCRE_FOUND) + IF(PCRE_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find PCRE") + ENDIF(PCRE_FIND_REQUIRED) + ENDIF(PCRE_FOUND) + + INCLUDE(FindPackageHandleStandardArgs) + FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE DEFAULT_MSG + PCRE_LIBRARIES + PCRE_INCLUDE_DIRS + ) + +ENDIF(WIN32) diff --git a/cmake/modules/Makefile.am b/cmake/modules/Makefile.am index 52fd92d..55334ca 100644 --- a/cmake/modules/Makefile.am +++ b/cmake/modules/Makefile.am @@ -2,5 +2,6 @@ EXTRA_DIST = \ COPYING-CMAKE-SCRIPTS \ FindLIBUSB.cmake \ FindPCSC.cmake \ + FindPCRE.cmake \ UseDoxygen.cmake \ LibnfcDrivers.cmake diff --git a/libnfc/CMakeLists.txt b/libnfc/CMakeLists.txt index 491f324..9edac93 100644 --- a/libnfc/CMakeLists.txt +++ b/libnfc/CMakeLists.txt @@ -8,6 +8,16 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/buses) INCLUDE(LibnfcDrivers) +IF(WIN32) + # Windows now requires regex, so we utilize PCRE + # since Windows doesn't get the benefit of finding in CMake + # it has to be added manually + IF(PCRE_FOUND) + INCLUDE_DIRECTORIES(${PCRE_INCLUDE_DIRS}) + LINK_DIRECTORIES(${PCRE_LIBRARY_DIRS}) + ENDIF(PCRE_FOUND) +ENDIF(WIN32) + IF(PCSC_FOUND) INCLUDE_DIRECTORIES(${PCSC_INCLUDE_DIRS}) LINK_DIRECTORIES(${PCSC_LIBRARY_DIRS}) @@ -40,6 +50,10 @@ ENDIF(WIN32) SET_TARGET_PROPERTIES(nfc PROPERTIES SOVERSION 0) IF(WIN32) + IF(PCRE_FOUND) + TARGET_LINK_LIBRARIES(nfc ${PCRE_LIBRARIES}) + ENDIF(PCRE_FOUND) + # On Windows the shared (runtime) library should be either in the same # directory as the excutables or in the path, we add it to same directory INSTALL(TARGETS nfc RUNTIME DESTINATION bin COMPONENT libraries) From 9f682cc52ba0979d673c002fcfe106e34fa48197 Mon Sep 17 00:00:00 2001 From: Alex Lian Date: Sun, 27 Jan 2013 21:55:34 -0500 Subject: [PATCH 14/32] Fix enabling of LIBNFC_DEBUG_OUTPUT - inclusion of log-printf.c didn't align with needed preprocessor definitions - Added extra #error as well as preprocessor protection - fixed CMakeList to specify -DLOG as appropriate per the header log.h usage --- CMakeLists.txt | 2 +- libnfc/log-printf.c | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e3aa50..fb668b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/") # Options SET(LIBNFC_DEBUG_OUTPUT OFF CACHE BOOL "Debug output of communication with the NFC chip") IF(LIBNFC_DEBUG_OUTPUT) - ADD_DEFINITIONS(-DDEBUG -g3) + ADD_DEFINITIONS(-DDEBUG -DLOG -g3) ENDIF(LIBNFC_DEBUG_OUTPUT) # Doxygen diff --git a/libnfc/log-printf.c b/libnfc/log-printf.c index 200ecf8..75c5e27 100644 --- a/libnfc/log-printf.c +++ b/libnfc/log-printf.c @@ -25,6 +25,12 @@ #include #include +#ifndef LOG + // Leaving in a preprocessor error, as the build system should skip this + // file otherwise. + #error "No logging defined, but log-printf.c still compiled." +#else // LOG + void log_init(const nfc_context *context) { @@ -67,3 +73,5 @@ log_put(const uint8_t group, const char *category, const uint8_t priority, const } } } + +#endif // LOG From ef33827f0433f40b18dd393380ea815aad8e57ff Mon Sep 17 00:00:00 2001 From: Alex Lian Date: Sun, 27 Jan 2013 22:34:58 -0500 Subject: [PATCH 15/32] Fix setenv/unsetenv link errors by implementing a local version using Windows SetEnvironmentVariable. Untested, and does not comply with the error returns per setenv. --- contrib/win32/nfc_win32.c | 48 +++++++++++++++++++++++++++++++++++++++ contrib/windows.h | 7 ++++++ libnfc/CMakeLists.txt | 10 +++++++- 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 contrib/win32/nfc_win32.c diff --git a/contrib/win32/nfc_win32.c b/contrib/win32/nfc_win32.c new file mode 100644 index 0000000..1ebb5b9 --- /dev/null +++ b/contrib/win32/nfc_win32.c @@ -0,0 +1,48 @@ +/*- + * Public platform independent Near Field Communication (NFC) library + * + * Copyright (C) 2013 Alex Lian + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see + * + */ + +/** + * @file nfc_win32.c + * @brief Windows System compatibility + */ + +// Handle platform specific includes +#include "contrib/windows.h" + +int setenv(const char *name, const char *value, int overwrite) +{ + int exists = GetEnvironmentVariableA(name, NULL, 0); + if ((exists && overwrite) || (!exists)) + { + if (!SetEnvironmentVariableA(name, value)) + { + // Set errno here correctly + return -1; + } + return 0; + } + // Exists and overwrite is 0. + return -1; +} + +void unsetenv(const char *name) +{ + SetEnvironmentVariableA(name, NULL); +} \ No newline at end of file diff --git a/contrib/windows.h b/contrib/windows.h index c0d213f..52d936b 100644 --- a/contrib/windows.h +++ b/contrib/windows.h @@ -45,4 +45,11 @@ # define strdup _strdup # endif +/* + * setenv and unsetenv are not Windows compliant nor implemented in MinGW. + * These declarations get rid of the "implicit declaration warning." + */ +int setenv(const char *name, const char *value, int overwrite); +void unsetenv(const char *name); + #endif diff --git a/libnfc/CMakeLists.txt b/libnfc/CMakeLists.txt index 9edac93..f26d8ba 100644 --- a/libnfc/CMakeLists.txt +++ b/libnfc/CMakeLists.txt @@ -1,3 +1,11 @@ +# Windows MinGW workarounds +IF(WIN32) + message("Adding in contrib win32 sources") + SET(WINDOWS_SOURCES ../contrib/win32/nfc_win32) + INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32) + message("Win32: " ${WINDOWS_SOURCES}) +ENDIF(WIN32) + # Library's chips SET(CHIPS_SOURCES chips/pn53x) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/chips) @@ -29,7 +37,7 @@ IF(LIBUSB_FOUND) ENDIF(LIBUSB_FOUND) # Library -SET(LIBRARY_SOURCES nfc nfc-device nfc-emulation nfc-internal conf iso14443-subr mirror-subr target-subr ${DRIVERS_SOURCES} ${BUSES_SOURCES} ${CHIPS_SOURCES}) +SET(LIBRARY_SOURCES nfc nfc-device nfc-emulation nfc-internal conf iso14443-subr mirror-subr target-subr log ${DRIVERS_SOURCES} ${BUSES_SOURCES} ${CHIPS_SOURCES} ${WINDOWS_SOURCES}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) IF(LIBNFC_DEBUG_OUTPUT) LIST(APPEND LIBRARY_SOURCES log-printf) From 3c9d9a872cc3800431d68529fc2eed8a110e6dbf Mon Sep 17 00:00:00 2001 From: Alex Lian Date: Sun, 27 Jan 2013 23:08:22 -0500 Subject: [PATCH 16/32] Fix all utils compilation on windows. - As nfc-utils now references str_nfc_target from the lib itself, so the static lib was not properly referencing the libnfc itself, so the final utility link would fail. - Simply added the libnfc as a target for the static nfcutils library internal to cmake --- utils/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 491fdfc..ae622ff 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -11,6 +11,7 @@ SET(UTILS-SOURCES ADD_LIBRARY(nfcutils STATIC nfc-utils.c ) +TARGET_LINK_LIBRARIES(nfcutils nfc) # Examples FOREACH(source ${UTILS-SOURCES}) From 9eeaf33b94338d1e7630405a2a01ee27c3986428 Mon Sep 17 00:00:00 2001 From: Alex Lian Date: Sun, 27 Jan 2013 23:22:35 -0500 Subject: [PATCH 17/32] Windows: getopt usage in nfc-read-forum-tag3 fixed by referencing correct header --- utils/nfc-read-forum-tag3.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/utils/nfc-read-forum-tag3.c b/utils/nfc-read-forum-tag3.c index f522727..643e5f4 100644 --- a/utils/nfc-read-forum-tag3.c +++ b/utils/nfc-read-forum-tag3.c @@ -55,6 +55,10 @@ #include "nfc-utils.h" +#if defined(WIN32) && defined(__GNUC__) /* mingw compiler */ + #include +#endif + static nfc_device *pnd; static void From 87182b5a65c628a308a5c5e30ea1fec4542faa4a Mon Sep 17 00:00:00 2001 From: Alex Lian Date: Sun, 27 Jan 2013 23:24:03 -0500 Subject: [PATCH 18/32] Windows: Fix nfc-scan-device to compile by linking in contrib/nfc_win32.c Re-factored the executable call with a list that is created, so that its easier to modify per tool. --- utils/CMakeLists.txt | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index ae622ff..57f4f03 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -15,13 +15,23 @@ TARGET_LINK_LIBRARIES(nfcutils nfc) # Examples FOREACH(source ${UTILS-SOURCES}) + SET (TARGETS ${source}.c) + IF((${source} MATCHES "nfc-mfultralight") OR (${source} MATCHES "nfc-mfclassic")) - ADD_EXECUTABLE(${source} ${source}.c mifare) - ELSE() - ADD_EXECUTABLE(${source} ${source}.c) + LIST(APPEND TARGETS mifare) ENDIF((${source} MATCHES "nfc-mfultralight") OR (${source} MATCHES "nfc-mfclassic")) + + IF(${source} MATCHES "nfc-scan-device") + LIST(APPEND TARGETS ../contrib/win32/nfc_win32) + INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32) + ENDIF(${source} MATCHES "nfc-scan-device") + + ADD_EXECUTABLE(${source} ${TARGETS}) + TARGET_LINK_LIBRARIES(${source} nfc) TARGET_LINK_LIBRARIES(${source} nfcutils) + + INSTALL(TARGETS ${source} RUNTIME DESTINATION bin COMPONENT utils) ENDFOREACH(source) From 3fff5985fc03d8737cb5332d76c99daf6a034dac Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Thu, 31 Jan 2013 15:58:20 +0100 Subject: [PATCH 19/32] Moves Windows conditional code to dedicated files --- contrib/win32/unistd.h | 8 +++++++- utils/nfc-read-forum-tag3.c | 4 ---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/contrib/win32/unistd.h b/contrib/win32/unistd.h index bc7965c..851dc60 100644 --- a/contrib/win32/unistd.h +++ b/contrib/win32/unistd.h @@ -1,7 +1,7 @@ /*- * Public platform independent Near Field Communication (NFC) library * - * Copyright (C) 2011, 2012 Romuald Conty + * Copyright (C) 2011, 2012, 2013 Romuald Conty * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by the @@ -31,5 +31,11 @@ # include # define sleep(X) Sleep( X * 1000) +// With MinGW, getopt(3) is provided as separate header +#if defined(WIN32) && defined(__GNUC__) /* mingw compiler */ + #include +#endif + + #endif /* _UNISTD_H_ */ diff --git a/utils/nfc-read-forum-tag3.c b/utils/nfc-read-forum-tag3.c index 643e5f4..f522727 100644 --- a/utils/nfc-read-forum-tag3.c +++ b/utils/nfc-read-forum-tag3.c @@ -55,10 +55,6 @@ #include "nfc-utils.h" -#if defined(WIN32) && defined(__GNUC__) /* mingw compiler */ - #include -#endif - static nfc_device *pnd; static void From c01b961be0a46c492427c72258058d3036f2baa1 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Thu, 31 Jan 2013 16:04:47 +0100 Subject: [PATCH 20/32] Fixes CMake under GNU/Linux --- utils/CMakeLists.txt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 57f4f03..01a2cfb 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -21,10 +21,12 @@ FOREACH(source ${UTILS-SOURCES}) LIST(APPEND TARGETS mifare) ENDIF((${source} MATCHES "nfc-mfultralight") OR (${source} MATCHES "nfc-mfclassic")) - IF(${source} MATCHES "nfc-scan-device") - LIST(APPEND TARGETS ../contrib/win32/nfc_win32) - INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32) - ENDIF(${source} MATCHES "nfc-scan-device") + IF(WIN32) + IF(${source} MATCHES "nfc-scan-device") + LIST(APPEND TARGETS ../contrib/win32/nfc_win32) + INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32) + ENDIF(${source} MATCHES "nfc-scan-device") + ENDIF(WIN32) ADD_EXECUTABLE(${source} ${TARGETS}) From acdde1088cca425c71ab8270783c69c1701112cb Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Thu, 31 Jan 2013 16:09:41 +0100 Subject: [PATCH 21/32] Renames contrib/win32/nfc_win32.c to contrib/win32/stdlib.c --- contrib/win32/{nfc_win32.c => stdlib.c} | 4 ++-- libnfc/CMakeLists.txt | 2 +- utils/CMakeLists.txt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename contrib/win32/{nfc_win32.c => stdlib.c} (98%) diff --git a/contrib/win32/nfc_win32.c b/contrib/win32/stdlib.c similarity index 98% rename from contrib/win32/nfc_win32.c rename to contrib/win32/stdlib.c index 1ebb5b9..c1edfe8 100644 --- a/contrib/win32/nfc_win32.c +++ b/contrib/win32/stdlib.c @@ -19,7 +19,7 @@ */ /** - * @file nfc_win32.c + * @file stdlib.c * @brief Windows System compatibility */ @@ -45,4 +45,4 @@ int setenv(const char *name, const char *value, int overwrite) void unsetenv(const char *name) { SetEnvironmentVariableA(name, NULL); -} \ No newline at end of file +} diff --git a/libnfc/CMakeLists.txt b/libnfc/CMakeLists.txt index f26d8ba..6bed790 100644 --- a/libnfc/CMakeLists.txt +++ b/libnfc/CMakeLists.txt @@ -1,7 +1,7 @@ # Windows MinGW workarounds IF(WIN32) message("Adding in contrib win32 sources") - SET(WINDOWS_SOURCES ../contrib/win32/nfc_win32) + SET(WINDOWS_SOURCES ../contrib/win32/stdlib) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32) message("Win32: " ${WINDOWS_SOURCES}) ENDIF(WIN32) diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 01a2cfb..2b828cb 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -23,7 +23,7 @@ FOREACH(source ${UTILS-SOURCES}) IF(WIN32) IF(${source} MATCHES "nfc-scan-device") - LIST(APPEND TARGETS ../contrib/win32/nfc_win32) + LIST(APPEND TARGETS ../contrib/win32/stdlib) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32) ENDIF(${source} MATCHES "nfc-scan-device") ENDIF(WIN32) From 519dd8f8e2e9dd23bd89826109bb256dfe4072ae Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Thu, 31 Jan 2013 16:12:14 +0100 Subject: [PATCH 22/32] make style --- contrib/win32/stdlib.c | 6 ++---- contrib/win32/unistd.h | 2 +- contrib/windows.h | 2 +- libnfc/log-printf.c | 6 +++--- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/contrib/win32/stdlib.c b/contrib/win32/stdlib.c index c1edfe8..87cbd4e 100644 --- a/contrib/win32/stdlib.c +++ b/contrib/win32/stdlib.c @@ -29,10 +29,8 @@ int setenv(const char *name, const char *value, int overwrite) { int exists = GetEnvironmentVariableA(name, NULL, 0); - if ((exists && overwrite) || (!exists)) - { - if (!SetEnvironmentVariableA(name, value)) - { + if ((exists && overwrite) || (!exists)) { + if (!SetEnvironmentVariableA(name, value)) { // Set errno here correctly return -1; } diff --git a/contrib/win32/unistd.h b/contrib/win32/unistd.h index 851dc60..89aeda8 100644 --- a/contrib/win32/unistd.h +++ b/contrib/win32/unistd.h @@ -33,7 +33,7 @@ // With MinGW, getopt(3) is provided as separate header #if defined(WIN32) && defined(__GNUC__) /* mingw compiler */ - #include +#include #endif diff --git a/contrib/windows.h b/contrib/windows.h index 52d936b..2384d59 100644 --- a/contrib/windows.h +++ b/contrib/windows.h @@ -45,7 +45,7 @@ # define strdup _strdup # endif -/* +/* * setenv and unsetenv are not Windows compliant nor implemented in MinGW. * These declarations get rid of the "implicit declaration warning." */ diff --git a/libnfc/log-printf.c b/libnfc/log-printf.c index 75c5e27..c2feaf9 100644 --- a/libnfc/log-printf.c +++ b/libnfc/log-printf.c @@ -26,9 +26,9 @@ #include #ifndef LOG - // Leaving in a preprocessor error, as the build system should skip this - // file otherwise. - #error "No logging defined, but log-printf.c still compiled." +// Leaving in a preprocessor error, as the build system should skip this +// file otherwise. +#error "No logging defined, but log-printf.c still compiled." #else // LOG void From d26c5b248ed3d3ecfe22d825ba9a697b55b520e3 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Thu, 31 Jan 2013 16:17:37 +0100 Subject: [PATCH 23/32] Adds windows files to tarball --- contrib/win32/Makefile.am | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contrib/win32/Makefile.am b/contrib/win32/Makefile.am index 135834f..978c2ed 100644 --- a/contrib/win32/Makefile.am +++ b/contrib/win32/Makefile.am @@ -1,4 +1,6 @@ SUBDIRS = sys . EXTRA_DIST = \ - err.h + err.h \ + stdlib.c \ + unistd.h From fff6a092abbff78e75ff6776f38785cbbcf0324f Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 31 Jan 2013 16:44:37 +0100 Subject: [PATCH 24/32] Fix Readme for drivers reqs --- README | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README b/README index 905fe80..67be619 100644 --- a/README +++ b/README @@ -25,11 +25,11 @@ Requirements Some NFC drivers depends on third party software: -* pn53x_usb: +* pn53x_usb & acr122_usb: - libusb-0.1 http://libusb.sf.net -* acr122: +* acr122_pcsc: - pcsc-lite http://pcsclite.alioth.debian.org/ From 93e26b1475c0f27d7d97f96464c86dc321bc7fb2 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Thu, 31 Jan 2013 17:53:00 +0100 Subject: [PATCH 25/32] Releases libnfc 1.7.0 RC3 --- ChangeLog | 3 +++ configure.ac | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e7b104b..d5e005c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,9 @@ Fixes: Changes: - nfc_emulate_target() now takes timeout parameter +Special thanks to: + - Alex Lian (Windows support refesh) + Jan 20, 2013 - 1.7.0-rc2 (release candidate) -------------------------------------------- diff --git a/configure.ac b/configure.ac index 944835b..6fd18d7 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,7 @@ # General init # /!\ Don't forget to update 'CMakeLists.txt' too /!\ -AC_INIT([libnfc],[1.7.0-rc2],[info@libnfc.org]) +AC_INIT([libnfc],[1.7.0-rc3],[info@libnfc.org]) AC_CONFIG_MACRO_DIR([m4]) From 06bfed11b943d752220c265d411699b5007f50f1 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 31 Jan 2013 21:58:29 +0100 Subject: [PATCH 26/32] Various typos --- ChangeLog | 2 +- README | 18 +++++++++++++----- README-Windows.txt | 2 ++ debian/control | 2 +- debian/copyright | 2 +- libnfc/additional-pages.dox | 2 +- utils/mifare.c | 2 +- windows/mm/libnfc.mm | 2 +- 8 files changed, 21 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index d5e005c..7075bcd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -16,7 +16,7 @@ Changes: - nfc_emulate_target() now takes timeout parameter Special thanks to: - - Alex Lian (Windows support refesh) + - Alex Lian (Windows support refresh) Jan 20, 2013 - 1.7.0-rc2 (release candidate) -------------------------------------------- diff --git a/README b/README index 67be619..5f44476 100644 --- a/README +++ b/README @@ -10,7 +10,7 @@ General Information libnfc is a library which allows userspace application access to NFC devices. The official web site is: - http://www.libnfc.org/ + http://www.nfc-tools.org/ The official forum site is: http://www.libnfc.org/community/ @@ -23,7 +23,7 @@ Important note: this file covers POSIX systems, for Windows please read README-W Requirements ============ -Some NFC drivers depends on third party software: +Some NFC drivers depend on third party software: * pn53x_usb & acr122_usb: @@ -33,7 +33,7 @@ Some NFC drivers depends on third party software: - pcsc-lite http://pcsclite.alioth.debian.org/ -The regression test suite depend on the cutter framework: +The regression test suite depends on the cutter framework: http://cutter.sf.net Installation @@ -69,7 +69,14 @@ Please make sure to include: And anything else you think is relevant. -* How to reproduce the bug. +* A trace with debug activated. + + Reproduce the bug with debug, e.g. if it was: + $ nfc-list -v + run it as: + $ LIBNFC_LOG_LEVEL=3 nfc-list -v + +* How to reproduce the bug. Please include a short test program that exhibits the behavior. As a last resort, you can also provide a pointer to a larger piece @@ -85,7 +92,8 @@ Patches ======= Patches can be posted to http://code.google.com/p/libnfc/issues/list or -can be sent directly to libnfc's developers: http://www.libnfc.org/contact +can be sent directly to libnfc's developers: +http://nfc-tools.org/index.php?title=Contact If the patch fixes a bug, it is usually a good idea to include all the information described in "How to Report Bugs". diff --git a/README-Windows.txt b/README-Windows.txt index 5f049d1..3a322c0 100644 --- a/README-Windows.txt +++ b/README-Windows.txt @@ -1,6 +1,8 @@ *- * Public platform independent Near Field Communication (NFC) library +* Windows-specific parts: * Copyright (C) 2010, Glenn Ergeerts +* Copyright (C) 2013, Alex Lian -* Requirements diff --git a/debian/control b/debian/control index 37bb20a..9c3f8a8 100644 --- a/debian/control +++ b/debian/control @@ -4,7 +4,7 @@ Priority: extra Maintainer: Nobuhiro Iwamatsu Build-Depends: debhelper (>= 8), dh-autoreconf, libtool, pkg-config, libusb-dev Standards-Version: 3.9.4 -Homepage: http://www.libnfc.org/ +Homepage: http://www.nfc-tools.org/ Vcs-Git: https://code.googlecode.com/p/libnfc/ Vcs-Browser: http://code.google.com/p/libnfc/source/browse/ diff --git a/debian/copyright b/debian/copyright index 1e9b121..b1d6826 100644 --- a/debian/copyright +++ b/debian/copyright @@ -1,6 +1,6 @@ Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: libnfc -Source: http://www.libnfc.org/ +Source: http://libnfc.googlecode.com/ Files: * Copyright: 2009, Roel Verdult , Romuald Conty diff --git a/libnfc/additional-pages.dox b/libnfc/additional-pages.dox index 37f1268..1fc57f9 100644 --- a/libnfc/additional-pages.dox +++ b/libnfc/additional-pages.dox @@ -4,7 +4,7 @@ * @section intro_sec Introduction * This is the developer manual for \b libnfc. * libnfc is an open source library that allows you to communicate with NFC devices. For more info, see the - * libnfc homepage. + * libnfc homepage. * * @section quick_start_sec Quick start * If you are looking for libnfc's public API, you should start with the Modules page which links to the different categories of libnfc's functionality. diff --git a/utils/mifare.c b/utils/mifare.c index 6c84724..d1d7809 100644 --- a/utils/mifare.c +++ b/utils/mifare.c @@ -47,7 +47,7 @@ * @note There are three different types of information (Authenticate, Data and Value). * * First an authentication must take place using Key A or B. It requires a 48 bit Key (6 bytes) and the UID. - * They are both used to initialize the internal cipher-state of the PN53X chip (http://libnfc.org/hardware/pn53x-chip). + * They are both used to initialize the internal cipher-state of the PN53X chip. * After a successful authentication it will be possible to execute other commands (e.g. Read/Write). * The MIFARE Classic Specification (http://www.nxp.com/acrobat/other/identification/M001053_MF1ICS50_rev5_3.pdf) explains more about this process. */ diff --git a/windows/mm/libnfc.mm b/windows/mm/libnfc.mm index 6d388c4..abd84ab 100644 --- a/windows/mm/libnfc.mm +++ b/windows/mm/libnfc.mm @@ -21,7 +21,7 @@ ; #define? COMPANY_PRODUCT_ICON ..\win32\libnfc.ico ;; override from company.mmh #define? UISAMPLE_DIALOG_FILE_dlgbmp nfcleft.bmp ;; override uisample.mmh -#define? UISAMPLE_BLINE_TEXT www.libnfc.org +#define? UISAMPLE_BLINE_TEXT www.nfc-tools.org #define? COMPANY_WANT_TO_INSTALL_DOCUMENTATION N ;--- Include MAKEMSI support (with my customisations and MSI branding) ------ From e81aaf53903c95aa1637c9b4968485f25326ea1e Mon Sep 17 00:00:00 2001 From: Nobuhiro Iwamatsu Date: Fri, 1 Feb 2013 08:42:09 +0900 Subject: [PATCH 27/32] Add symbols file for libnfc4 Signed-off-by: Nobuhiro Iwamatsu --- debian/libnfc4.symbols | 54 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 debian/libnfc4.symbols diff --git a/debian/libnfc4.symbols b/debian/libnfc4.symbols new file mode 100644 index 0000000..7c2303f --- /dev/null +++ b/debian/libnfc4.symbols @@ -0,0 +1,54 @@ +libnfc.so.4 libnfc4 #MINVER# + iso14443a_crc@Base 1.7.0~rc2 + iso14443a_crc_append@Base 1.7.0~rc2 + iso14443a_locate_historical_bytes@Base 1.7.0~rc2 + nfc_abort_command@Base 1.7.0~rc2 + nfc_close@Base 1.7.0~rc2 + nfc_context_free@Base 1.7.0~rc2 + nfc_context_new@Base 1.7.0~rc2 + nfc_device_free@Base 1.7.0~rc2 + nfc_device_get_connstring@Base 1.7.0~rc2 + nfc_device_get_information_about@Base 1.7.0~rc2 + nfc_device_get_last_error@Base 1.7.0~rc2 + nfc_device_get_name@Base 1.7.0~rc2 + nfc_device_get_supported_baud_rate@Base 1.7.0~rc2 + nfc_device_get_supported_modulation@Base 1.7.0~rc2 + nfc_device_new@Base 1.7.0~rc2 + nfc_device_set_property_bool@Base 1.7.0~rc2 + nfc_device_set_property_int@Base 1.7.0~rc2 + nfc_drivers@Base 1.7.0~rc2 + nfc_emulate_target@Base 1.7.0~rc2 + nfc_exit@Base 1.7.0~rc2 + nfc_idle@Base 1.7.0~rc2 + nfc_init@Base 1.7.0~rc2 + nfc_initiator_deselect_target@Base 1.7.0~rc2 + nfc_initiator_init@Base 1.7.0~rc2 + nfc_initiator_init_secure_element@Base 1.7.0~rc2 + nfc_initiator_list_passive_targets@Base 1.7.0~rc2 + nfc_initiator_poll_dep_target@Base 1.7.0~rc2 + nfc_initiator_poll_target@Base 1.7.0~rc2 + nfc_initiator_select_dep_target@Base 1.7.0~rc2 + nfc_initiator_select_passive_target@Base 1.7.0~rc2 + nfc_initiator_target_is_present@Base 1.7.0~rc2 + nfc_initiator_transceive_bits@Base 1.7.0~rc2 + nfc_initiator_transceive_bits_timed@Base 1.7.0~rc2 + nfc_initiator_transceive_bytes@Base 1.7.0~rc2 + nfc_initiator_transceive_bytes_timed@Base 1.7.0~rc2 + nfc_list_devices@Base 1.7.0~rc2 + nfc_open@Base 1.7.0~rc2 + nfc_perror@Base 1.7.0~rc2 + nfc_strerror@Base 1.7.0~rc2 + nfc_strerror_r@Base 1.7.0~rc2 + nfc_target_init@Base 1.7.0~rc2 + nfc_target_receive_bits@Base 1.7.0~rc2 + nfc_target_receive_bytes@Base 1.7.0~rc2 + nfc_target_send_bits@Base 1.7.0~rc2 + nfc_target_send_bytes@Base 1.7.0~rc2 + nfc_version@Base 1.7.0~rc2 + pn532_SAMConfiguration@Base 1.7.0~rc2 + pn53x_read_register@Base 1.7.0~rc2 + pn53x_transceive@Base 1.7.0~rc2 + pn53x_write_register@Base 1.7.0~rc2 + str_nfc_baud_rate@Base 1.7.0~rc2 + str_nfc_modulation_type@Base 1.7.0~rc2 + str_nfc_target@Base 1.7.0~rc2 From 3f6024cd64a4121fe7b93fd75b790b66f5d04e30 Mon Sep 17 00:00:00 2001 From: Nobuhiro Iwamatsu Date: Fri, 1 Feb 2013 08:53:10 +0900 Subject: [PATCH 28/32] Update package description Signed-off-by: Nobuhiro Iwamatsu --- debian/control | 49 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/debian/control b/debian/control index 9c3f8a8..5d0456d 100644 --- a/debian/control +++ b/debian/control @@ -14,9 +14,14 @@ Multi-Arch: same Pre-Depends: ${misc:Pre-Depends} Depends: ${shlibs:Depends}, ${misc:Depends} Description: Near Field Communication (NFC) library - libnfc is a Free Software library for Near Field Communication. - Supported NFC hardware devices are, theorically, all hardware - based on the NXP PN531, PN532 or PN533 NFC controller chip. + libnfc is a library for Near Field Communication. It abstracts the + low-level details of communicating with the devices away behind an + easy-to-use high-level API. + It supports most hardware based on the NXP PN531, PN532 or PN533 + controller chips. + . + This package contains the runtime library files needed to run software + using libnfc. Package: libnfc-dev Section: libdevel @@ -24,24 +29,42 @@ Architecture: any Multi-Arch: same Pre-Depends: ${misc:Pre-Depends} Depends: ${misc:Depends}, libnfc4 (= ${binary:Version}), libusb-dev -Description: Near Field Communication library (development files) - libnfc is a free software library for near-field communication. +Description: Near Field Communication (NFC) library (development files) + libnfc is a library for Near Field Communication. It abstracts the + low-level details of communicating with the devices away behind an + easy-to-use high-level API. It supports most hardware based on the NXP PN531, PN532 or PN533 controller chips. + . + This package contains the header and development files needed to build + programs and packages using libnfc. Package: libnfc-bin Section: utils Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, libnfc4 (>= ${binary:Version}) -Description: Near Field Communication binaries - Some binaries are provided with libnfc useful for development - purposes (nfc-list, nfc-mfclassic, nfc-mfultralight, etc.). +Description: Near Field Communication (NFC) binaries + libnfc is a library for Near Field Communication. It abstracts the + low-level details of communicating with the devices away behind an + easy-to-use high-level API. + It supports most hardware based on the NXP PN531, PN532 or PN533 + controller chips. + . + This package contains some utils that come along with libnfc, for + development or debugging purposes (including nfc-list, nfc-mfclassic, + nfc-mfultralight, etc). Package: libnfc-examples Section: utils Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, libnfc4 (>= ${binary:Version}) -Description: Near Field Communication examples +Description: Near Field Communication (NFC) examples + libnfc is a library for Near Field Communication. It abstracts the + low-level details of communicating with the devices away behind an + easy-to-use high-level API. + It supports most hardware based on the NXP PN531, PN532 or PN533 + controller chips. + . Some examples are provided with libnfc for debugging and/or educational purposes (nfc-anticol, nfc-emulate, etc.). @@ -49,6 +72,12 @@ Package: libnfc-pn53x-examples Section: utils Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, libnfc4 (>= ${binary:Version}) -Description: Near Field Communication examples for PN53x chips only +Description: Near Field Communication (NFC) examples for PN53x chips only + libnfc is a library for Near Field Communication. It abstracts the + low-level details of communicating with the devices away behind an + easy-to-use high-level API. + It supports most hardware based on the NXP PN531, PN532 or PN533 + controller chips. + . Some PN53x-only examples are provided with libnfc for debugging and/or educational purposes (pn53x-sam, pn53x-tamashell, etc.). From cf2c6ef9669fe2e4290adcae5fb4196508b6e2e8 Mon Sep 17 00:00:00 2001 From: Nobuhiro Iwamatsu Date: Fri, 1 Feb 2013 09:01:29 +0900 Subject: [PATCH 29/32] Add support libnfc4-dbg package Signed-off-by: Nobuhiro Iwamatsu --- debian/control | 15 +++++++++++++++ debian/rules | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/debian/control b/debian/control index 5d0456d..763d815 100644 --- a/debian/control +++ b/debian/control @@ -39,6 +39,21 @@ Description: Near Field Communication (NFC) library (development files) This package contains the header and development files needed to build programs and packages using libnfc. +Package: libnfc4-dbg +Section: debug +Architecture: any +Multi-Arch: same +Pre-Depends: ${misc:Pre-Depends} +Depends: ${misc:Depends}, libnfc4 (= ${binary:Version}) +Description: Near Field Communication (NFC) library (debugging information) + libnfc is a library for Near Field Communication. It abstracts the + low-level details of communicating with the devices away behind an + easy-to-use high-level API. + It supports most hardware based on the NXP PN531, PN532 or PN533 + controller chips. + . + This package contains the debugging information. + Package: libnfc-bin Section: utils Architecture: any diff --git a/debian/rules b/debian/rules index fbdd8f3..fad10c8 100755 --- a/debian/rules +++ b/debian/rules @@ -27,3 +27,7 @@ override_dh_auto_configure: %: dh $@ --with autoreconf + +override_dh_strip: + dh_strip -plibnfc4 --dbg-package=libnfc4-dbg + dh_strip --remaining-packages From 15be4b885c052f3dacd76c2457c98c169862f740 Mon Sep 17 00:00:00 2001 From: Nobuhiro Iwamatsu Date: Fri, 1 Feb 2013 09:27:47 +0900 Subject: [PATCH 30/32] install nfc-emulate-forum-tag2.1 to libnfc-examples Signed-off-by: Nobuhiro Iwamatsu --- debian/libnfc-examples.install | 1 + 1 file changed, 1 insertion(+) diff --git a/debian/libnfc-examples.install b/debian/libnfc-examples.install index f78621e..936bce1 100644 --- a/debian/libnfc-examples.install +++ b/debian/libnfc-examples.install @@ -10,6 +10,7 @@ debian/tmp/usr/bin/nfc-relay debian/tmp/usr/share/man/man1/nfc-anticol.1 debian/tmp/usr/share/man/man1/nfc-dep-initiator.1 debian/tmp/usr/share/man/man1/nfc-dep-target.1 +debian/tmp/usr/share/man/man1/nfc-emulate-forum-tag2.1 debian/tmp/usr/share/man/man1/nfc-emulate-tag.1 debian/tmp/usr/share/man/man1/nfc-emulate-uid.1 debian/tmp/usr/share/man/man1/nfc-mfsetuid.1 From 40fadb8d2c5af40b4c1d420ea65198f0341dd8c3 Mon Sep 17 00:00:00 2001 From: Nobuhiro Iwamatsu Date: Fri, 1 Feb 2013 09:06:33 +0900 Subject: [PATCH 31/32] Update to 1.7.0~rc3 Signed-off-by: Nobuhiro Iwamatsu --- debian/changelog | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index f79ff43..a83d45a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,8 +1,8 @@ -libnfc (1.7.0~rc2-1) unstable; urgency=low +libnfc (1.7.0~rc3-1) unstable; urgency=low * Upload to Debian. (Closes: #672795) - -- Nobuhiro Iwamatsu Mon, 21 Jan 2013 14:19:24 +0900 + -- Nobuhiro Iwamatsu Fri, 01 Feb 2013 09:01:53 +0900 libnfc (1.7.0~rc2-0) unstable; urgency=low From 50f5c610a1f92d35f655f1e6279bb7be5d82140c Mon Sep 17 00:00:00 2001 From: Nobuhiro Iwamatsu Date: Fri, 1 Feb 2013 09:42:00 +0900 Subject: [PATCH 32/32] Add man of nfc-emulate-forum-tag2 to the installation Signed-off-by: Nobuhiro Iwamatsu --- examples/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/Makefile.am b/examples/Makefile.am index d822df0..c767532 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -96,6 +96,7 @@ dist_man_MANS = \ nfc-mfsetuid.1 \ pn53x-diagnose.1 \ pn53x-sam.1 \ - pn53x-tamashell.1 + pn53x-tamashell.1 \ + nfc-emulate-forum-tag2.1 EXTRA_DIST = CMakeLists.txt