Add patch to work around the fact that the kernel gives us a device

descriptor with four fields (and _only_ those four fields) already
    byteswapped. This behaviour, although insane, needs to stay because
    libusb already copes with it.
This commit is contained in:
David Woodhouse 2005-01-21 18:38:19 +00:00
parent 663cbc5c2e
commit 93da4c3dcf
2 changed files with 66 additions and 1 deletions

View File

@ -0,0 +1,60 @@
--- usbutils-0.11/lsusb.c.endian 2005-01-20 08:14:23.234480568 +0000
+++ usbutils-0.11/lsusb.c 2005-01-20 08:14:34.742731048 +0000
@@ -35,6 +35,13 @@
#include <unistd.h>
#include <stdio.h>
#include <stdarg.h>
+#include <endian.h>
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+#define BE 1
+#else
+#define BE 0
+#endif
#include <linux/types.h>
#ifdef HAVE_LINUX_USBDEVICE_FS_H
@@ -290,8 +297,8 @@ static void dump_device(int fd, unsigned
printf(" Warning: Invalid descriptor\n");
else if (buf[0] < 18)
printf(" Warning: Descriptor too short\n");
- vid = buf[8] | (buf[9] << 8);
- pid = buf[10] | (buf[11] << 8);
+ vid = *(u_int16_t *)(buf+8);
+ pid = *(u_int16_t *)(buf+10);
get_vendor_string(vendor, sizeof(vendor), vid);
get_product_string(product, sizeof(product), vid, pid);
get_class_string(cls, sizeof(cls), buf[4]);
@@ -315,8 +322,8 @@ static void dump_device(int fd, unsigned
" iProduct %5u %s\n"
" iSerial %5u %s\n"
" bNumConfigurations %5u\n",
- buf[0], buf[1], buf[3], buf[2], buf[4], cls, buf[5], subcls, buf[6], proto, buf[7],
- vid, vendor, pid, product, buf[13], buf[12], buf[14], mfg, buf[15], prod, buf[16], serial, buf[17]);
+ buf[0], buf[1], buf[3-BE], buf[2+BE], buf[4], cls, buf[5], subcls, buf[6], proto, buf[7],
+ vid, vendor, pid, product, buf[13-BE], buf[12+BE], buf[14], mfg, buf[15], prod, buf[16], serial, buf[17]);
dump_junk(buf, " ", 18);
}
@@ -1575,8 +1582,8 @@ static int dump_one_device(const char *p
fprintf(stderr, "cannot get config descriptor, %s (%d)\n", strerror(errno), errno);
goto err;
}
- vid = buf[8] | (buf[9] << 8);
- pid = buf[10] | (buf[11] << 8);
+ vid = *(u_int16_t *)(buf+8);
+ pid = *(u_int16_t *)(buf+10);
get_vendor_string(vendor, sizeof(vendor), vid);
get_product_string(product, sizeof(product), vid, pid);
printf("Device: ID %04x:%04x %s %s\n", vid, pid, vendor, product);
@@ -1628,8 +1635,8 @@ static int list_devices(int bus, int dev
fprintf(stderr, "cannot read device descriptor %s (%d)\n", strerror(errno), errno);
goto err;
}
- vid = buf[8] | (buf[9] << 8);
- pid = buf[10] | (buf[11] << 8);
+ vid = *(u_int16_t *)(buf+8);
+ pid = *(u_int16_t *)(buf+10);
if (buf[0] >= USB_DT_DEVICE_SIZE && ((vendorid != -1 && vendorid != vid) || (productid != -1 && productid != pid)))
goto err;
status=0;

View File

@ -1,10 +1,11 @@
Name: usbutils
Version: 0.11
Release: 6.1
Release: 6.2
Source: http://usb.cs.tum.edu/download/%{name}-%{version}.tar.gz
Patch: usbutils-0.9-hwdata.patch
Patch2: usbutils-0214.patch
Patch3: usbutils-0.11-hidcc.patch
Patch4: usbutils-0.11-endian.patch
License: GPL
BuildRoot: %{_tmppath}/%{name}-%{version}-root
Requires: hwdata
@ -23,6 +24,7 @@ USB bus.
%patch -p1 -b .hwdata
%patch2 -p1 -b .0214
%patch3 -p1 -b .hidcc
%patch4 -p1 -b .endian
%build
cp /usr/share/libtool/config.{sub,guess} .
@ -50,6 +52,9 @@ rm -f $RPM_BUILD_ROOT%{_datadir}/usb.ids
rm -rf $RPM_BUILD_ROOT
%changelog
* Thu Jan 20 2005 David Woodhouse <dwmw2@redhat.com> 0.11-6.2
- Don't byteswap parts of device descriptor which kernel already swapped
* Mon Sep 13 2004 Thomas Woerner <twoerner@redhat.com> 0.11-6.1
- added missing BuildRequires for libtool (#132406)