17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*d29f5a71Szhigang lu - Sun Microsystems - Beijing China  * Common Development and Distribution License (the "License").
6*d29f5a71Szhigang lu - Sun Microsystems - Beijing China  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*d29f5a71Szhigang lu - Sun Microsystems - Beijing China  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _SYS_USB_HIDPARSER_IMPL_H
277c478bd9Sstevel@tonic-gate #define	_SYS_USB_HIDPARSER_IMPL_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifdef __cplusplus
317c478bd9Sstevel@tonic-gate extern "C" {
327c478bd9Sstevel@tonic-gate #endif
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate  * This header file is only included by the hidparser.  It contains
377c478bd9Sstevel@tonic-gate  * implementation specifc information for the hidparser.
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate /*
427c478bd9Sstevel@tonic-gate  *  This is for Global and Local items like Usage Page,
437c478bd9Sstevel@tonic-gate  *  Usage Min, Logical Min, Report Count, Report Size etc.
447c478bd9Sstevel@tonic-gate  *  "value" was declared as char array to handle
457c478bd9Sstevel@tonic-gate  *  the case of extended items which can be up to
467c478bd9Sstevel@tonic-gate  *  255 bytes.
477c478bd9Sstevel@tonic-gate  */
487c478bd9Sstevel@tonic-gate typedef struct entity_attribute {
497c478bd9Sstevel@tonic-gate 	uint_t	entity_attribute_tag;		/* see tag codes below */
507c478bd9Sstevel@tonic-gate 	char	*entity_attribute_value;	/* Data bytes */
517c478bd9Sstevel@tonic-gate 	int	entity_attribute_length; 	/* No. of data bytes */
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate 	/* linked list of attributes */
547c478bd9Sstevel@tonic-gate 	struct	entity_attribute	*entity_attribute_next;
557c478bd9Sstevel@tonic-gate } entity_attribute_t;
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate /*
597c478bd9Sstevel@tonic-gate  *  This is for these entities: Collection, Input, Output,
607c478bd9Sstevel@tonic-gate  *  Feature and End Collection.
617c478bd9Sstevel@tonic-gate  */
627c478bd9Sstevel@tonic-gate typedef struct entity_item {
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate 	/* input, output, collection, feature or end collection */
657c478bd9Sstevel@tonic-gate 	int		entity_item_type;
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate 	/* constant, variable, relative, etc... */
687c478bd9Sstevel@tonic-gate 	char		*entity_item_params;
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate 	int		entity_item_params_leng; /* No. of bytes for params */
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate 	/*
737c478bd9Sstevel@tonic-gate 	 *   linked list of entity and control attributes. Parser is
747c478bd9Sstevel@tonic-gate 	 *   responsbile for handling entity attributes' inheritance,
757c478bd9Sstevel@tonic-gate 	 *   therefore this is NULL for end collection. But not for
767c478bd9Sstevel@tonic-gate 	 *   begin collection.
777c478bd9Sstevel@tonic-gate 	 */
787c478bd9Sstevel@tonic-gate 	entity_attribute_t	*entity_item_attributes;
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate 	/*
817c478bd9Sstevel@tonic-gate 	 *  linked list of children if this is a collection
827c478bd9Sstevel@tonic-gate 	 *  otherwise pointer to data for input/output
837c478bd9Sstevel@tonic-gate 	 */
847c478bd9Sstevel@tonic-gate 	union info  {
857c478bd9Sstevel@tonic-gate 		struct entity_item	*child;
867c478bd9Sstevel@tonic-gate 		void			*data;
877c478bd9Sstevel@tonic-gate 	} info;
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate 	/* pointer to the right sibling */
907c478bd9Sstevel@tonic-gate 	struct entity_item	*entity_item_right_sibling;
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate 	struct entity_item	*prev_coll;
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate } entity_item_t;
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate /* Use this typedef in defining the FIRSTs */
997c478bd9Sstevel@tonic-gate typedef int			hidparser_terminal_t;
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate /*
1037c478bd9Sstevel@tonic-gate  * Hid parser handle
1047c478bd9Sstevel@tonic-gate  */
1057c478bd9Sstevel@tonic-gate typedef struct hidparser_handle_impl {
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate 	/* Pointer to the parser tree */
1087c478bd9Sstevel@tonic-gate 	entity_item_t		*hidparser_handle_parse_tree;
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 	/* Pointer to the hid descriptor */
1117c478bd9Sstevel@tonic-gate 	usb_hid_descr_t		*hidparser_handle_hid_descr;
1127c478bd9Sstevel@tonic-gate } hidparser_handle;
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate /*
1167c478bd9Sstevel@tonic-gate  * Additional items that are not defined in hid_parser.h because they should
1177c478bd9Sstevel@tonic-gate  * not be exposed to the hid streams modules.
1187c478bd9Sstevel@tonic-gate  */
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate /*
1227c478bd9Sstevel@tonic-gate  * Additional Local Items
1237c478bd9Sstevel@tonic-gate  *      See section 6.2.2.8 of the HID 1.0 specification for
1247c478bd9Sstevel@tonic-gate  *      more details.
1257c478bd9Sstevel@tonic-gate  */
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate #define	HIDPARSER_ITEM_SET_DELIMITER 0xA8
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate /*
1317c478bd9Sstevel@tonic-gate  * Addtional Global Items
1327c478bd9Sstevel@tonic-gate  *      See section 6.2.2.7 of the HID 1.0 specifations for
1337c478bd9Sstevel@tonic-gate  *      more details.
1347c478bd9Sstevel@tonic-gate  */
1357c478bd9Sstevel@tonic-gate #define	HIDPARSER_ITEM_USAGE_PAGE 0x04
1367c478bd9Sstevel@tonic-gate #define	HIDPARSER_ITEM_PUSH 0xA4
1377c478bd9Sstevel@tonic-gate #define	HIDPARSER_ITEM_POP 0xB4
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate /*
1407c478bd9Sstevel@tonic-gate  * Main Items
1417c478bd9Sstevel@tonic-gate  *      See section 6.2.2.5 of the HID 1.0 specification for
1427c478bd9Sstevel@tonic-gate  *      more details.
1437c478bd9Sstevel@tonic-gate  */
1447c478bd9Sstevel@tonic-gate #define	HIDPARSER_ITEM_COLLECTION 0xA0
1457c478bd9Sstevel@tonic-gate #define	HIDPARSER_ITEM_END_COLLECTION 0xC0
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate typedef struct entity_attribute_stack {
1487c478bd9Sstevel@tonic-gate 	struct entity_attribute_stack	*next;
1497c478bd9Sstevel@tonic-gate 	entity_attribute_t	*list;
1507c478bd9Sstevel@tonic-gate } entity_attribute_stack_t;
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate /*
1537c478bd9Sstevel@tonic-gate  * This structure is the interface between the parser
1547c478bd9Sstevel@tonic-gate  * and the scanner.
1557c478bd9Sstevel@tonic-gate  */
1567c478bd9Sstevel@tonic-gate typedef struct hidparser_tok {
1577c478bd9Sstevel@tonic-gate 	unsigned char		*hidparser_tok_text;	/* Data bytes */
1587c478bd9Sstevel@tonic-gate 	int			hidparser_tok_leng;	/* No. of data bytes */
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate 	/* Maximum buffer size */
1617c478bd9Sstevel@tonic-gate 	size_t			hidparser_tok_max_bsize;
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate 	/* Raw descriptor */
1647c478bd9Sstevel@tonic-gate 	unsigned char		*hidparser_tok_entity_descriptor;
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate 	/* Index to token currently being processed */
1677c478bd9Sstevel@tonic-gate 	size_t			hidparser_tok_index;
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate 	/* Current token being processed */
1707c478bd9Sstevel@tonic-gate 	int			hidparser_tok_token;
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate 	/* Pointer to the Global Item list */
1737c478bd9Sstevel@tonic-gate 	entity_attribute_t	*hidparser_tok_gitem_head;
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate 	/* Pointer to the Local Item list */
1767c478bd9Sstevel@tonic-gate 	entity_attribute_t	*hidparser_tok_litem_head;
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate 	/* Stack for push|pop Items */
1797c478bd9Sstevel@tonic-gate 	entity_attribute_stack_t	*hidparser_head;
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate } hidparser_tok_t;
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate /*  Entity Item Tags - HID 5.4.3  */
1857c478bd9Sstevel@tonic-gate #define	R_ITEM_INPUT 0x80
1867c478bd9Sstevel@tonic-gate #define	R_ITEM_OUTPUT 0x90
1877c478bd9Sstevel@tonic-gate #define	R_ITEM_COLLECTION 0xA0
1887c478bd9Sstevel@tonic-gate #define	R_ITEM_FEATURE 0xB0
1897c478bd9Sstevel@tonic-gate #define	R_ITEM_END_COLLECTION 0xC0
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate /*  Entity Attribute Item Tags HID 5.4.4 */
1927c478bd9Sstevel@tonic-gate #define	R_ITEM_USAGE_PAGE 0x04
1937c478bd9Sstevel@tonic-gate #define	R_ITEM_LOGICAL_MINIMUM 0x14
1947c478bd9Sstevel@tonic-gate #define	R_ITEM_LOGICAL_MAXIMUM 0x24
1957c478bd9Sstevel@tonic-gate #define	R_ITEM_PHYSICAL_MINIMUM 0x34
1967c478bd9Sstevel@tonic-gate #define	R_ITEM_PHYSICAL_MAXIMUM 0x44
1977c478bd9Sstevel@tonic-gate #define	R_ITEM_EXPONENT 0x54
1987c478bd9Sstevel@tonic-gate #define	R_ITEM_UNIT 0x64
1997c478bd9Sstevel@tonic-gate #define	R_ITEM_REPORT_SIZE 0x74
2007c478bd9Sstevel@tonic-gate #define	R_ITEM_REPORT_ID 0x84
2017c478bd9Sstevel@tonic-gate #define	R_ITEM_REPORT_COUNT 0x94
2027c478bd9Sstevel@tonic-gate #define	R_ITEM_PUSH 0xA4
2037c478bd9Sstevel@tonic-gate #define	R_ITEM_POP 0xB4
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate /*  Control Attribute Item Tags  */
2067c478bd9Sstevel@tonic-gate #define	R_ITEM_USAGE 0x08
2077c478bd9Sstevel@tonic-gate #define	R_ITEM_USAGE_MIN 0x18
2087c478bd9Sstevel@tonic-gate #define	R_ITEM_USAGE_MAX 0x28
2097c478bd9Sstevel@tonic-gate #define	R_ITEM_DESIGNATOR_INDEX 0x38
2107c478bd9Sstevel@tonic-gate #define	R_ITEM_DESIGNATOR_MIN 0x48
2117c478bd9Sstevel@tonic-gate #define	R_ITEM_DESIGNATOR_MAX 0x58
2127c478bd9Sstevel@tonic-gate #define	R_ITEM_STRING_INDEX 0x78
2137c478bd9Sstevel@tonic-gate #define	R_ITEM_STRING_MIN 0x88
2147c478bd9Sstevel@tonic-gate #define	R_ITEM_STRING_MAX 0x98
2157c478bd9Sstevel@tonic-gate #define	R_ITEM_SET_DELIMITER 0xA8
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate /* Tags used to find the FIRST tokens corresponding to a nonterminal */
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate #define	HIDPARSER_ITEMS		0
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate /* Used for hidparser Error check */
2237c478bd9Sstevel@tonic-gate #define	HIDPARSER_ERR_ERROR		0x8000
2247c478bd9Sstevel@tonic-gate #define	HIDPARSER_ERR_WARN		0x0000
2257c478bd9Sstevel@tonic-gate #define	HIDPARSER_ERR_STANDARD		0x0000
2267c478bd9Sstevel@tonic-gate #define	HIDPARSER_ERR_VENDOR		0x4000
2277c478bd9Sstevel@tonic-gate #define	HIDPARSER_ERR_TAG_MASK		0x3f00
2287c478bd9Sstevel@tonic-gate #define	HIDPARSER_ERR_SUBCODE_MASK	0xff
2297c478bd9Sstevel@tonic-gate #define	HIDPARSER_DELIM_ERR1		1
2307c478bd9Sstevel@tonic-gate #define	HIDPARSER_DELIM_ERR2		2
2317c478bd9Sstevel@tonic-gate #define	HIDPARSER_DELIM_ERR3		3
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate /* other */
2357c478bd9Sstevel@tonic-gate #define	EXTENDED_ITEM			0xFE
2367c478bd9Sstevel@tonic-gate #define	HIDPARSER_TEXT_LENGTH		500
2377c478bd9Sstevel@tonic-gate #define	HIDPARSER_ISLOCAL_MASK		0x08
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate /*
2407c478bd9Sstevel@tonic-gate  * Debug printing
2417c478bd9Sstevel@tonic-gate  */
2427c478bd9Sstevel@tonic-gate #define	PRINT_MASK_ALL		0xFFFFFFFF
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate #ifdef __cplusplus
2467c478bd9Sstevel@tonic-gate }
2477c478bd9Sstevel@tonic-gate #endif
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate #endif	/* _SYS_USB_HIDPARSER_IMPL_H */
250