Link Here
|
1 |
--- usbdevices.h.orig 2006-07-22 10:15:22.000000000 +0200 |
2 |
+++ usbdevices.h 2009-06-20 13:19:42.000000000 +0200 |
3 |
@@ -17,7 +17,9 @@ |
4 |
#include <qptrlist.h> |
5 |
|
6 |
#ifdef Q_OS_FREEBSD |
7 |
-#include <dev/usb/usb.h> |
8 |
+#include <libusb20.h> |
9 |
+#include <dev/usb/usb_ioctl.h> |
10 |
+#include <dev/usb/usb_revision.h> |
11 |
#endif |
12 |
|
13 |
class USBDB; |
14 |
@@ -66,7 +68,7 @@ |
15 |
unsigned int _vendorID, _prodID, _revMajor, _revMinor; |
16 |
|
17 |
#ifdef Q_OS_FREEBSD |
18 |
- void collectData( int fd, int level, usb_device_info &di, int parent ); |
19 |
+ void collectData(struct libusb20_backend *, struct libusb20_device *); |
20 |
QStringList _devnodes; |
21 |
#endif |
22 |
}; |
23 |
--- usbdevices.cpp.orig 2009-06-20 13:19:47.000000000 +0200 |
24 |
+++ usbdevices.cpp 2009-06-20 13:38:34.000000000 +0200 |
25 |
@@ -318,17 +318,25 @@ |
26 |
|
27 |
/* |
28 |
* FreeBSD support by Markus Brueffer <markus@brueffer.de> |
29 |
+ * libusb20 support by Hans Petter Selasky <hselasky@freebsd.org> |
30 |
* |
31 |
* Basic idea and some code fragments were taken from FreeBSD's usbdevs(8), |
32 |
* originally developed for NetBSD, so this code should work with no or |
33 |
* only little modification on NetBSD. |
34 |
*/ |
35 |
|
36 |
-void USBDevice::collectData( int fd, int level, usb_device_info &di, int parent) |
37 |
+void USBDevice::collectData(struct libusb20_backend *pbe, |
38 |
+ struct libusb20_device *pdev) |
39 |
{ |
40 |
+ char tempbuf[32]; |
41 |
+ struct usb_device_info di; |
42 |
+ |
43 |
+ if (libusb20_dev_get_info(pdev, &di)) |
44 |
+ memset(&di, 0, sizeof(di)); |
45 |
+ |
46 |
// determine data for this device |
47 |
- _level = level; |
48 |
- _parent = parent; |
49 |
+ _level = 0; |
50 |
+ _parent = 0; |
51 |
|
52 |
_bus = di.udi_bus; |
53 |
_device = di.udi_addr; |
54 |
@@ -345,87 +353,49 @@ |
55 |
_channels = di.udi_nports; |
56 |
|
57 |
// determine the speed |
58 |
-#if __FreeBSD_version > 490102 |
59 |
switch (di.udi_speed) { |
60 |
case USB_SPEED_LOW: _speed = 1.5; break; |
61 |
case USB_SPEED_FULL: _speed = 12.0; break; |
62 |
case USB_SPEED_HIGH: _speed = 480.0; break; |
63 |
+ case USB_SPEED_VARIABLE: _speed = 480.0; break; |
64 |
+ case USB_SPEED_SUPER: _speed = 4800.0; break; |
65 |
+ default: _speed = 480.0; break; |
66 |
} |
67 |
-#else |
68 |
- _speed = di.udi_lowspeed ? 1.5 : 12.0; |
69 |
-#endif |
70 |
|
71 |
// Get all attached devicenodes |
72 |
- for ( int i = 0; i < USB_MAX_DEVNAMES; ++i ) |
73 |
- if ( di.udi_devnames[i][0] ) |
74 |
- _devnodes << di.udi_devnames[i]; |
75 |
+ for (int i = 0; i < 32; ++i) { |
76 |
+ if (libusb20_dev_get_iface_desc(pdev, i, tempbuf, sizeof(tempbuf)) == 0) { |
77 |
+ _devnodes << tempbuf; |
78 |
+ } else { |
79 |
+ break; |
80 |
+ } |
81 |
+ } |
82 |
|
83 |
// For compatibility, split the revision number |
84 |
sscanf( di.udi_release, "%x.%x", &_revMajor, &_revMinor ); |
85 |
|
86 |
- // Cycle through the attached devices if there are any |
87 |
- for ( int p = 0; p < di.udi_nports; ++p ) { |
88 |
- // Get data for device |
89 |
- struct usb_device_info di2; |
90 |
- |
91 |
- di2.udi_addr = di.udi_ports[p]; |
92 |
- |
93 |
- if ( di2.udi_addr >= USB_MAX_DEVICES ) |
94 |
- continue; |
95 |
- |
96 |
- if ( ioctl(fd, USB_DEVICEINFO, &di2) == -1 ) |
97 |
- continue; |
98 |
- |
99 |
- // Only add the device if we didn't detect it, yet |
100 |
- if (!find( di2.udi_bus, di2.udi_addr ) ) |
101 |
- { |
102 |
- USBDevice *device = new USBDevice(); |
103 |
- device->collectData( fd, level + 1, di2, di.udi_addr ); |
104 |
- } |
105 |
- } |
106 |
} |
107 |
|
108 |
- |
109 |
- |
110 |
bool USBDevice::parse(QString fname) |
111 |
{ |
112 |
- static bool showErrorMessage = true; |
113 |
- bool error = false; |
114 |
+ struct libusb20_backend *pbe; |
115 |
+ struct libusb20_device *pdev; |
116 |
+ |
117 |
_devices.clear(); |
118 |
|
119 |
- QFile controller("/dev/usb0"); |
120 |
- int i = 1; |
121 |
- while ( controller.exists() ) |
122 |
- { |
123 |
- // If the devicenode exists, continue with further inspection |
124 |
- if ( controller.open(IO_ReadOnly) ) |
125 |
- { |
126 |
- for ( int addr = 1; addr < USB_MAX_DEVICES; ++addr ) |
127 |
- { |
128 |
- struct usb_device_info di; |
129 |
- |
130 |
- di.udi_addr = addr; |
131 |
- if ( ioctl(controller.handle(), USB_DEVICEINFO, &di) != -1 ) |
132 |
- { |
133 |
- if (!find( di.udi_bus, di.udi_addr ) ) |
134 |
- { |
135 |
- USBDevice *device = new USBDevice(); |
136 |
- device->collectData( controller.handle(), 0, di, 0); |
137 |
- } |
138 |
- } |
139 |
- } |
140 |
- controller.close(); |
141 |
- } else { |
142 |
- error = true; |
143 |
- } |
144 |
- controller.setName( QString::fromLocal8Bit("/dev/usb%1").arg(i++) ); |
145 |
- } |
146 |
- |
147 |
- if ( showErrorMessage && error ) { |
148 |
- showErrorMessage = false; |
149 |
- KMessageBox::error( 0, i18n("Could not open one or more USB controller. Make sure, you have read access to all USB controllers that should be listed here.")); |
150 |
+ pbe = libusb20_be_alloc_default(); |
151 |
+ if (pbe == NULL) |
152 |
+ return (false); |
153 |
+ |
154 |
+ pdev = NULL; |
155 |
+ |
156 |
+ while ((pdev = libusb20_be_device_foreach(pbe, pdev))) { |
157 |
+ USBDevice *device = new USBDevice(); |
158 |
+ device->collectData(pbe, pdev); |
159 |
} |
160 |
- |
161 |
+ |
162 |
+ libusb20_be_free(pbe); |
163 |
+ |
164 |
return true; |
165 |
} |
166 |
#endif |