68895e
diff -up ./src/ccid.c.omnikey ./src/ccid.c
68895e
--- ./src/ccid.c.omnikey	2012-06-08 07:17:11.000000000 -0700
68895e
+++ ./src/ccid.c	2014-09-26 16:40:54.279531436 -0700
68895e
@@ -47,8 +47,13 @@ int ccid_open_hack_pre(unsigned int read
68895e
 {
68895e
 	_ccid_descriptor *ccid_descriptor = get_ccid_descriptor(reader_index);
68895e
 
68895e
+	ccid_descriptor->dwNonStandardFlags = 0;
68895e
+
68895e
 	switch (ccid_descriptor->readerID)
68895e
 	{
68895e
+		case CARDMAN3121:
68895e
+			ccid_descriptor->dwNonStandardFlags = CCID_NON_STAND_OMK_3121_T1;
68895e
+			/* fall through */
68895e
 		case CARDMAN3121+1:
68895e
 			/* Reader announces APDU but is in fact TPDU */
68895e
 			ccid_descriptor->dwFeatures &= ~CCID_CLASS_EXCHANGE_MASK;
68895e
diff -up ./src/ccid.h.omnikey ./src/ccid.h
68895e
--- ./src/ccid.h.omnikey	2012-06-08 07:17:11.000000000 -0700
68895e
+++ ./src/ccid.h	2014-09-26 16:40:54.279531436 -0700
68895e
@@ -141,6 +141,7 @@ typedef struct
68895e
 	 * Gemalto extra features, if any
68895e
 	 */
68895e
 	struct GEMALTO_FIRMWARE_FEATURES *gemalto_firmware_features;
68895e
+	unsigned int dwNonStandardFlags;
68895e
 } _ccid_descriptor;
68895e
 
68895e
 /* Features from dwFeatures */
68895e
@@ -156,6 +157,9 @@ typedef struct
68895e
 #define CCID_CLASS_EXTENDED_APDU	0x00040000
68895e
 #define CCID_CLASS_EXCHANGE_MASK	0x00070000
68895e
 
68895e
+/* Features from the swNonStandardFlags */
68895e
+#define CCID_NON_STAND_OMK_3121_T1	0x00000001
68895e
+
68895e
 /* Features from bPINSupport */
68895e
 #define CCID_CLASS_PIN_VERIFY		0x01
68895e
 #define CCID_CLASS_PIN_MODIFY		0x02
68895e
diff -up ./src/commands.c.omnikey ./src/commands.c
68895e
--- ./src/commands.c.omnikey	2014-09-26 16:40:54.276531385 -0700
68895e
+++ ./src/commands.c	2014-09-26 16:41:39.463293364 -0700
68895e
@@ -1186,6 +1186,39 @@ RESPONSECODE CmdXfrBlock(unsigned int re
68895e
 	return return_value;
68895e
 } /* CmdXfrBlock */
68895e
 
68895e
+static RESPONSECODE omnikey_transmit_tpdu(unsigned int reader_index,
68895e
+        _ccid_descriptor *ccid_descriptor, unsigned int tx_length,
68895e
+        const unsigned char *tx_buffer)
68895e
+{
68895e
+	unsigned char cmd[11+CMD_BUF_SIZE];	 /* CCID + APDU buffer */
68895e
+	status_t ret;
68895e
+
68895e
+	cmd[0] = 0x6B; 				/* 3121 escape */
68895e
+	i2dw(tx_length+1, cmd+1); 	/* APDU length */
68895e
+	cmd[5] = ccid_descriptor->bCurrentSlotIndex;	/* slot number */
68895e
+	cmd[6] = (*ccid_descriptor->pbSeq)++;
68895e
+	cmd[7] = 0;
68895e
+	cmd[8] = 0;
68895e
+	cmd[9] = 0;
68895e
+	cmd[10] = 0x1A;
68895e
+
68895e
+	/* check that the command is not too large */
68895e
+	if (tx_length > CMD_BUF_SIZE)
68895e
+	{
68895e
+		DEBUG_CRITICAL2("TX Length too big: %d", tx_length);
68895e
+		return IFD_NOT_SUPPORTED;
68895e
+	}
68895e
+
68895e
+	memcpy(cmd+11, tx_buffer, tx_length);
68895e
+
68895e
+	ret = WritePort(reader_index, 11+tx_length, cmd);
68895e
+	if (STATUS_NO_SUCH_DEVICE == ret)
68895e
+		return IFD_NO_SUCH_DEVICE;
68895e
+	if (ret != STATUS_SUCCESS)
68895e
+		return IFD_COMMUNICATION_ERROR;
68895e
+
68895e
+	return IFD_SUCCESS;
68895e
+} /* omnikey_transmit_tpdu */
68895e
 
68895e
 /*****************************************************************************
68895e
  *
68895e
@@ -1242,6 +1275,13 @@ RESPONSECODE CCID_Transmit(unsigned int
68895e
 	}
68895e
 #endif
68895e
 
68895e
+	/* hack for Onmikey 3121 */
68895e
+	if ((ccid_descriptor->dwNonStandardFlags & CCID_NON_STAND_OMK_3121_T1) &&
68895e
+		(ccid_descriptor->cardProtocol == SCARD_PROTOCOL_T1)) {
68895e
+		return omnikey_transmit_tpdu(reader_index, ccid_descriptor, tx_length, 
68895e
+				tx_buffer);
68895e
+	}
68895e
+
68895e
 	cmd[0] = 0x6F; /* XfrBlock */
68895e
 	i2dw(tx_length, cmd+1);	/* APDU length */
68895e
 	cmd[5] = ccid_descriptor->bCurrentSlotIndex;	/* slot number */
68895e
@@ -1267,13 +1307,14 @@ RESPONSECODE CCID_Transmit(unsigned int
68895e
 RESPONSECODE CCID_Receive(unsigned int reader_index, unsigned int *rx_length,
68895e
 	unsigned char rx_buffer[], unsigned char *chain_parameter)
68895e
 {
68895e
-	unsigned char cmd[10+CMD_BUF_SIZE];	/* CCID + APDU buffer */
68895e
+	unsigned char cmd[11+CMD_BUF_SIZE];	/* CCID + APDU buffer */
68895e
 	unsigned int length;
68895e
+	unsigned char *rx_ptr = cmd+10;
68895e
 	RESPONSECODE return_value = IFD_SUCCESS;
68895e
 	status_t ret;
68895e
+	_ccid_descriptor *ccid_descriptor = get_ccid_descriptor(reader_index);
68895e
 
68895e
 #ifndef TWIN_SERIAL
68895e
-	_ccid_descriptor *ccid_descriptor = get_ccid_descriptor(reader_index);
68895e
 
68895e
 	if (PROTOCOL_ICCD_A == ccid_descriptor->bInterfaceProtocol)
68895e
 	{
68895e
@@ -1447,6 +1488,14 @@ time_request:
68895e
 	}
68895e
 
68895e
 	length = dw2i(cmd, 1);
68895e
+
68895e
+	if (length && 
68895e
+	  (ccid_descriptor->dwNonStandardFlags & CCID_NON_STAND_OMK_3121_T1) &&
68895e
+	  (ccid_descriptor->cardProtocol == SCARD_PROTOCOL_T1)) {
68895e
+		length--;
68895e
+		rx_ptr = cmd+11;
68895e
+	}
68895e
+
68895e
 	if (length <= *rx_length)
68895e
 		*rx_length = length;
68895e
 	else
68895e
@@ -1463,7 +1512,7 @@ time_request:
68895e
 		return_value = IFD_COMMUNICATION_ERROR;
68895e
 	}
68895e
 	else
68895e
-		memcpy(rx_buffer, cmd+10, length);
68895e
+		memcpy(rx_buffer, rx_ptr, length);
68895e
 
68895e
 	/* Extended case?
68895e
 	 * Only valid for RDR_to_PC_DataBlock frames */