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(); |
Yong Li | 2742b85 | 2019-12-16 14:55:11 +0800 | [diff] [blame] | 288 | std::string service = getService(*dbus, biosVersionIntf, biosObjPath); |
| 289 | setDbusProperty(*dbus, service, biosObjPath, biosVersionIntf, |
| 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 = |
| 366 | getService(*dbus, biosVersionIntf, biosObjPath); |
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 = |
| 370 | getDbusProperty(*dbus, service, biosObjPath, |
| 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 | |
| 1091 | if (ipmi::ccSuccess == |
| 1092 | ipmiUserSetUserName(ipmiDefaultUserId, |
| 1093 | reinterpret_cast<const char*>(userName.data()))) |
| 1094 | { |
| 1095 | if (ipmi::ccSuccess == |
| 1096 | ipmiUserSetUserPassword( |
| 1097 | ipmiDefaultUserId, |
| 1098 | reinterpret_cast<const char*>(userPassword.data()))) |
| 1099 | { |
| 1100 | if (ipmi::ccSuccess == |
| 1101 | ipmiUserSetPrivilegeAccess( |
| 1102 | ipmiDefaultUserId, |
| 1103 | static_cast<uint8_t>(ipmi::EChannelID::chanLan1), |
| 1104 | privAccess, true)) |
| 1105 | { |
| 1106 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 1107 | "ipmiOEMSetUser2Activation: user created successfully "); |
| 1108 | return ipmi::responseSuccess(); |
| 1109 | } |
| 1110 | } |
| 1111 | // we need to delete the default user id which added in this command as |
| 1112 | // password / priv setting is failed. |
| 1113 | ipmiUserSetUserName(ipmiDefaultUserId, ""); |
| 1114 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1115 | "ipmiOEMSetUser2Activation: password / priv setting is failed."); |
| 1116 | } |
| 1117 | else |
| 1118 | { |
| 1119 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1120 | "ipmiOEMSetUser2Activation: Setting username failed."); |
| 1121 | } |
| 1122 | |
| 1123 | return ipmi::response(ipmi::ccCommandNotAvailable); |
| 1124 | } |
| 1125 | |
Suryakanth Sekar | 822b0b4 | 2019-11-15 18:32:53 +0530 | [diff] [blame] | 1126 | /** @brief implementes executing the linux command |
| 1127 | * @param[in] linux command |
| 1128 | * @returns status |
| 1129 | */ |
| 1130 | |
| 1131 | static uint8_t executeCmd(const char* path) |
| 1132 | { |
| 1133 | boost::process::child execProg(path); |
| 1134 | execProg.wait(); |
| 1135 | |
| 1136 | int retCode = execProg.exit_code(); |
| 1137 | if (retCode) |
| 1138 | { |
| 1139 | return ipmi::ccUnspecifiedError; |
| 1140 | } |
| 1141 | return ipmi::ccSuccess; |
| 1142 | } |
| 1143 | |
| 1144 | /** @brief implementes ASD Security event logging |
| 1145 | * @param[in] Event message string |
| 1146 | * @param[in] Event Severity |
| 1147 | * @returns status |
| 1148 | */ |
| 1149 | |
| 1150 | static void atScaleDebugEventlog(std::string msg, int severity) |
| 1151 | { |
| 1152 | std::string eventStr = "OpenBMC.0.1." + msg; |
| 1153 | sd_journal_send("MESSAGE=Security Event: %s", eventStr.c_str(), |
| 1154 | "PRIORITY=%i", severity, "REDFISH_MESSAGE_ID=%s", |
| 1155 | eventStr.c_str(), NULL); |
| 1156 | } |
| 1157 | |
Richard Marian Thomaiyar | fc5e985 | 2019-04-14 15:06:27 +0530 | [diff] [blame] | 1158 | /** @brief implementes setting password for special user |
| 1159 | * @param[in] specialUserIndex |
| 1160 | * @param[in] userPassword - new password in 20 bytes |
| 1161 | * @returns ipmi completion code. |
| 1162 | */ |
| 1163 | ipmi::RspType<> ipmiOEMSetSpecialUserPassword(ipmi::Context::ptr ctx, |
| 1164 | uint8_t specialUserIndex, |
| 1165 | std::vector<uint8_t> userPassword) |
| 1166 | { |
| 1167 | ChannelInfo chInfo; |
Suryakanth Sekar | 822b0b4 | 2019-11-15 18:32:53 +0530 | [diff] [blame] | 1168 | ipmi_ret_t status = ipmi::ccSuccess; |
| 1169 | |
Richard Marian Thomaiyar | fc5e985 | 2019-04-14 15:06:27 +0530 | [diff] [blame] | 1170 | try |
| 1171 | { |
| 1172 | getChannelInfo(ctx->channel, chInfo); |
| 1173 | } |
| 1174 | catch (sdbusplus::exception_t& e) |
| 1175 | { |
| 1176 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1177 | "ipmiOEMSetSpecialUserPassword: Failed to get Channel Info", |
| 1178 | phosphor::logging::entry("MSG: %s", e.description())); |
| 1179 | return ipmi::responseUnspecifiedError(); |
| 1180 | } |
| 1181 | if (chInfo.mediumType != |
| 1182 | static_cast<uint8_t>(EChannelMediumType::systemInterface)) |
| 1183 | { |
| 1184 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1185 | "ipmiOEMSetSpecialUserPassword: Error - supported only in KCS " |
| 1186 | "interface"); |
| 1187 | return ipmi::responseCommandNotAvailable(); |
| 1188 | } |
Suryakanth Sekar | 822b0b4 | 2019-11-15 18:32:53 +0530 | [diff] [blame] | 1189 | |
| 1190 | // 0 for root user and 1 for AtScaleDebug is allowed |
| 1191 | if (specialUserIndex > |
| 1192 | static_cast<uint8_t>(SpecialUserIndex::atScaleDebugUser)) |
Richard Marian Thomaiyar | fc5e985 | 2019-04-14 15:06:27 +0530 | [diff] [blame] | 1193 | { |
| 1194 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1195 | "ipmiOEMSetSpecialUserPassword: Invalid user account"); |
| 1196 | return ipmi::responseParmOutOfRange(); |
| 1197 | } |
Suryakanth Sekar | 822b0b4 | 2019-11-15 18:32:53 +0530 | [diff] [blame] | 1198 | if (userPassword.size() != 0) |
Richard Marian Thomaiyar | fc5e985 | 2019-04-14 15:06:27 +0530 | [diff] [blame] | 1199 | { |
Suryakanth Sekar | 822b0b4 | 2019-11-15 18:32:53 +0530 | [diff] [blame] | 1200 | constexpr uint8_t minPasswordSizeRequired = 6; |
| 1201 | std::string passwd; |
| 1202 | if (userPassword.size() < minPasswordSizeRequired || |
| 1203 | userPassword.size() > ipmi::maxIpmi20PasswordSize) |
| 1204 | { |
| 1205 | return ipmi::responseReqDataLenInvalid(); |
| 1206 | } |
| 1207 | passwd.assign(reinterpret_cast<const char*>(userPassword.data()), |
| 1208 | userPassword.size()); |
| 1209 | if (specialUserIndex == |
| 1210 | static_cast<uint8_t>(SpecialUserIndex::atScaleDebugUser)) |
| 1211 | { |
| 1212 | status = ipmiSetSpecialUserPassword("asdbg", passwd); |
| 1213 | |
| 1214 | atScaleDebugEventlog("AtScaleDebugSpecialUserEnabled", LOG_CRIT); |
| 1215 | } |
| 1216 | else |
| 1217 | { |
| 1218 | status = ipmiSetSpecialUserPassword("root", passwd); |
| 1219 | } |
| 1220 | return ipmi::response(status); |
Richard Marian Thomaiyar | fc5e985 | 2019-04-14 15:06:27 +0530 | [diff] [blame] | 1221 | } |
Suryakanth Sekar | 822b0b4 | 2019-11-15 18:32:53 +0530 | [diff] [blame] | 1222 | else |
| 1223 | { |
| 1224 | if (specialUserIndex == |
| 1225 | static_cast<uint8_t>(SpecialUserIndex::rootUser)) |
| 1226 | { |
| 1227 | status = executeCmd("passwd -d root"); |
| 1228 | } |
| 1229 | else |
| 1230 | { |
| 1231 | |
| 1232 | status = executeCmd("passwd -d asdbg"); |
| 1233 | |
| 1234 | if (status == 0) |
| 1235 | { |
| 1236 | atScaleDebugEventlog("AtScaleDebugSpecialUserDisabled", |
| 1237 | LOG_INFO); |
| 1238 | } |
| 1239 | } |
| 1240 | return ipmi::response(status); |
| 1241 | } |
Richard Marian Thomaiyar | fc5e985 | 2019-04-14 15:06:27 +0530 | [diff] [blame] | 1242 | } |
| 1243 | |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 1244 | namespace ledAction |
| 1245 | { |
| 1246 | using namespace sdbusplus::xyz::openbmc_project::Led::server; |
| 1247 | std::map<Physical::Action, uint8_t> actionDbusToIpmi = { |
jayaprakash Mutyala | 934ee9c | 2019-12-13 17:49:27 +0000 | [diff] [blame] | 1248 | {Physical::Action::Off, 0}, |
| 1249 | {Physical::Action::On, 2}, |
| 1250 | {Physical::Action::Blink, 1}}; |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 1251 | |
| 1252 | std::map<uint8_t, std::string> offsetObjPath = { |
| 1253 | {2, statusAmberObjPath}, {4, statusGreenObjPath}, {6, identifyLEDObjPath}}; |
| 1254 | |
| 1255 | } // namespace ledAction |
| 1256 | |
| 1257 | int8_t getLEDState(sdbusplus::bus::bus& bus, const std::string& intf, |
| 1258 | const std::string& objPath, uint8_t& state) |
| 1259 | { |
| 1260 | try |
| 1261 | { |
| 1262 | std::string service = getService(bus, intf, objPath); |
| 1263 | Value stateValue = |
| 1264 | getDbusProperty(bus, service, objPath, intf, "State"); |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 1265 | std::string strState = std::get<std::string>(stateValue); |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 1266 | state = ledAction::actionDbusToIpmi.at( |
| 1267 | sdbusplus::xyz::openbmc_project::Led::server::Physical:: |
| 1268 | convertActionFromString(strState)); |
| 1269 | } |
| 1270 | catch (sdbusplus::exception::SdBusError& e) |
| 1271 | { |
| 1272 | phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
| 1273 | return -1; |
| 1274 | } |
| 1275 | return 0; |
| 1276 | } |
| 1277 | |
NITIN SHARMA | abd11ca | 2019-06-12 12:31:42 +0000 | [diff] [blame] | 1278 | ipmi::RspType<uint8_t> ipmiOEMGetLEDStatus() |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 1279 | { |
NITIN SHARMA | abd11ca | 2019-06-12 12:31:42 +0000 | [diff] [blame] | 1280 | uint8_t ledstate = 0; |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 1281 | phosphor::logging::log<phosphor::logging::level::DEBUG>("GET led status"); |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1282 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 1283 | for (auto it = ledAction::offsetObjPath.begin(); |
| 1284 | it != ledAction::offsetObjPath.end(); ++it) |
| 1285 | { |
| 1286 | uint8_t state = 0; |
NITIN SHARMA | abd11ca | 2019-06-12 12:31:42 +0000 | [diff] [blame] | 1287 | if (getLEDState(*dbus, ledIntf, it->second, state) == -1) |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 1288 | { |
| 1289 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1290 | "oem_get_led_status: fail to get ID LED status!"); |
NITIN SHARMA | abd11ca | 2019-06-12 12:31:42 +0000 | [diff] [blame] | 1291 | return ipmi::responseUnspecifiedError(); |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 1292 | } |
NITIN SHARMA | abd11ca | 2019-06-12 12:31:42 +0000 | [diff] [blame] | 1293 | ledstate |= state << it->first; |
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 | return ipmi::responseSuccess(ledstate); |
Kuiying Wang | 45f0498 | 2018-12-26 09:23:08 +0800 | [diff] [blame] | 1296 | } |
| 1297 | |
Yong Li | 23737fe | 2019-02-19 08:49:55 +0800 | [diff] [blame] | 1298 | ipmi_ret_t ipmiOEMCfgHostSerialPortSpeed(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 1299 | ipmi_request_t request, |
| 1300 | ipmi_response_t response, |
| 1301 | ipmi_data_len_t dataLen, |
| 1302 | ipmi_context_t context) |
| 1303 | { |
| 1304 | CfgHostSerialReq* req = reinterpret_cast<CfgHostSerialReq*>(request); |
| 1305 | uint8_t* resp = reinterpret_cast<uint8_t*>(response); |
| 1306 | |
| 1307 | if (*dataLen == 0) |
| 1308 | { |
| 1309 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1310 | "CfgHostSerial: invalid input len!", |
| 1311 | phosphor::logging::entry("LEN=%d", *dataLen)); |
| 1312 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 1313 | } |
| 1314 | |
| 1315 | switch (req->command) |
| 1316 | { |
| 1317 | case getHostSerialCfgCmd: |
| 1318 | { |
| 1319 | if (*dataLen != 1) |
| 1320 | { |
| 1321 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1322 | "CfgHostSerial: invalid input len!"); |
| 1323 | *dataLen = 0; |
| 1324 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 1325 | } |
| 1326 | |
| 1327 | *dataLen = 0; |
| 1328 | |
| 1329 | boost::process::ipstream is; |
| 1330 | std::vector<std::string> data; |
| 1331 | std::string line; |
| 1332 | boost::process::child c1(fwGetEnvCmd, "-n", fwHostSerailCfgEnvName, |
| 1333 | boost::process::std_out > is); |
| 1334 | |
| 1335 | while (c1.running() && std::getline(is, line) && !line.empty()) |
| 1336 | { |
| 1337 | data.push_back(line); |
| 1338 | } |
| 1339 | |
| 1340 | c1.wait(); |
| 1341 | if (c1.exit_code()) |
| 1342 | { |
| 1343 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1344 | "CfgHostSerial:: error on execute", |
| 1345 | phosphor::logging::entry("EXECUTE=%s", fwSetEnvCmd)); |
| 1346 | // Using the default value |
| 1347 | *resp = 0; |
| 1348 | } |
| 1349 | else |
| 1350 | { |
| 1351 | if (data.size() != 1) |
| 1352 | { |
| 1353 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1354 | "CfgHostSerial:: error on read env"); |
| 1355 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 1356 | } |
| 1357 | try |
| 1358 | { |
| 1359 | unsigned long tmp = std::stoul(data[0]); |
| 1360 | if (tmp > std::numeric_limits<uint8_t>::max()) |
| 1361 | { |
| 1362 | throw std::out_of_range("Out of range"); |
| 1363 | } |
| 1364 | *resp = static_cast<uint8_t>(tmp); |
| 1365 | } |
| 1366 | catch (const std::invalid_argument& e) |
| 1367 | { |
| 1368 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1369 | "invalid config ", |
| 1370 | phosphor::logging::entry("ERR=%s", e.what())); |
| 1371 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 1372 | } |
| 1373 | catch (const std::out_of_range& e) |
| 1374 | { |
| 1375 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1376 | "out_of_range config ", |
| 1377 | phosphor::logging::entry("ERR=%s", e.what())); |
| 1378 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 1379 | } |
| 1380 | } |
| 1381 | |
| 1382 | *dataLen = 1; |
| 1383 | break; |
| 1384 | } |
| 1385 | case setHostSerialCfgCmd: |
| 1386 | { |
| 1387 | if (*dataLen != sizeof(CfgHostSerialReq)) |
| 1388 | { |
| 1389 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1390 | "CfgHostSerial: invalid input len!"); |
| 1391 | *dataLen = 0; |
| 1392 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 1393 | } |
| 1394 | |
| 1395 | *dataLen = 0; |
| 1396 | |
| 1397 | if (req->parameter > HostSerialCfgParamMax) |
| 1398 | { |
| 1399 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1400 | "CfgHostSerial: invalid input!"); |
| 1401 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 1402 | } |
| 1403 | |
| 1404 | boost::process::child c1(fwSetEnvCmd, fwHostSerailCfgEnvName, |
| 1405 | std::to_string(req->parameter)); |
| 1406 | |
| 1407 | c1.wait(); |
| 1408 | if (c1.exit_code()) |
| 1409 | { |
| 1410 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1411 | "CfgHostSerial:: error on execute", |
| 1412 | phosphor::logging::entry("EXECUTE=%s", fwGetEnvCmd)); |
| 1413 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 1414 | } |
| 1415 | break; |
| 1416 | } |
| 1417 | default: |
| 1418 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1419 | "CfgHostSerial: invalid input!"); |
| 1420 | *dataLen = 0; |
| 1421 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 1422 | } |
| 1423 | |
| 1424 | return IPMI_CC_OK; |
| 1425 | } |
| 1426 | |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1427 | constexpr const char* thermalModeInterface = |
| 1428 | "xyz.openbmc_project.Control.ThermalMode"; |
| 1429 | constexpr const char* thermalModePath = |
| 1430 | "/xyz/openbmc_project/control/thermal_mode"; |
| 1431 | |
| 1432 | bool getFanProfileInterface( |
| 1433 | sdbusplus::bus::bus& bus, |
| 1434 | boost::container::flat_map< |
| 1435 | std::string, std::variant<std::vector<std::string>, std::string>>& resp) |
| 1436 | { |
| 1437 | auto call = bus.new_method_call(settingsBusName, thermalModePath, PROP_INTF, |
| 1438 | "GetAll"); |
| 1439 | call.append(thermalModeInterface); |
| 1440 | try |
| 1441 | { |
| 1442 | auto data = bus.call(call); |
| 1443 | data.read(resp); |
| 1444 | } |
| 1445 | catch (sdbusplus::exception_t& e) |
| 1446 | { |
| 1447 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1448 | "getFanProfileInterface: can't get thermal mode!", |
| 1449 | phosphor::logging::entry("ERR=%s", e.what())); |
| 1450 | return false; |
| 1451 | } |
| 1452 | return true; |
| 1453 | } |
| 1454 | |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 1455 | /**@brief implements the OEM set fan config. |
| 1456 | * @param selectedFanProfile - fan profile to enable |
| 1457 | * @param reserved1 |
| 1458 | * @param performanceMode - Performance/Acoustic mode |
| 1459 | * @param reserved2 |
| 1460 | * @param setPerformanceMode - set Performance/Acoustic mode |
| 1461 | * @param setFanProfile - set fan profile |
| 1462 | * |
| 1463 | * @return IPMI completion code. |
| 1464 | **/ |
| 1465 | ipmi::RspType<> ipmiOEMSetFanConfig(uint8_t selectedFanProfile, |
| 1466 | |
| 1467 | uint2_t reserved1, bool performanceMode, |
| 1468 | uint3_t reserved2, bool setPerformanceMode, |
Joshi-Mansi | 619186d | 2020-01-27 19:16:03 +0530 | [diff] [blame] | 1469 | bool setFanProfile, |
| 1470 | std::optional<uint8_t> dimmGroupId, |
| 1471 | std::optional<uint32_t> dimmPresenceBitmap) |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1472 | { |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 1473 | if (reserved1 || reserved2) |
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 | return ipmi::responseInvalidFieldRequest(); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1476 | } |
Joshi-Mansi | 619186d | 2020-01-27 19:16:03 +0530 | [diff] [blame] | 1477 | |
| 1478 | if (dimmGroupId) |
| 1479 | { |
| 1480 | if (*dimmGroupId >= maxCPUNum) |
| 1481 | { |
| 1482 | return ipmi::responseInvalidFieldRequest(); |
| 1483 | } |
| 1484 | if (!cpuPresent("CPU_" + std::to_string(*dimmGroupId + 1))) |
| 1485 | { |
| 1486 | return ipmi::responseInvalidFieldRequest(); |
| 1487 | } |
| 1488 | } |
| 1489 | |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1490 | // todo: tell bios to only send first 2 bytes |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1491 | boost::container::flat_map< |
| 1492 | std::string, std::variant<std::vector<std::string>, std::string>> |
| 1493 | profileData; |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1494 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 1495 | if (!getFanProfileInterface(*dbus, profileData)) |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1496 | { |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 1497 | return ipmi::responseUnspecifiedError(); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | std::vector<std::string>* supported = |
| 1501 | std::get_if<std::vector<std::string>>(&profileData["Supported"]); |
| 1502 | if (supported == nullptr) |
| 1503 | { |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 1504 | return ipmi::responseInvalidFieldRequest(); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1505 | } |
| 1506 | std::string mode; |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 1507 | if (setPerformanceMode) |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1508 | { |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1509 | if (performanceMode) |
| 1510 | { |
| 1511 | |
| 1512 | if (std::find(supported->begin(), supported->end(), |
| 1513 | "Performance") != supported->end()) |
| 1514 | { |
| 1515 | mode = "Performance"; |
| 1516 | } |
| 1517 | } |
| 1518 | else |
| 1519 | { |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1520 | if (std::find(supported->begin(), supported->end(), "Acoustic") != |
| 1521 | supported->end()) |
| 1522 | { |
| 1523 | mode = "Acoustic"; |
| 1524 | } |
| 1525 | } |
| 1526 | if (mode.empty()) |
| 1527 | { |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 1528 | return ipmi::responseInvalidFieldRequest(); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1529 | } |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 1530 | |
| 1531 | try |
| 1532 | { |
| 1533 | setDbusProperty(*dbus, settingsBusName, thermalModePath, |
| 1534 | thermalModeInterface, "Current", mode); |
| 1535 | } |
| 1536 | catch (sdbusplus::exception_t& e) |
| 1537 | { |
| 1538 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1539 | "ipmiOEMSetFanConfig: can't set thermal mode!", |
| 1540 | phosphor::logging::entry("EXCEPTION=%s", e.what())); |
| 1541 | return ipmi::responseResponseError(); |
| 1542 | } |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1543 | } |
| 1544 | |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 1545 | return ipmi::responseSuccess(); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1546 | } |
| 1547 | |
James Feist | 5b69363 | 2019-07-09 09:06:09 -0700 | [diff] [blame] | 1548 | ipmi::RspType<uint8_t, // profile support map |
| 1549 | uint8_t, // fan control profile enable |
| 1550 | uint8_t, // flags |
| 1551 | uint32_t // dimm presence bit map |
| 1552 | > |
| 1553 | ipmiOEMGetFanConfig(uint8_t dimmGroupId) |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1554 | { |
Joshi-Mansi | 36f05ce | 2020-01-14 14:29:34 +0530 | [diff] [blame] | 1555 | if (dimmGroupId >= maxCPUNum) |
| 1556 | { |
| 1557 | return ipmi::responseInvalidFieldRequest(); |
| 1558 | } |
| 1559 | |
| 1560 | bool cpuStatus = cpuPresent("CPU_" + std::to_string(dimmGroupId + 1)); |
| 1561 | |
| 1562 | if (!cpuStatus) |
| 1563 | { |
| 1564 | return ipmi::responseInvalidFieldRequest(); |
| 1565 | } |
| 1566 | |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1567 | boost::container::flat_map< |
| 1568 | std::string, std::variant<std::vector<std::string>, std::string>> |
| 1569 | profileData; |
| 1570 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1571 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 1572 | if (!getFanProfileInterface(*dbus, profileData)) |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1573 | { |
James Feist | 5b69363 | 2019-07-09 09:06:09 -0700 | [diff] [blame] | 1574 | return ipmi::responseResponseError(); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1575 | } |
| 1576 | |
| 1577 | std::string* current = std::get_if<std::string>(&profileData["Current"]); |
| 1578 | |
| 1579 | if (current == nullptr) |
| 1580 | { |
| 1581 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1582 | "ipmiOEMGetFanConfig: can't get current mode!"); |
James Feist | 5b69363 | 2019-07-09 09:06:09 -0700 | [diff] [blame] | 1583 | return ipmi::responseResponseError(); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1584 | } |
| 1585 | bool performance = (*current == "Performance"); |
| 1586 | |
James Feist | 5b69363 | 2019-07-09 09:06:09 -0700 | [diff] [blame] | 1587 | uint8_t flags = 0; |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1588 | if (performance) |
| 1589 | { |
James Feist | 5b69363 | 2019-07-09 09:06:09 -0700 | [diff] [blame] | 1590 | flags |= 1 << 2; |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1591 | } |
| 1592 | |
jayaprakash Mutyala | 4b1552d | 2020-02-11 12:07:29 +0000 | [diff] [blame] | 1593 | constexpr uint8_t fanControlDefaultProfile = 0x80; |
| 1594 | constexpr uint8_t fanControlProfileState = 0x00; |
| 1595 | constexpr uint32_t dimmPresenceBitmap = 0x00; |
| 1596 | |
| 1597 | return ipmi::responseSuccess(fanControlDefaultProfile, |
| 1598 | fanControlProfileState, flags, |
| 1599 | dimmPresenceBitmap); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 1600 | } |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1601 | constexpr const char* cfmLimitSettingPath = |
| 1602 | "/xyz/openbmc_project/control/cfm_limit"; |
| 1603 | constexpr const char* cfmLimitIface = "xyz.openbmc_project.Control.CFMLimit"; |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1604 | constexpr const size_t legacyExitAirSensorNumber = 0x2e; |
James Feist | 09f6b60 | 2019-08-08 11:30:03 -0700 | [diff] [blame] | 1605 | constexpr const size_t legacyPCHSensorNumber = 0x22; |
| 1606 | constexpr const char* exitAirPathName = "Exit_Air"; |
| 1607 | constexpr const char* pchPathName = "SSB_Temp"; |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1608 | constexpr const char* pidConfigurationIface = |
| 1609 | "xyz.openbmc_project.Configuration.Pid"; |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1610 | |
James Feist | 09f6b60 | 2019-08-08 11:30:03 -0700 | [diff] [blame] | 1611 | static std::string getConfigPath(const std::string& name) |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1612 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1613 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1614 | auto method = |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1615 | dbus->new_method_call("xyz.openbmc_project.ObjectMapper", |
| 1616 | "/xyz/openbmc_project/object_mapper", |
| 1617 | "xyz.openbmc_project.ObjectMapper", "GetSubTree"); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1618 | |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1619 | method.append("/", 0, std::array<const char*, 1>{pidConfigurationIface}); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1620 | std::string path; |
| 1621 | GetSubTreeType resp; |
| 1622 | try |
| 1623 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1624 | auto reply = dbus->call(method); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1625 | reply.read(resp); |
| 1626 | } |
| 1627 | catch (sdbusplus::exception_t&) |
| 1628 | { |
| 1629 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1630 | "ipmiOEMGetFscParameter: mapper error"); |
| 1631 | }; |
James Feist | 09f6b60 | 2019-08-08 11:30:03 -0700 | [diff] [blame] | 1632 | auto config = |
| 1633 | std::find_if(resp.begin(), resp.end(), [&name](const auto& pair) { |
| 1634 | return pair.first.find(name) != std::string::npos; |
| 1635 | }); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1636 | if (config != resp.end()) |
| 1637 | { |
| 1638 | path = std::move(config->first); |
| 1639 | } |
| 1640 | return path; |
| 1641 | } |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1642 | |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1643 | // flat map to make alphabetical |
| 1644 | static boost::container::flat_map<std::string, PropertyMap> getPidConfigs() |
| 1645 | { |
| 1646 | boost::container::flat_map<std::string, PropertyMap> ret; |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1647 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1648 | auto method = |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1649 | dbus->new_method_call("xyz.openbmc_project.ObjectMapper", |
| 1650 | "/xyz/openbmc_project/object_mapper", |
| 1651 | "xyz.openbmc_project.ObjectMapper", "GetSubTree"); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1652 | |
| 1653 | method.append("/", 0, std::array<const char*, 1>{pidConfigurationIface}); |
| 1654 | GetSubTreeType resp; |
| 1655 | |
| 1656 | try |
| 1657 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1658 | auto reply = dbus->call(method); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1659 | reply.read(resp); |
| 1660 | } |
| 1661 | catch (sdbusplus::exception_t&) |
| 1662 | { |
| 1663 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1664 | "getFanConfigPaths: mapper error"); |
| 1665 | }; |
| 1666 | for (const auto& [path, objects] : resp) |
| 1667 | { |
| 1668 | if (objects.empty()) |
| 1669 | { |
| 1670 | continue; // should be impossible |
| 1671 | } |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 1672 | |
| 1673 | try |
| 1674 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1675 | ret.emplace(path, |
| 1676 | getAllDbusProperties(*dbus, objects[0].first, path, |
| 1677 | pidConfigurationIface)); |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 1678 | } |
| 1679 | catch (sdbusplus::exception_t& e) |
| 1680 | { |
| 1681 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1682 | "getPidConfigs: can't get DbusProperties!", |
| 1683 | phosphor::logging::entry("ERR=%s", e.what())); |
| 1684 | } |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1685 | } |
| 1686 | return ret; |
| 1687 | } |
| 1688 | |
| 1689 | ipmi::RspType<uint8_t> ipmiOEMGetFanSpeedOffset(void) |
| 1690 | { |
| 1691 | boost::container::flat_map<std::string, PropertyMap> data = getPidConfigs(); |
| 1692 | if (data.empty()) |
| 1693 | { |
| 1694 | return ipmi::responseResponseError(); |
| 1695 | } |
| 1696 | uint8_t minOffset = std::numeric_limits<uint8_t>::max(); |
| 1697 | for (const auto& [_, pid] : data) |
| 1698 | { |
| 1699 | auto findClass = pid.find("Class"); |
| 1700 | if (findClass == pid.end()) |
| 1701 | { |
| 1702 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1703 | "ipmiOEMGetFscParameter: found illegal pid " |
| 1704 | "configurations"); |
| 1705 | return ipmi::responseResponseError(); |
| 1706 | } |
| 1707 | std::string type = std::get<std::string>(findClass->second); |
| 1708 | if (type == "fan") |
| 1709 | { |
| 1710 | auto findOutLimit = pid.find("OutLimitMin"); |
| 1711 | if (findOutLimit == pid.end()) |
| 1712 | { |
| 1713 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1714 | "ipmiOEMGetFscParameter: found illegal pid " |
| 1715 | "configurations"); |
| 1716 | return ipmi::responseResponseError(); |
| 1717 | } |
| 1718 | // get the min out of all the offsets |
| 1719 | minOffset = std::min( |
| 1720 | minOffset, |
| 1721 | static_cast<uint8_t>(std::get<double>(findOutLimit->second))); |
| 1722 | } |
| 1723 | } |
| 1724 | if (minOffset == std::numeric_limits<uint8_t>::max()) |
| 1725 | { |
| 1726 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1727 | "ipmiOEMGetFscParameter: found no fan configurations!"); |
| 1728 | return ipmi::responseResponseError(); |
| 1729 | } |
| 1730 | |
| 1731 | return ipmi::responseSuccess(minOffset); |
| 1732 | } |
| 1733 | |
| 1734 | ipmi::RspType<> ipmiOEMSetFanSpeedOffset(uint8_t offset) |
| 1735 | { |
| 1736 | boost::container::flat_map<std::string, PropertyMap> data = getPidConfigs(); |
| 1737 | if (data.empty()) |
| 1738 | { |
| 1739 | |
| 1740 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1741 | "ipmiOEMSetFanSpeedOffset: found no pid configurations!"); |
| 1742 | return ipmi::responseResponseError(); |
| 1743 | } |
| 1744 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1745 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1746 | bool found = false; |
| 1747 | for (const auto& [path, pid] : data) |
| 1748 | { |
| 1749 | auto findClass = pid.find("Class"); |
| 1750 | if (findClass == pid.end()) |
| 1751 | { |
| 1752 | |
| 1753 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1754 | "ipmiOEMSetFanSpeedOffset: found illegal pid " |
| 1755 | "configurations"); |
| 1756 | return ipmi::responseResponseError(); |
| 1757 | } |
| 1758 | std::string type = std::get<std::string>(findClass->second); |
| 1759 | if (type == "fan") |
| 1760 | { |
| 1761 | auto findOutLimit = pid.find("OutLimitMin"); |
| 1762 | if (findOutLimit == pid.end()) |
| 1763 | { |
| 1764 | |
| 1765 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1766 | "ipmiOEMSetFanSpeedOffset: found illegal pid " |
| 1767 | "configurations"); |
| 1768 | return ipmi::responseResponseError(); |
| 1769 | } |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1770 | ipmi::setDbusProperty(*dbus, "xyz.openbmc_project.EntityManager", |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1771 | path, pidConfigurationIface, "OutLimitMin", |
| 1772 | static_cast<double>(offset)); |
| 1773 | found = true; |
| 1774 | } |
| 1775 | } |
| 1776 | if (!found) |
| 1777 | { |
| 1778 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1779 | "ipmiOEMSetFanSpeedOffset: set no fan offsets"); |
| 1780 | return ipmi::responseResponseError(); |
| 1781 | } |
| 1782 | |
| 1783 | return ipmi::responseSuccess(); |
| 1784 | } |
| 1785 | |
| 1786 | ipmi::RspType<> ipmiOEMSetFscParameter(uint8_t command, uint8_t param1, |
| 1787 | uint8_t param2) |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1788 | { |
| 1789 | constexpr const size_t disableLimiting = 0x0; |
| 1790 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1791 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1792 | if (command == static_cast<uint8_t>(setFscParamFlags::tcontrol)) |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1793 | { |
James Feist | 09f6b60 | 2019-08-08 11:30:03 -0700 | [diff] [blame] | 1794 | std::string pathName; |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1795 | if (param1 == legacyExitAirSensorNumber) |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1796 | { |
James Feist | 09f6b60 | 2019-08-08 11:30:03 -0700 | [diff] [blame] | 1797 | pathName = exitAirPathName; |
| 1798 | } |
| 1799 | else if (param1 == legacyPCHSensorNumber) |
| 1800 | { |
| 1801 | pathName = pchPathName; |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1802 | } |
| 1803 | else |
| 1804 | { |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1805 | return ipmi::responseParmOutOfRange(); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1806 | } |
James Feist | 09f6b60 | 2019-08-08 11:30:03 -0700 | [diff] [blame] | 1807 | std::string path = getConfigPath(pathName); |
| 1808 | ipmi::setDbusProperty(*dbus, "xyz.openbmc_project.EntityManager", path, |
| 1809 | pidConfigurationIface, "SetPoint", |
| 1810 | static_cast<double>(param2)); |
| 1811 | return ipmi::responseSuccess(); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1812 | } |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1813 | else if (command == static_cast<uint8_t>(setFscParamFlags::cfm)) |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1814 | { |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1815 | uint16_t cfm = param1 | (static_cast<uint16_t>(param2) << 8); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1816 | |
| 1817 | // must be greater than 50 based on eps |
| 1818 | if (cfm < 50 && cfm != disableLimiting) |
| 1819 | { |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1820 | return ipmi::responseParmOutOfRange(); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | try |
| 1824 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1825 | ipmi::setDbusProperty(*dbus, settingsBusName, cfmLimitSettingPath, |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1826 | cfmLimitIface, "Limit", |
| 1827 | static_cast<double>(cfm)); |
| 1828 | } |
| 1829 | catch (sdbusplus::exception_t& e) |
| 1830 | { |
| 1831 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1832 | "ipmiOEMSetFscParameter: can't set cfm setting!", |
| 1833 | phosphor::logging::entry("ERR=%s", e.what())); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1834 | return ipmi::responseResponseError(); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1835 | } |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1836 | return ipmi::responseSuccess(); |
| 1837 | } |
| 1838 | else if (command == static_cast<uint8_t>(setFscParamFlags::maxPwm)) |
| 1839 | { |
| 1840 | constexpr const size_t maxDomainCount = 8; |
| 1841 | uint8_t requestedDomainMask = param1; |
| 1842 | boost::container::flat_map data = getPidConfigs(); |
| 1843 | if (data.empty()) |
| 1844 | { |
| 1845 | |
| 1846 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1847 | "ipmiOEMSetFscParameter: found no pid configurations!"); |
| 1848 | return ipmi::responseResponseError(); |
| 1849 | } |
| 1850 | size_t count = 0; |
| 1851 | for (const auto& [path, pid] : data) |
| 1852 | { |
| 1853 | auto findClass = pid.find("Class"); |
| 1854 | if (findClass == pid.end()) |
| 1855 | { |
| 1856 | |
| 1857 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1858 | "ipmiOEMSetFscParameter: found illegal pid " |
| 1859 | "configurations"); |
| 1860 | return ipmi::responseResponseError(); |
| 1861 | } |
| 1862 | std::string type = std::get<std::string>(findClass->second); |
| 1863 | if (type == "fan") |
| 1864 | { |
| 1865 | if (requestedDomainMask & (1 << count)) |
| 1866 | { |
| 1867 | ipmi::setDbusProperty( |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1868 | *dbus, "xyz.openbmc_project.EntityManager", path, |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1869 | pidConfigurationIface, "OutLimitMax", |
| 1870 | static_cast<double>(param2)); |
| 1871 | } |
| 1872 | count++; |
| 1873 | } |
| 1874 | } |
| 1875 | return ipmi::responseSuccess(); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1876 | } |
| 1877 | else |
| 1878 | { |
| 1879 | // todo other command parts possibly |
| 1880 | // tcontrol is handled in peci now |
| 1881 | // fan speed offset not implemented yet |
| 1882 | // domain pwm limit not implemented |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1883 | return ipmi::responseParmOutOfRange(); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1884 | } |
| 1885 | } |
| 1886 | |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1887 | ipmi::RspType< |
| 1888 | std::variant<uint8_t, std::array<uint8_t, 2>, std::array<uint16_t, 2>>> |
| 1889 | ipmiOEMGetFscParameter(uint8_t command, std::optional<uint8_t> param) |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1890 | { |
James Feist | 09f6b60 | 2019-08-08 11:30:03 -0700 | [diff] [blame] | 1891 | constexpr uint8_t legacyDefaultSetpoint = -128; |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1892 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1893 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1894 | if (command == static_cast<uint8_t>(setFscParamFlags::tcontrol)) |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1895 | { |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1896 | if (!param) |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1897 | { |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1898 | return ipmi::responseReqDataLenInvalid(); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1899 | } |
| 1900 | |
James Feist | 09f6b60 | 2019-08-08 11:30:03 -0700 | [diff] [blame] | 1901 | std::string pathName; |
| 1902 | |
| 1903 | if (*param == legacyExitAirSensorNumber) |
| 1904 | { |
| 1905 | pathName = exitAirPathName; |
| 1906 | } |
| 1907 | else if (*param == legacyPCHSensorNumber) |
| 1908 | { |
| 1909 | pathName = pchPathName; |
| 1910 | } |
| 1911 | else |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1912 | { |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1913 | return ipmi::responseParmOutOfRange(); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1914 | } |
James Feist | 09f6b60 | 2019-08-08 11:30:03 -0700 | [diff] [blame] | 1915 | |
| 1916 | uint8_t setpoint = legacyDefaultSetpoint; |
| 1917 | std::string path = getConfigPath(pathName); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1918 | if (path.size()) |
| 1919 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1920 | Value val = ipmi::getDbusProperty( |
| 1921 | *dbus, "xyz.openbmc_project.EntityManager", path, |
| 1922 | pidConfigurationIface, "SetPoint"); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1923 | setpoint = std::floor(std::get<double>(val) + 0.5); |
| 1924 | } |
| 1925 | |
| 1926 | // old implementation used to return the "default" and current, we |
| 1927 | // don't make the default readily available so just make both the |
| 1928 | // same |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1929 | |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1930 | return ipmi::responseSuccess( |
| 1931 | std::array<uint8_t, 2>{setpoint, setpoint}); |
James Feist | faa4f22 | 2019-03-21 16:21:55 -0700 | [diff] [blame] | 1932 | } |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 1933 | else if (command == static_cast<uint8_t>(setFscParamFlags::maxPwm)) |
| 1934 | { |
| 1935 | constexpr const size_t maxDomainCount = 8; |
| 1936 | |
| 1937 | if (!param) |
| 1938 | { |
| 1939 | return ipmi::responseReqDataLenInvalid(); |
| 1940 | } |
| 1941 | uint8_t requestedDomain = *param; |
| 1942 | if (requestedDomain >= maxDomainCount) |
| 1943 | { |
| 1944 | return ipmi::responseInvalidFieldRequest(); |
| 1945 | } |
| 1946 | |
| 1947 | boost::container::flat_map data = getPidConfigs(); |
| 1948 | if (data.empty()) |
| 1949 | { |
| 1950 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1951 | "ipmiOEMGetFscParameter: found no pid configurations!"); |
| 1952 | return ipmi::responseResponseError(); |
| 1953 | } |
| 1954 | size_t count = 0; |
| 1955 | for (const auto& [_, pid] : data) |
| 1956 | { |
| 1957 | auto findClass = pid.find("Class"); |
| 1958 | if (findClass == pid.end()) |
| 1959 | { |
| 1960 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1961 | "ipmiOEMGetFscParameter: found illegal pid " |
| 1962 | "configurations"); |
| 1963 | return ipmi::responseResponseError(); |
| 1964 | } |
| 1965 | std::string type = std::get<std::string>(findClass->second); |
| 1966 | if (type == "fan") |
| 1967 | { |
| 1968 | if (requestedDomain == count) |
| 1969 | { |
| 1970 | auto findOutLimit = pid.find("OutLimitMax"); |
| 1971 | if (findOutLimit == pid.end()) |
| 1972 | { |
| 1973 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1974 | "ipmiOEMGetFscParameter: found illegal pid " |
| 1975 | "configurations"); |
| 1976 | return ipmi::responseResponseError(); |
| 1977 | } |
| 1978 | |
| 1979 | return ipmi::responseSuccess( |
| 1980 | static_cast<uint8_t>(std::floor( |
| 1981 | std::get<double>(findOutLimit->second) + 0.5))); |
| 1982 | } |
| 1983 | else |
| 1984 | { |
| 1985 | count++; |
| 1986 | } |
| 1987 | } |
| 1988 | } |
| 1989 | |
| 1990 | return ipmi::responseInvalidFieldRequest(); |
| 1991 | } |
| 1992 | else if (command == static_cast<uint8_t>(setFscParamFlags::cfm)) |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1993 | { |
| 1994 | |
| 1995 | /* |
| 1996 | 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] | 1997 | previous behavior didn't seem to prevent this, ignore the check for |
| 1998 | now. |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 1999 | |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 2000 | if (param) |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2001 | { |
| 2002 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2003 | "ipmiOEMGetFscParameter: invalid input len!"); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2004 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 2005 | } |
| 2006 | */ |
| 2007 | Value cfmLimit; |
| 2008 | Value cfmMaximum; |
| 2009 | try |
| 2010 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 2011 | cfmLimit = ipmi::getDbusProperty(*dbus, settingsBusName, |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2012 | cfmLimitSettingPath, cfmLimitIface, |
| 2013 | "Limit"); |
| 2014 | cfmMaximum = ipmi::getDbusProperty( |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 2015 | *dbus, "xyz.openbmc_project.ExitAirTempSensor", |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2016 | "/xyz/openbmc_project/control/MaxCFM", cfmLimitIface, "Limit"); |
| 2017 | } |
| 2018 | catch (sdbusplus::exception_t& e) |
| 2019 | { |
| 2020 | phosphor::logging::log<phosphor::logging::level::ERR>( |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 2021 | "ipmiOEMGetFscParameter: can't get cfm setting!", |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2022 | phosphor::logging::entry("ERR=%s", e.what())); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 2023 | return ipmi::responseResponseError(); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2024 | } |
| 2025 | |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 2026 | double cfmMax = std::get<double>(cfmMaximum); |
| 2027 | double cfmLim = std::get<double>(cfmLimit); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2028 | |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 2029 | cfmLim = std::floor(cfmLim + 0.5); |
| 2030 | cfmMax = std::floor(cfmMax + 0.5); |
| 2031 | uint16_t cfmLimResp = static_cast<uint16_t>(cfmLim); |
| 2032 | uint16_t cfmMaxResp = static_cast<uint16_t>(cfmMax); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2033 | |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 2034 | return ipmi::responseSuccess( |
| 2035 | std::array<uint16_t, 2>{cfmLimResp, cfmMaxResp}); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2036 | } |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 2037 | |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2038 | else |
| 2039 | { |
| 2040 | // todo other command parts possibly |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2041 | // domain pwm limit not implemented |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 2042 | return ipmi::responseParmOutOfRange(); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 2043 | } |
| 2044 | } |
| 2045 | |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2046 | using crConfigVariant = |
| 2047 | std::variant<bool, uint8_t, uint32_t, std::vector<uint8_t>, std::string>; |
| 2048 | |
| 2049 | int setCRConfig(ipmi::Context::ptr ctx, const std::string& property, |
| 2050 | const crConfigVariant& value, |
| 2051 | std::chrono::microseconds timeout = ipmi::IPMI_DBUS_TIMEOUT) |
| 2052 | { |
| 2053 | boost::system::error_code ec; |
| 2054 | ctx->bus->yield_method_call<void>( |
James Feist | 28c7290 | 2019-09-16 10:34:07 -0700 | [diff] [blame] | 2055 | ctx->yield, ec, "xyz.openbmc_project.Settings", |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2056 | "/xyz/openbmc_project/control/power_supply_redundancy", |
| 2057 | "org.freedesktop.DBus.Properties", "Set", |
| 2058 | "xyz.openbmc_project.Control.PowerSupplyRedundancy", property, value); |
| 2059 | if (ec) |
| 2060 | { |
| 2061 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2062 | "Failed to set dbus property to cold redundancy"); |
| 2063 | return -1; |
| 2064 | } |
| 2065 | |
| 2066 | return 0; |
| 2067 | } |
| 2068 | |
| 2069 | int getCRConfig(ipmi::Context::ptr ctx, const std::string& property, |
| 2070 | crConfigVariant& value, |
Yong Li | 19445ab | 2019-12-20 18:25:29 +0800 | [diff] [blame] | 2071 | const std::string& service = "xyz.openbmc_project.Settings", |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2072 | std::chrono::microseconds timeout = ipmi::IPMI_DBUS_TIMEOUT) |
| 2073 | { |
| 2074 | boost::system::error_code ec; |
| 2075 | value = ctx->bus->yield_method_call<crConfigVariant>( |
Yong Li | 19445ab | 2019-12-20 18:25:29 +0800 | [diff] [blame] | 2076 | ctx->yield, ec, service, |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2077 | "/xyz/openbmc_project/control/power_supply_redundancy", |
| 2078 | "org.freedesktop.DBus.Properties", "Get", |
| 2079 | "xyz.openbmc_project.Control.PowerSupplyRedundancy", property); |
| 2080 | if (ec) |
| 2081 | { |
| 2082 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2083 | "Failed to get dbus property to cold redundancy"); |
| 2084 | return -1; |
| 2085 | } |
| 2086 | return 0; |
| 2087 | } |
| 2088 | |
| 2089 | uint8_t getPSUCount(void) |
| 2090 | { |
| 2091 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 2092 | ipmi::Value num; |
| 2093 | try |
| 2094 | { |
| 2095 | num = ipmi::getDbusProperty( |
| 2096 | *dbus, "xyz.openbmc_project.PSURedundancy", |
| 2097 | "/xyz/openbmc_project/control/power_supply_redundancy", |
| 2098 | "xyz.openbmc_project.Control.PowerSupplyRedundancy", "PSUNumber"); |
| 2099 | } |
| 2100 | catch (sdbusplus::exception_t& e) |
| 2101 | { |
| 2102 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2103 | "Failed to get PSUNumber property from dbus interface"); |
| 2104 | return 0; |
| 2105 | } |
| 2106 | uint8_t* pNum = std::get_if<uint8_t>(&num); |
| 2107 | if (!pNum) |
| 2108 | { |
| 2109 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2110 | "Error to get PSU Number"); |
| 2111 | return 0; |
| 2112 | } |
| 2113 | return *pNum; |
| 2114 | } |
| 2115 | |
| 2116 | bool validateCRAlgo(std::vector<uint8_t>& conf, uint8_t num) |
| 2117 | { |
| 2118 | if (conf.size() < num) |
| 2119 | { |
| 2120 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2121 | "Invalid PSU Ranking"); |
| 2122 | return false; |
| 2123 | } |
| 2124 | std::set<uint8_t> confSet; |
| 2125 | for (uint8_t i = 0; i < num; i++) |
| 2126 | { |
| 2127 | if (conf[i] > num) |
| 2128 | { |
| 2129 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2130 | "PSU Ranking is larger than current PSU number"); |
| 2131 | return false; |
| 2132 | } |
| 2133 | confSet.emplace(conf[i]); |
| 2134 | } |
| 2135 | |
| 2136 | if (confSet.size() != num) |
| 2137 | { |
| 2138 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2139 | "duplicate PSU Ranking"); |
| 2140 | return false; |
| 2141 | } |
| 2142 | return true; |
| 2143 | } |
| 2144 | |
| 2145 | enum class crParameter |
| 2146 | { |
| 2147 | crStatus = 0, |
| 2148 | crFeature = 1, |
| 2149 | rotationFeature = 2, |
| 2150 | rotationAlgo = 3, |
| 2151 | rotationPeriod = 4, |
Yong Li | 19445ab | 2019-12-20 18:25:29 +0800 | [diff] [blame] | 2152 | numOfPSU = 5, |
| 2153 | rotationRankOrderEffective = 6 |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2154 | }; |
| 2155 | |
| 2156 | constexpr ipmi::Cc ccParameterNotSupported = 0x80; |
| 2157 | static const constexpr uint32_t oneDay = 0x15180; |
| 2158 | static const constexpr uint32_t oneMonth = 0xf53700; |
| 2159 | static const constexpr uint8_t userSpecific = 0x01; |
| 2160 | static const constexpr uint8_t crSetCompleted = 0; |
| 2161 | ipmi::RspType<uint8_t> ipmiOEMSetCRConfig(ipmi::Context::ptr ctx, |
| 2162 | uint8_t parameter, |
| 2163 | ipmi::message::Payload& payload) |
| 2164 | { |
| 2165 | switch (static_cast<crParameter>(parameter)) |
| 2166 | { |
| 2167 | case crParameter::crFeature: |
| 2168 | { |
| 2169 | uint8_t param1; |
| 2170 | if (payload.unpack(param1) || !payload.fullyUnpacked()) |
| 2171 | { |
| 2172 | return ipmi::responseReqDataLenInvalid(); |
| 2173 | } |
| 2174 | // ColdRedundancy Enable can only be true or flase |
| 2175 | if (param1 > 1) |
| 2176 | { |
| 2177 | return ipmi::responseInvalidFieldRequest(); |
| 2178 | } |
| 2179 | if (setCRConfig(ctx, "ColdRedundancyEnabled", |
| 2180 | static_cast<bool>(param1))) |
| 2181 | { |
| 2182 | return ipmi::responseResponseError(); |
| 2183 | } |
| 2184 | break; |
| 2185 | } |
| 2186 | case crParameter::rotationFeature: |
| 2187 | { |
| 2188 | uint8_t param1; |
| 2189 | if (payload.unpack(param1) || !payload.fullyUnpacked()) |
| 2190 | { |
| 2191 | return ipmi::responseReqDataLenInvalid(); |
| 2192 | } |
| 2193 | // Rotation Enable can only be true or false |
| 2194 | if (param1 > 1) |
| 2195 | { |
| 2196 | return ipmi::responseInvalidFieldRequest(); |
| 2197 | } |
| 2198 | if (setCRConfig(ctx, "RotationEnabled", static_cast<bool>(param1))) |
| 2199 | { |
| 2200 | return ipmi::responseResponseError(); |
| 2201 | } |
| 2202 | break; |
| 2203 | } |
| 2204 | case crParameter::rotationAlgo: |
| 2205 | { |
| 2206 | // Rotation Algorithm can only be 0-BMC Specific or 1-User Specific |
| 2207 | std::string algoName; |
| 2208 | uint8_t param1; |
| 2209 | if (payload.unpack(param1)) |
| 2210 | { |
| 2211 | return ipmi::responseReqDataLenInvalid(); |
| 2212 | } |
| 2213 | switch (param1) |
| 2214 | { |
| 2215 | case 0: |
| 2216 | algoName = "xyz.openbmc_project.Control." |
| 2217 | "PowerSupplyRedundancy.Algo.bmcSpecific"; |
| 2218 | break; |
| 2219 | case 1: |
| 2220 | algoName = "xyz.openbmc_project.Control." |
| 2221 | "PowerSupplyRedundancy.Algo.userSpecific"; |
| 2222 | break; |
| 2223 | default: |
| 2224 | return ipmi::responseInvalidFieldRequest(); |
| 2225 | } |
| 2226 | if (setCRConfig(ctx, "RotationAlgorithm", algoName)) |
| 2227 | { |
| 2228 | return ipmi::responseResponseError(); |
| 2229 | } |
| 2230 | |
| 2231 | uint8_t numberOfPSU = getPSUCount(); |
| 2232 | if (!numberOfPSU) |
| 2233 | { |
| 2234 | return ipmi::responseResponseError(); |
| 2235 | } |
| 2236 | std::vector<uint8_t> rankOrder; |
| 2237 | |
| 2238 | if (param1 == userSpecific) |
| 2239 | { |
| 2240 | if (payload.unpack(rankOrder) || !payload.fullyUnpacked()) |
| 2241 | { |
| 2242 | ipmi::responseReqDataLenInvalid(); |
| 2243 | } |
Yong Li | 8331513 | 2019-10-23 17:42:24 +0800 | [diff] [blame] | 2244 | if (rankOrder.size() != numberOfPSU) |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2245 | { |
| 2246 | return ipmi::responseReqDataLenInvalid(); |
| 2247 | } |
| 2248 | |
| 2249 | if (!validateCRAlgo(rankOrder, numberOfPSU)) |
| 2250 | { |
| 2251 | return ipmi::responseInvalidFieldRequest(); |
| 2252 | } |
| 2253 | } |
| 2254 | else |
| 2255 | { |
| 2256 | if (rankOrder.size() > 0) |
| 2257 | { |
| 2258 | return ipmi::responseReqDataLenInvalid(); |
| 2259 | } |
| 2260 | for (uint8_t i = 1; i <= numberOfPSU; i++) |
| 2261 | { |
| 2262 | rankOrder.emplace_back(i); |
| 2263 | } |
| 2264 | } |
| 2265 | if (setCRConfig(ctx, "RotationRankOrder", rankOrder)) |
| 2266 | { |
| 2267 | return ipmi::responseResponseError(); |
| 2268 | } |
| 2269 | break; |
| 2270 | } |
| 2271 | case crParameter::rotationPeriod: |
| 2272 | { |
| 2273 | // Minimum Rotation period is One day (86400 seconds) and Max |
| 2274 | // Rotation Period is 6 month (0xf53700 seconds) |
| 2275 | uint32_t period; |
| 2276 | if (payload.unpack(period) || !payload.fullyUnpacked()) |
| 2277 | { |
| 2278 | return ipmi::responseReqDataLenInvalid(); |
| 2279 | } |
| 2280 | if ((period < oneDay) || (period > oneMonth)) |
| 2281 | { |
| 2282 | return ipmi::responseInvalidFieldRequest(); |
| 2283 | } |
| 2284 | if (setCRConfig(ctx, "PeriodOfRotation", period)) |
| 2285 | { |
| 2286 | return ipmi::responseResponseError(); |
| 2287 | } |
| 2288 | break; |
| 2289 | } |
| 2290 | default: |
| 2291 | { |
| 2292 | return ipmi::response(ccParameterNotSupported); |
| 2293 | } |
| 2294 | } |
| 2295 | |
| 2296 | // TODO Halfwidth needs to set SetInProgress |
| 2297 | if (setCRConfig(ctx, "ColdRedundancyStatus", |
Cheng C Yang | e8cecdf | 2019-08-26 23:48:08 +0800 | [diff] [blame] | 2298 | std::string("xyz.openbmc_project.Control." |
| 2299 | "PowerSupplyRedundancy.Status.completed"))) |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2300 | { |
| 2301 | return ipmi::responseResponseError(); |
| 2302 | } |
| 2303 | return ipmi::responseSuccess(crSetCompleted); |
| 2304 | } |
| 2305 | |
Yong Li | 8331513 | 2019-10-23 17:42:24 +0800 | [diff] [blame] | 2306 | 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] | 2307 | ipmiOEMGetCRConfig(ipmi::Context::ptr ctx, uint8_t parameter) |
| 2308 | { |
| 2309 | crConfigVariant value; |
| 2310 | switch (static_cast<crParameter>(parameter)) |
| 2311 | { |
| 2312 | case crParameter::crStatus: |
| 2313 | { |
| 2314 | if (getCRConfig(ctx, "ColdRedundancyStatus", value)) |
| 2315 | { |
| 2316 | return ipmi::responseResponseError(); |
| 2317 | } |
| 2318 | std::string* pStatus = std::get_if<std::string>(&value); |
| 2319 | if (!pStatus) |
| 2320 | { |
| 2321 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2322 | "Error to get ColdRedundancyStatus property"); |
| 2323 | return ipmi::responseResponseError(); |
| 2324 | } |
| 2325 | namespace server = sdbusplus::xyz::openbmc_project::Control::server; |
| 2326 | auto status = |
| 2327 | server::PowerSupplyRedundancy::convertStatusFromString( |
| 2328 | *pStatus); |
| 2329 | switch (status) |
| 2330 | { |
| 2331 | case server::PowerSupplyRedundancy::Status::inProgress: |
Cheng C Yang | f41e334 | 2019-09-10 04:47:23 +0800 | [diff] [blame] | 2332 | return ipmi::responseSuccess(parameter, |
| 2333 | static_cast<uint8_t>(0)); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2334 | |
| 2335 | case server::PowerSupplyRedundancy::Status::completed: |
Cheng C Yang | f41e334 | 2019-09-10 04:47:23 +0800 | [diff] [blame] | 2336 | return ipmi::responseSuccess(parameter, |
| 2337 | static_cast<uint8_t>(1)); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2338 | default: |
| 2339 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2340 | "Error to get valid status"); |
| 2341 | return ipmi::responseResponseError(); |
| 2342 | } |
| 2343 | } |
| 2344 | case crParameter::crFeature: |
| 2345 | { |
| 2346 | if (getCRConfig(ctx, "ColdRedundancyEnabled", value)) |
| 2347 | { |
| 2348 | return ipmi::responseResponseError(); |
| 2349 | } |
| 2350 | bool* pResponse = std::get_if<bool>(&value); |
| 2351 | if (!pResponse) |
| 2352 | { |
| 2353 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2354 | "Error to get ColdRedundancyEnable property"); |
| 2355 | return ipmi::responseResponseError(); |
| 2356 | } |
| 2357 | |
Cheng C Yang | f41e334 | 2019-09-10 04:47:23 +0800 | [diff] [blame] | 2358 | return ipmi::responseSuccess(parameter, |
| 2359 | static_cast<uint8_t>(*pResponse)); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2360 | } |
| 2361 | case crParameter::rotationFeature: |
| 2362 | { |
| 2363 | if (getCRConfig(ctx, "RotationEnabled", value)) |
| 2364 | { |
| 2365 | return ipmi::responseResponseError(); |
| 2366 | } |
| 2367 | bool* pResponse = std::get_if<bool>(&value); |
| 2368 | if (!pResponse) |
| 2369 | { |
| 2370 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2371 | "Error to get RotationEnabled property"); |
| 2372 | return ipmi::responseResponseError(); |
| 2373 | } |
Cheng C Yang | f41e334 | 2019-09-10 04:47:23 +0800 | [diff] [blame] | 2374 | return ipmi::responseSuccess(parameter, |
| 2375 | static_cast<uint8_t>(*pResponse)); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2376 | } |
| 2377 | case crParameter::rotationAlgo: |
| 2378 | { |
| 2379 | if (getCRConfig(ctx, "RotationAlgorithm", value)) |
| 2380 | { |
| 2381 | return ipmi::responseResponseError(); |
| 2382 | } |
| 2383 | |
| 2384 | std::string* pAlgo = std::get_if<std::string>(&value); |
| 2385 | if (!pAlgo) |
| 2386 | { |
| 2387 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2388 | "Error to get RotationAlgorithm property"); |
| 2389 | return ipmi::responseResponseError(); |
| 2390 | } |
Yong Li | 8331513 | 2019-10-23 17:42:24 +0800 | [diff] [blame] | 2391 | std::vector<uint8_t> response; |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2392 | namespace server = sdbusplus::xyz::openbmc_project::Control::server; |
| 2393 | auto algo = |
| 2394 | server::PowerSupplyRedundancy::convertAlgoFromString(*pAlgo); |
Yong Li | 8331513 | 2019-10-23 17:42:24 +0800 | [diff] [blame] | 2395 | |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2396 | switch (algo) |
| 2397 | { |
| 2398 | case server::PowerSupplyRedundancy::Algo::bmcSpecific: |
Yong Li | 8331513 | 2019-10-23 17:42:24 +0800 | [diff] [blame] | 2399 | response.push_back(0); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2400 | break; |
| 2401 | case server::PowerSupplyRedundancy::Algo::userSpecific: |
Yong Li | 8331513 | 2019-10-23 17:42:24 +0800 | [diff] [blame] | 2402 | response.push_back(1); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2403 | break; |
| 2404 | default: |
| 2405 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2406 | "Error to get valid algo"); |
| 2407 | return ipmi::responseResponseError(); |
| 2408 | } |
| 2409 | |
| 2410 | if (getCRConfig(ctx, "RotationRankOrder", value)) |
| 2411 | { |
| 2412 | return ipmi::responseResponseError(); |
| 2413 | } |
| 2414 | std::vector<uint8_t>* pResponse = |
| 2415 | std::get_if<std::vector<uint8_t>>(&value); |
| 2416 | if (!pResponse) |
| 2417 | { |
| 2418 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2419 | "Error to get RotationRankOrder property"); |
| 2420 | return ipmi::responseResponseError(); |
| 2421 | } |
Yong Li | 8331513 | 2019-10-23 17:42:24 +0800 | [diff] [blame] | 2422 | |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2423 | std::copy(pResponse->begin(), pResponse->end(), |
Yong Li | 8331513 | 2019-10-23 17:42:24 +0800 | [diff] [blame] | 2424 | std::back_inserter(response)); |
| 2425 | |
Cheng C Yang | f41e334 | 2019-09-10 04:47:23 +0800 | [diff] [blame] | 2426 | return ipmi::responseSuccess(parameter, response); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2427 | } |
| 2428 | case crParameter::rotationPeriod: |
| 2429 | { |
| 2430 | if (getCRConfig(ctx, "PeriodOfRotation", value)) |
| 2431 | { |
| 2432 | return ipmi::responseResponseError(); |
| 2433 | } |
| 2434 | uint32_t* pResponse = std::get_if<uint32_t>(&value); |
| 2435 | if (!pResponse) |
| 2436 | { |
| 2437 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2438 | "Error to get RotationAlgorithm property"); |
| 2439 | return ipmi::responseResponseError(); |
| 2440 | } |
Cheng C Yang | f41e334 | 2019-09-10 04:47:23 +0800 | [diff] [blame] | 2441 | return ipmi::responseSuccess(parameter, *pResponse); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2442 | } |
| 2443 | case crParameter::numOfPSU: |
| 2444 | { |
| 2445 | uint8_t numberOfPSU = getPSUCount(); |
| 2446 | if (!numberOfPSU) |
| 2447 | { |
| 2448 | return ipmi::responseResponseError(); |
| 2449 | } |
Cheng C Yang | f41e334 | 2019-09-10 04:47:23 +0800 | [diff] [blame] | 2450 | return ipmi::responseSuccess(parameter, numberOfPSU); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2451 | } |
Yong Li | 19445ab | 2019-12-20 18:25:29 +0800 | [diff] [blame] | 2452 | case crParameter::rotationRankOrderEffective: |
| 2453 | { |
| 2454 | if (getCRConfig(ctx, "RotationRankOrder", value, |
| 2455 | "xyz.openbmc_project.PSURedundancy")) |
| 2456 | { |
| 2457 | return ipmi::responseResponseError(); |
| 2458 | } |
| 2459 | std::vector<uint8_t>* pResponse = |
| 2460 | std::get_if<std::vector<uint8_t>>(&value); |
| 2461 | if (!pResponse) |
| 2462 | { |
| 2463 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2464 | "Error to get effective RotationRankOrder property"); |
| 2465 | return ipmi::responseResponseError(); |
| 2466 | } |
| 2467 | return ipmi::responseSuccess(parameter, *pResponse); |
| 2468 | } |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 2469 | default: |
| 2470 | { |
| 2471 | return ipmi::response(ccParameterNotSupported); |
| 2472 | } |
| 2473 | } |
| 2474 | } |
| 2475 | |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2476 | ipmi::RspType<> ipmiOEMSetFaultIndication(uint8_t sourceId, uint8_t faultType, |
| 2477 | uint8_t faultState, |
| 2478 | uint8_t faultGroup, |
| 2479 | std::array<uint8_t, 8>& ledStateData) |
| 2480 | { |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2481 | constexpr auto maxFaultType = static_cast<size_t>(RemoteFaultType::max); |
| 2482 | static const std::array<std::string, maxFaultType> faultNames = { |
| 2483 | "faultFan", "faultTemp", "faultPower", |
| 2484 | "faultDriveSlot", "faultSoftware", "faultMemory"}; |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2485 | |
| 2486 | constexpr uint8_t maxFaultSource = 0x4; |
| 2487 | constexpr uint8_t skipLEDs = 0xFF; |
| 2488 | constexpr uint8_t pinSize = 64; |
| 2489 | constexpr uint8_t groupSize = 16; |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2490 | constexpr uint8_t groupNum = 5; // 4 for fault memory, 1 for faultFan |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2491 | |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2492 | // same pin names need to be defined in dts file |
| 2493 | static const std::array<std::array<std::string, groupSize>, groupNum> |
| 2494 | faultLedPinNames = {{ |
| 2495 | "LED_CPU1_CH1_DIMM1_FAULT", |
| 2496 | "LED_CPU1_CH1_DIMM2_FAULT", |
| 2497 | "LED_CPU1_CH2_DIMM1_FAULT", |
| 2498 | "LED_CPU1_CH2_DIMM2_FAULT", |
| 2499 | "LED_CPU1_CH3_DIMM1_FAULT", |
| 2500 | "LED_CPU1_CH3_DIMM2_FAULT", |
| 2501 | "LED_CPU1_CH4_DIMM1_FAULT", |
| 2502 | "LED_CPU1_CH4_DIMM2_FAULT", |
| 2503 | "LED_CPU1_CH5_DIMM1_FAULT", |
| 2504 | "LED_CPU1_CH5_DIMM2_FAULT", |
| 2505 | "LED_CPU1_CH6_DIMM1_FAULT", |
| 2506 | "LED_CPU1_CH6_DIMM2_FAULT", |
| 2507 | "", |
| 2508 | "", |
| 2509 | "", |
| 2510 | "", // end of group1 |
| 2511 | "LED_CPU2_CH1_DIMM1_FAULT", |
| 2512 | "LED_CPU2_CH1_DIMM2_FAULT", |
| 2513 | "LED_CPU2_CH2_DIMM1_FAULT", |
| 2514 | "LED_CPU2_CH2_DIMM2_FAULT", |
| 2515 | "LED_CPU2_CH3_DIMM1_FAULT", |
| 2516 | "LED_CPU2_CH3_DIMM2_FAULT", |
| 2517 | "LED_CPU2_CH4_DIMM1_FAULT", |
| 2518 | "LED_CPU2_CH4_DIMM2_FAULT", |
| 2519 | "LED_CPU2_CH5_DIMM1_FAULT", |
| 2520 | "LED_CPU2_CH5_DIMM2_FAULT", |
| 2521 | "LED_CPU2_CH6_DIMM1_FAULT", |
| 2522 | "LED_CPU2_CH6_DIMM2_FAULT", |
| 2523 | "", |
| 2524 | "", |
| 2525 | "", |
| 2526 | "", // endof group2 |
| 2527 | "LED_CPU3_CH1_DIMM1_FAULT", |
| 2528 | "LED_CPU3_CH1_DIMM2_FAULT", |
| 2529 | "LED_CPU3_CH2_DIMM1_FAULT", |
| 2530 | "LED_CPU3_CH2_DIMM2_FAULT", |
| 2531 | "LED_CPU3_CH3_DIMM1_FAULT", |
| 2532 | "LED_CPU3_CH3_DIMM2_FAULT", |
| 2533 | "LED_CPU3_CH4_DIMM1_FAULT", |
| 2534 | "LED_CPU3_CH4_DIMM2_FAULT", |
| 2535 | "LED_CPU3_CH5_DIMM1_FAULT", |
| 2536 | "LED_CPU3_CH5_DIMM2_FAULT", |
| 2537 | "LED_CPU3_CH6_DIMM1_FAULT", |
| 2538 | "LED_CPU3_CH6_DIMM2_FAULT", |
| 2539 | "", |
| 2540 | "", |
| 2541 | "", |
| 2542 | "", // end of group3 |
| 2543 | "LED_CPU4_CH1_DIMM1_FAULT", |
| 2544 | "LED_CPU4_CH1_DIMM2_FAULT", |
| 2545 | "LED_CPU4_CH2_DIMM1_FAULT", |
| 2546 | "LED_CPU4_CH2_DIMM2_FAULT", |
| 2547 | "LED_CPU4_CH3_DIMM1_FAULT", |
| 2548 | "LED_CPU4_CH3_DIMM2_FAULT", |
| 2549 | "LED_CPU4_CH4_DIMM1_FAULT", |
| 2550 | "LED_CPU4_CH4_DIMM2_FAULT", |
| 2551 | "LED_CPU4_CH5_DIMM1_FAULT", |
| 2552 | "LED_CPU4_CH5_DIMM2_FAULT", |
| 2553 | "LED_CPU4_CH6_DIMM1_FAULT", |
| 2554 | "LED_CPU4_CH6_DIMM2_FAULT", |
| 2555 | "", |
| 2556 | "", |
| 2557 | "", |
| 2558 | "", // end of group4 |
| 2559 | "LED_FAN1_FAULT", |
| 2560 | "LED_FAN2_FAULT", |
| 2561 | "LED_FAN3_FAULT", |
| 2562 | "LED_FAN4_FAULT", |
| 2563 | "LED_FAN5_FAULT", |
| 2564 | "LED_FAN6_FAULT", |
| 2565 | "LED_FAN7_FAULT", |
| 2566 | "LED_FAN8_FAULT", |
| 2567 | "", |
| 2568 | "", |
| 2569 | "", |
| 2570 | "", |
| 2571 | "", |
| 2572 | "", |
| 2573 | "", |
| 2574 | "" // end of group5 |
| 2575 | }}; |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2576 | |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2577 | // Validate the source, fault type -- |
| 2578 | // (Byte 1) sourceId: Unspecified, Hot-Swap Controller 0, Hot-Swap |
| 2579 | // Controller 1, BIOS (Byte 2) fault type: fan, temperature, power, |
| 2580 | // driveslot, software, memory (Byte 3) FaultState: OK, Degraded, |
| 2581 | // Non-Critical, Critical, Non-Recoverable, (Byte 4) is faultGroup, |
| 2582 | // definition differs based on fault type (Byte 2) |
| 2583 | // Type Fan=> Group: 0=FanGroupID, FF-not used |
| 2584 | // Byte 5-11 00h, not used |
| 2585 | // Byte12 FanLedState [7:0]-Fans 7:0 |
| 2586 | // Type Memory=> Group: 0 = DIMM GroupID, FF-not used |
| 2587 | // Byte 5:12 - DIMM LED state (64bit field, LS Byte first) |
| 2588 | // [63:48] = CPU4 channels 7:0, 2 bits per channel |
| 2589 | // [47:32] = CPU3 channels 7:0, 2 bits per channel |
| 2590 | // [31:16] = CPU2 channels 7:0, 2 bits per channel |
| 2591 | // [15:0] = CPU1 channels 7:0, 2 bits per channel |
| 2592 | // Type Other=> Component Fault LED Group ID, not used set to 0xFF |
| 2593 | // Byte[5:12]: reserved 0x00h |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2594 | if ((sourceId >= maxFaultSource) || |
| 2595 | (faultType >= static_cast<int8_t>(RemoteFaultType::max)) || |
| 2596 | (faultState >= static_cast<int8_t>(RemoteFaultState::maxFaultState)) || |
| 2597 | (faultGroup >= static_cast<int8_t>(DimmFaultType::maxFaultGroup))) |
| 2598 | { |
| 2599 | return ipmi::responseParmOutOfRange(); |
| 2600 | } |
| 2601 | |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2602 | size_t pinGroupOffset = 0; |
| 2603 | size_t pinGroupMax = pinSize / groupSize; |
| 2604 | if (RemoteFaultType::fan == RemoteFaultType(faultType)) |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2605 | { |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2606 | pinGroupOffset = 4; |
| 2607 | pinGroupMax = groupNum - pinSize / groupSize; |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2608 | } |
| 2609 | |
| 2610 | switch (RemoteFaultType(faultType)) |
| 2611 | { |
| 2612 | case (RemoteFaultType::fan): |
| 2613 | case (RemoteFaultType::memory): |
| 2614 | { |
| 2615 | if (faultGroup == skipLEDs) |
| 2616 | { |
| 2617 | return ipmi::responseSuccess(); |
| 2618 | } |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2619 | // calculate led state bit filed count, each byte has 8bits |
| 2620 | // the maximum bits will be 8 * 8 bits |
| 2621 | constexpr uint8_t size = sizeof(ledStateData) * 8; |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2622 | |
| 2623 | // assemble ledState |
| 2624 | uint64_t ledState = 0; |
| 2625 | bool hasError = false; |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2626 | for (int i = 0; i < sizeof(ledStateData); i++) |
| 2627 | { |
| 2628 | ledState = (uint64_t)(ledState << 8); |
| 2629 | ledState = (uint64_t)(ledState | (uint64_t)ledStateData[i]); |
| 2630 | } |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2631 | std::bitset<size> ledStateBits(ledState); |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2632 | |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2633 | for (int group = 0; group < pinGroupMax; group++) |
| 2634 | { |
| 2635 | for (int i = 0; i < groupSize; i++) |
| 2636 | { // skip non-existing pins |
| 2637 | if (0 == faultLedPinNames[group + pinGroupOffset][i].size()) |
| 2638 | { |
| 2639 | continue; |
| 2640 | } |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2641 | |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2642 | gpiod::line line = gpiod::find_line( |
| 2643 | faultLedPinNames[group + pinGroupOffset][i]); |
| 2644 | if (!line) |
| 2645 | { |
| 2646 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2647 | "Not Find Led Gpio Device!", |
| 2648 | phosphor::logging::entry( |
| 2649 | "DEVICE=%s", |
| 2650 | faultLedPinNames[group + pinGroupOffset][i] |
| 2651 | .c_str())); |
| 2652 | hasError = true; |
| 2653 | continue; |
| 2654 | } |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2655 | |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2656 | bool activeHigh = |
| 2657 | (line.active_state() == gpiod::line::ACTIVE_HIGH); |
| 2658 | try |
| 2659 | { |
| 2660 | line.request( |
| 2661 | {"faultLed", gpiod::line_request::DIRECTION_OUTPUT, |
| 2662 | activeHigh |
| 2663 | ? 0 |
| 2664 | : gpiod::line_request::FLAG_ACTIVE_LOW}); |
| 2665 | line.set_value(ledStateBits[i + group * groupSize]); |
| 2666 | } |
| 2667 | catch (std::system_error&) |
| 2668 | { |
| 2669 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2670 | "Error write Led Gpio Device!", |
| 2671 | phosphor::logging::entry( |
| 2672 | "DEVICE=%s", |
| 2673 | faultLedPinNames[group + pinGroupOffset][i] |
| 2674 | .c_str())); |
| 2675 | hasError = true; |
| 2676 | continue; |
| 2677 | } |
| 2678 | } // for int i |
| 2679 | } |
| 2680 | if (hasError) |
| 2681 | { |
| 2682 | return ipmi::responseResponseError(); |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2683 | } |
| 2684 | break; |
| 2685 | } |
| 2686 | default: |
| 2687 | { |
| 2688 | // now only support two fault types |
| 2689 | return ipmi::responseParmOutOfRange(); |
| 2690 | } |
Zhikui Ren | ce4e73f | 2019-12-06 13:59:47 -0800 | [diff] [blame] | 2691 | } // switch |
Zhu, Yunge | be560b0 | 2019-04-21 21:19:21 -0400 | [diff] [blame] | 2692 | return ipmi::responseSuccess(); |
| 2693 | } |
| 2694 | |
Richard Marian Thomaiyar | ea537d5 | 2019-04-24 21:33:48 +0530 | [diff] [blame] | 2695 | ipmi::RspType<uint8_t> ipmiOEMReadBoardProductId() |
| 2696 | { |
| 2697 | uint8_t prodId = 0; |
| 2698 | try |
| 2699 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 2700 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
Richard Marian Thomaiyar | ea537d5 | 2019-04-24 21:33:48 +0530 | [diff] [blame] | 2701 | const DbusObjectInfo& object = getDbusObject( |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 2702 | *dbus, "xyz.openbmc_project.Inventory.Item.Board", |
Richard Marian Thomaiyar | ea537d5 | 2019-04-24 21:33:48 +0530 | [diff] [blame] | 2703 | "/xyz/openbmc_project/inventory/system/board/", "Baseboard"); |
| 2704 | const Value& propValue = getDbusProperty( |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 2705 | *dbus, object.second, object.first, |
Suryakanth Sekar | 6c57e5c | 2020-01-10 17:11:58 +0530 | [diff] [blame] | 2706 | "xyz.openbmc_project.Inventory.Item.Board.Motherboard", |
| 2707 | "ProductId"); |
Richard Marian Thomaiyar | ea537d5 | 2019-04-24 21:33:48 +0530 | [diff] [blame] | 2708 | prodId = static_cast<uint8_t>(std::get<uint64_t>(propValue)); |
| 2709 | } |
| 2710 | catch (std::exception& e) |
| 2711 | { |
| 2712 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2713 | "ipmiOEMReadBoardProductId: Product ID read failed!", |
| 2714 | phosphor::logging::entry("ERR=%s", e.what())); |
| 2715 | } |
| 2716 | return ipmi::responseSuccess(prodId); |
| 2717 | } |
| 2718 | |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 2719 | /** @brief implements the get security mode command |
| 2720 | * @param ctx - ctx pointer |
| 2721 | * |
| 2722 | * @returns IPMI completion code with following data |
| 2723 | * - restriction mode value - As specified in |
| 2724 | * xyz.openbmc_project.Control.Security.RestrictionMode.interface.yaml |
| 2725 | * - special mode value - As specified in |
| 2726 | * xyz.openbmc_project.Control.Security.SpecialMode.interface.yaml |
| 2727 | */ |
| 2728 | ipmi::RspType<uint8_t, uint8_t> ipmiGetSecurityMode(ipmi::Context::ptr ctx) |
| 2729 | { |
| 2730 | namespace securityNameSpace = |
| 2731 | sdbusplus::xyz::openbmc_project::Control::Security::server; |
| 2732 | uint8_t restrictionModeValue = 0; |
| 2733 | uint8_t specialModeValue = 0; |
| 2734 | |
| 2735 | boost::system::error_code ec; |
| 2736 | auto varRestrMode = ctx->bus->yield_method_call<std::variant<std::string>>( |
James Feist | 28c7290 | 2019-09-16 10:34:07 -0700 | [diff] [blame] | 2737 | ctx->yield, ec, restricionModeService, restricionModeBasePath, |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 2738 | dBusPropertyIntf, dBusPropertyGetMethod, restricionModeIntf, |
| 2739 | restricionModeProperty); |
| 2740 | if (ec) |
| 2741 | { |
| 2742 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2743 | "ipmiGetSecurityMode: failed to get RestrictionMode property", |
| 2744 | phosphor::logging::entry("ERROR=%s", ec.message().c_str())); |
| 2745 | return ipmi::responseUnspecifiedError(); |
| 2746 | } |
| 2747 | restrictionModeValue = static_cast<uint8_t>( |
| 2748 | securityNameSpace::RestrictionMode::convertModesFromString( |
| 2749 | std::get<std::string>(varRestrMode))); |
Richard Marian Thomaiyar | 8d4f8d7 | 2019-11-11 12:06:40 +0530 | [diff] [blame] | 2750 | auto varSpecialMode = |
| 2751 | ctx->bus->yield_method_call<std::variant<std::string>>( |
| 2752 | ctx->yield, ec, specialModeService, specialModeBasePath, |
| 2753 | dBusPropertyIntf, dBusPropertyGetMethod, specialModeIntf, |
| 2754 | specialModeProperty); |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 2755 | if (ec) |
| 2756 | { |
| 2757 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2758 | "ipmiGetSecurityMode: failed to get SpecialMode property", |
| 2759 | phosphor::logging::entry("ERROR=%s", ec.message().c_str())); |
| 2760 | // fall through, let us not worry about SpecialMode property, which is |
| 2761 | // not required in user scenario |
| 2762 | } |
| 2763 | else |
| 2764 | { |
Richard Marian Thomaiyar | 8d4f8d7 | 2019-11-11 12:06:40 +0530 | [diff] [blame] | 2765 | specialModeValue = static_cast<uint8_t>( |
| 2766 | securityNameSpace::SpecialMode::convertModesFromString( |
| 2767 | std::get<std::string>(varSpecialMode))); |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 2768 | } |
| 2769 | return ipmi::responseSuccess(restrictionModeValue, specialModeValue); |
| 2770 | } |
| 2771 | |
| 2772 | /** @brief implements the set security mode command |
| 2773 | * Command allows to upgrade the restriction mode and won't allow |
| 2774 | * to downgrade from system interface |
| 2775 | * @param ctx - ctx pointer |
| 2776 | * @param restrictionMode - restriction mode value to be set. |
| 2777 | * |
| 2778 | * @returns IPMI completion code |
| 2779 | */ |
| 2780 | ipmi::RspType<> ipmiSetSecurityMode(ipmi::Context::ptr ctx, |
Richard Marian Thomaiyar | 1079106 | 2019-11-11 12:19:53 +0530 | [diff] [blame] | 2781 | uint8_t restrictionMode, |
| 2782 | std::optional<uint8_t> specialMode) |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 2783 | { |
Richard Marian Thomaiyar | 1079106 | 2019-11-11 12:19:53 +0530 | [diff] [blame] | 2784 | #ifndef BMC_VALIDATION_UNSECURE_FEATURE |
| 2785 | if (specialMode) |
| 2786 | { |
| 2787 | return ipmi::responseReqDataLenInvalid(); |
| 2788 | } |
| 2789 | #endif |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 2790 | namespace securityNameSpace = |
| 2791 | sdbusplus::xyz::openbmc_project::Control::Security::server; |
| 2792 | |
| 2793 | ChannelInfo chInfo; |
| 2794 | if (getChannelInfo(ctx->channel, chInfo) != ccSuccess) |
| 2795 | { |
| 2796 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2797 | "ipmiSetSecurityMode: Failed to get Channel Info", |
| 2798 | phosphor::logging::entry("CHANNEL=%d", ctx->channel)); |
| 2799 | return ipmi::responseUnspecifiedError(); |
| 2800 | } |
| 2801 | auto reqMode = |
| 2802 | static_cast<securityNameSpace::RestrictionMode::Modes>(restrictionMode); |
| 2803 | |
| 2804 | if ((reqMode < securityNameSpace::RestrictionMode::Modes::Provisioning) || |
| 2805 | (reqMode > |
| 2806 | securityNameSpace::RestrictionMode::Modes::ProvisionedHostDisabled)) |
| 2807 | { |
| 2808 | return ipmi::responseInvalidFieldRequest(); |
| 2809 | } |
| 2810 | |
| 2811 | boost::system::error_code ec; |
| 2812 | auto varRestrMode = ctx->bus->yield_method_call<std::variant<std::string>>( |
James Feist | 28c7290 | 2019-09-16 10:34:07 -0700 | [diff] [blame] | 2813 | ctx->yield, ec, restricionModeService, restricionModeBasePath, |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 2814 | dBusPropertyIntf, dBusPropertyGetMethod, restricionModeIntf, |
| 2815 | restricionModeProperty); |
| 2816 | if (ec) |
| 2817 | { |
| 2818 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2819 | "ipmiSetSecurityMode: failed to get RestrictionMode property", |
| 2820 | phosphor::logging::entry("ERROR=%s", ec.message().c_str())); |
| 2821 | return ipmi::responseUnspecifiedError(); |
| 2822 | } |
| 2823 | auto currentRestrictionMode = |
| 2824 | securityNameSpace::RestrictionMode::convertModesFromString( |
| 2825 | std::get<std::string>(varRestrMode)); |
| 2826 | |
| 2827 | if (chInfo.mediumType != |
| 2828 | static_cast<uint8_t>(EChannelMediumType::lan8032) && |
| 2829 | currentRestrictionMode > reqMode) |
| 2830 | { |
| 2831 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2832 | "ipmiSetSecurityMode - Downgrading security mode not supported " |
| 2833 | "through system interface", |
| 2834 | phosphor::logging::entry( |
| 2835 | "CUR_MODE=%d", static_cast<uint8_t>(currentRestrictionMode)), |
| 2836 | phosphor::logging::entry("REQ_MODE=%d", restrictionMode)); |
| 2837 | return ipmi::responseCommandNotAvailable(); |
| 2838 | } |
| 2839 | |
| 2840 | ec.clear(); |
| 2841 | ctx->bus->yield_method_call<>( |
James Feist | 28c7290 | 2019-09-16 10:34:07 -0700 | [diff] [blame] | 2842 | ctx->yield, ec, restricionModeService, restricionModeBasePath, |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 2843 | dBusPropertyIntf, dBusPropertySetMethod, restricionModeIntf, |
| 2844 | restricionModeProperty, |
| 2845 | static_cast<std::variant<std::string>>( |
| 2846 | securityNameSpace::convertForMessage(reqMode))); |
| 2847 | |
| 2848 | if (ec) |
| 2849 | { |
| 2850 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2851 | "ipmiSetSecurityMode: failed to set RestrictionMode property", |
| 2852 | phosphor::logging::entry("ERROR=%s", ec.message().c_str())); |
| 2853 | return ipmi::responseUnspecifiedError(); |
| 2854 | } |
Richard Marian Thomaiyar | 1079106 | 2019-11-11 12:19:53 +0530 | [diff] [blame] | 2855 | |
| 2856 | #ifdef BMC_VALIDATION_UNSECURE_FEATURE |
| 2857 | if (specialMode) |
| 2858 | { |
| 2859 | ec.clear(); |
| 2860 | ctx->bus->yield_method_call<>( |
| 2861 | ctx->yield, ec, specialModeService, specialModeBasePath, |
| 2862 | dBusPropertyIntf, dBusPropertySetMethod, specialModeIntf, |
| 2863 | specialModeProperty, |
| 2864 | static_cast<std::variant<std::string>>( |
| 2865 | securityNameSpace::convertForMessage( |
| 2866 | static_cast<securityNameSpace::SpecialMode::Modes>( |
| 2867 | specialMode.value())))); |
| 2868 | |
| 2869 | if (ec) |
| 2870 | { |
| 2871 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2872 | "ipmiSetSecurityMode: failed to set SpecialMode property", |
| 2873 | phosphor::logging::entry("ERROR=%s", ec.message().c_str())); |
| 2874 | return ipmi::responseUnspecifiedError(); |
| 2875 | } |
| 2876 | } |
| 2877 | #endif |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 2878 | return ipmi::responseSuccess(); |
| 2879 | } |
| 2880 | |
Vernon Mauery | 4ac799d | 2019-05-20 15:50:37 -0700 | [diff] [blame] | 2881 | ipmi::RspType<uint8_t /* restore status */> |
| 2882 | ipmiRestoreConfiguration(const std::array<uint8_t, 3>& clr, uint8_t cmd) |
| 2883 | { |
| 2884 | static constexpr std::array<uint8_t, 3> expClr = {'C', 'L', 'R'}; |
| 2885 | |
| 2886 | if (clr != expClr) |
| 2887 | { |
| 2888 | return ipmi::responseInvalidFieldRequest(); |
| 2889 | } |
| 2890 | constexpr uint8_t cmdStatus = 0; |
| 2891 | constexpr uint8_t cmdDefaultRestore = 0xaa; |
| 2892 | constexpr uint8_t cmdFullRestore = 0xbb; |
| 2893 | constexpr uint8_t cmdFormat = 0xcc; |
| 2894 | |
| 2895 | constexpr const char* restoreOpFname = "/tmp/.rwfs/.restore_op"; |
| 2896 | |
| 2897 | switch (cmd) |
| 2898 | { |
| 2899 | case cmdStatus: |
| 2900 | break; |
| 2901 | case cmdDefaultRestore: |
| 2902 | case cmdFullRestore: |
| 2903 | case cmdFormat: |
| 2904 | { |
| 2905 | // write file to rwfs root |
| 2906 | int value = (cmd - 1) & 0x03; // map aa, bb, cc => 1, 2, 3 |
| 2907 | std::ofstream restoreFile(restoreOpFname); |
| 2908 | if (!restoreFile) |
| 2909 | { |
| 2910 | return ipmi::responseUnspecifiedError(); |
| 2911 | } |
| 2912 | restoreFile << value << "\n"; |
| 2913 | break; |
| 2914 | } |
| 2915 | default: |
| 2916 | return ipmi::responseInvalidFieldRequest(); |
| 2917 | } |
| 2918 | |
| 2919 | constexpr uint8_t restorePending = 0; |
| 2920 | constexpr uint8_t restoreComplete = 1; |
| 2921 | |
| 2922 | uint8_t restoreStatus = std::filesystem::exists(restoreOpFname) |
| 2923 | ? restorePending |
| 2924 | : restoreComplete; |
| 2925 | return ipmi::responseSuccess(restoreStatus); |
| 2926 | } |
| 2927 | |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 2928 | ipmi::RspType<uint8_t> ipmiOEMGetNmiSource(void) |
| 2929 | { |
| 2930 | uint8_t bmcSource; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 2931 | namespace nmi = sdbusplus::xyz::openbmc_project::Chassis::Control::server; |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 2932 | |
| 2933 | try |
| 2934 | { |
| 2935 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 2936 | std::string service = |
| 2937 | getService(*dbus, oemNmiSourceIntf, oemNmiSourceObjPath); |
| 2938 | Value variant = |
| 2939 | getDbusProperty(*dbus, service, oemNmiSourceObjPath, |
| 2940 | oemNmiSourceIntf, oemNmiBmcSourceObjPathProp); |
| 2941 | |
| 2942 | switch (nmi::NMISource::convertBMCSourceSignalFromString( |
| 2943 | std::get<std::string>(variant))) |
| 2944 | { |
| 2945 | case nmi::NMISource::BMCSourceSignal::None: |
| 2946 | bmcSource = static_cast<uint8_t>(NmiSource::none); |
| 2947 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 2948 | case nmi::NMISource::BMCSourceSignal::FrontPanelButton: |
| 2949 | bmcSource = static_cast<uint8_t>(NmiSource::frontPanelButton); |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 2950 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 2951 | case nmi::NMISource::BMCSourceSignal::Watchdog: |
| 2952 | bmcSource = static_cast<uint8_t>(NmiSource::watchdog); |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 2953 | break; |
| 2954 | case nmi::NMISource::BMCSourceSignal::ChassisCmd: |
| 2955 | bmcSource = static_cast<uint8_t>(NmiSource::chassisCmd); |
| 2956 | break; |
| 2957 | case nmi::NMISource::BMCSourceSignal::MemoryError: |
| 2958 | bmcSource = static_cast<uint8_t>(NmiSource::memoryError); |
| 2959 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 2960 | case nmi::NMISource::BMCSourceSignal::PciBusError: |
| 2961 | bmcSource = static_cast<uint8_t>(NmiSource::pciBusError); |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 2962 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 2963 | case nmi::NMISource::BMCSourceSignal::PCH: |
| 2964 | bmcSource = static_cast<uint8_t>(NmiSource::pch); |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 2965 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 2966 | case nmi::NMISource::BMCSourceSignal::Chipset: |
| 2967 | bmcSource = static_cast<uint8_t>(NmiSource::chipset); |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 2968 | break; |
| 2969 | default: |
| 2970 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 2971 | "NMI source: invalid property!", |
| 2972 | phosphor::logging::entry( |
| 2973 | "PROP=%s", std::get<std::string>(variant).c_str())); |
| 2974 | return ipmi::responseResponseError(); |
| 2975 | } |
| 2976 | } |
| 2977 | catch (sdbusplus::exception::SdBusError& e) |
| 2978 | { |
| 2979 | phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
| 2980 | return ipmi::responseResponseError(); |
| 2981 | } |
| 2982 | |
| 2983 | return ipmi::responseSuccess(bmcSource); |
| 2984 | } |
| 2985 | |
| 2986 | ipmi::RspType<> ipmiOEMSetNmiSource(uint8_t sourceId) |
| 2987 | { |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 2988 | namespace nmi = sdbusplus::xyz::openbmc_project::Chassis::Control::server; |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 2989 | |
| 2990 | nmi::NMISource::BMCSourceSignal bmcSourceSignal = |
| 2991 | nmi::NMISource::BMCSourceSignal::None; |
| 2992 | |
| 2993 | switch (NmiSource(sourceId)) |
| 2994 | { |
| 2995 | case NmiSource::none: |
| 2996 | bmcSourceSignal = nmi::NMISource::BMCSourceSignal::None; |
| 2997 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 2998 | case NmiSource::frontPanelButton: |
| 2999 | bmcSourceSignal = nmi::NMISource::BMCSourceSignal::FrontPanelButton; |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 3000 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 3001 | case NmiSource::watchdog: |
| 3002 | bmcSourceSignal = nmi::NMISource::BMCSourceSignal::Watchdog; |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 3003 | break; |
| 3004 | case NmiSource::chassisCmd: |
| 3005 | bmcSourceSignal = nmi::NMISource::BMCSourceSignal::ChassisCmd; |
| 3006 | break; |
| 3007 | case NmiSource::memoryError: |
| 3008 | bmcSourceSignal = nmi::NMISource::BMCSourceSignal::MemoryError; |
| 3009 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 3010 | case NmiSource::pciBusError: |
| 3011 | bmcSourceSignal = nmi::NMISource::BMCSourceSignal::PciBusError; |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 3012 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 3013 | case NmiSource::pch: |
| 3014 | bmcSourceSignal = nmi::NMISource::BMCSourceSignal::PCH; |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 3015 | break; |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 3016 | case NmiSource::chipset: |
| 3017 | bmcSourceSignal = nmi::NMISource::BMCSourceSignal::Chipset; |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 3018 | break; |
| 3019 | default: |
| 3020 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3021 | "NMI source: invalid property!"); |
| 3022 | return ipmi::responseResponseError(); |
| 3023 | } |
| 3024 | |
| 3025 | try |
| 3026 | { |
| 3027 | // keep NMI signal source |
| 3028 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 3029 | std::string service = |
| 3030 | getService(*dbus, oemNmiSourceIntf, oemNmiSourceObjPath); |
Chen Yugang | 97cf96e | 2019-11-01 08:55:11 +0800 | [diff] [blame] | 3031 | setDbusProperty(*dbus, service, oemNmiSourceObjPath, oemNmiSourceIntf, |
| 3032 | oemNmiBmcSourceObjPathProp, |
| 3033 | nmi::convertForMessage(bmcSourceSignal)); |
Chen Yugang | 99be633 | 2019-08-09 16:20:48 +0800 | [diff] [blame] | 3034 | // set Enabled property to inform NMI source handling |
| 3035 | // to trigger a NMI_OUT BSOD. |
| 3036 | // if it's triggered by NMI source property changed, |
| 3037 | // NMI_OUT BSOD could be missed if the same source occurs twice in a row |
| 3038 | if (bmcSourceSignal != nmi::NMISource::BMCSourceSignal::None) |
| 3039 | { |
| 3040 | setDbusProperty(*dbus, service, oemNmiSourceObjPath, |
| 3041 | oemNmiSourceIntf, oemNmiEnabledObjPathProp, |
| 3042 | static_cast<bool>(true)); |
| 3043 | } |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 3044 | } |
| 3045 | catch (sdbusplus::exception_t& e) |
| 3046 | { |
| 3047 | phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
| 3048 | return ipmi::responseResponseError(); |
| 3049 | } |
| 3050 | |
| 3051 | return ipmi::responseSuccess(); |
| 3052 | } |
| 3053 | |
James Feist | 63efafa | 2019-07-24 12:39:21 -0700 | [diff] [blame] | 3054 | namespace dimmOffset |
| 3055 | { |
| 3056 | constexpr const char* dimmPower = "DimmPower"; |
| 3057 | constexpr const char* staticCltt = "StaticCltt"; |
| 3058 | constexpr const char* offsetPath = "/xyz/openbmc_project/Inventory/Item/Dimm"; |
| 3059 | constexpr const char* offsetInterface = |
| 3060 | "xyz.openbmc_project.Inventory.Item.Dimm.Offset"; |
| 3061 | constexpr const char* property = "DimmOffset"; |
| 3062 | |
| 3063 | }; // namespace dimmOffset |
| 3064 | |
| 3065 | ipmi::RspType<> |
| 3066 | ipmiOEMSetDimmOffset(uint8_t type, |
| 3067 | const std::vector<std::tuple<uint8_t, uint8_t>>& data) |
| 3068 | { |
| 3069 | if (type != static_cast<uint8_t>(dimmOffsetTypes::dimmPower) && |
| 3070 | type != static_cast<uint8_t>(dimmOffsetTypes::staticCltt)) |
| 3071 | { |
| 3072 | return ipmi::responseInvalidFieldRequest(); |
| 3073 | } |
| 3074 | |
| 3075 | if (data.empty()) |
| 3076 | { |
| 3077 | return ipmi::responseInvalidFieldRequest(); |
| 3078 | } |
| 3079 | nlohmann::json json; |
| 3080 | |
| 3081 | std::ifstream jsonStream(dimmOffsetFile); |
| 3082 | if (jsonStream.good()) |
| 3083 | { |
| 3084 | json = nlohmann::json::parse(jsonStream, nullptr, false); |
| 3085 | if (json.is_discarded()) |
| 3086 | { |
| 3087 | json = nlohmann::json(); |
| 3088 | } |
| 3089 | jsonStream.close(); |
| 3090 | } |
| 3091 | |
| 3092 | std::string typeName; |
| 3093 | if (type == static_cast<uint8_t>(dimmOffsetTypes::dimmPower)) |
| 3094 | { |
| 3095 | typeName = dimmOffset::dimmPower; |
| 3096 | } |
| 3097 | else |
| 3098 | { |
| 3099 | typeName = dimmOffset::staticCltt; |
| 3100 | } |
| 3101 | |
| 3102 | nlohmann::json& field = json[typeName]; |
| 3103 | |
| 3104 | for (const auto& [index, value] : data) |
| 3105 | { |
| 3106 | field[index] = value; |
| 3107 | } |
| 3108 | |
| 3109 | for (nlohmann::json& val : field) |
| 3110 | { |
| 3111 | if (val == nullptr) |
| 3112 | { |
| 3113 | val = static_cast<uint8_t>(0); |
| 3114 | } |
| 3115 | } |
| 3116 | |
| 3117 | std::ofstream output(dimmOffsetFile); |
| 3118 | if (!output.good()) |
| 3119 | { |
| 3120 | std::cerr << "Error writing json file\n"; |
| 3121 | return ipmi::responseResponseError(); |
| 3122 | } |
| 3123 | |
| 3124 | output << json.dump(4); |
| 3125 | |
| 3126 | if (type == static_cast<uint8_t>(dimmOffsetTypes::staticCltt)) |
| 3127 | { |
| 3128 | std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus(); |
| 3129 | |
| 3130 | std::variant<std::vector<uint8_t>> offsets = |
| 3131 | field.get<std::vector<uint8_t>>(); |
| 3132 | auto call = bus->new_method_call( |
| 3133 | settingsBusName, dimmOffset::offsetPath, PROP_INTF, "Set"); |
| 3134 | call.append(dimmOffset::offsetInterface, dimmOffset::property, offsets); |
| 3135 | try |
| 3136 | { |
| 3137 | bus->call(call); |
| 3138 | } |
| 3139 | catch (sdbusplus::exception_t& e) |
| 3140 | { |
| 3141 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3142 | "ipmiOEMSetDimmOffset: can't set dimm offsets!", |
| 3143 | phosphor::logging::entry("ERR=%s", e.what())); |
| 3144 | return ipmi::responseResponseError(); |
| 3145 | } |
| 3146 | } |
| 3147 | |
| 3148 | return ipmi::responseSuccess(); |
| 3149 | } |
| 3150 | |
| 3151 | ipmi::RspType<uint8_t> ipmiOEMGetDimmOffset(uint8_t type, uint8_t index) |
| 3152 | { |
| 3153 | |
| 3154 | if (type != static_cast<uint8_t>(dimmOffsetTypes::dimmPower) && |
| 3155 | type != static_cast<uint8_t>(dimmOffsetTypes::staticCltt)) |
| 3156 | { |
| 3157 | return ipmi::responseInvalidFieldRequest(); |
| 3158 | } |
| 3159 | |
| 3160 | std::ifstream jsonStream(dimmOffsetFile); |
| 3161 | |
| 3162 | auto json = nlohmann::json::parse(jsonStream, nullptr, false); |
| 3163 | if (json.is_discarded()) |
| 3164 | { |
| 3165 | std::cerr << "File error in " << dimmOffsetFile << "\n"; |
| 3166 | return ipmi::responseResponseError(); |
| 3167 | } |
| 3168 | |
| 3169 | std::string typeName; |
| 3170 | if (type == static_cast<uint8_t>(dimmOffsetTypes::dimmPower)) |
| 3171 | { |
| 3172 | typeName = dimmOffset::dimmPower; |
| 3173 | } |
| 3174 | else |
| 3175 | { |
| 3176 | typeName = dimmOffset::staticCltt; |
| 3177 | } |
| 3178 | |
| 3179 | auto it = json.find(typeName); |
| 3180 | if (it == json.end()) |
| 3181 | { |
| 3182 | return ipmi::responseInvalidFieldRequest(); |
| 3183 | } |
| 3184 | |
| 3185 | if (it->size() <= index) |
| 3186 | { |
| 3187 | return ipmi::responseInvalidFieldRequest(); |
| 3188 | } |
| 3189 | |
| 3190 | uint8_t resp = it->at(index).get<uint8_t>(); |
| 3191 | return ipmi::responseSuccess(resp); |
| 3192 | } |
| 3193 | |
Chen,Yugang | 4f7e76b | 2019-08-20 09:28:06 +0800 | [diff] [blame] | 3194 | namespace boot_options |
| 3195 | { |
| 3196 | |
| 3197 | using namespace sdbusplus::xyz::openbmc_project::Control::Boot::server; |
| 3198 | using IpmiValue = uint8_t; |
| 3199 | constexpr auto ipmiDefault = 0; |
| 3200 | |
| 3201 | std::map<IpmiValue, Source::Sources> sourceIpmiToDbus = { |
| 3202 | {0x01, Source::Sources::Network}, |
| 3203 | {0x02, Source::Sources::Disk}, |
| 3204 | {0x05, Source::Sources::ExternalMedia}, |
| 3205 | {0x0f, Source::Sources::RemovableMedia}, |
| 3206 | {ipmiDefault, Source::Sources::Default}}; |
| 3207 | |
| 3208 | std::map<IpmiValue, Mode::Modes> modeIpmiToDbus = { |
Chen Yugang | ca12a7b | 2019-09-03 18:11:44 +0800 | [diff] [blame] | 3209 | {0x06, Mode::Modes::Setup}, {ipmiDefault, Mode::Modes::Regular}}; |
Chen,Yugang | 4f7e76b | 2019-08-20 09:28:06 +0800 | [diff] [blame] | 3210 | |
| 3211 | std::map<Source::Sources, IpmiValue> sourceDbusToIpmi = { |
| 3212 | {Source::Sources::Network, 0x01}, |
| 3213 | {Source::Sources::Disk, 0x02}, |
| 3214 | {Source::Sources::ExternalMedia, 0x05}, |
| 3215 | {Source::Sources::RemovableMedia, 0x0f}, |
| 3216 | {Source::Sources::Default, ipmiDefault}}; |
| 3217 | |
| 3218 | std::map<Mode::Modes, IpmiValue> modeDbusToIpmi = { |
Chen Yugang | ca12a7b | 2019-09-03 18:11:44 +0800 | [diff] [blame] | 3219 | {Mode::Modes::Setup, 0x06}, {Mode::Modes::Regular, ipmiDefault}}; |
Chen,Yugang | 4f7e76b | 2019-08-20 09:28:06 +0800 | [diff] [blame] | 3220 | |
| 3221 | static constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode"; |
| 3222 | static constexpr auto bootSourceIntf = |
| 3223 | "xyz.openbmc_project.Control.Boot.Source"; |
| 3224 | static constexpr auto enabledIntf = "xyz.openbmc_project.Object.Enable"; |
| 3225 | static constexpr auto persistentObjPath = |
| 3226 | "/xyz/openbmc_project/control/host0/boot"; |
| 3227 | static constexpr auto oneTimePath = |
| 3228 | "/xyz/openbmc_project/control/host0/boot/one_time"; |
| 3229 | static constexpr auto bootSourceProp = "BootSource"; |
| 3230 | static constexpr auto bootModeProp = "BootMode"; |
| 3231 | static constexpr auto oneTimeBootEnableProp = "Enabled"; |
| 3232 | static constexpr auto httpBootMode = |
| 3233 | "xyz.openbmc_project.Control.Boot.Source.Sources.Http"; |
| 3234 | |
| 3235 | enum class BootOptionParameter : size_t |
| 3236 | { |
| 3237 | setInProgress = 0x0, |
| 3238 | bootFlags = 0x5, |
| 3239 | }; |
| 3240 | static constexpr uint8_t setComplete = 0x0; |
| 3241 | static constexpr uint8_t setInProgress = 0x1; |
| 3242 | static uint8_t transferStatus = setComplete; |
| 3243 | static constexpr uint8_t setParmVersion = 0x01; |
| 3244 | static constexpr uint8_t setParmBootFlagsPermanent = 0x40; |
| 3245 | static constexpr uint8_t setParmBootFlagsValidOneTime = 0x80; |
| 3246 | static constexpr uint8_t setParmBootFlagsValidPermanent = 0xC0; |
| 3247 | static constexpr uint8_t httpBoot = 0xd; |
| 3248 | static constexpr uint8_t bootSourceMask = 0x3c; |
| 3249 | |
| 3250 | } // namespace boot_options |
| 3251 | |
| 3252 | ipmi::RspType<uint8_t, // version |
| 3253 | uint8_t, // param |
| 3254 | uint8_t, // data0, dependent on parameter |
| 3255 | std::optional<uint8_t> // data1, dependent on parameter |
| 3256 | > |
| 3257 | ipmiOemGetEfiBootOptions(uint8_t parameter, uint8_t set, uint8_t block) |
| 3258 | { |
| 3259 | using namespace boot_options; |
| 3260 | uint8_t bootOption = 0; |
| 3261 | |
| 3262 | if (parameter == static_cast<uint8_t>(BootOptionParameter::setInProgress)) |
| 3263 | { |
| 3264 | return ipmi::responseSuccess(setParmVersion, parameter, transferStatus, |
| 3265 | std::nullopt); |
| 3266 | } |
| 3267 | |
| 3268 | if (parameter != static_cast<uint8_t>(BootOptionParameter::bootFlags)) |
| 3269 | { |
| 3270 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3271 | "Unsupported parameter"); |
| 3272 | return ipmi::responseResponseError(); |
| 3273 | } |
| 3274 | |
| 3275 | try |
| 3276 | { |
| 3277 | auto oneTimeEnabled = false; |
| 3278 | // read one time Enabled property |
| 3279 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 3280 | std::string service = getService(*dbus, enabledIntf, oneTimePath); |
| 3281 | Value variant = getDbusProperty(*dbus, service, oneTimePath, |
| 3282 | enabledIntf, oneTimeBootEnableProp); |
| 3283 | oneTimeEnabled = std::get<bool>(variant); |
| 3284 | |
| 3285 | // get BootSource and BootMode properties |
| 3286 | // according to oneTimeEnable |
| 3287 | auto bootObjPath = oneTimePath; |
| 3288 | if (oneTimeEnabled == false) |
| 3289 | { |
| 3290 | bootObjPath = persistentObjPath; |
| 3291 | } |
| 3292 | |
| 3293 | service = getService(*dbus, bootModeIntf, bootObjPath); |
| 3294 | variant = getDbusProperty(*dbus, service, bootObjPath, bootModeIntf, |
| 3295 | bootModeProp); |
| 3296 | |
| 3297 | auto bootMode = |
| 3298 | Mode::convertModesFromString(std::get<std::string>(variant)); |
| 3299 | |
| 3300 | service = getService(*dbus, bootSourceIntf, bootObjPath); |
| 3301 | variant = getDbusProperty(*dbus, service, bootObjPath, bootSourceIntf, |
| 3302 | bootSourceProp); |
| 3303 | |
| 3304 | if (std::get<std::string>(variant) == httpBootMode) |
| 3305 | { |
| 3306 | bootOption = httpBoot; |
| 3307 | } |
| 3308 | else |
| 3309 | { |
| 3310 | auto bootSource = Source::convertSourcesFromString( |
| 3311 | std::get<std::string>(variant)); |
| 3312 | bootOption = sourceDbusToIpmi.at(bootSource); |
| 3313 | if (Source::Sources::Default == bootSource) |
| 3314 | { |
| 3315 | bootOption = modeDbusToIpmi.at(bootMode); |
| 3316 | } |
| 3317 | } |
| 3318 | |
| 3319 | uint8_t oneTime = oneTimeEnabled ? setParmBootFlagsValidOneTime |
| 3320 | : setParmBootFlagsValidPermanent; |
| 3321 | bootOption <<= 2; // shift for responseconstexpr |
| 3322 | return ipmi::responseSuccess(setParmVersion, parameter, oneTime, |
| 3323 | bootOption); |
| 3324 | } |
| 3325 | catch (sdbusplus::exception_t& e) |
| 3326 | { |
| 3327 | phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
| 3328 | return ipmi::responseResponseError(); |
| 3329 | } |
| 3330 | } |
| 3331 | |
| 3332 | ipmi::RspType<> ipmiOemSetEfiBootOptions(uint8_t bootFlag, uint8_t bootParam, |
| 3333 | std::optional<uint8_t> bootOption) |
| 3334 | { |
| 3335 | using namespace boot_options; |
| 3336 | auto oneTimeEnabled = false; |
| 3337 | |
| 3338 | if (bootFlag == static_cast<uint8_t>(BootOptionParameter::setInProgress)) |
| 3339 | { |
| 3340 | if (bootOption) |
| 3341 | { |
| 3342 | return ipmi::responseReqDataLenInvalid(); |
| 3343 | } |
| 3344 | |
| 3345 | if (transferStatus == setInProgress) |
| 3346 | { |
| 3347 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3348 | "boot option set in progress!"); |
| 3349 | return ipmi::responseResponseError(); |
| 3350 | } |
| 3351 | |
| 3352 | transferStatus = bootParam; |
| 3353 | return ipmi::responseSuccess(); |
| 3354 | } |
| 3355 | |
| 3356 | if (bootFlag != (uint8_t)BootOptionParameter::bootFlags) |
| 3357 | { |
| 3358 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3359 | "Unsupported parameter"); |
| 3360 | return ipmi::responseResponseError(); |
| 3361 | } |
| 3362 | |
| 3363 | if (!bootOption) |
| 3364 | { |
| 3365 | return ipmi::responseReqDataLenInvalid(); |
| 3366 | } |
| 3367 | |
| 3368 | if (((bootOption.value() & bootSourceMask) >> 2) != |
| 3369 | httpBoot) // not http boot, exit |
| 3370 | { |
| 3371 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3372 | "wrong boot option parameter!"); |
| 3373 | return ipmi::responseParmOutOfRange(); |
| 3374 | } |
| 3375 | |
| 3376 | try |
| 3377 | { |
| 3378 | bool permanent = (bootParam & setParmBootFlagsPermanent) == |
| 3379 | setParmBootFlagsPermanent; |
| 3380 | |
| 3381 | // read one time Enabled property |
| 3382 | std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus(); |
| 3383 | std::string service = getService(*dbus, enabledIntf, oneTimePath); |
| 3384 | Value variant = getDbusProperty(*dbus, service, oneTimePath, |
| 3385 | enabledIntf, oneTimeBootEnableProp); |
| 3386 | oneTimeEnabled = std::get<bool>(variant); |
| 3387 | |
| 3388 | /* |
| 3389 | * Check if the current boot setting is onetime or permanent, if the |
| 3390 | * request in the command is otherwise, then set the "Enabled" |
| 3391 | * property in one_time object path to 'True' to indicate onetime |
| 3392 | * and 'False' to indicate permanent. |
| 3393 | * |
| 3394 | * Once the onetime/permanent setting is applied, then the bootMode |
| 3395 | * and bootSource is updated for the corresponding object. |
| 3396 | */ |
| 3397 | if (permanent == oneTimeEnabled) |
| 3398 | { |
| 3399 | setDbusProperty(*dbus, service, oneTimePath, enabledIntf, |
| 3400 | oneTimeBootEnableProp, !permanent); |
| 3401 | } |
| 3402 | |
| 3403 | // set BootSource and BootMode properties |
| 3404 | // according to oneTimeEnable or persistent |
| 3405 | auto bootObjPath = oneTimePath; |
| 3406 | if (oneTimeEnabled == false) |
| 3407 | { |
| 3408 | bootObjPath = persistentObjPath; |
| 3409 | } |
| 3410 | std::string bootMode = |
| 3411 | "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; |
| 3412 | std::string bootSource = httpBootMode; |
| 3413 | |
| 3414 | service = getService(*dbus, bootModeIntf, bootObjPath); |
| 3415 | setDbusProperty(*dbus, service, bootObjPath, bootModeIntf, bootModeProp, |
| 3416 | bootMode); |
| 3417 | |
| 3418 | service = getService(*dbus, bootSourceIntf, bootObjPath); |
| 3419 | setDbusProperty(*dbus, service, bootObjPath, bootSourceIntf, |
| 3420 | bootSourceProp, bootSource); |
| 3421 | } |
| 3422 | catch (sdbusplus::exception_t& e) |
| 3423 | { |
| 3424 | phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
| 3425 | return ipmi::responseResponseError(); |
| 3426 | } |
| 3427 | |
| 3428 | return ipmi::responseSuccess(); |
| 3429 | } |
| 3430 | |
Cheng C Yang | 4e6ee15 | 2019-09-25 10:27:44 +0800 | [diff] [blame] | 3431 | using BasicVariantType = |
| 3432 | std::variant<std::vector<std::string>, std::vector<uint64_t>, std::string, |
| 3433 | int64_t, uint64_t, double, int32_t, uint32_t, int16_t, |
| 3434 | uint16_t, uint8_t, bool>; |
| 3435 | using PropertyMapType = |
| 3436 | boost::container::flat_map<std::string, BasicVariantType>; |
| 3437 | static constexpr const std::array<const char*, 1> psuPresenceTypes = { |
| 3438 | "xyz.openbmc_project.Configuration.PSUPresence"}; |
| 3439 | int getPSUAddress(ipmi::Context::ptr ctx, uint8_t& bus, |
| 3440 | std::vector<uint64_t>& addrTable) |
| 3441 | { |
| 3442 | boost::system::error_code ec; |
| 3443 | GetSubTreeType subtree = ctx->bus->yield_method_call<GetSubTreeType>( |
| 3444 | ctx->yield, ec, "xyz.openbmc_project.ObjectMapper", |
| 3445 | "/xyz/openbmc_project/object_mapper", |
| 3446 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
| 3447 | "/xyz/openbmc_project/inventory/system", 3, psuPresenceTypes); |
| 3448 | if (ec) |
| 3449 | { |
| 3450 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3451 | "Failed to set dbus property to cold redundancy"); |
| 3452 | return -1; |
| 3453 | } |
| 3454 | for (const auto& object : subtree) |
| 3455 | { |
| 3456 | std::string pathName = object.first; |
| 3457 | for (const auto& serviceIface : object.second) |
| 3458 | { |
| 3459 | std::string serviceName = serviceIface.first; |
| 3460 | |
| 3461 | ec.clear(); |
| 3462 | PropertyMapType propMap = |
| 3463 | ctx->bus->yield_method_call<PropertyMapType>( |
| 3464 | ctx->yield, ec, serviceName, pathName, |
| 3465 | "org.freedesktop.DBus.Properties", "GetAll", |
| 3466 | "xyz.openbmc_project.Configuration.PSUPresence"); |
| 3467 | if (ec) |
| 3468 | { |
| 3469 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 3470 | "Failed to set dbus property to cold redundancy"); |
| 3471 | return -1; |
| 3472 | } |
| 3473 | auto psuBus = std::get_if<uint64_t>(&propMap["Bus"]); |
| 3474 | auto psuAddress = |
| 3475 | std::get_if<std::vector<uint64_t>>(&propMap["Address"]); |
| 3476 | |
| 3477 | if (psuBus == nullptr || psuAddress == nullptr) |
| 3478 | { |
| 3479 | std::cerr << "error finding necessary " |
| 3480 | "entry in configuration\n"; |
| 3481 | return -1; |
| 3482 | } |
| 3483 | bus = static_cast<uint8_t>(*psuBus); |
| 3484 | addrTable = *psuAddress; |
| 3485 | return 0; |
| 3486 | } |
| 3487 | } |
| 3488 | return -1; |
| 3489 | } |
| 3490 | |
| 3491 | static const constexpr uint8_t addrOffset = 8; |
| 3492 | static const constexpr uint8_t psuRevision = 0xd9; |
| 3493 | static const constexpr uint8_t defaultPSUBus = 7; |
| 3494 | // Second Minor, Primary Minor, Major |
| 3495 | static const constexpr size_t verLen = 3; |
| 3496 | ipmi::RspType<std::vector<uint8_t>> ipmiOEMGetPSUVersion(ipmi::Context::ptr ctx) |
| 3497 | { |
| 3498 | uint8_t bus = defaultPSUBus; |
| 3499 | std::vector<uint64_t> addrTable; |
| 3500 | std::vector<uint8_t> result; |
| 3501 | if (getPSUAddress(ctx, bus, addrTable)) |
| 3502 | { |
| 3503 | std::cerr << "Failed to get PSU bus and address\n"; |
| 3504 | return ipmi::responseResponseError(); |
| 3505 | } |
| 3506 | |
| 3507 | for (const auto& slaveAddr : addrTable) |
| 3508 | { |
| 3509 | std::vector<uint8_t> writeData = {psuRevision}; |
| 3510 | std::vector<uint8_t> readBuf(verLen); |
| 3511 | uint8_t addr = static_cast<uint8_t>(slaveAddr) + addrOffset; |
| 3512 | std::string i2cBus = "/dev/i2c-" + std::to_string(bus); |
| 3513 | |
| 3514 | auto retI2C = ipmi::i2cWriteRead(i2cBus, addr, writeData, readBuf); |
| 3515 | if (retI2C != ipmi::ccSuccess) |
| 3516 | { |
| 3517 | for (size_t idx = 0; idx < verLen; idx++) |
| 3518 | { |
| 3519 | result.emplace_back(0x00); |
| 3520 | } |
| 3521 | } |
| 3522 | else |
| 3523 | { |
| 3524 | for (const uint8_t& data : readBuf) |
| 3525 | { |
| 3526 | result.emplace_back(data); |
| 3527 | } |
| 3528 | } |
| 3529 | } |
| 3530 | |
| 3531 | return ipmi::responseSuccess(result); |
| 3532 | } |
| 3533 | |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 3534 | /** @brief implements the maximum size of |
| 3535 | * bridgeable messages used between KCS and |
| 3536 | * IPMB interfacesget security mode command. |
| 3537 | * |
| 3538 | * @returns IPMI completion code with following data |
| 3539 | * - KCS Buffer Size (In multiples of four bytes) |
| 3540 | * - IPMB Buffer Size (In multiples of four bytes) |
| 3541 | **/ |
| 3542 | ipmi::RspType<uint8_t, uint8_t> ipmiOEMGetBufferSize() |
| 3543 | { |
| 3544 | // for now this is hard coded; really this number is dependent on |
| 3545 | // the BMC kcs driver as well as the host kcs driver.... |
| 3546 | // we can't know the latter. |
| 3547 | uint8_t kcsMaxBufferSize = 63 / 4; |
| 3548 | uint8_t ipmbMaxBufferSize = 128 / 4; |
| 3549 | |
| 3550 | return ipmi::responseSuccess(kcsMaxBufferSize, ipmbMaxBufferSize); |
| 3551 | } |
| 3552 | |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame] | 3553 | static void registerOEMFunctions(void) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 3554 | { |
| 3555 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 3556 | "Registering OEM commands"); |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3557 | ipmiPrintAndRegister(intel::netFnGeneral, |
| 3558 | intel::general::cmdGetChassisIdentifier, NULL, |
| 3559 | ipmiOEMGetChassisIdentifier, |
| 3560 | PRIVILEGE_USER); // get chassis identifier |
| 3561 | |
| 3562 | ipmiPrintAndRegister(intel::netFnGeneral, intel::general::cmdSetSystemGUID, |
| 3563 | NULL, ipmiOEMSetSystemGUID, |
| 3564 | PRIVILEGE_ADMIN); // set system guid |
Jason M. Bills | b02bf09 | 2019-08-15 13:01:56 -0700 | [diff] [blame] | 3565 | |
| 3566 | // <Disable BMC System Reset Action> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3567 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3568 | intel::general::cmdDisableBMCSystemReset, Privilege::Admin, |
| 3569 | ipmiOEMDisableBMCSystemReset); |
| 3570 | |
Jason M. Bills | b02bf09 | 2019-08-15 13:01:56 -0700 | [diff] [blame] | 3571 | // <Get BMC Reset Disables> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3572 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3573 | intel::general::cmdGetBMCResetDisables, Privilege::Admin, |
| 3574 | ipmiOEMGetBMCResetDisables); |
Jason M. Bills | b02bf09 | 2019-08-15 13:01:56 -0700 | [diff] [blame] | 3575 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3576 | ipmiPrintAndRegister(intel::netFnGeneral, intel::general::cmdSetBIOSID, |
| 3577 | NULL, ipmiOEMSetBIOSID, PRIVILEGE_ADMIN); |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 3578 | |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 3579 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3580 | intel::general::cmdGetOEMDeviceInfo, Privilege::User, |
| 3581 | ipmiOEMGetDeviceInfo); |
Jia, Chunhui | cc49b54 | 2019-03-20 15:41:07 +0800 | [diff] [blame] | 3582 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3583 | ipmiPrintAndRegister(intel::netFnGeneral, |
| 3584 | intel::general::cmdGetAICSlotFRUIDSlotPosRecords, NULL, |
| 3585 | ipmiOEMGetAICFRU, PRIVILEGE_USER); |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 3586 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3587 | registerHandler(prioOpenBmcBase, intel::netFnGeneral, |
| 3588 | intel::general::cmdSendEmbeddedFWUpdStatus, |
| 3589 | Privilege::Operator, ipmiOEMSendEmbeddedFwUpdStatus); |
Suryakanth Sekar | d509eb9 | 2018-11-15 17:44:11 +0530 | [diff] [blame] | 3590 | |
Rajashekar Gade Reddy | 2b664d5 | 2020-03-23 22:09:00 +0530 | [diff] [blame] | 3591 | registerHandler(prioOpenBmcBase, intel::netFnApp, intel::app::cmdSlotIpmb, |
| 3592 | Privilege::Admin, ipmiOEMSlotIpmb); |
| 3593 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3594 | ipmiPrintAndRegister(intel::netFnGeneral, |
| 3595 | intel::general::cmdSetPowerRestoreDelay, NULL, |
| 3596 | ipmiOEMSetPowerRestoreDelay, PRIVILEGE_OPERATOR); |
| 3597 | |
| 3598 | ipmiPrintAndRegister(intel::netFnGeneral, |
| 3599 | intel::general::cmdGetPowerRestoreDelay, NULL, |
| 3600 | ipmiOEMGetPowerRestoreDelay, PRIVILEGE_USER); |
| 3601 | |
| 3602 | registerHandler(prioOpenBmcBase, intel::netFnGeneral, |
| 3603 | intel::general::cmdSetOEMUser2Activation, |
| 3604 | Privilege::Callback, ipmiOEMSetUser2Activation); |
| 3605 | |
| 3606 | registerHandler(prioOpenBmcBase, intel::netFnGeneral, |
| 3607 | intel::general::cmdSetSpecialUserPassword, |
| 3608 | Privilege::Callback, ipmiOEMSetSpecialUserPassword); |
Richard Marian Thomaiyar | fc5e985 | 2019-04-14 15:06:27 +0530 | [diff] [blame] | 3609 | |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 3610 | // <Get Processor Error Config> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3611 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3612 | intel::general::cmdGetProcessorErrConfig, Privilege::User, |
| 3613 | ipmiOEMGetProcessorErrConfig); |
| 3614 | |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 3615 | // <Set Processor Error Config> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3616 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3617 | intel::general::cmdSetProcessorErrConfig, Privilege::Admin, |
| 3618 | ipmiOEMSetProcessorErrConfig); |
Jason M. Bills | 42bd9c8 | 2019-06-28 16:39:34 -0700 | [diff] [blame] | 3619 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3620 | ipmiPrintAndRegister(intel::netFnGeneral, |
| 3621 | intel::general::cmdSetShutdownPolicy, NULL, |
| 3622 | ipmiOEMSetShutdownPolicy, PRIVILEGE_ADMIN); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 3623 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3624 | ipmiPrintAndRegister(intel::netFnGeneral, |
| 3625 | intel::general::cmdGetShutdownPolicy, NULL, |
| 3626 | ipmiOEMGetShutdownPolicy, PRIVILEGE_ADMIN); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 3627 | |
anil kumar appana | f945eee | 2019-09-25 23:29:11 +0000 | [diff] [blame] | 3628 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3629 | intel::general::cmdSetFanConfig, Privilege::User, |
| 3630 | ipmiOEMSetFanConfig); |
James Feist | 91244a6 | 2019-02-19 15:04:54 -0800 | [diff] [blame] | 3631 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3632 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3633 | intel::general::cmdGetFanConfig, Privilege::User, |
| 3634 | ipmiOEMGetFanConfig); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 3635 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3636 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3637 | intel::general::cmdGetFanSpeedOffset, Privilege::User, |
| 3638 | ipmiOEMGetFanSpeedOffset); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 3639 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3640 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3641 | intel::general::cmdSetFanSpeedOffset, Privilege::User, |
| 3642 | ipmiOEMSetFanSpeedOffset); |
James Feist | acc8a4e | 2019-04-02 14:23:57 -0700 | [diff] [blame] | 3643 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3644 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3645 | intel::general::cmdSetFscParameter, Privilege::User, |
| 3646 | ipmiOEMSetFscParameter); |
James Feist | 5f957ca | 2019-03-14 15:33:55 -0700 | [diff] [blame] | 3647 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3648 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3649 | intel::general::cmdGetFscParameter, Privilege::User, |
| 3650 | ipmiOEMGetFscParameter); |
Richard Marian Thomaiyar | ea537d5 | 2019-04-24 21:33:48 +0530 | [diff] [blame] | 3651 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3652 | registerHandler(prioOpenBmcBase, intel::netFnGeneral, |
| 3653 | intel::general::cmdReadBaseBoardProductId, Privilege::Admin, |
| 3654 | ipmiOEMReadBoardProductId); |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 3655 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3656 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3657 | intel::general::cmdGetNmiStatus, Privilege::User, |
| 3658 | ipmiOEMGetNmiSource); |
Chen Yugang | 39736d5 | 2019-07-12 16:24:33 +0800 | [diff] [blame] | 3659 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3660 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3661 | intel::general::cmdSetNmiStatus, Privilege::Operator, |
| 3662 | ipmiOEMSetNmiSource); |
Chen,Yugang | 4f7e76b | 2019-08-20 09:28:06 +0800 | [diff] [blame] | 3663 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3664 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3665 | intel::general::cmdGetEfiBootOptions, Privilege::User, |
| 3666 | ipmiOemGetEfiBootOptions); |
Chen,Yugang | 4f7e76b | 2019-08-20 09:28:06 +0800 | [diff] [blame] | 3667 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3668 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3669 | intel::general::cmdSetEfiBootOptions, Privilege::Operator, |
| 3670 | ipmiOemSetEfiBootOptions); |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 3671 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3672 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3673 | intel::general::cmdGetSecurityMode, Privilege::User, |
| 3674 | ipmiGetSecurityMode); |
Richard Marian Thomaiyar | d801e46 | 2019-06-20 01:05:40 +0530 | [diff] [blame] | 3675 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3676 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3677 | intel::general::cmdSetSecurityMode, Privilege::Admin, |
| 3678 | ipmiSetSecurityMode); |
Vernon Mauery | 4ac799d | 2019-05-20 15:50:37 -0700 | [diff] [blame] | 3679 | |
NITIN SHARMA | abd11ca | 2019-06-12 12:31:42 +0000 | [diff] [blame] | 3680 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3681 | intel::general::cmdGetLEDStatus, Privilege::Admin, |
| 3682 | ipmiOEMGetLEDStatus); |
Cheng C Yang | 773703a | 2019-08-15 09:41:11 +0800 | [diff] [blame] | 3683 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3684 | ipmiPrintAndRegister(ipmi::intel::netFnPlatform, |
| 3685 | ipmi::intel::platform::cmdCfgHostSerialPortSpeed, NULL, |
| 3686 | ipmiOEMCfgHostSerialPortSpeed, PRIVILEGE_ADMIN); |
| 3687 | |
| 3688 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3689 | intel::general::cmdSetFaultIndication, Privilege::Operator, |
| 3690 | ipmiOEMSetFaultIndication); |
| 3691 | |
| 3692 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3693 | intel::general::cmdSetColdRedundancyConfig, Privilege::User, |
| 3694 | ipmiOEMSetCRConfig); |
| 3695 | |
| 3696 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3697 | intel::general::cmdGetColdRedundancyConfig, Privilege::User, |
| 3698 | ipmiOEMGetCRConfig); |
| 3699 | |
| 3700 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3701 | intel::general::cmdRestoreConfiguration, Privilege::Admin, |
Vernon Mauery | 4ac799d | 2019-05-20 15:50:37 -0700 | [diff] [blame] | 3702 | ipmiRestoreConfiguration); |
James Feist | 63efafa | 2019-07-24 12:39:21 -0700 | [diff] [blame] | 3703 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3704 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3705 | intel::general::cmdSetDimmOffset, Privilege::Operator, |
| 3706 | ipmiOEMSetDimmOffset); |
James Feist | 63efafa | 2019-07-24 12:39:21 -0700 | [diff] [blame] | 3707 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 3708 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3709 | intel::general::cmdGetDimmOffset, Privilege::Operator, |
| 3710 | ipmiOEMGetDimmOffset); |
Chen Yugang | ca12a7b | 2019-09-03 18:11:44 +0800 | [diff] [blame] | 3711 | |
Cheng C Yang | 4e6ee15 | 2019-09-25 10:27:44 +0800 | [diff] [blame] | 3712 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3713 | intel::general::cmdGetPSUVersion, Privilege::User, |
| 3714 | ipmiOEMGetPSUVersion); |
AppaRao Puli | 2897206 | 2019-11-11 02:04:45 +0530 | [diff] [blame] | 3715 | |
| 3716 | registerHandler(prioOemBase, intel::netFnGeneral, |
| 3717 | intel::general::cmdGetBufferSize, Privilege::User, |
| 3718 | ipmiOEMGetBufferSize); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 3719 | } |
| 3720 | |
| 3721 | } // namespace ipmi |