Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1 | #include <arpa/inet.h> |
William A. Kennington III | 194375f | 2018-12-14 02:14:33 -0800 | [diff] [blame] | 2 | #include <ipmid/api.h> |
Xo Wang | 8765133 | 2017-08-11 10:17:59 -0700 | [diff] [blame] | 3 | #include <limits.h> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 4 | #include <mapper.h> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 5 | #include <systemd/sd-bus.h> |
Xo Wang | 8765133 | 2017-08-11 10:17:59 -0700 | [diff] [blame] | 6 | #include <unistd.h> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 7 | |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 8 | #include <algorithm> |
Vernon Mauery | 0120b68 | 2019-03-25 13:08:54 -0700 | [diff] [blame] | 9 | #include <app/channel.hpp> |
| 10 | #include <app/watchdog.hpp> |
| 11 | #include <apphandler.hpp> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 12 | #include <array> |
| 13 | #include <cstddef> |
Vernon Mauery | 0120b68 | 2019-03-25 13:08:54 -0700 | [diff] [blame] | 14 | #include <cstdint> |
Vernon Mauery | bdda800 | 2019-02-26 10:18:51 -0800 | [diff] [blame] | 15 | #include <filesystem> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 16 | #include <fstream> |
Vernon Mauery | 0120b68 | 2019-03-25 13:08:54 -0700 | [diff] [blame] | 17 | #include <ipmid/api.hpp> |
| 18 | #include <ipmid/registration.hpp> |
Vernon Mauery | 3325024 | 2019-03-12 16:49:26 -0700 | [diff] [blame] | 19 | #include <ipmid/types.hpp> |
Vernon Mauery | 6a98fe7 | 2019-03-11 15:57:48 -0700 | [diff] [blame] | 20 | #include <ipmid/utils.hpp> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 21 | #include <memory> |
Patrick Venture | 46470a3 | 2018-09-07 19:26:25 -0700 | [diff] [blame] | 22 | #include <nlohmann/json.hpp> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 23 | #include <phosphor-logging/elog-errors.hpp> |
| 24 | #include <phosphor-logging/log.hpp> |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 25 | #include <sdbusplus/message/types.hpp> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 26 | #include <string> |
Vernon Mauery | 0120b68 | 2019-03-25 13:08:54 -0700 | [diff] [blame] | 27 | #include <sys_info_param.hpp> |
| 28 | #include <transporthandler.hpp> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 29 | #include <tuple> |
| 30 | #include <vector> |
| 31 | #include <xyz/openbmc_project/Common/error.hpp> |
Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 32 | #include <xyz/openbmc_project/Control/Power/ACPIPowerState/server.hpp> |
Patrick Venture | 3a5071a | 2018-09-12 13:27:42 -0700 | [diff] [blame] | 33 | #include <xyz/openbmc_project/Software/Activation/server.hpp> |
| 34 | #include <xyz/openbmc_project/Software/Version/server.hpp> |
| 35 | #include <xyz/openbmc_project/State/BMC/server.hpp> |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 36 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 37 | extern sd_bus* bus; |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 38 | |
Alexander Amelkin | ba19c18 | 2018-09-04 15:49:36 +0300 | [diff] [blame] | 39 | constexpr auto bmc_state_interface = "xyz.openbmc_project.State.BMC"; |
| 40 | constexpr auto bmc_state_property = "CurrentBMCState"; |
Marri Devender Rao | 5e007a5 | 2018-01-08 06:18:36 -0600 | [diff] [blame] | 41 | constexpr auto bmc_interface = "xyz.openbmc_project.Inventory.Item.Bmc"; |
| 42 | constexpr auto bmc_guid_interface = "xyz.openbmc_project.Common.UUID"; |
| 43 | constexpr auto bmc_guid_property = "UUID"; |
| 44 | constexpr auto bmc_guid_len = 16; |
| 45 | |
Nagaraju Goruganti | 744398d | 2018-02-20 09:52:00 -0600 | [diff] [blame] | 46 | static constexpr auto redundancyIntf = |
| 47 | "xyz.openbmc_project.Software.RedundancyPriority"; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 48 | static constexpr auto versionIntf = "xyz.openbmc_project.Software.Version"; |
Nagaraju Goruganti | 744398d | 2018-02-20 09:52:00 -0600 | [diff] [blame] | 49 | static constexpr auto activationIntf = |
| 50 | "xyz.openbmc_project.Software.Activation"; |
| 51 | static constexpr auto softwareRoot = "/xyz/openbmc_project/software"; |
| 52 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 53 | void register_netfn_app_functions() __attribute__((constructor)); |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 54 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 55 | using namespace phosphor::logging; |
| 56 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
Nagaraju Goruganti | 744398d | 2018-02-20 09:52:00 -0600 | [diff] [blame] | 57 | using Version = sdbusplus::xyz::openbmc_project::Software::server::Version; |
| 58 | using Activation = |
| 59 | sdbusplus::xyz::openbmc_project::Software::server::Activation; |
Alexander Amelkin | ba19c18 | 2018-09-04 15:49:36 +0300 | [diff] [blame] | 60 | using BMC = sdbusplus::xyz::openbmc_project::State::server::BMC; |
Vernon Mauery | 185b9f8 | 2018-07-20 10:52:36 -0700 | [diff] [blame] | 61 | namespace fs = std::filesystem; |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 62 | namespace variant_ns = sdbusplus::message::variant_ns; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 63 | |
Nagaraju Goruganti | 744398d | 2018-02-20 09:52:00 -0600 | [diff] [blame] | 64 | /** |
| 65 | * @brief Returns the Version info from primary s/w object |
| 66 | * |
| 67 | * Get the Version info from the active s/w object which is having high |
| 68 | * "Priority" value(a smaller number is a higher priority) and "Purpose" |
| 69 | * is "BMC" from the list of all s/w objects those are implementing |
| 70 | * RedundancyPriority interface from the given softwareRoot path. |
| 71 | * |
| 72 | * @return On success returns the Version info from primary s/w object. |
| 73 | * |
| 74 | */ |
| 75 | std::string getActiveSoftwareVersionInfo() |
| 76 | { |
Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 77 | auto busp = getSdBus(); |
Nagaraju Goruganti | 744398d | 2018-02-20 09:52:00 -0600 | [diff] [blame] | 78 | |
| 79 | std::string revision{}; |
Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 80 | ipmi::ObjectTree objectTree; |
| 81 | try |
Nagaraju Goruganti | 744398d | 2018-02-20 09:52:00 -0600 | [diff] [blame] | 82 | { |
Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 83 | objectTree = |
| 84 | ipmi::getAllDbusObjects(*busp, softwareRoot, redundancyIntf); |
| 85 | } |
| 86 | catch (sdbusplus::exception::SdBusError& e) |
| 87 | { |
| 88 | log<level::ERR>("Failed to fetch redundancy object from dbus", |
| 89 | entry("INTERFACE=%s", redundancyIntf), |
| 90 | entry("ERRMSG=%s", e.what())); |
Nagaraju Goruganti | 744398d | 2018-02-20 09:52:00 -0600 | [diff] [blame] | 91 | elog<InternalFailure>(); |
| 92 | } |
| 93 | |
| 94 | auto objectFound = false; |
| 95 | for (auto& softObject : objectTree) |
| 96 | { |
Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 97 | auto service = |
| 98 | ipmi::getService(*busp, redundancyIntf, softObject.first); |
| 99 | auto objValueTree = |
| 100 | ipmi::getManagedObjects(*busp, service, softwareRoot); |
Nagaraju Goruganti | 744398d | 2018-02-20 09:52:00 -0600 | [diff] [blame] | 101 | |
| 102 | auto minPriority = 0xFF; |
| 103 | for (const auto& objIter : objValueTree) |
| 104 | { |
| 105 | try |
| 106 | { |
| 107 | auto& intfMap = objIter.second; |
| 108 | auto& redundancyPriorityProps = intfMap.at(redundancyIntf); |
| 109 | auto& versionProps = intfMap.at(versionIntf); |
| 110 | auto& activationProps = intfMap.at(activationIntf); |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 111 | auto priority = variant_ns::get<uint8_t>( |
| 112 | redundancyPriorityProps.at("Priority")); |
| 113 | auto purpose = |
| 114 | variant_ns::get<std::string>(versionProps.at("Purpose")); |
| 115 | auto activation = variant_ns::get<std::string>( |
| 116 | activationProps.at("Activation")); |
| 117 | auto version = |
| 118 | variant_ns::get<std::string>(versionProps.at("Version")); |
Nagaraju Goruganti | 744398d | 2018-02-20 09:52:00 -0600 | [diff] [blame] | 119 | if ((Version::convertVersionPurposeFromString(purpose) == |
| 120 | Version::VersionPurpose::BMC) && |
| 121 | (Activation::convertActivationsFromString(activation) == |
| 122 | Activation::Activations::Active)) |
| 123 | { |
| 124 | if (priority < minPriority) |
| 125 | { |
| 126 | minPriority = priority; |
| 127 | objectFound = true; |
| 128 | revision = std::move(version); |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | catch (const std::exception& e) |
| 133 | { |
| 134 | log<level::ERR>(e.what()); |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | if (!objectFound) |
| 140 | { |
| 141 | log<level::ERR>("Could not found an BMC software Object"); |
| 142 | elog<InternalFailure>(); |
| 143 | } |
| 144 | |
| 145 | return revision; |
| 146 | } |
| 147 | |
Alexander Amelkin | ba19c18 | 2018-09-04 15:49:36 +0300 | [diff] [blame] | 148 | bool getCurrentBmcState() |
| 149 | { |
| 150 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 151 | |
| 152 | // Get the Inventory object implementing the BMC interface |
| 153 | ipmi::DbusObjectInfo bmcObject = |
| 154 | ipmi::getDbusObject(bus, bmc_state_interface); |
| 155 | auto variant = |
| 156 | ipmi::getDbusProperty(bus, bmcObject.second, bmcObject.first, |
| 157 | bmc_state_interface, bmc_state_property); |
| 158 | |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 159 | return variant_ns::holds_alternative<std::string>(variant) && |
| 160 | BMC::convertBMCStateFromString( |
| 161 | variant_ns::get<std::string>(variant)) == BMC::BMCState::Ready; |
Alexander Amelkin | ba19c18 | 2018-09-04 15:49:36 +0300 | [diff] [blame] | 162 | } |
| 163 | |
Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 164 | namespace acpi_state |
| 165 | { |
| 166 | using namespace sdbusplus::xyz::openbmc_project::Control::Power::server; |
| 167 | |
| 168 | const static constexpr char* acpiObjPath = |
| 169 | "/xyz/openbmc_project/control/host0/acpi_power_state"; |
| 170 | const static constexpr char* acpiInterface = |
| 171 | "xyz.openbmc_project.Control.Power.ACPIPowerState"; |
| 172 | const static constexpr char* sysACPIProp = "SysACPIStatus"; |
| 173 | const static constexpr char* devACPIProp = "DevACPIStatus"; |
| 174 | |
| 175 | enum class PowerStateType : uint8_t |
| 176 | { |
| 177 | sysPowerState = 0x00, |
| 178 | devPowerState = 0x01, |
| 179 | }; |
| 180 | |
| 181 | // Defined in 20.6 of ipmi doc |
| 182 | enum class PowerState : uint8_t |
| 183 | { |
| 184 | s0G0D0 = 0x00, |
| 185 | s1D1 = 0x01, |
| 186 | s2D2 = 0x02, |
| 187 | s3D3 = 0x03, |
| 188 | s4 = 0x04, |
| 189 | s5G2 = 0x05, |
| 190 | s4S5 = 0x06, |
| 191 | g3 = 0x07, |
| 192 | sleep = 0x08, |
| 193 | g1Sleep = 0x09, |
| 194 | override = 0x0a, |
| 195 | legacyOn = 0x20, |
| 196 | legacyOff = 0x21, |
| 197 | unknown = 0x2a, |
| 198 | noChange = 0x7f, |
| 199 | }; |
| 200 | |
| 201 | static constexpr uint8_t stateChanged = 0x80; |
| 202 | |
| 203 | struct ACPIState |
| 204 | { |
| 205 | uint8_t sysACPIState; |
| 206 | uint8_t devACPIState; |
| 207 | } __attribute__((packed)); |
| 208 | |
| 209 | std::map<ACPIPowerState::ACPI, PowerState> dbusToIPMI = { |
| 210 | {ACPIPowerState::ACPI::S0_G0_D0, PowerState::s0G0D0}, |
| 211 | {ACPIPowerState::ACPI::S1_D1, PowerState::s1D1}, |
| 212 | {ACPIPowerState::ACPI::S2_D2, PowerState::s2D2}, |
| 213 | {ACPIPowerState::ACPI::S3_D3, PowerState::s3D3}, |
| 214 | {ACPIPowerState::ACPI::S4, PowerState::s4}, |
| 215 | {ACPIPowerState::ACPI::S5_G2, PowerState::s5G2}, |
| 216 | {ACPIPowerState::ACPI::S4_S5, PowerState::s4S5}, |
| 217 | {ACPIPowerState::ACPI::G3, PowerState::g3}, |
| 218 | {ACPIPowerState::ACPI::SLEEP, PowerState::sleep}, |
| 219 | {ACPIPowerState::ACPI::G1_SLEEP, PowerState::g1Sleep}, |
| 220 | {ACPIPowerState::ACPI::OVERRIDE, PowerState::override}, |
| 221 | {ACPIPowerState::ACPI::LEGACY_ON, PowerState::legacyOn}, |
| 222 | {ACPIPowerState::ACPI::LEGACY_OFF, PowerState::legacyOff}, |
| 223 | {ACPIPowerState::ACPI::Unknown, PowerState::unknown}}; |
| 224 | |
| 225 | bool isValidACPIState(acpi_state::PowerStateType type, uint8_t state) |
| 226 | { |
| 227 | if (type == acpi_state::PowerStateType::sysPowerState) |
| 228 | { |
| 229 | if ((state <= static_cast<uint8_t>(acpi_state::PowerState::override)) || |
| 230 | (state == static_cast<uint8_t>(acpi_state::PowerState::legacyOn)) || |
| 231 | (state == |
| 232 | static_cast<uint8_t>(acpi_state::PowerState::legacyOff)) || |
| 233 | (state == static_cast<uint8_t>(acpi_state::PowerState::unknown)) || |
| 234 | (state == static_cast<uint8_t>(acpi_state::PowerState::noChange))) |
| 235 | { |
| 236 | return true; |
| 237 | } |
| 238 | else |
| 239 | { |
| 240 | return false; |
| 241 | } |
| 242 | } |
| 243 | else if (type == acpi_state::PowerStateType::devPowerState) |
| 244 | { |
| 245 | if ((state <= static_cast<uint8_t>(acpi_state::PowerState::s3D3)) || |
| 246 | (state == static_cast<uint8_t>(acpi_state::PowerState::unknown)) || |
| 247 | (state == static_cast<uint8_t>(acpi_state::PowerState::noChange))) |
| 248 | { |
| 249 | return true; |
| 250 | } |
| 251 | else |
| 252 | { |
| 253 | return false; |
| 254 | } |
| 255 | } |
| 256 | else |
| 257 | { |
| 258 | return false; |
| 259 | } |
| 260 | return false; |
| 261 | } |
| 262 | } // namespace acpi_state |
| 263 | |
Adriana Kobylak | 3a552e1 | 2015-10-19 16:11:00 -0500 | [diff] [blame] | 264 | 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] | 265 | ipmi_request_t request, |
| 266 | ipmi_response_t response, |
| 267 | ipmi_data_len_t data_len, |
| 268 | ipmi_context_t context) |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 269 | { |
Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 270 | auto s = static_cast<uint8_t>(acpi_state::PowerState::unknown); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 271 | ipmi_ret_t rc = IPMI_CC_OK; |
Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 272 | |
| 273 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 274 | |
| 275 | auto value = acpi_state::ACPIPowerState::ACPI::Unknown; |
| 276 | |
| 277 | auto* req = reinterpret_cast<acpi_state::ACPIState*>(request); |
| 278 | |
| 279 | if (*data_len != sizeof(acpi_state::ACPIState)) |
| 280 | { |
| 281 | log<level::ERR>("set_acpi invalid len"); |
| 282 | *data_len = 0; |
| 283 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 284 | } |
| 285 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 286 | *data_len = 0; |
| 287 | |
Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 288 | if (req->sysACPIState & acpi_state::stateChanged) |
| 289 | { |
| 290 | // set system power state |
| 291 | s = req->sysACPIState & ~acpi_state::stateChanged; |
| 292 | |
| 293 | if (!acpi_state::isValidACPIState( |
| 294 | acpi_state::PowerStateType::sysPowerState, s)) |
| 295 | { |
| 296 | log<level::ERR>("set_acpi_power sys invalid input", |
| 297 | entry("S=%x", s)); |
| 298 | return IPMI_CC_PARM_OUT_OF_RANGE; |
| 299 | } |
| 300 | |
| 301 | // valid input |
| 302 | if (s == static_cast<uint8_t>(acpi_state::PowerState::noChange)) |
| 303 | { |
| 304 | log<level::DEBUG>("No change for system power state"); |
| 305 | } |
| 306 | else |
| 307 | { |
| 308 | auto found = std::find_if( |
| 309 | acpi_state::dbusToIPMI.begin(), acpi_state::dbusToIPMI.end(), |
| 310 | [&s](const auto& iter) { |
| 311 | return (static_cast<uint8_t>(iter.second) == s); |
| 312 | }); |
| 313 | |
| 314 | value = found->first; |
| 315 | |
| 316 | try |
| 317 | { |
| 318 | auto acpiObject = |
| 319 | ipmi::getDbusObject(bus, acpi_state::acpiInterface); |
| 320 | ipmi::setDbusProperty(bus, acpiObject.second, acpiObject.first, |
| 321 | acpi_state::acpiInterface, |
| 322 | acpi_state::sysACPIProp, |
| 323 | convertForMessage(value)); |
| 324 | } |
| 325 | catch (const InternalFailure& e) |
| 326 | { |
| 327 | log<level::ERR>("Failed in set ACPI system property", |
| 328 | entry("EXCEPTION=%s", e.what())); |
| 329 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | else |
| 334 | { |
| 335 | log<level::DEBUG>("Do not change system power state"); |
| 336 | } |
| 337 | |
| 338 | if (req->devACPIState & acpi_state::stateChanged) |
| 339 | { |
| 340 | // set device power state |
| 341 | s = req->devACPIState & ~acpi_state::stateChanged; |
| 342 | if (!acpi_state::isValidACPIState( |
| 343 | acpi_state::PowerStateType::devPowerState, s)) |
| 344 | { |
| 345 | log<level::ERR>("set_acpi_power dev invalid input", |
| 346 | entry("S=%x", s)); |
| 347 | return IPMI_CC_PARM_OUT_OF_RANGE; |
| 348 | } |
| 349 | |
| 350 | // valid input |
| 351 | if (s == static_cast<uint8_t>(acpi_state::PowerState::noChange)) |
| 352 | { |
| 353 | log<level::DEBUG>("No change for device power state"); |
| 354 | } |
| 355 | else |
| 356 | { |
| 357 | auto found = std::find_if( |
| 358 | acpi_state::dbusToIPMI.begin(), acpi_state::dbusToIPMI.end(), |
| 359 | [&s](const auto& iter) { |
| 360 | return (static_cast<uint8_t>(iter.second) == s); |
| 361 | }); |
| 362 | |
| 363 | value = found->first; |
| 364 | |
| 365 | try |
| 366 | { |
| 367 | auto acpiObject = |
| 368 | ipmi::getDbusObject(bus, acpi_state::acpiInterface); |
| 369 | ipmi::setDbusProperty(bus, acpiObject.second, acpiObject.first, |
| 370 | acpi_state::acpiInterface, |
| 371 | acpi_state::devACPIProp, |
| 372 | convertForMessage(value)); |
| 373 | } |
| 374 | catch (const InternalFailure& e) |
| 375 | { |
| 376 | log<level::ERR>("Failed in set ACPI device property", |
| 377 | entry("EXCEPTION=%s", e.what())); |
| 378 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | else |
| 383 | { |
| 384 | log<level::DEBUG>("Do not change device power state"); |
| 385 | } |
| 386 | |
| 387 | return rc; |
| 388 | } |
| 389 | |
| 390 | ipmi_ret_t ipmi_app_get_acpi_power_state(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 391 | ipmi_request_t request, |
| 392 | ipmi_response_t response, |
| 393 | ipmi_data_len_t data_len, |
| 394 | ipmi_context_t context) |
| 395 | { |
| 396 | ipmi_ret_t rc = IPMI_CC_OK; |
| 397 | |
| 398 | auto* res = reinterpret_cast<acpi_state::ACPIState*>(response); |
| 399 | |
| 400 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 401 | |
| 402 | *data_len = 0; |
| 403 | |
| 404 | try |
| 405 | { |
| 406 | auto acpiObject = ipmi::getDbusObject(bus, acpi_state::acpiInterface); |
| 407 | |
| 408 | auto sysACPIVal = ipmi::getDbusProperty( |
| 409 | bus, acpiObject.second, acpiObject.first, acpi_state::acpiInterface, |
| 410 | acpi_state::sysACPIProp); |
| 411 | auto sysACPI = acpi_state::ACPIPowerState::convertACPIFromString( |
William A. Kennington III | dfad486 | 2018-11-19 17:45:35 -0800 | [diff] [blame] | 412 | variant_ns::get<std::string>(sysACPIVal)); |
Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 413 | res->sysACPIState = |
| 414 | static_cast<uint8_t>(acpi_state::dbusToIPMI.at(sysACPI)); |
| 415 | |
| 416 | auto devACPIVal = ipmi::getDbusProperty( |
| 417 | bus, acpiObject.second, acpiObject.first, acpi_state::acpiInterface, |
| 418 | acpi_state::devACPIProp); |
| 419 | auto devACPI = acpi_state::ACPIPowerState::convertACPIFromString( |
William A. Kennington III | dfad486 | 2018-11-19 17:45:35 -0800 | [diff] [blame] | 420 | variant_ns::get<std::string>(devACPIVal)); |
Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 421 | res->devACPIState = |
| 422 | static_cast<uint8_t>(acpi_state::dbusToIPMI.at(devACPI)); |
| 423 | |
| 424 | *data_len = sizeof(acpi_state::ACPIState); |
| 425 | } |
| 426 | catch (const InternalFailure& e) |
| 427 | { |
| 428 | log<level::ERR>("Failed in get ACPI property"); |
| 429 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 430 | } |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 431 | return rc; |
| 432 | } |
| 433 | |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 434 | typedef struct |
| 435 | { |
| 436 | char major; |
| 437 | char minor; |
Chris Austen | 176c965 | 2016-04-30 16:32:17 -0500 | [diff] [blame] | 438 | uint16_t d[2]; |
Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 439 | } Revision; |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 440 | |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 441 | /* Currently supports the vx.x-x-[-x] and v1.x.x-x-[-x] format. It will */ |
| 442 | /* 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] | 443 | /* version = v0.6-19-gf363f61-dirty */ |
| 444 | /* ^ ^ ^^ ^ */ |
| 445 | /* | | |----------|-- additional details */ |
| 446 | /* | |---------------- Minor */ |
| 447 | /* |------------------ Major */ |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 448 | /* and version = v1.99.10-113-g65edf7d-r3-0-g9e4f715 */ |
| 449 | /* ^ ^ ^^ ^ */ |
| 450 | /* | | |--|---------- additional details */ |
| 451 | /* | |---------------- Minor */ |
| 452 | /* |------------------ Major */ |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 453 | /* Additional details : If the option group exists it will force Auxiliary */ |
| 454 | /* Firmware Revision Information 4th byte to 1 indicating the build was */ |
| 455 | /* derived with additional edits */ |
Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 456 | int convertVersion(std::string s, Revision& rev) |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 457 | { |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 458 | std::string token; |
Chris Austen | 176c965 | 2016-04-30 16:32:17 -0500 | [diff] [blame] | 459 | uint16_t commits; |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 460 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 461 | auto location = s.find_first_of('v'); |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 462 | if (location != std::string::npos) |
| 463 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 464 | s = s.substr(location + 1); |
Chris Austen | 176c965 | 2016-04-30 16:32:17 -0500 | [diff] [blame] | 465 | } |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 466 | |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 467 | if (!s.empty()) |
| 468 | { |
| 469 | location = s.find_first_of("."); |
| 470 | if (location != std::string::npos) |
| 471 | { |
Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 472 | rev.major = |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 473 | static_cast<char>(std::stoi(s.substr(0, location), 0, 16)); |
| 474 | token = s.substr(location + 1); |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 475 | } |
Chris Austen | 176c965 | 2016-04-30 16:32:17 -0500 | [diff] [blame] | 476 | |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 477 | if (!token.empty()) |
| 478 | { |
| 479 | location = token.find_first_of(".-"); |
| 480 | if (location != std::string::npos) |
| 481 | { |
Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 482 | rev.minor = static_cast<char>( |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 483 | std::stoi(token.substr(0, location), 0, 16)); |
| 484 | token = token.substr(location + 1); |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 485 | } |
| 486 | } |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 487 | |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 488 | // Capture the number of commits on top of the minor tag. |
| 489 | // I'm using BE format like the ipmi spec asked for |
| 490 | location = token.find_first_of(".-"); |
| 491 | if (!token.empty()) |
| 492 | { |
| 493 | commits = std::stoi(token.substr(0, location), 0, 16); |
Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 494 | rev.d[0] = (commits >> 8) | (commits << 8); |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 495 | |
| 496 | // commit number we skip |
| 497 | location = token.find_first_of(".-"); |
| 498 | if (location != std::string::npos) |
| 499 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 500 | token = token.substr(location + 1); |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 501 | } |
| 502 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 503 | else |
| 504 | { |
Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 505 | rev.d[0] = 0; |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | if (location != std::string::npos) |
| 509 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 510 | token = token.substr(location + 1); |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | // Any value of the optional parameter forces it to 1 |
| 514 | location = token.find_first_of(".-"); |
| 515 | if (location != std::string::npos) |
| 516 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 517 | token = token.substr(location + 1); |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 518 | } |
| 519 | commits = (!token.empty()) ? 1 : 0; |
| 520 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 521 | // We do this operation to get this displayed in least significant bytes |
| 522 | // of ipmitool device id command. |
Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 523 | rev.d[1] = (commits >> 8) | (commits << 8); |
Dinesh Chinari | 2b7e07d | 2017-11-08 15:38:50 -0600 | [diff] [blame] | 524 | } |
| 525 | |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 526 | return 0; |
| 527 | } |
| 528 | |
Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 529 | auto ipmiAppGetDeviceId() -> ipmi::RspType<uint8_t, // Device ID |
| 530 | uint8_t, // Device Revision |
| 531 | uint8_t, // Firmware Revision Major |
| 532 | uint8_t, // Firmware Revision minor |
| 533 | uint8_t, // IPMI version |
| 534 | uint8_t, // Additional device support |
| 535 | uint24_t, // MFG ID |
| 536 | uint16_t, // Product ID |
| 537 | uint32_t // AUX info |
| 538 | > |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 539 | { |
Nagaraju Goruganti | 744398d | 2018-02-20 09:52:00 -0600 | [diff] [blame] | 540 | int r = -1; |
Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 541 | Revision rev = {0}; |
| 542 | static struct |
| 543 | { |
| 544 | uint8_t id; |
| 545 | uint8_t revision; |
| 546 | uint8_t fw[2]; |
| 547 | uint8_t ipmiVer; |
| 548 | uint8_t addnDevSupport; |
| 549 | uint24_t manufId; |
| 550 | uint16_t prodId; |
| 551 | uint32_t aux; |
| 552 | } devId; |
David Cobbley | a1adb07 | 2017-11-21 15:58:13 -0800 | [diff] [blame] | 553 | static bool dev_id_initialized = false; |
| 554 | const char* filename = "/usr/share/ipmi-providers/dev_id.json"; |
Alexander Amelkin | ba19c18 | 2018-09-04 15:49:36 +0300 | [diff] [blame] | 555 | constexpr auto ipmiDevIdStateShift = 7; |
| 556 | constexpr auto ipmiDevIdFw1Mask = ~(1 << ipmiDevIdStateShift); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 557 | |
David Cobbley | a1adb07 | 2017-11-21 15:58:13 -0800 | [diff] [blame] | 558 | if (!dev_id_initialized) |
| 559 | { |
Nagaraju Goruganti | 744398d | 2018-02-20 09:52:00 -0600 | [diff] [blame] | 560 | try |
| 561 | { |
| 562 | auto version = getActiveSoftwareVersionInfo(); |
Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 563 | r = convertVersion(version, rev); |
David Cobbley | a1adb07 | 2017-11-21 15:58:13 -0800 | [diff] [blame] | 564 | } |
Nagaraju Goruganti | 744398d | 2018-02-20 09:52:00 -0600 | [diff] [blame] | 565 | catch (const std::exception& e) |
| 566 | { |
| 567 | log<level::ERR>(e.what()); |
| 568 | } |
Nan Li | ee0cb90 | 2016-07-11 15:38:03 +0800 | [diff] [blame] | 569 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 570 | if (r >= 0) |
| 571 | { |
Nagaraju Goruganti | 744398d | 2018-02-20 09:52:00 -0600 | [diff] [blame] | 572 | // bit7 identifies if the device is available |
| 573 | // 0=normal operation |
| 574 | // 1=device firmware, SDR update, |
| 575 | // or self-initialization in progress. |
Alexander Amelkin | ba19c18 | 2018-09-04 15:49:36 +0300 | [diff] [blame] | 576 | // The availability may change in run time, so mask here |
| 577 | // and initialize later. |
Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 578 | devId.fw[0] = rev.major & ipmiDevIdFw1Mask; |
Nagaraju Goruganti | 744398d | 2018-02-20 09:52:00 -0600 | [diff] [blame] | 579 | |
| 580 | rev.minor = (rev.minor > 99 ? 99 : rev.minor); |
Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 581 | devId.fw[1] = rev.minor % 10 + (rev.minor / 10) * 16; |
| 582 | std::memcpy(&devId.aux, rev.d, 4); |
David Cobbley | a1adb07 | 2017-11-21 15:58:13 -0800 | [diff] [blame] | 583 | } |
Nan Li | ee0cb90 | 2016-07-11 15:38:03 +0800 | [diff] [blame] | 584 | |
David Cobbley | a1adb07 | 2017-11-21 15:58:13 -0800 | [diff] [blame] | 585 | // IPMI Spec version 2.0 |
Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 586 | devId.ipmiVer = 2; |
Adriana Kobylak | 0e91264 | 2016-06-22 16:54:39 -0500 | [diff] [blame] | 587 | |
Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 588 | std::ifstream devIdFile(filename); |
| 589 | if (devIdFile.is_open()) |
David Cobbley | a1adb07 | 2017-11-21 15:58:13 -0800 | [diff] [blame] | 590 | { |
Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 591 | auto data = nlohmann::json::parse(devIdFile, nullptr, false); |
David Cobbley | a1adb07 | 2017-11-21 15:58:13 -0800 | [diff] [blame] | 592 | if (!data.is_discarded()) |
| 593 | { |
Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 594 | devId.id = data.value("id", 0); |
| 595 | devId.revision = data.value("revision", 0); |
| 596 | devId.addnDevSupport = data.value("addn_dev_support", 0); |
| 597 | devId.manufId = data.value("manuf_id", 0); |
| 598 | devId.prodId = data.value("prod_id", 0); |
| 599 | devId.aux = data.value("aux", 0); |
David Cobbley | a1adb07 | 2017-11-21 15:58:13 -0800 | [diff] [blame] | 600 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 601 | // Don't read the file every time if successful |
David Cobbley | a1adb07 | 2017-11-21 15:58:13 -0800 | [diff] [blame] | 602 | dev_id_initialized = true; |
| 603 | } |
| 604 | else |
| 605 | { |
| 606 | log<level::ERR>("Device ID JSON parser failure"); |
Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 607 | return ipmi::response(ipmi::ccUnspecifiedError); |
David Cobbley | a1adb07 | 2017-11-21 15:58:13 -0800 | [diff] [blame] | 608 | } |
| 609 | } |
| 610 | else |
| 611 | { |
| 612 | log<level::ERR>("Device ID file not found"); |
Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 613 | return ipmi::response(ipmi::ccUnspecifiedError); |
Chris Austen | 7303bdc | 2016-04-17 11:50:54 -0500 | [diff] [blame] | 614 | } |
| 615 | } |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 616 | |
Alexander Amelkin | ba19c18 | 2018-09-04 15:49:36 +0300 | [diff] [blame] | 617 | // Set availability to the actual current BMC state |
Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 618 | devId.fw[0] &= ipmiDevIdFw1Mask; |
Alexander Amelkin | ba19c18 | 2018-09-04 15:49:36 +0300 | [diff] [blame] | 619 | if (!getCurrentBmcState()) |
| 620 | { |
Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 621 | devId.fw[0] |= (1 << ipmiDevIdStateShift); |
Alexander Amelkin | ba19c18 | 2018-09-04 15:49:36 +0300 | [diff] [blame] | 622 | } |
| 623 | |
Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 624 | return ipmi::responseSuccess( |
| 625 | devId.id, devId.revision, devId.fw[0], devId.fw[1], devId.ipmiVer, |
| 626 | devId.addnDevSupport, devId.manufId, devId.prodId, devId.aux); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 627 | } |
| 628 | |
Vernon Mauery | b84a528 | 2019-03-25 13:39:03 -0700 | [diff] [blame] | 629 | auto ipmiAppGetSelfTestResults() -> ipmi::RspType<uint8_t, uint8_t> |
Nan Li | 41fa24a | 2016-11-10 20:12:37 +0800 | [diff] [blame] | 630 | { |
Nan Li | 41fa24a | 2016-11-10 20:12:37 +0800 | [diff] [blame] | 631 | // Byte 2: |
| 632 | // 55h - No error. |
Gunnar Mills | 8991dd6 | 2017-10-25 17:11:29 -0500 | [diff] [blame] | 633 | // 56h - Self Test function not implemented in this controller. |
Nan Li | 41fa24a | 2016-11-10 20:12:37 +0800 | [diff] [blame] | 634 | // 57h - Corrupted or inaccesssible data or devices. |
| 635 | // 58h - Fatal hardware error. |
| 636 | // FFh - reserved. |
| 637 | // all other: Device-specific 'internal failure'. |
| 638 | // Byte 3: |
| 639 | // For byte 2 = 55h, 56h, FFh: 00h |
| 640 | // For byte 2 = 58h, all other: Device-specific |
| 641 | // For byte 2 = 57h: self-test error bitfield. |
| 642 | // Note: returning 57h does not imply that all test were run. |
| 643 | // [7] 1b = Cannot access SEL device. |
| 644 | // [6] 1b = Cannot access SDR Repository. |
| 645 | // [5] 1b = Cannot access BMC FRU device. |
| 646 | // [4] 1b = IPMB signal lines do not respond. |
| 647 | // [3] 1b = SDR Repository empty. |
| 648 | // [2] 1b = Internal Use Area of BMC FRU corrupted. |
| 649 | // [1] 1b = controller update 'boot block' firmware corrupted. |
| 650 | // [0] 1b = controller operational firmware corrupted. |
Vernon Mauery | b84a528 | 2019-03-25 13:39:03 -0700 | [diff] [blame] | 651 | constexpr uint8_t notImplemented = 0x56; |
| 652 | constexpr uint8_t zero = 0; |
| 653 | return ipmi::responseSuccess(notImplemented, zero); |
Nan Li | 41fa24a | 2016-11-10 20:12:37 +0800 | [diff] [blame] | 654 | } |
| 655 | |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 656 | ipmi_ret_t ipmi_app_get_device_guid(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 657 | ipmi_request_t request, |
| 658 | ipmi_response_t response, |
| 659 | ipmi_data_len_t data_len, |
| 660 | ipmi_context_t context) |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 661 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 662 | const char* objname = "/org/openbmc/control/chassis0"; |
| 663 | const char* iface = "org.freedesktop.DBus.Properties"; |
| 664 | const char* chassis_iface = "org.openbmc.control.Chassis"; |
| 665 | sd_bus_message* reply = NULL; |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 666 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 667 | int r = 0; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 668 | char* uuid = NULL; |
| 669 | char* busname = NULL; |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 670 | |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 671 | // UUID is in RFC4122 format. Ex: 61a39523-78f2-11e5-9862-e6402cfc3223 |
Patrick Venture | d211702 | 2018-02-06 08:54:37 -0800 | [diff] [blame] | 672 | // Per IPMI Spec 2.0 need to convert to 16 hex bytes and reverse the byte |
| 673 | // order |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 674 | // Ex: 0x2332fc2c40e66298e511f2782395a361 |
| 675 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 676 | const int resp_size = 16; // Response is 16 hex bytes per IPMI Spec |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 677 | uint8_t resp_uuid[resp_size]; // Array to hold the formatted response |
Patrick Venture | d211702 | 2018-02-06 08:54:37 -0800 | [diff] [blame] | 678 | // Point resp end of array to save in reverse order |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 679 | int resp_loc = resp_size - 1; |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 680 | int i = 0; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 681 | char* tokptr = NULL; |
| 682 | char* id_octet = NULL; |
Emily Shaffer | edb8bb0 | 2018-09-27 14:50:15 -0700 | [diff] [blame] | 683 | size_t total_uuid_size = 0; |
| 684 | // 1 byte of resp is built from 2 chars of uuid. |
| 685 | constexpr size_t max_uuid_size = 2 * resp_size; |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 686 | |
| 687 | // Status code. |
| 688 | ipmi_ret_t rc = IPMI_CC_OK; |
| 689 | *data_len = 0; |
| 690 | |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 691 | // Call Get properties method with the interface and property name |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 692 | r = mapper_get_service(bus, objname, &busname); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 693 | if (r < 0) |
| 694 | { |
| 695 | log<level::ERR>("Failed to get bus name", entry("BUS=%s", objname), |
Aditya Saripalli | 5fb1460 | 2017-11-09 14:46:27 +0530 | [diff] [blame] | 696 | entry("ERRNO=0x%X", -r)); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 697 | goto finish; |
| 698 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 699 | r = sd_bus_call_method(bus, busname, objname, iface, "Get", &error, &reply, |
| 700 | "ss", chassis_iface, "uuid"); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 701 | if (r < 0) |
| 702 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 703 | log<level::ERR>("Failed to call Get Method", entry("ERRNO=0x%X", -r)); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 704 | rc = IPMI_CC_UNSPECIFIED_ERROR; |
| 705 | goto finish; |
| 706 | } |
| 707 | |
| 708 | r = sd_bus_message_read(reply, "v", "s", &uuid); |
| 709 | if (r < 0 || uuid == NULL) |
| 710 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 711 | log<level::ERR>("Failed to get a response", entry("ERRNO=0x%X", -r)); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 712 | rc = IPMI_CC_RESPONSE_ERROR; |
| 713 | goto finish; |
| 714 | } |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 715 | |
| 716 | // Traverse the UUID |
Patrick Venture | d211702 | 2018-02-06 08:54:37 -0800 | [diff] [blame] | 717 | // Get the UUID octects separated by dash |
| 718 | id_octet = strtok_r(uuid, "-", &tokptr); |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 719 | |
| 720 | if (id_octet == NULL) |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 721 | { |
| 722 | // Error |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 723 | log<level::ERR>("Unexpected UUID format", entry("UUID=%s", uuid)); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 724 | rc = IPMI_CC_RESPONSE_ERROR; |
| 725 | goto finish; |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | while (id_octet != NULL) |
| 729 | { |
| 730 | // Calculate the octet string size since it varies |
| 731 | // Divide it by 2 for the array size since 1 byte is built from 2 chars |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 732 | int tmp_size = strlen(id_octet) / 2; |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 733 | |
Emily Shaffer | edb8bb0 | 2018-09-27 14:50:15 -0700 | [diff] [blame] | 734 | // Check if total UUID size has been exceeded |
| 735 | if ((total_uuid_size += strlen(id_octet)) > max_uuid_size) |
| 736 | { |
| 737 | // Error - UUID too long to store |
| 738 | log<level::ERR>("UUID too long", entry("UUID=%s", uuid)); |
| 739 | rc = IPMI_CC_RESPONSE_ERROR; |
| 740 | goto finish; |
| 741 | } |
| 742 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 743 | for (i = 0; i < tmp_size; i++) |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 744 | { |
Patrick Venture | d211702 | 2018-02-06 08:54:37 -0800 | [diff] [blame] | 745 | // Holder of the 2 chars that will become a byte |
| 746 | char tmp_array[3] = {0}; |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 747 | strncpy(tmp_array, id_octet, 2); // 2 chars at a time |
| 748 | |
| 749 | int resp_byte = strtoul(tmp_array, NULL, 16); // Convert to hex byte |
Patrick Venture | d211702 | 2018-02-06 08:54:37 -0800 | [diff] [blame] | 750 | // Copy end to first |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 751 | std::memcpy((void*)&resp_uuid[resp_loc], &resp_byte, 1); |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 752 | resp_loc--; |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 753 | id_octet += 2; // Finished with the 2 chars, advance |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 754 | } |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 755 | id_octet = strtok_r(NULL, "-", &tokptr); // Get next octet |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | // Data length |
| 759 | *data_len = resp_size; |
| 760 | |
| 761 | // Pack the actual response |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 762 | std::memcpy(response, &resp_uuid, *data_len); |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 763 | |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 764 | finish: |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 765 | sd_bus_error_free(&error); |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 766 | reply = sd_bus_message_unref(reply); |
Sergey Solomin | eb9b814 | 2016-08-23 09:07:28 -0500 | [diff] [blame] | 767 | free(busname); |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 768 | |
| 769 | return rc; |
| 770 | } |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 771 | |
Vernon Mauery | cc99ba4 | 2019-03-25 13:40:11 -0700 | [diff] [blame] | 772 | auto ipmiAppGetBtCapabilities() |
| 773 | -> ipmi::RspType<uint8_t, uint8_t, uint8_t, uint8_t, uint8_t> |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 774 | { |
Adriana Kobylak | 88ad815 | 2016-12-13 10:09:08 -0600 | [diff] [blame] | 775 | // Per IPMI 2.0 spec, the input and output buffer size must be the max |
| 776 | // buffer size minus one byte to allocate space for the length byte. |
Vernon Mauery | cc99ba4 | 2019-03-25 13:40:11 -0700 | [diff] [blame] | 777 | constexpr uint8_t nrOutstanding = 0x01; |
| 778 | constexpr uint8_t inputBufferSize = MAX_IPMI_BUFFER - 1; |
| 779 | constexpr uint8_t outputBufferSize = MAX_IPMI_BUFFER - 1; |
| 780 | constexpr uint8_t transactionTime = 0x0A; |
| 781 | constexpr uint8_t nrRetries = 0x01; |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 782 | |
Vernon Mauery | cc99ba4 | 2019-03-25 13:40:11 -0700 | [diff] [blame] | 783 | return ipmi::responseSuccess(nrOutstanding, inputBufferSize, |
| 784 | outputBufferSize, transactionTime, nrRetries); |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 785 | } |
| 786 | |
Marri Devender Rao | 5e007a5 | 2018-01-08 06:18:36 -0600 | [diff] [blame] | 787 | ipmi_ret_t ipmi_app_get_sys_guid(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 788 | ipmi_request_t request, |
| 789 | ipmi_response_t response, |
| 790 | ipmi_data_len_t data_len, |
| 791 | ipmi_context_t context) |
Marri Devender Rao | 5e007a5 | 2018-01-08 06:18:36 -0600 | [diff] [blame] | 792 | |
| 793 | { |
| 794 | ipmi_ret_t rc = IPMI_CC_OK; |
| 795 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 796 | |
| 797 | try |
| 798 | { |
| 799 | // Get the Inventory object implementing BMC interface |
| 800 | ipmi::DbusObjectInfo bmcObject = |
| 801 | ipmi::getDbusObject(bus, bmc_interface); |
| 802 | |
| 803 | // Read UUID property value from bmcObject |
| 804 | // UUID is in RFC4122 format Ex: 61a39523-78f2-11e5-9862-e6402cfc3223 |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 805 | auto variant = |
| 806 | ipmi::getDbusProperty(bus, bmcObject.second, bmcObject.first, |
| 807 | bmc_guid_interface, bmc_guid_property); |
William A. Kennington III | 4c00802 | 2018-10-12 17:18:14 -0700 | [diff] [blame] | 808 | std::string guidProp = variant_ns::get<std::string>(variant); |
Marri Devender Rao | 5e007a5 | 2018-01-08 06:18:36 -0600 | [diff] [blame] | 809 | |
| 810 | // Erase "-" characters from the property value |
| 811 | guidProp.erase(std::remove(guidProp.begin(), guidProp.end(), '-'), |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 812 | guidProp.end()); |
Marri Devender Rao | 5e007a5 | 2018-01-08 06:18:36 -0600 | [diff] [blame] | 813 | |
| 814 | auto guidPropLen = guidProp.length(); |
| 815 | // Validate UUID data |
| 816 | // Divide by 2 as 1 byte is built from 2 chars |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 817 | if ((guidPropLen <= 0) || ((guidPropLen / 2) != bmc_guid_len)) |
Marri Devender Rao | 5e007a5 | 2018-01-08 06:18:36 -0600 | [diff] [blame] | 818 | |
| 819 | { |
| 820 | log<level::ERR>("Invalid UUID property value", |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 821 | entry("UUID_LENGTH=%d", guidPropLen)); |
Marri Devender Rao | 5e007a5 | 2018-01-08 06:18:36 -0600 | [diff] [blame] | 822 | return IPMI_CC_RESPONSE_ERROR; |
| 823 | } |
| 824 | |
| 825 | // Convert data in RFC4122(MSB) format to LSB format |
| 826 | // Get 2 characters at a time as 1 byte is built from 2 chars and |
| 827 | // convert to hex byte |
| 828 | // TODO: Data printed for GUID command is not as per the |
| 829 | // GUID format defined in IPMI specification 2.0 section 20.8 |
| 830 | // Ticket raised: https://sourceforge.net/p/ipmitool/bugs/501/ |
| 831 | uint8_t respGuid[bmc_guid_len]; |
| 832 | for (size_t i = 0, respLoc = (bmc_guid_len - 1); |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 833 | i < guidPropLen && respLoc >= 0; i += 2, respLoc--) |
Marri Devender Rao | 5e007a5 | 2018-01-08 06:18:36 -0600 | [diff] [blame] | 834 | { |
| 835 | auto value = static_cast<uint8_t>( |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 836 | std::stoi(guidProp.substr(i, 2).c_str(), NULL, 16)); |
Marri Devender Rao | 5e007a5 | 2018-01-08 06:18:36 -0600 | [diff] [blame] | 837 | respGuid[respLoc] = value; |
| 838 | } |
| 839 | |
| 840 | *data_len = bmc_guid_len; |
Patrick Venture | b51bf9c | 2018-09-10 15:53:14 -0700 | [diff] [blame] | 841 | std::memcpy(response, &respGuid, bmc_guid_len); |
Marri Devender Rao | 5e007a5 | 2018-01-08 06:18:36 -0600 | [diff] [blame] | 842 | } |
| 843 | catch (const InternalFailure& e) |
| 844 | { |
| 845 | log<level::ERR>("Failed in reading BMC UUID property", |
| 846 | entry("INTERFACE=%s", bmc_interface), |
| 847 | entry("PROPERTY_INTERFACE=%s", bmc_guid_interface), |
| 848 | entry("PROPERTY=%s", bmc_guid_property)); |
| 849 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 850 | } |
| 851 | return rc; |
| 852 | } |
| 853 | |
Xo Wang | f542e8b | 2017-08-09 15:34:16 -0700 | [diff] [blame] | 854 | static std::unique_ptr<SysInfoParamStore> sysInfoParamStore; |
| 855 | |
Xo Wang | 8765133 | 2017-08-11 10:17:59 -0700 | [diff] [blame] | 856 | static std::string sysInfoReadSystemName() |
| 857 | { |
| 858 | // Use the BMC hostname as the "System Name." |
| 859 | char hostname[HOST_NAME_MAX + 1] = {}; |
| 860 | if (gethostname(hostname, HOST_NAME_MAX) != 0) |
| 861 | { |
| 862 | perror("System info parameter: system name"); |
| 863 | } |
| 864 | return hostname; |
| 865 | } |
| 866 | |
Xo Wang | f542e8b | 2017-08-09 15:34:16 -0700 | [diff] [blame] | 867 | struct IpmiSysInfoResp |
| 868 | { |
| 869 | uint8_t paramRevision; |
| 870 | uint8_t setSelector; |
| 871 | union |
| 872 | { |
| 873 | struct |
| 874 | { |
| 875 | uint8_t encoding; |
| 876 | uint8_t stringLen; |
| 877 | uint8_t stringData0[14]; |
| 878 | } __attribute__((packed)); |
| 879 | uint8_t stringDataN[16]; |
| 880 | uint8_t byteData; |
| 881 | }; |
| 882 | } __attribute__((packed)); |
| 883 | |
| 884 | /** |
| 885 | * Split a string into (up to) 16-byte chunks as expected in response for get |
| 886 | * system info parameter. |
| 887 | * |
| 888 | * @param[in] fullString: Input string to be split |
| 889 | * @param[in] chunkIndex: Index of the chunk to be written out |
| 890 | * @param[in,out] chunk: Output data buffer; must have 14 byte capacity if |
| 891 | * chunk_index = 0 and 16-byte capacity otherwise |
| 892 | * @return the number of bytes written into the output buffer, or -EINVAL for |
| 893 | * invalid arguments. |
| 894 | */ |
| 895 | static int splitStringParam(const std::string& fullString, int chunkIndex, |
| 896 | uint8_t* chunk) |
| 897 | { |
| 898 | constexpr int maxChunk = 255; |
| 899 | constexpr int smallChunk = 14; |
| 900 | constexpr int chunkSize = 16; |
| 901 | if (chunkIndex > maxChunk || chunk == nullptr) |
| 902 | { |
| 903 | return -EINVAL; |
| 904 | } |
| 905 | try |
| 906 | { |
| 907 | std::string output; |
| 908 | if (chunkIndex == 0) |
| 909 | { |
| 910 | // Output must have 14 byte capacity. |
| 911 | output = fullString.substr(0, smallChunk); |
| 912 | } |
| 913 | else |
| 914 | { |
| 915 | // Output must have 16 byte capacity. |
| 916 | output = fullString.substr((chunkIndex * chunkSize) - 2, chunkSize); |
| 917 | } |
| 918 | |
| 919 | std::memcpy(chunk, output.c_str(), output.length()); |
| 920 | return output.length(); |
| 921 | } |
| 922 | catch (const std::out_of_range& e) |
| 923 | { |
| 924 | // The position was beyond the end. |
| 925 | return -EINVAL; |
| 926 | } |
| 927 | } |
| 928 | |
| 929 | /** |
| 930 | * Packs the Get Sys Info Request Item into the response. |
| 931 | * |
| 932 | * @param[in] paramString - the parameter. |
| 933 | * @param[in] setSelector - the selector |
| 934 | * @param[in,out] resp - the System info response. |
| 935 | * @return The number of bytes packed or failure from splitStringParam(). |
| 936 | */ |
| 937 | static int packGetSysInfoResp(const std::string& paramString, |
| 938 | uint8_t setSelector, IpmiSysInfoResp* resp) |
| 939 | { |
| 940 | uint8_t* dataBuffer = resp->stringDataN; |
| 941 | resp->setSelector = setSelector; |
| 942 | if (resp->setSelector == 0) // First chunk has only 14 bytes. |
| 943 | { |
| 944 | resp->encoding = 0; |
| 945 | resp->stringLen = paramString.length(); |
| 946 | dataBuffer = resp->stringData0; |
| 947 | } |
| 948 | return splitStringParam(paramString, resp->setSelector, dataBuffer); |
| 949 | } |
| 950 | |
| 951 | ipmi_ret_t ipmi_app_get_system_info(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 952 | ipmi_request_t request, |
| 953 | ipmi_response_t response, |
| 954 | ipmi_data_len_t dataLen, |
| 955 | ipmi_context_t context) |
| 956 | { |
| 957 | IpmiSysInfoResp resp = {}; |
| 958 | size_t respLen = 0; |
| 959 | uint8_t* const reqData = static_cast<uint8_t*>(request); |
| 960 | std::string paramString; |
| 961 | bool found; |
| 962 | std::tuple<bool, std::string> ret; |
| 963 | constexpr int minRequestSize = 4; |
| 964 | constexpr int paramSelector = 1; |
| 965 | constexpr uint8_t revisionOnly = 0x80; |
| 966 | const uint8_t paramRequested = reqData[paramSelector]; |
| 967 | int rc; |
| 968 | |
| 969 | if (*dataLen < minRequestSize) |
| 970 | { |
| 971 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 972 | } |
| 973 | |
| 974 | *dataLen = 0; // default to 0. |
| 975 | |
| 976 | // Parameters revision as of IPMI spec v2.0 rev. 1.1 (Feb 11, 2014 E6) |
| 977 | resp.paramRevision = 0x11; |
| 978 | if (reqData[0] & revisionOnly) // Get parameter revision only |
| 979 | { |
| 980 | respLen = 1; |
| 981 | goto writeResponse; |
| 982 | } |
| 983 | |
| 984 | // The "Set In Progress" parameter can be used for rollback of parameter |
| 985 | // data and is not implemented. |
| 986 | if (paramRequested == 0) |
| 987 | { |
| 988 | resp.byteData = 0; |
| 989 | respLen = 2; |
| 990 | goto writeResponse; |
| 991 | } |
| 992 | |
| 993 | if (sysInfoParamStore == nullptr) |
| 994 | { |
| 995 | sysInfoParamStore = std::make_unique<SysInfoParamStore>(); |
Xo Wang | 8765133 | 2017-08-11 10:17:59 -0700 | [diff] [blame] | 996 | sysInfoParamStore->update(IPMI_SYSINFO_SYSTEM_NAME, |
| 997 | sysInfoReadSystemName); |
Xo Wang | f542e8b | 2017-08-09 15:34:16 -0700 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | // Parameters other than Set In Progress are assumed to be strings. |
| 1001 | ret = sysInfoParamStore->lookup(paramRequested); |
| 1002 | found = std::get<0>(ret); |
| 1003 | paramString = std::get<1>(ret); |
| 1004 | if (!found) |
| 1005 | { |
| 1006 | return IPMI_CC_SYSTEM_INFO_PARAMETER_NOT_SUPPORTED; |
| 1007 | } |
| 1008 | // TODO: Cache each parameter across multiple calls, until the whole string |
| 1009 | // has been read out. Otherwise, it's possible for a parameter to change |
| 1010 | // between requests for its chunks, returning chunks incoherent with each |
| 1011 | // other. For now, the parameter store is simply required to have only |
| 1012 | // idempotent callbacks. |
| 1013 | rc = packGetSysInfoResp(paramString, reqData[2], &resp); |
| 1014 | if (rc == -EINVAL) |
| 1015 | { |
| 1016 | return IPMI_CC_RESPONSE_ERROR; |
| 1017 | } |
| 1018 | |
| 1019 | respLen = sizeof(resp); // Write entire string data chunk in response. |
| 1020 | |
| 1021 | writeResponse: |
| 1022 | std::memcpy(response, &resp, sizeof(resp)); |
| 1023 | *dataLen = respLen; |
| 1024 | return IPMI_CC_OK; |
| 1025 | } |
| 1026 | |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 1027 | void register_netfn_app_functions() |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 1028 | { |
Vernon Mauery | 86a5082 | 2019-03-25 13:11:36 -0700 | [diff] [blame] | 1029 | // <Get Device ID> |
| 1030 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, |
| 1031 | ipmi::app::cmdGetDeviceId, ipmi::Privilege::User, |
| 1032 | ipmiAppGetDeviceId); |
| 1033 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1034 | // <Get BT Interface Capabilities> |
Vernon Mauery | cc99ba4 | 2019-03-25 13:40:11 -0700 | [diff] [blame] | 1035 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, |
| 1036 | ipmi::app::cmdGetBtIfaceCapabilities, |
| 1037 | ipmi::Privilege::User, ipmiAppGetBtCapabilities); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 1038 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1039 | // <Reset Watchdog Timer> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1040 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_RESET_WD, NULL, |
| 1041 | ipmi_app_watchdog_reset, PRIVILEGE_OPERATOR); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 1042 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1043 | // <Set Watchdog Timer> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1044 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_WD, NULL, |
| 1045 | ipmi_app_watchdog_set, PRIVILEGE_OPERATOR); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 1046 | |
William A. Kennington III | 73f4451 | 2018-02-09 15:28:46 -0800 | [diff] [blame] | 1047 | // <Get Watchdog Timer> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1048 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_WD, NULL, |
| 1049 | ipmi_app_watchdog_get, PRIVILEGE_OPERATOR); |
William A. Kennington III | 73f4451 | 2018-02-09 15:28:46 -0800 | [diff] [blame] | 1050 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1051 | // <Get Self Test Results> |
Vernon Mauery | b84a528 | 2019-03-25 13:39:03 -0700 | [diff] [blame] | 1052 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, |
| 1053 | ipmi::app::cmdGetSelfTestResults, |
| 1054 | ipmi::Privilege::User, ipmiAppGetSelfTestResults); |
Nan Li | 41fa24a | 2016-11-10 20:12:37 +0800 | [diff] [blame] | 1055 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1056 | // <Get Device GUID> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1057 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_DEVICE_GUID, NULL, |
| 1058 | ipmi_app_get_device_guid, PRIVILEGE_USER); |
Adriana Kobylak | d100ee5 | 2015-10-20 17:02:37 -0500 | [diff] [blame] | 1059 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1060 | // <Set ACPI Power State> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1061 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_ACPI, NULL, |
| 1062 | ipmi_app_set_acpi_power_state, PRIVILEGE_ADMIN); |
Chris Austen | 6caf28b | 2015-10-13 12:40:40 -0500 | [diff] [blame] | 1063 | |
Yong Li | 18d7726 | 2018-10-09 01:59:45 +0800 | [diff] [blame] | 1064 | // <Get ACPI Power State> |
| 1065 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_ACPI, NULL, |
| 1066 | ipmi_app_get_acpi_power_state, PRIVILEGE_ADMIN); |
| 1067 | |
Marri Devender Rao | 5e007a5 | 2018-01-08 06:18:36 -0600 | [diff] [blame] | 1068 | // <Get System GUID Command> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1069 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_SYS_GUID, NULL, |
| 1070 | ipmi_app_get_sys_guid, PRIVILEGE_USER); |
Tom Joseph | 7cbe228 | 2018-03-21 21:17:33 +0530 | [diff] [blame] | 1071 | |
| 1072 | // <Get Channel Cipher Suites Command> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 1073 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CHAN_CIPHER_SUITES, NULL, |
| 1074 | getChannelCipherSuites, PRIVILEGE_CALLBACK); |
Vernon Mauery | d2a57de | 2019-03-25 12:45:28 -0700 | [diff] [blame] | 1075 | |
Xo Wang | f542e8b | 2017-08-09 15:34:16 -0700 | [diff] [blame] | 1076 | // <Get System Info Command> |
| 1077 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_SYSTEM_INFO, NULL, |
| 1078 | ipmi_app_get_system_info, PRIVILEGE_USER); |
vishwabmc | ba0bd5f | 2015-09-30 16:50:23 +0530 | [diff] [blame] | 1079 | return; |
| 1080 | } |