Am Freitag, 1. Juli 2005 07:42 schrieb oujin.rera:
> Hi
> 
> I have a very basic question.
> 
> I have written a Kernel driver for an USB device. Now I want to write an
> user space application to open the device and get the handle. What will the
> parameter(Path) to the "open"  function in the user application. How will I
> find to
> which hub port my device is connected ?
> 
> Any input will be highly useful!!

Taking the printer driver as an example.
You have a data structure here called usblp for your interface

In probe:
        usb_set_intfdata (intf, usblp);
        ^^^ associate the interface to your data structure

        usblp->present = 1;

        retval = usb_register_dev(intf, &usblp_class);
        ^^^ export your interface to user space
 
        if (retval) {
                err("Not able to get a minor for this device.");
                goto abort_intfdata;
        }
        usblp->minor = intf->minor;
        ^^^ associate the export with your data structure


in open:
        int minor = iminor(inode);
        struct usblp *usblp;
        struct usb_interface *intf;
        int retval;

        if (minor < 0)
                return -ENODEV;

        down (&usblp_sem);

        retval = -ENODEV;
        intf = usb_find_interface(&usblp_driver, minor);
        ^^^ walk association user space -> interface
        if (!intf) {
                goto out;
        }
        usblp = usb_get_intfdata (intf);
        ^^^ walk interface -> data structure
        file->private_data = usblp;
        ^^^ set association between task in user space and data structure

in read/write/... :
        struct usblp *usblp = file->private_data;
        ^^^ follow association

There are other ways, too. Use the source.

        HTH
                Oliver


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to