[Pcsclite-muscle] Portable way to detect when a smart card is inserted

helpcrypto helpcrypto helpcrypto
Mon Sep 15 05:36:29 PDT 2014


Hello ignacio


As you said, you have to call SCardGetStatusChange twice:
The first call get the current state of the readers, and has a timeout of 0.
The second call, with a timeout of INFINITE wait until any difference is
detected.

Have a look at
http://pcsclite.alioth.debian.org/api/group__API.html#ga33247d5d1257d59e55647c3bb717db24

There are many tricky things you could do to improve the speed/trustworthy
of the detection, so start with something basic before looking for
performance.






On Mon, Sep 15, 2014 at 2:18 PM, Ignacio Casal <
ignacio.casal at nice-software.com> wrote:

> Hey guys,
>
> do you know what is the proper way to detect when a smart card is inserted?
>
> in some places I've seen something like this:
>
> rgReaderStates[0].szReader = &mszReaders[iList[iReader]];
> rgReaderStates[0].dwCurrentState = SCARD_STATE_EMPTY;
>
> rv = SCardGetStatusChange(hContext, INFINITE, rgReaderStates, 1);
>
> while this worked for me on linux with pcsclite it does not seem to work
> for me on windows, while doing this next does:
> rgReaderStates[0].szReader = &mszReaders[iList[iReader]];
> rgReaderStates[0].dwCurrentState = SCARD_STATE_UNAWARE;
>
> rv = SCardGetStatusChange(hContext, INFINITE, rgReaderStates, 1);
>
> if (rv == SCARD_S_SUCCESS) {
>   rgReaderStates[0].dwCurrentState = rgReaderStates[0].dwEventState;
> }
>
> rv = SCardGetStatusChange(hContext, INFINITE, rgReaderStates, 1);
>
> As you can see I need to do the call twice, first to get the current state
> and second to actually block to wait for the smart card to be inserted. Is
> this second way the recommended way also on pcsclite? If yes is the first
> version shown here in this mail some kind of shortcut for the 2 way call?
> Is there a better way to check when a smart card is inserted?
>
> Thanks in advance.
>
> --
> Ignacio Casal Quinteiro
>
> _______________________________________________
> Pcsclite-muscle mailing list
> Pcsclite-muscle at lists.alioth.debian.org
> http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pcsclite-muscle
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/pcsclite-muscle/attachments/20140915/2f147e44/attachment.html>



More information about the pcsclite-muscle mailing list