]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbBusDxe / UsbBus.c
index ef002f53bb71bbef0efb6cb9e75ae1e0e7f513da..d4002c48d74e1a7908e68cf0da000c422cb5e57a 100644 (file)
@@ -2,14 +2,8 @@
 \r
     Usb Bus Driver Binding and Bus IO Protocol.\r
 \r
-Copyright (c) 2004 - 2013, 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
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -76,6 +70,7 @@ UsbIoControlTransfer (
   USB_ENDPOINT_DESC       *EpDesc;\r
   EFI_TPL                 OldTpl;\r
   EFI_STATUS              Status;\r
+  UINTN                   RequestedDataLength;\r
 \r
   if (UsbStatus == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -86,6 +81,7 @@ UsbIoControlTransfer (
   UsbIf  = USB_INTERFACE_FROM_USBIO (This);\r
   Dev    = UsbIf->Device;\r
 \r
+  RequestedDataLength = DataLength;\r
   Status = UsbHcControlTransfer (\r
              Dev->Bus,\r
              Dev->Address,\r
@@ -99,6 +95,18 @@ UsbIoControlTransfer (
              &Dev->Translator,\r
              UsbStatus\r
              );\r
+  //\r
+  // If the request completed sucessfully and the Direction of the request is\r
+  // EfiUsbDataIn or EfiUsbDataOut, then make sure the actual number of bytes\r
+  // transfered is the same as the number of bytes requested.  If a different\r
+  // number of bytes were transfered, then return EFI_DEVICE_ERROR.\r
+  //\r
+  if (!EFI_ERROR (Status)) {\r
+    if (Direction != EfiUsbNoData && DataLength != RequestedDataLength) {\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto ON_EXIT;\r
+    }\r
+  }\r
 \r
   if (EFI_ERROR (Status) || (*UsbStatus != EFI_USB_NOERROR)) {\r
     //\r
@@ -848,7 +856,7 @@ UsbIoPortReset (
   Dev->Address = DevAddress;\r
 \r
   gBS->Stall (USB_SET_DEVICE_ADDRESS_STALL);\r
-  \r
+\r
   if (EFI_ERROR (Status)) {\r
     //\r
     // It may fail due to device disconnection or other reasons.\r
@@ -976,9 +984,6 @@ UsbBusBuildProtocol (
     }\r
   }\r
 \r
-  UsbHcReset (UsbBus, EFI_USB_HC_RESET_GLOBAL);\r
-  UsbHcSetState (UsbBus, EfiUsbHcStateOperational);\r
-\r
   //\r
   // Install an EFI_USB_BUS_PROTOCOL to host controller to identify it.\r
   //\r
@@ -1025,7 +1030,7 @@ UsbBusBuildProtocol (
   RootIf->Signature       = USB_INTERFACE_SIGNATURE;\r
   RootIf->Device          = RootHub;\r
   RootIf->DevicePath      = UsbBus->DevicePath;\r
-  \r
+\r
   //\r
   // Report Status Code here since we will enumerate the USB devices\r
   //\r
@@ -1034,7 +1039,7 @@ UsbBusBuildProtocol (
     (EFI_IO_BUS_USB | EFI_IOB_PC_DETECT),\r
     UsbBus->DevicePath\r
     );\r
-  \r
+\r
   Status                  = mUsbRootHubApi.Init (RootIf);\r
 \r
   if (EFI_ERROR (Status)) {\r
@@ -1146,7 +1151,7 @@ UsbBusControllerDriverSupported (
   //\r
   if (RemainingDevicePath != NULL) {\r
     //\r
-    // Check if RemainingDevicePath is the End of Device Path Node, \r
+    // Check if RemainingDevicePath is the End of Device Path Node,\r
     // if yes, go on checking other conditions\r
     //\r
     if (!IsDevicePathEnd (RemainingDevicePath)) {\r
@@ -1155,13 +1160,13 @@ UsbBusControllerDriverSupported (
       // check its validation\r
       //\r
       DevicePathNode.DevPath = RemainingDevicePath;\r
-      \r
+\r
       if ((DevicePathNode.DevPath->Type    != MESSAGING_DEVICE_PATH) ||\r
           (DevicePathNode.DevPath->SubType != MSG_USB_DP &&\r
            DevicePathNode.DevPath->SubType != MSG_USB_CLASS_DP\r
            && DevicePathNode.DevPath->SubType != MSG_USB_WWID_DP\r
            )) {\r
-      \r
+\r
         return EFI_UNSUPPORTED;\r
       }\r
     }\r
@@ -1197,7 +1202,7 @@ UsbBusControllerDriverSupported (
     if (Status == EFI_ALREADY_STARTED) {\r
       return EFI_SUCCESS;\r
     }\r
-  \r
+\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
@@ -1224,7 +1229,7 @@ UsbBusControllerDriverSupported (
            Controller\r
            );\r
   }\r
\r
+\r
   //\r
   // Open the EFI Device Path protocol needed to perform the supported test\r
   //\r
@@ -1351,7 +1356,7 @@ UsbBusControllerDriverStart (
         //\r
         // If RemainingDevicePath is the End of Device Path Node,\r
         // skip enumerate any device and return EFI_SUCESSS\r
-        // \r
+        //\r
         return EFI_SUCCESS;\r
       }\r
     }\r