diff --git a/legacy/Makefile.include b/legacy/Makefile.include index 35f1562de..1d7eadb92 100755 --- a/legacy/Makefile.include +++ b/legacy/Makefile.include @@ -46,6 +46,9 @@ FPUFLAGS ?= -msoft-float DEVICEFLAG ?= -D GD32F470 CFLAGS += $(DEVICEFLAG) +# USB control callback configuration +MAX_USB_CALLBACKS ?= 6 +CFLAGS += -DMAX_USER_CONTROL_CALLBACK=$(MAX_USB_CALLBACKS) ifeq ($(MAC_OS), 1) CONFFLAG ?= -DCONFIDENTIAL='__attribute__((used)) __attribute__((section("__CONFIDENTIAL,__confidential")))' diff --git a/legacy/bootloader/usb_desc.h b/legacy/bootloader/usb_desc.h index e29946c94..869963bc5 100755 --- a/legacy/bootloader/usb_desc.h +++ b/legacy/bootloader/usb_desc.h @@ -13,7 +13,7 @@ static const struct usb_device_descriptor dev_descr = { .bMaxPacketSize0 = 64, .idVendor = 0x1209, .idProduct = 0x53c0, - .bcdDevice = 0x0100, + .bcdDevice = 0x0101, .iManufacturer = 1, .iProduct = 2, .iSerialNumber = 3, @@ -71,7 +71,7 @@ static const struct usb_config_descriptor config = { }; static const char *usb_strings[] = { - "ByteForge", - "ONEKEY", + "OneKey", + "Classic", "000000000000000000000000", }; diff --git a/legacy/firmware/usb.c b/legacy/firmware/usb.c index d10da6935..c627504ee 100644 --- a/legacy/firmware/usb.c +++ b/legacy/firmware/usb.c @@ -76,12 +76,12 @@ #endif #define USB_STRINGS \ - X(MANUFACTURER, "ByteForge") \ - X(PRODUCT, "ONEKEY CLASSIC") \ + X(MANUFACTURER, "OneKey") \ + X(PRODUCT, "Classic") \ X(SERIAL_NUMBER, config_uuid_str) \ - X(INTERFACE_MAIN, "ONEKEY Interface") \ - X(INTERFACE_DEBUG, "ONEKEY Debug Link Interface") \ - X(INTERFACE_U2F, "ONEKEY U2F Interface") + X(INTERFACE_MAIN, "OneKey Interface") \ + X(INTERFACE_DEBUG, "OneKey Debug Link Interface") \ + X(INTERFACE_FIDO, "OneKey FIDO Interface") #define X(name, value) USB_STRING_##name, enum { @@ -109,7 +109,7 @@ static struct usb_device_descriptor dev_descr = { .bMaxPacketSize0 = USB_PACKET_SIZE, .idVendor = 0x1209, .idProduct = 0x4F4B, - .bcdDevice = 0x0100, + .bcdDevice = 0x0101, .iManufacturer = USB_STRING_MANUFACTURER, .iProduct = USB_STRING_PRODUCT, .iSerialNumber = USB_STRING_SERIAL_NUMBER, @@ -184,7 +184,7 @@ static const struct usb_interface_descriptor hid_iface_u2f[] = {{ .bInterfaceClass = USB_CLASS_HID, .bInterfaceSubClass = 0, .bInterfaceProtocol = 0, - .iInterface = USB_STRING_INTERFACE_U2F, + .iInterface = USB_STRING_INTERFACE_FIDO, .endpoint = hid_endpoints_u2f, .extra = &hid_function_u2f, .extralen = sizeof(hid_function_u2f), diff --git a/legacy/script/cibuild b/legacy/script/cibuild index 58073efd7..3d908eb35 100755 --- a/legacy/script/cibuild +++ b/legacy/script/cibuild @@ -12,7 +12,11 @@ vendor/trezor-common/tools/cointool.py render firmware/fido2 if [ "$EMULATOR" = 1 ]; then make -C emulator else - make -C vendor/libopencm3 lib/gd32/f4xx + # Pass MAX_USER_CONTROL_CALLBACK to libopencm3 build + # Read value from Makefile.include to keep it in sync + MAX_USB_CALLBACKS=$(grep "^MAX_USB_CALLBACKS" Makefile.include | cut -d'=' -f2 | tr -d ' ?') + MAX_USB_CALLBACKS=${MAX_USB_CALLBACKS:-6} # Default to 6 if not found + CFLAGS="-DMAX_USER_CONTROL_CALLBACK=$MAX_USB_CALLBACKS" make -C vendor/libopencm3 lib/gd32/f4xx fi make -C vendor/libsol rm layout.o || true diff --git a/legacy/usb_private.h b/legacy/usb_private.h index 00d4086d4..291ea9d82 100755 --- a/legacy/usb_private.h +++ b/legacy/usb_private.h @@ -39,8 +39,14 @@ LGPL License Terms @ref lgpl_license #ifndef __USB_PRIVATE_H #define __USB_PRIVATE_H +/* Allow override via compiler flag -DMAX_USER_CONTROL_CALLBACK=N */ +#ifndef MAX_USER_CONTROL_CALLBACK #define MAX_USER_CONTROL_CALLBACK 4 +#endif + +#ifndef MAX_USER_SET_CONFIG_CALLBACK #define MAX_USER_SET_CONFIG_CALLBACK 4 +#endif /** Internal collection of device information. */ struct _usbd_device { diff --git a/legacy/winusb.c b/legacy/winusb.c index 6c30c178d..08ee5fe36 100755 --- a/legacy/winusb.c +++ b/legacy/winusb.c @@ -138,6 +138,12 @@ static void winusb_set_config(usbd_device *usbd_dev, uint16_t wValue) { usbd_register_control_callback(usbd_dev, USB_REQ_TYPE_VENDOR, USB_REQ_TYPE_TYPE, winusb_control_vendor_request); + + /* Re-register descriptor callback for MS OS String Descriptor (0xEE) + * This is needed because SET_CONFIGURATION clears all user callbacks */ + usbd_register_control_callback(usbd_dev, USB_REQ_TYPE_DEVICE, + USB_REQ_TYPE_RECIPIENT, + winusb_descriptor_request); } void winusb_setup(usbd_device *usbd_dev, uint8_t interface) { diff --git a/vendor/libopencm3 b/vendor/libopencm3 index e8e1e0bdf..5600fccd6 160000 --- a/vendor/libopencm3 +++ b/vendor/libopencm3 @@ -1 +1 @@ -Subproject commit e8e1e0bdf1999289de4e05ce1d88c6ee4c55b446 +Subproject commit 5600fccd6dc80ed7e0eafc08acc455954898bd37