summaryrefslogtreecommitdiffstats
path: root/extensions/openpower-pels/failing_mtms.cpp
blob: b45c05dfcd60235dc4538e714084af8706ddfb8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
 * Copyright © 2019 IBM Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "failing_mtms.hpp"

#include "json_utils.hpp"
#include "pel_types.hpp"

#include <phosphor-logging/log.hpp>

namespace openpower
{
namespace pels
{

using namespace phosphor::logging;
static constexpr uint8_t failingMTMSVersion = 0x01;

FailingMTMS::FailingMTMS(const DataInterfaceBase& dataIface) :
    _mtms(dataIface.getMachineTypeModel(), dataIface.getMachineSerialNumber())
{
    _header.id = static_cast<uint16_t>(SectionID::failingMTMS);
    _header.size = FailingMTMS::flattenedSize();
    _header.version = failingMTMSVersion;
    _header.subType = 0;
    _header.componentID = static_cast<uint16_t>(ComponentID::phosphorLogging);

    _valid = true;
}

FailingMTMS::FailingMTMS(Stream& pel)
{
    try
    {
        unflatten(pel);
        validate();
    }
    catch (std::exception& e)
    {
        log<level::ERR>("Cannot unflatten failing MTM section",
                        entry("ERROR=%s", e.what()));
        _valid = false;
    }
}

void FailingMTMS::validate()
{
    bool failed = false;

    if (header().id != static_cast<uint16_t>(SectionID::failingMTMS))
    {
        log<level::ERR>("Invalid failing MTMS section ID",
                        entry("ID=0x%X", header().id));
        failed = true;
    }

    if (header().version != failingMTMSVersion)
    {
        log<level::ERR>("Invalid failing MTMS version",
                        entry("VERSION=0x%X", header().version));
        failed = true;
    }

    _valid = (failed) ? false : true;
}

void FailingMTMS::flatten(Stream& stream) const
{
    stream << _header << _mtms;
}

void FailingMTMS::unflatten(Stream& stream)
{
    stream >> _header >> _mtms;
}

std::optional<std::string> FailingMTMS::getJSON() const
{
    std::string json;
    jsonInsert(json, "Section Version", getNumberString("%d", _header.version),
               1);
    jsonInsert(json, "Sub-section type", getNumberString("%d", _header.subType),
               1);
    jsonInsert(json, "Created by", getNumberString("0x%X", _header.componentID),
               1);
    jsonInsert(json, "Machine Type Model", _mtms.machineTypeAndModel(), 1);
    jsonInsert(json, "Serial Number", trimEnd(_mtms.machineSerialNumber()), 1);
    json.erase(json.size() - 2);
    return json;
}
} // namespace pels
} // namespace openpower
OpenPOWER on IntegriCloud