Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
0002 #ifndef __UHID_H_
0003 #define __UHID_H_
0004 
0005 /*
0006  * User-space I/O driver support for HID subsystem
0007  * Copyright (c) 2012 David Herrmann
0008  */
0009 
0010 /*
0011  * This program is free software; you can redistribute it and/or modify it
0012  * under the terms of the GNU General Public License as published by the Free
0013  * Software Foundation; either version 2 of the License, or (at your option)
0014  * any later version.
0015  */
0016 
0017 /*
0018  * Public header for user-space communication. We try to keep every structure
0019  * aligned but to be safe we also use __attribute__((__packed__)). Therefore,
0020  * the communication should be ABI compatible even between architectures.
0021  */
0022 
0023 #include <linux/input.h>
0024 #include <linux/types.h>
0025 #include <linux/hid.h>
0026 
0027 enum uhid_event_type {
0028     __UHID_LEGACY_CREATE,
0029     UHID_DESTROY,
0030     UHID_START,
0031     UHID_STOP,
0032     UHID_OPEN,
0033     UHID_CLOSE,
0034     UHID_OUTPUT,
0035     __UHID_LEGACY_OUTPUT_EV,
0036     __UHID_LEGACY_INPUT,
0037     UHID_GET_REPORT,
0038     UHID_GET_REPORT_REPLY,
0039     UHID_CREATE2,
0040     UHID_INPUT2,
0041     UHID_SET_REPORT,
0042     UHID_SET_REPORT_REPLY,
0043 };
0044 
0045 struct uhid_create2_req {
0046     __u8 name[128];
0047     __u8 phys[64];
0048     __u8 uniq[64];
0049     __u16 rd_size;
0050     __u16 bus;
0051     __u32 vendor;
0052     __u32 product;
0053     __u32 version;
0054     __u32 country;
0055     __u8 rd_data[HID_MAX_DESCRIPTOR_SIZE];
0056 } __attribute__((__packed__));
0057 
0058 enum uhid_dev_flag {
0059     UHID_DEV_NUMBERED_FEATURE_REPORTS           = (1ULL << 0),
0060     UHID_DEV_NUMBERED_OUTPUT_REPORTS            = (1ULL << 1),
0061     UHID_DEV_NUMBERED_INPUT_REPORTS             = (1ULL << 2),
0062 };
0063 
0064 struct uhid_start_req {
0065     __u64 dev_flags;
0066 };
0067 
0068 #define UHID_DATA_MAX 4096
0069 
0070 enum uhid_report_type {
0071     UHID_FEATURE_REPORT,
0072     UHID_OUTPUT_REPORT,
0073     UHID_INPUT_REPORT,
0074 };
0075 
0076 struct uhid_input2_req {
0077     __u16 size;
0078     __u8 data[UHID_DATA_MAX];
0079 } __attribute__((__packed__));
0080 
0081 struct uhid_output_req {
0082     __u8 data[UHID_DATA_MAX];
0083     __u16 size;
0084     __u8 rtype;
0085 } __attribute__((__packed__));
0086 
0087 struct uhid_get_report_req {
0088     __u32 id;
0089     __u8 rnum;
0090     __u8 rtype;
0091 } __attribute__((__packed__));
0092 
0093 struct uhid_get_report_reply_req {
0094     __u32 id;
0095     __u16 err;
0096     __u16 size;
0097     __u8 data[UHID_DATA_MAX];
0098 } __attribute__((__packed__));
0099 
0100 struct uhid_set_report_req {
0101     __u32 id;
0102     __u8 rnum;
0103     __u8 rtype;
0104     __u16 size;
0105     __u8 data[UHID_DATA_MAX];
0106 } __attribute__((__packed__));
0107 
0108 struct uhid_set_report_reply_req {
0109     __u32 id;
0110     __u16 err;
0111 } __attribute__((__packed__));
0112 
0113 /*
0114  * Compat Layer
0115  * All these commands and requests are obsolete. You should avoid using them in
0116  * new code. We support them for backwards-compatibility, but you might not get
0117  * access to new feature in case you use them.
0118  */
0119 
0120 enum uhid_legacy_event_type {
0121     UHID_CREATE         = __UHID_LEGACY_CREATE,
0122     UHID_OUTPUT_EV          = __UHID_LEGACY_OUTPUT_EV,
0123     UHID_INPUT          = __UHID_LEGACY_INPUT,
0124     UHID_FEATURE            = UHID_GET_REPORT,
0125     UHID_FEATURE_ANSWER     = UHID_GET_REPORT_REPLY,
0126 };
0127 
0128 /* Obsolete! Use UHID_CREATE2. */
0129 struct uhid_create_req {
0130     __u8 name[128];
0131     __u8 phys[64];
0132     __u8 uniq[64];
0133     __u8 __user *rd_data;
0134     __u16 rd_size;
0135 
0136     __u16 bus;
0137     __u32 vendor;
0138     __u32 product;
0139     __u32 version;
0140     __u32 country;
0141 } __attribute__((__packed__));
0142 
0143 /* Obsolete! Use UHID_INPUT2. */
0144 struct uhid_input_req {
0145     __u8 data[UHID_DATA_MAX];
0146     __u16 size;
0147 } __attribute__((__packed__));
0148 
0149 /* Obsolete! Kernel uses UHID_OUTPUT exclusively now. */
0150 struct uhid_output_ev_req {
0151     __u16 type;
0152     __u16 code;
0153     __s32 value;
0154 } __attribute__((__packed__));
0155 
0156 /* Obsolete! Kernel uses ABI compatible UHID_GET_REPORT. */
0157 struct uhid_feature_req {
0158     __u32 id;
0159     __u8 rnum;
0160     __u8 rtype;
0161 } __attribute__((__packed__));
0162 
0163 /* Obsolete! Use ABI compatible UHID_GET_REPORT_REPLY. */
0164 struct uhid_feature_answer_req {
0165     __u32 id;
0166     __u16 err;
0167     __u16 size;
0168     __u8 data[UHID_DATA_MAX];
0169 } __attribute__((__packed__));
0170 
0171 /*
0172  * UHID Events
0173  * All UHID events from and to the kernel are encoded as "struct uhid_event".
0174  * The "type" field contains a UHID_* type identifier. All payload depends on
0175  * that type and can be accessed via ev->u.XYZ accordingly.
0176  * If user-space writes short events, they're extended with 0s by the kernel. If
0177  * the kernel writes short events, user-space shall extend them with 0s.
0178  */
0179 
0180 struct uhid_event {
0181     __u32 type;
0182 
0183     union {
0184         struct uhid_create_req create;
0185         struct uhid_input_req input;
0186         struct uhid_output_req output;
0187         struct uhid_output_ev_req output_ev;
0188         struct uhid_feature_req feature;
0189         struct uhid_get_report_req get_report;
0190         struct uhid_feature_answer_req feature_answer;
0191         struct uhid_get_report_reply_req get_report_reply;
0192         struct uhid_create2_req create2;
0193         struct uhid_input2_req input2;
0194         struct uhid_set_report_req set_report;
0195         struct uhid_set_report_reply_req set_report_reply;
0196         struct uhid_start_req start;
0197     } u;
0198 } __attribute__((__packed__));
0199 
0200 #endif /* __UHID_H_ */