On Fri, 2011-02-04 at 07:58 +0200, Martin Paljak wrote: > On Feb 3, 2011, at 10:04 PM, Douglas E. Engert wrote: > > > I have updates #321 with a new version of the cardmod patch > > and would like to start to commit it in pieces. > > > > Piece 1 is the attachment I sent on 1/28 as new.martin.patch > > based on Martin's patch from 1/19. This was the patch that would > > work for Brian. The main change is adding two parameters to all > > the *_detect_readers routines. Martin's patch already required these > > to be added in a number of places. > > > > Is there any objection to adding this patch now? > > I would consider using a new hook, like "use_reader" or > "use_pcsc_parameters" to send the arguments to reader-pcsc.c and set the > (pcsc, not cardmod) driver to "cardmod state". The reader operations API is > by no means set in stone. Nor is there need to abstract it away too much, the > usage pattern is known and the code path to implement it should be as simple > as possible (sc_XXX wrapper that will not be used by any other reader driver, > like sc_cancel and sc_wait_for_event are examples of "somewhat bad ideas". > Yet it is a working pattern.)
Attachment shows a different approach. It's not a complete solution but should be sufficient to demonstrate an alternative method of SCARDCONTEXT passing. Regards Andre
Index: src/libopensc/reader-pcsc.c =================================================================== --- src/libopensc/reader-pcsc.c (revision 5127) +++ src/libopensc/reader-pcsc.c (working copy) @@ -1900,6 +1900,20 @@ SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, ret); } +int sc_cardmod_set_ctx(sc_reader_t *reader, SCARDCONTEXT hSCardCtx, SCARDHANDLE hSCard) +{ + struct pcsc_private_data *priv; + + if (reader == NULL || strcmp(reader->driver->name, "cardmod") != 0) + return SC_ERROR_INVALID_ARGUMENTS; + + priv = GET_PRIV_DATA(reader); + priv->gpriv->pcsc_ctx = hSCardCtx; + priv->pcsc_card = hSCard; + + return SC_SUCCESS; +} + struct sc_reader_driver * sc_get_cardmod_driver(void) { Index: src/cardmod/cardmod.c =================================================================== --- src/cardmod/cardmod.c (revision 5127) +++ src/cardmod/cardmod.c (working copy) @@ -1454,6 +1454,14 @@ vs->reader = sc_ctx_get_reader(vs->ctx, 0); if(vs->reader) { + r = sc_cardmod_set_ctx(vs->reader, pCardData->hSCardCtx, pCardData->hScard); + if (r != SC_SUCCESS) + { + logprintf(pCardData, 0, ""); + /* TODO: free allocated resources */ + return SCARD_F_UNKNOWN_ERROR; + } + logprintf(pCardData, 3, "%s\n", NULLSTR(vs->reader->name)); r = sc_connect_card(vs->reader, &(vs->card));
_______________________________________________ opensc-devel mailing list opensc-devel@lists.opensc-project.org http://www.opensc-project.org/mailman/listinfo/opensc-devel