]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.h
MdeModulePkg/UsbBusDxe: Add UsbControlTransfer() error check
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbBusDxe / UsbDesc.h
CommitLineData
e237e7ae 1/** @file\r
2\r
8616fc4c 3 Manage Usb Descriptor List\r
4\r
43629612 5Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
cd5ebaa0 6This program and the accompanying materials\r
e237e7ae 7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
e237e7ae 14**/\r
15\r
16#ifndef _USB_DESCRIPTOR_H_\r
17#define _USB_DESCRIPTOR_H_\r
18\r
43629612 19#define USB_MAX_INTERFACE_SETTING 256\r
e237e7ae 20\r
21//\r
22// The RequestType in EFI_USB_DEVICE_REQUEST is composed of\r
23// three fields: One bit direction, 2 bit type, and 5 bit\r
24// target.\r
25//\r
26#define USB_REQUEST_TYPE(Dir, Type, Target) \\r
27 ((UINT8)((((Dir) == EfiUsbDataIn ? 0x01 : 0) << 7) | (Type) | (Target)))\r
28\r
29//\r
30// A common header for usb standard descriptor.\r
31// Each stand descriptor has a length and type.\r
32//\r
33#pragma pack(1)\r
34typedef struct {\r
35 UINT8 Len;\r
36 UINT8 Type;\r
37} USB_DESC_HEAD;\r
38#pragma pack()\r
39\r
40\r
41//\r
42// Each USB device has a device descriptor. Each device may\r
43// have several configures. Each configure contains several\r
44// interfaces. Each interface may have several settings. Each\r
45// setting has several endpoints.\r
46//\r
47// EFI_USB_..._DESCRIPTOR must be the first member of the\r
48// structure.\r
49//\r
50typedef struct {\r
51 EFI_USB_ENDPOINT_DESCRIPTOR Desc;\r
52 UINT8 Toggle;\r
53} USB_ENDPOINT_DESC;\r
54\r
55typedef struct {\r
56 EFI_USB_INTERFACE_DESCRIPTOR Desc;\r
57 USB_ENDPOINT_DESC **Endpoints;\r
58} USB_INTERFACE_SETTING;\r
59\r
60//\r
61// An interface may have several settings. Use a\r
62// fixed max number of settings to simplify code.\r
63// It should sufice in most environments.\r
64//\r
65typedef struct {\r
66 USB_INTERFACE_SETTING* Settings[USB_MAX_INTERFACE_SETTING];\r
67 UINTN NumOfSetting;\r
8d443a16 68 UINTN ActiveIndex; // Index of active setting\r
e237e7ae 69} USB_INTERFACE_DESC;\r
70\r
71typedef struct {\r
72 EFI_USB_CONFIG_DESCRIPTOR Desc;\r
73 USB_INTERFACE_DESC **Interfaces;\r
74} USB_CONFIG_DESC;\r
75\r
76typedef struct {\r
77 EFI_USB_DEVICE_DESCRIPTOR Desc;\r
78 USB_CONFIG_DESC **Configs;\r
79} USB_DEVICE_DESC;\r
80\r
8616fc4c 81/**\r
82 USB standard control transfer support routine. This\r
83 function is used by USB device. It is possible that\r
84 the device's interfaces are still waiting to be\r
85 enumerated.\r
86\r
87 @param UsbDev The usb device.\r
88 @param Direction The direction of data transfer.\r
89 @param Type Standard / class specific / vendor specific.\r
90 @param Target The receiving target.\r
91 @param Request Which request.\r
92 @param Value The wValue parameter of the request.\r
93 @param Index The wIndex parameter of the request.\r
94 @param Buf The buffer to receive data into / transmit from.\r
95 @param Length The length of the buffer.\r
96\r
97 @retval EFI_SUCCESS The control request is executed.\r
98 @retval EFI_DEVICE_ERROR Failed to execute the control transfer.\r
99\r
100**/\r
e237e7ae 101EFI_STATUS\r
102UsbCtrlRequest (\r
103 IN USB_DEVICE *UsbDev,\r
104 IN EFI_USB_DATA_DIRECTION Direction,\r
105 IN UINTN Type,\r
106 IN UINTN Target,\r
107 IN UINTN Request,\r
108 IN UINT16 Value,\r
109 IN UINT16 Index,\r
110 IN OUT VOID *Buf,\r
111 IN UINTN Length\r
112 );\r
113\r
8616fc4c 114/**\r
115 Return the max packet size for endpoint zero. This function\r
116 is the first function called to get descriptors during bus\r
117 enumeration.\r
118\r
119 @param UsbDev The usb device.\r
120\r
121 @retval EFI_SUCCESS The max packet size of endpoint zero is retrieved.\r
122 @retval EFI_DEVICE_ERROR Failed to retrieve it.\r
123\r
124**/\r
e237e7ae 125EFI_STATUS\r
126UsbGetMaxPacketSize0 (\r
127 IN USB_DEVICE *UsbDev\r
128 );\r
129\r
8616fc4c 130/**\r
131 Free a device descriptor with its configurations.\r
132\r
133 @param DevDesc The device descriptor.\r
134\r
135 @return None.\r
136\r
137**/\r
e237e7ae 138VOID\r
139UsbFreeDevDesc (\r
140 IN USB_DEVICE_DESC *DevDesc\r
141 );\r
142\r
8616fc4c 143/**\r
144 Retrieve the indexed string for the language. It requires two\r
145 steps to get a string, first to get the string's length. Then\r
146 the string itself.\r
147\r
148 @param UsbDev The usb device.\r
149 @param StringIndex The index of the string to retrieve.\r
150 @param LangId Language ID.\r
151\r
152 @return The created string descriptor or NULL.\r
153\r
154**/\r
e237e7ae 155EFI_USB_STRING_DESCRIPTOR*\r
156UsbGetOneString (\r
157 IN USB_DEVICE *UsbDev,\r
158 IN UINT8 StringIndex,\r
159 IN UINT16 LangId\r
160 );\r
161\r
8616fc4c 162/**\r
163 Build the whole array of descriptors. This function must\r
164 be called after UsbGetMaxPacketSize0 returns the max packet\r
165 size correctly for endpoint 0.\r
166\r
167 @param UsbDev The Usb device.\r
168\r
169 @retval EFI_SUCCESS The descriptor table is build.\r
170 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource for the descriptor.\r
171\r
172**/\r
e237e7ae 173EFI_STATUS\r
174UsbBuildDescTable (\r
175 IN USB_DEVICE *UsbDev\r
176 );\r
177\r
8616fc4c 178/**\r
179 Set the device's address.\r
180\r
181 @param UsbDev The device to set address to.\r
182 @param Address The address to set.\r
183\r
184 @retval EFI_SUCCESS The device is set to the address.\r
185 @retval Others Failed to set the device address.\r
186\r
187**/\r
e237e7ae 188EFI_STATUS\r
189UsbSetAddress (\r
190 IN USB_DEVICE *UsbDev,\r
191 IN UINT8 Address\r
192 );\r
193\r
8616fc4c 194/**\r
195 Set the device's configuration. This function changes\r
196 the device's internal state. UsbSelectConfig changes\r
197 the Usb bus's internal state.\r
198\r
199 @param UsbDev The USB device to set configure to.\r
200 @param ConfigIndex The configure index to set.\r
201\r
202 @retval EFI_SUCCESS The device is configured now.\r
203 @retval Others Failed to set the device configure.\r
204\r
205**/\r
e237e7ae 206EFI_STATUS\r
207UsbSetConfig (\r
208 IN USB_DEVICE *UsbDev,\r
209 IN UINT8 ConfigIndex\r
210 );\r
211\r
8616fc4c 212/**\r
213 Usb UsbIo interface to clear the feature. This is should\r
214 only be used by HUB which is considered a device driver\r
215 on top of the UsbIo interface.\r
216\r
217 @param UsbIo The UsbIo interface.\r
218 @param Target The target of the transfer: endpoint/device.\r
219 @param Feature The feature to clear.\r
220 @param Index The wIndex parameter.\r
221\r
222 @retval EFI_SUCCESS The device feature is cleared.\r
223 @retval Others Failed to clear the feature.\r
224\r
225**/\r
e237e7ae 226EFI_STATUS\r
227UsbIoClearFeature (\r
228 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
229 IN UINTN Target,\r
230 IN UINT16 Feature,\r
231 IN UINT16 Index\r
232 );\r
233#endif\r