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