Fix MinGW build bug and ACR122U PC/SC reconnect issue on Windows - #765
Open
doomfrawen wants to merge 1 commit into
Open
Fix MinGW build bug and ACR122U PC/SC reconnect issue on Windows#765doomfrawen wants to merge 1 commit into
doomfrawen wants to merge 1 commit into
Conversation
- contrib/win32/stdlib.c: setenv()/unsetenv() declared 'char *str[32]' (an array of 32 uninitialized pointers) instead of 'char str[32]' (a buffer). Under older GCC this only warned; GCC >= 14 rejects it as an incompatible pointer type, and even when it compiles the original code writes through a garbage pointer. - libnfc/drivers/acr122_pcsc.c: acr122_pcsc_close() disconnected with SCARD_LEAVE_CARD, which on an ACR122U talking through Windows' inbox CCID driver (WUDFUsbccidDriver) leaves the reader's internal session state such that the *next* SCardConnect from any process fails with 'No ACR122 firmware received' until the device is physically replugged. Disconnecting with SCARD_UNPOWER_CARD forces a clean depower/reset of the card interface on close, matching what a physical replug does, and the reader is immediately usable again by the next open.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two small, unrelated fixes found while building libnfc for native Windows via MSYS2 MinGW64 with
-DLIBNFC_DRIVER_ACR122_PCSC=ON:1.
contrib/win32/stdlib.c—setenv()/unsetenv()declarechar *str[32](an array of 32 uninitialized pointers) instead ofchar str[32](a buffer), thenstrcpy/strcatinto it. Older GCC only warned about the implicit pointer conversion; GCC 14+ rejects it outright, and even where it does compile this is a write through an uninitialized pointer.2.
libnfc/drivers/acr122_pcsc.c—acr122_pcsc_close()callsSCardDisconnect(..., SCARD_LEAVE_CARD). On an ACR122U behind Windows' inbox CCID driver (WUDFUsbccidDriver), this leaves the reader's internal PC/SC session in a state where the nextSCardConnectfrom any process fails withNo ACR122 firmware received, Error: 00000001until the device is physically unplugged and replugged. This reproduced 100% of the time across many runs (nfc-list, mfoc, mfcuk, mfoc-hardnested) on a genuine ACS ACR122U. Switching toSCARD_UNPOWER_CARDforces a full depower/reset of the card interface on close — electrically similar to a replug — and the reader is immediately reusable by the next process with no manual intervention.Both changes are minimal and platform-scoped (Windows/MinGW only). Happy to adjust style/commit message if you'd like it split into two PRs instead.