node-pcsclite icon indicating copy to clipboard operation
node-pcsclite copied to clipboard

Reader removed and connected again not detected

Open boris-savic opened this issue 7 years ago • 22 comments

Hi,

I've noticed that whenever I disconnect my reader the library does emit end as intended to notify about reader removal. But once the reader is plugged back in the reader message is never emitted again?

Shouldn't there be a message when a reader is detected?

Using latest release 0.5.0 on Linux.

Thanks for your help.

boris-savic avatar Feb 28 '17 10:02 boris-savic

@boris-savic I've just tested locally and it works correctly for me. Can you check that the pcscd daemon is still up after removing / pluggin the reader? I've seen sometimes pcscd crashes when doing that and could explain why you're not receiving the event

santigimeno avatar Feb 28 '17 10:02 santigimeno

Hmmm, there are some errors being outputted by pcscd status command after the reader is unplugged, but the pcscd daemon is still running after.

feb 28 11:13:50 zitko pcscd[6666]: 00059502 commands.c:245:CmdPowerOn error on byte 66
feb 28 11:13:50 zitko pcscd[6666]: 00000027 ifdhandler.c:1422:IFDHPowerICC() PowerUp failed
feb 28 11:13:50 zitko pcscd[6666]: 00000009 eventhandler.c:304:EHStatusHandlerThread() Error powering up card: 2148532246 0x80100016
feb 28 11:46:37 zitko pcscd[6666]: 99999999 ccid_usb.c:1132:WriteUSB() write failed (1/45): -4 LIBUSB_ERROR_NO_DEVICE
feb 28 11:46:37 zitko pcscd[6666]: 00000013 ifdwrapper.c:371:IFDStatusICC() Card not transacted: 617
feb 28 11:46:38 zitko pcscd[6666]: 01000072 eventhandler.c:335:EHStatusHandlerThread() Error communicating to: ACS ACR1222 3S PICC Reader 00 00
feb 28 11:46:38 zitko pcscd[6666]: 00000175 ccid_usb.c:1132:WriteUSB() write failed (1/45): -4 LIBUSB_ERROR_NO_DEVICE
feb 28 11:46:38 zitko pcscd[6666]: 00000054 ccid_usb.c:1132:WriteUSB() write failed (1/45): -4 LIBUSB_ERROR_NO_DEVICE
feb 28 11:46:38 zitko pcscd[6666]: 00000016 ccid_usb.c:1132:WriteUSB() write failed (1/45): -4 LIBUSB_ERROR_NO_DEVICE
feb 28 11:46:38 zitko pcscd[6666]: 00000107 ccid_usb.c:1132:WriteUSB() write failed (1/45): -4 LIBUSB_ERROR_NO_DEVICE

boris-savic avatar Feb 28 '17 10:02 boris-savic

ok, can you check that this scenario works correctly using pcsc_scan?

santigimeno avatar Feb 28 '17 10:02 santigimeno

Yes, pcsc_scan also closes after the reader is disconnected with error:

Reader 0: ACS ACR1222 3S PICC Reader 00 00 Card state: Status unavailable, SCardGetStatusChange: Unknown reader specified.

boris-savic avatar Feb 28 '17 10:02 boris-savic

Then it looks like a problem of your reader with pcscd, there's not much node-pcsclite can do here. Is this reader supported by libccid (1, 2, 3 ) or is it using a proprietary driver? What versions of pcscd and libccid are you using?

/cc @LudovicRousseau just in case

santigimeno avatar Feb 28 '17 11:02 santigimeno

Versions:

pcsc-lite version 1.8.14.
libccid 1.4.22

It's using proprietary ACS drivers.

boris-savic avatar Feb 28 '17 12:02 boris-savic

@boris-savic please follow http://pcsclite.alioth.debian.org/ccid.html#support

LudovicRousseau avatar Feb 28 '17 12:02 LudovicRousseau

Thanks. Will check out and get to you with all needed information tomorrow.

I also ran the simple example on Windows 10 and similar error happens. Just as I unplug the reader from USB port the app crashes with following output.

events.js:160 throw er; // Unhandled 'error' event ^ Error: SCardGetStatusChange error: The Smart Card Resource Manager is not running. (0x8010001d) at Error (native)

I have tried with both Windows stock drivers and vendor specific drivers - same result.

boris-savic avatar Feb 28 '17 17:02 boris-savic

Hi @boris-savic

I had the same issues on Windows like you. The problem is that Windows automatically stops pcsc daemon (Smart Card Service – SCardSvr) when the device is unplugged. In some cases the same problem occurs also when no devices are plugged (because SCardSvr is stopped). The behaviour on Windows is really inconsistent.

However, I have solved all these Windows related problems. You can try my fork https://github.com/pokusew/node-pcsclite (which on top of that removes buffertools dependency).

Hope it helps.

pokusew avatar Feb 28 '17 18:02 pokusew

@pokusew that's useful info! BTW, any particular reason why you needed a fork instead of trying to include your modifications upstream? In any event, would you be ok if I included some of your modifications / improvements here? Thanks!

santigimeno avatar Mar 01 '17 09:03 santigimeno

Hi @santigimeno

At the beginning I removed just the buffertools dependency, reformatted the code and replaced var by const, so there was no point in creating PR. But then I came across the Windows issues and solved them. But because of previous changes I couldn't create PR (with so many another modifications).

Definitely, it would be great if you included my improvements to your library. Your library is awesome. I will be glad when my changes and findings will be useful for another people.

Here is a brief summary of my most significant changes:

  • removed buffertools dependency
  • solved issues on Windows (fix crash when SCardSrv is not running, or when it stops after reader disconnection – the behaviour in Windows is really strange/inconsistent)
  • improved README (fixed links to pcsclite documentation and added table of content and info about usage in Elcetron)
  • upgraded dependencies and added yarn.lock (see Yarn)

Thanks for your library. It is awesome.

Hope it helps.

pokusew avatar Mar 02 '17 01:03 pokusew

@pokusew those changes indeed look very useful! It would be great if you could open PR's for those changes (at least those that you don't find hard to integrate). If not, I'll try to include them myself when I have time. Thanks!!

santigimeno avatar Mar 03 '17 15:03 santigimeno

@santigimeno I will definitely create PR's for my changes as soon as I have some free time (in a week or so).

pokusew avatar Mar 13 '17 17:03 pokusew

Hi @pokusew,

I'm running into this problem right now, where Windows stops the PCSC daemon. Any chance of your changes being merged still? Or should I use your fork instead?

Regardless, thanks for your earlier work on this!

jorispz avatar Aug 08 '18 11:08 jorispz

Uncaught Error when the card reader is unplugged: Uncaught Error: SCardGetStatusChange error: ���ܿ���Դ������δ���С� (0x8010001d) reinserted into the card reader, this event does not trigger, can not re-monitor the status of the card reader, encountered the same problem, what should I do before I can pull out the card reader, can correctly monitor Identify the connection to a new card reader? Thank you!

Zoe314 avatar May 21 '19 08:05 Zoe314

@Zoe314 I guess you are using Windows. Right?

LudovicRousseau avatar May 21 '19 09:05 LudovicRousseau

yes,Windows10

Zoe314 avatar May 21 '19 10:05 Zoe314

i connect the card and after sometime i unplug the reader from the device . Again i connect the reader ,When i trying to reestablish the context i am getting invalid handle error both from reset context and connect reader

gargsurbhi18 avatar Aug 11 '23 04:08 gargsurbhi18

这是来自QQ邮箱的假期自动回复邮件。   您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。

Zoe314 avatar Aug 11 '23 04:08 Zoe314

i used pcscd lib on linux based boss operating system

gargsurbhi18 avatar Aug 11 '23 04:08 gargsurbhi18