blob: 5edc82a3e4098d65582757d95ec8e4627410057b [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
22#include <array>
James Feist91244a62019-02-19 15:04:54 -080023#include <boost/container/flat_map.hpp>
Yong Li23737fe2019-02-19 08:49:55 +080024#include <boost/process/child.hpp>
25#include <boost/process/io.hpp>
Chen Yugang39736d52019-07-12 16:24:33 +080026#include <com/intel/Control/NMISource/server.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>
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080030#include <iostream>
Jia, Chunhuicc49b542019-03-20 15:41:07 +080031#include <ipmid/api.hpp>
Vernon Mauery5480ef62019-03-20 13:43:11 -070032#include <ipmid/utils.hpp>
James Feist63efafa2019-07-24 12:39:21 -070033#include <nlohmann/json.hpp>
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080034#include <oemcommands.hpp>
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080035#include <phosphor-logging/log.hpp>
36#include <sdbusplus/bus.hpp>
Suryakanth Sekard509eb92018-11-15 17:44:11 +053037#include <sdbusplus/message/types.hpp>
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080038#include <string>
James Feist91244a62019-02-19 15:04:54 -080039#include <variant>
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080040#include <vector>
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080041
42namespace ipmi
43{
Jason M. Bills64796042018-10-03 16:51:55 -070044static void registerOEMFunctions() __attribute__((constructor));
Vernon Mauery4ac799d2019-05-20 15:50:37 -070045
46namespace netfn::intel
47{
48constexpr NetFn oemGeneral = netFnOemOne;
49constexpr Cmd cmdRestoreConfiguration = 0x02;
50} // namespace netfn::intel
51
Jason M. Bills64796042018-10-03 16:51:55 -070052static constexpr size_t maxFRUStringLength = 0x3F;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080053
Suryakanth Sekard509eb92018-11-15 17:44:11 +053054static constexpr auto ethernetIntf =
55 "xyz.openbmc_project.Network.EthernetInterface";
56static constexpr auto networkIPIntf = "xyz.openbmc_project.Network.IP";
57static constexpr auto networkService = "xyz.openbmc_project.Network";
58static constexpr auto networkRoot = "/xyz/openbmc_project/network";
59
Chen Yugang39736d52019-07-12 16:24:33 +080060static constexpr const char* oemNmiSourceIntf = "com.intel.Control.NMISource";
61static constexpr const char* oemNmiSourceObjPath =
62 "/com/intel/control/NMISource";
63static constexpr const char* oemNmiBmcSourceObjPathProp = "BMCSource";
64static constexpr const char* oemNmiEnabledObjPathProp = "Enabled";
65
James Feist63efafa2019-07-24 12:39:21 -070066static constexpr const char* dimmOffsetFile = "/var/lib/ipmi/ipmi_dimms.json";
67
Chen Yugang39736d52019-07-12 16:24:33 +080068enum class NmiSource : uint8_t
69{
70 none = 0,
71 fpBtn = 1,
72 wdPreTimeout = 2,
73 pefMatch = 3,
74 chassisCmd = 4,
75 memoryError = 5,
76 pciSerrPerr = 6,
77 southbridgeNmi = 7,
78 chipsetNmi = 8,
79};
80
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080081// return code: 0 successful
82int8_t getChassisSerialNumber(sdbusplus::bus::bus& bus, std::string& serial)
83{
84 std::string objpath = "/xyz/openbmc_project/FruDevice";
85 std::string intf = "xyz.openbmc_project.FruDeviceManager";
86 std::string service = getService(bus, intf, objpath);
87 ObjectValueTree valueTree = getManagedObjects(bus, service, "/");
88 if (valueTree.empty())
89 {
90 phosphor::logging::log<phosphor::logging::level::ERR>(
91 "No object implements interface",
92 phosphor::logging::entry("INTF=%s", intf.c_str()));
93 return -1;
94 }
95
Jason M. Bills64796042018-10-03 16:51:55 -070096 for (const auto& item : valueTree)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +080097 {
98 auto interface = item.second.find("xyz.openbmc_project.FruDevice");
99 if (interface == item.second.end())
100 {
101 continue;
102 }
103
104 auto property = interface->second.find("CHASSIS_SERIAL_NUMBER");
105 if (property == interface->second.end())
106 {
107 continue;
108 }
109
110 try
111 {
112 Value variant = property->second;
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700113 std::string& result = std::get<std::string>(variant);
Jason M. Bills64796042018-10-03 16:51:55 -0700114 if (result.size() > maxFRUStringLength)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800115 {
116 phosphor::logging::log<phosphor::logging::level::ERR>(
117 "FRU serial number exceed maximum length");
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800118 return -1;
119 }
Jason M. Bills64796042018-10-03 16:51:55 -0700120 serial = result;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800121 return 0;
122 }
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700123 catch (std::bad_variant_access& e)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800124 {
Jason M. Bills64796042018-10-03 16:51:55 -0700125 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800126 return -1;
127 }
128 }
129 return -1;
130}
Jason M. Bills64796042018-10-03 16:51:55 -0700131
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800132ipmi_ret_t ipmiOEMWildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
133 ipmi_request_t request, ipmi_response_t response,
Jason M. Bills64796042018-10-03 16:51:55 -0700134 ipmi_data_len_t dataLen, ipmi_context_t context)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800135{
Jason M. Bills64796042018-10-03 16:51:55 -0700136 printCommand(+netfn, +cmd);
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800137 // Status code.
138 ipmi_ret_t rc = IPMI_CC_INVALID;
Jason M. Bills64796042018-10-03 16:51:55 -0700139 *dataLen = 0;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800140 return rc;
141}
142
143// Returns the Chassis Identifier (serial #)
144ipmi_ret_t ipmiOEMGetChassisIdentifier(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
145 ipmi_request_t request,
146 ipmi_response_t response,
Jason M. Bills64796042018-10-03 16:51:55 -0700147 ipmi_data_len_t dataLen,
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800148 ipmi_context_t context)
149{
150 std::string serial;
Jason M. Bills64796042018-10-03 16:51:55 -0700151 if (*dataLen != 0) // invalid request if there are extra parameters
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800152 {
Jason M. Bills64796042018-10-03 16:51:55 -0700153 *dataLen = 0;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800154 return IPMI_CC_REQ_DATA_LEN_INVALID;
155 }
Vernon Mauery15419dd2019-05-24 09:40:30 -0700156 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
157 if (getChassisSerialNumber(*dbus, serial) == 0)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800158 {
Jason M. Bills64796042018-10-03 16:51:55 -0700159 *dataLen = serial.size(); // length will never exceed response length
160 // as it is checked in getChassisSerialNumber
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800161 char* resp = static_cast<char*>(response);
Jason M. Bills64796042018-10-03 16:51:55 -0700162 serial.copy(resp, *dataLen);
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800163 return IPMI_CC_OK;
164 }
Jason M. Bills64796042018-10-03 16:51:55 -0700165 *dataLen = 0;
166 return IPMI_CC_RESPONSE_ERROR;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800167}
168
169ipmi_ret_t ipmiOEMSetSystemGUID(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
170 ipmi_request_t request,
171 ipmi_response_t response,
Jason M. Bills64796042018-10-03 16:51:55 -0700172 ipmi_data_len_t dataLen, ipmi_context_t context)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800173{
174 static constexpr size_t safeBufferLength = 50;
175 char buf[safeBufferLength] = {0};
176 GUIDData* Data = reinterpret_cast<GUIDData*>(request);
177
Jason M. Bills64796042018-10-03 16:51:55 -0700178 if (*dataLen != sizeof(GUIDData)) // 16bytes
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800179 {
Jason M. Bills64796042018-10-03 16:51:55 -0700180 *dataLen = 0;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800181 return IPMI_CC_REQ_DATA_LEN_INVALID;
182 }
183
Jason M. Bills64796042018-10-03 16:51:55 -0700184 *dataLen = 0;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800185
186 snprintf(
187 buf, safeBufferLength,
188 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
189 Data->timeLow4, Data->timeLow3, Data->timeLow2, Data->timeLow1,
190 Data->timeMid2, Data->timeMid1, Data->timeHigh2, Data->timeHigh1,
191 Data->clock2, Data->clock1, Data->node6, Data->node5, Data->node4,
192 Data->node3, Data->node2, Data->node1);
193 // UUID is in RFC4122 format. Ex: 61a39523-78f2-11e5-9862-e6402cfc3223
194 std::string guid = buf;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800195
196 std::string objpath = "/xyz/openbmc_project/control/host0/systemGUID";
197 std::string intf = "xyz.openbmc_project.Common.UUID";
Vernon Mauery15419dd2019-05-24 09:40:30 -0700198 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
199 std::string service = getService(*dbus, intf, objpath);
200 setDbusProperty(*dbus, service, objpath, intf, "UUID", guid);
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800201 return IPMI_CC_OK;
202}
203
204ipmi_ret_t ipmiOEMSetBIOSID(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
205 ipmi_request_t request, ipmi_response_t response,
206 ipmi_data_len_t dataLen, ipmi_context_t context)
207{
208 DeviceInfo* data = reinterpret_cast<DeviceInfo*>(request);
209
Jason M. Bills64796042018-10-03 16:51:55 -0700210 if ((*dataLen < 2) || (*dataLen != (1 + data->biosIDLength)))
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800211 {
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800212 *dataLen = 0;
213 return IPMI_CC_REQ_DATA_LEN_INVALID;
214 }
Jason M. Bills64796042018-10-03 16:51:55 -0700215 std::string idString((char*)data->biosId, data->biosIDLength);
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800216
Vernon Mauery15419dd2019-05-24 09:40:30 -0700217 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
218 std::string service = getService(*dbus, biosIntf, biosObjPath);
219 setDbusProperty(*dbus, service, biosObjPath, biosIntf, biosProp, idString);
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800220 uint8_t* bytesWritten = static_cast<uint8_t*>(response);
221 *bytesWritten =
Jason M. Bills64796042018-10-03 16:51:55 -0700222 data->biosIDLength; // how many bytes are written into storage
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800223 *dataLen = 1;
224 return IPMI_CC_OK;
225}
226
227ipmi_ret_t ipmiOEMGetDeviceInfo(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
228 ipmi_request_t request,
229 ipmi_response_t response,
230 ipmi_data_len_t dataLen, ipmi_context_t context)
231{
232 GetOemDeviceInfoReq* req = reinterpret_cast<GetOemDeviceInfoReq*>(request);
233 GetOemDeviceInfoRes* res = reinterpret_cast<GetOemDeviceInfoRes*>(response);
234
235 if (*dataLen == 0)
236 {
Jason M. Bills64796042018-10-03 16:51:55 -0700237 *dataLen = 0;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800238 return IPMI_CC_REQ_DATA_LEN_INVALID;
239 }
240
241 size_t reqDataLen = *dataLen;
242 *dataLen = 0;
Jason M. Bills64796042018-10-03 16:51:55 -0700243 if (req->entityType > static_cast<uint8_t>(OEMDevEntityType::sdrVer))
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800244 {
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800245 return IPMI_CC_INVALID_FIELD_REQUEST;
246 }
247
248 // handle OEM command items
Jason M. Bills64796042018-10-03 16:51:55 -0700249 switch (OEMDevEntityType(req->entityType))
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800250 {
251 case OEMDevEntityType::biosId:
252 {
253 if (sizeof(GetOemDeviceInfoReq) != reqDataLen)
254 {
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800255 return IPMI_CC_REQ_DATA_LEN_INVALID;
256 }
257
Vernon Mauery15419dd2019-05-24 09:40:30 -0700258 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
259 std::string service = getService(*dbus, biosIntf, biosObjPath);
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800260 try
261 {
Vernon Mauery15419dd2019-05-24 09:40:30 -0700262 Value variant = getDbusProperty(*dbus, service, biosObjPath,
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800263 biosIntf, biosProp);
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700264 std::string& idString = std::get<std::string>(variant);
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800265 if (req->offset >= idString.size())
266 {
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800267 return IPMI_CC_PARM_OUT_OF_RANGE;
268 }
Jason M. Bills64796042018-10-03 16:51:55 -0700269 size_t length = 0;
270 if (req->countToRead > (idString.size() - req->offset))
271 {
272 length = idString.size() - req->offset;
273 }
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800274 else
275 {
Jason M. Bills64796042018-10-03 16:51:55 -0700276 length = req->countToRead;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800277 }
Jason M. Bills64796042018-10-03 16:51:55 -0700278 std::copy(idString.begin() + req->offset, idString.end(),
279 res->data);
280 res->resDatalen = length;
281 *dataLen = res->resDatalen + 1;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800282 }
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700283 catch (std::bad_variant_access& e)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800284 {
Jason M. Bills64796042018-10-03 16:51:55 -0700285 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800286 return IPMI_CC_UNSPECIFIED_ERROR;
287 }
288 }
289 break;
290
291 case OEMDevEntityType::devVer:
292 case OEMDevEntityType::sdrVer:
293 // TODO:
294 return IPMI_CC_ILLEGAL_COMMAND;
295 default:
296 return IPMI_CC_INVALID_FIELD_REQUEST;
297 }
298 return IPMI_CC_OK;
299}
300
301ipmi_ret_t ipmiOEMGetAICFRU(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
302 ipmi_request_t request, ipmi_response_t response,
303 ipmi_data_len_t dataLen, ipmi_context_t context)
304{
305 if (*dataLen != 0)
306 {
Jason M. Bills64796042018-10-03 16:51:55 -0700307 *dataLen = 0;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800308 return IPMI_CC_REQ_DATA_LEN_INVALID;
309 }
310
311 *dataLen = 1;
312 uint8_t* res = reinterpret_cast<uint8_t*>(response);
313 // temporary fix. We don't support AIC FRU now. Just tell BIOS that no
314 // AIC is available so that BIOS will not timeout repeatly which leads to
315 // slow booting.
316 *res = 0; // Byte1=Count of SlotPosition/FruID records.
317 return IPMI_CC_OK;
318}
319
Jason M. Bills64796042018-10-03 16:51:55 -0700320ipmi_ret_t ipmiOEMGetPowerRestoreDelay(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
321 ipmi_request_t request,
322 ipmi_response_t response,
323 ipmi_data_len_t dataLen,
324 ipmi_context_t context)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800325{
Jason M. Bills64796042018-10-03 16:51:55 -0700326 GetPowerRestoreDelayRes* resp =
327 reinterpret_cast<GetPowerRestoreDelayRes*>(response);
328
329 if (*dataLen != 0)
330 {
331 *dataLen = 0;
332 return IPMI_CC_REQ_DATA_LEN_INVALID;
333 }
334
Vernon Mauery15419dd2019-05-24 09:40:30 -0700335 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Jason M. Bills64796042018-10-03 16:51:55 -0700336 std::string service =
Vernon Mauery15419dd2019-05-24 09:40:30 -0700337 getService(*dbus, powerRestoreDelayIntf, powerRestoreDelayObjPath);
Jason M. Bills64796042018-10-03 16:51:55 -0700338 Value variant =
Vernon Mauery15419dd2019-05-24 09:40:30 -0700339 getDbusProperty(*dbus, service, powerRestoreDelayObjPath,
Jason M. Bills64796042018-10-03 16:51:55 -0700340 powerRestoreDelayIntf, powerRestoreDelayProp);
341
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700342 uint16_t delay = std::get<uint16_t>(variant);
Jason M. Bills64796042018-10-03 16:51:55 -0700343 resp->byteLSB = delay;
344 resp->byteMSB = delay >> 8;
345
346 *dataLen = sizeof(GetPowerRestoreDelayRes);
347
348 return IPMI_CC_OK;
Jia, Chunhuia835eaa2018-09-05 09:00:41 +0800349}
350
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800351static uint8_t bcdToDec(uint8_t val)
352{
353 return ((val / 16 * 10) + (val % 16));
354}
355
356// Allows an update utility or system BIOS to send the status of an embedded
357// firmware update attempt to the BMC. After received, BMC will create a logging
358// record.
359ipmi::RspType<> ipmiOEMSendEmbeddedFwUpdStatus(uint8_t status, uint8_t target,
360 uint8_t majorRevision,
361 uint8_t minorRevision,
362 uint32_t auxInfo)
363{
364 std::string firmware;
Jason M. Billsdc249272019-04-03 09:58:40 -0700365 int instance = (target & targetInstanceMask) >> targetInstanceShift;
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800366 target = (target & selEvtTargetMask) >> selEvtTargetShift;
367
368 /* make sure the status is 0, 1, or 2 as per the spec */
369 if (status > 2)
370 {
371 return ipmi::response(ipmi::ccInvalidFieldRequest);
372 }
Jason M. Billsdc249272019-04-03 09:58:40 -0700373 /* make sure the target is 0, 1, 2, or 4 as per the spec */
374 if (target > 4 || target == 3)
375 {
376 return ipmi::response(ipmi::ccInvalidFieldRequest);
377 }
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800378 /*orignal OEM command is to record OEM SEL.
379 But openbmc does not support OEM SEL, so we redirect it to redfish event
380 logging. */
381 std::string buildInfo;
382 std::string action;
383 switch (FWUpdateTarget(target))
384 {
385 case FWUpdateTarget::targetBMC:
386 firmware = "BMC";
Jason M. Billsdc249272019-04-03 09:58:40 -0700387 buildInfo = "major: " + std::to_string(majorRevision) + " minor: " +
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800388 std::to_string(bcdToDec(minorRevision)) + // BCD encoded
389 " BuildID: " + std::to_string(auxInfo);
390 buildInfo += std::to_string(auxInfo);
391 break;
392 case FWUpdateTarget::targetBIOS:
393 firmware = "BIOS";
394 buildInfo =
Jason M. Billsdc249272019-04-03 09:58:40 -0700395 "major: " +
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800396 std::to_string(bcdToDec(majorRevision)) + // BCD encoded
397 " minor: " +
398 std::to_string(bcdToDec(minorRevision)) + // BCD encoded
399 " ReleaseNumber: " + // ASCII encoded
400 std::to_string(static_cast<uint8_t>(auxInfo >> 0) - '0') +
401 std::to_string(static_cast<uint8_t>(auxInfo >> 8) - '0') +
402 std::to_string(static_cast<uint8_t>(auxInfo >> 16) - '0') +
403 std::to_string(static_cast<uint8_t>(auxInfo >> 24) - '0');
404 break;
405 case FWUpdateTarget::targetME:
406 firmware = "ME";
407 buildInfo =
Jason M. Billsdc249272019-04-03 09:58:40 -0700408 "major: " + std::to_string(majorRevision) + " minor1: " +
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800409 std::to_string(bcdToDec(minorRevision)) + // BCD encoded
410 " minor2: " +
411 std::to_string(bcdToDec(static_cast<uint8_t>(auxInfo >> 0))) +
412 " build1: " +
413 std::to_string(bcdToDec(static_cast<uint8_t>(auxInfo >> 8))) +
414 " build2: " +
415 std::to_string(bcdToDec(static_cast<uint8_t>(auxInfo >> 16)));
416 break;
417 case FWUpdateTarget::targetOEMEWS:
418 firmware = "EWS";
Jason M. Billsdc249272019-04-03 09:58:40 -0700419 buildInfo = "major: " + std::to_string(majorRevision) + " minor: " +
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800420 std::to_string(bcdToDec(minorRevision)) + // BCD encoded
421 " BuildID: " + std::to_string(auxInfo);
422 break;
423 }
424
Jason M. Billsdc249272019-04-03 09:58:40 -0700425 static const std::string openBMCMessageRegistryVersion("0.1");
426 std::string redfishMsgID = "OpenBMC." + openBMCMessageRegistryVersion;
427
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800428 switch (status)
429 {
430 case 0x0:
431 action = "update started";
Jason M. Billsdc249272019-04-03 09:58:40 -0700432 redfishMsgID += ".FirmwareUpdateStarted";
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800433 break;
434 case 0x1:
435 action = "update completed successfully";
Jason M. Billsdc249272019-04-03 09:58:40 -0700436 redfishMsgID += ".FirmwareUpdateCompleted";
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800437 break;
438 case 0x2:
439 action = "update failure";
Jason M. Billsdc249272019-04-03 09:58:40 -0700440 redfishMsgID += ".FirmwareUpdateFailed";
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800441 break;
442 default:
443 action = "unknown";
444 break;
445 }
446
Jason M. Billsdc249272019-04-03 09:58:40 -0700447 std::string firmwareInstanceStr =
448 firmware + " instance: " + std::to_string(instance);
449 std::string message("[firmware update] " + firmwareInstanceStr +
450 " status: <" + action + "> " + buildInfo);
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800451
452 sd_journal_send("MESSAGE=%s", message.c_str(), "PRIORITY=%i", LOG_INFO,
Jason M. Billsdc249272019-04-03 09:58:40 -0700453 "REDFISH_MESSAGE_ID=%s", redfishMsgID.c_str(),
454 "REDFISH_MESSAGE_ARGS=%s,%s", firmwareInstanceStr.c_str(),
455 buildInfo.c_str(), NULL);
Jia, Chunhuicc49b542019-03-20 15:41:07 +0800456 return ipmi::responseSuccess();
457}
458
Jason M. Bills64796042018-10-03 16:51:55 -0700459ipmi_ret_t ipmiOEMSetPowerRestoreDelay(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
460 ipmi_request_t request,
461 ipmi_response_t response,
462 ipmi_data_len_t dataLen,
463 ipmi_context_t context)
464{
465 SetPowerRestoreDelayReq* data =
466 reinterpret_cast<SetPowerRestoreDelayReq*>(request);
467 uint16_t delay = 0;
468
469 if (*dataLen != sizeof(SetPowerRestoreDelayReq))
470 {
471 *dataLen = 0;
472 return IPMI_CC_REQ_DATA_LEN_INVALID;
473 }
474 delay = data->byteMSB;
475 delay = (delay << 8) | data->byteLSB;
Vernon Mauery15419dd2019-05-24 09:40:30 -0700476 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Jason M. Bills64796042018-10-03 16:51:55 -0700477 std::string service =
Vernon Mauery15419dd2019-05-24 09:40:30 -0700478 getService(*dbus, powerRestoreDelayIntf, powerRestoreDelayObjPath);
479 setDbusProperty(*dbus, service, powerRestoreDelayObjPath,
Jason M. Bills64796042018-10-03 16:51:55 -0700480 powerRestoreDelayIntf, powerRestoreDelayProp, delay);
481 *dataLen = 0;
482
483 return IPMI_CC_OK;
484}
485
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700486static bool cpuPresent(const std::string& cpuName)
Jason M. Bills64796042018-10-03 16:51:55 -0700487{
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700488 static constexpr const char* cpuPresencePathPrefix =
489 "/xyz/openbmc_project/inventory/system/chassis/motherboard/";
490 static constexpr const char* cpuPresenceIntf =
491 "xyz.openbmc_project.Inventory.Item";
492 std::string cpuPresencePath = cpuPresencePathPrefix + cpuName;
493 std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
494 try
Jason M. Bills64796042018-10-03 16:51:55 -0700495 {
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700496 auto service =
497 ipmi::getService(*busp, cpuPresenceIntf, cpuPresencePath);
498
499 ipmi::Value result = ipmi::getDbusProperty(
500 *busp, service, cpuPresencePath, cpuPresenceIntf, "Present");
501 return std::get<bool>(result);
502 }
503 catch (const std::exception& e)
504 {
505 phosphor::logging::log<phosphor::logging::level::INFO>(
506 "Cannot find processor presence",
507 phosphor::logging::entry("NAME=%s", cpuName.c_str()));
508 return false;
509 }
510}
511
512ipmi::RspType<bool, // CATERR Reset Enabled
513 bool, // ERR2 Reset Enabled
514 uint6_t, // reserved
515 uint8_t, // reserved, returns 0x3F
516 uint6_t, // CPU1 CATERR Count
517 uint2_t, // CPU1 Status
518 uint6_t, // CPU2 CATERR Count
519 uint2_t, // CPU2 Status
520 uint6_t, // CPU3 CATERR Count
521 uint2_t, // CPU3 Status
522 uint6_t, // CPU4 CATERR Count
523 uint2_t, // CPU4 Status
524 uint8_t // Crashdump Count
525 >
526 ipmiOEMGetProcessorErrConfig()
527{
528 bool resetOnCATERR = false;
529 bool resetOnERR2 = false;
530 uint6_t cpu1CATERRCount = 0;
531 uint6_t cpu2CATERRCount = 0;
532 uint6_t cpu3CATERRCount = 0;
533 uint6_t cpu4CATERRCount = 0;
534 uint8_t crashdumpCount = 0;
535 uint2_t cpu1Status =
536 cpuPresent("CPU_1") ? CPUStatus::enabled : CPUStatus::notPresent;
537 uint2_t cpu2Status =
538 cpuPresent("CPU_2") ? CPUStatus::enabled : CPUStatus::notPresent;
539 uint2_t cpu3Status =
540 cpuPresent("CPU_3") ? CPUStatus::enabled : CPUStatus::notPresent;
541 uint2_t cpu4Status =
542 cpuPresent("CPU_4") ? CPUStatus::enabled : CPUStatus::notPresent;
543
544 std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
545 try
546 {
547 auto service = ipmi::getService(*busp, processorErrConfigIntf,
548 processorErrConfigObjPath);
549
550 ipmi::PropertyMap result = ipmi::getAllDbusProperties(
551 *busp, service, processorErrConfigObjPath, processorErrConfigIntf);
552 resetOnCATERR = std::get<bool>(result.at("ResetOnCATERR"));
553 resetOnERR2 = std::get<bool>(result.at("ResetOnERR2"));
554 cpu1CATERRCount = std::get<uint8_t>(result.at("ErrorCountCPU1"));
555 cpu2CATERRCount = std::get<uint8_t>(result.at("ErrorCountCPU2"));
556 cpu3CATERRCount = std::get<uint8_t>(result.at("ErrorCountCPU3"));
557 cpu4CATERRCount = std::get<uint8_t>(result.at("ErrorCountCPU4"));
558 crashdumpCount = std::get<uint8_t>(result.at("CrashdumpCount"));
559 }
560 catch (const std::exception& e)
561 {
562 phosphor::logging::log<phosphor::logging::level::ERR>(
563 "Failed to fetch processor error config",
564 phosphor::logging::entry("ERROR=%s", e.what()));
565 return ipmi::responseUnspecifiedError();
Jason M. Bills64796042018-10-03 16:51:55 -0700566 }
567
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700568 return ipmi::responseSuccess(resetOnCATERR, resetOnERR2, 0, 0x3F,
569 cpu1CATERRCount, cpu1Status, cpu2CATERRCount,
570 cpu2Status, cpu3CATERRCount, cpu3Status,
571 cpu4CATERRCount, cpu4Status, crashdumpCount);
572}
Jason M. Bills64796042018-10-03 16:51:55 -0700573
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700574ipmi::RspType<> ipmiOEMSetProcessorErrConfig(
575 bool resetOnCATERR, bool resetOnERR2, uint6_t reserved1, uint8_t reserved2,
576 std::optional<bool> clearCPUErrorCount,
577 std::optional<bool> clearCrashdumpCount, std::optional<uint6_t> reserved3)
578{
579 std::shared_ptr<sdbusplus::asio::connection> busp = getSdBus();
Jason M. Bills64796042018-10-03 16:51:55 -0700580
581 try
582 {
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700583 auto service = ipmi::getService(*busp, processorErrConfigIntf,
584 processorErrConfigObjPath);
585 ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath,
586 processorErrConfigIntf, "ResetOnCATERR",
587 resetOnCATERR);
588 ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath,
589 processorErrConfigIntf, "ResetOnERR2",
590 resetOnERR2);
591 if (clearCPUErrorCount.value_or(false))
592 {
593 ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath,
594 processorErrConfigIntf, "ErrorCountCPU1", 0);
595 ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath,
596 processorErrConfigIntf, "ErrorCountCPU2", 0);
597 }
598 if (clearCrashdumpCount.value_or(false))
599 {
600 ipmi::setDbusProperty(*busp, service, processorErrConfigObjPath,
601 processorErrConfigIntf, "CrashdumpCount", 0);
602 }
Jason M. Bills64796042018-10-03 16:51:55 -0700603 }
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700604 catch (std::exception& e)
Jason M. Bills64796042018-10-03 16:51:55 -0700605 {
Kuiying Wangbc546672018-11-23 15:41:05 +0800606 phosphor::logging::log<phosphor::logging::level::ERR>(
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700607 "Failed to set processor error config",
608 phosphor::logging::entry("EXCEPTION=%s", e.what()));
609 return ipmi::responseUnspecifiedError();
Jason M. Bills64796042018-10-03 16:51:55 -0700610 }
611
Jason M. Bills42bd9c82019-06-28 16:39:34 -0700612 return ipmi::responseSuccess();
Jason M. Bills64796042018-10-03 16:51:55 -0700613}
614
Yong Li703922d2018-11-06 13:25:31 +0800615ipmi_ret_t ipmiOEMGetShutdownPolicy(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
616 ipmi_request_t request,
617 ipmi_response_t response,
618 ipmi_data_len_t dataLen,
619 ipmi_context_t context)
620{
621 GetOEMShutdownPolicyRes* resp =
622 reinterpret_cast<GetOEMShutdownPolicyRes*>(response);
623
624 if (*dataLen != 0)
625 {
626 phosphor::logging::log<phosphor::logging::level::ERR>(
Kuiying Wang45f04982018-12-26 09:23:08 +0800627 "oem_get_shutdown_policy: invalid input len!");
Yong Li703922d2018-11-06 13:25:31 +0800628 *dataLen = 0;
629 return IPMI_CC_REQ_DATA_LEN_INVALID;
630 }
631
632 *dataLen = 0;
633
634 try
635 {
Vernon Mauery15419dd2019-05-24 09:40:30 -0700636 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Yong Li703922d2018-11-06 13:25:31 +0800637 std::string service =
Vernon Mauery15419dd2019-05-24 09:40:30 -0700638 getService(*dbus, oemShutdownPolicyIntf, oemShutdownPolicyObjPath);
639 Value variant = getDbusProperty(
640 *dbus, service, oemShutdownPolicyObjPath, oemShutdownPolicyIntf,
641 oemShutdownPolicyObjPathProp);
Yong Li0669d192019-05-06 14:01:46 +0800642
643 if (sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::
644 convertPolicyFromString(std::get<std::string>(variant)) ==
645 sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::Policy::
646 NoShutdownOnOCOT)
647 {
648 resp->policy = 0;
649 }
650 else if (sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::
651 convertPolicyFromString(std::get<std::string>(variant)) ==
652 sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::
653 Policy::ShutdownOnOCOT)
654 {
655 resp->policy = 1;
656 }
657 else
658 {
659 phosphor::logging::log<phosphor::logging::level::ERR>(
660 "oem_set_shutdown_policy: invalid property!",
661 phosphor::logging::entry(
662 "PROP=%s", std::get<std::string>(variant).c_str()));
663 return IPMI_CC_UNSPECIFIED_ERROR;
664 }
Yong Li703922d2018-11-06 13:25:31 +0800665 // TODO needs to check if it is multi-node products,
666 // policy is only supported on node 3/4
667 resp->policySupport = shutdownPolicySupported;
668 }
669 catch (sdbusplus::exception_t& e)
670 {
671 phosphor::logging::log<phosphor::logging::level::ERR>(e.description());
672 return IPMI_CC_UNSPECIFIED_ERROR;
673 }
674
675 *dataLen = sizeof(GetOEMShutdownPolicyRes);
676 return IPMI_CC_OK;
677}
678
679ipmi_ret_t ipmiOEMSetShutdownPolicy(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
680 ipmi_request_t request,
681 ipmi_response_t response,
682 ipmi_data_len_t dataLen,
683 ipmi_context_t context)
684{
685 uint8_t* req = reinterpret_cast<uint8_t*>(request);
Yong Li0669d192019-05-06 14:01:46 +0800686 sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::Policy policy =
687 sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::Policy::
688 NoShutdownOnOCOT;
Yong Li703922d2018-11-06 13:25:31 +0800689
690 // TODO needs to check if it is multi-node products,
691 // policy is only supported on node 3/4
692 if (*dataLen != 1)
693 {
694 phosphor::logging::log<phosphor::logging::level::ERR>(
695 "oem_set_shutdown_policy: invalid input len!");
696 *dataLen = 0;
697 return IPMI_CC_REQ_DATA_LEN_INVALID;
698 }
699
700 *dataLen = 0;
701 if ((*req != noShutdownOnOCOT) && (*req != shutdownOnOCOT))
702 {
703 phosphor::logging::log<phosphor::logging::level::ERR>(
704 "oem_set_shutdown_policy: invalid input!");
705 return IPMI_CC_INVALID_FIELD_REQUEST;
706 }
707
Yong Li0669d192019-05-06 14:01:46 +0800708 if (*req == noShutdownOnOCOT)
709 {
710 policy = sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::
711 Policy::NoShutdownOnOCOT;
712 }
713 else
714 {
715 policy = sdbusplus::com::intel::Control::server::OCOTShutdownPolicy::
716 Policy::ShutdownOnOCOT;
717 }
718
Yong Li703922d2018-11-06 13:25:31 +0800719 try
720 {
Vernon Mauery15419dd2019-05-24 09:40:30 -0700721 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Yong Li703922d2018-11-06 13:25:31 +0800722 std::string service =
Vernon Mauery15419dd2019-05-24 09:40:30 -0700723 getService(*dbus, oemShutdownPolicyIntf, oemShutdownPolicyObjPath);
Yong Li0669d192019-05-06 14:01:46 +0800724 setDbusProperty(
Vernon Mauery15419dd2019-05-24 09:40:30 -0700725 *dbus, service, oemShutdownPolicyObjPath, oemShutdownPolicyIntf,
Yong Li0669d192019-05-06 14:01:46 +0800726 oemShutdownPolicyObjPathProp,
727 sdbusplus::com::intel::Control::server::convertForMessage(policy));
Yong Li703922d2018-11-06 13:25:31 +0800728 }
729 catch (sdbusplus::exception_t& e)
730 {
731 phosphor::logging::log<phosphor::logging::level::ERR>(e.description());
732 return IPMI_CC_UNSPECIFIED_ERROR;
733 }
734
735 return IPMI_CC_OK;
736}
737
Suryakanth Sekard509eb92018-11-15 17:44:11 +0530738/** @brief implementation for check the DHCP or not in IPv4
739 * @param[in] Channel - Channel number
740 * @returns true or false.
741 */
742static bool isDHCPEnabled(uint8_t Channel)
743{
744 try
745 {
746 auto ethdevice = getChannelName(Channel);
747 if (ethdevice.empty())
748 {
749 return false;
750 }
751 auto ethIP = ethdevice + "/ipv4";
Vernon Mauery15419dd2019-05-24 09:40:30 -0700752 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Suryakanth Sekard509eb92018-11-15 17:44:11 +0530753 auto ethernetObj =
Vernon Mauery15419dd2019-05-24 09:40:30 -0700754 getDbusObject(*dbus, networkIPIntf, networkRoot, ethIP);
755 auto value = getDbusProperty(*dbus, networkService, ethernetObj.first,
Suryakanth Sekard509eb92018-11-15 17:44:11 +0530756 networkIPIntf, "Origin");
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700757 if (std::get<std::string>(value) ==
Suryakanth Sekard509eb92018-11-15 17:44:11 +0530758 "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP")
759 {
760 return true;
761 }
762 else
763 {
764 return false;
765 }
766 }
767 catch (sdbusplus::exception_t& e)
768 {
769 phosphor::logging::log<phosphor::logging::level::ERR>(e.description());
770 return true;
771 }
772}
773
774/** @brief implementes for check the DHCP or not in IPv6
775 * @param[in] Channel - Channel number
776 * @returns true or false.
777 */
778static bool isDHCPIPv6Enabled(uint8_t Channel)
779{
780
781 try
782 {
783 auto ethdevice = getChannelName(Channel);
784 if (ethdevice.empty())
785 {
786 return false;
787 }
788 auto ethIP = ethdevice + "/ipv6";
Vernon Mauery15419dd2019-05-24 09:40:30 -0700789 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Suryakanth Sekard509eb92018-11-15 17:44:11 +0530790 auto objectInfo =
Vernon Mauery15419dd2019-05-24 09:40:30 -0700791 getDbusObject(*dbus, networkIPIntf, networkRoot, ethIP);
792 auto properties = getAllDbusProperties(*dbus, objectInfo.second,
Suryakanth Sekard509eb92018-11-15 17:44:11 +0530793 objectInfo.first, networkIPIntf);
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700794 if (std::get<std::string>(properties["Origin"]) ==
Suryakanth Sekard509eb92018-11-15 17:44:11 +0530795 "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP")
796 {
797 return true;
798 }
799 else
800 {
801 return false;
802 }
803 }
804 catch (sdbusplus::exception_t& e)
805 {
806 phosphor::logging::log<phosphor::logging::level::ERR>(e.description());
807 return true;
808 }
809}
810
811/** @brief implementes the creating of default new user
812 * @param[in] userName - new username in 16 bytes.
813 * @param[in] userPassword - new password in 20 bytes
814 * @returns ipmi completion code.
815 */
816ipmi::RspType<> ipmiOEMSetUser2Activation(
817 std::array<uint8_t, ipmi::ipmiMaxUserName>& userName,
818 std::array<uint8_t, ipmi::maxIpmi20PasswordSize>& userPassword)
819{
820 bool userState = false;
821 // Check for System Interface not exist and LAN should be static
822 for (uint8_t channel = 0; channel < maxIpmiChannels; channel++)
823 {
824 ChannelInfo chInfo;
825 try
826 {
827 getChannelInfo(channel, chInfo);
828 }
829 catch (sdbusplus::exception_t& e)
830 {
831 phosphor::logging::log<phosphor::logging::level::ERR>(
832 "ipmiOEMSetUser2Activation: Failed to get Channel Info",
833 phosphor::logging::entry("MSG: %s", e.description()));
834 return ipmi::response(ipmi::ccUnspecifiedError);
835 }
836 if (chInfo.mediumType ==
837 static_cast<uint8_t>(EChannelMediumType::systemInterface))
838 {
839 phosphor::logging::log<phosphor::logging::level::ERR>(
840 "ipmiOEMSetUser2Activation: system interface exist .");
841 return ipmi::response(ipmi::ccCommandNotAvailable);
842 }
843 else
844 {
845
846 if (chInfo.mediumType ==
847 static_cast<uint8_t>(EChannelMediumType::lan8032))
848 {
849 if (isDHCPIPv6Enabled(channel) || isDHCPEnabled(channel))
850 {
851 phosphor::logging::log<phosphor::logging::level::ERR>(
852 "ipmiOEMSetUser2Activation: DHCP enabled .");
853 return ipmi::response(ipmi::ccCommandNotAvailable);
854 }
855 }
856 }
857 }
858 uint8_t maxChUsers = 0, enabledUsers = 0, fixedUsers = 0;
859 if (ipmi::ccSuccess ==
860 ipmiUserGetAllCounts(maxChUsers, enabledUsers, fixedUsers))
861 {
862 if (enabledUsers > 1)
863 {
864 phosphor::logging::log<phosphor::logging::level::ERR>(
865 "ipmiOEMSetUser2Activation: more than one user is enabled.");
866 return ipmi::response(ipmi::ccCommandNotAvailable);
867 }
868 // Check the user 2 is enabled or not
869 ipmiUserCheckEnabled(ipmiDefaultUserId, userState);
870 if (userState == true)
871 {
872 phosphor::logging::log<phosphor::logging::level::ERR>(
873 "ipmiOEMSetUser2Activation: user 2 already enabled .");
874 return ipmi::response(ipmi::ccCommandNotAvailable);
875 }
876 }
877 else
878 {
879 return ipmi::response(ipmi::ccUnspecifiedError);
880 }
881
882#if BYTE_ORDER == LITTLE_ENDIAN
883 PrivAccess privAccess = {PRIVILEGE_ADMIN, true, true, true, 0};
884#endif
885#if BYTE_ORDER == BIG_ENDIAN
886 PrivAccess privAccess = {0, true, true, true, PRIVILEGE_ADMIN};
887#endif
888
889 if (ipmi::ccSuccess ==
890 ipmiUserSetUserName(ipmiDefaultUserId,
891 reinterpret_cast<const char*>(userName.data())))
892 {
893 if (ipmi::ccSuccess ==
894 ipmiUserSetUserPassword(
895 ipmiDefaultUserId,
896 reinterpret_cast<const char*>(userPassword.data())))
897 {
898 if (ipmi::ccSuccess ==
899 ipmiUserSetPrivilegeAccess(
900 ipmiDefaultUserId,
901 static_cast<uint8_t>(ipmi::EChannelID::chanLan1),
902 privAccess, true))
903 {
904 phosphor::logging::log<phosphor::logging::level::INFO>(
905 "ipmiOEMSetUser2Activation: user created successfully ");
906 return ipmi::responseSuccess();
907 }
908 }
909 // we need to delete the default user id which added in this command as
910 // password / priv setting is failed.
911 ipmiUserSetUserName(ipmiDefaultUserId, "");
912 phosphor::logging::log<phosphor::logging::level::ERR>(
913 "ipmiOEMSetUser2Activation: password / priv setting is failed.");
914 }
915 else
916 {
917 phosphor::logging::log<phosphor::logging::level::ERR>(
918 "ipmiOEMSetUser2Activation: Setting username failed.");
919 }
920
921 return ipmi::response(ipmi::ccCommandNotAvailable);
922}
923
Richard Marian Thomaiyarfc5e9852019-04-14 15:06:27 +0530924/** @brief implementes setting password for special user
925 * @param[in] specialUserIndex
926 * @param[in] userPassword - new password in 20 bytes
927 * @returns ipmi completion code.
928 */
929ipmi::RspType<> ipmiOEMSetSpecialUserPassword(ipmi::Context::ptr ctx,
930 uint8_t specialUserIndex,
931 std::vector<uint8_t> userPassword)
932{
933 ChannelInfo chInfo;
934 try
935 {
936 getChannelInfo(ctx->channel, chInfo);
937 }
938 catch (sdbusplus::exception_t& e)
939 {
940 phosphor::logging::log<phosphor::logging::level::ERR>(
941 "ipmiOEMSetSpecialUserPassword: Failed to get Channel Info",
942 phosphor::logging::entry("MSG: %s", e.description()));
943 return ipmi::responseUnspecifiedError();
944 }
945 if (chInfo.mediumType !=
946 static_cast<uint8_t>(EChannelMediumType::systemInterface))
947 {
948 phosphor::logging::log<phosphor::logging::level::ERR>(
949 "ipmiOEMSetSpecialUserPassword: Error - supported only in KCS "
950 "interface");
951 return ipmi::responseCommandNotAvailable();
952 }
953 if (specialUserIndex != 0)
954 {
955 phosphor::logging::log<phosphor::logging::level::ERR>(
956 "ipmiOEMSetSpecialUserPassword: Invalid user account");
957 return ipmi::responseParmOutOfRange();
958 }
959 constexpr uint8_t minPasswordSizeRequired = 6;
960 if (userPassword.size() < minPasswordSizeRequired ||
961 userPassword.size() > ipmi::maxIpmi20PasswordSize)
962 {
963 return ipmi::responseReqDataLenInvalid();
964 }
965 std::string passwd;
966 passwd.assign(reinterpret_cast<const char*>(userPassword.data()),
967 userPassword.size());
968 return ipmi::response(ipmiSetSpecialUserPassword("root", passwd));
969}
970
Kuiying Wang45f04982018-12-26 09:23:08 +0800971namespace ledAction
972{
973using namespace sdbusplus::xyz::openbmc_project::Led::server;
974std::map<Physical::Action, uint8_t> actionDbusToIpmi = {
975 {Physical::Action::Off, 0x00},
976 {Physical::Action::On, 0x10},
977 {Physical::Action::Blink, 0x01}};
978
979std::map<uint8_t, std::string> offsetObjPath = {
980 {2, statusAmberObjPath}, {4, statusGreenObjPath}, {6, identifyLEDObjPath}};
981
982} // namespace ledAction
983
984int8_t getLEDState(sdbusplus::bus::bus& bus, const std::string& intf,
985 const std::string& objPath, uint8_t& state)
986{
987 try
988 {
989 std::string service = getService(bus, intf, objPath);
990 Value stateValue =
991 getDbusProperty(bus, service, objPath, intf, "State");
Vernon Mauery8166c8d2019-05-23 11:22:30 -0700992 std::string strState = std::get<std::string>(stateValue);
Kuiying Wang45f04982018-12-26 09:23:08 +0800993 state = ledAction::actionDbusToIpmi.at(
994 sdbusplus::xyz::openbmc_project::Led::server::Physical::
995 convertActionFromString(strState));
996 }
997 catch (sdbusplus::exception::SdBusError& e)
998 {
999 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
1000 return -1;
1001 }
1002 return 0;
1003}
1004
1005ipmi_ret_t ipmiOEMGetLEDStatus(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
1006 ipmi_request_t request, ipmi_response_t response,
1007 ipmi_data_len_t dataLen, ipmi_context_t context)
1008{
1009 uint8_t* resp = reinterpret_cast<uint8_t*>(response);
1010 // LED Status
1011 //[1:0] = Reserved
1012 //[3:2] = Status(Amber)
1013 //[5:4] = Status(Green)
1014 //[7:6] = System Identify
1015 // Status definitions:
1016 // 00b = Off
1017 // 01b = Blink
1018 // 10b = On
1019 // 11b = invalid
1020 if (*dataLen != 0)
1021 {
1022 phosphor::logging::log<phosphor::logging::level::ERR>(
1023 "oem_get_led_status: invalid input len!");
1024 *dataLen = 0;
1025 return IPMI_CC_REQ_DATA_LEN_INVALID;
1026 }
1027
1028 phosphor::logging::log<phosphor::logging::level::DEBUG>("GET led status");
1029 *resp = 0;
1030 *dataLen = 0;
Vernon Mauery15419dd2019-05-24 09:40:30 -07001031 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Kuiying Wang45f04982018-12-26 09:23:08 +08001032 for (auto it = ledAction::offsetObjPath.begin();
1033 it != ledAction::offsetObjPath.end(); ++it)
1034 {
1035 uint8_t state = 0;
Vernon Mauery15419dd2019-05-24 09:40:30 -07001036 if (-1 == getLEDState(*dbus, ledIntf, it->second, state))
Kuiying Wang45f04982018-12-26 09:23:08 +08001037 {
1038 phosphor::logging::log<phosphor::logging::level::ERR>(
1039 "oem_get_led_status: fail to get ID LED status!");
1040 return IPMI_CC_UNSPECIFIED_ERROR;
1041 }
1042 *resp |= state << it->first;
1043 }
1044
1045 *dataLen = sizeof(*resp);
1046 return IPMI_CC_OK;
1047}
1048
Yong Li23737fe2019-02-19 08:49:55 +08001049ipmi_ret_t ipmiOEMCfgHostSerialPortSpeed(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
1050 ipmi_request_t request,
1051 ipmi_response_t response,
1052 ipmi_data_len_t dataLen,
1053 ipmi_context_t context)
1054{
1055 CfgHostSerialReq* req = reinterpret_cast<CfgHostSerialReq*>(request);
1056 uint8_t* resp = reinterpret_cast<uint8_t*>(response);
1057
1058 if (*dataLen == 0)
1059 {
1060 phosphor::logging::log<phosphor::logging::level::ERR>(
1061 "CfgHostSerial: invalid input len!",
1062 phosphor::logging::entry("LEN=%d", *dataLen));
1063 return IPMI_CC_REQ_DATA_LEN_INVALID;
1064 }
1065
1066 switch (req->command)
1067 {
1068 case getHostSerialCfgCmd:
1069 {
1070 if (*dataLen != 1)
1071 {
1072 phosphor::logging::log<phosphor::logging::level::ERR>(
1073 "CfgHostSerial: invalid input len!");
1074 *dataLen = 0;
1075 return IPMI_CC_REQ_DATA_LEN_INVALID;
1076 }
1077
1078 *dataLen = 0;
1079
1080 boost::process::ipstream is;
1081 std::vector<std::string> data;
1082 std::string line;
1083 boost::process::child c1(fwGetEnvCmd, "-n", fwHostSerailCfgEnvName,
1084 boost::process::std_out > is);
1085
1086 while (c1.running() && std::getline(is, line) && !line.empty())
1087 {
1088 data.push_back(line);
1089 }
1090
1091 c1.wait();
1092 if (c1.exit_code())
1093 {
1094 phosphor::logging::log<phosphor::logging::level::ERR>(
1095 "CfgHostSerial:: error on execute",
1096 phosphor::logging::entry("EXECUTE=%s", fwSetEnvCmd));
1097 // Using the default value
1098 *resp = 0;
1099 }
1100 else
1101 {
1102 if (data.size() != 1)
1103 {
1104 phosphor::logging::log<phosphor::logging::level::ERR>(
1105 "CfgHostSerial:: error on read env");
1106 return IPMI_CC_UNSPECIFIED_ERROR;
1107 }
1108 try
1109 {
1110 unsigned long tmp = std::stoul(data[0]);
1111 if (tmp > std::numeric_limits<uint8_t>::max())
1112 {
1113 throw std::out_of_range("Out of range");
1114 }
1115 *resp = static_cast<uint8_t>(tmp);
1116 }
1117 catch (const std::invalid_argument& e)
1118 {
1119 phosphor::logging::log<phosphor::logging::level::ERR>(
1120 "invalid config ",
1121 phosphor::logging::entry("ERR=%s", e.what()));
1122 return IPMI_CC_UNSPECIFIED_ERROR;
1123 }
1124 catch (const std::out_of_range& e)
1125 {
1126 phosphor::logging::log<phosphor::logging::level::ERR>(
1127 "out_of_range config ",
1128 phosphor::logging::entry("ERR=%s", e.what()));
1129 return IPMI_CC_UNSPECIFIED_ERROR;
1130 }
1131 }
1132
1133 *dataLen = 1;
1134 break;
1135 }
1136 case setHostSerialCfgCmd:
1137 {
1138 if (*dataLen != sizeof(CfgHostSerialReq))
1139 {
1140 phosphor::logging::log<phosphor::logging::level::ERR>(
1141 "CfgHostSerial: invalid input len!");
1142 *dataLen = 0;
1143 return IPMI_CC_REQ_DATA_LEN_INVALID;
1144 }
1145
1146 *dataLen = 0;
1147
1148 if (req->parameter > HostSerialCfgParamMax)
1149 {
1150 phosphor::logging::log<phosphor::logging::level::ERR>(
1151 "CfgHostSerial: invalid input!");
1152 return IPMI_CC_INVALID_FIELD_REQUEST;
1153 }
1154
1155 boost::process::child c1(fwSetEnvCmd, fwHostSerailCfgEnvName,
1156 std::to_string(req->parameter));
1157
1158 c1.wait();
1159 if (c1.exit_code())
1160 {
1161 phosphor::logging::log<phosphor::logging::level::ERR>(
1162 "CfgHostSerial:: error on execute",
1163 phosphor::logging::entry("EXECUTE=%s", fwGetEnvCmd));
1164 return IPMI_CC_UNSPECIFIED_ERROR;
1165 }
1166 break;
1167 }
1168 default:
1169 phosphor::logging::log<phosphor::logging::level::ERR>(
1170 "CfgHostSerial: invalid input!");
1171 *dataLen = 0;
1172 return IPMI_CC_INVALID_FIELD_REQUEST;
1173 }
1174
1175 return IPMI_CC_OK;
1176}
1177
James Feist91244a62019-02-19 15:04:54 -08001178constexpr const char* thermalModeInterface =
1179 "xyz.openbmc_project.Control.ThermalMode";
1180constexpr const char* thermalModePath =
1181 "/xyz/openbmc_project/control/thermal_mode";
1182
1183bool getFanProfileInterface(
1184 sdbusplus::bus::bus& bus,
1185 boost::container::flat_map<
1186 std::string, std::variant<std::vector<std::string>, std::string>>& resp)
1187{
1188 auto call = bus.new_method_call(settingsBusName, thermalModePath, PROP_INTF,
1189 "GetAll");
1190 call.append(thermalModeInterface);
1191 try
1192 {
1193 auto data = bus.call(call);
1194 data.read(resp);
1195 }
1196 catch (sdbusplus::exception_t& e)
1197 {
1198 phosphor::logging::log<phosphor::logging::level::ERR>(
1199 "getFanProfileInterface: can't get thermal mode!",
1200 phosphor::logging::entry("ERR=%s", e.what()));
1201 return false;
1202 }
1203 return true;
1204}
1205
1206ipmi_ret_t ipmiOEMSetFanConfig(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
1207 ipmi_request_t request, ipmi_response_t response,
1208 ipmi_data_len_t dataLen, ipmi_context_t context)
1209{
1210
1211 if (*dataLen < 2 || *dataLen > 7)
1212 {
1213 phosphor::logging::log<phosphor::logging::level::ERR>(
1214 "ipmiOEMSetFanConfig: invalid input len!");
1215 *dataLen = 0;
1216 return IPMI_CC_REQ_DATA_LEN_INVALID;
1217 }
1218
1219 // todo: tell bios to only send first 2 bytes
1220
1221 SetFanConfigReq* req = reinterpret_cast<SetFanConfigReq*>(request);
1222 boost::container::flat_map<
1223 std::string, std::variant<std::vector<std::string>, std::string>>
1224 profileData;
Vernon Mauery15419dd2019-05-24 09:40:30 -07001225 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
1226 if (!getFanProfileInterface(*dbus, profileData))
James Feist91244a62019-02-19 15:04:54 -08001227 {
1228 return IPMI_CC_UNSPECIFIED_ERROR;
1229 }
1230
1231 std::vector<std::string>* supported =
1232 std::get_if<std::vector<std::string>>(&profileData["Supported"]);
1233 if (supported == nullptr)
1234 {
1235 return IPMI_CC_INVALID_FIELD_REQUEST;
1236 }
1237 std::string mode;
1238 if (req->flags &
1239 (1 << static_cast<uint8_t>(setFanProfileFlags::setPerfAcousMode)))
1240 {
1241 bool performanceMode =
1242 (req->flags & (1 << static_cast<uint8_t>(
1243 setFanProfileFlags::performAcousSelect))) > 0;
1244
1245 if (performanceMode)
1246 {
1247
1248 if (std::find(supported->begin(), supported->end(),
1249 "Performance") != supported->end())
1250 {
1251 mode = "Performance";
1252 }
1253 }
1254 else
1255 {
1256
1257 if (std::find(supported->begin(), supported->end(), "Acoustic") !=
1258 supported->end())
1259 {
1260 mode = "Acoustic";
1261 }
1262 }
1263 if (mode.empty())
1264 {
1265 return IPMI_CC_INVALID_FIELD_REQUEST;
1266 }
Vernon Mauery15419dd2019-05-24 09:40:30 -07001267 setDbusProperty(*dbus, settingsBusName, thermalModePath,
James Feist91244a62019-02-19 15:04:54 -08001268 thermalModeInterface, "Current", mode);
1269 }
1270
1271 return IPMI_CC_OK;
1272}
1273
James Feist5b693632019-07-09 09:06:09 -07001274ipmi::RspType<uint8_t, // profile support map
1275 uint8_t, // fan control profile enable
1276 uint8_t, // flags
1277 uint32_t // dimm presence bit map
1278 >
1279 ipmiOEMGetFanConfig(uint8_t dimmGroupId)
James Feist91244a62019-02-19 15:04:54 -08001280{
James Feist91244a62019-02-19 15:04:54 -08001281 boost::container::flat_map<
1282 std::string, std::variant<std::vector<std::string>, std::string>>
1283 profileData;
1284
Vernon Mauery15419dd2019-05-24 09:40:30 -07001285 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
1286 if (!getFanProfileInterface(*dbus, profileData))
James Feist91244a62019-02-19 15:04:54 -08001287 {
James Feist5b693632019-07-09 09:06:09 -07001288 return ipmi::responseResponseError();
James Feist91244a62019-02-19 15:04:54 -08001289 }
1290
1291 std::string* current = std::get_if<std::string>(&profileData["Current"]);
1292
1293 if (current == nullptr)
1294 {
1295 phosphor::logging::log<phosphor::logging::level::ERR>(
1296 "ipmiOEMGetFanConfig: can't get current mode!");
James Feist5b693632019-07-09 09:06:09 -07001297 return ipmi::responseResponseError();
James Feist91244a62019-02-19 15:04:54 -08001298 }
1299 bool performance = (*current == "Performance");
1300
James Feist5b693632019-07-09 09:06:09 -07001301 uint8_t flags = 0;
James Feist91244a62019-02-19 15:04:54 -08001302 if (performance)
1303 {
James Feist5b693632019-07-09 09:06:09 -07001304 flags |= 1 << 2;
James Feist91244a62019-02-19 15:04:54 -08001305 }
1306
James Feist5b693632019-07-09 09:06:09 -07001307 return ipmi::responseSuccess(0, 0, flags, 0);
James Feist91244a62019-02-19 15:04:54 -08001308}
James Feist5f957ca2019-03-14 15:33:55 -07001309constexpr const char* cfmLimitSettingPath =
1310 "/xyz/openbmc_project/control/cfm_limit";
1311constexpr const char* cfmLimitIface = "xyz.openbmc_project.Control.CFMLimit";
James Feistfaa4f222019-03-21 16:21:55 -07001312constexpr const size_t legacyExitAirSensorNumber = 0x2e;
James Feistacc8a4e2019-04-02 14:23:57 -07001313constexpr const char* pidConfigurationIface =
1314 "xyz.openbmc_project.Configuration.Pid";
James Feistfaa4f222019-03-21 16:21:55 -07001315
1316static std::string getExitAirConfigPath()
1317{
Vernon Mauery15419dd2019-05-24 09:40:30 -07001318 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
James Feistfaa4f222019-03-21 16:21:55 -07001319 auto method =
Vernon Mauery15419dd2019-05-24 09:40:30 -07001320 dbus->new_method_call("xyz.openbmc_project.ObjectMapper",
1321 "/xyz/openbmc_project/object_mapper",
1322 "xyz.openbmc_project.ObjectMapper", "GetSubTree");
James Feistfaa4f222019-03-21 16:21:55 -07001323
James Feistacc8a4e2019-04-02 14:23:57 -07001324 method.append("/", 0, std::array<const char*, 1>{pidConfigurationIface});
James Feistfaa4f222019-03-21 16:21:55 -07001325 std::string path;
1326 GetSubTreeType resp;
1327 try
1328 {
Vernon Mauery15419dd2019-05-24 09:40:30 -07001329 auto reply = dbus->call(method);
James Feistfaa4f222019-03-21 16:21:55 -07001330 reply.read(resp);
1331 }
1332 catch (sdbusplus::exception_t&)
1333 {
1334 phosphor::logging::log<phosphor::logging::level::ERR>(
1335 "ipmiOEMGetFscParameter: mapper error");
1336 };
1337 auto config = std::find_if(resp.begin(), resp.end(), [](const auto& pair) {
1338 return pair.first.find("Exit_Air") != std::string::npos;
1339 });
1340 if (config != resp.end())
1341 {
1342 path = std::move(config->first);
1343 }
1344 return path;
1345}
James Feist5f957ca2019-03-14 15:33:55 -07001346
James Feistacc8a4e2019-04-02 14:23:57 -07001347// flat map to make alphabetical
1348static boost::container::flat_map<std::string, PropertyMap> getPidConfigs()
1349{
1350 boost::container::flat_map<std::string, PropertyMap> ret;
Vernon Mauery15419dd2019-05-24 09:40:30 -07001351 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
James Feistacc8a4e2019-04-02 14:23:57 -07001352 auto method =
Vernon Mauery15419dd2019-05-24 09:40:30 -07001353 dbus->new_method_call("xyz.openbmc_project.ObjectMapper",
1354 "/xyz/openbmc_project/object_mapper",
1355 "xyz.openbmc_project.ObjectMapper", "GetSubTree");
James Feistacc8a4e2019-04-02 14:23:57 -07001356
1357 method.append("/", 0, std::array<const char*, 1>{pidConfigurationIface});
1358 GetSubTreeType resp;
1359
1360 try
1361 {
Vernon Mauery15419dd2019-05-24 09:40:30 -07001362 auto reply = dbus->call(method);
James Feistacc8a4e2019-04-02 14:23:57 -07001363 reply.read(resp);
1364 }
1365 catch (sdbusplus::exception_t&)
1366 {
1367 phosphor::logging::log<phosphor::logging::level::ERR>(
1368 "getFanConfigPaths: mapper error");
1369 };
1370 for (const auto& [path, objects] : resp)
1371 {
1372 if (objects.empty())
1373 {
1374 continue; // should be impossible
1375 }
Zhu, Yungebe560b02019-04-21 21:19:21 -04001376
1377 try
1378 {
Vernon Mauery15419dd2019-05-24 09:40:30 -07001379 ret.emplace(path,
1380 getAllDbusProperties(*dbus, objects[0].first, path,
1381 pidConfigurationIface));
Zhu, Yungebe560b02019-04-21 21:19:21 -04001382 }
1383 catch (sdbusplus::exception_t& e)
1384 {
1385 phosphor::logging::log<phosphor::logging::level::ERR>(
1386 "getPidConfigs: can't get DbusProperties!",
1387 phosphor::logging::entry("ERR=%s", e.what()));
1388 }
James Feistacc8a4e2019-04-02 14:23:57 -07001389 }
1390 return ret;
1391}
1392
1393ipmi::RspType<uint8_t> ipmiOEMGetFanSpeedOffset(void)
1394{
1395 boost::container::flat_map<std::string, PropertyMap> data = getPidConfigs();
1396 if (data.empty())
1397 {
1398 return ipmi::responseResponseError();
1399 }
1400 uint8_t minOffset = std::numeric_limits<uint8_t>::max();
1401 for (const auto& [_, pid] : data)
1402 {
1403 auto findClass = pid.find("Class");
1404 if (findClass == pid.end())
1405 {
1406 phosphor::logging::log<phosphor::logging::level::ERR>(
1407 "ipmiOEMGetFscParameter: found illegal pid "
1408 "configurations");
1409 return ipmi::responseResponseError();
1410 }
1411 std::string type = std::get<std::string>(findClass->second);
1412 if (type == "fan")
1413 {
1414 auto findOutLimit = pid.find("OutLimitMin");
1415 if (findOutLimit == pid.end())
1416 {
1417 phosphor::logging::log<phosphor::logging::level::ERR>(
1418 "ipmiOEMGetFscParameter: found illegal pid "
1419 "configurations");
1420 return ipmi::responseResponseError();
1421 }
1422 // get the min out of all the offsets
1423 minOffset = std::min(
1424 minOffset,
1425 static_cast<uint8_t>(std::get<double>(findOutLimit->second)));
1426 }
1427 }
1428 if (minOffset == std::numeric_limits<uint8_t>::max())
1429 {
1430 phosphor::logging::log<phosphor::logging::level::ERR>(
1431 "ipmiOEMGetFscParameter: found no fan configurations!");
1432 return ipmi::responseResponseError();
1433 }
1434
1435 return ipmi::responseSuccess(minOffset);
1436}
1437
1438ipmi::RspType<> ipmiOEMSetFanSpeedOffset(uint8_t offset)
1439{
1440 boost::container::flat_map<std::string, PropertyMap> data = getPidConfigs();
1441 if (data.empty())
1442 {
1443
1444 phosphor::logging::log<phosphor::logging::level::ERR>(
1445 "ipmiOEMSetFanSpeedOffset: found no pid configurations!");
1446 return ipmi::responseResponseError();
1447 }
1448
Vernon Mauery15419dd2019-05-24 09:40:30 -07001449 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
James Feistacc8a4e2019-04-02 14:23:57 -07001450 bool found = false;
1451 for (const auto& [path, pid] : data)
1452 {
1453 auto findClass = pid.find("Class");
1454 if (findClass == pid.end())
1455 {
1456
1457 phosphor::logging::log<phosphor::logging::level::ERR>(
1458 "ipmiOEMSetFanSpeedOffset: found illegal pid "
1459 "configurations");
1460 return ipmi::responseResponseError();
1461 }
1462 std::string type = std::get<std::string>(findClass->second);
1463 if (type == "fan")
1464 {
1465 auto findOutLimit = pid.find("OutLimitMin");
1466 if (findOutLimit == pid.end())
1467 {
1468
1469 phosphor::logging::log<phosphor::logging::level::ERR>(
1470 "ipmiOEMSetFanSpeedOffset: found illegal pid "
1471 "configurations");
1472 return ipmi::responseResponseError();
1473 }
Vernon Mauery15419dd2019-05-24 09:40:30 -07001474 ipmi::setDbusProperty(*dbus, "xyz.openbmc_project.EntityManager",
James Feistacc8a4e2019-04-02 14:23:57 -07001475 path, pidConfigurationIface, "OutLimitMin",
1476 static_cast<double>(offset));
1477 found = true;
1478 }
1479 }
1480 if (!found)
1481 {
1482 phosphor::logging::log<phosphor::logging::level::ERR>(
1483 "ipmiOEMSetFanSpeedOffset: set no fan offsets");
1484 return ipmi::responseResponseError();
1485 }
1486
1487 return ipmi::responseSuccess();
1488}
1489
1490ipmi::RspType<> ipmiOEMSetFscParameter(uint8_t command, uint8_t param1,
1491 uint8_t param2)
James Feist5f957ca2019-03-14 15:33:55 -07001492{
1493 constexpr const size_t disableLimiting = 0x0;
1494
Vernon Mauery15419dd2019-05-24 09:40:30 -07001495 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
James Feistacc8a4e2019-04-02 14:23:57 -07001496 if (command == static_cast<uint8_t>(setFscParamFlags::tcontrol))
James Feist5f957ca2019-03-14 15:33:55 -07001497 {
James Feistacc8a4e2019-04-02 14:23:57 -07001498 if (param1 == legacyExitAirSensorNumber)
James Feistfaa4f222019-03-21 16:21:55 -07001499 {
James Feistfaa4f222019-03-21 16:21:55 -07001500 std::string path = getExitAirConfigPath();
Vernon Mauery15419dd2019-05-24 09:40:30 -07001501 ipmi::setDbusProperty(*dbus, "xyz.openbmc_project.EntityManager",
James Feistacc8a4e2019-04-02 14:23:57 -07001502 path, pidConfigurationIface, "SetPoint",
1503 static_cast<double>(param2));
1504 return ipmi::responseSuccess();
James Feistfaa4f222019-03-21 16:21:55 -07001505 }
1506 else
1507 {
James Feistacc8a4e2019-04-02 14:23:57 -07001508 return ipmi::responseParmOutOfRange();
James Feistfaa4f222019-03-21 16:21:55 -07001509 }
1510 }
James Feistacc8a4e2019-04-02 14:23:57 -07001511 else if (command == static_cast<uint8_t>(setFscParamFlags::cfm))
James Feist5f957ca2019-03-14 15:33:55 -07001512 {
James Feistacc8a4e2019-04-02 14:23:57 -07001513 uint16_t cfm = param1 | (static_cast<uint16_t>(param2) << 8);
James Feist5f957ca2019-03-14 15:33:55 -07001514
1515 // must be greater than 50 based on eps
1516 if (cfm < 50 && cfm != disableLimiting)
1517 {
James Feistacc8a4e2019-04-02 14:23:57 -07001518 return ipmi::responseParmOutOfRange();
James Feist5f957ca2019-03-14 15:33:55 -07001519 }
1520
1521 try
1522 {
Vernon Mauery15419dd2019-05-24 09:40:30 -07001523 ipmi::setDbusProperty(*dbus, settingsBusName, cfmLimitSettingPath,
James Feist5f957ca2019-03-14 15:33:55 -07001524 cfmLimitIface, "Limit",
1525 static_cast<double>(cfm));
1526 }
1527 catch (sdbusplus::exception_t& e)
1528 {
1529 phosphor::logging::log<phosphor::logging::level::ERR>(
1530 "ipmiOEMSetFscParameter: can't set cfm setting!",
1531 phosphor::logging::entry("ERR=%s", e.what()));
James Feistacc8a4e2019-04-02 14:23:57 -07001532 return ipmi::responseResponseError();
James Feist5f957ca2019-03-14 15:33:55 -07001533 }
James Feistacc8a4e2019-04-02 14:23:57 -07001534 return ipmi::responseSuccess();
1535 }
1536 else if (command == static_cast<uint8_t>(setFscParamFlags::maxPwm))
1537 {
1538 constexpr const size_t maxDomainCount = 8;
1539 uint8_t requestedDomainMask = param1;
1540 boost::container::flat_map data = getPidConfigs();
1541 if (data.empty())
1542 {
1543
1544 phosphor::logging::log<phosphor::logging::level::ERR>(
1545 "ipmiOEMSetFscParameter: found no pid configurations!");
1546 return ipmi::responseResponseError();
1547 }
1548 size_t count = 0;
1549 for (const auto& [path, pid] : data)
1550 {
1551 auto findClass = pid.find("Class");
1552 if (findClass == pid.end())
1553 {
1554
1555 phosphor::logging::log<phosphor::logging::level::ERR>(
1556 "ipmiOEMSetFscParameter: found illegal pid "
1557 "configurations");
1558 return ipmi::responseResponseError();
1559 }
1560 std::string type = std::get<std::string>(findClass->second);
1561 if (type == "fan")
1562 {
1563 if (requestedDomainMask & (1 << count))
1564 {
1565 ipmi::setDbusProperty(
Vernon Mauery15419dd2019-05-24 09:40:30 -07001566 *dbus, "xyz.openbmc_project.EntityManager", path,
James Feistacc8a4e2019-04-02 14:23:57 -07001567 pidConfigurationIface, "OutLimitMax",
1568 static_cast<double>(param2));
1569 }
1570 count++;
1571 }
1572 }
1573 return ipmi::responseSuccess();
James Feist5f957ca2019-03-14 15:33:55 -07001574 }
1575 else
1576 {
1577 // todo other command parts possibly
1578 // tcontrol is handled in peci now
1579 // fan speed offset not implemented yet
1580 // domain pwm limit not implemented
James Feistacc8a4e2019-04-02 14:23:57 -07001581 return ipmi::responseParmOutOfRange();
James Feist5f957ca2019-03-14 15:33:55 -07001582 }
1583}
1584
James Feistacc8a4e2019-04-02 14:23:57 -07001585ipmi::RspType<
1586 std::variant<uint8_t, std::array<uint8_t, 2>, std::array<uint16_t, 2>>>
1587 ipmiOEMGetFscParameter(uint8_t command, std::optional<uint8_t> param)
James Feist5f957ca2019-03-14 15:33:55 -07001588{
James Feistfaa4f222019-03-21 16:21:55 -07001589 constexpr uint8_t legacyDefaultExitAirLimit = -128;
James Feist5f957ca2019-03-14 15:33:55 -07001590
Vernon Mauery15419dd2019-05-24 09:40:30 -07001591 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
James Feistacc8a4e2019-04-02 14:23:57 -07001592 if (command == static_cast<uint8_t>(setFscParamFlags::tcontrol))
James Feist5f957ca2019-03-14 15:33:55 -07001593 {
James Feistacc8a4e2019-04-02 14:23:57 -07001594 if (!param)
James Feistfaa4f222019-03-21 16:21:55 -07001595 {
James Feistacc8a4e2019-04-02 14:23:57 -07001596 return ipmi::responseReqDataLenInvalid();
James Feistfaa4f222019-03-21 16:21:55 -07001597 }
1598
James Feistacc8a4e2019-04-02 14:23:57 -07001599 if (*param != legacyExitAirSensorNumber)
James Feistfaa4f222019-03-21 16:21:55 -07001600 {
James Feistacc8a4e2019-04-02 14:23:57 -07001601 return ipmi::responseParmOutOfRange();
James Feistfaa4f222019-03-21 16:21:55 -07001602 }
1603 uint8_t setpoint = legacyDefaultExitAirLimit;
1604 std::string path = getExitAirConfigPath();
1605 if (path.size())
1606 {
Vernon Mauery15419dd2019-05-24 09:40:30 -07001607 Value val = ipmi::getDbusProperty(
1608 *dbus, "xyz.openbmc_project.EntityManager", path,
1609 pidConfigurationIface, "SetPoint");
James Feistfaa4f222019-03-21 16:21:55 -07001610 setpoint = std::floor(std::get<double>(val) + 0.5);
1611 }
1612
1613 // old implementation used to return the "default" and current, we
1614 // don't make the default readily available so just make both the
1615 // same
James Feistfaa4f222019-03-21 16:21:55 -07001616
James Feistacc8a4e2019-04-02 14:23:57 -07001617 return ipmi::responseSuccess(
1618 std::array<uint8_t, 2>{setpoint, setpoint});
James Feistfaa4f222019-03-21 16:21:55 -07001619 }
James Feistacc8a4e2019-04-02 14:23:57 -07001620 else if (command == static_cast<uint8_t>(setFscParamFlags::maxPwm))
1621 {
1622 constexpr const size_t maxDomainCount = 8;
1623
1624 if (!param)
1625 {
1626 return ipmi::responseReqDataLenInvalid();
1627 }
1628 uint8_t requestedDomain = *param;
1629 if (requestedDomain >= maxDomainCount)
1630 {
1631 return ipmi::responseInvalidFieldRequest();
1632 }
1633
1634 boost::container::flat_map data = getPidConfigs();
1635 if (data.empty())
1636 {
1637 phosphor::logging::log<phosphor::logging::level::ERR>(
1638 "ipmiOEMGetFscParameter: found no pid configurations!");
1639 return ipmi::responseResponseError();
1640 }
1641 size_t count = 0;
1642 for (const auto& [_, pid] : data)
1643 {
1644 auto findClass = pid.find("Class");
1645 if (findClass == pid.end())
1646 {
1647 phosphor::logging::log<phosphor::logging::level::ERR>(
1648 "ipmiOEMGetFscParameter: found illegal pid "
1649 "configurations");
1650 return ipmi::responseResponseError();
1651 }
1652 std::string type = std::get<std::string>(findClass->second);
1653 if (type == "fan")
1654 {
1655 if (requestedDomain == count)
1656 {
1657 auto findOutLimit = pid.find("OutLimitMax");
1658 if (findOutLimit == pid.end())
1659 {
1660 phosphor::logging::log<phosphor::logging::level::ERR>(
1661 "ipmiOEMGetFscParameter: found illegal pid "
1662 "configurations");
1663 return ipmi::responseResponseError();
1664 }
1665
1666 return ipmi::responseSuccess(
1667 static_cast<uint8_t>(std::floor(
1668 std::get<double>(findOutLimit->second) + 0.5)));
1669 }
1670 else
1671 {
1672 count++;
1673 }
1674 }
1675 }
1676
1677 return ipmi::responseInvalidFieldRequest();
1678 }
1679 else if (command == static_cast<uint8_t>(setFscParamFlags::cfm))
James Feist5f957ca2019-03-14 15:33:55 -07001680 {
1681
1682 /*
1683 DataLen should be 1, but host is sending us an extra bit. As the
James Feistacc8a4e2019-04-02 14:23:57 -07001684 previous behavior didn't seem to prevent this, ignore the check for
1685 now.
James Feist5f957ca2019-03-14 15:33:55 -07001686
James Feistacc8a4e2019-04-02 14:23:57 -07001687 if (param)
James Feist5f957ca2019-03-14 15:33:55 -07001688 {
1689 phosphor::logging::log<phosphor::logging::level::ERR>(
1690 "ipmiOEMGetFscParameter: invalid input len!");
James Feist5f957ca2019-03-14 15:33:55 -07001691 return IPMI_CC_REQ_DATA_LEN_INVALID;
1692 }
1693 */
1694 Value cfmLimit;
1695 Value cfmMaximum;
1696 try
1697 {
Vernon Mauery15419dd2019-05-24 09:40:30 -07001698 cfmLimit = ipmi::getDbusProperty(*dbus, settingsBusName,
James Feist5f957ca2019-03-14 15:33:55 -07001699 cfmLimitSettingPath, cfmLimitIface,
1700 "Limit");
1701 cfmMaximum = ipmi::getDbusProperty(
Vernon Mauery15419dd2019-05-24 09:40:30 -07001702 *dbus, "xyz.openbmc_project.ExitAirTempSensor",
James Feist5f957ca2019-03-14 15:33:55 -07001703 "/xyz/openbmc_project/control/MaxCFM", cfmLimitIface, "Limit");
1704 }
1705 catch (sdbusplus::exception_t& e)
1706 {
1707 phosphor::logging::log<phosphor::logging::level::ERR>(
James Feistacc8a4e2019-04-02 14:23:57 -07001708 "ipmiOEMGetFscParameter: can't get cfm setting!",
James Feist5f957ca2019-03-14 15:33:55 -07001709 phosphor::logging::entry("ERR=%s", e.what()));
James Feistacc8a4e2019-04-02 14:23:57 -07001710 return ipmi::responseResponseError();
James Feist5f957ca2019-03-14 15:33:55 -07001711 }
1712
James Feistacc8a4e2019-04-02 14:23:57 -07001713 double cfmMax = std::get<double>(cfmMaximum);
1714 double cfmLim = std::get<double>(cfmLimit);
James Feist5f957ca2019-03-14 15:33:55 -07001715
James Feistacc8a4e2019-04-02 14:23:57 -07001716 cfmLim = std::floor(cfmLim + 0.5);
1717 cfmMax = std::floor(cfmMax + 0.5);
1718 uint16_t cfmLimResp = static_cast<uint16_t>(cfmLim);
1719 uint16_t cfmMaxResp = static_cast<uint16_t>(cfmMax);
James Feist5f957ca2019-03-14 15:33:55 -07001720
James Feistacc8a4e2019-04-02 14:23:57 -07001721 return ipmi::responseSuccess(
1722 std::array<uint16_t, 2>{cfmLimResp, cfmMaxResp});
James Feist5f957ca2019-03-14 15:33:55 -07001723 }
James Feistacc8a4e2019-04-02 14:23:57 -07001724
James Feist5f957ca2019-03-14 15:33:55 -07001725 else
1726 {
1727 // todo other command parts possibly
James Feist5f957ca2019-03-14 15:33:55 -07001728 // domain pwm limit not implemented
James Feistacc8a4e2019-04-02 14:23:57 -07001729 return ipmi::responseParmOutOfRange();
James Feist5f957ca2019-03-14 15:33:55 -07001730 }
1731}
1732
Zhu, Yungebe560b02019-04-21 21:19:21 -04001733ipmi::RspType<> ipmiOEMSetFaultIndication(uint8_t sourceId, uint8_t faultType,
1734 uint8_t faultState,
1735 uint8_t faultGroup,
1736 std::array<uint8_t, 8>& ledStateData)
1737{
1738 static constexpr const char* objpath = "/xyz/openbmc_project/EntityManager";
1739 static constexpr const char* intf = "xyz.openbmc_project.EntityManager";
1740 constexpr auto maxFaultType = static_cast<size_t>(RemoteFaultType::max);
1741 static const std::array<std::string, maxFaultType> faultNames = {
1742 "faultFan", "faultTemp", "faultPower",
1743 "faultDriveSlot", "faultSoftware", "faultMemory"};
1744 static constexpr const char* sysGpioPath = "/sys/class/gpio/gpio";
1745 static constexpr const char* postfixValue = "/value";
1746
1747 constexpr uint8_t maxFaultSource = 0x4;
1748 constexpr uint8_t skipLEDs = 0xFF;
1749 constexpr uint8_t pinSize = 64;
1750 constexpr uint8_t groupSize = 16;
1751
1752 std::vector<uint16_t> ledFaultPins(pinSize, 0xFFFF);
1753 uint64_t resFIndex = 0;
1754 std::string resFType;
1755 std::string service;
1756 ObjectValueTree valueTree;
1757
1758 // Validate the source, fault type
1759 if ((sourceId >= maxFaultSource) ||
1760 (faultType >= static_cast<int8_t>(RemoteFaultType::max)) ||
1761 (faultState >= static_cast<int8_t>(RemoteFaultState::maxFaultState)) ||
1762 (faultGroup >= static_cast<int8_t>(DimmFaultType::maxFaultGroup)))
1763 {
1764 return ipmi::responseParmOutOfRange();
1765 }
1766
Vernon Mauery15419dd2019-05-24 09:40:30 -07001767 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Zhu, Yungebe560b02019-04-21 21:19:21 -04001768 try
1769 {
Vernon Mauery15419dd2019-05-24 09:40:30 -07001770 service = getService(*dbus, intf, objpath);
1771 valueTree = getManagedObjects(*dbus, service, "/");
Zhu, Yungebe560b02019-04-21 21:19:21 -04001772 }
1773 catch (const std::exception& e)
1774 {
1775 phosphor::logging::log<phosphor::logging::level::ERR>(
1776 "No object implements interface",
1777 phosphor::logging::entry("SERVICE=%s", service.c_str()),
1778 phosphor::logging::entry("INTF=%s", intf));
1779 return ipmi::responseResponseError();
1780 }
1781
1782 if (valueTree.empty())
1783 {
1784 phosphor::logging::log<phosphor::logging::level::ERR>(
1785 "No object implements interface",
1786 phosphor::logging::entry("INTF=%s", intf));
1787 return ipmi::responseResponseError();
1788 }
1789
1790 for (const auto& item : valueTree)
1791 {
1792 // find LedFault configuration
1793 auto interface =
1794 item.second.find("xyz.openbmc_project.Configuration.LedFault");
1795 if (interface == item.second.end())
1796 {
1797 continue;
1798 }
1799
1800 // find matched fault type: faultMemmory / faultFan
1801 // find LedGpioPins/FaultIndex configuration
1802 auto propertyFaultType = interface->second.find("FaultType");
1803 auto propertyFIndex = interface->second.find("FaultIndex");
1804 auto ledIndex = interface->second.find("LedGpioPins");
1805
1806 if (propertyFaultType == interface->second.end() ||
1807 propertyFIndex == interface->second.end() ||
1808 ledIndex == interface->second.end())
1809 {
1810 continue;
1811 }
1812
1813 try
1814 {
1815 Value valIndex = propertyFIndex->second;
1816 resFIndex = std::get<uint64_t>(valIndex);
1817
1818 Value valFType = propertyFaultType->second;
1819 resFType = std::get<std::string>(valFType);
1820 }
1821 catch (const std::bad_variant_access& e)
1822 {
1823 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
1824 return ipmi::responseResponseError();
1825 }
1826 // find the matched requested fault type: faultMemmory or faultFan
1827 if (resFType != faultNames[faultType])
1828 {
1829 continue;
1830 }
1831
1832 // read LedGpioPins data
1833 std::vector<uint64_t> ledgpios;
1834 std::variant<std::vector<uint64_t>> message;
1835
Vernon Mauery15419dd2019-05-24 09:40:30 -07001836 auto method = dbus->new_method_call(
Zhu, Yungebe560b02019-04-21 21:19:21 -04001837 service.c_str(), (std::string(item.first)).c_str(),
1838 "org.freedesktop.DBus.Properties", "Get");
1839
1840 method.append("xyz.openbmc_project.Configuration.LedFault",
1841 "LedGpioPins");
1842
1843 try
1844 {
Vernon Mauery15419dd2019-05-24 09:40:30 -07001845 auto reply = dbus->call(method);
Zhu, Yungebe560b02019-04-21 21:19:21 -04001846 reply.read(message);
1847 ledgpios = std::get<std::vector<uint64_t>>(message);
1848 }
1849 catch (std::exception& e)
1850 {
1851 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
1852 return ipmi::responseResponseError();
1853 }
1854
1855 // Check the size to be sure it will never overflow on groupSize
1856 if (ledgpios.size() > groupSize)
1857 {
1858 phosphor::logging::log<phosphor::logging::level::ERR>(
1859 "Fault gpio Pins out of range!");
1860 return ipmi::responseParmOutOfRange();
1861 }
1862 // Store data, according to command data bit index order
1863 for (int i = 0; i < ledgpios.size(); i++)
1864 {
1865 ledFaultPins[i + groupSize * resFIndex] = ledgpios[i];
1866 }
1867 }
1868
1869 switch (RemoteFaultType(faultType))
1870 {
1871 case (RemoteFaultType::fan):
1872 case (RemoteFaultType::memory):
1873 {
1874 if (faultGroup == skipLEDs)
1875 {
1876 return ipmi::responseSuccess();
1877 }
1878
1879 uint64_t ledState = 0;
1880 // calculate led state bit filed count, each byte has 8bits
1881 // the maximum bits will be 8 * 8 bits
1882 constexpr uint8_t size = sizeof(ledStateData) * 8;
1883 for (int i = 0; i < sizeof(ledStateData); i++)
1884 {
1885 ledState = (uint64_t)(ledState << 8);
1886 ledState = (uint64_t)(ledState | (uint64_t)ledStateData[i]);
1887 }
1888
1889 std::bitset<size> ledStateBits(ledState);
1890 std::string gpioValue;
1891 for (int i = 0; i < size; i++)
1892 { // skip invalid value
1893 if (ledFaultPins[i] == 0xFFFF)
1894 {
1895 continue;
1896 }
1897
1898 std::string device = sysGpioPath +
1899 std::to_string(ledFaultPins[i]) +
1900 postfixValue;
1901 std::fstream gpioFile;
1902
1903 gpioFile.open(device, std::ios::out);
1904
1905 if (!gpioFile.good())
1906 {
1907 phosphor::logging::log<phosphor::logging::level::ERR>(
1908 "Not Find Led Gpio Device!",
1909 phosphor::logging::entry("DEVICE=%s", device.c_str()));
1910 return ipmi::responseResponseError();
1911 }
1912 gpioFile << std::to_string(
1913 static_cast<uint8_t>(ledStateBits[i]));
1914 gpioFile.close();
1915 }
1916 break;
1917 }
1918 default:
1919 {
1920 // now only support two fault types
1921 return ipmi::responseParmOutOfRange();
1922 }
1923 }
1924
1925 return ipmi::responseSuccess();
1926}
1927
Richard Marian Thomaiyarea537d52019-04-24 21:33:48 +05301928ipmi::RspType<uint8_t> ipmiOEMReadBoardProductId()
1929{
1930 uint8_t prodId = 0;
1931 try
1932 {
Vernon Mauery15419dd2019-05-24 09:40:30 -07001933 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
Richard Marian Thomaiyarea537d52019-04-24 21:33:48 +05301934 const DbusObjectInfo& object = getDbusObject(
Vernon Mauery15419dd2019-05-24 09:40:30 -07001935 *dbus, "xyz.openbmc_project.Inventory.Item.Board",
Richard Marian Thomaiyarea537d52019-04-24 21:33:48 +05301936 "/xyz/openbmc_project/inventory/system/board/", "Baseboard");
1937 const Value& propValue = getDbusProperty(
Vernon Mauery15419dd2019-05-24 09:40:30 -07001938 *dbus, object.second, object.first,
Richard Marian Thomaiyarea537d52019-04-24 21:33:48 +05301939 "xyz.openbmc_project.Inventory.Item.Board", "ProductId");
1940 prodId = static_cast<uint8_t>(std::get<uint64_t>(propValue));
1941 }
1942 catch (std::exception& e)
1943 {
1944 phosphor::logging::log<phosphor::logging::level::ERR>(
1945 "ipmiOEMReadBoardProductId: Product ID read failed!",
1946 phosphor::logging::entry("ERR=%s", e.what()));
1947 }
1948 return ipmi::responseSuccess(prodId);
1949}
1950
Vernon Mauery4ac799d2019-05-20 15:50:37 -07001951ipmi::RspType<uint8_t /* restore status */>
1952 ipmiRestoreConfiguration(const std::array<uint8_t, 3>& clr, uint8_t cmd)
1953{
1954 static constexpr std::array<uint8_t, 3> expClr = {'C', 'L', 'R'};
1955
1956 if (clr != expClr)
1957 {
1958 return ipmi::responseInvalidFieldRequest();
1959 }
1960 constexpr uint8_t cmdStatus = 0;
1961 constexpr uint8_t cmdDefaultRestore = 0xaa;
1962 constexpr uint8_t cmdFullRestore = 0xbb;
1963 constexpr uint8_t cmdFormat = 0xcc;
1964
1965 constexpr const char* restoreOpFname = "/tmp/.rwfs/.restore_op";
1966
1967 switch (cmd)
1968 {
1969 case cmdStatus:
1970 break;
1971 case cmdDefaultRestore:
1972 case cmdFullRestore:
1973 case cmdFormat:
1974 {
1975 // write file to rwfs root
1976 int value = (cmd - 1) & 0x03; // map aa, bb, cc => 1, 2, 3
1977 std::ofstream restoreFile(restoreOpFname);
1978 if (!restoreFile)
1979 {
1980 return ipmi::responseUnspecifiedError();
1981 }
1982 restoreFile << value << "\n";
1983 break;
1984 }
1985 default:
1986 return ipmi::responseInvalidFieldRequest();
1987 }
1988
1989 constexpr uint8_t restorePending = 0;
1990 constexpr uint8_t restoreComplete = 1;
1991
1992 uint8_t restoreStatus = std::filesystem::exists(restoreOpFname)
1993 ? restorePending
1994 : restoreComplete;
1995 return ipmi::responseSuccess(restoreStatus);
1996}
1997
Chen Yugang39736d52019-07-12 16:24:33 +08001998ipmi::RspType<uint8_t> ipmiOEMGetNmiSource(void)
1999{
2000 uint8_t bmcSource;
2001 namespace nmi = sdbusplus::com::intel::Control::server;
2002
2003 try
2004 {
2005 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
2006 std::string service =
2007 getService(*dbus, oemNmiSourceIntf, oemNmiSourceObjPath);
2008 Value variant =
2009 getDbusProperty(*dbus, service, oemNmiSourceObjPath,
2010 oemNmiSourceIntf, oemNmiBmcSourceObjPathProp);
2011
2012 switch (nmi::NMISource::convertBMCSourceSignalFromString(
2013 std::get<std::string>(variant)))
2014 {
2015 case nmi::NMISource::BMCSourceSignal::None:
2016 bmcSource = static_cast<uint8_t>(NmiSource::none);
2017 break;
2018 case nmi::NMISource::BMCSourceSignal::FpBtn:
2019 bmcSource = static_cast<uint8_t>(NmiSource::fpBtn);
2020 break;
2021 case nmi::NMISource::BMCSourceSignal::WdPreTimeout:
2022 bmcSource = static_cast<uint8_t>(NmiSource::wdPreTimeout);
2023 break;
2024 case nmi::NMISource::BMCSourceSignal::PefMatch:
2025 bmcSource = static_cast<uint8_t>(NmiSource::pefMatch);
2026 break;
2027 case nmi::NMISource::BMCSourceSignal::ChassisCmd:
2028 bmcSource = static_cast<uint8_t>(NmiSource::chassisCmd);
2029 break;
2030 case nmi::NMISource::BMCSourceSignal::MemoryError:
2031 bmcSource = static_cast<uint8_t>(NmiSource::memoryError);
2032 break;
2033 case nmi::NMISource::BMCSourceSignal::PciSerrPerr:
2034 bmcSource = static_cast<uint8_t>(NmiSource::pciSerrPerr);
2035 break;
2036 case nmi::NMISource::BMCSourceSignal::SouthbridgeNmi:
2037 bmcSource = static_cast<uint8_t>(NmiSource::southbridgeNmi);
2038 break;
2039 case nmi::NMISource::BMCSourceSignal::ChipsetNmi:
2040 bmcSource = static_cast<uint8_t>(NmiSource::chipsetNmi);
2041 break;
2042 default:
2043 phosphor::logging::log<phosphor::logging::level::ERR>(
2044 "NMI source: invalid property!",
2045 phosphor::logging::entry(
2046 "PROP=%s", std::get<std::string>(variant).c_str()));
2047 return ipmi::responseResponseError();
2048 }
2049 }
2050 catch (sdbusplus::exception::SdBusError& e)
2051 {
2052 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
2053 return ipmi::responseResponseError();
2054 }
2055
2056 return ipmi::responseSuccess(bmcSource);
2057}
2058
2059ipmi::RspType<> ipmiOEMSetNmiSource(uint8_t sourceId)
2060{
2061 namespace nmi = sdbusplus::com::intel::Control::server;
2062
2063 nmi::NMISource::BMCSourceSignal bmcSourceSignal =
2064 nmi::NMISource::BMCSourceSignal::None;
2065
2066 switch (NmiSource(sourceId))
2067 {
2068 case NmiSource::none:
2069 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::None;
2070 break;
2071 case NmiSource::fpBtn:
2072 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::FpBtn;
2073 break;
2074 case NmiSource::wdPreTimeout:
2075 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::WdPreTimeout;
2076 break;
2077 case NmiSource::pefMatch:
2078 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::PefMatch;
2079 break;
2080 case NmiSource::chassisCmd:
2081 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::ChassisCmd;
2082 break;
2083 case NmiSource::memoryError:
2084 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::MemoryError;
2085 break;
2086 case NmiSource::pciSerrPerr:
2087 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::PciSerrPerr;
2088 break;
2089 case NmiSource::southbridgeNmi:
2090 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::SouthbridgeNmi;
2091 break;
2092 case NmiSource::chipsetNmi:
2093 bmcSourceSignal = nmi::NMISource::BMCSourceSignal::ChipsetNmi;
2094 break;
2095 default:
2096 phosphor::logging::log<phosphor::logging::level::ERR>(
2097 "NMI source: invalid property!");
2098 return ipmi::responseResponseError();
2099 }
2100
2101 try
2102 {
2103 // keep NMI signal source
2104 std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
2105 std::string service =
2106 getService(*dbus, oemNmiSourceIntf, oemNmiSourceObjPath);
2107 setDbusProperty(
2108 *dbus, service, oemNmiSourceObjPath, oemNmiSourceIntf,
2109 oemNmiBmcSourceObjPathProp,
2110 sdbusplus::com::intel::Control::server::convertForMessage(
2111 bmcSourceSignal));
2112 }
2113 catch (sdbusplus::exception_t& e)
2114 {
2115 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
2116 return ipmi::responseResponseError();
2117 }
2118
2119 return ipmi::responseSuccess();
2120}
2121
James Feist63efafa2019-07-24 12:39:21 -07002122namespace dimmOffset
2123{
2124constexpr const char* dimmPower = "DimmPower";
2125constexpr const char* staticCltt = "StaticCltt";
2126constexpr const char* offsetPath = "/xyz/openbmc_project/Inventory/Item/Dimm";
2127constexpr const char* offsetInterface =
2128 "xyz.openbmc_project.Inventory.Item.Dimm.Offset";
2129constexpr const char* property = "DimmOffset";
2130
2131}; // namespace dimmOffset
2132
2133ipmi::RspType<>
2134 ipmiOEMSetDimmOffset(uint8_t type,
2135 const std::vector<std::tuple<uint8_t, uint8_t>>& data)
2136{
2137 if (type != static_cast<uint8_t>(dimmOffsetTypes::dimmPower) &&
2138 type != static_cast<uint8_t>(dimmOffsetTypes::staticCltt))
2139 {
2140 return ipmi::responseInvalidFieldRequest();
2141 }
2142
2143 if (data.empty())
2144 {
2145 return ipmi::responseInvalidFieldRequest();
2146 }
2147 nlohmann::json json;
2148
2149 std::ifstream jsonStream(dimmOffsetFile);
2150 if (jsonStream.good())
2151 {
2152 json = nlohmann::json::parse(jsonStream, nullptr, false);
2153 if (json.is_discarded())
2154 {
2155 json = nlohmann::json();
2156 }
2157 jsonStream.close();
2158 }
2159
2160 std::string typeName;
2161 if (type == static_cast<uint8_t>(dimmOffsetTypes::dimmPower))
2162 {
2163 typeName = dimmOffset::dimmPower;
2164 }
2165 else
2166 {
2167 typeName = dimmOffset::staticCltt;
2168 }
2169
2170 nlohmann::json& field = json[typeName];
2171
2172 for (const auto& [index, value] : data)
2173 {
2174 field[index] = value;
2175 }
2176
2177 for (nlohmann::json& val : field)
2178 {
2179 if (val == nullptr)
2180 {
2181 val = static_cast<uint8_t>(0);
2182 }
2183 }
2184
2185 std::ofstream output(dimmOffsetFile);
2186 if (!output.good())
2187 {
2188 std::cerr << "Error writing json file\n";
2189 return ipmi::responseResponseError();
2190 }
2191
2192 output << json.dump(4);
2193
2194 if (type == static_cast<uint8_t>(dimmOffsetTypes::staticCltt))
2195 {
2196 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
2197
2198 std::variant<std::vector<uint8_t>> offsets =
2199 field.get<std::vector<uint8_t>>();
2200 auto call = bus->new_method_call(
2201 settingsBusName, dimmOffset::offsetPath, PROP_INTF, "Set");
2202 call.append(dimmOffset::offsetInterface, dimmOffset::property, offsets);
2203 try
2204 {
2205 bus->call(call);
2206 }
2207 catch (sdbusplus::exception_t& e)
2208 {
2209 phosphor::logging::log<phosphor::logging::level::ERR>(
2210 "ipmiOEMSetDimmOffset: can't set dimm offsets!",
2211 phosphor::logging::entry("ERR=%s", e.what()));
2212 return ipmi::responseResponseError();
2213 }
2214 }
2215
2216 return ipmi::responseSuccess();
2217}
2218
2219ipmi::RspType<uint8_t> ipmiOEMGetDimmOffset(uint8_t type, uint8_t index)
2220{
2221
2222 if (type != static_cast<uint8_t>(dimmOffsetTypes::dimmPower) &&
2223 type != static_cast<uint8_t>(dimmOffsetTypes::staticCltt))
2224 {
2225 return ipmi::responseInvalidFieldRequest();
2226 }
2227
2228 std::ifstream jsonStream(dimmOffsetFile);
2229
2230 auto json = nlohmann::json::parse(jsonStream, nullptr, false);
2231 if (json.is_discarded())
2232 {
2233 std::cerr << "File error in " << dimmOffsetFile << "\n";
2234 return ipmi::responseResponseError();
2235 }
2236
2237 std::string typeName;
2238 if (type == static_cast<uint8_t>(dimmOffsetTypes::dimmPower))
2239 {
2240 typeName = dimmOffset::dimmPower;
2241 }
2242 else
2243 {
2244 typeName = dimmOffset::staticCltt;
2245 }
2246
2247 auto it = json.find(typeName);
2248 if (it == json.end())
2249 {
2250 return ipmi::responseInvalidFieldRequest();
2251 }
2252
2253 if (it->size() <= index)
2254 {
2255 return ipmi::responseInvalidFieldRequest();
2256 }
2257
2258 uint8_t resp = it->at(index).get<uint8_t>();
2259 return ipmi::responseSuccess(resp);
2260}
2261
Jason M. Bills64796042018-10-03 16:51:55 -07002262static void registerOEMFunctions(void)
Jia, Chunhuia835eaa2018-09-05 09:00:41 +08002263{
2264 phosphor::logging::log<phosphor::logging::level::INFO>(
2265 "Registering OEM commands");
Jason M. Bills64796042018-10-03 16:51:55 -07002266 ipmiPrintAndRegister(netfnIntcOEMGeneral, IPMI_CMD_WILDCARD, NULL,
2267 ipmiOEMWildcard,
2268 PRIVILEGE_USER); // wildcard default handler
2269 ipmiPrintAndRegister(netfunIntelAppOEM, IPMI_CMD_WILDCARD, NULL,
2270 ipmiOEMWildcard,
2271 PRIVILEGE_USER); // wildcard default handler
2272 ipmiPrintAndRegister(
2273 netfnIntcOEMGeneral,
2274 static_cast<ipmi_cmd_t>(
2275 IPMINetfnIntelOEMGeneralCmd::cmdGetChassisIdentifier),
2276 NULL, ipmiOEMGetChassisIdentifier,
2277 PRIVILEGE_USER); // get chassis identifier
2278 ipmiPrintAndRegister(
2279 netfnIntcOEMGeneral,
2280 static_cast<ipmi_cmd_t>(IPMINetfnIntelOEMGeneralCmd::cmdSetSystemGUID),
2281 NULL, ipmiOEMSetSystemGUID,
2282 PRIVILEGE_ADMIN); // set system guid
2283 ipmiPrintAndRegister(
2284 netfnIntcOEMGeneral,
2285 static_cast<ipmi_cmd_t>(IPMINetfnIntelOEMGeneralCmd::cmdSetBIOSID),
2286 NULL, ipmiOEMSetBIOSID, PRIVILEGE_ADMIN);
2287 ipmiPrintAndRegister(netfnIntcOEMGeneral,
2288 static_cast<ipmi_cmd_t>(
2289 IPMINetfnIntelOEMGeneralCmd::cmdGetOEMDeviceInfo),
2290 NULL, ipmiOEMGetDeviceInfo, PRIVILEGE_USER);
2291 ipmiPrintAndRegister(
2292 netfnIntcOEMGeneral,
2293 static_cast<ipmi_cmd_t>(
2294 IPMINetfnIntelOEMGeneralCmd::cmdGetAICSlotFRUIDSlotPosRecords),
2295 NULL, ipmiOEMGetAICFRU, PRIVILEGE_USER);
Jia, Chunhuicc49b542019-03-20 15:41:07 +08002296
2297 ipmi::registerHandler(
2298 ipmi::prioOpenBmcBase, ipmi::netFnOemOne,
2299 static_cast<ipmi::Cmd>(
2300 IPMINetfnIntelOEMGeneralCmd::cmdSendEmbeddedFWUpdStatus),
2301 ipmi::Privilege::Operator, ipmiOEMSendEmbeddedFwUpdStatus);
2302
Jason M. Bills64796042018-10-03 16:51:55 -07002303 ipmiPrintAndRegister(
2304 netfnIntcOEMGeneral,
2305 static_cast<ipmi_cmd_t>(
2306 IPMINetfnIntelOEMGeneralCmd::cmdSetPowerRestoreDelay),
2307 NULL, ipmiOEMSetPowerRestoreDelay, PRIVILEGE_OPERATOR);
2308 ipmiPrintAndRegister(
2309 netfnIntcOEMGeneral,
2310 static_cast<ipmi_cmd_t>(
2311 IPMINetfnIntelOEMGeneralCmd::cmdGetPowerRestoreDelay),
2312 NULL, ipmiOEMGetPowerRestoreDelay, PRIVILEGE_USER);
Suryakanth Sekard509eb92018-11-15 17:44:11 +05302313
2314 ipmi::registerHandler(
2315 ipmi::prioOpenBmcBase, ipmi::netFnOemOne,
2316 static_cast<ipmi::Cmd>(
2317 IPMINetfnIntelOEMGeneralCmd::cmdSetOEMUser2Activation),
2318 ipmi::Privilege::Callback, ipmiOEMSetUser2Activation);
2319
Richard Marian Thomaiyarfc5e9852019-04-14 15:06:27 +05302320 ipmi::registerHandler(
2321 ipmi::prioOpenBmcBase, ipmi::netFnOemOne,
2322 static_cast<ipmi::Cmd>(
2323 IPMINetfnIntelOEMGeneralCmd::cmdSetSpecialUserPassword),
2324 ipmi::Privilege::Callback, ipmiOEMSetSpecialUserPassword);
2325
Jason M. Bills42bd9c82019-06-28 16:39:34 -07002326 // <Get Processor Error Config>
2327 ipmi::registerHandler(
2328 ipmi::prioOemBase, netfnIntcOEMGeneral,
2329 static_cast<ipmi::Cmd>(
Jason M. Bills64796042018-10-03 16:51:55 -07002330 IPMINetfnIntelOEMGeneralCmd::cmdGetProcessorErrConfig),
Jason M. Bills42bd9c82019-06-28 16:39:34 -07002331 ipmi::Privilege::User, ipmiOEMGetProcessorErrConfig);
2332 // <Set Processor Error Config>
2333 ipmi::registerHandler(
2334 ipmi::prioOemBase, netfnIntcOEMGeneral,
2335 static_cast<ipmi::Cmd>(
Jason M. Bills64796042018-10-03 16:51:55 -07002336 IPMINetfnIntelOEMGeneralCmd::cmdSetProcessorErrConfig),
Jason M. Bills42bd9c82019-06-28 16:39:34 -07002337 ipmi::Privilege::Admin, ipmiOEMSetProcessorErrConfig);
2338
Yong Li703922d2018-11-06 13:25:31 +08002339 ipmiPrintAndRegister(netfnIntcOEMGeneral,
2340 static_cast<ipmi_cmd_t>(
2341 IPMINetfnIntelOEMGeneralCmd::cmdSetShutdownPolicy),
2342 NULL, ipmiOEMSetShutdownPolicy, PRIVILEGE_ADMIN);
2343 ipmiPrintAndRegister(netfnIntcOEMGeneral,
2344 static_cast<ipmi_cmd_t>(
2345 IPMINetfnIntelOEMGeneralCmd::cmdGetShutdownPolicy),
2346 NULL, ipmiOEMGetShutdownPolicy, PRIVILEGE_ADMIN);
James Feist91244a62019-02-19 15:04:54 -08002347
2348 ipmiPrintAndRegister(
2349 netfnIntcOEMGeneral,
2350 static_cast<ipmi_cmd_t>(IPMINetfnIntelOEMGeneralCmd::cmdSetFanConfig),
2351 NULL, ipmiOEMSetFanConfig, PRIVILEGE_USER);
2352
James Feist5b693632019-07-09 09:06:09 -07002353 ipmi::registerHandler(
2354 ipmi::prioOemBase, netfnIntcOEMGeneral,
2355 static_cast<ipmi::Cmd>(IPMINetfnIntelOEMGeneralCmd::cmdGetFanConfig),
2356 ipmi::Privilege::User, ipmiOEMGetFanConfig);
James Feist91244a62019-02-19 15:04:54 -08002357
James Feistacc8a4e2019-04-02 14:23:57 -07002358 ipmi::registerHandler(
2359 ipmi::prioOemBase, netfnIntcOEMGeneral,
2360 static_cast<ipmi::Cmd>(
2361 IPMINetfnIntelOEMGeneralCmd::cmdGetFanSpeedOffset),
2362 ipmi::Privilege::User, ipmiOEMGetFanSpeedOffset);
James Feist5f957ca2019-03-14 15:33:55 -07002363
James Feistacc8a4e2019-04-02 14:23:57 -07002364 ipmi::registerHandler(
2365 ipmi::prioOemBase, netfnIntcOEMGeneral,
2366 static_cast<ipmi::Cmd>(
2367 IPMINetfnIntelOEMGeneralCmd::cmdSetFanSpeedOffset),
2368 ipmi::Privilege::User, ipmiOEMSetFanSpeedOffset);
2369
2370 ipmi::registerHandler(
2371 ipmi::prioOemBase, netfnIntcOEMGeneral,
2372 static_cast<ipmi::Cmd>(IPMINetfnIntelOEMGeneralCmd::cmdSetFscParameter),
2373 ipmi::Privilege::User, ipmiOEMSetFscParameter);
2374
2375 ipmi::registerHandler(
2376 ipmi::prioOemBase, netfnIntcOEMGeneral,
2377 static_cast<ipmi::Cmd>(IPMINetfnIntelOEMGeneralCmd::cmdGetFscParameter),
2378 ipmi::Privilege::User, ipmiOEMGetFscParameter);
James Feist5f957ca2019-03-14 15:33:55 -07002379
Richard Marian Thomaiyarea537d52019-04-24 21:33:48 +05302380 ipmi::registerHandler(
2381 ipmi::prioOpenBmcBase, netfnIntcOEMGeneral,
2382 static_cast<ipmi::Cmd>(
2383 IPMINetfnIntelOEMGeneralCmd::cmdReadBaseBoardProductId),
2384 ipmi::Privilege::Admin, ipmiOEMReadBoardProductId);
2385
Chen Yugang39736d52019-07-12 16:24:33 +08002386 ipmi::registerHandler(
2387 ipmi::prioOemBase, netfnIntcOEMGeneral,
2388 static_cast<ipmi::Cmd>(IPMINetfnIntelOEMGeneralCmd::cmdGetNmiStatus),
2389 ipmi::Privilege::User, ipmiOEMGetNmiSource);
2390
2391 ipmi::registerHandler(
2392 ipmi::prioOemBase, netfnIntcOEMGeneral,
2393 static_cast<ipmi::Cmd>(IPMINetfnIntelOEMGeneralCmd::cmdSetNmiStatus),
2394 ipmi::Privilege::Operator, ipmiOEMSetNmiSource);
2395
Kuiying Wang45f04982018-12-26 09:23:08 +08002396 ipmiPrintAndRegister(
2397 netfnIntcOEMGeneral,
2398 static_cast<ipmi_cmd_t>(IPMINetfnIntelOEMGeneralCmd::cmdGetLEDStatus),
2399 NULL, ipmiOEMGetLEDStatus, PRIVILEGE_ADMIN);
Yong Li23737fe2019-02-19 08:49:55 +08002400 ipmiPrintAndRegister(
2401 netfnIntcOEMPlatform,
2402 static_cast<ipmi_cmd_t>(
2403 IPMINetfnIntelOEMPlatformCmd::cmdCfgHostSerialPortSpeed),
2404 NULL, ipmiOEMCfgHostSerialPortSpeed, PRIVILEGE_ADMIN);
Zhu, Yungebe560b02019-04-21 21:19:21 -04002405 ipmi::registerHandler(
2406 ipmi::prioOemBase, netfnIntcOEMGeneral,
2407 static_cast<ipmi::Cmd>(
2408 IPMINetfnIntelOEMGeneralCmd::cmdSetFaultIndication),
2409 ipmi::Privilege::Operator, ipmiOEMSetFaultIndication);
Vernon Mauery4ac799d2019-05-20 15:50:37 -07002410
2411 registerHandler(prioOemBase, netfn::intel::oemGeneral,
2412 netfn::intel::cmdRestoreConfiguration, Privilege::Admin,
2413 ipmiRestoreConfiguration);
James Feist63efafa2019-07-24 12:39:21 -07002414
2415 ipmi::registerHandler(
2416 ipmi::prioOemBase, netfnIntcOEMGeneral,
2417 static_cast<ipmi::Cmd>(IPMINetfnIntelOEMGeneralCmd::cmdSetDimmOffset),
2418 ipmi::Privilege::Operator, ipmiOEMSetDimmOffset);
2419
2420 ipmi::registerHandler(
2421 ipmi::prioOemBase, netfnIntcOEMGeneral,
2422 static_cast<ipmi::Cmd>(IPMINetfnIntelOEMGeneralCmd::cmdGetDimmOffset),
2423 ipmi::Privilege::Operator, ipmiOEMGetDimmOffset);
Jia, Chunhuia835eaa2018-09-05 09:00:41 +08002424}
2425
2426} // namespace ipmi