399b0b
diff -up ccid-1.4.26/src/ccid.c.omnikey ccid-1.4.26/src/ccid.c
399b0b
--- ccid-1.4.26/src/ccid.c.omnikey	2017-02-24 10:04:25.742132234 +0100
399b0b
+++ ccid-1.4.26/src/ccid.c	2017-02-24 10:07:26.145976335 +0100
399b0b
@@ -55,8 +55,16 @@ int ccid_open_hack_pre(unsigned int read
399b0b
 {
399b0b
 	_ccid_descriptor *ccid_descriptor = get_ccid_descriptor(reader_index);
399b0b
 
399b0b
+	ccid_descriptor->dwNonStandardFlags = 0;
399b0b
+
399b0b
 	switch (ccid_descriptor->readerID)
399b0b
 	{
399b0b
+		case CARDMAN3121:
399b0b
+			ccid_descriptor->dwNonStandardFlags = CCID_NON_STAND_OMK_3121_T1;
399b0b
+			ccid_descriptor->dwFeatures &= ~CCID_CLASS_EXCHANGE_MASK;
399b0b
+			ccid_descriptor->dwFeatures |= CCID_CLASS_TPDU;
399b0b
+			break;
399b0b
+
399b0b
 		case MYSMARTPAD:
399b0b
 			ccid_descriptor->dwMaxIFSD = 254;
399b0b
 			break;
399b0b
diff -up ccid-1.4.26/src/ccid.h.omnikey ccid-1.4.26/src/ccid.h
399b0b
--- ccid-1.4.26/src/ccid.h.omnikey	2017-01-07 15:50:47.000000000 +0100
399b0b
+++ ccid-1.4.26/src/ccid.h	2017-02-24 10:04:25.742132234 +0100
399b0b
@@ -137,6 +137,7 @@ typedef struct
399b0b
 	 */
399b0b
 	char zlp;
399b0b
 #endif
399b0b
+	unsigned int dwNonStandardFlags;
399b0b
 } _ccid_descriptor;
399b0b
 
399b0b
 /* Features from dwFeatures */
399b0b
@@ -153,6 +154,9 @@ typedef struct
399b0b
 #define CCID_CLASS_EXTENDED_APDU	0x00040000
399b0b
 #define CCID_CLASS_EXCHANGE_MASK	0x00070000
399b0b
 
399b0b
+/* Features from the swNonStandardFlags */
399b0b
+#define CCID_NON_STAND_OMK_3121_T1	0x00000001
399b0b
+
399b0b
 /* Features from bPINSupport */
399b0b
 #define CCID_CLASS_PIN_VERIFY		0x01
399b0b
 #define CCID_CLASS_PIN_MODIFY		0x02
399b0b
diff -up ccid-1.4.26/src/commands.c.omnikey ccid-1.4.26/src/commands.c
399b0b
--- ccid-1.4.26/src/commands.c.omnikey	2017-01-07 15:50:47.000000000 +0100
399b0b
+++ ccid-1.4.26/src/commands.c	2017-02-24 10:11:21.297778870 +0100
399b0b
@@ -1292,6 +1292,39 @@ RESPONSECODE CmdXfrBlock(unsigned int re
399b0b
 	return return_value;
399b0b
 } /* CmdXfrBlock */
399b0b
 
399b0b
+static RESPONSECODE omnikey_transmit_tpdu(unsigned int reader_index,
399b0b
+        _ccid_descriptor *ccid_descriptor, unsigned int tx_length,
399b0b
+        const unsigned char *tx_buffer)
399b0b
+{
399b0b
+	unsigned char cmd[11+CMD_BUF_SIZE];	 /* CCID + APDU buffer */
399b0b
+	status_t ret;
399b0b
+
399b0b
+	cmd[0] = 0x6B; 				/* 3121 escape */
399b0b
+	i2dw(tx_length+1, cmd+1); 	/* APDU length */
399b0b
+	cmd[5] = ccid_descriptor->bCurrentSlotIndex;	/* slot number */
399b0b
+	cmd[6] = (*ccid_descriptor->pbSeq)++;
399b0b
+	cmd[7] = 0;
399b0b
+	cmd[8] = 0;
399b0b
+	cmd[9] = 0;
399b0b
+	cmd[10] = 0x1A;
399b0b
+
399b0b
+	/* check that the command is not too large */
399b0b
+	if (tx_length > CMD_BUF_SIZE)
399b0b
+	{
399b0b
+		DEBUG_CRITICAL2("TX Length too big: %d", tx_length);
399b0b
+		return IFD_NOT_SUPPORTED;
399b0b
+	}
399b0b
+
399b0b
+	memcpy(cmd+11, tx_buffer, tx_length);
399b0b
+
399b0b
+	ret = WritePort(reader_index, 11+tx_length, cmd);
399b0b
+	if (STATUS_NO_SUCH_DEVICE == ret)
399b0b
+		return IFD_NO_SUCH_DEVICE;
399b0b
+	if (ret != STATUS_SUCCESS)
399b0b
+		return IFD_COMMUNICATION_ERROR;
399b0b
+
399b0b
+	return IFD_SUCCESS;
399b0b
+} /* omnikey_transmit_tpdu */
399b0b
 
399b0b
 /*****************************************************************************
399b0b
  *
399b0b
@@ -1348,6 +1381,13 @@ RESPONSECODE CCID_Transmit(unsigned int
399b0b
 	}
399b0b
 #endif
399b0b
 
399b0b
+	/* hack for Onmikey 3121 */
399b0b
+	if ((ccid_descriptor->dwNonStandardFlags & CCID_NON_STAND_OMK_3121_T1) &&
399b0b
+		(ccid_descriptor->cardProtocol == SCARD_PROTOCOL_T1)) {
399b0b
+		return omnikey_transmit_tpdu(reader_index, ccid_descriptor, tx_length, 
399b0b
+				tx_buffer);
399b0b
+	}
399b0b
+
399b0b
 	cmd[0] = 0x6F; /* XfrBlock */
399b0b
 	i2dw(tx_length, cmd+1);	/* APDU length */
399b0b
 	cmd[5] = ccid_descriptor->bCurrentSlotIndex;	/* slot number */
399b0b
@@ -1373,8 +1413,9 @@ RESPONSECODE CCID_Transmit(unsigned int
399b0b
 RESPONSECODE CCID_Receive(unsigned int reader_index, unsigned int *rx_length,
399b0b
 	unsigned char rx_buffer[], unsigned char *chain_parameter)
399b0b
 {
399b0b
-	unsigned char cmd[10+CMD_BUF_SIZE];	/* CCID + APDU buffer */
399b0b
+	unsigned char cmd[11+CMD_BUF_SIZE];	/* CCID + APDU buffer */
399b0b
 	unsigned int length;
399b0b
+	unsigned char *rx_ptr = cmd+10;
399b0b
 	RESPONSECODE return_value = IFD_SUCCESS;
399b0b
 	status_t ret;
399b0b
 	_ccid_descriptor *ccid_descriptor = get_ccid_descriptor(reader_index);
399b0b
@@ -1565,6 +1606,14 @@ time_request:
399b0b
 	}
399b0b
 
399b0b
 	length = dw2i(cmd, 1);
399b0b
+
399b0b
+	if (length && 
399b0b
+	  (ccid_descriptor->dwNonStandardFlags & CCID_NON_STAND_OMK_3121_T1) &&
399b0b
+	  (ccid_descriptor->cardProtocol == SCARD_PROTOCOL_T1)) {
399b0b
+		length--;
399b0b
+		rx_ptr = cmd+11;
399b0b
+	}
399b0b
+
399b0b
 	if (length <= *rx_length)
399b0b
 		*rx_length = length;
399b0b
 	else
399b0b
@@ -1581,7 +1630,7 @@ time_request:
399b0b
 		return_value = IFD_COMMUNICATION_ERROR;
399b0b
 	}
399b0b
 	else
399b0b
-		memcpy(rx_buffer, cmd+10, length);
399b0b
+		memcpy(rx_buffer, rx_ptr, length);
399b0b
 
399b0b
 	/* Extended case?
399b0b
 	 * Only valid for RDR_to_PC_DataBlock frames */