blob: 669dc01a5fdfc82c74eb8cd884c6e14312d96b50 [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 *
Matt Spinlera27e2e52020-04-09 11:06:11 -050092 * @param[in] procedureFromRegistry - The maintenance procedure name
93 * as defined in the message registry.
Matt Spinlerba0ee002020-03-13 11:24:14 -050094 */
Matt Spinlera27e2e52020-04-09 11:06:11 -050095 FRUIdentity(const std::string& procedureFromRegistry);
Matt Spinlerba0ee002020-03-13 11:24:14 -050096
97 /**
Matt Spinlera906c942019-10-08 13:42:05 -050098 * @brief Flatten the object into the stream
99 *
100 * @param[in] stream - The stream to write to
101 */
Matt Spinler724d0d82019-11-06 10:05:36 -0600102 void flatten(Stream& pel) const;
Matt Spinlera906c942019-10-08 13:42:05 -0500103
104 /**
105 * @brief Returns the size of this structure when flattened into a PEL
106 *
107 * @return size_t - The size of the section
108 */
Matt Spinlera09354b2020-03-13 10:24:52 -0500109 size_t flattenedSize() const;
Matt Spinlera906c942019-10-08 13:42:05 -0500110
111 /**
Matt Spinlerba0ee002020-03-13 11:24:14 -0500112 * @brief Returns the type field
113 *
114 * @return uint16_t - The type, always 0x4944 "ID".
115 */
116 uint16_t type() const
117 {
118 return _type;
119 }
120 /**
Matt Spinlera906c942019-10-08 13:42:05 -0500121 * @brief The failing component type for this FRU callout.
122 *
123 * @return FailingComponentType
124 */
125 FailingComponentType failingComponentType() const
126 {
127 return static_cast<FailingComponentType>(_flags & 0xF0);
128 }
129
130 /**
131 * @brief Returns the part number, if supplied
132 *
133 * @return std::optional<std::string>
134 */
135 std::optional<std::string> getPN() const;
136
137 /**
138 * @brief Returns the maintenance procedure, if supplied
139 *
140 * @return std::optional<std::string>
141 */
142 std::optional<std::string> getMaintProc() const;
143
144 /**
145 * @brief Returns the CCIN, if supplied
146 *
147 * @return std::optional<std::string>
148 */
149 std::optional<std::string> getCCIN() const;
150
151 /**
152 * @brief Returns the serial number, if supplied
153 *
154 * @return std::optional<std::string>
155 */
156 std::optional<std::string> getSN() const;
157
158 /**
159 * @brief The type identifier value of this structure.
160 */
161 static const uint16_t substructureType = 0x4944; // "ID"
162
163 private:
164 /**
165 * @brief If the part number is contained in this structure.
166 *
167 * It takes the place of the maintenance procedure ID.
168 *
169 * @return bool
170 */
171 bool hasPN() const
172 {
173 return _flags & pnSupplied;
174 }
175
176 /**
177 * @brief If the CCIN is contained in this structure.
178 *
179 * @return bool
180 */
181 bool hasCCIN() const
182 {
183 return _flags & ccinSupplied;
184 }
185
186 /**
187 * @brief If a maintenance procedure is contained in this structure.
188 *
189 * It takes the place of the part number.
190 *
191 * @return bool
192 */
193 bool hasMP() const
194 {
195 return _flags & maintProcSupplied;
196 }
197
198 /**
199 * @brief If the serial number is contained in this structure.
200 *
201 * @return bool
202 */
203 bool hasSN() const
204 {
205 return _flags & snSupplied;
206 }
207
208 /**
Matt Spinlerba0ee002020-03-13 11:24:14 -0500209 * @brief Sets the 8 character null terminated part
210 * number field to the string passed in.
211 *
212 * @param[in] partNumber - The part number string.
213 */
214 void setPartNumber(const std::string& partNumber);
215
216 /**
217 * @brief Sets the 4 character CCIN field.
218 *
219 * @param[in] ccin - The CCIN string
220 */
221 void setCCIN(const std::string& ccin);
222
223 /**
224 * @brief Sets the 12 character serial number field.
225 *
226 * @param[in] serialNumber - The serial number string
227 */
228 void setSerialNumber(const std::string& serialNumber);
229
230 /**
231 * @brief Sets the 8 character null terminated procedure
232 * field. This is in the same field as the part
233 * number since they are mutually exclusive.
Matt Spinlera27e2e52020-04-09 11:06:11 -0500234 *
235 * @param procedureFromRegistry - The procedure name as defined in
236 * the PEL message registry.
Matt Spinlerba0ee002020-03-13 11:24:14 -0500237 */
Matt Spinlera27e2e52020-04-09 11:06:11 -0500238 void setMaintenanceProcedure(const std::string& procedureFromRegistry);
Matt Spinlerba0ee002020-03-13 11:24:14 -0500239
240 /**
Matt Spinlera906c942019-10-08 13:42:05 -0500241 * @brief The callout substructure type field. Will be "ID".
242 */
243 uint16_t _type;
244
245 /**
246 * @brief The size of this callout structure.
247 *
248 * Always a multiple of 4.
249 */
250 uint8_t _size;
251
252 /**
253 * @brief The flags byte of this substructure.
254 *
255 * See the FailingComponentType and Flags enums
256 */
257 uint8_t _flags;
258
259 /**
260 * @brief The part number OR maintenance procedure ID,
261 * depending on what the flags field specifies.
262 *
263 * A NULL terminated ASCII string.
264 */
265 std::array<char, 8> _pnOrProcedureID;
266
267 /**
268 * @brief The CCIN VPD keyword
269 *
270 * Four ASCII characters, not NULL terminated.
271 */
272 std::array<char, 4> _ccin;
273
274 /**
275 * @brief The serial number
276 *
277 * Twelve ASCII characters, not NULL terminated.
278 */
279 std::array<char, 12> _sn;
280};
281
282} // namespace src
283} // namespace pels
284} // namespace openpower