From nobody Sat Nov 29 10:15:25 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; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1764167190; cv=none; d=zohomail.com; s=zohoarc; b=iJeJRBV/Ll+iz5JJBSoIrhPRlFvcwggUkCRCxXr/jlizs3wdyZGorBXasNCUKZaPlcFIMc6h+/KOHfh3ZCfsih49Gjzl2e5f+KUv14MW64SmlzZXVez660+T9bMX5yhkiMTti37yT15L09YV2fAlzQfhdnU04x+ugjMlgLwOIww= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764167190; 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=UpWA4flCdk9F+i36KGIcPFvvLP3A+c4pIOB6fsgACdM=; b=VZNlyYYwYiwXo90IzbuoP/XC7clHhKlbBFK+CoIok+BGSc0ZMF2432XSbBpGYg/aIlkFawSLQqBPOP/Gnt36VlWz5KnBbmRZYTT/ZNvKaPb9wHfMe8ya4Mpi7gfoMZA+yZUZ8KLDHtQMxUZ5DFiJHhqvwik3l5KL7DMM7U2/4S0= 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1764167190798635.5032692439413; Wed, 26 Nov 2025 06:26:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vOGTB-0000Nr-1e; Wed, 26 Nov 2025 09:26:09 -0500 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 1vOGT9-0000N3-Rv for qemu-devel@nongnu.org; Wed, 26 Nov 2025 09:26:07 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vOGT7-0006YD-GF for qemu-devel@nongnu.org; Wed, 26 Nov 2025 09:26:07 -0500 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-440-bnnzMhI4NPOzB1vLCPjhiQ-1; Wed, 26 Nov 2025 09:26:02 -0500 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 208871956066 for ; Wed, 26 Nov 2025 14:26:02 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.44.33.126]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B3376195608E; Wed, 26 Nov 2025 14:26:01 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 9BB071800395; Wed, 26 Nov 2025 15:25:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764167164; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UpWA4flCdk9F+i36KGIcPFvvLP3A+c4pIOB6fsgACdM=; b=N7OUJ7s8S6vGUt5OsQr6yVq5t+ZDh1Bfb8sRqGumi84hZZzdFGGjN5UcnQy2uzPVQ4mnt6 6o4KwjvHgQ6TGLxjoxTnGrScshwv6mF+qxbz+UUr4IVxSyyaMlYJKYte5VdAtbEiQNgkRr 17TpTEyToyQUrsbx49ozuQZ4PR82tHY= X-MC-Unique: bnnzMhI4NPOzB1vLCPjhiQ-1 X-Mimecast-MFC-AGG-ID: bnnzMhI4NPOzB1vLCPjhiQ_1764167162 From: Gerd Hoffmann To: qemu-devel@nongnu.org Cc: Gerd Hoffmann Subject: [PATCH 1/2] move pcap structs to header file Date: Wed, 26 Nov 2025 15:25:58 +0100 Message-ID: <20251126142559.4081483-2-kraxel@redhat.com> In-Reply-To: <20251126142559.4081483-1-kraxel@redhat.com> References: <20251126142559.4081483-1-kraxel@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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=170.10.133.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.224, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 @redhat.com) X-ZM-MESSAGEID: 1764167191164019200 Content-Type: text/plain; charset="utf-8" Allow reusing them elsewhere in qemu. Signed-off-by: Gerd Hoffmann Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/qemu/pcap.h | 27 +++++++++++++++++++++++++++ hw/usb/pcap.c | 24 +----------------------- 2 files changed, 28 insertions(+), 23 deletions(-) create mode 100644 include/qemu/pcap.h diff --git a/include/qemu/pcap.h b/include/qemu/pcap.h new file mode 100644 index 000000000000..48e6070ffe04 --- /dev/null +++ b/include/qemu/pcap.h @@ -0,0 +1,27 @@ +#ifndef QEMU_PCAP_H +#define QEMU_PCAP_H + +#define PCAP_MAGIC 0xa1b2c3d4 +#define PCAP_MAJOR 2 +#define PCAP_MINOR 4 + +/* https://wiki.wireshark.org/Development/LibpcapFileFormat */ + +struct pcap_hdr { + uint32_t magic_number; /* magic number */ + uint16_t version_major; /* major version number */ + uint16_t version_minor; /* minor version number */ + int32_t thiszone; /* GMT to local correction */ + uint32_t sigfigs; /* accuracy of timestamps */ + uint32_t snaplen; /* max length of captured packets, in octets = */ + uint32_t network; /* data link type */ +}; + +struct pcaprec_hdr { + uint32_t ts_sec; /* timestamp seconds */ + uint32_t ts_usec; /* timestamp microseconds */ + uint32_t incl_len; /* number of octets of packet saved in file */ + uint32_t orig_len; /* actual length of packet */ +}; + +#endif /* QEMU_PCAP_H */ diff --git a/hw/usb/pcap.c b/hw/usb/pcap.c index dbff00be252e..10ca6279f7d3 100644 --- a/hw/usb/pcap.c +++ b/hw/usb/pcap.c @@ -8,31 +8,9 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/pcap.h" #include "hw/usb.h" =20 -#define PCAP_MAGIC 0xa1b2c3d4 -#define PCAP_MAJOR 2 -#define PCAP_MINOR 4 - -/* https://wiki.wireshark.org/Development/LibpcapFileFormat */ - -struct pcap_hdr { - uint32_t magic_number; /* magic number */ - uint16_t version_major; /* major version number */ - uint16_t version_minor; /* minor version number */ - int32_t thiszone; /* GMT to local correction */ - uint32_t sigfigs; /* accuracy of timestamps */ - uint32_t snaplen; /* max length of captured packets, in octets = */ - uint32_t network; /* data link type */ -}; - -struct pcaprec_hdr { - uint32_t ts_sec; /* timestamp seconds */ - uint32_t ts_usec; /* timestamp microseconds */ - uint32_t incl_len; /* number of octets of packet saved in file */ - uint32_t orig_len; /* actual length of packet */ -}; - /* https://www.tcpdump.org/linktypes.html */ /* linux: Documentation/usb/usbmon.rst */ /* linux: drivers/usb/mon/mon_bin.c */ --=20 2.52.0 From nobody Sat Nov 29 10:15:25 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; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1764167179; cv=none; d=zohomail.com; s=zohoarc; b=eRzZXMwtWkDjlilF6kZq+vzLPxbxM/STbug+hitzdtV5aVIpBoHqPlZgsTSe4NWTbNiy3KTG86nsiRmY/tiVR6nvDkGeBJOE1NnZNQfHuQe46H012jPJ7uuswgb+YZ4HSJjPoN5m+zBrwPUkUfqOrsM/zn2pyWlLLpjCSP5iALk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764167179; 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=aR8Q56hXIcWVV17OLcpeOmz3e6PhKAJ2AMYxM59GumA=; b=EgenIrVUGjf6tNjBtkULL8CiTsXmh2Y5PWTZ9/5R6GB3WRHb6v+ER/Nse960/Ioqf4+e4OJ+1XxceFlUoztEkb3vAcVrn6pPUeXRCbbquKONmc95bYaxPMDv01nNwT3+UN570CUXVbeJ7fv6zLgwO933zqc2MAOBBN0bt0gw990= 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; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1764167179519454.04826434862093; Wed, 26 Nov 2025 06:26:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vOGTF-0000T9-J5; Wed, 26 Nov 2025 09:26:13 -0500 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 1vOGTC-0000Ps-Az for qemu-devel@nongnu.org; Wed, 26 Nov 2025 09:26:10 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vOGTA-0006Yy-FB for qemu-devel@nongnu.org; Wed, 26 Nov 2025 09:26:10 -0500 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-231-F2lWqx9MPHie5qvzGGnAjg-1; Wed, 26 Nov 2025 09:26:05 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2BF721956052 for ; Wed, 26 Nov 2025 14:26:05 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.44.33.126]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 748961800451; Wed, 26 Nov 2025 14:26:04 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id B81541800397; Wed, 26 Nov 2025 15:25:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764167167; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aR8Q56hXIcWVV17OLcpeOmz3e6PhKAJ2AMYxM59GumA=; b=C0ChYnuD1Z6Nm7LqKupNyiXAh+ArGjox2i8eH5rgdIOAMOivR8H6fi9SvbBg3dNPRwLoqc BTbd6QonM5ozUDquJfBK7WqU0AtIN4OQbeMmaYbPzREx/Lxrw5uO5I1AZr9PqvGS8WAH8p sMFjVjogbWnL45CWslOePYPlMv5WA54= X-MC-Unique: F2lWqx9MPHie5qvzGGnAjg-1 X-Mimecast-MFC-AGG-ID: F2lWqx9MPHie5qvzGGnAjg_1764167165 From: Gerd Hoffmann To: qemu-devel@nongnu.org Cc: Gerd Hoffmann Subject: [PATCH 2/2] hw/uefi: add pcap support Date: Wed, 26 Nov 2025 15:25:59 +0100 Message-ID: <20251126142559.4081483-3-kraxel@redhat.com> In-Reply-To: <20251126142559.4081483-1-kraxel@redhat.com> References: <20251126142559.4081483-1-kraxel@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 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=170.10.129.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.224, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, 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 @redhat.com) X-ZM-MESSAGEID: 1764167181080019200 Content-Type: text/plain; charset="utf-8" Add pcapfile property to uevi-vars-* devices, allowing to write out a capture of the communication traffic between uefi firmware and qemu. Signed-off-by: Gerd Hoffmann Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/uefi/var-service.h | 10 ++++ hw/uefi/var-service-core.c | 7 +++ hw/uefi/var-service-pcap.c | 94 +++++++++++++++++++++++++++++++++++ hw/uefi/var-service-sysbus.c | 1 + hw/uefi/meson.build | 1 + roms/edk2 | 2 +- 6 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 hw/uefi/var-service-pcap.c diff --git a/include/hw/uefi/var-service.h b/include/hw/uefi/var-service.h index 91fb4a20918a..116ee90a1146 100644 --- a/include/hw/uefi/var-service.h +++ b/include/hw/uefi/var-service.h @@ -77,6 +77,10 @@ struct uefi_vars_state { bool force_secure_boot; bool disable_custom_mode; bool use_pio; + + /* request + reply capture */ + char *pcapfile; + FILE *pcapfp; }; =20 struct uefi_vars_cert { @@ -189,4 +193,10 @@ uefi_var_policy *uefi_vars_add_policy(uefi_vars_state = *uv, variable_policy_entry *pe); uint32_t uefi_vars_mm_check_policy_proto(uefi_vars_state *uv); =20 +/* vars-service-pcap.c */ +void uefi_vars_pcap_init(uefi_vars_state *uv); +void uefi_vars_pcap_reset(uefi_vars_state *uv); +void uefi_vars_pcap_request(uefi_vars_state *uv, void *buffer, size_t size= ); +void uefi_vars_pcap_reply(uefi_vars_state *uv, void *buffer, size_t size); + #endif /* QEMU_UEFI_VAR_SERVICE_H */ diff --git a/hw/uefi/var-service-core.c b/hw/uefi/var-service-core.c index 6ab8df091aaf..6d7913e03f45 100644 --- a/hw/uefi/var-service-core.c +++ b/hw/uefi/var-service-core.c @@ -101,6 +101,8 @@ static uint32_t uefi_vars_cmd_mm(uefi_vars_state *uv, b= ool dma_mode) } memset(uv->buffer + size, 0, uv->buf_size - size); =20 + uefi_vars_pcap_request(uv, uv->buffer, size); + /* dispatch */ if (qemu_uuid_is_equal(&mhdr->guid, &EfiSmmVariableProtocolGuid)) { retval =3D uefi_vars_mm_vars_proto(uv); @@ -127,6 +129,8 @@ static uint32_t uefi_vars_cmd_mm(uefi_vars_state *uv, b= ool dma_mode) retval =3D UEFI_VARS_STS_ERR_NOT_SUPPORTED; } =20 + uefi_vars_pcap_reply(uv, uv->buffer, sizeof(*mhdr) + mhdr->length); + /* write buffer */ if (dma_mode) { dma_memory_write(&address_space_memory, dma, @@ -163,6 +167,8 @@ void uefi_vars_hard_reset(uefi_vars_state *uv) uefi_vars_clear_volatile(uv); uefi_vars_policies_clear(uv); uefi_vars_auth_init(uv); + + uefi_vars_pcap_reset(uv); } =20 static uint32_t uefi_vars_cmd(uefi_vars_state *uv, uint32_t cmd) @@ -319,4 +325,5 @@ void uefi_vars_realize(uefi_vars_state *uv, Error **err= p) { uefi_vars_json_init(uv, errp); uefi_vars_json_load(uv, errp); + uefi_vars_pcap_init(uv); } diff --git a/hw/uefi/var-service-pcap.c b/hw/uefi/var-service-pcap.c new file mode 100644 index 000000000000..879eee4699a3 --- /dev/null +++ b/hw/uefi/var-service-pcap.c @@ -0,0 +1,94 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include "qemu/osdep.h" +#include "qemu/error-report.h" +#include "qemu/pcap.h" +#include "system/dma.h" + +#include "hw/uefi/var-service.h" + +#define LINKTYPE_EDK2_MM 302 + +#define SNAPLEN (64 * 1024) +#define TYPE_RESET 0x01 +#define TYPE_REQUEST 0x02 +#define TYPE_REPLY 0x03 + +static void uefi_vars_pcap_header(FILE *fp) +{ + struct pcap_hdr header =3D { + .magic_number =3D PCAP_MAGIC, + .version_major =3D PCAP_MAJOR, + .version_minor =3D PCAP_MINOR, + .snaplen =3D SNAPLEN, + .network =3D LINKTYPE_EDK2_MM, + }; + + fwrite(&header, sizeof(header), 1, fp); + fflush(fp); +} + +static void uefi_vars_pcap_packet(FILE *fp, uint32_t type, void *buffer, s= ize_t size) +{ + struct pcaprec_hdr header; + struct timeval tv; + uint32_t orig_len =3D size + sizeof(type); + uint32_t incl_len =3D MIN(orig_len, SNAPLEN); + + gettimeofday(&tv, NULL); + header.ts_sec =3D tv.tv_sec; + header.ts_usec =3D tv.tv_usec; + header.incl_len =3D incl_len; + header.orig_len =3D orig_len; + + fwrite(&header, sizeof(header), 1, fp); + fwrite(&type, sizeof(type), 1, fp); + if (buffer) { + fwrite(buffer, incl_len - sizeof(type), 1, fp); + } + fflush(fp); +} + +void uefi_vars_pcap_init(uefi_vars_state *uv) +{ + int fd; + + if (!uv->pcapfile) { + return; + } + + fd =3D qemu_open_old(uv->pcapfile, + O_CREAT | O_WRONLY | O_TRUNC | O_BINARY, 0666); + if (fd < 0) { + warn_report("open %s: %s", uv->pcapfile, strerror(errno)); + return; + } + + uv->pcapfp =3D fdopen(fd, "wb"); + uefi_vars_pcap_header(uv->pcapfp); +} + +void uefi_vars_pcap_reset(uefi_vars_state *uv) +{ + if (!uv->pcapfp) { + return; + } + uefi_vars_pcap_packet(uv->pcapfp, TYPE_RESET, NULL, 0); +} + +void uefi_vars_pcap_request(uefi_vars_state *uv, void *buffer, size_t size) +{ + if (!uv->pcapfp) { + return; + } + uefi_vars_pcap_packet(uv->pcapfp, TYPE_REQUEST, buffer, size); +} + +void uefi_vars_pcap_reply(uefi_vars_state *uv, void *buffer, size_t size) +{ + if (!uv->pcapfp) { + return; + } + uefi_vars_pcap_packet(uv->pcapfp, TYPE_REPLY, buffer, size); +} diff --git a/hw/uefi/var-service-sysbus.c b/hw/uefi/var-service-sysbus.c index a5aa218e2600..bd37d5bd3526 100644 --- a/hw/uefi/var-service-sysbus.c +++ b/hw/uefi/var-service-sysbus.c @@ -33,6 +33,7 @@ static const Property uefi_vars_sysbus_properties[] =3D { DEFINE_PROP_SIZE("size", uefi_vars_sysbus_state, state.max_storage, 256 * 1024), DEFINE_PROP_STRING("jsonfile", uefi_vars_sysbus_state, state.jsonfile), + DEFINE_PROP_STRING("pcapfile", uefi_vars_sysbus_state, state.pcapfile), DEFINE_PROP_BOOL("force-secure-boot", uefi_vars_sysbus_state, state.force_secure_boot, false), DEFINE_PROP_BOOL("disable-custom-mode", uefi_vars_sysbus_state, diff --git a/hw/uefi/meson.build b/hw/uefi/meson.build index c8f38dfae247..3eae47553315 100644 --- a/hw/uefi/meson.build +++ b/hw/uefi/meson.build @@ -3,6 +3,7 @@ system_ss.add(files('hardware-info.c', 'ovmf-log.c')) uefi_vars_ss =3D ss.source_set() if (config_all_devices.has_key('CONFIG_UEFI_VARS')) uefi_vars_ss.add(files('var-service-core.c', + 'var-service-pcap.c', 'var-service-json.c', 'var-service-vars.c', 'var-service-auth.c', diff --git a/roms/edk2 b/roms/edk2 index 4dfdca63a934..46548b1adac8 160000 --- a/roms/edk2 +++ b/roms/edk2 @@ -1 +1 @@ -Subproject commit 4dfdca63a93497203f197ec98ba20e2327e4afe4 +Subproject commit 46548b1adac82211d8d11da12dd914f41e7aa775 --=20 2.52.0