Matt Spinler | 09d6400 | 2019-09-11 14:29:46 -0500 | [diff] [blame] | 1 | #include "failing_mtms.hpp" |
| 2 | |
| 3 | #include "pel_types.hpp" |
| 4 | |
| 5 | #include <phosphor-logging/log.hpp> |
| 6 | |
| 7 | namespace openpower |
| 8 | { |
| 9 | namespace pels |
| 10 | { |
| 11 | |
| 12 | using namespace phosphor::logging; |
| 13 | static constexpr uint8_t failingMTMSVersion = 0x01; |
| 14 | |
| 15 | FailingMTMS::FailingMTMS(const DataInterfaceBase& dataIface) : |
| 16 | _mtms(dataIface.getMachineTypeModel(), dataIface.getMachineSerialNumber()) |
| 17 | { |
| 18 | _header.id = static_cast<uint16_t>(SectionID::failingMTMS); |
| 19 | _header.size = FailingMTMS::flattenedSize(); |
| 20 | _header.version = failingMTMSVersion; |
| 21 | _header.subType = 0; |
| 22 | _header.componentID = static_cast<uint16_t>(ComponentID::phosphorLogging); |
| 23 | } |
| 24 | |
| 25 | FailingMTMS::FailingMTMS(Stream& pel) |
| 26 | { |
| 27 | try |
| 28 | { |
| 29 | unflatten(pel); |
| 30 | validate(); |
| 31 | } |
| 32 | catch (std::exception& e) |
| 33 | { |
| 34 | log<level::ERR>("Cannot unflatten failing MTM section", |
| 35 | entry("ERROR=%s", e.what())); |
| 36 | _valid = false; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | void FailingMTMS::validate() |
| 41 | { |
| 42 | bool failed = false; |
| 43 | |
| 44 | if (header().id != static_cast<uint16_t>(SectionID::failingMTMS)) |
| 45 | { |
| 46 | log<level::ERR>("Invalid failing MTMS section ID", |
| 47 | entry("ID=0x%X", header().id)); |
| 48 | failed = true; |
| 49 | } |
| 50 | |
| 51 | if (header().version != failingMTMSVersion) |
| 52 | { |
| 53 | log<level::ERR>("Invalid failing MTMS version", |
| 54 | entry("VERSION=0x%X", header().version)); |
| 55 | failed = true; |
| 56 | } |
| 57 | |
| 58 | _valid = (failed) ? false : true; |
| 59 | } |
| 60 | |
| 61 | std::string FailingMTMS::getMachineTypeModel() |
| 62 | { |
| 63 | std::string mtmString; |
| 64 | const auto& mtm = _mtms.machineTypeAndModel(); |
| 65 | |
| 66 | for (size_t i = 0; (i < MTMS::mtmSize) && (mtm[i] != 0); i++) |
| 67 | { |
| 68 | mtmString.push_back(mtm[i]); |
| 69 | } |
| 70 | return mtmString; |
| 71 | } |
| 72 | |
| 73 | std::string FailingMTMS::getMachineSerialNumber() |
| 74 | { |
| 75 | std::string snString; |
| 76 | const auto& sn = _mtms.machineSerialNumber(); |
| 77 | |
| 78 | // Get everything up to the 0s. |
| 79 | for (size_t i = 0; (i < MTMS::snSize) && (sn[i] != 0); i++) |
| 80 | { |
| 81 | snString.push_back(sn[i]); |
| 82 | } |
| 83 | return snString; |
| 84 | } |
| 85 | |
| 86 | void FailingMTMS::flatten(Stream& stream) |
| 87 | { |
| 88 | stream << _header << _mtms; |
| 89 | } |
| 90 | |
| 91 | void FailingMTMS::unflatten(Stream& stream) |
| 92 | { |
| 93 | stream >> _header >> _mtms; |
| 94 | } |
| 95 | |
| 96 | } // namespace pels |
| 97 | } // namespace openpower |