Mohamed Ait Ouaziz | 25 Feb 2011 21:01
Picon

libhid::error sending control message: Protocol error !!

Hi everybody,
Im knew to libhid. I try to write a user-space driver to control a usb device. I started whit the example code, but i get the following error:

NOTICE: hid_init(): libhid 0.2.17 is being initialized.
  TRACE: hid_init(): initialising USB subsystem...
  TRACE: hid_init(): scanning for USB busses...
  TRACE: hid_init(): scanning for USB devices...
 NOTICE: hid_init(): successfully initialised HID library.
  TRACE: hid_new_HIDInterface(): creating a new HIDInterface instance...
  TRACE: hid_force_open(): forcefully opening a device interface according to matching criteria...
  TRACE: hid_get_usb_handle(): acquiring handle for a USB device...
  TRACE: hid_find_usb_device(): enumerating USB busses...
  TRACE: hid_find_usb_device(): enumerating USB devices on bus 008...
  TRACE: hid_find_usb_device(): inspecting USB device 008/002[0]...
  TRACE: hid_compare_usb_device(): comparing match specifications to USB device...
  TRACE: hid_compare_usb_device(): inspecting vendor ID...
  TRACE: hid_compare_usb_device(): match on vendor ID: 0x046d.
  TRACE: hid_compare_usb_device(): inspecting product ID...
  TRACE: hid_compare_usb_device(): no match on product ID.
  TRACE: hid_compare_usb_device(): no custom matching function supplied.
 NOTICE: hid_find_usb_device(): product 0xc045 of USB device 008/002[0] does not match 0x0050.
  TRACE: hid_find_usb_device(): inspecting USB device 008/001[0]...
  TRACE: hid_compare_usb_device(): comparing match specifications to USB device...
  TRACE: hid_compare_usb_device(): inspecting vendor ID...
  TRACE: hid_compare_usb_device(): match on vendor ID: 0x1d6b.
  TRACE: hid_compare_usb_device(): inspecting product ID...
  TRACE: hid_compare_usb_device(): no match on product ID.
  TRACE: hid_compare_usb_device(): no custom matching function supplied.
 NOTICE: hid_find_usb_device(): product 0x0001 of USB device 008/001[0] does not match 0x0050.
  TRACE: hid_find_usb_device(): enumerating USB devices on bus 007...
  TRACE: hid_find_usb_device(): inspecting USB device 007/004[0]...
  TRACE: hid_find_usb_device(): Could not claim interface 0...

  TRACE: hid_compare_usb_device(): comparing match specifications to USB device...
  TRACE: hid_compare_usb_device(): inspecting vendor ID...
  TRACE: hid_compare_usb_device(): match on vendor ID: 0x0461.
  TRACE: hid_compare_usb_device(): inspecting product ID...
  TRACE: hid_compare_usb_device(): match on product ID: 0x0050.
  TRACE: hid_compare_usb_device(): no custom matching function supplied.
 NOTICE: hid_find_usb_device(): found a matching USB device 007/004[0].
  TRACE: hid_force_open(): claiming USB device 007/004[0].
 NOTICE: hid_force_open(): successfully claimed USB device 007/004[0].
  TRACE: hid_init_parser(): initialising the HID parser for USB Device 007/004[0]...
  TRACE: hid_init_parser(): allocating space for HIDData structure...
  TRACE: hid_init_parser(): successfully allocated memory for HIDData strcture.
  TRACE: hid_init_parser(): allocating space for HIDParser structure...
  TRACE: hid_init_parser(): successfully allocated memory for HIDParser strcture.
 NOTICE: hid_init_parser(): successfully initialised the HID parser for USB Device 007/004[0].
  TRACE: hid_prepare_hid_descriptor(): initialising the HID descriptor for USB device 007/004[0]...
  TRACE: hid_prepare_hid_descriptor(): retrieving HID descriptor for USB device 007/004[0]...
WARNING: hid_prepare_hid_descriptor(): failed to get HID descriptor for USB device 007/004[0]:error sending control message: Protocol error
  TRACE: hid_close(): closing USB device 007/004[0]...
  TRACE: hid_close(): closing handle of USB device 007/004[0]...
 NOTICE: hid_close(): successfully closed USB device 007/004[0].
  TRACE: hid_close(): remove hidif from open list...
  TRACE: hid_reset_parser(): resetting the HID parser for USB device 007/004[0]...
  TRACE: hid_close(): freeing memory allocated for HID parser...
  TRACE: hid_close(): resetting HIDInterface...
hid_force_open failed with return code 13

Note: Im running this program as a sudoer.

Can you please give some elements to resolve this problem??

Cheers,
Wa3ziz

_______________________________________________
libhid-discuss mailing list
libhid-discuss <at> lists.alioth.debian.org
http://lists.alioth.debian.org/mailman/listinfo/libhid-discuss
http://libhid.alioth.debian.org/
Peter Stuge | 25 Feb 2011 21:25
Picon

Re: libhid::error sending control message: Protocol error !!

Hi Mohamed,

Mohamed Ait Ouaziz wrote:
> I try to write a user-space driver to control a usb device.

Do you know how you will communicate with the device on top of USB?

Separate from that, could you post lsusb -v output for the device?

>   TRACE: hid_compare_usb_device(): match on vendor ID: 0x0461.
>   TRACE: hid_compare_usb_device(): match on product ID: 0x0050.

Primax Electronics it seems, but my usb.ids file doesn't know the
product id.

> WARNING: hid_prepare_hid_descriptor(): failed to get HID descriptor for USB
> device 007/004[0]:error sending control message: Protocol error

Are you sure that this is a HID class device at all?

And if it turns out you'll need to perform simple communication that
has just been wrapped in HID class by someone for the wrong reasons,
then suggest using the HIDAPI by Signal 11 instead.

//Peter

_______________________________________________
libhid-discuss mailing list
libhid-discuss <at> lists.alioth.debian.org
http://lists.alioth.debian.org/mailman/listinfo/libhid-discuss
http://libhid.alioth.debian.org/

Mohamed Ait Ouaziz | 25 Feb 2011 21:44
Picon

Re: libhid::error sending control message: Protocol error !!



2011/2/25 Peter Stuge <peter <at> stuge.se>
Hi Mohamed,

Mohamed Ait Ouaziz wrote:
> I try to write a user-space driver to control a usb device.

Do you know how you will communicate with the device on top of USB?

Separate from that, could you post lsusb -v output for the device?


>   TRACE: hid_compare_usb_device(): match on vendor ID: 0x0461.
>   TRACE: hid_compare_usb_device(): match on product ID: 0x0050.

Primax Electronics it seems, but my usb.ids file doesn't know the
product id.


> WARNING: hid_prepare_hid_descriptor(): failed to get HID descriptor for USB
> device 007/004[0]:error sending control message: Protocol error

Are you sure that this is a HID class device at all?

And if it turns out you'll need to perform simple communication that
has just been wrapped in HID class by someone for the wrong reasons,
then suggest using the HIDAPI by Signal 11 instead.


//Peter

_______________________________________________
libhid-discuss mailing list
libhid-discuss <at> lists.alioth.debian.org
http://lists.alioth.debian.org/mailman/listinfo/libhid-discuss
http://libhid.alioth.debian.org/



Thanks Peter,

Here is the output of : sudo lsusb -v (edited)

Bus 007 Device 004: ID 0461:0050 Primax Electronics, Ltd
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0         8
  idVendor           0x0461 Primax Electronics, Ltd
  idProduct          0x0050
  bcdDevice            0.0f
  iManufacturer           1
  iProduct                2
  iSerial                 0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           41
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0xc0
      Self Powered
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 No Subclass
      bInterfaceProtocol      0 None
      iInterface              0
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.00
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      32
          Report Descriptor: (length is -71)
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval             250
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval            
_______________________________________________
libhid-discuss mailing list
libhid-discuss <at> lists.alioth.debian.org
http://lists.alioth.debian.org/mailman/listinfo/libhid-discuss
http://libhid.alioth.debian.org/
Peter Stuge | 25 Feb 2011 21:51
Picon

Re: libhid::error sending control message: Protocol error !!

Mohamed Ait Ouaziz wrote:
> > > I try to write a user-space driver to control a usb device.
> >
> > Do you know how you will communicate with the device on top of USB?

Do you?

> > Separate from that, could you post lsusb -v output for the device?

Thanks for posting this. Indeed the device has a HID class interface,
but possibly libhid is sending some HID class request to the device,
which could legitimately fail.

Strongly recommend using HIDAPI. http://www.signal11.us/oss/hidapi/

//Peter

_______________________________________________
libhid-discuss mailing list
libhid-discuss <at> lists.alioth.debian.org
http://lists.alioth.debian.org/mailman/listinfo/libhid-discuss
http://libhid.alioth.debian.org/

Mohamed Ait Ouaziz | 25 Feb 2011 22:04
Picon

Re: libhid::error sending control message: Protocol error !!



2011/2/25 Peter Stuge <peter <at> stuge.se>
Mohamed Ait Ouaziz wrote:
> > > I try to write a user-space driver to control a usb device.
> >
> > Do you know how you will communicate with the device on top of USB?

Do you?

Actually i don't. My understanding is that  i after opening the device i will send and receive reports!!
 


> > Separate from that, could you post lsusb -v output for the device?

Thanks for posting this. Indeed the device has a HID class interface,
but possibly libhid is sending some HID class request to the device,
which could legitimately fail.

Strongly recommend using HIDAPI. http://www.signal11.us/oss/hidapi/

I will look at this and come back to you.
 

Thank you for your time.

Mohamed.
_______________________________________________
libhid-discuss mailing list
libhid-discuss <at> lists.alioth.debian.org
http://lists.alioth.debian.org/mailman/listinfo/libhid-discuss
http://libhid.alioth.debian.org/
Mohamed Ait Ouaziz | 25 Feb 2011 22:33
Picon

Re: libhid::error sending control message: Protocol error !!


Peter,

here is the simple code im trying to execute:


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>    // To define Have Bool!!
#include<hid.h>


//#define VENDOR_ID_PICARD     0x0461
//#define PRODUCT_ID_FILTER     0x0050
#define INPUTREPORT_SIZE    500

#define ITEM_INPUT 0x81
#define ITEM_OUTPUT 0x01

#define dev_id { 0x0461, 0x0050 ,  NULL, NULL, 0 }

int main(int argc, char *argv[])
{
    printf("Hello World!\n");
   
    HIDInterface* hid;
    hid_return ret;
    unsigned short vendor_id = 0x0461;
    unsigned short product_id = 0x0050;
   
    HIDInterfaceMatcher matcher = { vendor_id, product_id ,  NULL, NULL, 0 };
   
    hid_set_debug(HID_DEBUG_ALL);
    hid_set_debug_stream(stderr);
   
    ret = hid_init();
   
    if (ret != HID_RET_SUCCESS)
    {
        fprintf(stderr, "hid_init failed with return code %d\n", ret);
        return 1;
    }
   
    hid = hid_new_HIDInterface();
    if(hid == 0)
    {
        fprintf(stderr, "hid_new_HIDInterface! Out of memory?\n");
    }
   
   
    ret = hid_force_open(hid, 0, &matcher, 3);
    if (ret != HID_RET_SUCCESS)
    {
        fprintf(stderr, "hid_force_open failed with return code %d\n", ret);
        return 1;
    }
   
   
    ret = hid_write_identification(stdout, hid);
    if (ret != HID_RET_SUCCESS)
    {
        fprintf(stderr, "hid_write_identification failed with return code %d\n", ret);
        return 1;
    }
   
    ret = hid_dump_tree(stdout, hid);
    if (ret != HID_RET_SUCCESS)
    {
        fprintf(stderr, "hid_dump_tree failed with return code %d\n", ret);
        return 1;
    }
   
   
   
    return 0;
}


Do you have any idea about the origin of the error?


cheers,
Mohamed.
_______________________________________________
libhid-discuss mailing list
libhid-discuss <at> lists.alioth.debian.org
http://lists.alioth.debian.org/mailman/listinfo/libhid-discuss
http://libhid.alioth.debian.org/
Peter Stuge | 26 Feb 2011 02:17
Picon

Re: libhid::error sending control message: Protocol error !!

Hi Mohamad,

Mohamed Ait Ouaziz wrote:
> > > > > I try to write a user-space driver to control a usb device.
> > > >
> > > > Do you know how you will communicate with the device on top of USB?
> >
> > Do you?
> 
> Actually i don't. My understanding is that i after opening the
> device i will send and receive reports!!

Ah, sorry, this wasn't quite what I meant, but you are correct in
that reports are used for HID class devices.

What I mean is if you know (from vendor documentation, or from
reverse engineering) what you will put inside the reports, so to
speak.

That is the difficult part with any USB device.

> > Strongly recommend using HIDAPI. http://www.signal11.us/oss/hidapi/
> 
> I will look at this and come back to you.

Great! Depending on how the device communicates, HIDAPI can be
significantly more suitable than libhid or libusb. For devices
which are only freeriding on HID in order to avoid having a kernel
driver at all cost HIDAPI is frequently the better fit.

> Thank you for your time.

You're welcome!

Mohamed Ait Ouaziz wrote:
> Peter,
> 
> here is the simple code im trying to execute:

..

>     ret = hid_force_open(hid, 0, &matcher, 3);
>     ret = hid_write_identification(stdout, hid);
>     ret = hid_dump_tree(stdout, hid);
> 
>     return 0;
> }
> 
> Do you have any idea about the origin of the error?

The code looks good to me, although I'm not quite a libhid expert.

I still believe that the problem may be either in the device, or
between libhid and the device. Ie. I think it would be very useful
to test exchanging some data also with another library.

Your device is a little odd when it comes to USB, because it's USB
interface (this is a special term in the USB protocol) is HID class,
while the USB device is not. This can create complications. Would
suggest testing with HIDAPI, and if that also doesn't work then
either look into fixing HIDAPI or possibly use a kernel API directly.

//Peter

_______________________________________________
libhid-discuss mailing list
libhid-discuss <at> lists.alioth.debian.org
http://lists.alioth.debian.org/mailman/listinfo/libhid-discuss
http://libhid.alioth.debian.org/


Gmane