/*---------------------------------------------------------------------------* Project: USB Host Stack (UHS) File: uhs_ch9.h Description: USB constants and structures that are needed for public USB device APIs. These are used by the USB device model, which is defined in chapter 9 of the USB 2.0 specification. Copyright (C) 2011 Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. *---------------------------------------------------------------------------*/ #ifndef __UHS_CH9_H__ #define __UHS_CH9_H__ #ifdef __cplusplus extern "C" { #endif PACKED_STRUCT_BEGIN /* * * CONTROL REQUESTS * */ /* USB directions, used in endpoint descriptor bEndpointAddress field and in control requests bRequestType. */ #define UHS_DIR_OUT 0 /* to device */ #define UHS_DIR_IN 0x80 /* to host */ /* USB types, the second of three bRequestType fields */ #define UHS_TYPE_MASK (0x03 << 5) #define UHS_TYPE_STANDARD (0x00 << 5) #define UHS_TYPE_CLASS (0x01 << 5) #define UHS_TYPE_VENDOR (0x02 << 5) #define UHS_TYPE_RESERVED (0x03 << 5) /* USB recipients, the third of three bRequestType fields */ #define UHS_RECIP_MASK 0x1f #define UHS_RECIP_DEVICE 0x00 #define UHS_RECIP_INTERFACE 0x01 #define UHS_RECIP_ENDPOINT 0x02 #define UHS_RECIP_OTHER 0x03 #define UHS_RECIP_PORT 0x04 #define UHS_RECIP_RPIPE 0x05 /* Standard requests, for the bRequest field of a SETUP packet. */ #define UHS_REQ_GET_STATUS 0x00 #define UHS_REQ_CLEAR_FEATURE 0x01 #define UHS_REQ_SET_FEATURE 0x03 #define UHS_REQ_SET_ADDRESS 0x05 #define UHS_REQ_GET_DESCRIPTOR 0x06 #define UHS_REQ_SET_DESCRIPTOR 0x07 #define UHS_REQ_GET_CONFIGURATION 0x08 #define UHS_REQ_SET_CONFIGURATION 0x09 #define UHS_REQ_GET_INTERFACE 0x0A #define UHS_REQ_SET_INTERFACE 0x0B #define UHS_REQ_SYNCH_FRAME 0x0C #define UHS_REQ_SET_ENCRYPTION 0x0D #define UHS_REQ_GET_ENCRYPTION 0x0E #define UHS_REQ_RPIPE_ABORT 0x0E #define UHS_REQ_SET_HANDSHAKE 0x0F #define UHS_REQ_RPIPE_RESET 0x0F #define UHS_REQ_GET_HANDSHAKE 0x10 #define UHS_REQ_SET_CONNECTION 0x11 #define UHS_REQ_SET_SECURITY_DATA 0x12 #define UHS_REQ_GET_SECURITY_DATA 0x13 #define UHS_REQ_SET_WUHS_DATA 0x14 #define UHS_REQ_LOOPBACK_DATA_WRITE 0x15 #define UHS_REQ_LOOPBACK_DATA_READ 0x16 #define UHS_REQ_SET_INTERFACE_DS 0x17 /** * * FEATURE SELECTORS * */ #define UHS_DEVICE_SELF_POWERED 0 /* (read only) */ #define UHS_DEVICE_REMOTE_WAKEUP 1 /* dev may initiate wakeup */ #define UHS_DEVICE_TEST_MODE 2 /* (wired high speed only) */ #define UHS_DEVICE_BATTERY 2 /* (wireless) */ #define UHS_DEVICE_B_HNP_ENABLE 3 /* (otg) dev may initiate HNP */ #define UHS_DEVICE_WUHS_DEVICE 3 /* (wireless)*/ #define UHS_DEVICE_A_HNP_SUPPORT 4 /* (otg) RH port supports HNP */ #define UHS_DEVICE_A_ALT_HNP_SUPPORT 5 /* (otg) other RH port does */ #define UHS_DEVICE_DEBUG_MODE 6 /* (special devices only) */ #define UHS_DEVICE_U1_ENABLE 48 /* dev may initiate U1 transition */ #define UHS_DEVICE_U2_ENABLE 49 /* dev may initiate U2 transition */ #define UHS_DEVICE_LTM_ENABLE 50 /* dev may send LTM */ #define UHS_INTRF_FUNC_SUSPEND 0 /* function suspend */ #define UHS_INTR_FUNC_SUSPEND_OPT_MASK 0xFF00 #define UHS_ENDPOINT_HALT 0 /* IN/OUT will STALL */ /* SETUP data for a USB device control request */ typedef struct { u8 bRequestType; u8 bRequest; u16 wValue; u16 wIndex; u16 wLength; } PACKED_STRUCT_ATTRIBUTE UhsCtrlRequest; /* * * STANDARD DESCRIPTORS * Note that all multi-byte values are encoded in little endian byte order, * as they appear on the bus. * */ /* Descriptor types, USB 2.0 spec table 9.5 */ #define UHS_DT_DEVICE 0x01 #define UHS_DT_CONFIG 0x02 #define UHS_DT_STRING 0x03 #define UHS_DT_INTERFACE 0x04 #define UHS_DT_ENDPOINT 0x05 #define UHS_DT_DEVICE_QUALIFIER 0x06 #define UHS_DT_OTHER_SPEED_CONFIG 0x07 #define UHS_DT_INTERFACE_POWER 0x08 /* these are from a minor USB 2.0 revision (ECN) */ #define UHS_DT_OTG 0x09 #define UHS_DT_DEBUG 0x0a #define UHS_DT_INTERFACE_ASSOCIATION 0x0b /* these are from the Wireless USB spec */ #define UHS_DT_SECURITY 0x0c #define UHS_DT_KEY 0x0d #define UHS_DT_ENCRYPTION_TYPE 0x0e #define UHS_DT_BOS 0x0f #define UHS_DT_DEVICE_CAPABILITY 0x10 #define UHS_DT_WIRELESS_ENDPOINT_COMP 0x11 #define UHS_DT_WIRE_ADAPTER 0x21 #define UHS_DT_RPIPE 0x22 #define UHS_DT_CS_RADIO_CONTROL 0x23 /* Conventional codes for class-specific descriptors. The convention is * defined in the UHS "Common Class" Spec (3.11). Individual class specs * are authoritative for their usage, not the "common class" writeup. */ #define UHS_DT_CS_DEVICE (UHS_TYPE_CLASS | UHS_DT_DEVICE) #define UHS_DT_CS_CONFIG (UHS_TYPE_CLASS | UHS_DT_CONFIG) #define UHS_DT_CS_STRING (UHS_TYPE_CLASS | UHS_DT_STRING) #define UHS_DT_CS_INTERFACE (UHS_TYPE_CLASS | UHS_DT_INTERFACE) #define UHS_DT_CS_ENDPOINT (UHS_TYPE_CLASS | UHS_DT_ENDPOINT) /* All standard descriptors have these 2 fields at the beginning */ typedef struct { u8 bLength; u8 bDescriptorType; } PACKED_STRUCT_ATTRIBUTE UhsDescriptorHeader; #define UHS_DT_HEADER_SIZE 2 /* Device descriptor, UHS_DT_DEVICE */ typedef struct { u8 bLength; u8 bDescriptorType; u16 bcdUSB; u8 bDeviceClass; u8 bDeviceSubClass; u8 bDeviceProtocol; u8 bMaxPacketSize0; u16 idVendor; u16 idProduct; u16 bcdDevice; u8 iManufacturer; u8 iProduct; u8 iSerialNumber; u8 bNumConfigurations; } PACKED_STRUCT_ATTRIBUTE UhsDeviceDescriptor; #define UHS_DT_DEVICE_SIZE 18 /* Device and/or Interface Class codes in bDeviceClass or bInterfaceClass */ #define UHS_CLASS_PER_INTERFACE 0 /* for DeviceClass */ #define UHS_CLASS_AUDIO 1 #define UHS_CLASS_COMM 2 #define UHS_CLASS_HID 3 #define UHS_CLASS_PHYSICAL 5 #define UHS_CLASS_STILL_IMAGE 6 #define UHS_CLASS_PRINTER 7 #define UHS_CLASS_MASS_STORAGE 8 #define UHS_CLASS_HUB 9 #define UHS_CLASS_CDC_DATA 0x0a #define UHS_CLASS_CSCID 0x0b /* chip+ smart card */ #define UHS_CLASS_CONTENT_SEC 0x0d /* content security */ #define UHS_CLASS_VIDEO 0x0e #define UHS_CLASS_WIRELESS_CONTROLLER 0xe0 #define UHS_CLASS_MISC 0xef #define UHS_CLASS_APP_SPEC 0xfe #define UHS_CLASS_VENDOR_SPEC 0xff #define UHS_SUBCLASS_VENDOR_SPEC 0xff /* Configuration descriptor, UHS_DT_CONFIG */ typedef struct { u8 bLength; u8 bDescriptorType; u16 wTotalLength; u8 bNumInterfaces; u8 bConfigurationValue; u8 iConfiguration; u8 bmAttributes; u8 bMaxPower; } PACKED_STRUCT_ATTRIBUTE UhsConfigDescriptor; #define UHS_DT_CONFIG_SIZE 9 /* from config descriptor bmAttributes */ #define UHS_CONFIG_ATT_ONE (1 << 7) /* must be set */ #define UHS_CONFIG_ATT_SELFPOWER (1 << 6) /* self powered */ #define UHS_CONFIG_ATT_WAKEUP (1 << 5) /* can wakeup */ #define UHS_CONFIG_ATT_BATTERY (1 << 4) /* battery powered */ /* String descriptor, UHS_DT_STRING */ typedef struct { u8 bLength; u8 bDescriptorType; u16 wData[1]; /* UTF-16LE encoded */ } PACKED_STRUCT_ATTRIBUTE UhsStringDescriptor; /* Interface descriptor, UHS_DT_INTERFACE */ typedef struct { u8 bLength; u8 bDescriptorType; u8 bInterfaceNumber; u8 bAlternateSetting; u8 bNumEndpoints; u8 bInterfaceClass; u8 bInterfaceSubClass; u8 bInterfaceProtocol; u8 iInterface; } PACKED_STRUCT_ATTRIBUTE UhsInterfaceDescriptor; #define UHS_DT_INTERFACE_SIZE 9 /* Endpoint descriptor, UHS_DT_ENDPOINT */ typedef struct { u8 bLength; u8 bDescriptorType; u8 bEndpointAddress; u8 bmAttributes; u16 wMaxPacketSize; u8 bInterval; /* NOTE: these two are _only_ in audio endpoints. use UHS_DT_ENDPOINT_AUDIO_SIZE in bLength, not sizeof. */ u8 bRefresh; u8 bSynchAddress; } PACKED_STRUCT_ATTRIBUTE UhsEndpointDescriptor; #define UHS_DT_ENDPOINT_SIZE 7 #define UHS_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */ /* Endpoints */ #define UHS_ENDPOINT_NUMBER_MAX 15 /* bEndpointAddress */ #define UHS_ENDPOINT_NUMBER_SHIFT 0 #define UHS_ENDPOINT_NUMBER_MASK (0x0f<