Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2019 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 16 | #include <byteswap.h> |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 17 | |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 18 | #include <appcommands.hpp> |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 19 | #include <fstream> |
| 20 | #include <ipmid/api.hpp> |
| 21 | #include <ipmid/utils.hpp> |
| 22 | #include <nlohmann/json.hpp> |
| 23 | #include <phosphor-logging/log.hpp> |
| 24 | #include <regex> |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 25 | |
| 26 | namespace ipmi |
| 27 | { |
| 28 | |
| 29 | static void registerAPPFunctions() __attribute__((constructor)); |
| 30 | |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 31 | static constexpr const char* bmcStateIntf = "xyz.openbmc_project.State.BMC"; |
| 32 | static constexpr const char* softwareVerIntf = |
| 33 | "xyz.openbmc_project.Software.Version"; |
| 34 | static constexpr const char* softwareActivationIntf = |
| 35 | "xyz.openbmc_project.Software.Activation"; |
| 36 | static constexpr const char* associationIntf = |
| 37 | "xyz.openbmc_project.Association"; |
| 38 | static constexpr const char* softwareFunctionalPath = |
| 39 | "/xyz/openbmc_project/software/functional"; |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 40 | |
AppaRao Puli | 6c6cec4 | 2020-02-26 11:56:47 +0530 | [diff] [blame] | 41 | static constexpr const char* currentBmcStateProp = "CurrentBMCState"; |
| 42 | static constexpr const char* bmcStateReadyStr = |
| 43 | "xyz.openbmc_project.State.BMC.BMCState.Ready"; |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 44 | |
AppaRao Puli | 6c6cec4 | 2020-02-26 11:56:47 +0530 | [diff] [blame] | 45 | static std::unique_ptr<sdbusplus::bus::match::match> bmcStateChangedSignal; |
| 46 | static uint8_t bmcDeviceBusy = true; |
| 47 | |
| 48 | int initBMCDeviceState(ipmi::Context::ptr ctx) |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 49 | { |
AppaRao Puli | 6c6cec4 | 2020-02-26 11:56:47 +0530 | [diff] [blame] | 50 | DbusObjectInfo objInfo; |
| 51 | boost::system::error_code ec = |
| 52 | ipmi::getDbusObject(ctx, bmcStateIntf, "/", "bmc0", objInfo); |
| 53 | if (ec) |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 54 | { |
AppaRao Puli | 6c6cec4 | 2020-02-26 11:56:47 +0530 | [diff] [blame] | 55 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 56 | "initBMCDeviceState: Failed to perform GetSubTree action", |
| 57 | phosphor::logging::entry("ERROR=%s", ec.message().c_str()), |
| 58 | phosphor::logging::entry("INTERFACE=%s", bmcStateIntf)); |
| 59 | return -1; |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 60 | } |
AppaRao Puli | 6c6cec4 | 2020-02-26 11:56:47 +0530 | [diff] [blame] | 61 | |
| 62 | std::string bmcState; |
| 63 | ec = ipmi::getDbusProperty(ctx, objInfo.second, objInfo.first, bmcStateIntf, |
| 64 | currentBmcStateProp, bmcState); |
| 65 | if (ec) |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 66 | { |
AppaRao Puli | 6c6cec4 | 2020-02-26 11:56:47 +0530 | [diff] [blame] | 67 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 68 | "initBMCDeviceState: Failed to get CurrentBMCState property", |
| 69 | phosphor::logging::entry("ERROR=%s", ec.message().c_str())); |
| 70 | return -1; |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 71 | } |
AppaRao Puli | 6c6cec4 | 2020-02-26 11:56:47 +0530 | [diff] [blame] | 72 | |
| 73 | bmcDeviceBusy = (bmcState != bmcStateReadyStr); |
| 74 | |
| 75 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 76 | "BMC device state updated"); |
| 77 | |
| 78 | // BMC state may change runtime while doing firmware udpate. |
| 79 | // Register for property change signal to update state. |
| 80 | bmcStateChangedSignal = std::make_unique<sdbusplus::bus::match::match>( |
| 81 | *(ctx->bus), |
| 82 | sdbusplus::bus::match::rules::propertiesChanged(objInfo.first, |
| 83 | bmcStateIntf), |
| 84 | [](sdbusplus::message::message& msg) { |
| 85 | std::map<std::string, sdbusplus::message::variant<std::string>> |
| 86 | props; |
| 87 | std::vector<std::string> inVal; |
| 88 | std::string iface; |
| 89 | try |
| 90 | { |
| 91 | msg.read(iface, props, inVal); |
| 92 | } |
| 93 | catch (const std::exception& e) |
| 94 | { |
| 95 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 96 | "Exception caught in Get CurrentBMCState"); |
| 97 | return; |
| 98 | } |
| 99 | |
| 100 | auto it = props.find(currentBmcStateProp); |
| 101 | if (it != props.end()) |
| 102 | { |
| 103 | std::string* state = std::get_if<std::string>(&it->second); |
| 104 | if (state) |
| 105 | { |
| 106 | bmcDeviceBusy = (*state != bmcStateReadyStr); |
| 107 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 108 | "BMC device state updated"); |
| 109 | } |
| 110 | } |
| 111 | }); |
| 112 | |
| 113 | return 0; |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 114 | } |
Jia, chunhui | 82d178c | 2019-06-27 16:48:14 +0800 | [diff] [blame] | 115 | |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 116 | /** |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 117 | * @brief Returns the functional firmware version information. |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 118 | * |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 119 | * It reads the active firmware versions by checking functional |
| 120 | * endpoints association and matching the input version purpose string. |
| 121 | * ctx[in] - ipmi context. |
| 122 | * reqVersionPurpose[in] - Version purpose which need to be read. |
| 123 | * version[out] - Output Version string. |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 124 | * |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 125 | * @return Returns '0' on success and '-1' on failure. |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 126 | * |
| 127 | */ |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 128 | int getActiveSoftwareVersionInfo(ipmi::Context::ptr ctx, |
| 129 | const std::string& reqVersionPurpose, |
| 130 | std::string& version) |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 131 | { |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 132 | std::vector<std::string> activeEndPoints; |
| 133 | boost::system::error_code ec = ipmi::getDbusProperty( |
| 134 | ctx, ipmi::MAPPER_BUS_NAME, softwareFunctionalPath, associationIntf, |
| 135 | "endpoints", activeEndPoints); |
| 136 | if (ec) |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 137 | { |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 138 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 139 | "Failed to get Active firmware version endpoints."); |
| 140 | return -1; |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 141 | } |
| 142 | |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 143 | for (auto& activeEndPoint : activeEndPoints) |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 144 | { |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 145 | std::string serviceName; |
| 146 | ec = ipmi::getService(ctx, softwareActivationIntf, activeEndPoint, |
| 147 | serviceName); |
| 148 | if (ec) |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 149 | { |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 150 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 151 | "Failed to perform getService.", |
| 152 | phosphor::logging::entry("OBJPATH=%s", activeEndPoint.c_str())); |
| 153 | continue; |
| 154 | } |
| 155 | |
| 156 | PropertyMap propMap; |
| 157 | ec = ipmi::getAllDbusProperties(ctx, serviceName, activeEndPoint, |
| 158 | softwareVerIntf, propMap); |
| 159 | if (ec) |
| 160 | { |
| 161 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 162 | "Failed to perform GetAll on Version interface.", |
| 163 | phosphor::logging::entry("SERVICE=%s", serviceName.c_str()), |
| 164 | phosphor::logging::entry("PATH=%s", activeEndPoint.c_str())); |
| 165 | continue; |
| 166 | } |
| 167 | |
| 168 | std::string* purposeProp = |
| 169 | std::get_if<std::string>(&propMap["Purpose"]); |
| 170 | std::string* versionProp = |
| 171 | std::get_if<std::string>(&propMap["Version"]); |
| 172 | if (!purposeProp || !versionProp) |
| 173 | { |
| 174 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 175 | "Failed to get version or purpose property"); |
| 176 | continue; |
| 177 | } |
| 178 | |
| 179 | // Check for requested version information and return if found. |
| 180 | if (*purposeProp == reqVersionPurpose) |
| 181 | { |
| 182 | version = *versionProp; |
| 183 | return 0; |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 184 | } |
| 185 | } |
| 186 | |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 187 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 188 | "Failed to find version information.", |
| 189 | phosphor::logging::entry("PURPOSE=%s", reqVersionPurpose.c_str())); |
| 190 | return -1; |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 193 | // Support both 2 solutions: |
| 194 | // 1.Current solution 2.7.0-dev-533-g14dc00e79-5e7d997 |
| 195 | // openbmcTag 2.7.0-dev |
| 196 | // BuildNo 533 |
Jia, chunhui | 82d178c | 2019-06-27 16:48:14 +0800 | [diff] [blame] | 197 | // openbmcHash 14dc00e79 |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 198 | // MetaHasg 5e7d997 |
| 199 | // |
Jia, chunhui | 82d178c | 2019-06-27 16:48:14 +0800 | [diff] [blame] | 200 | // 2.New solution wht-0.2-3-gab3500-38384ac |
| 201 | // IdStr wht |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 202 | // Major 0 |
Jia, chunhui | 82d178c | 2019-06-27 16:48:14 +0800 | [diff] [blame] | 203 | // Minor 2 |
| 204 | // buildNo 3 |
| 205 | // MetaHash ab3500 |
| 206 | // openbmcHash 38384ac |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 207 | std::optional<MetaRevision> convertIntelVersion(std::string& s) |
| 208 | { |
| 209 | std::smatch results; |
| 210 | MetaRevision rev; |
Jia, chunhui | 82d178c | 2019-06-27 16:48:14 +0800 | [diff] [blame] | 211 | std::regex pattern1("(\\d+?).(\\d+?).\\d+?-\\w*?-(\\d+?)-g(\\w+?)-(\\w+?)"); |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 212 | constexpr size_t matchedPhosphor = 6; |
| 213 | if (std::regex_match(s, results, pattern1)) |
| 214 | { |
| 215 | if (results.size() == matchedPhosphor) |
| 216 | { |
| 217 | rev.platform = "whtref"; |
| 218 | rev.major = static_cast<uint8_t>(std::stoi(results[1])); |
| 219 | rev.minor = static_cast<uint8_t>(std::stoi(results[2])); |
| 220 | rev.buildNo = static_cast<uint32_t>(std::stoi(results[3])); |
| 221 | rev.openbmcHash = results[4]; |
| 222 | rev.metaHash = results[5]; |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 223 | std::string versionString = |
| 224 | rev.platform + ":" + std::to_string(rev.major) + ":" + |
| 225 | std::to_string(rev.minor) + ":" + std::to_string(rev.buildNo) + |
Jia, chunhui | 82d178c | 2019-06-27 16:48:14 +0800 | [diff] [blame] | 226 | ":" + rev.openbmcHash + ":" + rev.metaHash; |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 227 | phosphor::logging::log<phosphor::logging::level::INFO>( |
Jia, chunhui | 82d178c | 2019-06-27 16:48:14 +0800 | [diff] [blame] | 228 | "Get BMC version", |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 229 | phosphor::logging::entry("VERSION=%s", versionString.c_str())); |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 230 | return rev; |
| 231 | } |
| 232 | } |
Jia, chunhui | 82d178c | 2019-06-27 16:48:14 +0800 | [diff] [blame] | 233 | constexpr size_t matchedIntel = 7; |
| 234 | std::regex pattern2("(\\w+?)-(\\d+?).(\\d+?)-(\\d+?)-g(\\w+?)-(\\w+?)"); |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 235 | if (std::regex_match(s, results, pattern2)) |
| 236 | { |
| 237 | if (results.size() == matchedIntel) |
| 238 | { |
| 239 | rev.platform = results[1]; |
| 240 | rev.major = static_cast<uint8_t>(std::stoi(results[2])); |
| 241 | rev.minor = static_cast<uint8_t>(std::stoi(results[3])); |
| 242 | rev.buildNo = static_cast<uint32_t>(std::stoi(results[4])); |
Jia, chunhui | 82d178c | 2019-06-27 16:48:14 +0800 | [diff] [blame] | 243 | rev.openbmcHash = results[6]; |
| 244 | rev.metaHash = results[5]; |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 245 | std::string versionString = |
| 246 | rev.platform + ":" + std::to_string(rev.major) + ":" + |
| 247 | std::to_string(rev.minor) + ":" + std::to_string(rev.buildNo) + |
Jia, chunhui | 82d178c | 2019-06-27 16:48:14 +0800 | [diff] [blame] | 248 | ":" + rev.openbmcHash + ":" + rev.metaHash; |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 249 | phosphor::logging::log<phosphor::logging::level::INFO>( |
Jia, chunhui | 82d178c | 2019-06-27 16:48:14 +0800 | [diff] [blame] | 250 | "Get BMC version", |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 251 | phosphor::logging::entry("VERSION=%s", versionString.c_str())); |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 252 | return rev; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | return std::nullopt; |
| 257 | } |
Chen Yugang | 7a04f3a | 2019-10-08 11:12:35 +0800 | [diff] [blame] | 258 | |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 259 | RspType<uint8_t, // Device ID |
| 260 | uint8_t, // Device Revision |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 261 | uint7_t, // Firmware Revision Major |
| 262 | bool, // Device available(0=NormalMode,1=DeviceFirmware) |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 263 | uint8_t, // Firmware Revision minor |
| 264 | uint8_t, // IPMI version |
| 265 | uint8_t, // Additional device support |
| 266 | uint24_t, // MFG ID |
| 267 | uint16_t, // Product ID |
| 268 | uint32_t // AUX info |
| 269 | > |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 270 | ipmiAppGetDeviceId(ipmi::Context::ptr ctx) |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 271 | { |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 272 | static struct |
| 273 | { |
| 274 | uint8_t id; |
| 275 | uint8_t revision; |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 276 | uint7_t fwMajor; |
| 277 | bool devBusy; |
| 278 | uint8_t fwMinor; |
Johnathan Mantey | 3c8af65 | 2019-12-19 11:29:15 -0800 | [diff] [blame] | 279 | uint8_t ipmiVer = 2; |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 280 | uint8_t addnDevSupport; |
| 281 | uint24_t manufId; |
| 282 | uint16_t prodId; |
| 283 | uint32_t aux; |
| 284 | } devId; |
AppaRao Puli | cb6386b | 2020-01-16 14:53:30 +0530 | [diff] [blame] | 285 | static bool fwVerInitialized = false; |
| 286 | static bool devIdInitialized = false; |
AppaRao Puli | 6c6cec4 | 2020-02-26 11:56:47 +0530 | [diff] [blame] | 287 | static bool bmcStateInitialized = false; |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 288 | const char* filename = "/usr/share/ipmi-providers/dev_id.json"; |
Johnathan Mantey | 3c8af65 | 2019-12-19 11:29:15 -0800 | [diff] [blame] | 289 | const char* prodIdFilename = "/var/cache/private/prodID"; |
AppaRao Puli | cb6386b | 2020-01-16 14:53:30 +0530 | [diff] [blame] | 290 | if (!fwVerInitialized) |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 291 | { |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 292 | std::string versionString; |
| 293 | if (!getActiveSoftwareVersionInfo(ctx, versionPurposeBMC, |
| 294 | versionString)) |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 295 | { |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 296 | std::optional<MetaRevision> rev = |
| 297 | convertIntelVersion(versionString); |
| 298 | if (rev.has_value()) |
Jia, chunhui | 82d178c | 2019-06-27 16:48:14 +0800 | [diff] [blame] | 299 | { |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 300 | MetaRevision revision = rev.value(); |
| 301 | devId.fwMajor = static_cast<uint7_t>(revision.major); |
| 302 | |
| 303 | revision.minor = (revision.minor > 99 ? 99 : revision.minor); |
| 304 | devId.fwMinor = |
| 305 | revision.minor % 10 + (revision.minor / 10) * 16; |
| 306 | try |
| 307 | { |
| 308 | uint32_t hash = std::stoul(revision.metaHash, 0, 16); |
| 309 | hash = bswap_32(hash); |
| 310 | devId.aux = (revision.buildNo & 0xFF) + (hash & 0xFFFFFF00); |
| 311 | fwVerInitialized = true; |
| 312 | } |
| 313 | catch (const std::exception& e) |
| 314 | { |
| 315 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 316 | "Failed to convert git hash", |
| 317 | phosphor::logging::entry("ERROR=%s", e.what())); |
| 318 | } |
Jia, chunhui | 82d178c | 2019-06-27 16:48:14 +0800 | [diff] [blame] | 319 | } |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 320 | } |
AppaRao Puli | cb6386b | 2020-01-16 14:53:30 +0530 | [diff] [blame] | 321 | } |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 322 | |
AppaRao Puli | cb6386b | 2020-01-16 14:53:30 +0530 | [diff] [blame] | 323 | if (!devIdInitialized) |
| 324 | { |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 325 | std::ifstream devIdFile(filename); |
| 326 | if (devIdFile.is_open()) |
| 327 | { |
| 328 | auto data = nlohmann::json::parse(devIdFile, nullptr, false); |
| 329 | if (!data.is_discarded()) |
| 330 | { |
| 331 | devId.id = data.value("id", 0); |
| 332 | devId.revision = data.value("revision", 0); |
| 333 | devId.addnDevSupport = data.value("addn_dev_support", 0); |
| 334 | devId.manufId = data.value("manuf_id", 0); |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 335 | } |
| 336 | else |
| 337 | { |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 338 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 339 | "Device ID JSON parser failure"); |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 340 | return ipmi::responseUnspecifiedError(); |
| 341 | } |
| 342 | } |
| 343 | else |
| 344 | { |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 345 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 346 | "Device ID file not found"); |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 347 | return ipmi::responseUnspecifiedError(); |
| 348 | } |
Johnathan Mantey | 3c8af65 | 2019-12-19 11:29:15 -0800 | [diff] [blame] | 349 | |
| 350 | // Determine the Product ID. Using the DBus system is painfully slow at |
| 351 | // boot time. Avoid using DBus to get the Product ID. The Product ID is |
| 352 | // stored in a non-volatile file now. The /usr/bin/checkFru.sh script, |
| 353 | // run during bootup, will populate the productIdFile. |
| 354 | std::fstream prodIdFile(prodIdFilename); |
| 355 | if (prodIdFile.is_open()) |
| 356 | { |
| 357 | std::string id = "0x00"; |
| 358 | char* end; |
| 359 | prodIdFile.getline(&id[0], id.size() + 1); |
| 360 | devId.prodId = std::strtol(&id[0], &end, 0); |
AppaRao Puli | cb6386b | 2020-01-16 14:53:30 +0530 | [diff] [blame] | 361 | devIdInitialized = true; |
Johnathan Mantey | 3c8af65 | 2019-12-19 11:29:15 -0800 | [diff] [blame] | 362 | } |
| 363 | else |
| 364 | { |
| 365 | // For any exception send out platform id as 0, |
| 366 | // and make sure to re-query the device id. |
AppaRao Puli | cb6386b | 2020-01-16 14:53:30 +0530 | [diff] [blame] | 367 | devIdInitialized = false; |
Johnathan Mantey | 3c8af65 | 2019-12-19 11:29:15 -0800 | [diff] [blame] | 368 | devId.prodId = 0; |
| 369 | } |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 370 | } |
| 371 | |
AppaRao Puli | 6c6cec4 | 2020-02-26 11:56:47 +0530 | [diff] [blame] | 372 | if (!bmcStateInitialized) |
| 373 | { |
| 374 | if (!initBMCDeviceState(ctx)) |
| 375 | { |
| 376 | bmcStateInitialized = true; |
| 377 | } |
| 378 | } |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 379 | |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 380 | return ipmi::responseSuccess(devId.id, devId.revision, devId.fwMajor, |
AppaRao Puli | 6c6cec4 | 2020-02-26 11:56:47 +0530 | [diff] [blame] | 381 | bmcDeviceBusy, devId.fwMinor, devId.ipmiVer, |
AppaRao Puli | e99e7ed | 2020-01-17 12:27:10 +0530 | [diff] [blame] | 382 | devId.addnDevSupport, devId.manufId, |
| 383 | devId.prodId, devId.aux); |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | static void registerAPPFunctions(void) |
| 387 | { |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 388 | // <Get Device ID> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 389 | registerHandler(prioOemBase, netFnApp, app::cmdGetDeviceId, Privilege::User, |
| 390 | ipmiAppGetDeviceId); |
Vernon Mauery | ce14e4d | 2019-06-25 11:38:20 -0700 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | } // namespace ipmi |