]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdePkg/Library/UefiUsbLib/Hid.c
Use #include <XXX.h> for public include files.
[mirror_edk2.git] / MdePkg / Library / UefiUsbLib / Hid.c
... / ...
CommitLineData
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 Hid Descriptor.\r
34\r
35 @param UsbIo EFI_USB_IO_PROTOCOL.\r
36 @param InterfaceNum Hid interface number.\r
37 @param HidDescriptor Caller allocated buffer to store Usb hid descriptor if\r
38 successfully returned.\r
39\r
40 @return Status of getting HID descriptor through USB I/O\r
41 protocol's UsbControlTransfer().\r
42\r
43**/\r
44EFI_STATUS\r
45EFIAPI\r
46UsbGetHidDescriptor (\r
47 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
48 IN UINT8 InterfaceNum,\r
49 OUT EFI_USB_HID_DESCRIPTOR *HidDescriptor\r
50 )\r
51{\r
52 UINT32 Status;\r
53 EFI_STATUS Result;\r
54 EFI_USB_DEVICE_REQUEST Request;\r
55 \r
56 if (UsbIo == NULL) {\r
57 return EFI_INVALID_PARAMETER;\r
58 }\r
59\r
60 Request.RequestType = USB_HID_GET_DESCRIPTOR_REQ_TYPE;\r
61 Request.Request = USB_REQ_GET_DESCRIPTOR;\r
62 Request.Value = (UINT16) (USB_DESC_TYPE_HID << 8);\r
63 Request.Index = InterfaceNum;\r
64 Request.Length = sizeof (EFI_USB_HID_DESCRIPTOR);\r
65\r
66 Result = UsbIo->UsbControlTransfer (\r
67 UsbIo,\r
68 &Request,\r
69 EfiUsbDataIn,\r
70 TIMEOUT_VALUE,\r
71 HidDescriptor,\r
72 sizeof (EFI_USB_HID_DESCRIPTOR),\r
73 &Status\r
74 );\r
75\r
76 return Result;\r
77\r
78}\r
79\r
80/**\r
81 Get Report Class descriptor.\r
82\r
83 @param UsbIo EFI_USB_IO_PROTOCOL.\r
84 @param InterfaceNum Report interface number.\r
85 @param DescriptorSize Length of DescriptorBuffer.\r
86 @param DescriptorBuffer Caller allocated buffer to store Usb report descriptor\r
87 if successfully returned.\r
88\r
89 @return Status of getting Report Class descriptor through USB\r
90 I/O protocol's UsbControlTransfer().\r
91\r
92**/\r
93EFI_STATUS\r
94EFIAPI\r
95UsbGetReportDescriptor (\r
96 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
97 IN UINT8 InterfaceNum,\r
98 IN UINT16 DescriptorSize,\r
99 OUT UINT8 *DescriptorBuffer\r
100 )\r
101{\r
102 UINT32 Status;\r
103 EFI_STATUS Result;\r
104 EFI_USB_DEVICE_REQUEST Request;\r
105\r
106 if (UsbIo == NULL) {\r
107 return EFI_INVALID_PARAMETER;\r
108 }\r
109 //\r
110 // Fill Device request packet\r
111 //\r
112 Request.RequestType = USB_HID_GET_DESCRIPTOR_REQ_TYPE;\r
113 Request.Request = USB_REQ_GET_DESCRIPTOR;\r
114 Request.Value = (UINT16) (USB_DESC_TYPE_REPORT << 8);\r
115 Request.Index = InterfaceNum;\r
116 Request.Length = DescriptorSize;\r
117\r
118 Result = UsbIo->UsbControlTransfer (\r
119 UsbIo,\r
120 &Request,\r
121 EfiUsbDataIn,\r
122 TIMEOUT_VALUE,\r
123 DescriptorBuffer,\r
124 DescriptorSize,\r
125 &Status\r
126 );\r
127\r
128 return Result;\r
129\r
130}\r
131\r
132/**\r
133 Get Hid Protocol Request\r
134\r
135 @param UsbIo EFI_USB_IO_PROTOCOL.\r
136 @param Interface Which interface the caller wants to get protocol\r
137 @param Protocol Protocol value returned.\r
138\r
139 @return Status of getting Protocol Request through USB I/O\r
140 protocol's UsbControlTransfer().\r
141\r
142**/\r
143EFI_STATUS\r
144EFIAPI\r
145UsbGetProtocolRequest (\r
146 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
147 IN UINT8 Interface,\r
148 IN UINT8 *Protocol\r
149 )\r
150{\r
151 UINT32 Status;\r
152 EFI_STATUS Result;\r
153 EFI_USB_DEVICE_REQUEST Request;\r
154\r
155 if (UsbIo == NULL) {\r
156 return EFI_INVALID_PARAMETER;\r
157 }\r
158 //\r
159 // Fill Device request packet\r
160 //\r
161 Request.RequestType = USB_HID_CLASS_GET_REQ_TYPE;\r
162 Request.Request = EFI_USB_GET_PROTOCOL_REQUEST;\r
163 Request.Value = 0;\r
164 Request.Index = Interface;\r
165 Request.Length = 1;\r
166\r
167 Result = UsbIo->UsbControlTransfer (\r
168 UsbIo,\r
169 &Request,\r
170 EfiUsbDataIn,\r
171 TIMEOUT_VALUE,\r
172 Protocol,\r
173 sizeof (UINT8),\r
174 &Status\r
175 );\r
176\r
177 return Result;\r
178}\r
179\r
180\r
181\r
182/**\r
183 Set Hid Protocol Request.\r
184\r
185 @param UsbIo EFI_USB_IO_PROTOCOL.\r
186 @param Interface Which interface the caller wants to\r
187 set protocol.\r
188 @param Protocol Protocol value the caller wants to set.\r
189\r
190 @return Status of setting Protocol Request through USB I/O\r
191 protocol's UsbControlTransfer().\r
192\r
193**/\r
194EFI_STATUS\r
195EFIAPI\r
196UsbSetProtocolRequest (\r
197 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
198 IN UINT8 Interface,\r
199 IN UINT8 Protocol\r
200 )\r
201{\r
202 UINT32 Status;\r
203 EFI_STATUS Result;\r
204 EFI_USB_DEVICE_REQUEST Request;\r
205\r
206 if (UsbIo == NULL) {\r
207 return EFI_INVALID_PARAMETER;\r
208 }\r
209 //\r
210 // Fill Device request packet\r
211 //\r
212 Request.RequestType = USB_HID_CLASS_SET_REQ_TYPE;\r
213 Request.Request = EFI_USB_SET_PROTOCOL_REQUEST;\r
214 Request.Value = Protocol;\r
215 Request.Index = Interface;\r
216 Request.Length = 0;\r
217\r
218 Result = UsbIo->UsbControlTransfer (\r
219 UsbIo,\r
220 &Request,\r
221 EfiUsbNoData,\r
222 TIMEOUT_VALUE,\r
223 NULL,\r
224 0,\r
225 &Status\r
226 );\r
227 return Result;\r
228}\r
229\r
230\r
231/**\r
232 Set Idel request.\r
233\r
234 @param UsbIo EFI_USB_IO_PROTOCOL.\r
235 @param Interface Which interface the caller wants to set.\r
236 @param ReportId Which report the caller wants to set.\r
237 @param Duration Idle rate the caller wants to set.\r
238\r
239 @return Status of setting IDLE Request through USB I/O\r
240 protocol's UsbControlTransfer().\r
241\r
242**/\r
243EFI_STATUS\r
244EFIAPI\r
245UsbSetIdleRequest (\r
246 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
247 IN UINT8 Interface,\r
248 IN UINT8 ReportId,\r
249 IN UINT8 Duration\r
250 )\r
251{\r
252 UINT32 Status;\r
253 EFI_STATUS Result;\r
254 EFI_USB_DEVICE_REQUEST Request;\r
255\r
256 if (UsbIo == NULL) {\r
257 return EFI_INVALID_PARAMETER;\r
258 }\r
259 //\r
260 // Fill Device request packet\r
261 //\r
262 Request.RequestType = USB_HID_CLASS_SET_REQ_TYPE;\r
263 Request.Request = EFI_USB_SET_IDLE_REQUEST;\r
264 Request.Value = (UINT16) ((Duration << 8) | ReportId);\r
265 Request.Index = Interface;\r
266 Request.Length = 0;\r
267\r
268 Result = UsbIo->UsbControlTransfer (\r
269 UsbIo,\r
270 &Request,\r
271 EfiUsbNoData,\r
272 TIMEOUT_VALUE,\r
273 NULL,\r
274 0,\r
275 &Status\r
276 );\r
277 return Result;\r
278}\r
279\r
280\r
281/**\r
282 Get Idel request.\r
283\r
284 @param UsbIo EFI_USB_IO_PROTOCOL.\r
285 @param Interface Which interface the caller wants to get.\r
286 @param ReportId Which report the caller wants to get.\r
287 @param Duration Idle rate the caller wants to get.\r
288\r
289 @return Status of getting IDLE Request through USB I/O\r
290 protocol's UsbControlTransfer().\r
291\r
292**/\r
293EFI_STATUS\r
294EFIAPI\r
295UsbGetIdleRequest (\r
296 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
297 IN UINT8 Interface,\r
298 IN UINT8 ReportId,\r
299 OUT UINT8 *Duration\r
300 )\r
301{\r
302 UINT32 Status;\r
303 EFI_STATUS Result;\r
304 EFI_USB_DEVICE_REQUEST Request;\r
305 \r
306 if (UsbIo == NULL) {\r
307 return EFI_INVALID_PARAMETER;\r
308 }\r
309 //\r
310 // Fill Device request packet\r
311 //\r
312 Request.RequestType = USB_HID_CLASS_GET_REQ_TYPE;\r
313 Request.Request = EFI_USB_GET_IDLE_REQUEST;\r
314 Request.Value = ReportId;\r
315 Request.Index = Interface;\r
316 Request.Length = 1;\r
317\r
318 Result = UsbIo->UsbControlTransfer (\r
319 UsbIo,\r
320 &Request,\r
321 EfiUsbDataIn,\r
322 TIMEOUT_VALUE,\r
323 Duration,\r
324 1,\r
325 &Status\r
326 );\r
327\r
328 return Result;\r
329}\r
330\r
331\r
332\r
333/**\r
334 Hid Set Report request.\r
335\r
336 @param UsbIo EFI_USB_IO_PROTOCOL.\r
337 @param Interface Which interface the caller wants to set.\r
338 @param ReportId Which report the caller wants to set.\r
339 @param ReportType Type of report.\r
340 @param ReportLen Length of report descriptor.\r
341 @param Report Report Descriptor buffer.\r
342\r
343 @return Status of setting Report Request through USB I/O\r
344 protocol's UsbControlTransfer().\r
345\r
346**/\r
347EFI_STATUS\r
348EFIAPI\r
349UsbSetReportRequest (\r
350 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
351 IN UINT8 Interface,\r
352 IN UINT8 ReportId,\r
353 IN UINT8 ReportType,\r
354 IN UINT16 ReportLen,\r
355 IN UINT8 *Report\r
356 )\r
357{\r
358 UINT32 Status;\r
359 EFI_STATUS Result;\r
360 EFI_USB_DEVICE_REQUEST Request;\r
361\r
362 if (UsbIo == NULL) {\r
363 return EFI_INVALID_PARAMETER;\r
364 }\r
365 //\r
366 // Fill Device request packet\r
367 //\r
368 Request.RequestType = USB_HID_CLASS_SET_REQ_TYPE;\r
369 Request.Request = EFI_USB_SET_REPORT_REQUEST;\r
370 Request.Value = (UINT16) ((ReportType << 8) | ReportId);\r
371 Request.Index = Interface;\r
372 Request.Length = ReportLen;\r
373\r
374 Result = UsbIo->UsbControlTransfer (\r
375 UsbIo,\r
376 &Request,\r
377 EfiUsbDataOut,\r
378 TIMEOUT_VALUE,\r
379 Report,\r
380 ReportLen,\r
381 &Status\r
382 );\r
383\r
384 return Result;\r
385}\r
386\r
387\r
388/**\r
389 Hid Set Report request.\r
390\r
391 @param UsbIo EFI_USB_IO_PROTOCOL.\r
392 @param Interface Which interface the caller wants to set.\r
393 @param ReportId Which report the caller wants to set.\r
394 @param ReportType Type of report.\r
395 @param ReportLen Length of report descriptor.\r
396 @param Report Caller allocated buffer to store Report Descriptor.\r
397\r
398 @return Status of getting Report Request through USB I/O\r
399 protocol's UsbControlTransfer().\r
400\r
401**/\r
402EFI_STATUS\r
403EFIAPI\r
404UsbGetReportRequest (\r
405 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
406 IN UINT8 Interface,\r
407 IN UINT8 ReportId,\r
408 IN UINT8 ReportType,\r
409 IN UINT16 ReportLen,\r
410 IN UINT8 *Report\r
411 )\r
412{\r
413 UINT32 Status;\r
414 EFI_STATUS Result;\r
415 EFI_USB_DEVICE_REQUEST Request;\r
416\r
417 if (UsbIo == NULL) {\r
418 return EFI_INVALID_PARAMETER;\r
419 }\r
420 //\r
421 // Fill Device request packet\r
422 //\r
423 Request.RequestType = USB_HID_CLASS_GET_REQ_TYPE;\r
424 Request.Request = EFI_USB_GET_REPORT_REQUEST;\r
425 Request.Value = (UINT16) ((ReportType << 8) | ReportId);\r
426 Request.Index = Interface;\r
427 Request.Length = ReportLen;\r
428\r
429 Result = UsbIo->UsbControlTransfer (\r
430 UsbIo,\r
431 &Request,\r
432 EfiUsbDataIn,\r
433 TIMEOUT_VALUE,\r
434 Report,\r
435 ReportLen,\r
436 &Status\r
437 );\r
438\r
439 return Result;\r
440}\r