public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Gernot Hillier <gernot@hillier.de>
To: Matthias Urlichs <smurf@smurf.noris.de>,
	Greg Kroah-Hartman <gregkh@suse.de>,
	Oliver Neukum <oliver@neukum.org>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] option.c: Add blacklisting infrastructure for special device handling
Date: Mon, 11 Jan 2010 09:30:00 +0100	[thread overview]
Message-ID: <4B4AE188.5010004@hillier.de> (raw)

From: Gernot Hillier <gernot@hillier.de>

As suggested by Matthias Urlichs, this patch adds a somehow generic 
mechanism for special handling of devices which don't support all 
bits expected by this driver.

The blacklisting code is heavily stolen from sierra.c, but extended to
support different special cases.

For now, one case is implemented (OPTION_BLACKLIST_SENDSETUP),
targeted at the 4G W14 device: devices which don't understand the 
setting of RTS/DTR in option_send_setup() causing a USB timeout of
5 s in any userspace open() which leads to errors in most userspace
applications.

In addition, I prepared another case for devices with interfaces which 
shall not be accessed by this driver (targeted at the D-Link DWM 652).

However, OPTION_BLACKLIST_RESERVED_IF is not fully implemented yet as 
I have no device to test this. Anyone volunteering to help here?
If not, I'll contact the guys who added D-Link DWM 652 support soon.

Signed-off-by: Gernot Hillier <gernot@hillier.de>

Index: linux-next/drivers/usb/serial/option.c
===================================================================
--- linux-next.orig/drivers/usb/serial/option.c	2010-01-09 10:24:57.000000000 +0100
+++ linux-next/drivers/usb/serial/option.c	2010-01-09 10:25:00.000000000 +0100
@@ -344,6 +344,19 @@ static int  option_resume(struct usb_ser
 #define HAIER_VENDOR_ID				0x201e
 #define HAIER_PRODUCT_CE100			0x2009
 
+/* some devices interfaces need special handling due to a number of reasons */
+typedef enum {
+		OPTION_BLACKLIST_NONE = 0,
+		OPTION_BLACKLIST_SENDSETUP = 1,
+		OPTION_BLACKLIST_RESERVED_IF = 2
+} option_blacklist_reason_t;
+
+struct option_blacklist_info {
+	const u32 infolen;	/* number of interface numbers on blacklist */
+	const u8  *ifaceinfo;	/* pointer to the array holding the numbers */
+	option_blacklist_reason_t reason;
+};
+
 static struct usb_device_id option_ids[] = {
 	{ USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COLT) },
 	{ USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA) },
@@ -709,6 +722,7 @@ struct option_intf_private {
 	spinlock_t susp_lock;
 	unsigned int suspended:1;
 	int in_flight;
+	struct option_blacklist_info *blacklist_info;
 };
 
 struct option_port_private {
@@ -778,9 +792,27 @@ static int option_probe(struct usb_seria
 	if (!data)
 		return -ENOMEM;
 	spin_lock_init(&data->susp_lock);
+	data->blacklist_info = (struct option_blacklist_info*) id->driver_info;
 	return 0;
 }
 
+static option_blacklist_reason_t is_blacklisted(const u8 ifnum,
+				const struct option_blacklist_info *blacklist)
+{
+	const u8  *info;
+	int i;
+
+	if (blacklist) {
+		info = blacklist->ifaceinfo;
+
+		for (i = 0; i < blacklist->infolen; i++) {
+			if (info[i] == ifnum)
+				return blacklist->reason;
+		}
+	}
+	return OPTION_BLACKLIST_NONE;
+}
+
 static void option_set_termios(struct tty_struct *tty,
 		struct usb_serial_port *port, struct ktermios *old_termios)
 {
@@ -1211,11 +1243,19 @@ static void option_setup_urbs(struct usb
 static int option_send_setup(struct usb_serial_port *port)
 {
 	struct usb_serial *serial = port->serial;
+	struct option_intf_private *intfdata =
+		(struct option_intf_private *) serial->private;
 	struct option_port_private *portdata;
 	int ifNum = serial->interface->cur_altsetting->desc.bInterfaceNumber;
 	int val = 0;
 	dbg("%s", __func__);
 
+	if (is_blacklisted(ifNum, intfdata->blacklist_info) ==
+						OPTION_BLACKLIST_SENDSETUP) {
+		dbg("No send_setup on blacklisted interface #%d\n", ifNum);
+		return -EIO;
+	}
+
 	portdata = usb_get_serial_port_data(port);
 
 	if (portdata->dtr_state)

             reply	other threads:[~2010-01-11  8:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-11  8:30 Gernot Hillier [this message]
2010-01-15 22:48 ` [PATCH 1/2] option.c: Add blacklisting infrastructure for special device handling Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B4AE188.5010004@hillier.de \
    --to=gernot@hillier.de \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=oliver@neukum.org \
    --cc=smurf@smurf.noris.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox