10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7492SZhigang.Lu@Sun.COM  * Common Development and Distribution License (the "License").
6*7492SZhigang.Lu@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*7492SZhigang.Lu@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef _SYS_USB_HIDPARSER_IMPL_H
270Sstevel@tonic-gate #define	_SYS_USB_HIDPARSER_IMPL_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #ifdef __cplusplus
310Sstevel@tonic-gate extern "C" {
320Sstevel@tonic-gate #endif
330Sstevel@tonic-gate 
340Sstevel@tonic-gate 
350Sstevel@tonic-gate /*
360Sstevel@tonic-gate  * This header file is only included by the hidparser.  It contains
370Sstevel@tonic-gate  * implementation specifc information for the hidparser.
380Sstevel@tonic-gate  */
390Sstevel@tonic-gate 
400Sstevel@tonic-gate 
410Sstevel@tonic-gate /*
420Sstevel@tonic-gate  *  This is for Global and Local items like Usage Page,
430Sstevel@tonic-gate  *  Usage Min, Logical Min, Report Count, Report Size etc.
440Sstevel@tonic-gate  *  "value" was declared as char array to handle
450Sstevel@tonic-gate  *  the case of extended items which can be up to
460Sstevel@tonic-gate  *  255 bytes.
470Sstevel@tonic-gate  */
480Sstevel@tonic-gate typedef struct entity_attribute {
490Sstevel@tonic-gate 	uint_t	entity_attribute_tag;		/* see tag codes below */
500Sstevel@tonic-gate 	char	*entity_attribute_value;	/* Data bytes */
510Sstevel@tonic-gate 	int	entity_attribute_length; 	/* No. of data bytes */
520Sstevel@tonic-gate 
530Sstevel@tonic-gate 	/* linked list of attributes */
540Sstevel@tonic-gate 	struct	entity_attribute	*entity_attribute_next;
550Sstevel@tonic-gate } entity_attribute_t;
560Sstevel@tonic-gate 
570Sstevel@tonic-gate 
580Sstevel@tonic-gate /*
590Sstevel@tonic-gate  *  This is for these entities: Collection, Input, Output,
600Sstevel@tonic-gate  *  Feature and End Collection.
610Sstevel@tonic-gate  */
620Sstevel@tonic-gate typedef struct entity_item {
630Sstevel@tonic-gate 
640Sstevel@tonic-gate 	/* input, output, collection, feature or end collection */
650Sstevel@tonic-gate 	int		entity_item_type;
660Sstevel@tonic-gate 
670Sstevel@tonic-gate 	/* constant, variable, relative, etc... */
680Sstevel@tonic-gate 	char		*entity_item_params;
690Sstevel@tonic-gate 
700Sstevel@tonic-gate 	int		entity_item_params_leng; /* No. of bytes for params */
710Sstevel@tonic-gate 
720Sstevel@tonic-gate 	/*
730Sstevel@tonic-gate 	 *   linked list of entity and control attributes. Parser is
740Sstevel@tonic-gate 	 *   responsbile for handling entity attributes' inheritance,
750Sstevel@tonic-gate 	 *   therefore this is NULL for end collection. But not for
760Sstevel@tonic-gate 	 *   begin collection.
770Sstevel@tonic-gate 	 */
780Sstevel@tonic-gate 	entity_attribute_t	*entity_item_attributes;
790Sstevel@tonic-gate 
800Sstevel@tonic-gate 	/*
810Sstevel@tonic-gate 	 *  linked list of children if this is a collection
820Sstevel@tonic-gate 	 *  otherwise pointer to data for input/output
830Sstevel@tonic-gate 	 */
840Sstevel@tonic-gate 	union info  {
850Sstevel@tonic-gate 		struct entity_item	*child;
860Sstevel@tonic-gate 		void			*data;
870Sstevel@tonic-gate 	} info;
880Sstevel@tonic-gate 
890Sstevel@tonic-gate 	/* pointer to the right sibling */
900Sstevel@tonic-gate 	struct entity_item	*entity_item_right_sibling;
910Sstevel@tonic-gate 
920Sstevel@tonic-gate 	struct entity_item	*prev_coll;
930Sstevel@tonic-gate 
940Sstevel@tonic-gate } entity_item_t;
950Sstevel@tonic-gate 
960Sstevel@tonic-gate 
970Sstevel@tonic-gate 
980Sstevel@tonic-gate /* Use this typedef in defining the FIRSTs */
990Sstevel@tonic-gate typedef int			hidparser_terminal_t;
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate /*
1030Sstevel@tonic-gate  * Hid parser handle
1040Sstevel@tonic-gate  */
1050Sstevel@tonic-gate typedef struct hidparser_handle_impl {
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate 	/* Pointer to the parser tree */
1080Sstevel@tonic-gate 	entity_item_t		*hidparser_handle_parse_tree;
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate 	/* Pointer to the hid descriptor */
1110Sstevel@tonic-gate 	usb_hid_descr_t		*hidparser_handle_hid_descr;
1120Sstevel@tonic-gate } hidparser_handle;
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate /*
1160Sstevel@tonic-gate  * Additional items that are not defined in hid_parser.h because they should
1170Sstevel@tonic-gate  * not be exposed to the hid streams modules.
1180Sstevel@tonic-gate  */
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate /*
1220Sstevel@tonic-gate  * Additional Local Items
1230Sstevel@tonic-gate  *      See section 6.2.2.8 of the HID 1.0 specification for
1240Sstevel@tonic-gate  *      more details.
1250Sstevel@tonic-gate  */
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate #define	HIDPARSER_ITEM_SET_DELIMITER 0xA8
1280Sstevel@tonic-gate 
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate /*
1310Sstevel@tonic-gate  * Addtional Global Items
1320Sstevel@tonic-gate  *      See section 6.2.2.7 of the HID 1.0 specifations for
1330Sstevel@tonic-gate  *      more details.
1340Sstevel@tonic-gate  */
1350Sstevel@tonic-gate #define	HIDPARSER_ITEM_USAGE_PAGE 0x04
1360Sstevel@tonic-gate #define	HIDPARSER_ITEM_PUSH 0xA4
1370Sstevel@tonic-gate #define	HIDPARSER_ITEM_POP 0xB4
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate /*
1400Sstevel@tonic-gate  * Main Items
1410Sstevel@tonic-gate  *      See section 6.2.2.5 of the HID 1.0 specification for
1420Sstevel@tonic-gate  *      more details.
1430Sstevel@tonic-gate  */
1440Sstevel@tonic-gate #define	HIDPARSER_ITEM_COLLECTION 0xA0
1450Sstevel@tonic-gate #define	HIDPARSER_ITEM_END_COLLECTION 0xC0
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate typedef struct entity_attribute_stack {
1480Sstevel@tonic-gate 	struct entity_attribute_stack	*next;
1490Sstevel@tonic-gate 	entity_attribute_t	*list;
1500Sstevel@tonic-gate } entity_attribute_stack_t;
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate /*
1530Sstevel@tonic-gate  * This structure is the interface between the parser
1540Sstevel@tonic-gate  * and the scanner.
1550Sstevel@tonic-gate  */
1560Sstevel@tonic-gate typedef struct hidparser_tok {
1570Sstevel@tonic-gate 	unsigned char		*hidparser_tok_text;	/* Data bytes */
1580Sstevel@tonic-gate 	int			hidparser_tok_leng;	/* No. of data bytes */
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate 	/* Maximum buffer size */
1610Sstevel@tonic-gate 	size_t			hidparser_tok_max_bsize;
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate 	/* Raw descriptor */
1640Sstevel@tonic-gate 	unsigned char		*hidparser_tok_entity_descriptor;
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate 	/* Index to token currently being processed */
1670Sstevel@tonic-gate 	size_t			hidparser_tok_index;
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate 	/* Current token being processed */
1700Sstevel@tonic-gate 	int			hidparser_tok_token;
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate 	/* Pointer to the Global Item list */
1730Sstevel@tonic-gate 	entity_attribute_t	*hidparser_tok_gitem_head;
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate 	/* Pointer to the Local Item list */
1760Sstevel@tonic-gate 	entity_attribute_t	*hidparser_tok_litem_head;
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate 	/* Stack for push|pop Items */
1790Sstevel@tonic-gate 	entity_attribute_stack_t	*hidparser_head;
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate } hidparser_tok_t;
1820Sstevel@tonic-gate 
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate /*  Entity Item Tags - HID 5.4.3  */
1850Sstevel@tonic-gate #define	R_ITEM_INPUT 0x80
1860Sstevel@tonic-gate #define	R_ITEM_OUTPUT 0x90
1870Sstevel@tonic-gate #define	R_ITEM_COLLECTION 0xA0
1880Sstevel@tonic-gate #define	R_ITEM_FEATURE 0xB0
1890Sstevel@tonic-gate #define	R_ITEM_END_COLLECTION 0xC0
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate /*  Entity Attribute Item Tags HID 5.4.4 */
1920Sstevel@tonic-gate #define	R_ITEM_USAGE_PAGE 0x04
1930Sstevel@tonic-gate #define	R_ITEM_LOGICAL_MINIMUM 0x14
1940Sstevel@tonic-gate #define	R_ITEM_LOGICAL_MAXIMUM 0x24
1950Sstevel@tonic-gate #define	R_ITEM_PHYSICAL_MINIMUM 0x34
1960Sstevel@tonic-gate #define	R_ITEM_PHYSICAL_MAXIMUM 0x44
1970Sstevel@tonic-gate #define	R_ITEM_EXPONENT 0x54
1980Sstevel@tonic-gate #define	R_ITEM_UNIT 0x64
1990Sstevel@tonic-gate #define	R_ITEM_REPORT_SIZE 0x74
2000Sstevel@tonic-gate #define	R_ITEM_REPORT_ID 0x84
2010Sstevel@tonic-gate #define	R_ITEM_REPORT_COUNT 0x94
2020Sstevel@tonic-gate #define	R_ITEM_PUSH 0xA4
2030Sstevel@tonic-gate #define	R_ITEM_POP 0xB4
2040Sstevel@tonic-gate 
2050Sstevel@tonic-gate /*  Control Attribute Item Tags  */
2060Sstevel@tonic-gate #define	R_ITEM_USAGE 0x08
2070Sstevel@tonic-gate #define	R_ITEM_USAGE_MIN 0x18
2080Sstevel@tonic-gate #define	R_ITEM_USAGE_MAX 0x28
2090Sstevel@tonic-gate #define	R_ITEM_DESIGNATOR_INDEX 0x38
2100Sstevel@tonic-gate #define	R_ITEM_DESIGNATOR_MIN 0x48
2110Sstevel@tonic-gate #define	R_ITEM_DESIGNATOR_MAX 0x58
2120Sstevel@tonic-gate #define	R_ITEM_STRING_INDEX 0x78
2130Sstevel@tonic-gate #define	R_ITEM_STRING_MIN 0x88
2140Sstevel@tonic-gate #define	R_ITEM_STRING_MAX 0x98
2150Sstevel@tonic-gate #define	R_ITEM_SET_DELIMITER 0xA8
2160Sstevel@tonic-gate 
2170Sstevel@tonic-gate 
2180Sstevel@tonic-gate /* Tags used to find the FIRST tokens corresponding to a nonterminal */
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate #define	HIDPARSER_ITEMS		0
2210Sstevel@tonic-gate 
2220Sstevel@tonic-gate /* Used for hidparser Error check */
2230Sstevel@tonic-gate #define	HIDPARSER_ERR_ERROR		0x8000
2240Sstevel@tonic-gate #define	HIDPARSER_ERR_WARN		0x0000
2250Sstevel@tonic-gate #define	HIDPARSER_ERR_STANDARD		0x0000
2260Sstevel@tonic-gate #define	HIDPARSER_ERR_VENDOR		0x4000
2270Sstevel@tonic-gate #define	HIDPARSER_ERR_TAG_MASK		0x3f00
2280Sstevel@tonic-gate #define	HIDPARSER_ERR_SUBCODE_MASK	0xff
2290Sstevel@tonic-gate #define	HIDPARSER_DELIM_ERR1		1
2300Sstevel@tonic-gate #define	HIDPARSER_DELIM_ERR2		2
2310Sstevel@tonic-gate #define	HIDPARSER_DELIM_ERR3		3
2320Sstevel@tonic-gate 
2330Sstevel@tonic-gate 
2340Sstevel@tonic-gate /* other */
2350Sstevel@tonic-gate #define	EXTENDED_ITEM			0xFE
2360Sstevel@tonic-gate #define	HIDPARSER_TEXT_LENGTH		500
2370Sstevel@tonic-gate #define	HIDPARSER_ISLOCAL_MASK		0x08
2380Sstevel@tonic-gate 
2390Sstevel@tonic-gate /*
2400Sstevel@tonic-gate  * Debug printing
2410Sstevel@tonic-gate  */
2420Sstevel@tonic-gate #define	PRINT_MASK_ALL		0xFFFFFFFF
2430Sstevel@tonic-gate 
2440Sstevel@tonic-gate 
2450Sstevel@tonic-gate #ifdef __cplusplus
2460Sstevel@tonic-gate }
2470Sstevel@tonic-gate #endif
2480Sstevel@tonic-gate 
2490Sstevel@tonic-gate #endif	/* _SYS_USB_HIDPARSER_IMPL_H */
250