blob: 73b4200f7b22c50d939008741db49a9ff18dffb1 [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 Spinlera906c942019-10-08 13:42:05 -050016#include "fru_identity.hpp"
17
18namespace openpower
19{
20namespace pels
21{
22namespace src
23{
24
25FRUIdentity::FRUIdentity(Stream& pel)
26{
27 pel >> _type >> _size >> _flags;
28
29 if (_flags & (pnSupplied | maintProcSupplied))
30 {
31 pel.read(_pnOrProcedureID.data(), _pnOrProcedureID.size());
32 }
33
34 if (_flags & ccinSupplied)
35 {
36 pel.read(_ccin.data(), _ccin.size());
37 }
38
39 if (_flags & snSupplied)
40 {
41 pel.read(_sn.data(), _sn.size());
42 }
43}
44
Matt Spinlera09354b2020-03-13 10:24:52 -050045size_t FRUIdentity::flattenedSize() const
46{
47 size_t size = sizeof(_type) + sizeof(_size) + sizeof(_flags);
48
49 if (hasPN() || hasMP())
50 {
51 size += _pnOrProcedureID.size();
52 }
53
54 if (hasCCIN())
55 {
56 size += _ccin.size();
57 }
58
59 if (hasSN())
60 {
61 size += _sn.size();
62 }
63
64 return size;
65}
66
Matt Spinlera906c942019-10-08 13:42:05 -050067std::optional<std::string> FRUIdentity::getPN() const
68{
69 if (hasPN())
70 {
71 // NULL terminated
72 std::string pn{_pnOrProcedureID.data()};
73 return pn;
74 }
75
76 return std::nullopt;
77}
78
79std::optional<std::string> FRUIdentity::getMaintProc() const
80{
81 if (hasMP())
82 {
83 // NULL terminated
84 std::string mp{_pnOrProcedureID.data()};
85 return mp;
86 }
87
88 return std::nullopt;
89}
90
91std::optional<std::string> FRUIdentity::getCCIN() const
92{
93 if (hasCCIN())
94 {
95 std::string ccin{_ccin.begin(), _ccin.begin() + _ccin.size()};
96 return ccin;
97 }
98
99 return std::nullopt;
100}
101
102std::optional<std::string> FRUIdentity::getSN() const
103{
104 if (hasSN())
105 {
106 std::string sn{_sn.begin(), _sn.begin() + _sn.size()};
107 return sn;
108 }
109
110 return std::nullopt;
111}
112
Matt Spinler724d0d82019-11-06 10:05:36 -0600113void FRUIdentity::flatten(Stream& pel) const
Matt Spinlera906c942019-10-08 13:42:05 -0500114{
115 pel << _type << _size << _flags;
116
117 if (hasPN() || hasMP())
118 {
119 pel.write(_pnOrProcedureID.data(), _pnOrProcedureID.size());
120 }
121
122 if (hasCCIN())
123 {
124 pel.write(_ccin.data(), _ccin.size());
125 }
126
127 if (hasSN())
128 {
129 pel.write(_sn.data(), _sn.size());
130 }
131}
132
133} // namespace src
134} // namespace pels
135} // namespace openpower