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