Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reader removed and connected again not detected #68

Open
boris-savic opened this issue Feb 28, 2017 · 22 comments
Open

Reader removed and connected again not detected #68

boris-savic opened this issue Feb 28, 2017 · 22 comments

Comments

@boris-savic
Copy link

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
Copy link
Owner

santigimeno commented Feb 28, 2017

@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
Copy link
Author

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
Copy link
Owner

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

@boris-savic
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

Versions:

pcsc-lite version 1.8.14.
libccid 1.4.22

It's using proprietary ACS drivers.

@LudovicRousseau
Copy link
Contributor

@boris-savic
Copy link
Author

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
Copy link

pokusew commented Feb 28, 2017

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
Copy link
Owner

@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
Copy link

pokusew commented Mar 2, 2017

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.

@santigimeno
Copy link
Owner

@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
Copy link

pokusew commented Mar 13, 2017

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

@jorispz
Copy link

jorispz commented Aug 8, 2018

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
Copy link

Zoe314 commented May 21, 2019

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
Copy link
Contributor

@Zoe314 I guess you are using Windows. Right?

@Zoe314
Copy link

Zoe314 commented May 21, 2019

yes,Windows10

@gargsurbhi18
Copy link

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
Copy link

Zoe314 commented Aug 11, 2023 via email

@gargsurbhi18
Copy link

i used pcscd lib on linux based boss operating system

@cyrstron
Copy link

cyrstron commented May 9, 2024

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

@Zoe314
Copy link

Zoe314 commented May 9, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants