On Tue, 28 Jun 2005, coin wrote:
> Here is the new code:
>
> int main(){
> struct usbdevfs_bulktransfer bulk;
> struct usbdevfs_ioctl ctrl;
> int fd,ret,interface=0x00;
> static unsigned char dato[4] = {0xFF, 0, 0, 0};
> fd = open("/proc/bus/usb/002/003", O_RDWR);
> if(fd != -1) {
> //bulk.ep = USB_DIR_IN | 1;
> bulk.ep = 1;
> bulk.len = 6;
It doesn't matter much, but bulk.len should be no larger than the size
of dato. Since dato has 4 bytes, bulk.len should be 4, not 6.
> bulk.data = &dato;
> bulk.timeout = 1000;
> ioctl(fd, USBDEVFS_CLAIMINTERFACE, &interface);
> perror("ioctl");
> ioctl(fd, USBDEVFS_BULK, &bulk);
> perror("ioctl");
> close(fd);
> }else
> printf("No lo pudo abrir");
You forgot the '\n' at the end. :-)
> return 0;
> }
I don't see anything else wrong with the program.
> But i receive the same thing.
> ioctl: Success
> ioctl: Invalid argument
> syslog
> usb 2-2: usbfs: USBDEVFS_BULK failed ep 0x1 len 6 ret -22
>
> A comment.
> I send the data 0xFF just for an example. The firmware receive 4 bytes
> and then plus every one.
> Can the device's firmware be waiting another data or another kind of data?
That wouldn't cause a -EINVAL (-22) error.
You will have to do some debugging in the kernel to find out what is going
wrong. Are you familiar with the procedure for editing the kernel source
code and compiling drivers?
You will have to edit the devio.c file in the drivers/usb/core
subdirectory of the kernel. Find the proc_bulk() function. Insert a
number of lines with calls to printk(KERN_INFO ...). For example, here is
the code at the start of the function, together with some lines that you
could add:
if (copy_from_user(&bulk, arg, sizeof(bulk)))
return -EFAULT;
printk(KERN_INFO "Line A\n");
if ((ret = findintfep(ps->dev, bulk.ep)) < 0)
return ret;
printk(KERN_INFO "Line B\n");
if ((ret = checkintf(ps, ret)))
return ret;
printk(KERN_INFO "Line C\n");
if (bulk.ep & USB_DIR_IN)
pipe = usb_rcvbulkpipe(dev, bulk.ep & 0x7f);
else
pipe = usb_sndbulkpipe(dev, bulk.ep & 0x7f);
if (!usb_maxpacket(dev, pipe, !(bulk.ep & USB_DIR_IN)))
return -EINVAL;
printk(KERN_INFO "Line D\n");
len1 = bulk.len;
if (len1 > MAX_USBFS_BUFFER_SIZE)
return -EINVAL;
printk(KERN_INFO "Line E\n");
Here I put the new lines all the way to the left so you can tell where
they are. You will want to add similar lines throughout the entire
function.
When you install the rebuilt usbcore.ko driver and run
your test program, each of those lines will produce output in the system
log. By seeing which lines get executed and which ones don't, you'll be
able to tell where the problem occurs.
Alan Stern
-------------------------------------------------------
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