Hooks and how they are called

Hooks and how they are called

The linux HID subsystem offers kernel driver programmers a whole bunch of hooks to insert custom code before, after and while automatic processing. Those hooks are defined in <linux/hid.h>, unfortunately they aren’t documented very well.

Table of contents

raw_event hook

The raw_event hook is called whenever a HID report comes in. Every report the device can send (or receive) is described by the devices report descriptor.

Before the hook is called, a list named report_table is checked for the specific report, if it isn’t in it, the report is not passed to the raw_event hook. When report_table is not defined (NULL), then every report is passed to the hook.

parameters

struct hid_device *hdev
struct hid_report *report
u8 *data
int size

return code (int)

-1error
0continue automatic processing (no action performed)
1no further (automatic) processing

event hook

The event hook is called for every event which was automatically processed from the report. That means, if a report comes in – hid-core will automatically process it and divide it into several events. When one of those events fits the descriptions in usage_table (or when usage_table is NULL), then the event_hook is called.

What that means is, that a report which contains more than one fields (like ten buttons and four axis), a event is created for every one – and not only for the one which changed.

parameters

struct hid_device *hdev
struct hid_field *field
struct hid_usage *usage
__s32 value

return code (int)

-1error
0continue automatic processing (no action performed)
1no further (automatic) processing