]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/UefiUsbLib/Hid.c
aeab8f11aa15f723dfa5a9812c87a6a64a4afe2c
[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 /**
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 EFI_SUCCESS
77 @return EFI_DEVICE_ERROR
78 @return EFI_TIMEOUT
79
80 **/
81 EFI_STATUS
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 EFI_SUCCESS
127 @return EFI_DEVICE_ERROR
128 @return EFI_TIMEOUT
129
130 **/
131 EFI_STATUS
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 Set Hid Protocol Request.
173
174 @param UsbIo EFI_USB_IO_PROTOCOL.
175 @param Interface Which interface the caller wants to set protocol.
176 @param Protocol Protocol value the caller wants to set.
177
178 @return EFI_SUCCESS
179 @return EFI_DEVICE_ERROR
180 @return EFI_TIMEOUT
181
182 **/
183 EFI_STATUS
184 UsbSetProtocolRequest (
185 IN EFI_USB_IO_PROTOCOL *UsbIo,
186 IN UINT8 Interface,
187 IN UINT8 Protocol
188 )
189 {
190 UINT32 Status;
191 EFI_STATUS Result;
192 EFI_USB_DEVICE_REQUEST Request;
193
194 if (UsbIo == NULL) {
195 return EFI_INVALID_PARAMETER;
196 }
197 //
198 // Fill Device request packet
199 //
200 Request.RequestType = 0x21;
201 //
202 // 00100001b;
203 //
204 Request.Request = EFI_USB_SET_PROTOCOL_REQUEST;
205 Request.Value = Protocol;
206 Request.Index = Interface;
207 Request.Length = 0;
208
209 Result = UsbIo->UsbControlTransfer (
210 UsbIo,
211 &Request,
212 EfiUsbNoData,
213 TIMEOUT_VALUE,
214 NULL,
215 0,
216 &Status
217 );
218 return Result;
219 }
220
221
222 /**
223 Set Idel request.
224
225 @param UsbIo EFI_USB_IO_PROTOCOL.
226 @param Interface Which interface the caller wants to set.
227 @param ReportId Which report the caller wants to set.
228 @param Duration Idle rate the caller wants to set.
229
230 @return EFI_SUCCESS
231 @return EFI_DEVICE_ERROR
232 @return EFI_TIMEOUT
233
234 **/
235 EFI_STATUS
236 UsbSetIdleRequest (
237 IN EFI_USB_IO_PROTOCOL *UsbIo,
238 IN UINT8 Interface,
239 IN UINT8 ReportId,
240 IN UINT8 Duration
241 )
242 {
243 UINT32 Status;
244 EFI_STATUS Result;
245 EFI_USB_DEVICE_REQUEST Request;
246
247 if (UsbIo == NULL) {
248 return EFI_INVALID_PARAMETER;
249 }
250 //
251 // Fill Device request packet
252 //
253 Request.RequestType = 0x21;
254 //
255 // 00100001b;
256 //
257 Request.Request = EFI_USB_SET_IDLE_REQUEST;
258 Request.Value = (UINT16) ((Duration << 8) | ReportId);
259 Request.Index = Interface;
260 Request.Length = 0;
261
262 Result = UsbIo->UsbControlTransfer (
263 UsbIo,
264 &Request,
265 EfiUsbNoData,
266 TIMEOUT_VALUE,
267 NULL,
268 0,
269 &Status
270 );
271 return Result;
272 }
273
274
275 /**
276 Get Idel request.
277
278 @param UsbIo EFI_USB_IO_PROTOCOL.
279 @param Interface Which interface the caller wants to get.
280 @param ReportId Which report the caller wants to get.
281 @param Duration Idle rate the caller wants to get.
282
283 @return EFI_SUCCESS
284 @return EFI_DEVICE_ERROR
285 @return EFI_TIMEOUT
286
287 **/
288 EFI_STATUS
289 UsbGetIdleRequest (
290 IN EFI_USB_IO_PROTOCOL *UsbIo,
291 IN UINT8 Interface,
292 IN UINT8 ReportId,
293 OUT UINT8 *Duration
294 )
295 {
296 UINT32 Status;
297 EFI_STATUS Result;
298 EFI_USB_DEVICE_REQUEST Request;
299
300 if (UsbIo == NULL) {
301 return EFI_INVALID_PARAMETER;
302 }
303 //
304 // Fill Device request packet
305 //
306 Request.RequestType = 0xa1;
307 //
308 // 10100001b;
309 //
310 Request.Request = EFI_USB_GET_IDLE_REQUEST;
311 Request.Value = ReportId;
312 Request.Index = Interface;
313 Request.Length = 1;
314
315 Result = UsbIo->UsbControlTransfer (
316 UsbIo,
317 &Request,
318 EfiUsbDataIn,
319 TIMEOUT_VALUE,
320 Duration,
321 1,
322 &Status
323 );
324
325 return Result;
326 }
327
328
329 /**
330 Hid Set Report request.
331
332 @param UsbIo EFI_USB_IO_PROTOCOL.
333 @param Interface Which interface the caller wants to set.
334 @param ReportId Which report the caller wants to set.
335 @param ReportType Type of report.
336 @param ReportLen Length of report descriptor.
337 @param Report Report Descriptor buffer.
338
339 @return EFI_SUCCESS
340 @return EFI_DEVICE_ERROR
341 @return EFI_TIMEOUT
342
343 **/
344 EFI_STATUS
345 UsbSetReportRequest (
346 IN EFI_USB_IO_PROTOCOL *UsbIo,
347 IN UINT8 Interface,
348 IN UINT8 ReportId,
349 IN UINT8 ReportType,
350 IN UINT16 ReportLen,
351 IN UINT8 *Report
352 )
353 {
354 UINT32 Status;
355 EFI_STATUS Result;
356 EFI_USB_DEVICE_REQUEST Request;
357
358 if (UsbIo == NULL) {
359 return EFI_INVALID_PARAMETER;
360 }
361 //
362 // Fill Device request packet
363 //
364 Request.RequestType = 0x21;
365 //
366 // 00100001b;
367 //
368 Request.Request = EFI_USB_SET_REPORT_REQUEST;
369 Request.Value = (UINT16) ((ReportType << 8) | ReportId);
370 Request.Index = Interface;
371 Request.Length = ReportLen;
372
373 Result = UsbIo->UsbControlTransfer (
374 UsbIo,
375 &Request,
376 EfiUsbDataOut,
377 TIMEOUT_VALUE,
378 Report,
379 ReportLen,
380 &Status
381 );
382
383 return Result;
384 }
385
386
387 /**
388 Hid Set Report request.
389
390 @param UsbIo EFI_USB_IO_PROTOCOL.
391 @param Interface Which interface the caller wants to set.
392 @param ReportId Which report the caller wants to set.
393 @param ReportType Type of report.
394 @param ReportLen Length of report descriptor.
395 @param Report Caller allocated buffer to store Report Descriptor.
396
397 @return EFI_SUCCESS
398 @return EFI_DEVICE_ERROR
399 @return EFI_TIMEOUT
400
401 **/
402 EFI_STATUS
403 UsbGetReportRequest (
404 IN EFI_USB_IO_PROTOCOL *UsbIo,
405 IN UINT8 Interface,
406 IN UINT8 ReportId,
407 IN UINT8 ReportType,
408 IN UINT16 ReportLen,
409 IN UINT8 *Report
410 )
411 {
412 UINT32 Status;
413 EFI_STATUS Result;
414 EFI_USB_DEVICE_REQUEST Request;
415
416 if (UsbIo == NULL) {
417 return EFI_INVALID_PARAMETER;
418 }
419 //
420 // Fill Device request packet
421 //
422 Request.RequestType = 0xa1;
423 //
424 // 10100001b;
425 //
426 Request.Request = EFI_USB_GET_REPORT_REQUEST;
427 Request.Value = (UINT16) ((ReportType << 8) | ReportId);
428 Request.Index = Interface;
429 Request.Length = ReportLen;
430
431 Result = UsbIo->UsbControlTransfer (
432 UsbIo,
433 &Request,
434 EfiUsbDataIn,
435 TIMEOUT_VALUE,
436 Report,
437 ReportLen,
438 &Status
439 );
440
441 return Result;
442 }