Add BaseCustomDecompressLibNull, DxeDebugLibSerialPort and UefiUsbLib library instanc...
[mirror_edk2.git] / MdePkg / Library / UefiUsbLib / hid.c
CommitLineData
7bc232b2
LG
1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12 Module Name:\r
13\r
14 hid.c\r
15\r
16 Abstract:\r
17\r
18 HID class request\r
19\r
20 Revision History\r
21\r
22--*/\r
23\r
24//\r
25// Include common header file for this module.\r
26//\r
27#include "CommonHeader.h"\r
28\r
29//\r
30// Function to get HID descriptor\r
31//\r
32EFI_STATUS\r
33UsbGetHidDescriptor (\r
34 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
35 IN UINT8 InterfaceNum,\r
36 OUT EFI_USB_HID_DESCRIPTOR *HidDescriptor\r
37 )\r
38/*++\r
39\r
40 Routine Description:\r
41 Get Hid Descriptor\r
42\r
43 Arguments:\r
44 UsbIo - EFI_USB_IO_PROTOCOL\r
45 InterfaceNum - Hid interface number\r
46 HidDescriptor - Caller allocated buffer to store Usb hid descriptor\r
47 if successfully returned.\r
48\r
49 Returns:\r
50 EFI_SUCCESS\r
51 EFI_DEVICE_ERROR\r
52 EFI_TIMEOUT\r
53\r
54--*/\r
55{\r
56 UINT32 Status;\r
57 EFI_STATUS Result;\r
58 EFI_USB_DEVICE_REQUEST Request;\r
59\r
60 Request.RequestType = 0x81;\r
61 Request.Request = 0x06;\r
62 Request.Value = (UINT16) (0x21 << 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// Function to get Report Class descriptor\r
81//\r
82EFI_STATUS\r
83UsbGetReportDescriptor (\r
84 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
85 IN UINT8 InterfaceNum,\r
86 IN UINT16 DescriptorSize,\r
87 OUT UINT8 *DescriptorBuffer\r
88 )\r
89/*++\r
90\r
91 Routine Description:\r
92 get Report Class descriptor\r
93\r
94 Arguments:\r
95 UsbIo - EFI_USB_IO_PROTOCOL.\r
96 InterfaceNum - Report interface number.\r
97 DescriptorSize - Length of DescriptorBuffer.\r
98 DescriptorBuffer - Caller allocated buffer to store Usb report descriptor\r
99 if successfully returned.\r
100\r
101 Returns:\r
102 EFI_SUCCESS\r
103 EFI_DEVICE_ERROR\r
104 EFI_TIMEOUT\r
105\r
106--*/\r
107{\r
108 UINT32 Status;\r
109 EFI_STATUS Result;\r
110 EFI_USB_DEVICE_REQUEST Request;\r
111\r
112 //\r
113 // Fill Device request packet\r
114 //\r
115 Request.RequestType = 0x81;\r
116 Request.Request = 0x06;\r
117 Request.Value = (UINT16) (0x22 << 8);\r
118 Request.Index = InterfaceNum;\r
119 Request.Length = DescriptorSize;\r
120\r
121 Result = UsbIo->UsbControlTransfer (\r
122 UsbIo,\r
123 &Request,\r
124 EfiUsbDataIn,\r
125 TIMEOUT_VALUE,\r
126 DescriptorBuffer,\r
127 DescriptorSize,\r
128 &Status\r
129 );\r
130\r
131 return Result;\r
132\r
133}\r
134//\r
135// Following are HID class request\r
136//\r
137EFI_STATUS\r
138UsbGetProtocolRequest (\r
139 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
140 IN UINT8 Interface,\r
141 IN UINT8 *Protocol\r
142 )\r
143/*++\r
144\r
145 Routine Description:\r
146 Get Hid Protocol Request\r
147\r
148 Arguments:\r
149 UsbIo - EFI_USB_IO_PROTOCOL\r
150 Interface - Which interface the caller wants to get protocol\r
151 Protocol - Protocol value returned.\r
152\r
153 Returns:\r
154 EFI_SUCCESS\r
155 EFI_DEVICE_ERROR\r
156 EFI_TIMEOUT\r
157\r
158--*/\r
159{\r
160 UINT32 Status;\r
161 EFI_STATUS Result;\r
162 EFI_USB_DEVICE_REQUEST Request;\r
163\r
164 //\r
165 // Fill Device request packet\r
166 //\r
167 Request.RequestType = 0xa1;\r
168 //\r
169 // 10100001b;\r
170 //\r
171 Request.Request = EFI_USB_GET_PROTOCOL_REQUEST;\r
172 Request.Value = 0;\r
173 Request.Index = Interface;\r
174 Request.Length = 1;\r
175\r
176 Result = UsbIo->UsbControlTransfer (\r
177 UsbIo,\r
178 &Request,\r
179 EfiUsbDataIn,\r
180 TIMEOUT_VALUE,\r
181 Protocol,\r
182 sizeof (UINT8),\r
183 &Status\r
184 );\r
185\r
186 return Result;\r
187}\r
188\r
189\r
190EFI_STATUS\r
191UsbSetProtocolRequest (\r
192 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
193 IN UINT8 Interface,\r
194 IN UINT8 Protocol\r
195 )\r
196/*++\r
197\r
198 Routine Description:\r
199 Set Hid Protocol Request\r
200\r
201 Arguments:\r
202 UsbIo - EFI_USB_IO_PROTOCOL\r
203 Interface - Which interface the caller wants to set protocol\r
204 Protocol - Protocol value the caller wants to set.\r
205\r
206 Returns:\r
207 EFI_SUCCESS\r
208 EFI_DEVICE_ERROR\r
209 EFI_TIMEOUT\r
210\r
211--*/\r
212{\r
213 UINT32 Status;\r
214 EFI_STATUS Result;\r
215 EFI_USB_DEVICE_REQUEST Request;\r
216\r
217 //\r
218 // Fill Device request packet\r
219 //\r
220 Request.RequestType = 0x21;\r
221 //\r
222 // 00100001b;\r
223 //\r
224 Request.Request = EFI_USB_SET_PROTOCOL_REQUEST;\r
225 Request.Value = Protocol;\r
226 Request.Index = Interface;\r
227 Request.Length = 0;\r
228\r
229 Result = UsbIo->UsbControlTransfer (\r
230 UsbIo,\r
231 &Request,\r
232 EfiUsbNoData,\r
233 TIMEOUT_VALUE,\r
234 NULL,\r
235 0,\r
236 &Status\r
237 );\r
238 return Result;\r
239}\r
240\r
241\r
242EFI_STATUS\r
243UsbSetIdleRequest (\r
244 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
245 IN UINT8 Interface,\r
246 IN UINT8 ReportId,\r
247 IN UINT8 Duration\r
248 )\r
249/*++\r
250\r
251 Routine Description:\r
252 Set Idel request.\r
253\r
254 Arguments:\r
255 UsbIo - EFI_USB_IO_PROTOCOL\r
256 Interface - Which interface the caller wants to set.\r
257 ReportId - Which report the caller wants to set.\r
258 Duration - Idle rate the caller wants to set.\r
259\r
260 Returns:\r
261 EFI_SUCCESS\r
262 EFI_DEVICE_ERROR\r
263 EFI_TIMEOUT\r
264\r
265--*/\r
266{\r
267 UINT32 Status;\r
268 EFI_STATUS Result;\r
269 EFI_USB_DEVICE_REQUEST Request;\r
270\r
271 //\r
272 // Fill Device request packet\r
273 //\r
274 Request.RequestType = 0x21;\r
275 //\r
276 // 00100001b;\r
277 //\r
278 Request.Request = EFI_USB_SET_IDLE_REQUEST;\r
279 Request.Value = (UINT16) ((Duration << 8) | ReportId);\r
280 Request.Index = Interface;\r
281 Request.Length = 0;\r
282\r
283 Result = UsbIo->UsbControlTransfer (\r
284 UsbIo,\r
285 &Request,\r
286 EfiUsbNoData,\r
287 TIMEOUT_VALUE,\r
288 NULL,\r
289 0,\r
290 &Status\r
291 );\r
292 return Result;\r
293}\r
294\r
295EFI_STATUS\r
296UsbGetIdleRequest (\r
297 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
298 IN UINT8 Interface,\r
299 IN UINT8 ReportId,\r
300 OUT UINT8 *Duration\r
301 )\r
302/*++\r
303\r
304 Routine Description:\r
305 Get Idel request.\r
306\r
307 Arguments:\r
308 UsbIo - EFI_USB_IO_PROTOCOL\r
309 Interface - Which interface the caller wants to get.\r
310 ReportId - Which report the caller wants to get.\r
311 Duration - Idle rate the caller wants to get.\r
312\r
313 Returns:\r
314 EFI_SUCCESS\r
315 EFI_DEVICE_ERROR\r
316 EFI_TIMEOUT\r
317\r
318--*/\r
319{\r
320 UINT32 Status;\r
321 EFI_STATUS Result;\r
322 EFI_USB_DEVICE_REQUEST Request;\r
323\r
324 //\r
325 // Fill Device request packet\r
326 //\r
327 Request.RequestType = 0xa1;\r
328 //\r
329 // 10100001b;\r
330 //\r
331 Request.Request = EFI_USB_GET_IDLE_REQUEST;\r
332 Request.Value = ReportId;\r
333 Request.Index = Interface;\r
334 Request.Length = 1;\r
335\r
336 Result = UsbIo->UsbControlTransfer (\r
337 UsbIo,\r
338 &Request,\r
339 EfiUsbDataIn,\r
340 TIMEOUT_VALUE,\r
341 Duration,\r
342 1,\r
343 &Status\r
344 );\r
345\r
346 return Result;\r
347}\r
348\r
349\r
350EFI_STATUS\r
351UsbSetReportRequest (\r
352 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
353 IN UINT8 Interface,\r
354 IN UINT8 ReportId,\r
355 IN UINT8 ReportType,\r
356 IN UINT16 ReportLen,\r
357 IN UINT8 *Report\r
358 )\r
359/*++\r
360\r
361 Routine Description:\r
362 Hid Set Report request.\r
363\r
364 Arguments:\r
365 UsbIo - EFI_USB_IO_PROTOCOL\r
366 Interface - Which interface the caller wants to set.\r
367 ReportId - Which report the caller wants to set.\r
368 ReportType - Type of report.\r
369 ReportLen - Length of report descriptor.\r
370 Report - Report Descriptor buffer.\r
371\r
372 Returns:\r
373 EFI_SUCCESS\r
374 EFI_DEVICE_ERROR\r
375 EFI_TIMEOUT\r
376\r
377--*/\r
378{\r
379 UINT32 Status;\r
380 EFI_STATUS Result;\r
381 EFI_USB_DEVICE_REQUEST Request;\r
382\r
383 //\r
384 // Fill Device request packet\r
385 //\r
386 Request.RequestType = 0x21;\r
387 //\r
388 // 00100001b;\r
389 //\r
390 Request.Request = EFI_USB_SET_REPORT_REQUEST;\r
391 Request.Value = (UINT16) ((ReportType << 8) | ReportId);\r
392 Request.Index = Interface;\r
393 Request.Length = ReportLen;\r
394\r
395 Result = UsbIo->UsbControlTransfer (\r
396 UsbIo,\r
397 &Request,\r
398 EfiUsbDataOut,\r
399 TIMEOUT_VALUE,\r
400 Report,\r
401 ReportLen,\r
402 &Status\r
403 );\r
404\r
405 return Result;\r
406}\r
407\r
408EFI_STATUS\r
409UsbGetReportRequest (\r
410 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
411 IN UINT8 Interface,\r
412 IN UINT8 ReportId,\r
413 IN UINT8 ReportType,\r
414 IN UINT16 ReportLen,\r
415 IN UINT8 *Report\r
416 )\r
417/*++\r
418\r
419 Routine Description:\r
420 Hid Set Report request.\r
421\r
422 Arguments:\r
423 UsbIo - EFI_USB_IO_PROTOCOL\r
424 Interface - Which interface the caller wants to set.\r
425 ReportId - Which report the caller wants to set.\r
426 ReportType - Type of report.\r
427 ReportLen - Length of report descriptor.\r
428 Report - Caller allocated buffer to store Report Descriptor.\r
429\r
430 Returns:\r
431 EFI_SUCCESS\r
432 EFI_DEVICE_ERROR\r
433 EFI_TIMEOUT\r
434\r
435--*/\r
436{\r
437 UINT32 Status;\r
438 EFI_STATUS Result;\r
439 EFI_USB_DEVICE_REQUEST Request;\r
440\r
441 //\r
442 // Fill Device request packet\r
443 //\r
444 Request.RequestType = 0xa1;\r
445 //\r
446 // 10100001b;\r
447 //\r
448 Request.Request = EFI_USB_GET_REPORT_REQUEST;\r
449 Request.Value = (UINT16) ((ReportType << 8) | ReportId);\r
450 Request.Index = Interface;\r
451 Request.Length = ReportLen;\r
452\r
453 Result = UsbIo->UsbControlTransfer (\r
454 UsbIo,\r
455 &Request,\r
456 EfiUsbDataIn,\r
457 TIMEOUT_VALUE,\r
458 Report,\r
459 ReportLen,\r
460 &Status\r
461 );\r
462\r
463 return Result;\r
464}\r