On 2/7/2011 11:26 AM, Douglas E. Engert wrote:


On 2/3/2011 11:58 PM, Martin Paljak wrote:

On Feb 3, 2011, at 10:04 PM, Douglas E. Engert wrote:

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.)

I agree, a new entry point use_reader would work. I will look at adding such
and entry point that will be ignored by the other drivers, and callable
as sc_ctx_use_reader(ctx, void *, void *)


Attached is a patch that implements a sc_ctx_use_reader, to pass in two void
pointers to an underling driver. The code to use this from cardmod.c to the
cardmod code in reader-pcsc.c (or where ever it ends up) will be added as part
of a much larger patch.

The intent is to keep this sc_ctx_use_reader patch simple and small so it
can be committed soon.

Martin, If you agree that this is OK, I will commit it.

This patch is now independent of any patch needed for Brian to not call the
sc_ctc_detect_readers.

Once that is done, I can commit a much large patch for the cardmod code
that will use this.

--

 Douglas E. Engert  <deeng...@anl.gov>
 Argonne National Laboratory
 9700 South Cass Avenue
 Argonne, Illinois  60439
 (630) 252-5444
Index: src/libopensc/reader-pcsc.c
===================================================================
--- src/libopensc/reader-pcsc.c	(revision 5187)
+++ src/libopensc/reader-pcsc.c	(working copy)
@@ -1535,6 +1535,7 @@
 	pcsc_ops.wait_for_event = pcsc_wait_for_event;
 	pcsc_ops.cancel = pcsc_cancel;
 	pcsc_ops.reset = pcsc_reset;
+	pcsc_ops.use_reader = NULL;
 
 	return &pcsc_drv;
 }
@@ -1926,6 +1927,7 @@
 	/* cardmod_ops.perform_verify = ; */
 	cardmod_ops.wait_for_event = NULL; 
 	cardmod_ops.reset = NULL; 
+	cardmod_ops.use_reader = NULL; /* TODO Replace with entry point with major changes to cardmod */
 
 	return &cardmod_drv;
 }
Index: src/libopensc/ctx.c
===================================================================
--- src/libopensc/ctx.c	(revision 5187)
+++ src/libopensc/ctx.c	(working copy)
@@ -677,6 +677,16 @@
 	return SC_SUCCESS;
 }
 
+/* use by cardmod to pass in provided handles to reader-pcsc */
+int sc_ctx_use_reader(sc_context_t *ctx, void * pcsc_context_handle, void * pcsc_card_handle)
+{
+	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_NORMAL);
+	if (ctx->reader_driver->ops->use_reader != NULL)
+		return ctx->reader_driver->ops->use_reader(ctx, pcsc_context_handle, pcsc_card_handle);
+
+	return SC_ERROR_NOT_SUPPORTED;
+}
+
 /* Following two are only implemented with internal PC/SC and don't consume a reader object */
 int sc_cancel(sc_context_t *ctx)
 {
Index: src/libopensc/libopensc.exports
===================================================================
--- src/libopensc/libopensc.exports	(revision 5187)
+++ src/libopensc/libopensc.exports	(working copy)
@@ -71,6 +71,7 @@
 sc_ctx_get_reader_by_id
 sc_ctx_get_reader_by_name
 sc_ctx_get_reader_count
+sc_ctx_use_reader
 sc_decipher
 sc_delete_file
 sc_delete_record
Index: src/libopensc/reader-ctapi.c
===================================================================
--- src/libopensc/reader-ctapi.c	(revision 5187)
+++ src/libopensc/reader-ctapi.c	(working copy)
@@ -563,6 +563,7 @@
 	ctapi_ops.connect = ctapi_connect;
 	ctapi_ops.disconnect = ctapi_disconnect;
 	ctapi_ops.perform_verify = ctbcs_pin_cmd;
+	ctapi_ops.use_reader = NULL;
 	
 	return &ctapi_drv;
 }
Index: src/libopensc/reader-openct.c
===================================================================
--- src/libopensc/reader-openct.c	(revision 5187)
+++ src/libopensc/reader-openct.c	(working copy)
@@ -450,6 +450,7 @@
 	openct_ops.perform_verify = openct_reader_perform_verify;
 	openct_ops.lock = openct_reader_lock;
 	openct_ops.unlock = openct_reader_unlock;
+	openct_ops.use_reader = NULL;
 
 	return &openct_reader_driver;
 }
Index: src/libopensc/opensc.h
===================================================================
--- src/libopensc/opensc.h	(revision 5187)
+++ src/libopensc/opensc.h	(working copy)
@@ -388,6 +388,8 @@
 			int timeout, void **reader_states);
 	/* Reset a reader */
 	int (*reset)(struct sc_reader *, int);
+	/* used to pass in reader handles in cardmod mode */
+	int (*use_reader)(struct sc_context *ctx, void * pcsc_context_handle, void * pcsc_card_handle);
 };
 
 /*
@@ -726,6 +728,17 @@
  */
 sc_reader_t *sc_ctx_get_reader(sc_context_t *ctx, unsigned int i);
 
+/**
+ * Pass in pointers to handles to be used for the pcsc reader.
+ * This is used by cardmod to pass in handles provided by BaseCSP
+ *
+ * @param  ctx   pointer to a sc_context_t
+ * @param  pcsc_context_handle pointer to the  new context_handle to use
+ * @param  pcsc_card_handle pointer to the new card_handle to use 
+ * @return SC_SUCCESS on success and an error code otherwise.
+ */
+int sc_ctx_use_reader(sc_context_t *ctx, void * pcsc_context_handle, void * pcsc_card_handle);
+
 /** 
  * Returns a pointer to the specified sc_reader_t object
  * @param  ctx  OpenSC context
_______________________________________________
opensc-devel mailing list
opensc-devel@lists.opensc-project.org
http://www.opensc-project.org/mailman/listinfo/opensc-devel

Reply via email to