Compare commits
4 Commits
release/1.
...
release/1.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6b96fe434 | ||
|
|
c5a83cb9a5 | ||
|
|
8f20122e54 | ||
|
|
c31a91947d |
10
ChangeLog
10
ChangeLog
@@ -1,3 +1,13 @@
|
||||
2021-10-12 NIIBE Yutaka <gniibe@fsij.org>
|
||||
|
||||
* VERSION: 1.20.
|
||||
* doc/chopstx.texi (VERSION): 1.20.
|
||||
|
||||
2021-10-11 NIIBE Yutaka <gniibe@fsij.org>
|
||||
|
||||
Backport from master.
|
||||
* mcu/usb-usbip.c (URB_DATA_SIZE): Tweak the value.
|
||||
|
||||
2021-02-18 NIIBE Yutaka <gniibe@fsij.org>
|
||||
|
||||
* VERSION: 1.19.
|
||||
|
||||
9
NEWS
9
NEWS
@@ -1,6 +1,15 @@
|
||||
NEWS - Noteworthy changes
|
||||
|
||||
|
||||
* Major changes in Chopstx 1.20
|
||||
|
||||
Released 2021-10-12
|
||||
|
||||
** Fix of USB driver for GNU/Linux emulation
|
||||
|
||||
Fix the value of URB_DATA_SIZE, so that Gnuk can work with PC/SC.
|
||||
|
||||
|
||||
* Major changes in Chopstx 1.19
|
||||
|
||||
Released 2021-02-18
|
||||
|
||||
12
README
12
README
@@ -1,6 +1,6 @@
|
||||
Chopstx - Threads and only Threads
|
||||
Version 1.19
|
||||
2021-02-18
|
||||
Version 1.20
|
||||
2021-10-12
|
||||
Niibe Yutaka
|
||||
Flying Stone Technology
|
||||
|
||||
@@ -62,12 +62,4 @@ Future Works
|
||||
|
||||
RISC-V port (for GD32VF103) is available in 2.x. Please have a look
|
||||
at the master branch, and test it if possible.
|
||||
|
||||
Convenience function to determine the bottom of thread stack,
|
||||
configuration of thread size by compiler's output would be next things
|
||||
to be done.
|
||||
|
||||
Experimental SMP port for Cortex-A7 is under development. For SMP,
|
||||
more careful considerations for shared access to objects of struct
|
||||
chx_pq is needed. So, modifications required will not be small.
|
||||
--
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
\input texinfo @c -*-texinfo-*-
|
||||
@c %**start of header
|
||||
@setfilename chopstx.info
|
||||
@set VERSION 1.19
|
||||
@set VERSION 1.20
|
||||
@settitle Chopstx Reference Manual
|
||||
@c Unify some of the indices.
|
||||
@syncodeindex tp fn
|
||||
|
||||
126
mcu/usb-usbip.c
126
mcu/usb-usbip.c
@@ -22,10 +22,26 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
FIXME:
|
||||
RESET handling
|
||||
USB Shutdown
|
||||
Use reply structure of its own
|
||||
* This driver is intended to emulate USB full-speed device, which
|
||||
* maximum packet size is 64.
|
||||
*
|
||||
* "USBIP" is actually URB over network (instead of USB packet over
|
||||
* network), and its (current) naive protocol may expose possible
|
||||
* demarcation problem, which never occurs in real host-device; In
|
||||
* real host-device relationship, it is host side, which does
|
||||
* composition/decomposition of URB to/from packets. In an
|
||||
* implmentation of USB device with USBIP, it needs to be device side,
|
||||
* which does composition/decomposition of URB to/from packets.
|
||||
*
|
||||
* In this implementation of USB driver, URB_DATA_SIZE is defined as
|
||||
* (65544+10), because (major) target device intended is CCID. In the
|
||||
* CCID specification, you can find the value 65544+10.
|
||||
*/
|
||||
/*
|
||||
* FIXME:
|
||||
* RESET handling
|
||||
* USB Shutdown
|
||||
* Use reply structure of its own
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
@@ -96,7 +112,7 @@ struct urb {
|
||||
struct urb *next;
|
||||
struct urb *prev;
|
||||
|
||||
uint16_t remain;
|
||||
uint32_t remain;
|
||||
char *data_p;
|
||||
|
||||
pthread_t tid;
|
||||
@@ -236,7 +252,67 @@ attach_device (char busid[32], size_t *len_p)
|
||||
return (const char *)&usbip_usb_device;
|
||||
}
|
||||
|
||||
#define URB_DATA_SIZE 65535
|
||||
/*
|
||||
* The number 65544 comes from ISO 7816-4, which defines data format
|
||||
* of smartcard; CLS INS P1 P2 occupies four octets. Then, Lc-octet
|
||||
* to represent size of command data block, then command data block.
|
||||
* Lastly, Le-octet to represent size of response data block to be
|
||||
* returned.
|
||||
*
|
||||
* /----- for CLS INS P1 P2
|
||||
* |
|
||||
* | /-- for Lc
|
||||
* | |
|
||||
* | | /-- for data block
|
||||
* | | |
|
||||
* | | | /-- for Le
|
||||
* | | | |
|
||||
* v v v v
|
||||
* 4 + 3 + 65535 + 2 = 65544
|
||||
*
|
||||
* The number 10 comes from the CCID protocol specification; It is the
|
||||
* header size of CCID. Besides, we can find the number 65544 in the
|
||||
* CCID protocol specification, too.
|
||||
*
|
||||
* And... we have "AND ONE MORE" three times.
|
||||
*
|
||||
* We accept that, as Buddha did.
|
||||
*
|
||||
* There are different interpretations for the historical fact and the
|
||||
* idiom. Most likely, nowadays, here, third-time is considered a
|
||||
* strikeout, perhaps, due to popularity of baseball.
|
||||
*/
|
||||
#define URB_DATA_SIZE (65544+10+1+1+1)
|
||||
|
||||
/*
|
||||
* The reasons why there are "+1" three times.
|
||||
*
|
||||
* Wrong (1): +1, because of confusion of data size maximum.
|
||||
* Wrong (2): +1, because of confusion of the size for Le.
|
||||
* Wrong (3): +1, because of keeping applying old patch.
|
||||
*
|
||||
* Something like this may occur, unfortunately, in our world.
|
||||
*
|
||||
* We need to consider the real case of the max buffer size for
|
||||
* libusb_bulk_transfer with CCID (let us call this "CASE_MAX").
|
||||
*
|
||||
* (1) Although the data size maximum (for all cases) is 65536, it
|
||||
* only occurs when Le size is zero. In the particular case of
|
||||
* CASE_MAX, it is actually 65535. When just applying the max value
|
||||
* 65536, +1 occurs.
|
||||
*
|
||||
* (2) Although maximum size to represent Le is 3, it only occurs when
|
||||
* Lc size is zero. In the particular case of CASE_MAX, it is
|
||||
* actually 2. When just applying the max value 3, +1 occurs.
|
||||
*
|
||||
* (3) Fedora keeps a old patch for Ominikey 3121. The patch was
|
||||
* written when the value of CMD_BUF_SIZE in libccid was small for
|
||||
* short extended APDU exchange. In the patch, it uses the value 11
|
||||
* for the header size (instead of 10) of TPDU, for its special
|
||||
* support. Historically, CMD_BUF_SIZE in libccid was updated
|
||||
* to bigger value to handle extended APDU exchange. When just applying
|
||||
* the old patch using 11, +1 occurs.
|
||||
*/
|
||||
|
||||
struct usbip_msg_cmd {
|
||||
uint32_t devid;
|
||||
@@ -299,12 +375,14 @@ static int write_data_transaction (struct usb_control *usbc_p,
|
||||
static int read_data_transaction (struct usb_control *usbc_p,
|
||||
int ep_num, char *buf, uint16_t count);
|
||||
|
||||
#define USB_MAX_PACKET_SIZE 64 /* For USB fullspeed device. */
|
||||
|
||||
static int
|
||||
hc_handle_control_urb (struct urb *urb)
|
||||
{
|
||||
int r;
|
||||
uint16_t count;
|
||||
uint16_t remain = urb->len;
|
||||
uint32_t remain = urb->len;
|
||||
uint64_t l;
|
||||
|
||||
if ((debug & DEBUG_USB))
|
||||
@@ -325,10 +403,10 @@ hc_handle_control_urb (struct urb *urb)
|
||||
|
||||
while (r == 0)
|
||||
{
|
||||
if (remain > 64)
|
||||
count = 64;
|
||||
if (remain > USB_MAX_PACKET_SIZE)
|
||||
count = USB_MAX_PACKET_SIZE;
|
||||
else
|
||||
count = remain;
|
||||
count = (uint16_t)remain;
|
||||
|
||||
read (usbc_ep0.eventfd, &l, sizeof (l));
|
||||
r = control_write_data_transaction (urb->data_p, count);
|
||||
@@ -337,7 +415,7 @@ hc_handle_control_urb (struct urb *urb)
|
||||
|
||||
urb->data_p += count;
|
||||
remain -= count;
|
||||
if (count < 64)
|
||||
if (count < USB_MAX_PACKET_SIZE)
|
||||
break;
|
||||
}
|
||||
if (r >= 0)
|
||||
@@ -353,10 +431,10 @@ hc_handle_control_urb (struct urb *urb)
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (remain > 64)
|
||||
count = 64;
|
||||
if (remain > USB_MAX_PACKET_SIZE)
|
||||
count = USB_MAX_PACKET_SIZE;
|
||||
else
|
||||
count = remain;
|
||||
count = (uint16_t)remain;
|
||||
|
||||
read (usbc_ep0.eventfd, &l, sizeof (l));
|
||||
r = control_read_data_transaction (urb->data_p, count);
|
||||
@@ -368,7 +446,7 @@ hc_handle_control_urb (struct urb *urb)
|
||||
|
||||
remain -= r;
|
||||
urb->data_p += r;
|
||||
if (r < 64)
|
||||
if (r < USB_MAX_PACKET_SIZE)
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -516,10 +594,10 @@ hc_handle_data_urb (struct usb_control *usbc_p)
|
||||
if ((debug & DEBUG_USB))
|
||||
puts ("hc_hdu 0");
|
||||
|
||||
if (urb->remain > 64)
|
||||
count = 64;
|
||||
if (urb->remain > USB_MAX_PACKET_SIZE)
|
||||
count = USB_MAX_PACKET_SIZE;
|
||||
else
|
||||
count = urb->remain;
|
||||
count = (uint16_t)urb->remain;
|
||||
|
||||
if (urb->dir == USBIP_DIR_OUT)
|
||||
{ /* Output from host to device. */
|
||||
@@ -533,7 +611,7 @@ hc_handle_data_urb (struct usb_control *usbc_p)
|
||||
urb->data_p += count;
|
||||
urb->remain -= count;
|
||||
|
||||
if (urb->remain == 0 || count < 64)
|
||||
if (urb->remain == 0 || count < USB_MAX_PACKET_SIZE)
|
||||
{
|
||||
size_t len = urb->len - urb->remain;
|
||||
|
||||
@@ -565,7 +643,7 @@ hc_handle_data_urb (struct usb_control *usbc_p)
|
||||
|
||||
urb->remain -= r;
|
||||
urb->data_p += r;
|
||||
if (urb->remain == 0 || r < 64)
|
||||
if (urb->remain == 0 || r < USB_MAX_PACKET_SIZE)
|
||||
{
|
||||
size_t len = urb->len - urb->remain;
|
||||
|
||||
@@ -596,7 +674,7 @@ issue_get_desc (void)
|
||||
{
|
||||
struct urb *urb;
|
||||
|
||||
urb = malloc (sizeof (struct urb) + 64);
|
||||
urb = malloc (sizeof (struct urb) + USB_MAX_PACKET_SIZE);
|
||||
|
||||
urb->next = urb->prev = urb;
|
||||
|
||||
@@ -606,14 +684,14 @@ issue_get_desc (void)
|
||||
urb->setup[3] = 1; /* Value H: desc_type */
|
||||
urb->setup[4] = 0; /* Index */
|
||||
urb->setup[5] = 0;
|
||||
urb->setup[6] = 64; /* Length */
|
||||
urb->setup[6] = USB_MAX_PACKET_SIZE; /* Length */
|
||||
urb->setup[7] = 0;
|
||||
urb->data_p = urb->data;
|
||||
urb->seq = 0;
|
||||
urb->devid = 0;
|
||||
urb->dir = USBIP_DIR_IN;
|
||||
urb->ep = 0;
|
||||
urb->remain = urb->len = 64;
|
||||
urb->remain = urb->len = USB_MAX_PACKET_SIZE;
|
||||
hc_handle_control_urb (urb);
|
||||
return urb;
|
||||
}
|
||||
@@ -729,7 +807,7 @@ usbip_handle_urb (uint32_t seq)
|
||||
|
||||
leave:
|
||||
msg.cmd = htonl (REP_URB_SUBMIT);
|
||||
msg.seq = htonl (urb->seq);
|
||||
msg.seq = htonl (seq);
|
||||
|
||||
memset (&msg_rep, 0, sizeof (msg_rep));
|
||||
msg_rep.status = htonl (r);
|
||||
|
||||
Reference in New Issue
Block a user