From owner-freebsd-usb@FreeBSD.ORG Sun Nov 21 00:24:35 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 355A9106566C; Sun, 21 Nov 2010 00:24:35 +0000 (UTC) (envelope-from perryh@pluto.rain.com) Received: from agora.rdrop.com (agora.rdrop.com [IPv6:2607:f678:1010::34]) by mx1.freebsd.org (Postfix) with ESMTP id 140AA8FC15; Sun, 21 Nov 2010 00:24:35 +0000 (UTC) Received: from agora.rdrop.com (66@localhost [127.0.0.1]) by agora.rdrop.com (8.13.1/8.12.7) with ESMTP id oAL0OWgX042171 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sat, 20 Nov 2010 16:24:34 -0800 (PST) (envelope-from perryh@pluto.rain.com) Received: (from uucp@localhost) by agora.rdrop.com (8.13.1/8.12.9/Submit) with UUCP id oAL0OW8A042170; Sat, 20 Nov 2010 16:24:32 -0800 (PST) Received: from fbsd61 by pluto.rain.com (4.1/SMI-4.1-pluto-M2060407) id AA05385; Sat, 20 Nov 10 16:19:49 PST Date: Sat, 20 Nov 2010 16:19:48 -0800 From: perryh@pluto.rain.com To: guru@unixarea.de, mav@freebsd.org Message-Id: <4ce865a4.aMSvcjRoHgImeAYF%perryh@pluto.rain.com> References: <201011191916.53655.hselasky@c2i.net> <4CE6C73A.4070208@FreeBSD.org> <20101120151655.GA4010@current.Sisis.de> In-Reply-To: <20101120151655.GA4010@current.Sisis.de> User-Agent: nail 11.25 7/29/05 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Cc: freebsd-usb@freebsd.org Subject: Re: copying /dev/da0 with dd(1) to file: output differs X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Nov 2010 00:24:35 -0000 Matthias Apitz wrote: > El d?a Friday, November 19, 2010 a las 08:51:38PM +0200, > Alexander Motin escribi?: > > > Could it be that unwritten/unformatted blocks are read as > > > random data from that USB key? Should I overwrite the full > > > USB key from /dev/zero? > > > > It is allowed behavior for SATA SSDs with TRIM command support. > > Deleted blocks can be not guarantied to return any predictable > > or even repeatable value. May be this logic could be extended to > > USB devices. > > A cmp(1) with -l gives a file like this: > > $ head -10 diff > 196971771 134 34 > 196971797 134 34 ... > of 2385059 lines, i.e. of 2385059 bytes which differ in the 3.8 > GByte copy; there are only a few patterns of diffs which are > repeating: ... > What does this mean? Does not look like errors, in case of random > error it whould be more caotic, or? Good question. To help sort out whether it matters, what happens if you read the stick using dump(8) instead of dd (or mount it read-only and read it with tar)? Either of those methods will read only the parts that are in use. From owner-freebsd-usb@FreeBSD.ORG Sun Nov 21 07:24:01 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 38C2D106566B; Sun, 21 Nov 2010 07:24:01 +0000 (UTC) (envelope-from guru@unixarea.de) Received: from ms16-1.1blu.de (ms16-1.1blu.de [89.202.0.34]) by mx1.freebsd.org (Postfix) with ESMTP id 814488FC0C; Sun, 21 Nov 2010 07:24:00 +0000 (UTC) Received: from [88.217.28.104] (helo=current.Sisis.de) by ms16-1.1blu.de with esmtpsa (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1PK4HF-0001u2-F2; Sun, 21 Nov 2010 08:23:57 +0100 Received: from current.Sisis.de (current [127.0.0.1]) by current.Sisis.de (8.14.3/8.14.3) with ESMTP id oAL7Nuwh069466; Sun, 21 Nov 2010 08:23:56 +0100 (CET) (envelope-from guru@unixarea.de) Received: (from guru@localhost) by current.Sisis.de (8.14.3/8.14.3/Submit) id oAL7NtJA069465; Sun, 21 Nov 2010 08:23:55 +0100 (CET) (envelope-from guru@unixarea.de) X-Authentication-Warning: current.Sisis.de: guru set sender to guru@unixarea.de using -f Date: Sun, 21 Nov 2010 08:23:54 +0100 From: Matthias Apitz To: perryh@pluto.rain.com Message-ID: <20101121072354.GA69433@current.Sisis.de> References: <201011191916.53655.hselasky@c2i.net> <4CE6C73A.4070208@FreeBSD.org> <20101120151655.GA4010@current.Sisis.de> <4ce865a4.aMSvcjRoHgImeAYF%perryh@pluto.rain.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4ce865a4.aMSvcjRoHgImeAYF%perryh@pluto.rain.com> X-Operating-System: FreeBSD 8.0-CURRENT (i386) User-Agent: Mutt/1.5.19 (2009-01-05) X-Con-Id: 51246 X-Originating-IP: 88.217.28.104 Cc: mav@freebsd.org, freebsd-usb@freebsd.org Subject: Re: copying /dev/da0 with dd(1) to file: output differs X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Matthias Apitz List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Nov 2010 07:24:01 -0000 El día Saturday, November 20, 2010 a las 04:19:48PM -0800, perryh@pluto.rain.com escribió: > ... > > What does this mean? Does not look like errors, in case of random > > error it whould be more caotic, or? > > Good question. > > To help sort out whether it matters, what happens if you read the > stick using dump(8) instead of dd (or mount it read-only and read it > with tar)? Either of those methods will read only the parts that > are in use. Good idea! A dump is fine and gives more or less the same size as the dump which was restored to the USB key: # dump -0au -f reRead.dmp /dev/da0s1a DUMP: Date of this level 0 dump: Sun Nov 21 08:05:25 2010 DUMP: Date of last level 0 dump: the epoch DUMP: Dumping /dev/da0s1a to reRead.dmp DUMP: mapping (Pass I) [regular files] DUMP: mapping (Pass II) [directories] DUMP: estimated 3282758 tape blocks. DUMP: dumping (Pass III) [directories] DUMP: dumping (Pass IV) [regular files] DUMP: 56.62% done, finished in 0:03 at Sun Nov 21 08:14:18 2010 DUMP: DUMP: 3287561 tape blocks on 1 volume DUMP: finished in 586 seconds, throughput 5610 KBytes/sec DUMP: level 0 dump on Sun Nov 21 08:05:25 2010 DUMP: Closing reRead.dmp DUMP: DUMP IS DONE current# ls -l reRead.dmp ~guru/usb9root.dmp -r--r--r-- 1 guru wheel 3351920640 12 nov 13:40 /home/guru/usb9root.dmp -rw-r--r-- 1 root wheel 3366461440 21 nov 08:15 reRead.dmp One could as well MD5 compare all files with find(1), but this is perhaps a bit overkill... I will buy a 2nd key and restore the dd(1)'ed file to it with dd(1)... matthias -- Matthias Apitz t +49-89-61308 351 - f +49-89-61308 399 - m +49-170-4527211 e - w http://www.unixarea.de/ From owner-freebsd-usb@FreeBSD.ORG Sun Nov 21 14:50:12 2010 Return-Path: Delivered-To: freebsd-usb@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BF5561065695 for ; Sun, 21 Nov 2010 14:50:12 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id AE4CA8FC22 for ; Sun, 21 Nov 2010 14:50:12 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id oALEoC8U054788 for ; Sun, 21 Nov 2010 14:50:12 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id oALEoCAJ054787; Sun, 21 Nov 2010 14:50:12 GMT (envelope-from gnats) Date: Sun, 21 Nov 2010 14:50:12 GMT Message-Id: <201011211450.oALEoCAJ054787@freefall.freebsd.org> To: freebsd-usb@FreeBSD.org From: Derrick Edwards Cc: Subject: Re: usb/80361: [umass] [patch] mounting of Dell usb-stick fails X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Derrick Edwards List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Nov 2010 14:50:12 -0000 The following reply was made to PR usb/80361; it has been noted by GNATS. From: Derrick Edwards To: bug-followup@freebsd.org, fbusse@gmx.de Cc: Subject: Re: usb/80361: [umass] [patch] mounting of Dell usb-stick fails Date: Sun, 21 Nov 2010 09:26:09 -0500 I am using 8.1-STABLE and I continue to have this problem. At boot time if my Android phone is attached to system I get a device entry /dev/da0s1 however, if I detach and attempt to reattach I can not get an device entry. An cat /dev/null > /dev/da0 produces an /dev/da0s1 entry however, that is not optimal. Any help would be great. ugen6.3: at usbus6, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=ON Derrick From owner-freebsd-usb@FreeBSD.ORG Sun Nov 21 21:05:10 2010 Return-Path: Delivered-To: freebsd-usb@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B8E011065698; Sun, 21 Nov 2010 21:05:10 +0000 (UTC) (envelope-from stefan@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 8F5CF8FC0A; Sun, 21 Nov 2010 21:05:10 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id oALL5AZT048969; Sun, 21 Nov 2010 21:05:10 GMT (envelope-from stefan@freefall.freebsd.org) Received: (from stefan@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id oALL59M0048965; Sun, 21 Nov 2010 21:05:09 GMT (envelope-from stefan) Date: Sun, 21 Nov 2010 21:05:09 GMT Message-Id: <201011212105.oALL59M0048965@freefall.freebsd.org> To: sw@gegenunendlich.de, stefan@FreeBSD.org, freebsd-usb@FreeBSD.org From: stefan@FreeBSD.org Cc: Subject: Re: usb/82660: [ehci] [panic] EHCI: I/O stuck in state 'physrd'/panic X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Nov 2010 21:05:10 -0000 Synopsis: [ehci] [panic] EHCI: I/O stuck in state 'physrd'/panic State-Changed-From-To: open->closed State-Changed-By: stefan State-Changed-When: Sun Nov 21 21:02:54 UTC 2010 State-Changed-Why: This PR is more than five years old and I do not use the problematic hardware any more. http://www.freebsd.org/cgi/query-pr.cgi?pr=82660 From owner-freebsd-usb@FreeBSD.ORG Sun Nov 21 23:10:12 2010 Return-Path: Delivered-To: freebsd-usb@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 609B2106564A for ; Sun, 21 Nov 2010 23:10:12 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 4F77E8FC13 for ; Sun, 21 Nov 2010 23:10:12 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id oALNACqa072293 for ; Sun, 21 Nov 2010 23:10:12 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id oALNACBd072290; Sun, 21 Nov 2010 23:10:12 GMT (envelope-from gnats) Date: Sun, 21 Nov 2010 23:10:12 GMT Message-Id: <201011212310.oALNACBd072290@freefall.freebsd.org> To: freebsd-usb@FreeBSD.org From: Maurice Castro Cc: Subject: Re: usb/122819: [usb] [patch] Patch to provide dynamic additions to the usb quirks table X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Maurice Castro List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Nov 2010 23:10:12 -0000 The following reply was made to PR usb/122819; it has been noted by GNATS. From: Maurice Castro To: bug-followup@FreeBSD.org, maurice@castro.aus.net Cc: Subject: Re: usb/122819: [usb] [patch] Patch to provide dynamic additions to the usb quirks table Date: Mon, 22 Nov 2010 10:04:33 +1100 After quickly reviewing the code in 8.1 there appears to be dynamic usb = quirks in the new usb stack. The patch is effectively orphaned as the = new usb stack provides the feature; but people using the old stack do = not have the functionality. To summarise the patch is relevant to the 7 = series of kernels, but the functionality appears to be available in the = 8 and beyond series of kernels. Maurice Castro= From owner-freebsd-usb@FreeBSD.ORG Mon Nov 22 11:07:16 2010 Return-Path: Delivered-To: freebsd-usb@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DBBFC10656D5 for ; Mon, 22 Nov 2010 11:07:16 +0000 (UTC) (envelope-from owner-bugmaster@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id C86918FC22 for ; Mon, 22 Nov 2010 11:07:16 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id oAMB7GRZ051902 for ; Mon, 22 Nov 2010 11:07:16 GMT (envelope-from owner-bugmaster@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id oAMB7GTl051896 for freebsd-usb@FreeBSD.org; Mon, 22 Nov 2010 11:07:16 GMT (envelope-from owner-bugmaster@FreeBSD.org) Date: Mon, 22 Nov 2010 11:07:16 GMT Message-Id: <201011221107.oAMB7GTl051896@freefall.freebsd.org> X-Authentication-Warning: freefall.freebsd.org: gnats set sender to owner-bugmaster@FreeBSD.org using -f From: FreeBSD bugmaster To: freebsd-usb@FreeBSD.org Cc: Subject: Current problem reports assigned to freebsd-usb@FreeBSD.org X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Nov 2010 11:07:16 -0000 Note: to view an individual PR, use: http://www.freebsd.org/cgi/query-pr.cgi?pr=(number). The following is a listing of current problems submitted by FreeBSD users. These represent problem reports covering all versions including experimental development code and obsolete releases. S Tracker Resp. Description -------------------------------------------------------------------------------- o usb/152075 usb [usb8] [ehci] Add quirk for CS5536 USB o usb/151862 usb adding support of USB GSM modem Falcom Twist o usb/151043 usb Please add USB device MELCO WLR-UC-G o usb/150989 usb [patch] Add Netgear WG111V2_2 support to upgt(4) o usb/150892 usb [zyd] Whenever network contacted in any shape, way or p usb/150546 usb libusb(3) libusb_control_transfer() prototype is incor o usb/150401 usb [umass] [usb8] Errors from USB drives mixed between UF o usb/150189 usb [run] [usb8] [patch] if_run appears to corrupt IP traf p usb/149934 usb [patch] [usb8] Transcend JetFlash V85 poor performance o usb/149900 usb [uftdi] [patch] FreeBSD 8.1 uftdi patch to support usb p usb/149764 usb [u3g] [patch] usbdevs update: Huawei K3765 3G modem o usb/149675 usb [uftdi] [usb_serial] doesn't react to break properly o usb/149528 usb [zyd] Wireless USB stick not detected - vendor id 0x08 o usb/149283 usb [uftdi] avrdude unable to talk to Arduino board (via u o usb/149162 usb [ural] ASUS WL-167g doesn't work in 8.1 (continue of 1 o usb/149039 usb [uhso] [patch] Binding problem with uhso s usb/148702 usb [usb8] [request] IO DATA USB-RSAQ5 support on FreeBSD- o usb/148080 usb usbconfig(8) sometimes does not turn off the device o usb/147516 usb [umass] [usb67] kernel unable to deal with Olympus USB o i386/147475 usb [install] FreeBSD 8.x does not install on ASUS K8N4-E p usb/146871 usb [usbdevs] [usb8] [patch] provide descriprive string fo o usb/146840 usb [hang] FreeBSD 7.2 / 7.3 / 8.0 hang at startup after e o usb/146153 usb [axe] [usb8] Hosts in network doesn't receive any pack o usb/146054 usb [urtw] [usb8] urtw driver potentially out of date f usb/145513 usb [usb8] New USB stack: no new devices after forced usb p usb/145455 usb [usb8] [patch] USB debug support cannot be disabled o usb/145415 usb [umass] [usb8] USB card reader does not create slices a usb/145184 usb GENERIC can't mount root from USB on Asus EEE o usb/145165 usb [keyboard] [usb8] ukbd_set_leds_callback: error=USB_ER f kern/144938 usb [keyboard] [boot] Boot Failure with Apple (MB869LL/A) o usb/144387 usb [run] [panic] if_run panic o usb/144043 usb [umass] [usb8] USB DLT tape drive throws random errors a usb/143790 usb [boot] [cam] can not boot from usb hdd f usb/143620 usb [cdce] [usb8] the module if_cdce doesn't support my Op f usb/143294 usb [usb8] copying process stops at some time (10 - 50 sec o usb/143286 usb [ukbd] [usb8] [boot] boot failures on RELENG_8 system p usb/143186 usb [usbdevs] [usb8] [patch] add USB device IDs for Google a usb/143139 usb [umass] [usb8] [patch] Quirk for Century EX35SW4_SB4 J o usb/143045 usb [umass] [usb8] [patch] mounting Fujitsu 2600Z camera d o usb/142991 usb [uftdi] [usb67] [patch] Patch to add Crystalfontz 533 f usb/142989 usb [usb8] canon eos 50D attaches but detaches after few s f usb/142957 usb [umass] [usb8] [patch] patch for USB disk SYNCHRONIZE o usb/142719 usb [urtw] [usb8] AirLive WL-1600USB (RTL8187L chipset) fa o usb/142713 usb [usb67] [panic] Kernel Panik when connecting an IPhone f usb/142276 usb [umass] [usb8] Cache Synchronization Error with Olympu o usb/142229 usb [ums] [usb8] [hang] connecting a USB mouse to a Dell P o usb/141777 usb [usb8] [usbdevs] [rum] [patch] Support usbdevs / rum(4 f usb/141680 usb [uath] [usb8] Netgear WG111T not working with uath dri o usb/141664 usb [pcm] [usb8] Logitech USB microphone failure [regressi o usb/141474 usb [boot] [usb8] FreeBSD 8.0 can not install from USB CDR o usb/141327 usb [ukbd] [usb67] USB kbd not working with 7.1+PAE on IBM o usb/141212 usb [ukbd] [usb8] ukbd_set_leds_callback:700: error=USB_ER o kern/141011 usb [usb8] Encrypted root, geli password at boot; enter ke o usb/140920 usb [install] [usb8] USB based install fails on 8.0-RELEAS o usb/140893 usb [urtw] [usb8] WPA2 not working on rtl8187b f usb/140883 usb [axe] [usb8] USB gigabit ethernet hangs after short pe o kern/140849 usb [ums] [usb8] USB mouse doesn't work under FreeBSD 8.0- a usb/140810 usb [uftdi] [usb8] 8.X copy and paste problem / tty overfl o usb/140477 usb [umass] [usb8] [patch] allow boot-time attachment of d o usb/140236 usb [msdosfs] [usb8] Labels wiped on external Journaled US o usb/140160 usb [usb8] [acpi] USB ports are no longer "active" after A s usb/139990 usb [panic] [patch] [usb67] Kernel frequently panics after a usb/139598 usb [umass] [usb8] CAM reports "xptioctl: put "device pass o usb/139243 usb [uhci] [usb67] unplug prolific USB serial -> uhci_abor a usb/138904 usb [rum] [panic] [usb67] unpluging USB wifi card panics s f usb/138882 usb [ohci] [panic] [usb67] Can't install FreeBSD 7.2 due t o usb/138798 usb [boot] [usb8] 8.0-BETA4 can't boot from USB flash driv o usb/138659 usb [usb8][uftdi] driver broken in RELENG_8/CURRENT s usb/138570 usb [usb67] [panic] USB mass device panics current 7.2-STA o usb/138175 usb [usb67] [boot] System cannot boot, when USB reader wit o usb/138124 usb [snd_uaudio] [usb8] Axed uaudio functionality in the u o usb/138119 usb [usb67] [usb8] MultiBay CDROM (probably on USB bus) is o usb/137872 usb [usb67] [boot] slow booting on usb flash drive o usb/137806 usb [ukbd] [usb67] USB keyboard doesn't work until it's un o usb/137763 usb [usb67][ukbd] Logitech wireless keyboard media keys no o usb/137377 usb [usb8] request support for Huawei E180 o usb/137341 usb [usb8][rum] driver if_rum doesn't work at all and thro f usb/137190 usb [usb8][patch] inhibit spurious button releases for som o usb/137189 usb [usb8][patch] create and use sysctl nodes for HID repo p usb/137188 usb [usb8][patch] correctly handle USB report descriptors o usb/137129 usb [ums] [usb8] SteelSeries Ikari USB laser mouse not att p usb/136761 usb [usbdevs][usb67][patch] Teach usbdevs / u3g(4) about H o usb/135938 usb [aue] [usb67] aue driver only passes traffic in promis o usb/135542 usb [keyboard] boot loader does not work with a usb keyboa o usb/135348 usb [umass] [patch] USB Drive Hangs with ZFS (JMicron USB2 o usb/135206 usb machine reboots when inserted USB device f usb/135200 usb SAMSUNG i740 usb mass: Synchronize cache failed, statu o usb/135182 usb UMASS quirk - Olympus FE20 camera o usb/134950 usb Lowering DTR for USB-modem via ubsa is not possible o usb/134299 usb Kernel Panic plugging in MF626 USB UMTS Stick u3g o usb/134193 usb System freeze on usb MP3 player insertion o usb/134085 usb [umass] Adding usb quirk for Sony USB flash drive o usb/133989 usb [usb8] [ukbd] USB keyboard dead at mountroot> prompt o usb/133712 usb [ural] [patch] RE: Fixed an issue with ural(4) that wa o usb/133390 usb umass crashes system in 7.1 when Olympus D-540 attache o usb/133296 usb [rum] driver not working properly in hostap mode o usb/132594 usb USB subsystem causes page fault and crashes o usb/132312 usb [hang] Xorg 7.4 halts USB controller o usb/132080 usb [patch] [usb] [rum] [panic] Kernel panic after NOMEM c o usb/132066 usb [ukbd] Keyboard failure USB keyboard DELL 760 o usb/132036 usb [panic] page fault when connecting Olympus C740 camera o usb/131583 usb [umass] Failure when detaching umass Device o usb/131576 usb [aue] ADMtek USB To LAN Converter can't send data o usb/131521 usb Registering Belkin UPS to usb_quirks.c p usb/131123 usb [patch] [usb67] re-add UQ_ASSUME_CM_OVER_DATA USB quir o usb/131074 usb no run-time detection of usb devices plugged into exte o usb/130736 usb Page fault unplugging USB stick o usb/130230 usb [patch] [quirk] [usb67] [usb] [cam] [umass] Samsung El o usb/130208 usb Boot process severely hampered by umass0 error o usb/130122 usb [usb8] DVD drive detects as 'da' device f usb/129766 usb [usb] [panic] plugging in usb modem HUAWEI E226 panics o usb/129673 usb [uhci] uhci (uhub) confused on replugging USB 1.1 scan o usb/129500 usb [umass] [panic] FreeBSD Crashes when connecting SanDis o usb/129311 usb [usb] [panic] Instant crash with an USB card reader s usb/128990 usb [usb] u3g does not handle RTS/CTS available on for exa o usb/128977 usb [usb67] [patch] uaudio is not full duplex p usb/128803 usb [usbdevs] [patch] Quirk for I-Tuner Networks USBLCD4X2 o usb/128485 usb [umodem] [patch] Nokia N80 modem support o usb/128425 usb [umass] Cannot Connect Maxtor Onetouch 4 USB drive o usb/128418 usb [panic] [rum] loading if_rum causes panic, looks like o usb/127926 usb [boot] USB Timeout during bootup s usb/127453 usb [request] ubsa, uark, ubser, uftdi, and friends should p docs/127406 usb [patch] update umodem man page: Sony Ericsson W810i o usb/127342 usb [boot] [panic] enabling usb keyboard and mouse support o usb/127248 usb [ucom] panic while uplcom devices attach and detach o usb/127222 usb [ohci] Regression in 7.0 usb storage generic driver o usb/126884 usb [ugen] [patch] Bug in buffer handling in ugen.c o usb/126848 usb [usb]: USB Keyboard hangs during Installation o usb/126740 usb [ulpt] doesn't work on 7.0-RELEASE, 10 second stall be o usb/126519 usb [usb] [panic] panic when plugging in an iphone o kern/126396 usb [panic] kernel panic after unplug USB Bluetooth device o usb/125631 usb [ums] [panic] kernel panic during bootup while 'Logite o usb/125510 usb [panic] repeated plug and unplug of USB mass storage d o usb/125450 usb [panic] Removing USB flash card while being accessed c o usb/125238 usb [ums] Habu Mouse turns off in X o usb/125088 usb [keyboard] Touchpad not detected on Adesso AKB-430UG U o usb/124980 usb [panic] kernel panic on detaching unmounted umass devi o kern/124777 usb [ucom] USB cua devices don't revert to tty devices whe o usb/124758 usb [rum] [panic] rum panics SMP kernel o usb/124708 usb [panic] Kernel panic on USB KVM reattach f usb/124604 usb [ums] Microsoft combo wireless mouse doesn't work o kern/124130 usb [usb] gmirror fails to start usb devices that were pre o usb/123969 usb [usb] Supermicro H8SMi-2 usb problem: port reset faile o usb/123714 usb [usb] [panic] Panic when hald-storage-probe runs with o usb/123691 usb usbd(8): usbd hangs o usb/123690 usb [usb] [panic] Panic on USB device insertion when usb l o usb/123611 usb [usb] BBB reset failed, STALLED from Imation/Mitsumi U o usb/122992 usb [umass] [patch] MotoROKR Z6 Phone not recognised by um o usb/122936 usb [ucom] [ubsa] Device does not receive interrupt o usb/122905 usb [ubsa] [patch] add Huawei E220 to ubsa f usb/122819 usb [usb] [patch] Patch to provide dynamic additions to th o usb/122813 usb [udbp] [request] udbp driver should be removed in favo o usb/122547 usb [ehci] USB Printer not being recognized after reboot o usb/122539 usb [ohci] [panic] AnyDATA ADU-E1000D - kernel panic: ohci o usb/122483 usb [panic] [ulpt] Repeatable panic in 7.0-STABLE o usb/122119 usb [umass] umass device causes creation of daX but not da o usb/121755 usb [ohci] [patch] Fix panic after ohci/uhub cardbus devic o usb/121734 usb [ugen] ugen HP1022 printer device not working since up o usb/121708 usb [keyboard] nforce 650i mobo w/ usb keyboard infinite k o usb/121474 usb [cam] [patch] QUIRK: SAMSUNG HM250JI in LaCie usb hard o usb/121275 usb [boot] [panic] FreeBSD fails to boot with usb legacy s f usb/121232 usb [usb67] [panic] USB CardBus card removal causes reboot p usb/121184 usb [uipaq] [patch] add ids from linux ipaq driver (plus a o usb/121169 usb [umass] Issues with usb mp3 player o usb/121045 usb [uftdi] [patch] Add support for PC-OP-RS1 and KURO-RS f usb/120786 usb [usb] [panic] Kernel panic when forced umount of a det o usb/120729 usb [panic] fault while in kernel mode with connecting USB o usb/120572 usb [usb67] [umass] [patch] quirk to support ASUS P535 as o usb/120321 usb [hang] System hangs when transferring data to WD MyBoo o usb/120283 usb [panic] Automation reboot with wireless keyboard & mou o usb/120034 usb [hang] 6.2 & 6.3 hangs on boot at usb0: OHCI with 1.5 o usb/119977 usb [ums] Mouse does not work in a Cherry-USB keyboard/mou o usb/119653 usb [cam] [patch] iriver s7 player sync cache error patch o usb/119633 usb [umass] umass0: BBB reset failed, IOERROR [regression] o usb/119513 usb [irq] inserting dlink dwl-g630 wireless card results i o usb/119509 usb [usb] USB flaky on Dell Optiplex 755 o usb/119481 usb [hang] FreeBSD not responding after connecting USB-Mas o usb/119389 usb [umass] Sony DSC-W1 CBI reset failed, STALLED [regress o usb/119227 usb [ubsa] [patch] ubsa buffer is too small; should be tun o usb/119201 usb [cam] [patch] Quirks for Olympus FE-210 camera, LG and o usb/118480 usb [umass] Timeout in USB mass storage freezes vfs layer o usb/118353 usb [panic] [ppp] repeatable kernel panic during ppp(4) se o usb/118141 usb [ucom] usb serial and nokia phones ucomreadcb ucomread o usb/118140 usb [ucom] [patch] quick hack for ucom to get it behave wi o usb/118098 usb [umass] 6th gen iPod causes problems when disconnectin o usb/117955 usb [umass] [panic] inserting minolta dimage a2 crashes OS o usb/117946 usb [panic] D-Link DUB-E100 rev. B1 crashes FreeBSD 7.0-BE o usb/117938 usb [ums] [patch] Adding support for MS WL Natural and MS o usb/117911 usb [ums] [request] Mouse Gembird MUSWC not work o usb/117893 usb [umass] Lacie USB DVD writing failing o usb/117613 usb [uhci] [irq] uhci interrupt storm & USB leaked memory o usb/117598 usb [snd_uaudio] [patch] Not possible to record with Plant o usb/117313 usb [umass] [panic] panic on usb camera insertion o usb/117200 usb [ugen] ugen0 prints strange string on attach if detach o usb/117183 usb [panic] USB/fusefs -- panic while transferring large a p usb/116947 usb [ukbd] [patch] [regression] enable boot protocol on th p usb/116699 usb [usb] [usb67] USB HID devices do not initialize at sys o usb/116561 usb [umodem] [panic] RELENG_6 umodem panic "trying to slee o usb/116282 usb [ulpt] Cannot print on USB HP LJ1018 or LJ1300 o usb/115935 usb [usbdevs] [patch] kernel counterproductively attaches o usb/115933 usb [uftdi] [patch] RATOC REX-USB60F (usb serial converter o usb/115400 usb [ehci] Problem with EHCI on ASUS M2N4-SLI o usb/115298 usb [ulpt] [panic] Turning off USB printer panics kernel o usb/114916 usb [umass] [patch] USB Maxtor drive (L300RO) requires qui o kern/114780 usb [uplcom] [panic] Panics while stress testing the uplco o usb/114682 usb [umass] generic USB media-card reader unusable o usb/114310 usb [libusb] [patch] [panic] USB hub attachment panics ker o usb/114068 usb [usb67] [usb8] [umass] [patch] Problem with connection o conf/114013 usb [patch] WITHOUT_USB allow to compil a lot of USB stuff s usb/113060 usb [usb67] [ulpt] [patch] Samsung printer not working in o usb/110856 usb [usb67] [ugen] [patch] interrupt in msgs are truncated o usb/107827 usb [usb67] [ohci] [panic] ohci_add_done addr not found o usb/107388 usb [usb67] [usb8] [new driver] [patch] add utoppy device o usb/106041 usb [usb67] [usb8] [request] FreeBSD does not recognise Mu o usb/105361 usb [usb67] [panic] Kernel panic during unmounting mass st s usb/103917 usb [usb67] [uhub] USB driver reports "Addr 0 should never o usb/103418 usb [usb67] [usb8] [patch] [request] usbhidctl(8) add abil o usb/103046 usb [usb67] [ulpt] [patch] ulpt event driven I/O with sele p usb/101775 usb [usb67] [libusbhid] [patch] possible error in report d o usb/101761 usb [usb67] [patch] [request] usb.h: increase maximal size o usb/100746 usb [usb67] [ukbd] system does not boot due to USB keyboar o usb/99431 usb [keyboard] FreeBSD on MSI 6566E (Intel 845E motherboar o kern/99200 usb [usb67] SMP-Kernel crashes reliably when Bluetooth con o usb/98343 usb [boot] BBB reset failed errors with Creative Muvo MP3 o usb/97472 usb [cam] [patch] add support for Olympus C150,D390 s usb/97286 usb [mouse] [request] MS Wireless Intellimouse Explorer 2. o usb/97175 usb [umass] [hang] USB cardreader hangs system o usb/96457 usb [umass] [panic] fatback on umass = reboot o usb/96381 usb [cam] [patch] add a quirk table entry for a flash ram o usb/96224 usb [usb] [msdosfs] mount_msdosfs cause page fault in sync s usb/96120 usb [ums] [request] USB mouse not always detected s usb/95636 usb [umass] [boot] 5 minute delay at boot when using VT620 o usb/95562 usb [umass] Write Stress in USB Mass drive causes "vinvalb s usb/95348 usb [keyboard] USB keyboard unplug causes noise on screen o usb/95037 usb [umass] USB disk not recognized on hot-plug. o usb/94897 usb [panic] Kernel Panic when cleanly unmounting USB disk o usb/94717 usb [ulpt] Reading from /dev/ulpt can break work of a UHCI o usb/94384 usb [panic] kernel panic with usb2 hardware o usb/93872 usb [cam] [patch] SCSI quirk required for ELTA 8061 OL USB o usb/93828 usb [ohci] [panic] ohci causes panic on boot (HP Pavillion o usb/93389 usb [umass] [patch] Digital Camera Pentax S60 don't work o usb/92852 usb [ums] [patch] Vertical scroll not working properly on o usb/92171 usb [panic] panic unplugging Vodafone Mobile Connect (UMTS o usb/92142 usb [uhub] SET_ADDR_FAILED and SHORT_XFER errors from usb o usb/92083 usb [ural] [panic] panic using WPA on ural NIC in 6.0-RELE o usb/92052 usb [ulpt] usbd causes defunct process with busy file-hand o usb/91906 usb [ehci] [hang] FreeBSD hangs while booting with USB leg f usb/91896 usb camcontrol(8): Serial Number of USB Memory Sticks is n o usb/91811 usb [umass] Compact Flash in HP Photosmart 2610 return " o usb/91546 usb [umodem] [patch] Nokia 6630 mobile phone does not work o usb/91538 usb [ulpt] [patch] Unable to print to EPSON CX3500 o usb/91283 usb [boot] [regression] booting very slow with usb devices o usb/91238 usb [umass] USB tape unit fails to write a second tape fil o usb/90700 usb [umass] [panic] Kernel panic on connect/mount/use umas o usb/89954 usb [umass] [panic] USB Disk driver race condition? s usb/89003 usb [request] LaCie Firewire drive not properly supported o usb/88743 usb [hang] [regression] USB makes kernel hang at boot (reg o usb/88408 usb [axe] axe0 read PHY failed o usb/87648 usb [mouse] Logitech USB-optical mouse problem. f usb/87224 usb [usb] Cannot mount USB Zip750 o usb/86767 usb [umass] [patch] bogus "slice starts beyond end of the o usb/86298 usb [mouse] Known good USB mouse won't work with correct s s usb/85067 usb [uscanner] Cannot attach ScanJet 4300C to usb device s usb/84336 usb [usb] [reboot] instant system reboot when unmounting a o usb/83977 usb [ucom] [panic] ucom1: open bulk out error (addr 2): IN o usb/83863 usb [ugen] Communication problem between opensc/openct via o usb/83756 usb [ums] [patch] Microsoft Intellimouse Explorer 4.0A doe o usb/83563 usb [umass] [panic] Page Fault while detaching Mpman Usb d o usb/83504 usb [kernel] [patch] SpeedTouch USB stop working on recent s usb/82569 usb [umass] [panic] USB mass storage plug/unplug causes sy o usb/82520 usb [udbp] [reboot] Reboot when USL101 connected o usb/82350 usb [ucom] [panic] null pointer dereference in USB stack o usb/81621 usb [ehci] [hang] external hd hangs under load on ehci o usb/80935 usb [uvisor] [patch] uvisor.c is not work with CLIE TH55. o usb/80854 usb [patch] [request] suggestion for new iface-no-probe me s usb/80777 usb [request] usb_rem_task() should wait for callback to c s usb/80776 usb [udav] [request] UDAV device driver shouldn't use usb_ o usb/80774 usb [patch] have "usbd_find_desc" in line with the other " f usb/80361 usb [umass] [patch] mounting of Dell usb-stick fails f usb/80040 usb [sound] [hang] Use of sound mixer causes system freeze o usb/79723 usb [usb] [request] prepare for high speed isochronous tra o usb/78984 usb [umass] [patch] Creative MUVO umass failure f usb/77294 usb [ucom] [panic] ucom + ulpcom panic o usb/76732 usb [ums] Mouse problems with USB KVM Switch o usb/76653 usb [umass] [patch] Problem with Asahi Optical usb device o usb/76461 usb [umass] disklabel of umass(4)-CAM(4)-da(4) not used by f usb/76395 usb [uhci] USB printer does not work, usbdevs says "addr 0 s usb/75928 usb [umass] [request] Cytronix SmartMedia card (SMC) reade o usb/75800 usb [ucom] ucom1: init failed STALLED error in time of syn f usb/75797 usb [sound] [regression] 5.3-STABLE(2005 1/4) detect USB h o usb/75764 usb [umass] [patch] "umass0: Phase Error" - no device for f usb/75705 usb [umass] [panic] da0 attach / Optio S4 (with backtrace) f usb/74771 usb [umass] [hang] mounting write-protected umass device a s usb/74453 usb [umass] [patch] Q-lity CD-RW USB ECW-043 (ScanLogic SL o usb/74211 usb [umass] USB flash drive causes CAM status 0x4 on 4.10R o usb/73307 usb [panic] Kernel panics on USB disconnect s usb/72733 usb [ucom] [request] Kyocera 7135 Palm OS connection probl o usb/71455 usb [umass] Slow USB umass performance of 5.3 o usb/71417 usb [ugen] Cryptoflex e-gate USB token (ugen0) communicati o usb/71416 usb [ugen] Cryptoflex e-gate USB token (ugen0) detach is n o usb/71280 usb [aue] aue0 device (linksys usb100tx) doesn't work in 1 o usb/71155 usb [ulpt] misbehaving usb-printer hangs processes, causes o usb/70523 usb [umct] [patch] umct sending/receiving wrong characters o usb/69006 usb [usbdevs] [patch] Apple Cinema Display hangs USB ports o usb/68232 usb [ugen] [patch] ugen(4) isochronous handling correction o usb/67301 usb [uftdi] [panic] RTS and system panic o usb/66547 usb [ucom] Palm Tungsten T USB does not initialize correct o usb/63621 usb [umass] [panic] USB MemoryStick Reader stalls/crashes s usb/62257 usb [umass] [request] card reader UCR-61S2B is only half-s o usb/59698 usb [keyboard] [patch] Rework of ukbd HID to AT code trans s bin/57255 usb [patch] usbd(8) and multi-function devices s usb/52026 usb [usb] [request] umass driver support for InSystem ISD2 s usb/51958 usb [urio] [patch] update for urio driver o usb/40948 usb [umass] [request] USB HP CDW8200 does not work o usb/30929 usb [usb] [patch] use usbd to initialize USB ADSL modem 315 problems total. From owner-freebsd-usb@FreeBSD.ORG Mon Nov 22 22:32:44 2010 Return-Path: Delivered-To: freebsd-usb@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D25161065693; Mon, 22 Nov 2010 22:32:44 +0000 (UTC) (envelope-from arundel@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id A85BC8FC12; Mon, 22 Nov 2010 22:32:44 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id oAMMWicc071646; Mon, 22 Nov 2010 22:32:44 GMT (envelope-from arundel@freefall.freebsd.org) Received: (from arundel@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id oAMMWi7H071642; Mon, 22 Nov 2010 22:32:44 GMT (envelope-from arundel) Date: Mon, 22 Nov 2010 22:32:44 GMT Message-Id: <201011222232.oAMMWi7H071642@freefall.freebsd.org> To: maurice@castro.aus.net, arundel@FreeBSD.org, freebsd-usb@FreeBSD.org From: arundel@FreeBSD.org Cc: Subject: Re: usb/122819: [usb67] [patch] Patch to provide dynamic additions to the usb quirks table X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Nov 2010 22:32:44 -0000 Old Synopsis: [usb] [patch] Patch to provide dynamic additions to the usb quirks table New Synopsis: [usb67] [patch] Patch to provide dynamic additions to the usb quirks table State-Changed-From-To: feedback->suspended State-Changed-By: arundel State-Changed-When: Mon Nov 22 22:30:10 UTC 2010 State-Changed-Why: Thank you for your feedback. I've tagged this PR with [usb67]. Due to the fact that there's very little chance that this functionality will be committed to the old USB 1 stack, i've also set it into suspend state. http://www.freebsd.org/cgi/query-pr.cgi?pr=122819 From owner-freebsd-usb@FreeBSD.ORG Mon Nov 22 22:36:14 2010 Return-Path: Delivered-To: freebsd-usb@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4CF091065670; Mon, 22 Nov 2010 22:36:14 +0000 (UTC) (envelope-from arundel@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 22F098FC14; Mon, 22 Nov 2010 22:36:14 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id oAMMaEe9071754; Mon, 22 Nov 2010 22:36:14 GMT (envelope-from arundel@freefall.freebsd.org) Received: (from arundel@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id oAMMaDJK071750; Mon, 22 Nov 2010 22:36:13 GMT (envelope-from arundel) Date: Mon, 22 Nov 2010 22:36:13 GMT Message-Id: <201011222236.oAMMaDJK071750@freefall.freebsd.org> To: fbusse@gmx.de, arundel@FreeBSD.org, freebsd-usb@FreeBSD.org From: arundel@FreeBSD.org Cc: Subject: Re: usb/80361: [umass] [patch] mounting of Dell usb-stick fails X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Nov 2010 22:36:14 -0000 Synopsis: [umass] [patch] mounting of Dell usb-stick fails State-Changed-From-To: feedback->open State-Changed-By: arundel State-Changed-When: Mon Nov 22 22:35:21 UTC 2010 State-Changed-Why: Feedback received. This problem still exists in the new USB stack. http://www.freebsd.org/cgi/query-pr.cgi?pr=80361 From owner-freebsd-usb@FreeBSD.ORG Tue Nov 23 12:30:29 2010 Return-Path: Delivered-To: freebsd-usb@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 88CEE1065672 for ; Tue, 23 Nov 2010 12:30:29 +0000 (UTC) (envelope-from arved@FreeBSD.org) Received: from gazoz.arved.priv.at (cl-1383.ham-01.de.sixxs.net [IPv6:2001:6f8:900:566::2]) by mx1.freebsd.org (Postfix) with ESMTP id 1A6BD8FC21 for ; Tue, 23 Nov 2010 12:30:28 +0000 (UTC) Received: from ferdinand.arved.priv.at (ferdinand-gif0.arved.priv.at [IPv6:2001:6f8:13fb::2]) by gazoz.arved.priv.at (8.14.3/8.14.3) with ESMTP id oANCUPYT007542; Tue, 23 Nov 2010 13:30:25 +0100 (CET) (envelope-from arved@FreeBSD.org) Received: from direk.arved.priv.at (dilek.arved.priv.at [IPv6:2001:6f8:13fb:3:230:1bff:fe45:f2d4] (may be forged)) by ferdinand.arved.priv.at (8.14.4/8.14.4) with ESMTP id oANCUJjv001771; Tue, 23 Nov 2010 13:30:24 +0100 (CET) (envelope-from arved@FreeBSD.org) Message-ID: <4CEBB3DB.4070802@FreeBSD.org> Date: Tue, 23 Nov 2010 13:30:19 +0100 From: =?UTF-8?B?VGlsbWFuIEtlc2tpbsO2eg==?= User-Agent: Mozilla/5.0 (X11; U; FreeBSD amd64; en-US; rv:1.9.2.12) Gecko/20101116 Thunderbird/3.1.6 MIME-Version: 1.0 To: freebsd-usb@FreeBSD.org Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: Subject: Prolific USB Serial adapter not working in 8.x X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Nov 2010 12:30:29 -0000 Hi list, I have a Prolific Serial Adapter which is working fine in FreeBSD 6.x and Linux. But on FreeBSD 8.x It frequently disconnects: ugen0.2: at usbus0 (disconnected) uplcom0: at uhub0, port 2, addr 2 (disconnected) ugen0.2: at usbus0 uplcom0: on usbus0 ugen0.2: at usbus0 (disconnected) uplcom0: at uhub0, port 2, addr 2 (disconnected) usb_alloc_device: set address 2 failed (USB_ERR_STALLED, ignored) usb_alloc_device: getting device descriptor at addr 2 failed, USB_ERR_STALLED usbd_req_re_enumerate: addr=2, set address failed! (USB_ERR_STALLED, ignored) usbd_req_re_enumerate: getting device descriptor at addr 2 failed, USB_ERR_STALLED ugen0.2: at usbus0 uplcom0: on usbus0 Any ideas? regards tilman From owner-freebsd-usb@FreeBSD.ORG Tue Nov 23 22:18:52 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A728B106564A; Tue, 23 Nov 2010 22:18:52 +0000 (UTC) (envelope-from hselasky@c2i.net) Received: from swip.net (mailfe02.c2i.net [212.247.154.34]) by mx1.freebsd.org (Postfix) with ESMTP id C7A958FC14; Tue, 23 Nov 2010 22:18:50 +0000 (UTC) X-Cloudmark-Score: 0.000000 [] X-Cloudmark-Analysis: v=1.1 cv=yevn+QCjI6xy199BDvBOOiO14qYvyLq62he9tTtU3M8= c=1 sm=1 a=CL8lFSKtTFcA:10 a=i9M/sDlu2rpZ9XS819oYzg==:17 a=GKANS73W_H1YUHF9cLYA:9 a=JSGXHWr3w_kZHBXgGGEA:7 a=bg2TYH3fR4Ixh4MHh3pSPB43lbAA:4 a=wPNLvfGTeEIA:10 a=AUm0BtE-NW8nfsnmmIAA:9 a=xy6Nf_H3Id43_UrJgO4A:7 a=UIURJFlpRTt8J218KGRp3c-_B_QA:4 a=QUpfW9hM3dV7orKE:21 a=A32uPXuG2dLAu3s1:21 a=i9M/sDlu2rpZ9XS819oYzg==:117 Received: from [188.126.198.129] (account mc467741@c2i.net HELO laptop002.hselasky.homeunix.org) by mailfe02.swip.net (CommuniGate Pro SMTP 5.2.19) with ESMTPA id 52926160; Tue, 23 Nov 2010 23:18:48 +0100 From: Hans Petter Selasky To: Weongyo Jeong Date: Tue, 23 Nov 2010 23:19:33 +0100 User-Agent: KMail/1.13.5 (FreeBSD/8.1-STABLE; KDE/4.4.5; amd64; ; ) References: <20101123212448.GG92881@weongyo> In-Reply-To: <20101123212448.GG92881@weongyo> X-Face: +~\`s("[*|O,="7?X@L.elg*F"OA\I/3%^p8g?ab%RN'( =?iso-8859-1?q?=3B=5FIjlA=3A=0A=09hGE=2E=2EEw?=, =?iso-8859-1?q?XAQ*o=23=5C/M=7ESC=3DS1-f9=7BEzRfT=27=7CHhll5Q=5Dha5Bt-s=7Co?= =?iso-8859-1?q?TlKMusi=3A1e=5BwJl=7Dkd=7DGR=0A=09Z0adGx-x=5F0zGbZj=27e?=(Y[(UNle~)8CQWXW@:DX+9)_YlB[tIccCPN$7/L' MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_13D7MYPyuRTPmLV" Message-Id: <201011232319.33678.hselasky@c2i.net> Cc: freebsd-usb@freebsd.org, Jung-uk Kim Subject: [RFC] USBdump patches X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Nov 2010 22:18:52 -0000 --Boundary-00=_13D7MYPyuRTPmLV Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hi, Please find attached official usbdump patch from HPS trying to re-use as much as possible of Weongyo's code which was committed not long ago. You need to SVN up to the latest 9-current. This patch should fix all USB-dump issues reported so far! 1) Fix for proper offset calculation on ISOCHRONOUS reception. 2) Fixes for device mode. 3) PF-virtual-machine is OK (and done before copy of data). 4) Can load and unload the PF-code like a module. How to use: cd /usr/src cat usbdump_r215656_patch.txt | patch You need to make new kernel, but not userland. Install sys/dev/usb/usb_pf.h into /usr/include/dev/usb/ and make all install in src/usr.sbin/usbdump . After reboot: kldload usb_pf usbdump -d -1 -vvv man usbdump --HPS --Boundary-00=_13D7MYPyuRTPmLV Content-Type: text/plain; charset="iso-8859-1"; name="usbdump_r215656_patch.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="usbdump_r215656_patch.txt" === sys/conf/files ================================================================== --- sys/conf/files (revision 215656) +++ sys/conf/files (local) @@ -1779,12 +1779,15 @@ dev/usb/usb_mbuf.c optional usb dev/usb/usb_msctest.c optional usb dev/usb/usb_parse.c optional usb -dev/usb/usb_pf.c optional usb dev/usb/usb_process.c optional usb dev/usb/usb_request.c optional usb dev/usb/usb_transfer.c optional usb dev/usb/usb_util.c optional usb # +# USB packet filter +# +dev/usb/usb_pf.c optional usb_pf +# # USB network drivers # dev/usb/net/if_aue.c optional aue === sys/dev/usb/controller/usb_controller.c ================================================================== --- sys/dev/usb/controller/usb_controller.c (revision 215656) +++ sys/dev/usb/controller/usb_controller.c (local) @@ -61,7 +61,6 @@ #include #include -#include /* function prototypes */ @@ -548,8 +547,6 @@ TAILQ_INIT(&bus->intr_q.head); - usbpf_attach(bus, &bus->uif); - #if USB_HAVE_BUSDMA usb_dma_tag_setup(bus->dma_parent_tag, bus->dma_tags, dmat, &bus->bus_mtx, NULL, 32, USB_BUS_DMA_TAG_MAX); @@ -597,34 +594,5 @@ usb_dma_tag_unsetup(bus->dma_parent_tag); #endif - usbpf_detach(bus); - mtx_destroy(&bus->bus_mtx); } - -struct usb_bus * -usb_bus_find(const char *name) -{ - struct usb_bus *ubus; - devclass_t dc; - device_t *devlist; - int devcount, error, i; - const char *nameunit; - - dc = devclass_find("usbus"); - if (dc == NULL) - return (NULL); - error = devclass_get_devices(dc, &devlist, &devcount); - if (error != 0) - return (NULL); - for (i = 0; i < devcount; i++) { - nameunit = device_get_nameunit(devlist[i]); - if (!strncmp(name, nameunit, strlen(nameunit))) { - ubus = device_get_ivars(devlist[i]); - free(devlist, M_TEMP); - return (ubus); - } - } - free(devlist, M_TEMP); - return (NULL); -} === sys/dev/usb/usb_bus.h ================================================================== --- sys/dev/usb/usb_bus.h (revision 215656) +++ sys/dev/usb/usb_bus.h (local) @@ -86,8 +86,6 @@ struct usb_bus_methods *methods; /* filled by HC driver */ struct usb_device **devices; - struct usbpf_if *uif; /* USB Packet Filter */ - usb_power_mask_t hw_power_state; /* see USB_HW_POWER_XXX */ usb_size_t uframe_usage[USB_HS_MICRO_FRAMES_MAX]; === sys/dev/usb/usb_controller.h ================================================================== --- sys/dev/usb/usb_controller.h (revision 215656) +++ sys/dev/usb/usb_controller.h (local) @@ -221,6 +221,5 @@ uint16_t usb_isoc_time_expand(struct usb_bus *bus, uint16_t isoc_time_curr); uint16_t usbd_fs_isoc_schedule_isoc_time_expand(struct usb_device *udev, struct usb_fs_isoc_schedule **pp_start, struct usb_fs_isoc_schedule **pp_end, uint16_t isoc_time); uint8_t usbd_fs_isoc_schedule_alloc(struct usb_fs_isoc_schedule *fss, uint8_t *pstart, uint16_t len); -struct usb_bus *usb_bus_find(const char *name); #endif /* _USB_CONTROLLER_H_ */ === sys/dev/usb/usb_dynamic.c ================================================================== --- sys/dev/usb/usb_dynamic.c (revision 215656) +++ sys/dev/usb/usb_dynamic.c (local) @@ -58,6 +58,9 @@ static usb_temp_unsetup_t usb_temp_unsetup_w; static usb_test_quirk_t usb_test_quirk_w; static usb_quirk_ioctl_t usb_quirk_ioctl_w; +#if USB_HAVE_PF +static usb_pf_xfertap_t usb_pf_xfertap_w; +#endif /* global variables */ usb_handle_req_t *usb_temp_get_desc_p = &usb_temp_get_desc_w; @@ -66,6 +69,9 @@ usb_test_quirk_t *usb_test_quirk_p = &usb_test_quirk_w; usb_quirk_ioctl_t *usb_quirk_ioctl_p = &usb_quirk_ioctl_w; devclass_t usb_devclass_ptr = NULL; +#if USB_HAVE_PF +usb_pf_xfertap_t *usb_pf_xfertap_p = &usb_pf_xfertap_w; +#endif static usb_error_t usb_temp_setup_by_index_w(struct usb_device *udev, uint16_t index) @@ -103,6 +109,14 @@ } } +#if USB_HAVE_PF +static void +usb_pf_xfertap_w(struct usb_xfer *xfer, int type) +{ + /* NOP */ +} +#endif + void usb_quirk_unload(void *arg) { @@ -147,3 +161,19 @@ pause("WAIT", hz); } + +#if USB_HAVE_PF +void +usb_pf_unload(void *arg) +{ + /* reset function pointers */ + + usb_pf_xfertap_p = &usb_pf_xfertap_w; + + /* wait for CPU to exit the loaded functions, if any */ + + /* XXX this is a tradeoff */ + + pause("WAIT", hz); +} +#endif === sys/dev/usb/usb_dynamic.h ================================================================== --- sys/dev/usb/usb_dynamic.h (revision 215656) +++ sys/dev/usb/usb_dynamic.h (local) @@ -32,6 +32,7 @@ struct usb_device; struct usbd_lookup_info; struct usb_device_request; +struct usb_xfer; /* typedefs */ @@ -42,6 +43,7 @@ typedef int (usb_quirk_ioctl_t)(unsigned long cmd, caddr_t data, int fflag, struct thread *td); typedef void (usb_temp_unsetup_t)(struct usb_device *udev); +typedef void (usb_pf_xfertap_t)(struct usb_xfer *, int); /* global function pointers */ @@ -51,11 +53,13 @@ extern usb_test_quirk_t *usb_test_quirk_p; extern usb_quirk_ioctl_t *usb_quirk_ioctl_p; extern devclass_t usb_devclass_ptr; +extern usb_pf_xfertap_t *usb_pf_xfertap_p; /* function prototypes */ void usb_temp_unload(void *); void usb_quirk_unload(void *); void usb_bus_unload(void *); +void usb_pf_unload(void *); #endif /* _USB_DYNAMIC_H_ */ === sys/dev/usb/usb_freebsd.h ================================================================== --- sys/dev/usb/usb_freebsd.h (revision 215656) +++ sys/dev/usb/usb_freebsd.h (local) @@ -41,6 +41,7 @@ #define USB_HAVE_TT_SUPPORT 1 #define USB_HAVE_POWERD 1 #define USB_HAVE_MSCTEST 1 +#define USB_HAVE_PF 1 #define USB_TD_GET_PROC(td) (td)->td_proc #define USB_PROC_GET_GID(td) (td)->p_pgid === sys/dev/usb/usb_pf.c ================================================================== --- sys/dev/usb/usb_pf.c (revision 215656) +++ sys/dev/usb/usb_pf.c (local) @@ -1,11 +1,12 @@ /*- + * Copyright (c) 2010 Hans Petter Selasky. All rights reserved. * Copyright (c) 1990, 1991, 1993 * The Regents of the University of California. All rights reserved. * - * This code is derived from the Stanford/CMU enet packet filter, - * (net/enet.c) distributed as part of 4.3BSD, and code contributed - * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence - * Berkeley Laboratory. + * The packet filter virtual CPU machine code is derived from the + * Stanford/CMU enet packet filter, (net/enet.c) distributed as part + * of 4.3BSD, and code contributed to Berkeley by Steven McCanne and + * Van Jacobson both of Lawrence Berkeley Laboratory. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -34,19 +35,23 @@ #include __FBSDID("$FreeBSD$"); + #include #include #include #include #include +#include #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -54,75 +59,21 @@ #include #include #include +#include /* - * All usbpf implementations are extracted from bpf(9) APIs and it's - * specialized for USB packet filtering between the driver and the host - * controller. + * The virtual CPU machine code has been extracted from bpf(9). */ MALLOC_DEFINE(M_USBPF, "USBPktFilter", "USB Packet Filter"); -/* - * Rotate the packet buffers in descriptor ud. Move the store buffer into the - * hold slot, and the free buffer ino the store slot. Zero the length of the - * new store buffer. Descriptor lock should be held. - */ -#define USBPF_ROTATE_BUFFERS(ud) do { \ - (ud)->ud_hbuf = (ud)->ud_sbuf; \ - (ud)->ud_hlen = (ud)->ud_slen; \ - (ud)->ud_sbuf = (ud)->ud_fbuf; \ - (ud)->ud_slen = 0; \ - (ud)->ud_fbuf = NULL; \ - usbpf_bufheld(ud); \ -} while (0) +MODULE_DEPEND(usb_pf, usb, 1, 1, 1); +MODULE_VERSION(usb_pf, 1); -#ifndef __i386__ -#define USBPF_ALIGN -#endif +static struct mtx usbpf_global_mtx; /* global lock */ +static TAILQ_HEAD(, usbpf_d) usbpf_filters; /* list of filters */ +static struct cdev *usbpf_dev; /* our character device */ -#ifndef USBPF_ALIGN -#define USBPF_EXTRACT_SHORT(p) ((u_int16_t)ntohs(*(u_int16_t *)p)) -#define USBPF_EXTRACT_LONG(p) (ntohl(*(u_int32_t *)p)) -#else -#define USBPF_EXTRACT_SHORT(p) \ - ((u_int16_t) \ - ((u_int16_t)*((u_char *)p+0)<<8| \ - (u_int16_t)*((u_char *)p+1)<<0)) -#define USBPF_EXTRACT_LONG(p) \ - ((u_int32_t)*((u_char *)p+0)<<24| \ - (u_int32_t)*((u_char *)p+1)<<16| \ - (u_int32_t)*((u_char *)p+2)<<8| \ - (u_int32_t)*((u_char *)p+3)<<0) -#endif - -/* - * Number of scratch memory words (for USBPF_LD|USBPF_MEM and USBPF_ST). - */ -#define USBPF_MEMWORDS 16 - -/* Values for ud_state */ -#define USBPF_IDLE 0 /* no select in progress */ -#define USBPF_WAITING 1 /* waiting for read timeout in select */ -#define USBPF_TIMED_OUT 2 /* read timeout has expired in select */ - -#define PRIUSB 26 /* interruptible */ - -/* Frame directions */ -enum usbpf_direction { - USBPF_D_IN, /* See incoming frames */ - USBPF_D_INOUT, /* See incoming and outgoing frames */ - USBPF_D_OUT /* See outgoing frames */ -}; - -static void usbpf_append_bytes(struct usbpf_d *, caddr_t, u_int, void *, - u_int); -static void usbpf_attachd(struct usbpf_d *, struct usbpf_if *); -static void usbpf_detachd(struct usbpf_d *); -static int usbpf_canfreebuf(struct usbpf_d *); -static void usbpf_buf_reclaimed(struct usbpf_d *); -static int usbpf_canwritebuf(struct usbpf_d *); - static d_open_t usbpf_open; static d_read_t usbpf_read; static d_write_t usbpf_write; @@ -141,106 +92,7 @@ .d_kqfilter = usbpf_kqfilter, }; -static LIST_HEAD(, usbpf_if) usbpf_iflist; -static struct mtx usbpf_mtx; /* global lock */ -static int usbpf_uifd_cnt; - -static int usbpf_bufsize = 4096; -#define USBPF_MINBUFSIZE 32 -#define USBPF_MAXBUFSIZE 0x80000 -static int usbpf_maxbufsize = USBPF_MAXBUFSIZE; -#define USBPF_MAXINSNS 512 -static int usbpf_maxinsns = USBPF_MAXINSNS; - -static void -usbpf_buffer_init(struct usbpf_d *ud) -{ - - ud->ud_bufsize = usbpf_bufsize; -} - -/* - * Free USBPF kernel buffers on device close. - */ -static void -usbpf_buffer_free(struct usbpf_d *ud) -{ - - if (ud->ud_sbuf != NULL) - free(ud->ud_sbuf, M_USBPF); - if (ud->ud_hbuf != NULL) - free(ud->ud_hbuf, M_USBPF); - if (ud->ud_fbuf != NULL) - free(ud->ud_fbuf, M_USBPF); - -#ifdef INVARIANTS - ud->ud_sbuf = ud->ud_hbuf = ud->ud_fbuf = (caddr_t)~0; -#endif -} - -static void -usbpf_buffer_alloc(struct usbpf_d *ud) -{ - - KASSERT(ud->ud_fbuf == NULL, ("%s: ud_fbuf != NULL", __func__)); - KASSERT(ud->ud_sbuf == NULL, ("%s: ud_sbuf != NULL", __func__)); - KASSERT(ud->ud_hbuf == NULL, ("%s: ud_hbuf != NULL", __func__)); - - ud->ud_fbuf = (caddr_t)malloc(ud->ud_bufsize, M_USBPF, M_WAITOK); - ud->ud_sbuf = (caddr_t)malloc(ud->ud_bufsize, M_USBPF, M_WAITOK); - ud->ud_hbuf = NULL; - ud->ud_slen = 0; - ud->ud_hlen = 0; -} - -/* - * Copy buffer storage to user space in read(). - */ -static int -usbpf_buffer_uiomove(struct usbpf_d *ud, caddr_t buf, u_int len, - struct uio *uio) -{ - - return (uiomove(buf, len, uio)); -} - -/* - * Simple data copy to the current kernel buffer. - */ -static void -usbpf_buffer_append_bytes(struct usbpf_d *ud, caddr_t buf, u_int offset, - void *src, u_int len) -{ - u_char *src_bytes; - - src_bytes = (u_char *)src; - bcopy(src_bytes, buf + offset, len); -} - -/* - * Allocate or resize buffers. - */ -static int -usbpf_buffer_ioctl_sblen(struct usbpf_d *ud, u_int *i) -{ - u_int size; - - USBPFD_LOCK(ud); - if (ud->ud_bif != NULL) { - USBPFD_UNLOCK(ud); - return (EINVAL); - } - size = *i; - if (size > usbpf_maxbufsize) - *i = size = usbpf_maxbufsize; - else if (size < USBPF_MINBUFSIZE) - *i = size = USBPF_MINBUFSIZE; - ud->ud_bufsize = size; - USBPFD_UNLOCK(ud); - return (0); -} - -static const u_short usbpf_code_map[] = { +static const uint16_t usbpf_code_map[] = { 0x10ff, /* 0x00-0x0f: 1111111100001000 */ 0x3070, /* 0x10-0x1f: 0000111000001100 */ 0x3131, /* 0x20-0x2f: 1000110010001100 */ @@ -270,7 +122,7 @@ * The kernel needs to be able to verify an application's filter code. * Otherwise, a bogus program could easily crash the system. */ -static int +static uint8_t usbpf_validate(const struct usbpf_insn *f, int len) { register int i; @@ -296,13 +148,13 @@ * the code block. */ if (USBPF_CLASS(p->code) == USBPF_JMP) { - register u_int offset; + uint32_t offset; if (p->code == (USBPF_JMP|USBPF_JA)) offset = p->k; else offset = p->jt > p->jf ? p->jt : p->jf; - if (offset >= (u_int)(len - i) - 1) + if (offset >= (uint32_t)(len - i - 1)) return (0); continue; } @@ -325,295 +177,128 @@ return (USBPF_CLASS(f[len - 1].code) == USBPF_RET); } -#ifdef _KERNEL -#define MINDEX(m, k) \ -{ \ - register int len = m->m_len; \ - \ - while (k >= len) { \ - k -= len; \ - m = m->m_next; \ - if (m == 0) \ - return (0); \ - len = m->m_len; \ - } \ -} - -static u_int16_t m_xhalf(struct mbuf *m, usbpf_u_int32 k, int *err); -static u_int32_t m_xword(struct mbuf *m, usbpf_u_int32 k, int *err); - -static u_int32_t -m_xword(struct mbuf *m, usbpf_u_int32 k, int *err) -{ - size_t len; - u_char *cp, *np; - struct mbuf *m0; - - len = m->m_len; - while (k >= len) { - k -= len; - m = m->m_next; - if (m == 0) - goto bad; - len = m->m_len; - } - cp = mtod(m, u_char *) + k; - if (len - k >= 4) { - *err = 0; - return (USBPF_EXTRACT_LONG(cp)); - } - m0 = m->m_next; - if (m0 == 0 || m0->m_len + len - k < 4) - goto bad; - *err = 0; - np = mtod(m0, u_char *); - switch (len - k) { - case 1: - return (((u_int32_t)cp[0] << 24) | - ((u_int32_t)np[0] << 16) | - ((u_int32_t)np[1] << 8) | - (u_int32_t)np[2]); - - case 2: - return (((u_int32_t)cp[0] << 24) | - ((u_int32_t)cp[1] << 16) | - ((u_int32_t)np[0] << 8) | - (u_int32_t)np[1]); - - default: - return (((u_int32_t)cp[0] << 24) | - ((u_int32_t)cp[1] << 16) | - ((u_int32_t)cp[2] << 8) | - (u_int32_t)np[0]); - } - bad: - *err = 1; - return (0); -} - -static u_int16_t -m_xhalf(struct mbuf *m, usbpf_u_int32 k, int *err) -{ - size_t len; - u_char *cp; - struct mbuf *m0; - - len = m->m_len; - while (k >= len) { - k -= len; - m = m->m_next; - if (m == 0) - goto bad; - len = m->m_len; - } - cp = mtod(m, u_char *) + k; - if (len - k >= 2) { - *err = 0; - return (USBPF_EXTRACT_SHORT(cp)); - } - m0 = m->m_next; - if (m0 == 0) - goto bad; - *err = 0; - return ((cp[0] << 8) | mtod(m0, u_char *)[0]); - bad: - *err = 1; - return (0); -} -#endif - /* * Execute the filter program starting at pc on the packet p * wirelen is the length of the original packet * buflen is the amount of data present */ -static u_int -usbpf_filter(const struct usbpf_insn *pc, u_char *p, u_int wirelen, - u_int buflen) +static uint32_t +usbpf_filter_sub(const struct usbpf_insn *pc, + struct usb_page_cache *upc, uint32_t offset, uint32_t buflen) { - u_int32_t A = 0, X = 0; - usbpf_u_int32 k; - u_int32_t mem[USBPF_MEMWORDS]; + uint32_t A = 0; + uint32_t X = 0; + uint32_t k; + uint32_t mem[USBPF_MEMWORDS]; + uint8_t temp[8]; - /* - * XXX temporarily the filter system is disabled because currently it - * could not handle the some machine code properly that leads to - * kernel crash by invalid usage. - */ - return ((u_int)-1); - if (pc == NULL) /* * No filter means accept all. */ - return ((u_int)-1); + return ((uint32_t)-1); --pc; while (1) { ++pc; switch (pc->code) { - default: -#ifdef _KERNEL - return (0); -#else - abort(); -#endif - case USBPF_RET|USBPF_K: - return ((u_int)pc->k); + return ((uint32_t)pc->k); case USBPF_RET|USBPF_A: - return ((u_int)A); + return ((uint32_t)A); case USBPF_LD|USBPF_W|USBPF_ABS: k = pc->k; - if (k > buflen || sizeof(int32_t) > buflen - k) { -#ifdef _KERNEL - int merr; - - if (buflen != 0) - return (0); - A = m_xword((struct mbuf *)p, k, &merr); - if (merr != 0) - return (0); - continue; -#else + if (k > buflen || sizeof(uint32_t) > buflen - k) return (0); -#endif - } -#ifdef USBPF_ALIGN - if (((intptr_t)(p + k) & 3) != 0) - A = USBPF_EXTRACT_LONG(&p[k]); - else -#endif - A = ntohl(*(int32_t *)(p + k)); + + /* get the actual data */ + usbd_copy_out(upc, offset + k, &temp, 4); + + /* get unsigned little endian 32-bit value */ + A = UGETDW(temp); continue; case USBPF_LD|USBPF_H|USBPF_ABS: k = pc->k; - if (k > buflen || sizeof(int16_t) > buflen - k) { -#ifdef _KERNEL - int merr; - - if (buflen != 0) - return (0); - A = m_xhalf((struct mbuf *)p, k, &merr); - continue; -#else + if (k > buflen || sizeof(uint16_t) > buflen - k) return (0); -#endif - } - A = USBPF_EXTRACT_SHORT(&p[k]); + + /* get the actual data */ + usbd_copy_out(upc, offset + k, &temp, 2); + + /* get unsigned little endian 16-bit value */ + A = UGETW(temp); continue; case USBPF_LD|USBPF_B|USBPF_ABS: k = pc->k; - if (k >= buflen) { -#ifdef _KERNEL - struct mbuf *m; - - if (buflen != 0) - return (0); - m = (struct mbuf *)p; - MINDEX(m, k); - A = mtod(m, u_char *)[k]; - continue; -#else + if (k >= buflen) return (0); -#endif - } - A = p[k]; + + /* get the actual data */ + usbd_copy_out(upc, offset + k, &temp, 1); + + A = temp[0]; continue; case USBPF_LD|USBPF_W|USBPF_LEN: - A = wirelen; + A = buflen; continue; case USBPF_LDX|USBPF_W|USBPF_LEN: - X = wirelen; + X = buflen; continue; case USBPF_LD|USBPF_W|USBPF_IND: k = X + pc->k; if (pc->k > buflen || X > buflen - pc->k || - sizeof(int32_t) > buflen - k) { -#ifdef _KERNEL - int merr; - - if (buflen != 0) - return (0); - A = m_xword((struct mbuf *)p, k, &merr); - if (merr != 0) - return (0); - continue; -#else + sizeof(uint32_t) > buflen - k) return (0); -#endif - } -#ifdef USBPF_ALIGN - if (((intptr_t)(p + k) & 3) != 0) - A = USBPF_EXTRACT_LONG(&p[k]); - else -#endif - A = ntohl(*(int32_t *)(p + k)); + + /* get the actual data */ + usbd_copy_out(upc, offset + k, &temp, 4); + + /* get unsigned little endian 32-bit value */ + A = UGETDW(temp); continue; case USBPF_LD|USBPF_H|USBPF_IND: k = X + pc->k; if (X > buflen || pc->k > buflen - X || - sizeof(int16_t) > buflen - k) { -#ifdef _KERNEL - int merr; - - if (buflen != 0) - return (0); - A = m_xhalf((struct mbuf *)p, k, &merr); - if (merr != 0) - return (0); - continue; -#else + sizeof(uint16_t) > buflen - k) return (0); -#endif - } - A = USBPF_EXTRACT_SHORT(&p[k]); + + /* get the actual data */ + usbd_copy_out(upc, offset + k, &temp, 2); + + /* get unsigned little endian 16-bit value */ + A = UGETW(temp); continue; case USBPF_LD|USBPF_B|USBPF_IND: k = X + pc->k; - if (pc->k >= buflen || X >= buflen - pc->k) { -#ifdef _KERNEL - struct mbuf *m; - - if (buflen != 0) - return (0); - m = (struct mbuf *)p; - MINDEX(m, k); - A = mtod(m, u_char *)[k]; - continue; -#else + if (pc->k >= buflen || X >= buflen - pc->k) return (0); -#endif - } - A = p[k]; + + /* get the actual data */ + usbd_copy_out(upc, offset + k, &temp, 1); + + /* get 8-bit value */ + A = temp[0]; continue; case USBPF_LDX|USBPF_MSH|USBPF_B: k = pc->k; - if (k >= buflen) { -#ifdef _KERNEL - register struct mbuf *m; - - if (buflen != 0) - return (0); - m = (struct mbuf *)p; - MINDEX(m, k); - X = (mtod(m, u_char *)[k] & 0xf) << 2; - continue; -#else + if (k >= buflen) return (0); -#endif - } - X = (p[pc->k] & 0xf) << 2; + + /* get the actual data */ + usbd_copy_out(upc, offset + k, &temp, 1); + + /* get 4-bit value */ + X = (temp[0] & 0xf) << 2; continue; case USBPF_LD|USBPF_IMM: @@ -753,51 +438,39 @@ case USBPF_MISC|USBPF_TXA: A = X; continue; + default: + return (0); } } } -static void -usbpf_free(struct usbpf_d *ud) +static uint8_t +usbpf_filter(struct usbpf_d *ud, struct usbpf_pkthdr_first *hdr) { + if (ud->ud_running == 0) + return (0); - switch (ud->ud_bufmode) { - case USBPF_BUFMODE_BUFFER: - return (usbpf_buffer_free(ud)); - default: - panic("usbpf_buf_free"); - } -} + /* match bus unit */ + if (ud->ud_filter.ua_bus_unit != USBPF_IFREQ_ANY && + ud->ud_filter.ua_bus_unit != hdr->up_busunit) + return (0); -/* - * Notify the buffer model that a buffer has moved into the hold position. - */ -static void -usbpf_bufheld(struct usbpf_d *ud) -{ + /* match device unit (this is not the device address) */ + if (ud->ud_filter.ua_dev_unit != USBPF_IFREQ_ANY && + ud->ud_filter.ua_dev_unit != hdr->up_devunit) + return (0); - USBPFD_LOCK_ASSERT(ud); -} + /* match endpoint */ + if (ud->ud_filter.ua_endpoint_mask != USBPF_IFREQ_ANY) { + uint8_t shift; -/* - * Free buffers currently in use by a descriptor. - * Called on close. - */ -static void -usbpf_freed(struct usbpf_d *ud) -{ + shift = (2 * (hdr->up_endpoint & UE_ADDR)) | + ((hdr->up_endpoint & (UE_DIR_IN | UE_DIR_OUT)) ? 1 : 0); - /* - * We don't need to lock out interrupts since this descriptor has - * been detached from its interface and it yet hasn't been marked - * free. - */ - usbpf_free(ud); - if (ud->ud_rfilter != NULL) - free((caddr_t)ud->ud_rfilter, M_USBPF); - if (ud->ud_wfilter != NULL) - free((caddr_t)ud->ud_wfilter, M_USBPF); - mtx_destroy(&ud->ud_mtx); + if (!(ud->ud_filter.ua_endpoint_mask & (1U << shift))) + return (0); + } + return (1); /* accept */ } /* @@ -808,28 +481,32 @@ usbpf_dtor(void *data) { struct usbpf_d *ud = data; + struct usbpf_pkthdr *phdr; - USBPFD_LOCK(ud); - if (ud->ud_state == USBPF_WAITING) - callout_stop(&ud->ud_callout); - ud->ud_state = USBPF_IDLE; - USBPFD_UNLOCK(ud); - funsetown(&ud->ud_sigio); - mtx_lock(&usbpf_mtx); - if (ud->ud_bif) - usbpf_detachd(ud); - mtx_unlock(&usbpf_mtx); - selwakeuppri(&ud->ud_sel, PRIUSB); + USBPFD_GLOBAL_LOCK(); + + ud->ud_running = 0; + + while ((phdr = TAILQ_FIRST(&ud->ud_head)) != NULL) { + TAILQ_REMOVE(&ud->ud_head, phdr, reserved.entry); + ud->ud_queue_len--; + free(phdr, M_USBPF); + } + + TAILQ_REMOVE(&usbpf_filters, ud, ud_next); + + USBPFD_GLOBAL_UNLOCK(); + + selwakeup(&ud->ud_sel); + knlist_destroy(&ud->ud_sel.si_note); - callout_drain(&ud->ud_callout); - usbpf_freed(ud); + + if (ud->ud_filter_code) + free(ud->ud_filter_code, M_USBPF); + free(ud, M_USBPF); } -/* - * Open device. Returns ENXIO for illegal minor device number, - * EBUSY if file is open by another process. - */ /* ARGSUSED */ static int usbpf_open(struct cdev *dev, int flags, int fmt, struct thread *td) @@ -844,25 +521,15 @@ return (error); } - usbpf_buffer_init(ud); - ud->ud_bufmode = USBPF_BUFMODE_BUFFER; - ud->ud_sig = SIGIO; - ud->ud_direction = USBPF_D_INOUT; - ud->ud_pid = td->td_proc->p_pid; - mtx_init(&ud->ud_mtx, devtoname(dev), "usbpf cdev lock", MTX_DEF); - callout_init_mtx(&ud->ud_callout, &ud->ud_mtx, 0); - knlist_init_mtx(&ud->ud_sel.si_note, &ud->ud_mtx); + TAILQ_INIT(&ud->ud_head); - return (0); -} + knlist_init_mtx(&ud->ud_sel.si_note, &usbpf_global_mtx); -static int -usbpf_uiomove(struct usbpf_d *ud, caddr_t buf, u_int len, struct uio *uio) -{ + USBPFD_GLOBAL_LOCK(); + TAILQ_INSERT_TAIL(&usbpf_filters, ud, ud_next); + USBPFD_GLOBAL_UNLOCK(); - if (ud->ud_bufmode != USBPF_BUFMODE_BUFFER) - return (EOPNOTSUPP); - return (usbpf_buffer_uiomove(ud, buf, len, uio)); + return (0); } /* @@ -872,120 +539,75 @@ usbpf_read(struct cdev *dev, struct uio *uio, int ioflag) { struct usbpf_d *ud; + struct usbpf_pkthdr *phdr; int error; int non_block; - int timed_out; + int moved_data; error = devfs_get_cdevpriv((void **)&ud); if (error != 0) return (error); - /* - * Restrict application to use a buffer the same size as - * as kernel buffers. - */ - if (uio->uio_resid != ud->ud_bufsize) - return (EINVAL); - non_block = ((ioflag & O_NONBLOCK) != 0); + moved_data = 0; - USBPFD_LOCK(ud); - ud->ud_pid = curthread->td_proc->p_pid; - if (ud->ud_bufmode != USBPF_BUFMODE_BUFFER) { - USBPFD_UNLOCK(ud); - return (EOPNOTSUPP); - } - if (ud->ud_state == USBPF_WAITING) - callout_stop(&ud->ud_callout); - timed_out = (ud->ud_state == USBPF_TIMED_OUT); - ud->ud_state = USBPF_IDLE; - /* - * If the hold buffer is empty, then do a timed sleep, which - * ends when the timeout expires or when enough packets - * have arrived to fill the store buffer. - */ - while (ud->ud_hbuf == NULL) { - if (ud->ud_slen != 0) { - /* - * A packet(s) either arrived since the previous - * read or arrived while we were asleep. - */ - if (ud->ud_immediate || non_block || timed_out) { - /* - * Rotate the buffers and return what's here - * if we are in immediate mode, non-blocking - * flag is set, or this descriptor timed out. - */ - USBPF_ROTATE_BUFFERS(ud); + USBPFD_GLOBAL_LOCK(); + + while (1) { + while ((phdr = TAILQ_FIRST(&ud->ud_head)) != NULL) { + + int totlen; + + totlen = le32toh(phdr->hdr.up_totlen); + + if (uio->uio_resid >= totlen) { + + TAILQ_REMOVE(&ud->ud_head, phdr, reserved.entry); + ud->ud_queue_len--; + + memset(&phdr->reserved.entry, 0, sizeof(phdr->reserved.entry)); + + USBPFD_GLOBAL_UNLOCK(); + + error = uiomove(phdr, totlen, uio); + + USBPFD_GLOBAL_LOCK(); + + free(phdr, M_USBPF); + + moved_data = 1; + + if (error) + break; + + } else if (moved_data == 0) { + + /* size too big */ + + ud->ud_dcount++; + + TAILQ_REMOVE(&ud->ud_head, phdr, reserved.entry); + ud->ud_queue_len--; + + free(phdr, M_USBPF); + } else { break; } } - /* - * No data is available, check to see if the usbpf device - * is still pointed at a real interface. If not, return - * ENXIO so that the userland process knows to rebind - * it before using it again. - */ - if (ud->ud_bif == NULL) { - USBPFD_UNLOCK(ud); - return (ENXIO); - } + if (moved_data || non_block || ud->ud_running == 0) + break; - if (non_block) { - USBPFD_UNLOCK(ud); - return (EWOULDBLOCK); - } - error = msleep(ud, &ud->ud_mtx, PRIUSB|PCATCH, - "uff", ud->ud_rtout); - if (error == EINTR || error == ERESTART) { - USBPFD_UNLOCK(ud); - return (error); - } - if (error == EWOULDBLOCK) { - /* - * On a timeout, return what's in the buffer, - * which may be nothing. If there is something - * in the store buffer, we can rotate the buffers. - */ - if (ud->ud_hbuf) - /* - * We filled up the buffer in between - * getting the timeout and arriving - * here, so we don't need to rotate. - */ - break; + error = msleep(ud, &usbpf_global_mtx, PCATCH, "upf", ud->ud_rtout); - if (ud->ud_slen == 0) { - USBPFD_UNLOCK(ud); - return (0); - } - USBPF_ROTATE_BUFFERS(ud); + if (error || ud->ud_running == 0) break; - } } - /* - * At this point, we know we have something in the hold slot. - */ - USBPFD_UNLOCK(ud); - /* - * Move data from hold buffer into user space. - * We know the entire buffer is transferred since - * we checked above that the read buffer is usbpf_bufsize bytes. - * - * XXXRW: More synchronization needed here: what if a second thread - * issues a read on the same fd at the same time? Don't want this - * getting invalidated. - */ - error = usbpf_uiomove(ud, ud->ud_hbuf, ud->ud_hlen, uio); + if (ud->ud_running == 0) + error = EINVAL; - USBPFD_LOCK(ud); - ud->ud_fbuf = ud->ud_hbuf; - ud->ud_hbuf = NULL; - ud->ud_hlen = 0; - usbpf_buf_reclaimed(ud); - USBPFD_UNLOCK(ud); + USBPFD_GLOBAL_UNLOCK(); return (error); } @@ -998,141 +620,58 @@ return (ENOSYS); } -static int -usbpf_ioctl_sblen(struct usbpf_d *ud, u_int *i) -{ - - if (ud->ud_bufmode != USBPF_BUFMODE_BUFFER) - return (EOPNOTSUPP); - return (usbpf_buffer_ioctl_sblen(ud, i)); -} - -/* - * Reset a descriptor by flushing its packet buffer and clearing the receive - * and drop counts. This is doable for kernel-only buffers, but with - * zero-copy buffers, we can't write to (or rotate) buffers that are - * currently owned by userspace. It would be nice if we could encapsulate - * this logic in the buffer code rather than here. - */ static void usbpf_reset_d(struct usbpf_d *ud) { + USBPFD_GLOBAL_ASSERT_LOCKED(); - USBPFD_LOCK_ASSERT(ud); - - if ((ud->ud_hbuf != NULL) && - (ud->ud_bufmode != USBPF_BUFMODE_ZBUF || usbpf_canfreebuf(ud))) { - /* Free the hold buffer. */ - ud->ud_fbuf = ud->ud_hbuf; - ud->ud_hbuf = NULL; - ud->ud_hlen = 0; - usbpf_buf_reclaimed(ud); - } - if (usbpf_canwritebuf(ud)) - ud->ud_slen = 0; ud->ud_rcount = 0; ud->ud_dcount = 0; - ud->ud_fcount = 0; - ud->ud_wcount = 0; - ud->ud_wfcount = 0; - ud->ud_wdcount = 0; - ud->ud_zcopy = 0; } static int usbpf_setif(struct usbpf_d *ud, struct usbpf_ifreq *ufr) { - struct usbpf_if *uif; - struct usb_bus *theywant; + struct usbpf_insn *pfilt; + struct usbpf_insn *ofilt; + uint32_t lfilt; + uint32_t size; - theywant = usb_bus_find(ufr->ufr_name); - if (theywant == NULL || theywant->uif == NULL) - return (ENXIO); + if (ufr->ua_filter_len != 0) { + lfilt = ufr->ua_filter_len; + if (lfilt > USBPF_MAX_FILTER) + return (E2BIG); + size = lfilt * sizeof(struct usbpf_insn); + pfilt = malloc(size, M_USBPF, M_WAITOK); + if (pfilt == NULL) + return (ENOMEM); + if (copyin(ufr->ua_filter_ptr, pfilt, size) != 0) { + free(pfilt, M_USBPF); + return (EFAULT); + } + if (usbpf_validate(pfilt, lfilt) != 0) { + free(pfilt, M_USBPF); + return (EINVAL); + } + } else { + pfilt = NULL; + } - uif = theywant->uif; + USBPFD_GLOBAL_LOCK(); - switch (ud->ud_bufmode) { - case USBPF_BUFMODE_BUFFER: - if (ud->ud_sbuf == NULL) - usbpf_buffer_alloc(ud); - KASSERT(ud->ud_sbuf != NULL, ("%s: ud_sbuf == NULL", __func__)); - break; + ofilt = ud->ud_filter_code; + ud->ud_filter_code = pfilt; - default: - panic("usbpf_setif: bufmode %d", ud->ud_bufmode); - } - if (uif != ud->ud_bif) { - if (ud->ud_bif) - /* - * Detach if attached to something else. - */ - usbpf_detachd(ud); + ud->ud_filter = *ufr; + ud->ud_running = 1; - usbpf_attachd(ud, uif); - } - USBPFD_LOCK(ud); usbpf_reset_d(ud); - USBPFD_UNLOCK(ud); - return (0); -} -/* - * Set d's packet filter program to fp. If this file already has a filter, - * free it and replace it. Returns EINVAL for bogus requests. - */ -static int -usbpf_setf(struct usbpf_d *ud, struct usbpf_program *fp, u_long cmd) -{ - struct usbpf_insn *fcode, *old; - u_int wfilter, flen, size; + USBPFD_GLOBAL_UNLOCK(); - if (cmd == UIOCSETWF) { - old = ud->ud_wfilter; - wfilter = 1; - } else { - wfilter = 0; - old = ud->ud_rfilter; - } - if (fp->uf_insns == NULL) { - if (fp->uf_len != 0) - return (EINVAL); - USBPFD_LOCK(ud); - if (wfilter) - ud->ud_wfilter = NULL; - else { - ud->ud_rfilter = NULL; - if (cmd == UIOCSETF) - usbpf_reset_d(ud); - } - USBPFD_UNLOCK(ud); - if (old != NULL) - free((caddr_t)old, M_USBPF); - return (0); - } - flen = fp->uf_len; - if (flen > usbpf_maxinsns) - return (EINVAL); + free(ofilt, M_USBPF); - size = flen * sizeof(*fp->uf_insns); - fcode = (struct usbpf_insn *)malloc(size, M_USBPF, M_WAITOK); - if (copyin((caddr_t)fp->uf_insns, (caddr_t)fcode, size) == 0 && - usbpf_validate(fcode, (int)flen)) { - USBPFD_LOCK(ud); - if (wfilter) - ud->ud_wfilter = fcode; - else { - ud->ud_rfilter = fcode; - if (cmd == UIOCSETF) - usbpf_reset_d(ud); - } - USBPFD_UNLOCK(ud); - if (old != NULL) - free((caddr_t)old, M_USBPF); - - return (0); - } - free((caddr_t)fcode, M_USBPF); - return (EINVAL); + return (0); } static int @@ -1146,55 +685,15 @@ if (error != 0) return (error); - /* - * Refresh PID associated with this descriptor. - */ - USBPFD_LOCK(ud); - ud->ud_pid = td->td_proc->p_pid; - if (ud->ud_state == USBPF_WAITING) - callout_stop(&ud->ud_callout); - ud->ud_state = USBPF_IDLE; - USBPFD_UNLOCK(ud); - - if (ud->ud_locked == 1) { - switch (cmd) { - case UIOCGBLEN: - case UIOCSBLEN: - case UIOCVERSION: - break; - default: - return (EPERM); - } - } - switch (cmd) { - - default: - error = EINVAL; - break; - /* - * Get buffer len [for read()]. + * Get maximum data length including packet header. */ case UIOCGBLEN: - *(u_int *)addr = ud->ud_bufsize; + *(long *)addr = USBPF_MAX_BUFFER_LEN; break; /* - * Set buffer length. - */ - case UIOCSBLEN: - error = usbpf_ioctl_sblen(ud, (u_int *)addr); - break; - - /* - * Set read filter. - */ - case UIOCSETF: - error = usbpf_setf(ud, (struct usbpf_program *)addr, cmd); - break; - - /* * Set read timeout. */ case UIOCSRTIMEOUT: @@ -1229,7 +728,6 @@ { struct usbpf_stat *us = (struct usbpf_stat *)addr; - /* XXXCSJP overflow */ us->us_recv = ud->ud_rcount; us->us_drop = ud->ud_dcount; break; @@ -1251,6 +749,9 @@ error = usbpf_setif(ud, (struct usbpf_ifreq *)addr); break; + default: + error = ENOTTY; + break; } return (error); } @@ -1264,9 +765,9 @@ static int usbpf_poll(struct cdev *dev, int events, struct thread *td) { - /* NOT IMPLEMENTED */ - return (ENOSYS); + /* NOTE: This function does not return an error code! */ + return (events & (POLLHUP | POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM)); } /* @@ -1282,581 +783,319 @@ } /* - * Attach file to the usbpf interface, i.e. make d listen on bp. + * If there are processes sleeping on this descriptor, wake them up. */ static void -usbpf_attachd(struct usbpf_d *ud, struct usbpf_if *uif) +usbpf_wakeup(struct usbpf_d *ud) { + USBPFD_GLOBAL_ASSERT_LOCKED(); - USBPFIF_LOCK(uif); - ud->ud_bif = uif; - LIST_INSERT_HEAD(&uif->uif_dlist, ud, ud_next); + wakeup(ud); - usbpf_uifd_cnt++; - USBPFIF_UNLOCK(uif); -} + selwakeup(&ud->ud_sel); -/* - * Detach a file from its interface. - */ -static void -usbpf_detachd(struct usbpf_d *ud) -{ - struct usbpf_if *uif; - struct usb_bus *ubus; - - uif = ud->ud_bif; - USBPFIF_LOCK(uif); - USBPFD_LOCK(ud); - ubus = ud->ud_bif->uif_ubus; - - /* - * Remove d from the interface's descriptor list. - */ - LIST_REMOVE(ud, ud_next); - - usbpf_uifd_cnt--; - ud->ud_bif = NULL; - USBPFD_UNLOCK(ud); - USBPFIF_UNLOCK(uif); + KNOTE_LOCKED(&ud->ud_sel.si_note, 0); } -void -usbpf_attach(struct usb_bus *ubus, struct usbpf_if **driverp) +static uint32_t +usbpf_get_xfer_flags(struct usb_xfer *xfer, uint32_t frame) { - struct usbpf_if *uif; + uint32_t temp = 0; + uint8_t isread; - uif = malloc(sizeof(*uif), M_USBPF, M_WAITOK | M_ZERO); - LIST_INIT(&uif->uif_dlist); - uif->uif_ubus = ubus; - mtx_init(&uif->uif_mtx, "usbpf interface lock", NULL, MTX_DEF); - KASSERT(*driverp == NULL, - ("usbpf_attach: driverp already initialized")); - *driverp = uif; + if ((frame == 0) && xfer->flags_int.control_xfr && + xfer->flags_int.control_hdr) { + /* special case */ + if (xfer->flags_int.usb_mode == USB_MODE_DEVICE) { + /* The device controller writes to memory */ + isread = 1; + } else { + /* The host controller reads from memory */ + isread = 0; + } + } else { + isread = USB_GET_DATA_ISREAD(xfer); + } - mtx_lock(&usbpf_mtx); - LIST_INSERT_HEAD(&usbpf_iflist, uif, uif_next); - mtx_unlock(&usbpf_mtx); + if (isread) + temp |= USBPF_XFERFLAG_READ; + if (xfer->flags.short_xfer_ok) + temp |= USBPF_XFERFLAG_SHORT_OK; + if (xfer->flags.short_frames_ok) + temp |= USBPF_XFERFLAG_MULTI_SHORT_OK; + if (xfer->flags.force_short_xfer) + temp |= USBPF_XFERFLAG_FORCE_SHORT; + if (xfer->flags.stall_pipe) + temp |= USBPF_XFERFLAG_STALL_PIPE; + if (xfer->flags_int.control_act == 1) + temp |= USBPF_XFERFLAG_CONTROL_ACT; - if (bootverbose) - device_printf(ubus->parent, "usbpf attached\n"); + return (temp); } -/* - * If there are processes sleeping on this descriptor, wake them up. - */ -static __inline void -usbpf_wakeup(struct usbpf_d *ud) +static void +usbpf_xfertap_sub(struct usb_xfer *xfer, struct usbpf_d *ud, + struct usbpf_pkthdr_first *fhdr, int type) { + struct usbpf_pkthdr *hdr; + uint32_t *ptr; + uint32_t x; + uint32_t offset; + uint32_t frame; + uint32_t filter_length; - USBPFD_LOCK_ASSERT(ud); - if (ud->ud_state == USBPF_WAITING) { - callout_stop(&ud->ud_callout); - ud->ud_state = USBPF_IDLE; + if (ud->ud_queue_len >= USBPF_MAX_QUEUE_LEN) { + ud->ud_dcount++; + return; } - wakeup(ud); - if (ud->ud_async && ud->ud_sig && ud->ud_sigio) - pgsigio(&ud->ud_sigio, ud->ud_sig, 0); - selwakeuppri(&ud->ud_sel, PRIUSB); - KNOTE_LOCKED(&ud->ud_sel.si_note, 0); -} - -void -usbpf_detach(struct usb_bus *ubus) -{ - struct usbpf_if *uif; - struct usbpf_d *ud; - - /* Locate USBPF interface information */ - mtx_lock(&usbpf_mtx); - LIST_FOREACH(uif, &usbpf_iflist, uif_next) { - if (ubus == uif->uif_ubus) - break; - } - - /* Interface wasn't attached */ - if ((uif == NULL) || (uif->uif_ubus == NULL)) { - mtx_unlock(&usbpf_mtx); - printf("usbpf_detach: not attached\n"); /* XXX */ + ptr = malloc(fhdr->up_totlen, M_USBPF, M_NOWAIT); + if (ptr == NULL) { + ud->ud_dcount++; return; } - LIST_REMOVE(uif, uif_next); - mtx_unlock(&usbpf_mtx); + hdr = (struct usbpf_pkthdr *)ptr; - while ((ud = LIST_FIRST(&uif->uif_dlist)) != NULL) { - usbpf_detachd(ud); - USBPFD_LOCK(ud); - usbpf_wakeup(ud); - USBPFD_UNLOCK(ud); - } + /* do endian conversion of header */ - mtx_destroy(&uif->uif_mtx); - free(uif, M_USBPF); -} + hdr->hdr.up_sec = htole64(fhdr->up_sec); + hdr->hdr.up_frac = htole64(fhdr->up_frac); + hdr->hdr.up_busunit = htole32(fhdr->up_busunit); + hdr->hdr.up_frames = htole32(fhdr->up_frames); + hdr->hdr.up_hdrlen = htole32(sizeof(hdr->hdr)); + hdr->hdr.up_interval = htole32(fhdr->up_interval); + hdr->hdr.up_status = htole32(fhdr->up_status); + hdr->hdr.up_totlen = htole32(fhdr->up_totlen); + hdr->hdr.up_error = htole32(fhdr->up_error); + hdr->hdr.up_packet_size = htole32(fhdr->up_packet_size); + hdr->hdr.up_packet_count = htole32(fhdr->up_packet_count); + hdr->hdr.up_devunit = fhdr->up_devunit; + hdr->hdr.up_dmode = fhdr->up_dmode; + hdr->hdr.up_endpoint = fhdr->up_endpoint; + hdr->hdr.up_type = fhdr->up_type; + hdr->hdr.up_xfertype = fhdr->up_xfertype; -/* Time stamping functions */ -#define USBPF_T_MICROTIME 0x0000 -#define USBPF_T_NANOTIME 0x0001 -#define USBPF_T_BINTIME 0x0002 -#define USBPF_T_NONE 0x0003 -#define USBPF_T_FORMAT_MASK 0x0003 -#define USBPF_T_NORMAL 0x0000 -#define USBPF_T_FAST 0x0100 -#define USBPF_T_MONOTONIC 0x0200 -#define USBPF_T_FORMAT(t) ((t) & USBPF_T_FORMAT_MASK) + ptr = (uint32_t *)(hdr + 1); -#define USBPF_TSTAMP_NONE 0 -#define USBPF_TSTAMP_FAST 1 -#define USBPF_TSTAMP_NORMAL 2 + /* copy all data last */ -static int -usbpf_ts_quality(int tstype) -{ + offset = 0; + frame = 0; - if (tstype == USBPF_T_NONE) - return (USBPF_TSTAMP_NONE); - if ((tstype & USBPF_T_FAST) != 0) - return (USBPF_TSTAMP_FAST); + for (x = 0; x != xfer->nframes; x++) { + uint32_t length; + uint32_t temp; - return (USBPF_TSTAMP_NORMAL); -} + /* get length and flags */ + length = xfer->frlengths[x]; + temp = usbpf_get_xfer_flags(xfer, x); -static int -usbpf_gettime(struct bintime *bt, int tstype) -{ - int quality; + /* check if we need to copy any data */ + if (temp & USBPF_XFERFLAG_READ) { + if (type == USBPF_XFERTAP_SUBMIT) + length = 0; + } else { + if (type != USBPF_XFERTAP_SUBMIT) + length = 0; + } - quality = usbpf_ts_quality(tstype); - if (quality == USBPF_TSTAMP_NONE) - return (quality); - if (quality == USBPF_TSTAMP_NORMAL) - binuptime(bt); - else - getbinuptime(bt); + /* fill out packet header */ + ptr[0] = htole32(length); + ptr[1] = htole32(temp); - return (quality); -} + /* copy USB data, if any */ + if (length != 0) { + /* there is a data buffer after the length and flags */ + ptr[1] |= htole32(USBPF_XFERFLAG_DATA_FOLLOWS); -/* - * If the buffer mechanism has a way to decide that a held buffer can be made - * free, then it is exposed via the usbpf_canfreebuf() interface. (1) is - * returned if the buffer can be discarded, (0) is returned if it cannot. - */ -static int -usbpf_canfreebuf(struct usbpf_d *ud) -{ + /* run filter */ + filter_length = usbpf_filter_sub(ud->ud_filter_code, + &xfer->frbuffers[frame], offset, length); - USBPFD_LOCK_ASSERT(ud); + /* get actual amount of data to copy */ + if (filter_length >= length) + filter_length = length; + else { + uint32_t totlen; + /* update total length */ + totlen = le32toh(hdr->hdr.up_totlen); + totlen -= USBPF_LENGTH_ALIGN(length); + totlen += USBPF_LENGTH_ALIGN(filter_length); + hdr->hdr.up_totlen = htole32(totlen); + } - return (0); -} + ptr[2] = htole32(filter_length); + ptr += USBPF_FRAMEHDR_SIZE; -/* - * Allow the buffer model to indicate that the current store buffer is - * immutable, regardless of the appearance of space. Return (1) if the - * buffer is writable, and (0) if not. - */ -static int -usbpf_canwritebuf(struct usbpf_d *ud) -{ + /* zero-pad the last 32-bits in case of aligment */ + ptr[(filter_length - 1) / 4] = 0; - USBPFD_LOCK_ASSERT(ud); - return (1); -} + /* copy data */ + usbd_copy_out(&xfer->frbuffers[frame], offset, ptr, filter_length); -/* - * Notify buffer model that an attempt to write to the store buffer has - * resulted in a dropped packet, in which case the buffer may be considered - * full. - */ -static void -usbpf_buffull(struct usbpf_d *ud) -{ + /* align length */ + length = USBPF_LENGTH_ALIGN(filter_length); - USBPFD_LOCK_ASSERT(ud); -} + /* advance data pointer */ + ptr += length / 4; + } else { + ptr[2] = 0; + ptr += USBPF_FRAMEHDR_SIZE; + } -/* - * This function gets called when the free buffer is re-assigned. - */ -static void -usbpf_buf_reclaimed(struct usbpf_d *ud) -{ - - USBPFD_LOCK_ASSERT(ud); - - switch (ud->ud_bufmode) { - case USBPF_BUFMODE_BUFFER: - return; - - default: - panic("usbpf_buf_reclaimed"); + if (xfer->flags_int.isochronous_xfr) { +#if USB_HAVE_PF + offset += xfer->frlengths[x + xfer->max_frame_count]; +#endif + } else { + frame ++; + } } -} -#define SIZEOF_USBPF_HDR(type) \ - (offsetof(type, uh_hdrlen) + sizeof(((type *)0)->uh_hdrlen)) + /* clear reserved area */ + memset(&hdr->reserved, 0, sizeof(hdr->reserved)); -static int -usbpf_hdrlen(struct usbpf_d *ud) -{ - int hdrlen; + /* enqueue header */ + TAILQ_INSERT_TAIL(&ud->ud_head, hdr, reserved.entry); + ud->ud_queue_len++; - hdrlen = ud->ud_bif->uif_hdrlen; - hdrlen += SIZEOF_USBPF_HDR(struct usbpf_xhdr); - hdrlen = USBPF_WORDALIGN(hdrlen); - - return (hdrlen - ud->ud_bif->uif_hdrlen); + /* wakeup any sleeping receiver */ + usbpf_wakeup(ud); } static void -usbpf_bintime2ts(struct bintime *bt, struct usbpf_ts *ts, int tstype) +usbpf_xfertap(struct usb_xfer *xfer, int type) { - struct bintime bt2; + struct usbpf_pkthdr_first fhdr; + struct usb_xfer_root *info; + struct usb_bus *bus; + struct usbpf_d *ud; struct timeval tsm; - struct timespec tsn; + struct bintime bt; + uint32_t totlen; + uint32_t x; - if ((tstype & USBPF_T_MONOTONIC) == 0) { - bt2 = *bt; - bintime_add(&bt2, &boottimebin); - bt = &bt2; + USBPFD_GLOBAL_LOCK(); + if (TAILQ_FIRST(&usbpf_filters) == NULL) { + USBPFD_GLOBAL_UNLOCK(); + /* no filters no work */ + return; } - switch (USBPF_T_FORMAT(tstype)) { - case USBPF_T_MICROTIME: - bintime2timeval(bt, &tsm); - ts->ut_sec = tsm.tv_sec; - ts->ut_frac = tsm.tv_usec; - break; - case USBPF_T_NANOTIME: - bintime2timespec(bt, &tsn); - ts->ut_sec = tsn.tv_sec; - ts->ut_frac = tsn.tv_nsec; - break; - case USBPF_T_BINTIME: - ts->ut_sec = bt->sec; - ts->ut_frac = bt->frac; - break; - } -} -/* - * Move the packet data from interface memory (pkt) into the - * store buffer. "cpfn" is the routine called to do the actual data - * transfer. bcopy is passed in to copy contiguous chunks, while - * usbpf_append_mbuf is passed in to copy mbuf chains. In the latter case, - * pkt is really an mbuf. - */ -static void -catchpacket(struct usbpf_d *ud, u_char *pkt, u_int pktlen, u_int snaplen, - void (*cpfn)(struct usbpf_d *, caddr_t, u_int, void *, u_int), - struct bintime *bt) -{ - struct usbpf_xhdr hdr; - int caplen, curlen, hdrlen, totlen; - int do_wakeup = 0; - int do_timestamp; - int tstype; + info = xfer->xroot; + bus = info->bus; - USBPFD_LOCK_ASSERT(ud); - - /* - * Detect whether user space has released a buffer back to us, and if - * so, move it from being a hold buffer to a free buffer. This may - * not be the best place to do it (for example, we might only want to - * run this check if we need the space), but for now it's a reliable - * spot to do it. + /* + * It would be better to get the 125us-frame + * count from the USB hardware. */ - if (ud->ud_fbuf == NULL && usbpf_canfreebuf(ud)) { - ud->ud_fbuf = ud->ud_hbuf; - ud->ud_hbuf = NULL; - ud->ud_hlen = 0; - usbpf_buf_reclaimed(ud); - } + getbinuptime(&bt); + bintime2timeval(&bt, &tsm); - /* - * Figure out how many bytes to move. If the packet is - * greater or equal to the snapshot length, transfer that - * much. Otherwise, transfer the whole packet (unless - * we hit the buffer size limit). - */ - hdrlen = usbpf_hdrlen(ud); - totlen = hdrlen + min(snaplen, pktlen); - if (totlen > ud->ud_bufsize) - totlen = ud->ud_bufsize; + /* timestamp */ + fhdr.up_sec = tsm.tv_sec; + fhdr.up_frac = tsm.tv_usec; - /* - * Round up the end of the previous packet to the next longword. - * - * Drop the packet if there's no room and no hope of room - * If the packet would overflow the storage buffer or the storage - * buffer is considered immutable by the buffer model, try to rotate - * the buffer and wakeup pending processes. - */ - curlen = USBPF_WORDALIGN(ud->ud_slen); - if (curlen + totlen > ud->ud_bufsize || !usbpf_canwritebuf(ud)) { - if (ud->ud_fbuf == NULL) { - /* - * There's no room in the store buffer, and no - * prospect of room, so drop the packet. Notify the - * buffer model. - */ - usbpf_buffull(ud); - ++ud->ud_dcount; - return; - } - USBPF_ROTATE_BUFFERS(ud); - do_wakeup = 1; - curlen = 0; - } else if (ud->ud_immediate || ud->ud_state == USBPF_TIMED_OUT) - /* - * Immediate mode is set, or the read timeout has already - * expired during a select call. A packet arrived, so the - * reader should be woken up. - */ - do_wakeup = 1; - caplen = totlen - hdrlen; - tstype = ud->ud_tstamp; - do_timestamp = tstype != USBPF_T_NONE; + /* transfer information */ + fhdr.up_busunit = device_get_unit(bus->bdev); + fhdr.up_interval = xfer->interval; + fhdr.up_status = xfer->usb_state; + fhdr.up_packet_size = xfer->max_packet_size; + fhdr.up_packet_count = xfer->max_packet_count; + fhdr.up_frames = xfer->nframes; - /* - * Append the usbpf header. Note we append the actual header size, but - * move forward the length of the header plus padding. - */ - bzero(&hdr, sizeof(hdr)); - if (do_timestamp) - usbpf_bintime2ts(bt, &hdr.uh_tstamp, tstype); - hdr.uh_datalen = pktlen; - hdr.uh_hdrlen = hdrlen; - hdr.uh_caplen = caplen; - usbpf_append_bytes(ud, ud->ud_sbuf, curlen, &hdr, sizeof(hdr)); + /* compute total header overhead length */ + totlen = USBPF_PKTHDR_SIZE + ((USBPF_FRAMEHDR_SIZE * 4) * xfer->nframes); - /* - * Copy the packet data into the store buffer and update its length. - */ - (*cpfn)(ud, ud->ud_sbuf, curlen + hdrlen, pkt, caplen); - ud->ud_slen = curlen + totlen; + /* precompute all trace lengths */ + for (x = 0; x != xfer->nframes; x++) { + uint32_t temp; + temp = usbpf_get_xfer_flags(xfer, x); - if (do_wakeup) - usbpf_wakeup(ud); -} + if (temp & USBPF_XFERFLAG_READ) { + if (type != USBPF_XFERTAP_SUBMIT) + totlen += USBPF_LENGTH_ALIGN(xfer->frlengths[x]); + } else { + if (type == USBPF_XFERTAP_SUBMIT) + totlen += USBPF_LENGTH_ALIGN(xfer->frlengths[x]); + } + } -/* - * Incoming linkage from device drivers. Process the packet pkt, of length - * pktlen, which is stored in a contiguous buffer. The packet is parsed - * by each process' filter, and if accepted, stashed into the corresponding - * buffer. - */ -static void -usbpf_tap(struct usbpf_if *uif, u_char *pkt, u_int pktlen) -{ - struct bintime bt; - struct usbpf_d *ud; - u_int slen; - int gottime; + /* sanity check */ + if (totlen >= USBPF_MAX_BUFFER_LEN) { + static int once; + USBPFD_GLOBAL_UNLOCK(); - gottime = USBPF_TSTAMP_NONE; - USBPFIF_LOCK(uif); - LIST_FOREACH(ud, &uif->uif_dlist, ud_next) { - USBPFD_LOCK(ud); - ++ud->ud_rcount; - slen = usbpf_filter(ud->ud_rfilter, pkt, pktlen, pktlen); - if (slen != 0) { - ud->ud_fcount++; - if (gottime < usbpf_ts_quality(ud->ud_tstamp)) - gottime = usbpf_gettime(&bt, ud->ud_tstamp); - catchpacket(ud, pkt, pktlen, slen, - usbpf_append_bytes, &bt); + if (once == 0) { + printf("usb_pf: Total trace length(%u) " + "exceeds maximum(%u).\n", + totlen, USBPF_MAX_BUFFER_LEN); + once = 1; } - USBPFD_UNLOCK(ud); + + /* too much data */ + return; } - USBPFIF_UNLOCK(uif); -} -static uint32_t -usbpf_aggregate_xferflags(struct usb_xfer_flags *flags) -{ - uint32_t val = 0; + fhdr.up_totlen = totlen; + fhdr.up_error = xfer->error; + fhdr.up_xfertype = xfer->endpoint->edesc->bmAttributes & UE_XFERTYPE; + fhdr.up_devunit = info->udev->device_index; + fhdr.up_endpoint = xfer->endpointno; + fhdr.up_dmode = (xfer->flags_int.usb_mode == USB_MODE_DEVICE); + fhdr.up_type = type; - if (flags->force_short_xfer == 1) - val |= USBPF_FLAG_FORCE_SHORT_XFER; - if (flags->short_xfer_ok == 1) - val |= USBPF_FLAG_SHORT_XFER_OK; - if (flags->short_frames_ok == 1) - val |= USBPF_FLAG_SHORT_FRAMES_OK; - if (flags->pipe_bof == 1) - val |= USBPF_FLAG_PIPE_BOF; - if (flags->proxy_buffer == 1) - val |= USBPF_FLAG_PROXY_BUFFER; - if (flags->ext_buffer == 1) - val |= USBPF_FLAG_EXT_BUFFER; - if (flags->manual_status == 1) - val |= USBPF_FLAG_MANUAL_STATUS; - if (flags->no_pipe_ok == 1) - val |= USBPF_FLAG_NO_PIPE_OK; - if (flags->stall_pipe == 1) - val |= USBPF_FLAG_STALL_PIPE; - return (val); + TAILQ_FOREACH(ud, &usbpf_filters, ud_next) { + if (usbpf_filter(ud, &fhdr)) + usbpf_xfertap_sub(xfer, ud, &fhdr, type); + } + + USBPFD_GLOBAL_UNLOCK(); } -static uint32_t -usbpf_aggregate_status(struct usb_xfer_flags_int *flags) +static void +usbpf_drvinit(void *unused) { - uint32_t val = 0; + mtx_init(&usbpf_global_mtx, "USB packet filter global lock", + NULL, MTX_DEF); - if (flags->open == 1) - val |= USBPF_STATUS_OPEN; - if (flags->transferring == 1) - val |= USBPF_STATUS_TRANSFERRING; - if (flags->did_dma_delay == 1) - val |= USBPF_STATUS_DID_DMA_DELAY; - if (flags->did_close == 1) - val |= USBPF_STATUS_DID_CLOSE; - if (flags->draining == 1) - val |= USBPF_STATUS_DRAINING; - if (flags->started == 1) - val |= USBPF_STATUS_STARTED; - if (flags->bandwidth_reclaimed == 1) - val |= USBPF_STATUS_BW_RECLAIMED; - if (flags->control_xfr == 1) - val |= USBPF_STATUS_CONTROL_XFR; - if (flags->control_hdr == 1) - val |= USBPF_STATUS_CONTROL_HDR; - if (flags->control_act == 1) - val |= USBPF_STATUS_CONTROL_ACT; - if (flags->control_stall == 1) - val |= USBPF_STATUS_CONTROL_STALL; - if (flags->short_frames_ok == 1) - val |= USBPF_STATUS_SHORT_FRAMES_OK; - if (flags->short_xfer_ok == 1) - val |= USBPF_STATUS_SHORT_XFER_OK; -#if USB_HAVE_BUSDMA - if (flags->bdma_enable == 1) - val |= USBPF_STATUS_BDMA_ENABLE; - if (flags->bdma_no_post_sync == 1) - val |= USBPF_STATUS_BDMA_NO_POST_SYNC; - if (flags->bdma_setup == 1) - val |= USBPF_STATUS_BDMA_SETUP; -#endif - if (flags->isochronous_xfr == 1) - val |= USBPF_STATUS_ISOCHRONOUS_XFR; - if (flags->curr_dma_set == 1) - val |= USBPF_STATUS_CURR_DMA_SET; - if (flags->can_cancel_immed == 1) - val |= USBPF_STATUS_CAN_CANCEL_IMMED; - if (flags->doing_callback == 1) - val |= USBPF_STATUS_DOING_CALLBACK; + TAILQ_INIT(&usbpf_filters); - return (val); -} + usbpf_dev = make_dev(&usbpf_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "usbpf"); -void -usbpf_xfertap(struct usb_xfer *xfer, int type) -{ - struct usb_endpoint *ep = xfer->endpoint; - struct usb_page_search res; - struct usb_xfer_root *info = xfer->xroot; - struct usb_bus *bus = info->bus; - struct usbpf_pkthdr *up; - usb_frlength_t isoc_offset = 0; - int i; - char *buf, *ptr, *end; + /* Set our function pointer callback */ - /* - * NB: usbpf_uifd_cnt isn't protected by USBPFIF_LOCK() because it's - * not harmful. - */ - if (usbpf_uifd_cnt == 0) - return; + usb_pf_xfertap_p = &usbpf_xfertap; - /* - * XXX TODO - * Allocating the buffer here causes copy operations twice what's - * really inefficient. Copying usbpf_pkthdr and data is for USB packet - * read filter to pass a virtually linear buffer. - */ - buf = ptr = malloc(sizeof(struct usbpf_pkthdr) + (USB_PAGE_SIZE * 5), - M_USBPF, M_NOWAIT); - if (buf == NULL) { - printf("usbpf_xfertap: out of memory\n"); /* XXX */ - return; - } - end = buf + sizeof(struct usbpf_pkthdr) + (USB_PAGE_SIZE * 5); + printf("usb_pf: USB packet filter v%u.%u.\n", + USBPF_MAJOR_VERSION, USBPF_MINOR_VERSION); +} +SYSINIT(usbpf_dev, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, usbpf_drvinit, NULL); - bzero(ptr, sizeof(struct usbpf_pkthdr)); - up = (struct usbpf_pkthdr *)ptr; - up->up_busunit = htole32(device_get_unit(bus->bdev)); - up->up_type = type; - up->up_xfertype = ep->edesc->bmAttributes & UE_XFERTYPE; - up->up_address = xfer->address; - up->up_endpoint = xfer->endpointno; - up->up_flags = htole32(usbpf_aggregate_xferflags(&xfer->flags)); - up->up_status = htole32(usbpf_aggregate_status(&xfer->flags_int)); - switch (type) { - case USBPF_XFERTAP_SUBMIT: - up->up_length = htole32(xfer->sumlen); - up->up_frames = htole32(xfer->nframes); - break; - case USBPF_XFERTAP_DONE: - up->up_length = htole32(xfer->actlen); - up->up_frames = htole32(xfer->aframes); - break; - default: - panic("wrong usbpf type (%d)", type); - } +static void +usbpf_drvuninit(void *arg) +{ + usb_pf_unload(arg); - up->up_error = htole32(xfer->error); - up->up_interval = htole32(xfer->interval); - ptr += sizeof(struct usbpf_pkthdr); + if (usbpf_dev != NULL) + destroy_dev(usbpf_dev); - for (i = 0; i < up->up_frames; i++) { - if (ptr + sizeof(u_int32_t) >= end) - goto done; - *((u_int32_t *)ptr) = htole32(xfer->frlengths[i]); - ptr += sizeof(u_int32_t); + USBPFD_GLOBAL_LOCK(); - if (ptr + xfer->frlengths[i] >= end) - goto done; - if (xfer->flags_int.isochronous_xfr == 1) { - usbd_get_page(&xfer->frbuffers[0], isoc_offset, &res); - isoc_offset += xfer->frlengths[i]; - } else - usbd_get_page(&xfer->frbuffers[i], 0, &res); - bcopy(res.buffer, ptr, xfer->frlengths[i]); - ptr += xfer->frlengths[i]; - } + while (TAILQ_FIRST(&usbpf_filters) != NULL) { - usbpf_tap(bus->uif, buf, ptr - buf); -done: - free(buf, M_USBPF); -} + USBPFD_GLOBAL_UNLOCK(); -static void -usbpf_append_bytes(struct usbpf_d *ud, caddr_t buf, u_int offset, void *src, - u_int len) -{ + printf("usb_pf: Please close all device instances\n"); - USBPFD_LOCK_ASSERT(ud); + pause("WAIT", 2 * hz); - switch (ud->ud_bufmode) { - case USBPF_BUFMODE_BUFFER: - return (usbpf_buffer_append_bytes(ud, buf, offset, src, len)); - default: - panic("usbpf_buf_append_bytes"); + USBPFD_GLOBAL_LOCK(); } -} -static void -usbpf_drvinit(void *unused) -{ - struct cdev *dev; + USBPFD_GLOBAL_UNLOCK(); - mtx_init(&usbpf_mtx, "USB packet filter global lock", NULL, - MTX_DEF); - LIST_INIT(&usbpf_iflist); - - dev = make_dev(&usbpf_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "usbpf"); + mtx_destroy(&usbpf_global_mtx); } - -SYSINIT(usbpf_dev, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, usbpf_drvinit, NULL); +SYSUNINIT(usbpf_dev, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, usbpf_drvuninit, NULL); === sys/dev/usb/usb_pf.h ================================================================== --- sys/dev/usb/usb_pf.h (revision 215656) +++ sys/dev/usb/usb_pf.h (local) @@ -1,12 +1,7 @@ /*- - * Copyright (c) 1990, 1991, 1993 - * The Regents of the University of California. All rights reserved. + * Copyright (c) 2010 Weongyo Jeong. All rights reserved. + * Copyright (c) 2010 Hans Petter Selasky. All rights reserved. * - * This code is derived from the Stanford/CMU enet packet filter, - * (net/enet.c) distributed as part of 4.3BSD, and code contributed - * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence - * Berkeley Laboratory. - * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -15,9 +10,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -44,20 +36,53 @@ #include #endif -typedef int32_t usbpf_int32; -typedef u_int32_t usbpf_u_int32; -typedef int64_t usbpf_int64; -typedef u_int64_t usbpf_u_int64; - +struct usb_xfer; struct usbpf_if; +struct usbpf_pkthdr; +#define USBPF_MAX_BUFFER_LEN (1U << 20) /* maximum tap length */ +#define USBPF_MAX_QUEUE_LEN 64 /* maximum number of unread transfers */ +#define USBPF_PKTHDR_SIZE 128 /* bytes */ +#define USBPF_LENGTH_ALIGN(x) (((x) + 3) & ~(uint32_t)3) +#define USBPF_FRAMEHDR_SIZE 3 /* dwords */ +#define USBPF_MAX_FILTER 65536 /* instructions */ + +/* scratch size in 32-bits for (for USBPF_LD|USBPF_MEM and USBPF_ST) */ +#define USBPF_MEMWORDS 16 + /* - * Alignment macros. USBPF_WORDALIGN rounds up to the next - * even multiple of USBPF_ALIGNMENT. + * Structure prepended to each packet. */ -#define USBPF_ALIGNMENT sizeof(long) -#define USBPF_WORDALIGN(x) (((x)+(USBPF_ALIGNMENT-1))&~(USBPF_ALIGNMENT-1)) +struct usbpf_pkthdr_first { + uint64_t up_sec; /* timestamp seconds */ + uint64_t up_frac; /* timestamp fraction */ + uint32_t up_busunit; /* Host controller unit number */ + uint32_t up_frames; /* USB frame number (submit/actual) */ + uint32_t up_hdrlen; /* total header length */ + uint32_t up_interval; /* for interrupt and isoc */ + uint32_t up_nframes; /* number of USB frames */ + uint32_t up_status; /* transfer status */ + uint32_t up_totlen; /* total packet length (including data) */ + uint32_t up_error; /* usb_error_t */ + uint32_t up_packet_size; /* USB packet size */ + uint32_t up_packet_count;/* USB packet count */ + uint8_t up_devunit; /* USB device unit number */ + uint8_t up_dmode; /* set if device mode, else host */ + uint8_t up_endpoint; /* USB endpoint */ + uint8_t up_type; /* type: SUBMIT or DONE */ + uint8_t up_xfertype; /* USB transfer type */ +} __packed; +struct usbpf_pkthdr { + struct usbpf_pkthdr_first hdr; + union { +#ifdef _KERNEL + TAILQ_ENTRY(usbpf_pkthdr) entry; /* for internal use */ +#endif + uint8_t dummy[USBPF_PKTHDR_SIZE - sizeof(struct usbpf_pkthdr_first)]; + } __packed reserved; +} __packed; + /* * The instruction encodings. */ @@ -119,201 +144,93 @@ * The instruction data structure. */ struct usbpf_insn { - u_short code; - u_char jt; - u_char jf; - usbpf_u_int32 k; + uint16_t code; + uint8_t jt; + uint8_t jf; + uint32_t k; }; -#ifdef _KERNEL +struct usbpf_version { + uint16_t uv_major; + uint16_t uv_minor; +}; +#define USBPF_MAJOR_VERSION 1 +#define USBPF_MINOR_VERSION 2 +struct usbpf_ifreq { + /* pre-filter parameters */ + uint32_t ua_bus_unit; /* must match, if not ANY */ + uint32_t ua_dev_unit; /* must match, if not ANY */ + uint32_t ua_endpoint_mask; /* must match, if not ANY */ +#define USBPF_IFREQ_ANY 0xFFFFFFFFU /* ANY bus, device or endpoint unit */ + /* post-filter parameters */ + uint32_t ua_filter_len; /* number of filter entries */ + const struct usbpf_insn *ua_filter_ptr; +}; + /* - * Descriptor associated with each open uff file. + * Struct returned by UIOCGSTATS. */ +struct usbpf_stat { + uint64_t us_recv; /* number of packets received */ + uint64_t us_drop; /* number of packets dropped */ +}; -struct usbpf_d { - LIST_ENTRY(usbpf_d) ud_next; /* Linked list of descriptors */ - /* - * Buffer slots: two memory buffers store the incoming packets. - * The model has three slots. Sbuf is always occupied. - * sbuf (store) - Receive interrupt puts packets here. - * hbuf (hold) - When sbuf is full, put buffer here and - * wakeup read (replace sbuf with fbuf). - * fbuf (free) - When read is done, put buffer here. - * On receiving, if sbuf is full and fbuf is 0, packet is dropped. - */ - caddr_t ud_sbuf; /* store slot */ - caddr_t ud_hbuf; /* hold slot */ - caddr_t ud_fbuf; /* free slot */ - int ud_slen; /* current length of store buffer */ - int ud_hlen; /* current length of hold buffer */ +#define UIOCSETIF _IOW('U', 108, struct usbpf_ifreq) +#define UIOCSRTIMEOUT _IOW('U', 109, struct timeval) +#define UIOCGRTIMEOUT _IOR('U', 110, struct timeval) +#define UIOCGSTATS _IOR('U', 111, struct usbpf_stat) +#define UIOCVERSION _IOR('U', 112, struct usbpf_version) +#define UIOCGBLEN _IOR('U', 113, long) - int ud_bufsize; /* absolute length of buffers */ +/* definition of second parameter in usb_pf_xfertap_t function */ - struct usbpf_if *ud_bif; /* interface descriptor */ - u_long ud_rtout; /* Read timeout in 'ticks' */ - struct usbpf_insn *ud_rfilter; /* read filter code */ - struct usbpf_insn *ud_wfilter; /* write filter code */ - void *ud_bfilter; /* binary filter code */ - u_int64_t ud_rcount; /* number of packets received */ - u_int64_t ud_dcount; /* number of packets dropped */ +#define USBPF_XFERTAP_SUBMIT 0 +#define USBPF_XFERTAP_DONE 1 - u_char ud_promisc; /* true if listening promiscuously */ - u_char ud_state; /* idle, waiting, or timed out */ - u_char ud_immediate; /* true to return on packet arrival */ - int ud_hdrcmplt; /* false to fill in src lladdr automatically */ - int ud_direction; /* select packet direction */ - int ud_tstamp; /* select time stamping function */ - int ud_feedback; /* true to feed back sent packets */ - int ud_async; /* non-zero if packet reception should generate signal */ - int ud_sig; /* signal to send upon packet reception */ - struct sigio * ud_sigio; /* information for async I/O */ - struct selinfo ud_sel; /* bsd select info */ - struct mtx ud_mtx; /* mutex for this descriptor */ - struct callout ud_callout; /* for USBPF timeouts with select */ - struct label *ud_label; /* MAC label for descriptor */ - u_int64_t ud_fcount; /* number of packets which matched filter */ - pid_t ud_pid; /* PID which created descriptor */ - int ud_locked; /* true if descriptor is locked */ - u_int ud_bufmode; /* Current buffer mode. */ - u_int64_t ud_wcount; /* number of packets written */ - u_int64_t ud_wfcount; /* number of packets that matched write filter */ - u_int64_t ud_wdcount; /* number of packets dropped during a write */ - u_int64_t ud_zcopy; /* number of zero copy operations */ - u_char ud_compat32; /* 32-bit stream on LP64 system */ -}; +/* definition of USB transfer flags */ -#define USBPFD_LOCK(ud) mtx_lock(&(ud)->ud_mtx) -#define USBPFD_UNLOCK(ud) mtx_unlock(&(ud)->ud_mtx) -#define USBPFD_LOCK_ASSERT(ud) mtx_assert(&(ud)->ud_mtx, MA_OWNED) +#define USBPF_XFERFLAG_READ 0x00000001U +#define USBPF_XFERFLAG_SHORT_OK 0x00000002U +#define USBPF_XFERFLAG_MULTI_SHORT_OK 0x00000004U +#define USBPF_XFERFLAG_FORCE_SHORT 0x00000008U +#define USBPF_XFERFLAG_STALL_PIPE 0x00000010U +#define USBPF_XFERFLAG_CONTROL_ACT 0x00000020U +#define USBPF_XFERFLAG_DATA_FOLLOWS 0x00000040U +#ifdef _KERNEL + /* - * Descriptor associated with each attached hardware interface. + * Descriptor associated with each open upf file. */ -struct usbpf_if { - LIST_ENTRY(usbpf_if) uif_next; /* list of all interfaces */ - LIST_HEAD(, usbpf_d) uif_dlist; /* descriptor list */ - u_int uif_hdrlen; /* length of link header */ - struct usb_bus *uif_ubus; /* corresponding interface */ - struct mtx uif_mtx; /* mutex for interface */ -}; +struct usbpf_d { + TAILQ_ENTRY(usbpf_d) ud_next; /* Linked list of descriptors */ -#define USBPFIF_LOCK(uif) mtx_lock(&(uif)->uif_mtx) -#define USBPFIF_UNLOCK(uif) mtx_unlock(&(uif)->uif_mtx) + TAILQ_HEAD(, usbpf_pkthdr) ud_head; -#endif + uint32_t ud_queue_len; /* number of packets queued */ + uint32_t ud_rtout; /* Read timeout in 'ticks' */ -/* - * Structure prepended to each packet. - */ -struct usbpf_ts { - usbpf_int64 ut_sec; /* seconds */ - usbpf_u_int64 ut_frac; /* fraction */ -}; -struct usbpf_xhdr { - struct usbpf_ts uh_tstamp; /* time stamp */ - usbpf_u_int32 uh_caplen; /* length of captured portion */ - usbpf_u_int32 uh_datalen; /* original length of packet */ - u_short uh_hdrlen; /* length of uff header (this struct - plus alignment padding) */ -}; + struct usbpf_insn *ud_filter_code; /* post-filter code */ -#define USBPF_BUFMODE_BUFFER 1 /* Kernel buffers with read(). */ -#define USBPF_BUFMODE_ZBUF 2 /* Zero-copy buffers. */ + uint64_t ud_rcount; /* number of packets received */ + uint64_t ud_dcount; /* number of packets dropped */ -struct usbpf_pkthdr { - int up_busunit; /* Host controller unit number */ - u_char up_address; /* USB device address */ - u_char up_endpoint; /* USB endpoint */ - u_char up_type; /* points SUBMIT / DONE */ - u_char up_xfertype; /* Transfer type */ - u_int32_t up_flags; /* Transfer flags */ -#define USBPF_FLAG_FORCE_SHORT_XFER (1 << 0) -#define USBPF_FLAG_SHORT_XFER_OK (1 << 1) -#define USBPF_FLAG_SHORT_FRAMES_OK (1 << 2) -#define USBPF_FLAG_PIPE_BOF (1 << 3) -#define USBPF_FLAG_PROXY_BUFFER (1 << 4) -#define USBPF_FLAG_EXT_BUFFER (1 << 5) -#define USBPF_FLAG_MANUAL_STATUS (1 << 6) -#define USBPF_FLAG_NO_PIPE_OK (1 << 7) -#define USBPF_FLAG_STALL_PIPE (1 << 8) - u_int32_t up_status; /* Transfer status */ -#define USBPF_STATUS_OPEN (1 << 0) -#define USBPF_STATUS_TRANSFERRING (1 << 1) -#define USBPF_STATUS_DID_DMA_DELAY (1 << 2) -#define USBPF_STATUS_DID_CLOSE (1 << 3) -#define USBPF_STATUS_DRAINING (1 << 4) -#define USBPF_STATUS_STARTED (1 << 5) -#define USBPF_STATUS_BW_RECLAIMED (1 << 6) -#define USBPF_STATUS_CONTROL_XFR (1 << 7) -#define USBPF_STATUS_CONTROL_HDR (1 << 8) -#define USBPF_STATUS_CONTROL_ACT (1 << 9) -#define USBPF_STATUS_CONTROL_STALL (1 << 10) -#define USBPF_STATUS_SHORT_FRAMES_OK (1 << 11) -#define USBPF_STATUS_SHORT_XFER_OK (1 << 12) -#if USB_HAVE_BUSDMA -#define USBPF_STATUS_BDMA_ENABLE (1 << 13) -#define USBPF_STATUS_BDMA_NO_POST_SYNC (1 << 14) -#define USBPF_STATUS_BDMA_SETUP (1 << 15) -#endif -#define USBPF_STATUS_ISOCHRONOUS_XFR (1 << 16) -#define USBPF_STATUS_CURR_DMA_SET (1 << 17) -#define USBPF_STATUS_CAN_CANCEL_IMMED (1 << 18) -#define USBPF_STATUS_DOING_CALLBACK (1 << 19) - u_int32_t up_length; /* Total data length (submit/actual) */ - u_int32_t up_frames; /* USB frame number (submit/actual) */ - u_int32_t up_error; /* usb_error_t */ - u_int32_t up_interval; /* for interrupt and isoc */ - /* sizeof(struct usbpf_pkthdr) == 128 bytes */ - u_char up_reserved[96]; -}; + int ud_tstamp; /* select time stamping function */ -struct usbpf_version { - u_short uv_major; - u_short uv_minor; -}; -#define USBPF_MAJOR_VERSION 1 -#define USBPF_MINOR_VERSION 1 + struct selinfo ud_sel; /* BSD select info */ -#define USBPF_IFNAMSIZ 32 -struct usbpf_ifreq { - /* bus name, e.g. "usbus0" */ - char ufr_name[USBPF_IFNAMSIZ]; -}; + uint64_t ud_fcount; /* number of packets which matched filter */ -/* - * Structure for UIOCSETF. - */ -struct usbpf_program { - u_int uf_len; - struct usbpf_insn *uf_insns; -}; + int ud_running; /* set if running */ -/* - * Struct returned by UIOCGSTATS. - */ -struct usbpf_stat { - u_int us_recv; /* number of packets received */ - u_int us_drop; /* number of packets dropped */ + struct usbpf_ifreq ud_filter; /* data filter */ }; -#define UIOCGBLEN _IOR('U', 102, u_int) -#define UIOCSBLEN _IOWR('U', 102, u_int) -#define UIOCSETF _IOW('U', 103, struct usbpf_program) -#define UIOCSETIF _IOW('U', 108, struct usbpf_ifreq) -#define UIOCSRTIMEOUT _IOW('U', 109, struct timeval) -#define UIOCGRTIMEOUT _IOR('U', 110, struct timeval) -#define UIOCGSTATS _IOR('U', 111, struct usbpf_stat) -#define UIOCVERSION _IOR('U', 113, struct usbpf_version) -#define UIOCSETWF _IOW('U', 123, struct usbpf_program) +#define USBPFD_GLOBAL_LOCK() mtx_lock(&usbpf_global_mtx) +#define USBPFD_GLOBAL_UNLOCK() mtx_unlock(&usbpf_global_mtx) +#define USBPFD_GLOBAL_ASSERT_LOCKED() mtx_assert(&usbpf_global_mtx, MA_OWNED) -#define USBPF_XFERTAP_SUBMIT 0 -#define USBPF_XFERTAP_DONE 1 - -#ifdef _KERNEL -void usbpf_attach(struct usb_bus *, struct usbpf_if **); -void usbpf_detach(struct usb_bus *); -void usbpf_xfertap(struct usb_xfer *, int); #endif #endif === sys/dev/usb/usb_transfer.c ================================================================== --- sys/dev/usb/usb_transfer.c (revision 215656) +++ sys/dev/usb/usb_transfer.c (local) @@ -57,10 +57,13 @@ #include #include #include +#if USB_HAVE_PF +#include +#include +#endif #include #include -#include struct usb_std_packet_size { struct { @@ -666,6 +669,14 @@ /* setup "frlengths" */ xfer->frlengths = parm->xfer_length_ptr; parm->xfer_length_ptr += n_frlengths; +#if USB_HAVE_PF + /* + * We need extra room to store the initial + * length values in case of isochronous + * transfers. + */ + parm->xfer_length_ptr += n_frlengths; +#endif /* setup "frbuffers" */ xfer->frbuffers = parm->xfer_page_cache_ptr; @@ -1587,6 +1598,10 @@ USB_BUS_UNLOCK(bus); return; } +#if USB_HAVE_PF + /* Make a copy of the initial frame lengths */ + xfer->frlengths[x + xfer->max_frame_count] = xfer->frlengths[x]; +#endif } /* clear some internal flags */ @@ -1636,7 +1651,15 @@ } } } + /* + * Tap frames to the USB packet filter before + * any BUSDMA operations. + */ +#if USB_HAVE_PF + usb_pf_xfertap_p(xfer, USBPF_XFERTAP_SUBMIT); +#endif + /* * Check if BUS-DMA support is enabled and try to load virtual * buffers into DMA, if any: */ @@ -2195,11 +2218,11 @@ } #endif } +#if USB_HAVE_PF + usb_pf_xfertap_p(xfer, USBPF_XFERTAP_DONE); +#endif } - if (xfer->usb_state != USB_ST_SETUP) - usbpf_xfertap(xfer, USBPF_XFERTAP_DONE); - /* call processing routine */ (xfer->callback) (xfer, xfer->error); @@ -2387,8 +2410,6 @@ DPRINTF("start\n"); - usbpf_xfertap(xfer, USBPF_XFERTAP_SUBMIT); - /* start the transfer */ (ep->methods->start) (xfer); @@ -2566,8 +2587,6 @@ } DPRINTF("start\n"); - usbpf_xfertap(xfer, USBPF_XFERTAP_SUBMIT); - /* start USB transfer */ (ep->methods->start) (xfer); === sys/modules/usb/Makefile ================================================================== --- sys/modules/usb/Makefile (revision 215656) +++ sys/modules/usb/Makefile (local) @@ -34,6 +34,7 @@ SUBDIR += uether aue axe cdce cue kue rue udav uhso ipheth SUBDIR += usfs umass urio SUBDIR += quirk template +SUBDIR += upf .if ${MACHINE_CPUARCH} == "amd64" _urtw= urtw === sys/modules/usb/upf (new directory) ================================================================== === sys/modules/usb/upf/Makefile ================================================================== --- sys/modules/usb/upf/Makefile (revision 215656) +++ sys/modules/usb/upf/Makefile (local) @@ -0,0 +1,37 @@ +# +# $FreeBSD$ +# +# Copyright (c) 2010 Hans Petter Selasky. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +S= ${.CURDIR}/../../.. + +.PATH: $S/dev/usb + +KMOD= usb_pf +SRCS= opt_bus.h opt_usb.h device_if.h bus_if.h usb_if.h \ + usb_pf.c + +.include + Property changes on: sys/modules/usb/upf/Makefile ___________________________________________________________________ Name: svn:eol-style +native Name: svn:keywords +FreeBSD=%H Name: svn:mime-type +text/plain === usr.sbin/Makefile ================================================================== --- usr.sbin/Makefile (revision 215656) +++ usr.sbin/Makefile (local) @@ -293,6 +293,7 @@ .if ${MK_USB} != "no" SUBDIR+= uathload SUBDIR+= uhsoctl +SUBDIR+= usbdump SUBDIR+= usbconfig .endif === usr.sbin/usbdump/usbdump.8 ================================================================== --- usr.sbin/usbdump/usbdump.8 (revision 215656) +++ usr.sbin/usbdump/usbdump.8 (local) @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd October 14, 2010 +.Dd November 23, 2010 .Dt usbdump 8 .Os .Sh NAME @@ -33,7 +33,8 @@ .Nd "dump traffic on USB host controller" .Sh SYNOPSIS .Nm -.Op Fl i Ar ifname +.Op Fl d Ar bus.dev.endpoint +.Op Fl b Ar bufsize .Op Fl r Ar file .Op Fl s Ar snaplen .Op Fl v @@ -45,27 +46,40 @@ .Pp The following options are accepted. .Bl -tag -width ".Fl f Ar file" -.It Fl i Ar ifname -Listen on USB bus interface. +.It Fl d Ar bus.dev.endpoint +Listen on the given bus, device and endpoint. +This option is mandatory. +A negative value in any of the given fields means any bus, device or endpoint. +.It Fl b Ar bufsize +Set internal buffer size in bytes. +Default: -1. .It Fl r Ar file Read the raw packets from file. +Default: Off .It Fl s Ar snaplen Snapshot bytes from each packet. +Default: 192 .It Fl v Enable debugging messages. When it defined multiple times the verbose level increases. +Default: Off .It Fl w Ar file Write the raw packets to file. +Default: Off .El .Sh EXAMPLES -Captures the USB raw packets alive on usbus2: +Captures the USB raw packets alive on ugen2.x: .Pp -.Dl "usbdump -i usbus2 -s 256 -v" +.Dl "usbdump -d 2 -s 256 -v" .Pp -Dumps the USB raw packets of usbus2 into the file without packet +Captures the USB raw packets alive on ugen2.1: +.Pp +.Dl "usbdump -d 2.1 -s 256 -v" +.Pp +Dumps the USB raw packets of ugen2.x into the file without packet size limit: .Pp -.Dl "usbdump -i usbus2 -s 0 -w /tmp/dump_pkts" +.Dl "usbdump -d 2 -s 0 -w /tmp/dump_pkts" .Pp Read the USB raw packets from the file: .Pp === usr.sbin/usbdump/usbdump.c ================================================================== --- usr.sbin/usbdump/usbdump.c (revision 215656) +++ usr.sbin/usbdump/usbdump.c (local) @@ -49,8 +49,8 @@ struct usbcap { int fd; /* fd for /dev/usbpf */ - u_int bufsize; - char *buffer; + uint32_t bufsize; + void *buffer; /* for -w option */ int wfd; @@ -59,17 +59,21 @@ }; struct usbcap_filehdr { - u_int magic; + uint32_t magic; #define USBCAP_FILEHDR_MAGIC 0x9a90000e - u_char major; - u_char minor; - u_char reserved[26]; + uint8_t major; + uint8_t minor; + uint8_t reserved[26]; } __packed; static int doexit = 0; static int pkt_captured = 0; static int verbose = 0; -static const char *i_arg = "usbus0";; +static int bus = -1; +static int device = -1; +static int endpoint = -1; +static int bufsize = -1; + static const char *r_arg = NULL; static const char *w_arg = NULL; static const char *errstr_table[USB_ERR_MAX] = { @@ -114,67 +118,29 @@ static void handle_sigint(int sig) { + (void)sig; - (void)sig; doexit = 1; } static void -print_flags(u_int32_t flags) +print_flags(uint32_t flags) { #define PRINTFLAGS(name) \ - if ((flags & USBPF_FLAG_##name) != 0) \ - printf("%s ", #name); - printf(" flags %#x", flags); - printf(" < "); - PRINTFLAGS(FORCE_SHORT_XFER); - PRINTFLAGS(SHORT_XFER_OK); - PRINTFLAGS(SHORT_FRAMES_OK); - PRINTFLAGS(PIPE_BOF); - PRINTFLAGS(PROXY_BUFFER); - PRINTFLAGS(EXT_BUFFER); - PRINTFLAGS(MANUAL_STATUS); - PRINTFLAGS(NO_PIPE_OK); + if ((flags & USBPF_XFERFLAG_##name) != 0) \ + printf("%s/", #name); + printf(" flags["); + PRINTFLAGS(READ); + PRINTFLAGS(SHORT_OK); + PRINTFLAGS(MULTI_SHORT_OK); + PRINTFLAGS(FORCE_SHORT); PRINTFLAGS(STALL_PIPE); - printf(">\n"); + PRINTFLAGS(CONTROL_ACT); + PRINTFLAGS(DATA_FOLLOWS); + printf("0x%08x]", flags); #undef PRINTFLAGS } -static void -print_status(u_int32_t status) -{ -#define PRINTSTATUS(name) \ - if ((status & USBPF_STATUS_##name) != 0) \ - printf("%s ", #name); - - printf(" status %#x", status); - printf(" < "); - PRINTSTATUS(OPEN); - PRINTSTATUS(TRANSFERRING); - PRINTSTATUS(DID_DMA_DELAY); - PRINTSTATUS(DID_CLOSE); - PRINTSTATUS(DRAINING); - PRINTSTATUS(STARTED); - PRINTSTATUS(BW_RECLAIMED); - PRINTSTATUS(CONTROL_XFR); - PRINTSTATUS(CONTROL_HDR); - PRINTSTATUS(CONTROL_ACT); - PRINTSTATUS(CONTROL_STALL); - PRINTSTATUS(SHORT_FRAMES_OK); - PRINTSTATUS(SHORT_XFER_OK); -#if USB_HAVE_BUSDMA - PRINTSTATUS(BDMA_ENABLE); - PRINTSTATUS(BDMA_NO_POST_SYNC); - PRINTSTATUS(BDMA_SETUP); -#endif - PRINTSTATUS(ISOCHRONOUS_XFR); - PRINTSTATUS(CURR_DMA_SET); - PRINTSTATUS(CAN_CANCEL_IMMED); - PRINTSTATUS(DOING_CALLBACK); - printf(">\n"); -#undef PRINTSTATUS -} - /* * Display a region in traditional hexdump format. */ @@ -216,90 +182,124 @@ } static void -print_apacket(const struct usbpf_xhdr *hdr, struct usbpf_pkthdr *up, - const char *payload) +print_apacket(const struct usbpf_pkthdr *up, const uint32_t *ptr, + uint32_t framelen, uint32_t snaplen, uint32_t flags, uint32_t frameno) { + struct usbpf_pkthdr_first hdr; struct tm *tm; struct timeval tv; size_t len; - u_int32_t framelen, x; - const char *ptr = payload; char buf[64]; /* A packet from the kernel is based on little endian byte order. */ - up->up_busunit = le32toh(up->up_busunit); - up->up_flags = le32toh(up->up_flags); - up->up_status = le32toh(up->up_status); - up->up_length = le32toh(up->up_length); - up->up_frames = le32toh(up->up_frames); - up->up_error = le32toh(up->up_error); - up->up_interval = le32toh(up->up_interval); + hdr.up_sec = le64toh(up->hdr.up_sec); + hdr.up_frac = le64toh(up->hdr.up_frac); + hdr.up_busunit = le32toh(up->hdr.up_busunit); + hdr.up_frames = le32toh(up->hdr.up_frames); + hdr.up_interval = le32toh(up->hdr.up_interval); + hdr.up_status = le32toh(up->hdr.up_status); + hdr.up_totlen = le32toh(up->hdr.up_totlen); + hdr.up_error = le32toh(up->hdr.up_error); + hdr.up_packet_size = le32toh(up->hdr.up_packet_size); + hdr.up_packet_count = le32toh(up->hdr.up_packet_count); + hdr.up_devunit = up->hdr.up_devunit; + hdr.up_dmode = up->hdr.up_dmode; + hdr.up_endpoint = up->hdr.up_endpoint; + hdr.up_type = up->hdr.up_type; + hdr.up_xfertype = up->hdr.up_xfertype; - tv.tv_sec = hdr->uh_tstamp.ut_sec; - tv.tv_usec = hdr->uh_tstamp.ut_frac; + tv.tv_sec = hdr.up_sec; + tv.tv_usec = hdr.up_frac; tm = localtime(&tv.tv_sec); len = strftime(buf, sizeof(buf), "%H:%M:%S", tm); printf("%.*s.%06ju", (int)len, buf, tv.tv_usec); - printf(" usbus%d.%d 0x%02x %s %s", up->up_busunit, up->up_address, - up->up_endpoint, - xfertype_table[up->up_xfertype], - up->up_type == USBPF_XFERTAP_SUBMIT ? ">" : "<"); - printf(" (%d/%d)", up->up_frames, up->up_length); - if (up->up_type == USBPF_XFERTAP_DONE) - printf(" %s", errstr_table[up->up_error]); - if (up->up_xfertype == UE_BULK || up->up_xfertype == UE_ISOCHRONOUS) - printf(" %d", up->up_interval); + printf(" usbus%d.%d 0x%02x %s %s %s", hdr.up_busunit, hdr.up_devunit, + hdr.up_xfertype != UE_CONTROL ? hdr.up_endpoint : hdr.up_endpoint & 0x0F, + xfertype_table[hdr.up_xfertype & 3], + hdr.up_type == USBPF_XFERTAP_SUBMIT ? "->" : "<-", + (flags & USBPF_XFERFLAG_READ) ? "RD" : "WR"); + + printf(" (%d+%d)", hdr.up_frames, + hdr.up_totlen - USBPF_PKTHDR_SIZE - (4 * USBPF_FRAMEHDR_SIZE * hdr.up_frames)); + + if (hdr.up_type == USBPF_XFERTAP_DONE) { + printf(" %s", (errstr_table[hdr.up_error] != NULL) ? + errstr_table[hdr.up_error] : ""); + } + if (hdr.up_xfertype != UE_ISOCHRONOUS) + printf(" %d ms", hdr.up_interval); printf("\n"); if (verbose >= 1) { - for (x = 0; x < up->up_frames; x++) { - framelen = le32toh(*((const u_int32_t *)ptr)); - ptr += sizeof(u_int32_t); - printf(" frame[%u] len %d\n", x, framelen); - assert(framelen < (1024 * 4)); - hexdump(ptr, framelen); - ptr += framelen; - } + printf(" frame[%u/%u] len[%u/%u]", frameno, hdr.up_frames, snaplen, framelen); + if (verbose >= 2) + print_flags(flags); + printf("\n"); + if (flags & USBPF_XFERFLAG_DATA_FOLLOWS) + hexdump((const uint8_t *)ptr, snaplen); } - if (verbose >= 2) { - print_flags(up->up_flags); - print_status(up->up_status); - } } - static void -print_packets(char *data, const int datalen) +print_packets(const struct usbpf_pkthdr *up, uint32_t maxlen) { - struct usbpf_pkthdr *up; - const struct usbpf_xhdr *hdr; - u_int32_t framelen, x; - char *ptr, *next; + const uint32_t *data; + const uint32_t *ptr; + const uint32_t *next; + const uint32_t *end; + uint32_t datalen; + uint32_t framelen; + uint32_t snaplen; + uint32_t flags; + uint32_t x; - for (ptr = data; ptr < (data + datalen); ptr = next) { - hdr = (const struct usbpf_xhdr *)ptr; - up = (struct usbpf_pkthdr *)(ptr + hdr->uh_hdrlen); - next = ptr + USBPF_WORDALIGN(hdr->uh_hdrlen + hdr->uh_caplen); + if (maxlen < USBPF_PKTHDR_SIZE) + return; - ptr = ((char *)up) + sizeof(struct usbpf_pkthdr); + datalen = le32toh(up->hdr.up_totlen); + + if (datalen > maxlen || datalen < sizeof(*up)) + return; + + data = (const uint32_t *)(up + 1); + end = data + ((datalen - sizeof(*up)) / 4); + x = 0; + + for (ptr = data; ptr <= (end - USBPF_FRAMEHDR_SIZE); ptr = next, x++) { + + framelen = le32toh(ptr[0]); + flags = le32toh(ptr[1]); + snaplen = le32toh(ptr[2]); + + /* sanity check */ + if (snaplen > framelen) + snaplen = framelen; + + next = ptr + USBPF_FRAMEHDR_SIZE; + + if (flags & USBPF_XFERFLAG_DATA_FOLLOWS) + next += (USBPF_LENGTH_ALIGN(framelen) / 4); + else + snaplen = 0; + + /* Corrupt data? We are done! */ + if (next > end || next < data) + return; if (w_arg == NULL) - print_apacket(hdr, up, ptr); + print_apacket(up, ptr + USBPF_FRAMEHDR_SIZE, + framelen, snaplen, flags, x); pkt_captured++; - for (x = 0; x < up->up_frames; x++) { - framelen = le32toh(*((const u_int32_t *)ptr)); - ptr += sizeof(u_int32_t) + framelen; - } } } static void -write_packets(struct usbcap *p, const char *data, const int datalen) +write_packets(struct usbcap *p, const char *data, const uint32_t datalen) { - int len = htole32(datalen), ret; + uint32_t len = htole32(datalen), ret; - ret = write(p->wfd, &len, sizeof(int)); - assert(ret == sizeof(int)); + ret = write(p->wfd, &len, sizeof(uint32_t)); + assert(ret == sizeof(uint32_t)); ret = write(p->wfd, data, datalen); assert(ret == datalen); } @@ -307,15 +307,16 @@ static void read_file(struct usbcap *p) { - int datalen, ret; - char *data; + void *data; + uint32_t datalen; + int ret; - while ((ret = read(p->rfd, &datalen, sizeof(int))) == sizeof(int)) { + while ((ret = read(p->rfd, &datalen, sizeof(uint32_t))) == sizeof(uint32_t)) { datalen = le32toh(datalen); data = malloc(datalen); assert(data != NULL); ret = read(p->rfd, data, datalen); - assert(ret == datalen); + assert(ret == (int)datalen); print_packets(data, datalen); free(data); } @@ -329,18 +330,20 @@ int cc; while (doexit == 0) { - cc = read(p->fd, (char *)p->buffer, p->bufsize); + cc = read(p->fd, p->buffer, p->bufsize); if (cc < 0) { switch (errno) { case EINTR: break; + case EWOULDBLOCK: + break; default: fprintf(stderr, "read: %s\n", strerror(errno)); return; } continue; } - if (cc == 0) + if (cc < USBPF_PKTHDR_SIZE) continue; if (w_arg != NULL) write_packets(p, p->buffer, cc); @@ -363,7 +366,7 @@ assert(ret == sizeof(uf)); assert(le32toh(uf.magic) == USBCAP_FILEHDR_MAGIC); assert(uf.major == 0); - assert(uf.minor == 1); + assert(uf.minor == 2); } static void @@ -380,7 +383,7 @@ bzero(&uf, sizeof(uf)); uf.magic = htole32(USBCAP_FILEHDR_MAGIC); uf.major = 0; - uf.minor = 1; + uf.minor = 2; ret = write(p->wfd, (const void *)&uf, sizeof(uf)); assert(ret == sizeof(uf)); } @@ -389,11 +392,12 @@ usage(void) { -#define FMT " %-14s %s\n" - fprintf(stderr, "usage: usbdump [options]\n"); - fprintf(stderr, FMT, "-i ifname", "Listen on USB bus interface"); +#define FMT " %-14s %s\n" + fprintf(stderr, "usage: usbdump -d <...> [options]\n"); + fprintf(stderr, FMT, "-d ", "Listen on the give bus, device and endpoint"); + fprintf(stderr, FMT, "-b ", "Buffer size"); fprintf(stderr, FMT, "-r file", "Read the raw packets from file"); - fprintf(stderr, FMT, "-s snaplen", "Snapshot bytes from each packet"); + fprintf(stderr, FMT, "-s ", "Snapshot bytes from each USB packet."); fprintf(stderr, FMT, "-v", "Increases the verbose level"); fprintf(stderr, FMT, "-w file", "Write the raw packets to file"); #undef FMT @@ -405,24 +409,51 @@ { struct timeval tv; struct usbpf_insn total_insn; - struct usbpf_program total_prog; struct usbpf_stat us; struct usbpf_version uv; - struct usbcap uc, *p = &uc; + struct usbcap uc; + struct usbcap *p = &uc; struct usbpf_ifreq ufr; + char *ptr; long snapshot = 192; - u_int v; - int fd, o; - const char *optstring; + long v; + int fd; + int o; + int got_dev = 0; - bzero(&uc, sizeof(struct usbcap)); + memset(&uc, 0, sizeof(struct usbcap)); - optstring = "i:r:s:vw:"; - while ((o = getopt(argc, argv, optstring)) != -1) { + while ((o = getopt(argc, argv, "b:d:r:s:vw:")) != -1) { switch (o) { - case 'i': - i_arg = optarg; + case 'b': + bufsize = atoi(optarg); break; + case 'd': + got_dev = 1; + ptr = strstr(optarg, "."); + if (ptr != NULL) + ptr[0] = 0; + bus = atoi(optarg); + if (ptr == NULL) + break; + optarg = ptr + 1; + + ptr = strstr(optarg, "."); + if (ptr != NULL) + ptr[0] = 0; + device = atoi(optarg); + if (ptr == NULL) + break; + optarg = ptr + 1; + + ptr = strstr(optarg, "."); + if (ptr != NULL) + ptr[0] = 0; + endpoint = atoi(optarg); + if (ptr == NULL) + break; + optarg = ptr + 1; + break; case 'r': r_arg = optarg; init_rfile(p); @@ -454,12 +485,14 @@ exit(EXIT_SUCCESS); } + if (got_dev == 0) + usage(); + p->fd = fd = open("/dev/usbpf", O_RDONLY); if (p->fd < 0) { fprintf(stderr, "(no devices found)\n"); return (EXIT_FAILURE); } - if (ioctl(fd, UIOCVERSION, (caddr_t)&uv) < 0) { fprintf(stderr, "UIOCVERSION: %s\n", strerror(errno)); return (EXIT_FAILURE); @@ -469,46 +502,44 @@ fprintf(stderr, "kernel bpf filter out of date"); return (EXIT_FAILURE); } - - if ((ioctl(fd, UIOCGBLEN, (caddr_t)&v) < 0) || v < 65536) - v = 65536; - for ( ; v != 0; v >>= 1) { - (void)ioctl(fd, UIOCSBLEN, (caddr_t)&v); - (void)strncpy(ufr.ufr_name, i_arg, sizeof(ufr.ufr_name)); - if (ioctl(fd, UIOCSETIF, (caddr_t)&ufr) >= 0) - break; - } - if (v == 0) { - fprintf(stderr, "UIOCSBLEN: %s: No buffer size worked", i_arg); + if (ioctl(fd, UIOCGBLEN, (caddr_t)&v) < 0) { + fprintf(stderr, "UIOCGBLEN: %s\n", strerror(errno)); return (EXIT_FAILURE); } + if (bufsize < 0 || bufsize > v) + bufsize = v; - if (ioctl(fd, UIOCGBLEN, (caddr_t)&v) < 0) { - fprintf(stderr, "UIOCGBLEN: %s", strerror(errno)); + /* XXX no read filter rules yet so at this moment accept everything */ + total_insn.code = (uint16_t)(USBPF_RET | USBPF_K); + total_insn.jt = 0; + total_insn.jf = 0; + total_insn.k = snapshot; + + memset(&ufr, 0, sizeof(ufr)); + + ufr.ua_bus_unit = bus; + ufr.ua_dev_unit = device; + if (endpoint < 0) + ufr.ua_endpoint_mask = -1; + else + ufr.ua_endpoint_mask = 3U << (2 * (endpoint & 0xF)); + + ufr.ua_filter_ptr = &total_insn; + ufr.ua_filter_len = sizeof(total_insn); + + if (ioctl(fd, UIOCSETIF, (caddr_t)&ufr) < 0) { + fprintf(stderr, "UIOCSETIF: %s\n", strerror(errno)); return (EXIT_FAILURE); } p->bufsize = v; - p->buffer = (u_char *)malloc(p->bufsize); + p->buffer = malloc(p->bufsize); if (p->buffer == NULL) { fprintf(stderr, "malloc: %s", strerror(errno)); return (EXIT_FAILURE); } - /* XXX no read filter rules yet so at this moment accept everything */ - total_insn.code = (u_short)(USBPF_RET | USBPF_K); - total_insn.jt = 0; - total_insn.jf = 0; - total_insn.k = snapshot; - - total_prog.uf_len = 1; - total_prog.uf_insns = &total_insn; - if (ioctl(p->fd, UIOCSETF, (caddr_t)&total_prog) < 0) { - fprintf(stderr, "UIOCSETF: %s", strerror(errno)); - return (EXIT_FAILURE); - } - - /* 1 second read timeout */ + /* set timeout */ tv.tv_sec = 1; tv.tv_usec = 0; if (ioctl(p->fd, UIOCSRTIMEOUT, (caddr_t)&tv) < 0) { @@ -528,8 +559,8 @@ /* XXX what's difference between pkt_captured and us.us_recv? */ printf("\n"); printf("%d packets captured\n", pkt_captured); - printf("%d packets received by filter\n", us.us_recv); - printf("%d packets dropped by kernel\n", us.us_drop); + printf("%lld packets received by filter\n", (long long)us.us_recv); + printf("%lld packets dropped by kernel\n", (long long)us.us_drop); if (p->fd > 0) close(p->fd); --Boundary-00=_13D7MYPyuRTPmLV-- From owner-freebsd-usb@FreeBSD.ORG Tue Nov 23 22:24:09 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 46723106567A; Tue, 23 Nov 2010 22:24:09 +0000 (UTC) (envelope-from hselasky@c2i.net) Received: from swip.net (mailfe07.c2i.net [212.247.154.194]) by mx1.freebsd.org (Postfix) with ESMTP id 3E2DC8FC0A; Tue, 23 Nov 2010 22:24:07 +0000 (UTC) X-Cloudmark-Score: 0.000000 [] X-Cloudmark-Analysis: v=1.1 cv=vDUu4pv7IaR8DTRzVjjCCOYxZ4yAx/7/dG3VXczAVmg= c=1 sm=1 a=Q9fys5e9bTEA:10 a=CL8lFSKtTFcA:10 a=i9M/sDlu2rpZ9XS819oYzg==:17 a=6I5d2MoRAAAA:8 a=bmL0k31DdukF0L54MHEA:9 a=GiBFSOmcp0ExmL4i0MTBzoW8rywA:4 a=PUjeQqilurYA:10 a=i9M/sDlu2rpZ9XS819oYzg==:117 Received: from [188.126.198.129] (account mc467741@c2i.net HELO laptop002.hselasky.homeunix.org) by mailfe07.swip.net (CommuniGate Pro SMTP 5.2.19) with ESMTPA id 52927339; Tue, 23 Nov 2010 23:24:06 +0100 From: Hans Petter Selasky To: Weongyo Jeong Date: Tue, 23 Nov 2010 23:24:52 +0100 User-Agent: KMail/1.13.5 (FreeBSD/8.1-STABLE; KDE/4.4.5; amd64; ; ) References: <20101123212448.GG92881@weongyo> <201011232319.33678.hselasky@c2i.net> In-Reply-To: <201011232319.33678.hselasky@c2i.net> X-Face: +~\`s("[*|O,="7?X@L.elg*F"OA\I/3%^p8g?ab%RN'(; _IjlA: hGE..Ew, XAQ*o#\/M~SC=S1-f9{EzRfT'|Hhll5Q]ha5Bt-s|oTlKMusi:1e[wJl}kd}GR Z0adGx-x_0zGbZj'e(Y[(UNle~)8CQWXW@:DX+9)_YlB[tIccCPN$7/L' MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Message-Id: <201011232324.52536.hselasky@c2i.net> Cc: freebsd-usb@freebsd.org, Jung-uk Kim Subject: Re: [RFC] USBdump patches X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Nov 2010 22:24:09 -0000 NOTE: Please revert the following patch before applying my patch, else there is a conflict. http://svn.freebsd.org/changeset/base/215764 --HPS From owner-freebsd-usb@FreeBSD.ORG Tue Nov 23 22:39:41 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B8E35106566B; Tue, 23 Nov 2010 22:39:41 +0000 (UTC) (envelope-from weongyo.jeong@gmail.com) Received: from mail-ww0-f50.google.com (mail-ww0-f50.google.com [74.125.82.50]) by mx1.freebsd.org (Postfix) with ESMTP id EAC198FC13; Tue, 23 Nov 2010 22:39:40 +0000 (UTC) Received: by wwd20 with SMTP id 20so8849073wwd.31 for ; Tue, 23 Nov 2010 14:39:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:received:from:date:to:cc :subject:message-id:reply-to:references:mime-version:content-type :content-disposition:in-reply-to:user-agent:organization :x-operation-sytem; bh=/VHs0lpSKSyfCFEb+vsYrULT4UreuAe3kr0mQ1QsUoo=; b=GmijduyDdavrmxdyRW0ESaHnz/DV9sqAE04+Hk9PxfpOHh1dzaJpBkh8ETwjnZbUEl BkVnfYF1HCnrd++qmMNw6LcGLtrKpKQUwl9XJ8DW5K+PwDCW0NcMb1xoSPyhg41hg72B lAuLbypHHsXduCl27MOyP+3QfbWDSq6ygycMg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:date:to:cc:subject:message-id:reply-to:references:mime-version :content-type:content-disposition:in-reply-to:user-agent :organization:x-operation-sytem; b=BkhYPOmDYJXaC4eSOFZ0DdlepogIQ9NaQWuRo8jSstMnDpSHwHKavzmIybvqhp+tRM +mvPP5jEewMhWxuEfoPmXRlT5e5qpKD4Oim8hivXU3jSs/1SuJccrxTGxLJ6wOmGPMQQ rnaHBcxfr4iCahH6AkN8ppz9qNbPW59aVhfws= Received: by 10.227.29.102 with SMTP id p38mr8355255wbc.220.1290551978913; Tue, 23 Nov 2010 14:39:38 -0800 (PST) Received: from weongyo ([174.35.1.224]) by mx.google.com with ESMTPS id k4sm3143348weq.9.2010.11.23.14.39.34 (version=SSLv3 cipher=RC4-MD5); Tue, 23 Nov 2010 14:39:37 -0800 (PST) Received: by weongyo (sSMTP sendmail emulation); Tue, 23 Nov 2010 14:40:02 -0800 From: Weongyo Jeong Date: Tue, 23 Nov 2010 14:40:02 -0800 To: Hans Petter Selasky Message-ID: <20101123224002.GH92881@weongyo> References: <20101123212448.GG92881@weongyo> <201011232319.33678.hselasky@c2i.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201011232319.33678.hselasky@c2i.net> User-Agent: Mutt/1.4.2.3i Organization: CDNetworks. X-Operation-Sytem: FreeBSD Cc: freebsd-usb@freebsd.org, Jung-uk Kim Subject: Re: [RFC] USBdump patches X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Weongyo Jeong List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Nov 2010 22:39:41 -0000 On Tue, Nov 23, 2010 at 11:19:33PM +0100, Hans Petter Selasky wrote: > Hi, > > Please find attached official usbdump patch from HPS trying to re-use as much > as possible of Weongyo's code which was committed not long ago. You need to > SVN up to the latest 9-current. > > This patch should fix all USB-dump issues reported so far! > > 1) Fix for proper offset calculation on ISOCHRONOUS reception. > 2) Fixes for device mode. > 3) PF-virtual-machine is OK (and done before copy of data). > 4) Can load and unload the PF-code like a module. > > How to use: > > cd /usr/src > cat usbdump_r215656_patch.txt | patch > > You need to make new kernel, but not userland. > > Install sys/dev/usb/usb_pf.h into /usr/include/dev/usb/ and make all install > in src/usr.sbin/usbdump . > > After reboot: > > kldload usb_pf > > usbdump -d -1 -vvv > > man usbdump NACK. You already could recognize that the patch is quite big and multiple patches are mixed into one. Please separate into smallest pieces then send freebsd-usb@ again. I don't want to do a jumbo jump. regards, Weongyo Jeong From owner-freebsd-usb@FreeBSD.ORG Tue Nov 23 22:44:22 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3AF59106566C; Tue, 23 Nov 2010 22:44:22 +0000 (UTC) (envelope-from hselasky@c2i.net) Received: from swip.net (mailfe02.c2i.net [212.247.154.34]) by mx1.freebsd.org (Postfix) with ESMTP id 6B0A48FC08; Tue, 23 Nov 2010 22:44:19 +0000 (UTC) X-Cloudmark-Score: 0.000000 [] X-Cloudmark-Analysis: v=1.1 cv=yevn+QCjI6xy199BDvBOOiO14qYvyLq62he9tTtU3M8= c=1 sm=1 a=CL8lFSKtTFcA:10 a=i9M/sDlu2rpZ9XS819oYzg==:17 a=bXOYZ0yGvB0H-BxlFEsA:9 a=PRQBQePtPsWppuMY5u9RZPxO9qsA:4 a=PUjeQqilurYA:10 a=PxqV9peTTuALj_g5XaAA:9 a=o_NIKTLwjSL8JrpYuUYA:7 a=nMl8Cb_gUz567UfiHFI5zKHAStQA:4 a=KQMpSm9P4UcOS1fI:21 a=ecBVoA20XLTE8kSV:21 a=i9M/sDlu2rpZ9XS819oYzg==:117 Received: from [188.126.198.129] (account mc467741@c2i.net HELO laptop002.hselasky.homeunix.org) by mailfe02.swip.net (CommuniGate Pro SMTP 5.2.19) with ESMTPA id 52931285; Tue, 23 Nov 2010 23:44:18 +0100 To: Weongyo Jeong From: Hans Petter Selasky X-Face: +~\`s("[*|O,="7?X@L.elg*F"OA\I/3%^p8g?ab%RN'( =?iso-8859-15?q?=3B=5FIjlA=3A=0A=09hGE=2E=2EEw?=, =?iso-8859-15?q?XAQ*o=23=5C/M=7ESC=3DS1-f9=7BEzRfT=27=7CHhll5Q=5Dha5Bt-s=7Co?= =?iso-8859-15?q?TlKMusi=3A1e=5BwJl=7Dkd=7DGR=0A=09Z0adGx-x=5F0zGbZj=27e?=(Y[(UNle~)8CQWXW@:DX+9)_YlB[tIccCPN$7/L' Date: Tue, 23 Nov 2010 23:45:05 +0100 MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_xPE7MXid1vdrtfA" Message-Id: <201011232345.05070.hselasky@c2i.net> Cc: freebsd-usb@freebsd.org, Jung-uk Kim Subject: Re: [RFC] USBdump patches X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Nov 2010 22:44:22 -0000 --Boundary-00=_xPE7MXid1vdrtfA Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Update patch for latest SVN. --HPS --Boundary-00=_xPE7MXid1vdrtfA Content-Type: text/plain; charset="iso-8859-15"; name="usbdump_r215783_patch.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="usbdump_r215783_patch.txt" === sys/conf/files ================================================================== --- sys/conf/files (revision 215787) +++ sys/conf/files (local) @@ -1779,12 +1779,15 @@ dev/usb/usb_mbuf.c optional usb dev/usb/usb_msctest.c optional usb dev/usb/usb_parse.c optional usb -dev/usb/usb_pf.c optional usb dev/usb/usb_process.c optional usb dev/usb/usb_request.c optional usb dev/usb/usb_transfer.c optional usb dev/usb/usb_util.c optional usb # +# USB packet filter +# +dev/usb/usb_pf.c optional usb_pf +# # USB network drivers # dev/usb/net/if_aue.c optional aue === sys/dev/usb/controller/usb_controller.c ================================================================== --- sys/dev/usb/controller/usb_controller.c (revision 215787) +++ sys/dev/usb/controller/usb_controller.c (local) @@ -61,7 +61,6 @@ #include #include -#include /* function prototypes */ @@ -548,8 +547,6 @@ TAILQ_INIT(&bus->intr_q.head); - usbpf_attach(bus, &bus->uif); - #if USB_HAVE_BUSDMA usb_dma_tag_setup(bus->dma_parent_tag, bus->dma_tags, dmat, &bus->bus_mtx, NULL, 32, USB_BUS_DMA_TAG_MAX); @@ -597,34 +594,5 @@ usb_dma_tag_unsetup(bus->dma_parent_tag); #endif - usbpf_detach(bus); - mtx_destroy(&bus->bus_mtx); } - -struct usb_bus * -usb_bus_find(const char *name) -{ - struct usb_bus *ubus; - devclass_t dc; - device_t *devlist; - int devcount, error, i; - const char *nameunit; - - dc = devclass_find("usbus"); - if (dc == NULL) - return (NULL); - error = devclass_get_devices(dc, &devlist, &devcount); - if (error != 0) - return (NULL); - for (i = 0; i < devcount; i++) { - nameunit = device_get_nameunit(devlist[i]); - if (!strncmp(name, nameunit, strlen(nameunit))) { - ubus = device_get_ivars(devlist[i]); - free(devlist, M_TEMP); - return (ubus); - } - } - free(devlist, M_TEMP); - return (NULL); -} === sys/dev/usb/usb_bus.h ================================================================== --- sys/dev/usb/usb_bus.h (revision 215787) +++ sys/dev/usb/usb_bus.h (local) @@ -86,8 +86,6 @@ struct usb_bus_methods *methods; /* filled by HC driver */ struct usb_device **devices; - struct usbpf_if *uif; /* USB Packet Filter */ - usb_power_mask_t hw_power_state; /* see USB_HW_POWER_XXX */ usb_size_t uframe_usage[USB_HS_MICRO_FRAMES_MAX]; === sys/dev/usb/usb_controller.h ================================================================== --- sys/dev/usb/usb_controller.h (revision 215787) +++ sys/dev/usb/usb_controller.h (local) @@ -221,6 +221,5 @@ uint16_t usb_isoc_time_expand(struct usb_bus *bus, uint16_t isoc_time_curr); uint16_t usbd_fs_isoc_schedule_isoc_time_expand(struct usb_device *udev, struct usb_fs_isoc_schedule **pp_start, struct usb_fs_isoc_schedule **pp_end, uint16_t isoc_time); uint8_t usbd_fs_isoc_schedule_alloc(struct usb_fs_isoc_schedule *fss, uint8_t *pstart, uint16_t len); -struct usb_bus *usb_bus_find(const char *name); #endif /* _USB_CONTROLLER_H_ */ === sys/dev/usb/usb_dynamic.c ================================================================== --- sys/dev/usb/usb_dynamic.c (revision 215787) +++ sys/dev/usb/usb_dynamic.c (local) @@ -58,6 +58,9 @@ static usb_temp_unsetup_t usb_temp_unsetup_w; static usb_test_quirk_t usb_test_quirk_w; static usb_quirk_ioctl_t usb_quirk_ioctl_w; +#if USB_HAVE_PF +static usb_pf_xfertap_t usb_pf_xfertap_w; +#endif /* global variables */ usb_handle_req_t *usb_temp_get_desc_p = &usb_temp_get_desc_w; @@ -66,6 +69,9 @@ usb_test_quirk_t *usb_test_quirk_p = &usb_test_quirk_w; usb_quirk_ioctl_t *usb_quirk_ioctl_p = &usb_quirk_ioctl_w; devclass_t usb_devclass_ptr = NULL; +#if USB_HAVE_PF +usb_pf_xfertap_t *usb_pf_xfertap_p = &usb_pf_xfertap_w; +#endif static usb_error_t usb_temp_setup_by_index_w(struct usb_device *udev, uint16_t index) @@ -103,6 +109,14 @@ } } +#if USB_HAVE_PF +static void +usb_pf_xfertap_w(struct usb_xfer *xfer, int type) +{ + /* NOP */ +} +#endif + void usb_quirk_unload(void *arg) { @@ -147,3 +161,19 @@ pause("WAIT", hz); } + +#if USB_HAVE_PF +void +usb_pf_unload(void *arg) +{ + /* reset function pointers */ + + usb_pf_xfertap_p = &usb_pf_xfertap_w; + + /* wait for CPU to exit the loaded functions, if any */ + + /* XXX this is a tradeoff */ + + pause("WAIT", hz); +} +#endif === sys/dev/usb/usb_dynamic.h ================================================================== --- sys/dev/usb/usb_dynamic.h (revision 215787) +++ sys/dev/usb/usb_dynamic.h (local) @@ -32,6 +32,7 @@ struct usb_device; struct usbd_lookup_info; struct usb_device_request; +struct usb_xfer; /* typedefs */ @@ -42,6 +43,7 @@ typedef int (usb_quirk_ioctl_t)(unsigned long cmd, caddr_t data, int fflag, struct thread *td); typedef void (usb_temp_unsetup_t)(struct usb_device *udev); +typedef void (usb_pf_xfertap_t)(struct usb_xfer *, int); /* global function pointers */ @@ -51,11 +53,13 @@ extern usb_test_quirk_t *usb_test_quirk_p; extern usb_quirk_ioctl_t *usb_quirk_ioctl_p; extern devclass_t usb_devclass_ptr; +extern usb_pf_xfertap_t *usb_pf_xfertap_p; /* function prototypes */ void usb_temp_unload(void *); void usb_quirk_unload(void *); void usb_bus_unload(void *); +void usb_pf_unload(void *); #endif /* _USB_DYNAMIC_H_ */ === sys/dev/usb/usb_freebsd.h ================================================================== --- sys/dev/usb/usb_freebsd.h (revision 215787) +++ sys/dev/usb/usb_freebsd.h (local) @@ -41,6 +41,7 @@ #define USB_HAVE_TT_SUPPORT 1 #define USB_HAVE_POWERD 1 #define USB_HAVE_MSCTEST 1 +#define USB_HAVE_PF 1 #define USB_TD_GET_PROC(td) (td)->td_proc #define USB_PROC_GET_GID(td) (td)->p_pgid === sys/dev/usb/usb_pf.c ================================================================== --- sys/dev/usb/usb_pf.c (revision 215787) +++ sys/dev/usb/usb_pf.c (local) @@ -1,11 +1,12 @@ /*- + * Copyright (c) 2010 Hans Petter Selasky. All rights reserved. * Copyright (c) 1990, 1991, 1993 * The Regents of the University of California. All rights reserved. * - * This code is derived from the Stanford/CMU enet packet filter, - * (net/enet.c) distributed as part of 4.3BSD, and code contributed - * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence - * Berkeley Laboratory. + * The packet filter virtual CPU machine code is derived from the + * Stanford/CMU enet packet filter, (net/enet.c) distributed as part + * of 4.3BSD, and code contributed to Berkeley by Steven McCanne and + * Van Jacobson both of Lawrence Berkeley Laboratory. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -34,19 +35,23 @@ #include __FBSDID("$FreeBSD$"); + #include #include #include #include #include +#include #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -54,75 +59,21 @@ #include #include #include +#include /* - * All usbpf implementations are extracted from bpf(9) APIs and it's - * specialized for USB packet filtering between the driver and the host - * controller. + * The virtual CPU machine code has been extracted from bpf(9). */ MALLOC_DEFINE(M_USBPF, "USBPktFilter", "USB Packet Filter"); -/* - * Rotate the packet buffers in descriptor ud. Move the store buffer into the - * hold slot, and the free buffer ino the store slot. Zero the length of the - * new store buffer. Descriptor lock should be held. - */ -#define USBPF_ROTATE_BUFFERS(ud) do { \ - (ud)->ud_hbuf = (ud)->ud_sbuf; \ - (ud)->ud_hlen = (ud)->ud_slen; \ - (ud)->ud_sbuf = (ud)->ud_fbuf; \ - (ud)->ud_slen = 0; \ - (ud)->ud_fbuf = NULL; \ - usbpf_bufheld(ud); \ -} while (0) +MODULE_DEPEND(usb_pf, usb, 1, 1, 1); +MODULE_VERSION(usb_pf, 1); -#ifndef __i386__ -#define USBPF_ALIGN -#endif +static struct mtx usbpf_global_mtx; /* global lock */ +static TAILQ_HEAD(, usbpf_d) usbpf_filters; /* list of filters */ +static struct cdev *usbpf_dev; /* our character device */ -#ifndef USBPF_ALIGN -#define USBPF_EXTRACT_SHORT(p) ((u_int16_t)ntohs(*(u_int16_t *)p)) -#define USBPF_EXTRACT_LONG(p) (ntohl(*(u_int32_t *)p)) -#else -#define USBPF_EXTRACT_SHORT(p) \ - ((u_int16_t) \ - ((u_int16_t)*((u_char *)p+0)<<8| \ - (u_int16_t)*((u_char *)p+1)<<0)) -#define USBPF_EXTRACT_LONG(p) \ - ((u_int32_t)*((u_char *)p+0)<<24| \ - (u_int32_t)*((u_char *)p+1)<<16| \ - (u_int32_t)*((u_char *)p+2)<<8| \ - (u_int32_t)*((u_char *)p+3)<<0) -#endif - -/* - * Number of scratch memory words (for USBPF_LD|USBPF_MEM and USBPF_ST). - */ -#define USBPF_MEMWORDS 16 - -/* Values for ud_state */ -#define USBPF_IDLE 0 /* no select in progress */ -#define USBPF_WAITING 1 /* waiting for read timeout in select */ -#define USBPF_TIMED_OUT 2 /* read timeout has expired in select */ - -#define PRIUSB 26 /* interruptible */ - -/* Frame directions */ -enum usbpf_direction { - USBPF_D_IN, /* See incoming frames */ - USBPF_D_INOUT, /* See incoming and outgoing frames */ - USBPF_D_OUT /* See outgoing frames */ -}; - -static void usbpf_append_bytes(struct usbpf_d *, caddr_t, u_int, void *, - u_int); -static void usbpf_attachd(struct usbpf_d *, struct usbpf_if *); -static void usbpf_detachd(struct usbpf_d *); -static int usbpf_canfreebuf(struct usbpf_d *); -static void usbpf_buf_reclaimed(struct usbpf_d *); -static int usbpf_canwritebuf(struct usbpf_d *); - static d_open_t usbpf_open; static d_read_t usbpf_read; static d_write_t usbpf_write; @@ -141,107 +92,7 @@ .d_kqfilter = usbpf_kqfilter, }; -static struct cdev *usbpf_cdev; -static LIST_HEAD(, usbpf_if) usbpf_iflist; -static struct mtx usbpf_mtx; /* global lock */ -static int usbpf_uifd_cnt; - -static int usbpf_bufsize = 4096; -#define USBPF_MINBUFSIZE 32 -#define USBPF_MAXBUFSIZE 0x80000 -static int usbpf_maxbufsize = USBPF_MAXBUFSIZE; -#define USBPF_MAXINSNS 512 -static int usbpf_maxinsns = USBPF_MAXINSNS; - -static void -usbpf_buffer_init(struct usbpf_d *ud) -{ - - ud->ud_bufsize = usbpf_bufsize; -} - -/* - * Free USBPF kernel buffers on device close. - */ -static void -usbpf_buffer_free(struct usbpf_d *ud) -{ - - if (ud->ud_sbuf != NULL) - free(ud->ud_sbuf, M_USBPF); - if (ud->ud_hbuf != NULL) - free(ud->ud_hbuf, M_USBPF); - if (ud->ud_fbuf != NULL) - free(ud->ud_fbuf, M_USBPF); - -#ifdef INVARIANTS - ud->ud_sbuf = ud->ud_hbuf = ud->ud_fbuf = (caddr_t)~0; -#endif -} - -static void -usbpf_buffer_alloc(struct usbpf_d *ud) -{ - - KASSERT(ud->ud_fbuf == NULL, ("%s: ud_fbuf != NULL", __func__)); - KASSERT(ud->ud_sbuf == NULL, ("%s: ud_sbuf != NULL", __func__)); - KASSERT(ud->ud_hbuf == NULL, ("%s: ud_hbuf != NULL", __func__)); - - ud->ud_fbuf = (caddr_t)malloc(ud->ud_bufsize, M_USBPF, M_WAITOK); - ud->ud_sbuf = (caddr_t)malloc(ud->ud_bufsize, M_USBPF, M_WAITOK); - ud->ud_hbuf = NULL; - ud->ud_slen = 0; - ud->ud_hlen = 0; -} - -/* - * Copy buffer storage to user space in read(). - */ -static int -usbpf_buffer_uiomove(struct usbpf_d *ud, caddr_t buf, u_int len, - struct uio *uio) -{ - - return (uiomove(buf, len, uio)); -} - -/* - * Simple data copy to the current kernel buffer. - */ -static void -usbpf_buffer_append_bytes(struct usbpf_d *ud, caddr_t buf, u_int offset, - void *src, u_int len) -{ - u_char *src_bytes; - - src_bytes = (u_char *)src; - bcopy(src_bytes, buf + offset, len); -} - -/* - * Allocate or resize buffers. - */ -static int -usbpf_buffer_ioctl_sblen(struct usbpf_d *ud, u_int *i) -{ - u_int size; - - USBPFD_LOCK(ud); - if (ud->ud_bif != NULL) { - USBPFD_UNLOCK(ud); - return (EINVAL); - } - size = *i; - if (size > usbpf_maxbufsize) - *i = size = usbpf_maxbufsize; - else if (size < USBPF_MINBUFSIZE) - *i = size = USBPF_MINBUFSIZE; - ud->ud_bufsize = size; - USBPFD_UNLOCK(ud); - return (0); -} - -static const u_short usbpf_code_map[] = { +static const uint16_t usbpf_code_map[] = { 0x10ff, /* 0x00-0x0f: 1111111100001000 */ 0x3070, /* 0x10-0x1f: 0000111000001100 */ 0x3131, /* 0x20-0x2f: 1000110010001100 */ @@ -271,7 +122,7 @@ * The kernel needs to be able to verify an application's filter code. * Otherwise, a bogus program could easily crash the system. */ -static int +static uint8_t usbpf_validate(const struct usbpf_insn *f, int len) { register int i; @@ -297,13 +148,13 @@ * the code block. */ if (USBPF_CLASS(p->code) == USBPF_JMP) { - register u_int offset; + uint32_t offset; if (p->code == (USBPF_JMP|USBPF_JA)) offset = p->k; else offset = p->jt > p->jf ? p->jt : p->jf; - if (offset >= (u_int)(len - i) - 1) + if (offset >= (uint32_t)(len - i - 1)) return (0); continue; } @@ -326,295 +177,128 @@ return (USBPF_CLASS(f[len - 1].code) == USBPF_RET); } -#ifdef _KERNEL -#define MINDEX(m, k) \ -{ \ - register int len = m->m_len; \ - \ - while (k >= len) { \ - k -= len; \ - m = m->m_next; \ - if (m == 0) \ - return (0); \ - len = m->m_len; \ - } \ -} - -static u_int16_t m_xhalf(struct mbuf *m, usbpf_u_int32 k, int *err); -static u_int32_t m_xword(struct mbuf *m, usbpf_u_int32 k, int *err); - -static u_int32_t -m_xword(struct mbuf *m, usbpf_u_int32 k, int *err) -{ - size_t len; - u_char *cp, *np; - struct mbuf *m0; - - len = m->m_len; - while (k >= len) { - k -= len; - m = m->m_next; - if (m == 0) - goto bad; - len = m->m_len; - } - cp = mtod(m, u_char *) + k; - if (len - k >= 4) { - *err = 0; - return (USBPF_EXTRACT_LONG(cp)); - } - m0 = m->m_next; - if (m0 == 0 || m0->m_len + len - k < 4) - goto bad; - *err = 0; - np = mtod(m0, u_char *); - switch (len - k) { - case 1: - return (((u_int32_t)cp[0] << 24) | - ((u_int32_t)np[0] << 16) | - ((u_int32_t)np[1] << 8) | - (u_int32_t)np[2]); - - case 2: - return (((u_int32_t)cp[0] << 24) | - ((u_int32_t)cp[1] << 16) | - ((u_int32_t)np[0] << 8) | - (u_int32_t)np[1]); - - default: - return (((u_int32_t)cp[0] << 24) | - ((u_int32_t)cp[1] << 16) | - ((u_int32_t)cp[2] << 8) | - (u_int32_t)np[0]); - } - bad: - *err = 1; - return (0); -} - -static u_int16_t -m_xhalf(struct mbuf *m, usbpf_u_int32 k, int *err) -{ - size_t len; - u_char *cp; - struct mbuf *m0; - - len = m->m_len; - while (k >= len) { - k -= len; - m = m->m_next; - if (m == 0) - goto bad; - len = m->m_len; - } - cp = mtod(m, u_char *) + k; - if (len - k >= 2) { - *err = 0; - return (USBPF_EXTRACT_SHORT(cp)); - } - m0 = m->m_next; - if (m0 == 0) - goto bad; - *err = 0; - return ((cp[0] << 8) | mtod(m0, u_char *)[0]); - bad: - *err = 1; - return (0); -} -#endif - /* * Execute the filter program starting at pc on the packet p * wirelen is the length of the original packet * buflen is the amount of data present */ -static u_int -usbpf_filter(const struct usbpf_insn *pc, u_char *p, u_int wirelen, - u_int buflen) +static uint32_t +usbpf_filter_sub(const struct usbpf_insn *pc, + struct usb_page_cache *upc, uint32_t offset, uint32_t buflen) { - u_int32_t A = 0, X = 0; - usbpf_u_int32 k; - u_int32_t mem[USBPF_MEMWORDS]; + uint32_t A = 0; + uint32_t X = 0; + uint32_t k; + uint32_t mem[USBPF_MEMWORDS]; + uint8_t temp[8]; - /* - * XXX temporarily the filter system is disabled because currently it - * could not handle the some machine code properly that leads to - * kernel crash by invalid usage. - */ - return ((u_int)-1); - if (pc == NULL) /* * No filter means accept all. */ - return ((u_int)-1); + return ((uint32_t)-1); --pc; while (1) { ++pc; switch (pc->code) { - default: -#ifdef _KERNEL - return (0); -#else - abort(); -#endif - case USBPF_RET|USBPF_K: - return ((u_int)pc->k); + return ((uint32_t)pc->k); case USBPF_RET|USBPF_A: - return ((u_int)A); + return ((uint32_t)A); case USBPF_LD|USBPF_W|USBPF_ABS: k = pc->k; - if (k > buflen || sizeof(int32_t) > buflen - k) { -#ifdef _KERNEL - int merr; - - if (buflen != 0) - return (0); - A = m_xword((struct mbuf *)p, k, &merr); - if (merr != 0) - return (0); - continue; -#else + if (k > buflen || sizeof(uint32_t) > buflen - k) return (0); -#endif - } -#ifdef USBPF_ALIGN - if (((intptr_t)(p + k) & 3) != 0) - A = USBPF_EXTRACT_LONG(&p[k]); - else -#endif - A = ntohl(*(int32_t *)(p + k)); + + /* get the actual data */ + usbd_copy_out(upc, offset + k, &temp, 4); + + /* get unsigned little endian 32-bit value */ + A = UGETDW(temp); continue; case USBPF_LD|USBPF_H|USBPF_ABS: k = pc->k; - if (k > buflen || sizeof(int16_t) > buflen - k) { -#ifdef _KERNEL - int merr; - - if (buflen != 0) - return (0); - A = m_xhalf((struct mbuf *)p, k, &merr); - continue; -#else + if (k > buflen || sizeof(uint16_t) > buflen - k) return (0); -#endif - } - A = USBPF_EXTRACT_SHORT(&p[k]); + + /* get the actual data */ + usbd_copy_out(upc, offset + k, &temp, 2); + + /* get unsigned little endian 16-bit value */ + A = UGETW(temp); continue; case USBPF_LD|USBPF_B|USBPF_ABS: k = pc->k; - if (k >= buflen) { -#ifdef _KERNEL - struct mbuf *m; - - if (buflen != 0) - return (0); - m = (struct mbuf *)p; - MINDEX(m, k); - A = mtod(m, u_char *)[k]; - continue; -#else + if (k >= buflen) return (0); -#endif - } - A = p[k]; + + /* get the actual data */ + usbd_copy_out(upc, offset + k, &temp, 1); + + A = temp[0]; continue; case USBPF_LD|USBPF_W|USBPF_LEN: - A = wirelen; + A = buflen; continue; case USBPF_LDX|USBPF_W|USBPF_LEN: - X = wirelen; + X = buflen; continue; case USBPF_LD|USBPF_W|USBPF_IND: k = X + pc->k; if (pc->k > buflen || X > buflen - pc->k || - sizeof(int32_t) > buflen - k) { -#ifdef _KERNEL - int merr; - - if (buflen != 0) - return (0); - A = m_xword((struct mbuf *)p, k, &merr); - if (merr != 0) - return (0); - continue; -#else + sizeof(uint32_t) > buflen - k) return (0); -#endif - } -#ifdef USBPF_ALIGN - if (((intptr_t)(p + k) & 3) != 0) - A = USBPF_EXTRACT_LONG(&p[k]); - else -#endif - A = ntohl(*(int32_t *)(p + k)); + + /* get the actual data */ + usbd_copy_out(upc, offset + k, &temp, 4); + + /* get unsigned little endian 32-bit value */ + A = UGETDW(temp); continue; case USBPF_LD|USBPF_H|USBPF_IND: k = X + pc->k; if (X > buflen || pc->k > buflen - X || - sizeof(int16_t) > buflen - k) { -#ifdef _KERNEL - int merr; - - if (buflen != 0) - return (0); - A = m_xhalf((struct mbuf *)p, k, &merr); - if (merr != 0) - return (0); - continue; -#else + sizeof(uint16_t) > buflen - k) return (0); -#endif - } - A = USBPF_EXTRACT_SHORT(&p[k]); + + /* get the actual data */ + usbd_copy_out(upc, offset + k, &temp, 2); + + /* get unsigned little endian 16-bit value */ + A = UGETW(temp); continue; case USBPF_LD|USBPF_B|USBPF_IND: k = X + pc->k; - if (pc->k >= buflen || X >= buflen - pc->k) { -#ifdef _KERNEL - struct mbuf *m; - - if (buflen != 0) - return (0); - m = (struct mbuf *)p; - MINDEX(m, k); - A = mtod(m, u_char *)[k]; - continue; -#else + if (pc->k >= buflen || X >= buflen - pc->k) return (0); -#endif - } - A = p[k]; + + /* get the actual data */ + usbd_copy_out(upc, offset + k, &temp, 1); + + /* get 8-bit value */ + A = temp[0]; continue; case USBPF_LDX|USBPF_MSH|USBPF_B: k = pc->k; - if (k >= buflen) { -#ifdef _KERNEL - register struct mbuf *m; - - if (buflen != 0) - return (0); - m = (struct mbuf *)p; - MINDEX(m, k); - X = (mtod(m, u_char *)[k] & 0xf) << 2; - continue; -#else + if (k >= buflen) return (0); -#endif - } - X = (p[pc->k] & 0xf) << 2; + + /* get the actual data */ + usbd_copy_out(upc, offset + k, &temp, 1); + + /* get 4-bit value */ + X = (temp[0] & 0xf) << 2; continue; case USBPF_LD|USBPF_IMM: @@ -754,51 +438,39 @@ case USBPF_MISC|USBPF_TXA: A = X; continue; + default: + return (0); } } } -static void -usbpf_free(struct usbpf_d *ud) +static uint8_t +usbpf_filter(struct usbpf_d *ud, struct usbpf_pkthdr_first *hdr) { + if (ud->ud_running == 0) + return (0); - switch (ud->ud_bufmode) { - case USBPF_BUFMODE_BUFFER: - return (usbpf_buffer_free(ud)); - default: - panic("usbpf_buf_free"); - } -} + /* match bus unit */ + if (ud->ud_filter.ua_bus_unit != USBPF_IFREQ_ANY && + ud->ud_filter.ua_bus_unit != hdr->up_busunit) + return (0); -/* - * Notify the buffer model that a buffer has moved into the hold position. - */ -static void -usbpf_bufheld(struct usbpf_d *ud) -{ + /* match device unit (this is not the device address) */ + if (ud->ud_filter.ua_dev_unit != USBPF_IFREQ_ANY && + ud->ud_filter.ua_dev_unit != hdr->up_devunit) + return (0); - USBPFD_LOCK_ASSERT(ud); -} + /* match endpoint */ + if (ud->ud_filter.ua_endpoint_mask != USBPF_IFREQ_ANY) { + uint8_t shift; -/* - * Free buffers currently in use by a descriptor. - * Called on close. - */ -static void -usbpf_freed(struct usbpf_d *ud) -{ + shift = (2 * (hdr->up_endpoint & UE_ADDR)) | + ((hdr->up_endpoint & (UE_DIR_IN | UE_DIR_OUT)) ? 1 : 0); - /* - * We don't need to lock out interrupts since this descriptor has - * been detached from its interface and it yet hasn't been marked - * free. - */ - usbpf_free(ud); - if (ud->ud_rfilter != NULL) - free((caddr_t)ud->ud_rfilter, M_USBPF); - if (ud->ud_wfilter != NULL) - free((caddr_t)ud->ud_wfilter, M_USBPF); - mtx_destroy(&ud->ud_mtx); + if (!(ud->ud_filter.ua_endpoint_mask & (1U << shift))) + return (0); + } + return (1); /* accept */ } /* @@ -809,28 +481,32 @@ usbpf_dtor(void *data) { struct usbpf_d *ud = data; + struct usbpf_pkthdr *phdr; - USBPFD_LOCK(ud); - if (ud->ud_state == USBPF_WAITING) - callout_stop(&ud->ud_callout); - ud->ud_state = USBPF_IDLE; - USBPFD_UNLOCK(ud); - funsetown(&ud->ud_sigio); - mtx_lock(&usbpf_mtx); - if (ud->ud_bif) - usbpf_detachd(ud); - mtx_unlock(&usbpf_mtx); - selwakeuppri(&ud->ud_sel, PRIUSB); + USBPFD_GLOBAL_LOCK(); + + ud->ud_running = 0; + + while ((phdr = TAILQ_FIRST(&ud->ud_head)) != NULL) { + TAILQ_REMOVE(&ud->ud_head, phdr, reserved.entry); + ud->ud_queue_len--; + free(phdr, M_USBPF); + } + + TAILQ_REMOVE(&usbpf_filters, ud, ud_next); + + USBPFD_GLOBAL_UNLOCK(); + + selwakeup(&ud->ud_sel); + knlist_destroy(&ud->ud_sel.si_note); - callout_drain(&ud->ud_callout); - usbpf_freed(ud); + + if (ud->ud_filter_code) + free(ud->ud_filter_code, M_USBPF); + free(ud, M_USBPF); } -/* - * Open device. Returns ENXIO for illegal minor device number, - * EBUSY if file is open by another process. - */ /* ARGSUSED */ static int usbpf_open(struct cdev *dev, int flags, int fmt, struct thread *td) @@ -845,25 +521,15 @@ return (error); } - usbpf_buffer_init(ud); - ud->ud_bufmode = USBPF_BUFMODE_BUFFER; - ud->ud_sig = SIGIO; - ud->ud_direction = USBPF_D_INOUT; - ud->ud_pid = td->td_proc->p_pid; - mtx_init(&ud->ud_mtx, devtoname(dev), "usbpf cdev lock", MTX_DEF); - callout_init_mtx(&ud->ud_callout, &ud->ud_mtx, 0); - knlist_init_mtx(&ud->ud_sel.si_note, &ud->ud_mtx); + TAILQ_INIT(&ud->ud_head); - return (0); -} + knlist_init_mtx(&ud->ud_sel.si_note, &usbpf_global_mtx); -static int -usbpf_uiomove(struct usbpf_d *ud, caddr_t buf, u_int len, struct uio *uio) -{ + USBPFD_GLOBAL_LOCK(); + TAILQ_INSERT_TAIL(&usbpf_filters, ud, ud_next); + USBPFD_GLOBAL_UNLOCK(); - if (ud->ud_bufmode != USBPF_BUFMODE_BUFFER) - return (EOPNOTSUPP); - return (usbpf_buffer_uiomove(ud, buf, len, uio)); + return (0); } /* @@ -873,120 +539,75 @@ usbpf_read(struct cdev *dev, struct uio *uio, int ioflag) { struct usbpf_d *ud; + struct usbpf_pkthdr *phdr; int error; int non_block; - int timed_out; + int moved_data; error = devfs_get_cdevpriv((void **)&ud); if (error != 0) return (error); - /* - * Restrict application to use a buffer the same size as - * as kernel buffers. - */ - if (uio->uio_resid != ud->ud_bufsize) - return (EINVAL); - non_block = ((ioflag & O_NONBLOCK) != 0); + moved_data = 0; - USBPFD_LOCK(ud); - ud->ud_pid = curthread->td_proc->p_pid; - if (ud->ud_bufmode != USBPF_BUFMODE_BUFFER) { - USBPFD_UNLOCK(ud); - return (EOPNOTSUPP); - } - if (ud->ud_state == USBPF_WAITING) - callout_stop(&ud->ud_callout); - timed_out = (ud->ud_state == USBPF_TIMED_OUT); - ud->ud_state = USBPF_IDLE; - /* - * If the hold buffer is empty, then do a timed sleep, which - * ends when the timeout expires or when enough packets - * have arrived to fill the store buffer. - */ - while (ud->ud_hbuf == NULL) { - if (ud->ud_slen != 0) { - /* - * A packet(s) either arrived since the previous - * read or arrived while we were asleep. - */ - if (ud->ud_immediate || non_block || timed_out) { - /* - * Rotate the buffers and return what's here - * if we are in immediate mode, non-blocking - * flag is set, or this descriptor timed out. - */ - USBPF_ROTATE_BUFFERS(ud); + USBPFD_GLOBAL_LOCK(); + + while (1) { + while ((phdr = TAILQ_FIRST(&ud->ud_head)) != NULL) { + + int totlen; + + totlen = le32toh(phdr->hdr.up_totlen); + + if (uio->uio_resid >= totlen) { + + TAILQ_REMOVE(&ud->ud_head, phdr, reserved.entry); + ud->ud_queue_len--; + + memset(&phdr->reserved.entry, 0, sizeof(phdr->reserved.entry)); + + USBPFD_GLOBAL_UNLOCK(); + + error = uiomove(phdr, totlen, uio); + + USBPFD_GLOBAL_LOCK(); + + free(phdr, M_USBPF); + + moved_data = 1; + + if (error) + break; + + } else if (moved_data == 0) { + + /* size too big */ + + ud->ud_dcount++; + + TAILQ_REMOVE(&ud->ud_head, phdr, reserved.entry); + ud->ud_queue_len--; + + free(phdr, M_USBPF); + } else { break; } } - /* - * No data is available, check to see if the usbpf device - * is still pointed at a real interface. If not, return - * ENXIO so that the userland process knows to rebind - * it before using it again. - */ - if (ud->ud_bif == NULL) { - USBPFD_UNLOCK(ud); - return (ENXIO); - } + if (moved_data || non_block || ud->ud_running == 0) + break; - if (non_block) { - USBPFD_UNLOCK(ud); - return (EWOULDBLOCK); - } - error = msleep(ud, &ud->ud_mtx, PRIUSB|PCATCH, - "uff", ud->ud_rtout); - if (error == EINTR || error == ERESTART) { - USBPFD_UNLOCK(ud); - return (error); - } - if (error == EWOULDBLOCK) { - /* - * On a timeout, return what's in the buffer, - * which may be nothing. If there is something - * in the store buffer, we can rotate the buffers. - */ - if (ud->ud_hbuf) - /* - * We filled up the buffer in between - * getting the timeout and arriving - * here, so we don't need to rotate. - */ - break; + error = msleep(ud, &usbpf_global_mtx, PCATCH, "upf", ud->ud_rtout); - if (ud->ud_slen == 0) { - USBPFD_UNLOCK(ud); - return (0); - } - USBPF_ROTATE_BUFFERS(ud); + if (error || ud->ud_running == 0) break; - } } - /* - * At this point, we know we have something in the hold slot. - */ - USBPFD_UNLOCK(ud); - /* - * Move data from hold buffer into user space. - * We know the entire buffer is transferred since - * we checked above that the read buffer is usbpf_bufsize bytes. - * - * XXXRW: More synchronization needed here: what if a second thread - * issues a read on the same fd at the same time? Don't want this - * getting invalidated. - */ - error = usbpf_uiomove(ud, ud->ud_hbuf, ud->ud_hlen, uio); + if (ud->ud_running == 0) + error = EINVAL; - USBPFD_LOCK(ud); - ud->ud_fbuf = ud->ud_hbuf; - ud->ud_hbuf = NULL; - ud->ud_hlen = 0; - usbpf_buf_reclaimed(ud); - USBPFD_UNLOCK(ud); + USBPFD_GLOBAL_UNLOCK(); return (error); } @@ -999,141 +620,58 @@ return (ENOSYS); } -static int -usbpf_ioctl_sblen(struct usbpf_d *ud, u_int *i) -{ - - if (ud->ud_bufmode != USBPF_BUFMODE_BUFFER) - return (EOPNOTSUPP); - return (usbpf_buffer_ioctl_sblen(ud, i)); -} - -/* - * Reset a descriptor by flushing its packet buffer and clearing the receive - * and drop counts. This is doable for kernel-only buffers, but with - * zero-copy buffers, we can't write to (or rotate) buffers that are - * currently owned by userspace. It would be nice if we could encapsulate - * this logic in the buffer code rather than here. - */ static void usbpf_reset_d(struct usbpf_d *ud) { + USBPFD_GLOBAL_ASSERT_LOCKED(); - USBPFD_LOCK_ASSERT(ud); - - if ((ud->ud_hbuf != NULL) && - (ud->ud_bufmode != USBPF_BUFMODE_ZBUF || usbpf_canfreebuf(ud))) { - /* Free the hold buffer. */ - ud->ud_fbuf = ud->ud_hbuf; - ud->ud_hbuf = NULL; - ud->ud_hlen = 0; - usbpf_buf_reclaimed(ud); - } - if (usbpf_canwritebuf(ud)) - ud->ud_slen = 0; ud->ud_rcount = 0; ud->ud_dcount = 0; - ud->ud_fcount = 0; - ud->ud_wcount = 0; - ud->ud_wfcount = 0; - ud->ud_wdcount = 0; - ud->ud_zcopy = 0; } static int usbpf_setif(struct usbpf_d *ud, struct usbpf_ifreq *ufr) { - struct usbpf_if *uif; - struct usb_bus *theywant; + struct usbpf_insn *pfilt; + struct usbpf_insn *ofilt; + uint32_t lfilt; + uint32_t size; - theywant = usb_bus_find(ufr->ufr_name); - if (theywant == NULL || theywant->uif == NULL) - return (ENXIO); + if (ufr->ua_filter_len != 0) { + lfilt = ufr->ua_filter_len; + if (lfilt > USBPF_MAX_FILTER) + return (E2BIG); + size = lfilt * sizeof(struct usbpf_insn); + pfilt = malloc(size, M_USBPF, M_WAITOK); + if (pfilt == NULL) + return (ENOMEM); + if (copyin(ufr->ua_filter_ptr, pfilt, size) != 0) { + free(pfilt, M_USBPF); + return (EFAULT); + } + if (usbpf_validate(pfilt, lfilt) != 0) { + free(pfilt, M_USBPF); + return (EINVAL); + } + } else { + pfilt = NULL; + } - uif = theywant->uif; + USBPFD_GLOBAL_LOCK(); - switch (ud->ud_bufmode) { - case USBPF_BUFMODE_BUFFER: - if (ud->ud_sbuf == NULL) - usbpf_buffer_alloc(ud); - KASSERT(ud->ud_sbuf != NULL, ("%s: ud_sbuf == NULL", __func__)); - break; + ofilt = ud->ud_filter_code; + ud->ud_filter_code = pfilt; - default: - panic("usbpf_setif: bufmode %d", ud->ud_bufmode); - } - if (uif != ud->ud_bif) { - if (ud->ud_bif) - /* - * Detach if attached to something else. - */ - usbpf_detachd(ud); + ud->ud_filter = *ufr; + ud->ud_running = 1; - usbpf_attachd(ud, uif); - } - USBPFD_LOCK(ud); usbpf_reset_d(ud); - USBPFD_UNLOCK(ud); - return (0); -} -/* - * Set d's packet filter program to fp. If this file already has a filter, - * free it and replace it. Returns EINVAL for bogus requests. - */ -static int -usbpf_setf(struct usbpf_d *ud, struct usbpf_program *fp, u_long cmd) -{ - struct usbpf_insn *fcode, *old; - u_int wfilter, flen, size; + USBPFD_GLOBAL_UNLOCK(); - if (cmd == UIOCSETWF) { - old = ud->ud_wfilter; - wfilter = 1; - } else { - wfilter = 0; - old = ud->ud_rfilter; - } - if (fp->uf_insns == NULL) { - if (fp->uf_len != 0) - return (EINVAL); - USBPFD_LOCK(ud); - if (wfilter) - ud->ud_wfilter = NULL; - else { - ud->ud_rfilter = NULL; - if (cmd == UIOCSETF) - usbpf_reset_d(ud); - } - USBPFD_UNLOCK(ud); - if (old != NULL) - free((caddr_t)old, M_USBPF); - return (0); - } - flen = fp->uf_len; - if (flen > usbpf_maxinsns) - return (EINVAL); + free(ofilt, M_USBPF); - size = flen * sizeof(*fp->uf_insns); - fcode = (struct usbpf_insn *)malloc(size, M_USBPF, M_WAITOK); - if (copyin((caddr_t)fp->uf_insns, (caddr_t)fcode, size) == 0 && - usbpf_validate(fcode, (int)flen)) { - USBPFD_LOCK(ud); - if (wfilter) - ud->ud_wfilter = fcode; - else { - ud->ud_rfilter = fcode; - if (cmd == UIOCSETF) - usbpf_reset_d(ud); - } - USBPFD_UNLOCK(ud); - if (old != NULL) - free((caddr_t)old, M_USBPF); - - return (0); - } - free((caddr_t)fcode, M_USBPF); - return (EINVAL); + return (0); } static int @@ -1147,55 +685,15 @@ if (error != 0) return (error); - /* - * Refresh PID associated with this descriptor. - */ - USBPFD_LOCK(ud); - ud->ud_pid = td->td_proc->p_pid; - if (ud->ud_state == USBPF_WAITING) - callout_stop(&ud->ud_callout); - ud->ud_state = USBPF_IDLE; - USBPFD_UNLOCK(ud); - - if (ud->ud_locked == 1) { - switch (cmd) { - case UIOCGBLEN: - case UIOCSBLEN: - case UIOCVERSION: - break; - default: - return (EPERM); - } - } - switch (cmd) { - - default: - error = EINVAL; - break; - /* - * Get buffer len [for read()]. + * Get maximum data length including packet header. */ case UIOCGBLEN: - *(u_int *)addr = ud->ud_bufsize; + *(long *)addr = USBPF_MAX_BUFFER_LEN; break; /* - * Set buffer length. - */ - case UIOCSBLEN: - error = usbpf_ioctl_sblen(ud, (u_int *)addr); - break; - - /* - * Set read filter. - */ - case UIOCSETF: - error = usbpf_setf(ud, (struct usbpf_program *)addr, cmd); - break; - - /* * Set read timeout. */ case UIOCSRTIMEOUT: @@ -1230,7 +728,6 @@ { struct usbpf_stat *us = (struct usbpf_stat *)addr; - /* XXXCSJP overflow */ us->us_recv = ud->ud_rcount; us->us_drop = ud->ud_dcount; break; @@ -1252,6 +749,9 @@ error = usbpf_setif(ud, (struct usbpf_ifreq *)addr); break; + default: + error = ENOTTY; + break; } return (error); } @@ -1265,9 +765,9 @@ static int usbpf_poll(struct cdev *dev, int events, struct thread *td) { - /* NOT IMPLEMENTED */ - return (ENOSYS); + /* NOTE: This function does not return an error code! */ + return (events & (POLLHUP | POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM)); } /* @@ -1283,594 +783,319 @@ } /* - * Attach file to the usbpf interface, i.e. make d listen on bp. + * If there are processes sleeping on this descriptor, wake them up. */ static void -usbpf_attachd(struct usbpf_d *ud, struct usbpf_if *uif) +usbpf_wakeup(struct usbpf_d *ud) { + USBPFD_GLOBAL_ASSERT_LOCKED(); - USBPFIF_LOCK(uif); - ud->ud_bif = uif; - LIST_INSERT_HEAD(&uif->uif_dlist, ud, ud_next); + wakeup(ud); - usbpf_uifd_cnt++; - USBPFIF_UNLOCK(uif); -} + selwakeup(&ud->ud_sel); -/* - * Detach a file from its interface. - */ -static void -usbpf_detachd(struct usbpf_d *ud) -{ - struct usbpf_if *uif; - struct usb_bus *ubus; - - uif = ud->ud_bif; - USBPFIF_LOCK(uif); - USBPFD_LOCK(ud); - ubus = ud->ud_bif->uif_ubus; - - /* - * Remove d from the interface's descriptor list. - */ - LIST_REMOVE(ud, ud_next); - - usbpf_uifd_cnt--; - ud->ud_bif = NULL; - USBPFD_UNLOCK(ud); - USBPFIF_UNLOCK(uif); + KNOTE_LOCKED(&ud->ud_sel.si_note, 0); } -void -usbpf_attach(struct usb_bus *ubus, struct usbpf_if **driverp) +static uint32_t +usbpf_get_xfer_flags(struct usb_xfer *xfer, uint32_t frame) { - struct usbpf_if *uif; + uint32_t temp = 0; + uint8_t isread; - uif = malloc(sizeof(*uif), M_USBPF, M_WAITOK | M_ZERO); - LIST_INIT(&uif->uif_dlist); - uif->uif_ubus = ubus; - mtx_init(&uif->uif_mtx, "usbpf interface lock", NULL, MTX_DEF); - KASSERT(*driverp == NULL, - ("usbpf_attach: driverp already initialized")); - *driverp = uif; + if ((frame == 0) && xfer->flags_int.control_xfr && + xfer->flags_int.control_hdr) { + /* special case */ + if (xfer->flags_int.usb_mode == USB_MODE_DEVICE) { + /* The device controller writes to memory */ + isread = 1; + } else { + /* The host controller reads from memory */ + isread = 0; + } + } else { + isread = USB_GET_DATA_ISREAD(xfer); + } - mtx_lock(&usbpf_mtx); - LIST_INSERT_HEAD(&usbpf_iflist, uif, uif_next); - mtx_unlock(&usbpf_mtx); + if (isread) + temp |= USBPF_XFERFLAG_READ; + if (xfer->flags.short_xfer_ok) + temp |= USBPF_XFERFLAG_SHORT_OK; + if (xfer->flags.short_frames_ok) + temp |= USBPF_XFERFLAG_MULTI_SHORT_OK; + if (xfer->flags.force_short_xfer) + temp |= USBPF_XFERFLAG_FORCE_SHORT; + if (xfer->flags.stall_pipe) + temp |= USBPF_XFERFLAG_STALL_PIPE; + if (xfer->flags_int.control_act == 1) + temp |= USBPF_XFERFLAG_CONTROL_ACT; - if (bootverbose) - device_printf(ubus->parent, "usbpf attached\n"); + return (temp); } -/* - * If there are processes sleeping on this descriptor, wake them up. - */ -static __inline void -usbpf_wakeup(struct usbpf_d *ud) +static void +usbpf_xfertap_sub(struct usb_xfer *xfer, struct usbpf_d *ud, + struct usbpf_pkthdr_first *fhdr, int type) { + struct usbpf_pkthdr *hdr; + uint32_t *ptr; + uint32_t x; + uint32_t offset; + uint32_t frame; + uint32_t filter_length; - USBPFD_LOCK_ASSERT(ud); - if (ud->ud_state == USBPF_WAITING) { - callout_stop(&ud->ud_callout); - ud->ud_state = USBPF_IDLE; + if (ud->ud_queue_len >= USBPF_MAX_QUEUE_LEN) { + ud->ud_dcount++; + return; } - wakeup(ud); - if (ud->ud_async && ud->ud_sig && ud->ud_sigio) - pgsigio(&ud->ud_sigio, ud->ud_sig, 0); - selwakeuppri(&ud->ud_sel, PRIUSB); - KNOTE_LOCKED(&ud->ud_sel.si_note, 0); -} - -void -usbpf_detach(struct usb_bus *ubus) -{ - struct usbpf_if *uif; - struct usbpf_d *ud; - - /* Locate USBPF interface information */ - mtx_lock(&usbpf_mtx); - LIST_FOREACH(uif, &usbpf_iflist, uif_next) { - if (ubus == uif->uif_ubus) - break; - } - - /* Interface wasn't attached */ - if ((uif == NULL) || (uif->uif_ubus == NULL)) { - mtx_unlock(&usbpf_mtx); - printf("usbpf_detach: not attached\n"); /* XXX */ + ptr = malloc(fhdr->up_totlen, M_USBPF, M_NOWAIT); + if (ptr == NULL) { + ud->ud_dcount++; return; } - LIST_REMOVE(uif, uif_next); - mtx_unlock(&usbpf_mtx); + hdr = (struct usbpf_pkthdr *)ptr; - while ((ud = LIST_FIRST(&uif->uif_dlist)) != NULL) { - usbpf_detachd(ud); - USBPFD_LOCK(ud); - usbpf_wakeup(ud); - USBPFD_UNLOCK(ud); - } + /* do endian conversion of header */ - mtx_destroy(&uif->uif_mtx); - free(uif, M_USBPF); -} + hdr->hdr.up_sec = htole64(fhdr->up_sec); + hdr->hdr.up_frac = htole64(fhdr->up_frac); + hdr->hdr.up_busunit = htole32(fhdr->up_busunit); + hdr->hdr.up_frames = htole32(fhdr->up_frames); + hdr->hdr.up_hdrlen = htole32(sizeof(hdr->hdr)); + hdr->hdr.up_interval = htole32(fhdr->up_interval); + hdr->hdr.up_status = htole32(fhdr->up_status); + hdr->hdr.up_totlen = htole32(fhdr->up_totlen); + hdr->hdr.up_error = htole32(fhdr->up_error); + hdr->hdr.up_packet_size = htole32(fhdr->up_packet_size); + hdr->hdr.up_packet_count = htole32(fhdr->up_packet_count); + hdr->hdr.up_devunit = fhdr->up_devunit; + hdr->hdr.up_dmode = fhdr->up_dmode; + hdr->hdr.up_endpoint = fhdr->up_endpoint; + hdr->hdr.up_type = fhdr->up_type; + hdr->hdr.up_xfertype = fhdr->up_xfertype; -/* Time stamping functions */ -#define USBPF_T_MICROTIME 0x0000 -#define USBPF_T_NANOTIME 0x0001 -#define USBPF_T_BINTIME 0x0002 -#define USBPF_T_NONE 0x0003 -#define USBPF_T_FORMAT_MASK 0x0003 -#define USBPF_T_NORMAL 0x0000 -#define USBPF_T_FAST 0x0100 -#define USBPF_T_MONOTONIC 0x0200 -#define USBPF_T_FORMAT(t) ((t) & USBPF_T_FORMAT_MASK) + ptr = (uint32_t *)(hdr + 1); -#define USBPF_TSTAMP_NONE 0 -#define USBPF_TSTAMP_FAST 1 -#define USBPF_TSTAMP_NORMAL 2 + /* copy all data last */ -static int -usbpf_ts_quality(int tstype) -{ + offset = 0; + frame = 0; - if (tstype == USBPF_T_NONE) - return (USBPF_TSTAMP_NONE); - if ((tstype & USBPF_T_FAST) != 0) - return (USBPF_TSTAMP_FAST); + for (x = 0; x != xfer->nframes; x++) { + uint32_t length; + uint32_t temp; - return (USBPF_TSTAMP_NORMAL); -} + /* get length and flags */ + length = xfer->frlengths[x]; + temp = usbpf_get_xfer_flags(xfer, x); -static int -usbpf_gettime(struct bintime *bt, int tstype) -{ - int quality; + /* check if we need to copy any data */ + if (temp & USBPF_XFERFLAG_READ) { + if (type == USBPF_XFERTAP_SUBMIT) + length = 0; + } else { + if (type != USBPF_XFERTAP_SUBMIT) + length = 0; + } - quality = usbpf_ts_quality(tstype); - if (quality == USBPF_TSTAMP_NONE) - return (quality); - if (quality == USBPF_TSTAMP_NORMAL) - binuptime(bt); - else - getbinuptime(bt); + /* fill out packet header */ + ptr[0] = htole32(length); + ptr[1] = htole32(temp); - return (quality); -} + /* copy USB data, if any */ + if (length != 0) { + /* there is a data buffer after the length and flags */ + ptr[1] |= htole32(USBPF_XFERFLAG_DATA_FOLLOWS); -/* - * If the buffer mechanism has a way to decide that a held buffer can be made - * free, then it is exposed via the usbpf_canfreebuf() interface. (1) is - * returned if the buffer can be discarded, (0) is returned if it cannot. - */ -static int -usbpf_canfreebuf(struct usbpf_d *ud) -{ + /* run filter */ + filter_length = usbpf_filter_sub(ud->ud_filter_code, + &xfer->frbuffers[frame], offset, length); - USBPFD_LOCK_ASSERT(ud); + /* get actual amount of data to copy */ + if (filter_length >= length) + filter_length = length; + else { + uint32_t totlen; + /* update total length */ + totlen = le32toh(hdr->hdr.up_totlen); + totlen -= USBPF_LENGTH_ALIGN(length); + totlen += USBPF_LENGTH_ALIGN(filter_length); + hdr->hdr.up_totlen = htole32(totlen); + } - return (0); -} + ptr[2] = htole32(filter_length); + ptr += USBPF_FRAMEHDR_SIZE; -/* - * Allow the buffer model to indicate that the current store buffer is - * immutable, regardless of the appearance of space. Return (1) if the - * buffer is writable, and (0) if not. - */ -static int -usbpf_canwritebuf(struct usbpf_d *ud) -{ + /* zero-pad the last 32-bits in case of aligment */ + ptr[(filter_length - 1) / 4] = 0; - USBPFD_LOCK_ASSERT(ud); - return (1); -} + /* copy data */ + usbd_copy_out(&xfer->frbuffers[frame], offset, ptr, filter_length); -/* - * Notify buffer model that an attempt to write to the store buffer has - * resulted in a dropped packet, in which case the buffer may be considered - * full. - */ -static void -usbpf_buffull(struct usbpf_d *ud) -{ + /* align length */ + length = USBPF_LENGTH_ALIGN(filter_length); - USBPFD_LOCK_ASSERT(ud); -} + /* advance data pointer */ + ptr += length / 4; + } else { + ptr[2] = 0; + ptr += USBPF_FRAMEHDR_SIZE; + } -/* - * This function gets called when the free buffer is re-assigned. - */ -static void -usbpf_buf_reclaimed(struct usbpf_d *ud) -{ - - USBPFD_LOCK_ASSERT(ud); - - switch (ud->ud_bufmode) { - case USBPF_BUFMODE_BUFFER: - return; - - default: - panic("usbpf_buf_reclaimed"); + if (xfer->flags_int.isochronous_xfr) { +#if USB_HAVE_PF + offset += xfer->frlengths[x + xfer->max_frame_count]; +#endif + } else { + frame ++; + } } -} -#define SIZEOF_USBPF_HDR(type) \ - (offsetof(type, uh_hdrlen) + sizeof(((type *)0)->uh_hdrlen)) + /* clear reserved area */ + memset(&hdr->reserved, 0, sizeof(hdr->reserved)); -static int -usbpf_hdrlen(struct usbpf_d *ud) -{ - int hdrlen; + /* enqueue header */ + TAILQ_INSERT_TAIL(&ud->ud_head, hdr, reserved.entry); + ud->ud_queue_len++; - hdrlen = ud->ud_bif->uif_hdrlen; - hdrlen += SIZEOF_USBPF_HDR(struct usbpf_xhdr); - hdrlen = USBPF_WORDALIGN(hdrlen); - - return (hdrlen - ud->ud_bif->uif_hdrlen); + /* wakeup any sleeping receiver */ + usbpf_wakeup(ud); } static void -usbpf_bintime2ts(struct bintime *bt, struct usbpf_ts *ts, int tstype) +usbpf_xfertap(struct usb_xfer *xfer, int type) { - struct bintime bt2; + struct usbpf_pkthdr_first fhdr; + struct usb_xfer_root *info; + struct usb_bus *bus; + struct usbpf_d *ud; struct timeval tsm; - struct timespec tsn; + struct bintime bt; + uint32_t totlen; + uint32_t x; - if ((tstype & USBPF_T_MONOTONIC) == 0) { - bt2 = *bt; - bintime_add(&bt2, &boottimebin); - bt = &bt2; + USBPFD_GLOBAL_LOCK(); + if (TAILQ_FIRST(&usbpf_filters) == NULL) { + USBPFD_GLOBAL_UNLOCK(); + /* no filters no work */ + return; } - switch (USBPF_T_FORMAT(tstype)) { - case USBPF_T_MICROTIME: - bintime2timeval(bt, &tsm); - ts->ut_sec = tsm.tv_sec; - ts->ut_frac = tsm.tv_usec; - break; - case USBPF_T_NANOTIME: - bintime2timespec(bt, &tsn); - ts->ut_sec = tsn.tv_sec; - ts->ut_frac = tsn.tv_nsec; - break; - case USBPF_T_BINTIME: - ts->ut_sec = bt->sec; - ts->ut_frac = bt->frac; - break; - } -} -/* - * Move the packet data from interface memory (pkt) into the - * store buffer. "cpfn" is the routine called to do the actual data - * transfer. bcopy is passed in to copy contiguous chunks, while - * usbpf_append_mbuf is passed in to copy mbuf chains. In the latter case, - * pkt is really an mbuf. - */ -static void -catchpacket(struct usbpf_d *ud, u_char *pkt, u_int pktlen, u_int snaplen, - void (*cpfn)(struct usbpf_d *, caddr_t, u_int, void *, u_int), - struct bintime *bt) -{ - struct usbpf_xhdr hdr; - int caplen, curlen, hdrlen, totlen; - int do_wakeup = 0; - int do_timestamp; - int tstype; + info = xfer->xroot; + bus = info->bus; - USBPFD_LOCK_ASSERT(ud); - - /* - * Detect whether user space has released a buffer back to us, and if - * so, move it from being a hold buffer to a free buffer. This may - * not be the best place to do it (for example, we might only want to - * run this check if we need the space), but for now it's a reliable - * spot to do it. + /* + * It would be better to get the 125us-frame + * count from the USB hardware. */ - if (ud->ud_fbuf == NULL && usbpf_canfreebuf(ud)) { - ud->ud_fbuf = ud->ud_hbuf; - ud->ud_hbuf = NULL; - ud->ud_hlen = 0; - usbpf_buf_reclaimed(ud); - } + getbinuptime(&bt); + bintime2timeval(&bt, &tsm); - /* - * Figure out how many bytes to move. If the packet is - * greater or equal to the snapshot length, transfer that - * much. Otherwise, transfer the whole packet (unless - * we hit the buffer size limit). - */ - hdrlen = usbpf_hdrlen(ud); - totlen = hdrlen + min(snaplen, pktlen); - if (totlen > ud->ud_bufsize) - totlen = ud->ud_bufsize; + /* timestamp */ + fhdr.up_sec = tsm.tv_sec; + fhdr.up_frac = tsm.tv_usec; - /* - * Round up the end of the previous packet to the next longword. - * - * Drop the packet if there's no room and no hope of room - * If the packet would overflow the storage buffer or the storage - * buffer is considered immutable by the buffer model, try to rotate - * the buffer and wakeup pending processes. - */ - curlen = USBPF_WORDALIGN(ud->ud_slen); - if (curlen + totlen > ud->ud_bufsize || !usbpf_canwritebuf(ud)) { - if (ud->ud_fbuf == NULL) { - /* - * There's no room in the store buffer, and no - * prospect of room, so drop the packet. Notify the - * buffer model. - */ - usbpf_buffull(ud); - ++ud->ud_dcount; - return; - } - USBPF_ROTATE_BUFFERS(ud); - do_wakeup = 1; - curlen = 0; - } else if (ud->ud_immediate || ud->ud_state == USBPF_TIMED_OUT) - /* - * Immediate mode is set, or the read timeout has already - * expired during a select call. A packet arrived, so the - * reader should be woken up. - */ - do_wakeup = 1; - caplen = totlen - hdrlen; - tstype = ud->ud_tstamp; - do_timestamp = tstype != USBPF_T_NONE; + /* transfer information */ + fhdr.up_busunit = device_get_unit(bus->bdev); + fhdr.up_interval = xfer->interval; + fhdr.up_status = xfer->usb_state; + fhdr.up_packet_size = xfer->max_packet_size; + fhdr.up_packet_count = xfer->max_packet_count; + fhdr.up_frames = xfer->nframes; - /* - * Append the usbpf header. Note we append the actual header size, but - * move forward the length of the header plus padding. - */ - bzero(&hdr, sizeof(hdr)); - if (do_timestamp) - usbpf_bintime2ts(bt, &hdr.uh_tstamp, tstype); - hdr.uh_datalen = pktlen; - hdr.uh_hdrlen = hdrlen; - hdr.uh_caplen = caplen; - usbpf_append_bytes(ud, ud->ud_sbuf, curlen, &hdr, sizeof(hdr)); + /* compute total header overhead length */ + totlen = USBPF_PKTHDR_SIZE + ((USBPF_FRAMEHDR_SIZE * 4) * xfer->nframes); - /* - * Copy the packet data into the store buffer and update its length. - */ - (*cpfn)(ud, ud->ud_sbuf, curlen + hdrlen, pkt, caplen); - ud->ud_slen = curlen + totlen; + /* precompute all trace lengths */ + for (x = 0; x != xfer->nframes; x++) { + uint32_t temp; + temp = usbpf_get_xfer_flags(xfer, x); - if (do_wakeup) - usbpf_wakeup(ud); -} - -/* - * Incoming linkage from device drivers. Process the packet pkt, of length - * pktlen, which is stored in a contiguous buffer. The packet is parsed - * by each process' filter, and if accepted, stashed into the corresponding - * buffer. - */ -static void -usbpf_tap(struct usbpf_if *uif, u_char *pkt, u_int pktlen) -{ - struct bintime bt; - struct usbpf_d *ud; - u_int slen; - int gottime; - - gottime = USBPF_TSTAMP_NONE; - USBPFIF_LOCK(uif); - LIST_FOREACH(ud, &uif->uif_dlist, ud_next) { - USBPFD_LOCK(ud); - ++ud->ud_rcount; - slen = usbpf_filter(ud->ud_rfilter, pkt, pktlen, pktlen); - if (slen != 0) { - ud->ud_fcount++; - if (gottime < usbpf_ts_quality(ud->ud_tstamp)) - gottime = usbpf_gettime(&bt, ud->ud_tstamp); - catchpacket(ud, pkt, pktlen, slen, - usbpf_append_bytes, &bt); + if (temp & USBPF_XFERFLAG_READ) { + if (type != USBPF_XFERTAP_SUBMIT) + totlen += USBPF_LENGTH_ALIGN(xfer->frlengths[x]); + } else { + if (type == USBPF_XFERTAP_SUBMIT) + totlen += USBPF_LENGTH_ALIGN(xfer->frlengths[x]); } - USBPFD_UNLOCK(ud); } - USBPFIF_UNLOCK(uif); -} -static uint32_t -usbpf_aggregate_xferflags(struct usb_xfer_flags *flags) -{ - uint32_t val = 0; + /* sanity check */ + if (totlen >= USBPF_MAX_BUFFER_LEN) { + static int once; + USBPFD_GLOBAL_UNLOCK(); - if (flags->force_short_xfer == 1) - val |= USBPF_FLAG_FORCE_SHORT_XFER; - if (flags->short_xfer_ok == 1) - val |= USBPF_FLAG_SHORT_XFER_OK; - if (flags->short_frames_ok == 1) - val |= USBPF_FLAG_SHORT_FRAMES_OK; - if (flags->pipe_bof == 1) - val |= USBPF_FLAG_PIPE_BOF; - if (flags->proxy_buffer == 1) - val |= USBPF_FLAG_PROXY_BUFFER; - if (flags->ext_buffer == 1) - val |= USBPF_FLAG_EXT_BUFFER; - if (flags->manual_status == 1) - val |= USBPF_FLAG_MANUAL_STATUS; - if (flags->no_pipe_ok == 1) - val |= USBPF_FLAG_NO_PIPE_OK; - if (flags->stall_pipe == 1) - val |= USBPF_FLAG_STALL_PIPE; - return (val); -} + if (once == 0) { + printf("usb_pf: Total trace length(%u) " + "exceeds maximum(%u).\n", + totlen, USBPF_MAX_BUFFER_LEN); + once = 1; + } -static uint32_t -usbpf_aggregate_status(struct usb_xfer_flags_int *flags) -{ - uint32_t val = 0; + /* too much data */ + return; + } - if (flags->open == 1) - val |= USBPF_STATUS_OPEN; - if (flags->transferring == 1) - val |= USBPF_STATUS_TRANSFERRING; - if (flags->did_dma_delay == 1) - val |= USBPF_STATUS_DID_DMA_DELAY; - if (flags->did_close == 1) - val |= USBPF_STATUS_DID_CLOSE; - if (flags->draining == 1) - val |= USBPF_STATUS_DRAINING; - if (flags->started == 1) - val |= USBPF_STATUS_STARTED; - if (flags->bandwidth_reclaimed == 1) - val |= USBPF_STATUS_BW_RECLAIMED; - if (flags->control_xfr == 1) - val |= USBPF_STATUS_CONTROL_XFR; - if (flags->control_hdr == 1) - val |= USBPF_STATUS_CONTROL_HDR; - if (flags->control_act == 1) - val |= USBPF_STATUS_CONTROL_ACT; - if (flags->control_stall == 1) - val |= USBPF_STATUS_CONTROL_STALL; - if (flags->short_frames_ok == 1) - val |= USBPF_STATUS_SHORT_FRAMES_OK; - if (flags->short_xfer_ok == 1) - val |= USBPF_STATUS_SHORT_XFER_OK; -#if USB_HAVE_BUSDMA - if (flags->bdma_enable == 1) - val |= USBPF_STATUS_BDMA_ENABLE; - if (flags->bdma_no_post_sync == 1) - val |= USBPF_STATUS_BDMA_NO_POST_SYNC; - if (flags->bdma_setup == 1) - val |= USBPF_STATUS_BDMA_SETUP; -#endif - if (flags->isochronous_xfr == 1) - val |= USBPF_STATUS_ISOCHRONOUS_XFR; - if (flags->curr_dma_set == 1) - val |= USBPF_STATUS_CURR_DMA_SET; - if (flags->can_cancel_immed == 1) - val |= USBPF_STATUS_CAN_CANCEL_IMMED; - if (flags->doing_callback == 1) - val |= USBPF_STATUS_DOING_CALLBACK; + fhdr.up_totlen = totlen; + fhdr.up_error = xfer->error; + fhdr.up_xfertype = xfer->endpoint->edesc->bmAttributes & UE_XFERTYPE; + fhdr.up_devunit = info->udev->device_index; + fhdr.up_endpoint = xfer->endpointno; + fhdr.up_dmode = (xfer->flags_int.usb_mode == USB_MODE_DEVICE); + fhdr.up_type = type; - return (val); + TAILQ_FOREACH(ud, &usbpf_filters, ud_next) { + if (usbpf_filter(ud, &fhdr)) + usbpf_xfertap_sub(xfer, ud, &fhdr, type); + } + + USBPFD_GLOBAL_UNLOCK(); } -void -usbpf_xfertap(struct usb_xfer *xfer, int type) +static void +usbpf_drvinit(void *unused) { - struct usb_endpoint *ep = xfer->endpoint; - struct usb_page_search res; - struct usb_xfer_root *info = xfer->xroot; - struct usb_bus *bus = info->bus; - struct usbpf_pkthdr *up; - usb_frlength_t isoc_offset = 0; - int i; - char *buf, *ptr, *end; + mtx_init(&usbpf_global_mtx, "USB packet filter global lock", + NULL, MTX_DEF); - /* - * NB: usbpf_uifd_cnt isn't protected by USBPFIF_LOCK() because it's - * not harmful. - */ - if (usbpf_uifd_cnt == 0) - return; + TAILQ_INIT(&usbpf_filters); - /* - * XXX TODO - * Allocating the buffer here causes copy operations twice what's - * really inefficient. Copying usbpf_pkthdr and data is for USB packet - * read filter to pass a virtually linear buffer. - */ - buf = ptr = malloc(sizeof(struct usbpf_pkthdr) + (USB_PAGE_SIZE * 5), - M_USBPF, M_NOWAIT); - if (buf == NULL) { - printf("usbpf_xfertap: out of memory\n"); /* XXX */ - return; - } - end = buf + sizeof(struct usbpf_pkthdr) + (USB_PAGE_SIZE * 5); + usbpf_dev = make_dev(&usbpf_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "usbpf"); - bzero(ptr, sizeof(struct usbpf_pkthdr)); - up = (struct usbpf_pkthdr *)ptr; - up->up_busunit = htole32(device_get_unit(bus->bdev)); - up->up_type = type; - up->up_xfertype = ep->edesc->bmAttributes & UE_XFERTYPE; - up->up_address = xfer->address; - up->up_endpoint = xfer->endpointno; - up->up_flags = htole32(usbpf_aggregate_xferflags(&xfer->flags)); - up->up_status = htole32(usbpf_aggregate_status(&xfer->flags_int)); - switch (type) { - case USBPF_XFERTAP_SUBMIT: - up->up_length = htole32(xfer->sumlen); - up->up_frames = htole32(xfer->nframes); - break; - case USBPF_XFERTAP_DONE: - up->up_length = htole32(xfer->actlen); - up->up_frames = htole32(xfer->aframes); - break; - default: - panic("wrong usbpf type (%d)", type); - } + /* Set our function pointer callback */ - up->up_error = htole32(xfer->error); - up->up_interval = htole32(xfer->interval); - ptr += sizeof(struct usbpf_pkthdr); + usb_pf_xfertap_p = &usbpf_xfertap; - for (i = 0; i < up->up_frames; i++) { - if (ptr + sizeof(u_int32_t) >= end) - goto done; - *((u_int32_t *)ptr) = htole32(xfer->frlengths[i]); - ptr += sizeof(u_int32_t); - - if (ptr + xfer->frlengths[i] >= end) - goto done; - if (xfer->flags_int.isochronous_xfr == 1) { - usbd_get_page(&xfer->frbuffers[0], isoc_offset, &res); - isoc_offset += xfer->frlengths[i]; - } else - usbd_get_page(&xfer->frbuffers[i], 0, &res); - bcopy(res.buffer, ptr, xfer->frlengths[i]); - ptr += xfer->frlengths[i]; - } - - usbpf_tap(bus->uif, buf, ptr - buf); -done: - free(buf, M_USBPF); + printf("usb_pf: USB packet filter v%u.%u.\n", + USBPF_MAJOR_VERSION, USBPF_MINOR_VERSION); } +SYSINIT(usbpf_dev, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, usbpf_drvinit, NULL); static void -usbpf_append_bytes(struct usbpf_d *ud, caddr_t buf, u_int offset, void *src, - u_int len) +usbpf_drvuninit(void *arg) { + usb_pf_unload(arg); - USBPFD_LOCK_ASSERT(ud); + if (usbpf_dev != NULL) + destroy_dev(usbpf_dev); - switch (ud->ud_bufmode) { - case USBPF_BUFMODE_BUFFER: - return (usbpf_buffer_append_bytes(ud, buf, offset, src, len)); - default: - panic("usbpf_buf_append_bytes"); - } -} + USBPFD_GLOBAL_LOCK(); -static void -usbpf_drvinit(void *unused) -{ + while (TAILQ_FIRST(&usbpf_filters) != NULL) { - mtx_init(&usbpf_mtx, "USB packet filter global lock", NULL, - MTX_DEF); - LIST_INIT(&usbpf_iflist); + USBPFD_GLOBAL_UNLOCK(); - usbpf_cdev = make_dev(&usbpf_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, - "usbpf"); -} + printf("usb_pf: Please close all device instances\n"); -static void -usbpf_drvuninit(void) -{ + pause("WAIT", 2 * hz); - if (usbpf_cdev != NULL) { - destroy_dev(usbpf_cdev); - usbpf_cdev = NULL; + USBPFD_GLOBAL_LOCK(); } - mtx_destroy(&usbpf_mtx); -} -SYSINIT(usbpf_dev, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, usbpf_drvinit, NULL); -SYSUNINIT(usbpf_undev, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, usbpf_drvuninit, NULL); + USBPFD_GLOBAL_UNLOCK(); + mtx_destroy(&usbpf_global_mtx); +} +SYSUNINIT(usbpf_dev, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, usbpf_drvuninit, NULL); === sys/dev/usb/usb_pf.h ================================================================== --- sys/dev/usb/usb_pf.h (revision 215787) +++ sys/dev/usb/usb_pf.h (local) @@ -1,12 +1,7 @@ /*- - * Copyright (c) 1990, 1991, 1993 - * The Regents of the University of California. All rights reserved. + * Copyright (c) 2010 Weongyo Jeong. All rights reserved. + * Copyright (c) 2010 Hans Petter Selasky. All rights reserved. * - * This code is derived from the Stanford/CMU enet packet filter, - * (net/enet.c) distributed as part of 4.3BSD, and code contributed - * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence - * Berkeley Laboratory. - * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -15,9 +10,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -44,20 +36,53 @@ #include #endif -typedef int32_t usbpf_int32; -typedef u_int32_t usbpf_u_int32; -typedef int64_t usbpf_int64; -typedef u_int64_t usbpf_u_int64; - +struct usb_xfer; struct usbpf_if; +struct usbpf_pkthdr; +#define USBPF_MAX_BUFFER_LEN (1U << 20) /* maximum tap length */ +#define USBPF_MAX_QUEUE_LEN 64 /* maximum number of unread transfers */ +#define USBPF_PKTHDR_SIZE 128 /* bytes */ +#define USBPF_LENGTH_ALIGN(x) (((x) + 3) & ~(uint32_t)3) +#define USBPF_FRAMEHDR_SIZE 3 /* dwords */ +#define USBPF_MAX_FILTER 65536 /* instructions */ + +/* scratch size in 32-bits for (for USBPF_LD|USBPF_MEM and USBPF_ST) */ +#define USBPF_MEMWORDS 16 + /* - * Alignment macros. USBPF_WORDALIGN rounds up to the next - * even multiple of USBPF_ALIGNMENT. + * Structure prepended to each packet. */ -#define USBPF_ALIGNMENT sizeof(long) -#define USBPF_WORDALIGN(x) (((x)+(USBPF_ALIGNMENT-1))&~(USBPF_ALIGNMENT-1)) +struct usbpf_pkthdr_first { + uint64_t up_sec; /* timestamp seconds */ + uint64_t up_frac; /* timestamp fraction */ + uint32_t up_busunit; /* Host controller unit number */ + uint32_t up_frames; /* USB frame number (submit/actual) */ + uint32_t up_hdrlen; /* total header length */ + uint32_t up_interval; /* for interrupt and isoc */ + uint32_t up_nframes; /* number of USB frames */ + uint32_t up_status; /* transfer status */ + uint32_t up_totlen; /* total packet length (including data) */ + uint32_t up_error; /* usb_error_t */ + uint32_t up_packet_size; /* USB packet size */ + uint32_t up_packet_count;/* USB packet count */ + uint8_t up_devunit; /* USB device unit number */ + uint8_t up_dmode; /* set if device mode, else host */ + uint8_t up_endpoint; /* USB endpoint */ + uint8_t up_type; /* type: SUBMIT or DONE */ + uint8_t up_xfertype; /* USB transfer type */ +} __packed; +struct usbpf_pkthdr { + struct usbpf_pkthdr_first hdr; + union { +#ifdef _KERNEL + TAILQ_ENTRY(usbpf_pkthdr) entry; /* for internal use */ +#endif + uint8_t dummy[USBPF_PKTHDR_SIZE - sizeof(struct usbpf_pkthdr_first)]; + } __packed reserved; +} __packed; + /* * The instruction encodings. */ @@ -119,201 +144,93 @@ * The instruction data structure. */ struct usbpf_insn { - u_short code; - u_char jt; - u_char jf; - usbpf_u_int32 k; + uint16_t code; + uint8_t jt; + uint8_t jf; + uint32_t k; }; -#ifdef _KERNEL +struct usbpf_version { + uint16_t uv_major; + uint16_t uv_minor; +}; +#define USBPF_MAJOR_VERSION 1 +#define USBPF_MINOR_VERSION 2 +struct usbpf_ifreq { + /* pre-filter parameters */ + uint32_t ua_bus_unit; /* must match, if not ANY */ + uint32_t ua_dev_unit; /* must match, if not ANY */ + uint32_t ua_endpoint_mask; /* must match, if not ANY */ +#define USBPF_IFREQ_ANY 0xFFFFFFFFU /* ANY bus, device or endpoint unit */ + /* post-filter parameters */ + uint32_t ua_filter_len; /* number of filter entries */ + const struct usbpf_insn *ua_filter_ptr; +}; + /* - * Descriptor associated with each open uff file. + * Struct returned by UIOCGSTATS. */ +struct usbpf_stat { + uint64_t us_recv; /* number of packets received */ + uint64_t us_drop; /* number of packets dropped */ +}; -struct usbpf_d { - LIST_ENTRY(usbpf_d) ud_next; /* Linked list of descriptors */ - /* - * Buffer slots: two memory buffers store the incoming packets. - * The model has three slots. Sbuf is always occupied. - * sbuf (store) - Receive interrupt puts packets here. - * hbuf (hold) - When sbuf is full, put buffer here and - * wakeup read (replace sbuf with fbuf). - * fbuf (free) - When read is done, put buffer here. - * On receiving, if sbuf is full and fbuf is 0, packet is dropped. - */ - caddr_t ud_sbuf; /* store slot */ - caddr_t ud_hbuf; /* hold slot */ - caddr_t ud_fbuf; /* free slot */ - int ud_slen; /* current length of store buffer */ - int ud_hlen; /* current length of hold buffer */ +#define UIOCSETIF _IOW('U', 108, struct usbpf_ifreq) +#define UIOCSRTIMEOUT _IOW('U', 109, struct timeval) +#define UIOCGRTIMEOUT _IOR('U', 110, struct timeval) +#define UIOCGSTATS _IOR('U', 111, struct usbpf_stat) +#define UIOCVERSION _IOR('U', 112, struct usbpf_version) +#define UIOCGBLEN _IOR('U', 113, long) - int ud_bufsize; /* absolute length of buffers */ +/* definition of second parameter in usb_pf_xfertap_t function */ - struct usbpf_if *ud_bif; /* interface descriptor */ - u_long ud_rtout; /* Read timeout in 'ticks' */ - struct usbpf_insn *ud_rfilter; /* read filter code */ - struct usbpf_insn *ud_wfilter; /* write filter code */ - void *ud_bfilter; /* binary filter code */ - u_int64_t ud_rcount; /* number of packets received */ - u_int64_t ud_dcount; /* number of packets dropped */ +#define USBPF_XFERTAP_SUBMIT 0 +#define USBPF_XFERTAP_DONE 1 - u_char ud_promisc; /* true if listening promiscuously */ - u_char ud_state; /* idle, waiting, or timed out */ - u_char ud_immediate; /* true to return on packet arrival */ - int ud_hdrcmplt; /* false to fill in src lladdr automatically */ - int ud_direction; /* select packet direction */ - int ud_tstamp; /* select time stamping function */ - int ud_feedback; /* true to feed back sent packets */ - int ud_async; /* non-zero if packet reception should generate signal */ - int ud_sig; /* signal to send upon packet reception */ - struct sigio * ud_sigio; /* information for async I/O */ - struct selinfo ud_sel; /* bsd select info */ - struct mtx ud_mtx; /* mutex for this descriptor */ - struct callout ud_callout; /* for USBPF timeouts with select */ - struct label *ud_label; /* MAC label for descriptor */ - u_int64_t ud_fcount; /* number of packets which matched filter */ - pid_t ud_pid; /* PID which created descriptor */ - int ud_locked; /* true if descriptor is locked */ - u_int ud_bufmode; /* Current buffer mode. */ - u_int64_t ud_wcount; /* number of packets written */ - u_int64_t ud_wfcount; /* number of packets that matched write filter */ - u_int64_t ud_wdcount; /* number of packets dropped during a write */ - u_int64_t ud_zcopy; /* number of zero copy operations */ - u_char ud_compat32; /* 32-bit stream on LP64 system */ -}; +/* definition of USB transfer flags */ -#define USBPFD_LOCK(ud) mtx_lock(&(ud)->ud_mtx) -#define USBPFD_UNLOCK(ud) mtx_unlock(&(ud)->ud_mtx) -#define USBPFD_LOCK_ASSERT(ud) mtx_assert(&(ud)->ud_mtx, MA_OWNED) +#define USBPF_XFERFLAG_READ 0x00000001U +#define USBPF_XFERFLAG_SHORT_OK 0x00000002U +#define USBPF_XFERFLAG_MULTI_SHORT_OK 0x00000004U +#define USBPF_XFERFLAG_FORCE_SHORT 0x00000008U +#define USBPF_XFERFLAG_STALL_PIPE 0x00000010U +#define USBPF_XFERFLAG_CONTROL_ACT 0x00000020U +#define USBPF_XFERFLAG_DATA_FOLLOWS 0x00000040U +#ifdef _KERNEL + /* - * Descriptor associated with each attached hardware interface. + * Descriptor associated with each open upf file. */ -struct usbpf_if { - LIST_ENTRY(usbpf_if) uif_next; /* list of all interfaces */ - LIST_HEAD(, usbpf_d) uif_dlist; /* descriptor list */ - u_int uif_hdrlen; /* length of link header */ - struct usb_bus *uif_ubus; /* corresponding interface */ - struct mtx uif_mtx; /* mutex for interface */ -}; +struct usbpf_d { + TAILQ_ENTRY(usbpf_d) ud_next; /* Linked list of descriptors */ -#define USBPFIF_LOCK(uif) mtx_lock(&(uif)->uif_mtx) -#define USBPFIF_UNLOCK(uif) mtx_unlock(&(uif)->uif_mtx) + TAILQ_HEAD(, usbpf_pkthdr) ud_head; -#endif + uint32_t ud_queue_len; /* number of packets queued */ + uint32_t ud_rtout; /* Read timeout in 'ticks' */ -/* - * Structure prepended to each packet. - */ -struct usbpf_ts { - usbpf_int64 ut_sec; /* seconds */ - usbpf_u_int64 ut_frac; /* fraction */ -}; -struct usbpf_xhdr { - struct usbpf_ts uh_tstamp; /* time stamp */ - usbpf_u_int32 uh_caplen; /* length of captured portion */ - usbpf_u_int32 uh_datalen; /* original length of packet */ - u_short uh_hdrlen; /* length of uff header (this struct - plus alignment padding) */ -}; + struct usbpf_insn *ud_filter_code; /* post-filter code */ -#define USBPF_BUFMODE_BUFFER 1 /* Kernel buffers with read(). */ -#define USBPF_BUFMODE_ZBUF 2 /* Zero-copy buffers. */ + uint64_t ud_rcount; /* number of packets received */ + uint64_t ud_dcount; /* number of packets dropped */ -struct usbpf_pkthdr { - int up_busunit; /* Host controller unit number */ - u_char up_address; /* USB device address */ - u_char up_endpoint; /* USB endpoint */ - u_char up_type; /* points SUBMIT / DONE */ - u_char up_xfertype; /* Transfer type */ - u_int32_t up_flags; /* Transfer flags */ -#define USBPF_FLAG_FORCE_SHORT_XFER (1 << 0) -#define USBPF_FLAG_SHORT_XFER_OK (1 << 1) -#define USBPF_FLAG_SHORT_FRAMES_OK (1 << 2) -#define USBPF_FLAG_PIPE_BOF (1 << 3) -#define USBPF_FLAG_PROXY_BUFFER (1 << 4) -#define USBPF_FLAG_EXT_BUFFER (1 << 5) -#define USBPF_FLAG_MANUAL_STATUS (1 << 6) -#define USBPF_FLAG_NO_PIPE_OK (1 << 7) -#define USBPF_FLAG_STALL_PIPE (1 << 8) - u_int32_t up_status; /* Transfer status */ -#define USBPF_STATUS_OPEN (1 << 0) -#define USBPF_STATUS_TRANSFERRING (1 << 1) -#define USBPF_STATUS_DID_DMA_DELAY (1 << 2) -#define USBPF_STATUS_DID_CLOSE (1 << 3) -#define USBPF_STATUS_DRAINING (1 << 4) -#define USBPF_STATUS_STARTED (1 << 5) -#define USBPF_STATUS_BW_RECLAIMED (1 << 6) -#define USBPF_STATUS_CONTROL_XFR (1 << 7) -#define USBPF_STATUS_CONTROL_HDR (1 << 8) -#define USBPF_STATUS_CONTROL_ACT (1 << 9) -#define USBPF_STATUS_CONTROL_STALL (1 << 10) -#define USBPF_STATUS_SHORT_FRAMES_OK (1 << 11) -#define USBPF_STATUS_SHORT_XFER_OK (1 << 12) -#if USB_HAVE_BUSDMA -#define USBPF_STATUS_BDMA_ENABLE (1 << 13) -#define USBPF_STATUS_BDMA_NO_POST_SYNC (1 << 14) -#define USBPF_STATUS_BDMA_SETUP (1 << 15) -#endif -#define USBPF_STATUS_ISOCHRONOUS_XFR (1 << 16) -#define USBPF_STATUS_CURR_DMA_SET (1 << 17) -#define USBPF_STATUS_CAN_CANCEL_IMMED (1 << 18) -#define USBPF_STATUS_DOING_CALLBACK (1 << 19) - u_int32_t up_length; /* Total data length (submit/actual) */ - u_int32_t up_frames; /* USB frame number (submit/actual) */ - u_int32_t up_error; /* usb_error_t */ - u_int32_t up_interval; /* for interrupt and isoc */ - /* sizeof(struct usbpf_pkthdr) == 128 bytes */ - u_char up_reserved[96]; -}; + int ud_tstamp; /* select time stamping function */ -struct usbpf_version { - u_short uv_major; - u_short uv_minor; -}; -#define USBPF_MAJOR_VERSION 1 -#define USBPF_MINOR_VERSION 1 + struct selinfo ud_sel; /* BSD select info */ -#define USBPF_IFNAMSIZ 32 -struct usbpf_ifreq { - /* bus name, e.g. "usbus0" */ - char ufr_name[USBPF_IFNAMSIZ]; -}; + uint64_t ud_fcount; /* number of packets which matched filter */ -/* - * Structure for UIOCSETF. - */ -struct usbpf_program { - u_int uf_len; - struct usbpf_insn *uf_insns; -}; + int ud_running; /* set if running */ -/* - * Struct returned by UIOCGSTATS. - */ -struct usbpf_stat { - u_int us_recv; /* number of packets received */ - u_int us_drop; /* number of packets dropped */ + struct usbpf_ifreq ud_filter; /* data filter */ }; -#define UIOCGBLEN _IOR('U', 102, u_int) -#define UIOCSBLEN _IOWR('U', 102, u_int) -#define UIOCSETF _IOW('U', 103, struct usbpf_program) -#define UIOCSETIF _IOW('U', 108, struct usbpf_ifreq) -#define UIOCSRTIMEOUT _IOW('U', 109, struct timeval) -#define UIOCGRTIMEOUT _IOR('U', 110, struct timeval) -#define UIOCGSTATS _IOR('U', 111, struct usbpf_stat) -#define UIOCVERSION _IOR('U', 113, struct usbpf_version) -#define UIOCSETWF _IOW('U', 123, struct usbpf_program) +#define USBPFD_GLOBAL_LOCK() mtx_lock(&usbpf_global_mtx) +#define USBPFD_GLOBAL_UNLOCK() mtx_unlock(&usbpf_global_mtx) +#define USBPFD_GLOBAL_ASSERT_LOCKED() mtx_assert(&usbpf_global_mtx, MA_OWNED) -#define USBPF_XFERTAP_SUBMIT 0 -#define USBPF_XFERTAP_DONE 1 - -#ifdef _KERNEL -void usbpf_attach(struct usb_bus *, struct usbpf_if **); -void usbpf_detach(struct usb_bus *); -void usbpf_xfertap(struct usb_xfer *, int); #endif #endif === sys/dev/usb/usb_transfer.c ================================================================== --- sys/dev/usb/usb_transfer.c (revision 215787) +++ sys/dev/usb/usb_transfer.c (local) @@ -57,10 +57,13 @@ #include #include #include +#if USB_HAVE_PF +#include +#include +#endif #include #include -#include struct usb_std_packet_size { struct { @@ -666,6 +669,14 @@ /* setup "frlengths" */ xfer->frlengths = parm->xfer_length_ptr; parm->xfer_length_ptr += n_frlengths; +#if USB_HAVE_PF + /* + * We need extra room to store the initial + * length values in case of isochronous + * transfers. + */ + parm->xfer_length_ptr += n_frlengths; +#endif /* setup "frbuffers" */ xfer->frbuffers = parm->xfer_page_cache_ptr; @@ -1587,6 +1598,10 @@ USB_BUS_UNLOCK(bus); return; } +#if USB_HAVE_PF + /* Make a copy of the initial frame lengths */ + xfer->frlengths[x + xfer->max_frame_count] = xfer->frlengths[x]; +#endif } /* clear some internal flags */ @@ -1636,7 +1651,15 @@ } } } + /* + * Tap frames to the USB packet filter before + * any BUSDMA operations. + */ +#if USB_HAVE_PF + usb_pf_xfertap_p(xfer, USBPF_XFERTAP_SUBMIT); +#endif + /* * Check if BUS-DMA support is enabled and try to load virtual * buffers into DMA, if any: */ @@ -2195,11 +2218,11 @@ } #endif } +#if USB_HAVE_PF + usb_pf_xfertap_p(xfer, USBPF_XFERTAP_DONE); +#endif } - if (xfer->usb_state != USB_ST_SETUP) - usbpf_xfertap(xfer, USBPF_XFERTAP_DONE); - /* call processing routine */ (xfer->callback) (xfer, xfer->error); @@ -2387,8 +2410,6 @@ DPRINTF("start\n"); - usbpf_xfertap(xfer, USBPF_XFERTAP_SUBMIT); - /* start the transfer */ (ep->methods->start) (xfer); @@ -2566,8 +2587,6 @@ } DPRINTF("start\n"); - usbpf_xfertap(xfer, USBPF_XFERTAP_SUBMIT); - /* start USB transfer */ (ep->methods->start) (xfer); === sys/modules/usb/Makefile ================================================================== --- sys/modules/usb/Makefile (revision 215787) +++ sys/modules/usb/Makefile (local) @@ -34,6 +34,7 @@ SUBDIR += uether aue axe cdce cue kue rue udav uhso ipheth SUBDIR += usfs umass urio SUBDIR += quirk template +SUBDIR += upf .if ${MACHINE_CPUARCH} == "amd64" _urtw= urtw === sys/modules/usb/upf (new directory) ================================================================== === sys/modules/usb/upf/Makefile ================================================================== --- sys/modules/usb/upf/Makefile (revision 215787) +++ sys/modules/usb/upf/Makefile (local) @@ -0,0 +1,37 @@ +# +# $FreeBSD$ +# +# Copyright (c) 2010 Hans Petter Selasky. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +S= ${.CURDIR}/../../.. + +.PATH: $S/dev/usb + +KMOD= usb_pf +SRCS= opt_bus.h opt_usb.h device_if.h bus_if.h usb_if.h \ + usb_pf.c + +.include + Property changes on: sys/modules/usb/upf/Makefile ___________________________________________________________________ Name: svn:eol-style +native Name: svn:keywords +FreeBSD=%H Name: svn:mime-type +text/plain === usr.sbin/Makefile ================================================================== --- usr.sbin/Makefile (revision 215787) +++ usr.sbin/Makefile (local) @@ -293,6 +293,7 @@ .if ${MK_USB} != "no" SUBDIR+= uathload SUBDIR+= uhsoctl +SUBDIR+= usbdump SUBDIR+= usbconfig .endif === usr.sbin/usbdump/usbdump.8 ================================================================== --- usr.sbin/usbdump/usbdump.8 (revision 215787) +++ usr.sbin/usbdump/usbdump.8 (local) @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd October 14, 2010 +.Dd November 23, 2010 .Dt usbdump 8 .Os .Sh NAME @@ -33,7 +33,8 @@ .Nd "dump traffic on USB host controller" .Sh SYNOPSIS .Nm -.Op Fl i Ar ifname +.Op Fl d Ar bus.dev.endpoint +.Op Fl b Ar bufsize .Op Fl r Ar file .Op Fl s Ar snaplen .Op Fl v @@ -45,27 +46,40 @@ .Pp The following options are accepted. .Bl -tag -width ".Fl f Ar file" -.It Fl i Ar ifname -Listen on USB bus interface. +.It Fl d Ar bus.dev.endpoint +Listen on the given bus, device and endpoint. +This option is mandatory. +A negative value in any of the given fields means any bus, device or endpoint. +.It Fl b Ar bufsize +Set internal buffer size in bytes. +Default: -1. .It Fl r Ar file Read the raw packets from file. +Default: Off .It Fl s Ar snaplen Snapshot bytes from each packet. +Default: 192 .It Fl v Enable debugging messages. When it defined multiple times the verbose level increases. +Default: Off .It Fl w Ar file Write the raw packets to file. +Default: Off .El .Sh EXAMPLES -Captures the USB raw packets alive on usbus2: +Captures the USB raw packets alive on ugen2.x: .Pp -.Dl "usbdump -i usbus2 -s 256 -v" +.Dl "usbdump -d 2 -s 256 -v" .Pp -Dumps the USB raw packets of usbus2 into the file without packet +Captures the USB raw packets alive on ugen2.1: +.Pp +.Dl "usbdump -d 2.1 -s 256 -v" +.Pp +Dumps the USB raw packets of ugen2.x into the file without packet size limit: .Pp -.Dl "usbdump -i usbus2 -s 0 -w /tmp/dump_pkts" +.Dl "usbdump -d 2 -s 0 -w /tmp/dump_pkts" .Pp Read the USB raw packets from the file: .Pp === usr.sbin/usbdump/usbdump.c ================================================================== --- usr.sbin/usbdump/usbdump.c (revision 215787) +++ usr.sbin/usbdump/usbdump.c (local) @@ -49,8 +49,8 @@ struct usbcap { int fd; /* fd for /dev/usbpf */ - u_int bufsize; - char *buffer; + uint32_t bufsize; + void *buffer; /* for -w option */ int wfd; @@ -59,17 +59,21 @@ }; struct usbcap_filehdr { - u_int magic; + uint32_t magic; #define USBCAP_FILEHDR_MAGIC 0x9a90000e - u_char major; - u_char minor; - u_char reserved[26]; + uint8_t major; + uint8_t minor; + uint8_t reserved[26]; } __packed; static int doexit = 0; static int pkt_captured = 0; static int verbose = 0; -static const char *i_arg = "usbus0";; +static int bus = -1; +static int device = -1; +static int endpoint = -1; +static int bufsize = -1; + static const char *r_arg = NULL; static const char *w_arg = NULL; static const char *errstr_table[USB_ERR_MAX] = { @@ -114,67 +118,29 @@ static void handle_sigint(int sig) { + (void)sig; - (void)sig; doexit = 1; } static void -print_flags(u_int32_t flags) +print_flags(uint32_t flags) { #define PRINTFLAGS(name) \ - if ((flags & USBPF_FLAG_##name) != 0) \ - printf("%s ", #name); - printf(" flags %#x", flags); - printf(" < "); - PRINTFLAGS(FORCE_SHORT_XFER); - PRINTFLAGS(SHORT_XFER_OK); - PRINTFLAGS(SHORT_FRAMES_OK); - PRINTFLAGS(PIPE_BOF); - PRINTFLAGS(PROXY_BUFFER); - PRINTFLAGS(EXT_BUFFER); - PRINTFLAGS(MANUAL_STATUS); - PRINTFLAGS(NO_PIPE_OK); + if ((flags & USBPF_XFERFLAG_##name) != 0) \ + printf("%s/", #name); + printf(" flags["); + PRINTFLAGS(READ); + PRINTFLAGS(SHORT_OK); + PRINTFLAGS(MULTI_SHORT_OK); + PRINTFLAGS(FORCE_SHORT); PRINTFLAGS(STALL_PIPE); - printf(">\n"); + PRINTFLAGS(CONTROL_ACT); + PRINTFLAGS(DATA_FOLLOWS); + printf("0x%08x]", flags); #undef PRINTFLAGS } -static void -print_status(u_int32_t status) -{ -#define PRINTSTATUS(name) \ - if ((status & USBPF_STATUS_##name) != 0) \ - printf("%s ", #name); - - printf(" status %#x", status); - printf(" < "); - PRINTSTATUS(OPEN); - PRINTSTATUS(TRANSFERRING); - PRINTSTATUS(DID_DMA_DELAY); - PRINTSTATUS(DID_CLOSE); - PRINTSTATUS(DRAINING); - PRINTSTATUS(STARTED); - PRINTSTATUS(BW_RECLAIMED); - PRINTSTATUS(CONTROL_XFR); - PRINTSTATUS(CONTROL_HDR); - PRINTSTATUS(CONTROL_ACT); - PRINTSTATUS(CONTROL_STALL); - PRINTSTATUS(SHORT_FRAMES_OK); - PRINTSTATUS(SHORT_XFER_OK); -#if USB_HAVE_BUSDMA - PRINTSTATUS(BDMA_ENABLE); - PRINTSTATUS(BDMA_NO_POST_SYNC); - PRINTSTATUS(BDMA_SETUP); -#endif - PRINTSTATUS(ISOCHRONOUS_XFR); - PRINTSTATUS(CURR_DMA_SET); - PRINTSTATUS(CAN_CANCEL_IMMED); - PRINTSTATUS(DOING_CALLBACK); - printf(">\n"); -#undef PRINTSTATUS -} - /* * Display a region in traditional hexdump format. */ @@ -216,90 +182,129 @@ } static void -print_apacket(const struct usbpf_xhdr *hdr, struct usbpf_pkthdr *up, - const char *payload) +print_apacket(const struct usbpf_pkthdr *up, const uint32_t *ptr, + uint32_t framelen, uint32_t snaplen, uint32_t flags, uint32_t frameno) { + struct usbpf_pkthdr_first hdr; struct tm *tm; struct timeval tv; size_t len; - u_int32_t framelen, x; - const char *ptr = payload; char buf[64]; /* A packet from the kernel is based on little endian byte order. */ - up->up_busunit = le32toh(up->up_busunit); - up->up_flags = le32toh(up->up_flags); - up->up_status = le32toh(up->up_status); - up->up_length = le32toh(up->up_length); - up->up_frames = le32toh(up->up_frames); - up->up_error = le32toh(up->up_error); - up->up_interval = le32toh(up->up_interval); + hdr.up_sec = le64toh(up->hdr.up_sec); + hdr.up_frac = le64toh(up->hdr.up_frac); + hdr.up_busunit = le32toh(up->hdr.up_busunit); + hdr.up_frames = le32toh(up->hdr.up_frames); + hdr.up_interval = le32toh(up->hdr.up_interval); + hdr.up_status = le32toh(up->hdr.up_status); + hdr.up_totlen = le32toh(up->hdr.up_totlen); + hdr.up_error = le32toh(up->hdr.up_error); + hdr.up_packet_size = le32toh(up->hdr.up_packet_size); + hdr.up_packet_count = le32toh(up->hdr.up_packet_count); + hdr.up_devunit = up->hdr.up_devunit; + hdr.up_dmode = up->hdr.up_dmode; + hdr.up_endpoint = up->hdr.up_endpoint; + hdr.up_type = up->hdr.up_type; + hdr.up_xfertype = up->hdr.up_xfertype; - tv.tv_sec = hdr->uh_tstamp.ut_sec; - tv.tv_usec = hdr->uh_tstamp.ut_frac; + if (frameno != 0) + goto skip_hdr; + + tv.tv_sec = hdr.up_sec; + tv.tv_usec = hdr.up_frac; tm = localtime(&tv.tv_sec); len = strftime(buf, sizeof(buf), "%H:%M:%S", tm); printf("%.*s.%06ju", (int)len, buf, tv.tv_usec); - printf(" usbus%d.%d 0x%02x %s %s", up->up_busunit, up->up_address, - up->up_endpoint, - xfertype_table[up->up_xfertype], - up->up_type == USBPF_XFERTAP_SUBMIT ? ">" : "<"); - printf(" (%d/%d)", up->up_frames, up->up_length); - if (up->up_type == USBPF_XFERTAP_DONE) - printf(" %s", errstr_table[up->up_error]); - if (up->up_xfertype == UE_BULK || up->up_xfertype == UE_ISOCHRONOUS) - printf(" %d", up->up_interval); + printf(" usbus%d.%d 0x%02x %s %s %s", hdr.up_busunit, hdr.up_devunit, + hdr.up_xfertype != UE_CONTROL ? hdr.up_endpoint : hdr.up_endpoint & 0x0F, + xfertype_table[hdr.up_xfertype & 3], + hdr.up_type == USBPF_XFERTAP_SUBMIT ? "->" : "<-", + (flags & USBPF_XFERFLAG_READ) ? "RD" : "WR"); + + printf(" (%d+%d)", hdr.up_frames, + hdr.up_totlen - USBPF_PKTHDR_SIZE - (4 * USBPF_FRAMEHDR_SIZE * hdr.up_frames)); + + if (hdr.up_type == USBPF_XFERTAP_DONE) { + printf(" %s", (errstr_table[hdr.up_error] != NULL) ? + errstr_table[hdr.up_error] : ""); + } + if (hdr.up_xfertype != UE_ISOCHRONOUS) + printf(" %d ms", hdr.up_interval); printf("\n"); - if (verbose >= 1) { - for (x = 0; x < up->up_frames; x++) { - framelen = le32toh(*((const u_int32_t *)ptr)); - ptr += sizeof(u_int32_t); - printf(" frame[%u] len %d\n", x, framelen); - assert(framelen < (1024 * 4)); - hexdump(ptr, framelen); - ptr += framelen; - } +skip_hdr: + if (verbose >= 1) { + printf(" frame[%u/%u] len[%u/%u]", frameno, + hdr.up_frames, snaplen, framelen); + if (verbose >= 2) + print_flags(flags); + printf("\n"); + if (flags & USBPF_XFERFLAG_DATA_FOLLOWS) + hexdump((const uint8_t *)ptr, snaplen); } - if (verbose >= 2) { - print_flags(up->up_flags); - print_status(up->up_status); - } } - static void -print_packets(char *data, const int datalen) +print_packets(const struct usbpf_pkthdr *up, uint32_t maxlen) { - struct usbpf_pkthdr *up; - const struct usbpf_xhdr *hdr; - u_int32_t framelen, x; - char *ptr, *next; + const uint32_t *data; + const uint32_t *ptr; + const uint32_t *next; + const uint32_t *end; + uint32_t datalen; + uint32_t framelen; + uint32_t snaplen; + uint32_t flags; + uint32_t x; - for (ptr = data; ptr < (data + datalen); ptr = next) { - hdr = (const struct usbpf_xhdr *)ptr; - up = (struct usbpf_pkthdr *)(ptr + hdr->uh_hdrlen); - next = ptr + USBPF_WORDALIGN(hdr->uh_hdrlen + hdr->uh_caplen); + if (maxlen < USBPF_PKTHDR_SIZE) + return; - ptr = ((char *)up) + sizeof(struct usbpf_pkthdr); + datalen = le32toh(up->hdr.up_totlen); + + if (datalen > maxlen || datalen < sizeof(*up)) + return; + + data = (const uint32_t *)(up + 1); + end = data + ((datalen - sizeof(*up)) / 4); + x = 0; + + for (ptr = data; ptr <= (end - USBPF_FRAMEHDR_SIZE); ptr = next, x++) { + + framelen = le32toh(ptr[0]); + flags = le32toh(ptr[1]); + snaplen = le32toh(ptr[2]); + + /* sanity check */ + if (snaplen > framelen) + snaplen = framelen; + + next = ptr + USBPF_FRAMEHDR_SIZE; + + if (flags & USBPF_XFERFLAG_DATA_FOLLOWS) + next += (USBPF_LENGTH_ALIGN(snaplen) / 4); + else + snaplen = 0; + + /* Corrupt data? We are done! */ + if (next > end || next < data) + return; if (w_arg == NULL) - print_apacket(hdr, up, ptr); + print_apacket(up, ptr + USBPF_FRAMEHDR_SIZE, + framelen, snaplen, flags, x); pkt_captured++; - for (x = 0; x < up->up_frames; x++) { - framelen = le32toh(*((const u_int32_t *)ptr)); - ptr += sizeof(u_int32_t) + framelen; - } } } static void -write_packets(struct usbcap *p, const char *data, const int datalen) +write_packets(struct usbcap *p, const char *data, const uint32_t datalen) { - int len = htole32(datalen), ret; + uint32_t len = htole32(datalen), ret; - ret = write(p->wfd, &len, sizeof(int)); - assert(ret == sizeof(int)); + ret = write(p->wfd, &len, sizeof(uint32_t)); + assert(ret == sizeof(uint32_t)); ret = write(p->wfd, data, datalen); assert(ret == datalen); } @@ -307,15 +312,16 @@ static void read_file(struct usbcap *p) { - int datalen, ret; - char *data; + void *data; + uint32_t datalen; + int ret; - while ((ret = read(p->rfd, &datalen, sizeof(int))) == sizeof(int)) { + while ((ret = read(p->rfd, &datalen, sizeof(uint32_t))) == sizeof(uint32_t)) { datalen = le32toh(datalen); data = malloc(datalen); assert(data != NULL); ret = read(p->rfd, data, datalen); - assert(ret == datalen); + assert(ret == (int)datalen); print_packets(data, datalen); free(data); } @@ -329,18 +335,20 @@ int cc; while (doexit == 0) { - cc = read(p->fd, (char *)p->buffer, p->bufsize); + cc = read(p->fd, p->buffer, p->bufsize); if (cc < 0) { switch (errno) { case EINTR: break; + case EWOULDBLOCK: + break; default: fprintf(stderr, "read: %s\n", strerror(errno)); return; } continue; } - if (cc == 0) + if (cc < USBPF_PKTHDR_SIZE) continue; if (w_arg != NULL) write_packets(p, p->buffer, cc); @@ -363,7 +371,7 @@ assert(ret == sizeof(uf)); assert(le32toh(uf.magic) == USBCAP_FILEHDR_MAGIC); assert(uf.major == 0); - assert(uf.minor == 1); + assert(uf.minor == 2); } static void @@ -380,7 +388,7 @@ bzero(&uf, sizeof(uf)); uf.magic = htole32(USBCAP_FILEHDR_MAGIC); uf.major = 0; - uf.minor = 1; + uf.minor = 2; ret = write(p->wfd, (const void *)&uf, sizeof(uf)); assert(ret == sizeof(uf)); } @@ -389,11 +397,12 @@ usage(void) { -#define FMT " %-14s %s\n" - fprintf(stderr, "usage: usbdump [options]\n"); - fprintf(stderr, FMT, "-i ifname", "Listen on USB bus interface"); +#define FMT " %-14s %s\n" + fprintf(stderr, "usage: usbdump -d <...> [options]\n"); + fprintf(stderr, FMT, "-d ", "Listen on the give bus, device and endpoint"); + fprintf(stderr, FMT, "-b ", "Buffer size"); fprintf(stderr, FMT, "-r file", "Read the raw packets from file"); - fprintf(stderr, FMT, "-s snaplen", "Snapshot bytes from each packet"); + fprintf(stderr, FMT, "-s ", "Snapshot bytes from each USB packet."); fprintf(stderr, FMT, "-v", "Increases the verbose level"); fprintf(stderr, FMT, "-w file", "Write the raw packets to file"); #undef FMT @@ -405,24 +414,51 @@ { struct timeval tv; struct usbpf_insn total_insn; - struct usbpf_program total_prog; struct usbpf_stat us; struct usbpf_version uv; - struct usbcap uc, *p = &uc; + struct usbcap uc; + struct usbcap *p = &uc; struct usbpf_ifreq ufr; + char *ptr; long snapshot = 192; - u_int v; - int fd, o; - const char *optstring; + long v; + int fd; + int o; + int got_dev = 0; - bzero(&uc, sizeof(struct usbcap)); + memset(&uc, 0, sizeof(struct usbcap)); - optstring = "i:r:s:vw:"; - while ((o = getopt(argc, argv, optstring)) != -1) { + while ((o = getopt(argc, argv, "b:d:r:s:vw:")) != -1) { switch (o) { - case 'i': - i_arg = optarg; + case 'b': + bufsize = atoi(optarg); break; + case 'd': + got_dev = 1; + ptr = strstr(optarg, "."); + if (ptr != NULL) + ptr[0] = 0; + bus = atoi(optarg); + if (ptr == NULL) + break; + optarg = ptr + 1; + + ptr = strstr(optarg, "."); + if (ptr != NULL) + ptr[0] = 0; + device = atoi(optarg); + if (ptr == NULL) + break; + optarg = ptr + 1; + + ptr = strstr(optarg, "."); + if (ptr != NULL) + ptr[0] = 0; + endpoint = atoi(optarg); + if (ptr == NULL) + break; + optarg = ptr + 1; + break; case 'r': r_arg = optarg; init_rfile(p); @@ -454,12 +490,14 @@ exit(EXIT_SUCCESS); } + if (got_dev == 0) + usage(); + p->fd = fd = open("/dev/usbpf", O_RDONLY); if (p->fd < 0) { fprintf(stderr, "(no devices found)\n"); return (EXIT_FAILURE); } - if (ioctl(fd, UIOCVERSION, (caddr_t)&uv) < 0) { fprintf(stderr, "UIOCVERSION: %s\n", strerror(errno)); return (EXIT_FAILURE); @@ -469,46 +507,44 @@ fprintf(stderr, "kernel bpf filter out of date"); return (EXIT_FAILURE); } - - if ((ioctl(fd, UIOCGBLEN, (caddr_t)&v) < 0) || v < 65536) - v = 65536; - for ( ; v != 0; v >>= 1) { - (void)ioctl(fd, UIOCSBLEN, (caddr_t)&v); - (void)strncpy(ufr.ufr_name, i_arg, sizeof(ufr.ufr_name)); - if (ioctl(fd, UIOCSETIF, (caddr_t)&ufr) >= 0) - break; - } - if (v == 0) { - fprintf(stderr, "UIOCSBLEN: %s: No buffer size worked", i_arg); + if (ioctl(fd, UIOCGBLEN, (caddr_t)&v) < 0) { + fprintf(stderr, "UIOCGBLEN: %s\n", strerror(errno)); return (EXIT_FAILURE); } + if (bufsize < 0 || bufsize > v) + bufsize = v; - if (ioctl(fd, UIOCGBLEN, (caddr_t)&v) < 0) { - fprintf(stderr, "UIOCGBLEN: %s", strerror(errno)); + /* XXX no read filter rules yet so at this moment accept everything */ + total_insn.code = (uint16_t)(USBPF_RET | USBPF_K); + total_insn.jt = 0; + total_insn.jf = 0; + total_insn.k = snapshot; + + memset(&ufr, 0, sizeof(ufr)); + + ufr.ua_bus_unit = bus; + ufr.ua_dev_unit = device; + if (endpoint < 0) + ufr.ua_endpoint_mask = -1; + else + ufr.ua_endpoint_mask = 3U << (2 * (endpoint & 0xF)); + + ufr.ua_filter_ptr = &total_insn; + ufr.ua_filter_len = sizeof(total_insn); + + if (ioctl(fd, UIOCSETIF, (caddr_t)&ufr) < 0) { + fprintf(stderr, "UIOCSETIF: %s\n", strerror(errno)); return (EXIT_FAILURE); } p->bufsize = v; - p->buffer = (u_char *)malloc(p->bufsize); + p->buffer = malloc(p->bufsize); if (p->buffer == NULL) { fprintf(stderr, "malloc: %s", strerror(errno)); return (EXIT_FAILURE); } - /* XXX no read filter rules yet so at this moment accept everything */ - total_insn.code = (u_short)(USBPF_RET | USBPF_K); - total_insn.jt = 0; - total_insn.jf = 0; - total_insn.k = snapshot; - - total_prog.uf_len = 1; - total_prog.uf_insns = &total_insn; - if (ioctl(p->fd, UIOCSETF, (caddr_t)&total_prog) < 0) { - fprintf(stderr, "UIOCSETF: %s", strerror(errno)); - return (EXIT_FAILURE); - } - - /* 1 second read timeout */ + /* set timeout */ tv.tv_sec = 1; tv.tv_usec = 0; if (ioctl(p->fd, UIOCSRTIMEOUT, (caddr_t)&tv) < 0) { @@ -528,8 +564,8 @@ /* XXX what's difference between pkt_captured and us.us_recv? */ printf("\n"); printf("%d packets captured\n", pkt_captured); - printf("%d packets received by filter\n", us.us_recv); - printf("%d packets dropped by kernel\n", us.us_drop); + printf("%lld packets received by filter\n", (long long)us.us_recv); + printf("%lld packets dropped by kernel\n", (long long)us.us_drop); if (p->fd > 0) close(p->fd); --Boundary-00=_xPE7MXid1vdrtfA-- From owner-freebsd-usb@FreeBSD.ORG Tue Nov 23 23:00:43 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 92940106566B; Tue, 23 Nov 2010 23:00:43 +0000 (UTC) (envelope-from hselasky@c2i.net) Received: from swip.net (mailfe03.c2i.net [212.247.154.66]) by mx1.freebsd.org (Postfix) with ESMTP id 922DB8FC17; Tue, 23 Nov 2010 23:00:42 +0000 (UTC) X-Cloudmark-Score: 0.000000 [] X-Cloudmark-Analysis: v=1.1 cv=drJD7N2WYgraSrvx4WFOmF+tWOmhzpnKhDnOdsziBzQ= c=1 sm=1 a=8nJEP1OIZ-IA:10 a=CL8lFSKtTFcA:10 a=i9M/sDlu2rpZ9XS819oYzg==:17 a=dzaNoIAK7SHRQIN9sMwA:9 a=fBbDyyt7ynrgeEVBM3iD6kBOmEsA:4 a=wPNLvfGTeEIA:10 a=i9M/sDlu2rpZ9XS819oYzg==:117 Received: from [188.126.198.129] (account mc467741@c2i.net HELO laptop002.hselasky.homeunix.org) by mailfe03.swip.net (CommuniGate Pro SMTP 5.2.19) with ESMTPA id 53172795; Wed, 24 Nov 2010 00:00:40 +0100 From: Hans Petter Selasky To: Weongyo Jeong Date: Wed, 24 Nov 2010 00:01:27 +0100 User-Agent: KMail/1.13.5 (FreeBSD/8.1-STABLE; KDE/4.4.5; amd64; ; ) References: <201011232319.33678.hselasky@c2i.net> <20101123224002.GH92881@weongyo> In-Reply-To: <20101123224002.GH92881@weongyo> X-Face: +~\`s("[*|O,="7?X@L.elg*F"OA\I/3%^p8g?ab%RN'(; _IjlA: hGE..Ew, XAQ*o#\/M~SC=S1-f9{EzRfT'|Hhll5Q]ha5Bt-s|oTlKMusi:1e[wJl}kd}GR Z0adGx-x_0zGbZj'e(Y[(UNle~)8CQWXW@:DX+9)_YlB[tIccCPN$7/L' MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201011240001.27237.hselasky@c2i.net> Cc: freebsd-usb@freebsd.org, Jung-uk Kim Subject: Re: [RFC] USBdump patches X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Nov 2010 23:00:43 -0000 Dear Weongyo, > NACK. You already could recognize that the patch is quite big and > multiple patches are mixed into one. Please separate into smallest > pieces then send freebsd-usb@ again. I don't want to do a jumbo jump. Probably it is easier if you look at the code after you've applied it to SVN. We are talking about a small amount of C-code, < 1000 LOC. I've spent 6-7 hours today alone cleaning up the initial patch from you. I think I've spent 2-3 work-days now in total reviewing and rewriting USB PF. How much effort did you put into the code, hence you are so critical to my changes? --HPS From owner-freebsd-usb@FreeBSD.ORG Tue Nov 23 23:53:12 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BEA24106564A; Tue, 23 Nov 2010 23:53:12 +0000 (UTC) (envelope-from andy@fud.org.nz) Received: from mail-wy0-f182.google.com (mail-wy0-f182.google.com [74.125.82.182]) by mx1.freebsd.org (Postfix) with ESMTP id 382938FC14; Tue, 23 Nov 2010 23:53:11 +0000 (UTC) Received: by wyf19 with SMTP id 19so18201wyf.13 for ; Tue, 23 Nov 2010 15:53:11 -0800 (PST) MIME-Version: 1.0 Received: by 10.227.29.92 with SMTP id p28mr8439498wbc.70.1290556389775; Tue, 23 Nov 2010 15:53:09 -0800 (PST) Sender: andy@fud.org.nz Received: by 10.227.146.67 with HTTP; Tue, 23 Nov 2010 15:53:09 -0800 (PST) In-Reply-To: <201011232319.33678.hselasky@c2i.net> References: <20101123212448.GG92881@weongyo> <201011232319.33678.hselasky@c2i.net> Date: Wed, 24 Nov 2010 12:53:09 +1300 X-Google-Sender-Auth: EibjyIu2hOuznnlijZ4XqMJVgGI Message-ID: From: Andrew Thompson To: Hans Petter Selasky Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: Weongyo Jeong , freebsd-usb@freebsd.org Subject: Re: [RFC] USBdump patches X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Nov 2010 23:53:12 -0000 On 24 November 2010 11:19, Hans Petter Selasky wrote: > Hi, > > Please find attached official usbdump patch from HPS trying to re-use as = much > as possible of Weongyo's code which was committed not long ago. You need = to > SVN up to the latest 9-current. > @@ -270,7 +122,7 @@ > =A0* The kernel needs to be able to verify an application's filter code. > =A0* Otherwise, a bogus program could easily crash the system. > =A0*/ > -static int > +static uint8_t > =A0usbpf_validate(const struct usbpf_insn *f, int len) > =A0{ Not related to the patch as a whole, but changing the return code of a yes/no function from int to uint8_t doesn't save anything and I think is less readable. Andrew From owner-freebsd-usb@FreeBSD.ORG Wed Nov 24 00:18:11 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5DD031065670; Wed, 24 Nov 2010 00:18:11 +0000 (UTC) (envelope-from weongyo.jeong@gmail.com) Received: from mail-vw0-f54.google.com (mail-vw0-f54.google.com [209.85.212.54]) by mx1.freebsd.org (Postfix) with ESMTP id C9B248FC25; Wed, 24 Nov 2010 00:18:10 +0000 (UTC) Received: by vws9 with SMTP id 9so1747257vws.13 for ; Tue, 23 Nov 2010 16:18:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:received:from:date:to:cc :subject:message-id:reply-to:references:mime-version:content-type :content-disposition:in-reply-to:user-agent:organization :x-operation-sytem; bh=EfycHotO6dDWEI3IHKXWCaT0VV94+LWVcWurAKQaMLw=; b=jmJiPYET6aTcZQz05zXN8NE5Ac5sWfxzr5yaJxCUphBfVFSQa7aoWigVD5ZbDv1y9/ GI4AC4wL0JMSemGZ+wyqjGqFBVOK0QRoysUON3suJhv7t/5jsHKmeGQGUM6XW/NafYEv MSnFCRqv/wwgKwzeD83oOwFib1TujS+kk5HiY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:date:to:cc:subject:message-id:reply-to:references:mime-version :content-type:content-disposition:in-reply-to:user-agent :organization:x-operation-sytem; b=uBGrIkB0y7ehCHlysu/SLFn9CnYUEGQPOgh5xnbs5d9zwCS33HY10JuijJqshARxTk XphRzQwjriqzUhg77Ow6S3/m2Ia1xWoYumd8lEjaU9/1s7iH7kRYZ3cccFDRuBTBvt1c O7PYguzwTtLznyVoMbcaDPPHNUay4efAwlPj4= Received: by 10.220.189.6 with SMTP id dc6mr1397257vcb.43.1290557889426; Tue, 23 Nov 2010 16:18:09 -0800 (PST) Received: from weongyo ([174.35.1.224]) by mx.google.com with ESMTPS id n38sm2426551vba.15.2010.11.23.16.18.05 (version=SSLv3 cipher=RC4-MD5); Tue, 23 Nov 2010 16:18:08 -0800 (PST) Received: by weongyo (sSMTP sendmail emulation); Tue, 23 Nov 2010 16:18:32 -0800 From: Weongyo Jeong Date: Tue, 23 Nov 2010 16:18:32 -0800 To: Jung-uk Kim Message-ID: <20101124001832.GI92881@weongyo> References: <201011240001.27237.hselasky@c2i.net> <201011231831.14555.jkim@FreeBSD.org> <201011231852.40484.jkim@FreeBSD.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201011231852.40484.jkim@FreeBSD.org> User-Agent: Mutt/1.4.2.3i Organization: CDNetworks. X-Operation-Sytem: FreeBSD Cc: freebsd-usb@freebsd.org Subject: Re: [RFC] USBdump patches X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Weongyo Jeong List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Nov 2010 00:18:11 -0000 On Tue, Nov 23, 2010 at 06:52:36PM -0500, Jung-uk Kim wrote: > On Tuesday 23 November 2010 06:31 pm, Jung-uk Kim wrote: > > [CC sanitized] > > > > On Tuesday 23 November 2010 06:01 pm, Hans Petter Selasky wrote: > > > Dear Weongyo, > > > > > > > NACK. You already could recognize that the patch is quite big > > > > and multiple patches are mixed into one. Please separate into > > > > smallest pieces then send freebsd-usb@ again. I don't want to > > > > do a jumbo jump. > > > > > > > Technically, I don't like the copy-and-pasted code from bpf.c and > bpf_filter.c. Was it really necessary? Is the dump file in PCAP > format? > > Please enlighten me if I missed something. The following paragraph is extracted from email I sent to rwatson@ because he also asked same question to me. And I added CC to freebsd-usb@ to share my story with other developers who might think similar. Hello Roberts, I understand what you're worry and agree with you that if I could remove this duplication it'd be best one. I think it could be happen enough later if we could reach the consensus. The biggest confusions I encountered during implementing? (porting) it for USB packet filter were as follows. Please let me know if there are something I missed: - BPF was normally for ethernet frames (most operations were based on mbuf including the machine filter and there were a lot of assumptions the input buffer is mbuf type. For example, handling BPF_LD|BPF_W|BPF_ABS). However the USB packet isn't like mbuf style that it's just a linear buffer. So the most important code or assumption wasn't compatible. - Just making the patch for BPF code, it looked like a trick or a hack to me because I couldn't define what BPF should be. - I could not define BPF exactly myself that what BPF should cover. I agreed with that BPF is for ethernet packet filtering but could not make sure myself that BPF could cover USB packets. Please tell me your opinion if you guys have better approach. regards, Weongyo Jeong From owner-freebsd-usb@FreeBSD.ORG Wed Nov 24 00:37:07 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from [127.0.0.1] (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by hub.freebsd.org (Postfix) with ESMTP id 795691065672; Wed, 24 Nov 2010 00:37:07 +0000 (UTC) (envelope-from jkim@FreeBSD.org) From: Jung-uk Kim To: Weongyo Jeong Date: Tue, 23 Nov 2010 19:36:47 -0500 User-Agent: KMail/1.6.2 References: <201011231852.40484.jkim@FreeBSD.org> <20101124001832.GI92881@weongyo> In-Reply-To: <20101124001832.GI92881@weongyo> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201011231936.57818.jkim@FreeBSD.org> Cc: freebsd-usb@freebsd.org Subject: Re: [RFC] USBdump patches X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Nov 2010 00:37:07 -0000 On Tuesday 23 November 2010 07:18 pm, Weongyo Jeong wrote: > On Tue, Nov 23, 2010 at 06:52:36PM -0500, Jung-uk Kim wrote: > > On Tuesday 23 November 2010 06:31 pm, Jung-uk Kim wrote: > > > [CC sanitized] > > > > > > On Tuesday 23 November 2010 06:01 pm, Hans Petter Selasky wrote: > > > > Dear Weongyo, > > > > > > > > > NACK. You already could recognize that the patch is quite > > > > > big and multiple patches are mixed into one. Please > > > > > separate into smallest pieces then send freebsd-usb@ again. > > > > > I don't want to do a jumbo jump. > > > > Technically, I don't like the copy-and-pasted code from bpf.c and > > bpf_filter.c. Was it really necessary? Is the dump file in PCAP > > format? > > > > Please enlighten me if I missed something. > > The following paragraph is extracted from email I sent to rwatson@ > because he also asked same question to me. And I added CC to > freebsd-usb@ to share my story with other developers who might > think similar. > > Hello Roberts, > > I understand what you're worry and agree with you that if I could > remove this duplication it'd be best one. I think it could be > happen enough later if we could reach the consensus. > > The biggest confusions I encountered during implementing? > (porting) it for USB packet filter were as follows. Please let me > know if there are something I missed: > > - BPF was normally for ethernet frames (most operations were > based on mbuf including the machine filter and there were a lot of > assumptions the input buffer is mbuf type. For example, handling > BPF_LD|BPF_W|BPF_ABS). However the USB packet isn't like mbuf > style that it's just a linear buffer. So the most important code > or assumption wasn't compatible. BPF can deal with linear buffer just fine. For example, ng_bpf(4) does it. Please see sys/netgraph/ng_bpf.c. > - Just making the patch for BPF code, it looked like a trick or > a hack to me because I couldn't define what BPF should be. If you don't want to touch bpf.c for some reason, netgraph(4) (-> ng_bpf) may be an alternate solution for you. > - I could not define BPF exactly myself that what BPF should > cover. I agreed with that BPF is for ethernet packet filtering but > could not make sure myself that BPF could cover USB packets. BPF is a generic packet filter machine, i.e., bytecode is generic enough for any type of data stream. Jung-uk Kim From owner-freebsd-usb@FreeBSD.ORG Wed Nov 24 00:59:51 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 00654106564A; Wed, 24 Nov 2010 00:59:51 +0000 (UTC) (envelope-from andy@fud.org.nz) Received: from mail-wy0-f182.google.com (mail-wy0-f182.google.com [74.125.82.182]) by mx1.freebsd.org (Postfix) with ESMTP id 6DC578FC15; Wed, 24 Nov 2010 00:59:49 +0000 (UTC) Received: by wyf19 with SMTP id 19so72408wyf.13 for ; Tue, 23 Nov 2010 16:59:49 -0800 (PST) MIME-Version: 1.0 Received: by 10.227.129.2 with SMTP id m2mr1473880wbs.99.1290560387983; Tue, 23 Nov 2010 16:59:47 -0800 (PST) Sender: andy@fud.org.nz Received: by 10.227.146.67 with HTTP; Tue, 23 Nov 2010 16:59:47 -0800 (PST) In-Reply-To: <201011231936.57818.jkim@FreeBSD.org> References: <201011231852.40484.jkim@FreeBSD.org> <20101124001832.GI92881@weongyo> <201011231936.57818.jkim@FreeBSD.org> Date: Wed, 24 Nov 2010 13:59:47 +1300 X-Google-Sender-Auth: gHFTvUnSnf6xBIrCUxI9Lp4xDhU Message-ID: From: Andrew Thompson To: Jung-uk Kim Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: Weongyo Jeong , freebsd-usb@freebsd.org Subject: Re: [RFC] USBdump patches X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Nov 2010 00:59:51 -0000 On 24 November 2010 13:36, Jung-uk Kim wrote: > On Tuesday 23 November 2010 07:18 pm, Weongyo Jeong wrote: >> =A0 =A0- BPF was normally for ethernet frames (most operations were >> based on mbuf including the machine filter and there were a lot of >> assumptions the input buffer is mbuf type. =A0For example, handling >> BPF_LD|BPF_W|BPF_ABS). =A0However the USB packet isn't like mbuf >> style that it's just a linear buffer. =A0So the most important code >> or assumption wasn't compatible. > > BPF can deal with linear buffer just fine. =A0For example, ng_bpf(4) > does it. =A0Please see sys/netgraph/ng_bpf.c. > >> =A0 =A0- Just making the patch for BPF code, it looked like a trick or >> a hack to me because I couldn't define what BPF should be. > > If you don't want to touch bpf.c for some reason, netgraph(4) (-> > ng_bpf) may be an alternate solution for you. > >> =A0 =A0- I could not define BPF exactly myself that what BPF should >> cover. I agreed with that BPF is for ethernet packet filtering but >> could not make sure myself that BPF could cover USB packets. > > BPF is a generic packet filter machine, i.e., bytecode is generic > enough for any type of data stream. I agree that this is the best way forward, if it can be achieved. Andrew From owner-freebsd-usb@FreeBSD.ORG Wed Nov 24 01:19:04 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 24B7F106564A; Wed, 24 Nov 2010 01:19:04 +0000 (UTC) (envelope-from weongyo.jeong@gmail.com) Received: from mail-vw0-f54.google.com (mail-vw0-f54.google.com [209.85.212.54]) by mx1.freebsd.org (Postfix) with ESMTP id 9028B8FC0C; Wed, 24 Nov 2010 01:19:03 +0000 (UTC) Received: by vws9 with SMTP id 9so1775438vws.13 for ; Tue, 23 Nov 2010 17:19:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:received:from:date:to:cc :subject:message-id:reply-to:references:mime-version:content-type :content-disposition:in-reply-to:user-agent:organization :x-operation-sytem; bh=20NQtsQ8+jKbX+oSa9JsyAJwxitwsDUBOirAF5euaKw=; b=otE1OI/LTJu28WGjo/3A7LbyT1Mkl9yznGFcRqCaTV16/zP0seU0GoAoUkAnqHV4ec crZMc97SgOt0Vt6afUxkXI0qrRVJDG7jWMPOwb1t9jBWhP6WSmr60UaoP8GnygbeUNE4 fK5I+m2xXqT7LMasuRq2nkAFahfBmfh5JUijQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:date:to:cc:subject:message-id:reply-to:references:mime-version :content-type:content-disposition:in-reply-to:user-agent :organization:x-operation-sytem; b=AHdL48Wj7sMaNu9SMJM70ZtitksDq54a0EZ+uES6BgqL2I3S8SOYYEQsfepm8LrCxw H8/+gzVFeuNaAaK9NBIo9Ghn0B6BHCh84Y3nrhNXcJbpiQmveYRGRwdRpiQz0F1F10vr /NPhURD/27quy+y+CpmiOyGf3PAsvaoQeA2so= Received: by 10.220.160.205 with SMTP id o13mr2020786vcx.278.1290561542580; Tue, 23 Nov 2010 17:19:02 -0800 (PST) Received: from weongyo ([174.35.1.224]) by mx.google.com with ESMTPS id y8sm1550737vch.5.2010.11.23.17.18.59 (version=SSLv3 cipher=RC4-MD5); Tue, 23 Nov 2010 17:19:01 -0800 (PST) Received: by weongyo (sSMTP sendmail emulation); Tue, 23 Nov 2010 17:19:29 -0800 From: Weongyo Jeong Date: Tue, 23 Nov 2010 17:19:29 -0800 To: Jung-uk Kim Message-ID: <20101124011929.GJ92881@weongyo> References: <201011231852.40484.jkim@FreeBSD.org> <20101124001832.GI92881@weongyo> <201011231936.57818.jkim@FreeBSD.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201011231936.57818.jkim@FreeBSD.org> User-Agent: Mutt/1.4.2.3i Organization: CDNetworks. X-Operation-Sytem: FreeBSD Cc: freebsd-usb@freebsd.org Subject: Re: [RFC] USBdump patches X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Weongyo Jeong List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Nov 2010 01:19:04 -0000 On Tue, Nov 23, 2010 at 07:36:47PM -0500, Jung-uk Kim wrote: > On Tuesday 23 November 2010 07:18 pm, Weongyo Jeong wrote: > > On Tue, Nov 23, 2010 at 06:52:36PM -0500, Jung-uk Kim wrote: > > > On Tuesday 23 November 2010 06:31 pm, Jung-uk Kim wrote: > > > > [CC sanitized] > > > > > > > > On Tuesday 23 November 2010 06:01 pm, Hans Petter Selasky wrote: > > > > > Dear Weongyo, > > > > > > > > > > > NACK. You already could recognize that the patch is quite > > > > > > big and multiple patches are mixed into one. Please > > > > > > separate into smallest pieces then send freebsd-usb@ again. > > > > > > I don't want to do a jumbo jump. > > > > > > Technically, I don't like the copy-and-pasted code from bpf.c and > > > bpf_filter.c. Was it really necessary? Is the dump file in PCAP > > > format? > > > > > > Please enlighten me if I missed something. > > > > The following paragraph is extracted from email I sent to rwatson@ > > because he also asked same question to me. And I added CC to > > freebsd-usb@ to share my story with other developers who might > > think similar. > > > > Hello Roberts, > > > > I understand what you're worry and agree with you that if I could > > remove this duplication it'd be best one. I think it could be > > happen enough later if we could reach the consensus. > > > > The biggest confusions I encountered during implementing? > > (porting) it for USB packet filter were as follows. Please let me > > know if there are something I missed: > > > > - BPF was normally for ethernet frames (most operations were > > based on mbuf including the machine filter and there were a lot of > > assumptions the input buffer is mbuf type. For example, handling > > BPF_LD|BPF_W|BPF_ABS). However the USB packet isn't like mbuf > > style that it's just a linear buffer. So the most important code > > or assumption wasn't compatible. > > BPF can deal with linear buffer just fine. For example, ng_bpf(4) > does it. Please see sys/netgraph/ng_bpf.c. > > > - Just making the patch for BPF code, it looked like a trick or > > a hack to me because I couldn't define what BPF should be. > > If you don't want to touch bpf.c for some reason, netgraph(4) (-> > ng_bpf) may be an alternate solution for you. > > > - I could not define BPF exactly myself that what BPF should > > cover. I agreed with that BPF is for ethernet packet filtering but > > could not make sure myself that BPF could cover USB packets. > > BPF is a generic packet filter machine, i.e., bytecode is generic > enough for any type of data stream. Oh I see what you mean. `buflen' was a key variable whether the buffer is mbuf or linear buffer that I missed it. You saved my enough time. :-) I think we could reduce significant code of USB pf. And I'll provide a second patch for this. Please forgive my ignorance. Thank you! regards, Weongyo Jeong From owner-freebsd-usb@FreeBSD.ORG Wed Nov 24 01:23:49 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 07513106564A; Wed, 24 Nov 2010 01:23:49 +0000 (UTC) (envelope-from weongyo.jeong@gmail.com) Received: from mail-vw0-f54.google.com (mail-vw0-f54.google.com [209.85.212.54]) by mx1.freebsd.org (Postfix) with ESMTP id 6ABDA8FC18; Wed, 24 Nov 2010 01:23:48 +0000 (UTC) Received: by vws9 with SMTP id 9so1776844vws.13 for ; Tue, 23 Nov 2010 17:23:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:received:from:date:to:cc :subject:message-id:reply-to:references:mime-version:content-type :content-disposition:content-transfer-encoding:in-reply-to :user-agent:organization:x-operation-sytem; bh=8VS3aJoYSbgWz/5ltDU54Ub0IREYC+/f5g+RWjQ0L54=; b=Fqa4WlW+Z3E9SdHfvYs3ivBK0BF/TRrEp3z1Qe1sG72z+YWuX/n5Z43Y0p/hwmTRcn eNAYSgcBNVCEX9Zee7iRckd5U0Y+gXAkVKTdPcAZ3FucBsC1Of8I+qrCwIW6SlWySlSn YSxjuI7xWQENnYjHjCEL4n7MUely/9sqH4D+U= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:date:to:cc:subject:message-id:reply-to:references:mime-version :content-type:content-disposition:content-transfer-encoding :in-reply-to:user-agent:organization:x-operation-sytem; b=T8etsb/wcn48VdxGLlVf5+Ri6JQ9lEIGiNaoisZiU4hcUqSt3PRsz2I3FQq3qCIEj7 NGrRya4lpS2QPI66TvnKPRsu0jn5E1H259BI+duZreRafVscQGNLW7VA/xBAbnU896qe YYTipC4paO6I+I9eh8WR20g3YXH7u2skIAcdw= Received: by 10.220.180.135 with SMTP id bu7mr1119662vcb.0.1290561827186; Tue, 23 Nov 2010 17:23:47 -0800 (PST) Received: from weongyo ([174.35.1.224]) by mx.google.com with ESMTPS id j7sm1555838vcr.39.2010.11.23.17.23.44 (version=SSLv3 cipher=RC4-MD5); Tue, 23 Nov 2010 17:23:46 -0800 (PST) Received: by weongyo (sSMTP sendmail emulation); Tue, 23 Nov 2010 17:24:13 -0800 From: Weongyo Jeong Date: Tue, 23 Nov 2010 17:24:13 -0800 To: Andrew Thompson Message-ID: <20101124012413.GK92881@weongyo> References: <201011231852.40484.jkim@FreeBSD.org> <20101124001832.GI92881@weongyo> <201011231936.57818.jkim@FreeBSD.org> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.4.2.3i Organization: CDNetworks. X-Operation-Sytem: FreeBSD Cc: freebsd-usb@FreeBSD.org, Jung-uk Kim Subject: Re: [RFC] USBdump patches X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Weongyo Jeong List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Nov 2010 01:23:49 -0000 On Wed, Nov 24, 2010 at 01:59:47PM +1300, Andrew Thompson wrote: > On 24 November 2010 13:36, Jung-uk Kim wrote: > > On Tuesday 23 November 2010 07:18 pm, Weongyo Jeong wrote: > >>    - BPF was normally for ethernet frames (most operations were > >> based on mbuf including the machine filter and there were a lot of > >> assumptions the input buffer is mbuf type.  For example, handling > >> BPF_LD|BPF_W|BPF_ABS).  However the USB packet isn't like mbuf > >> style that it's just a linear buffer.  So the most important code > >> or assumption wasn't compatible. > > > > BPF can deal with linear buffer just fine.  For example, ng_bpf(4) > > does it.  Please see sys/netgraph/ng_bpf.c. > > > >>    - Just making the patch for BPF code, it looked like a trick or > >> a hack to me because I couldn't define what BPF should be. > > > > If you don't want to touch bpf.c for some reason, netgraph(4) (-> > > ng_bpf) may be an alternate solution for you. > > > >>    - I could not define BPF exactly myself that what BPF should > >> cover. I agreed with that BPF is for ethernet packet filtering but > >> could not make sure myself that BPF could cover USB packets. > > > > BPF is a generic packet filter machine, i.e., bytecode is generic > > enough for any type of data stream. > > I agree that this is the best way forward, if it can be achieved. Yes it's best. I think it could be achieved. I'll make the patch. regards, Weongyo Jeong From owner-freebsd-usb@FreeBSD.ORG Wed Nov 24 05:46:34 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 66C71106564A; Wed, 24 Nov 2010 05:46:34 +0000 (UTC) (envelope-from weongyo.jeong@gmail.com) Received: from mail-gx0-f182.google.com (mail-gx0-f182.google.com [209.85.161.182]) by mx1.freebsd.org (Postfix) with ESMTP id C25E58FC13; Wed, 24 Nov 2010 05:46:33 +0000 (UTC) Received: by gxk8 with SMTP id 8so390737gxk.13 for ; Tue, 23 Nov 2010 21:46:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:received:from:date:to:cc :subject:message-id:reply-to:references:mime-version:content-type :content-disposition:content-transfer-encoding:in-reply-to :user-agent:organization:x-operation-sytem; bh=ERRwEdNYFsl0J7rXAxyyK4QEivQFoZ72UXFF45b89RI=; b=jWdohmO36dPMQPtOrn+HRpxbN3YuT5DdOmvR/HK8BIzqs2MMnRICIpMIkn/vHLZNbB N/ACAFVZS7OtCczf+CizsxfmQM1BBTQ0ymqqa9ZXSoC+Lq22pwKsiPtcxSsepBRqFJIV 6y1erpno8yvMqZyCt1Is+CluOuQBlxGEAzp7w= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:date:to:cc:subject:message-id:reply-to:references:mime-version :content-type:content-disposition:content-transfer-encoding :in-reply-to:user-agent:organization:x-operation-sytem; b=btLX6L0o1qjfiLOkNgfH+0v1+4VTSbEKOvwz3Fx0fmgvuxwv849237itKng4QUmfBP kv029oPKLvum0kSeUr8bHC0sPrGNZKqoHHEUfwJAsqeZohVxyaf8dhGAthBmMBcao0ka Qwwn5ICKwkJCGklo4rei0nvchIlICglx3l4iQ= Received: by 10.151.7.10 with SMTP id k10mr248122ybi.222.1290577592938; Tue, 23 Nov 2010 21:46:32 -0800 (PST) Received: from weongyo ([174.35.1.224]) by mx.google.com with ESMTPS id m27sm4575778yha.29.2010.11.23.21.46.29 (version=SSLv3 cipher=RC4-MD5); Tue, 23 Nov 2010 21:46:31 -0800 (PST) Received: by weongyo (sSMTP sendmail emulation); Tue, 23 Nov 2010 21:46:59 -0800 From: Weongyo Jeong Date: Tue, 23 Nov 2010 21:46:59 -0800 To: Andrew Thompson Message-ID: <20101124054659.GL92881@weongyo> References: <201011231852.40484.jkim@FreeBSD.org> <20101124001832.GI92881@weongyo> <201011231936.57818.jkim@FreeBSD.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Pk6IbRAofICFmK5e" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.4.2.3i Organization: CDNetworks. X-Operation-Sytem: FreeBSD X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: freebsd-usb@FreeBSD.org, Jung-uk Kim Subject: Re: [RFC] USBdump patches X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Weongyo Jeong List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Nov 2010 05:46:34 -0000 --Pk6IbRAofICFmK5e Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Wed, Nov 24, 2010 at 01:59:47PM +1300, Andrew Thompson wrote: > On 24 November 2010 13:36, Jung-uk Kim wrote: > > On Tuesday 23 November 2010 07:18 pm, Weongyo Jeong wrote: > >>    - BPF was normally for ethernet frames (most operations were > >> based on mbuf including the machine filter and there were a lot of > >> assumptions the input buffer is mbuf type.  For example, handling > >> BPF_LD|BPF_W|BPF_ABS).  However the USB packet isn't like mbuf > >> style that it's just a linear buffer.  So the most important code > >> or assumption wasn't compatible. > > > > BPF can deal with linear buffer just fine.  For example, ng_bpf(4) > > does it.  Please see sys/netgraph/ng_bpf.c. > > > >>    - Just making the patch for BPF code, it looked like a trick or > >> a hack to me because I couldn't define what BPF should be. > > > > If you don't want to touch bpf.c for some reason, netgraph(4) (-> > > ng_bpf) may be an alternate solution for you. > > > >>    - I could not define BPF exactly myself that what BPF should > >> cover. I agreed with that BPF is for ethernet packet filtering but > >> could not make sure myself that BPF could cover USB packets. > > > > BPF is a generic packet filter machine, i.e., bytecode is generic > > enough for any type of data stream. > > I agree that this is the best way forward, if it can be achieved. Attached is what I really wanted to do. USB pf is greatly simplified and perfectly satisfy me. It'll fully benefit from changes of BPF code. I'll commit this version into HEAD if no objections. regards, Weongyo Jeong --Pk6IbRAofICFmK5e-- From owner-freebsd-usb@FreeBSD.ORG Wed Nov 24 06:35:32 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D32F0106564A; Wed, 24 Nov 2010 06:35:32 +0000 (UTC) (envelope-from andy@fud.org.nz) Received: from mail-ww0-f50.google.com (mail-ww0-f50.google.com [74.125.82.50]) by mx1.freebsd.org (Postfix) with ESMTP id 1A4638FC0A; Wed, 24 Nov 2010 06:35:31 +0000 (UTC) Received: by wwd20 with SMTP id 20so9189484wwd.31 for ; Tue, 23 Nov 2010 22:35:30 -0800 (PST) MIME-Version: 1.0 Received: by 10.227.142.17 with SMTP id o17mr8772462wbu.41.1290580530353; Tue, 23 Nov 2010 22:35:30 -0800 (PST) Sender: andy@fud.org.nz Received: by 10.227.146.67 with HTTP; Tue, 23 Nov 2010 22:35:30 -0800 (PST) In-Reply-To: <20101124054659.GL92881@weongyo> References: <201011231852.40484.jkim@FreeBSD.org> <20101124001832.GI92881@weongyo> <201011231936.57818.jkim@FreeBSD.org> <20101124054659.GL92881@weongyo> Date: Wed, 24 Nov 2010 19:35:30 +1300 X-Google-Sender-Auth: kTEPrDRCVrvqlsF6EIhQP_xdbOs Message-ID: From: Andrew Thompson To: Weongyo Jeong Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: freebsd-usb@freebsd.org, Jung-uk Kim Subject: Re: [RFC] USBdump patches X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Nov 2010 06:35:32 -0000 On 24 November 2010 18:46, Weongyo Jeong wrote: > On Wed, Nov 24, 2010 at 01:59:47PM +1300, Andrew Thompson wrote: >> On 24 November 2010 13:36, Jung-uk Kim wrote: >> > On Tuesday 23 November 2010 07:18 pm, Weongyo Jeong wrote: >> >> =A0 =A0- BPF was normally for ethernet frames (most operations were >> >> based on mbuf including the machine filter and there were a lot of >> >> assumptions the input buffer is mbuf type. =A0For example, handling >> >> BPF_LD|BPF_W|BPF_ABS). =A0However the USB packet isn't like mbuf >> >> style that it's just a linear buffer. =A0So the most important code >> >> or assumption wasn't compatible. >> > >> > BPF can deal with linear buffer just fine. =A0For example, ng_bpf(4) >> > does it. =A0Please see sys/netgraph/ng_bpf.c. >> > >> >> =A0 =A0- Just making the patch for BPF code, it looked like a trick o= r >> >> a hack to me because I couldn't define what BPF should be. >> > >> > If you don't want to touch bpf.c for some reason, netgraph(4) (-> >> > ng_bpf) may be an alternate solution for you. >> > >> >> =A0 =A0- I could not define BPF exactly myself that what BPF should >> >> cover. I agreed with that BPF is for ethernet packet filtering but >> >> could not make sure myself that BPF could cover USB packets. >> > >> > BPF is a generic packet filter machine, i.e., bytecode is generic >> > enough for any type of data stream. >> >> I agree that this is the best way forward, if it can be achieved. > > Attached is what I really wanted to do. =A0USB pf is greatly simplified > and perfectly satisfy me. =A0It'll fully benefit from changes of BPF code= . > > I'll commit this version into HEAD if no objections. Looks good. Is this compatible with the wireshark pcap format? Andrew From owner-freebsd-usb@FreeBSD.ORG Wed Nov 24 07:48:16 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 572971065672; Wed, 24 Nov 2010 07:48:16 +0000 (UTC) (envelope-from hselasky@c2i.net) Received: from swip.net (mailfe01.c2i.net [212.247.154.2]) by mx1.freebsd.org (Postfix) with ESMTP id 2341E8FC14; Wed, 24 Nov 2010 07:48:14 +0000 (UTC) X-Cloudmark-Score: 0.000000 [] X-Cloudmark-Analysis: v=1.1 cv=omSrwDgyMf70S47Fr5SNr0rQzcmIOo0IafWlB/wSLLo= c=1 sm=1 a=8nJEP1OIZ-IA:10 a=CL8lFSKtTFcA:10 a=i9M/sDlu2rpZ9XS819oYzg==:17 a=H2kbW76CCrRkqfbJtkEA:9 a=53qomvQOeuqg4SESCM0A:7 a=j3yvkjYWhmW8eml3-1t4C3UAVl8A:4 a=wPNLvfGTeEIA:10 a=KmmMOgcckWkV5R1e:21 a=hqvrXj6X0W2ftIpt:21 a=i9M/sDlu2rpZ9XS819oYzg==:117 Received: from [188.126.198.129] (account mc467741@c2i.net HELO laptop002.hselasky.homeunix.org) by mailfe01.swip.net (CommuniGate Pro SMTP 5.2.19) with ESMTPA id 53694218; Wed, 24 Nov 2010 08:48:12 +0100 From: Hans Petter Selasky To: Weongyo Jeong Date: Wed, 24 Nov 2010 08:48:58 +0100 User-Agent: KMail/1.13.5 (FreeBSD/8.1-STABLE; KDE/4.4.5; amd64; ; ) References: <201011231852.40484.jkim@FreeBSD.org> <20101124001832.GI92881@weongyo> In-Reply-To: <20101124001832.GI92881@weongyo> X-Face: +~\`s("[*|O,="7?X@L.elg*F"OA\I/3%^p8g?ab%RN'(; _IjlA: hGE..Ew, XAQ*o#\/M~SC=S1-f9{EzRfT'|Hhll5Q]ha5Bt-s|oTlKMusi:1e[wJl}kd}GR Z0adGx-x_0zGbZj'e(Y[(UNle~)8CQWXW@:DX+9)_YlB[tIccCPN$7/L' MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201011240848.58463.hselasky@c2i.net> Cc: freebsd-usb@freebsd.org, Jung-uk Kim Subject: Re: [RFC] USBdump patches X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Nov 2010 07:48:16 -0000 On Wednesday 24 November 2010 01:18:32 Weongyo Jeong wrote: > On Tue, Nov 23, 2010 at 06:52:36PM -0500, Jung-uk Kim wrote: > > On Tuesday 23 November 2010 06:31 pm, Jung-uk Kim wrote: > > > [CC sanitized] > > > > > > On Tuesday 23 November 2010 06:01 pm, Hans Petter Selasky wrote: > > > > Dear Weongyo, > > > > > > > > > NACK. You already could recognize that the patch is quite big > > > > > and multiple patches are mixed into one. Please separate into > > > > > smallest pieces then send freebsd-usb@ again. I don't want to > > > > > do a jumbo jump. > > > > Technically, I don't like the copy-and-pasted code from bpf.c and > > bpf_filter.c. Was it really necessary? Is the dump file in PCAP > > format? > > > > Please enlighten me if I missed something. > > The following paragraph is extracted from email I sent to rwatson@ > because he also asked same question to me. And I added CC to > freebsd-usb@ to share my story with other developers who might think > similar. Hi, > > Hello Roberts, > > I understand what you're worry and agree with you that if I could remove > this duplication it'd be best one. I think it could be happen enough > later if we could reach the consensus. > > The biggest confusions I encountered during implementing? (porting) it > for USB packet filter were as follows. Please let me know if there are > something I missed: > > - BPF was normally for ethernet frames (most operations were based on > mbuf including the machine filter and there were a lot of > assumptions the input buffer is mbuf type. For example, handling > BPF_LD|BPF_W|BPF_ABS). However the USB packet isn't like mbuf style > that it's just a linear buffer. So the most important code or > assumption wasn't compatible. The equivalent to mbufs in USB terms are page caches. Where mbuf references are used pc's should be used instead. > - Just making the patch for BPF code, it looked like a trick or a hack > to me because I couldn't define what BPF should be. I think that to be really useful the BPF code needs some additional information through additional misc. instructions to orientate about the data it is getting from USB. For example the frame number, state for control transfers and endpoint number. > - I could not define BPF exactly myself that what BPF should cover. > I agreed with that BPF is for ethernet packet filtering but could > not make sure myself that BPF could cover USB packets. I think this is a good idea, but it needs some adoption. For example not all USB packets have a fixed header. But in case of mass storage there is a fixed header where we could add trigger fields. > Please tell me your opinion if you guys have better approach. --HPS From owner-freebsd-usb@FreeBSD.ORG Wed Nov 24 08:04:44 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 26BFC1065672; Wed, 24 Nov 2010 08:04:44 +0000 (UTC) (envelope-from hselasky@c2i.net) Received: from swip.net (mailfe01.c2i.net [212.247.154.2]) by mx1.freebsd.org (Postfix) with ESMTP id 1E6998FC0C; Wed, 24 Nov 2010 08:04:42 +0000 (UTC) X-Cloudmark-Score: 0.000000 [] X-Cloudmark-Analysis: v=1.1 cv=omSrwDgyMf70S47Fr5SNr0rQzcmIOo0IafWlB/wSLLo= c=1 sm=1 a=8nJEP1OIZ-IA:10 a=CL8lFSKtTFcA:10 a=i9M/sDlu2rpZ9XS819oYzg==:17 a=pGLkceISAAAA:8 a=6I5d2MoRAAAA:8 a=B0GTDe5DdRcSPBvPNw0A:9 a=hF6JhM7GM2wjaf0KoIsA:7 a=oR3ofNzb4A0HifhHvj_FUNAm8xkA:4 a=wPNLvfGTeEIA:10 a=MSl-tDqOz04A:10 a=SV7veod9ZcQA:10 a=1JPyhn8fX9h5KmoN:21 a=byVP6iE8OTHqx98H:21 a=i9M/sDlu2rpZ9XS819oYzg==:117 Received: from [188.126.198.129] (account mc467741@c2i.net HELO laptop002.hselasky.homeunix.org) by mailfe01.swip.net (CommuniGate Pro SMTP 5.2.19) with ESMTPA id 53701353; Wed, 24 Nov 2010 09:04:41 +0100 From: Hans Petter Selasky To: Andrew Thompson Date: Wed, 24 Nov 2010 09:05:28 +0100 User-Agent: KMail/1.13.5 (FreeBSD/8.1-STABLE; KDE/4.4.5; amd64; ; ) References: <20101124054659.GL92881@weongyo> In-Reply-To: X-Face: +~\`s("[*|O,="7?X@L.elg*F"OA\I/3%^p8g?ab%RN'( =?iso-8859-1?q?=3B=5FIjlA=3A=0A=09hGE=2E=2EEw?=, =?iso-8859-1?q?XAQ*o=23=5C/M=7ESC=3DS1-f9=7BEzRfT=27=7CHhll5Q=5Dha5Bt-s=7Co?= =?iso-8859-1?q?TlKMusi=3A1e=5BwJl=7Dkd=7DGR=0A=09Z0adGx-x=5F0zGbZj=27e?=(Y[(UNle~)8CQWXW@:DX+9)_YlB[tIccCPN$7/L' MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201011240905.28307.hselasky@c2i.net> Cc: Weongyo Jeong , freebsd-usb@freebsd.org, Jung-uk Kim Subject: Re: [RFC] USBdump patches X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Nov 2010 08:04:44 -0000 On Wednesday 24 November 2010 07:35:30 Andrew Thompson wrote: > On 24 November 2010 18:46, Weongyo Jeong wrote: > > On Wed, Nov 24, 2010 at 01:59:47PM +1300, Andrew Thompson wrote: > >> On 24 November 2010 13:36, Jung-uk Kim wrote: > >> > On Tuesday 23 November 2010 07:18 pm, Weongyo Jeong wrote: > >> >> - BPF was normally for ethernet frames (most operations were > >> >> based on mbuf including the machine filter and there were a lot of > >> >> assumptions the input buffer is mbuf type. For example, handling > >> >> BPF_LD|BPF_W|BPF_ABS). However the USB packet isn't like mbuf > >> >> style that it's just a linear buffer. So the most important code > >> >> or assumption wasn't compatible. > >> > > >> > BPF can deal with linear buffer just fine. For example, ng_bpf(4) > >> > does it. Please see sys/netgraph/ng_bpf.c. > >> > > >> >> - Just making the patch for BPF code, it looked like a trick or > >> >> a hack to me because I couldn't define what BPF should be. > >> > > >> > If you don't want to touch bpf.c for some reason, netgraph(4) (-> > >> > ng_bpf) may be an alternate solution for you. > >> > > >> >> - I could not define BPF exactly myself that what BPF should > >> >> cover. I agreed with that BPF is for ethernet packet filtering but > >> >> could not make sure myself that BPF could cover USB packets. > >> > > >> > BPF is a generic packet filter machine, i.e., bytecode is generic > >> > enough for any type of data stream. > >> > >> I agree that this is the best way forward, if it can be achieved. > > > > Attached is what I really wanted to do. USB pf is greatly simplified > > and perfectly satisfy me. It'll fully benefit from changes of BPF code. > > > > I'll commit this version into HEAD if no objections. > > Looks good. Is this compatible with the wireshark pcap format? Hi, To avoid that extra copy of all the data into a linear buffer before the PF- code is run, I think you should look more carefully at my last released patch. Probably what we need is a special function that can tap "struct usb_page_cache *" with a offset and a length. We can probably do this in a similar fashion as to this: #if USB_HAVE_MBUF struct usb_m_copy_in_arg { struct usb_page_cache *cache; usb_frlength_t dst_offset; }; static int usbd_m_copy_in_cb(void *arg, void *src, uint32_t count) { register struct usb_m_copy_in_arg *ua = arg; usbd_copy_in(ua->cache, ua->dst_offset, src, count); ua->dst_offset += count; return (0); } void usbd_m_copy_in(struct usb_page_cache *cache, usb_frlength_t dst_offset, struct mbuf *m, usb_size_t src_offset, usb_frlength_t src_len) { struct usb_m_copy_in_arg arg = {cache, dst_offset}; int error; error = m_apply(m, src_offset, src_len, &usbd_m_copy_in_cb, &arg); } #endif So I would suggest a function like this: bpf_tap_apply(bus->ifp, src_offset, src_len, usbd_m_copy_in_cb, &arg); But USB-PF would also require some additional information, which I'm not sure where to put. Please have a look at my patch posted to freebsd-usb yesterday. Reference: @@ -1778,7 +187,7 @@ usbpf_xfertap(struct usb_xfer *xfer, int type) * read filter to pass a virtually linear buffer. */ buf = ptr = malloc(sizeof(struct usbpf_pkthdr) + (USB_PAGE_SIZE * 5), - M_USBPF, M_NOWAIT); + M_TEMP, M_NOWAIT); if (buf == NULL) { printf("usbpf_xfertap: out of memory\n"); /* XXX */ return; @@ -1828,49 +237,7 @@ usbpf_xfertap(struct usb_xfer *xfer, int type) ptr += xfer->frlengths[i]; } - usbpf_tap(bus->uif, buf, ptr - buf); + bpf_tap(bus->ifp->if_bpf, buf, ptr - buf); done: - free(buf, M_USBPF); + free(buf, M_TEMP); } --HPS From owner-freebsd-usb@FreeBSD.ORG Wed Nov 24 08:39:40 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 52257106564A; Wed, 24 Nov 2010 08:39:40 +0000 (UTC) (envelope-from hselasky@c2i.net) Received: from swip.net (mailfe05.c2i.net [212.247.154.130]) by mx1.freebsd.org (Postfix) with ESMTP id 57E4F8FC18; Wed, 24 Nov 2010 08:39:38 +0000 (UTC) X-Cloudmark-Score: 0.000000 [] X-Cloudmark-Analysis: v=1.1 cv=5OBHFxb9I47YZ7HELXzI6cL6pwPTRnd5uxbD1DPQ4WY= c=1 sm=1 a=8nJEP1OIZ-IA:10 a=CL8lFSKtTFcA:10 a=i9M/sDlu2rpZ9XS819oYzg==:17 a=_PsO0DgB1mCPU-CRcHEA:9 a=yqmR9SbAUAPz11acFgDhiq5XVaoA:4 a=wPNLvfGTeEIA:10 a=APlzIhDOvauD0obv:21 a=t0EVy8ukcCl6QuDH:21 a=i9M/sDlu2rpZ9XS819oYzg==:117 Received: from [188.126.198.129] (account mc467741@c2i.net HELO laptop002.hselasky.homeunix.org) by mailfe05.swip.net (CommuniGate Pro SMTP 5.2.19) with ESMTPA id 52437270; Wed, 24 Nov 2010 09:39:37 +0100 From: Hans Petter Selasky To: Weongyo Jeong Date: Wed, 24 Nov 2010 09:40:24 +0100 User-Agent: KMail/1.13.5 (FreeBSD/8.1-STABLE; KDE/4.4.5; amd64; ; ) References: <20101124001832.GI92881@weongyo> <201011240848.58463.hselasky@c2i.net> In-Reply-To: <201011240848.58463.hselasky@c2i.net> X-Face: +~\`s("[*|O,="7?X@L.elg*F"OA\I/3%^p8g?ab%RN'( =?iso-8859-1?q?=3B=5FIjlA=3A=0A=09hGE=2E=2EEw?=, =?iso-8859-1?q?XAQ*o=23=5C/M=7ESC=3DS1-f9=7BEzRfT=27=7CHhll5Q=5Dha5Bt-s=7Co?= =?iso-8859-1?q?TlKMusi=3A1e=5BwJl=7Dkd=7DGR=0A=09Z0adGx-x=5F0zGbZj=27e?=(Y[(UNle~)8CQWXW@:DX+9)_YlB[tIccCPN$7/L' MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201011240940.24333.hselasky@c2i.net> Cc: freebsd-usb@freebsd.org, Jung-uk Kim Subject: Re: [RFC] USBdump patches X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Nov 2010 08:39:40 -0000 On Wednesday 24 November 2010 08:48:58 Hans Petter Selasky wrote: > I think that to be really useful the BPF code needs some additional > information through additional misc. instructions to orientate about the > data it is getting from USB. For example the frame number, state for > control transfers and endpoint number. Another idea is to prepend this information into a fixed sized header which is "virtually" prepended to the data. --HPS From owner-freebsd-usb@FreeBSD.ORG Wed Nov 24 12:34:09 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6F1A31065674; Wed, 24 Nov 2010 12:34:09 +0000 (UTC) (envelope-from alexander@leidinger.net) Received: from mail.ebusiness-leidinger.de (mail.ebusiness-leidinger.de [217.11.53.44]) by mx1.freebsd.org (Postfix) with ESMTP id 1FA618FC0C; Wed, 24 Nov 2010 12:34:08 +0000 (UTC) Received: from outgoing.leidinger.net (p57B39C93.dip.t-dialin.net [87.179.156.147]) by mail.ebusiness-leidinger.de (Postfix) with ESMTPSA id 676BB84400F; Wed, 24 Nov 2010 13:34:04 +0100 (CET) Received: from webmail.leidinger.net (unknown [IPv6:fd73:10c7:2053:1::2:102]) by outgoing.leidinger.net (Postfix) with ESMTP id 5925626BA; Wed, 24 Nov 2010 13:33:55 +0100 (CET) Received: (from www@localhost) by webmail.leidinger.net (8.14.4/8.13.8/Submit) id oAOCXnnh092304; Wed, 24 Nov 2010 13:33:49 +0100 (CET) (envelope-from Alexander@Leidinger.net) Received: from pslux.ec.europa.eu (pslux.ec.europa.eu [158.169.9.14]) by webmail.leidinger.net (Horde Framework) with HTTP; Wed, 24 Nov 2010 13:33:49 +0100 Message-ID: <20101124133349.50601j0a0ywpbx8g@webmail.leidinger.net> Date: Wed, 24 Nov 2010 13:33:49 +0100 From: Alexander Leidinger To: Alexander Leidinger References: <20101102103208.45064dxs60sp833w@webmail.leidinger.net> <201011021036.41617.hselasky@freebsd.org> <20101105154156.12764ne6zf5rahs0@webmail.leidinger.net> In-Reply-To: <20101105154156.12764ne6zf5rahs0@webmail.leidinger.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; DelSp="Yes"; format="flowed" Content-Disposition: inline Content-Transfer-Encoding: 7bit User-Agent: Dynamic Internet Messaging Program (DIMP) H3 (1.1.4) X-EBL-MailScanner-Information: Please contact the ISP for more information X-EBL-MailScanner-ID: 676BB84400F.A2F89 X-EBL-MailScanner: Found to be clean X-EBL-MailScanner-SpamCheck: not spam, spamhaus-ZEN, SpamAssassin (not cached, score=1.274, required 6, autolearn=disabled, RDNS_NONE 1.27) X-EBL-MailScanner-SpamScore: s X-EBL-MailScanner-From: alexander@leidinger.net X-EBL-MailScanner-Watermark: 1291206846.22862@QSp6ixkad1DDkNTrLRPwiw X-EBL-Spam-Status: No Cc: Alexander Motin , Hans Petter Selasky , freebsd-usb@freebsd.org Subject: Re: usbconfig reset ugen4.2 hanging since an hour X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Nov 2010 12:34:09 -0000 Quoting Alexander Leidinger (from Fri, 05 Nov 2010 15:41:56 +0100): > I do not know yet if this is because of failed hardware, or because > of a problem in the USB stack. As the first traces of this appeared > after an update, I lean towards a regression... > > I will have a look at getting some time to update the older FreeBSD > 9 system to something in between the working and not working version. After a lot of testing with 2 machines I'm now at a state where I think the EHCI part of the mainboard is not far away of stopping working completely. So far the UHCI ports seem to still work correctly. Does someone know if EHCI and UHCI in an ICH5 chipset are separate parts of the chip, or are they sharing common USB parts? Depending on the answer I should maybe raise the priority of the replacement of this... Bye, Alexander. -- Q: Have you heard about the man who didn't pay for his exorcism? A: He got re-possessed! http://www.Leidinger.net Alexander @ Leidinger.net: PGP ID = B0063FE7 http://www.FreeBSD.org netchild @ FreeBSD.org : PGP ID = 72077137 From owner-freebsd-usb@FreeBSD.ORG Wed Nov 24 18:54:14 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 12864106566C; Wed, 24 Nov 2010 18:54:14 +0000 (UTC) (envelope-from weongyo.jeong@gmail.com) Received: from mail-fx0-f54.google.com (mail-fx0-f54.google.com [209.85.161.54]) by mx1.freebsd.org (Postfix) with ESMTP id 327938FC0A; Wed, 24 Nov 2010 18:54:12 +0000 (UTC) Received: by fxm19 with SMTP id 19so63119fxm.13 for ; Wed, 24 Nov 2010 10:54:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:received:from:date:to:cc :subject:message-id:reply-to:references:mime-version:content-type :content-disposition:content-transfer-encoding:in-reply-to :user-agent:organization:x-operation-sytem; bh=Jc8pmiF4ZHxyJXck3AR7b+Thmj+vpwUhp03VoQXncjg=; b=Z4fnPngfg/HZJ26/QYX42QQq+J2ZpjMQZcrvd3vdRHc9/ATkoBBteXaI2fZTzyJiie FqymNGW58JyMQoLkK9IIAPWIgDnufrJBjx1FEXfPiYjmOcNvz3ZOqYaZmvPcFg1pGov7 RjOC3CGPJ6p33MjYr5VunFdARb4ydyHLXErxo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:date:to:cc:subject:message-id:reply-to:references:mime-version :content-type:content-disposition:content-transfer-encoding :in-reply-to:user-agent:organization:x-operation-sytem; b=BX6DCDUuG/6f1nn6KB6ymqmkY++Ds7tF1u24d3qxkkH9BtlNAp5V3pLQIGtYLdw9W6 zViUPKHt04CWozF63RPvQCN5C4+VVriq/qT/B2PfEuNc15iV93d68PstEagc6DM2nT8L 3zOnGbpNI8WjHtmudZJIBmp1mHbJi2glj6LcM= Received: by 10.223.120.84 with SMTP id c20mr1810875far.102.1290624851964; Wed, 24 Nov 2010 10:54:11 -0800 (PST) Received: from weongyo ([174.35.1.224]) by mx.google.com with ESMTPS id c11sm1411673fav.26.2010.11.24.10.54.08 (version=SSLv3 cipher=RC4-MD5); Wed, 24 Nov 2010 10:54:10 -0800 (PST) Received: by weongyo (sSMTP sendmail emulation); Wed, 24 Nov 2010 10:54:38 -0800 From: Weongyo Jeong Date: Wed, 24 Nov 2010 10:54:38 -0800 To: Andrew Thompson Message-ID: <20101124185438.GM92881@weongyo> References: <201011231852.40484.jkim@FreeBSD.org> <20101124001832.GI92881@weongyo> <201011231936.57818.jkim@FreeBSD.org> <20101124054659.GL92881@weongyo> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.4.2.3i Organization: CDNetworks. X-Operation-Sytem: FreeBSD Cc: freebsd-usb@FreeBSD.org, Jung-uk Kim Subject: Re: [RFC] USBdump patches X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Weongyo Jeong List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Nov 2010 18:54:14 -0000 On Wed, Nov 24, 2010 at 07:35:30PM +1300, Andrew Thompson wrote: > On 24 November 2010 18:46, Weongyo Jeong wrote: > > On Wed, Nov 24, 2010 at 01:59:47PM +1300, Andrew Thompson wrote: > >> On 24 November 2010 13:36, Jung-uk Kim wrote: > >> > On Tuesday 23 November 2010 07:18 pm, Weongyo Jeong wrote: > >> >>    - BPF was normally for ethernet frames (most operations were > >> >> based on mbuf including the machine filter and there were a lot of > >> >> assumptions the input buffer is mbuf type.  For example, handling > >> >> BPF_LD|BPF_W|BPF_ABS).  However the USB packet isn't like mbuf > >> >> style that it's just a linear buffer.  So the most important code > >> >> or assumption wasn't compatible. > >> > > >> > BPF can deal with linear buffer just fine.  For example, ng_bpf(4) > >> > does it.  Please see sys/netgraph/ng_bpf.c. > >> > > >> >>    - Just making the patch for BPF code, it looked like a trick or > >> >> a hack to me because I couldn't define what BPF should be. > >> > > >> > If you don't want to touch bpf.c for some reason, netgraph(4) (-> > >> > ng_bpf) may be an alternate solution for you. > >> > > >> >>    - I could not define BPF exactly myself that what BPF should > >> >> cover. I agreed with that BPF is for ethernet packet filtering but > >> >> could not make sure myself that BPF could cover USB packets. > >> > > >> > BPF is a generic packet filter machine, i.e., bytecode is generic > >> > enough for any type of data stream. > >> > >> I agree that this is the best way forward, if it can be achieved. > > > > Attached is what I really wanted to do.  USB pf is greatly simplified > > and perfectly satisfy me.  It'll fully benefit from changes of BPF code. > > > > I'll commit this version into HEAD if no objections. > > Looks good. Is this compatible with the wireshark pcap format? Not yet. I think it could happen soon. regards, Weongyo Jeong From owner-freebsd-usb@FreeBSD.ORG Thu Nov 25 03:11:27 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 41CD41065672 for ; Thu, 25 Nov 2010 03:11:27 +0000 (UTC) (envelope-from misc@nezmer.info) Received: from mail.nezmer.info (nezmer.info [97.107.142.36]) by mx1.freebsd.org (Postfix) with ESMTP id 1E7238FC12 for ; Thu, 25 Nov 2010 03:11:26 +0000 (UTC) Date: Thu, 25 Nov 2010 04:55:26 +0200 From: Nezmer To: freebsd-usb@freebsd.org Message-ID: <20101125025526.GA2772@mail> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Subject: External usb HDD disconnects, system gets messed up X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Nov 2010 03:11:27 -0000 Hi, FreeBSD 8.1-STABLE r215402M GENERIC amd64 I'm having a weird issue. I have a 300GB external usb HDD with one ext2 partition. I use ZFS for my internal HDD. Almost daily, The usb HDD disconnects(according to dmesg) and the system gets messed up. Running processes keep responding but they would not exit. And no new processes would start running. I eventually would have to hard reset and run fsck.ext2 on the next run. Any idea what's going on? Do you need any specific information? From owner-freebsd-usb@FreeBSD.ORG Thu Nov 25 07:42:19 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9718B106567A for ; Thu, 25 Nov 2010 07:42:19 +0000 (UTC) (envelope-from peterjeremy@acm.org) Received: from fallbackmx10.syd.optusnet.com.au (fallbackmx10.syd.optusnet.com.au [211.29.132.251]) by mx1.freebsd.org (Postfix) with ESMTP id 22E048FC0C for ; Thu, 25 Nov 2010 07:42:18 +0000 (UTC) Received: from mail14.syd.optusnet.com.au (mail14.syd.optusnet.com.au [211.29.132.195]) by fallbackmx10.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id oAP3gZgE006144 for ; Thu, 25 Nov 2010 14:42:35 +1100 Received: from server.vk2pj.dyndns.org (c220-239-116-103.belrs4.nsw.optusnet.com.au [220.239.116.103]) by mail14.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id oAP3gVm6017457 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 25 Nov 2010 14:42:32 +1100 X-Bogosity: Ham, spamicity=0.000000 Received: from server.vk2pj.dyndns.org (localhost.vk2pj.dyndns.org [127.0.0.1]) by server.vk2pj.dyndns.org (8.14.4/8.14.4) with ESMTP id oAP3gUP1096586 for ; Thu, 25 Nov 2010 14:42:30 +1100 (EST) (envelope-from peter@server.vk2pj.dyndns.org) Received: (from peter@localhost) by server.vk2pj.dyndns.org (8.14.4/8.14.4/Submit) id oAP3gUQ2096585 for freebsd-usb@freebsd.org; Thu, 25 Nov 2010 14:42:30 +1100 (EST) (envelope-from peter) Date: Thu, 25 Nov 2010 14:42:30 +1100 From: Peter Jeremy To: freebsd-usb@freebsd.org Message-ID: <20101125034230.GA89666@server.vk2pj.dyndns.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="7JfCtLOvnd9MIVvH" Content-Disposition: inline X-PGP-Key: http://members.optusnet.com.au/peterjeremy/pubkey.asc User-Agent: Mutt/1.5.20 (2009-06-14) Subject: Multimedia keys on Dell SK-8135 X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Nov 2010 07:42:19 -0000 --7JfCtLOvnd9MIVvH Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable I have a Dell SK-8135 keyboard which has multimedia keys in addition to the normal PC105 keyboard. As far as I can tell (by setting hw.usb.debug, hw.usb.ugen.debug, hw.usb.uhid.debug and hw.usb.ukbd.debug), the keys aren't generating any output. I've done some searching and it looks like some people have had sucess getting the keys to work, at least on Linux, though it's not clear how. Can anyone help? The keyboard includes an integrated hub and I have my mouse plugged into it. I'm running FreeBSD-8.1/amd64 Relevant output: dmesg: ugen0.2: at usbus0 uhub6: on usbus0 uhub6: 3 ports with 2 removable, bus powered ugen0.3: at usbus0 ukbd0: on usbus0 kbd0 at ukbd0 uhid0: on usbus0 ugen0.4: at usbus0 ums0: on u= sbus0 ums0: 3 buttons and [XYZ] coordinates ID=3D0 $ usbconfig ugen0.1: at usbus0, cfg=3D0 md=3DHOST spd=3DFULL (12M= bps) pwr=3DON ugen1.1: at usbus1, cfg=3D0 md=3DHOST spd=3DFULL (12M= bps) pwr=3DON ugen2.1: at usbus2, cfg=3D0 md=3DHOST spd=3DFULL (12M= bps) pwr=3DON ugen3.1: at usbus3, cfg=3D0 md=3DHOST spd=3DFULL (12M= bps) pwr=3DON ugen4.1: at usbus4, cfg=3D0 md=3DHOST spd=3DHIGH (480= Mbps) pwr=3DON ugen4.2: at usbus4, cfg=3D0 md=3DHO= ST spd=3DHIGH (480Mbps) pwr=3DSAVE ugen0.2: at usbus0, cfg=3D0 md=3DHOST spd=3DFU= LL (12Mbps) pwr=3DSAVE ugen0.3: at usbus0, cfg=3D0 md=3DHOST spd=3DFULL (= 12Mbps) pwr=3DON ugen0.4: at usbus0, cfg=3D0 md=3DHOST spd=3D= LOW (1.5Mbps) pwr=3DON $ usbconfig -u 0 -a 3 dump_device_desc ugen0.3: at usbus0, cfg=3D0 md=3DHOST spd=3DFULL (= 12Mbps) pwr=3DON bLength =3D 0x0012=20 bDescriptorType =3D 0x0001=20 bcdUSB =3D 0x0110=20 bDeviceClass =3D 0x0000=20 bDeviceSubClass =3D 0x0000=20 bDeviceProtocol =3D 0x0000=20 bMaxPacketSize0 =3D 0x0008=20 idVendor =3D 0x413c=20 idProduct =3D 0x2010=20 bcdDevice =3D 0x0200=20 iManufacturer =3D 0x0001 iProduct =3D 0x0003 iSerialNumber =3D 0x0000 bNumConfigurations =3D 0x0001=20 $ usbconfig -u 0 -a 3 dump_curr_config_desc ugen0.3: at usbus0, cfg=3D0 md=3DHOST spd=3DFULL (= 12Mbps) pwr=3DON Configuration index 0 bLength =3D 0x0009=20 bDescriptorType =3D 0x0002=20 wTotalLength =3D 0x003b=20 bNumInterfaces =3D 0x0002=20 bConfigurationValue =3D 0x0001=20 iConfiguration =3D 0x0003 bmAttributes =3D 0x00a0=20 bMaxPower =3D 0x0019=20 Interface 0 bLength =3D 0x0009=20 bDescriptorType =3D 0x0004=20 bInterfaceNumber =3D 0x0000=20 bAlternateSetting =3D 0x0000=20 bNumEndpoints =3D 0x0001=20 bInterfaceClass =3D 0x0003=20 bInterfaceSubClass =3D 0x0001=20 bInterfaceProtocol =3D 0x0001=20 iInterface =3D 0x0003 Additional Descriptor bLength =3D 0x09 bDescriptorType =3D 0x21 bDescriptorSubType =3D 0x10 RAW dump:=20 0x00 | 0x09, 0x21, 0x10, 0x01, 0x00, 0x01, 0x22, 0x41,=20 0x08 | 0x00 Endpoint 0 bLength =3D 0x0007=20 bDescriptorType =3D 0x0005=20 bEndpointAddress =3D 0x0081 bmAttributes =3D 0x0003 wMaxPacketSize =3D 0x0008=20 bInterval =3D 0x000a=20 bRefresh =3D 0x0000=20 bSynchAddress =3D 0x0000=20 Interface 1 bLength =3D 0x0009=20 bDescriptorType =3D 0x0004=20 bInterfaceNumber =3D 0x0001=20 bAlternateSetting =3D 0x0000=20 bNumEndpoints =3D 0x0001=20 bInterfaceClass =3D 0x0003=20 bInterfaceSubClass =3D 0x0000=20 bInterfaceProtocol =3D 0x0000=20 iInterface =3D 0x0003 Additional Descriptor bLength =3D 0x09 bDescriptorType =3D 0x21 bDescriptorSubType =3D 0x10 RAW dump:=20 0x00 | 0x09, 0x21, 0x10, 0x01, 0x00, 0x01, 0x22, 0x8e,=20 0x08 | 0x00 Endpoint 0 bLength =3D 0x0007=20 bDescriptorType =3D 0x0005=20 bEndpointAddress =3D 0x0082 bmAttributes =3D 0x0003 wMaxPacketSize =3D 0x0004=20 bInterval =3D 0x00ff=20 bRefresh =3D 0x0000=20 bSynchAddress =3D 0x0000=20 --=20 Peter Jeremy --7JfCtLOvnd9MIVvH Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.15 (FreeBSD) iEYEARECAAYFAkzt2yYACgkQ/opHv/APuIdUlACgjfNX1mChr2AvaE24qRM4vrz/ D7IAoL3QpdVdAOLuqrLTTGaKK8D/bybh =4akw -----END PGP SIGNATURE----- --7JfCtLOvnd9MIVvH-- From owner-freebsd-usb@FreeBSD.ORG Thu Nov 25 08:37:32 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6B5791065670 for ; Thu, 25 Nov 2010 08:37:32 +0000 (UTC) (envelope-from hselasky@c2i.net) Received: from swip.net (mailfe02.c2i.net [212.247.154.34]) by mx1.freebsd.org (Postfix) with ESMTP id CE16D8FC20 for ; Thu, 25 Nov 2010 08:37:31 +0000 (UTC) X-Cloudmark-Score: 0.000000 [] X-Cloudmark-Analysis: v=1.1 cv=yevn+QCjI6xy199BDvBOOiO14qYvyLq62he9tTtU3M8= c=1 sm=1 a=s7G_MHeCTl8A:10 a=Q9fys5e9bTEA:10 a=CL8lFSKtTFcA:10 a=i9M/sDlu2rpZ9XS819oYzg==:17 a=6I5d2MoRAAAA:8 a=esaPwiBamq2h-7CKMe0A:9 a=BWVfn9rA29TJTbiGIFUIP_g75z4A:4 a=PUjeQqilurYA:10 a=i9M/sDlu2rpZ9XS819oYzg==:117 Received: from [188.126.198.129] (account mc467741@c2i.net HELO laptop002.hselasky.homeunix.org) by mailfe02.swip.net (CommuniGate Pro SMTP 5.2.19) with ESMTPA id 53543018; Thu, 25 Nov 2010 09:37:30 +0100 From: Hans Petter Selasky To: freebsd-usb@freebsd.org Date: Thu, 25 Nov 2010 09:38:15 +0100 User-Agent: KMail/1.13.5 (FreeBSD/8.1-STABLE; KDE/4.4.5; amd64; ; ) References: <20101125034230.GA89666@server.vk2pj.dyndns.org> In-Reply-To: <20101125034230.GA89666@server.vk2pj.dyndns.org> X-Face: +~\`s("[*|O,="7?X@L.elg*F"OA\I/3%^p8g?ab%RN'(; _IjlA: hGE..Ew, XAQ*o#\/M~SC=S1-f9{EzRfT'|Hhll5Q]ha5Bt-s|oTlKMusi:1e[wJl}kd}GR Z0adGx-x_0zGbZj'e(Y[(UNle~)8CQWXW@:DX+9)_YlB[tIccCPN$7/L' MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Message-Id: <201011250938.15470.hselasky@c2i.net> Cc: Subject: Re: Multimedia keys on Dell SK-8135 X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Nov 2010 08:37:32 -0000 On Thursday 25 November 2010 04:42:30 Peter Jeremy wrote: > I have a Dell SK-8135 keyboard which has multimedia keys in addition > to the normal PC105 keyboard. As far as I can tell (by setting > hw.usb.debug, hw.usb.ugen.debug, hw.usb.uhid.debug and > hw.usb.ukbd.debug), the keys aren't generating any output. I've done > some searching and it looks like some people have had sucess getting > the keys to work, at least on Linux, though it's not clear how. > Can anyone help? > > The keyboard includes an integrated hub and I have my mouse plugged > into it. > > I'm running FreeBSD-8.1/amd64 Have you looked at: http://wiki.freebsd.org/uhidd --HPS > > Relevant output: > > dmesg: > ugen0.2: at usbus0 > uhub6: on usbus0 > uhub6: 3 ports with 2 removable, bus powered > ugen0.3: at usbus0 > ukbd0: on usbus0 > kbd0 at ukbd0 > uhid0: on usbus0 > ugen0.4: at usbus0 > ums0: on > usbus0 ums0: 3 buttons and [XYZ] coordinates ID=0 > > $ usbconfig > ugen0.1: at usbus0, cfg=0 md=HOST spd=FULL (12Mbps) > pwr=ON ugen1.1: at usbus1, cfg=0 md=HOST spd=FULL > (12Mbps) pwr=ON ugen2.1: at usbus2, cfg=0 md=HOST > spd=FULL (12Mbps) pwr=ON ugen3.1: at usbus3, cfg=0 > md=HOST spd=FULL (12Mbps) pwr=ON ugen4.1: at usbus4, > cfg=0 md=HOST spd=HIGH (480Mbps) pwr=ON ugen4.2: NEC Corporation> at usbus4, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=SAVE > ugen0.2: at usbus0, cfg=0 md=HOST spd=FULL > (12Mbps) pwr=SAVE ugen0.3: at usbus0, cfg=0 > md=HOST spd=FULL (12Mbps) pwr=ON ugen0.4: > at usbus0, cfg=0 md=HOST spd=LOW (1.5Mbps) pwr=ON $ usbconfig -u 0 -a 3 > dump_device_desc > ugen0.3: at usbus0, cfg=0 md=HOST spd=FULL > (12Mbps) pwr=ON > > bLength = 0x0012 > bDescriptorType = 0x0001 > bcdUSB = 0x0110 > bDeviceClass = 0x0000 > bDeviceSubClass = 0x0000 > bDeviceProtocol = 0x0000 > bMaxPacketSize0 = 0x0008 > idVendor = 0x413c > idProduct = 0x2010 > bcdDevice = 0x0200 > iManufacturer = 0x0001 > iProduct = 0x0003 > iSerialNumber = 0x0000 > bNumConfigurations = 0x0001 > > $ usbconfig -u 0 -a 3 dump_curr_config_desc > ugen0.3: at usbus0, cfg=0 md=HOST spd=FULL > (12Mbps) pwr=ON > > > Configuration index 0 > > bLength = 0x0009 > bDescriptorType = 0x0002 > wTotalLength = 0x003b > bNumInterfaces = 0x0002 > bConfigurationValue = 0x0001 > iConfiguration = 0x0003 > bmAttributes = 0x00a0 > bMaxPower = 0x0019 > > Interface 0 > bLength = 0x0009 > bDescriptorType = 0x0004 > bInterfaceNumber = 0x0000 > bAlternateSetting = 0x0000 > bNumEndpoints = 0x0001 > bInterfaceClass = 0x0003 > bInterfaceSubClass = 0x0001 > bInterfaceProtocol = 0x0001 > iInterface = 0x0003 > > Additional Descriptor > > bLength = 0x09 > bDescriptorType = 0x21 > bDescriptorSubType = 0x10 > RAW dump: > 0x00 | 0x09, 0x21, 0x10, 0x01, 0x00, 0x01, 0x22, 0x41, > 0x08 | 0x00 > > Endpoint 0 > bLength = 0x0007 > bDescriptorType = 0x0005 > bEndpointAddress = 0x0081 > bmAttributes = 0x0003 > wMaxPacketSize = 0x0008 > bInterval = 0x000a > bRefresh = 0x0000 > bSynchAddress = 0x0000 > > > Interface 1 > bLength = 0x0009 > bDescriptorType = 0x0004 > bInterfaceNumber = 0x0001 > bAlternateSetting = 0x0000 > bNumEndpoints = 0x0001 > bInterfaceClass = 0x0003 > bInterfaceSubClass = 0x0000 > bInterfaceProtocol = 0x0000 > iInterface = 0x0003 > > Additional Descriptor > > bLength = 0x09 > bDescriptorType = 0x21 > bDescriptorSubType = 0x10 > RAW dump: > 0x00 | 0x09, 0x21, 0x10, 0x01, 0x00, 0x01, 0x22, 0x8e, > 0x08 | 0x00 > > Endpoint 0 > bLength = 0x0007 > bDescriptorType = 0x0005 > bEndpointAddress = 0x0082 > bmAttributes = 0x0003 > wMaxPacketSize = 0x0004 > bInterval = 0x00ff > bRefresh = 0x0000 > bSynchAddress = 0x0000 From owner-freebsd-usb@FreeBSD.ORG Thu Nov 25 08:39:38 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 44010106564A for ; Thu, 25 Nov 2010 08:39:38 +0000 (UTC) (envelope-from hselasky@c2i.net) Received: from swip.net (mailfe03.c2i.net [212.247.154.66]) by mx1.freebsd.org (Postfix) with ESMTP id B67378FC15 for ; Thu, 25 Nov 2010 08:39:35 +0000 (UTC) X-Cloudmark-Score: 0.000000 [] X-Cloudmark-Analysis: v=1.1 cv=drJD7N2WYgraSrvx4WFOmF+tWOmhzpnKhDnOdsziBzQ= c=1 sm=1 a=oxsbxpBOTrQA:10 a=8nJEP1OIZ-IA:10 a=CL8lFSKtTFcA:10 a=i9M/sDlu2rpZ9XS819oYzg==:17 a=diKPPO5FKv5czL47UHkA:9 a=xDTcEdudPwbE18CQwXBoAY_IdMAA:4 a=wPNLvfGTeEIA:10 a=i9M/sDlu2rpZ9XS819oYzg==:117 Received: from [188.126.198.129] (account mc467741@c2i.net HELO laptop002.hselasky.homeunix.org) by mailfe03.swip.net (CommuniGate Pro SMTP 5.2.19) with ESMTPA id 53806834; Thu, 25 Nov 2010 09:39:34 +0100 From: Hans Petter Selasky To: freebsd-usb@freebsd.org Date: Thu, 25 Nov 2010 09:40:19 +0100 User-Agent: KMail/1.13.5 (FreeBSD/8.1-STABLE; KDE/4.4.5; amd64; ; ) References: <20101125025526.GA2772@mail> In-Reply-To: <20101125025526.GA2772@mail> X-Face: +~\`s("[*|O,="7?X@L.elg*F"OA\I/3%^p8g?ab%RN'(; _IjlA: hGE..Ew, XAQ*o#\/M~SC=S1-f9{EzRfT'|Hhll5Q]ha5Bt-s|oTlKMusi:1e[wJl}kd}GR Z0adGx-x_0zGbZj'e(Y[(UNle~)8CQWXW@:DX+9)_YlB[tIccCPN$7/L' MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201011250940.19677.hselasky@c2i.net> Cc: Subject: Re: External usb HDD disconnects, system gets messed up X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Nov 2010 08:39:38 -0000 On Thursday 25 November 2010 03:55:26 Nezmer wrote: > Hi, > > FreeBSD 8.1-STABLE r215402M GENERIC amd64 > > I'm having a weird issue. I have a 300GB external usb HDD with one ext2 > partition. I use ZFS for my internal HDD. > > Almost daily, The usb HDD disconnects(according to dmesg) and the system > gets messed up. Running processes keep responding but they would not > exit. And no new processes would start running. I eventually would have > to hard reset and run fsck.ext2 on the next run. > > Any idea what's going on? > Do you need any specific information? Hi, When this hang happens you can try to turn on umass debugging: sysctl hw.usb.umass.debug=-1 You need this option in your kernel config or when building the umass module to enable the sysctl above: options USB_DEBUG --HPS From owner-freebsd-usb@FreeBSD.ORG Thu Nov 25 13:06:57 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3517B106566B for ; Thu, 25 Nov 2010 13:06:57 +0000 (UTC) (envelope-from ticso@cicely7.cicely.de) Received: from raven.bwct.de (raven.bwct.de [85.159.14.73]) by mx1.freebsd.org (Postfix) with ESMTP id B92E38FC0A for ; Thu, 25 Nov 2010 13:06:56 +0000 (UTC) Received: from mail.cicely.de ([10.1.1.37]) by raven.bwct.de (8.13.4/8.13.4) with ESMTP id oAPCUdxE076657 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 25 Nov 2010 13:30:39 +0100 (CET) (envelope-from ticso@cicely7.cicely.de) Received: from cicely7.cicely.de (cicely7.cicely.de [10.1.1.9]) by mail.cicely.de (8.14.4/8.14.4) with ESMTP id oAPCUJcL028568 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 25 Nov 2010 13:30:19 +0100 (CET) (envelope-from ticso@cicely7.cicely.de) Received: from cicely7.cicely.de (localhost [127.0.0.1]) by cicely7.cicely.de (8.14.2/8.14.2) with ESMTP id oAPCUIWx074151; Thu, 25 Nov 2010 13:30:18 +0100 (CET) (envelope-from ticso@cicely7.cicely.de) Received: (from ticso@localhost) by cicely7.cicely.de (8.14.2/8.14.2/Submit) id oAPCUI2e074150; Thu, 25 Nov 2010 13:30:18 +0100 (CET) (envelope-from ticso) Date: Thu, 25 Nov 2010 13:30:18 +0100 From: Bernd Walter To: freebsd-usb@freebsd.org Message-ID: <20101125123018.GS62027@cicely7.cicely.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Operating-System: FreeBSD cicely7.cicely.de 7.0-STABLE i386 User-Agent: Mutt/1.5.11 X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED=-1, BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 autolearn=unavailable version=3.3.0 X-Spam-Checker-Version: SpamAssassin 3.3.0 (2010-01-18) on spamd.cicely.de Cc: Bernd Walter Subject: selecting configuration X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: ticso@cicely.de List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Nov 2010 13:06:57 -0000 I have a USB device with two alternative configurations. After enumerating the device I need to switch the device to configuration 1 via usbconfig. Do we have any kind of support to do this automatically? -- B.Walter http://www.bwct.de Modbus/TCP Ethernet I/O Baugruppen, ARM basierte FreeBSD Rechner uvm. From owner-freebsd-usb@FreeBSD.ORG Thu Nov 25 13:36:49 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 962951065670 for ; Thu, 25 Nov 2010 13:36:49 +0000 (UTC) (envelope-from hselasky@c2i.net) Received: from swip.net (mailfe03.c2i.net [212.247.154.66]) by mx1.freebsd.org (Postfix) with ESMTP id DEF158FC13 for ; Thu, 25 Nov 2010 13:36:48 +0000 (UTC) X-Cloudmark-Score: 0.000000 [] X-Cloudmark-Analysis: v=1.1 cv=drJD7N2WYgraSrvx4WFOmF+tWOmhzpnKhDnOdsziBzQ= c=1 sm=1 a=8nJEP1OIZ-IA:10 a=CL8lFSKtTFcA:10 a=i9M/sDlu2rpZ9XS819oYzg==:17 a=bp58_WeSyKD3-SPpDtwA:9 a=suylDgjHeN47zPYVwYgdFihOyIcA:4 a=wPNLvfGTeEIA:10 a=i9M/sDlu2rpZ9XS819oYzg==:117 Received: from [188.126.198.129] (account mc467741@c2i.net HELO laptop002.hselasky.homeunix.org) by mailfe03.swip.net (CommuniGate Pro SMTP 5.2.19) with ESMTPA id 53973489; Thu, 25 Nov 2010 14:36:46 +0100 From: Hans Petter Selasky To: freebsd-usb@freebsd.org, ticso@cicely.de Date: Thu, 25 Nov 2010 14:37:31 +0100 User-Agent: KMail/1.13.5 (FreeBSD/8.1-STABLE; KDE/4.4.5; amd64; ; ) References: <20101125123018.GS62027@cicely7.cicely.de> In-Reply-To: <20101125123018.GS62027@cicely7.cicely.de> X-Face: +~\`s("[*|O,="7?X@L.elg*F"OA\I/3%^p8g?ab%RN'(; _IjlA: hGE..Ew, XAQ*o#\/M~SC=S1-f9{EzRfT'|Hhll5Q]ha5Bt-s|oTlKMusi:1e[wJl}kd}GR Z0adGx-x_0zGbZj'e(Y[(UNle~)8CQWXW@:DX+9)_YlB[tIccCPN$7/L' MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201011251437.31383.hselasky@c2i.net> Cc: Bernd Walter Subject: Re: selecting configuration X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Nov 2010 13:36:49 -0000 On Thursday 25 November 2010 13:30:18 Bernd Walter wrote: > I have a USB device with two alternative configurations. > After enumerating the device I need to switch the device to > configuration 1 via usbconfig. > Do we have any kind of support to do this automatically? Yes, see the USB quirks. UQ_CFG_INDEX_1 --HPS From owner-freebsd-usb@FreeBSD.ORG Thu Nov 25 15:51:03 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 96E13106566C for ; Thu, 25 Nov 2010 15:51:03 +0000 (UTC) (envelope-from ticso@cicely7.cicely.de) Received: from raven.bwct.de (raven.bwct.de [85.159.14.73]) by mx1.freebsd.org (Postfix) with ESMTP id 226B78FC0C for ; Thu, 25 Nov 2010 15:51:02 +0000 (UTC) Received: from mail.cicely.de ([10.1.1.37]) by raven.bwct.de (8.13.4/8.13.4) with ESMTP id oAPFp6PD084964 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 25 Nov 2010 16:51:06 +0100 (CET) (envelope-from ticso@cicely7.cicely.de) Received: from cicely7.cicely.de (cicely7.cicely.de [10.1.1.9]) by mail.cicely.de (8.14.4/8.14.4) with ESMTP id oAPFokUQ035169 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 25 Nov 2010 16:50:46 +0100 (CET) (envelope-from ticso@cicely7.cicely.de) Received: from cicely7.cicely.de (localhost [127.0.0.1]) by cicely7.cicely.de (8.14.2/8.14.2) with ESMTP id oAPFokim074991; Thu, 25 Nov 2010 16:50:46 +0100 (CET) (envelope-from ticso@cicely7.cicely.de) Received: (from ticso@localhost) by cicely7.cicely.de (8.14.2/8.14.2/Submit) id oAPFokvc074990; Thu, 25 Nov 2010 16:50:46 +0100 (CET) (envelope-from ticso) Date: Thu, 25 Nov 2010 16:50:46 +0100 From: Bernd Walter To: Hans Petter Selasky Message-ID: <20101125155045.GW62027@cicely7.cicely.de> References: <20101125123018.GS62027@cicely7.cicely.de> <201011251437.31383.hselasky@c2i.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201011251437.31383.hselasky@c2i.net> X-Operating-System: FreeBSD cicely7.cicely.de 7.0-STABLE i386 User-Agent: Mutt/1.5.11 X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED=-1, BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 autolearn=unavailable version=3.3.0 X-Spam-Checker-Version: SpamAssassin 3.3.0 (2010-01-18) on spamd.cicely.de Cc: Bernd Walter , ticso@cicely.de, freebsd-usb@freebsd.org Subject: Re: selecting configuration X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: ticso@cicely.de List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Nov 2010 15:51:03 -0000 On Thu, Nov 25, 2010 at 02:37:31PM +0100, Hans Petter Selasky wrote: > On Thursday 25 November 2010 13:30:18 Bernd Walter wrote: > > I have a USB device with two alternative configurations. > > After enumerating the device I need to switch the device to > > configuration 1 via usbconfig. > > Do we have any kind of support to do this automatically? > > Yes, see the USB quirks. > > UQ_CFG_INDEX_1 Ok - this is something to be compiled into the kernel - right? Is it possible to add a quirk with usbconfig after the device is already detected? devd won't work since it won't say anything as config 0 won't attach to any driver and ugen isn't listed there. Also the devd data would be missing the bus number. -- B.Walter http://www.bwct.de Modbus/TCP Ethernet I/O Baugruppen, ARM basierte FreeBSD Rechner uvm. From owner-freebsd-usb@FreeBSD.ORG Thu Nov 25 15:55:39 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BC463106564A for ; Thu, 25 Nov 2010 15:55:39 +0000 (UTC) (envelope-from hselasky@c2i.net) Received: from swip.net (mailfe08.c2i.net [212.247.154.226]) by mx1.freebsd.org (Postfix) with ESMTP id 4D8A88FC1A for ; Thu, 25 Nov 2010 15:55:38 +0000 (UTC) X-Cloudmark-Score: 0.000000 [] X-Cloudmark-Analysis: v=1.1 cv=4dE6tNKVm/0afO7MQGRPv7y2YwMo4emTIiDjbh74onY= c=1 sm=1 a=8nJEP1OIZ-IA:10 a=CL8lFSKtTFcA:10 a=i9M/sDlu2rpZ9XS819oYzg==:17 a=zVhf5b1Y-Qv6nhwp_NcA:9 a=I-2wTyi9SkPsPLmICI5X6ZSzRiAA:4 a=wPNLvfGTeEIA:10 a=BgdZMVEbE5UxzQAc:21 a=dLDjOws6hoXNPmAy:21 a=i9M/sDlu2rpZ9XS819oYzg==:117 Received: from [188.126.198.129] (account mc467741@c2i.net HELO laptop002.hselasky.homeunix.org) by mailfe08.swip.net (CommuniGate Pro SMTP 5.2.19) with ESMTPA id 54061225; Thu, 25 Nov 2010 16:55:37 +0100 From: Hans Petter Selasky To: ticso@cicely.de Date: Thu, 25 Nov 2010 16:56:22 +0100 User-Agent: KMail/1.13.5 (FreeBSD/8.1-STABLE; KDE/4.4.5; amd64; ; ) References: <20101125123018.GS62027@cicely7.cicely.de> <201011251437.31383.hselasky@c2i.net> <20101125155045.GW62027@cicely7.cicely.de> In-Reply-To: <20101125155045.GW62027@cicely7.cicely.de> X-Face: +~\`s("[*|O,="7?X@L.elg*F"OA\I/3%^p8g?ab%RN'(; _IjlA: hGE..Ew, XAQ*o#\/M~SC=S1-f9{EzRfT'|Hhll5Q]ha5Bt-s|oTlKMusi:1e[wJl}kd}GR Z0adGx-x_0zGbZj'e(Y[(UNle~)8CQWXW@:DX+9)_YlB[tIccCPN$7/L' MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201011251656.22246.hselasky@c2i.net> Cc: Bernd Walter , freebsd-usb@freebsd.org Subject: Re: selecting configuration X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Nov 2010 15:55:39 -0000 On Thursday 25 November 2010 16:50:46 Bernd Walter wrote: > On Thu, Nov 25, 2010 at 02:37:31PM +0100, Hans Petter Selasky wrote: > > On Thursday 25 November 2010 13:30:18 Bernd Walter wrote: > > > I have a USB device with two alternative configurations. > > > After enumerating the device I need to switch the device to > > > configuration 1 via usbconfig. > > > Do we have any kind of support to do this automatically? > > > > Yes, see the USB quirks. > > > > UQ_CFG_INDEX_1 Hi, > > Ok - this is something to be compiled into the kernel - right? > Is it possible to add a quirk with usbconfig after the device is > already detected? You can load the usb_quirk.ko. Plug the device and run: usbconfig -d x.y add_quirk At next plug the setting is remembered. > devd won't work since it won't say anything as config 0 won't > attach to any driver and ugen isn't listed there. > Also the devd data would be missing the bus number. --HPS From owner-freebsd-usb@FreeBSD.ORG Fri Nov 26 02:02:06 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4B4D71065673 for ; Fri, 26 Nov 2010 02:02:06 +0000 (UTC) (envelope-from misc@nezmer.info) Received: from mail.nezmer.info (nezmer.info [97.107.142.36]) by mx1.freebsd.org (Postfix) with ESMTP id 238348FC1F for ; Fri, 26 Nov 2010 02:02:05 +0000 (UTC) Date: Fri, 26 Nov 2010 04:01:59 +0200 From: Nezmer To: freebsd-usb@freebsd.org Message-ID: <20101126020159.GA2408@mail> References: <20101125025526.GA2772@mail> <201011250940.19677.hselasky@c2i.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201011250940.19677.hselasky@c2i.net> User-Agent: Mutt/1.5.20 (2009-06-14) Subject: Re: External usb HDD disconnects, system gets messed up X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Nov 2010 02:02:06 -0000 On Thu, Nov 25, 2010 at 09:40:19AM +0100, Hans Petter Selasky wrote: > On Thursday 25 November 2010 03:55:26 Nezmer wrote: > > Hi, > > > > FreeBSD 8.1-STABLE r215402M GENERIC amd64 > > > > I'm having a weird issue. I have a 300GB external usb HDD with one ext2 > > partition. I use ZFS for my internal HDD. > > > > Almost daily, The usb HDD disconnects(according to dmesg) and the system > > gets messed up. Running processes keep responding but they would not > > exit. And no new processes would start running. I eventually would have > > to hard reset and run fsck.ext2 on the next run. > > > > Any idea what's going on? > > Do you need any specific information? > > Hi, > > When this hang happens you can try to turn on umass debugging: > > sysctl hw.usb.umass.debug=-1 > > You need this option in your kernel config or when building the umass module > to enable the sysctl above: > > options USB_DEBUG > > --HPS Thank you for the hint. I managed to freeze the system this time. 1st, I tried to cd to a dir and got an I/O error. Here is some debug output: umass0:umass_bbb_dump_csw: CSW 208387: sig = 0x53425355 (valid), tag = 0x00032e03, res = 4096, status = 0x01 (failed) umass0:umass_t_bbb_status_callback: Command failed, residue = 4096 umass0:umass_cam_cb: Fetching 32 bytes of sense data umass0:umass_bbb_dump_cbw: CBW 208388: cmd = 6b (0x030000002000), data = 32b, lun = 0, dir = in umass0:umass_transfer_start: transfer index = 4 umass0:umass_t_bbb_data_read_callback: max_bulk=131072, data_rem=32 umass0:umass_t_bbb_data_read_callback: max_bulk=131072, data_rem=0 umass0:umass_transfer_start: transfer index = 8 umass0:umass_t_bbb_status_callback: Failed to read CSW: USB_ERR_STALLED, try 0 umass0:umass_transfer_start: transfer index = 5 umass0:umass_transfer_start: transfer index = 8 umass0:umass_bbb_dump_csw: CSW 208388: sig = 0x53425355 (valid), tag = 0x00032e04, res = 14, status = 0x00 (good) (da0:umass-sim0:0:0:0): READ(10). CDB: 28 0 0 0 30 57 0 0 8 0 (da0:umass-sim0:0:0:0): CAM status: SCSI Status Error (da0:umass-sim0:0:0:0): SCSI status: Check Condition (da0:umass-sim0:0:0:0): SCSI sense: UNIT ATTENTION asc:28,0 (Not ready to ready change, medium may have changed) umass0:umass_cam_action: 2:0:0:XPT_SCSI_IO: cmd: 0x28, flags: 0x40, 10b cmd/4096b data/32b sense umass0:umass_bbb_dump_cbw: CBW 208389: cmd = 10b (0x280000003057...), data = 4096b, lun = 0, dir = in umass0:umass_transfer_start: transfer index = 4 umass0:umass_t_bbb_data_read_callback: max_bulk=131072, data_rem=4096 umass0:umass_transfer_start: transfer index = 5 umass0:umass_transfer_start: transfer index = 8 umass0:umass_bbb_dump_csw: CSW 208389: sig = 0x53425355 (valid), tag = 0x00032e05, res = 4096, status = 0x01 (failed) umass0:umass_t_bbb_status_callback: Command failed, residue = 4096 umass0:umass_cam_cb: Fetching 32 bytes of sense data umass0:umass_bbb_dump_cbw: CBW 208390: cmd = 6b (0x030000002000), data = 32b, lun = 0, dir = in umass0:umass_transfer_start: transfer index = 4 umass0:umass_t_bbb_data_read_callback: max_bulk=131072, data_rem=32 umass0:umass_t_bbb_data_read_callback: max_bulk=131072, data_rem=0 umass0:umass_transfer_start: transfer index = 8 umass0:umass_t_bbb_status_callback: Failed to read CSW: USB_ERR_STALLED, try 0 umass0:umass_transfer_start: transfer index = 5 umass0:umass_transfer_start: transfer index = 8 umass0:umass_bbb_dump_csw: CSW 208390: sig = 0x53425355 (valid), tag = 0x00032e06, res = 14, status = 0x00 (good) (da0:umass-sim0:0:0:0): READ(10). CDB: 28 0 0 0 30 57 0 0 8 0 (da0:umass-sim0:0:0:0): CAM status: SCSI Status Error (da0:umass-sim0:0:0:0): SCSI status: Check Condition (da0:umass-sim0:0:0:0): SCSI sense: UNIT ATTENTION asc:28,0 (Not ready to ready change, medium may have changed) umass0:umass_cam_action: 2:0:0:XPT_SCSI_IO: cmd: 0x28, flags: 0x40, 10b cmd/4096b data/32b sense umass0:umass_bbb_dump_cbw: CBW 208391: cmd = 10b (0x280000003057...), data = 4096b, lun = 0, dir = in umass0:umass_transfer_start: transfer index = 4 umass0:umass_t_bbb_data_read_callback: max_bulk=131072, data_rem=4096 umass0:umass_transfer_start: transfer index = 5 umass0:umass_transfer_start: transfer index = 8 umass0:umass_bbb_dump_csw: CSW 208391: sig = 0x53425355 (valid), tag = 0x00032e07, res = 4096, status = 0x01 (failed) umass0:umass_t_bbb_status_callback: Command failed, residue = 4096 umass0:umass_cam_cb: Fetching 32 bytes of sense data umass0:umass_bbb_dump_cbw: CBW 208392: cmd = 6b (0x030000002000), data = 32b, lun = 0, dir = in umass0:umass_transfer_start: transfer index = 4 umass0:umass_t_bbb_data_read_callback: max_bulk=131072, data_rem=32 umass0:umass_t_bbb_data_read_callback: max_bulk=131072, data_rem=0 umass0:umass_transfer_start: transfer index = 8 umass0:umass_t_bbb_status_callback: Failed to read CSW: USB_ERR_STALLED, try 0 umass0:umass_transfer_start: transfer index = 5 umass0:umass_transfer_start: transfer index = 8 umass0:umass_bbb_dump_csw: CSW 208392: sig = 0x53425355 (valid), tag = 0x00032e08, res = 14, status = 0x00 (good) (da0:umass-sim0:0:0:0): READ(10). CDB: 28 0 0 0 30 57 0 0 8 0 (da0:umass-sim0:0:0:0): CAM status: SCSI Status Error (da0:umass-sim0:0:0:0): SCSI status: Check Condition (da0:umass-sim0:0:0:0): SCSI sense: UNIT ATTENTION asc:28,0 (Not ready to ready change, medium may have changed) umass0:umass_cam_action: 2:0:0:XPT_SCSI_IO: cmd: 0x28, flags: 0x40, 10b cmd/4096b data/32b sense umass0:umass_bbb_dump_cbw: CBW 208393: cmd = 10b (0x280000003057...), data = 4096b, lun = 0, dir = in umass0:umass_transfer_start: transfer index = 4 umass0:umass_t_bbb_data_read_callback: max_bulk=131072, data_rem=4096 umass0:umass_transfer_start: transfer index = 5 umass0:umass_transfer_start: transfer index = 8 umass0:umass_bbb_dump_csw: CSW 208393: sig = 0x53425355 (valid), tag = 0x00032e09, res = 4096, status = 0x01 (failed) umass0:umass_t_bbb_status_callback: Command failed, residue = 4096 umass0:umass_cam_cb: Fetching 32 bytes of sense data umass0:umass_bbb_dump_cbw: CBW 208394: cmd = 6b (0x030000002000), data = 32b, lun = 0, dir = in umass0:umass_transfer_start: transfer index = 4 umass0:umass_t_bbb_data_read_callback: max_bulk=131072, data_rem=32 umass0:umass_t_bbb_data_read_callback: max_bulk=131072, data_rem=0 umass0:umass_transfer_start: transfer index = 8 umass0:umass_t_bbb_status_callback: Failed to read CSW: USB_ERR_STALLED, try 0 umass0:umass_transfer_start: transfer index = 5 umass0:umass_transfer_start: transfer index = 8 umass0:umass_bbb_dump_csw: CSW 208394: sig = 0x53425355 (valid), tag = 0x00032e0a, res = 14, status = 0x00 (good) (da0:umass-sim0:0:0:0): READ(10). CDB: 28 0 0 0 30 57 0 0 8 0 (da0:umass-sim0:0:0:0): CAM status: SCSI Status Error (da0:umass-sim0:0:0:0): SCSI status: Check Condition (da0:umass-sim0:0:0:0): SCSI sense: UNIT ATTENTION asc:28,0 (Not ready to ready change, medium may have changed) umass0:umass_cam_action: 2:0:0:XPT_SCSI_IO: cmd: 0x28, flags: 0x40, 10b cmd/4096b data/32b sense umass0:umass_bbb_dump_cbw: CBW 208395: cmd = 10b (0x280000003057...), data = 4096b, lun = 0, dir = in umass0:umass_transfer_start: transfer index = 4 umass0:umass_t_bbb_data_read_callback: max_bulk=131072, data_rem=4096 umass0:umass_transfer_start: transfer index = 5 umass0:umass_tr_error: transfer error, USB_ERR_TIMEOUT -> reset umass0:umass_cam_action: 2:0:0:XPT_SCSI_IO: cmd: 0x03, flags: 0x40, 6b cmd/32b data/32b sense umass0:umass_t_bbb_reset1_callback: BBB reset! umass0:umass_tr_error: transfer error, USB_ERR_TIMEOUT -> reset (da0:umass-sim0:0:0:0): AutoSense failed g_vfs_done():ext2fs/EXTERNAL[READ(offset=6303744, length=4096)]error = 5 Then I tried to umount and the system froze. I obviously couldn't save any dmesg output. But I think a try to write to the system and "fsync giving up on dirty" caused the freeze. I took some pictures of the screen. So I can write more output down if needed. From owner-freebsd-usb@FreeBSD.ORG Fri Nov 26 03:17:57 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 57D68106566B for ; Fri, 26 Nov 2010 03:17:57 +0000 (UTC) (envelope-from jamesbrandongooch@gmail.com) Received: from mail-ww0-f50.google.com (mail-ww0-f50.google.com [74.125.82.50]) by mx1.freebsd.org (Postfix) with ESMTP id E17ED8FC13 for ; Fri, 26 Nov 2010 03:17:56 +0000 (UTC) Received: by wwd20 with SMTP id 20so1475894wwd.31 for ; Thu, 25 Nov 2010 19:17:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=bp+fJqQmyfo6OGYmDdWA7/Kxyvc3YfVmw+t8JmuULq8=; b=rIrRNLxtUv0KiJvXdvLMNLeLZt635D2K+huG3ok6hThPO9XB7zljkswqha4Y6c8CbI Y+2YMlUkZb16R+rbzcGiCO7tGzpY4HMse9qxTu6qBrfzQpm0Jovll/e7Og/jJrjMMniA s+vhG44bPvno9dD9JVIYulW5TzwP3y5wbFMxU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=MQv8YyYVqIli+BO+DenBzq9H1yBlsmbdFNjPNt3cWgfDKyIFe0jnO9QY7C4JnZQVkO tLgIgKEBPCs/BLTWnMYXJEBRT3iE4Fp8m6NVCuwPMIofJT0h533WcOXkZz+QONG1GC+C kj0+QSX3T5Yhc5m7IV6cyJA9NF7OFgYUbH1fU= MIME-Version: 1.0 Received: by 10.216.142.199 with SMTP id i49mr1359889wej.96.1290739602750; Thu, 25 Nov 2010 18:46:42 -0800 (PST) Received: by 10.216.12.80 with HTTP; Thu, 25 Nov 2010 18:46:42 -0800 (PST) In-Reply-To: <201011142136.57161.bruce@cran.org.uk> References: <201011142136.57161.bruce@cran.org.uk> Date: Thu, 25 Nov 2010 20:46:42 -0600 Message-ID: From: Brandon Gooch To: Bruce Cran Content-Type: text/plain; charset=ISO-8859-1 Cc: freebsd-usb@freebsd.org Subject: Re: USB controller error logged when resuming after suspend X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Nov 2010 03:17:57 -0000 On Sun, Nov 14, 2010 at 3:36 PM, Bruce Cran wrote: > I've been trying to get my laptop working with suspend/resume. It comes back, > but USB seems rather unhappy about something for a while. Despite this, > plugging a flash drive in does attach to the EHCI controller at usbus6. You have better luck than me! On my system, "port 2 reset" fails, port is disabled, an none of my external ports work at all, like this: [SNIP] > uhub_reattach_port: port 2 reset failed, error=USB_ERR_TIMEOUT > uhub_reattach_port: device problem (USB_ERR_TIMEOUT), disabling port 2 [SNIP] It's becoming more well known that the USB stack isn't "suspend/resume" safe at this point. Have you tried building your USB systems as kernel modules and unloading/loading them via /etc/rs.suspend|resume? I used to have luck doing that here, but recently that has broken as well (running HEAD). Also, it's been my experience that multiple suspend/resume cycles can permanently shut down your ports... -Brandon From owner-freebsd-usb@FreeBSD.ORG Fri Nov 26 03:54:45 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0D369106566C for ; Fri, 26 Nov 2010 03:54:45 +0000 (UTC) (envelope-from peterjeremy@acm.org) Received: from mail36.syd.optusnet.com.au (mail36.syd.optusnet.com.au [211.29.133.76]) by mx1.freebsd.org (Postfix) with ESMTP id 60FC68FC15 for ; Fri, 26 Nov 2010 03:54:44 +0000 (UTC) Received: from server.vk2pj.dyndns.org (c220-239-116-103.belrs4.nsw.optusnet.com.au [220.239.116.103]) by mail36.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id oAQ3sfFo015354 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 26 Nov 2010 14:54:41 +1100 X-Bogosity: Ham, spamicity=0.000000 Received: from server.vk2pj.dyndns.org (localhost.vk2pj.dyndns.org [127.0.0.1]) by server.vk2pj.dyndns.org (8.14.4/8.14.4) with ESMTP id oAQ3se4T052727; Fri, 26 Nov 2010 14:54:40 +1100 (EST) (envelope-from peter@server.vk2pj.dyndns.org) Received: (from peter@localhost) by server.vk2pj.dyndns.org (8.14.4/8.14.4/Submit) id oAQ3sdnP052726; Fri, 26 Nov 2010 14:54:39 +1100 (EST) (envelope-from peter) Date: Fri, 26 Nov 2010 14:54:39 +1100 From: Peter Jeremy To: freebsd-usb@freebsd.org, kaiw@freebsd.org Message-ID: <20101126035439.GA50277@server.vk2pj.dyndns.org> References: <20101125034230.GA89666@server.vk2pj.dyndns.org> <201011250938.15470.hselasky@c2i.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="wq9mPyueHGvFACwf" Content-Disposition: inline In-Reply-To: <201011250938.15470.hselasky@c2i.net> X-PGP-Key: http://members.optusnet.com.au/peterjeremy/pubkey.asc User-Agent: Mutt/1.5.20 (2009-06-14) Cc: Subject: Re: Multimedia keys on Dell SK-8135 X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Nov 2010 03:54:45 -0000 --wq9mPyueHGvFACwf Content-Type: multipart/mixed; boundary="bp/iNruPH9dso1Pn" Content-Disposition: inline --bp/iNruPH9dso1Pn Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable [adding kaiw@ as per the wiki page] On 2010-Nov-25 09:38:15 +0100, Hans Petter Selasky wrote: >On Thursday 25 November 2010 04:42:30 Peter Jeremy wrote: >> I have a Dell SK-8135 keyboard which has multimedia keys in addition =2E.. >http://wiki.freebsd.org/uhidd Thanks. I didn't think to search for multimedia keyboards in general. I've tried uhidd and, using it to manage the multimedia keys, it mostly works. I want to use ukbd because I want a functioning keyboard in single-user mode and my mouse didn't get cleanly handled so I switched back to ums (which handles all my mouse functions). The bit that doesn't work is the volume control: The knob returns a HID code and a 7-bit 2-complement number defining the direction and rate (ie '1' is one click up, '127' is one click down). Unfortunately, xev shows that as soon as I move the volume control, I start receiving a continuous stream of alternating KeyPress and KeyRelease events until I kill uhidd. I have attached my uhidd.conf file and the debug output from uhidd (the second execution shows the effect of turning the volume control faster). Sample output from xev showing the volume control events: KeyPress event, serial 27, synthetic NO, window 0x1000001, root 0x120, subw 0x0, time 7007489, (172,122), root:(913,147), state 0x0, keycode 191 (keysym 0x0, NoSymbol), same_screen YES, XLookupString gives 0 bytes:=20 XmbLookupString gives 0 bytes:=20 XFilterEvent returns: False KeyRelease event, serial 27, synthetic NO, window 0x1000001, root 0x120, subw 0x0, time 7007530, (172,122), root:(913,147), state 0x0, keycode 191 (keysym 0x0, NoSymbol), same_screen YES, XLookupString gives 0 bytes:=20 XFilterEvent returns: False KeyPress event, serial 27, synthetic NO, window 0x1000001, root 0x120, subw 0x0, time 7007530, (172,122), root:(913,147), state 0x0, keycode 191 (keysym 0x0, NoSymbol), same_screen YES, XLookupString gives 0 bytes:=20 XmbLookupString gives 0 bytes:=20 XFilterEvent returns: False KeyRelease event, serial 27, synthetic NO, window 0x1000001, root 0x120, subw 0x0, time 7007571, (172,122), root:(913,147), state 0x0, keycode 191 (keysym 0x0, NoSymbol), same_screen YES, XLookupString gives 0 bytes:=20 XFilterEvent returns: False KeyPress event, serial 27, synthetic NO, window 0x1000001, root 0x120, subw 0x0, time 7007571, (172,122), root:(913,147), state 0x0, keycode 191 (keysym 0x0, NoSymbol), same_screen YES, XLookupString gives 0 bytes:=20 XmbLookupString gives 0 bytes:=20 XFilterEvent returns: False KeyRelease event, serial 27, synthetic NO, window 0x1000001, root 0x120, subw 0x0, time 7007612, (172,122), root:(913,147), state 0x0, keycode 191 (keysym 0x0, NoSymbol), same_screen YES, XLookupString gives 0 bytes:=20 XFilterEvent returns: False --=20 Peter Jeremy --bp/iNruPH9dso1Pn Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=uhidd Content-Transfer-Encoding: quoted-printable Script started on Fri Nov 26 14:30:49 2010 # uhidd -vvv /dev/ugen1.3=0D ugen1.3[0]-> HID interface=0D ugen1.3[0]-> Report descriptor size =3D 65=0D ugen1.3[0]-> Find IN interrupt ep: 0x81 packet_size=3D0x8=0D ugen1.3[1]-> HID interface=0D ugen1.3[1]-> Report descriptor size =3D 142=0D ugen1.3[1]-> Find IN interrupt ep: 0x82 packet_size=3D0x4=0D HID APPLICATION COLLECTION (Keyboard) size(65)=0D HID REPORT: ID 0=0D INPUT: =0D POS:0 SIZE:1 COUNT:8 [VARIABLE]=0D USAGE Keyboard LeftControl=0D USAGE Keyboard LeftShift=0D USAGE Keyboard LeftAlt=0D USAGE Keyboard Left GUI=0D USAGE Keyboard RightControl=0D USAGE Keyboard RightShift=0D USAGE Keyboard RightAlt=0D USAGE Keyboard Right GUI=0D POS:8 SIZE:8 COUNT:1 [CONST]=0D POS:16 SIZE:8 COUNT:6 [ARRAY]=0D USAGE [0 -> 255] (Keyboard)=0D OUTPUT: =0D POS:0 SIZE:1 COUNT:5 [VARIABLE]=0D USAGE Num Lock=0D USAGE Caps Lock=0D USAGE Scroll Lock=0D USAGE Compose=0D USAGE Kana=0D POS:5 SIZE:3 COUNT:1 [CONST]=0D HID APPLICATION COLLECTION (Consumer Control) size(31)=0D HID REPORT: ID 1=0D INPUT: =0D POS:0 SIZE:7 COUNT:1 [VARIABLE]=0D USAGE Volume=0D POS:7 SIZE:1 COUNT:1 [VARIABLE]=0D USAGE Mute=0D HID APPLICATION COLLECTION (System Control) size(29)=0D HID REPORT: ID 2=0D INPUT: =0D POS:0 SIZE:1 COUNT:3 [VARIABLE]=0D USAGE System Sleep=0D USAGE System Sleep=0D USAGE System Sleep=0D POS:3 SIZE:1 COUNT:5 [CONST]=0D HID APPLICATION COLLECTION (Consumer Control) size(82)=0D HID REPORT: ID 3=0D INPUT: =0D POS:0 SIZE:1 COUNT:1 [VARIABLE]=0D USAGE AC Refresh=0D POS:1 SIZE:1 COUNT:1 [VARIABLE]=0D USAGE AL Local Machine Browser=0D POS:2 SIZE:1 COUNT:1 [VARIABLE]=0D USAGE AC Home=0D POS:3 SIZE:1 COUNT:1 [VARIABLE]=0D USAGE AL Email Reader=0D POS:4 SIZE:1 COUNT:1 [VARIABLE]=0D USAGE AL Calculator=0D POS:5 SIZE:1 COUNT:1 [VARIABLE]=0D USAGE AC Stop=0D POS:6 SIZE:1 COUNT:1 [VARIABLE]=0D USAGE AC Forward=0D POS:7 SIZE:1 COUNT:1 [VARIABLE]=0D USAGE AC Back=0D POS:8 SIZE:1 COUNT:1 [VARIABLE]=0D USAGE Scan Next Track=0D POS:9 SIZE:1 COUNT:1 [VARIABLE]=0D USAGE Scan Previous Track=0D POS:10 SIZE:1 COUNT:1 [VARIABLE]=0D USAGE Play/Pause=0D POS:11 SIZE:1 COUNT:1 [VARIABLE]=0D USAGE Stop=0D POS:12 SIZE:1 COUNT:1 [VARIABLE]=0D USAGE AL Consumer Control Configuration=0D POS:13 SIZE:1 COUNT:11 [CONST]=0D ugen1.3[1]-> kbd device name: vkbdctl22=0D ugen1.3[1]-> kbd device name: vkbdctl23=0D ugen1.3[1]-> HID interface task started=0D ugen1.3[1]-> received data(4): 03 00 08 00 =0D hid_appcol_recv_data: len(4) 0x03 0x00 0x08 0x00=0D ugen1.3[1]-> hid coeds: 0xB7 =0D ugen1.3[1]-> received data(4): 03 00 00 00 =0D hid_appcol_recv_data: len(4) 0x03 0x00 0x00 0x00=0D ugen1.3[1]-> hid coeds: none=0D ugen1.3[1]-> received data(2): 01 127 =0D hid_appcol_recv_data: len(2) 0x01 0x7f=0D ugen1.3[1]-> hid coeds: 0xE0 =0D ugen1.3[1]-> received data(2): 01 -128 =0D hid_appcol_recv_data: len(2) 0x01 0x80=0D ugen1.3[1]-> hid coeds: 0xE2 =0D ugen1.3[1]-> received data(2): 01 00 =0D hid_appcol_recv_data: len(2) 0x01 0x00=0D ugen1.3[1]-> hid coeds: none=0D ^Cuhidd[1546]: terminated=0D # =0D # =0D # ^[[A=08 =08=08 =08=08=08 =08=08uhidd -vvv /dev/ugen1.3=0D ugen1.3[0]-> HID interface=0D ugen1.3[0]-> Report descriptor size =3D 65=0D ugen1.3[0]-> Find IN interrupt ep: 0x81 packet_size=3D0x8=0D ugen1.3[1]-> HID interface=0D ugen1.3[1]-> Report descriptor size =3D 142=0D ugen1.3[1]-> Find IN interrupt ep: 0x82 packet_size=3D0x4=0D HID APPLICATION COLLECTION (Keyboard) size(65)=0D HID REPORT: ID 0=0D INPUT: =0D POS:0 SIZE:1 COUNT:8 [VARIABLE]=0D USAGE Keyboard LeftControl=0D USAGE Keyboard LeftShift=0D USAGE Keyboard LeftAlt=0D USAGE Keyboard Left GUI=0D USAGE Keyboard RightControl=0D USAGE Keyboard RightShift=0D USAGE Keyboard RightAlt=0D USAGE Keyboard Right GUI=0D POS:8 SIZE:8 COUNT:1 [CONST]=0D POS:16 SIZE:8 COUNT:6 [ARRAY]=0D USAGE [0 -> 255] (Keyboard)=0D OUTPUT: =0D POS:0 SIZE:1 COUNT:5 [VARIABLE]=0D USAGE Num Lock=0D USAGE Caps Lock=0D USAGE Scroll Lock=0D USAGE Compose=0D USAGE Kana=0D POS:5 SIZE:3 COUNT:1 [CONST]=0D HID APPLICATION COLLECTION (Consumer Control) size(31)=0D HID REPORT: ID 1=0D INPUT: =0D POS:0 SIZE:7 COUNT:1 [VARIABLE]=0D USAGE Volume=0D POS:7 SIZE:1 COUNT:1 [VARIABLE]=0D USAGE Mute=0D HID APPLICATION COLLECTION (System Control) size(29)=0D HID REPORT: ID 2=0D INPUT: =0D POS:0 SIZE:1 COUNT:3 [VARIABLE]=0D USAGE System Sleep=0D USAGE System Sleep=0D USAGE System Sleep=0D POS:3 SIZE:1 COUNT:5 [CONST]=0D HID APPLICATION COLLECTION (Consumer Control) size(82)=0D HID REPORT: ID 3=0D INPUT: =0D POS:0 SIZE:1 COUNT:1 [VARIABLE]=0D USAGE AC Refresh=0D POS:1 SIZE:1 COUNT:1 [VARIABLE]=0D USAGE AL Local Machine Browser=0D POS:2 SIZE:1 COUNT:1 [VARIABLE]=0D USAGE AC Home=0D POS:3 SIZE:1 COUNT:1 [VARIABLE]=0D USAGE AL Email Reader=0D POS:4 SIZE:1 COUNT:1 [VARIABLE]=0D USAGE AL Calculator=0D POS:5 SIZE:1 COUNT:1 [VARIABLE]=0D USAGE AC Stop=0D POS:6 SIZE:1 COUNT:1 [VARIABLE]=0D USAGE AC Forward=0D POS:7 SIZE:1 COUNT:1 [VARIABLE]=0D USAGE AC Back=0D POS:8 SIZE:1 COUNT:1 [VARIABLE]=0D USAGE Scan Next Track=0D POS:9 SIZE:1 COUNT:1 [VARIABLE]=0D USAGE Scan Previous Track=0D POS:10 SIZE:1 COUNT:1 [VARIABLE]=0D USAGE Play/Pause=0D POS:11 SIZE:1 COUNT:1 [VARIABLE]=0D USAGE Stop=0D POS:12 SIZE:1 COUNT:1 [VARIABLE]=0D USAGE AL Consumer Control Configuration=0D POS:13 SIZE:1 COUNT:11 [CONST]=0D ugen1.3[1]-> kbd device name: vkbdctl24=0D ugen1.3[1]-> kbd device name: vkbdctl25=0D ugen1.3[1]-> HID interface task started=0D ugen1.3[1]-> received data(2): 01 127 =0D hid_appcol_recv_data: len(2) 0x01 0x7f=0D ugen1.3[1]-> hid coeds: 0xE0 =0D ugen1.3[1]-> received data(2): 01 127 =0D hid_appcol_recv_data: len(2) 0x01 0x7f=0D ugen1.3[1]-> hid coeds: 0xE0 =0D ugen1.3[1]-> received data(2): 01 127 =0D hid_appcol_recv_data: len(2) 0x01 0x7f=0D ugen1.3[1]-> hid coeds: 0xE0 =0D ugen1.3[1]-> received data(2): 01 126 =0D hid_appcol_recv_data: len(2) 0x01 0x7e=0D ugen1.3[1]-> hid coeds: 0xE0 =0D ugen1.3[1]-> received data(2): 01 127 =0D hid_appcol_recv_data: len(2) 0x01 0x7f=0D ugen1.3[1]-> hid coeds: 0xE0 =0D ugen1.3[1]-> received data(2): 01 01 =0D hid_appcol_recv_data: len(2) 0x01 0x01=0D ugen1.3[1]-> hid coeds: 0xE0 =0D ugen1.3[1]-> received data(2): 01 02 =0D hid_appcol_recv_data: len(2) 0x01 0x02=0D ugen1.3[1]-> hid coeds: 0xE0 =0D ugen1.3[1]-> received data(2): 01 02 =0D hid_appcol_recv_data: len(2) 0x01 0x02=0D ugen1.3[1]-> hid coeds: 0xE0 =0D ugen1.3[1]-> received data(2): 01 01 =0D hid_appcol_recv_data: len(2) 0x01 0x01=0D ugen1.3[1]-> hid coeds: 0xE0 =0D ugen1.3[1]-> received data(2): 01 02 =0D hid_appcol_recv_data: len(2) 0x01 0x02=0D ugen1.3[1]-> hid coeds: 0xE0 =0D ugen1.3[1]-> received data(2): 01 01 =0D hid_appcol_recv_data: len(2) 0x01 0x01=0D ugen1.3[1]-> hid coeds: 0xE0 =0D ugen1.3[1]-> received data(2): 01 01 =0D hid_appcol_recv_data: len(2) 0x01 0x01=0D ugen1.3[1]-> hid coeds: 0xE0 =0D ^Cuhidd[1563]: terminated=0D # ^D=08=08 Script done on Fri Nov 26 14:35:13 2010 --bp/iNruPH9dso1Pn Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="uhidd.conf" # Default bindings default={ mouse_attach="NO" kbd_attach="NO" vhid_attach="NO" cc_attach="YES" } # Dell SK-8135 0x413c:0x2010={ cc_keymap={ Scan_Next_Track="0x7A" Scan_Previous_Track="0x75" Stop="0x74" Play/Pause="0x7C" Volume="0x64" Mute="0x72" AL_Consumer_Control_Configuration="0x7F" AL_Email_Reader="0x63" AL_Calculator="0x71" AL_Local_Machine_Browser="0x6F" AC_Home="0x62" AC_Back="0x54" AC_Forward="0x5A" AC_Stop="0x5F" AC_Refresh="0x60" } } --bp/iNruPH9dso1Pn-- --wq9mPyueHGvFACwf Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.15 (FreeBSD) iEYEARECAAYFAkzvL38ACgkQ/opHv/APuIcMkwCfejBDHGRBwQNJic93oU27L8mt KTgAnjNq5QF7I+ED+cF1YZiMLL0qW8IN =noS9 -----END PGP SIGNATURE----- --wq9mPyueHGvFACwf-- From owner-freebsd-usb@FreeBSD.ORG Fri Nov 26 07:17:07 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 74F4E106566B for ; Fri, 26 Nov 2010 07:17:07 +0000 (UTC) (envelope-from hselasky@c2i.net) Received: from swip.net (mailfe05.c2i.net [212.247.154.130]) by mx1.freebsd.org (Postfix) with ESMTP id CCFDD8FC12 for ; Fri, 26 Nov 2010 07:17:06 +0000 (UTC) X-Cloudmark-Score: 0.000000 [] X-Cloudmark-Analysis: v=1.1 cv=5OBHFxb9I47YZ7HELXzI6cL6pwPTRnd5uxbD1DPQ4WY= c=1 sm=1 a=oxsbxpBOTrQA:10 a=8nJEP1OIZ-IA:10 a=CL8lFSKtTFcA:10 a=i9M/sDlu2rpZ9XS819oYzg==:17 a=XxwbJlYx2tXRAuZoGKQA:9 a=Gs7XepssB-ancf94k8UA:7 a=GjnPFqkwu897K2FBW8dW8I8UYeoA:4 a=wPNLvfGTeEIA:10 a=UoitZPY4WyemRQEF:21 a=pDSSAvNxvEMTSf0Q:21 a=i9M/sDlu2rpZ9XS819oYzg==:117 Received: from [188.126.198.129] (account mc467741@c2i.net HELO laptop002.hselasky.homeunix.org) by mailfe05.swip.net (CommuniGate Pro SMTP 5.2.19) with ESMTPA id 53401091; Fri, 26 Nov 2010 08:17:04 +0100 From: Hans Petter Selasky To: freebsd-usb@freebsd.org Date: Fri, 26 Nov 2010 08:17:47 +0100 User-Agent: KMail/1.13.5 (FreeBSD/8.1-STABLE; KDE/4.4.5; amd64; ; ) References: <20101125025526.GA2772@mail> <201011250940.19677.hselasky@c2i.net> <20101126020159.GA2408@mail> In-Reply-To: <20101126020159.GA2408@mail> X-Face: +~\`s("[*|O,="7?X@L.elg*F"OA\I/3%^p8g?ab%RN'(; _IjlA: hGE..Ew, XAQ*o#\/M~SC=S1-f9{EzRfT'|Hhll5Q]ha5Bt-s|oTlKMusi:1e[wJl}kd}GR Z0adGx-x_0zGbZj'e(Y[(UNle~)8CQWXW@:DX+9)_YlB[tIccCPN$7/L' MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201011260817.47338.hselasky@c2i.net> Cc: Subject: Re: External usb HDD disconnects, system gets messed up X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Nov 2010 07:17:07 -0000 On Friday 26 November 2010 03:01:59 Nezmer wrote: > On Thu, Nov 25, 2010 at 09:40:19AM +0100, Hans Petter Selasky wrote: > > On Thursday 25 November 2010 03:55:26 Nezmer wrote: > > > Hi, > > > > > > FreeBSD 8.1-STABLE r215402M GENERIC amd64 > > > > > > I'm having a weird issue. I have a 300GB external usb HDD with one ext2 > > > partition. I use ZFS for my internal HDD. > > > > > > Almost daily, The usb HDD disconnects(according to dmesg) and the > > > system gets messed up. Running processes keep responding but they > > > would not exit. And no new processes would start running. I eventually > > > would have to hard reset and run fsck.ext2 on the next run. > > > > > > Any idea what's going on? > > > Do you need any specific information? > > > > Hi, > > > > When this hang happens you can try to turn on umass debugging: > > > > sysctl hw.usb.umass.debug=-1 > > > > You need this option in your kernel config or when building the umass > > module to enable the sysctl above: > > > > options USB_DEBUG > > > > --HPS > > Thank you for the hint. I managed to freeze the system this time. > > 1st, I tried to cd to a dir and got an I/O error. Here is some debug > output: > > > umass0:umass_bbb_dump_csw: CSW 208387: sig = 0x53425355 (valid), tag = > 0x00032e03, res = 4096, status = 0x01 (failed) > umass0:umass_t_bbb_status_callback: Command failed, residue = 4096 > umass0:umass_cam_cb: Fetching 32 bytes of sense data > umass0:umass_bbb_dump_cbw: CBW 208388: cmd = 6b (0x030000002000), data = > 32b, lun = 0, dir = in umass0:umass_transfer_start: transfer index = 4 > umass0:umass_t_bbb_data_read_callback: max_bulk=131072, data_rem=32 > umass0:umass_t_bbb_data_read_callback: max_bulk=131072, data_rem=0 > umass0:umass_transfer_start: transfer index = 8 > umass0:umass_t_bbb_status_callback: Failed to read CSW: USB_ERR_STALLED, > try 0 umass0:umass_transfer_start: transfer index = 5 > umass0:umass_transfer_start: transfer index = 8 > umass0:umass_bbb_dump_csw: CSW 208388: sig = 0x53425355 (valid), tag = > 0x00032e04, res = 14, status = 0x00 (good) (da0:umass-sim0:0:0:0): > READ(10). CDB: 28 0 0 0 30 57 0 0 8 0 > (da0:umass-sim0:0:0:0): CAM status: SCSI Status Error > (da0:umass-sim0:0:0:0): SCSI status: Check Condition > (da0:umass-sim0:0:0:0): SCSI sense: UNIT ATTENTION asc:28,0 (Not ready to > ready change, medium may have changed) umass0:umass_cam_action: > 2:0:0:XPT_SCSI_IO: cmd: 0x28, flags: 0x40, 10b cmd/4096b data/32b sense > umass0:umass_bbb_dump_cbw: CBW 208389: cmd = 10b (0x280000003057...), data > = 4096b, lun = 0, dir = in umass0:umass_transfer_start: transfer index = 4 > umass0:umass_t_bbb_data_read_callback: max_bulk=131072, data_rem=4096 > umass0:umass_transfer_start: transfer index = 5 > umass0:umass_transfer_start: transfer index = 8 > umass0:umass_bbb_dump_csw: CSW 208389: sig = 0x53425355 (valid), tag = > 0x00032e05, res = 4096, status = 0x01 (failed) > umass0:umass_t_bbb_status_callback: Command failed, residue = 4096 > umass0:umass_cam_cb: Fetching 32 bytes of sense data > umass0:umass_bbb_dump_cbw: CBW 208390: cmd = 6b (0x030000002000), data = > 32b, lun = 0, dir = in umass0:umass_transfer_start: transfer index = 4 > umass0:umass_t_bbb_data_read_callback: max_bulk=131072, data_rem=32 > umass0:umass_t_bbb_data_read_callback: max_bulk=131072, data_rem=0 > umass0:umass_transfer_start: transfer index = 8 > umass0:umass_t_bbb_status_callback: Failed to read CSW: USB_ERR_STALLED, > try 0 umass0:umass_transfer_start: transfer index = 5 > umass0:umass_transfer_start: transfer index = 8 > umass0:umass_bbb_dump_csw: CSW 208390: sig = 0x53425355 (valid), tag = > 0x00032e06, res = 14, status = 0x00 (good) (da0:umass-sim0:0:0:0): > READ(10). CDB: 28 0 0 0 30 57 0 0 8 0 > (da0:umass-sim0:0:0:0): CAM status: SCSI Status Error > (da0:umass-sim0:0:0:0): SCSI status: Check Condition > (da0:umass-sim0:0:0:0): SCSI sense: UNIT ATTENTION asc:28,0 (Not ready to > ready change, medium may have changed) umass0:umass_cam_action: > 2:0:0:XPT_SCSI_IO: cmd: 0x28, flags: 0x40, 10b cmd/4096b data/32b sense > umass0:umass_bbb_dump_cbw: CBW 208391: cmd = 10b (0x280000003057...), data > = 4096b, lun = 0, dir = in umass0:umass_transfer_start: transfer index = 4 > umass0:umass_t_bbb_data_read_callback: max_bulk=131072, data_rem=4096 > umass0:umass_transfer_start: transfer index = 5 > umass0:umass_transfer_start: transfer index = 8 > umass0:umass_bbb_dump_csw: CSW 208391: sig = 0x53425355 (valid), tag = > 0x00032e07, res = 4096, status = 0x01 (failed) > umass0:umass_t_bbb_status_callback: Command failed, residue = 4096 > umass0:umass_cam_cb: Fetching 32 bytes of sense data > umass0:umass_bbb_dump_cbw: CBW 208392: cmd = 6b (0x030000002000), data = > 32b, lun = 0, dir = in umass0:umass_transfer_start: transfer index = 4 > umass0:umass_t_bbb_data_read_callback: max_bulk=131072, data_rem=32 > umass0:umass_t_bbb_data_read_callback: max_bulk=131072, data_rem=0 > umass0:umass_transfer_start: transfer index = 8 > umass0:umass_t_bbb_status_callback: Failed to read CSW: USB_ERR_STALLED, > try 0 umass0:umass_transfer_start: transfer index = 5 > umass0:umass_transfer_start: transfer index = 8 > umass0:umass_bbb_dump_csw: CSW 208392: sig = 0x53425355 (valid), tag = > 0x00032e08, res = 14, status = 0x00 (good) (da0:umass-sim0:0:0:0): > READ(10). CDB: 28 0 0 0 30 57 0 0 8 0 > (da0:umass-sim0:0:0:0): CAM status: SCSI Status Error > (da0:umass-sim0:0:0:0): SCSI status: Check Condition > (da0:umass-sim0:0:0:0): SCSI sense: UNIT ATTENTION asc:28,0 (Not ready to > ready change, medium may have changed) umass0:umass_cam_action: > 2:0:0:XPT_SCSI_IO: cmd: 0x28, flags: 0x40, 10b cmd/4096b data/32b sense > umass0:umass_bbb_dump_cbw: CBW 208393: cmd = 10b (0x280000003057...), data > = 4096b, lun = 0, dir = in umass0:umass_transfer_start: transfer index = 4 > umass0:umass_t_bbb_data_read_callback: max_bulk=131072, data_rem=4096 > umass0:umass_transfer_start: transfer index = 5 > umass0:umass_transfer_start: transfer index = 8 > umass0:umass_bbb_dump_csw: CSW 208393: sig = 0x53425355 (valid), tag = > 0x00032e09, res = 4096, status = 0x01 (failed) > umass0:umass_t_bbb_status_callback: Command failed, residue = 4096 > umass0:umass_cam_cb: Fetching 32 bytes of sense data > umass0:umass_bbb_dump_cbw: CBW 208394: cmd = 6b (0x030000002000), data = > 32b, lun = 0, dir = in umass0:umass_transfer_start: transfer index = 4 > umass0:umass_t_bbb_data_read_callback: max_bulk=131072, data_rem=32 > umass0:umass_t_bbb_data_read_callback: max_bulk=131072, data_rem=0 > umass0:umass_transfer_start: transfer index = 8 > umass0:umass_t_bbb_status_callback: Failed to read CSW: USB_ERR_STALLED, > try 0 umass0:umass_transfer_start: transfer index = 5 > umass0:umass_transfer_start: transfer index = 8 > umass0:umass_bbb_dump_csw: CSW 208394: sig = 0x53425355 (valid), tag = > 0x00032e0a, res = 14, status = 0x00 (good) (da0:umass-sim0:0:0:0): > READ(10). CDB: 28 0 0 0 30 57 0 0 8 0 > (da0:umass-sim0:0:0:0): CAM status: SCSI Status Error > (da0:umass-sim0:0:0:0): SCSI status: Check Condition > (da0:umass-sim0:0:0:0): SCSI sense: UNIT ATTENTION asc:28,0 (Not ready to > ready change, medium may have changed) umass0:umass_cam_action: > 2:0:0:XPT_SCSI_IO: cmd: 0x28, flags: 0x40, 10b cmd/4096b data/32b sense > umass0:umass_bbb_dump_cbw: CBW 208395: cmd = 10b (0x280000003057...), data > = 4096b, lun = 0, dir = in umass0:umass_transfer_start: transfer index = 4 > umass0:umass_t_bbb_data_read_callback: max_bulk=131072, data_rem=4096 > umass0:umass_transfer_start: transfer index = 5 > umass0:umass_tr_error: transfer error, USB_ERR_TIMEOUT -> reset > umass0:umass_cam_action: 2:0:0:XPT_SCSI_IO: cmd: 0x03, flags: 0x40, 6b > cmd/32b data/32b sense umass0:umass_t_bbb_reset1_callback: BBB reset! > umass0:umass_tr_error: transfer error, USB_ERR_TIMEOUT -> reset > (da0:umass-sim0:0:0:0): AutoSense failed > g_vfs_done():ext2fs/EXTERNAL[READ(offset=6303744, length=4096)]error = 5 > > Then I tried to umount and the system froze. I obviously couldn't save > any dmesg output. But I think a try to write to the system and > "fsync giving up on dirty" caused the freeze. > > I took some pictures of the screen. So I can write more output down if > needed. Hi, I think that the USB part of your USB disk has died or there has been a firmware crash. Other OS'es will perform a complete device reset in this situation and sometimes that help, but still that is hiding a problem about the device. We don't do that on FreeBSD, and that might be the reason it does not recover. Check that your disk has external power supply! Sometimes the power supplied on the USB port is not sufficient. --HPS From owner-freebsd-usb@FreeBSD.ORG Fri Nov 26 07:50:13 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 13A19106564A for ; Fri, 26 Nov 2010 07:50:13 +0000 (UTC) (envelope-from bruce@cran.org.uk) Received: from muon.cran.org.uk (muon.cran.org.uk [IPv6:2a01:348:0:15:5d59:5c40:0:1]) by mx1.freebsd.org (Postfix) with ESMTP id A44AA8FC12 for ; Fri, 26 Nov 2010 07:50:12 +0000 (UTC) Received: from muon.cran.org.uk (localhost [127.0.0.1]) by muon.cran.org.uk (Postfix) with ESMTP id F105BE7225; Fri, 26 Nov 2010 07:50:11 +0000 (GMT) Received: from unknown (client-86-29-107-54.glfd.adsl.virginmedia.com [86.29.107.54]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by muon.cran.org.uk (Postfix) with ESMTPSA; Fri, 26 Nov 2010 07:50:11 +0000 (GMT) Date: Fri, 26 Nov 2010 07:49:43 +0000 From: Bruce Cran To: Brandon Gooch Message-ID: <20101126074943.00001950@unknown> In-Reply-To: References: <201011142136.57161.bruce@cran.org.uk> X-Mailer: Claws Mail 3.7.6 (GTK+ 2.16.0; i586-pc-mingw32msvc) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: freebsd-usb@freebsd.org Subject: Re: USB controller error logged when resuming after suspend X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Nov 2010 07:50:13 -0000 On Thu, 25 Nov 2010 20:46:42 -0600 Brandon Gooch wrote: > It's becoming more well known that the USB stack isn't > "suspend/resume" safe at this point. Have you tried building your USB > systems as kernel modules and unloading/loading them via > /etc/rs.suspend|resume? I used to have luck doing that here, but > recently that has broken as well (running HEAD). I'm not so interested in using suspend/resume as a real feature, but more as a developer to report issues so that in the future we can perhaps have it working for end-users. Apparently there's lots of infrastructure work that still needs to be done before it's going to be reliable unfortunately. -- Bruce Cran From owner-freebsd-usb@FreeBSD.ORG Fri Nov 26 12:27:10 2010 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2CFF51065670 for ; Fri, 26 Nov 2010 12:27:10 +0000 (UTC) (envelope-from kaiwang27@gmail.com) Received: from mail-ew0-f54.google.com (mail-ew0-f54.google.com [209.85.215.54]) by mx1.freebsd.org (Postfix) with ESMTP id A30198FC14 for ; Fri, 26 Nov 2010 12:27:09 +0000 (UTC) Received: by ewy24 with SMTP id 24so929308ewy.13 for ; Fri, 26 Nov 2010 04:27:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:received:received :x-authentication-warning:date:from:to:cc:subject:message-id :references:mime-version:content-type:content-disposition :in-reply-to:user-agent; bh=JgSJ5B6+j14R44Ub55WYsloyUBldY0j+chQ/a0kgBTA=; b=BDB/lg7ej8r4BCeDYxWUJztT04mx/zJ9IKqPpB9X7qeMJPr8keEfv0Yci7rkyeOjQ4 EGrSKdEai0wiiEU5rA02xS0HP1gnEpP3rC3pm51B+sTiCYmJTsjYFc1mFB/LmMhTm+1U RhAQJc+8aYQW06daJqZjybXE0O7OvYGzwgwNc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=x-authentication-warning:date:from:to:cc:subject:message-id :references:mime-version:content-type:content-disposition :in-reply-to:user-agent; b=nxfQ+KAILUN/hyTt3SqyFo/6/Lzq20hhO1HONo0LwrhrdnbwWIDHjEyIBrGIftpgK8 eXcFj597f0dz4STDfk++uRlKzWeu1A/HY36M93lc7ivxiJNLziR3XgXn1kP4soyk4HzL 4SaCoSrca2DWtRHU09nCJu/W8RRBDzRtNj5ro= Received: by 10.213.3.66 with SMTP id 2mr671672ebm.82.1290772581531; Fri, 26 Nov 2010 03:56:21 -0800 (PST) Received: from localhost (81-233-38-26-no36.tbcn.telia.com [81.233.38.26]) by mx.google.com with ESMTPS id b52sm1684353eei.1.2010.11.26.03.56.18 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 26 Nov 2010 03:56:19 -0800 (PST) Received: from localhost ([127.0.0.1] helo=localhost.my.domain) by localhost with esmtp (Exim 4.71 (FreeBSD)) (envelope-from ) id 1PLwuX-0000i0-Q9; Fri, 26 Nov 2010 12:56:17 +0100 Received: (from kaiw@localhost) by localhost.my.domain (8.14.3/8.14.3/Submit) id oAQBuHVd002727; Fri, 26 Nov 2010 12:56:17 +0100 (CET) (envelope-from kaiwang27@gmail.com) X-Authentication-Warning: localhost.my.domain: kaiw set sender to kaiwang27@gmail.com using -f Date: Fri, 26 Nov 2010 12:56:17 +0100 From: Kai Wang To: Peter Jeremy Message-ID: <20101126115617.GA2566@viskning> References: <20101125034230.GA89666@server.vk2pj.dyndns.org> <201011250938.15470.hselasky@c2i.net> <20101126035439.GA50277@server.vk2pj.dyndns.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20101126035439.GA50277@server.vk2pj.dyndns.org> User-Agent: Mutt/1.5.20 (2009-06-14) Cc: freebsd-usb@freebsd.org Subject: Re: Multimedia keys on Dell SK-8135 X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Nov 2010 12:27:10 -0000 Hi Peter, On Fri, Nov 26, 2010 at 02:54:39PM +1100, Peter Jeremy wrote: > [adding kaiw@ as per the wiki page] > > On 2010-Nov-25 09:38:15 +0100, Hans Petter Selasky wrote: > >On Thursday 25 November 2010 04:42:30 Peter Jeremy wrote: > >> I have a Dell SK-8135 keyboard which has multimedia keys in addition > ... > >http://wiki.freebsd.org/uhidd > > Thanks. I didn't think to search for multimedia keyboards in general. > I've tried uhidd and, using it to manage the multimedia keys, it > mostly works. I want to use ukbd because I want a functioning > keyboard in single-user mode and my mouse didn't get cleanly handled > so I switched back to ums (which handles all my mouse functions). > > The bit that doesn't work is the volume control: The knob returns > a HID code and a 7-bit 2-complement number defining the direction > and rate (ie '1' is one click up, '127' is one click down). > Unfortunately, xev shows that as soon as I move the volume control, > I start receiving a continuous stream of alternating KeyPress and > KeyRelease events until I kill uhidd. Some time ago, We added support for this SK-8135 keyboard's linear volume control by simulating VOLUME_UP and VOLUME_DOWN events. However the code is not released yet; if you want to test it, you can check out the source from our svn: % svn checkout http://uhidd.googlecode.com/svn/trunk/ uhidd % cd uhidd/uhidd % make # ./uhidd -vvv /.../ugenXXX Also you need to change the configuration file: > # Dell SK-8135 > 0x413c:0x2010={ > cc_keymap={ > Scan_Next_Track="0x7A" > Scan_Previous_Track="0x75" > Stop="0x74" > Play/Pause="0x7C" > Volume="0x64" Remove "Volume" and use "Volume_Increment" and "Volume_Decrement" here instead. Kai From owner-freebsd-usb@FreeBSD.ORG Sat Nov 27 19:40:09 2010 Return-Path: Delivered-To: freebsd-usb@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 44E881065675 for ; Sat, 27 Nov 2010 19:40:09 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 13B208FC19 for ; Sat, 27 Nov 2010 19:40:09 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id oARJe8KK083857 for ; Sat, 27 Nov 2010 19:40:08 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id oARJe8FB083856; Sat, 27 Nov 2010 19:40:08 GMT (envelope-from gnats) Date: Sat, 27 Nov 2010 19:40:08 GMT Message-Id: <201011271940.oARJe8FB083856@freefall.freebsd.org> To: freebsd-usb@FreeBSD.org From: dfilter@FreeBSD.ORG (dfilter service) Cc: Subject: Re: usb/149039: commit references a PR X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: dfilter service List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Nov 2010 19:40:09 -0000 The following reply was made to PR usb/149039; it has been noted by GNATS. From: dfilter@FreeBSD.ORG (dfilter service) To: bug-followup@FreeBSD.org Cc: Subject: Re: usb/149039: commit references a PR Date: Sat, 27 Nov 2010 19:39:35 +0000 (UTC) Author: thompsa Date: Sat Nov 27 19:39:29 2010 New Revision: 215947 URL: http://svn.freebsd.org/changeset/base/215947 Log: MFC r213803 USB network (UHSO): - Correct network interface flags. PR: usb/149039 Submitted by: Fredrik Lindberg Modified: stable/8/sys/dev/usb/net/uhso.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/mips/alchemy/ (props changed) stable/8/sys/mips/atheros/ (props changed) stable/8/sys/mips/cavium/ (props changed) stable/8/sys/mips/cavium/dev/ (props changed) stable/8/sys/mips/rmi/ (props changed) stable/8/sys/mips/rmi/dev/ (props changed) stable/8/sys/mips/sibyte/ (props changed) Modified: stable/8/sys/dev/usb/net/uhso.c ============================================================================== --- stable/8/sys/dev/usb/net/uhso.c Sat Nov 27 19:38:40 2010 (r215946) +++ stable/8/sys/dev/usb/net/uhso.c Sat Nov 27 19:39:29 2010 (r215947) @@ -1560,7 +1560,7 @@ uhso_attach_ifnet(struct uhso_softc *sc, ifp->if_init = uhso_if_init; ifp->if_start = uhso_if_start; ifp->if_output = uhso_if_output; - ifp->if_flags = 0; + ifp->if_flags = IFF_BROADCAST | IFF_MULTICAST | IFF_NOARP; ifp->if_softc = sc; IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen); ifp->if_snd.ifq_drv_maxlen = ifqmaxlen; _______________________________________________ svn-src-all@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"