From 919e2b9c3bf5ba8af6bc85bdab046a3e025c0882 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Tue, 23 Jan 2018 01:34:47 +0100 Subject: [PATCH] trezorhal: formatting nits in usb --- embed/trezorhal/usb.c | 6 ++--- embed/trezorhal/usb.h | 6 ++--- embed/trezorhal/usb_hid-impl.h | 18 ++++++------- embed/trezorhal/usb_vcp-impl.h | 44 +++++++++++++++---------------- embed/trezorhal/usb_webusb-defs.h | 10 +++---- embed/trezorhal/usb_webusb-impl.h | 14 +++++----- 6 files changed, 49 insertions(+), 49 deletions(-) diff --git a/embed/trezorhal/usb.c b/embed/trezorhal/usb.c index 750dee55ce..064f8b3fd6 100644 --- a/embed/trezorhal/usb.c +++ b/embed/trezorhal/usb.c @@ -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 diff --git a/embed/trezorhal/usb.h b/embed/trezorhal/usb.h index 31758bdf6c..3f690def3f 100644 --- a/embed/trezorhal/usb.h +++ b/embed/trezorhal/usb.h @@ -11,9 +11,9 @@ #include #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; diff --git a/embed/trezorhal/usb_hid-impl.h b/embed/trezorhal/usb_hid-impl.h index 63219ea583..2384599685 100644 --- a/embed/trezorhal/usb_hid-impl.h +++ b/embed/trezorhal/usb_hid-impl.h @@ -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) { diff --git a/embed/trezorhal/usb_vcp-impl.h b/embed/trezorhal/usb_vcp-impl.h index 338c5d201b..292803fbf3 100644 --- a/embed/trezorhal/usb_vcp-impl.h +++ b/embed/trezorhal/usb_vcp-impl.h @@ -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))); } diff --git a/embed/trezorhal/usb_webusb-defs.h b/embed/trezorhal/usb_webusb-defs.h index 910c9206af..31d5948304 100644 --- a/embed/trezorhal/usb_webusb-defs.h +++ b/embed/trezorhal/usb_webusb-defs.h @@ -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)) { diff --git a/embed/trezorhal/usb_webusb-impl.h b/embed/trezorhal/usb_webusb-impl.h index 9374390645..9f060e0c97 100644 --- a/embed/trezorhal/usb_webusb-impl.h +++ b/embed/trezorhal/usb_webusb-impl.h @@ -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) {