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