usb:tools: usb unittests framework
cover usb:tools: usb unittests framework
This patch introduces a user-space framework for developing unit tests in order to test the USB functionality of a connected device. These tests communicate with the USB device via libusb interface. They are meant to run with the g_zero and dummy_hcd module since several proprietary control messages were added to those modules. But a smaller subset of the tests can be run on any USB device and on real UDCs.
Implemented tests:
1. Test device descriptors - this test is applicable both for HS and SS devices
2. Test the SET_FEATURE requests
3. Test bulk in
4. Test bulk out
5. Test connect/disconnect
6. Streams capability testing
7. UAS test suite
This patch also includes patches that should be applied to libusb. Some of them were already sent upstream for approval but not yet accepted. Other will be sent in the near future.
For more info please read the files under Documentation.
(I've splited the patch into 3 since it was too big)
Tatyana Brokhman (3):
usb unittests framework: test files
usb unittests framework: Documentation
usb unitests framework: libusb patches
.../usb/unittests/Documentation/autoconfig_readme | 20 + .../usb/unittests/Documentation/create-gadget-img | 47 + tools/usb/unittests/Documentation/unittests-info | 526 +++++ tools/usb/unittests/Documentation/unittests-setup | 127 ++ .../0001-Add-support-to-USB3-descriptors.patch | 420 ++++ ...2-Add-support-for-libusb_get_device_speed.patch | 172 ++ .../libusb_patches/0003-Add-UAS-defines.patch | 56 + tools/usb/unittests/make/Makefile | 132 ++ tools/usb/unittests/make/autoconfig.sh | 118 ++ tools/usb/unittests/usb/UASP_CMD_tests.cc | 2140 ++++++++++++++++++++ tools/usb/unittests/usb/UASP_TM_tests.cc | 1207 +++++++++++ tools/usb/unittests/usb/UASP_tests.h | 434 ++++ tools/usb/unittests/usb/composite_tests.cc | 1646 +++++++++++++++ tools/usb/unittests/usb/composite_tests.h | 65 + tools/usb/unittests/usb/g_serial_tests.cc | 198 ++ tools/usb/unittests/usb/g_serial_tests.h | 68 + tools/usb/unittests/usb/hs_expected_desc.h | 164 ++ tools/usb/unittests/usb/libusb_utils.cc | 358 ++++ tools/usb/unittests/usb/libusb_utils.h | 149 ++ tools/usb/unittests/usb/ss_expected_desc.h | 291 +++ tools/usb/unittests/usb/streams_tests.cc | 243 +++ tools/usb/unittests/usb/streams_tests.h | 51 + tools/usb/unittests/usb/usb_devel_mode.cc | 185 ++ tools/usb/unittests/usb/usb_devel_mode.h | 50 + tools/usb/unittests/usb/usb_tests.cc | 651 ++++++ tools/usb/unittests/usb/usb_tests.h | 146 ++ tools/usb/unittests/usb/usb_tests_main.cc | 83 + tools/usb/unittests/usb/ut_config.h | 89 + 28 files changed, 9836 insertions(+), 0 deletions(-) create mode 100644 tools/usb/unittests/Documentation/autoconfig_readme create mode 100644 tools/usb/unittests/Documentation/create-gadget-img create mode 100644 tools/usb/unittests/Documentation/unittests-info create mode 100644 tools/usb/unittests/Documentation/unittests-setup create mode 100644 tools/usb/unittests/libusb_patches/0001-Add-support-to-USB3-descriptors.patch create mode 100644 tools/usb/unittests/libusb_patches/0002-Add-support-for-libusb_get_device_speed.patch create mode 100644 tools/usb/unittests/libusb_patches/0003-Add-UAS-defines.patch create mode 100644 tools/usb/unittests/make/Makefile create mode 100644 tools/usb/unittests/make/autoconfig.sh create mode 100644 tools/usb/unittests/usb/UASP_CMD_tests.cc create mode 100644 tools/usb/unittests/usb/UASP_TM_tests.cc create mode 100644 tools/usb/unittests/usb/UASP_tests.h create mode 100644 tools/usb/unittests/usb/composite_tests.cc create mode 100644 tools/usb/unittests/usb/composite_tests.h create mode 100644 tools/usb/unittests/usb/g_serial_tests.cc create mode 100644 tools/usb/unittests/usb/g_serial_tests.h create mode 100644 tools/usb/unittests/usb/hs_expected_desc.h create mode 100644 tools/usb/unittests/usb/libusb_utils.cc create mode 100644 tools/usb/unittests/usb/libusb_utils.h create mode 100644 tools/usb/unittests/usb/ss_expected_desc.h create mode 100644 tools/usb/unittests/usb/streams_tests.cc create mode 100644 tools/usb/unittests/usb/streams_tests.h create mode 100644 tools/usb/unittests/usb/usb_devel_mode.cc create mode 100644 tools/usb/unittests/usb/usb_devel_mode.h create mode 100644 tools/usb/unittests/usb/usb_tests.cc create mode 100644 tools/usb/unittests/usb/usb_tests.h create mode 100644 tools/usb/unittests/usb/usb_tests_main.cc create mode 100644 tools/usb/unittests/usb/ut_config.h
--
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
PATCH 1/3 usb unittests framework: test files
This patch includes the tests that should be compiled with the GoogleTest framework.
--- tools/usb/unittests/make/Makefile | 132 ++ tools/usb/unittests/make/autoconfig.sh | 118 ++ tools/usb/unittests/usb/UASP_CMD_tests.cc | 2140 ++++++++++++++++++++++++++++ tools/usb/unittests/usb/UASP_TM_tests.cc | 1207 ++++++++++++++++ tools/usb/unittests/usb/UASP_tests.h | 434 ++++++ tools/usb/unittests/usb/composite_tests.cc | 1646 +++++++++++++++++++++ tools/usb/unittests/usb/composite_tests.h | 65 + tools/usb/unittests/usb/g_serial_tests.cc | 198 +++ tools/usb/unittests/usb/g_serial_tests.h | 68 + tools/usb/unittests/usb/hs_expected_desc.h | 164 +++ tools/usb/unittests/usb/libusb_utils.cc | 358 +++++ tools/usb/unittests/usb/libusb_utils.h | 149 ++ tools/usb/unittests/usb/ss_expected_desc.h | 291 ++++ tools/usb/unittests/usb/streams_tests.cc | 243 ++++ tools/usb/unittests/usb/streams_tests.h | 51 + tools/usb/unittests/usb/usb_devel_mode.cc | 185 +++ tools/usb/unittests/usb/usb_devel_mode.h | 50 + tools/usb/unittests/usb/usb_tests.cc | 651 +++++++++ tools/usb/unittests/usb/usb_tests.h | 146 ++ tools/usb/unittests/usb/usb_tests_main.cc | 83 ++ tools/usb/unittests/usb/ut_config.h | 89 ++ 21 files changed, 8468 insertions(+), 0 deletions(-) create mode 100644 tools/usb/unittests/make/Makefile create mode 100644 tools/usb/unittests/make/autoconfig.sh create mode 100644 tools/usb/unittests/usb/UASP_CMD_tests.cc create mode 100644 tools/usb/unittests/usb/UASP_TM_tests.cc create mode 100644 tools/usb/unittests/usb/UASP_tests.h create mode 100644 tools/usb/unittests/usb/composite_tests.cc create mode 100644 tools/usb/unittests/usb/composite_tests.h create mode 100644 tools/usb/unittests/usb/g_serial_tests.cc create mode 100644 tools/usb/unittests/usb/g_serial_tests.h create mode 100644 tools/usb/unittests/usb/hs_expected_desc.h create mode 100644 tools/usb/unittests/usb/libusb_utils.cc create mode 100644 tools/usb/unittests/usb/libusb_utils.h create mode 100644 tools/usb/unittests/usb/ss_expected_desc.h create mode 100644 tools/usb/unittests/usb/streams_tests.cc create mode 100644 tools/usb/unittests/usb/streams_tests.h create mode 100644 tools/usb/unittests/usb/usb_devel_mode.cc create mode 100644 tools/usb/unittests/usb/usb_devel_mode.h create mode 100644 tools/usb/unittests/usb/usb_tests.cc create mode 100644 tools/usb/unittests/usb/usb_tests.h create mode 100644 tools/usb/unittests/usb/usb_tests_main.cc create mode 100644 tools/usb/unittests/usb/ut_config.h
tools/usb/unittests/make/Makefile new file +132 -0
@@ -0,0 +1,132 @@ +# A Makefile for building Google Test and USB30 tests. +# +# SYNOPSIS: +# +# make [all] - makes everything. +# make TARGET - makes the given target. +# make clean - removes all files generated by make. +# +# Befor building the code the folowing env. variables needs to be set: +# GTEST - Pointer to the root of Google Tests +# KERNEL - Pointer to the Kernel code the test are about to be ran on +# + +# Points to the root of Google Test, relative to where this file is. +GTEST_DIR = $(GTEST) + +# Where to find usb tests code. +USER_DIR = ../usb + +# Where to find kernel code. +KERNEL_DIR = $(KERNEL) + +USB_INC_DIR = $(KERNEL_DIR)/include/linux/usb + +LINUX_INC_DIR = $(KERNEL_DIR)/arch/x86/include/asm + +# Flags passed to the preprocessor. +CPPFLAGS += -I$(GTEST_DIR) -I$(GTEST_DIR)/include -I$(LIBUSB_INC) +CPPFLAGS += -I$(KERNEL_DIR)/include +#CPPFLAGS += -I$(KERNEL_DIR)/arch/x86/include + +# Flags passed to the C++ compiler. +CXXFLAGS += -g -Wall -Wextra -m32 + +LIBUSB_LIB = $(LIBUSB)/lib +LFLAGS = -L/usr/lib32 -lstdc++ -L$(LIBUSB_LIB) -lusb-1.0 -lpthread + +# All tests produced by this Makefile. Remember to add new tests you +# created to the list. +TESTS = usb_tests + + +# All Google Test headers. Usually you shouldn't change this +# definition. +GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \ + $(GTEST_DIR)/include/gtest/internal/*.h + + +KERNEL_HEADERS = $(USB_INC_DIR)/*.h + + +LIBUSB_INC = $(LIBUSB)/include/libusb-1.0 +LIBUSB_HEADERS = $(LIBUSB_INC)/libusb.h + +# House-keeping build targets. + +all : $(TESTS) + +clean : + rm -f $(TESTS) gtest.a gtest_main.a *.o + +# Builds gtest.a and gtest_main.a. + +# Usually you shouldn't tweak such internal variables, indicated by a +# trailing _. +GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS) + +# For simplicity and to avoid depending on Google Test's +# implementation details, the dependencies specified below are +# conservative and not optimized. This is fine as Google Test +# compiles fast and for ordinary users its source rarely changes. +gtest-all.o : $(GTEST_SRCS_) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(GTEST_DIR)/src/gtest-all.cc + +gtest_main.o : $(GTEST_SRCS_) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(GTEST_DIR)/src/gtest_main.cc + +gtest.a : gtest-all.o + $(AR) $(ARFLAGS) $@ $^ + +gtest_main.a : gtest-all.o gtest_main.o + $(AR) $(ARFLAGS) $@ $^ + +# Builds a sample test. A test should link with either gtest.a or +# gtest_main.a, depending on whether it defines its own main() +# function. + +libusb_utils.o : $(USER_DIR)/libusb_utils.cc \ + $(USER_DIR)/libusb_utils.h $(KERNEL_HEADERS) \ + $(GTEST_HEADERS) $(LIBUSB_HEADERS) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/libusb_utils.cc + +composite_tests.o : $(USER_DIR)/composite_tests.cc \ + $(USER_DIR)/composite_tests.h $(KERNEL_HEADERS) \ + $(GTEST_HEADERS) $(LIBUSB_HEADERS) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/composite_tests.cc + +g_serial_tests.o : $(USER_DIR)/g_serial_tests.cc \ + $(USER_DIR)/g_serial_tests.h $(KERNEL_HEADERS) \ + $(GTEST_HEADERS) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/g_serial_tests.cc + +streams_tests.o : $(USER_DIR)/streams_tests.cc \ + $(USER_DIR)/streams_tests.h $(KERNEL_HEADERS) \ + $(GTEST_HEADERS) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/streams_tests.cc + +UASP_CMD_tests.o : $(USER_DIR)/UASP_CMD_tests.cc \ + $(USER_DIR)/UASP_tests.h $(KERNEL_HEADERS) \ + $(GTEST_HEADERS) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/UASP_CMD_tests.cc + + +UASP_TM_tests.o : $(USER_DIR)/UASP_TM_tests.cc \ + $(USER_DIR)/UASP_tests.h $(KERNEL_HEADERS) \ + $(GTEST_HEADERS) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/UASP_TM_tests.cc + +usb_tests.o : $(USER_DIR)/usb_tests.cc $(GTEST_HEADERS) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/usb_tests.cc + +usb_tests_main.o : $(USER_DIR)/usb_tests_main.cc $(GTEST_HEADERS) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/usb_tests_main.cc + +usb_devel_mode.o : $(USER_DIR)/usb_devel_mode.cc $(GTEST_HEADERS) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/usb_devel_mode.cc + +usb_tests : g_serial_tests.o usb_tests.o usb_tests_main.o gtest.a \ + composite_tests.o libusb_utils.o usb_devel_mode.o UASP_CMD_tests.o \ + UASP_TM_tests.o streams_tests.o + $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LFLAGS) $^ -o $@ +
tools/usb/unittests/make/autoconfig.sh new file +118 -0
119 lines not on this page · raw message
tools/usb/unittests/usb/UASP_CMD_tests.cc new file +2140 -0
2,140 lines not on this page · raw message
tools/usb/unittests/usb/UASP_TM_tests.cc new file +1207 -0
609 lines not on this page · raw message
tools/usb/unittests/usb/UASP_tests.h new file +434 -0
434 lines not on this page · raw message
tools/usb/unittests/usb/composite_tests.cc new file +1646 -0
1,646 lines not on this page · raw message
tools/usb/unittests/usb/composite_tests.h new file +65 -0
65 lines not on this page · raw message
tools/usb/unittests/usb/g_serial_tests.cc new file +198 -0
198 lines not on this page · raw message
tools/usb/unittests/usb/g_serial_tests.h new file +68 -0
68 lines not on this page · raw message
tools/usb/unittests/usb/hs_expected_desc.h new file +164 -0
164 lines not on this page · raw message
tools/usb/unittests/usb/libusb_utils.cc new file +358 -0
358 lines not on this page · raw message
tools/usb/unittests/usb/libusb_utils.h new file +149 -0
149 lines not on this page · raw message
tools/usb/unittests/usb/ss_expected_desc.h new file +291 -0
291 lines not on this page · raw message
tools/usb/unittests/usb/streams_tests.cc new file +243 -0
243 lines not on this page · raw message
tools/usb/unittests/usb/streams_tests.h new file +51 -0
51 lines not on this page · raw message
tools/usb/unittests/usb/usb_devel_mode.cc new file +185 -0
185 lines not on this page · raw message
tools/usb/unittests/usb/usb_devel_mode.h new file +50 -0
50 lines not on this page · raw message
tools/usb/unittests/usb/usb_tests.cc new file +651 -0
651 lines not on this page · raw message
tools/usb/unittests/usb/usb_tests.h new file +146 -0
146 lines not on this page · raw message
tools/usb/unittests/usb/usb_tests_main.cc new file +83 -0
83 lines not on this page · raw message
tools/usb/unittests/usb/ut_config.h new file +89 -0
89 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 5 lines
1.7.0.4 -- Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Part of the diff is not shown here. View the raw message.
PATCH 2/3 usb unittests framework: Documentation
In reply to Tatyana Brokhman--- .../usb/unittests/Documentation/autoconfig_readme | 20 + .../usb/unittests/Documentation/create-gadget-img | 47 ++ tools/usb/unittests/Documentation/unittests-info | 526 ++++++++++++++++++++ tools/usb/unittests/Documentation/unittests-setup | 127 +++++ 4 files changed, 720 insertions(+), 0 deletions(-) create mode 100644 tools/usb/unittests/Documentation/autoconfig_readme create mode 100644 tools/usb/unittests/Documentation/create-gadget-img create mode 100644 tools/usb/unittests/Documentation/unittests-info create mode 100644 tools/usb/unittests/Documentation/unittests-setup
tools/usb/unittests/Documentation/autoconfig_readme new file +20 -0
@@ -0,0 +1,20 @@ + +Questions can be refereed to [email protected] +Copyright (C) 2011 Code Aurora Forum. All rights reserved + +Description +----------- +This script is used to automatically configure the kernel .config file +(instead of using menuconfig). +This script should be ran after using defconfig. + +Please note that the script modifies the .config file under out-32 (and +should be executed in the out-32 directory). + +The script activates the dummy_HCD controller and configures the gadget +to operate in a SS mode. + +-- +Created by a consultant of the Qualcomm Innovation Center, Inc. +The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum. +
tools/usb/unittests/Documentation/create-gadget-img new file +47 -0
48 lines not on this page · raw message
tools/usb/unittests/Documentation/unittests-info new file +526 -0
527 lines not on this page · raw message
tools/usb/unittests/Documentation/unittests-setup new file +127 -0
127 lines not on this page · raw message
Signature · 9 lines
1.7.0.4 -- Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum. -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 3/3 usb unitests framework: libusb patches
In reply to Tatyana BrokhmanThis patch includes patches that should be applied to the latest libusb tree. They have not been released to the libusb tree formally just yet.
--- .../0001-Add-support-to-USB3-descriptors.patch | 420 ++++++++++++++++++++ ...2-Add-support-for-libusb_get_device_speed.patch | 172 ++++++++ .../libusb_patches/0003-Add-UAS-defines.patch | 56 +++ 3 files changed, 648 insertions(+), 0 deletions(-) create mode 100644 tools/usb/unittests/libusb_patches/0001-Add-support-to-USB3-descriptors.patch create mode 100644 tools/usb/unittests/libusb_patches/0002-Add-support-for-libusb_get_device_speed.patch create mode 100644 tools/usb/unittests/libusb_patches/0003-Add-UAS-defines.patch
tools/usb/unittests/libusb_patches/0001-Add-support-to-USB3-descriptors.patch new file +420 -0
@@ -0,0 +1,420 @@ +From fcc8bb8ea6a326a2c84e92b29004e8e3896925b7 Mon Sep 17 00:00:00 2001 +From: Maya Erez <[email protected]> +Date: Sun, 13 Mar 2011 22:01:07 +0200 +Subject: [PATCH 1/4] Add support to USB3 descriptors + +Add definitions for Endpoint Companion and BOS descriptors. +Add APIs for parsing the Endpoint Companion and BOS descriptors. + +Signed-off-by: Maya Erez <[email protected]> + +--- + libusb/descriptor.c | 160 +++++++++++++++++++++++++++++++++++++++++++++++--- + libusb/libusb.h | 115 ++++++++++++++++++++++++++++++++++++- + 2 files changed, 264 insertions(+), 11 deletions(-) + +diff --git a/libusb/descriptor.c b/libusb/descriptor.c +index 11480e8..0ce6975 100644 +--- a/libusb/descriptor.c ++++ b/libusb/descriptor.c +@@ -22,6 +22,7 @@ + #include <stdint.h> + #include <stdlib.h> + #include <string.h> ++#include <stdio.h> + + #include "libusbi.h" + +@@ -45,6 +46,7 @@ int usbi_parse_descriptor(unsigned char *source, const char *descriptor, + unsigned char *sp = source, *dp = dest; + uint16_t w; + const char *cp; ++ uint32_t d; + + for (cp = descriptor; *cp; cp++) { + switch (*cp) { +@@ -63,6 +65,21 @@ int usbi_parse_descriptor(unsigned char *source, const char *descriptor, + sp += 2; + dp += 2; + break; ++ /* 32-bit word, convert from little endian to CPU */ ++ case 'd': ++ /* Align to word boundary */ ++ dp += ((unsigned long)dp & 1); ++ ++ if (host_endian) { ++ memcpy(dp, sp, 4); ++ } else { ++ d = (sp[3] << 24) | (sp[2] << 16) | ++ (sp[1] << 8) | sp[0]; ++ *((uint32_t *)dp) = d; ++ } ++ sp += 4; ++ dp += 4; ++ break; + } + } + +@@ -75,6 +92,39 @@ static void clear_endpoint(struct libusb_endpoint_descriptor *endpoint) + free((unsigned char *) endpoint->extra); + } + ++static int parse_endpoint_comp(struct libusb_context *ctx, ++ struct libusb_ss_ep_comp_descriptor *ep_comp, ++ unsigned char *buffer, int size) ++{ ++ struct usb_descriptor_header header; ++ int parsed = 0; ++ ++ usbi_parse_descriptor(buffer, "bb", &header, 0); ++ ++ /* Everything should be fine being passed into here, but we sanity */ ++ /* check JIC */ ++ if (header.bLength > size) { ++ usbi_err(ctx, "ran out of descriptors parsing"); ++ return LIBUSB_ERROR_NO_MEM; ++ } ++ ++ if (header.bDescriptorType != LIBUSB_DT_SS_ENDPOINT_COMP) { ++ usbi_err(ctx, "unexpected descriptor %x (expected %x)", ++ header.bDescriptorType, LIBUSB_DT_SS_ENDPOINT_COMP); ++ return parsed; ++ } ++ ++ if (header.bLength >= LIBUSB_DT_SS_EP_COMP_SIZE) ++ usbi_parse_descriptor(buffer, "bbbbw", ep_comp, 0); ++ ++ buffer += header.bLength; ++ size -= header.bLength; ++ parsed += header.bLength; ++ ++ return parsed; ++} ++ ++ + static int parse_endpoint(struct libusb_context *ctx, + struct libusb_endpoint_descriptor *endpoint, unsigned char *buffer, + int size, int host_endian) +@@ -83,7 +133,7 @@ static int parse_endpoint(struct libusb_context *ctx, + unsigned char *extra; + unsigned char *begin; + int parsed = 0; +- int len; ++ int len, retval; + + usbi_parse_descriptor(buffer, "bb", &header, 0); + +@@ -109,6 +159,28 @@ static int parse_endpoint(struct libusb_context *ctx, + size -= header.bLength; + parsed += header.bLength; + ++ /* check if we have a Comapnion descriptor */ ++ usbi_parse_descriptor(buffer, "bb", &header, 0); ++ if (header.bDescriptorType == LIBUSB_DT_SS_ENDPOINT_COMP) { ++ endpoint->ep_comp = (struct libusb_ss_ep_comp_descriptor *) ++ malloc(sizeof(struct libusb_ss_ep_comp_descriptor)); ++ if (!endpoint->ep_comp) { ++ usbi_err(ctx, "couldn't allocate memory for ep_comp"); ++ return LIBUSB_ERROR_NO_MEM; ++ } ++ ++ memset(endpoint->ep_comp, 0, ++ sizeof(struct libusb_ss_ep_comp_descriptor)); ++ retval = parse_endpoint_comp(ctx, endpoint->ep_comp, ++ buffer, size); ++ if (retval < 0) ++ return retval; ++ ++ buffer += retval; ++ parsed += retval; ++ size -= retval; ++ } ++ + /* Skip over the rest of the Class Specific or Vendor Specific */ + /* descriptors */ + begin = buffer; +@@ -122,9 +194,10 @@ static int parse_endpoint(struct libusb_context *ctx, + + /* If we find another "proper" descriptor then we're done */ + if ((header.bDescriptorType == LIBUSB_DT_ENDPOINT) || +- (header.bDescriptorType == LIBUSB_DT_INTERFACE) || +- (header.bDescriptorType == LIBUSB_DT_CONFIG) || +- (header.bDescriptorType == LIBUSB_DT_DEVICE)) ++ (header.bDescriptorType == LIBUSB_DT_INTERFACE) || ++ (header.bDescriptorType == LIBUSB_DT_CONFIG) || ++ (header.bDescriptorType == LIBUSB_DT_DEVICE) || ++ (header.bDescriptorType == LIBUSB_DT_SS_ENDPOINT_COMP)) + break; + + usbi_dbg("skipping descriptor %x", header.bDescriptorType); +@@ -233,9 +306,11 @@ static int parse_interface(libusb_context *ctx, + + /* If we find another "proper" descriptor then we're done */ + if ((header.bDescriptorType == LIBUSB_DT_INTERFACE) || +- (header.bDescriptorType == LIBUSB_DT_ENDPOINT) || +- (header.bDescriptorType == LIBUSB_DT_CONFIG) || +- (header.bDescriptorType == LIBUSB_DT_DEVICE)) ++ (header.bDescriptorType == LIBUSB_DT_ENDPOINT) || ++ (header.bDescriptorType == LIBUSB_DT_CONFIG) || ++ (header.bDescriptorType == LIBUSB_DT_DEVICE) || ++ (header.bDescriptorType == ++ LIBUSB_DT_SS_ENDPOINT_COMP)) + break; + + buffer += header.bLength; +@@ -379,9 +454,11 @@ static int parse_configuration(struct libusb_context *ctx, + + /* If we find another "proper" descriptor then we're done */ + if ((header.bDescriptorType == LIBUSB_DT_ENDPOINT) || +- (header.bDescriptorType == LIBUSB_DT_INTERFACE) || +- (header.bDescriptorType == LIBUSB_DT_CONFIG) || +- (header.bDescriptorType == LIBUSB_DT_DEVICE)) ++ (header.bDescriptorType == LIBUSB_DT_INTERFACE) || ++ (header.bDescriptorType == LIBUSB_DT_CONFIG) || ++ (header.bDescriptorType == LIBUSB_DT_DEVICE) || ++ (header.bDescriptorType == ++ LIBUSB_DT_SS_ENDPOINT_COMP)) + break; + + usbi_dbg("skipping descriptor 0x%x\n", header.bDescriptorType); +@@ -726,3 +803,66 @@ int API_EXPORTED libusb_get_string_descriptor_ascii(libusb_device_handle *dev, + return di; + } + ++ ++/** \ingroup desc ++ * Get the USB bos descriptor for a given device. ++ * ++ * \param dev the device ++ * \param bos output bos descriptor ++ * \returns 0 on success ++ */ ++API_EXPORTED int libusb_parse_bos_desc(struct libusb_device *dev, ++ struct libusb_bos_descriptor *bos, ++ unsigned char *buf) ++{ ++ int i; ++ int desc_begin = 0; ++ ++ usbi_parse_descriptor(buf, "bbwb", bos, 0); ++ desc_begin = LIBUSB_DT_BOS_SIZE; ++ ++ /* Get the device capability descriptors */ ++ for (i = 0; i < bos->bNumDeviceCaps; ++i) { ++ if (buf[desc_begin+2] == LIBUSB_USB_CAP_TYPE_EXT) { ++ if (!bos->usb_ext_cap) { ++ bos->usb_ext_cap = ++ (struct libusb_usb_ext_cap_descriptor *) ++ malloc(sizeof(struct ++ libusb_usb_ext_cap_descriptor)); ++ usbi_parse_descriptor(buf+desc_begin, "bbbd", ++ bos->usb_ext_cap, 0); ++ } else ++ usbi_warn(dev->ctx, ++ "usb_ext_cap was already allocated"); ++ ++ /* move to the next device capability descriptor */ ++ desc_begin += LIBUSB_DT_USB_CAP_TYPE_EXT_SIZE; ++ } else if (buf[desc_begin+2] == LIBUSB_SS_USB_CAP_TYPE) { ++ if (!bos->ss_usb_cap) { ++ bos->ss_usb_cap = ++ (struct libusb_ss_usb_cap_descriptor *) ++ malloc(sizeof(struct ++ libusb_ss_usb_cap_descriptor)); ++ ++ usbi_parse_descriptor(buf+desc_begin, ++ "bbbbwbbw", ++ bos->ss_usb_cap, 0); ++ } else ++ usbi_warn(dev->ctx, ++ "ss_usb_cap was already allocated"); ++ ++ /* move to the next device capability descriptor */ ++ desc_begin += LIBUSB_DT_SS_USB_CAP_TYPE_SIZE; ++ } else { ++ usbi_info(dev->ctx, ++ "wireless/container_id capability " ++ "descriptor"); ++ ++ /* move to the next device capability descriptor */ ++ desc_begin += buf[desc_begin]; ++ } ++ } ++ return 0; ++} ++ ++ +diff --git a/libusb/libusb.h b/libusb/libusb.h +index 8dc3362..9f2243a 100644 +--- a/libusb/libusb.h ++++ b/libusb/libusb.h +@@ -191,7 +191,16 @@ enum libusb_descriptor_type { + LIBUSB_DT_PHYSICAL = 0x23, + + /** Hub descriptor */ +- LIBUSB_DT_HUB = 0x29 ++ LIBUSB_DT_HUB = 0x29, ++ ++ /** BOS descriptor */ ++ LIBUSB_DT_BOS = 0x0f, ++ ++ /** Device Capability descriptor */ ++ LIBUSB_DT_DEVICE_CAPABILITY = 0x10, ++ ++ /** SuperSpeed Endpoint Companion descriptor */ ++ LIBUSB_DT_SS_ENDPOINT_COMP = 0x30 + }; + + /* Descriptor sizes per descriptor type */ +@@ -201,6 +210,13 @@ enum libusb_descriptor_type { + #define LIBUSB_DT_ENDPOINT_SIZE 7 + #define LIBUSB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */ + #define LIBUSB_DT_HUB_NONVAR_SIZE 7 ++#define LIBUSB_DT_SS_EP_COMP_SIZE 6 ++#define LIBUSB_DT_BOS_SIZE 5 ++#define LIBUSB_DT_USB_CAP_TYPE_EXT_SIZE 7 ++#define LIBUSB_DT_SS_USB_CAP_TYPE_SIZE 10 ++#define LIBUSB_DT_BOS_MAX_SIZE ((LIBUSB_DT_BOS_SIZE) + \ ++ (LIBUSB_DT_USB_CAP_TYPE_EXT_SIZE) + \ ++ (LIBUSB_DT_SS_USB_CAP_TYPE_SIZE)) + + #define LIBUSB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */ + #define LIBUSB_ENDPOINT_DIR_MASK 0x80 +@@ -407,6 +423,33 @@ struct libusb_device_descriptor { + uint8_t bNumConfigurations; + }; + ++/* USB_DT_SS_ENDPOINT_COMP: SuperSpeed Endpoint Companion descriptor */ ++struct libusb_ss_ep_comp_descriptor { ++ ++ /** Size of this descriptor (in bytes) */ ++ u_int8_t bLength; ++ ++ /** Descriptor type. Will have value ++ * \ref libusb_descriptor_type::LIBUSB_DT_SS_ENDPOINT_COMP in ++ * this context. */ ++ u_int8_t bDescriptorType; ++ ++ ++ /** The maximum number of packets the endpoint can send or ++ * recieve as part of a burst. */ ++ u_int8_t bMaxBurst; ++ ++ /** In bulk EP: bits 4:0 represents the maximum number of ++ * streams the EP supports. In isochronous EP: bits 1:0 ++ * represents the Mult - a zero based value that determines ++ * the maximum number of packets within a service interval */ ++ u_int8_t bmAttributes; ++ ++ /** The total number of bytes this EP will transfer every ++ * service interval. valid only for periodic EPs. */ ++ u_int16_t wBytesPerInterval; ++}; ++ + /** \ingroup desc + * A structure representing the standard USB endpoint descriptor. This + * descriptor is documented in section 9.6.3 of the USB 2.0 specification. +@@ -449,6 +492,9 @@ struct libusb_endpoint_descriptor { + /** For audio devices only: the address if the synch endpoint */ + uint8_t bSynchAddress; + ++ /** The EP companion descriptor */ ++ struct libusb_ss_ep_comp_descriptor *ep_comp; ++ + /** Extra descriptors. If libusb encounters unknown endpoint descriptors, + * it will store them here, should you wish to parse them. */ + const unsigned char *extra; +@@ -457,6 +503,7 @@ struct libusb_endpoint_descriptor { + int extra_length; + }; + ++ + /** \ingroup desc + * A structure representing the standard USB interface descriptor. This + * descriptor is documented in section 9.6.5 of the USB 2.0 specification. +@@ -565,6 +612,60 @@ struct libusb_config_descriptor { + int extra_length; + }; + ++/** \ingroup desc ++ * A structure representing the BOS descriptor. This ++ * descriptor is documented in section 9.6.2 of the USB 3.0 ++ * specification. All multiple-byte fields are represented in ++ * host-endian format. ++ */ ++struct libusb_bos_descriptor { ++ u_int8_t bLength; ++ u_int8_t bDescriptorType; ++ u_int16_t wTotalLength; ++ u_int8_t bNumDeviceCaps; ++ ++ struct libusb_usb_ext_cap_descriptor *usb_ext_cap; ++ struct libusb_ss_usb_cap_descriptor *ss_usb_cap; ++}; ++ ++ ++struct libusb_dev_cap_header { ++ u_int8_t bLength; ++ u_int8_t bDescriptorType; ++ u_int8_t bDevCapabilityType; ++}; ++ ++ ++#define LIBUSB_USB_CAP_TYPE_EXT 2 ++ ++struct libusb_usb_ext_cap_descriptor { /* Link Power Management */ ++ u_int8_t bLength; ++ u_int8_t bDescriptorType; ++ u_int8_t bDevCapabilityType; ++ u_int32_t bmAttributes; ++#define LIBUSB_LPM_SUPPORT (1 << 1) /* supports LPM */ ++}; ++ ++ ++#define LIBUSB_SS_USB_CAP_TYPE 3 ++ ++struct libusb_ss_usb_cap_descriptor { /* Link Power Management */ ++ u_int8_t bLength; ++ u_int8_t bDescriptorType; ++ u_int8_t bDevCapabilityType; ++ u_int8_t bmAttributes; ++#define LIBUSB_LPM_SUPPORT (1 << 1) /* supports LPM */ ++ u_int16_t wSpeedSupported; ++#define LIBUSB_LOW_SPEED_OPERATION (1) /* Low speed operation */ ++#define LIBUSB_FULL_SPEED_OPERATION (1 << 1)/* Full speed operation */ ++#define LIBUSB_HIGH_SPEED_OPERATION (1 << 2)/* High speed operation */ ++#define LIBUSB_5GBPS_OPERATION (1 << 3)/* Operation at 5Gbps */ ++ u_int8_t bFunctionalitySupport; ++ u_int8_t bU1devExitLat; ++ u_int16_t bU2DevExitLat; ++}; ++ ++ + /** \ingroup asyncio + * Setup packet for control transfers. */ + struct libusb_control_setup { +@@ -1315,6 +1416,18 @@ void LIBUSB_CALL libusb_set_pollfd_notifiers(libusb_context *ctx, + libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb, + void *user_data); + ++ ++/** \ingroup desc ++ * Get the USB bos descriptor for a given device. ++ * ++ * \param dev the device ++ * \param bos output bos descriptor ++ * \returns 0 on success ++ */ ++int libusb_parse_bos_desc(struct libusb_device *dev, ++ struct libusb_bos_descriptor *bos, ++ unsigned char *buf); ++ + #ifdef __cplusplus + } + #endif +-- +1.7.3.3 + +-- +Sent by an employee of the Qualcomm Innovation Center, Inc. +The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
tools/usb/unittests/libusb_patches/0002-Add-support-for-libusb_get_device_speed.patch new file +172 -0
173 lines not on this page · raw message
tools/usb/unittests/libusb_patches/0003-Add-UAS-defines.patch new file +56 -0
57 lines not on this page · raw message
Signature · 5 lines
1.7.0.4 -- Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.