From e5ab844259f569656e95f5324f7428229dd811a7 Mon Sep 17 00:00:00 2001 From: Cheng C Yang Date: Wed, 3 Jul 2019 07:39:47 +0800 Subject: [PATCH] Add dbus interface for sol commands Add dbus interface for sol config parameters so that after move set/get sol config parameter command from net-ipmid to host-ipmid, the command can send config parameters to net-ipmid sol service through the dbus interface. Tested by: busctl introspect xyz.openbmc_project.Settings /xyz/openbmc_project /network/host0/sol can show correct dbus properties of sol parameters. ipmitool -I lanplus -H x -U x -P x raw 0x0c 0x21 0x0e 0x00 0x01 ipmitool -I lanplus -H x -U x -P x raw 0x0c 0x21 0x0e 0x01 0x00 ipmitool -I lanplus -H x -U x -P x raw 0x0c 0x21 0x0e 0x02 0x83 ipmitool -I lanplus -H x -U x -P x raw 0x0c 0x21 0x0e 0x03 0x5 0x03 ipmitool -I lanplus -H x -U x -P x raw 0x0c 0x21 0x0e 0x04 0x5 0x03 all these commands can change the dbus properties as the value in above commands. Before and after run these commands, ipmitool -I lanplus -H x -U x -P x sol activate can start sol session correctly. After reboot BMC, "Progress" property in dbus interface change back to 0 and other properties will not reset to default value. Signed-off-by: Cheng C Yang --- command/payload_cmds.cpp | 3 + command/sol_cmds.cpp | 84 -------------------------- sol/sol_manager.cpp | 124 +++++++++++++++++++++++++++++++++++++++ sol/sol_manager.hpp | 1 + sol_module.cpp | 6 -- 5 files changed, 128 insertions(+), 90 deletions(-) diff --git a/command/payload_cmds.cpp b/command/payload_cmds.cpp index c8e682e..bc987c5 100644 --- a/command/payload_cmds.cpp +++ b/command/payload_cmds.cpp @@ -41,6 +41,9 @@ std::vector activatePayload(const std::vector& inPayload, return outPayload; } + std::get(singletonPool) + .updateSOLParameter(ipmi::convertCurrentChannelNum( + ipmi::currentChNum, getInterfaceIndex())); if (!std::get(singletonPool).enable) { response->completionCode = IPMI_CC_PAYLOAD_TYPE_DISABLED; diff --git a/command/sol_cmds.cpp b/command/sol_cmds.cpp index fda3e91..a1e820f 100644 --- a/command/sol_cmds.cpp +++ b/command/sol_cmds.cpp @@ -71,90 +71,6 @@ void activating(uint8_t payloadInstance, uint32_t sessionID) outPayload); } -std::vector setConfParams(const std::vector& inPayload, - const message::Handler& handler) -{ - std::vector outPayload(sizeof(SetConfParamsResponse)); - auto request = - reinterpret_cast(inPayload.data()); - auto response = reinterpret_cast(outPayload.data()); - response->completionCode = IPMI_CC_OK; - - switch (static_cast(request->paramSelector)) - { - case Parameter::PROGRESS: - { - uint8_t progress = request->value & progressMask; - std::get(singletonPool).progress = progress; - break; - } - case Parameter::ENABLE: - { - bool enable = request->value & enableMask; - std::get(singletonPool).enable = enable; - break; - } - case Parameter::AUTHENTICATION: - { - if (!request->auth.auth || !request->auth.encrypt) - { - response->completionCode = ipmiCCWriteReadParameter; - } - else if (request->auth.privilege < - static_cast(session::Privilege::USER) || - request->auth.privilege > - static_cast(session::Privilege::OEM)) - { - response->completionCode = IPMI_CC_INVALID_FIELD_REQUEST; - } - else - { - std::get(singletonPool).solMinPrivilege = - static_cast(request->auth.privilege); - } - break; - } - case Parameter::ACCUMULATE: - { - using namespace std::chrono_literals; - - if (request->acc.threshold == 0) - { - response->completionCode = IPMI_CC_INVALID_FIELD_REQUEST; - break; - } - - std::get(singletonPool).accumulateInterval = - request->acc.interval * sol::accIntervalFactor * 1ms; - std::get(singletonPool).sendThreshold = - request->acc.threshold; - break; - } - case Parameter::RETRY: - { - using namespace std::chrono_literals; - - std::get(singletonPool).retryCount = - request->retry.count; - std::get(singletonPool).retryInterval = - request->retry.interval * sol::retryIntervalFactor * 1ms; - break; - } - case Parameter::PORT: - { - response->completionCode = ipmiCCWriteReadParameter; - break; - } - case Parameter::NVBITRATE: - case Parameter::VBITRATE: - case Parameter::CHANNEL: - default: - response->completionCode = ipmiCCParamNotSupported; - } - - return outPayload; -} - std::vector getConfParams(const std::vector& inPayload, const message::Handler& handler) { diff --git a/sol/sol_manager.cpp b/sol/sol_manager.cpp index a118457..55d269a 100644 --- a/sol/sol_manager.cpp +++ b/sol/sol_manager.cpp @@ -14,6 +14,11 @@ #include #include #include +#include + +constexpr const char* solInterface = "xyz.openbmc_project.Ipmi.SOL"; +constexpr const char* solPath = "/xyz/openbmc_project/ipmi/sol/"; +constexpr const char* PROP_INTF = "org.freedesktop.DBus.Properties"; namespace sol { @@ -103,6 +108,125 @@ void Manager::stopHostConsole() } } +std::string getService(sdbusplus::bus::bus& bus, const std::string& intf, + const std::string& path) +{ + auto mapperCall = + bus.new_method_call("xyz.openbmc_project.ObjectMapper", + "/xyz/openbmc_project/object_mapper", + "xyz.openbmc_project.ObjectMapper", "GetObject"); + + mapperCall.append(path); + mapperCall.append(std::vector({intf})); + + std::map> mapperResponse; + + try + { + auto mapperResponseMsg = bus.call(mapperCall); + mapperResponseMsg.read(mapperResponse); + } + catch (sdbusplus::exception_t&) + { + throw std::runtime_error("ERROR in mapper call"); + } + + if (mapperResponse.begin() == mapperResponse.end()) + { + throw std::runtime_error("ERROR in reading the mapper response"); + } + + return mapperResponse.begin()->first; +} + +ipmi::PropertyMap getAllDbusProperties(sdbusplus::bus::bus& bus, + const std::string& service, + const std::string& objPath, + const std::string& interface) +{ + ipmi::PropertyMap properties; + + sdbusplus::message::message method = bus.new_method_call( + service.c_str(), objPath.c_str(), PROP_INTF, "GetAll"); + + method.append(interface); + + try + { + sdbusplus::message::message reply = bus.call(method); + reply.read(properties); + } + catch (sdbusplus::exception_t&) + { + phosphor::logging::log( + "Failed to get all properties", + phosphor::logging::entry("PATH=%s", objPath.c_str()), + phosphor::logging::entry("INTERFACE=%s", interface.c_str())); + throw std::runtime_error("ERROR in reading proerties"); + } + + return properties; +} + +void Manager::updateSOLParameter(uint8_t channelNum) +{ + std::variant value; + sdbusplus::bus::bus dbus(ipmid_get_sd_bus_connection()); + static std::string solService{}; + ipmi::PropertyMap properties; + std::string ethdevice = ipmi::getChannelName(channelNum); + std::string solPathWitheEthName = solPath + ethdevice; + if (solService.empty()) + { + try + { + solService = getService(dbus, solInterface, solPathWitheEthName); + } + catch (const std::runtime_error& e) + { + solService.clear(); + phosphor::logging::log( + "Error: get SOL service failed"); + return; + } + } + try + { + properties = getAllDbusProperties(dbus, solService, solPathWitheEthName, + solInterface); + } + catch (const std::runtime_error&) + { + phosphor::logging::log( + "Error setting sol parameter"); + return; + } + + progress = std::get(properties["Progress"]); + + enable = std::get(properties["Enable"]); + + forceEncrypt = std::get(properties["ForceEncryption"]); + + forceAuth = std::get(properties["ForceAuthentication"]); + + solMinPrivilege = static_cast( + std::get(properties["Privilege"])); + + accumulateInterval = + std::get((properties["AccumulateIntervalMS"])) * + sol::accIntervalFactor * 1ms; + + sendThreshold = std::get(properties["Threshold"]); + + retryCount = std::get(properties["RetryCount"]); + + retryInterval = std::get(properties["RetryIntervalMS"]) * + sol::retryIntervalFactor * 1ms; + + return; +} + void Manager::startPayloadInstance(uint8_t payloadInstance, session::SessionID sessionID) { diff --git a/sol/sol_manager.hpp b/sol/sol_manager.hpp index 5b48add..4e797d4 100644 --- a/sol/sol_manager.hpp +++ b/sol/sol_manager.hpp @@ -252,6 +252,7 @@ class Manager * @return 0 on success and errno on failure. */ int writeConsoleSocket(const std::vector& input) const; + void updateSOLParameter(uint8_t channelNum); private: SOLPayloadMap payloadMap; diff --git a/sol_module.cpp b/sol_module.cpp index 8200e74..2b1fb46 100644 --- a/sol_module.cpp +++ b/sol_module.cpp @@ -42,12 +42,6 @@ void registerCommands() &getPayloadInfo, session::Privilege::USER, false}, - // Set SOL Configuration Parameters - {{(static_cast(message::PayloadType::IPMI) << 16) | - static_cast(::command::NetFns::TRANSPORT) | 0x21}, - &setConfParams, - session::Privilege::ADMIN, - false}, // Get SOL Configuration Parameters {{(static_cast(message::PayloadType::IPMI) << 16) | static_cast(::command::NetFns::TRANSPORT) | 0x22}, -- 2.17.1