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