Browse Source

Fix build with libusb 2.0 on freebsd

[taken from FreeBSD kdebase3 patches]

Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
pull/2/head
Slávek Banko 4 years ago
parent
commit
e1d8ccc637

+ 3
- 3
kcontrol/ConfigureChecks.cmake View File

@@ -47,12 +47,12 @@ endif( )
47 47
 
48 48
 ##### check for libusb ##########################
49 49
 
50
-if( WITH_LIBUSB )
51
-  pkg_search_module( LIBUSB libusb )
50
+if( WITH_LIBUSB OR ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" )
51
+  pkg_search_module( LIBUSB libusb libusb-2.0 )
52 52
   if( LIBUSB_FOUND )
53 53
     set( HAVE_LIBUSB 1 CACHE INTERNAL "" FORCE )
54 54
   else( )
55
-    tde_message_fatal( "libusb are requested, but not found on your system" )
55
+    tde_message_fatal( "libusb is required, but not found on your system" )
56 56
   endif( )
57 57
 endif( )
58 58
 

+ 4
- 0
kcontrol/usbview/CMakeLists.txt View File

@@ -40,3 +40,7 @@ tde_add_kpart( kcm_usb AUTOMOC
40 40
   LINK tdeui-shared
41 41
   DESTINATION ${PLUGIN_INSTALL_DIR}
42 42
 )
43
+
44
+if( ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" )
45
+  target_link_libraries( kcm_usb-module ${LIBUSB_LIBRARIES} )
46
+endif( )

+ 50
- 74
kcontrol/usbview/usbdevices.cpp View File

@@ -230,9 +230,9 @@ TQString USBDevice::dump()
230 230
 	if ( _devnodes.count() > 1 )
231 231
 		for ( TQStringList::Iterator it = _devnodes.at(1); it != _devnodes.end(); ++it )
232 232
 			r += "<tr><td></td><td>" + *it + "</td></tr>";
233
-#else  
233
+#else
234 234
   r += i18n("<tr><td><i>Max. Packet Size</i></td><td>%1</td></tr>").arg(_maxPacketSize);
235
-#endif  
235
+#endif
236 236
   r += "<tr><td></td></tr>";
237 237
 
238 238
   if (_hasBW)
@@ -318,18 +318,26 @@ bool USBDevice::parseSys(TQString dname)
318 318
 
319 319
 /*
320 320
  * FreeBSD support by Markus Brueffer <markus@brueffer.de>
321
+ * libusb20 support by Hans Petter Selasky <hselasky@freebsd.org>
321 322
  *
322 323
  * Basic idea and some code fragments were taken from FreeBSD's usbdevs(8), 
323 324
  * originally developed for NetBSD, so this code should work with no or 
324 325
  * only little modification on NetBSD.
325 326
  */
326 327
 
327
-void USBDevice::collectData( int fd, int level, usb_device_info &di, int parent)
328
+void USBDevice::collectData(struct libusb20_backend *pbe,
329
+    struct libusb20_device *pdev)
328 330
 {
331
+	char tempbuf[32];
332
+	struct usb_device_info di;
333
+
334
+	if (libusb20_dev_get_info(pdev, &di))
335
+		memset(&di, 0, sizeof(di));
336
+
329 337
 	// determine data for this device
330
-	_level        = level;
331
-	_parent       = parent;
332
-	
338
+	_level        = 0;
339
+	_parent       = 0;
340
+
333 341
 	_bus          = di.udi_bus;
334 342
 	_device       = di.udi_addr;
335 343
 	_product      = TQString::fromLatin1(di.udi_product);
@@ -343,89 +351,57 @@ void USBDevice::collectData( int fd, int level, usb_device_info &di, int parent)
343 351
 	_prot         = di.udi_protocol;
344 352
 	_power        = di.udi_power;
345 353
 	_channels     = di.udi_nports;
346
-	
354
+
347 355
 	// determine the speed
348
-#if __FreeBSD_version > 490102
349 356
 	switch (di.udi_speed) {
350
-		case USB_SPEED_LOW:  _speed = 1.5;   break;
351
-		case USB_SPEED_FULL: _speed = 12.0;  break;
352
-		case USB_SPEED_HIGH: _speed = 480.0; break;
357
+		case LIBUSB20_SPEED_LOW:  _speed = 1.5;   break;
358
+		case LIBUSB20_SPEED_FULL: _speed = 12.0;  break;
359
+		case LIBUSB20_SPEED_HIGH: _speed = 480.0; break;
360
+		case LIBUSB20_SPEED_VARIABLE: _speed = 480.0; break;
361
+		case LIBUSB20_SPEED_SUPER: _speed = 4800.0; break;
362
+		default: _speed = 480.0; break;
353 363
 	}
354
-#else
355
-	_speed = di.udi_lowspeed ? 1.5 : 12.0;
356
-#endif
357 364
 
358 365
 	// Get all attached devicenodes
359
-	for ( int i = 0; i < USB_MAX_DEVNAMES; ++i )
360
-		if ( di.udi_devnames[i][0] )
361
-			_devnodes << di.udi_devnames[i];
366
+	for (int i = 0; i < 32; ++i) {
367
+	    if (libusb20_dev_get_iface_desc(pdev, i, tempbuf, sizeof(tempbuf)) == 0) {
368
+		_devnodes << tempbuf;
369
+	    } else {
370
+		break;
371
+	    }
372
+	}
362 373
 
363 374
 	// For compatibility, split the revision number
364 375
 	sscanf( di.udi_release, "%x.%x", &_revMajor, &_revMinor );
365 376
 
366
-	// Cycle through the attached devices if there are any
367
-	for ( int p = 0; p < di.udi_nports; ++p ) {
368
-		// Get data for device
369
-		struct usb_device_info di2;
370
-
371
-		di2.udi_addr = di.udi_ports[p];
372
-		
373
-		if ( di2.udi_addr >= USB_MAX_DEVICES )
374
-			continue;
375
-			
376
-		if ( ioctl(fd, USB_DEVICEINFO, &di2) == -1 )
377
-			continue;
378
-
379
-		// Only add the device if we didn't detect it, yet
380
-		if (!find( di2.udi_bus, di2.udi_addr ) )
381
-		{
382
-			USBDevice *device = new USBDevice();
383
-			device->collectData( fd, level + 1, di2, di.udi_addr );
384
-		}
385
-	}
386 377
 }
387 378
 
388
-
389
-
390 379
 bool USBDevice::parse(TQString fname)
391 380
 {
392
-	static bool showErrorMessage = true;
393
-	bool error = false;
381
+	struct libusb20_backend *pbe;
382
+	struct libusb20_device *pdev;
383
+
394 384
 	_devices.clear();
395
-	
396
-	TQFile controller("/dev/usb0");
397
-	int i = 1;
398
-	while ( controller.exists() )
399
-	{
400
-		// If the devicenode exists, continue with further inspection
401
-		if ( controller.open(IO_ReadOnly) )
402
-		{
403
-			for ( int addr = 1; addr < USB_MAX_DEVICES; ++addr ) 
404
-			{
405
-				struct usb_device_info di;
406
-				
407
-				di.udi_addr = addr;
408
-				if ( ioctl(controller.handle(), USB_DEVICEINFO, &di) != -1 )
409
-				{
410
-					if (!find( di.udi_bus, di.udi_addr ) )
411
-					{
412
-						USBDevice *device = new USBDevice();
413
-						device->collectData( controller.handle(), 0, di, 0);
414
-					}
415
-				}
416
-			}
417
-			controller.close();
418
-		} else {
419
-			error = true;
420
-		}
421
-		controller.setName( TQString::fromLocal8Bit("/dev/usb%1").arg(i++) );
422
-	}
423
-	
424
-	if ( showErrorMessage && error ) {
425
-		showErrorMessage = false;
426
-		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."));
385
+
386
+	pbe = libusb20_be_alloc_default();
387
+	if (pbe == NULL)
388
+	    return (false);
389
+
390
+	pdev = NULL;
391
+
392
+	while ((pdev = libusb20_be_device_foreach(pbe, pdev))) {
393
+	    USBDevice *device = new USBDevice();
394
+	    device->collectData(pbe, pdev);
427 395
 	}
428
-	
396
+
397
+	libusb20_be_free(pbe);
398
+
429 399
 	return true;
430 400
 }
401
+
402
+bool USBDevice::parseSys(TQString)
403
+{
404
+	// sysfs is not available on FreeBSD
405
+	return 0;
406
+}
431 407
 #endif

+ 4
- 3
kcontrol/usbview/usbdevices.h View File

@@ -17,7 +17,8 @@
17 17
 #include <tqptrlist.h>
18 18
 
19 19
 #ifdef Q_OS_FREEBSD
20
-#include <dev/usb/usb.h>
20
+#include <libusb20.h>
21
+#include <dev/usb/usb_ioctl.h>
21 22
 #endif
22 23
 
23 24
 class USBDB;
@@ -26,7 +27,7 @@ class USBDB;
26 27
 class USBDevice
27 28
 {
28 29
 public:
29
-  
30
+
30 31
   USBDevice();
31 32
 
32 33
   void parseLine(TQString line);
@@ -66,7 +67,7 @@ private:
66 67
   unsigned int _vendorID, _prodID, _revMajor, _revMinor;
67 68
 
68 69
 #ifdef Q_OS_FREEBSD
69
-  void collectData( int fd, int level, usb_device_info &di, int parent );
70
+  void collectData(struct libusb20_backend *, struct libusb20_device *);
70 71
   TQStringList _devnodes;
71 72
 #endif
72 73
 };

Loading…
Cancel
Save