diff -urw opensc-0.11.11-orig/src/libopensc/apdu.c opensc-0.11.11-fixes/src/libopensc/apdu.c
--- opensc-0.11.11-orig/src/libopensc/apdu.c	2008-08-27 09:21:36.000000000 +0200
+++ opensc-0.11.11-fixes/src/libopensc/apdu.c	2009-12-17 09:39:54.000000000 +0100
@@ -530,10 +530,13 @@
 	} 
 
 	if ((apdu->flags & SC_APDU_FLAGS_CHAINING) != 0) {
-		/* divide et impera: transmit APDU in chunks with Lc < 255
+		/* divide et impera: transmit APDU in chunks with Lc <= max_send_size
 		 * bytes using command chaining */
 		size_t    len  = apdu->datalen;
 		const u8  *buf = apdu->data;
+	  	size_t    max_send_size = ((card->max_send_size > 0) ?
+					   card->max_send_size :
+					   card->reader->driver->max_send_size);
 
 		while (len != 0) {
 			size_t    plen;
@@ -543,14 +546,14 @@
 			tapdu = *apdu;
 			/* clear chaining flag */
 			tapdu.flags &= ~SC_APDU_FLAGS_CHAINING;
-			if (len > 255) {
+			if (len > max_send_size) {
 				/* adjust APDU case: in case of CASE 4 APDU
 				 * the intermediate APDU are of CASE 3 */
 				if ((tapdu.cse & SC_APDU_SHORT_MASK) == SC_APDU_CASE_4_SHORT)
 					tapdu.cse--;
 				/* XXX: the chunk size must be adjusted when
 				 *      secure messaging is used */
-				plen          = 255;
+				plen          = max_send_size;
 				tapdu.cla    |= 0x10;
 				tapdu.le      = 0;
 				/* the intermediate APDU don't expect data */
diff -urw opensc-0.11.11-orig/src/libopensc/card-piv.c opensc-0.11.11-fixes/src/libopensc/card-piv.c
--- opensc-0.11.11-orig/src/libopensc/card-piv.c	2009-10-21 09:51:20.000000000 +0200
+++ opensc-0.11.11-fixes/src/libopensc/card-piv.c	2009-12-17 09:45:16.000000000 +0100
@@ -1789,7 +1789,9 @@
 	priv->max_send_size = card->max_send_size;
 	/* TODO fix read_binary and write_binary (read_binary is fixed) */
 	card->max_recv_size = 0xffff; /* must force pkcs15 read_binary in one call */
-	card->max_send_size = 0xffff;
+
+	/* Since we patched apdu.c to use max_send_size when chaining we must set to real value */
+	card->max_send_size = 0xff;
 	
 	sc_debug(card->ctx, "Max send = %d recv = %d\n", 
 			card->max_send_size, card->max_recv_size);
Only in opensc-0.11.11-fixes/src/libopensc: card-piv.c~
Only in opensc-0.11.11-fixes/src/libopensc: pkcs15-syn.c~
