Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
0002 /*
0003  *  Copyright (c) 1999-2000 Vojtech Pavlik
0004  *
0005  *  Sponsored by SuSE
0006  */
0007 /*
0008  * This program is free software; you can redistribute it and/or modify
0009  * it under the terms of the GNU General Public License as published by
0010  * the Free Software Foundation; either version 2 of the License, or 
0011  * (at your option) any later version.
0012  * 
0013  * This program is distributed in the hope that it will be useful,
0014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0016  * GNU General Public License for more details.
0017  * 
0018  * You should have received a copy of the GNU General Public License
0019  * along with this program; if not, write to the Free Software
0020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0021  * 
0022  * Should you need to contact me, the author, you can do so either by
0023  * e-mail - mail your message to <vojtech@suse.cz>, or by paper mail:
0024  * Vojtech Pavlik, Ucitelska 1576, Prague 8, 182 00 Czech Republic
0025  */
0026 #ifndef _UAPI_HIDDEV_H
0027 #define _UAPI_HIDDEV_H
0028 
0029 
0030 
0031 #include <linux/types.h>
0032 
0033 /*
0034  * The event structure itself
0035  */
0036 
0037 struct hiddev_event {
0038     unsigned hid;
0039     signed int value;
0040 };
0041 
0042 struct hiddev_devinfo {
0043     __u32 bustype;
0044     __u32 busnum;
0045     __u32 devnum;
0046     __u32 ifnum;
0047     __s16 vendor;
0048     __s16 product;
0049     __s16 version;
0050     __u32 num_applications;
0051 };
0052 
0053 struct hiddev_collection_info {
0054     __u32 index;
0055     __u32 type;
0056     __u32 usage;
0057     __u32 level;
0058 };
0059 
0060 #define HID_STRING_SIZE 256
0061 struct hiddev_string_descriptor {
0062     __s32 index;
0063     char value[HID_STRING_SIZE];
0064 };
0065 
0066 struct hiddev_report_info {
0067     __u32 report_type;
0068     __u32 report_id;
0069     __u32 num_fields;
0070 };
0071 
0072 /* To do a GUSAGE/SUSAGE, fill in at least usage_code,  report_type and 
0073  * report_id.  Set report_id to REPORT_ID_UNKNOWN if the rest of the fields 
0074  * are unknown.  Otherwise use a usage_ref struct filled in from a previous 
0075  * successful GUSAGE call to save time.  To actually send a value to the
0076  * device, perform a SUSAGE first, followed by a SREPORT.  An INITREPORT or a
0077  * GREPORT isn't necessary for a GUSAGE to return valid data.
0078  */
0079 #define HID_REPORT_ID_UNKNOWN 0xffffffff
0080 #define HID_REPORT_ID_FIRST   0x00000100
0081 #define HID_REPORT_ID_NEXT    0x00000200
0082 #define HID_REPORT_ID_MASK    0x000000ff
0083 #define HID_REPORT_ID_MAX     0x000000ff
0084 
0085 #define HID_REPORT_TYPE_INPUT   1
0086 #define HID_REPORT_TYPE_OUTPUT  2
0087 #define HID_REPORT_TYPE_FEATURE 3
0088 #define HID_REPORT_TYPE_MIN     1
0089 #define HID_REPORT_TYPE_MAX     3
0090 
0091 struct hiddev_field_info {
0092     __u32 report_type;
0093     __u32 report_id;
0094     __u32 field_index;
0095     __u32 maxusage;
0096     __u32 flags;
0097     __u32 physical;     /* physical usage for this field */
0098     __u32 logical;      /* logical usage for this field */
0099     __u32 application;      /* application usage for this field */
0100     __s32 logical_minimum;
0101     __s32 logical_maximum;
0102     __s32 physical_minimum;
0103     __s32 physical_maximum;
0104     __u32 unit_exponent;
0105     __u32 unit;
0106 };
0107 
0108 /* Fill in report_type, report_id and field_index to get the information on a
0109  * field.
0110  */
0111 #define HID_FIELD_CONSTANT      0x001
0112 #define HID_FIELD_VARIABLE      0x002
0113 #define HID_FIELD_RELATIVE      0x004
0114 #define HID_FIELD_WRAP          0x008   
0115 #define HID_FIELD_NONLINEAR     0x010
0116 #define HID_FIELD_NO_PREFERRED      0x020
0117 #define HID_FIELD_NULL_STATE        0x040
0118 #define HID_FIELD_VOLATILE      0x080
0119 #define HID_FIELD_BUFFERED_BYTE     0x100
0120 
0121 struct hiddev_usage_ref {
0122     __u32 report_type;
0123     __u32 report_id;
0124     __u32 field_index;
0125     __u32 usage_index;
0126     __u32 usage_code;
0127     __s32 value;
0128 };
0129 
0130 /* hiddev_usage_ref_multi is used for sending multiple bytes to a control.
0131  * It really manifests itself as setting the value of consecutive usages */
0132 #define HID_MAX_MULTI_USAGES 1024
0133 struct hiddev_usage_ref_multi {
0134     struct hiddev_usage_ref uref;
0135     __u32 num_values;
0136     __s32 values[HID_MAX_MULTI_USAGES];
0137 };
0138 
0139 /* FIELD_INDEX_NONE is returned in read() data from the kernel when flags
0140  * is set to (HIDDEV_FLAG_UREF | HIDDEV_FLAG_REPORT) and a new report has
0141  * been sent by the device 
0142  */
0143 #define HID_FIELD_INDEX_NONE 0xffffffff
0144 
0145 /*
0146  * Protocol version.
0147  */
0148 
0149 #define HID_VERSION     0x010004
0150 
0151 /*
0152  * IOCTLs (0x00 - 0x7f)
0153  */
0154 
0155 #define HIDIOCGVERSION      _IOR('H', 0x01, int)
0156 #define HIDIOCAPPLICATION   _IO('H', 0x02)
0157 #define HIDIOCGDEVINFO      _IOR('H', 0x03, struct hiddev_devinfo)
0158 #define HIDIOCGSTRING       _IOR('H', 0x04, struct hiddev_string_descriptor)
0159 #define HIDIOCINITREPORT    _IO('H', 0x05)
0160 #define HIDIOCGNAME(len)    _IOC(_IOC_READ, 'H', 0x06, len)
0161 #define HIDIOCGREPORT       _IOW('H', 0x07, struct hiddev_report_info)
0162 #define HIDIOCSREPORT       _IOW('H', 0x08, struct hiddev_report_info)
0163 #define HIDIOCGREPORTINFO   _IOWR('H', 0x09, struct hiddev_report_info)
0164 #define HIDIOCGFIELDINFO    _IOWR('H', 0x0A, struct hiddev_field_info)
0165 #define HIDIOCGUSAGE        _IOWR('H', 0x0B, struct hiddev_usage_ref)
0166 #define HIDIOCSUSAGE        _IOW('H', 0x0C, struct hiddev_usage_ref)
0167 #define HIDIOCGUCODE        _IOWR('H', 0x0D, struct hiddev_usage_ref)
0168 #define HIDIOCGFLAG     _IOR('H', 0x0E, int)
0169 #define HIDIOCSFLAG     _IOW('H', 0x0F, int)
0170 #define HIDIOCGCOLLECTIONINDEX  _IOW('H', 0x10, struct hiddev_usage_ref)
0171 #define HIDIOCGCOLLECTIONINFO   _IOWR('H', 0x11, struct hiddev_collection_info)
0172 #define HIDIOCGPHYS(len)    _IOC(_IOC_READ, 'H', 0x12, len)
0173 
0174 /* For writing/reading to multiple/consecutive usages */
0175 #define HIDIOCGUSAGES       _IOWR('H', 0x13, struct hiddev_usage_ref_multi)
0176 #define HIDIOCSUSAGES       _IOW('H', 0x14, struct hiddev_usage_ref_multi)
0177 
0178 /* 
0179  * Flags to be used in HIDIOCSFLAG
0180  */
0181 #define HIDDEV_FLAG_UREF    0x1
0182 #define HIDDEV_FLAG_REPORT  0x2
0183 #define HIDDEV_FLAGS        0x3
0184 
0185 /* To traverse the input report descriptor info for a HID device, perform the 
0186  * following:
0187  *
0188  * rinfo.report_type = HID_REPORT_TYPE_INPUT;
0189  * rinfo.report_id = HID_REPORT_ID_FIRST;
0190  * ret = ioctl(fd, HIDIOCGREPORTINFO, &rinfo);
0191  *
0192  * while (ret >= 0) {
0193  *  for (i = 0; i < rinfo.num_fields; i++) {
0194  *      finfo.report_type = rinfo.report_type;
0195  *      finfo.report_id = rinfo.report_id;
0196  *      finfo.field_index = i;
0197  *      ioctl(fd, HIDIOCGFIELDINFO, &finfo);
0198  *      for (j = 0; j < finfo.maxusage; j++) {
0199  *          uref.report_type = rinfo.report_type;
0200  *          uref.report_id = rinfo.report_id;
0201  *          uref.field_index = i;
0202  *          uref.usage_index = j;
0203  *          ioctl(fd, HIDIOCGUCODE, &uref);
0204  *          ioctl(fd, HIDIOCGUSAGE, &uref);
0205  *      }
0206  *  }
0207  *  rinfo.report_id |= HID_REPORT_ID_NEXT;
0208  *  ret = ioctl(fd, HIDIOCGREPORTINFO, &rinfo);
0209  * }
0210  */
0211 
0212 
0213 #endif /* _UAPI_HIDDEV_H */