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