blob: 98f7caa8fcc323797f789e6805f4b1df9b0d7c2a [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
Patrick Venture3a5071a2018-09-12 13:27:42 -070015#include <algorithm>
Vernon Mauery0120b682019-03-25 13:08:54 -070016#include <app/channel.hpp>
17#include <app/watchdog.hpp>
18#include <apphandler.hpp>
Patrick Venture3a5071a2018-09-12 13:27:42 -070019#include <array>
Willy Tu886d6842022-06-03 02:50:47 -070020#include <charconv>
Patrick Venture3a5071a2018-09-12 13:27:42 -070021#include <cstddef>
Vernon Mauery0120b682019-03-25 13:08:54 -070022#include <cstdint>
Vernon Mauerybdda8002019-02-26 10:18:51 -080023#include <filesystem>
Patrick Venture3a5071a2018-09-12 13:27:42 -070024#include <fstream>
Vernon Mauery0120b682019-03-25 13:08:54 -070025#include <ipmid/api.hpp>
Rajashekar Gade Reddye7023922019-07-10 16:54:55 +000026#include <ipmid/sessiondef.hpp>
27#include <ipmid/sessionhelper.hpp>
Vernon Mauery33250242019-03-12 16:49:26 -070028#include <ipmid/types.hpp>
Vernon Mauery6a98fe72019-03-11 15:57:48 -070029#include <ipmid/utils.hpp>
Patrick Venture3a5071a2018-09-12 13:27:42 -070030#include <memory>
Patrick Venture46470a32018-09-07 19:26:25 -070031#include <nlohmann/json.hpp>
Patrick Venture3a5071a2018-09-12 13:27:42 -070032#include <phosphor-logging/elog-errors.hpp>
33#include <phosphor-logging/log.hpp>
Potin Lai5d214202023-01-16 18:11:49 +080034#include <regex>
William A. Kennington III4c008022018-10-12 17:18:14 -070035#include <sdbusplus/message/types.hpp>
Patrick Venture3a5071a2018-09-12 13:27:42 -070036#include <string>
Willy Tu886d6842022-06-03 02:50:47 -070037#include <string_view>
Vernon Mauery0120b682019-03-25 13:08:54 -070038#include <sys_info_param.hpp>
Patrick Venture3a5071a2018-09-12 13:27:42 -070039#include <tuple>
40#include <vector>
41#include <xyz/openbmc_project/Common/error.hpp>
Yong Li18d77262018-10-09 01:59:45 +080042#include <xyz/openbmc_project/Control/Power/ACPIPowerState/server.hpp>
Patrick Venture3a5071a2018-09-12 13:27:42 -070043#include <xyz/openbmc_project/Software/Activation/server.hpp>
44#include <xyz/openbmc_project/Software/Version/server.hpp>
45#include <xyz/openbmc_project/State/BMC/server.hpp>
Ratan Guptab8e99552017-07-27 07:07:48 +053046
Patrick Venture0b02be92018-08-31 11:55:55 -070047extern sd_bus* bus;
vishwabmcba0bd5f2015-09-30 16:50:23 +053048
Alexander Amelkinba19c182018-09-04 15:49:36 +030049constexpr auto bmc_state_interface = "xyz.openbmc_project.State.BMC";
50constexpr auto bmc_state_property = "CurrentBMCState";
Marri Devender Rao5e007a52018-01-08 06:18:36 -060051
Nagaraju Goruganti744398d2018-02-20 09:52:00 -060052static constexpr auto redundancyIntf =
53 "xyz.openbmc_project.Software.RedundancyPriority";
Patrick Venture0b02be92018-08-31 11:55:55 -070054static constexpr auto versionIntf = "xyz.openbmc_project.Software.Version";
Nagaraju Goruganti744398d2018-02-20 09:52:00 -060055static constexpr auto activationIntf =
56 "xyz.openbmc_project.Software.Activation";
57static constexpr auto softwareRoot = "/xyz/openbmc_project/software";
58
Chris Austen6caf28b2015-10-13 12:40:40 -050059void register_netfn_app_functions() __attribute__((constructor));
vishwabmcba0bd5f2015-09-30 16:50:23 +053060
Ratan Guptab8e99552017-07-27 07:07:48 +053061using namespace phosphor::logging;
62using namespace sdbusplus::xyz::openbmc_project::Common::Error;
Nagaraju Goruganti744398d2018-02-20 09:52:00 -060063using Version = sdbusplus::xyz::openbmc_project::Software::server::Version;
64using Activation =
65 sdbusplus::xyz::openbmc_project::Software::server::Activation;
Alexander Amelkinba19c182018-09-04 15:49:36 +030066using BMC = sdbusplus::xyz::openbmc_project::State::server::BMC;
Vernon Mauery185b9f82018-07-20 10:52:36 -070067namespace fs = std::filesystem;
Ratan Guptab8e99552017-07-27 07:07:48 +053068
Yong Libd0503a2019-08-22 17:17:17 +080069#ifdef ENABLE_I2C_WHITELIST_CHECK
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +053070typedef struct
71{
72 uint8_t busId;
73 uint8_t slaveAddr;
74 uint8_t slaveAddrMask;
75 std::vector<uint8_t> data;
76 std::vector<uint8_t> dataMask;
77} i2cMasterWRWhitelist;
78
79static std::vector<i2cMasterWRWhitelist>& getWRWhitelist()
80{
81 static std::vector<i2cMasterWRWhitelist> wrWhitelist;
82 return wrWhitelist;
83}
84
85static constexpr const char* i2cMasterWRWhitelistFile =
86 "/usr/share/ipmi-providers/master_write_read_white_list.json";
87
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +053088static constexpr const char* filtersStr = "filters";
89static constexpr const char* busIdStr = "busId";
90static constexpr const char* slaveAddrStr = "slaveAddr";
91static constexpr const char* slaveAddrMaskStr = "slaveAddrMask";
92static constexpr const char* cmdStr = "command";
93static constexpr const char* cmdMaskStr = "commandMask";
94static constexpr int base_16 = 16;
Yong Libd0503a2019-08-22 17:17:17 +080095#endif // ENABLE_I2C_WHITELIST_CHECK
Joshi-Mansi7fd91fa2021-06-11 07:18:15 +053096static constexpr uint8_t maxIPMIWriteReadSize = 255;
jayaprakash Mutyala3c5e4132020-04-27 23:00:05 +000097static constexpr uint8_t oemCmdStart = 192;
98static constexpr uint8_t oemCmdEnd = 255;
99static constexpr uint8_t invalidParamSelectorStart = 8;
100static constexpr uint8_t invalidParamSelectorEnd = 191;
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +0530101
Nagaraju Goruganti744398d2018-02-20 09:52:00 -0600102/**
103 * @brief Returns the Version info from primary s/w object
104 *
105 * Get the Version info from the active s/w object which is having high
106 * "Priority" value(a smaller number is a higher priority) and "Purpose"
107 * is "BMC" from the list of all s/w objects those are implementing
108 * RedundancyPriority interface from the given softwareRoot path.
109 *
110 * @return On success returns the Version info from primary s/w object.
111 *
112 */
Vernon Maueryea1c4012019-05-24 13:26:16 -0700113std::string getActiveSoftwareVersionInfo(ipmi::Context::ptr ctx)
Nagaraju Goruganti744398d2018-02-20 09:52:00 -0600114{
Nagaraju Goruganti744398d2018-02-20 09:52:00 -0600115 std::string revision{};
Vernon Mauery86a50822019-03-25 13:11:36 -0700116 ipmi::ObjectTree objectTree;
117 try
Nagaraju Goruganti744398d2018-02-20 09:52:00 -0600118 {
Vernon Mauery86a50822019-03-25 13:11:36 -0700119 objectTree =
Vernon Maueryea1c4012019-05-24 13:26:16 -0700120 ipmi::getAllDbusObjects(*ctx->bus, softwareRoot, redundancyIntf);
Vernon Mauery86a50822019-03-25 13:11:36 -0700121 }
Patrick Williams5d82f472022-07-22 19:26:53 -0500122 catch (const sdbusplus::exception_t& e)
Vernon Mauery86a50822019-03-25 13:11:36 -0700123 {
124 log<level::ERR>("Failed to fetch redundancy object from dbus",
125 entry("INTERFACE=%s", redundancyIntf),
126 entry("ERRMSG=%s", e.what()));
Nagaraju Goruganti744398d2018-02-20 09:52:00 -0600127 elog<InternalFailure>();
128 }
129
130 auto objectFound = false;
131 for (auto& softObject : objectTree)
132 {
Vernon Mauery86a50822019-03-25 13:11:36 -0700133 auto service =
Vernon Maueryea1c4012019-05-24 13:26:16 -0700134 ipmi::getService(*ctx->bus, redundancyIntf, softObject.first);
Vernon Mauery86a50822019-03-25 13:11:36 -0700135 auto objValueTree =
Vernon Maueryea1c4012019-05-24 13:26:16 -0700136 ipmi::getManagedObjects(*ctx->bus, service, softwareRoot);
Nagaraju Goruganti744398d2018-02-20 09:52:00 -0600137
138 auto minPriority = 0xFF;
139 for (const auto& objIter : objValueTree)
140 {
141 try
142 {
143 auto& intfMap = objIter.second;
144 auto& redundancyPriorityProps = intfMap.at(redundancyIntf);
145 auto& versionProps = intfMap.at(versionIntf);
146 auto& activationProps = intfMap.at(activationIntf);
Vernon Maueryf442e112019-04-09 11:44:36 -0700147 auto priority =
148 std::get<uint8_t>(redundancyPriorityProps.at("Priority"));
William A. Kennington III4c008022018-10-12 17:18:14 -0700149 auto purpose =
Vernon Maueryf442e112019-04-09 11:44:36 -0700150 std::get<std::string>(versionProps.at("Purpose"));
151 auto activation =
152 std::get<std::string>(activationProps.at("Activation"));
William A. Kennington III4c008022018-10-12 17:18:14 -0700153 auto version =
Vernon Maueryf442e112019-04-09 11:44:36 -0700154 std::get<std::string>(versionProps.at("Version"));
Nagaraju Goruganti744398d2018-02-20 09:52:00 -0600155 if ((Version::convertVersionPurposeFromString(purpose) ==
156 Version::VersionPurpose::BMC) &&
157 (Activation::convertActivationsFromString(activation) ==
158 Activation::Activations::Active))
159 {
160 if (priority < minPriority)
161 {
162 minPriority = priority;
163 objectFound = true;
164 revision = std::move(version);
165 }
166 }
167 }
168 catch (const std::exception& e)
169 {
170 log<level::ERR>(e.what());
171 }
172 }
173 }
174
175 if (!objectFound)
176 {
177 log<level::ERR>("Could not found an BMC software Object");
178 elog<InternalFailure>();
179 }
180
181 return revision;
182}
183
Alexander Amelkinba19c182018-09-04 15:49:36 +0300184bool getCurrentBmcState()
185{
Patrick Williams5d82f472022-07-22 19:26:53 -0500186 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Alexander Amelkinba19c182018-09-04 15:49:36 +0300187
188 // Get the Inventory object implementing the BMC interface
189 ipmi::DbusObjectInfo bmcObject =
190 ipmi::getDbusObject(bus, bmc_state_interface);
191 auto variant =
192 ipmi::getDbusProperty(bus, bmcObject.second, bmcObject.first,
193 bmc_state_interface, bmc_state_property);
194
Vernon Maueryf442e112019-04-09 11:44:36 -0700195 return std::holds_alternative<std::string>(variant) &&
196 BMC::convertBMCStateFromString(std::get<std::string>(variant)) ==
197 BMC::BMCState::Ready;
Alexander Amelkinba19c182018-09-04 15:49:36 +0300198}
199
Patrick Venture94930a12019-04-30 10:01:58 -0700200bool getCurrentBmcStateWithFallback(const bool fallbackAvailability)
201{
202 try
203 {
204 return getCurrentBmcState();
205 }
206 catch (...)
207 {
208 // Nothing provided the BMC interface, therefore return whatever was
209 // configured as the default.
210 return fallbackAvailability;
211 }
212}
213
Yong Li18d77262018-10-09 01:59:45 +0800214namespace acpi_state
215{
216using namespace sdbusplus::xyz::openbmc_project::Control::Power::server;
217
218const static constexpr char* acpiObjPath =
219 "/xyz/openbmc_project/control/host0/acpi_power_state";
220const static constexpr char* acpiInterface =
221 "xyz.openbmc_project.Control.Power.ACPIPowerState";
222const static constexpr char* sysACPIProp = "SysACPIStatus";
223const static constexpr char* devACPIProp = "DevACPIStatus";
224
225enum class PowerStateType : uint8_t
226{
227 sysPowerState = 0x00,
228 devPowerState = 0x01,
229};
230
231// Defined in 20.6 of ipmi doc
232enum class PowerState : uint8_t
233{
234 s0G0D0 = 0x00,
235 s1D1 = 0x01,
236 s2D2 = 0x02,
237 s3D3 = 0x03,
238 s4 = 0x04,
239 s5G2 = 0x05,
240 s4S5 = 0x06,
241 g3 = 0x07,
242 sleep = 0x08,
243 g1Sleep = 0x09,
244 override = 0x0a,
245 legacyOn = 0x20,
246 legacyOff = 0x21,
247 unknown = 0x2a,
248 noChange = 0x7f,
249};
250
251static constexpr uint8_t stateChanged = 0x80;
252
Yong Li18d77262018-10-09 01:59:45 +0800253std::map<ACPIPowerState::ACPI, PowerState> dbusToIPMI = {
254 {ACPIPowerState::ACPI::S0_G0_D0, PowerState::s0G0D0},
255 {ACPIPowerState::ACPI::S1_D1, PowerState::s1D1},
256 {ACPIPowerState::ACPI::S2_D2, PowerState::s2D2},
257 {ACPIPowerState::ACPI::S3_D3, PowerState::s3D3},
258 {ACPIPowerState::ACPI::S4, PowerState::s4},
259 {ACPIPowerState::ACPI::S5_G2, PowerState::s5G2},
260 {ACPIPowerState::ACPI::S4_S5, PowerState::s4S5},
261 {ACPIPowerState::ACPI::G3, PowerState::g3},
262 {ACPIPowerState::ACPI::SLEEP, PowerState::sleep},
263 {ACPIPowerState::ACPI::G1_SLEEP, PowerState::g1Sleep},
264 {ACPIPowerState::ACPI::OVERRIDE, PowerState::override},
265 {ACPIPowerState::ACPI::LEGACY_ON, PowerState::legacyOn},
266 {ACPIPowerState::ACPI::LEGACY_OFF, PowerState::legacyOff},
267 {ACPIPowerState::ACPI::Unknown, PowerState::unknown}};
268
269bool isValidACPIState(acpi_state::PowerStateType type, uint8_t state)
270{
271 if (type == acpi_state::PowerStateType::sysPowerState)
272 {
273 if ((state <= static_cast<uint8_t>(acpi_state::PowerState::override)) ||
274 (state == static_cast<uint8_t>(acpi_state::PowerState::legacyOn)) ||
275 (state ==
276 static_cast<uint8_t>(acpi_state::PowerState::legacyOff)) ||
277 (state == static_cast<uint8_t>(acpi_state::PowerState::unknown)) ||
278 (state == static_cast<uint8_t>(acpi_state::PowerState::noChange)))
279 {
280 return true;
281 }
282 else
283 {
284 return false;
285 }
286 }
287 else if (type == acpi_state::PowerStateType::devPowerState)
288 {
289 if ((state <= static_cast<uint8_t>(acpi_state::PowerState::s3D3)) ||
290 (state == static_cast<uint8_t>(acpi_state::PowerState::unknown)) ||
291 (state == static_cast<uint8_t>(acpi_state::PowerState::noChange)))
292 {
293 return true;
294 }
295 else
296 {
297 return false;
298 }
299 }
300 else
301 {
302 return false;
303 }
304 return false;
305}
306} // namespace acpi_state
307
Deepak Kumar Sahu520c1312019-05-17 18:14:09 +0000308/** @brief implements Set ACPI Power State command
309 * @param sysAcpiState - ACPI system power state to set
310 * @param devAcpiState - ACPI device power state to set
311 *
312 * @return IPMI completion code on success
313 **/
314ipmi::RspType<> ipmiSetAcpiPowerState(uint8_t sysAcpiState,
315 uint8_t devAcpiState)
Chris Austen6caf28b2015-10-13 12:40:40 -0500316{
Yong Li18d77262018-10-09 01:59:45 +0800317 auto s = static_cast<uint8_t>(acpi_state::PowerState::unknown);
Yong Li18d77262018-10-09 01:59:45 +0800318
Patrick Williams5d82f472022-07-22 19:26:53 -0500319 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Yong Li18d77262018-10-09 01:59:45 +0800320
321 auto value = acpi_state::ACPIPowerState::ACPI::Unknown;
322
Deepak Kumar Sahu520c1312019-05-17 18:14:09 +0000323 if (sysAcpiState & acpi_state::stateChanged)
Yong Li18d77262018-10-09 01:59:45 +0800324 {
325 // set system power state
Deepak Kumar Sahu520c1312019-05-17 18:14:09 +0000326 s = sysAcpiState & ~acpi_state::stateChanged;
Yong Li18d77262018-10-09 01:59:45 +0800327
328 if (!acpi_state::isValidACPIState(
329 acpi_state::PowerStateType::sysPowerState, s))
330 {
331 log<level::ERR>("set_acpi_power sys invalid input",
332 entry("S=%x", s));
Deepak Kumar Sahu520c1312019-05-17 18:14:09 +0000333 return ipmi::responseParmOutOfRange();
Yong Li18d77262018-10-09 01:59:45 +0800334 }
335
336 // valid input
337 if (s == static_cast<uint8_t>(acpi_state::PowerState::noChange))
338 {
339 log<level::DEBUG>("No change for system power state");
340 }
341 else
342 {
343 auto found = std::find_if(
344 acpi_state::dbusToIPMI.begin(), acpi_state::dbusToIPMI.end(),
345 [&s](const auto& iter) {
346 return (static_cast<uint8_t>(iter.second) == s);
347 });
348
349 value = found->first;
350
351 try
352 {
353 auto acpiObject =
354 ipmi::getDbusObject(bus, acpi_state::acpiInterface);
355 ipmi::setDbusProperty(bus, acpiObject.second, acpiObject.first,
356 acpi_state::acpiInterface,
357 acpi_state::sysACPIProp,
358 convertForMessage(value));
359 }
360 catch (const InternalFailure& e)
361 {
362 log<level::ERR>("Failed in set ACPI system property",
363 entry("EXCEPTION=%s", e.what()));
Deepak Kumar Sahu520c1312019-05-17 18:14:09 +0000364 return ipmi::responseUnspecifiedError();
Yong Li18d77262018-10-09 01:59:45 +0800365 }
366 }
367 }
368 else
369 {
370 log<level::DEBUG>("Do not change system power state");
371 }
372
Deepak Kumar Sahu520c1312019-05-17 18:14:09 +0000373 if (devAcpiState & acpi_state::stateChanged)
Yong Li18d77262018-10-09 01:59:45 +0800374 {
375 // set device power state
Deepak Kumar Sahu520c1312019-05-17 18:14:09 +0000376 s = devAcpiState & ~acpi_state::stateChanged;
Yong Li18d77262018-10-09 01:59:45 +0800377 if (!acpi_state::isValidACPIState(
378 acpi_state::PowerStateType::devPowerState, s))
379 {
380 log<level::ERR>("set_acpi_power dev invalid input",
381 entry("S=%x", s));
Deepak Kumar Sahu520c1312019-05-17 18:14:09 +0000382 return ipmi::responseParmOutOfRange();
Yong Li18d77262018-10-09 01:59:45 +0800383 }
384
385 // valid input
386 if (s == static_cast<uint8_t>(acpi_state::PowerState::noChange))
387 {
388 log<level::DEBUG>("No change for device power state");
389 }
390 else
391 {
392 auto found = std::find_if(
393 acpi_state::dbusToIPMI.begin(), acpi_state::dbusToIPMI.end(),
394 [&s](const auto& iter) {
395 return (static_cast<uint8_t>(iter.second) == s);
396 });
397
398 value = found->first;
399
400 try
401 {
402 auto acpiObject =
403 ipmi::getDbusObject(bus, acpi_state::acpiInterface);
404 ipmi::setDbusProperty(bus, acpiObject.second, acpiObject.first,
405 acpi_state::acpiInterface,
406 acpi_state::devACPIProp,
407 convertForMessage(value));
408 }
409 catch (const InternalFailure& e)
410 {
411 log<level::ERR>("Failed in set ACPI device property",
412 entry("EXCEPTION=%s", e.what()));
Deepak Kumar Sahu520c1312019-05-17 18:14:09 +0000413 return ipmi::responseUnspecifiedError();
Yong Li18d77262018-10-09 01:59:45 +0800414 }
415 }
416 }
417 else
418 {
419 log<level::DEBUG>("Do not change device power state");
420 }
Deepak Kumar Sahu520c1312019-05-17 18:14:09 +0000421 return ipmi::responseSuccess();
Yong Li18d77262018-10-09 01:59:45 +0800422}
423
Deepak Kumar Sahu4e6d2572019-05-07 19:53:37 +0000424/**
425 * @brief implements the get ACPI power state command
426 *
427 * @return IPMI completion code plus response data on success.
428 * - ACPI system power state
429 * - ACPI device power state
430 **/
431ipmi::RspType<uint8_t, // acpiSystemPowerState
432 uint8_t // acpiDevicePowerState
433 >
434 ipmiGetAcpiPowerState()
Yong Li18d77262018-10-09 01:59:45 +0800435{
Deepak Kumar Sahu4e6d2572019-05-07 19:53:37 +0000436 uint8_t sysAcpiState;
437 uint8_t devAcpiState;
Yong Li18d77262018-10-09 01:59:45 +0800438
Patrick Williams5d82f472022-07-22 19:26:53 -0500439 sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
Yong Li18d77262018-10-09 01:59:45 +0800440
Yong Li18d77262018-10-09 01:59:45 +0800441 try
442 {
443 auto acpiObject = ipmi::getDbusObject(bus, acpi_state::acpiInterface);
444
445 auto sysACPIVal = ipmi::getDbusProperty(
446 bus, acpiObject.second, acpiObject.first, acpi_state::acpiInterface,
447 acpi_state::sysACPIProp);
448 auto sysACPI = acpi_state::ACPIPowerState::convertACPIFromString(
Vernon Maueryf442e112019-04-09 11:44:36 -0700449 std::get<std::string>(sysACPIVal));
Deepak Kumar Sahu4e6d2572019-05-07 19:53:37 +0000450 sysAcpiState = static_cast<uint8_t>(acpi_state::dbusToIPMI.at(sysACPI));
Yong Li18d77262018-10-09 01:59:45 +0800451
452 auto devACPIVal = ipmi::getDbusProperty(
453 bus, acpiObject.second, acpiObject.first, acpi_state::acpiInterface,
454 acpi_state::devACPIProp);
455 auto devACPI = acpi_state::ACPIPowerState::convertACPIFromString(
Vernon Maueryf442e112019-04-09 11:44:36 -0700456 std::get<std::string>(devACPIVal));
Deepak Kumar Sahu4e6d2572019-05-07 19:53:37 +0000457 devAcpiState = static_cast<uint8_t>(acpi_state::dbusToIPMI.at(devACPI));
Yong Li18d77262018-10-09 01:59:45 +0800458 }
459 catch (const InternalFailure& e)
460 {
Deepak Kumar Sahu4e6d2572019-05-07 19:53:37 +0000461 return ipmi::responseUnspecifiedError();
Yong Li18d77262018-10-09 01:59:45 +0800462 }
Deepak Kumar Sahu4e6d2572019-05-07 19:53:37 +0000463
464 return ipmi::responseSuccess(sysAcpiState, devAcpiState);
Chris Austen6caf28b2015-10-13 12:40:40 -0500465}
466
Chris Austen7303bdc2016-04-17 11:50:54 -0500467typedef struct
468{
469 char major;
470 char minor;
Potin Laic7c55922023-02-16 10:33:55 +0800471 uint8_t aux[4];
Vernon Mauery86a50822019-03-25 13:11:36 -0700472} Revision;
Chris Austen7303bdc2016-04-17 11:50:54 -0500473
Potin Lai5d214202023-01-16 18:11:49 +0800474/* Use regular expression searching matched pattern X.Y, and convert it to */
475/* Major (X) and Minor (Y) version. */
476/* Example: */
477/* version = 2.14.0-dev */
478/* ^ ^ */
479/* | |---------------- Minor */
480/* |------------------ Major */
481/* */
Potin Laic7c55922023-02-16 10:33:55 +0800482/* Default regex string only tries to match Major and Minor version. */
483/* */
484/* To match more firmware version info, platforms need to define it own */
485/* regex string to match more strings, and assign correct mapping index in */
486/* matches array. */
487/* */
488/* matches[0]: matched index for major ver */
489/* matches[1]: matched index for minor ver */
490/* matches[2]: matched index for aux[0] (set 0 to skip) */
491/* matches[3]: matched index for aux[1] (set 0 to skip) */
492/* matches[4]: matched index for aux[2] (set 0 to skip) */
493/* matches[5]: matched index for aux[3] (set 0 to skip) */
494/* Example: */
495/* regex = "([\d]+).([\d]+).([\d]+)-dev-([\d]+)-g([0-9a-fA-F]{2}) */
496/* ([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})" */
497/* matches = {1,2,5,6,7,8} */
498/* version = 2.14.0-dev-750-g37a7c5ad1-dirty */
499/* ^ ^ ^ ^ ^ ^ ^ ^ */
500/* | | | | | | | | */
501/* | | | | | | | |-- Aux byte 3 (0xAD), index 8 */
502/* | | | | | | |---- Aux byte 2 (0xC5), index 7 */
503/* | | | | | |------ Aux byte 1 (0xA7), index 6 */
504/* | | | | |-------- Aux byte 0 (0x37), index 5 */
505/* | | | |------------- Not used, index 4 */
506/* | | |------------------- Not used, index 3 */
507/* | |---------------------- Minor (14), index 2 */
508/* |------------------------ Major (2), index 1 */
Potin Lai5d214202023-01-16 18:11:49 +0800509int convertVersion(std::string s, Revision& rev)
Chris Austen7303bdc2016-04-17 11:50:54 -0500510{
Potin Laic7c55922023-02-16 10:33:55 +0800511 static const std::vector<size_t> matches = {
512 MAJOR_MATCH_INDEX, MINOR_MATCH_INDEX, AUX_0_MATCH_INDEX,
513 AUX_1_MATCH_INDEX, AUX_2_MATCH_INDEX, AUX_3_MATCH_INDEX};
Potin Lai5d214202023-01-16 18:11:49 +0800514 std::regex fw_regex(FW_VER_REGEX);
515 std::smatch m;
516 Revision r = {0};
517 size_t val;
Chris Austen7303bdc2016-04-17 11:50:54 -0500518
Potin Laidcde04e2023-03-16 18:44:15 +0800519 if (std::regex_search(s, m, fw_regex))
Dinesh Chinari2b7e07d2017-11-08 15:38:50 -0600520 {
Potin Laic7c55922023-02-16 10:33:55 +0800521 if (m.size() < *std::max_element(matches.begin(), matches.end()))
522 { // max index higher than match count
Potin Laidcde04e2023-03-16 18:44:15 +0800523 return -1;
524 }
525
Potin Lai5d214202023-01-16 18:11:49 +0800526 // convert major
527 {
Potin Laic7c55922023-02-16 10:33:55 +0800528 std::string_view str = m[matches[0]].str();
Potin Lai5d214202023-01-16 18:11:49 +0800529 auto [ptr, ec]{std::from_chars(str.begin(), str.end(), val)};
530 if (ec != std::errc() || ptr != str.begin() + str.size())
531 { // failed to convert major string
Potin Laidcde04e2023-03-16 18:44:15 +0800532 return -1;
Potin Lai5d214202023-01-16 18:11:49 +0800533 }
534 r.major = val & 0x7F;
535 }
536
537 // convert minor
538 {
Potin Laic7c55922023-02-16 10:33:55 +0800539 std::string_view str = m[matches[1]].str();
Potin Lai5d214202023-01-16 18:11:49 +0800540 auto [ptr, ec]{std::from_chars(str.begin(), str.end(), val)};
541 if (ec != std::errc() || ptr != str.begin() + str.size())
542 { // failed to convert minor string
Potin Laidcde04e2023-03-16 18:44:15 +0800543 return -1;
Potin Lai5d214202023-01-16 18:11:49 +0800544 }
545 r.minor = val & 0xFF;
546 }
547
Potin Laic7c55922023-02-16 10:33:55 +0800548 // convert aux bytes
549 {
550 size_t i;
551 for (i = 0; i < 4; i++)
552 {
553 if (matches[i + 2] == 0)
554 {
555 continue;
556 }
557
558 std::string_view str = m[matches[i + 2]].str();
559 auto [ptr,
560 ec]{std::from_chars(str.begin(), str.end(), val, 16)};
561 if (ec != std::errc() || ptr != str.begin() + str.size())
562 { // failed to convert aux byte string
563 break;
564 }
565
566 r.aux[i] = val & 0xFF;
567 }
568
569 if (i != 4)
570 { // something wrong durign converting aux bytes
571 return -1;
572 }
573 }
574
Potin Lai5d214202023-01-16 18:11:49 +0800575 // all matched
576 rev = r;
577 return 0;
Chris Austen176c9652016-04-30 16:32:17 -0500578 }
Chris Austen7303bdc2016-04-17 11:50:54 -0500579
Potin Lai5d214202023-01-16 18:11:49 +0800580 return -1;
Chris Austen7303bdc2016-04-17 11:50:54 -0500581}
582
Vernon Maueryea1c4012019-05-24 13:26:16 -0700583/* @brief: Implement the Get Device ID IPMI command per the IPMI spec
584 * @param[in] ctx - shared_ptr to an IPMI context struct
585 *
586 * @returns IPMI completion code plus response data
587 * - Device ID (manufacturer defined)
588 * - Device revision[4 bits]; reserved[3 bits]; SDR support[1 bit]
589 * - FW revision major[7 bits] (binary encoded); available[1 bit]
590 * - FW Revision minor (BCD encoded)
591 * - IPMI version (0x02 for IPMI 2.0)
592 * - device support (bitfield of supported options)
593 * - MFG IANA ID (3 bytes)
594 * - product ID (2 bytes)
595 * - AUX info (4 bytes)
596 */
597ipmi::RspType<uint8_t, // Device ID
598 uint8_t, // Device Revision
599 uint8_t, // Firmware Revision Major
600 uint8_t, // Firmware Revision minor
601 uint8_t, // IPMI version
602 uint8_t, // Additional device support
603 uint24_t, // MFG ID
604 uint16_t, // Product ID
605 uint32_t // AUX info
606 >
Willy Tu11d68892022-01-20 10:37:34 -0800607 ipmiAppGetDeviceId([[maybe_unused]] ipmi::Context::ptr ctx)
Chris Austen6caf28b2015-10-13 12:40:40 -0500608{
Vernon Mauery86a50822019-03-25 13:11:36 -0700609 static struct
610 {
611 uint8_t id;
612 uint8_t revision;
613 uint8_t fw[2];
614 uint8_t ipmiVer;
615 uint8_t addnDevSupport;
616 uint24_t manufId;
617 uint16_t prodId;
618 uint32_t aux;
619 } devId;
David Cobbleya1adb072017-11-21 15:58:13 -0800620 static bool dev_id_initialized = false;
Patrick Venture94930a12019-04-30 10:01:58 -0700621 static bool defaultActivationSetting = true;
David Cobbleya1adb072017-11-21 15:58:13 -0800622 const char* filename = "/usr/share/ipmi-providers/dev_id.json";
Alexander Amelkinba19c182018-09-04 15:49:36 +0300623 constexpr auto ipmiDevIdStateShift = 7;
624 constexpr auto ipmiDevIdFw1Mask = ~(1 << ipmiDevIdStateShift);
Willy Tub78184e2022-10-27 22:57:38 +0000625
626#ifdef GET_DBUS_ACTIVE_SOFTWARE
627 static bool haveBMCVersion = false;
JeffLin27a62ec2021-11-24 15:40:33 +0800628 if (!haveBMCVersion || !dev_id_initialized)
David Cobbleya1adb072017-11-21 15:58:13 -0800629 {
Willy Tub78184e2022-10-27 22:57:38 +0000630 int r = -1;
631 Revision rev = {0, 0, 0, 0};
Nagaraju Goruganti744398d2018-02-20 09:52:00 -0600632 try
633 {
Vernon Maueryea1c4012019-05-24 13:26:16 -0700634 auto version = getActiveSoftwareVersionInfo(ctx);
Vernon Mauery86a50822019-03-25 13:11:36 -0700635 r = convertVersion(version, rev);
David Cobbleya1adb072017-11-21 15:58:13 -0800636 }
Nagaraju Goruganti744398d2018-02-20 09:52:00 -0600637 catch (const std::exception& e)
638 {
639 log<level::ERR>(e.what());
640 }
Nan Liee0cb902016-07-11 15:38:03 +0800641
Patrick Venture0b02be92018-08-31 11:55:55 -0700642 if (r >= 0)
643 {
Nagaraju Goruganti744398d2018-02-20 09:52:00 -0600644 // bit7 identifies if the device is available
645 // 0=normal operation
646 // 1=device firmware, SDR update,
647 // or self-initialization in progress.
Alexander Amelkinba19c182018-09-04 15:49:36 +0300648 // The availability may change in run time, so mask here
649 // and initialize later.
Vernon Mauery86a50822019-03-25 13:11:36 -0700650 devId.fw[0] = rev.major & ipmiDevIdFw1Mask;
Nagaraju Goruganti744398d2018-02-20 09:52:00 -0600651
652 rev.minor = (rev.minor > 99 ? 99 : rev.minor);
Vernon Mauery86a50822019-03-25 13:11:36 -0700653 devId.fw[1] = rev.minor % 10 + (rev.minor / 10) * 16;
Potin Laic7c55922023-02-16 10:33:55 +0800654 std::memcpy(&devId.aux, rev.aux, sizeof(rev.aux));
Brandon Kimc1f5aca2022-03-17 17:54:06 -0700655 haveBMCVersion = true;
David Cobbleya1adb072017-11-21 15:58:13 -0800656 }
JeffLin27a62ec2021-11-24 15:40:33 +0800657 }
Willy Tub78184e2022-10-27 22:57:38 +0000658#endif
JeffLin27a62ec2021-11-24 15:40:33 +0800659 if (!dev_id_initialized)
660 {
David Cobbleya1adb072017-11-21 15:58:13 -0800661 // IPMI Spec version 2.0
Vernon Mauery86a50822019-03-25 13:11:36 -0700662 devId.ipmiVer = 2;
Adriana Kobylak0e912642016-06-22 16:54:39 -0500663
Vernon Mauery86a50822019-03-25 13:11:36 -0700664 std::ifstream devIdFile(filename);
665 if (devIdFile.is_open())
David Cobbleya1adb072017-11-21 15:58:13 -0800666 {
Vernon Mauery86a50822019-03-25 13:11:36 -0700667 auto data = nlohmann::json::parse(devIdFile, nullptr, false);
David Cobbleya1adb072017-11-21 15:58:13 -0800668 if (!data.is_discarded())
669 {
Vernon Mauery86a50822019-03-25 13:11:36 -0700670 devId.id = data.value("id", 0);
671 devId.revision = data.value("revision", 0);
672 devId.addnDevSupport = data.value("addn_dev_support", 0);
673 devId.manufId = data.value("manuf_id", 0);
674 devId.prodId = data.value("prod_id", 0);
675 devId.aux = data.value("aux", 0);
David Cobbleya1adb072017-11-21 15:58:13 -0800676
Willy Tubfd3a172022-05-31 13:57:54 -0700677 if (data.contains("firmware_revision"))
678 {
679 const auto& firmwareRevision = data.at("firmware_revision");
680 if (firmwareRevision.contains("major"))
681 {
682 firmwareRevision.at("major").get_to(devId.fw[0]);
683 }
684 if (firmwareRevision.contains("minor"))
685 {
686 firmwareRevision.at("minor").get_to(devId.fw[1]);
687 }
688 }
689
Patrick Venture94930a12019-04-30 10:01:58 -0700690 // Set the availablitity of the BMC.
691 defaultActivationSetting = data.value("availability", true);
692
Patrick Venture0b02be92018-08-31 11:55:55 -0700693 // Don't read the file every time if successful
David Cobbleya1adb072017-11-21 15:58:13 -0800694 dev_id_initialized = true;
695 }
696 else
697 {
698 log<level::ERR>("Device ID JSON parser failure");
Vernon Maueryf2587fc2019-04-09 14:28:15 -0700699 return ipmi::responseUnspecifiedError();
David Cobbleya1adb072017-11-21 15:58:13 -0800700 }
701 }
702 else
703 {
704 log<level::ERR>("Device ID file not found");
Vernon Maueryf2587fc2019-04-09 14:28:15 -0700705 return ipmi::responseUnspecifiedError();
Chris Austen7303bdc2016-04-17 11:50:54 -0500706 }
707 }
Chris Austen6caf28b2015-10-13 12:40:40 -0500708
Alexander Amelkinba19c182018-09-04 15:49:36 +0300709 // Set availability to the actual current BMC state
Vernon Mauery86a50822019-03-25 13:11:36 -0700710 devId.fw[0] &= ipmiDevIdFw1Mask;
Patrick Venture94930a12019-04-30 10:01:58 -0700711 if (!getCurrentBmcStateWithFallback(defaultActivationSetting))
Alexander Amelkinba19c182018-09-04 15:49:36 +0300712 {
Vernon Mauery86a50822019-03-25 13:11:36 -0700713 devId.fw[0] |= (1 << ipmiDevIdStateShift);
Alexander Amelkinba19c182018-09-04 15:49:36 +0300714 }
715
Vernon Mauery86a50822019-03-25 13:11:36 -0700716 return ipmi::responseSuccess(
717 devId.id, devId.revision, devId.fw[0], devId.fw[1], devId.ipmiVer,
718 devId.addnDevSupport, devId.manufId, devId.prodId, devId.aux);
Chris Austen6caf28b2015-10-13 12:40:40 -0500719}
720
Vernon Maueryb84a5282019-03-25 13:39:03 -0700721auto ipmiAppGetSelfTestResults() -> ipmi::RspType<uint8_t, uint8_t>
Nan Li41fa24a2016-11-10 20:12:37 +0800722{
Nan Li41fa24a2016-11-10 20:12:37 +0800723 // Byte 2:
724 // 55h - No error.
Gunnar Mills8991dd62017-10-25 17:11:29 -0500725 // 56h - Self Test function not implemented in this controller.
Nan Li41fa24a2016-11-10 20:12:37 +0800726 // 57h - Corrupted or inaccesssible data or devices.
727 // 58h - Fatal hardware error.
728 // FFh - reserved.
729 // all other: Device-specific 'internal failure'.
730 // Byte 3:
731 // For byte 2 = 55h, 56h, FFh: 00h
732 // For byte 2 = 58h, all other: Device-specific
733 // For byte 2 = 57h: self-test error bitfield.
734 // Note: returning 57h does not imply that all test were run.
735 // [7] 1b = Cannot access SEL device.
736 // [6] 1b = Cannot access SDR Repository.
737 // [5] 1b = Cannot access BMC FRU device.
738 // [4] 1b = IPMB signal lines do not respond.
739 // [3] 1b = SDR Repository empty.
740 // [2] 1b = Internal Use Area of BMC FRU corrupted.
741 // [1] 1b = controller update 'boot block' firmware corrupted.
742 // [0] 1b = controller operational firmware corrupted.
Vernon Maueryb84a5282019-03-25 13:39:03 -0700743 constexpr uint8_t notImplemented = 0x56;
744 constexpr uint8_t zero = 0;
745 return ipmi::responseSuccess(notImplemented, zero);
Nan Li41fa24a2016-11-10 20:12:37 +0800746}
747
Vernon Mauery15541322019-03-25 13:33:03 -0700748static constexpr size_t uuidBinaryLength = 16;
749static std::array<uint8_t, uuidBinaryLength> rfc4122ToIpmi(std::string rfc4122)
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500750{
Vernon Mauery15541322019-03-25 13:33:03 -0700751 using Argument = xyz::openbmc_project::Common::InvalidArgument;
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500752 // UUID is in RFC4122 format. Ex: 61a39523-78f2-11e5-9862-e6402cfc3223
Patrick Ventured2117022018-02-06 08:54:37 -0800753 // Per IPMI Spec 2.0 need to convert to 16 hex bytes and reverse the byte
754 // order
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500755 // Ex: 0x2332fc2c40e66298e511f2782395a361
Vernon Mauery15541322019-03-25 13:33:03 -0700756 constexpr size_t uuidHexLength = (2 * uuidBinaryLength);
757 constexpr size_t uuidRfc4122Length = (uuidHexLength + 4);
758 std::array<uint8_t, uuidBinaryLength> uuid;
759 if (rfc4122.size() == uuidRfc4122Length)
Patrick Venture0b02be92018-08-31 11:55:55 -0700760 {
Vernon Mauery15541322019-03-25 13:33:03 -0700761 rfc4122.erase(std::remove(rfc4122.begin(), rfc4122.end(), '-'),
762 rfc4122.end());
Sergey Solomineb9b8142016-08-23 09:07:28 -0500763 }
Vernon Mauery15541322019-03-25 13:33:03 -0700764 if (rfc4122.size() != uuidHexLength)
vishwa1eaea4f2016-02-26 11:57:40 -0600765 {
Vernon Mauery15541322019-03-25 13:33:03 -0700766 elog<InvalidArgument>(Argument::ARGUMENT_NAME("rfc4122"),
767 Argument::ARGUMENT_VALUE(rfc4122.c_str()));
vishwa1eaea4f2016-02-26 11:57:40 -0600768 }
Vernon Mauery15541322019-03-25 13:33:03 -0700769 for (size_t ind = 0; ind < uuidHexLength; ind += 2)
vishwa1eaea4f2016-02-26 11:57:40 -0600770 {
Vernon Mauery15541322019-03-25 13:33:03 -0700771 char v[3];
772 v[0] = rfc4122[ind];
773 v[1] = rfc4122[ind + 1];
774 v[2] = 0;
775 size_t err;
776 long b;
777 try
Emily Shafferedb8bb02018-09-27 14:50:15 -0700778 {
Vernon Mauery15541322019-03-25 13:33:03 -0700779 b = std::stoul(v, &err, 16);
Emily Shafferedb8bb02018-09-27 14:50:15 -0700780 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500781 catch (const std::exception& e)
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500782 {
Vernon Mauery15541322019-03-25 13:33:03 -0700783 elog<InvalidArgument>(Argument::ARGUMENT_NAME("rfc4122"),
784 Argument::ARGUMENT_VALUE(rfc4122.c_str()));
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500785 }
Vernon Mauery15541322019-03-25 13:33:03 -0700786 // check that exactly two ascii bytes were converted
787 if (err != 2)
788 {
789 elog<InvalidArgument>(Argument::ARGUMENT_NAME("rfc4122"),
790 Argument::ARGUMENT_VALUE(rfc4122.c_str()));
791 }
792 uuid[uuidBinaryLength - (ind / 2) - 1] = static_cast<uint8_t>(b);
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500793 }
Vernon Mauery15541322019-03-25 13:33:03 -0700794 return uuid;
795}
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500796
Vernon Mauery15541322019-03-25 13:33:03 -0700797auto ipmiAppGetDeviceGuid()
798 -> ipmi::RspType<std::array<uint8_t, uuidBinaryLength>>
799{
800 // return a fixed GUID based on /etc/machine-id
801 // This should match the /redfish/v1/Managers/bmc's UUID data
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500802
Vernon Mauery15541322019-03-25 13:33:03 -0700803 // machine specific application ID (for BMC ID)
804 // generated by systemd-id128 -p new as per man page
805 static constexpr sd_id128_t bmcUuidAppId = SD_ID128_MAKE(
806 e0, e1, 73, 76, 64, 61, 47, da, a5, 0c, d0, cc, 64, 12, 45, 78);
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500807
Vernon Mauery15541322019-03-25 13:33:03 -0700808 sd_id128_t bmcUuid;
809 // create the UUID from /etc/machine-id via the systemd API
810 sd_id128_get_machine_app_specific(bmcUuidAppId, &bmcUuid);
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500811
Vernon Mauery15541322019-03-25 13:33:03 -0700812 char bmcUuidCstr[SD_ID128_STRING_MAX];
813 std::string systemUuid = sd_id128_to_string(bmcUuid, bmcUuidCstr);
814
815 std::array<uint8_t, uuidBinaryLength> uuid = rfc4122ToIpmi(systemUuid);
816 return ipmi::responseSuccess(uuid);
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500817}
Chris Austen6caf28b2015-10-13 12:40:40 -0500818
Vernon Mauerycc99ba42019-03-25 13:40:11 -0700819auto ipmiAppGetBtCapabilities()
820 -> ipmi::RspType<uint8_t, uint8_t, uint8_t, uint8_t, uint8_t>
vishwabmcba0bd5f2015-09-30 16:50:23 +0530821{
Adriana Kobylak88ad8152016-12-13 10:09:08 -0600822 // Per IPMI 2.0 spec, the input and output buffer size must be the max
823 // buffer size minus one byte to allocate space for the length byte.
Vernon Mauerycc99ba42019-03-25 13:40:11 -0700824 constexpr uint8_t nrOutstanding = 0x01;
825 constexpr uint8_t inputBufferSize = MAX_IPMI_BUFFER - 1;
826 constexpr uint8_t outputBufferSize = MAX_IPMI_BUFFER - 1;
827 constexpr uint8_t transactionTime = 0x0A;
828 constexpr uint8_t nrRetries = 0x01;
vishwabmcba0bd5f2015-09-30 16:50:23 +0530829
Vernon Mauerycc99ba42019-03-25 13:40:11 -0700830 return ipmi::responseSuccess(nrOutstanding, inputBufferSize,
831 outputBufferSize, transactionTime, nrRetries);
vishwabmcba0bd5f2015-09-30 16:50:23 +0530832}
833
Vernon Maueryb90a5322019-03-25 13:36:55 -0700834auto ipmiAppGetSystemGuid() -> ipmi::RspType<std::array<uint8_t, 16>>
Marri Devender Rao5e007a52018-01-08 06:18:36 -0600835{
Vernon Maueryb90a5322019-03-25 13:36:55 -0700836 static constexpr auto uuidInterface = "xyz.openbmc_project.Common.UUID";
837 static constexpr auto uuidProperty = "UUID";
Marri Devender Rao5e007a52018-01-08 06:18:36 -0600838
Vernon Maueryb90a5322019-03-25 13:36:55 -0700839 ipmi::Value propValue;
Marri Devender Rao5e007a52018-01-08 06:18:36 -0600840 try
841 {
842 // Get the Inventory object implementing BMC interface
Vernon Maueryb90a5322019-03-25 13:36:55 -0700843 auto busPtr = getSdBus();
Hieu Huynh45aed692022-10-12 10:58:26 +0000844 auto objectInfo = ipmi::getDbusObject(*busPtr, uuidInterface);
Marri Devender Rao5e007a52018-01-08 06:18:36 -0600845
846 // Read UUID property value from bmcObject
847 // UUID is in RFC4122 format Ex: 61a39523-78f2-11e5-9862-e6402cfc3223
Vernon Maueryb90a5322019-03-25 13:36:55 -0700848 propValue =
849 ipmi::getDbusProperty(*busPtr, objectInfo.second, objectInfo.first,
850 uuidInterface, uuidProperty);
Marri Devender Rao5e007a52018-01-08 06:18:36 -0600851 }
852 catch (const InternalFailure& e)
853 {
854 log<level::ERR>("Failed in reading BMC UUID property",
Vernon Maueryb90a5322019-03-25 13:36:55 -0700855 entry("INTERFACE=%s", uuidInterface),
856 entry("PROPERTY=%s", uuidProperty));
857 return ipmi::responseUnspecifiedError();
Marri Devender Rao5e007a52018-01-08 06:18:36 -0600858 }
Vernon Maueryb90a5322019-03-25 13:36:55 -0700859 std::array<uint8_t, 16> uuid;
860 std::string rfc4122Uuid = std::get<std::string>(propValue);
861 try
862 {
863 // convert to IPMI format
864 uuid = rfc4122ToIpmi(rfc4122Uuid);
865 }
866 catch (const InvalidArgument& e)
867 {
868 log<level::ERR>("Failed in parsing BMC UUID property",
869 entry("INTERFACE=%s", uuidInterface),
870 entry("PROPERTY=%s", uuidProperty),
871 entry("VALUE=%s", rfc4122Uuid.c_str()));
872 return ipmi::responseUnspecifiedError();
873 }
874 return ipmi::responseSuccess(uuid);
Marri Devender Rao5e007a52018-01-08 06:18:36 -0600875}
876
Rajashekar Gade Reddye7023922019-07-10 16:54:55 +0000877/**
878 * @brief set the session state as teardown
879 *
880 * This function is to set the session state to tear down in progress if the
881 * state is active.
882 *
883 * @param[in] busp - Dbus obj
884 * @param[in] service - service name
885 * @param[in] obj - object path
886 *
887 * @return success completion code if it sets the session state to
888 * tearDownInProgress else return the corresponding error completion code.
889 **/
890uint8_t setSessionState(std::shared_ptr<sdbusplus::asio::connection>& busp,
891 const std::string& service, const std::string& obj)
892{
893 try
894 {
895 uint8_t sessionState = std::get<uint8_t>(ipmi::getDbusProperty(
896 *busp, service, obj, session::sessionIntf, "State"));
897
898 if (sessionState == static_cast<uint8_t>(session::State::active))
899 {
900 ipmi::setDbusProperty(
901 *busp, service, obj, session::sessionIntf, "State",
902 static_cast<uint8_t>(session::State::tearDownInProgress));
903 return ipmi::ccSuccess;
904 }
905 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -0500906 catch (const std::exception& e)
Rajashekar Gade Reddye7023922019-07-10 16:54:55 +0000907 {
908 log<level::ERR>("Failed in getting session state property",
909 entry("service=%s", service.c_str()),
910 entry("object path=%s", obj.c_str()),
911 entry("interface=%s", session::sessionIntf));
912 return ipmi::ccUnspecifiedError;
913 }
914
915 return ipmi::ccInvalidFieldRequest;
916}
917
918ipmi::RspType<> ipmiAppCloseSession(uint32_t reqSessionId,
919 std::optional<uint8_t> requestSessionHandle)
920{
921 auto busp = getSdBus();
922 uint8_t reqSessionHandle =
923 requestSessionHandle.value_or(session::defaultSessionHandle);
924
925 if (reqSessionId == session::sessionZero &&
926 reqSessionHandle == session::defaultSessionHandle)
927 {
928 return ipmi::response(session::ccInvalidSessionId);
929 }
930
931 if (reqSessionId == session::sessionZero &&
932 reqSessionHandle == session::invalidSessionHandle)
933 {
934 return ipmi::response(session::ccInvalidSessionHandle);
935 }
936
937 if (reqSessionId != session::sessionZero &&
938 reqSessionHandle != session::defaultSessionHandle)
939 {
940 return ipmi::response(ipmi::ccInvalidFieldRequest);
941 }
942
943 try
944 {
945 ipmi::ObjectTree objectTree = ipmi::getAllDbusObjects(
946 *busp, session::sessionManagerRootPath, session::sessionIntf);
947
948 for (auto& objectTreeItr : objectTree)
949 {
950 const std::string obj = objectTreeItr.first;
951
952 if (isSessionObjectMatched(obj, reqSessionId, reqSessionHandle))
953 {
954 auto& serviceMap = objectTreeItr.second;
955
956 // Session id and session handle are unique for each session.
957 // Session id and handler are retrived from the object path and
958 // object path will be unique for each session. Checking if
959 // multiple objects exist with same object path under multiple
960 // services.
961 if (serviceMap.size() != 1)
962 {
963 return ipmi::responseUnspecifiedError();
964 }
965
966 auto itr = serviceMap.begin();
967 const std::string service = itr->first;
968 return ipmi::response(setSessionState(busp, service, obj));
969 }
970 }
971 }
Patrick Williams5d82f472022-07-22 19:26:53 -0500972 catch (const sdbusplus::exception_t& e)
Rajashekar Gade Reddye7023922019-07-10 16:54:55 +0000973 {
974 log<level::ERR>("Failed to fetch object from dbus",
975 entry("INTERFACE=%s", session::sessionIntf),
976 entry("ERRMSG=%s", e.what()));
977 return ipmi::responseUnspecifiedError();
978 }
979
980 return ipmi::responseInvalidFieldRequest();
981}
982
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +0000983uint8_t getTotalSessionCount()
984{
Meera-Kattac1789482021-05-18 09:53:26 +0000985 uint8_t count = 0, ch = 0;
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +0000986
987 while (ch < ipmi::maxIpmiChannels &&
988 count < session::maxNetworkInstanceSupported)
989 {
Jayaprakash Mutyala80207e62020-07-04 16:34:15 +0000990 ipmi::ChannelInfo chInfo{};
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +0000991 ipmi::getChannelInfo(ch, chInfo);
992 if (static_cast<ipmi::EChannelMediumType>(chInfo.mediumType) ==
993 ipmi::EChannelMediumType::lan8032)
994 {
995 count++;
996 }
997 ch++;
998 }
999 return count * session::maxSessionCountPerChannel;
1000}
1001
1002/**
1003 * @brief get session info request data.
1004 *
1005 * This function validates the request data and retrive request session id,
1006 * session handle.
1007 *
Rajashekar Gade Reddy4d226402019-11-13 17:13:05 +05301008 * @param[in] ctx - context of current session.
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001009 * @param[in] sessionIndex - request session index
1010 * @param[in] payload - input payload
1011 * @param[in] reqSessionId - unpacked session Id will be asigned
1012 * @param[in] reqSessionHandle - unpacked session handle will be asigned
1013 *
1014 * @return success completion code if request data is valid
1015 * else return the correcponding error completion code.
1016 **/
Rajashekar Gade Reddy4d226402019-11-13 17:13:05 +05301017uint8_t getSessionInfoRequestData(const ipmi::Context::ptr ctx,
1018 const uint8_t sessionIndex,
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001019 ipmi::message::Payload& payload,
1020 uint32_t& reqSessionId,
1021 uint8_t& reqSessionHandle)
1022{
Rajashekar Gade Reddy4d226402019-11-13 17:13:05 +05301023 if ((sessionIndex > session::maxSessionCountPerChannel) &&
1024 (sessionIndex < session::searchSessionByHandle))
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001025 {
1026 return ipmi::ccInvalidFieldRequest;
1027 }
1028
1029 switch (sessionIndex)
1030 {
Rajashekar Gade Reddy4d226402019-11-13 17:13:05 +05301031 case session::searchCurrentSession:
1032
1033 ipmi::ChannelInfo chInfo;
1034 ipmi::getChannelInfo(ctx->channel, chInfo);
1035
1036 if (static_cast<ipmi::EChannelMediumType>(chInfo.mediumType) !=
1037 ipmi::EChannelMediumType::lan8032)
1038 {
1039 return ipmi::ccInvalidFieldRequest;
1040 }
1041
1042 if (!payload.fullyUnpacked())
1043 {
1044 return ipmi::ccReqDataLenInvalid;
1045 }
1046 // Check if current sessionId is 0, sessionId 0 is reserved.
1047 if (ctx->sessionId == session::sessionZero)
1048 {
1049 return session::ccInvalidSessionId;
1050 }
1051 reqSessionId = ctx->sessionId;
1052 break;
1053
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001054 case session::searchSessionByHandle:
1055
1056 if ((payload.unpack(reqSessionHandle)) ||
1057 (!payload.fullyUnpacked()))
1058 {
1059 return ipmi::ccReqDataLenInvalid;
1060 }
1061
1062 if ((reqSessionHandle == session::sessionZero) ||
1063 ((reqSessionHandle & session::multiIntfaceSessionHandleMask) >
1064 session::maxSessionCountPerChannel))
1065 {
1066 return session::ccInvalidSessionHandle;
1067 }
1068 break;
1069
1070 case session::searchSessionById:
1071
1072 if ((payload.unpack(reqSessionId)) || (!payload.fullyUnpacked()))
1073 {
1074 return ipmi::ccReqDataLenInvalid;
1075 }
1076
1077 if (reqSessionId == session::sessionZero)
1078 {
1079 return session::ccInvalidSessionId;
1080 }
1081 break;
1082
1083 default:
1084 if (!payload.fullyUnpacked())
1085 {
1086 return ipmi::ccReqDataLenInvalid;
1087 }
1088 break;
1089 }
1090 return ipmi::ccSuccess;
1091}
1092
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001093uint8_t getSessionState(ipmi::Context::ptr ctx, const std::string& service,
1094 const std::string& objPath, uint8_t& sessionState)
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001095{
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001096 boost::system::error_code ec = ipmi::getDbusProperty(
1097 ctx, service, objPath, session::sessionIntf, "State", sessionState);
1098 if (ec)
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001099 {
1100 log<level::ERR>("Failed to fetch state property ",
1101 entry("SERVICE=%s", service.c_str()),
1102 entry("OBJECTPATH=%s", objPath.c_str()),
1103 entry("INTERFACE=%s", session::sessionIntf),
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001104 entry("ERRMSG=%s", ec.message().c_str()));
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001105 return ipmi::ccUnspecifiedError;
1106 }
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001107 return ipmi::ccSuccess;
1108}
1109
1110static constexpr uint8_t macAddrLen = 6;
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001111/** Alias SessionDetails - contain the optional information about an
1112 * RMCP+ session.
1113 *
1114 * @param userID - uint6_t session user ID (0-63)
1115 * @param reserved - uint2_t reserved
1116 * @param privilege - uint4_t session privilege (0-5)
1117 * @param reserved - uint4_t reserved
1118 * @param channel - uint4_t session channel number
1119 * @param protocol - uint4_t session protocol
1120 * @param remoteIP - uint32_t remote IP address
1121 * @param macAddr - std::array<uint8_t, 6> mac address
1122 * @param port - uint16_t remote port
1123 */
1124using SessionDetails =
1125 std::tuple<uint2_t, uint6_t, uint4_t, uint4_t, uint4_t, uint4_t, uint32_t,
1126 std::array<uint8_t, macAddrLen>, uint16_t>;
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001127
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001128/** @brief get session details for a given session
1129 *
1130 * @param[in] ctx - ipmi::Context pointer for accessing D-Bus
1131 * @param[in] service - D-Bus service name to fetch details from
1132 * @param[in] objPath - D-Bus object path for session
1133 * @param[out] sessionHandle - return session handle for session
1134 * @param[out] sessionState - return session state for session
1135 * @param[out] details - return a SessionDetails tuple containing other
1136 * session info
1137 * @return - ipmi::Cc success or error code
1138 */
1139ipmi::Cc getSessionDetails(ipmi::Context::ptr ctx, const std::string& service,
1140 const std::string& objPath, uint8_t& sessionHandle,
1141 uint8_t& sessionState, SessionDetails& details)
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001142{
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001143 ipmi::PropertyMap sessionProps;
1144 boost::system::error_code ec = ipmi::getAllDbusProperties(
1145 ctx, service, objPath, session::sessionIntf, sessionProps);
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001146
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001147 if (ec)
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001148 {
1149 log<level::ERR>("Failed to fetch state property ",
1150 entry("SERVICE=%s", service.c_str()),
1151 entry("OBJECTPATH=%s", objPath.c_str()),
1152 entry("INTERFACE=%s", session::sessionIntf),
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001153 entry("ERRMSG=%s", ec.message().c_str()));
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001154 return ipmi::ccUnspecifiedError;
1155 }
1156
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001157 sessionState = ipmi::mappedVariant<uint8_t>(
1158 sessionProps, "State", static_cast<uint8_t>(session::State::inactive));
1159 if (sessionState == static_cast<uint8_t>(session::State::active))
1160 {
1161 sessionHandle =
1162 ipmi::mappedVariant<uint8_t>(sessionProps, "SessionHandle", 0);
1163 std::get<0>(details) =
1164 ipmi::mappedVariant<uint8_t>(sessionProps, "UserID", 0xff);
1165 // std::get<1>(details) = 0; // (default constructed to 0)
1166 std::get<2>(details) =
1167 ipmi::mappedVariant<uint8_t>(sessionProps, "CurrentPrivilege", 0);
1168 // std::get<3>(details) = 0; // (default constructed to 0)
1169 std::get<4>(details) =
1170 ipmi::mappedVariant<uint8_t>(sessionProps, "ChannelNum", 0xff);
1171 constexpr uint4_t rmcpPlusProtocol = 1;
1172 std::get<5>(details) = rmcpPlusProtocol;
1173 std::get<6>(details) =
1174 ipmi::mappedVariant<uint32_t>(sessionProps, "RemoteIPAddr", 0);
1175 // std::get<7>(details) = {{0}}; // default constructed to all 0
1176 std::get<8>(details) =
1177 ipmi::mappedVariant<uint16_t>(sessionProps, "RemotePort", 0);
1178 }
1179
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001180 return ipmi::ccSuccess;
1181}
1182
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001183ipmi::RspType<uint8_t, // session handle,
1184 uint8_t, // total session count
1185 uint8_t, // active session count
1186 std::optional<SessionDetails>>
Rajashekar Gade Reddy4d226402019-11-13 17:13:05 +05301187 ipmiAppGetSessionInfo(ipmi::Context::ptr ctx, uint8_t sessionIndex,
1188 ipmi::message::Payload& payload)
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001189{
1190 uint32_t reqSessionId = 0;
1191 uint8_t reqSessionHandle = session::defaultSessionHandle;
1192 // initializing state to 0xff as 0 represents state as inactive.
1193 uint8_t state = 0xFF;
1194
1195 uint8_t completionCode = getSessionInfoRequestData(
Rajashekar Gade Reddy4d226402019-11-13 17:13:05 +05301196 ctx, sessionIndex, payload, reqSessionId, reqSessionHandle);
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001197
1198 if (completionCode)
1199 {
1200 return ipmi::response(completionCode);
1201 }
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001202 ipmi::ObjectTree objectTree;
1203 boost::system::error_code ec = ipmi::getAllDbusObjects(
1204 ctx, session::sessionManagerRootPath, session::sessionIntf, objectTree);
1205 if (ec)
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001206 {
1207 log<level::ERR>("Failed to fetch object from dbus",
1208 entry("INTERFACE=%s", session::sessionIntf),
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001209 entry("ERRMSG=%s", ec.message().c_str()));
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001210 return ipmi::responseUnspecifiedError();
1211 }
1212
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001213 uint8_t totalSessionCount = getTotalSessionCount();
1214 uint8_t activeSessionCount = 0;
1215 uint8_t sessionHandle = session::defaultSessionHandle;
Johnathan Manteyca93bb12022-12-02 13:33:17 -08001216 uint8_t activeSessionHandle = 0;
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001217 std::optional<SessionDetails> maybeDetails;
1218 uint8_t index = 0;
1219 for (auto& objectTreeItr : objectTree)
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001220 {
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001221 uint32_t sessionId = 0;
1222 std::string objectPath = objectTreeItr.first;
1223
1224 if (!parseCloseSessionInputPayload(objectPath, sessionId,
1225 sessionHandle))
1226 {
1227 continue;
1228 }
1229 index++;
1230 auto& serviceMap = objectTreeItr.second;
1231 auto itr = serviceMap.begin();
1232
1233 if (serviceMap.size() != 1)
1234 {
1235 return ipmi::responseUnspecifiedError();
1236 }
1237
1238 std::string service = itr->first;
1239 uint8_t sessionState = 0;
1240 completionCode =
1241 getSessionState(ctx, service, objectPath, sessionState);
1242 if (completionCode)
1243 {
1244 return ipmi::response(completionCode);
1245 }
1246
1247 if (sessionState == static_cast<uint8_t>(session::State::active))
1248 {
1249 activeSessionCount++;
1250 }
1251
Johnathan Manteyca93bb12022-12-02 13:33:17 -08001252 if (index == sessionIndex || reqSessionId == sessionId ||
1253 reqSessionHandle == sessionHandle)
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001254 {
Johnathan Manteyca93bb12022-12-02 13:33:17 -08001255 SessionDetails details{};
1256 completionCode = getSessionDetails(ctx, service, objectPath,
1257 sessionHandle, state, details);
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001258
Johnathan Manteyca93bb12022-12-02 13:33:17 -08001259 if (completionCode)
1260 {
1261 return ipmi::response(completionCode);
1262 }
1263 activeSessionHandle = sessionHandle;
1264 maybeDetails = std::move(details);
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001265 }
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001266 }
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001267
1268 if (state == static_cast<uint8_t>(session::State::active) ||
1269 state == static_cast<uint8_t>(session::State::tearDownInProgress))
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001270 {
Johnathan Manteyca93bb12022-12-02 13:33:17 -08001271 return ipmi::responseSuccess(activeSessionHandle, totalSessionCount,
Vernon Mauerye7e8b812019-10-28 16:00:34 -07001272 activeSessionCount, maybeDetails);
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001273 }
1274
1275 return ipmi::responseInvalidFieldRequest();
1276}
1277
Xo Wangf542e8b2017-08-09 15:34:16 -07001278static std::unique_ptr<SysInfoParamStore> sysInfoParamStore;
1279
Xo Wang87651332017-08-11 10:17:59 -07001280static std::string sysInfoReadSystemName()
1281{
1282 // Use the BMC hostname as the "System Name."
1283 char hostname[HOST_NAME_MAX + 1] = {};
1284 if (gethostname(hostname, HOST_NAME_MAX) != 0)
1285 {
1286 perror("System info parameter: system name");
1287 }
1288 return hostname;
1289}
1290
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001291static constexpr uint8_t paramRevision = 0x11;
1292static constexpr size_t configParameterLength = 16;
Xo Wangf542e8b2017-08-09 15:34:16 -07001293
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001294static constexpr size_t smallChunkSize = 14;
1295static constexpr size_t fullChunkSize = 16;
Jia, chunhui449f2162019-09-11 16:51:51 +08001296static constexpr uint8_t progressMask = 0x3;
Xo Wangf542e8b2017-08-09 15:34:16 -07001297
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001298static constexpr uint8_t setComplete = 0x0;
1299static constexpr uint8_t setInProgress = 0x1;
1300static constexpr uint8_t commitWrite = 0x2;
1301static uint8_t transferStatus = setComplete;
1302
Jia, chunhui449f2162019-09-11 16:51:51 +08001303static constexpr uint8_t configDataOverhead = 2;
1304
1305// For EFI based system, 256 bytes is recommended.
1306static constexpr size_t maxBytesPerParameter = 256;
1307
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001308namespace ipmi
1309{
1310constexpr Cc ccParmNotSupported = 0x80;
Jia, chunhui449f2162019-09-11 16:51:51 +08001311constexpr Cc ccSetInProgressActive = 0x81;
1312constexpr Cc ccSystemInfoParameterSetReadOnly = 0x82;
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001313
1314static inline auto responseParmNotSupported()
1315{
1316 return response(ccParmNotSupported);
Xo Wangf542e8b2017-08-09 15:34:16 -07001317}
Jia, chunhui449f2162019-09-11 16:51:51 +08001318static inline auto responseSetInProgressActive()
1319{
1320 return response(ccSetInProgressActive);
1321}
1322static inline auto responseSystemInfoParameterSetReadOnly()
1323{
1324 return response(ccSystemInfoParameterSetReadOnly);
1325}
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001326} // namespace ipmi
Xo Wangf542e8b2017-08-09 15:34:16 -07001327
Jia, chunhui449f2162019-09-11 16:51:51 +08001328ipmi::RspType<uint8_t, // Parameter revision
1329 std::optional<uint8_t>, // data1 / setSelector / ProgressStatus
1330 std::optional<std::vector<uint8_t>>> // data2-17
jayaprakash Mutyalac2566a92020-04-23 21:18:35 +00001331 ipmiAppGetSystemInfo(uint7_t reserved, bool getRevision,
1332 uint8_t paramSelector, uint8_t setSelector,
1333 uint8_t BlockSelector)
Xo Wangf542e8b2017-08-09 15:34:16 -07001334{
Snehalatha Va5ae7722020-05-02 18:18:57 +00001335 if (reserved || (paramSelector >= invalidParamSelectorStart &&
1336 paramSelector <= invalidParamSelectorEnd))
jayaprakash Mutyalac2566a92020-04-23 21:18:35 +00001337 {
1338 return ipmi::responseInvalidFieldRequest();
1339 }
Snehalatha Va5ae7722020-05-02 18:18:57 +00001340 if ((paramSelector >= oemCmdStart) && (paramSelector <= oemCmdEnd))
1341 {
1342 return ipmi::responseParmNotSupported();
1343 }
jayaprakash Mutyalac2566a92020-04-23 21:18:35 +00001344 if (getRevision)
Xo Wangf542e8b2017-08-09 15:34:16 -07001345 {
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001346 return ipmi::responseSuccess(paramRevision, std::nullopt, std::nullopt);
Xo Wangf542e8b2017-08-09 15:34:16 -07001347 }
1348
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001349 if (paramSelector == 0)
Xo Wangf542e8b2017-08-09 15:34:16 -07001350 {
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001351 return ipmi::responseSuccess(paramRevision, transferStatus,
1352 std::nullopt);
Xo Wangf542e8b2017-08-09 15:34:16 -07001353 }
1354
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001355 if (BlockSelector != 0) // 00h if parameter does not require a block number
Xo Wangf542e8b2017-08-09 15:34:16 -07001356 {
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001357 return ipmi::responseParmNotSupported();
Xo Wangf542e8b2017-08-09 15:34:16 -07001358 }
1359
1360 if (sysInfoParamStore == nullptr)
1361 {
1362 sysInfoParamStore = std::make_unique<SysInfoParamStore>();
Xo Wang87651332017-08-11 10:17:59 -07001363 sysInfoParamStore->update(IPMI_SYSINFO_SYSTEM_NAME,
1364 sysInfoReadSystemName);
Xo Wangf542e8b2017-08-09 15:34:16 -07001365 }
1366
1367 // Parameters other than Set In Progress are assumed to be strings.
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001368 std::tuple<bool, std::string> ret =
1369 sysInfoParamStore->lookup(paramSelector);
1370 bool found = std::get<0>(ret);
Xo Wangf542e8b2017-08-09 15:34:16 -07001371 if (!found)
1372 {
Snehalatha Va5ae7722020-05-02 18:18:57 +00001373 return ipmi::responseSensorInvalid();
Xo Wangf542e8b2017-08-09 15:34:16 -07001374 }
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001375 std::string& paramString = std::get<1>(ret);
Jia, chunhui449f2162019-09-11 16:51:51 +08001376 std::vector<uint8_t> configData;
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001377 size_t count = 0;
1378 if (setSelector == 0)
Jia, chunhui449f2162019-09-11 16:51:51 +08001379 { // First chunk has only 14 bytes.
1380 configData.emplace_back(0); // encoding
1381 configData.emplace_back(paramString.length()); // string length
1382 count = std::min(paramString.length(), smallChunkSize);
1383 configData.resize(count + configDataOverhead);
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001384 std::copy_n(paramString.begin(), count,
Snehalatha Va5ae7722020-05-02 18:18:57 +00001385 configData.begin() + configDataOverhead); // 14 bytes chunk
1386
1387 // Append zero's to remaining bytes
1388 if (configData.size() < configParameterLength)
1389 {
1390 std::fill_n(std::back_inserter(configData),
1391 configParameterLength - configData.size(), 0x00);
1392 }
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001393 }
1394 else
Xo Wangf542e8b2017-08-09 15:34:16 -07001395 {
Jia, chunhui449f2162019-09-11 16:51:51 +08001396 size_t offset = (setSelector * fullChunkSize) - configDataOverhead;
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001397 if (offset >= paramString.length())
1398 {
1399 return ipmi::responseParmOutOfRange();
1400 }
Jia, chunhui449f2162019-09-11 16:51:51 +08001401 count = std::min(paramString.length() - offset, fullChunkSize);
1402 configData.resize(count);
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001403 std::copy_n(paramString.begin() + offset, count,
1404 configData.begin()); // 16 bytes chunk
Xo Wangf542e8b2017-08-09 15:34:16 -07001405 }
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001406 return ipmi::responseSuccess(paramRevision, setSelector, configData);
Xo Wangf542e8b2017-08-09 15:34:16 -07001407}
1408
Jia, chunhui449f2162019-09-11 16:51:51 +08001409ipmi::RspType<> ipmiAppSetSystemInfo(uint8_t paramSelector, uint8_t data1,
1410 std::vector<uint8_t> configData)
1411{
jayaprakash Mutyala3c5e4132020-04-27 23:00:05 +00001412 if (paramSelector >= invalidParamSelectorStart &&
1413 paramSelector <= invalidParamSelectorEnd)
1414 {
1415 return ipmi::responseInvalidFieldRequest();
1416 }
1417 if ((paramSelector >= oemCmdStart) && (paramSelector <= oemCmdEnd))
1418 {
1419 return ipmi::responseParmNotSupported();
1420 }
1421
Jia, chunhui449f2162019-09-11 16:51:51 +08001422 if (paramSelector == 0)
1423 {
1424 // attempt to set the 'set in progress' value (in parameter #0)
1425 // when not in the set complete state.
1426 if ((transferStatus != setComplete) && (data1 == setInProgress))
1427 {
1428 return ipmi::responseSetInProgressActive();
1429 }
1430 // only following 2 states are supported
1431 if (data1 > setInProgress)
1432 {
1433 phosphor::logging::log<phosphor::logging::level::ERR>(
1434 "illegal SetInProgress status");
1435 return ipmi::responseInvalidFieldRequest();
1436 }
1437
1438 transferStatus = data1 & progressMask;
1439 return ipmi::responseSuccess();
1440 }
1441
1442 if (configData.size() > configParameterLength)
1443 {
1444 return ipmi::responseInvalidFieldRequest();
1445 }
1446
jayaprakash Mutyala3c5e4132020-04-27 23:00:05 +00001447 // Append zero's to remaining bytes
1448 if (configData.size() < configParameterLength)
1449 {
1450 fill_n(back_inserter(configData),
1451 (configParameterLength - configData.size()), 0x00);
1452 }
1453
Jia, chunhui449f2162019-09-11 16:51:51 +08001454 if (!sysInfoParamStore)
1455 {
1456 sysInfoParamStore = std::make_unique<SysInfoParamStore>();
1457 sysInfoParamStore->update(IPMI_SYSINFO_SYSTEM_NAME,
1458 sysInfoReadSystemName);
1459 }
1460
1461 // lookup
1462 std::tuple<bool, std::string> ret =
1463 sysInfoParamStore->lookup(paramSelector);
1464 bool found = std::get<0>(ret);
1465 std::string& paramString = std::get<1>(ret);
1466 if (!found)
1467 {
1468 // parameter does not exist. Init new
1469 paramString = "";
1470 }
1471
1472 uint8_t setSelector = data1;
1473 size_t count = 0;
1474 if (setSelector == 0) // First chunk has only 14 bytes.
1475 {
1476 size_t stringLen = configData.at(1); // string length
1477 // maxBytesPerParamter is 256. It will always be greater than stringLen
1478 // (unit8_t) if maxBytes changes in future, then following line is
1479 // needed.
1480 // stringLen = std::min(stringLen, maxBytesPerParameter);
1481 count = std::min(stringLen, smallChunkSize);
1482 count = std::min(count, configData.size());
1483 paramString.resize(stringLen); // reserve space
1484 std::copy_n(configData.begin() + configDataOverhead, count,
1485 paramString.begin());
1486 }
1487 else
1488 {
1489 size_t offset = (setSelector * fullChunkSize) - configDataOverhead;
1490 if (offset >= paramString.length())
1491 {
1492 return ipmi::responseParmOutOfRange();
1493 }
1494 count = std::min(paramString.length() - offset, configData.size());
1495 std::copy_n(configData.begin(), count, paramString.begin() + offset);
1496 }
1497 sysInfoParamStore->update(paramSelector, paramString);
1498 return ipmi::responseSuccess();
1499}
1500
Yong Libd0503a2019-08-22 17:17:17 +08001501#ifdef ENABLE_I2C_WHITELIST_CHECK
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +05301502inline std::vector<uint8_t> convertStringToData(const std::string& command)
1503{
1504 std::istringstream iss(command);
1505 std::string token;
1506 std::vector<uint8_t> dataValue;
1507 while (std::getline(iss, token, ' '))
1508 {
1509 dataValue.emplace_back(
1510 static_cast<uint8_t>(std::stoul(token, nullptr, base_16)));
1511 }
1512 return dataValue;
1513}
1514
1515static bool populateI2CMasterWRWhitelist()
1516{
1517 nlohmann::json data = nullptr;
1518 std::ifstream jsonFile(i2cMasterWRWhitelistFile);
1519
1520 if (!jsonFile.good())
1521 {
1522 log<level::WARNING>("i2c white list file not found!",
1523 entry("FILE_NAME: %s", i2cMasterWRWhitelistFile));
1524 return false;
1525 }
1526
1527 try
1528 {
1529 data = nlohmann::json::parse(jsonFile, nullptr, false);
1530 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -05001531 catch (const nlohmann::json::parse_error& e)
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +05301532 {
1533 log<level::ERR>("Corrupted i2c white list config file",
1534 entry("FILE_NAME: %s", i2cMasterWRWhitelistFile),
1535 entry("MSG: %s", e.what()));
1536 return false;
1537 }
1538
1539 try
1540 {
1541 // Example JSON Structure format
1542 // "filters": [
1543 // {
1544 // "Description": "Allow full read - ignore first byte write value
1545 // for 0x40 to 0x4F",
1546 // "busId": "0x01",
1547 // "slaveAddr": "0x40",
1548 // "slaveAddrMask": "0x0F",
1549 // "command": "0x00",
1550 // "commandMask": "0xFF"
1551 // },
1552 // {
1553 // "Description": "Allow full read - first byte match 0x05 and
1554 // ignore second byte",
1555 // "busId": "0x01",
1556 // "slaveAddr": "0x57",
1557 // "slaveAddrMask": "0x00",
1558 // "command": "0x05 0x00",
1559 // "commandMask": "0x00 0xFF"
1560 // },]
1561
1562 nlohmann::json filters = data[filtersStr].get<nlohmann::json>();
1563 std::vector<i2cMasterWRWhitelist>& whitelist = getWRWhitelist();
1564 for (const auto& it : filters.items())
1565 {
1566 nlohmann::json filter = it.value();
1567 if (filter.is_null())
1568 {
1569 log<level::ERR>(
1570 "Corrupted I2C master write read whitelist config file",
1571 entry("FILE_NAME: %s", i2cMasterWRWhitelistFile));
1572 return false;
1573 }
1574 const std::vector<uint8_t>& writeData =
1575 convertStringToData(filter[cmdStr].get<std::string>());
1576 const std::vector<uint8_t>& writeDataMask =
1577 convertStringToData(filter[cmdMaskStr].get<std::string>());
1578 if (writeDataMask.size() != writeData.size())
1579 {
1580 log<level::ERR>("I2C master write read whitelist filter "
1581 "mismatch for command & mask size");
1582 return false;
1583 }
1584 whitelist.push_back(
1585 {static_cast<uint8_t>(std::stoul(
1586 filter[busIdStr].get<std::string>(), nullptr, base_16)),
1587 static_cast<uint8_t>(
1588 std::stoul(filter[slaveAddrStr].get<std::string>(),
1589 nullptr, base_16)),
1590 static_cast<uint8_t>(
1591 std::stoul(filter[slaveAddrMaskStr].get<std::string>(),
1592 nullptr, base_16)),
1593 writeData, writeDataMask});
1594 }
1595 if (whitelist.size() != filters.size())
1596 {
1597 log<level::ERR>(
1598 "I2C master write read whitelist filter size mismatch");
1599 return false;
1600 }
1601 }
Patrick Williamsa2ad2da2021-10-06 12:21:46 -05001602 catch (const std::exception& e)
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +05301603 {
1604 log<level::ERR>("I2C master write read whitelist unexpected exception",
1605 entry("ERROR=%s", e.what()));
1606 return false;
1607 }
1608 return true;
1609}
1610
1611static inline bool isWriteDataWhitelisted(const std::vector<uint8_t>& data,
1612 const std::vector<uint8_t>& dataMask,
1613 const std::vector<uint8_t>& writeData)
1614{
1615 std::vector<uint8_t> processedDataBuf(data.size());
1616 std::vector<uint8_t> processedReqBuf(dataMask.size());
1617 std::transform(writeData.begin(), writeData.end(), dataMask.begin(),
1618 processedReqBuf.begin(), std::bit_or<uint8_t>());
1619 std::transform(data.begin(), data.end(), dataMask.begin(),
1620 processedDataBuf.begin(), std::bit_or<uint8_t>());
1621
1622 return (processedDataBuf == processedReqBuf);
1623}
1624
1625static bool isCmdWhitelisted(uint8_t busId, uint8_t slaveAddr,
1626 std::vector<uint8_t>& writeData)
1627{
1628 std::vector<i2cMasterWRWhitelist>& whiteList = getWRWhitelist();
1629 for (const auto& wlEntry : whiteList)
1630 {
1631 if ((busId == wlEntry.busId) &&
1632 ((slaveAddr | wlEntry.slaveAddrMask) ==
1633 (wlEntry.slaveAddr | wlEntry.slaveAddrMask)))
1634 {
1635 const std::vector<uint8_t>& dataMask = wlEntry.dataMask;
1636 // Skip as no-match, if requested write data is more than the
1637 // write data mask size
1638 if (writeData.size() > dataMask.size())
1639 {
1640 continue;
1641 }
1642 if (isWriteDataWhitelisted(wlEntry.data, dataMask, writeData))
1643 {
1644 return true;
1645 }
1646 }
1647 }
1648 return false;
1649}
Yong Libd0503a2019-08-22 17:17:17 +08001650#else
1651static bool populateI2CMasterWRWhitelist()
1652{
1653 log<level::INFO>(
1654 "I2C_WHITELIST_CHECK is disabled, do not populate whitelist");
1655 return true;
1656}
1657#endif // ENABLE_I2C_WHITELIST_CHECK
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +05301658
1659/** @brief implements master write read IPMI command which can be used for
1660 * low-level I2C/SMBus write, read or write-read access
1661 * @param isPrivateBus -to indicate private bus usage
1662 * @param busId - bus id
1663 * @param channelNum - channel number
1664 * @param reserved - skip 1 bit
1665 * @param slaveAddr - slave address
1666 * @param read count - number of bytes to be read
1667 * @param writeData - data to be written
1668 *
1669 * @returns IPMI completion code plus response data
1670 * - readData - i2c response data
1671 */
1672ipmi::RspType<std::vector<uint8_t>>
Willy Tu11d68892022-01-20 10:37:34 -08001673 ipmiMasterWriteRead([[maybe_unused]] bool isPrivateBus, uint3_t busId,
1674 [[maybe_unused]] uint4_t channelNum, bool reserved,
1675 uint7_t slaveAddr, uint8_t readCount,
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +05301676 std::vector<uint8_t> writeData)
1677{
Jayaprakash Mutyalac2af98b2021-09-14 09:19:11 +00001678 if (reserved)
1679 {
1680 return ipmi::responseInvalidFieldRequest();
1681 }
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +05301682 if (readCount > maxIPMIWriteReadSize)
1683 {
1684 log<level::ERR>("Master write read command: Read count exceeds limit");
1685 return ipmi::responseParmOutOfRange();
1686 }
1687 const size_t writeCount = writeData.size();
1688 if (!readCount && !writeCount)
1689 {
1690 log<level::ERR>("Master write read command: Read & write count are 0");
1691 return ipmi::responseInvalidFieldRequest();
1692 }
Yong Libd0503a2019-08-22 17:17:17 +08001693#ifdef ENABLE_I2C_WHITELIST_CHECK
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +05301694 if (!isCmdWhitelisted(static_cast<uint8_t>(busId),
1695 static_cast<uint8_t>(slaveAddr), writeData))
1696 {
1697 log<level::ERR>("Master write read request blocked!",
1698 entry("BUS=%d", static_cast<uint8_t>(busId)),
1699 entry("ADDR=0x%x", static_cast<uint8_t>(slaveAddr)));
1700 return ipmi::responseInvalidFieldRequest();
1701 }
Yong Libd0503a2019-08-22 17:17:17 +08001702#endif // ENABLE_I2C_WHITELIST_CHECK
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +05301703 std::vector<uint8_t> readBuf(readCount);
1704 std::string i2cBus =
1705 "/dev/i2c-" + std::to_string(static_cast<uint8_t>(busId));
1706
Yong Li7dc4ac02019-08-23 17:44:32 +08001707 ipmi::Cc ret = ipmi::i2cWriteRead(i2cBus, static_cast<uint8_t>(slaveAddr),
1708 writeData, readBuf);
1709 if (ret != ipmi::ccSuccess)
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +05301710 {
Yong Li7dc4ac02019-08-23 17:44:32 +08001711 return ipmi::response(ret);
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +05301712 }
1713 return ipmi::responseSuccess(readBuf);
1714}
1715
Chris Austen6caf28b2015-10-13 12:40:40 -05001716void register_netfn_app_functions()
vishwabmcba0bd5f2015-09-30 16:50:23 +05301717{
Vernon Mauery86a50822019-03-25 13:11:36 -07001718 // <Get Device ID>
1719 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
1720 ipmi::app::cmdGetDeviceId, ipmi::Privilege::User,
1721 ipmiAppGetDeviceId);
1722
Tom05732372016-09-06 17:21:23 +05301723 // <Get BT Interface Capabilities>
Vernon Mauerycc99ba42019-03-25 13:40:11 -07001724 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
1725 ipmi::app::cmdGetBtIfaceCapabilities,
1726 ipmi::Privilege::User, ipmiAppGetBtCapabilities);
Chris Austen6caf28b2015-10-13 12:40:40 -05001727
Tom05732372016-09-06 17:21:23 +05301728 // <Reset Watchdog Timer>
Vernon Mauery11df4f62019-03-25 14:17:54 -07001729 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
1730 ipmi::app::cmdResetWatchdogTimer,
1731 ipmi::Privilege::Operator, ipmiAppResetWatchdogTimer);
Chris Austen6caf28b2015-10-13 12:40:40 -05001732
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001733 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
AppaRao Puli5a98ea62019-11-10 21:15:02 +05301734 ipmi::app::cmdGetSessionInfo, ipmi::Privilege::User,
1735 ipmiAppGetSessionInfo);
Rajashekar Gade Reddyf71444d2019-07-25 15:12:17 +00001736
Tom05732372016-09-06 17:21:23 +05301737 // <Set Watchdog Timer>
Deepak Kumar Sahucfae9482019-05-20 14:58:58 +00001738 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
1739 ipmi::app::cmdSetWatchdogTimer,
1740 ipmi::Privilege::Operator, ipmiSetWatchdogTimer);
Chris Austen6caf28b2015-10-13 12:40:40 -05001741
Rajashekar Gade Reddye7023922019-07-10 16:54:55 +00001742 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
1743 ipmi::app::cmdCloseSession, ipmi::Privilege::Callback,
1744 ipmiAppCloseSession);
1745
William A. Kennington III73f44512018-02-09 15:28:46 -08001746 // <Get Watchdog Timer>
Deepak Kumar Sahucfae9482019-05-20 14:58:58 +00001747 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
AppaRao Puli5a98ea62019-11-10 21:15:02 +05301748 ipmi::app::cmdGetWatchdogTimer, ipmi::Privilege::User,
1749 ipmiGetWatchdogTimer);
William A. Kennington III73f44512018-02-09 15:28:46 -08001750
Tom05732372016-09-06 17:21:23 +05301751 // <Get Self Test Results>
Vernon Maueryb84a5282019-03-25 13:39:03 -07001752 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
1753 ipmi::app::cmdGetSelfTestResults,
1754 ipmi::Privilege::User, ipmiAppGetSelfTestResults);
Nan Li41fa24a2016-11-10 20:12:37 +08001755
Tom05732372016-09-06 17:21:23 +05301756 // <Get Device GUID>
Vernon Mauery15541322019-03-25 13:33:03 -07001757 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
1758 ipmi::app::cmdGetDeviceGuid, ipmi::Privilege::User,
1759 ipmiAppGetDeviceGuid);
Adriana Kobylakd100ee52015-10-20 17:02:37 -05001760
Tom05732372016-09-06 17:21:23 +05301761 // <Set ACPI Power State>
Deepak Kumar Sahu520c1312019-05-17 18:14:09 +00001762 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
1763 ipmi::app::cmdSetAcpiPowerState,
1764 ipmi::Privilege::Admin, ipmiSetAcpiPowerState);
Yong Li18d77262018-10-09 01:59:45 +08001765 // <Get ACPI Power State>
Deepak Kumar Sahu4e6d2572019-05-07 19:53:37 +00001766 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
1767 ipmi::app::cmdGetAcpiPowerState,
AppaRao Puli5a98ea62019-11-10 21:15:02 +05301768 ipmi::Privilege::User, ipmiGetAcpiPowerState);
Yong Li18d77262018-10-09 01:59:45 +08001769
Richard Marian Thomaiyar84bf9be2019-04-26 22:59:16 +05301770 // Note: For security reason, this command will be registered only when
1771 // there are proper I2C Master write read whitelist
1772 if (populateI2CMasterWRWhitelist())
1773 {
1774 // Note: For security reasons, registering master write read as admin
1775 // privilege command, even though IPMI 2.0 specification allows it as
1776 // operator privilege.
1777 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
1778 ipmi::app::cmdMasterWriteRead,
1779 ipmi::Privilege::Admin, ipmiMasterWriteRead);
1780 }
1781
Marri Devender Rao5e007a52018-01-08 06:18:36 -06001782 // <Get System GUID Command>
Vernon Maueryb90a5322019-03-25 13:36:55 -07001783 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
1784 ipmi::app::cmdGetSystemGuid, ipmi::Privilege::User,
1785 ipmiAppGetSystemGuid);
Tom Joseph7cbe2282018-03-21 21:17:33 +05301786
1787 // <Get Channel Cipher Suites Command>
Ayushi Smriti5c3b72c2019-08-30 13:47:31 +00001788 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
1789 ipmi::app::cmdGetChannelCipherSuites,
Vernon Mauery79b4eea2019-11-07 09:51:39 -08001790 ipmi::Privilege::None, getChannelCipherSuites);
Vernon Maueryd2a57de2019-03-25 12:45:28 -07001791
Xo Wangf542e8b2017-08-09 15:34:16 -07001792 // <Get System Info Command>
Jia, chunhui98b43ba2019-09-05 15:54:23 +08001793 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
1794 ipmi::app::cmdGetSystemInfoParameters,
1795 ipmi::Privilege::User, ipmiAppGetSystemInfo);
Jia, chunhui449f2162019-09-11 16:51:51 +08001796 // <Set System Info Command>
1797 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
1798 ipmi::app::cmdSetSystemInfoParameters,
1799 ipmi::Privilege::Admin, ipmiAppSetSystemInfo);
vishwabmcba0bd5f2015-09-30 16:50:23 +05301800 return;
1801}