이것저것/My_Work

USB Descriptors

우담바라 2008. 10. 28. 20:42

USB Descriptors

 

모든 USB device들은 device종류, 제조사, 지원하는 USB version, configure될 수 있는 방법이 몇 개인지, Endpoint개수 와 이들에 대한type은 무엇인지…… 등등에 대한 정보를 USB host에 알려주는 descriptor들을 가지고 있다.

 

USB device descriptor는 아래 와 같은 공통구성을 가진다.  

USB deviceDevice Descriptor하나만 가질 수 있다.

Device descriptor device가 어떤 USB revision을 따르는지에 대한 정보, 적절한 device driverload하기 위해 사용되는 Product ID Vendor ID 그리고 device가 가질 수 있는 configuration의 개수에 대한 정보를 포함하고 있다.

Configuration의 개수는 몇 개의 configuration descriptor 들이 다음에 파생되는지를 알려준다. 

Configuration descriptor device self전원 또는 bus전원을 사용한다면, 각각의 configuration이 사용하는 소비전력(mA)device가지고 있는 interface개수를 명시하고 있다. Device enumerate될 때 host device descriptor를 읽어서 어느 configuration enable될지를 결정한다.

한번에 하나의 configuration enable될 수 있다.

예들 들면, device high power bus전원 configuration self 전원configuration을 가질 수 있다. Devicebus의 전원을 사용하여 host에 연결되면, device driver high power 버스전원 configuration을 선택해서 device가 외부의 전원 연결 없이도 전원공급상태가 가능하도록 한다. 반면에 devicelaptop 또는 개인용 단말기에 연결되면, 사용자가 device에 전원에 연결할 것을 요구하는 두 번째 configuration(self powered) enable한다.

 

Configuration setting은 전원 차이에 한정되지 않는다. configuration은 같은 방법으로 전원을 사용하고 같이 전류를 흘릴 수 있다. 게다가 서로 다른 interface endpoint조합을 가질 수 있다. 하지만 configuration의 변경은 모든 endpoint의 동작을 정지해야 한다.

USB가 이러한 유연성을 제공하지만 극히 드문 device들만이 1개 이상의 configuration을 가지고 있다.

 

 

Interface descriptor device의 한 기능을 수행하는 function그룹으로서 header 또는 endpoint들의 집합체로 간주될 수 있다. 예를 들면, 복합기능이 제공되는 Fax, Scanner, Printer등이 있다. 첫 번째 interface descriptor Fax기능의 endpoint들을 descript하고, 두 번째 interface descriptor scanner기능, 세 번째 interface descriptor printer기능을 descript할 수 있다. Configuration descriptor와 다르게 한번에 하나의 interface enable되는 제한이 없다. Device는 한번에 enable interface descriptor를 하나 또는 여러 개를 가질 수 있다.

 

Interface descriptor interface number와 작동 중 interface setting을 변경 가능하게 하는 AlternateSetting을 명시한 bInterfaceNumber필드를 가지고 있다.

예를 들어, interface 1 interface 2, interface를 가진 device를 들 수 있다.

Interface 1bInterfaceNumber‘0’으로 설정되어 이 interface가 첫 번째 interface descriptor임을 가리키고, ‘0’으로 설정된bAlternativeSetting을 가지고 있다.

Interface 2bInterfaceNumber‘1’로 설정되어 이 interface가 두 번째 interface descriptor임을 가리키고 ‘0’으로(default) 설정된bAlternativeSetting을 가질 수 있다

bInterfaceNumber‘1’로 설정되어 두 번째 interface descriptor임을 가리키는 다른 descriptor를 전달할 수 있다. 그러나 이 때 bAlternativeSetting‘1’로 설정되어 다른 interface descriptor 2interface descriptoralternative설정이 가능함을 가리킨다.

 

Configuration enable될 때, bAlternativeSettings ‘0’인 첫 번째 두 interface descriptor가 사용된다. 하지만 host가 동작 중에 다른 interface descriptor enable하기 위해 interface descriptor 1 alternative설정과 함께SetInterface요구를 직접 보낼 수 있다.

 



 

이러한 동작은 두 개 이상의 configuration을 가지게 하는 장점을 제공하며, interface 0에 영향을 끼치지 않고 interface 0에 구성된 endpoint setting들을 변경하는 동안 interface 0을 통해서 data를 전송 할 수 있다. 

 

각각의 endpoint descriptor는 전송형태, 방향, polling interval 그리고 각 endpoint에 대한 최대 packet size를 명시하기 위해서 사용된다.
Default control endpoint
endpoint 0은 항상 control endpoint로 사용되고 descriptor를 가지고 있지 않다.

 

USB Descriptors의 구성

 

모든 descriptor들은 공통된 구조로 만들어진다. 첫 번째 byte descriptor의 길이를 명시하고, 두 번째 byte descriptor type을 가리킨다. 만약 descriptor의 길이가 specification의 정의보다 작으면 host descriptor를 무시하게 된다.
그러나 descriptor size가 예상 보다 크면 host는 여분의 byte들을 무시하고, 마지막에 리턴 된 실제 length에서 다음 descriptor를 찾기 시작한다.     

 

Offset

Field

Size

Value

Description

0

bLength

1

Number

Size of Descriptor in Bytes

1

bDescriptionType

1

Constant

DescriptorType

2

...

n

Start of parameters for descriptor

 

 

 

 

 

 

 

 

 

 

Device Descriptors

 

USB device device descriptor device에 대한 전체를 묘사한다.  

USB device는 한 개의 device descriptor만을 가질 수 있다.  지원하는 USB version, 최대 packet size, Vendor Product ID 그리고 device가 가질 수 있는 configuration의 수와 같은 중요 정보들을 명시하고 있다.

다음은 device descriptor의 구조를 보여 주고 있다.

 

Offset

Field

Size

Value

Description

0

bLength

1

Number

Size of the Descriptor in Bytes (18 bytes)

1

bDescriptorType

1

Constant

Device Descriptor (0x01)

2

bcdUSB

2

BCD

USB Specification Number which device complies too.

4

bDeviceClass

1

Class

Class Code (Assigned by USB Org)
If equal to Zero, each interface specifies it
own class code
If equal to 0xFF, the class code is vendor specified.
Otherwise field is valid Class Code.

5

bDeviceSubClass

1

SubClass

Subclass Code (Assigned by USB Org)

6

bDeviceProtocol

1

Protocol

Protocol Code (Assigned by USB Org)

7

bMaxPacketSize

1

Number

Maximum Packet Size for Zero Endpoint. Valid Sizes are 8, 16, 32, 64

8

idVendor

2

ID

Vendor ID (Assigned by USB Org)

10

idProduct

2

ID

Product ID (Assigned by Manufacturer)

12

bcdDevice

2

BCD

Device Release Number

14

iManufacturer

1

Index

Index of Manufacturer String Descriptor

15

iProduct

1

Index

Index of Product String Descriptor

16

iSerialNumber

1

Index

Index of Serial Number String Descriptor

17

bNumConfigurations

1

Integer

Number of Possible Configurations

  • bcdUSB필드는 device가 지원하는 USB version을 알려준다.  
    이 값은 major version number를 의미하는 “JJ”, minor version number를 의미하는 ‘M’ 그리고 sub minor version number를 의미하는 ‘N’으로 된 “0xJJMM”의 구조를 가진 2진화된 10진 코드이다
    .
    예를 들면, USB 2.0 0x2000, USB 1.1 0x0110 그리고 USB 1.0 0x0100으로 된다.
  • bDeviceClass, bDeviceSubClass 그리고 bDeviceProtocol들은 OS system에서 class driver를 찾기 위해서 사용된다. 일반적으로 bDeviceClass device level에서 설정된다. 대부분의 class specification들은 내부적으로 device자신을 확인하는 것을 선택하며, 결과적으로 bDeviceClass 0x00으로 설정된다.
    이는 하나의 device가 여러 개의 class를 지원하도록 한다. 
  • bMaxPacketSize 필드는 endpoint 0의 최대 packet size를 알려준다. 모든 device endpoint zero를 지원해야 한다.
  • idVendor idProduct device에 대한 driver를 찾기 위해서 OS system에서 사용된다.
    Vendor ID
    USB-IF에 의해서 정해진다.  
  • BcdDevicebcdUSB와 같은 구조를 가지고 있으며 device version number 를 알려주기 위해서 사용된다.
    이 값은 개발자에 의해서 정해진다.
  • Manufacturer, Product 그리고 Serial number등에 대한 자세한 정보를 제공하는 3개의 string descriptor가 있다.  
    String descriptor
    들을 가져야 한다는 요구사항은 없지만, string descriptor가 제공되지 않으면 ‘0’ index가 정의되어야 한다. 
  • bNumConfiguration은 현재 device speed에서 device가 지원하는 Configuration의 개수가 정의된다.

Configuration Descriptors

 

대다수의 USB deviceconfiguration하나만 가지고 있음에도 불구하고, USB device는 여러 개의 각기 다른 configuration들을 가질 수 있다.

Configuration descriptor device의 전원이 어떻게 되는지, 최대 전력소비는 무엇인지, 가지고 있는 interface는 몇 개인지에 대한 정보를 명시하고 있다.

그러므로 device는 두 개의 configuration을 가질 수 있다. 하나는 device USB bus의 전원을 사용할 때 그리고 다른 하나는 외부의 주 전원을 사용할 때 사용된다.

Interface descriptor들에 대한 header처럼, 다른 configuration에 대한 다른 전송 mode를 사용하는 것으로 한 개의 configuration을 가지게 하는 것이 가능하다.  

 

한번에 모든 configuration들은 host에 의해서 확인되고, host configuration descriptor들 중 하나의 configurationbConfigurarionValue값과 일치되는 ‘0’이 아닌 값으로 SetConfiguration 명령을 보낸다. 
이 명령은 원하는 configuration을 선택하는데 사용된다.

 

Offset

Field

Size

Value

Description

0

bLength

1

Number

Size of Descriptor in Bytes

1

bDescriptorType

1

Constant

Configuration Descriptor (0x02)

2

wTotalLength

2

Number

Total length in bytes of data returned

4

bNumInterfaces

1

Number

Number of Interfaces

5

bConfigurationValue

1

Number

Value to use as an argument to select this configuration

6

iConfiguration

1

Index

Index of String Descriptor describing this configuration

7

bmAttributes

1

Bitmap

D7 Reserved, set to 1. (USB 1.0 Bus Powered)
D6 Self Powered
D5 Remote Wakeup
D4..0 Reserved, set to 0.

8

bMaxPower

1

mA

Maximum Power Consumption in 2mA units

 

·         Configuration descriptor가 읽혀질 때, device interface endpoint descriptor에 관련 모든 것이 포함된 전체configuration체계를 회신한다. 
wTotalLength
필드는 configuration 체계의 byte수를 의미한다
.



  • bNumInterfacesconfiguration에 대한 interface의 수를 명시한다.
  • bConfigurationValue configuration을 선택하기 위해서 SetConfiguration 요구에서 사용된다.
  • iConfiguration은 사용자가 읽을 수 있는 폼으로 configuration을 설명한 string descriptorindex이다. 
  • bmAttributesconfiguration에 대한 전원 정보를 명시한다.
    device
    self전원상태이면, D6 bit set된다. D7 bit USB 1.0에서 device bus의 전원을 사용한다는 것을 알기 위해 사용된다. 하지만 이 bit는 현재 bMaxPower에서 처리된다
    . 
    device
    bus에서 전원을 사용하면, device bus powered device 또는 self powered device인지, 소비전력에 대한 정보를 bMaxPower로 알려줘야 한다. Device는 또한 host suspend일 때 device host wake up할 수 있도록 원격 remote wakeup을 지원 할 수 있다.  
  • bMaxPower device bus로 부터 흘릴 최대전류에 대한 정보를 정의한다.
    이 값은 2mA단위이며, 대략 최대 500mA까지 명시될 수 있다
    .
    USB specification
    Vbus로부터 500mA이상 전류를 흘릴 수 없다고 정의한다
    .
    device
    가 외부 전원공급을 잃어버리면, devicebMaxPower에 명시된 것 이상의 전류를 흘릴 수 없으며 외부의 전원공급 없으면 동작오류를 일으킬 수 있다.

Interface Descriptors

Interface descriptor device header또는 device의 한 기능을 수행하는 functional group으로 endpoint의 집합체로 묘사될 수 있다.
Interface descriptor
는 아래와 같은 구조를 따른다. 

Offset

Field

Size

Value

Description

0

bLength

1

Number

Size of Descriptor in Bytes (9 Bytes)

1

bDescriptorType

1

Constant

Interface Descriptor (0x04)

2

bInterfaceNumber

1

Number

Number of Interface

3

bAlternateSetting

1

Number

Value used to select alternative setting

4

bNumEndpoints

1

Number

Number of Endpoints used for this interface

5

bInterfaceClass

1

Class

Class Code (Assigned by USB Org)

6

bInterfaceSubClass

1

SubClass

Subclass Code (Assigned by USB Org)

7

bInterfaceProtocol

1

Protocol

Protocol Code (Assigned by USB Org)

8

iInterface

1

Index

Index of String Descriptor Describing this interface

 

·         bInterfaceNumber interface descriptor index를 가리킨다.
이 값은 zero기반이어야 하고, 새로운 interface descriptor에 대해서 한번씩 증가 되야 한다.

·         bAlternativeSetting alternative interfaces을 명시하기 위해 사용된다.
Alternative Interface
들은
Set Interface 요구에 의해서 선택될 수 있다.

·         bNumEndpoints interface에서 사용되는 endpoint의 개수를 가리킨다.
이 값은 endpoint 0을 제외해야 하고, 다음에 명시될 endpoint descriptor들에 대한 개수를 가리키기 위해서 사용된다.

·         bInterfaceClass, bInterfaceSubClass bInterfaceProtocoldevice가 지원하는 Class를 명시하기 위해서 사용된다. ( : HID, Mass Storage 등등)
Class
의 지원은 많은USB device class driver를 사용하도록 하여 불 필요한 driver의 개발을 막는다.

·         iInterface interface string descriptor의 개수를 명시한다.    

 

Endpoint Descriptors

 

Endpoint descriptor들은 endpoint zero를 제외한 endpoint들을 설명하는데 사용된다.

Endpoint 0은 항상 control endpoint로 다루어 지며, 어느 descriptor들이라도 요구되기 전에 설정된다.

Hostbus bandwidth요구사항을 결정하기 위해서 endpoint descriptor에서 회신된 정보를 사용한다.

 

Offset

Field

Size

Value

Description

0

bLength

1

Number

Size of Descriptor in Bytes (7 bytes)

1

bDescriptorType

1

Constant

Endpoint Descriptor (0x05)

2

bEndpointAddress

1

Endpoint

Endpoint Address
Bits 0..3b Endpoint Number.
Bits 4..6b Reserved. Set to Zero
Bits 7 Direction 0 = Out, 1 = In (Ignored for Control Endpoints)

3

bmAttributes

1

Bitmap

Bits 0..1 Transfer Type

00 = Control
01 = Isochronous
10 = Bulk
11 = Interrupt

Bits 2..7 are reserved. If Isochronous endpoint,
Bits 3..2 = Synchronisation Type (Iso Mode)

00 = No Synchonisation
01 = Asynchronous
10 = Adaptive
11 = Synchronous

Bits 5..4 = Usage Type (Iso Mode)

00 = Data Endpoint
01 = Feedback Endpoint
10 = Explicit Feedback Data Endpoint
11 = Reserved

4

wMaxPacketSize

2

Number

Maximum Packet Size this endpoint is capable of sending or receiving

6

bInterval

1

Number

Interval for polling endpoint data transfers. Value in frame counts. Ignored for Bulk & Control Endpoints. Isochronous must equal 1 and field may range from 1 to 255 for interrupt endpoints.

  • bEndpointAddress는 이 descriptor가 어떤 endpoint를 설명하는지를 가리킨다.
  • bmArrributes Control, Interrupt, Isochronous or Bulk Transfers과 같은 전송 type을 명시한다.
    만약Isochronous endpoint가 명시 된다면, Synchronisation usage type과 같은 추가적인 속성이 선택될 수 있다. 
  • wMaxPacketSize endpoint의 최대 payload size를 가리킨다.
  • bInterval은 확실한 전송의 polling interval을 명시한다.
    frame
    단위로 표현되므로 low/full speed device에서는 1ms 이거나 high speed device에서는 125us가 된다.

String Descriptors

 

String descriptor는 부가적인 option으로 사용자가(사람이) 읽을 수 있는 정보를 제공한다.
String descriptor
가 사용되지 않으면, descriptor string index필드는 0으로 set되어 유효한 string descriptor가 없다는 것을 가리켜야 한다. 

StringUnicode 포멧으로 encode되고 제품은 다국어를 지원 하도록 만들 수 있다. String index 0은 지원하는 언어에 대한 list를 회신해야 한다.
USB
언어 ID들의 list
Universal Serial Bus Language Identifiers (LANGIDs) version 1.0 에서 찾을 수 있다.

 

Offset

Field

Size

Value

Description

0

bLength

1

Number

Size of Descriptor in Bytes

1

bDescriptorType

1

Constant

String Descriptor (0x03)

2

wLANGID[0]

2

number

Supported Language Code Zero
(e.g. 0x0409 English - United States)

4

wLANGID[1]

2

number

Supported Language Code One
(e.g. 0x0c09 English - Australian)

n

wLANGID[x]

2

number

Supported Language Code x
(e.g. 0x0407 German - Standard)

위의 String Descriptor String Descriptor 0번의 구조를 보여준다.
Host
는 이 descriptor를 읽어서 어떠한 언어가 사용가능한지 결정해야 한다. 만약 언어가 지원된다면,
Get Descriptor(String)요구의 wIndex필드에 언어 ID를 보내는 것으로 참조 될 수 있다.  

이후의 모든 string들은 아래와 같은 구조를 따른다.

 

Offset

Field

Size

Value

Description

0

bLength

1

Number

Size of Descriptor in Bytes

1

bDescriptorType

1

Constant

String Descriptor (0x03)

2

bString

n

Unicode

Unicode Encoded String

 

'이것저것 > My_Work' 카테고리의 다른 글

EDID ( Extended display identification data )  (0) 2008.11.14
USB Enumeration  (0) 2008.10.28
전력관리  (0) 2008.10.08
MFC - 콤보박스  (2) 2008.10.08
[MFC] Tab 컨트롤에 모달리스창 넣기  (1) 2008.09.30