blob: 7611a751e845e6b180243320e98c1b6e404ad746 [file] [log] [blame]
Matt Spinlerd3335df2019-07-10 11:04:21 -05001#include "private_header.hpp"
2
3#include <phosphor-logging/log.hpp>
4
5namespace openpower
6{
7namespace pels
8{
9
10using namespace phosphor::logging;
11
12PrivateHeader::PrivateHeader(Stream& pel)
13{
14 try
15 {
16 pel >> *this;
17 validate();
18 }
19 catch (const std::exception& e)
20 {
21 log<level::ERR>("Cannot unflatten private header",
22 entry("ERROR=%s", e.what()));
23 _valid = false;
24 }
25}
26
27void PrivateHeader::validate()
28{
29 bool failed = false;
30
31 if (header().id != privateHeaderSectionID)
32 {
33 log<level::ERR>("Invalid private header section ID",
34 entry("ID=0x%X", header().id));
35 failed = true;
36 }
37
38 if (header().version != privateHeaderVersion)
39 {
40 log<level::ERR>("Invalid private header version",
41 entry("VERSION=0x%X", header().version));
42 failed = true;
43 }
44
45 if (_sectionCount < minSectionCount)
46 {
47 log<level::ERR>("Invalid section count in private header",
48 entry("SECTION_COUNT=0x%X", _sectionCount));
49 failed = true;
50 }
51
52 _valid = (failed) ? false : true;
53}
54
55Stream& operator>>(Stream& s, PrivateHeader& ph)
56{
57 s >> ph._header >> ph._createTimestamp >> ph._commitTimestamp >>
58 ph._creatorID >> ph._logType >> ph._reservedByte >> ph._sectionCount >>
59 ph._obmcLogID >> ph._creatorVersion >> ph._plid >> ph._id;
60 return s;
61}
62
63Stream& operator<<(Stream& s, PrivateHeader& ph)
64{
65 s << ph._header << ph._createTimestamp << ph._commitTimestamp
66 << ph._creatorID << ph._logType << ph._reservedByte << ph._sectionCount
67 << ph._obmcLogID << ph._creatorVersion << ph._plid << ph._id;
68 return s;
69}
70
71Stream& operator>>(Stream& s, CreatorVersion& cv)
72{
73 for (size_t i = 0; i < sizeof(CreatorVersion); i++)
74 {
75 s >> cv.version[i];
76 }
77 return s;
78}
79
80Stream& operator<<(Stream& s, CreatorVersion& cv)
81{
82 for (size_t i = 0; i < sizeof(CreatorVersion); i++)
83 {
84 s << cv.version[i];
85 }
86 return s;
87}
88
89} // namespace pels
90} // namespace openpower