blob: 016f3fd1cfad06952c423b4943437493a1378728 [file] [log] [blame]
Matt Spinlera906c942019-10-08 13:42:05 -05001#pragma once
2
Matt Spinlerba0ee002020-03-13 11:24:14 -05003#include "pel_types.hpp"
Matt Spinlera906c942019-10-08 13:42:05 -05004#include "stream.hpp"
5
6#include <optional>
7
8namespace openpower
9{
10namespace pels
11{
12namespace src
13{
14
15/**
16 * @class FRUIdentity
17 *
18 * This represents the FRU Identity substructure in the
19 * callout subsection of the SRC PEL section.
20 *
21 * It provides information about the FRU being called out,
22 * such as serial number and part number. A maintenance
23 * procedure name may be used instead of the part number,
24 * and this would be indicated in the flags field.
25 */
26class FRUIdentity
27{
28 public:
29 /**
30 * @brief The failing component type
31 *
32 * Upper nibble of the flags byte
33 */
34 enum FailingComponentType
35 {
36 hardwareFRU = 0x10,
37 codeFRU = 0x20,
38 configError = 0x30,
39 maintenanceProc = 0x40,
40 externalFRU = 0x90,
41 externalCodeFRU = 0xA0,
42 toolFRU = 0xB0,
43 symbolicFRU = 0xC0,
44 symbolicFRUTrustedLocCode = 0xE0
45 };
46
47 /**
48 * @brief The lower nibble of the flags byte
49 */
50 enum Flags
51 {
52 pnSupplied = 0x08,
53 ccinSupplied = 0x04,
54 maintProcSupplied = 0x02,
55 snSupplied = 0x01
56 };
57
58 FRUIdentity() = delete;
59 ~FRUIdentity() = default;
60 FRUIdentity(const FRUIdentity&) = default;
61 FRUIdentity& operator=(const FRUIdentity&) = default;
62 FRUIdentity(FRUIdentity&&) = default;
63 FRUIdentity& operator=(FRUIdentity&&) = default;
64
65 /**
66 * @brief Constructor
67 *
68 * Fills in this class's data fields from the stream.
69 *
70 * @param[in] pel - the PEL data stream
71 */
72 explicit FRUIdentity(Stream& pel);
73
74 /**
Matt Spinlerba0ee002020-03-13 11:24:14 -050075 * Constructor
76 *
77 * Creates the object as a hardware callout with the part number,
78 * CCIN, and serial number fields supplied.
79 *
80 * @param[in] partNumber - The part number of the FRU
81 * @param[in] ccin - The CCIN of the FRU
82 * @param[in] serialNumber - The serial number of the FRU
83 */
84 FRUIdentity(const std::string& partNumber, const std::string& ccin,
85 const std::string& serialNumber);
86
87 /**
88 * @brief Constructor
89 *
90 * Creates the object with a maintenance procedure callout.
91 *
92 * @param[in] procedure - The procedure to use
93 */
94 FRUIdentity(MaintProcedure procedure);
95
96 /**
Matt Spinlera906c942019-10-08 13:42:05 -050097 * @brief Flatten the object into the stream
98 *
99 * @param[in] stream - The stream to write to
100 */
Matt Spinler724d0d82019-11-06 10:05:36 -0600101 void flatten(Stream& pel) const;
Matt Spinlera906c942019-10-08 13:42:05 -0500102
103 /**
104 * @brief Returns the size of this structure when flattened into a PEL
105 *
106 * @return size_t - The size of the section
107 */
Matt Spinlera09354b2020-03-13 10:24:52 -0500108 size_t flattenedSize() const;
Matt Spinlera906c942019-10-08 13:42:05 -0500109
110 /**
Matt Spinlerba0ee002020-03-13 11:24:14 -0500111 * @brief Returns the type field
112 *
113 * @return uint16_t - The type, always 0x4944 "ID".
114 */
115 uint16_t type() const
116 {
117 return _type;
118 }
119 /**
Matt Spinlera906c942019-10-08 13:42:05 -0500120 * @brief The failing component type for this FRU callout.
121 *
122 * @return FailingComponentType
123 */
124 FailingComponentType failingComponentType() const
125 {
126 return static_cast<FailingComponentType>(_flags & 0xF0);
127 }
128
129 /**
130 * @brief Returns the part number, if supplied
131 *
132 * @return std::optional<std::string>
133 */
134 std::optional<std::string> getPN() const;
135
136 /**
137 * @brief Returns the maintenance procedure, if supplied
138 *
139 * @return std::optional<std::string>
140 */
141 std::optional<std::string> getMaintProc() const;
142
143 /**
144 * @brief Returns the CCIN, if supplied
145 *
146 * @return std::optional<std::string>
147 */
148 std::optional<std::string> getCCIN() const;
149
150 /**
151 * @brief Returns the serial number, if supplied
152 *
153 * @return std::optional<std::string>
154 */
155 std::optional<std::string> getSN() const;
156
157 /**
158 * @brief The type identifier value of this structure.
159 */
160 static const uint16_t substructureType = 0x4944; // "ID"
161
162 private:
163 /**
164 * @brief If the part number is contained in this structure.
165 *
166 * It takes the place of the maintenance procedure ID.
167 *
168 * @return bool
169 */
170 bool hasPN() const
171 {
172 return _flags & pnSupplied;
173 }
174
175 /**
176 * @brief If the CCIN is contained in this structure.
177 *
178 * @return bool
179 */
180 bool hasCCIN() const
181 {
182 return _flags & ccinSupplied;
183 }
184
185 /**
186 * @brief If a maintenance procedure is contained in this structure.
187 *
188 * It takes the place of the part number.
189 *
190 * @return bool
191 */
192 bool hasMP() const
193 {
194 return _flags & maintProcSupplied;
195 }
196
197 /**
198 * @brief If the serial number is contained in this structure.
199 *
200 * @return bool
201 */
202 bool hasSN() const
203 {
204 return _flags & snSupplied;
205 }
206
207 /**
Matt Spinlerba0ee002020-03-13 11:24:14 -0500208 * @brief Sets the 8 character null terminated part
209 * number field to the string passed in.
210 *
211 * @param[in] partNumber - The part number string.
212 */
213 void setPartNumber(const std::string& partNumber);
214
215 /**
216 * @brief Sets the 4 character CCIN field.
217 *
218 * @param[in] ccin - The CCIN string
219 */
220 void setCCIN(const std::string& ccin);
221
222 /**
223 * @brief Sets the 12 character serial number field.
224 *
225 * @param[in] serialNumber - The serial number string
226 */
227 void setSerialNumber(const std::string& serialNumber);
228
229 /**
230 * @brief Sets the 8 character null terminated procedure
231 * field. This is in the same field as the part
232 * number since they are mutually exclusive.
233 */
234 void setMaintenanceProcedure(MaintProcedure procedure);
235
236 /**
Matt Spinlera906c942019-10-08 13:42:05 -0500237 * @brief The callout substructure type field. Will be "ID".
238 */
239 uint16_t _type;
240
241 /**
242 * @brief The size of this callout structure.
243 *
244 * Always a multiple of 4.
245 */
246 uint8_t _size;
247
248 /**
249 * @brief The flags byte of this substructure.
250 *
251 * See the FailingComponentType and Flags enums
252 */
253 uint8_t _flags;
254
255 /**
256 * @brief The part number OR maintenance procedure ID,
257 * depending on what the flags field specifies.
258 *
259 * A NULL terminated ASCII string.
260 */
261 std::array<char, 8> _pnOrProcedureID;
262
263 /**
264 * @brief The CCIN VPD keyword
265 *
266 * Four ASCII characters, not NULL terminated.
267 */
268 std::array<char, 4> _ccin;
269
270 /**
271 * @brief The serial number
272 *
273 * Twelve ASCII characters, not NULL terminated.
274 */
275 std::array<char, 12> _sn;
276};
277
278} // namespace src
279} // namespace pels
280} // namespace openpower