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