blob: 0014b57717a8c0c2d3c7ad02c4ea923afe89967f [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 Spinler06885452019-11-06 10:35:42 -060037void UserHeader::flatten(Stream& stream) const
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
Matt Spinlerf1e85e22019-11-01 11:31:31 -050065 if (entry.eventType)
66 {
67 _eventType = *entry.eventType;
68 }
69 else
70 {
71 // There are different default event types for info errors
72 // vs non info ones.
73 auto sevType = static_cast<SeverityType>(_eventSeverity & 0xF0);
74
75 _eventType = (sevType == SeverityType::nonError)
76 ? static_cast<uint8_t>(EventType::miscInformational)
77 : static_cast<uint8_t>(EventType::notApplicable);
78 }
Matt Spinlerfdb6a202019-09-20 14:09:20 -050079
80 _reserved4Byte1 = 0;
81
82 // No uses for problem domain or vector
83 _problemDomain = 0;
84 _problemVector = 0;
85
Matt Spinlerf1e85e22019-11-01 11:31:31 -050086 // These will be cleaned up later in pel_rules::check()
Matt Spinlere07f9152019-11-01 10:48:36 -050087 _actionFlags = entry.actionFlags.value_or(0);
Matt Spinlerfdb6a202019-09-20 14:09:20 -050088
89 _reserved4Byte2 = 0;
90
91 _valid = true;
92}
93
Matt Spinler03c1d912019-07-10 14:12:15 -050094UserHeader::UserHeader(Stream& pel)
95{
96 try
97 {
Matt Spinlercf5a8d02019-09-05 12:58:53 -050098 unflatten(pel);
Matt Spinler03c1d912019-07-10 14:12:15 -050099 validate();
100 }
101 catch (const std::exception& e)
102 {
103 log<level::ERR>("Cannot unflatten user header",
104 entry("ERROR=%s", e.what()));
105 _valid = false;
106 }
107}
108
109void UserHeader::validate()
110{
111 bool failed = false;
Matt Spinler1a94cc32019-09-11 13:32:12 -0500112 if (header().id != static_cast<uint16_t>(SectionID::userHeader))
Matt Spinler03c1d912019-07-10 14:12:15 -0500113 {
114 log<level::ERR>("Invalid user header section ID",
115 entry("ID=0x%X", header().id));
116 failed = true;
Matt Spinler03c1d912019-07-10 14:12:15 -0500117 }
118
119 if (header().version != userHeaderVersion)
120 {
121 log<level::ERR>("Invalid user header version",
122 entry("VERSION=0x%X", header().version));
123 failed = true;
Matt Spinler03c1d912019-07-10 14:12:15 -0500124 }
125
126 _valid = (failed) ? false : true;
127}
128
129} // namespace pels
130} // namespace openpower