]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/UsbMouse: Get HID descriptor from the return of Get_Desc(Configuration...
authorerictian <erictian@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 13 Jun 2012 08:05:03 +0000 (08:05 +0000)
committererictian <erictian@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 13 Jun 2012 08:05:03 +0000 (08:05 +0000)
Signed-off-by: Feng Tian <feng.tian@intel.com>
Reviewed-by: Elvin Li <elvin.li@intel.com>
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13449 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/UsbMouseAbsolutePointer.c
MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/UsbMouseAbsolutePointer.h
MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.c
MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.h

index 8c2edb4f998d6d8ace3d8265f56798c14eb63302..3540cd4a0fcec7a5881b4ba77d04180da5e2e936 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   USB Mouse Driver that manages USB mouse and produces Absolute Pointer Protocol.\r
 \r
-Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -521,46 +521,108 @@ InitializeUsbMouseDevice (
   IN  USB_MOUSE_ABSOLUTE_POINTER_DEV           *UsbMouseAbsolutePointerDev\r
   )\r
 {\r
-  EFI_USB_IO_PROTOCOL     *UsbIo;\r
-  UINT8                   Protocol;\r
-  EFI_STATUS              Status;\r
-  EFI_USB_HID_DESCRIPTOR  MouseHidDesc;\r
-  UINT8                   *ReportDesc;\r
-  UINT8                   ReportId;\r
-  UINT8                   Duration;\r
+  EFI_USB_IO_PROTOCOL       *UsbIo;\r
+  UINT8                     Protocol;\r
+  EFI_STATUS                Status;\r
+  EFI_USB_HID_DESCRIPTOR    *MouseHidDesc;\r
+  UINT8                     *ReportDesc;\r
+  UINT8                     ReportId;\r
+  UINT8                     Duration;\r
+  EFI_USB_CONFIG_DESCRIPTOR ConfigDesc;\r
+  VOID                      *Buf;\r
+  UINT32                    TransferResult;\r
+  UINT16                    Total;\r
+  USB_DESC_HEAD             *Head;\r
+  BOOLEAN                   Start;\r
 \r
   UsbIo = UsbMouseAbsolutePointerDev->UsbIo;\r
 \r
   //\r
-  // Get HID descriptor\r
+  // Get the current configuration descriptor. Note that it doesn't include other descriptors.\r
+  //\r
+  Status = UsbIo->UsbGetConfigDescriptor (\r
+                    UsbIo,\r
+                    &ConfigDesc\r
+                    );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // By issuing Get_Descriptor(Configuration) request with total length, we get the Configuration descriptor,\r
+  // all Interface descriptors, all Endpoint descriptors, and the HID descriptor for each interface.\r
   //\r
-  Status = UsbGetHidDescriptor (\r
+  Buf = AllocateZeroPool (ConfigDesc.TotalLength);\r
+  if (Buf == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  Status = UsbGetDescriptor (\r
              UsbIo,\r
-             UsbMouseAbsolutePointerDev->InterfaceDescriptor.InterfaceNumber,\r
-             &MouseHidDesc\r
+             (UINT16)((USB_DESC_TYPE_CONFIG << 8) | (ConfigDesc.ConfigurationValue - 1)),\r
+             0,\r
+             ConfigDesc.TotalLength,\r
+             Buf,\r
+             &TransferResult\r
              );\r
   if (EFI_ERROR (Status)) {\r
+    FreePool (Buf);\r
     return Status;\r
   }\r
 \r
+  Total = 0;\r
+  Start = FALSE;\r
+  Head  = (USB_DESC_HEAD *)Buf;  \r
+  MouseHidDesc = NULL;\r
+\r
+  //\r
+  // Get HID descriptor from the receipt of Get_Descriptor(Configuration) request.\r
+  // This algorithm is based on the fact that the HID descriptor shall be interleaved\r
+  // between the interface and endpoint descriptors for HID interfaces.\r
+  //\r
+  while (Total < ConfigDesc.TotalLength) {\r
+    if (Head->Type == USB_DESC_TYPE_INTERFACE) {\r
+      if ((((USB_INTERFACE_DESCRIPTOR *)Head)->InterfaceNumber == UsbMouseAbsolutePointerDev->InterfaceDescriptor.InterfaceNumber) &&\r
+        (((USB_INTERFACE_DESCRIPTOR *)Head)->AlternateSetting == UsbMouseAbsolutePointerDev->InterfaceDescriptor.AlternateSetting)) {\r
+        Start = TRUE;\r
+      }\r
+    }\r
+    if ((Start == TRUE) && (Head->Type == USB_DESC_TYPE_ENDPOINT)) {\r
+      break;\r
+    }\r
+    if ((Start == TRUE) && (Head->Type == USB_DESC_TYPE_HID)) {\r
+      MouseHidDesc = (EFI_USB_HID_DESCRIPTOR *)Head;\r
+      break;\r
+    }\r
+    Total += (UINT16)Head->Len;\r
+    Head   = (USB_DESC_HEAD*)((UINT8 *)Buf + Total);\r
+  }\r
+\r
+  if (MouseHidDesc == NULL) {\r
+    FreePool (Buf);\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
   //\r
   // Get report descriptor\r
   //\r
-  if (MouseHidDesc.HidClassDesc[0].DescriptorType != USB_DESC_TYPE_REPORT) {\r
+  if (MouseHidDesc->HidClassDesc[0].DescriptorType != USB_DESC_TYPE_REPORT) {\r
+    FreePool (Buf);\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
-  ReportDesc = AllocateZeroPool (MouseHidDesc.HidClassDesc[0].DescriptorLength);\r
+  ReportDesc = AllocateZeroPool (MouseHidDesc->HidClassDesc[0].DescriptorLength);\r
   ASSERT (ReportDesc != NULL);\r
 \r
   Status = UsbGetReportDescriptor (\r
              UsbIo,\r
              UsbMouseAbsolutePointerDev->InterfaceDescriptor.InterfaceNumber,\r
-             MouseHidDesc.HidClassDesc[0].DescriptorLength,\r
+             MouseHidDesc->HidClassDesc[0].DescriptorLength,\r
              ReportDesc\r
              );\r
 \r
   if (EFI_ERROR (Status)) {\r
+    FreePool (Buf);\r
     FreePool (ReportDesc);\r
     return Status;\r
   }\r
@@ -571,10 +633,11 @@ InitializeUsbMouseDevice (
   Status = ParseMouseReportDescriptor (\r
              UsbMouseAbsolutePointerDev,\r
              ReportDesc,\r
-             MouseHidDesc.HidClassDesc[0].DescriptorLength\r
+             MouseHidDesc->HidClassDesc[0].DescriptorLength\r
              );\r
 \r
   if (EFI_ERROR (Status)) {\r
+    FreePool (Buf);\r
     FreePool (ReportDesc);\r
     return Status;\r
   }\r
@@ -604,6 +667,7 @@ InitializeUsbMouseDevice (
                );\r
 \r
     if (EFI_ERROR (Status)) {\r
+      FreePool (Buf);\r
       FreePool (ReportDesc);\r
       return Status;\r
     }\r
@@ -626,6 +690,7 @@ InitializeUsbMouseDevice (
     Duration\r
     );\r
 \r
+  FreePool (Buf);\r
   FreePool (ReportDesc);\r
 \r
   //\r
index 169f0be4f749e4c7251130c8af7c4ca2f9e750a1..08b8d56dd8f7e2d4a5328b6d95cc4632bcd64959 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Helper routine and corresponding data struct used by USB Mouse Absolute Pointer Driver.\r
 \r
-Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -42,6 +42,17 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #define USB_MOUSE_ABSOLUTE_POINTER_DEV_SIGNATURE SIGNATURE_32 ('u', 'm', 's', 't')\r
 \r
+//\r
+// A common header for usb standard descriptor.\r
+// Each stand descriptor has a length and type.\r
+//\r
+#pragma pack(1)\r
+typedef struct {\r
+  UINT8                   Len;\r
+  UINT8                   Type;\r
+} USB_DESC_HEAD;\r
+#pragma pack()\r
+\r
 ///\r
 /// Button range and status\r
 ///\r
index d81eaf7eae07e36211845a131a1bd6f92cf5589c..d4e5a03475849f4d3ca9c0f117862fec4de3aa22 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   USB Mouse Driver that manages USB mouse and produces Simple Pointer Protocol.\r
 \r
-Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -521,46 +521,108 @@ InitializeUsbMouseDevice (
   IN OUT USB_MOUSE_DEV           *UsbMouseDev\r
   )\r
 {\r
-  EFI_USB_IO_PROTOCOL     *UsbIo;\r
-  UINT8                   Protocol;\r
-  EFI_STATUS              Status;\r
-  EFI_USB_HID_DESCRIPTOR  MouseHidDesc;\r
-  UINT8                   *ReportDesc;\r
-  UINT8                   ReportId;\r
-  UINT8                   Duration;\r
+  EFI_USB_IO_PROTOCOL       *UsbIo;\r
+  UINT8                     Protocol;\r
+  EFI_STATUS                Status;\r
+  EFI_USB_HID_DESCRIPTOR    *MouseHidDesc;\r
+  UINT8                     *ReportDesc;\r
+  UINT8                     ReportId;\r
+  UINT8                     Duration;\r
+  EFI_USB_CONFIG_DESCRIPTOR ConfigDesc;\r
+  VOID                      *Buf;\r
+  UINT32                    TransferResult;\r
+  UINT16                    Total;\r
+  USB_DESC_HEAD             *Head;\r
+  BOOLEAN                   Start;\r
 \r
   UsbIo = UsbMouseDev->UsbIo;\r
 \r
   //\r
-  // Get HID descriptor\r
+  // Get the current configuration descriptor. Note that it doesn't include other descriptors.\r
+  //\r
+  Status = UsbIo->UsbGetConfigDescriptor (\r
+                    UsbIo,\r
+                    &ConfigDesc\r
+                    );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // By issuing Get_Descriptor(Configuration) request with total length, we get the Configuration descriptor,\r
+  // all Interface descriptors, all Endpoint descriptors, and the HID descriptor for each interface.\r
   //\r
-  Status = UsbGetHidDescriptor (\r
+  Buf = AllocateZeroPool (ConfigDesc.TotalLength);\r
+  if (Buf == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  Status = UsbGetDescriptor (\r
              UsbIo,\r
-             UsbMouseDev->InterfaceDescriptor.InterfaceNumber,\r
-             &MouseHidDesc\r
+             (UINT16)((USB_DESC_TYPE_CONFIG << 8) | (ConfigDesc.ConfigurationValue - 1)),\r
+             0,\r
+             ConfigDesc.TotalLength,\r
+             Buf,\r
+             &TransferResult\r
              );\r
   if (EFI_ERROR (Status)) {\r
+    FreePool (Buf);\r
     return Status;\r
   }\r
 \r
+  Total = 0;\r
+  Start = FALSE;\r
+  Head  = (USB_DESC_HEAD *)Buf;  \r
+  MouseHidDesc = NULL;\r
+\r
+  //\r
+  // Get HID descriptor from the receipt of Get_Descriptor(Configuration) request.\r
+  // This algorithm is based on the fact that the HID descriptor shall be interleaved\r
+  // between the interface and endpoint descriptors for HID interfaces.\r
+  //\r
+  while (Total < ConfigDesc.TotalLength) {\r
+    if (Head->Type == USB_DESC_TYPE_INTERFACE) {\r
+      if ((((USB_INTERFACE_DESCRIPTOR *)Head)->InterfaceNumber == UsbMouseDev->InterfaceDescriptor.InterfaceNumber) &&\r
+        (((USB_INTERFACE_DESCRIPTOR *)Head)->AlternateSetting == UsbMouseDev->InterfaceDescriptor.AlternateSetting)) {\r
+        Start = TRUE;\r
+      }\r
+    }\r
+    if ((Start == TRUE) && (Head->Type == USB_DESC_TYPE_ENDPOINT)) {\r
+      break;\r
+    }\r
+    if ((Start == TRUE) && (Head->Type == USB_DESC_TYPE_HID)) {\r
+      MouseHidDesc = (EFI_USB_HID_DESCRIPTOR *)Head;\r
+      break;\r
+    }\r
+    Total += (UINT16)Head->Len;\r
+    Head   = (USB_DESC_HEAD*)((UINT8 *)Buf + Total);\r
+  }\r
+\r
+  if (MouseHidDesc == NULL) {\r
+    FreePool (Buf);\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
   //\r
   // Get report descriptor\r
   //\r
-  if (MouseHidDesc.HidClassDesc[0].DescriptorType != USB_DESC_TYPE_REPORT) {\r
+  if (MouseHidDesc->HidClassDesc[0].DescriptorType != USB_DESC_TYPE_REPORT) {\r
+    FreePool (Buf);\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
-  ReportDesc = AllocateZeroPool (MouseHidDesc.HidClassDesc[0].DescriptorLength);\r
+  ReportDesc = AllocateZeroPool (MouseHidDesc->HidClassDesc[0].DescriptorLength);\r
   ASSERT (ReportDesc != NULL);\r
 \r
   Status = UsbGetReportDescriptor (\r
              UsbIo,\r
              UsbMouseDev->InterfaceDescriptor.InterfaceNumber,\r
-             MouseHidDesc.HidClassDesc[0].DescriptorLength,\r
+             MouseHidDesc->HidClassDesc[0].DescriptorLength,\r
              ReportDesc\r
              );\r
 \r
   if (EFI_ERROR (Status)) {\r
+    FreePool (Buf);\r
     FreePool (ReportDesc);\r
     return Status;\r
   }\r
@@ -571,10 +633,11 @@ InitializeUsbMouseDevice (
   Status = ParseMouseReportDescriptor (\r
              UsbMouseDev,\r
              ReportDesc,\r
-             MouseHidDesc.HidClassDesc[0].DescriptorLength\r
+             MouseHidDesc->HidClassDesc[0].DescriptorLength\r
              );\r
 \r
   if (EFI_ERROR (Status)) {\r
+    FreePool (Buf);\r
     FreePool (ReportDesc);\r
     return Status;\r
   }\r
@@ -610,6 +673,7 @@ InitializeUsbMouseDevice (
                );\r
 \r
     if (EFI_ERROR (Status)) {\r
+      FreePool (Buf);\r
       FreePool (ReportDesc);\r
       return Status;\r
     }\r
@@ -632,6 +696,7 @@ InitializeUsbMouseDevice (
     Duration\r
     );\r
 \r
+  FreePool (Buf);\r
   FreePool (ReportDesc);\r
 \r
   //\r
index 6d677f770928c0630a81638c8337567b6cda900c..0dab9de11d8f1d3a592d9159b51e49d3c736e20f 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Helper routine and corresponding data struct used by USB Mouse Driver.\r
 \r
-Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -42,6 +42,17 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #define USB_MOUSE_DEV_SIGNATURE SIGNATURE_32 ('u', 'm', 'o', 'u')\r
 \r
+//\r
+// A common header for usb standard descriptor.\r
+// Each stand descriptor has a length and type.\r
+//\r
+#pragma pack(1)\r
+typedef struct {\r
+  UINT8                   Len;\r
+  UINT8                   Type;\r
+} USB_DESC_HEAD;\r
+#pragma pack()\r
+\r
 ///\r
 /// Button range and status\r
 ///\r