Revision: 5286
          http://ipcop.svn.sourceforge.net/ipcop/?rev=5286&view=rev
Author:   owes
Date:     2010-12-29 13:49:48 +0000 (Wed, 29 Dec 2010)

Log Message:
-----------
Use libusb-1.0 in installer/setup. Old libusb is now only used for 
usb-modeswitch

Modified Paths:
--------------
    ipcop/trunk/src/installer/Makefile
    ipcop/trunk/src/installer/hardware.c

Modified: ipcop/trunk/src/installer/Makefile
===================================================================
--- ipcop/trunk/src/installer/Makefile  2010-12-28 09:07:51 UTC (rev 5285)
+++ ipcop/trunk/src/installer/Makefile  2010-12-29 13:49:48 UTC (rev 5286)
@@ -8,10 +8,10 @@
 HEADERS = arch_defs.h common.h
 SRC_HELP = helper.c
 OBJS_INST = installer.o helper.o helper_backup.o helper_newt.o hardware.o 
language.o timezone.o keymap.o partition.o restore.o usbnames.o
-LIBS_INST = -lnewt -lslang -lpci -lusb -lz
+LIBS_INST = -lnewt -lslang -lpci -lusb-1.0 -lz
 OBJS_SETUP = setup.o helper.o helper_newt.o hardware.o host_domain.o keymap.o 
passwords.o timezone.o \
        networking.o net_dhcp.o net_isdn.o usbnames.o
-LIBS_SETUP = -lnewt -lslang -lpci -lusb -lz
+LIBS_SETUP = -lnewt -lslang -lpci -lusb-1.0 -lz
 
 all: installer setup
 

Modified: ipcop/trunk/src/installer/hardware.c
===================================================================
--- ipcop/trunk/src/installer/hardware.c        2010-12-28 09:07:51 UTC (rev 
5285)
+++ ipcop/trunk/src/installer/hardware.c        2010-12-29 13:49:48 UTC (rev 
5286)
@@ -17,7 +17,7 @@
  * along with IPCop; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  *
- * (c) 2007-2009, the IPCop team
+ * (c) 2007-2010, the IPCop team
  *
  * $Id$
  * 
@@ -31,7 +31,7 @@
 #include <string.h>
 #include <unistd.h>
 
-#include "usb.h"
+#include "libusb-1.0/libusb.h"
 #include "usbnames.h"
 #include "pci/pci.h"
 
@@ -381,6 +381,7 @@
     struct pci_dev *pcidev;
     char vendor[STRING_SIZE];
     char description[STRING_SIZE];
+    int i;
 
 
     install_setup = flag_i_s;
@@ -592,43 +593,46 @@
     newtRefresh();
 
     names_init("/usr/share/usb.ids.gz");
-    usb_init();
-    usb_find_busses();
-    usb_find_devices();
+    libusb_device **usbdevs;
+    ssize_t cnt = 0;
+    if (libusb_init(NULL) >= 0) {
+        cnt = libusb_get_device_list(NULL, &usbdevs);
+    }
 
-    struct usb_bus *usbbus;
-    struct usb_device *usbdev;
-    int status;
+    for (i = 0; (i < cnt) && (usbdevs[i] != NULL); i++) {
+        struct libusb_device_descriptor descriptor;
 
-    status=1; /* 1 device not found, 0 device found */
+        if (libusb_get_device_descriptor(usbdevs[i], &descriptor) < 0) {
+            fprintf(flog, "libusb failed to get device descriptor\n");
+            fprintf(fhwdetect, "libusb failed to get device descriptor\n");
+            continue;
+        }
 
-    for (usbbus = usb_busses; usbbus; usbbus = usbbus->next) {
-               for (usbdev = usbbus->devices; usbdev; usbdev = usbdev->next) {
             type = none;
             strcpy(vendor, "");
             strcpy(line, "");
-            get_vendor_string(vendor, sizeof(vendor), 
usbdev->descriptor.idVendor);
-            get_product_string(line, sizeof(line), 
usbdev->descriptor.idVendor, usbdev->descriptor.idProduct);
+            get_vendor_string(vendor, sizeof(vendor), descriptor.idVendor);
+            get_product_string(line, sizeof(line), descriptor.idVendor, 
descriptor.idProduct);
             snprintf(description, STRING_SIZE, "%s %s", vendor, line);
 
             /* TODO: find a better way to differentiate network devices from 
other USB devices */
-            switch (usbdev->descriptor.bDeviceClass) {
-            case USB_CLASS_PER_INTERFACE:
+            switch (descriptor.bDeviceClass) {
+            case LIBUSB_CLASS_PER_INTERFACE:
                 type = network;
                 break;
 
-            case USB_CLASS_COMM:
+            case LIBUSB_CLASS_COMM:
                 type = network;
                 break;
 
-            case USB_CLASS_VENDOR_SPEC:
+            case LIBUSB_CLASS_VENDOR_SPEC:
                 type = network;
                 break;
             }
 
             if (type == none) {
                 snprintf(logline, STRING_SIZE, "  Skip %02x %04x:%04x, %s\n",
-                        usbdev->descriptor.bDeviceClass, 
usbdev->descriptor.idVendor, usbdev->descriptor.idProduct, description);
+                        descriptor.bDeviceClass, descriptor.idVendor, 
descriptor.idProduct, description);
                 fprintf(flog, logline);
                 fprintf(fhwdetect, logline);
             }
@@ -638,7 +642,7 @@
 
                 snprintf(command, STRING_SIZE,
                          "/bin/grep \"0x%04x   0x%04x\" 
/lib/modules/%s/modules.usbmap",
-                         usbdev->descriptor.idVendor, 
usbdev->descriptor.idProduct, utsbuf.release);
+                         descriptor.idVendor, descriptor.idProduct, 
utsbuf.release);
 
                 p = popen(command, "r");
                 if (fgets(modulemap, STRING_SIZE, p)) {
@@ -651,24 +655,26 @@
 
                 if (module != NULL) {
                     snprintf(logline, STRING_SIZE, "  Add  %02x %04x:%04x, 
%s\n",
-                            usbdev->descriptor.bDeviceClass, 
usbdev->descriptor.idVendor, usbdev->descriptor.idProduct, description);
+                            descriptor.bDeviceClass, descriptor.idVendor, 
descriptor.idProduct, description);
                     fprintf(flog, logline);
                     fprintf(fhwdetect, logline);
 
-                    hardwareadd(network, module, NULL, NULL, description, 
usbdev->descriptor.idVendor, usbdev->descriptor.idProduct);
+                    hardwareadd(network, module, NULL, NULL, description, 
descriptor.idVendor, descriptor.idProduct);
                 }
                 else {
                     /* There is little to add if there is no module */
-                    snprintf(logline, STRING_SIZE, "  Skip (no module) %04x 
%04x:%04x\n",
-                            usbdev->descriptor.bDeviceClass, 
usbdev->descriptor.idVendor, usbdev->descriptor.idProduct);
+                    snprintf(logline, STRING_SIZE, "  Skip (no module) %02x 
%04x:%04x\n",
+                            descriptor.bDeviceClass, descriptor.idVendor, 
descriptor.idProduct);
                     fprintf(flog, logline);
                     fprintf(fhwdetect, logline);
                 }
             }
-        }
     }
 
     numBusses++;
+    libusb_free_device_list(usbdevs, 1);
+
+    libusb_exit(NULL);
     sleep(1);
 
 skipusb:


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and, 
should the need arise, upgrade to a full multi-node Oracle RAC database 
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Ipcop-svn mailing list
Ipcop-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ipcop-svn

Reply via email to