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