]> git.proxmox.com Git - mirror_edk2.git/commitdiff
1. update MatchUsbWwid() to check Vendor Id, Product Id and Interface Number.
authorxdu2 <xdu2@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 24 Dec 2010 05:32:34 +0000 (05:32 +0000)
committerxdu2 <xdu2@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 24 Dec 2010 05:32:34 +0000 (05:32 +0000)
2. update SerialNumber comparing logic to handle possible NULL-terminator in WWID device path
3. fix bug in UsbIo->UsbIoGetSupportedLanguages(): TableSize is size in bytes of LangIDTable instead of number of LangID.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11197 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h
MdeModulePkg/Bus/Usb/UsbBusDxe/UsbUtility.c

index 90dcf61443dc29e378bb77f35a1f45880c9d9e0a..35da41b3e39eab379ee04067e40e7bc0cb3e75a3 100644 (file)
@@ -2,7 +2,7 @@
 \r
     Usb Bus Driver Binding and Bus IO Protocol.\r
 \r
-Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2010, 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
@@ -680,7 +680,7 @@ UsbIoGetEndpointDescriptor (
 \r
   @param  This                   The USB IO instance.\r
   @param  LangIDTable            The table to return the language IDs.\r
-  @param  TableSize              The number of supported languanges.\r
+  @param  TableSize              The size, in bytes, of the table LangIDTable.\r
 \r
   @retval EFI_SUCCESS            The language ID is return.\r
 \r
@@ -703,7 +703,7 @@ UsbIoGetSupportedLanguages (
   Dev           = UsbIf->Device;\r
 \r
   *LangIDTable  = Dev->LangId;\r
-  *TableSize    = Dev->TotalLangId;\r
+  *TableSize    = (UINT16) (Dev->TotalLangId * sizeof (UINT16));\r
 \r
   gBS->RestoreTPL (OldTpl);\r
   return EFI_SUCCESS;\r
index ff04103be994c0a239895503d79064422c003688..5d5535185ca54c70740307cd96e5bf7ed17b06c6 100644 (file)
@@ -596,7 +596,7 @@ UsbIoGetEndpointDescriptor (
 \r
   @param  This                   The USB IO instance.\r
   @param  LangIDTable            The table to return the language IDs.\r
-  @param  TableSize              The number of supported languanges.\r
+  @param  TableSize              The size, in bytes, of the table LangIDTable.\r
 \r
   @retval EFI_SUCCESS            The language ID is return.\r
 \r
index 67f149cbdaf26929219bf1511d93d24523a13a48..9bebc27bfe1faa6ec64be3f487b9aa64ddef181d 100644 (file)
@@ -2,7 +2,7 @@
 \r
     Wrapper function for usb host controller interface.\r
 \r
-Copyright (c) 2007 - 2009, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2010, 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
@@ -950,12 +950,9 @@ MatchUsbClass (
       (UsbClassDevicePathPtr->ProductId == 0xffff || UsbClassDevicePathPtr->ProductId == DevDesc->IdProduct)) {\r
 \r
     //\r
-    // If class or subclass or protocol is 0, the counterparts in interface should be checked.\r
+    // If Class in Device Descriptor is set to 0, the counterparts in interface should be checked.\r
     //\r
-    if (DevDesc->DeviceClass == 0 ||\r
-        DevDesc->DeviceSubClass == 0 ||\r
-        DevDesc->DeviceProtocol == 0) {\r
-\r
+    if (DevDesc->DeviceClass == 0) {\r
       if ((UsbClassDevicePathPtr->DeviceClass == ActIfDesc->InterfaceClass ||\r
                                           UsbClassDevicePathPtr->DeviceClass == 0xff) &&\r
           (UsbClassDevicePathPtr->DeviceSubClass == ActIfDesc->InterfaceSubClass ||\r
@@ -1001,6 +998,10 @@ MatchUsbWwid (
   EFI_USB_DEVICE_DESCRIPTOR     *DevDesc;\r
   EFI_USB_STRING_DESCRIPTOR     *StrDesc;\r
   UINT16                        *SnString;\r
+  UINT16                        Index;\r
+  CHAR16                        *CompareStr;\r
+  UINTN                         CompareLen;\r
+  UINTN                         Length;\r
 \r
   if ((UsbWWIDDevicePathPtr->Header.Type != MESSAGING_DEVICE_PATH) ||\r
      (UsbWWIDDevicePathPtr->Header.SubType != MSG_USB_WWID_DP )){\r
@@ -1012,27 +1013,55 @@ MatchUsbWwid (
   ASSERT (IfDesc->ActiveIndex < USB_MAX_INTERFACE_SETTING);\r
   ActIfDesc    = &(IfDesc->Settings[IfDesc->ActiveIndex]->Desc);\r
   DevDesc      = &(UsbIf->Device->DevDesc->Desc);\r
-  StrDesc      = UsbGetOneString (UsbIf->Device, DevDesc->StrSerialNumber, USB_US_LAND_ID);\r
   SnString     = (UINT16 *) ((UINT8 *)UsbWWIDDevicePathPtr + 10);\r
 \r
   //\r
-  //In addtion, hub interface is always matched for this policy.\r
+  // In addition, Hub interface is always matched for this policy.\r
   //\r
   if ((ActIfDesc->InterfaceClass == USB_HUB_CLASS_CODE) &&\r
       (ActIfDesc->InterfaceSubClass == USB_HUB_SUBCLASS_CODE)) {\r
     return TRUE;\r
   }\r
+\r
+  //\r
+  // Check Vendor Id, Product Id and Interface Number.\r
   //\r
-  // If connect wwid policy, determine the objective device by the serial number of\r
-  // device descriptor.\r
-  // Get serial number index from device descriptor, then get serial number by index\r
-  // and land id, compare the serial number with wwid device path node at last\r
+  if ((DevDesc->IdVendor != UsbWWIDDevicePathPtr->VendorId) ||\r
+      (DevDesc->IdProduct != UsbWWIDDevicePathPtr->ProductId) ||\r
+      (ActIfDesc->InterfaceNumber != UsbWWIDDevicePathPtr->InterfaceNumber)) {\r
+    return FALSE;\r
+  }\r
+\r
   //\r
-  // BugBug: only check serial number here, should check Interface Number, Device Vendor Id, Device Product Id  in later version\r
+  // Check SerialNumber.\r
   //\r
-  if (StrDesc != NULL && (StrnCmp (StrDesc->String, SnString, StrDesc->Length) == 0)) {\r
+  if (DevDesc->StrSerialNumber == 0) {\r
+    return FALSE;\r
+  }\r
 \r
-    return TRUE;\r
+  //\r
+  // Serial number in USB WWID device path is the last 64-or-less UTF-16 characters.\r
+  //\r
+  CompareStr = (CHAR16 *) (UINTN) (UsbWWIDDevicePathPtr + 1);\r
+  CompareLen = (DevicePathNodeLength (UsbWWIDDevicePathPtr) - sizeof (USB_WWID_DEVICE_PATH)) / sizeof (CHAR16);\r
+  if (CompareStr[CompareLen - 1] == L'\0') {\r
+    CompareLen--;\r
+  }\r
+\r
+  //\r
+  // Compare serial number in each supported language.\r
+  //\r
+  for (Index = 0; Index < UsbIf->Device->TotalLangId; Index++) {\r
+    StrDesc = UsbGetOneString (UsbIf->Device, DevDesc->StrSerialNumber, UsbIf->Device->LangId[Index]);\r
+    if (StrDesc == NULL) {\r
+      continue;\r
+    }\r
+\r
+    Length = (StrDesc->Length - 2) / sizeof (CHAR16);\r
+    if ((Length >= CompareLen) &&\r
+        (CompareMem (StrDesc->String + Length - CompareLen, CompareStr, CompareLen * sizeof (CHAR16)) == 0)) {\r
+      return TRUE;\r
+    }\r
   }\r
 \r
   return FALSE;\r