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