Closed riseansmal closed 7 years ago
Hi @therealri,
I think that it caused by the special feature of standard PCSC drivers (in all OSs).
By default standard system PCSC driver doesn't allow to send any commands in direct mode (i.e. without any card present). You can still send LED control commands when a card is present but it is quite useless.
To allow sending control (i.e. escape) commands in direct mode, you have to set a special value in registry (when you are on Windows) or in Info.plist of driver (on macOS and Linux). Here is an article to this problematic, but it is quite old.
I was dealing with this problem too (I am also on macOS and btw using ACR122U too š). So, I figured out the instructions how to enable this feature in macOS (OS X):
You have to set the value of ifdDriverOptions
to 0x0001
(the default value is 0x0000 which disables control commands).
Unfortunately, this file is protected by System Integrity Protection (csrutil), so before editing you have to temporary disable it.
So step by step:
csrutil disable
/usr/libexec/SmartCardServices/drivers/ifd-ccid.bundle/Contents/Info.plist
(Finder -> Go To Folder or Command-Shift-G)ifdDriverOptions
to 0x0001
and save the changes
(now after rebooting the example and other control commands should work as expected)csrutil enable
)Let me know if you have any problems.
Hope it helps.
Thanks so much @pokusew!
any help on how to enable this on win 10 x64?
I figured out where to add the DWORD values, but I'm still unable to connect in direct mode. If anyone stumbles upon this and is able to figure it out, please let me know! Here's how to figure out where to add your values:
Properties
and go to Details
Device Instance Path
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum
+ the path you got from step 4 as described in http://tech.springcard.com/2013/scardcontrol-linux-and-java/ at "Working with MSā CCID driver"The error I get is:
{ ConnectError: An error occurred while connecting.
at reader.connect (...\node_modules\nfc-pcsc\dist\Reader.js:217:20)
name: 'ConnectError',
code: 'failure',
previous: Error: SCardConnect error: The smart card has been removed, so that further communication is not possible.
(0x80100069) }
Obviously changing port means you have to re-add the values for that entry.
I'm pretty confident this is the right place, but for some reason it just isn't working :/
Hey,
I'm also stuck in turning off the buzzer of the ACR122 reader.
Is it possible to turn it off in the code behind?
Anyone who can help me?
@mich356c I am having the same issue with an ACR1222L. I tried your solution but it didn't work. Did you manage to find a solution?
@carol-braileanu Unfortunately I havenāt
@pokusew Any docs for how to do this on linux? Debby based.
Edit: Editing the file should work
sudo nano /usr/lib/pcsc/drivers/ifd-ccid.bundle/Contents/Info.plist
Making the change as per above then
sudo reboot
Should do it :)
Hi, Any progress connecting directly on Win 10?
{ ControlError: An error occurred while transmitting control. at reader.control (C:\Users\Irakli.Tabagari\Desktop\fitness_backend_Geo\node _modules\nfc-pcsc\dist\Reader.js:260:25) at C:\Users\Irakli.Tabagari\Desktop\fitness_backend_Geo\node_modules\@pokuse w\pcsclite\lib\pcsclite.js:170:11 name: 'ControlError', code: 'failure', previous: Error: SCardControl error: Incorrect function. (0x00000001) }
Any update on windows 10? I'm getting:
{ ConnectError: An error occurred while connecting.
at reader.connect (C:\Users\Gonzalo\Desktop\nfc-reader\node_modules\nfc-pcsc\dist\Reader.js:195:25)
name: 'ConnectError',
code: 'failure',
previous: Error: SCardConnect error: Se ha quitado la tarjeta inteligente, por lo que ya no serļæ½ posible la comunicaciļæ½n.
(0x80100069) }
@carol-braileanu Any luck ?
I figured out where to add the DWORD values, but I'm still unable to connect in direct mode. If anyone stumbles upon this and is able to figure it out, please let me know! Here's how to figure out where to add your values:
- Open the device manager
- Locate your device
- Open
Properties
and go toDetails
- Find the vlaue for the property
Device Instance Path
- Add your new DWORD values in
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum
+ the path you got from step 4 as described in http://tech.springcard.com/2013/scardcontrol-linux-and-java/ at "Working with MSā CCID driver"- Reconnect the device / restart your PC
- Check if you can connect in DIRECT mode like in https://github.com/pokusew/nfc-pcsc/blob/master/examples/led.js
The error I get is:
{ ConnectError: An error occurred while connecting. at reader.connect (...\node_modules\nfc-pcsc\dist\Reader.js:217:20) name: 'ConnectError', code: 'failure', previous: Error: SCardConnect error: The smart card has been removed, so that further communication is not possible. (0x80100069) }
Obviously changing port means you have to re-add the values for that entry.
I'm pretty confident this is the right place, but for some reason it just isn't working :/
No luck here either. The problem (I think) lies in the manufacturer's driver itself. I was not able to disable the buzzer or the LEDs on Windows 10 even when using the provided ACR122UTool which is made by the same people that made the ACR122U reader/writer. Upon disabling the buzzer and applying changes, the reader responds with a "success" message, but the buzzer doesn't actually turn off.
I tried using older driver versions as well to no avail.
I was able to connect and disable the buzzer and manipulate the LEDs on Linux though (Raspberry Pi 3 using Raspbian).
Might be worth checking if this is possible on Windows 7 or even message the manufacturer to see if they have any suggestions. I'll get back with any more info.
Any new info on this? :/
Hello, I'm trying to disable the buzzer with the ACR122U on ubuntu. I've modified the Info.plist as shown above, but the control operation still fails.
Sending the turn-off ADPU when a card is placed on the reader works but it will beep when the card is detected for the first time. Any idea?
Looks like it is possible to disable the speaker when using @pokesuw/pcslite
library directly.
const connect = reader => new Promise((resolve, reject) =>
reader.connect(
{ share_mode: reader.SCARD_SHARE_SHARED },
(err, protocol) => err ? reject(err) : resolve(protocol)
)
);
const send = (reader, data, protocol) => new Promise((resolve, reject) =>
reader.transmit(
Buffer.from(data),
40, protocol,
(err, data) => err ? reject(err) : resolve(data)
)
);
const pcsc = pcsclite();
pcsc.on('reader', (reader) => {
reader.on('status', async (status) => {
// status changed to 'present'
if (!(reader.state & reader.SCARD_STATE_PRESENT) && (status.state & reader.SCARD_STATE_PRESENT)) {
try {
const protocol = await connect(reader);
const result = await send(reader, [0xFF, 0xCA, 0x00, 0x00, 0x00], protocol); // read id
await send(reader, [0xFF, 0x00, 0x52, 0x00, 0x00], protocol); // mute speaker
console.log("card present", result.subarray(0, result.length - 2).toString('hex'));
} catch (e) {
console.error('cannot read data', reader.name, e);
}
}
});
});
For me, the control commands do not work at all and a quick fix seems to be sending everything as a transmit command. Then, the LED and buzzer control works at least while a card is present.
this.nfc.on('reader', async reader => {
reader.control = reader.transmit;
...
reader.on('card', async card => {
await reader.led(0b01011101, [0x02, 0x01, 0x05, 0x01]);
UPDATE
The final fix on Windows was to change the following in the node module, file Reader.js
:
this.reader.connect({
share_mode: modes[mode]
}
to
this.reader.connect({
share_mode: modes[mode],
protocol: (mode === CONNECT_MODE_DIRECT) ? 0 : this.reader.SCARD_PROTOCOL_UNDEFINED
}
And in pcsclite change in cardreader.h
#define IOCTL_CCID_ESCAPE (0x42000000 + 3500)
to
#define IOCTL_CCID_ESCAPE (0x003136B0)
and run yarn
to rebuild.
Maybe they released a new hardware version and by that the escape command changed?!
@aximut has the key solution but it's easier than they outline. I extracted the logic of Reader.js (https://github.com/pokusew/nfc-pcsc/blob/master/src/Reader.js#L215) into my own code and called reader.control
directly. Using protocol 0 and 0x003136B0
instead of the constant value it works! How on earth did you discover that value?
@aximut has the key solution but it's easier than they outline. I extracted the logic of Reader.js (https://github.com/pokusew/nfc-pcsc/blob/master/src/Reader.js#L215) into my own code and called
reader.control
directly. Using protocol 0 and0x003136B0
instead of the constant value it works! How on earth did you discover that value?
@AdamMcCormick ACS included it in their card reader tool.
Nevertheless, they were lazy enough to not update their API docs and made me drain some hours on this.
Meanwhile, I did some other hacky improvements on this, e. g. do a repeated connect attempt in case it fails once, because if you reconnect to the card shortly after disconnecting from direct mode, it will fail undeterministically. I work with a lot of APIs, but this hardware and/or the Windows driver stack is really crap and a pain for developers, I would not want to be the one responsible for it. I just wanted to make it work with my time management software and now the days pass on getting this "popular" reader to work as it is supposed to.
@pokusew workaround no longer works on Big Sur in which the system volume is mounted read only.
I asked on Apple Developers: https://developer.apple.com/forums/thread/678700 Maybe they will help...
Just remove the buzzer :D https://wf.lavatech.top/ave/wogsd-physically-removing-the-buzzer-from-acr122u
Pasting this from the forum that I found this issue attached to. In case anyone's still trying to figure out how to do it on OSX.
It took Apple completely dropping the ball with Sonoma in terms of smart card reader support for the solution to this problem to come to light. In turns out, there is a way to completely ignore the CCID driver that comes with OSX and just install you own. Not sure why I never thought about doing that until I was forced to do it. Here are the steps I took to achieve this:
Make sure you have installed both libusb and pkg-config from brew.
Assuming you've followed along correctly and everything ran without issues, you should now have a new CCID driver installed in /usr/local/libexec/SmartCardServices/drivers/ifd-ccid.bundle. If you open the bundle, you can find the same Info.plist but this one is editable.
Once you have made all your changes, in order for this driver to take effect you have to reboot the system.
I'm on MAC (Sonoma), my SIP is disabled (and Filevault too), impossible to change ifdDriverOptions to 0x0001 (Info.plist), as soon as I save it, the system resets systematically the value to 0x0000.
I don't understand, any ideas? Thks
I'm on MAC (Sonoma), my SIP is disabled (and Filevault too), impossible to change ifdDriverOptions to 0x0001 (Info.plist), as soon as I save it, the system resets systematically the value to 0x0000.
I don't understand, any ideas? Thks
Are you using the ifdDriverOptions in /usr/local/libexec/SmartCardServices/drivers/ifd-ccid.bundle or the one in /usr/libexec/SmartCardServices/drivers/ifd-ccid.bundle? The one in usr/libexec is in a read only part of the OS file structure
/usr/local/libexec/SmartCardServices/drivers/ifd-ccid.bundle/Contents/MacOS/Info.pList file (ifdDriverOptions to 0x0001), but after a reboot some APDU commands (LED, Initiator Mode, ... -> NFC Tag Emulation) don't work, I always get a transmission error (Transaction failed.(0x80100016).
Odd, my change has survived after reboots and OS updates. What are you using to edit the file?
I m having similar issue as you. On linux, I manage to do it, via python and by modifying the plist On MAC, there is no possibility to change the plist contained in the read only path. I tried to install libusb, ccid and pcsc-lite (had to recompile it). The problem i have is the driver can not be loaded... On windows, I don't manage to perform a successfull SCardConnect in pure C. i have tried to edit the registry but it is for the next step i guess
Update, on Windows you need to SCardConnect with no Protocol value (0)
Hey @pokusew,
Thanks for this great package!
I am getting this error when trying to run the led.js example on macOS 10.12.4: