1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-13 19:18:56 +00:00

trezorhal: rename winusb_enabled to usb21_enabled

This commit is contained in:
Pavol Rusnak 2018-02-02 16:02:37 +01:00
parent 4f44c2577b
commit b8b8e38765
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
5 changed files with 42 additions and 37 deletions

View File

@ -41,7 +41,7 @@ static void usb_init_all(void) {
.product = "TREZOR",
.serial_number = "000000000000000000000000",
.interface = "TREZOR Interface",
.winusb_enabled = sectrue,
.usb21_enabled = sectrue,
};
static uint8_t rx_buffer[USB_PACKET_SIZE];

View File

@ -41,7 +41,7 @@ static const char *get_0str(mp_obj_t o, size_t min_len, size_t max_len) {
/// product: str='',
/// serial_number: str='',
/// interface: str='',
/// winusb_enabled: bool=True) -> None:
/// usb21_enabled: bool=True) -> None:
/// '''
/// '''
STATIC mp_obj_t mod_trezorio_USB_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
@ -57,7 +57,7 @@ STATIC mp_obj_t mod_trezorio_USB_make_new(const mp_obj_type_t *type, size_t n_ar
{ MP_QSTR_product, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_empty_bytes} },
{ MP_QSTR_serial_number, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_empty_bytes} },
{ MP_QSTR_interface, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_empty_bytes} },
{ MP_QSTR_winusb_enabled, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} },
{ MP_QSTR_usb21_enabled, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} },
};
mp_arg_val_t vals[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all_kw_array(n_args, n_kw, args, MP_ARRAY_SIZE(allowed_args), allowed_args, vals);
@ -72,7 +72,7 @@ STATIC mp_obj_t mod_trezorio_USB_make_new(const mp_obj_type_t *type, size_t n_ar
const char *product = get_0str(vals[7].u_obj, 0, 32);
const char *serial_number = get_0str(vals[8].u_obj, 0, 32);
const char *interface = get_0str(vals[9].u_obj, 0, 32);
const secbool winusb_enabled = vals[10].u_bool ? sectrue : secfalse;
const secbool usb21_enabled = vals[10].u_bool ? sectrue : secfalse;
CHECK_PARAM_RANGE(device_class, 0, 255)
CHECK_PARAM_RANGE(device_subclass, 0, 255)
@ -108,7 +108,7 @@ STATIC mp_obj_t mod_trezorio_USB_make_new(const mp_obj_type_t *type, size_t n_ar
o->info.product = product;
o->info.serial_number = serial_number;
o->info.interface = interface;
o->info.winusb_enabled = winusb_enabled;
o->info.usb21_enabled = usb21_enabled;
mp_obj_list_init(&o->ifaces, 0);

View File

@ -96,7 +96,7 @@ static void usb_init_all(void)
.product = "TREZOR",
.serial_number = "000000000000",
.interface = "TREZOR Interface",
.winusb_enabled = secfalse,
.usb21_enabled = secfalse,
};
static uint8_t tx_packet[VCP_PACKET_LEN];

View File

@ -48,7 +48,7 @@ static USBD_HandleTypeDef usb_dev_handle;
static const USBD_DescriptorsTypeDef usb_descriptors;
static const USBD_ClassTypeDef usb_class;
static secbool usb_winusb_enabled = secfalse;
static secbool usb21_enabled = secfalse;
static secbool __wur check_desc_str(const char *s) {
if (NULL == s) return secfalse;
@ -58,10 +58,13 @@ static secbool __wur check_desc_str(const char *s) {
void usb_init(const usb_dev_info_t *dev_info) {
// enable/disable USB 2.1 features
usb21_enabled = dev_info->usb21_enabled;
// Device descriptor
usb_dev_desc.bLength = sizeof(usb_device_descriptor_t);
usb_dev_desc.bDescriptorType = USB_DESC_TYPE_DEVICE;
usb_dev_desc.bcdUSB = 0x0210; // USB 2.1
usb_dev_desc.bcdUSB = (sectrue == usb21_enabled) ? 0x0210 : 0x2000; // USB 2.1 or USB 2.0
usb_dev_desc.bDeviceClass = dev_info->device_class;
usb_dev_desc.bDeviceSubClass = dev_info->device_subclass;
usb_dev_desc.bDeviceProtocol = dev_info->device_protocol;
@ -85,9 +88,6 @@ void usb_init(const usb_dev_info_t *dev_info) {
usb_str_table.serial_number = dev_info->serial_number;
usb_str_table.interface = dev_info->interface;
// enable/disable WinUSB
usb_winusb_enabled = dev_info->winusb_enabled;
// Configuration descriptor
usb_config_desc->bLength = sizeof(usb_config_descriptor_t);
usb_config_desc->bDescriptorType = USB_DESC_TYPE_CONFIGURATION;
@ -213,26 +213,31 @@ static uint8_t *usb_get_interface_str_descriptor(USBD_SpeedTypeDef speed, uint16
}
static uint8_t *usb_get_bos_descriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
static const uint8_t bos[] = {
// usb_bos_descriptor {
0x05, // uint8_t bLength
USB_DESC_TYPE_BOS, // uint8_t bDescriptorType
0x1d, 0x0, // uint16_t wTotalLength
0x01, // uint8_t bNumDeviceCaps
// }
// usb_device_capability_descriptor {
0x18, // uint8_t bLength
USB_DESC_TYPE_DEVICE_CAPABILITY, // uint8_t bDescriptorType
USB_DEVICE_CAPABILITY_PLATFORM, // uint8_t bDevCapabilityType
0x00, // uint8_t bReserved
0x38, 0xb6, 0x08, 0x34, 0xa9, 0x09, 0xa0, 0x47, 0x8b, 0xfd, 0xa0, 0x76, 0x88, 0x15, 0xb6, 0x65, // uint128_t platformCompatibilityUUID
0x00, 0x01, // uint16_t bcdVersion
USB_WEBUSB_VENDOR_CODE, // uint8_t bVendorCode
USB_WEBUSB_LANDING_PAGE, // uint8_t iLandingPage
// }
};
*length = sizeof(bos);
return UNCONST(bos);
if (sectrue == usb21_enabled) {
static const uint8_t bos[] = {
// usb_bos_descriptor {
0x05, // uint8_t bLength
USB_DESC_TYPE_BOS, // uint8_t bDescriptorType
0x1d, 0x0, // uint16_t wTotalLength
0x01, // uint8_t bNumDeviceCaps
// }
// usb_device_capability_descriptor {
0x18, // uint8_t bLength
USB_DESC_TYPE_DEVICE_CAPABILITY, // uint8_t bDescriptorType
USB_DEVICE_CAPABILITY_PLATFORM, // uint8_t bDevCapabilityType
0x00, // uint8_t bReserved
0x38, 0xb6, 0x08, 0x34, 0xa9, 0x09, 0xa0, 0x47, 0x8b, 0xfd, 0xa0, 0x76, 0x88, 0x15, 0xb6, 0x65, // uint128_t platformCompatibilityUUID
0x00, 0x01, // uint16_t bcdVersion
USB_WEBUSB_VENDOR_CODE, // uint8_t bVendorCode
USB_WEBUSB_LANDING_PAGE, // uint8_t iLandingPage
// }
};
*length = sizeof(bos);
return UNCONST(bos);
} else {
*length = 0;
return NULL;
}
}
static const USBD_DescriptorsTypeDef usb_descriptors = {
@ -302,7 +307,7 @@ static uint8_t usb_class_setup(USBD_HandleTypeDef *dev, USBD_SetupReqTypedef *re
if ((req->bmRequest & USB_REQ_TYPE_MASK) == USB_REQ_TYPE_VENDOR) {
if ((req->bmRequest & USB_REQ_RECIPIENT_MASK) == USB_REQ_RECIPIENT_DEVICE) {
if (req->bRequest == USB_WEBUSB_VENDOR_CODE) {
if (sectrue == usb21_enabled && req->bRequest == USB_WEBUSB_VENDOR_CODE) {
if (req->wIndex == USB_WEBUSB_REQ_GET_URL && req->wValue == USB_WEBUSB_LANDING_PAGE) {
static const char webusb_url[] = {
3 + 15, // uint8_t bLength
@ -318,7 +323,7 @@ static uint8_t usb_class_setup(USBD_HandleTypeDef *dev, USBD_SetupReqTypedef *re
}
}
else
if (sectrue == usb_winusb_enabled && req->bRequest == USB_WINUSB_VENDOR_CODE) {
if (sectrue == usb21_enabled && req->bRequest == USB_WINUSB_VENDOR_CODE) {
if (req->wIndex == USB_WINUSB_REQ_GET_COMPATIBLE_ID_FEATURE_DESCRIPTOR) {
static const uint8_t winusb_wcid[] = {
// header
@ -343,7 +348,7 @@ static uint8_t usb_class_setup(USBD_HandleTypeDef *dev, USBD_SetupReqTypedef *re
}
}
if ((req->bmRequest & USB_REQ_RECIPIENT_MASK) == USB_REQ_RECIPIENT_INTERFACE) {
if (sectrue == usb_winusb_enabled && req->bRequest == USB_WINUSB_VENDOR_CODE) {
if (sectrue == usb21_enabled && req->bRequest == USB_WINUSB_VENDOR_CODE) {
if (req->wIndex == USB_WINUSB_REQ_GET_EXTENDED_PROPERTIES_OS_FEATURE_DESCRIPTOR &&
(req->wValue & 0xFF) == 0) { // reply only if interface is 0
static const uint8_t winusb_guid[] = {
@ -442,7 +447,7 @@ static uint8_t *usb_class_get_cfg_desc(uint16_t *length) {
}
static uint8_t *usb_class_get_usrstr_desc(USBD_HandleTypeDef *dev, uint8_t index, uint16_t *length) {
if (sectrue == usb_winusb_enabled && index == USB_WINUSB_EXTRA_STRING_INDEX) {
if (sectrue == usb21_enabled && index == USB_WINUSB_EXTRA_STRING_INDEX) {
static const uint8_t winusb_string_descriptor[] = {
0x12, // bLength
USB_DESC_TYPE_STRING, // bDescriptorType
@ -452,7 +457,7 @@ static uint8_t *usb_class_get_usrstr_desc(USBD_HandleTypeDef *dev, uint8_t index
return UNCONST(winusb_string_descriptor);
} else {
*length = 0;
return 0;
return NULL;
}
}

View File

@ -103,7 +103,7 @@ typedef struct {
const char *product;
const char *serial_number;
const char *interface;
secbool winusb_enabled;
secbool usb21_enabled;
} usb_dev_info_t;
typedef enum {