]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/UefiUsbLib/Hid.c
Update doxygen comment for VarArg list parameter. "..."'s description is added.
[mirror_edk2.git] / MdePkg / Library / UefiUsbLib / Hid.c
CommitLineData
ce821dff 1/** @file\r
2\r
11ceade4
LG
3 The library provides USB HID Class standard and specific requests defined\r
4 in USB HID Firmware Specification 7 section : Requests.\r
c311f86b 5 \r
6 Copyright (c) 2004, Intel Corporation\r
7 All rights reserved. This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php\r
11 \r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
ce821dff 14\r
15**/\r
16\r
6c401377 17#include "UefiUsbLibInternal.h"\r
ce821dff 18\r
11ceade4
LG
19// \r
20// Hid RequestType Bits specifying characteristics of request.\r
21// Valid values are 10100001b (0xa1) or 00100001b (0x21).\r
22// The following description:\r
23// 7 Data transfer direction\r
24// 0 = Host to device\r
25// 1 = Device to host\r
26// 6..5 Type\r
27// 1 = Class\r
28// 4..0 Recipient\r
29// 1 = Interface\r
30//\r
ce821dff 31\r
32/**\r
d5954c61 33 Get the descriptor of the specified USB HID interface.\r
ce821dff 34\r
d5954c61 35 Submit a USB get HID descriptor request for the USB device specified by UsbIo\r
36 and Interface and return the HID descriptor in HidDescriptor.\r
37 If UsbIo is NULL, then ASSERT().\r
38 If HidDescriptor is NULL, then ASSERT().\r
ce821dff 39\r
d5954c61 40 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
41 @param Interface The index of the HID interface on the USB target.\r
42 @param HidDescriptor Pointer to the USB HID descriptor that was retrieved from\r
43 the specified USB target and interface. Type EFI_USB_HID_DESCRIPTOR\r
44 is defined in the MDE Package Industry Standard include file Usb.h.\r
45\r
46 @retval EFI_SUCCESS The request executed successfully.\r
47 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
48 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
ce821dff 49\r
50**/\r
51EFI_STATUS\r
373b5cf9 52EFIAPI\r
ce821dff 53UsbGetHidDescriptor (\r
54 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
d5954c61 55 IN UINT8 Interface,\r
ce821dff 56 OUT EFI_USB_HID_DESCRIPTOR *HidDescriptor\r
57 )\r
58{\r
59 UINT32 Status;\r
60 EFI_STATUS Result;\r
61 EFI_USB_DEVICE_REQUEST Request;\r
d5954c61 62\r
63 ASSERT(UsbIo != NULL);\r
64 ASSERT(HidDescriptor != NULL);\r
ce821dff 65\r
11ceade4
LG
66 Request.RequestType = USB_HID_GET_DESCRIPTOR_REQ_TYPE;\r
67 Request.Request = USB_REQ_GET_DESCRIPTOR;\r
68 Request.Value = (UINT16) (USB_DESC_TYPE_HID << 8);\r
d5954c61 69 Request.Index = Interface;\r
ce821dff 70 Request.Length = sizeof (EFI_USB_HID_DESCRIPTOR);\r
71\r
72 Result = UsbIo->UsbControlTransfer (\r
73 UsbIo,\r
74 &Request,\r
75 EfiUsbDataIn,\r
76 TIMEOUT_VALUE,\r
77 HidDescriptor,\r
78 sizeof (EFI_USB_HID_DESCRIPTOR),\r
79 &Status\r
80 );\r
81\r
82 return Result;\r
83\r
84}\r
ce821dff 85\r
86/**\r
d5954c61 87 Get the report descriptor of the specified USB HID interface.\r
ce821dff 88\r
d5954c61 89 Submit a USB get HID report descriptor request for the USB device specified by\r
90 UsbIo and Interface and return the report descriptor in DescriptorBuffer.\r
91 If UsbIo is NULL, then ASSERT().\r
92 If DescriptorBuffer is NULL, then ASSERT().\r
ce821dff 93\r
d5954c61 94 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
95 @param Interface The index of the report interface on the USB target.\r
96 @param DescriptorLength The size, in bytes, of DescriptorBuffer.\r
97 @param DescriptorBuffer A pointer to the buffer to store the report class descriptor.\r
98\r
99 @retval EFI_SUCCESS The request executed successfully.\r
100 @retval EFI_OUT_OF_RESOURCES The request could not be completed because the\r
101 buffer specifed by DescriptorLength and DescriptorBuffer\r
102 is not large enough to hold the result of the request.\r
103 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
104 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
ce821dff 105\r
106**/\r
107EFI_STATUS\r
373b5cf9 108EFIAPI\r
ce821dff 109UsbGetReportDescriptor (\r
110 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
d5954c61 111 IN UINT8 Interface,\r
112 IN UINT16 DescriptorLength,\r
ce821dff 113 OUT UINT8 *DescriptorBuffer\r
114 )\r
115{\r
116 UINT32 Status;\r
117 EFI_STATUS Result;\r
118 EFI_USB_DEVICE_REQUEST Request;\r
119\r
d5954c61 120 ASSERT (UsbIo != NULL);\r
121 ASSERT (DescriptorBuffer != NULL);\r
122\r
ce821dff 123 //\r
124 // Fill Device request packet\r
125 //\r
11ceade4
LG
126 Request.RequestType = USB_HID_GET_DESCRIPTOR_REQ_TYPE;\r
127 Request.Request = USB_REQ_GET_DESCRIPTOR;\r
128 Request.Value = (UINT16) (USB_DESC_TYPE_REPORT << 8);\r
d5954c61 129 Request.Index = Interface;\r
130 Request.Length = DescriptorLength;\r
ce821dff 131\r
132 Result = UsbIo->UsbControlTransfer (\r
133 UsbIo,\r
134 &Request,\r
135 EfiUsbDataIn,\r
136 TIMEOUT_VALUE,\r
137 DescriptorBuffer,\r
d5954c61 138 DescriptorLength,\r
ce821dff 139 &Status\r
140 );\r
141\r
142 return Result;\r
143\r
144}\r
ce821dff 145\r
146/**\r
d5954c61 147 Get the HID protocol of the specified USB HID interface.\r
148\r
149 Submit a USB get HID protocol request for the USB device specified by UsbIo\r
150 and Interface and return the protocol retrieved in Protocol.\r
151 If UsbIo is NULL, then ASSERT().\r
152 If Protocol is NULL, then ASSERT().\r
ce821dff 153\r
d5954c61 154 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
155 @param Interface The index of the report interface on the USB target.\r
156 @param Protocol A pointer to the protocol for the specified USB target.\r
ce821dff 157\r
d5954c61 158 @retval EFI_SUCCESS The request executed successfully.\r
159 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
160 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
ce821dff 161\r
162**/\r
163EFI_STATUS\r
373b5cf9 164EFIAPI\r
ce821dff 165UsbGetProtocolRequest (\r
166 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
167 IN UINT8 Interface,\r
168 IN UINT8 *Protocol\r
169 )\r
170{\r
171 UINT32 Status;\r
172 EFI_STATUS Result;\r
173 EFI_USB_DEVICE_REQUEST Request;\r
174\r
d5954c61 175 ASSERT (UsbIo != NULL);\r
176 ASSERT (Protocol != NULL);\r
177\r
ce821dff 178 //\r
179 // Fill Device request packet\r
180 //\r
11ceade4 181 Request.RequestType = USB_HID_CLASS_GET_REQ_TYPE;\r
ce821dff 182 Request.Request = EFI_USB_GET_PROTOCOL_REQUEST;\r
183 Request.Value = 0;\r
184 Request.Index = Interface;\r
185 Request.Length = 1;\r
186\r
187 Result = UsbIo->UsbControlTransfer (\r
188 UsbIo,\r
189 &Request,\r
190 EfiUsbDataIn,\r
191 TIMEOUT_VALUE,\r
192 Protocol,\r
193 sizeof (UINT8),\r
194 &Status\r
195 );\r
196\r
197 return Result;\r
198}\r
199\r
200\r
373b5cf9 201\r
ce821dff 202/**\r
d5954c61 203 Set the HID protocol of the specified USB HID interface.\r
ce821dff 204\r
d5954c61 205 Submit a USB set HID protocol request for the USB device specified by UsbIo\r
206 and Interface and set the protocol to the value specified by Protocol.\r
207 If UsbIo is NULL, then ASSERT().\r
ce821dff 208\r
d5954c61 209 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
210 @param Interface The index of the report interface on the USB target.\r
211 @param Protocol The protocol value to set for the specified USB target.\r
212\r
213 @retval EFI_SUCCESS The request executed successfully.\r
214 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
215 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
ce821dff 216\r
217**/\r
218EFI_STATUS\r
373b5cf9 219EFIAPI\r
ce821dff 220UsbSetProtocolRequest (\r
221 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
222 IN UINT8 Interface,\r
223 IN UINT8 Protocol\r
224 )\r
225{\r
226 UINT32 Status;\r
227 EFI_STATUS Result;\r
228 EFI_USB_DEVICE_REQUEST Request;\r
229\r
d5954c61 230 ASSERT (UsbIo != NULL);\r
231 \r
ce821dff 232 //\r
233 // Fill Device request packet\r
234 //\r
11ceade4 235 Request.RequestType = USB_HID_CLASS_SET_REQ_TYPE;\r
ce821dff 236 Request.Request = EFI_USB_SET_PROTOCOL_REQUEST;\r
237 Request.Value = Protocol;\r
238 Request.Index = Interface;\r
239 Request.Length = 0;\r
240\r
241 Result = UsbIo->UsbControlTransfer (\r
242 UsbIo,\r
243 &Request,\r
244 EfiUsbNoData,\r
245 TIMEOUT_VALUE,\r
246 NULL,\r
247 0,\r
248 &Status\r
249 );\r
250 return Result;\r
251}\r
252\r
253\r
ce821dff 254/**\r
d5954c61 255 Set the idle rate of the specified USB HID report.\r
ce821dff 256\r
d5954c61 257 Submit a USB set HID report idle request for the USB device specified by UsbIo,\r
258 Interface, and ReportId, and set the idle rate to the value specified by Duration.\r
259 If UsbIo is NULL, then ASSERT().\r
ce821dff 260\r
d5954c61 261 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
262 @param Interface The index of the report interface on the USB target.\r
263 @param ReportId The identifier of the report to retrieve.\r
264 @param Duration The idle rate to set for the specified USB target.\r
265\r
266 @retval EFI_SUCCESS The request executed successfully.\r
267 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
268 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
ce821dff 269\r
270**/\r
271EFI_STATUS\r
373b5cf9 272EFIAPI\r
ce821dff 273UsbSetIdleRequest (\r
274 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
275 IN UINT8 Interface,\r
276 IN UINT8 ReportId,\r
277 IN UINT8 Duration\r
278 )\r
279{\r
280 UINT32 Status;\r
281 EFI_STATUS Result;\r
282 EFI_USB_DEVICE_REQUEST Request;\r
283\r
d5954c61 284 ASSERT (UsbIo != NULL);\r
ce821dff 285 //\r
286 // Fill Device request packet\r
287 //\r
11ceade4 288 Request.RequestType = USB_HID_CLASS_SET_REQ_TYPE;\r
ce821dff 289 Request.Request = EFI_USB_SET_IDLE_REQUEST;\r
290 Request.Value = (UINT16) ((Duration << 8) | ReportId);\r
291 Request.Index = Interface;\r
292 Request.Length = 0;\r
293\r
294 Result = UsbIo->UsbControlTransfer (\r
295 UsbIo,\r
296 &Request,\r
297 EfiUsbNoData,\r
298 TIMEOUT_VALUE,\r
299 NULL,\r
300 0,\r
301 &Status\r
302 );\r
303 return Result;\r
304}\r
305\r
306\r
307/**\r
d5954c61 308 Get the idle rate of the specified USB HID report.\r
309\r
310 Submit a USB get HID report idle request for the USB device specified by UsbIo,\r
311 Interface, and ReportId, and return the ide rate in Duration.\r
312 If UsbIo is NULL, then ASSERT().\r
313 If Duration is NULL, then ASSERT().\r
ce821dff 314\r
d5954c61 315 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
316 @param Interface The index of the report interface on the USB target.\r
317 @param ReportId The identifier of the report to retrieve.\r
318 @param Duration A pointer to the idle rate retrieved from the specified USB target.\r
ce821dff 319\r
d5954c61 320 @retval EFI_SUCCESS The request executed successfully.\r
321 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
322 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
ce821dff 323\r
324**/\r
325EFI_STATUS\r
373b5cf9 326EFIAPI\r
ce821dff 327UsbGetIdleRequest (\r
328 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
329 IN UINT8 Interface,\r
330 IN UINT8 ReportId,\r
331 OUT UINT8 *Duration\r
332 )\r
333{\r
334 UINT32 Status;\r
335 EFI_STATUS Result;\r
336 EFI_USB_DEVICE_REQUEST Request;\r
8069d49e 337 \r
d5954c61 338 ASSERT (UsbIo != NULL);\r
339 ASSERT (Duration != NULL);\r
ce821dff 340 //\r
341 // Fill Device request packet\r
342 //\r
11ceade4 343 Request.RequestType = USB_HID_CLASS_GET_REQ_TYPE;\r
ce821dff 344 Request.Request = EFI_USB_GET_IDLE_REQUEST;\r
345 Request.Value = ReportId;\r
346 Request.Index = Interface;\r
347 Request.Length = 1;\r
348\r
349 Result = UsbIo->UsbControlTransfer (\r
350 UsbIo,\r
351 &Request,\r
352 EfiUsbDataIn,\r
353 TIMEOUT_VALUE,\r
354 Duration,\r
355 1,\r
356 &Status\r
357 );\r
358\r
359 return Result;\r
360}\r
361\r
362\r
373b5cf9 363\r
ce821dff 364/**\r
d5954c61 365 Set the report descriptor of the specified USB HID interface.\r
366\r
367 Submit a USB set HID report request for the USB device specified by UsbIo,\r
368 Interface, ReportId, and ReportType, and set the report descriptor using the\r
369 buffer specified by ReportLength and Report.\r
370 If UsbIo is NULL, then ASSERT().\r
371 If Report is NULL, then ASSERT().\r
ce821dff 372\r
d5954c61 373 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
374 @param Interface The index of the report interface on the USB target.\r
375 @param ReportId The identifier of the report to retrieve.\r
376 @param ReportType The type of report to retrieve.\r
377 @param ReportLength The size, in bytes, of Report.\r
378 @param Report A pointer to the report descriptor buffer to set.\r
ce821dff 379\r
d5954c61 380 @retval EFI_SUCCESS The request executed successfully.\r
381 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
382 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
ce821dff 383\r
384**/\r
385EFI_STATUS\r
373b5cf9 386EFIAPI\r
ce821dff 387UsbSetReportRequest (\r
388 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
389 IN UINT8 Interface,\r
390 IN UINT8 ReportId,\r
391 IN UINT8 ReportType,\r
d5954c61 392 IN UINT16 ReportLength,\r
ce821dff 393 IN UINT8 *Report\r
394 )\r
395{\r
396 UINT32 Status;\r
397 EFI_STATUS Result;\r
398 EFI_USB_DEVICE_REQUEST Request;\r
399\r
d5954c61 400 ASSERT (UsbIo != NULL);\r
401 ASSERT (Report != NULL);\r
402\r
ce821dff 403 //\r
404 // Fill Device request packet\r
405 //\r
11ceade4 406 Request.RequestType = USB_HID_CLASS_SET_REQ_TYPE;\r
ce821dff 407 Request.Request = EFI_USB_SET_REPORT_REQUEST;\r
408 Request.Value = (UINT16) ((ReportType << 8) | ReportId);\r
409 Request.Index = Interface;\r
d5954c61 410 Request.Length = ReportLength;\r
ce821dff 411\r
412 Result = UsbIo->UsbControlTransfer (\r
413 UsbIo,\r
414 &Request,\r
415 EfiUsbDataOut,\r
416 TIMEOUT_VALUE,\r
417 Report,\r
d5954c61 418 ReportLength,\r
ce821dff 419 &Status\r
420 );\r
421\r
422 return Result;\r
423}\r
424\r
425\r
426/**\r
d5954c61 427 Get the report descriptor of the specified USB HID interface.\r
428\r
429 Submit a USB get HID report request for the USB device specified by UsbIo,\r
430 Interface, ReportId, and ReportType, and return the report in the buffer\r
431 specified by Report.\r
432 If UsbIo is NULL, then ASSERT().\r
433 If Report is NULL, then ASSERT().\r
434\r
435 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
436 @param Interface The index of the report interface on the USB target.\r
437 @param ReportId The identifier of the report to retrieve.\r
438 @param ReportType The type of report to retrieve.\r
439 @param ReportLength The size, in bytes, of Report.\r
440 @param Report A pointer to the buffer to store the report descriptor.\r
441\r
442 @retval EFI_SUCCESS The request executed successfully.\r
443 @retval EFI_OUT_OF_RESOURCES The request could not be completed because the\r
444 buffer specifed by ReportLength and Report is not\r
445 large enough to hold the result of the request.\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
ce821dff 448\r
449**/\r
450EFI_STATUS\r
373b5cf9 451EFIAPI\r
ce821dff 452UsbGetReportRequest (\r
453 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
454 IN UINT8 Interface,\r
455 IN UINT8 ReportId,\r
456 IN UINT8 ReportType,\r
457 IN UINT16 ReportLen,\r
458 IN UINT8 *Report\r
459 )\r
460{\r
461 UINT32 Status;\r
462 EFI_STATUS Result;\r
463 EFI_USB_DEVICE_REQUEST Request;\r
464\r
d5954c61 465 ASSERT (UsbIo != NULL);\r
466 ASSERT (Report != NULL);\r
467\r
ce821dff 468 //\r
469 // Fill Device request packet\r
470 //\r
11ceade4 471 Request.RequestType = USB_HID_CLASS_GET_REQ_TYPE;\r
ce821dff 472 Request.Request = EFI_USB_GET_REPORT_REQUEST;\r
473 Request.Value = (UINT16) ((ReportType << 8) | ReportId);\r
474 Request.Index = Interface;\r
475 Request.Length = ReportLen;\r
476\r
477 Result = UsbIo->UsbControlTransfer (\r
478 UsbIo,\r
479 &Request,\r
480 EfiUsbDataIn,\r
481 TIMEOUT_VALUE,\r
482 Report,\r
483 ReportLen,\r
484 &Status\r
485 );\r
486\r
487 return Result;\r
488}\r