embed/trezorhal: move cmd_buffer into usb_vcp_state_t

This commit is contained in:
Pavol Rusnak 2018-02-06 15:30:15 +01:00
parent 585e9842f8
commit 548b8cb25b
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 6 additions and 8 deletions

View File

@ -100,6 +100,9 @@ typedef struct {
uint8_t *buf; uint8_t *buf;
} usb_rbuf_t; } usb_rbuf_t;
// Maximal length of packets on IN CMD EP
#define USB_CDC_MAX_CMD_PACKET_LEN 0x08
/* usb_vcp_state_t encapsulates all state used by enabled VCP interface. It /* usb_vcp_state_t encapsulates all state used by enabled VCP interface. It
* needs to be completely initialized in usb_vcp_add and reset in * needs to be completely initialized in usb_vcp_add and reset in
* usb_vcp_class_init. See usb_vcp_info_t for details of the configuration * usb_vcp_class_init. See usb_vcp_info_t for details of the configuration
@ -117,6 +120,7 @@ typedef struct {
uint8_t ep_out; uint8_t ep_out;
uint8_t max_packet_len; uint8_t max_packet_len;
uint8_t ep_in_is_idle; // Set to 1 after IN endpoint gets idle uint8_t ep_in_is_idle; // Set to 1 after IN endpoint gets idle
uint8_t cmd_buffer[USB_CDC_MAX_CMD_PACKET_LEN];
} usb_vcp_state_t; } usb_vcp_state_t;
secbool __wur usb_vcp_add(const usb_vcp_info_t *vcp_info); secbool __wur usb_vcp_add(const usb_vcp_info_t *vcp_info);

View File

@ -37,9 +37,6 @@
#define USB_CDC_GET_LINE_CODING 0x21 #define USB_CDC_GET_LINE_CODING 0x21
#define USB_CDC_SET_CONTROL_LINE_STATE 0x22 #define USB_CDC_SET_CONTROL_LINE_STATE 0x22
// Maximal length of packets on IN CMD EP
#define USB_CDC_MAX_CMD_PACKET_LEN 0x08
/* usb_vcp_add adds and configures new USB VCP interface according to /* usb_vcp_add adds and configures new USB VCP interface according to
* configuration options passed in `info`. */ * configuration options passed in `info`. */
secbool usb_vcp_add(const usb_vcp_info_t *info) { secbool usb_vcp_add(const usb_vcp_info_t *info) {
@ -349,9 +346,6 @@ static int usb_vcp_class_setup(USBD_HandleTypeDef *dev, usb_vcp_state_t *state,
.bDataBits = 8, .bDataBits = 8,
}; };
// TODO: make cmd buffer part of interface state
static uint8_t cmd_buffer[USB_CDC_MAX_CMD_PACKET_LEN];
if ((req->bmRequest & USB_REQ_TYPE_MASK) != USB_REQ_TYPE_CLASS) { if ((req->bmRequest & USB_REQ_TYPE_MASK) != USB_REQ_TYPE_CLASS) {
return USBD_OK; return USBD_OK;
} }
@ -360,11 +354,11 @@ static int usb_vcp_class_setup(USBD_HandleTypeDef *dev, usb_vcp_state_t *state,
if (req->bRequest == USB_CDC_GET_LINE_CODING) { if (req->bRequest == USB_CDC_GET_LINE_CODING) {
USBD_CtlSendData(dev, UNCONST(&line_coding), MIN(req->wLength, sizeof(line_coding))); USBD_CtlSendData(dev, UNCONST(&line_coding), MIN(req->wLength, sizeof(line_coding)));
} else { } else {
USBD_CtlSendData(dev, cmd_buffer, MIN(req->wLength, sizeof(cmd_buffer))); USBD_CtlSendData(dev, state->cmd_buffer, MIN(req->wLength, USB_CDC_MAX_CMD_PACKET_LEN));
} }
} else { // USB_REQ_DIR_H2D } else { // USB_REQ_DIR_H2D
if (req->wLength > 0) { if (req->wLength > 0) {
USBD_CtlPrepareRx(dev, cmd_buffer, MIN(req->wLength, sizeof(cmd_buffer))); USBD_CtlPrepareRx(dev, state->cmd_buffer, MIN(req->wLength, USB_CDC_MAX_CMD_PACKET_LEN));
} }
} }