Universal Serial Bus: Difference between revisions

Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content deleted Content added
added more to standard descriptors, made some minor cosmetic changes to previous parts of the article
finished framework section
Line 1,739: Line 1,739:


==== INTERFACE ====
==== INTERFACE ====
INTERFACE descriptors are only returned following a CONFIGURATION descriptor when the host requests a specific CONFIGURATION descriptor; it is not possible to directly request a specific INTERFACE descriptor. An interface may provide alternate settings within a configuration that allow the endpoints and/or their characteristics to be varied. A default interface has the ''bAlternateSetting'' field in its INTERFACE descriptor reset to zero.
{| align="center" border="1"
!Offset
!Field
!Size
!Type
!Description
|- valign="top"
|align="center" |0
|bLength
|align="center" |1
|align="center" |Number
|Size of this descriptor in bytes
|- valign="top"
|align="center" |1
|bDescriptorType
|align="center" |1
|align="center" |Constant
|INTERFACE Descriptor Type
|- valign="top"
|align="center" |2
|bInterfaceNumber
|align="center" |1
|align="center" |Number
|Number of this interface. Zero-based value which identifies the index of this interface in the array of interfaces supported within a configuration.
|- valign="top"
|align="center" |3
|bAlternateSetting
|align="center" |1
|align="center" |Number
|Value used to select the alternate settings described by this INTERFACE descriptor for the interface with the ''bInterfaceNumber'' in the previous field. This value is zero if this descriptor describes the default settings for a particular interface.
|- valign="top"
|align="center" |4
|bNumEndpoints
|align="center" |1
|align="center" |Number
|Number of endpoints used by this interface, not including endpoint zero.
|- valign="top"
|align="center" |5
|bInterfaceClass
|align="center" |1
|align="center" |Class
|Class code (assigned by the USB-IF)
* A value of zero here is reserved for future standardization.
* If this value is FFh, the interface class is vendor-specific.
* All other values are reserved for assignment by the USB-IF.
|- valign="top"
|align="center" |6
|bInterfaceSubClass
|align="center" |1
|align="center" |SubClass
|Subclass code (assigned by the USB-IF)
* The subclass code in this field is qualified by the value of the ''bInterfaceClass'' field.
* If ''bInterfaceClass'' is reset to zero, then this field must also be reset to zero.
* If ''bInterfaceClass'' is not set to the value of FFh, then all values of this field are reserved for assignment by the USB-IF.
|- valign="top"
|align="center" |7
|bInterfaceProtocol
|align="center" |1
|align="center" |Protocol
|Protocol code (assigned by the USB-IF)
* The protocol code in this field is qualified by the values of the ''bInterfaceClass'' and ''bInterfaceSubClass'' fields.
* If an interface supports class-specific requests, then this field identifies the protocols that the device uses as defined by the specifications of the device class.
* If this field is reset to zero, then the device does not use a class-specific protocol on this interface.
* If this field is set to FFh, then the devices uses a vendor-specific protocol on this interface.
|- valign="top"
|align="center" |8
|iInterface
|align="center" |1
|align="center" |Index
|Index of STRING descriptor describing this interface
|}




==== ENDPOINT ====
==== ENDPOINT ====
Each endpoint used for a particular interface has a descriptor which follows after that particular interface's descriptor when the host requests a specific CONFIGURATION descriptor; the host cannot request a specific ENDPOINT descriptor explicitly. And ENDPOINT descriptor never describes endpoint zero.
{| align="center" border="1"
!Offset
!Field
!Size
!Type
!Description
|- valign="top"
|align="center" |0
|bLength
|align="center" |1
|align="center" |Number
|Size of this descriptor in bytes
|- valign="top"
|align="center" |1
|bDescriptorType
|align="center" |1
|align="center" |Constant
|ENDPOINT Descriptor Type
|- valign="top"
|align="center" |2
|bEndpointAddress
|align="center" |1
|align="center" |Endpoint
|The address of the endpoint on the USB device described by this descriptor. This field has the following format:
{| border="1" cellpadding="15" align="center"
|D<span style="vertical-align:sub;">7</span>
|D<span style="vertical-align:sub;">6</span>
|D<span style="vertical-align:sub;">5</span>
|D<span style="vertical-align:sub;">4</span>
|D<span style="vertical-align:sub;">3</span>
|D<span style="vertical-align:sub;">2</span>
|D<span style="vertical-align:sub;">1</span>
|D<span style="vertical-align:sub;">0</span>
|}
{| border="0" cellpadding="0" align="center" style="max-width:500px;"
|valign="top" style="min-width:80px;" |'''D<span style="vertical-align:sub;">7</span>'''
|'''Direction''' (ignored for control endpoints)
* 0 = OUT endpoint
* 1 = IN endpoint
|-
|valign="top" style="min-width:80px;" |'''D<span style="vertical-align:sub;">6...4</span>'''
|''Reserved, reset to zero''
|-
|valign="top" style="min-width:80px;" |'''D<span style="vertical-align:sub;">3...0</span>'''
|'''Endpoint Number'''
|}
|- valign="top"
|align="center" |3
|bmAttributes
|align="center" |1
|align="center" |Bitmap
|This field describes the endpoint's attributes as follows:
{| border="1" cellpadding="15" align="center"
|D<span style="vertical-align:sub;">7</span>
|D<span style="vertical-align:sub;">6</span>
|D<span style="vertical-align:sub;">5</span>
|D<span style="vertical-align:sub;">4</span>
|D<span style="vertical-align:sub;">3</span>
|D<span style="vertical-align:sub;">2</span>
|D<span style="vertical-align:sub;">1</span>
|D<span style="vertical-align:sub;">0</span>
|}
{| border="0" cellpadding="0" align="center" style="max-width:500px;"
|valign="top" style="min-width:80px;" |'''D<span style="vertical-align:sub;">7...6</span>'''
|''Reserved, reset to zero''
|-
|valign="top" style="min-width:80px;" |'''D<span style="vertical-align:sub;">5...4</span>'''
|'''Usage Type''' (Isochronous endpoints only; reserved and reset to zero for other endpoints)
* 00 = Data endpoint
* 01 = Feedback endpoint
* 10 = Implicit feedback data endpoint
* 11 = Reserved
|-
|valign="top" style="min-width:80px;" |'''D<span style="vertical-align:sub;">3...2</span>'''
|'''Synchronization Type''' (Isochronous endpoints only; reserved and reset to zero for other endpoint types)
* 00 = No synchronization
* 01 = Asynchronous
* 10 = Adaptive
* 11 = Synchronous
|-
|valign="top" style="min-width:80px;" |'''D<span style="vertical-align:sub;">1...0</span>'''
|'''Transfer Type'''
* 00 = Control
* 01 = Isochronous
* 10 = Bulk
* 11 = Interrupt
|}
|- valign="top"
|align="center" |4
|wMaxPacketSize
|align="center" |2
|align="center" |Number
|Maximum packet size that this endpoint is capable of sending or receiving.
* For isochronous endpoints, this value is used to reserve bus time; the pipe, however, may not always use all of the reserved bus time.
* Bits 10...0 specify the maximum packet size in bytes.
* For high-speed isochronous and interrupt endpoints, bits 12...11 specify the number of additional transaction opportunities per microframe (see [[#High-Speed.2C_High-Bandwidth_Endpoints|High-Speed, High-Bandwidth Endpoints]]). The format is as follows:
** 00 = None (1 transaction per microframe)
** 01 = 1 additional (2 transactions per microframe)
** 10 = 2 additional (3 transactions per microframe)
** 11 = Reserved
* Bits 15...13 are reserved and must be reset to zero.
|- valign="top"
|align="center" |6
|bInterval
|align="center" |1
|align="center" |Number
|Interval for polling a device during a data transfer, expressed in units of microframes for high-speed devices, and frames for low- and full-speed devices. The exact meaning of the value in this field depends on the endpoint type and the operating speed of the device:
* Full- and High-speed isochronous endpoints, and high-speed interrupt endpoints:
** This field must be in the range from 1 to 16.
** This field is used to calculate the period as 2<span style="vertical-align:super;">''bInterval'' - 1</span>. That is, a value of 4 calculates to 2<span style="vertical-align:super;">4 - 1</span> = 2<span style="vertical-align:super;">3</span> = 8.
* Full- and Low-speed interrupt endpoints:
** This field must be in the range from 1 to 255.
* High-speed bulk and control OUT endpoints:
** This field must be in the range from 0 to 255.
** This field specifies the maximum NAK rate of the endpoint.
** A value of zero indicates that the endpoint never NAKs
** Other values indicate at most 1 NAK each ''bInterval'' number of microframes.
** See [[#PING_Transaction_Protocol|PING Transaction Protocol]]
|}


==== STRING ====
==== STRING ====
Devices may optionally support STRING descriptors. If a device does not support STRING descriptors, any field which references the index of a STRING descriptor must be reset to zero. STRING descriptors use unicode encodings and may support multiple languages. The host requests a STRING descriptor with the [[#GET_DESCRIPTOR|GET_DECRIPTOR]] request and must pass the 16-bit LANGID (as defined by the USB-IF) of the desired language in the ''wIndex'' field. The list of currently accepted LANGIDs is located [[http://www.usb.org/developers/docs/USB_LANGIDs.pdf|here]].

String index 0 for all languages returns a STRING descriptor that contains an array of all the two-byte LANGID codes that the device supports.

Whether requesting a string or an array of LANGIDs, the data is not NULL-terminated. Instead, the host determines the length of the data by subtracting 2 from the ''bLength'' field of the descriptor.

When the host requests string index 0, the following descriptor is returned:
{| align="center" border="1"
!Offset
!Field
!Size
!Type
!Description
|- valign="top"
|align="center" |0
|bLength
|align="center" |1
|align="center" |Number
|Size of this descriptor in bytes
|- valign="top"
|align="center" |1
|bDescriptorType
|align="center" |1
|align="center" |Constant
|STRING Descriptor Type
|- valign="top"
|align="center" |2
|wLangID[0]
|align="center" |2
|align="center" |Number
|LANGID code zero
|- valign="top"
|align="center" |...
|align="center" |...
|align="center" |...
|align="center" |...
|align="center" |...
|- valign="top"
|align="center" |N
|wLangID[x]
|align="center" |2
|align="center" |Number
|LANGID code x
|}


When the host requests a valid string index other than string index 0 for a supported LANGID, the following descriptor is returned:
{| align="center" border="1"
!Offset
!Field
!Size
!Type
!Description
|- valign="top"
|align="center" |0
|bLength
|align="center" |1
|align="center" |Number
|Size of this descriptor in bytes
|- valign="top"
|align="center" |1
|bDescriptorType
|align="center" |1
|align="center" |Constant
|STRING Descriptor Type
|- valign="top"
|align="center" |2
|bString
|align="center" |N
|align="center" |Number
|Unicode string
|}


== TODO ==
== TODO ==
Currently the above article is missing the following topics:
Currently the above article is missing the following topics:
* USB Framework
** Finish standard descriptors section
* Typical organization of system software
* Typical organization of system software
* Hubs (including Split Transactions)
* Hubs (including Split Transactions)