blob: b45c05dfcd60235dc4538e714084af8706ddfb8e [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
Harisuddin Mohamed Isae2d1bf32020-02-06 17:32:38 +080018#include "json_utils.hpp"
Matt Spinler09d64002019-09-11 14:29:46 -050019#include "pel_types.hpp"
20
21#include <phosphor-logging/log.hpp>
22
23namespace openpower
24{
25namespace pels
26{
27
28using namespace phosphor::logging;
29static constexpr uint8_t failingMTMSVersion = 0x01;
30
31FailingMTMS::FailingMTMS(const DataInterfaceBase& dataIface) :
32 _mtms(dataIface.getMachineTypeModel(), dataIface.getMachineSerialNumber())
33{
34 _header.id = static_cast<uint16_t>(SectionID::failingMTMS);
35 _header.size = FailingMTMS::flattenedSize();
36 _header.version = failingMTMSVersion;
37 _header.subType = 0;
38 _header.componentID = static_cast<uint16_t>(ComponentID::phosphorLogging);
Matt Spinleraa659472019-10-23 09:26:48 -050039
40 _valid = true;
Matt Spinler09d64002019-09-11 14:29:46 -050041}
42
43FailingMTMS::FailingMTMS(Stream& pel)
44{
45 try
46 {
47 unflatten(pel);
48 validate();
49 }
50 catch (std::exception& e)
51 {
52 log<level::ERR>("Cannot unflatten failing MTM section",
53 entry("ERROR=%s", e.what()));
54 _valid = false;
55 }
56}
57
58void FailingMTMS::validate()
59{
60 bool failed = false;
61
62 if (header().id != static_cast<uint16_t>(SectionID::failingMTMS))
63 {
64 log<level::ERR>("Invalid failing MTMS section ID",
65 entry("ID=0x%X", header().id));
66 failed = true;
67 }
68
69 if (header().version != failingMTMSVersion)
70 {
71 log<level::ERR>("Invalid failing MTMS version",
72 entry("VERSION=0x%X", header().version));
73 failed = true;
74 }
75
76 _valid = (failed) ? false : true;
77}
78
Matt Spinler06885452019-11-06 10:35:42 -060079void FailingMTMS::flatten(Stream& stream) const
Matt Spinler09d64002019-09-11 14:29:46 -050080{
81 stream << _header << _mtms;
82}
83
84void FailingMTMS::unflatten(Stream& stream)
85{
86 stream >> _header >> _mtms;
87}
88
Harisuddin Mohamed Isae2d1bf32020-02-06 17:32:38 +080089std::optional<std::string> FailingMTMS::getJSON() const
90{
91 std::string json;
92 jsonInsert(json, "Section Version", getNumberString("%d", _header.version),
93 1);
94 jsonInsert(json, "Sub-section type", getNumberString("%d", _header.subType),
95 1);
96 jsonInsert(json, "Created by", getNumberString("0x%X", _header.componentID),
97 1);
98 jsonInsert(json, "Machine Type Model", _mtms.machineTypeAndModel(), 1);
99 jsonInsert(json, "Serial Number", trimEnd(_mtms.machineSerialNumber()), 1);
100 json.erase(json.size() - 2);
101 return json;
102}
Matt Spinler09d64002019-09-11 14:29:46 -0500103} // namespace pels
104} // namespace openpower