blob: 20a529df0a9742f6412fe81028a1de45ba667cc2 [file] [log] [blame]
Potin Lai5d214202023-01-16 18:11:49 +08001#include "config.h"
2
Patrick Venture0b02be92018-08-31 11:55:55 -07003#include <arpa/inet.h>
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +05304#include <fcntl.h>
Xo Wang87651332017-08-11 10:17:59 -07005#include <limits.h>
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +05306#include <linux/i2c-dev.h>
7#include <linux/i2c.h>
Patrick Venture0b02be92018-08-31 11:55:55 -07008#include <mapper.h>
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +05309#include <sys/ioctl.h>
10#include <sys/stat.h>
11#include <sys/types.h>
Patrick Venture0b02be92018-08-31 11:55:55 -070012#include <systemd/sd-bus.h>
Xo Wang87651332017-08-11 10:17:59 -070013#include <unistd.h>
Patrick Venture0b02be92018-08-31 11:55:55 -070014
Vernon Mauery0120b682019-03-25 13:08:54 -070015#include <app/channel.hpp>
16#include <app/watchdog.hpp>
17#include <apphandler.hpp>
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -050018#include <ipmid/api.hpp>
19#include <ipmid/sessiondef.hpp>
20#include <ipmid/sessionhelper.hpp>
21#include <ipmid/types.hpp>
22#include <ipmid/utils.hpp>
23#include <nlohmann/json.hpp>
24#include <phosphor-logging/elog-errors.hpp>
25#include <phosphor-logging/log.hpp>
26#include <sdbusplus/message/types.hpp>
27#include <sys_info_param.hpp>
28#include <xyz/openbmc_project/Common/error.hpp>
29#include <xyz/openbmc_project/Control/Power/ACPIPowerState/server.hpp>
30#include <xyz/openbmc_project/Software/Activation/server.hpp>
31#include <xyz/openbmc_project/Software/Version/server.hpp>
32#include <xyz/openbmc_project/State/BMC/server.hpp>
33
34#include <algorithm>
Patrick Venture3a5071a2018-09-12 13:27:42 -070035#include <array>
Willy Tu886d6842022-06-03 02:50:47 -070036#include <charconv>
Patrick Venture3a5071a2018-09-12 13:27:42 -070037#include <cstddef>
Vernon Mauery0120b682019-03-25 13:08:54 -070038#include <cstdint>
Vernon Mauerybdda8002019-02-26 10:18:51 -080039#include <filesystem>
Patrick Venture3a5071a2018-09-12 13:27:42 -070040#include <fstream>
41#include <memory>
Potin Lai5d214202023-01-16 18:11:49 +080042#include <regex>
Patrick Venture3a5071a2018-09-12 13:27:42 -070043#include <string>
Willy Tu886d6842022-06-03 02:50:47 -070044#include <string_view>
Patrick Venture3a5071a2018-09-12 13:27:42 -070045#include <tuple>
46#include <vector>
Ratan Guptab8e99552017-07-27 07:07:48 +053047
Patrick Venture0b02be92018-08-31 11:55:55 -070048extern sd_bus* bus;
vishwabmcba0bd5f2015-09-30 16:50:23 +053049
Alexander Amelkinba19c182018-09-04 15:49:36 +030050constexpr auto bmc_state_interface = "xyz.openbmc_project.State.BMC";
51constexpr auto bmc_state_property = "CurrentBMCState";
Marri Devender Rao5e007a52018-01-08 06:18:36 -060052
Nagaraju Goruganti744398d2018-02-20 09:52:00 -060053static constexpr auto redundancyIntf =
54 "xyz.openbmc_project.Software.RedundancyPriority";
Patrick Venture0b02be92018-08-31 11:55:55 -070055static constexpr auto versionIntf = "xyz.openbmc_project.Software.Version";
Nagaraju Goruganti744398d2018-02-20 09:52:00 -060056static constexpr auto activationIntf =
57 "xyz.openbmc_project.Software.Activation";
58static constexpr auto softwareRoot = "/xyz/openbmc_project/software";
59
Chris Austen6caf28b2015-10-13 12:40:40 -050060void register_netfn_app_functions() __attribute__((constructor));
vishwabmcba0bd5f2015-09-30 16:50:23 +053061
Ratan Guptab8e99552017-07-27 07:07:48 +053062using namespace phosphor::logging;
Willy Tu523e2d12023-09-05 11:36:48 -070063using namespace sdbusplus::error::xyz::openbmc_project::common;
64using Version = sdbusplus::server::xyz::openbmc_project::software::Version;
Nagaraju Goruganti744398d2018-02-20 09:52:00 -060065using Activation =
Willy Tu523e2d12023-09-05 11:36:48 -070066 sdbusplus::server::xyz::openbmc_project::software::Activation;
67using BMC = sdbusplus::server::xyz::openbmc_project::state::BMC;
Vernon Mauery185b9f82018-07-20 10:52:36 -070068namespace fs = std::filesystem;
Ratan Guptab8e99552017-07-27 07:07:48 +053069
Yong Libd0503a2019-08-22 17:17:17 +080070#ifdef ENABLE_I2C_WHITELIST_CHECK
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +053071typedef struct
72{
73 uint8_t busId;
74 uint8_t slaveAddr;
75 uint8_t slaveAddrMask;
76 std::vector<uint8_t> data;
77 std::vector<uint8_t> dataMask;
78} i2cMasterWRWhitelist;
79
80static std::vector<i2cMasterWRWhitelist>& getWRWhitelist()
81{
82 static std::vector<i2cMasterWRWhitelist> wrWhitelist;
83 return wrWhitelist;
84}
85
86static constexpr const char* i2cMasterWRWhitelistFile =
87 "/usr/share/ipmi-providers/master_write_read_white_list.json";
88
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +053089static constexpr const char* filtersStr = "filters";
90static constexpr const char* busIdStr = "busId";
91static constexpr const char* slaveAddrStr = "slaveAddr";
92static constexpr const char* slaveAddrMaskStr = "slaveAddrMask";
93static constexpr const char* cmdStr = "command";
94static constexpr const char* cmdMaskStr = "commandMask";
95static constexpr int base_16 = 16;
Yong Libd0503a2019-08-22 17:17:17 +080096#endif // ENABLE_I2C_WHITELIST_CHECK
Joshi-Mansi7fd91fa2021-06-11 07:18:15 +053097static constexpr uint8_t maxIPMIWriteReadSize = 255;
jayaprakash Mutyala3c5e4132020-04-27 23:00:05 +000098static constexpr uint8_t oemCmdStart = 192;
99static constexpr uint8_t oemCmdEnd = 255;
100static constexpr uint8_t invalidParamSelectorStart = 8;
101static constexpr uint8_t invalidParamSelectorEnd = 191;
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +0530102
Nagaraju Goruganti744398d2018-02-20 09:52:00 -0600103/**
104 * @brief Returns the Version info from primary s/w object
105 *
106 * Get the Version info from the active s/w object which is having high
107 * "Priority" value(a smaller number is a higher priority) and "Purpose"
108 * is "BMC" from the list of all s/w objects those are implementing
109 * RedundancyPriority interface from the given softwareRoot path.
110 *
111 * @return On success returns the Version info from primary s/w object.
112 *
113 */
Vernon Maueryea1c4012019-05-24 13:26:16 -0700114std::string getActiveSoftwareVersionInfo(ipmi::Context::ptr ctx)
Nagaraju Goruganti744398d2018-02-20 09:52:00 -0600115{
Nagaraju Goruganti744398d2018-02-20 09:52:00 -0600116 std::string revision{};
Vernon Mauery86a50822019-03-25 13:11:36 -0700117 ipmi::ObjectTree objectTree;
118 try
Nagaraju Goruganti744398d2018-02-20 09:52:00 -0600119 {
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500120 objectTree = ipmi::getAllDbusObjects(*ctx->bus, softwareRoot,
121 redundancyIntf);
Vernon Mauery86a50822019-03-25 13:11:36 -0700122 }
Patrick Williams5d82f472022-07-22 19:26:53 -0500123 catch (const sdbusplus::exception_t& e)
Vernon Mauery86a50822019-03-25 13:11:36 -0700124 {
125 log<level::ERR>("Failed to fetch redundancy object from dbus",
126 entry("INTERFACE=%s", redundancyIntf),
127 entry("ERRMSG=%s", e.what()));
Nagaraju Goruganti744398d2018-02-20 09:52:00 -0600128 elog<InternalFailure>();
129 }
130
131 auto objectFound = false;
132 for (auto& softObject : objectTree)
133 {
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500134 auto service = ipmi::getService(*ctx->bus, redundancyIntf,
135 softObject.first);
136 auto objValueTree = ipmi::getManagedObjects(*ctx->bus, service,
137 softwareRoot);
Nagaraju Goruganti744398d2018-02-20 09:52:00 -0600138
139 auto minPriority = 0xFF;
140 for (const auto& objIter : objValueTree)
141 {
142 try
143 {
144 auto& intfMap = objIter.second;
145 auto& redundancyPriorityProps = intfMap.at(redundancyIntf);
146 auto& versionProps = intfMap.at(versionIntf);
147 auto& activationProps = intfMap.at(activationIntf);
Vernon Maueryf442e112019-04-09 11:44:36 -0700148 auto priority =
149 std::get<uint8_t>(redundancyPriorityProps.at("Priority"));
William A. Kennington III4c008022018-10-12 17:18:14 -0700150 auto purpose =
Vernon Maueryf442e112019-04-09 11:44:36 -0700151 std::get<std::string>(versionProps.at("Purpose"));
152 auto activation =
153 std::get<std::string>(activationProps.at("Activation"));
William A. Kennington III4c008022018-10-12 17:18:14 -0700154 auto version =
Vernon Maueryf442e112019-04-09 11:44:36 -0700155 std::get<std::string>(versionProps.at("Version"));
Nagaraju Goruganti744398d2018-02-20 09:52:00 -0600156 if ((Version::convertVersionPurposeFromString(purpose) ==
157 Version::VersionPurpose::BMC) &&
158 (Activation::convertActivationsFromString(activation) ==
159 Activation::Activations::Active))
160 {
161 if (priority < minPriority)
162 {
163 minPriority = priority;
164 objectFound = true;
165 revision = std::move(version);
166 }
167 }
168 }
169 catch (const std::exception& e)
170 {
171 log<level::ERR>(e.what());
172 }
173 }
174 }
175
176 if (!objectFound)
177 {
178 log<level::ERR>("Could not found an BMC software Object");
179 elog<InternalFailure>();
180 }
181
182 return revision;
183}
184
Alexander Amelkinba19c182018-09-04 15:49:36 +0300185bool getCurrentBmcState()
186{
Patrick Williams5d82f472022-07-22 19:26:53 -0500187 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Alexander Amelkinba19c182018-09-04 15:49:36 +0300188
189 // Get the Inventory object implementing the BMC interface
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500190 ipmi::DbusObjectInfo bmcObject = ipmi::getDbusObject(bus,
191 bmc_state_interface);
192 auto variant = ipmi::getDbusProperty(bus, bmcObject.second, bmcObject.first,
193 bmc_state_interface,
194 bmc_state_property);
Alexander Amelkinba19c182018-09-04 15:49:36 +0300195
Vernon Maueryf442e112019-04-09 11:44:36 -0700196 return std::holds_alternative<std::string>(variant) &&
197 BMC::convertBMCStateFromString(std::get<std::string>(variant)) ==
198 BMC::BMCState::Ready;
Alexander Amelkinba19c182018-09-04 15:49:36 +0300199}
200
Patrick Venture94930a12019-04-30 10:01:58 -0700201bool getCurrentBmcStateWithFallback(const bool fallbackAvailability)
202{
203 try
204 {
205 return getCurrentBmcState();
206 }
207 catch (...)
208 {
209 // Nothing provided the BMC interface, therefore return whatever was
210 // configured as the default.
211 return fallbackAvailability;
212 }
213}
214
Yong Li18d77262018-10-09 01:59:45 +0800215namespace acpi_state
216{
Willy Tu523e2d12023-09-05 11:36:48 -0700217using namespace sdbusplus::server::xyz::openbmc_project::control::power;
Yong Li18d77262018-10-09 01:59:45 +0800218
219const static constexpr char* acpiObjPath =
220 "/xyz/openbmc_project/control/host0/acpi_power_state";
221const static constexpr char* acpiInterface =
222 "xyz.openbmc_project.Control.Power.ACPIPowerState";
223const static constexpr char* sysACPIProp = "SysACPIStatus";
224const static constexpr char* devACPIProp = "DevACPIStatus";
225
226enum class PowerStateType : uint8_t
227{
228 sysPowerState = 0x00,
229 devPowerState = 0x01,
230};
231
232// Defined in 20.6 of ipmi doc
233enum class PowerState : uint8_t
234{
235 s0G0D0 = 0x00,
236 s1D1 = 0x01,
237 s2D2 = 0x02,
238 s3D3 = 0x03,
239 s4 = 0x04,
240 s5G2 = 0x05,
241 s4S5 = 0x06,
242 g3 = 0x07,
243 sleep = 0x08,
244 g1Sleep = 0x09,
245 override = 0x0a,
246 legacyOn = 0x20,
247 legacyOff = 0x21,
248 unknown = 0x2a,
249 noChange = 0x7f,
250};
251
252static constexpr uint8_t stateChanged = 0x80;
253
Yong Li18d77262018-10-09 01:59:45 +0800254std::map<ACPIPowerState::ACPI, PowerState> dbusToIPMI = {
255 {ACPIPowerState::ACPI::S0_G0_D0, PowerState::s0G0D0},
256 {ACPIPowerState::ACPI::S1_D1, PowerState::s1D1},
257 {ACPIPowerState::ACPI::S2_D2, PowerState::s2D2},
258 {ACPIPowerState::ACPI::S3_D3, PowerState::s3D3},
259 {ACPIPowerState::ACPI::S4, PowerState::s4},
260 {ACPIPowerState::ACPI::S5_G2, PowerState::s5G2},
261 {ACPIPowerState::ACPI::S4_S5, PowerState::s4S5},
262 {ACPIPowerState::ACPI::G3, PowerState::g3},
263 {ACPIPowerState::ACPI::SLEEP, PowerState::sleep},
264 {ACPIPowerState::ACPI::G1_SLEEP, PowerState::g1Sleep},
265 {ACPIPowerState::ACPI::OVERRIDE, PowerState::override},
266 {ACPIPowerState::ACPI::LEGACY_ON, PowerState::legacyOn},
267 {ACPIPowerState::ACPI::LEGACY_OFF, PowerState::legacyOff},
268 {ACPIPowerState::ACPI::Unknown, PowerState::unknown}};
269
270bool isValidACPIState(acpi_state::PowerStateType type, uint8_t state)
271{
272 if (type == acpi_state::PowerStateType::sysPowerState)
273 {
274 if ((state <= static_cast<uint8_t>(acpi_state::PowerState::override)) ||
275 (state == static_cast<uint8_t>(acpi_state::PowerState::legacyOn)) ||
276 (state ==
277 static_cast<uint8_t>(acpi_state::PowerState::legacyOff)) ||
278 (state == static_cast<uint8_t>(acpi_state::PowerState::unknown)) ||
279 (state == static_cast<uint8_t>(acpi_state::PowerState::noChange)))
280 {
281 return true;
282 }
283 else
284 {
285 return false;
286 }
287 }
288 else if (type == acpi_state::PowerStateType::devPowerState)
289 {
290 if ((state <= static_cast<uint8_t>(acpi_state::PowerState::s3D3)) ||
291 (state == static_cast<uint8_t>(acpi_state::PowerState::unknown)) ||
292 (state == static_cast<uint8_t>(acpi_state::PowerState::noChange)))
293 {
294 return true;
295 }
296 else
297 {
298 return false;
299 }
300 }
301 else
302 {
303 return false;
304 }
305 return false;
306}
307} // namespace acpi_state
308
Deepak Kumar Sahu520c1312019-05-17 18:14:09 +0000309/** @brief implements Set ACPI Power State command
310 * @param sysAcpiState - ACPI system power state to set
311 * @param devAcpiState - ACPI device power state to set
312 *
313 * @return IPMI completion code on success
314 **/
315ipmi::RspType<> ipmiSetAcpiPowerState(uint8_t sysAcpiState,
316 uint8_t devAcpiState)
Chris Austen6caf28b2015-10-13 12:40:40 -0500317{
Yong Li18d77262018-10-09 01:59:45 +0800318 auto s = static_cast<uint8_t>(acpi_state::PowerState::unknown);
Yong Li18d77262018-10-09 01:59:45 +0800319
Patrick Williams5d82f472022-07-22 19:26:53 -0500320 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Yong Li18d77262018-10-09 01:59:45 +0800321
322 auto value = acpi_state::ACPIPowerState::ACPI::Unknown;
323
Deepak Kumar Sahu520c1312019-05-17 18:14:09 +0000324 if (sysAcpiState & acpi_state::stateChanged)
Yong Li18d77262018-10-09 01:59:45 +0800325 {
326 // set system power state
Deepak Kumar Sahu520c1312019-05-17 18:14:09 +0000327 s = sysAcpiState & ~acpi_state::stateChanged;
Yong Li18d77262018-10-09 01:59:45 +0800328
329 if (!acpi_state::isValidACPIState(
330 acpi_state::PowerStateType::sysPowerState, s))
331 {
332 log<level::ERR>("set_acpi_power sys invalid input",
333 entry("S=%x", s));
Deepak Kumar Sahu520c1312019-05-17 18:14:09 +0000334 return ipmi::responseParmOutOfRange();
Yong Li18d77262018-10-09 01:59:45 +0800335 }
336
337 // valid input
338 if (s == static_cast<uint8_t>(acpi_state::PowerState::noChange))
339 {
340 log<level::DEBUG>("No change for system power state");
341 }
342 else
343 {
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500344 auto found = std::find_if(acpi_state::dbusToIPMI.begin(),
345 acpi_state::dbusToIPMI.end(),
346 [&s](const auto& iter) {
347 return (static_cast<uint8_t>(iter.second) == s);
348 });
Yong Li18d77262018-10-09 01:59:45 +0800349
350 value = found->first;
351
352 try
353 {
354 auto acpiObject =
355 ipmi::getDbusObject(bus, acpi_state::acpiInterface);
356 ipmi::setDbusProperty(bus, acpiObject.second, acpiObject.first,
357 acpi_state::acpiInterface,
358 acpi_state::sysACPIProp,
359 convertForMessage(value));
360 }
361 catch (const InternalFailure& e)
362 {
363 log<level::ERR>("Failed in set ACPI system property",
364 entry("EXCEPTION=%s", e.what()));
Deepak Kumar Sahu520c1312019-05-17 18:14:09 +0000365 return ipmi::responseUnspecifiedError();
Yong Li18d77262018-10-09 01:59:45 +0800366 }
367 }
368 }
369 else
370 {
371 log<level::DEBUG>("Do not change system power state");
372 }
373
Deepak Kumar Sahu520c1312019-05-17 18:14:09 +0000374 if (devAcpiState & acpi_state::stateChanged)
Yong Li18d77262018-10-09 01:59:45 +0800375 {
376 // set device power state
Deepak Kumar Sahu520c1312019-05-17 18:14:09 +0000377 s = devAcpiState & ~acpi_state::stateChanged;
Yong Li18d77262018-10-09 01:59:45 +0800378 if (!acpi_state::isValidACPIState(
379 acpi_state::PowerStateType::devPowerState, s))
380 {
381 log<level::ERR>("set_acpi_power dev invalid input",
382 entry("S=%x", s));
Deepak Kumar Sahu520c1312019-05-17 18:14:09 +0000383 return ipmi::responseParmOutOfRange();
Yong Li18d77262018-10-09 01:59:45 +0800384 }
385
386 // valid input
387 if (s == static_cast<uint8_t>(acpi_state::PowerState::noChange))
388 {
389 log<level::DEBUG>("No change for device power state");
390 }
391 else
392 {
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -0500393 auto found = std::find_if(acpi_state::dbusToIPMI.begin(),
394 acpi_state::dbusToIPMI.end(),
395 [&s](const auto& iter) {
396 return (static_cast<uint8_t>(iter.second) == s);
397 });
Yong Li18d77262018-10-09 01:59:45 +0800398
399 value = found->first;
400
401 try
402 {
403 auto acpiObject =
404 ipmi::getDbusObject(bus, acpi_state::acpiInterface);
405 ipmi::setDbusProperty(bus, acpiObject.second, acpiObject.first,
406 acpi_state::acpiInterface,
407 acpi_state::devACPIProp,
408 convertForMessage(value));
409 }
410 catch (const InternalFailure& e)
411 {
412 log<level::ERR>("Failed in set ACPI device property",
413 entry("EXCEPTION=%s", e.what()));
Deepak Kumar Sahu520c1312019-05-17 18:14:09 +0000414 return ipmi::responseUnspecifiedError();
Yong Li18d77262018-10-09 01:59:45 +0800415 }
416 }
417 }
418 else
419 {
420 log<level::DEBUG>("Do not change device power state");
421 }
Deepak Kumar Sahu520c1312019-05-17 18:14:09 +0000422 return ipmi::responseSuccess();
Yong Li18d77262018-10-09 01:59:45 +0800423}
424
Deepak Kumar Sahu4e6d2572019-05-07 19:53:37 +0000425/**
426 * @brief implements the get ACPI power state command
427 *
428 * @return IPMI completion code plus response data on success.
429 * - ACPI system power state
430 * - ACPI device power state
431 **/
432ipmi::RspType<uint8_t, // acpiSystemPowerState
433 uint8_t // acpiDevicePowerState
434 >
435 ipmiGetAcpiPowerState()
Yong Li18d77262018-10-09 01:59:45 +0800436{
Deepak Kumar Sahu4e6d2572019-05-07 19:53:37 +0000437 uint8_t sysAcpiState;
438 uint8_t devAcpiState;
Yong Li18d77262018-10-09 01:59:45 +0800439
Patrick Williams5d82f472022-07-22 19:26:53 -0500440 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Yong Li18d77262018-10-09 01:59:45 +0800441
Yong Li18d77262018-10-09 01:59:45 +0800442 try
443 {
444 auto acpiObject = ipmi::getDbusObject(bus, acpi_state::acpiInterface);
445
446 auto sysACPIVal = ipmi::getDbusProperty(
447 bus, acpiObject.second, acpiObject.first, acpi_state::acpiInterface,
448 acpi_state::sysACPIProp);
449 auto sysACPI = acpi_state::ACPIPowerState::convertACPIFromString(
Vernon Maueryf442e112019-04-09 11:44:36 -0700450 std::get<std::string>(sysACPIVal));
Deepak Kumar Sahu4e6d2572019-05-07 19:53:37 +0000451 sysAcpiState = static_cast<uint8_t>(acpi_state::dbusToIPMI.at(sysACPI));
Yong Li18d77262018-10-09 01:59:45 +0800452
453 auto devACPIVal = ipmi::getDbusProperty(
454 bus, acpiObject.second, acpiObject.first, acpi_state::acpiInterface,
455 acpi_state::devACPIProp);
456 auto devACPI = acpi_state::ACPIPowerState::convertACPIFromString(
Vernon Maueryf442e112019-04-09 11:44:36 -0700457 std::get<std::string>(devACPIVal));
Deepak Kumar Sahu4e6d2572019-05-07 19:53:37 +0000458 devAcpiState = static_cast<uint8_t>(acpi_state::dbusToIPMI.at(devACPI));
Yong Li18d77262018-10-09 01:59:45 +0800459 }
460 catch (const InternalFailure& e)
461 {
Deepak Kumar Sahu4e6d2572019-05-07 19:53:37 +0000462 return ipmi::responseUnspecifiedError();
Yong Li18d77262018-10-09 01:59:45 +0800463 }
Deepak Kumar Sahu4e6d2572019-05-07 19:53:37 +0000464
465 return ipmi::responseSuccess(sysAcpiState, devAcpiState);
Chris Austen6caf28b2015-10-13 12:40:40 -0500466}
467
Chris Austen7303bdc2016-04-17 11:50:54 -0500468typedef struct
469{
470 char major;
471 char minor;
Potin Laic7c55922023-02-16 10:33:55 +0800472 uint8_t aux[4];
Vernon Mauery86a50822019-03-25 13:11:36 -0700473} Revision;
Chris Austen7303bdc2016-04-17 11:50:54 -0500474
Potin Lai5d214202023-01-16 18:11:49 +0800475/* Use regular expression searching matched pattern X.Y, and convert it to */
476/* Major (X) and Minor (Y) version. */
477/* Example: */
478/* version = 2.14.0-dev */
479/* ^ ^ */
480/* | |---------------- Minor */
481/* |------------------ Major */
482/* */
Potin Laic7c55922023-02-16 10:33:55 +0800483/* Default regex string only tries to match Major and Minor version. */
484/* */
485/* To match more firmware version info, platforms need to define it own */
486/* regex string to match more strings, and assign correct mapping index in */
487/* matches array. */
488/* */
489/* matches[0]: matched index for major ver */
490/* matches[1]: matched index for minor ver */
491/* matches[2]: matched index for aux[0] (set 0 to skip) */
492/* matches[3]: matched index for aux[1] (set 0 to skip) */
493/* matches[4]: matched index for aux[2] (set 0 to skip) */
494/* matches[5]: matched index for aux[3] (set 0 to skip) */
495/* Example: */
496/* regex = "([\d]+).([\d]+).([\d]+)-dev-([\d]+)-g([0-9a-fA-F]{2}) */
497/* ([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})" */
498/* matches = {1,2,5,6,7,8} */
499/* version = 2.14.0-dev-750-g37a7c5ad1-dirty */
500/* ^ ^ ^ ^ ^ ^ ^ ^ */
501/* | | | | | | | | */
502/* | | | | | | | |-- Aux byte 3 (0xAD), index 8 */
503/* | | | | | | |---- Aux byte 2 (0xC5), index 7 */
504/* | | | | | |------ Aux byte 1 (0xA7), index 6 */
505/* | | | | |-------- Aux byte 0 (0x37), index 5 */
506/* | | | |------------- Not used, index 4 */
507/* | | |------------------- Not used, index 3 */
508/* | |---------------------- Minor (14), index 2 */
509/* |------------------------ Major (2), index 1 */
Potin Lai5d214202023-01-16 18:11:49 +0800510int convertVersion(std::string s, Revision& rev)
Chris Austen7303bdc2016-04-17 11:50:54 -0500511{
Potin Laic7c55922023-02-16 10:33:55 +0800512 static const std::vector<size_t> matches = {
513 MAJOR_MATCH_INDEX, MINOR_MATCH_INDEX, AUX_0_MATCH_INDEX,
514 AUX_1_MATCH_INDEX, AUX_2_MATCH_INDEX, AUX_3_MATCH_INDEX};
Potin Lai5d214202023-01-16 18:11:49 +0800515 std::regex fw_regex(FW_VER_REGEX);
516 std::smatch m;
517 Revision r = {0};
518 size_t val;
Chris Austen7303bdc2016-04-17 11:50:54 -0500519
Potin Laidcde04e2023-03-16 18:44:15 +0800520 if (std::regex_search(s, m, fw_regex))
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -0600521 {
Potin Laic7c55922023-02-16 10:33:55 +0800522 if (m.size() < *std::max_element(matches.begin(), matches.end()))
523 { // max index higher than match count
Potin Laidcde04e2023-03-16 18:44:15 +0800524 return -1;
525 }
526
Potin Lai5d214202023-01-16 18:11:49 +0800527 // convert major
528 {
Potin Laic7c55922023-02-16 10:33:55 +0800529 std::string_view str = m[matches[0]].str();
Potin Lai5d214202023-01-16 18:11:49 +0800530 auto [ptr, ec]{std::from_chars(str.begin(), str.end(), val)};
531 if (ec != std::errc() || ptr != str.begin() + str.size())
532 { // failed to convert major string
Potin Laidcde04e2023-03-16 18:44:15 +0800533 return -1;
Potin Lai5d214202023-01-16 18:11:49 +0800534 }
535 r.major = val & 0x7F;
536 }
537
538 // convert minor
539 {
Potin Laic7c55922023-02-16 10:33:55 +0800540 std::string_view str = m[matches[1]].str();
Potin Lai5d214202023-01-16 18:11:49 +0800541 auto [ptr, ec]{std::from_chars(str.begin(), str.end(), val)};
542 if (ec != std::errc() || ptr != str.begin() + str.size())
543 { // failed to convert minor string
Potin Laidcde04e2023-03-16 18:44:15 +0800544 return -1;
Potin Lai5d214202023-01-16 18:11:49 +0800545 }
546 r.minor = val & 0xFF;
547 }
548
Potin Laic7c55922023-02-16 10:33:55 +0800549 // convert aux bytes
550 {
551 size_t i;
552 for (i = 0; i < 4; i++)
553 {
554 if (matches[i + 2] == 0)
555 {
556 continue;
557 }
558
559 std::string_view str = m[matches[i + 2]].str();
560 auto [ptr,
561 ec]{std::from_chars(str.begin(), str.end(), val, 16)};
562 if (ec != std::errc() || ptr != str.begin() + str.size())
563 { // failed to convert aux byte string
564 break;
565 }
566
567 r.aux[i] = val & 0xFF;
568 }
569
570 if (i != 4)
571 { // something wrong durign converting aux bytes
572 return -1;
573 }
574 }
575
Potin Lai5d214202023-01-16 18:11:49 +0800576 // all matched
577 rev = r;
578 return 0;
Chris Austen176c9652016-04-30 16:32:17 -0500579 }
Chris Austen7303bdc2016-04-17 11:50:54 -0500580
Potin Lai5d214202023-01-16 18:11:49 +0800581 return -1;
Chris Austen7303bdc2016-04-17 11:50:54 -0500582}
583
Vernon Maueryea1c4012019-05-24 13:26:16 -0700584/* @brief: Implement the Get Device ID IPMI command per the IPMI spec
585 * @param[in] ctx - shared_ptr to an IPMI context struct
586 *
587 * @returns IPMI completion code plus response data
588 * - Device ID (manufacturer defined)
589 * - Device revision[4 bits]; reserved[3 bits]; SDR support[1 bit]
590 * - FW revision major[7 bits] (binary encoded); available[1 bit]
591 * - FW Revision minor (BCD encoded)
592 * - IPMI version (0x02 for IPMI 2.0)
593 * - device support (bitfield of supported options)
594 * - MFG IANA ID (3 bytes)
595 * - product ID (2 bytes)
596 * - AUX info (4 bytes)
597 */
598ipmi::RspType<uint8_t, // Device ID
599 uint8_t, // Device Revision
600 uint8_t, // Firmware Revision Major
601 uint8_t, // Firmware Revision minor
602 uint8_t, // IPMI version
603 uint8_t, // Additional device support
604 uint24_t, // MFG ID
605 uint16_t, // Product ID
606 uint32_t // AUX info
607 >
Willy Tu11d68892022-01-20 10:37:34 -0800608 ipmiAppGetDeviceId([[maybe_unused]] ipmi::Context::ptr ctx)
Chris Austen6caf28b2015-10-13 12:40:40 -0500609{
Vernon Mauery86a50822019-03-25 13:11:36 -0700610 static struct
611 {
612 uint8_t id;
613 uint8_t revision;
614 uint8_t fw[2];
615 uint8_t ipmiVer;
616 uint8_t addnDevSupport;
617 uint24_t manufId;
618 uint16_t prodId;
619 uint32_t aux;
620 } devId;
David Cobbleya1adb072017-11-21 15:58:13 -0800621 static bool dev_id_initialized = false;
Patrick Venture94930a12019-04-30 10:01:58 -0700622 static bool defaultActivationSetting = true;
David Cobbleya1adb072017-11-21 15:58:13 -0800623 const char* filename = "/usr/share/ipmi-providers/dev_id.json";
Alexander Amelkinba19c182018-09-04 15:49:36 +0300624 constexpr auto ipmiDevIdStateShift = 7;
625 constexpr auto ipmiDevIdFw1Mask = ~(1 << ipmiDevIdStateShift);
Willy Tub78184e2022-10-27 22:57:38 +0000626
627#ifdef GET_DBUS_ACTIVE_SOFTWARE
628 static bool haveBMCVersion = false;
JeffLin27a62ec2021-11-24 15:40:33 +0800629 if (!haveBMCVersion || !dev_id_initialized)
David Cobbleya1adb072017-11-21 15:58:13 -0800630 {
Willy Tub78184e2022-10-27 22:57:38 +0000631 int r = -1;
632 Revision rev = {0, 0, 0, 0};
Nagaraju Goruganti744398d2018-02-20 09:52:00 -0600633 try
634 {
Vernon Maueryea1c4012019-05-24 13:26:16 -0700635 auto version = getActiveSoftwareVersionInfo(ctx);
Vernon Mauery86a50822019-03-25 13:11:36 -0700636 r = convertVersion(version, rev);
David Cobbleya1adb072017-11-21 15:58:13 -0800637 }
Nagaraju Goruganti744398d2018-02-20 09:52:00 -0600638 catch (const std::exception& e)
639 {
640 log<level::ERR>(e.what());
641 }
Nan Liee0cb902016-07-11 15:38:03 +0800642
Patrick Venture0b02be92018-08-31 11:55:55 -0700643 if (r >= 0)
644 {
Nagaraju Goruganti744398d2018-02-20 09:52:00 -0600645 // bit7 identifies if the device is available
646 // 0=normal operation
647 // 1=device firmware, SDR update,
648 // or self-initialization in progress.
Alexander Amelkinba19c182018-09-04 15:49:36 +0300649 // The availability may change in run time, so mask here
650 // and initialize later.
Vernon Mauery86a50822019-03-25 13:11:36 -0700651 devId.fw[0] = rev.major & ipmiDevIdFw1Mask;
Nagaraju Goruganti744398d2018-02-20 09:52:00 -0600652
653 rev.minor = (rev.minor > 99 ? 99 : rev.minor);
Vernon Mauery86a50822019-03-25 13:11:36 -0700654 devId.fw[1] = rev.minor % 10 + (rev.minor / 10) * 16;
Potin Laic7c55922023-02-16 10:33:55 +0800655 std::memcpy(&devId.aux, rev.aux, sizeof(rev.aux));
Brandon Kimc1f5aca2022-03-17 17:54:06 -0700656 haveBMCVersion = true;
David Cobbleya1adb072017-11-21 15:58:13 -0800657 }
JeffLin27a62ec2021-11-24 15:40:33 +0800658 }
Willy Tub78184e2022-10-27 22:57:38 +0000659#endif
JeffLin27a62ec2021-11-24 15:40:33 +0800660 if (!dev_id_initialized)
661 {
David Cobbleya1adb072017-11-21 15:58:13 -0800662 // IPMI Spec version 2.0
Vernon Mauery86a50822019-03-25 13:11:36 -0700663 devId.ipmiVer = 2;
Adriana Kobylak0e912642016-06-22 16:54:39 -0500664
Vernon Mauery86a50822019-03-25 13:11:36 -0700665 std::ifstream devIdFile(filename);
666 if (devIdFile.is_open())
David Cobbleya1adb072017-11-21 15:58:13 -0800667 {
Vernon Mauery86a50822019-03-25 13:11:36 -0700668 auto data = nlohmann::json::parse(devIdFile, nullptr, false);
David Cobbleya1adb072017-11-21 15:58:13 -0800669 if (!data.is_discarded())
670 {
Vernon Mauery86a50822019-03-25 13:11:36 -0700671 devId.id = data.value("id", 0);
672 devId.revision = data.value("revision", 0);
673 devId.addnDevSupport = data.value("addn_dev_support", 0);
674 devId.manufId = data.value("manuf_id", 0);
675 devId.prodId = data.value("prod_id", 0);
Potin Lai9a686362023-09-05 09:27:53 +0800676#ifdef GET_DBUS_ACTIVE_SOFTWARE
677 if (!(AUX_0_MATCH_INDEX || AUX_1_MATCH_INDEX ||
678 AUX_2_MATCH_INDEX || AUX_3_MATCH_INDEX))
679#endif
680 {
681 devId.aux = data.value("aux", 0);
682 }
David Cobbleya1adb072017-11-21 15:58:13 -0800683
Willy Tubfd3a172022-05-31 13:57:54 -0700684 if (data.contains("firmware_revision"))
685 {
686 const auto& firmwareRevision = data.at("firmware_revision");
687 if (firmwareRevision.contains("major"))
688 {
689 firmwareRevision.at("major").get_to(devId.fw[0]);
690 }
691 if (firmwareRevision.contains("minor"))
692 {
693 firmwareRevision.at("minor").get_to(devId.fw[1]);
694 }
695 }
696
Patrick Venture94930a12019-04-30 10:01:58 -0700697 // Set the availablitity of the BMC.
698 defaultActivationSetting = data.value("availability", true);
699
Patrick Venture0b02be92018-08-31 11:55:55 -0700700 // Don't read the file every time if successful
David Cobbleya1adb072017-11-21 15:58:13 -0800701 dev_id_initialized = true;
702 }
703 else
704 {
705 log<level::ERR>("Device ID JSON parser failure");
Vernon Maueryf2587fc2019-04-09 14:28:15 -0700706 return ipmi::responseUnspecifiedError();
David Cobbleya1adb072017-11-21 15:58:13 -0800707 }
708 }
709 else
710 {
711 log<level::ERR>("Device ID file not found");
Vernon Maueryf2587fc2019-04-09 14:28:15 -0700712 return ipmi::responseUnspecifiedError();
Chris Austen7303bdc2016-04-17 11:50:54 -0500713 }
714 }
Chris Austen6caf28b2015-10-13 12:40:40 -0500715
Alexander Amelkinba19c182018-09-04 15:49:36 +0300716 // Set availability to the actual current BMC state
Vernon Mauery86a50822019-03-25 13:11:36 -0700717 devId.fw[0] &= ipmiDevIdFw1Mask;
Patrick Venture94930a12019-04-30 10:01:58 -0700718 if (!getCurrentBmcStateWithFallback(defaultActivationSetting))
Alexander Amelkinba19c182018-09-04 15:49:36 +0300719 {
Vernon Mauery86a50822019-03-25 13:11:36 -0700720 devId.fw[0] |= (1 << ipmiDevIdStateShift);
Alexander Amelkinba19c182018-09-04 15:49:36 +0300721 }
722
Vernon Mauery86a50822019-03-25 13:11:36 -0700723 return ipmi::responseSuccess(
724 devId.id, devId.revision, devId.fw[0], devId.fw[1], devId.ipmiVer,
725 devId.addnDevSupport, devId.manufId, devId.prodId, devId.aux);
Chris Austen6caf28b2015-10-13 12:40:40 -0500726}
727
Vernon Maueryb84a5282019-03-25 13:39:03 -0700728auto ipmiAppGetSelfTestResults() -> ipmi::RspType<uint8_t, uint8_t>
Nan Li41fa24a2016-11-10 20:12:37 +0800729{
Nan Li41fa24a2016-11-10 20:12:37 +0800730 // Byte 2:
731 // 55h - No error.
Gunnar Mills8991dd62017-10-25 17:11:29 -0500732 // 56h - Self Test function not implemented in this controller.
Nan Li41fa24a2016-11-10 20:12:37 +0800733 // 57h - Corrupted or inaccesssible data or devices.
734 // 58h - Fatal hardware error.
735 // FFh - reserved.
736 // all other: Device-specific 'internal failure'.
737 // Byte 3:
738 // For byte 2 = 55h, 56h, FFh: 00h
739 // For byte 2 = 58h, all other: Device-specific
740 // For byte 2 = 57h: self-test error bitfield.
741 // Note: returning 57h does not imply that all test were run.
742 // [7] 1b = Cannot access SEL device.
743 // [6] 1b = Cannot access SDR Repository.
744 // [5] 1b = Cannot access BMC FRU device.
745 // [4] 1b = IPMB signal lines do not respond.
746 // [3] 1b = SDR Repository empty.
747 // [2] 1b = Internal Use Area of BMC FRU corrupted.
748 // [1] 1b = controller update 'boot block' firmware corrupted.
749 // [0] 1b = controller operational firmware corrupted.
Vernon Maueryb84a5282019-03-25 13:39:03 -0700750 constexpr uint8_t notImplemented = 0x56;
751 constexpr uint8_t zero = 0;
752 return ipmi::responseSuccess(notImplemented, zero);
Nan Li41fa24a2016-11-10 20:12:37 +0800753}
754
Vernon Mauery15541322019-03-25 13:33:03 -0700755static constexpr size_t uuidBinaryLength = 16;
756static std::array<uint8_t, uuidBinaryLength> rfc4122ToIpmi(std::string rfc4122)
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500757{
Willy Tu523e2d12023-09-05 11:36:48 -0700758 using Argument = xyz::openbmc_project::common::InvalidArgument;
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500759 // UUID is in RFC4122 format. Ex: 61a39523-78f2-11e5-9862-e6402cfc3223
Patrick Ventured2117022018-02-06 08:54:37 -0800760 // Per IPMI Spec 2.0 need to convert to 16 hex bytes and reverse the byte
761 // order
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500762 // Ex: 0x2332fc2c40e66298e511f2782395a361
Vernon Mauery15541322019-03-25 13:33:03 -0700763 constexpr size_t uuidHexLength = (2 * uuidBinaryLength);
764 constexpr size_t uuidRfc4122Length = (uuidHexLength + 4);
765 std::array<uint8_t, uuidBinaryLength> uuid;
766 if (rfc4122.size() == uuidRfc4122Length)
Patrick Venture0b02be92018-08-31 11:55:55 -0700767 {
Vernon Mauery15541322019-03-25 13:33:03 -0700768 rfc4122.erase(std::remove(rfc4122.begin(), rfc4122.end(), '-'),
769 rfc4122.end());
Sergey Solomineb9b8142016-08-23 09:07:28 -0500770 }
Vernon Mauery15541322019-03-25 13:33:03 -0700771 if (rfc4122.size() != uuidHexLength)
vishwa1eaea4f2016-02-26 11:57:40 -0600772 {
Vernon Mauery15541322019-03-25 13:33:03 -0700773 elog<InvalidArgument>(Argument::ARGUMENT_NAME("rfc4122"),
774 Argument::ARGUMENT_VALUE(rfc4122.c_str()));
vishwa1eaea4f2016-02-26 11:57:40 -0600775 }
Vernon Mauery15541322019-03-25 13:33:03 -0700776 for (size_t ind = 0; ind < uuidHexLength; ind += 2)
vishwa1eaea4f2016-02-26 11:57:40 -0600777 {
Vernon Mauery15541322019-03-25 13:33:03 -0700778 char v[3];
779 v[0] = rfc4122[ind];
780 v[1] = rfc4122[ind + 1];
781 v[2] = 0;
782 size_t err;
783 long b;
784 try
Emily Shafferedb8bb02018-09-27 14:50:15 -0700785 {
Vernon Mauery15541322019-03-25 13:33:03 -0700786 b = std::stoul(v, &err, 16);
Emily Shafferedb8bb02018-09-27 14:50:15 -0700787 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500788 catch (const std::exception& e)
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500789 {
Vernon Mauery15541322019-03-25 13:33:03 -0700790 elog<InvalidArgument>(Argument::ARGUMENT_NAME("rfc4122"),
791 Argument::ARGUMENT_VALUE(rfc4122.c_str()));
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500792 }
Vernon Mauery15541322019-03-25 13:33:03 -0700793 // check that exactly two ascii bytes were converted
794 if (err != 2)
795 {
796 elog<InvalidArgument>(Argument::ARGUMENT_NAME("rfc4122"),
797 Argument::ARGUMENT_VALUE(rfc4122.c_str()));
798 }
799 uuid[uuidBinaryLength - (ind / 2) - 1] = static_cast<uint8_t>(b);
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500800 }
Vernon Mauery15541322019-03-25 13:33:03 -0700801 return uuid;
802}
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500803
Vernon Mauery15541322019-03-25 13:33:03 -0700804auto ipmiAppGetDeviceGuid()
805 -> ipmi::RspType<std::array<uint8_t, uuidBinaryLength>>
806{
807 // return a fixed GUID based on /etc/machine-id
808 // This should match the /redfish/v1/Managers/bmc's UUID data
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500809
Vernon Mauery15541322019-03-25 13:33:03 -0700810 // machine specific application ID (for BMC ID)
811 // generated by systemd-id128 -p new as per man page
812 static constexpr sd_id128_t bmcUuidAppId = SD_ID128_MAKE(
813 e0, e1, 73, 76, 64, 61, 47, da, a5, 0c, d0, cc, 64, 12, 45, 78);
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500814
Vernon Mauery15541322019-03-25 13:33:03 -0700815 sd_id128_t bmcUuid;
816 // create the UUID from /etc/machine-id via the systemd API
817 sd_id128_get_machine_app_specific(bmcUuidAppId, &bmcUuid);
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500818
Vernon Mauery15541322019-03-25 13:33:03 -0700819 char bmcUuidCstr[SD_ID128_STRING_MAX];
820 std::string systemUuid = sd_id128_to_string(bmcUuid, bmcUuidCstr);
821
822 std::array<uint8_t, uuidBinaryLength> uuid = rfc4122ToIpmi(systemUuid);
823 return ipmi::responseSuccess(uuid);
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500824}
Chris Austen6caf28b2015-10-13 12:40:40 -0500825
Vernon Mauerycc99ba42019-03-25 13:40:11 -0700826auto ipmiAppGetBtCapabilities()
827 -> ipmi::RspType<uint8_t, uint8_t, uint8_t, uint8_t, uint8_t>
vishwabmcba0bd5f2015-09-30 16:50:23 +0530828{
Adriana Kobylak88ad8152016-12-13 10:09:08 -0600829 // Per IPMI 2.0 spec, the input and output buffer size must be the max
830 // buffer size minus one byte to allocate space for the length byte.
Vernon Mauerycc99ba42019-03-25 13:40:11 -0700831 constexpr uint8_t nrOutstanding = 0x01;
832 constexpr uint8_t inputBufferSize = MAX_IPMI_BUFFER - 1;
833 constexpr uint8_t outputBufferSize = MAX_IPMI_BUFFER - 1;
834 constexpr uint8_t transactionTime = 0x0A;
835 constexpr uint8_t nrRetries = 0x01;
vishwabmcba0bd5f2015-09-30 16:50:23 +0530836
Vernon Mauerycc99ba42019-03-25 13:40:11 -0700837 return ipmi::responseSuccess(nrOutstanding, inputBufferSize,
838 outputBufferSize, transactionTime, nrRetries);
vishwabmcba0bd5f2015-09-30 16:50:23 +0530839}
840
Vernon Mauery6c44a942023-07-27 11:00:10 -0700841auto ipmiAppGetSystemGuid(ipmi::Context::ptr& ctx)
842 -> ipmi::RspType<std::array<uint8_t, 16>>
Marri Devender Rao5e007a52018-01-08 06:18:36 -0600843{
Vernon Maueryb90a5322019-03-25 13:36:55 -0700844 static constexpr auto uuidInterface = "xyz.openbmc_project.Common.UUID";
845 static constexpr auto uuidProperty = "UUID";
Marri Devender Rao5e007a52018-01-08 06:18:36 -0600846
Vernon Mauery6c44a942023-07-27 11:00:10 -0700847 // Get the Inventory object implementing BMC interface
848 ipmi::DbusObjectInfo objectInfo{};
849 boost::system::error_code ec = ipmi::getDbusObject(ctx, uuidInterface,
850 objectInfo);
851 if (ec.value())
Marri Devender Rao5e007a52018-01-08 06:18:36 -0600852 {
Vernon Mauery6c44a942023-07-27 11:00:10 -0700853 log<level::ERR>("Failed to locate System UUID object",
854 entry("INTERFACE=%s", uuidInterface),
855 entry("ERROR=%s", ec.message().c_str()));
856 return ipmi::responseUnspecifiedError();
Marri Devender Rao5e007a52018-01-08 06:18:36 -0600857 }
Vernon Mauery6c44a942023-07-27 11:00:10 -0700858
859 // Read UUID property value from bmcObject
860 // UUID is in RFC4122 format Ex: 61a39523-78f2-11e5-9862-e6402cfc3223
861 std::string rfc4122Uuid{};
862 ec = ipmi::getDbusProperty(ctx, objectInfo.second, objectInfo.first,
863 uuidInterface, uuidProperty, rfc4122Uuid);
864 if (ec.value())
Marri Devender Rao5e007a52018-01-08 06:18:36 -0600865 {
866 log<level::ERR>("Failed in reading BMC UUID property",
Vernon Maueryb90a5322019-03-25 13:36:55 -0700867 entry("INTERFACE=%s", uuidInterface),
Vernon Mauery6c44a942023-07-27 11:00:10 -0700868 entry("PROPERTY=%s", uuidProperty),
869 entry("ERROR=%s", ec.message().c_str()));
Vernon Maueryb90a5322019-03-25 13:36:55 -0700870 return ipmi::responseUnspecifiedError();
Marri Devender Rao5e007a52018-01-08 06:18:36 -0600871 }
Vernon Maueryb90a5322019-03-25 13:36:55 -0700872 std::array<uint8_t, 16> uuid;
Vernon Maueryb90a5322019-03-25 13:36:55 -0700873 try
874 {
875 // convert to IPMI format
876 uuid = rfc4122ToIpmi(rfc4122Uuid);
877 }
878 catch (const InvalidArgument& e)
879 {
880 log<level::ERR>("Failed in parsing BMC UUID property",
881 entry("INTERFACE=%s", uuidInterface),
882 entry("PROPERTY=%s", uuidProperty),
883 entry("VALUE=%s", rfc4122Uuid.c_str()));
884 return ipmi::responseUnspecifiedError();
885 }
886 return ipmi::responseSuccess(uuid);
Marri Devender Rao5e007a52018-01-08 06:18:36 -0600887}
888
Rajashekar Gade Reddye7023922019-07-10 16:54:55 +0000889/**
890 * @brief set the session state as teardown
891 *
892 * This function is to set the session state to tear down in progress if the
893 * state is active.
894 *
895 * @param[in] busp - Dbus obj
896 * @param[in] service - service name
897 * @param[in] obj - object path
898 *
899 * @return success completion code if it sets the session state to
900 * tearDownInProgress else return the corresponding error completion code.
901 **/
902uint8_t setSessionState(std::shared_ptr<sdbusplus::asio::connection>& busp,
903 const std::string& service, const std::string& obj)
904{
905 try
906 {
907 uint8_t sessionState = std::get<uint8_t>(ipmi::getDbusProperty(
908 *busp, service, obj, session::sessionIntf, "State"));
909
910 if (sessionState == static_cast<uint8_t>(session::State::active))
911 {
912 ipmi::setDbusProperty(
913 *busp, service, obj, session::sessionIntf, "State",
914 static_cast<uint8_t>(session::State::tearDownInProgress));
915 return ipmi::ccSuccess;
916 }
917 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500918 catch (const std::exception& e)
Rajashekar Gade Reddye7023922019-07-10 16:54:55 +0000919 {
920 log<level::ERR>("Failed in getting session state property",
921 entry("service=%s", service.c_str()),
922 entry("object path=%s", obj.c_str()),
923 entry("interface=%s", session::sessionIntf));
924 return ipmi::ccUnspecifiedError;
925 }
926
927 return ipmi::ccInvalidFieldRequest;
928}
929
930ipmi::RspType<> ipmiAppCloseSession(uint32_t reqSessionId,
931 std::optional<uint8_t> requestSessionHandle)
932{
933 auto busp = getSdBus();
934 uint8_t reqSessionHandle =
935 requestSessionHandle.value_or(session::defaultSessionHandle);
936
937 if (reqSessionId == session::sessionZero &&
938 reqSessionHandle == session::defaultSessionHandle)
939 {
940 return ipmi::response(session::ccInvalidSessionId);
941 }
942
943 if (reqSessionId == session::sessionZero &&
944 reqSessionHandle == session::invalidSessionHandle)
945 {
946 return ipmi::response(session::ccInvalidSessionHandle);
947 }
948
949 if (reqSessionId != session::sessionZero &&
950 reqSessionHandle != session::defaultSessionHandle)
951 {
952 return ipmi::response(ipmi::ccInvalidFieldRequest);
953 }
954
955 try
956 {
957 ipmi::ObjectTree objectTree = ipmi::getAllDbusObjects(
958 *busp, session::sessionManagerRootPath, session::sessionIntf);
959
960 for (auto& objectTreeItr : objectTree)
961 {
962 const std::string obj = objectTreeItr.first;
963
964 if (isSessionObjectMatched(obj, reqSessionId, reqSessionHandle))
965 {
966 auto& serviceMap = objectTreeItr.second;
967
968 // Session id and session handle are unique for each session.
969 // Session id and handler are retrived from the object path and
970 // object path will be unique for each session. Checking if
971 // multiple objects exist with same object path under multiple
972 // services.
973 if (serviceMap.size() != 1)
974 {
975 return ipmi::responseUnspecifiedError();
976 }
977
978 auto itr = serviceMap.begin();
979 const std::string service = itr->first;
980 return ipmi::response(setSessionState(busp, service, obj));
981 }
982 }
983 }
Patrick Williams5d82f472022-07-22 19:26:53 -0500984 catch (const sdbusplus::exception_t& e)
Rajashekar Gade Reddye7023922019-07-10 16:54:55 +0000985 {
986 log<level::ERR>("Failed to fetch object from dbus",
987 entry("INTERFACE=%s", session::sessionIntf),
988 entry("ERRMSG=%s", e.what()));
989 return ipmi::responseUnspecifiedError();
990 }
991
992 return ipmi::responseInvalidFieldRequest();
993}
994
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +0000995uint8_t getTotalSessionCount()
996{
Meera-Kattac1789482021-05-18 09:53:26 +0000997 uint8_t count = 0, ch = 0;
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +0000998
999 while (ch < ipmi::maxIpmiChannels &&
1000 count < session::maxNetworkInstanceSupported)
1001 {
Jayaprakash Mutyala80207e62020-07-04 16:34:15 +00001002 ipmi::ChannelInfo chInfo{};
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001003 ipmi::getChannelInfo(ch, chInfo);
1004 if (static_cast<ipmi::EChannelMediumType>(chInfo.mediumType) ==
1005 ipmi::EChannelMediumType::lan8032)
1006 {
1007 count++;
1008 }
1009 ch++;
1010 }
1011 return count * session::maxSessionCountPerChannel;
1012}
1013
1014/**
1015 * @brief get session info request data.
1016 *
1017 * This function validates the request data and retrive request session id,
1018 * session handle.
1019 *
Rajashekar Gade Reddy4d226402019-11-13 17:13:05 +05301020 * @param[in] ctx - context of current session.
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001021 * @param[in] sessionIndex - request session index
1022 * @param[in] payload - input payload
1023 * @param[in] reqSessionId - unpacked session Id will be asigned
1024 * @param[in] reqSessionHandle - unpacked session handle will be asigned
1025 *
1026 * @return success completion code if request data is valid
1027 * else return the correcponding error completion code.
1028 **/
Rajashekar Gade Reddy4d226402019-11-13 17:13:05 +05301029uint8_t getSessionInfoRequestData(const ipmi::Context::ptr ctx,
1030 const uint8_t sessionIndex,
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001031 ipmi::message::Payload& payload,
1032 uint32_t& reqSessionId,
1033 uint8_t& reqSessionHandle)
1034{
Rajashekar Gade Reddy4d226402019-11-13 17:13:05 +05301035 if ((sessionIndex > session::maxSessionCountPerChannel) &&
1036 (sessionIndex < session::searchSessionByHandle))
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001037 {
1038 return ipmi::ccInvalidFieldRequest;
1039 }
1040
1041 switch (sessionIndex)
1042 {
Rajashekar Gade Reddy4d226402019-11-13 17:13:05 +05301043 case session::searchCurrentSession:
1044
1045 ipmi::ChannelInfo chInfo;
1046 ipmi::getChannelInfo(ctx->channel, chInfo);
1047
1048 if (static_cast<ipmi::EChannelMediumType>(chInfo.mediumType) !=
1049 ipmi::EChannelMediumType::lan8032)
1050 {
1051 return ipmi::ccInvalidFieldRequest;
1052 }
1053
1054 if (!payload.fullyUnpacked())
1055 {
1056 return ipmi::ccReqDataLenInvalid;
1057 }
1058 // Check if current sessionId is 0, sessionId 0 is reserved.
1059 if (ctx->sessionId == session::sessionZero)
1060 {
1061 return session::ccInvalidSessionId;
1062 }
1063 reqSessionId = ctx->sessionId;
1064 break;
1065
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001066 case session::searchSessionByHandle:
1067
1068 if ((payload.unpack(reqSessionHandle)) ||
1069 (!payload.fullyUnpacked()))
1070 {
1071 return ipmi::ccReqDataLenInvalid;
1072 }
1073
1074 if ((reqSessionHandle == session::sessionZero) ||
1075 ((reqSessionHandle & session::multiIntfaceSessionHandleMask) >
1076 session::maxSessionCountPerChannel))
1077 {
1078 return session::ccInvalidSessionHandle;
1079 }
1080 break;
1081
1082 case session::searchSessionById:
1083
1084 if ((payload.unpack(reqSessionId)) || (!payload.fullyUnpacked()))
1085 {
1086 return ipmi::ccReqDataLenInvalid;
1087 }
1088
1089 if (reqSessionId == session::sessionZero)
1090 {
1091 return session::ccInvalidSessionId;
1092 }
1093 break;
1094
1095 default:
1096 if (!payload.fullyUnpacked())
1097 {
1098 return ipmi::ccReqDataLenInvalid;
1099 }
1100 break;
1101 }
1102 return ipmi::ccSuccess;
1103}
1104
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001105uint8_t getSessionState(ipmi::Context::ptr ctx, const std::string& service,
1106 const std::string& objPath, uint8_t& sessionState)
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001107{
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001108 boost::system::error_code ec = ipmi::getDbusProperty(
1109 ctx, service, objPath, session::sessionIntf, "State", sessionState);
1110 if (ec)
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001111 {
1112 log<level::ERR>("Failed to fetch state property ",
1113 entry("SERVICE=%s", service.c_str()),
1114 entry("OBJECTPATH=%s", objPath.c_str()),
1115 entry("INTERFACE=%s", session::sessionIntf),
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001116 entry("ERRMSG=%s", ec.message().c_str()));
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001117 return ipmi::ccUnspecifiedError;
1118 }
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001119 return ipmi::ccSuccess;
1120}
1121
1122static constexpr uint8_t macAddrLen = 6;
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001123/** Alias SessionDetails - contain the optional information about an
1124 * RMCP+ session.
1125 *
1126 * @param userID - uint6_t session user ID (0-63)
1127 * @param reserved - uint2_t reserved
1128 * @param privilege - uint4_t session privilege (0-5)
1129 * @param reserved - uint4_t reserved
1130 * @param channel - uint4_t session channel number
1131 * @param protocol - uint4_t session protocol
1132 * @param remoteIP - uint32_t remote IP address
1133 * @param macAddr - std::array<uint8_t, 6> mac address
1134 * @param port - uint16_t remote port
1135 */
1136using SessionDetails =
1137 std::tuple<uint2_t, uint6_t, uint4_t, uint4_t, uint4_t, uint4_t, uint32_t,
1138 std::array<uint8_t, macAddrLen>, uint16_t>;
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001139
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001140/** @brief get session details for a given session
1141 *
1142 * @param[in] ctx - ipmi::Context pointer for accessing D-Bus
1143 * @param[in] service - D-Bus service name to fetch details from
1144 * @param[in] objPath - D-Bus object path for session
1145 * @param[out] sessionHandle - return session handle for session
1146 * @param[out] sessionState - return session state for session
1147 * @param[out] details - return a SessionDetails tuple containing other
1148 * session info
1149 * @return - ipmi::Cc success or error code
1150 */
1151ipmi::Cc getSessionDetails(ipmi::Context::ptr ctx, const std::string& service,
1152 const std::string& objPath, uint8_t& sessionHandle,
1153 uint8_t& sessionState, SessionDetails& details)
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001154{
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001155 ipmi::PropertyMap sessionProps;
1156 boost::system::error_code ec = ipmi::getAllDbusProperties(
1157 ctx, service, objPath, session::sessionIntf, sessionProps);
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001158
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001159 if (ec)
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001160 {
1161 log<level::ERR>("Failed to fetch state property ",
1162 entry("SERVICE=%s", service.c_str()),
1163 entry("OBJECTPATH=%s", objPath.c_str()),
1164 entry("INTERFACE=%s", session::sessionIntf),
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001165 entry("ERRMSG=%s", ec.message().c_str()));
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001166 return ipmi::ccUnspecifiedError;
1167 }
1168
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001169 sessionState = ipmi::mappedVariant<uint8_t>(
1170 sessionProps, "State", static_cast<uint8_t>(session::State::inactive));
1171 if (sessionState == static_cast<uint8_t>(session::State::active))
1172 {
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001173 sessionHandle = ipmi::mappedVariant<uint8_t>(sessionProps,
1174 "SessionHandle", 0);
1175 std::get<0>(details) = ipmi::mappedVariant<uint8_t>(sessionProps,
1176 "UserID", 0xff);
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001177 // std::get<1>(details) = 0; // (default constructed to 0)
1178 std::get<2>(details) =
1179 ipmi::mappedVariant<uint8_t>(sessionProps, "CurrentPrivilege", 0);
1180 // std::get<3>(details) = 0; // (default constructed to 0)
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001181 std::get<4>(details) = ipmi::mappedVariant<uint8_t>(sessionProps,
1182 "ChannelNum", 0xff);
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001183 constexpr uint4_t rmcpPlusProtocol = 1;
1184 std::get<5>(details) = rmcpPlusProtocol;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001185 std::get<6>(details) = ipmi::mappedVariant<uint32_t>(sessionProps,
1186 "RemoteIPAddr", 0);
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001187 // std::get<7>(details) = {{0}}; // default constructed to all 0
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001188 std::get<8>(details) = ipmi::mappedVariant<uint16_t>(sessionProps,
1189 "RemotePort", 0);
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001190 }
1191
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001192 return ipmi::ccSuccess;
1193}
1194
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001195ipmi::RspType<uint8_t, // session handle,
1196 uint8_t, // total session count
1197 uint8_t, // active session count
1198 std::optional<SessionDetails>>
Rajashekar Gade Reddy4d226402019-11-13 17:13:05 +05301199 ipmiAppGetSessionInfo(ipmi::Context::ptr ctx, uint8_t sessionIndex,
1200 ipmi::message::Payload& payload)
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001201{
1202 uint32_t reqSessionId = 0;
1203 uint8_t reqSessionHandle = session::defaultSessionHandle;
1204 // initializing state to 0xff as 0 represents state as inactive.
1205 uint8_t state = 0xFF;
1206
1207 uint8_t completionCode = getSessionInfoRequestData(
Rajashekar Gade Reddy4d226402019-11-13 17:13:05 +05301208 ctx, sessionIndex, payload, reqSessionId, reqSessionHandle);
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001209
1210 if (completionCode)
1211 {
1212 return ipmi::response(completionCode);
1213 }
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001214 ipmi::ObjectTree objectTree;
1215 boost::system::error_code ec = ipmi::getAllDbusObjects(
1216 ctx, session::sessionManagerRootPath, session::sessionIntf, objectTree);
1217 if (ec)
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001218 {
1219 log<level::ERR>("Failed to fetch object from dbus",
1220 entry("INTERFACE=%s", session::sessionIntf),
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001221 entry("ERRMSG=%s", ec.message().c_str()));
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001222 return ipmi::responseUnspecifiedError();
1223 }
1224
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001225 uint8_t totalSessionCount = getTotalSessionCount();
1226 uint8_t activeSessionCount = 0;
1227 uint8_t sessionHandle = session::defaultSessionHandle;
Johnathan Manteyca93bb12022-12-02 13:33:17 -08001228 uint8_t activeSessionHandle = 0;
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001229 std::optional<SessionDetails> maybeDetails;
1230 uint8_t index = 0;
1231 for (auto& objectTreeItr : objectTree)
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001232 {
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001233 uint32_t sessionId = 0;
1234 std::string objectPath = objectTreeItr.first;
1235
1236 if (!parseCloseSessionInputPayload(objectPath, sessionId,
1237 sessionHandle))
1238 {
1239 continue;
1240 }
1241 index++;
1242 auto& serviceMap = objectTreeItr.second;
1243 auto itr = serviceMap.begin();
1244
1245 if (serviceMap.size() != 1)
1246 {
1247 return ipmi::responseUnspecifiedError();
1248 }
1249
1250 std::string service = itr->first;
1251 uint8_t sessionState = 0;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001252 completionCode = getSessionState(ctx, service, objectPath,
1253 sessionState);
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001254 if (completionCode)
1255 {
1256 return ipmi::response(completionCode);
1257 }
1258
1259 if (sessionState == static_cast<uint8_t>(session::State::active))
1260 {
1261 activeSessionCount++;
1262 }
1263
Johnathan Manteyca93bb12022-12-02 13:33:17 -08001264 if (index == sessionIndex || reqSessionId == sessionId ||
1265 reqSessionHandle == sessionHandle)
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001266 {
Johnathan Manteyca93bb12022-12-02 13:33:17 -08001267 SessionDetails details{};
1268 completionCode = getSessionDetails(ctx, service, objectPath,
1269 sessionHandle, state, details);
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001270
Johnathan Manteyca93bb12022-12-02 13:33:17 -08001271 if (completionCode)
1272 {
1273 return ipmi::response(completionCode);
1274 }
1275 activeSessionHandle = sessionHandle;
1276 maybeDetails = std::move(details);
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001277 }
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001278 }
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001279
1280 if (state == static_cast<uint8_t>(session::State::active) ||
1281 state == static_cast<uint8_t>(session::State::tearDownInProgress))
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001282 {
Johnathan Manteyca93bb12022-12-02 13:33:17 -08001283 return ipmi::responseSuccess(activeSessionHandle, totalSessionCount,
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001284 activeSessionCount, maybeDetails);
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001285 }
1286
1287 return ipmi::responseInvalidFieldRequest();
1288}
1289
Xo Wangf542e8b2017-08-09 15:34:16 -07001290static std::unique_ptr<SysInfoParamStore> sysInfoParamStore;
1291
Xo Wang87651332017-08-11 10:17:59 -07001292static std::string sysInfoReadSystemName()
1293{
1294 // Use the BMC hostname as the "System Name."
1295 char hostname[HOST_NAME_MAX + 1] = {};
1296 if (gethostname(hostname, HOST_NAME_MAX) != 0)
1297 {
1298 perror("System info parameter: system name");
1299 }
1300 return hostname;
1301}
1302
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001303static constexpr uint8_t paramRevision = 0x11;
1304static constexpr size_t configParameterLength = 16;
Xo Wangf542e8b2017-08-09 15:34:16 -07001305
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001306static constexpr size_t smallChunkSize = 14;
1307static constexpr size_t fullChunkSize = 16;
Jia, chunhui449f2162019-09-11 16:51:51 +08001308static constexpr uint8_t progressMask = 0x3;
Xo Wangf542e8b2017-08-09 15:34:16 -07001309
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001310static constexpr uint8_t setComplete = 0x0;
1311static constexpr uint8_t setInProgress = 0x1;
1312static constexpr uint8_t commitWrite = 0x2;
1313static uint8_t transferStatus = setComplete;
1314
Jia, chunhui449f2162019-09-11 16:51:51 +08001315static constexpr uint8_t configDataOverhead = 2;
1316
1317// For EFI based system, 256 bytes is recommended.
1318static constexpr size_t maxBytesPerParameter = 256;
1319
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001320namespace ipmi
1321{
1322constexpr Cc ccParmNotSupported = 0x80;
Jia, chunhui449f2162019-09-11 16:51:51 +08001323constexpr Cc ccSetInProgressActive = 0x81;
1324constexpr Cc ccSystemInfoParameterSetReadOnly = 0x82;
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001325
1326static inline auto responseParmNotSupported()
1327{
1328 return response(ccParmNotSupported);
Xo Wangf542e8b2017-08-09 15:34:16 -07001329}
Jia, chunhui449f2162019-09-11 16:51:51 +08001330static inline auto responseSetInProgressActive()
1331{
1332 return response(ccSetInProgressActive);
1333}
1334static inline auto responseSystemInfoParameterSetReadOnly()
1335{
1336 return response(ccSystemInfoParameterSetReadOnly);
1337}
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001338} // namespace ipmi
Xo Wangf542e8b2017-08-09 15:34:16 -07001339
Jia, chunhui449f2162019-09-11 16:51:51 +08001340ipmi::RspType<uint8_t, // Parameter revision
1341 std::optional<uint8_t>, // data1 / setSelector / ProgressStatus
1342 std::optional<std::vector<uint8_t>>> // data2-17
jayaprakash Mutyalac2566a92020-04-23 21:18:35 +00001343 ipmiAppGetSystemInfo(uint7_t reserved, bool getRevision,
1344 uint8_t paramSelector, uint8_t setSelector,
1345 uint8_t BlockSelector)
Xo Wangf542e8b2017-08-09 15:34:16 -07001346{
Snehalatha Va5ae7722020-05-02 18:18:57 +00001347 if (reserved || (paramSelector >= invalidParamSelectorStart &&
1348 paramSelector <= invalidParamSelectorEnd))
jayaprakash Mutyalac2566a92020-04-23 21:18:35 +00001349 {
1350 return ipmi::responseInvalidFieldRequest();
1351 }
Snehalatha Va5ae7722020-05-02 18:18:57 +00001352 if ((paramSelector >= oemCmdStart) && (paramSelector <= oemCmdEnd))
1353 {
1354 return ipmi::responseParmNotSupported();
1355 }
jayaprakash Mutyalac2566a92020-04-23 21:18:35 +00001356 if (getRevision)
Xo Wangf542e8b2017-08-09 15:34:16 -07001357 {
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001358 return ipmi::responseSuccess(paramRevision, std::nullopt, std::nullopt);
Xo Wangf542e8b2017-08-09 15:34:16 -07001359 }
1360
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001361 if (paramSelector == 0)
Xo Wangf542e8b2017-08-09 15:34:16 -07001362 {
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001363 return ipmi::responseSuccess(paramRevision, transferStatus,
1364 std::nullopt);
Xo Wangf542e8b2017-08-09 15:34:16 -07001365 }
1366
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001367 if (BlockSelector != 0) // 00h if parameter does not require a block number
Xo Wangf542e8b2017-08-09 15:34:16 -07001368 {
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001369 return ipmi::responseParmNotSupported();
Xo Wangf542e8b2017-08-09 15:34:16 -07001370 }
1371
1372 if (sysInfoParamStore == nullptr)
1373 {
1374 sysInfoParamStore = std::make_unique<SysInfoParamStore>();
Xo Wang87651332017-08-11 10:17:59 -07001375 sysInfoParamStore->update(IPMI_SYSINFO_SYSTEM_NAME,
1376 sysInfoReadSystemName);
Xo Wangf542e8b2017-08-09 15:34:16 -07001377 }
1378
1379 // Parameters other than Set In Progress are assumed to be strings.
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001380 std::tuple<bool, std::string> ret =
1381 sysInfoParamStore->lookup(paramSelector);
1382 bool found = std::get<0>(ret);
Xo Wangf542e8b2017-08-09 15:34:16 -07001383 if (!found)
1384 {
Snehalatha Va5ae7722020-05-02 18:18:57 +00001385 return ipmi::responseSensorInvalid();
Xo Wangf542e8b2017-08-09 15:34:16 -07001386 }
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001387 std::string& paramString = std::get<1>(ret);
Jia, chunhui449f2162019-09-11 16:51:51 +08001388 std::vector<uint8_t> configData;
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001389 size_t count = 0;
1390 if (setSelector == 0)
Jia, chunhui449f2162019-09-11 16:51:51 +08001391 { // First chunk has only 14 bytes.
1392 configData.emplace_back(0); // encoding
1393 configData.emplace_back(paramString.length()); // string length
1394 count = std::min(paramString.length(), smallChunkSize);
1395 configData.resize(count + configDataOverhead);
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001396 std::copy_n(paramString.begin(), count,
Snehalatha Va5ae7722020-05-02 18:18:57 +00001397 configData.begin() + configDataOverhead); // 14 bytes chunk
1398
1399 // Append zero's to remaining bytes
1400 if (configData.size() < configParameterLength)
1401 {
1402 std::fill_n(std::back_inserter(configData),
1403 configParameterLength - configData.size(), 0x00);
1404 }
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001405 }
1406 else
Xo Wangf542e8b2017-08-09 15:34:16 -07001407 {
Jia, chunhui449f2162019-09-11 16:51:51 +08001408 size_t offset = (setSelector * fullChunkSize) - configDataOverhead;
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001409 if (offset >= paramString.length())
1410 {
1411 return ipmi::responseParmOutOfRange();
1412 }
Jia, chunhui449f2162019-09-11 16:51:51 +08001413 count = std::min(paramString.length() - offset, fullChunkSize);
1414 configData.resize(count);
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001415 std::copy_n(paramString.begin() + offset, count,
1416 configData.begin()); // 16 bytes chunk
Xo Wangf542e8b2017-08-09 15:34:16 -07001417 }
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001418 return ipmi::responseSuccess(paramRevision, setSelector, configData);
Xo Wangf542e8b2017-08-09 15:34:16 -07001419}
1420
Jia, chunhui449f2162019-09-11 16:51:51 +08001421ipmi::RspType<> ipmiAppSetSystemInfo(uint8_t paramSelector, uint8_t data1,
1422 std::vector<uint8_t> configData)
1423{
jayaprakash Mutyala3c5e4132020-04-27 23:00:05 +00001424 if (paramSelector >= invalidParamSelectorStart &&
1425 paramSelector <= invalidParamSelectorEnd)
1426 {
1427 return ipmi::responseInvalidFieldRequest();
1428 }
1429 if ((paramSelector >= oemCmdStart) && (paramSelector <= oemCmdEnd))
1430 {
1431 return ipmi::responseParmNotSupported();
1432 }
1433
Jia, chunhui449f2162019-09-11 16:51:51 +08001434 if (paramSelector == 0)
1435 {
1436 // attempt to set the 'set in progress' value (in parameter #0)
1437 // when not in the set complete state.
1438 if ((transferStatus != setComplete) && (data1 == setInProgress))
1439 {
1440 return ipmi::responseSetInProgressActive();
1441 }
1442 // only following 2 states are supported
1443 if (data1 > setInProgress)
1444 {
1445 phosphor::logging::log<phosphor::logging::level::ERR>(
1446 "illegal SetInProgress status");
1447 return ipmi::responseInvalidFieldRequest();
1448 }
1449
1450 transferStatus = data1 & progressMask;
1451 return ipmi::responseSuccess();
1452 }
1453
1454 if (configData.size() > configParameterLength)
1455 {
1456 return ipmi::responseInvalidFieldRequest();
1457 }
1458
jayaprakash Mutyala3c5e4132020-04-27 23:00:05 +00001459 // Append zero's to remaining bytes
1460 if (configData.size() < configParameterLength)
1461 {
1462 fill_n(back_inserter(configData),
1463 (configParameterLength - configData.size()), 0x00);
1464 }
1465
Jia, chunhui449f2162019-09-11 16:51:51 +08001466 if (!sysInfoParamStore)
1467 {
1468 sysInfoParamStore = std::make_unique<SysInfoParamStore>();
1469 sysInfoParamStore->update(IPMI_SYSINFO_SYSTEM_NAME,
1470 sysInfoReadSystemName);
1471 }
1472
1473 // lookup
1474 std::tuple<bool, std::string> ret =
1475 sysInfoParamStore->lookup(paramSelector);
1476 bool found = std::get<0>(ret);
1477 std::string& paramString = std::get<1>(ret);
1478 if (!found)
1479 {
1480 // parameter does not exist. Init new
1481 paramString = "";
1482 }
1483
1484 uint8_t setSelector = data1;
1485 size_t count = 0;
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001486 if (setSelector == 0) // First chunk has only 14 bytes.
Jia, chunhui449f2162019-09-11 16:51:51 +08001487 {
1488 size_t stringLen = configData.at(1); // string length
1489 // maxBytesPerParamter is 256. It will always be greater than stringLen
1490 // (unit8_t) if maxBytes changes in future, then following line is
1491 // needed.
1492 // stringLen = std::min(stringLen, maxBytesPerParameter);
1493 count = std::min(stringLen, smallChunkSize);
1494 count = std::min(count, configData.size());
1495 paramString.resize(stringLen); // reserve space
1496 std::copy_n(configData.begin() + configDataOverhead, count,
1497 paramString.begin());
1498 }
1499 else
1500 {
1501 size_t offset = (setSelector * fullChunkSize) - configDataOverhead;
1502 if (offset >= paramString.length())
1503 {
1504 return ipmi::responseParmOutOfRange();
1505 }
1506 count = std::min(paramString.length() - offset, configData.size());
1507 std::copy_n(configData.begin(), count, paramString.begin() + offset);
1508 }
1509 sysInfoParamStore->update(paramSelector, paramString);
1510 return ipmi::responseSuccess();
1511}
1512
Yong Libd0503a2019-08-22 17:17:17 +08001513#ifdef ENABLE_I2C_WHITELIST_CHECK
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +05301514inline std::vector<uint8_t> convertStringToData(const std::string& command)
1515{
1516 std::istringstream iss(command);
1517 std::string token;
1518 std::vector<uint8_t> dataValue;
1519 while (std::getline(iss, token, ' '))
1520 {
1521 dataValue.emplace_back(
1522 static_cast<uint8_t>(std::stoul(token, nullptr, base_16)));
1523 }
1524 return dataValue;
1525}
1526
1527static bool populateI2CMasterWRWhitelist()
1528{
1529 nlohmann::json data = nullptr;
1530 std::ifstream jsonFile(i2cMasterWRWhitelistFile);
1531
1532 if (!jsonFile.good())
1533 {
1534 log<level::WARNING>("i2c white list file not found!",
1535 entry("FILE_NAME: %s", i2cMasterWRWhitelistFile));
1536 return false;
1537 }
1538
1539 try
1540 {
1541 data = nlohmann::json::parse(jsonFile, nullptr, false);
1542 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -05001543 catch (const nlohmann::json::parse_error& e)
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +05301544 {
1545 log<level::ERR>("Corrupted i2c white list config file",
1546 entry("FILE_NAME: %s", i2cMasterWRWhitelistFile),
1547 entry("MSG: %s", e.what()));
1548 return false;
1549 }
1550
1551 try
1552 {
1553 // Example JSON Structure format
1554 // "filters": [
1555 // {
1556 // "Description": "Allow full read - ignore first byte write value
1557 // for 0x40 to 0x4F",
1558 // "busId": "0x01",
1559 // "slaveAddr": "0x40",
1560 // "slaveAddrMask": "0x0F",
1561 // "command": "0x00",
1562 // "commandMask": "0xFF"
1563 // },
1564 // {
1565 // "Description": "Allow full read - first byte match 0x05 and
1566 // ignore second byte",
1567 // "busId": "0x01",
1568 // "slaveAddr": "0x57",
1569 // "slaveAddrMask": "0x00",
1570 // "command": "0x05 0x00",
1571 // "commandMask": "0x00 0xFF"
1572 // },]
1573
1574 nlohmann::json filters = data[filtersStr].get<nlohmann::json>();
1575 std::vector<i2cMasterWRWhitelist>& whitelist = getWRWhitelist();
1576 for (const auto& it : filters.items())
1577 {
1578 nlohmann::json filter = it.value();
1579 if (filter.is_null())
1580 {
1581 log<level::ERR>(
1582 "Corrupted I2C master write read whitelist config file",
1583 entry("FILE_NAME: %s", i2cMasterWRWhitelistFile));
1584 return false;
1585 }
1586 const std::vector<uint8_t>& writeData =
1587 convertStringToData(filter[cmdStr].get<std::string>());
1588 const std::vector<uint8_t>& writeDataMask =
1589 convertStringToData(filter[cmdMaskStr].get<std::string>());
1590 if (writeDataMask.size() != writeData.size())
1591 {
1592 log<level::ERR>("I2C master write read whitelist filter "
1593 "mismatch for command & mask size");
1594 return false;
1595 }
1596 whitelist.push_back(
1597 {static_cast<uint8_t>(std::stoul(
1598 filter[busIdStr].get<std::string>(), nullptr, base_16)),
1599 static_cast<uint8_t>(
1600 std::stoul(filter[slaveAddrStr].get<std::string>(),
1601 nullptr, base_16)),
1602 static_cast<uint8_t>(
1603 std::stoul(filter[slaveAddrMaskStr].get<std::string>(),
1604 nullptr, base_16)),
1605 writeData, writeDataMask});
1606 }
1607 if (whitelist.size() != filters.size())
1608 {
1609 log<level::ERR>(
1610 "I2C master write read whitelist filter size mismatch");
1611 return false;
1612 }
1613 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -05001614 catch (const std::exception& e)
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +05301615 {
1616 log<level::ERR>("I2C master write read whitelist unexpected exception",
1617 entry("ERROR=%s", e.what()));
1618 return false;
1619 }
1620 return true;
1621}
1622
1623static inline bool isWriteDataWhitelisted(const std::vector<uint8_t>& data,
1624 const std::vector<uint8_t>& dataMask,
1625 const std::vector<uint8_t>& writeData)
1626{
1627 std::vector<uint8_t> processedDataBuf(data.size());
1628 std::vector<uint8_t> processedReqBuf(dataMask.size());
1629 std::transform(writeData.begin(), writeData.end(), dataMask.begin(),
1630 processedReqBuf.begin(), std::bit_or<uint8_t>());
1631 std::transform(data.begin(), data.end(), dataMask.begin(),
1632 processedDataBuf.begin(), std::bit_or<uint8_t>());
1633
1634 return (processedDataBuf == processedReqBuf);
1635}
1636
1637static bool isCmdWhitelisted(uint8_t busId, uint8_t slaveAddr,
1638 std::vector<uint8_t>& writeData)
1639{
1640 std::vector<i2cMasterWRWhitelist>& whiteList = getWRWhitelist();
1641 for (const auto& wlEntry : whiteList)
1642 {
1643 if ((busId == wlEntry.busId) &&
1644 ((slaveAddr | wlEntry.slaveAddrMask) ==
1645 (wlEntry.slaveAddr | wlEntry.slaveAddrMask)))
1646 {
1647 const std::vector<uint8_t>& dataMask = wlEntry.dataMask;
1648 // Skip as no-match, if requested write data is more than the
1649 // write data mask size
1650 if (writeData.size() > dataMask.size())
1651 {
1652 continue;
1653 }
1654 if (isWriteDataWhitelisted(wlEntry.data, dataMask, writeData))
1655 {
1656 return true;
1657 }
1658 }
1659 }
1660 return false;
1661}
Yong Libd0503a2019-08-22 17:17:17 +08001662#else
1663static bool populateI2CMasterWRWhitelist()
1664{
1665 log<level::INFO>(
1666 "I2C_WHITELIST_CHECK is disabled, do not populate whitelist");
1667 return true;
1668}
1669#endif // ENABLE_I2C_WHITELIST_CHECK
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +05301670
1671/** @brief implements master write read IPMI command which can be used for
1672 * low-level I2C/SMBus write, read or write-read access
1673 * @param isPrivateBus -to indicate private bus usage
1674 * @param busId - bus id
1675 * @param channelNum - channel number
1676 * @param reserved - skip 1 bit
1677 * @param slaveAddr - slave address
1678 * @param read count - number of bytes to be read
1679 * @param writeData - data to be written
1680 *
1681 * @returns IPMI completion code plus response data
1682 * - readData - i2c response data
1683 */
1684ipmi::RspType<std::vector<uint8_t>>
Willy Tu11d68892022-01-20 10:37:34 -08001685 ipmiMasterWriteRead([[maybe_unused]] bool isPrivateBus, uint3_t busId,
1686 [[maybe_unused]] uint4_t channelNum, bool reserved,
1687 uint7_t slaveAddr, uint8_t readCount,
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +05301688 std::vector<uint8_t> writeData)
1689{
Jayaprakash Mutyalac2af98b2021-09-14 09:19:11 +00001690 if (reserved)
1691 {
1692 return ipmi::responseInvalidFieldRequest();
1693 }
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +05301694 if (readCount > maxIPMIWriteReadSize)
1695 {
1696 log<level::ERR>("Master write read command: Read count exceeds limit");
1697 return ipmi::responseParmOutOfRange();
1698 }
1699 const size_t writeCount = writeData.size();
1700 if (!readCount && !writeCount)
1701 {
1702 log<level::ERR>("Master write read command: Read & write count are 0");
1703 return ipmi::responseInvalidFieldRequest();
1704 }
Yong Libd0503a2019-08-22 17:17:17 +08001705#ifdef ENABLE_I2C_WHITELIST_CHECK
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +05301706 if (!isCmdWhitelisted(static_cast<uint8_t>(busId),
1707 static_cast<uint8_t>(slaveAddr), writeData))
1708 {
1709 log<level::ERR>("Master write read request blocked!",
1710 entry("BUS=%d", static_cast<uint8_t>(busId)),
1711 entry("ADDR=0x%x", static_cast<uint8_t>(slaveAddr)));
1712 return ipmi::responseInvalidFieldRequest();
1713 }
Yong Libd0503a2019-08-22 17:17:17 +08001714#endif // ENABLE_I2C_WHITELIST_CHECK
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +05301715 std::vector<uint8_t> readBuf(readCount);
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -05001716 std::string i2cBus = "/dev/i2c-" +
1717 std::to_string(static_cast<uint8_t>(busId));
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +05301718
Yong Li7dc4ac02019-08-23 17:44:32 +08001719 ipmi::Cc ret = ipmi::i2cWriteRead(i2cBus, static_cast<uint8_t>(slaveAddr),
1720 writeData, readBuf);
1721 if (ret != ipmi::ccSuccess)
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +05301722 {
Yong Li7dc4ac02019-08-23 17:44:32 +08001723 return ipmi::response(ret);
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +05301724 }
1725 return ipmi::responseSuccess(readBuf);
1726}
1727
Chris Austen6caf28b2015-10-13 12:40:40 -05001728void register_netfn_app_functions()
vishwabmcba0bd5f2015-09-30 16:50:23 +05301729{
Vernon Mauery86a50822019-03-25 13:11:36 -07001730 // <Get Device ID>
1731 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
1732 ipmi::app::cmdGetDeviceId, ipmi::Privilege::User,
1733 ipmiAppGetDeviceId);
1734
Tom05732372016-09-06 17:21:23 +05301735 // <Get BT Interface Capabilities>
Vernon Mauerycc99ba42019-03-25 13:40:11 -07001736 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
1737 ipmi::app::cmdGetBtIfaceCapabilities,
1738 ipmi::Privilege::User, ipmiAppGetBtCapabilities);
Chris Austen6caf28b2015-10-13 12:40:40 -05001739
Tom05732372016-09-06 17:21:23 +05301740 // <Reset Watchdog Timer>
Vernon Mauery11df4f62019-03-25 14:17:54 -07001741 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
1742 ipmi::app::cmdResetWatchdogTimer,
1743 ipmi::Privilege::Operator, ipmiAppResetWatchdogTimer);
Chris Austen6caf28b2015-10-13 12:40:40 -05001744
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001745 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
AppaRao Puli5a98ea62019-11-10 21:15:02 +05301746 ipmi::app::cmdGetSessionInfo, ipmi::Privilege::User,
1747 ipmiAppGetSessionInfo);
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001748
Tom05732372016-09-06 17:21:23 +05301749 // <Set Watchdog Timer>
Deepak Kumar Sahucfae9482019-05-20 14:58:58 +00001750 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
1751 ipmi::app::cmdSetWatchdogTimer,
1752 ipmi::Privilege::Operator, ipmiSetWatchdogTimer);
Chris Austen6caf28b2015-10-13 12:40:40 -05001753
Rajashekar Gade Reddye7023922019-07-10 16:54:55 +00001754 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
1755 ipmi::app::cmdCloseSession, ipmi::Privilege::Callback,
1756 ipmiAppCloseSession);
1757
William A. Kennington III73f44512018-02-09 15:28:46 -08001758 // <Get Watchdog Timer>
Deepak Kumar Sahucfae9482019-05-20 14:58:58 +00001759 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
AppaRao Puli5a98ea62019-11-10 21:15:02 +05301760 ipmi::app::cmdGetWatchdogTimer, ipmi::Privilege::User,
1761 ipmiGetWatchdogTimer);
William A. Kennington III73f44512018-02-09 15:28:46 -08001762
Tom05732372016-09-06 17:21:23 +05301763 // <Get Self Test Results>
Vernon Maueryb84a5282019-03-25 13:39:03 -07001764 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
1765 ipmi::app::cmdGetSelfTestResults,
1766 ipmi::Privilege::User, ipmiAppGetSelfTestResults);
Nan Li41fa24a2016-11-10 20:12:37 +08001767
Tom05732372016-09-06 17:21:23 +05301768 // <Get Device GUID>
Vernon Mauery15541322019-03-25 13:33:03 -07001769 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
1770 ipmi::app::cmdGetDeviceGuid, ipmi::Privilege::User,
1771 ipmiAppGetDeviceGuid);
Adriana Kobylakd100ee52015-10-20 17:02:37 -05001772
Tom05732372016-09-06 17:21:23 +05301773 // <Set ACPI Power State>
Deepak Kumar Sahu520c1312019-05-17 18:14:09 +00001774 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
1775 ipmi::app::cmdSetAcpiPowerState,
1776 ipmi::Privilege::Admin, ipmiSetAcpiPowerState);
Yong Li18d77262018-10-09 01:59:45 +08001777 // <Get ACPI Power State>
Deepak Kumar Sahu4e6d2572019-05-07 19:53:37 +00001778 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
1779 ipmi::app::cmdGetAcpiPowerState,
AppaRao Puli5a98ea62019-11-10 21:15:02 +05301780 ipmi::Privilege::User, ipmiGetAcpiPowerState);
Yong Li18d77262018-10-09 01:59:45 +08001781
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +05301782 // Note: For security reason, this command will be registered only when
1783 // there are proper I2C Master write read whitelist
1784 if (populateI2CMasterWRWhitelist())
1785 {
1786 // Note: For security reasons, registering master write read as admin
1787 // privilege command, even though IPMI 2.0 specification allows it as
1788 // operator privilege.
1789 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
1790 ipmi::app::cmdMasterWriteRead,
1791 ipmi::Privilege::Admin, ipmiMasterWriteRead);
1792 }
1793
Marri Devender Rao5e007a52018-01-08 06:18:36 -06001794 // <Get System GUID Command>
Vernon Maueryb90a5322019-03-25 13:36:55 -07001795 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
1796 ipmi::app::cmdGetSystemGuid, ipmi::Privilege::User,
1797 ipmiAppGetSystemGuid);
Tom Joseph7cbe2282018-03-21 21:17:33 +05301798
1799 // <Get Channel Cipher Suites Command>
Ayushi Smriti5c3b72c2019-08-30 13:47:31 +00001800 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
1801 ipmi::app::cmdGetChannelCipherSuites,
Vernon Mauery79b4eea2019-11-07 09:51:39 -08001802 ipmi::Privilege::None, getChannelCipherSuites);
Vernon Maueryd2a57de2019-03-25 12:45:28 -07001803
Xo Wangf542e8b2017-08-09 15:34:16 -07001804 // <Get System Info Command>
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001805 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
1806 ipmi::app::cmdGetSystemInfoParameters,
1807 ipmi::Privilege::User, ipmiAppGetSystemInfo);
Jia, chunhui449f2162019-09-11 16:51:51 +08001808 // <Set System Info Command>
1809 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
1810 ipmi::app::cmdSetSystemInfoParameters,
1811 ipmi::Privilege::Admin, ipmiAppSetSystemInfo);
vishwabmcba0bd5f2015-09-30 16:50:23 +05301812 return;
1813}