| Potin Lai | 5d21420 | 2023-01-16 18:11:49 +0800 | [diff] [blame] | 1 | #include "config.h" | 
|  | 2 |  | 
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 3 | #include <arpa/inet.h> | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 4 | #include <fcntl.h> | 
| Xo Wang | 8765133 | 2017-08-11 10:17:59 -0700 | [diff] [blame] | 5 | #include <limits.h> | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 6 | #include <linux/i2c-dev.h> | 
|  | 7 | #include <linux/i2c.h> | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 8 | #include <sys/ioctl.h> | 
|  | 9 | #include <sys/stat.h> | 
|  | 10 | #include <sys/types.h> | 
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 11 | #include <systemd/sd-bus.h> | 
| Xo Wang | 8765133 | 2017-08-11 10:17:59 -0700 | [diff] [blame] | 12 | #include <unistd.h> | 
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 13 |  | 
| Vernon Mauery | 0120b68 | 2019-03-25 13:08:54 -0700 | [diff] [blame] | 14 | #include <app/channel.hpp> | 
|  | 15 | #include <app/watchdog.hpp> | 
|  | 16 | #include <apphandler.hpp> | 
| Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 17 | #include <ipmid/api.hpp> | 
|  | 18 | #include <ipmid/sessiondef.hpp> | 
|  | 19 | #include <ipmid/sessionhelper.hpp> | 
|  | 20 | #include <ipmid/types.hpp> | 
|  | 21 | #include <ipmid/utils.hpp> | 
|  | 22 | #include <nlohmann/json.hpp> | 
|  | 23 | #include <phosphor-logging/elog-errors.hpp> | 
|  | 24 | #include <phosphor-logging/log.hpp> | 
|  | 25 | #include <sdbusplus/message/types.hpp> | 
|  | 26 | #include <sys_info_param.hpp> | 
|  | 27 | #include <xyz/openbmc_project/Common/error.hpp> | 
|  | 28 | #include <xyz/openbmc_project/Control/Power/ACPIPowerState/server.hpp> | 
|  | 29 | #include <xyz/openbmc_project/Software/Activation/server.hpp> | 
|  | 30 | #include <xyz/openbmc_project/Software/Version/server.hpp> | 
|  | 31 | #include <xyz/openbmc_project/State/BMC/server.hpp> | 
|  | 32 |  | 
|  | 33 | #include <algorithm> | 
| Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 34 | #include <array> | 
| Willy Tu | 886d684 | 2022-06-03 02:50:47 -0700 | [diff] [blame] | 35 | #include <charconv> | 
| Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 36 | #include <cstddef> | 
| Vernon Mauery | 0120b68 | 2019-03-25 13:08:54 -0700 | [diff] [blame] | 37 | #include <cstdint> | 
| Vernon Mauery | bdda800 | 2019-02-26 10:18:51 -0800 | [diff] [blame] | 38 | #include <filesystem> | 
| Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 39 | #include <fstream> | 
|  | 40 | #include <memory> | 
| Potin Lai | 5d21420 | 2023-01-16 18:11:49 +0800 | [diff] [blame] | 41 | #include <regex> | 
| Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 42 | #include <string> | 
| Willy Tu | 886d684 | 2022-06-03 02:50:47 -0700 | [diff] [blame] | 43 | #include <string_view> | 
| Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 44 | #include <tuple> | 
|  | 45 | #include <vector> | 
| Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 46 |  | 
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 47 | extern sd_bus* bus; | 
| vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 48 |  | 
| Alexander Amelkin | ba19c18 | 2018-09-04 15:49:36 +0300 | [diff] [blame] | 49 | constexpr auto bmc_state_interface = "xyz.openbmc_project.State.BMC"; | 
|  | 50 | constexpr auto bmc_state_property = "CurrentBMCState"; | 
| Marri Devender Rao | 5e007a5 | 2018-01-08 06:18:36 -0600 | [diff] [blame] | 51 |  | 
| Nagaraju Goruganti | 744398d | 2018-02-20 09:52:00 -0600 | [diff] [blame] | 52 | static constexpr auto redundancyIntf = | 
|  | 53 | "xyz.openbmc_project.Software.RedundancyPriority"; | 
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 54 | static constexpr auto versionIntf = "xyz.openbmc_project.Software.Version"; | 
| Nagaraju Goruganti | 744398d | 2018-02-20 09:52:00 -0600 | [diff] [blame] | 55 | static constexpr auto activationIntf = | 
|  | 56 | "xyz.openbmc_project.Software.Activation"; | 
|  | 57 | static constexpr auto softwareRoot = "/xyz/openbmc_project/software"; | 
|  | 58 |  | 
| Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 59 | void register_netfn_app_functions() __attribute__((constructor)); | 
| vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 60 |  | 
| Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 61 | using namespace phosphor::logging; | 
| Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 62 | using namespace sdbusplus::error::xyz::openbmc_project::common; | 
|  | 63 | using Version = sdbusplus::server::xyz::openbmc_project::software::Version; | 
| Nagaraju Goruganti | 744398d | 2018-02-20 09:52:00 -0600 | [diff] [blame] | 64 | using Activation = | 
| Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 65 | sdbusplus::server::xyz::openbmc_project::software::Activation; | 
|  | 66 | using BMC = sdbusplus::server::xyz::openbmc_project::state::BMC; | 
| Vernon Mauery | 185b9f8 | 2018-07-20 10:52:36 -0700 | [diff] [blame] | 67 | namespace fs = std::filesystem; | 
| Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 68 |  | 
| Yong Li | bd0503a | 2019-08-22 17:17:17 +0800 | [diff] [blame] | 69 | #ifdef ENABLE_I2C_WHITELIST_CHECK | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 70 | typedef struct | 
|  | 71 | { | 
|  | 72 | uint8_t busId; | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 73 | uint8_t targetAddr; | 
|  | 74 | uint8_t targetAddrMask; | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 75 | std::vector<uint8_t> data; | 
|  | 76 | std::vector<uint8_t> dataMask; | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 77 | } i2cControllerWRAllowlist; | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 78 |  | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 79 | static std::vector<i2cControllerWRAllowlist>& getWRAllowlist() | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 80 | { | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 81 | static std::vector<i2cControllerWRAllowlist> wrAllowlist; | 
|  | 82 | return wrAllowlist; | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 83 | } | 
|  | 84 |  | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 85 | static constexpr const char* i2cControllerWRAllowlistFile = | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 86 | "/usr/share/ipmi-providers/master_write_read_white_list.json"; | 
|  | 87 |  | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 88 | static constexpr const char* filtersStr = "filters"; | 
|  | 89 | static constexpr const char* busIdStr = "busId"; | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 90 | static constexpr const char* targetAddrStr = "slaveAddr"; | 
|  | 91 | static constexpr const char* targetAddrMaskStr = "slaveAddrMask"; | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 92 | static constexpr const char* cmdStr = "command"; | 
|  | 93 | static constexpr const char* cmdMaskStr = "commandMask"; | 
|  | 94 | static constexpr int base_16 = 16; | 
| Yong Li | bd0503a | 2019-08-22 17:17:17 +0800 | [diff] [blame] | 95 | #endif // ENABLE_I2C_WHITELIST_CHECK | 
| jayaprakash Mutyala | 3c5e413 | 2020-04-27 23:00:05 +0000 | [diff] [blame] | 96 | static constexpr uint8_t oemCmdStart = 192; | 
| jayaprakash Mutyala | 3c5e413 | 2020-04-27 23:00:05 +0000 | [diff] [blame] | 97 | static constexpr uint8_t invalidParamSelectorStart = 8; | 
|  | 98 | static constexpr uint8_t invalidParamSelectorEnd = 191; | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 99 |  | 
| Nagaraju Goruganti | 744398d | 2018-02-20 09:52:00 -0600 | [diff] [blame] | 100 | /** | 
|  | 101 | * @brief Returns the Version info from primary s/w object | 
|  | 102 | * | 
|  | 103 | * Get the Version info from the active s/w object which is having high | 
|  | 104 | * "Priority" value(a smaller number is a higher priority) and "Purpose" | 
|  | 105 | * is "BMC" from the list of all s/w objects those are implementing | 
|  | 106 | * RedundancyPriority interface from the given softwareRoot path. | 
|  | 107 | * | 
|  | 108 | * @return On success returns the Version info from primary s/w object. | 
|  | 109 | * | 
|  | 110 | */ | 
| Vernon Mauery | ea1c401 | 2019-05-24 13:26:16 -0700 | [diff] [blame] | 111 | std::string getActiveSoftwareVersionInfo(ipmi::Context::ptr ctx) | 
| Nagaraju Goruganti | 744398d | 2018-02-20 09:52:00 -0600 | [diff] [blame] | 112 | { | 
| Nagaraju Goruganti | 744398d | 2018-02-20 09:52:00 -0600 | [diff] [blame] | 113 | std::string revision{}; | 
| Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 114 | ipmi::ObjectTree objectTree; | 
|  | 115 | try | 
| Nagaraju Goruganti | 744398d | 2018-02-20 09:52:00 -0600 | [diff] [blame] | 116 | { | 
| Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 117 | objectTree = ipmi::getAllDbusObjects(*ctx->bus, softwareRoot, | 
|  | 118 | redundancyIntf); | 
| Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 119 | } | 
| Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 120 | catch (const sdbusplus::exception_t& e) | 
| Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 121 | { | 
|  | 122 | log<level::ERR>("Failed to fetch redundancy object from dbus", | 
|  | 123 | entry("INTERFACE=%s", redundancyIntf), | 
|  | 124 | entry("ERRMSG=%s", e.what())); | 
| Nagaraju Goruganti | 744398d | 2018-02-20 09:52:00 -0600 | [diff] [blame] | 125 | elog<InternalFailure>(); | 
|  | 126 | } | 
|  | 127 |  | 
|  | 128 | auto objectFound = false; | 
|  | 129 | for (auto& softObject : objectTree) | 
|  | 130 | { | 
| Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 131 | auto service = ipmi::getService(*ctx->bus, redundancyIntf, | 
|  | 132 | softObject.first); | 
|  | 133 | auto objValueTree = ipmi::getManagedObjects(*ctx->bus, service, | 
|  | 134 | softwareRoot); | 
| Nagaraju Goruganti | 744398d | 2018-02-20 09:52:00 -0600 | [diff] [blame] | 135 |  | 
|  | 136 | auto minPriority = 0xFF; | 
|  | 137 | for (const auto& objIter : objValueTree) | 
|  | 138 | { | 
|  | 139 | try | 
|  | 140 | { | 
|  | 141 | auto& intfMap = objIter.second; | 
|  | 142 | auto& redundancyPriorityProps = intfMap.at(redundancyIntf); | 
|  | 143 | auto& versionProps = intfMap.at(versionIntf); | 
|  | 144 | auto& activationProps = intfMap.at(activationIntf); | 
| Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 145 | auto priority = | 
|  | 146 | std::get<uint8_t>(redundancyPriorityProps.at("Priority")); | 
| William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 147 | auto purpose = | 
| Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 148 | std::get<std::string>(versionProps.at("Purpose")); | 
|  | 149 | auto activation = | 
|  | 150 | std::get<std::string>(activationProps.at("Activation")); | 
| William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 151 | auto version = | 
| Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 152 | std::get<std::string>(versionProps.at("Version")); | 
| Nagaraju Goruganti | 744398d | 2018-02-20 09:52:00 -0600 | [diff] [blame] | 153 | if ((Version::convertVersionPurposeFromString(purpose) == | 
|  | 154 | Version::VersionPurpose::BMC) && | 
|  | 155 | (Activation::convertActivationsFromString(activation) == | 
|  | 156 | Activation::Activations::Active)) | 
|  | 157 | { | 
|  | 158 | if (priority < minPriority) | 
|  | 159 | { | 
|  | 160 | minPriority = priority; | 
|  | 161 | objectFound = true; | 
|  | 162 | revision = std::move(version); | 
|  | 163 | } | 
|  | 164 | } | 
|  | 165 | } | 
|  | 166 | catch (const std::exception& e) | 
|  | 167 | { | 
|  | 168 | log<level::ERR>(e.what()); | 
|  | 169 | } | 
|  | 170 | } | 
|  | 171 | } | 
|  | 172 |  | 
|  | 173 | if (!objectFound) | 
|  | 174 | { | 
|  | 175 | log<level::ERR>("Could not found an BMC software Object"); | 
|  | 176 | elog<InternalFailure>(); | 
|  | 177 | } | 
|  | 178 |  | 
|  | 179 | return revision; | 
|  | 180 | } | 
|  | 181 |  | 
| Alexander Amelkin | ba19c18 | 2018-09-04 15:49:36 +0300 | [diff] [blame] | 182 | bool getCurrentBmcState() | 
|  | 183 | { | 
| Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 184 | sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()}; | 
| Alexander Amelkin | ba19c18 | 2018-09-04 15:49:36 +0300 | [diff] [blame] | 185 |  | 
|  | 186 | // Get the Inventory object implementing the BMC interface | 
| Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 187 | ipmi::DbusObjectInfo bmcObject = ipmi::getDbusObject(bus, | 
|  | 188 | bmc_state_interface); | 
|  | 189 | auto variant = ipmi::getDbusProperty(bus, bmcObject.second, bmcObject.first, | 
|  | 190 | bmc_state_interface, | 
|  | 191 | bmc_state_property); | 
| Alexander Amelkin | ba19c18 | 2018-09-04 15:49:36 +0300 | [diff] [blame] | 192 |  | 
| Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 193 | return std::holds_alternative<std::string>(variant) && | 
|  | 194 | BMC::convertBMCStateFromString(std::get<std::string>(variant)) == | 
|  | 195 | BMC::BMCState::Ready; | 
| Alexander Amelkin | ba19c18 | 2018-09-04 15:49:36 +0300 | [diff] [blame] | 196 | } | 
|  | 197 |  | 
| Patrick Venture | 94930a1 | 2019-04-30 10:01:58 -0700 | [diff] [blame] | 198 | bool getCurrentBmcStateWithFallback(const bool fallbackAvailability) | 
|  | 199 | { | 
|  | 200 | try | 
|  | 201 | { | 
|  | 202 | return getCurrentBmcState(); | 
|  | 203 | } | 
|  | 204 | catch (...) | 
|  | 205 | { | 
|  | 206 | // Nothing provided the BMC interface, therefore return whatever was | 
|  | 207 | // configured as the default. | 
|  | 208 | return fallbackAvailability; | 
|  | 209 | } | 
|  | 210 | } | 
|  | 211 |  | 
| Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 212 | namespace acpi_state | 
|  | 213 | { | 
| Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 214 | using namespace sdbusplus::server::xyz::openbmc_project::control::power; | 
| Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 215 |  | 
|  | 216 | const static constexpr char* acpiObjPath = | 
|  | 217 | "/xyz/openbmc_project/control/host0/acpi_power_state"; | 
|  | 218 | const static constexpr char* acpiInterface = | 
|  | 219 | "xyz.openbmc_project.Control.Power.ACPIPowerState"; | 
|  | 220 | const static constexpr char* sysACPIProp = "SysACPIStatus"; | 
|  | 221 | const static constexpr char* devACPIProp = "DevACPIStatus"; | 
|  | 222 |  | 
|  | 223 | enum class PowerStateType : uint8_t | 
|  | 224 | { | 
|  | 225 | sysPowerState = 0x00, | 
|  | 226 | devPowerState = 0x01, | 
|  | 227 | }; | 
|  | 228 |  | 
|  | 229 | // Defined in 20.6 of ipmi doc | 
|  | 230 | enum class PowerState : uint8_t | 
|  | 231 | { | 
|  | 232 | s0G0D0 = 0x00, | 
|  | 233 | s1D1 = 0x01, | 
|  | 234 | s2D2 = 0x02, | 
|  | 235 | s3D3 = 0x03, | 
|  | 236 | s4 = 0x04, | 
|  | 237 | s5G2 = 0x05, | 
|  | 238 | s4S5 = 0x06, | 
|  | 239 | g3 = 0x07, | 
|  | 240 | sleep = 0x08, | 
|  | 241 | g1Sleep = 0x09, | 
|  | 242 | override = 0x0a, | 
|  | 243 | legacyOn = 0x20, | 
|  | 244 | legacyOff = 0x21, | 
|  | 245 | unknown = 0x2a, | 
|  | 246 | noChange = 0x7f, | 
|  | 247 | }; | 
|  | 248 |  | 
|  | 249 | static constexpr uint8_t stateChanged = 0x80; | 
|  | 250 |  | 
| Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 251 | std::map<ACPIPowerState::ACPI, PowerState> dbusToIPMI = { | 
|  | 252 | {ACPIPowerState::ACPI::S0_G0_D0, PowerState::s0G0D0}, | 
|  | 253 | {ACPIPowerState::ACPI::S1_D1, PowerState::s1D1}, | 
|  | 254 | {ACPIPowerState::ACPI::S2_D2, PowerState::s2D2}, | 
|  | 255 | {ACPIPowerState::ACPI::S3_D3, PowerState::s3D3}, | 
|  | 256 | {ACPIPowerState::ACPI::S4, PowerState::s4}, | 
|  | 257 | {ACPIPowerState::ACPI::S5_G2, PowerState::s5G2}, | 
|  | 258 | {ACPIPowerState::ACPI::S4_S5, PowerState::s4S5}, | 
|  | 259 | {ACPIPowerState::ACPI::G3, PowerState::g3}, | 
|  | 260 | {ACPIPowerState::ACPI::SLEEP, PowerState::sleep}, | 
|  | 261 | {ACPIPowerState::ACPI::G1_SLEEP, PowerState::g1Sleep}, | 
|  | 262 | {ACPIPowerState::ACPI::OVERRIDE, PowerState::override}, | 
|  | 263 | {ACPIPowerState::ACPI::LEGACY_ON, PowerState::legacyOn}, | 
|  | 264 | {ACPIPowerState::ACPI::LEGACY_OFF, PowerState::legacyOff}, | 
|  | 265 | {ACPIPowerState::ACPI::Unknown, PowerState::unknown}}; | 
|  | 266 |  | 
|  | 267 | bool isValidACPIState(acpi_state::PowerStateType type, uint8_t state) | 
|  | 268 | { | 
|  | 269 | if (type == acpi_state::PowerStateType::sysPowerState) | 
|  | 270 | { | 
|  | 271 | if ((state <= static_cast<uint8_t>(acpi_state::PowerState::override)) || | 
|  | 272 | (state == static_cast<uint8_t>(acpi_state::PowerState::legacyOn)) || | 
|  | 273 | (state == | 
|  | 274 | static_cast<uint8_t>(acpi_state::PowerState::legacyOff)) || | 
|  | 275 | (state == static_cast<uint8_t>(acpi_state::PowerState::unknown)) || | 
|  | 276 | (state == static_cast<uint8_t>(acpi_state::PowerState::noChange))) | 
|  | 277 | { | 
|  | 278 | return true; | 
|  | 279 | } | 
|  | 280 | else | 
|  | 281 | { | 
|  | 282 | return false; | 
|  | 283 | } | 
|  | 284 | } | 
|  | 285 | else if (type == acpi_state::PowerStateType::devPowerState) | 
|  | 286 | { | 
|  | 287 | if ((state <= static_cast<uint8_t>(acpi_state::PowerState::s3D3)) || | 
|  | 288 | (state == static_cast<uint8_t>(acpi_state::PowerState::unknown)) || | 
|  | 289 | (state == static_cast<uint8_t>(acpi_state::PowerState::noChange))) | 
|  | 290 | { | 
|  | 291 | return true; | 
|  | 292 | } | 
|  | 293 | else | 
|  | 294 | { | 
|  | 295 | return false; | 
|  | 296 | } | 
|  | 297 | } | 
|  | 298 | else | 
|  | 299 | { | 
|  | 300 | return false; | 
|  | 301 | } | 
|  | 302 | return false; | 
|  | 303 | } | 
|  | 304 | } // namespace acpi_state | 
|  | 305 |  | 
| Deepak Kumar Sahu | 520c131 | 2019-05-17 18:14:09 +0000 | [diff] [blame] | 306 | /** @brief implements Set ACPI Power State command | 
|  | 307 | * @param sysAcpiState - ACPI system power state to set | 
|  | 308 | * @param devAcpiState - ACPI device power state to set | 
|  | 309 | * | 
|  | 310 | * @return IPMI completion code on success | 
|  | 311 | **/ | 
|  | 312 | ipmi::RspType<> ipmiSetAcpiPowerState(uint8_t sysAcpiState, | 
|  | 313 | uint8_t devAcpiState) | 
| Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 314 | { | 
| Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 315 | auto s = static_cast<uint8_t>(acpi_state::PowerState::unknown); | 
| Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 316 |  | 
| Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 317 | sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()}; | 
| Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 318 |  | 
|  | 319 | auto value = acpi_state::ACPIPowerState::ACPI::Unknown; | 
|  | 320 |  | 
| Deepak Kumar Sahu | 520c131 | 2019-05-17 18:14:09 +0000 | [diff] [blame] | 321 | if (sysAcpiState & acpi_state::stateChanged) | 
| Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 322 | { | 
|  | 323 | // set system power state | 
| Deepak Kumar Sahu | 520c131 | 2019-05-17 18:14:09 +0000 | [diff] [blame] | 324 | s = sysAcpiState & ~acpi_state::stateChanged; | 
| Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 325 |  | 
|  | 326 | if (!acpi_state::isValidACPIState( | 
|  | 327 | acpi_state::PowerStateType::sysPowerState, s)) | 
|  | 328 | { | 
|  | 329 | log<level::ERR>("set_acpi_power sys invalid input", | 
|  | 330 | entry("S=%x", s)); | 
| Deepak Kumar Sahu | 520c131 | 2019-05-17 18:14:09 +0000 | [diff] [blame] | 331 | return ipmi::responseParmOutOfRange(); | 
| Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 332 | } | 
|  | 333 |  | 
|  | 334 | // valid input | 
|  | 335 | if (s == static_cast<uint8_t>(acpi_state::PowerState::noChange)) | 
|  | 336 | { | 
|  | 337 | log<level::DEBUG>("No change for system power state"); | 
|  | 338 | } | 
|  | 339 | else | 
|  | 340 | { | 
| Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 341 | auto found = std::find_if(acpi_state::dbusToIPMI.begin(), | 
|  | 342 | acpi_state::dbusToIPMI.end(), | 
|  | 343 | [&s](const auto& iter) { | 
|  | 344 | return (static_cast<uint8_t>(iter.second) == s); | 
|  | 345 | }); | 
| Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 346 |  | 
|  | 347 | value = found->first; | 
|  | 348 |  | 
|  | 349 | try | 
|  | 350 | { | 
|  | 351 | auto acpiObject = | 
|  | 352 | ipmi::getDbusObject(bus, acpi_state::acpiInterface); | 
|  | 353 | ipmi::setDbusProperty(bus, acpiObject.second, acpiObject.first, | 
|  | 354 | acpi_state::acpiInterface, | 
|  | 355 | acpi_state::sysACPIProp, | 
|  | 356 | convertForMessage(value)); | 
|  | 357 | } | 
|  | 358 | catch (const InternalFailure& e) | 
|  | 359 | { | 
|  | 360 | log<level::ERR>("Failed in set ACPI system property", | 
|  | 361 | entry("EXCEPTION=%s", e.what())); | 
| Deepak Kumar Sahu | 520c131 | 2019-05-17 18:14:09 +0000 | [diff] [blame] | 362 | return ipmi::responseUnspecifiedError(); | 
| Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 363 | } | 
|  | 364 | } | 
|  | 365 | } | 
|  | 366 | else | 
|  | 367 | { | 
|  | 368 | log<level::DEBUG>("Do not change system power state"); | 
|  | 369 | } | 
|  | 370 |  | 
| Deepak Kumar Sahu | 520c131 | 2019-05-17 18:14:09 +0000 | [diff] [blame] | 371 | if (devAcpiState & acpi_state::stateChanged) | 
| Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 372 | { | 
|  | 373 | // set device power state | 
| Deepak Kumar Sahu | 520c131 | 2019-05-17 18:14:09 +0000 | [diff] [blame] | 374 | s = devAcpiState & ~acpi_state::stateChanged; | 
| Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 375 | if (!acpi_state::isValidACPIState( | 
|  | 376 | acpi_state::PowerStateType::devPowerState, s)) | 
|  | 377 | { | 
|  | 378 | log<level::ERR>("set_acpi_power dev invalid input", | 
|  | 379 | entry("S=%x", s)); | 
| Deepak Kumar Sahu | 520c131 | 2019-05-17 18:14:09 +0000 | [diff] [blame] | 380 | return ipmi::responseParmOutOfRange(); | 
| Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 381 | } | 
|  | 382 |  | 
|  | 383 | // valid input | 
|  | 384 | if (s == static_cast<uint8_t>(acpi_state::PowerState::noChange)) | 
|  | 385 | { | 
|  | 386 | log<level::DEBUG>("No change for device power state"); | 
|  | 387 | } | 
|  | 388 | else | 
|  | 389 | { | 
| Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 390 | auto found = std::find_if(acpi_state::dbusToIPMI.begin(), | 
|  | 391 | acpi_state::dbusToIPMI.end(), | 
|  | 392 | [&s](const auto& iter) { | 
|  | 393 | return (static_cast<uint8_t>(iter.second) == s); | 
|  | 394 | }); | 
| Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 395 |  | 
|  | 396 | value = found->first; | 
|  | 397 |  | 
|  | 398 | try | 
|  | 399 | { | 
|  | 400 | auto acpiObject = | 
|  | 401 | ipmi::getDbusObject(bus, acpi_state::acpiInterface); | 
|  | 402 | ipmi::setDbusProperty(bus, acpiObject.second, acpiObject.first, | 
|  | 403 | acpi_state::acpiInterface, | 
|  | 404 | acpi_state::devACPIProp, | 
|  | 405 | convertForMessage(value)); | 
|  | 406 | } | 
|  | 407 | catch (const InternalFailure& e) | 
|  | 408 | { | 
|  | 409 | log<level::ERR>("Failed in set ACPI device property", | 
|  | 410 | entry("EXCEPTION=%s", e.what())); | 
| Deepak Kumar Sahu | 520c131 | 2019-05-17 18:14:09 +0000 | [diff] [blame] | 411 | return ipmi::responseUnspecifiedError(); | 
| Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 412 | } | 
|  | 413 | } | 
|  | 414 | } | 
|  | 415 | else | 
|  | 416 | { | 
|  | 417 | log<level::DEBUG>("Do not change device power state"); | 
|  | 418 | } | 
| Deepak Kumar Sahu | 520c131 | 2019-05-17 18:14:09 +0000 | [diff] [blame] | 419 | return ipmi::responseSuccess(); | 
| Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 420 | } | 
|  | 421 |  | 
| Deepak Kumar Sahu | 4e6d257 | 2019-05-07 19:53:37 +0000 | [diff] [blame] | 422 | /** | 
|  | 423 | *  @brief implements the get ACPI power state command | 
|  | 424 | * | 
|  | 425 | *  @return IPMI completion code plus response data on success. | 
|  | 426 | *   -  ACPI system power state | 
|  | 427 | *   -  ACPI device power state | 
|  | 428 | **/ | 
|  | 429 | ipmi::RspType<uint8_t, // acpiSystemPowerState | 
|  | 430 | uint8_t  // acpiDevicePowerState | 
|  | 431 | > | 
|  | 432 | ipmiGetAcpiPowerState() | 
| Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 433 | { | 
| Deepak Kumar Sahu | 4e6d257 | 2019-05-07 19:53:37 +0000 | [diff] [blame] | 434 | uint8_t sysAcpiState; | 
|  | 435 | uint8_t devAcpiState; | 
| Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 436 |  | 
| Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 437 | sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()}; | 
| Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 438 |  | 
| Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 439 | try | 
|  | 440 | { | 
|  | 441 | auto acpiObject = ipmi::getDbusObject(bus, acpi_state::acpiInterface); | 
|  | 442 |  | 
|  | 443 | auto sysACPIVal = ipmi::getDbusProperty( | 
|  | 444 | bus, acpiObject.second, acpiObject.first, acpi_state::acpiInterface, | 
|  | 445 | acpi_state::sysACPIProp); | 
|  | 446 | auto sysACPI = acpi_state::ACPIPowerState::convertACPIFromString( | 
| Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 447 | std::get<std::string>(sysACPIVal)); | 
| Deepak Kumar Sahu | 4e6d257 | 2019-05-07 19:53:37 +0000 | [diff] [blame] | 448 | sysAcpiState = static_cast<uint8_t>(acpi_state::dbusToIPMI.at(sysACPI)); | 
| Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 449 |  | 
|  | 450 | auto devACPIVal = ipmi::getDbusProperty( | 
|  | 451 | bus, acpiObject.second, acpiObject.first, acpi_state::acpiInterface, | 
|  | 452 | acpi_state::devACPIProp); | 
|  | 453 | auto devACPI = acpi_state::ACPIPowerState::convertACPIFromString( | 
| Vernon Mauery | f442e11 | 2019-04-09 11:44:36 -0700 | [diff] [blame] | 454 | std::get<std::string>(devACPIVal)); | 
| Deepak Kumar Sahu | 4e6d257 | 2019-05-07 19:53:37 +0000 | [diff] [blame] | 455 | devAcpiState = static_cast<uint8_t>(acpi_state::dbusToIPMI.at(devACPI)); | 
| Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 456 | } | 
|  | 457 | catch (const InternalFailure& e) | 
|  | 458 | { | 
| Deepak Kumar Sahu | 4e6d257 | 2019-05-07 19:53:37 +0000 | [diff] [blame] | 459 | return ipmi::responseUnspecifiedError(); | 
| Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 460 | } | 
| Deepak Kumar Sahu | 4e6d257 | 2019-05-07 19:53:37 +0000 | [diff] [blame] | 461 |  | 
|  | 462 | return ipmi::responseSuccess(sysAcpiState, devAcpiState); | 
| Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 463 | } | 
|  | 464 |  | 
| Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 465 | typedef struct | 
|  | 466 | { | 
|  | 467 | char major; | 
|  | 468 | char minor; | 
| Potin Lai | c7c5592 | 2023-02-16 10:33:55 +0800 | [diff] [blame] | 469 | uint8_t aux[4]; | 
| Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 470 | } Revision; | 
| Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 471 |  | 
| Potin Lai | 5d21420 | 2023-01-16 18:11:49 +0800 | [diff] [blame] | 472 | /* Use regular expression searching matched pattern X.Y, and convert it to  */ | 
|  | 473 | /* Major (X) and Minor (Y) version.                                         */ | 
|  | 474 | /* Example:                                                                 */ | 
|  | 475 | /* version = 2.14.0-dev                                                     */ | 
|  | 476 | /*           ^ ^                                                            */ | 
|  | 477 | /*           | |---------------- Minor                                      */ | 
|  | 478 | /*           |------------------ Major                                      */ | 
|  | 479 | /*                                                                          */ | 
| Potin Lai | c7c5592 | 2023-02-16 10:33:55 +0800 | [diff] [blame] | 480 | /* Default regex string only tries to match Major and Minor version.        */ | 
|  | 481 | /*                                                                          */ | 
|  | 482 | /* To match more firmware version info, platforms need to define it own     */ | 
|  | 483 | /* regex string to match more strings, and assign correct mapping index in  */ | 
|  | 484 | /* matches array.                                                           */ | 
|  | 485 | /*                                                                          */ | 
|  | 486 | /* matches[0]: matched index for major ver                                  */ | 
|  | 487 | /* matches[1]: matched index for minor ver                                  */ | 
|  | 488 | /* matches[2]: matched index for aux[0] (set 0 to skip)                     */ | 
|  | 489 | /* matches[3]: matched index for aux[1] (set 0 to skip)                     */ | 
|  | 490 | /* matches[4]: matched index for aux[2] (set 0 to skip)                     */ | 
|  | 491 | /* matches[5]: matched index for aux[3] (set 0 to skip)                     */ | 
|  | 492 | /* Example:                                                                 */ | 
|  | 493 | /* regex = "([\d]+).([\d]+).([\d]+)-dev-([\d]+)-g([0-9a-fA-F]{2})           */ | 
|  | 494 | /*          ([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})"               */ | 
|  | 495 | /* matches = {1,2,5,6,7,8}                                                  */ | 
|  | 496 | /* version = 2.14.0-dev-750-g37a7c5ad1-dirty                                */ | 
|  | 497 | /*           ^ ^  ^     ^    ^ ^ ^ ^                                        */ | 
|  | 498 | /*           | |  |     |    | | | |                                        */ | 
|  | 499 | /*           | |  |     |    | | | |-- Aux byte 3 (0xAD), index 8           */ | 
|  | 500 | /*           | |  |     |    | | |---- Aux byte 2 (0xC5), index 7           */ | 
|  | 501 | /*           | |  |     |    | |------ Aux byte 1 (0xA7), index 6           */ | 
|  | 502 | /*           | |  |     |    |-------- Aux byte 0 (0x37), index 5           */ | 
|  | 503 | /*           | |  |     |------------- Not used, index 4                    */ | 
|  | 504 | /*           | |  |------------------- Not used, index 3                    */ | 
|  | 505 | /*           | |---------------------- Minor (14), index 2                  */ | 
|  | 506 | /*           |------------------------ Major (2), index 1                   */ | 
| Potin Lai | 5d21420 | 2023-01-16 18:11:49 +0800 | [diff] [blame] | 507 | int convertVersion(std::string s, Revision& rev) | 
| Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 508 | { | 
| Potin Lai | c7c5592 | 2023-02-16 10:33:55 +0800 | [diff] [blame] | 509 | static const std::vector<size_t> matches = { | 
|  | 510 | MAJOR_MATCH_INDEX, MINOR_MATCH_INDEX, AUX_0_MATCH_INDEX, | 
|  | 511 | AUX_1_MATCH_INDEX, AUX_2_MATCH_INDEX, AUX_3_MATCH_INDEX}; | 
| Potin Lai | 5d21420 | 2023-01-16 18:11:49 +0800 | [diff] [blame] | 512 | std::regex fw_regex(FW_VER_REGEX); | 
|  | 513 | std::smatch m; | 
|  | 514 | Revision r = {0}; | 
|  | 515 | size_t val; | 
| Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 516 |  | 
| Potin Lai | dcde04e | 2023-03-16 18:44:15 +0800 | [diff] [blame] | 517 | if (std::regex_search(s, m, fw_regex)) | 
| Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 518 | { | 
| Potin Lai | c7c5592 | 2023-02-16 10:33:55 +0800 | [diff] [blame] | 519 | if (m.size() < *std::max_element(matches.begin(), matches.end())) | 
|  | 520 | { // max index higher than match count | 
| Potin Lai | dcde04e | 2023-03-16 18:44:15 +0800 | [diff] [blame] | 521 | return -1; | 
|  | 522 | } | 
|  | 523 |  | 
| Potin Lai | 5d21420 | 2023-01-16 18:11:49 +0800 | [diff] [blame] | 524 | // convert major | 
|  | 525 | { | 
| Potin Lai | c7c5592 | 2023-02-16 10:33:55 +0800 | [diff] [blame] | 526 | std::string_view str = m[matches[0]].str(); | 
| Potin Lai | 5d21420 | 2023-01-16 18:11:49 +0800 | [diff] [blame] | 527 | auto [ptr, ec]{std::from_chars(str.begin(), str.end(), val)}; | 
|  | 528 | if (ec != std::errc() || ptr != str.begin() + str.size()) | 
|  | 529 | { // failed to convert major string | 
| Potin Lai | dcde04e | 2023-03-16 18:44:15 +0800 | [diff] [blame] | 530 | return -1; | 
| Potin Lai | 5d21420 | 2023-01-16 18:11:49 +0800 | [diff] [blame] | 531 | } | 
| Potin Lai | 058e291 | 2023-09-07 10:16:38 +0800 | [diff] [blame] | 532 |  | 
|  | 533 | if (val >= 2000) | 
|  | 534 | { // For the platforms use year as major version, it would expect to | 
|  | 535 | // have major version between 0 - 99. If the major version is | 
|  | 536 | // greater than or equal to 2000, it is treated as a year and | 
|  | 537 | // converted to 0 - 99. | 
|  | 538 | r.major = val % 100; | 
|  | 539 | } | 
|  | 540 | else | 
|  | 541 | { | 
|  | 542 | r.major = val & 0x7F; | 
|  | 543 | } | 
| Potin Lai | 5d21420 | 2023-01-16 18:11:49 +0800 | [diff] [blame] | 544 | } | 
|  | 545 |  | 
|  | 546 | // convert minor | 
|  | 547 | { | 
| Potin Lai | c7c5592 | 2023-02-16 10:33:55 +0800 | [diff] [blame] | 548 | std::string_view str = m[matches[1]].str(); | 
| Potin Lai | 5d21420 | 2023-01-16 18:11:49 +0800 | [diff] [blame] | 549 | auto [ptr, ec]{std::from_chars(str.begin(), str.end(), val)}; | 
|  | 550 | if (ec != std::errc() || ptr != str.begin() + str.size()) | 
|  | 551 | { // failed to convert minor string | 
| Potin Lai | dcde04e | 2023-03-16 18:44:15 +0800 | [diff] [blame] | 552 | return -1; | 
| Potin Lai | 5d21420 | 2023-01-16 18:11:49 +0800 | [diff] [blame] | 553 | } | 
|  | 554 | r.minor = val & 0xFF; | 
|  | 555 | } | 
|  | 556 |  | 
| Potin Lai | c7c5592 | 2023-02-16 10:33:55 +0800 | [diff] [blame] | 557 | // convert aux bytes | 
|  | 558 | { | 
|  | 559 | size_t i; | 
|  | 560 | for (i = 0; i < 4; i++) | 
|  | 561 | { | 
|  | 562 | if (matches[i + 2] == 0) | 
|  | 563 | { | 
|  | 564 | continue; | 
|  | 565 | } | 
|  | 566 |  | 
|  | 567 | std::string_view str = m[matches[i + 2]].str(); | 
|  | 568 | auto [ptr, | 
|  | 569 | ec]{std::from_chars(str.begin(), str.end(), val, 16)}; | 
|  | 570 | if (ec != std::errc() || ptr != str.begin() + str.size()) | 
|  | 571 | { // failed to convert aux byte string | 
|  | 572 | break; | 
|  | 573 | } | 
|  | 574 |  | 
|  | 575 | r.aux[i] = val & 0xFF; | 
|  | 576 | } | 
|  | 577 |  | 
|  | 578 | if (i != 4) | 
|  | 579 | { // something wrong durign converting aux bytes | 
|  | 580 | return -1; | 
|  | 581 | } | 
|  | 582 | } | 
|  | 583 |  | 
| Potin Lai | 5d21420 | 2023-01-16 18:11:49 +0800 | [diff] [blame] | 584 | // all matched | 
|  | 585 | rev = r; | 
|  | 586 | return 0; | 
| Chris Austen | 176c965 | 2016-04-30 16:32:17 -0500 | [diff] [blame] | 587 | } | 
| Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 588 |  | 
| Potin Lai | 5d21420 | 2023-01-16 18:11:49 +0800 | [diff] [blame] | 589 | return -1; | 
| Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 590 | } | 
|  | 591 |  | 
| Vernon Mauery | ea1c401 | 2019-05-24 13:26:16 -0700 | [diff] [blame] | 592 | /* @brief: Implement the Get Device ID IPMI command per the IPMI spec | 
|  | 593 | *  @param[in] ctx - shared_ptr to an IPMI context struct | 
|  | 594 | * | 
|  | 595 | *  @returns IPMI completion code plus response data | 
|  | 596 | *   - Device ID (manufacturer defined) | 
|  | 597 | *   - Device revision[4 bits]; reserved[3 bits]; SDR support[1 bit] | 
|  | 598 | *   - FW revision major[7 bits] (binary encoded); available[1 bit] | 
|  | 599 | *   - FW Revision minor (BCD encoded) | 
|  | 600 | *   - IPMI version (0x02 for IPMI 2.0) | 
|  | 601 | *   - device support (bitfield of supported options) | 
|  | 602 | *   - MFG IANA ID (3 bytes) | 
|  | 603 | *   - product ID (2 bytes) | 
|  | 604 | *   - AUX info (4 bytes) | 
|  | 605 | */ | 
|  | 606 | ipmi::RspType<uint8_t,  // Device ID | 
|  | 607 | uint8_t,  // Device Revision | 
|  | 608 | uint8_t,  // Firmware Revision Major | 
|  | 609 | uint8_t,  // Firmware Revision minor | 
|  | 610 | uint8_t,  // IPMI version | 
|  | 611 | uint8_t,  // Additional device support | 
|  | 612 | uint24_t, // MFG ID | 
|  | 613 | uint16_t, // Product ID | 
|  | 614 | uint32_t  // AUX info | 
|  | 615 | > | 
| Willy Tu | 11d6889 | 2022-01-20 10:37:34 -0800 | [diff] [blame] | 616 | ipmiAppGetDeviceId([[maybe_unused]] ipmi::Context::ptr ctx) | 
| Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 617 | { | 
| Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 618 | static struct | 
|  | 619 | { | 
|  | 620 | uint8_t id; | 
|  | 621 | uint8_t revision; | 
|  | 622 | uint8_t fw[2]; | 
|  | 623 | uint8_t ipmiVer; | 
|  | 624 | uint8_t addnDevSupport; | 
|  | 625 | uint24_t manufId; | 
|  | 626 | uint16_t prodId; | 
|  | 627 | uint32_t aux; | 
|  | 628 | } devId; | 
| David Cobbley | a1adb07 | 2017-11-21 15:58:13 -0800 | [diff] [blame] | 629 | static bool dev_id_initialized = false; | 
| Patrick Venture | 94930a1 | 2019-04-30 10:01:58 -0700 | [diff] [blame] | 630 | static bool defaultActivationSetting = true; | 
| David Cobbley | a1adb07 | 2017-11-21 15:58:13 -0800 | [diff] [blame] | 631 | const char* filename = "/usr/share/ipmi-providers/dev_id.json"; | 
| Alexander Amelkin | ba19c18 | 2018-09-04 15:49:36 +0300 | [diff] [blame] | 632 | constexpr auto ipmiDevIdStateShift = 7; | 
|  | 633 | constexpr auto ipmiDevIdFw1Mask = ~(1 << ipmiDevIdStateShift); | 
| Willy Tu | b78184e | 2022-10-27 22:57:38 +0000 | [diff] [blame] | 634 |  | 
|  | 635 | #ifdef GET_DBUS_ACTIVE_SOFTWARE | 
|  | 636 | static bool haveBMCVersion = false; | 
| JeffLin | 27a62ec | 2021-11-24 15:40:33 +0800 | [diff] [blame] | 637 | if (!haveBMCVersion || !dev_id_initialized) | 
| David Cobbley | a1adb07 | 2017-11-21 15:58:13 -0800 | [diff] [blame] | 638 | { | 
| Willy Tu | b78184e | 2022-10-27 22:57:38 +0000 | [diff] [blame] | 639 | int r = -1; | 
|  | 640 | Revision rev = {0, 0, 0, 0}; | 
| Nagaraju Goruganti | 744398d | 2018-02-20 09:52:00 -0600 | [diff] [blame] | 641 | try | 
|  | 642 | { | 
| Vernon Mauery | ea1c401 | 2019-05-24 13:26:16 -0700 | [diff] [blame] | 643 | auto version = getActiveSoftwareVersionInfo(ctx); | 
| Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 644 | r = convertVersion(version, rev); | 
| David Cobbley | a1adb07 | 2017-11-21 15:58:13 -0800 | [diff] [blame] | 645 | } | 
| Nagaraju Goruganti | 744398d | 2018-02-20 09:52:00 -0600 | [diff] [blame] | 646 | catch (const std::exception& e) | 
|  | 647 | { | 
|  | 648 | log<level::ERR>(e.what()); | 
|  | 649 | } | 
| Nan Li | ee0cb90 | 2016-07-11 15:38:03 +0800 | [diff] [blame] | 650 |  | 
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 651 | if (r >= 0) | 
|  | 652 | { | 
| Nagaraju Goruganti | 744398d | 2018-02-20 09:52:00 -0600 | [diff] [blame] | 653 | // bit7 identifies if the device is available | 
|  | 654 | // 0=normal operation | 
|  | 655 | // 1=device firmware, SDR update, | 
|  | 656 | // or self-initialization in progress. | 
| Alexander Amelkin | ba19c18 | 2018-09-04 15:49:36 +0300 | [diff] [blame] | 657 | // The availability may change in run time, so mask here | 
|  | 658 | // and initialize later. | 
| Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 659 | devId.fw[0] = rev.major & ipmiDevIdFw1Mask; | 
| Nagaraju Goruganti | 744398d | 2018-02-20 09:52:00 -0600 | [diff] [blame] | 660 |  | 
|  | 661 | rev.minor = (rev.minor > 99 ? 99 : rev.minor); | 
| Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 662 | devId.fw[1] = rev.minor % 10 + (rev.minor / 10) * 16; | 
| Potin Lai | c7c5592 | 2023-02-16 10:33:55 +0800 | [diff] [blame] | 663 | std::memcpy(&devId.aux, rev.aux, sizeof(rev.aux)); | 
| Brandon Kim | c1f5aca | 2022-03-17 17:54:06 -0700 | [diff] [blame] | 664 | haveBMCVersion = true; | 
| David Cobbley | a1adb07 | 2017-11-21 15:58:13 -0800 | [diff] [blame] | 665 | } | 
| JeffLin | 27a62ec | 2021-11-24 15:40:33 +0800 | [diff] [blame] | 666 | } | 
| Willy Tu | b78184e | 2022-10-27 22:57:38 +0000 | [diff] [blame] | 667 | #endif | 
| JeffLin | 27a62ec | 2021-11-24 15:40:33 +0800 | [diff] [blame] | 668 | if (!dev_id_initialized) | 
|  | 669 | { | 
| David Cobbley | a1adb07 | 2017-11-21 15:58:13 -0800 | [diff] [blame] | 670 | // IPMI Spec version 2.0 | 
| Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 671 | devId.ipmiVer = 2; | 
| Adriana Kobylak | 0e91264 | 2016-06-22 16:54:39 -0500 | [diff] [blame] | 672 |  | 
| Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 673 | std::ifstream devIdFile(filename); | 
|  | 674 | if (devIdFile.is_open()) | 
| David Cobbley | a1adb07 | 2017-11-21 15:58:13 -0800 | [diff] [blame] | 675 | { | 
| Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 676 | auto data = nlohmann::json::parse(devIdFile, nullptr, false); | 
| David Cobbley | a1adb07 | 2017-11-21 15:58:13 -0800 | [diff] [blame] | 677 | if (!data.is_discarded()) | 
|  | 678 | { | 
| Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 679 | devId.id = data.value("id", 0); | 
|  | 680 | devId.revision = data.value("revision", 0); | 
|  | 681 | devId.addnDevSupport = data.value("addn_dev_support", 0); | 
|  | 682 | devId.manufId = data.value("manuf_id", 0); | 
|  | 683 | devId.prodId = data.value("prod_id", 0); | 
| Potin Lai | 9a68636 | 2023-09-05 09:27:53 +0800 | [diff] [blame] | 684 | #ifdef GET_DBUS_ACTIVE_SOFTWARE | 
|  | 685 | if (!(AUX_0_MATCH_INDEX || AUX_1_MATCH_INDEX || | 
|  | 686 | AUX_2_MATCH_INDEX || AUX_3_MATCH_INDEX)) | 
|  | 687 | #endif | 
|  | 688 | { | 
|  | 689 | devId.aux = data.value("aux", 0); | 
|  | 690 | } | 
| David Cobbley | a1adb07 | 2017-11-21 15:58:13 -0800 | [diff] [blame] | 691 |  | 
| Willy Tu | bfd3a17 | 2022-05-31 13:57:54 -0700 | [diff] [blame] | 692 | if (data.contains("firmware_revision")) | 
|  | 693 | { | 
|  | 694 | const auto& firmwareRevision = data.at("firmware_revision"); | 
|  | 695 | if (firmwareRevision.contains("major")) | 
|  | 696 | { | 
|  | 697 | firmwareRevision.at("major").get_to(devId.fw[0]); | 
|  | 698 | } | 
|  | 699 | if (firmwareRevision.contains("minor")) | 
|  | 700 | { | 
|  | 701 | firmwareRevision.at("minor").get_to(devId.fw[1]); | 
|  | 702 | } | 
|  | 703 | } | 
|  | 704 |  | 
| Patrick Venture | 94930a1 | 2019-04-30 10:01:58 -0700 | [diff] [blame] | 705 | // Set the availablitity of the BMC. | 
|  | 706 | defaultActivationSetting = data.value("availability", true); | 
|  | 707 |  | 
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 708 | // Don't read the file every time if successful | 
| David Cobbley | a1adb07 | 2017-11-21 15:58:13 -0800 | [diff] [blame] | 709 | dev_id_initialized = true; | 
|  | 710 | } | 
|  | 711 | else | 
|  | 712 | { | 
|  | 713 | log<level::ERR>("Device ID JSON parser failure"); | 
| Vernon Mauery | f2587fc | 2019-04-09 14:28:15 -0700 | [diff] [blame] | 714 | return ipmi::responseUnspecifiedError(); | 
| David Cobbley | a1adb07 | 2017-11-21 15:58:13 -0800 | [diff] [blame] | 715 | } | 
|  | 716 | } | 
|  | 717 | else | 
|  | 718 | { | 
|  | 719 | log<level::ERR>("Device ID file not found"); | 
| Vernon Mauery | f2587fc | 2019-04-09 14:28:15 -0700 | [diff] [blame] | 720 | return ipmi::responseUnspecifiedError(); | 
| Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 721 | } | 
|  | 722 | } | 
| Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 723 |  | 
| Alexander Amelkin | ba19c18 | 2018-09-04 15:49:36 +0300 | [diff] [blame] | 724 | // Set availability to the actual current BMC state | 
| Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 725 | devId.fw[0] &= ipmiDevIdFw1Mask; | 
| Patrick Venture | 94930a1 | 2019-04-30 10:01:58 -0700 | [diff] [blame] | 726 | if (!getCurrentBmcStateWithFallback(defaultActivationSetting)) | 
| Alexander Amelkin | ba19c18 | 2018-09-04 15:49:36 +0300 | [diff] [blame] | 727 | { | 
| Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 728 | devId.fw[0] |= (1 << ipmiDevIdStateShift); | 
| Alexander Amelkin | ba19c18 | 2018-09-04 15:49:36 +0300 | [diff] [blame] | 729 | } | 
|  | 730 |  | 
| Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 731 | return ipmi::responseSuccess( | 
|  | 732 | devId.id, devId.revision, devId.fw[0], devId.fw[1], devId.ipmiVer, | 
|  | 733 | devId.addnDevSupport, devId.manufId, devId.prodId, devId.aux); | 
| Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 734 | } | 
|  | 735 |  | 
| Vernon Mauery | b84a528 | 2019-03-25 13:39:03 -0700 | [diff] [blame] | 736 | auto ipmiAppGetSelfTestResults() -> ipmi::RspType<uint8_t, uint8_t> | 
| Nan Li | 41fa24a | 2016-11-10 20:12:37 +0800 | [diff] [blame] | 737 | { | 
| Nan Li | 41fa24a | 2016-11-10 20:12:37 +0800 | [diff] [blame] | 738 | // Byte 2: | 
|  | 739 | //  55h - No error. | 
| Gunnar Mills | 8991dd6 | 2017-10-25 17:11:29 -0500 | [diff] [blame] | 740 | //  56h - Self Test function not implemented in this controller. | 
| Nan Li | 41fa24a | 2016-11-10 20:12:37 +0800 | [diff] [blame] | 741 | //  57h - Corrupted or inaccesssible data or devices. | 
|  | 742 | //  58h - Fatal hardware error. | 
|  | 743 | //  FFh - reserved. | 
|  | 744 | //  all other: Device-specific 'internal failure'. | 
|  | 745 | //  Byte 3: | 
|  | 746 | //      For byte 2 = 55h, 56h, FFh:     00h | 
|  | 747 | //      For byte 2 = 58h, all other:    Device-specific | 
|  | 748 | //      For byte 2 = 57h:   self-test error bitfield. | 
|  | 749 | //      Note: returning 57h does not imply that all test were run. | 
|  | 750 | //      [7] 1b = Cannot access SEL device. | 
|  | 751 | //      [6] 1b = Cannot access SDR Repository. | 
|  | 752 | //      [5] 1b = Cannot access BMC FRU device. | 
|  | 753 | //      [4] 1b = IPMB signal lines do not respond. | 
|  | 754 | //      [3] 1b = SDR Repository empty. | 
|  | 755 | //      [2] 1b = Internal Use Area of BMC FRU corrupted. | 
|  | 756 | //      [1] 1b = controller update 'boot block' firmware corrupted. | 
|  | 757 | //      [0] 1b = controller operational firmware corrupted. | 
| Vernon Mauery | b84a528 | 2019-03-25 13:39:03 -0700 | [diff] [blame] | 758 | constexpr uint8_t notImplemented = 0x56; | 
|  | 759 | constexpr uint8_t zero = 0; | 
|  | 760 | return ipmi::responseSuccess(notImplemented, zero); | 
| Nan Li | 41fa24a | 2016-11-10 20:12:37 +0800 | [diff] [blame] | 761 | } | 
|  | 762 |  | 
| Vernon Mauery | 1554132 | 2019-03-25 13:33:03 -0700 | [diff] [blame] | 763 | static constexpr size_t uuidBinaryLength = 16; | 
|  | 764 | static std::array<uint8_t, uuidBinaryLength> rfc4122ToIpmi(std::string rfc4122) | 
| Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 765 | { | 
| Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 766 | using Argument = xyz::openbmc_project::common::InvalidArgument; | 
| Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 767 | // UUID is in RFC4122 format. Ex: 61a39523-78f2-11e5-9862-e6402cfc3223 | 
| Patrick Venture | d211702 | 2018-02-06 08:54:37 -0800 | [diff] [blame] | 768 | // Per IPMI Spec 2.0 need to convert to 16 hex bytes and reverse the byte | 
|  | 769 | // order | 
| Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 770 | // Ex: 0x2332fc2c40e66298e511f2782395a361 | 
| Vernon Mauery | 1554132 | 2019-03-25 13:33:03 -0700 | [diff] [blame] | 771 | constexpr size_t uuidHexLength = (2 * uuidBinaryLength); | 
|  | 772 | constexpr size_t uuidRfc4122Length = (uuidHexLength + 4); | 
|  | 773 | std::array<uint8_t, uuidBinaryLength> uuid; | 
|  | 774 | if (rfc4122.size() == uuidRfc4122Length) | 
| Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 775 | { | 
| Vernon Mauery | 1554132 | 2019-03-25 13:33:03 -0700 | [diff] [blame] | 776 | rfc4122.erase(std::remove(rfc4122.begin(), rfc4122.end(), '-'), | 
|  | 777 | rfc4122.end()); | 
| Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 778 | } | 
| Vernon Mauery | 1554132 | 2019-03-25 13:33:03 -0700 | [diff] [blame] | 779 | if (rfc4122.size() != uuidHexLength) | 
| vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 780 | { | 
| Vernon Mauery | 1554132 | 2019-03-25 13:33:03 -0700 | [diff] [blame] | 781 | elog<InvalidArgument>(Argument::ARGUMENT_NAME("rfc4122"), | 
|  | 782 | Argument::ARGUMENT_VALUE(rfc4122.c_str())); | 
| vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 783 | } | 
| Vernon Mauery | 1554132 | 2019-03-25 13:33:03 -0700 | [diff] [blame] | 784 | for (size_t ind = 0; ind < uuidHexLength; ind += 2) | 
| vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 785 | { | 
| Vernon Mauery | 1554132 | 2019-03-25 13:33:03 -0700 | [diff] [blame] | 786 | char v[3]; | 
|  | 787 | v[0] = rfc4122[ind]; | 
|  | 788 | v[1] = rfc4122[ind + 1]; | 
|  | 789 | v[2] = 0; | 
|  | 790 | size_t err; | 
|  | 791 | long b; | 
|  | 792 | try | 
| Emily Shaffer | edb8bb0 | 2018-09-27 14:50:15 -0700 | [diff] [blame] | 793 | { | 
| Vernon Mauery | 1554132 | 2019-03-25 13:33:03 -0700 | [diff] [blame] | 794 | b = std::stoul(v, &err, 16); | 
| Emily Shaffer | edb8bb0 | 2018-09-27 14:50:15 -0700 | [diff] [blame] | 795 | } | 
| Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 796 | catch (const std::exception& e) | 
| Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 797 | { | 
| Vernon Mauery | 1554132 | 2019-03-25 13:33:03 -0700 | [diff] [blame] | 798 | elog<InvalidArgument>(Argument::ARGUMENT_NAME("rfc4122"), | 
|  | 799 | Argument::ARGUMENT_VALUE(rfc4122.c_str())); | 
| Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 800 | } | 
| Vernon Mauery | 1554132 | 2019-03-25 13:33:03 -0700 | [diff] [blame] | 801 | // check that exactly two ascii bytes were converted | 
|  | 802 | if (err != 2) | 
|  | 803 | { | 
|  | 804 | elog<InvalidArgument>(Argument::ARGUMENT_NAME("rfc4122"), | 
|  | 805 | Argument::ARGUMENT_VALUE(rfc4122.c_str())); | 
|  | 806 | } | 
|  | 807 | uuid[uuidBinaryLength - (ind / 2) - 1] = static_cast<uint8_t>(b); | 
| Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 808 | } | 
| Vernon Mauery | 1554132 | 2019-03-25 13:33:03 -0700 | [diff] [blame] | 809 | return uuid; | 
|  | 810 | } | 
| Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 811 |  | 
| Vernon Mauery | 1554132 | 2019-03-25 13:33:03 -0700 | [diff] [blame] | 812 | auto ipmiAppGetDeviceGuid() | 
|  | 813 | -> ipmi::RspType<std::array<uint8_t, uuidBinaryLength>> | 
|  | 814 | { | 
|  | 815 | // return a fixed GUID based on /etc/machine-id | 
|  | 816 | // This should match the /redfish/v1/Managers/bmc's UUID data | 
| Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 817 |  | 
| Vernon Mauery | 1554132 | 2019-03-25 13:33:03 -0700 | [diff] [blame] | 818 | // machine specific application ID (for BMC ID) | 
|  | 819 | // generated by systemd-id128 -p new as per man page | 
|  | 820 | static constexpr sd_id128_t bmcUuidAppId = SD_ID128_MAKE( | 
|  | 821 | e0, e1, 73, 76, 64, 61, 47, da, a5, 0c, d0, cc, 64, 12, 45, 78); | 
| Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 822 |  | 
| Vernon Mauery | 1554132 | 2019-03-25 13:33:03 -0700 | [diff] [blame] | 823 | sd_id128_t bmcUuid; | 
|  | 824 | // create the UUID from /etc/machine-id via the systemd API | 
|  | 825 | sd_id128_get_machine_app_specific(bmcUuidAppId, &bmcUuid); | 
| Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 826 |  | 
| Vernon Mauery | 1554132 | 2019-03-25 13:33:03 -0700 | [diff] [blame] | 827 | char bmcUuidCstr[SD_ID128_STRING_MAX]; | 
|  | 828 | std::string systemUuid = sd_id128_to_string(bmcUuid, bmcUuidCstr); | 
|  | 829 |  | 
|  | 830 | std::array<uint8_t, uuidBinaryLength> uuid = rfc4122ToIpmi(systemUuid); | 
|  | 831 | return ipmi::responseSuccess(uuid); | 
| Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 832 | } | 
| Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 833 |  | 
| Vernon Mauery | cc99ba4 | 2019-03-25 13:40:11 -0700 | [diff] [blame] | 834 | auto ipmiAppGetBtCapabilities() | 
|  | 835 | -> ipmi::RspType<uint8_t, uint8_t, uint8_t, uint8_t, uint8_t> | 
| vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 836 | { | 
| Adriana Kobylak | 88ad815 | 2016-12-13 10:09:08 -0600 | [diff] [blame] | 837 | // Per IPMI 2.0 spec, the input and output buffer size must be the max | 
|  | 838 | // buffer size minus one byte to allocate space for the length byte. | 
| Vernon Mauery | cc99ba4 | 2019-03-25 13:40:11 -0700 | [diff] [blame] | 839 | constexpr uint8_t nrOutstanding = 0x01; | 
|  | 840 | constexpr uint8_t inputBufferSize = MAX_IPMI_BUFFER - 1; | 
|  | 841 | constexpr uint8_t outputBufferSize = MAX_IPMI_BUFFER - 1; | 
|  | 842 | constexpr uint8_t transactionTime = 0x0A; | 
|  | 843 | constexpr uint8_t nrRetries = 0x01; | 
| vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 844 |  | 
| Vernon Mauery | cc99ba4 | 2019-03-25 13:40:11 -0700 | [diff] [blame] | 845 | return ipmi::responseSuccess(nrOutstanding, inputBufferSize, | 
|  | 846 | outputBufferSize, transactionTime, nrRetries); | 
| vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 847 | } | 
|  | 848 |  | 
| Vernon Mauery | 6c44a94 | 2023-07-27 11:00:10 -0700 | [diff] [blame] | 849 | auto ipmiAppGetSystemGuid(ipmi::Context::ptr& ctx) | 
|  | 850 | -> ipmi::RspType<std::array<uint8_t, 16>> | 
| Marri Devender Rao | 5e007a5 | 2018-01-08 06:18:36 -0600 | [diff] [blame] | 851 | { | 
| Vernon Mauery | b90a532 | 2019-03-25 13:36:55 -0700 | [diff] [blame] | 852 | static constexpr auto uuidInterface = "xyz.openbmc_project.Common.UUID"; | 
|  | 853 | static constexpr auto uuidProperty = "UUID"; | 
| Marri Devender Rao | 5e007a5 | 2018-01-08 06:18:36 -0600 | [diff] [blame] | 854 |  | 
| Vernon Mauery | 6c44a94 | 2023-07-27 11:00:10 -0700 | [diff] [blame] | 855 | // Get the Inventory object implementing BMC interface | 
|  | 856 | ipmi::DbusObjectInfo objectInfo{}; | 
|  | 857 | boost::system::error_code ec = ipmi::getDbusObject(ctx, uuidInterface, | 
|  | 858 | objectInfo); | 
|  | 859 | if (ec.value()) | 
| Marri Devender Rao | 5e007a5 | 2018-01-08 06:18:36 -0600 | [diff] [blame] | 860 | { | 
| Vernon Mauery | 6c44a94 | 2023-07-27 11:00:10 -0700 | [diff] [blame] | 861 | log<level::ERR>("Failed to locate System UUID object", | 
|  | 862 | entry("INTERFACE=%s", uuidInterface), | 
|  | 863 | entry("ERROR=%s", ec.message().c_str())); | 
|  | 864 | return ipmi::responseUnspecifiedError(); | 
| Marri Devender Rao | 5e007a5 | 2018-01-08 06:18:36 -0600 | [diff] [blame] | 865 | } | 
| Vernon Mauery | 6c44a94 | 2023-07-27 11:00:10 -0700 | [diff] [blame] | 866 |  | 
|  | 867 | // Read UUID property value from bmcObject | 
|  | 868 | // UUID is in RFC4122 format Ex: 61a39523-78f2-11e5-9862-e6402cfc3223 | 
|  | 869 | std::string rfc4122Uuid{}; | 
|  | 870 | ec = ipmi::getDbusProperty(ctx, objectInfo.second, objectInfo.first, | 
|  | 871 | uuidInterface, uuidProperty, rfc4122Uuid); | 
|  | 872 | if (ec.value()) | 
| Marri Devender Rao | 5e007a5 | 2018-01-08 06:18:36 -0600 | [diff] [blame] | 873 | { | 
|  | 874 | log<level::ERR>("Failed in reading BMC UUID property", | 
| Vernon Mauery | b90a532 | 2019-03-25 13:36:55 -0700 | [diff] [blame] | 875 | entry("INTERFACE=%s", uuidInterface), | 
| Vernon Mauery | 6c44a94 | 2023-07-27 11:00:10 -0700 | [diff] [blame] | 876 | entry("PROPERTY=%s", uuidProperty), | 
|  | 877 | entry("ERROR=%s", ec.message().c_str())); | 
| Vernon Mauery | b90a532 | 2019-03-25 13:36:55 -0700 | [diff] [blame] | 878 | return ipmi::responseUnspecifiedError(); | 
| Marri Devender Rao | 5e007a5 | 2018-01-08 06:18:36 -0600 | [diff] [blame] | 879 | } | 
| Vernon Mauery | b90a532 | 2019-03-25 13:36:55 -0700 | [diff] [blame] | 880 | std::array<uint8_t, 16> uuid; | 
| Vernon Mauery | b90a532 | 2019-03-25 13:36:55 -0700 | [diff] [blame] | 881 | try | 
|  | 882 | { | 
|  | 883 | // convert to IPMI format | 
|  | 884 | uuid = rfc4122ToIpmi(rfc4122Uuid); | 
|  | 885 | } | 
|  | 886 | catch (const InvalidArgument& e) | 
|  | 887 | { | 
|  | 888 | log<level::ERR>("Failed in parsing BMC UUID property", | 
|  | 889 | entry("INTERFACE=%s", uuidInterface), | 
|  | 890 | entry("PROPERTY=%s", uuidProperty), | 
|  | 891 | entry("VALUE=%s", rfc4122Uuid.c_str())); | 
|  | 892 | return ipmi::responseUnspecifiedError(); | 
|  | 893 | } | 
|  | 894 | return ipmi::responseSuccess(uuid); | 
| Marri Devender Rao | 5e007a5 | 2018-01-08 06:18:36 -0600 | [diff] [blame] | 895 | } | 
|  | 896 |  | 
| Rajashekar Gade Reddy | e702392 | 2019-07-10 16:54:55 +0000 | [diff] [blame] | 897 | /** | 
|  | 898 | * @brief set the session state as teardown | 
|  | 899 | * | 
|  | 900 | * This function is to set the session state to tear down in progress if the | 
|  | 901 | * state is active. | 
|  | 902 | * | 
|  | 903 | * @param[in] busp - Dbus obj | 
|  | 904 | * @param[in] service - service name | 
|  | 905 | * @param[in] obj - object path | 
|  | 906 | * | 
|  | 907 | * @return success completion code if it sets the session state to | 
|  | 908 | * tearDownInProgress else return the corresponding error completion code. | 
|  | 909 | **/ | 
|  | 910 | uint8_t setSessionState(std::shared_ptr<sdbusplus::asio::connection>& busp, | 
|  | 911 | const std::string& service, const std::string& obj) | 
|  | 912 | { | 
|  | 913 | try | 
|  | 914 | { | 
|  | 915 | uint8_t sessionState = std::get<uint8_t>(ipmi::getDbusProperty( | 
|  | 916 | *busp, service, obj, session::sessionIntf, "State")); | 
|  | 917 |  | 
|  | 918 | if (sessionState == static_cast<uint8_t>(session::State::active)) | 
|  | 919 | { | 
|  | 920 | ipmi::setDbusProperty( | 
|  | 921 | *busp, service, obj, session::sessionIntf, "State", | 
|  | 922 | static_cast<uint8_t>(session::State::tearDownInProgress)); | 
|  | 923 | return ipmi::ccSuccess; | 
|  | 924 | } | 
|  | 925 | } | 
| Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 926 | catch (const std::exception& e) | 
| Rajashekar Gade Reddy | e702392 | 2019-07-10 16:54:55 +0000 | [diff] [blame] | 927 | { | 
|  | 928 | log<level::ERR>("Failed in getting session state property", | 
|  | 929 | entry("service=%s", service.c_str()), | 
|  | 930 | entry("object path=%s", obj.c_str()), | 
|  | 931 | entry("interface=%s", session::sessionIntf)); | 
|  | 932 | return ipmi::ccUnspecifiedError; | 
|  | 933 | } | 
|  | 934 |  | 
|  | 935 | return ipmi::ccInvalidFieldRequest; | 
|  | 936 | } | 
|  | 937 |  | 
|  | 938 | ipmi::RspType<> ipmiAppCloseSession(uint32_t reqSessionId, | 
|  | 939 | std::optional<uint8_t> requestSessionHandle) | 
|  | 940 | { | 
|  | 941 | auto busp = getSdBus(); | 
|  | 942 | uint8_t reqSessionHandle = | 
|  | 943 | requestSessionHandle.value_or(session::defaultSessionHandle); | 
|  | 944 |  | 
|  | 945 | if (reqSessionId == session::sessionZero && | 
|  | 946 | reqSessionHandle == session::defaultSessionHandle) | 
|  | 947 | { | 
|  | 948 | return ipmi::response(session::ccInvalidSessionId); | 
|  | 949 | } | 
|  | 950 |  | 
|  | 951 | if (reqSessionId == session::sessionZero && | 
|  | 952 | reqSessionHandle == session::invalidSessionHandle) | 
|  | 953 | { | 
|  | 954 | return ipmi::response(session::ccInvalidSessionHandle); | 
|  | 955 | } | 
|  | 956 |  | 
|  | 957 | if (reqSessionId != session::sessionZero && | 
|  | 958 | reqSessionHandle != session::defaultSessionHandle) | 
|  | 959 | { | 
|  | 960 | return ipmi::response(ipmi::ccInvalidFieldRequest); | 
|  | 961 | } | 
|  | 962 |  | 
|  | 963 | try | 
|  | 964 | { | 
|  | 965 | ipmi::ObjectTree objectTree = ipmi::getAllDbusObjects( | 
|  | 966 | *busp, session::sessionManagerRootPath, session::sessionIntf); | 
|  | 967 |  | 
|  | 968 | for (auto& objectTreeItr : objectTree) | 
|  | 969 | { | 
|  | 970 | const std::string obj = objectTreeItr.first; | 
|  | 971 |  | 
|  | 972 | if (isSessionObjectMatched(obj, reqSessionId, reqSessionHandle)) | 
|  | 973 | { | 
|  | 974 | auto& serviceMap = objectTreeItr.second; | 
|  | 975 |  | 
|  | 976 | // Session id and session handle are unique for each session. | 
|  | 977 | // Session id and handler are retrived from the object path and | 
|  | 978 | // object path will be unique for each session. Checking if | 
|  | 979 | // multiple objects exist with same object path under multiple | 
|  | 980 | // services. | 
|  | 981 | if (serviceMap.size() != 1) | 
|  | 982 | { | 
|  | 983 | return ipmi::responseUnspecifiedError(); | 
|  | 984 | } | 
|  | 985 |  | 
|  | 986 | auto itr = serviceMap.begin(); | 
|  | 987 | const std::string service = itr->first; | 
|  | 988 | return ipmi::response(setSessionState(busp, service, obj)); | 
|  | 989 | } | 
|  | 990 | } | 
|  | 991 | } | 
| Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 992 | catch (const sdbusplus::exception_t& e) | 
| Rajashekar Gade Reddy | e702392 | 2019-07-10 16:54:55 +0000 | [diff] [blame] | 993 | { | 
|  | 994 | log<level::ERR>("Failed to fetch object from dbus", | 
|  | 995 | entry("INTERFACE=%s", session::sessionIntf), | 
|  | 996 | entry("ERRMSG=%s", e.what())); | 
|  | 997 | return ipmi::responseUnspecifiedError(); | 
|  | 998 | } | 
|  | 999 |  | 
|  | 1000 | return ipmi::responseInvalidFieldRequest(); | 
|  | 1001 | } | 
|  | 1002 |  | 
| Rajashekar Gade Reddy | f71444d | 2019-07-25 15:12:17 +0000 | [diff] [blame] | 1003 | uint8_t getTotalSessionCount() | 
|  | 1004 | { | 
| Meera-Katta | c178948 | 2021-05-18 09:53:26 +0000 | [diff] [blame] | 1005 | uint8_t count = 0, ch = 0; | 
| Rajashekar Gade Reddy | f71444d | 2019-07-25 15:12:17 +0000 | [diff] [blame] | 1006 |  | 
|  | 1007 | while (ch < ipmi::maxIpmiChannels && | 
|  | 1008 | count < session::maxNetworkInstanceSupported) | 
|  | 1009 | { | 
| Jayaprakash Mutyala | 80207e6 | 2020-07-04 16:34:15 +0000 | [diff] [blame] | 1010 | ipmi::ChannelInfo chInfo{}; | 
| Rajashekar Gade Reddy | f71444d | 2019-07-25 15:12:17 +0000 | [diff] [blame] | 1011 | ipmi::getChannelInfo(ch, chInfo); | 
|  | 1012 | if (static_cast<ipmi::EChannelMediumType>(chInfo.mediumType) == | 
|  | 1013 | ipmi::EChannelMediumType::lan8032) | 
|  | 1014 | { | 
|  | 1015 | count++; | 
|  | 1016 | } | 
|  | 1017 | ch++; | 
|  | 1018 | } | 
|  | 1019 | return count * session::maxSessionCountPerChannel; | 
|  | 1020 | } | 
|  | 1021 |  | 
|  | 1022 | /** | 
|  | 1023 | * @brief get session info request data. | 
|  | 1024 | * | 
|  | 1025 | * This function validates the request data and retrive request session id, | 
|  | 1026 | * session handle. | 
|  | 1027 | * | 
| Rajashekar Gade Reddy | 4d22640 | 2019-11-13 17:13:05 +0530 | [diff] [blame] | 1028 | * @param[in] ctx - context of current session. | 
| Rajashekar Gade Reddy | f71444d | 2019-07-25 15:12:17 +0000 | [diff] [blame] | 1029 | * @param[in] sessionIndex - request session index | 
|  | 1030 | * @param[in] payload - input payload | 
|  | 1031 | * @param[in] reqSessionId - unpacked session Id will be asigned | 
|  | 1032 | * @param[in] reqSessionHandle - unpacked session handle will be asigned | 
|  | 1033 | * | 
|  | 1034 | * @return success completion code if request data is valid | 
|  | 1035 | * else return the correcponding error completion code. | 
|  | 1036 | **/ | 
| Rajashekar Gade Reddy | 4d22640 | 2019-11-13 17:13:05 +0530 | [diff] [blame] | 1037 | uint8_t getSessionInfoRequestData(const ipmi::Context::ptr ctx, | 
|  | 1038 | const uint8_t sessionIndex, | 
| Rajashekar Gade Reddy | f71444d | 2019-07-25 15:12:17 +0000 | [diff] [blame] | 1039 | ipmi::message::Payload& payload, | 
|  | 1040 | uint32_t& reqSessionId, | 
|  | 1041 | uint8_t& reqSessionHandle) | 
|  | 1042 | { | 
| Rajashekar Gade Reddy | 4d22640 | 2019-11-13 17:13:05 +0530 | [diff] [blame] | 1043 | if ((sessionIndex > session::maxSessionCountPerChannel) && | 
|  | 1044 | (sessionIndex < session::searchSessionByHandle)) | 
| Rajashekar Gade Reddy | f71444d | 2019-07-25 15:12:17 +0000 | [diff] [blame] | 1045 | { | 
|  | 1046 | return ipmi::ccInvalidFieldRequest; | 
|  | 1047 | } | 
|  | 1048 |  | 
|  | 1049 | switch (sessionIndex) | 
|  | 1050 | { | 
| Rajashekar Gade Reddy | 4d22640 | 2019-11-13 17:13:05 +0530 | [diff] [blame] | 1051 | case session::searchCurrentSession: | 
|  | 1052 |  | 
|  | 1053 | ipmi::ChannelInfo chInfo; | 
|  | 1054 | ipmi::getChannelInfo(ctx->channel, chInfo); | 
|  | 1055 |  | 
|  | 1056 | if (static_cast<ipmi::EChannelMediumType>(chInfo.mediumType) != | 
|  | 1057 | ipmi::EChannelMediumType::lan8032) | 
|  | 1058 | { | 
|  | 1059 | return ipmi::ccInvalidFieldRequest; | 
|  | 1060 | } | 
|  | 1061 |  | 
|  | 1062 | if (!payload.fullyUnpacked()) | 
|  | 1063 | { | 
|  | 1064 | return ipmi::ccReqDataLenInvalid; | 
|  | 1065 | } | 
|  | 1066 | // Check if current sessionId is 0, sessionId 0 is reserved. | 
|  | 1067 | if (ctx->sessionId == session::sessionZero) | 
|  | 1068 | { | 
|  | 1069 | return session::ccInvalidSessionId; | 
|  | 1070 | } | 
|  | 1071 | reqSessionId = ctx->sessionId; | 
|  | 1072 | break; | 
|  | 1073 |  | 
| Rajashekar Gade Reddy | f71444d | 2019-07-25 15:12:17 +0000 | [diff] [blame] | 1074 | case session::searchSessionByHandle: | 
|  | 1075 |  | 
|  | 1076 | if ((payload.unpack(reqSessionHandle)) || | 
|  | 1077 | (!payload.fullyUnpacked())) | 
|  | 1078 | { | 
|  | 1079 | return ipmi::ccReqDataLenInvalid; | 
|  | 1080 | } | 
|  | 1081 |  | 
|  | 1082 | if ((reqSessionHandle == session::sessionZero) || | 
|  | 1083 | ((reqSessionHandle & session::multiIntfaceSessionHandleMask) > | 
|  | 1084 | session::maxSessionCountPerChannel)) | 
|  | 1085 | { | 
|  | 1086 | return session::ccInvalidSessionHandle; | 
|  | 1087 | } | 
|  | 1088 | break; | 
|  | 1089 |  | 
|  | 1090 | case session::searchSessionById: | 
|  | 1091 |  | 
|  | 1092 | if ((payload.unpack(reqSessionId)) || (!payload.fullyUnpacked())) | 
|  | 1093 | { | 
|  | 1094 | return ipmi::ccReqDataLenInvalid; | 
|  | 1095 | } | 
|  | 1096 |  | 
|  | 1097 | if (reqSessionId == session::sessionZero) | 
|  | 1098 | { | 
|  | 1099 | return session::ccInvalidSessionId; | 
|  | 1100 | } | 
|  | 1101 | break; | 
|  | 1102 |  | 
|  | 1103 | default: | 
|  | 1104 | if (!payload.fullyUnpacked()) | 
|  | 1105 | { | 
|  | 1106 | return ipmi::ccReqDataLenInvalid; | 
|  | 1107 | } | 
|  | 1108 | break; | 
|  | 1109 | } | 
|  | 1110 | return ipmi::ccSuccess; | 
|  | 1111 | } | 
|  | 1112 |  | 
| Vernon Mauery | e7e8b81 | 2019-10-28 16:00:34 -0700 | [diff] [blame] | 1113 | uint8_t getSessionState(ipmi::Context::ptr ctx, const std::string& service, | 
|  | 1114 | const std::string& objPath, uint8_t& sessionState) | 
| Rajashekar Gade Reddy | f71444d | 2019-07-25 15:12:17 +0000 | [diff] [blame] | 1115 | { | 
| Vernon Mauery | e7e8b81 | 2019-10-28 16:00:34 -0700 | [diff] [blame] | 1116 | boost::system::error_code ec = ipmi::getDbusProperty( | 
|  | 1117 | ctx, service, objPath, session::sessionIntf, "State", sessionState); | 
|  | 1118 | if (ec) | 
| Rajashekar Gade Reddy | f71444d | 2019-07-25 15:12:17 +0000 | [diff] [blame] | 1119 | { | 
|  | 1120 | log<level::ERR>("Failed to fetch state property ", | 
|  | 1121 | entry("SERVICE=%s", service.c_str()), | 
|  | 1122 | entry("OBJECTPATH=%s", objPath.c_str()), | 
|  | 1123 | entry("INTERFACE=%s", session::sessionIntf), | 
| Vernon Mauery | e7e8b81 | 2019-10-28 16:00:34 -0700 | [diff] [blame] | 1124 | entry("ERRMSG=%s", ec.message().c_str())); | 
| Rajashekar Gade Reddy | f71444d | 2019-07-25 15:12:17 +0000 | [diff] [blame] | 1125 | return ipmi::ccUnspecifiedError; | 
|  | 1126 | } | 
| Rajashekar Gade Reddy | f71444d | 2019-07-25 15:12:17 +0000 | [diff] [blame] | 1127 | return ipmi::ccSuccess; | 
|  | 1128 | } | 
|  | 1129 |  | 
|  | 1130 | static constexpr uint8_t macAddrLen = 6; | 
| Vernon Mauery | e7e8b81 | 2019-10-28 16:00:34 -0700 | [diff] [blame] | 1131 | /** Alias SessionDetails - contain the optional information about an | 
|  | 1132 | *        RMCP+ session. | 
|  | 1133 | * | 
|  | 1134 | *  @param userID - uint6_t session user ID (0-63) | 
|  | 1135 | *  @param reserved - uint2_t reserved | 
|  | 1136 | *  @param privilege - uint4_t session privilege (0-5) | 
|  | 1137 | *  @param reserved - uint4_t reserved | 
|  | 1138 | *  @param channel - uint4_t session channel number | 
|  | 1139 | *  @param protocol - uint4_t session protocol | 
|  | 1140 | *  @param remoteIP - uint32_t remote IP address | 
|  | 1141 | *  @param macAddr - std::array<uint8_t, 6> mac address | 
|  | 1142 | *  @param port - uint16_t remote port | 
|  | 1143 | */ | 
|  | 1144 | using SessionDetails = | 
|  | 1145 | std::tuple<uint2_t, uint6_t, uint4_t, uint4_t, uint4_t, uint4_t, uint32_t, | 
|  | 1146 | std::array<uint8_t, macAddrLen>, uint16_t>; | 
| Rajashekar Gade Reddy | f71444d | 2019-07-25 15:12:17 +0000 | [diff] [blame] | 1147 |  | 
| Vernon Mauery | e7e8b81 | 2019-10-28 16:00:34 -0700 | [diff] [blame] | 1148 | /** @brief get session details for a given session | 
|  | 1149 | * | 
|  | 1150 | *  @param[in] ctx - ipmi::Context pointer for accessing D-Bus | 
|  | 1151 | *  @param[in] service - D-Bus service name to fetch details from | 
|  | 1152 | *  @param[in] objPath - D-Bus object path for session | 
|  | 1153 | *  @param[out] sessionHandle - return session handle for session | 
|  | 1154 | *  @param[out] sessionState - return session state for session | 
|  | 1155 | *  @param[out] details - return a SessionDetails tuple containing other | 
|  | 1156 | *                        session info | 
|  | 1157 | *  @return - ipmi::Cc success or error code | 
|  | 1158 | */ | 
|  | 1159 | ipmi::Cc getSessionDetails(ipmi::Context::ptr ctx, const std::string& service, | 
|  | 1160 | const std::string& objPath, uint8_t& sessionHandle, | 
|  | 1161 | uint8_t& sessionState, SessionDetails& details) | 
| Rajashekar Gade Reddy | f71444d | 2019-07-25 15:12:17 +0000 | [diff] [blame] | 1162 | { | 
| Vernon Mauery | e7e8b81 | 2019-10-28 16:00:34 -0700 | [diff] [blame] | 1163 | ipmi::PropertyMap sessionProps; | 
|  | 1164 | boost::system::error_code ec = ipmi::getAllDbusProperties( | 
|  | 1165 | ctx, service, objPath, session::sessionIntf, sessionProps); | 
| Rajashekar Gade Reddy | f71444d | 2019-07-25 15:12:17 +0000 | [diff] [blame] | 1166 |  | 
| Vernon Mauery | e7e8b81 | 2019-10-28 16:00:34 -0700 | [diff] [blame] | 1167 | if (ec) | 
| Rajashekar Gade Reddy | f71444d | 2019-07-25 15:12:17 +0000 | [diff] [blame] | 1168 | { | 
|  | 1169 | log<level::ERR>("Failed to fetch state property ", | 
|  | 1170 | entry("SERVICE=%s", service.c_str()), | 
|  | 1171 | entry("OBJECTPATH=%s", objPath.c_str()), | 
|  | 1172 | entry("INTERFACE=%s", session::sessionIntf), | 
| Vernon Mauery | e7e8b81 | 2019-10-28 16:00:34 -0700 | [diff] [blame] | 1173 | entry("ERRMSG=%s", ec.message().c_str())); | 
| Rajashekar Gade Reddy | f71444d | 2019-07-25 15:12:17 +0000 | [diff] [blame] | 1174 | return ipmi::ccUnspecifiedError; | 
|  | 1175 | } | 
|  | 1176 |  | 
| Vernon Mauery | e7e8b81 | 2019-10-28 16:00:34 -0700 | [diff] [blame] | 1177 | sessionState = ipmi::mappedVariant<uint8_t>( | 
|  | 1178 | sessionProps, "State", static_cast<uint8_t>(session::State::inactive)); | 
|  | 1179 | if (sessionState == static_cast<uint8_t>(session::State::active)) | 
|  | 1180 | { | 
| Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 1181 | sessionHandle = ipmi::mappedVariant<uint8_t>(sessionProps, | 
|  | 1182 | "SessionHandle", 0); | 
|  | 1183 | std::get<0>(details) = ipmi::mappedVariant<uint8_t>(sessionProps, | 
|  | 1184 | "UserID", 0xff); | 
| Vernon Mauery | e7e8b81 | 2019-10-28 16:00:34 -0700 | [diff] [blame] | 1185 | // std::get<1>(details) = 0; // (default constructed to 0) | 
|  | 1186 | std::get<2>(details) = | 
|  | 1187 | ipmi::mappedVariant<uint8_t>(sessionProps, "CurrentPrivilege", 0); | 
|  | 1188 | // std::get<3>(details) = 0; // (default constructed to 0) | 
| Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 1189 | std::get<4>(details) = ipmi::mappedVariant<uint8_t>(sessionProps, | 
|  | 1190 | "ChannelNum", 0xff); | 
| Vernon Mauery | e7e8b81 | 2019-10-28 16:00:34 -0700 | [diff] [blame] | 1191 | constexpr uint4_t rmcpPlusProtocol = 1; | 
|  | 1192 | std::get<5>(details) = rmcpPlusProtocol; | 
| Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 1193 | std::get<6>(details) = ipmi::mappedVariant<uint32_t>(sessionProps, | 
|  | 1194 | "RemoteIPAddr", 0); | 
| Vernon Mauery | e7e8b81 | 2019-10-28 16:00:34 -0700 | [diff] [blame] | 1195 | // std::get<7>(details) = {{0}}; // default constructed to all 0 | 
| Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 1196 | std::get<8>(details) = ipmi::mappedVariant<uint16_t>(sessionProps, | 
|  | 1197 | "RemotePort", 0); | 
| Vernon Mauery | e7e8b81 | 2019-10-28 16:00:34 -0700 | [diff] [blame] | 1198 | } | 
|  | 1199 |  | 
| Rajashekar Gade Reddy | f71444d | 2019-07-25 15:12:17 +0000 | [diff] [blame] | 1200 | return ipmi::ccSuccess; | 
|  | 1201 | } | 
|  | 1202 |  | 
| Vernon Mauery | e7e8b81 | 2019-10-28 16:00:34 -0700 | [diff] [blame] | 1203 | ipmi::RspType<uint8_t, // session handle, | 
|  | 1204 | uint8_t, // total session count | 
|  | 1205 | uint8_t, // active session count | 
|  | 1206 | std::optional<SessionDetails>> | 
| Rajashekar Gade Reddy | 4d22640 | 2019-11-13 17:13:05 +0530 | [diff] [blame] | 1207 | ipmiAppGetSessionInfo(ipmi::Context::ptr ctx, uint8_t sessionIndex, | 
|  | 1208 | ipmi::message::Payload& payload) | 
| Rajashekar Gade Reddy | f71444d | 2019-07-25 15:12:17 +0000 | [diff] [blame] | 1209 | { | 
|  | 1210 | uint32_t reqSessionId = 0; | 
|  | 1211 | uint8_t reqSessionHandle = session::defaultSessionHandle; | 
|  | 1212 | // initializing state to 0xff as 0 represents state as inactive. | 
|  | 1213 | uint8_t state = 0xFF; | 
|  | 1214 |  | 
|  | 1215 | uint8_t completionCode = getSessionInfoRequestData( | 
| Rajashekar Gade Reddy | 4d22640 | 2019-11-13 17:13:05 +0530 | [diff] [blame] | 1216 | ctx, sessionIndex, payload, reqSessionId, reqSessionHandle); | 
| Rajashekar Gade Reddy | f71444d | 2019-07-25 15:12:17 +0000 | [diff] [blame] | 1217 |  | 
|  | 1218 | if (completionCode) | 
|  | 1219 | { | 
|  | 1220 | return ipmi::response(completionCode); | 
|  | 1221 | } | 
| Vernon Mauery | e7e8b81 | 2019-10-28 16:00:34 -0700 | [diff] [blame] | 1222 | ipmi::ObjectTree objectTree; | 
|  | 1223 | boost::system::error_code ec = ipmi::getAllDbusObjects( | 
|  | 1224 | ctx, session::sessionManagerRootPath, session::sessionIntf, objectTree); | 
|  | 1225 | if (ec) | 
| Rajashekar Gade Reddy | f71444d | 2019-07-25 15:12:17 +0000 | [diff] [blame] | 1226 | { | 
|  | 1227 | log<level::ERR>("Failed to fetch object from dbus", | 
|  | 1228 | entry("INTERFACE=%s", session::sessionIntf), | 
| Vernon Mauery | e7e8b81 | 2019-10-28 16:00:34 -0700 | [diff] [blame] | 1229 | entry("ERRMSG=%s", ec.message().c_str())); | 
| Rajashekar Gade Reddy | f71444d | 2019-07-25 15:12:17 +0000 | [diff] [blame] | 1230 | return ipmi::responseUnspecifiedError(); | 
|  | 1231 | } | 
|  | 1232 |  | 
| Vernon Mauery | e7e8b81 | 2019-10-28 16:00:34 -0700 | [diff] [blame] | 1233 | uint8_t totalSessionCount = getTotalSessionCount(); | 
|  | 1234 | uint8_t activeSessionCount = 0; | 
|  | 1235 | uint8_t sessionHandle = session::defaultSessionHandle; | 
| Johnathan Mantey | ca93bb1 | 2022-12-02 13:33:17 -0800 | [diff] [blame] | 1236 | uint8_t activeSessionHandle = 0; | 
| Vernon Mauery | e7e8b81 | 2019-10-28 16:00:34 -0700 | [diff] [blame] | 1237 | std::optional<SessionDetails> maybeDetails; | 
|  | 1238 | uint8_t index = 0; | 
|  | 1239 | for (auto& objectTreeItr : objectTree) | 
| Rajashekar Gade Reddy | f71444d | 2019-07-25 15:12:17 +0000 | [diff] [blame] | 1240 | { | 
| Vernon Mauery | e7e8b81 | 2019-10-28 16:00:34 -0700 | [diff] [blame] | 1241 | uint32_t sessionId = 0; | 
|  | 1242 | std::string objectPath = objectTreeItr.first; | 
|  | 1243 |  | 
|  | 1244 | if (!parseCloseSessionInputPayload(objectPath, sessionId, | 
|  | 1245 | sessionHandle)) | 
|  | 1246 | { | 
|  | 1247 | continue; | 
|  | 1248 | } | 
|  | 1249 | index++; | 
|  | 1250 | auto& serviceMap = objectTreeItr.second; | 
|  | 1251 | auto itr = serviceMap.begin(); | 
|  | 1252 |  | 
|  | 1253 | if (serviceMap.size() != 1) | 
|  | 1254 | { | 
|  | 1255 | return ipmi::responseUnspecifiedError(); | 
|  | 1256 | } | 
|  | 1257 |  | 
|  | 1258 | std::string service = itr->first; | 
|  | 1259 | uint8_t sessionState = 0; | 
| Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 1260 | completionCode = getSessionState(ctx, service, objectPath, | 
|  | 1261 | sessionState); | 
| Vernon Mauery | e7e8b81 | 2019-10-28 16:00:34 -0700 | [diff] [blame] | 1262 | if (completionCode) | 
|  | 1263 | { | 
|  | 1264 | return ipmi::response(completionCode); | 
|  | 1265 | } | 
|  | 1266 |  | 
|  | 1267 | if (sessionState == static_cast<uint8_t>(session::State::active)) | 
|  | 1268 | { | 
|  | 1269 | activeSessionCount++; | 
|  | 1270 | } | 
|  | 1271 |  | 
| Johnathan Mantey | ca93bb1 | 2022-12-02 13:33:17 -0800 | [diff] [blame] | 1272 | if (index == sessionIndex || reqSessionId == sessionId || | 
|  | 1273 | reqSessionHandle == sessionHandle) | 
| Vernon Mauery | e7e8b81 | 2019-10-28 16:00:34 -0700 | [diff] [blame] | 1274 | { | 
| Johnathan Mantey | ca93bb1 | 2022-12-02 13:33:17 -0800 | [diff] [blame] | 1275 | SessionDetails details{}; | 
|  | 1276 | completionCode = getSessionDetails(ctx, service, objectPath, | 
|  | 1277 | sessionHandle, state, details); | 
| Vernon Mauery | e7e8b81 | 2019-10-28 16:00:34 -0700 | [diff] [blame] | 1278 |  | 
| Johnathan Mantey | ca93bb1 | 2022-12-02 13:33:17 -0800 | [diff] [blame] | 1279 | if (completionCode) | 
|  | 1280 | { | 
|  | 1281 | return ipmi::response(completionCode); | 
|  | 1282 | } | 
|  | 1283 | activeSessionHandle = sessionHandle; | 
|  | 1284 | maybeDetails = std::move(details); | 
| Vernon Mauery | e7e8b81 | 2019-10-28 16:00:34 -0700 | [diff] [blame] | 1285 | } | 
| Rajashekar Gade Reddy | f71444d | 2019-07-25 15:12:17 +0000 | [diff] [blame] | 1286 | } | 
| Vernon Mauery | e7e8b81 | 2019-10-28 16:00:34 -0700 | [diff] [blame] | 1287 |  | 
|  | 1288 | if (state == static_cast<uint8_t>(session::State::active) || | 
|  | 1289 | state == static_cast<uint8_t>(session::State::tearDownInProgress)) | 
| Rajashekar Gade Reddy | f71444d | 2019-07-25 15:12:17 +0000 | [diff] [blame] | 1290 | { | 
| Johnathan Mantey | ca93bb1 | 2022-12-02 13:33:17 -0800 | [diff] [blame] | 1291 | return ipmi::responseSuccess(activeSessionHandle, totalSessionCount, | 
| Vernon Mauery | e7e8b81 | 2019-10-28 16:00:34 -0700 | [diff] [blame] | 1292 | activeSessionCount, maybeDetails); | 
| Rajashekar Gade Reddy | f71444d | 2019-07-25 15:12:17 +0000 | [diff] [blame] | 1293 | } | 
|  | 1294 |  | 
|  | 1295 | return ipmi::responseInvalidFieldRequest(); | 
|  | 1296 | } | 
|  | 1297 |  | 
| Xo Wang | f542e8b | 2017-08-09 15:34:16 -0700 | [diff] [blame] | 1298 | static std::unique_ptr<SysInfoParamStore> sysInfoParamStore; | 
|  | 1299 |  | 
| Xo Wang | 8765133 | 2017-08-11 10:17:59 -0700 | [diff] [blame] | 1300 | static std::string sysInfoReadSystemName() | 
|  | 1301 | { | 
|  | 1302 | // Use the BMC hostname as the "System Name." | 
|  | 1303 | char hostname[HOST_NAME_MAX + 1] = {}; | 
|  | 1304 | if (gethostname(hostname, HOST_NAME_MAX) != 0) | 
|  | 1305 | { | 
|  | 1306 | perror("System info parameter: system name"); | 
|  | 1307 | } | 
|  | 1308 | return hostname; | 
|  | 1309 | } | 
|  | 1310 |  | 
| Jia, chunhui | 98b43ba | 2019-09-05 15:54:23 +0800 | [diff] [blame] | 1311 | static constexpr uint8_t paramRevision = 0x11; | 
|  | 1312 | static constexpr size_t configParameterLength = 16; | 
| Xo Wang | f542e8b | 2017-08-09 15:34:16 -0700 | [diff] [blame] | 1313 |  | 
| Jia, chunhui | 98b43ba | 2019-09-05 15:54:23 +0800 | [diff] [blame] | 1314 | static constexpr size_t smallChunkSize = 14; | 
|  | 1315 | static constexpr size_t fullChunkSize = 16; | 
| Jia, chunhui | 449f216 | 2019-09-11 16:51:51 +0800 | [diff] [blame] | 1316 | static constexpr uint8_t progressMask = 0x3; | 
| krishnar4 | 1075283 | 2023-11-06 13:58:35 +0530 | [diff] [blame] | 1317 | static constexpr uint8_t maxValidEncodingData = 0x02; | 
| Xo Wang | f542e8b | 2017-08-09 15:34:16 -0700 | [diff] [blame] | 1318 |  | 
| Jia, chunhui | 98b43ba | 2019-09-05 15:54:23 +0800 | [diff] [blame] | 1319 | static constexpr uint8_t setComplete = 0x0; | 
|  | 1320 | static constexpr uint8_t setInProgress = 0x1; | 
|  | 1321 | static constexpr uint8_t commitWrite = 0x2; | 
|  | 1322 | static uint8_t transferStatus = setComplete; | 
|  | 1323 |  | 
| Jia, chunhui | 449f216 | 2019-09-11 16:51:51 +0800 | [diff] [blame] | 1324 | static constexpr uint8_t configDataOverhead = 2; | 
|  | 1325 |  | 
|  | 1326 | // For EFI based system, 256 bytes is recommended. | 
|  | 1327 | static constexpr size_t maxBytesPerParameter = 256; | 
|  | 1328 |  | 
| Jia, chunhui | 98b43ba | 2019-09-05 15:54:23 +0800 | [diff] [blame] | 1329 | namespace ipmi | 
|  | 1330 | { | 
|  | 1331 | constexpr Cc ccParmNotSupported = 0x80; | 
| Jia, chunhui | 449f216 | 2019-09-11 16:51:51 +0800 | [diff] [blame] | 1332 | constexpr Cc ccSetInProgressActive = 0x81; | 
|  | 1333 | constexpr Cc ccSystemInfoParameterSetReadOnly = 0x82; | 
| Jia, chunhui | 98b43ba | 2019-09-05 15:54:23 +0800 | [diff] [blame] | 1334 |  | 
|  | 1335 | static inline auto responseParmNotSupported() | 
|  | 1336 | { | 
|  | 1337 | return response(ccParmNotSupported); | 
| Xo Wang | f542e8b | 2017-08-09 15:34:16 -0700 | [diff] [blame] | 1338 | } | 
| Jia, chunhui | 449f216 | 2019-09-11 16:51:51 +0800 | [diff] [blame] | 1339 | static inline auto responseSetInProgressActive() | 
|  | 1340 | { | 
|  | 1341 | return response(ccSetInProgressActive); | 
|  | 1342 | } | 
|  | 1343 | static inline auto responseSystemInfoParameterSetReadOnly() | 
|  | 1344 | { | 
|  | 1345 | return response(ccSystemInfoParameterSetReadOnly); | 
|  | 1346 | } | 
| Jia, chunhui | 98b43ba | 2019-09-05 15:54:23 +0800 | [diff] [blame] | 1347 | } // namespace ipmi | 
| Xo Wang | f542e8b | 2017-08-09 15:34:16 -0700 | [diff] [blame] | 1348 |  | 
| Jia, chunhui | 449f216 | 2019-09-11 16:51:51 +0800 | [diff] [blame] | 1349 | ipmi::RspType<uint8_t,                // Parameter revision | 
|  | 1350 | std::optional<uint8_t>, // data1 / setSelector / ProgressStatus | 
|  | 1351 | std::optional<std::vector<uint8_t>>> // data2-17 | 
| jayaprakash Mutyala | c2566a9 | 2020-04-23 21:18:35 +0000 | [diff] [blame] | 1352 | ipmiAppGetSystemInfo(uint7_t reserved, bool getRevision, | 
|  | 1353 | uint8_t paramSelector, uint8_t setSelector, | 
|  | 1354 | uint8_t BlockSelector) | 
| Xo Wang | f542e8b | 2017-08-09 15:34:16 -0700 | [diff] [blame] | 1355 | { | 
| Snehalatha V | a5ae772 | 2020-05-02 18:18:57 +0000 | [diff] [blame] | 1356 | if (reserved || (paramSelector >= invalidParamSelectorStart && | 
|  | 1357 | paramSelector <= invalidParamSelectorEnd)) | 
| jayaprakash Mutyala | c2566a9 | 2020-04-23 21:18:35 +0000 | [diff] [blame] | 1358 | { | 
|  | 1359 | return ipmi::responseInvalidFieldRequest(); | 
|  | 1360 | } | 
| PavanKumarIntel | 3771f5f | 2023-11-02 06:26:42 +0000 | [diff] [blame] | 1361 | if (paramSelector >= oemCmdStart) | 
| Snehalatha V | a5ae772 | 2020-05-02 18:18:57 +0000 | [diff] [blame] | 1362 | { | 
|  | 1363 | return ipmi::responseParmNotSupported(); | 
|  | 1364 | } | 
| jayaprakash Mutyala | c2566a9 | 2020-04-23 21:18:35 +0000 | [diff] [blame] | 1365 | if (getRevision) | 
| Xo Wang | f542e8b | 2017-08-09 15:34:16 -0700 | [diff] [blame] | 1366 | { | 
| Jia, chunhui | 98b43ba | 2019-09-05 15:54:23 +0800 | [diff] [blame] | 1367 | return ipmi::responseSuccess(paramRevision, std::nullopt, std::nullopt); | 
| Xo Wang | f542e8b | 2017-08-09 15:34:16 -0700 | [diff] [blame] | 1368 | } | 
|  | 1369 |  | 
| Jia, chunhui | 98b43ba | 2019-09-05 15:54:23 +0800 | [diff] [blame] | 1370 | if (paramSelector == 0) | 
| Xo Wang | f542e8b | 2017-08-09 15:34:16 -0700 | [diff] [blame] | 1371 | { | 
| Jia, chunhui | 98b43ba | 2019-09-05 15:54:23 +0800 | [diff] [blame] | 1372 | return ipmi::responseSuccess(paramRevision, transferStatus, | 
|  | 1373 | std::nullopt); | 
| Xo Wang | f542e8b | 2017-08-09 15:34:16 -0700 | [diff] [blame] | 1374 | } | 
|  | 1375 |  | 
| Jia, chunhui | 98b43ba | 2019-09-05 15:54:23 +0800 | [diff] [blame] | 1376 | if (BlockSelector != 0) // 00h if parameter does not require a block number | 
| Xo Wang | f542e8b | 2017-08-09 15:34:16 -0700 | [diff] [blame] | 1377 | { | 
| Jia, chunhui | 98b43ba | 2019-09-05 15:54:23 +0800 | [diff] [blame] | 1378 | return ipmi::responseParmNotSupported(); | 
| Xo Wang | f542e8b | 2017-08-09 15:34:16 -0700 | [diff] [blame] | 1379 | } | 
|  | 1380 |  | 
|  | 1381 | if (sysInfoParamStore == nullptr) | 
|  | 1382 | { | 
|  | 1383 | sysInfoParamStore = std::make_unique<SysInfoParamStore>(); | 
| Xo Wang | 8765133 | 2017-08-11 10:17:59 -0700 | [diff] [blame] | 1384 | sysInfoParamStore->update(IPMI_SYSINFO_SYSTEM_NAME, | 
|  | 1385 | sysInfoReadSystemName); | 
| Xo Wang | f542e8b | 2017-08-09 15:34:16 -0700 | [diff] [blame] | 1386 | } | 
|  | 1387 |  | 
|  | 1388 | // Parameters other than Set In Progress are assumed to be strings. | 
| Jia, chunhui | 98b43ba | 2019-09-05 15:54:23 +0800 | [diff] [blame] | 1389 | std::tuple<bool, std::string> ret = | 
|  | 1390 | sysInfoParamStore->lookup(paramSelector); | 
|  | 1391 | bool found = std::get<0>(ret); | 
| Xo Wang | f542e8b | 2017-08-09 15:34:16 -0700 | [diff] [blame] | 1392 | if (!found) | 
|  | 1393 | { | 
| Snehalatha V | a5ae772 | 2020-05-02 18:18:57 +0000 | [diff] [blame] | 1394 | return ipmi::responseSensorInvalid(); | 
| Xo Wang | f542e8b | 2017-08-09 15:34:16 -0700 | [diff] [blame] | 1395 | } | 
| Jia, chunhui | 98b43ba | 2019-09-05 15:54:23 +0800 | [diff] [blame] | 1396 | std::string& paramString = std::get<1>(ret); | 
| Jia, chunhui | 449f216 | 2019-09-11 16:51:51 +0800 | [diff] [blame] | 1397 | std::vector<uint8_t> configData; | 
| Jia, chunhui | 98b43ba | 2019-09-05 15:54:23 +0800 | [diff] [blame] | 1398 | size_t count = 0; | 
|  | 1399 | if (setSelector == 0) | 
| Jia, chunhui | 449f216 | 2019-09-11 16:51:51 +0800 | [diff] [blame] | 1400 | {                               // First chunk has only 14 bytes. | 
|  | 1401 | configData.emplace_back(0); // encoding | 
|  | 1402 | configData.emplace_back(paramString.length()); // string length | 
|  | 1403 | count = std::min(paramString.length(), smallChunkSize); | 
|  | 1404 | configData.resize(count + configDataOverhead); | 
| Jia, chunhui | 98b43ba | 2019-09-05 15:54:23 +0800 | [diff] [blame] | 1405 | std::copy_n(paramString.begin(), count, | 
| Snehalatha V | a5ae772 | 2020-05-02 18:18:57 +0000 | [diff] [blame] | 1406 | configData.begin() + configDataOverhead); // 14 bytes chunk | 
|  | 1407 |  | 
|  | 1408 | // Append zero's to remaining bytes | 
|  | 1409 | if (configData.size() < configParameterLength) | 
|  | 1410 | { | 
|  | 1411 | std::fill_n(std::back_inserter(configData), | 
|  | 1412 | configParameterLength - configData.size(), 0x00); | 
|  | 1413 | } | 
| Jia, chunhui | 98b43ba | 2019-09-05 15:54:23 +0800 | [diff] [blame] | 1414 | } | 
|  | 1415 | else | 
| Xo Wang | f542e8b | 2017-08-09 15:34:16 -0700 | [diff] [blame] | 1416 | { | 
| Jia, chunhui | 449f216 | 2019-09-11 16:51:51 +0800 | [diff] [blame] | 1417 | size_t offset = (setSelector * fullChunkSize) - configDataOverhead; | 
| Jia, chunhui | 98b43ba | 2019-09-05 15:54:23 +0800 | [diff] [blame] | 1418 | if (offset >= paramString.length()) | 
|  | 1419 | { | 
|  | 1420 | return ipmi::responseParmOutOfRange(); | 
|  | 1421 | } | 
| Jia, chunhui | 449f216 | 2019-09-11 16:51:51 +0800 | [diff] [blame] | 1422 | count = std::min(paramString.length() - offset, fullChunkSize); | 
|  | 1423 | configData.resize(count); | 
| Jia, chunhui | 98b43ba | 2019-09-05 15:54:23 +0800 | [diff] [blame] | 1424 | std::copy_n(paramString.begin() + offset, count, | 
|  | 1425 | configData.begin()); // 16 bytes chunk | 
| Xo Wang | f542e8b | 2017-08-09 15:34:16 -0700 | [diff] [blame] | 1426 | } | 
| Jia, chunhui | 98b43ba | 2019-09-05 15:54:23 +0800 | [diff] [blame] | 1427 | return ipmi::responseSuccess(paramRevision, setSelector, configData); | 
| Xo Wang | f542e8b | 2017-08-09 15:34:16 -0700 | [diff] [blame] | 1428 | } | 
|  | 1429 |  | 
| Jia, chunhui | 449f216 | 2019-09-11 16:51:51 +0800 | [diff] [blame] | 1430 | ipmi::RspType<> ipmiAppSetSystemInfo(uint8_t paramSelector, uint8_t data1, | 
|  | 1431 | std::vector<uint8_t> configData) | 
|  | 1432 | { | 
| jayaprakash Mutyala | 3c5e413 | 2020-04-27 23:00:05 +0000 | [diff] [blame] | 1433 | if (paramSelector >= invalidParamSelectorStart && | 
|  | 1434 | paramSelector <= invalidParamSelectorEnd) | 
|  | 1435 | { | 
|  | 1436 | return ipmi::responseInvalidFieldRequest(); | 
|  | 1437 | } | 
| PavanKumarIntel | 3771f5f | 2023-11-02 06:26:42 +0000 | [diff] [blame] | 1438 | if (paramSelector >= oemCmdStart) | 
| jayaprakash Mutyala | 3c5e413 | 2020-04-27 23:00:05 +0000 | [diff] [blame] | 1439 | { | 
|  | 1440 | return ipmi::responseParmNotSupported(); | 
|  | 1441 | } | 
|  | 1442 |  | 
| Jia, chunhui | 449f216 | 2019-09-11 16:51:51 +0800 | [diff] [blame] | 1443 | if (paramSelector == 0) | 
|  | 1444 | { | 
|  | 1445 | // attempt to set the 'set in progress' value (in parameter #0) | 
|  | 1446 | // when not in the set complete state. | 
|  | 1447 | if ((transferStatus != setComplete) && (data1 == setInProgress)) | 
|  | 1448 | { | 
|  | 1449 | return ipmi::responseSetInProgressActive(); | 
|  | 1450 | } | 
|  | 1451 | // only following 2 states are supported | 
|  | 1452 | if (data1 > setInProgress) | 
|  | 1453 | { | 
|  | 1454 | phosphor::logging::log<phosphor::logging::level::ERR>( | 
|  | 1455 | "illegal SetInProgress status"); | 
|  | 1456 | return ipmi::responseInvalidFieldRequest(); | 
|  | 1457 | } | 
|  | 1458 |  | 
|  | 1459 | transferStatus = data1 & progressMask; | 
|  | 1460 | return ipmi::responseSuccess(); | 
|  | 1461 | } | 
|  | 1462 |  | 
|  | 1463 | if (configData.size() > configParameterLength) | 
|  | 1464 | { | 
|  | 1465 | return ipmi::responseInvalidFieldRequest(); | 
|  | 1466 | } | 
|  | 1467 |  | 
| jayaprakash Mutyala | 3c5e413 | 2020-04-27 23:00:05 +0000 | [diff] [blame] | 1468 | // Append zero's to remaining bytes | 
|  | 1469 | if (configData.size() < configParameterLength) | 
|  | 1470 | { | 
|  | 1471 | fill_n(back_inserter(configData), | 
|  | 1472 | (configParameterLength - configData.size()), 0x00); | 
|  | 1473 | } | 
|  | 1474 |  | 
| Jia, chunhui | 449f216 | 2019-09-11 16:51:51 +0800 | [diff] [blame] | 1475 | if (!sysInfoParamStore) | 
|  | 1476 | { | 
|  | 1477 | sysInfoParamStore = std::make_unique<SysInfoParamStore>(); | 
|  | 1478 | sysInfoParamStore->update(IPMI_SYSINFO_SYSTEM_NAME, | 
|  | 1479 | sysInfoReadSystemName); | 
|  | 1480 | } | 
|  | 1481 |  | 
|  | 1482 | // lookup | 
|  | 1483 | std::tuple<bool, std::string> ret = | 
|  | 1484 | sysInfoParamStore->lookup(paramSelector); | 
|  | 1485 | bool found = std::get<0>(ret); | 
|  | 1486 | std::string& paramString = std::get<1>(ret); | 
|  | 1487 | if (!found) | 
|  | 1488 | { | 
|  | 1489 | // parameter does not exist. Init new | 
|  | 1490 | paramString = ""; | 
|  | 1491 | } | 
|  | 1492 |  | 
|  | 1493 | uint8_t setSelector = data1; | 
|  | 1494 | size_t count = 0; | 
| krishnar4 | 1075283 | 2023-11-06 13:58:35 +0530 | [diff] [blame] | 1495 | if (setSelector == 0) // First chunk has only 14 bytes. | 
| Jia, chunhui | 449f216 | 2019-09-11 16:51:51 +0800 | [diff] [blame] | 1496 | { | 
| krishnar4 | 1075283 | 2023-11-06 13:58:35 +0530 | [diff] [blame] | 1497 | uint8_t encoding = configData.at(0); | 
|  | 1498 | if (encoding > maxValidEncodingData) | 
|  | 1499 | { | 
|  | 1500 | return ipmi::responseInvalidFieldRequest(); | 
|  | 1501 | } | 
|  | 1502 |  | 
| Jia, chunhui | 449f216 | 2019-09-11 16:51:51 +0800 | [diff] [blame] | 1503 | size_t stringLen = configData.at(1); // string length | 
|  | 1504 | // maxBytesPerParamter is 256. It will always be greater than stringLen | 
|  | 1505 | // (unit8_t) if maxBytes changes in future, then following line is | 
|  | 1506 | // needed. | 
|  | 1507 | // stringLen = std::min(stringLen, maxBytesPerParameter); | 
|  | 1508 | count = std::min(stringLen, smallChunkSize); | 
|  | 1509 | count = std::min(count, configData.size()); | 
|  | 1510 | paramString.resize(stringLen); // reserve space | 
|  | 1511 | std::copy_n(configData.begin() + configDataOverhead, count, | 
|  | 1512 | paramString.begin()); | 
|  | 1513 | } | 
|  | 1514 | else | 
|  | 1515 | { | 
|  | 1516 | size_t offset = (setSelector * fullChunkSize) - configDataOverhead; | 
|  | 1517 | if (offset >= paramString.length()) | 
|  | 1518 | { | 
|  | 1519 | return ipmi::responseParmOutOfRange(); | 
|  | 1520 | } | 
|  | 1521 | count = std::min(paramString.length() - offset, configData.size()); | 
|  | 1522 | std::copy_n(configData.begin(), count, paramString.begin() + offset); | 
|  | 1523 | } | 
|  | 1524 | sysInfoParamStore->update(paramSelector, paramString); | 
|  | 1525 | return ipmi::responseSuccess(); | 
|  | 1526 | } | 
|  | 1527 |  | 
| Yong Li | bd0503a | 2019-08-22 17:17:17 +0800 | [diff] [blame] | 1528 | #ifdef ENABLE_I2C_WHITELIST_CHECK | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1529 | inline std::vector<uint8_t> convertStringToData(const std::string& command) | 
|  | 1530 | { | 
|  | 1531 | std::istringstream iss(command); | 
|  | 1532 | std::string token; | 
|  | 1533 | std::vector<uint8_t> dataValue; | 
|  | 1534 | while (std::getline(iss, token, ' ')) | 
|  | 1535 | { | 
|  | 1536 | dataValue.emplace_back( | 
|  | 1537 | static_cast<uint8_t>(std::stoul(token, nullptr, base_16))); | 
|  | 1538 | } | 
|  | 1539 | return dataValue; | 
|  | 1540 | } | 
|  | 1541 |  | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1542 | static bool populateI2CControllerWRAllowlist() | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1543 | { | 
|  | 1544 | nlohmann::json data = nullptr; | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1545 | std::ifstream jsonFile(i2cControllerWRAllowlistFile); | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1546 |  | 
|  | 1547 | if (!jsonFile.good()) | 
|  | 1548 | { | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1549 | log<level::WARNING>( | 
|  | 1550 | "i2c allow list file not found!", | 
|  | 1551 | entry("FILE_NAME: %s", i2cControllerWRAllowlistFile)); | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1552 | return false; | 
|  | 1553 | } | 
|  | 1554 |  | 
|  | 1555 | try | 
|  | 1556 | { | 
|  | 1557 | data = nlohmann::json::parse(jsonFile, nullptr, false); | 
|  | 1558 | } | 
| Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 1559 | catch (const nlohmann::json::parse_error& e) | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1560 | { | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1561 | log<level::ERR>("Corrupted i2c allow list config file", | 
|  | 1562 | entry("FILE_NAME: %s", i2cControllerWRAllowlistFile), | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1563 | entry("MSG: %s", e.what())); | 
|  | 1564 | return false; | 
|  | 1565 | } | 
|  | 1566 |  | 
|  | 1567 | try | 
|  | 1568 | { | 
|  | 1569 | // Example JSON Structure format | 
|  | 1570 | // "filters": [ | 
|  | 1571 | //    { | 
|  | 1572 | //      "Description": "Allow full read - ignore first byte write value | 
|  | 1573 | //      for 0x40 to 0x4F", | 
|  | 1574 | //      "busId": "0x01", | 
|  | 1575 | //      "slaveAddr": "0x40", | 
|  | 1576 | //      "slaveAddrMask": "0x0F", | 
|  | 1577 | //      "command": "0x00", | 
|  | 1578 | //      "commandMask": "0xFF" | 
|  | 1579 | //    }, | 
|  | 1580 | //    { | 
|  | 1581 | //      "Description": "Allow full read - first byte match 0x05 and | 
|  | 1582 | //      ignore second byte", | 
|  | 1583 | //      "busId": "0x01", | 
|  | 1584 | //      "slaveAddr": "0x57", | 
|  | 1585 | //      "slaveAddrMask": "0x00", | 
|  | 1586 | //      "command": "0x05 0x00", | 
|  | 1587 | //      "commandMask": "0x00 0xFF" | 
|  | 1588 | //    },] | 
|  | 1589 |  | 
|  | 1590 | nlohmann::json filters = data[filtersStr].get<nlohmann::json>(); | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1591 | std::vector<i2cControllerWRAllowlist>& allowlist = getWRAllowlist(); | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1592 | for (const auto& it : filters.items()) | 
|  | 1593 | { | 
|  | 1594 | nlohmann::json filter = it.value(); | 
|  | 1595 | if (filter.is_null()) | 
|  | 1596 | { | 
|  | 1597 | log<level::ERR>( | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1598 | "Corrupted I2C controller write read allowlist config file", | 
|  | 1599 | entry("FILE_NAME: %s", i2cControllerWRAllowlistFile)); | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1600 | return false; | 
|  | 1601 | } | 
|  | 1602 | const std::vector<uint8_t>& writeData = | 
|  | 1603 | convertStringToData(filter[cmdStr].get<std::string>()); | 
|  | 1604 | const std::vector<uint8_t>& writeDataMask = | 
|  | 1605 | convertStringToData(filter[cmdMaskStr].get<std::string>()); | 
|  | 1606 | if (writeDataMask.size() != writeData.size()) | 
|  | 1607 | { | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1608 | log<level::ERR>("I2C controller write read allowlist filter " | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1609 | "mismatch for command & mask size"); | 
|  | 1610 | return false; | 
|  | 1611 | } | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1612 | allowlist.push_back( | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1613 | {static_cast<uint8_t>(std::stoul( | 
|  | 1614 | filter[busIdStr].get<std::string>(), nullptr, base_16)), | 
|  | 1615 | static_cast<uint8_t>( | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1616 | std::stoul(filter[targetAddrStr].get<std::string>(), | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1617 | nullptr, base_16)), | 
|  | 1618 | static_cast<uint8_t>( | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1619 | std::stoul(filter[targetAddrMaskStr].get<std::string>(), | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1620 | nullptr, base_16)), | 
|  | 1621 | writeData, writeDataMask}); | 
|  | 1622 | } | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1623 | if (allowlist.size() != filters.size()) | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1624 | { | 
|  | 1625 | log<level::ERR>( | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1626 | "I2C controller write read allowlist filter size mismatch"); | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1627 | return false; | 
|  | 1628 | } | 
|  | 1629 | } | 
| Patrick Williams | a2ad2da | 2021-10-06 12:21:46 -0500 | [diff] [blame] | 1630 | catch (const std::exception& e) | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1631 | { | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1632 | log<level::ERR>( | 
|  | 1633 | "I2C controller write read allowlist unexpected exception", | 
|  | 1634 | entry("ERROR=%s", e.what())); | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1635 | return false; | 
|  | 1636 | } | 
|  | 1637 | return true; | 
|  | 1638 | } | 
|  | 1639 |  | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1640 | static inline bool isWriteDataAllowlisted(const std::vector<uint8_t>& data, | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1641 | const std::vector<uint8_t>& dataMask, | 
|  | 1642 | const std::vector<uint8_t>& writeData) | 
|  | 1643 | { | 
|  | 1644 | std::vector<uint8_t> processedDataBuf(data.size()); | 
|  | 1645 | std::vector<uint8_t> processedReqBuf(dataMask.size()); | 
|  | 1646 | std::transform(writeData.begin(), writeData.end(), dataMask.begin(), | 
|  | 1647 | processedReqBuf.begin(), std::bit_or<uint8_t>()); | 
|  | 1648 | std::transform(data.begin(), data.end(), dataMask.begin(), | 
|  | 1649 | processedDataBuf.begin(), std::bit_or<uint8_t>()); | 
|  | 1650 |  | 
|  | 1651 | return (processedDataBuf == processedReqBuf); | 
|  | 1652 | } | 
|  | 1653 |  | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1654 | static bool isCmdAllowlisted(uint8_t busId, uint8_t targetAddr, | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1655 | std::vector<uint8_t>& writeData) | 
|  | 1656 | { | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1657 | std::vector<i2cControllerWRAllowlist>& allowList = getWRAllowlist(); | 
|  | 1658 | for (const auto& wlEntry : allowList) | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1659 | { | 
|  | 1660 | if ((busId == wlEntry.busId) && | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1661 | ((targetAddr | wlEntry.targetAddrMask) == | 
|  | 1662 | (wlEntry.targetAddr | wlEntry.targetAddrMask))) | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1663 | { | 
|  | 1664 | const std::vector<uint8_t>& dataMask = wlEntry.dataMask; | 
|  | 1665 | // Skip as no-match, if requested write data is more than the | 
|  | 1666 | // write data mask size | 
|  | 1667 | if (writeData.size() > dataMask.size()) | 
|  | 1668 | { | 
|  | 1669 | continue; | 
|  | 1670 | } | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1671 | if (isWriteDataAllowlisted(wlEntry.data, dataMask, writeData)) | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1672 | { | 
|  | 1673 | return true; | 
|  | 1674 | } | 
|  | 1675 | } | 
|  | 1676 | } | 
|  | 1677 | return false; | 
|  | 1678 | } | 
| Yong Li | bd0503a | 2019-08-22 17:17:17 +0800 | [diff] [blame] | 1679 | #else | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1680 | static bool populateI2CControllerWRAllowlist() | 
| Yong Li | bd0503a | 2019-08-22 17:17:17 +0800 | [diff] [blame] | 1681 | { | 
|  | 1682 | log<level::INFO>( | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1683 | "I2C_WHITELIST_CHECK is disabled, do not populate allowlist"); | 
| Yong Li | bd0503a | 2019-08-22 17:17:17 +0800 | [diff] [blame] | 1684 | return true; | 
|  | 1685 | } | 
|  | 1686 | #endif // ENABLE_I2C_WHITELIST_CHECK | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1687 |  | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1688 | /** @brief implements controller write read IPMI command which can be used for | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1689 | * low-level I2C/SMBus write, read or write-read access | 
|  | 1690 | *  @param isPrivateBus -to indicate private bus usage | 
|  | 1691 | *  @param busId - bus id | 
|  | 1692 | *  @param channelNum - channel number | 
|  | 1693 | *  @param reserved - skip 1 bit | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1694 | *  @param targetAddr - target address | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1695 | *  @param read count - number of bytes to be read | 
|  | 1696 | *  @param writeData - data to be written | 
|  | 1697 | * | 
|  | 1698 | *  @returns IPMI completion code plus response data | 
|  | 1699 | *   - readData - i2c response data | 
|  | 1700 | */ | 
|  | 1701 | ipmi::RspType<std::vector<uint8_t>> | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1702 | ipmiControllerWriteRead([[maybe_unused]] bool isPrivateBus, uint3_t busId, | 
|  | 1703 | [[maybe_unused]] uint4_t channelNum, bool reserved, | 
|  | 1704 | uint7_t targetAddr, uint8_t readCount, | 
|  | 1705 | std::vector<uint8_t> writeData) | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1706 | { | 
| Jayaprakash Mutyala | c2af98b | 2021-09-14 09:19:11 +0000 | [diff] [blame] | 1707 | if (reserved) | 
|  | 1708 | { | 
|  | 1709 | return ipmi::responseInvalidFieldRequest(); | 
|  | 1710 | } | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1711 | const size_t writeCount = writeData.size(); | 
|  | 1712 | if (!readCount && !writeCount) | 
|  | 1713 | { | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1714 | log<level::ERR>( | 
|  | 1715 | "Controller write read command: Read & write count are 0"); | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1716 | return ipmi::responseInvalidFieldRequest(); | 
|  | 1717 | } | 
| Yong Li | bd0503a | 2019-08-22 17:17:17 +0800 | [diff] [blame] | 1718 | #ifdef ENABLE_I2C_WHITELIST_CHECK | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1719 | if (!isCmdAllowlisted(static_cast<uint8_t>(busId), | 
|  | 1720 | static_cast<uint8_t>(targetAddr), writeData)) | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1721 | { | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1722 | log<level::ERR>("Controller write read request blocked!", | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1723 | entry("BUS=%d", static_cast<uint8_t>(busId)), | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1724 | entry("ADDR=0x%x", static_cast<uint8_t>(targetAddr))); | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1725 | return ipmi::responseInvalidFieldRequest(); | 
|  | 1726 | } | 
| Yong Li | bd0503a | 2019-08-22 17:17:17 +0800 | [diff] [blame] | 1727 | #endif // ENABLE_I2C_WHITELIST_CHECK | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1728 | std::vector<uint8_t> readBuf(readCount); | 
| Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 1729 | std::string i2cBus = "/dev/i2c-" + | 
|  | 1730 | std::to_string(static_cast<uint8_t>(busId)); | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1731 |  | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1732 | ipmi::Cc ret = ipmi::i2cWriteRead(i2cBus, static_cast<uint8_t>(targetAddr), | 
| Yong Li | 7dc4ac0 | 2019-08-23 17:44:32 +0800 | [diff] [blame] | 1733 | writeData, readBuf); | 
|  | 1734 | if (ret != ipmi::ccSuccess) | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1735 | { | 
| Yong Li | 7dc4ac0 | 2019-08-23 17:44:32 +0800 | [diff] [blame] | 1736 | return ipmi::response(ret); | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1737 | } | 
|  | 1738 | return ipmi::responseSuccess(readBuf); | 
|  | 1739 | } | 
|  | 1740 |  | 
| Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 1741 | void register_netfn_app_functions() | 
| vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 1742 | { | 
| Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 1743 | // <Get Device ID> | 
|  | 1744 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, | 
|  | 1745 | ipmi::app::cmdGetDeviceId, ipmi::Privilege::User, | 
|  | 1746 | ipmiAppGetDeviceId); | 
|  | 1747 |  | 
| Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1748 | // <Get BT Interface Capabilities> | 
| Vernon Mauery | cc99ba4 | 2019-03-25 13:40:11 -0700 | [diff] [blame] | 1749 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, | 
|  | 1750 | ipmi::app::cmdGetBtIfaceCapabilities, | 
|  | 1751 | ipmi::Privilege::User, ipmiAppGetBtCapabilities); | 
| Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 1752 |  | 
| Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1753 | // <Reset Watchdog Timer> | 
| Vernon Mauery | 11df4f6 | 2019-03-25 14:17:54 -0700 | [diff] [blame] | 1754 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, | 
|  | 1755 | ipmi::app::cmdResetWatchdogTimer, | 
|  | 1756 | ipmi::Privilege::Operator, ipmiAppResetWatchdogTimer); | 
| Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 1757 |  | 
| Rajashekar Gade Reddy | f71444d | 2019-07-25 15:12:17 +0000 | [diff] [blame] | 1758 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, | 
| AppaRao Puli | 5a98ea6 | 2019-11-10 21:15:02 +0530 | [diff] [blame] | 1759 | ipmi::app::cmdGetSessionInfo, ipmi::Privilege::User, | 
|  | 1760 | ipmiAppGetSessionInfo); | 
| Rajashekar Gade Reddy | f71444d | 2019-07-25 15:12:17 +0000 | [diff] [blame] | 1761 |  | 
| Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1762 | // <Set Watchdog Timer> | 
| Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 1763 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, | 
|  | 1764 | ipmi::app::cmdSetWatchdogTimer, | 
|  | 1765 | ipmi::Privilege::Operator, ipmiSetWatchdogTimer); | 
| Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 1766 |  | 
| Rajashekar Gade Reddy | e702392 | 2019-07-10 16:54:55 +0000 | [diff] [blame] | 1767 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, | 
|  | 1768 | ipmi::app::cmdCloseSession, ipmi::Privilege::Callback, | 
|  | 1769 | ipmiAppCloseSession); | 
|  | 1770 |  | 
| William A. Kennington III | 73f4451 | 2018-02-09 15:28:46 -0800 | [diff] [blame] | 1771 | // <Get Watchdog Timer> | 
| Deepak Kumar Sahu | cfae948 | 2019-05-20 14:58:58 +0000 | [diff] [blame] | 1772 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, | 
| AppaRao Puli | 5a98ea6 | 2019-11-10 21:15:02 +0530 | [diff] [blame] | 1773 | ipmi::app::cmdGetWatchdogTimer, ipmi::Privilege::User, | 
|  | 1774 | ipmiGetWatchdogTimer); | 
| William A. Kennington III | 73f4451 | 2018-02-09 15:28:46 -0800 | [diff] [blame] | 1775 |  | 
| Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1776 | // <Get Self Test Results> | 
| Vernon Mauery | b84a528 | 2019-03-25 13:39:03 -0700 | [diff] [blame] | 1777 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, | 
|  | 1778 | ipmi::app::cmdGetSelfTestResults, | 
|  | 1779 | ipmi::Privilege::User, ipmiAppGetSelfTestResults); | 
| Nan Li | 41fa24a | 2016-11-10 20:12:37 +0800 | [diff] [blame] | 1780 |  | 
| Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1781 | // <Get Device GUID> | 
| Vernon Mauery | 1554132 | 2019-03-25 13:33:03 -0700 | [diff] [blame] | 1782 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, | 
|  | 1783 | ipmi::app::cmdGetDeviceGuid, ipmi::Privilege::User, | 
|  | 1784 | ipmiAppGetDeviceGuid); | 
| Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 1785 |  | 
| Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1786 | // <Set ACPI Power State> | 
| Deepak Kumar Sahu | 520c131 | 2019-05-17 18:14:09 +0000 | [diff] [blame] | 1787 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, | 
|  | 1788 | ipmi::app::cmdSetAcpiPowerState, | 
|  | 1789 | ipmi::Privilege::Admin, ipmiSetAcpiPowerState); | 
| Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 1790 | // <Get ACPI Power State> | 
| Deepak Kumar Sahu | 4e6d257 | 2019-05-07 19:53:37 +0000 | [diff] [blame] | 1791 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, | 
|  | 1792 | ipmi::app::cmdGetAcpiPowerState, | 
| AppaRao Puli | 5a98ea6 | 2019-11-10 21:15:02 +0530 | [diff] [blame] | 1793 | ipmi::Privilege::User, ipmiGetAcpiPowerState); | 
| Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 1794 |  | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1795 | // Note: For security reason, this command will be registered only when | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1796 | // there are proper I2C Controller write read allowlist | 
|  | 1797 | if (populateI2CControllerWRAllowlist()) | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1798 | { | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1799 | // Note: For security reasons, registering controller write read as | 
|  | 1800 | // admin privilege command, even though IPMI 2.0 specification allows it | 
|  | 1801 | // as operator privilege. | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1802 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, | 
|  | 1803 | ipmi::app::cmdMasterWriteRead, | 
| Matt Simmering | 68d9d40 | 2023-11-09 14:22:11 -0800 | [diff] [blame] | 1804 | ipmi::Privilege::Admin, ipmiControllerWriteRead); | 
| Richard Marian Thomaiyar | 84bf9be | 2019-04-26 22:59:16 +0530 | [diff] [blame] | 1805 | } | 
|  | 1806 |  | 
| Marri Devender Rao | 5e007a5 | 2018-01-08 06:18:36 -0600 | [diff] [blame] | 1807 | // <Get System GUID Command> | 
| Vernon Mauery | b90a532 | 2019-03-25 13:36:55 -0700 | [diff] [blame] | 1808 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, | 
|  | 1809 | ipmi::app::cmdGetSystemGuid, ipmi::Privilege::User, | 
|  | 1810 | ipmiAppGetSystemGuid); | 
| Tom Joseph | 7cbe228 | 2018-03-21 21:17:33 +0530 | [diff] [blame] | 1811 |  | 
|  | 1812 | // <Get Channel Cipher Suites Command> | 
| Ayushi Smriti | 5c3b72c | 2019-08-30 13:47:31 +0000 | [diff] [blame] | 1813 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, | 
|  | 1814 | ipmi::app::cmdGetChannelCipherSuites, | 
| Vernon Mauery | 79b4eea | 2019-11-07 09:51:39 -0800 | [diff] [blame] | 1815 | ipmi::Privilege::None, getChannelCipherSuites); | 
| Vernon Mauery | d2a57de | 2019-03-25 12:45:28 -0700 | [diff] [blame] | 1816 |  | 
| Xo Wang | f542e8b | 2017-08-09 15:34:16 -0700 | [diff] [blame] | 1817 | // <Get System Info Command> | 
| Jia, chunhui | 98b43ba | 2019-09-05 15:54:23 +0800 | [diff] [blame] | 1818 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, | 
|  | 1819 | ipmi::app::cmdGetSystemInfoParameters, | 
|  | 1820 | ipmi::Privilege::User, ipmiAppGetSystemInfo); | 
| Jia, chunhui | 449f216 | 2019-09-11 16:51:51 +0800 | [diff] [blame] | 1821 | // <Set System Info Command> | 
|  | 1822 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, | 
|  | 1823 | ipmi::app::cmdSetSystemInfoParameters, | 
|  | 1824 | ipmi::Privilege::Admin, ipmiAppSetSystemInfo); | 
| vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 1825 | return; | 
|  | 1826 | } |