]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/UefiUsbLib/Hid.c
[Description]
[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 EFI_SUCCESS
28 @return EFI_DEVICE_ERROR
29 @return EFI_TIMEOUT
30
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 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 // Function to get Report Class descriptor
68 //
69
70 /**
71 get Report Class descriptor
72
73 @param UsbIo EFI_USB_IO_PROTOCOL.
74 @param InterfaceNum Report interface number.
75 @param DescriptorSize Length of DescriptorBuffer.
76 @param DescriptorBuffer Caller allocated buffer to store Usb report descriptor
77 if successfully returned.
78
79 @return EFI_SUCCESS
80 @return EFI_DEVICE_ERROR
81 @return EFI_TIMEOUT
82
83 **/
84 EFI_STATUS
85 UsbGetReportDescriptor (
86 IN EFI_USB_IO_PROTOCOL *UsbIo,
87 IN UINT8 InterfaceNum,
88 IN UINT16 DescriptorSize,
89 OUT UINT8 *DescriptorBuffer
90 )
91 {
92 UINT32 Status;
93 EFI_STATUS Result;
94 EFI_USB_DEVICE_REQUEST Request;
95
96 if (UsbIo == NULL) {
97 return EFI_INVALID_PARAMETER;
98 }
99 //
100 // Fill Device request packet
101 //
102 Request.RequestType = 0x81;
103 Request.Request = 0x06;
104 Request.Value = (UINT16) (0x22 << 8);
105 Request.Index = InterfaceNum;
106 Request.Length = DescriptorSize;
107
108 Result = UsbIo->UsbControlTransfer (
109 UsbIo,
110 &Request,
111 EfiUsbDataIn,
112 TIMEOUT_VALUE,
113 DescriptorBuffer,
114 DescriptorSize,
115 &Status
116 );
117
118 return Result;
119
120 }
121 //
122 // Following are HID class request
123 //
124
125 /**
126 Get Hid Protocol Request
127
128 @param UsbIo EFI_USB_IO_PROTOCOL
129 @param Interface Which interface the caller wants to get protocol
130 @param Protocol Protocol value returned.
131
132 @return EFI_SUCCESS
133 @return EFI_DEVICE_ERROR
134 @return EFI_TIMEOUT
135
136 **/
137 EFI_STATUS
138 UsbGetProtocolRequest (
139 IN EFI_USB_IO_PROTOCOL *UsbIo,
140 IN UINT8 Interface,
141 IN UINT8 *Protocol
142 )
143 {
144 UINT32 Status;
145 EFI_STATUS Result;
146 EFI_USB_DEVICE_REQUEST Request;
147
148 if (UsbIo == NULL) {
149 return EFI_INVALID_PARAMETER;
150 }
151 //
152 // Fill Device request packet
153 //
154 Request.RequestType = 0xa1;
155 //
156 // 10100001b;
157 //
158 Request.Request = EFI_USB_GET_PROTOCOL_REQUEST;
159 Request.Value = 0;
160 Request.Index = Interface;
161 Request.Length = 1;
162
163 Result = UsbIo->UsbControlTransfer (
164 UsbIo,
165 &Request,
166 EfiUsbDataIn,
167 TIMEOUT_VALUE,
168 Protocol,
169 sizeof (UINT8),
170 &Status
171 );
172
173 return Result;
174 }
175
176
177
178 /**
179 Set Hid Protocol Request
180
181 @param UsbIo EFI_USB_IO_PROTOCOL
182 @param Interface Which interface the caller wants to set protocol
183 @param Protocol Protocol value the caller wants to set.
184
185 @return EFI_SUCCESS
186 @return EFI_DEVICE_ERROR
187 @return EFI_TIMEOUT
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 UINT32 Status;
198 EFI_STATUS Result;
199 EFI_USB_DEVICE_REQUEST Request;
200
201 if (UsbIo == NULL) {
202 return EFI_INVALID_PARAMETER;
203 }
204 //
205 // Fill Device request packet
206 //
207 Request.RequestType = 0x21;
208 //
209 // 00100001b;
210 //
211 Request.Request = EFI_USB_SET_PROTOCOL_REQUEST;
212 Request.Value = Protocol;
213 Request.Index = Interface;
214 Request.Length = 0;
215
216 Result = UsbIo->UsbControlTransfer (
217 UsbIo,
218 &Request,
219 EfiUsbNoData,
220 TIMEOUT_VALUE,
221 NULL,
222 0,
223 &Status
224 );
225 return Result;
226 }
227
228
229
230 /**
231 Set Idel request.
232
233 @param UsbIo EFI_USB_IO_PROTOCOL
234 @param Interface Which interface the caller wants to set.
235 @param ReportId Which report the caller wants to set.
236 @param Duration Idle rate the caller wants to set.
237
238 @return EFI_SUCCESS
239 @return EFI_DEVICE_ERROR
240 @return EFI_TIMEOUT
241
242 **/
243 EFI_STATUS
244 UsbSetIdleRequest (
245 IN EFI_USB_IO_PROTOCOL *UsbIo,
246 IN UINT8 Interface,
247 IN UINT8 ReportId,
248 IN UINT8 Duration
249 )
250 {
251 UINT32 Status;
252 EFI_STATUS Result;
253 EFI_USB_DEVICE_REQUEST Request;
254
255 if (UsbIo == NULL) {
256 return EFI_INVALID_PARAMETER;
257 }
258 //
259 // Fill Device request packet
260 //
261 Request.RequestType = 0x21;
262 //
263 // 00100001b;
264 //
265 Request.Request = EFI_USB_SET_IDLE_REQUEST;
266 Request.Value = (UINT16) ((Duration << 8) | ReportId);
267 Request.Index = Interface;
268 Request.Length = 0;
269
270 Result = UsbIo->UsbControlTransfer (
271 UsbIo,
272 &Request,
273 EfiUsbNoData,
274 TIMEOUT_VALUE,
275 NULL,
276 0,
277 &Status
278 );
279 return Result;
280 }
281
282
283 /**
284 Get Idel request.
285
286 @param UsbIo EFI_USB_IO_PROTOCOL
287 @param Interface Which interface the caller wants to get.
288 @param ReportId Which report the caller wants to get.
289 @param Duration Idle rate the caller wants to get.
290
291 @return EFI_SUCCESS
292 @return EFI_DEVICE_ERROR
293 @return EFI_TIMEOUT
294
295 **/
296 EFI_STATUS
297 UsbGetIdleRequest (
298 IN EFI_USB_IO_PROTOCOL *UsbIo,
299 IN UINT8 Interface,
300 IN UINT8 ReportId,
301 OUT UINT8 *Duration
302 )
303 {
304 UINT32 Status;
305 EFI_STATUS Result;
306 EFI_USB_DEVICE_REQUEST Request;
307
308 if (UsbIo == NULL) {
309 return EFI_INVALID_PARAMETER;
310 }
311 //
312 // Fill Device request packet
313 //
314 Request.RequestType = 0xa1;
315 //
316 // 10100001b;
317 //
318 Request.Request = EFI_USB_GET_IDLE_REQUEST;
319 Request.Value = ReportId;
320 Request.Index = Interface;
321 Request.Length = 1;
322
323 Result = UsbIo->UsbControlTransfer (
324 UsbIo,
325 &Request,
326 EfiUsbDataIn,
327 TIMEOUT_VALUE,
328 Duration,
329 1,
330 &Status
331 );
332
333 return Result;
334 }
335
336
337
338 /**
339 Hid Set Report request.
340
341 @param UsbIo EFI_USB_IO_PROTOCOL
342 @param Interface Which interface the caller wants to set.
343 @param ReportId Which report the caller wants to set.
344 @param ReportType Type of report.
345 @param ReportLen Length of report descriptor.
346 @param Report Report Descriptor buffer.
347
348 @return EFI_SUCCESS
349 @return EFI_DEVICE_ERROR
350 @return EFI_TIMEOUT
351
352 **/
353 EFI_STATUS
354 UsbSetReportRequest (
355 IN EFI_USB_IO_PROTOCOL *UsbIo,
356 IN UINT8 Interface,
357 IN UINT8 ReportId,
358 IN UINT8 ReportType,
359 IN UINT16 ReportLen,
360 IN UINT8 *Report
361 )
362 {
363 UINT32 Status;
364 EFI_STATUS Result;
365 EFI_USB_DEVICE_REQUEST Request;
366
367 if (UsbIo == NULL) {
368 return EFI_INVALID_PARAMETER;
369 }
370 //
371 // Fill Device request packet
372 //
373 Request.RequestType = 0x21;
374 //
375 // 00100001b;
376 //
377 Request.Request = EFI_USB_SET_REPORT_REQUEST;
378 Request.Value = (UINT16) ((ReportType << 8) | ReportId);
379 Request.Index = Interface;
380 Request.Length = ReportLen;
381
382 Result = UsbIo->UsbControlTransfer (
383 UsbIo,
384 &Request,
385 EfiUsbDataOut,
386 TIMEOUT_VALUE,
387 Report,
388 ReportLen,
389 &Status
390 );
391
392 return Result;
393 }
394
395
396 /**
397 Hid Set Report request.
398
399 @param UsbIo EFI_USB_IO_PROTOCOL
400 @param Interface Which interface the caller wants to set.
401 @param ReportId Which report the caller wants to set.
402 @param ReportType Type of report.
403 @param ReportLen Length of report descriptor.
404 @param Report Caller allocated buffer to store Report Descriptor.
405
406 @return EFI_SUCCESS
407 @return EFI_DEVICE_ERROR
408 @return EFI_TIMEOUT
409
410 **/
411 EFI_STATUS
412 UsbGetReportRequest (
413 IN EFI_USB_IO_PROTOCOL *UsbIo,
414 IN UINT8 Interface,
415 IN UINT8 ReportId,
416 IN UINT8 ReportType,
417 IN UINT16 ReportLen,
418 IN UINT8 *Report
419 )
420 {
421 UINT32 Status;
422 EFI_STATUS Result;
423 EFI_USB_DEVICE_REQUEST Request;
424
425 if (UsbIo == NULL) {
426 return EFI_INVALID_PARAMETER;
427 }
428 //
429 // Fill Device request packet
430 //
431 Request.RequestType = 0xa1;
432 //
433 // 10100001b;
434 //
435 Request.Request = EFI_USB_GET_REPORT_REQUEST;
436 Request.Value = (UINT16) ((ReportType << 8) | ReportId);
437 Request.Index = Interface;
438 Request.Length = ReportLen;
439
440 Result = UsbIo->UsbControlTransfer (
441 UsbIo,
442 &Request,
443 EfiUsbDataIn,
444 TIMEOUT_VALUE,
445 Report,
446 ReportLen,
447 &Status
448 );
449
450 return Result;
451 }