Matt Spinler | 711d51d | 2019-11-06 09:36:51 -0600 | [diff] [blame] | 1 | /** |
| 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 Spinler | 09d6400 | 2019-09-11 14:29:46 -0500 | [diff] [blame] | 16 | #include "failing_mtms.hpp" |
| 17 | |
| 18 | #include "pel_types.hpp" |
| 19 | |
| 20 | #include <phosphor-logging/log.hpp> |
| 21 | |
| 22 | namespace openpower |
| 23 | { |
| 24 | namespace pels |
| 25 | { |
| 26 | |
| 27 | using namespace phosphor::logging; |
| 28 | static constexpr uint8_t failingMTMSVersion = 0x01; |
| 29 | |
| 30 | FailingMTMS::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 Spinler | aa65947 | 2019-10-23 09:26:48 -0500 | [diff] [blame] | 38 | |
| 39 | _valid = true; |
Matt Spinler | 09d6400 | 2019-09-11 14:29:46 -0500 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | FailingMTMS::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 | |
| 57 | void 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 Spinler | 0688545 | 2019-11-06 10:35:42 -0600 | [diff] [blame] | 78 | void FailingMTMS::flatten(Stream& stream) const |
Matt Spinler | 09d6400 | 2019-09-11 14:29:46 -0500 | [diff] [blame] | 79 | { |
| 80 | stream << _header << _mtms; |
| 81 | } |
| 82 | |
| 83 | void FailingMTMS::unflatten(Stream& stream) |
| 84 | { |
| 85 | stream >> _header >> _mtms; |
| 86 | } |
| 87 | |
| 88 | } // namespace pels |
| 89 | } // namespace openpower |