Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

further issues with O2MICRO OZ776 (0b97:7772) #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/ccid.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,17 @@ typedef struct
*/
#define O2MICRO_OZ776_PATCH

/*
* The O2Micro OZ776_7772 reader randomly times out in bulk read.
* (This is very depending on the smartcard. Even same types of the
* same batch behave completely different. Another hardware bug?)
* In order to avoid operations to fail, do some resync and retries
* during transceiving. This seems to help in all observed cases.
*
* Observed, tested and fixed on Fujitsu Lifebook E754
*/
#define O2MICRO_OZ776_TIMEOUTPATCH 5 /* number of max. resyncs using this reader */

/* Escape sequence codes */
#define ESC_GEMPC_SET_ISO_MODE 1
#define ESC_GEMPC_SET_APDU_MODE 2
Expand Down
4 changes: 4 additions & 0 deletions src/openct/README
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ project <http:https://www.opensc.org/>

I (Ludovic Rousseau) greatly patched proto-t1.c to add all the needed
code to reach the quality level requested by the EMV standard.

I (Stephan Baerwolf) slightly modified error-handling in "t1_transceive"
for "O2 Micro OZ776 CCID Smartcard Reader" devices (0b97:7772).
(There some "random?" usb timeouts cause operations to fail otherwise.)
16 changes: 16 additions & 0 deletions src/openct/proto-t1.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ int t1_transceive(t1_state_t * t1, unsigned int dad,
unsigned char sdata[T1_BUFFER_SIZE], sblk[5];
unsigned int slen, retries, resyncs;
size_t last_send = 0;
#ifdef O2MICRO_OZ776_TIMEOUTPATCH
_ccid_descriptor *ccid_descriptor = get_ccid_descriptor(t1->lun);
#endif

if (snd_len == 0)
return -1;
Expand All @@ -174,6 +177,11 @@ int t1_transceive(t1_state_t * t1, unsigned int dad,

t1->state = SENDING;
retries = t1->retries;
#if ((O2MICRO_OZ776_TIMEOUTPATCH) > 0)
if (ccid_descriptor->readerID == OZ776_7772) {
resyncs = (O2MICRO_OZ776_TIMEOUTPATCH);
} else
#endif
resyncs = 3;

/* Initialize send/recv buffer */
Expand Down Expand Up @@ -213,6 +221,14 @@ int t1_transceive(t1_state_t * t1, unsigned int dad,

if (n < 0) {
DEBUG_CRITICAL("fatal: transmit/receive failed");
#ifdef O2MICRO_OZ776_TIMEOUTPATCH
if (ccid_descriptor->readerID == OZ776_7772) {
DEBUG_INFO2("patching timeout bug for O2MICRO_OZ776, retries=%u",retries);
if (retries <= 0) {
goto resync;
} else continue;
}
#endif
t1->state = DEAD;
goto error;
}
Expand Down