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