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 | |
Matt Spinler | 09d6400 | 2019-09-11 14:29:46 -0500 | [diff] [blame] | 61 | void FailingMTMS::flatten(Stream& stream) |
| 62 | { |
| 63 | stream << _header << _mtms; |
| 64 | } |
| 65 | |
| 66 | void FailingMTMS::unflatten(Stream& stream) |
| 67 | { |
| 68 | stream >> _header >> _mtms; |
| 69 | } |
| 70 | |
| 71 | } // namespace pels |
| 72 | } // namespace openpower |