usbhid.h revision 208009
1184610Salfred/* $FreeBSD: head/sys/dev/usb/usbhid.h 208009 2010-05-12 22:43:33Z thompsa $ */ 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 32188942Sthompsa#include <dev/usb/usb_endian.h> 33187994Salfred 34184610Salfred#define UR_GET_HID_DESCRIPTOR 0x06 35184610Salfred#define UDESC_HID 0x21 36184610Salfred#define UDESC_REPORT 0x22 37184610Salfred#define UDESC_PHYSICAL 0x23 38184610Salfred#define UR_SET_HID_DESCRIPTOR 0x07 39184610Salfred#define UR_GET_REPORT 0x01 40184610Salfred#define UR_SET_REPORT 0x09 41184610Salfred#define UR_GET_IDLE 0x02 42184610Salfred#define UR_SET_IDLE 0x0a 43184610Salfred#define UR_GET_PROTOCOL 0x03 44184610Salfred#define UR_SET_PROTOCOL 0x0b 45184610Salfred 46192984Sthompsastruct usb_hid_descriptor { 47184610Salfred uByte bLength; 48184610Salfred uByte bDescriptorType; 49184610Salfred uWord bcdHID; 50184610Salfred uByte bCountryCode; 51184610Salfred uByte bNumDescriptors; 52184610Salfred struct { 53184610Salfred uByte bDescriptorType; 54184610Salfred uWord wDescriptorLength; 55184610Salfred } descrs[1]; 56184610Salfred} __packed; 57184610Salfred 58184610Salfred#define USB_HID_DESCRIPTOR_SIZE(n) (9+((n)*3)) 59184610Salfred 60184610Salfred/* Usage pages */ 61184610Salfred#define HUP_UNDEFINED 0x0000 62184610Salfred#define HUP_GENERIC_DESKTOP 0x0001 63184610Salfred#define HUP_SIMULATION 0x0002 64184610Salfred#define HUP_VR_CONTROLS 0x0003 65184610Salfred#define HUP_SPORTS_CONTROLS 0x0004 66184610Salfred#define HUP_GAMING_CONTROLS 0x0005 67184610Salfred#define HUP_KEYBOARD 0x0007 68184610Salfred#define HUP_LEDS 0x0008 69184610Salfred#define HUP_BUTTON 0x0009 70184610Salfred#define HUP_ORDINALS 0x000a 71184610Salfred#define HUP_TELEPHONY 0x000b 72184610Salfred#define HUP_CONSUMER 0x000c 73184610Salfred#define HUP_DIGITIZERS 0x000d 74184610Salfred#define HUP_PHYSICAL_IFACE 0x000e 75184610Salfred#define HUP_UNICODE 0x0010 76184610Salfred#define HUP_ALPHANUM_DISPLAY 0x0014 77184610Salfred#define HUP_MONITOR 0x0080 78184610Salfred#define HUP_MONITOR_ENUM_VAL 0x0081 79184610Salfred#define HUP_VESA_VC 0x0082 80184610Salfred#define HUP_VESA_CMD 0x0083 81184610Salfred#define HUP_POWER 0x0084 82184610Salfred#define HUP_BATTERY_SYSTEM 0x0085 83184610Salfred#define HUP_BARCODE_SCANNER 0x008b 84184610Salfred#define HUP_SCALE 0x008c 85184610Salfred#define HUP_CAMERA_CONTROL 0x0090 86184610Salfred#define HUP_ARCADE 0x0091 87184610Salfred#define HUP_MICROSOFT 0xff00 88184610Salfred 89184610Salfred/* Usages, generic desktop */ 90184610Salfred#define HUG_POINTER 0x0001 91184610Salfred#define HUG_MOUSE 0x0002 92184610Salfred#define HUG_JOYSTICK 0x0004 93184610Salfred#define HUG_GAME_PAD 0x0005 94184610Salfred#define HUG_KEYBOARD 0x0006 95184610Salfred#define HUG_KEYPAD 0x0007 96184610Salfred#define HUG_X 0x0030 97184610Salfred#define HUG_Y 0x0031 98184610Salfred#define HUG_Z 0x0032 99184610Salfred#define HUG_RX 0x0033 100184610Salfred#define HUG_RY 0x0034 101184610Salfred#define HUG_RZ 0x0035 102184610Salfred#define HUG_SLIDER 0x0036 103184610Salfred#define HUG_DIAL 0x0037 104184610Salfred#define HUG_WHEEL 0x0038 105184610Salfred#define HUG_HAT_SWITCH 0x0039 106184610Salfred#define HUG_COUNTED_BUFFER 0x003a 107184610Salfred#define HUG_BYTE_COUNT 0x003b 108184610Salfred#define HUG_MOTION_WAKEUP 0x003c 109184610Salfred#define HUG_VX 0x0040 110184610Salfred#define HUG_VY 0x0041 111184610Salfred#define HUG_VZ 0x0042 112184610Salfred#define HUG_VBRX 0x0043 113184610Salfred#define HUG_VBRY 0x0044 114184610Salfred#define HUG_VBRZ 0x0045 115184610Salfred#define HUG_VNO 0x0046 116184610Salfred#define HUG_TWHEEL 0x0048 /* M$ Wireless Intellimouse Wheel */ 117184610Salfred#define HUG_SYSTEM_CONTROL 0x0080 118184610Salfred#define HUG_SYSTEM_POWER_DOWN 0x0081 119184610Salfred#define HUG_SYSTEM_SLEEP 0x0082 120184610Salfred#define HUG_SYSTEM_WAKEUP 0x0083 121184610Salfred#define HUG_SYSTEM_CONTEXT_MENU 0x0084 122184610Salfred#define HUG_SYSTEM_MAIN_MENU 0x0085 123184610Salfred#define HUG_SYSTEM_APP_MENU 0x0086 124184610Salfred#define HUG_SYSTEM_MENU_HELP 0x0087 125184610Salfred#define HUG_SYSTEM_MENU_EXIT 0x0088 126184610Salfred#define HUG_SYSTEM_MENU_SELECT 0x0089 127184610Salfred#define HUG_SYSTEM_MENU_RIGHT 0x008a 128184610Salfred#define HUG_SYSTEM_MENU_LEFT 0x008b 129184610Salfred#define HUG_SYSTEM_MENU_UP 0x008c 130184610Salfred#define HUG_SYSTEM_MENU_DOWN 0x008d 131192925Sthompsa#define HUG_APPLE_EJECT 0x00b8 132184610Salfred 133184610Salfred/* Usages Digitizers */ 134184610Salfred#define HUD_UNDEFINED 0x0000 135184610Salfred#define HUD_TIP_PRESSURE 0x0030 136184610Salfred#define HUD_BARREL_PRESSURE 0x0031 137184610Salfred#define HUD_IN_RANGE 0x0032 138184610Salfred#define HUD_TOUCH 0x0033 139184610Salfred#define HUD_UNTOUCH 0x0034 140184610Salfred#define HUD_TAP 0x0035 141184610Salfred#define HUD_QUALITY 0x0036 142184610Salfred#define HUD_DATA_VALID 0x0037 143184610Salfred#define HUD_TRANSDUCER_INDEX 0x0038 144184610Salfred#define HUD_TABLET_FKEYS 0x0039 145184610Salfred#define HUD_PROGRAM_CHANGE_KEYS 0x003a 146184610Salfred#define HUD_BATTERY_STRENGTH 0x003b 147184610Salfred#define HUD_INVERT 0x003c 148184610Salfred#define HUD_X_TILT 0x003d 149184610Salfred#define HUD_Y_TILT 0x003e 150184610Salfred#define HUD_AZIMUTH 0x003f 151184610Salfred#define HUD_ALTITUDE 0x0040 152184610Salfred#define HUD_TWIST 0x0041 153184610Salfred#define HUD_TIP_SWITCH 0x0042 154184610Salfred#define HUD_SEC_TIP_SWITCH 0x0043 155184610Salfred#define HUD_BARREL_SWITCH 0x0044 156184610Salfred#define HUD_ERASER 0x0045 157184610Salfred#define HUD_TABLET_PICK 0x0046 158184610Salfred 159208009Sthompsa/* Usages, Consumer */ 160208009Sthompsa#define HUC_AC_PAN 0x0238 161208009Sthompsa 162184610Salfred#define HID_USAGE2(p,u) (((p) << 16) | (u)) 163184610Salfred 164184610Salfred#define UHID_INPUT_REPORT 0x01 165184610Salfred#define UHID_OUTPUT_REPORT 0x02 166184610Salfred#define UHID_FEATURE_REPORT 0x03 167184610Salfred 168184610Salfred/* Bits in the input/output/feature items */ 169184610Salfred#define HIO_CONST 0x001 170184610Salfred#define HIO_VARIABLE 0x002 171184610Salfred#define HIO_RELATIVE 0x004 172184610Salfred#define HIO_WRAP 0x008 173184610Salfred#define HIO_NONLINEAR 0x010 174184610Salfred#define HIO_NOPREF 0x020 175184610Salfred#define HIO_NULLSTATE 0x040 176184610Salfred#define HIO_VOLATILE 0x080 177184610Salfred#define HIO_BUFBYTES 0x100 178184610Salfred 179194677Sthompsa#ifdef _KERNEL 180194677Sthompsastruct usb_config_descriptor; 181194677Sthompsa 182194677Sthompsaenum hid_kind { 183194677Sthompsa hid_input, hid_output, hid_feature, hid_collection, hid_endcollection 184194677Sthompsa}; 185194677Sthompsa 186194677Sthompsastruct hid_location { 187194677Sthompsa uint32_t size; 188194677Sthompsa uint32_t count; 189194677Sthompsa uint32_t pos; 190194677Sthompsa}; 191194677Sthompsa 192194677Sthompsastruct hid_item { 193194677Sthompsa /* Global */ 194194677Sthompsa int32_t _usage_page; 195194677Sthompsa int32_t logical_minimum; 196194677Sthompsa int32_t logical_maximum; 197194677Sthompsa int32_t physical_minimum; 198194677Sthompsa int32_t physical_maximum; 199194677Sthompsa int32_t unit_exponent; 200194677Sthompsa int32_t unit; 201194677Sthompsa int32_t report_ID; 202194677Sthompsa /* Local */ 203194677Sthompsa int32_t usage; 204194677Sthompsa int32_t usage_minimum; 205194677Sthompsa int32_t usage_maximum; 206194677Sthompsa int32_t designator_index; 207194677Sthompsa int32_t designator_minimum; 208194677Sthompsa int32_t designator_maximum; 209194677Sthompsa int32_t string_index; 210194677Sthompsa int32_t string_minimum; 211194677Sthompsa int32_t string_maximum; 212194677Sthompsa int32_t set_delimiter; 213194677Sthompsa /* Misc */ 214194677Sthompsa int32_t collection; 215194677Sthompsa int collevel; 216194677Sthompsa enum hid_kind kind; 217194677Sthompsa uint32_t flags; 218194677Sthompsa /* Location */ 219194677Sthompsa struct hid_location loc; 220194677Sthompsa}; 221194677Sthompsa 222194677Sthompsa/* prototypes from "usb_hid.c" */ 223194677Sthompsa 224194677Sthompsastruct hid_data *hid_start_parse(const void *d, usb_size_t len, int kindset); 225194677Sthompsavoid hid_end_parse(struct hid_data *s); 226194677Sthompsaint hid_get_item(struct hid_data *s, struct hid_item *h); 227194677Sthompsaint hid_report_size(const void *buf, usb_size_t len, enum hid_kind k, 228194677Sthompsa uint8_t *id); 229194677Sthompsaint hid_locate(const void *desc, usb_size_t size, uint32_t usage, 230194677Sthompsa enum hid_kind kind, uint8_t index, struct hid_location *loc, 231194677Sthompsa uint32_t *flags, uint8_t *id); 232194677Sthompsauint32_t hid_get_data(const uint8_t *buf, usb_size_t len, 233194677Sthompsa struct hid_location *loc); 234194677Sthompsaint hid_is_collection(const void *desc, usb_size_t size, uint32_t usage); 235194677Sthompsastruct usb_hid_descriptor *hid_get_descriptor_from_usb( 236194677Sthompsa struct usb_config_descriptor *cd, 237194677Sthompsa struct usb_interface_descriptor *id); 238194677Sthompsausb_error_t usbd_req_get_hid_desc(struct usb_device *udev, struct mtx *mtx, 239194677Sthompsa void **descp, uint16_t *sizep, struct malloc_type *mem, 240194677Sthompsa uint8_t iface_index); 241194677Sthompsa#endif /* _KERNEL */ 242194230Sthompsa#endif /* _USB_HID_H_ */ 243