Getting information about the HID device

The hiddev interface supports getting information associated with the device using the HIDIOCGDEVINFO ioctl. The argument is a pointer to a hiddev_devinfo structure.

The hiddev_devinfo structure is defined as:

struct hiddev_devinfo {
        unsigned int bustype;
        unsigned int busnum;
        unsigned int devnum;
        unsigned int ifnum;
        short vendor;
        short product;
        short version;
        unsigned num_applications;
};

Lets look at an example of the HIDIOCDEVINFO ioctl call.

NoteAbout this example
 

This example is intentionally a code fragment, and is not complete,nor is it meant to show good programming style.

A complete form of this example (that will compile with gcc -Wall -W) is provided in the second part of this document.

Example 2. HIDIOCDEVINFO example

  /* suck out some device information */
  ioctl(fd, HIDIOCGDEVINFO, &device_info);

  printf("vendor 0x%04hx product 0x%04hx version 0x%04hx ",
          device_info.vendor, device_info.product, device_info.version);
  printf("has %i application%s ", device_info.num_applications,
         (device_info.num_applications==1?"":"s"));
  printf("and is on bus: %d devnum: %d ifnum: %d\n",
         device_info.busnum, device_info.devnum, device_info.ifnum);

The vendor, product and version fields correspond to the vendor identification, product identification and BCD revision of the device.

The busnum, devnum and ifnum fields correspond to the logical location of the device on the USB bus.

The num_applications field is the number of applications in the HID descriptor.