﻿# hidraw report IDs: read and write buffers have different prefix rules

Do not strip or insert a report-ID byte uniformly in Linux hidraw sensor input. Numbered reads, unnumbered reads and writes follow distinct documented buffer contracts.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/edge-linux-hidraw-report-id-read-write/
Language: en

## A symmetric wrapper shifts the sensor payload

An edge application wraps hidraw reads and writes with one rule: reserve the first byte for a report identifier. It works with a numbered fixture, then drops the first real measurement byte from an unnumbered device’s input. The resulting vector may retain the expected shape after later padding and still contain incorrect values. Review the operation-specific interface instead of treating every raw HID buffer as the same envelope. The descriptor and actual read contract determine where input payload begins.

## Numbered and unnumbered reads differ

The [hidraw API documentation](https://docs.kernel.org/hid/hidraw.html) states that a numbered read returns the report number first, followed by report data. For unnumbered reports, data begins in the first byte. Do not invent a leading zero in the received payload or discard a byte merely because the write path reserves one. Keep returned length and report identity with the raw input. A short or unsupported report should remain an explicit parser outcome rather than being silently padded into a plausible sample.

## Writes retain their own report-number slot

The same API requires the write buffer’s first byte to contain the report number, using 0 when the device is unnumbered; data follows that slot. This is the Linux hidraw write interface, not a universal claim that an unnumbered device emits that extra byte on input. Separate construction and parsing routines or make the operation contract explicit in a shared abstraction. A round-trip test that compares raw read and write lengths without accounting for this asymmetry can validate the wrong wrapper behavior.

## The descriptor selects more than a byte offset

The [HID descriptor introduction](https://docs.kernel.org/hid/hidintro.html) explains that Report IDs distinguish report structures and that Input, Output and Feature reports have different roles. Preserve the selected layout, bit fields and logical interpretation rather than sending every identifier through one sensor decoder. An identifier is not itself a measurement. Nonconforming devices can require a specifically documented path; raw access does not parse or certify their semantics automatically. Keep device-specific exceptions explicit instead of turning one unusual fixture into a global prefix rule.

## Propose separate input and output fixtures

Create harmless numbered and unnumbered report fixtures with recognizable first payload bytes. Verify that parsing preserves those bytes under the documented read rule and that output construction uses its separate report-number slot. Include an unknown report identifier and truncated data for explicit rejection. Exercise the declared descriptor layout before model inference. Acceptance requires exact feature extraction, not just matching tensor length. No HID device was opened, configured or written here; these are buffer-contract checks without a claimed device compatibility measurement.

## Keep raw framing separate from classification quality

[Binary tensor boundaries](/journal/guide-triton-binary-offset/) explain why payload offsets need a real contract. [Device-input metadata](/journal/fg2-onnxruntime-io-binding-device-buffer-lifetime/) explains why an address and shape are incomplete. Hidraw adds a descriptor- and operation-specific prefix boundary. Record it with the raw fixture and extracted features so a sensor-input shift is not mistaken for a model regression. Correct parsing establishes the intended input representation, leaving actual classification quality and physical calibration to their own evidence.
