From nobody Mon Feb 9 07:05:35 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+46992+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+46992+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1567807941; cv=none; d=zoho.com; s=zohoarc; b=RDm8EzDs6euUOUZTqapkAKJ8S/jQW0XcWIapnTxOoFTVAyHGGGRgqVwk1/TZWxg89+zgtODVCue+PZ3pwzjfgUGdHp5MAyB/EoXYkBeI/Qcvl80vBE2fBYLDpvWubMmjhevlccbCH3JapmAGOE6PCQbFI9OYDabJffswHUs0X/A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567807941; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=DaOlANfNbFlQyMh+YzYOKEAx9zS79WAXlwFt1SEOONU=; b=iW0IkS1PJkM1hGZjLbxQtn5sjWjlJ8CeUMyAy7PfXpbTglPxRzqNyiaq5K5sCUIYGjRVGSxwr96mgAFiEpVZM8OKSRbun59CDDK7KrZAydT014HI3kYB5A3uEwsfxIpVR+G5bnVD7I/k7yuTp9WMAriAuTyW1Z6KYoc+WSmbIwc= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+46992+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1567807941423400.18055708621944; Fri, 6 Sep 2019 15:12:21 -0700 (PDT) Return-Path: X-Received: from mga05.intel.com (mga05.intel.com []) by groups.io with SMTP; Fri, 06 Sep 2019 15:12:19 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Sep 2019 15:12:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,474,1559545200"; d="scan'208";a="195568578" X-Received: from cjzurch-desk.amr.corp.intel.com ([10.9.70.181]) by orsmga002.jf.intel.com with ESMTP; 06 Sep 2019 15:12:17 -0700 From: "Zurcher, Christopher J" To: devel@edk2.groups.io Cc: Jiewen Yao , Jian J Wang , Liming Gao Subject: [edk2-devel] [PATCH v6 1/4] MdePkg: Implement SCSI commands for Security Protocol In/Out Date: Fri, 6 Sep 2019 15:12:13 -0700 Message-Id: <20190906221217.34180-2-christopher.j.zurcher@intel.com> In-Reply-To: <20190906221217.34180-1-christopher.j.zurcher@intel.com> References: <20190906221217.34180-1-christopher.j.zurcher@intel.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,christopher.j.zurcher@intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1567807940; bh=DJ6NNxASdv1Mg/WQdgF6dNjbRW0Tiv+WpJteEbMA6fc=; h=Cc:Date:From:Reply-To:Subject:To; b=Rnmhnq5d7ZRgeMYMuG606Be7U1vwcn4o/92HyRrw57R1CFcVsTbofdMoZSsbLZ8vxwK v6q8ALoGoq00ZYm2gPkhr07Ju91VQWPxf9oNV9sQQlMmRqH+//SDf46pdaI3CU7y8pu9w oS9vF+cWtwLsIPZq2JdgLsrIvUuCgtICVJs= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1546 This patch implements the Security Protocol In and Security Protocol Out commands in UefiScsiLib to prepare support for the Storage Security Command Protocol. Cc: Jiewen Yao Cc: Jian J Wang Cc: Liming Gao Signed-off-by: Christopher J Zurcher --- MdePkg/Include/IndustryStandard/Scsi.h | 48 +++-- MdePkg/Include/Library/UefiScsiLib.h | 128 +++++++++++- MdePkg/Library/UefiScsiLib/UefiScsiLib.c | 217 +++++++++++++++++++- 3 files changed, 374 insertions(+), 19 deletions(-) diff --git a/MdePkg/Include/IndustryStandard/Scsi.h b/MdePkg/Include/Indust= ryStandard/Scsi.h index cbe5709fe5..d03886417f 100644 --- a/MdePkg/Include/IndustryStandard/Scsi.h +++ b/MdePkg/Include/IndustryStandard/Scsi.h @@ -1,7 +1,7 @@ /** @file Support for SCSI-2 standard =20 - Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -163,6 +163,12 @@ #define EFI_SCSI_OP_SEND_MESSAGE10 0x2a #define EFI_SCSI_OP_SEND_MESSAGE12 0xaa =20 +// +// Additional commands for Secure Transactions +// +#define EFI_SCSI_OP_SECURITY_PROTOCOL_IN 0xa2 +#define EFI_SCSI_OP_SECURITY_PROTOCOL_OUT 0xb5 + // // SCSI Data Transfer Direction // @@ -172,22 +178,30 @@ // // Peripheral Device Type Definitions // -#define EFI_SCSI_TYPE_DISK 0x00 ///< Direct-access device (e.g. = magnetic disk) -#define EFI_SCSI_TYPE_TAPE 0x01 ///< Sequential-access device (e= .g. magnetic tape) -#define EFI_SCSI_TYPE_PRINTER 0x02 ///< Printer device -#define EFI_SCSI_TYPE_PROCESSOR 0x03 ///< Processor device -#define EFI_SCSI_TYPE_WORM 0x04 ///< Write-once device (e.g. som= e optical disks) -#define EFI_SCSI_TYPE_CDROM 0x05 ///< CD-ROM device -#define EFI_SCSI_TYPE_SCANNER 0x06 ///< Scanner device -#define EFI_SCSI_TYPE_OPTICAL 0x07 ///< Optical memory device (e.g.= some optical disks) -#define EFI_SCSI_TYPE_MEDIUMCHANGER 0x08 ///< Medium changer device (e.g.= jukeboxes) -#define EFI_SCSI_TYPE_COMMUNICATION 0x09 ///< Communications device -#define EFI_SCSI_TYPE_ASCIT8_1 0x0A ///< Defined by ASC IT8 (Graphic= arts pre-press devices) -#define EFI_SCSI_TYPE_ASCIT8_2 0x0B ///< Defined by ASC IT8 (Graphic= arts pre-press devices) -// -// 0Ch - 1Eh are reserved -// -#define EFI_SCSI_TYPE_UNKNOWN 0x1F ///< Unknown or no device type +#define EFI_SCSI_TYPE_DISK 0x00 ///< Direct-access device (e.g= . magnetic disk) +#define EFI_SCSI_TYPE_TAPE 0x01 ///< Sequential-access device = (e.g. magnetic tape) +#define EFI_SCSI_TYPE_PRINTER 0x02 ///< Printer device +#define EFI_SCSI_TYPE_PROCESSOR 0x03 ///< Processor device +#define EFI_SCSI_TYPE_WORM 0x04 ///< Write-once device (e.g. s= ome optical disks) +#define EFI_SCSI_TYPE_CDROM 0x05 ///< CD/DVD device +#define EFI_SCSI_TYPE_SCANNER 0x06 ///< Scanner device (obsolete) +#define EFI_SCSI_TYPE_OPTICAL 0x07 ///< Optical memory device (e.= g. some optical disks) +#define EFI_SCSI_TYPE_MEDIUMCHANGER 0x08 ///< Medium changer device (e.= g. jukeboxes) +#define EFI_SCSI_TYPE_COMMUNICATION 0x09 ///< Communications device (ob= solete) +#define EFI_SCSI_TYPE_ASCIT8_1 0x0A ///< Defined by ASC IT8 (Graph= ic arts pre-press devices) +#define EFI_SCSI_TYPE_ASCIT8_2 0x0B ///< Defined by ASC IT8 (Graph= ic arts pre-press devices) +#define EFI_SCSI_TYPE_RAID 0x0C ///< Storage array controller = device (e.g., RAID) +#define EFI_SCSI_TYPE_SES 0x0D ///< Enclosure services device +#define EFI_SCSI_TYPE_RBC 0x0E ///< Simplified direct-access = device (e.g., magnetic disk) +#define EFI_SCSI_TYPE_OCRW 0x0F ///< Optical card reader/write= r device +#define EFI_SCSI_TYPE_BRIDGE 0x10 ///< Bridge Controller Commands +#define EFI_SCSI_TYPE_OSD 0x11 ///< Object-based Storage Devi= ce +#define EFI_SCSI_TYPE_AUTOMATION 0x12 ///< Automation/Drive Interface +#define EFI_SCSI_TYPE_SECURITYMANAGER 0x13 ///< Security manager device +#define EFI_SCSI_TYPE_RESERVED_LOW 0x14 ///< Reserved (low) +#define EFI_SCSI_TYPE_RESERVED_HIGH 0x1D ///< Reserved (high) +#define EFI_SCSI_TYPE_WLUN 0x1E ///< Well known logical unit +#define EFI_SCSI_TYPE_UNKNOWN 0x1F ///< Unknown or no device type =20 // // Page Codes for INQUIRY command diff --git a/MdePkg/Include/Library/UefiScsiLib.h b/MdePkg/Include/Library/= UefiScsiLib.h index 10dd81902b..5c94b0aa16 100644 --- a/MdePkg/Include/Library/UefiScsiLib.h +++ b/MdePkg/Include/Library/UefiScsiLib.h @@ -5,7 +5,7 @@ for hard drive, CD and DVD devices that are the most common SCSI boot ta= rgets used by UEFI platforms. This library class depends on SCSI I/O Protocol defined in UEFI Specific= ation and SCSI-2 industry standard. =20 -Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -813,6 +813,132 @@ ScsiWrite16Command ( ); =20 =20 +/** + Execute Security Protocol In SCSI command on a specific SCSI target. + + Executes the SCSI Security Protocol In command on the SCSI target specif= ied by ScsiIo. + If Timeout is zero, then this function waits indefinitely for the comman= d to complete. + If Timeout is greater than zero, then the command is executed and will t= imeout after + Timeout 100 ns units. + If ScsiIo is NULL, then ASSERT(). + If SenseDataLength is NULL, then ASSERT(). + If HostAdapterStatus is NULL, then ASSERT(). + If TargetStatus is NULL, then ASSERT(). + If TransferLength is NULL, then ASSERT(). + + If SenseDataLength is non-zero and SenseData is not NULL, SenseData must= meet buffer + alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INV= ALID_PARAMETER + gets returned. + + If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must me= et buffer + alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INV= ALID_PARAMETER + gets returned. + + @param[in] ScsiIo SCSI IO Protocol to use. + @param[in] Timeout The length of timeout period. + @param[in, out] SenseData A pointer to output sense data. + @param[in, out] SenseDataLength The length of output sense dat= a. + @param[out] HostAdapterStatus The status of Host Adapter. + @param[out] TargetStatus The status of the target. + @param[in] SecurityProtocol The Security Protocol to use. + @param[in] SecurityProtocolSpecific The Security Protocol Specific= data. + @param[in] Inc512 If Inc512 is TRUE, DataLength = is expressed in 512-byte increments. + @param[in] DataLength The size in bytes of the data = buffer. + @param[in, out] DataBuffer A pointer to a data buffer. + @param[out] TransferLength A pointer to a buffer to store= the size in + bytes of the data written to t= he data buffer. + + @retval EFI_SUCCESS Command is executed successfully. + @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was execute= d, but the entire DataBuffer could + not be transferred. The actual numb= er of bytes transferred is returned in TransferLength. + @retval EFI_NOT_READY The SCSI Request Packet could not b= e sent because there are too many + SCSI Command Packets already queued. + @retval EFI_DEVICE_ERROR A device error occurred while attem= pting to send SCSI Request Packet. + @retval EFI_UNSUPPORTED The command described by the SCSI R= equest Packet is not supported by + the SCSI initiator(i.e., SCSI Host= Controller) + @retval EFI_TIMEOUT A timeout occurred while waiting fo= r the SCSI Request Packet to execute. + @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Pa= cket are invalid. + +**/ +EFI_STATUS +EFIAPI +ScsiSecurityProtocolInCommand ( + IN EFI_SCSI_IO_PROTOCOL *ScsiIo, + IN UINT64 Timeout, + IN OUT VOID *SenseData, OPTIONAL + IN OUT UINT8 *SenseDataLength, + OUT UINT8 *HostAdapterStatus, + OUT UINT8 *TargetStatus, + IN UINT8 SecurityProtocol, + IN UINT16 SecurityProtocolSpecific, + IN BOOLEAN Inc512, + IN UINTN DataLength, + IN OUT VOID *DataBuffer, OPTIONAL + OUT UINTN *TransferLength + ); + + +/** + Execute Security Protocol Out SCSI command on a specific SCSI target. + + Executes the SCSI Security Protocol Out command on the SCSI target speci= fied by ScsiIo. + If Timeout is zero, then this function waits indefinitely for the comman= d to complete. + If Timeout is greater than zero, then the command is executed and will t= imeout after + Timeout 100 ns units. + If ScsiIo is NULL, then ASSERT(). + If SenseDataLength is NULL, then ASSERT(). + If HostAdapterStatus is NULL, then ASSERT(). + If TargetStatus is NULL, then ASSERT(). + + If SenseDataLength is non-zero and SenseData is not NULL, SenseData must= meet buffer + alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INV= ALID_PARAMETER + gets returned. + + If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must me= et buffer + alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INV= ALID_PARAMETER + gets returned. + + @param[in] ScsiIo SCSI IO Protocol to use. + @param[in] Timeout The length of timeout period. + @param[in, out] SenseData A pointer to output sense data. + @param[in, out] SenseDataLength The length of output sense dat= a. + @param[out] HostAdapterStatus The status of Host Adapter. + @param[out] TargetStatus The status of the target. + @param[in] SecurityProtocol The Security Protocol to use. + @param[in] SecurityProtocolSpecific The Security Protocol Specific= data. + @param[in] Inc512 If Inc512 is TRUE, DataLength = is expressed in 512-byte increments. + @param[in] DataLength The size in bytes of the trans= fer data. + @param[in, out] DataBuffer A pointer to a data buffer. + + @retval EFI_SUCCESS Command is executed successfully. + @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was execute= d, but the entire DataBuffer could + not be transferred. The actual numb= er of bytes transferred is returned in DataLength. + @retval EFI_NOT_READY The SCSI Request Packet could not b= e sent because there are too many + SCSI Command Packets already queued. + @retval EFI_DEVICE_ERROR A device error occurred while attem= pting to send SCSI Request Packet. + @retval EFI_UNSUPPORTED The command described by the SCSI R= equest Packet is not supported by + the SCSI initiator(i.e., SCSI Host= Controller) + @retval EFI_TIMEOUT A timeout occurred while waiting fo= r the SCSI Request Packet to execute. + @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Pa= cket are invalid. + +**/ +EFI_STATUS +EFIAPI +ScsiSecurityProtocolOutCommand ( + IN EFI_SCSI_IO_PROTOCOL *ScsiIo, + IN UINT64 Timeout, + IN OUT VOID *SenseData, OPTIONAL + IN OUT UINT8 *SenseDataLength, + OUT UINT8 *HostAdapterStatus, + OUT UINT8 *TargetStatus, + IN UINT8 SecurityProtocol, + IN UINT16 SecurityProtocolSpecific, + IN BOOLEAN Inc512, + IN UINTN DataLength, + IN OUT VOID *DataBuffer OPTIONAL + ); + + /** Execute blocking/non-blocking Read(10) SCSI command on a specific SCSI target. diff --git a/MdePkg/Library/UefiScsiLib/UefiScsiLib.c b/MdePkg/Library/Uefi= ScsiLib/UefiScsiLib.c index c7491d1436..229fe11ef2 100644 --- a/MdePkg/Library/UefiScsiLib/UefiScsiLib.c +++ b/MdePkg/Library/UefiScsiLib/UefiScsiLib.c @@ -1,7 +1,7 @@ /** @file UEFI SCSI Library implementation =20 - Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -23,6 +23,7 @@ // #define EFI_SCSI_OP_LENGTH_SIX 0x6 #define EFI_SCSI_OP_LENGTH_TEN 0xa +#define EFI_SCSI_OP_LENGTH_TWELVE 0xc #define EFI_SCSI_OP_LENGTH_SIXTEEN 0x10 =20 // @@ -1280,6 +1281,220 @@ ScsiWrite16Command ( } =20 =20 +/** + Execute Security Protocol In SCSI command on a specific SCSI target. + + Executes the SCSI Security Protocol In command on the SCSI target specif= ied by ScsiIo. + If Timeout is zero, then this function waits indefinitely for the comman= d to complete. + If Timeout is greater than zero, then the command is executed and will t= imeout after + Timeout 100 ns units. + If ScsiIo is NULL, then ASSERT(). + If SenseDataLength is NULL, then ASSERT(). + If HostAdapterStatus is NULL, then ASSERT(). + If TargetStatus is NULL, then ASSERT(). + If TransferLength is NULL, then ASSERT(). + + If SenseDataLength is non-zero and SenseData is not NULL, SenseData must= meet buffer + alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INV= ALID_PARAMETER + gets returned. + + If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must me= et buffer + alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INV= ALID_PARAMETER + gets returned. + + @param[in] ScsiIo SCSI IO Protocol to use. + @param[in] Timeout The length of timeout period. + @param[in, out] SenseData A pointer to output sense data. + @param[in, out] SenseDataLength The length of output sense dat= a. + @param[out] HostAdapterStatus The status of Host Adapter. + @param[out] TargetStatus The status of the target. + @param[in] SecurityProtocol The Security Protocol to use. + @param[in] SecurityProtocolSpecific The Security Protocol Specific= data. + @param[in] Inc512 If Inc512 is TRUE, DataLength = is expressed in 512-byte increments. + @param[in] DataLength The size in bytes of the data = buffer. + @param[in, out] DataBuffer A pointer to a data buffer. + @param[out] TransferLength A pointer to a buffer to store= the size in + bytes of the data written to t= he data buffer. + + @retval EFI_SUCCESS Command is executed successfully. + @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was execute= d, but the entire DataBuffer could + not be transferred. The actual numb= er of bytes transferred is returned in TransferLength. + @retval EFI_NOT_READY The SCSI Request Packet could not b= e sent because there are too many + SCSI Command Packets already queued. + @retval EFI_DEVICE_ERROR A device error occurred while attem= pting to send SCSI Request Packet. + @retval EFI_UNSUPPORTED The command described by the SCSI R= equest Packet is not supported by + the SCSI initiator(i.e., SCSI Host= Controller) + @retval EFI_TIMEOUT A timeout occurred while waiting fo= r the SCSI Request Packet to execute. + @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Pa= cket are invalid. + +**/ +EFI_STATUS +EFIAPI +ScsiSecurityProtocolInCommand ( + IN EFI_SCSI_IO_PROTOCOL *ScsiIo, + IN UINT64 Timeout, + IN OUT VOID *SenseData, OPTIONAL + IN OUT UINT8 *SenseDataLength, + OUT UINT8 *HostAdapterStatus, + OUT UINT8 *TargetStatus, + IN UINT8 SecurityProtocol, + IN UINT16 SecurityProtocolSpecific, + IN BOOLEAN Inc512, + IN UINTN DataLength, + IN OUT VOID *DataBuffer, OPTIONAL + OUT UINTN *TransferLength + ) +{ + EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket; + EFI_STATUS Status; + UINT8 Cdb[EFI_SCSI_OP_LENGTH_TWELVE]; + + ASSERT (SenseDataLength !=3D NULL); + ASSERT (HostAdapterStatus !=3D NULL); + ASSERT (TargetStatus !=3D NULL); + ASSERT (ScsiIo !=3D NULL); + ASSERT (TransferLength !=3D NULL); + ASSERT (DataLength <=3D MAX_UINT32); + + ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET)); + ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_TWELVE); + + CommandPacket.Timeout =3D Timeout; + CommandPacket.InDataBuffer =3D DataBuffer; + CommandPacket.SenseData =3D SenseData; + CommandPacket.InTransferLength =3D (UINT32) DataLength; + CommandPacket.Cdb =3D Cdb; + // + // Fill Cdb for Security Protocol In Command + // + Cdb[0] =3D EFI_SCSI_OP_SECURITY_PROTOCOL_IN; + Cdb[1] =3D SecurityProtocol; + WriteUnaligned16 ((UINT16 *)&Cdb[2], SwapBytes16 (SecurityProtocolSpecif= ic)); + WriteUnaligned32 ((UINT32 *)&Cdb[6], SwapBytes32 ((UINT32) DataLength)); + + if (Inc512) { + Cdb[4] =3D BIT7; + } + + CommandPacket.CdbLength =3D EFI_SCSI_OP_LENGTH_TWELVE; + CommandPacket.DataDirection =3D EFI_SCSI_DATA_IN; + CommandPacket.SenseDataLength =3D *SenseDataLength; + + Status =3D ScsiIo->ExecuteScsiCommand (ScsiIo, &C= ommandPacket, NULL); + + *HostAdapterStatus =3D CommandPacket.HostAdapterStatus; + *TargetStatus =3D CommandPacket.TargetStatus; + *SenseDataLength =3D CommandPacket.SenseDataLength; + *TransferLength =3D (UINTN) CommandPacket.InTransferLength; + + return Status; +} + + +/** + Execute Security Protocol Out SCSI command on a specific SCSI target. + + Executes the SCSI Security Protocol Out command on the SCSI target speci= fied by ScsiIo. + If Timeout is zero, then this function waits indefinitely for the comman= d to complete. + If Timeout is greater than zero, then the command is executed and will t= imeout after + Timeout 100 ns units. + If ScsiIo is NULL, then ASSERT(). + If SenseDataLength is NULL, then ASSERT(). + If HostAdapterStatus is NULL, then ASSERT(). + If TargetStatus is NULL, then ASSERT(). + + If SenseDataLength is non-zero and SenseData is not NULL, SenseData must= meet buffer + alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INV= ALID_PARAMETER + gets returned. + + If DataLength is non-zero and DataBuffer is not NULL, DataBuffer must me= et buffer + alignment requirement defined in EFI_SCSI_IO_PROTOCOL. Otherwise EFI_INV= ALID_PARAMETER + gets returned. + + @param[in] ScsiIo SCSI IO Protocol to use. + @param[in] Timeout The length of timeout period. + @param[in, out] SenseData A pointer to output sense data. + @param[in, out] SenseDataLength The length of output sense dat= a. + @param[out] HostAdapterStatus The status of Host Adapter. + @param[out] TargetStatus The status of the target. + @param[in] SecurityProtocol The Security Protocol to use. + @param[in] SecurityProtocolSpecific The Security Protocol Specific= data. + @param[in] Inc512 If Inc512 is TRUE, DataLength = is expressed in 512-byte increments. + @param[in] DataLength The size in bytes of the trans= fer data. + @param[in, out] DataBuffer A pointer to a data buffer. + + @retval EFI_SUCCESS Command is executed successfully. + @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was execute= d, but the entire DataBuffer could + not be transferred. The actual numb= er of bytes transferred is returned in DataLength. + @retval EFI_NOT_READY The SCSI Request Packet could not b= e sent because there are too many + SCSI Command Packets already queued. + @retval EFI_DEVICE_ERROR A device error occurred while attem= pting to send SCSI Request Packet. + @retval EFI_UNSUPPORTED The command described by the SCSI R= equest Packet is not supported by + the SCSI initiator(i.e., SCSI Host= Controller) + @retval EFI_TIMEOUT A timeout occurred while waiting fo= r the SCSI Request Packet to execute. + @retval EFI_INVALID_PARAMETER The contents of the SCSI Request Pa= cket are invalid. + +**/ +EFI_STATUS +EFIAPI +ScsiSecurityProtocolOutCommand ( + IN EFI_SCSI_IO_PROTOCOL *ScsiIo, + IN UINT64 Timeout, + IN OUT VOID *SenseData, OPTIONAL + IN OUT UINT8 *SenseDataLength, + OUT UINT8 *HostAdapterStatus, + OUT UINT8 *TargetStatus, + IN UINT8 SecurityProtocol, + IN UINT16 SecurityProtocolSpecific, + IN BOOLEAN Inc512, + IN UINTN DataLength, + IN OUT VOID *DataBuffer OPTIONAL + ) +{ + EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket; + EFI_STATUS Status; + UINT8 Cdb[EFI_SCSI_OP_LENGTH_TWELVE]; + + ASSERT (SenseDataLength !=3D NULL); + ASSERT (HostAdapterStatus !=3D NULL); + ASSERT (TargetStatus !=3D NULL); + ASSERT (ScsiIo !=3D NULL); + ASSERT (DataLength <=3D MAX_UINT32); + + ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET)); + ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_TWELVE); + + CommandPacket.Timeout =3D Timeout; + CommandPacket.OutDataBuffer =3D DataBuffer; + CommandPacket.SenseData =3D SenseData; + CommandPacket.OutTransferLength =3D (UINT32) DataLength; + CommandPacket.Cdb =3D Cdb; + // + // Fill Cdb for Security Protocol Out Command + // + Cdb[0] =3D EFI_SCSI_OP_SECURITY_PROTOCOL_OUT; + Cdb[1] =3D SecurityProtocol; + WriteUnaligned16 ((UINT16 *)&Cdb[2], SwapBytes16 (SecurityProtocolSpecif= ic)); + WriteUnaligned32 ((UINT32 *)&Cdb[6], SwapBytes32 ((UINT32) DataLength)); + + if (Inc512) { + Cdb[4] =3D BIT7; + } + + CommandPacket.CdbLength =3D EFI_SCSI_OP_LENGTH_TWELVE; + CommandPacket.DataDirection =3D EFI_SCSI_DATA_OUT; + CommandPacket.SenseDataLength =3D *SenseDataLength; + + Status =3D ScsiIo->ExecuteScsiCommand (ScsiIo, &C= ommandPacket, NULL); + + *HostAdapterStatus =3D CommandPacket.HostAdapterStatus; + *TargetStatus =3D CommandPacket.TargetStatus; + *SenseDataLength =3D CommandPacket.SenseDataLength; + + return Status; +} + + /** Internal helper notify function in which update the result of the non-blocking SCSI Read/Write commands and signal caller event. --=20 2.16.2.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#46992): https://edk2.groups.io/g/devel/message/46992 Mute This Topic: https://groups.io/mt/33202221/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-