nfc-pcsc: Control Error in LED Example

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:

*[master][~/Desktop/nfc-pcsc]$ node -r babel-register examples/led.js 
New reader detected ACS ACR122U
12:38:01 AM info ACS ACR122U  device attached
Setting AID to F222222222
AID parsed [ 242, 34, 34, 34, 34 ]

trying to connect CONNECT_MODE_DIRECT 3
status { state: 18, atr: <Buffer > }
changes 18
card removed
connected { type: 3, protocol: 3 }
<Buffer ff 00 52 00 00>
transmitting control <Buffer ff 00 52 00 00> 2
{ ControlError: An error occurred while transmitting control.
    at reader.control (/Users/risean/Desktop/nfc-pcsc/src/Reader.js:327:20)
    at /Users/risean/Desktop/nfc-pcsc/node_modules/@pokusew/pcsclite/lib/pcsclite.js:169:11
  name: 'ControlError',
  code: 'failure',
  previous: 
   Error: SCardControl error: Transaction failed.(0x80100016)
       at Error (native) }

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 27 (2 by maintainers)

Most upvoted comments

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?!

@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 😃

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) }

any help on how to enable this on win 10 x64?

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.

  1. Download the latest CCID driver from here https://ccid.apdu.fr/files/ and unzip it
  2. In terminal, cd to where the libs from libusb are installed (mine was in /opt/homebrew/Cellar/libusb/1.0.26/lib) and run these 2 commands:
  • mv libusb-1.0.dylib libusb-1.0.lib
  • mv libusb-1.0.0.dylib libusb-1.0.0.lib
  1. cd to where you the CCID stuff and run these 2 commands:
  • pkg-config --libs libusb-1.0
  • pkg-config --cflags libusb-1.0
  1. Install the driver using these commands:
  • ./MacOSX/configure
  • make
  • sudo make install

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.

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) }

@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?

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:

  1. Open the device manager
  2. Locate your device
  3. Open Properties and go to Details
  4. Find the vlaue for the property Device Instance Path
  5. 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ā€
  6. Reconnect the device / restart your PC
  7. 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 šŸ˜•

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:

  1. disable System Integrity Protection
    1. Boot to Recovery OS by restarting your machine and holding down Command+R shortcut at startup.
    2. Launch Terminal from the Utilities menu.
    3. Enter the following command: csrutil disable
    4. Reboot back to normal OS
    5. (for more info see Apple docs here)
  2. locate driver’s Info.plist file at /usr/libexec/SmartCardServices/drivers/ifd-ccid.bundle/Contents/Info.plist (Finder -> Go To Folder or Command-Shift-G)
  3. open Info.plist in your text editor
  4. set the value of ifdDriverOptions to 0x0001 and save the changes (now after rebooting the example and other control commands should work as expected)
  5. enable System Integrity Protection (as in step 1 just use csrutil enable)
  6. šŸ You’re done. Control commands should work.

Let me know if you have any problems.

Hope it helps.