diff options
Diffstat (limited to 'MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.c')
-rw-r--r-- | MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.c | 97 |
1 files changed, 81 insertions, 16 deletions
diff --git a/MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.c b/MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.c index d81eaf7eae..d4e5a03475 100644 --- a/MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.c +++ b/MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.c @@ -1,7 +1,7 @@ /** @file
USB Mouse Driver that manages USB mouse and produces Simple Pointer Protocol.
-Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -521,46 +521,108 @@ InitializeUsbMouseDevice ( IN OUT USB_MOUSE_DEV *UsbMouseDev
)
{
- EFI_USB_IO_PROTOCOL *UsbIo;
- UINT8 Protocol;
- EFI_STATUS Status;
- EFI_USB_HID_DESCRIPTOR MouseHidDesc;
- UINT8 *ReportDesc;
- UINT8 ReportId;
- UINT8 Duration;
+ EFI_USB_IO_PROTOCOL *UsbIo;
+ UINT8 Protocol;
+ EFI_STATUS Status;
+ EFI_USB_HID_DESCRIPTOR *MouseHidDesc;
+ UINT8 *ReportDesc;
+ UINT8 ReportId;
+ UINT8 Duration;
+ EFI_USB_CONFIG_DESCRIPTOR ConfigDesc;
+ VOID *Buf;
+ UINT32 TransferResult;
+ UINT16 Total;
+ USB_DESC_HEAD *Head;
+ BOOLEAN Start;
UsbIo = UsbMouseDev->UsbIo;
//
- // Get HID descriptor
+ // Get the current configuration descriptor. Note that it doesn't include other descriptors.
+ //
+ Status = UsbIo->UsbGetConfigDescriptor (
+ UsbIo,
+ &ConfigDesc
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // By issuing Get_Descriptor(Configuration) request with total length, we get the Configuration descriptor,
+ // all Interface descriptors, all Endpoint descriptors, and the HID descriptor for each interface.
//
- Status = UsbGetHidDescriptor (
+ Buf = AllocateZeroPool (ConfigDesc.TotalLength);
+ if (Buf == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ Status = UsbGetDescriptor (
UsbIo,
- UsbMouseDev->InterfaceDescriptor.InterfaceNumber,
- &MouseHidDesc
+ (UINT16)((USB_DESC_TYPE_CONFIG << 8) | (ConfigDesc.ConfigurationValue - 1)),
+ 0,
+ ConfigDesc.TotalLength,
+ Buf,
+ &TransferResult
);
if (EFI_ERROR (Status)) {
+ FreePool (Buf);
return Status;
}
+ Total = 0;
+ Start = FALSE;
+ Head = (USB_DESC_HEAD *)Buf;
+ MouseHidDesc = NULL;
+
+ //
+ // Get HID descriptor from the receipt of Get_Descriptor(Configuration) request.
+ // This algorithm is based on the fact that the HID descriptor shall be interleaved
+ // between the interface and endpoint descriptors for HID interfaces.
+ //
+ while (Total < ConfigDesc.TotalLength) {
+ if (Head->Type == USB_DESC_TYPE_INTERFACE) {
+ if ((((USB_INTERFACE_DESCRIPTOR *)Head)->InterfaceNumber == UsbMouseDev->InterfaceDescriptor.InterfaceNumber) &&
+ (((USB_INTERFACE_DESCRIPTOR *)Head)->AlternateSetting == UsbMouseDev->InterfaceDescriptor.AlternateSetting)) {
+ Start = TRUE;
+ }
+ }
+ if ((Start == TRUE) && (Head->Type == USB_DESC_TYPE_ENDPOINT)) {
+ break;
+ }
+ if ((Start == TRUE) && (Head->Type == USB_DESC_TYPE_HID)) {
+ MouseHidDesc = (EFI_USB_HID_DESCRIPTOR *)Head;
+ break;
+ }
+ Total += (UINT16)Head->Len;
+ Head = (USB_DESC_HEAD*)((UINT8 *)Buf + Total);
+ }
+
+ if (MouseHidDesc == NULL) {
+ FreePool (Buf);
+ return EFI_UNSUPPORTED;
+ }
+
//
// Get report descriptor
//
- if (MouseHidDesc.HidClassDesc[0].DescriptorType != USB_DESC_TYPE_REPORT) {
+ if (MouseHidDesc->HidClassDesc[0].DescriptorType != USB_DESC_TYPE_REPORT) {
+ FreePool (Buf);
return EFI_UNSUPPORTED;
}
- ReportDesc = AllocateZeroPool (MouseHidDesc.HidClassDesc[0].DescriptorLength);
+ ReportDesc = AllocateZeroPool (MouseHidDesc->HidClassDesc[0].DescriptorLength);
ASSERT (ReportDesc != NULL);
Status = UsbGetReportDescriptor (
UsbIo,
UsbMouseDev->InterfaceDescriptor.InterfaceNumber,
- MouseHidDesc.HidClassDesc[0].DescriptorLength,
+ MouseHidDesc->HidClassDesc[0].DescriptorLength,
ReportDesc
);
if (EFI_ERROR (Status)) {
+ FreePool (Buf);
FreePool (ReportDesc);
return Status;
}
@@ -571,10 +633,11 @@ InitializeUsbMouseDevice ( Status = ParseMouseReportDescriptor (
UsbMouseDev,
ReportDesc,
- MouseHidDesc.HidClassDesc[0].DescriptorLength
+ MouseHidDesc->HidClassDesc[0].DescriptorLength
);
if (EFI_ERROR (Status)) {
+ FreePool (Buf);
FreePool (ReportDesc);
return Status;
}
@@ -610,6 +673,7 @@ InitializeUsbMouseDevice ( );
if (EFI_ERROR (Status)) {
+ FreePool (Buf);
FreePool (ReportDesc);
return Status;
}
@@ -632,6 +696,7 @@ InitializeUsbMouseDevice ( Duration
);
+ FreePool (Buf);
FreePool (ReportDesc);
//
|