1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2020 Vladimir Kondratyev <wulf@FreeBSD.org> 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * $FreeBSD$ 28 */ 29 30 #ifndef _HID_HIDRAW_H 31 #define _HID_HIDRAW_H 32 33 #include <sys/ioccom.h> 34 35 #define HIDRAW_BUFFER_SIZE 64 /* number of input reports buffered */ 36 #define HID_MAX_DESCRIPTOR_SIZE 4096 /* artificial limit taken from Linux */ 37 38 /* Compatible with usb_gen_descriptor structure */ 39 struct hidraw_gen_descriptor { 40 void *hgd_data; 41 uint16_t hgd_lang_id; 42 uint16_t hgd_maxlen; 43 uint16_t hgd_actlen; 44 uint16_t hgd_offset; 45 uint8_t hgd_config_index; 46 uint8_t hgd_string_index; 47 uint8_t hgd_iface_index; 48 uint8_t hgd_altif_index; 49 uint8_t hgd_endpt_index; 50 uint8_t hgd_report_type; 51 uint8_t reserved[8]; 52 }; 53 54 /* Compatible with usb_device_info structure */ 55 struct hidraw_device_info { 56 uint16_t hdi_product; 57 uint16_t hdi_vendor; 58 uint16_t hdi_version; 59 uint8_t occupied[18]; /* by usb_device_info */ 60 uint16_t hdi_bustype; 61 uint8_t reserved[14]; /* leave space for the future */ 62 char hdi_name[128]; 63 char hdi_phys[128]; 64 char hdi_uniq[64]; 65 char hdi_release[8]; /* decrypted USB bcdDevice */ 66 }; 67 68 struct hidraw_report_descriptor { 69 uint32_t size; 70 uint8_t value[HID_MAX_DESCRIPTOR_SIZE]; 71 }; 72 73 struct hidraw_devinfo { 74 uint32_t bustype; 75 int16_t vendor; 76 int16_t product; 77 }; 78 79 /* FreeBSD uhid(4)-compatible ioctl interface */ 80 #define HIDRAW_GET_REPORT_DESC _IOWR('U', 21, struct hidraw_gen_descriptor) 81 #define HIDRAW_SET_IMMED _IOW ('U', 22, int) 82 #define HIDRAW_GET_REPORT _IOWR('U', 23, struct hidraw_gen_descriptor) 83 #define HIDRAW_SET_REPORT _IOW ('U', 24, struct hidraw_gen_descriptor) 84 #define HIDRAW_GET_REPORT_ID _IOR ('U', 25, int) 85 #define HIDRAW_SET_REPORT_DESC _IOW ('U', 26, struct hidraw_gen_descriptor) 86 #define HIDRAW_GET_DEVICEINFO _IOR ('U', 112, struct hidraw_device_info) 87 88 /* Linux hidraw-compatible ioctl interface */ 89 #define HIDIOCGRDESCSIZE _IOR('U', 30, int) 90 #define HIDIOCGRDESC _IO ('U', 31) 91 #define HIDIOCGRAWINFO _IOR('U', 32, struct hidraw_devinfo) 92 #define HIDIOCGRAWNAME(len) _IOC(IOC_OUT, 'U', 33, len) 93 #define HIDIOCGRAWPHYS(len) _IOC(IOC_OUT, 'U', 34, len) 94 #define HIDIOCSFEATURE(len) _IOC(IOC_IN, 'U', 35, len) 95 #define HIDIOCGFEATURE(len) _IOC(IOC_INOUT, 'U', 36, len) 96 #define HIDIOCGRAWUNIQ(len) _IOC(IOC_OUT, 'U', 37, len) 97 98 #endif /* _HID_HIDRAW_H */ 99