blob: 432ae6799eab2fce68a283e1f8badb1f52d5409d [file] [log] [blame]
Matt Spinler711d51d2019-11-06 09:36:51 -06001/**
2 * Copyright © 2019 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Matt Spinler03c1d912019-07-10 14:12:15 -050016#include "user_header.hpp"
17
Matt Spinler1a94cc32019-09-11 13:32:12 -050018#include "pel_types.hpp"
Matt Spinlerfdb6a202019-09-20 14:09:20 -050019#include "severity.hpp"
Matt Spinler1a94cc32019-09-11 13:32:12 -050020
Matt Spinler03c1d912019-07-10 14:12:15 -050021#include <phosphor-logging/log.hpp>
22
23namespace openpower
24{
25namespace pels
26{
27
28using namespace phosphor::logging;
29
Matt Spinlercf5a8d02019-09-05 12:58:53 -050030void UserHeader::unflatten(Stream& stream)
Matt Spinler03c1d912019-07-10 14:12:15 -050031{
Matt Spinlercf5a8d02019-09-05 12:58:53 -050032 stream >> _header >> _eventSubsystem >> _eventScope >> _eventSeverity >>
33 _eventType >> _reserved4Byte1 >> _problemDomain >> _problemVector >>
34 _actionFlags >> _reserved4Byte2;
Matt Spinler03c1d912019-07-10 14:12:15 -050035}
36
Matt Spinlercf5a8d02019-09-05 12:58:53 -050037void UserHeader::flatten(Stream& stream)
Matt Spinler03c1d912019-07-10 14:12:15 -050038{
Matt Spinlercf5a8d02019-09-05 12:58:53 -050039 stream << _header << _eventSubsystem << _eventScope << _eventSeverity
40 << _eventType << _reserved4Byte1 << _problemDomain << _problemVector
41 << _actionFlags << _reserved4Byte2;
Matt Spinler03c1d912019-07-10 14:12:15 -050042}
43
Matt Spinlerfdb6a202019-09-20 14:09:20 -050044UserHeader::UserHeader(const message::Entry& entry,
45 phosphor::logging::Entry::Level severity)
46{
47 _header.id = static_cast<uint16_t>(SectionID::userHeader);
48 _header.size = UserHeader::flattenedSize();
49 _header.version = userHeaderVersion;
50 _header.subType = 0;
51 _header.componentID = static_cast<uint16_t>(ComponentID::phosphorLogging);
52
53 _eventSubsystem = entry.subsystem;
54
55 _eventScope = entry.eventScope.value_or(
56 static_cast<uint8_t>(EventScope::entirePlatform));
57
58 // Get the severity from the registry if it's there, otherwise get it
59 // from the OpenBMC event log severity value.
60 _eventSeverity =
61 entry.severity.value_or(convertOBMCSeverityToPEL(severity));
62
63 // TODO: ibm-dev/dev/#1144 Handle manufacturing sev & action flags
64
65 _eventType = entry.eventType.value_or(
66 static_cast<uint8_t>(EventType::notApplicable));
67
68 _reserved4Byte1 = 0;
69
70 // No uses for problem domain or vector
71 _problemDomain = 0;
72 _problemVector = 0;
73
Matt Spinlere07f9152019-11-01 10:48:36 -050074 _actionFlags = entry.actionFlags.value_or(0);
Matt Spinlerfdb6a202019-09-20 14:09:20 -050075
76 _reserved4Byte2 = 0;
77
78 _valid = true;
79}
80
Matt Spinler03c1d912019-07-10 14:12:15 -050081UserHeader::UserHeader(Stream& pel)
82{
83 try
84 {
Matt Spinlercf5a8d02019-09-05 12:58:53 -050085 unflatten(pel);
Matt Spinler03c1d912019-07-10 14:12:15 -050086 validate();
87 }
88 catch (const std::exception& e)
89 {
90 log<level::ERR>("Cannot unflatten user header",
91 entry("ERROR=%s", e.what()));
92 _valid = false;
93 }
94}
95
96void UserHeader::validate()
97{
98 bool failed = false;
Matt Spinler1a94cc32019-09-11 13:32:12 -050099 if (header().id != static_cast<uint16_t>(SectionID::userHeader))
Matt Spinler03c1d912019-07-10 14:12:15 -0500100 {
101 log<level::ERR>("Invalid user header section ID",
102 entry("ID=0x%X", header().id));
103 failed = true;
Matt Spinler03c1d912019-07-10 14:12:15 -0500104 }
105
106 if (header().version != userHeaderVersion)
107 {
108 log<level::ERR>("Invalid user header version",
109 entry("VERSION=0x%X", header().version));
110 failed = true;
Matt Spinler03c1d912019-07-10 14:12:15 -0500111 }
112
113 _valid = (failed) ? false : true;
114}
115
116} // namespace pels
117} // namespace openpower