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