[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#810408: discover: please switch to libusb 1.0



Package: discover
Followup-For: Bug #810408

Hi,

Please find a patch attached here.

This seems to work on my laptop, that obviously needs more testing.

discover-static cannot be built anymore as libusb 1.0 package in debian
is not providing the static archive anymore.

Kind regards,

Laurent Bigonville

-- System Information:
Debian Release: bullseye/sid
  APT prefers unstable-debug
  APT policy: (500, 'unstable-debug'), (500, 'unstable'), (1, 'experimental-debug'), (1, 'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 4.19.0-5-amd64 (SMP w/8 CPU cores)
Locale: LANG=fr_BE.UTF-8, LC_CTYPE=fr_BE.UTF-8 (charmap=UTF-8), LANGUAGE=fr_BE:fr (charmap=UTF-8)
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages discover depends on:
ii  debconf [debconf-2.0]  1.5.72
ii  libc6                  2.28-10
ii  libdiscover2           2.1.2-8
ii  libexpat1              2.2.7-1
ii  libusb-0.1-4           2:0.1.12-32

discover recommends no packages.

Versions of packages discover suggests:
ii  lsb-base  10.2019051400

-- debconf information excluded
diff -u discover-2.1.2/configure.ac discover-2.1.2/configure.ac
--- discover-2.1.2/configure.ac
+++ discover-2.1.2/configure.ac
@@ -129,8 +129,8 @@
 AC_CHECK_LIB(expat, XML_ParserCreate, ,
              AC_MSG_ERROR([Can't find expat library.]))
 
-AC_CHECK_HEADER(usb.h, , AC_MSG_ERROR([Can't find usb.h.]))
-AC_CHECK_LIB(usb, usb_init, ,
+AC_CHECK_HEADER(libusb-1.0/libusb.h, , AC_MSG_ERROR([Can't find libusb-1.0/libusb.h.]))
+AC_CHECK_LIB(usb-1.0, libusb_init, ,
              AC_MSG_ERROR([Can't find usb library.]))
 
 # curl
diff -u discover-2.1.2/debian/control discover-2.1.2/debian/control
--- discover-2.1.2/debian/control
+++ discover-2.1.2/debian/control
@@ -3,7 +3,7 @@
 Priority: optional
 Maintainer: Debian Install System Team <debian-boot@lists.debian.org>
 Uploaders: David Nusinow <dnusinow@debian.org>, Petter Reinholdtsen <pere@debian.org>
-Build-Depends: debhelper (>= 8), libexpat1-dev, po-debconf, libusb-dev, autotools-dev
+Build-Depends: debhelper (>= 8), libexpat1-dev, po-debconf, libusb-1.0-0-dev, autotools-dev
 Standards-Version: 3.8.0
 
 Package: discover
diff -u discover-2.1.2/debian/rules discover-2.1.2/debian/rules
--- discover-2.1.2/debian/rules
+++ discover-2.1.2/debian/rules
@@ -119,7 +119,6 @@
 	install -d debian/tmp/usr/share/bug/discover
 	install -m 755 debian/discover.bug debian/tmp/usr/share/bug/discover
 
-	rm $(CURDIR)/debian/tmp/usr/bin/discover-static
 	mv $(CURDIR)/debian/tmp/usr/bin/discover \
 		$(CURDIR)/debian/tmp/sbin/discover
 
diff -u discover-2.1.2/sysdeps/linux/usb.c discover-2.1.2/sysdeps/linux/usb.c
--- discover-2.1.2/sysdeps/linux/usb.c
+++ discover-2.1.2/sysdeps/linux/usb.c
@@ -32,7 +32,7 @@
 #include <discover/sysdep.h>
 #include <discover/utils.h>
 
-#include <usb.h>
+#include <libusb-1.0/libusb.h>
 
 /*
  * This function is specific to each sysdep.
@@ -55,9 +55,8 @@
     unsigned int id;
     char class[3], subclass[3];
 
-    struct usb_bus *bus;
-    struct usb_device *dev;
-    struct usb_bus *busses;
+    libusb_device **devs = NULL;
+    ssize_t cnt;
 
     /* First try old /proc/bus/usb/devices */
     if ((f = fopen(PATH_PROC_USB, "r"))) {
@@ -96,30 +95,38 @@
         free(line);
     } else { /* if that fail, use libusb */
 
-        usb_init();
-        usb_find_busses();
-        usb_find_devices();
-        busses = usb_get_busses();
-
-        for (bus = busses; bus; bus = bus->next)
-            for (dev = bus->devices; dev; dev = dev->next) {
-                node = _discover_sysdep_data_new();
-                _discover_sysdep_init(node);
-
-                snprintf(node->vendor, 5, "%04x", dev->descriptor.idVendor);
-                snprintf(node->model, 5, "%04x", dev->descriptor.idProduct);
-                snprintf(node->busclass, 5, "%02x%02x",
-                         dev->descriptor.bDeviceClass,
-                         dev->descriptor.bDeviceSubClass);
-
-                if (head == NULL) {
-                    head = node;
-                    last = head;
-                } else {
-                    last->next = node;
-                    last = node;
-                }
+        if (libusb_init(NULL) < 0)
+            goto out;
+
+        cnt = libusb_get_device_list(NULL, &devs);
+        if (cnt < 0)
+            goto out;
+
+        for (int i = 0; devs[i]; ++i) {
+            struct libusb_device_descriptor desc;
+
+            node = _discover_sysdep_data_new();
+            _discover_sysdep_init(node);
+
+            libusb_get_device_descriptor(devs[i], &desc);
+            snprintf(node->vendor, 5, "%04x", desc.idVendor);
+            snprintf(node->model, 5, "%04x", desc.idProduct);
+            snprintf(node->busclass, 5, "%02x%02x",
+                     desc.bDeviceClass,
+                     desc.bDeviceSubClass);
+
+            if (head == NULL) {
+                head = node;
+                last = head;
+            } else {
+                last->next = node;
+                last = node;
             }
+        }
+out:
+        if (devs != NULL)
+	    libusb_free_device_list(devs, 1);
+        libusb_exit(NULL);
     }
     return head;
 }
--- discover-2.1.2.orig/discover/Makefile.in
+++ discover-2.1.2/discover/Makefile.in
@@ -1,6 +1,6 @@
 # $Progeny$
 
-all: discover discover-static
+all: discover
 
 ###############################################################################
 # Build
@@ -38,7 +38,7 @@
 install: discover
 	${INSTALL_DIR} ${DESTDIR}${bindir}
 	${INSTALL_PROGRAM} discover ${DESTDIR}${bindir}/discover
-	${INSTALL_PROGRAM} discover-static ${DESTDIR}${bindir}/discover-static
+#	${INSTALL_PROGRAM} discover-static ${DESTDIR}${bindir}/discover-static
 
 uninstall:
 	rm -f ${DESTDIR}${bindir}/discover ${DESTDIR}${bindir}/discover-static

Reply to: