HIDRAW(4)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

✨ HIDRAW(4) ✨

okay so bestie, welcome to the HIDRAW(4) glow-up πŸ’… this is the Kernel Interfaces Manual tea, and we're about to spill it.


🌸 NAME 🌸

hidraw β€” Raw Access to HID devices. literally the VIP pass to your Human Interface Devices, no cap πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

so if you wanna compile this driver into the kernel (main character energy), you drop these lines into your kernel config file:

device hidraw
device hid
device hidbus

OR, if you'd rather load it as a module at boot time (lowkey more flexible), you put this line in loader.conf(5):

hidraw_load="YES"

slay, moving on ✨


πŸ’– DESCRIPTION πŸ’–

The hidraw driver gives you a raw interface to Human Interface Devices (HIDs). The reports go to and from the device unmodified β€” no processing, no filter, just pure vibes. πŸ¦‹

The device handles 2 sets of ioctl(2) calls:

πŸŽ€ FreeBSD uhid(4)-compatible calls:

  • HIDRAW_GET_REPORT_ID (int) β€” Grabs the report identifier this HID report is using. It's giving "what's your number?" energy πŸ’…
  • HIDRAW_GET_REPORT_DESC (struct hidraw_gen_descriptor) β€” Gets the HID report descriptor. Copies a maximum of hgd_maxlen bytes of the report descriptor data into the memory specified by hgd_data. Upon return, hgd_actlen is set to the number of bytes copied. Using this descriptor you can find the exact layout and meaning of data to/from the device. The report descriptor is delivered without any processing β€” raw and unfiltered, periodt. πŸ”₯
struct hidraw_gen_descriptor {
        void   *hgd_data;
        uint16_t hgd_maxlen;
        uint16_t hgd_actlen;
        uint8_t hgd_report_type;
        ...
};
  • HIDRAW_SET_IMMED (int) β€” Sets the device into a mode where each read(2) returns the current value of the input report. Normally a read(2) only returns data the device reports on its interrupt pipe. ngl this call may fail if the device doesn't support this feature 😭
  • HIDRAW_GET_REPORT (struct hidraw_gen_descriptor) β€” Gets a report from the device without waiting for data on the interrupt pipe. Copies a maximum of hgd_maxlen bytes of report data into the memory specified by hgd_data. Upon return, hgd_actlen is set to the number of bytes copied. The hgd_report_type field tells it which report you want β€” it should be HID_INPUT_REPORT, HID_OUTPUT_REPORT, or HID_FEATURE_REPORT. On a device using numbered reports, the first byte of returned data is the report number, and report data begins from the second byte. For devices without numbered reports, report data begins at the first byte. This call may fail if the device doesn't support it πŸ™ˆ
  • HIDRAW_SET_REPORT (struct hidraw_gen_descriptor) β€” Sets a report in the device. The hgd_report_type field indicates which report is to be set β€” should be HID_INPUT_REPORT, HID_OUTPUT_REPORT, or HID_FEATURE_REPORT. The value is specified by hgd_data and hgd_maxlen fields. On devices with numbered reports, the first byte of data sent is the report number, and report data begins from the second byte. For devices without numbered reports, report data begins at the first byte. May fail if the device doesn't support this feature πŸ’€
  • HIDRAW_GET_DEVICEINFO (struct hidraw_device_info) β€” Returns info about the device, like vendor ID and product ID. This call will not issue any hardware transfers β€” it's all vibes, no hardware drama ✨

🧚 Linux hidraw-compatible calls:

  • HIDIOCGRDESCSIZE (int) β€” Gets the HID report descriptor size. Returns the size of the device report descriptor to use with HIDIOCGRDESC ioctl(2). iconic πŸ‘‘
  • HIDIOCGRDESC (struct hidraw_report_descriptor) β€” Gets the HID report descriptor. Copies a maximum of size bytes of report descriptor data into the memory specified by value. πŸŽ€
struct hidraw_report_descriptor {
        uint32_t        size;
        uint8_t         value[HID_MAX_DESCRIPTOR_SIZE];
};
  • HIDIOCGRAWINFO (struct hidraw_devinfo) β€” Gets a structure containing the bus type, vendor ID (VID), and product ID (PID) of the device. Bus type can be BUS_USB or BUS_I2C, which are defined in dev/evdev/input.h. πŸ¦‹
struct hidraw_devinfo {
        uint32_t        bustype;
        int16_t         vendor;
        int16_t         product;
};
  • HIDIOCGRAWNAME(len) (char[] buf) β€” Gets device description. Copies a maximum of len bytes of the device description (previously set with device_set_desc(9) procedure) into the memory specified by buf. πŸ’–
  • HIDIOCGRAWPHYS(len) (char[] buf) β€” Gets the newbus path to the device. Copies a maximum of len bytes of the newbus device path into the memory specified by buf. slay 🌸
  • HIDIOCGFEATURE(len) (void[] buf)
  • HIDIOCGINPUT(len) (void[] buf)
  • HIDIOCGOUTPUT(len) (void[] buf)

Get respectively a feature, input, or output report from the device. Copies a maximum of len bytes of report data into the memory specified by buf. The first byte of the supplied buffer should be set to the report number of the requested report. For devices without numbered reports, set the first byte to 0. The report will be returned starting at the first byte of the buffer (ie: the report number is not returned). This call may fail if the device doesn't support this feature 😭

  • HIDIOCSFEATURE(len) (void[] buf)
  • HIDIOCSINPUT(len) (void[] buf)
  • HIDIOCSOUTPUT(len) (void[] buf)

Set respectively a feature, input, or output report in the device. Value of the report is specified by the buf and len parameters. Set the first byte of the supplied buffer to the report number. For devices without numbered reports, set the first byte to 0. Report data begins in the second byte. Make sure to set len accordingly, to one more than the length of the report (to account for the report number). This call may fail if the device doesn't support this feature. fr fr πŸ’…


Use read(2) to get data from the device. Data should be read in chunks of the size prescribed by the report descriptor. On devices using numbered reports, the first byte of returned data is the report number, and report data begins from the second byte. For devices without numbered reports, report data begins at the first byte. 🫢

Use write(2) to send data to the device. Data should be written in chunks of the size prescribed by the report descriptor. The first byte of the buffer passed to write(2) should be set to the report number. If the device doesn't use numbered reports, there are 2 operation modes: hidraw mode and uhid(4) mode. In hidraw mode, the first byte should be set to 0 and report data itself should begin at the second byte. In uhid(4) mode, report data should begin at the first byte. The modes can be switched by issuing one of HIDIOCGRDESC or HID_GET_REPORT_DESC ioctl(2) accordingly. Default mode is hidraw. periodt. ✨


πŸ’œ SYSCTL VARIABLES πŸ’œ

The following variables are available as both sysctl(8) variables and loader(8) tunables:

  • hw.hid.hidraw.debug β€” Debug output level, where 0 is debugging disabled and larger values increase debug message verbosity. Default is 0. ngl this is the "how much tea do you want in your logs" dial πŸ“

🌈 FILES 🌈

/dev/hidraw? β€” that's the spot, bestie πŸ‘‘


⭐ SEE ALSO ⭐

usbhidctl(1), hid(4), hidbus(4), uhid(4) β€” go read these too, they're iconic in their own right πŸ¦‹


πŸŽ€ HISTORY πŸŽ€

The uhid(4) driver appeared in NetBSD 1.4. hidraw protocol support was added in FreeBSD 13 by Vladimir Kondratyev <wulf@FreeBSD.org>. This manual page was adopted from NetBSD by Tom Rhodes <trhodes@FreeBSD.org> in April 2002. we stan the OGs πŸ’–


okay that's the whole tea, bestie 🫢 this HIDRAW(4) page is from the Debian manual, dated April 27, 2025 β€” go forth and slay your HID game πŸ’…βœ¨πŸŒΈ

πŸ“¦ where this page comes from