1184610Salfred/* $FreeBSD$ */ 2184610Salfred/*- 3184610Salfred * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 4184610Salfred * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved. 5184610Salfred * Copyright (c) 1998 Lennart Augustsson. All rights reserved. 6184610Salfred * 7184610Salfred * Redistribution and use in source and binary forms, with or without 8184610Salfred * modification, are permitted provided that the following conditions 9184610Salfred * are met: 10184610Salfred * 1. Redistributions of source code must retain the above copyright 11184610Salfred * notice, this list of conditions and the following disclaimer. 12184610Salfred * 2. Redistributions in binary form must reproduce the above copyright 13184610Salfred * notice, this list of conditions and the following disclaimer in the 14184610Salfred * documentation and/or other materials provided with the distribution. 15184610Salfred * 16184610Salfred * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17184610Salfred * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18184610Salfred * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19184610Salfred * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20184610Salfred * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21184610Salfred * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22184610Salfred * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23184610Salfred * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24184610Salfred * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25184610Salfred * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26184610Salfred * SUCH DAMAGE. 27184610Salfred */ 28184610Salfred 29194230Sthompsa#ifndef _USB_HID_H_ 30194230Sthompsa#define _USB_HID_H_ 31184610Salfred 32246122Shselasky#ifndef USB_GLOBAL_INCLUDE_FILE 33188942Sthompsa#include <dev/usb/usb_endian.h> 34246122Shselasky#endif 35187994Salfred 36184610Salfred#define UR_GET_HID_DESCRIPTOR 0x06 37184610Salfred#define UDESC_HID 0x21 38184610Salfred#define UDESC_REPORT 0x22 39184610Salfred#define UDESC_PHYSICAL 0x23 40184610Salfred#define UR_SET_HID_DESCRIPTOR 0x07 41184610Salfred#define UR_GET_REPORT 0x01 42184610Salfred#define UR_SET_REPORT 0x09 43184610Salfred#define UR_GET_IDLE 0x02 44184610Salfred#define UR_SET_IDLE 0x0a 45184610Salfred#define UR_GET_PROTOCOL 0x03 46184610Salfred#define UR_SET_PROTOCOL 0x0b 47184610Salfred 48192984Sthompsastruct usb_hid_descriptor { 49184610Salfred uByte bLength; 50184610Salfred uByte bDescriptorType; 51184610Salfred uWord bcdHID; 52184610Salfred uByte bCountryCode; 53184610Salfred uByte bNumDescriptors; 54184610Salfred struct { 55184610Salfred uByte bDescriptorType; 56184610Salfred uWord wDescriptorLength; 57184610Salfred } descrs[1]; 58184610Salfred} __packed; 59184610Salfred 60184610Salfred#define USB_HID_DESCRIPTOR_SIZE(n) (9+((n)*3)) 61184610Salfred 62184610Salfred/* Usage pages */ 63184610Salfred#define HUP_UNDEFINED 0x0000 64184610Salfred#define HUP_GENERIC_DESKTOP 0x0001 65184610Salfred#define HUP_SIMULATION 0x0002 66184610Salfred#define HUP_VR_CONTROLS 0x0003 67184610Salfred#define HUP_SPORTS_CONTROLS 0x0004 68184610Salfred#define HUP_GAMING_CONTROLS 0x0005 69184610Salfred#define HUP_KEYBOARD 0x0007 70184610Salfred#define HUP_LEDS 0x0008 71184610Salfred#define HUP_BUTTON 0x0009 72184610Salfred#define HUP_ORDINALS 0x000a 73184610Salfred#define HUP_TELEPHONY 0x000b 74184610Salfred#define HUP_CONSUMER 0x000c 75184610Salfred#define HUP_DIGITIZERS 0x000d 76184610Salfred#define HUP_PHYSICAL_IFACE 0x000e 77184610Salfred#define HUP_UNICODE 0x0010 78184610Salfred#define HUP_ALPHANUM_DISPLAY 0x0014 79184610Salfred#define HUP_MONITOR 0x0080 80184610Salfred#define HUP_MONITOR_ENUM_VAL 0x0081 81184610Salfred#define HUP_VESA_VC 0x0082 82184610Salfred#define HUP_VESA_CMD 0x0083 83184610Salfred#define HUP_POWER 0x0084 84184610Salfred#define HUP_BATTERY_SYSTEM 0x0085 85184610Salfred#define HUP_BARCODE_SCANNER 0x008b 86184610Salfred#define HUP_SCALE 0x008c 87184610Salfred#define HUP_CAMERA_CONTROL 0x0090 88184610Salfred#define HUP_ARCADE 0x0091 89184610Salfred#define HUP_MICROSOFT 0xff00 90184610Salfred 91184610Salfred/* Usages, generic desktop */ 92184610Salfred#define HUG_POINTER 0x0001 93184610Salfred#define HUG_MOUSE 0x0002 94184610Salfred#define HUG_JOYSTICK 0x0004 95184610Salfred#define HUG_GAME_PAD 0x0005 96184610Salfred#define HUG_KEYBOARD 0x0006 97184610Salfred#define HUG_KEYPAD 0x0007 98184610Salfred#define HUG_X 0x0030 99184610Salfred#define HUG_Y 0x0031 100184610Salfred#define HUG_Z 0x0032 101184610Salfred#define HUG_RX 0x0033 102184610Salfred#define HUG_RY 0x0034 103184610Salfred#define HUG_RZ 0x0035 104184610Salfred#define HUG_SLIDER 0x0036 105184610Salfred#define HUG_DIAL 0x0037 106184610Salfred#define HUG_WHEEL 0x0038 107184610Salfred#define HUG_HAT_SWITCH 0x0039 108184610Salfred#define HUG_COUNTED_BUFFER 0x003a 109184610Salfred#define HUG_BYTE_COUNT 0x003b 110184610Salfred#define HUG_MOTION_WAKEUP 0x003c 111184610Salfred#define HUG_VX 0x0040 112184610Salfred#define HUG_VY 0x0041 113184610Salfred#define HUG_VZ 0x0042 114184610Salfred#define HUG_VBRX 0x0043 115184610Salfred#define HUG_VBRY 0x0044 116184610Salfred#define HUG_VBRZ 0x0045 117184610Salfred#define HUG_VNO 0x0046 118184610Salfred#define HUG_TWHEEL 0x0048 /* M$ Wireless Intellimouse Wheel */ 119184610Salfred#define HUG_SYSTEM_CONTROL 0x0080 120184610Salfred#define HUG_SYSTEM_POWER_DOWN 0x0081 121184610Salfred#define HUG_SYSTEM_SLEEP 0x0082 122184610Salfred#define HUG_SYSTEM_WAKEUP 0x0083 123184610Salfred#define HUG_SYSTEM_CONTEXT_MENU 0x0084 124184610Salfred#define HUG_SYSTEM_MAIN_MENU 0x0085 125184610Salfred#define HUG_SYSTEM_APP_MENU 0x0086 126184610Salfred#define HUG_SYSTEM_MENU_HELP 0x0087 127184610Salfred#define HUG_SYSTEM_MENU_EXIT 0x0088 128184610Salfred#define HUG_SYSTEM_MENU_SELECT 0x0089 129184610Salfred#define HUG_SYSTEM_MENU_RIGHT 0x008a 130184610Salfred#define HUG_SYSTEM_MENU_LEFT 0x008b 131184610Salfred#define HUG_SYSTEM_MENU_UP 0x008c 132184610Salfred#define HUG_SYSTEM_MENU_DOWN 0x008d 133192925Sthompsa#define HUG_APPLE_EJECT 0x00b8 134184610Salfred 135184610Salfred/* Usages Digitizers */ 136184610Salfred#define HUD_UNDEFINED 0x0000 137184610Salfred#define HUD_TIP_PRESSURE 0x0030 138184610Salfred#define HUD_BARREL_PRESSURE 0x0031 139184610Salfred#define HUD_IN_RANGE 0x0032 140184610Salfred#define HUD_TOUCH 0x0033 141184610Salfred#define HUD_UNTOUCH 0x0034 142184610Salfred#define HUD_TAP 0x0035 143184610Salfred#define HUD_QUALITY 0x0036 144184610Salfred#define HUD_DATA_VALID 0x0037 145184610Salfred#define HUD_TRANSDUCER_INDEX 0x0038 146184610Salfred#define HUD_TABLET_FKEYS 0x0039 147184610Salfred#define HUD_PROGRAM_CHANGE_KEYS 0x003a 148184610Salfred#define HUD_BATTERY_STRENGTH 0x003b 149184610Salfred#define HUD_INVERT 0x003c 150184610Salfred#define HUD_X_TILT 0x003d 151184610Salfred#define HUD_Y_TILT 0x003e 152184610Salfred#define HUD_AZIMUTH 0x003f 153184610Salfred#define HUD_ALTITUDE 0x0040 154184610Salfred#define HUD_TWIST 0x0041 155184610Salfred#define HUD_TIP_SWITCH 0x0042 156184610Salfred#define HUD_SEC_TIP_SWITCH 0x0043 157184610Salfred#define HUD_BARREL_SWITCH 0x0044 158184610Salfred#define HUD_ERASER 0x0045 159184610Salfred#define HUD_TABLET_PICK 0x0046 160184610Salfred 161208009Sthompsa/* Usages, Consumer */ 162208009Sthompsa#define HUC_AC_PAN 0x0238 163208009Sthompsa 164184610Salfred#define HID_USAGE2(p,u) (((p) << 16) | (u)) 165184610Salfred 166184610Salfred#define UHID_INPUT_REPORT 0x01 167184610Salfred#define UHID_OUTPUT_REPORT 0x02 168184610Salfred#define UHID_FEATURE_REPORT 0x03 169184610Salfred 170184610Salfred/* Bits in the input/output/feature items */ 171184610Salfred#define HIO_CONST 0x001 172184610Salfred#define HIO_VARIABLE 0x002 173184610Salfred#define HIO_RELATIVE 0x004 174184610Salfred#define HIO_WRAP 0x008 175184610Salfred#define HIO_NONLINEAR 0x010 176184610Salfred#define HIO_NOPREF 0x020 177184610Salfred#define HIO_NULLSTATE 0x040 178184610Salfred#define HIO_VOLATILE 0x080 179184610Salfred#define HIO_BUFBYTES 0x100 180184610Salfred 181194677Sthompsa#ifdef _KERNEL 182194677Sthompsastruct usb_config_descriptor; 183194677Sthompsa 184194677Sthompsaenum hid_kind { 185194677Sthompsa hid_input, hid_output, hid_feature, hid_collection, hid_endcollection 186194677Sthompsa}; 187194677Sthompsa 188194677Sthompsastruct hid_location { 189194677Sthompsa uint32_t size; 190194677Sthompsa uint32_t count; 191194677Sthompsa uint32_t pos; 192194677Sthompsa}; 193194677Sthompsa 194194677Sthompsastruct hid_item { 195194677Sthompsa /* Global */ 196194677Sthompsa int32_t _usage_page; 197194677Sthompsa int32_t logical_minimum; 198194677Sthompsa int32_t logical_maximum; 199194677Sthompsa int32_t physical_minimum; 200194677Sthompsa int32_t physical_maximum; 201194677Sthompsa int32_t unit_exponent; 202194677Sthompsa int32_t unit; 203194677Sthompsa int32_t report_ID; 204194677Sthompsa /* Local */ 205194677Sthompsa int32_t usage; 206194677Sthompsa int32_t usage_minimum; 207194677Sthompsa int32_t usage_maximum; 208194677Sthompsa int32_t designator_index; 209194677Sthompsa int32_t designator_minimum; 210194677Sthompsa int32_t designator_maximum; 211194677Sthompsa int32_t string_index; 212194677Sthompsa int32_t string_minimum; 213194677Sthompsa int32_t string_maximum; 214194677Sthompsa int32_t set_delimiter; 215194677Sthompsa /* Misc */ 216194677Sthompsa int32_t collection; 217194677Sthompsa int collevel; 218194677Sthompsa enum hid_kind kind; 219194677Sthompsa uint32_t flags; 220194677Sthompsa /* Location */ 221194677Sthompsa struct hid_location loc; 222194677Sthompsa}; 223194677Sthompsa 224194677Sthompsa/* prototypes from "usb_hid.c" */ 225194677Sthompsa 226194677Sthompsastruct hid_data *hid_start_parse(const void *d, usb_size_t len, int kindset); 227194677Sthompsavoid hid_end_parse(struct hid_data *s); 228194677Sthompsaint hid_get_item(struct hid_data *s, struct hid_item *h); 229194677Sthompsaint hid_report_size(const void *buf, usb_size_t len, enum hid_kind k, 230194677Sthompsa uint8_t *id); 231233774Shselaskyint hid_locate(const void *desc, usb_size_t size, int32_t usage, 232194677Sthompsa enum hid_kind kind, uint8_t index, struct hid_location *loc, 233194677Sthompsa uint32_t *flags, uint8_t *id); 234208012Sthompsaint32_t hid_get_data(const uint8_t *buf, usb_size_t len, 235194677Sthompsa struct hid_location *loc); 236208012Sthompsauint32_t hid_get_data_unsigned(const uint8_t *buf, usb_size_t len, 237208012Sthompsa struct hid_location *loc); 238223755Shselaskyvoid hid_put_data_unsigned(uint8_t *buf, usb_size_t len, 239223755Shselasky struct hid_location *loc, unsigned int value); 240233774Shselaskyint hid_is_collection(const void *desc, usb_size_t size, int32_t usage); 241194677Sthompsastruct usb_hid_descriptor *hid_get_descriptor_from_usb( 242194677Sthompsa struct usb_config_descriptor *cd, 243194677Sthompsa struct usb_interface_descriptor *id); 244194677Sthompsausb_error_t usbd_req_get_hid_desc(struct usb_device *udev, struct mtx *mtx, 245194677Sthompsa void **descp, uint16_t *sizep, struct malloc_type *mem, 246194677Sthompsa uint8_t iface_index); 247245248Shselaskyint hid_is_mouse(const void *d_ptr, uint16_t d_len); 248245248Shselaskyint hid_is_keyboard(const void *d_ptr, uint16_t d_len); 249194677Sthompsa#endif /* _KERNEL */ 250194230Sthompsa#endif /* _USB_HID_H_ */ 251