diff --git a/drivers/usb/device/usb_dc_native_posix_adapt.c b/drivers/usb/device/usb_dc_native_posix_adapt.c index e1ac35a5d36..34a9d4f8ce7 100644 --- a/drivers/usb/device/usb_dc_native_posix_adapt.c +++ b/drivers/usb/device/usb_dc_native_posix_adapt.c @@ -75,7 +75,7 @@ static void usbip_header_dump(struct usbip_header *hdr) void get_interface(u8_t *descriptors) { while (descriptors[0]) { - if (descriptors[1] == DESC_INTERFACE) { + if (descriptors[1] == USB_INTERFACE_DESC) { LOG_DBG("interface found"); } @@ -94,7 +94,7 @@ static int send_interfaces(const u8_t *descriptors, int connfd) } __packed iface; while (descriptors[0]) { - if (descriptors[1] == DESC_INTERFACE) { + if (descriptors[1] == USB_INTERFACE_DESC) { struct usb_if_descriptor *desc = (void *)descriptors; iface.bInterfaceClass = desc->bInterfaceClass; diff --git a/include/usb/class/usb_cdc.h b/include/usb/class/usb_cdc.h index d5751a85d00..7c973585e1c 100644 --- a/include/usb/class/usb_cdc.h +++ b/include/usb/class/usb_cdc.h @@ -39,13 +39,6 @@ */ #define DATA_INTERFACE_CLASS 0x0A -/** - * @brief Values for the bDescriptorType Field - * @note CDC120-20101103-track.pdf, 5.2.3, Table 12 - */ -#define CS_INTERFACE 0x24 -#define CS_ENDPOINT 0x25 - /** * @brief bDescriptor SubType for Communications * Class Functional Descriptors diff --git a/include/usb/usb_common.h b/include/usb/usb_common.h index c5bfc31a0e4..22383ab7768 100644 --- a/include/usb/usb_common.h +++ b/include/usb/usb_common.h @@ -65,10 +65,14 @@ #define USB_INTERFACE_DESC 0x04 #define USB_ENDPOINT_DESC 0x05 #define USB_DEVICE_QUAL_DESC 0x06 +#define USB_OTHER_SPEED 0x07 +#define USB_INTERFACE_POWER 0x08 #define USB_INTERFACE_ASSOC_DESC 0x0B #define USB_DEVICE_CAPABILITY_DESC 0x10 #define USB_HID_DESC 0x21 #define USB_HID_REPORT_DESC 0x22 +#define CS_INTERFACE 0x24 +#define CS_ENDPOINT 0x25 #define USB_DFU_FUNCTIONAL_DESC 0x21 #define USB_ASSOCIATION_DESC 0x0B #define USB_BINARY_OBJECT_STORE_DESC 0x0F diff --git a/include/usb/usbstruct.h b/include/usb/usbstruct.h index 62337f4221b..b9ae6ffec3e 100644 --- a/include/usb/usbstruct.h +++ b/include/usb/usbstruct.h @@ -84,18 +84,6 @@ struct usb_desc_header { u8_t bDescriptorType; /**< descriptor type */ }; -#define DESC_DEVICE 1 -#define DESC_CONFIGURATION 2 -#define DESC_STRING 3 -#define DESC_INTERFACE 4 -#define DESC_ENDPOINT 5 -#define DESC_DEVICE_QUALIFIER 6 -#define DESC_OTHER_SPEED 7 -#define DESC_INTERFACE_POWER 8 - -#define CS_INTERFACE 0x24 -#define CS_ENDPOINT 0x25 - #define GET_DESC_TYPE(x) (((x)>>8)&0xFF) #define GET_DESC_INDEX(x) ((x)&0xFF) diff --git a/samples/subsys/usb/webusb/src/main.c b/samples/subsys/usb/webusb/src/main.c index 111da28e38c..6c0b1e6f42d 100644 --- a/samples/subsys/usb/webusb/src/main.c +++ b/samples/subsys/usb/webusb/src/main.c @@ -202,7 +202,7 @@ static const u8_t msos1_compatid_descriptor[] = { int custom_handle_req(struct usb_setup_packet *pSetup, s32_t *len, u8_t **data) { - if (GET_DESC_TYPE(pSetup->wValue) == DESC_STRING && + if (GET_DESC_TYPE(pSetup->wValue) == USB_STRING_DESC && GET_DESC_INDEX(pSetup->wValue) == 0xEE) { *data = (u8_t *)(&msos1_string_descriptor); *len = sizeof(msos1_string_descriptor); diff --git a/subsys/usb/os_desc.c b/subsys/usb/os_desc.c index 93743a0dd9c..d925ef11793 100644 --- a/subsys/usb/os_desc.c +++ b/subsys/usb/os_desc.c @@ -11,6 +11,7 @@ LOG_MODULE_REGISTER(usb_os_desc); #include #include +#include #include static struct usb_os_descriptor *os_desc; @@ -22,7 +23,7 @@ int usb_handle_os_desc(struct usb_setup_packet *setup, return -ENOTSUP; } - if (GET_DESC_TYPE(setup->wValue) == DESC_STRING && + if (GET_DESC_TYPE(setup->wValue) == USB_STRING_DESC && GET_DESC_INDEX(setup->wValue) == USB_OSDESC_STRING_DESC_INDEX) { LOG_DBG("MS OS Descriptor string read"); *data = os_desc->string; diff --git a/subsys/usb/usb_device.c b/subsys/usb/usb_device.c index 96727c5af3e..0a7fba68527 100644 --- a/subsys/usb/usb_device.c +++ b/subsys/usb/usb_device.c @@ -440,8 +440,8 @@ static bool usb_get_descriptor(u16_t type_index, u16_t lang_id, * Invalid types of descriptors, * see USB Spec. Revision 2.0, 9.4.3 Get Descriptor */ - if ((type == DESC_INTERFACE) || (type == DESC_ENDPOINT) || - (type > DESC_OTHER_SPEED)) { + if ((type == USB_INTERFACE_DESC) || (type == USB_ENDPOINT_DESC) || + (type > USB_OTHER_SPEED)) { return false; } @@ -464,7 +464,7 @@ static bool usb_get_descriptor(u16_t type_index, u16_t lang_id, /* set data pointer */ *data = p; /* get length from structure */ - if (type == DESC_CONFIGURATION) { + if (type == USB_CONFIGURATION_DESC) { /* configuration descriptor is an * exception, length is at offset * 2 and 3 @@ -539,7 +539,7 @@ static bool usb_set_configuration(u8_t config_index, u8_t alt_setting) /* configure endpoints for this configuration/altsetting */ while (p[DESC_bLength] != 0U) { switch (p[DESC_bDescriptorType]) { - case DESC_CONFIGURATION: + case USB_CONFIGURATION_DESC: /* remember current configuration index */ cur_config = p[CONF_DESC_bConfigurationValue]; if (cur_config == config_index) { @@ -548,13 +548,13 @@ static bool usb_set_configuration(u8_t config_index, u8_t alt_setting) break; - case DESC_INTERFACE: + case USB_INTERFACE_DESC: /* remember current alternate setting */ cur_alt_setting = p[INTF_DESC_bAlternateSetting]; break; - case DESC_ENDPOINT: + case USB_ENDPOINT_DESC: if ((cur_config != config_index) || (cur_alt_setting != alt_setting)) { break; @@ -598,7 +598,7 @@ static bool usb_set_interface(u8_t iface, u8_t alt_setting) while (p[DESC_bLength] != 0U) { switch (p[DESC_bDescriptorType]) { - case DESC_INTERFACE: + case USB_INTERFACE_DESC: /* remember current alternate setting */ cur_alt_setting = p[INTF_DESC_bAlternateSetting]; cur_iface = p[INTF_DESC_bInterfaceNumber]; @@ -610,10 +610,9 @@ static bool usb_set_interface(u8_t iface, u8_t alt_setting) LOG_DBG("iface_num %u alt_set %u", iface, alt_setting); break; - case DESC_ENDPOINT: + case USB_ENDPOINT_DESC: if ((cur_iface != iface) || (cur_alt_setting != alt_setting)) { - break; } found = set_endpoint((struct usb_ep_descriptor *)p); diff --git a/tests/subsys/usb/os_desc/src/usb_osdesc.c b/tests/subsys/usb/os_desc/src/usb_osdesc.c index 6d743b89979..78891c600ac 100644 --- a/tests/subsys/usb/os_desc/src/usb_osdesc.c +++ b/tests/subsys/usb/os_desc/src/usb_osdesc.c @@ -95,7 +95,7 @@ static void test_handle_os_desc(void) u8_t *data = NULL; int ret; - setup.wValue = (DESC_STRING & 0xFF) << 8; + setup.wValue = (USB_STRING_DESC & 0xFF) << 8; setup.wValue |= USB_OSDESC_STRING_DESC_INDEX; ret = usb_handle_os_desc(&setup, &len, &data);