blob: ad2e21ebdc8877cc3da40b6db59ab61bc8b38ed4 [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
Jason M. Bills64796042018-10-03 16:51:55 -070017#include "xyz/openbmc_project/Common/error.hpp"
Kuiying Wang45f04982018-12-26 09:23:08 +080018#include "xyz/openbmc_project/Led/Physical/server.hpp"
Jason M. Bills64796042018-10-03 16:51:55 -070019
Jia, Chunhuicc49b542019-03-20 15:41:07 +080020#include <systemd/sd-journal.h>
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080021
Chen Yugang7a04f3a2019-10-08 11:12:35 +080022#include <appcommands.hpp>
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080023#include <array>
James Feist91244a62019-02-19 15:04:54 -080024#include <boost/container/flat_map.hpp>
Yong Li23737fe2019-02-19 08:49:55 +080025#include <boost/process/child.hpp>
26#include <boost/process/io.hpp>
Yong Li0669d192019-05-06 14:01:46 +080027#include <com/intel/Control/OCOTShutdownPolicy/server.hpp>
Jason M. Bills64796042018-10-03 16:51:55 -070028#include <commandutils.hpp>
Vernon Mauery4ac799d2019-05-20 15:50:37 -070029#include <filesystem>
Zhikui Rence4e73f2019-12-06 13:59:47 -080030#include <gpiod.hpp>
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080031#include <iostream>
Jia, Chunhuicc49b542019-03-20 15:41:07 +080032#include <ipmid/api.hpp>
Vernon Mauery5480ef62019-03-20 13:43:11 -070033#include <ipmid/utils.hpp>
James Feist63efafa2019-07-24 12:39:21 -070034#include <nlohmann/json.hpp>
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080035#include <oemcommands.hpp>
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080036#include <phosphor-logging/log.hpp>
Chen Yugang7a04f3a2019-10-08 11:12:35 +080037#include <regex>
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080038#include <sdbusplus/bus.hpp>
Suryakanth Sekard509eb92018-11-15 17:44:11 +053039#include <sdbusplus/message/types.hpp>
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080040#include <string>
James Feist91244a62019-02-19 15:04:54 -080041#include <variant>
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080042#include <vector>
Chen Yugang97cf96e2019-11-01 08:55:11 +080043#include <xyz/openbmc_project/Chassis/Control/NMISource/server.hpp>
Chen,Yugang4f7e76b2019-08-20 09:28:06 +080044#include <xyz/openbmc_project/Control/Boot/Mode/server.hpp>
45#include <xyz/openbmc_project/Control/Boot/Source/server.hpp>
Cheng C Yang773703a2019-08-15 09:41:11 +080046#include <xyz/openbmc_project/Control/PowerSupplyRedundancy/server.hpp>
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +053047#include <xyz/openbmc_project/Control/Security/RestrictionMode/server.hpp>
Richard Marian Thomaiyar8d4f8d72019-11-11 12:06:40 +053048#include <xyz/openbmc_project/Control/Security/SpecialMode/server.hpp>
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080049
50namespace ipmi
51{
Jason M. Bills64796042018-10-03 16:51:55 -070052static void registerOEMFunctions() __attribute__((constructor));
Vernon Mauery4ac799d2019-05-20 15:50:37 -070053
Jason M. Bills64796042018-10-03 16:51:55 -070054static constexpr size_t maxFRUStringLength = 0x3F;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080055
Suryakanth Sekard509eb92018-11-15 17:44:11 +053056static constexpr auto ethernetIntf =
57 "xyz.openbmc_project.Network.EthernetInterface";
58static constexpr auto networkIPIntf = "xyz.openbmc_project.Network.IP";
59static constexpr auto networkService = "xyz.openbmc_project.Network";
60static constexpr auto networkRoot = "/xyz/openbmc_project/network";
61
Chen Yugang97cf96e2019-11-01 08:55:11 +080062static constexpr const char* oemNmiSourceIntf =
63 "xyz.openbmc_project.Chassis.Control.NMISource";
Chen Yugang39736d52019-07-12 16:24:33 +080064static constexpr const char* oemNmiSourceObjPath =
Chen Yugang97cf96e2019-11-01 08:55:11 +080065 "/xyz/openbmc_project/Chassis/Control/NMISource";
Chen Yugang39736d52019-07-12 16:24:33 +080066static constexpr const char* oemNmiBmcSourceObjPathProp = "BMCSource";
67static constexpr const char* oemNmiEnabledObjPathProp = "Enabled";
68
James Feist63efafa2019-07-24 12:39:21 -070069static constexpr const char* dimmOffsetFile = "/var/lib/ipmi/ipmi_dimms.json";
70
Chen Yugang39736d52019-07-12 16:24:33 +080071enum class NmiSource : uint8_t
72{
73 none = 0,
Chen Yugang97cf96e2019-11-01 08:55:11 +080074 frontPanelButton = 1,
75 watchdog = 2,
76 chassisCmd = 3,
77 memoryError = 4,
78 pciBusError = 5,
79 pch = 6,
80 chipset = 7,
Chen Yugang39736d52019-07-12 16:24:33 +080081};
82
Suryakanth Sekar822b0b42019-11-15 18:32:53 +053083enum class SpecialUserIndex : uint8_t
84{
85 rootUser = 0,
86 atScaleDebugUser = 1
87};
88
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +053089static constexpr const char* restricionModeService =
90 "xyz.openbmc_project.RestrictionMode.Manager";
91static constexpr const char* restricionModeBasePath =
92 "/xyz/openbmc_project/control/security/restriction_mode";
93static constexpr const char* restricionModeIntf =
94 "xyz.openbmc_project.Control.Security.RestrictionMode";
95static constexpr const char* restricionModeProperty = "RestrictionMode";
96
97static constexpr const char* specialModeService =
98 "xyz.openbmc_project.SpecialMode";
99static constexpr const char* specialModeBasePath =
Richard Marian Thomaiyara7b74282019-09-22 21:53:14 +0530100 "/xyz/openbmc_project/security/special_mode";
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +0530101static constexpr const char* specialModeIntf =
102 "xyz.openbmc_project.Security.SpecialMode";
103static constexpr const char* specialModeProperty = "SpecialMode";
104
105static constexpr const char* dBusPropertyIntf =
106 "org.freedesktop.DBus.Properties";
107static constexpr const char* dBusPropertyGetMethod = "Get";
108static constexpr const char* dBusPropertySetMethod = "Set";
109
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800110// return code: 0 successful
111int8_t getChassisSerialNumber(sdbusplus::bus::bus& bus, std::string& serial)
112{
113 std::string objpath = "/xyz/openbmc_project/FruDevice";
114 std::string intf = "xyz.openbmc_project.FruDeviceManager";
115 std::string service = getService(bus, intf, objpath);
116 ObjectValueTree valueTree = getManagedObjects(bus, service, "/");
117 if (valueTree.empty())
118 {
119 phosphor::logging::log<phosphor::logging::level::ERR>(
120 "No object implements interface",
121 phosphor::logging::entry("INTF=%s", intf.c_str()));
122 return -1;
123 }
124
Jason M. Bills64796042018-10-03 16:51:55 -0700125 for (const auto& item : valueTree)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800126 {
127 auto interface = item.second.find("xyz.openbmc_project.FruDevice");
128 if (interface == item.second.end())
129 {
130 continue;
131 }
132
133 auto property = interface->second.find("CHASSIS_SERIAL_NUMBER");
134 if (property == interface->second.end())
135 {
136 continue;
137 }
138
139 try
140 {
141 Value variant = property->second;
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700142 std::string& result = std::get<std::string>(variant);
Jason M. Bills64796042018-10-03 16:51:55 -0700143 if (result.size() > maxFRUStringLength)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800144 {
145 phosphor::logging::log<phosphor::logging::level::ERR>(
146 "FRU serial number exceed maximum length");
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800147 return -1;
148 }
Jason M. Bills64796042018-10-03 16:51:55 -0700149 serial = result;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800150 return 0;
151 }
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700152 catch (std::bad_variant_access& e)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800153 {
Jason M. Bills64796042018-10-03 16:51:55 -0700154 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800155 return -1;
156 }
157 }
158 return -1;
159}
Jason M. Bills64796042018-10-03 16:51:55 -0700160
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800161ipmi_ret_t ipmiOEMWildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
162 ipmi_request_t request, ipmi_response_t response,
Jason M. Bills64796042018-10-03 16:51:55 -0700163 ipmi_data_len_t dataLen, ipmi_context_t context)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800164{
Jason M. Bills64796042018-10-03 16:51:55 -0700165 printCommand(+netfn, +cmd);
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800166 // Status code.
167 ipmi_ret_t rc = IPMI_CC_INVALID;
Jason M. Bills64796042018-10-03 16:51:55 -0700168 *dataLen = 0;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800169 return rc;
170}
171
172// Returns the Chassis Identifier (serial #)
173ipmi_ret_t ipmiOEMGetChassisIdentifier(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
174 ipmi_request_t request,
175 ipmi_response_t response,
Jason M. Bills64796042018-10-03 16:51:55 -0700176 ipmi_data_len_t dataLen,
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800177 ipmi_context_t context)
178{
179 std::string serial;
Jason M. Bills64796042018-10-03 16:51:55 -0700180 if (*dataLen != 0) // invalid request if there are extra parameters
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800181 {
Jason M. Bills64796042018-10-03 16:51:55 -0700182 *dataLen = 0;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800183 return IPMI_CC_REQ_DATA_LEN_INVALID;
184 }
Vernon Mauery15419dd2019-05-24 09:40:30 -0700185 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
186 if (getChassisSerialNumber(*dbus, serial) == 0)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800187 {
Jason M. Bills64796042018-10-03 16:51:55 -0700188 *dataLen = serial.size(); // length will never exceed response length
189 // as it is checked in getChassisSerialNumber
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800190 char* resp = static_cast<char*>(response);
Jason M. Bills64796042018-10-03 16:51:55 -0700191 serial.copy(resp, *dataLen);
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800192 return IPMI_CC_OK;
193 }
Jason M. Bills64796042018-10-03 16:51:55 -0700194 *dataLen = 0;
195 return IPMI_CC_RESPONSE_ERROR;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800196}
197
198ipmi_ret_t ipmiOEMSetSystemGUID(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
199 ipmi_request_t request,
200 ipmi_response_t response,
Jason M. Bills64796042018-10-03 16:51:55 -0700201 ipmi_data_len_t dataLen, ipmi_context_t context)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800202{
203 static constexpr size_t safeBufferLength = 50;
204 char buf[safeBufferLength] = {0};
205 GUIDData* Data = reinterpret_cast<GUIDData*>(request);
206
Jason M. Bills64796042018-10-03 16:51:55 -0700207 if (*dataLen != sizeof(GUIDData)) // 16bytes
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800208 {
Jason M. Bills64796042018-10-03 16:51:55 -0700209 *dataLen = 0;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800210 return IPMI_CC_REQ_DATA_LEN_INVALID;
211 }
212
Jason M. Bills64796042018-10-03 16:51:55 -0700213 *dataLen = 0;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800214
215 snprintf(
216 buf, safeBufferLength,
217 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
218 Data->timeLow4, Data->timeLow3, Data->timeLow2, Data->timeLow1,
219 Data->timeMid2, Data->timeMid1, Data->timeHigh2, Data->timeHigh1,
220 Data->clock2, Data->clock1, Data->node6, Data->node5, Data->node4,
221 Data->node3, Data->node2, Data->node1);
222 // UUID is in RFC4122 format. Ex: 61a39523-78f2-11e5-9862-e6402cfc3223
223 std::string guid = buf;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800224
225 std::string objpath = "/xyz/openbmc_project/control/host0/systemGUID";
226 std::string intf = "xyz.openbmc_project.Common.UUID";
Vernon Mauery15419dd2019-05-24 09:40:30 -0700227 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
228 std::string service = getService(*dbus, intf, objpath);
229 setDbusProperty(*dbus, service, objpath, intf, "UUID", guid);
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800230 return IPMI_CC_OK;
231}
232
Jason M. Billsb02bf092019-08-15 13:01:56 -0700233ipmi::RspType<> ipmiOEMDisableBMCSystemReset(bool disableResetOnSMI,
234 uint7_t reserved1)
235{
236 std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
237
238 try
239 {
240 auto service =
241 ipmi::getService(*busp, bmcResetDisablesIntf, bmcResetDisablesPath);
242 ipmi::setDbusProperty(*busp, service, bmcResetDisablesPath,
243 bmcResetDisablesIntf, "ResetOnSMI",
244 !disableResetOnSMI);
245 }
246 catch (std::exception& e)
247 {
248 phosphor::logging::log<phosphor::logging::level::ERR>(
249 "Failed to set BMC reset disables",
250 phosphor::logging::entry("EXCEPTION=%s", e.what()));
251 return ipmi::responseUnspecifiedError();
252 }
253
254 return ipmi::responseSuccess();
255}
256
257ipmi::RspType<bool, // disableResetOnSMI
258 uint7_t // reserved
259 >
260 ipmiOEMGetBMCResetDisables()
261{
262 bool disableResetOnSMI = true;
263
264 std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
265 try
266 {
267 auto service =
268 ipmi::getService(*busp, bmcResetDisablesIntf, bmcResetDisablesPath);
269 Value variant =
270 ipmi::getDbusProperty(*busp, service, bmcResetDisablesPath,
271 bmcResetDisablesIntf, "ResetOnSMI");
272 disableResetOnSMI = !std::get<bool>(variant);
273 }
274 catch (std::exception& e)
275 {
276 phosphor::logging::log<phosphor::logging::level::ERR>(
277 "Failed to get BMC reset disables",
278 phosphor::logging::entry("EXCEPTION=%s", e.what()));
279 return ipmi::responseUnspecifiedError();
280 }
281
282 return ipmi::responseSuccess(disableResetOnSMI, 0);
283}
284
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800285ipmi_ret_t ipmiOEMSetBIOSID(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
286 ipmi_request_t request, ipmi_response_t response,
287 ipmi_data_len_t dataLen, ipmi_context_t context)
288{
289 DeviceInfo* data = reinterpret_cast<DeviceInfo*>(request);
290
Jason M. Bills64796042018-10-03 16:51:55 -0700291 if ((*dataLen < 2) || (*dataLen != (1 + data->biosIDLength)))
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800292 {
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800293 *dataLen = 0;
294 return IPMI_CC_REQ_DATA_LEN_INVALID;
295 }
Jason M. Bills64796042018-10-03 16:51:55 -0700296 std::string idString((char*)data->biosId, data->biosIDLength);
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800297
Vernon Mauery15419dd2019-05-24 09:40:30 -0700298 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Yong Li2742b852019-12-16 14:55:11 +0800299 std::string service = getService(*dbus, biosVersionIntf, biosObjPath);
300 setDbusProperty(*dbus, service, biosObjPath, biosVersionIntf,
301 biosVersionProp, idString);
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800302 uint8_t* bytesWritten = static_cast<uint8_t*>(response);
303 *bytesWritten =
Jason M. Bills64796042018-10-03 16:51:55 -0700304 data->biosIDLength; // how many bytes are written into storage
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800305 *dataLen = 1;
306 return IPMI_CC_OK;
307}
308
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800309bool getSwVerInfo(uint8_t& bmcMajor, uint8_t& bmcMinor, uint8_t& meMajor,
310 uint8_t& meMinor)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800311{
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800312 // step 1 : get BMC Major and Minor numbers from its DBUS property
313 std::optional<MetaRevision> rev{};
314 try
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800315 {
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800316 std::string version = getActiveSoftwareVersionInfo();
317 rev = convertIntelVersion(version);
318 }
319 catch (const std::exception& e)
320 {
321 return false;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800322 }
323
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800324 if (rev.has_value())
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800325 {
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800326 MetaRevision revision = rev.value();
327 bmcMajor = revision.major;
328
329 revision.minor = (revision.minor > 99 ? 99 : revision.minor);
330 bmcMinor = revision.minor % 10 + (revision.minor / 10) * 16;
331 }
332
333 // step 2 : get ME Major and Minor numbers from its DBUS property
334 try
335 {
336 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
337 std::string service =
338 getService(*dbus, "xyz.openbmc_project.Software.Version",
339 "/xyz/openbmc_project/me_version");
340 Value variant =
341 getDbusProperty(*dbus, service, "/xyz/openbmc_project/me_version",
342 "xyz.openbmc_project.Software.Version", "Version");
343
344 std::string& meString = std::get<std::string>(variant);
345
346 // get ME major number
347 std::regex pattern1("(\\d+?).(\\d+?).(\\d+?).(\\d+?).(\\d+?)");
348 constexpr size_t matchedPhosphor = 6;
349 std::smatch results;
350 if (std::regex_match(meString, results, pattern1))
351 {
352 if (results.size() == matchedPhosphor)
353 {
354 meMajor = static_cast<uint8_t>(std::stoi(results[1]));
355 meMinor = static_cast<uint8_t>(std::stoi(results[2]));
356 }
357 }
358 }
359 catch (sdbusplus::exception::SdBusError& e)
360 {
361 return false;
362 }
363 return true;
364}
365
366ipmi::RspType<
367 std::variant<std::string,
368 std::tuple<uint8_t, std::array<uint8_t, 2>,
369 std::array<uint8_t, 2>, std::array<uint8_t, 2>,
370 std::array<uint8_t, 2>, std::array<uint8_t, 2>>,
371 std::tuple<uint8_t, std::array<uint8_t, 2>>>>
372 ipmiOEMGetDeviceInfo(uint8_t entityType, uint8_t countToRead,
373 uint8_t offset)
374{
375 if (countToRead == 0)
376 {
377 return ipmi::responseReqDataLenInvalid();
378 }
379
380 if (entityType > static_cast<uint8_t>(OEMDevEntityType::sdrVer))
381 {
382 return ipmi::responseInvalidFieldRequest();
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800383 }
384
385 // handle OEM command items
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800386 switch (OEMDevEntityType(entityType))
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800387 {
388 case OEMDevEntityType::biosId:
389 {
Vernon Mauery15419dd2019-05-24 09:40:30 -0700390 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Yong Li2742b852019-12-16 14:55:11 +0800391 std::string service =
392 getService(*dbus, biosVersionIntf, biosObjPath);
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800393 try
394 {
Yong Li2742b852019-12-16 14:55:11 +0800395 Value variant =
396 getDbusProperty(*dbus, service, biosObjPath,
397 biosVersionIntf, biosVersionProp);
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700398 std::string& idString = std::get<std::string>(variant);
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800399 if (offset >= idString.size())
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800400 {
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800401 return ipmi::responseParmOutOfRange();
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800402 }
Jason M. Bills64796042018-10-03 16:51:55 -0700403 size_t length = 0;
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800404 if (countToRead > (idString.size() - offset))
Jason M. Bills64796042018-10-03 16:51:55 -0700405 {
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800406 length = idString.size() - offset;
Jason M. Bills64796042018-10-03 16:51:55 -0700407 }
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800408 else
409 {
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800410 length = countToRead;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800411 }
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800412
413 std::string readBuf = {0};
414 readBuf.resize(length);
415 std::copy_n(idString.begin() + offset, length,
416 (readBuf.begin()));
417 return ipmi::responseSuccess(readBuf);
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800418 }
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700419 catch (std::bad_variant_access& e)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800420 {
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800421 return ipmi::responseUnspecifiedError();
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800422 }
423 }
424 break;
425
426 case OEMDevEntityType::devVer:
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800427 {
428 constexpr const size_t verLen = 2;
429 constexpr const size_t verTotalLen = 10;
430 std::array<uint8_t, verLen> bmcBuf = {0xff, 0xff};
431 std::array<uint8_t, verLen> hsc0Buf = {0xff, 0xff};
432 std::array<uint8_t, verLen> hsc1Buf = {0xff, 0xff};
433 std::array<uint8_t, verLen> meBuf = {0xff, 0xff};
434 std::array<uint8_t, verLen> hsc2Buf = {0xff, 0xff};
435 // data0/1: BMC version number; data6/7: ME version number
436 // the others: HSC0/1/2 version number, not avaible.
437 if (true != getSwVerInfo(bmcBuf[0], bmcBuf[1], meBuf[0], meBuf[1]))
438 {
439 return ipmi::responseUnspecifiedError();
440 }
441 return ipmi::responseSuccess(
442 std::tuple<
443 uint8_t, std::array<uint8_t, verLen>,
444 std::array<uint8_t, verLen>, std::array<uint8_t, verLen>,
445 std::array<uint8_t, verLen>, std::array<uint8_t, verLen>>{
446 verTotalLen, bmcBuf, hsc0Buf, hsc1Buf, meBuf, hsc2Buf});
447 }
448 break;
449
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800450 case OEMDevEntityType::sdrVer:
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800451 {
452 constexpr const size_t sdrLen = 2;
453 std::array<uint8_t, sdrLen> readBuf = {0x01, 0x0};
454 return ipmi::responseSuccess(
455 std::tuple<uint8_t, std::array<uint8_t, sdrLen>>{sdrLen,
456 readBuf});
457 }
458 break;
459
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800460 default:
Chen Yugang7a04f3a2019-10-08 11:12:35 +0800461 return ipmi::responseInvalidFieldRequest();
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800462 }
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800463}
464
465ipmi_ret_t ipmiOEMGetAICFRU(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
466 ipmi_request_t request, ipmi_response_t response,
467 ipmi_data_len_t dataLen, ipmi_context_t context)
468{
469 if (*dataLen != 0)
470 {
Jason M. Bills64796042018-10-03 16:51:55 -0700471 *dataLen = 0;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800472 return IPMI_CC_REQ_DATA_LEN_INVALID;
473 }
474
475 *dataLen = 1;
476 uint8_t* res = reinterpret_cast<uint8_t*>(response);
477 // temporary fix. We don't support AIC FRU now. Just tell BIOS that no
478 // AIC is available so that BIOS will not timeout repeatly which leads to
479 // slow booting.
480 *res = 0; // Byte1=Count of SlotPosition/FruID records.
481 return IPMI_CC_OK;
482}
483
Jason M. Bills64796042018-10-03 16:51:55 -0700484ipmi_ret_t ipmiOEMGetPowerRestoreDelay(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
485 ipmi_request_t request,
486 ipmi_response_t response,
487 ipmi_data_len_t dataLen,
488 ipmi_context_t context)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800489{
Jason M. Bills64796042018-10-03 16:51:55 -0700490 GetPowerRestoreDelayRes* resp =
491 reinterpret_cast<GetPowerRestoreDelayRes*>(response);
492
493 if (*dataLen != 0)
494 {
495 *dataLen = 0;
496 return IPMI_CC_REQ_DATA_LEN_INVALID;
497 }
498
Vernon Mauery15419dd2019-05-24 09:40:30 -0700499 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Jason M. Bills64796042018-10-03 16:51:55 -0700500 std::string service =
Vernon Mauery15419dd2019-05-24 09:40:30 -0700501 getService(*dbus, powerRestoreDelayIntf, powerRestoreDelayObjPath);
Jason M. Bills64796042018-10-03 16:51:55 -0700502 Value variant =
Vernon Mauery15419dd2019-05-24 09:40:30 -0700503 getDbusProperty(*dbus, service, powerRestoreDelayObjPath,
Jason M. Bills64796042018-10-03 16:51:55 -0700504 powerRestoreDelayIntf, powerRestoreDelayProp);
505
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700506 uint16_t delay = std::get<uint16_t>(variant);
Jason M. Bills64796042018-10-03 16:51:55 -0700507 resp->byteLSB = delay;
508 resp->byteMSB = delay >> 8;
509
510 *dataLen = sizeof(GetPowerRestoreDelayRes);
511
512 return IPMI_CC_OK;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800513}
514
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800515static uint8_t bcdToDec(uint8_t val)
516{
517 return ((val / 16 * 10) + (val % 16));
518}
519
520// Allows an update utility or system BIOS to send the status of an embedded
521// firmware update attempt to the BMC. After received, BMC will create a logging
522// record.
523ipmi::RspType<> ipmiOEMSendEmbeddedFwUpdStatus(uint8_t status, uint8_t target,
524 uint8_t majorRevision,
525 uint8_t minorRevision,
526 uint32_t auxInfo)
527{
528 std::string firmware;
Jason M. Billsdc249272019-04-03 09:58:40 -0700529 int instance = (target & targetInstanceMask) >> targetInstanceShift;
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800530 target = (target & selEvtTargetMask) >> selEvtTargetShift;
531
532 /* make sure the status is 0, 1, or 2 as per the spec */
533 if (status > 2)
534 {
535 return ipmi::response(ipmi::ccInvalidFieldRequest);
536 }
Jason M. Billsdc249272019-04-03 09:58:40 -0700537 /* make sure the target is 0, 1, 2, or 4 as per the spec */
538 if (target > 4 || target == 3)
539 {
540 return ipmi::response(ipmi::ccInvalidFieldRequest);
541 }
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800542 /*orignal OEM command is to record OEM SEL.
543 But openbmc does not support OEM SEL, so we redirect it to redfish event
544 logging. */
545 std::string buildInfo;
546 std::string action;
547 switch (FWUpdateTarget(target))
548 {
549 case FWUpdateTarget::targetBMC:
550 firmware = "BMC";
Jason M. Billsdc249272019-04-03 09:58:40 -0700551 buildInfo = "major: " + std::to_string(majorRevision) + " minor: " +
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800552 std::to_string(bcdToDec(minorRevision)) + // BCD encoded
553 " BuildID: " + std::to_string(auxInfo);
554 buildInfo += std::to_string(auxInfo);
555 break;
556 case FWUpdateTarget::targetBIOS:
557 firmware = "BIOS";
558 buildInfo =
Jason M. Billsdc249272019-04-03 09:58:40 -0700559 "major: " +
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800560 std::to_string(bcdToDec(majorRevision)) + // BCD encoded
561 " minor: " +
562 std::to_string(bcdToDec(minorRevision)) + // BCD encoded
563 " ReleaseNumber: " + // ASCII encoded
564 std::to_string(static_cast<uint8_t>(auxInfo >> 0) - '0') +
565 std::to_string(static_cast<uint8_t>(auxInfo >> 8) - '0') +
566 std::to_string(static_cast<uint8_t>(auxInfo >> 16) - '0') +
567 std::to_string(static_cast<uint8_t>(auxInfo >> 24) - '0');
568 break;
569 case FWUpdateTarget::targetME:
570 firmware = "ME";
571 buildInfo =
Jason M. Billsdc249272019-04-03 09:58:40 -0700572 "major: " + std::to_string(majorRevision) + " minor1: " +
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800573 std::to_string(bcdToDec(minorRevision)) + // BCD encoded
574 " minor2: " +
575 std::to_string(bcdToDec(static_cast<uint8_t>(auxInfo >> 0))) +
576 " build1: " +
577 std::to_string(bcdToDec(static_cast<uint8_t>(auxInfo >> 8))) +
578 " build2: " +
579 std::to_string(bcdToDec(static_cast<uint8_t>(auxInfo >> 16)));
580 break;
581 case FWUpdateTarget::targetOEMEWS:
582 firmware = "EWS";
Jason M. Billsdc249272019-04-03 09:58:40 -0700583 buildInfo = "major: " + std::to_string(majorRevision) + " minor: " +
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800584 std::to_string(bcdToDec(minorRevision)) + // BCD encoded
585 " BuildID: " + std::to_string(auxInfo);
586 break;
587 }
588
Jason M. Billsdc249272019-04-03 09:58:40 -0700589 static const std::string openBMCMessageRegistryVersion("0.1");
590 std::string redfishMsgID = "OpenBMC." + openBMCMessageRegistryVersion;
591
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800592 switch (status)
593 {
594 case 0x0:
595 action = "update started";
Jason M. Billsdc249272019-04-03 09:58:40 -0700596 redfishMsgID += ".FirmwareUpdateStarted";
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800597 break;
598 case 0x1:
599 action = "update completed successfully";
Jason M. Billsdc249272019-04-03 09:58:40 -0700600 redfishMsgID += ".FirmwareUpdateCompleted";
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800601 break;
602 case 0x2:
603 action = "update failure";
Jason M. Billsdc249272019-04-03 09:58:40 -0700604 redfishMsgID += ".FirmwareUpdateFailed";
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800605 break;
606 default:
607 action = "unknown";
608 break;
609 }
610
Jason M. Billsdc249272019-04-03 09:58:40 -0700611 std::string firmwareInstanceStr =
612 firmware + " instance: " + std::to_string(instance);
613 std::string message("[firmware update] " + firmwareInstanceStr +
614 " status: <" + action + "> " + buildInfo);
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800615
616 sd_journal_send("MESSAGE=%s", message.c_str(), "PRIORITY=%i", LOG_INFO,
Jason M. Billsdc249272019-04-03 09:58:40 -0700617 "REDFISH_MESSAGE_ID=%s", redfishMsgID.c_str(),
618 "REDFISH_MESSAGE_ARGS=%s,%s", firmwareInstanceStr.c_str(),
619 buildInfo.c_str(), NULL);
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800620 return ipmi::responseSuccess();
621}
622
Jason M. Bills64796042018-10-03 16:51:55 -0700623ipmi_ret_t ipmiOEMSetPowerRestoreDelay(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
624 ipmi_request_t request,
625 ipmi_response_t response,
626 ipmi_data_len_t dataLen,
627 ipmi_context_t context)
628{
629 SetPowerRestoreDelayReq* data =
630 reinterpret_cast<SetPowerRestoreDelayReq*>(request);
631 uint16_t delay = 0;
632
633 if (*dataLen != sizeof(SetPowerRestoreDelayReq))
634 {
635 *dataLen = 0;
636 return IPMI_CC_REQ_DATA_LEN_INVALID;
637 }
638 delay = data->byteMSB;
639 delay = (delay << 8) | data->byteLSB;
Vernon Mauery15419dd2019-05-24 09:40:30 -0700640 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Jason M. Bills64796042018-10-03 16:51:55 -0700641 std::string service =
Vernon Mauery15419dd2019-05-24 09:40:30 -0700642 getService(*dbus, powerRestoreDelayIntf, powerRestoreDelayObjPath);
643 setDbusProperty(*dbus, service, powerRestoreDelayObjPath,
Jason M. Bills64796042018-10-03 16:51:55 -0700644 powerRestoreDelayIntf, powerRestoreDelayProp, delay);
645 *dataLen = 0;
646
647 return IPMI_CC_OK;
648}
649
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700650static bool cpuPresent(const std::string& cpuName)
Jason M. Bills64796042018-10-03 16:51:55 -0700651{
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700652 static constexpr const char* cpuPresencePathPrefix =
653 "/xyz/openbmc_project/inventory/system/chassis/motherboard/";
654 static constexpr const char* cpuPresenceIntf =
655 "xyz.openbmc_project.Inventory.Item";
656 std::string cpuPresencePath = cpuPresencePathPrefix + cpuName;
657 std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
658 try
Jason M. Bills64796042018-10-03 16:51:55 -0700659 {
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700660 auto service =
661 ipmi::getService(*busp, cpuPresenceIntf, cpuPresencePath);
662
663 ipmi::Value result = ipmi::getDbusProperty(
664 *busp, service, cpuPresencePath, cpuPresenceIntf, "Present");
665 return std::get<bool>(result);
666 }
667 catch (const std::exception& e)
668 {
669 phosphor::logging::log<phosphor::logging::level::INFO>(
670 "Cannot find processor presence",
671 phosphor::logging::entry("NAME=%s", cpuName.c_str()));
672 return false;
673 }
674}
675
676ipmi::RspType<bool, // CATERR Reset Enabled
677 bool, // ERR2 Reset Enabled
678 uint6_t, // reserved
679 uint8_t, // reserved, returns 0x3F
680 uint6_t, // CPU1 CATERR Count
681 uint2_t, // CPU1 Status
682 uint6_t, // CPU2 CATERR Count
683 uint2_t, // CPU2 Status
684 uint6_t, // CPU3 CATERR Count
685 uint2_t, // CPU3 Status
686 uint6_t, // CPU4 CATERR Count
687 uint2_t, // CPU4 Status
688 uint8_t // Crashdump Count
689 >
690 ipmiOEMGetProcessorErrConfig()
691{
692 bool resetOnCATERR = false;
693 bool resetOnERR2 = false;
694 uint6_t cpu1CATERRCount = 0;
695 uint6_t cpu2CATERRCount = 0;
696 uint6_t cpu3CATERRCount = 0;
697 uint6_t cpu4CATERRCount = 0;
698 uint8_t crashdumpCount = 0;
699 uint2_t cpu1Status =
700 cpuPresent("CPU_1") ? CPUStatus::enabled : CPUStatus::notPresent;
701 uint2_t cpu2Status =
702 cpuPresent("CPU_2") ? CPUStatus::enabled : CPUStatus::notPresent;
703 uint2_t cpu3Status =
704 cpuPresent("CPU_3") ? CPUStatus::enabled : CPUStatus::notPresent;
705 uint2_t cpu4Status =
706 cpuPresent("CPU_4") ? CPUStatus::enabled : CPUStatus::notPresent;
707
708 std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
709 try
710 {
711 auto service = ipmi::getService(*busp, processorErrConfigIntf,
712 processorErrConfigObjPath);
713
714 ipmi::PropertyMap result = ipmi::getAllDbusProperties(
715 *busp, service, processorErrConfigObjPath, processorErrConfigIntf);
716 resetOnCATERR = std::get<bool>(result.at("ResetOnCATERR"));
717 resetOnERR2 = std::get<bool>(result.at("ResetOnERR2"));
718 cpu1CATERRCount = std::get<uint8_t>(result.at("ErrorCountCPU1"));
719 cpu2CATERRCount = std::get<uint8_t>(result.at("ErrorCountCPU2"));
720 cpu3CATERRCount = std::get<uint8_t>(result.at("ErrorCountCPU3"));
721 cpu4CATERRCount = std::get<uint8_t>(result.at("ErrorCountCPU4"));
722 crashdumpCount = std::get<uint8_t>(result.at("CrashdumpCount"));
723 }
724 catch (const std::exception& e)
725 {
726 phosphor::logging::log<phosphor::logging::level::ERR>(
727 "Failed to fetch processor error config",
728 phosphor::logging::entry("ERROR=%s", e.what()));
729 return ipmi::responseUnspecifiedError();
Jason M. Bills64796042018-10-03 16:51:55 -0700730 }
731
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700732 return ipmi::responseSuccess(resetOnCATERR, resetOnERR2, 0, 0x3F,
733 cpu1CATERRCount, cpu1Status, cpu2CATERRCount,
734 cpu2Status, cpu3CATERRCount, cpu3Status,
735 cpu4CATERRCount, cpu4Status, crashdumpCount);
736}
Jason M. Bills64796042018-10-03 16:51:55 -0700737
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700738ipmi::RspType<> ipmiOEMSetProcessorErrConfig(
739 bool resetOnCATERR, bool resetOnERR2, uint6_t reserved1, uint8_t reserved2,
740 std::optional<bool> clearCPUErrorCount,
741 std::optional<bool> clearCrashdumpCount, std::optional<uint6_t> reserved3)
742{
743 std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
Jason M. Bills64796042018-10-03 16:51:55 -0700744
745 try
746 {
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700747 auto service = ipmi::getService(*busp, processorErrConfigIntf,
748 processorErrConfigObjPath);
749 ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath,
750 processorErrConfigIntf, "ResetOnCATERR",
751 resetOnCATERR);
752 ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath,
753 processorErrConfigIntf, "ResetOnERR2",
754 resetOnERR2);
755 if (clearCPUErrorCount.value_or(false))
756 {
757 ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath,
Jason M. Billsd3e19932019-08-15 12:39:03 -0700758 processorErrConfigIntf, "ErrorCountCPU1",
759 static_cast<uint8_t>(0));
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700760 ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath,
Jason M. Billsd3e19932019-08-15 12:39:03 -0700761 processorErrConfigIntf, "ErrorCountCPU2",
762 static_cast<uint8_t>(0));
763 ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath,
764 processorErrConfigIntf, "ErrorCountCPU3",
765 static_cast<uint8_t>(0));
766 ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath,
767 processorErrConfigIntf, "ErrorCountCPU4",
768 static_cast<uint8_t>(0));
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700769 }
770 if (clearCrashdumpCount.value_or(false))
771 {
772 ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath,
Jason M. Billsd3e19932019-08-15 12:39:03 -0700773 processorErrConfigIntf, "CrashdumpCount",
774 static_cast<uint8_t>(0));
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700775 }
Jason M. Bills64796042018-10-03 16:51:55 -0700776 }
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700777 catch (std::exception& e)
Jason M. Bills64796042018-10-03 16:51:55 -0700778 {
Kuiying Wangbc546672018-11-23 15:41:05 +0800779 phosphor::logging::log<phosphor::logging::level::ERR>(
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700780 "Failed to set processor error config",
781 phosphor::logging::entry("EXCEPTION=%s", e.what()));
782 return ipmi::responseUnspecifiedError();
Jason M. Bills64796042018-10-03 16:51:55 -0700783 }
784
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700785 return ipmi::responseSuccess();
Jason M. Bills64796042018-10-03 16:51:55 -0700786}
787
Yong Li703922d2018-11-06 13:25:31 +0800788ipmi_ret_t ipmiOEMGetShutdownPolicy(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
789 ipmi_request_t request,
790 ipmi_response_t response,
791 ipmi_data_len_t dataLen,
792 ipmi_context_t context)
793{
794 GetOEMShutdownPolicyRes* resp =
795 reinterpret_cast<GetOEMShutdownPolicyRes*>(response);
796
797 if (*dataLen != 0)
798 {
799 phosphor::logging::log<phosphor::logging::level::ERR>(
Kuiying Wang45f04982018-12-26 09:23:08 +0800800 "oem_get_shutdown_policy: invalid input len!");
Yong Li703922d2018-11-06 13:25:31 +0800801 *dataLen = 0;
802 return IPMI_CC_REQ_DATA_LEN_INVALID;
803 }
804
805 *dataLen = 0;
806
807 try
808 {
Vernon Mauery15419dd2019-05-24 09:40:30 -0700809 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Yong Li703922d2018-11-06 13:25:31 +0800810 std::string service =
Vernon Mauery15419dd2019-05-24 09:40:30 -0700811 getService(*dbus, oemShutdownPolicyIntf, oemShutdownPolicyObjPath);
812 Value variant = getDbusProperty(
813 *dbus, service, oemShutdownPolicyObjPath, oemShutdownPolicyIntf,
814 oemShutdownPolicyObjPathProp);
Yong Li0669d192019-05-06 14:01:46 +0800815
816 if (sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::
817 convertPolicyFromString(std::get<std::string>(variant)) ==
818 sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::Policy::
819 NoShutdownOnOCOT)
820 {
821 resp->policy = 0;
822 }
823 else if (sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::
824 convertPolicyFromString(std::get<std::string>(variant)) ==
825 sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::
826 Policy::ShutdownOnOCOT)
827 {
828 resp->policy = 1;
829 }
830 else
831 {
832 phosphor::logging::log<phosphor::logging::level::ERR>(
833 "oem_set_shutdown_policy: invalid property!",
834 phosphor::logging::entry(
835 "PROP=%s", std::get<std::string>(variant).c_str()));
836 return IPMI_CC_UNSPECIFIED_ERROR;
837 }
Yong Li703922d2018-11-06 13:25:31 +0800838 // TODO needs to check if it is multi-node products,
839 // policy is only supported on node 3/4
840 resp->policySupport = shutdownPolicySupported;
841 }
842 catch (sdbusplus::exception_t& e)
843 {
844 phosphor::logging::log<phosphor::logging::level::ERR>(e.description());
845 return IPMI_CC_UNSPECIFIED_ERROR;
846 }
847
848 *dataLen = sizeof(GetOEMShutdownPolicyRes);
849 return IPMI_CC_OK;
850}
851
852ipmi_ret_t ipmiOEMSetShutdownPolicy(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 uint8_t* req = reinterpret_cast<uint8_t*>(request);
Yong Li0669d192019-05-06 14:01:46 +0800859 sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::Policy policy =
860 sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::Policy::
861 NoShutdownOnOCOT;
Yong Li703922d2018-11-06 13:25:31 +0800862
863 // TODO needs to check if it is multi-node products,
864 // policy is only supported on node 3/4
865 if (*dataLen != 1)
866 {
867 phosphor::logging::log<phosphor::logging::level::ERR>(
868 "oem_set_shutdown_policy: invalid input len!");
869 *dataLen = 0;
870 return IPMI_CC_REQ_DATA_LEN_INVALID;
871 }
872
873 *dataLen = 0;
874 if ((*req != noShutdownOnOCOT) && (*req != shutdownOnOCOT))
875 {
876 phosphor::logging::log<phosphor::logging::level::ERR>(
877 "oem_set_shutdown_policy: invalid input!");
878 return IPMI_CC_INVALID_FIELD_REQUEST;
879 }
880
Yong Li0669d192019-05-06 14:01:46 +0800881 if (*req == noShutdownOnOCOT)
882 {
883 policy = sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::
884 Policy::NoShutdownOnOCOT;
885 }
886 else
887 {
888 policy = sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::
889 Policy::ShutdownOnOCOT;
890 }
891
Yong Li703922d2018-11-06 13:25:31 +0800892 try
893 {
Vernon Mauery15419dd2019-05-24 09:40:30 -0700894 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Yong Li703922d2018-11-06 13:25:31 +0800895 std::string service =
Vernon Mauery15419dd2019-05-24 09:40:30 -0700896 getService(*dbus, oemShutdownPolicyIntf, oemShutdownPolicyObjPath);
Yong Li0669d192019-05-06 14:01:46 +0800897 setDbusProperty(
Vernon Mauery15419dd2019-05-24 09:40:30 -0700898 *dbus, service, oemShutdownPolicyObjPath, oemShutdownPolicyIntf,
Yong Li0669d192019-05-06 14:01:46 +0800899 oemShutdownPolicyObjPathProp,
900 sdbusplus::com::intel::Control::server::convertForMessage(policy));
Yong Li703922d2018-11-06 13:25:31 +0800901 }
902 catch (sdbusplus::exception_t& e)
903 {
904 phosphor::logging::log<phosphor::logging::level::ERR>(e.description());
905 return IPMI_CC_UNSPECIFIED_ERROR;
906 }
907
908 return IPMI_CC_OK;
909}
910
Suryakanth Sekard509eb92018-11-15 17:44:11 +0530911/** @brief implementation for check the DHCP or not in IPv4
912 * @param[in] Channel - Channel number
913 * @returns true or false.
914 */
915static bool isDHCPEnabled(uint8_t Channel)
916{
917 try
918 {
919 auto ethdevice = getChannelName(Channel);
920 if (ethdevice.empty())
921 {
922 return false;
923 }
924 auto ethIP = ethdevice + "/ipv4";
Vernon Mauery15419dd2019-05-24 09:40:30 -0700925 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Suryakanth Sekard509eb92018-11-15 17:44:11 +0530926 auto ethernetObj =
Vernon Mauery15419dd2019-05-24 09:40:30 -0700927 getDbusObject(*dbus, networkIPIntf, networkRoot, ethIP);
928 auto value = getDbusProperty(*dbus, networkService, ethernetObj.first,
Suryakanth Sekard509eb92018-11-15 17:44:11 +0530929 networkIPIntf, "Origin");
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700930 if (std::get<std::string>(value) ==
Suryakanth Sekard509eb92018-11-15 17:44:11 +0530931 "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP")
932 {
933 return true;
934 }
935 else
936 {
937 return false;
938 }
939 }
940 catch (sdbusplus::exception_t& e)
941 {
942 phosphor::logging::log<phosphor::logging::level::ERR>(e.description());
943 return true;
944 }
945}
946
947/** @brief implementes for check the DHCP or not in IPv6
948 * @param[in] Channel - Channel number
949 * @returns true or false.
950 */
951static bool isDHCPIPv6Enabled(uint8_t Channel)
952{
953
954 try
955 {
956 auto ethdevice = getChannelName(Channel);
957 if (ethdevice.empty())
958 {
959 return false;
960 }
961 auto ethIP = ethdevice + "/ipv6";
Vernon Mauery15419dd2019-05-24 09:40:30 -0700962 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Suryakanth Sekard509eb92018-11-15 17:44:11 +0530963 auto objectInfo =
Vernon Mauery15419dd2019-05-24 09:40:30 -0700964 getDbusObject(*dbus, networkIPIntf, networkRoot, ethIP);
965 auto properties = getAllDbusProperties(*dbus, objectInfo.second,
Suryakanth Sekard509eb92018-11-15 17:44:11 +0530966 objectInfo.first, networkIPIntf);
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700967 if (std::get<std::string>(properties["Origin"]) ==
Suryakanth Sekard509eb92018-11-15 17:44:11 +0530968 "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP")
969 {
970 return true;
971 }
972 else
973 {
974 return false;
975 }
976 }
977 catch (sdbusplus::exception_t& e)
978 {
979 phosphor::logging::log<phosphor::logging::level::ERR>(e.description());
980 return true;
981 }
982}
983
984/** @brief implementes the creating of default new user
985 * @param[in] userName - new username in 16 bytes.
986 * @param[in] userPassword - new password in 20 bytes
987 * @returns ipmi completion code.
988 */
989ipmi::RspType<> ipmiOEMSetUser2Activation(
990 std::array<uint8_t, ipmi::ipmiMaxUserName>& userName,
991 std::array<uint8_t, ipmi::maxIpmi20PasswordSize>& userPassword)
992{
993 bool userState = false;
994 // Check for System Interface not exist and LAN should be static
995 for (uint8_t channel = 0; channel < maxIpmiChannels; channel++)
996 {
997 ChannelInfo chInfo;
998 try
999 {
1000 getChannelInfo(channel, chInfo);
1001 }
1002 catch (sdbusplus::exception_t& e)
1003 {
1004 phosphor::logging::log<phosphor::logging::level::ERR>(
1005 "ipmiOEMSetUser2Activation: Failed to get Channel Info",
1006 phosphor::logging::entry("MSG: %s", e.description()));
1007 return ipmi::response(ipmi::ccUnspecifiedError);
1008 }
1009 if (chInfo.mediumType ==
1010 static_cast<uint8_t>(EChannelMediumType::systemInterface))
1011 {
1012 phosphor::logging::log<phosphor::logging::level::ERR>(
1013 "ipmiOEMSetUser2Activation: system interface exist .");
1014 return ipmi::response(ipmi::ccCommandNotAvailable);
1015 }
1016 else
1017 {
1018
1019 if (chInfo.mediumType ==
1020 static_cast<uint8_t>(EChannelMediumType::lan8032))
1021 {
1022 if (isDHCPIPv6Enabled(channel) || isDHCPEnabled(channel))
1023 {
1024 phosphor::logging::log<phosphor::logging::level::ERR>(
1025 "ipmiOEMSetUser2Activation: DHCP enabled .");
1026 return ipmi::response(ipmi::ccCommandNotAvailable);
1027 }
1028 }
1029 }
1030 }
1031 uint8_t maxChUsers = 0, enabledUsers = 0, fixedUsers = 0;
1032 if (ipmi::ccSuccess ==
1033 ipmiUserGetAllCounts(maxChUsers, enabledUsers, fixedUsers))
1034 {
1035 if (enabledUsers > 1)
1036 {
1037 phosphor::logging::log<phosphor::logging::level::ERR>(
1038 "ipmiOEMSetUser2Activation: more than one user is enabled.");
1039 return ipmi::response(ipmi::ccCommandNotAvailable);
1040 }
1041 // Check the user 2 is enabled or not
1042 ipmiUserCheckEnabled(ipmiDefaultUserId, userState);
1043 if (userState == true)
1044 {
1045 phosphor::logging::log<phosphor::logging::level::ERR>(
1046 "ipmiOEMSetUser2Activation: user 2 already enabled .");
1047 return ipmi::response(ipmi::ccCommandNotAvailable);
1048 }
1049 }
1050 else
1051 {
1052 return ipmi::response(ipmi::ccUnspecifiedError);
1053 }
1054
1055#if BYTE_ORDER == LITTLE_ENDIAN
1056 PrivAccess privAccess = {PRIVILEGE_ADMIN, true, true, true, 0};
1057#endif
1058#if BYTE_ORDER == BIG_ENDIAN
1059 PrivAccess privAccess = {0, true, true, true, PRIVILEGE_ADMIN};
1060#endif
1061
1062 if (ipmi::ccSuccess ==
1063 ipmiUserSetUserName(ipmiDefaultUserId,
1064 reinterpret_cast<const char*>(userName.data())))
1065 {
1066 if (ipmi::ccSuccess ==
1067 ipmiUserSetUserPassword(
1068 ipmiDefaultUserId,
1069 reinterpret_cast<const char*>(userPassword.data())))
1070 {
1071 if (ipmi::ccSuccess ==
1072 ipmiUserSetPrivilegeAccess(
1073 ipmiDefaultUserId,
1074 static_cast<uint8_t>(ipmi::EChannelID::chanLan1),
1075 privAccess, true))
1076 {
1077 phosphor::logging::log<phosphor::logging::level::INFO>(
1078 "ipmiOEMSetUser2Activation: user created successfully ");
1079 return ipmi::responseSuccess();
1080 }
1081 }
1082 // we need to delete the default user id which added in this command as
1083 // password / priv setting is failed.
1084 ipmiUserSetUserName(ipmiDefaultUserId, "");
1085 phosphor::logging::log<phosphor::logging::level::ERR>(
1086 "ipmiOEMSetUser2Activation: password / priv setting is failed.");
1087 }
1088 else
1089 {
1090 phosphor::logging::log<phosphor::logging::level::ERR>(
1091 "ipmiOEMSetUser2Activation: Setting username failed.");
1092 }
1093
1094 return ipmi::response(ipmi::ccCommandNotAvailable);
1095}
1096
Suryakanth Sekar822b0b42019-11-15 18:32:53 +05301097/** @brief implementes executing the linux command
1098 * @param[in] linux command
1099 * @returns status
1100 */
1101
1102static uint8_t executeCmd(const char* path)
1103{
1104 boost::process::child execProg(path);
1105 execProg.wait();
1106
1107 int retCode = execProg.exit_code();
1108 if (retCode)
1109 {
1110 return ipmi::ccUnspecifiedError;
1111 }
1112 return ipmi::ccSuccess;
1113}
1114
1115/** @brief implementes ASD Security event logging
1116 * @param[in] Event message string
1117 * @param[in] Event Severity
1118 * @returns status
1119 */
1120
1121static void atScaleDebugEventlog(std::string msg, int severity)
1122{
1123 std::string eventStr = "OpenBMC.0.1." + msg;
1124 sd_journal_send("MESSAGE=Security Event: %s", eventStr.c_str(),
1125 "PRIORITY=%i", severity, "REDFISH_MESSAGE_ID=%s",
1126 eventStr.c_str(), NULL);
1127}
1128
Richard Marian Thomaiyarfc5e9852019-04-14 15:06:27 +05301129/** @brief implementes setting password for special user
1130 * @param[in] specialUserIndex
1131 * @param[in] userPassword - new password in 20 bytes
1132 * @returns ipmi completion code.
1133 */
1134ipmi::RspType<> ipmiOEMSetSpecialUserPassword(ipmi::Context::ptr ctx,
1135 uint8_t specialUserIndex,
1136 std::vector<uint8_t> userPassword)
1137{
1138 ChannelInfo chInfo;
Suryakanth Sekar822b0b42019-11-15 18:32:53 +05301139 ipmi_ret_t status = ipmi::ccSuccess;
1140
Richard Marian Thomaiyarfc5e9852019-04-14 15:06:27 +05301141 try
1142 {
1143 getChannelInfo(ctx->channel, chInfo);
1144 }
1145 catch (sdbusplus::exception_t& e)
1146 {
1147 phosphor::logging::log<phosphor::logging::level::ERR>(
1148 "ipmiOEMSetSpecialUserPassword: Failed to get Channel Info",
1149 phosphor::logging::entry("MSG: %s", e.description()));
1150 return ipmi::responseUnspecifiedError();
1151 }
1152 if (chInfo.mediumType !=
1153 static_cast<uint8_t>(EChannelMediumType::systemInterface))
1154 {
1155 phosphor::logging::log<phosphor::logging::level::ERR>(
1156 "ipmiOEMSetSpecialUserPassword: Error - supported only in KCS "
1157 "interface");
1158 return ipmi::responseCommandNotAvailable();
1159 }
Suryakanth Sekar822b0b42019-11-15 18:32:53 +05301160
1161 // 0 for root user and 1 for AtScaleDebug is allowed
1162 if (specialUserIndex >
1163 static_cast<uint8_t>(SpecialUserIndex::atScaleDebugUser))
Richard Marian Thomaiyarfc5e9852019-04-14 15:06:27 +05301164 {
1165 phosphor::logging::log<phosphor::logging::level::ERR>(
1166 "ipmiOEMSetSpecialUserPassword: Invalid user account");
1167 return ipmi::responseParmOutOfRange();
1168 }
Suryakanth Sekar822b0b42019-11-15 18:32:53 +05301169 if (userPassword.size() != 0)
Richard Marian Thomaiyarfc5e9852019-04-14 15:06:27 +05301170 {
Suryakanth Sekar822b0b42019-11-15 18:32:53 +05301171 constexpr uint8_t minPasswordSizeRequired = 6;
1172 std::string passwd;
1173 if (userPassword.size() < minPasswordSizeRequired ||
1174 userPassword.size() > ipmi::maxIpmi20PasswordSize)
1175 {
1176 return ipmi::responseReqDataLenInvalid();
1177 }
1178 passwd.assign(reinterpret_cast<const char*>(userPassword.data()),
1179 userPassword.size());
1180 if (specialUserIndex ==
1181 static_cast<uint8_t>(SpecialUserIndex::atScaleDebugUser))
1182 {
1183 status = ipmiSetSpecialUserPassword("asdbg", passwd);
1184
1185 atScaleDebugEventlog("AtScaleDebugSpecialUserEnabled", LOG_CRIT);
1186 }
1187 else
1188 {
1189 status = ipmiSetSpecialUserPassword("root", passwd);
1190 }
1191 return ipmi::response(status);
Richard Marian Thomaiyarfc5e9852019-04-14 15:06:27 +05301192 }
Suryakanth Sekar822b0b42019-11-15 18:32:53 +05301193 else
1194 {
1195 if (specialUserIndex ==
1196 static_cast<uint8_t>(SpecialUserIndex::rootUser))
1197 {
1198 status = executeCmd("passwd -d root");
1199 }
1200 else
1201 {
1202
1203 status = executeCmd("passwd -d asdbg");
1204
1205 if (status == 0)
1206 {
1207 atScaleDebugEventlog("AtScaleDebugSpecialUserDisabled",
1208 LOG_INFO);
1209 }
1210 }
1211 return ipmi::response(status);
1212 }
Richard Marian Thomaiyarfc5e9852019-04-14 15:06:27 +05301213}
1214
Kuiying Wang45f04982018-12-26 09:23:08 +08001215namespace ledAction
1216{
1217using namespace sdbusplus::xyz::openbmc_project::Led::server;
1218std::map<Physical::Action, uint8_t> actionDbusToIpmi = {
jayaprakash Mutyala934ee9c2019-12-13 17:49:27 +00001219 {Physical::Action::Off, 0},
1220 {Physical::Action::On, 2},
1221 {Physical::Action::Blink, 1}};
Kuiying Wang45f04982018-12-26 09:23:08 +08001222
1223std::map<uint8_t, std::string> offsetObjPath = {
1224 {2, statusAmberObjPath}, {4, statusGreenObjPath}, {6, identifyLEDObjPath}};
1225
1226} // namespace ledAction
1227
1228int8_t getLEDState(sdbusplus::bus::bus& bus, const std::string& intf,
1229 const std::string& objPath, uint8_t& state)
1230{
1231 try
1232 {
1233 std::string service = getService(bus, intf, objPath);
1234 Value stateValue =
1235 getDbusProperty(bus, service, objPath, intf, "State");
Vernon Mauery8166c8d2019-05-23 11:22:30 -07001236 std::string strState = std::get<std::string>(stateValue);
Kuiying Wang45f04982018-12-26 09:23:08 +08001237 state = ledAction::actionDbusToIpmi.at(
1238 sdbusplus::xyz::openbmc_project::Led::server::Physical::
1239 convertActionFromString(strState));
1240 }
1241 catch (sdbusplus::exception::SdBusError& e)
1242 {
1243 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
1244 return -1;
1245 }
1246 return 0;
1247}
1248
1249ipmi_ret_t ipmiOEMGetLEDStatus(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
1250 ipmi_request_t request, ipmi_response_t response,
1251 ipmi_data_len_t dataLen, ipmi_context_t context)
1252{
1253 uint8_t* resp = reinterpret_cast<uint8_t*>(response);
1254 // LED Status
1255 //[1:0] = Reserved
1256 //[3:2] = Status(Amber)
1257 //[5:4] = Status(Green)
1258 //[7:6] = System Identify
1259 // Status definitions:
1260 // 00b = Off
1261 // 01b = Blink
1262 // 10b = On
1263 // 11b = invalid
1264 if (*dataLen != 0)
1265 {
1266 phosphor::logging::log<phosphor::logging::level::ERR>(
1267 "oem_get_led_status: invalid input len!");
1268 *dataLen = 0;
1269 return IPMI_CC_REQ_DATA_LEN_INVALID;
1270 }
1271
1272 phosphor::logging::log<phosphor::logging::level::DEBUG>("GET led status");
1273 *resp = 0;
1274 *dataLen = 0;
Vernon Mauery15419dd2019-05-24 09:40:30 -07001275 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Kuiying Wang45f04982018-12-26 09:23:08 +08001276 for (auto it = ledAction::offsetObjPath.begin();
1277 it != ledAction::offsetObjPath.end(); ++it)
1278 {
1279 uint8_t state = 0;
Vernon Mauery15419dd2019-05-24 09:40:30 -07001280 if (-1 == getLEDState(*dbus, ledIntf, it->second, state))
Kuiying Wang45f04982018-12-26 09:23:08 +08001281 {
1282 phosphor::logging::log<phosphor::logging::level::ERR>(
1283 "oem_get_led_status: fail to get ID LED status!");
1284 return IPMI_CC_UNSPECIFIED_ERROR;
1285 }
1286 *resp |= state << it->first;
1287 }
1288
1289 *dataLen = sizeof(*resp);
1290 return IPMI_CC_OK;
1291}
1292
Yong Li23737fe2019-02-19 08:49:55 +08001293ipmi_ret_t ipmiOEMCfgHostSerialPortSpeed(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
1294 ipmi_request_t request,
1295 ipmi_response_t response,
1296 ipmi_data_len_t dataLen,
1297 ipmi_context_t context)
1298{
1299 CfgHostSerialReq* req = reinterpret_cast<CfgHostSerialReq*>(request);
1300 uint8_t* resp = reinterpret_cast<uint8_t*>(response);
1301
1302 if (*dataLen == 0)
1303 {
1304 phosphor::logging::log<phosphor::logging::level::ERR>(
1305 "CfgHostSerial: invalid input len!",
1306 phosphor::logging::entry("LEN=%d", *dataLen));
1307 return IPMI_CC_REQ_DATA_LEN_INVALID;
1308 }
1309
1310 switch (req->command)
1311 {
1312 case getHostSerialCfgCmd:
1313 {
1314 if (*dataLen != 1)
1315 {
1316 phosphor::logging::log<phosphor::logging::level::ERR>(
1317 "CfgHostSerial: invalid input len!");
1318 *dataLen = 0;
1319 return IPMI_CC_REQ_DATA_LEN_INVALID;
1320 }
1321
1322 *dataLen = 0;
1323
1324 boost::process::ipstream is;
1325 std::vector<std::string> data;
1326 std::string line;
1327 boost::process::child c1(fwGetEnvCmd, "-n", fwHostSerailCfgEnvName,
1328 boost::process::std_out > is);
1329
1330 while (c1.running() && std::getline(is, line) && !line.empty())
1331 {
1332 data.push_back(line);
1333 }
1334
1335 c1.wait();
1336 if (c1.exit_code())
1337 {
1338 phosphor::logging::log<phosphor::logging::level::ERR>(
1339 "CfgHostSerial:: error on execute",
1340 phosphor::logging::entry("EXECUTE=%s", fwSetEnvCmd));
1341 // Using the default value
1342 *resp = 0;
1343 }
1344 else
1345 {
1346 if (data.size() != 1)
1347 {
1348 phosphor::logging::log<phosphor::logging::level::ERR>(
1349 "CfgHostSerial:: error on read env");
1350 return IPMI_CC_UNSPECIFIED_ERROR;
1351 }
1352 try
1353 {
1354 unsigned long tmp = std::stoul(data[0]);
1355 if (tmp > std::numeric_limits<uint8_t>::max())
1356 {
1357 throw std::out_of_range("Out of range");
1358 }
1359 *resp = static_cast<uint8_t>(tmp);
1360 }
1361 catch (const std::invalid_argument& e)
1362 {
1363 phosphor::logging::log<phosphor::logging::level::ERR>(
1364 "invalid config ",
1365 phosphor::logging::entry("ERR=%s", e.what()));
1366 return IPMI_CC_UNSPECIFIED_ERROR;
1367 }
1368 catch (const std::out_of_range& e)
1369 {
1370 phosphor::logging::log<phosphor::logging::level::ERR>(
1371 "out_of_range config ",
1372 phosphor::logging::entry("ERR=%s", e.what()));
1373 return IPMI_CC_UNSPECIFIED_ERROR;
1374 }
1375 }
1376
1377 *dataLen = 1;
1378 break;
1379 }
1380 case setHostSerialCfgCmd:
1381 {
1382 if (*dataLen != sizeof(CfgHostSerialReq))
1383 {
1384 phosphor::logging::log<phosphor::logging::level::ERR>(
1385 "CfgHostSerial: invalid input len!");
1386 *dataLen = 0;
1387 return IPMI_CC_REQ_DATA_LEN_INVALID;
1388 }
1389
1390 *dataLen = 0;
1391
1392 if (req->parameter > HostSerialCfgParamMax)
1393 {
1394 phosphor::logging::log<phosphor::logging::level::ERR>(
1395 "CfgHostSerial: invalid input!");
1396 return IPMI_CC_INVALID_FIELD_REQUEST;
1397 }
1398
1399 boost::process::child c1(fwSetEnvCmd, fwHostSerailCfgEnvName,
1400 std::to_string(req->parameter));
1401
1402 c1.wait();
1403 if (c1.exit_code())
1404 {
1405 phosphor::logging::log<phosphor::logging::level::ERR>(
1406 "CfgHostSerial:: error on execute",
1407 phosphor::logging::entry("EXECUTE=%s", fwGetEnvCmd));
1408 return IPMI_CC_UNSPECIFIED_ERROR;
1409 }
1410 break;
1411 }
1412 default:
1413 phosphor::logging::log<phosphor::logging::level::ERR>(
1414 "CfgHostSerial: invalid input!");
1415 *dataLen = 0;
1416 return IPMI_CC_INVALID_FIELD_REQUEST;
1417 }
1418
1419 return IPMI_CC_OK;
1420}
1421
James Feist91244a62019-02-19 15:04:54 -08001422constexpr const char* thermalModeInterface =
1423 "xyz.openbmc_project.Control.ThermalMode";
1424constexpr const char* thermalModePath =
1425 "/xyz/openbmc_project/control/thermal_mode";
1426
1427bool getFanProfileInterface(
1428 sdbusplus::bus::bus& bus,
1429 boost::container::flat_map<
1430 std::string, std::variant<std::vector<std::string>, std::string>>& resp)
1431{
1432 auto call = bus.new_method_call(settingsBusName, thermalModePath, PROP_INTF,
1433 "GetAll");
1434 call.append(thermalModeInterface);
1435 try
1436 {
1437 auto data = bus.call(call);
1438 data.read(resp);
1439 }
1440 catch (sdbusplus::exception_t& e)
1441 {
1442 phosphor::logging::log<phosphor::logging::level::ERR>(
1443 "getFanProfileInterface: can't get thermal mode!",
1444 phosphor::logging::entry("ERR=%s", e.what()));
1445 return false;
1446 }
1447 return true;
1448}
1449
anil kumar appanaf945eee2019-09-25 23:29:11 +00001450/**@brief implements the OEM set fan config.
1451 * @param selectedFanProfile - fan profile to enable
1452 * @param reserved1
1453 * @param performanceMode - Performance/Acoustic mode
1454 * @param reserved2
1455 * @param setPerformanceMode - set Performance/Acoustic mode
1456 * @param setFanProfile - set fan profile
1457 *
1458 * @return IPMI completion code.
1459 **/
1460ipmi::RspType<> ipmiOEMSetFanConfig(uint8_t selectedFanProfile,
1461
1462 uint2_t reserved1, bool performanceMode,
1463 uint3_t reserved2, bool setPerformanceMode,
1464 bool setFanProfile)
James Feist91244a62019-02-19 15:04:54 -08001465{
anil kumar appanaf945eee2019-09-25 23:29:11 +00001466 if (reserved1 || reserved2)
James Feist91244a62019-02-19 15:04:54 -08001467 {
anil kumar appanaf945eee2019-09-25 23:29:11 +00001468 return ipmi::responseInvalidFieldRequest();
James Feist91244a62019-02-19 15:04:54 -08001469 }
James Feist91244a62019-02-19 15:04:54 -08001470 // todo: tell bios to only send first 2 bytes
James Feist91244a62019-02-19 15:04:54 -08001471 boost::container::flat_map<
1472 std::string, std::variant<std::vector<std::string>, std::string>>
1473 profileData;
Vernon Mauery15419dd2019-05-24 09:40:30 -07001474 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
1475 if (!getFanProfileInterface(*dbus, profileData))
James Feist91244a62019-02-19 15:04:54 -08001476 {
anil kumar appanaf945eee2019-09-25 23:29:11 +00001477 return ipmi::responseUnspecifiedError();
James Feist91244a62019-02-19 15:04:54 -08001478 }
1479
1480 std::vector<std::string>* supported =
1481 std::get_if<std::vector<std::string>>(&profileData["Supported"]);
1482 if (supported == nullptr)
1483 {
anil kumar appanaf945eee2019-09-25 23:29:11 +00001484 return ipmi::responseInvalidFieldRequest();
James Feist91244a62019-02-19 15:04:54 -08001485 }
1486 std::string mode;
anil kumar appanaf945eee2019-09-25 23:29:11 +00001487 if (setPerformanceMode)
James Feist91244a62019-02-19 15:04:54 -08001488 {
James Feist91244a62019-02-19 15:04:54 -08001489 if (performanceMode)
1490 {
1491
1492 if (std::find(supported->begin(), supported->end(),
1493 "Performance") != supported->end())
1494 {
1495 mode = "Performance";
1496 }
1497 }
1498 else
1499 {
James Feist91244a62019-02-19 15:04:54 -08001500 if (std::find(supported->begin(), supported->end(), "Acoustic") !=
1501 supported->end())
1502 {
1503 mode = "Acoustic";
1504 }
1505 }
1506 if (mode.empty())
1507 {
anil kumar appanaf945eee2019-09-25 23:29:11 +00001508 return ipmi::responseInvalidFieldRequest();
James Feist91244a62019-02-19 15:04:54 -08001509 }
anil kumar appanaf945eee2019-09-25 23:29:11 +00001510
1511 try
1512 {
1513 setDbusProperty(*dbus, settingsBusName, thermalModePath,
1514 thermalModeInterface, "Current", mode);
1515 }
1516 catch (sdbusplus::exception_t& e)
1517 {
1518 phosphor::logging::log<phosphor::logging::level::ERR>(
1519 "ipmiOEMSetFanConfig: can't set thermal mode!",
1520 phosphor::logging::entry("EXCEPTION=%s", e.what()));
1521 return ipmi::responseResponseError();
1522 }
James Feist91244a62019-02-19 15:04:54 -08001523 }
1524
anil kumar appanaf945eee2019-09-25 23:29:11 +00001525 return ipmi::responseSuccess();
James Feist91244a62019-02-19 15:04:54 -08001526}
1527
James Feist5b693632019-07-09 09:06:09 -07001528ipmi::RspType<uint8_t, // profile support map
1529 uint8_t, // fan control profile enable
1530 uint8_t, // flags
1531 uint32_t // dimm presence bit map
1532 >
1533 ipmiOEMGetFanConfig(uint8_t dimmGroupId)
James Feist91244a62019-02-19 15:04:54 -08001534{
James Feist91244a62019-02-19 15:04:54 -08001535 boost::container::flat_map<
1536 std::string, std::variant<std::vector<std::string>, std::string>>
1537 profileData;
1538
Vernon Mauery15419dd2019-05-24 09:40:30 -07001539 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
1540 if (!getFanProfileInterface(*dbus, profileData))
James Feist91244a62019-02-19 15:04:54 -08001541 {
James Feist5b693632019-07-09 09:06:09 -07001542 return ipmi::responseResponseError();
James Feist91244a62019-02-19 15:04:54 -08001543 }
1544
1545 std::string* current = std::get_if<std::string>(&profileData["Current"]);
1546
1547 if (current == nullptr)
1548 {
1549 phosphor::logging::log<phosphor::logging::level::ERR>(
1550 "ipmiOEMGetFanConfig: can't get current mode!");
James Feist5b693632019-07-09 09:06:09 -07001551 return ipmi::responseResponseError();
James Feist91244a62019-02-19 15:04:54 -08001552 }
1553 bool performance = (*current == "Performance");
1554
James Feist5b693632019-07-09 09:06:09 -07001555 uint8_t flags = 0;
James Feist91244a62019-02-19 15:04:54 -08001556 if (performance)
1557 {
James Feist5b693632019-07-09 09:06:09 -07001558 flags |= 1 << 2;
James Feist91244a62019-02-19 15:04:54 -08001559 }
1560
James Feist5b693632019-07-09 09:06:09 -07001561 return ipmi::responseSuccess(0, 0, flags, 0);
James Feist91244a62019-02-19 15:04:54 -08001562}
James Feist5f957ca2019-03-14 15:33:55 -07001563constexpr const char* cfmLimitSettingPath =
1564 "/xyz/openbmc_project/control/cfm_limit";
1565constexpr const char* cfmLimitIface = "xyz.openbmc_project.Control.CFMLimit";
James Feistfaa4f222019-03-21 16:21:55 -07001566constexpr const size_t legacyExitAirSensorNumber = 0x2e;
James Feist09f6b602019-08-08 11:30:03 -07001567constexpr const size_t legacyPCHSensorNumber = 0x22;
1568constexpr const char* exitAirPathName = "Exit_Air";
1569constexpr const char* pchPathName = "SSB_Temp";
James Feistacc8a4e2019-04-02 14:23:57 -07001570constexpr const char* pidConfigurationIface =
1571 "xyz.openbmc_project.Configuration.Pid";
James Feistfaa4f222019-03-21 16:21:55 -07001572
James Feist09f6b602019-08-08 11:30:03 -07001573static std::string getConfigPath(const std::string& name)
James Feistfaa4f222019-03-21 16:21:55 -07001574{
Vernon Mauery15419dd2019-05-24 09:40:30 -07001575 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
James Feistfaa4f222019-03-21 16:21:55 -07001576 auto method =
Vernon Mauery15419dd2019-05-24 09:40:30 -07001577 dbus->new_method_call("xyz.openbmc_project.ObjectMapper",
1578 "/xyz/openbmc_project/object_mapper",
1579 "xyz.openbmc_project.ObjectMapper", "GetSubTree");
James Feistfaa4f222019-03-21 16:21:55 -07001580
James Feistacc8a4e2019-04-02 14:23:57 -07001581 method.append("/", 0, std::array<const char*, 1>{pidConfigurationIface});
James Feistfaa4f222019-03-21 16:21:55 -07001582 std::string path;
1583 GetSubTreeType resp;
1584 try
1585 {
Vernon Mauery15419dd2019-05-24 09:40:30 -07001586 auto reply = dbus->call(method);
James Feistfaa4f222019-03-21 16:21:55 -07001587 reply.read(resp);
1588 }
1589 catch (sdbusplus::exception_t&)
1590 {
1591 phosphor::logging::log<phosphor::logging::level::ERR>(
1592 "ipmiOEMGetFscParameter: mapper error");
1593 };
James Feist09f6b602019-08-08 11:30:03 -07001594 auto config =
1595 std::find_if(resp.begin(), resp.end(), [&name](const auto& pair) {
1596 return pair.first.find(name) != std::string::npos;
1597 });
James Feistfaa4f222019-03-21 16:21:55 -07001598 if (config != resp.end())
1599 {
1600 path = std::move(config->first);
1601 }
1602 return path;
1603}
James Feist5f957ca2019-03-14 15:33:55 -07001604
James Feistacc8a4e2019-04-02 14:23:57 -07001605// flat map to make alphabetical
1606static boost::container::flat_map<std::string, PropertyMap> getPidConfigs()
1607{
1608 boost::container::flat_map<std::string, PropertyMap> ret;
Vernon Mauery15419dd2019-05-24 09:40:30 -07001609 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
James Feistacc8a4e2019-04-02 14:23:57 -07001610 auto method =
Vernon Mauery15419dd2019-05-24 09:40:30 -07001611 dbus->new_method_call("xyz.openbmc_project.ObjectMapper",
1612 "/xyz/openbmc_project/object_mapper",
1613 "xyz.openbmc_project.ObjectMapper", "GetSubTree");
James Feistacc8a4e2019-04-02 14:23:57 -07001614
1615 method.append("/", 0, std::array<const char*, 1>{pidConfigurationIface});
1616 GetSubTreeType resp;
1617
1618 try
1619 {
Vernon Mauery15419dd2019-05-24 09:40:30 -07001620 auto reply = dbus->call(method);
James Feistacc8a4e2019-04-02 14:23:57 -07001621 reply.read(resp);
1622 }
1623 catch (sdbusplus::exception_t&)
1624 {
1625 phosphor::logging::log<phosphor::logging::level::ERR>(
1626 "getFanConfigPaths: mapper error");
1627 };
1628 for (const auto& [path, objects] : resp)
1629 {
1630 if (objects.empty())
1631 {
1632 continue; // should be impossible
1633 }
Zhu, Yungebe560b02019-04-21 21:19:21 -04001634
1635 try
1636 {
Vernon Mauery15419dd2019-05-24 09:40:30 -07001637 ret.emplace(path,
1638 getAllDbusProperties(*dbus, objects[0].first, path,
1639 pidConfigurationIface));
Zhu, Yungebe560b02019-04-21 21:19:21 -04001640 }
1641 catch (sdbusplus::exception_t& e)
1642 {
1643 phosphor::logging::log<phosphor::logging::level::ERR>(
1644 "getPidConfigs: can't get DbusProperties!",
1645 phosphor::logging::entry("ERR=%s", e.what()));
1646 }
James Feistacc8a4e2019-04-02 14:23:57 -07001647 }
1648 return ret;
1649}
1650
1651ipmi::RspType<uint8_t> ipmiOEMGetFanSpeedOffset(void)
1652{
1653 boost::container::flat_map<std::string, PropertyMap> data = getPidConfigs();
1654 if (data.empty())
1655 {
1656 return ipmi::responseResponseError();
1657 }
1658 uint8_t minOffset = std::numeric_limits<uint8_t>::max();
1659 for (const auto& [_, pid] : data)
1660 {
1661 auto findClass = pid.find("Class");
1662 if (findClass == pid.end())
1663 {
1664 phosphor::logging::log<phosphor::logging::level::ERR>(
1665 "ipmiOEMGetFscParameter: found illegal pid "
1666 "configurations");
1667 return ipmi::responseResponseError();
1668 }
1669 std::string type = std::get<std::string>(findClass->second);
1670 if (type == "fan")
1671 {
1672 auto findOutLimit = pid.find("OutLimitMin");
1673 if (findOutLimit == pid.end())
1674 {
1675 phosphor::logging::log<phosphor::logging::level::ERR>(
1676 "ipmiOEMGetFscParameter: found illegal pid "
1677 "configurations");
1678 return ipmi::responseResponseError();
1679 }
1680 // get the min out of all the offsets
1681 minOffset = std::min(
1682 minOffset,
1683 static_cast<uint8_t>(std::get<double>(findOutLimit->second)));
1684 }
1685 }
1686 if (minOffset == std::numeric_limits<uint8_t>::max())
1687 {
1688 phosphor::logging::log<phosphor::logging::level::ERR>(
1689 "ipmiOEMGetFscParameter: found no fan configurations!");
1690 return ipmi::responseResponseError();
1691 }
1692
1693 return ipmi::responseSuccess(minOffset);
1694}
1695
1696ipmi::RspType<> ipmiOEMSetFanSpeedOffset(uint8_t offset)
1697{
1698 boost::container::flat_map<std::string, PropertyMap> data = getPidConfigs();
1699 if (data.empty())
1700 {
1701
1702 phosphor::logging::log<phosphor::logging::level::ERR>(
1703 "ipmiOEMSetFanSpeedOffset: found no pid configurations!");
1704 return ipmi::responseResponseError();
1705 }
1706
Vernon Mauery15419dd2019-05-24 09:40:30 -07001707 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
James Feistacc8a4e2019-04-02 14:23:57 -07001708 bool found = false;
1709 for (const auto& [path, pid] : data)
1710 {
1711 auto findClass = pid.find("Class");
1712 if (findClass == pid.end())
1713 {
1714
1715 phosphor::logging::log<phosphor::logging::level::ERR>(
1716 "ipmiOEMSetFanSpeedOffset: found illegal pid "
1717 "configurations");
1718 return ipmi::responseResponseError();
1719 }
1720 std::string type = std::get<std::string>(findClass->second);
1721 if (type == "fan")
1722 {
1723 auto findOutLimit = pid.find("OutLimitMin");
1724 if (findOutLimit == pid.end())
1725 {
1726
1727 phosphor::logging::log<phosphor::logging::level::ERR>(
1728 "ipmiOEMSetFanSpeedOffset: found illegal pid "
1729 "configurations");
1730 return ipmi::responseResponseError();
1731 }
Vernon Mauery15419dd2019-05-24 09:40:30 -07001732 ipmi::setDbusProperty(*dbus, "xyz.openbmc_project.EntityManager",
James Feistacc8a4e2019-04-02 14:23:57 -07001733 path, pidConfigurationIface, "OutLimitMin",
1734 static_cast<double>(offset));
1735 found = true;
1736 }
1737 }
1738 if (!found)
1739 {
1740 phosphor::logging::log<phosphor::logging::level::ERR>(
1741 "ipmiOEMSetFanSpeedOffset: set no fan offsets");
1742 return ipmi::responseResponseError();
1743 }
1744
1745 return ipmi::responseSuccess();
1746}
1747
1748ipmi::RspType<> ipmiOEMSetFscParameter(uint8_t command, uint8_t param1,
1749 uint8_t param2)
James Feist5f957ca2019-03-14 15:33:55 -07001750{
1751 constexpr const size_t disableLimiting = 0x0;
1752
Vernon Mauery15419dd2019-05-24 09:40:30 -07001753 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
James Feistacc8a4e2019-04-02 14:23:57 -07001754 if (command == static_cast<uint8_t>(setFscParamFlags::tcontrol))
James Feist5f957ca2019-03-14 15:33:55 -07001755 {
James Feist09f6b602019-08-08 11:30:03 -07001756 std::string pathName;
James Feistacc8a4e2019-04-02 14:23:57 -07001757 if (param1 == legacyExitAirSensorNumber)
James Feistfaa4f222019-03-21 16:21:55 -07001758 {
James Feist09f6b602019-08-08 11:30:03 -07001759 pathName = exitAirPathName;
1760 }
1761 else if (param1 == legacyPCHSensorNumber)
1762 {
1763 pathName = pchPathName;
James Feistfaa4f222019-03-21 16:21:55 -07001764 }
1765 else
1766 {
James Feistacc8a4e2019-04-02 14:23:57 -07001767 return ipmi::responseParmOutOfRange();
James Feistfaa4f222019-03-21 16:21:55 -07001768 }
James Feist09f6b602019-08-08 11:30:03 -07001769 std::string path = getConfigPath(pathName);
1770 ipmi::setDbusProperty(*dbus, "xyz.openbmc_project.EntityManager", path,
1771 pidConfigurationIface, "SetPoint",
1772 static_cast<double>(param2));
1773 return ipmi::responseSuccess();
James Feistfaa4f222019-03-21 16:21:55 -07001774 }
James Feistacc8a4e2019-04-02 14:23:57 -07001775 else if (command == static_cast<uint8_t>(setFscParamFlags::cfm))
James Feist5f957ca2019-03-14 15:33:55 -07001776 {
James Feistacc8a4e2019-04-02 14:23:57 -07001777 uint16_t cfm = param1 | (static_cast<uint16_t>(param2) << 8);
James Feist5f957ca2019-03-14 15:33:55 -07001778
1779 // must be greater than 50 based on eps
1780 if (cfm < 50 && cfm != disableLimiting)
1781 {
James Feistacc8a4e2019-04-02 14:23:57 -07001782 return ipmi::responseParmOutOfRange();
James Feist5f957ca2019-03-14 15:33:55 -07001783 }
1784
1785 try
1786 {
Vernon Mauery15419dd2019-05-24 09:40:30 -07001787 ipmi::setDbusProperty(*dbus, settingsBusName, cfmLimitSettingPath,
James Feist5f957ca2019-03-14 15:33:55 -07001788 cfmLimitIface, "Limit",
1789 static_cast<double>(cfm));
1790 }
1791 catch (sdbusplus::exception_t& e)
1792 {
1793 phosphor::logging::log<phosphor::logging::level::ERR>(
1794 "ipmiOEMSetFscParameter: can't set cfm setting!",
1795 phosphor::logging::entry("ERR=%s", e.what()));
James Feistacc8a4e2019-04-02 14:23:57 -07001796 return ipmi::responseResponseError();
James Feist5f957ca2019-03-14 15:33:55 -07001797 }
James Feistacc8a4e2019-04-02 14:23:57 -07001798 return ipmi::responseSuccess();
1799 }
1800 else if (command == static_cast<uint8_t>(setFscParamFlags::maxPwm))
1801 {
1802 constexpr const size_t maxDomainCount = 8;
1803 uint8_t requestedDomainMask = param1;
1804 boost::container::flat_map data = getPidConfigs();
1805 if (data.empty())
1806 {
1807
1808 phosphor::logging::log<phosphor::logging::level::ERR>(
1809 "ipmiOEMSetFscParameter: found no pid configurations!");
1810 return ipmi::responseResponseError();
1811 }
1812 size_t count = 0;
1813 for (const auto& [path, pid] : data)
1814 {
1815 auto findClass = pid.find("Class");
1816 if (findClass == pid.end())
1817 {
1818
1819 phosphor::logging::log<phosphor::logging::level::ERR>(
1820 "ipmiOEMSetFscParameter: found illegal pid "
1821 "configurations");
1822 return ipmi::responseResponseError();
1823 }
1824 std::string type = std::get<std::string>(findClass->second);
1825 if (type == "fan")
1826 {
1827 if (requestedDomainMask & (1 << count))
1828 {
1829 ipmi::setDbusProperty(
Vernon Mauery15419dd2019-05-24 09:40:30 -07001830 *dbus, "xyz.openbmc_project.EntityManager", path,
James Feistacc8a4e2019-04-02 14:23:57 -07001831 pidConfigurationIface, "OutLimitMax",
1832 static_cast<double>(param2));
1833 }
1834 count++;
1835 }
1836 }
1837 return ipmi::responseSuccess();
James Feist5f957ca2019-03-14 15:33:55 -07001838 }
1839 else
1840 {
1841 // todo other command parts possibly
1842 // tcontrol is handled in peci now
1843 // fan speed offset not implemented yet
1844 // domain pwm limit not implemented
James Feistacc8a4e2019-04-02 14:23:57 -07001845 return ipmi::responseParmOutOfRange();
James Feist5f957ca2019-03-14 15:33:55 -07001846 }
1847}
1848
James Feistacc8a4e2019-04-02 14:23:57 -07001849ipmi::RspType<
1850 std::variant<uint8_t, std::array<uint8_t, 2>, std::array<uint16_t, 2>>>
1851 ipmiOEMGetFscParameter(uint8_t command, std::optional<uint8_t> param)
James Feist5f957ca2019-03-14 15:33:55 -07001852{
James Feist09f6b602019-08-08 11:30:03 -07001853 constexpr uint8_t legacyDefaultSetpoint = -128;
James Feist5f957ca2019-03-14 15:33:55 -07001854
Vernon Mauery15419dd2019-05-24 09:40:30 -07001855 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
James Feistacc8a4e2019-04-02 14:23:57 -07001856 if (command == static_cast<uint8_t>(setFscParamFlags::tcontrol))
James Feist5f957ca2019-03-14 15:33:55 -07001857 {
James Feistacc8a4e2019-04-02 14:23:57 -07001858 if (!param)
James Feistfaa4f222019-03-21 16:21:55 -07001859 {
James Feistacc8a4e2019-04-02 14:23:57 -07001860 return ipmi::responseReqDataLenInvalid();
James Feistfaa4f222019-03-21 16:21:55 -07001861 }
1862
James Feist09f6b602019-08-08 11:30:03 -07001863 std::string pathName;
1864
1865 if (*param == legacyExitAirSensorNumber)
1866 {
1867 pathName = exitAirPathName;
1868 }
1869 else if (*param == legacyPCHSensorNumber)
1870 {
1871 pathName = pchPathName;
1872 }
1873 else
James Feistfaa4f222019-03-21 16:21:55 -07001874 {
James Feistacc8a4e2019-04-02 14:23:57 -07001875 return ipmi::responseParmOutOfRange();
James Feistfaa4f222019-03-21 16:21:55 -07001876 }
James Feist09f6b602019-08-08 11:30:03 -07001877
1878 uint8_t setpoint = legacyDefaultSetpoint;
1879 std::string path = getConfigPath(pathName);
James Feistfaa4f222019-03-21 16:21:55 -07001880 if (path.size())
1881 {
Vernon Mauery15419dd2019-05-24 09:40:30 -07001882 Value val = ipmi::getDbusProperty(
1883 *dbus, "xyz.openbmc_project.EntityManager", path,
1884 pidConfigurationIface, "SetPoint");
James Feistfaa4f222019-03-21 16:21:55 -07001885 setpoint = std::floor(std::get<double>(val) + 0.5);
1886 }
1887
1888 // old implementation used to return the "default" and current, we
1889 // don't make the default readily available so just make both the
1890 // same
James Feistfaa4f222019-03-21 16:21:55 -07001891
James Feistacc8a4e2019-04-02 14:23:57 -07001892 return ipmi::responseSuccess(
1893 std::array<uint8_t, 2>{setpoint, setpoint});
James Feistfaa4f222019-03-21 16:21:55 -07001894 }
James Feistacc8a4e2019-04-02 14:23:57 -07001895 else if (command == static_cast<uint8_t>(setFscParamFlags::maxPwm))
1896 {
1897 constexpr const size_t maxDomainCount = 8;
1898
1899 if (!param)
1900 {
1901 return ipmi::responseReqDataLenInvalid();
1902 }
1903 uint8_t requestedDomain = *param;
1904 if (requestedDomain >= maxDomainCount)
1905 {
1906 return ipmi::responseInvalidFieldRequest();
1907 }
1908
1909 boost::container::flat_map data = getPidConfigs();
1910 if (data.empty())
1911 {
1912 phosphor::logging::log<phosphor::logging::level::ERR>(
1913 "ipmiOEMGetFscParameter: found no pid configurations!");
1914 return ipmi::responseResponseError();
1915 }
1916 size_t count = 0;
1917 for (const auto& [_, pid] : data)
1918 {
1919 auto findClass = pid.find("Class");
1920 if (findClass == pid.end())
1921 {
1922 phosphor::logging::log<phosphor::logging::level::ERR>(
1923 "ipmiOEMGetFscParameter: found illegal pid "
1924 "configurations");
1925 return ipmi::responseResponseError();
1926 }
1927 std::string type = std::get<std::string>(findClass->second);
1928 if (type == "fan")
1929 {
1930 if (requestedDomain == count)
1931 {
1932 auto findOutLimit = pid.find("OutLimitMax");
1933 if (findOutLimit == pid.end())
1934 {
1935 phosphor::logging::log<phosphor::logging::level::ERR>(
1936 "ipmiOEMGetFscParameter: found illegal pid "
1937 "configurations");
1938 return ipmi::responseResponseError();
1939 }
1940
1941 return ipmi::responseSuccess(
1942 static_cast<uint8_t>(std::floor(
1943 std::get<double>(findOutLimit->second) + 0.5)));
1944 }
1945 else
1946 {
1947 count++;
1948 }
1949 }
1950 }
1951
1952 return ipmi::responseInvalidFieldRequest();
1953 }
1954 else if (command == static_cast<uint8_t>(setFscParamFlags::cfm))
James Feist5f957ca2019-03-14 15:33:55 -07001955 {
1956
1957 /*
1958 DataLen should be 1, but host is sending us an extra bit. As the
James Feistacc8a4e2019-04-02 14:23:57 -07001959 previous behavior didn't seem to prevent this, ignore the check for
1960 now.
James Feist5f957ca2019-03-14 15:33:55 -07001961
James Feistacc8a4e2019-04-02 14:23:57 -07001962 if (param)
James Feist5f957ca2019-03-14 15:33:55 -07001963 {
1964 phosphor::logging::log<phosphor::logging::level::ERR>(
1965 "ipmiOEMGetFscParameter: invalid input len!");
James Feist5f957ca2019-03-14 15:33:55 -07001966 return IPMI_CC_REQ_DATA_LEN_INVALID;
1967 }
1968 */
1969 Value cfmLimit;
1970 Value cfmMaximum;
1971 try
1972 {
Vernon Mauery15419dd2019-05-24 09:40:30 -07001973 cfmLimit = ipmi::getDbusProperty(*dbus, settingsBusName,
James Feist5f957ca2019-03-14 15:33:55 -07001974 cfmLimitSettingPath, cfmLimitIface,
1975 "Limit");
1976 cfmMaximum = ipmi::getDbusProperty(
Vernon Mauery15419dd2019-05-24 09:40:30 -07001977 *dbus, "xyz.openbmc_project.ExitAirTempSensor",
James Feist5f957ca2019-03-14 15:33:55 -07001978 "/xyz/openbmc_project/control/MaxCFM", cfmLimitIface, "Limit");
1979 }
1980 catch (sdbusplus::exception_t& e)
1981 {
1982 phosphor::logging::log<phosphor::logging::level::ERR>(
James Feistacc8a4e2019-04-02 14:23:57 -07001983 "ipmiOEMGetFscParameter: can't get cfm setting!",
James Feist5f957ca2019-03-14 15:33:55 -07001984 phosphor::logging::entry("ERR=%s", e.what()));
James Feistacc8a4e2019-04-02 14:23:57 -07001985 return ipmi::responseResponseError();
James Feist5f957ca2019-03-14 15:33:55 -07001986 }
1987
James Feistacc8a4e2019-04-02 14:23:57 -07001988 double cfmMax = std::get<double>(cfmMaximum);
1989 double cfmLim = std::get<double>(cfmLimit);
James Feist5f957ca2019-03-14 15:33:55 -07001990
James Feistacc8a4e2019-04-02 14:23:57 -07001991 cfmLim = std::floor(cfmLim + 0.5);
1992 cfmMax = std::floor(cfmMax + 0.5);
1993 uint16_t cfmLimResp = static_cast<uint16_t>(cfmLim);
1994 uint16_t cfmMaxResp = static_cast<uint16_t>(cfmMax);
James Feist5f957ca2019-03-14 15:33:55 -07001995
James Feistacc8a4e2019-04-02 14:23:57 -07001996 return ipmi::responseSuccess(
1997 std::array<uint16_t, 2>{cfmLimResp, cfmMaxResp});
James Feist5f957ca2019-03-14 15:33:55 -07001998 }
James Feistacc8a4e2019-04-02 14:23:57 -07001999
James Feist5f957ca2019-03-14 15:33:55 -07002000 else
2001 {
2002 // todo other command parts possibly
James Feist5f957ca2019-03-14 15:33:55 -07002003 // domain pwm limit not implemented
James Feistacc8a4e2019-04-02 14:23:57 -07002004 return ipmi::responseParmOutOfRange();
James Feist5f957ca2019-03-14 15:33:55 -07002005 }
2006}
2007
Cheng C Yang773703a2019-08-15 09:41:11 +08002008using crConfigVariant =
2009 std::variant<bool, uint8_t, uint32_t, std::vector<uint8_t>, std::string>;
2010
2011int setCRConfig(ipmi::Context::ptr ctx, const std::string& property,
2012 const crConfigVariant& value,
2013 std::chrono::microseconds timeout = ipmi::IPMI_DBUS_TIMEOUT)
2014{
2015 boost::system::error_code ec;
2016 ctx->bus->yield_method_call<void>(
James Feist28c72902019-09-16 10:34:07 -07002017 ctx->yield, ec, "xyz.openbmc_project.Settings",
Cheng C Yang773703a2019-08-15 09:41:11 +08002018 "/xyz/openbmc_project/control/power_supply_redundancy",
2019 "org.freedesktop.DBus.Properties", "Set",
2020 "xyz.openbmc_project.Control.PowerSupplyRedundancy", property, value);
2021 if (ec)
2022 {
2023 phosphor::logging::log<phosphor::logging::level::ERR>(
2024 "Failed to set dbus property to cold redundancy");
2025 return -1;
2026 }
2027
2028 return 0;
2029}
2030
2031int getCRConfig(ipmi::Context::ptr ctx, const std::string& property,
2032 crConfigVariant& value,
Yong Li19445ab2019-12-20 18:25:29 +08002033 const std::string& service = "xyz.openbmc_project.Settings",
Cheng C Yang773703a2019-08-15 09:41:11 +08002034 std::chrono::microseconds timeout = ipmi::IPMI_DBUS_TIMEOUT)
2035{
2036 boost::system::error_code ec;
2037 value = ctx->bus->yield_method_call<crConfigVariant>(
Yong Li19445ab2019-12-20 18:25:29 +08002038 ctx->yield, ec, service,
Cheng C Yang773703a2019-08-15 09:41:11 +08002039 "/xyz/openbmc_project/control/power_supply_redundancy",
2040 "org.freedesktop.DBus.Properties", "Get",
2041 "xyz.openbmc_project.Control.PowerSupplyRedundancy", property);
2042 if (ec)
2043 {
2044 phosphor::logging::log<phosphor::logging::level::ERR>(
2045 "Failed to get dbus property to cold redundancy");
2046 return -1;
2047 }
2048 return 0;
2049}
2050
2051uint8_t getPSUCount(void)
2052{
2053 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
2054 ipmi::Value num;
2055 try
2056 {
2057 num = ipmi::getDbusProperty(
2058 *dbus, "xyz.openbmc_project.PSURedundancy",
2059 "/xyz/openbmc_project/control/power_supply_redundancy",
2060 "xyz.openbmc_project.Control.PowerSupplyRedundancy", "PSUNumber");
2061 }
2062 catch (sdbusplus::exception_t& e)
2063 {
2064 phosphor::logging::log<phosphor::logging::level::ERR>(
2065 "Failed to get PSUNumber property from dbus interface");
2066 return 0;
2067 }
2068 uint8_t* pNum = std::get_if<uint8_t>(&num);
2069 if (!pNum)
2070 {
2071 phosphor::logging::log<phosphor::logging::level::ERR>(
2072 "Error to get PSU Number");
2073 return 0;
2074 }
2075 return *pNum;
2076}
2077
2078bool validateCRAlgo(std::vector<uint8_t>& conf, uint8_t num)
2079{
2080 if (conf.size() < num)
2081 {
2082 phosphor::logging::log<phosphor::logging::level::ERR>(
2083 "Invalid PSU Ranking");
2084 return false;
2085 }
2086 std::set<uint8_t> confSet;
2087 for (uint8_t i = 0; i < num; i++)
2088 {
2089 if (conf[i] > num)
2090 {
2091 phosphor::logging::log<phosphor::logging::level::ERR>(
2092 "PSU Ranking is larger than current PSU number");
2093 return false;
2094 }
2095 confSet.emplace(conf[i]);
2096 }
2097
2098 if (confSet.size() != num)
2099 {
2100 phosphor::logging::log<phosphor::logging::level::ERR>(
2101 "duplicate PSU Ranking");
2102 return false;
2103 }
2104 return true;
2105}
2106
2107enum class crParameter
2108{
2109 crStatus = 0,
2110 crFeature = 1,
2111 rotationFeature = 2,
2112 rotationAlgo = 3,
2113 rotationPeriod = 4,
Yong Li19445ab2019-12-20 18:25:29 +08002114 numOfPSU = 5,
2115 rotationRankOrderEffective = 6
Cheng C Yang773703a2019-08-15 09:41:11 +08002116};
2117
2118constexpr ipmi::Cc ccParameterNotSupported = 0x80;
2119static const constexpr uint32_t oneDay = 0x15180;
2120static const constexpr uint32_t oneMonth = 0xf53700;
2121static const constexpr uint8_t userSpecific = 0x01;
2122static const constexpr uint8_t crSetCompleted = 0;
2123ipmi::RspType<uint8_t> ipmiOEMSetCRConfig(ipmi::Context::ptr ctx,
2124 uint8_t parameter,
2125 ipmi::message::Payload& payload)
2126{
2127 switch (static_cast<crParameter>(parameter))
2128 {
2129 case crParameter::crFeature:
2130 {
2131 uint8_t param1;
2132 if (payload.unpack(param1) || !payload.fullyUnpacked())
2133 {
2134 return ipmi::responseReqDataLenInvalid();
2135 }
2136 // ColdRedundancy Enable can only be true or flase
2137 if (param1 > 1)
2138 {
2139 return ipmi::responseInvalidFieldRequest();
2140 }
2141 if (setCRConfig(ctx, "ColdRedundancyEnabled",
2142 static_cast<bool>(param1)))
2143 {
2144 return ipmi::responseResponseError();
2145 }
2146 break;
2147 }
2148 case crParameter::rotationFeature:
2149 {
2150 uint8_t param1;
2151 if (payload.unpack(param1) || !payload.fullyUnpacked())
2152 {
2153 return ipmi::responseReqDataLenInvalid();
2154 }
2155 // Rotation Enable can only be true or false
2156 if (param1 > 1)
2157 {
2158 return ipmi::responseInvalidFieldRequest();
2159 }
2160 if (setCRConfig(ctx, "RotationEnabled", static_cast<bool>(param1)))
2161 {
2162 return ipmi::responseResponseError();
2163 }
2164 break;
2165 }
2166 case crParameter::rotationAlgo:
2167 {
2168 // Rotation Algorithm can only be 0-BMC Specific or 1-User Specific
2169 std::string algoName;
2170 uint8_t param1;
2171 if (payload.unpack(param1))
2172 {
2173 return ipmi::responseReqDataLenInvalid();
2174 }
2175 switch (param1)
2176 {
2177 case 0:
2178 algoName = "xyz.openbmc_project.Control."
2179 "PowerSupplyRedundancy.Algo.bmcSpecific";
2180 break;
2181 case 1:
2182 algoName = "xyz.openbmc_project.Control."
2183 "PowerSupplyRedundancy.Algo.userSpecific";
2184 break;
2185 default:
2186 return ipmi::responseInvalidFieldRequest();
2187 }
2188 if (setCRConfig(ctx, "RotationAlgorithm", algoName))
2189 {
2190 return ipmi::responseResponseError();
2191 }
2192
2193 uint8_t numberOfPSU = getPSUCount();
2194 if (!numberOfPSU)
2195 {
2196 return ipmi::responseResponseError();
2197 }
2198 std::vector<uint8_t> rankOrder;
2199
2200 if (param1 == userSpecific)
2201 {
2202 if (payload.unpack(rankOrder) || !payload.fullyUnpacked())
2203 {
2204 ipmi::responseReqDataLenInvalid();
2205 }
Yong Li83315132019-10-23 17:42:24 +08002206 if (rankOrder.size() != numberOfPSU)
Cheng C Yang773703a2019-08-15 09:41:11 +08002207 {
2208 return ipmi::responseReqDataLenInvalid();
2209 }
2210
2211 if (!validateCRAlgo(rankOrder, numberOfPSU))
2212 {
2213 return ipmi::responseInvalidFieldRequest();
2214 }
2215 }
2216 else
2217 {
2218 if (rankOrder.size() > 0)
2219 {
2220 return ipmi::responseReqDataLenInvalid();
2221 }
2222 for (uint8_t i = 1; i <= numberOfPSU; i++)
2223 {
2224 rankOrder.emplace_back(i);
2225 }
2226 }
2227 if (setCRConfig(ctx, "RotationRankOrder", rankOrder))
2228 {
2229 return ipmi::responseResponseError();
2230 }
2231 break;
2232 }
2233 case crParameter::rotationPeriod:
2234 {
2235 // Minimum Rotation period is One day (86400 seconds) and Max
2236 // Rotation Period is 6 month (0xf53700 seconds)
2237 uint32_t period;
2238 if (payload.unpack(period) || !payload.fullyUnpacked())
2239 {
2240 return ipmi::responseReqDataLenInvalid();
2241 }
2242 if ((period < oneDay) || (period > oneMonth))
2243 {
2244 return ipmi::responseInvalidFieldRequest();
2245 }
2246 if (setCRConfig(ctx, "PeriodOfRotation", period))
2247 {
2248 return ipmi::responseResponseError();
2249 }
2250 break;
2251 }
2252 default:
2253 {
2254 return ipmi::response(ccParameterNotSupported);
2255 }
2256 }
2257
2258 // TODO Halfwidth needs to set SetInProgress
2259 if (setCRConfig(ctx, "ColdRedundancyStatus",
Cheng C Yange8cecdf2019-08-26 23:48:08 +08002260 std::string("xyz.openbmc_project.Control."
2261 "PowerSupplyRedundancy.Status.completed")))
Cheng C Yang773703a2019-08-15 09:41:11 +08002262 {
2263 return ipmi::responseResponseError();
2264 }
2265 return ipmi::responseSuccess(crSetCompleted);
2266}
2267
Yong Li83315132019-10-23 17:42:24 +08002268ipmi::RspType<uint8_t, std::variant<uint8_t, uint32_t, std::vector<uint8_t>>>
Cheng C Yang773703a2019-08-15 09:41:11 +08002269 ipmiOEMGetCRConfig(ipmi::Context::ptr ctx, uint8_t parameter)
2270{
2271 crConfigVariant value;
2272 switch (static_cast<crParameter>(parameter))
2273 {
2274 case crParameter::crStatus:
2275 {
2276 if (getCRConfig(ctx, "ColdRedundancyStatus", value))
2277 {
2278 return ipmi::responseResponseError();
2279 }
2280 std::string* pStatus = std::get_if<std::string>(&value);
2281 if (!pStatus)
2282 {
2283 phosphor::logging::log<phosphor::logging::level::ERR>(
2284 "Error to get ColdRedundancyStatus property");
2285 return ipmi::responseResponseError();
2286 }
2287 namespace server = sdbusplus::xyz::openbmc_project::Control::server;
2288 auto status =
2289 server::PowerSupplyRedundancy::convertStatusFromString(
2290 *pStatus);
2291 switch (status)
2292 {
2293 case server::PowerSupplyRedundancy::Status::inProgress:
Cheng C Yangf41e3342019-09-10 04:47:23 +08002294 return ipmi::responseSuccess(parameter,
2295 static_cast<uint8_t>(0));
Cheng C Yang773703a2019-08-15 09:41:11 +08002296
2297 case server::PowerSupplyRedundancy::Status::completed:
Cheng C Yangf41e3342019-09-10 04:47:23 +08002298 return ipmi::responseSuccess(parameter,
2299 static_cast<uint8_t>(1));
Cheng C Yang773703a2019-08-15 09:41:11 +08002300 default:
2301 phosphor::logging::log<phosphor::logging::level::ERR>(
2302 "Error to get valid status");
2303 return ipmi::responseResponseError();
2304 }
2305 }
2306 case crParameter::crFeature:
2307 {
2308 if (getCRConfig(ctx, "ColdRedundancyEnabled", value))
2309 {
2310 return ipmi::responseResponseError();
2311 }
2312 bool* pResponse = std::get_if<bool>(&value);
2313 if (!pResponse)
2314 {
2315 phosphor::logging::log<phosphor::logging::level::ERR>(
2316 "Error to get ColdRedundancyEnable property");
2317 return ipmi::responseResponseError();
2318 }
2319
Cheng C Yangf41e3342019-09-10 04:47:23 +08002320 return ipmi::responseSuccess(parameter,
2321 static_cast<uint8_t>(*pResponse));
Cheng C Yang773703a2019-08-15 09:41:11 +08002322 }
2323 case crParameter::rotationFeature:
2324 {
2325 if (getCRConfig(ctx, "RotationEnabled", value))
2326 {
2327 return ipmi::responseResponseError();
2328 }
2329 bool* pResponse = std::get_if<bool>(&value);
2330 if (!pResponse)
2331 {
2332 phosphor::logging::log<phosphor::logging::level::ERR>(
2333 "Error to get RotationEnabled property");
2334 return ipmi::responseResponseError();
2335 }
Cheng C Yangf41e3342019-09-10 04:47:23 +08002336 return ipmi::responseSuccess(parameter,
2337 static_cast<uint8_t>(*pResponse));
Cheng C Yang773703a2019-08-15 09:41:11 +08002338 }
2339 case crParameter::rotationAlgo:
2340 {
2341 if (getCRConfig(ctx, "RotationAlgorithm", value))
2342 {
2343 return ipmi::responseResponseError();
2344 }
2345
2346 std::string* pAlgo = std::get_if<std::string>(&value);
2347 if (!pAlgo)
2348 {
2349 phosphor::logging::log<phosphor::logging::level::ERR>(
2350 "Error to get RotationAlgorithm property");
2351 return ipmi::responseResponseError();
2352 }
Yong Li83315132019-10-23 17:42:24 +08002353 std::vector<uint8_t> response;
Cheng C Yang773703a2019-08-15 09:41:11 +08002354 namespace server = sdbusplus::xyz::openbmc_project::Control::server;
2355 auto algo =
2356 server::PowerSupplyRedundancy::convertAlgoFromString(*pAlgo);
Yong Li83315132019-10-23 17:42:24 +08002357
Cheng C Yang773703a2019-08-15 09:41:11 +08002358 switch (algo)
2359 {
2360 case server::PowerSupplyRedundancy::Algo::bmcSpecific:
Yong Li83315132019-10-23 17:42:24 +08002361 response.push_back(0);
Cheng C Yang773703a2019-08-15 09:41:11 +08002362 break;
2363 case server::PowerSupplyRedundancy::Algo::userSpecific:
Yong Li83315132019-10-23 17:42:24 +08002364 response.push_back(1);
Cheng C Yang773703a2019-08-15 09:41:11 +08002365 break;
2366 default:
2367 phosphor::logging::log<phosphor::logging::level::ERR>(
2368 "Error to get valid algo");
2369 return ipmi::responseResponseError();
2370 }
2371
2372 if (getCRConfig(ctx, "RotationRankOrder", value))
2373 {
2374 return ipmi::responseResponseError();
2375 }
2376 std::vector<uint8_t>* pResponse =
2377 std::get_if<std::vector<uint8_t>>(&value);
2378 if (!pResponse)
2379 {
2380 phosphor::logging::log<phosphor::logging::level::ERR>(
2381 "Error to get RotationRankOrder property");
2382 return ipmi::responseResponseError();
2383 }
Yong Li83315132019-10-23 17:42:24 +08002384
Cheng C Yang773703a2019-08-15 09:41:11 +08002385 std::copy(pResponse->begin(), pResponse->end(),
Yong Li83315132019-10-23 17:42:24 +08002386 std::back_inserter(response));
2387
Cheng C Yangf41e3342019-09-10 04:47:23 +08002388 return ipmi::responseSuccess(parameter, response);
Cheng C Yang773703a2019-08-15 09:41:11 +08002389 }
2390 case crParameter::rotationPeriod:
2391 {
2392 if (getCRConfig(ctx, "PeriodOfRotation", value))
2393 {
2394 return ipmi::responseResponseError();
2395 }
2396 uint32_t* pResponse = std::get_if<uint32_t>(&value);
2397 if (!pResponse)
2398 {
2399 phosphor::logging::log<phosphor::logging::level::ERR>(
2400 "Error to get RotationAlgorithm property");
2401 return ipmi::responseResponseError();
2402 }
Cheng C Yangf41e3342019-09-10 04:47:23 +08002403 return ipmi::responseSuccess(parameter, *pResponse);
Cheng C Yang773703a2019-08-15 09:41:11 +08002404 }
2405 case crParameter::numOfPSU:
2406 {
2407 uint8_t numberOfPSU = getPSUCount();
2408 if (!numberOfPSU)
2409 {
2410 return ipmi::responseResponseError();
2411 }
Cheng C Yangf41e3342019-09-10 04:47:23 +08002412 return ipmi::responseSuccess(parameter, numberOfPSU);
Cheng C Yang773703a2019-08-15 09:41:11 +08002413 }
Yong Li19445ab2019-12-20 18:25:29 +08002414 case crParameter::rotationRankOrderEffective:
2415 {
2416 if (getCRConfig(ctx, "RotationRankOrder", value,
2417 "xyz.openbmc_project.PSURedundancy"))
2418 {
2419 return ipmi::responseResponseError();
2420 }
2421 std::vector<uint8_t>* pResponse =
2422 std::get_if<std::vector<uint8_t>>(&value);
2423 if (!pResponse)
2424 {
2425 phosphor::logging::log<phosphor::logging::level::ERR>(
2426 "Error to get effective RotationRankOrder property");
2427 return ipmi::responseResponseError();
2428 }
2429 return ipmi::responseSuccess(parameter, *pResponse);
2430 }
Cheng C Yang773703a2019-08-15 09:41:11 +08002431 default:
2432 {
2433 return ipmi::response(ccParameterNotSupported);
2434 }
2435 }
2436}
2437
Zhu, Yungebe560b02019-04-21 21:19:21 -04002438ipmi::RspType<> ipmiOEMSetFaultIndication(uint8_t sourceId, uint8_t faultType,
2439 uint8_t faultState,
2440 uint8_t faultGroup,
2441 std::array<uint8_t, 8>& ledStateData)
2442{
Zhu, Yungebe560b02019-04-21 21:19:21 -04002443 constexpr auto maxFaultType = static_cast<size_t>(RemoteFaultType::max);
2444 static const std::array<std::string, maxFaultType> faultNames = {
2445 "faultFan", "faultTemp", "faultPower",
2446 "faultDriveSlot", "faultSoftware", "faultMemory"};
Zhu, Yungebe560b02019-04-21 21:19:21 -04002447
2448 constexpr uint8_t maxFaultSource = 0x4;
2449 constexpr uint8_t skipLEDs = 0xFF;
2450 constexpr uint8_t pinSize = 64;
2451 constexpr uint8_t groupSize = 16;
Zhikui Rence4e73f2019-12-06 13:59:47 -08002452 constexpr uint8_t groupNum = 5; // 4 for fault memory, 1 for faultFan
Zhu, Yungebe560b02019-04-21 21:19:21 -04002453
Zhikui Rence4e73f2019-12-06 13:59:47 -08002454 // same pin names need to be defined in dts file
2455 static const std::array<std::array<std::string, groupSize>, groupNum>
2456 faultLedPinNames = {{
2457 "LED_CPU1_CH1_DIMM1_FAULT",
2458 "LED_CPU1_CH1_DIMM2_FAULT",
2459 "LED_CPU1_CH2_DIMM1_FAULT",
2460 "LED_CPU1_CH2_DIMM2_FAULT",
2461 "LED_CPU1_CH3_DIMM1_FAULT",
2462 "LED_CPU1_CH3_DIMM2_FAULT",
2463 "LED_CPU1_CH4_DIMM1_FAULT",
2464 "LED_CPU1_CH4_DIMM2_FAULT",
2465 "LED_CPU1_CH5_DIMM1_FAULT",
2466 "LED_CPU1_CH5_DIMM2_FAULT",
2467 "LED_CPU1_CH6_DIMM1_FAULT",
2468 "LED_CPU1_CH6_DIMM2_FAULT",
2469 "",
2470 "",
2471 "",
2472 "", // end of group1
2473 "LED_CPU2_CH1_DIMM1_FAULT",
2474 "LED_CPU2_CH1_DIMM2_FAULT",
2475 "LED_CPU2_CH2_DIMM1_FAULT",
2476 "LED_CPU2_CH2_DIMM2_FAULT",
2477 "LED_CPU2_CH3_DIMM1_FAULT",
2478 "LED_CPU2_CH3_DIMM2_FAULT",
2479 "LED_CPU2_CH4_DIMM1_FAULT",
2480 "LED_CPU2_CH4_DIMM2_FAULT",
2481 "LED_CPU2_CH5_DIMM1_FAULT",
2482 "LED_CPU2_CH5_DIMM2_FAULT",
2483 "LED_CPU2_CH6_DIMM1_FAULT",
2484 "LED_CPU2_CH6_DIMM2_FAULT",
2485 "",
2486 "",
2487 "",
2488 "", // endof group2
2489 "LED_CPU3_CH1_DIMM1_FAULT",
2490 "LED_CPU3_CH1_DIMM2_FAULT",
2491 "LED_CPU3_CH2_DIMM1_FAULT",
2492 "LED_CPU3_CH2_DIMM2_FAULT",
2493 "LED_CPU3_CH3_DIMM1_FAULT",
2494 "LED_CPU3_CH3_DIMM2_FAULT",
2495 "LED_CPU3_CH4_DIMM1_FAULT",
2496 "LED_CPU3_CH4_DIMM2_FAULT",
2497 "LED_CPU3_CH5_DIMM1_FAULT",
2498 "LED_CPU3_CH5_DIMM2_FAULT",
2499 "LED_CPU3_CH6_DIMM1_FAULT",
2500 "LED_CPU3_CH6_DIMM2_FAULT",
2501 "",
2502 "",
2503 "",
2504 "", // end of group3
2505 "LED_CPU4_CH1_DIMM1_FAULT",
2506 "LED_CPU4_CH1_DIMM2_FAULT",
2507 "LED_CPU4_CH2_DIMM1_FAULT",
2508 "LED_CPU4_CH2_DIMM2_FAULT",
2509 "LED_CPU4_CH3_DIMM1_FAULT",
2510 "LED_CPU4_CH3_DIMM2_FAULT",
2511 "LED_CPU4_CH4_DIMM1_FAULT",
2512 "LED_CPU4_CH4_DIMM2_FAULT",
2513 "LED_CPU4_CH5_DIMM1_FAULT",
2514 "LED_CPU4_CH5_DIMM2_FAULT",
2515 "LED_CPU4_CH6_DIMM1_FAULT",
2516 "LED_CPU4_CH6_DIMM2_FAULT",
2517 "",
2518 "",
2519 "",
2520 "", // end of group4
2521 "LED_FAN1_FAULT",
2522 "LED_FAN2_FAULT",
2523 "LED_FAN3_FAULT",
2524 "LED_FAN4_FAULT",
2525 "LED_FAN5_FAULT",
2526 "LED_FAN6_FAULT",
2527 "LED_FAN7_FAULT",
2528 "LED_FAN8_FAULT",
2529 "",
2530 "",
2531 "",
2532 "",
2533 "",
2534 "",
2535 "",
2536 "" // end of group5
2537 }};
Zhu, Yungebe560b02019-04-21 21:19:21 -04002538
Zhikui Rence4e73f2019-12-06 13:59:47 -08002539 // Validate the source, fault type --
2540 // (Byte 1) sourceId: Unspecified, Hot-Swap Controller 0, Hot-Swap
2541 // Controller 1, BIOS (Byte 2) fault type: fan, temperature, power,
2542 // driveslot, software, memory (Byte 3) FaultState: OK, Degraded,
2543 // Non-Critical, Critical, Non-Recoverable, (Byte 4) is faultGroup,
2544 // definition differs based on fault type (Byte 2)
2545 // Type Fan=> Group: 0=FanGroupID, FF-not used
2546 // Byte 5-11 00h, not used
2547 // Byte12 FanLedState [7:0]-Fans 7:0
2548 // Type Memory=> Group: 0 = DIMM GroupID, FF-not used
2549 // Byte 5:12 - DIMM LED state (64bit field, LS Byte first)
2550 // [63:48] = CPU4 channels 7:0, 2 bits per channel
2551 // [47:32] = CPU3 channels 7:0, 2 bits per channel
2552 // [31:16] = CPU2 channels 7:0, 2 bits per channel
2553 // [15:0] = CPU1 channels 7:0, 2 bits per channel
2554 // Type Other=> Component Fault LED Group ID, not used set to 0xFF
2555 // Byte[5:12]: reserved 0x00h
Zhu, Yungebe560b02019-04-21 21:19:21 -04002556 if ((sourceId >= maxFaultSource) ||
2557 (faultType >= static_cast<int8_t>(RemoteFaultType::max)) ||
2558 (faultState >= static_cast<int8_t>(RemoteFaultState::maxFaultState)) ||
2559 (faultGroup >= static_cast<int8_t>(DimmFaultType::maxFaultGroup)))
2560 {
2561 return ipmi::responseParmOutOfRange();
2562 }
2563
Zhikui Rence4e73f2019-12-06 13:59:47 -08002564 size_t pinGroupOffset = 0;
2565 size_t pinGroupMax = pinSize / groupSize;
2566 if (RemoteFaultType::fan == RemoteFaultType(faultType))
Zhu, Yungebe560b02019-04-21 21:19:21 -04002567 {
Zhikui Rence4e73f2019-12-06 13:59:47 -08002568 pinGroupOffset = 4;
2569 pinGroupMax = groupNum - pinSize / groupSize;
Zhu, Yungebe560b02019-04-21 21:19:21 -04002570 }
2571
2572 switch (RemoteFaultType(faultType))
2573 {
2574 case (RemoteFaultType::fan):
2575 case (RemoteFaultType::memory):
2576 {
2577 if (faultGroup == skipLEDs)
2578 {
2579 return ipmi::responseSuccess();
2580 }
Zhu, Yungebe560b02019-04-21 21:19:21 -04002581 // calculate led state bit filed count, each byte has 8bits
2582 // the maximum bits will be 8 * 8 bits
2583 constexpr uint8_t size = sizeof(ledStateData) * 8;
Zhikui Rence4e73f2019-12-06 13:59:47 -08002584
2585 // assemble ledState
2586 uint64_t ledState = 0;
2587 bool hasError = false;
Zhu, Yungebe560b02019-04-21 21:19:21 -04002588 for (int i = 0; i < sizeof(ledStateData); i++)
2589 {
2590 ledState = (uint64_t)(ledState << 8);
2591 ledState = (uint64_t)(ledState | (uint64_t)ledStateData[i]);
2592 }
Zhu, Yungebe560b02019-04-21 21:19:21 -04002593 std::bitset<size> ledStateBits(ledState);
Zhu, Yungebe560b02019-04-21 21:19:21 -04002594
Zhikui Rence4e73f2019-12-06 13:59:47 -08002595 for (int group = 0; group < pinGroupMax; group++)
2596 {
2597 for (int i = 0; i < groupSize; i++)
2598 { // skip non-existing pins
2599 if (0 == faultLedPinNames[group + pinGroupOffset][i].size())
2600 {
2601 continue;
2602 }
Zhu, Yungebe560b02019-04-21 21:19:21 -04002603
Zhikui Rence4e73f2019-12-06 13:59:47 -08002604 gpiod::line line = gpiod::find_line(
2605 faultLedPinNames[group + pinGroupOffset][i]);
2606 if (!line)
2607 {
2608 phosphor::logging::log<phosphor::logging::level::ERR>(
2609 "Not Find Led Gpio Device!",
2610 phosphor::logging::entry(
2611 "DEVICE=%s",
2612 faultLedPinNames[group + pinGroupOffset][i]
2613 .c_str()));
2614 hasError = true;
2615 continue;
2616 }
Zhu, Yungebe560b02019-04-21 21:19:21 -04002617
Zhikui Rence4e73f2019-12-06 13:59:47 -08002618 bool activeHigh =
2619 (line.active_state() == gpiod::line::ACTIVE_HIGH);
2620 try
2621 {
2622 line.request(
2623 {"faultLed", gpiod::line_request::DIRECTION_OUTPUT,
2624 activeHigh
2625 ? 0
2626 : gpiod::line_request::FLAG_ACTIVE_LOW});
2627 line.set_value(ledStateBits[i + group * groupSize]);
2628 }
2629 catch (std::system_error&)
2630 {
2631 phosphor::logging::log<phosphor::logging::level::ERR>(
2632 "Error write Led Gpio Device!",
2633 phosphor::logging::entry(
2634 "DEVICE=%s",
2635 faultLedPinNames[group + pinGroupOffset][i]
2636 .c_str()));
2637 hasError = true;
2638 continue;
2639 }
2640 } // for int i
2641 }
2642 if (hasError)
2643 {
2644 return ipmi::responseResponseError();
Zhu, Yungebe560b02019-04-21 21:19:21 -04002645 }
2646 break;
2647 }
2648 default:
2649 {
2650 // now only support two fault types
2651 return ipmi::responseParmOutOfRange();
2652 }
Zhikui Rence4e73f2019-12-06 13:59:47 -08002653 } // switch
Zhu, Yungebe560b02019-04-21 21:19:21 -04002654 return ipmi::responseSuccess();
2655}
2656
Richard Marian Thomaiyarea537d52019-04-24 21:33:48 +05302657ipmi::RspType<uint8_t> ipmiOEMReadBoardProductId()
2658{
2659 uint8_t prodId = 0;
2660 try
2661 {
Vernon Mauery15419dd2019-05-24 09:40:30 -07002662 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Richard Marian Thomaiyarea537d52019-04-24 21:33:48 +05302663 const DbusObjectInfo& object = getDbusObject(
Vernon Mauery15419dd2019-05-24 09:40:30 -07002664 *dbus, "xyz.openbmc_project.Inventory.Item.Board",
Richard Marian Thomaiyarea537d52019-04-24 21:33:48 +05302665 "/xyz/openbmc_project/inventory/system/board/", "Baseboard");
2666 const Value& propValue = getDbusProperty(
Vernon Mauery15419dd2019-05-24 09:40:30 -07002667 *dbus, object.second, object.first,
Suryakanth Sekar6c57e5c2020-01-10 17:11:58 +05302668 "xyz.openbmc_project.Inventory.Item.Board.Motherboard",
2669 "ProductId");
Richard Marian Thomaiyarea537d52019-04-24 21:33:48 +05302670 prodId = static_cast<uint8_t>(std::get<uint64_t>(propValue));
2671 }
2672 catch (std::exception& e)
2673 {
2674 phosphor::logging::log<phosphor::logging::level::ERR>(
2675 "ipmiOEMReadBoardProductId: Product ID read failed!",
2676 phosphor::logging::entry("ERR=%s", e.what()));
2677 }
2678 return ipmi::responseSuccess(prodId);
2679}
2680
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05302681/** @brief implements the get security mode command
2682 * @param ctx - ctx pointer
2683 *
2684 * @returns IPMI completion code with following data
2685 * - restriction mode value - As specified in
2686 * xyz.openbmc_project.Control.Security.RestrictionMode.interface.yaml
2687 * - special mode value - As specified in
2688 * xyz.openbmc_project.Control.Security.SpecialMode.interface.yaml
2689 */
2690ipmi::RspType<uint8_t, uint8_t> ipmiGetSecurityMode(ipmi::Context::ptr ctx)
2691{
2692 namespace securityNameSpace =
2693 sdbusplus::xyz::openbmc_project::Control::Security::server;
2694 uint8_t restrictionModeValue = 0;
2695 uint8_t specialModeValue = 0;
2696
2697 boost::system::error_code ec;
2698 auto varRestrMode = ctx->bus->yield_method_call<std::variant<std::string>>(
James Feist28c72902019-09-16 10:34:07 -07002699 ctx->yield, ec, restricionModeService, restricionModeBasePath,
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05302700 dBusPropertyIntf, dBusPropertyGetMethod, restricionModeIntf,
2701 restricionModeProperty);
2702 if (ec)
2703 {
2704 phosphor::logging::log<phosphor::logging::level::ERR>(
2705 "ipmiGetSecurityMode: failed to get RestrictionMode property",
2706 phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
2707 return ipmi::responseUnspecifiedError();
2708 }
2709 restrictionModeValue = static_cast<uint8_t>(
2710 securityNameSpace::RestrictionMode::convertModesFromString(
2711 std::get<std::string>(varRestrMode)));
Richard Marian Thomaiyar8d4f8d72019-11-11 12:06:40 +05302712 auto varSpecialMode =
2713 ctx->bus->yield_method_call<std::variant<std::string>>(
2714 ctx->yield, ec, specialModeService, specialModeBasePath,
2715 dBusPropertyIntf, dBusPropertyGetMethod, specialModeIntf,
2716 specialModeProperty);
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05302717 if (ec)
2718 {
2719 phosphor::logging::log<phosphor::logging::level::ERR>(
2720 "ipmiGetSecurityMode: failed to get SpecialMode property",
2721 phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
2722 // fall through, let us not worry about SpecialMode property, which is
2723 // not required in user scenario
2724 }
2725 else
2726 {
Richard Marian Thomaiyar8d4f8d72019-11-11 12:06:40 +05302727 specialModeValue = static_cast<uint8_t>(
2728 securityNameSpace::SpecialMode::convertModesFromString(
2729 std::get<std::string>(varSpecialMode)));
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05302730 }
2731 return ipmi::responseSuccess(restrictionModeValue, specialModeValue);
2732}
2733
2734/** @brief implements the set security mode command
2735 * Command allows to upgrade the restriction mode and won't allow
2736 * to downgrade from system interface
2737 * @param ctx - ctx pointer
2738 * @param restrictionMode - restriction mode value to be set.
2739 *
2740 * @returns IPMI completion code
2741 */
2742ipmi::RspType<> ipmiSetSecurityMode(ipmi::Context::ptr ctx,
Richard Marian Thomaiyar10791062019-11-11 12:19:53 +05302743 uint8_t restrictionMode,
2744 std::optional<uint8_t> specialMode)
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05302745{
Richard Marian Thomaiyar10791062019-11-11 12:19:53 +05302746#ifndef BMC_VALIDATION_UNSECURE_FEATURE
2747 if (specialMode)
2748 {
2749 return ipmi::responseReqDataLenInvalid();
2750 }
2751#endif
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05302752 namespace securityNameSpace =
2753 sdbusplus::xyz::openbmc_project::Control::Security::server;
2754
2755 ChannelInfo chInfo;
2756 if (getChannelInfo(ctx->channel, chInfo) != ccSuccess)
2757 {
2758 phosphor::logging::log<phosphor::logging::level::ERR>(
2759 "ipmiSetSecurityMode: Failed to get Channel Info",
2760 phosphor::logging::entry("CHANNEL=%d", ctx->channel));
2761 return ipmi::responseUnspecifiedError();
2762 }
2763 auto reqMode =
2764 static_cast<securityNameSpace::RestrictionMode::Modes>(restrictionMode);
2765
2766 if ((reqMode < securityNameSpace::RestrictionMode::Modes::Provisioning) ||
2767 (reqMode >
2768 securityNameSpace::RestrictionMode::Modes::ProvisionedHostDisabled))
2769 {
2770 return ipmi::responseInvalidFieldRequest();
2771 }
2772
2773 boost::system::error_code ec;
2774 auto varRestrMode = ctx->bus->yield_method_call<std::variant<std::string>>(
James Feist28c72902019-09-16 10:34:07 -07002775 ctx->yield, ec, restricionModeService, restricionModeBasePath,
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05302776 dBusPropertyIntf, dBusPropertyGetMethod, restricionModeIntf,
2777 restricionModeProperty);
2778 if (ec)
2779 {
2780 phosphor::logging::log<phosphor::logging::level::ERR>(
2781 "ipmiSetSecurityMode: failed to get RestrictionMode property",
2782 phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
2783 return ipmi::responseUnspecifiedError();
2784 }
2785 auto currentRestrictionMode =
2786 securityNameSpace::RestrictionMode::convertModesFromString(
2787 std::get<std::string>(varRestrMode));
2788
2789 if (chInfo.mediumType !=
2790 static_cast<uint8_t>(EChannelMediumType::lan8032) &&
2791 currentRestrictionMode > reqMode)
2792 {
2793 phosphor::logging::log<phosphor::logging::level::ERR>(
2794 "ipmiSetSecurityMode - Downgrading security mode not supported "
2795 "through system interface",
2796 phosphor::logging::entry(
2797 "CUR_MODE=%d", static_cast<uint8_t>(currentRestrictionMode)),
2798 phosphor::logging::entry("REQ_MODE=%d", restrictionMode));
2799 return ipmi::responseCommandNotAvailable();
2800 }
2801
2802 ec.clear();
2803 ctx->bus->yield_method_call<>(
James Feist28c72902019-09-16 10:34:07 -07002804 ctx->yield, ec, restricionModeService, restricionModeBasePath,
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05302805 dBusPropertyIntf, dBusPropertySetMethod, restricionModeIntf,
2806 restricionModeProperty,
2807 static_cast<std::variant<std::string>>(
2808 securityNameSpace::convertForMessage(reqMode)));
2809
2810 if (ec)
2811 {
2812 phosphor::logging::log<phosphor::logging::level::ERR>(
2813 "ipmiSetSecurityMode: failed to set RestrictionMode property",
2814 phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
2815 return ipmi::responseUnspecifiedError();
2816 }
Richard Marian Thomaiyar10791062019-11-11 12:19:53 +05302817
2818#ifdef BMC_VALIDATION_UNSECURE_FEATURE
2819 if (specialMode)
2820 {
2821 ec.clear();
2822 ctx->bus->yield_method_call<>(
2823 ctx->yield, ec, specialModeService, specialModeBasePath,
2824 dBusPropertyIntf, dBusPropertySetMethod, specialModeIntf,
2825 specialModeProperty,
2826 static_cast<std::variant<std::string>>(
2827 securityNameSpace::convertForMessage(
2828 static_cast<securityNameSpace::SpecialMode::Modes>(
2829 specialMode.value()))));
2830
2831 if (ec)
2832 {
2833 phosphor::logging::log<phosphor::logging::level::ERR>(
2834 "ipmiSetSecurityMode: failed to set SpecialMode property",
2835 phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
2836 return ipmi::responseUnspecifiedError();
2837 }
2838 }
2839#endif
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05302840 return ipmi::responseSuccess();
2841}
2842
Vernon Mauery4ac799d2019-05-20 15:50:37 -07002843ipmi::RspType<uint8_t /* restore status */>
2844 ipmiRestoreConfiguration(const std::array<uint8_t, 3>& clr, uint8_t cmd)
2845{
2846 static constexpr std::array<uint8_t, 3> expClr = {'C', 'L', 'R'};
2847
2848 if (clr != expClr)
2849 {
2850 return ipmi::responseInvalidFieldRequest();
2851 }
2852 constexpr uint8_t cmdStatus = 0;
2853 constexpr uint8_t cmdDefaultRestore = 0xaa;
2854 constexpr uint8_t cmdFullRestore = 0xbb;
2855 constexpr uint8_t cmdFormat = 0xcc;
2856
2857 constexpr const char* restoreOpFname = "/tmp/.rwfs/.restore_op";
2858
2859 switch (cmd)
2860 {
2861 case cmdStatus:
2862 break;
2863 case cmdDefaultRestore:
2864 case cmdFullRestore:
2865 case cmdFormat:
2866 {
2867 // write file to rwfs root
2868 int value = (cmd - 1) & 0x03; // map aa, bb, cc => 1, 2, 3
2869 std::ofstream restoreFile(restoreOpFname);
2870 if (!restoreFile)
2871 {
2872 return ipmi::responseUnspecifiedError();
2873 }
2874 restoreFile << value << "\n";
2875 break;
2876 }
2877 default:
2878 return ipmi::responseInvalidFieldRequest();
2879 }
2880
2881 constexpr uint8_t restorePending = 0;
2882 constexpr uint8_t restoreComplete = 1;
2883
2884 uint8_t restoreStatus = std::filesystem::exists(restoreOpFname)
2885 ? restorePending
2886 : restoreComplete;
2887 return ipmi::responseSuccess(restoreStatus);
2888}
2889
Chen Yugang39736d52019-07-12 16:24:33 +08002890ipmi::RspType<uint8_t> ipmiOEMGetNmiSource(void)
2891{
2892 uint8_t bmcSource;
Chen Yugang97cf96e2019-11-01 08:55:11 +08002893 namespace nmi = sdbusplus::xyz::openbmc_project::Chassis::Control::server;
Chen Yugang39736d52019-07-12 16:24:33 +08002894
2895 try
2896 {
2897 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
2898 std::string service =
2899 getService(*dbus, oemNmiSourceIntf, oemNmiSourceObjPath);
2900 Value variant =
2901 getDbusProperty(*dbus, service, oemNmiSourceObjPath,
2902 oemNmiSourceIntf, oemNmiBmcSourceObjPathProp);
2903
2904 switch (nmi::NMISource::convertBMCSourceSignalFromString(
2905 std::get<std::string>(variant)))
2906 {
2907 case nmi::NMISource::BMCSourceSignal::None:
2908 bmcSource = static_cast<uint8_t>(NmiSource::none);
2909 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08002910 case nmi::NMISource::BMCSourceSignal::FrontPanelButton:
2911 bmcSource = static_cast<uint8_t>(NmiSource::frontPanelButton);
Chen Yugang39736d52019-07-12 16:24:33 +08002912 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08002913 case nmi::NMISource::BMCSourceSignal::Watchdog:
2914 bmcSource = static_cast<uint8_t>(NmiSource::watchdog);
Chen Yugang39736d52019-07-12 16:24:33 +08002915 break;
2916 case nmi::NMISource::BMCSourceSignal::ChassisCmd:
2917 bmcSource = static_cast<uint8_t>(NmiSource::chassisCmd);
2918 break;
2919 case nmi::NMISource::BMCSourceSignal::MemoryError:
2920 bmcSource = static_cast<uint8_t>(NmiSource::memoryError);
2921 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08002922 case nmi::NMISource::BMCSourceSignal::PciBusError:
2923 bmcSource = static_cast<uint8_t>(NmiSource::pciBusError);
Chen Yugang39736d52019-07-12 16:24:33 +08002924 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08002925 case nmi::NMISource::BMCSourceSignal::PCH:
2926 bmcSource = static_cast<uint8_t>(NmiSource::pch);
Chen Yugang39736d52019-07-12 16:24:33 +08002927 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08002928 case nmi::NMISource::BMCSourceSignal::Chipset:
2929 bmcSource = static_cast<uint8_t>(NmiSource::chipset);
Chen Yugang39736d52019-07-12 16:24:33 +08002930 break;
2931 default:
2932 phosphor::logging::log<phosphor::logging::level::ERR>(
2933 "NMI source: invalid property!",
2934 phosphor::logging::entry(
2935 "PROP=%s", std::get<std::string>(variant).c_str()));
2936 return ipmi::responseResponseError();
2937 }
2938 }
2939 catch (sdbusplus::exception::SdBusError& e)
2940 {
2941 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
2942 return ipmi::responseResponseError();
2943 }
2944
2945 return ipmi::responseSuccess(bmcSource);
2946}
2947
2948ipmi::RspType<> ipmiOEMSetNmiSource(uint8_t sourceId)
2949{
Chen Yugang97cf96e2019-11-01 08:55:11 +08002950 namespace nmi = sdbusplus::xyz::openbmc_project::Chassis::Control::server;
Chen Yugang39736d52019-07-12 16:24:33 +08002951
2952 nmi::NMISource::BMCSourceSignal bmcSourceSignal =
2953 nmi::NMISource::BMCSourceSignal::None;
2954
2955 switch (NmiSource(sourceId))
2956 {
2957 case NmiSource::none:
2958 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::None;
2959 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08002960 case NmiSource::frontPanelButton:
2961 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::FrontPanelButton;
Chen Yugang39736d52019-07-12 16:24:33 +08002962 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08002963 case NmiSource::watchdog:
2964 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::Watchdog;
Chen Yugang39736d52019-07-12 16:24:33 +08002965 break;
2966 case NmiSource::chassisCmd:
2967 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::ChassisCmd;
2968 break;
2969 case NmiSource::memoryError:
2970 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::MemoryError;
2971 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08002972 case NmiSource::pciBusError:
2973 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::PciBusError;
Chen Yugang39736d52019-07-12 16:24:33 +08002974 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08002975 case NmiSource::pch:
2976 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::PCH;
Chen Yugang39736d52019-07-12 16:24:33 +08002977 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08002978 case NmiSource::chipset:
2979 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::Chipset;
Chen Yugang39736d52019-07-12 16:24:33 +08002980 break;
2981 default:
2982 phosphor::logging::log<phosphor::logging::level::ERR>(
2983 "NMI source: invalid property!");
2984 return ipmi::responseResponseError();
2985 }
2986
2987 try
2988 {
2989 // keep NMI signal source
2990 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
2991 std::string service =
2992 getService(*dbus, oemNmiSourceIntf, oemNmiSourceObjPath);
Chen Yugang97cf96e2019-11-01 08:55:11 +08002993 setDbusProperty(*dbus, service, oemNmiSourceObjPath, oemNmiSourceIntf,
2994 oemNmiBmcSourceObjPathProp,
2995 nmi::convertForMessage(bmcSourceSignal));
Chen Yugang99be6332019-08-09 16:20:48 +08002996 // set Enabled property to inform NMI source handling
2997 // to trigger a NMI_OUT BSOD.
2998 // if it's triggered by NMI source property changed,
2999 // NMI_OUT BSOD could be missed if the same source occurs twice in a row
3000 if (bmcSourceSignal != nmi::NMISource::BMCSourceSignal::None)
3001 {
3002 setDbusProperty(*dbus, service, oemNmiSourceObjPath,
3003 oemNmiSourceIntf, oemNmiEnabledObjPathProp,
3004 static_cast<bool>(true));
3005 }
Chen Yugang39736d52019-07-12 16:24:33 +08003006 }
3007 catch (sdbusplus::exception_t& e)
3008 {
3009 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
3010 return ipmi::responseResponseError();
3011 }
3012
3013 return ipmi::responseSuccess();
3014}
3015
James Feist63efafa2019-07-24 12:39:21 -07003016namespace dimmOffset
3017{
3018constexpr const char* dimmPower = "DimmPower";
3019constexpr const char* staticCltt = "StaticCltt";
3020constexpr const char* offsetPath = "/xyz/openbmc_project/Inventory/Item/Dimm";
3021constexpr const char* offsetInterface =
3022 "xyz.openbmc_project.Inventory.Item.Dimm.Offset";
3023constexpr const char* property = "DimmOffset";
3024
3025}; // namespace dimmOffset
3026
3027ipmi::RspType<>
3028 ipmiOEMSetDimmOffset(uint8_t type,
3029 const std::vector<std::tuple<uint8_t, uint8_t>>& data)
3030{
3031 if (type != static_cast<uint8_t>(dimmOffsetTypes::dimmPower) &&
3032 type != static_cast<uint8_t>(dimmOffsetTypes::staticCltt))
3033 {
3034 return ipmi::responseInvalidFieldRequest();
3035 }
3036
3037 if (data.empty())
3038 {
3039 return ipmi::responseInvalidFieldRequest();
3040 }
3041 nlohmann::json json;
3042
3043 std::ifstream jsonStream(dimmOffsetFile);
3044 if (jsonStream.good())
3045 {
3046 json = nlohmann::json::parse(jsonStream, nullptr, false);
3047 if (json.is_discarded())
3048 {
3049 json = nlohmann::json();
3050 }
3051 jsonStream.close();
3052 }
3053
3054 std::string typeName;
3055 if (type == static_cast<uint8_t>(dimmOffsetTypes::dimmPower))
3056 {
3057 typeName = dimmOffset::dimmPower;
3058 }
3059 else
3060 {
3061 typeName = dimmOffset::staticCltt;
3062 }
3063
3064 nlohmann::json& field = json[typeName];
3065
3066 for (const auto& [index, value] : data)
3067 {
3068 field[index] = value;
3069 }
3070
3071 for (nlohmann::json& val : field)
3072 {
3073 if (val == nullptr)
3074 {
3075 val = static_cast<uint8_t>(0);
3076 }
3077 }
3078
3079 std::ofstream output(dimmOffsetFile);
3080 if (!output.good())
3081 {
3082 std::cerr << "Error writing json file\n";
3083 return ipmi::responseResponseError();
3084 }
3085
3086 output << json.dump(4);
3087
3088 if (type == static_cast<uint8_t>(dimmOffsetTypes::staticCltt))
3089 {
3090 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
3091
3092 std::variant<std::vector<uint8_t>> offsets =
3093 field.get<std::vector<uint8_t>>();
3094 auto call = bus->new_method_call(
3095 settingsBusName, dimmOffset::offsetPath, PROP_INTF, "Set");
3096 call.append(dimmOffset::offsetInterface, dimmOffset::property, offsets);
3097 try
3098 {
3099 bus->call(call);
3100 }
3101 catch (sdbusplus::exception_t& e)
3102 {
3103 phosphor::logging::log<phosphor::logging::level::ERR>(
3104 "ipmiOEMSetDimmOffset: can't set dimm offsets!",
3105 phosphor::logging::entry("ERR=%s", e.what()));
3106 return ipmi::responseResponseError();
3107 }
3108 }
3109
3110 return ipmi::responseSuccess();
3111}
3112
3113ipmi::RspType<uint8_t> ipmiOEMGetDimmOffset(uint8_t type, uint8_t index)
3114{
3115
3116 if (type != static_cast<uint8_t>(dimmOffsetTypes::dimmPower) &&
3117 type != static_cast<uint8_t>(dimmOffsetTypes::staticCltt))
3118 {
3119 return ipmi::responseInvalidFieldRequest();
3120 }
3121
3122 std::ifstream jsonStream(dimmOffsetFile);
3123
3124 auto json = nlohmann::json::parse(jsonStream, nullptr, false);
3125 if (json.is_discarded())
3126 {
3127 std::cerr << "File error in " << dimmOffsetFile << "\n";
3128 return ipmi::responseResponseError();
3129 }
3130
3131 std::string typeName;
3132 if (type == static_cast<uint8_t>(dimmOffsetTypes::dimmPower))
3133 {
3134 typeName = dimmOffset::dimmPower;
3135 }
3136 else
3137 {
3138 typeName = dimmOffset::staticCltt;
3139 }
3140
3141 auto it = json.find(typeName);
3142 if (it == json.end())
3143 {
3144 return ipmi::responseInvalidFieldRequest();
3145 }
3146
3147 if (it->size() <= index)
3148 {
3149 return ipmi::responseInvalidFieldRequest();
3150 }
3151
3152 uint8_t resp = it->at(index).get<uint8_t>();
3153 return ipmi::responseSuccess(resp);
3154}
3155
Chen,Yugang4f7e76b2019-08-20 09:28:06 +08003156namespace boot_options
3157{
3158
3159using namespace sdbusplus::xyz::openbmc_project::Control::Boot::server;
3160using IpmiValue = uint8_t;
3161constexpr auto ipmiDefault = 0;
3162
3163std::map<IpmiValue, Source::Sources> sourceIpmiToDbus = {
3164 {0x01, Source::Sources::Network},
3165 {0x02, Source::Sources::Disk},
3166 {0x05, Source::Sources::ExternalMedia},
3167 {0x0f, Source::Sources::RemovableMedia},
3168 {ipmiDefault, Source::Sources::Default}};
3169
3170std::map<IpmiValue, Mode::Modes> modeIpmiToDbus = {
Chen Yugangca12a7b2019-09-03 18:11:44 +08003171 {0x06, Mode::Modes::Setup}, {ipmiDefault, Mode::Modes::Regular}};
Chen,Yugang4f7e76b2019-08-20 09:28:06 +08003172
3173std::map<Source::Sources, IpmiValue> sourceDbusToIpmi = {
3174 {Source::Sources::Network, 0x01},
3175 {Source::Sources::Disk, 0x02},
3176 {Source::Sources::ExternalMedia, 0x05},
3177 {Source::Sources::RemovableMedia, 0x0f},
3178 {Source::Sources::Default, ipmiDefault}};
3179
3180std::map<Mode::Modes, IpmiValue> modeDbusToIpmi = {
Chen Yugangca12a7b2019-09-03 18:11:44 +08003181 {Mode::Modes::Setup, 0x06}, {Mode::Modes::Regular, ipmiDefault}};
Chen,Yugang4f7e76b2019-08-20 09:28:06 +08003182
3183static constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode";
3184static constexpr auto bootSourceIntf =
3185 "xyz.openbmc_project.Control.Boot.Source";
3186static constexpr auto enabledIntf = "xyz.openbmc_project.Object.Enable";
3187static constexpr auto persistentObjPath =
3188 "/xyz/openbmc_project/control/host0/boot";
3189static constexpr auto oneTimePath =
3190 "/xyz/openbmc_project/control/host0/boot/one_time";
3191static constexpr auto bootSourceProp = "BootSource";
3192static constexpr auto bootModeProp = "BootMode";
3193static constexpr auto oneTimeBootEnableProp = "Enabled";
3194static constexpr auto httpBootMode =
3195 "xyz.openbmc_project.Control.Boot.Source.Sources.Http";
3196
3197enum class BootOptionParameter : size_t
3198{
3199 setInProgress = 0x0,
3200 bootFlags = 0x5,
3201};
3202static constexpr uint8_t setComplete = 0x0;
3203static constexpr uint8_t setInProgress = 0x1;
3204static uint8_t transferStatus = setComplete;
3205static constexpr uint8_t setParmVersion = 0x01;
3206static constexpr uint8_t setParmBootFlagsPermanent = 0x40;
3207static constexpr uint8_t setParmBootFlagsValidOneTime = 0x80;
3208static constexpr uint8_t setParmBootFlagsValidPermanent = 0xC0;
3209static constexpr uint8_t httpBoot = 0xd;
3210static constexpr uint8_t bootSourceMask = 0x3c;
3211
3212} // namespace boot_options
3213
3214ipmi::RspType<uint8_t, // version
3215 uint8_t, // param
3216 uint8_t, // data0, dependent on parameter
3217 std::optional<uint8_t> // data1, dependent on parameter
3218 >
3219 ipmiOemGetEfiBootOptions(uint8_t parameter, uint8_t set, uint8_t block)
3220{
3221 using namespace boot_options;
3222 uint8_t bootOption = 0;
3223
3224 if (parameter == static_cast<uint8_t>(BootOptionParameter::setInProgress))
3225 {
3226 return ipmi::responseSuccess(setParmVersion, parameter, transferStatus,
3227 std::nullopt);
3228 }
3229
3230 if (parameter != static_cast<uint8_t>(BootOptionParameter::bootFlags))
3231 {
3232 phosphor::logging::log<phosphor::logging::level::ERR>(
3233 "Unsupported parameter");
3234 return ipmi::responseResponseError();
3235 }
3236
3237 try
3238 {
3239 auto oneTimeEnabled = false;
3240 // read one time Enabled property
3241 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
3242 std::string service = getService(*dbus, enabledIntf, oneTimePath);
3243 Value variant = getDbusProperty(*dbus, service, oneTimePath,
3244 enabledIntf, oneTimeBootEnableProp);
3245 oneTimeEnabled = std::get<bool>(variant);
3246
3247 // get BootSource and BootMode properties
3248 // according to oneTimeEnable
3249 auto bootObjPath = oneTimePath;
3250 if (oneTimeEnabled == false)
3251 {
3252 bootObjPath = persistentObjPath;
3253 }
3254
3255 service = getService(*dbus, bootModeIntf, bootObjPath);
3256 variant = getDbusProperty(*dbus, service, bootObjPath, bootModeIntf,
3257 bootModeProp);
3258
3259 auto bootMode =
3260 Mode::convertModesFromString(std::get<std::string>(variant));
3261
3262 service = getService(*dbus, bootSourceIntf, bootObjPath);
3263 variant = getDbusProperty(*dbus, service, bootObjPath, bootSourceIntf,
3264 bootSourceProp);
3265
3266 if (std::get<std::string>(variant) == httpBootMode)
3267 {
3268 bootOption = httpBoot;
3269 }
3270 else
3271 {
3272 auto bootSource = Source::convertSourcesFromString(
3273 std::get<std::string>(variant));
3274 bootOption = sourceDbusToIpmi.at(bootSource);
3275 if (Source::Sources::Default == bootSource)
3276 {
3277 bootOption = modeDbusToIpmi.at(bootMode);
3278 }
3279 }
3280
3281 uint8_t oneTime = oneTimeEnabled ? setParmBootFlagsValidOneTime
3282 : setParmBootFlagsValidPermanent;
3283 bootOption <<= 2; // shift for responseconstexpr
3284 return ipmi::responseSuccess(setParmVersion, parameter, oneTime,
3285 bootOption);
3286 }
3287 catch (sdbusplus::exception_t& e)
3288 {
3289 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
3290 return ipmi::responseResponseError();
3291 }
3292}
3293
3294ipmi::RspType<> ipmiOemSetEfiBootOptions(uint8_t bootFlag, uint8_t bootParam,
3295 std::optional<uint8_t> bootOption)
3296{
3297 using namespace boot_options;
3298 auto oneTimeEnabled = false;
3299
3300 if (bootFlag == static_cast<uint8_t>(BootOptionParameter::setInProgress))
3301 {
3302 if (bootOption)
3303 {
3304 return ipmi::responseReqDataLenInvalid();
3305 }
3306
3307 if (transferStatus == setInProgress)
3308 {
3309 phosphor::logging::log<phosphor::logging::level::ERR>(
3310 "boot option set in progress!");
3311 return ipmi::responseResponseError();
3312 }
3313
3314 transferStatus = bootParam;
3315 return ipmi::responseSuccess();
3316 }
3317
3318 if (bootFlag != (uint8_t)BootOptionParameter::bootFlags)
3319 {
3320 phosphor::logging::log<phosphor::logging::level::ERR>(
3321 "Unsupported parameter");
3322 return ipmi::responseResponseError();
3323 }
3324
3325 if (!bootOption)
3326 {
3327 return ipmi::responseReqDataLenInvalid();
3328 }
3329
3330 if (((bootOption.value() & bootSourceMask) >> 2) !=
3331 httpBoot) // not http boot, exit
3332 {
3333 phosphor::logging::log<phosphor::logging::level::ERR>(
3334 "wrong boot option parameter!");
3335 return ipmi::responseParmOutOfRange();
3336 }
3337
3338 try
3339 {
3340 bool permanent = (bootParam & setParmBootFlagsPermanent) ==
3341 setParmBootFlagsPermanent;
3342
3343 // read one time Enabled property
3344 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
3345 std::string service = getService(*dbus, enabledIntf, oneTimePath);
3346 Value variant = getDbusProperty(*dbus, service, oneTimePath,
3347 enabledIntf, oneTimeBootEnableProp);
3348 oneTimeEnabled = std::get<bool>(variant);
3349
3350 /*
3351 * Check if the current boot setting is onetime or permanent, if the
3352 * request in the command is otherwise, then set the "Enabled"
3353 * property in one_time object path to 'True' to indicate onetime
3354 * and 'False' to indicate permanent.
3355 *
3356 * Once the onetime/permanent setting is applied, then the bootMode
3357 * and bootSource is updated for the corresponding object.
3358 */
3359 if (permanent == oneTimeEnabled)
3360 {
3361 setDbusProperty(*dbus, service, oneTimePath, enabledIntf,
3362 oneTimeBootEnableProp, !permanent);
3363 }
3364
3365 // set BootSource and BootMode properties
3366 // according to oneTimeEnable or persistent
3367 auto bootObjPath = oneTimePath;
3368 if (oneTimeEnabled == false)
3369 {
3370 bootObjPath = persistentObjPath;
3371 }
3372 std::string bootMode =
3373 "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular";
3374 std::string bootSource = httpBootMode;
3375
3376 service = getService(*dbus, bootModeIntf, bootObjPath);
3377 setDbusProperty(*dbus, service, bootObjPath, bootModeIntf, bootModeProp,
3378 bootMode);
3379
3380 service = getService(*dbus, bootSourceIntf, bootObjPath);
3381 setDbusProperty(*dbus, service, bootObjPath, bootSourceIntf,
3382 bootSourceProp, bootSource);
3383 }
3384 catch (sdbusplus::exception_t& e)
3385 {
3386 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
3387 return ipmi::responseResponseError();
3388 }
3389
3390 return ipmi::responseSuccess();
3391}
3392
Cheng C Yang4e6ee152019-09-25 10:27:44 +08003393using BasicVariantType =
3394 std::variant<std::vector<std::string>, std::vector<uint64_t>, std::string,
3395 int64_t, uint64_t, double, int32_t, uint32_t, int16_t,
3396 uint16_t, uint8_t, bool>;
3397using PropertyMapType =
3398 boost::container::flat_map<std::string, BasicVariantType>;
3399static constexpr const std::array<const char*, 1> psuPresenceTypes = {
3400 "xyz.openbmc_project.Configuration.PSUPresence"};
3401int getPSUAddress(ipmi::Context::ptr ctx, uint8_t& bus,
3402 std::vector<uint64_t>& addrTable)
3403{
3404 boost::system::error_code ec;
3405 GetSubTreeType subtree = ctx->bus->yield_method_call<GetSubTreeType>(
3406 ctx->yield, ec, "xyz.openbmc_project.ObjectMapper",
3407 "/xyz/openbmc_project/object_mapper",
3408 "xyz.openbmc_project.ObjectMapper", "GetSubTree",
3409 "/xyz/openbmc_project/inventory/system", 3, psuPresenceTypes);
3410 if (ec)
3411 {
3412 phosphor::logging::log<phosphor::logging::level::ERR>(
3413 "Failed to set dbus property to cold redundancy");
3414 return -1;
3415 }
3416 for (const auto& object : subtree)
3417 {
3418 std::string pathName = object.first;
3419 for (const auto& serviceIface : object.second)
3420 {
3421 std::string serviceName = serviceIface.first;
3422
3423 ec.clear();
3424 PropertyMapType propMap =
3425 ctx->bus->yield_method_call<PropertyMapType>(
3426 ctx->yield, ec, serviceName, pathName,
3427 "org.freedesktop.DBus.Properties", "GetAll",
3428 "xyz.openbmc_project.Configuration.PSUPresence");
3429 if (ec)
3430 {
3431 phosphor::logging::log<phosphor::logging::level::ERR>(
3432 "Failed to set dbus property to cold redundancy");
3433 return -1;
3434 }
3435 auto psuBus = std::get_if<uint64_t>(&propMap["Bus"]);
3436 auto psuAddress =
3437 std::get_if<std::vector<uint64_t>>(&propMap["Address"]);
3438
3439 if (psuBus == nullptr || psuAddress == nullptr)
3440 {
3441 std::cerr << "error finding necessary "
3442 "entry in configuration\n";
3443 return -1;
3444 }
3445 bus = static_cast<uint8_t>(*psuBus);
3446 addrTable = *psuAddress;
3447 return 0;
3448 }
3449 }
3450 return -1;
3451}
3452
3453static const constexpr uint8_t addrOffset = 8;
3454static const constexpr uint8_t psuRevision = 0xd9;
3455static const constexpr uint8_t defaultPSUBus = 7;
3456// Second Minor, Primary Minor, Major
3457static const constexpr size_t verLen = 3;
3458ipmi::RspType<std::vector<uint8_t>> ipmiOEMGetPSUVersion(ipmi::Context::ptr ctx)
3459{
3460 uint8_t bus = defaultPSUBus;
3461 std::vector<uint64_t> addrTable;
3462 std::vector<uint8_t> result;
3463 if (getPSUAddress(ctx, bus, addrTable))
3464 {
3465 std::cerr << "Failed to get PSU bus and address\n";
3466 return ipmi::responseResponseError();
3467 }
3468
3469 for (const auto& slaveAddr : addrTable)
3470 {
3471 std::vector<uint8_t> writeData = {psuRevision};
3472 std::vector<uint8_t> readBuf(verLen);
3473 uint8_t addr = static_cast<uint8_t>(slaveAddr) + addrOffset;
3474 std::string i2cBus = "/dev/i2c-" + std::to_string(bus);
3475
3476 auto retI2C = ipmi::i2cWriteRead(i2cBus, addr, writeData, readBuf);
3477 if (retI2C != ipmi::ccSuccess)
3478 {
3479 for (size_t idx = 0; idx < verLen; idx++)
3480 {
3481 result.emplace_back(0x00);
3482 }
3483 }
3484 else
3485 {
3486 for (const uint8_t& data : readBuf)
3487 {
3488 result.emplace_back(data);
3489 }
3490 }
3491 }
3492
3493 return ipmi::responseSuccess(result);
3494}
3495
AppaRao Puli28972062019-11-11 02:04:45 +05303496/** @brief implements the maximum size of
3497 * bridgeable messages used between KCS and
3498 * IPMB interfacesget security mode command.
3499 *
3500 * @returns IPMI completion code with following data
3501 * - KCS Buffer Size (In multiples of four bytes)
3502 * - IPMB Buffer Size (In multiples of four bytes)
3503 **/
3504ipmi::RspType<uint8_t, uint8_t> ipmiOEMGetBufferSize()
3505{
3506 // for now this is hard coded; really this number is dependent on
3507 // the BMC kcs driver as well as the host kcs driver....
3508 // we can't know the latter.
3509 uint8_t kcsMaxBufferSize = 63 / 4;
3510 uint8_t ipmbMaxBufferSize = 128 / 4;
3511
3512 return ipmi::responseSuccess(kcsMaxBufferSize, ipmbMaxBufferSize);
3513}
3514
Jason M. Bills64796042018-10-03 16:51:55 -07003515static void registerOEMFunctions(void)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +08003516{
3517 phosphor::logging::log<phosphor::logging::level::INFO>(
3518 "Registering OEM commands");
Vernon Mauery98bbf692019-09-16 11:14:59 -07003519 ipmiPrintAndRegister(intel::netFnGeneral, IPMI_CMD_WILDCARD, NULL,
Jason M. Bills64796042018-10-03 16:51:55 -07003520 ipmiOEMWildcard,
3521 PRIVILEGE_USER); // wildcard default handler
Vernon Mauery98bbf692019-09-16 11:14:59 -07003522
3523 ipmiPrintAndRegister(intel::netFnApp, IPMI_CMD_WILDCARD, NULL,
Jason M. Bills64796042018-10-03 16:51:55 -07003524 ipmiOEMWildcard,
3525 PRIVILEGE_USER); // wildcard default handler
Vernon Mauery98bbf692019-09-16 11:14:59 -07003526
3527 ipmiPrintAndRegister(intel::netFnGeneral,
3528 intel::general::cmdGetChassisIdentifier, NULL,
3529 ipmiOEMGetChassisIdentifier,
3530 PRIVILEGE_USER); // get chassis identifier
3531
3532 ipmiPrintAndRegister(intel::netFnGeneral, intel::general::cmdSetSystemGUID,
3533 NULL, ipmiOEMSetSystemGUID,
3534 PRIVILEGE_ADMIN); // set system guid
Jason M. Billsb02bf092019-08-15 13:01:56 -07003535
3536 // <Disable BMC System Reset Action>
Vernon Mauery98bbf692019-09-16 11:14:59 -07003537 registerHandler(prioOemBase, intel::netFnGeneral,
3538 intel::general::cmdDisableBMCSystemReset, Privilege::Admin,
3539 ipmiOEMDisableBMCSystemReset);
3540
Jason M. Billsb02bf092019-08-15 13:01:56 -07003541 // <Get BMC Reset Disables>
Vernon Mauery98bbf692019-09-16 11:14:59 -07003542 registerHandler(prioOemBase, intel::netFnGeneral,
3543 intel::general::cmdGetBMCResetDisables, Privilege::Admin,
3544 ipmiOEMGetBMCResetDisables);
Jason M. Billsb02bf092019-08-15 13:01:56 -07003545
Vernon Mauery98bbf692019-09-16 11:14:59 -07003546 ipmiPrintAndRegister(intel::netFnGeneral, intel::general::cmdSetBIOSID,
3547 NULL, ipmiOEMSetBIOSID, PRIVILEGE_ADMIN);
Jia, Chunhuicc49b542019-03-20 15:41:07 +08003548
Chen Yugang7a04f3a2019-10-08 11:12:35 +08003549 registerHandler(prioOemBase, intel::netFnGeneral,
3550 intel::general::cmdGetOEMDeviceInfo, Privilege::User,
3551 ipmiOEMGetDeviceInfo);
Jia, Chunhuicc49b542019-03-20 15:41:07 +08003552
Vernon Mauery98bbf692019-09-16 11:14:59 -07003553 ipmiPrintAndRegister(intel::netFnGeneral,
3554 intel::general::cmdGetAICSlotFRUIDSlotPosRecords, NULL,
3555 ipmiOEMGetAICFRU, PRIVILEGE_USER);
Suryakanth Sekard509eb92018-11-15 17:44:11 +05303556
Vernon Mauery98bbf692019-09-16 11:14:59 -07003557 registerHandler(prioOpenBmcBase, intel::netFnGeneral,
3558 intel::general::cmdSendEmbeddedFWUpdStatus,
3559 Privilege::Operator, ipmiOEMSendEmbeddedFwUpdStatus);
Suryakanth Sekard509eb92018-11-15 17:44:11 +05303560
Vernon Mauery98bbf692019-09-16 11:14:59 -07003561 ipmiPrintAndRegister(intel::netFnGeneral,
3562 intel::general::cmdSetPowerRestoreDelay, NULL,
3563 ipmiOEMSetPowerRestoreDelay, PRIVILEGE_OPERATOR);
3564
3565 ipmiPrintAndRegister(intel::netFnGeneral,
3566 intel::general::cmdGetPowerRestoreDelay, NULL,
3567 ipmiOEMGetPowerRestoreDelay, PRIVILEGE_USER);
3568
3569 registerHandler(prioOpenBmcBase, intel::netFnGeneral,
3570 intel::general::cmdSetOEMUser2Activation,
3571 Privilege::Callback, ipmiOEMSetUser2Activation);
3572
3573 registerHandler(prioOpenBmcBase, intel::netFnGeneral,
3574 intel::general::cmdSetSpecialUserPassword,
3575 Privilege::Callback, ipmiOEMSetSpecialUserPassword);
Richard Marian Thomaiyarfc5e9852019-04-14 15:06:27 +05303576
Jason M. Bills42bd9c82019-06-28 16:39:34 -07003577 // <Get Processor Error Config>
Vernon Mauery98bbf692019-09-16 11:14:59 -07003578 registerHandler(prioOemBase, intel::netFnGeneral,
3579 intel::general::cmdGetProcessorErrConfig, Privilege::User,
3580 ipmiOEMGetProcessorErrConfig);
3581
Jason M. Bills42bd9c82019-06-28 16:39:34 -07003582 // <Set Processor Error Config>
Vernon Mauery98bbf692019-09-16 11:14:59 -07003583 registerHandler(prioOemBase, intel::netFnGeneral,
3584 intel::general::cmdSetProcessorErrConfig, Privilege::Admin,
3585 ipmiOEMSetProcessorErrConfig);
Jason M. Bills42bd9c82019-06-28 16:39:34 -07003586
Vernon Mauery98bbf692019-09-16 11:14:59 -07003587 ipmiPrintAndRegister(intel::netFnGeneral,
3588 intel::general::cmdSetShutdownPolicy, NULL,
3589 ipmiOEMSetShutdownPolicy, PRIVILEGE_ADMIN);
James Feist91244a62019-02-19 15:04:54 -08003590
Vernon Mauery98bbf692019-09-16 11:14:59 -07003591 ipmiPrintAndRegister(intel::netFnGeneral,
3592 intel::general::cmdGetShutdownPolicy, NULL,
3593 ipmiOEMGetShutdownPolicy, PRIVILEGE_ADMIN);
James Feist91244a62019-02-19 15:04:54 -08003594
anil kumar appanaf945eee2019-09-25 23:29:11 +00003595 registerHandler(prioOemBase, intel::netFnGeneral,
3596 intel::general::cmdSetFanConfig, Privilege::User,
3597 ipmiOEMSetFanConfig);
James Feist91244a62019-02-19 15:04:54 -08003598
Vernon Mauery98bbf692019-09-16 11:14:59 -07003599 registerHandler(prioOemBase, intel::netFnGeneral,
3600 intel::general::cmdGetFanConfig, Privilege::User,
3601 ipmiOEMGetFanConfig);
James Feist5f957ca2019-03-14 15:33:55 -07003602
Vernon Mauery98bbf692019-09-16 11:14:59 -07003603 registerHandler(prioOemBase, intel::netFnGeneral,
3604 intel::general::cmdGetFanSpeedOffset, Privilege::User,
3605 ipmiOEMGetFanSpeedOffset);
James Feistacc8a4e2019-04-02 14:23:57 -07003606
Vernon Mauery98bbf692019-09-16 11:14:59 -07003607 registerHandler(prioOemBase, intel::netFnGeneral,
3608 intel::general::cmdSetFanSpeedOffset, Privilege::User,
3609 ipmiOEMSetFanSpeedOffset);
James Feistacc8a4e2019-04-02 14:23:57 -07003610
Vernon Mauery98bbf692019-09-16 11:14:59 -07003611 registerHandler(prioOemBase, intel::netFnGeneral,
3612 intel::general::cmdSetFscParameter, Privilege::User,
3613 ipmiOEMSetFscParameter);
James Feist5f957ca2019-03-14 15:33:55 -07003614
Vernon Mauery98bbf692019-09-16 11:14:59 -07003615 registerHandler(prioOemBase, intel::netFnGeneral,
3616 intel::general::cmdGetFscParameter, Privilege::User,
3617 ipmiOEMGetFscParameter);
Richard Marian Thomaiyarea537d52019-04-24 21:33:48 +05303618
Vernon Mauery98bbf692019-09-16 11:14:59 -07003619 registerHandler(prioOpenBmcBase, intel::netFnGeneral,
3620 intel::general::cmdReadBaseBoardProductId, Privilege::Admin,
3621 ipmiOEMReadBoardProductId);
Chen Yugang39736d52019-07-12 16:24:33 +08003622
Vernon Mauery98bbf692019-09-16 11:14:59 -07003623 registerHandler(prioOemBase, intel::netFnGeneral,
3624 intel::general::cmdGetNmiStatus, Privilege::User,
3625 ipmiOEMGetNmiSource);
Chen Yugang39736d52019-07-12 16:24:33 +08003626
Vernon Mauery98bbf692019-09-16 11:14:59 -07003627 registerHandler(prioOemBase, intel::netFnGeneral,
3628 intel::general::cmdSetNmiStatus, Privilege::Operator,
3629 ipmiOEMSetNmiSource);
Chen,Yugang4f7e76b2019-08-20 09:28:06 +08003630
Vernon Mauery98bbf692019-09-16 11:14:59 -07003631 registerHandler(prioOemBase, intel::netFnGeneral,
3632 intel::general::cmdGetEfiBootOptions, Privilege::User,
3633 ipmiOemGetEfiBootOptions);
Chen,Yugang4f7e76b2019-08-20 09:28:06 +08003634
Vernon Mauery98bbf692019-09-16 11:14:59 -07003635 registerHandler(prioOemBase, intel::netFnGeneral,
3636 intel::general::cmdSetEfiBootOptions, Privilege::Operator,
3637 ipmiOemSetEfiBootOptions);
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05303638
Vernon Mauery98bbf692019-09-16 11:14:59 -07003639 registerHandler(prioOemBase, intel::netFnGeneral,
3640 intel::general::cmdGetSecurityMode, Privilege::User,
3641 ipmiGetSecurityMode);
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05303642
Vernon Mauery98bbf692019-09-16 11:14:59 -07003643 registerHandler(prioOemBase, intel::netFnGeneral,
3644 intel::general::cmdSetSecurityMode, Privilege::Admin,
3645 ipmiSetSecurityMode);
Vernon Mauery4ac799d2019-05-20 15:50:37 -07003646
Vernon Mauery98bbf692019-09-16 11:14:59 -07003647 ipmiPrintAndRegister(intel::netFnGeneral, intel::general::cmdGetLEDStatus,
3648 NULL, ipmiOEMGetLEDStatus, PRIVILEGE_ADMIN);
Cheng C Yang773703a2019-08-15 09:41:11 +08003649
Vernon Mauery98bbf692019-09-16 11:14:59 -07003650 ipmiPrintAndRegister(ipmi::intel::netFnPlatform,
3651 ipmi::intel::platform::cmdCfgHostSerialPortSpeed, NULL,
3652 ipmiOEMCfgHostSerialPortSpeed, PRIVILEGE_ADMIN);
3653
3654 registerHandler(prioOemBase, intel::netFnGeneral,
3655 intel::general::cmdSetFaultIndication, Privilege::Operator,
3656 ipmiOEMSetFaultIndication);
3657
3658 registerHandler(prioOemBase, intel::netFnGeneral,
3659 intel::general::cmdSetColdRedundancyConfig, Privilege::User,
3660 ipmiOEMSetCRConfig);
3661
3662 registerHandler(prioOemBase, intel::netFnGeneral,
3663 intel::general::cmdGetColdRedundancyConfig, Privilege::User,
3664 ipmiOEMGetCRConfig);
3665
3666 registerHandler(prioOemBase, intel::netFnGeneral,
3667 intel::general::cmdRestoreConfiguration, Privilege::Admin,
Vernon Mauery4ac799d2019-05-20 15:50:37 -07003668 ipmiRestoreConfiguration);
James Feist63efafa2019-07-24 12:39:21 -07003669
Vernon Mauery98bbf692019-09-16 11:14:59 -07003670 registerHandler(prioOemBase, intel::netFnGeneral,
3671 intel::general::cmdSetDimmOffset, Privilege::Operator,
3672 ipmiOEMSetDimmOffset);
James Feist63efafa2019-07-24 12:39:21 -07003673
Vernon Mauery98bbf692019-09-16 11:14:59 -07003674 registerHandler(prioOemBase, intel::netFnGeneral,
3675 intel::general::cmdGetDimmOffset, Privilege::Operator,
3676 ipmiOEMGetDimmOffset);
Chen Yugangca12a7b2019-09-03 18:11:44 +08003677
Cheng C Yang4e6ee152019-09-25 10:27:44 +08003678 registerHandler(prioOemBase, intel::netFnGeneral,
3679 intel::general::cmdGetPSUVersion, Privilege::User,
3680 ipmiOEMGetPSUVersion);
AppaRao Puli28972062019-11-11 02:04:45 +05303681
3682 registerHandler(prioOemBase, intel::netFnGeneral,
3683 intel::general::cmdGetBufferSize, Privilege::User,
3684 ipmiOEMGetBufferSize);
Jia, Chunhuia835eaa2018-09-05 09:00:41 +08003685}
3686
3687} // namespace ipmi