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