Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 1 | #include "private_header.hpp" |
| 2 | |
Matt Spinler | 289aa47 | 2019-09-20 12:33:29 -0500 | [diff] [blame] | 3 | #include "log_id.hpp" |
Matt Spinler | 1a94cc3 | 2019-09-11 13:32:12 -0500 | [diff] [blame] | 4 | #include "pel_types.hpp" |
| 5 | |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 6 | #include <phosphor-logging/log.hpp> |
| 7 | |
| 8 | namespace openpower |
| 9 | { |
| 10 | namespace pels |
| 11 | { |
| 12 | |
| 13 | using namespace phosphor::logging; |
| 14 | |
Matt Spinler | 289aa47 | 2019-09-20 12:33:29 -0500 | [diff] [blame] | 15 | PrivateHeader::PrivateHeader(uint16_t componentID, uint32_t obmcLogID, |
| 16 | uint64_t timestamp) |
| 17 | { |
| 18 | _header.id = static_cast<uint16_t>(SectionID::privateHeader); |
| 19 | _header.size = PrivateHeader::flattenedSize(); |
| 20 | _header.version = privateHeaderVersion; |
| 21 | _header.subType = 0; |
| 22 | _header.componentID = componentID; |
| 23 | |
| 24 | _createTimestamp = getBCDTime(timestamp); |
| 25 | |
| 26 | auto now = std::chrono::system_clock::now(); |
| 27 | _commitTimestamp = getBCDTime(now); |
| 28 | |
| 29 | _creatorID = static_cast<uint8_t>(CreatorID::openBMC); |
| 30 | |
| 31 | // Add support for reminder and telemetry log types here if |
| 32 | // ever necessary. |
| 33 | _logType = 0; |
| 34 | |
| 35 | _reservedByte = 0; |
| 36 | |
| 37 | // the final section count will be updated later |
| 38 | _sectionCount = 1; |
| 39 | |
| 40 | _obmcLogID = obmcLogID; |
| 41 | |
| 42 | _id = generatePELID(); |
| 43 | |
| 44 | _plid = _id; |
| 45 | |
| 46 | // Leave _creatorVersion at 0 |
| 47 | |
| 48 | _valid = true; |
| 49 | } |
| 50 | |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 51 | PrivateHeader::PrivateHeader(Stream& pel) |
| 52 | { |
| 53 | try |
| 54 | { |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 55 | unflatten(pel); |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 56 | validate(); |
| 57 | } |
| 58 | catch (const std::exception& e) |
| 59 | { |
| 60 | log<level::ERR>("Cannot unflatten private header", |
| 61 | entry("ERROR=%s", e.what())); |
| 62 | _valid = false; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | void PrivateHeader::validate() |
| 67 | { |
| 68 | bool failed = false; |
| 69 | |
Matt Spinler | 1a94cc3 | 2019-09-11 13:32:12 -0500 | [diff] [blame] | 70 | if (header().id != static_cast<uint16_t>(SectionID::privateHeader)) |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 71 | { |
| 72 | log<level::ERR>("Invalid private header section ID", |
| 73 | entry("ID=0x%X", header().id)); |
| 74 | failed = true; |
| 75 | } |
| 76 | |
| 77 | if (header().version != privateHeaderVersion) |
| 78 | { |
| 79 | log<level::ERR>("Invalid private header version", |
| 80 | entry("VERSION=0x%X", header().version)); |
| 81 | failed = true; |
| 82 | } |
| 83 | |
| 84 | if (_sectionCount < minSectionCount) |
| 85 | { |
| 86 | log<level::ERR>("Invalid section count in private header", |
| 87 | entry("SECTION_COUNT=0x%X", _sectionCount)); |
| 88 | failed = true; |
| 89 | } |
| 90 | |
| 91 | _valid = (failed) ? false : true; |
| 92 | } |
| 93 | |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 94 | void PrivateHeader::unflatten(Stream& stream) |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 95 | { |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 96 | stream >> _header >> _createTimestamp >> _commitTimestamp >> _creatorID >> |
| 97 | _logType >> _reservedByte >> _sectionCount >> _obmcLogID >> |
| 98 | _creatorVersion >> _plid >> _id; |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 99 | } |
| 100 | |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 101 | void PrivateHeader::flatten(Stream& stream) |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 102 | { |
Matt Spinler | cf5a8d0 | 2019-09-05 12:58:53 -0500 | [diff] [blame] | 103 | stream << _header << _createTimestamp << _commitTimestamp << _creatorID |
| 104 | << _logType << _reservedByte << _sectionCount << _obmcLogID |
| 105 | << _creatorVersion << _plid << _id; |
Matt Spinler | d3335df | 2019-07-10 11:04:21 -0500 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | Stream& operator>>(Stream& s, CreatorVersion& cv) |
| 109 | { |
| 110 | for (size_t i = 0; i < sizeof(CreatorVersion); i++) |
| 111 | { |
| 112 | s >> cv.version[i]; |
| 113 | } |
| 114 | return s; |
| 115 | } |
| 116 | |
| 117 | Stream& operator<<(Stream& s, CreatorVersion& cv) |
| 118 | { |
| 119 | for (size_t i = 0; i < sizeof(CreatorVersion); i++) |
| 120 | { |
| 121 | s << cv.version[i]; |
| 122 | } |
| 123 | return s; |
| 124 | } |
| 125 | |
| 126 | } // namespace pels |
| 127 | } // namespace openpower |