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

Add some workarounds to make VMWARE CCID work #24

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add some workarounds to make the emulated CCID reader presented by th…
…e VMWare hypervisor to the guests, work

properly. Tested on a VMWare Fusion guest, running Gentoo linux.
  • Loading branch information
mickflemm committed Oct 23, 2016
commit d9461a342fdf7cc3cb1022fe61dd5e9941c0e518
9 changes: 9 additions & 0 deletions src/ccid.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ int ccid_open_hack_pre(unsigned int reader_index)
/* The SCM SCL011 reader needs 350 ms to answer */
ccid_descriptor->readTimeout = DEFAULT_COM_READ_TIMEOUT * 4;
break;

case VMWARE_CCID:
/* This is not an actual reader, it's an emulated reader that
* acts as a proxy to the reader present on the host machine.
* Anounced dwFeatures are wrong, override them here. */
ccid_descriptor->dwFeatures = 0x0002047E;
/* It also doesn't have any pinpad */
ccid_descriptor->bPINSupport = 0;
break;
}

/* CCID */
Expand Down
15 changes: 15 additions & 0 deletions src/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -1121,8 +1121,10 @@ RESPONSECODE CmdGetSlotStatus(unsigned int reader_index, unsigned char buffer[])
unsigned char cmd[10];
status_t res;
unsigned int length;
int retries = 2;
RESPONSECODE return_value = IFD_SUCCESS;
_ccid_descriptor *ccid_descriptor = get_ccid_descriptor(reader_index);
int saved_timeout = ccid_descriptor->readTimeout;

#ifndef TWIN_SERIAL
if (PROTOCOL_ICCD_A == ccid_descriptor->bInterfaceProtocol)
Expand Down Expand Up @@ -1211,11 +1213,24 @@ RESPONSECODE CmdGetSlotStatus(unsigned int reader_index, unsigned char buffer[])
cmd[6] = (*ccid_descriptor->pbSeq)++;
cmd[7] = cmd[8] = cmd[9] = 0; /* RFU */

/* There is a bug when the reader sometimes ignores the first request
* and we get a timeout from libusb. Since we expect it let's reduce
* the timeout here to come back from it quickly. We'll restore the
* timeout on the retry */
if (ccid_descriptor->readerID == VMWARE_CCID)
ccid_descriptor->readTimeout = 150;
again:
res = WritePort(reader_index, sizeof(cmd), cmd);
CHECK_STATUS(res)

length = SIZE_GET_SLOT_STATUS;
res = ReadPort(reader_index, &length, buffer);
if (ccid_descriptor->readerID == VMWARE_CCID &&
res != STATUS_SUCCESS && retries > 0) {
retries--;
ccid_descriptor->readTimeout = saved_timeout;
goto again;
}
CHECK_STATUS(res)

if (length < STATUS_OFFSET+1)
Expand Down