diff --git a/include/usb/usb_device.h b/include/usb/usb_device.h index c383cafe48c..d8a76bd645e 100644 --- a/include/usb/usb_device.h +++ b/include/usb/usb_device.h @@ -157,6 +157,10 @@ struct usb_interface_cfg_data { * The custom request handler gets a first chance at handling * the request before it is handed over to the 'chapter 9' request * handler. + * return 0 on success, -EINVAL if the request has not been handled by + * the custom handler and instead needs to be handled by the + * core USB stack. Any other error code to denote failure within + * the custom handler. */ usb_request_handler custom_handler; }; diff --git a/samples/subsys/usb/webusb/src/main.c b/samples/subsys/usb/webusb/src/main.c index df5749c4907..ca1135395be 100644 --- a/samples/subsys/usb/webusb/src/main.c +++ b/samples/subsys/usb/webusb/src/main.c @@ -212,7 +212,7 @@ int custom_handle_req(struct usb_setup_packet *pSetup, return 0; } - return -ENOTSUP; + return -EINVAL; } /** diff --git a/samples/subsys/usb/webusb/src/webusb.c b/samples/subsys/usb/webusb/src/webusb.c index 397ccca1ae3..69e17cf68c2 100644 --- a/samples/subsys/usb/webusb/src/webusb.c +++ b/samples/subsys/usb/webusb/src/webusb.c @@ -89,12 +89,11 @@ int webusb_custom_handle_req(struct usb_setup_packet *pSetup, LOG_DBG(""); /* Call the callback */ - if ((req_handlers && req_handlers->custom_handler) && - (!req_handlers->custom_handler(pSetup, len, data))) { - return 0; + if (req_handlers && req_handlers->custom_handler) { + return req_handlers->custom_handler(pSetup, len, data); } - return -ENOTSUP; + return -EINVAL; } /** @@ -110,12 +109,11 @@ int webusb_vendor_handle_req(struct usb_setup_packet *pSetup, s32_t *len, u8_t **data) { /* Call the callback */ - if ((req_handlers && req_handlers->vendor_handler) && - (!req_handlers->vendor_handler(pSetup, len, data))) { - return 0; + if (req_handlers && req_handlers->vendor_handler) { + return req_handlers->vendor_handler(pSetup, len, data); } - return -ENOTSUP; + return -EINVAL; } /** diff --git a/subsys/usb/class/hid/core.c b/subsys/usb/class/hid/core.c index 47eac0abeca..08771997813 100644 --- a/subsys/usb/class/hid/core.c +++ b/subsys/usb/class/hid/core.c @@ -509,7 +509,7 @@ static int hid_custom_handle_req(struct usb_setup_packet *setup, if (common == NULL) { LOG_WRN("Device data not found for interface %u", sys_le16_to_cpu(setup->wIndex)); - return -ENODEV; + return -EINVAL; } dev_data = CONTAINER_OF(common, struct hid_device_info, common); @@ -545,7 +545,7 @@ static int hid_custom_handle_req(struct usb_setup_packet *setup, return 0; } - return -ENOTSUP; + return -EINVAL; } static void hid_int_in(u8_t ep, enum usb_dc_ep_cb_status_code ep_status) diff --git a/subsys/usb/class/usb_dfu.c b/subsys/usb/class/usb_dfu.c index a6bbb05dcb9..80d42926e63 100644 --- a/subsys/usb/class/usb_dfu.c +++ b/subsys/usb/class/usb_dfu.c @@ -694,7 +694,7 @@ static int dfu_custom_handle_req(struct usb_setup_packet *pSetup, } /* Not handled by us */ - return -ENOTSUP; + return -EINVAL; } static void dfu_interface_config(struct usb_desc_header *head,