| 1 | /*	$OpenBSD: usbhid.h,v 1.9 2021/05/30 19:54:52 jcs Exp $	*/ |
| 2 | /*	$NetBSD: usbhid.h,v 1.1 2001/12/28 17:45:27 augustss Exp $	*/ |
| 3 | |
| 4 | /* |
| 5 | * Copyright (c) 1999 Lennart Augustsson <augustss@netbsd.org> |
| 6 | * All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in the |
| 15 | * documentation and/or other materials provided with the distribution. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 27 | * SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | typedef struct report_desc *report_desc_t; |
| 31 | |
| 32 | typedef struct hid_data *hid_data_t; |
| 33 | |
| 34 | typedef enum hid_kind { |
| 35 | 	hid_input, hid_output, hid_feature, hid_collection, hid_endcollection |
| 36 | } hid_kind_t; |
| 37 | |
| 38 | typedef struct hid_item { |
| 39 | 	/* Global */ |
| 40 | 	uint32_t _usage_page; |
| 41 | 	int32_t logical_minimum; |
| 42 | 	int32_t logical_maximum; |
| 43 | 	int32_t physical_minimum; |
| 44 | 	int32_t physical_maximum; |
| 45 | 	int32_t unit_exponent; |
| 46 | 	int32_t unit; |
| 47 | 	int32_t report_size; |
| 48 | 	int32_t report_ID; |
| 49 | #define NO_REPORT_ID 0 |
| 50 | 	int32_t report_count; |
| 51 | 	/* Local */ |
| 52 | 	uint32_t usage; |
| 53 | 	int32_t usage_minimum; |
| 54 | 	int32_t usage_maximum; |
| 55 | 	int32_t designator_index; |
| 56 | 	int32_t designator_minimum; |
| 57 | 	int32_t designator_maximum; |
| 58 | 	int32_t string_index; |
| 59 | 	int32_t string_minimum; |
| 60 | 	int32_t string_maximum; |
| 61 | 	int32_t set_delimiter; |
| 62 | 	/* Misc */ |
| 63 | 	int32_t collection; |
| 64 | 	int	collevel; |
| 65 | 	enum hid_kind kind; |
| 66 | 	uint32_t flags; |
| 67 | 	/* Location */ |
| 68 | 	uint32_t pos; |
| 69 | 	/* unused */ |
| 70 | 	struct hid_item *next; |
| 71 | } hid_item_t; |
| 72 | |
| 73 | #define HID_PAGE(u) (((u) >> 16) & 0xffff) |
| 74 | #define HID_USAGE(u) ((u) & 0xffff) |
| 75 | |
| 76 | /* Obtaining a report descriptor, descr.c: */ |
| 77 | report_desc_t	hid_get_report_desc(int file); |
| 78 | report_desc_t	hid_use_report_desc(unsigned char *data, unsigned int size); |
| 79 | void		hid_dispose_report_desc(report_desc_t); |
| 80 | void		hid_get_report_desc_data(report_desc_t, uint8_t **, uint32_t *); |
| 81 | |
| 82 | /* Parsing of a HID report descriptor, parse.c: */ |
| 83 | hid_data_t	hid_start_parse(report_desc_t d, int kindset, int id); |
| 84 | void		hid_end_parse(hid_data_t s); |
| 85 | int		hid_get_item(hid_data_t s, hid_item_t *h); |
| 86 | int		hid_report_size(report_desc_t d, enum hid_kind k, int id); |
| 87 | int		hid_locate(report_desc_t d, unsigned int usage, enum hid_kind k, |
| 88 | 		 hid_item_t *h, int id); |
| 89 | |
| 90 | /* Conversion to/from usage names, usage.c: */ |
| 91 | const char	*hid_usage_page(int i); |
| 92 | const char	*hid_usage_in_page(unsigned int u); |
| 93 | void		hid_init(const char *file); |
| 94 | int		hid_start(const char *file); |
| 95 | int		hid_parse_usage_in_page(const char *name); |
| 96 | int		hid_parse_usage_page(const char *name); |
| 97 | |
| 98 | /* Extracting/insertion of data, data.c: */ |
| 99 | int32_t		hid_get_data(const void *p, const hid_item_t *h); |
| 100 | void		hid_set_data(void *p, const hid_item_t *h, int32_t data); |