summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Bus/Usb
diff options
context:
space:
mode:
authorxdu2 <xdu2@6f19259b-4bc3-4df7-8a09-765794883524>2010-12-24 05:32:34 +0000
committerxdu2 <xdu2@6f19259b-4bc3-4df7-8a09-765794883524>2010-12-24 05:32:34 +0000
commit84909ad446e02f16dce9b8f6541a038d7c378fab (patch)
tree0c60045b6355feb6a105ed27b146e084cbfc60ae /MdeModulePkg/Bus/Usb
parente2100bfa651cd0d1295ef13451b9cf4adddb8bfa (diff)
downloadedk2-platforms-84909ad446e02f16dce9b8f6541a038d7c378fab.tar.xz
1. update MatchUsbWwid() to check Vendor Id, Product Id and Interface Number.
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
Diffstat (limited to 'MdeModulePkg/Bus/Usb')
-rw-r--r--MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c6
-rw-r--r--MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h2
-rw-r--r--MdeModulePkg/Bus/Usb/UsbBusDxe/UsbUtility.c59
3 files changed, 48 insertions, 19 deletions
diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
index 90dcf61443..35da41b3e3 100644
--- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
+++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
@@ -2,7 +2,7 @@
Usb Bus Driver Binding and Bus IO Protocol.
-Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2010, 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
@@ -680,7 +680,7 @@ UsbIoGetEndpointDescriptor (
@param This The USB IO instance.
@param LangIDTable The table to return the language IDs.
- @param TableSize The number of supported languanges.
+ @param TableSize The size, in bytes, of the table LangIDTable.
@retval EFI_SUCCESS The language ID is return.
@@ -703,7 +703,7 @@ UsbIoGetSupportedLanguages (
Dev = UsbIf->Device;
*LangIDTable = Dev->LangId;
- *TableSize = Dev->TotalLangId;
+ *TableSize = (UINT16) (Dev->TotalLangId * sizeof (UINT16));
gBS->RestoreTPL (OldTpl);
return EFI_SUCCESS;
diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h
index ff04103be9..5d5535185c 100644
--- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h
+++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.h
@@ -596,7 +596,7 @@ UsbIoGetEndpointDescriptor (
@param This The USB IO instance.
@param LangIDTable The table to return the language IDs.
- @param TableSize The number of supported languanges.
+ @param TableSize The size, in bytes, of the table LangIDTable.
@retval EFI_SUCCESS The language ID is return.
diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbUtility.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbUtility.c
index 67f149cbda..9bebc27bfe 100644
--- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbUtility.c
+++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbUtility.c
@@ -2,7 +2,7 @@
Wrapper function for usb host controller interface.
-Copyright (c) 2007 - 2009, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2007 - 2010, 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
@@ -950,12 +950,9 @@ MatchUsbClass (
(UsbClassDevicePathPtr->ProductId == 0xffff || UsbClassDevicePathPtr->ProductId == DevDesc->IdProduct)) {
//
- // If class or subclass or protocol is 0, the counterparts in interface should be checked.
+ // If Class in Device Descriptor is set to 0, the counterparts in interface should be checked.
//
- if (DevDesc->DeviceClass == 0 ||
- DevDesc->DeviceSubClass == 0 ||
- DevDesc->DeviceProtocol == 0) {
-
+ if (DevDesc->DeviceClass == 0) {
if ((UsbClassDevicePathPtr->DeviceClass == ActIfDesc->InterfaceClass ||
UsbClassDevicePathPtr->DeviceClass == 0xff) &&
(UsbClassDevicePathPtr->DeviceSubClass == ActIfDesc->InterfaceSubClass ||
@@ -1001,6 +998,10 @@ MatchUsbWwid (
EFI_USB_DEVICE_DESCRIPTOR *DevDesc;
EFI_USB_STRING_DESCRIPTOR *StrDesc;
UINT16 *SnString;
+ UINT16 Index;
+ CHAR16 *CompareStr;
+ UINTN CompareLen;
+ UINTN Length;
if ((UsbWWIDDevicePathPtr->Header.Type != MESSAGING_DEVICE_PATH) ||
(UsbWWIDDevicePathPtr->Header.SubType != MSG_USB_WWID_DP )){
@@ -1012,27 +1013,55 @@ MatchUsbWwid (
ASSERT (IfDesc->ActiveIndex < USB_MAX_INTERFACE_SETTING);
ActIfDesc = &(IfDesc->Settings[IfDesc->ActiveIndex]->Desc);
DevDesc = &(UsbIf->Device->DevDesc->Desc);
- StrDesc = UsbGetOneString (UsbIf->Device, DevDesc->StrSerialNumber, USB_US_LAND_ID);
SnString = (UINT16 *) ((UINT8 *)UsbWWIDDevicePathPtr + 10);
//
- //In addtion, hub interface is always matched for this policy.
+ // In addition, Hub interface is always matched for this policy.
//
if ((ActIfDesc->InterfaceClass == USB_HUB_CLASS_CODE) &&
(ActIfDesc->InterfaceSubClass == USB_HUB_SUBCLASS_CODE)) {
return TRUE;
}
+
+ //
+ // Check Vendor Id, Product Id and Interface Number.
//
- // If connect wwid policy, determine the objective device by the serial number of
- // device descriptor.
- // Get serial number index from device descriptor, then get serial number by index
- // and land id, compare the serial number with wwid device path node at last
+ if ((DevDesc->IdVendor != UsbWWIDDevicePathPtr->VendorId) ||
+ (DevDesc->IdProduct != UsbWWIDDevicePathPtr->ProductId) ||
+ (ActIfDesc->InterfaceNumber != UsbWWIDDevicePathPtr->InterfaceNumber)) {
+ return FALSE;
+ }
+
//
- // BugBug: only check serial number here, should check Interface Number, Device Vendor Id, Device Product Id in later version
+ // Check SerialNumber.
//
- if (StrDesc != NULL && (StrnCmp (StrDesc->String, SnString, StrDesc->Length) == 0)) {
+ if (DevDesc->StrSerialNumber == 0) {
+ return FALSE;
+ }
- return TRUE;
+ //
+ // Serial number in USB WWID device path is the last 64-or-less UTF-16 characters.
+ //
+ CompareStr = (CHAR16 *) (UINTN) (UsbWWIDDevicePathPtr + 1);
+ CompareLen = (DevicePathNodeLength (UsbWWIDDevicePathPtr) - sizeof (USB_WWID_DEVICE_PATH)) / sizeof (CHAR16);
+ if (CompareStr[CompareLen - 1] == L'\0') {
+ CompareLen--;
+ }
+
+ //
+ // Compare serial number in each supported language.
+ //
+ for (Index = 0; Index < UsbIf->Device->TotalLangId; Index++) {
+ StrDesc = UsbGetOneString (UsbIf->Device, DevDesc->StrSerialNumber, UsbIf->Device->LangId[Index]);
+ if (StrDesc == NULL) {
+ continue;
+ }
+
+ Length = (StrDesc->Length - 2) / sizeof (CHAR16);
+ if ((Length >= CompareLen) &&
+ (CompareMem (StrDesc->String + Length - CompareLen, CompareStr, CompareLen * sizeof (CHAR16)) == 0)) {
+ return TRUE;
+ }
}
return FALSE;