diff options
author | Huang Rui <ray.huang@amd.com> | 2013-10-29 23:27:38 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-10-30 12:52:14 -0400 |
commit | 82f92672ac3e36458fdb298f798913da8460fce9 (patch) | |
tree | 6054c61485447f6e247106cf9b568cdeb364e3e2 /drivers/usb/misc/usbtest.c | |
parent | c2ec3a732a6bb65635693f6d86d2b7bf073b6148 (diff) |
usb: usbtest: support usb2 extension descriptor test
In Test 9 of usbtest module, it is used for performing chapter 9 tests N
times.
USB2.0 Extension descriptor is one of the generic device-level capbility
descriptors which added in section 9.6.2.1 of USB 3.0 spec.
This patch adds to support getting usb2.0 extension descriptor test
scenario for USB 3.0.
Signed-off-by: Huang Rui <ray.huang@amd.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb/misc/usbtest.c')
-rw-r--r-- | drivers/usb/misc/usbtest.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c index e7235d5cce85..1c78e747f72b 100644 --- a/drivers/usb/misc/usbtest.c +++ b/drivers/usb/misc/usbtest.c | |||
@@ -606,6 +606,28 @@ static int is_good_config(struct usbtest_dev *tdev, int len) | |||
606 | return 0; | 606 | return 0; |
607 | } | 607 | } |
608 | 608 | ||
609 | static int is_good_ext(struct usbtest_dev *tdev, u8 *buf) | ||
610 | { | ||
611 | struct usb_ext_cap_descriptor *ext; | ||
612 | u32 attr; | ||
613 | |||
614 | ext = (struct usb_ext_cap_descriptor *) buf; | ||
615 | |||
616 | if (ext->bLength != USB_DT_USB_EXT_CAP_SIZE) { | ||
617 | ERROR(tdev, "bogus usb 2.0 extension descriptor length\n"); | ||
618 | return 0; | ||
619 | } | ||
620 | |||
621 | attr = le32_to_cpu(ext->bmAttributes); | ||
622 | /* bits[1:4] is used and others are reserved */ | ||
623 | if (attr & ~0x1e) { /* reserved == 0 */ | ||
624 | ERROR(tdev, "reserved bits set\n"); | ||
625 | return 0; | ||
626 | } | ||
627 | |||
628 | return 1; | ||
629 | } | ||
630 | |||
609 | /* sanity test for standard requests working with usb_control_mesg() and some | 631 | /* sanity test for standard requests working with usb_control_mesg() and some |
610 | * of the utility functions which use it. | 632 | * of the utility functions which use it. |
611 | * | 633 | * |
@@ -694,12 +716,67 @@ static int ch9_postconfig(struct usbtest_dev *dev) | |||
694 | * 3.0 spec | 716 | * 3.0 spec |
695 | */ | 717 | */ |
696 | if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0300) { | 718 | if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0300) { |
719 | struct usb_bos_descriptor *bos = NULL; | ||
720 | struct usb_dev_cap_header *header = NULL; | ||
721 | unsigned total, num, length; | ||
722 | u8 *buf; | ||
723 | |||
697 | retval = usb_get_descriptor(udev, USB_DT_BOS, 0, dev->buf, | 724 | retval = usb_get_descriptor(udev, USB_DT_BOS, 0, dev->buf, |
698 | sizeof(*udev->bos->desc)); | 725 | sizeof(*udev->bos->desc)); |
699 | if (retval != sizeof(*udev->bos->desc)) { | 726 | if (retval != sizeof(*udev->bos->desc)) { |
700 | dev_err(&iface->dev, "bos descriptor --> %d\n", retval); | 727 | dev_err(&iface->dev, "bos descriptor --> %d\n", retval); |
701 | return (retval < 0) ? retval : -EDOM; | 728 | return (retval < 0) ? retval : -EDOM; |
702 | } | 729 | } |
730 | |||
731 | bos = (struct usb_bos_descriptor *)dev->buf; | ||
732 | total = le16_to_cpu(bos->wTotalLength); | ||
733 | num = bos->bNumDeviceCaps; | ||
734 | |||
735 | if (total > TBUF_SIZE) | ||
736 | total = TBUF_SIZE; | ||
737 | |||
738 | /* | ||
739 | * get generic device-level capability descriptors [9.6.2] | ||
740 | * in USB 3.0 spec | ||
741 | */ | ||
742 | retval = usb_get_descriptor(udev, USB_DT_BOS, 0, dev->buf, | ||
743 | total); | ||
744 | if (retval != total) { | ||
745 | dev_err(&iface->dev, "bos descriptor set --> %d\n", | ||
746 | retval); | ||
747 | return (retval < 0) ? retval : -EDOM; | ||
748 | } | ||
749 | |||
750 | length = sizeof(*udev->bos->desc); | ||
751 | buf = dev->buf; | ||
752 | for (i = 0; i < num; i++) { | ||
753 | buf += length; | ||
754 | if (buf + sizeof(struct usb_dev_cap_header) > | ||
755 | dev->buf + total) | ||
756 | break; | ||
757 | |||
758 | header = (struct usb_dev_cap_header *)buf; | ||
759 | length = header->bLength; | ||
760 | |||
761 | if (header->bDescriptorType != | ||
762 | USB_DT_DEVICE_CAPABILITY) { | ||
763 | dev_warn(&udev->dev, "not device capability descriptor, skip\n"); | ||
764 | continue; | ||
765 | } | ||
766 | |||
767 | switch (header->bDevCapabilityType) { | ||
768 | case USB_CAP_TYPE_EXT: | ||
769 | if (buf + USB_DT_USB_EXT_CAP_SIZE > | ||
770 | dev->buf + total || | ||
771 | !is_good_ext(dev, buf)) { | ||
772 | dev_err(&iface->dev, "bogus usb 2.0 extension descriptor\n"); | ||
773 | return -EDOM; | ||
774 | } | ||
775 | break; | ||
776 | default: | ||
777 | break; | ||
778 | } | ||
779 | } | ||
703 | } | 780 | } |
704 | 781 | ||
705 | /* there's always [9.4.3] at least one config descriptor [9.6.3] */ | 782 | /* there's always [9.4.3] at least one config descriptor [9.6.3] */ |