Hello All You Wise Developer Types,

I would like to implement a simple kernel hack which Involves the USB
drivers. I would like to identify a USB device by VendorID and
ProductID and have linux treat it as a device for which it does not
have any driver, even though it does. Linux should not claim the
device. I am looking to do this so that I can use the device with
VMWare which depends on Linux never claiming the device. I tried
forcing linux to disconnect/drop the device through IOCtl calls, some
libusb calls, etc., and it did not work - the necessary sequence of
events will only fire, I believe, if I can stop Linux from ever
thinking it knows what to do with the device. I have seen this work
with a USB Bluetooth device on my machine - I had USB support, but I
did not compile in bluetooth support, and Linux thus never recognized
a driver for the device and ignored it, such that VMWare could then
take control when Linux passed over it.

At first I will be selfish and be satisfied with a hack for myself
where I hard code the vendorid and productid I need blocked into the
drivers. I thought, perhaps, for the good of all VMWare users,
however, implementing some sort of code to read a blacklist of
vendorid/productid pairs from a file in, say, /etc, might be really
useful. Then people could apply the patch, create
/etc/usbblacklist.conf (or whatever) plug in their desired
vendorid:productid pair, and the USB driver would just block from that
list.

I've never hacked the kernel before. I'm not afraid to, but I don't
know where best to start - although I already took a swing. I went and
found a seemingly reasonable place to insert code...
drivers/usb/storage/usb.c

In the function 

/* Probe to see if we can drive a newly-connected USB device */
static int storage_probe(struct usb_interface *intf, const struct
usb_device_id *id)

I inserted the following code snippet...

if ((us->vendor == "4855") && (us->product == "3288")) {
  goto BadDevice;
  }

I then, knowing nothing else about kernel compiling, went back to the
kernel source root and typed
make modules
make modules_install

to rebuild my usb modules and put them in place.

After doing this tiny edit, nothing seemed different.

So then I started over by first doing a make clean at the kernel root
to clean up any precompiled kernel module object files, and did all of
the above again. Still, no effect.

How should I go about my little process here? Thanks for any info!

-Nick

PS for more background, I am attaching a previous post to the USB-Users group:
--- snip ---
> I have a situation, thanks to VMware, where I want to block the the
> various USB drivers in Linux from recognizing and attaching to a
> device when I plug it in... HOWEVER, I have a similiar device that
> must remain plugged in and attached.
>
> Basically, I have a Debian system with Kernel 2.6.10 which stores a
> lot of necessary data (VMWare images) on an external USB hard disk. I
> want to now load up Windows XP in VMWare and attach a USB DVDRW drive
> to WindowsXP. I can only do this if Linux does not attach to and thus
> claim the DVDRW drive when I plug it in. From my reading my log/dmesg
> output, I can see that the usb-storage driver controls access to both
> of my devices, so the typical answer I see everywhere of "rmmod
> usb-storage" won't really work, as I understand it. If  I rmmod
> usb-storage, then my external hard disk will become unavailable,
> VMWare will crash, and I won't need to bother trying to use the DVDRW
> drive anyway.
>
> Is there ANY way to block USB from attaching a specific device, given
> perhaps by its ID, manufacturer, or some unique characteristic?

You seem to be asking two closely related but different questions:

       Is there any way to prevent a USB driver from binding to a
       particular device?  In general, no.  However if you really
       wanted to, you could hack the driver's source code to make
       it recognize that device and refuse to bind to it.

       Is there any way to force a USB driver to unbind from a
       particular device once it is bound?  Yes.  For an example
       of a program to do this, see

http://marc.theaimsgroup.com/?l=linux-usb-devel&m=111390170718187&w=2

       You will want to use the "-d ifnum" option.


-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.
Get your fingers limbered up and give it your best shot. 4 great events, 4
opportunities to win big! Highest score wins.NEC IT Guy Games. Play to
win an NEC 61 plasma display. Visit http://www.necitguy.com/?r 
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to