blob: 8c81e88cb1c8c2dcc1cacfd281c01a671168d6b6 [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
45std::optional<std::string> FRUIdentity::getPN() const
46{
47 if (hasPN())
48 {
49 // NULL terminated
50 std::string pn{_pnOrProcedureID.data()};
51 return pn;
52 }
53
54 return std::nullopt;
55}
56
57std::optional<std::string> FRUIdentity::getMaintProc() const
58{
59 if (hasMP())
60 {
61 // NULL terminated
62 std::string mp{_pnOrProcedureID.data()};
63 return mp;
64 }
65
66 return std::nullopt;
67}
68
69std::optional<std::string> FRUIdentity::getCCIN() const
70{
71 if (hasCCIN())
72 {
73 std::string ccin{_ccin.begin(), _ccin.begin() + _ccin.size()};
74 return ccin;
75 }
76
77 return std::nullopt;
78}
79
80std::optional<std::string> FRUIdentity::getSN() const
81{
82 if (hasSN())
83 {
84 std::string sn{_sn.begin(), _sn.begin() + _sn.size()};
85 return sn;
86 }
87
88 return std::nullopt;
89}
90
Matt Spinler724d0d82019-11-06 10:05:36 -060091void FRUIdentity::flatten(Stream& pel) const
Matt Spinlera906c942019-10-08 13:42:05 -050092{
93 pel << _type << _size << _flags;
94
95 if (hasPN() || hasMP())
96 {
97 pel.write(_pnOrProcedureID.data(), _pnOrProcedureID.size());
98 }
99
100 if (hasCCIN())
101 {
102 pel.write(_ccin.data(), _ccin.size());
103 }
104
105 if (hasSN())
106 {
107 pel.write(_sn.data(), _sn.size());
108 }
109}
110
111} // namespace src
112} // namespace pels
113} // namespace openpower