cleanup usage of USB endpoint

This commit is contained in:
NIIBE Yutaka
2012-05-12 08:06:33 +09:00
parent f5cefbcab4
commit 7fb547a87e
7 changed files with 79 additions and 43 deletions

View File

@@ -1,3 +1,26 @@
2012-05-12 Niibe Yutaka <gniibe@fsij.org>
* src/usb_msc.c (ep6_out): Rename (was: ep7_out).
(usb_start_receive): Use ep6_out and ENDP6.
(EP6_OUT_Callback): Rename (was: EP7_OUT_Callback).
Use ep6_out and ENDP6.
(msc_handle_command): Use ep6_out and ENDP6.
* src/main.c (main): Wait USB reset.
* src/usb-icc.c (EP1_OUT_Callback): Rename from EP2_OUT_Callback.
(USBthread): Use ENDP1 for both of epi_init and epo_init.
* src/usb_conf.h (ENDP1_RXADDR, ENDP2_TXADDR, ENDP6_RXADDR): New.
(ENDP3_TXADDR, ENDP4_TXADDR, ENDP5_RXADDR): New value.
(ENDP7_RXADDR): Remove.
* src/usb_desc.c (gnukConfigDescriptor): Use endpoint OUT1 (was
IN2), endpoint OUT6 (IN7).
* src/usb_prop.c (gnuk_setup_endpoints_for_interface): Use ENDP1
and ENDP6 for both directions.
2012-05-11 Niibe Yutaka <gniibe@fsij.org>
* src/configure (--vidpid): New mandatory option.

View File

@@ -1,7 +1,7 @@
/*
* main.c - main routine of Gnuk
*
* Copyright (C) 2010, 2011 Free Software Initiative of Japan
* Copyright (C) 2010, 2011, 2012 Free Software Initiative of Japan
* Author: NIIBE Yutaka <gniibe@fsij.org>
*
* This file is a part of Gnuk, a GnuPG USB Token implementation.
@@ -376,6 +376,14 @@ main (int argc, char **argv)
usb_lld_init ();
random_init ();
while (1)
{
if (bDeviceState != UNCONNECTED)
break;
chThdSleepMilliseconds (250);
}
#ifdef DEBUG
stdout_init ();

View File

@@ -635,7 +635,7 @@ icc_prepare_receive (struct ccid *c)
*/
void
EP2_OUT_Callback (void)
EP1_OUT_Callback (void)
{
struct ep_out *epo = &endpoint_out;
size_t len = usb_lld_rx_data_len (epo->ep_num);
@@ -1285,7 +1285,7 @@ USBthread (void *arg)
(void)arg;
epi_init (epi, ENDP1, notify_tx, c);
epo_init (epo, ENDP2, notify_icc, c);
epo_init (epo, ENDP1, notify_icc, c);
ccid_init (c, epi, epo, a, chThdSelf ());
apdu_init (a);

View File

@@ -5,25 +5,36 @@
#define NUM_STRING_DESC 4
/* Control pipe */
/* EP0 */
#define ENDP0_RXADDR (0x40)
#define ENDP0_TXADDR (0x80)
/* CCID/ICCD BULK_IN, BULK_OUT */
/* EP1 */
#define ENDP1_TXADDR (0xc0)
#define ENDP1_RXADDR (0x100)
/* HID INTR_IN, INTR_OUT */
/* EP2 */
#define ENDP2_RXADDR (0x100)
#define ENDP2_TXADDR (0x140)
#define ENDP2_RXADDR (0x148)
/* CDC BULK_IN, INTR_IN, BULK_OUT */
/* EP3 */
#define ENDP3_TXADDR (0x140)
#define ENDP3_TXADDR (0x14a)
/* EP4 */
#define ENDP4_TXADDR (0x150)
#define ENDP4_TXADDR (0x15a)
/* EP5 */
#define ENDP5_RXADDR (0x160)
#define ENDP5_RXADDR (0x162)
/* 0x172 - 0x180 : 14-byte */
/* MSC BULK_IN, BULK_OUT */
/* EP6 */
#define ENDP6_TXADDR (0x180)
/* EP7 */
#define ENDP7_RXADDR (0x1c0)
#define ENDP6_RXADDR (0x1c0)
/* EP7: free */
#endif /* __USB_CONF_H */

View File

@@ -129,17 +129,17 @@ static const uint8_t gnukConfigDescriptor[] = {
0, /* bPinSupport: No PIN pad */
#endif
1, /* bMaxCCIDBusySlots: 1 */
/*Endpoint 1 Descriptor*/
/*Endpoint IN1 Descriptor*/
7, /* bLength: Endpoint Descriptor size */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
0x81, /* bEndpointAddress: (IN1) */
0x02, /* bmAttributes: Bulk */
USB_ICC_DATA_SIZE, 0x00, /* wMaxPacketSize: */
0x00, /* bInterval */
/*Endpoint 2 Descriptor*/
/*Endpoint OUT1 Descriptor*/
7, /* bLength: Endpoint Descriptor size */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
0x02, /* bEndpointAddress: (OUT2) */
0x01, /* bEndpointAddress: (OUT1) */
0x02, /* bmAttributes: Bulk */
USB_ICC_DATA_SIZE, 0x00, /* wMaxPacketSize: */
0x00, /* bInterval */
@@ -238,7 +238,7 @@ static const uint8_t gnukConfigDescriptor[] = {
/* Endpoint Descriptor.*/
7, /* bLength: Endpoint Descriptor size */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
0x07, /* bEndpointAddress: (OUT7) */
0x06, /* bEndpointAddress: (OUT6) */
0x02, /* bmAttributes (Bulk). */
0x40, 0x00, /* wMaxPacketSize. */
0x00, /* bInterval (ignored for bulk). */

View File

@@ -40,7 +40,7 @@ struct usb_endp_out {
};
static struct usb_endp_in ep6_in;
static struct usb_endp_out ep7_out;
static struct usb_endp_out ep6_out;
static Thread *the_thread;
@@ -102,32 +102,32 @@ void EP6_IN_Callback (void)
static void usb_start_receive (uint8_t *p, size_t n)
{
ep7_out.rxbuf = p;
ep7_out.rxsize = n;
ep7_out.rxcnt = 0;
usb_lld_rx_enable (ENDP7);
ep6_out.rxbuf = p;
ep6_out.rxsize = n;
ep6_out.rxcnt = 0;
usb_lld_rx_enable (ENDP6);
}
/* "Data Received" call back */
void EP7_OUT_Callback (void)
void EP6_OUT_Callback (void)
{
size_t n = (size_t)usb_lld_rx_data_len (ENDP7);
size_t n = (size_t)usb_lld_rx_data_len (ENDP6);
int err = 0;
if (n > ep7_out.rxsize)
if (n > ep6_out.rxsize)
{ /* buffer overflow */
err = 1;
n = ep7_out.rxsize;
n = ep6_out.rxsize;
}
usb_lld_rxcpy (ep7_out.rxbuf, ENDP7, 0, n);
ep7_out.rxbuf += n;
ep7_out.rxcnt += n;
ep7_out.rxsize -= n;
usb_lld_rxcpy (ep6_out.rxbuf, ENDP6, 0, n);
ep6_out.rxbuf += n;
ep6_out.rxcnt += n;
ep6_out.rxsize -= n;
if (n == ENDP_MAX_SIZE && ep7_out.rxsize != 0)
if (n == ENDP_MAX_SIZE && ep6_out.rxsize != 0)
{ /* More data to be received */
usb_lld_rx_enable (ENDP7);
usb_lld_rx_enable (ENDP6);
return;
}
@@ -316,19 +316,19 @@ void msc_handle_command (void)
if (msg != RDY_TIMEOUT)
{
chSysLock ();
usb_lld_stall_rx (ENDP7);
usb_lld_stall_rx (ENDP6);
chSysUnlock ();
}
return;
}
n = ep7_out.rxcnt;
n = ep6_out.rxcnt;
if ((n != sizeof (struct CBW)) || (CBW.dCBWSignature != MSC_CBW_SIGNATURE))
{
msc_state = MSC_ERROR;
chSysLock ();
usb_lld_stall_rx (ENDP7);
usb_lld_stall_rx (ENDP6);
chSysUnlock ();
return;
}
@@ -432,7 +432,7 @@ void msc_handle_command (void)
msc_state = MSC_ERROR;
chSysLock ();
usb_lld_stall_tx (ENDP6);
usb_lld_stall_rx (ENDP7);
usb_lld_stall_rx (ENDP6);
chSysUnlock ();
return;
}

View File

@@ -90,10 +90,7 @@ gnuk_setup_endpoints_for_interface (uint16_t interface)
if (interface == 0)
{
/* Initialize Endpoint 1 */
usb_lld_setup_endpoint (ENDP1, EP_BULK, 0, 0, ENDP1_TXADDR, 0);
/* Initialize Endpoint 2 */
usb_lld_setup_endpoint (ENDP2, EP_BULK, 0, ENDP2_RXADDR, 0,
usb_lld_setup_endpoint (ENDP1, EP_BULK, 0, ENDP1_RXADDR, ENDP1_TXADDR,
GNUK_MAX_PACKET_SIZE);
}
#ifdef ENABLE_VIRTUAL_COM_PORT
@@ -120,11 +117,9 @@ gnuk_setup_endpoints_for_interface (uint16_t interface)
# endif
{
/* Initialize Endpoint 6 */
usb_lld_setup_endpoint (ENDP6, EP_BULK, 0, 0, ENDP6_TXADDR, 0);
/* Initialize Endpoint 7 */
usb_lld_setup_endpoint (ENDP7, EP_BULK, 0, ENDP7_RXADDR, 0, 64);
usb_lld_stall_rx (ENDP7);
usb_lld_setup_endpoint (ENDP6, EP_BULK, 0, ENDP6_RXADDR, ENDP6_TXADDR,
64);
usb_lld_stall_rx (ENDP6);
}
#endif
}
@@ -157,8 +152,7 @@ gnuk_device_reset (void)
usb_lld_reset ();
/* Initialize Endpoint 0 */
usb_lld_setup_endpoint (ENDP0, EP_CONTROL, 0,
ENDP0_RXADDR, ENDP0_TXADDR,
usb_lld_setup_endpoint (ENDP0, EP_CONTROL, 0, ENDP0_RXADDR, ENDP0_TXADDR,
GNUK_MAX_PACKET_SIZE);
for (i = 0; i < NUM_INTERFACES; i++)