mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-10 15:30:55 +00:00
trezorhal: formatting nits in usb
This commit is contained in:
parent
11a5825928
commit
919e2b9c3b
@ -13,9 +13,9 @@
|
||||
|
||||
#define UNCONST(X) ((uint8_t *)(X))
|
||||
|
||||
#define USB_MAX_CONFIG_DESC_SIZE 256
|
||||
#define USB_MAX_STR_SIZE 62
|
||||
#define USB_MAX_STR_DESC_SIZE (USB_MAX_STR_SIZE * 2 + 2)
|
||||
#define USB_MAX_CONFIG_DESC_SIZE 256
|
||||
#define USB_MAX_STR_SIZE 62
|
||||
#define USB_MAX_STR_DESC_SIZE (USB_MAX_STR_SIZE * 2 + 2)
|
||||
|
||||
#if defined(USE_USB_FS)
|
||||
#define USB_PHY_ID USB_PHY_FS_ID
|
||||
|
@ -11,9 +11,9 @@
|
||||
#include <stdint.h>
|
||||
#include "secbool.h"
|
||||
|
||||
#define USB_EP_DIR_OUT 0x00
|
||||
#define USB_EP_DIR_IN 0x80
|
||||
#define USB_EP_DIR_MSK 0x80
|
||||
#define USB_EP_DIR_MASK 0x80
|
||||
#define USB_EP_DIR_OUT 0x00
|
||||
#define USB_EP_DIR_IN 0x80
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint8_t bLength;
|
||||
|
@ -5,15 +5,15 @@
|
||||
* see LICENSE file for details
|
||||
*/
|
||||
|
||||
#define USB_CLASS_HID 0x03
|
||||
#define USB_CLASS_HID 0x03
|
||||
|
||||
#define USB_DESC_TYPE_HID 0x21
|
||||
#define USB_DESC_TYPE_REPORT 0x22
|
||||
#define USB_DESC_TYPE_HID 0x21
|
||||
#define USB_DESC_TYPE_REPORT 0x22
|
||||
|
||||
#define USB_HID_REQ_SET_PROTOCOL 0x0B
|
||||
#define USB_HID_REQ_GET_PROTOCOL 0x03
|
||||
#define USB_HID_REQ_SET_IDLE 0x0A
|
||||
#define USB_HID_REQ_GET_IDLE 0x02
|
||||
#define USB_HID_REQ_SET_PROTOCOL 0x0B
|
||||
#define USB_HID_REQ_GET_PROTOCOL 0x03
|
||||
#define USB_HID_REQ_SET_IDLE 0x0A
|
||||
#define USB_HID_REQ_GET_IDLE 0x02
|
||||
|
||||
/* usb_hid_add adds and configures new USB HID interface according to
|
||||
* configuration options passed in `info`. */
|
||||
@ -34,10 +34,10 @@ secbool usb_hid_add(const usb_hid_info_t *info) {
|
||||
return secfalse; // Not enough space in the configuration descriptor
|
||||
}
|
||||
|
||||
if ((info->ep_in & USB_EP_DIR_MSK) != USB_EP_DIR_IN) {
|
||||
if ((info->ep_in & USB_EP_DIR_MASK) != USB_EP_DIR_IN) {
|
||||
return secfalse; // IN EP is invalid
|
||||
}
|
||||
if ((info->ep_out & USB_EP_DIR_MSK) != USB_EP_DIR_OUT) {
|
||||
if ((info->ep_out & USB_EP_DIR_MASK) != USB_EP_DIR_OUT) {
|
||||
return secfalse; // OUT EP is invalid
|
||||
}
|
||||
if (info->rx_buffer == NULL) {
|
||||
|
@ -6,39 +6,39 @@
|
||||
*/
|
||||
|
||||
// Communications Device Class Code (bFunctionClass, bInterfaceClass)
|
||||
#define USB_CLASS_CDC 0x02
|
||||
#define USB_CLASS_CDC 0x02
|
||||
|
||||
// Data Interface Class Code (bInterfaceClass)
|
||||
#define USB_CLASS_DATA 0x0A
|
||||
#define USB_CLASS_DATA 0x0A
|
||||
|
||||
// Class Subclass Code (bFunctionSubClass, bInterfaceSubClass)
|
||||
#define USB_CDC_SUBCLASS_ACM 0x02
|
||||
#define USB_CDC_SUBCLASS_ACM 0x02
|
||||
|
||||
// Communications Interface Class Control Protocol Codes (bFunctionProtocol, bInterfaceProtocol)
|
||||
#define USB_CDC_PROTOCOL_AT 0x01
|
||||
#define USB_CDC_PROTOCOL_AT 0x01
|
||||
|
||||
// Descriptor Types (bDescriptorType)
|
||||
#define USB_DESC_TYPE_ASSOCIATION 0x0B
|
||||
#define USB_DESC_TYPE_CS_INTERACE 0x24
|
||||
#define USB_DESC_TYPE_ASSOCIATION 0x0B
|
||||
#define USB_DESC_TYPE_CS_INTERACE 0x24
|
||||
|
||||
// Descriptor SubTypes (bDescriptorSubtype)
|
||||
#define USB_DESC_TYPE_HEADER 0x00
|
||||
#define USB_DESC_TYPE_CM 0x01
|
||||
#define USB_DESC_TYPE_ACM 0x02
|
||||
#define USB_DESC_TYPE_UNION 0x06
|
||||
#define USB_DESC_TYPE_HEADER 0x00
|
||||
#define USB_DESC_TYPE_CM 0x01
|
||||
#define USB_DESC_TYPE_ACM 0x02
|
||||
#define USB_DESC_TYPE_UNION 0x06
|
||||
|
||||
// Data Phase Transfer Direction (bmRequest)
|
||||
#define USB_REQ_DIR_MASK 0x80
|
||||
#define USB_H2D 0x00
|
||||
#define USB_D2H 0x80
|
||||
#define USB_REQ_DIR_MASK 0x80
|
||||
#define USB_REQ_DIR_H2D 0x00
|
||||
#define USB_REQ_DIR_D2H 0x80
|
||||
|
||||
// Class-Specific Request Codes for PSTN subclasses
|
||||
#define USB_CDC_SET_LINE_CODING 0x20
|
||||
#define USB_CDC_GET_LINE_CODING 0x21
|
||||
#define USB_CDC_SET_CONTROL_LINE_STATE 0x22
|
||||
#define USB_CDC_SET_LINE_CODING 0x20
|
||||
#define USB_CDC_GET_LINE_CODING 0x21
|
||||
#define USB_CDC_SET_CONTROL_LINE_STATE 0x22
|
||||
|
||||
// Maximal length of packets on IN CMD EP
|
||||
#define USB_CDC_MAX_CMD_PACKET_LEN 0x08
|
||||
#define USB_CDC_MAX_CMD_PACKET_LEN 0x08
|
||||
|
||||
/* usb_vcp_add adds and configures new USB VCP interface according to
|
||||
* configuration options passed in `info`. */
|
||||
@ -59,13 +59,13 @@ secbool usb_vcp_add(const usb_vcp_info_t *info) {
|
||||
return secfalse; // Not enough space in the configuration descriptor
|
||||
}
|
||||
|
||||
if ((info->ep_cmd & USB_EP_DIR_MSK) != USB_EP_DIR_IN) {
|
||||
if ((info->ep_cmd & USB_EP_DIR_MASK) != USB_EP_DIR_IN) {
|
||||
return secfalse; // IN CMD EP is invalid
|
||||
}
|
||||
if ((info->ep_in & USB_EP_DIR_MSK) != USB_EP_DIR_IN) {
|
||||
if ((info->ep_in & USB_EP_DIR_MASK) != USB_EP_DIR_IN) {
|
||||
return secfalse; // IN EP is invalid
|
||||
}
|
||||
if ((info->ep_out & USB_EP_DIR_MSK) != USB_EP_DIR_OUT) {
|
||||
if ((info->ep_out & USB_EP_DIR_MASK) != USB_EP_DIR_OUT) {
|
||||
return secfalse; // OUT EP is invalid
|
||||
}
|
||||
if ((info->rx_buffer_len == 0) || (info->rx_buffer_len & (info->rx_buffer_len - 1)) != 0) {
|
||||
@ -357,7 +357,7 @@ static int usb_vcp_class_setup(USBD_HandleTypeDef *dev, usb_vcp_state_t *state,
|
||||
}
|
||||
|
||||
switch (req->bmRequest & USB_REQ_DIR_MASK) {
|
||||
case USB_D2H:
|
||||
case USB_REQ_DIR_D2H:
|
||||
switch (req->bRequest) {
|
||||
case USB_CDC_GET_LINE_CODING:
|
||||
USBD_CtlSendData(dev, UNCONST(&line_coding), MIN(req->wLength, sizeof(line_coding)));
|
||||
@ -367,7 +367,7 @@ static int usb_vcp_class_setup(USBD_HandleTypeDef *dev, usb_vcp_state_t *state,
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case USB_H2D:
|
||||
case USB_REQ_DIR_H2D:
|
||||
if (req->wLength > 0) {
|
||||
USBD_CtlPrepareRx(dev, cmd_buffer, MIN(req->wLength, sizeof(cmd_buffer)));
|
||||
}
|
||||
|
@ -5,15 +5,15 @@
|
||||
* see LICENSE file for details
|
||||
*/
|
||||
|
||||
#define USB_WEBUSB_VENDOR_CODE 0x01 // arbitrary
|
||||
#define USB_WEBUSB_LANDING_PAGE 0x01 // arbitrary
|
||||
#define USB_WEBUSB_VENDOR_CODE 0x01 // arbitrary
|
||||
#define USB_WEBUSB_LANDING_PAGE 0x01 // arbitrary
|
||||
|
||||
#define USE_WINUSB 1
|
||||
|
||||
#if USE_WINUSB
|
||||
#define USB_WINUSB_VENDOR_CODE '!' // arbitrary, but must be equivalent to the last character in extra string
|
||||
#define USB_WINUSB_EXTRA_STRING 'M', 0x00, 'S', 0x00, 'F', 0x00, 'T', 0x00, USB_WINUSB_VENDOR_CODE , 0x00, 0x00, 0x00 // MSFT100!
|
||||
#define USB_WINUSB_EXTRA_STRING_INDEX 0xEE
|
||||
#define USB_WINUSB_VENDOR_CODE '!' // arbitrary, but must be equivalent to the last character in extra string
|
||||
#define USB_WINUSB_EXTRA_STRING 'M', 0x00, 'S', 0x00, 'F', 0x00, 'T', 0x00, USB_WINUSB_VENDOR_CODE , 0x00, 0x00, 0x00 // MSFT100!
|
||||
#define USB_WINUSB_EXTRA_STRING_INDEX 0xEE
|
||||
#endif
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
|
@ -5,12 +5,12 @@
|
||||
* see LICENSE file for details
|
||||
*/
|
||||
|
||||
#define USB_CLASS_WEBUSB 0xFF
|
||||
#define USB_CLASS_WEBUSB 0xFF
|
||||
|
||||
#define USB_WEBUSB_REQ_SET_PROTOCOL 0x0B
|
||||
#define USB_WEBUSB_REQ_GET_PROTOCOL 0x03
|
||||
#define USB_WEBUSB_REQ_SET_IDLE 0x0A
|
||||
#define USB_WEBUSB_REQ_GET_IDLE 0x02
|
||||
#define USB_WEBUSB_REQ_SET_PROTOCOL 0x0B
|
||||
#define USB_WEBUSB_REQ_GET_PROTOCOL 0x03
|
||||
#define USB_WEBUSB_REQ_SET_IDLE 0x0A
|
||||
#define USB_WEBUSB_REQ_GET_IDLE 0x02
|
||||
|
||||
#define USB_WEBUSB_REQ_GET_URL 0x02
|
||||
#define USB_WEBUSB_DESCRIPTOR_TYPE_URL 0x03
|
||||
@ -36,10 +36,10 @@ secbool usb_webusb_add(const usb_webusb_info_t *info) {
|
||||
return secfalse; // Not enough space in the configuration descriptor
|
||||
}
|
||||
|
||||
if ((info->ep_in & USB_EP_DIR_MSK) != USB_EP_DIR_IN) {
|
||||
if ((info->ep_in & USB_EP_DIR_MASK) != USB_EP_DIR_IN) {
|
||||
return secfalse; // IN EP is invalid
|
||||
}
|
||||
if ((info->ep_out & USB_EP_DIR_MSK) != USB_EP_DIR_OUT) {
|
||||
if ((info->ep_out & USB_EP_DIR_MASK) != USB_EP_DIR_OUT) {
|
||||
return secfalse; // OUT EP is invalid
|
||||
}
|
||||
if (info->rx_buffer == NULL) {
|
||||
|
Loading…
Reference in New Issue
Block a user