Fix USB stack a bit
This commit is contained in:
23
ChangeLog
23
ChangeLog
@@ -1,3 +1,26 @@
|
|||||||
|
2016-03-08 Niibe Yutaka <gniibe@fsij.org>
|
||||||
|
|
||||||
|
* tool/gnuk_token.py (gnuk_token.__init__, regnual.__init__):
|
||||||
|
Don't call setConfiguration method.
|
||||||
|
|
||||||
|
* src/usb_lld.h (usb_cb_ctrl_write_finish): Change the API of
|
||||||
|
callback, which possibly needs INDEX, VALUE, and LEN parameters.
|
||||||
|
(usb_lld_set_data_to_recv): Fix the type of P.
|
||||||
|
(USB_DEVICE_DESCRIPTOR_TYPE, USB_CONFIGURATION_DESCRIPTOR_TYPE)
|
||||||
|
(USB_STRING_DESCRIPTOR_TYPE, USB_INTERFACE_DESCRIPTOR_TYPE)
|
||||||
|
(USB_ENDPOINT_DESCRIPTOR_TYPE): Remove, as we have the enumeration
|
||||||
|
values for same things.
|
||||||
|
|
||||||
|
* src/usb_stm32f103.c (handle_in0): Follow the change.
|
||||||
|
* src/usb_ctrl.c (usb_cb_ctrl_write_finish): Likewise.
|
||||||
|
|
||||||
|
* src/usb_desc.c (usb_cb_get_descriptor): Use HID_INTERFACE.
|
||||||
|
(device_desc, config_desc, string_descriptors)
|
||||||
|
(usb_cb_get_descriptor): Use the enumeration types.
|
||||||
|
* src/configure: Use the enumeration types.
|
||||||
|
|
||||||
|
* regnual/regnual.c: Follow the change of usb_lld.h.
|
||||||
|
|
||||||
2016-02-09 Niibe Yutaka <gniibe@fsij.org>
|
2016-02-09 Niibe Yutaka <gniibe@fsij.org>
|
||||||
|
|
||||||
* src/openpgp.c (cmd_verify): Support VERIFY reset, which is
|
* src/openpgp.c (cmd_verify): Support VERIFY reset, which is
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* regnual.c -- Firmware installation for STM32F103 Flash ROM
|
* regnual.c -- Firmware installation for STM32F103 Flash ROM
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012, 2013, 2015
|
* Copyright (C) 2012, 2013, 2015, 2016
|
||||||
* Free Software Initiative of Japan
|
* Free Software Initiative of Japan
|
||||||
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
||||||
*
|
*
|
||||||
@@ -51,7 +51,7 @@ static uint32_t flash_end;
|
|||||||
/* USB Standard Device Descriptor */
|
/* USB Standard Device Descriptor */
|
||||||
static const uint8_t regnual_device_desc[] = {
|
static const uint8_t regnual_device_desc[] = {
|
||||||
18, /* bLength */
|
18, /* bLength */
|
||||||
USB_DEVICE_DESCRIPTOR_TYPE, /* bDescriptorType */
|
DEVICE_DESCRIPTOR, /* bDescriptorType */
|
||||||
0x10, 0x01, /* bcdUSB = 1.1 */
|
0x10, 0x01, /* bcdUSB = 1.1 */
|
||||||
0xFF, /* bDeviceClass: VENDOR */
|
0xFF, /* bDeviceClass: VENDOR */
|
||||||
0x00, /* bDeviceSubClass */
|
0x00, /* bDeviceSubClass */
|
||||||
@@ -66,7 +66,7 @@ static const uint8_t regnual_device_desc[] = {
|
|||||||
|
|
||||||
static const uint8_t regnual_config_desc[] = {
|
static const uint8_t regnual_config_desc[] = {
|
||||||
9,
|
9,
|
||||||
USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
|
CONFIG_DESCRIPTOR, /* bDescriptorType: Configuration */
|
||||||
18, 0, /* wTotalLength: no of returned bytes */
|
18, 0, /* wTotalLength: no of returned bytes */
|
||||||
1, /* bNumInterfaces: single vendor interface */
|
1, /* bNumInterfaces: single vendor interface */
|
||||||
0x01, /* bConfigurationValue: Configuration value */
|
0x01, /* bConfigurationValue: Configuration value */
|
||||||
@@ -80,7 +80,7 @@ static const uint8_t regnual_config_desc[] = {
|
|||||||
|
|
||||||
/* Interface Descriptor */
|
/* Interface Descriptor */
|
||||||
9,
|
9,
|
||||||
USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: Interface */
|
INTERFACE_DESCRIPTOR, /* bDescriptorType: Interface */
|
||||||
0, /* bInterfaceNumber: Index of this interface */
|
0, /* bInterfaceNumber: Index of this interface */
|
||||||
0, /* Alternate setting for this interface */
|
0, /* Alternate setting for this interface */
|
||||||
0, /* bNumEndpoints: None */
|
0, /* bNumEndpoints: None */
|
||||||
@@ -92,7 +92,7 @@ static const uint8_t regnual_config_desc[] = {
|
|||||||
|
|
||||||
static const uint8_t regnual_string_lang_id[] = {
|
static const uint8_t regnual_string_lang_id[] = {
|
||||||
4, /* bLength */
|
4, /* bLength */
|
||||||
USB_STRING_DESCRIPTOR_TYPE,
|
STRING_DESCRIPTOR,
|
||||||
0x09, 0x04 /* LangID = 0x0409: US-English */
|
0x09, 0x04 /* LangID = 0x0409: US-English */
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@ static const uint8_t regnual_string_lang_id[] = {
|
|||||||
|
|
||||||
static const uint8_t regnual_string_serial[] = {
|
static const uint8_t regnual_string_serial[] = {
|
||||||
8*2+2,
|
8*2+2,
|
||||||
USB_STRING_DESCRIPTOR_TYPE,
|
STRING_DESCRIPTOR,
|
||||||
/* FSIJ-0.0 */
|
/* FSIJ-0.0 */
|
||||||
'F', 0, 'S', 0, 'I', 0, 'J', 0, '-', 0,
|
'F', 0, 'S', 0, 'I', 0, 'J', 0, '-', 0,
|
||||||
'0', 0, '.', 0, '0', 0,
|
'0', 0, '.', 0, '0', 0,
|
||||||
@@ -173,29 +173,30 @@ static uint32_t calc_crc32 (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void usb_cb_ctrl_write_finish (uint8_t req, uint8_t req_no, uint16_t value)
|
void usb_cb_ctrl_write_finish (uint8_t req, uint8_t req_no,
|
||||||
|
struct req_args *detail)
|
||||||
{
|
{
|
||||||
uint8_t type_rcp = req & (REQUEST_TYPE|RECIPIENT);
|
uint8_t type_rcp = req & (REQUEST_TYPE|RECIPIENT);
|
||||||
|
|
||||||
if (type_rcp == (VENDOR_REQUEST | DEVICE_RECIPIENT) && USB_SETUP_SET (req))
|
if (type_rcp == (VENDOR_REQUEST | DEVICE_RECIPIENT) && USB_SETUP_SET (req))
|
||||||
{
|
{
|
||||||
if (req_no == USB_REGNUAL_SEND && value == 0)
|
if (req_no == USB_REGNUAL_SEND && detail->value == 0)
|
||||||
result = calc_crc32 ();
|
result = calc_crc32 ();
|
||||||
else if (req_no == USB_REGNUAL_FLASH)
|
else if (req_no == USB_REGNUAL_FLASH)
|
||||||
{
|
{
|
||||||
uint32_t dst_addr = (0x08000000 + value * 0x100);
|
uint32_t dst_addr = (0x08000000 + detail->value * 0x100);
|
||||||
|
|
||||||
result = flash_write (dst_addr, (const uint8_t *)mem, 256);
|
result = flash_write (dst_addr, (const uint8_t *)mem, 256);
|
||||||
}
|
}
|
||||||
else if (req_no == USB_REGNUAL_PROTECT && value == 0)
|
else if (req_no == USB_REGNUAL_PROTECT && detail->value == 0)
|
||||||
result = flash_protect ();
|
result = flash_protect ();
|
||||||
else if (req_no == USB_REGNUAL_FINISH && value == 0)
|
else if (req_no == USB_REGNUAL_FINISH && detail->value == 0)
|
||||||
nvic_system_reset ();
|
nvic_system_reset ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
usb_cb_setup (uint8_t req, uint8_t req_no, struct control_info *detail)
|
usb_cb_setup (uint8_t req, uint8_t req_no, struct req_args *detail)
|
||||||
{
|
{
|
||||||
uint8_t type_rcp = req & (REQUEST_TYPE|RECIPIENT);
|
uint8_t type_rcp = req & (REQUEST_TYPE|RECIPIENT);
|
||||||
|
|
||||||
@@ -250,7 +251,7 @@ usb_cb_setup (uint8_t req, uint8_t req_no, struct control_info *detail)
|
|||||||
|
|
||||||
int
|
int
|
||||||
usb_cb_get_descriptor (uint8_t rcp, uint8_t desc_type, uint8_t desc_index,
|
usb_cb_get_descriptor (uint8_t rcp, uint8_t desc_type, uint8_t desc_index,
|
||||||
struct control_info *detail)
|
struct req_args *detail)
|
||||||
{
|
{
|
||||||
if (rcp != DEVICE_RECIPIENT)
|
if (rcp != DEVICE_RECIPIENT)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
@@ -310,7 +311,7 @@ int usb_cb_handle_event (uint8_t event_type, uint16_t value)
|
|||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
int usb_cb_interface (uint8_t cmd, struct control_info *detail)
|
int usb_cb_interface (uint8_t cmd, struct req_args *detail)
|
||||||
{
|
{
|
||||||
(void)cmd; (void)detail;
|
(void)cmd; (void)detail;
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|||||||
10
src/configure
vendored
10
src/configure
vendored
@@ -276,14 +276,14 @@ output_vendor_product_serial_strings () {
|
|||||||
|
|
||||||
echo "static const uint8_t ${prefix}string_vendor[] = {"
|
echo "static const uint8_t ${prefix}string_vendor[] = {"
|
||||||
echo " ${#VENDOR}*2+2, /* bLength */"
|
echo " ${#VENDOR}*2+2, /* bLength */"
|
||||||
echo " USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */"
|
echo " STRING_DESCRIPTOR, /* bDescriptorType */"
|
||||||
echo " /* Manufacturer: \"$VENDOR\" */"
|
echo " /* Manufacturer: \"$VENDOR\" */"
|
||||||
echo $VENDOR | sed -e "s/\(........\)/\1\\${nl}/g" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "/^ ./s/ $//p"
|
echo $VENDOR | sed -e "s/\(........\)/\1\\${nl}/g" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "/^ ./s/ $//p"
|
||||||
echo '};'
|
echo '};'
|
||||||
echo
|
echo
|
||||||
echo "static const uint8_t ${prefix}string_product[] = {"
|
echo "static const uint8_t ${prefix}string_product[] = {"
|
||||||
echo " ${#PRODUCT}*2+2, /* bLength */"
|
echo " ${#PRODUCT}*2+2, /* bLength */"
|
||||||
echo " USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */"
|
echo " STRING_DESCRIPTOR, /* bDescriptorType */"
|
||||||
echo " /* Product name: \"$PRODUCT\" */"
|
echo " /* Product name: \"$PRODUCT\" */"
|
||||||
echo $PRODUCT | sed -e "s/\(........\)/\1\\${nl}/g" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "/^ ./s/ $//p"
|
echo $PRODUCT | sed -e "s/\(........\)/\1\\${nl}/g" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "/^ ./s/ $//p"
|
||||||
echo '};'
|
echo '};'
|
||||||
@@ -292,7 +292,7 @@ output_vendor_product_serial_strings () {
|
|||||||
echo
|
echo
|
||||||
echo "uint8_t ${prefix}string_serial[] = {"
|
echo "uint8_t ${prefix}string_serial[] = {"
|
||||||
echo " ${#SERIALNO}*2+2+16, /* bLength */"
|
echo " ${#SERIALNO}*2+2+16, /* bLength */"
|
||||||
echo " USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */"
|
echo " STRING_DESCRIPTOR, /* bDescriptorType */"
|
||||||
echo " /* Serial number: \"$SERIALNO\" */"
|
echo " /* Serial number: \"$SERIALNO\" */"
|
||||||
echo $SERIALNO | sed -e "s/\(........\)/\1\\${nl}/g" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "/^ ./s/ $//p"
|
echo $SERIALNO | sed -e "s/\(........\)/\1\\${nl}/g" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "/^ ./s/ $//p"
|
||||||
echo " 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,"
|
echo " 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,"
|
||||||
@@ -302,14 +302,14 @@ output_vendor_product_serial_strings () {
|
|||||||
echo '#ifdef USB_STRINGS_FOR_GNUK'
|
echo '#ifdef USB_STRINGS_FOR_GNUK'
|
||||||
echo "static const uint8_t ${prefix}revision_detail[] = {"
|
echo "static const uint8_t ${prefix}revision_detail[] = {"
|
||||||
echo " ${#REVISION}*2+2, /* bLength */"
|
echo " ${#REVISION}*2+2, /* bLength */"
|
||||||
echo " USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */"
|
echo " STRING_DESCRIPTOR, /* bDescriptorType */"
|
||||||
echo " /* revision detail: \"$REVISION\" */"
|
echo " /* revision detail: \"$REVISION\" */"
|
||||||
echo $REVISION | sed -e "s/\(........\)/\1\\${nl}/g" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "/^ ./s/ $//p"
|
echo $REVISION | sed -e "s/\(........\)/\1\\${nl}/g" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "/^ ./s/ $//p"
|
||||||
echo '};'
|
echo '};'
|
||||||
echo
|
echo
|
||||||
echo "static const uint8_t ${prefix}config_options[] = {"
|
echo "static const uint8_t ${prefix}config_options[] = {"
|
||||||
echo " ${#CONFIG}*2+2, /* bLength */"
|
echo " ${#CONFIG}*2+2, /* bLength */"
|
||||||
echo " USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */"
|
echo " STRING_DESCRIPTOR, /* bDescriptorType */"
|
||||||
echo " /* configure options: \"$CONFIG\" */"
|
echo " /* configure options: \"$CONFIG\" */"
|
||||||
echo $CONFIG | sed -e "s/\(........\)/\1\\${nl}/g" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "/^ ./s/ $//p"
|
echo $CONFIG | sed -e "s/\(........\)/\1\\${nl}/g" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "/^ ./s/ $//p"
|
||||||
echo '};'
|
echo '};'
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* usb_ctrl.c - USB control pipe device specific code for Gnuk
|
* usb_ctrl.c - USB control pipe device specific code for Gnuk
|
||||||
*
|
*
|
||||||
* Copyright (C) 2010, 2011, 2012, 2013, 2015
|
* Copyright (C) 2010, 2011, 2012, 2013, 2015, 2016
|
||||||
* Free Software Initiative of Japan
|
* Free Software Initiative of Japan
|
||||||
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
* Author: NIIBE Yutaka <gniibe@fsij.org>
|
||||||
*
|
*
|
||||||
@@ -61,12 +61,12 @@ static struct line_coding line_coding = {
|
|||||||
#define CDC_CTRL_DTR 0x0001
|
#define CDC_CTRL_DTR 0x0001
|
||||||
|
|
||||||
static int
|
static int
|
||||||
vcom_port_data_setup (uint8_t req, uint8_t req_no, struct control_info *detail)
|
vcom_port_data_setup (uint8_t req, uint8_t req_no, struct req_args *arg)
|
||||||
{
|
{
|
||||||
if (USB_SETUP_GET (req))
|
if (USB_SETUP_GET (req))
|
||||||
{
|
{
|
||||||
if (req_no == USB_CDC_REQ_GET_LINE_CODING)
|
if (req_no == USB_CDC_REQ_GET_LINE_CODING)
|
||||||
return usb_lld_reply_request (&line_coding, sizeof(line_coding), detail);
|
return usb_lld_reply_request (&line_coding, sizeof(line_coding), arg);
|
||||||
}
|
}
|
||||||
else /* USB_SETUP_SET (req) */
|
else /* USB_SETUP_SET (req) */
|
||||||
{
|
{
|
||||||
@@ -79,7 +79,7 @@ vcom_port_data_setup (uint8_t req, uint8_t req_no, struct control_info *detail)
|
|||||||
{
|
{
|
||||||
uint8_t connected_saved = stdout.connected;
|
uint8_t connected_saved = stdout.connected;
|
||||||
|
|
||||||
if ((detail->value & CDC_CTRL_DTR) != 0)
|
if ((arg->value & CDC_CTRL_DTR) != 0)
|
||||||
{
|
{
|
||||||
if (stdout.connected == 0)
|
if (stdout.connected == 0)
|
||||||
/* It's Open call */
|
/* It's Open call */
|
||||||
@@ -264,7 +264,7 @@ static int download_check_crc32 (const uint32_t *end_p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
usb_cb_setup (uint8_t req, uint8_t req_no, struct control_info *detail)
|
usb_cb_setup (uint8_t req, uint8_t req_no, struct req_args *arg)
|
||||||
{
|
{
|
||||||
uint8_t type_rcp = req & (REQUEST_TYPE|RECIPIENT);
|
uint8_t type_rcp = req & (REQUEST_TYPE|RECIPIENT);
|
||||||
|
|
||||||
@@ -273,27 +273,29 @@ usb_cb_setup (uint8_t req, uint8_t req_no, struct control_info *detail)
|
|||||||
if (USB_SETUP_GET (req))
|
if (USB_SETUP_GET (req))
|
||||||
{
|
{
|
||||||
if (req_no == USB_FSIJ_GNUK_MEMINFO)
|
if (req_no == USB_FSIJ_GNUK_MEMINFO)
|
||||||
return usb_lld_reply_request (mem_info, sizeof (mem_info), detail);
|
return usb_lld_reply_request (mem_info, sizeof (mem_info), arg);
|
||||||
}
|
}
|
||||||
else /* SETUP_SET */
|
else /* SETUP_SET */
|
||||||
{
|
{
|
||||||
uint8_t *addr = (uint8_t *)(0x20000000 + detail->value * 0x100 + detail->index);
|
uint8_t *addr = (uint8_t *)(0x20000000 + arg->value * 0x100
|
||||||
|
+ arg->index);
|
||||||
|
|
||||||
if (req_no == USB_FSIJ_GNUK_DOWNLOAD)
|
if (req_no == USB_FSIJ_GNUK_DOWNLOAD)
|
||||||
{
|
{
|
||||||
if (*icc_state_p != ICC_STATE_EXITED)
|
if (*icc_state_p != ICC_STATE_EXITED)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if (addr < &_regnual_start || addr + detail->len > __heap_end__)
|
if (addr < &_regnual_start || addr + arg->len > __heap_end__)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if (detail->index + detail->len < 256)
|
if (arg->index + arg->len < 256)
|
||||||
memset (addr + detail->index + detail->len, 0, 256 - (detail->index + detail->len));
|
memset (addr + arg->index + arg->len, 0,
|
||||||
|
256 - (arg->index + arg->len));
|
||||||
|
|
||||||
usb_lld_set_data_to_recv (addr, detail->len);
|
usb_lld_set_data_to_recv (addr, arg->len);
|
||||||
return USB_SUCCESS;
|
return USB_SUCCESS;
|
||||||
}
|
}
|
||||||
else if (req_no == USB_FSIJ_GNUK_EXEC && detail->len == 0)
|
else if (req_no == USB_FSIJ_GNUK_EXEC && arg->len == 0)
|
||||||
{
|
{
|
||||||
if (*icc_state_p != ICC_STATE_EXITED)
|
if (*icc_state_p != ICC_STATE_EXITED)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
@@ -303,28 +305,28 @@ usb_cb_setup (uint8_t req, uint8_t req_no, struct control_info *detail)
|
|||||||
|
|
||||||
return download_check_crc32 ((uint32_t *)addr);
|
return download_check_crc32 ((uint32_t *)addr);
|
||||||
}
|
}
|
||||||
else if (req_no == USB_FSIJ_GNUK_CARD_CHANGE && detail->len == 0)
|
else if (req_no == USB_FSIJ_GNUK_CARD_CHANGE && arg->len == 0)
|
||||||
{
|
{
|
||||||
if (detail->value != 0 && detail->value != 1 && detail->value != 2)
|
if (arg->value != 0 && arg->value != 1 && arg->value != 2)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
ccid_card_change_signal (detail->value);
|
ccid_card_change_signal (arg->value);
|
||||||
return USB_SUCCESS;
|
return USB_SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (type_rcp == (CLASS_REQUEST | INTERFACE_RECIPIENT))
|
else if (type_rcp == (CLASS_REQUEST | INTERFACE_RECIPIENT))
|
||||||
{
|
{
|
||||||
if (detail->index == ICC_INTERFACE)
|
if (arg->index == ICC_INTERFACE)
|
||||||
{
|
{
|
||||||
if (USB_SETUP_GET (req))
|
if (USB_SETUP_GET (req))
|
||||||
{
|
{
|
||||||
if (req_no == USB_CCID_REQ_GET_CLOCK_FREQUENCIES)
|
if (req_no == USB_CCID_REQ_GET_CLOCK_FREQUENCIES)
|
||||||
return usb_lld_reply_request (freq_table, sizeof (freq_table),
|
return usb_lld_reply_request (freq_table, sizeof (freq_table),
|
||||||
detail);
|
arg);
|
||||||
else if (req_no == USB_CCID_REQ_GET_DATA_RATES)
|
else if (req_no == USB_CCID_REQ_GET_DATA_RATES)
|
||||||
return usb_lld_reply_request (data_rate_table,
|
return usb_lld_reply_request (data_rate_table,
|
||||||
sizeof (data_rate_table), detail);
|
sizeof (data_rate_table), arg);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -335,24 +337,24 @@ usb_cb_setup (uint8_t req, uint8_t req_no, struct control_info *detail)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef HID_CARD_CHANGE_SUPPORT
|
#ifdef HID_CARD_CHANGE_SUPPORT
|
||||||
else if (index == HID_INTERFACE)
|
else if (arg->index == HID_INTERFACE)
|
||||||
{
|
{
|
||||||
switch (req_no)
|
switch (req_no)
|
||||||
{
|
{
|
||||||
case USB_HID_REQ_GET_IDLE:
|
case USB_HID_REQ_GET_IDLE:
|
||||||
return usb_lld_reply_request (&hid_idle_rate, 1, detail);
|
return usb_lld_reply_request (&hid_idle_rate, 1, arg);
|
||||||
case USB_HID_REQ_SET_IDLE:
|
case USB_HID_REQ_SET_IDLE:
|
||||||
usb_lld_set_data_to_recv (&hid_idle_rate, 1, detail);
|
usb_lld_set_data_to_recv (&hid_idle_rate, 1);
|
||||||
return USB_SUCCESS;
|
return USB_SUCCESS;
|
||||||
|
|
||||||
case USB_HID_REQ_GET_REPORT:
|
case USB_HID_REQ_GET_REPORT:
|
||||||
/* Request of LED status and key press */
|
/* Request of LED status and key press */
|
||||||
return usb_lld_reply_request (&hid_report, 2, detail);
|
return usb_lld_reply_request (&hid_report, 2, arg);
|
||||||
|
|
||||||
case USB_HID_REQ_SET_REPORT:
|
case USB_HID_REQ_SET_REPORT:
|
||||||
/* Received LED set request */
|
/* Received LED set request */
|
||||||
if (detail->len == 1)
|
if (arg->len == 1)
|
||||||
usb_lld_set_data_to_recv (&hid_report, detail->len);
|
usb_lld_set_data_to_recv (&hid_report, arg->len);
|
||||||
return USB_SUCCESS;
|
return USB_SUCCESS;
|
||||||
|
|
||||||
case USB_HID_REQ_GET_PROTOCOL:
|
case USB_HID_REQ_GET_PROTOCOL:
|
||||||
@@ -366,17 +368,17 @@ usb_cb_setup (uint8_t req, uint8_t req_no, struct control_info *detail)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_VIRTUAL_COM_PORT
|
#ifdef ENABLE_VIRTUAL_COM_PORT
|
||||||
else if (index == VCOM_INTERFACE_0)
|
else if (arg->index == VCOM_INTERFACE_0)
|
||||||
return vcom_port_data_setup (req, req_no, detail);
|
return vcom_port_data_setup (req, req_no, arg);
|
||||||
#endif
|
#endif
|
||||||
#ifdef PINPAD_DND_SUPPORT
|
#ifdef PINPAD_DND_SUPPORT
|
||||||
else if (index == MSC_INTERFACE)
|
else if (arg->index == MSC_INTERFACE)
|
||||||
{
|
{
|
||||||
if (USB_SETUP_GET (req))
|
if (USB_SETUP_GET (req))
|
||||||
{
|
{
|
||||||
if (req_no == MSC_GET_MAX_LUN_COMMAND)
|
if (req_no == MSC_GET_MAX_LUN_COMMAND)
|
||||||
return usb_lld_reply_request (lun_table, sizeof (lun_table),
|
return usb_lld_reply_request (lun_table, sizeof (lun_table),
|
||||||
detail);
|
arg);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (req_no == MSC_MASS_STORAGE_RESET_COMMAND)
|
if (req_no == MSC_MASS_STORAGE_RESET_COMMAND)
|
||||||
@@ -391,7 +393,7 @@ usb_cb_setup (uint8_t req, uint8_t req_no, struct control_info *detail)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
usb_cb_ctrl_write_finish (uint8_t req, uint8_t req_no, uint16_t value)
|
usb_cb_ctrl_write_finish (uint8_t req, uint8_t req_no, struct req_args *arg)
|
||||||
{
|
{
|
||||||
uint8_t type_rcp = req & (REQUEST_TYPE|RECIPIENT);
|
uint8_t type_rcp = req & (REQUEST_TYPE|RECIPIENT);
|
||||||
|
|
||||||
@@ -402,7 +404,7 @@ usb_cb_ctrl_write_finish (uint8_t req, uint8_t req_no, uint16_t value)
|
|||||||
if (*icc_state_p != ICC_STATE_EXITED)
|
if (*icc_state_p != ICC_STATE_EXITED)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
(void)value; (void)index;
|
(void)arg;
|
||||||
usb_lld_prepare_shutdown (); /* No further USB communication */
|
usb_lld_prepare_shutdown (); /* No further USB communication */
|
||||||
led_blink (LED_GNUK_EXEC); /* Notify the main. */
|
led_blink (LED_GNUK_EXEC); /* Notify the main. */
|
||||||
}
|
}
|
||||||
@@ -410,7 +412,7 @@ usb_cb_ctrl_write_finish (uint8_t req, uint8_t req_no, uint16_t value)
|
|||||||
#ifdef HID_CARD_CHANGE_SUPPORT
|
#ifdef HID_CARD_CHANGE_SUPPORT
|
||||||
else if (type_rcp == (CLASS_REQUEST | INTERFACE_RECIPIENT))
|
else if (type_rcp == (CLASS_REQUEST | INTERFACE_RECIPIENT))
|
||||||
{
|
{
|
||||||
if (index == HID_INTERFACE && req_no == USB_HID_REQ_SET_REPORT)
|
if (arg->index == HID_INTERFACE && req_no == USB_HID_REQ_SET_REPORT)
|
||||||
{
|
{
|
||||||
if ((hid_report ^ hid_report_saved) & HID_LED_STATUS_CARDCHANGE)
|
if ((hid_report ^ hid_report_saved) & HID_LED_STATUS_CARDCHANGE)
|
||||||
ccid_card_change_signal (CARD_CHANGE_TOGGLE);
|
ccid_card_change_signal (CARD_CHANGE_TOGGLE);
|
||||||
@@ -464,11 +466,11 @@ int usb_cb_handle_event (uint8_t event_type, uint16_t value)
|
|||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
int usb_cb_interface (uint8_t cmd, struct control_info *detail)
|
int usb_cb_interface (uint8_t cmd, struct req_args *arg)
|
||||||
{
|
{
|
||||||
const uint8_t zero = 0;
|
const uint8_t zero = 0;
|
||||||
uint16_t interface = detail->index;
|
uint16_t interface = arg->index;
|
||||||
uint16_t alt = detail->value;
|
uint16_t alt = arg->value;
|
||||||
|
|
||||||
if (interface >= NUM_INTERFACES)
|
if (interface >= NUM_INTERFACES)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
@@ -485,7 +487,7 @@ int usb_cb_interface (uint8_t cmd, struct control_info *detail)
|
|||||||
}
|
}
|
||||||
|
|
||||||
case USB_GET_INTERFACE:
|
case USB_GET_INTERFACE:
|
||||||
return usb_lld_reply_request (&zero, 1, detail);
|
return usb_lld_reply_request (&zero, 1, arg);
|
||||||
|
|
||||||
case USB_QUERY_INTERFACE:
|
case USB_QUERY_INTERFACE:
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ static const uint8_t hid_report_desc[] = {
|
|||||||
/* USB Standard Device Descriptor */
|
/* USB Standard Device Descriptor */
|
||||||
static const uint8_t device_desc[] = {
|
static const uint8_t device_desc[] = {
|
||||||
18, /* bLength */
|
18, /* bLength */
|
||||||
USB_DEVICE_DESCRIPTOR_TYPE, /* bDescriptorType */
|
DEVICE_DESCRIPTOR, /* bDescriptorType */
|
||||||
0x10, 0x01, /* bcdUSB = 1.1 */
|
0x10, 0x01, /* bcdUSB = 1.1 */
|
||||||
0x00, /* bDeviceClass: 0 means deferred to interface */
|
0x00, /* bDeviceClass: 0 means deferred to interface */
|
||||||
0x00, /* bDeviceSubClass */
|
0x00, /* bDeviceSubClass */
|
||||||
@@ -101,7 +101,7 @@ static const uint8_t device_desc[] = {
|
|||||||
/* Configuation Descriptor */
|
/* Configuation Descriptor */
|
||||||
static const uint8_t config_desc[] = {
|
static const uint8_t config_desc[] = {
|
||||||
9, /* bLength: Configuation Descriptor size */
|
9, /* bLength: Configuation Descriptor size */
|
||||||
USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
|
CONFIG_DESCRIPTOR, /* bDescriptorType: Configuration */
|
||||||
W_TOTAL_LENGTH, 0x00, /* wTotalLength:no of returned bytes */
|
W_TOTAL_LENGTH, 0x00, /* wTotalLength:no of returned bytes */
|
||||||
NUM_INTERFACES, /* bNumInterfaces: */
|
NUM_INTERFACES, /* bNumInterfaces: */
|
||||||
0x01, /* bConfigurationValue: Configuration value */
|
0x01, /* bConfigurationValue: Configuration value */
|
||||||
@@ -111,7 +111,7 @@ static const uint8_t config_desc[] = {
|
|||||||
|
|
||||||
/* Interface Descriptor */
|
/* Interface Descriptor */
|
||||||
9, /* bLength: Interface Descriptor size */
|
9, /* bLength: Interface Descriptor size */
|
||||||
USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: Interface */
|
INTERFACE_DESCRIPTOR, /* bDescriptorType: Interface */
|
||||||
ICC_INTERFACE, /* bInterfaceNumber: Index of this interface */
|
ICC_INTERFACE, /* bInterfaceNumber: Index of this interface */
|
||||||
0, /* Alternate setting for this interface */
|
0, /* Alternate setting for this interface */
|
||||||
3, /* bNumEndpoints: Bulk-IN, Bulk-OUT, Intr-IN */
|
3, /* bNumEndpoints: Bulk-IN, Bulk-OUT, Intr-IN */
|
||||||
@@ -167,21 +167,21 @@ static const uint8_t config_desc[] = {
|
|||||||
1, /* bMaxCCIDBusySlots: 1 */
|
1, /* bMaxCCIDBusySlots: 1 */
|
||||||
/*Endpoint IN1 Descriptor*/
|
/*Endpoint IN1 Descriptor*/
|
||||||
7, /* bLength: Endpoint Descriptor size */
|
7, /* bLength: Endpoint Descriptor size */
|
||||||
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
|
ENDPOINT_DESCRIPTOR, /* bDescriptorType: Endpoint */
|
||||||
0x81, /* bEndpointAddress: (IN1) */
|
0x81, /* bEndpointAddress: (IN1) */
|
||||||
0x02, /* bmAttributes: Bulk */
|
0x02, /* bmAttributes: Bulk */
|
||||||
USB_ICC_DATA_SIZE, 0x00, /* wMaxPacketSize: */
|
USB_ICC_DATA_SIZE, 0x00, /* wMaxPacketSize: */
|
||||||
0x00, /* bInterval */
|
0x00, /* bInterval */
|
||||||
/*Endpoint OUT1 Descriptor*/
|
/*Endpoint OUT1 Descriptor*/
|
||||||
7, /* bLength: Endpoint Descriptor size */
|
7, /* bLength: Endpoint Descriptor size */
|
||||||
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
|
ENDPOINT_DESCRIPTOR, /* bDescriptorType: Endpoint */
|
||||||
0x01, /* bEndpointAddress: (OUT1) */
|
0x01, /* bEndpointAddress: (OUT1) */
|
||||||
0x02, /* bmAttributes: Bulk */
|
0x02, /* bmAttributes: Bulk */
|
||||||
USB_ICC_DATA_SIZE, 0x00, /* wMaxPacketSize: */
|
USB_ICC_DATA_SIZE, 0x00, /* wMaxPacketSize: */
|
||||||
0x00, /* bInterval */
|
0x00, /* bInterval */
|
||||||
/*Endpoint IN2 Descriptor*/
|
/*Endpoint IN2 Descriptor*/
|
||||||
7, /* bLength: Endpoint Descriptor size */
|
7, /* bLength: Endpoint Descriptor size */
|
||||||
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
|
ENDPOINT_DESCRIPTOR, /* bDescriptorType: Endpoint */
|
||||||
0x82, /* bEndpointAddress: (IN2) */
|
0x82, /* bEndpointAddress: (IN2) */
|
||||||
0x03, /* bmAttributes: Interrupt */
|
0x03, /* bmAttributes: Interrupt */
|
||||||
0x04, 0x00, /* wMaxPacketSize: 4 */
|
0x04, 0x00, /* wMaxPacketSize: 4 */
|
||||||
@@ -190,7 +190,7 @@ static const uint8_t config_desc[] = {
|
|||||||
#ifdef HID_CARD_CHANGE_SUPPORT
|
#ifdef HID_CARD_CHANGE_SUPPORT
|
||||||
/* Interface Descriptor */
|
/* Interface Descriptor */
|
||||||
9, /* bLength: Interface Descriptor size */
|
9, /* bLength: Interface Descriptor size */
|
||||||
USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: Interface */
|
INTERFACE_DESCRIPTOR, /* bDescriptorType: Interface */
|
||||||
HID_INTERFACE, /* bInterfaceNumber: Number of Interface */
|
HID_INTERFACE, /* bInterfaceNumber: Number of Interface */
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
0x00, /* bAlternateSetting: Alternate setting */
|
||||||
0x01, /* bNumEndpoints: One endpoint used */
|
0x01, /* bNumEndpoints: One endpoint used */
|
||||||
@@ -209,7 +209,7 @@ static const uint8_t config_desc[] = {
|
|||||||
|
|
||||||
/*Endpoint IN7 Descriptor*/
|
/*Endpoint IN7 Descriptor*/
|
||||||
7, /* bLength: Endpoint Descriptor size */
|
7, /* bLength: Endpoint Descriptor size */
|
||||||
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
|
ENDPOINT_DESCRIPTOR, /* bDescriptorType: Endpoint */
|
||||||
0x87, /* bEndpointAddress: (IN7) */
|
0x87, /* bEndpointAddress: (IN7) */
|
||||||
0x03, /* bmAttributes: Interrupt */
|
0x03, /* bmAttributes: Interrupt */
|
||||||
0x02, 0x00, /* wMaxPacketSize: 2 */
|
0x02, 0x00, /* wMaxPacketSize: 2 */
|
||||||
@@ -219,7 +219,7 @@ static const uint8_t config_desc[] = {
|
|||||||
#ifdef ENABLE_VIRTUAL_COM_PORT
|
#ifdef ENABLE_VIRTUAL_COM_PORT
|
||||||
/* Interface Descriptor */
|
/* Interface Descriptor */
|
||||||
9, /* bLength: Interface Descriptor size */
|
9, /* bLength: Interface Descriptor size */
|
||||||
USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: Interface */
|
INTERFACE_DESCRIPTOR, /* bDescriptorType: Interface */
|
||||||
VCOM_INTERFACE_0, /* bInterfaceNumber: Index of Interface */
|
VCOM_INTERFACE_0, /* bInterfaceNumber: Index of Interface */
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
0x00, /* bAlternateSetting: Alternate setting */
|
||||||
0x01, /* bNumEndpoints: One endpoints used */
|
0x01, /* bNumEndpoints: One endpoints used */
|
||||||
@@ -251,7 +251,7 @@ static const uint8_t config_desc[] = {
|
|||||||
VCOM_INTERFACE_1, /* bSlaveInterface0: Data Class Interface */
|
VCOM_INTERFACE_1, /* bSlaveInterface0: Data Class Interface */
|
||||||
/*Endpoint 4 Descriptor*/
|
/*Endpoint 4 Descriptor*/
|
||||||
7, /* bLength: Endpoint Descriptor size */
|
7, /* bLength: Endpoint Descriptor size */
|
||||||
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
|
ENDPOINT_DESCRIPTOR, /* bDescriptorType: Endpoint */
|
||||||
0x84, /* bEndpointAddress: (IN4) */
|
0x84, /* bEndpointAddress: (IN4) */
|
||||||
0x03, /* bmAttributes: Interrupt */
|
0x03, /* bmAttributes: Interrupt */
|
||||||
VIRTUAL_COM_PORT_INT_SIZE, 0x00, /* wMaxPacketSize: */
|
VIRTUAL_COM_PORT_INT_SIZE, 0x00, /* wMaxPacketSize: */
|
||||||
@@ -259,7 +259,7 @@ static const uint8_t config_desc[] = {
|
|||||||
|
|
||||||
/*Data class interface descriptor*/
|
/*Data class interface descriptor*/
|
||||||
9, /* bLength: Endpoint Descriptor size */
|
9, /* bLength: Endpoint Descriptor size */
|
||||||
USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: */
|
INTERFACE_DESCRIPTOR, /* bDescriptorType: */
|
||||||
VCOM_INTERFACE_1, /* bInterfaceNumber: Index of Interface */
|
VCOM_INTERFACE_1, /* bInterfaceNumber: Index of Interface */
|
||||||
0x00, /* bAlternateSetting: Alternate setting */
|
0x00, /* bAlternateSetting: Alternate setting */
|
||||||
0x02, /* bNumEndpoints: Two endpoints used */
|
0x02, /* bNumEndpoints: Two endpoints used */
|
||||||
@@ -269,14 +269,14 @@ static const uint8_t config_desc[] = {
|
|||||||
0x00, /* iInterface: */
|
0x00, /* iInterface: */
|
||||||
/*Endpoint 5 Descriptor*/
|
/*Endpoint 5 Descriptor*/
|
||||||
7, /* bLength: Endpoint Descriptor size */
|
7, /* bLength: Endpoint Descriptor size */
|
||||||
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
|
ENDPOINT_DESCRIPTOR, /* bDescriptorType: Endpoint */
|
||||||
0x05, /* bEndpointAddress: (OUT5) */
|
0x05, /* bEndpointAddress: (OUT5) */
|
||||||
0x02, /* bmAttributes: Bulk */
|
0x02, /* bmAttributes: Bulk */
|
||||||
VIRTUAL_COM_PORT_DATA_SIZE, 0x00, /* wMaxPacketSize: */
|
VIRTUAL_COM_PORT_DATA_SIZE, 0x00, /* wMaxPacketSize: */
|
||||||
0x00, /* bInterval: ignore for Bulk transfer */
|
0x00, /* bInterval: ignore for Bulk transfer */
|
||||||
/*Endpoint 3 Descriptor*/
|
/*Endpoint 3 Descriptor*/
|
||||||
7, /* bLength: Endpoint Descriptor size */
|
7, /* bLength: Endpoint Descriptor size */
|
||||||
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
|
ENDPOINT_DESCRIPTOR, /* bDescriptorType: Endpoint */
|
||||||
0x83, /* bEndpointAddress: (IN3) */
|
0x83, /* bEndpointAddress: (IN3) */
|
||||||
0x02, /* bmAttributes: Bulk */
|
0x02, /* bmAttributes: Bulk */
|
||||||
VIRTUAL_COM_PORT_DATA_SIZE, 0x00, /* wMaxPacketSize: */
|
VIRTUAL_COM_PORT_DATA_SIZE, 0x00, /* wMaxPacketSize: */
|
||||||
@@ -285,7 +285,7 @@ static const uint8_t config_desc[] = {
|
|||||||
#ifdef PINPAD_DND_SUPPORT
|
#ifdef PINPAD_DND_SUPPORT
|
||||||
/* Interface Descriptor.*/
|
/* Interface Descriptor.*/
|
||||||
9, /* bLength: Interface Descriptor size */
|
9, /* bLength: Interface Descriptor size */
|
||||||
USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: Interface */
|
INTERFACE_DESCRIPTOR, /* bDescriptorType: Interface */
|
||||||
MSC_INTERFACE, /* bInterfaceNumber. */
|
MSC_INTERFACE, /* bInterfaceNumber. */
|
||||||
0x00, /* bAlternateSetting. */
|
0x00, /* bAlternateSetting. */
|
||||||
0x02, /* bNumEndpoints. */
|
0x02, /* bNumEndpoints. */
|
||||||
@@ -298,14 +298,14 @@ static const uint8_t config_desc[] = {
|
|||||||
0x00, /* iInterface. */
|
0x00, /* iInterface. */
|
||||||
/* Endpoint Descriptor.*/
|
/* Endpoint Descriptor.*/
|
||||||
7, /* bLength: Endpoint Descriptor size */
|
7, /* bLength: Endpoint Descriptor size */
|
||||||
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
|
ENDPOINT_DESCRIPTOR, /* bDescriptorType: Endpoint */
|
||||||
0x86, /* bEndpointAddress: (IN6) */
|
0x86, /* bEndpointAddress: (IN6) */
|
||||||
0x02, /* bmAttributes (Bulk). */
|
0x02, /* bmAttributes (Bulk). */
|
||||||
0x40, 0x00, /* wMaxPacketSize. */
|
0x40, 0x00, /* wMaxPacketSize. */
|
||||||
0x00, /* bInterval (ignored for bulk). */
|
0x00, /* bInterval (ignored for bulk). */
|
||||||
/* Endpoint Descriptor.*/
|
/* Endpoint Descriptor.*/
|
||||||
7, /* bLength: Endpoint Descriptor size */
|
7, /* bLength: Endpoint Descriptor size */
|
||||||
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
|
ENDPOINT_DESCRIPTOR, /* bDescriptorType: Endpoint */
|
||||||
0x06, /* bEndpointAddress: (OUT6) */
|
0x06, /* bEndpointAddress: (OUT6) */
|
||||||
0x02, /* bmAttributes (Bulk). */
|
0x02, /* bmAttributes (Bulk). */
|
||||||
0x40, 0x00, /* wMaxPacketSize. */
|
0x40, 0x00, /* wMaxPacketSize. */
|
||||||
@@ -317,7 +317,7 @@ static const uint8_t config_desc[] = {
|
|||||||
/* USB String Descriptors */
|
/* USB String Descriptors */
|
||||||
static const uint8_t gnuk_string_lang_id[] = {
|
static const uint8_t gnuk_string_lang_id[] = {
|
||||||
4, /* bLength */
|
4, /* bLength */
|
||||||
USB_STRING_DESCRIPTOR_TYPE,
|
STRING_DESCRIPTOR,
|
||||||
0x09, 0x04 /* LangID = 0x0409: US-English */
|
0x09, 0x04 /* LangID = 0x0409: US-English */
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -346,20 +346,20 @@ static const struct desc string_descriptors[] = {
|
|||||||
|
|
||||||
int
|
int
|
||||||
usb_cb_get_descriptor (uint8_t rcp, uint8_t desc_type, uint8_t desc_index,
|
usb_cb_get_descriptor (uint8_t rcp, uint8_t desc_type, uint8_t desc_index,
|
||||||
struct control_info *detail)
|
struct req_args *arg)
|
||||||
{
|
{
|
||||||
if (rcp == DEVICE_RECIPIENT)
|
if (rcp == DEVICE_RECIPIENT)
|
||||||
{
|
{
|
||||||
if (desc_type == DEVICE_DESCRIPTOR)
|
if (desc_type == DEVICE_DESCRIPTOR)
|
||||||
return usb_lld_reply_request (device_desc, sizeof (device_desc), detail);
|
return usb_lld_reply_request (device_desc, sizeof (device_desc), arg);
|
||||||
else if (desc_type == CONFIG_DESCRIPTOR)
|
else if (desc_type == CONFIG_DESCRIPTOR)
|
||||||
return usb_lld_reply_request (config_desc, sizeof (config_desc), detail);
|
return usb_lld_reply_request (config_desc, sizeof (config_desc), arg);
|
||||||
else if (desc_type == STRING_DESCRIPTOR)
|
else if (desc_type == STRING_DESCRIPTOR)
|
||||||
{
|
{
|
||||||
if (desc_index < NUM_STRING_DESC)
|
if (desc_index < NUM_STRING_DESC)
|
||||||
return usb_lld_reply_request (string_descriptors[desc_index].desc,
|
return usb_lld_reply_request (string_descriptors[desc_index].desc,
|
||||||
string_descriptors[desc_index].size,
|
string_descriptors[desc_index].size,
|
||||||
detail);
|
arg);
|
||||||
else if (desc_index == NUM_STRING_DESC)
|
else if (desc_index == NUM_STRING_DESC)
|
||||||
{
|
{
|
||||||
uint8_t usbbuf[64];
|
uint8_t usbbuf[64];
|
||||||
@@ -375,22 +375,22 @@ usb_cb_get_descriptor (uint8_t rcp, uint8_t desc_type, uint8_t desc_index,
|
|||||||
usbbuf[i*2+3] = 0;
|
usbbuf[i*2+3] = 0;
|
||||||
}
|
}
|
||||||
usbbuf[0] = len = i*2 + 2;
|
usbbuf[0] = len = i*2 + 2;
|
||||||
usbbuf[1] = USB_STRING_DESCRIPTOR_TYPE;
|
usbbuf[1] = STRING_DESCRIPTOR;
|
||||||
return usb_lld_reply_request (usbbuf, len, detail);
|
return usb_lld_reply_request (usbbuf, len, arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef HID_CARD_CHANGE_SUPPORT
|
#ifdef HID_CARD_CHANGE_SUPPORT
|
||||||
else if (rcp == INTERFACE_RECIPIENT)
|
else if (rcp == INTERFACE_RECIPIENT)
|
||||||
{
|
{
|
||||||
if (detail->index == 1)
|
if (arg->index == HID_INTERFACE)
|
||||||
{
|
{
|
||||||
if (desc_type == USB_DT_HID)
|
if (desc_type == USB_DT_HID)
|
||||||
return usb_lld_reply_request (config_desc+ICC_TOTAL_LENGTH+9, 9,
|
return usb_lld_reply_request (config_desc+ICC_TOTAL_LENGTH+9, 9,
|
||||||
detail);
|
arg);
|
||||||
else if (desc_type == USB_DT_REPORT)
|
else if (desc_type == USB_DT_REPORT)
|
||||||
return usb_lld_reply_request (hid_report_desc, HID_REPORT_DESC_SIZE,
|
return usb_lld_reply_request (hid_report_desc, HID_REPORT_DESC_SIZE,
|
||||||
detail);
|
arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,9 +1,3 @@
|
|||||||
#define USB_DEVICE_DESCRIPTOR_TYPE 0x01
|
|
||||||
#define USB_CONFIGURATION_DESCRIPTOR_TYPE 0x02
|
|
||||||
#define USB_STRING_DESCRIPTOR_TYPE 0x03
|
|
||||||
#define USB_INTERFACE_DESCRIPTOR_TYPE 0x04
|
|
||||||
#define USB_ENDPOINT_DESCRIPTOR_TYPE 0x05
|
|
||||||
|
|
||||||
#define STANDARD_ENDPOINT_DESC_SIZE 0x09
|
#define STANDARD_ENDPOINT_DESC_SIZE 0x09
|
||||||
|
|
||||||
/* endpoints enumeration */
|
/* endpoints enumeration */
|
||||||
@@ -24,7 +18,7 @@
|
|||||||
|
|
||||||
enum RECIPIENT_TYPE
|
enum RECIPIENT_TYPE
|
||||||
{
|
{
|
||||||
DEVICE_RECIPIENT, /* Recipient device */
|
DEVICE_RECIPIENT = 0, /* Recipient device */
|
||||||
INTERFACE_RECIPIENT, /* Recipient interface */
|
INTERFACE_RECIPIENT, /* Recipient interface */
|
||||||
ENDPOINT_RECIPIENT, /* Recipient endpoint */
|
ENDPOINT_RECIPIENT, /* Recipient endpoint */
|
||||||
OTHER_RECIPIENT
|
OTHER_RECIPIENT
|
||||||
@@ -55,19 +49,20 @@ enum
|
|||||||
USB_SUCCESS = 1,
|
USB_SUCCESS = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct control_info {
|
struct req_args {
|
||||||
uint16_t value;
|
uint16_t value;
|
||||||
uint16_t index;
|
uint16_t index;
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
};
|
};
|
||||||
|
|
||||||
void usb_cb_device_reset (void);
|
void usb_cb_device_reset (void);
|
||||||
int usb_cb_setup (uint8_t req, uint8_t req_no, struct control_info *detail);
|
int usb_cb_setup (uint8_t req, uint8_t req_no, struct req_args *arg);
|
||||||
int usb_cb_interface (uint8_t cmd, struct control_info *detail);
|
int usb_cb_interface (uint8_t cmd, struct req_args *arg);
|
||||||
int usb_cb_get_descriptor (uint8_t rcp, uint8_t desc_type, uint8_t desc_index,
|
int usb_cb_get_descriptor (uint8_t rcp, uint8_t desc_type, uint8_t desc_index,
|
||||||
struct control_info *detail);
|
struct req_args *arg);
|
||||||
int usb_cb_handle_event (uint8_t event_type, uint16_t value);
|
int usb_cb_handle_event (uint8_t event_type, uint16_t value);
|
||||||
void usb_cb_ctrl_write_finish (uint8_t req, uint8_t req_no, uint16_t value);
|
void usb_cb_ctrl_write_finish (uint8_t req, uint8_t req_no,
|
||||||
|
struct req_args *arg);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
USB_EVENT_ADDRESS,
|
USB_EVENT_ADDRESS,
|
||||||
@@ -103,7 +98,7 @@ void usb_lld_txcpy (const void *src, int ep_num, int offset, size_t len);
|
|||||||
void usb_lld_tx_enable (int ep_num, size_t len);
|
void usb_lld_tx_enable (int ep_num, size_t len);
|
||||||
void usb_lld_write (uint8_t ep_num, const void *buf, size_t len);
|
void usb_lld_write (uint8_t ep_num, const void *buf, size_t len);
|
||||||
int usb_lld_reply_request (const void *buf, size_t buflen,
|
int usb_lld_reply_request (const void *buf, size_t buflen,
|
||||||
struct control_info *ctrl);
|
struct req_args *arg);
|
||||||
void usb_lld_rx_enable (int ep_num);
|
void usb_lld_rx_enable (int ep_num);
|
||||||
int usb_lld_rx_data_len (int ep_num);
|
int usb_lld_rx_data_len (int ep_num);
|
||||||
void usb_lld_rxcpy (uint8_t *dst, int ep_num, int offset, size_t len);
|
void usb_lld_rxcpy (uint8_t *dst, int ep_num, int offset, size_t len);
|
||||||
@@ -114,7 +109,7 @@ void usb_lld_setup_endpoint (int ep_num, int ep_type, int ep_kind,
|
|||||||
void usb_lld_set_configuration (uint8_t config);
|
void usb_lld_set_configuration (uint8_t config);
|
||||||
uint8_t usb_lld_current_configuration (void);
|
uint8_t usb_lld_current_configuration (void);
|
||||||
void usb_lld_set_feature (uint8_t feature);
|
void usb_lld_set_feature (uint8_t feature);
|
||||||
void usb_lld_set_data_to_recv (const void *p, size_t len);
|
void usb_lld_set_data_to_recv (void *p, size_t len);
|
||||||
|
|
||||||
void usb_lld_prepare_shutdown (void);
|
void usb_lld_prepare_shutdown (void);
|
||||||
void usb_lld_shutdown (void);
|
void usb_lld_shutdown (void);
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ struct DEVICE_INFO
|
|||||||
uint8_t bRequest;
|
uint8_t bRequest;
|
||||||
/**/
|
/**/
|
||||||
uint16_t value;
|
uint16_t value;
|
||||||
|
uint16_t index;
|
||||||
|
uint16_t len;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct DEVICE_INFO device_info;
|
static struct DEVICE_INFO device_info;
|
||||||
@@ -462,26 +464,26 @@ static void handle_datastage_in (void)
|
|||||||
st103_ep_set_tx_status (ENDP0, EP_TX_VALID);
|
st103_ep_set_tx_status (ENDP0, EP_TX_VALID);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef int (*HANDLER) (uint8_t req, struct control_info *detail);
|
typedef int (*HANDLER) (uint8_t req, struct req_args *arg);
|
||||||
|
|
||||||
static int std_none (uint8_t req, struct control_info *detail)
|
static int std_none (uint8_t req, struct req_args *arg)
|
||||||
{
|
{
|
||||||
(void)req; (void)detail;
|
(void)req; (void)arg;
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int std_get_status (uint8_t req, struct control_info *detail)
|
static int std_get_status (uint8_t req, struct req_args *arg)
|
||||||
{
|
{
|
||||||
uint8_t rcp = req & RECIPIENT;
|
uint8_t rcp = req & RECIPIENT;
|
||||||
uint16_t status_info = 0;
|
uint16_t status_info = 0;
|
||||||
|
|
||||||
if (detail->value != 0 || detail->len != 2 || (detail->index >> 8) != 0
|
if (arg->value != 0 || arg->len != 2 || (arg->index >> 8) != 0
|
||||||
|| (req & REQUEST_DIR) == 0)
|
|| (req & REQUEST_DIR) == 0)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if (rcp == DEVICE_RECIPIENT)
|
if (rcp == DEVICE_RECIPIENT)
|
||||||
{
|
{
|
||||||
if (detail->index == 0)
|
if (arg->index == 0)
|
||||||
{
|
{
|
||||||
/* Get Device Status */
|
/* Get Device Status */
|
||||||
uint8_t feature = dev_p->current_feature;
|
uint8_t feature = dev_p->current_feature;
|
||||||
@@ -498,7 +500,7 @@ static int std_get_status (uint8_t req, struct control_info *detail)
|
|||||||
else /* Self-powered */
|
else /* Self-powered */
|
||||||
status_info &= ~1;
|
status_info &= ~1;
|
||||||
|
|
||||||
return usb_lld_reply_request (&status_info, 2, detail);
|
return usb_lld_reply_request (&status_info, 2, arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (rcp == INTERFACE_RECIPIENT)
|
else if (rcp == INTERFACE_RECIPIENT)
|
||||||
@@ -508,21 +510,21 @@ static int std_get_status (uint8_t req, struct control_info *detail)
|
|||||||
if (dev_p->current_configuration == 0)
|
if (dev_p->current_configuration == 0)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
r = usb_cb_interface (USB_QUERY_INTERFACE, detail);
|
r = usb_cb_interface (USB_QUERY_INTERFACE, arg);
|
||||||
if (r != USB_SUCCESS)
|
if (r != USB_SUCCESS)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
return usb_lld_reply_request (&status_info, 2, detail);
|
return usb_lld_reply_request (&status_info, 2, arg);
|
||||||
}
|
}
|
||||||
else if (rcp == ENDPOINT_RECIPIENT)
|
else if (rcp == ENDPOINT_RECIPIENT)
|
||||||
{
|
{
|
||||||
uint8_t endpoint = (detail->index & 0x0f);
|
uint8_t endpoint = (arg->index & 0x0f);
|
||||||
uint16_t status;
|
uint16_t status;
|
||||||
|
|
||||||
if ((detail->index & 0x70) || endpoint == ENDP0)
|
if ((arg->index & 0x70) || endpoint == ENDP0)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if ((detail->index & 0x80))
|
if ((arg->index & 0x80))
|
||||||
{
|
{
|
||||||
status = st103_ep_get_tx_status (endpoint);
|
status = st103_ep_get_tx_status (endpoint);
|
||||||
if (status == 0) /* Disabled */
|
if (status == 0) /* Disabled */
|
||||||
@@ -539,13 +541,13 @@ static int std_get_status (uint8_t req, struct control_info *detail)
|
|||||||
status_info |= 1; /* OUT Endpoint stalled */
|
status_info |= 1; /* OUT Endpoint stalled */
|
||||||
}
|
}
|
||||||
|
|
||||||
return usb_lld_reply_request (&status_info, 2, detail);
|
return usb_lld_reply_request (&status_info, 2, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int std_clear_feature (uint8_t req, struct control_info *detail)
|
static int std_clear_feature (uint8_t req, struct req_args *arg)
|
||||||
{
|
{
|
||||||
uint8_t rcp = req & RECIPIENT;
|
uint8_t rcp = req & RECIPIENT;
|
||||||
|
|
||||||
@@ -554,10 +556,10 @@ static int std_clear_feature (uint8_t req, struct control_info *detail)
|
|||||||
|
|
||||||
if (rcp == DEVICE_RECIPIENT)
|
if (rcp == DEVICE_RECIPIENT)
|
||||||
{
|
{
|
||||||
if (detail->len != 0 || detail->index != 0)
|
if (arg->len != 0 || arg->index != 0)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if (detail->value == DEVICE_REMOTE_WAKEUP)
|
if (arg->value == DEVICE_REMOTE_WAKEUP)
|
||||||
{
|
{
|
||||||
dev_p->current_feature &= ~(1 << 5);
|
dev_p->current_feature &= ~(1 << 5);
|
||||||
return USB_SUCCESS;
|
return USB_SUCCESS;
|
||||||
@@ -565,17 +567,17 @@ static int std_clear_feature (uint8_t req, struct control_info *detail)
|
|||||||
}
|
}
|
||||||
else if (rcp == ENDPOINT_RECIPIENT)
|
else if (rcp == ENDPOINT_RECIPIENT)
|
||||||
{
|
{
|
||||||
uint8_t endpoint = (detail->index & 0x0f);
|
uint8_t endpoint = (arg->index & 0x0f);
|
||||||
uint16_t status;
|
uint16_t status;
|
||||||
|
|
||||||
if (dev_p->current_configuration == 0)
|
if (dev_p->current_configuration == 0)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if (detail->len != 0 || (detail->index >> 8) != 0
|
if (arg->len != 0 || (arg->index >> 8) != 0
|
||||||
|| detail->value != ENDPOINT_STALL || endpoint == ENDP0)
|
|| arg->value != ENDPOINT_STALL || endpoint == ENDP0)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if ((detail->index & 0x80))
|
if ((arg->index & 0x80))
|
||||||
status = st103_ep_get_tx_status (endpoint);
|
status = st103_ep_get_tx_status (endpoint);
|
||||||
else
|
else
|
||||||
status = st103_ep_get_rx_status (endpoint);
|
status = st103_ep_get_rx_status (endpoint);
|
||||||
@@ -583,7 +585,7 @@ static int std_clear_feature (uint8_t req, struct control_info *detail)
|
|||||||
if (status == 0) /* Disabled */
|
if (status == 0) /* Disabled */
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if (detail->index & 0x80) /* IN endpoint */
|
if (arg->index & 0x80) /* IN endpoint */
|
||||||
st103_ep_clear_dtog_tx (endpoint);
|
st103_ep_clear_dtog_tx (endpoint);
|
||||||
else /* OUT endpoint */
|
else /* OUT endpoint */
|
||||||
st103_ep_clear_dtog_rx (endpoint);
|
st103_ep_clear_dtog_rx (endpoint);
|
||||||
@@ -595,7 +597,7 @@ static int std_clear_feature (uint8_t req, struct control_info *detail)
|
|||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int std_set_feature (uint8_t req, struct control_info *detail)
|
static int std_set_feature (uint8_t req, struct req_args *arg)
|
||||||
{
|
{
|
||||||
uint8_t rcp = req & RECIPIENT;
|
uint8_t rcp = req & RECIPIENT;
|
||||||
|
|
||||||
@@ -604,10 +606,10 @@ static int std_set_feature (uint8_t req, struct control_info *detail)
|
|||||||
|
|
||||||
if (rcp == DEVICE_RECIPIENT)
|
if (rcp == DEVICE_RECIPIENT)
|
||||||
{
|
{
|
||||||
if (detail->len != 0 || detail->index != 0)
|
if (arg->len != 0 || arg->index != 0)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if (detail->value == DEVICE_REMOTE_WAKEUP)
|
if (arg->value == DEVICE_REMOTE_WAKEUP)
|
||||||
{
|
{
|
||||||
dev_p->current_feature |= 1 << 5;
|
dev_p->current_feature |= 1 << 5;
|
||||||
// event??
|
// event??
|
||||||
@@ -616,17 +618,17 @@ static int std_set_feature (uint8_t req, struct control_info *detail)
|
|||||||
}
|
}
|
||||||
else if (rcp == ENDPOINT_RECIPIENT)
|
else if (rcp == ENDPOINT_RECIPIENT)
|
||||||
{
|
{
|
||||||
uint8_t endpoint = (detail->index & 0x0f);
|
uint8_t endpoint = (arg->index & 0x0f);
|
||||||
uint32_t status;
|
uint32_t status;
|
||||||
|
|
||||||
if (dev_p->current_configuration == 0)
|
if (dev_p->current_configuration == 0)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if (detail->len != 0 || (detail->index >> 8) != 0
|
if (arg->len != 0 || (arg->index >> 8) != 0
|
||||||
|| detail->value != 0 || endpoint == ENDP0)
|
|| arg->value != 0 || endpoint == ENDP0)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if ((detail->index & 0x80))
|
if ((arg->index & 0x80))
|
||||||
status = st103_ep_get_tx_status (endpoint);
|
status = st103_ep_get_tx_status (endpoint);
|
||||||
else
|
else
|
||||||
status = st103_ep_get_rx_status (endpoint);
|
status = st103_ep_get_rx_status (endpoint);
|
||||||
@@ -634,7 +636,7 @@ static int std_set_feature (uint8_t req, struct control_info *detail)
|
|||||||
if (status == 0) /* Disabled */
|
if (status == 0) /* Disabled */
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if (detail->index & 0x80)
|
if (arg->index & 0x80)
|
||||||
/* IN endpoint */
|
/* IN endpoint */
|
||||||
st103_ep_set_tx_status (endpoint, EP_TX_STALL);
|
st103_ep_set_tx_status (endpoint, EP_TX_STALL);
|
||||||
else
|
else
|
||||||
@@ -648,59 +650,58 @@ static int std_set_feature (uint8_t req, struct control_info *detail)
|
|||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int std_set_address (uint8_t req, struct control_info *detail)
|
static int std_set_address (uint8_t req, struct req_args *arg)
|
||||||
{
|
{
|
||||||
uint8_t rcp = req & RECIPIENT;
|
uint8_t rcp = req & RECIPIENT;
|
||||||
|
|
||||||
if ((req & REQUEST_DIR) == 1)
|
if ((req & REQUEST_DIR) == 1)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if (rcp == DEVICE_RECIPIENT && detail->len == 0 && detail->value <= 127
|
if (rcp == DEVICE_RECIPIENT && arg->len == 0 && arg->value <= 127
|
||||||
&& detail->index == 0 && dev_p->current_configuration == 0)
|
&& arg->index == 0 && dev_p->current_configuration == 0)
|
||||||
return USB_SUCCESS;
|
return USB_SUCCESS;
|
||||||
|
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int std_get_descriptor (uint8_t req, struct control_info *detail)
|
static int std_get_descriptor (uint8_t req, struct req_args *arg)
|
||||||
{
|
{
|
||||||
uint8_t rcp = req & RECIPIENT;
|
uint8_t rcp = req & RECIPIENT;
|
||||||
|
|
||||||
if ((req & REQUEST_DIR) == 0)
|
if ((req & REQUEST_DIR) == 0)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
return usb_cb_get_descriptor (rcp, (detail->value >> 8),
|
return usb_cb_get_descriptor (rcp, (arg->value >> 8),
|
||||||
(detail->value & 0xff), detail);
|
(arg->value & 0xff), arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int std_get_configuration (uint8_t req, struct control_info *detail)
|
static int std_get_configuration (uint8_t req, struct req_args *arg)
|
||||||
{
|
{
|
||||||
uint8_t rcp = req & RECIPIENT;
|
uint8_t rcp = req & RECIPIENT;
|
||||||
|
|
||||||
(void)detail;
|
|
||||||
if ((req & REQUEST_DIR) == 0)
|
if ((req & REQUEST_DIR) == 0)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if (rcp == DEVICE_RECIPIENT)
|
if (rcp == DEVICE_RECIPIENT)
|
||||||
return usb_lld_reply_request (&dev_p->current_configuration, 1, detail);
|
return usb_lld_reply_request (&dev_p->current_configuration, 1, arg);
|
||||||
|
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int std_set_configuration (uint8_t req, struct control_info *detail)
|
static int std_set_configuration (uint8_t req, struct req_args *arg)
|
||||||
{
|
{
|
||||||
uint8_t rcp = req & RECIPIENT;
|
uint8_t rcp = req & RECIPIENT;
|
||||||
|
|
||||||
if ((req & REQUEST_DIR) == 1)
|
if ((req & REQUEST_DIR) == 1)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if (rcp == DEVICE_RECIPIENT && detail->index == 0 && detail->len == 0)
|
if (rcp == DEVICE_RECIPIENT && arg->index == 0 && arg->len == 0)
|
||||||
return usb_cb_handle_event (USB_EVENT_CONFIG, detail->value);
|
return usb_cb_handle_event (USB_EVENT_CONFIG, arg->value);
|
||||||
|
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int std_get_interface (uint8_t req, struct control_info *detail)
|
static int std_get_interface (uint8_t req, struct req_args *arg)
|
||||||
{
|
{
|
||||||
uint8_t rcp = req & RECIPIENT;
|
uint8_t rcp = req & RECIPIENT;
|
||||||
|
|
||||||
@@ -709,35 +710,34 @@ static int std_get_interface (uint8_t req, struct control_info *detail)
|
|||||||
|
|
||||||
if (rcp == INTERFACE_RECIPIENT)
|
if (rcp == INTERFACE_RECIPIENT)
|
||||||
{
|
{
|
||||||
if (detail->value != 0 || (detail->index >> 8) != 0 || detail->len != 1)
|
if (arg->value != 0 || (arg->index >> 8) != 0 || arg->len != 1)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
if (dev_p->current_configuration == 0)
|
if (dev_p->current_configuration == 0)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
return usb_cb_interface (USB_GET_INTERFACE, detail);
|
return usb_cb_interface (USB_GET_INTERFACE, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int std_set_interface (uint8_t req, struct control_info *detail)
|
static int std_set_interface (uint8_t req, struct req_args *arg)
|
||||||
{
|
{
|
||||||
uint8_t rcp = req & RECIPIENT;
|
uint8_t rcp = req & RECIPIENT;
|
||||||
|
|
||||||
if ((req & REQUEST_DIR) == 1 || rcp != INTERFACE_RECIPIENT
|
if ((req & REQUEST_DIR) == 1 || rcp != INTERFACE_RECIPIENT
|
||||||
|| detail->len != 0 || (detail->index >> 8) != 0
|
|| arg->len != 0 || (arg->index >> 8) != 0
|
||||||
|| (detail->value >> 8) != 0 || dev_p->current_configuration == 0)
|
|| (arg->value >> 8) != 0 || dev_p->current_configuration == 0)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
return usb_cb_interface (USB_SET_INTERFACE, detail);
|
return usb_cb_interface (USB_SET_INTERFACE, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void handle_setup0 (void)
|
static void handle_setup0 (void)
|
||||||
{
|
{
|
||||||
const uint16_t *pw;
|
const uint16_t *pw;
|
||||||
struct control_info ctrl;
|
|
||||||
uint16_t w;
|
uint16_t w;
|
||||||
uint8_t req_no;
|
uint8_t req_no;
|
||||||
int r = USB_UNSUPPORT;
|
int r = USB_UNSUPPORT;
|
||||||
@@ -749,11 +749,11 @@ static void handle_setup0 (void)
|
|||||||
dev_p->bmRequestType = w & 0xff;
|
dev_p->bmRequestType = w & 0xff;
|
||||||
dev_p->bRequest = req_no = w >> 8;
|
dev_p->bRequest = req_no = w >> 8;
|
||||||
pw++;
|
pw++;
|
||||||
ctrl.value = *pw++;
|
dev_p->value = *pw++;
|
||||||
pw++;
|
pw++;
|
||||||
ctrl.index = *pw++;
|
dev_p->index = *pw++;
|
||||||
pw++;
|
pw++;
|
||||||
ctrl.len = *pw;
|
dev_p->len = *pw;
|
||||||
|
|
||||||
data_p->addr = NULL;
|
data_p->addr = NULL;
|
||||||
data_p->len = 0;
|
data_p->len = 0;
|
||||||
@@ -777,11 +777,13 @@ static void handle_setup0 (void)
|
|||||||
default: handler = std_none; break;
|
default: handler = std_none; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = (*handler) (dev_p->bmRequestType, &ctrl);
|
r = (*handler) (dev_p->bmRequestType,
|
||||||
|
(struct req_args *)&dev_p->value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
r = usb_cb_setup (dev_p->bmRequestType, req_no, &ctrl);
|
r = usb_cb_setup (dev_p->bmRequestType, req_no,
|
||||||
|
(struct req_args *)&dev_p->value);
|
||||||
|
|
||||||
if (r != USB_SUCCESS)
|
if (r != USB_SUCCESS)
|
||||||
dev_p->state = STALLED;
|
dev_p->state = STALLED;
|
||||||
@@ -789,8 +791,7 @@ static void handle_setup0 (void)
|
|||||||
{
|
{
|
||||||
if (USB_SETUP_SET (dev_p->bmRequestType))
|
if (USB_SETUP_SET (dev_p->bmRequestType))
|
||||||
{
|
{
|
||||||
dev_p->value = ctrl.value;
|
if (dev_p->len == 0)
|
||||||
if (ctrl.len == 0)
|
|
||||||
{
|
{
|
||||||
dev_p->state = WAIT_STATUS_IN;
|
dev_p->state = WAIT_STATUS_IN;
|
||||||
st103_set_tx_count (ENDP0, 0);
|
st103_set_tx_count (ENDP0, 0);
|
||||||
@@ -820,7 +821,7 @@ static void handle_in0 (void)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
usb_cb_ctrl_write_finish (dev_p->bmRequestType, dev_p->bRequest,
|
usb_cb_ctrl_write_finish (dev_p->bmRequestType, dev_p->bRequest,
|
||||||
dev_p->value);
|
(struct req_args *)&dev_p->value);
|
||||||
|
|
||||||
dev_p->state = STALLED;
|
dev_p->state = STALLED;
|
||||||
}
|
}
|
||||||
@@ -1042,9 +1043,9 @@ void usb_lld_set_feature (uint8_t feature)
|
|||||||
dev_p->current_feature = feature;
|
dev_p->current_feature = feature;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usb_lld_set_data_to_recv (const void *p, size_t len)
|
void usb_lld_set_data_to_recv (void *p, size_t len)
|
||||||
{
|
{
|
||||||
data_p->addr = (uint8_t *)p;
|
data_p->addr = p;
|
||||||
data_p->len = len;
|
data_p->len = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1129,7 +1130,7 @@ void usb_lld_from_pmabuf (void *dst, uint16_t addr, size_t n)
|
|||||||
* BUFLEN: size of the data.
|
* BUFLEN: size of the data.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
usb_lld_reply_request (const void *buf, size_t buflen, struct control_info *ctl)
|
usb_lld_reply_request (const void *buf, size_t buflen, struct req_args *ctl)
|
||||||
{
|
{
|
||||||
uint32_t len_asked = ctl->len;
|
uint32_t len_asked = ctl->len;
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
|
|||||||
@@ -67,7 +67,6 @@ class gnuk_token(object):
|
|||||||
if interface.interfaceSubClass != CCID_SUBCLASS:
|
if interface.interfaceSubClass != CCID_SUBCLASS:
|
||||||
raise ValueError("Wrong interface sub class")
|
raise ValueError("Wrong interface sub class")
|
||||||
self.__devhandle = device.open()
|
self.__devhandle = device.open()
|
||||||
self.__devhandle.setConfiguration(configuration.value)
|
|
||||||
self.__devhandle.claimInterface(interface)
|
self.__devhandle.claimInterface(interface)
|
||||||
self.__devhandle.setAltInterface(0)
|
self.__devhandle.setAltInterface(0)
|
||||||
|
|
||||||
@@ -473,10 +472,6 @@ class regnual(object):
|
|||||||
if intf.interfaceClass != 0xff:
|
if intf.interfaceClass != 0xff:
|
||||||
raise ValueError("Wrong interface class")
|
raise ValueError("Wrong interface class")
|
||||||
self.__devhandle = dev.open()
|
self.__devhandle = dev.open()
|
||||||
try:
|
|
||||||
self.__devhandle.setConfiguration(conf)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
self.__devhandle.claimInterface(intf)
|
self.__devhandle.claimInterface(intf)
|
||||||
self.__devhandle.setAltInterface(0)
|
self.__devhandle.setAltInterface(0)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user