18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
28c2ecf20Sopenharmony_ci#ifndef __UHID_H_
38c2ecf20Sopenharmony_ci#define __UHID_H_
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci/*
68c2ecf20Sopenharmony_ci * User-space I/O driver support for HID subsystem
78c2ecf20Sopenharmony_ci * Copyright (c) 2012 David Herrmann
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci/*
118c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify it
128c2ecf20Sopenharmony_ci * under the terms of the GNU General Public License as published by the Free
138c2ecf20Sopenharmony_ci * Software Foundation; either version 2 of the License, or (at your option)
148c2ecf20Sopenharmony_ci * any later version.
158c2ecf20Sopenharmony_ci */
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci/*
188c2ecf20Sopenharmony_ci * Public header for user-space communication. We try to keep every structure
198c2ecf20Sopenharmony_ci * aligned but to be safe we also use __attribute__((__packed__)). Therefore,
208c2ecf20Sopenharmony_ci * the communication should be ABI compatible even between architectures.
218c2ecf20Sopenharmony_ci */
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#include <linux/input.h>
248c2ecf20Sopenharmony_ci#include <linux/types.h>
258c2ecf20Sopenharmony_ci#include <linux/hid.h>
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_cienum uhid_event_type {
288c2ecf20Sopenharmony_ci	__UHID_LEGACY_CREATE,
298c2ecf20Sopenharmony_ci	UHID_DESTROY,
308c2ecf20Sopenharmony_ci	UHID_START,
318c2ecf20Sopenharmony_ci	UHID_STOP,
328c2ecf20Sopenharmony_ci	UHID_OPEN,
338c2ecf20Sopenharmony_ci	UHID_CLOSE,
348c2ecf20Sopenharmony_ci	UHID_OUTPUT,
358c2ecf20Sopenharmony_ci	__UHID_LEGACY_OUTPUT_EV,
368c2ecf20Sopenharmony_ci	__UHID_LEGACY_INPUT,
378c2ecf20Sopenharmony_ci	UHID_GET_REPORT,
388c2ecf20Sopenharmony_ci	UHID_GET_REPORT_REPLY,
398c2ecf20Sopenharmony_ci	UHID_CREATE2,
408c2ecf20Sopenharmony_ci	UHID_INPUT2,
418c2ecf20Sopenharmony_ci	UHID_SET_REPORT,
428c2ecf20Sopenharmony_ci	UHID_SET_REPORT_REPLY,
438c2ecf20Sopenharmony_ci};
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_cistruct uhid_create2_req {
468c2ecf20Sopenharmony_ci	__u8 name[128];
478c2ecf20Sopenharmony_ci	__u8 phys[64];
488c2ecf20Sopenharmony_ci	__u8 uniq[64];
498c2ecf20Sopenharmony_ci	__u16 rd_size;
508c2ecf20Sopenharmony_ci	__u16 bus;
518c2ecf20Sopenharmony_ci	__u32 vendor;
528c2ecf20Sopenharmony_ci	__u32 product;
538c2ecf20Sopenharmony_ci	__u32 version;
548c2ecf20Sopenharmony_ci	__u32 country;
558c2ecf20Sopenharmony_ci	__u8 rd_data[HID_MAX_DESCRIPTOR_SIZE];
568c2ecf20Sopenharmony_ci} __attribute__((__packed__));
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cienum uhid_dev_flag {
598c2ecf20Sopenharmony_ci	UHID_DEV_NUMBERED_FEATURE_REPORTS			= (1ULL << 0),
608c2ecf20Sopenharmony_ci	UHID_DEV_NUMBERED_OUTPUT_REPORTS			= (1ULL << 1),
618c2ecf20Sopenharmony_ci	UHID_DEV_NUMBERED_INPUT_REPORTS				= (1ULL << 2),
628c2ecf20Sopenharmony_ci};
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_cistruct uhid_start_req {
658c2ecf20Sopenharmony_ci	__u64 dev_flags;
668c2ecf20Sopenharmony_ci};
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci#define UHID_DATA_MAX 4096
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_cienum uhid_report_type {
718c2ecf20Sopenharmony_ci	UHID_FEATURE_REPORT,
728c2ecf20Sopenharmony_ci	UHID_OUTPUT_REPORT,
738c2ecf20Sopenharmony_ci	UHID_INPUT_REPORT,
748c2ecf20Sopenharmony_ci};
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_cistruct uhid_input2_req {
778c2ecf20Sopenharmony_ci	__u16 size;
788c2ecf20Sopenharmony_ci	__u8 data[UHID_DATA_MAX];
798c2ecf20Sopenharmony_ci} __attribute__((__packed__));
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_cistruct uhid_output_req {
828c2ecf20Sopenharmony_ci	__u8 data[UHID_DATA_MAX];
838c2ecf20Sopenharmony_ci	__u16 size;
848c2ecf20Sopenharmony_ci	__u8 rtype;
858c2ecf20Sopenharmony_ci} __attribute__((__packed__));
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_cistruct uhid_get_report_req {
888c2ecf20Sopenharmony_ci	__u32 id;
898c2ecf20Sopenharmony_ci	__u8 rnum;
908c2ecf20Sopenharmony_ci	__u8 rtype;
918c2ecf20Sopenharmony_ci} __attribute__((__packed__));
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_cistruct uhid_get_report_reply_req {
948c2ecf20Sopenharmony_ci	__u32 id;
958c2ecf20Sopenharmony_ci	__u16 err;
968c2ecf20Sopenharmony_ci	__u16 size;
978c2ecf20Sopenharmony_ci	__u8 data[UHID_DATA_MAX];
988c2ecf20Sopenharmony_ci} __attribute__((__packed__));
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_cistruct uhid_set_report_req {
1018c2ecf20Sopenharmony_ci	__u32 id;
1028c2ecf20Sopenharmony_ci	__u8 rnum;
1038c2ecf20Sopenharmony_ci	__u8 rtype;
1048c2ecf20Sopenharmony_ci	__u16 size;
1058c2ecf20Sopenharmony_ci	__u8 data[UHID_DATA_MAX];
1068c2ecf20Sopenharmony_ci} __attribute__((__packed__));
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_cistruct uhid_set_report_reply_req {
1098c2ecf20Sopenharmony_ci	__u32 id;
1108c2ecf20Sopenharmony_ci	__u16 err;
1118c2ecf20Sopenharmony_ci} __attribute__((__packed__));
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci/*
1148c2ecf20Sopenharmony_ci * Compat Layer
1158c2ecf20Sopenharmony_ci * All these commands and requests are obsolete. You should avoid using them in
1168c2ecf20Sopenharmony_ci * new code. We support them for backwards-compatibility, but you might not get
1178c2ecf20Sopenharmony_ci * access to new feature in case you use them.
1188c2ecf20Sopenharmony_ci */
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_cienum uhid_legacy_event_type {
1218c2ecf20Sopenharmony_ci	UHID_CREATE			= __UHID_LEGACY_CREATE,
1228c2ecf20Sopenharmony_ci	UHID_OUTPUT_EV			= __UHID_LEGACY_OUTPUT_EV,
1238c2ecf20Sopenharmony_ci	UHID_INPUT			= __UHID_LEGACY_INPUT,
1248c2ecf20Sopenharmony_ci	UHID_FEATURE			= UHID_GET_REPORT,
1258c2ecf20Sopenharmony_ci	UHID_FEATURE_ANSWER		= UHID_GET_REPORT_REPLY,
1268c2ecf20Sopenharmony_ci};
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci/* Obsolete! Use UHID_CREATE2. */
1298c2ecf20Sopenharmony_cistruct uhid_create_req {
1308c2ecf20Sopenharmony_ci	__u8 name[128];
1318c2ecf20Sopenharmony_ci	__u8 phys[64];
1328c2ecf20Sopenharmony_ci	__u8 uniq[64];
1338c2ecf20Sopenharmony_ci	__u8 __user *rd_data;
1348c2ecf20Sopenharmony_ci	__u16 rd_size;
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci	__u16 bus;
1378c2ecf20Sopenharmony_ci	__u32 vendor;
1388c2ecf20Sopenharmony_ci	__u32 product;
1398c2ecf20Sopenharmony_ci	__u32 version;
1408c2ecf20Sopenharmony_ci	__u32 country;
1418c2ecf20Sopenharmony_ci} __attribute__((__packed__));
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci/* Obsolete! Use UHID_INPUT2. */
1448c2ecf20Sopenharmony_cistruct uhid_input_req {
1458c2ecf20Sopenharmony_ci	__u8 data[UHID_DATA_MAX];
1468c2ecf20Sopenharmony_ci	__u16 size;
1478c2ecf20Sopenharmony_ci} __attribute__((__packed__));
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci/* Obsolete! Kernel uses UHID_OUTPUT exclusively now. */
1508c2ecf20Sopenharmony_cistruct uhid_output_ev_req {
1518c2ecf20Sopenharmony_ci	__u16 type;
1528c2ecf20Sopenharmony_ci	__u16 code;
1538c2ecf20Sopenharmony_ci	__s32 value;
1548c2ecf20Sopenharmony_ci} __attribute__((__packed__));
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci/* Obsolete! Kernel uses ABI compatible UHID_GET_REPORT. */
1578c2ecf20Sopenharmony_cistruct uhid_feature_req {
1588c2ecf20Sopenharmony_ci	__u32 id;
1598c2ecf20Sopenharmony_ci	__u8 rnum;
1608c2ecf20Sopenharmony_ci	__u8 rtype;
1618c2ecf20Sopenharmony_ci} __attribute__((__packed__));
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci/* Obsolete! Use ABI compatible UHID_GET_REPORT_REPLY. */
1648c2ecf20Sopenharmony_cistruct uhid_feature_answer_req {
1658c2ecf20Sopenharmony_ci	__u32 id;
1668c2ecf20Sopenharmony_ci	__u16 err;
1678c2ecf20Sopenharmony_ci	__u16 size;
1688c2ecf20Sopenharmony_ci	__u8 data[UHID_DATA_MAX];
1698c2ecf20Sopenharmony_ci} __attribute__((__packed__));
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci/*
1728c2ecf20Sopenharmony_ci * UHID Events
1738c2ecf20Sopenharmony_ci * All UHID events from and to the kernel are encoded as "struct uhid_event".
1748c2ecf20Sopenharmony_ci * The "type" field contains a UHID_* type identifier. All payload depends on
1758c2ecf20Sopenharmony_ci * that type and can be accessed via ev->u.XYZ accordingly.
1768c2ecf20Sopenharmony_ci * If user-space writes short events, they're extended with 0s by the kernel. If
1778c2ecf20Sopenharmony_ci * the kernel writes short events, user-space shall extend them with 0s.
1788c2ecf20Sopenharmony_ci */
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_cistruct uhid_event {
1818c2ecf20Sopenharmony_ci	__u32 type;
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci	union {
1848c2ecf20Sopenharmony_ci		struct uhid_create_req create;
1858c2ecf20Sopenharmony_ci		struct uhid_input_req input;
1868c2ecf20Sopenharmony_ci		struct uhid_output_req output;
1878c2ecf20Sopenharmony_ci		struct uhid_output_ev_req output_ev;
1888c2ecf20Sopenharmony_ci		struct uhid_feature_req feature;
1898c2ecf20Sopenharmony_ci		struct uhid_get_report_req get_report;
1908c2ecf20Sopenharmony_ci		struct uhid_feature_answer_req feature_answer;
1918c2ecf20Sopenharmony_ci		struct uhid_get_report_reply_req get_report_reply;
1928c2ecf20Sopenharmony_ci		struct uhid_create2_req create2;
1938c2ecf20Sopenharmony_ci		struct uhid_input2_req input2;
1948c2ecf20Sopenharmony_ci		struct uhid_set_report_req set_report;
1958c2ecf20Sopenharmony_ci		struct uhid_set_report_reply_req set_report_reply;
1968c2ecf20Sopenharmony_ci		struct uhid_start_req start;
1978c2ecf20Sopenharmony_ci	} u;
1988c2ecf20Sopenharmony_ci} __attribute__((__packed__));
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci#endif /* __UHID_H_ */
201