parent
e1bc0ebc40
commit
eba242b806
@ -0,0 +1,2 @@
|
||||
---
|
||||
BasedOnStyle: Google
|
@ -1,75 +1,77 @@
|
||||
#define USB_INTERFACE_INDEX_MAIN 0
|
||||
|
||||
#define ENDPOINT_ADDRESS_IN (0x81)
|
||||
#define ENDPOINT_ADDRESS_OUT (0x01)
|
||||
#define ENDPOINT_ADDRESS_IN (0x81)
|
||||
#define ENDPOINT_ADDRESS_OUT (0x01)
|
||||
|
||||
static const struct usb_device_descriptor dev_descr = {
|
||||
.bLength = USB_DT_DEVICE_SIZE,
|
||||
.bDescriptorType = USB_DT_DEVICE,
|
||||
.bcdUSB = 0x0210,
|
||||
.bDeviceClass = 0,
|
||||
.bDeviceSubClass = 0,
|
||||
.bDeviceProtocol = 0,
|
||||
.bMaxPacketSize0 = 64,
|
||||
.idVendor = 0x1209,
|
||||
.idProduct = 0x53c0,
|
||||
.bcdDevice = 0x0100,
|
||||
.iManufacturer = 1,
|
||||
.iProduct = 2,
|
||||
.iSerialNumber = 3,
|
||||
.bNumConfigurations = 1,
|
||||
.bLength = USB_DT_DEVICE_SIZE,
|
||||
.bDescriptorType = USB_DT_DEVICE,
|
||||
.bcdUSB = 0x0210,
|
||||
.bDeviceClass = 0,
|
||||
.bDeviceSubClass = 0,
|
||||
.bDeviceProtocol = 0,
|
||||
.bMaxPacketSize0 = 64,
|
||||
.idVendor = 0x1209,
|
||||
.idProduct = 0x53c0,
|
||||
.bcdDevice = 0x0100,
|
||||
.iManufacturer = 1,
|
||||
.iProduct = 2,
|
||||
.iSerialNumber = 3,
|
||||
.bNumConfigurations = 1,
|
||||
};
|
||||
|
||||
static const struct usb_endpoint_descriptor endpoints[2] = {{
|
||||
.bLength = USB_DT_ENDPOINT_SIZE,
|
||||
.bDescriptorType = USB_DT_ENDPOINT,
|
||||
.bEndpointAddress = ENDPOINT_ADDRESS_IN,
|
||||
.bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT,
|
||||
.wMaxPacketSize = 64,
|
||||
.bInterval = 1,
|
||||
}, {
|
||||
.bLength = USB_DT_ENDPOINT_SIZE,
|
||||
.bDescriptorType = USB_DT_ENDPOINT,
|
||||
.bEndpointAddress = ENDPOINT_ADDRESS_OUT,
|
||||
.bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT,
|
||||
.wMaxPacketSize = 64,
|
||||
.bInterval = 1,
|
||||
}};
|
||||
static const struct usb_endpoint_descriptor endpoints[2] = {
|
||||
{
|
||||
.bLength = USB_DT_ENDPOINT_SIZE,
|
||||
.bDescriptorType = USB_DT_ENDPOINT,
|
||||
.bEndpointAddress = ENDPOINT_ADDRESS_IN,
|
||||
.bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT,
|
||||
.wMaxPacketSize = 64,
|
||||
.bInterval = 1,
|
||||
},
|
||||
{
|
||||
.bLength = USB_DT_ENDPOINT_SIZE,
|
||||
.bDescriptorType = USB_DT_ENDPOINT,
|
||||
.bEndpointAddress = ENDPOINT_ADDRESS_OUT,
|
||||
.bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT,
|
||||
.wMaxPacketSize = 64,
|
||||
.bInterval = 1,
|
||||
}};
|
||||
|
||||
static const struct usb_interface_descriptor iface[] = {{
|
||||
.bLength = USB_DT_INTERFACE_SIZE,
|
||||
.bDescriptorType = USB_DT_INTERFACE,
|
||||
.bInterfaceNumber = USB_INTERFACE_INDEX_MAIN,
|
||||
.bAlternateSetting = 0,
|
||||
.bNumEndpoints = 2,
|
||||
.bInterfaceClass = USB_CLASS_VENDOR,
|
||||
.bInterfaceSubClass = 0,
|
||||
.bInterfaceProtocol = 0,
|
||||
.iInterface = 0,
|
||||
.endpoint = endpoints,
|
||||
.extra = NULL,
|
||||
.extralen = 0,
|
||||
.bLength = USB_DT_INTERFACE_SIZE,
|
||||
.bDescriptorType = USB_DT_INTERFACE,
|
||||
.bInterfaceNumber = USB_INTERFACE_INDEX_MAIN,
|
||||
.bAlternateSetting = 0,
|
||||
.bNumEndpoints = 2,
|
||||
.bInterfaceClass = USB_CLASS_VENDOR,
|
||||
.bInterfaceSubClass = 0,
|
||||
.bInterfaceProtocol = 0,
|
||||
.iInterface = 0,
|
||||
.endpoint = endpoints,
|
||||
.extra = NULL,
|
||||
.extralen = 0,
|
||||
}};
|
||||
|
||||
static const struct usb_interface ifaces[] = {{
|
||||
.num_altsetting = 1,
|
||||
.altsetting = iface,
|
||||
.num_altsetting = 1,
|
||||
.altsetting = iface,
|
||||
}};
|
||||
|
||||
static const struct usb_config_descriptor config = {
|
||||
.bLength = USB_DT_CONFIGURATION_SIZE,
|
||||
.bDescriptorType = USB_DT_CONFIGURATION,
|
||||
.wTotalLength = 0,
|
||||
.bNumInterfaces = 1,
|
||||
.bConfigurationValue = 1,
|
||||
.iConfiguration = 0,
|
||||
.bmAttributes = 0x80,
|
||||
.bMaxPower = 0x32,
|
||||
.interface = ifaces,
|
||||
.bLength = USB_DT_CONFIGURATION_SIZE,
|
||||
.bDescriptorType = USB_DT_CONFIGURATION,
|
||||
.wTotalLength = 0,
|
||||
.bNumInterfaces = 1,
|
||||
.bConfigurationValue = 1,
|
||||
.iConfiguration = 0,
|
||||
.bmAttributes = 0x80,
|
||||
.bMaxPower = 0x32,
|
||||
.interface = ifaces,
|
||||
};
|
||||
|
||||
static const char *usb_strings[] = {
|
||||
"SatoshiLabs",
|
||||
"TREZOR",
|
||||
"000000000000000000000000",
|
||||
"SatoshiLabs",
|
||||
"TREZOR",
|
||||
"000000000000000000000000",
|
||||
};
|
||||
|
@ -1,44 +1,49 @@
|
||||
static void erase_storage_code_progress(void)
|
||||
{
|
||||
flash_wait_for_last_operation();
|
||||
flash_clear_status_flags();
|
||||
flash_unlock();
|
||||
// erase storage area
|
||||
for (int i = FLASH_STORAGE_SECTOR_FIRST; i <= FLASH_STORAGE_SECTOR_LAST; i++) {
|
||||
layoutProgress("WIPING ... Please wait", 1000 * (i - FLASH_STORAGE_SECTOR_FIRST) / (FLASH_CODE_SECTOR_LAST - FLASH_STORAGE_SECTOR_FIRST));
|
||||
flash_erase_sector(i, FLASH_CR_PROGRAM_X32);
|
||||
}
|
||||
// erase code area
|
||||
for (int i = FLASH_CODE_SECTOR_FIRST; i <= FLASH_CODE_SECTOR_LAST; i++) {
|
||||
layoutProgress("WIPING ... Please wait", 1000 * (i - FLASH_STORAGE_SECTOR_FIRST) / (FLASH_CODE_SECTOR_LAST - FLASH_STORAGE_SECTOR_FIRST));
|
||||
flash_erase_sector(i, FLASH_CR_PROGRAM_X32);
|
||||
}
|
||||
flash_wait_for_last_operation();
|
||||
flash_lock();
|
||||
static void erase_storage_code_progress(void) {
|
||||
flash_wait_for_last_operation();
|
||||
flash_clear_status_flags();
|
||||
flash_unlock();
|
||||
// erase storage area
|
||||
for (int i = FLASH_STORAGE_SECTOR_FIRST; i <= FLASH_STORAGE_SECTOR_LAST;
|
||||
i++) {
|
||||
layoutProgress("WIPING ... Please wait",
|
||||
1000 * (i - FLASH_STORAGE_SECTOR_FIRST) /
|
||||
(FLASH_CODE_SECTOR_LAST - FLASH_STORAGE_SECTOR_FIRST));
|
||||
flash_erase_sector(i, FLASH_CR_PROGRAM_X32);
|
||||
}
|
||||
// erase code area
|
||||
for (int i = FLASH_CODE_SECTOR_FIRST; i <= FLASH_CODE_SECTOR_LAST; i++) {
|
||||
layoutProgress("WIPING ... Please wait",
|
||||
1000 * (i - FLASH_STORAGE_SECTOR_FIRST) /
|
||||
(FLASH_CODE_SECTOR_LAST - FLASH_STORAGE_SECTOR_FIRST));
|
||||
flash_erase_sector(i, FLASH_CR_PROGRAM_X32);
|
||||
}
|
||||
flash_wait_for_last_operation();
|
||||
flash_lock();
|
||||
}
|
||||
|
||||
static void erase_code_progress(void)
|
||||
{
|
||||
flash_wait_for_last_operation();
|
||||
flash_clear_status_flags();
|
||||
flash_unlock();
|
||||
for (int i = FLASH_CODE_SECTOR_FIRST; i <= FLASH_CODE_SECTOR_LAST; i++) {
|
||||
layoutProgress("PREPARING ... Please wait", 1000 * (i - FLASH_CODE_SECTOR_FIRST) / (FLASH_CODE_SECTOR_LAST - FLASH_CODE_SECTOR_FIRST));
|
||||
flash_erase_sector(i, FLASH_CR_PROGRAM_X32);
|
||||
}
|
||||
layoutProgress("INSTALLING ... Please wait", 0);
|
||||
flash_wait_for_last_operation();
|
||||
flash_lock();
|
||||
static void erase_code_progress(void) {
|
||||
flash_wait_for_last_operation();
|
||||
flash_clear_status_flags();
|
||||
flash_unlock();
|
||||
for (int i = FLASH_CODE_SECTOR_FIRST; i <= FLASH_CODE_SECTOR_LAST; i++) {
|
||||
layoutProgress("PREPARING ... Please wait",
|
||||
1000 * (i - FLASH_CODE_SECTOR_FIRST) /
|
||||
(FLASH_CODE_SECTOR_LAST - FLASH_CODE_SECTOR_FIRST));
|
||||
flash_erase_sector(i, FLASH_CR_PROGRAM_X32);
|
||||
}
|
||||
layoutProgress("INSTALLING ... Please wait", 0);
|
||||
flash_wait_for_last_operation();
|
||||
flash_lock();
|
||||
}
|
||||
|
||||
static void erase_storage(void)
|
||||
{
|
||||
flash_wait_for_last_operation();
|
||||
flash_clear_status_flags();
|
||||
flash_unlock();
|
||||
for (int i = FLASH_STORAGE_SECTOR_FIRST; i <= FLASH_STORAGE_SECTOR_LAST; i++) {
|
||||
flash_erase_sector(i, FLASH_CR_PROGRAM_X32);
|
||||
}
|
||||
flash_wait_for_last_operation();
|
||||
flash_lock();
|
||||
static void erase_storage(void) {
|
||||
flash_wait_for_last_operation();
|
||||
flash_clear_status_flags();
|
||||
flash_unlock();
|
||||
for (int i = FLASH_STORAGE_SECTOR_FIRST; i <= FLASH_STORAGE_SECTOR_LAST;
|
||||
i++) {
|
||||
flash_erase_sector(i, FLASH_CR_PROGRAM_X32);
|
||||
}
|
||||
flash_wait_for_last_operation();
|
||||
flash_lock();
|
||||
}
|
||||
|
@ -1,86 +1,92 @@
|
||||
static void send_msg_success(usbd_device *dev)
|
||||
{
|
||||
uint8_t response[64];
|
||||
memzero(response, sizeof(response));
|
||||
// response: Success message (id 2), payload len 0
|
||||
memcpy(response,
|
||||
// header
|
||||
"?##"
|
||||
// msg_id
|
||||
"\x00\x02"
|
||||
// msg_size
|
||||
"\x00\x00\x00\x00",
|
||||
9);
|
||||
while (usbd_ep_write_packet(dev, ENDPOINT_ADDRESS_IN, response, 64) != 64) {}
|
||||
static void send_msg_success(usbd_device *dev) {
|
||||
uint8_t response[64];
|
||||
memzero(response, sizeof(response));
|
||||
// response: Success message (id 2), payload len 0
|
||||
memcpy(response,
|
||||
// header
|
||||
"?##"
|
||||
// msg_id
|
||||
"\x00\x02"
|
||||
// msg_size
|
||||
"\x00\x00\x00\x00",
|
||||
9);
|
||||
while (usbd_ep_write_packet(dev, ENDPOINT_ADDRESS_IN, response, 64) != 64) {
|
||||
}
|
||||
}
|
||||
|
||||
static void send_msg_failure(usbd_device *dev)
|
||||
{
|
||||
uint8_t response[64];
|
||||
memzero(response, sizeof(response));
|
||||
// response: Failure message (id 3), payload len 2
|
||||
// - code = 99 (Failure_FirmwareError)
|
||||
memcpy(response,
|
||||
// header
|
||||
"?##"
|
||||
// msg_id
|
||||
"\x00\x03"
|
||||
// msg_size
|
||||
"\x00\x00\x00\x02"
|
||||
// data
|
||||
"\x08" "\x63",
|
||||
11);
|
||||
while (usbd_ep_write_packet(dev, ENDPOINT_ADDRESS_IN, response, 64) != 64) {}
|
||||
static void send_msg_failure(usbd_device *dev) {
|
||||
uint8_t response[64];
|
||||
memzero(response, sizeof(response));
|
||||
// response: Failure message (id 3), payload len 2
|
||||
// - code = 99 (Failure_FirmwareError)
|
||||
memcpy(response,
|
||||
// header
|
||||
"?##"
|
||||
// msg_id
|
||||
"\x00\x03"
|
||||
// msg_size
|
||||
"\x00\x00\x00\x02"
|
||||
// data
|
||||
"\x08"
|
||||
"\x63",
|
||||
11);
|
||||
while (usbd_ep_write_packet(dev, ENDPOINT_ADDRESS_IN, response, 64) != 64) {
|
||||
}
|
||||
}
|
||||
|
||||
static void send_msg_features(usbd_device *dev)
|
||||
{
|
||||
uint8_t response[64];
|
||||
memzero(response, sizeof(response));
|
||||
// response: Features message (id 17), payload len 25
|
||||
// - vendor = "trezor.io"
|
||||
// - major_version = VERSION_MAJOR
|
||||
// - minor_version = VERSION_MINOR
|
||||
// - patch_version = VERSION_PATCH
|
||||
// - bootloader_mode = True
|
||||
// - firmware_present = True/False
|
||||
// - model = "1"
|
||||
memcpy(response,
|
||||
// header
|
||||
"?##"
|
||||
// msg_id
|
||||
"\x00\x11"
|
||||
// msg_size
|
||||
"\x00\x00\x00\x16"
|
||||
// data
|
||||
"\x0a" "\x09" "trezor.io"
|
||||
"\x10" VERSION_MAJOR_CHAR
|
||||
"\x18" VERSION_MINOR_CHAR
|
||||
"\x20" VERSION_PATCH_CHAR
|
||||
"\x28" "\x01"
|
||||
"\x90\x01" "\x00"
|
||||
"\xaa" "\x01" "1",
|
||||
34);
|
||||
response[30] = firmware_present_new() ? 0x01 : 0x00;
|
||||
while (usbd_ep_write_packet(dev, ENDPOINT_ADDRESS_IN, response, 64) != 64) {}
|
||||
static void send_msg_features(usbd_device *dev) {
|
||||
uint8_t response[64];
|
||||
memzero(response, sizeof(response));
|
||||
// response: Features message (id 17), payload len 25
|
||||
// - vendor = "trezor.io"
|
||||
// - major_version = VERSION_MAJOR
|
||||
// - minor_version = VERSION_MINOR
|
||||
// - patch_version = VERSION_PATCH
|
||||
// - bootloader_mode = True
|
||||
// - firmware_present = True/False
|
||||
// - model = "1"
|
||||
memcpy(response,
|
||||
// header
|
||||
"?##"
|
||||
// msg_id
|
||||
"\x00\x11"
|
||||
// msg_size
|
||||
"\x00\x00\x00\x16"
|
||||
// data
|
||||
"\x0a"
|
||||
"\x09"
|
||||
"trezor.io"
|
||||
"\x10" VERSION_MAJOR_CHAR "\x18" VERSION_MINOR_CHAR
|
||||
"\x20" VERSION_PATCH_CHAR
|
||||
"\x28"
|
||||
"\x01"
|
||||
"\x90\x01"
|
||||
"\x00"
|
||||
"\xaa"
|
||||
"\x01"
|
||||
"1",
|
||||
34);
|
||||
response[30] = firmware_present_new() ? 0x01 : 0x00;
|
||||
while (usbd_ep_write_packet(dev, ENDPOINT_ADDRESS_IN, response, 64) != 64) {
|
||||
}
|
||||
}
|
||||
|
||||
static void send_msg_buttonrequest_firmwarecheck(usbd_device *dev)
|
||||
{
|
||||
uint8_t response[64];
|
||||
memzero(response, sizeof(response));
|
||||
// response: ButtonRequest message (id 26), payload len 2
|
||||
// - code = ButtonRequest_FirmwareCheck (9)
|
||||
memcpy(response,
|
||||
// header
|
||||
"?##"
|
||||
// msg_id
|
||||
"\x00\x1a"
|
||||
// msg_size
|
||||
"\x00\x00\x00\x02"
|
||||
// data
|
||||
"\x08" "\x09",
|
||||
11
|
||||
);
|
||||
while (usbd_ep_write_packet(dev, ENDPOINT_ADDRESS_IN, response, 64) != 64) {}
|
||||
static void send_msg_buttonrequest_firmwarecheck(usbd_device *dev) {
|
||||
uint8_t response[64];
|
||||
memzero(response, sizeof(response));
|
||||
// response: ButtonRequest message (id 26), payload len 2
|
||||
// - code = ButtonRequest_FirmwareCheck (9)
|
||||
memcpy(response,
|
||||
// header
|
||||
"?##"
|
||||
// msg_id
|
||||
"\x00\x1a"
|
||||
// msg_size
|
||||
"\x00\x00\x00\x02"
|
||||
// data
|
||||
"\x08"
|
||||
"\x09",
|
||||
11);
|
||||
while (usbd_ep_write_packet(dev, ENDPOINT_ADDRESS_IN, response, 64) != 64) {
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue