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