hw/usb/dev-smartcard-reader: Handle 64 B USB packets
commit8030dca376fa1bc4d8a6be7628196578f8783ab3
authorJakub Jelen <jjelen@redhat.com>
Wed, 16 May 2018 11:55:44 +0000 (16 13:55 +0200)
committerGerd Hoffmann <kraxel@redhat.com>
Fri, 18 May 2018 07:42:16 +0000 (18 09:42 +0200)
tree2e4638c4b4f40ad20a62101ab8ff801889c5ba62
parente58d64a16abc2304c4dcb644411eb9580bf63b1e
hw/usb/dev-smartcard-reader: Handle 64 B USB packets

The current code was not correctly handling 64 B (Max USB 1.1 payload size)
packets and therefore preventing some of the messages from smart card to
pass through to the guest.

If the smart card in host responded with 34 B of data in APDU layer, the
CCID headers added up to 64 B. The packet was send, but not correctly
committed per USB specification (8.5.3.2  Variable-length Data Stage):

>   When all of the data structure is returned to the host, the function
> should indicate that the Data stage is ended by returning a packet
> that is shorter than the MaxPacketSize for the pipe.  If the data
> structure is an exact multiple of wMaxPacketSize for the pipe, the
> function will return a zero-length packet to indicate the end of the
> Data stage.

This lead the guest applications to timeout while waiting for the rest
of data (the emulation layer is answering with NAK until the timeout).

This patch is checking the current maximum packet size and if the
payload of this size is detected, the message buffer is not yet released.
With the next call, the empty buffer is sent and the message buffer
is finally released.

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Message-id: 20180516115544.3897-2-jjelen@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
hw/usb/dev-smartcard-reader.c