blob: 13133163d8d4ae11721104427b2a14da1735a99b [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,
2033 std::chrono::microseconds timeout = ipmi::IPMI_DBUS_TIMEOUT)
2034{
2035 boost::system::error_code ec;
2036 value = ctx->bus->yield_method_call<crConfigVariant>(
James Feist28c72902019-09-16 10:34:07 -07002037 ctx->yield, ec, "xyz.openbmc_project.Settings",
Cheng C Yang773703a2019-08-15 09:41:11 +08002038 "/xyz/openbmc_project/control/power_supply_redundancy",
2039 "org.freedesktop.DBus.Properties", "Get",
2040 "xyz.openbmc_project.Control.PowerSupplyRedundancy", property);
2041 if (ec)
2042 {
2043 phosphor::logging::log<phosphor::logging::level::ERR>(
2044 "Failed to get dbus property to cold redundancy");
2045 return -1;
2046 }
2047 return 0;
2048}
2049
2050uint8_t getPSUCount(void)
2051{
2052 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
2053 ipmi::Value num;
2054 try
2055 {
2056 num = ipmi::getDbusProperty(
2057 *dbus, "xyz.openbmc_project.PSURedundancy",
2058 "/xyz/openbmc_project/control/power_supply_redundancy",
2059 "xyz.openbmc_project.Control.PowerSupplyRedundancy", "PSUNumber");
2060 }
2061 catch (sdbusplus::exception_t& e)
2062 {
2063 phosphor::logging::log<phosphor::logging::level::ERR>(
2064 "Failed to get PSUNumber property from dbus interface");
2065 return 0;
2066 }
2067 uint8_t* pNum = std::get_if<uint8_t>(&num);
2068 if (!pNum)
2069 {
2070 phosphor::logging::log<phosphor::logging::level::ERR>(
2071 "Error to get PSU Number");
2072 return 0;
2073 }
2074 return *pNum;
2075}
2076
2077bool validateCRAlgo(std::vector<uint8_t>& conf, uint8_t num)
2078{
2079 if (conf.size() < num)
2080 {
2081 phosphor::logging::log<phosphor::logging::level::ERR>(
2082 "Invalid PSU Ranking");
2083 return false;
2084 }
2085 std::set<uint8_t> confSet;
2086 for (uint8_t i = 0; i < num; i++)
2087 {
2088 if (conf[i] > num)
2089 {
2090 phosphor::logging::log<phosphor::logging::level::ERR>(
2091 "PSU Ranking is larger than current PSU number");
2092 return false;
2093 }
2094 confSet.emplace(conf[i]);
2095 }
2096
2097 if (confSet.size() != num)
2098 {
2099 phosphor::logging::log<phosphor::logging::level::ERR>(
2100 "duplicate PSU Ranking");
2101 return false;
2102 }
2103 return true;
2104}
2105
2106enum class crParameter
2107{
2108 crStatus = 0,
2109 crFeature = 1,
2110 rotationFeature = 2,
2111 rotationAlgo = 3,
2112 rotationPeriod = 4,
2113 numOfPSU = 5
2114};
2115
2116constexpr ipmi::Cc ccParameterNotSupported = 0x80;
2117static const constexpr uint32_t oneDay = 0x15180;
2118static const constexpr uint32_t oneMonth = 0xf53700;
2119static const constexpr uint8_t userSpecific = 0x01;
2120static const constexpr uint8_t crSetCompleted = 0;
2121ipmi::RspType<uint8_t> ipmiOEMSetCRConfig(ipmi::Context::ptr ctx,
2122 uint8_t parameter,
2123 ipmi::message::Payload& payload)
2124{
2125 switch (static_cast<crParameter>(parameter))
2126 {
2127 case crParameter::crFeature:
2128 {
2129 uint8_t param1;
2130 if (payload.unpack(param1) || !payload.fullyUnpacked())
2131 {
2132 return ipmi::responseReqDataLenInvalid();
2133 }
2134 // ColdRedundancy Enable can only be true or flase
2135 if (param1 > 1)
2136 {
2137 return ipmi::responseInvalidFieldRequest();
2138 }
2139 if (setCRConfig(ctx, "ColdRedundancyEnabled",
2140 static_cast<bool>(param1)))
2141 {
2142 return ipmi::responseResponseError();
2143 }
2144 break;
2145 }
2146 case crParameter::rotationFeature:
2147 {
2148 uint8_t param1;
2149 if (payload.unpack(param1) || !payload.fullyUnpacked())
2150 {
2151 return ipmi::responseReqDataLenInvalid();
2152 }
2153 // Rotation Enable can only be true or false
2154 if (param1 > 1)
2155 {
2156 return ipmi::responseInvalidFieldRequest();
2157 }
2158 if (setCRConfig(ctx, "RotationEnabled", static_cast<bool>(param1)))
2159 {
2160 return ipmi::responseResponseError();
2161 }
2162 break;
2163 }
2164 case crParameter::rotationAlgo:
2165 {
2166 // Rotation Algorithm can only be 0-BMC Specific or 1-User Specific
2167 std::string algoName;
2168 uint8_t param1;
2169 if (payload.unpack(param1))
2170 {
2171 return ipmi::responseReqDataLenInvalid();
2172 }
2173 switch (param1)
2174 {
2175 case 0:
2176 algoName = "xyz.openbmc_project.Control."
2177 "PowerSupplyRedundancy.Algo.bmcSpecific";
2178 break;
2179 case 1:
2180 algoName = "xyz.openbmc_project.Control."
2181 "PowerSupplyRedundancy.Algo.userSpecific";
2182 break;
2183 default:
2184 return ipmi::responseInvalidFieldRequest();
2185 }
2186 if (setCRConfig(ctx, "RotationAlgorithm", algoName))
2187 {
2188 return ipmi::responseResponseError();
2189 }
2190
2191 uint8_t numberOfPSU = getPSUCount();
2192 if (!numberOfPSU)
2193 {
2194 return ipmi::responseResponseError();
2195 }
2196 std::vector<uint8_t> rankOrder;
2197
2198 if (param1 == userSpecific)
2199 {
2200 if (payload.unpack(rankOrder) || !payload.fullyUnpacked())
2201 {
2202 ipmi::responseReqDataLenInvalid();
2203 }
Yong Li83315132019-10-23 17:42:24 +08002204 if (rankOrder.size() != numberOfPSU)
Cheng C Yang773703a2019-08-15 09:41:11 +08002205 {
2206 return ipmi::responseReqDataLenInvalid();
2207 }
2208
2209 if (!validateCRAlgo(rankOrder, numberOfPSU))
2210 {
2211 return ipmi::responseInvalidFieldRequest();
2212 }
2213 }
2214 else
2215 {
2216 if (rankOrder.size() > 0)
2217 {
2218 return ipmi::responseReqDataLenInvalid();
2219 }
2220 for (uint8_t i = 1; i <= numberOfPSU; i++)
2221 {
2222 rankOrder.emplace_back(i);
2223 }
2224 }
2225 if (setCRConfig(ctx, "RotationRankOrder", rankOrder))
2226 {
2227 return ipmi::responseResponseError();
2228 }
2229 break;
2230 }
2231 case crParameter::rotationPeriod:
2232 {
2233 // Minimum Rotation period is One day (86400 seconds) and Max
2234 // Rotation Period is 6 month (0xf53700 seconds)
2235 uint32_t period;
2236 if (payload.unpack(period) || !payload.fullyUnpacked())
2237 {
2238 return ipmi::responseReqDataLenInvalid();
2239 }
2240 if ((period < oneDay) || (period > oneMonth))
2241 {
2242 return ipmi::responseInvalidFieldRequest();
2243 }
2244 if (setCRConfig(ctx, "PeriodOfRotation", period))
2245 {
2246 return ipmi::responseResponseError();
2247 }
2248 break;
2249 }
2250 default:
2251 {
2252 return ipmi::response(ccParameterNotSupported);
2253 }
2254 }
2255
2256 // TODO Halfwidth needs to set SetInProgress
2257 if (setCRConfig(ctx, "ColdRedundancyStatus",
Cheng C Yange8cecdf2019-08-26 23:48:08 +08002258 std::string("xyz.openbmc_project.Control."
2259 "PowerSupplyRedundancy.Status.completed")))
Cheng C Yang773703a2019-08-15 09:41:11 +08002260 {
2261 return ipmi::responseResponseError();
2262 }
2263 return ipmi::responseSuccess(crSetCompleted);
2264}
2265
Yong Li83315132019-10-23 17:42:24 +08002266ipmi::RspType<uint8_t, std::variant<uint8_t, uint32_t, std::vector<uint8_t>>>
Cheng C Yang773703a2019-08-15 09:41:11 +08002267 ipmiOEMGetCRConfig(ipmi::Context::ptr ctx, uint8_t parameter)
2268{
2269 crConfigVariant value;
2270 switch (static_cast<crParameter>(parameter))
2271 {
2272 case crParameter::crStatus:
2273 {
2274 if (getCRConfig(ctx, "ColdRedundancyStatus", value))
2275 {
2276 return ipmi::responseResponseError();
2277 }
2278 std::string* pStatus = std::get_if<std::string>(&value);
2279 if (!pStatus)
2280 {
2281 phosphor::logging::log<phosphor::logging::level::ERR>(
2282 "Error to get ColdRedundancyStatus property");
2283 return ipmi::responseResponseError();
2284 }
2285 namespace server = sdbusplus::xyz::openbmc_project::Control::server;
2286 auto status =
2287 server::PowerSupplyRedundancy::convertStatusFromString(
2288 *pStatus);
2289 switch (status)
2290 {
2291 case server::PowerSupplyRedundancy::Status::inProgress:
Cheng C Yangf41e3342019-09-10 04:47:23 +08002292 return ipmi::responseSuccess(parameter,
2293 static_cast<uint8_t>(0));
Cheng C Yang773703a2019-08-15 09:41:11 +08002294
2295 case server::PowerSupplyRedundancy::Status::completed:
Cheng C Yangf41e3342019-09-10 04:47:23 +08002296 return ipmi::responseSuccess(parameter,
2297 static_cast<uint8_t>(1));
Cheng C Yang773703a2019-08-15 09:41:11 +08002298 default:
2299 phosphor::logging::log<phosphor::logging::level::ERR>(
2300 "Error to get valid status");
2301 return ipmi::responseResponseError();
2302 }
2303 }
2304 case crParameter::crFeature:
2305 {
2306 if (getCRConfig(ctx, "ColdRedundancyEnabled", value))
2307 {
2308 return ipmi::responseResponseError();
2309 }
2310 bool* pResponse = std::get_if<bool>(&value);
2311 if (!pResponse)
2312 {
2313 phosphor::logging::log<phosphor::logging::level::ERR>(
2314 "Error to get ColdRedundancyEnable property");
2315 return ipmi::responseResponseError();
2316 }
2317
Cheng C Yangf41e3342019-09-10 04:47:23 +08002318 return ipmi::responseSuccess(parameter,
2319 static_cast<uint8_t>(*pResponse));
Cheng C Yang773703a2019-08-15 09:41:11 +08002320 }
2321 case crParameter::rotationFeature:
2322 {
2323 if (getCRConfig(ctx, "RotationEnabled", value))
2324 {
2325 return ipmi::responseResponseError();
2326 }
2327 bool* pResponse = std::get_if<bool>(&value);
2328 if (!pResponse)
2329 {
2330 phosphor::logging::log<phosphor::logging::level::ERR>(
2331 "Error to get RotationEnabled property");
2332 return ipmi::responseResponseError();
2333 }
Cheng C Yangf41e3342019-09-10 04:47:23 +08002334 return ipmi::responseSuccess(parameter,
2335 static_cast<uint8_t>(*pResponse));
Cheng C Yang773703a2019-08-15 09:41:11 +08002336 }
2337 case crParameter::rotationAlgo:
2338 {
2339 if (getCRConfig(ctx, "RotationAlgorithm", value))
2340 {
2341 return ipmi::responseResponseError();
2342 }
2343
2344 std::string* pAlgo = std::get_if<std::string>(&value);
2345 if (!pAlgo)
2346 {
2347 phosphor::logging::log<phosphor::logging::level::ERR>(
2348 "Error to get RotationAlgorithm property");
2349 return ipmi::responseResponseError();
2350 }
Yong Li83315132019-10-23 17:42:24 +08002351 std::vector<uint8_t> response;
Cheng C Yang773703a2019-08-15 09:41:11 +08002352 namespace server = sdbusplus::xyz::openbmc_project::Control::server;
2353 auto algo =
2354 server::PowerSupplyRedundancy::convertAlgoFromString(*pAlgo);
Yong Li83315132019-10-23 17:42:24 +08002355
Cheng C Yang773703a2019-08-15 09:41:11 +08002356 switch (algo)
2357 {
2358 case server::PowerSupplyRedundancy::Algo::bmcSpecific:
Yong Li83315132019-10-23 17:42:24 +08002359 response.push_back(0);
Cheng C Yang773703a2019-08-15 09:41:11 +08002360 break;
2361 case server::PowerSupplyRedundancy::Algo::userSpecific:
Yong Li83315132019-10-23 17:42:24 +08002362 response.push_back(1);
Cheng C Yang773703a2019-08-15 09:41:11 +08002363 break;
2364 default:
2365 phosphor::logging::log<phosphor::logging::level::ERR>(
2366 "Error to get valid algo");
2367 return ipmi::responseResponseError();
2368 }
2369
2370 if (getCRConfig(ctx, "RotationRankOrder", value))
2371 {
2372 return ipmi::responseResponseError();
2373 }
2374 std::vector<uint8_t>* pResponse =
2375 std::get_if<std::vector<uint8_t>>(&value);
2376 if (!pResponse)
2377 {
2378 phosphor::logging::log<phosphor::logging::level::ERR>(
2379 "Error to get RotationRankOrder property");
2380 return ipmi::responseResponseError();
2381 }
Yong Li83315132019-10-23 17:42:24 +08002382
Cheng C Yang773703a2019-08-15 09:41:11 +08002383 std::copy(pResponse->begin(), pResponse->end(),
Yong Li83315132019-10-23 17:42:24 +08002384 std::back_inserter(response));
2385
Cheng C Yangf41e3342019-09-10 04:47:23 +08002386 return ipmi::responseSuccess(parameter, response);
Cheng C Yang773703a2019-08-15 09:41:11 +08002387 }
2388 case crParameter::rotationPeriod:
2389 {
2390 if (getCRConfig(ctx, "PeriodOfRotation", value))
2391 {
2392 return ipmi::responseResponseError();
2393 }
2394 uint32_t* pResponse = std::get_if<uint32_t>(&value);
2395 if (!pResponse)
2396 {
2397 phosphor::logging::log<phosphor::logging::level::ERR>(
2398 "Error to get RotationAlgorithm property");
2399 return ipmi::responseResponseError();
2400 }
Cheng C Yangf41e3342019-09-10 04:47:23 +08002401 return ipmi::responseSuccess(parameter, *pResponse);
Cheng C Yang773703a2019-08-15 09:41:11 +08002402 }
2403 case crParameter::numOfPSU:
2404 {
2405 uint8_t numberOfPSU = getPSUCount();
2406 if (!numberOfPSU)
2407 {
2408 return ipmi::responseResponseError();
2409 }
Cheng C Yangf41e3342019-09-10 04:47:23 +08002410 return ipmi::responseSuccess(parameter, numberOfPSU);
Cheng C Yang773703a2019-08-15 09:41:11 +08002411 }
2412 default:
2413 {
2414 return ipmi::response(ccParameterNotSupported);
2415 }
2416 }
2417}
2418
Zhu, Yungebe560b02019-04-21 21:19:21 -04002419ipmi::RspType<> ipmiOEMSetFaultIndication(uint8_t sourceId, uint8_t faultType,
2420 uint8_t faultState,
2421 uint8_t faultGroup,
2422 std::array<uint8_t, 8>& ledStateData)
2423{
Zhu, Yungebe560b02019-04-21 21:19:21 -04002424 constexpr auto maxFaultType = static_cast<size_t>(RemoteFaultType::max);
2425 static const std::array<std::string, maxFaultType> faultNames = {
2426 "faultFan", "faultTemp", "faultPower",
2427 "faultDriveSlot", "faultSoftware", "faultMemory"};
Zhu, Yungebe560b02019-04-21 21:19:21 -04002428
2429 constexpr uint8_t maxFaultSource = 0x4;
2430 constexpr uint8_t skipLEDs = 0xFF;
2431 constexpr uint8_t pinSize = 64;
2432 constexpr uint8_t groupSize = 16;
Zhikui Rence4e73f2019-12-06 13:59:47 -08002433 constexpr uint8_t groupNum = 5; // 4 for fault memory, 1 for faultFan
Zhu, Yungebe560b02019-04-21 21:19:21 -04002434
Zhikui Rence4e73f2019-12-06 13:59:47 -08002435 // same pin names need to be defined in dts file
2436 static const std::array<std::array<std::string, groupSize>, groupNum>
2437 faultLedPinNames = {{
2438 "LED_CPU1_CH1_DIMM1_FAULT",
2439 "LED_CPU1_CH1_DIMM2_FAULT",
2440 "LED_CPU1_CH2_DIMM1_FAULT",
2441 "LED_CPU1_CH2_DIMM2_FAULT",
2442 "LED_CPU1_CH3_DIMM1_FAULT",
2443 "LED_CPU1_CH3_DIMM2_FAULT",
2444 "LED_CPU1_CH4_DIMM1_FAULT",
2445 "LED_CPU1_CH4_DIMM2_FAULT",
2446 "LED_CPU1_CH5_DIMM1_FAULT",
2447 "LED_CPU1_CH5_DIMM2_FAULT",
2448 "LED_CPU1_CH6_DIMM1_FAULT",
2449 "LED_CPU1_CH6_DIMM2_FAULT",
2450 "",
2451 "",
2452 "",
2453 "", // end of group1
2454 "LED_CPU2_CH1_DIMM1_FAULT",
2455 "LED_CPU2_CH1_DIMM2_FAULT",
2456 "LED_CPU2_CH2_DIMM1_FAULT",
2457 "LED_CPU2_CH2_DIMM2_FAULT",
2458 "LED_CPU2_CH3_DIMM1_FAULT",
2459 "LED_CPU2_CH3_DIMM2_FAULT",
2460 "LED_CPU2_CH4_DIMM1_FAULT",
2461 "LED_CPU2_CH4_DIMM2_FAULT",
2462 "LED_CPU2_CH5_DIMM1_FAULT",
2463 "LED_CPU2_CH5_DIMM2_FAULT",
2464 "LED_CPU2_CH6_DIMM1_FAULT",
2465 "LED_CPU2_CH6_DIMM2_FAULT",
2466 "",
2467 "",
2468 "",
2469 "", // endof group2
2470 "LED_CPU3_CH1_DIMM1_FAULT",
2471 "LED_CPU3_CH1_DIMM2_FAULT",
2472 "LED_CPU3_CH2_DIMM1_FAULT",
2473 "LED_CPU3_CH2_DIMM2_FAULT",
2474 "LED_CPU3_CH3_DIMM1_FAULT",
2475 "LED_CPU3_CH3_DIMM2_FAULT",
2476 "LED_CPU3_CH4_DIMM1_FAULT",
2477 "LED_CPU3_CH4_DIMM2_FAULT",
2478 "LED_CPU3_CH5_DIMM1_FAULT",
2479 "LED_CPU3_CH5_DIMM2_FAULT",
2480 "LED_CPU3_CH6_DIMM1_FAULT",
2481 "LED_CPU3_CH6_DIMM2_FAULT",
2482 "",
2483 "",
2484 "",
2485 "", // end of group3
2486 "LED_CPU4_CH1_DIMM1_FAULT",
2487 "LED_CPU4_CH1_DIMM2_FAULT",
2488 "LED_CPU4_CH2_DIMM1_FAULT",
2489 "LED_CPU4_CH2_DIMM2_FAULT",
2490 "LED_CPU4_CH3_DIMM1_FAULT",
2491 "LED_CPU4_CH3_DIMM2_FAULT",
2492 "LED_CPU4_CH4_DIMM1_FAULT",
2493 "LED_CPU4_CH4_DIMM2_FAULT",
2494 "LED_CPU4_CH5_DIMM1_FAULT",
2495 "LED_CPU4_CH5_DIMM2_FAULT",
2496 "LED_CPU4_CH6_DIMM1_FAULT",
2497 "LED_CPU4_CH6_DIMM2_FAULT",
2498 "",
2499 "",
2500 "",
2501 "", // end of group4
2502 "LED_FAN1_FAULT",
2503 "LED_FAN2_FAULT",
2504 "LED_FAN3_FAULT",
2505 "LED_FAN4_FAULT",
2506 "LED_FAN5_FAULT",
2507 "LED_FAN6_FAULT",
2508 "LED_FAN7_FAULT",
2509 "LED_FAN8_FAULT",
2510 "",
2511 "",
2512 "",
2513 "",
2514 "",
2515 "",
2516 "",
2517 "" // end of group5
2518 }};
Zhu, Yungebe560b02019-04-21 21:19:21 -04002519
Zhikui Rence4e73f2019-12-06 13:59:47 -08002520 // Validate the source, fault type --
2521 // (Byte 1) sourceId: Unspecified, Hot-Swap Controller 0, Hot-Swap
2522 // Controller 1, BIOS (Byte 2) fault type: fan, temperature, power,
2523 // driveslot, software, memory (Byte 3) FaultState: OK, Degraded,
2524 // Non-Critical, Critical, Non-Recoverable, (Byte 4) is faultGroup,
2525 // definition differs based on fault type (Byte 2)
2526 // Type Fan=> Group: 0=FanGroupID, FF-not used
2527 // Byte 5-11 00h, not used
2528 // Byte12 FanLedState [7:0]-Fans 7:0
2529 // Type Memory=> Group: 0 = DIMM GroupID, FF-not used
2530 // Byte 5:12 - DIMM LED state (64bit field, LS Byte first)
2531 // [63:48] = CPU4 channels 7:0, 2 bits per channel
2532 // [47:32] = CPU3 channels 7:0, 2 bits per channel
2533 // [31:16] = CPU2 channels 7:0, 2 bits per channel
2534 // [15:0] = CPU1 channels 7:0, 2 bits per channel
2535 // Type Other=> Component Fault LED Group ID, not used set to 0xFF
2536 // Byte[5:12]: reserved 0x00h
Zhu, Yungebe560b02019-04-21 21:19:21 -04002537 if ((sourceId >= maxFaultSource) ||
2538 (faultType >= static_cast<int8_t>(RemoteFaultType::max)) ||
2539 (faultState >= static_cast<int8_t>(RemoteFaultState::maxFaultState)) ||
2540 (faultGroup >= static_cast<int8_t>(DimmFaultType::maxFaultGroup)))
2541 {
2542 return ipmi::responseParmOutOfRange();
2543 }
2544
Zhikui Rence4e73f2019-12-06 13:59:47 -08002545 size_t pinGroupOffset = 0;
2546 size_t pinGroupMax = pinSize / groupSize;
2547 if (RemoteFaultType::fan == RemoteFaultType(faultType))
Zhu, Yungebe560b02019-04-21 21:19:21 -04002548 {
Zhikui Rence4e73f2019-12-06 13:59:47 -08002549 pinGroupOffset = 4;
2550 pinGroupMax = groupNum - pinSize / groupSize;
Zhu, Yungebe560b02019-04-21 21:19:21 -04002551 }
2552
2553 switch (RemoteFaultType(faultType))
2554 {
2555 case (RemoteFaultType::fan):
2556 case (RemoteFaultType::memory):
2557 {
2558 if (faultGroup == skipLEDs)
2559 {
2560 return ipmi::responseSuccess();
2561 }
Zhu, Yungebe560b02019-04-21 21:19:21 -04002562 // calculate led state bit filed count, each byte has 8bits
2563 // the maximum bits will be 8 * 8 bits
2564 constexpr uint8_t size = sizeof(ledStateData) * 8;
Zhikui Rence4e73f2019-12-06 13:59:47 -08002565
2566 // assemble ledState
2567 uint64_t ledState = 0;
2568 bool hasError = false;
Zhu, Yungebe560b02019-04-21 21:19:21 -04002569 for (int i = 0; i < sizeof(ledStateData); i++)
2570 {
2571 ledState = (uint64_t)(ledState << 8);
2572 ledState = (uint64_t)(ledState | (uint64_t)ledStateData[i]);
2573 }
Zhu, Yungebe560b02019-04-21 21:19:21 -04002574 std::bitset<size> ledStateBits(ledState);
Zhu, Yungebe560b02019-04-21 21:19:21 -04002575
Zhikui Rence4e73f2019-12-06 13:59:47 -08002576 for (int group = 0; group < pinGroupMax; group++)
2577 {
2578 for (int i = 0; i < groupSize; i++)
2579 { // skip non-existing pins
2580 if (0 == faultLedPinNames[group + pinGroupOffset][i].size())
2581 {
2582 continue;
2583 }
Zhu, Yungebe560b02019-04-21 21:19:21 -04002584
Zhikui Rence4e73f2019-12-06 13:59:47 -08002585 gpiod::line line = gpiod::find_line(
2586 faultLedPinNames[group + pinGroupOffset][i]);
2587 if (!line)
2588 {
2589 phosphor::logging::log<phosphor::logging::level::ERR>(
2590 "Not Find Led Gpio Device!",
2591 phosphor::logging::entry(
2592 "DEVICE=%s",
2593 faultLedPinNames[group + pinGroupOffset][i]
2594 .c_str()));
2595 hasError = true;
2596 continue;
2597 }
Zhu, Yungebe560b02019-04-21 21:19:21 -04002598
Zhikui Rence4e73f2019-12-06 13:59:47 -08002599 bool activeHigh =
2600 (line.active_state() == gpiod::line::ACTIVE_HIGH);
2601 try
2602 {
2603 line.request(
2604 {"faultLed", gpiod::line_request::DIRECTION_OUTPUT,
2605 activeHigh
2606 ? 0
2607 : gpiod::line_request::FLAG_ACTIVE_LOW});
2608 line.set_value(ledStateBits[i + group * groupSize]);
2609 }
2610 catch (std::system_error&)
2611 {
2612 phosphor::logging::log<phosphor::logging::level::ERR>(
2613 "Error write Led Gpio Device!",
2614 phosphor::logging::entry(
2615 "DEVICE=%s",
2616 faultLedPinNames[group + pinGroupOffset][i]
2617 .c_str()));
2618 hasError = true;
2619 continue;
2620 }
2621 } // for int i
2622 }
2623 if (hasError)
2624 {
2625 return ipmi::responseResponseError();
Zhu, Yungebe560b02019-04-21 21:19:21 -04002626 }
2627 break;
2628 }
2629 default:
2630 {
2631 // now only support two fault types
2632 return ipmi::responseParmOutOfRange();
2633 }
Zhikui Rence4e73f2019-12-06 13:59:47 -08002634 } // switch
Zhu, Yungebe560b02019-04-21 21:19:21 -04002635 return ipmi::responseSuccess();
2636}
2637
Richard Marian Thomaiyarea537d52019-04-24 21:33:48 +05302638ipmi::RspType<uint8_t> ipmiOEMReadBoardProductId()
2639{
2640 uint8_t prodId = 0;
2641 try
2642 {
Vernon Mauery15419dd2019-05-24 09:40:30 -07002643 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Richard Marian Thomaiyarea537d52019-04-24 21:33:48 +05302644 const DbusObjectInfo& object = getDbusObject(
Vernon Mauery15419dd2019-05-24 09:40:30 -07002645 *dbus, "xyz.openbmc_project.Inventory.Item.Board",
Richard Marian Thomaiyarea537d52019-04-24 21:33:48 +05302646 "/xyz/openbmc_project/inventory/system/board/", "Baseboard");
2647 const Value& propValue = getDbusProperty(
Vernon Mauery15419dd2019-05-24 09:40:30 -07002648 *dbus, object.second, object.first,
Richard Marian Thomaiyarea537d52019-04-24 21:33:48 +05302649 "xyz.openbmc_project.Inventory.Item.Board", "ProductId");
2650 prodId = static_cast<uint8_t>(std::get<uint64_t>(propValue));
2651 }
2652 catch (std::exception& e)
2653 {
2654 phosphor::logging::log<phosphor::logging::level::ERR>(
2655 "ipmiOEMReadBoardProductId: Product ID read failed!",
2656 phosphor::logging::entry("ERR=%s", e.what()));
2657 }
2658 return ipmi::responseSuccess(prodId);
2659}
2660
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05302661/** @brief implements the get security mode command
2662 * @param ctx - ctx pointer
2663 *
2664 * @returns IPMI completion code with following data
2665 * - restriction mode value - As specified in
2666 * xyz.openbmc_project.Control.Security.RestrictionMode.interface.yaml
2667 * - special mode value - As specified in
2668 * xyz.openbmc_project.Control.Security.SpecialMode.interface.yaml
2669 */
2670ipmi::RspType<uint8_t, uint8_t> ipmiGetSecurityMode(ipmi::Context::ptr ctx)
2671{
2672 namespace securityNameSpace =
2673 sdbusplus::xyz::openbmc_project::Control::Security::server;
2674 uint8_t restrictionModeValue = 0;
2675 uint8_t specialModeValue = 0;
2676
2677 boost::system::error_code ec;
2678 auto varRestrMode = ctx->bus->yield_method_call<std::variant<std::string>>(
James Feist28c72902019-09-16 10:34:07 -07002679 ctx->yield, ec, restricionModeService, restricionModeBasePath,
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05302680 dBusPropertyIntf, dBusPropertyGetMethod, restricionModeIntf,
2681 restricionModeProperty);
2682 if (ec)
2683 {
2684 phosphor::logging::log<phosphor::logging::level::ERR>(
2685 "ipmiGetSecurityMode: failed to get RestrictionMode property",
2686 phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
2687 return ipmi::responseUnspecifiedError();
2688 }
2689 restrictionModeValue = static_cast<uint8_t>(
2690 securityNameSpace::RestrictionMode::convertModesFromString(
2691 std::get<std::string>(varRestrMode)));
Richard Marian Thomaiyar8d4f8d72019-11-11 12:06:40 +05302692 auto varSpecialMode =
2693 ctx->bus->yield_method_call<std::variant<std::string>>(
2694 ctx->yield, ec, specialModeService, specialModeBasePath,
2695 dBusPropertyIntf, dBusPropertyGetMethod, specialModeIntf,
2696 specialModeProperty);
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05302697 if (ec)
2698 {
2699 phosphor::logging::log<phosphor::logging::level::ERR>(
2700 "ipmiGetSecurityMode: failed to get SpecialMode property",
2701 phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
2702 // fall through, let us not worry about SpecialMode property, which is
2703 // not required in user scenario
2704 }
2705 else
2706 {
Richard Marian Thomaiyar8d4f8d72019-11-11 12:06:40 +05302707 specialModeValue = static_cast<uint8_t>(
2708 securityNameSpace::SpecialMode::convertModesFromString(
2709 std::get<std::string>(varSpecialMode)));
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05302710 }
2711 return ipmi::responseSuccess(restrictionModeValue, specialModeValue);
2712}
2713
2714/** @brief implements the set security mode command
2715 * Command allows to upgrade the restriction mode and won't allow
2716 * to downgrade from system interface
2717 * @param ctx - ctx pointer
2718 * @param restrictionMode - restriction mode value to be set.
2719 *
2720 * @returns IPMI completion code
2721 */
2722ipmi::RspType<> ipmiSetSecurityMode(ipmi::Context::ptr ctx,
Richard Marian Thomaiyar10791062019-11-11 12:19:53 +05302723 uint8_t restrictionMode,
2724 std::optional<uint8_t> specialMode)
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05302725{
Richard Marian Thomaiyar10791062019-11-11 12:19:53 +05302726#ifndef BMC_VALIDATION_UNSECURE_FEATURE
2727 if (specialMode)
2728 {
2729 return ipmi::responseReqDataLenInvalid();
2730 }
2731#endif
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05302732 namespace securityNameSpace =
2733 sdbusplus::xyz::openbmc_project::Control::Security::server;
2734
2735 ChannelInfo chInfo;
2736 if (getChannelInfo(ctx->channel, chInfo) != ccSuccess)
2737 {
2738 phosphor::logging::log<phosphor::logging::level::ERR>(
2739 "ipmiSetSecurityMode: Failed to get Channel Info",
2740 phosphor::logging::entry("CHANNEL=%d", ctx->channel));
2741 return ipmi::responseUnspecifiedError();
2742 }
2743 auto reqMode =
2744 static_cast<securityNameSpace::RestrictionMode::Modes>(restrictionMode);
2745
2746 if ((reqMode < securityNameSpace::RestrictionMode::Modes::Provisioning) ||
2747 (reqMode >
2748 securityNameSpace::RestrictionMode::Modes::ProvisionedHostDisabled))
2749 {
2750 return ipmi::responseInvalidFieldRequest();
2751 }
2752
2753 boost::system::error_code ec;
2754 auto varRestrMode = ctx->bus->yield_method_call<std::variant<std::string>>(
James Feist28c72902019-09-16 10:34:07 -07002755 ctx->yield, ec, restricionModeService, restricionModeBasePath,
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05302756 dBusPropertyIntf, dBusPropertyGetMethod, restricionModeIntf,
2757 restricionModeProperty);
2758 if (ec)
2759 {
2760 phosphor::logging::log<phosphor::logging::level::ERR>(
2761 "ipmiSetSecurityMode: failed to get RestrictionMode property",
2762 phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
2763 return ipmi::responseUnspecifiedError();
2764 }
2765 auto currentRestrictionMode =
2766 securityNameSpace::RestrictionMode::convertModesFromString(
2767 std::get<std::string>(varRestrMode));
2768
2769 if (chInfo.mediumType !=
2770 static_cast<uint8_t>(EChannelMediumType::lan8032) &&
2771 currentRestrictionMode > reqMode)
2772 {
2773 phosphor::logging::log<phosphor::logging::level::ERR>(
2774 "ipmiSetSecurityMode - Downgrading security mode not supported "
2775 "through system interface",
2776 phosphor::logging::entry(
2777 "CUR_MODE=%d", static_cast<uint8_t>(currentRestrictionMode)),
2778 phosphor::logging::entry("REQ_MODE=%d", restrictionMode));
2779 return ipmi::responseCommandNotAvailable();
2780 }
2781
2782 ec.clear();
2783 ctx->bus->yield_method_call<>(
James Feist28c72902019-09-16 10:34:07 -07002784 ctx->yield, ec, restricionModeService, restricionModeBasePath,
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05302785 dBusPropertyIntf, dBusPropertySetMethod, restricionModeIntf,
2786 restricionModeProperty,
2787 static_cast<std::variant<std::string>>(
2788 securityNameSpace::convertForMessage(reqMode)));
2789
2790 if (ec)
2791 {
2792 phosphor::logging::log<phosphor::logging::level::ERR>(
2793 "ipmiSetSecurityMode: failed to set RestrictionMode property",
2794 phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
2795 return ipmi::responseUnspecifiedError();
2796 }
Richard Marian Thomaiyar10791062019-11-11 12:19:53 +05302797
2798#ifdef BMC_VALIDATION_UNSECURE_FEATURE
2799 if (specialMode)
2800 {
2801 ec.clear();
2802 ctx->bus->yield_method_call<>(
2803 ctx->yield, ec, specialModeService, specialModeBasePath,
2804 dBusPropertyIntf, dBusPropertySetMethod, specialModeIntf,
2805 specialModeProperty,
2806 static_cast<std::variant<std::string>>(
2807 securityNameSpace::convertForMessage(
2808 static_cast<securityNameSpace::SpecialMode::Modes>(
2809 specialMode.value()))));
2810
2811 if (ec)
2812 {
2813 phosphor::logging::log<phosphor::logging::level::ERR>(
2814 "ipmiSetSecurityMode: failed to set SpecialMode property",
2815 phosphor::logging::entry("ERROR=%s", ec.message().c_str()));
2816 return ipmi::responseUnspecifiedError();
2817 }
2818 }
2819#endif
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05302820 return ipmi::responseSuccess();
2821}
2822
Vernon Mauery4ac799d2019-05-20 15:50:37 -07002823ipmi::RspType<uint8_t /* restore status */>
2824 ipmiRestoreConfiguration(const std::array<uint8_t, 3>& clr, uint8_t cmd)
2825{
2826 static constexpr std::array<uint8_t, 3> expClr = {'C', 'L', 'R'};
2827
2828 if (clr != expClr)
2829 {
2830 return ipmi::responseInvalidFieldRequest();
2831 }
2832 constexpr uint8_t cmdStatus = 0;
2833 constexpr uint8_t cmdDefaultRestore = 0xaa;
2834 constexpr uint8_t cmdFullRestore = 0xbb;
2835 constexpr uint8_t cmdFormat = 0xcc;
2836
2837 constexpr const char* restoreOpFname = "/tmp/.rwfs/.restore_op";
2838
2839 switch (cmd)
2840 {
2841 case cmdStatus:
2842 break;
2843 case cmdDefaultRestore:
2844 case cmdFullRestore:
2845 case cmdFormat:
2846 {
2847 // write file to rwfs root
2848 int value = (cmd - 1) & 0x03; // map aa, bb, cc => 1, 2, 3
2849 std::ofstream restoreFile(restoreOpFname);
2850 if (!restoreFile)
2851 {
2852 return ipmi::responseUnspecifiedError();
2853 }
2854 restoreFile << value << "\n";
2855 break;
2856 }
2857 default:
2858 return ipmi::responseInvalidFieldRequest();
2859 }
2860
2861 constexpr uint8_t restorePending = 0;
2862 constexpr uint8_t restoreComplete = 1;
2863
2864 uint8_t restoreStatus = std::filesystem::exists(restoreOpFname)
2865 ? restorePending
2866 : restoreComplete;
2867 return ipmi::responseSuccess(restoreStatus);
2868}
2869
Chen Yugang39736d52019-07-12 16:24:33 +08002870ipmi::RspType<uint8_t> ipmiOEMGetNmiSource(void)
2871{
2872 uint8_t bmcSource;
Chen Yugang97cf96e2019-11-01 08:55:11 +08002873 namespace nmi = sdbusplus::xyz::openbmc_project::Chassis::Control::server;
Chen Yugang39736d52019-07-12 16:24:33 +08002874
2875 try
2876 {
2877 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
2878 std::string service =
2879 getService(*dbus, oemNmiSourceIntf, oemNmiSourceObjPath);
2880 Value variant =
2881 getDbusProperty(*dbus, service, oemNmiSourceObjPath,
2882 oemNmiSourceIntf, oemNmiBmcSourceObjPathProp);
2883
2884 switch (nmi::NMISource::convertBMCSourceSignalFromString(
2885 std::get<std::string>(variant)))
2886 {
2887 case nmi::NMISource::BMCSourceSignal::None:
2888 bmcSource = static_cast<uint8_t>(NmiSource::none);
2889 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08002890 case nmi::NMISource::BMCSourceSignal::FrontPanelButton:
2891 bmcSource = static_cast<uint8_t>(NmiSource::frontPanelButton);
Chen Yugang39736d52019-07-12 16:24:33 +08002892 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08002893 case nmi::NMISource::BMCSourceSignal::Watchdog:
2894 bmcSource = static_cast<uint8_t>(NmiSource::watchdog);
Chen Yugang39736d52019-07-12 16:24:33 +08002895 break;
2896 case nmi::NMISource::BMCSourceSignal::ChassisCmd:
2897 bmcSource = static_cast<uint8_t>(NmiSource::chassisCmd);
2898 break;
2899 case nmi::NMISource::BMCSourceSignal::MemoryError:
2900 bmcSource = static_cast<uint8_t>(NmiSource::memoryError);
2901 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08002902 case nmi::NMISource::BMCSourceSignal::PciBusError:
2903 bmcSource = static_cast<uint8_t>(NmiSource::pciBusError);
Chen Yugang39736d52019-07-12 16:24:33 +08002904 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08002905 case nmi::NMISource::BMCSourceSignal::PCH:
2906 bmcSource = static_cast<uint8_t>(NmiSource::pch);
Chen Yugang39736d52019-07-12 16:24:33 +08002907 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08002908 case nmi::NMISource::BMCSourceSignal::Chipset:
2909 bmcSource = static_cast<uint8_t>(NmiSource::chipset);
Chen Yugang39736d52019-07-12 16:24:33 +08002910 break;
2911 default:
2912 phosphor::logging::log<phosphor::logging::level::ERR>(
2913 "NMI source: invalid property!",
2914 phosphor::logging::entry(
2915 "PROP=%s", std::get<std::string>(variant).c_str()));
2916 return ipmi::responseResponseError();
2917 }
2918 }
2919 catch (sdbusplus::exception::SdBusError& e)
2920 {
2921 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
2922 return ipmi::responseResponseError();
2923 }
2924
2925 return ipmi::responseSuccess(bmcSource);
2926}
2927
2928ipmi::RspType<> ipmiOEMSetNmiSource(uint8_t sourceId)
2929{
Chen Yugang97cf96e2019-11-01 08:55:11 +08002930 namespace nmi = sdbusplus::xyz::openbmc_project::Chassis::Control::server;
Chen Yugang39736d52019-07-12 16:24:33 +08002931
2932 nmi::NMISource::BMCSourceSignal bmcSourceSignal =
2933 nmi::NMISource::BMCSourceSignal::None;
2934
2935 switch (NmiSource(sourceId))
2936 {
2937 case NmiSource::none:
2938 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::None;
2939 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08002940 case NmiSource::frontPanelButton:
2941 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::FrontPanelButton;
Chen Yugang39736d52019-07-12 16:24:33 +08002942 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08002943 case NmiSource::watchdog:
2944 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::Watchdog;
Chen Yugang39736d52019-07-12 16:24:33 +08002945 break;
2946 case NmiSource::chassisCmd:
2947 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::ChassisCmd;
2948 break;
2949 case NmiSource::memoryError:
2950 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::MemoryError;
2951 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08002952 case NmiSource::pciBusError:
2953 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::PciBusError;
Chen Yugang39736d52019-07-12 16:24:33 +08002954 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08002955 case NmiSource::pch:
2956 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::PCH;
Chen Yugang39736d52019-07-12 16:24:33 +08002957 break;
Chen Yugang97cf96e2019-11-01 08:55:11 +08002958 case NmiSource::chipset:
2959 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::Chipset;
Chen Yugang39736d52019-07-12 16:24:33 +08002960 break;
2961 default:
2962 phosphor::logging::log<phosphor::logging::level::ERR>(
2963 "NMI source: invalid property!");
2964 return ipmi::responseResponseError();
2965 }
2966
2967 try
2968 {
2969 // keep NMI signal source
2970 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
2971 std::string service =
2972 getService(*dbus, oemNmiSourceIntf, oemNmiSourceObjPath);
Chen Yugang97cf96e2019-11-01 08:55:11 +08002973 setDbusProperty(*dbus, service, oemNmiSourceObjPath, oemNmiSourceIntf,
2974 oemNmiBmcSourceObjPathProp,
2975 nmi::convertForMessage(bmcSourceSignal));
Chen Yugang99be6332019-08-09 16:20:48 +08002976 // set Enabled property to inform NMI source handling
2977 // to trigger a NMI_OUT BSOD.
2978 // if it's triggered by NMI source property changed,
2979 // NMI_OUT BSOD could be missed if the same source occurs twice in a row
2980 if (bmcSourceSignal != nmi::NMISource::BMCSourceSignal::None)
2981 {
2982 setDbusProperty(*dbus, service, oemNmiSourceObjPath,
2983 oemNmiSourceIntf, oemNmiEnabledObjPathProp,
2984 static_cast<bool>(true));
2985 }
Chen Yugang39736d52019-07-12 16:24:33 +08002986 }
2987 catch (sdbusplus::exception_t& e)
2988 {
2989 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
2990 return ipmi::responseResponseError();
2991 }
2992
2993 return ipmi::responseSuccess();
2994}
2995
James Feist63efafa2019-07-24 12:39:21 -07002996namespace dimmOffset
2997{
2998constexpr const char* dimmPower = "DimmPower";
2999constexpr const char* staticCltt = "StaticCltt";
3000constexpr const char* offsetPath = "/xyz/openbmc_project/Inventory/Item/Dimm";
3001constexpr const char* offsetInterface =
3002 "xyz.openbmc_project.Inventory.Item.Dimm.Offset";
3003constexpr const char* property = "DimmOffset";
3004
3005}; // namespace dimmOffset
3006
3007ipmi::RspType<>
3008 ipmiOEMSetDimmOffset(uint8_t type,
3009 const std::vector<std::tuple<uint8_t, uint8_t>>& data)
3010{
3011 if (type != static_cast<uint8_t>(dimmOffsetTypes::dimmPower) &&
3012 type != static_cast<uint8_t>(dimmOffsetTypes::staticCltt))
3013 {
3014 return ipmi::responseInvalidFieldRequest();
3015 }
3016
3017 if (data.empty())
3018 {
3019 return ipmi::responseInvalidFieldRequest();
3020 }
3021 nlohmann::json json;
3022
3023 std::ifstream jsonStream(dimmOffsetFile);
3024 if (jsonStream.good())
3025 {
3026 json = nlohmann::json::parse(jsonStream, nullptr, false);
3027 if (json.is_discarded())
3028 {
3029 json = nlohmann::json();
3030 }
3031 jsonStream.close();
3032 }
3033
3034 std::string typeName;
3035 if (type == static_cast<uint8_t>(dimmOffsetTypes::dimmPower))
3036 {
3037 typeName = dimmOffset::dimmPower;
3038 }
3039 else
3040 {
3041 typeName = dimmOffset::staticCltt;
3042 }
3043
3044 nlohmann::json& field = json[typeName];
3045
3046 for (const auto& [index, value] : data)
3047 {
3048 field[index] = value;
3049 }
3050
3051 for (nlohmann::json& val : field)
3052 {
3053 if (val == nullptr)
3054 {
3055 val = static_cast<uint8_t>(0);
3056 }
3057 }
3058
3059 std::ofstream output(dimmOffsetFile);
3060 if (!output.good())
3061 {
3062 std::cerr << "Error writing json file\n";
3063 return ipmi::responseResponseError();
3064 }
3065
3066 output << json.dump(4);
3067
3068 if (type == static_cast<uint8_t>(dimmOffsetTypes::staticCltt))
3069 {
3070 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
3071
3072 std::variant<std::vector<uint8_t>> offsets =
3073 field.get<std::vector<uint8_t>>();
3074 auto call = bus->new_method_call(
3075 settingsBusName, dimmOffset::offsetPath, PROP_INTF, "Set");
3076 call.append(dimmOffset::offsetInterface, dimmOffset::property, offsets);
3077 try
3078 {
3079 bus->call(call);
3080 }
3081 catch (sdbusplus::exception_t& e)
3082 {
3083 phosphor::logging::log<phosphor::logging::level::ERR>(
3084 "ipmiOEMSetDimmOffset: can't set dimm offsets!",
3085 phosphor::logging::entry("ERR=%s", e.what()));
3086 return ipmi::responseResponseError();
3087 }
3088 }
3089
3090 return ipmi::responseSuccess();
3091}
3092
3093ipmi::RspType<uint8_t> ipmiOEMGetDimmOffset(uint8_t type, uint8_t index)
3094{
3095
3096 if (type != static_cast<uint8_t>(dimmOffsetTypes::dimmPower) &&
3097 type != static_cast<uint8_t>(dimmOffsetTypes::staticCltt))
3098 {
3099 return ipmi::responseInvalidFieldRequest();
3100 }
3101
3102 std::ifstream jsonStream(dimmOffsetFile);
3103
3104 auto json = nlohmann::json::parse(jsonStream, nullptr, false);
3105 if (json.is_discarded())
3106 {
3107 std::cerr << "File error in " << dimmOffsetFile << "\n";
3108 return ipmi::responseResponseError();
3109 }
3110
3111 std::string typeName;
3112 if (type == static_cast<uint8_t>(dimmOffsetTypes::dimmPower))
3113 {
3114 typeName = dimmOffset::dimmPower;
3115 }
3116 else
3117 {
3118 typeName = dimmOffset::staticCltt;
3119 }
3120
3121 auto it = json.find(typeName);
3122 if (it == json.end())
3123 {
3124 return ipmi::responseInvalidFieldRequest();
3125 }
3126
3127 if (it->size() <= index)
3128 {
3129 return ipmi::responseInvalidFieldRequest();
3130 }
3131
3132 uint8_t resp = it->at(index).get<uint8_t>();
3133 return ipmi::responseSuccess(resp);
3134}
3135
Chen,Yugang4f7e76b2019-08-20 09:28:06 +08003136namespace boot_options
3137{
3138
3139using namespace sdbusplus::xyz::openbmc_project::Control::Boot::server;
3140using IpmiValue = uint8_t;
3141constexpr auto ipmiDefault = 0;
3142
3143std::map<IpmiValue, Source::Sources> sourceIpmiToDbus = {
3144 {0x01, Source::Sources::Network},
3145 {0x02, Source::Sources::Disk},
3146 {0x05, Source::Sources::ExternalMedia},
3147 {0x0f, Source::Sources::RemovableMedia},
3148 {ipmiDefault, Source::Sources::Default}};
3149
3150std::map<IpmiValue, Mode::Modes> modeIpmiToDbus = {
Chen Yugangca12a7b2019-09-03 18:11:44 +08003151 {0x06, Mode::Modes::Setup}, {ipmiDefault, Mode::Modes::Regular}};
Chen,Yugang4f7e76b2019-08-20 09:28:06 +08003152
3153std::map<Source::Sources, IpmiValue> sourceDbusToIpmi = {
3154 {Source::Sources::Network, 0x01},
3155 {Source::Sources::Disk, 0x02},
3156 {Source::Sources::ExternalMedia, 0x05},
3157 {Source::Sources::RemovableMedia, 0x0f},
3158 {Source::Sources::Default, ipmiDefault}};
3159
3160std::map<Mode::Modes, IpmiValue> modeDbusToIpmi = {
Chen Yugangca12a7b2019-09-03 18:11:44 +08003161 {Mode::Modes::Setup, 0x06}, {Mode::Modes::Regular, ipmiDefault}};
Chen,Yugang4f7e76b2019-08-20 09:28:06 +08003162
3163static constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode";
3164static constexpr auto bootSourceIntf =
3165 "xyz.openbmc_project.Control.Boot.Source";
3166static constexpr auto enabledIntf = "xyz.openbmc_project.Object.Enable";
3167static constexpr auto persistentObjPath =
3168 "/xyz/openbmc_project/control/host0/boot";
3169static constexpr auto oneTimePath =
3170 "/xyz/openbmc_project/control/host0/boot/one_time";
3171static constexpr auto bootSourceProp = "BootSource";
3172static constexpr auto bootModeProp = "BootMode";
3173static constexpr auto oneTimeBootEnableProp = "Enabled";
3174static constexpr auto httpBootMode =
3175 "xyz.openbmc_project.Control.Boot.Source.Sources.Http";
3176
3177enum class BootOptionParameter : size_t
3178{
3179 setInProgress = 0x0,
3180 bootFlags = 0x5,
3181};
3182static constexpr uint8_t setComplete = 0x0;
3183static constexpr uint8_t setInProgress = 0x1;
3184static uint8_t transferStatus = setComplete;
3185static constexpr uint8_t setParmVersion = 0x01;
3186static constexpr uint8_t setParmBootFlagsPermanent = 0x40;
3187static constexpr uint8_t setParmBootFlagsValidOneTime = 0x80;
3188static constexpr uint8_t setParmBootFlagsValidPermanent = 0xC0;
3189static constexpr uint8_t httpBoot = 0xd;
3190static constexpr uint8_t bootSourceMask = 0x3c;
3191
3192} // namespace boot_options
3193
3194ipmi::RspType<uint8_t, // version
3195 uint8_t, // param
3196 uint8_t, // data0, dependent on parameter
3197 std::optional<uint8_t> // data1, dependent on parameter
3198 >
3199 ipmiOemGetEfiBootOptions(uint8_t parameter, uint8_t set, uint8_t block)
3200{
3201 using namespace boot_options;
3202 uint8_t bootOption = 0;
3203
3204 if (parameter == static_cast<uint8_t>(BootOptionParameter::setInProgress))
3205 {
3206 return ipmi::responseSuccess(setParmVersion, parameter, transferStatus,
3207 std::nullopt);
3208 }
3209
3210 if (parameter != static_cast<uint8_t>(BootOptionParameter::bootFlags))
3211 {
3212 phosphor::logging::log<phosphor::logging::level::ERR>(
3213 "Unsupported parameter");
3214 return ipmi::responseResponseError();
3215 }
3216
3217 try
3218 {
3219 auto oneTimeEnabled = false;
3220 // read one time Enabled property
3221 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
3222 std::string service = getService(*dbus, enabledIntf, oneTimePath);
3223 Value variant = getDbusProperty(*dbus, service, oneTimePath,
3224 enabledIntf, oneTimeBootEnableProp);
3225 oneTimeEnabled = std::get<bool>(variant);
3226
3227 // get BootSource and BootMode properties
3228 // according to oneTimeEnable
3229 auto bootObjPath = oneTimePath;
3230 if (oneTimeEnabled == false)
3231 {
3232 bootObjPath = persistentObjPath;
3233 }
3234
3235 service = getService(*dbus, bootModeIntf, bootObjPath);
3236 variant = getDbusProperty(*dbus, service, bootObjPath, bootModeIntf,
3237 bootModeProp);
3238
3239 auto bootMode =
3240 Mode::convertModesFromString(std::get<std::string>(variant));
3241
3242 service = getService(*dbus, bootSourceIntf, bootObjPath);
3243 variant = getDbusProperty(*dbus, service, bootObjPath, bootSourceIntf,
3244 bootSourceProp);
3245
3246 if (std::get<std::string>(variant) == httpBootMode)
3247 {
3248 bootOption = httpBoot;
3249 }
3250 else
3251 {
3252 auto bootSource = Source::convertSourcesFromString(
3253 std::get<std::string>(variant));
3254 bootOption = sourceDbusToIpmi.at(bootSource);
3255 if (Source::Sources::Default == bootSource)
3256 {
3257 bootOption = modeDbusToIpmi.at(bootMode);
3258 }
3259 }
3260
3261 uint8_t oneTime = oneTimeEnabled ? setParmBootFlagsValidOneTime
3262 : setParmBootFlagsValidPermanent;
3263 bootOption <<= 2; // shift for responseconstexpr
3264 return ipmi::responseSuccess(setParmVersion, parameter, oneTime,
3265 bootOption);
3266 }
3267 catch (sdbusplus::exception_t& e)
3268 {
3269 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
3270 return ipmi::responseResponseError();
3271 }
3272}
3273
3274ipmi::RspType<> ipmiOemSetEfiBootOptions(uint8_t bootFlag, uint8_t bootParam,
3275 std::optional<uint8_t> bootOption)
3276{
3277 using namespace boot_options;
3278 auto oneTimeEnabled = false;
3279
3280 if (bootFlag == static_cast<uint8_t>(BootOptionParameter::setInProgress))
3281 {
3282 if (bootOption)
3283 {
3284 return ipmi::responseReqDataLenInvalid();
3285 }
3286
3287 if (transferStatus == setInProgress)
3288 {
3289 phosphor::logging::log<phosphor::logging::level::ERR>(
3290 "boot option set in progress!");
3291 return ipmi::responseResponseError();
3292 }
3293
3294 transferStatus = bootParam;
3295 return ipmi::responseSuccess();
3296 }
3297
3298 if (bootFlag != (uint8_t)BootOptionParameter::bootFlags)
3299 {
3300 phosphor::logging::log<phosphor::logging::level::ERR>(
3301 "Unsupported parameter");
3302 return ipmi::responseResponseError();
3303 }
3304
3305 if (!bootOption)
3306 {
3307 return ipmi::responseReqDataLenInvalid();
3308 }
3309
3310 if (((bootOption.value() & bootSourceMask) >> 2) !=
3311 httpBoot) // not http boot, exit
3312 {
3313 phosphor::logging::log<phosphor::logging::level::ERR>(
3314 "wrong boot option parameter!");
3315 return ipmi::responseParmOutOfRange();
3316 }
3317
3318 try
3319 {
3320 bool permanent = (bootParam & setParmBootFlagsPermanent) ==
3321 setParmBootFlagsPermanent;
3322
3323 // read one time Enabled property
3324 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
3325 std::string service = getService(*dbus, enabledIntf, oneTimePath);
3326 Value variant = getDbusProperty(*dbus, service, oneTimePath,
3327 enabledIntf, oneTimeBootEnableProp);
3328 oneTimeEnabled = std::get<bool>(variant);
3329
3330 /*
3331 * Check if the current boot setting is onetime or permanent, if the
3332 * request in the command is otherwise, then set the "Enabled"
3333 * property in one_time object path to 'True' to indicate onetime
3334 * and 'False' to indicate permanent.
3335 *
3336 * Once the onetime/permanent setting is applied, then the bootMode
3337 * and bootSource is updated for the corresponding object.
3338 */
3339 if (permanent == oneTimeEnabled)
3340 {
3341 setDbusProperty(*dbus, service, oneTimePath, enabledIntf,
3342 oneTimeBootEnableProp, !permanent);
3343 }
3344
3345 // set BootSource and BootMode properties
3346 // according to oneTimeEnable or persistent
3347 auto bootObjPath = oneTimePath;
3348 if (oneTimeEnabled == false)
3349 {
3350 bootObjPath = persistentObjPath;
3351 }
3352 std::string bootMode =
3353 "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular";
3354 std::string bootSource = httpBootMode;
3355
3356 service = getService(*dbus, bootModeIntf, bootObjPath);
3357 setDbusProperty(*dbus, service, bootObjPath, bootModeIntf, bootModeProp,
3358 bootMode);
3359
3360 service = getService(*dbus, bootSourceIntf, bootObjPath);
3361 setDbusProperty(*dbus, service, bootObjPath, bootSourceIntf,
3362 bootSourceProp, bootSource);
3363 }
3364 catch (sdbusplus::exception_t& e)
3365 {
3366 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
3367 return ipmi::responseResponseError();
3368 }
3369
3370 return ipmi::responseSuccess();
3371}
3372
Cheng C Yang4e6ee152019-09-25 10:27:44 +08003373using BasicVariantType =
3374 std::variant<std::vector<std::string>, std::vector<uint64_t>, std::string,
3375 int64_t, uint64_t, double, int32_t, uint32_t, int16_t,
3376 uint16_t, uint8_t, bool>;
3377using PropertyMapType =
3378 boost::container::flat_map<std::string, BasicVariantType>;
3379static constexpr const std::array<const char*, 1> psuPresenceTypes = {
3380 "xyz.openbmc_project.Configuration.PSUPresence"};
3381int getPSUAddress(ipmi::Context::ptr ctx, uint8_t& bus,
3382 std::vector<uint64_t>& addrTable)
3383{
3384 boost::system::error_code ec;
3385 GetSubTreeType subtree = ctx->bus->yield_method_call<GetSubTreeType>(
3386 ctx->yield, ec, "xyz.openbmc_project.ObjectMapper",
3387 "/xyz/openbmc_project/object_mapper",
3388 "xyz.openbmc_project.ObjectMapper", "GetSubTree",
3389 "/xyz/openbmc_project/inventory/system", 3, psuPresenceTypes);
3390 if (ec)
3391 {
3392 phosphor::logging::log<phosphor::logging::level::ERR>(
3393 "Failed to set dbus property to cold redundancy");
3394 return -1;
3395 }
3396 for (const auto& object : subtree)
3397 {
3398 std::string pathName = object.first;
3399 for (const auto& serviceIface : object.second)
3400 {
3401 std::string serviceName = serviceIface.first;
3402
3403 ec.clear();
3404 PropertyMapType propMap =
3405 ctx->bus->yield_method_call<PropertyMapType>(
3406 ctx->yield, ec, serviceName, pathName,
3407 "org.freedesktop.DBus.Properties", "GetAll",
3408 "xyz.openbmc_project.Configuration.PSUPresence");
3409 if (ec)
3410 {
3411 phosphor::logging::log<phosphor::logging::level::ERR>(
3412 "Failed to set dbus property to cold redundancy");
3413 return -1;
3414 }
3415 auto psuBus = std::get_if<uint64_t>(&propMap["Bus"]);
3416 auto psuAddress =
3417 std::get_if<std::vector<uint64_t>>(&propMap["Address"]);
3418
3419 if (psuBus == nullptr || psuAddress == nullptr)
3420 {
3421 std::cerr << "error finding necessary "
3422 "entry in configuration\n";
3423 return -1;
3424 }
3425 bus = static_cast<uint8_t>(*psuBus);
3426 addrTable = *psuAddress;
3427 return 0;
3428 }
3429 }
3430 return -1;
3431}
3432
3433static const constexpr uint8_t addrOffset = 8;
3434static const constexpr uint8_t psuRevision = 0xd9;
3435static const constexpr uint8_t defaultPSUBus = 7;
3436// Second Minor, Primary Minor, Major
3437static const constexpr size_t verLen = 3;
3438ipmi::RspType<std::vector<uint8_t>> ipmiOEMGetPSUVersion(ipmi::Context::ptr ctx)
3439{
3440 uint8_t bus = defaultPSUBus;
3441 std::vector<uint64_t> addrTable;
3442 std::vector<uint8_t> result;
3443 if (getPSUAddress(ctx, bus, addrTable))
3444 {
3445 std::cerr << "Failed to get PSU bus and address\n";
3446 return ipmi::responseResponseError();
3447 }
3448
3449 for (const auto& slaveAddr : addrTable)
3450 {
3451 std::vector<uint8_t> writeData = {psuRevision};
3452 std::vector<uint8_t> readBuf(verLen);
3453 uint8_t addr = static_cast<uint8_t>(slaveAddr) + addrOffset;
3454 std::string i2cBus = "/dev/i2c-" + std::to_string(bus);
3455
3456 auto retI2C = ipmi::i2cWriteRead(i2cBus, addr, writeData, readBuf);
3457 if (retI2C != ipmi::ccSuccess)
3458 {
3459 for (size_t idx = 0; idx < verLen; idx++)
3460 {
3461 result.emplace_back(0x00);
3462 }
3463 }
3464 else
3465 {
3466 for (const uint8_t& data : readBuf)
3467 {
3468 result.emplace_back(data);
3469 }
3470 }
3471 }
3472
3473 return ipmi::responseSuccess(result);
3474}
3475
AppaRao Puli28972062019-11-11 02:04:45 +05303476/** @brief implements the maximum size of
3477 * bridgeable messages used between KCS and
3478 * IPMB interfacesget security mode command.
3479 *
3480 * @returns IPMI completion code with following data
3481 * - KCS Buffer Size (In multiples of four bytes)
3482 * - IPMB Buffer Size (In multiples of four bytes)
3483 **/
3484ipmi::RspType<uint8_t, uint8_t> ipmiOEMGetBufferSize()
3485{
3486 // for now this is hard coded; really this number is dependent on
3487 // the BMC kcs driver as well as the host kcs driver....
3488 // we can't know the latter.
3489 uint8_t kcsMaxBufferSize = 63 / 4;
3490 uint8_t ipmbMaxBufferSize = 128 / 4;
3491
3492 return ipmi::responseSuccess(kcsMaxBufferSize, ipmbMaxBufferSize);
3493}
3494
Jason M. Bills64796042018-10-03 16:51:55 -07003495static void registerOEMFunctions(void)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +08003496{
3497 phosphor::logging::log<phosphor::logging::level::INFO>(
3498 "Registering OEM commands");
Vernon Mauery98bbf692019-09-16 11:14:59 -07003499 ipmiPrintAndRegister(intel::netFnGeneral, IPMI_CMD_WILDCARD, NULL,
Jason M. Bills64796042018-10-03 16:51:55 -07003500 ipmiOEMWildcard,
3501 PRIVILEGE_USER); // wildcard default handler
Vernon Mauery98bbf692019-09-16 11:14:59 -07003502
3503 ipmiPrintAndRegister(intel::netFnApp, IPMI_CMD_WILDCARD, NULL,
Jason M. Bills64796042018-10-03 16:51:55 -07003504 ipmiOEMWildcard,
3505 PRIVILEGE_USER); // wildcard default handler
Vernon Mauery98bbf692019-09-16 11:14:59 -07003506
3507 ipmiPrintAndRegister(intel::netFnGeneral,
3508 intel::general::cmdGetChassisIdentifier, NULL,
3509 ipmiOEMGetChassisIdentifier,
3510 PRIVILEGE_USER); // get chassis identifier
3511
3512 ipmiPrintAndRegister(intel::netFnGeneral, intel::general::cmdSetSystemGUID,
3513 NULL, ipmiOEMSetSystemGUID,
3514 PRIVILEGE_ADMIN); // set system guid
Jason M. Billsb02bf092019-08-15 13:01:56 -07003515
3516 // <Disable BMC System Reset Action>
Vernon Mauery98bbf692019-09-16 11:14:59 -07003517 registerHandler(prioOemBase, intel::netFnGeneral,
3518 intel::general::cmdDisableBMCSystemReset, Privilege::Admin,
3519 ipmiOEMDisableBMCSystemReset);
3520
Jason M. Billsb02bf092019-08-15 13:01:56 -07003521 // <Get BMC Reset Disables>
Vernon Mauery98bbf692019-09-16 11:14:59 -07003522 registerHandler(prioOemBase, intel::netFnGeneral,
3523 intel::general::cmdGetBMCResetDisables, Privilege::Admin,
3524 ipmiOEMGetBMCResetDisables);
Jason M. Billsb02bf092019-08-15 13:01:56 -07003525
Vernon Mauery98bbf692019-09-16 11:14:59 -07003526 ipmiPrintAndRegister(intel::netFnGeneral, intel::general::cmdSetBIOSID,
3527 NULL, ipmiOEMSetBIOSID, PRIVILEGE_ADMIN);
Jia, Chunhuicc49b542019-03-20 15:41:07 +08003528
Chen Yugang7a04f3a2019-10-08 11:12:35 +08003529 registerHandler(prioOemBase, intel::netFnGeneral,
3530 intel::general::cmdGetOEMDeviceInfo, Privilege::User,
3531 ipmiOEMGetDeviceInfo);
Jia, Chunhuicc49b542019-03-20 15:41:07 +08003532
Vernon Mauery98bbf692019-09-16 11:14:59 -07003533 ipmiPrintAndRegister(intel::netFnGeneral,
3534 intel::general::cmdGetAICSlotFRUIDSlotPosRecords, NULL,
3535 ipmiOEMGetAICFRU, PRIVILEGE_USER);
Suryakanth Sekard509eb92018-11-15 17:44:11 +05303536
Vernon Mauery98bbf692019-09-16 11:14:59 -07003537 registerHandler(prioOpenBmcBase, intel::netFnGeneral,
3538 intel::general::cmdSendEmbeddedFWUpdStatus,
3539 Privilege::Operator, ipmiOEMSendEmbeddedFwUpdStatus);
Suryakanth Sekard509eb92018-11-15 17:44:11 +05303540
Vernon Mauery98bbf692019-09-16 11:14:59 -07003541 ipmiPrintAndRegister(intel::netFnGeneral,
3542 intel::general::cmdSetPowerRestoreDelay, NULL,
3543 ipmiOEMSetPowerRestoreDelay, PRIVILEGE_OPERATOR);
3544
3545 ipmiPrintAndRegister(intel::netFnGeneral,
3546 intel::general::cmdGetPowerRestoreDelay, NULL,
3547 ipmiOEMGetPowerRestoreDelay, PRIVILEGE_USER);
3548
3549 registerHandler(prioOpenBmcBase, intel::netFnGeneral,
3550 intel::general::cmdSetOEMUser2Activation,
3551 Privilege::Callback, ipmiOEMSetUser2Activation);
3552
3553 registerHandler(prioOpenBmcBase, intel::netFnGeneral,
3554 intel::general::cmdSetSpecialUserPassword,
3555 Privilege::Callback, ipmiOEMSetSpecialUserPassword);
Richard Marian Thomaiyarfc5e9852019-04-14 15:06:27 +05303556
Jason M. Bills42bd9c82019-06-28 16:39:34 -07003557 // <Get Processor Error Config>
Vernon Mauery98bbf692019-09-16 11:14:59 -07003558 registerHandler(prioOemBase, intel::netFnGeneral,
3559 intel::general::cmdGetProcessorErrConfig, Privilege::User,
3560 ipmiOEMGetProcessorErrConfig);
3561
Jason M. Bills42bd9c82019-06-28 16:39:34 -07003562 // <Set Processor Error Config>
Vernon Mauery98bbf692019-09-16 11:14:59 -07003563 registerHandler(prioOemBase, intel::netFnGeneral,
3564 intel::general::cmdSetProcessorErrConfig, Privilege::Admin,
3565 ipmiOEMSetProcessorErrConfig);
Jason M. Bills42bd9c82019-06-28 16:39:34 -07003566
Vernon Mauery98bbf692019-09-16 11:14:59 -07003567 ipmiPrintAndRegister(intel::netFnGeneral,
3568 intel::general::cmdSetShutdownPolicy, NULL,
3569 ipmiOEMSetShutdownPolicy, PRIVILEGE_ADMIN);
James Feist91244a62019-02-19 15:04:54 -08003570
Vernon Mauery98bbf692019-09-16 11:14:59 -07003571 ipmiPrintAndRegister(intel::netFnGeneral,
3572 intel::general::cmdGetShutdownPolicy, NULL,
3573 ipmiOEMGetShutdownPolicy, PRIVILEGE_ADMIN);
James Feist91244a62019-02-19 15:04:54 -08003574
anil kumar appanaf945eee2019-09-25 23:29:11 +00003575 registerHandler(prioOemBase, intel::netFnGeneral,
3576 intel::general::cmdSetFanConfig, Privilege::User,
3577 ipmiOEMSetFanConfig);
James Feist91244a62019-02-19 15:04:54 -08003578
Vernon Mauery98bbf692019-09-16 11:14:59 -07003579 registerHandler(prioOemBase, intel::netFnGeneral,
3580 intel::general::cmdGetFanConfig, Privilege::User,
3581 ipmiOEMGetFanConfig);
James Feist5f957ca2019-03-14 15:33:55 -07003582
Vernon Mauery98bbf692019-09-16 11:14:59 -07003583 registerHandler(prioOemBase, intel::netFnGeneral,
3584 intel::general::cmdGetFanSpeedOffset, Privilege::User,
3585 ipmiOEMGetFanSpeedOffset);
James Feistacc8a4e2019-04-02 14:23:57 -07003586
Vernon Mauery98bbf692019-09-16 11:14:59 -07003587 registerHandler(prioOemBase, intel::netFnGeneral,
3588 intel::general::cmdSetFanSpeedOffset, Privilege::User,
3589 ipmiOEMSetFanSpeedOffset);
James Feistacc8a4e2019-04-02 14:23:57 -07003590
Vernon Mauery98bbf692019-09-16 11:14:59 -07003591 registerHandler(prioOemBase, intel::netFnGeneral,
3592 intel::general::cmdSetFscParameter, Privilege::User,
3593 ipmiOEMSetFscParameter);
James Feist5f957ca2019-03-14 15:33:55 -07003594
Vernon Mauery98bbf692019-09-16 11:14:59 -07003595 registerHandler(prioOemBase, intel::netFnGeneral,
3596 intel::general::cmdGetFscParameter, Privilege::User,
3597 ipmiOEMGetFscParameter);
Richard Marian Thomaiyarea537d52019-04-24 21:33:48 +05303598
Vernon Mauery98bbf692019-09-16 11:14:59 -07003599 registerHandler(prioOpenBmcBase, intel::netFnGeneral,
3600 intel::general::cmdReadBaseBoardProductId, Privilege::Admin,
3601 ipmiOEMReadBoardProductId);
Chen Yugang39736d52019-07-12 16:24:33 +08003602
Vernon Mauery98bbf692019-09-16 11:14:59 -07003603 registerHandler(prioOemBase, intel::netFnGeneral,
3604 intel::general::cmdGetNmiStatus, Privilege::User,
3605 ipmiOEMGetNmiSource);
Chen Yugang39736d52019-07-12 16:24:33 +08003606
Vernon Mauery98bbf692019-09-16 11:14:59 -07003607 registerHandler(prioOemBase, intel::netFnGeneral,
3608 intel::general::cmdSetNmiStatus, Privilege::Operator,
3609 ipmiOEMSetNmiSource);
Chen,Yugang4f7e76b2019-08-20 09:28:06 +08003610
Vernon Mauery98bbf692019-09-16 11:14:59 -07003611 registerHandler(prioOemBase, intel::netFnGeneral,
3612 intel::general::cmdGetEfiBootOptions, Privilege::User,
3613 ipmiOemGetEfiBootOptions);
Chen,Yugang4f7e76b2019-08-20 09:28:06 +08003614
Vernon Mauery98bbf692019-09-16 11:14:59 -07003615 registerHandler(prioOemBase, intel::netFnGeneral,
3616 intel::general::cmdSetEfiBootOptions, Privilege::Operator,
3617 ipmiOemSetEfiBootOptions);
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05303618
Vernon Mauery98bbf692019-09-16 11:14:59 -07003619 registerHandler(prioOemBase, intel::netFnGeneral,
3620 intel::general::cmdGetSecurityMode, Privilege::User,
3621 ipmiGetSecurityMode);
Richard Marian Thomaiyard801e462019-06-20 01:05:40 +05303622
Vernon Mauery98bbf692019-09-16 11:14:59 -07003623 registerHandler(prioOemBase, intel::netFnGeneral,
3624 intel::general::cmdSetSecurityMode, Privilege::Admin,
3625 ipmiSetSecurityMode);
Vernon Mauery4ac799d2019-05-20 15:50:37 -07003626
Vernon Mauery98bbf692019-09-16 11:14:59 -07003627 ipmiPrintAndRegister(intel::netFnGeneral, intel::general::cmdGetLEDStatus,
3628 NULL, ipmiOEMGetLEDStatus, PRIVILEGE_ADMIN);
Cheng C Yang773703a2019-08-15 09:41:11 +08003629
Vernon Mauery98bbf692019-09-16 11:14:59 -07003630 ipmiPrintAndRegister(ipmi::intel::netFnPlatform,
3631 ipmi::intel::platform::cmdCfgHostSerialPortSpeed, NULL,
3632 ipmiOEMCfgHostSerialPortSpeed, PRIVILEGE_ADMIN);
3633
3634 registerHandler(prioOemBase, intel::netFnGeneral,
3635 intel::general::cmdSetFaultIndication, Privilege::Operator,
3636 ipmiOEMSetFaultIndication);
3637
3638 registerHandler(prioOemBase, intel::netFnGeneral,
3639 intel::general::cmdSetColdRedundancyConfig, Privilege::User,
3640 ipmiOEMSetCRConfig);
3641
3642 registerHandler(prioOemBase, intel::netFnGeneral,
3643 intel::general::cmdGetColdRedundancyConfig, Privilege::User,
3644 ipmiOEMGetCRConfig);
3645
3646 registerHandler(prioOemBase, intel::netFnGeneral,
3647 intel::general::cmdRestoreConfiguration, Privilege::Admin,
Vernon Mauery4ac799d2019-05-20 15:50:37 -07003648 ipmiRestoreConfiguration);
James Feist63efafa2019-07-24 12:39:21 -07003649
Vernon Mauery98bbf692019-09-16 11:14:59 -07003650 registerHandler(prioOemBase, intel::netFnGeneral,
3651 intel::general::cmdSetDimmOffset, Privilege::Operator,
3652 ipmiOEMSetDimmOffset);
James Feist63efafa2019-07-24 12:39:21 -07003653
Vernon Mauery98bbf692019-09-16 11:14:59 -07003654 registerHandler(prioOemBase, intel::netFnGeneral,
3655 intel::general::cmdGetDimmOffset, Privilege::Operator,
3656 ipmiOEMGetDimmOffset);
Chen Yugangca12a7b2019-09-03 18:11:44 +08003657
Cheng C Yang4e6ee152019-09-25 10:27:44 +08003658 registerHandler(prioOemBase, intel::netFnGeneral,
3659 intel::general::cmdGetPSUVersion, Privilege::User,
3660 ipmiOEMGetPSUVersion);
AppaRao Puli28972062019-11-11 02:04:45 +05303661
3662 registerHandler(prioOemBase, intel::netFnGeneral,
3663 intel::general::cmdGetBufferSize, Privilege::User,
3664 ipmiOEMGetBufferSize);
Jia, Chunhuia835eaa2018-09-05 09:00:41 +08003665}
3666
3667} // namespace ipmi