blob: fc62df10015dcf31499ad4e8e1f17665bbc5d2a0 [file] [log] [blame]
Matt Spinlerd3335df2019-07-10 11:04:21 -05001#include "private_header.hpp"
2
Matt Spinler1a94cc32019-09-11 13:32:12 -05003#include "pel_types.hpp"
4
Matt Spinlerd3335df2019-07-10 11:04:21 -05005#include <phosphor-logging/log.hpp>
6
7namespace openpower
8{
9namespace pels
10{
11
12using namespace phosphor::logging;
13
14PrivateHeader::PrivateHeader(Stream& pel)
15{
16 try
17 {
Matt Spinlercf5a8d02019-09-05 12:58:53 -050018 unflatten(pel);
Matt Spinlerd3335df2019-07-10 11:04:21 -050019 validate();
20 }
21 catch (const std::exception& e)
22 {
23 log<level::ERR>("Cannot unflatten private header",
24 entry("ERROR=%s", e.what()));
25 _valid = false;
26 }
27}
28
29void PrivateHeader::validate()
30{
31 bool failed = false;
32
Matt Spinler1a94cc32019-09-11 13:32:12 -050033 if (header().id != static_cast<uint16_t>(SectionID::privateHeader))
Matt Spinlerd3335df2019-07-10 11:04:21 -050034 {
35 log<level::ERR>("Invalid private header section ID",
36 entry("ID=0x%X", header().id));
37 failed = true;
38 }
39
40 if (header().version != privateHeaderVersion)
41 {
42 log<level::ERR>("Invalid private header version",
43 entry("VERSION=0x%X", header().version));
44 failed = true;
45 }
46
47 if (_sectionCount < minSectionCount)
48 {
49 log<level::ERR>("Invalid section count in private header",
50 entry("SECTION_COUNT=0x%X", _sectionCount));
51 failed = true;
52 }
53
54 _valid = (failed) ? false : true;
55}
56
Matt Spinlercf5a8d02019-09-05 12:58:53 -050057void PrivateHeader::unflatten(Stream& stream)
Matt Spinlerd3335df2019-07-10 11:04:21 -050058{
Matt Spinlercf5a8d02019-09-05 12:58:53 -050059 stream >> _header >> _createTimestamp >> _commitTimestamp >> _creatorID >>
60 _logType >> _reservedByte >> _sectionCount >> _obmcLogID >>
61 _creatorVersion >> _plid >> _id;
Matt Spinlerd3335df2019-07-10 11:04:21 -050062}
63
Matt Spinlercf5a8d02019-09-05 12:58:53 -050064void PrivateHeader::flatten(Stream& stream)
Matt Spinlerd3335df2019-07-10 11:04:21 -050065{
Matt Spinlercf5a8d02019-09-05 12:58:53 -050066 stream << _header << _createTimestamp << _commitTimestamp << _creatorID
67 << _logType << _reservedByte << _sectionCount << _obmcLogID
68 << _creatorVersion << _plid << _id;
Matt Spinlerd3335df2019-07-10 11:04:21 -050069}
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