102ac6454SAndrew Thompson /* $FreeBSD$ */ 202ac6454SAndrew Thompson /*- 3*718cf2ccSPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause-NetBSD 4*718cf2ccSPedro F. Giffuni * 502ac6454SAndrew Thompson * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 602ac6454SAndrew Thompson * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved. 702ac6454SAndrew Thompson * Copyright (c) 1998 Lennart Augustsson. All rights reserved. 802ac6454SAndrew Thompson * 902ac6454SAndrew Thompson * Redistribution and use in source and binary forms, with or without 1002ac6454SAndrew Thompson * modification, are permitted provided that the following conditions 1102ac6454SAndrew Thompson * are met: 1202ac6454SAndrew Thompson * 1. Redistributions of source code must retain the above copyright 1302ac6454SAndrew Thompson * notice, this list of conditions and the following disclaimer. 1402ac6454SAndrew Thompson * 2. Redistributions in binary form must reproduce the above copyright 1502ac6454SAndrew Thompson * notice, this list of conditions and the following disclaimer in the 1602ac6454SAndrew Thompson * documentation and/or other materials provided with the distribution. 1702ac6454SAndrew Thompson * 1802ac6454SAndrew Thompson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1902ac6454SAndrew Thompson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2002ac6454SAndrew Thompson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2102ac6454SAndrew Thompson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2202ac6454SAndrew Thompson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2302ac6454SAndrew Thompson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2402ac6454SAndrew Thompson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2502ac6454SAndrew Thompson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2602ac6454SAndrew Thompson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2702ac6454SAndrew Thompson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2802ac6454SAndrew Thompson * SUCH DAMAGE. 2902ac6454SAndrew Thompson */ 3002ac6454SAndrew Thompson 3175973647SAndrew Thompson #ifndef _USB_HID_H_ 3275973647SAndrew Thompson #define _USB_HID_H_ 3302ac6454SAndrew Thompson 34d2b99310SHans Petter Selasky #ifndef USB_GLOBAL_INCLUDE_FILE 3502ac6454SAndrew Thompson #include <dev/usb/usb_endian.h> 36d2b99310SHans Petter Selasky #endif 3702ac6454SAndrew Thompson 3802ac6454SAndrew Thompson #define UR_GET_HID_DESCRIPTOR 0x06 3902ac6454SAndrew Thompson #define UDESC_HID 0x21 4002ac6454SAndrew Thompson #define UDESC_REPORT 0x22 4102ac6454SAndrew Thompson #define UDESC_PHYSICAL 0x23 4202ac6454SAndrew Thompson #define UR_SET_HID_DESCRIPTOR 0x07 4302ac6454SAndrew Thompson #define UR_GET_REPORT 0x01 4402ac6454SAndrew Thompson #define UR_SET_REPORT 0x09 4502ac6454SAndrew Thompson #define UR_GET_IDLE 0x02 4602ac6454SAndrew Thompson #define UR_SET_IDLE 0x0a 4702ac6454SAndrew Thompson #define UR_GET_PROTOCOL 0x03 4802ac6454SAndrew Thompson #define UR_SET_PROTOCOL 0x0b 4902ac6454SAndrew Thompson 50760bc48eSAndrew Thompson struct usb_hid_descriptor { 5102ac6454SAndrew Thompson uByte bLength; 5202ac6454SAndrew Thompson uByte bDescriptorType; 5302ac6454SAndrew Thompson uWord bcdHID; 5402ac6454SAndrew Thompson uByte bCountryCode; 5502ac6454SAndrew Thompson uByte bNumDescriptors; 5602ac6454SAndrew Thompson struct { 5702ac6454SAndrew Thompson uByte bDescriptorType; 5802ac6454SAndrew Thompson uWord wDescriptorLength; 5902ac6454SAndrew Thompson } descrs[1]; 6002ac6454SAndrew Thompson } __packed; 6102ac6454SAndrew Thompson 6202ac6454SAndrew Thompson #define USB_HID_DESCRIPTOR_SIZE(n) (9+((n)*3)) 6302ac6454SAndrew Thompson 6402ac6454SAndrew Thompson /* Usage pages */ 6502ac6454SAndrew Thompson #define HUP_UNDEFINED 0x0000 6602ac6454SAndrew Thompson #define HUP_GENERIC_DESKTOP 0x0001 6702ac6454SAndrew Thompson #define HUP_SIMULATION 0x0002 6802ac6454SAndrew Thompson #define HUP_VR_CONTROLS 0x0003 6902ac6454SAndrew Thompson #define HUP_SPORTS_CONTROLS 0x0004 7002ac6454SAndrew Thompson #define HUP_GAMING_CONTROLS 0x0005 7102ac6454SAndrew Thompson #define HUP_KEYBOARD 0x0007 7202ac6454SAndrew Thompson #define HUP_LEDS 0x0008 7302ac6454SAndrew Thompson #define HUP_BUTTON 0x0009 7402ac6454SAndrew Thompson #define HUP_ORDINALS 0x000a 7502ac6454SAndrew Thompson #define HUP_TELEPHONY 0x000b 7602ac6454SAndrew Thompson #define HUP_CONSUMER 0x000c 7702ac6454SAndrew Thompson #define HUP_DIGITIZERS 0x000d 7802ac6454SAndrew Thompson #define HUP_PHYSICAL_IFACE 0x000e 7902ac6454SAndrew Thompson #define HUP_UNICODE 0x0010 8002ac6454SAndrew Thompson #define HUP_ALPHANUM_DISPLAY 0x0014 8102ac6454SAndrew Thompson #define HUP_MONITOR 0x0080 8202ac6454SAndrew Thompson #define HUP_MONITOR_ENUM_VAL 0x0081 8302ac6454SAndrew Thompson #define HUP_VESA_VC 0x0082 8402ac6454SAndrew Thompson #define HUP_VESA_CMD 0x0083 8502ac6454SAndrew Thompson #define HUP_POWER 0x0084 8602ac6454SAndrew Thompson #define HUP_BATTERY_SYSTEM 0x0085 8702ac6454SAndrew Thompson #define HUP_BARCODE_SCANNER 0x008b 8802ac6454SAndrew Thompson #define HUP_SCALE 0x008c 8902ac6454SAndrew Thompson #define HUP_CAMERA_CONTROL 0x0090 9002ac6454SAndrew Thompson #define HUP_ARCADE 0x0091 9102ac6454SAndrew Thompson #define HUP_MICROSOFT 0xff00 9202ac6454SAndrew Thompson 9302ac6454SAndrew Thompson /* Usages, generic desktop */ 9402ac6454SAndrew Thompson #define HUG_POINTER 0x0001 9502ac6454SAndrew Thompson #define HUG_MOUSE 0x0002 9602ac6454SAndrew Thompson #define HUG_JOYSTICK 0x0004 9702ac6454SAndrew Thompson #define HUG_GAME_PAD 0x0005 9802ac6454SAndrew Thompson #define HUG_KEYBOARD 0x0006 9902ac6454SAndrew Thompson #define HUG_KEYPAD 0x0007 10002ac6454SAndrew Thompson #define HUG_X 0x0030 10102ac6454SAndrew Thompson #define HUG_Y 0x0031 10202ac6454SAndrew Thompson #define HUG_Z 0x0032 10302ac6454SAndrew Thompson #define HUG_RX 0x0033 10402ac6454SAndrew Thompson #define HUG_RY 0x0034 10502ac6454SAndrew Thompson #define HUG_RZ 0x0035 10602ac6454SAndrew Thompson #define HUG_SLIDER 0x0036 10702ac6454SAndrew Thompson #define HUG_DIAL 0x0037 10802ac6454SAndrew Thompson #define HUG_WHEEL 0x0038 10902ac6454SAndrew Thompson #define HUG_HAT_SWITCH 0x0039 11002ac6454SAndrew Thompson #define HUG_COUNTED_BUFFER 0x003a 11102ac6454SAndrew Thompson #define HUG_BYTE_COUNT 0x003b 11202ac6454SAndrew Thompson #define HUG_MOTION_WAKEUP 0x003c 11302ac6454SAndrew Thompson #define HUG_VX 0x0040 11402ac6454SAndrew Thompson #define HUG_VY 0x0041 11502ac6454SAndrew Thompson #define HUG_VZ 0x0042 11602ac6454SAndrew Thompson #define HUG_VBRX 0x0043 11702ac6454SAndrew Thompson #define HUG_VBRY 0x0044 11802ac6454SAndrew Thompson #define HUG_VBRZ 0x0045 11902ac6454SAndrew Thompson #define HUG_VNO 0x0046 12002ac6454SAndrew Thompson #define HUG_TWHEEL 0x0048 /* M$ Wireless Intellimouse Wheel */ 12102ac6454SAndrew Thompson #define HUG_SYSTEM_CONTROL 0x0080 12202ac6454SAndrew Thompson #define HUG_SYSTEM_POWER_DOWN 0x0081 12302ac6454SAndrew Thompson #define HUG_SYSTEM_SLEEP 0x0082 12402ac6454SAndrew Thompson #define HUG_SYSTEM_WAKEUP 0x0083 12502ac6454SAndrew Thompson #define HUG_SYSTEM_CONTEXT_MENU 0x0084 12602ac6454SAndrew Thompson #define HUG_SYSTEM_MAIN_MENU 0x0085 12702ac6454SAndrew Thompson #define HUG_SYSTEM_APP_MENU 0x0086 12802ac6454SAndrew Thompson #define HUG_SYSTEM_MENU_HELP 0x0087 12902ac6454SAndrew Thompson #define HUG_SYSTEM_MENU_EXIT 0x0088 13002ac6454SAndrew Thompson #define HUG_SYSTEM_MENU_SELECT 0x0089 13102ac6454SAndrew Thompson #define HUG_SYSTEM_MENU_RIGHT 0x008a 13202ac6454SAndrew Thompson #define HUG_SYSTEM_MENU_LEFT 0x008b 13302ac6454SAndrew Thompson #define HUG_SYSTEM_MENU_UP 0x008c 13402ac6454SAndrew Thompson #define HUG_SYSTEM_MENU_DOWN 0x008d 135fa64b944SAndrew Thompson #define HUG_APPLE_EJECT 0x00b8 13602ac6454SAndrew Thompson 13702ac6454SAndrew Thompson /* Usages Digitizers */ 13802ac6454SAndrew Thompson #define HUD_UNDEFINED 0x0000 13976136d20SVladimir Kondratyev #define HUD_DIGITIZER 0x0001 14076136d20SVladimir Kondratyev #define HUD_PEN 0x0002 14176136d20SVladimir Kondratyev #define HUD_TOUCHSCREEN 0x0004 14276136d20SVladimir Kondratyev #define HUD_TOUCHPAD 0x0005 14376136d20SVladimir Kondratyev #define HUD_CONFIG 0x000e 14476136d20SVladimir Kondratyev #define HUD_FINGER 0x0022 14502ac6454SAndrew Thompson #define HUD_TIP_PRESSURE 0x0030 14602ac6454SAndrew Thompson #define HUD_BARREL_PRESSURE 0x0031 14702ac6454SAndrew Thompson #define HUD_IN_RANGE 0x0032 14802ac6454SAndrew Thompson #define HUD_TOUCH 0x0033 14902ac6454SAndrew Thompson #define HUD_UNTOUCH 0x0034 15002ac6454SAndrew Thompson #define HUD_TAP 0x0035 15102ac6454SAndrew Thompson #define HUD_QUALITY 0x0036 15202ac6454SAndrew Thompson #define HUD_DATA_VALID 0x0037 15302ac6454SAndrew Thompson #define HUD_TRANSDUCER_INDEX 0x0038 15402ac6454SAndrew Thompson #define HUD_TABLET_FKEYS 0x0039 15502ac6454SAndrew Thompson #define HUD_PROGRAM_CHANGE_KEYS 0x003a 15602ac6454SAndrew Thompson #define HUD_BATTERY_STRENGTH 0x003b 15702ac6454SAndrew Thompson #define HUD_INVERT 0x003c 15802ac6454SAndrew Thompson #define HUD_X_TILT 0x003d 15902ac6454SAndrew Thompson #define HUD_Y_TILT 0x003e 16002ac6454SAndrew Thompson #define HUD_AZIMUTH 0x003f 16102ac6454SAndrew Thompson #define HUD_ALTITUDE 0x0040 16202ac6454SAndrew Thompson #define HUD_TWIST 0x0041 16302ac6454SAndrew Thompson #define HUD_TIP_SWITCH 0x0042 16402ac6454SAndrew Thompson #define HUD_SEC_TIP_SWITCH 0x0043 16502ac6454SAndrew Thompson #define HUD_BARREL_SWITCH 0x0044 16602ac6454SAndrew Thompson #define HUD_ERASER 0x0045 16702ac6454SAndrew Thompson #define HUD_TABLET_PICK 0x0046 16876136d20SVladimir Kondratyev #define HUD_CONFIDENCE 0x0047 16976136d20SVladimir Kondratyev #define HUD_WIDTH 0x0048 17076136d20SVladimir Kondratyev #define HUD_HEIGHT 0x0049 17176136d20SVladimir Kondratyev #define HUD_CONTACTID 0x0051 17276136d20SVladimir Kondratyev #define HUD_INPUT_MODE 0x0052 17376136d20SVladimir Kondratyev #define HUD_DEVICE_INDEX 0x0053 17476136d20SVladimir Kondratyev #define HUD_CONTACTCOUNT 0x0054 17576136d20SVladimir Kondratyev #define HUD_CONTACT_MAX 0x0055 17676136d20SVladimir Kondratyev #define HUD_SCAN_TIME 0x0056 17776136d20SVladimir Kondratyev #define HUD_BUTTON_TYPE 0x0059 17802ac6454SAndrew Thompson 179300f96f1SAndrew Thompson /* Usages, Consumer */ 180300f96f1SAndrew Thompson #define HUC_AC_PAN 0x0238 181300f96f1SAndrew Thompson 18202ac6454SAndrew Thompson #define HID_USAGE2(p,u) (((p) << 16) | (u)) 18302ac6454SAndrew Thompson 18402ac6454SAndrew Thompson #define UHID_INPUT_REPORT 0x01 18502ac6454SAndrew Thompson #define UHID_OUTPUT_REPORT 0x02 18602ac6454SAndrew Thompson #define UHID_FEATURE_REPORT 0x03 18702ac6454SAndrew Thompson 18802ac6454SAndrew Thompson /* Bits in the input/output/feature items */ 18902ac6454SAndrew Thompson #define HIO_CONST 0x001 19002ac6454SAndrew Thompson #define HIO_VARIABLE 0x002 19102ac6454SAndrew Thompson #define HIO_RELATIVE 0x004 19202ac6454SAndrew Thompson #define HIO_WRAP 0x008 19302ac6454SAndrew Thompson #define HIO_NONLINEAR 0x010 19402ac6454SAndrew Thompson #define HIO_NOPREF 0x020 19502ac6454SAndrew Thompson #define HIO_NULLSTATE 0x040 19602ac6454SAndrew Thompson #define HIO_VOLATILE 0x080 19702ac6454SAndrew Thompson #define HIO_BUFBYTES 0x100 19802ac6454SAndrew Thompson 19976136d20SVladimir Kondratyev /* Units of Measure */ 20076136d20SVladimir Kondratyev #define HUM_CENTIMETER 0x11 20176136d20SVladimir Kondratyev #define HUM_RADIAN 0x12 20276136d20SVladimir Kondratyev #define HUM_INCH 0x13 20376136d20SVladimir Kondratyev #define HUM_DEGREE 0x14 20476136d20SVladimir Kondratyev 205ed6d949aSAndrew Thompson #ifdef _KERNEL 206ed6d949aSAndrew Thompson struct usb_config_descriptor; 207ed6d949aSAndrew Thompson 208ed6d949aSAndrew Thompson enum hid_kind { 209ed6d949aSAndrew Thompson hid_input, hid_output, hid_feature, hid_collection, hid_endcollection 210ed6d949aSAndrew Thompson }; 211ed6d949aSAndrew Thompson 212ed6d949aSAndrew Thompson struct hid_location { 213ed6d949aSAndrew Thompson uint32_t size; 214ed6d949aSAndrew Thompson uint32_t count; 215ed6d949aSAndrew Thompson uint32_t pos; 216ed6d949aSAndrew Thompson }; 217ed6d949aSAndrew Thompson 218ed6d949aSAndrew Thompson struct hid_item { 219ed6d949aSAndrew Thompson /* Global */ 220ed6d949aSAndrew Thompson int32_t _usage_page; 221ed6d949aSAndrew Thompson int32_t logical_minimum; 222ed6d949aSAndrew Thompson int32_t logical_maximum; 223ed6d949aSAndrew Thompson int32_t physical_minimum; 224ed6d949aSAndrew Thompson int32_t physical_maximum; 225ed6d949aSAndrew Thompson int32_t unit_exponent; 226ed6d949aSAndrew Thompson int32_t unit; 227ed6d949aSAndrew Thompson int32_t report_ID; 228ed6d949aSAndrew Thompson /* Local */ 229ed6d949aSAndrew Thompson int32_t usage; 230ed6d949aSAndrew Thompson int32_t usage_minimum; 231ed6d949aSAndrew Thompson int32_t usage_maximum; 232ed6d949aSAndrew Thompson int32_t designator_index; 233ed6d949aSAndrew Thompson int32_t designator_minimum; 234ed6d949aSAndrew Thompson int32_t designator_maximum; 235ed6d949aSAndrew Thompson int32_t string_index; 236ed6d949aSAndrew Thompson int32_t string_minimum; 237ed6d949aSAndrew Thompson int32_t string_maximum; 238ed6d949aSAndrew Thompson int32_t set_delimiter; 239ed6d949aSAndrew Thompson /* Misc */ 240ed6d949aSAndrew Thompson int32_t collection; 241ed6d949aSAndrew Thompson int collevel; 242ed6d949aSAndrew Thompson enum hid_kind kind; 243ed6d949aSAndrew Thompson uint32_t flags; 244ed6d949aSAndrew Thompson /* Location */ 245ed6d949aSAndrew Thompson struct hid_location loc; 246ed6d949aSAndrew Thompson }; 247ed6d949aSAndrew Thompson 248ed6d949aSAndrew Thompson /* prototypes from "usb_hid.c" */ 249ed6d949aSAndrew Thompson 250ed6d949aSAndrew Thompson struct hid_data *hid_start_parse(const void *d, usb_size_t len, int kindset); 251ed6d949aSAndrew Thompson void hid_end_parse(struct hid_data *s); 252ed6d949aSAndrew Thompson int hid_get_item(struct hid_data *s, struct hid_item *h); 253ed6d949aSAndrew Thompson int hid_report_size(const void *buf, usb_size_t len, enum hid_kind k, 254ed6d949aSAndrew Thompson uint8_t *id); 2556d917491SHans Petter Selasky int hid_locate(const void *desc, usb_size_t size, int32_t usage, 256ed6d949aSAndrew Thompson enum hid_kind kind, uint8_t index, struct hid_location *loc, 257ed6d949aSAndrew Thompson uint32_t *flags, uint8_t *id); 2585fdb3a67SAndrew Thompson int32_t hid_get_data(const uint8_t *buf, usb_size_t len, 2595fdb3a67SAndrew Thompson struct hid_location *loc); 2605fdb3a67SAndrew Thompson uint32_t hid_get_data_unsigned(const uint8_t *buf, usb_size_t len, 261ed6d949aSAndrew Thompson struct hid_location *loc); 262e92091adSHans Petter Selasky void hid_put_data_unsigned(uint8_t *buf, usb_size_t len, 263e92091adSHans Petter Selasky struct hid_location *loc, unsigned int value); 2646d917491SHans Petter Selasky int hid_is_collection(const void *desc, usb_size_t size, int32_t usage); 265ed6d949aSAndrew Thompson struct usb_hid_descriptor *hid_get_descriptor_from_usb( 266ed6d949aSAndrew Thompson struct usb_config_descriptor *cd, 267ed6d949aSAndrew Thompson struct usb_interface_descriptor *id); 268ed6d949aSAndrew Thompson usb_error_t usbd_req_get_hid_desc(struct usb_device *udev, struct mtx *mtx, 269ed6d949aSAndrew Thompson void **descp, uint16_t *sizep, struct malloc_type *mem, 270ed6d949aSAndrew Thompson uint8_t iface_index); 27176136d20SVladimir Kondratyev int32_t hid_item_resolution(struct hid_item *hi); 27260867f57SHans Petter Selasky int hid_is_mouse(const void *d_ptr, uint16_t d_len); 27360867f57SHans Petter Selasky int hid_is_keyboard(const void *d_ptr, uint16_t d_len); 274ed6d949aSAndrew Thompson #endif /* _KERNEL */ 27575973647SAndrew Thompson #endif /* _USB_HID_H_ */ 276