Skip to content

Commit

Permalink
ZLP: enable the patch only if --enable-zlp is used
Browse files Browse the repository at this point in the history
The Zero Length Packet patch has issues with some non-bogus readers. So
the patch is _disabled_ by default.

If your Gemalto reader suffer from the ZLP problem then recompile the CCID
reader with:
$ ./configure --enable-zlp
  • Loading branch information
LudovicRousseau committed Mar 21, 2017
1 parent 0b55708 commit 7e20d8d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,15 @@ if test x$use_embedded = xyes; then
AC_DEFINE(NO_LOG, 1, [Disable logging support])
fi

# --enable-zlp
AC_ARG_ENABLE(zlp,
AS_HELP_STRING([--enable-zlp],[enable the Zero Length Packet patch for some Gemalto readers]),
[ use_zlp="${enableval}" ])

if test x$use_zlp = xyes; then
AC_DEFINE(ENABLE_ZLP, 1, [Enable Zero Length Packet patch])
fi

# Setup dist stuff
AC_SUBST(ac_aux_dir)
AC_SUBST(bundle)
Expand Down
2 changes: 2 additions & 0 deletions src/ccid.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ int ccid_open_hack_pre(unsigned int reader_index)
ccid_descriptor->readTimeout = 60*1000; /* 60 seconds */
break;

#ifdef ENABLE_ZLP
case GEMPCTWIN:
case GEMPCKEY:
case DELLSCRK:
Expand All @@ -79,6 +80,7 @@ int ccid_open_hack_pre(unsigned int reader_index)
DEBUG_INFO1("ZLP fixup");
}
break;
#endif

case OZ776:
case OZ776_7772:
Expand Down
2 changes: 2 additions & 0 deletions src/ccid.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,12 @@ typedef struct
*/
struct GEMALTO_FIRMWARE_FEATURES *gemalto_firmware_features;

#ifdef ENABLE_ZLP
/*
* Zero Length Packet fixup (boolean)
*/
char zlp;
#endif
} _ccid_descriptor;

/* Features from dwFeatures */
Expand Down
2 changes: 2 additions & 0 deletions src/ccid_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,9 @@ static status_t set_ccid_descriptor(unsigned int reader_index,
serialDevice[reader_index].ccid.dwSlotStatus = IFD_ICC_PRESENT;
serialDevice[reader_index].ccid.bVoltageSupport = 0x07; /* 1.8V, 3V and 5V */
serialDevice[reader_index].ccid.gemalto_firmware_features = NULL;
#ifdef ENABLE_ZLP
serialDevice[reader_index].ccid.zlp = FALSE;
#endif
serialDevice[reader_index].echo = TRUE;

/* change some values depending on the reader */
Expand Down
4 changes: 4 additions & 0 deletions src/ccid_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,9 @@ status_t OpenUSBByName(unsigned int reader_index, /*@null@*/ char *device)
usbDevice[reader_index].ccid.bVoltageSupport = device_descriptor[5];
usbDevice[reader_index].ccid.sIFD_serial_number = NULL;
usbDevice[reader_index].ccid.gemalto_firmware_features = NULL;
#ifdef ENABLE_ZLP
usbDevice[reader_index].ccid.zlp = FALSE;
#endif
if (desc.iSerialNumber)
{
unsigned char serial[128];
Expand Down Expand Up @@ -822,6 +824,7 @@ status_t WriteUSB(unsigned int reader_index, unsigned int length,
(void)snprintf(debug_header, sizeof(debug_header), "-> %06X ",
(int)reader_index);

#ifdef ENABLE_ZLP
if (usbDevice[reader_index].ccid.zlp)
{ /* Zero Length Packet */
int dummy_length;
Expand All @@ -831,6 +834,7 @@ status_t WriteUSB(unsigned int reader_index, unsigned int length,
(void)libusb_bulk_transfer(usbDevice[reader_index].dev_handle,
usbDevice[reader_index].bulk_in, NULL, 0, &dummy_length, 10);
}
#endif

DEBUG_XXD(debug_header, buffer, length);

Expand Down

0 comments on commit 7e20d8d

Please sign in to comment.