blob: 1b15c16e36fa1488c5cb7ac83fe5ffa035107c66 [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);
23}
24
25FailingMTMS::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
40void 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 Spinler09d64002019-09-11 14:29:46 -050061void FailingMTMS::flatten(Stream& stream)
62{
63 stream << _header << _mtms;
64}
65
66void FailingMTMS::unflatten(Stream& stream)
67{
68 stream >> _header >> _mtms;
69}
70
71} // namespace pels
72} // namespace openpower