]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | \r | |
3 | The library provides USB HID Class standard and specific requests defined\r | |
4 | in USB HID Firmware Specification 7 section : Requests.\r | |
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 | |
14 | \r | |
15 | **/\r | |
16 | \r | |
17 | #include "UefiUsbLibInternal.h"\r | |
18 | \r | |
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 | |
31 | \r | |
32 | /**\r | |
33 | Get the descriptor of the specified USB HID interface.\r | |
34 | \r | |
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 | |
39 | \r | |
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 | |
49 | \r | |
50 | **/\r | |
51 | EFI_STATUS\r | |
52 | EFIAPI\r | |
53 | UsbGetHidDescriptor (\r | |
54 | IN EFI_USB_IO_PROTOCOL *UsbIo,\r | |
55 | IN UINT8 Interface,\r | |
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 | |
62 | \r | |
63 | ASSERT(UsbIo != NULL);\r | |
64 | ASSERT(HidDescriptor != NULL);\r | |
65 | \r | |
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 | |
69 | Request.Index = Interface;\r | |
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 | |
85 | \r | |
86 | /**\r | |
87 | Get the report descriptor of the specified USB HID interface.\r | |
88 | \r | |
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 | |
93 | \r | |
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 specified 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 | |
105 | \r | |
106 | **/\r | |
107 | EFI_STATUS\r | |
108 | EFIAPI\r | |
109 | UsbGetReportDescriptor (\r | |
110 | IN EFI_USB_IO_PROTOCOL *UsbIo,\r | |
111 | IN UINT8 Interface,\r | |
112 | IN UINT16 DescriptorLength,\r | |
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 | |
120 | ASSERT (UsbIo != NULL);\r | |
121 | ASSERT (DescriptorBuffer != NULL);\r | |
122 | \r | |
123 | //\r | |
124 | // Fill Device request packet\r | |
125 | //\r | |
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 | |
129 | Request.Index = Interface;\r | |
130 | Request.Length = DescriptorLength;\r | |
131 | \r | |
132 | Result = UsbIo->UsbControlTransfer (\r | |
133 | UsbIo,\r | |
134 | &Request,\r | |
135 | EfiUsbDataIn,\r | |
136 | TIMEOUT_VALUE,\r | |
137 | DescriptorBuffer,\r | |
138 | DescriptorLength,\r | |
139 | &Status\r | |
140 | );\r | |
141 | \r | |
142 | return Result;\r | |
143 | \r | |
144 | }\r | |
145 | \r | |
146 | /**\r | |
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 | |
153 | \r | |
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 | |
157 | \r | |
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 | |
161 | \r | |
162 | **/\r | |
163 | EFI_STATUS\r | |
164 | EFIAPI\r | |
165 | UsbGetProtocolRequest (\r | |
166 | IN EFI_USB_IO_PROTOCOL *UsbIo,\r | |
167 | IN UINT8 Interface,\r | |
168 | OUT 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 | |
175 | ASSERT (UsbIo != NULL);\r | |
176 | ASSERT (Protocol != NULL);\r | |
177 | \r | |
178 | //\r | |
179 | // Fill Device request packet\r | |
180 | //\r | |
181 | Request.RequestType = USB_HID_CLASS_GET_REQ_TYPE;\r | |
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 | |
201 | \r | |
202 | /**\r | |
203 | Set the HID protocol of the specified USB HID interface.\r | |
204 | \r | |
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 | |
208 | \r | |
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 | |
216 | \r | |
217 | **/\r | |
218 | EFI_STATUS\r | |
219 | EFIAPI\r | |
220 | UsbSetProtocolRequest (\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 | |
230 | ASSERT (UsbIo != NULL);\r | |
231 | \r | |
232 | //\r | |
233 | // Fill Device request packet\r | |
234 | //\r | |
235 | Request.RequestType = USB_HID_CLASS_SET_REQ_TYPE;\r | |
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 | |
254 | /**\r | |
255 | Set the idle rate of the specified USB HID report.\r | |
256 | \r | |
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 | |
260 | \r | |
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 | |
269 | \r | |
270 | **/\r | |
271 | EFI_STATUS\r | |
272 | EFIAPI\r | |
273 | UsbSetIdleRequest (\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 | |
284 | ASSERT (UsbIo != NULL);\r | |
285 | //\r | |
286 | // Fill Device request packet\r | |
287 | //\r | |
288 | Request.RequestType = USB_HID_CLASS_SET_REQ_TYPE;\r | |
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 | |
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 | |
314 | \r | |
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 | |
319 | \r | |
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 | |
323 | \r | |
324 | **/\r | |
325 | EFI_STATUS\r | |
326 | EFIAPI\r | |
327 | UsbGetIdleRequest (\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 | |
337 | \r | |
338 | ASSERT (UsbIo != NULL);\r | |
339 | ASSERT (Duration != NULL);\r | |
340 | //\r | |
341 | // Fill Device request packet\r | |
342 | //\r | |
343 | Request.RequestType = USB_HID_CLASS_GET_REQ_TYPE;\r | |
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 | |
363 | \r | |
364 | /**\r | |
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 | |
372 | \r | |
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 | |
379 | \r | |
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 | |
383 | \r | |
384 | **/\r | |
385 | EFI_STATUS\r | |
386 | EFIAPI\r | |
387 | UsbSetReportRequest (\r | |
388 | IN EFI_USB_IO_PROTOCOL *UsbIo,\r | |
389 | IN UINT8 Interface,\r | |
390 | IN UINT8 ReportId,\r | |
391 | IN UINT8 ReportType,\r | |
392 | IN UINT16 ReportLen,\r | |
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 | |
400 | ASSERT (UsbIo != NULL);\r | |
401 | ASSERT (Report != NULL);\r | |
402 | \r | |
403 | //\r | |
404 | // Fill Device request packet\r | |
405 | //\r | |
406 | Request.RequestType = USB_HID_CLASS_SET_REQ_TYPE;\r | |
407 | Request.Request = EFI_USB_SET_REPORT_REQUEST;\r | |
408 | Request.Value = (UINT16) ((ReportType << 8) | ReportId);\r | |
409 | Request.Index = Interface;\r | |
410 | Request.Length = ReportLen;\r | |
411 | \r | |
412 | Result = UsbIo->UsbControlTransfer (\r | |
413 | UsbIo,\r | |
414 | &Request,\r | |
415 | EfiUsbDataOut,\r | |
416 | TIMEOUT_VALUE,\r | |
417 | Report,\r | |
418 | ReportLen,\r | |
419 | &Status\r | |
420 | );\r | |
421 | \r | |
422 | return Result;\r | |
423 | }\r | |
424 | \r | |
425 | \r | |
426 | /**\r | |
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 | |
448 | \r | |
449 | **/\r | |
450 | EFI_STATUS\r | |
451 | EFIAPI\r | |
452 | UsbGetReportRequest (\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 | OUT 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 | |
465 | ASSERT (UsbIo != NULL);\r | |
466 | ASSERT (Report != NULL);\r | |
467 | \r | |
468 | //\r | |
469 | // Fill Device request packet\r | |
470 | //\r | |
471 | Request.RequestType = USB_HID_CLASS_GET_REQ_TYPE;\r | |
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 |