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