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