blob: 6dfbc09e8571c4a1719d026503c73048efbb4cab [file] [log] [blame]
Matt Spinler03c1d912019-07-10 14:12:15 -05001#include "user_header.hpp"
2
Matt Spinler1a94cc32019-09-11 13:32:12 -05003#include "pel_types.hpp"
Matt Spinlerfdb6a202019-09-20 14:09:20 -05004#include "severity.hpp"
Matt Spinler1a94cc32019-09-11 13:32:12 -05005
Matt Spinler03c1d912019-07-10 14:12:15 -05006#include <phosphor-logging/log.hpp>
7
8namespace openpower
9{
10namespace pels
11{
12
13using namespace phosphor::logging;
14
Matt Spinlercf5a8d02019-09-05 12:58:53 -050015void UserHeader::unflatten(Stream& stream)
Matt Spinler03c1d912019-07-10 14:12:15 -050016{
Matt Spinlercf5a8d02019-09-05 12:58:53 -050017 stream >> _header >> _eventSubsystem >> _eventScope >> _eventSeverity >>
18 _eventType >> _reserved4Byte1 >> _problemDomain >> _problemVector >>
19 _actionFlags >> _reserved4Byte2;
Matt Spinler03c1d912019-07-10 14:12:15 -050020}
21
Matt Spinlercf5a8d02019-09-05 12:58:53 -050022void UserHeader::flatten(Stream& stream)
Matt Spinler03c1d912019-07-10 14:12:15 -050023{
Matt Spinlercf5a8d02019-09-05 12:58:53 -050024 stream << _header << _eventSubsystem << _eventScope << _eventSeverity
25 << _eventType << _reserved4Byte1 << _problemDomain << _problemVector
26 << _actionFlags << _reserved4Byte2;
Matt Spinler03c1d912019-07-10 14:12:15 -050027}
28
Matt Spinlerfdb6a202019-09-20 14:09:20 -050029UserHeader::UserHeader(const message::Entry& entry,
30 phosphor::logging::Entry::Level severity)
31{
32 _header.id = static_cast<uint16_t>(SectionID::userHeader);
33 _header.size = UserHeader::flattenedSize();
34 _header.version = userHeaderVersion;
35 _header.subType = 0;
36 _header.componentID = static_cast<uint16_t>(ComponentID::phosphorLogging);
37
38 _eventSubsystem = entry.subsystem;
39
40 _eventScope = entry.eventScope.value_or(
41 static_cast<uint8_t>(EventScope::entirePlatform));
42
43 // Get the severity from the registry if it's there, otherwise get it
44 // from the OpenBMC event log severity value.
45 _eventSeverity =
46 entry.severity.value_or(convertOBMCSeverityToPEL(severity));
47
48 // TODO: ibm-dev/dev/#1144 Handle manufacturing sev & action flags
49
50 _eventType = entry.eventType.value_or(
51 static_cast<uint8_t>(EventType::notApplicable));
52
53 _reserved4Byte1 = 0;
54
55 // No uses for problem domain or vector
56 _problemDomain = 0;
57 _problemVector = 0;
58
59 _actionFlags = entry.actionFlags;
60
61 _reserved4Byte2 = 0;
62
63 _valid = true;
64}
65
Matt Spinler03c1d912019-07-10 14:12:15 -050066UserHeader::UserHeader(Stream& pel)
67{
68 try
69 {
Matt Spinlercf5a8d02019-09-05 12:58:53 -050070 unflatten(pel);
Matt Spinler03c1d912019-07-10 14:12:15 -050071 validate();
72 }
73 catch (const std::exception& e)
74 {
75 log<level::ERR>("Cannot unflatten user header",
76 entry("ERROR=%s", e.what()));
77 _valid = false;
78 }
79}
80
81void UserHeader::validate()
82{
83 bool failed = false;
Matt Spinler1a94cc32019-09-11 13:32:12 -050084 if (header().id != static_cast<uint16_t>(SectionID::userHeader))
Matt Spinler03c1d912019-07-10 14:12:15 -050085 {
86 log<level::ERR>("Invalid user header section ID",
87 entry("ID=0x%X", header().id));
88 failed = true;
Matt Spinler03c1d912019-07-10 14:12:15 -050089 }
90
91 if (header().version != userHeaderVersion)
92 {
93 log<level::ERR>("Invalid user header version",
94 entry("VERSION=0x%X", header().version));
95 failed = true;
Matt Spinler03c1d912019-07-10 14:12:15 -050096 }
97
98 _valid = (failed) ? false : true;
99}
100
101} // namespace pels
102} // namespace openpower