blob: 16d621252f3826c15b2ba0c9a9e4a8471de013b9 [file] [log] [blame]
Matt Spinler03c1d912019-07-10 14:12:15 -05001#include "user_header.hpp"
2
3#include <phosphor-logging/log.hpp>
4
5namespace openpower
6{
7namespace pels
8{
9
10using namespace phosphor::logging;
11
12Stream& operator>>(Stream& s, UserHeader& uh)
13{
14 s >> uh._header >> uh._eventSubsystem >> uh._eventScope >>
15 uh._eventSeverity >> uh._eventType >> uh._reserved4Byte1 >>
16 uh._problemDomain >> uh._problemVector >> uh._actionFlags >>
17 uh._reserved4Byte2;
18 return s;
19}
20
21Stream& operator<<(Stream& s, UserHeader& uh)
22{
23 s << uh._header << uh._eventSubsystem << uh._eventScope << uh._eventSeverity
24 << uh._eventType << uh._reserved4Byte1 << uh._problemDomain
25 << uh._problemVector << uh._actionFlags << uh._reserved4Byte2;
26 return s;
27}
28
29UserHeader::UserHeader(Stream& pel)
30{
31 try
32 {
33 pel >> *this;
34 validate();
35 }
36 catch (const std::exception& e)
37 {
38 log<level::ERR>("Cannot unflatten user header",
39 entry("ERROR=%s", e.what()));
40 _valid = false;
41 }
42}
43
44void UserHeader::validate()
45{
46 bool failed = false;
47 if (header().id != userHeaderSectionID)
48 {
49 log<level::ERR>("Invalid user header section ID",
50 entry("ID=0x%X", header().id));
51 failed = true;
52 return;
53 }
54
55 if (header().version != userHeaderVersion)
56 {
57 log<level::ERR>("Invalid user header version",
58 entry("VERSION=0x%X", header().version));
59 failed = true;
60 return;
61 }
62
63 _valid = (failed) ? false : true;
64}
65
66} // namespace pels
67} // namespace openpower