blob: deecca7155471e85deeb45d6b07f20c76b6ea343 [file] [log] [blame]
Jia, Chunhuia835eaa2018-09-05 09:00:41 +08001/*
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 Venturec2a07d42020-05-30 16:35:03 -070017#include "types.hpp"
Jason M. Bills64796042018-10-03 16:51:55 -070018#include "xyz/openbmc_project/Common/error.hpp"
Kuiying Wang45f04982018-12-26 09:23:08 +080019#include "xyz/openbmc_project/Led/Physical/server.hpp"
Jason M. Bills64796042018-10-03 16:51:55 -070020
Jayaprakash Mutyala94204162020-10-23 06:17:56 +000021#include <openssl/crypto.h>
Jia, Chunhuicc49b542019-03-20 15:41:07 +080022#include <systemd/sd-journal.h>
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080023
Chen Yugang7a04f3a2019-10-08 11:12:35 +080024#include <appcommands.hpp>
James Feist91244a62019-02-19 15:04:54 -080025#include <boost/container/flat_map.hpp>
Yong Li23737fe2019-02-19 08:49:55 +080026#include <boost/process/child.hpp>
27#include <boost/process/io.hpp>
Yong Li0669d192019-05-06 14:01:46 +080028#include <com/intel/Control/OCOTShutdownPolicy/server.hpp>
Jason M. Bills64796042018-10-03 16:51:55 -070029#include <commandutils.hpp>
Zhikui Rence4e73f2019-12-06 13:59:47 -080030#include <gpiod.hpp>
Jia, Chunhuicc49b542019-03-20 15:41:07 +080031#include <ipmid/api.hpp>
Vernon Mauery5480ef62019-03-20 13:43:11 -070032#include <ipmid/utils.hpp>
James Feist63efafa2019-07-24 12:39:21 -070033#include <nlohmann/json.hpp>
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080034#include <oemcommands.hpp>
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080035#include <phosphor-logging/log.hpp>
36#include <sdbusplus/bus.hpp>
Suryakanth Sekard509eb92018-11-15 17:44:11 +053037#include <sdbusplus/message/types.hpp>
Chen Yugang97cf96e2019-11-01 08:55:11 +080038#include <xyz/openbmc_project/Chassis/Control/NMISource/server.hpp>
Chen,Yugang4f7e76b2019-08-20 09:28:06 +080039#include <xyz/openbmc_project/Control/Boot/Mode/server.hpp>
40#include <xyz/openbmc_project/Control/Boot/Source/server.hpp>
Cheng C Yang773703a2019-08-15 09:41:11 +080041#include <xyz/openbmc_project/Control/PowerSupplyRedundancy/server.hpp>
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +053042#include <xyz/openbmc_project/Control/Security/RestrictionMode/server.hpp>
Richard Marian Thomaiyar8d4f8d72019-11-11 12:06:40 +053043#include <xyz/openbmc_project/Control/Security/SpecialMode/server.hpp>
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080044
James Feistfcd2d3a2020-05-28 10:38:15 -070045#include <array>
46#include <filesystem>
47#include <iostream>
48#include <regex>
49#include <string>
50#include <variant>
51#include <vector>
52
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080053namespace ipmi
54{
Jason M. Bills64796042018-10-03 16:51:55 -070055static void registerOEMFunctions() __attribute__((constructor));
Vernon Mauery4ac799d2019-05-20 15:50:37 -070056
Jason M. Bills64796042018-10-03 16:51:55 -070057static constexpr size_t maxFRUStringLength = 0x3F;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080058
Suryakanth Sekard509eb92018-11-15 17:44:11 +053059static constexpr auto ethernetIntf =
60 "xyz.openbmc_project.Network.EthernetInterface";
61static constexpr auto networkIPIntf = "xyz.openbmc_project.Network.IP";
62static constexpr auto networkService = "xyz.openbmc_project.Network";
63static constexpr auto networkRoot = "/xyz/openbmc_project/network";
64
Chen Yugang97cf96e2019-11-01 08:55:11 +080065static constexpr const char* oemNmiSourceIntf =
66 "xyz.openbmc_project.Chassis.Control.NMISource";
Chen Yugang39736d52019-07-12 16:24:33 +080067static constexpr const char* oemNmiSourceObjPath =
Chen Yugang97cf96e2019-11-01 08:55:11 +080068 "/xyz/openbmc_project/Chassis/Control/NMISource";
Chen Yugang39736d52019-07-12 16:24:33 +080069static constexpr const char* oemNmiBmcSourceObjPathProp = "BMCSource";
70static constexpr const char* oemNmiEnabledObjPathProp = "Enabled";
71
James Feist63efafa2019-07-24 12:39:21 -070072static constexpr const char* dimmOffsetFile = "/var/lib/ipmi/ipmi_dimms.json";
srikanta mondal2030d7c2020-05-03 17:25:25 +000073static constexpr const char* multiNodeObjPath =
74 "/xyz/openbmc_project/MultiNode/Status";
75static constexpr const char* multiNodeIntf =
76 "xyz.openbmc_project.Chassis.MultiNode";
James Feist63efafa2019-07-24 12:39:21 -070077
Chen Yugang39736d52019-07-12 16:24:33 +080078enum class NmiSource : uint8_t
79{
80 none = 0,
Chen Yugang97cf96e2019-11-01 08:55:11 +080081 frontPanelButton = 1,
82 watchdog = 2,
83 chassisCmd = 3,
84 memoryError = 4,
85 pciBusError = 5,
86 pch = 6,
87 chipset = 7,
Chen Yugang39736d52019-07-12 16:24:33 +080088};
89
Suryakanth Sekar822b0b42019-11-15 18:32:53 +053090enum class SpecialUserIndex : uint8_t
91{
92 rootUser = 0,
93 atScaleDebugUser = 1
94};
95
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +053096static constexpr const char* restricionModeService =
97 "xyz.openbmc_project.RestrictionMode.Manager";
98static constexpr const char* restricionModeBasePath =
99 "/xyz/openbmc_project/control/security/restriction_mode";
100static constexpr const char* restricionModeIntf =
101 "xyz.openbmc_project.Control.Security.RestrictionMode";
102static constexpr const char* restricionModeProperty = "RestrictionMode";
103
104static constexpr const char* specialModeService =
105 "xyz.openbmc_project.SpecialMode";
106static constexpr const char* specialModeBasePath =
Richard Marian Thomaiyara7b74282019-09-22 21:53:14 +0530107 "/xyz/openbmc_project/security/special_mode";
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +0530108static constexpr const char* specialModeIntf =
109 "xyz.openbmc_project.Security.SpecialMode";
110static constexpr const char* specialModeProperty = "SpecialMode";
111
112static constexpr const char* dBusPropertyIntf =
113 "org.freedesktop.DBus.Properties";
114static constexpr const char* dBusPropertyGetMethod = "Get";
115static constexpr const char* dBusPropertySetMethod = "Set";
116
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800117// return code: 0 successful
118int8_t getChassisSerialNumber(sdbusplus::bus::bus& bus, std::string& serial)
119{
120 std::string objpath = "/xyz/openbmc_project/FruDevice";
121 std::string intf = "xyz.openbmc_project.FruDeviceManager";
122 std::string service = getService(bus, intf, objpath);
123 ObjectValueTree valueTree = getManagedObjects(bus, service, "/");
124 if (valueTree.empty())
125 {
126 phosphor::logging::log<phosphor::logging::level::ERR>(
127 "No object implements interface",
128 phosphor::logging::entry("INTF=%s", intf.c_str()));
129 return -1;
130 }
131
Jason M. Bills64796042018-10-03 16:51:55 -0700132 for (const auto& item : valueTree)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800133 {
134 auto interface = item.second.find("xyz.openbmc_project.FruDevice");
135 if (interface == item.second.end())
136 {
137 continue;
138 }
139
140 auto property = interface->second.find("CHASSIS_SERIAL_NUMBER");
141 if (property == interface->second.end())
142 {
143 continue;
144 }
145
146 try
147 {
148 Value variant = property->second;
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700149 std::string& result = std::get<std::string>(variant);
Jason M. Bills64796042018-10-03 16:51:55 -0700150 if (result.size() > maxFRUStringLength)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800151 {
152 phosphor::logging::log<phosphor::logging::level::ERR>(
153 "FRU serial number exceed maximum length");
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800154 return -1;
155 }
Jason M. Bills64796042018-10-03 16:51:55 -0700156 serial = result;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800157 return 0;
158 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -0500159 catch (const std::bad_variant_access& e)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800160 {
Jason M. Bills64796042018-10-03 16:51:55 -0700161 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800162 return -1;
163 }
164 }
165 return -1;
166}
Jason M. Bills64796042018-10-03 16:51:55 -0700167
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800168// Returns the Chassis Identifier (serial #)
169ipmi_ret_t ipmiOEMGetChassisIdentifier(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
170 ipmi_request_t request,
171 ipmi_response_t response,
Jason M. Bills64796042018-10-03 16:51:55 -0700172 ipmi_data_len_t dataLen,
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800173 ipmi_context_t context)
174{
175 std::string serial;
Jason M. Bills64796042018-10-03 16:51:55 -0700176 if (*dataLen != 0) // invalid request if there are extra parameters
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800177 {
Jason M. Bills64796042018-10-03 16:51:55 -0700178 *dataLen = 0;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800179 return IPMI_CC_REQ_DATA_LEN_INVALID;
180 }
Vernon Mauery15419dd2019-05-24 09:40:30 -0700181 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
182 if (getChassisSerialNumber(*dbus, serial) == 0)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800183 {
Jason M. Bills64796042018-10-03 16:51:55 -0700184 *dataLen = serial.size(); // length will never exceed response length
185 // as it is checked in getChassisSerialNumber
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800186 char* resp = static_cast<char*>(response);
Jason M. Bills64796042018-10-03 16:51:55 -0700187 serial.copy(resp, *dataLen);
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800188 return IPMI_CC_OK;
189 }
Jason M. Bills64796042018-10-03 16:51:55 -0700190 *dataLen = 0;
191 return IPMI_CC_RESPONSE_ERROR;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800192}
193
194ipmi_ret_t ipmiOEMSetSystemGUID(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
195 ipmi_request_t request,
196 ipmi_response_t response,
Jason M. Bills64796042018-10-03 16:51:55 -0700197 ipmi_data_len_t dataLen, ipmi_context_t context)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800198{
199 static constexpr size_t safeBufferLength = 50;
200 char buf[safeBufferLength] = {0};
201 GUIDData* Data = reinterpret_cast<GUIDData*>(request);
202
Jason M. Bills64796042018-10-03 16:51:55 -0700203 if (*dataLen != sizeof(GUIDData)) // 16bytes
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800204 {
Jason M. Bills64796042018-10-03 16:51:55 -0700205 *dataLen = 0;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800206 return IPMI_CC_REQ_DATA_LEN_INVALID;
207 }
208
Jason M. Bills64796042018-10-03 16:51:55 -0700209 *dataLen = 0;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800210
211 snprintf(
212 buf, safeBufferLength,
213 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
214 Data->timeLow4, Data->timeLow3, Data->timeLow2, Data->timeLow1,
215 Data->timeMid2, Data->timeMid1, Data->timeHigh2, Data->timeHigh1,
216 Data->clock2, Data->clock1, Data->node6, Data->node5, Data->node4,
217 Data->node3, Data->node2, Data->node1);
218 // UUID is in RFC4122 format. Ex: 61a39523-78f2-11e5-9862-e6402cfc3223
219 std::string guid = buf;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800220
221 std::string objpath = "/xyz/openbmc_project/control/host0/systemGUID";
222 std::string intf = "xyz.openbmc_project.Common.UUID";
Vernon Mauery15419dd2019-05-24 09:40:30 -0700223 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
224 std::string service = getService(*dbus, intf, objpath);
225 setDbusProperty(*dbus, service, objpath, intf, "UUID", guid);
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800226 return IPMI_CC_OK;
227}
228
Jason M. Billsb02bf092019-08-15 13:01:56 -0700229ipmi::RspType<> ipmiOEMDisableBMCSystemReset(bool disableResetOnSMI,
230 uint7_t reserved1)
231{
Jayaprakash Mutyala0a652fa2021-07-01 17:09:39 +0000232 if (reserved1)
233 {
234 return ipmi::responseInvalidFieldRequest();
235 }
236
Jason M. Billsb02bf092019-08-15 13:01:56 -0700237 std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
238
239 try
240 {
241 auto service =
242 ipmi::getService(*busp, bmcResetDisablesIntf, bmcResetDisablesPath);
243 ipmi::setDbusProperty(*busp, service, bmcResetDisablesPath,
244 bmcResetDisablesIntf, "ResetOnSMI",
245 !disableResetOnSMI);
246 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -0500247 catch (const std::exception& e)
Jason M. Billsb02bf092019-08-15 13:01:56 -0700248 {
249 phosphor::logging::log<phosphor::logging::level::ERR>(
250 "Failed to set BMC reset disables",
251 phosphor::logging::entry("EXCEPTION=%s", e.what()));
252 return ipmi::responseUnspecifiedError();
253 }
254
255 return ipmi::responseSuccess();
256}
257
258ipmi::RspType<bool, // disableResetOnSMI
259 uint7_t // reserved
260 >
261 ipmiOEMGetBMCResetDisables()
262{
263 bool disableResetOnSMI = true;
264
265 std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
266 try
267 {
268 auto service =
269 ipmi::getService(*busp, bmcResetDisablesIntf, bmcResetDisablesPath);
270 Value variant =
271 ipmi::getDbusProperty(*busp, service, bmcResetDisablesPath,
272 bmcResetDisablesIntf, "ResetOnSMI");
273 disableResetOnSMI = !std::get<bool>(variant);
274 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -0500275 catch (const std::exception& e)
Jason M. Billsb02bf092019-08-15 13:01:56 -0700276 {
277 phosphor::logging::log<phosphor::logging::level::ERR>(
278 "Failed to get BMC reset disables",
279 phosphor::logging::entry("EXCEPTION=%s", e.what()));
280 return ipmi::responseUnspecifiedError();
281 }
282
283 return ipmi::responseSuccess(disableResetOnSMI, 0);
284}
285
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800286ipmi_ret_t ipmiOEMSetBIOSID(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
287 ipmi_request_t request, ipmi_response_t response,
288 ipmi_data_len_t dataLen, ipmi_context_t context)
289{
290 DeviceInfo* data = reinterpret_cast<DeviceInfo*>(request);
291
Jason M. Bills64796042018-10-03 16:51:55 -0700292 if ((*dataLen < 2) || (*dataLen != (1 + data->biosIDLength)))
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800293 {
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800294 *dataLen = 0;
295 return IPMI_CC_REQ_DATA_LEN_INVALID;
296 }
Jason M. Bills64796042018-10-03 16:51:55 -0700297 std::string idString((char*)data->biosId, data->biosIDLength);
Chalapathi Venkataramashettyfb9f1aa2021-05-07 08:37:07 +0000298 for (auto idChar : idString)
299 {
300 if (!std::isprint(static_cast<unsigned char>(idChar)))
301 {
302 phosphor::logging::log<phosphor::logging::level::ERR>(
303 "BIOS ID contains non printable character");
304 return IPMI_CC_INVALID_FIELD_REQUEST;
305 }
306 }
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800307
Vernon Mauery15419dd2019-05-24 09:40:30 -0700308 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Chalapathi899bfd12020-04-15 15:07:02 +0000309 std::string service = getService(*dbus, biosVersionIntf, biosActiveObjPath);
310 setDbusProperty(*dbus, service, biosActiveObjPath, biosVersionIntf,
Yong Li2742b852019-12-16 14:55:11 +0800311 biosVersionProp, idString);
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800312 uint8_t* bytesWritten = static_cast<uint8_t*>(response);
313 *bytesWritten =
Jason M. Bills64796042018-10-03 16:51:55 -0700314 data->biosIDLength; // how many bytes are written into storage
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800315 *dataLen = 1;
316 return IPMI_CC_OK;
317}
318
AppaRao Pulie99e7ed2020-01-17 12:27:10 +0530319bool getSwVerInfo(ipmi::Context::ptr ctx, uint8_t& bmcMajor, uint8_t& bmcMinor,
320 uint8_t& meMajor, uint8_t& meMinor)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800321{
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800322 // step 1 : get BMC Major and Minor numbers from its DBUS property
AppaRao Pulie99e7ed2020-01-17 12:27:10 +0530323 std::string bmcVersion;
324 if (getActiveSoftwareVersionInfo(ctx, versionPurposeBMC, bmcVersion))
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800325 {
326 return false;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800327 }
328
AppaRao Pulie99e7ed2020-01-17 12:27:10 +0530329 std::optional<MetaRevision> rev = convertIntelVersion(bmcVersion);
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800330 if (rev.has_value())
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800331 {
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800332 MetaRevision revision = rev.value();
333 bmcMajor = revision.major;
334
335 revision.minor = (revision.minor > 99 ? 99 : revision.minor);
336 bmcMinor = revision.minor % 10 + (revision.minor / 10) * 16;
337 }
338
339 // step 2 : get ME Major and Minor numbers from its DBUS property
AppaRao Puli32825a22020-01-17 15:52:41 +0530340 std::string meVersion;
341 if (getActiveSoftwareVersionInfo(ctx, versionPurposeME, meVersion))
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800342 {
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800343 return false;
344 }
AppaRao Puli32825a22020-01-17 15:52:41 +0530345 std::regex pattern1("(\\d+?).(\\d+?).(\\d+?).(\\d+?).(\\d+?)");
346 constexpr size_t matchedPhosphor = 6;
347 std::smatch results;
348 if (std::regex_match(meVersion, results, pattern1))
349 {
350 if (results.size() == matchedPhosphor)
351 {
352 meMajor = static_cast<uint8_t>(std::stoi(results[1]));
Jayaprakash Mutyalad0657022021-08-26 21:18:08 +0000353 meMinor = static_cast<uint8_t>(std::stoi(results[2]) << 4 |
354 std::stoi(results[3]));
AppaRao Puli32825a22020-01-17 15:52:41 +0530355 }
356 }
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800357 return true;
358}
359
360ipmi::RspType<
361 std::variant<std::string,
362 std::tuple<uint8_t, std::array<uint8_t, 2>,
363 std::array<uint8_t, 2>, std::array<uint8_t, 2>,
364 std::array<uint8_t, 2>, std::array<uint8_t, 2>>,
365 std::tuple<uint8_t, std::array<uint8_t, 2>>>>
AppaRao Pulie99e7ed2020-01-17 12:27:10 +0530366 ipmiOEMGetDeviceInfo(ipmi::Context::ptr ctx, uint8_t entityType,
367 std::optional<uint8_t> countToRead,
AppaRao Pulid46cb422020-01-21 18:40:21 +0530368 std::optional<uint8_t> offset)
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800369{
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800370 if (entityType > static_cast<uint8_t>(OEMDevEntityType::sdrVer))
371 {
372 return ipmi::responseInvalidFieldRequest();
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800373 }
374
375 // handle OEM command items
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800376 switch (OEMDevEntityType(entityType))
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800377 {
378 case OEMDevEntityType::biosId:
379 {
AppaRao Pulid46cb422020-01-21 18:40:21 +0530380 // Byte 2&3, Only used with selecting BIOS
381 if (!countToRead || !offset)
382 {
383 return ipmi::responseReqDataLenInvalid();
384 }
385
Vernon Mauery15419dd2019-05-24 09:40:30 -0700386 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Yong Li2742b852019-12-16 14:55:11 +0800387 std::string service =
Chalapathi899bfd12020-04-15 15:07:02 +0000388 getService(*dbus, biosVersionIntf, biosActiveObjPath);
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800389 try
390 {
Yong Li2742b852019-12-16 14:55:11 +0800391 Value variant =
Chalapathi899bfd12020-04-15 15:07:02 +0000392 getDbusProperty(*dbus, service, biosActiveObjPath,
Yong Li2742b852019-12-16 14:55:11 +0800393 biosVersionIntf, biosVersionProp);
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700394 std::string& idString = std::get<std::string>(variant);
AppaRao Pulid46cb422020-01-21 18:40:21 +0530395 if (*offset >= idString.size())
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800396 {
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800397 return ipmi::responseParmOutOfRange();
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800398 }
Jason M. Bills64796042018-10-03 16:51:55 -0700399 size_t length = 0;
AppaRao Pulid46cb422020-01-21 18:40:21 +0530400 if (*countToRead > (idString.size() - *offset))
Jason M. Bills64796042018-10-03 16:51:55 -0700401 {
AppaRao Pulid46cb422020-01-21 18:40:21 +0530402 length = idString.size() - *offset;
Jason M. Bills64796042018-10-03 16:51:55 -0700403 }
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800404 else
405 {
AppaRao Pulid46cb422020-01-21 18:40:21 +0530406 length = *countToRead;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800407 }
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800408
409 std::string readBuf = {0};
410 readBuf.resize(length);
AppaRao Pulid46cb422020-01-21 18:40:21 +0530411 std::copy_n(idString.begin() + *offset, length,
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800412 (readBuf.begin()));
413 return ipmi::responseSuccess(readBuf);
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800414 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -0500415 catch (const std::bad_variant_access& e)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800416 {
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800417 return ipmi::responseUnspecifiedError();
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800418 }
419 }
420 break;
421
422 case OEMDevEntityType::devVer:
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800423 {
AppaRao Pulid46cb422020-01-21 18:40:21 +0530424 // Byte 2&3, Only used with selecting BIOS
425 if (countToRead || offset)
426 {
427 return ipmi::responseReqDataLenInvalid();
428 }
429
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800430 constexpr const size_t verLen = 2;
431 constexpr const size_t verTotalLen = 10;
432 std::array<uint8_t, verLen> bmcBuf = {0xff, 0xff};
433 std::array<uint8_t, verLen> hsc0Buf = {0xff, 0xff};
434 std::array<uint8_t, verLen> hsc1Buf = {0xff, 0xff};
435 std::array<uint8_t, verLen> meBuf = {0xff, 0xff};
436 std::array<uint8_t, verLen> hsc2Buf = {0xff, 0xff};
437 // data0/1: BMC version number; data6/7: ME version number
438 // the others: HSC0/1/2 version number, not avaible.
AppaRao Pulie99e7ed2020-01-17 12:27:10 +0530439 if (!getSwVerInfo(ctx, bmcBuf[0], bmcBuf[1], meBuf[0], meBuf[1]))
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800440 {
441 return ipmi::responseUnspecifiedError();
442 }
443 return ipmi::responseSuccess(
444 std::tuple<
445 uint8_t, std::array<uint8_t, verLen>,
446 std::array<uint8_t, verLen>, std::array<uint8_t, verLen>,
447 std::array<uint8_t, verLen>, std::array<uint8_t, verLen>>{
448 verTotalLen, bmcBuf, hsc0Buf, hsc1Buf, meBuf, hsc2Buf});
449 }
450 break;
451
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800452 case OEMDevEntityType::sdrVer:
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800453 {
AppaRao Pulid46cb422020-01-21 18:40:21 +0530454 // Byte 2&3, Only used with selecting BIOS
455 if (countToRead || offset)
456 {
457 return ipmi::responseReqDataLenInvalid();
458 }
459
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800460 constexpr const size_t sdrLen = 2;
461 std::array<uint8_t, sdrLen> readBuf = {0x01, 0x0};
462 return ipmi::responseSuccess(
463 std::tuple<uint8_t, std::array<uint8_t, sdrLen>>{sdrLen,
464 readBuf});
465 }
466 break;
467
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800468 default:
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800469 return ipmi::responseInvalidFieldRequest();
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800470 }
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800471}
472
473ipmi_ret_t ipmiOEMGetAICFRU(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
474 ipmi_request_t request, ipmi_response_t response,
475 ipmi_data_len_t dataLen, ipmi_context_t context)
476{
477 if (*dataLen != 0)
478 {
Jason M. Bills64796042018-10-03 16:51:55 -0700479 *dataLen = 0;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800480 return IPMI_CC_REQ_DATA_LEN_INVALID;
481 }
482
483 *dataLen = 1;
484 uint8_t* res = reinterpret_cast<uint8_t*>(response);
485 // temporary fix. We don't support AIC FRU now. Just tell BIOS that no
486 // AIC is available so that BIOS will not timeout repeatly which leads to
487 // slow booting.
488 *res = 0; // Byte1=Count of SlotPosition/FruID records.
489 return IPMI_CC_OK;
490}
491
Jason M. Bills64796042018-10-03 16:51:55 -0700492ipmi_ret_t ipmiOEMGetPowerRestoreDelay(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
493 ipmi_request_t request,
494 ipmi_response_t response,
495 ipmi_data_len_t dataLen,
496 ipmi_context_t context)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800497{
Jason M. Bills64796042018-10-03 16:51:55 -0700498 GetPowerRestoreDelayRes* resp =
499 reinterpret_cast<GetPowerRestoreDelayRes*>(response);
500
501 if (*dataLen != 0)
502 {
503 *dataLen = 0;
504 return IPMI_CC_REQ_DATA_LEN_INVALID;
505 }
506
Vernon Mauery15419dd2019-05-24 09:40:30 -0700507 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Jason M. Bills64796042018-10-03 16:51:55 -0700508 std::string service =
Vernon Mauery15419dd2019-05-24 09:40:30 -0700509 getService(*dbus, powerRestoreDelayIntf, powerRestoreDelayObjPath);
Jason M. Bills64796042018-10-03 16:51:55 -0700510 Value variant =
Vernon Mauery15419dd2019-05-24 09:40:30 -0700511 getDbusProperty(*dbus, service, powerRestoreDelayObjPath,
Jason M. Bills64796042018-10-03 16:51:55 -0700512 powerRestoreDelayIntf, powerRestoreDelayProp);
513
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700514 uint16_t delay = std::get<uint16_t>(variant);
Jason M. Bills64796042018-10-03 16:51:55 -0700515 resp->byteLSB = delay;
516 resp->byteMSB = delay >> 8;
517
518 *dataLen = sizeof(GetPowerRestoreDelayRes);
519
520 return IPMI_CC_OK;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800521}
522
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800523static uint8_t bcdToDec(uint8_t val)
524{
525 return ((val / 16 * 10) + (val % 16));
526}
527
528// Allows an update utility or system BIOS to send the status of an embedded
529// firmware update attempt to the BMC. After received, BMC will create a logging
530// record.
531ipmi::RspType<> ipmiOEMSendEmbeddedFwUpdStatus(uint8_t status, uint8_t target,
532 uint8_t majorRevision,
533 uint8_t minorRevision,
534 uint32_t auxInfo)
535{
536 std::string firmware;
Jason M. Billsdc249272019-04-03 09:58:40 -0700537 int instance = (target & targetInstanceMask) >> targetInstanceShift;
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800538 target = (target & selEvtTargetMask) >> selEvtTargetShift;
539
540 /* make sure the status is 0, 1, or 2 as per the spec */
541 if (status > 2)
542 {
543 return ipmi::response(ipmi::ccInvalidFieldRequest);
544 }
Jason M. Billsdc249272019-04-03 09:58:40 -0700545 /* make sure the target is 0, 1, 2, or 4 as per the spec */
546 if (target > 4 || target == 3)
547 {
548 return ipmi::response(ipmi::ccInvalidFieldRequest);
549 }
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800550 /*orignal OEM command is to record OEM SEL.
551 But openbmc does not support OEM SEL, so we redirect it to redfish event
552 logging. */
553 std::string buildInfo;
554 std::string action;
555 switch (FWUpdateTarget(target))
556 {
557 case FWUpdateTarget::targetBMC:
558 firmware = "BMC";
Jason M. Billsdc249272019-04-03 09:58:40 -0700559 buildInfo = "major: " + std::to_string(majorRevision) + " minor: " +
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800560 std::to_string(bcdToDec(minorRevision)) + // BCD encoded
561 " BuildID: " + std::to_string(auxInfo);
562 buildInfo += std::to_string(auxInfo);
563 break;
564 case FWUpdateTarget::targetBIOS:
565 firmware = "BIOS";
566 buildInfo =
Jason M. Billsdc249272019-04-03 09:58:40 -0700567 "major: " +
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800568 std::to_string(bcdToDec(majorRevision)) + // BCD encoded
569 " minor: " +
570 std::to_string(bcdToDec(minorRevision)) + // BCD encoded
571 " ReleaseNumber: " + // ASCII encoded
572 std::to_string(static_cast<uint8_t>(auxInfo >> 0) - '0') +
573 std::to_string(static_cast<uint8_t>(auxInfo >> 8) - '0') +
574 std::to_string(static_cast<uint8_t>(auxInfo >> 16) - '0') +
575 std::to_string(static_cast<uint8_t>(auxInfo >> 24) - '0');
576 break;
577 case FWUpdateTarget::targetME:
578 firmware = "ME";
579 buildInfo =
Jason M. Billsdc249272019-04-03 09:58:40 -0700580 "major: " + std::to_string(majorRevision) + " minor1: " +
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800581 std::to_string(bcdToDec(minorRevision)) + // BCD encoded
582 " minor2: " +
583 std::to_string(bcdToDec(static_cast<uint8_t>(auxInfo >> 0))) +
584 " build1: " +
585 std::to_string(bcdToDec(static_cast<uint8_t>(auxInfo >> 8))) +
586 " build2: " +
587 std::to_string(bcdToDec(static_cast<uint8_t>(auxInfo >> 16)));
588 break;
589 case FWUpdateTarget::targetOEMEWS:
590 firmware = "EWS";
Jason M. Billsdc249272019-04-03 09:58:40 -0700591 buildInfo = "major: " + std::to_string(majorRevision) + " minor: " +
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800592 std::to_string(bcdToDec(minorRevision)) + // BCD encoded
593 " BuildID: " + std::to_string(auxInfo);
594 break;
595 }
596
Jason M. Billsdc249272019-04-03 09:58:40 -0700597 static const std::string openBMCMessageRegistryVersion("0.1");
598 std::string redfishMsgID = "OpenBMC." + openBMCMessageRegistryVersion;
599
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800600 switch (status)
601 {
602 case 0x0:
603 action = "update started";
Jason M. Billsdc249272019-04-03 09:58:40 -0700604 redfishMsgID += ".FirmwareUpdateStarted";
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800605 break;
606 case 0x1:
607 action = "update completed successfully";
Jason M. Billsdc249272019-04-03 09:58:40 -0700608 redfishMsgID += ".FirmwareUpdateCompleted";
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800609 break;
610 case 0x2:
611 action = "update failure";
Jason M. Billsdc249272019-04-03 09:58:40 -0700612 redfishMsgID += ".FirmwareUpdateFailed";
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800613 break;
614 default:
615 action = "unknown";
616 break;
617 }
618
Jason M. Billsdc249272019-04-03 09:58:40 -0700619 std::string firmwareInstanceStr =
620 firmware + " instance: " + std::to_string(instance);
621 std::string message("[firmware update] " + firmwareInstanceStr +
622 " status: <" + action + "> " + buildInfo);
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800623
624 sd_journal_send("MESSAGE=%s", message.c_str(), "PRIORITY=%i", LOG_INFO,
Jason M. Billsdc249272019-04-03 09:58:40 -0700625 "REDFISH_MESSAGE_ID=%s", redfishMsgID.c_str(),
626 "REDFISH_MESSAGE_ARGS=%s,%s", firmwareInstanceStr.c_str(),
627 buildInfo.c_str(), NULL);
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800628 return ipmi::responseSuccess();
629}
630
Rajashekar Gade Reddy2b664d52020-03-23 22:09:00 +0530631ipmi::RspType<uint8_t, std::vector<uint8_t>>
632 ipmiOEMSlotIpmb(ipmi::Context::ptr ctx, uint6_t reserved1,
633 uint2_t slotNumber, uint3_t baseBoardSlotNum,
634 uint3_t riserSlotNum, uint2_t reserved2, uint8_t slaveAddr,
635 uint8_t netFn, uint8_t cmd,
636 std::optional<std::vector<uint8_t>> writeData)
637{
638 if (reserved1 || reserved2)
639 {
640 return ipmi::responseInvalidFieldRequest();
641 }
642
643 boost::system::error_code ec;
644 using ipmbResponse = std::tuple<int, uint8_t, uint8_t, uint8_t, uint8_t,
645 std::vector<uint8_t>>;
646 ipmbResponse res = ctx->bus->yield_method_call<ipmbResponse>(
647 ctx->yield, ec, "xyz.openbmc_project.Ipmi.Channel.Ipmb",
648 "/xyz/openbmc_project/Ipmi/Channel/Ipmb", "org.openbmc.Ipmb",
649 "SlotIpmbRequest", static_cast<uint8_t>(slotNumber),
650 static_cast<uint8_t>(baseBoardSlotNum), slaveAddr, netFn, cmd,
651 *writeData);
652 if (ec)
653 {
654 phosphor::logging::log<phosphor::logging::level::ERR>(
655 "Failed to call dbus method SlotIpmbRequest");
656 return ipmi::responseUnspecifiedError();
657 }
658
659 std::vector<uint8_t> dataReceived(0);
660 int status = -1;
661 uint8_t resNetFn = 0, resLun = 0, resCmd = 0, cc = 0;
662
663 std::tie(status, resNetFn, resLun, resCmd, cc, dataReceived) = res;
664
665 if (status)
666 {
667 phosphor::logging::log<phosphor::logging::level::ERR>(
668 "Failed to get response from SlotIpmbRequest");
669 return ipmi::responseResponseError();
670 }
671 return ipmi::responseSuccess(cc, dataReceived);
672}
673
Jason M. Bills64796042018-10-03 16:51:55 -0700674ipmi_ret_t ipmiOEMSetPowerRestoreDelay(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
675 ipmi_request_t request,
676 ipmi_response_t response,
677 ipmi_data_len_t dataLen,
678 ipmi_context_t context)
679{
680 SetPowerRestoreDelayReq* data =
681 reinterpret_cast<SetPowerRestoreDelayReq*>(request);
682 uint16_t delay = 0;
683
684 if (*dataLen != sizeof(SetPowerRestoreDelayReq))
685 {
686 *dataLen = 0;
687 return IPMI_CC_REQ_DATA_LEN_INVALID;
688 }
689 delay = data->byteMSB;
690 delay = (delay << 8) | data->byteLSB;
Vernon Mauery15419dd2019-05-24 09:40:30 -0700691 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Jason M. Bills64796042018-10-03 16:51:55 -0700692 std::string service =
Vernon Mauery15419dd2019-05-24 09:40:30 -0700693 getService(*dbus, powerRestoreDelayIntf, powerRestoreDelayObjPath);
694 setDbusProperty(*dbus, service, powerRestoreDelayObjPath,
Jason M. Bills64796042018-10-03 16:51:55 -0700695 powerRestoreDelayIntf, powerRestoreDelayProp, delay);
696 *dataLen = 0;
697
698 return IPMI_CC_OK;
699}
700
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700701static bool cpuPresent(const std::string& cpuName)
Jason M. Bills64796042018-10-03 16:51:55 -0700702{
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700703 static constexpr const char* cpuPresencePathPrefix =
704 "/xyz/openbmc_project/inventory/system/chassis/motherboard/";
705 static constexpr const char* cpuPresenceIntf =
706 "xyz.openbmc_project.Inventory.Item";
707 std::string cpuPresencePath = cpuPresencePathPrefix + cpuName;
708 std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
709 try
Jason M. Bills64796042018-10-03 16:51:55 -0700710 {
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700711 auto service =
712 ipmi::getService(*busp, cpuPresenceIntf, cpuPresencePath);
713
714 ipmi::Value result = ipmi::getDbusProperty(
715 *busp, service, cpuPresencePath, cpuPresenceIntf, "Present");
716 return std::get<bool>(result);
717 }
718 catch (const std::exception& e)
719 {
720 phosphor::logging::log<phosphor::logging::level::INFO>(
721 "Cannot find processor presence",
722 phosphor::logging::entry("NAME=%s", cpuName.c_str()));
723 return false;
724 }
725}
726
727ipmi::RspType<bool, // CATERR Reset Enabled
728 bool, // ERR2 Reset Enabled
729 uint6_t, // reserved
730 uint8_t, // reserved, returns 0x3F
731 uint6_t, // CPU1 CATERR Count
732 uint2_t, // CPU1 Status
733 uint6_t, // CPU2 CATERR Count
734 uint2_t, // CPU2 Status
735 uint6_t, // CPU3 CATERR Count
736 uint2_t, // CPU3 Status
737 uint6_t, // CPU4 CATERR Count
738 uint2_t, // CPU4 Status
739 uint8_t // Crashdump Count
740 >
741 ipmiOEMGetProcessorErrConfig()
742{
743 bool resetOnCATERR = false;
744 bool resetOnERR2 = false;
745 uint6_t cpu1CATERRCount = 0;
746 uint6_t cpu2CATERRCount = 0;
747 uint6_t cpu3CATERRCount = 0;
748 uint6_t cpu4CATERRCount = 0;
749 uint8_t crashdumpCount = 0;
Jason M. Bills24df90f2021-06-15 12:46:13 -0700750 uint2_t cpu1Status = cpuPresent("CPU_1")
751 ? types::enum_cast<uint8_t>(CPUStatus::enabled)
752 : types::enum_cast<uint8_t>(CPUStatus::notPresent);
753 uint2_t cpu2Status = cpuPresent("CPU_2")
754 ? types::enum_cast<uint8_t>(CPUStatus::enabled)
755 : types::enum_cast<uint8_t>(CPUStatus::notPresent);
756 uint2_t cpu3Status = cpuPresent("CPU_3")
757 ? types::enum_cast<uint8_t>(CPUStatus::enabled)
758 : types::enum_cast<uint8_t>(CPUStatus::notPresent);
759 uint2_t cpu4Status = cpuPresent("CPU_4")
760 ? types::enum_cast<uint8_t>(CPUStatus::enabled)
761 : types::enum_cast<uint8_t>(CPUStatus::notPresent);
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700762
763 std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
764 try
765 {
766 auto service = ipmi::getService(*busp, processorErrConfigIntf,
767 processorErrConfigObjPath);
768
769 ipmi::PropertyMap result = ipmi::getAllDbusProperties(
770 *busp, service, processorErrConfigObjPath, processorErrConfigIntf);
771 resetOnCATERR = std::get<bool>(result.at("ResetOnCATERR"));
772 resetOnERR2 = std::get<bool>(result.at("ResetOnERR2"));
773 cpu1CATERRCount = std::get<uint8_t>(result.at("ErrorCountCPU1"));
774 cpu2CATERRCount = std::get<uint8_t>(result.at("ErrorCountCPU2"));
775 cpu3CATERRCount = std::get<uint8_t>(result.at("ErrorCountCPU3"));
776 cpu4CATERRCount = std::get<uint8_t>(result.at("ErrorCountCPU4"));
777 crashdumpCount = std::get<uint8_t>(result.at("CrashdumpCount"));
778 }
779 catch (const std::exception& e)
780 {
781 phosphor::logging::log<phosphor::logging::level::ERR>(
782 "Failed to fetch processor error config",
783 phosphor::logging::entry("ERROR=%s", e.what()));
784 return ipmi::responseUnspecifiedError();
Jason M. Bills64796042018-10-03 16:51:55 -0700785 }
786
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700787 return ipmi::responseSuccess(resetOnCATERR, resetOnERR2, 0, 0x3F,
788 cpu1CATERRCount, cpu1Status, cpu2CATERRCount,
789 cpu2Status, cpu3CATERRCount, cpu3Status,
790 cpu4CATERRCount, cpu4Status, crashdumpCount);
791}
Jason M. Bills64796042018-10-03 16:51:55 -0700792
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700793ipmi::RspType<> ipmiOEMSetProcessorErrConfig(
794 bool resetOnCATERR, bool resetOnERR2, uint6_t reserved1, uint8_t reserved2,
795 std::optional<bool> clearCPUErrorCount,
796 std::optional<bool> clearCrashdumpCount, std::optional<uint6_t> reserved3)
797{
Jayaprakash Mutyala0a652fa2021-07-01 17:09:39 +0000798 if (reserved1 || reserved2)
799 {
800 return ipmi::responseInvalidFieldRequest();
801 }
802
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700803 std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
Jason M. Bills64796042018-10-03 16:51:55 -0700804
805 try
806 {
Jayaprakash Mutyala0a652fa2021-07-01 17:09:39 +0000807 if (reserved3.value_or(0))
808 {
809 return ipmi::responseInvalidFieldRequest();
810 }
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700811 auto service = ipmi::getService(*busp, processorErrConfigIntf,
812 processorErrConfigObjPath);
813 ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath,
814 processorErrConfigIntf, "ResetOnCATERR",
815 resetOnCATERR);
816 ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath,
817 processorErrConfigIntf, "ResetOnERR2",
818 resetOnERR2);
819 if (clearCPUErrorCount.value_or(false))
820 {
821 ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath,
Jason M. Billsd3e19932019-08-15 12:39:03 -0700822 processorErrConfigIntf, "ErrorCountCPU1",
823 static_cast<uint8_t>(0));
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700824 ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath,
Jason M. Billsd3e19932019-08-15 12:39:03 -0700825 processorErrConfigIntf, "ErrorCountCPU2",
826 static_cast<uint8_t>(0));
827 ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath,
828 processorErrConfigIntf, "ErrorCountCPU3",
829 static_cast<uint8_t>(0));
830 ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath,
831 processorErrConfigIntf, "ErrorCountCPU4",
832 static_cast<uint8_t>(0));
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700833 }
834 if (clearCrashdumpCount.value_or(false))
835 {
836 ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath,
Jason M. Billsd3e19932019-08-15 12:39:03 -0700837 processorErrConfigIntf, "CrashdumpCount",
838 static_cast<uint8_t>(0));
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700839 }
Jason M. Bills64796042018-10-03 16:51:55 -0700840 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -0500841 catch (const std::exception& e)
Jason M. Bills64796042018-10-03 16:51:55 -0700842 {
Kuiying Wangbc546672018-11-23 15:41:05 +0800843 phosphor::logging::log<phosphor::logging::level::ERR>(
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700844 "Failed to set processor error config",
845 phosphor::logging::entry("EXCEPTION=%s", e.what()));
846 return ipmi::responseUnspecifiedError();
Jason M. Bills64796042018-10-03 16:51:55 -0700847 }
848
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700849 return ipmi::responseSuccess();
Jason M. Bills64796042018-10-03 16:51:55 -0700850}
851
Yong Li703922d2018-11-06 13:25:31 +0800852ipmi_ret_t ipmiOEMGetShutdownPolicy(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
853 ipmi_request_t request,
854 ipmi_response_t response,
855 ipmi_data_len_t dataLen,
856 ipmi_context_t context)
857{
858 GetOEMShutdownPolicyRes* resp =
859 reinterpret_cast<GetOEMShutdownPolicyRes*>(response);
860
861 if (*dataLen != 0)
862 {
863 phosphor::logging::log<phosphor::logging::level::ERR>(
Kuiying Wang45f04982018-12-26 09:23:08 +0800864 "oem_get_shutdown_policy: invalid input len!");
Yong Li703922d2018-11-06 13:25:31 +0800865 *dataLen = 0;
866 return IPMI_CC_REQ_DATA_LEN_INVALID;
867 }
868
869 *dataLen = 0;
870
871 try
872 {
Vernon Mauery15419dd2019-05-24 09:40:30 -0700873 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Yong Li703922d2018-11-06 13:25:31 +0800874 std::string service =
Vernon Mauery15419dd2019-05-24 09:40:30 -0700875 getService(*dbus, oemShutdownPolicyIntf, oemShutdownPolicyObjPath);
876 Value variant = getDbusProperty(
877 *dbus, service, oemShutdownPolicyObjPath, oemShutdownPolicyIntf,
878 oemShutdownPolicyObjPathProp);
Yong Li0669d192019-05-06 14:01:46 +0800879
880 if (sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::
881 convertPolicyFromString(std::get<std::string>(variant)) ==
882 sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::Policy::
883 NoShutdownOnOCOT)
884 {
885 resp->policy = 0;
886 }
887 else if (sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::
888 convertPolicyFromString(std::get<std::string>(variant)) ==
889 sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::
890 Policy::ShutdownOnOCOT)
891 {
892 resp->policy = 1;
893 }
894 else
895 {
896 phosphor::logging::log<phosphor::logging::level::ERR>(
897 "oem_set_shutdown_policy: invalid property!",
898 phosphor::logging::entry(
899 "PROP=%s", std::get<std::string>(variant).c_str()));
900 return IPMI_CC_UNSPECIFIED_ERROR;
901 }
Yong Li703922d2018-11-06 13:25:31 +0800902 // TODO needs to check if it is multi-node products,
903 // policy is only supported on node 3/4
904 resp->policySupport = shutdownPolicySupported;
905 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -0500906 catch (const sdbusplus::exception_t& e)
Yong Li703922d2018-11-06 13:25:31 +0800907 {
908 phosphor::logging::log<phosphor::logging::level::ERR>(e.description());
909 return IPMI_CC_UNSPECIFIED_ERROR;
910 }
911
912 *dataLen = sizeof(GetOEMShutdownPolicyRes);
913 return IPMI_CC_OK;
914}
915
916ipmi_ret_t ipmiOEMSetShutdownPolicy(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
917 ipmi_request_t request,
918 ipmi_response_t response,
919 ipmi_data_len_t dataLen,
920 ipmi_context_t context)
921{
922 uint8_t* req = reinterpret_cast<uint8_t*>(request);
Yong Li0669d192019-05-06 14:01:46 +0800923 sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::Policy policy =
924 sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::Policy::
925 NoShutdownOnOCOT;
Yong Li703922d2018-11-06 13:25:31 +0800926
927 // TODO needs to check if it is multi-node products,
928 // policy is only supported on node 3/4
929 if (*dataLen != 1)
930 {
931 phosphor::logging::log<phosphor::logging::level::ERR>(
932 "oem_set_shutdown_policy: invalid input len!");
933 *dataLen = 0;
934 return IPMI_CC_REQ_DATA_LEN_INVALID;
935 }
936
937 *dataLen = 0;
938 if ((*req != noShutdownOnOCOT) && (*req != shutdownOnOCOT))
939 {
940 phosphor::logging::log<phosphor::logging::level::ERR>(
941 "oem_set_shutdown_policy: invalid input!");
942 return IPMI_CC_INVALID_FIELD_REQUEST;
943 }
944
Yong Li0669d192019-05-06 14:01:46 +0800945 if (*req == noShutdownOnOCOT)
946 {
947 policy = sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::
948 Policy::NoShutdownOnOCOT;
949 }
950 else
951 {
952 policy = sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::
953 Policy::ShutdownOnOCOT;
954 }
955
Yong Li703922d2018-11-06 13:25:31 +0800956 try
957 {
Vernon Mauery15419dd2019-05-24 09:40:30 -0700958 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Yong Li703922d2018-11-06 13:25:31 +0800959 std::string service =
Vernon Mauery15419dd2019-05-24 09:40:30 -0700960 getService(*dbus, oemShutdownPolicyIntf, oemShutdownPolicyObjPath);
Yong Li0669d192019-05-06 14:01:46 +0800961 setDbusProperty(
Vernon Mauery15419dd2019-05-24 09:40:30 -0700962 *dbus, service, oemShutdownPolicyObjPath, oemShutdownPolicyIntf,
Yong Li0669d192019-05-06 14:01:46 +0800963 oemShutdownPolicyObjPathProp,
964 sdbusplus::com::intel::Control::server::convertForMessage(policy));
Yong Li703922d2018-11-06 13:25:31 +0800965 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -0500966 catch (const sdbusplus::exception_t& e)
Yong Li703922d2018-11-06 13:25:31 +0800967 {
968 phosphor::logging::log<phosphor::logging::level::ERR>(e.description());
969 return IPMI_CC_UNSPECIFIED_ERROR;
970 }
971
972 return IPMI_CC_OK;
973}
974
Suryakanth Sekard509eb92018-11-15 17:44:11 +0530975/** @brief implementation for check the DHCP or not in IPv4
976 * @param[in] Channel - Channel number
977 * @returns true or false.
978 */
979static bool isDHCPEnabled(uint8_t Channel)
980{
981 try
982 {
983 auto ethdevice = getChannelName(Channel);
984 if (ethdevice.empty())
985 {
986 return false;
987 }
988 auto ethIP = ethdevice + "/ipv4";
Vernon Mauery15419dd2019-05-24 09:40:30 -0700989 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Suryakanth Sekard509eb92018-11-15 17:44:11 +0530990 auto ethernetObj =
Vernon Mauery15419dd2019-05-24 09:40:30 -0700991 getDbusObject(*dbus, networkIPIntf, networkRoot, ethIP);
992 auto value = getDbusProperty(*dbus, networkService, ethernetObj.first,
Suryakanth Sekard509eb92018-11-15 17:44:11 +0530993 networkIPIntf, "Origin");
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700994 if (std::get<std::string>(value) ==
Suryakanth Sekard509eb92018-11-15 17:44:11 +0530995 "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP")
996 {
997 return true;
998 }
999 else
1000 {
1001 return false;
1002 }
1003 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -05001004 catch (const sdbusplus::exception_t& e)
Suryakanth Sekard509eb92018-11-15 17:44:11 +05301005 {
1006 phosphor::logging::log<phosphor::logging::level::ERR>(e.description());
1007 return true;
1008 }
1009}
1010
1011/** @brief implementes for check the DHCP or not in IPv6
1012 * @param[in] Channel - Channel number
1013 * @returns true or false.
1014 */
1015static bool isDHCPIPv6Enabled(uint8_t Channel)
1016{
1017
1018 try
1019 {
1020 auto ethdevice = getChannelName(Channel);
1021 if (ethdevice.empty())
1022 {
1023 return false;
1024 }
1025 auto ethIP = ethdevice + "/ipv6";
Vernon Mauery15419dd2019-05-24 09:40:30 -07001026 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Suryakanth Sekard509eb92018-11-15 17:44:11 +05301027 auto objectInfo =
Vernon Mauery15419dd2019-05-24 09:40:30 -07001028 getDbusObject(*dbus, networkIPIntf, networkRoot, ethIP);
1029 auto properties = getAllDbusProperties(*dbus, objectInfo.second,
Suryakanth Sekard509eb92018-11-15 17:44:11 +05301030 objectInfo.first, networkIPIntf);
Vernon Mauery8166c8d2019-05-23 11:22:30 -07001031 if (std::get<std::string>(properties["Origin"]) ==
Suryakanth Sekard509eb92018-11-15 17:44:11 +05301032 "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP")
1033 {
1034 return true;
1035 }
1036 else
1037 {
1038 return false;
1039 }
1040 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -05001041 catch (const sdbusplus::exception_t& e)
Suryakanth Sekard509eb92018-11-15 17:44:11 +05301042 {
1043 phosphor::logging::log<phosphor::logging::level::ERR>(e.description());
1044 return true;
1045 }
1046}
1047
1048/** @brief implementes the creating of default new user
1049 * @param[in] userName - new username in 16 bytes.
1050 * @param[in] userPassword - new password in 20 bytes
1051 * @returns ipmi completion code.
1052 */
1053ipmi::RspType<> ipmiOEMSetUser2Activation(
1054 std::array<uint8_t, ipmi::ipmiMaxUserName>& userName,
Vernon Mauery3b3d29b2021-08-05 15:03:35 -07001055 const SecureBuffer& userPassword)
Suryakanth Sekard509eb92018-11-15 17:44:11 +05301056{
Vernon Mauery3b3d29b2021-08-05 15:03:35 -07001057 if (userPassword.size() != ipmi::maxIpmi20PasswordSize)
1058 {
1059 return ipmi::responseReqDataLenInvalid();
1060 }
Suryakanth Sekard509eb92018-11-15 17:44:11 +05301061 bool userState = false;
1062 // Check for System Interface not exist and LAN should be static
1063 for (uint8_t channel = 0; channel < maxIpmiChannels; channel++)
1064 {
Manish Baing440f62b2021-07-15 22:00:37 +00001065 ChannelInfo chInfo{};
Suryakanth Sekard509eb92018-11-15 17:44:11 +05301066 try
1067 {
1068 getChannelInfo(channel, chInfo);
1069 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -05001070 catch (const sdbusplus::exception_t& e)
Suryakanth Sekard509eb92018-11-15 17:44:11 +05301071 {
1072 phosphor::logging::log<phosphor::logging::level::ERR>(
1073 "ipmiOEMSetUser2Activation: Failed to get Channel Info",
1074 phosphor::logging::entry("MSG: %s", e.description()));
1075 return ipmi::response(ipmi::ccUnspecifiedError);
1076 }
1077 if (chInfo.mediumType ==
1078 static_cast<uint8_t>(EChannelMediumType::systemInterface))
1079 {
1080 phosphor::logging::log<phosphor::logging::level::ERR>(
1081 "ipmiOEMSetUser2Activation: system interface exist .");
1082 return ipmi::response(ipmi::ccCommandNotAvailable);
1083 }
1084 else
1085 {
1086
1087 if (chInfo.mediumType ==
1088 static_cast<uint8_t>(EChannelMediumType::lan8032))
1089 {
1090 if (isDHCPIPv6Enabled(channel) || isDHCPEnabled(channel))
1091 {
1092 phosphor::logging::log<phosphor::logging::level::ERR>(
1093 "ipmiOEMSetUser2Activation: DHCP enabled .");
1094 return ipmi::response(ipmi::ccCommandNotAvailable);
1095 }
1096 }
1097 }
1098 }
1099 uint8_t maxChUsers = 0, enabledUsers = 0, fixedUsers = 0;
1100 if (ipmi::ccSuccess ==
1101 ipmiUserGetAllCounts(maxChUsers, enabledUsers, fixedUsers))
1102 {
1103 if (enabledUsers > 1)
1104 {
1105 phosphor::logging::log<phosphor::logging::level::ERR>(
1106 "ipmiOEMSetUser2Activation: more than one user is enabled.");
1107 return ipmi::response(ipmi::ccCommandNotAvailable);
1108 }
1109 // Check the user 2 is enabled or not
1110 ipmiUserCheckEnabled(ipmiDefaultUserId, userState);
1111 if (userState == true)
1112 {
1113 phosphor::logging::log<phosphor::logging::level::ERR>(
1114 "ipmiOEMSetUser2Activation: user 2 already enabled .");
1115 return ipmi::response(ipmi::ccCommandNotAvailable);
1116 }
1117 }
1118 else
1119 {
1120 return ipmi::response(ipmi::ccUnspecifiedError);
1121 }
1122
1123#if BYTE_ORDER == LITTLE_ENDIAN
1124 PrivAccess privAccess = {PRIVILEGE_ADMIN, true, true, true, 0};
1125#endif
1126#if BYTE_ORDER == BIG_ENDIAN
1127 PrivAccess privAccess = {0, true, true, true, PRIVILEGE_ADMIN};
1128#endif
1129
Vernon Mauery037cabd2020-05-14 12:16:01 -07001130 // ipmiUserSetUserName correctly handles char*, possibly non-null
1131 // terminated strings using ipmiMaxUserName size
Jayaprakash Mutyala3fbe8d22020-10-29 14:42:59 +00001132 size_t nameLen = strnlen(reinterpret_cast<const char*>(userName.data()),
1133 sizeof(userName));
1134 const std::string userNameRaw(
1135 reinterpret_cast<const char*>(userName.data()), nameLen);
jayaprakash Mutyala1429d4f2020-03-04 18:20:16 +00001136
Vernon Mauery037cabd2020-05-14 12:16:01 -07001137 if (ipmi::ccSuccess == ipmiUserSetUserName(ipmiDefaultUserId, userNameRaw))
Suryakanth Sekard509eb92018-11-15 17:44:11 +05301138 {
1139 if (ipmi::ccSuccess ==
1140 ipmiUserSetUserPassword(
1141 ipmiDefaultUserId,
1142 reinterpret_cast<const char*>(userPassword.data())))
1143 {
1144 if (ipmi::ccSuccess ==
1145 ipmiUserSetPrivilegeAccess(
1146 ipmiDefaultUserId,
1147 static_cast<uint8_t>(ipmi::EChannelID::chanLan1),
1148 privAccess, true))
1149 {
1150 phosphor::logging::log<phosphor::logging::level::INFO>(
1151 "ipmiOEMSetUser2Activation: user created successfully ");
Jayaprakash Mutyala94204162020-10-23 06:17:56 +00001152
Suryakanth Sekard509eb92018-11-15 17:44:11 +05301153 return ipmi::responseSuccess();
1154 }
1155 }
1156 // we need to delete the default user id which added in this command as
1157 // password / priv setting is failed.
Jayaprakash Mutyala3fbe8d22020-10-29 14:42:59 +00001158 ipmiUserSetUserName(ipmiDefaultUserId, static_cast<std::string>(""));
Suryakanth Sekard509eb92018-11-15 17:44:11 +05301159 phosphor::logging::log<phosphor::logging::level::ERR>(
1160 "ipmiOEMSetUser2Activation: password / priv setting is failed.");
1161 }
1162 else
1163 {
1164 phosphor::logging::log<phosphor::logging::level::ERR>(
1165 "ipmiOEMSetUser2Activation: Setting username failed.");
1166 }
1167
1168 return ipmi::response(ipmi::ccCommandNotAvailable);
1169}
1170
Suryakanth Sekar822b0b42019-11-15 18:32:53 +05301171/** @brief implementes executing the linux command
1172 * @param[in] linux command
1173 * @returns status
1174 */
1175
1176static uint8_t executeCmd(const char* path)
1177{
1178 boost::process::child execProg(path);
1179 execProg.wait();
1180
1181 int retCode = execProg.exit_code();
1182 if (retCode)
1183 {
1184 return ipmi::ccUnspecifiedError;
1185 }
1186 return ipmi::ccSuccess;
1187}
1188
1189/** @brief implementes ASD Security event logging
1190 * @param[in] Event message string
1191 * @param[in] Event Severity
1192 * @returns status
1193 */
1194
1195static void atScaleDebugEventlog(std::string msg, int severity)
1196{
1197 std::string eventStr = "OpenBMC.0.1." + msg;
1198 sd_journal_send("MESSAGE=Security Event: %s", eventStr.c_str(),
1199 "PRIORITY=%i", severity, "REDFISH_MESSAGE_ID=%s",
1200 eventStr.c_str(), NULL);
1201}
1202
Richard Marian Thomaiyarfc5e9852019-04-14 15:06:27 +05301203/** @brief implementes setting password for special user
1204 * @param[in] specialUserIndex
1205 * @param[in] userPassword - new password in 20 bytes
1206 * @returns ipmi completion code.
1207 */
1208ipmi::RspType<> ipmiOEMSetSpecialUserPassword(ipmi::Context::ptr ctx,
1209 uint8_t specialUserIndex,
1210 std::vector<uint8_t> userPassword)
1211{
1212 ChannelInfo chInfo;
Suryakanth Sekar822b0b42019-11-15 18:32:53 +05301213 ipmi_ret_t status = ipmi::ccSuccess;
1214
Richard Marian Thomaiyarfc5e9852019-04-14 15:06:27 +05301215 try
1216 {
1217 getChannelInfo(ctx->channel, chInfo);
1218 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -05001219 catch (const sdbusplus::exception_t& e)
Richard Marian Thomaiyarfc5e9852019-04-14 15:06:27 +05301220 {
1221 phosphor::logging::log<phosphor::logging::level::ERR>(
1222 "ipmiOEMSetSpecialUserPassword: Failed to get Channel Info",
1223 phosphor::logging::entry("MSG: %s", e.description()));
1224 return ipmi::responseUnspecifiedError();
1225 }
1226 if (chInfo.mediumType !=
1227 static_cast<uint8_t>(EChannelMediumType::systemInterface))
1228 {
1229 phosphor::logging::log<phosphor::logging::level::ERR>(
1230 "ipmiOEMSetSpecialUserPassword: Error - supported only in KCS "
1231 "interface");
1232 return ipmi::responseCommandNotAvailable();
1233 }
Suryakanth Sekar822b0b42019-11-15 18:32:53 +05301234
1235 // 0 for root user and 1 for AtScaleDebug is allowed
1236 if (specialUserIndex >
1237 static_cast<uint8_t>(SpecialUserIndex::atScaleDebugUser))
Richard Marian Thomaiyarfc5e9852019-04-14 15:06:27 +05301238 {
1239 phosphor::logging::log<phosphor::logging::level::ERR>(
1240 "ipmiOEMSetSpecialUserPassword: Invalid user account");
1241 return ipmi::responseParmOutOfRange();
1242 }
Suryakanth Sekar822b0b42019-11-15 18:32:53 +05301243 if (userPassword.size() != 0)
Richard Marian Thomaiyarfc5e9852019-04-14 15:06:27 +05301244 {
Suryakanth Sekar822b0b42019-11-15 18:32:53 +05301245 constexpr uint8_t minPasswordSizeRequired = 6;
Patrick Williams23939852021-09-02 11:18:35 -05001246 SecureString passwd;
Suryakanth Sekar822b0b42019-11-15 18:32:53 +05301247 if (userPassword.size() < minPasswordSizeRequired ||
1248 userPassword.size() > ipmi::maxIpmi20PasswordSize)
1249 {
Jayaprakash Mutyala94204162020-10-23 06:17:56 +00001250 OPENSSL_cleanse(userPassword.data(), userPassword.size());
Suryakanth Sekar822b0b42019-11-15 18:32:53 +05301251 return ipmi::responseReqDataLenInvalid();
1252 }
1253 passwd.assign(reinterpret_cast<const char*>(userPassword.data()),
1254 userPassword.size());
Jayaprakash Mutyala94204162020-10-23 06:17:56 +00001255 // Clear sensitive data
1256 OPENSSL_cleanse(userPassword.data(), userPassword.size());
Suryakanth Sekar822b0b42019-11-15 18:32:53 +05301257 if (specialUserIndex ==
1258 static_cast<uint8_t>(SpecialUserIndex::atScaleDebugUser))
1259 {
1260 status = ipmiSetSpecialUserPassword("asdbg", passwd);
1261
1262 atScaleDebugEventlog("AtScaleDebugSpecialUserEnabled", LOG_CRIT);
1263 }
1264 else
1265 {
1266 status = ipmiSetSpecialUserPassword("root", passwd);
1267 }
1268 return ipmi::response(status);
Richard Marian Thomaiyarfc5e9852019-04-14 15:06:27 +05301269 }
Suryakanth Sekar822b0b42019-11-15 18:32:53 +05301270 else
1271 {
1272 if (specialUserIndex ==
1273 static_cast<uint8_t>(SpecialUserIndex::rootUser))
1274 {
1275 status = executeCmd("passwd -d root");
1276 }
1277 else
1278 {
1279
1280 status = executeCmd("passwd -d asdbg");
1281
1282 if (status == 0)
1283 {
1284 atScaleDebugEventlog("AtScaleDebugSpecialUserDisabled",
1285 LOG_INFO);
1286 }
1287 }
1288 return ipmi::response(status);
1289 }
Richard Marian Thomaiyarfc5e9852019-04-14 15:06:27 +05301290}
1291
Kuiying Wang45f04982018-12-26 09:23:08 +08001292namespace ledAction
1293{
1294using namespace sdbusplus::xyz::openbmc_project::Led::server;
1295std::map<Physical::Action, uint8_t> actionDbusToIpmi = {
jayaprakash Mutyala934ee9c2019-12-13 17:49:27 +00001296 {Physical::Action::Off, 0},
1297 {Physical::Action::On, 2},
1298 {Physical::Action::Blink, 1}};
Kuiying Wang45f04982018-12-26 09:23:08 +08001299
1300std::map<uint8_t, std::string> offsetObjPath = {
1301 {2, statusAmberObjPath}, {4, statusGreenObjPath}, {6, identifyLEDObjPath}};
1302
1303} // namespace ledAction
1304
1305int8_t getLEDState(sdbusplus::bus::bus& bus, const std::string& intf,
1306 const std::string& objPath, uint8_t& state)
1307{
1308 try
1309 {
1310 std::string service = getService(bus, intf, objPath);
1311 Value stateValue =
1312 getDbusProperty(bus, service, objPath, intf, "State");
Vernon Mauery8166c8d2019-05-23 11:22:30 -07001313 std::string strState = std::get<std::string>(stateValue);
Kuiying Wang45f04982018-12-26 09:23:08 +08001314 state = ledAction::actionDbusToIpmi.at(
1315 sdbusplus::xyz::openbmc_project::Led::server::Physical::
1316 convertActionFromString(strState));
1317 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -05001318 catch (const sdbusplus::exception::exception& e)
Kuiying Wang45f04982018-12-26 09:23:08 +08001319 {
1320 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
1321 return -1;
1322 }
1323 return 0;
1324}
1325
NITIN SHARMAabd11ca2019-06-12 12:31:42 +00001326ipmi::RspType<uint8_t> ipmiOEMGetLEDStatus()
Kuiying Wang45f04982018-12-26 09:23:08 +08001327{
NITIN SHARMAabd11ca2019-06-12 12:31:42 +00001328 uint8_t ledstate = 0;
Kuiying Wang45f04982018-12-26 09:23:08 +08001329 phosphor::logging::log<phosphor::logging::level::DEBUG>("GET led status");
Vernon Mauery15419dd2019-05-24 09:40:30 -07001330 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Kuiying Wang45f04982018-12-26 09:23:08 +08001331 for (auto it = ledAction::offsetObjPath.begin();
1332 it != ledAction::offsetObjPath.end(); ++it)
1333 {
1334 uint8_t state = 0;
NITIN SHARMAabd11ca2019-06-12 12:31:42 +00001335 if (getLEDState(*dbus, ledIntf, it->second, state) == -1)
Kuiying Wang45f04982018-12-26 09:23:08 +08001336 {
1337 phosphor::logging::log<phosphor::logging::level::ERR>(
1338 "oem_get_led_status: fail to get ID LED status!");
NITIN SHARMAabd11ca2019-06-12 12:31:42 +00001339 return ipmi::responseUnspecifiedError();
Kuiying Wang45f04982018-12-26 09:23:08 +08001340 }
NITIN SHARMAabd11ca2019-06-12 12:31:42 +00001341 ledstate |= state << it->first;
Kuiying Wang45f04982018-12-26 09:23:08 +08001342 }
NITIN SHARMAabd11ca2019-06-12 12:31:42 +00001343 return ipmi::responseSuccess(ledstate);
Kuiying Wang45f04982018-12-26 09:23:08 +08001344}
1345
Yong Li23737fe2019-02-19 08:49:55 +08001346ipmi_ret_t ipmiOEMCfgHostSerialPortSpeed(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
1347 ipmi_request_t request,
1348 ipmi_response_t response,
1349 ipmi_data_len_t dataLen,
1350 ipmi_context_t context)
1351{
1352 CfgHostSerialReq* req = reinterpret_cast<CfgHostSerialReq*>(request);
1353 uint8_t* resp = reinterpret_cast<uint8_t*>(response);
1354
1355 if (*dataLen == 0)
1356 {
1357 phosphor::logging::log<phosphor::logging::level::ERR>(
1358 "CfgHostSerial: invalid input len!",
1359 phosphor::logging::entry("LEN=%d", *dataLen));
1360 return IPMI_CC_REQ_DATA_LEN_INVALID;
1361 }
1362
1363 switch (req->command)
1364 {
1365 case getHostSerialCfgCmd:
1366 {
1367 if (*dataLen != 1)
1368 {
1369 phosphor::logging::log<phosphor::logging::level::ERR>(
1370 "CfgHostSerial: invalid input len!");
1371 *dataLen = 0;
1372 return IPMI_CC_REQ_DATA_LEN_INVALID;
1373 }
1374
1375 *dataLen = 0;
1376
1377 boost::process::ipstream is;
1378 std::vector<std::string> data;
1379 std::string line;
1380 boost::process::child c1(fwGetEnvCmd, "-n", fwHostSerailCfgEnvName,
1381 boost::process::std_out > is);
1382
1383 while (c1.running() && std::getline(is, line) && !line.empty())
1384 {
1385 data.push_back(line);
1386 }
1387
1388 c1.wait();
1389 if (c1.exit_code())
1390 {
1391 phosphor::logging::log<phosphor::logging::level::ERR>(
1392 "CfgHostSerial:: error on execute",
1393 phosphor::logging::entry("EXECUTE=%s", fwSetEnvCmd));
1394 // Using the default value
1395 *resp = 0;
1396 }
1397 else
1398 {
1399 if (data.size() != 1)
1400 {
1401 phosphor::logging::log<phosphor::logging::level::ERR>(
1402 "CfgHostSerial:: error on read env");
1403 return IPMI_CC_UNSPECIFIED_ERROR;
1404 }
1405 try
1406 {
1407 unsigned long tmp = std::stoul(data[0]);
1408 if (tmp > std::numeric_limits<uint8_t>::max())
1409 {
1410 throw std::out_of_range("Out of range");
1411 }
1412 *resp = static_cast<uint8_t>(tmp);
1413 }
1414 catch (const std::invalid_argument& e)
1415 {
1416 phosphor::logging::log<phosphor::logging::level::ERR>(
1417 "invalid config ",
1418 phosphor::logging::entry("ERR=%s", e.what()));
1419 return IPMI_CC_UNSPECIFIED_ERROR;
1420 }
1421 catch (const std::out_of_range& e)
1422 {
1423 phosphor::logging::log<phosphor::logging::level::ERR>(
1424 "out_of_range config ",
1425 phosphor::logging::entry("ERR=%s", e.what()));
1426 return IPMI_CC_UNSPECIFIED_ERROR;
1427 }
1428 }
1429
1430 *dataLen = 1;
1431 break;
1432 }
1433 case setHostSerialCfgCmd:
1434 {
1435 if (*dataLen != sizeof(CfgHostSerialReq))
1436 {
1437 phosphor::logging::log<phosphor::logging::level::ERR>(
1438 "CfgHostSerial: invalid input len!");
1439 *dataLen = 0;
1440 return IPMI_CC_REQ_DATA_LEN_INVALID;
1441 }
1442
1443 *dataLen = 0;
1444
1445 if (req->parameter > HostSerialCfgParamMax)
1446 {
1447 phosphor::logging::log<phosphor::logging::level::ERR>(
1448 "CfgHostSerial: invalid input!");
1449 return IPMI_CC_INVALID_FIELD_REQUEST;
1450 }
1451
1452 boost::process::child c1(fwSetEnvCmd, fwHostSerailCfgEnvName,
1453 std::to_string(req->parameter));
1454
1455 c1.wait();
1456 if (c1.exit_code())
1457 {
1458 phosphor::logging::log<phosphor::logging::level::ERR>(
1459 "CfgHostSerial:: error on execute",
1460 phosphor::logging::entry("EXECUTE=%s", fwGetEnvCmd));
1461 return IPMI_CC_UNSPECIFIED_ERROR;
1462 }
1463 break;
1464 }
1465 default:
1466 phosphor::logging::log<phosphor::logging::level::ERR>(
1467 "CfgHostSerial: invalid input!");
1468 *dataLen = 0;
1469 return IPMI_CC_INVALID_FIELD_REQUEST;
1470 }
1471
1472 return IPMI_CC_OK;
1473}
1474
James Feist91244a62019-02-19 15:04:54 -08001475constexpr const char* thermalModeInterface =
1476 "xyz.openbmc_project.Control.ThermalMode";
1477constexpr const char* thermalModePath =
1478 "/xyz/openbmc_project/control/thermal_mode";
1479
1480bool getFanProfileInterface(
1481 sdbusplus::bus::bus& bus,
1482 boost::container::flat_map<
1483 std::string, std::variant<std::vector<std::string>, std::string>>& resp)
1484{
1485 auto call = bus.new_method_call(settingsBusName, thermalModePath, PROP_INTF,
1486 "GetAll");
1487 call.append(thermalModeInterface);
1488 try
1489 {
1490 auto data = bus.call(call);
1491 data.read(resp);
1492 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -05001493 catch (const sdbusplus::exception_t& e)
James Feist91244a62019-02-19 15:04:54 -08001494 {
1495 phosphor::logging::log<phosphor::logging::level::ERR>(
1496 "getFanProfileInterface: can't get thermal mode!",
1497 phosphor::logging::entry("ERR=%s", e.what()));
1498 return false;
1499 }
1500 return true;
1501}
1502
anil kumar appanaf945eee2019-09-25 23:29:11 +00001503/**@brief implements the OEM set fan config.
1504 * @param selectedFanProfile - fan profile to enable
1505 * @param reserved1
1506 * @param performanceMode - Performance/Acoustic mode
1507 * @param reserved2
1508 * @param setPerformanceMode - set Performance/Acoustic mode
1509 * @param setFanProfile - set fan profile
1510 *
1511 * @return IPMI completion code.
1512 **/
1513ipmi::RspType<> ipmiOEMSetFanConfig(uint8_t selectedFanProfile,
1514
1515 uint2_t reserved1, bool performanceMode,
1516 uint3_t reserved2, bool setPerformanceMode,
Joshi-Mansi619186d2020-01-27 19:16:03 +05301517 bool setFanProfile,
1518 std::optional<uint8_t> dimmGroupId,
1519 std::optional<uint32_t> dimmPresenceBitmap)
James Feist91244a62019-02-19 15:04:54 -08001520{
anil kumar appanaf945eee2019-09-25 23:29:11 +00001521 if (reserved1 || reserved2)
James Feist91244a62019-02-19 15:04:54 -08001522 {
anil kumar appanaf945eee2019-09-25 23:29:11 +00001523 return ipmi::responseInvalidFieldRequest();
James Feist91244a62019-02-19 15:04:54 -08001524 }
Joshi-Mansi619186d2020-01-27 19:16:03 +05301525
1526 if (dimmGroupId)
1527 {
1528 if (*dimmGroupId >= maxCPUNum)
1529 {
1530 return ipmi::responseInvalidFieldRequest();
1531 }
1532 if (!cpuPresent("CPU_" + std::to_string(*dimmGroupId + 1)))
1533 {
1534 return ipmi::responseInvalidFieldRequest();
1535 }
1536 }
1537
James Feist91244a62019-02-19 15:04:54 -08001538 // todo: tell bios to only send first 2 bytes
James Feist91244a62019-02-19 15:04:54 -08001539 boost::container::flat_map<
1540 std::string, std::variant<std::vector<std::string>, std::string>>
1541 profileData;
Vernon Mauery15419dd2019-05-24 09:40:30 -07001542 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
1543 if (!getFanProfileInterface(*dbus, profileData))
James Feist91244a62019-02-19 15:04:54 -08001544 {
anil kumar appanaf945eee2019-09-25 23:29:11 +00001545 return ipmi::responseUnspecifiedError();
James Feist91244a62019-02-19 15:04:54 -08001546 }
1547
1548 std::vector<std::string>* supported =
1549 std::get_if<std::vector<std::string>>(&profileData["Supported"]);
1550 if (supported == nullptr)
1551 {
anil kumar appanaf945eee2019-09-25 23:29:11 +00001552 return ipmi::responseInvalidFieldRequest();
James Feist91244a62019-02-19 15:04:54 -08001553 }
1554 std::string mode;
anil kumar appanaf945eee2019-09-25 23:29:11 +00001555 if (setPerformanceMode)
James Feist91244a62019-02-19 15:04:54 -08001556 {
James Feist91244a62019-02-19 15:04:54 -08001557 if (performanceMode)
1558 {
1559
1560 if (std::find(supported->begin(), supported->end(),
1561 "Performance") != supported->end())
1562 {
1563 mode = "Performance";
1564 }
1565 }
1566 else
1567 {
James Feist91244a62019-02-19 15:04:54 -08001568 if (std::find(supported->begin(), supported->end(), "Acoustic") !=
1569 supported->end())
1570 {
1571 mode = "Acoustic";
1572 }
1573 }
1574 if (mode.empty())
1575 {
anil kumar appanaf945eee2019-09-25 23:29:11 +00001576 return ipmi::responseInvalidFieldRequest();
James Feist91244a62019-02-19 15:04:54 -08001577 }
anil kumar appanaf945eee2019-09-25 23:29:11 +00001578
1579 try
1580 {
1581 setDbusProperty(*dbus, settingsBusName, thermalModePath,
1582 thermalModeInterface, "Current", mode);
1583 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -05001584 catch (const sdbusplus::exception_t& e)
anil kumar appanaf945eee2019-09-25 23:29:11 +00001585 {
1586 phosphor::logging::log<phosphor::logging::level::ERR>(
1587 "ipmiOEMSetFanConfig: can't set thermal mode!",
1588 phosphor::logging::entry("EXCEPTION=%s", e.what()));
1589 return ipmi::responseResponseError();
1590 }
James Feist91244a62019-02-19 15:04:54 -08001591 }
1592
anil kumar appanaf945eee2019-09-25 23:29:11 +00001593 return ipmi::responseSuccess();
James Feist91244a62019-02-19 15:04:54 -08001594}
1595
James Feist5b693632019-07-09 09:06:09 -07001596ipmi::RspType<uint8_t, // profile support map
1597 uint8_t, // fan control profile enable
1598 uint8_t, // flags
1599 uint32_t // dimm presence bit map
1600 >
1601 ipmiOEMGetFanConfig(uint8_t dimmGroupId)
James Feist91244a62019-02-19 15:04:54 -08001602{
Joshi-Mansi36f05ce2020-01-14 14:29:34 +05301603 if (dimmGroupId >= maxCPUNum)
1604 {
1605 return ipmi::responseInvalidFieldRequest();
1606 }
1607
1608 bool cpuStatus = cpuPresent("CPU_" + std::to_string(dimmGroupId + 1));
1609
1610 if (!cpuStatus)
1611 {
1612 return ipmi::responseInvalidFieldRequest();
1613 }
1614
James Feist91244a62019-02-19 15:04:54 -08001615 boost::container::flat_map<
1616 std::string, std::variant<std::vector<std::string>, std::string>>
1617 profileData;
1618
Vernon Mauery15419dd2019-05-24 09:40:30 -07001619 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
1620 if (!getFanProfileInterface(*dbus, profileData))
James Feist91244a62019-02-19 15:04:54 -08001621 {
James Feist5b693632019-07-09 09:06:09 -07001622 return ipmi::responseResponseError();
James Feist91244a62019-02-19 15:04:54 -08001623 }
1624
1625 std::string* current = std::get_if<std::string>(&profileData["Current"]);
1626
1627 if (current == nullptr)
1628 {
1629 phosphor::logging::log<phosphor::logging::level::ERR>(
1630 "ipmiOEMGetFanConfig: can't get current mode!");
James Feist5b693632019-07-09 09:06:09 -07001631 return ipmi::responseResponseError();
James Feist91244a62019-02-19 15:04:54 -08001632 }
1633 bool performance = (*current == "Performance");
1634
James Feist5b693632019-07-09 09:06:09 -07001635 uint8_t flags = 0;
James Feist91244a62019-02-19 15:04:54 -08001636 if (performance)
1637 {
James Feist5b693632019-07-09 09:06:09 -07001638 flags |= 1 << 2;
James Feist91244a62019-02-19 15:04:54 -08001639 }
1640
jayaprakash Mutyala4b1552d2020-02-11 12:07:29 +00001641 constexpr uint8_t fanControlDefaultProfile = 0x80;
1642 constexpr uint8_t fanControlProfileState = 0x00;
1643 constexpr uint32_t dimmPresenceBitmap = 0x00;
1644
1645 return ipmi::responseSuccess(fanControlDefaultProfile,
1646 fanControlProfileState, flags,
1647 dimmPresenceBitmap);
James Feist91244a62019-02-19 15:04:54 -08001648}
James Feist5f957ca2019-03-14 15:33:55 -07001649constexpr const char* cfmLimitSettingPath =
1650 "/xyz/openbmc_project/control/cfm_limit";
1651constexpr const char* cfmLimitIface = "xyz.openbmc_project.Control.CFMLimit";
James Feistfaa4f222019-03-21 16:21:55 -07001652constexpr const size_t legacyExitAirSensorNumber = 0x2e;
James Feist09f6b602019-08-08 11:30:03 -07001653constexpr const size_t legacyPCHSensorNumber = 0x22;
1654constexpr const char* exitAirPathName = "Exit_Air";
1655constexpr const char* pchPathName = "SSB_Temp";
James Feistacc8a4e2019-04-02 14:23:57 -07001656constexpr const char* pidConfigurationIface =
1657 "xyz.openbmc_project.Configuration.Pid";
James Feistfaa4f222019-03-21 16:21:55 -07001658
James Feist09f6b602019-08-08 11:30:03 -07001659static std::string getConfigPath(const std::string& name)
James Feistfaa4f222019-03-21 16:21:55 -07001660{
Vernon Mauery15419dd2019-05-24 09:40:30 -07001661 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
James Feistfaa4f222019-03-21 16:21:55 -07001662 auto method =
Vernon Mauery15419dd2019-05-24 09:40:30 -07001663 dbus->new_method_call("xyz.openbmc_project.ObjectMapper",
1664 "/xyz/openbmc_project/object_mapper",
1665 "xyz.openbmc_project.ObjectMapper", "GetSubTree");
James Feistfaa4f222019-03-21 16:21:55 -07001666
James Feistacc8a4e2019-04-02 14:23:57 -07001667 method.append("/", 0, std::array<const char*, 1>{pidConfigurationIface});
James Feistfaa4f222019-03-21 16:21:55 -07001668 std::string path;
1669 GetSubTreeType resp;
1670 try
1671 {
Vernon Mauery15419dd2019-05-24 09:40:30 -07001672 auto reply = dbus->call(method);
James Feistfaa4f222019-03-21 16:21:55 -07001673 reply.read(resp);
1674 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -05001675 catch (const sdbusplus::exception_t&)
James Feistfaa4f222019-03-21 16:21:55 -07001676 {
1677 phosphor::logging::log<phosphor::logging::level::ERR>(
1678 "ipmiOEMGetFscParameter: mapper error");
1679 };
James Feist09f6b602019-08-08 11:30:03 -07001680 auto config =
1681 std::find_if(resp.begin(), resp.end(), [&name](const auto& pair) {
1682 return pair.first.find(name) != std::string::npos;
1683 });
James Feistfaa4f222019-03-21 16:21:55 -07001684 if (config != resp.end())
1685 {
1686 path = std::move(config->first);
1687 }
1688 return path;
1689}
James Feist5f957ca2019-03-14 15:33:55 -07001690
James Feistacc8a4e2019-04-02 14:23:57 -07001691// flat map to make alphabetical
1692static boost::container::flat_map<std::string, PropertyMap> getPidConfigs()
1693{
1694 boost::container::flat_map<std::string, PropertyMap> ret;
Vernon Mauery15419dd2019-05-24 09:40:30 -07001695 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
James Feistacc8a4e2019-04-02 14:23:57 -07001696 auto method =
Vernon Mauery15419dd2019-05-24 09:40:30 -07001697 dbus->new_method_call("xyz.openbmc_project.ObjectMapper",
1698 "/xyz/openbmc_project/object_mapper",
1699 "xyz.openbmc_project.ObjectMapper", "GetSubTree");
James Feistacc8a4e2019-04-02 14:23:57 -07001700
1701 method.append("/", 0, std::array<const char*, 1>{pidConfigurationIface});
1702 GetSubTreeType resp;
1703
1704 try
1705 {
Vernon Mauery15419dd2019-05-24 09:40:30 -07001706 auto reply = dbus->call(method);
James Feistacc8a4e2019-04-02 14:23:57 -07001707 reply.read(resp);
1708 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -05001709 catch (const sdbusplus::exception_t&)
James Feistacc8a4e2019-04-02 14:23:57 -07001710 {
1711 phosphor::logging::log<phosphor::logging::level::ERR>(
1712 "getFanConfigPaths: mapper error");
1713 };
1714 for (const auto& [path, objects] : resp)
1715 {
1716 if (objects.empty())
1717 {
1718 continue; // should be impossible
1719 }
Zhu, Yungebe560b02019-04-21 21:19:21 -04001720
1721 try
1722 {
Vernon Mauery15419dd2019-05-24 09:40:30 -07001723 ret.emplace(path,
1724 getAllDbusProperties(*dbus, objects[0].first, path,
1725 pidConfigurationIface));
Zhu, Yungebe560b02019-04-21 21:19:21 -04001726 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -05001727 catch (const sdbusplus::exception_t& e)
Zhu, Yungebe560b02019-04-21 21:19:21 -04001728 {
1729 phosphor::logging::log<phosphor::logging::level::ERR>(
1730 "getPidConfigs: can't get DbusProperties!",
1731 phosphor::logging::entry("ERR=%s", e.what()));
1732 }
James Feistacc8a4e2019-04-02 14:23:57 -07001733 }
1734 return ret;
1735}
1736
1737ipmi::RspType<uint8_t> ipmiOEMGetFanSpeedOffset(void)
1738{
1739 boost::container::flat_map<std::string, PropertyMap> data = getPidConfigs();
1740 if (data.empty())
1741 {
1742 return ipmi::responseResponseError();
1743 }
1744 uint8_t minOffset = std::numeric_limits<uint8_t>::max();
1745 for (const auto& [_, pid] : data)
1746 {
1747 auto findClass = pid.find("Class");
1748 if (findClass == pid.end())
1749 {
1750 phosphor::logging::log<phosphor::logging::level::ERR>(
1751 "ipmiOEMGetFscParameter: found illegal pid "
1752 "configurations");
1753 return ipmi::responseResponseError();
1754 }
1755 std::string type = std::get<std::string>(findClass->second);
1756 if (type == "fan")
1757 {
1758 auto findOutLimit = pid.find("OutLimitMin");
1759 if (findOutLimit == pid.end())
1760 {
1761 phosphor::logging::log<phosphor::logging::level::ERR>(
1762 "ipmiOEMGetFscParameter: found illegal pid "
1763 "configurations");
1764 return ipmi::responseResponseError();
1765 }
1766 // get the min out of all the offsets
1767 minOffset = std::min(
1768 minOffset,
1769 static_cast<uint8_t>(std::get<double>(findOutLimit->second)));
1770 }
1771 }
1772 if (minOffset == std::numeric_limits<uint8_t>::max())
1773 {
1774 phosphor::logging::log<phosphor::logging::level::ERR>(
1775 "ipmiOEMGetFscParameter: found no fan configurations!");
1776 return ipmi::responseResponseError();
1777 }
1778
1779 return ipmi::responseSuccess(minOffset);
1780}
1781
1782ipmi::RspType<> ipmiOEMSetFanSpeedOffset(uint8_t offset)
1783{
Manish Baingbaa579f2021-10-08 22:30:32 +00001784 constexpr uint8_t maxFanSpeedOffset = 100;
1785 if (offset > maxFanSpeedOffset)
1786 {
1787 phosphor::logging::log<phosphor::logging::level::ERR>(
1788 "ipmiOEMSetFanSpeedOffset: fan offset greater than limit");
1789 return ipmi::responseInvalidFieldRequest();
1790 }
James Feistacc8a4e2019-04-02 14:23:57 -07001791 boost::container::flat_map<std::string, PropertyMap> data = getPidConfigs();
1792 if (data.empty())
1793 {
1794
1795 phosphor::logging::log<phosphor::logging::level::ERR>(
1796 "ipmiOEMSetFanSpeedOffset: found no pid configurations!");
1797 return ipmi::responseResponseError();
1798 }
1799
Vernon Mauery15419dd2019-05-24 09:40:30 -07001800 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
James Feistacc8a4e2019-04-02 14:23:57 -07001801 bool found = false;
1802 for (const auto& [path, pid] : data)
1803 {
1804 auto findClass = pid.find("Class");
1805 if (findClass == pid.end())
1806 {
1807
1808 phosphor::logging::log<phosphor::logging::level::ERR>(
1809 "ipmiOEMSetFanSpeedOffset: found illegal pid "
1810 "configurations");
1811 return ipmi::responseResponseError();
1812 }
1813 std::string type = std::get<std::string>(findClass->second);
1814 if (type == "fan")
1815 {
1816 auto findOutLimit = pid.find("OutLimitMin");
1817 if (findOutLimit == pid.end())
1818 {
1819
1820 phosphor::logging::log<phosphor::logging::level::ERR>(
1821 "ipmiOEMSetFanSpeedOffset: found illegal pid "
1822 "configurations");
1823 return ipmi::responseResponseError();
1824 }
Vernon Mauery15419dd2019-05-24 09:40:30 -07001825 ipmi::setDbusProperty(*dbus, "xyz.openbmc_project.EntityManager",
James Feistacc8a4e2019-04-02 14:23:57 -07001826 path, pidConfigurationIface, "OutLimitMin",
1827 static_cast<double>(offset));
1828 found = true;
1829 }
1830 }
1831 if (!found)
1832 {
1833 phosphor::logging::log<phosphor::logging::level::ERR>(
1834 "ipmiOEMSetFanSpeedOffset: set no fan offsets");
1835 return ipmi::responseResponseError();
1836 }
1837
1838 return ipmi::responseSuccess();
1839}
1840
1841ipmi::RspType<> ipmiOEMSetFscParameter(uint8_t command, uint8_t param1,
1842 uint8_t param2)
James Feist5f957ca2019-03-14 15:33:55 -07001843{
1844 constexpr const size_t disableLimiting = 0x0;
1845
Vernon Mauery15419dd2019-05-24 09:40:30 -07001846 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
James Feistacc8a4e2019-04-02 14:23:57 -07001847 if (command == static_cast<uint8_t>(setFscParamFlags::tcontrol))
James Feist5f957ca2019-03-14 15:33:55 -07001848 {
James Feist09f6b602019-08-08 11:30:03 -07001849 std::string pathName;
James Feistacc8a4e2019-04-02 14:23:57 -07001850 if (param1 == legacyExitAirSensorNumber)
James Feistfaa4f222019-03-21 16:21:55 -07001851 {
James Feist09f6b602019-08-08 11:30:03 -07001852 pathName = exitAirPathName;
1853 }
1854 else if (param1 == legacyPCHSensorNumber)
1855 {
1856 pathName = pchPathName;
James Feistfaa4f222019-03-21 16:21:55 -07001857 }
1858 else
1859 {
James Feistacc8a4e2019-04-02 14:23:57 -07001860 return ipmi::responseParmOutOfRange();
James Feistfaa4f222019-03-21 16:21:55 -07001861 }
James Feist09f6b602019-08-08 11:30:03 -07001862 std::string path = getConfigPath(pathName);
1863 ipmi::setDbusProperty(*dbus, "xyz.openbmc_project.EntityManager", path,
1864 pidConfigurationIface, "SetPoint",
1865 static_cast<double>(param2));
1866 return ipmi::responseSuccess();
James Feistfaa4f222019-03-21 16:21:55 -07001867 }
James Feistacc8a4e2019-04-02 14:23:57 -07001868 else if (command == static_cast<uint8_t>(setFscParamFlags::cfm))
James Feist5f957ca2019-03-14 15:33:55 -07001869 {
James Feistacc8a4e2019-04-02 14:23:57 -07001870 uint16_t cfm = param1 | (static_cast<uint16_t>(param2) << 8);
James Feist5f957ca2019-03-14 15:33:55 -07001871
1872 // must be greater than 50 based on eps
1873 if (cfm < 50 && cfm != disableLimiting)
1874 {
James Feistacc8a4e2019-04-02 14:23:57 -07001875 return ipmi::responseParmOutOfRange();
James Feist5f957ca2019-03-14 15:33:55 -07001876 }
1877
1878 try
1879 {
Vernon Mauery15419dd2019-05-24 09:40:30 -07001880 ipmi::setDbusProperty(*dbus, settingsBusName, cfmLimitSettingPath,
James Feist5f957ca2019-03-14 15:33:55 -07001881 cfmLimitIface, "Limit",
1882 static_cast<double>(cfm));
1883 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -05001884 catch (const sdbusplus::exception_t& e)
James Feist5f957ca2019-03-14 15:33:55 -07001885 {
1886 phosphor::logging::log<phosphor::logging::level::ERR>(
1887 "ipmiOEMSetFscParameter: can't set cfm setting!",
1888 phosphor::logging::entry("ERR=%s", e.what()));
James Feistacc8a4e2019-04-02 14:23:57 -07001889 return ipmi::responseResponseError();
James Feist5f957ca2019-03-14 15:33:55 -07001890 }
James Feistacc8a4e2019-04-02 14:23:57 -07001891 return ipmi::responseSuccess();
1892 }
1893 else if (command == static_cast<uint8_t>(setFscParamFlags::maxPwm))
1894 {
1895 constexpr const size_t maxDomainCount = 8;
1896 uint8_t requestedDomainMask = param1;
1897 boost::container::flat_map data = getPidConfigs();
1898 if (data.empty())
1899 {
1900
1901 phosphor::logging::log<phosphor::logging::level::ERR>(
1902 "ipmiOEMSetFscParameter: found no pid configurations!");
1903 return ipmi::responseResponseError();
1904 }
1905 size_t count = 0;
1906 for (const auto& [path, pid] : data)
1907 {
1908 auto findClass = pid.find("Class");
1909 if (findClass == pid.end())
1910 {
1911
1912 phosphor::logging::log<phosphor::logging::level::ERR>(
1913 "ipmiOEMSetFscParameter: found illegal pid "
1914 "configurations");
1915 return ipmi::responseResponseError();
1916 }
1917 std::string type = std::get<std::string>(findClass->second);
1918 if (type == "fan")
1919 {
1920 if (requestedDomainMask & (1 << count))
1921 {
1922 ipmi::setDbusProperty(
Vernon Mauery15419dd2019-05-24 09:40:30 -07001923 *dbus, "xyz.openbmc_project.EntityManager", path,
James Feistacc8a4e2019-04-02 14:23:57 -07001924 pidConfigurationIface, "OutLimitMax",
1925 static_cast<double>(param2));
1926 }
1927 count++;
1928 }
1929 }
1930 return ipmi::responseSuccess();
James Feist5f957ca2019-03-14 15:33:55 -07001931 }
1932 else
1933 {
1934 // todo other command parts possibly
1935 // tcontrol is handled in peci now
1936 // fan speed offset not implemented yet
1937 // domain pwm limit not implemented
James Feistacc8a4e2019-04-02 14:23:57 -07001938 return ipmi::responseParmOutOfRange();
James Feist5f957ca2019-03-14 15:33:55 -07001939 }
1940}
1941
James Feistacc8a4e2019-04-02 14:23:57 -07001942ipmi::RspType<
1943 std::variant<uint8_t, std::array<uint8_t, 2>, std::array<uint16_t, 2>>>
1944 ipmiOEMGetFscParameter(uint8_t command, std::optional<uint8_t> param)
James Feist5f957ca2019-03-14 15:33:55 -07001945{
James Feist09f6b602019-08-08 11:30:03 -07001946 constexpr uint8_t legacyDefaultSetpoint = -128;
James Feist5f957ca2019-03-14 15:33:55 -07001947
Vernon Mauery15419dd2019-05-24 09:40:30 -07001948 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
James Feistacc8a4e2019-04-02 14:23:57 -07001949 if (command == static_cast<uint8_t>(setFscParamFlags::tcontrol))
James Feist5f957ca2019-03-14 15:33:55 -07001950 {
James Feistacc8a4e2019-04-02 14:23:57 -07001951 if (!param)
James Feistfaa4f222019-03-21 16:21:55 -07001952 {
James Feistacc8a4e2019-04-02 14:23:57 -07001953 return ipmi::responseReqDataLenInvalid();
James Feistfaa4f222019-03-21 16:21:55 -07001954 }
1955
James Feist09f6b602019-08-08 11:30:03 -07001956 std::string pathName;
1957
1958 if (*param == legacyExitAirSensorNumber)
1959 {
1960 pathName = exitAirPathName;
1961 }
1962 else if (*param == legacyPCHSensorNumber)
1963 {
1964 pathName = pchPathName;
1965 }
1966 else
James Feistfaa4f222019-03-21 16:21:55 -07001967 {
James Feistacc8a4e2019-04-02 14:23:57 -07001968 return ipmi::responseParmOutOfRange();
James Feistfaa4f222019-03-21 16:21:55 -07001969 }
James Feist09f6b602019-08-08 11:30:03 -07001970
1971 uint8_t setpoint = legacyDefaultSetpoint;
1972 std::string path = getConfigPath(pathName);
James Feistfaa4f222019-03-21 16:21:55 -07001973 if (path.size())
1974 {
Vernon Mauery15419dd2019-05-24 09:40:30 -07001975 Value val = ipmi::getDbusProperty(
1976 *dbus, "xyz.openbmc_project.EntityManager", path,
1977 pidConfigurationIface, "SetPoint");
James Feistfaa4f222019-03-21 16:21:55 -07001978 setpoint = std::floor(std::get<double>(val) + 0.5);
1979 }
1980
1981 // old implementation used to return the "default" and current, we
1982 // don't make the default readily available so just make both the
1983 // same
James Feistfaa4f222019-03-21 16:21:55 -07001984
James Feistacc8a4e2019-04-02 14:23:57 -07001985 return ipmi::responseSuccess(
1986 std::array<uint8_t, 2>{setpoint, setpoint});
James Feistfaa4f222019-03-21 16:21:55 -07001987 }
James Feistacc8a4e2019-04-02 14:23:57 -07001988 else if (command == static_cast<uint8_t>(setFscParamFlags::maxPwm))
1989 {
1990 constexpr const size_t maxDomainCount = 8;
1991
1992 if (!param)
1993 {
1994 return ipmi::responseReqDataLenInvalid();
1995 }
1996 uint8_t requestedDomain = *param;
1997 if (requestedDomain >= maxDomainCount)
1998 {
1999 return ipmi::responseInvalidFieldRequest();
2000 }
2001
2002 boost::container::flat_map data = getPidConfigs();
2003 if (data.empty())
2004 {
2005 phosphor::logging::log<phosphor::logging::level::ERR>(
2006 "ipmiOEMGetFscParameter: found no pid configurations!");
2007 return ipmi::responseResponseError();
2008 }
2009 size_t count = 0;
2010 for (const auto& [_, pid] : data)
2011 {
2012 auto findClass = pid.find("Class");
2013 if (findClass == pid.end())
2014 {
2015 phosphor::logging::log<phosphor::logging::level::ERR>(
2016 "ipmiOEMGetFscParameter: found illegal pid "
2017 "configurations");
2018 return ipmi::responseResponseError();
2019 }
2020 std::string type = std::get<std::string>(findClass->second);
2021 if (type == "fan")
2022 {
2023 if (requestedDomain == count)
2024 {
2025 auto findOutLimit = pid.find("OutLimitMax");
2026 if (findOutLimit == pid.end())
2027 {
2028 phosphor::logging::log<phosphor::logging::level::ERR>(
2029 "ipmiOEMGetFscParameter: found illegal pid "
2030 "configurations");
2031 return ipmi::responseResponseError();
2032 }
2033
2034 return ipmi::responseSuccess(
2035 static_cast<uint8_t>(std::floor(
2036 std::get<double>(findOutLimit->second) + 0.5)));
2037 }
2038 else
2039 {
2040 count++;
2041 }
2042 }
2043 }
2044
2045 return ipmi::responseInvalidFieldRequest();
2046 }
2047 else if (command == static_cast<uint8_t>(setFscParamFlags::cfm))
James Feist5f957ca2019-03-14 15:33:55 -07002048 {
2049
2050 /*
2051 DataLen should be 1, but host is sending us an extra bit. As the
James Feistacc8a4e2019-04-02 14:23:57 -07002052 previous behavior didn't seem to prevent this, ignore the check for
2053 now.
James Feist5f957ca2019-03-14 15:33:55 -07002054
James Feistacc8a4e2019-04-02 14:23:57 -07002055 if (param)
James Feist5f957ca2019-03-14 15:33:55 -07002056 {
2057 phosphor::logging::log<phosphor::logging::level::ERR>(
2058 "ipmiOEMGetFscParameter: invalid input len!");
James Feist5f957ca2019-03-14 15:33:55 -07002059 return IPMI_CC_REQ_DATA_LEN_INVALID;
2060 }
2061 */
2062 Value cfmLimit;
2063 Value cfmMaximum;
2064 try
2065 {
Vernon Mauery15419dd2019-05-24 09:40:30 -07002066 cfmLimit = ipmi::getDbusProperty(*dbus, settingsBusName,
James Feist5f957ca2019-03-14 15:33:55 -07002067 cfmLimitSettingPath, cfmLimitIface,
2068 "Limit");
2069 cfmMaximum = ipmi::getDbusProperty(
Vernon Mauery15419dd2019-05-24 09:40:30 -07002070 *dbus, "xyz.openbmc_project.ExitAirTempSensor",
James Feist5f957ca2019-03-14 15:33:55 -07002071 "/xyz/openbmc_project/control/MaxCFM", cfmLimitIface, "Limit");
2072 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -05002073 catch (const sdbusplus::exception_t& e)
James Feist5f957ca2019-03-14 15:33:55 -07002074 {
2075 phosphor::logging::log<phosphor::logging::level::ERR>(
James Feistacc8a4e2019-04-02 14:23:57 -07002076 "ipmiOEMGetFscParameter: can't get cfm setting!",
James Feist5f957ca2019-03-14 15:33:55 -07002077 phosphor::logging::entry("ERR=%s", e.what()));
James Feistacc8a4e2019-04-02 14:23:57 -07002078 return ipmi::responseResponseError();
James Feist5f957ca2019-03-14 15:33:55 -07002079 }
2080
James Feistacc8a4e2019-04-02 14:23:57 -07002081 double cfmMax = std::get<double>(cfmMaximum);
2082 double cfmLim = std::get<double>(cfmLimit);
James Feist5f957ca2019-03-14 15:33:55 -07002083
James Feistacc8a4e2019-04-02 14:23:57 -07002084 cfmLim = std::floor(cfmLim + 0.5);
2085 cfmMax = std::floor(cfmMax + 0.5);
2086 uint16_t cfmLimResp = static_cast<uint16_t>(cfmLim);
2087 uint16_t cfmMaxResp = static_cast<uint16_t>(cfmMax);
James Feist5f957ca2019-03-14 15:33:55 -07002088
James Feistacc8a4e2019-04-02 14:23:57 -07002089 return ipmi::responseSuccess(
2090 std::array<uint16_t, 2>{cfmLimResp, cfmMaxResp});
James Feist5f957ca2019-03-14 15:33:55 -07002091 }
James Feistacc8a4e2019-04-02 14:23:57 -07002092
James Feist5f957ca2019-03-14 15:33:55 -07002093 else
2094 {
2095 // todo other command parts possibly
James Feist5f957ca2019-03-14 15:33:55 -07002096 // domain pwm limit not implemented
James Feistacc8a4e2019-04-02 14:23:57 -07002097 return ipmi::responseParmOutOfRange();
James Feist5f957ca2019-03-14 15:33:55 -07002098 }
2099}
2100
Cheng C Yang773703a2019-08-15 09:41:11 +08002101using crConfigVariant =
2102 std::variant<bool, uint8_t, uint32_t, std::vector<uint8_t>, std::string>;
2103
2104int setCRConfig(ipmi::Context::ptr ctx, const std::string& property,
2105 const crConfigVariant& value,
2106 std::chrono::microseconds timeout = ipmi::IPMI_DBUS_TIMEOUT)
2107{
2108 boost::system::error_code ec;
2109 ctx->bus->yield_method_call<void>(
Kuiying Wange45333a2020-07-22 22:06:37 +08002110 ctx->yield, ec, "xyz.openbmc_project.PSURedundancy",
Cheng C Yang773703a2019-08-15 09:41:11 +08002111 "/xyz/openbmc_project/control/power_supply_redundancy",
2112 "org.freedesktop.DBus.Properties", "Set",
2113 "xyz.openbmc_project.Control.PowerSupplyRedundancy", property, value);
2114 if (ec)
2115 {
2116 phosphor::logging::log<phosphor::logging::level::ERR>(
2117 "Failed to set dbus property to cold redundancy");
2118 return -1;
2119 }
2120
2121 return 0;
2122}
2123
Kuiying Wange45333a2020-07-22 22:06:37 +08002124int getCRConfig(
2125 ipmi::Context::ptr ctx, const std::string& property, crConfigVariant& value,
2126 const std::string& service = "xyz.openbmc_project.PSURedundancy",
2127 std::chrono::microseconds timeout = ipmi::IPMI_DBUS_TIMEOUT)
Cheng C Yang773703a2019-08-15 09:41:11 +08002128{
2129 boost::system::error_code ec;
2130 value = ctx->bus->yield_method_call<crConfigVariant>(
Yong Li19445ab2019-12-20 18:25:29 +08002131 ctx->yield, ec, service,
Cheng C Yang773703a2019-08-15 09:41:11 +08002132 "/xyz/openbmc_project/control/power_supply_redundancy",
2133 "org.freedesktop.DBus.Properties", "Get",
2134 "xyz.openbmc_project.Control.PowerSupplyRedundancy", property);
2135 if (ec)
2136 {
2137 phosphor::logging::log<phosphor::logging::level::ERR>(
2138 "Failed to get dbus property to cold redundancy");
2139 return -1;
2140 }
2141 return 0;
2142}
2143
2144uint8_t getPSUCount(void)
2145{
2146 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
2147 ipmi::Value num;
2148 try
2149 {
2150 num = ipmi::getDbusProperty(
2151 *dbus, "xyz.openbmc_project.PSURedundancy",
2152 "/xyz/openbmc_project/control/power_supply_redundancy",
2153 "xyz.openbmc_project.Control.PowerSupplyRedundancy", "PSUNumber");
2154 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -05002155 catch (const sdbusplus::exception_t& e)
Cheng C Yang773703a2019-08-15 09:41:11 +08002156 {
2157 phosphor::logging::log<phosphor::logging::level::ERR>(
2158 "Failed to get PSUNumber property from dbus interface");
2159 return 0;
2160 }
2161 uint8_t* pNum = std::get_if<uint8_t>(&num);
2162 if (!pNum)
2163 {
2164 phosphor::logging::log<phosphor::logging::level::ERR>(
2165 "Error to get PSU Number");
2166 return 0;
2167 }
2168 return *pNum;
2169}
2170
2171bool validateCRAlgo(std::vector<uint8_t>& conf, uint8_t num)
2172{
2173 if (conf.size() < num)
2174 {
2175 phosphor::logging::log<phosphor::logging::level::ERR>(
2176 "Invalid PSU Ranking");
2177 return false;
2178 }
2179 std::set<uint8_t> confSet;
2180 for (uint8_t i = 0; i < num; i++)
2181 {
2182 if (conf[i] > num)
2183 {
2184 phosphor::logging::log<phosphor::logging::level::ERR>(
2185 "PSU Ranking is larger than current PSU number");
2186 return false;
2187 }
2188 confSet.emplace(conf[i]);
2189 }
2190
2191 if (confSet.size() != num)
2192 {
2193 phosphor::logging::log<phosphor::logging::level::ERR>(
2194 "duplicate PSU Ranking");
2195 return false;
2196 }
2197 return true;
2198}
2199
2200enum class crParameter
2201{
2202 crStatus = 0,
2203 crFeature = 1,
2204 rotationFeature = 2,
2205 rotationAlgo = 3,
2206 rotationPeriod = 4,
Yong Li19445ab2019-12-20 18:25:29 +08002207 numOfPSU = 5,
2208 rotationRankOrderEffective = 6
Cheng C Yang773703a2019-08-15 09:41:11 +08002209};
2210
2211constexpr ipmi::Cc ccParameterNotSupported = 0x80;
2212static const constexpr uint32_t oneDay = 0x15180;
2213static const constexpr uint32_t oneMonth = 0xf53700;
2214static const constexpr uint8_t userSpecific = 0x01;
2215static const constexpr uint8_t crSetCompleted = 0;
2216ipmi::RspType<uint8_t> ipmiOEMSetCRConfig(ipmi::Context::ptr ctx,
2217 uint8_t parameter,
2218 ipmi::message::Payload& payload)
2219{
2220 switch (static_cast<crParameter>(parameter))
2221 {
Cheng C Yang773703a2019-08-15 09:41:11 +08002222 case crParameter::rotationFeature:
2223 {
2224 uint8_t param1;
2225 if (payload.unpack(param1) || !payload.fullyUnpacked())
2226 {
2227 return ipmi::responseReqDataLenInvalid();
2228 }
2229 // Rotation Enable can only be true or false
2230 if (param1 > 1)
2231 {
2232 return ipmi::responseInvalidFieldRequest();
2233 }
2234 if (setCRConfig(ctx, "RotationEnabled", static_cast<bool>(param1)))
2235 {
2236 return ipmi::responseResponseError();
2237 }
2238 break;
2239 }
2240 case crParameter::rotationAlgo:
2241 {
2242 // Rotation Algorithm can only be 0-BMC Specific or 1-User Specific
2243 std::string algoName;
2244 uint8_t param1;
2245 if (payload.unpack(param1))
2246 {
2247 return ipmi::responseReqDataLenInvalid();
2248 }
2249 switch (param1)
2250 {
2251 case 0:
2252 algoName = "xyz.openbmc_project.Control."
2253 "PowerSupplyRedundancy.Algo.bmcSpecific";
2254 break;
2255 case 1:
2256 algoName = "xyz.openbmc_project.Control."
2257 "PowerSupplyRedundancy.Algo.userSpecific";
2258 break;
2259 default:
2260 return ipmi::responseInvalidFieldRequest();
2261 }
2262 if (setCRConfig(ctx, "RotationAlgorithm", algoName))
2263 {
2264 return ipmi::responseResponseError();
2265 }
2266
2267 uint8_t numberOfPSU = getPSUCount();
2268 if (!numberOfPSU)
2269 {
2270 return ipmi::responseResponseError();
2271 }
2272 std::vector<uint8_t> rankOrder;
2273
2274 if (param1 == userSpecific)
2275 {
2276 if (payload.unpack(rankOrder) || !payload.fullyUnpacked())
2277 {
2278 ipmi::responseReqDataLenInvalid();
2279 }
Yong Li83315132019-10-23 17:42:24 +08002280 if (rankOrder.size() != numberOfPSU)
Cheng C Yang773703a2019-08-15 09:41:11 +08002281 {
2282 return ipmi::responseReqDataLenInvalid();
2283 }
2284
2285 if (!validateCRAlgo(rankOrder, numberOfPSU))
2286 {
2287 return ipmi::responseInvalidFieldRequest();
2288 }
2289 }
2290 else
2291 {
2292 if (rankOrder.size() > 0)
2293 {
2294 return ipmi::responseReqDataLenInvalid();
2295 }
2296 for (uint8_t i = 1; i <= numberOfPSU; i++)
2297 {
2298 rankOrder.emplace_back(i);
2299 }
2300 }
2301 if (setCRConfig(ctx, "RotationRankOrder", rankOrder))
2302 {
2303 return ipmi::responseResponseError();
2304 }
2305 break;
2306 }
2307 case crParameter::rotationPeriod:
2308 {
2309 // Minimum Rotation period is One day (86400 seconds) and Max
2310 // Rotation Period is 6 month (0xf53700 seconds)
2311 uint32_t period;
2312 if (payload.unpack(period) || !payload.fullyUnpacked())
2313 {
2314 return ipmi::responseReqDataLenInvalid();
2315 }
2316 if ((period < oneDay) || (period > oneMonth))
2317 {
2318 return ipmi::responseInvalidFieldRequest();
2319 }
2320 if (setCRConfig(ctx, "PeriodOfRotation", period))
2321 {
2322 return ipmi::responseResponseError();
2323 }
2324 break;
2325 }
2326 default:
2327 {
2328 return ipmi::response(ccParameterNotSupported);
2329 }
2330 }
2331
Cheng C Yang773703a2019-08-15 09:41:11 +08002332 return ipmi::responseSuccess(crSetCompleted);
2333}
2334
Yong Li83315132019-10-23 17:42:24 +08002335ipmi::RspType<uint8_t, std::variant<uint8_t, uint32_t, std::vector<uint8_t>>>
Cheng C Yang773703a2019-08-15 09:41:11 +08002336 ipmiOEMGetCRConfig(ipmi::Context::ptr ctx, uint8_t parameter)
2337{
2338 crConfigVariant value;
2339 switch (static_cast<crParameter>(parameter))
2340 {
2341 case crParameter::crStatus:
2342 {
2343 if (getCRConfig(ctx, "ColdRedundancyStatus", value))
2344 {
2345 return ipmi::responseResponseError();
2346 }
2347 std::string* pStatus = std::get_if<std::string>(&value);
2348 if (!pStatus)
2349 {
2350 phosphor::logging::log<phosphor::logging::level::ERR>(
2351 "Error to get ColdRedundancyStatus property");
2352 return ipmi::responseResponseError();
2353 }
2354 namespace server = sdbusplus::xyz::openbmc_project::Control::server;
2355 auto status =
2356 server::PowerSupplyRedundancy::convertStatusFromString(
2357 *pStatus);
2358 switch (status)
2359 {
2360 case server::PowerSupplyRedundancy::Status::inProgress:
Cheng C Yangf41e3342019-09-10 04:47:23 +08002361 return ipmi::responseSuccess(parameter,
Kuiying Wange45333a2020-07-22 22:06:37 +08002362 static_cast<uint8_t>(1));
Cheng C Yang773703a2019-08-15 09:41:11 +08002363
2364 case server::PowerSupplyRedundancy::Status::completed:
Cheng C Yangf41e3342019-09-10 04:47:23 +08002365 return ipmi::responseSuccess(parameter,
Kuiying Wange45333a2020-07-22 22:06:37 +08002366 static_cast<uint8_t>(0));
Cheng C Yang773703a2019-08-15 09:41:11 +08002367 default:
2368 phosphor::logging::log<phosphor::logging::level::ERR>(
2369 "Error to get valid status");
2370 return ipmi::responseResponseError();
2371 }
2372 }
2373 case crParameter::crFeature:
2374 {
Kuiying Wange45333a2020-07-22 22:06:37 +08002375 if (getCRConfig(ctx, "PowerSupplyRedundancyEnabled", value))
Cheng C Yang773703a2019-08-15 09:41:11 +08002376 {
2377 return ipmi::responseResponseError();
2378 }
2379 bool* pResponse = std::get_if<bool>(&value);
2380 if (!pResponse)
2381 {
2382 phosphor::logging::log<phosphor::logging::level::ERR>(
Kuiying Wange45333a2020-07-22 22:06:37 +08002383 "Error to get PowerSupplyRedundancyEnabled property");
Cheng C Yang773703a2019-08-15 09:41:11 +08002384 return ipmi::responseResponseError();
2385 }
2386
Cheng C Yangf41e3342019-09-10 04:47:23 +08002387 return ipmi::responseSuccess(parameter,
2388 static_cast<uint8_t>(*pResponse));
Cheng C Yang773703a2019-08-15 09:41:11 +08002389 }
2390 case crParameter::rotationFeature:
2391 {
2392 if (getCRConfig(ctx, "RotationEnabled", value))
2393 {
2394 return ipmi::responseResponseError();
2395 }
2396 bool* pResponse = std::get_if<bool>(&value);
2397 if (!pResponse)
2398 {
2399 phosphor::logging::log<phosphor::logging::level::ERR>(
2400 "Error to get RotationEnabled property");
2401 return ipmi::responseResponseError();
2402 }
Cheng C Yangf41e3342019-09-10 04:47:23 +08002403 return ipmi::responseSuccess(parameter,
2404 static_cast<uint8_t>(*pResponse));
Cheng C Yang773703a2019-08-15 09:41:11 +08002405 }
2406 case crParameter::rotationAlgo:
2407 {
2408 if (getCRConfig(ctx, "RotationAlgorithm", value))
2409 {
2410 return ipmi::responseResponseError();
2411 }
2412
2413 std::string* pAlgo = std::get_if<std::string>(&value);
2414 if (!pAlgo)
2415 {
2416 phosphor::logging::log<phosphor::logging::level::ERR>(
2417 "Error to get RotationAlgorithm property");
2418 return ipmi::responseResponseError();
2419 }
Yong Li83315132019-10-23 17:42:24 +08002420 std::vector<uint8_t> response;
Cheng C Yang773703a2019-08-15 09:41:11 +08002421 namespace server = sdbusplus::xyz::openbmc_project::Control::server;
2422 auto algo =
2423 server::PowerSupplyRedundancy::convertAlgoFromString(*pAlgo);
Yong Li83315132019-10-23 17:42:24 +08002424
Cheng C Yang773703a2019-08-15 09:41:11 +08002425 switch (algo)
2426 {
2427 case server::PowerSupplyRedundancy::Algo::bmcSpecific:
Yong Li83315132019-10-23 17:42:24 +08002428 response.push_back(0);
Cheng C Yang773703a2019-08-15 09:41:11 +08002429 break;
2430 case server::PowerSupplyRedundancy::Algo::userSpecific:
Yong Li83315132019-10-23 17:42:24 +08002431 response.push_back(1);
Cheng C Yang773703a2019-08-15 09:41:11 +08002432 break;
2433 default:
2434 phosphor::logging::log<phosphor::logging::level::ERR>(
2435 "Error to get valid algo");
2436 return ipmi::responseResponseError();
2437 }
2438
2439 if (getCRConfig(ctx, "RotationRankOrder", value))
2440 {
2441 return ipmi::responseResponseError();
2442 }
2443 std::vector<uint8_t>* pResponse =
2444 std::get_if<std::vector<uint8_t>>(&value);
2445 if (!pResponse)
2446 {
2447 phosphor::logging::log<phosphor::logging::level::ERR>(
2448 "Error to get RotationRankOrder property");
2449 return ipmi::responseResponseError();
2450 }
Yong Li83315132019-10-23 17:42:24 +08002451
Cheng C Yang773703a2019-08-15 09:41:11 +08002452 std::copy(pResponse->begin(), pResponse->end(),
Yong Li83315132019-10-23 17:42:24 +08002453 std::back_inserter(response));
2454
Cheng C Yangf41e3342019-09-10 04:47:23 +08002455 return ipmi::responseSuccess(parameter, response);
Cheng C Yang773703a2019-08-15 09:41:11 +08002456 }
2457 case crParameter::rotationPeriod:
2458 {
2459 if (getCRConfig(ctx, "PeriodOfRotation", value))
2460 {
2461 return ipmi::responseResponseError();
2462 }
2463 uint32_t* pResponse = std::get_if<uint32_t>(&value);
2464 if (!pResponse)
2465 {
2466 phosphor::logging::log<phosphor::logging::level::ERR>(
2467 "Error to get RotationAlgorithm property");
2468 return ipmi::responseResponseError();
2469 }
Cheng C Yangf41e3342019-09-10 04:47:23 +08002470 return ipmi::responseSuccess(parameter, *pResponse);
Cheng C Yang773703a2019-08-15 09:41:11 +08002471 }
2472 case crParameter::numOfPSU:
2473 {
2474 uint8_t numberOfPSU = getPSUCount();
2475 if (!numberOfPSU)
2476 {
2477 return ipmi::responseResponseError();
2478 }
Cheng C Yangf41e3342019-09-10 04:47:23 +08002479 return ipmi::responseSuccess(parameter, numberOfPSU);
Cheng C Yang773703a2019-08-15 09:41:11 +08002480 }
Yong Li19445ab2019-12-20 18:25:29 +08002481 case crParameter::rotationRankOrderEffective:
2482 {
2483 if (getCRConfig(ctx, "RotationRankOrder", value,
2484 "xyz.openbmc_project.PSURedundancy"))
2485 {
2486 return ipmi::responseResponseError();
2487 }
2488 std::vector<uint8_t>* pResponse =
2489 std::get_if<std::vector<uint8_t>>(&value);
2490 if (!pResponse)
2491 {
2492 phosphor::logging::log<phosphor::logging::level::ERR>(
2493 "Error to get effective RotationRankOrder property");
2494 return ipmi::responseResponseError();
2495 }
2496 return ipmi::responseSuccess(parameter, *pResponse);
2497 }
Cheng C Yang773703a2019-08-15 09:41:11 +08002498 default:
2499 {
2500 return ipmi::response(ccParameterNotSupported);
2501 }
2502 }
2503}
2504
Zhu, Yungebe560b02019-04-21 21:19:21 -04002505ipmi::RspType<> ipmiOEMSetFaultIndication(uint8_t sourceId, uint8_t faultType,
2506 uint8_t faultState,
2507 uint8_t faultGroup,
2508 std::array<uint8_t, 8>& ledStateData)
2509{
Zhu, Yungebe560b02019-04-21 21:19:21 -04002510 constexpr auto maxFaultType = static_cast<size_t>(RemoteFaultType::max);
2511 static const std::array<std::string, maxFaultType> faultNames = {
2512 "faultFan", "faultTemp", "faultPower",
2513 "faultDriveSlot", "faultSoftware", "faultMemory"};
Zhu, Yungebe560b02019-04-21 21:19:21 -04002514
2515 constexpr uint8_t maxFaultSource = 0x4;
2516 constexpr uint8_t skipLEDs = 0xFF;
2517 constexpr uint8_t pinSize = 64;
2518 constexpr uint8_t groupSize = 16;
Zhikui Rence4e73f2019-12-06 13:59:47 -08002519 constexpr uint8_t groupNum = 5; // 4 for fault memory, 1 for faultFan
Zhu, Yungebe560b02019-04-21 21:19:21 -04002520
Zhikui Rence4e73f2019-12-06 13:59:47 -08002521 // same pin names need to be defined in dts file
2522 static const std::array<std::array<std::string, groupSize>, groupNum>
2523 faultLedPinNames = {{
2524 "LED_CPU1_CH1_DIMM1_FAULT",
2525 "LED_CPU1_CH1_DIMM2_FAULT",
2526 "LED_CPU1_CH2_DIMM1_FAULT",
2527 "LED_CPU1_CH2_DIMM2_FAULT",
2528 "LED_CPU1_CH3_DIMM1_FAULT",
2529 "LED_CPU1_CH3_DIMM2_FAULT",
2530 "LED_CPU1_CH4_DIMM1_FAULT",
2531 "LED_CPU1_CH4_DIMM2_FAULT",
2532 "LED_CPU1_CH5_DIMM1_FAULT",
2533 "LED_CPU1_CH5_DIMM2_FAULT",
2534 "LED_CPU1_CH6_DIMM1_FAULT",
2535 "LED_CPU1_CH6_DIMM2_FAULT",
2536 "",
2537 "",
2538 "",
2539 "", // end of group1
2540 "LED_CPU2_CH1_DIMM1_FAULT",
2541 "LED_CPU2_CH1_DIMM2_FAULT",
2542 "LED_CPU2_CH2_DIMM1_FAULT",
2543 "LED_CPU2_CH2_DIMM2_FAULT",
2544 "LED_CPU2_CH3_DIMM1_FAULT",
2545 "LED_CPU2_CH3_DIMM2_FAULT",
2546 "LED_CPU2_CH4_DIMM1_FAULT",
2547 "LED_CPU2_CH4_DIMM2_FAULT",
2548 "LED_CPU2_CH5_DIMM1_FAULT",
2549 "LED_CPU2_CH5_DIMM2_FAULT",
2550 "LED_CPU2_CH6_DIMM1_FAULT",
2551 "LED_CPU2_CH6_DIMM2_FAULT",
2552 "",
2553 "",
2554 "",
2555 "", // endof group2
2556 "LED_CPU3_CH1_DIMM1_FAULT",
2557 "LED_CPU3_CH1_DIMM2_FAULT",
2558 "LED_CPU3_CH2_DIMM1_FAULT",
2559 "LED_CPU3_CH2_DIMM2_FAULT",
2560 "LED_CPU3_CH3_DIMM1_FAULT",
2561 "LED_CPU3_CH3_DIMM2_FAULT",
2562 "LED_CPU3_CH4_DIMM1_FAULT",
2563 "LED_CPU3_CH4_DIMM2_FAULT",
2564 "LED_CPU3_CH5_DIMM1_FAULT",
2565 "LED_CPU3_CH5_DIMM2_FAULT",
2566 "LED_CPU3_CH6_DIMM1_FAULT",
2567 "LED_CPU3_CH6_DIMM2_FAULT",
2568 "",
2569 "",
2570 "",
2571 "", // end of group3
2572 "LED_CPU4_CH1_DIMM1_FAULT",
2573 "LED_CPU4_CH1_DIMM2_FAULT",
2574 "LED_CPU4_CH2_DIMM1_FAULT",
2575 "LED_CPU4_CH2_DIMM2_FAULT",
2576 "LED_CPU4_CH3_DIMM1_FAULT",
2577 "LED_CPU4_CH3_DIMM2_FAULT",
2578 "LED_CPU4_CH4_DIMM1_FAULT",
2579 "LED_CPU4_CH4_DIMM2_FAULT",
2580 "LED_CPU4_CH5_DIMM1_FAULT",
2581 "LED_CPU4_CH5_DIMM2_FAULT",
2582 "LED_CPU4_CH6_DIMM1_FAULT",
2583 "LED_CPU4_CH6_DIMM2_FAULT",
2584 "",
2585 "",
2586 "",
2587 "", // end of group4
2588 "LED_FAN1_FAULT",
2589 "LED_FAN2_FAULT",
2590 "LED_FAN3_FAULT",
2591 "LED_FAN4_FAULT",
2592 "LED_FAN5_FAULT",
2593 "LED_FAN6_FAULT",
2594 "LED_FAN7_FAULT",
2595 "LED_FAN8_FAULT",
2596 "",
2597 "",
2598 "",
2599 "",
2600 "",
2601 "",
2602 "",
2603 "" // end of group5
2604 }};
Zhu, Yungebe560b02019-04-21 21:19:21 -04002605
Zhikui Rence4e73f2019-12-06 13:59:47 -08002606 // Validate the source, fault type --
2607 // (Byte 1) sourceId: Unspecified, Hot-Swap Controller 0, Hot-Swap
2608 // Controller 1, BIOS (Byte 2) fault type: fan, temperature, power,
2609 // driveslot, software, memory (Byte 3) FaultState: OK, Degraded,
2610 // Non-Critical, Critical, Non-Recoverable, (Byte 4) is faultGroup,
2611 // definition differs based on fault type (Byte 2)
2612 // Type Fan=> Group: 0=FanGroupID, FF-not used
2613 // Byte 5-11 00h, not used
2614 // Byte12 FanLedState [7:0]-Fans 7:0
2615 // Type Memory=> Group: 0 = DIMM GroupID, FF-not used
2616 // Byte 5:12 - DIMM LED state (64bit field, LS Byte first)
2617 // [63:48] = CPU4 channels 7:0, 2 bits per channel
2618 // [47:32] = CPU3 channels 7:0, 2 bits per channel
2619 // [31:16] = CPU2 channels 7:0, 2 bits per channel
2620 // [15:0] = CPU1 channels 7:0, 2 bits per channel
2621 // Type Other=> Component Fault LED Group ID, not used set to 0xFF
2622 // Byte[5:12]: reserved 0x00h
Zhu, Yungebe560b02019-04-21 21:19:21 -04002623 if ((sourceId >= maxFaultSource) ||
2624 (faultType >= static_cast<int8_t>(RemoteFaultType::max)) ||
2625 (faultState >= static_cast<int8_t>(RemoteFaultState::maxFaultState)) ||
2626 (faultGroup >= static_cast<int8_t>(DimmFaultType::maxFaultGroup)))
2627 {
2628 return ipmi::responseParmOutOfRange();
2629 }
2630
Zhikui Rence4e73f2019-12-06 13:59:47 -08002631 size_t pinGroupOffset = 0;
2632 size_t pinGroupMax = pinSize / groupSize;
2633 if (RemoteFaultType::fan == RemoteFaultType(faultType))
Zhu, Yungebe560b02019-04-21 21:19:21 -04002634 {
Zhikui Rence4e73f2019-12-06 13:59:47 -08002635 pinGroupOffset = 4;
2636 pinGroupMax = groupNum - pinSize / groupSize;
Zhu, Yungebe560b02019-04-21 21:19:21 -04002637 }
2638
2639 switch (RemoteFaultType(faultType))
2640 {
2641 case (RemoteFaultType::fan):
2642 case (RemoteFaultType::memory):
2643 {
2644 if (faultGroup == skipLEDs)
2645 {
2646 return ipmi::responseSuccess();
2647 }
Zhu, Yungebe560b02019-04-21 21:19:21 -04002648 // calculate led state bit filed count, each byte has 8bits
2649 // the maximum bits will be 8 * 8 bits
2650 constexpr uint8_t size = sizeof(ledStateData) * 8;
Zhikui Rence4e73f2019-12-06 13:59:47 -08002651
2652 // assemble ledState
2653 uint64_t ledState = 0;
2654 bool hasError = false;
Zhu, Yungebe560b02019-04-21 21:19:21 -04002655 for (int i = 0; i < sizeof(ledStateData); i++)
2656 {
2657 ledState = (uint64_t)(ledState << 8);
2658 ledState = (uint64_t)(ledState | (uint64_t)ledStateData[i]);
2659 }
Zhu, Yungebe560b02019-04-21 21:19:21 -04002660 std::bitset<size> ledStateBits(ledState);
Zhu, Yungebe560b02019-04-21 21:19:21 -04002661
Zhikui Rence4e73f2019-12-06 13:59:47 -08002662 for (int group = 0; group < pinGroupMax; group++)
2663 {
2664 for (int i = 0; i < groupSize; i++)
2665 { // skip non-existing pins
2666 if (0 == faultLedPinNames[group + pinGroupOffset][i].size())
2667 {
2668 continue;
2669 }
Zhu, Yungebe560b02019-04-21 21:19:21 -04002670
Zhikui Rence4e73f2019-12-06 13:59:47 -08002671 gpiod::line line = gpiod::find_line(
2672 faultLedPinNames[group + pinGroupOffset][i]);
2673 if (!line)
2674 {
2675 phosphor::logging::log<phosphor::logging::level::ERR>(
2676 "Not Find Led Gpio Device!",
2677 phosphor::logging::entry(
2678 "DEVICE=%s",
2679 faultLedPinNames[group + pinGroupOffset][i]
2680 .c_str()));
2681 hasError = true;
2682 continue;
2683 }
Zhu, Yungebe560b02019-04-21 21:19:21 -04002684
Zhikui Rence4e73f2019-12-06 13:59:47 -08002685 bool activeHigh =
2686 (line.active_state() == gpiod::line::ACTIVE_HIGH);
2687 try
2688 {
2689 line.request(
2690 {"faultLed", gpiod::line_request::DIRECTION_OUTPUT,
2691 activeHigh
2692 ? 0
2693 : gpiod::line_request::FLAG_ACTIVE_LOW});
2694 line.set_value(ledStateBits[i + group * groupSize]);
2695 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -05002696 catch (const std::system_error&)
Zhikui Rence4e73f2019-12-06 13:59:47 -08002697 {
2698 phosphor::logging::log<phosphor::logging::level::ERR>(
2699 "Error write Led Gpio Device!",
2700 phosphor::logging::entry(
2701 "DEVICE=%s",
2702 faultLedPinNames[group + pinGroupOffset][i]
2703 .c_str()));
2704 hasError = true;
2705 continue;
2706 }
2707 } // for int i
2708 }
2709 if (hasError)
2710 {
2711 return ipmi::responseResponseError();
Zhu, Yungebe560b02019-04-21 21:19:21 -04002712 }
2713 break;
2714 }
2715 default:
2716 {
2717 // now only support two fault types
2718 return ipmi::responseParmOutOfRange();
2719 }
Zhikui Rence4e73f2019-12-06 13:59:47 -08002720 } // switch
Zhu, Yungebe560b02019-04-21 21:19:21 -04002721 return ipmi::responseSuccess();
2722}
2723
Richard Marian Thomaiyarea537d52019-04-24 21:33:48 +05302724ipmi::RspType<uint8_t> ipmiOEMReadBoardProductId()
2725{
2726 uint8_t prodId = 0;
2727 try
2728 {
Vernon Mauery15419dd2019-05-24 09:40:30 -07002729 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Richard Marian Thomaiyarea537d52019-04-24 21:33:48 +05302730 const DbusObjectInfo& object = getDbusObject(
Vernon Mauery15419dd2019-05-24 09:40:30 -07002731 *dbus, "xyz.openbmc_project.Inventory.Item.Board",
Richard Marian Thomaiyarea537d52019-04-24 21:33:48 +05302732 "/xyz/openbmc_project/inventory/system/board/", "Baseboard");
2733 const Value& propValue = getDbusProperty(
Vernon Mauery15419dd2019-05-24 09:40:30 -07002734 *dbus, object.second, object.first,
Suryakanth Sekar6c57e5c2020-01-10 17:11:58 +05302735 "xyz.openbmc_project.Inventory.Item.Board.Motherboard",
2736 "ProductId");
Richard Marian Thomaiyarea537d52019-04-24 21:33:48 +05302737 prodId = static_cast<uint8_t>(std::get<uint64_t>(propValue));
2738 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -05002739 catch (const std::exception& e)
Richard Marian Thomaiyarea537d52019-04-24 21:33:48 +05302740 {
2741 phosphor::logging::log<phosphor::logging::level::ERR>(
2742 "ipmiOEMReadBoardProductId: Product ID read failed!",
2743 phosphor::logging::entry("ERR=%s", e.what()));
2744 }
2745 return ipmi::responseSuccess(prodId);
2746}
2747
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05302748/** @brief implements the get security mode command
2749 * @param ctx - ctx pointer
2750 *
2751 * @returns IPMI completion code with following data
2752 * - restriction mode value - As specified in
2753 * xyz.openbmc_project.Control.Security.RestrictionMode.interface.yaml
2754 * - special mode value - As specified in
2755 * xyz.openbmc_project.Control.Security.SpecialMode.interface.yaml
2756 */
2757ipmi::RspType<uint8_t, uint8_t> ipmiGetSecurityMode(ipmi::Context::ptr ctx)
2758{
2759 namespace securityNameSpace =
2760 sdbusplus::xyz::openbmc_project::Control::Security::server;
2761 uint8_t restrictionModeValue = 0;
2762 uint8_t specialModeValue = 0;
2763
2764 boost::system::error_code ec;
2765 auto varRestrMode = ctx->bus->yield_method_call<std::variant<std::string>>(
James Feist28c72902019-09-16 10:34:07 -07002766 ctx->yield, ec, restricionModeService, restricionModeBasePath,
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05302767 dBusPropertyIntf, dBusPropertyGetMethod, restricionModeIntf,
2768 restricionModeProperty);
2769 if (ec)
2770 {
2771 phosphor::logging::log<phosphor::logging::level::ERR>(
2772 "ipmiGetSecurityMode: failed to get RestrictionMode property",
2773 phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
2774 return ipmi::responseUnspecifiedError();
2775 }
2776 restrictionModeValue = static_cast<uint8_t>(
2777 securityNameSpace::RestrictionMode::convertModesFromString(
2778 std::get<std::string>(varRestrMode)));
Richard Marian Thomaiyar8d4f8d72019-11-11 12:06:40 +05302779 auto varSpecialMode =
2780 ctx->bus->yield_method_call<std::variant<std::string>>(
2781 ctx->yield, ec, specialModeService, specialModeBasePath,
2782 dBusPropertyIntf, dBusPropertyGetMethod, specialModeIntf,
2783 specialModeProperty);
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05302784 if (ec)
2785 {
2786 phosphor::logging::log<phosphor::logging::level::ERR>(
2787 "ipmiGetSecurityMode: failed to get SpecialMode property",
2788 phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
2789 // fall through, let us not worry about SpecialMode property, which is
2790 // not required in user scenario
2791 }
2792 else
2793 {
Richard Marian Thomaiyar8d4f8d72019-11-11 12:06:40 +05302794 specialModeValue = static_cast<uint8_t>(
2795 securityNameSpace::SpecialMode::convertModesFromString(
2796 std::get<std::string>(varSpecialMode)));
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05302797 }
2798 return ipmi::responseSuccess(restrictionModeValue, specialModeValue);
2799}
2800
2801/** @brief implements the set security mode command
2802 * Command allows to upgrade the restriction mode and won't allow
2803 * to downgrade from system interface
2804 * @param ctx - ctx pointer
2805 * @param restrictionMode - restriction mode value to be set.
2806 *
2807 * @returns IPMI completion code
2808 */
2809ipmi::RspType<> ipmiSetSecurityMode(ipmi::Context::ptr ctx,
Richard Marian Thomaiyar10791062019-11-11 12:19:53 +05302810 uint8_t restrictionMode,
2811 std::optional<uint8_t> specialMode)
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05302812{
Richard Marian Thomaiyar10791062019-11-11 12:19:53 +05302813#ifndef BMC_VALIDATION_UNSECURE_FEATURE
2814 if (specialMode)
2815 {
2816 return ipmi::responseReqDataLenInvalid();
2817 }
2818#endif
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05302819 namespace securityNameSpace =
2820 sdbusplus::xyz::openbmc_project::Control::Security::server;
2821
2822 ChannelInfo chInfo;
2823 if (getChannelInfo(ctx->channel, chInfo) != ccSuccess)
2824 {
2825 phosphor::logging::log<phosphor::logging::level::ERR>(
2826 "ipmiSetSecurityMode: Failed to get Channel Info",
2827 phosphor::logging::entry("CHANNEL=%d", ctx->channel));
2828 return ipmi::responseUnspecifiedError();
2829 }
2830 auto reqMode =
2831 static_cast<securityNameSpace::RestrictionMode::Modes>(restrictionMode);
2832
2833 if ((reqMode < securityNameSpace::RestrictionMode::Modes::Provisioning) ||
2834 (reqMode >
2835 securityNameSpace::RestrictionMode::Modes::ProvisionedHostDisabled))
2836 {
2837 return ipmi::responseInvalidFieldRequest();
2838 }
2839
2840 boost::system::error_code ec;
2841 auto varRestrMode = ctx->bus->yield_method_call<std::variant<std::string>>(
James Feist28c72902019-09-16 10:34:07 -07002842 ctx->yield, ec, restricionModeService, restricionModeBasePath,
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05302843 dBusPropertyIntf, dBusPropertyGetMethod, restricionModeIntf,
2844 restricionModeProperty);
2845 if (ec)
2846 {
2847 phosphor::logging::log<phosphor::logging::level::ERR>(
2848 "ipmiSetSecurityMode: failed to get RestrictionMode property",
2849 phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
2850 return ipmi::responseUnspecifiedError();
2851 }
2852 auto currentRestrictionMode =
2853 securityNameSpace::RestrictionMode::convertModesFromString(
2854 std::get<std::string>(varRestrMode));
2855
2856 if (chInfo.mediumType !=
2857 static_cast<uint8_t>(EChannelMediumType::lan8032) &&
2858 currentRestrictionMode > reqMode)
2859 {
2860 phosphor::logging::log<phosphor::logging::level::ERR>(
2861 "ipmiSetSecurityMode - Downgrading security mode not supported "
2862 "through system interface",
2863 phosphor::logging::entry(
2864 "CUR_MODE=%d", static_cast<uint8_t>(currentRestrictionMode)),
2865 phosphor::logging::entry("REQ_MODE=%d", restrictionMode));
2866 return ipmi::responseCommandNotAvailable();
2867 }
2868
2869 ec.clear();
2870 ctx->bus->yield_method_call<>(
James Feist28c72902019-09-16 10:34:07 -07002871 ctx->yield, ec, restricionModeService, restricionModeBasePath,
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05302872 dBusPropertyIntf, dBusPropertySetMethod, restricionModeIntf,
2873 restricionModeProperty,
2874 static_cast<std::variant<std::string>>(
2875 securityNameSpace::convertForMessage(reqMode)));
2876
2877 if (ec)
2878 {
2879 phosphor::logging::log<phosphor::logging::level::ERR>(
2880 "ipmiSetSecurityMode: failed to set RestrictionMode property",
2881 phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
2882 return ipmi::responseUnspecifiedError();
2883 }
Richard Marian Thomaiyar10791062019-11-11 12:19:53 +05302884
2885#ifdef BMC_VALIDATION_UNSECURE_FEATURE
2886 if (specialMode)
2887 {
Jayaprakash Mutyalad77489f2020-09-05 01:00:04 +00002888 constexpr uint8_t mfgMode = 0x01;
2889 // Manufacturing mode is reserved. So can't enable this mode.
2890 if (specialMode.value() == mfgMode)
2891 {
2892 phosphor::logging::log<phosphor::logging::level::INFO>(
2893 "ipmiSetSecurityMode: Can't enable Manufacturing mode");
2894 return ipmi::responseInvalidFieldRequest();
2895 }
2896
Richard Marian Thomaiyar10791062019-11-11 12:19:53 +05302897 ec.clear();
2898 ctx->bus->yield_method_call<>(
2899 ctx->yield, ec, specialModeService, specialModeBasePath,
2900 dBusPropertyIntf, dBusPropertySetMethod, specialModeIntf,
2901 specialModeProperty,
2902 static_cast<std::variant<std::string>>(
2903 securityNameSpace::convertForMessage(
2904 static_cast<securityNameSpace::SpecialMode::Modes>(
2905 specialMode.value()))));
2906
2907 if (ec)
2908 {
2909 phosphor::logging::log<phosphor::logging::level::ERR>(
2910 "ipmiSetSecurityMode: failed to set SpecialMode property",
2911 phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
2912 return ipmi::responseUnspecifiedError();
2913 }
2914 }
2915#endif
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05302916 return ipmi::responseSuccess();
2917}
2918
Vernon Mauery4ac799d2019-05-20 15:50:37 -07002919ipmi::RspType<uint8_t /* restore status */>
2920 ipmiRestoreConfiguration(const std::array<uint8_t, 3>& clr, uint8_t cmd)
2921{
2922 static constexpr std::array<uint8_t, 3> expClr = {'C', 'L', 'R'};
2923
2924 if (clr != expClr)
2925 {
2926 return ipmi::responseInvalidFieldRequest();
2927 }
2928 constexpr uint8_t cmdStatus = 0;
2929 constexpr uint8_t cmdDefaultRestore = 0xaa;
2930 constexpr uint8_t cmdFullRestore = 0xbb;
2931 constexpr uint8_t cmdFormat = 0xcc;
2932
2933 constexpr const char* restoreOpFname = "/tmp/.rwfs/.restore_op";
2934
2935 switch (cmd)
2936 {
2937 case cmdStatus:
2938 break;
2939 case cmdDefaultRestore:
2940 case cmdFullRestore:
2941 case cmdFormat:
2942 {
2943 // write file to rwfs root
2944 int value = (cmd - 1) & 0x03; // map aa, bb, cc => 1, 2, 3
2945 std::ofstream restoreFile(restoreOpFname);
2946 if (!restoreFile)
2947 {
2948 return ipmi::responseUnspecifiedError();
2949 }
2950 restoreFile << value << "\n";
Arun P. Mohananba1fbc82021-04-26 11:26:53 +05302951
2952 phosphor::logging::log<phosphor::logging::level::WARNING>(
2953 "Restore to default will be performed on next BMC boot",
2954 phosphor::logging::entry("ACTION=0x%0X", cmd));
2955
Vernon Mauery4ac799d2019-05-20 15:50:37 -07002956 break;
2957 }
2958 default:
2959 return ipmi::responseInvalidFieldRequest();
2960 }
2961
2962 constexpr uint8_t restorePending = 0;
2963 constexpr uint8_t restoreComplete = 1;
2964
2965 uint8_t restoreStatus = std::filesystem::exists(restoreOpFname)
2966 ? restorePending
2967 : restoreComplete;
2968 return ipmi::responseSuccess(restoreStatus);
2969}
2970
Chen Yugang39736d52019-07-12 16:24:33 +08002971ipmi::RspType<uint8_t> ipmiOEMGetNmiSource(void)
2972{
2973 uint8_t bmcSource;
Chen Yugang97cf96e2019-11-01 08:55:11 +08002974 namespace nmi = sdbusplus::xyz::openbmc_project::Chassis::Control::server;
Chen Yugang39736d52019-07-12 16:24:33 +08002975
2976 try
2977 {
2978 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
2979 std::string service =
2980 getService(*dbus, oemNmiSourceIntf, oemNmiSourceObjPath);
2981 Value variant =
2982 getDbusProperty(*dbus, service, oemNmiSourceObjPath,
2983 oemNmiSourceIntf, oemNmiBmcSourceObjPathProp);
2984
2985 switch (nmi::NMISource::convertBMCSourceSignalFromString(
2986 std::get<std::string>(variant)))
2987 {
2988 case nmi::NMISource::BMCSourceSignal::None:
2989 bmcSource = static_cast<uint8_t>(NmiSource::none);
2990 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08002991 case nmi::NMISource::BMCSourceSignal::FrontPanelButton:
2992 bmcSource = static_cast<uint8_t>(NmiSource::frontPanelButton);
Chen Yugang39736d52019-07-12 16:24:33 +08002993 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08002994 case nmi::NMISource::BMCSourceSignal::Watchdog:
2995 bmcSource = static_cast<uint8_t>(NmiSource::watchdog);
Chen Yugang39736d52019-07-12 16:24:33 +08002996 break;
2997 case nmi::NMISource::BMCSourceSignal::ChassisCmd:
2998 bmcSource = static_cast<uint8_t>(NmiSource::chassisCmd);
2999 break;
3000 case nmi::NMISource::BMCSourceSignal::MemoryError:
3001 bmcSource = static_cast<uint8_t>(NmiSource::memoryError);
3002 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08003003 case nmi::NMISource::BMCSourceSignal::PciBusError:
3004 bmcSource = static_cast<uint8_t>(NmiSource::pciBusError);
Chen Yugang39736d52019-07-12 16:24:33 +08003005 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08003006 case nmi::NMISource::BMCSourceSignal::PCH:
3007 bmcSource = static_cast<uint8_t>(NmiSource::pch);
Chen Yugang39736d52019-07-12 16:24:33 +08003008 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08003009 case nmi::NMISource::BMCSourceSignal::Chipset:
3010 bmcSource = static_cast<uint8_t>(NmiSource::chipset);
Chen Yugang39736d52019-07-12 16:24:33 +08003011 break;
3012 default:
3013 phosphor::logging::log<phosphor::logging::level::ERR>(
3014 "NMI source: invalid property!",
3015 phosphor::logging::entry(
3016 "PROP=%s", std::get<std::string>(variant).c_str()));
3017 return ipmi::responseResponseError();
3018 }
3019 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -05003020 catch (const sdbusplus::exception::exception& e)
Chen Yugang39736d52019-07-12 16:24:33 +08003021 {
3022 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
3023 return ipmi::responseResponseError();
3024 }
3025
3026 return ipmi::responseSuccess(bmcSource);
3027}
3028
3029ipmi::RspType<> ipmiOEMSetNmiSource(uint8_t sourceId)
3030{
Chen Yugang97cf96e2019-11-01 08:55:11 +08003031 namespace nmi = sdbusplus::xyz::openbmc_project::Chassis::Control::server;
Chen Yugang39736d52019-07-12 16:24:33 +08003032
3033 nmi::NMISource::BMCSourceSignal bmcSourceSignal =
3034 nmi::NMISource::BMCSourceSignal::None;
3035
3036 switch (NmiSource(sourceId))
3037 {
3038 case NmiSource::none:
3039 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::None;
3040 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08003041 case NmiSource::frontPanelButton:
3042 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::FrontPanelButton;
Chen Yugang39736d52019-07-12 16:24:33 +08003043 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08003044 case NmiSource::watchdog:
3045 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::Watchdog;
Chen Yugang39736d52019-07-12 16:24:33 +08003046 break;
3047 case NmiSource::chassisCmd:
3048 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::ChassisCmd;
3049 break;
3050 case NmiSource::memoryError:
3051 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::MemoryError;
3052 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08003053 case NmiSource::pciBusError:
3054 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::PciBusError;
Chen Yugang39736d52019-07-12 16:24:33 +08003055 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08003056 case NmiSource::pch:
3057 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::PCH;
Chen Yugang39736d52019-07-12 16:24:33 +08003058 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08003059 case NmiSource::chipset:
3060 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::Chipset;
Chen Yugang39736d52019-07-12 16:24:33 +08003061 break;
3062 default:
3063 phosphor::logging::log<phosphor::logging::level::ERR>(
3064 "NMI source: invalid property!");
3065 return ipmi::responseResponseError();
3066 }
3067
3068 try
3069 {
3070 // keep NMI signal source
3071 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
3072 std::string service =
3073 getService(*dbus, oemNmiSourceIntf, oemNmiSourceObjPath);
Chen Yugang97cf96e2019-11-01 08:55:11 +08003074 setDbusProperty(*dbus, service, oemNmiSourceObjPath, oemNmiSourceIntf,
3075 oemNmiBmcSourceObjPathProp,
3076 nmi::convertForMessage(bmcSourceSignal));
Chen Yugang99be6332019-08-09 16:20:48 +08003077 // set Enabled property to inform NMI source handling
3078 // to trigger a NMI_OUT BSOD.
3079 // if it's triggered by NMI source property changed,
3080 // NMI_OUT BSOD could be missed if the same source occurs twice in a row
3081 if (bmcSourceSignal != nmi::NMISource::BMCSourceSignal::None)
3082 {
3083 setDbusProperty(*dbus, service, oemNmiSourceObjPath,
3084 oemNmiSourceIntf, oemNmiEnabledObjPathProp,
3085 static_cast<bool>(true));
3086 }
Chen Yugang39736d52019-07-12 16:24:33 +08003087 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -05003088 catch (const sdbusplus::exception_t& e)
Chen Yugang39736d52019-07-12 16:24:33 +08003089 {
3090 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
3091 return ipmi::responseResponseError();
3092 }
3093
3094 return ipmi::responseSuccess();
3095}
3096
James Feist63efafa2019-07-24 12:39:21 -07003097namespace dimmOffset
3098{
3099constexpr const char* dimmPower = "DimmPower";
3100constexpr const char* staticCltt = "StaticCltt";
3101constexpr const char* offsetPath = "/xyz/openbmc_project/Inventory/Item/Dimm";
3102constexpr const char* offsetInterface =
3103 "xyz.openbmc_project.Inventory.Item.Dimm.Offset";
3104constexpr const char* property = "DimmOffset";
3105
3106}; // namespace dimmOffset
3107
3108ipmi::RspType<>
3109 ipmiOEMSetDimmOffset(uint8_t type,
3110 const std::vector<std::tuple<uint8_t, uint8_t>>& data)
3111{
3112 if (type != static_cast<uint8_t>(dimmOffsetTypes::dimmPower) &&
3113 type != static_cast<uint8_t>(dimmOffsetTypes::staticCltt))
3114 {
3115 return ipmi::responseInvalidFieldRequest();
3116 }
3117
3118 if (data.empty())
3119 {
3120 return ipmi::responseInvalidFieldRequest();
3121 }
3122 nlohmann::json json;
3123
3124 std::ifstream jsonStream(dimmOffsetFile);
3125 if (jsonStream.good())
3126 {
3127 json = nlohmann::json::parse(jsonStream, nullptr, false);
3128 if (json.is_discarded())
3129 {
3130 json = nlohmann::json();
3131 }
3132 jsonStream.close();
3133 }
3134
3135 std::string typeName;
3136 if (type == static_cast<uint8_t>(dimmOffsetTypes::dimmPower))
3137 {
3138 typeName = dimmOffset::dimmPower;
3139 }
3140 else
3141 {
3142 typeName = dimmOffset::staticCltt;
3143 }
3144
3145 nlohmann::json& field = json[typeName];
3146
3147 for (const auto& [index, value] : data)
3148 {
3149 field[index] = value;
3150 }
3151
3152 for (nlohmann::json& val : field)
3153 {
3154 if (val == nullptr)
3155 {
3156 val = static_cast<uint8_t>(0);
3157 }
3158 }
3159
3160 std::ofstream output(dimmOffsetFile);
3161 if (!output.good())
3162 {
3163 std::cerr << "Error writing json file\n";
3164 return ipmi::responseResponseError();
3165 }
3166
3167 output << json.dump(4);
3168
3169 if (type == static_cast<uint8_t>(dimmOffsetTypes::staticCltt))
3170 {
3171 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
3172
3173 std::variant<std::vector<uint8_t>> offsets =
3174 field.get<std::vector<uint8_t>>();
3175 auto call = bus->new_method_call(
3176 settingsBusName, dimmOffset::offsetPath, PROP_INTF, "Set");
3177 call.append(dimmOffset::offsetInterface, dimmOffset::property, offsets);
3178 try
3179 {
3180 bus->call(call);
3181 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -05003182 catch (const sdbusplus::exception_t& e)
James Feist63efafa2019-07-24 12:39:21 -07003183 {
3184 phosphor::logging::log<phosphor::logging::level::ERR>(
3185 "ipmiOEMSetDimmOffset: can't set dimm offsets!",
3186 phosphor::logging::entry("ERR=%s", e.what()));
3187 return ipmi::responseResponseError();
3188 }
3189 }
3190
3191 return ipmi::responseSuccess();
3192}
3193
3194ipmi::RspType<uint8_t> ipmiOEMGetDimmOffset(uint8_t type, uint8_t index)
3195{
3196
3197 if (type != static_cast<uint8_t>(dimmOffsetTypes::dimmPower) &&
3198 type != static_cast<uint8_t>(dimmOffsetTypes::staticCltt))
3199 {
3200 return ipmi::responseInvalidFieldRequest();
3201 }
3202
3203 std::ifstream jsonStream(dimmOffsetFile);
3204
3205 auto json = nlohmann::json::parse(jsonStream, nullptr, false);
3206 if (json.is_discarded())
3207 {
3208 std::cerr << "File error in " << dimmOffsetFile << "\n";
3209 return ipmi::responseResponseError();
3210 }
3211
3212 std::string typeName;
3213 if (type == static_cast<uint8_t>(dimmOffsetTypes::dimmPower))
3214 {
3215 typeName = dimmOffset::dimmPower;
3216 }
3217 else
3218 {
3219 typeName = dimmOffset::staticCltt;
3220 }
3221
3222 auto it = json.find(typeName);
3223 if (it == json.end())
3224 {
3225 return ipmi::responseInvalidFieldRequest();
3226 }
3227
3228 if (it->size() <= index)
3229 {
3230 return ipmi::responseInvalidFieldRequest();
3231 }
3232
3233 uint8_t resp = it->at(index).get<uint8_t>();
3234 return ipmi::responseSuccess(resp);
3235}
3236
Chen,Yugang4f7e76b2019-08-20 09:28:06 +08003237namespace boot_options
3238{
3239
3240using namespace sdbusplus::xyz::openbmc_project::Control::Boot::server;
3241using IpmiValue = uint8_t;
3242constexpr auto ipmiDefault = 0;
3243
3244std::map<IpmiValue, Source::Sources> sourceIpmiToDbus = {
3245 {0x01, Source::Sources::Network},
3246 {0x02, Source::Sources::Disk},
3247 {0x05, Source::Sources::ExternalMedia},
3248 {0x0f, Source::Sources::RemovableMedia},
3249 {ipmiDefault, Source::Sources::Default}};
3250
3251std::map<IpmiValue, Mode::Modes> modeIpmiToDbus = {
Chen Yugangca12a7b2019-09-03 18:11:44 +08003252 {0x06, Mode::Modes::Setup}, {ipmiDefault, Mode::Modes::Regular}};
Chen,Yugang4f7e76b2019-08-20 09:28:06 +08003253
3254std::map<Source::Sources, IpmiValue> sourceDbusToIpmi = {
3255 {Source::Sources::Network, 0x01},
3256 {Source::Sources::Disk, 0x02},
3257 {Source::Sources::ExternalMedia, 0x05},
3258 {Source::Sources::RemovableMedia, 0x0f},
3259 {Source::Sources::Default, ipmiDefault}};
3260
3261std::map<Mode::Modes, IpmiValue> modeDbusToIpmi = {
Chen Yugangca12a7b2019-09-03 18:11:44 +08003262 {Mode::Modes::Setup, 0x06}, {Mode::Modes::Regular, ipmiDefault}};
Chen,Yugang4f7e76b2019-08-20 09:28:06 +08003263
3264static constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode";
3265static constexpr auto bootSourceIntf =
3266 "xyz.openbmc_project.Control.Boot.Source";
3267static constexpr auto enabledIntf = "xyz.openbmc_project.Object.Enable";
3268static constexpr auto persistentObjPath =
3269 "/xyz/openbmc_project/control/host0/boot";
3270static constexpr auto oneTimePath =
3271 "/xyz/openbmc_project/control/host0/boot/one_time";
3272static constexpr auto bootSourceProp = "BootSource";
3273static constexpr auto bootModeProp = "BootMode";
3274static constexpr auto oneTimeBootEnableProp = "Enabled";
3275static constexpr auto httpBootMode =
3276 "xyz.openbmc_project.Control.Boot.Source.Sources.Http";
3277
3278enum class BootOptionParameter : size_t
3279{
3280 setInProgress = 0x0,
3281 bootFlags = 0x5,
3282};
3283static constexpr uint8_t setComplete = 0x0;
3284static constexpr uint8_t setInProgress = 0x1;
3285static uint8_t transferStatus = setComplete;
3286static constexpr uint8_t setParmVersion = 0x01;
3287static constexpr uint8_t setParmBootFlagsPermanent = 0x40;
3288static constexpr uint8_t setParmBootFlagsValidOneTime = 0x80;
3289static constexpr uint8_t setParmBootFlagsValidPermanent = 0xC0;
3290static constexpr uint8_t httpBoot = 0xd;
3291static constexpr uint8_t bootSourceMask = 0x3c;
3292
3293} // namespace boot_options
3294
3295ipmi::RspType<uint8_t, // version
3296 uint8_t, // param
3297 uint8_t, // data0, dependent on parameter
3298 std::optional<uint8_t> // data1, dependent on parameter
3299 >
3300 ipmiOemGetEfiBootOptions(uint8_t parameter, uint8_t set, uint8_t block)
3301{
3302 using namespace boot_options;
3303 uint8_t bootOption = 0;
3304
3305 if (parameter == static_cast<uint8_t>(BootOptionParameter::setInProgress))
3306 {
3307 return ipmi::responseSuccess(setParmVersion, parameter, transferStatus,
3308 std::nullopt);
3309 }
3310
3311 if (parameter != static_cast<uint8_t>(BootOptionParameter::bootFlags))
3312 {
3313 phosphor::logging::log<phosphor::logging::level::ERR>(
3314 "Unsupported parameter");
Jayaprakash Mutyala3694d072021-07-22 10:34:37 +00003315 return ipmi::response(ccParameterNotSupported);
Chen,Yugang4f7e76b2019-08-20 09:28:06 +08003316 }
3317
3318 try
3319 {
3320 auto oneTimeEnabled = false;
3321 // read one time Enabled property
3322 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
3323 std::string service = getService(*dbus, enabledIntf, oneTimePath);
3324 Value variant = getDbusProperty(*dbus, service, oneTimePath,
3325 enabledIntf, oneTimeBootEnableProp);
3326 oneTimeEnabled = std::get<bool>(variant);
3327
3328 // get BootSource and BootMode properties
3329 // according to oneTimeEnable
3330 auto bootObjPath = oneTimePath;
3331 if (oneTimeEnabled == false)
3332 {
3333 bootObjPath = persistentObjPath;
3334 }
3335
3336 service = getService(*dbus, bootModeIntf, bootObjPath);
3337 variant = getDbusProperty(*dbus, service, bootObjPath, bootModeIntf,
3338 bootModeProp);
3339
3340 auto bootMode =
3341 Mode::convertModesFromString(std::get<std::string>(variant));
3342
3343 service = getService(*dbus, bootSourceIntf, bootObjPath);
3344 variant = getDbusProperty(*dbus, service, bootObjPath, bootSourceIntf,
3345 bootSourceProp);
3346
3347 if (std::get<std::string>(variant) == httpBootMode)
3348 {
3349 bootOption = httpBoot;
3350 }
3351 else
3352 {
3353 auto bootSource = Source::convertSourcesFromString(
3354 std::get<std::string>(variant));
3355 bootOption = sourceDbusToIpmi.at(bootSource);
3356 if (Source::Sources::Default == bootSource)
3357 {
3358 bootOption = modeDbusToIpmi.at(bootMode);
3359 }
3360 }
3361
3362 uint8_t oneTime = oneTimeEnabled ? setParmBootFlagsValidOneTime
3363 : setParmBootFlagsValidPermanent;
3364 bootOption <<= 2; // shift for responseconstexpr
3365 return ipmi::responseSuccess(setParmVersion, parameter, oneTime,
3366 bootOption);
3367 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -05003368 catch (const sdbusplus::exception_t& e)
Chen,Yugang4f7e76b2019-08-20 09:28:06 +08003369 {
3370 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
3371 return ipmi::responseResponseError();
3372 }
3373}
3374
3375ipmi::RspType<> ipmiOemSetEfiBootOptions(uint8_t bootFlag, uint8_t bootParam,
3376 std::optional<uint8_t> bootOption)
3377{
3378 using namespace boot_options;
3379 auto oneTimeEnabled = false;
3380
3381 if (bootFlag == static_cast<uint8_t>(BootOptionParameter::setInProgress))
3382 {
3383 if (bootOption)
3384 {
3385 return ipmi::responseReqDataLenInvalid();
3386 }
3387
3388 if (transferStatus == setInProgress)
3389 {
3390 phosphor::logging::log<phosphor::logging::level::ERR>(
3391 "boot option set in progress!");
3392 return ipmi::responseResponseError();
3393 }
3394
3395 transferStatus = bootParam;
3396 return ipmi::responseSuccess();
3397 }
3398
3399 if (bootFlag != (uint8_t)BootOptionParameter::bootFlags)
3400 {
3401 phosphor::logging::log<phosphor::logging::level::ERR>(
3402 "Unsupported parameter");
Jayaprakash Mutyala3694d072021-07-22 10:34:37 +00003403 return ipmi::response(ccParameterNotSupported);
Chen,Yugang4f7e76b2019-08-20 09:28:06 +08003404 }
3405
3406 if (!bootOption)
3407 {
3408 return ipmi::responseReqDataLenInvalid();
3409 }
3410
3411 if (((bootOption.value() & bootSourceMask) >> 2) !=
3412 httpBoot) // not http boot, exit
3413 {
3414 phosphor::logging::log<phosphor::logging::level::ERR>(
3415 "wrong boot option parameter!");
3416 return ipmi::responseParmOutOfRange();
3417 }
3418
3419 try
3420 {
3421 bool permanent = (bootParam & setParmBootFlagsPermanent) ==
3422 setParmBootFlagsPermanent;
3423
3424 // read one time Enabled property
3425 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
3426 std::string service = getService(*dbus, enabledIntf, oneTimePath);
3427 Value variant = getDbusProperty(*dbus, service, oneTimePath,
3428 enabledIntf, oneTimeBootEnableProp);
3429 oneTimeEnabled = std::get<bool>(variant);
3430
3431 /*
3432 * Check if the current boot setting is onetime or permanent, if the
3433 * request in the command is otherwise, then set the "Enabled"
3434 * property in one_time object path to 'True' to indicate onetime
3435 * and 'False' to indicate permanent.
3436 *
3437 * Once the onetime/permanent setting is applied, then the bootMode
3438 * and bootSource is updated for the corresponding object.
3439 */
3440 if (permanent == oneTimeEnabled)
3441 {
3442 setDbusProperty(*dbus, service, oneTimePath, enabledIntf,
3443 oneTimeBootEnableProp, !permanent);
3444 }
3445
3446 // set BootSource and BootMode properties
3447 // according to oneTimeEnable or persistent
3448 auto bootObjPath = oneTimePath;
3449 if (oneTimeEnabled == false)
3450 {
3451 bootObjPath = persistentObjPath;
3452 }
3453 std::string bootMode =
3454 "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular";
3455 std::string bootSource = httpBootMode;
3456
3457 service = getService(*dbus, bootModeIntf, bootObjPath);
3458 setDbusProperty(*dbus, service, bootObjPath, bootModeIntf, bootModeProp,
3459 bootMode);
3460
3461 service = getService(*dbus, bootSourceIntf, bootObjPath);
3462 setDbusProperty(*dbus, service, bootObjPath, bootSourceIntf,
3463 bootSourceProp, bootSource);
3464 }
Patrick Williamsbd51e6a2021-10-06 13:09:44 -05003465 catch (const sdbusplus::exception_t& e)
Chen,Yugang4f7e76b2019-08-20 09:28:06 +08003466 {
3467 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
3468 return ipmi::responseResponseError();
3469 }
3470
3471 return ipmi::responseSuccess();
3472}
3473
Cheng C Yang4e6ee152019-09-25 10:27:44 +08003474using BasicVariantType =
3475 std::variant<std::vector<std::string>, std::vector<uint64_t>, std::string,
3476 int64_t, uint64_t, double, int32_t, uint32_t, int16_t,
3477 uint16_t, uint8_t, bool>;
3478using PropertyMapType =
3479 boost::container::flat_map<std::string, BasicVariantType>;
3480static constexpr const std::array<const char*, 1> psuPresenceTypes = {
3481 "xyz.openbmc_project.Configuration.PSUPresence"};
3482int getPSUAddress(ipmi::Context::ptr ctx, uint8_t& bus,
3483 std::vector<uint64_t>& addrTable)
3484{
3485 boost::system::error_code ec;
3486 GetSubTreeType subtree = ctx->bus->yield_method_call<GetSubTreeType>(
3487 ctx->yield, ec, "xyz.openbmc_project.ObjectMapper",
3488 "/xyz/openbmc_project/object_mapper",
3489 "xyz.openbmc_project.ObjectMapper", "GetSubTree",
3490 "/xyz/openbmc_project/inventory/system", 3, psuPresenceTypes);
3491 if (ec)
3492 {
3493 phosphor::logging::log<phosphor::logging::level::ERR>(
3494 "Failed to set dbus property to cold redundancy");
3495 return -1;
3496 }
3497 for (const auto& object : subtree)
3498 {
3499 std::string pathName = object.first;
3500 for (const auto& serviceIface : object.second)
3501 {
3502 std::string serviceName = serviceIface.first;
3503
3504 ec.clear();
3505 PropertyMapType propMap =
3506 ctx->bus->yield_method_call<PropertyMapType>(
3507 ctx->yield, ec, serviceName, pathName,
3508 "org.freedesktop.DBus.Properties", "GetAll",
3509 "xyz.openbmc_project.Configuration.PSUPresence");
3510 if (ec)
3511 {
3512 phosphor::logging::log<phosphor::logging::level::ERR>(
3513 "Failed to set dbus property to cold redundancy");
3514 return -1;
3515 }
3516 auto psuBus = std::get_if<uint64_t>(&propMap["Bus"]);
3517 auto psuAddress =
3518 std::get_if<std::vector<uint64_t>>(&propMap["Address"]);
3519
3520 if (psuBus == nullptr || psuAddress == nullptr)
3521 {
3522 std::cerr << "error finding necessary "
3523 "entry in configuration\n";
3524 return -1;
3525 }
3526 bus = static_cast<uint8_t>(*psuBus);
3527 addrTable = *psuAddress;
3528 return 0;
3529 }
3530 }
3531 return -1;
3532}
3533
3534static const constexpr uint8_t addrOffset = 8;
3535static const constexpr uint8_t psuRevision = 0xd9;
3536static const constexpr uint8_t defaultPSUBus = 7;
3537// Second Minor, Primary Minor, Major
3538static const constexpr size_t verLen = 3;
3539ipmi::RspType<std::vector<uint8_t>> ipmiOEMGetPSUVersion(ipmi::Context::ptr ctx)
3540{
3541 uint8_t bus = defaultPSUBus;
3542 std::vector<uint64_t> addrTable;
3543 std::vector<uint8_t> result;
3544 if (getPSUAddress(ctx, bus, addrTable))
3545 {
3546 std::cerr << "Failed to get PSU bus and address\n";
3547 return ipmi::responseResponseError();
3548 }
3549
3550 for (const auto& slaveAddr : addrTable)
3551 {
3552 std::vector<uint8_t> writeData = {psuRevision};
3553 std::vector<uint8_t> readBuf(verLen);
3554 uint8_t addr = static_cast<uint8_t>(slaveAddr) + addrOffset;
3555 std::string i2cBus = "/dev/i2c-" + std::to_string(bus);
3556
3557 auto retI2C = ipmi::i2cWriteRead(i2cBus, addr, writeData, readBuf);
3558 if (retI2C != ipmi::ccSuccess)
3559 {
3560 for (size_t idx = 0; idx < verLen; idx++)
3561 {
3562 result.emplace_back(0x00);
3563 }
3564 }
3565 else
3566 {
3567 for (const uint8_t& data : readBuf)
3568 {
3569 result.emplace_back(data);
3570 }
3571 }
3572 }
3573
3574 return ipmi::responseSuccess(result);
3575}
3576
srikanta mondal2030d7c2020-05-03 17:25:25 +00003577std::optional<uint8_t> getMultiNodeInfoPresence(ipmi::Context::ptr ctx,
3578 const std::string& name)
3579{
3580 Value dbusValue = 0;
3581 std::string serviceName;
3582
3583 boost::system::error_code ec =
3584 ipmi::getService(ctx, multiNodeIntf, multiNodeObjPath, serviceName);
3585
3586 if (ec)
3587 {
3588 phosphor::logging::log<phosphor::logging::level::ERR>(
3589 "Failed to perform Multinode getService.");
3590 return std::nullopt;
3591 }
3592
3593 ec = ipmi::getDbusProperty(ctx, serviceName, multiNodeObjPath,
3594 multiNodeIntf, name, dbusValue);
3595 if (ec)
3596 {
3597 phosphor::logging::log<phosphor::logging::level::ERR>(
3598 "Failed to perform Multinode get property");
3599 return std::nullopt;
3600 }
3601
3602 auto multiNodeVal = std::get_if<uint8_t>(&dbusValue);
3603 if (!multiNodeVal)
3604 {
3605 phosphor::logging::log<phosphor::logging::level::ERR>(
3606 "getMultiNodeInfoPresence: error to get multinode");
3607 return std::nullopt;
3608 }
3609 return *multiNodeVal;
3610}
3611
3612/** @brief implements OEM get reading command
3613 * @param domain ID
3614 * @param reading Type
3615 * - 00h = platform Power Consumption
3616 * - 01h = inlet Air Temp
3617 * - 02h = icc_TDC from PECI
3618 * @param reserved, write as 0000h
3619 *
3620 * @returns IPMI completion code plus response data
3621 * - response
3622 * - domain ID
3623 * - reading Type
3624 * - 00h = platform Power Consumption
3625 * - 01h = inlet Air Temp
3626 * - 02h = icc_TDC from PECI
3627 * - reading
3628 */
3629ipmi::RspType<uint4_t, // domain ID
3630 uint4_t, // reading Type
3631 uint16_t // reading Value
3632 >
3633 ipmiOEMGetReading(ipmi::Context::ptr ctx, uint4_t domainId,
3634 uint4_t readingType, uint16_t reserved)
3635{
3636 constexpr uint8_t platformPower = 0;
3637 constexpr uint8_t inletAirTemp = 1;
3638 constexpr uint8_t iccTdc = 2;
3639
3640 if ((static_cast<uint8_t>(readingType) > iccTdc) || domainId || reserved)
3641 {
3642 return ipmi::responseInvalidFieldRequest();
3643 }
3644
3645 // This command should run only from multi-node product.
3646 // For all other platforms this command will return invalid.
3647
3648 std::optional<uint8_t> nodeInfo =
3649 getMultiNodeInfoPresence(ctx, "NodePresence");
3650 if (!nodeInfo || !*nodeInfo)
3651 {
3652 return ipmi::responseInvalidCommand();
3653 }
3654
3655 uint16_t oemReadingValue = 0;
3656 if (static_cast<uint8_t>(readingType) == inletAirTemp)
3657 {
3658 double value = 0;
3659 boost::system::error_code ec = ipmi::getDbusProperty(
3660 ctx, "xyz.openbmc_project.HwmonTempSensor",
3661 "/xyz/openbmc_project/sensors/temperature/Inlet_BRD_Temp",
3662 "xyz.openbmc_project.Sensor.Value", "Value", value);
3663 if (ec)
3664 {
3665 phosphor::logging::log<phosphor::logging::level::ERR>(
3666 "Failed to get BMC Get OEM temperature",
3667 phosphor::logging::entry("EXCEPTION=%s", ec.message().c_str()));
3668 return ipmi::responseUnspecifiedError();
3669 }
3670 // Take the Inlet temperature
3671 oemReadingValue = static_cast<uint16_t>(value);
3672 }
3673 else
3674 {
3675 phosphor::logging::log<phosphor::logging::level::ERR>(
3676 "Currently Get OEM Reading support only for Inlet Air Temp");
3677 return ipmi::responseParmOutOfRange();
3678 }
3679 return ipmi::responseSuccess(domainId, readingType, oemReadingValue);
3680}
3681
AppaRao Puli28972062019-11-11 02:04:45 +05303682/** @brief implements the maximum size of
3683 * bridgeable messages used between KCS and
3684 * IPMB interfacesget security mode command.
3685 *
3686 * @returns IPMI completion code with following data
3687 * - KCS Buffer Size (In multiples of four bytes)
3688 * - IPMB Buffer Size (In multiples of four bytes)
3689 **/
3690ipmi::RspType<uint8_t, uint8_t> ipmiOEMGetBufferSize()
3691{
3692 // for now this is hard coded; really this number is dependent on
3693 // the BMC kcs driver as well as the host kcs driver....
3694 // we can't know the latter.
3695 uint8_t kcsMaxBufferSize = 63 / 4;
3696 uint8_t ipmbMaxBufferSize = 128 / 4;
3697
3698 return ipmi::responseSuccess(kcsMaxBufferSize, ipmbMaxBufferSize);
3699}
3700
Jason M. Bills64796042018-10-03 16:51:55 -07003701static void registerOEMFunctions(void)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +08003702{
3703 phosphor::logging::log<phosphor::logging::level::INFO>(
3704 "Registering OEM commands");
Vernon Mauery98bbf692019-09-16 11:14:59 -07003705 ipmiPrintAndRegister(intel::netFnGeneral,
3706 intel::general::cmdGetChassisIdentifier, NULL,
3707 ipmiOEMGetChassisIdentifier,
3708 PRIVILEGE_USER); // get chassis identifier
3709
3710 ipmiPrintAndRegister(intel::netFnGeneral, intel::general::cmdSetSystemGUID,
3711 NULL, ipmiOEMSetSystemGUID,
3712 PRIVILEGE_ADMIN); // set system guid
Jason M. Billsb02bf092019-08-15 13:01:56 -07003713
3714 // <Disable BMC System Reset Action>
Vernon Mauery98bbf692019-09-16 11:14:59 -07003715 registerHandler(prioOemBase, intel::netFnGeneral,
3716 intel::general::cmdDisableBMCSystemReset, Privilege::Admin,
3717 ipmiOEMDisableBMCSystemReset);
3718
Jason M. Billsb02bf092019-08-15 13:01:56 -07003719 // <Get BMC Reset Disables>
Vernon Mauery98bbf692019-09-16 11:14:59 -07003720 registerHandler(prioOemBase, intel::netFnGeneral,
3721 intel::general::cmdGetBMCResetDisables, Privilege::Admin,
3722 ipmiOEMGetBMCResetDisables);
Jason M. Billsb02bf092019-08-15 13:01:56 -07003723
Vernon Mauery98bbf692019-09-16 11:14:59 -07003724 ipmiPrintAndRegister(intel::netFnGeneral, intel::general::cmdSetBIOSID,
3725 NULL, ipmiOEMSetBIOSID, PRIVILEGE_ADMIN);
Jia, Chunhuicc49b542019-03-20 15:41:07 +08003726
Chen Yugang7a04f3a2019-10-08 11:12:35 +08003727 registerHandler(prioOemBase, intel::netFnGeneral,
3728 intel::general::cmdGetOEMDeviceInfo, Privilege::User,
3729 ipmiOEMGetDeviceInfo);
Jia, Chunhuicc49b542019-03-20 15:41:07 +08003730
Vernon Mauery98bbf692019-09-16 11:14:59 -07003731 ipmiPrintAndRegister(intel::netFnGeneral,
3732 intel::general::cmdGetAICSlotFRUIDSlotPosRecords, NULL,
3733 ipmiOEMGetAICFRU, PRIVILEGE_USER);
Suryakanth Sekard509eb92018-11-15 17:44:11 +05303734
Vernon Mauery98bbf692019-09-16 11:14:59 -07003735 registerHandler(prioOpenBmcBase, intel::netFnGeneral,
3736 intel::general::cmdSendEmbeddedFWUpdStatus,
3737 Privilege::Operator, ipmiOEMSendEmbeddedFwUpdStatus);
Suryakanth Sekard509eb92018-11-15 17:44:11 +05303738
Rajashekar Gade Reddy2b664d52020-03-23 22:09:00 +05303739 registerHandler(prioOpenBmcBase, intel::netFnApp, intel::app::cmdSlotIpmb,
3740 Privilege::Admin, ipmiOEMSlotIpmb);
3741
Vernon Mauery98bbf692019-09-16 11:14:59 -07003742 ipmiPrintAndRegister(intel::netFnGeneral,
3743 intel::general::cmdSetPowerRestoreDelay, NULL,
3744 ipmiOEMSetPowerRestoreDelay, PRIVILEGE_OPERATOR);
3745
3746 ipmiPrintAndRegister(intel::netFnGeneral,
3747 intel::general::cmdGetPowerRestoreDelay, NULL,
3748 ipmiOEMGetPowerRestoreDelay, PRIVILEGE_USER);
3749
3750 registerHandler(prioOpenBmcBase, intel::netFnGeneral,
3751 intel::general::cmdSetOEMUser2Activation,
3752 Privilege::Callback, ipmiOEMSetUser2Activation);
3753
3754 registerHandler(prioOpenBmcBase, intel::netFnGeneral,
3755 intel::general::cmdSetSpecialUserPassword,
3756 Privilege::Callback, ipmiOEMSetSpecialUserPassword);
Richard Marian Thomaiyarfc5e9852019-04-14 15:06:27 +05303757
Jason M. Bills42bd9c82019-06-28 16:39:34 -07003758 // <Get Processor Error Config>
Vernon Mauery98bbf692019-09-16 11:14:59 -07003759 registerHandler(prioOemBase, intel::netFnGeneral,
3760 intel::general::cmdGetProcessorErrConfig, Privilege::User,
3761 ipmiOEMGetProcessorErrConfig);
3762
Jason M. Bills42bd9c82019-06-28 16:39:34 -07003763 // <Set Processor Error Config>
Vernon Mauery98bbf692019-09-16 11:14:59 -07003764 registerHandler(prioOemBase, intel::netFnGeneral,
3765 intel::general::cmdSetProcessorErrConfig, Privilege::Admin,
3766 ipmiOEMSetProcessorErrConfig);
Jason M. Bills42bd9c82019-06-28 16:39:34 -07003767
Vernon Mauery98bbf692019-09-16 11:14:59 -07003768 ipmiPrintAndRegister(intel::netFnGeneral,
3769 intel::general::cmdSetShutdownPolicy, NULL,
3770 ipmiOEMSetShutdownPolicy, PRIVILEGE_ADMIN);
James Feist91244a62019-02-19 15:04:54 -08003771
Vernon Mauery98bbf692019-09-16 11:14:59 -07003772 ipmiPrintAndRegister(intel::netFnGeneral,
3773 intel::general::cmdGetShutdownPolicy, NULL,
3774 ipmiOEMGetShutdownPolicy, PRIVILEGE_ADMIN);
James Feist91244a62019-02-19 15:04:54 -08003775
anil kumar appanaf945eee2019-09-25 23:29:11 +00003776 registerHandler(prioOemBase, intel::netFnGeneral,
3777 intel::general::cmdSetFanConfig, Privilege::User,
3778 ipmiOEMSetFanConfig);
James Feist91244a62019-02-19 15:04:54 -08003779
Vernon Mauery98bbf692019-09-16 11:14:59 -07003780 registerHandler(prioOemBase, intel::netFnGeneral,
3781 intel::general::cmdGetFanConfig, Privilege::User,
3782 ipmiOEMGetFanConfig);
James Feist5f957ca2019-03-14 15:33:55 -07003783
Vernon Mauery98bbf692019-09-16 11:14:59 -07003784 registerHandler(prioOemBase, intel::netFnGeneral,
3785 intel::general::cmdGetFanSpeedOffset, Privilege::User,
3786 ipmiOEMGetFanSpeedOffset);
James Feistacc8a4e2019-04-02 14:23:57 -07003787
Vernon Mauery98bbf692019-09-16 11:14:59 -07003788 registerHandler(prioOemBase, intel::netFnGeneral,
3789 intel::general::cmdSetFanSpeedOffset, Privilege::User,
3790 ipmiOEMSetFanSpeedOffset);
James Feistacc8a4e2019-04-02 14:23:57 -07003791
Vernon Mauery98bbf692019-09-16 11:14:59 -07003792 registerHandler(prioOemBase, intel::netFnGeneral,
3793 intel::general::cmdSetFscParameter, Privilege::User,
3794 ipmiOEMSetFscParameter);
James Feist5f957ca2019-03-14 15:33:55 -07003795
Vernon Mauery98bbf692019-09-16 11:14:59 -07003796 registerHandler(prioOemBase, intel::netFnGeneral,
3797 intel::general::cmdGetFscParameter, Privilege::User,
3798 ipmiOEMGetFscParameter);
Richard Marian Thomaiyarea537d52019-04-24 21:33:48 +05303799
Vernon Mauery98bbf692019-09-16 11:14:59 -07003800 registerHandler(prioOpenBmcBase, intel::netFnGeneral,
3801 intel::general::cmdReadBaseBoardProductId, Privilege::Admin,
3802 ipmiOEMReadBoardProductId);
Chen Yugang39736d52019-07-12 16:24:33 +08003803
Vernon Mauery98bbf692019-09-16 11:14:59 -07003804 registerHandler(prioOemBase, intel::netFnGeneral,
3805 intel::general::cmdGetNmiStatus, Privilege::User,
3806 ipmiOEMGetNmiSource);
Chen Yugang39736d52019-07-12 16:24:33 +08003807
Vernon Mauery98bbf692019-09-16 11:14:59 -07003808 registerHandler(prioOemBase, intel::netFnGeneral,
3809 intel::general::cmdSetNmiStatus, Privilege::Operator,
3810 ipmiOEMSetNmiSource);
Chen,Yugang4f7e76b2019-08-20 09:28:06 +08003811
Vernon Mauery98bbf692019-09-16 11:14:59 -07003812 registerHandler(prioOemBase, intel::netFnGeneral,
3813 intel::general::cmdGetEfiBootOptions, Privilege::User,
3814 ipmiOemGetEfiBootOptions);
Chen,Yugang4f7e76b2019-08-20 09:28:06 +08003815
Vernon Mauery98bbf692019-09-16 11:14:59 -07003816 registerHandler(prioOemBase, intel::netFnGeneral,
3817 intel::general::cmdSetEfiBootOptions, Privilege::Operator,
3818 ipmiOemSetEfiBootOptions);
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05303819
Vernon Mauery98bbf692019-09-16 11:14:59 -07003820 registerHandler(prioOemBase, intel::netFnGeneral,
3821 intel::general::cmdGetSecurityMode, Privilege::User,
3822 ipmiGetSecurityMode);
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05303823
Vernon Mauery98bbf692019-09-16 11:14:59 -07003824 registerHandler(prioOemBase, intel::netFnGeneral,
3825 intel::general::cmdSetSecurityMode, Privilege::Admin,
3826 ipmiSetSecurityMode);
Vernon Mauery4ac799d2019-05-20 15:50:37 -07003827
NITIN SHARMAabd11ca2019-06-12 12:31:42 +00003828 registerHandler(prioOemBase, intel::netFnGeneral,
3829 intel::general::cmdGetLEDStatus, Privilege::Admin,
3830 ipmiOEMGetLEDStatus);
Cheng C Yang773703a2019-08-15 09:41:11 +08003831
Vernon Mauery98bbf692019-09-16 11:14:59 -07003832 ipmiPrintAndRegister(ipmi::intel::netFnPlatform,
3833 ipmi::intel::platform::cmdCfgHostSerialPortSpeed, NULL,
3834 ipmiOEMCfgHostSerialPortSpeed, PRIVILEGE_ADMIN);
3835
3836 registerHandler(prioOemBase, intel::netFnGeneral,
3837 intel::general::cmdSetFaultIndication, Privilege::Operator,
3838 ipmiOEMSetFaultIndication);
3839
3840 registerHandler(prioOemBase, intel::netFnGeneral,
3841 intel::general::cmdSetColdRedundancyConfig, Privilege::User,
3842 ipmiOEMSetCRConfig);
3843
3844 registerHandler(prioOemBase, intel::netFnGeneral,
3845 intel::general::cmdGetColdRedundancyConfig, Privilege::User,
3846 ipmiOEMGetCRConfig);
3847
3848 registerHandler(prioOemBase, intel::netFnGeneral,
3849 intel::general::cmdRestoreConfiguration, Privilege::Admin,
Vernon Mauery4ac799d2019-05-20 15:50:37 -07003850 ipmiRestoreConfiguration);
James Feist63efafa2019-07-24 12:39:21 -07003851
Vernon Mauery98bbf692019-09-16 11:14:59 -07003852 registerHandler(prioOemBase, intel::netFnGeneral,
3853 intel::general::cmdSetDimmOffset, Privilege::Operator,
3854 ipmiOEMSetDimmOffset);
James Feist63efafa2019-07-24 12:39:21 -07003855
Vernon Mauery98bbf692019-09-16 11:14:59 -07003856 registerHandler(prioOemBase, intel::netFnGeneral,
3857 intel::general::cmdGetDimmOffset, Privilege::Operator,
3858 ipmiOEMGetDimmOffset);
Chen Yugangca12a7b2019-09-03 18:11:44 +08003859
Cheng C Yang4e6ee152019-09-25 10:27:44 +08003860 registerHandler(prioOemBase, intel::netFnGeneral,
3861 intel::general::cmdGetPSUVersion, Privilege::User,
3862 ipmiOEMGetPSUVersion);
AppaRao Puli28972062019-11-11 02:04:45 +05303863
3864 registerHandler(prioOemBase, intel::netFnGeneral,
3865 intel::general::cmdGetBufferSize, Privilege::User,
3866 ipmiOEMGetBufferSize);
srikanta mondal2030d7c2020-05-03 17:25:25 +00003867
3868 registerHandler(prioOemBase, intel::netFnGeneral,
3869 intel::general::cmdOEMGetReading, Privilege::User,
3870 ipmiOEMGetReading);
Jia, Chunhuia835eaa2018-09-05 09:00:41 +08003871}
3872
3873} // namespace ipmi