reconsideration of USB protocol

revert UUID endianess to traitional

Signed-off-by: SergeySlice <sergey.slice@gmail.com>
This commit is contained in:
SergeySlice 2022-05-07 17:03:25 +03:00
parent 12b589410a
commit 8fc250a95c
18 changed files with 142 additions and 120 deletions

View File

@ -3,13 +3,7 @@
UEFI Component Name(2) protocol implementation for Usb Bus driver.
Copyright (c) 2004 - 2011, 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
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

View File

@ -2,14 +2,8 @@
Usb Bus Driver Binding and Bus IO Protocol.
Copyright (c) 2004 - 2016, 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
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@ -95,6 +89,7 @@ UsbIoControlTransfer (
USB_ENDPOINT_DESC *EpDesc;
EFI_TPL OldTpl;
EFI_STATUS Status;
UINTN RequestedDataLength;
if (UsbStatus == NULL) {
return EFI_INVALID_PARAMETER;
@ -105,6 +100,7 @@ UsbIoControlTransfer (
UsbIf = USB_INTERFACE_FROM_USBIO (This);
Dev = UsbIf->Device;
RequestedDataLength = DataLength;
Status = UsbHcControlTransfer (
Dev->Bus,
Dev->Address,
@ -118,6 +114,18 @@ UsbIoControlTransfer (
&Dev->Translator,
UsbStatus
);
//
// If the request completed sucessfully and the Direction of the request is
// EfiUsbDataIn or EfiUsbDataOut, then make sure the actual number of bytes
// transfered is the same as the number of bytes requested. If a different
// number of bytes were transfered, then return EFI_DEVICE_ERROR.
//
if (!EFI_ERROR(Status)) {
if (Direction != EfiUsbNoData && DataLength != RequestedDataLength) {
Status = EFI_DEVICE_ERROR;
goto ON_EXIT;
}
}
if (EFI_ERROR(Status) || (*UsbStatus != EFI_USB_NOERROR)) {
//
@ -282,7 +290,7 @@ UsbIoBulkTransfer (
Dev->Speed,
EpDesc->Desc.MaxPacketSize,
BufNum,
&Data,
Data,
DataLength,
&Toggle,
Timeout,
@ -297,7 +305,7 @@ UsbIoBulkTransfer (
// Clear TT buffer when CTRL/BULK split transaction failes.
// Clear the TRANSLATOR TT buffer, not parent's buffer
//
ASSERT (Dev->Translator.TranslatorHubAddress < Dev->Bus->MaxDevices);
// ASSERT (Dev->Translator.TranslatorHubAddress < Dev->Bus->MaxDevices);
if (Dev->Translator.TranslatorHubAddress != 0) {
UsbHubCtrlClearTTBuffer (
Dev->Bus->Devices[Dev->Translator.TranslatorHubAddress],

View File

@ -2,14 +2,8 @@
Usb Bus Driver Binding and Bus IO Protocol.
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
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

View File

@ -1,15 +1,9 @@
## @file
# The Usb Bus Dxe driver is used to enumerate and manage all attached usb devices.
#
# Copyright (c) 2006 - 2014, 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
# http://opensource.org/licenses/bsd-license.php
# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
#
##
@ -27,9 +21,9 @@
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
# VALID_ARCHITECTURES = IA32 X64 EBC ARM AARCH64
#
# DRIVER_BINDING = mUsbBusDriverBinding
# DRIVER_BINDING = mUsbBusDriverBinding
# COMPONENT_NAME = mUsbBusComponentName
# COMPONENT_NAME2 = mUsbBusComponentName2
#
@ -66,7 +60,9 @@
[Protocols]
gEfiUsbIoProtocolGuid ## BY_START
gEfiDevicePathProtocolGuid ## BY_START
## TO_START
## BY_START
gEfiDevicePathProtocolGuid
gEfiUsb2HcProtocolGuid ## TO_START
gEfiUsbHcProtocolGuid ## TO_START

Binary file not shown.

Binary file not shown.

View File

@ -2,14 +2,8 @@
Manage Usb Descriptor List
Copyright (c) 2007 - 2016, 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
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@ -177,6 +171,18 @@ UsbCreateDesc (
DescLen = sizeof (EFI_USB_ENDPOINT_DESCRIPTOR);
CtrlLen = sizeof (USB_ENDPOINT_DESC);
break;
default:
// ASSERT (FALSE);
return NULL;
}
//
// Total length is too small that cannot hold the single descriptor header plus data.
//
if (Len <= sizeof (USB_DESC_HEAD)) {
DEBUG ((DEBUG_ERROR, "UsbCreateDesc: met mal-format descriptor, total length = %d!\n", Len));
return NULL;
}
//
@ -184,24 +190,44 @@ UsbCreateDesc (
// format. Skip the descriptor that isn't of this Type
//
Offset = 0;
Head = (USB_DESC_HEAD*)DescBuf;
Head = (USB_DESC_HEAD *)DescBuf;
while (Offset < Len - sizeof (USB_DESC_HEAD)) {
//
// Above condition make sure Head->Len and Head->Type are safe to access
//
Head = (USB_DESC_HEAD *)&DescBuf[Offset];
while ((Offset < Len) && (Head->Type != Type)) {
Offset += Head->Len;
if (Len <= Offset) {
DEBUG (( EFI_D_ERROR, "UsbCreateDesc: met mal-format descriptor, Beyond boundary!\n"));
if (Head->Len == 0) {
DEBUG ((DEBUG_ERROR, "UsbCreateDesc: met mal-format descriptor, Head->Len = 0!\n"));
return NULL;
}
Head = (USB_DESC_HEAD*)(DescBuf + Offset);
if (Head->Len == 0) {
DEBUG (( EFI_D_ERROR, "UsbCreateDesc: met mal-format descriptor, Head->Len = 0!\n"));
//
// Make sure no overflow when adding Head->Len to Offset.
//
if (Head->Len > MAX_UINTN - Offset) {
DEBUG ((DEBUG_ERROR, "UsbCreateDesc: met mal-format descriptor, Head->Len = %d!\n", Head->Len));
return NULL;
}
Offset += Head->Len;
if (Head->Type == Type) {
break;
}
}
if ((Len <= Offset) || (Len < Offset + Head->Len) ||
(Head->Type != Type) || (Head->Len < DescLen)) {
DEBUG (( EFI_D_ERROR, "UsbCreateDesc: met mal-format descriptor\n"));
//
// Head->Len is invalid resulting data beyond boundary, or
// Descriptor cannot be found: No such type.
//
if (Len < Offset) {
DEBUG ((DEBUG_ERROR, "UsbCreateDesc: met mal-format descriptor, Offset/Len = %d/%d!\n", Offset, Len));
return NULL;
}
if ((Head->Type != Type) || (Head->Len < DescLen)) {
DEBUG ((DEBUG_ERROR, "UsbCreateDesc: descriptor cannot be found, Header(T/L) = %d/%d!\n", Head->Type, Head->Len));
return NULL;
}
@ -212,7 +238,7 @@ UsbCreateDesc (
CopyMem(Desc, Head, (UINTN) DescLen);
*Consumed = Offset + Head->Len;
*Consumed = Offset;
return Desc;
}
@ -627,7 +653,13 @@ UsbGetOneString (
//
Status = UsbCtrlGetDesc (UsbDev, USB_DESC_TYPE_STRING, Index, LangId, &Desc, 2);
if (EFI_ERROR(Status)) {
//
// Reject if Length even cannot cover itself, or odd because Unicode string byte length should be even.
//
if (EFI_ERROR(Status) ||
(Desc.Length < OFFSET_OF (EFI_USB_STRING_DESCRIPTOR, Length) + sizeof (Desc.Length)) ||
(Desc.Length % 2 != 0)
) {
return NULL;
}
@ -744,6 +776,13 @@ UsbGetOneConfig (
DEBUG (( EFI_D_INFO, "UsbGetOneConfig: total length is %d\n", Desc.TotalLength));
//
// Reject if TotalLength even cannot cover itself.
//
if (Desc.TotalLength < OFFSET_OF (EFI_USB_CONFIG_DESCRIPTOR, TotalLength) + sizeof (Desc.TotalLength)) {
return NULL;
}
Buf = AllocateZeroPool(Desc.TotalLength);
if (Buf == NULL) {

View File

@ -3,13 +3,7 @@
Manage Usb Descriptor List
Copyright (c) 2007 - 2014, 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
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

View File

@ -2,14 +2,8 @@
Usb bus enumeration support.
Copyright (c) 2007 - 2013, 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
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@ -71,28 +65,33 @@ UsbGetEndpointDesc (
@param UsbIf The USB interface to free.
**/
VOID
@retval EFI_ACCESS_DENIED The interface is still occupied.
@retval EFI_SUCCESS The interface is freed.
**/
EFI_STATUS
UsbFreeInterface (
IN USB_INTERFACE *UsbIf
)
{
EFI_STATUS Status;
UsbCloseHostProtoByChild (UsbIf->Device->Bus, UsbIf->Handle);
gBS->UninstallMultipleProtocolInterfaces (
UsbIf->Handle,
&gEfiDevicePathProtocolGuid,
UsbIf->DevicePath,
&gEfiUsbIoProtocolGuid,
&UsbIf->UsbIo,
NULL
);
if (UsbIf->DevicePath != NULL) {
FreePool(UsbIf->DevicePath);
}
FreePool(UsbIf);
Status = gBS->UninstallMultipleProtocolInterfaces (
UsbIf->Handle,
&gEfiDevicePathProtocolGuid, UsbIf->DevicePath,
&gEfiUsbIoProtocolGuid, &UsbIf->UsbIo,
NULL
);
if (!EFI_ERROR(Status)) {
if (UsbIf->DevicePath != NULL) {
FreePool(UsbIf->DevicePath);
}
FreePool(UsbIf);
} else {
UsbOpenHostProtoByChild (UsbIf->Device->Bus, UsbIf->Handle);
}
return Status;
}
@ -185,7 +184,7 @@ UsbCreateInterface (
if (EFI_ERROR(Status)) {
gBS->UninstallMultipleProtocolInterfaces (
&UsbIf->Handle,
UsbIf->Handle,
&gEfiDevicePathProtocolGuid,
UsbIf->DevicePath,
&gEfiUsbIoProtocolGuid,

View File

@ -2,14 +2,8 @@
The definition for USB hub.
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
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@ -96,7 +90,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#define USB_HUB_SUBCLASS_CODE 0x00
//
// Host software return timeout if port status doesn't change
// Host software return timeout if port status doesn't change
// after 500ms(LOOP * STALL = 5000 * 0.1ms), set by experience
//
#define USB_WAIT_PORT_STS_CHANGE_LOOP 5000

View File

@ -386,7 +386,7 @@ UsbHcBulkTransfer (
IN UINT8 DevSpeed,
IN UINTN MaxPacket,
IN UINT8 BufferNum,
IN OUT VOID *Data[EFI_USB_MAX_BULK_BUFFER_NUM],
IN OUT VOID **Data, //[EFI_USB_MAX_BULK_BUFFER_NUM],
IN OUT UINTN *DataLength,
IN OUT UINT8 *DataToggle,
IN UINTN TimeOut,

View File

@ -3,13 +3,7 @@
Manage Usb Port/Hc/Etc.
Copyright (c) 2007, 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
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@ -204,7 +198,7 @@ UsbHcBulkTransfer (
IN UINT8 DevSpeed,
IN UINTN MaxPacket,
IN UINT8 BufferNum,
IN OUT VOID *Data[EFI_USB_MAX_BULK_BUFFER_NUM],
IN OUT VOID **Data, //[EFI_USB_MAX_BULK_BUFFER_NUM],
IN OUT UINTN *DataLength,
IN OUT UINT8 *DataToggle,
IN UINTN TimeOut,

View File

@ -800,7 +800,10 @@ XhcTransfer (
EFI_STATUS RecoveryStatus;
URB *Urb;
ASSERT ((Type == XHC_CTRL_TRANSFER) || (Type == XHC_BULK_TRANSFER) || (Type == XHC_INT_TRANSFER_SYNC));
// ASSERT ((Type == XHC_CTRL_TRANSFER) || (Type == XHC_BULK_TRANSFER) || (Type == XHC_INT_TRANSFER_SYNC));
if ((Type != XHC_CTRL_TRANSFER) && (Type != XHC_BULK_TRANSFER) && (Type != XHC_INT_TRANSFER_SYNC)) {
return EFI_INVALID_PARAMETER;
}
Urb = XhcCreateUrb (
Xhc,
DeviceAddress,
@ -832,7 +835,10 @@ XhcTransfer (
// The URB is finished just before stopping endpoint.
// Change returning status from EFI_TIMEOUT to EFI_SUCCESS.
//
ASSERT (Urb->Result == EFI_USB_NOERROR);
// ASSERT (Urb->Result == EFI_USB_NOERROR);
if (Urb->Result != EFI_USB_NOERROR) {
return EFI_DEVICE_ERROR;
}
Status = EFI_SUCCESS;
DEBUG ((DEBUG_ERROR, "XhcTransfer[Type=%d]: pending URB is finished, Length = %d.\n", Type, Urb->Completed));
} else if (EFI_ERROR(RecoveryStatus)) {
@ -844,7 +850,7 @@ XhcTransfer (
*DataLength = Urb->Completed;
if ((*TransferResult == EFI_USB_ERR_STALL) || (*TransferResult == EFI_USB_ERR_BABBLE)) {
ASSERT (Status == EFI_DEVICE_ERROR);
// ASSERT (Status == EFI_DEVICE_ERROR);
RecoveryStatus = XhcRecoverHaltedEndpoint(Xhc, Urb);
if (EFI_ERROR(RecoveryStatus)) {
DEBUG ((DEBUG_ERROR, "XhcTransfer[Type=%d]: XhcRecoverHaltedEndpoint failed!\n", Type));
@ -1285,7 +1291,7 @@ XhcBulkTransfer (
IN UINT8 DeviceSpeed,
IN UINTN MaximumPacketLength,
IN UINT8 DataBuffersNumber,
IN OUT VOID *Data[EFI_USB_MAX_BULK_BUFFER_NUM],
IN OUT VOID **Data, //[EFI_USB_MAX_BULK_BUFFER_NUM],
IN OUT UINTN *DataLength,
IN OUT UINT8 *DataToggle,
IN UINTN Timeout,
@ -1302,7 +1308,7 @@ XhcBulkTransfer (
// Validate the parameters
//
if ((DataLength == NULL) || (*DataLength == 0) ||
(Data == NULL) || (Data[0] == NULL) || (TransferResult == NULL)) {
(Data == NULL) || (*Data == NULL) || (TransferResult == NULL)) {
return EFI_INVALID_PARAMETER;
}
@ -1350,10 +1356,10 @@ XhcBulkTransfer (
MaximumPacketLength,
XHC_BULK_TRANSFER,
NULL,
Data[0],
DataLength,
Timeout,
TransferResult
*Data,
DataLength,
Timeout,
TransferResult
);
ON_EXIT:

View File

@ -562,7 +562,7 @@ XhcBulkTransfer (
IN UINT8 DeviceSpeed,
IN UINTN MaximumPacketLength,
IN UINT8 DataBuffersNumber,
IN OUT VOID *Data[EFI_USB_MAX_BULK_BUFFER_NUM],
IN OUT VOID **Data, //[EFI_USB_MAX_BULK_BUFFER_NUM],
IN OUT UINTN *DataLength,
IN OUT UINT8 *DataToggle,
IN UINTN Timeout,

View File

@ -298,7 +298,7 @@ EFI_STATUS
IN UINT8 DeviceSpeed,
IN UINTN MaximumPacketLength,
IN UINT8 DataBuffersNumber,
IN OUT VOID *Data[EFI_USB_MAX_BULK_BUFFER_NUM],
IN OUT VOID **Data, //[EFI_USB_MAX_BULK_BUFFER_NUM],
IN OUT UINTN *DataLength,
IN OUT UINT8 *DataToggle,
IN UINTN TimeOut,

View File

@ -76,7 +76,7 @@ public:
EFI_GUID dgetCustomUuid() const {
if ( !CustomUUID.isDefined() ) return nullGuid;
EFI_GUID g;
g.takeValueFrom(CustomUUID.value());
g.takeValueFromBE(CustomUUID.value());
return g;
}
UINT8 dget_InjectSystemID() const { return InjectSystemID.isDefined() ? (int)InjectSystemID.value() : 2; }

View File

@ -671,7 +671,7 @@ public:
EFI_GUID dgetSmUUID() const {
if ( !SmUUID.isDefined() ) return nullGuid;
EFI_GUID g;
g.takeValueFrom(SmUUID.value());
g.takeValueFromBE(SmUUID.value());
if ( g.isNull() ) panic("SmUUID is not valid. This could not happen because SmUUID is checked to be valid. Did you comment out the validation ?");
return g;
}

View File

@ -2798,6 +2798,10 @@ RefitMain (IN EFI_HANDLE ImageHandle,
// For example, if you do "gCPUStructure.TSCCalibr = GetMemLogTscTicksPerSecond();" before this point, it will be erased by construct_globals_objects()
construct_globals_objects(gImageHandle);
#endif
#ifdef DEBUG_ERALY_CRASH
SystemTable->ConOut->OutputString(SystemTable->ConOut, L"Step41");
PauseForKey("press any key\n"_XS8);
#endif
gCPUStructure.TSCCalibr = GetMemLogTscTicksPerSecond(); //ticks for 1second