147000651SAxel Dörfler/*
247000651SAxel Dörfler * Copyright 2009, Haiku Inc. All Rights Reserved.
347000651SAxel Dörfler * Distributed under the terms of the MIT License.
447000651SAxel Dörfler */
51501c2bfSNiels Sascha Reedijk#ifndef _USB_SPEC_H
61501c2bfSNiels Sascha Reedijk#define _USB_SPEC_H
71501c2bfSNiels Sascha Reedijk
847000651SAxel Dörfler
947000651SAxel Dörfler#include <SupportDefs.h>
1047000651SAxel Dörfler
1147000651SAxel Dörfler
1247000651SAxel Dörfler/* Request types (target/direction) for send_request() */
1347000651SAxel Dörfler#define USB_REQTYPE_DEVICE_IN				0x80
1447000651SAxel Dörfler#define USB_REQTYPE_DEVICE_OUT				0x00
1547000651SAxel Dörfler#define USB_REQTYPE_INTERFACE_IN			0x81
1647000651SAxel Dörfler#define USB_REQTYPE_INTERFACE_OUT			0x01
1747000651SAxel Dörfler#define USB_REQTYPE_ENDPOINT_IN				0x82
1847000651SAxel Dörfler#define USB_REQTYPE_ENDPOINT_OUT			0x02
1947000651SAxel Dörfler#define USB_REQTYPE_OTHER_IN				0x83
2019c52a6cSJérôme Duval#define USB_REQTYPE_OTHER_OUT				0x03
2147000651SAxel Dörfler
2247000651SAxel Dörfler/* Request types for send_request() */
2347000651SAxel Dörfler#define USB_REQTYPE_STANDARD				0x00
2447000651SAxel Dörfler#define USB_REQTYPE_CLASS					0x20
2547000651SAxel Dörfler#define USB_REQTYPE_VENDOR					0x40
2647000651SAxel Dörfler#define USB_REQTYPE_RESERVED				0x60
2747000651SAxel Dörfler#define USB_REQTYPE_MASK					0x9f
2847000651SAxel Dörfler
2947000651SAxel Dörfler/* Standard request values for send_request() */
3047000651SAxel Dörfler#define USB_REQUEST_GET_STATUS				0
3147000651SAxel Dörfler#define USB_REQUEST_CLEAR_FEATURE			1
3247000651SAxel Dörfler#define USB_REQUEST_SET_FEATURE				3
3347000651SAxel Dörfler#define USB_REQUEST_SET_ADDRESS				5
3447000651SAxel Dörfler#define USB_REQUEST_GET_DESCRIPTOR			6
3547000651SAxel Dörfler#define USB_REQUEST_SET_DESCRIPTOR			7
3647000651SAxel Dörfler#define USB_REQUEST_GET_CONFIGURATION		8
3747000651SAxel Dörfler#define USB_REQUEST_SET_CONFIGURATION		9
3847000651SAxel Dörfler#define USB_REQUEST_GET_INTERFACE			10
3947000651SAxel Dörfler#define USB_REQUEST_SET_INTERFACE			11
4047000651SAxel Dörfler#define USB_REQUEST_SYNCH_FRAME				12
4147000651SAxel Dörfler
4247000651SAxel Dörfler/* Used by {set|get}_descriptor() */
43d136bfb1SPhilippe Houdoin#define USB_DESCRIPTOR_DEVICE				0x01
44d136bfb1SPhilippe Houdoin#define USB_DESCRIPTOR_CONFIGURATION		0x02
45d136bfb1SPhilippe Houdoin#define USB_DESCRIPTOR_STRING				0x03
46d136bfb1SPhilippe Houdoin#define USB_DESCRIPTOR_INTERFACE			0x04
47d136bfb1SPhilippe Houdoin#define USB_DESCRIPTOR_ENDPOINT				0x05
48d136bfb1SPhilippe Houdoin/* conventional class-specific descriptors */
49d136bfb1SPhilippe Houdoin#define USB_DESCRIPTOR_CS_DEVICE			0x21
50d136bfb1SPhilippe Houdoin#define USB_DESCRIPTOR_CS_CONFIGURATION		0x22
51d136bfb1SPhilippe Houdoin#define USB_DESCRIPTOR_CS_STRING			0x23
52d136bfb1SPhilippe Houdoin#define USB_DESCRIPTOR_CS_INTERFACE			0x24
53d136bfb1SPhilippe Houdoin#define USB_DESCRIPTOR_CS_ENDPOINT			0x25
5447000651SAxel Dörfler
5547000651SAxel Dörfler/* Used by {set|clear}_feature() */
561501c2bfSNiels Sascha Reedijk#define USB_FEATURE_DEVICE_REMOTE_WAKEUP	1
571501c2bfSNiels Sascha Reedijk#define USB_FEATURE_ENDPOINT_HALT			0
581501c2bfSNiels Sascha Reedijk
5947000651SAxel Dörfler#define USB_ENDPOINT_ATTR_CONTROL			0x00
6047000651SAxel Dörfler#define USB_ENDPOINT_ATTR_ISOCHRONOUS		0x01
6147000651SAxel Dörfler#define USB_ENDPOINT_ATTR_BULK				0x02
6247000651SAxel Dörfler#define USB_ENDPOINT_ATTR_INTERRUPT			0x03
6347000651SAxel Dörfler#define USB_ENDPOINT_ATTR_MASK				0x03
6447000651SAxel Dörfler
65cf58476cSSiarzhuk Zharski/* Synchronization - isochrnous endpoints only */
66cf58476cSSiarzhuk Zharski#define USB_ENDPOINT_ATTR_NO_SYNCHRONIZE	0x00
67cf58476cSSiarzhuk Zharski#define USB_ENDPOINT_ATTR_ASYNCRONOUS		0x04
68cf58476cSSiarzhuk Zharski#define USB_ENDPOINT_ATTR_ADAPTIVE_SYNCHRO	0x08
69cf58476cSSiarzhuk Zharski#define USB_ENDPOINT_ATTR_SYNCHRONOUS		0x0C
70cf58476cSSiarzhuk Zharski#define USB_ENDPOINT_ATTR_SYNCHRONIZE_MASK	0x0C
71cf58476cSSiarzhuk Zharski
72cf58476cSSiarzhuk Zharski/* Usage Type - isochrnous endpoints only */
73cf58476cSSiarzhuk Zharski#define USB_ENDPOINT_ATTR_DATA_USAGE		0x00
74cf58476cSSiarzhuk Zharski#define USB_ENDPOINT_ATTR_FEEDBACK_USAGE	0x10
75cf58476cSSiarzhuk Zharski#define USB_ENDPOINT_ATTR_IMPLICIT_USAGE	0x20
76cf58476cSSiarzhuk Zharski#define USB_ENDPOINT_ATTR_USAGE_MASK		0x30
77cf58476cSSiarzhuk Zharski
7812d046d0SAdrien Destugues/* Direction */
7947000651SAxel Dörfler#define USB_ENDPOINT_ADDR_DIR_IN			0x80
8047000651SAxel Dörfler#define USB_ENDPOINT_ADDR_DIR_OUT			0x00
8112d046d0SAdrien Destugues#define USB_ENDPOINT_ADDR_DIR_MASK			0x80
8247000651SAxel Dörfler
8347000651SAxel Dörfler
8447000651SAxel Dörflertypedef struct usb_device_descriptor {
8547000651SAxel Dörfler	uint8	length;
8647000651SAxel Dörfler	uint8	descriptor_type;
8747000651SAxel Dörfler	uint16	usb_version;
8847000651SAxel Dörfler	uint8	device_class;
8947000651SAxel Dörfler	uint8	device_subclass;
9047000651SAxel Dörfler	uint8	device_protocol;
9147000651SAxel Dörfler	uint8	max_packet_size_0;
9247000651SAxel Dörfler	uint16	vendor_id;
9347000651SAxel Dörfler	uint16	product_id;
9447000651SAxel Dörfler	uint16	device_version;
9547000651SAxel Dörfler	uint8	manufacturer;
9647000651SAxel Dörfler	uint8	product;
9747000651SAxel Dörfler	uint8	serial_number;
9847000651SAxel Dörfler	uint8	num_configurations;
991501c2bfSNiels Sascha Reedijk} _PACKED usb_device_descriptor;
1001501c2bfSNiels Sascha Reedijk
10147000651SAxel Dörflertypedef struct usb_configuration_descriptor {
10247000651SAxel Dörfler	uint8	length;
10347000651SAxel Dörfler	uint8	descriptor_type;
10447000651SAxel Dörfler	uint16	total_length;
10547000651SAxel Dörfler	uint8	number_interfaces;
10647000651SAxel Dörfler	uint8	configuration_value;
10747000651SAxel Dörfler	uint8	configuration;
10847000651SAxel Dörfler	uint8	attributes;
10947000651SAxel Dörfler	uint8	max_power;
1101501c2bfSNiels Sascha Reedijk} _PACKED usb_configuration_descriptor;
1111501c2bfSNiels Sascha Reedijk
11247000651SAxel Dörflertypedef struct usb_interface_descriptor {
11347000651SAxel Dörfler	uint8	length;
11447000651SAxel Dörfler	uint8	descriptor_type;
11547000651SAxel Dörfler	uint8	interface_number;
11647000651SAxel Dörfler	uint8	alternate_setting;
11747000651SAxel Dörfler	uint8	num_endpoints;
11847000651SAxel Dörfler	uint8	interface_class;
11947000651SAxel Dörfler	uint8	interface_subclass;
12047000651SAxel Dörfler	uint8	interface_protocol;
12147000651SAxel Dörfler	uint8	interface;
1221501c2bfSNiels Sascha Reedijk} _PACKED usb_interface_descriptor;
1231501c2bfSNiels Sascha Reedijk
12447000651SAxel Dörflertypedef struct usb_endpoint_descriptor {
12547000651SAxel Dörfler	uint8	length;
12647000651SAxel Dörfler	uint8	descriptor_type;
12747000651SAxel Dörfler	uint8	endpoint_address;
12847000651SAxel Dörfler	uint8	attributes;
12947000651SAxel Dörfler	uint16	max_packet_size;
13047000651SAxel Dörfler	uint8	interval;
1311501c2bfSNiels Sascha Reedijk} _PACKED usb_endpoint_descriptor;
1321501c2bfSNiels Sascha Reedijk
13347000651SAxel Dörflertypedef struct usb_string_descriptor {
13447000651SAxel Dörfler	uint8	length;
13547000651SAxel Dörfler	uint8	descriptor_type;
13647000651SAxel Dörfler	uchar	string[1];
1371501c2bfSNiels Sascha Reedijk} _PACKED usb_string_descriptor;
1381501c2bfSNiels Sascha Reedijk
13947000651SAxel Dörflertypedef struct usb_generic_descriptor {
14047000651SAxel Dörfler	uint8	length;
14147000651SAxel Dörfler	uint8	descriptor_type;
14247000651SAxel Dörfler	uint8	data[1];
1431501c2bfSNiels Sascha Reedijk} _PACKED usb_generic_descriptor;
1441501c2bfSNiels Sascha Reedijk
14547000651SAxel Dörflertypedef union usb_descriptor {
14647000651SAxel Dörfler	usb_generic_descriptor			generic;
14747000651SAxel Dörfler	usb_device_descriptor			device;
14847000651SAxel Dörfler	usb_interface_descriptor		interface;
14947000651SAxel Dörfler	usb_endpoint_descriptor			endpoint;
15047000651SAxel Dörfler	usb_configuration_descriptor	configuration;
15147000651SAxel Dörfler	usb_string_descriptor			string;
1521501c2bfSNiels Sascha Reedijk} usb_descriptor;
1531501c2bfSNiels Sascha Reedijk
1541501c2bfSNiels Sascha Reedijk
15547000651SAxel Dörfler#endif	/* _USB_SPEC_H */
156