From nobody Sun Apr 12 05:51:27 2026 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=none dis=none) header.from=minyard.net ARC-Seal: i=1; a=rsa-sha256; t=1770918115; cv=none; d=zohomail.com; s=zohoarc; b=ElGFAynBz/1tTRhw8h4GbuPpRJ0Eyg4IgKJHYsBcq2TELWiqIo7zXTWdQjV0jHCTuWDXIexFYJB+ylMr5N0F6ZZcHvAnCAeHuAUHOAURHeM95uBlqszo8oSS8UbQE6armQzqyNn+srlX5l/02NnZ1/RycO29k9uRb+dHn1CqNs0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770918115; 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=NKo06MhGRsampsYGV+hkgGqoCl32gdVA9X/y9dLvz74=; b=Xly/y/u/9vAM4shsI/ms3gUM7Pg87S1EmNO+/yfblAJNpZA+O6/jspAykWnpfTLYGH6S1tNKCD30sWdz9JrT5Pva0Mz37HuchacUOt8TEBQfksGvUk3RPPmXMAj3b8Hds9djiR2H651DsLx7RBvI2vFZHOBf3zwvO4pWTCaxlhw= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770918115278916.2449721601454; Thu, 12 Feb 2026 09:41:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqahF-00087A-FP; Thu, 12 Feb 2026 12:41:45 -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 1vqahD-00086R-WA for qemu-devel@nongnu.org; Thu, 12 Feb 2026 12:41:44 -0500 Received: from mail-ot1-x336.google.com ([2607:f8b0:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vqahA-0002WK-4y for qemu-devel@nongnu.org; Thu, 12 Feb 2026 12:41:43 -0500 Received: by mail-ot1-x336.google.com with SMTP id 46e09a7af769-7d15b8feca3so30831a34.3 for ; Thu, 12 Feb 2026 09:41:39 -0800 (PST) Received: from localhost ([2001:470:b8f6:1b:ac4f:9c7a:97e9:f745]) by smtp.gmail.com with UTF8SMTPSA id 46e09a7af769-7d4a76e1e59sm4082731a34.17.2026.02.12.09.41.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 Feb 2026 09:41:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minyard.net; s=google; t=1770918099; x=1771522899; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NKo06MhGRsampsYGV+hkgGqoCl32gdVA9X/y9dLvz74=; b=FZDw9L0x8etCZ0jiXQerNRxb7kXDMnAmumFbwc2mzghxwoXq0QbQUNBYpfrvIpC2wV xNncPX0UXvUTovXhbaF14ugm1gWGYnuwu7XIK3ulifvwWhKgaZXuCFoDlP3MRqTZj1Dn qvbjrq0CjINgGj7970M716HTPzSYwWx55Akz2SrUZIr7nqHy5kso27fzIIOfdD74uTBN 9/n6a9sq2KD55+jXqs9SAM7aKOb/hk6aZRlBMhCndLvK6HHVrTYJLGuLqlUvLclRXSnw /BjwkTjRhkCSJjkLP+XAGpoaMrmGKM3J/zX0lrKG0KacBrIwjSwgVFok6xedFd+AhE8/ QNtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770918099; x=1771522899; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=NKo06MhGRsampsYGV+hkgGqoCl32gdVA9X/y9dLvz74=; b=gmOVaB1xBrSlFiwqAxyA29Ln1FHR+IoX0DL97QgHwg5id2NWeHCvGwZhFjZ6oir7Xd qZQR7gcu2HrQeXnk5hEiQwZRC6G6ZTdCYqYYSWZsEfZg9tPbH/bXk6uVu5Xw5wXbZUsu PRHhvKp/VrKlbwH/MK94zhcGgguNJbL4t527IPoBVpAzHG63/KozeVsnRMv0Qw7EtJA7 XAVNszz030RGaoDJ2ZeTw+8NieSgr5aAp5juJSFAuTb35+vcC/JTuDehjmxdUfR5kpVn GBiuKEXzHpvM5imEgXAbg3NIk7vs5g4VTHeEJrKEvgswl9E/vjGEsDWCTznhb1VPnWwA MYaA== X-Forwarded-Encrypted: i=1; AJvYcCXzur3N2Si8L1ptBVPaC8a9FzZkX0h5do/wAbQ/rKh/kqtqR5xqUnzbg7cM4iARo8tS6woFCVBwECjY@nongnu.org X-Gm-Message-State: AOJu0Yxpw+Y3Y8hOFecn/WX/ODjlKe0RlP4QjLOQKks0OFGRtbCx/4x4 7qHuYLHCbpxRHRdlrJQeYS3l3boqEH9mgQk+r+nKbId1fx+9vt/E5vfv53QNM05/KMI= X-Gm-Gg: AZuq6aLPkzdANXdC8q8hPRAXEVpjrrmnQSZWdhCKgLEOxMfbXqEKi/092TFDTH013fw hUE3i+jojDo80noLU++lLa3lO6GGugrM8Tpj1lsLoQIE2yCKzVUvYwvA5uKZhv+Oj4lX5gaVadi 1CxXFM5WhzqKgeSMXnE9oj12Q7V6EBo70VYzHd37MABzEhM5+C3z09SzbpSYdPP65Sze4tpzZNI woJ8eYHV4cJ3dyfJ0/ZjZ/QY4CbHT8UQm/ZczCbcsRDKTpSqCr9F1o10XweeawTK220Do2qLzhn GFfvcTldvC4XhvIGHVmAM9leD8jI6RSLkTpdpM8ZWjqeVnYZpt5wmCmyMmMhpyE6jW/TM11txoq 23cHaYc1udwbF+eOsIeqHe9pTNRrUc9mSaIR9NNfeWUMnNg3CJAFhHUSs0kBli7NI1xVv8itX1N D++Q8LdeITzaUzQNnP7y2gZ4YpY7+9ZQ0pnZv9NBc3EIfTuSPSsD66meE8tZwMenZURE5R1pD5M oTHIAo80c4Fmy+Y X-Received: by 2002:a05:6830:4116:b0:7cf:d9a3:12cf with SMTP id 46e09a7af769-7d4b3fcd2c4mr1802868a34.16.1770918098770; Thu, 12 Feb 2026 09:41:38 -0800 (PST) From: Corey Minyard To: Peter Maydell Cc: Yunpeng Yang , QEMU Developers , Mark Cave-Ayland , Jonathan Davies , Corey Minyard Subject: [PULL 1/2] hw/ipmi/ipmi_bmc_sim: Support getting fake LAN channel config Date: Thu, 12 Feb 2026 11:40:49 -0600 Message-ID: <20260212174103.504520-2-corey@minyard.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260212174103.504520-1-corey@minyard.net> References: <20260212174103.504520-1-corey@minyard.net> 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=2607:f8b0:4864:20::336; envelope-from=corey@minyard.net; helo=mail-ot1-x336.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, SPF_HELO_NONE=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: qemu development 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 @minyard.net) X-ZM-MESSAGEID: 1770918117626154100 Content-Type: text/plain; charset="utf-8" From: Yunpeng Yang The following IPMI commands are added or modified to support getting fake LAN channel configurations from the `ipmi_bmc_sim` device: * Get Channel Access; * Get Channel Info Command; * Get LAN Configuration Parameters. The fake LAN channel configurations can be specified from QEMU commandline options for device `ipmi_bmc_sim`. Inside the guest OS, the configurations can be retrieved from the device using some IPMI tools, e.g., `ipmitool lan print`. Note, there is not a real LAN channel. The fake LAN channel is suitable for testing purposes. Signed-off-by: Yunpeng Yang Message-ID: <20260105155648.1037077-2-yunpeng.yang@nutanix.com> Signed-off-by: Corey Minyard --- hw/ipmi/ipmi_bmc_sim.c | 302 +++++++++++++++++++++++++++++++++++++++-- include/hw/ipmi/ipmi.h | 1 + qemu-options.hx | 26 ++++ 3 files changed, 319 insertions(+), 10 deletions(-) diff --git a/hw/ipmi/ipmi_bmc_sim.c b/hw/ipmi/ipmi_bmc_sim.c index 3d4fe1a699..d88aa22b72 100644 --- a/hw/ipmi/ipmi_bmc_sim.c +++ b/hw/ipmi/ipmi_bmc_sim.c @@ -27,11 +27,13 @@ #include "qemu/timer.h" #include "hw/ipmi/ipmi.h" #include "qemu/error-report.h" +#include "qapi/error.h" #include "qemu/module.h" #include "hw/core/loader.h" #include "hw/core/qdev-properties.h" #include "hw/core/qdev-properties-system.h" #include "migration/vmstate.h" +#include "net/net.h" =20 #define IPMI_NETFN_CHASSIS 0x00 =20 @@ -70,6 +72,7 @@ #define IPMI_CMD_GET_MSG 0x33 #define IPMI_CMD_SEND_MSG 0x34 #define IPMI_CMD_READ_EVT_MSG_BUF 0x35 +#define IPMI_CMD_GET_CHANNEL_ACCESS 0x41 #define IPMI_CMD_GET_CHANNEL_INFO 0x42 =20 #define IPMI_NETFN_STORAGE 0x0a @@ -101,6 +104,10 @@ #define IPMI_CMD_GET_SEL_TIME 0x48 #define IPMI_CMD_SET_SEL_TIME 0x49 =20 +#define IPMI_NETFN_TRANSPORT 0x0c + +#define IPMI_CMD_GET_LAN_CONFIG 0x02 + =20 /* Same as a timespec struct. */ struct ipmi_time { @@ -170,6 +177,23 @@ typedef struct IPMISensor { #define MAX_SENSORS 20 #define IPMI_WATCHDOG_SENSOR 0 =20 +#define NBYTES_IP 4 +#define NBYTES_MAC 6 + +typedef struct IPMILan { + uint8_t channel; + uint8_t ipaddr[NBYTES_IP]; + uint8_t ipsrc; + MACAddr macaddr; + uint8_t netmask[NBYTES_IP]; + uint8_t defgw_ipaddr[NBYTES_IP]; + MACAddr defgw_macaddr; + + char *arg_ipaddr; + char *arg_netmask; + char *arg_defgw_ipaddr; +} IPMILan; + #define MAX_NETFNS 64 =20 typedef struct IPMIRcvBufEntry { @@ -215,6 +239,7 @@ struct IPMIBmcSim { IPMIFru fru; IPMISensor sensors[MAX_SENSORS]; char *sdr_filename; + IPMILan lan; =20 /* Odd netfns are for responses, so we only need the even ones. */ const IPMINetfn *netfns[MAX_NETFNS / 2]; @@ -265,6 +290,36 @@ struct IPMIBmcSim { #define IPMI_BMC_WATCHDOG_ACTION_POWER_DOWN 2 #define IPMI_BMC_WATCHDOG_ACTION_POWER_CYCLE 3 =20 +#define IPMI_CHANNEL_IMPLEMENTATION_MIN 0x1 +#define IPMI_CHANNEL_IMPLEMENTATION_MAX 0xb +#define IPMI_CHANNEL_IS_IMPLEMENTATION_SPECIFIC(c) \ + (IPMI_CHANNEL_IMPLEMENTATION_MIN <=3D (c) && \ + (c) <=3D IPMI_CHANNEL_IMPLEMENTATION_MAX) + +#define IPMI_BMC_CHANNEL_IS_LAN(ibs, c) \ + ((ibs)->lan.channel !=3D 0 && (ibs)->lan.channel =3D=3D (c)) + +#define IPMI_BMC_LAN_CFG_CC_PARAM_NOT_SUPPORTED 0x80 + +#define IPMI_BMC_LAN_CFG_PARAM_SET_IN_PROGRESS 0x00 +#define IPMI_BMC_LAN_CFG_PARAM_AUTH_TYPE_SUPPORT 0x01 +#define IPMI_BMC_LAN_CFG_PARAM_AUTH_TYPE_ENABLES 0x02 +#define IPMI_BMC_LAN_CFG_PARAM_IP_ADDR 0x03 +#define IPMI_BMC_LAN_CFG_PARAM_IP_ADDR_SOURCE 0x04 +#define IPMI_BMC_LAN_CFG_PARAM_MAC_ADDR 0x05 +#define IPMI_BMC_LAN_CFG_PARAM_SUBNET_MASK 0x06 +#define IPMI_BMC_LAN_CFG_PARAM_IPV4_HDR_PARAMS 0x07 +#define IPMI_BMC_LAN_CFG_PARAM_DEFAULT_GW_IP_ADDR 0x0c +#define IPMI_BMC_LAN_CFG_PARAM_DEFAULT_GW_MAC_ADDR 0x0d +#define IPMI_BMC_LAN_CFG_PARAM_BACKUP_GW_ADDR 0x0e +#define IPMI_BMC_LAN_CFG_PARAM_BACKUP_GW_MAC_ADDR 0x0f +#define IPMI_BMC_LAN_CFG_PARAM_COMMUNITY_STRING 0x10 +#define IPMI_BMC_LAN_CFG_PARAM_NUM_DESTINATIONS 0x11 + +#define IPMI_BMC_LAN_CFG_PARAMETER_REVISION 0x11 + +#define IPMI_BMC_LAN_CFG_IS_VALID_IP_SOURCE(v) (0x0 <=3D (v) && (v) <= =3D 0x4) + #define RSP_BUFFER_INITIALIZER { } =20 static inline void rsp_buffer_pushmore(RspBuffer *rsp, uint8_t *bytes, @@ -1231,6 +1286,25 @@ static void get_watchdog_timer(IPMIBmcSim *ibs, } } =20 +static void get_channel_access(IPMIBmcSim *ibs, + uint8_t *cmd, unsigned int cmd_len, + RspBuffer *rsp) +{ + uint8_t channel =3D cmd[2] & 0xf; + + if (channel =3D=3D IPMI_CHANNEL_IPMB || channel =3D=3D IPMI_CHANNEL_SY= STEM || + IPMI_BMC_CHANNEL_IS_LAN(ibs, channel)) { + /* alerting disabled */ + /* per message authentication disabled */ + /* user level authentication disabled */ + /* channel always available */ + rsp_buffer_push(rsp, 0x20 | 0x10 | 0x08 | 0x02); + rsp_buffer_push(rsp, 0x04); /* privilege limit: ADMINISTRATOR */ + } else { + rsp_buffer_set_error(rsp, IPMI_CC_INVALID_DATA_FIELD); + } +} + static void get_channel_info(IPMIBmcSim *ibs, uint8_t *cmd, unsigned int cmd_len, RspBuffer *rsp) @@ -1240,29 +1314,29 @@ static void get_channel_info(IPMIBmcSim *ibs, IPMIFwInfo info =3D {}; uint8_t ch =3D cmd[2] & 0x0f; =20 - /* Only define channel 0h (IPMB) and Fh (system interface) */ - if (ch =3D=3D 0x0e) { /* "This channel" */ ch =3D IPMI_CHANNEL_SYSTEM; } rsp_buffer_push(rsp, ch); =20 - if (ch !=3D IPMI_CHANNEL_IPMB && ch !=3D IPMI_CHANNEL_SYSTEM) { - /* Not a supported channel */ - rsp_buffer_set_error(rsp, IPMI_CC_INVALID_DATA_FIELD); - return; - } - if (k->get_fwinfo) { k->get_fwinfo(s, &info); } =20 + /* Only define channel 0h (IPMB), LAN, and Fh (system interface) */ if (ch =3D=3D IPMI_CHANNEL_IPMB) { rsp_buffer_push(rsp, IPMI_CHANNEL_MEDIUM_IPMB); rsp_buffer_push(rsp, IPMI_CHANNEL_PROTOCOL_IPMB); - } else { /* IPMI_CHANNEL_SYSTEM */ + } else if (IPMI_BMC_CHANNEL_IS_LAN(ibs, ch)) { + rsp_buffer_push(rsp, IPMI_CHANNEL_MEDIUM_802_3_LAN); + rsp_buffer_push(rsp, IPMI_CHANNEL_PROTOCOL_IPMB); + } else if (ch =3D=3D IPMI_CHANNEL_SYSTEM) { rsp_buffer_push(rsp, IPMI_CHANNEL_MEDIUM_SYSTEM); rsp_buffer_push(rsp, info.ipmi_channel_protocol); + } else { + /* Not a supported channel */ + rsp_buffer_set_error(rsp, IPMI_CC_INVALID_DATA_FIELD); + return; } =20 rsp_buffer_push(rsp, 0x00); /* Session-less */ @@ -2045,6 +2119,135 @@ static void set_sensor_reading(IPMIBmcSim *ibs, } } =20 +static inline bool is_ipv4_netmask_valid(const void *buf) +{ + uint32_t netmask =3D ldl_be_p(buf); + + return netmask !=3D 0 && clo32(netmask) + ctz32(netmask) =3D=3D 32; +} + +/* + * Request data (from cmd[2] to cmd[5] inclusive): + * bytes meaning + * 1 [bit 7] revision only flag, [bits 3:0] channel number + * 2 parameter selector + * 3 set selector + * 4 block selector + */ +static void get_lan_config(IPMIBmcSim *ibs, + uint8_t *cmd, unsigned int cmd_len, + RspBuffer *rsp) +{ + uint8_t channel; + + if (ibs->lan.channel =3D=3D 0) { + /* LAN channel disabled. Fail as if this command were not defined.= */ + rsp_buffer_set_error(rsp, IPMI_CC_INVALID_CMD); + return; + } + if (cmd_len < 6) { + rsp_buffer_set_error(rsp, IPMI_CC_REQUEST_DATA_LENGTH_INVALID); + return; + } + channel =3D cmd[2] & 0xf; + + rsp_buffer_push(rsp, IPMI_BMC_LAN_CFG_PARAMETER_REVISION); + if (cmd[2] & 0x80) { + /* The requester only requests parameter revision, not the paramet= er */ + return; + } + if (!IPMI_BMC_CHANNEL_IS_LAN(ibs, channel)) { + rsp_buffer_set_error(rsp, IPMI_CC_INVALID_DATA_FIELD); + return; + } + + switch (cmd[3]) { + case IPMI_BMC_LAN_CFG_PARAM_SET_IN_PROGRESS: + rsp_buffer_push(rsp, 0x0); /* set complete */ + break; + + case IPMI_BMC_LAN_CFG_PARAM_AUTH_TYPE_SUPPORT: + rsp_buffer_push(rsp, 0x01); /* Authentication type "none" supporte= d */ + break; + + case IPMI_BMC_LAN_CFG_PARAM_AUTH_TYPE_ENABLES: + /* Only authentication type "none" enabled */ + rsp_buffer_push(rsp, 0x01); /* for privilege level "Callback" */ + rsp_buffer_push(rsp, 0x01); /* for privilege level "User" */ + rsp_buffer_push(rsp, 0x01); /* for privilege level "Operator" */ + rsp_buffer_push(rsp, 0x01); /* for privilege level "Administrator"= */ + rsp_buffer_push(rsp, 0x01); /* for privilege level "OEM" */ + break; + + case IPMI_BMC_LAN_CFG_PARAM_IP_ADDR: + rsp_buffer_pushmore(rsp, ibs->lan.ipaddr, NBYTES_IP); + break; + + case IPMI_BMC_LAN_CFG_PARAM_IP_ADDR_SOURCE: + rsp_buffer_push(rsp, ibs->lan.ipsrc); + break; + + case IPMI_BMC_LAN_CFG_PARAM_MAC_ADDR: + rsp_buffer_pushmore(rsp, ibs->lan.macaddr.a, NBYTES_MAC); + break; + + case IPMI_BMC_LAN_CFG_PARAM_SUBNET_MASK: + rsp_buffer_pushmore(rsp, ibs->lan.netmask, NBYTES_IP); + break; + + case IPMI_BMC_LAN_CFG_PARAM_IPV4_HDR_PARAMS: + /* TTL 0x40 */ + rsp_buffer_push(rsp, 0x40); + /* don't fragment */ + rsp_buffer_push(rsp, 0x40); + /* precedence 0x0, minimize delay */ + rsp_buffer_push(rsp, 0x10); + break; + + case IPMI_BMC_LAN_CFG_PARAM_DEFAULT_GW_IP_ADDR: + rsp_buffer_pushmore(rsp, ibs->lan.defgw_ipaddr, NBYTES_IP); + break; + + case IPMI_BMC_LAN_CFG_PARAM_DEFAULT_GW_MAC_ADDR: + rsp_buffer_pushmore(rsp, ibs->lan.defgw_macaddr.a, NBYTES_MAC); + break; + + case IPMI_BMC_LAN_CFG_PARAM_BACKUP_GW_ADDR: + /* 0.0.0.0 */ + rsp_buffer_push(rsp, 0x00); + rsp_buffer_push(rsp, 0x00); + rsp_buffer_push(rsp, 0x00); + rsp_buffer_push(rsp, 0x00); + break; + + case IPMI_BMC_LAN_CFG_PARAM_BACKUP_GW_MAC_ADDR: + /* 00:00:00:00:00:00 */ + rsp_buffer_push(rsp, 0x00); + rsp_buffer_push(rsp, 0x00); + rsp_buffer_push(rsp, 0x00); + rsp_buffer_push(rsp, 0x00); + rsp_buffer_push(rsp, 0x00); + rsp_buffer_push(rsp, 0x00); + break; + + case IPMI_BMC_LAN_CFG_PARAM_COMMUNITY_STRING: + { + static uint8_t community_str[18] =3D "public"; + + rsp_buffer_pushmore(rsp, community_str, sizeof(community_str)); + } + break; + + case IPMI_BMC_LAN_CFG_PARAM_NUM_DESTINATIONS: + rsp_buffer_push(rsp, 0x00); /* LAN Alerting not supported */ + break; + + default: + rsp_buffer_set_error(rsp, IPMI_BMC_LAN_CFG_CC_PARAM_NOT_SUPPORTED); + return; + }; +} + static const IPMICmdHandler chassis_cmds[] =3D { [IPMI_CMD_GET_CHASSIS_CAPABILITIES] =3D { chassis_capabilities }, [IPMI_CMD_GET_CHASSIS_STATUS] =3D { chassis_status }, @@ -2089,6 +2292,7 @@ static const IPMICmdHandler app_cmds[] =3D { [IPMI_CMD_RESET_WATCHDOG_TIMER] =3D { reset_watchdog_timer }, [IPMI_CMD_SET_WATCHDOG_TIMER] =3D { set_watchdog_timer, 8 }, [IPMI_CMD_GET_WATCHDOG_TIMER] =3D { get_watchdog_timer }, + [IPMI_CMD_GET_CHANNEL_ACCESS] =3D { get_channel_access, 4 }, [IPMI_CMD_GET_CHANNEL_INFO] =3D { get_channel_info, 3 }, }; static const IPMINetfn app_netfn =3D { @@ -2119,12 +2323,22 @@ static const IPMINetfn storage_netfn =3D { .cmd_handlers =3D storage_cmds }; =20 +static const IPMICmdHandler transport_cmds[] =3D { + [IPMI_CMD_GET_LAN_CONFIG] =3D { get_lan_config }, +}; +static const IPMINetfn transport_netfn =3D { + .cmd_nums =3D ARRAY_SIZE(transport_cmds), + .cmd_handlers =3D transport_cmds +}; + + static void register_cmds(IPMIBmcSim *s) { ipmi_sim_register_netfn(s, IPMI_NETFN_CHASSIS, &chassis_netfn); ipmi_sim_register_netfn(s, IPMI_NETFN_SENSOR_EVENT, &sensor_event_netf= n); ipmi_sim_register_netfn(s, IPMI_NETFN_APP, &app_netfn); ipmi_sim_register_netfn(s, IPMI_NETFN_STORAGE, &storage_netfn); + ipmi_sim_register_netfn(s, IPMI_NETFN_TRANSPORT, &transport_netfn); } =20 static uint8_t init_sdrs[] =3D { @@ -2174,9 +2388,25 @@ static void ipmi_sdr_init(IPMIBmcSim *ibs) } } =20 +static const VMStateDescription vmstate_ipmi_sim_lan =3D { + .name =3D TYPE_IPMI_BMC_SIMULATOR "-lan", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (const VMStateField[]) { + VMSTATE_UINT8(channel, IPMILan), + VMSTATE_UINT8_ARRAY(ipaddr, IPMILan, NBYTES_IP), + VMSTATE_UINT8(ipsrc, IPMILan), + VMSTATE_UINT8_ARRAY(macaddr.a, IPMILan, NBYTES_MAC), + VMSTATE_UINT8_ARRAY(netmask, IPMILan, NBYTES_IP), + VMSTATE_UINT8_ARRAY(defgw_ipaddr, IPMILan, NBYTES_IP), + VMSTATE_UINT8_ARRAY(defgw_macaddr.a, IPMILan, NBYTES_MAC), + VMSTATE_END_OF_LIST() + } +}; + static const VMStateDescription vmstate_ipmi_sim =3D { .name =3D TYPE_IPMI_BMC_SIMULATOR, - .version_id =3D 1, + .version_id =3D 2, .minimum_version_id =3D 1, .fields =3D (const VMStateField[]) { VMSTATE_UINT8(bmc_global_enables, IPMIBmcSim), @@ -2198,6 +2428,7 @@ static const VMStateDescription vmstate_ipmi_sim =3D { VMSTATE_UINT16(sensors[IPMI_WATCHDOG_SENSOR].deassert_states, IPMIBmcSim), VMSTATE_UINT16(sensors[IPMI_WATCHDOG_SENSOR].assert_enable, IPMIBm= cSim), + VMSTATE_STRUCT(lan, IPMIBmcSim, 2, vmstate_ipmi_sim_lan, IPMILan), VMSTATE_END_OF_LIST() } }; @@ -2232,6 +2463,47 @@ out: fru->nentries =3D size / fru->areasize; } =20 +static void ipmi_lan_init(IPMILan *lan, Error **errp) +{ + struct in_addr ip; + + /* + * `lan->channel` can be either 0 (meaning LAN channel disabled) or + * a valid IPMI implementation-specific channel. + */ + if (lan->channel !=3D 0 && + !IPMI_CHANNEL_IS_IMPLEMENTATION_SPECIFIC(lan->channel)) { + error_setg(errp, "invalid LAN channel %d", lan->channel); + return; + } + if (lan->arg_ipaddr) { + if (inet_pton(AF_INET, lan->arg_ipaddr, &ip) !=3D 1) { + error_setg(errp, "invalid ip address '%s'", lan->arg_ipaddr); + return; + } + memcpy(lan->ipaddr, &ip.s_addr, NBYTES_IP); + } + if (!IPMI_BMC_LAN_CFG_IS_VALID_IP_SOURCE(lan->ipsrc)) { + error_setg(errp, "invalid ip source %d", lan->ipsrc); + return; + } + if (lan->arg_netmask) { + if (inet_pton(AF_INET, lan->arg_netmask, &ip) !=3D 1 || + !is_ipv4_netmask_valid(&ip.s_addr)) { + error_setg(errp, "invalid subnet mask '%s'", lan->arg_netmask); + return; + } + memcpy(lan->netmask, &ip.s_addr, NBYTES_IP); + } + if (lan->arg_defgw_ipaddr) { + if (inet_pton(AF_INET, lan->arg_defgw_ipaddr, &ip) !=3D 1) { + error_setg(errp, "invalid ip address '%s'", lan->arg_defgw_ipa= ddr); + return; + } + memcpy(lan->defgw_ipaddr, &ip.s_addr, NBYTES_IP); + } +} + static void ipmi_sim_realize(DeviceState *dev, Error **errp) { IPMIBmc *b =3D IPMI_BMC(dev); @@ -2259,6 +2531,9 @@ static void ipmi_sim_realize(DeviceState *dev, Error = **errp) ibs->acpi_power_state[1] =3D 0; =20 ipmi_init_sensors_from_sdrs(ibs); + + ipmi_lan_init(&ibs->lan, errp); + register_cmds(ibs); =20 ibs->timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, ipmi_timeout, ibs); @@ -2276,6 +2551,13 @@ static const Property ipmi_sim_properties[] =3D { DEFINE_PROP_UINT32("mfg_id", IPMIBmcSim, mfg_id, 0), DEFINE_PROP_UINT16("product_id", IPMIBmcSim, product_id, 0), DEFINE_PROP_UUID_NODEFAULT("guid", IPMIBmcSim, uuid), + DEFINE_PROP_UINT8("lan.channel", IPMIBmcSim, lan.channel, 0), + DEFINE_PROP_STRING("lan.ipaddr", IPMIBmcSim, lan.arg_ipaddr), + DEFINE_PROP_UINT8("lan.ipsrc", IPMIBmcSim, lan.ipsrc, 0), + DEFINE_PROP_MACADDR("lan.macaddr", IPMIBmcSim, lan.macaddr), + DEFINE_PROP_STRING("lan.netmask", IPMIBmcSim, lan.arg_netmask), + DEFINE_PROP_STRING("lan.defgw_ipaddr", IPMIBmcSim, lan.arg_defgw_ipadd= r), + DEFINE_PROP_MACADDR("lan.defgw_macaddr", IPMIBmcSim, lan.defgw_macaddr= ), }; =20 static void ipmi_sim_class_init(ObjectClass *oc, const void *data) diff --git a/include/hw/ipmi/ipmi.h b/include/hw/ipmi/ipmi.h index dabbb9ec5d..3134a85c58 100644 --- a/include/hw/ipmi/ipmi.h +++ b/include/hw/ipmi/ipmi.h @@ -45,6 +45,7 @@ enum ipmi_op { #define IPMI_CHANNEL_IPMB 0x00 #define IPMI_CHANNEL_SYSTEM 0x0f #define IPMI_CHANNEL_MEDIUM_IPMB 0x01 +#define IPMI_CHANNEL_MEDIUM_802_3_LAN 0x04 #define IPMI_CHANNEL_MEDIUM_SYSTEM 0x0c #define IPMI_CHANNEL_PROTOCOL_IPMB 0x01 #define IPMI_CHANNEL_PROTOCOL_KCS 0x05 diff --git a/qemu-options.hx b/qemu-options.hx index ec92723f10..01f2923cf8 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -1144,6 +1144,32 @@ SRST is set, get "Get GUID" command to the BMC will return it. Otherwise "Get GUID" will return an error. =20 + ``lan.channel=3Dval`` + channel number of the fake LAN channel. It can be 0 or any + integer from 0x1 to 0xb inclusive. If set to 0, the LAN channel + is disabled, otherwise the LAN channel is enabled at the + specified channel number. The default is 0. + + ``lan.ipaddr=3Daddr`` + the ipv4 address of the BMC LAN channel. + + ``lan.ipsrc=3Dval`` + the ipv4 address source of the BMC LAN channel. It can be 0 + (unspecified source), 1 (static address), 2 (DHCP), 3 (BIOS or + system software), or 4 (other source). The default is 0. + + ``lan.macaddr=3Dmac`` + the mac address of the BMC LAN channel. + + ``lan.netmask=3Dmask`` + the ipv4 subnet mask for the BMC LAN channel. + + ``lan.defgw_ipaddr=3Daddr`` + the default gateway ipv4 address for the BMC LAN channel. + + ``lan.defgw_macaddr=3Dmac`` + the default gateway mac address for the BMC LAN channel. + ``-device ipmi-bmc-extern,id=3Did,chardev=3Did[,slave_addr=3Dval]`` Add a connection to an external IPMI BMC simulator. Instead of locally emulating the BMC like the above item, instead connect to an --=20 2.43.0 From nobody Sun Apr 12 05:51:27 2026 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=none dis=none) header.from=minyard.net ARC-Seal: i=1; a=rsa-sha256; t=1770918132; cv=none; d=zohomail.com; s=zohoarc; b=PSHGmCBGpIIqtWSdo5eG4+pBNHespxX23DKj7ttWy1ql8/5jxYKsptBaSU1MLmvx6zWU8GRrzXeVEpIio+ry9YeACFYFiIz63kpFVhNFfjdhrN271ISx4/PjFJTGT7sQlxLkAgwZE64lvqumLgB0TgoGyyACyWG6fEf59gUvHos= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770918132; 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=yDTi7HslrZikJ1EUQBDRsEFUZ77CfEi18p0+zH03j1s=; b=aH+QGIQAwuG85TvjpH4TzT7V6+VDM4NKz9jqxuI8IcoPkX5X82SB3NE29AoKjGAfSdmFVSQdHbr0CGEuL9GZKJI+lRLzWiRM8JD/2fbe025cceWFrEVHdTrEJcbjkNvYuNI+yJoD+8ohGMrSTioQhvW4Aw1GMh+RmXjwk9HpUBs= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770918132800709.8173139258712; Thu, 12 Feb 2026 09:42:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqahG-00087l-Ow; Thu, 12 Feb 2026 12:41:46 -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 1vqahF-00086v-02 for qemu-devel@nongnu.org; Thu, 12 Feb 2026 12:41:45 -0500 Received: from mail-oa1-x2d.google.com ([2001:4860:4864:20::2d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vqahC-0002Xa-SR for qemu-devel@nongnu.org; Thu, 12 Feb 2026 12:41:44 -0500 Received: by mail-oa1-x2d.google.com with SMTP id 586e51a60fabf-408199852c5so50857fac.0 for ; Thu, 12 Feb 2026 09:41:41 -0800 (PST) Received: from localhost ([2001:470:b8f6:1b:ac4f:9c7a:97e9:f745]) by smtp.gmail.com with UTF8SMTPSA id 586e51a60fabf-40ee90ba325sm148055fac.8.2026.02.12.09.41.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 Feb 2026 09:41:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minyard.net; s=google; t=1770918100; x=1771522900; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yDTi7HslrZikJ1EUQBDRsEFUZ77CfEi18p0+zH03j1s=; b=BnXpnmYTmbTeKxsVMw+N2DHADtgb4qlDeb+wPgX09itJ2CAkIm0td9gc30AkIU5DCy eCM4eKFel5o0rlDfa1tdsN3w7nntFL/ApzxWeQIo3aOhmYqHO94SM6h73QxDkcXQDu2/ XQh0rMQbIMBCS+hecKMixOL9A4XZjAzMIN45yskBSt9SuFPUtbjTz/Y8dtleR9K8tlrn bVDbbvWkg/Td9mmrIfwP2Lc21NGPa8p619wLonSnogU+xSJz8bOLVMQpt2gN2/LFHDox q3s1wF7fdCSu1iAinAXrwuFku9saDbiqwV2ucCFIR3yjGeJ4aSH4nBw2IOLssWoSCawg IT5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770918100; x=1771522900; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=yDTi7HslrZikJ1EUQBDRsEFUZ77CfEi18p0+zH03j1s=; b=oenoGzuG9cWjNLMVlf4AGVVr5wM2x7FH+FpRnGLCNbZfpt5DyLjWC3qNLAhFP/AMlS Xgg/HIn91jAJ2z6DLGw4BqgJq+OH20Ni207gLn4/kWIro4z0Bqb3nBx3bn3pysrsJsy/ pI2FOp2P1Kf6TvY/QcB2NwDZkRWOHj+lfUZtpk6rc+zwZG91UxtB9vvuyDjSyWFlXfJk QldbMfES0HAO6aeA7GnoEzArQ3sONQzDB5bVs3yEuKqJwn1xmi7g0+1NGyEHg0c1n2s/ sD8Oj+f/rYsACbk73Vo3u/+8eQ5sEoihzMMxMPFSFZb0K7leDMJ4lllirYA79iX39fcm /nkg== X-Forwarded-Encrypted: i=1; AJvYcCVwkjkICwWYCLqOtF7examEitUjq66wOVHjt5K7sp/apsHObtH6sJ5q0nUTQM3pXwGyTjKw5jD3754U@nongnu.org X-Gm-Message-State: AOJu0YyZ3URHBsmou8zHED8cfSDPV6v+KK9q5GmtFNtH7HDEbfbXuNYV HgYGawPXxpObgHO5qzKnQwnYLKY346oyoFI6YY3kkH53jcEcVjqXekxncivGQrxNXBM= X-Gm-Gg: AZuq6aJ/V0q1FJQqg3GWIkfDpondWGH+l2Dn7IkcOfLjdtW7i8pnNh6qtX2ajSbw5QI LylGuyBt7LyIcv2b3qMsvvHTH+wCZ9Wrae89/GzWuvSXzdD2rj6V5l4fPY4T3nWNINAXbu0UHmh UfEhmOZmAVP2cyphUe54bYf0xwppYq13fHvo/dpvLNVCPHufp5LrkTjeiVIKaMzjcjP4mzhd0nn /0Nmb/bb7YNHoSzbPMsLUyOoAl1nuZNl8xiKV0GEcRvYpJ47GmrjgYUJxxTha6f7jQKKkqzIset UyMZcg4ftMxAbOClkzCR3mEbEcFNQobVK0/Fn+rZZBVE+GC9QnZqT4KZ0kc1oULEpH/EiFC5nZP P8PZ9g3Lb/IyIm0k0n8A5m81vhE6LhBi6ocUlwzNB4Vh+u94+wRRMSZ9M1MrqDF831Bp3dqXZi0 J8IZ2NT+GgxEj2e8Djk8J3F/FI2U5aDClxay5MAANTOG8H80KNi5t25+xNOcBOUgBsgtHAEkudb InzPA== X-Received: by 2002:a05:6871:2ea8:b0:3d4:6fba:31ff with SMTP id 586e51a60fabf-40ec9fc322fmr1340835fac.1.1770918100191; Thu, 12 Feb 2026 09:41:40 -0800 (PST) From: Corey Minyard To: Peter Maydell Cc: Yunpeng Yang , QEMU Developers , Mark Cave-Ayland , Jonathan Davies , Corey Minyard Subject: [PULL 2/2] hw/ipmi/ipmi_bmc_sim: Support setting fake LAN channel config Date: Thu, 12 Feb 2026 11:40:50 -0600 Message-ID: <20260212174103.504520-3-corey@minyard.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260212174103.504520-1-corey@minyard.net> References: <20260212174103.504520-1-corey@minyard.net> 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=2001:4860:4864:20::2d; envelope-from=corey@minyard.net; helo=mail-oa1-x2d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, SPF_HELO_NONE=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: qemu development 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 @minyard.net) X-ZM-MESSAGEID: 1770918135728154100 Content-Type: text/plain; charset="utf-8" From: Yunpeng Yang The "Set LAN Configuration Parameters" IPMI command is added to the `ipmi_bmc_sim` device to support dynamically setting fake LAN channel configurations. With the fake LAN channel enabled, inside the guest OS, tools such as `ipmitool` can be used to modify the configurations. Signed-off-by: Yunpeng Yang Message-ID: <20260105155648.1037077-3-yunpeng.yang@nutanix.com> Signed-off-by: Corey Minyard --- hw/ipmi/ipmi_bmc_sim.c | 110 +++++++++++++++++++++++++++ tests/qtest/ipmi-kcs-test.c | 143 ++++++++++++++++++++++++++++++++++++ 2 files changed, 253 insertions(+) diff --git a/hw/ipmi/ipmi_bmc_sim.c b/hw/ipmi/ipmi_bmc_sim.c index d88aa22b72..012e2ee4fe 100644 --- a/hw/ipmi/ipmi_bmc_sim.c +++ b/hw/ipmi/ipmi_bmc_sim.c @@ -106,6 +106,7 @@ =20 #define IPMI_NETFN_TRANSPORT 0x0c =20 +#define IPMI_CMD_SET_LAN_CONFIG 0x01 #define IPMI_CMD_GET_LAN_CONFIG 0x02 =20 =20 @@ -300,6 +301,7 @@ struct IPMIBmcSim { ((ibs)->lan.channel !=3D 0 && (ibs)->lan.channel =3D=3D (c)) =20 #define IPMI_BMC_LAN_CFG_CC_PARAM_NOT_SUPPORTED 0x80 +#define IPMI_BMC_LAN_CFG_CC_PARAM_READONLY 0x82 =20 #define IPMI_BMC_LAN_CFG_PARAM_SET_IN_PROGRESS 0x00 #define IPMI_BMC_LAN_CFG_PARAM_AUTH_TYPE_SUPPORT 0x01 @@ -2126,6 +2128,113 @@ static inline bool is_ipv4_netmask_valid(const void= *buf) return netmask !=3D 0 && clo32(netmask) + ctz32(netmask) =3D=3D 32; } =20 +/* + * Request data (from cmd[2] on): + * bytes meaning + * 1 [bits 3:0] channel number + * 2 parameter selector + * [3:N] configuration parameter data (from cmd[4] on) + */ +static void set_lan_config(IPMIBmcSim *ibs, + uint8_t *cmd, unsigned int cmd_len, + RspBuffer *rsp) +{ + uint8_t channel; + uint8_t *param; /* pointer to configuration parameter data */ + unsigned int param_len; + + if (ibs->lan.channel =3D=3D 0) { + /* LAN channel disabled. Fail as if this command were not defined.= */ + rsp_buffer_set_error(rsp, IPMI_CC_INVALID_CMD); + return; + } + if (cmd_len < 5) { + rsp_buffer_set_error(rsp, IPMI_CC_REQUEST_DATA_LENGTH_INVALID); + return; + } + channel =3D cmd[2] & 0xf; + param =3D cmd + 4; + param_len =3D cmd_len - 4; + + if (!IPMI_BMC_CHANNEL_IS_LAN(ibs, channel)) { + rsp_buffer_set_error(rsp, IPMI_CC_INVALID_DATA_FIELD); + return; + } + + switch (cmd[3]) { + case IPMI_BMC_LAN_CFG_PARAM_IP_ADDR: + if (param_len < NBYTES_IP) { + rsp_buffer_set_error(rsp, IPMI_CC_REQUEST_DATA_LENGTH_INVALID); + return; + } + memcpy(ibs->lan.ipaddr, param, NBYTES_IP); + break; + + case IPMI_BMC_LAN_CFG_PARAM_IP_ADDR_SOURCE: + if (param_len < 1) { + rsp_buffer_set_error(rsp, IPMI_CC_REQUEST_DATA_LENGTH_INVALID); + return; + } + if (!IPMI_BMC_LAN_CFG_IS_VALID_IP_SOURCE(*param)) { + rsp_buffer_set_error(rsp, IPMI_CC_INVALID_DATA_FIELD); + return; + } + ibs->lan.ipsrc =3D *param; + break; + + case IPMI_BMC_LAN_CFG_PARAM_MAC_ADDR: + if (param_len < NBYTES_MAC) { + rsp_buffer_set_error(rsp, IPMI_CC_REQUEST_DATA_LENGTH_INVALID); + return; + } + memcpy(ibs->lan.macaddr.a, param, NBYTES_MAC); + break; + + case IPMI_BMC_LAN_CFG_PARAM_SUBNET_MASK: + if (param_len < NBYTES_IP) { + rsp_buffer_set_error(rsp, IPMI_CC_REQUEST_DATA_LENGTH_INVALID); + return; + } + if (!is_ipv4_netmask_valid(param)) { + rsp_buffer_set_error(rsp, IPMI_CC_INVALID_DATA_FIELD); + return; + } + memcpy(ibs->lan.netmask, param, NBYTES_IP); + break; + + case IPMI_BMC_LAN_CFG_PARAM_DEFAULT_GW_IP_ADDR: + if (param_len < NBYTES_IP) { + rsp_buffer_set_error(rsp, IPMI_CC_REQUEST_DATA_LENGTH_INVALID); + return; + } + memcpy(ibs->lan.defgw_ipaddr, param, NBYTES_IP); + break; + + case IPMI_BMC_LAN_CFG_PARAM_DEFAULT_GW_MAC_ADDR: + if (param_len < NBYTES_MAC) { + rsp_buffer_set_error(rsp, IPMI_CC_REQUEST_DATA_LENGTH_INVALID); + return; + } + memcpy(ibs->lan.defgw_macaddr.a, param, NBYTES_MAC); + break; + + case IPMI_BMC_LAN_CFG_PARAM_SET_IN_PROGRESS: + case IPMI_BMC_LAN_CFG_PARAM_AUTH_TYPE_SUPPORT: + case IPMI_BMC_LAN_CFG_PARAM_AUTH_TYPE_ENABLES: + case IPMI_BMC_LAN_CFG_PARAM_IPV4_HDR_PARAMS: + case IPMI_BMC_LAN_CFG_PARAM_BACKUP_GW_ADDR: + case IPMI_BMC_LAN_CFG_PARAM_BACKUP_GW_MAC_ADDR: + case IPMI_BMC_LAN_CFG_PARAM_COMMUNITY_STRING: + case IPMI_BMC_LAN_CFG_PARAM_NUM_DESTINATIONS: + rsp_buffer_set_error(rsp, IPMI_BMC_LAN_CFG_CC_PARAM_READONLY); + return; + + default: + rsp_buffer_set_error(rsp, IPMI_BMC_LAN_CFG_CC_PARAM_NOT_SUPPORTED); + return; + } +} + /* * Request data (from cmd[2] to cmd[5] inclusive): * bytes meaning @@ -2324,6 +2433,7 @@ static const IPMINetfn storage_netfn =3D { }; =20 static const IPMICmdHandler transport_cmds[] =3D { + [IPMI_CMD_SET_LAN_CONFIG] =3D { set_lan_config }, [IPMI_CMD_GET_LAN_CONFIG] =3D { get_lan_config }, }; static const IPMINetfn transport_netfn =3D { diff --git a/tests/qtest/ipmi-kcs-test.c b/tests/qtest/ipmi-kcs-test.c index 3186c6ad64..9bab0d84ad 100644 --- a/tests/qtest/ipmi-kcs-test.c +++ b/tests/qtest/ipmi-kcs-test.c @@ -262,6 +262,144 @@ static void test_enable_irq(void) kcs_ints_enabled =3D 1; } =20 + +static uint8_t get_channel_access_cmd[] =3D { 0x18, 0x41, 0x01, 0x40 }; +static uint8_t get_channel_access_rsp[] =3D { 0x1c, 0x41, 0x00, 0x3a, 0x04= }; + +/* + * Get channel access + */ +static void test_kcs_channel_access(void) +{ + uint8_t rsp[20]; + unsigned int rsplen =3D sizeof(rsp); + + kcs_cmd(get_channel_access_cmd, sizeof(get_channel_access_cmd), + rsp, &rsplen); + g_assert(rsplen =3D=3D sizeof(get_channel_access_rsp)); + g_assert(memcmp(get_channel_access_rsp, rsp, rsplen) =3D=3D 0); +} + + +static uint8_t get_channel_info_cmd[] =3D { 0x18, 0x42, 0x01 }; +static uint8_t get_channel_info_rsp[] =3D { 0x1c, 0x42, 0x00, 0x01, 0x04, = 0x01, + 0x00, 0xf2, 0x1b, 0x00, 0x00, 0x= 00 }; + +/* + * Get channel info + */ +static void test_kcs_channel_info(void) +{ + uint8_t rsp[20]; + unsigned int rsplen =3D sizeof(rsp); + + kcs_cmd(get_channel_info_cmd, sizeof(get_channel_info_cmd), rsp, &rspl= en); + g_assert(rsplen =3D=3D sizeof(get_channel_info_rsp)); + g_assert(memcmp(get_channel_info_rsp, rsp, rsplen) =3D=3D 0); +} + + +/* get ip address (specified in cmdline): 10.0.0.2 */ +static uint8_t get_ipaddr_cmd[] =3D { 0x30, 0x02, 0x01, 0x03, 0x00, 0x00 }; +static uint8_t get_ipaddr_rsp[] =3D { 0x34, 0x02, 0x00, 0x11, + 0x0a, 0x00, 0x00, 0x02 }; + +/* + * Get LAN configurations + */ +static void test_kcs_lan_get(void) +{ + uint8_t rsp[20]; + unsigned int rsplen =3D sizeof(rsp); + + kcs_cmd(get_ipaddr_cmd, sizeof(get_ipaddr_cmd), rsp, &rsplen); + g_assert(rsplen =3D=3D sizeof(get_ipaddr_rsp)); + g_assert(memcmp(get_ipaddr_rsp, rsp, rsplen) =3D=3D 0); +} + + +/* set/get ip address: 192.0.2.2 */ +static uint8_t lan_set_ipaddr_cmd[] =3D { 0x30, 0x01, 0x01, 0x03, + 0xc0, 0x00, 0x02, 0x02 }; +static uint8_t lan_set_ipaddr_rsp[] =3D { 0x34, 0x01, 0x00 }; +static uint8_t lan_get_ipaddr_cmd[] =3D { 0x30, 0x02, 0x01, 0x03, 0x00, 0x= 00 }; +static uint8_t lan_get_ipaddr_rsp[] =3D { 0x34, 0x02, 0x00, 0x11, + 0xc0, 0x00, 0x02, 0x02 }; +/* set ip address source: static */ +static uint8_t lan_set_ipsrc_cmd[] =3D { 0x30, 0x01, 0x01, 0x04, 0x01 }; +static uint8_t lan_set_ipsrc_rsp[] =3D { 0x34, 0x01, 0x00 }; + +/* set/get subnet mask: 255.255.255.0 */ +static uint8_t lan_set_netmask_cmd[] =3D { 0x30, 0x01, 0x01, 0x06, + 0xff, 0xff, 0xff, 0x00 }; +static uint8_t lan_set_netmask_rsp[] =3D { 0x34, 0x01, 0x00 }; +static uint8_t lan_get_netmask_cmd[] =3D { 0x30, 0x02, 0x01, 0x06, 0x00, 0= x00 }; +static uint8_t lan_get_netmask_rsp[] =3D { 0x34, 0x02, 0x00, 0x11, + 0xff, 0xff, 0xff, 0x00 }; + +/* set/get default gateway ip address: 192.0.2.1 */ +static uint8_t lan_set_defgw_ipaddr_cmd[] =3D { 0x30, 0x01, 0x01, 0x0c, + 0xc0, 0x00, 0x02, 0x01 }; +static uint8_t lan_set_defgw_ipaddr_rsp[] =3D { 0x34, 0x01, 0x00 }; +static uint8_t lan_get_defgw_ipaddr_cmd[] =3D { 0x30, 0x02, 0x01, 0x0c, + 0x00, 0x00 }; +static uint8_t lan_get_defgw_ipaddr_rsp[] =3D { 0x34, 0x02, 0x00, 0x11, + 0xc0, 0x00, 0x02, 0x01 }; + +/* + * Set and then get LAN configurations + */ +static void test_kcs_lan_set_get(void) +{ + uint8_t rsp[20]; + unsigned int rsplen =3D 0; + + /* set ip address */ + rsplen =3D sizeof(rsp); + kcs_cmd(lan_set_ipaddr_cmd, sizeof(lan_set_ipaddr_cmd), rsp, &rsplen); + g_assert(rsplen =3D=3D sizeof(lan_set_ipaddr_rsp)); + g_assert(memcmp(lan_set_ipaddr_rsp, rsp, rsplen) =3D=3D 0); + + /* get ip address */ + rsplen =3D sizeof(rsp); + kcs_cmd(lan_get_ipaddr_cmd, sizeof(lan_get_ipaddr_cmd), rsp, &rsplen); + g_assert(rsplen =3D=3D sizeof(lan_get_ipaddr_rsp)); + g_assert(memcmp(lan_get_ipaddr_rsp, rsp, rsplen) =3D=3D 0); + + /* set ip address source */ + rsplen =3D sizeof(rsp); + kcs_cmd(lan_set_ipsrc_cmd, sizeof(lan_set_ipsrc_cmd), rsp, &rsplen); + g_assert(rsplen =3D=3D sizeof(lan_set_ipsrc_rsp)); + g_assert(memcmp(lan_set_ipsrc_rsp, rsp, rsplen) =3D=3D 0); + + /* set subnet mask */ + rsplen =3D sizeof(rsp); + kcs_cmd(lan_set_netmask_cmd, sizeof(lan_set_netmask_cmd), rsp, &rsplen= ); + g_assert(rsplen =3D=3D sizeof(lan_set_netmask_rsp)); + g_assert(memcmp(lan_set_netmask_rsp, rsp, rsplen) =3D=3D 0); + + /* get subnet mask */ + rsplen =3D sizeof(rsp); + kcs_cmd(lan_get_netmask_cmd, sizeof(lan_get_netmask_cmd), rsp, &rsplen= ); + g_assert(rsplen =3D=3D sizeof(lan_get_netmask_rsp)); + g_assert(memcmp(lan_get_netmask_rsp, rsp, rsplen) =3D=3D 0); + + /* set default gateway ip address */ + rsplen =3D sizeof(rsp); + kcs_cmd(lan_set_defgw_ipaddr_cmd, sizeof(lan_set_defgw_ipaddr_cmd), + rsp, &rsplen); + g_assert(rsplen =3D=3D sizeof(lan_set_defgw_ipaddr_rsp)); + g_assert(memcmp(lan_set_defgw_ipaddr_rsp, rsp, rsplen) =3D=3D 0); + + /* get default gateway ip address */ + rsplen =3D sizeof(rsp); + kcs_cmd(lan_get_defgw_ipaddr_cmd, sizeof(lan_get_defgw_ipaddr_cmd), + rsp, &rsplen); + g_assert(rsplen =3D=3D sizeof(lan_get_defgw_ipaddr_rsp)); + g_assert(memcmp(lan_get_defgw_ipaddr_rsp, rsp, rsplen) =3D=3D 0); +} + + int main(int argc, char **argv) { char *cmdline; @@ -271,6 +409,7 @@ int main(int argc, char **argv) g_test_init(&argc, &argv, NULL); =20 cmdline =3D g_strdup_printf("-device ipmi-bmc-sim,id=3Dbmc0" + ",lan.channel=3D1,lan.ipaddr=3D10.0= .0.2" " -device isa-ipmi-kcs,bmc=3Dbmc0"); qtest_start(cmdline); g_free(cmdline); @@ -280,6 +419,10 @@ int main(int argc, char **argv) qtest_add_func("/ipmi/local/kcs_enable_irq", test_enable_irq); qtest_add_func("/ipmi/local/kcs_base_irq", test_kcs_base); qtest_add_func("/ipmi/local/kcs_abort_irq", test_kcs_abort); + qtest_add_func("/ipmi/local/kcs_channel_access", test_kcs_channel_acce= ss); + qtest_add_func("/ipmi/local/kcs_channel_info", test_kcs_channel_info); + qtest_add_func("/ipmi/local/kcs_lan_get", test_kcs_lan_get); + qtest_add_func("/ipmi/local/kcs_lan_set_get", test_kcs_lan_set_get); ret =3D g_test_run(); qtest_quit(global_qtest); =20 --=20 2.43.0