usb: device_next: remove foobaz interface from common shell code
Foobaz interface will be renamed and added as a standalone part
to serve as an API example in a subsequent commit.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
diff --git a/subsys/usb/device_next/usbd_shell.c b/subsys/usb/device_next/usbd_shell.c
index f93e096..1b0738d 100644
--- a/subsys/usb/device_next/usbd_shell.c
+++ b/subsys/usb/device_next/usbd_shell.c
@@ -16,226 +16,8 @@
const struct shell *ctx_shell;
-/*
- * We define foobaz USB device class which is to be used for the
- * specific shell commands like register and submit.
- */
-
-#define FOOBAZ_VREQ_OUT 0x5b
-#define FOOBAZ_VREQ_IN 0x5c
-
-static uint8_t foobaz_buf[512];
-
-/* Make supported vendor request visible for the device stack */
-static const struct usbd_cctx_vendor_req foobaz_vregs =
- USBD_VENDOR_REQ(FOOBAZ_VREQ_OUT, FOOBAZ_VREQ_IN);
-
-struct foobaz_iface_desc {
- struct usb_if_descriptor if0;
- struct usb_if_descriptor if1;
- struct usb_ep_descriptor if1_out_ep;
- struct usb_ep_descriptor if1_in_ep;
- struct usb_desc_header nil_desc;
-} __packed;
-
-static struct foobaz_iface_desc foobaz_desc = {
- .if0 = {
- .bLength = sizeof(struct usb_if_descriptor),
- .bDescriptorType = USB_DESC_INTERFACE,
- .bInterfaceNumber = 0,
- .bAlternateSetting = 0,
- .bNumEndpoints = 0,
- .bInterfaceClass = USB_BCC_VENDOR,
- .bInterfaceSubClass = 0,
- .bInterfaceProtocol = 0,
- .iInterface = 0,
- },
-
- .if1 = {
- .bLength = sizeof(struct usb_if_descriptor),
- .bDescriptorType = USB_DESC_INTERFACE,
- .bInterfaceNumber = 0,
- .bAlternateSetting = 1,
- .bNumEndpoints = 2,
- .bInterfaceClass = USB_BCC_VENDOR,
- .bInterfaceSubClass = 0,
- .bInterfaceProtocol = 0,
- .iInterface = 0,
- },
-
- .if1_out_ep = {
- .bLength = sizeof(struct usb_ep_descriptor),
- .bDescriptorType = USB_DESC_ENDPOINT,
- .bEndpointAddress = 0x01,
- .bmAttributes = USB_EP_TYPE_BULK,
- .wMaxPacketSize = 0,
- .bInterval = 0x00,
- },
-
- .if1_in_ep = {
- .bLength = sizeof(struct usb_ep_descriptor),
- .bDescriptorType = USB_DESC_ENDPOINT,
- .bEndpointAddress = 0x81,
- .bmAttributes = USB_EP_TYPE_BULK,
- .wMaxPacketSize = 0,
- .bInterval = 0x00,
- },
-
- /* Termination descriptor */
- .nil_desc = {
- .bLength = 0,
- .bDescriptorType = 0,
- },
-};
-
-static size_t foobaz_get_ep_mps(struct usbd_class_data *const data)
-{
- struct foobaz_iface_desc *desc = data->desc;
-
- return desc->if1_out_ep.wMaxPacketSize;
-}
-
-static size_t foobaz_ep_addr_out(struct usbd_class_data *const data)
-{
- struct foobaz_iface_desc *desc = data->desc;
-
- return desc->if1_out_ep.bEndpointAddress;
-}
-
-static size_t foobaz_ep_addr_in(struct usbd_class_data *const data)
-{
- struct foobaz_iface_desc *desc = data->desc;
-
- return desc->if1_in_ep.bEndpointAddress;
-}
-
-static void foobaz_update(struct usbd_class_node *const node,
- uint8_t iface, uint8_t alternate)
-{
- shell_info(ctx_shell,
- "dev: New configuration, interface %u alternate %u",
- iface, alternate);
-}
-
-static int foobaz_cth(struct usbd_class_node *const node,
- const struct usb_setup_packet *const setup,
- struct net_buf *const buf)
-{
- size_t min_len = MIN(sizeof(foobaz_buf), setup->wLength);
-
- if (setup->bRequest == FOOBAZ_VREQ_IN) {
- if (buf == NULL) {
- errno = -ENOMEM;
- return 0;
- }
-
- net_buf_add_mem(buf, foobaz_buf, min_len);
- shell_info(ctx_shell,
- "dev: conrol transfer to host, wLength %u | %zu",
- setup->wLength, min_len);
-
- return 0;
- }
-
- errno = -ENOTSUP;
- return 0;
-}
-
-static int foobaz_ctd(struct usbd_class_node *const node,
- const struct usb_setup_packet *const setup,
- const struct net_buf *const buf)
-{
- size_t min_len = MIN(sizeof(foobaz_buf), setup->wLength);
-
- if (setup->bRequest == FOOBAZ_VREQ_OUT) {
- shell_info(ctx_shell,
- "dev: control transfer to device, wLength %u | %zu",
- setup->wLength, min_len);
- memcpy(foobaz_buf, buf->data, min_len);
- return 0;
- }
-
- errno = -ENOTSUP;
- return 0;
-}
-
-static int foobaz_request_cancelled(struct usbd_class_node *const node,
- struct net_buf *buf)
-{
- struct udc_buf_info *bi;
-
- bi = udc_get_buf_info(buf);
- shell_warn(ctx_shell, "Request ep 0x%02x cancelled", bi->ep);
- shell_warn(ctx_shell, "|-> %p", buf);
- for (struct net_buf *n = buf; n->frags != NULL; n = n->frags) {
- shell_warn(ctx_shell, "|-> %p", n->frags);
- }
-
- return 0;
-}
-
-static int foobaz_ep_request(struct usbd_class_node *const node,
- struct net_buf *buf, int err)
-{
- struct usbd_contex *uds_ctx = node->data->uds_ctx;
- struct udc_buf_info *bi;
-
- bi = udc_get_buf_info(buf);
- shell_info(ctx_shell, "dev: Handle request ep 0x%02x, len %u",
- bi->ep, buf->len);
-
- if (err) {
- if (err == -ECONNABORTED) {
- foobaz_request_cancelled(node, buf);
- } else {
- shell_error(ctx_shell,
- "dev: Request failed (%d) ep 0x%02x, len %u",
- err, bi->ep, buf->len);
- }
- }
-
- if (err == 0 && USB_EP_DIR_IS_OUT(bi->ep)) {
- shell_hexdump(ctx_shell, buf->data, buf->len);
- }
-
- return usbd_ep_buf_free(uds_ctx, buf);
-}
-
-static void foobaz_suspended(struct usbd_class_node *const node)
-{
- shell_info(ctx_shell, "dev: Device suspended");
-}
-
-static void foobaz_resumed(struct usbd_class_node *const node)
-{
- shell_info(ctx_shell, "dev: Device resumed");
-}
-
-static int foobaz_init(struct usbd_class_node *const node)
-{
- return 0;
-}
-
-/* Define foobaz interface to USB device class API */
-struct usbd_class_api foobaz_api = {
- .update = foobaz_update,
- .control_to_host = foobaz_cth,
- .control_to_dev = foobaz_ctd,
- .request = foobaz_ep_request,
- .suspended = foobaz_suspended,
- .resumed = foobaz_resumed,
- .init = foobaz_init,
-};
-
-static struct usbd_class_data foobaz_data = {
- .desc = (struct usb_desc_header *)&foobaz_desc,
- .v_reqs = &foobaz_vregs,
-};
-
-USBD_DEFINE_CLASS(foobaz, &foobaz_api, &foobaz_data);
-
-USBD_CONFIGURATION_DEFINE(config_foo, USB_SCD_SELF_POWERED, 200);
USBD_CONFIGURATION_DEFINE(config_baz, USB_SCD_REMOTE_WAKEUP, 200);
+USBD_CONFIGURATION_DEFINE(config_foo, USB_SCD_SELF_POWERED, 200);
USBD_DESC_LANG_DEFINE(lang);
USBD_DESC_STRING_DEFINE(mfr, "ZEPHYR", 1);
@@ -260,112 +42,6 @@
return err;
}
-static int cmd_submit_request(const struct shell *sh,
- size_t argc, char **argv)
-{
- struct net_buf *buf;
- size_t len;
- uint8_t ep;
- int ret;
-
- ep = strtol(argv[1], NULL, 16);
-
- if (ep != foobaz_ep_addr_out(&foobaz_data) &&
- ep != foobaz_ep_addr_in(&foobaz_data)) {
- struct foobaz_iface_desc *desc = foobaz_data.desc;
-
- shell_error(sh, "dev: Endpoint address not valid %x",
- desc->if1_out_ep.bEndpointAddress);
-
-
- return -EINVAL;
- }
-
- if (argc > 2) {
- len = strtol(argv[2], NULL, 10);
- } else {
- len = foobaz_get_ep_mps(&foobaz_data);
- }
-
- if (USB_EP_DIR_IS_IN(ep)) {
- len = MIN(len, sizeof(foobaz_buf));
- }
-
- buf = usbd_ep_buf_alloc(&foobaz, ep, len);
- if (buf == NULL) {
- return -ENOMEM;
- }
-
- if (USB_EP_DIR_IS_IN(ep)) {
- net_buf_add_mem(buf, foobaz_buf, len);
- }
-
- shell_print(sh, "dev: Submit ep 0x%02x len %zu buf %p", ep, len, buf);
- ret = usbd_ep_enqueue(&foobaz, buf);
- if (ret) {
- shell_print(sh, "dev: Failed to queue request buffer");
- usbd_ep_buf_free(&uds_ctx, buf);
- }
-
- return ret;
-}
-
-static int cmd_cancel_request(const struct shell *sh,
- size_t argc, char **argv)
-{
- uint8_t ep;
- int ret;
-
- shell_print(sh, "dev: Request %s %s", argv[1], argv[2]);
-
- ep = strtol(argv[1], NULL, 16);
- if (ep != foobaz_ep_addr_out(&foobaz_data) &&
- ep != foobaz_ep_addr_in(&foobaz_data)) {
- shell_error(sh, "dev: Endpoint address not valid");
- return -EINVAL;
- }
-
- ret = usbd_ep_dequeue(&uds_ctx, ep);
- if (ret) {
- shell_print(sh, "dev: Failed to dequeue request buffer");
- }
-
- return ret;
-}
-
-static int cmd_endpoint_halt(const struct shell *sh,
- size_t argc, char **argv)
-{
- uint8_t ep;
- int ret = 0;
-
- ep = strtol(argv[1], NULL, 16);
- if (ep != foobaz_ep_addr_out(&foobaz_data) &&
- ep != foobaz_ep_addr_in(&foobaz_data)) {
- shell_error(sh, "dev: Endpoint address not valid");
- return -EINVAL;
- }
-
- if (!strcmp(argv[2], "set")) {
- ret = usbd_ep_set_halt(&uds_ctx, ep);
- } else if (!strcmp(argv[2], "clear")) {
- ret = usbd_ep_clear_halt(&uds_ctx, ep);
- } else {
- shell_error(sh, "dev: Invalid argument: %s", argv[1]);
- return -EINVAL;
- }
-
- if (ret) {
- shell_print(sh, "dev: endpoint %s %s halt failed",
- argv[2], argv[1]);
- } else {
- shell_print(sh, "dev: endpoint %s %s halt successful",
- argv[2], argv[1]);
- }
-
- return ret;
-}
-
static int cmd_register(const struct shell *sh,
size_t argc, char **argv)
{
@@ -427,9 +103,11 @@
shell_error(sh, "dev: Failed to add configuration");
}
- err = usbd_register_class(&uds_ctx, "foobaz", 1);
- if (err) {
- shell_error(sh, "dev: Failed to add foobaz class");
+ if (IS_ENABLED(CONFIG_USBD_LOOPBACK_CLASS)) {
+ err = usbd_register_class(&uds_ctx, "loopback_0", 1);
+ if (err) {
+ shell_error(sh, "dev: Failed to add loopback_0 class");
+ }
}
ctx_shell = sh;
@@ -775,16 +453,6 @@
SHELL_SUBCMD_SET_END
);
-SHELL_STATIC_SUBCMD_SET_CREATE(endpoint_cmds,
- SHELL_CMD_ARG(halt, NULL, "<endpoint> <set clear>",
- cmd_endpoint_halt, 3, 0),
- SHELL_CMD_ARG(submit, NULL, "<endpoint> [length]",
- cmd_submit_request, 2, 1),
- SHELL_CMD_ARG(cancel, NULL, "<endpoint>",
- cmd_cancel_request, 2, 0),
- SHELL_SUBCMD_SET_END
-);
-
SHELL_STATIC_SUBCMD_SET_CREATE(sub_usbd_cmds,
SHELL_CMD_ARG(wakeup, NULL, "[none]",
cmd_wakeup_request, 1, 0),
@@ -806,8 +474,6 @@
NULL, 1, 0),
SHELL_CMD_ARG(class, &class_cmds, "class commands",
NULL, 1, 0),
- SHELL_CMD_ARG(endpoint, &endpoint_cmds, "endpoint commands",
- NULL, 1, 0),
SHELL_SUBCMD_SET_END
);