Matt Spinler | 711d51d | 2019-11-06 09:36:51 -0600 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2019 IBM 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 | */ |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 16 | #include "src.hpp" |
| 17 | |
Matt Spinler | 717de42 | 2020-06-04 13:10:14 -0500 | [diff] [blame] | 18 | #include "device_callouts.hpp" |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 19 | #include "json_utils.hpp" |
| 20 | #include "paths.hpp" |
| 21 | #include "pel_values.hpp" |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 22 | #ifdef PELTOOL |
| 23 | #include <Python.h> |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 24 | |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 25 | #include <nlohmann/json.hpp> |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 26 | |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 27 | #include <sstream> |
| 28 | #endif |
Matt Spinler | 0bacc8e | 2023-07-07 16:25:39 -0500 | [diff] [blame] | 29 | #include <phosphor-logging/lg2.hpp> |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 30 | |
Jayanth Othayoth | 1aa90d4 | 2023-09-13 04:25:45 -0500 | [diff] [blame] | 31 | #include <format> |
| 32 | |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 33 | namespace openpower |
| 34 | { |
| 35 | namespace pels |
| 36 | { |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 37 | namespace pv = openpower::pels::pel_values; |
| 38 | namespace rg = openpower::pels::message; |
Matt Spinler | 85f61a6 | 2020-06-03 16:28:55 -0500 | [diff] [blame] | 39 | using namespace std::string_literals; |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 40 | |
Matt Spinler | 075e5ba | 2020-02-21 15:46:00 -0600 | [diff] [blame] | 41 | constexpr size_t ccinSize = 4; |
| 42 | |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 43 | #ifdef PELTOOL |
Sumit Kumar | 516935a | 2021-04-14 13:00:54 -0500 | [diff] [blame] | 44 | using orderedJSON = nlohmann::ordered_json; |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 45 | |
| 46 | void pyDecRef(PyObject* pyObj) |
| 47 | { |
| 48 | Py_XDECREF(pyObj); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @brief Returns a JSON string to append to SRC section. |
| 53 | * |
| 54 | * The returning string will contain a JSON object, but without |
| 55 | * the outer {}. If the input JSON isn't a JSON object (dict), then |
| 56 | * one will be created with the input added to a 'SRC Details' key. |
| 57 | * |
| 58 | * @param[in] json - The JSON to convert to a string |
| 59 | * |
| 60 | * @return std::string - The JSON string |
| 61 | */ |
Sumit Kumar | 516935a | 2021-04-14 13:00:54 -0500 | [diff] [blame] | 62 | std::string prettyJSON(const orderedJSON& json) |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 63 | { |
Sumit Kumar | 516935a | 2021-04-14 13:00:54 -0500 | [diff] [blame] | 64 | orderedJSON output; |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 65 | if (!json.is_object()) |
| 66 | { |
| 67 | output["SRC Details"] = json; |
| 68 | } |
| 69 | else |
| 70 | { |
| 71 | for (const auto& [key, value] : json.items()) |
| 72 | { |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 73 | output["SRC Details"][key] = value; |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 74 | } |
| 75 | } |
| 76 | |
| 77 | // Let nlohmann do the pretty printing. |
| 78 | std::stringstream stream; |
| 79 | stream << std::setw(4) << output; |
| 80 | |
| 81 | auto jsonString = stream.str(); |
| 82 | |
| 83 | // Now it looks like: |
| 84 | // { |
| 85 | // "Key": "Value", |
| 86 | // ... |
| 87 | // } |
| 88 | |
| 89 | // Replace the { and the following newline, and the } and its |
| 90 | // preceeding newline. |
| 91 | jsonString.erase(0, 2); |
| 92 | |
| 93 | auto pos = jsonString.find_last_of('}'); |
| 94 | jsonString.erase(pos - 1); |
| 95 | |
| 96 | return jsonString; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * @brief Call Python modules to parse the data into a JSON string |
| 101 | * |
| 102 | * The module to call is based on the Creator Subsystem ID under the namespace |
| 103 | * "srcparsers". For example: "srcparsers.xsrc.xsrc" where "x" is the Creator |
| 104 | * Subsystem ID in ASCII lowercase. |
| 105 | * |
| 106 | * All modules must provide the following: |
| 107 | * Function: parseSRCToJson |
| 108 | * Argument list: |
| 109 | * 1. (str) ASCII string (Hex Word 1) |
| 110 | * 2. (str) Hex Word 2 |
| 111 | * 3. (str) Hex Word 3 |
| 112 | * 4. (str) Hex Word 4 |
| 113 | * 5. (str) Hex Word 5 |
| 114 | * 6. (str) Hex Word 6 |
| 115 | * 7. (str) Hex Word 7 |
| 116 | * 8. (str) Hex Word 8 |
| 117 | * 9. (str) Hex Word 9 |
| 118 | *-Return data: |
| 119 | * 1. (str) JSON string |
| 120 | * |
| 121 | * @param[in] hexwords - Vector of strings of Hexwords 1-9 |
| 122 | * @param[in] creatorID - The creatorID from the Private Header section |
| 123 | * @return std::optional<std::string> - The JSON string if it could be created, |
| 124 | * else std::nullopt |
| 125 | */ |
| 126 | std::optional<std::string> getPythonJSON(std::vector<std::string>& hexwords, |
| 127 | uint8_t creatorID) |
| 128 | { |
Matt Spinler | be952d2 | 2022-07-01 11:30:11 -0500 | [diff] [blame] | 129 | PyObject *pName, *pModule, *eType, *eValue, *eTraceback; |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 130 | std::string pErrStr; |
| 131 | std::string module = getNumberString("%c", tolower(creatorID)) + "src"; |
| 132 | pName = PyUnicode_FromString( |
| 133 | std::string("srcparsers." + module + "." + module).c_str()); |
| 134 | std::unique_ptr<PyObject, decltype(&pyDecRef)> modNamePtr(pName, &pyDecRef); |
| 135 | pModule = PyImport_Import(pName); |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 136 | if (pModule == NULL) |
| 137 | { |
| 138 | pErrStr = "No error string found"; |
| 139 | PyErr_Fetch(&eType, &eValue, &eTraceback); |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 140 | if (eType) |
| 141 | { |
| 142 | Py_XDECREF(eType); |
| 143 | } |
| 144 | if (eTraceback) |
| 145 | { |
| 146 | Py_XDECREF(eTraceback); |
| 147 | } |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 148 | if (eValue) |
| 149 | { |
| 150 | PyObject* pStr = PyObject_Str(eValue); |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 151 | Py_XDECREF(eValue); |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 152 | if (pStr) |
| 153 | { |
| 154 | pErrStr = PyUnicode_AsUTF8(pStr); |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 155 | Py_XDECREF(pStr); |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 156 | } |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 157 | } |
| 158 | } |
| 159 | else |
| 160 | { |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 161 | std::unique_ptr<PyObject, decltype(&pyDecRef)> modPtr( |
| 162 | pModule, &pyDecRef); |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 163 | std::string funcToCall = "parseSRCToJson"; |
Matt Spinler | be952d2 | 2022-07-01 11:30:11 -0500 | [diff] [blame] | 164 | PyObject* pKey = PyUnicode_FromString(funcToCall.c_str()); |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 165 | std::unique_ptr<PyObject, decltype(&pyDecRef)> keyPtr(pKey, &pyDecRef); |
Matt Spinler | be952d2 | 2022-07-01 11:30:11 -0500 | [diff] [blame] | 166 | PyObject* pDict = PyModule_GetDict(pModule); |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 167 | Py_INCREF(pDict); |
| 168 | if (!PyDict_Contains(pDict, pKey)) |
| 169 | { |
| 170 | Py_DECREF(pDict); |
Matt Spinler | 0bacc8e | 2023-07-07 16:25:39 -0500 | [diff] [blame] | 171 | lg2::error( |
| 172 | "Python module error. Function missing: {FUNC}, SRC = {SRC}, module = {MODULE}", |
| 173 | "FUNC", funcToCall, "SRC", hexwords.front(), "MODULE", module); |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 174 | return std::nullopt; |
| 175 | } |
Matt Spinler | be952d2 | 2022-07-01 11:30:11 -0500 | [diff] [blame] | 176 | PyObject* pFunc = PyDict_GetItemString(pDict, funcToCall.c_str()); |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 177 | Py_DECREF(pDict); |
| 178 | Py_INCREF(pFunc); |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 179 | if (PyCallable_Check(pFunc)) |
| 180 | { |
Matt Spinler | be952d2 | 2022-07-01 11:30:11 -0500 | [diff] [blame] | 181 | PyObject* pArgs = PyTuple_New(9); |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 182 | std::unique_ptr<PyObject, decltype(&pyDecRef)> argPtr( |
| 183 | pArgs, &pyDecRef); |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 184 | for (size_t i = 0; i < 9; i++) |
| 185 | { |
Matt Spinler | c198403 | 2023-01-05 10:09:59 -0600 | [diff] [blame] | 186 | std::string arg{"00000000"}; |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 187 | if (i < hexwords.size()) |
| 188 | { |
Matt Spinler | c198403 | 2023-01-05 10:09:59 -0600 | [diff] [blame] | 189 | arg = hexwords[i]; |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 190 | } |
Matt Spinler | c198403 | 2023-01-05 10:09:59 -0600 | [diff] [blame] | 191 | PyTuple_SetItem(pArgs, i, Py_BuildValue("s", arg.c_str())); |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 192 | } |
Matt Spinler | be952d2 | 2022-07-01 11:30:11 -0500 | [diff] [blame] | 193 | PyObject* pResult = PyObject_CallObject(pFunc, pArgs); |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 194 | Py_DECREF(pFunc); |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 195 | if (pResult) |
| 196 | { |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 197 | std::unique_ptr<PyObject, decltype(&pyDecRef)> resPtr( |
| 198 | pResult, &pyDecRef); |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 199 | PyObject* pBytes = |
| 200 | PyUnicode_AsEncodedString(pResult, "utf-8", "~E~"); |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 201 | std::unique_ptr<PyObject, decltype(&pyDecRef)> pyBytePtr( |
| 202 | pBytes, &pyDecRef); |
| 203 | const char* output = PyBytes_AS_STRING(pBytes); |
| 204 | try |
| 205 | { |
Matt Spinler | bb1c1d5 | 2021-06-03 13:18:48 -0600 | [diff] [blame] | 206 | orderedJSON json = orderedJSON::parse(output); |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 207 | if ((json.is_object() && !json.empty()) || |
| 208 | (json.is_array() && json.size() > 0) || |
| 209 | (json.is_string() && json != "")) |
| 210 | { |
| 211 | return prettyJSON(json); |
| 212 | } |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 213 | } |
Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 214 | catch (const std::exception& e) |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 215 | { |
Matt Spinler | 0bacc8e | 2023-07-07 16:25:39 -0500 | [diff] [blame] | 216 | lg2::error( |
| 217 | "Bad JSON from parser. Error = {ERROR}, SRC = {SRC}, module = {MODULE}", |
| 218 | "ERROR", e, "SRC", hexwords.front(), "MODULE", module); |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 219 | return std::nullopt; |
| 220 | } |
| 221 | } |
| 222 | else |
| 223 | { |
| 224 | pErrStr = "No error string found"; |
| 225 | PyErr_Fetch(&eType, &eValue, &eTraceback); |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 226 | if (eType) |
| 227 | { |
| 228 | Py_XDECREF(eType); |
| 229 | } |
| 230 | if (eTraceback) |
| 231 | { |
| 232 | Py_XDECREF(eTraceback); |
| 233 | } |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 234 | if (eValue) |
| 235 | { |
| 236 | PyObject* pStr = PyObject_Str(eValue); |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 237 | Py_XDECREF(eValue); |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 238 | if (pStr) |
| 239 | { |
| 240 | pErrStr = PyUnicode_AsUTF8(pStr); |
Harisuddin Mohamed Isa | 69c1827 | 2021-05-29 13:18:45 +0800 | [diff] [blame] | 241 | Py_XDECREF(pStr); |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 242 | } |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | if (!pErrStr.empty()) |
| 248 | { |
Matt Spinler | 0bacc8e | 2023-07-07 16:25:39 -0500 | [diff] [blame] | 249 | lg2::debug("Python exception thrown by parser. Error = {ERROR}, " |
| 250 | "SRC = {SRC}, module = {MODULE}", |
| 251 | "ERROR", pErrStr, "SRC", hexwords.front(), "MODULE", module); |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 252 | } |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 253 | return std::nullopt; |
| 254 | } |
| 255 | #endif |
| 256 | |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 257 | void SRC::unflatten(Stream& stream) |
| 258 | { |
| 259 | stream >> _header >> _version >> _flags >> _reserved1B >> _wordCount >> |
| 260 | _reserved2B >> _size; |
| 261 | |
| 262 | for (auto& word : _hexData) |
| 263 | { |
| 264 | stream >> word; |
| 265 | } |
| 266 | |
| 267 | _asciiString = std::make_unique<src::AsciiString>(stream); |
| 268 | |
| 269 | if (hasAdditionalSections()) |
| 270 | { |
| 271 | // The callouts section is currently the only extra subsection type |
| 272 | _callouts = std::make_unique<src::Callouts>(stream); |
| 273 | } |
| 274 | } |
| 275 | |
Matt Spinler | 0688545 | 2019-11-06 10:35:42 -0600 | [diff] [blame] | 276 | void SRC::flatten(Stream& stream) const |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 277 | { |
| 278 | stream << _header << _version << _flags << _reserved1B << _wordCount |
| 279 | << _reserved2B << _size; |
| 280 | |
| 281 | for (auto& word : _hexData) |
| 282 | { |
| 283 | stream << word; |
| 284 | } |
| 285 | |
| 286 | _asciiString->flatten(stream); |
| 287 | |
| 288 | if (_callouts) |
| 289 | { |
| 290 | _callouts->flatten(stream); |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | SRC::SRC(Stream& pel) |
| 295 | { |
| 296 | try |
| 297 | { |
| 298 | unflatten(pel); |
| 299 | validate(); |
| 300 | } |
| 301 | catch (const std::exception& e) |
| 302 | { |
Matt Spinler | 0bacc8e | 2023-07-07 16:25:39 -0500 | [diff] [blame] | 303 | lg2::error("Cannot unflatten SRC, error = {ERROR}", "ERROR", e); |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 304 | _valid = false; |
| 305 | } |
| 306 | } |
| 307 | |
Matt Spinler | 075e5ba | 2020-02-21 15:46:00 -0600 | [diff] [blame] | 308 | SRC::SRC(const message::Entry& regEntry, const AdditionalData& additionalData, |
Matt Spinler | 5a90a95 | 2020-08-27 09:39:03 -0500 | [diff] [blame] | 309 | const nlohmann::json& jsonCallouts, const DataInterfaceBase& dataIface) |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 310 | { |
| 311 | _header.id = static_cast<uint16_t>(SectionID::primarySRC); |
| 312 | _header.version = srcSectionVersion; |
| 313 | _header.subType = srcSectionSubtype; |
| 314 | _header.componentID = regEntry.componentID; |
| 315 | |
| 316 | _version = srcVersion; |
| 317 | |
| 318 | _flags = 0; |
Vijay Lobo | f3702bb | 2021-04-09 15:10:19 -0500 | [diff] [blame] | 319 | |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 320 | _reserved1B = 0; |
| 321 | |
| 322 | _wordCount = numSRCHexDataWords + 1; |
| 323 | |
| 324 | _reserved2B = 0; |
| 325 | |
| 326 | // There are multiple fields encoded in the hex data words. |
| 327 | std::for_each(_hexData.begin(), _hexData.end(), |
| 328 | [](auto& word) { word = 0; }); |
Matt Spinler | 7c61918 | 2020-07-27 15:15:11 -0500 | [diff] [blame] | 329 | |
| 330 | // Hex Word 2 Nibbles: |
| 331 | // MIGVEPFF |
| 332 | // M: Partition dump status = 0 |
| 333 | // I: System boot state = TODO |
| 334 | // G: Partition Boot type = 0 |
Sumit Kumar | 9d43a72 | 2021-08-24 09:46:19 -0500 | [diff] [blame] | 335 | // V: BMC dump status |
Matt Spinler | 7c61918 | 2020-07-27 15:15:11 -0500 | [diff] [blame] | 336 | // E: Platform boot mode = 0 (side = temporary, speed = fast) |
Sumit Kumar | 9d43a72 | 2021-08-24 09:46:19 -0500 | [diff] [blame] | 337 | // P: Platform dump status |
Matt Spinler | 7c61918 | 2020-07-27 15:15:11 -0500 | [diff] [blame] | 338 | // FF: SRC format, set below |
| 339 | |
Vijay Lobo | 875b6c7 | 2021-10-20 17:38:56 -0500 | [diff] [blame] | 340 | setProgressCode(dataIface); |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 341 | setBMCFormat(); |
| 342 | setBMCPosition(); |
Matt Spinler | 075e5ba | 2020-02-21 15:46:00 -0600 | [diff] [blame] | 343 | setMotherboardCCIN(dataIface); |
| 344 | |
Matt Spinler | da5b76b | 2023-06-01 15:56:57 -0500 | [diff] [blame] | 345 | if (regEntry.src.checkstopFlag) |
| 346 | { |
| 347 | setErrorStatusFlag(ErrorStatusFlags::hwCheckstop); |
| 348 | } |
| 349 | |
Matt Spinler | 3fe93e9 | 2023-04-14 14:06:59 -0500 | [diff] [blame] | 350 | if (regEntry.src.deconfigFlag) |
| 351 | { |
| 352 | setErrorStatusFlag(ErrorStatusFlags::deconfigured); |
| 353 | } |
| 354 | |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 355 | // Fill in the last 4 words from the AdditionalData property contents. |
| 356 | setUserDefinedHexWords(regEntry, additionalData); |
| 357 | |
| 358 | _asciiString = std::make_unique<src::AsciiString>(regEntry); |
| 359 | |
Sumit Kumar | 50bfa69 | 2022-01-06 06:48:26 -0600 | [diff] [blame] | 360 | // Check for additional data - PEL_SUBSYSTEM |
| 361 | auto ss = additionalData.getValue("PEL_SUBSYSTEM"); |
| 362 | if (ss) |
| 363 | { |
| 364 | auto eventSubsystem = std::stoul(*ss, NULL, 16); |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 365 | std::string subsystem = |
| 366 | pv::getValue(eventSubsystem, pel_values::subsystemValues); |
Sumit Kumar | 50bfa69 | 2022-01-06 06:48:26 -0600 | [diff] [blame] | 367 | if (subsystem == "invalid") |
| 368 | { |
Matt Spinler | 0bacc8e | 2023-07-07 16:25:39 -0500 | [diff] [blame] | 369 | lg2::warning("SRC: Invalid SubSystem value: {VAL}", "VAL", lg2::hex, |
| 370 | eventSubsystem); |
Sumit Kumar | 50bfa69 | 2022-01-06 06:48:26 -0600 | [diff] [blame] | 371 | } |
| 372 | else |
| 373 | { |
| 374 | _asciiString->setByte(2, eventSubsystem); |
| 375 | } |
| 376 | } |
| 377 | |
Matt Spinler | 5a90a95 | 2020-08-27 09:39:03 -0500 | [diff] [blame] | 378 | addCallouts(regEntry, additionalData, jsonCallouts, dataIface); |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 379 | |
| 380 | _size = baseSRCSize; |
| 381 | _size += _callouts ? _callouts->flattenedSize() : 0; |
| 382 | _header.size = Section::flattenedSize() + _size; |
| 383 | |
| 384 | _valid = true; |
| 385 | } |
| 386 | |
| 387 | void SRC::setUserDefinedHexWords(const message::Entry& regEntry, |
| 388 | const AdditionalData& ad) |
| 389 | { |
| 390 | if (!regEntry.src.hexwordADFields) |
| 391 | { |
| 392 | return; |
| 393 | } |
| 394 | |
Harisuddin Mohamed Isa | 1a1b0df | 2020-11-23 16:34:36 +0800 | [diff] [blame] | 395 | // Save the AdditionalData value corresponding to the first element of |
| 396 | // adName tuple into _hexData[wordNum]. |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 397 | for (const auto& [wordNum, adName] : *regEntry.src.hexwordADFields) |
| 398 | { |
| 399 | // Can only set words 6 - 9 |
| 400 | if (!isUserDefinedWord(wordNum)) |
| 401 | { |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 402 | std::string msg = |
| 403 | "SRC user data word out of range: " + std::to_string(wordNum); |
Matt Spinler | 85f61a6 | 2020-06-03 16:28:55 -0500 | [diff] [blame] | 404 | addDebugData(msg); |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 405 | continue; |
| 406 | } |
| 407 | |
Harisuddin Mohamed Isa | 1a1b0df | 2020-11-23 16:34:36 +0800 | [diff] [blame] | 408 | auto value = ad.getValue(std::get<0>(adName)); |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 409 | if (value) |
| 410 | { |
| 411 | _hexData[getWordIndexFromWordNum(wordNum)] = |
| 412 | std::strtoul(value.value().c_str(), nullptr, 0); |
| 413 | } |
| 414 | else |
| 415 | { |
Harisuddin Mohamed Isa | 1a1b0df | 2020-11-23 16:34:36 +0800 | [diff] [blame] | 416 | std::string msg = "Source for user data SRC word not found: " + |
| 417 | std::get<0>(adName); |
Matt Spinler | 85f61a6 | 2020-06-03 16:28:55 -0500 | [diff] [blame] | 418 | addDebugData(msg); |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 419 | } |
| 420 | } |
| 421 | } |
| 422 | |
Matt Spinler | 075e5ba | 2020-02-21 15:46:00 -0600 | [diff] [blame] | 423 | void SRC::setMotherboardCCIN(const DataInterfaceBase& dataIface) |
| 424 | { |
| 425 | uint32_t ccin = 0; |
| 426 | auto ccinString = dataIface.getMotherboardCCIN(); |
| 427 | |
| 428 | try |
| 429 | { |
| 430 | if (ccinString.size() == ccinSize) |
| 431 | { |
| 432 | ccin = std::stoi(ccinString, 0, 16); |
| 433 | } |
| 434 | } |
Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 435 | catch (const std::exception& e) |
Matt Spinler | 075e5ba | 2020-02-21 15:46:00 -0600 | [diff] [blame] | 436 | { |
Matt Spinler | 0bacc8e | 2023-07-07 16:25:39 -0500 | [diff] [blame] | 437 | lg2::warning("Could not convert motherboard CCIN {CCIN} to a number", |
| 438 | "CCIN", ccinString); |
Matt Spinler | 075e5ba | 2020-02-21 15:46:00 -0600 | [diff] [blame] | 439 | return; |
| 440 | } |
| 441 | |
| 442 | // Set the first 2 bytes |
| 443 | _hexData[1] |= ccin << 16; |
| 444 | } |
| 445 | |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 446 | void SRC::validate() |
| 447 | { |
| 448 | bool failed = false; |
| 449 | |
| 450 | if ((header().id != static_cast<uint16_t>(SectionID::primarySRC)) && |
| 451 | (header().id != static_cast<uint16_t>(SectionID::secondarySRC))) |
| 452 | { |
Matt Spinler | 0bacc8e | 2023-07-07 16:25:39 -0500 | [diff] [blame] | 453 | lg2::error("Invalid SRC section ID: {ID}", "ID", lg2::hex, header().id); |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 454 | failed = true; |
| 455 | } |
| 456 | |
| 457 | // Check the version in the SRC, not in the header |
Matt Spinler | bd716f0 | 2019-10-15 10:54:11 -0500 | [diff] [blame] | 458 | if (_version != srcVersion) |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 459 | { |
Matt Spinler | 0bacc8e | 2023-07-07 16:25:39 -0500 | [diff] [blame] | 460 | lg2::error("Invalid SRC version: {VERSION}", "VERSION", lg2::hex, |
| 461 | header().version); |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 462 | failed = true; |
| 463 | } |
| 464 | |
| 465 | _valid = failed ? false : true; |
| 466 | } |
| 467 | |
Matt Spinler | 075e5ba | 2020-02-21 15:46:00 -0600 | [diff] [blame] | 468 | bool SRC::isBMCSRC() const |
| 469 | { |
| 470 | auto as = asciiString(); |
| 471 | if (as.length() >= 2) |
| 472 | { |
| 473 | uint8_t errorType = strtoul(as.substr(0, 2).c_str(), nullptr, 16); |
| 474 | return (errorType == static_cast<uint8_t>(SRCType::bmcError) || |
| 475 | errorType == static_cast<uint8_t>(SRCType::powerError)); |
| 476 | } |
| 477 | return false; |
| 478 | } |
| 479 | |
Matt Spinler | 4deed97 | 2023-04-28 14:09:22 -0500 | [diff] [blame] | 480 | bool SRC::isHostbootSRC() const |
| 481 | { |
| 482 | auto as = asciiString(); |
| 483 | if (as.length() >= 2) |
| 484 | { |
| 485 | uint8_t errorType = strtoul(as.substr(0, 2).c_str(), nullptr, 16); |
| 486 | return errorType == static_cast<uint8_t>(SRCType::hostbootError); |
| 487 | } |
| 488 | return false; |
| 489 | } |
| 490 | |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 491 | std::optional<std::string> SRC::getErrorDetails( |
| 492 | message::Registry& registry, DetailLevel type, bool toCache) const |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 493 | { |
| 494 | const std::string jsonIndent(indentLevel, 0x20); |
| 495 | std::string errorOut; |
Matt Spinler | 075e5ba | 2020-02-21 15:46:00 -0600 | [diff] [blame] | 496 | if (isBMCSRC()) |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 497 | { |
| 498 | auto entry = registry.lookup("0x" + asciiString().substr(4, 4), |
| 499 | rg::LookupType::reasonCode, toCache); |
| 500 | if (entry) |
| 501 | { |
| 502 | errorOut.append(jsonIndent + "\"Error Details\": {\n"); |
| 503 | auto errorMsg = getErrorMessage(*entry); |
| 504 | if (errorMsg) |
| 505 | { |
| 506 | if (type == DetailLevel::message) |
| 507 | { |
| 508 | return errorMsg.value(); |
| 509 | } |
| 510 | else |
| 511 | { |
| 512 | jsonInsert(errorOut, "Message", errorMsg.value(), 2); |
| 513 | } |
| 514 | } |
| 515 | if (entry->src.hexwordADFields) |
| 516 | { |
Harisuddin Mohamed Isa | 1a1b0df | 2020-11-23 16:34:36 +0800 | [diff] [blame] | 517 | std::map<size_t, std::tuple<std::string, std::string>> |
| 518 | adFields = entry->src.hexwordADFields.value(); |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 519 | for (const auto& hexwordMap : adFields) |
| 520 | { |
Zane Shelley | e8db29b | 2021-11-13 10:34:07 -0600 | [diff] [blame] | 521 | auto srcValue = getNumberString( |
Harisuddin Mohamed Isa | 1a1b0df | 2020-11-23 16:34:36 +0800 | [diff] [blame] | 522 | "0x%X", |
Zane Shelley | e8db29b | 2021-11-13 10:34:07 -0600 | [diff] [blame] | 523 | _hexData[getWordIndexFromWordNum(hexwordMap.first)]); |
| 524 | |
| 525 | auto srcKey = std::get<0>(hexwordMap.second); |
| 526 | auto srcDesc = std::get<1>(hexwordMap.second); |
| 527 | |
| 528 | // Only include this hex word in the error details if the |
| 529 | // description exists. |
| 530 | if (!srcDesc.empty()) |
| 531 | { |
| 532 | std::vector<std::string> valueDescr; |
| 533 | valueDescr.push_back(srcValue); |
| 534 | valueDescr.push_back(srcDesc); |
| 535 | jsonInsertArray(errorOut, srcKey, valueDescr, 2); |
| 536 | } |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 537 | } |
| 538 | } |
| 539 | errorOut.erase(errorOut.size() - 2); |
| 540 | errorOut.append("\n"); |
| 541 | errorOut.append(jsonIndent + "},\n"); |
| 542 | return errorOut; |
| 543 | } |
| 544 | } |
| 545 | return std::nullopt; |
| 546 | } |
| 547 | |
| 548 | std::optional<std::string> |
| 549 | SRC::getErrorMessage(const message::Entry& regEntry) const |
| 550 | { |
| 551 | try |
| 552 | { |
| 553 | if (regEntry.doc.messageArgSources) |
| 554 | { |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 555 | std::vector<uint32_t> argSourceVals; |
| 556 | std::string message; |
| 557 | const auto& argValues = regEntry.doc.messageArgSources.value(); |
| 558 | for (size_t i = 0; i < argValues.size(); ++i) |
| 559 | { |
| 560 | argSourceVals.push_back(_hexData[getWordIndexFromWordNum( |
| 561 | argValues[i].back() - '0')]); |
| 562 | } |
Patrick Williams | 0230abb | 2021-04-19 14:32:50 -0500 | [diff] [blame] | 563 | |
| 564 | auto it = std::begin(regEntry.doc.message); |
| 565 | auto it_end = std::end(regEntry.doc.message); |
| 566 | |
| 567 | while (it != it_end) |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 568 | { |
Patrick Williams | 0230abb | 2021-04-19 14:32:50 -0500 | [diff] [blame] | 569 | if (*it == '%') |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 570 | { |
Patrick Williams | 0230abb | 2021-04-19 14:32:50 -0500 | [diff] [blame] | 571 | ++it; |
| 572 | |
| 573 | size_t wordIndex = *it - '0'; |
| 574 | if (isdigit(*it) && wordIndex >= 1 && |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 575 | static_cast<uint16_t>(wordIndex) <= |
| 576 | argSourceVals.size()) |
| 577 | { |
| 578 | message.append(getNumberString( |
Zane Shelley | 39936e3 | 2021-11-13 16:19:34 -0600 | [diff] [blame] | 579 | "0x%08X", argSourceVals[wordIndex - 1])); |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 580 | } |
| 581 | else |
| 582 | { |
Patrick Williams | 0230abb | 2021-04-19 14:32:50 -0500 | [diff] [blame] | 583 | message.append("%" + std::string(1, *it)); |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 584 | } |
| 585 | } |
| 586 | else |
| 587 | { |
Patrick Williams | 0230abb | 2021-04-19 14:32:50 -0500 | [diff] [blame] | 588 | message.push_back(*it); |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 589 | } |
Patrick Williams | 0230abb | 2021-04-19 14:32:50 -0500 | [diff] [blame] | 590 | ++it; |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 591 | } |
Patrick Williams | 0230abb | 2021-04-19 14:32:50 -0500 | [diff] [blame] | 592 | |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 593 | return message; |
| 594 | } |
| 595 | else |
| 596 | { |
| 597 | return regEntry.doc.message; |
| 598 | } |
| 599 | } |
| 600 | catch (const std::exception& e) |
| 601 | { |
Matt Spinler | 0bacc8e | 2023-07-07 16:25:39 -0500 | [diff] [blame] | 602 | lg2::error( |
| 603 | "Cannot get error message from registry entry, error = {ERROR}", |
| 604 | "ERROR", e); |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 605 | } |
| 606 | return std::nullopt; |
| 607 | } |
| 608 | |
| 609 | std::optional<std::string> SRC::getCallouts() const |
| 610 | { |
| 611 | if (!_callouts) |
| 612 | { |
| 613 | return std::nullopt; |
| 614 | } |
| 615 | std::string printOut; |
| 616 | const std::string jsonIndent(indentLevel, 0x20); |
| 617 | const auto& callout = _callouts->callouts(); |
| 618 | const auto& compDescrp = pv::failingComponentType; |
| 619 | printOut.append(jsonIndent + "\"Callout Section\": {\n"); |
| 620 | jsonInsert(printOut, "Callout Count", std::to_string(callout.size()), 2); |
| 621 | printOut.append(jsonIndent + jsonIndent + "\"Callouts\": ["); |
| 622 | for (auto& entry : callout) |
| 623 | { |
| 624 | printOut.append("{\n"); |
| 625 | if (entry->fruIdentity()) |
| 626 | { |
| 627 | jsonInsert( |
| 628 | printOut, "FRU Type", |
| 629 | compDescrp.at(entry->fruIdentity()->failingComponentType()), 3); |
| 630 | jsonInsert(printOut, "Priority", |
| 631 | pv::getValue(entry->priority(), |
| 632 | pel_values::calloutPriorityValues), |
| 633 | 3); |
| 634 | if (!entry->locationCode().empty()) |
| 635 | { |
| 636 | jsonInsert(printOut, "Location Code", entry->locationCode(), 3); |
| 637 | } |
| 638 | if (entry->fruIdentity()->getPN().has_value()) |
| 639 | { |
| 640 | jsonInsert(printOut, "Part Number", |
| 641 | entry->fruIdentity()->getPN().value(), 3); |
| 642 | } |
| 643 | if (entry->fruIdentity()->getMaintProc().has_value()) |
| 644 | { |
Matt Spinler | 9e8b49e | 2020-09-10 13:15:26 -0500 | [diff] [blame] | 645 | jsonInsert(printOut, "Procedure", |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 646 | entry->fruIdentity()->getMaintProc().value(), 3); |
| 647 | if (pv::procedureDesc.find( |
| 648 | entry->fruIdentity()->getMaintProc().value()) != |
| 649 | pv::procedureDesc.end()) |
| 650 | { |
| 651 | jsonInsert( |
| 652 | printOut, "Description", |
| 653 | pv::procedureDesc.at( |
| 654 | entry->fruIdentity()->getMaintProc().value()), |
| 655 | 3); |
| 656 | } |
| 657 | } |
| 658 | if (entry->fruIdentity()->getCCIN().has_value()) |
| 659 | { |
| 660 | jsonInsert(printOut, "CCIN", |
| 661 | entry->fruIdentity()->getCCIN().value(), 3); |
| 662 | } |
| 663 | if (entry->fruIdentity()->getSN().has_value()) |
| 664 | { |
| 665 | jsonInsert(printOut, "Serial Number", |
| 666 | entry->fruIdentity()->getSN().value(), 3); |
| 667 | } |
| 668 | } |
| 669 | if (entry->pceIdentity()) |
| 670 | { |
| 671 | const auto& pceIdentMtms = entry->pceIdentity()->mtms(); |
| 672 | if (!pceIdentMtms.machineTypeAndModel().empty()) |
| 673 | { |
| 674 | jsonInsert(printOut, "PCE MTMS", |
| 675 | pceIdentMtms.machineTypeAndModel() + "_" + |
| 676 | pceIdentMtms.machineSerialNumber(), |
| 677 | 3); |
| 678 | } |
| 679 | if (!entry->pceIdentity()->enclosureName().empty()) |
| 680 | { |
| 681 | jsonInsert(printOut, "PCE Name", |
| 682 | entry->pceIdentity()->enclosureName(), 3); |
| 683 | } |
| 684 | } |
| 685 | if (entry->mru()) |
| 686 | { |
| 687 | const auto& mruCallouts = entry->mru()->mrus(); |
| 688 | std::string mruId; |
| 689 | for (auto& element : mruCallouts) |
| 690 | { |
| 691 | if (!mruId.empty()) |
| 692 | { |
| 693 | mruId.append(", " + getNumberString("%08X", element.id)); |
| 694 | } |
| 695 | else |
| 696 | { |
| 697 | mruId.append(getNumberString("%08X", element.id)); |
| 698 | } |
| 699 | } |
| 700 | jsonInsert(printOut, "MRU Id", mruId, 3); |
| 701 | } |
| 702 | printOut.erase(printOut.size() - 2); |
| 703 | printOut.append("\n" + jsonIndent + jsonIndent + "}, "); |
| 704 | }; |
| 705 | printOut.erase(printOut.size() - 2); |
| 706 | printOut.append("]\n" + jsonIndent + "}"); |
| 707 | return printOut; |
| 708 | } |
| 709 | |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 710 | std::optional<std::string> |
| 711 | SRC::getJSON(message::Registry& registry, |
| 712 | const std::vector<std::string>& plugins [[maybe_unused]], |
| 713 | uint8_t creatorID) const |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 714 | { |
| 715 | std::string ps; |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 716 | std::vector<std::string> hexwords; |
Harisuddin Mohamed Isa | bebeb94 | 2020-03-12 17:12:24 +0800 | [diff] [blame] | 717 | jsonInsert(ps, pv::sectionVer, getNumberString("%d", _header.version), 1); |
| 718 | jsonInsert(ps, pv::subSection, getNumberString("%d", _header.subType), 1); |
Matt Spinler | b832aa5 | 2023-03-21 15:32:34 -0500 | [diff] [blame] | 719 | jsonInsert(ps, pv::createdBy, |
| 720 | getComponentName(_header.componentID, creatorID), 1); |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 721 | jsonInsert(ps, "SRC Version", getNumberString("0x%02X", _version), 1); |
Harisuddin Mohamed Isa | c32e551 | 2020-02-06 18:05:21 +0800 | [diff] [blame] | 722 | jsonInsert(ps, "SRC Format", getNumberString("0x%02X", _hexData[0] & 0xFF), |
| 723 | 1); |
| 724 | jsonInsert(ps, "Virtual Progress SRC", |
| 725 | pv::boolString.at(_flags & virtualProgressSRC), 1); |
| 726 | jsonInsert(ps, "I5/OS Service Event Bit", |
| 727 | pv::boolString.at(_flags & i5OSServiceEventBit), 1); |
| 728 | jsonInsert(ps, "Hypervisor Dump Initiated", |
| 729 | pv::boolString.at(_flags & hypDumpInit), 1); |
Matt Spinler | 075e5ba | 2020-02-21 15:46:00 -0600 | [diff] [blame] | 730 | |
| 731 | if (isBMCSRC()) |
| 732 | { |
| 733 | std::string ccinString; |
| 734 | uint32_t ccin = _hexData[1] >> 16; |
| 735 | |
| 736 | if (ccin) |
| 737 | { |
| 738 | ccinString = getNumberString("%04X", ccin); |
| 739 | } |
| 740 | // The PEL spec calls it a backplane, so call it that here. |
| 741 | jsonInsert(ps, "Backplane CCIN", ccinString, 1); |
Matt Spinler | afa2c79 | 2020-08-27 11:01:39 -0500 | [diff] [blame] | 742 | |
Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 743 | jsonInsert(ps, "Terminate FW Error", |
| 744 | pv::boolString.at( |
| 745 | _hexData[3] & |
| 746 | static_cast<uint32_t>(ErrorStatusFlags::terminateFwErr)), |
| 747 | 1); |
Matt Spinler | 4deed97 | 2023-04-28 14:09:22 -0500 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | if (isBMCSRC() || isHostbootSRC()) |
| 751 | { |
Matt Spinler | afa2c79 | 2020-08-27 11:01:39 -0500 | [diff] [blame] | 752 | jsonInsert(ps, "Deconfigured", |
| 753 | pv::boolString.at( |
| 754 | _hexData[3] & |
| 755 | static_cast<uint32_t>(ErrorStatusFlags::deconfigured)), |
| 756 | 1); |
| 757 | |
| 758 | jsonInsert( |
| 759 | ps, "Guarded", |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 760 | pv::boolString.at( |
| 761 | _hexData[3] & static_cast<uint32_t>(ErrorStatusFlags::guarded)), |
Matt Spinler | afa2c79 | 2020-08-27 11:01:39 -0500 | [diff] [blame] | 762 | 1); |
Matt Spinler | 075e5ba | 2020-02-21 15:46:00 -0600 | [diff] [blame] | 763 | } |
| 764 | |
Harisuddin Mohamed Isa | a214ed3 | 2020-02-28 15:58:23 +0800 | [diff] [blame] | 765 | auto errorDetails = getErrorDetails(registry, DetailLevel::json, true); |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 766 | if (errorDetails) |
| 767 | { |
| 768 | ps.append(errorDetails.value()); |
| 769 | } |
| 770 | jsonInsert(ps, "Valid Word Count", getNumberString("0x%02X", _wordCount), |
| 771 | 1); |
| 772 | std::string refcode = asciiString(); |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 773 | hexwords.push_back(refcode); |
Harisuddin Mohamed Isa | fecaa57 | 2020-03-11 16:04:50 +0800 | [diff] [blame] | 774 | std::string extRefcode; |
| 775 | size_t pos = refcode.find(0x20); |
| 776 | if (pos != std::string::npos) |
| 777 | { |
| 778 | size_t nextPos = refcode.find_first_not_of(0x20, pos); |
| 779 | if (nextPos != std::string::npos) |
| 780 | { |
| 781 | extRefcode = trimEnd(refcode.substr(nextPos)); |
| 782 | } |
| 783 | refcode.erase(pos); |
| 784 | } |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 785 | jsonInsert(ps, "Reference Code", refcode, 1); |
Harisuddin Mohamed Isa | fecaa57 | 2020-03-11 16:04:50 +0800 | [diff] [blame] | 786 | if (!extRefcode.empty()) |
| 787 | { |
| 788 | jsonInsert(ps, "Extended Reference Code", extRefcode, 1); |
| 789 | } |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 790 | for (size_t i = 2; i <= _wordCount; i++) |
| 791 | { |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 792 | std::string tmpWord = |
| 793 | getNumberString("%08X", _hexData[getWordIndexFromWordNum(i)]); |
| 794 | jsonInsert(ps, "Hex Word " + std::to_string(i), tmpWord, 1); |
| 795 | hexwords.push_back(tmpWord); |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 796 | } |
| 797 | auto calloutJson = getCallouts(); |
| 798 | if (calloutJson) |
| 799 | { |
| 800 | ps.append(calloutJson.value()); |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 801 | ps.append(",\n"); |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 802 | } |
Harisuddin Mohamed Isa | c8d6cc6 | 2020-08-19 22:47:19 +0800 | [diff] [blame] | 803 | std::string subsystem = getNumberString("%c", tolower(creatorID)); |
| 804 | bool srcDetailExists = false; |
| 805 | #ifdef PELTOOL |
| 806 | if (std::find(plugins.begin(), plugins.end(), subsystem + "src") != |
| 807 | plugins.end()) |
| 808 | { |
| 809 | auto pyJson = getPythonJSON(hexwords, creatorID); |
| 810 | if (pyJson) |
| 811 | { |
| 812 | ps.append(pyJson.value()); |
| 813 | srcDetailExists = true; |
| 814 | } |
| 815 | } |
| 816 | #endif |
| 817 | if (!srcDetailExists) |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 818 | { |
| 819 | ps.erase(ps.size() - 2); |
| 820 | } |
| 821 | return ps; |
| 822 | } |
| 823 | |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 824 | void SRC::addCallouts(const message::Entry& regEntry, |
| 825 | const AdditionalData& additionalData, |
Matt Spinler | 5a90a95 | 2020-08-27 09:39:03 -0500 | [diff] [blame] | 826 | const nlohmann::json& jsonCallouts, |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 827 | const DataInterfaceBase& dataIface) |
| 828 | { |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 829 | auto registryCallouts = |
| 830 | getRegistryCallouts(regEntry, additionalData, dataIface); |
Matt Spinler | f00f9d0 | 2020-10-23 09:14:22 -0500 | [diff] [blame] | 831 | |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 832 | auto item = additionalData.getValue("CALLOUT_INVENTORY_PATH"); |
Miguel Gomez | 53ef155 | 2020-10-14 21:16:32 +0000 | [diff] [blame] | 833 | auto priority = additionalData.getValue("CALLOUT_PRIORITY"); |
Matt Spinler | f00f9d0 | 2020-10-23 09:14:22 -0500 | [diff] [blame] | 834 | |
Miguel Gomez | 53ef155 | 2020-10-14 21:16:32 +0000 | [diff] [blame] | 835 | std::optional<CalloutPriority> calloutPriority; |
| 836 | |
| 837 | // Only H, M or L priority values. |
| 838 | if (priority && !(*priority).empty()) |
| 839 | { |
| 840 | uint8_t p = (*priority)[0]; |
| 841 | if (p == 'H' || p == 'M' || p == 'L') |
| 842 | { |
| 843 | calloutPriority = static_cast<CalloutPriority>(p); |
| 844 | } |
| 845 | } |
Matt Spinler | f00f9d0 | 2020-10-23 09:14:22 -0500 | [diff] [blame] | 846 | // If the first registry callout says to use the passed in inventory |
| 847 | // path to get the location code for a symbolic FRU callout with a |
| 848 | // trusted location code, then do not add the inventory path as a |
| 849 | // normal FRU callout. |
| 850 | bool useInvForSymbolicFRULocCode = |
| 851 | !registryCallouts.empty() && registryCallouts[0].useInventoryLocCode && |
| 852 | !registryCallouts[0].symbolicFRUTrusted.empty(); |
| 853 | |
| 854 | if (item && !useInvForSymbolicFRULocCode) |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 855 | { |
Miguel Gomez | 53ef155 | 2020-10-14 21:16:32 +0000 | [diff] [blame] | 856 | addInventoryCallout(*item, calloutPriority, std::nullopt, dataIface); |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 857 | } |
| 858 | |
Matt Spinler | 717de42 | 2020-06-04 13:10:14 -0500 | [diff] [blame] | 859 | addDevicePathCallouts(additionalData, dataIface); |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 860 | |
Matt Spinler | f00f9d0 | 2020-10-23 09:14:22 -0500 | [diff] [blame] | 861 | addRegistryCallouts(registryCallouts, dataIface, |
| 862 | (useInvForSymbolicFRULocCode) ? item : std::nullopt); |
Matt Spinler | 5a90a95 | 2020-08-27 09:39:03 -0500 | [diff] [blame] | 863 | |
| 864 | if (!jsonCallouts.empty()) |
| 865 | { |
| 866 | addJSONCallouts(jsonCallouts, dataIface); |
| 867 | } |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | void SRC::addInventoryCallout(const std::string& inventoryPath, |
Matt Spinler | af191c7 | 2020-06-04 11:35:13 -0500 | [diff] [blame] | 871 | const std::optional<CalloutPriority>& priority, |
| 872 | const std::optional<std::string>& locationCode, |
Matt Spinler | b8cb60f | 2020-08-27 10:55:55 -0500 | [diff] [blame] | 873 | const DataInterfaceBase& dataIface, |
| 874 | const std::vector<src::MRU::MRUCallout>& mrus) |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 875 | { |
| 876 | std::string locCode; |
| 877 | std::string fn; |
| 878 | std::string ccin; |
| 879 | std::string sn; |
| 880 | std::unique_ptr<src::Callout> callout; |
| 881 | |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 882 | try |
| 883 | { |
Matt Spinler | af191c7 | 2020-06-04 11:35:13 -0500 | [diff] [blame] | 884 | // Use the passed in location code if there otherwise look it up |
| 885 | if (locationCode) |
| 886 | { |
| 887 | locCode = *locationCode; |
| 888 | } |
| 889 | else |
| 890 | { |
| 891 | locCode = dataIface.getLocationCode(inventoryPath); |
| 892 | } |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 893 | |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 894 | try |
| 895 | { |
| 896 | dataIface.getHWCalloutFields(inventoryPath, fn, ccin, sn); |
| 897 | |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 898 | CalloutPriority p = |
| 899 | priority ? priority.value() : CalloutPriority::high; |
Matt Spinler | af191c7 | 2020-06-04 11:35:13 -0500 | [diff] [blame] | 900 | |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 901 | callout = |
| 902 | std::make_unique<src::Callout>(p, locCode, fn, ccin, sn, mrus); |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 903 | } |
Patrick Williams | 45e8352 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 904 | catch (const sdbusplus::exception_t& e) |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 905 | { |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 906 | std::string msg = |
| 907 | "No VPD found for " + inventoryPath + ": " + e.what(); |
Matt Spinler | 85f61a6 | 2020-06-03 16:28:55 -0500 | [diff] [blame] | 908 | addDebugData(msg); |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 909 | |
| 910 | // Just create the callout with empty FRU fields |
Matt Spinler | b8cb60f | 2020-08-27 10:55:55 -0500 | [diff] [blame] | 911 | callout = std::make_unique<src::Callout>( |
| 912 | CalloutPriority::high, locCode, fn, ccin, sn, mrus); |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 913 | } |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 914 | } |
Patrick Williams | 45e8352 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 915 | catch (const sdbusplus::exception_t& e) |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 916 | { |
Matt Spinler | 85f61a6 | 2020-06-03 16:28:55 -0500 | [diff] [blame] | 917 | std::string msg = "Could not get location code for " + inventoryPath + |
| 918 | ": " + e.what(); |
| 919 | addDebugData(msg); |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 920 | |
Matt Spinler | 479b692 | 2021-08-17 16:34:59 -0500 | [diff] [blame] | 921 | // Don't add a callout in this case, because: |
| 922 | // 1) With how the inventory is primed, there is no case where |
| 923 | // a location code is expected to be missing. This implies |
| 924 | // the caller is passing in something invalid. |
| 925 | // 2) The addDebugData call above will put the passed in path into |
| 926 | // a user data section that can be seen by development for debug. |
| 927 | // 3) Even if we wanted to do a 'no_vpd_for_fru' sort of maint. |
| 928 | // procedure, we don't have a good way to indicate to the user |
| 929 | // anything about the intended callout (they won't see user data). |
| 930 | // 4) Creating a new standalone event log for this problem isn't |
| 931 | // possible from inside a PEL section. |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 932 | } |
| 933 | |
Matt Spinler | 479b692 | 2021-08-17 16:34:59 -0500 | [diff] [blame] | 934 | if (callout) |
| 935 | { |
| 936 | createCalloutsObject(); |
| 937 | _callouts->addCallout(std::move(callout)); |
| 938 | } |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 939 | } |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 940 | |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 941 | std::vector<message::RegistryCallout> SRC::getRegistryCallouts( |
| 942 | const message::Entry& regEntry, const AdditionalData& additionalData, |
| 943 | const DataInterfaceBase& dataIface) |
Matt Spinler | f00f9d0 | 2020-10-23 09:14:22 -0500 | [diff] [blame] | 944 | { |
| 945 | std::vector<message::RegistryCallout> registryCallouts; |
| 946 | |
| 947 | if (regEntry.callouts) |
| 948 | { |
Matt Spinler | 9a50c8d | 2021-04-12 14:22:26 -0500 | [diff] [blame] | 949 | std::vector<std::string> systemNames; |
| 950 | |
Matt Spinler | f00f9d0 | 2020-10-23 09:14:22 -0500 | [diff] [blame] | 951 | try |
| 952 | { |
Matt Spinler | 9a50c8d | 2021-04-12 14:22:26 -0500 | [diff] [blame] | 953 | systemNames = dataIface.getSystemNames(); |
| 954 | } |
| 955 | catch (const std::exception& e) |
| 956 | { |
| 957 | // Compatible interface not available yet |
| 958 | } |
Matt Spinler | f00f9d0 | 2020-10-23 09:14:22 -0500 | [diff] [blame] | 959 | |
Matt Spinler | 9a50c8d | 2021-04-12 14:22:26 -0500 | [diff] [blame] | 960 | try |
| 961 | { |
Matt Spinler | f00f9d0 | 2020-10-23 09:14:22 -0500 | [diff] [blame] | 962 | registryCallouts = message::Registry::getCallouts( |
| 963 | regEntry.callouts.value(), systemNames, additionalData); |
| 964 | } |
| 965 | catch (const std::exception& e) |
| 966 | { |
Jayanth Othayoth | 1aa90d4 | 2023-09-13 04:25:45 -0500 | [diff] [blame] | 967 | addDebugData(std::format( |
Matt Spinler | f00f9d0 | 2020-10-23 09:14:22 -0500 | [diff] [blame] | 968 | "Error parsing PEL message registry callout JSON: {}", |
| 969 | e.what())); |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | return registryCallouts; |
| 974 | } |
| 975 | |
| 976 | void SRC::addRegistryCallouts( |
| 977 | const std::vector<message::RegistryCallout>& callouts, |
| 978 | const DataInterfaceBase& dataIface, |
| 979 | std::optional<std::string> trustedSymbolicFRUInvPath) |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 980 | { |
| 981 | try |
| 982 | { |
Matt Spinler | f00f9d0 | 2020-10-23 09:14:22 -0500 | [diff] [blame] | 983 | for (const auto& callout : callouts) |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 984 | { |
Matt Spinler | f00f9d0 | 2020-10-23 09:14:22 -0500 | [diff] [blame] | 985 | addRegistryCallout(callout, dataIface, trustedSymbolicFRUInvPath); |
| 986 | |
| 987 | // Only the first callout gets the inventory path |
| 988 | if (trustedSymbolicFRUInvPath) |
| 989 | { |
| 990 | trustedSymbolicFRUInvPath = std::nullopt; |
| 991 | } |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 992 | } |
| 993 | } |
Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 994 | catch (const std::exception& e) |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 995 | { |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 996 | std::string msg = |
| 997 | "Error parsing PEL message registry callout JSON: "s + e.what(); |
Matt Spinler | 85f61a6 | 2020-06-03 16:28:55 -0500 | [diff] [blame] | 998 | addDebugData(msg); |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 999 | } |
| 1000 | } |
| 1001 | |
Matt Spinler | f00f9d0 | 2020-10-23 09:14:22 -0500 | [diff] [blame] | 1002 | void SRC::addRegistryCallout( |
| 1003 | const message::RegistryCallout& regCallout, |
| 1004 | const DataInterfaceBase& dataIface, |
| 1005 | const std::optional<std::string>& trustedSymbolicFRUInvPath) |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 1006 | { |
| 1007 | std::unique_ptr<src::Callout> callout; |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 1008 | auto locCode = regCallout.locCode; |
| 1009 | |
Matt Spinler | af191c7 | 2020-06-04 11:35:13 -0500 | [diff] [blame] | 1010 | if (!locCode.empty()) |
| 1011 | { |
| 1012 | try |
| 1013 | { |
| 1014 | locCode = dataIface.expandLocationCode(locCode, 0); |
| 1015 | } |
| 1016 | catch (const std::exception& e) |
| 1017 | { |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 1018 | auto msg = "Unable to expand location code " + locCode + ": " + |
| 1019 | e.what(); |
Matt Spinler | af191c7 | 2020-06-04 11:35:13 -0500 | [diff] [blame] | 1020 | addDebugData(msg); |
| 1021 | return; |
| 1022 | } |
| 1023 | } |
| 1024 | |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 1025 | // Via the PEL values table, get the priority enum. |
| 1026 | // The schema will have validated the priority was a valid value. |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 1027 | auto priorityIt = |
| 1028 | pv::findByName(regCallout.priority, pv::calloutPriorityValues); |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 1029 | assert(priorityIt != pv::calloutPriorityValues.end()); |
| 1030 | auto priority = |
| 1031 | static_cast<CalloutPriority>(std::get<pv::fieldValuePos>(*priorityIt)); |
| 1032 | |
| 1033 | if (!regCallout.procedure.empty()) |
| 1034 | { |
| 1035 | // Procedure callout |
Matt Spinler | 2edce4e | 2024-01-17 11:13:51 -0600 | [diff] [blame] | 1036 | callout = std::make_unique<src::Callout>(priority, regCallout.procedure, |
| 1037 | src::CalloutValueType::raw); |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 1038 | } |
| 1039 | else if (!regCallout.symbolicFRU.empty()) |
| 1040 | { |
| 1041 | // Symbolic FRU callout |
| 1042 | callout = std::make_unique<src::Callout>( |
| 1043 | priority, regCallout.symbolicFRU, locCode, false); |
| 1044 | } |
| 1045 | else if (!regCallout.symbolicFRUTrusted.empty()) |
| 1046 | { |
| 1047 | // Symbolic FRU with trusted location code callout |
| 1048 | |
Matt Spinler | f00f9d0 | 2020-10-23 09:14:22 -0500 | [diff] [blame] | 1049 | // Use the location code from the inventory path if there is one. |
| 1050 | if (trustedSymbolicFRUInvPath) |
| 1051 | { |
| 1052 | try |
| 1053 | { |
| 1054 | locCode = dataIface.getLocationCode(*trustedSymbolicFRUInvPath); |
| 1055 | } |
| 1056 | catch (const std::exception& e) |
| 1057 | { |
| 1058 | addDebugData( |
Jayanth Othayoth | 1aa90d4 | 2023-09-13 04:25:45 -0500 | [diff] [blame] | 1059 | std::format("Could not get location code for {}: {}", |
Matt Spinler | f00f9d0 | 2020-10-23 09:14:22 -0500 | [diff] [blame] | 1060 | *trustedSymbolicFRUInvPath, e.what())); |
| 1061 | locCode.clear(); |
| 1062 | } |
| 1063 | } |
| 1064 | |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 1065 | // The registry wants it to be trusted, but that requires a valid |
| 1066 | // location code for it to actually be. |
| 1067 | callout = std::make_unique<src::Callout>( |
| 1068 | priority, regCallout.symbolicFRUTrusted, locCode, !locCode.empty()); |
| 1069 | } |
| 1070 | else |
| 1071 | { |
Matt Spinler | af191c7 | 2020-06-04 11:35:13 -0500 | [diff] [blame] | 1072 | // A hardware callout |
Matt Spinler | bad056b | 2023-01-25 14:16:57 -0600 | [diff] [blame] | 1073 | std::vector<std::string> inventoryPaths; |
Matt Spinler | af191c7 | 2020-06-04 11:35:13 -0500 | [diff] [blame] | 1074 | |
| 1075 | try |
| 1076 | { |
| 1077 | // Get the inventory item from the unexpanded location code |
Matt Spinler | bad056b | 2023-01-25 14:16:57 -0600 | [diff] [blame] | 1078 | inventoryPaths = |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 1079 | dataIface.getInventoryFromLocCode(regCallout.locCode, 0, false); |
Matt Spinler | af191c7 | 2020-06-04 11:35:13 -0500 | [diff] [blame] | 1080 | } |
| 1081 | catch (const std::exception& e) |
| 1082 | { |
| 1083 | std::string msg = |
| 1084 | "Unable to get inventory path from location code: " + locCode + |
| 1085 | ": " + e.what(); |
| 1086 | addDebugData(msg); |
| 1087 | return; |
| 1088 | } |
| 1089 | |
Matt Spinler | bad056b | 2023-01-25 14:16:57 -0600 | [diff] [blame] | 1090 | // Just use first path returned since they all point to the same FRU. |
| 1091 | addInventoryCallout(inventoryPaths[0], priority, locCode, dataIface); |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | if (callout) |
| 1095 | { |
| 1096 | createCalloutsObject(); |
| 1097 | _callouts->addCallout(std::move(callout)); |
| 1098 | } |
| 1099 | } |
Matt Spinler | ed04685 | 2020-03-13 13:58:15 -0500 | [diff] [blame] | 1100 | |
Matt Spinler | 717de42 | 2020-06-04 13:10:14 -0500 | [diff] [blame] | 1101 | void SRC::addDevicePathCallouts(const AdditionalData& additionalData, |
| 1102 | const DataInterfaceBase& dataIface) |
| 1103 | { |
| 1104 | std::vector<device_callouts::Callout> callouts; |
| 1105 | auto i2cBus = additionalData.getValue("CALLOUT_IIC_BUS"); |
| 1106 | auto i2cAddr = additionalData.getValue("CALLOUT_IIC_ADDR"); |
| 1107 | auto devPath = additionalData.getValue("CALLOUT_DEVICE_PATH"); |
| 1108 | |
| 1109 | // A device callout contains either: |
| 1110 | // * CALLOUT_ERRNO, CALLOUT_DEVICE_PATH |
| 1111 | // * CALLOUT_ERRNO, CALLOUT_IIC_BUS, CALLOUT_IIC_ADDR |
| 1112 | // We don't care about the errno. |
| 1113 | |
| 1114 | if (devPath) |
| 1115 | { |
| 1116 | try |
| 1117 | { |
| 1118 | callouts = device_callouts::getCallouts(*devPath, |
| 1119 | dataIface.getSystemNames()); |
| 1120 | } |
| 1121 | catch (const std::exception& e) |
| 1122 | { |
| 1123 | addDebugData(e.what()); |
| 1124 | callouts.clear(); |
| 1125 | } |
| 1126 | } |
| 1127 | else if (i2cBus && i2cAddr) |
| 1128 | { |
| 1129 | size_t bus; |
| 1130 | uint8_t address; |
| 1131 | |
| 1132 | try |
| 1133 | { |
| 1134 | // If /dev/i2c- is prepended, remove it |
| 1135 | if (i2cBus->find("/dev/i2c-") != std::string::npos) |
| 1136 | { |
| 1137 | *i2cBus = i2cBus->substr(9); |
| 1138 | } |
| 1139 | |
| 1140 | bus = stoul(*i2cBus, nullptr, 0); |
| 1141 | address = stoul(*i2cAddr, nullptr, 0); |
| 1142 | } |
| 1143 | catch (const std::exception& e) |
| 1144 | { |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 1145 | std::string msg = |
| 1146 | "Invalid CALLOUT_IIC_BUS " + *i2cBus + " or CALLOUT_IIC_ADDR " + |
| 1147 | *i2cAddr + " in AdditionalData property"; |
Matt Spinler | 717de42 | 2020-06-04 13:10:14 -0500 | [diff] [blame] | 1148 | addDebugData(msg); |
| 1149 | return; |
| 1150 | } |
| 1151 | |
| 1152 | try |
| 1153 | { |
| 1154 | callouts = device_callouts::getI2CCallouts( |
| 1155 | bus, address, dataIface.getSystemNames()); |
| 1156 | } |
| 1157 | catch (const std::exception& e) |
| 1158 | { |
| 1159 | addDebugData(e.what()); |
| 1160 | callouts.clear(); |
| 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | for (const auto& callout : callouts) |
| 1165 | { |
| 1166 | // The priority shouldn't be invalid, but check just in case. |
| 1167 | CalloutPriority priority = CalloutPriority::high; |
| 1168 | |
| 1169 | if (!callout.priority.empty()) |
| 1170 | { |
| 1171 | auto p = pel_values::findByValue( |
| 1172 | static_cast<uint32_t>(callout.priority[0]), |
| 1173 | pel_values::calloutPriorityValues); |
| 1174 | |
| 1175 | if (p != pel_values::calloutPriorityValues.end()) |
| 1176 | { |
| 1177 | priority = static_cast<CalloutPriority>(callout.priority[0]); |
| 1178 | } |
| 1179 | else |
| 1180 | { |
| 1181 | std::string msg = |
| 1182 | "Invalid priority found in dev callout JSON: " + |
| 1183 | callout.priority[0]; |
| 1184 | addDebugData(msg); |
| 1185 | } |
| 1186 | } |
| 1187 | |
Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 1188 | std::optional<std::string> locCode; |
| 1189 | |
| 1190 | try |
| 1191 | { |
| 1192 | locCode = dataIface.expandLocationCode(callout.locationCode, 0); |
| 1193 | } |
| 1194 | catch (const std::exception& e) |
| 1195 | { |
Jayanth Othayoth | 1aa90d4 | 2023-09-13 04:25:45 -0500 | [diff] [blame] | 1196 | auto msg = std::format("Unable to expand location code {}: {}", |
Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 1197 | callout.locationCode, e.what()); |
| 1198 | addDebugData(msg); |
| 1199 | } |
| 1200 | |
Matt Spinler | 717de42 | 2020-06-04 13:10:14 -0500 | [diff] [blame] | 1201 | try |
| 1202 | { |
Matt Spinler | bad056b | 2023-01-25 14:16:57 -0600 | [diff] [blame] | 1203 | auto inventoryPaths = dataIface.getInventoryFromLocCode( |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 1204 | callout.locationCode, 0, false); |
Matt Spinler | 717de42 | 2020-06-04 13:10:14 -0500 | [diff] [blame] | 1205 | |
Matt Spinler | bad056b | 2023-01-25 14:16:57 -0600 | [diff] [blame] | 1206 | // Just use first path returned since they all |
| 1207 | // point to the same FRU. |
| 1208 | addInventoryCallout(inventoryPaths[0], priority, locCode, |
| 1209 | dataIface); |
Matt Spinler | 717de42 | 2020-06-04 13:10:14 -0500 | [diff] [blame] | 1210 | } |
| 1211 | catch (const std::exception& e) |
| 1212 | { |
| 1213 | std::string msg = |
| 1214 | "Unable to get inventory path from location code: " + |
| 1215 | callout.locationCode + ": " + e.what(); |
| 1216 | addDebugData(msg); |
| 1217 | } |
| 1218 | |
| 1219 | // Until the code is there to convert these MRU value strings to |
| 1220 | // the official MRU values in the callout objects, just store |
| 1221 | // the MRU name in the debug UserData section. |
| 1222 | if (!callout.mru.empty()) |
| 1223 | { |
| 1224 | std::string msg = "MRU: " + callout.mru; |
| 1225 | addDebugData(msg); |
| 1226 | } |
| 1227 | |
| 1228 | // getCallouts() may have generated some debug data it stored |
| 1229 | // in a callout object. Save it as well. |
| 1230 | if (!callout.debug.empty()) |
| 1231 | { |
| 1232 | addDebugData(callout.debug); |
| 1233 | } |
| 1234 | } |
| 1235 | } |
| 1236 | |
Matt Spinler | 5a90a95 | 2020-08-27 09:39:03 -0500 | [diff] [blame] | 1237 | void SRC::addJSONCallouts(const nlohmann::json& jsonCallouts, |
| 1238 | const DataInterfaceBase& dataIface) |
| 1239 | { |
| 1240 | if (jsonCallouts.empty()) |
| 1241 | { |
| 1242 | return; |
| 1243 | } |
| 1244 | |
| 1245 | if (!jsonCallouts.is_array()) |
| 1246 | { |
| 1247 | addDebugData("Callout JSON isn't an array"); |
| 1248 | return; |
| 1249 | } |
| 1250 | |
| 1251 | for (const auto& callout : jsonCallouts) |
| 1252 | { |
| 1253 | try |
| 1254 | { |
| 1255 | addJSONCallout(callout, dataIface); |
| 1256 | } |
| 1257 | catch (const std::exception& e) |
| 1258 | { |
Jayanth Othayoth | 1aa90d4 | 2023-09-13 04:25:45 -0500 | [diff] [blame] | 1259 | addDebugData(std::format( |
Matt Spinler | 5a90a95 | 2020-08-27 09:39:03 -0500 | [diff] [blame] | 1260 | "Failed extracting callout data from JSON: {}", e.what())); |
| 1261 | } |
| 1262 | } |
| 1263 | } |
| 1264 | |
| 1265 | void SRC::addJSONCallout(const nlohmann::json& jsonCallout, |
| 1266 | const DataInterfaceBase& dataIface) |
| 1267 | { |
Matt Spinler | 3bdd011 | 2020-08-27 10:24:34 -0500 | [diff] [blame] | 1268 | auto priority = getPriorityFromJSON(jsonCallout); |
| 1269 | std::string locCode; |
| 1270 | std::string unexpandedLocCode; |
| 1271 | std::unique_ptr<src::Callout> callout; |
| 1272 | |
| 1273 | // Expand the location code if it's there |
| 1274 | if (jsonCallout.contains("LocationCode")) |
| 1275 | { |
| 1276 | unexpandedLocCode = jsonCallout.at("LocationCode").get<std::string>(); |
| 1277 | |
| 1278 | try |
| 1279 | { |
| 1280 | locCode = dataIface.expandLocationCode(unexpandedLocCode, 0); |
| 1281 | } |
| 1282 | catch (const std::exception& e) |
| 1283 | { |
Jayanth Othayoth | 1aa90d4 | 2023-09-13 04:25:45 -0500 | [diff] [blame] | 1284 | addDebugData(std::format("Unable to expand location code {}: {}", |
Matt Spinler | 3bdd011 | 2020-08-27 10:24:34 -0500 | [diff] [blame] | 1285 | unexpandedLocCode, e.what())); |
| 1286 | // Use the value from the JSON so at least there's something |
| 1287 | locCode = unexpandedLocCode; |
| 1288 | } |
| 1289 | } |
| 1290 | |
| 1291 | // Create either a procedure, symbolic FRU, or normal FRU callout. |
| 1292 | if (jsonCallout.contains("Procedure")) |
| 1293 | { |
| 1294 | auto procedure = jsonCallout.at("Procedure").get<std::string>(); |
| 1295 | |
Matt Spinler | 3c7ec6d | 2022-05-06 08:50:20 -0500 | [diff] [blame] | 1296 | // If it's the registry name instead of the raw name, convert. |
| 1297 | if (pv::maintenanceProcedures.find(procedure) != |
| 1298 | pv::maintenanceProcedures.end()) |
| 1299 | { |
| 1300 | procedure = pv::maintenanceProcedures.at(procedure); |
| 1301 | } |
| 1302 | |
Matt Spinler | 3bdd011 | 2020-08-27 10:24:34 -0500 | [diff] [blame] | 1303 | callout = std::make_unique<src::Callout>( |
| 1304 | static_cast<CalloutPriority>(priority), procedure, |
| 1305 | src::CalloutValueType::raw); |
| 1306 | } |
| 1307 | else if (jsonCallout.contains("SymbolicFRU")) |
| 1308 | { |
| 1309 | auto fru = jsonCallout.at("SymbolicFRU").get<std::string>(); |
| 1310 | |
Matt Spinler | 3c7ec6d | 2022-05-06 08:50:20 -0500 | [diff] [blame] | 1311 | // If it's the registry name instead of the raw name, convert. |
| 1312 | if (pv::symbolicFRUs.find(fru) != pv::symbolicFRUs.end()) |
| 1313 | { |
| 1314 | fru = pv::symbolicFRUs.at(fru); |
| 1315 | } |
| 1316 | |
Matt Spinler | 3bdd011 | 2020-08-27 10:24:34 -0500 | [diff] [blame] | 1317 | bool trusted = false; |
| 1318 | if (jsonCallout.contains("TrustedLocationCode") && !locCode.empty()) |
| 1319 | { |
| 1320 | trusted = jsonCallout.at("TrustedLocationCode").get<bool>(); |
| 1321 | } |
| 1322 | |
| 1323 | callout = std::make_unique<src::Callout>( |
| 1324 | static_cast<CalloutPriority>(priority), fru, |
| 1325 | src::CalloutValueType::raw, locCode, trusted); |
| 1326 | } |
| 1327 | else |
| 1328 | { |
| 1329 | // A hardware FRU |
| 1330 | std::string inventoryPath; |
Matt Spinler | b8cb60f | 2020-08-27 10:55:55 -0500 | [diff] [blame] | 1331 | std::vector<src::MRU::MRUCallout> mrus; |
Matt Spinler | 3bdd011 | 2020-08-27 10:24:34 -0500 | [diff] [blame] | 1332 | |
| 1333 | if (jsonCallout.contains("InventoryPath")) |
| 1334 | { |
| 1335 | inventoryPath = jsonCallout.at("InventoryPath").get<std::string>(); |
| 1336 | } |
| 1337 | else |
| 1338 | { |
| 1339 | if (unexpandedLocCode.empty()) |
| 1340 | { |
| 1341 | throw std::runtime_error{"JSON callout needs either an " |
| 1342 | "inventory path or location code"}; |
| 1343 | } |
| 1344 | |
| 1345 | try |
| 1346 | { |
Matt Spinler | bad056b | 2023-01-25 14:16:57 -0600 | [diff] [blame] | 1347 | auto inventoryPaths = dataIface.getInventoryFromLocCode( |
Matt Spinler | 3bdd011 | 2020-08-27 10:24:34 -0500 | [diff] [blame] | 1348 | unexpandedLocCode, 0, false); |
Matt Spinler | bad056b | 2023-01-25 14:16:57 -0600 | [diff] [blame] | 1349 | // Just use first path returned since they all |
| 1350 | // point to the same FRU. |
| 1351 | inventoryPath = inventoryPaths[0]; |
Matt Spinler | 3bdd011 | 2020-08-27 10:24:34 -0500 | [diff] [blame] | 1352 | } |
| 1353 | catch (const std::exception& e) |
| 1354 | { |
| 1355 | throw std::runtime_error{ |
Jayanth Othayoth | 1aa90d4 | 2023-09-13 04:25:45 -0500 | [diff] [blame] | 1356 | std::format("Unable to get inventory path from " |
Matt Spinler | 3bdd011 | 2020-08-27 10:24:34 -0500 | [diff] [blame] | 1357 | "location code: {}: {}", |
| 1358 | unexpandedLocCode, e.what())}; |
| 1359 | } |
| 1360 | } |
| 1361 | |
Matt Spinler | b8cb60f | 2020-08-27 10:55:55 -0500 | [diff] [blame] | 1362 | if (jsonCallout.contains("MRUs")) |
| 1363 | { |
| 1364 | mrus = getMRUsFromJSON(jsonCallout.at("MRUs")); |
| 1365 | } |
| 1366 | |
Matt Spinler | 3bdd011 | 2020-08-27 10:24:34 -0500 | [diff] [blame] | 1367 | // If the location code was also passed in, use that here too |
| 1368 | // so addInventoryCallout doesn't have to look it up. |
| 1369 | std::optional<std::string> lc; |
| 1370 | if (!locCode.empty()) |
| 1371 | { |
| 1372 | lc = locCode; |
| 1373 | } |
| 1374 | |
Matt Spinler | b8cb60f | 2020-08-27 10:55:55 -0500 | [diff] [blame] | 1375 | addInventoryCallout(inventoryPath, priority, lc, dataIface, mrus); |
Matt Spinler | afa2c79 | 2020-08-27 11:01:39 -0500 | [diff] [blame] | 1376 | |
| 1377 | if (jsonCallout.contains("Deconfigured")) |
| 1378 | { |
| 1379 | if (jsonCallout.at("Deconfigured").get<bool>()) |
| 1380 | { |
| 1381 | setErrorStatusFlag(ErrorStatusFlags::deconfigured); |
| 1382 | } |
| 1383 | } |
| 1384 | |
| 1385 | if (jsonCallout.contains("Guarded")) |
| 1386 | { |
| 1387 | if (jsonCallout.at("Guarded").get<bool>()) |
| 1388 | { |
| 1389 | setErrorStatusFlag(ErrorStatusFlags::guarded); |
| 1390 | } |
| 1391 | } |
Matt Spinler | 3bdd011 | 2020-08-27 10:24:34 -0500 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | if (callout) |
| 1395 | { |
| 1396 | createCalloutsObject(); |
| 1397 | _callouts->addCallout(std::move(callout)); |
| 1398 | } |
| 1399 | } |
| 1400 | |
| 1401 | CalloutPriority SRC::getPriorityFromJSON(const nlohmann::json& json) |
| 1402 | { |
| 1403 | // Looks like: |
| 1404 | // { |
| 1405 | // "Priority": "H" |
| 1406 | // } |
| 1407 | auto p = json.at("Priority").get<std::string>(); |
| 1408 | if (p.empty()) |
| 1409 | { |
| 1410 | throw std::runtime_error{"Priority field in callout is empty"}; |
| 1411 | } |
| 1412 | |
| 1413 | auto priority = static_cast<CalloutPriority>(p.front()); |
| 1414 | |
| 1415 | // Validate it |
| 1416 | auto priorityIt = pv::findByValue(static_cast<uint32_t>(priority), |
| 1417 | pv::calloutPriorityValues); |
| 1418 | if (priorityIt == pv::calloutPriorityValues.end()) |
| 1419 | { |
| 1420 | throw std::runtime_error{ |
Jayanth Othayoth | 1aa90d4 | 2023-09-13 04:25:45 -0500 | [diff] [blame] | 1421 | std::format("Invalid priority '{}' found in JSON callout", p)}; |
Matt Spinler | 3bdd011 | 2020-08-27 10:24:34 -0500 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | return priority; |
Matt Spinler | 5a90a95 | 2020-08-27 09:39:03 -0500 | [diff] [blame] | 1425 | } |
| 1426 | |
Matt Spinler | b8cb60f | 2020-08-27 10:55:55 -0500 | [diff] [blame] | 1427 | std::vector<src::MRU::MRUCallout> |
| 1428 | SRC::getMRUsFromJSON(const nlohmann::json& mruJSON) |
| 1429 | { |
| 1430 | std::vector<src::MRU::MRUCallout> mrus; |
| 1431 | |
| 1432 | // Looks like: |
| 1433 | // [ |
| 1434 | // { |
| 1435 | // "ID": 100, |
| 1436 | // "Priority": "H" |
| 1437 | // } |
| 1438 | // ] |
| 1439 | if (!mruJSON.is_array()) |
| 1440 | { |
| 1441 | addDebugData("MRU callout JSON is not an array"); |
| 1442 | return mrus; |
| 1443 | } |
| 1444 | |
| 1445 | for (const auto& mruCallout : mruJSON) |
| 1446 | { |
| 1447 | try |
| 1448 | { |
| 1449 | auto priority = getPriorityFromJSON(mruCallout); |
| 1450 | auto id = mruCallout.at("ID").get<uint32_t>(); |
| 1451 | |
| 1452 | src::MRU::MRUCallout mru{static_cast<uint32_t>(priority), id}; |
| 1453 | mrus.push_back(std::move(mru)); |
| 1454 | } |
| 1455 | catch (const std::exception& e) |
| 1456 | { |
Jayanth Othayoth | 1aa90d4 | 2023-09-13 04:25:45 -0500 | [diff] [blame] | 1457 | addDebugData(std::format("Invalid MRU entry in JSON: {}: {}", |
Matt Spinler | b8cb60f | 2020-08-27 10:55:55 -0500 | [diff] [blame] | 1458 | mruCallout.dump(), e.what())); |
| 1459 | } |
| 1460 | } |
| 1461 | |
| 1462 | return mrus; |
| 1463 | } |
| 1464 | |
Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 1465 | std::vector<uint8_t> SRC::getSrcStruct() |
| 1466 | { |
| 1467 | std::vector<uint8_t> data; |
| 1468 | Stream stream{data}; |
| 1469 | |
| 1470 | //------ Ref section 4.3 in PEL doc--- |
| 1471 | //------ SRC Structure 40 bytes------- |
| 1472 | // Byte-0 | Byte-1 | Byte-2 | Byte-3 | |
| 1473 | // ----------------------------------- |
| 1474 | // 02 | 08 | 00 | 09 | ==> Header |
| 1475 | // 00 | 00 | 00 | 48 | ==> Header |
| 1476 | // 00 | 00 | 00 | 00 | ==> Hex data word-2 |
| 1477 | // 00 | 00 | 00 | 00 | ==> Hex data word-3 |
| 1478 | // 00 | 00 | 00 | 00 | ==> Hex data word-4 |
| 1479 | // 20 | 00 | 00 | 00 | ==> Hex data word-5 |
| 1480 | // 00 | 00 | 00 | 00 | ==> Hex data word-6 |
| 1481 | // 00 | 00 | 00 | 00 | ==> Hex data word-7 |
| 1482 | // 00 | 00 | 00 | 00 | ==> Hex data word-8 |
| 1483 | // 00 | 00 | 00 | 00 | ==> Hex data word-9 |
| 1484 | // ----------------------------------- |
| 1485 | // ASCII string - 8 bytes | |
| 1486 | // ----------------------------------- |
| 1487 | // ASCII space NULL - 24 bytes | |
| 1488 | // ----------------------------------- |
| 1489 | //_size = Base SRC struct: 8 byte header + hex data section + ASCII string |
| 1490 | |
| 1491 | uint8_t flags = (_flags | postOPPanel); |
| 1492 | |
| 1493 | stream << _version << flags << _reserved1B << _wordCount << _reserved2B |
| 1494 | << _size; |
| 1495 | |
| 1496 | for (auto& word : _hexData) |
| 1497 | { |
| 1498 | stream << word; |
| 1499 | } |
| 1500 | |
| 1501 | _asciiString->flatten(stream); |
| 1502 | |
| 1503 | return data; |
| 1504 | } |
| 1505 | |
Vijay Lobo | 875b6c7 | 2021-10-20 17:38:56 -0500 | [diff] [blame] | 1506 | void SRC::setProgressCode(const DataInterfaceBase& dataIface) |
| 1507 | { |
| 1508 | std::vector<uint8_t> progressSRC; |
| 1509 | |
| 1510 | try |
| 1511 | { |
| 1512 | progressSRC = dataIface.getRawProgressSRC(); |
| 1513 | } |
| 1514 | catch (const std::exception& e) |
| 1515 | { |
Matt Spinler | 0bacc8e | 2023-07-07 16:25:39 -0500 | [diff] [blame] | 1516 | lg2::error("Error getting progress code: {ERROR}", "ERROR", e); |
Vijay Lobo | 875b6c7 | 2021-10-20 17:38:56 -0500 | [diff] [blame] | 1517 | return; |
| 1518 | } |
| 1519 | |
| 1520 | _hexData[2] = getProgressCode(progressSRC); |
| 1521 | } |
| 1522 | |
| 1523 | uint32_t SRC::getProgressCode(std::vector<uint8_t>& rawProgressSRC) |
| 1524 | { |
| 1525 | uint32_t progressCode = 0; |
| 1526 | |
| 1527 | // A valid progress SRC is at least 72 bytes |
| 1528 | if (rawProgressSRC.size() < 72) |
| 1529 | { |
| 1530 | return progressCode; |
| 1531 | } |
| 1532 | |
| 1533 | try |
| 1534 | { |
| 1535 | // The ASCII string field in progress SRCs starts at offset 40. |
| 1536 | // Take the first 8 characters to put in the uint32: |
| 1537 | // "CC009189" -> 0xCC009189 |
| 1538 | Stream stream{rawProgressSRC, 40}; |
| 1539 | src::AsciiString aString{stream}; |
| 1540 | auto progressCodeString = aString.get().substr(0, 8); |
| 1541 | |
| 1542 | if (std::all_of(progressCodeString.begin(), progressCodeString.end(), |
| 1543 | [](char c) { |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 1544 | return std::isxdigit(static_cast<unsigned char>(c)); |
| 1545 | })) |
Vijay Lobo | 875b6c7 | 2021-10-20 17:38:56 -0500 | [diff] [blame] | 1546 | { |
| 1547 | progressCode = std::stoul(progressCodeString, nullptr, 16); |
| 1548 | } |
| 1549 | } |
| 1550 | catch (const std::exception& e) |
| 1551 | {} |
| 1552 | |
| 1553 | return progressCode; |
| 1554 | } |
| 1555 | |
Matt Spinler | f9bae18 | 2019-10-09 13:37:38 -0500 | [diff] [blame] | 1556 | } // namespace pels |
| 1557 | } // namespace openpower |