summaryrefslogtreecommitdiff
path: root/chip/stm32
diff options
context:
space:
mode:
authorAnton Staaf <robotboy@chromium.org>2014-12-01 13:36:42 -0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-12-02 21:11:35 +0000
commit0f10bf88b27746d6f757538a11d9f7d6ca334e8d (patch)
tree2240ddc0767e1ed6750773655456351f797fd116 /chip/stm32
parent8fa4947f7681aac58937395610ed204fa34b6d5a (diff)
downloadchrome-ec-0f10bf88b27746d6f757538a11d9f7d6ca334e8d.tar.gz
USB: Interface callbacks now return an error code
A non-zero error code returned by the callback causes EP0 to STALL. This is the common mechanism used in USB to indicate an error while processing a control request. This simplifies the implementation of interface callbacks. Signed-off-by: Anton Staaf <robotboy@chromium.org> BRANCH=None BUG=None TEST=make buildall -j Change-Id: I89ceb4892f9f810fcaf6e975e6982fc5b2ae447b Reviewed-on: https://chromium-review.googlesource.com/232368 Reviewed-by: Anton Staaf <robotboy@chromium.org> Commit-Queue: Anton Staaf <robotboy@chromium.org> Tested-by: Anton Staaf <robotboy@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'chip/stm32')
-rw-r--r--chip/stm32/usb.c5
-rw-r--r--chip/stm32/usb_endpoints.S4
-rw-r--r--chip/stm32/usb_hid.c7
-rw-r--r--chip/stm32/usb_ms.c42
4 files changed, 30 insertions, 28 deletions
diff --git a/chip/stm32/usb.c b/chip/stm32/usb.c
index b4dfb31fb5..64bff8bd40 100644
--- a/chip/stm32/usb.c
+++ b/chip/stm32/usb.c
@@ -94,8 +94,9 @@ static void ep0_rx(void)
/* interface specific requests */
if ((req & USB_RECIP_MASK) == USB_RECIP_INTERFACE) {
uint8_t iface = ep0_buf_rx[2] & 0xff;
- if (iface < USB_IFACE_COUNT)
- usb_iface_request[iface](ep0_buf_rx, ep0_buf_tx);
+ if (iface < USB_IFACE_COUNT &&
+ usb_iface_request[iface](ep0_buf_rx, ep0_buf_tx))
+ goto unknown_req;
return;
}
diff --git a/chip/stm32/usb_endpoints.S b/chip/stm32/usb_endpoints.S
index 0c950ccbe1..cc13cadeb3 100644
--- a/chip/stm32/usb_endpoints.S
+++ b/chip/stm32/usb_endpoints.S
@@ -100,6 +100,8 @@ interface 7
.code 16
.thumb_func
-ep_undefined:
+/* Undefined interface callbacks fail by returning non-zero*/
iface_undefined:
+ mov r0, #1
+ep_undefined:
bx lr
diff --git a/chip/stm32/usb_hid.c b/chip/stm32/usb_hid.c
index 347140f9ac..bdcf09c3f8 100644
--- a/chip/stm32/usb_hid.c
+++ b/chip/stm32/usb_hid.c
@@ -118,7 +118,7 @@ static void hid_reset(void)
USB_DECLARE_EP(USB_EP_HID, hid_tx, hid_tx, hid_reset);
-static void hid_iface_request(usb_uint *ep0_buf_rx, usb_uint *ep0_buf_tx)
+static int hid_iface_request(usb_uint *ep0_buf_rx, usb_uint *ep0_buf_tx)
{
if ((ep0_buf_rx[0] == (USB_DIR_IN | USB_RECIP_INTERFACE |
(USB_REQ_GET_DESCRIPTOR << 8))) &&
@@ -132,9 +132,10 @@ static void hid_iface_request(usb_uint *ep0_buf_rx, usb_uint *ep0_buf_tx)
EP_STATUS_OUT);
CPRINTF("RPT %04x[l %04x]\n", STM32_USB_EP(0),
ep0_buf_rx[3]);
- } else {
- STM32_TOGGLE_EP(0, EP_TX_RX_MASK, EP_RX_VALID | EP_TX_STALL, 0);
+ return 0;
}
+
+ return 1;
}
USB_DECLARE_IFACE(USB_IFACE_HID, hid_iface_request)
diff --git a/chip/stm32/usb_ms.c b/chip/stm32/usb_ms.c
index 8c0abbe1d5..329f80e8a1 100644
--- a/chip/stm32/usb_ms.c
+++ b/chip/stm32/usb_ms.c
@@ -163,35 +163,33 @@ static void ms_rx(void)
USB_DECLARE_EP(USB_EP_MS_TX, ms_tx, ms_tx, ms_tx_reset);
USB_DECLARE_EP(USB_EP_MS_RX, ms_rx, ms_rx, ms_rx_reset);
-static void ms_iface_request(usb_uint *ep0_buf_rx, usb_uint *ep0_buf_tx)
+static int ms_iface_request(usb_uint *ep0_buf_rx, usb_uint *ep0_buf_tx)
{
uint16_t *req = (uint16_t *) ep0_buf_rx;
- if ((req[0] & (USB_DIR_OUT | USB_RECIP_INTERFACE | USB_TYPE_CLASS)) ==
- (USB_DIR_OUT | USB_RECIP_INTERFACE | USB_TYPE_CLASS)) {
- switch (req[0] >> 8) {
- case USB_MS_REQ_RESET:
- if (req[1] == 0 && req[2] == USB_IFACE_MS &&
- req[3] == 0) {
- ms_rx_reset();
- }
+ if ((req[0] & (USB_DIR_OUT | USB_RECIP_INTERFACE | USB_TYPE_CLASS)) !=
+ (USB_DIR_OUT | USB_RECIP_INTERFACE | USB_TYPE_CLASS))
+ return 1;
+
+ switch (req[0] >> 8) {
+ case USB_MS_REQ_RESET:
+ if (req[1] == 0 && req[2] == USB_IFACE_MS &&
+ req[3] == 0) {
+ ms_rx_reset();
+ }
break;
- case USB_MS_REQ_GET_MAX_LUN:
- if (req[1] == 0 && req[2] == USB_IFACE_MS &&
- req[3] == 1) {
- ep0_buf_tx[0] = SCSI_MAX_LUN;
- btable_ep[0].tx_count = sizeof(uint8_t);
- STM32_TOGGLE_EP(USB_EP_CONTROL, EP_TX_RX_MASK,
+ case USB_MS_REQ_GET_MAX_LUN:
+ if (req[1] == 0 && req[2] == USB_IFACE_MS &&
+ req[3] == 1) {
+ ep0_buf_tx[0] = SCSI_MAX_LUN;
+ btable_ep[0].tx_count = sizeof(uint8_t);
+ STM32_TOGGLE_EP(USB_EP_CONTROL, EP_TX_RX_MASK,
EP_TX_RX_VALID, 0);
- }
- break;
}
- } else {
- CPRINTF("ms stalling: %x %x %x %x\n",
- req[0], req[1], req[2], req[3]);
- STM32_TOGGLE_EP(USB_EP_CONTROL, EP_TX_RX_MASK,
- EP_RX_VALID | EP_TX_STALL, 0);
+ break;
}
+
+ return 0;
}
USB_DECLARE_IFACE(USB_IFACE_MS, ms_iface_request);