From nobody Fri Nov 14 19:43:54 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1761809525; cv=none; d=zohomail.com; s=zohoarc; b=dl8lmo4QVnVZNstv2ABUYQunc17675T38Crfc/oqNurYJ2IiSsH7Y9akgtC6a4hLBCxcjXh2SSlOc3lgA1XXF7EULnuc437G9tRcLn0JmD6Z5yHf0JJifuzuzPT5UuSvf2kpCymqm87gGKsKrAHfg/lCKvcaHO8OGTyXx/BtdYQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761809525; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8uqjS+B4/mrj9+8st/Ib3h3tRy9os/inVyIXpM7VHcU=; b=eujyt3qOX38jlGUPYfh6ritRZICVfMzDujSu7m4tl3FfvQr3i4pzC1Jucg1b+5p+Ltiu9G1O2QNQNkWKPVfbeRchM88EPpa8BFHKINNxdo5ZAvwgGqKgN/AcPW14JSy5wKu+R1maq0PQQNfah/G++4t/C+FRNcUwSICEW5jUEXQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1761809525101740.4500524939443; Thu, 30 Oct 2025 00:32:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vEN7U-0002vS-GY; Thu, 30 Oct 2025 03:30:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vEN7K-0002rn-26 for qemu-devel@nongnu.org; Thu, 30 Oct 2025 03:30:49 -0400 Received: from fout-a6-smtp.messagingengine.com ([103.168.172.149]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vEN72-000532-Hr for qemu-devel@nongnu.org; Thu, 30 Oct 2025 03:30:38 -0400 Received: from phl-compute-12.internal (phl-compute-12.internal [10.202.2.52]) by mailfout.phl.internal (Postfix) with ESMTP id D55C9EC01BF; Thu, 30 Oct 2025 03:30:18 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Thu, 30 Oct 2025 03:30:18 -0400 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 30 Oct 2025 03:30:17 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irrelevant.dk; h=cc:cc:content-transfer-encoding:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1761809418; x= 1761895818; bh=8uqjS+B4/mrj9+8st/Ib3h3tRy9os/inVyIXpM7VHcU=; b=i QVJfe4MAm110M5uTD5/0XjocRYD/AMcW0UOdtg5ZM8Sdb2b4ekMwQ00pOmyMxHjm Nsj/vILp74SRC1gs8Im8lomNWrBqoXl7JIICbnisqMj7XHF7Dk5gxgBCKmj5HlgZ WcgurhllWtdftXkHwYTpKWxeRX76uA45fxw6JZEcZpH+R1Ga20ywjFGnn5S/QeSc asAt8vud6FqRmULWQdTl2SWAhw/Z1ea4whpn2sIsRT5zDRCsT8xHtFkqH28l+RpK rFkTZGIEmUtYkVkUsVc04UW+YvyclPC8MVfr2ATWGGFnVHXlz9oXCnbVk8UjHSaZ 646oGp1b00Bjux0NhE1pA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1761809418; x=1761895818; bh=8 uqjS+B4/mrj9+8st/Ib3h3tRy9os/inVyIXpM7VHcU=; b=aSSl/JlAG1edeJylZ ZmoN2/Ejp1O7+7gdYEkEw/WqlYthBLusWVCZpWRU1+fLwAMSIYPPQuetYfJMgcud lznkOUVVvuYA5JRxopvA2OTJV+YDfScj+wmPvY6WOJBeb2Rqx3DXg6Zk9Jy+nRMb +B1UAXjyyiBfCmO1vTuivdEoLbw8ElNWOlKPIuPCEwMUVie/kiRRd7TaWERRGHfz G7DT3S7FmA2JaAv1WR0D+a/FN9hdAKrLxVhUWl3BDiyAqkqibJjNGhrPCWl2ILVo 4xrsM5WfIpho0+1h+ZBcleMQq/BCxmjZUVUISa9da4yuRGothdDnf8IUME5NP3dr vrKlw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggdduieeitdduucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepmfhlrghushcu lfgvnhhsvghnuceoihhtshesihhrrhgvlhgvvhgrnhhtrdgukheqnecuggftrfgrthhtvg hrnhepjefgieelgfeiveehkeeuveehheekfeevgeeigfehfefgjeejhefffeegudejudeg necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepihhtsh esihhrrhgvlhgvvhgrnhhtrdgukhdpnhgspghrtghpthhtohepiedpmhhouggvpehsmhht phhouhhtpdhrtghpthhtohepqhgvmhhuqdguvghvvghlsehnohhnghhnuhdrohhrghdprh gtphhtthhopehpvghtvghrrdhmrgihuggvlhhlsehlihhnrghrohdrohhrghdprhgtphht thhopeifihhlfhhrvggurdhmrghllhgrfigrseifuggtrdgtohhmpdhrtghpthhtoheprg hlihhsthgrihhrrdhfrhgrnhgtihhsseifuggtrdgtohhmpdhrtghpthhtohepjhhonhgr thhhrghnrdgtrghmvghrohhnsehhuhgrfigvihdrtghomhdprhgtphhtthhopehkrdhjvg hnshgvnhesshgrmhhsuhhnghdrtghomh X-ME-Proxy: Feedback-ID: idc91472f:Fastmail From: Klaus Jensen To: qemu-devel@nongnu.org Cc: Peter Maydell , Wilfred Mallawa , Alistair Francis , Jonathan Cameron , Klaus Jensen Subject: [PULL 1/7] spdm-socket: add seperate send/recv functions Date: Thu, 30 Oct 2025 08:29:49 +0100 Message-ID: <20251030072956.1194-2-its@irrelevant.dk> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251030072956.1194-1-its@irrelevant.dk> References: <20251030072956.1194-1-its@irrelevant.dk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=103.168.172.149; envelope-from=its@irrelevant.dk; helo=fout-a6-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @irrelevant.dk) X-ZM-MESSAGEID: 1761809527733158500 Content-Type: text/plain; charset="utf-8" From: Wilfred Mallawa This is to support uni-directional transports such as SPDM over Storage. As specified by the DMTF DSP0286. Also update spdm_socket_rsp() to use the new send()/receive() functions. For the case of spdm_socket_receive(), this allows us to do error checking in one place with the addition of spdm_socket_command_valid(). Signed-off-by: Wilfred Mallawa Reviewed-by: Alistair Francis Reviewed-by: Jonathan Cameron Signed-off-by: Klaus Jensen --- backends/spdm-socket.c | 58 ++++++++++++++++++++++++++++-------- include/system/spdm-socket.h | 32 ++++++++++++++++++++ 2 files changed, 77 insertions(+), 13 deletions(-) diff --git a/backends/spdm-socket.c b/backends/spdm-socket.c index 2c709c68c873..ab74a02d9cf6 100644 --- a/backends/spdm-socket.c +++ b/backends/spdm-socket.c @@ -184,29 +184,61 @@ int spdm_socket_connect(uint16_t port, Error **errp) return client_socket; } =20 -uint32_t spdm_socket_rsp(const int socket, uint32_t transport_type, - void *req, uint32_t req_len, - void *rsp, uint32_t rsp_len) +static bool spdm_socket_command_valid(uint32_t command) +{ + switch (command) { + case SPDM_SOCKET_COMMAND_NORMAL: + case SPDM_SOCKET_STORAGE_CMD_IF_SEND: + case SPDM_SOCKET_STORAGE_CMD_IF_RECV: + case SOCKET_SPDM_STORAGE_ACK_STATUS: + case SPDM_SOCKET_COMMAND_OOB_ENCAP_KEY_UPDATE: + case SPDM_SOCKET_COMMAND_CONTINUE: + case SPDM_SOCKET_COMMAND_SHUTDOWN: + case SPDM_SOCKET_COMMAND_UNKOWN: + case SPDM_SOCKET_COMMAND_TEST: + return true; + default: + return false; + } +} + +uint32_t spdm_socket_receive(const int socket, uint32_t transport_type, + void *rsp, uint32_t rsp_len) { uint32_t command; bool result; =20 - result =3D send_platform_data(socket, transport_type, - SPDM_SOCKET_COMMAND_NORMAL, - req, req_len); - if (!result) { - return 0; - } - result =3D receive_platform_data(socket, transport_type, &command, (uint8_t *)rsp, &rsp_len); + + /* we may have received some data, but check if the command is valid */ + if (!result || !spdm_socket_command_valid(command)) { + return 0; + } + + return rsp_len; +} + +bool spdm_socket_send(const int socket, uint32_t socket_cmd, + uint32_t transport_type, void *req, uint32_t req_len) +{ + return send_platform_data(socket, transport_type, socket_cmd, req, + req_len); +} + +uint32_t spdm_socket_rsp(const int socket, uint32_t transport_type, + void *req, uint32_t req_len, + void *rsp, uint32_t rsp_len) +{ + bool result; + + result =3D spdm_socket_send(socket, SPDM_SOCKET_COMMAND_NORMAL, + transport_type, req, req_len); if (!result) { return 0; } =20 - assert(command !=3D 0); - - return rsp_len; + return spdm_socket_receive(socket, transport_type, rsp, rsp_len); } =20 void spdm_socket_close(const int socket, uint32_t transport_type) diff --git a/include/system/spdm-socket.h b/include/system/spdm-socket.h index 5d8bd9aa4e1d..29aa04fd5211 100644 --- a/include/system/spdm-socket.h +++ b/include/system/spdm-socket.h @@ -50,6 +50,35 @@ uint32_t spdm_socket_rsp(const int socket, uint32_t tran= sport_type, void *req, uint32_t req_len, void *rsp, uint32_t rsp_len); =20 +/** + * spdm_socket_rsp: Receive a message from an SPDM server + * @socket: socket returned from spdm_socket_connect() + * @transport_type: SPDM_SOCKET_TRANSPORT_TYPE_* macro + * @rsp: response buffer + * @rsp_len: response buffer length + * + * Receives a message from the SPDM server and returns the number of bytes + * received or 0 on failure. This can be used to receive a message from th= e SPDM + * server without sending anything first. + */ +uint32_t spdm_socket_receive(const int socket, uint32_t transport_type, + void *rsp, uint32_t rsp_len); + +/** + * spdm_socket_rsp: Sends a message to an SPDM server + * @socket: socket returned from spdm_socket_connect() + * @socket_cmd: socket command type (normal/if_recv/if_send etc...) + * @transport_type: SPDM_SOCKET_TRANSPORT_TYPE_* macro + * @req: request buffer + * @req_len: request buffer length + * + * Sends platform data to a SPDM server on socket, returns true on success. + * The response from the server must then be fetched by using + * spdm_socket_receive(). + */ +bool spdm_socket_send(const int socket, uint32_t socket_cmd, + uint32_t transport_type, void *req, uint32_t req_len= ); + /** * spdm_socket_close: send a shutdown command to the server * @socket: socket returned from spdm_socket_connect() @@ -60,6 +89,9 @@ uint32_t spdm_socket_rsp(const int socket, uint32_t trans= port_type, void spdm_socket_close(const int socket, uint32_t transport_type); =20 #define SPDM_SOCKET_COMMAND_NORMAL 0x0001 +#define SPDM_SOCKET_STORAGE_CMD_IF_SEND 0x0002 +#define SPDM_SOCKET_STORAGE_CMD_IF_RECV 0x0003 +#define SOCKET_SPDM_STORAGE_ACK_STATUS 0x0004 #define SPDM_SOCKET_COMMAND_OOB_ENCAP_KEY_UPDATE 0x8001 #define SPDM_SOCKET_COMMAND_CONTINUE 0xFFFD #define SPDM_SOCKET_COMMAND_SHUTDOWN 0xFFFE --=20 2.51.0