usbtest.c (9d3bd7684645834ede59d285af1d70ccabee9bf3) | usbtest.c (82f92672ac3e36458fdb298f798913da8460fce9) |
---|---|
1#include <linux/kernel.h> 2#include <linux/errno.h> 3#include <linux/init.h> 4#include <linux/slab.h> 5#include <linux/mm.h> 6#include <linux/module.h> 7#include <linux/moduleparam.h> 8#include <linux/scatterlist.h> --- 592 unchanged lines hidden (view full) --- 601 if (le16_to_cpu(config->wTotalLength) == len) /* read it all */ 602 return 1; 603 if (le16_to_cpu(config->wTotalLength) >= TBUF_SIZE) /* max partial read */ 604 return 1; 605 ERROR(tdev, "bogus config descriptor read size\n"); 606 return 0; 607} 608 | 1#include <linux/kernel.h> 2#include <linux/errno.h> 3#include <linux/init.h> 4#include <linux/slab.h> 5#include <linux/mm.h> 6#include <linux/module.h> 7#include <linux/moduleparam.h> 8#include <linux/scatterlist.h> --- 592 unchanged lines hidden (view full) --- 601 if (le16_to_cpu(config->wTotalLength) == len) /* read it all */ 602 return 1; 603 if (le16_to_cpu(config->wTotalLength) >= TBUF_SIZE) /* max partial read */ 604 return 1; 605 ERROR(tdev, "bogus config descriptor read size\n"); 606 return 0; 607} 608 |
609static 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 610 * of the utility functions which use it. 611 * 612 * this doesn't test how endpoint halts behave or data toggles get set, since 613 * we won't do I/O to bulk/interrupt endpoints here (which is how to change 614 * halt or toggle). toggle testing is impractical without support from hcds. 615 * 616 * this avoids failing devices linux would normally work with, by not testing --- 72 unchanged lines hidden (view full) --- 689 return (retval < 0) ? retval : -EDOM; 690 } 691 692 /* 693 * there's always [9.4.3] a bos device descriptor [9.6.2] in USB 694 * 3.0 spec 695 */ 696 if (le16_to_cpu(udev->descriptor.bcdUSB) >= 0x0300) { | 631/* sanity test for standard requests working with usb_control_mesg() and some 632 * of the utility functions which use it. 633 * 634 * this doesn't test how endpoint halts behave or data toggles get set, since 635 * we won't do I/O to bulk/interrupt endpoints here (which is how to change 636 * halt or toggle). toggle testing is impractical without support from hcds. 637 * 638 * this avoids failing devices linux would normally work with, by not testing --- 72 unchanged lines hidden (view full) --- 711 return (retval < 0) ? retval : -EDOM; 712 } 713 714 /* 715 * there's always [9.4.3] a bos device descriptor [9.6.2] in USB 716 * 3.0 spec 717 */ 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, 698 sizeof(*udev->bos->desc)); 699 if (retval != sizeof(*udev->bos->desc)) { 700 dev_err(&iface->dev, "bos descriptor --> %d\n", retval); 701 return (retval < 0) ? retval : -EDOM; 702 } | 724 retval = usb_get_descriptor(udev, USB_DT_BOS, 0, dev->buf, 725 sizeof(*udev->bos->desc)); 726 if (retval != sizeof(*udev->bos->desc)) { 727 dev_err(&iface->dev, "bos descriptor --> %d\n", retval); 728 return (retval < 0) ? retval : -EDOM; 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 } 704 705 /* there's always [9.4.3] at least one config descriptor [9.6.3] */ 706 for (i = 0; i < udev->descriptor.bNumConfigurations; i++) { 707 retval = usb_get_descriptor(udev, USB_DT_CONFIG, i, 708 dev->buf, TBUF_SIZE); 709 if (!is_good_config(dev, retval)) { 710 dev_err(&iface->dev, --- 1846 unchanged lines hidden --- | 780 } 781 782 /* there's always [9.4.3] at least one config descriptor [9.6.3] */ 783 for (i = 0; i < udev->descriptor.bNumConfigurations; i++) { 784 retval = usb_get_descriptor(udev, USB_DT_CONFIG, i, 785 dev->buf, TBUF_SIZE); 786 if (!is_good_config(dev, retval)) { 787 dev_err(&iface->dev, --- 1846 unchanged lines hidden --- |