Blame SOURCES/ccid-1.4.26-omnikey-3121.patch

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