mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-13 19:18:56 +00:00
trezorhal: add device_class, etc. to usb object
This commit is contained in:
parent
52a942afd4
commit
488e516cbf
@ -31,13 +31,16 @@ static const uint8_t * const BOOTLOADER_KEYS[] = {
|
||||
static void usb_init_all(void) {
|
||||
|
||||
static const usb_dev_info_t dev_info = {
|
||||
.vendor_id = 0x1209,
|
||||
.product_id = 0x53C0,
|
||||
.release_num = 0x0200,
|
||||
.manufacturer = "SatoshiLabs",
|
||||
.product = "TREZOR",
|
||||
.serial_number = "000000000000000000000000",
|
||||
.interface = "TREZOR Interface",
|
||||
.device_class = 0x00,
|
||||
.device_subclass = 0x00,
|
||||
.device_protocol = 0x00,
|
||||
.vendor_id = 0x1209,
|
||||
.product_id = 0x53C0,
|
||||
.release_num = 0x0200,
|
||||
.manufacturer = "SatoshiLabs",
|
||||
.product = "TREZOR",
|
||||
.serial_number = "000000000000000000000000",
|
||||
.interface = "TREZOR Interface",
|
||||
};
|
||||
|
||||
static uint8_t rx_buffer[USB_PACKET_SIZE];
|
||||
|
@ -31,6 +31,9 @@ static const char *get_0str(mp_obj_t o, size_t min_len, size_t max_len) {
|
||||
}
|
||||
|
||||
/// def __init__(self,
|
||||
/// device_class: int=0,
|
||||
/// device_subclass: int=0,
|
||||
/// device_protocol: int=0,
|
||||
/// vendor_id: int,
|
||||
/// product_id: int,
|
||||
/// release_num: int,
|
||||
@ -43,6 +46,9 @@ static const char *get_0str(mp_obj_t o, size_t min_len, size_t max_len) {
|
||||
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) {
|
||||
|
||||
STATIC const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_device_class, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
|
||||
{ MP_QSTR_device_subclass, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
|
||||
{ MP_QSTR_device_protocol, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
|
||||
{ MP_QSTR_vendor_id, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
|
||||
{ MP_QSTR_product_id, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
|
||||
{ MP_QSTR_release_num, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
|
||||
@ -54,14 +60,20 @@ STATIC mp_obj_t mod_trezorio_USB_make_new(const mp_obj_type_t *type, size_t n_ar
|
||||
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);
|
||||
|
||||
const mp_int_t vendor_id = vals[0].u_int;
|
||||
const mp_int_t product_id = vals[1].u_int;
|
||||
const mp_int_t release_num = vals[2].u_int;
|
||||
const char *manufacturer = get_0str(vals[3].u_obj, 0, 32);
|
||||
const char *product = get_0str(vals[4].u_obj, 0, 32);
|
||||
const char *serial_number = get_0str(vals[5].u_obj, 0, 32);
|
||||
const char *interface = get_0str(vals[6].u_obj, 0, 32);
|
||||
const mp_int_t device_class = vals[0].u_int;
|
||||
const mp_int_t device_subclass = vals[1].u_int;
|
||||
const mp_int_t device_protocol = vals[2].u_int;
|
||||
const mp_int_t vendor_id = vals[3].u_int;
|
||||
const mp_int_t product_id = vals[4].u_int;
|
||||
const mp_int_t release_num = vals[5].u_int;
|
||||
const char *manufacturer = get_0str(vals[6].u_obj, 0, 32);
|
||||
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);
|
||||
|
||||
CHECK_PARAM_RANGE(device_class, 0, 255)
|
||||
CHECK_PARAM_RANGE(device_subclass, 0, 255)
|
||||
CHECK_PARAM_RANGE(device_protocol, 0, 255)
|
||||
CHECK_PARAM_RANGE(vendor_id, 0, 65535)
|
||||
CHECK_PARAM_RANGE(product_id, 0, 65535)
|
||||
CHECK_PARAM_RANGE(release_num, 0, 65535)
|
||||
@ -83,13 +95,16 @@ STATIC mp_obj_t mod_trezorio_USB_make_new(const mp_obj_type_t *type, size_t n_ar
|
||||
|
||||
o->state = USB_CLOSED;
|
||||
|
||||
o->info.vendor_id = (uint16_t)(vendor_id);
|
||||
o->info.product_id = (uint16_t)(product_id);
|
||||
o->info.release_num = (uint16_t)(release_num);
|
||||
o->info.manufacturer = manufacturer;
|
||||
o->info.product = product;
|
||||
o->info.serial_number = serial_number;
|
||||
o->info.interface = interface;
|
||||
o->info.device_class = (uint8_t)(device_class);
|
||||
o->info.device_subclass = (uint8_t)(device_subclass);
|
||||
o->info.device_protocol = (uint8_t)(device_protocol);
|
||||
o->info.vendor_id = (uint16_t)(vendor_id);
|
||||
o->info.product_id = (uint16_t)(product_id);
|
||||
o->info.release_num = (uint16_t)(release_num);
|
||||
o->info.manufacturer = manufacturer;
|
||||
o->info.product = product;
|
||||
o->info.serial_number = serial_number;
|
||||
o->info.interface = interface;
|
||||
mp_obj_list_init(&o->ifaces, 0);
|
||||
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
|
@ -86,13 +86,16 @@ static void usb_init_all(void)
|
||||
};
|
||||
|
||||
static const usb_dev_info_t dev_info = {
|
||||
.vendor_id = 0x1209,
|
||||
.product_id = 0x53C1,
|
||||
.release_num = 0x0200,
|
||||
.manufacturer = "SatoshiLabs",
|
||||
.product = "TREZOR",
|
||||
.serial_number = "000000000000",
|
||||
.interface = "TREZOR Interface",
|
||||
.device_class = 0xEF, // Composite Device Class
|
||||
.device_subclass = 0x02, // Common Class
|
||||
.device_protocol = 0x01, // Interface Association Descriptor
|
||||
.vendor_id = 0x1209,
|
||||
.product_id = 0x53C1,
|
||||
.release_num = 0x0200,
|
||||
.manufacturer = "SatoshiLabs",
|
||||
.product = "TREZOR",
|
||||
.serial_number = "000000000000",
|
||||
.interface = "TREZOR Interface",
|
||||
};
|
||||
|
||||
static uint8_t tx_packet[VCP_PACKET_LEN];
|
||||
|
@ -64,9 +64,9 @@ void usb_init(const usb_dev_info_t *dev_info) {
|
||||
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.bDeviceClass = 0x00; // Use class code info from Interface Descriptors
|
||||
usb_dev_desc.bDeviceSubClass = 0x00;
|
||||
usb_dev_desc.bDeviceProtocol = 0x00;
|
||||
usb_dev_desc.bDeviceClass = dev_info->device_class;
|
||||
usb_dev_desc.bDeviceSubClass = dev_info->device_subclass;
|
||||
usb_dev_desc.bDeviceProtocol = dev_info->device_protocol;
|
||||
usb_dev_desc.bMaxPacketSize0 = USB_MAX_EP0_SIZE;
|
||||
usb_dev_desc.idVendor = dev_info->vendor_id;
|
||||
usb_dev_desc.idProduct = dev_info->product_id;
|
||||
|
@ -93,6 +93,9 @@ typedef struct {
|
||||
} usb_dev_string_table_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t device_class;
|
||||
uint8_t device_subclass;
|
||||
uint8_t device_protocol;
|
||||
uint16_t vendor_id;
|
||||
uint16_t product_id;
|
||||
uint16_t release_num;
|
||||
|
Loading…
Reference in New Issue
Block a user