From owner-freebsd-current@FreeBSD.ORG Mon Jun 8 06:58:44 2009 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7448B106566C; Mon, 8 Jun 2009 06:58:44 +0000 (UTC) (envelope-from hselasky@c2i.net) Received: from swip.net (mailfe03.swip.net [212.247.154.65]) by mx1.freebsd.org (Postfix) with ESMTP id 6090D8FC08; Mon, 8 Jun 2009 06:58:43 +0000 (UTC) (envelope-from hselasky@c2i.net) X-Cloudmark-Score: 0.000000 [] X-Cloudmark-Analysis: v=1.0 c=1 a=MXw7gxVQKqGXY79tIT8aFQ==:17 a=hkXuOvdueeTi8q5JRoAA:9 a=H2OH1hjEtW89SgMMYSEGWWgDOJUA:4 a=6I5d2MoRAAAA:8 a=HeMcwBzoyQ0cjYn5-V0A:9 a=-chr25bUZnwl8BsOjpMA:7 a=d6jAjl7vY0ZEsLz9ji0zdCXRUDkA:4 a=nF_S5m_C9V8A:10 a=SV7veod9ZcQA:10 Received: from [62.113.132.61] (account mc467741@c2i.net HELO laptop.adsl.tele2.no) by mailfe03.swip.net (CommuniGate Pro SMTP 5.2.13) with ESMTPA id 1258787690; Mon, 08 Jun 2009 08:58:32 +0200 From: Hans Petter Selasky To: freebsd-usb@freebsd.org, freebsd-ports@freebsd.org, markus@brueffer.de, freebsd-current@freebsd.org Date: Mon, 8 Jun 2009 09:02:40 +0200 User-Agent: KMail/1.11.4 (FreeBSD/8.0-CURRENT; KDE/4.2.4; i386; ; ) MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_TeLLKg/mWYdeuZZ" Message-Id: <200906080902.43391.hselasky@c2i.net> Cc: Subject: Temporary patch to fix USB in kdebase4 X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Jun 2009 06:58:44 -0000 --Boundary-00=_TeLLKg/mWYdeuZZ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline See attachment. --HPS --Boundary-00=_TeLLKg/mWYdeuZZ Content-Type: text/x-patch; charset="us-ascii"; name="kdebase4.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="kdebase4.diff" diff -u -r work.old/kdebase-4.2.4/apps/kinfocenter/usbview/CMakeLists.txt work/kdebase-4.2.4/apps/kinfocenter/usbview/CMakeLists.txt --- work.old/kdebase-4.2.4/apps/kinfocenter/usbview/CMakeLists.txt 2009-06-07 10:54:55.000000000 +0200 +++ work/kdebase-4.2.4/apps/kinfocenter/usbview/CMakeLists.txt 2009-06-07 10:55:58.000000000 +0200 @@ -9,7 +9,7 @@ kde4_add_plugin(kcm_usb ${kcm_usb_PART_SRCS}) -target_link_libraries(kcm_usb ${KDE4_KDEUI_LIBS} ${QT_QTGUI_LIBRARY}) +target_link_libraries(kcm_usb ${KDE4_KDEUI_LIBS} ${QT_QTGUI_LIBRARY} -lusb) install(TARGETS kcm_usb DESTINATION ${PLUGIN_INSTALL_DIR} ) diff -u -r work.old/kdebase-4.2.4/apps/kinfocenter/usbview/usbdevices.cpp work/kdebase-4.2.4/apps/kinfocenter/usbview/usbdevices.cpp --- work.old/kdebase-4.2.4/apps/kinfocenter/usbview/usbdevices.cpp 2009-06-07 10:54:55.000000000 +0200 +++ work/kdebase-4.2.4/apps/kinfocenter/usbview/usbdevices.cpp 2009-06-07 10:55:58.000000000 +0200 @@ -294,17 +294,25 @@ /* * FreeBSD support by Markus Brueffer + * libusb20 support by Hans Petter Selasky * * Basic idea and some code fragments were taken from FreeBSD's usbdevs(8), * originally developed for NetBSD, so this code should work with no or * only little modification on NetBSD. */ -void USBDevice::collectData( int fd, int level, usb_device_info &di, int parent) +void USBDevice::collectData(struct libusb20_backend *pbe, + struct libusb20_device *pdev) { + char tempbuf[32]; + struct usb_device_info di; + + if (libusb20_dev_get_info(pdev, &di)) + memset(&di, 0, sizeof(di)); + // determine data for this device - _level = level; - _parent = parent; + _level = 0; + _parent = 0; _bus = di.udi_bus; _device = di.udi_addr; @@ -320,88 +328,47 @@ _power = di.udi_power; _channels = di.udi_nports; - // determine the speed -#if defined(__DragonFly__) || (defined(Q_OS_FREEBSD) && __FreeBSD_version > 490102) || defined(Q_OS_NETBSD) switch (di.udi_speed) { case USB_SPEED_LOW: _speed = 1.5; break; case USB_SPEED_FULL: _speed = 12.0; break; case USB_SPEED_HIGH: _speed = 480.0; break; + case USB_SPEED_VARIABLE: _speed = 480.0; break; + case USB_SPEED_SUPER: _speed = 4800.0; break; + default: _speed = 480.0; break; } -#else - _speed = di.udi_lowspeed ? 1.5 : 12.0; -#endif // Get all attached devicenodes - for ( int i = 0; i < USB_MAX_DEVNAMES; ++i ) - if ( di.udi_devnames[i][0] ) - _devnodes << di.udi_devnames[i]; + for ( int i = 0; i < 32; ++i ) { + if (libusb20_dev_get_iface_desc( + pdev, i, tempbuf, sizeof(tempbuf)) == 0) { + _devnodes << tempbuf; + } else { + break; + } + } // For compatibility, split the revision number sscanf( di.udi_release, "%x.%x", &_revMajor, &_revMinor ); - - // Cycle through the attached devices if there are any - for ( int p = 0; p < di.udi_nports; ++p ) { - // Get data for device - struct usb_device_info di2; - - di2.udi_addr = di.udi_ports[p]; - - if ( di2.udi_addr >= USB_MAX_DEVICES ) - continue; - - if ( ioctl(fd, USB_DEVICEINFO, &di2) == -1 ) - continue; - - // Only add the device if we didn't detect it, yet - if (!find( di2.udi_bus, di2.udi_addr ) ) - { - USBDevice *device = new USBDevice(); - device->collectData( fd, level + 1, di2, di.udi_addr ); - } - } } bool USBDevice::parse(const QString &fname) { static bool showErrorMessage = true; - bool error = false; + struct libusb20_backend *pbe; + struct libusb20_device *pdev; _devices.clear(); - QFile controller("/dev/usb0"); - int i = 1; - while ( controller.exists() ) - { - // If the devicenode exists, continue with further inspection - if ( controller.open(QIODevice::ReadOnly) ) - { - for ( int addr = 1; addr < USB_MAX_DEVICES; ++addr ) - { - struct usb_device_info di; - - di.udi_addr = addr; - if ( ioctl(controller.handle(), USB_DEVICEINFO, &di) != -1 ) - { - if (!find( di.udi_bus, di.udi_addr ) ) - { - USBDevice *device = new USBDevice(); - device->collectData( controller.handle(), 0, di, 0); - } - } - } - controller.close(); -#ifndef Q_OS_NETBSD - } else { - error = true; -#endif - } - controller.setFileName( QString::fromLocal8Bit("/dev/usb%1").arg(i++) ); + pbe = libusb20_be_alloc_default(); + if (pbe == NULL) + return (false); + + pdev = NULL; + + while ((pdev = libusb20_be_device_foreach(pbe, pdev))) { + USBDevice *device = new USBDevice(); + device->collectData(pbe, pdev); } - - if ( showErrorMessage && error ) { - showErrorMessage = false; - 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.")); - } - + libusb20_be_free(pbe); return true; } #endif diff -u -r work.old/kdebase-4.2.4/apps/kinfocenter/usbview/usbdevices.h work/kdebase-4.2.4/apps/kinfocenter/usbview/usbdevices.h --- work.old/kdebase-4.2.4/apps/kinfocenter/usbview/usbdevices.h 2009-06-07 10:54:55.000000000 +0200 +++ work/kdebase-4.2.4/apps/kinfocenter/usbview/usbdevices.h 2009-06-07 10:59:11.000000000 +0200 @@ -14,18 +14,11 @@ #include #include -#if defined(__DragonFly__) -#include -#include -#elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) #include -#if __FreeBSD_version >= 800061 -#include -#else -#include -#endif +#include +#include +#include #include -#endif class USBDB; @@ -81,10 +74,8 @@ unsigned int _vendorID, _prodID, _revMajor, _revMinor; -#if defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) - void collectData( int fd, int level, usb_device_info &di, int parent ); + void collectData(struct libusb20_backend *, struct libusb20_device *); QStringList _devnodes; -#endif }; #endif --Boundary-00=_TeLLKg/mWYdeuZZ--