/* * The tablet send these values when the pad buttons are pressed individually: * * Buttons released: 06 00 00 00 00 00 00 00 * Button 1: 06 00 05 00 00 00 00 00 -> b * Button 2: 06 00 08 00 00 00 00 00 -> e * Button 3: 06 04 00 00 00 00 00 00 -> LAlt * Button 4: 06 00 2c 00 00 00 00 00 -> Space * Button 5: 06 01 16 00 00 00 00 00 -> LControl + s * Button 6: 06 01 1d 00 00 00 00 00 -> LControl + z * * When multiple buttons are pressed at the same time, the values used to * identify the buttons are identical, but they appear in different bytes of the * record. For example, when button 2 (0x08) and button 1 (0x05) are pressed, * this is the report: * * Buttons 2 and 1: 06 00 08 05 00 00 00 00 -> e + b * * Buttons 1, 2, 4, 5 and 6 can be matched by finding their values in the * report. * * Button 3 is pressed when the 3rd bit is 1. For example, pressing buttons 3 * and 5 generates this report: * * Buttons 3 and 5: 06 05 16 00 00 00 00 00 -> LControl + LAlt + s * -- -- * | | * | `- Button 5 (0x16) * `- 0x05 = 0101. Button 3 is pressed * ^ * * pad_buttons contains a list of buttons that can be matched in * HID_BPF_DEVICE_EVENT. Button 3 as it has a dedicated bit.
*/ staticconst __u8 pad_buttons[] = { 0x05, 0x08, 0x00, 0x2C, 0x16, 0x1D };
/* data[1] stores the status of BTN_2 in the 3rd bit*/ if (data[1] & BIT(2))
button_mask |= BIT(2);
/* The rest of the descriptor stores the buttons as in pad_buttons */ for (d = 2; d < 8; d++) { for (b = 0; b < sizeof(pad_buttons); b++) { if (data[d] != 0 && data[d] == pad_buttons[b])
button_mask |= BIT(b);
}
}
SEC("syscall") int probe(struct hid_bpf_probe_args *ctx)
{ /* * The device has 2 modes: The compatibility mode, enabled by default, * and the raw mode, that can be activated by sending a buffer of magic * data to a certain USB endpoint. * * Depending on the mode, different interfaces of the device are used: * - First interface: Pad in compatibility mode * - Second interface: Pen in compatibility mode * - Third interface: Only used in raw mode * * We'll use the device in compatibility mode.
*/
ctx->retval = ctx->rdesc_size != RDESC_SIZE_PAD &&
ctx->rdesc_size != RDESC_SIZE_PEN; if (ctx->retval)
ctx->retval = -EINVAL;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.