Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | |
Patrick Venture | c2a07d4 | 2020-05-30 16:35:03 -0700 | [diff] [blame] | 17 | #include "types.hpp" |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 18 | #include "xyz/openbmc_project/Common/error.hpp" |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 19 | #include "xyz/openbmc_project/Led/Physical/server.hpp" |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 20 | |
Jayaprakash Mutyala | 9420416 | 2020-10-23 06:17:56 +0000 | [diff] [blame] | 21 | #include <openssl/crypto.h> |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 22 | #include <systemd/sd-journal.h> |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 23 | |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 24 | #include <appcommands.hpp> |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 25 | #include <boost/container/flat_map.hpp> |
Yong Li | 23737fe | 2019-02-19 08:49:55 +0800 | [diff] [blame] | 26 | #include <boost/process/child.hpp> |
| 27 | #include <boost/process/io.hpp> |
Yong Li | 0669d19 | 2019-05-06 14:01:46 +0800 | [diff] [blame] | 28 | #include <com/intel/Control/OCOTShutdownPolicy/server.hpp> |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 29 | #include <commandutils.hpp> |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 30 | #include <gpiod.hpp> |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 31 | #include <ipmid/api.hpp> |
Vernon Mauery | 5480ef6 | 2019-03-20 13:43:11 -0700 | [diff] [blame] | 32 | #include <ipmid/utils.hpp> |
James Feist | 63efafa | 2019-07-24 12:39:21 -0700 | [diff] [blame] | 33 | #include <nlohmann/json.hpp> |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 34 | #include <oemcommands.hpp> |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 35 | #include <phosphor-logging/log.hpp> |
| 36 | #include <sdbusplus/bus.hpp> |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 37 | #include <sdbusplus/message/types.hpp> |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 38 | #include <xyz/openbmc_project/Chassis/Control/NMISource/server.hpp> |
Chen,Yugang | 4f7e76b | 2019-08-20 09:28:06 +0800 | [diff] [blame] | 39 | #include <xyz/openbmc_project/Control/Boot/Mode/server.hpp> |
| 40 | #include <xyz/openbmc_project/Control/Boot/Source/server.hpp> |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 41 | #include <xyz/openbmc_project/Control/PowerSupplyRedundancy/server.hpp> |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 42 | #include <xyz/openbmc_project/Control/Security/RestrictionMode/server.hpp> |
Richard Marian Thomaiyar | 8d4f8d7 | 2019-11-11 12:06:40 +0530 | [diff] [blame] | 43 | #include <xyz/openbmc_project/Control/Security/SpecialMode/server.hpp> |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 44 | |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 45 | #include <array> |
| 46 | #include <filesystem> |
| 47 | #include <iostream> |
| 48 | #include <regex> |
| 49 | #include <string> |
| 50 | #include <variant> |
| 51 | #include <vector> |
| 52 | |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 53 | namespace ipmi |
| 54 | { |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 55 | static void registerOEMFunctions() __attribute__((constructor)); |
Vernon Mauery | 4ac799d | 2019-05-20 15:50:37 -0700 | [diff] [blame] | 56 | |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 57 | static constexpr size_t maxFRUStringLength = 0x3F; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 58 | |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 59 | static constexpr auto ethernetIntf = |
| 60 | "xyz.openbmc_project.Network.EthernetInterface"; |
| 61 | static constexpr auto networkIPIntf = "xyz.openbmc_project.Network.IP"; |
| 62 | static constexpr auto networkService = "xyz.openbmc_project.Network"; |
| 63 | static constexpr auto networkRoot = "/xyz/openbmc_project/network"; |
| 64 | |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 65 | static constexpr const char* oemNmiSourceIntf = |
| 66 | "xyz.openbmc_project.Chassis.Control.NMISource"; |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 67 | static constexpr const char* oemNmiSourceObjPath = |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 68 | "/xyz/openbmc_project/Chassis/Control/NMISource"; |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 69 | static constexpr const char* oemNmiBmcSourceObjPathProp = "BMCSource"; |
| 70 | static constexpr const char* oemNmiEnabledObjPathProp = "Enabled"; |
| 71 | |
James Feist | 63efafa | 2019-07-24 12:39:21 -0700 | [diff] [blame] | 72 | static constexpr const char* dimmOffsetFile = "/var/lib/ipmi/ipmi_dimms.json"; |
srikanta mondal | 2030d7c | 2020-05-03 17:25:25 +0000 | [diff] [blame] | 73 | static constexpr const char* multiNodeObjPath = |
| 74 | "/xyz/openbmc_project/MultiNode/Status"; |
| 75 | static constexpr const char* multiNodeIntf = |
| 76 | "xyz.openbmc_project.Chassis.MultiNode"; |
James Feist | 63efafa | 2019-07-24 12:39:21 -0700 | [diff] [blame] | 77 | |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 78 | enum class NmiSource : uint8_t |
| 79 | { |
| 80 | none = 0, |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 81 | frontPanelButton = 1, |
| 82 | watchdog = 2, |
| 83 | chassisCmd = 3, |
| 84 | memoryError = 4, |
| 85 | pciBusError = 5, |
| 86 | pch = 6, |
| 87 | chipset = 7, |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 88 | }; |
| 89 | |
Suryakanth Sekar | 822b0b4 | 2019-11-15 18:32:53 +0530 | [diff] [blame] | 90 | enum class SpecialUserIndex : uint8_t |
| 91 | { |
| 92 | rootUser = 0, |
| 93 | atScaleDebugUser = 1 |
| 94 | }; |
| 95 | |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 96 | static constexpr const char* restricionModeService = |
| 97 | "xyz.openbmc_project.RestrictionMode.Manager"; |
| 98 | static constexpr const char* restricionModeBasePath = |
| 99 | "/xyz/openbmc_project/control/security/restriction_mode"; |
| 100 | static constexpr const char* restricionModeIntf = |
| 101 | "xyz.openbmc_project.Control.Security.RestrictionMode"; |
| 102 | static constexpr const char* restricionModeProperty = "RestrictionMode"; |
| 103 | |
| 104 | static constexpr const char* specialModeService = |
| 105 | "xyz.openbmc_project.SpecialMode"; |
| 106 | static constexpr const char* specialModeBasePath = |
Richard Marian Thomaiyar | a7b7428 | 2019-09-22 21:53:14 +0530 | [diff] [blame] | 107 | "/xyz/openbmc_project/security/special_mode"; |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 108 | static constexpr const char* specialModeIntf = |
| 109 | "xyz.openbmc_project.Security.SpecialMode"; |
| 110 | static constexpr const char* specialModeProperty = "SpecialMode"; |
| 111 | |
| 112 | static constexpr const char* dBusPropertyIntf = |
| 113 | "org.freedesktop.DBus.Properties"; |
| 114 | static constexpr const char* dBusPropertyGetMethod = "Get"; |
| 115 | static constexpr const char* dBusPropertySetMethod = "Set"; |
| 116 | |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 117 | // return code: 0 successful |
| 118 | int8_t getChassisSerialNumber(sdbusplus::bus::bus& bus, std::string& serial) |
| 119 | { |
| 120 | std::string objpath = "/xyz/openbmc_project/FruDevice"; |
| 121 | std::string intf = "xyz.openbmc_project.FruDeviceManager"; |
| 122 | std::string service = getService(bus, intf, objpath); |
| 123 | ObjectValueTree valueTree = getManagedObjects(bus, service, "/"); |
| 124 | if (valueTree.empty()) |
| 125 | { |
| 126 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 127 | "No object implements interface", |
| 128 | phosphor::logging::entry("INTF=%s", intf.c_str())); |
| 129 | return -1; |
| 130 | } |
| 131 | |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 132 | for (const auto& item : valueTree) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 133 | { |
| 134 | auto interface = item.second.find("xyz.openbmc_project.FruDevice"); |
| 135 | if (interface == item.second.end()) |
| 136 | { |
| 137 | continue; |
| 138 | } |
| 139 | |
| 140 | auto property = interface->second.find("CHASSIS_SERIAL_NUMBER"); |
| 141 | if (property == interface->second.end()) |
| 142 | { |
| 143 | continue; |
| 144 | } |
| 145 | |
| 146 | try |
| 147 | { |
| 148 | Value variant = property->second; |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 149 | std::string& result = std::get<std::string>(variant); |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 150 | if (result.size() > maxFRUStringLength) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 151 | { |
| 152 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 153 | "FRU serial number exceed maximum length"); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 154 | return -1; |
| 155 | } |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 156 | serial = result; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 157 | return 0; |
| 158 | } |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 159 | catch (std::bad_variant_access& e) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 160 | { |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 161 | phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 162 | return -1; |
| 163 | } |
| 164 | } |
| 165 | return -1; |
| 166 | } |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 167 | |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 168 | // Returns the Chassis Identifier (serial #) |
| 169 | ipmi_ret_t ipmiOEMGetChassisIdentifier(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 170 | ipmi_request_t request, |
| 171 | ipmi_response_t response, |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 172 | ipmi_data_len_t dataLen, |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 173 | ipmi_context_t context) |
| 174 | { |
| 175 | std::string serial; |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 176 | if (*dataLen != 0) // invalid request if there are extra parameters |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 177 | { |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 178 | *dataLen = 0; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 179 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 180 | } |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 181 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 182 | if (getChassisSerialNumber(*dbus, serial) == 0) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 183 | { |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 184 | *dataLen = serial.size(); // length will never exceed response length |
| 185 | // as it is checked in getChassisSerialNumber |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 186 | char* resp = static_cast<char*>(response); |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 187 | serial.copy(resp, *dataLen); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 188 | return IPMI_CC_OK; |
| 189 | } |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 190 | *dataLen = 0; |
| 191 | return IPMI_CC_RESPONSE_ERROR; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | ipmi_ret_t ipmiOEMSetSystemGUID(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 195 | ipmi_request_t request, |
| 196 | ipmi_response_t response, |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 197 | ipmi_data_len_t dataLen, ipmi_context_t context) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 198 | { |
| 199 | static constexpr size_t safeBufferLength = 50; |
| 200 | char buf[safeBufferLength] = {0}; |
| 201 | GUIDData* Data = reinterpret_cast<GUIDData*>(request); |
| 202 | |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 203 | if (*dataLen != sizeof(GUIDData)) // 16bytes |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 204 | { |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 205 | *dataLen = 0; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 206 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 207 | } |
| 208 | |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 209 | *dataLen = 0; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 210 | |
| 211 | snprintf( |
| 212 | buf, safeBufferLength, |
| 213 | "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", |
| 214 | Data->timeLow4, Data->timeLow3, Data->timeLow2, Data->timeLow1, |
| 215 | Data->timeMid2, Data->timeMid1, Data->timeHigh2, Data->timeHigh1, |
| 216 | Data->clock2, Data->clock1, Data->node6, Data->node5, Data->node4, |
| 217 | Data->node3, Data->node2, Data->node1); |
| 218 | // UUID is in RFC4122 format. Ex: 61a39523-78f2-11e5-9862-e6402cfc3223 |
| 219 | std::string guid = buf; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 220 | |
| 221 | std::string objpath = "/xyz/openbmc_project/control/host0/systemGUID"; |
| 222 | std::string intf = "xyz.openbmc_project.Common.UUID"; |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 223 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 224 | std::string service = getService(*dbus, intf, objpath); |
| 225 | setDbusProperty(*dbus, service, objpath, intf, "UUID", guid); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 226 | return IPMI_CC_OK; |
| 227 | } |
| 228 | |
Jason M. Bills | b02bf09 | 2019-08-15 13:01:56 -0700 | [diff] [blame] | 229 | ipmi::RspType<> ipmiOEMDisableBMCSystemReset(bool disableResetOnSMI, |
| 230 | uint7_t reserved1) |
| 231 | { |
Jayaprakash Mutyala | 0a652fa | 2021-07-01 17:09:39 +0000 | [diff] [blame] | 232 | if (reserved1) |
| 233 | { |
| 234 | return ipmi::responseInvalidFieldRequest(); |
| 235 | } |
| 236 | |
Jason M. Bills | b02bf09 | 2019-08-15 13:01:56 -0700 | [diff] [blame] | 237 | std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus(); |
| 238 | |
| 239 | try |
| 240 | { |
| 241 | auto service = |
| 242 | ipmi::getService(*busp, bmcResetDisablesIntf, bmcResetDisablesPath); |
| 243 | ipmi::setDbusProperty(*busp, service, bmcResetDisablesPath, |
| 244 | bmcResetDisablesIntf, "ResetOnSMI", |
| 245 | !disableResetOnSMI); |
| 246 | } |
| 247 | catch (std::exception& e) |
| 248 | { |
| 249 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 250 | "Failed to set BMC reset disables", |
| 251 | phosphor::logging::entry("EXCEPTION=%s", e.what())); |
| 252 | return ipmi::responseUnspecifiedError(); |
| 253 | } |
| 254 | |
| 255 | return ipmi::responseSuccess(); |
| 256 | } |
| 257 | |
| 258 | ipmi::RspType<bool, // disableResetOnSMI |
| 259 | uint7_t // reserved |
| 260 | > |
| 261 | ipmiOEMGetBMCResetDisables() |
| 262 | { |
| 263 | bool disableResetOnSMI = true; |
| 264 | |
| 265 | std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus(); |
| 266 | try |
| 267 | { |
| 268 | auto service = |
| 269 | ipmi::getService(*busp, bmcResetDisablesIntf, bmcResetDisablesPath); |
| 270 | Value variant = |
| 271 | ipmi::getDbusProperty(*busp, service, bmcResetDisablesPath, |
| 272 | bmcResetDisablesIntf, "ResetOnSMI"); |
| 273 | disableResetOnSMI = !std::get<bool>(variant); |
| 274 | } |
| 275 | catch (std::exception& e) |
| 276 | { |
| 277 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 278 | "Failed to get BMC reset disables", |
| 279 | phosphor::logging::entry("EXCEPTION=%s", e.what())); |
| 280 | return ipmi::responseUnspecifiedError(); |
| 281 | } |
| 282 | |
| 283 | return ipmi::responseSuccess(disableResetOnSMI, 0); |
| 284 | } |
| 285 | |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 286 | ipmi_ret_t ipmiOEMSetBIOSID(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 287 | ipmi_request_t request, ipmi_response_t response, |
| 288 | ipmi_data_len_t dataLen, ipmi_context_t context) |
| 289 | { |
| 290 | DeviceInfo* data = reinterpret_cast<DeviceInfo*>(request); |
| 291 | |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 292 | if ((*dataLen < 2) || (*dataLen != (1 + data->biosIDLength))) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 293 | { |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 294 | *dataLen = 0; |
| 295 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 296 | } |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 297 | std::string idString((char*)data->biosId, data->biosIDLength); |
Chalapathi Venkataramashetty | fb9f1aa | 2021-05-07 08:37:07 +0000 | [diff] [blame] | 298 | for (auto idChar : idString) |
| 299 | { |
| 300 | if (!std::isprint(static_cast<unsigned char>(idChar))) |
| 301 | { |
| 302 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 303 | "BIOS ID contains non printable character"); |
| 304 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 305 | } |
| 306 | } |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 307 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 308 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
Chalapathi | 899bfd1 | 2020-04-15 15:07:02 +0000 | [diff] [blame] | 309 | std::string service = getService(*dbus, biosVersionIntf, biosActiveObjPath); |
| 310 | setDbusProperty(*dbus, service, biosActiveObjPath, biosVersionIntf, |
Yong Li | 2742b85 | 2019-12-16 14:55:11 +0800 | [diff] [blame] | 311 | biosVersionProp, idString); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 312 | uint8_t* bytesWritten = static_cast<uint8_t*>(response); |
| 313 | *bytesWritten = |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 314 | data->biosIDLength; // how many bytes are written into storage |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 315 | *dataLen = 1; |
| 316 | return IPMI_CC_OK; |
| 317 | } |
| 318 | |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 319 | bool getSwVerInfo(ipmi::Context::ptr ctx, uint8_t& bmcMajor, uint8_t& bmcMinor, |
| 320 | uint8_t& meMajor, uint8_t& meMinor) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 321 | { |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 322 | // step 1 : get BMC Major and Minor numbers from its DBUS property |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 323 | std::string bmcVersion; |
| 324 | if (getActiveSoftwareVersionInfo(ctx, versionPurposeBMC, bmcVersion)) |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 325 | { |
| 326 | return false; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 327 | } |
| 328 | |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 329 | std::optional<MetaRevision> rev = convertIntelVersion(bmcVersion); |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 330 | if (rev.has_value()) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 331 | { |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 332 | MetaRevision revision = rev.value(); |
| 333 | bmcMajor = revision.major; |
| 334 | |
| 335 | revision.minor = (revision.minor > 99 ? 99 : revision.minor); |
| 336 | bmcMinor = revision.minor % 10 + (revision.minor / 10) * 16; |
| 337 | } |
| 338 | |
| 339 | // step 2 : get ME Major and Minor numbers from its DBUS property |
AppaRao Puli | 32825a2 | 2020-01-17 15:52:41 +0530 | [diff] [blame] | 340 | std::string meVersion; |
| 341 | if (getActiveSoftwareVersionInfo(ctx, versionPurposeME, meVersion)) |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 342 | { |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 343 | return false; |
| 344 | } |
AppaRao Puli | 32825a2 | 2020-01-17 15:52:41 +0530 | [diff] [blame] | 345 | std::regex pattern1("(\\d+?).(\\d+?).(\\d+?).(\\d+?).(\\d+?)"); |
| 346 | constexpr size_t matchedPhosphor = 6; |
| 347 | std::smatch results; |
| 348 | if (std::regex_match(meVersion, results, pattern1)) |
| 349 | { |
| 350 | if (results.size() == matchedPhosphor) |
| 351 | { |
| 352 | meMajor = static_cast<uint8_t>(std::stoi(results[1])); |
Jayaprakash Mutyala | d065702 | 2021-08-26 21:18:08 +0000 | [diff] [blame] | 353 | meMinor = static_cast<uint8_t>(std::stoi(results[2]) << 4 | |
| 354 | std::stoi(results[3])); |
AppaRao Puli | 32825a2 | 2020-01-17 15:52:41 +0530 | [diff] [blame] | 355 | } |
| 356 | } |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 357 | return true; |
| 358 | } |
| 359 | |
| 360 | ipmi::RspType< |
| 361 | std::variant<std::string, |
| 362 | std::tuple<uint8_t, std::array<uint8_t, 2>, |
| 363 | std::array<uint8_t, 2>, std::array<uint8_t, 2>, |
| 364 | std::array<uint8_t, 2>, std::array<uint8_t, 2>>, |
| 365 | std::tuple<uint8_t, std::array<uint8_t, 2>>>> |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 366 | ipmiOEMGetDeviceInfo(ipmi::Context::ptr ctx, uint8_t entityType, |
| 367 | std::optional<uint8_t> countToRead, |
AppaRao Puli | d46cb42 | 2020-01-21 18:40:21 +0530 | [diff] [blame] | 368 | std::optional<uint8_t> offset) |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 369 | { |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 370 | if (entityType > static_cast<uint8_t>(OEMDevEntityType::sdrVer)) |
| 371 | { |
| 372 | return ipmi::responseInvalidFieldRequest(); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | // handle OEM command items |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 376 | switch (OEMDevEntityType(entityType)) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 377 | { |
| 378 | case OEMDevEntityType::biosId: |
| 379 | { |
AppaRao Puli | d46cb42 | 2020-01-21 18:40:21 +0530 | [diff] [blame] | 380 | // Byte 2&3, Only used with selecting BIOS |
| 381 | if (!countToRead || !offset) |
| 382 | { |
| 383 | return ipmi::responseReqDataLenInvalid(); |
| 384 | } |
| 385 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 386 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
Yong Li | 2742b85 | 2019-12-16 14:55:11 +0800 | [diff] [blame] | 387 | std::string service = |
Chalapathi | 899bfd1 | 2020-04-15 15:07:02 +0000 | [diff] [blame] | 388 | getService(*dbus, biosVersionIntf, biosActiveObjPath); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 389 | try |
| 390 | { |
Yong Li | 2742b85 | 2019-12-16 14:55:11 +0800 | [diff] [blame] | 391 | Value variant = |
Chalapathi | 899bfd1 | 2020-04-15 15:07:02 +0000 | [diff] [blame] | 392 | getDbusProperty(*dbus, service, biosActiveObjPath, |
Yong Li | 2742b85 | 2019-12-16 14:55:11 +0800 | [diff] [blame] | 393 | biosVersionIntf, biosVersionProp); |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 394 | std::string& idString = std::get<std::string>(variant); |
AppaRao Puli | d46cb42 | 2020-01-21 18:40:21 +0530 | [diff] [blame] | 395 | if (*offset >= idString.size()) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 396 | { |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 397 | return ipmi::responseParmOutOfRange(); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 398 | } |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 399 | size_t length = 0; |
AppaRao Puli | d46cb42 | 2020-01-21 18:40:21 +0530 | [diff] [blame] | 400 | if (*countToRead > (idString.size() - *offset)) |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 401 | { |
AppaRao Puli | d46cb42 | 2020-01-21 18:40:21 +0530 | [diff] [blame] | 402 | length = idString.size() - *offset; |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 403 | } |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 404 | else |
| 405 | { |
AppaRao Puli | d46cb42 | 2020-01-21 18:40:21 +0530 | [diff] [blame] | 406 | length = *countToRead; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 407 | } |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 408 | |
| 409 | std::string readBuf = {0}; |
| 410 | readBuf.resize(length); |
AppaRao Puli | d46cb42 | 2020-01-21 18:40:21 +0530 | [diff] [blame] | 411 | std::copy_n(idString.begin() + *offset, length, |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 412 | (readBuf.begin())); |
| 413 | return ipmi::responseSuccess(readBuf); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 414 | } |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 415 | catch (std::bad_variant_access& e) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 416 | { |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 417 | return ipmi::responseUnspecifiedError(); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 418 | } |
| 419 | } |
| 420 | break; |
| 421 | |
| 422 | case OEMDevEntityType::devVer: |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 423 | { |
AppaRao Puli | d46cb42 | 2020-01-21 18:40:21 +0530 | [diff] [blame] | 424 | // Byte 2&3, Only used with selecting BIOS |
| 425 | if (countToRead || offset) |
| 426 | { |
| 427 | return ipmi::responseReqDataLenInvalid(); |
| 428 | } |
| 429 | |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 430 | constexpr const size_t verLen = 2; |
| 431 | constexpr const size_t verTotalLen = 10; |
| 432 | std::array<uint8_t, verLen> bmcBuf = {0xff, 0xff}; |
| 433 | std::array<uint8_t, verLen> hsc0Buf = {0xff, 0xff}; |
| 434 | std::array<uint8_t, verLen> hsc1Buf = {0xff, 0xff}; |
| 435 | std::array<uint8_t, verLen> meBuf = {0xff, 0xff}; |
| 436 | std::array<uint8_t, verLen> hsc2Buf = {0xff, 0xff}; |
| 437 | // data0/1: BMC version number; data6/7: ME version number |
| 438 | // the others: HSC0/1/2 version number, not avaible. |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 439 | if (!getSwVerInfo(ctx, bmcBuf[0], bmcBuf[1], meBuf[0], meBuf[1])) |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 440 | { |
| 441 | return ipmi::responseUnspecifiedError(); |
| 442 | } |
| 443 | return ipmi::responseSuccess( |
| 444 | std::tuple< |
| 445 | uint8_t, std::array<uint8_t, verLen>, |
| 446 | std::array<uint8_t, verLen>, std::array<uint8_t, verLen>, |
| 447 | std::array<uint8_t, verLen>, std::array<uint8_t, verLen>>{ |
| 448 | verTotalLen, bmcBuf, hsc0Buf, hsc1Buf, meBuf, hsc2Buf}); |
| 449 | } |
| 450 | break; |
| 451 | |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 452 | case OEMDevEntityType::sdrVer: |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 453 | { |
AppaRao Puli | d46cb42 | 2020-01-21 18:40:21 +0530 | [diff] [blame] | 454 | // Byte 2&3, Only used with selecting BIOS |
| 455 | if (countToRead || offset) |
| 456 | { |
| 457 | return ipmi::responseReqDataLenInvalid(); |
| 458 | } |
| 459 | |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 460 | constexpr const size_t sdrLen = 2; |
| 461 | std::array<uint8_t, sdrLen> readBuf = {0x01, 0x0}; |
| 462 | return ipmi::responseSuccess( |
| 463 | std::tuple<uint8_t, std::array<uint8_t, sdrLen>>{sdrLen, |
| 464 | readBuf}); |
| 465 | } |
| 466 | break; |
| 467 | |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 468 | default: |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 469 | return ipmi::responseInvalidFieldRequest(); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 470 | } |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | ipmi_ret_t ipmiOEMGetAICFRU(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 474 | ipmi_request_t request, ipmi_response_t response, |
| 475 | ipmi_data_len_t dataLen, ipmi_context_t context) |
| 476 | { |
| 477 | if (*dataLen != 0) |
| 478 | { |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 479 | *dataLen = 0; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 480 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 481 | } |
| 482 | |
| 483 | *dataLen = 1; |
| 484 | uint8_t* res = reinterpret_cast<uint8_t*>(response); |
| 485 | // temporary fix. We don't support AIC FRU now. Just tell BIOS that no |
| 486 | // AIC is available so that BIOS will not timeout repeatly which leads to |
| 487 | // slow booting. |
| 488 | *res = 0; // Byte1=Count of SlotPosition/FruID records. |
| 489 | return IPMI_CC_OK; |
| 490 | } |
| 491 | |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 492 | ipmi_ret_t ipmiOEMGetPowerRestoreDelay(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 493 | ipmi_request_t request, |
| 494 | ipmi_response_t response, |
| 495 | ipmi_data_len_t dataLen, |
| 496 | ipmi_context_t context) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 497 | { |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 498 | GetPowerRestoreDelayRes* resp = |
| 499 | reinterpret_cast<GetPowerRestoreDelayRes*>(response); |
| 500 | |
| 501 | if (*dataLen != 0) |
| 502 | { |
| 503 | *dataLen = 0; |
| 504 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 505 | } |
| 506 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 507 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 508 | std::string service = |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 509 | getService(*dbus, powerRestoreDelayIntf, powerRestoreDelayObjPath); |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 510 | Value variant = |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 511 | getDbusProperty(*dbus, service, powerRestoreDelayObjPath, |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 512 | powerRestoreDelayIntf, powerRestoreDelayProp); |
| 513 | |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 514 | uint16_t delay = std::get<uint16_t>(variant); |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 515 | resp->byteLSB = delay; |
| 516 | resp->byteMSB = delay >> 8; |
| 517 | |
| 518 | *dataLen = sizeof(GetPowerRestoreDelayRes); |
| 519 | |
| 520 | return IPMI_CC_OK; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 521 | } |
| 522 | |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 523 | static uint8_t bcdToDec(uint8_t val) |
| 524 | { |
| 525 | return ((val / 16 * 10) + (val % 16)); |
| 526 | } |
| 527 | |
| 528 | // Allows an update utility or system BIOS to send the status of an embedded |
| 529 | // firmware update attempt to the BMC. After received, BMC will create a logging |
| 530 | // record. |
| 531 | ipmi::RspType<> ipmiOEMSendEmbeddedFwUpdStatus(uint8_t status, uint8_t target, |
| 532 | uint8_t majorRevision, |
| 533 | uint8_t minorRevision, |
| 534 | uint32_t auxInfo) |
| 535 | { |
| 536 | std::string firmware; |
Jason M. Bills | dc24927 | 2019-04-03 09:58:40 -0700 | [diff] [blame] | 537 | int instance = (target & targetInstanceMask) >> targetInstanceShift; |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 538 | target = (target & selEvtTargetMask) >> selEvtTargetShift; |
| 539 | |
| 540 | /* make sure the status is 0, 1, or 2 as per the spec */ |
| 541 | if (status > 2) |
| 542 | { |
| 543 | return ipmi::response(ipmi::ccInvalidFieldRequest); |
| 544 | } |
Jason M. Bills | dc24927 | 2019-04-03 09:58:40 -0700 | [diff] [blame] | 545 | /* make sure the target is 0, 1, 2, or 4 as per the spec */ |
| 546 | if (target > 4 || target == 3) |
| 547 | { |
| 548 | return ipmi::response(ipmi::ccInvalidFieldRequest); |
| 549 | } |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 550 | /*orignal OEM command is to record OEM SEL. |
| 551 | But openbmc does not support OEM SEL, so we redirect it to redfish event |
| 552 | logging. */ |
| 553 | std::string buildInfo; |
| 554 | std::string action; |
| 555 | switch (FWUpdateTarget(target)) |
| 556 | { |
| 557 | case FWUpdateTarget::targetBMC: |
| 558 | firmware = "BMC"; |
Jason M. Bills | dc24927 | 2019-04-03 09:58:40 -0700 | [diff] [blame] | 559 | buildInfo = "major: " + std::to_string(majorRevision) + " minor: " + |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 560 | std::to_string(bcdToDec(minorRevision)) + // BCD encoded |
| 561 | " BuildID: " + std::to_string(auxInfo); |
| 562 | buildInfo += std::to_string(auxInfo); |
| 563 | break; |
| 564 | case FWUpdateTarget::targetBIOS: |
| 565 | firmware = "BIOS"; |
| 566 | buildInfo = |
Jason M. Bills | dc24927 | 2019-04-03 09:58:40 -0700 | [diff] [blame] | 567 | "major: " + |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 568 | std::to_string(bcdToDec(majorRevision)) + // BCD encoded |
| 569 | " minor: " + |
| 570 | std::to_string(bcdToDec(minorRevision)) + // BCD encoded |
| 571 | " ReleaseNumber: " + // ASCII encoded |
| 572 | std::to_string(static_cast<uint8_t>(auxInfo >> 0) - '0') + |
| 573 | std::to_string(static_cast<uint8_t>(auxInfo >> 8) - '0') + |
| 574 | std::to_string(static_cast<uint8_t>(auxInfo >> 16) - '0') + |
| 575 | std::to_string(static_cast<uint8_t>(auxInfo >> 24) - '0'); |
| 576 | break; |
| 577 | case FWUpdateTarget::targetME: |
| 578 | firmware = "ME"; |
| 579 | buildInfo = |
Jason M. Bills | dc24927 | 2019-04-03 09:58:40 -0700 | [diff] [blame] | 580 | "major: " + std::to_string(majorRevision) + " minor1: " + |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 581 | std::to_string(bcdToDec(minorRevision)) + // BCD encoded |
| 582 | " minor2: " + |
| 583 | std::to_string(bcdToDec(static_cast<uint8_t>(auxInfo >> 0))) + |
| 584 | " build1: " + |
| 585 | std::to_string(bcdToDec(static_cast<uint8_t>(auxInfo >> 8))) + |
| 586 | " build2: " + |
| 587 | std::to_string(bcdToDec(static_cast<uint8_t>(auxInfo >> 16))); |
| 588 | break; |
| 589 | case FWUpdateTarget::targetOEMEWS: |
| 590 | firmware = "EWS"; |
Jason M. Bills | dc24927 | 2019-04-03 09:58:40 -0700 | [diff] [blame] | 591 | buildInfo = "major: " + std::to_string(majorRevision) + " minor: " + |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 592 | std::to_string(bcdToDec(minorRevision)) + // BCD encoded |
| 593 | " BuildID: " + std::to_string(auxInfo); |
| 594 | break; |
| 595 | } |
| 596 | |
Jason M. Bills | dc24927 | 2019-04-03 09:58:40 -0700 | [diff] [blame] | 597 | static const std::string openBMCMessageRegistryVersion("0.1"); |
| 598 | std::string redfishMsgID = "OpenBMC." + openBMCMessageRegistryVersion; |
| 599 | |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 600 | switch (status) |
| 601 | { |
| 602 | case 0x0: |
| 603 | action = "update started"; |
Jason M. Bills | dc24927 | 2019-04-03 09:58:40 -0700 | [diff] [blame] | 604 | redfishMsgID += ".FirmwareUpdateStarted"; |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 605 | break; |
| 606 | case 0x1: |
| 607 | action = "update completed successfully"; |
Jason M. Bills | dc24927 | 2019-04-03 09:58:40 -0700 | [diff] [blame] | 608 | redfishMsgID += ".FirmwareUpdateCompleted"; |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 609 | break; |
| 610 | case 0x2: |
| 611 | action = "update failure"; |
Jason M. Bills | dc24927 | 2019-04-03 09:58:40 -0700 | [diff] [blame] | 612 | redfishMsgID += ".FirmwareUpdateFailed"; |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 613 | break; |
| 614 | default: |
| 615 | action = "unknown"; |
| 616 | break; |
| 617 | } |
| 618 | |
Jason M. Bills | dc24927 | 2019-04-03 09:58:40 -0700 | [diff] [blame] | 619 | std::string firmwareInstanceStr = |
| 620 | firmware + " instance: " + std::to_string(instance); |
| 621 | std::string message("[firmware update] " + firmwareInstanceStr + |
| 622 | " status: <" + action + "> " + buildInfo); |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 623 | |
| 624 | sd_journal_send("MESSAGE=%s", message.c_str(), "PRIORITY=%i", LOG_INFO, |
Jason M. Bills | dc24927 | 2019-04-03 09:58:40 -0700 | [diff] [blame] | 625 | "REDFISH_MESSAGE_ID=%s", redfishMsgID.c_str(), |
| 626 | "REDFISH_MESSAGE_ARGS=%s,%s", firmwareInstanceStr.c_str(), |
| 627 | buildInfo.c_str(), NULL); |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 628 | return ipmi::responseSuccess(); |
| 629 | } |
| 630 | |
Rajashekar Gade Reddy | 2b664d5 | 2020-03-23 22:09:00 +0530 | [diff] [blame] | 631 | ipmi::RspType<uint8_t, std::vector<uint8_t>> |
| 632 | ipmiOEMSlotIpmb(ipmi::Context::ptr ctx, uint6_t reserved1, |
| 633 | uint2_t slotNumber, uint3_t baseBoardSlotNum, |
| 634 | uint3_t riserSlotNum, uint2_t reserved2, uint8_t slaveAddr, |
| 635 | uint8_t netFn, uint8_t cmd, |
| 636 | std::optional<std::vector<uint8_t>> writeData) |
| 637 | { |
| 638 | if (reserved1 || reserved2) |
| 639 | { |
| 640 | return ipmi::responseInvalidFieldRequest(); |
| 641 | } |
| 642 | |
| 643 | boost::system::error_code ec; |
| 644 | using ipmbResponse = std::tuple<int, uint8_t, uint8_t, uint8_t, uint8_t, |
| 645 | std::vector<uint8_t>>; |
| 646 | ipmbResponse res = ctx->bus->yield_method_call<ipmbResponse>( |
| 647 | ctx->yield, ec, "xyz.openbmc_project.Ipmi.Channel.Ipmb", |
| 648 | "/xyz/openbmc_project/Ipmi/Channel/Ipmb", "org.openbmc.Ipmb", |
| 649 | "SlotIpmbRequest", static_cast<uint8_t>(slotNumber), |
| 650 | static_cast<uint8_t>(baseBoardSlotNum), slaveAddr, netFn, cmd, |
| 651 | *writeData); |
| 652 | if (ec) |
| 653 | { |
| 654 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 655 | "Failed to call dbus method SlotIpmbRequest"); |
| 656 | return ipmi::responseUnspecifiedError(); |
| 657 | } |
| 658 | |
| 659 | std::vector<uint8_t> dataReceived(0); |
| 660 | int status = -1; |
| 661 | uint8_t resNetFn = 0, resLun = 0, resCmd = 0, cc = 0; |
| 662 | |
| 663 | std::tie(status, resNetFn, resLun, resCmd, cc, dataReceived) = res; |
| 664 | |
| 665 | if (status) |
| 666 | { |
| 667 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 668 | "Failed to get response from SlotIpmbRequest"); |
| 669 | return ipmi::responseResponseError(); |
| 670 | } |
| 671 | return ipmi::responseSuccess(cc, dataReceived); |
| 672 | } |
| 673 | |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 674 | ipmi_ret_t ipmiOEMSetPowerRestoreDelay(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 675 | ipmi_request_t request, |
| 676 | ipmi_response_t response, |
| 677 | ipmi_data_len_t dataLen, |
| 678 | ipmi_context_t context) |
| 679 | { |
| 680 | SetPowerRestoreDelayReq* data = |
| 681 | reinterpret_cast<SetPowerRestoreDelayReq*>(request); |
| 682 | uint16_t delay = 0; |
| 683 | |
| 684 | if (*dataLen != sizeof(SetPowerRestoreDelayReq)) |
| 685 | { |
| 686 | *dataLen = 0; |
| 687 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 688 | } |
| 689 | delay = data->byteMSB; |
| 690 | delay = (delay << 8) | data->byteLSB; |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 691 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 692 | std::string service = |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 693 | getService(*dbus, powerRestoreDelayIntf, powerRestoreDelayObjPath); |
| 694 | setDbusProperty(*dbus, service, powerRestoreDelayObjPath, |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 695 | powerRestoreDelayIntf, powerRestoreDelayProp, delay); |
| 696 | *dataLen = 0; |
| 697 | |
| 698 | return IPMI_CC_OK; |
| 699 | } |
| 700 | |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 701 | static bool cpuPresent(const std::string& cpuName) |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 702 | { |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 703 | static constexpr const char* cpuPresencePathPrefix = |
| 704 | "/xyz/openbmc_project/inventory/system/chassis/motherboard/"; |
| 705 | static constexpr const char* cpuPresenceIntf = |
| 706 | "xyz.openbmc_project.Inventory.Item"; |
| 707 | std::string cpuPresencePath = cpuPresencePathPrefix + cpuName; |
| 708 | std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus(); |
| 709 | try |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 710 | { |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 711 | auto service = |
| 712 | ipmi::getService(*busp, cpuPresenceIntf, cpuPresencePath); |
| 713 | |
| 714 | ipmi::Value result = ipmi::getDbusProperty( |
| 715 | *busp, service, cpuPresencePath, cpuPresenceIntf, "Present"); |
| 716 | return std::get<bool>(result); |
| 717 | } |
| 718 | catch (const std::exception& e) |
| 719 | { |
| 720 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 721 | "Cannot find processor presence", |
| 722 | phosphor::logging::entry("NAME=%s", cpuName.c_str())); |
| 723 | return false; |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | ipmi::RspType<bool, // CATERR Reset Enabled |
| 728 | bool, // ERR2 Reset Enabled |
| 729 | uint6_t, // reserved |
| 730 | uint8_t, // reserved, returns 0x3F |
| 731 | uint6_t, // CPU1 CATERR Count |
| 732 | uint2_t, // CPU1 Status |
| 733 | uint6_t, // CPU2 CATERR Count |
| 734 | uint2_t, // CPU2 Status |
| 735 | uint6_t, // CPU3 CATERR Count |
| 736 | uint2_t, // CPU3 Status |
| 737 | uint6_t, // CPU4 CATERR Count |
| 738 | uint2_t, // CPU4 Status |
| 739 | uint8_t // Crashdump Count |
| 740 | > |
| 741 | ipmiOEMGetProcessorErrConfig() |
| 742 | { |
| 743 | bool resetOnCATERR = false; |
| 744 | bool resetOnERR2 = false; |
| 745 | uint6_t cpu1CATERRCount = 0; |
| 746 | uint6_t cpu2CATERRCount = 0; |
| 747 | uint6_t cpu3CATERRCount = 0; |
| 748 | uint6_t cpu4CATERRCount = 0; |
| 749 | uint8_t crashdumpCount = 0; |
Jason M. Bills | 24df90f | 2021-06-15 12:46:13 -0700 | [diff] [blame] | 750 | uint2_t cpu1Status = cpuPresent("CPU_1") |
| 751 | ? types::enum_cast<uint8_t>(CPUStatus::enabled) |
| 752 | : types::enum_cast<uint8_t>(CPUStatus::notPresent); |
| 753 | uint2_t cpu2Status = cpuPresent("CPU_2") |
| 754 | ? types::enum_cast<uint8_t>(CPUStatus::enabled) |
| 755 | : types::enum_cast<uint8_t>(CPUStatus::notPresent); |
| 756 | uint2_t cpu3Status = cpuPresent("CPU_3") |
| 757 | ? types::enum_cast<uint8_t>(CPUStatus::enabled) |
| 758 | : types::enum_cast<uint8_t>(CPUStatus::notPresent); |
| 759 | uint2_t cpu4Status = cpuPresent("CPU_4") |
| 760 | ? types::enum_cast<uint8_t>(CPUStatus::enabled) |
| 761 | : types::enum_cast<uint8_t>(CPUStatus::notPresent); |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 762 | |
| 763 | std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus(); |
| 764 | try |
| 765 | { |
| 766 | auto service = ipmi::getService(*busp, processorErrConfigIntf, |
| 767 | processorErrConfigObjPath); |
| 768 | |
| 769 | ipmi::PropertyMap result = ipmi::getAllDbusProperties( |
| 770 | *busp, service, processorErrConfigObjPath, processorErrConfigIntf); |
| 771 | resetOnCATERR = std::get<bool>(result.at("ResetOnCATERR")); |
| 772 | resetOnERR2 = std::get<bool>(result.at("ResetOnERR2")); |
| 773 | cpu1CATERRCount = std::get<uint8_t>(result.at("ErrorCountCPU1")); |
| 774 | cpu2CATERRCount = std::get<uint8_t>(result.at("ErrorCountCPU2")); |
| 775 | cpu3CATERRCount = std::get<uint8_t>(result.at("ErrorCountCPU3")); |
| 776 | cpu4CATERRCount = std::get<uint8_t>(result.at("ErrorCountCPU4")); |
| 777 | crashdumpCount = std::get<uint8_t>(result.at("CrashdumpCount")); |
| 778 | } |
| 779 | catch (const std::exception& e) |
| 780 | { |
| 781 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 782 | "Failed to fetch processor error config", |
| 783 | phosphor::logging::entry("ERROR=%s", e.what())); |
| 784 | return ipmi::responseUnspecifiedError(); |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 785 | } |
| 786 | |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 787 | return ipmi::responseSuccess(resetOnCATERR, resetOnERR2, 0, 0x3F, |
| 788 | cpu1CATERRCount, cpu1Status, cpu2CATERRCount, |
| 789 | cpu2Status, cpu3CATERRCount, cpu3Status, |
| 790 | cpu4CATERRCount, cpu4Status, crashdumpCount); |
| 791 | } |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 792 | |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 793 | ipmi::RspType<> ipmiOEMSetProcessorErrConfig( |
| 794 | bool resetOnCATERR, bool resetOnERR2, uint6_t reserved1, uint8_t reserved2, |
| 795 | std::optional<bool> clearCPUErrorCount, |
| 796 | std::optional<bool> clearCrashdumpCount, std::optional<uint6_t> reserved3) |
| 797 | { |
Jayaprakash Mutyala | 0a652fa | 2021-07-01 17:09:39 +0000 | [diff] [blame] | 798 | if (reserved1 || reserved2) |
| 799 | { |
| 800 | return ipmi::responseInvalidFieldRequest(); |
| 801 | } |
| 802 | |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 803 | std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus(); |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 804 | |
| 805 | try |
| 806 | { |
Jayaprakash Mutyala | 0a652fa | 2021-07-01 17:09:39 +0000 | [diff] [blame] | 807 | if (reserved3.value_or(0)) |
| 808 | { |
| 809 | return ipmi::responseInvalidFieldRequest(); |
| 810 | } |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 811 | auto service = ipmi::getService(*busp, processorErrConfigIntf, |
| 812 | processorErrConfigObjPath); |
| 813 | ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath, |
| 814 | processorErrConfigIntf, "ResetOnCATERR", |
| 815 | resetOnCATERR); |
| 816 | ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath, |
| 817 | processorErrConfigIntf, "ResetOnERR2", |
| 818 | resetOnERR2); |
| 819 | if (clearCPUErrorCount.value_or(false)) |
| 820 | { |
| 821 | ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath, |
Jason M. Bills | d3e1993 | 2019-08-15 12:39:03 -0700 | [diff] [blame] | 822 | processorErrConfigIntf, "ErrorCountCPU1", |
| 823 | static_cast<uint8_t>(0)); |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 824 | ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath, |
Jason M. Bills | d3e1993 | 2019-08-15 12:39:03 -0700 | [diff] [blame] | 825 | processorErrConfigIntf, "ErrorCountCPU2", |
| 826 | static_cast<uint8_t>(0)); |
| 827 | ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath, |
| 828 | processorErrConfigIntf, "ErrorCountCPU3", |
| 829 | static_cast<uint8_t>(0)); |
| 830 | ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath, |
| 831 | processorErrConfigIntf, "ErrorCountCPU4", |
| 832 | static_cast<uint8_t>(0)); |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 833 | } |
| 834 | if (clearCrashdumpCount.value_or(false)) |
| 835 | { |
| 836 | ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath, |
Jason M. Bills | d3e1993 | 2019-08-15 12:39:03 -0700 | [diff] [blame] | 837 | processorErrConfigIntf, "CrashdumpCount", |
| 838 | static_cast<uint8_t>(0)); |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 839 | } |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 840 | } |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 841 | catch (std::exception& e) |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 842 | { |
Kuiying Wang | bc54667 | 2018-11-23 15:41:05 +0800 | [diff] [blame] | 843 | phosphor::logging::log<phosphor::logging::level::ERR>( |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 844 | "Failed to set processor error config", |
| 845 | phosphor::logging::entry("EXCEPTION=%s", e.what())); |
| 846 | return ipmi::responseUnspecifiedError(); |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 847 | } |
| 848 | |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 849 | return ipmi::responseSuccess(); |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 850 | } |
| 851 | |
Yong Li | 703922d | 2018-11-06 13:25:31 +0800 | [diff] [blame] | 852 | ipmi_ret_t ipmiOEMGetShutdownPolicy(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 853 | ipmi_request_t request, |
| 854 | ipmi_response_t response, |
| 855 | ipmi_data_len_t dataLen, |
| 856 | ipmi_context_t context) |
| 857 | { |
| 858 | GetOEMShutdownPolicyRes* resp = |
| 859 | reinterpret_cast<GetOEMShutdownPolicyRes*>(response); |
| 860 | |
| 861 | if (*dataLen != 0) |
| 862 | { |
| 863 | phosphor::logging::log<phosphor::logging::level::ERR>( |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 864 | "oem_get_shutdown_policy: invalid input len!"); |
Yong Li | 703922d | 2018-11-06 13:25:31 +0800 | [diff] [blame] | 865 | *dataLen = 0; |
| 866 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 867 | } |
| 868 | |
| 869 | *dataLen = 0; |
| 870 | |
| 871 | try |
| 872 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 873 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
Yong Li | 703922d | 2018-11-06 13:25:31 +0800 | [diff] [blame] | 874 | std::string service = |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 875 | getService(*dbus, oemShutdownPolicyIntf, oemShutdownPolicyObjPath); |
| 876 | Value variant = getDbusProperty( |
| 877 | *dbus, service, oemShutdownPolicyObjPath, oemShutdownPolicyIntf, |
| 878 | oemShutdownPolicyObjPathProp); |
Yong Li | 0669d19 | 2019-05-06 14:01:46 +0800 | [diff] [blame] | 879 | |
| 880 | if (sdbusplus::com::intel::Control::server::OCOTShutdownPolicy:: |
| 881 | convertPolicyFromString(std::get<std::string>(variant)) == |
| 882 | sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::Policy:: |
| 883 | NoShutdownOnOCOT) |
| 884 | { |
| 885 | resp->policy = 0; |
| 886 | } |
| 887 | else if (sdbusplus::com::intel::Control::server::OCOTShutdownPolicy:: |
| 888 | convertPolicyFromString(std::get<std::string>(variant)) == |
| 889 | sdbusplus::com::intel::Control::server::OCOTShutdownPolicy:: |
| 890 | Policy::ShutdownOnOCOT) |
| 891 | { |
| 892 | resp->policy = 1; |
| 893 | } |
| 894 | else |
| 895 | { |
| 896 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 897 | "oem_set_shutdown_policy: invalid property!", |
| 898 | phosphor::logging::entry( |
| 899 | "PROP=%s", std::get<std::string>(variant).c_str())); |
| 900 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 901 | } |
Yong Li | 703922d | 2018-11-06 13:25:31 +0800 | [diff] [blame] | 902 | // TODO needs to check if it is multi-node products, |
| 903 | // policy is only supported on node 3/4 |
| 904 | resp->policySupport = shutdownPolicySupported; |
| 905 | } |
| 906 | catch (sdbusplus::exception_t& e) |
| 907 | { |
| 908 | phosphor::logging::log<phosphor::logging::level::ERR>(e.description()); |
| 909 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 910 | } |
| 911 | |
| 912 | *dataLen = sizeof(GetOEMShutdownPolicyRes); |
| 913 | return IPMI_CC_OK; |
| 914 | } |
| 915 | |
| 916 | ipmi_ret_t ipmiOEMSetShutdownPolicy(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 917 | ipmi_request_t request, |
| 918 | ipmi_response_t response, |
| 919 | ipmi_data_len_t dataLen, |
| 920 | ipmi_context_t context) |
| 921 | { |
| 922 | uint8_t* req = reinterpret_cast<uint8_t*>(request); |
Yong Li | 0669d19 | 2019-05-06 14:01:46 +0800 | [diff] [blame] | 923 | sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::Policy policy = |
| 924 | sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::Policy:: |
| 925 | NoShutdownOnOCOT; |
Yong Li | 703922d | 2018-11-06 13:25:31 +0800 | [diff] [blame] | 926 | |
| 927 | // TODO needs to check if it is multi-node products, |
| 928 | // policy is only supported on node 3/4 |
| 929 | if (*dataLen != 1) |
| 930 | { |
| 931 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 932 | "oem_set_shutdown_policy: invalid input len!"); |
| 933 | *dataLen = 0; |
| 934 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 935 | } |
| 936 | |
| 937 | *dataLen = 0; |
| 938 | if ((*req != noShutdownOnOCOT) && (*req != shutdownOnOCOT)) |
| 939 | { |
| 940 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 941 | "oem_set_shutdown_policy: invalid input!"); |
| 942 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 943 | } |
| 944 | |
Yong Li | 0669d19 | 2019-05-06 14:01:46 +0800 | [diff] [blame] | 945 | if (*req == noShutdownOnOCOT) |
| 946 | { |
| 947 | policy = sdbusplus::com::intel::Control::server::OCOTShutdownPolicy:: |
| 948 | Policy::NoShutdownOnOCOT; |
| 949 | } |
| 950 | else |
| 951 | { |
| 952 | policy = sdbusplus::com::intel::Control::server::OCOTShutdownPolicy:: |
| 953 | Policy::ShutdownOnOCOT; |
| 954 | } |
| 955 | |
Yong Li | 703922d | 2018-11-06 13:25:31 +0800 | [diff] [blame] | 956 | try |
| 957 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 958 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
Yong Li | 703922d | 2018-11-06 13:25:31 +0800 | [diff] [blame] | 959 | std::string service = |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 960 | getService(*dbus, oemShutdownPolicyIntf, oemShutdownPolicyObjPath); |
Yong Li | 0669d19 | 2019-05-06 14:01:46 +0800 | [diff] [blame] | 961 | setDbusProperty( |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 962 | *dbus, service, oemShutdownPolicyObjPath, oemShutdownPolicyIntf, |
Yong Li | 0669d19 | 2019-05-06 14:01:46 +0800 | [diff] [blame] | 963 | oemShutdownPolicyObjPathProp, |
| 964 | sdbusplus::com::intel::Control::server::convertForMessage(policy)); |
Yong Li | 703922d | 2018-11-06 13:25:31 +0800 | [diff] [blame] | 965 | } |
| 966 | catch (sdbusplus::exception_t& e) |
| 967 | { |
| 968 | phosphor::logging::log<phosphor::logging::level::ERR>(e.description()); |
| 969 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 970 | } |
| 971 | |
| 972 | return IPMI_CC_OK; |
| 973 | } |
| 974 | |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 975 | /** @brief implementation for check the DHCP or not in IPv4 |
| 976 | * @param[in] Channel - Channel number |
| 977 | * @returns true or false. |
| 978 | */ |
| 979 | static bool isDHCPEnabled(uint8_t Channel) |
| 980 | { |
| 981 | try |
| 982 | { |
| 983 | auto ethdevice = getChannelName(Channel); |
| 984 | if (ethdevice.empty()) |
| 985 | { |
| 986 | return false; |
| 987 | } |
| 988 | auto ethIP = ethdevice + "/ipv4"; |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 989 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 990 | auto ethernetObj = |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 991 | getDbusObject(*dbus, networkIPIntf, networkRoot, ethIP); |
| 992 | auto value = getDbusProperty(*dbus, networkService, ethernetObj.first, |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 993 | networkIPIntf, "Origin"); |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 994 | if (std::get<std::string>(value) == |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 995 | "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP") |
| 996 | { |
| 997 | return true; |
| 998 | } |
| 999 | else |
| 1000 | { |
| 1001 | return false; |
| 1002 | } |
| 1003 | } |
| 1004 | catch (sdbusplus::exception_t& e) |
| 1005 | { |
| 1006 | phosphor::logging::log<phosphor::logging::level::ERR>(e.description()); |
| 1007 | return true; |
| 1008 | } |
| 1009 | } |
| 1010 | |
| 1011 | /** @brief implementes for check the DHCP or not in IPv6 |
| 1012 | * @param[in] Channel - Channel number |
| 1013 | * @returns true or false. |
| 1014 | */ |
| 1015 | static bool isDHCPIPv6Enabled(uint8_t Channel) |
| 1016 | { |
| 1017 | |
| 1018 | try |
| 1019 | { |
| 1020 | auto ethdevice = getChannelName(Channel); |
| 1021 | if (ethdevice.empty()) |
| 1022 | { |
| 1023 | return false; |
| 1024 | } |
| 1025 | auto ethIP = ethdevice + "/ipv6"; |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1026 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 1027 | auto objectInfo = |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1028 | getDbusObject(*dbus, networkIPIntf, networkRoot, ethIP); |
| 1029 | auto properties = getAllDbusProperties(*dbus, objectInfo.second, |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 1030 | objectInfo.first, networkIPIntf); |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 1031 | if (std::get<std::string>(properties["Origin"]) == |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 1032 | "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP") |
| 1033 | { |
| 1034 | return true; |
| 1035 | } |
| 1036 | else |
| 1037 | { |
| 1038 | return false; |
| 1039 | } |
| 1040 | } |
| 1041 | catch (sdbusplus::exception_t& e) |
| 1042 | { |
| 1043 | phosphor::logging::log<phosphor::logging::level::ERR>(e.description()); |
| 1044 | return true; |
| 1045 | } |
| 1046 | } |
| 1047 | |
| 1048 | /** @brief implementes the creating of default new user |
| 1049 | * @param[in] userName - new username in 16 bytes. |
| 1050 | * @param[in] userPassword - new password in 20 bytes |
| 1051 | * @returns ipmi completion code. |
| 1052 | */ |
| 1053 | ipmi::RspType<> ipmiOEMSetUser2Activation( |
| 1054 | std::array<uint8_t, ipmi::ipmiMaxUserName>& userName, |
Vernon Mauery | 3b3d29b | 2021-08-05 15:03:35 -0700 | [diff] [blame] | 1055 | const SecureBuffer& userPassword) |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 1056 | { |
Vernon Mauery | 3b3d29b | 2021-08-05 15:03:35 -0700 | [diff] [blame] | 1057 | if (userPassword.size() != ipmi::maxIpmi20PasswordSize) |
| 1058 | { |
| 1059 | return ipmi::responseReqDataLenInvalid(); |
| 1060 | } |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 1061 | bool userState = false; |
| 1062 | // Check for System Interface not exist and LAN should be static |
| 1063 | for (uint8_t channel = 0; channel < maxIpmiChannels; channel++) |
| 1064 | { |
Manish Baing | 440f62b | 2021-07-15 22:00:37 +0000 | [diff] [blame] | 1065 | ChannelInfo chInfo{}; |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 1066 | try |
| 1067 | { |
| 1068 | getChannelInfo(channel, chInfo); |
| 1069 | } |
| 1070 | catch (sdbusplus::exception_t& e) |
| 1071 | { |
| 1072 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1073 | "ipmiOEMSetUser2Activation: Failed to get Channel Info", |
| 1074 | phosphor::logging::entry("MSG: %s", e.description())); |
| 1075 | return ipmi::response(ipmi::ccUnspecifiedError); |
| 1076 | } |
| 1077 | if (chInfo.mediumType == |
| 1078 | static_cast<uint8_t>(EChannelMediumType::systemInterface)) |
| 1079 | { |
| 1080 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1081 | "ipmiOEMSetUser2Activation: system interface exist ."); |
| 1082 | return ipmi::response(ipmi::ccCommandNotAvailable); |
| 1083 | } |
| 1084 | else |
| 1085 | { |
| 1086 | |
| 1087 | if (chInfo.mediumType == |
| 1088 | static_cast<uint8_t>(EChannelMediumType::lan8032)) |
| 1089 | { |
| 1090 | if (isDHCPIPv6Enabled(channel) || isDHCPEnabled(channel)) |
| 1091 | { |
| 1092 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1093 | "ipmiOEMSetUser2Activation: DHCP enabled ."); |
| 1094 | return ipmi::response(ipmi::ccCommandNotAvailable); |
| 1095 | } |
| 1096 | } |
| 1097 | } |
| 1098 | } |
| 1099 | uint8_t maxChUsers = 0, enabledUsers = 0, fixedUsers = 0; |
| 1100 | if (ipmi::ccSuccess == |
| 1101 | ipmiUserGetAllCounts(maxChUsers, enabledUsers, fixedUsers)) |
| 1102 | { |
| 1103 | if (enabledUsers > 1) |
| 1104 | { |
| 1105 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1106 | "ipmiOEMSetUser2Activation: more than one user is enabled."); |
| 1107 | return ipmi::response(ipmi::ccCommandNotAvailable); |
| 1108 | } |
| 1109 | // Check the user 2 is enabled or not |
| 1110 | ipmiUserCheckEnabled(ipmiDefaultUserId, userState); |
| 1111 | if (userState == true) |
| 1112 | { |
| 1113 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1114 | "ipmiOEMSetUser2Activation: user 2 already enabled ."); |
| 1115 | return ipmi::response(ipmi::ccCommandNotAvailable); |
| 1116 | } |
| 1117 | } |
| 1118 | else |
| 1119 | { |
| 1120 | return ipmi::response(ipmi::ccUnspecifiedError); |
| 1121 | } |
| 1122 | |
| 1123 | #if BYTE_ORDER == LITTLE_ENDIAN |
| 1124 | PrivAccess privAccess = {PRIVILEGE_ADMIN, true, true, true, 0}; |
| 1125 | #endif |
| 1126 | #if BYTE_ORDER == BIG_ENDIAN |
| 1127 | PrivAccess privAccess = {0, true, true, true, PRIVILEGE_ADMIN}; |
| 1128 | #endif |
| 1129 | |
Vernon Mauery | 037cabd | 2020-05-14 12:16:01 -0700 | [diff] [blame] | 1130 | // ipmiUserSetUserName correctly handles char*, possibly non-null |
| 1131 | // terminated strings using ipmiMaxUserName size |
Jayaprakash Mutyala | 3fbe8d2 | 2020-10-29 14:42:59 +0000 | [diff] [blame] | 1132 | size_t nameLen = strnlen(reinterpret_cast<const char*>(userName.data()), |
| 1133 | sizeof(userName)); |
| 1134 | const std::string userNameRaw( |
| 1135 | reinterpret_cast<const char*>(userName.data()), nameLen); |
jayaprakash Mutyala | 1429d4f | 2020-03-04 18:20:16 +0000 | [diff] [blame] | 1136 | |
Vernon Mauery | 037cabd | 2020-05-14 12:16:01 -0700 | [diff] [blame] | 1137 | if (ipmi::ccSuccess == ipmiUserSetUserName(ipmiDefaultUserId, userNameRaw)) |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 1138 | { |
| 1139 | if (ipmi::ccSuccess == |
| 1140 | ipmiUserSetUserPassword( |
| 1141 | ipmiDefaultUserId, |
| 1142 | reinterpret_cast<const char*>(userPassword.data()))) |
| 1143 | { |
| 1144 | if (ipmi::ccSuccess == |
| 1145 | ipmiUserSetPrivilegeAccess( |
| 1146 | ipmiDefaultUserId, |
| 1147 | static_cast<uint8_t>(ipmi::EChannelID::chanLan1), |
| 1148 | privAccess, true)) |
| 1149 | { |
| 1150 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 1151 | "ipmiOEMSetUser2Activation: user created successfully "); |
Jayaprakash Mutyala | 9420416 | 2020-10-23 06:17:56 +0000 | [diff] [blame] | 1152 | |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 1153 | return ipmi::responseSuccess(); |
| 1154 | } |
| 1155 | } |
| 1156 | // we need to delete the default user id which added in this command as |
| 1157 | // password / priv setting is failed. |
Jayaprakash Mutyala | 3fbe8d2 | 2020-10-29 14:42:59 +0000 | [diff] [blame] | 1158 | ipmiUserSetUserName(ipmiDefaultUserId, static_cast<std::string>("")); |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 1159 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1160 | "ipmiOEMSetUser2Activation: password / priv setting is failed."); |
| 1161 | } |
| 1162 | else |
| 1163 | { |
| 1164 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1165 | "ipmiOEMSetUser2Activation: Setting username failed."); |
| 1166 | } |
| 1167 | |
| 1168 | return ipmi::response(ipmi::ccCommandNotAvailable); |
| 1169 | } |
| 1170 | |
Suryakanth Sekar | 822b0b4 | 2019-11-15 18:32:53 +0530 | [diff] [blame] | 1171 | /** @brief implementes executing the linux command |
| 1172 | * @param[in] linux command |
| 1173 | * @returns status |
| 1174 | */ |
| 1175 | |
| 1176 | static uint8_t executeCmd(const char* path) |
| 1177 | { |
| 1178 | boost::process::child execProg(path); |
| 1179 | execProg.wait(); |
| 1180 | |
| 1181 | int retCode = execProg.exit_code(); |
| 1182 | if (retCode) |
| 1183 | { |
| 1184 | return ipmi::ccUnspecifiedError; |
| 1185 | } |
| 1186 | return ipmi::ccSuccess; |
| 1187 | } |
| 1188 | |
| 1189 | /** @brief implementes ASD Security event logging |
| 1190 | * @param[in] Event message string |
| 1191 | * @param[in] Event Severity |
| 1192 | * @returns status |
| 1193 | */ |
| 1194 | |
| 1195 | static void atScaleDebugEventlog(std::string msg, int severity) |
| 1196 | { |
| 1197 | std::string eventStr = "OpenBMC.0.1." + msg; |
| 1198 | sd_journal_send("MESSAGE=Security Event: %s", eventStr.c_str(), |
| 1199 | "PRIORITY=%i", severity, "REDFISH_MESSAGE_ID=%s", |
| 1200 | eventStr.c_str(), NULL); |
| 1201 | } |
| 1202 | |
Richard Marian Thomaiyar | fc5e985 | 2019-04-14 15:06:27 +0530 | [diff] [blame] | 1203 | /** @brief implementes setting password for special user |
| 1204 | * @param[in] specialUserIndex |
| 1205 | * @param[in] userPassword - new password in 20 bytes |
| 1206 | * @returns ipmi completion code. |
| 1207 | */ |
| 1208 | ipmi::RspType<> ipmiOEMSetSpecialUserPassword(ipmi::Context::ptr ctx, |
| 1209 | uint8_t specialUserIndex, |
| 1210 | std::vector<uint8_t> userPassword) |
| 1211 | { |
| 1212 | ChannelInfo chInfo; |
Suryakanth Sekar | 822b0b4 | 2019-11-15 18:32:53 +0530 | [diff] [blame] | 1213 | ipmi_ret_t status = ipmi::ccSuccess; |
| 1214 | |
Richard Marian Thomaiyar | fc5e985 | 2019-04-14 15:06:27 +0530 | [diff] [blame] | 1215 | try |
| 1216 | { |
| 1217 | getChannelInfo(ctx->channel, chInfo); |
| 1218 | } |
| 1219 | catch (sdbusplus::exception_t& e) |
| 1220 | { |
| 1221 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1222 | "ipmiOEMSetSpecialUserPassword: Failed to get Channel Info", |
| 1223 | phosphor::logging::entry("MSG: %s", e.description())); |
| 1224 | return ipmi::responseUnspecifiedError(); |
| 1225 | } |
| 1226 | if (chInfo.mediumType != |
| 1227 | static_cast<uint8_t>(EChannelMediumType::systemInterface)) |
| 1228 | { |
| 1229 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1230 | "ipmiOEMSetSpecialUserPassword: Error - supported only in KCS " |
| 1231 | "interface"); |
| 1232 | return ipmi::responseCommandNotAvailable(); |
| 1233 | } |
Suryakanth Sekar | 822b0b4 | 2019-11-15 18:32:53 +0530 | [diff] [blame] | 1234 | |
| 1235 | // 0 for root user and 1 for AtScaleDebug is allowed |
| 1236 | if (specialUserIndex > |
| 1237 | static_cast<uint8_t>(SpecialUserIndex::atScaleDebugUser)) |
Richard Marian Thomaiyar | fc5e985 | 2019-04-14 15:06:27 +0530 | [diff] [blame] | 1238 | { |
| 1239 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1240 | "ipmiOEMSetSpecialUserPassword: Invalid user account"); |
| 1241 | return ipmi::responseParmOutOfRange(); |
| 1242 | } |
Suryakanth Sekar | 822b0b4 | 2019-11-15 18:32:53 +0530 | [diff] [blame] | 1243 | if (userPassword.size() != 0) |
Richard Marian Thomaiyar | fc5e985 | 2019-04-14 15:06:27 +0530 | [diff] [blame] | 1244 | { |
Suryakanth Sekar | 822b0b4 | 2019-11-15 18:32:53 +0530 | [diff] [blame] | 1245 | constexpr uint8_t minPasswordSizeRequired = 6; |
Patrick Williams | 2393985 | 2021-09-02 11:18:35 -0500 | [diff] [blame] | 1246 | SecureString passwd; |
Suryakanth Sekar | 822b0b4 | 2019-11-15 18:32:53 +0530 | [diff] [blame] | 1247 | if (userPassword.size() < minPasswordSizeRequired || |
| 1248 | userPassword.size() > ipmi::maxIpmi20PasswordSize) |
| 1249 | { |
Jayaprakash Mutyala | 9420416 | 2020-10-23 06:17:56 +0000 | [diff] [blame] | 1250 | OPENSSL_cleanse(userPassword.data(), userPassword.size()); |
Suryakanth Sekar | 822b0b4 | 2019-11-15 18:32:53 +0530 | [diff] [blame] | 1251 | return ipmi::responseReqDataLenInvalid(); |
| 1252 | } |
| 1253 | passwd.assign(reinterpret_cast<const char*>(userPassword.data()), |
| 1254 | userPassword.size()); |
Jayaprakash Mutyala | 9420416 | 2020-10-23 06:17:56 +0000 | [diff] [blame] | 1255 | // Clear sensitive data |
| 1256 | OPENSSL_cleanse(userPassword.data(), userPassword.size()); |
Suryakanth Sekar | 822b0b4 | 2019-11-15 18:32:53 +0530 | [diff] [blame] | 1257 | if (specialUserIndex == |
| 1258 | static_cast<uint8_t>(SpecialUserIndex::atScaleDebugUser)) |
| 1259 | { |
| 1260 | status = ipmiSetSpecialUserPassword("asdbg", passwd); |
| 1261 | |
| 1262 | atScaleDebugEventlog("AtScaleDebugSpecialUserEnabled", LOG_CRIT); |
| 1263 | } |
| 1264 | else |
| 1265 | { |
| 1266 | status = ipmiSetSpecialUserPassword("root", passwd); |
| 1267 | } |
| 1268 | return ipmi::response(status); |
Richard Marian Thomaiyar | fc5e985 | 2019-04-14 15:06:27 +0530 | [diff] [blame] | 1269 | } |
Suryakanth Sekar | 822b0b4 | 2019-11-15 18:32:53 +0530 | [diff] [blame] | 1270 | else |
| 1271 | { |
| 1272 | if (specialUserIndex == |
| 1273 | static_cast<uint8_t>(SpecialUserIndex::rootUser)) |
| 1274 | { |
| 1275 | status = executeCmd("passwd -d root"); |
| 1276 | } |
| 1277 | else |
| 1278 | { |
| 1279 | |
| 1280 | status = executeCmd("passwd -d asdbg"); |
| 1281 | |
| 1282 | if (status == 0) |
| 1283 | { |
| 1284 | atScaleDebugEventlog("AtScaleDebugSpecialUserDisabled", |
| 1285 | LOG_INFO); |
| 1286 | } |
| 1287 | } |
| 1288 | return ipmi::response(status); |
| 1289 | } |
Richard Marian Thomaiyar | fc5e985 | 2019-04-14 15:06:27 +0530 | [diff] [blame] | 1290 | } |
| 1291 | |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 1292 | namespace ledAction |
| 1293 | { |
| 1294 | using namespace sdbusplus::xyz::openbmc_project::Led::server; |
| 1295 | std::map<Physical::Action, uint8_t> actionDbusToIpmi = { |
jayaprakash Mutyala | 934ee9c | 2019-12-13 17:49:27 +0000 | [diff] [blame] | 1296 | {Physical::Action::Off, 0}, |
| 1297 | {Physical::Action::On, 2}, |
| 1298 | {Physical::Action::Blink, 1}}; |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 1299 | |
| 1300 | std::map<uint8_t, std::string> offsetObjPath = { |
| 1301 | {2, statusAmberObjPath}, {4, statusGreenObjPath}, {6, identifyLEDObjPath}}; |
| 1302 | |
| 1303 | } // namespace ledAction |
| 1304 | |
| 1305 | int8_t getLEDState(sdbusplus::bus::bus& bus, const std::string& intf, |
| 1306 | const std::string& objPath, uint8_t& state) |
| 1307 | { |
| 1308 | try |
| 1309 | { |
| 1310 | std::string service = getService(bus, intf, objPath); |
| 1311 | Value stateValue = |
| 1312 | getDbusProperty(bus, service, objPath, intf, "State"); |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 1313 | std::string strState = std::get<std::string>(stateValue); |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 1314 | state = ledAction::actionDbusToIpmi.at( |
| 1315 | sdbusplus::xyz::openbmc_project::Led::server::Physical:: |
| 1316 | convertActionFromString(strState)); |
| 1317 | } |
Patrick Williams | 69245b7 | 2021-09-02 09:23:01 -0500 | [diff] [blame] | 1318 | catch (sdbusplus::exception::exception& e) |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 1319 | { |
| 1320 | phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
| 1321 | return -1; |
| 1322 | } |
| 1323 | return 0; |
| 1324 | } |
| 1325 | |
NITIN SHARMA | abd11ca | 2019-06-12 12:31:42 +0000 | [diff] [blame] | 1326 | ipmi::RspType<uint8_t> ipmiOEMGetLEDStatus() |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 1327 | { |
NITIN SHARMA | abd11ca | 2019-06-12 12:31:42 +0000 | [diff] [blame] | 1328 | uint8_t ledstate = 0; |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 1329 | phosphor::logging::log<phosphor::logging::level::DEBUG>("GET led status"); |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1330 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 1331 | for (auto it = ledAction::offsetObjPath.begin(); |
| 1332 | it != ledAction::offsetObjPath.end(); ++it) |
| 1333 | { |
| 1334 | uint8_t state = 0; |
NITIN SHARMA | abd11ca | 2019-06-12 12:31:42 +0000 | [diff] [blame] | 1335 | if (getLEDState(*dbus, ledIntf, it->second, state) == -1) |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 1336 | { |
| 1337 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1338 | "oem_get_led_status: fail to get ID LED status!"); |
NITIN SHARMA | abd11ca | 2019-06-12 12:31:42 +0000 | [diff] [blame] | 1339 | return ipmi::responseUnspecifiedError(); |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 1340 | } |
NITIN SHARMA | abd11ca | 2019-06-12 12:31:42 +0000 | [diff] [blame] | 1341 | ledstate |= state << it->first; |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 1342 | } |
NITIN SHARMA | abd11ca | 2019-06-12 12:31:42 +0000 | [diff] [blame] | 1343 | return ipmi::responseSuccess(ledstate); |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 1344 | } |
| 1345 | |
Yong Li | 23737fe | 2019-02-19 08:49:55 +0800 | [diff] [blame] | 1346 | ipmi_ret_t ipmiOEMCfgHostSerialPortSpeed(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 1347 | ipmi_request_t request, |
| 1348 | ipmi_response_t response, |
| 1349 | ipmi_data_len_t dataLen, |
| 1350 | ipmi_context_t context) |
| 1351 | { |
| 1352 | CfgHostSerialReq* req = reinterpret_cast<CfgHostSerialReq*>(request); |
| 1353 | uint8_t* resp = reinterpret_cast<uint8_t*>(response); |
| 1354 | |
| 1355 | if (*dataLen == 0) |
| 1356 | { |
| 1357 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1358 | "CfgHostSerial: invalid input len!", |
| 1359 | phosphor::logging::entry("LEN=%d", *dataLen)); |
| 1360 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 1361 | } |
| 1362 | |
| 1363 | switch (req->command) |
| 1364 | { |
| 1365 | case getHostSerialCfgCmd: |
| 1366 | { |
| 1367 | if (*dataLen != 1) |
| 1368 | { |
| 1369 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1370 | "CfgHostSerial: invalid input len!"); |
| 1371 | *dataLen = 0; |
| 1372 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 1373 | } |
| 1374 | |
| 1375 | *dataLen = 0; |
| 1376 | |
| 1377 | boost::process::ipstream is; |
| 1378 | std::vector<std::string> data; |
| 1379 | std::string line; |
| 1380 | boost::process::child c1(fwGetEnvCmd, "-n", fwHostSerailCfgEnvName, |
| 1381 | boost::process::std_out > is); |
| 1382 | |
| 1383 | while (c1.running() && std::getline(is, line) && !line.empty()) |
| 1384 | { |
| 1385 | data.push_back(line); |
| 1386 | } |
| 1387 | |
| 1388 | c1.wait(); |
| 1389 | if (c1.exit_code()) |
| 1390 | { |
| 1391 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1392 | "CfgHostSerial:: error on execute", |
| 1393 | phosphor::logging::entry("EXECUTE=%s", fwSetEnvCmd)); |
| 1394 | // Using the default value |
| 1395 | *resp = 0; |
| 1396 | } |
| 1397 | else |
| 1398 | { |
| 1399 | if (data.size() != 1) |
| 1400 | { |
| 1401 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1402 | "CfgHostSerial:: error on read env"); |
| 1403 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 1404 | } |
| 1405 | try |
| 1406 | { |
| 1407 | unsigned long tmp = std::stoul(data[0]); |
| 1408 | if (tmp > std::numeric_limits<uint8_t>::max()) |
| 1409 | { |
| 1410 | throw std::out_of_range("Out of range"); |
| 1411 | } |
| 1412 | *resp = static_cast<uint8_t>(tmp); |
| 1413 | } |
| 1414 | catch (const std::invalid_argument& e) |
| 1415 | { |
| 1416 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1417 | "invalid config ", |
| 1418 | phosphor::logging::entry("ERR=%s", e.what())); |
| 1419 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 1420 | } |
| 1421 | catch (const std::out_of_range& e) |
| 1422 | { |
| 1423 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1424 | "out_of_range config ", |
| 1425 | phosphor::logging::entry("ERR=%s", e.what())); |
| 1426 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 1427 | } |
| 1428 | } |
| 1429 | |
| 1430 | *dataLen = 1; |
| 1431 | break; |
| 1432 | } |
| 1433 | case setHostSerialCfgCmd: |
| 1434 | { |
| 1435 | if (*dataLen != sizeof(CfgHostSerialReq)) |
| 1436 | { |
| 1437 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1438 | "CfgHostSerial: invalid input len!"); |
| 1439 | *dataLen = 0; |
| 1440 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 1441 | } |
| 1442 | |
| 1443 | *dataLen = 0; |
| 1444 | |
| 1445 | if (req->parameter > HostSerialCfgParamMax) |
| 1446 | { |
| 1447 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1448 | "CfgHostSerial: invalid input!"); |
| 1449 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 1450 | } |
| 1451 | |
| 1452 | boost::process::child c1(fwSetEnvCmd, fwHostSerailCfgEnvName, |
| 1453 | std::to_string(req->parameter)); |
| 1454 | |
| 1455 | c1.wait(); |
| 1456 | if (c1.exit_code()) |
| 1457 | { |
| 1458 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1459 | "CfgHostSerial:: error on execute", |
| 1460 | phosphor::logging::entry("EXECUTE=%s", fwGetEnvCmd)); |
| 1461 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 1462 | } |
| 1463 | break; |
| 1464 | } |
| 1465 | default: |
| 1466 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1467 | "CfgHostSerial: invalid input!"); |
| 1468 | *dataLen = 0; |
| 1469 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 1470 | } |
| 1471 | |
| 1472 | return IPMI_CC_OK; |
| 1473 | } |
| 1474 | |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1475 | constexpr const char* thermalModeInterface = |
| 1476 | "xyz.openbmc_project.Control.ThermalMode"; |
| 1477 | constexpr const char* thermalModePath = |
| 1478 | "/xyz/openbmc_project/control/thermal_mode"; |
| 1479 | |
| 1480 | bool getFanProfileInterface( |
| 1481 | sdbusplus::bus::bus& bus, |
| 1482 | boost::container::flat_map< |
| 1483 | std::string, std::variant<std::vector<std::string>, std::string>>& resp) |
| 1484 | { |
| 1485 | auto call = bus.new_method_call(settingsBusName, thermalModePath, PROP_INTF, |
| 1486 | "GetAll"); |
| 1487 | call.append(thermalModeInterface); |
| 1488 | try |
| 1489 | { |
| 1490 | auto data = bus.call(call); |
| 1491 | data.read(resp); |
| 1492 | } |
| 1493 | catch (sdbusplus::exception_t& e) |
| 1494 | { |
| 1495 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1496 | "getFanProfileInterface: can't get thermal mode!", |
| 1497 | phosphor::logging::entry("ERR=%s", e.what())); |
| 1498 | return false; |
| 1499 | } |
| 1500 | return true; |
| 1501 | } |
| 1502 | |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 1503 | /**@brief implements the OEM set fan config. |
| 1504 | * @param selectedFanProfile - fan profile to enable |
| 1505 | * @param reserved1 |
| 1506 | * @param performanceMode - Performance/Acoustic mode |
| 1507 | * @param reserved2 |
| 1508 | * @param setPerformanceMode - set Performance/Acoustic mode |
| 1509 | * @param setFanProfile - set fan profile |
| 1510 | * |
| 1511 | * @return IPMI completion code. |
| 1512 | **/ |
| 1513 | ipmi::RspType<> ipmiOEMSetFanConfig(uint8_t selectedFanProfile, |
| 1514 | |
| 1515 | uint2_t reserved1, bool performanceMode, |
| 1516 | uint3_t reserved2, bool setPerformanceMode, |
Joshi-Mansi | 619186d | 2020-01-27 19:16:03 +0530 | [diff] [blame] | 1517 | bool setFanProfile, |
| 1518 | std::optional<uint8_t> dimmGroupId, |
| 1519 | std::optional<uint32_t> dimmPresenceBitmap) |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1520 | { |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 1521 | if (reserved1 || reserved2) |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1522 | { |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 1523 | return ipmi::responseInvalidFieldRequest(); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1524 | } |
Joshi-Mansi | 619186d | 2020-01-27 19:16:03 +0530 | [diff] [blame] | 1525 | |
| 1526 | if (dimmGroupId) |
| 1527 | { |
| 1528 | if (*dimmGroupId >= maxCPUNum) |
| 1529 | { |
| 1530 | return ipmi::responseInvalidFieldRequest(); |
| 1531 | } |
| 1532 | if (!cpuPresent("CPU_" + std::to_string(*dimmGroupId + 1))) |
| 1533 | { |
| 1534 | return ipmi::responseInvalidFieldRequest(); |
| 1535 | } |
| 1536 | } |
| 1537 | |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1538 | // todo: tell bios to only send first 2 bytes |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1539 | boost::container::flat_map< |
| 1540 | std::string, std::variant<std::vector<std::string>, std::string>> |
| 1541 | profileData; |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1542 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 1543 | if (!getFanProfileInterface(*dbus, profileData)) |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1544 | { |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 1545 | return ipmi::responseUnspecifiedError(); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | std::vector<std::string>* supported = |
| 1549 | std::get_if<std::vector<std::string>>(&profileData["Supported"]); |
| 1550 | if (supported == nullptr) |
| 1551 | { |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 1552 | return ipmi::responseInvalidFieldRequest(); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1553 | } |
| 1554 | std::string mode; |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 1555 | if (setPerformanceMode) |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1556 | { |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1557 | if (performanceMode) |
| 1558 | { |
| 1559 | |
| 1560 | if (std::find(supported->begin(), supported->end(), |
| 1561 | "Performance") != supported->end()) |
| 1562 | { |
| 1563 | mode = "Performance"; |
| 1564 | } |
| 1565 | } |
| 1566 | else |
| 1567 | { |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1568 | if (std::find(supported->begin(), supported->end(), "Acoustic") != |
| 1569 | supported->end()) |
| 1570 | { |
| 1571 | mode = "Acoustic"; |
| 1572 | } |
| 1573 | } |
| 1574 | if (mode.empty()) |
| 1575 | { |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 1576 | return ipmi::responseInvalidFieldRequest(); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1577 | } |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 1578 | |
| 1579 | try |
| 1580 | { |
| 1581 | setDbusProperty(*dbus, settingsBusName, thermalModePath, |
| 1582 | thermalModeInterface, "Current", mode); |
| 1583 | } |
| 1584 | catch (sdbusplus::exception_t& e) |
| 1585 | { |
| 1586 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1587 | "ipmiOEMSetFanConfig: can't set thermal mode!", |
| 1588 | phosphor::logging::entry("EXCEPTION=%s", e.what())); |
| 1589 | return ipmi::responseResponseError(); |
| 1590 | } |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1591 | } |
| 1592 | |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 1593 | return ipmi::responseSuccess(); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1594 | } |
| 1595 | |
James Feist | 5b69363 | 2019-07-09 09:06:09 -0700 | [diff] [blame] | 1596 | ipmi::RspType<uint8_t, // profile support map |
| 1597 | uint8_t, // fan control profile enable |
| 1598 | uint8_t, // flags |
| 1599 | uint32_t // dimm presence bit map |
| 1600 | > |
| 1601 | ipmiOEMGetFanConfig(uint8_t dimmGroupId) |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1602 | { |
Joshi-Mansi | 36f05ce | 2020-01-14 14:29:34 +0530 | [diff] [blame] | 1603 | if (dimmGroupId >= maxCPUNum) |
| 1604 | { |
| 1605 | return ipmi::responseInvalidFieldRequest(); |
| 1606 | } |
| 1607 | |
| 1608 | bool cpuStatus = cpuPresent("CPU_" + std::to_string(dimmGroupId + 1)); |
| 1609 | |
| 1610 | if (!cpuStatus) |
| 1611 | { |
| 1612 | return ipmi::responseInvalidFieldRequest(); |
| 1613 | } |
| 1614 | |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1615 | boost::container::flat_map< |
| 1616 | std::string, std::variant<std::vector<std::string>, std::string>> |
| 1617 | profileData; |
| 1618 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1619 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 1620 | if (!getFanProfileInterface(*dbus, profileData)) |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1621 | { |
James Feist | 5b69363 | 2019-07-09 09:06:09 -0700 | [diff] [blame] | 1622 | return ipmi::responseResponseError(); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1623 | } |
| 1624 | |
| 1625 | std::string* current = std::get_if<std::string>(&profileData["Current"]); |
| 1626 | |
| 1627 | if (current == nullptr) |
| 1628 | { |
| 1629 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1630 | "ipmiOEMGetFanConfig: can't get current mode!"); |
James Feist | 5b69363 | 2019-07-09 09:06:09 -0700 | [diff] [blame] | 1631 | return ipmi::responseResponseError(); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1632 | } |
| 1633 | bool performance = (*current == "Performance"); |
| 1634 | |
James Feist | 5b69363 | 2019-07-09 09:06:09 -0700 | [diff] [blame] | 1635 | uint8_t flags = 0; |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1636 | if (performance) |
| 1637 | { |
James Feist | 5b69363 | 2019-07-09 09:06:09 -0700 | [diff] [blame] | 1638 | flags |= 1 << 2; |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1639 | } |
| 1640 | |
jayaprakash Mutyala | 4b1552d | 2020-02-11 12:07:29 +0000 | [diff] [blame] | 1641 | constexpr uint8_t fanControlDefaultProfile = 0x80; |
| 1642 | constexpr uint8_t fanControlProfileState = 0x00; |
| 1643 | constexpr uint32_t dimmPresenceBitmap = 0x00; |
| 1644 | |
| 1645 | return ipmi::responseSuccess(fanControlDefaultProfile, |
| 1646 | fanControlProfileState, flags, |
| 1647 | dimmPresenceBitmap); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1648 | } |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1649 | constexpr const char* cfmLimitSettingPath = |
| 1650 | "/xyz/openbmc_project/control/cfm_limit"; |
| 1651 | constexpr const char* cfmLimitIface = "xyz.openbmc_project.Control.CFMLimit"; |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1652 | constexpr const size_t legacyExitAirSensorNumber = 0x2e; |
James Feist | 09f6b60 | 2019-08-08 11:30:03 -0700 | [diff] [blame] | 1653 | constexpr const size_t legacyPCHSensorNumber = 0x22; |
| 1654 | constexpr const char* exitAirPathName = "Exit_Air"; |
| 1655 | constexpr const char* pchPathName = "SSB_Temp"; |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1656 | constexpr const char* pidConfigurationIface = |
| 1657 | "xyz.openbmc_project.Configuration.Pid"; |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1658 | |
James Feist | 09f6b60 | 2019-08-08 11:30:03 -0700 | [diff] [blame] | 1659 | static std::string getConfigPath(const std::string& name) |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1660 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1661 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1662 | auto method = |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1663 | dbus->new_method_call("xyz.openbmc_project.ObjectMapper", |
| 1664 | "/xyz/openbmc_project/object_mapper", |
| 1665 | "xyz.openbmc_project.ObjectMapper", "GetSubTree"); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1666 | |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1667 | method.append("/", 0, std::array<const char*, 1>{pidConfigurationIface}); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1668 | std::string path; |
| 1669 | GetSubTreeType resp; |
| 1670 | try |
| 1671 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1672 | auto reply = dbus->call(method); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1673 | reply.read(resp); |
| 1674 | } |
| 1675 | catch (sdbusplus::exception_t&) |
| 1676 | { |
| 1677 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1678 | "ipmiOEMGetFscParameter: mapper error"); |
| 1679 | }; |
James Feist | 09f6b60 | 2019-08-08 11:30:03 -0700 | [diff] [blame] | 1680 | auto config = |
| 1681 | std::find_if(resp.begin(), resp.end(), [&name](const auto& pair) { |
| 1682 | return pair.first.find(name) != std::string::npos; |
| 1683 | }); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1684 | if (config != resp.end()) |
| 1685 | { |
| 1686 | path = std::move(config->first); |
| 1687 | } |
| 1688 | return path; |
| 1689 | } |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1690 | |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1691 | // flat map to make alphabetical |
| 1692 | static boost::container::flat_map<std::string, PropertyMap> getPidConfigs() |
| 1693 | { |
| 1694 | boost::container::flat_map<std::string, PropertyMap> ret; |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1695 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1696 | auto method = |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1697 | dbus->new_method_call("xyz.openbmc_project.ObjectMapper", |
| 1698 | "/xyz/openbmc_project/object_mapper", |
| 1699 | "xyz.openbmc_project.ObjectMapper", "GetSubTree"); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1700 | |
| 1701 | method.append("/", 0, std::array<const char*, 1>{pidConfigurationIface}); |
| 1702 | GetSubTreeType resp; |
| 1703 | |
| 1704 | try |
| 1705 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1706 | auto reply = dbus->call(method); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1707 | reply.read(resp); |
| 1708 | } |
| 1709 | catch (sdbusplus::exception_t&) |
| 1710 | { |
| 1711 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1712 | "getFanConfigPaths: mapper error"); |
| 1713 | }; |
| 1714 | for (const auto& [path, objects] : resp) |
| 1715 | { |
| 1716 | if (objects.empty()) |
| 1717 | { |
| 1718 | continue; // should be impossible |
| 1719 | } |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 1720 | |
| 1721 | try |
| 1722 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1723 | ret.emplace(path, |
| 1724 | getAllDbusProperties(*dbus, objects[0].first, path, |
| 1725 | pidConfigurationIface)); |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 1726 | } |
| 1727 | catch (sdbusplus::exception_t& e) |
| 1728 | { |
| 1729 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1730 | "getPidConfigs: can't get DbusProperties!", |
| 1731 | phosphor::logging::entry("ERR=%s", e.what())); |
| 1732 | } |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1733 | } |
| 1734 | return ret; |
| 1735 | } |
| 1736 | |
| 1737 | ipmi::RspType<uint8_t> ipmiOEMGetFanSpeedOffset(void) |
| 1738 | { |
| 1739 | boost::container::flat_map<std::string, PropertyMap> data = getPidConfigs(); |
| 1740 | if (data.empty()) |
| 1741 | { |
| 1742 | return ipmi::responseResponseError(); |
| 1743 | } |
| 1744 | uint8_t minOffset = std::numeric_limits<uint8_t>::max(); |
| 1745 | for (const auto& [_, pid] : data) |
| 1746 | { |
| 1747 | auto findClass = pid.find("Class"); |
| 1748 | if (findClass == pid.end()) |
| 1749 | { |
| 1750 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1751 | "ipmiOEMGetFscParameter: found illegal pid " |
| 1752 | "configurations"); |
| 1753 | return ipmi::responseResponseError(); |
| 1754 | } |
| 1755 | std::string type = std::get<std::string>(findClass->second); |
| 1756 | if (type == "fan") |
| 1757 | { |
| 1758 | auto findOutLimit = pid.find("OutLimitMin"); |
| 1759 | if (findOutLimit == pid.end()) |
| 1760 | { |
| 1761 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1762 | "ipmiOEMGetFscParameter: found illegal pid " |
| 1763 | "configurations"); |
| 1764 | return ipmi::responseResponseError(); |
| 1765 | } |
| 1766 | // get the min out of all the offsets |
| 1767 | minOffset = std::min( |
| 1768 | minOffset, |
| 1769 | static_cast<uint8_t>(std::get<double>(findOutLimit->second))); |
| 1770 | } |
| 1771 | } |
| 1772 | if (minOffset == std::numeric_limits<uint8_t>::max()) |
| 1773 | { |
| 1774 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1775 | "ipmiOEMGetFscParameter: found no fan configurations!"); |
| 1776 | return ipmi::responseResponseError(); |
| 1777 | } |
| 1778 | |
| 1779 | return ipmi::responseSuccess(minOffset); |
| 1780 | } |
| 1781 | |
| 1782 | ipmi::RspType<> ipmiOEMSetFanSpeedOffset(uint8_t offset) |
| 1783 | { |
Manish Baing | baa579f | 2021-10-08 22:30:32 +0000 | [diff] [blame^] | 1784 | constexpr uint8_t maxFanSpeedOffset = 100; |
| 1785 | if (offset > maxFanSpeedOffset) |
| 1786 | { |
| 1787 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1788 | "ipmiOEMSetFanSpeedOffset: fan offset greater than limit"); |
| 1789 | return ipmi::responseInvalidFieldRequest(); |
| 1790 | } |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1791 | boost::container::flat_map<std::string, PropertyMap> data = getPidConfigs(); |
| 1792 | if (data.empty()) |
| 1793 | { |
| 1794 | |
| 1795 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1796 | "ipmiOEMSetFanSpeedOffset: found no pid configurations!"); |
| 1797 | return ipmi::responseResponseError(); |
| 1798 | } |
| 1799 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1800 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1801 | bool found = false; |
| 1802 | for (const auto& [path, pid] : data) |
| 1803 | { |
| 1804 | auto findClass = pid.find("Class"); |
| 1805 | if (findClass == pid.end()) |
| 1806 | { |
| 1807 | |
| 1808 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1809 | "ipmiOEMSetFanSpeedOffset: found illegal pid " |
| 1810 | "configurations"); |
| 1811 | return ipmi::responseResponseError(); |
| 1812 | } |
| 1813 | std::string type = std::get<std::string>(findClass->second); |
| 1814 | if (type == "fan") |
| 1815 | { |
| 1816 | auto findOutLimit = pid.find("OutLimitMin"); |
| 1817 | if (findOutLimit == pid.end()) |
| 1818 | { |
| 1819 | |
| 1820 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1821 | "ipmiOEMSetFanSpeedOffset: found illegal pid " |
| 1822 | "configurations"); |
| 1823 | return ipmi::responseResponseError(); |
| 1824 | } |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1825 | ipmi::setDbusProperty(*dbus, "xyz.openbmc_project.EntityManager", |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1826 | path, pidConfigurationIface, "OutLimitMin", |
| 1827 | static_cast<double>(offset)); |
| 1828 | found = true; |
| 1829 | } |
| 1830 | } |
| 1831 | if (!found) |
| 1832 | { |
| 1833 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1834 | "ipmiOEMSetFanSpeedOffset: set no fan offsets"); |
| 1835 | return ipmi::responseResponseError(); |
| 1836 | } |
| 1837 | |
| 1838 | return ipmi::responseSuccess(); |
| 1839 | } |
| 1840 | |
| 1841 | ipmi::RspType<> ipmiOEMSetFscParameter(uint8_t command, uint8_t param1, |
| 1842 | uint8_t param2) |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1843 | { |
| 1844 | constexpr const size_t disableLimiting = 0x0; |
| 1845 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1846 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1847 | if (command == static_cast<uint8_t>(setFscParamFlags::tcontrol)) |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1848 | { |
James Feist | 09f6b60 | 2019-08-08 11:30:03 -0700 | [diff] [blame] | 1849 | std::string pathName; |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1850 | if (param1 == legacyExitAirSensorNumber) |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1851 | { |
James Feist | 09f6b60 | 2019-08-08 11:30:03 -0700 | [diff] [blame] | 1852 | pathName = exitAirPathName; |
| 1853 | } |
| 1854 | else if (param1 == legacyPCHSensorNumber) |
| 1855 | { |
| 1856 | pathName = pchPathName; |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1857 | } |
| 1858 | else |
| 1859 | { |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1860 | return ipmi::responseParmOutOfRange(); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1861 | } |
James Feist | 09f6b60 | 2019-08-08 11:30:03 -0700 | [diff] [blame] | 1862 | std::string path = getConfigPath(pathName); |
| 1863 | ipmi::setDbusProperty(*dbus, "xyz.openbmc_project.EntityManager", path, |
| 1864 | pidConfigurationIface, "SetPoint", |
| 1865 | static_cast<double>(param2)); |
| 1866 | return ipmi::responseSuccess(); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1867 | } |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1868 | else if (command == static_cast<uint8_t>(setFscParamFlags::cfm)) |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1869 | { |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1870 | uint16_t cfm = param1 | (static_cast<uint16_t>(param2) << 8); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1871 | |
| 1872 | // must be greater than 50 based on eps |
| 1873 | if (cfm < 50 && cfm != disableLimiting) |
| 1874 | { |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1875 | return ipmi::responseParmOutOfRange(); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1876 | } |
| 1877 | |
| 1878 | try |
| 1879 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1880 | ipmi::setDbusProperty(*dbus, settingsBusName, cfmLimitSettingPath, |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1881 | cfmLimitIface, "Limit", |
| 1882 | static_cast<double>(cfm)); |
| 1883 | } |
| 1884 | catch (sdbusplus::exception_t& e) |
| 1885 | { |
| 1886 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1887 | "ipmiOEMSetFscParameter: can't set cfm setting!", |
| 1888 | phosphor::logging::entry("ERR=%s", e.what())); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1889 | return ipmi::responseResponseError(); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1890 | } |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1891 | return ipmi::responseSuccess(); |
| 1892 | } |
| 1893 | else if (command == static_cast<uint8_t>(setFscParamFlags::maxPwm)) |
| 1894 | { |
| 1895 | constexpr const size_t maxDomainCount = 8; |
| 1896 | uint8_t requestedDomainMask = param1; |
| 1897 | boost::container::flat_map data = getPidConfigs(); |
| 1898 | if (data.empty()) |
| 1899 | { |
| 1900 | |
| 1901 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1902 | "ipmiOEMSetFscParameter: found no pid configurations!"); |
| 1903 | return ipmi::responseResponseError(); |
| 1904 | } |
| 1905 | size_t count = 0; |
| 1906 | for (const auto& [path, pid] : data) |
| 1907 | { |
| 1908 | auto findClass = pid.find("Class"); |
| 1909 | if (findClass == pid.end()) |
| 1910 | { |
| 1911 | |
| 1912 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1913 | "ipmiOEMSetFscParameter: found illegal pid " |
| 1914 | "configurations"); |
| 1915 | return ipmi::responseResponseError(); |
| 1916 | } |
| 1917 | std::string type = std::get<std::string>(findClass->second); |
| 1918 | if (type == "fan") |
| 1919 | { |
| 1920 | if (requestedDomainMask & (1 << count)) |
| 1921 | { |
| 1922 | ipmi::setDbusProperty( |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1923 | *dbus, "xyz.openbmc_project.EntityManager", path, |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1924 | pidConfigurationIface, "OutLimitMax", |
| 1925 | static_cast<double>(param2)); |
| 1926 | } |
| 1927 | count++; |
| 1928 | } |
| 1929 | } |
| 1930 | return ipmi::responseSuccess(); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1931 | } |
| 1932 | else |
| 1933 | { |
| 1934 | // todo other command parts possibly |
| 1935 | // tcontrol is handled in peci now |
| 1936 | // fan speed offset not implemented yet |
| 1937 | // domain pwm limit not implemented |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1938 | return ipmi::responseParmOutOfRange(); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1939 | } |
| 1940 | } |
| 1941 | |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1942 | ipmi::RspType< |
| 1943 | std::variant<uint8_t, std::array<uint8_t, 2>, std::array<uint16_t, 2>>> |
| 1944 | ipmiOEMGetFscParameter(uint8_t command, std::optional<uint8_t> param) |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1945 | { |
James Feist | 09f6b60 | 2019-08-08 11:30:03 -0700 | [diff] [blame] | 1946 | constexpr uint8_t legacyDefaultSetpoint = -128; |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1947 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1948 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1949 | if (command == static_cast<uint8_t>(setFscParamFlags::tcontrol)) |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1950 | { |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1951 | if (!param) |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1952 | { |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1953 | return ipmi::responseReqDataLenInvalid(); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1954 | } |
| 1955 | |
James Feist | 09f6b60 | 2019-08-08 11:30:03 -0700 | [diff] [blame] | 1956 | std::string pathName; |
| 1957 | |
| 1958 | if (*param == legacyExitAirSensorNumber) |
| 1959 | { |
| 1960 | pathName = exitAirPathName; |
| 1961 | } |
| 1962 | else if (*param == legacyPCHSensorNumber) |
| 1963 | { |
| 1964 | pathName = pchPathName; |
| 1965 | } |
| 1966 | else |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1967 | { |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1968 | return ipmi::responseParmOutOfRange(); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1969 | } |
James Feist | 09f6b60 | 2019-08-08 11:30:03 -0700 | [diff] [blame] | 1970 | |
| 1971 | uint8_t setpoint = legacyDefaultSetpoint; |
| 1972 | std::string path = getConfigPath(pathName); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1973 | if (path.size()) |
| 1974 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1975 | Value val = ipmi::getDbusProperty( |
| 1976 | *dbus, "xyz.openbmc_project.EntityManager", path, |
| 1977 | pidConfigurationIface, "SetPoint"); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1978 | setpoint = std::floor(std::get<double>(val) + 0.5); |
| 1979 | } |
| 1980 | |
| 1981 | // old implementation used to return the "default" and current, we |
| 1982 | // don't make the default readily available so just make both the |
| 1983 | // same |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1984 | |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1985 | return ipmi::responseSuccess( |
| 1986 | std::array<uint8_t, 2>{setpoint, setpoint}); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1987 | } |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1988 | else if (command == static_cast<uint8_t>(setFscParamFlags::maxPwm)) |
| 1989 | { |
| 1990 | constexpr const size_t maxDomainCount = 8; |
| 1991 | |
| 1992 | if (!param) |
| 1993 | { |
| 1994 | return ipmi::responseReqDataLenInvalid(); |
| 1995 | } |
| 1996 | uint8_t requestedDomain = *param; |
| 1997 | if (requestedDomain >= maxDomainCount) |
| 1998 | { |
| 1999 | return ipmi::responseInvalidFieldRequest(); |
| 2000 | } |
| 2001 | |
| 2002 | boost::container::flat_map data = getPidConfigs(); |
| 2003 | if (data.empty()) |
| 2004 | { |
| 2005 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2006 | "ipmiOEMGetFscParameter: found no pid configurations!"); |
| 2007 | return ipmi::responseResponseError(); |
| 2008 | } |
| 2009 | size_t count = 0; |
| 2010 | for (const auto& [_, pid] : data) |
| 2011 | { |
| 2012 | auto findClass = pid.find("Class"); |
| 2013 | if (findClass == pid.end()) |
| 2014 | { |
| 2015 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2016 | "ipmiOEMGetFscParameter: found illegal pid " |
| 2017 | "configurations"); |
| 2018 | return ipmi::responseResponseError(); |
| 2019 | } |
| 2020 | std::string type = std::get<std::string>(findClass->second); |
| 2021 | if (type == "fan") |
| 2022 | { |
| 2023 | if (requestedDomain == count) |
| 2024 | { |
| 2025 | auto findOutLimit = pid.find("OutLimitMax"); |
| 2026 | if (findOutLimit == pid.end()) |
| 2027 | { |
| 2028 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2029 | "ipmiOEMGetFscParameter: found illegal pid " |
| 2030 | "configurations"); |
| 2031 | return ipmi::responseResponseError(); |
| 2032 | } |
| 2033 | |
| 2034 | return ipmi::responseSuccess( |
| 2035 | static_cast<uint8_t>(std::floor( |
| 2036 | std::get<double>(findOutLimit->second) + 0.5))); |
| 2037 | } |
| 2038 | else |
| 2039 | { |
| 2040 | count++; |
| 2041 | } |
| 2042 | } |
| 2043 | } |
| 2044 | |
| 2045 | return ipmi::responseInvalidFieldRequest(); |
| 2046 | } |
| 2047 | else if (command == static_cast<uint8_t>(setFscParamFlags::cfm)) |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2048 | { |
| 2049 | |
| 2050 | /* |
| 2051 | DataLen should be 1, but host is sending us an extra bit. As the |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 2052 | previous behavior didn't seem to prevent this, ignore the check for |
| 2053 | now. |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2054 | |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 2055 | if (param) |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2056 | { |
| 2057 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2058 | "ipmiOEMGetFscParameter: invalid input len!"); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2059 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 2060 | } |
| 2061 | */ |
| 2062 | Value cfmLimit; |
| 2063 | Value cfmMaximum; |
| 2064 | try |
| 2065 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 2066 | cfmLimit = ipmi::getDbusProperty(*dbus, settingsBusName, |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2067 | cfmLimitSettingPath, cfmLimitIface, |
| 2068 | "Limit"); |
| 2069 | cfmMaximum = ipmi::getDbusProperty( |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 2070 | *dbus, "xyz.openbmc_project.ExitAirTempSensor", |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2071 | "/xyz/openbmc_project/control/MaxCFM", cfmLimitIface, "Limit"); |
| 2072 | } |
| 2073 | catch (sdbusplus::exception_t& e) |
| 2074 | { |
| 2075 | phosphor::logging::log<phosphor::logging::level::ERR>( |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 2076 | "ipmiOEMGetFscParameter: can't get cfm setting!", |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2077 | phosphor::logging::entry("ERR=%s", e.what())); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 2078 | return ipmi::responseResponseError(); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2079 | } |
| 2080 | |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 2081 | double cfmMax = std::get<double>(cfmMaximum); |
| 2082 | double cfmLim = std::get<double>(cfmLimit); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2083 | |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 2084 | cfmLim = std::floor(cfmLim + 0.5); |
| 2085 | cfmMax = std::floor(cfmMax + 0.5); |
| 2086 | uint16_t cfmLimResp = static_cast<uint16_t>(cfmLim); |
| 2087 | uint16_t cfmMaxResp = static_cast<uint16_t>(cfmMax); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2088 | |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 2089 | return ipmi::responseSuccess( |
| 2090 | std::array<uint16_t, 2>{cfmLimResp, cfmMaxResp}); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2091 | } |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 2092 | |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2093 | else |
| 2094 | { |
| 2095 | // todo other command parts possibly |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2096 | // domain pwm limit not implemented |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 2097 | return ipmi::responseParmOutOfRange(); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2098 | } |
| 2099 | } |
| 2100 | |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2101 | using crConfigVariant = |
| 2102 | std::variant<bool, uint8_t, uint32_t, std::vector<uint8_t>, std::string>; |
| 2103 | |
| 2104 | int setCRConfig(ipmi::Context::ptr ctx, const std::string& property, |
| 2105 | const crConfigVariant& value, |
| 2106 | std::chrono::microseconds timeout = ipmi::IPMI_DBUS_TIMEOUT) |
| 2107 | { |
| 2108 | boost::system::error_code ec; |
| 2109 | ctx->bus->yield_method_call<void>( |
Kuiying Wang | e45333a | 2020-07-22 22:06:37 +0800 | [diff] [blame] | 2110 | ctx->yield, ec, "xyz.openbmc_project.PSURedundancy", |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2111 | "/xyz/openbmc_project/control/power_supply_redundancy", |
| 2112 | "org.freedesktop.DBus.Properties", "Set", |
| 2113 | "xyz.openbmc_project.Control.PowerSupplyRedundancy", property, value); |
| 2114 | if (ec) |
| 2115 | { |
| 2116 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2117 | "Failed to set dbus property to cold redundancy"); |
| 2118 | return -1; |
| 2119 | } |
| 2120 | |
| 2121 | return 0; |
| 2122 | } |
| 2123 | |
Kuiying Wang | e45333a | 2020-07-22 22:06:37 +0800 | [diff] [blame] | 2124 | int getCRConfig( |
| 2125 | ipmi::Context::ptr ctx, const std::string& property, crConfigVariant& value, |
| 2126 | const std::string& service = "xyz.openbmc_project.PSURedundancy", |
| 2127 | std::chrono::microseconds timeout = ipmi::IPMI_DBUS_TIMEOUT) |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2128 | { |
| 2129 | boost::system::error_code ec; |
| 2130 | value = ctx->bus->yield_method_call<crConfigVariant>( |
Yong Li | 19445ab | 2019-12-20 18:25:29 +0800 | [diff] [blame] | 2131 | ctx->yield, ec, service, |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2132 | "/xyz/openbmc_project/control/power_supply_redundancy", |
| 2133 | "org.freedesktop.DBus.Properties", "Get", |
| 2134 | "xyz.openbmc_project.Control.PowerSupplyRedundancy", property); |
| 2135 | if (ec) |
| 2136 | { |
| 2137 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2138 | "Failed to get dbus property to cold redundancy"); |
| 2139 | return -1; |
| 2140 | } |
| 2141 | return 0; |
| 2142 | } |
| 2143 | |
| 2144 | uint8_t getPSUCount(void) |
| 2145 | { |
| 2146 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 2147 | ipmi::Value num; |
| 2148 | try |
| 2149 | { |
| 2150 | num = ipmi::getDbusProperty( |
| 2151 | *dbus, "xyz.openbmc_project.PSURedundancy", |
| 2152 | "/xyz/openbmc_project/control/power_supply_redundancy", |
| 2153 | "xyz.openbmc_project.Control.PowerSupplyRedundancy", "PSUNumber"); |
| 2154 | } |
| 2155 | catch (sdbusplus::exception_t& e) |
| 2156 | { |
| 2157 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2158 | "Failed to get PSUNumber property from dbus interface"); |
| 2159 | return 0; |
| 2160 | } |
| 2161 | uint8_t* pNum = std::get_if<uint8_t>(&num); |
| 2162 | if (!pNum) |
| 2163 | { |
| 2164 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2165 | "Error to get PSU Number"); |
| 2166 | return 0; |
| 2167 | } |
| 2168 | return *pNum; |
| 2169 | } |
| 2170 | |
| 2171 | bool validateCRAlgo(std::vector<uint8_t>& conf, uint8_t num) |
| 2172 | { |
| 2173 | if (conf.size() < num) |
| 2174 | { |
| 2175 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2176 | "Invalid PSU Ranking"); |
| 2177 | return false; |
| 2178 | } |
| 2179 | std::set<uint8_t> confSet; |
| 2180 | for (uint8_t i = 0; i < num; i++) |
| 2181 | { |
| 2182 | if (conf[i] > num) |
| 2183 | { |
| 2184 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2185 | "PSU Ranking is larger than current PSU number"); |
| 2186 | return false; |
| 2187 | } |
| 2188 | confSet.emplace(conf[i]); |
| 2189 | } |
| 2190 | |
| 2191 | if (confSet.size() != num) |
| 2192 | { |
| 2193 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2194 | "duplicate PSU Ranking"); |
| 2195 | return false; |
| 2196 | } |
| 2197 | return true; |
| 2198 | } |
| 2199 | |
| 2200 | enum class crParameter |
| 2201 | { |
| 2202 | crStatus = 0, |
| 2203 | crFeature = 1, |
| 2204 | rotationFeature = 2, |
| 2205 | rotationAlgo = 3, |
| 2206 | rotationPeriod = 4, |
Yong Li | 19445ab | 2019-12-20 18:25:29 +0800 | [diff] [blame] | 2207 | numOfPSU = 5, |
| 2208 | rotationRankOrderEffective = 6 |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2209 | }; |
| 2210 | |
| 2211 | constexpr ipmi::Cc ccParameterNotSupported = 0x80; |
| 2212 | static const constexpr uint32_t oneDay = 0x15180; |
| 2213 | static const constexpr uint32_t oneMonth = 0xf53700; |
| 2214 | static const constexpr uint8_t userSpecific = 0x01; |
| 2215 | static const constexpr uint8_t crSetCompleted = 0; |
| 2216 | ipmi::RspType<uint8_t> ipmiOEMSetCRConfig(ipmi::Context::ptr ctx, |
| 2217 | uint8_t parameter, |
| 2218 | ipmi::message::Payload& payload) |
| 2219 | { |
| 2220 | switch (static_cast<crParameter>(parameter)) |
| 2221 | { |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2222 | case crParameter::rotationFeature: |
| 2223 | { |
| 2224 | uint8_t param1; |
| 2225 | if (payload.unpack(param1) || !payload.fullyUnpacked()) |
| 2226 | { |
| 2227 | return ipmi::responseReqDataLenInvalid(); |
| 2228 | } |
| 2229 | // Rotation Enable can only be true or false |
| 2230 | if (param1 > 1) |
| 2231 | { |
| 2232 | return ipmi::responseInvalidFieldRequest(); |
| 2233 | } |
| 2234 | if (setCRConfig(ctx, "RotationEnabled", static_cast<bool>(param1))) |
| 2235 | { |
| 2236 | return ipmi::responseResponseError(); |
| 2237 | } |
| 2238 | break; |
| 2239 | } |
| 2240 | case crParameter::rotationAlgo: |
| 2241 | { |
| 2242 | // Rotation Algorithm can only be 0-BMC Specific or 1-User Specific |
| 2243 | std::string algoName; |
| 2244 | uint8_t param1; |
| 2245 | if (payload.unpack(param1)) |
| 2246 | { |
| 2247 | return ipmi::responseReqDataLenInvalid(); |
| 2248 | } |
| 2249 | switch (param1) |
| 2250 | { |
| 2251 | case 0: |
| 2252 | algoName = "xyz.openbmc_project.Control." |
| 2253 | "PowerSupplyRedundancy.Algo.bmcSpecific"; |
| 2254 | break; |
| 2255 | case 1: |
| 2256 | algoName = "xyz.openbmc_project.Control." |
| 2257 | "PowerSupplyRedundancy.Algo.userSpecific"; |
| 2258 | break; |
| 2259 | default: |
| 2260 | return ipmi::responseInvalidFieldRequest(); |
| 2261 | } |
| 2262 | if (setCRConfig(ctx, "RotationAlgorithm", algoName)) |
| 2263 | { |
| 2264 | return ipmi::responseResponseError(); |
| 2265 | } |
| 2266 | |
| 2267 | uint8_t numberOfPSU = getPSUCount(); |
| 2268 | if (!numberOfPSU) |
| 2269 | { |
| 2270 | return ipmi::responseResponseError(); |
| 2271 | } |
| 2272 | std::vector<uint8_t> rankOrder; |
| 2273 | |
| 2274 | if (param1 == userSpecific) |
| 2275 | { |
| 2276 | if (payload.unpack(rankOrder) || !payload.fullyUnpacked()) |
| 2277 | { |
| 2278 | ipmi::responseReqDataLenInvalid(); |
| 2279 | } |
Yong Li | 8331513 | 2019-10-23 17:42:24 +0800 | [diff] [blame] | 2280 | if (rankOrder.size() != numberOfPSU) |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2281 | { |
| 2282 | return ipmi::responseReqDataLenInvalid(); |
| 2283 | } |
| 2284 | |
| 2285 | if (!validateCRAlgo(rankOrder, numberOfPSU)) |
| 2286 | { |
| 2287 | return ipmi::responseInvalidFieldRequest(); |
| 2288 | } |
| 2289 | } |
| 2290 | else |
| 2291 | { |
| 2292 | if (rankOrder.size() > 0) |
| 2293 | { |
| 2294 | return ipmi::responseReqDataLenInvalid(); |
| 2295 | } |
| 2296 | for (uint8_t i = 1; i <= numberOfPSU; i++) |
| 2297 | { |
| 2298 | rankOrder.emplace_back(i); |
| 2299 | } |
| 2300 | } |
| 2301 | if (setCRConfig(ctx, "RotationRankOrder", rankOrder)) |
| 2302 | { |
| 2303 | return ipmi::responseResponseError(); |
| 2304 | } |
| 2305 | break; |
| 2306 | } |
| 2307 | case crParameter::rotationPeriod: |
| 2308 | { |
| 2309 | // Minimum Rotation period is One day (86400 seconds) and Max |
| 2310 | // Rotation Period is 6 month (0xf53700 seconds) |
| 2311 | uint32_t period; |
| 2312 | if (payload.unpack(period) || !payload.fullyUnpacked()) |
| 2313 | { |
| 2314 | return ipmi::responseReqDataLenInvalid(); |
| 2315 | } |
| 2316 | if ((period < oneDay) || (period > oneMonth)) |
| 2317 | { |
| 2318 | return ipmi::responseInvalidFieldRequest(); |
| 2319 | } |
| 2320 | if (setCRConfig(ctx, "PeriodOfRotation", period)) |
| 2321 | { |
| 2322 | return ipmi::responseResponseError(); |
| 2323 | } |
| 2324 | break; |
| 2325 | } |
| 2326 | default: |
| 2327 | { |
| 2328 | return ipmi::response(ccParameterNotSupported); |
| 2329 | } |
| 2330 | } |
| 2331 | |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2332 | return ipmi::responseSuccess(crSetCompleted); |
| 2333 | } |
| 2334 | |
Yong Li | 8331513 | 2019-10-23 17:42:24 +0800 | [diff] [blame] | 2335 | ipmi::RspType<uint8_t, std::variant<uint8_t, uint32_t, std::vector<uint8_t>>> |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2336 | ipmiOEMGetCRConfig(ipmi::Context::ptr ctx, uint8_t parameter) |
| 2337 | { |
| 2338 | crConfigVariant value; |
| 2339 | switch (static_cast<crParameter>(parameter)) |
| 2340 | { |
| 2341 | case crParameter::crStatus: |
| 2342 | { |
| 2343 | if (getCRConfig(ctx, "ColdRedundancyStatus", value)) |
| 2344 | { |
| 2345 | return ipmi::responseResponseError(); |
| 2346 | } |
| 2347 | std::string* pStatus = std::get_if<std::string>(&value); |
| 2348 | if (!pStatus) |
| 2349 | { |
| 2350 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2351 | "Error to get ColdRedundancyStatus property"); |
| 2352 | return ipmi::responseResponseError(); |
| 2353 | } |
| 2354 | namespace server = sdbusplus::xyz::openbmc_project::Control::server; |
| 2355 | auto status = |
| 2356 | server::PowerSupplyRedundancy::convertStatusFromString( |
| 2357 | *pStatus); |
| 2358 | switch (status) |
| 2359 | { |
| 2360 | case server::PowerSupplyRedundancy::Status::inProgress: |
Cheng C Yang | f41e334 | 2019-09-10 04:47:23 +0800 | [diff] [blame] | 2361 | return ipmi::responseSuccess(parameter, |
Kuiying Wang | e45333a | 2020-07-22 22:06:37 +0800 | [diff] [blame] | 2362 | static_cast<uint8_t>(1)); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2363 | |
| 2364 | case server::PowerSupplyRedundancy::Status::completed: |
Cheng C Yang | f41e334 | 2019-09-10 04:47:23 +0800 | [diff] [blame] | 2365 | return ipmi::responseSuccess(parameter, |
Kuiying Wang | e45333a | 2020-07-22 22:06:37 +0800 | [diff] [blame] | 2366 | static_cast<uint8_t>(0)); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2367 | default: |
| 2368 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2369 | "Error to get valid status"); |
| 2370 | return ipmi::responseResponseError(); |
| 2371 | } |
| 2372 | } |
| 2373 | case crParameter::crFeature: |
| 2374 | { |
Kuiying Wang | e45333a | 2020-07-22 22:06:37 +0800 | [diff] [blame] | 2375 | if (getCRConfig(ctx, "PowerSupplyRedundancyEnabled", value)) |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2376 | { |
| 2377 | return ipmi::responseResponseError(); |
| 2378 | } |
| 2379 | bool* pResponse = std::get_if<bool>(&value); |
| 2380 | if (!pResponse) |
| 2381 | { |
| 2382 | phosphor::logging::log<phosphor::logging::level::ERR>( |
Kuiying Wang | e45333a | 2020-07-22 22:06:37 +0800 | [diff] [blame] | 2383 | "Error to get PowerSupplyRedundancyEnabled property"); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2384 | return ipmi::responseResponseError(); |
| 2385 | } |
| 2386 | |
Cheng C Yang | f41e334 | 2019-09-10 04:47:23 +0800 | [diff] [blame] | 2387 | return ipmi::responseSuccess(parameter, |
| 2388 | static_cast<uint8_t>(*pResponse)); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2389 | } |
| 2390 | case crParameter::rotationFeature: |
| 2391 | { |
| 2392 | if (getCRConfig(ctx, "RotationEnabled", value)) |
| 2393 | { |
| 2394 | return ipmi::responseResponseError(); |
| 2395 | } |
| 2396 | bool* pResponse = std::get_if<bool>(&value); |
| 2397 | if (!pResponse) |
| 2398 | { |
| 2399 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2400 | "Error to get RotationEnabled property"); |
| 2401 | return ipmi::responseResponseError(); |
| 2402 | } |
Cheng C Yang | f41e334 | 2019-09-10 04:47:23 +0800 | [diff] [blame] | 2403 | return ipmi::responseSuccess(parameter, |
| 2404 | static_cast<uint8_t>(*pResponse)); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2405 | } |
| 2406 | case crParameter::rotationAlgo: |
| 2407 | { |
| 2408 | if (getCRConfig(ctx, "RotationAlgorithm", value)) |
| 2409 | { |
| 2410 | return ipmi::responseResponseError(); |
| 2411 | } |
| 2412 | |
| 2413 | std::string* pAlgo = std::get_if<std::string>(&value); |
| 2414 | if (!pAlgo) |
| 2415 | { |
| 2416 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2417 | "Error to get RotationAlgorithm property"); |
| 2418 | return ipmi::responseResponseError(); |
| 2419 | } |
Yong Li | 8331513 | 2019-10-23 17:42:24 +0800 | [diff] [blame] | 2420 | std::vector<uint8_t> response; |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2421 | namespace server = sdbusplus::xyz::openbmc_project::Control::server; |
| 2422 | auto algo = |
| 2423 | server::PowerSupplyRedundancy::convertAlgoFromString(*pAlgo); |
Yong Li | 8331513 | 2019-10-23 17:42:24 +0800 | [diff] [blame] | 2424 | |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2425 | switch (algo) |
| 2426 | { |
| 2427 | case server::PowerSupplyRedundancy::Algo::bmcSpecific: |
Yong Li | 8331513 | 2019-10-23 17:42:24 +0800 | [diff] [blame] | 2428 | response.push_back(0); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2429 | break; |
| 2430 | case server::PowerSupplyRedundancy::Algo::userSpecific: |
Yong Li | 8331513 | 2019-10-23 17:42:24 +0800 | [diff] [blame] | 2431 | response.push_back(1); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2432 | break; |
| 2433 | default: |
| 2434 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2435 | "Error to get valid algo"); |
| 2436 | return ipmi::responseResponseError(); |
| 2437 | } |
| 2438 | |
| 2439 | if (getCRConfig(ctx, "RotationRankOrder", value)) |
| 2440 | { |
| 2441 | return ipmi::responseResponseError(); |
| 2442 | } |
| 2443 | std::vector<uint8_t>* pResponse = |
| 2444 | std::get_if<std::vector<uint8_t>>(&value); |
| 2445 | if (!pResponse) |
| 2446 | { |
| 2447 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2448 | "Error to get RotationRankOrder property"); |
| 2449 | return ipmi::responseResponseError(); |
| 2450 | } |
Yong Li | 8331513 | 2019-10-23 17:42:24 +0800 | [diff] [blame] | 2451 | |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2452 | std::copy(pResponse->begin(), pResponse->end(), |
Yong Li | 8331513 | 2019-10-23 17:42:24 +0800 | [diff] [blame] | 2453 | std::back_inserter(response)); |
| 2454 | |
Cheng C Yang | f41e334 | 2019-09-10 04:47:23 +0800 | [diff] [blame] | 2455 | return ipmi::responseSuccess(parameter, response); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2456 | } |
| 2457 | case crParameter::rotationPeriod: |
| 2458 | { |
| 2459 | if (getCRConfig(ctx, "PeriodOfRotation", value)) |
| 2460 | { |
| 2461 | return ipmi::responseResponseError(); |
| 2462 | } |
| 2463 | uint32_t* pResponse = std::get_if<uint32_t>(&value); |
| 2464 | if (!pResponse) |
| 2465 | { |
| 2466 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2467 | "Error to get RotationAlgorithm property"); |
| 2468 | return ipmi::responseResponseError(); |
| 2469 | } |
Cheng C Yang | f41e334 | 2019-09-10 04:47:23 +0800 | [diff] [blame] | 2470 | return ipmi::responseSuccess(parameter, *pResponse); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2471 | } |
| 2472 | case crParameter::numOfPSU: |
| 2473 | { |
| 2474 | uint8_t numberOfPSU = getPSUCount(); |
| 2475 | if (!numberOfPSU) |
| 2476 | { |
| 2477 | return ipmi::responseResponseError(); |
| 2478 | } |
Cheng C Yang | f41e334 | 2019-09-10 04:47:23 +0800 | [diff] [blame] | 2479 | return ipmi::responseSuccess(parameter, numberOfPSU); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2480 | } |
Yong Li | 19445ab | 2019-12-20 18:25:29 +0800 | [diff] [blame] | 2481 | case crParameter::rotationRankOrderEffective: |
| 2482 | { |
| 2483 | if (getCRConfig(ctx, "RotationRankOrder", value, |
| 2484 | "xyz.openbmc_project.PSURedundancy")) |
| 2485 | { |
| 2486 | return ipmi::responseResponseError(); |
| 2487 | } |
| 2488 | std::vector<uint8_t>* pResponse = |
| 2489 | std::get_if<std::vector<uint8_t>>(&value); |
| 2490 | if (!pResponse) |
| 2491 | { |
| 2492 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2493 | "Error to get effective RotationRankOrder property"); |
| 2494 | return ipmi::responseResponseError(); |
| 2495 | } |
| 2496 | return ipmi::responseSuccess(parameter, *pResponse); |
| 2497 | } |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2498 | default: |
| 2499 | { |
| 2500 | return ipmi::response(ccParameterNotSupported); |
| 2501 | } |
| 2502 | } |
| 2503 | } |
| 2504 | |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2505 | ipmi::RspType<> ipmiOEMSetFaultIndication(uint8_t sourceId, uint8_t faultType, |
| 2506 | uint8_t faultState, |
| 2507 | uint8_t faultGroup, |
| 2508 | std::array<uint8_t, 8>& ledStateData) |
| 2509 | { |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2510 | constexpr auto maxFaultType = static_cast<size_t>(RemoteFaultType::max); |
| 2511 | static const std::array<std::string, maxFaultType> faultNames = { |
| 2512 | "faultFan", "faultTemp", "faultPower", |
| 2513 | "faultDriveSlot", "faultSoftware", "faultMemory"}; |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2514 | |
| 2515 | constexpr uint8_t maxFaultSource = 0x4; |
| 2516 | constexpr uint8_t skipLEDs = 0xFF; |
| 2517 | constexpr uint8_t pinSize = 64; |
| 2518 | constexpr uint8_t groupSize = 16; |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2519 | constexpr uint8_t groupNum = 5; // 4 for fault memory, 1 for faultFan |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2520 | |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2521 | // same pin names need to be defined in dts file |
| 2522 | static const std::array<std::array<std::string, groupSize>, groupNum> |
| 2523 | faultLedPinNames = {{ |
| 2524 | "LED_CPU1_CH1_DIMM1_FAULT", |
| 2525 | "LED_CPU1_CH1_DIMM2_FAULT", |
| 2526 | "LED_CPU1_CH2_DIMM1_FAULT", |
| 2527 | "LED_CPU1_CH2_DIMM2_FAULT", |
| 2528 | "LED_CPU1_CH3_DIMM1_FAULT", |
| 2529 | "LED_CPU1_CH3_DIMM2_FAULT", |
| 2530 | "LED_CPU1_CH4_DIMM1_FAULT", |
| 2531 | "LED_CPU1_CH4_DIMM2_FAULT", |
| 2532 | "LED_CPU1_CH5_DIMM1_FAULT", |
| 2533 | "LED_CPU1_CH5_DIMM2_FAULT", |
| 2534 | "LED_CPU1_CH6_DIMM1_FAULT", |
| 2535 | "LED_CPU1_CH6_DIMM2_FAULT", |
| 2536 | "", |
| 2537 | "", |
| 2538 | "", |
| 2539 | "", // end of group1 |
| 2540 | "LED_CPU2_CH1_DIMM1_FAULT", |
| 2541 | "LED_CPU2_CH1_DIMM2_FAULT", |
| 2542 | "LED_CPU2_CH2_DIMM1_FAULT", |
| 2543 | "LED_CPU2_CH2_DIMM2_FAULT", |
| 2544 | "LED_CPU2_CH3_DIMM1_FAULT", |
| 2545 | "LED_CPU2_CH3_DIMM2_FAULT", |
| 2546 | "LED_CPU2_CH4_DIMM1_FAULT", |
| 2547 | "LED_CPU2_CH4_DIMM2_FAULT", |
| 2548 | "LED_CPU2_CH5_DIMM1_FAULT", |
| 2549 | "LED_CPU2_CH5_DIMM2_FAULT", |
| 2550 | "LED_CPU2_CH6_DIMM1_FAULT", |
| 2551 | "LED_CPU2_CH6_DIMM2_FAULT", |
| 2552 | "", |
| 2553 | "", |
| 2554 | "", |
| 2555 | "", // endof group2 |
| 2556 | "LED_CPU3_CH1_DIMM1_FAULT", |
| 2557 | "LED_CPU3_CH1_DIMM2_FAULT", |
| 2558 | "LED_CPU3_CH2_DIMM1_FAULT", |
| 2559 | "LED_CPU3_CH2_DIMM2_FAULT", |
| 2560 | "LED_CPU3_CH3_DIMM1_FAULT", |
| 2561 | "LED_CPU3_CH3_DIMM2_FAULT", |
| 2562 | "LED_CPU3_CH4_DIMM1_FAULT", |
| 2563 | "LED_CPU3_CH4_DIMM2_FAULT", |
| 2564 | "LED_CPU3_CH5_DIMM1_FAULT", |
| 2565 | "LED_CPU3_CH5_DIMM2_FAULT", |
| 2566 | "LED_CPU3_CH6_DIMM1_FAULT", |
| 2567 | "LED_CPU3_CH6_DIMM2_FAULT", |
| 2568 | "", |
| 2569 | "", |
| 2570 | "", |
| 2571 | "", // end of group3 |
| 2572 | "LED_CPU4_CH1_DIMM1_FAULT", |
| 2573 | "LED_CPU4_CH1_DIMM2_FAULT", |
| 2574 | "LED_CPU4_CH2_DIMM1_FAULT", |
| 2575 | "LED_CPU4_CH2_DIMM2_FAULT", |
| 2576 | "LED_CPU4_CH3_DIMM1_FAULT", |
| 2577 | "LED_CPU4_CH3_DIMM2_FAULT", |
| 2578 | "LED_CPU4_CH4_DIMM1_FAULT", |
| 2579 | "LED_CPU4_CH4_DIMM2_FAULT", |
| 2580 | "LED_CPU4_CH5_DIMM1_FAULT", |
| 2581 | "LED_CPU4_CH5_DIMM2_FAULT", |
| 2582 | "LED_CPU4_CH6_DIMM1_FAULT", |
| 2583 | "LED_CPU4_CH6_DIMM2_FAULT", |
| 2584 | "", |
| 2585 | "", |
| 2586 | "", |
| 2587 | "", // end of group4 |
| 2588 | "LED_FAN1_FAULT", |
| 2589 | "LED_FAN2_FAULT", |
| 2590 | "LED_FAN3_FAULT", |
| 2591 | "LED_FAN4_FAULT", |
| 2592 | "LED_FAN5_FAULT", |
| 2593 | "LED_FAN6_FAULT", |
| 2594 | "LED_FAN7_FAULT", |
| 2595 | "LED_FAN8_FAULT", |
| 2596 | "", |
| 2597 | "", |
| 2598 | "", |
| 2599 | "", |
| 2600 | "", |
| 2601 | "", |
| 2602 | "", |
| 2603 | "" // end of group5 |
| 2604 | }}; |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2605 | |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2606 | // Validate the source, fault type -- |
| 2607 | // (Byte 1) sourceId: Unspecified, Hot-Swap Controller 0, Hot-Swap |
| 2608 | // Controller 1, BIOS (Byte 2) fault type: fan, temperature, power, |
| 2609 | // driveslot, software, memory (Byte 3) FaultState: OK, Degraded, |
| 2610 | // Non-Critical, Critical, Non-Recoverable, (Byte 4) is faultGroup, |
| 2611 | // definition differs based on fault type (Byte 2) |
| 2612 | // Type Fan=> Group: 0=FanGroupID, FF-not used |
| 2613 | // Byte 5-11 00h, not used |
| 2614 | // Byte12 FanLedState [7:0]-Fans 7:0 |
| 2615 | // Type Memory=> Group: 0 = DIMM GroupID, FF-not used |
| 2616 | // Byte 5:12 - DIMM LED state (64bit field, LS Byte first) |
| 2617 | // [63:48] = CPU4 channels 7:0, 2 bits per channel |
| 2618 | // [47:32] = CPU3 channels 7:0, 2 bits per channel |
| 2619 | // [31:16] = CPU2 channels 7:0, 2 bits per channel |
| 2620 | // [15:0] = CPU1 channels 7:0, 2 bits per channel |
| 2621 | // Type Other=> Component Fault LED Group ID, not used set to 0xFF |
| 2622 | // Byte[5:12]: reserved 0x00h |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2623 | if ((sourceId >= maxFaultSource) || |
| 2624 | (faultType >= static_cast<int8_t>(RemoteFaultType::max)) || |
| 2625 | (faultState >= static_cast<int8_t>(RemoteFaultState::maxFaultState)) || |
| 2626 | (faultGroup >= static_cast<int8_t>(DimmFaultType::maxFaultGroup))) |
| 2627 | { |
| 2628 | return ipmi::responseParmOutOfRange(); |
| 2629 | } |
| 2630 | |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2631 | size_t pinGroupOffset = 0; |
| 2632 | size_t pinGroupMax = pinSize / groupSize; |
| 2633 | if (RemoteFaultType::fan == RemoteFaultType(faultType)) |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2634 | { |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2635 | pinGroupOffset = 4; |
| 2636 | pinGroupMax = groupNum - pinSize / groupSize; |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2637 | } |
| 2638 | |
| 2639 | switch (RemoteFaultType(faultType)) |
| 2640 | { |
| 2641 | case (RemoteFaultType::fan): |
| 2642 | case (RemoteFaultType::memory): |
| 2643 | { |
| 2644 | if (faultGroup == skipLEDs) |
| 2645 | { |
| 2646 | return ipmi::responseSuccess(); |
| 2647 | } |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2648 | // calculate led state bit filed count, each byte has 8bits |
| 2649 | // the maximum bits will be 8 * 8 bits |
| 2650 | constexpr uint8_t size = sizeof(ledStateData) * 8; |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2651 | |
| 2652 | // assemble ledState |
| 2653 | uint64_t ledState = 0; |
| 2654 | bool hasError = false; |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2655 | for (int i = 0; i < sizeof(ledStateData); i++) |
| 2656 | { |
| 2657 | ledState = (uint64_t)(ledState << 8); |
| 2658 | ledState = (uint64_t)(ledState | (uint64_t)ledStateData[i]); |
| 2659 | } |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2660 | std::bitset<size> ledStateBits(ledState); |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2661 | |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2662 | for (int group = 0; group < pinGroupMax; group++) |
| 2663 | { |
| 2664 | for (int i = 0; i < groupSize; i++) |
| 2665 | { // skip non-existing pins |
| 2666 | if (0 == faultLedPinNames[group + pinGroupOffset][i].size()) |
| 2667 | { |
| 2668 | continue; |
| 2669 | } |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2670 | |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2671 | gpiod::line line = gpiod::find_line( |
| 2672 | faultLedPinNames[group + pinGroupOffset][i]); |
| 2673 | if (!line) |
| 2674 | { |
| 2675 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2676 | "Not Find Led Gpio Device!", |
| 2677 | phosphor::logging::entry( |
| 2678 | "DEVICE=%s", |
| 2679 | faultLedPinNames[group + pinGroupOffset][i] |
| 2680 | .c_str())); |
| 2681 | hasError = true; |
| 2682 | continue; |
| 2683 | } |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2684 | |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2685 | bool activeHigh = |
| 2686 | (line.active_state() == gpiod::line::ACTIVE_HIGH); |
| 2687 | try |
| 2688 | { |
| 2689 | line.request( |
| 2690 | {"faultLed", gpiod::line_request::DIRECTION_OUTPUT, |
| 2691 | activeHigh |
| 2692 | ? 0 |
| 2693 | : gpiod::line_request::FLAG_ACTIVE_LOW}); |
| 2694 | line.set_value(ledStateBits[i + group * groupSize]); |
| 2695 | } |
| 2696 | catch (std::system_error&) |
| 2697 | { |
| 2698 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2699 | "Error write Led Gpio Device!", |
| 2700 | phosphor::logging::entry( |
| 2701 | "DEVICE=%s", |
| 2702 | faultLedPinNames[group + pinGroupOffset][i] |
| 2703 | .c_str())); |
| 2704 | hasError = true; |
| 2705 | continue; |
| 2706 | } |
| 2707 | } // for int i |
| 2708 | } |
| 2709 | if (hasError) |
| 2710 | { |
| 2711 | return ipmi::responseResponseError(); |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2712 | } |
| 2713 | break; |
| 2714 | } |
| 2715 | default: |
| 2716 | { |
| 2717 | // now only support two fault types |
| 2718 | return ipmi::responseParmOutOfRange(); |
| 2719 | } |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2720 | } // switch |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2721 | return ipmi::responseSuccess(); |
| 2722 | } |
| 2723 | |
Richard Marian Thomaiyar | ea537d5 | 2019-04-24 21:33:48 +0530 | [diff] [blame] | 2724 | ipmi::RspType<uint8_t> ipmiOEMReadBoardProductId() |
| 2725 | { |
| 2726 | uint8_t prodId = 0; |
| 2727 | try |
| 2728 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 2729 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
Richard Marian Thomaiyar | ea537d5 | 2019-04-24 21:33:48 +0530 | [diff] [blame] | 2730 | const DbusObjectInfo& object = getDbusObject( |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 2731 | *dbus, "xyz.openbmc_project.Inventory.Item.Board", |
Richard Marian Thomaiyar | ea537d5 | 2019-04-24 21:33:48 +0530 | [diff] [blame] | 2732 | "/xyz/openbmc_project/inventory/system/board/", "Baseboard"); |
| 2733 | const Value& propValue = getDbusProperty( |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 2734 | *dbus, object.second, object.first, |
Suryakanth Sekar | 6c57e5c | 2020-01-10 17:11:58 +0530 | [diff] [blame] | 2735 | "xyz.openbmc_project.Inventory.Item.Board.Motherboard", |
| 2736 | "ProductId"); |
Richard Marian Thomaiyar | ea537d5 | 2019-04-24 21:33:48 +0530 | [diff] [blame] | 2737 | prodId = static_cast<uint8_t>(std::get<uint64_t>(propValue)); |
| 2738 | } |
| 2739 | catch (std::exception& e) |
| 2740 | { |
| 2741 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2742 | "ipmiOEMReadBoardProductId: Product ID read failed!", |
| 2743 | phosphor::logging::entry("ERR=%s", e.what())); |
| 2744 | } |
| 2745 | return ipmi::responseSuccess(prodId); |
| 2746 | } |
| 2747 | |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 2748 | /** @brief implements the get security mode command |
| 2749 | * @param ctx - ctx pointer |
| 2750 | * |
| 2751 | * @returns IPMI completion code with following data |
| 2752 | * - restriction mode value - As specified in |
| 2753 | * xyz.openbmc_project.Control.Security.RestrictionMode.interface.yaml |
| 2754 | * - special mode value - As specified in |
| 2755 | * xyz.openbmc_project.Control.Security.SpecialMode.interface.yaml |
| 2756 | */ |
| 2757 | ipmi::RspType<uint8_t, uint8_t> ipmiGetSecurityMode(ipmi::Context::ptr ctx) |
| 2758 | { |
| 2759 | namespace securityNameSpace = |
| 2760 | sdbusplus::xyz::openbmc_project::Control::Security::server; |
| 2761 | uint8_t restrictionModeValue = 0; |
| 2762 | uint8_t specialModeValue = 0; |
| 2763 | |
| 2764 | boost::system::error_code ec; |
| 2765 | auto varRestrMode = ctx->bus->yield_method_call<std::variant<std::string>>( |
James Feist | 28c7290 | 2019-09-16 10:34:07 -0700 | [diff] [blame] | 2766 | ctx->yield, ec, restricionModeService, restricionModeBasePath, |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 2767 | dBusPropertyIntf, dBusPropertyGetMethod, restricionModeIntf, |
| 2768 | restricionModeProperty); |
| 2769 | if (ec) |
| 2770 | { |
| 2771 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2772 | "ipmiGetSecurityMode: failed to get RestrictionMode property", |
| 2773 | phosphor::logging::entry("ERROR=%s", ec.message().c_str())); |
| 2774 | return ipmi::responseUnspecifiedError(); |
| 2775 | } |
| 2776 | restrictionModeValue = static_cast<uint8_t>( |
| 2777 | securityNameSpace::RestrictionMode::convertModesFromString( |
| 2778 | std::get<std::string>(varRestrMode))); |
Richard Marian Thomaiyar | 8d4f8d7 | 2019-11-11 12:06:40 +0530 | [diff] [blame] | 2779 | auto varSpecialMode = |
| 2780 | ctx->bus->yield_method_call<std::variant<std::string>>( |
| 2781 | ctx->yield, ec, specialModeService, specialModeBasePath, |
| 2782 | dBusPropertyIntf, dBusPropertyGetMethod, specialModeIntf, |
| 2783 | specialModeProperty); |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 2784 | if (ec) |
| 2785 | { |
| 2786 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2787 | "ipmiGetSecurityMode: failed to get SpecialMode property", |
| 2788 | phosphor::logging::entry("ERROR=%s", ec.message().c_str())); |
| 2789 | // fall through, let us not worry about SpecialMode property, which is |
| 2790 | // not required in user scenario |
| 2791 | } |
| 2792 | else |
| 2793 | { |
Richard Marian Thomaiyar | 8d4f8d7 | 2019-11-11 12:06:40 +0530 | [diff] [blame] | 2794 | specialModeValue = static_cast<uint8_t>( |
| 2795 | securityNameSpace::SpecialMode::convertModesFromString( |
| 2796 | std::get<std::string>(varSpecialMode))); |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 2797 | } |
| 2798 | return ipmi::responseSuccess(restrictionModeValue, specialModeValue); |
| 2799 | } |
| 2800 | |
| 2801 | /** @brief implements the set security mode command |
| 2802 | * Command allows to upgrade the restriction mode and won't allow |
| 2803 | * to downgrade from system interface |
| 2804 | * @param ctx - ctx pointer |
| 2805 | * @param restrictionMode - restriction mode value to be set. |
| 2806 | * |
| 2807 | * @returns IPMI completion code |
| 2808 | */ |
| 2809 | ipmi::RspType<> ipmiSetSecurityMode(ipmi::Context::ptr ctx, |
Richard Marian Thomaiyar | 1079106 | 2019-11-11 12:19:53 +0530 | [diff] [blame] | 2810 | uint8_t restrictionMode, |
| 2811 | std::optional<uint8_t> specialMode) |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 2812 | { |
Richard Marian Thomaiyar | 1079106 | 2019-11-11 12:19:53 +0530 | [diff] [blame] | 2813 | #ifndef BMC_VALIDATION_UNSECURE_FEATURE |
| 2814 | if (specialMode) |
| 2815 | { |
| 2816 | return ipmi::responseReqDataLenInvalid(); |
| 2817 | } |
| 2818 | #endif |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 2819 | namespace securityNameSpace = |
| 2820 | sdbusplus::xyz::openbmc_project::Control::Security::server; |
| 2821 | |
| 2822 | ChannelInfo chInfo; |
| 2823 | if (getChannelInfo(ctx->channel, chInfo) != ccSuccess) |
| 2824 | { |
| 2825 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2826 | "ipmiSetSecurityMode: Failed to get Channel Info", |
| 2827 | phosphor::logging::entry("CHANNEL=%d", ctx->channel)); |
| 2828 | return ipmi::responseUnspecifiedError(); |
| 2829 | } |
| 2830 | auto reqMode = |
| 2831 | static_cast<securityNameSpace::RestrictionMode::Modes>(restrictionMode); |
| 2832 | |
| 2833 | if ((reqMode < securityNameSpace::RestrictionMode::Modes::Provisioning) || |
| 2834 | (reqMode > |
| 2835 | securityNameSpace::RestrictionMode::Modes::ProvisionedHostDisabled)) |
| 2836 | { |
| 2837 | return ipmi::responseInvalidFieldRequest(); |
| 2838 | } |
| 2839 | |
| 2840 | boost::system::error_code ec; |
| 2841 | auto varRestrMode = ctx->bus->yield_method_call<std::variant<std::string>>( |
James Feist | 28c7290 | 2019-09-16 10:34:07 -0700 | [diff] [blame] | 2842 | ctx->yield, ec, restricionModeService, restricionModeBasePath, |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 2843 | dBusPropertyIntf, dBusPropertyGetMethod, restricionModeIntf, |
| 2844 | restricionModeProperty); |
| 2845 | if (ec) |
| 2846 | { |
| 2847 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2848 | "ipmiSetSecurityMode: failed to get RestrictionMode property", |
| 2849 | phosphor::logging::entry("ERROR=%s", ec.message().c_str())); |
| 2850 | return ipmi::responseUnspecifiedError(); |
| 2851 | } |
| 2852 | auto currentRestrictionMode = |
| 2853 | securityNameSpace::RestrictionMode::convertModesFromString( |
| 2854 | std::get<std::string>(varRestrMode)); |
| 2855 | |
| 2856 | if (chInfo.mediumType != |
| 2857 | static_cast<uint8_t>(EChannelMediumType::lan8032) && |
| 2858 | currentRestrictionMode > reqMode) |
| 2859 | { |
| 2860 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2861 | "ipmiSetSecurityMode - Downgrading security mode not supported " |
| 2862 | "through system interface", |
| 2863 | phosphor::logging::entry( |
| 2864 | "CUR_MODE=%d", static_cast<uint8_t>(currentRestrictionMode)), |
| 2865 | phosphor::logging::entry("REQ_MODE=%d", restrictionMode)); |
| 2866 | return ipmi::responseCommandNotAvailable(); |
| 2867 | } |
| 2868 | |
| 2869 | ec.clear(); |
| 2870 | ctx->bus->yield_method_call<>( |
James Feist | 28c7290 | 2019-09-16 10:34:07 -0700 | [diff] [blame] | 2871 | ctx->yield, ec, restricionModeService, restricionModeBasePath, |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 2872 | dBusPropertyIntf, dBusPropertySetMethod, restricionModeIntf, |
| 2873 | restricionModeProperty, |
| 2874 | static_cast<std::variant<std::string>>( |
| 2875 | securityNameSpace::convertForMessage(reqMode))); |
| 2876 | |
| 2877 | if (ec) |
| 2878 | { |
| 2879 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2880 | "ipmiSetSecurityMode: failed to set RestrictionMode property", |
| 2881 | phosphor::logging::entry("ERROR=%s", ec.message().c_str())); |
| 2882 | return ipmi::responseUnspecifiedError(); |
| 2883 | } |
Richard Marian Thomaiyar | 1079106 | 2019-11-11 12:19:53 +0530 | [diff] [blame] | 2884 | |
| 2885 | #ifdef BMC_VALIDATION_UNSECURE_FEATURE |
| 2886 | if (specialMode) |
| 2887 | { |
Jayaprakash Mutyala | d77489f | 2020-09-05 01:00:04 +0000 | [diff] [blame] | 2888 | constexpr uint8_t mfgMode = 0x01; |
| 2889 | // Manufacturing mode is reserved. So can't enable this mode. |
| 2890 | if (specialMode.value() == mfgMode) |
| 2891 | { |
| 2892 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 2893 | "ipmiSetSecurityMode: Can't enable Manufacturing mode"); |
| 2894 | return ipmi::responseInvalidFieldRequest(); |
| 2895 | } |
| 2896 | |
Richard Marian Thomaiyar | 1079106 | 2019-11-11 12:19:53 +0530 | [diff] [blame] | 2897 | ec.clear(); |
| 2898 | ctx->bus->yield_method_call<>( |
| 2899 | ctx->yield, ec, specialModeService, specialModeBasePath, |
| 2900 | dBusPropertyIntf, dBusPropertySetMethod, specialModeIntf, |
| 2901 | specialModeProperty, |
| 2902 | static_cast<std::variant<std::string>>( |
| 2903 | securityNameSpace::convertForMessage( |
| 2904 | static_cast<securityNameSpace::SpecialMode::Modes>( |
| 2905 | specialMode.value())))); |
| 2906 | |
| 2907 | if (ec) |
| 2908 | { |
| 2909 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2910 | "ipmiSetSecurityMode: failed to set SpecialMode property", |
| 2911 | phosphor::logging::entry("ERROR=%s", ec.message().c_str())); |
| 2912 | return ipmi::responseUnspecifiedError(); |
| 2913 | } |
| 2914 | } |
| 2915 | #endif |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 2916 | return ipmi::responseSuccess(); |
| 2917 | } |
| 2918 | |
Vernon Mauery | 4ac799d | 2019-05-20 15:50:37 -0700 | [diff] [blame] | 2919 | ipmi::RspType<uint8_t /* restore status */> |
| 2920 | ipmiRestoreConfiguration(const std::array<uint8_t, 3>& clr, uint8_t cmd) |
| 2921 | { |
| 2922 | static constexpr std::array<uint8_t, 3> expClr = {'C', 'L', 'R'}; |
| 2923 | |
| 2924 | if (clr != expClr) |
| 2925 | { |
| 2926 | return ipmi::responseInvalidFieldRequest(); |
| 2927 | } |
| 2928 | constexpr uint8_t cmdStatus = 0; |
| 2929 | constexpr uint8_t cmdDefaultRestore = 0xaa; |
| 2930 | constexpr uint8_t cmdFullRestore = 0xbb; |
| 2931 | constexpr uint8_t cmdFormat = 0xcc; |
| 2932 | |
| 2933 | constexpr const char* restoreOpFname = "/tmp/.rwfs/.restore_op"; |
| 2934 | |
| 2935 | switch (cmd) |
| 2936 | { |
| 2937 | case cmdStatus: |
| 2938 | break; |
| 2939 | case cmdDefaultRestore: |
| 2940 | case cmdFullRestore: |
| 2941 | case cmdFormat: |
| 2942 | { |
| 2943 | // write file to rwfs root |
| 2944 | int value = (cmd - 1) & 0x03; // map aa, bb, cc => 1, 2, 3 |
| 2945 | std::ofstream restoreFile(restoreOpFname); |
| 2946 | if (!restoreFile) |
| 2947 | { |
| 2948 | return ipmi::responseUnspecifiedError(); |
| 2949 | } |
| 2950 | restoreFile << value << "\n"; |
Arun P. Mohanan | ba1fbc8 | 2021-04-26 11:26:53 +0530 | [diff] [blame] | 2951 | |
| 2952 | phosphor::logging::log<phosphor::logging::level::WARNING>( |
| 2953 | "Restore to default will be performed on next BMC boot", |
| 2954 | phosphor::logging::entry("ACTION=0x%0X", cmd)); |
| 2955 | |
Vernon Mauery | 4ac799d | 2019-05-20 15:50:37 -0700 | [diff] [blame] | 2956 | break; |
| 2957 | } |
| 2958 | default: |
| 2959 | return ipmi::responseInvalidFieldRequest(); |
| 2960 | } |
| 2961 | |
| 2962 | constexpr uint8_t restorePending = 0; |
| 2963 | constexpr uint8_t restoreComplete = 1; |
| 2964 | |
| 2965 | uint8_t restoreStatus = std::filesystem::exists(restoreOpFname) |
| 2966 | ? restorePending |
| 2967 | : restoreComplete; |
| 2968 | return ipmi::responseSuccess(restoreStatus); |
| 2969 | } |
| 2970 | |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 2971 | ipmi::RspType<uint8_t> ipmiOEMGetNmiSource(void) |
| 2972 | { |
| 2973 | uint8_t bmcSource; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 2974 | namespace nmi = sdbusplus::xyz::openbmc_project::Chassis::Control::server; |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 2975 | |
| 2976 | try |
| 2977 | { |
| 2978 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 2979 | std::string service = |
| 2980 | getService(*dbus, oemNmiSourceIntf, oemNmiSourceObjPath); |
| 2981 | Value variant = |
| 2982 | getDbusProperty(*dbus, service, oemNmiSourceObjPath, |
| 2983 | oemNmiSourceIntf, oemNmiBmcSourceObjPathProp); |
| 2984 | |
| 2985 | switch (nmi::NMISource::convertBMCSourceSignalFromString( |
| 2986 | std::get<std::string>(variant))) |
| 2987 | { |
| 2988 | case nmi::NMISource::BMCSourceSignal::None: |
| 2989 | bmcSource = static_cast<uint8_t>(NmiSource::none); |
| 2990 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 2991 | case nmi::NMISource::BMCSourceSignal::FrontPanelButton: |
| 2992 | bmcSource = static_cast<uint8_t>(NmiSource::frontPanelButton); |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 2993 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 2994 | case nmi::NMISource::BMCSourceSignal::Watchdog: |
| 2995 | bmcSource = static_cast<uint8_t>(NmiSource::watchdog); |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 2996 | break; |
| 2997 | case nmi::NMISource::BMCSourceSignal::ChassisCmd: |
| 2998 | bmcSource = static_cast<uint8_t>(NmiSource::chassisCmd); |
| 2999 | break; |
| 3000 | case nmi::NMISource::BMCSourceSignal::MemoryError: |
| 3001 | bmcSource = static_cast<uint8_t>(NmiSource::memoryError); |
| 3002 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 3003 | case nmi::NMISource::BMCSourceSignal::PciBusError: |
| 3004 | bmcSource = static_cast<uint8_t>(NmiSource::pciBusError); |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 3005 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 3006 | case nmi::NMISource::BMCSourceSignal::PCH: |
| 3007 | bmcSource = static_cast<uint8_t>(NmiSource::pch); |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 3008 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 3009 | case nmi::NMISource::BMCSourceSignal::Chipset: |
| 3010 | bmcSource = static_cast<uint8_t>(NmiSource::chipset); |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 3011 | break; |
| 3012 | default: |
| 3013 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3014 | "NMI source: invalid property!", |
| 3015 | phosphor::logging::entry( |
| 3016 | "PROP=%s", std::get<std::string>(variant).c_str())); |
| 3017 | return ipmi::responseResponseError(); |
| 3018 | } |
| 3019 | } |
Patrick Williams | 69245b7 | 2021-09-02 09:23:01 -0500 | [diff] [blame] | 3020 | catch (sdbusplus::exception::exception& e) |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 3021 | { |
| 3022 | phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
| 3023 | return ipmi::responseResponseError(); |
| 3024 | } |
| 3025 | |
| 3026 | return ipmi::responseSuccess(bmcSource); |
| 3027 | } |
| 3028 | |
| 3029 | ipmi::RspType<> ipmiOEMSetNmiSource(uint8_t sourceId) |
| 3030 | { |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 3031 | namespace nmi = sdbusplus::xyz::openbmc_project::Chassis::Control::server; |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 3032 | |
| 3033 | nmi::NMISource::BMCSourceSignal bmcSourceSignal = |
| 3034 | nmi::NMISource::BMCSourceSignal::None; |
| 3035 | |
| 3036 | switch (NmiSource(sourceId)) |
| 3037 | { |
| 3038 | case NmiSource::none: |
| 3039 | bmcSourceSignal = nmi::NMISource::BMCSourceSignal::None; |
| 3040 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 3041 | case NmiSource::frontPanelButton: |
| 3042 | bmcSourceSignal = nmi::NMISource::BMCSourceSignal::FrontPanelButton; |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 3043 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 3044 | case NmiSource::watchdog: |
| 3045 | bmcSourceSignal = nmi::NMISource::BMCSourceSignal::Watchdog; |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 3046 | break; |
| 3047 | case NmiSource::chassisCmd: |
| 3048 | bmcSourceSignal = nmi::NMISource::BMCSourceSignal::ChassisCmd; |
| 3049 | break; |
| 3050 | case NmiSource::memoryError: |
| 3051 | bmcSourceSignal = nmi::NMISource::BMCSourceSignal::MemoryError; |
| 3052 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 3053 | case NmiSource::pciBusError: |
| 3054 | bmcSourceSignal = nmi::NMISource::BMCSourceSignal::PciBusError; |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 3055 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 3056 | case NmiSource::pch: |
| 3057 | bmcSourceSignal = nmi::NMISource::BMCSourceSignal::PCH; |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 3058 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 3059 | case NmiSource::chipset: |
| 3060 | bmcSourceSignal = nmi::NMISource::BMCSourceSignal::Chipset; |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 3061 | break; |
| 3062 | default: |
| 3063 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3064 | "NMI source: invalid property!"); |
| 3065 | return ipmi::responseResponseError(); |
| 3066 | } |
| 3067 | |
| 3068 | try |
| 3069 | { |
| 3070 | // keep NMI signal source |
| 3071 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 3072 | std::string service = |
| 3073 | getService(*dbus, oemNmiSourceIntf, oemNmiSourceObjPath); |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 3074 | setDbusProperty(*dbus, service, oemNmiSourceObjPath, oemNmiSourceIntf, |
| 3075 | oemNmiBmcSourceObjPathProp, |
| 3076 | nmi::convertForMessage(bmcSourceSignal)); |
Chen Yugang | 99be633 | 2019-08-09 16:20:48 +0800 | [diff] [blame] | 3077 | // set Enabled property to inform NMI source handling |
| 3078 | // to trigger a NMI_OUT BSOD. |
| 3079 | // if it's triggered by NMI source property changed, |
| 3080 | // NMI_OUT BSOD could be missed if the same source occurs twice in a row |
| 3081 | if (bmcSourceSignal != nmi::NMISource::BMCSourceSignal::None) |
| 3082 | { |
| 3083 | setDbusProperty(*dbus, service, oemNmiSourceObjPath, |
| 3084 | oemNmiSourceIntf, oemNmiEnabledObjPathProp, |
| 3085 | static_cast<bool>(true)); |
| 3086 | } |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 3087 | } |
| 3088 | catch (sdbusplus::exception_t& e) |
| 3089 | { |
| 3090 | phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
| 3091 | return ipmi::responseResponseError(); |
| 3092 | } |
| 3093 | |
| 3094 | return ipmi::responseSuccess(); |
| 3095 | } |
| 3096 | |
James Feist | 63efafa | 2019-07-24 12:39:21 -0700 | [diff] [blame] | 3097 | namespace dimmOffset |
| 3098 | { |
| 3099 | constexpr const char* dimmPower = "DimmPower"; |
| 3100 | constexpr const char* staticCltt = "StaticCltt"; |
| 3101 | constexpr const char* offsetPath = "/xyz/openbmc_project/Inventory/Item/Dimm"; |
| 3102 | constexpr const char* offsetInterface = |
| 3103 | "xyz.openbmc_project.Inventory.Item.Dimm.Offset"; |
| 3104 | constexpr const char* property = "DimmOffset"; |
| 3105 | |
| 3106 | }; // namespace dimmOffset |
| 3107 | |
| 3108 | ipmi::RspType<> |
| 3109 | ipmiOEMSetDimmOffset(uint8_t type, |
| 3110 | const std::vector<std::tuple<uint8_t, uint8_t>>& data) |
| 3111 | { |
| 3112 | if (type != static_cast<uint8_t>(dimmOffsetTypes::dimmPower) && |
| 3113 | type != static_cast<uint8_t>(dimmOffsetTypes::staticCltt)) |
| 3114 | { |
| 3115 | return ipmi::responseInvalidFieldRequest(); |
| 3116 | } |
| 3117 | |
| 3118 | if (data.empty()) |
| 3119 | { |
| 3120 | return ipmi::responseInvalidFieldRequest(); |
| 3121 | } |
| 3122 | nlohmann::json json; |
| 3123 | |
| 3124 | std::ifstream jsonStream(dimmOffsetFile); |
| 3125 | if (jsonStream.good()) |
| 3126 | { |
| 3127 | json = nlohmann::json::parse(jsonStream, nullptr, false); |
| 3128 | if (json.is_discarded()) |
| 3129 | { |
| 3130 | json = nlohmann::json(); |
| 3131 | } |
| 3132 | jsonStream.close(); |
| 3133 | } |
| 3134 | |
| 3135 | std::string typeName; |
| 3136 | if (type == static_cast<uint8_t>(dimmOffsetTypes::dimmPower)) |
| 3137 | { |
| 3138 | typeName = dimmOffset::dimmPower; |
| 3139 | } |
| 3140 | else |
| 3141 | { |
| 3142 | typeName = dimmOffset::staticCltt; |
| 3143 | } |
| 3144 | |
| 3145 | nlohmann::json& field = json[typeName]; |
| 3146 | |
| 3147 | for (const auto& [index, value] : data) |
| 3148 | { |
| 3149 | field[index] = value; |
| 3150 | } |
| 3151 | |
| 3152 | for (nlohmann::json& val : field) |
| 3153 | { |
| 3154 | if (val == nullptr) |
| 3155 | { |
| 3156 | val = static_cast<uint8_t>(0); |
| 3157 | } |
| 3158 | } |
| 3159 | |
| 3160 | std::ofstream output(dimmOffsetFile); |
| 3161 | if (!output.good()) |
| 3162 | { |
| 3163 | std::cerr << "Error writing json file\n"; |
| 3164 | return ipmi::responseResponseError(); |
| 3165 | } |
| 3166 | |
| 3167 | output << json.dump(4); |
| 3168 | |
| 3169 | if (type == static_cast<uint8_t>(dimmOffsetTypes::staticCltt)) |
| 3170 | { |
| 3171 | std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus(); |
| 3172 | |
| 3173 | std::variant<std::vector<uint8_t>> offsets = |
| 3174 | field.get<std::vector<uint8_t>>(); |
| 3175 | auto call = bus->new_method_call( |
| 3176 | settingsBusName, dimmOffset::offsetPath, PROP_INTF, "Set"); |
| 3177 | call.append(dimmOffset::offsetInterface, dimmOffset::property, offsets); |
| 3178 | try |
| 3179 | { |
| 3180 | bus->call(call); |
| 3181 | } |
| 3182 | catch (sdbusplus::exception_t& e) |
| 3183 | { |
| 3184 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3185 | "ipmiOEMSetDimmOffset: can't set dimm offsets!", |
| 3186 | phosphor::logging::entry("ERR=%s", e.what())); |
| 3187 | return ipmi::responseResponseError(); |
| 3188 | } |
| 3189 | } |
| 3190 | |
| 3191 | return ipmi::responseSuccess(); |
| 3192 | } |
| 3193 | |
| 3194 | ipmi::RspType<uint8_t> ipmiOEMGetDimmOffset(uint8_t type, uint8_t index) |
| 3195 | { |
| 3196 | |
| 3197 | if (type != static_cast<uint8_t>(dimmOffsetTypes::dimmPower) && |
| 3198 | type != static_cast<uint8_t>(dimmOffsetTypes::staticCltt)) |
| 3199 | { |
| 3200 | return ipmi::responseInvalidFieldRequest(); |
| 3201 | } |
| 3202 | |
| 3203 | std::ifstream jsonStream(dimmOffsetFile); |
| 3204 | |
| 3205 | auto json = nlohmann::json::parse(jsonStream, nullptr, false); |
| 3206 | if (json.is_discarded()) |
| 3207 | { |
| 3208 | std::cerr << "File error in " << dimmOffsetFile << "\n"; |
| 3209 | return ipmi::responseResponseError(); |
| 3210 | } |
| 3211 | |
| 3212 | std::string typeName; |
| 3213 | if (type == static_cast<uint8_t>(dimmOffsetTypes::dimmPower)) |
| 3214 | { |
| 3215 | typeName = dimmOffset::dimmPower; |
| 3216 | } |
| 3217 | else |
| 3218 | { |
| 3219 | typeName = dimmOffset::staticCltt; |
| 3220 | } |
| 3221 | |
| 3222 | auto it = json.find(typeName); |
| 3223 | if (it == json.end()) |
| 3224 | { |
| 3225 | return ipmi::responseInvalidFieldRequest(); |
| 3226 | } |
| 3227 | |
| 3228 | if (it->size() <= index) |
| 3229 | { |
| 3230 | return ipmi::responseInvalidFieldRequest(); |
| 3231 | } |
| 3232 | |
| 3233 | uint8_t resp = it->at(index).get<uint8_t>(); |
| 3234 | return ipmi::responseSuccess(resp); |
| 3235 | } |
| 3236 | |
Chen,Yugang | 4f7e76b | 2019-08-20 09:28:06 +0800 | [diff] [blame] | 3237 | namespace boot_options |
| 3238 | { |
| 3239 | |
| 3240 | using namespace sdbusplus::xyz::openbmc_project::Control::Boot::server; |
| 3241 | using IpmiValue = uint8_t; |
| 3242 | constexpr auto ipmiDefault = 0; |
| 3243 | |
| 3244 | std::map<IpmiValue, Source::Sources> sourceIpmiToDbus = { |
| 3245 | {0x01, Source::Sources::Network}, |
| 3246 | {0x02, Source::Sources::Disk}, |
| 3247 | {0x05, Source::Sources::ExternalMedia}, |
| 3248 | {0x0f, Source::Sources::RemovableMedia}, |
| 3249 | {ipmiDefault, Source::Sources::Default}}; |
| 3250 | |
| 3251 | std::map<IpmiValue, Mode::Modes> modeIpmiToDbus = { |
Chen Yugang | ca12a7b | 2019-09-03 18:11:44 +0800 | [diff] [blame] | 3252 | {0x06, Mode::Modes::Setup}, {ipmiDefault, Mode::Modes::Regular}}; |
Chen,Yugang | 4f7e76b | 2019-08-20 09:28:06 +0800 | [diff] [blame] | 3253 | |
| 3254 | std::map<Source::Sources, IpmiValue> sourceDbusToIpmi = { |
| 3255 | {Source::Sources::Network, 0x01}, |
| 3256 | {Source::Sources::Disk, 0x02}, |
| 3257 | {Source::Sources::ExternalMedia, 0x05}, |
| 3258 | {Source::Sources::RemovableMedia, 0x0f}, |
| 3259 | {Source::Sources::Default, ipmiDefault}}; |
| 3260 | |
| 3261 | std::map<Mode::Modes, IpmiValue> modeDbusToIpmi = { |
Chen Yugang | ca12a7b | 2019-09-03 18:11:44 +0800 | [diff] [blame] | 3262 | {Mode::Modes::Setup, 0x06}, {Mode::Modes::Regular, ipmiDefault}}; |
Chen,Yugang | 4f7e76b | 2019-08-20 09:28:06 +0800 | [diff] [blame] | 3263 | |
| 3264 | static constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode"; |
| 3265 | static constexpr auto bootSourceIntf = |
| 3266 | "xyz.openbmc_project.Control.Boot.Source"; |
| 3267 | static constexpr auto enabledIntf = "xyz.openbmc_project.Object.Enable"; |
| 3268 | static constexpr auto persistentObjPath = |
| 3269 | "/xyz/openbmc_project/control/host0/boot"; |
| 3270 | static constexpr auto oneTimePath = |
| 3271 | "/xyz/openbmc_project/control/host0/boot/one_time"; |
| 3272 | static constexpr auto bootSourceProp = "BootSource"; |
| 3273 | static constexpr auto bootModeProp = "BootMode"; |
| 3274 | static constexpr auto oneTimeBootEnableProp = "Enabled"; |
| 3275 | static constexpr auto httpBootMode = |
| 3276 | "xyz.openbmc_project.Control.Boot.Source.Sources.Http"; |
| 3277 | |
| 3278 | enum class BootOptionParameter : size_t |
| 3279 | { |
| 3280 | setInProgress = 0x0, |
| 3281 | bootFlags = 0x5, |
| 3282 | }; |
| 3283 | static constexpr uint8_t setComplete = 0x0; |
| 3284 | static constexpr uint8_t setInProgress = 0x1; |
| 3285 | static uint8_t transferStatus = setComplete; |
| 3286 | static constexpr uint8_t setParmVersion = 0x01; |
| 3287 | static constexpr uint8_t setParmBootFlagsPermanent = 0x40; |
| 3288 | static constexpr uint8_t setParmBootFlagsValidOneTime = 0x80; |
| 3289 | static constexpr uint8_t setParmBootFlagsValidPermanent = 0xC0; |
| 3290 | static constexpr uint8_t httpBoot = 0xd; |
| 3291 | static constexpr uint8_t bootSourceMask = 0x3c; |
| 3292 | |
| 3293 | } // namespace boot_options |
| 3294 | |
| 3295 | ipmi::RspType<uint8_t, // version |
| 3296 | uint8_t, // param |
| 3297 | uint8_t, // data0, dependent on parameter |
| 3298 | std::optional<uint8_t> // data1, dependent on parameter |
| 3299 | > |
| 3300 | ipmiOemGetEfiBootOptions(uint8_t parameter, uint8_t set, uint8_t block) |
| 3301 | { |
| 3302 | using namespace boot_options; |
| 3303 | uint8_t bootOption = 0; |
| 3304 | |
| 3305 | if (parameter == static_cast<uint8_t>(BootOptionParameter::setInProgress)) |
| 3306 | { |
| 3307 | return ipmi::responseSuccess(setParmVersion, parameter, transferStatus, |
| 3308 | std::nullopt); |
| 3309 | } |
| 3310 | |
| 3311 | if (parameter != static_cast<uint8_t>(BootOptionParameter::bootFlags)) |
| 3312 | { |
| 3313 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3314 | "Unsupported parameter"); |
Jayaprakash Mutyala | 3694d07 | 2021-07-22 10:34:37 +0000 | [diff] [blame] | 3315 | return ipmi::response(ccParameterNotSupported); |
Chen,Yugang | 4f7e76b | 2019-08-20 09:28:06 +0800 | [diff] [blame] | 3316 | } |
| 3317 | |
| 3318 | try |
| 3319 | { |
| 3320 | auto oneTimeEnabled = false; |
| 3321 | // read one time Enabled property |
| 3322 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 3323 | std::string service = getService(*dbus, enabledIntf, oneTimePath); |
| 3324 | Value variant = getDbusProperty(*dbus, service, oneTimePath, |
| 3325 | enabledIntf, oneTimeBootEnableProp); |
| 3326 | oneTimeEnabled = std::get<bool>(variant); |
| 3327 | |
| 3328 | // get BootSource and BootMode properties |
| 3329 | // according to oneTimeEnable |
| 3330 | auto bootObjPath = oneTimePath; |
| 3331 | if (oneTimeEnabled == false) |
| 3332 | { |
| 3333 | bootObjPath = persistentObjPath; |
| 3334 | } |
| 3335 | |
| 3336 | service = getService(*dbus, bootModeIntf, bootObjPath); |
| 3337 | variant = getDbusProperty(*dbus, service, bootObjPath, bootModeIntf, |
| 3338 | bootModeProp); |
| 3339 | |
| 3340 | auto bootMode = |
| 3341 | Mode::convertModesFromString(std::get<std::string>(variant)); |
| 3342 | |
| 3343 | service = getService(*dbus, bootSourceIntf, bootObjPath); |
| 3344 | variant = getDbusProperty(*dbus, service, bootObjPath, bootSourceIntf, |
| 3345 | bootSourceProp); |
| 3346 | |
| 3347 | if (std::get<std::string>(variant) == httpBootMode) |
| 3348 | { |
| 3349 | bootOption = httpBoot; |
| 3350 | } |
| 3351 | else |
| 3352 | { |
| 3353 | auto bootSource = Source::convertSourcesFromString( |
| 3354 | std::get<std::string>(variant)); |
| 3355 | bootOption = sourceDbusToIpmi.at(bootSource); |
| 3356 | if (Source::Sources::Default == bootSource) |
| 3357 | { |
| 3358 | bootOption = modeDbusToIpmi.at(bootMode); |
| 3359 | } |
| 3360 | } |
| 3361 | |
| 3362 | uint8_t oneTime = oneTimeEnabled ? setParmBootFlagsValidOneTime |
| 3363 | : setParmBootFlagsValidPermanent; |
| 3364 | bootOption <<= 2; // shift for responseconstexpr |
| 3365 | return ipmi::responseSuccess(setParmVersion, parameter, oneTime, |
| 3366 | bootOption); |
| 3367 | } |
| 3368 | catch (sdbusplus::exception_t& e) |
| 3369 | { |
| 3370 | phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
| 3371 | return ipmi::responseResponseError(); |
| 3372 | } |
| 3373 | } |
| 3374 | |
| 3375 | ipmi::RspType<> ipmiOemSetEfiBootOptions(uint8_t bootFlag, uint8_t bootParam, |
| 3376 | std::optional<uint8_t> bootOption) |
| 3377 | { |
| 3378 | using namespace boot_options; |
| 3379 | auto oneTimeEnabled = false; |
| 3380 | |
| 3381 | if (bootFlag == static_cast<uint8_t>(BootOptionParameter::setInProgress)) |
| 3382 | { |
| 3383 | if (bootOption) |
| 3384 | { |
| 3385 | return ipmi::responseReqDataLenInvalid(); |
| 3386 | } |
| 3387 | |
| 3388 | if (transferStatus == setInProgress) |
| 3389 | { |
| 3390 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3391 | "boot option set in progress!"); |
| 3392 | return ipmi::responseResponseError(); |
| 3393 | } |
| 3394 | |
| 3395 | transferStatus = bootParam; |
| 3396 | return ipmi::responseSuccess(); |
| 3397 | } |
| 3398 | |
| 3399 | if (bootFlag != (uint8_t)BootOptionParameter::bootFlags) |
| 3400 | { |
| 3401 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3402 | "Unsupported parameter"); |
Jayaprakash Mutyala | 3694d07 | 2021-07-22 10:34:37 +0000 | [diff] [blame] | 3403 | return ipmi::response(ccParameterNotSupported); |
Chen,Yugang | 4f7e76b | 2019-08-20 09:28:06 +0800 | [diff] [blame] | 3404 | } |
| 3405 | |
| 3406 | if (!bootOption) |
| 3407 | { |
| 3408 | return ipmi::responseReqDataLenInvalid(); |
| 3409 | } |
| 3410 | |
| 3411 | if (((bootOption.value() & bootSourceMask) >> 2) != |
| 3412 | httpBoot) // not http boot, exit |
| 3413 | { |
| 3414 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3415 | "wrong boot option parameter!"); |
| 3416 | return ipmi::responseParmOutOfRange(); |
| 3417 | } |
| 3418 | |
| 3419 | try |
| 3420 | { |
| 3421 | bool permanent = (bootParam & setParmBootFlagsPermanent) == |
| 3422 | setParmBootFlagsPermanent; |
| 3423 | |
| 3424 | // read one time Enabled property |
| 3425 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 3426 | std::string service = getService(*dbus, enabledIntf, oneTimePath); |
| 3427 | Value variant = getDbusProperty(*dbus, service, oneTimePath, |
| 3428 | enabledIntf, oneTimeBootEnableProp); |
| 3429 | oneTimeEnabled = std::get<bool>(variant); |
| 3430 | |
| 3431 | /* |
| 3432 | * Check if the current boot setting is onetime or permanent, if the |
| 3433 | * request in the command is otherwise, then set the "Enabled" |
| 3434 | * property in one_time object path to 'True' to indicate onetime |
| 3435 | * and 'False' to indicate permanent. |
| 3436 | * |
| 3437 | * Once the onetime/permanent setting is applied, then the bootMode |
| 3438 | * and bootSource is updated for the corresponding object. |
| 3439 | */ |
| 3440 | if (permanent == oneTimeEnabled) |
| 3441 | { |
| 3442 | setDbusProperty(*dbus, service, oneTimePath, enabledIntf, |
| 3443 | oneTimeBootEnableProp, !permanent); |
| 3444 | } |
| 3445 | |
| 3446 | // set BootSource and BootMode properties |
| 3447 | // according to oneTimeEnable or persistent |
| 3448 | auto bootObjPath = oneTimePath; |
| 3449 | if (oneTimeEnabled == false) |
| 3450 | { |
| 3451 | bootObjPath = persistentObjPath; |
| 3452 | } |
| 3453 | std::string bootMode = |
| 3454 | "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; |
| 3455 | std::string bootSource = httpBootMode; |
| 3456 | |
| 3457 | service = getService(*dbus, bootModeIntf, bootObjPath); |
| 3458 | setDbusProperty(*dbus, service, bootObjPath, bootModeIntf, bootModeProp, |
| 3459 | bootMode); |
| 3460 | |
| 3461 | service = getService(*dbus, bootSourceIntf, bootObjPath); |
| 3462 | setDbusProperty(*dbus, service, bootObjPath, bootSourceIntf, |
| 3463 | bootSourceProp, bootSource); |
| 3464 | } |
| 3465 | catch (sdbusplus::exception_t& e) |
| 3466 | { |
| 3467 | phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
| 3468 | return ipmi::responseResponseError(); |
| 3469 | } |
| 3470 | |
| 3471 | return ipmi::responseSuccess(); |
| 3472 | } |
| 3473 | |
Cheng C Yang | 4e6ee15 | 2019-09-25 10:27:44 +0800 | [diff] [blame] | 3474 | using BasicVariantType = |
| 3475 | std::variant<std::vector<std::string>, std::vector<uint64_t>, std::string, |
| 3476 | int64_t, uint64_t, double, int32_t, uint32_t, int16_t, |
| 3477 | uint16_t, uint8_t, bool>; |
| 3478 | using PropertyMapType = |
| 3479 | boost::container::flat_map<std::string, BasicVariantType>; |
| 3480 | static constexpr const std::array<const char*, 1> psuPresenceTypes = { |
| 3481 | "xyz.openbmc_project.Configuration.PSUPresence"}; |
| 3482 | int getPSUAddress(ipmi::Context::ptr ctx, uint8_t& bus, |
| 3483 | std::vector<uint64_t>& addrTable) |
| 3484 | { |
| 3485 | boost::system::error_code ec; |
| 3486 | GetSubTreeType subtree = ctx->bus->yield_method_call<GetSubTreeType>( |
| 3487 | ctx->yield, ec, "xyz.openbmc_project.ObjectMapper", |
| 3488 | "/xyz/openbmc_project/object_mapper", |
| 3489 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
| 3490 | "/xyz/openbmc_project/inventory/system", 3, psuPresenceTypes); |
| 3491 | if (ec) |
| 3492 | { |
| 3493 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3494 | "Failed to set dbus property to cold redundancy"); |
| 3495 | return -1; |
| 3496 | } |
| 3497 | for (const auto& object : subtree) |
| 3498 | { |
| 3499 | std::string pathName = object.first; |
| 3500 | for (const auto& serviceIface : object.second) |
| 3501 | { |
| 3502 | std::string serviceName = serviceIface.first; |
| 3503 | |
| 3504 | ec.clear(); |
| 3505 | PropertyMapType propMap = |
| 3506 | ctx->bus->yield_method_call<PropertyMapType>( |
| 3507 | ctx->yield, ec, serviceName, pathName, |
| 3508 | "org.freedesktop.DBus.Properties", "GetAll", |
| 3509 | "xyz.openbmc_project.Configuration.PSUPresence"); |
| 3510 | if (ec) |
| 3511 | { |
| 3512 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3513 | "Failed to set dbus property to cold redundancy"); |
| 3514 | return -1; |
| 3515 | } |
| 3516 | auto psuBus = std::get_if<uint64_t>(&propMap["Bus"]); |
| 3517 | auto psuAddress = |
| 3518 | std::get_if<std::vector<uint64_t>>(&propMap["Address"]); |
| 3519 | |
| 3520 | if (psuBus == nullptr || psuAddress == nullptr) |
| 3521 | { |
| 3522 | std::cerr << "error finding necessary " |
| 3523 | "entry in configuration\n"; |
| 3524 | return -1; |
| 3525 | } |
| 3526 | bus = static_cast<uint8_t>(*psuBus); |
| 3527 | addrTable = *psuAddress; |
| 3528 | return 0; |
| 3529 | } |
| 3530 | } |
| 3531 | return -1; |
| 3532 | } |
| 3533 | |
| 3534 | static const constexpr uint8_t addrOffset = 8; |
| 3535 | static const constexpr uint8_t psuRevision = 0xd9; |
| 3536 | static const constexpr uint8_t defaultPSUBus = 7; |
| 3537 | // Second Minor, Primary Minor, Major |
| 3538 | static const constexpr size_t verLen = 3; |
| 3539 | ipmi::RspType<std::vector<uint8_t>> ipmiOEMGetPSUVersion(ipmi::Context::ptr ctx) |
| 3540 | { |
| 3541 | uint8_t bus = defaultPSUBus; |
| 3542 | std::vector<uint64_t> addrTable; |
| 3543 | std::vector<uint8_t> result; |
| 3544 | if (getPSUAddress(ctx, bus, addrTable)) |
| 3545 | { |
| 3546 | std::cerr << "Failed to get PSU bus and address\n"; |
| 3547 | return ipmi::responseResponseError(); |
| 3548 | } |
| 3549 | |
| 3550 | for (const auto& slaveAddr : addrTable) |
| 3551 | { |
| 3552 | std::vector<uint8_t> writeData = {psuRevision}; |
| 3553 | std::vector<uint8_t> readBuf(verLen); |
| 3554 | uint8_t addr = static_cast<uint8_t>(slaveAddr) + addrOffset; |
| 3555 | std::string i2cBus = "/dev/i2c-" + std::to_string(bus); |
| 3556 | |
| 3557 | auto retI2C = ipmi::i2cWriteRead(i2cBus, addr, writeData, readBuf); |
| 3558 | if (retI2C != ipmi::ccSuccess) |
| 3559 | { |
| 3560 | for (size_t idx = 0; idx < verLen; idx++) |
| 3561 | { |
| 3562 | result.emplace_back(0x00); |
| 3563 | } |
| 3564 | } |
| 3565 | else |
| 3566 | { |
| 3567 | for (const uint8_t& data : readBuf) |
| 3568 | { |
| 3569 | result.emplace_back(data); |
| 3570 | } |
| 3571 | } |
| 3572 | } |
| 3573 | |
| 3574 | return ipmi::responseSuccess(result); |
| 3575 | } |
| 3576 | |
srikanta mondal | 2030d7c | 2020-05-03 17:25:25 +0000 | [diff] [blame] | 3577 | std::optional<uint8_t> getMultiNodeInfoPresence(ipmi::Context::ptr ctx, |
| 3578 | const std::string& name) |
| 3579 | { |
| 3580 | Value dbusValue = 0; |
| 3581 | std::string serviceName; |
| 3582 | |
| 3583 | boost::system::error_code ec = |
| 3584 | ipmi::getService(ctx, multiNodeIntf, multiNodeObjPath, serviceName); |
| 3585 | |
| 3586 | if (ec) |
| 3587 | { |
| 3588 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3589 | "Failed to perform Multinode getService."); |
| 3590 | return std::nullopt; |
| 3591 | } |
| 3592 | |
| 3593 | ec = ipmi::getDbusProperty(ctx, serviceName, multiNodeObjPath, |
| 3594 | multiNodeIntf, name, dbusValue); |
| 3595 | if (ec) |
| 3596 | { |
| 3597 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3598 | "Failed to perform Multinode get property"); |
| 3599 | return std::nullopt; |
| 3600 | } |
| 3601 | |
| 3602 | auto multiNodeVal = std::get_if<uint8_t>(&dbusValue); |
| 3603 | if (!multiNodeVal) |
| 3604 | { |
| 3605 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3606 | "getMultiNodeInfoPresence: error to get multinode"); |
| 3607 | return std::nullopt; |
| 3608 | } |
| 3609 | return *multiNodeVal; |
| 3610 | } |
| 3611 | |
| 3612 | /** @brief implements OEM get reading command |
| 3613 | * @param domain ID |
| 3614 | * @param reading Type |
| 3615 | * - 00h = platform Power Consumption |
| 3616 | * - 01h = inlet Air Temp |
| 3617 | * - 02h = icc_TDC from PECI |
| 3618 | * @param reserved, write as 0000h |
| 3619 | * |
| 3620 | * @returns IPMI completion code plus response data |
| 3621 | * - response |
| 3622 | * - domain ID |
| 3623 | * - reading Type |
| 3624 | * - 00h = platform Power Consumption |
| 3625 | * - 01h = inlet Air Temp |
| 3626 | * - 02h = icc_TDC from PECI |
| 3627 | * - reading |
| 3628 | */ |
| 3629 | ipmi::RspType<uint4_t, // domain ID |
| 3630 | uint4_t, // reading Type |
| 3631 | uint16_t // reading Value |
| 3632 | > |
| 3633 | ipmiOEMGetReading(ipmi::Context::ptr ctx, uint4_t domainId, |
| 3634 | uint4_t readingType, uint16_t reserved) |
| 3635 | { |
| 3636 | constexpr uint8_t platformPower = 0; |
| 3637 | constexpr uint8_t inletAirTemp = 1; |
| 3638 | constexpr uint8_t iccTdc = 2; |
| 3639 | |
| 3640 | if ((static_cast<uint8_t>(readingType) > iccTdc) || domainId || reserved) |
| 3641 | { |
| 3642 | return ipmi::responseInvalidFieldRequest(); |
| 3643 | } |
| 3644 | |
| 3645 | // This command should run only from multi-node product. |
| 3646 | // For all other platforms this command will return invalid. |
| 3647 | |
| 3648 | std::optional<uint8_t> nodeInfo = |
| 3649 | getMultiNodeInfoPresence(ctx, "NodePresence"); |
| 3650 | if (!nodeInfo || !*nodeInfo) |
| 3651 | { |
| 3652 | return ipmi::responseInvalidCommand(); |
| 3653 | } |
| 3654 | |
| 3655 | uint16_t oemReadingValue = 0; |
| 3656 | if (static_cast<uint8_t>(readingType) == inletAirTemp) |
| 3657 | { |
| 3658 | double value = 0; |
| 3659 | boost::system::error_code ec = ipmi::getDbusProperty( |
| 3660 | ctx, "xyz.openbmc_project.HwmonTempSensor", |
| 3661 | "/xyz/openbmc_project/sensors/temperature/Inlet_BRD_Temp", |
| 3662 | "xyz.openbmc_project.Sensor.Value", "Value", value); |
| 3663 | if (ec) |
| 3664 | { |
| 3665 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3666 | "Failed to get BMC Get OEM temperature", |
| 3667 | phosphor::logging::entry("EXCEPTION=%s", ec.message().c_str())); |
| 3668 | return ipmi::responseUnspecifiedError(); |
| 3669 | } |
| 3670 | // Take the Inlet temperature |
| 3671 | oemReadingValue = static_cast<uint16_t>(value); |
| 3672 | } |
| 3673 | else |
| 3674 | { |
| 3675 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3676 | "Currently Get OEM Reading support only for Inlet Air Temp"); |
| 3677 | return ipmi::responseParmOutOfRange(); |
| 3678 | } |
| 3679 | return ipmi::responseSuccess(domainId, readingType, oemReadingValue); |
| 3680 | } |
| 3681 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 3682 | /** @brief implements the maximum size of |
| 3683 | * bridgeable messages used between KCS and |
| 3684 | * IPMB interfacesget security mode command. |
| 3685 | * |
| 3686 | * @returns IPMI completion code with following data |
| 3687 | * - KCS Buffer Size (In multiples of four bytes) |
| 3688 | * - IPMB Buffer Size (In multiples of four bytes) |
| 3689 | **/ |
| 3690 | ipmi::RspType<uint8_t, uint8_t> ipmiOEMGetBufferSize() |
| 3691 | { |
| 3692 | // for now this is hard coded; really this number is dependent on |
| 3693 | // the BMC kcs driver as well as the host kcs driver.... |
| 3694 | // we can't know the latter. |
| 3695 | uint8_t kcsMaxBufferSize = 63 / 4; |
| 3696 | uint8_t ipmbMaxBufferSize = 128 / 4; |
| 3697 | |
| 3698 | return ipmi::responseSuccess(kcsMaxBufferSize, ipmbMaxBufferSize); |
| 3699 | } |
| 3700 | |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 3701 | static void registerOEMFunctions(void) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 3702 | { |
| 3703 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 3704 | "Registering OEM commands"); |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3705 | ipmiPrintAndRegister(intel::netFnGeneral, |
| 3706 | intel::general::cmdGetChassisIdentifier, NULL, |
| 3707 | ipmiOEMGetChassisIdentifier, |
| 3708 | PRIVILEGE_USER); // get chassis identifier |
| 3709 | |
| 3710 | ipmiPrintAndRegister(intel::netFnGeneral, intel::general::cmdSetSystemGUID, |
| 3711 | NULL, ipmiOEMSetSystemGUID, |
| 3712 | PRIVILEGE_ADMIN); // set system guid |
Jason M. Bills | b02bf09 | 2019-08-15 13:01:56 -0700 | [diff] [blame] | 3713 | |
| 3714 | // <Disable BMC System Reset Action> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3715 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3716 | intel::general::cmdDisableBMCSystemReset, Privilege::Admin, |
| 3717 | ipmiOEMDisableBMCSystemReset); |
| 3718 | |
Jason M. Bills | b02bf09 | 2019-08-15 13:01:56 -0700 | [diff] [blame] | 3719 | // <Get BMC Reset Disables> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3720 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3721 | intel::general::cmdGetBMCResetDisables, Privilege::Admin, |
| 3722 | ipmiOEMGetBMCResetDisables); |
Jason M. Bills | b02bf09 | 2019-08-15 13:01:56 -0700 | [diff] [blame] | 3723 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3724 | ipmiPrintAndRegister(intel::netFnGeneral, intel::general::cmdSetBIOSID, |
| 3725 | NULL, ipmiOEMSetBIOSID, PRIVILEGE_ADMIN); |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 3726 | |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 3727 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3728 | intel::general::cmdGetOEMDeviceInfo, Privilege::User, |
| 3729 | ipmiOEMGetDeviceInfo); |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 3730 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3731 | ipmiPrintAndRegister(intel::netFnGeneral, |
| 3732 | intel::general::cmdGetAICSlotFRUIDSlotPosRecords, NULL, |
| 3733 | ipmiOEMGetAICFRU, PRIVILEGE_USER); |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 3734 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3735 | registerHandler(prioOpenBmcBase, intel::netFnGeneral, |
| 3736 | intel::general::cmdSendEmbeddedFWUpdStatus, |
| 3737 | Privilege::Operator, ipmiOEMSendEmbeddedFwUpdStatus); |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 3738 | |
Rajashekar Gade Reddy | 2b664d5 | 2020-03-23 22:09:00 +0530 | [diff] [blame] | 3739 | registerHandler(prioOpenBmcBase, intel::netFnApp, intel::app::cmdSlotIpmb, |
| 3740 | Privilege::Admin, ipmiOEMSlotIpmb); |
| 3741 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3742 | ipmiPrintAndRegister(intel::netFnGeneral, |
| 3743 | intel::general::cmdSetPowerRestoreDelay, NULL, |
| 3744 | ipmiOEMSetPowerRestoreDelay, PRIVILEGE_OPERATOR); |
| 3745 | |
| 3746 | ipmiPrintAndRegister(intel::netFnGeneral, |
| 3747 | intel::general::cmdGetPowerRestoreDelay, NULL, |
| 3748 | ipmiOEMGetPowerRestoreDelay, PRIVILEGE_USER); |
| 3749 | |
| 3750 | registerHandler(prioOpenBmcBase, intel::netFnGeneral, |
| 3751 | intel::general::cmdSetOEMUser2Activation, |
| 3752 | Privilege::Callback, ipmiOEMSetUser2Activation); |
| 3753 | |
| 3754 | registerHandler(prioOpenBmcBase, intel::netFnGeneral, |
| 3755 | intel::general::cmdSetSpecialUserPassword, |
| 3756 | Privilege::Callback, ipmiOEMSetSpecialUserPassword); |
Richard Marian Thomaiyar | fc5e985 | 2019-04-14 15:06:27 +0530 | [diff] [blame] | 3757 | |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 3758 | // <Get Processor Error Config> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3759 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3760 | intel::general::cmdGetProcessorErrConfig, Privilege::User, |
| 3761 | ipmiOEMGetProcessorErrConfig); |
| 3762 | |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 3763 | // <Set Processor Error Config> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3764 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3765 | intel::general::cmdSetProcessorErrConfig, Privilege::Admin, |
| 3766 | ipmiOEMSetProcessorErrConfig); |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 3767 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3768 | ipmiPrintAndRegister(intel::netFnGeneral, |
| 3769 | intel::general::cmdSetShutdownPolicy, NULL, |
| 3770 | ipmiOEMSetShutdownPolicy, PRIVILEGE_ADMIN); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 3771 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3772 | ipmiPrintAndRegister(intel::netFnGeneral, |
| 3773 | intel::general::cmdGetShutdownPolicy, NULL, |
| 3774 | ipmiOEMGetShutdownPolicy, PRIVILEGE_ADMIN); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 3775 | |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 3776 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3777 | intel::general::cmdSetFanConfig, Privilege::User, |
| 3778 | ipmiOEMSetFanConfig); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 3779 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3780 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3781 | intel::general::cmdGetFanConfig, Privilege::User, |
| 3782 | ipmiOEMGetFanConfig); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 3783 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3784 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3785 | intel::general::cmdGetFanSpeedOffset, Privilege::User, |
| 3786 | ipmiOEMGetFanSpeedOffset); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 3787 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3788 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3789 | intel::general::cmdSetFanSpeedOffset, Privilege::User, |
| 3790 | ipmiOEMSetFanSpeedOffset); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 3791 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3792 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3793 | intel::general::cmdSetFscParameter, Privilege::User, |
| 3794 | ipmiOEMSetFscParameter); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 3795 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3796 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3797 | intel::general::cmdGetFscParameter, Privilege::User, |
| 3798 | ipmiOEMGetFscParameter); |
Richard Marian Thomaiyar | ea537d5 | 2019-04-24 21:33:48 +0530 | [diff] [blame] | 3799 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3800 | registerHandler(prioOpenBmcBase, intel::netFnGeneral, |
| 3801 | intel::general::cmdReadBaseBoardProductId, Privilege::Admin, |
| 3802 | ipmiOEMReadBoardProductId); |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 3803 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3804 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3805 | intel::general::cmdGetNmiStatus, Privilege::User, |
| 3806 | ipmiOEMGetNmiSource); |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 3807 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3808 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3809 | intel::general::cmdSetNmiStatus, Privilege::Operator, |
| 3810 | ipmiOEMSetNmiSource); |
Chen,Yugang | 4f7e76b | 2019-08-20 09:28:06 +0800 | [diff] [blame] | 3811 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3812 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3813 | intel::general::cmdGetEfiBootOptions, Privilege::User, |
| 3814 | ipmiOemGetEfiBootOptions); |
Chen,Yugang | 4f7e76b | 2019-08-20 09:28:06 +0800 | [diff] [blame] | 3815 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3816 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3817 | intel::general::cmdSetEfiBootOptions, Privilege::Operator, |
| 3818 | ipmiOemSetEfiBootOptions); |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 3819 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3820 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3821 | intel::general::cmdGetSecurityMode, Privilege::User, |
| 3822 | ipmiGetSecurityMode); |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 3823 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3824 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3825 | intel::general::cmdSetSecurityMode, Privilege::Admin, |
| 3826 | ipmiSetSecurityMode); |
Vernon Mauery | 4ac799d | 2019-05-20 15:50:37 -0700 | [diff] [blame] | 3827 | |
NITIN SHARMA | abd11ca | 2019-06-12 12:31:42 +0000 | [diff] [blame] | 3828 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3829 | intel::general::cmdGetLEDStatus, Privilege::Admin, |
| 3830 | ipmiOEMGetLEDStatus); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 3831 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3832 | ipmiPrintAndRegister(ipmi::intel::netFnPlatform, |
| 3833 | ipmi::intel::platform::cmdCfgHostSerialPortSpeed, NULL, |
| 3834 | ipmiOEMCfgHostSerialPortSpeed, PRIVILEGE_ADMIN); |
| 3835 | |
| 3836 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3837 | intel::general::cmdSetFaultIndication, Privilege::Operator, |
| 3838 | ipmiOEMSetFaultIndication); |
| 3839 | |
| 3840 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3841 | intel::general::cmdSetColdRedundancyConfig, Privilege::User, |
| 3842 | ipmiOEMSetCRConfig); |
| 3843 | |
| 3844 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3845 | intel::general::cmdGetColdRedundancyConfig, Privilege::User, |
| 3846 | ipmiOEMGetCRConfig); |
| 3847 | |
| 3848 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3849 | intel::general::cmdRestoreConfiguration, Privilege::Admin, |
Vernon Mauery | 4ac799d | 2019-05-20 15:50:37 -0700 | [diff] [blame] | 3850 | ipmiRestoreConfiguration); |
James Feist | 63efafa | 2019-07-24 12:39:21 -0700 | [diff] [blame] | 3851 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3852 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3853 | intel::general::cmdSetDimmOffset, Privilege::Operator, |
| 3854 | ipmiOEMSetDimmOffset); |
James Feist | 63efafa | 2019-07-24 12:39:21 -0700 | [diff] [blame] | 3855 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3856 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3857 | intel::general::cmdGetDimmOffset, Privilege::Operator, |
| 3858 | ipmiOEMGetDimmOffset); |
Chen Yugang | ca12a7b | 2019-09-03 18:11:44 +0800 | [diff] [blame] | 3859 | |
Cheng C Yang | 4e6ee15 | 2019-09-25 10:27:44 +0800 | [diff] [blame] | 3860 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3861 | intel::general::cmdGetPSUVersion, Privilege::User, |
| 3862 | ipmiOEMGetPSUVersion); |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 3863 | |
| 3864 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3865 | intel::general::cmdGetBufferSize, Privilege::User, |
| 3866 | ipmiOEMGetBufferSize); |
srikanta mondal | 2030d7c | 2020-05-03 17:25:25 +0000 | [diff] [blame] | 3867 | |
| 3868 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3869 | intel::general::cmdOEMGetReading, Privilege::User, |
| 3870 | ipmiOEMGetReading); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 3871 | } |
| 3872 | |
| 3873 | } // namespace ipmi |