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