4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
25 #ifndef _SYS_USB_LIBUSB_LIBUSB_IMPL_H
26 #define _SYS_USB_LIBUSB_LIBUSB_IMPL_H
34 #define DEBUG_ERRORS 1
35 #define DEBUG_RECOVERABLE 2
36 #define DEBUG_FUNCTIONS 3
37 #define DEBUG_DETAILED 4
38 #define DEBUG_DATA_DUMP 5
45 * XXX issues: remove duplicates with usb.h
47 typedef struct usb_device usb_device_t
;
48 typedef struct usb_bus usb_bus_t
;
49 typedef struct usb_ctrl_setup usb_ctrl_setup_t
;
51 /* some useful defines */
52 #define USB_DEV_REQ_HOST_TO_DEV 0x00
53 #define USB_DEV_REQ_DEV_TO_HOST 0x80
54 #define USB_DEV_REQ_DIR_MASK 0x80
56 #define USB_DESCR_TYPE_SETUP_DEV 0x0100
57 #define USB_DESCR_TYPE_SETUP_CFG 0x0200
58 #define USB_DESCR_TYPE_SETUP_STRING 0x0300
59 #define USB_DESCR_TYPE_SETUP_IF 0x0400
60 #define USB_DESCR_TYPE_SETUP_EP 0x0500
61 #define USB_DESCR_TYPE_SETUP_DEV_QLF 0x0600
62 #define USB_DESCR_TYPE_SETUP_OTHER_SPEED_CFG 0x0700
63 #define USB_DESCR_TYPE_SETUP_IFPWR 0x0800
65 #define USB_DESCR_TYPE_DEV 0x01
66 #define USB_DESCR_TYPE_CFG 0x02
67 #define USB_DESCR_TYPE_STRING 0x03
68 #define USB_DESCR_TYPE_IF 0x04
69 #define USB_DESCR_TYPE_EP 0x05
70 #define USB_DESCR_TYPE_DEV_QLF 0x06
71 #define USB_DESCR_TYPE_OTHER_SPEED_CFG 0x07
72 #define USB_DESCR_TYPE_IF_PWR 0x08
75 * bEndpointAddress masks
77 #define USB_EP_NUM_MASK 0x0F /* endpoint number mask */
78 #define USB_EP_DIR_MASK 0x80 /* direction mask */
79 #define USB_EP_DIR_OUT 0x00 /* OUT endpoint */
80 #define USB_EP_DIR_IN 0x80 /* IN endpoint */
83 * The compiler pads the above structures; the following represent the
84 * unpadded, aggregate data sizes.
86 #define USB_DEV_DESCR_SIZE 18 /* device descr size */
87 #define USB_CFG_DESCR_SIZE 9 /* configuration desc. size */
88 #define USBA_CFG_PWR_DESCR_SIZE 18 /* configuration pwr desc. size */
89 #define USB_IF_DESCR_SIZE 9 /* interface descr size */
90 #define USBA_IF_PWR_DESCR_SIZE 15 /* interface pwr descr size */
91 #define USB_EP_DESCR_SIZE 7 /* endpoint descr size */
93 #define BYTE_SWAP(x) ((((x) & 0xff) << 8) | (((x) & 0xff00) >> 8))
100 USB_ERROR_TYPE_NONE
= 0,
101 USB_ERROR_TYPE_STRING
,
106 * This records the file descriptors for endpoint/status devices.
108 typedef struct usb_dev_handle_info
{
109 int configuration_value
;
110 int configuration_index
;
111 int claimed_interface
;
113 int ep_fd
[USB_MAXENDPOINTS
];
114 int ep_status_fd
[USB_MAXENDPOINTS
];
115 int ep_interface
[USB_MAXENDPOINTS
];
116 } usb_dev_handle_info_t
;
119 usb_device_t
*device
;
120 usb_dev_handle_info_t
*info
;
121 } usb_dev_handle_impl_t
;
123 #define USB_MAX_INTERFACES 256
129 usb_dev_handle_impl_t
130 *claimed_interfaces
[USB_MAX_INTERFACES
];
131 } usb_device_specific_t
;
133 #define USB_PARSE_ERROR 0
134 #define USB_DESCR_TYPE_ANY -1 /* Wild card */
136 #define INCREMENT_BUF(buf) \
137 if ((buf)[0] == 0) { \
142 #define isdigit(ch) ((ch >= '0') && (ch <= '9'))
144 typedef struct usb_cfg_descr
{
145 uint8_t bLength
; /* descriptor size */
146 uint8_t bDescriptorType
; /* set to CONFIGURATION */
147 uint16_t wTotalLength
; /* total length of data returned */
148 uint8_t bNumInterfaces
; /* # interfaces in config */
149 uint8_t bConfigurationValue
; /* arg for SetConfiguration */
150 uint8_t iConfiguration
; /* configuration string */
151 uint8_t bmAttributes
; /* config characteristics */
152 uint8_t MaxPower
; /* max pwr consumption */
158 * usb interface descriptor, refer to USB 2.0/9.6.5
160 typedef struct usb_if_descr
{
161 uint8_t bLength
; /* descriptor size */
162 uint8_t bDescriptorType
; /* set to INTERFACE */
163 uint8_t bInterfaceNumber
; /* interface number */
164 uint8_t bAlternateSetting
; /* alt. interface number */
165 uint8_t bNumEndpoints
; /* # of endpoints */
166 uint8_t bInterfaceClass
; /* class code */
167 uint8_t bInterfaceSubClass
; /* sub class code */
168 uint8_t bInterfaceProtocol
; /* protocol code */
169 uint8_t iInterface
; /* description string */
175 * usb endpoint descriptor, refer to USB 2.0/9.6.6
177 typedef struct usb_ep_descr
{
178 uint8_t bLength
; /* descriptor size */
179 uint8_t bDescriptorType
; /* set to ENDPOINT */
180 uint8_t bEndpointAddress
; /* address of this e/p */
181 uint8_t bmAttributes
; /* transfer type */
182 uint16_t wMaxPacketSize
; /* maximum packet size */
183 uint8_t bInterval
; /* e/p polling interval */
184 uint8_t bRefresh
; /* refresh */
185 uint8_t bSynchAddress
;
192 #endif /* _SYS_USB_LIBUSB_LIBUSB_IMPL_H */