blob: b60ce31e1e952e785dc82fb2ff2259011b1bde73 [file] [log] [blame]
Matt Spinler09d64002019-09-11 14:29:46 -05001#include "failing_mtms.hpp"
2
3#include "pel_types.hpp"
4
5#include <phosphor-logging/log.hpp>
6
7namespace openpower
8{
9namespace pels
10{
11
12using namespace phosphor::logging;
13static constexpr uint8_t failingMTMSVersion = 0x01;
14
15FailingMTMS::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);
Matt Spinleraa659472019-10-23 09:26:48 -050023
24 _valid = true;
Matt Spinler09d64002019-09-11 14:29:46 -050025}
26
27FailingMTMS::FailingMTMS(Stream& pel)
28{
29 try
30 {
31 unflatten(pel);
32 validate();
33 }
34 catch (std::exception& e)
35 {
36 log<level::ERR>("Cannot unflatten failing MTM section",
37 entry("ERROR=%s", e.what()));
38 _valid = false;
39 }
40}
41
42void FailingMTMS::validate()
43{
44 bool failed = false;
45
46 if (header().id != static_cast<uint16_t>(SectionID::failingMTMS))
47 {
48 log<level::ERR>("Invalid failing MTMS section ID",
49 entry("ID=0x%X", header().id));
50 failed = true;
51 }
52
53 if (header().version != failingMTMSVersion)
54 {
55 log<level::ERR>("Invalid failing MTMS version",
56 entry("VERSION=0x%X", header().version));
57 failed = true;
58 }
59
60 _valid = (failed) ? false : true;
61}
62
Matt Spinler09d64002019-09-11 14:29:46 -050063void FailingMTMS::flatten(Stream& stream)
64{
65 stream << _header << _mtms;
66}
67
68void FailingMTMS::unflatten(Stream& stream)
69{
70 stream >> _header >> _mtms;
71}
72
73} // namespace pels
74} // namespace openpower