Return-path: Received: from mail.gmx.net ([213.165.64.20]:37929 "HELO mail.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1753021AbZKAR7y (ORCPT ); Sun, 1 Nov 2009 12:59:54 -0500 Message-ID: <4AEDCCA0.8050709@gmx.net> Date: Sun, 01 Nov 2009 19:00:00 +0100 From: Frank Schaefer MIME-Version: 1.0 To: linux-wireless@vger.kernel.org CC: linux-usb@vger.kernel.org, johannes@sipsolutions.net, chunkeey@web.de Subject: [PATCH] ar9170usb: add mode-switching for AVM Fritz!WLAN USB N devices in cdrom mode References: <200910171606.02961.oliver@neukum.org> <20091017220313.GH24502@one-eyed-alien.net> <4ADC3657.6080906@gmx.net> In-Reply-To: <4ADC3657.6080906@gmx.net> Content-Type: multipart/mixed; boundary="------------000006070502040201000502" Sender: linux-wireless-owner@vger.kernel.org List-ID: This is a multi-part message in MIME format. --------------000006070502040201000502 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Frank Schaefer schrieb: > Matthew Dharm schrieb: > >> On Sat, Oct 17, 2009 at 11:34:07AM -0400, Alan Stern wrote: >> >> >>> On Sat, 17 Oct 2009, Oliver Neukum wrote: >>> >>> >>> >>>> Am Samstag, 17. Oktober 2009 15:14:28 schrieb Frank Schaefer: >>>> >>>> >>>>> I can think of multiple solutions for this, my first questions are: >>>>> Is there already a common solution for these devices in the kernel ? >>>>> How widespread is this bad habit of device-design ? So far, the only >>>>> devices I know are >>>>> >>>>> >>>> This is usually handled by the modeswitch tool outside the kernel. >>>> >>>> >>> Alternatively, you may be able to force the device to switch modes by >>> running the "eject" program on it. >>> >>> There is mode-switching code in the kernel for a few devices. The >>> current trend is to move this out of the kernel and let user programs >>> be responsible for it. >>> >>> >> If you go with the current trend, then you probably will want to write some >> UDEV rules to recognize these devices and issue the mode-changing command >> (either modeswitch or eject). >> >> Matt >> >> > Thanks for your replies, I really didn't know that there are so many > devices showing this behavior. > > On Windows, AVM does the fast-eject for its devices with a small > filter-driver avmeject.sys. > I will try to find out the "magic sequence" needed for the mode-switch > with a USB-logger. > > Regards, > Frank > I finally found the "magic" sequence. In the meantime I've been thinking a lot (too much ?) about HOW and WHERE to do the mode-switching. The mailing-list-archieves were really inspiring, maybe you remember the discussion about Tejun Heos' patches in april 2008. The conclusion was that there is no clearly preferable way to do this and that compromises are inevitable. The attached patch adds the mode-switching-procedure to the WLAN-driver (ar9170usb) and disables the storage device in the usb-storage-driver. I really think the mode-switching should be done in the kernel and not in user-space for reasons of usability. Doing it in the driver means putting the code for these device together in a single place. It also doesn't "pollute" the driver with much code (adds a single usb_bulk_msg()). Another benfit is that it binds the mode-switching to the driver. If the driver is blacklisted/not used, there will be no mode-switching. If there would be a way to keep the usb-storage-driver enabled as "fallback-driver" it would be an almost perfect solution... Regards, Frank --------------000006070502040201000502 Content-Type: application/mbox; name="0001-ar9170usb-add-mode-switching-for-AVM-Fritz-WLAN-USB.patch" Content-Transfer-Encoding: base64 Content-Disposition: inline; filename*0="0001-ar9170usb-add-mode-switching-for-AVM-Fritz-WLAN-USB.pat"; filename*1="ch" RnJvbSAzNzJlOWYzZTZkNjFlMTk1MzM5ZDk1NWExZDc1YjE1YTIzZGRlNjI0IE1vbiBTZXAg MTcgMDA6MDA6MDAgMjAwMQpGcm9tOiBGcmFuayBTY2hhZWZlciA8c2NoYWVmZXIuZnJhbmtA Z214Lm5ldD4KRGF0ZTogU3VuLCAxIE5vdiAyMDA5IDE3OjMxOjE0ICswMTAwClN1YmplY3Q6 IFtQQVRDSF0gYXI5MTcwdXNiOiBhZGQgbW9kZS1zd2l0Y2hpbmcgZm9yIEFWTSBGcml0eiFX TEFOIFVTQiBOIGRldmljZXMgaW4gY2Ryb20gbW9kZQoKVGhlIGRldmljZXMKCjA1N2M6ODQw MSAgICBBVk0gRnJpdHohV0xBTiBVU0IgTgowNTdjOjg0MDIgICAgQVZNIEZyaXR6IVdMQU4g VVNCIE4gMi40CgpoYXZlIGEgYnVpbHQtaW4gY2Ryb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