David Corcoran wrote: > > Hello, > > Well, I have written a hot_plug plugin for pcsc-lite for USB and a quick > driver for a USB reader. I will probably make a release of the new > pcsc-lite with USB support next week. > > Also, I'm going to begin releasing RPM's and source from the website and I > have about 5 different test platforms. Is there anyone out there that > would like to provide a PC/SC API automated test that tries to send bogus > and non-bogus commands to the PC/SC API and does it also under Windows ? > I feel that I'm a bit too biased to create this test and it would really > help checking builds before release. I can't promise I will find the time to build a full testing program but here is a little contribution : I have a small program (in attachment) that : - connects to a reader and shares its connection. - reconnects to the same reader performing a reset (but still shares the reader) - set a transaction on the reader - waits a fair amount of time (15 sec) - sends some data - end the transaction and leave the card untouched... - closes up every thing (connection, context, etc...) but leave the card untouched. Then when I run this piece of code concurently. (say A first then B one or 2 seconds after A) : - B gives up with setting up the transaction as A has a lock on the reader (timeout) - however B has successfully reseted the card with reconnect() - A wakes up and tries to send data but complains the reader has gone reset (which is true)... Two questions about this : - shouldn't Reconnect() fails with E_SHARING_VIOLATION when B attempt to reconnect and reset a temporarily locked reader ? - does Windows behaves in a similar way ? <- if so then I suppose it is a normal feature but still what is allowed/disallowed while a transaction is on is fuzzy. ... This mail is already long enough so I believe I can consume some extra bytes and add a few words to appologize for being so descriptive... most of you have probably hit the delete button already... many thanks to those who didn't ;o) -- Lionel VICTOR - Security Engineer, Gemplus Software.
#include <unistd.h> #include <winscard.h> #include <stdio.h> int main () { SCARDCONTEXT hContext; LONG nError; SCARDHANDLE hCard; DWORD nProto; BYTE s[7], r[20]; DWORD dwSendLength, dwRecvLength; SCARD_IO_REQUEST sRecvPci; // Getting the context nError = SCardEstablishContext (SCARD_SCOPE_GLOBAL, NULL, NULL, &hContext); if (nError != SCARD_S_SUCCESS) { fprintf (stderr, "Can't establish the context : %s\n", pcsc_stringify_error(nError)); exit(0); } nError = SCardConnect (hContext, "GCR410 0 0", SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &hCard, &nProto); if (nError != SCARD_S_SUCCESS) { fprintf (stderr, "Can't connect to the card : %s\n", pcsc_stringify_error(nError)); exit(0); } nError = SCardReconnect (hCard, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, SCARD_RESET_CARD, &nProto); if (nError != SCARD_S_SUCCESS) { fprintf (stderr, "Can't reset the card : %s\n", pcsc_stringify_error(nError)); exit(0); } nError = SCardBeginTransaction (hCard); if (nError != SCARD_S_SUCCESS) { fprintf (stderr, "Can't initiate transaction : %s\n", pcsc_stringify_error(nError)); exit(0); } sleep (15); s[0] = 0x00; s[1] = 0xA4; s[2] = 0x01; s[3] = 0x00; s[4] = 0x02; s[5] = 0x10; s[6] = 0x00; dwSendLength = 7; nError = SCardTransmit (hCard, SCARD_PCI_T0, s, dwSendLength, &sRecvPci, r, &dwRecvLength); if (nError != SCARD_S_SUCCESS) { fprintf (stderr, "Can't initiate transaction : %s\n", pcsc_stringify_error(nError)); exit(0); } fprintf (stdout, "Received %X%X\n", r[0], r[1]); SCardEndTransaction (hCard, SCARD_LEAVE_CARD); SCardDisconnect (hCard, SCARD_LEAVE_CARD); SCardReleaseContext (hContext); } /* End of File */