[Pcsclite-cvs-commit] r7092 - in trunk/Drivers/ccid: . MacOSX src

ludovic.rousseau at free.fr ludovic.rousseau at free.fr
Fri Feb 13 14:57:31 UTC 2015


Author: rousseau
Date: 2015-02-13 14:57:31 +0000 (Fri, 13 Feb 2015)
New Revision: 7092

Modified:
   trunk/Drivers/ccid/MacOSX/configure
   trunk/Drivers/ccid/configure.ac
   trunk/Drivers/ccid/src/Info.plist.src
   trunk/Drivers/ccid/src/ccid_ifdhandler.h
   trunk/Drivers/ccid/src/debug.c
   trunk/Drivers/ccid/src/debug.h
   trunk/Drivers/ccid/src/ifdhandler.c
Log:
Add syslog(3) debug for Mac OS X Yosemite

New features:
--enable-syslog at build time
DRIVER_OPTION_LOG in Info.plist at run time


Modified: trunk/Drivers/ccid/MacOSX/configure
===================================================================
--- trunk/Drivers/ccid/MacOSX/configure	2015-02-09 10:23:16 UTC (rev 7091)
+++ trunk/Drivers/ccid/MacOSX/configure	2015-02-13 14:57:31 UTC (rev 7092)
@@ -72,6 +72,13 @@
 
 CONFIGURE_ARGS="--disable-dependency-tracking"
 
+# Are we on a CryptoTokenKit system? (like Mac OS X 10.10 Yosemite)
+if [ -d /System/Library/CryptoTokenKit ]
+then
+	# so we use syslog(3) to log errors
+	CONFIGURE_ARGS="$CONFIGURE_ARGS --enable-syslog"
+fi
+
 # do not build a static driver
 # (building fails when linking statically with libusb)
 CONFIGURE_ARGS="$CONFIGURE_ARGS --disable-static"

Modified: trunk/Drivers/ccid/configure.ac
===================================================================
--- trunk/Drivers/ccid/configure.ac	2015-02-09 10:23:16 UTC (rev 7091)
+++ trunk/Drivers/ccid/configure.ac	2015-02-13 14:57:31 UTC (rev 7092)
@@ -237,6 +237,17 @@
 fi
 AM_CONDITIONAL(WITHOUT_PCSC, test "${pcsclite}" != "yes")
 
+
+# --enable-syslog
+AC_ARG_ENABLE(syslog,
+	AS_HELP_STRING([--enable-syslog],[use syslog instead of printf for debug (Yosemite)]),
+	[ use_syslog="${enableval}" ], [ use_syslog=no ] )
+
+if test x$use_syslog = xyes; then
+  AC_DEFINE(USE_SYSLOG, 1, [Use syslog(3) for debug])
+fi
+
+
 # --disable-class
 AC_ARG_ENABLE(class,
 	AS_HELP_STRING([--disable-class],[remove the CCIDCLASSDRIVER from Info.plist]),
@@ -301,6 +312,7 @@
 serial twin install dir: ${ccidtwindir}
 serial config directory: ${serialconfdir}
 compiled for pcsc-lite:  ${pcsclite}
+syslog debug:            ${use_syslog}
 class driver:            ${class}
 
 EOF

Modified: trunk/Drivers/ccid/src/Info.plist.src
===================================================================
--- trunk/Drivers/ccid/src/Info.plist.src	2015-02-09 10:23:16 UTC (rev 7091)
+++ trunk/Drivers/ccid/src/Info.plist.src	2015-02-13 14:57:31 UTC (rev 7092)
@@ -94,6 +94,10 @@
 		value in order to retreive the remaining retries from the card.
 		Some cards (like the OpenPGP card) do not support this.
 
+	0x80: DRIVER_OPTION_LOG
+		Log the ATR, APDU + response.
+		This is usefull on Yosemite since pcscd disapeared.
+
 	Default value: 0
 	-->
 

Modified: trunk/Drivers/ccid/src/ccid_ifdhandler.h
===================================================================
--- trunk/Drivers/ccid/src/ccid_ifdhandler.h	2015-02-09 10:23:16 UTC (rev 7091)
+++ trunk/Drivers/ccid/src/ccid_ifdhandler.h	2015-02-13 14:57:31 UTC (rev 7092)
@@ -43,6 +43,7 @@
 #define DRIVER_OPTION_USE_BOGUS_FIRMWARE 4
 #define DRIVER_OPTION_RESET_ON_CLOSE 8
 #define DRIVER_OPTION_DISABLE_PIN_RETRIES (1 << 6)
+#define DRIVER_OPTION_LOG (1 << 7)
 
 extern int DriverOptions;
 

Modified: trunk/Drivers/ccid/src/debug.c
===================================================================
--- trunk/Drivers/ccid/src/debug.c	2015-02-09 10:23:16 UTC (rev 7091)
+++ trunk/Drivers/ccid/src/debug.c	2015-02-13 14:57:31 UTC (rev 7092)
@@ -32,6 +32,10 @@
 #include <sys/time.h>
 #include <stdlib.h>
 
+#ifdef USE_SYSLOG
+#include <syslog.h>
+#endif
+
 #include "strlcpycat.h"
 
 #undef LOG_TO_STDERR
@@ -50,6 +54,21 @@
 	struct timeval new_time = { 0, 0 };
 	struct timeval tmp;
 	int delta;
+#ifdef USE_SYSLOG
+	int syslog_level;
+
+	switch(priority)
+	{
+		case PCSC_LOG_CRITICAL:
+			syslog_level = LOG_CRIT;
+			break;
+		case PCSC_LOG_ERROR:
+			syslog_level = LOG_ERR;
+			break;
+		default:
+			syslog_level = LOG_WARNING;
+	}
+#else
 	const char *color_pfx = "", *color_sfx = "";
 	const char *time_pfx = "", *time_sfx = "";
 	static int initialized = 0;
@@ -105,6 +124,7 @@
 				break;
 		}
 	}
+#endif
 
 	gettimeofday(&new_time, NULL);
 	if (0 == last_time.tv_sec)
@@ -128,9 +148,13 @@
 	(void)vsnprintf(debug_buffer, sizeof debug_buffer, fmt, argptr);
 	va_end(argptr);
 
+#ifdef USE_SYSLOG
+	syslog(syslog_level, "%.8d %s", delta, debug_buffer);
+#else
 	(void)fprintf(LOG_STREAM, "%s%.8d%s %s%s%s\n", time_pfx, delta, time_sfx,
 		color_pfx, debug_buffer, color_sfx);
 	fflush(LOG_STREAM);
+#endif
 } /* log_msg */
 
 void log_xxd(const int priority, const char *msg, const unsigned char *buffer,
@@ -152,6 +176,10 @@
 		c += 3;
 	}
 
+#ifdef USE_SYSLOG
+	syslog(LOG_WARNING, "%s", debug_buffer);
+#else
 	(void)fprintf(LOG_STREAM, "%s\n", debug_buffer);
 	fflush(LOG_STREAM);
+#endif
 } /* log_xxd */

Modified: trunk/Drivers/ccid/src/debug.h
===================================================================
--- trunk/Drivers/ccid/src/debug.h	2015-02-09 10:23:16 UTC (rev 7091)
+++ trunk/Drivers/ccid/src/debug.h	2015-02-13 14:57:31 UTC (rev 7092)
@@ -96,5 +96,7 @@
 /* DEBUG_XXD */
 #define DEBUG_XXD(msg, buffer, size) if (LogLevel & DEBUG_LEVEL_COMM) LogXxd(PCSC_LOG_DEBUG, msg, buffer, size)
 
+#define DEBUG_XXD_APPLE(msg, buffer, size) if (DriverOptions & DRIVER_OPTION_LOG) LogXxd(PCSC_LOG_DEBUG, msg, buffer, size)
+
 #endif
 

Modified: trunk/Drivers/ccid/src/ifdhandler.c
===================================================================
--- trunk/Drivers/ccid/src/ifdhandler.c	2015-02-09 10:23:16 UTC (rev 7091)
+++ trunk/Drivers/ccid/src/ifdhandler.c	2015-02-13 14:57:31 UTC (rev 7092)
@@ -1218,6 +1218,9 @@
 			memcpy(Atr, pcbuffer, *AtrLength);
 			memcpy(CcidSlots[reader_index].pcATRBuffer, pcbuffer, *AtrLength);
 
+			/* Log ATR */
+			DEBUG_XXD_APPLE("ATR: ", Atr, *AtrLength);
+
 			/* initialise T=1 context */
 			(void)t1_init(&(get_ccid_slot(reader_index) -> t1), reader_index);
 			break;
@@ -1282,6 +1285,9 @@
 	DEBUG_INFO3("%s (lun: " DWORD_X ")", CcidSlots[reader_index].readerName,
 		Lun);
 
+	/* Log command */
+	DEBUG_XXD_APPLE("APDU: ", TxBuffer, TxLength);
+
 	/* special APDU for the Kobil IDToken (CLASS = 0xFF) */
 	if (KOBIL_IDTOKEN == get_ccid_descriptor(reader_index) -> readerID)
 	{
@@ -1341,6 +1347,9 @@
 	else
 		*RxLength = 0;
 
+	/* Log response */
+	DEBUG_XXD_APPLE("SW: ", RxBuffer, *RxLength);
+
 	return return_value;
 } /* IFDHTransmitToICC */
 




More information about the Pcsclite-cvs-commit mailing list