]>
Commit | Line | Data |
---|---|---|
ed838d0c | 1 | /** @file\r |
7bc232b2 | 2 | \r |
9095d37b | 3 | The library provides the USB Standard Device Requests defined\r |
11ceade4 | 4 | in Usb specification 9.4 section.\r |
9095d37b LG |
5 | \r |
6 | Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r | |
9344f092 | 7 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
7bc232b2 | 8 | \r |
ed838d0c | 9 | **/\r |
7bc232b2 | 10 | \r |
6c401377 | 11 | #include "UefiUsbLibInternal.h"\r |
dad203ec | 12 | \r |
ed838d0c | 13 | \r |
14 | /**\r | |
d5954c61 | 15 | Get the descriptor of the specified USB device.\r |
16 | \r | |
17 | Submit a USB get descriptor request for the USB device specified by UsbIo, Value,\r | |
18 | and Index, and return the descriptor in the buffer specified by Descriptor.\r | |
19 | The status of the transfer is returned in Status.\r | |
20 | If UsbIo is NULL, then ASSERT().\r | |
21 | If Descriptor is NULL, then ASSERT().\r | |
22 | If Status is NULL, then ASSERT().\r | |
23 | \r | |
24 | @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r | |
25 | @param Value The device request value.\r | |
26 | @param Index The device request index.\r | |
27 | @param DescriptorLength The size, in bytes, of Descriptor.\r | |
28 | @param Descriptor A pointer to the descriptor buffer to get.\r | |
29 | @param Status A pointer to the status of the transfer.\r | |
30 | \r | |
31 | @retval EFI_SUCCESS The request executed successfully.\r | |
32 | @retval EFI_OUT_OF_RESOURCES The request could not be completed because the\r | |
28d3e14f | 33 | buffer specified by DescriptorLength and Descriptor\r |
d5954c61 | 34 | is not large enough to hold the result of the request.\r |
35 | @retval EFI_TIMEOUT A timeout occurred executing the request.\r | |
36 | @retval EFI_DEVICE_ERROR The request failed due to a device error. The transfer\r | |
37 | status is returned in Status.\r | |
ed838d0c | 38 | \r |
39 | **/\r | |
7bc232b2 | 40 | EFI_STATUS\r |
f1787349 | 41 | EFIAPI\r |
7bc232b2 LG |
42 | UsbGetDescriptor (\r |
43 | IN EFI_USB_IO_PROTOCOL *UsbIo,\r | |
44 | IN UINT16 Value,\r | |
45 | IN UINT16 Index,\r | |
46 | IN UINT16 DescriptorLength,\r | |
47 | OUT VOID *Descriptor,\r | |
48 | OUT UINT32 *Status\r | |
49 | )\r | |
7bc232b2 LG |
50 | {\r |
51 | EFI_USB_DEVICE_REQUEST DevReq;\r | |
52 | \r | |
d5954c61 | 53 | ASSERT (UsbIo != NULL);\r |
54 | ASSERT (Descriptor != NULL);\r | |
55 | ASSERT (Status != NULL);\r | |
7bc232b2 LG |
56 | \r |
57 | ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r | |
58 | \r | |
59 | DevReq.RequestType = USB_DEV_GET_DESCRIPTOR_REQ_TYPE;\r | |
ed838d0c | 60 | DevReq.Request = USB_REQ_GET_DESCRIPTOR;\r |
7bc232b2 LG |
61 | DevReq.Value = Value;\r |
62 | DevReq.Index = Index;\r | |
63 | DevReq.Length = DescriptorLength;\r | |
64 | \r | |
65 | return UsbIo->UsbControlTransfer (\r | |
66 | UsbIo,\r | |
67 | &DevReq,\r | |
68 | EfiUsbDataIn,\r | |
65442978 | 69 | PcdGet32 (PcdUsbTransferTimeoutValue),\r |
7bc232b2 LG |
70 | Descriptor,\r |
71 | DescriptorLength,\r | |
72 | Status\r | |
73 | );\r | |
74 | }\r | |
ed838d0c | 75 | \r |
76 | \r | |
77 | /**\r | |
d5954c61 | 78 | Set the descriptor of the specified USB device.\r |
79 | \r | |
80 | Submit a USB set descriptor request for the USB device specified by UsbIo,\r | |
81 | Value, and Index, and set the descriptor using the buffer specified by DesriptorLength\r | |
82 | and Descriptor. The status of the transfer is returned in Status.\r | |
83 | If UsbIo is NULL, then ASSERT().\r | |
84 | If Descriptor is NULL, then ASSERT().\r | |
85 | If Status is NULL, then ASSERT().\r | |
86 | \r | |
87 | @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r | |
88 | @param Value The device request value.\r | |
89 | @param Index The device request index.\r | |
90 | @param DescriptorLength The size, in bytes, of Descriptor.\r | |
91 | @param Descriptor A pointer to the descriptor buffer to set.\r | |
92 | @param Status A pointer to the status of the transfer.\r | |
93 | \r | |
94 | @retval EFI_SUCCESS The request executed successfully.\r | |
95 | @retval EFI_TIMEOUT A timeout occurred executing the request.\r | |
96 | @retval EFI_DEVICE_ERROR The request failed due to a device error.\r | |
97 | The transfer status is returned in Status.\r | |
ed838d0c | 98 | \r |
99 | **/\r | |
7bc232b2 | 100 | EFI_STATUS\r |
f1787349 | 101 | EFIAPI\r |
7bc232b2 LG |
102 | UsbSetDescriptor (\r |
103 | IN EFI_USB_IO_PROTOCOL *UsbIo,\r | |
104 | IN UINT16 Value,\r | |
105 | IN UINT16 Index,\r | |
106 | IN UINT16 DescriptorLength,\r | |
107 | IN VOID *Descriptor,\r | |
108 | OUT UINT32 *Status\r | |
109 | )\r | |
7bc232b2 LG |
110 | {\r |
111 | EFI_USB_DEVICE_REQUEST DevReq;\r | |
112 | \r | |
d5954c61 | 113 | ASSERT (UsbIo != NULL);\r |
114 | ASSERT (Descriptor != NULL);\r | |
115 | ASSERT (Status != NULL);\r | |
7bc232b2 LG |
116 | \r |
117 | ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r | |
118 | \r | |
119 | DevReq.RequestType = USB_DEV_SET_DESCRIPTOR_REQ_TYPE;\r | |
ed838d0c | 120 | DevReq.Request = USB_REQ_SET_DESCRIPTOR;\r |
7bc232b2 LG |
121 | DevReq.Value = Value;\r |
122 | DevReq.Index = Index;\r | |
123 | DevReq.Length = DescriptorLength;\r | |
124 | \r | |
125 | return UsbIo->UsbControlTransfer (\r | |
126 | UsbIo,\r | |
127 | &DevReq,\r | |
128 | EfiUsbDataOut,\r | |
65442978 | 129 | PcdGet32 (PcdUsbTransferTimeoutValue),\r |
7bc232b2 LG |
130 | Descriptor,\r |
131 | DescriptorLength,\r | |
132 | Status\r | |
133 | );\r | |
134 | }\r | |
135 | \r | |
ed838d0c | 136 | \r |
137 | /**\r | |
d5954c61 | 138 | Get the interface setting of the specified USB device.\r |
ed838d0c | 139 | \r |
d5954c61 | 140 | Submit a USB get interface request for the USB device specified by UsbIo,\r |
141 | and Interface, and place the result in the buffer specified by AlternateSetting.\r | |
142 | The status of the transfer is returned in Status.\r | |
143 | If UsbIo is NULL, then ASSERT().\r | |
144 | If AlternateSetting is NULL, then ASSERT().\r | |
145 | If Status is NULL, then ASSERT().\r | |
ed838d0c | 146 | \r |
d5954c61 | 147 | @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r |
148 | @param Interface The interface index value.\r | |
149 | @param AlternateSetting A pointer to the alternate setting to be retrieved.\r | |
150 | @param Status A pointer to the status of the transfer.\r | |
151 | \r | |
152 | @retval EFI_SUCCESS The request executed successfully.\r | |
153 | @retval EFI_TIMEOUT A timeout occurred executing the request.\r | |
154 | @retval EFI_DEVICE_ERROR The request failed due to a device error.\r | |
155 | The transfer status is returned in Status.\r | |
ed838d0c | 156 | \r |
157 | **/\r | |
7bc232b2 | 158 | EFI_STATUS\r |
f1787349 | 159 | EFIAPI\r |
ed838d0c | 160 | UsbGetInterface (\r |
7bc232b2 | 161 | IN EFI_USB_IO_PROTOCOL *UsbIo,\r |
d5954c61 | 162 | IN UINT16 Interface,\r |
2d8a3c13 | 163 | OUT UINT16 *AlternateSetting,\r |
7bc232b2 LG |
164 | OUT UINT32 *Status\r |
165 | )\r | |
7bc232b2 LG |
166 | {\r |
167 | EFI_USB_DEVICE_REQUEST DevReq;\r | |
168 | \r | |
d5954c61 | 169 | ASSERT (UsbIo != NULL);\r |
170 | ASSERT (AlternateSetting != NULL);\r | |
171 | ASSERT (Status != NULL);\r | |
7bc232b2 | 172 | \r |
134c1f33 | 173 | *AlternateSetting = 0;\r |
174 | \r | |
7bc232b2 LG |
175 | ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r |
176 | \r | |
177 | DevReq.RequestType = USB_DEV_GET_INTERFACE_REQ_TYPE;\r | |
ed838d0c | 178 | DevReq.Request = USB_REQ_GET_INTERFACE;\r |
d5954c61 | 179 | DevReq.Index = Interface;\r |
7bc232b2 LG |
180 | DevReq.Length = 1;\r |
181 | \r | |
182 | return UsbIo->UsbControlTransfer (\r | |
183 | UsbIo,\r | |
184 | &DevReq,\r | |
185 | EfiUsbDataIn,\r | |
65442978 | 186 | PcdGet32 (PcdUsbTransferTimeoutValue),\r |
d5954c61 | 187 | AlternateSetting,\r |
c255449e | 188 | 1,\r |
7bc232b2 LG |
189 | Status\r |
190 | );\r | |
191 | }\r | |
7bc232b2 | 192 | \r |
7bc232b2 | 193 | \r |
ed838d0c | 194 | /**\r |
d5954c61 | 195 | Set the interface setting of the specified USB device.\r |
7bc232b2 | 196 | \r |
d5954c61 | 197 | Submit a USB set interface request for the USB device specified by UsbIo, and\r |
198 | Interface, and set the alternate setting to the value specified by AlternateSetting.\r | |
199 | The status of the transfer is returned in Status.\r | |
200 | If UsbIo is NULL, then ASSERT().\r | |
201 | If Status is NULL, then ASSERT().\r | |
7bc232b2 | 202 | \r |
d5954c61 | 203 | @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r |
204 | @param Interface The interface index value.\r | |
205 | @param AlternateSetting The alternate setting to be set.\r | |
206 | @param Status A pointer to the status of the transfer.\r | |
207 | \r | |
208 | @retval EFI_SUCCESS The request executed successfully.\r | |
209 | @retval EFI_TIMEOUT A timeout occurred executing the request.\r | |
210 | @retval EFI_SUCCESS The request failed due to a device error.\r | |
211 | The transfer status is returned in Status.\r | |
7bc232b2 | 212 | \r |
ed838d0c | 213 | **/\r |
214 | EFI_STATUS\r | |
f1787349 | 215 | EFIAPI\r |
ed838d0c | 216 | UsbSetInterface (\r |
217 | IN EFI_USB_IO_PROTOCOL *UsbIo,\r | |
d5954c61 | 218 | IN UINT16 Interface,\r |
219 | IN UINT16 AlternateSetting,\r | |
ed838d0c | 220 | OUT UINT32 *Status\r |
221 | )\r | |
7bc232b2 LG |
222 | {\r |
223 | EFI_USB_DEVICE_REQUEST DevReq;\r | |
224 | \r | |
d5954c61 | 225 | ASSERT (UsbIo != NULL);\r |
226 | ASSERT (Status != NULL);\r | |
7bc232b2 LG |
227 | \r |
228 | ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r | |
229 | \r | |
230 | DevReq.RequestType = USB_DEV_SET_INTERFACE_REQ_TYPE;\r | |
ed838d0c | 231 | DevReq.Request = USB_REQ_SET_INTERFACE;\r |
d5954c61 | 232 | DevReq.Value = AlternateSetting;\r |
233 | DevReq.Index = Interface;\r | |
7bc232b2 LG |
234 | \r |
235 | return UsbIo->UsbControlTransfer (\r | |
236 | UsbIo,\r | |
237 | &DevReq,\r | |
238 | EfiUsbNoData,\r | |
65442978 | 239 | PcdGet32 (PcdUsbTransferTimeoutValue),\r |
7bc232b2 LG |
240 | NULL,\r |
241 | 0,\r | |
242 | Status\r | |
243 | );\r | |
244 | }\r | |
7bc232b2 | 245 | \r |
7bc232b2 | 246 | \r |
ed838d0c | 247 | /**\r |
d5954c61 | 248 | Get the device configuration.\r |
249 | \r | |
250 | Submit a USB get configuration request for the USB device specified by UsbIo\r | |
251 | and place the result in the buffer specified by ConfigurationValue. The status\r | |
252 | of the transfer is returned in Status.\r | |
253 | If UsbIo is NULL, then ASSERT().\r | |
254 | If ConfigurationValue is NULL, then ASSERT().\r | |
255 | If Status is NULL, then ASSERT().\r | |
7bc232b2 | 256 | \r |
d5954c61 | 257 | @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r |
258 | @param ConfigurationValue A pointer to the device configuration to be retrieved.\r | |
259 | @param Status A pointer to the status of the transfer.\r | |
7bc232b2 | 260 | \r |
d5954c61 | 261 | @retval EFI_SUCCESS The request executed successfully.\r |
262 | @retval EFI_TIMEOUT A timeout occurred executing the request.\r | |
263 | @retval EFI_DEVICE_ERROR The request failed due to a device error.\r | |
264 | The transfer status is returned in Status.\r | |
7bc232b2 | 265 | \r |
ed838d0c | 266 | **/\r |
267 | EFI_STATUS\r | |
f1787349 | 268 | EFIAPI\r |
ed838d0c | 269 | UsbGetConfiguration (\r |
270 | IN EFI_USB_IO_PROTOCOL *UsbIo,\r | |
2d8a3c13 | 271 | OUT UINT16 *ConfigurationValue,\r |
ed838d0c | 272 | OUT UINT32 *Status\r |
273 | )\r | |
7bc232b2 LG |
274 | {\r |
275 | EFI_USB_DEVICE_REQUEST DevReq;\r | |
276 | \r | |
d5954c61 | 277 | ASSERT (UsbIo != NULL);\r |
278 | ASSERT (ConfigurationValue != NULL);\r | |
279 | ASSERT (Status != NULL);\r | |
7bc232b2 | 280 | \r |
134c1f33 | 281 | *ConfigurationValue = 0;\r |
282 | \r | |
7bc232b2 LG |
283 | ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r |
284 | \r | |
285 | DevReq.RequestType = USB_DEV_GET_CONFIGURATION_REQ_TYPE;\r | |
ed838d0c | 286 | DevReq.Request = USB_REQ_GET_CONFIG;\r |
7bc232b2 LG |
287 | DevReq.Length = 1;\r |
288 | \r | |
289 | return UsbIo->UsbControlTransfer (\r | |
290 | UsbIo,\r | |
291 | &DevReq,\r | |
292 | EfiUsbDataIn,\r | |
65442978 | 293 | PcdGet32 (PcdUsbTransferTimeoutValue),\r |
d5954c61 | 294 | ConfigurationValue,\r |
c255449e | 295 | 1,\r |
7bc232b2 LG |
296 | Status\r |
297 | );\r | |
298 | }\r | |
7bc232b2 | 299 | \r |
7bc232b2 | 300 | \r |
ed838d0c | 301 | /**\r |
d5954c61 | 302 | Set the device configuration.\r |
303 | \r | |
304 | Submit a USB set configuration request for the USB device specified by UsbIo\r | |
305 | and set the device configuration to the value specified by ConfigurationValue.\r | |
306 | The status of the transfer is returned in Status.\r | |
307 | If UsbIo is NULL, then ASSERT().\r | |
308 | If Status is NULL, then ASSERT().\r | |
7bc232b2 | 309 | \r |
d5954c61 | 310 | @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r |
311 | @param ConfigurationValue The device configuration value to be set.\r | |
312 | @param Status A pointer to the status of the transfer.\r | |
7bc232b2 | 313 | \r |
d5954c61 | 314 | @retval EFI_SUCCESS The request executed successfully.\r |
315 | @retval EFI_TIMEOUT A timeout occurred executing the request.\r | |
316 | @retval EFI_DEVICE_ERROR The request failed due to a device error.\r | |
317 | The transfer status is returned in Status.\r | |
7bc232b2 | 318 | \r |
ed838d0c | 319 | **/\r |
320 | EFI_STATUS\r | |
f1787349 | 321 | EFIAPI\r |
ed838d0c | 322 | UsbSetConfiguration (\r |
323 | IN EFI_USB_IO_PROTOCOL *UsbIo,\r | |
d5954c61 | 324 | IN UINT16 ConfigurationValue,\r |
ed838d0c | 325 | OUT UINT32 *Status\r |
326 | )\r | |
7bc232b2 LG |
327 | {\r |
328 | EFI_USB_DEVICE_REQUEST DevReq;\r | |
329 | \r | |
d5954c61 | 330 | ASSERT (UsbIo != NULL);\r |
331 | ASSERT (Status != NULL);\r | |
7bc232b2 LG |
332 | \r |
333 | ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r | |
334 | \r | |
335 | DevReq.RequestType = USB_DEV_SET_CONFIGURATION_REQ_TYPE;\r | |
ed838d0c | 336 | DevReq.Request = USB_REQ_SET_CONFIG;\r |
d5954c61 | 337 | DevReq.Value = ConfigurationValue;\r |
ed838d0c | 338 | \r |
7bc232b2 LG |
339 | return UsbIo->UsbControlTransfer (\r |
340 | UsbIo,\r | |
341 | &DevReq,\r | |
342 | EfiUsbNoData,\r | |
65442978 | 343 | PcdGet32 (PcdUsbTransferTimeoutValue),\r |
7bc232b2 LG |
344 | NULL,\r |
345 | 0,\r | |
346 | Status\r | |
347 | );\r | |
348 | }\r | |
7bc232b2 | 349 | \r |
7bc232b2 | 350 | \r |
ed838d0c | 351 | /**\r |
d5954c61 | 352 | Set the specified feature of the specified device.\r |
353 | \r | |
354 | Submit a USB set device feature request for the USB device specified by UsbIo,\r | |
355 | Recipient, and Target to the value specified by Value. The status of the\r | |
356 | transfer is returned in Status.\r | |
357 | If UsbIo is NULL, then ASSERT().\r | |
358 | If Status is NULL, then ASSERT().\r | |
359 | \r | |
360 | @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r | |
361 | @param Recipient The USB data recipient type (i.e. Device, Interface, Endpoint).\r | |
362 | Type USB_TYPES_DEFINITION is defined in the MDE Package Industry\r | |
363 | Standard include file Usb.h.\r | |
364 | @param Value The value of the feature to be set.\r | |
365 | @param Target The index of the device to be set.\r | |
366 | @param Status A pointer to the status of the transfer.\r | |
367 | \r | |
368 | @retval EFI_SUCCESS The request executed successfully.\r | |
369 | @retval EFI_TIMEOUT A timeout occurred executing the request.\r | |
370 | @retval EFI_DEVICE_ERROR The request failed due to a device error.\r | |
371 | The transfer status is returned in Status.\r | |
7bc232b2 | 372 | \r |
ed838d0c | 373 | **/\r |
374 | EFI_STATUS\r | |
f1787349 | 375 | EFIAPI\r |
ed838d0c | 376 | UsbSetFeature (\r |
377 | IN EFI_USB_IO_PROTOCOL *UsbIo,\r | |
d5954c61 | 378 | IN USB_TYPES_DEFINITION Recipient,\r |
ed838d0c | 379 | IN UINT16 Value,\r |
380 | IN UINT16 Target,\r | |
381 | OUT UINT32 *Status\r | |
382 | )\r | |
7bc232b2 LG |
383 | {\r |
384 | EFI_USB_DEVICE_REQUEST DevReq;\r | |
385 | \r | |
d5954c61 | 386 | ASSERT (UsbIo != NULL);\r |
387 | ASSERT (Status != NULL);\r | |
7bc232b2 LG |
388 | \r |
389 | ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r | |
390 | \r | |
391 | switch (Recipient) {\r | |
392 | \r | |
ed838d0c | 393 | case USB_TARGET_DEVICE:\r |
394 | DevReq.RequestType = USB_DEV_SET_FEATURE_REQ_TYPE_D;\r | |
7bc232b2 LG |
395 | break;\r |
396 | \r | |
ed838d0c | 397 | case USB_TARGET_INTERFACE:\r |
398 | DevReq.RequestType = USB_DEV_SET_FEATURE_REQ_TYPE_I;\r | |
7bc232b2 LG |
399 | break;\r |
400 | \r | |
ed838d0c | 401 | case USB_TARGET_ENDPOINT:\r |
402 | DevReq.RequestType = USB_DEV_SET_FEATURE_REQ_TYPE_E;\r | |
7bc232b2 | 403 | break;\r |
563353b7 | 404 | \r |
405 | default:\r | |
406 | break;\r | |
7bc232b2 LG |
407 | }\r |
408 | //\r | |
409 | // Fill device request, see USB1.1 spec\r | |
410 | //\r | |
ed838d0c | 411 | DevReq.Request = USB_REQ_SET_FEATURE;\r |
7bc232b2 LG |
412 | DevReq.Value = Value;\r |
413 | DevReq.Index = Target;\r | |
414 | \r | |
415 | \r | |
416 | return UsbIo->UsbControlTransfer (\r | |
417 | UsbIo,\r | |
418 | &DevReq,\r | |
419 | EfiUsbNoData,\r | |
65442978 | 420 | PcdGet32 (PcdUsbTransferTimeoutValue),\r |
7bc232b2 LG |
421 | NULL,\r |
422 | 0,\r | |
423 | Status\r | |
424 | );\r | |
425 | }\r | |
7bc232b2 | 426 | \r |
7bc232b2 | 427 | \r |
ed838d0c | 428 | /**\r |
d5954c61 | 429 | Clear the specified feature of the specified device.\r |
430 | \r | |
431 | Submit a USB clear device feature request for the USB device specified by UsbIo,\r | |
432 | Recipient, and Target to the value specified by Value. The status of the transfer\r | |
433 | is returned in Status.\r | |
434 | If UsbIo is NULL, then ASSERT().\r | |
435 | If Status is NULL, then ASSERT().\r | |
436 | \r | |
437 | @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r | |
438 | @param Recipient The USB data recipient type (i.e. Device, Interface, Endpoint).\r | |
439 | Type USB_TYPES_DEFINITION is defined in the MDE Package Industry Standard\r | |
440 | include file Usb.h.\r | |
441 | @param Value The value of the feature to be cleared.\r | |
442 | @param Target The index of the device to be cleared.\r | |
443 | @param Status A pointer to the status of the transfer.\r | |
444 | \r | |
445 | @retval EFI_SUCCESS The request executed successfully.\r | |
446 | @retval EFI_TIMEOUT A timeout occurred executing the request.\r | |
447 | @retval EFI_DEVICE_ERROR The request failed due to a device error.\r | |
448 | The transfer status is returned in Status.\r | |
7bc232b2 | 449 | \r |
ed838d0c | 450 | **/\r |
451 | EFI_STATUS\r | |
f1787349 | 452 | EFIAPI\r |
ed838d0c | 453 | UsbClearFeature (\r |
454 | IN EFI_USB_IO_PROTOCOL *UsbIo,\r | |
d5954c61 | 455 | IN USB_TYPES_DEFINITION Recipient,\r |
ed838d0c | 456 | IN UINT16 Value,\r |
457 | IN UINT16 Target,\r | |
458 | OUT UINT32 *Status\r | |
459 | )\r | |
7bc232b2 LG |
460 | {\r |
461 | EFI_USB_DEVICE_REQUEST DevReq;\r | |
462 | \r | |
d5954c61 | 463 | ASSERT (UsbIo != NULL);\r |
464 | ASSERT (Status != NULL);\r | |
465 | \r | |
7bc232b2 LG |
466 | \r |
467 | ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r | |
468 | \r | |
469 | switch (Recipient) {\r | |
470 | \r | |
ed838d0c | 471 | case USB_TARGET_DEVICE:\r |
472 | DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_D;\r | |
7bc232b2 LG |
473 | break;\r |
474 | \r | |
ed838d0c | 475 | case USB_TARGET_INTERFACE:\r |
476 | DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_I;\r | |
7bc232b2 LG |
477 | break;\r |
478 | \r | |
ed838d0c | 479 | case USB_TARGET_ENDPOINT:\r |
480 | DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_E;\r | |
7bc232b2 | 481 | break;\r |
563353b7 | 482 | \r |
483 | default:\r | |
484 | break;\r | |
7bc232b2 LG |
485 | }\r |
486 | //\r | |
487 | // Fill device request, see USB1.1 spec\r | |
488 | //\r | |
ed838d0c | 489 | DevReq.Request = USB_REQ_CLEAR_FEATURE;\r |
7bc232b2 LG |
490 | DevReq.Value = Value;\r |
491 | DevReq.Index = Target;\r | |
492 | \r | |
493 | \r | |
494 | return UsbIo->UsbControlTransfer (\r | |
495 | UsbIo,\r | |
496 | &DevReq,\r | |
497 | EfiUsbNoData,\r | |
65442978 | 498 | PcdGet32 (PcdUsbTransferTimeoutValue),\r |
7bc232b2 LG |
499 | NULL,\r |
500 | 0,\r | |
501 | Status\r | |
502 | );\r | |
503 | }\r | |
7bc232b2 | 504 | \r |
7bc232b2 | 505 | \r |
ed838d0c | 506 | /**\r |
d5954c61 | 507 | Get the status of the specified device.\r |
508 | \r | |
509 | Submit a USB device get status request for the USB device specified by UsbIo,\r | |
510 | Recipient, and Target and place the result in the buffer specified by DeviceStatus.\r | |
511 | The status of the transfer is returned in Status.\r | |
512 | If UsbIo is NULL, then ASSERT().\r | |
513 | If DeviceStatus is NULL, then ASSERT().\r | |
514 | If Status is NULL, then ASSERT().\r | |
515 | \r | |
516 | @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r | |
517 | @param Recipient The USB data recipient type (i.e. Device, Interface, Endpoint).\r | |
518 | Type USB_TYPES_DEFINITION is defined in the MDE Package Industry Standard\r | |
519 | include file Usb.h.\r | |
520 | @param Target The index of the device to be get the status of.\r | |
521 | @param DeviceStatus A pointer to the device status to be retrieved.\r | |
522 | @param Status A pointer to the status of the transfer.\r | |
523 | \r | |
524 | @retval EFI_SUCCESS The request executed successfully.\r | |
525 | @retval EFI_TIMEOUT A timeout occurred executing the request.\r | |
526 | @retval EFI_DEVICE_ERROR The request failed due to a device error.\r | |
527 | The transfer status is returned in Status.\r | |
7bc232b2 | 528 | \r |
ed838d0c | 529 | **/\r |
530 | EFI_STATUS\r | |
f1787349 | 531 | EFIAPI\r |
ed838d0c | 532 | UsbGetStatus (\r |
533 | IN EFI_USB_IO_PROTOCOL *UsbIo,\r | |
d5954c61 | 534 | IN USB_TYPES_DEFINITION Recipient,\r |
ed838d0c | 535 | IN UINT16 Target,\r |
d5954c61 | 536 | OUT UINT16 *DeviceStatus,\r |
ed838d0c | 537 | OUT UINT32 *Status\r |
538 | )\r | |
7bc232b2 LG |
539 | {\r |
540 | EFI_USB_DEVICE_REQUEST DevReq;\r | |
541 | \r | |
d5954c61 | 542 | ASSERT (UsbIo != NULL);\r |
543 | ASSERT (DeviceStatus != NULL);\r | |
544 | ASSERT (Status != NULL);\r | |
7bc232b2 LG |
545 | \r |
546 | ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r | |
547 | \r | |
548 | switch (Recipient) {\r | |
549 | \r | |
ed838d0c | 550 | case USB_TARGET_DEVICE:\r |
551 | DevReq.RequestType = USB_DEV_GET_STATUS_REQ_TYPE_D;\r | |
7bc232b2 LG |
552 | break;\r |
553 | \r | |
ed838d0c | 554 | case USB_TARGET_INTERFACE:\r |
555 | DevReq.RequestType = USB_DEV_GET_STATUS_REQ_TYPE_I;\r | |
7bc232b2 LG |
556 | break;\r |
557 | \r | |
ed838d0c | 558 | case USB_TARGET_ENDPOINT:\r |
559 | DevReq.RequestType = USB_DEV_GET_STATUS_REQ_TYPE_E;\r | |
7bc232b2 | 560 | break;\r |
563353b7 | 561 | \r |
562 | default:\r | |
563 | break;\r | |
7bc232b2 LG |
564 | }\r |
565 | //\r | |
566 | // Fill device request, see USB1.1 spec\r | |
567 | //\r | |
ed838d0c | 568 | DevReq.Request = USB_REQ_GET_STATUS;\r |
7bc232b2 LG |
569 | DevReq.Value = 0;\r |
570 | DevReq.Index = Target;\r | |
571 | DevReq.Length = 2;\r | |
572 | \r | |
573 | return UsbIo->UsbControlTransfer (\r | |
574 | UsbIo,\r | |
575 | &DevReq,\r | |
576 | EfiUsbDataIn,\r | |
65442978 | 577 | PcdGet32 (PcdUsbTransferTimeoutValue),\r |
d5954c61 | 578 | DeviceStatus,\r |
7bc232b2 LG |
579 | 2,\r |
580 | Status\r | |
581 | );\r | |
582 | }\r | |
7bc232b2 | 583 | \r |
7bc232b2 | 584 | \r |
ed838d0c | 585 | /**\r |
d5954c61 | 586 | Clear halt feature of the specified usb endpoint.\r |
587 | \r | |
588 | Retrieve the USB endpoint descriptor specified by UsbIo and EndPoint.\r | |
589 | If the USB endpoint descriptor can not be retrieved, then return EFI_NOT_FOUND.\r | |
070a76b1 | 590 | If the endpoint descriptor is found, then clear the halt feature of this USB endpoint.\r |
d5954c61 | 591 | The status of the transfer is returned in Status.\r |
592 | If UsbIo is NULL, then ASSERT().\r | |
593 | If Status is NULL, then ASSERT().\r | |
7bc232b2 | 594 | \r |
d5954c61 | 595 | @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r |
596 | @param Endpoint The endpoint address.\r | |
597 | @param Status A pointer to the status of the transfer.\r | |
7bc232b2 | 598 | \r |
d5954c61 | 599 | @retval EFI_SUCCESS The request executed successfully.\r |
600 | @retval EFI_TIMEOUT A timeout occurred executing the request.\r | |
601 | @retval EFI_DEVICE_ERROR The request failed due to a device error.\r | |
602 | The transfer status is returned in Status.\r | |
603 | @retval EFI_NOT_FOUND The specified USB endpoint descriptor can not be found\r | |
7bc232b2 | 604 | \r |
ed838d0c | 605 | **/\r |
7bc232b2 | 606 | EFI_STATUS\r |
f1787349 | 607 | EFIAPI\r |
7bc232b2 LG |
608 | UsbClearEndpointHalt (\r |
609 | IN EFI_USB_IO_PROTOCOL *UsbIo,\r | |
d5954c61 | 610 | IN UINT8 Endpoint,\r |
7bc232b2 LG |
611 | OUT UINT32 *Status\r |
612 | )\r | |
7bc232b2 LG |
613 | {\r |
614 | EFI_STATUS Result;\r | |
615 | EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor;\r | |
616 | EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;\r | |
617 | UINT8 Index;\r | |
618 | \r | |
d5954c61 | 619 | ASSERT (UsbIo != NULL);\r |
620 | ASSERT (Status != NULL);\r | |
8069d49e | 621 | \r |
7bc232b2 LG |
622 | ZeroMem (&EndpointDescriptor, sizeof (EFI_USB_ENDPOINT_DESCRIPTOR));\r |
623 | //\r | |
3868d06d | 624 | // First search the endpoint descriptor for that endpoint addr\r |
7bc232b2 LG |
625 | //\r |
626 | Result = UsbIo->UsbGetInterfaceDescriptor (\r | |
627 | UsbIo,\r | |
628 | &InterfaceDescriptor\r | |
629 | );\r | |
630 | if (EFI_ERROR (Result)) {\r | |
631 | return Result;\r | |
632 | }\r | |
633 | \r | |
634 | for (Index = 0; Index < InterfaceDescriptor.NumEndpoints; Index++) {\r | |
635 | Result = UsbIo->UsbGetEndpointDescriptor (\r | |
636 | UsbIo,\r | |
637 | Index,\r | |
638 | &EndpointDescriptor\r | |
639 | );\r | |
640 | if (EFI_ERROR (Result)) {\r | |
641 | continue;\r | |
642 | }\r | |
643 | \r | |
d5954c61 | 644 | if (EndpointDescriptor.EndpointAddress == Endpoint) {\r |
7bc232b2 LG |
645 | break;\r |
646 | }\r | |
647 | }\r | |
648 | \r | |
649 | if (Index == InterfaceDescriptor.NumEndpoints) {\r | |
650 | //\r | |
651 | // No such endpoint\r | |
652 | //\r | |
653 | return EFI_NOT_FOUND;\r | |
654 | }\r | |
655 | \r | |
ed838d0c | 656 | Result = UsbClearFeature (\r |
7bc232b2 | 657 | UsbIo,\r |
ed838d0c | 658 | USB_TARGET_ENDPOINT,\r |
d35be2a4 | 659 | USB_FEATURE_ENDPOINT_HALT,\r |
7bc232b2 LG |
660 | EndpointDescriptor.EndpointAddress,\r |
661 | Status\r | |
662 | );\r | |
663 | \r | |
664 | return Result;\r | |
665 | }\r |