usb: Special return values for custom_handler

This commit introduces dedicated return type for custom_handler.
Relevant code is updated to fulfill the API documentation.

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
This commit is contained in:
Emil Obalski 2020-05-06 15:55:35 +02:00 committed by Carles Cufí
commit 45bdb23005
5 changed files with 14 additions and 12 deletions

View file

@ -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;
};

View file

@ -212,7 +212,7 @@ int custom_handle_req(struct usb_setup_packet *pSetup,
return 0;
}
return -ENOTSUP;
return -EINVAL;
}
/**

View file

@ -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;
}
/**

View file

@ -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)

View file

@ -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,