On 2/18/06, David Brownell <[EMAIL PROTECTED]> wrote:
> Nobody should be using "usbmodules" on kernels newer than 2.5, so
> don't bother with that.  Just use the most current "usbutils", which
> is going to be a 0.71 or CVS version.

With the most current usbutils (0.71) my PS2->USB adapter does not
work.  That's what we've been attempting to solve in this thread.

I've done some additional hacking to find a more precise event that's
"enabling" this device we're fighting with.  I've gone through the old
usbmodules and found what part of it is making it all work.  I've
picked out the pieces to make a stand alone program to address the
issue.  I've attached the file to this email.  (does the mailing list
take attachments?  if not, I'll send it in the body of a message; it's
only ~75 lines long)

It seems to be the single ioctl call which is working the magic.  But
what all the parameters mean I truly haven't the foggiest.  If anyone
here can explain to me what's going on it would be greatly appreciated
and might help us know if there's a better way to address the issue. 
Otherwise perhaps someone could point the way to where we could get
some similar code executed automatically so that this thing works when
plugged in.

> For pretty much any device /sys/$DEV, "modprobe /sys/$DEV/modalias"
> is what to modprobe with recent (since maybe 2.6.12?) kernels and
> matching module-init-tools.

Ok, I'm rather clueless about these things.  I don't know what this
"modalias" is about.  The files there I found say
usb:bunch'o'gibberish and modprob'ing that file just gave errors.

-AF
#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <linux/types.h>

#define USB_DT_DEVICE_SIZE		18

#define USB_DIR_IN			0x80
#define USB_REQ_GET_DESCRIPTOR		0x06
#define USB_DT_DEVICE			0x01

struct usbdevfs_ctrltransfer {
	__u8 requesttype;
        __u8 request;
        __u16 value;
        __u16 index;
        __u16 length;
        __u32 timeout;  /* in milliseconds */
        void *data;
};
#define USBDEVFS_CONTROL     _IOWR('U', 0, struct usbdevfs_ctrltransfer)

#define CTRL_RETRIES    50
#define CTRL_TIMEOUT   100     /* milliseconds */

int main (int argc, char** argv)
{
  if( argc != 2 ) {
    fprintf( stderr, "You must specify a device with something like:\n"
        "\t%s /proc/bus/usb/001/009\n", argv[0] );
    return 1;
  }
  
  unsigned char buf[USB_DT_DEVICE_SIZE];
  int fd;

  if ((fd = open(argv[1], O_RDWR)) == -1) {
    fprintf(stderr, "cannot open %s, %s (%d)\n",
            argv[1], strerror(errno), errno);
    return 1;
  }

  {
    int result;
    int try = 0;

    struct usbdevfs_ctrltransfer ctrl;

    ctrl.requesttype = USB_DIR_IN;
    ctrl.request = USB_REQ_GET_DESCRIPTOR;
    ctrl.value = (USB_DT_DEVICE << 8);
    ctrl.index = 0;
    ctrl.length = USB_DT_DEVICE_SIZE;
    ctrl.data = buf;
    ctrl.timeout = CTRL_TIMEOUT;

       /* At least on UHCI controllers, this ioctl gets a lot of
    ETIMEDOUT errors which can often be retried with success
    one is persistent enough.  So, we try 100 times, which work
    on one machine, but not on my notebook computer.
    --Adam J. Richter ([EMAIL PROTECTED]) 2000 November 03. */

    do {
      result = ioctl(fd, USBDEVFS_CONTROL, &ctrl);
      try++;
    } while (try < CTRL_RETRIES && result == -1 && errno == ETIMEDOUT);
  }
  
  close(fd);
  
  return 0;
}




Reply via email to