blob: d4cdf37431f4ea4f54a5bb5fa97c5fada34b688a [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 Spinler09d64002019-09-11 14:29:46 -050016#include "failing_mtms.hpp"
17
18#include "pel_types.hpp"
19
20#include <phosphor-logging/log.hpp>
21
22namespace openpower
23{
24namespace pels
25{
26
27using namespace phosphor::logging;
28static constexpr uint8_t failingMTMSVersion = 0x01;
29
30FailingMTMS::FailingMTMS(const DataInterfaceBase& dataIface) :
31 _mtms(dataIface.getMachineTypeModel(), dataIface.getMachineSerialNumber())
32{
33 _header.id = static_cast<uint16_t>(SectionID::failingMTMS);
34 _header.size = FailingMTMS::flattenedSize();
35 _header.version = failingMTMSVersion;
36 _header.subType = 0;
37 _header.componentID = static_cast<uint16_t>(ComponentID::phosphorLogging);
Matt Spinleraa659472019-10-23 09:26:48 -050038
39 _valid = true;
Matt Spinler09d64002019-09-11 14:29:46 -050040}
41
42FailingMTMS::FailingMTMS(Stream& pel)
43{
44 try
45 {
46 unflatten(pel);
47 validate();
48 }
49 catch (std::exception& e)
50 {
51 log<level::ERR>("Cannot unflatten failing MTM section",
52 entry("ERROR=%s", e.what()));
53 _valid = false;
54 }
55}
56
57void FailingMTMS::validate()
58{
59 bool failed = false;
60
61 if (header().id != static_cast<uint16_t>(SectionID::failingMTMS))
62 {
63 log<level::ERR>("Invalid failing MTMS section ID",
64 entry("ID=0x%X", header().id));
65 failed = true;
66 }
67
68 if (header().version != failingMTMSVersion)
69 {
70 log<level::ERR>("Invalid failing MTMS version",
71 entry("VERSION=0x%X", header().version));
72 failed = true;
73 }
74
75 _valid = (failed) ? false : true;
76}
77
Matt Spinler06885452019-11-06 10:35:42 -060078void FailingMTMS::flatten(Stream& stream) const
Matt Spinler09d64002019-09-11 14:29:46 -050079{
80 stream << _header << _mtms;
81}
82
83void FailingMTMS::unflatten(Stream& stream)
84{
85 stream >> _header >> _mtms;
86}
87
88} // namespace pels
89} // namespace openpower