-   Linux - General (
-   -   usb_control msg sends extra '0x00' bytes (

niekvanagt 01-18-2013 10:10 AM

usb_control msg sends extra '0x00' bytes

I am developing a Linux USB driver for a Video capture device.
By initializing this device I have to set some settings. To do that I call the usb_control_msg function. This function seems to work correctly but when I look at the USB packets with the USB sniffer of wireshark the data that is send is not my data but only '0x00'.

When I set the 'size' parameter of that function to 17, my first data byte is showing up in the sniffed packets. When I set it to 18, my first two bytes, and so on.

I also tried to set the 'data' parameter to &mydata+16. &mydata+1 results in 16 '0x00' bytes followed by the second byte of my data buffer.

Also tried to alloc my data buffer with the kmalloc(x, GFP_KERNEL) call in stead of just initialize on the stack, but that doesn't make any difference. No matter what I try, I cant get the 16 '0x00' bytes out of the URB packet.

My code is:


int rc, i;
unsigned char data[13];

data[0] = 0x0b;
data[1] = 0x4a;
data[2] = 0xc0;
data[3] = 0x01;
data[4] = 0x01;
data[5] = reg;
data[6] = val;
data[7] = 0xFF;
data[8] = 0x06;
data[9] = 0x00;
data[10] = 0x00;
data[11] = 0x00;
data[12] = 0x00;

rc = usb_control_msg(somagic->dev,
                    usb_sndctrlpipe(somagic->dev, 0x00),
                    0x0B, // VALUE
                    0x00, // INDEX
                    sizeof(data)+16, // + 16 for the extra '0x00' bytes

And what's in a sniffed packet is the following:
40 03 0b 00 00 00 1d 00 // header
00 00 00 00 00 00 00 00 // where data should be
00 00 00 00 00 00 00 00 // where data should be
0b 4a c0 01 01 0c 40 ff // my data
06 00 00 00 00 // my data

The first row are metadatabytes / header / requesttype
The second row should be my data but there (and on the third row) are the 16 '0x00' bytes. On the fourth row my data buffer is shown...

The question is: What are those 16 bytes and how can I get rid of them? Can anyone help me with this?

michaelk 01-21-2013 01:56 PM

Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.

Continue here:

All times are GMT -5. The time now is 01:18 PM.