1/*
2 * Copyright 2006-2008, Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5
6#ifndef _USB_RAW_H_
7#define _USB_RAW_H_
8
9#include <USB3.h>
10
11#define B_USB_RAW_PROTOCOL_VERSION	0x0015
12#define B_USB_RAW_ACTIVE_ALTERNATE	0xffffffff
13
14typedef enum {
15	B_USB_RAW_COMMAND_GET_VERSION = 0x1000,
16
17	B_USB_RAW_COMMAND_GET_DEVICE_DESCRIPTOR = 0x2000,
18	B_USB_RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR,
19	B_USB_RAW_COMMAND_GET_INTERFACE_DESCRIPTOR,
20	B_USB_RAW_COMMAND_GET_ENDPOINT_DESCRIPTOR,
21	B_USB_RAW_COMMAND_GET_STRING_DESCRIPTOR,
22	B_USB_RAW_COMMAND_GET_GENERIC_DESCRIPTOR,
23	B_USB_RAW_COMMAND_GET_ALT_INTERFACE_COUNT,
24	B_USB_RAW_COMMAND_GET_ACTIVE_ALT_INTERFACE_INDEX,
25	B_USB_RAW_COMMAND_GET_INTERFACE_DESCRIPTOR_ETC,
26	B_USB_RAW_COMMAND_GET_ENDPOINT_DESCRIPTOR_ETC,
27	B_USB_RAW_COMMAND_GET_GENERIC_DESCRIPTOR_ETC,
28	B_USB_RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR_ETC,
29
30	B_USB_RAW_COMMAND_SET_CONFIGURATION = 0x3000,
31	B_USB_RAW_COMMAND_SET_FEATURE,
32	B_USB_RAW_COMMAND_CLEAR_FEATURE,
33	B_USB_RAW_COMMAND_GET_STATUS,
34	B_USB_RAW_COMMAND_GET_DESCRIPTOR,
35	B_USB_RAW_COMMAND_SET_ALT_INTERFACE,
36
37	B_USB_RAW_COMMAND_CONTROL_TRANSFER = 0x4000,
38	B_USB_RAW_COMMAND_INTERRUPT_TRANSFER,
39	B_USB_RAW_COMMAND_BULK_TRANSFER,
40	B_USB_RAW_COMMAND_ISOCHRONOUS_TRANSFER
41} usb_raw_command_id;
42
43
44typedef enum {
45	B_USB_RAW_STATUS_SUCCESS = 0,
46
47	B_USB_RAW_STATUS_FAILED,
48	B_USB_RAW_STATUS_ABORTED,
49	B_USB_RAW_STATUS_STALLED,
50	B_USB_RAW_STATUS_CRC_ERROR,
51	B_USB_RAW_STATUS_TIMEOUT,
52
53	B_USB_RAW_STATUS_INVALID_CONFIGURATION,
54	B_USB_RAW_STATUS_INVALID_INTERFACE,
55	B_USB_RAW_STATUS_INVALID_ENDPOINT,
56	B_USB_RAW_STATUS_INVALID_STRING,
57
58	B_USB_RAW_STATUS_NO_MEMORY
59} usb_raw_command_status;
60
61
62typedef union {
63	struct {
64		status_t						status;
65	} version;
66
67	struct {
68		status_t						status;
69		usb_device_descriptor			*descriptor;
70	} device;
71
72	struct {
73		status_t						status;
74		usb_configuration_descriptor	*descriptor;
75		uint32							config_index;
76	} config;
77
78	struct {
79		status_t						status;
80		usb_configuration_descriptor	*descriptor;
81		uint32							config_index;
82		size_t                          length;
83	} config_etc;
84
85	struct {
86		status_t						status;
87		uint32							alternate_info;
88		uint32							config_index;
89		uint32							interface_index;
90	} alternate;
91
92	struct {
93		status_t						status;
94		usb_interface_descriptor		*descriptor;
95		uint32							config_index;
96		uint32							interface_index;
97	} interface;
98
99	struct {
100		status_t						status;
101		usb_interface_descriptor		*descriptor;
102		uint32							config_index;
103		uint32							interface_index;
104		uint32							alternate_index;
105	} interface_etc;
106
107	struct {
108		status_t						status;
109		usb_endpoint_descriptor			*descriptor;
110		uint32							config_index;
111		uint32							interface_index;
112		uint32							endpoint_index;
113	} endpoint;
114
115	struct {
116		status_t						status;
117		usb_endpoint_descriptor			*descriptor;
118		uint32							config_index;
119		uint32							interface_index;
120		uint32							alternate_index;
121		uint32							endpoint_index;
122	} endpoint_etc;
123
124	struct {
125		status_t						status;
126		usb_descriptor					*descriptor;
127		uint32							config_index;
128		uint32							interface_index;
129		uint32							generic_index;
130		size_t							length;
131	} generic;
132
133	struct {
134		status_t						status;
135		usb_descriptor					*descriptor;
136		uint32							config_index;
137		uint32							interface_index;
138		uint32							alternate_index;
139		uint32							generic_index;
140		size_t							length;
141	} generic_etc;
142
143	struct {
144		status_t						status;
145		usb_string_descriptor			*descriptor;
146		uint32							string_index;
147		size_t							length;
148	} string;
149
150	struct {
151		status_t						status;
152		uint8							type;
153		uint8							index;
154		uint16							language_id;
155		void							*data;
156		size_t							length;
157	} descriptor;
158
159	struct {
160		status_t						status;
161		uint8							request_type;
162		uint8							request;
163		uint16							value;
164		uint16							index;
165		uint16							length;
166		void							*data;
167	} control;
168
169	struct {
170		status_t						status;
171		uint32							interface;
172		uint32							endpoint;
173		void							*data;
174		size_t							length;
175	} transfer;
176
177	struct {
178		status_t						status;
179		uint32							interface;
180		uint32							endpoint;
181		void							*data;
182		size_t							length;
183		usb_iso_packet_descriptor		*packet_descriptors;
184		uint32							packet_count;
185	} isochronous;
186} usb_raw_command;
187
188#endif // _USB_RAW_H_
189