santigimeno / node-pcsclite

Bindings over pcsclite to access Smart Cards
ISC License
171 stars 127 forks source link

Reader removed and connected again not detected #68

Open boris-savic opened 7 years ago

boris-savic commented 7 years ago

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.

santigimeno commented 7 years ago

@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

boris-savic commented 7 years ago

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
santigimeno commented 7 years ago

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

boris-savic commented 7 years ago

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.

santigimeno commented 7 years ago

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

boris-savic commented 7 years ago

Versions:

pcsc-lite version 1.8.14.
libccid 1.4.22

It's using proprietary ACS drivers.

LudovicRousseau commented 7 years ago

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

boris-savic commented 7 years ago

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.

pokusew commented 7 years ago

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.

santigimeno commented 7 years ago

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

pokusew commented 7 years ago

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:

Thanks for your library. It is awesome.

Hope it helps.

santigimeno commented 7 years ago

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

pokusew commented 7 years ago

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

jorispz commented 6 years ago

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!

Zoe314 commented 5 years ago

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!

LudovicRousseau commented 5 years ago

@Zoe314 I guess you are using Windows. Right?

Zoe314 commented 5 years ago

yes,Windows10

gargsurbhi18 commented 1 year ago

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

Zoe314 commented 1 year ago

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

gargsurbhi18 commented 1 year ago

i used pcscd lib on linux based boss operating system

cyrstron commented 5 months ago

re-creating a lib instance actually helps with making readers work again.

Zoe314 commented 5 months ago

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