Hi Oliver

Thanks for patience and time!

I would like to present my question in different way.

1) I have written a Kernel USB driver with open, ioctl , probe and
disconnect

2) Now i want to write an application above that. For example

main()
{


  int file_desc, ret_val;
  char *msg = "Message passed by ioctl\n";

  file_desc = open(DEVICE_FILE_NAME, 0); ====> How do i find the name of the
USB device along with the path
  if (file_desc < 0) {
    printf ("Can't open device file: %s\n",
            DEVICE_FILE_NAME);
    exit(-1);
  }

  ret_val = ioctl(file_desc, IOCTL_SET_MSG, msg);

  if (ret_val < 0) {
    printf ("ioctl_set_msg failed:%d\n", ret_val);
    exit(-1);
  }


  close(file_desc);
}

My Question :

In the above code "open" requires a file name. How do i find the name of the
USB device along with the path ?

TIA

OuJin



----- Original Message -----
From: "Oliver Neukum" <[EMAIL PROTECTED]>
To: <linux-usb-devel@lists.sourceforge.net>
Cc: "oujin.rera" <[EMAIL PROTECTED]>
Sent: Friday, July 01, 2005 1:57 PM
Subject: Re: [linux-usb-devel] opening a device


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
_______________________________________________
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