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