blob: 224142ce386e27eb24e1ec6f54d58ed2e882d663 [file] [log] [blame]
Matt Spinlerd3335df2019-07-10 11:04:21 -05001#pragma once
2
3#include "bcd_time.hpp"
4#include "section.hpp"
5#include "stream.hpp"
6
7namespace openpower
8{
9namespace pels
10{
11
12struct CreatorVersion
13{
14 uint8_t version[8];
Matt Spinler289aa472019-09-20 12:33:29 -050015
16 CreatorVersion()
17 {
18 memset(version, '\0', sizeof(version));
19 }
Matt Spinlerd3335df2019-07-10 11:04:21 -050020};
21
Matt Spinler1a94cc32019-09-11 13:32:12 -050022static constexpr uint8_t privateHeaderVersion = 0x01;
Matt Spinlerd3335df2019-07-10 11:04:21 -050023static constexpr uint8_t minSectionCount = 2;
24
25/**
26 * @class PrivateHeader
27 *
28 * This represents the Private Header section in a PEL. It is required,
29 * and it is always the first section.
30 *
31 * The Section base class handles the section header structure that every
32 * PEL section has at offset zero.
33 *
34 * The fields in this class directly correspond to the order and sizes of
35 * the fields in the section.
36 */
37class PrivateHeader : public Section
38{
39 public:
40 PrivateHeader() = delete;
41 ~PrivateHeader() = default;
42 PrivateHeader(const PrivateHeader&) = default;
43 PrivateHeader& operator=(const PrivateHeader&) = default;
44 PrivateHeader(PrivateHeader&&) = default;
45 PrivateHeader& operator=(PrivateHeader&&) = default;
46
47 /**
48 * @brief Constructor
49 *
Matt Spinler289aa472019-09-20 12:33:29 -050050 * Creates a valid PrivateHeader with the passed in data
51 *
52 * @param[in] componentID - the creator's component ID
53 * @param[in] obmcLogID - the corresponding OpenBMC event log ID
54 * @param[in] timestamp - the creation timestamp, in epoch milliseconds
55 */
56 PrivateHeader(uint16_t componentID, uint32_t obmcLogID, uint64_t timestamp);
57
58 /**
59 * @brief Constructor
60 *
Matt Spinlerd3335df2019-07-10 11:04:21 -050061 * Fills in this class's data fields from the stream.
62 *
63 * @param[in] pel - the PEL data stream
64 *
65 */
66 explicit PrivateHeader(Stream& pel);
67
68 /**
Matt Spinlercf5a8d02019-09-05 12:58:53 -050069 * @brief Flatten the section into the stream
70 *
71 * @param[in] stream - The stream to write to
72 */
Matt Spinler06885452019-11-06 10:35:42 -060073 void flatten(Stream& stream) const override;
Matt Spinlercf5a8d02019-09-05 12:58:53 -050074
75 /**
Matt Spinlerd3335df2019-07-10 11:04:21 -050076 * @brief Returns the creation timestamp
77 *
Matt Spinler97d19b42019-10-29 11:34:03 -050078 * @return const BCDTime& - the timestamp
Matt Spinlerd3335df2019-07-10 11:04:21 -050079 */
Matt Spinler97d19b42019-10-29 11:34:03 -050080 const BCDTime& createTimestamp() const
Matt Spinlerd3335df2019-07-10 11:04:21 -050081 {
82 return _createTimestamp;
83 }
84
85 /**
86 * @brief Returns the commit time timestamp
87 *
Matt Spinler97d19b42019-10-29 11:34:03 -050088 * @return const BCDTime& - the timestamp
Matt Spinlerd3335df2019-07-10 11:04:21 -050089 */
Matt Spinler97d19b42019-10-29 11:34:03 -050090 const BCDTime& commitTimestamp() const
Matt Spinlerd3335df2019-07-10 11:04:21 -050091 {
92 return _commitTimestamp;
93 }
94
95 /**
Matt Spinler97d19b42019-10-29 11:34:03 -050096 * @brief Sets the commit timestamp
97 *
98 * @param[in] time - the new timestamp
99 */
100 void setCommitTimestamp(const BCDTime& time)
101 {
102 _commitTimestamp = time;
103 }
104
105 /**
Matt Spinlerd3335df2019-07-10 11:04:21 -0500106 * @brief Returns the creator ID field
107 *
Matt Spinler97d19b42019-10-29 11:34:03 -0500108 * @return uint8_t - the creator ID
Matt Spinlerd3335df2019-07-10 11:04:21 -0500109 */
Matt Spinler97d19b42019-10-29 11:34:03 -0500110 uint8_t creatorID() const
Matt Spinlerd3335df2019-07-10 11:04:21 -0500111 {
112 return _creatorID;
113 }
114
115 /**
116 * @brief Returns the log type field
117 *
Matt Spinler97d19b42019-10-29 11:34:03 -0500118 * @return uint8_t - the log type
Matt Spinlerd3335df2019-07-10 11:04:21 -0500119 */
Matt Spinler97d19b42019-10-29 11:34:03 -0500120 uint8_t logType() const
Matt Spinlerd3335df2019-07-10 11:04:21 -0500121 {
122 return _logType;
123 }
124
125 /**
126 * @brief Returns the section count field
127 *
Matt Spinler97d19b42019-10-29 11:34:03 -0500128 * @return uint8_t - the section count
Matt Spinlerd3335df2019-07-10 11:04:21 -0500129 */
Matt Spinler97d19b42019-10-29 11:34:03 -0500130 uint8_t sectionCount() const
Matt Spinlerd3335df2019-07-10 11:04:21 -0500131 {
132 return _sectionCount;
133 }
134
135 /**
Matt Spinler97d19b42019-10-29 11:34:03 -0500136 * @brief Sets the section count field
137 *
138 * @param[in] count - the new section count
139 */
140 void setSectionCount(uint8_t count)
141 {
142 _sectionCount = count;
143 }
144
145 /**
Matt Spinlerd3335df2019-07-10 11:04:21 -0500146 * @brief Returns the OpenBMC log ID field
147 *
148 * This is the ID the OpenBMC event log that corresponds
149 * to this PEL.
150 *
Matt Spinler97d19b42019-10-29 11:34:03 -0500151 * @return uint32_t - the OpenBMC event log ID
Matt Spinlerd3335df2019-07-10 11:04:21 -0500152 */
Matt Spinler97d19b42019-10-29 11:34:03 -0500153 uint32_t obmcLogID() const
Matt Spinlerd3335df2019-07-10 11:04:21 -0500154 {
155 return _obmcLogID;
156 }
157
158 /**
Matt Spinler97d19b42019-10-29 11:34:03 -0500159 * @brief Sets the OpenBMC log ID field
160 *
161 * @param[in] id - the new ID
162 */
163 void setOBMCLogID(uint32_t id)
164 {
165 _obmcLogID = id;
166 }
167
168 /**
Matt Spinlerd3335df2019-07-10 11:04:21 -0500169 * @brief Returns the Creator Version field
170 *
171 * @return CreatorVersion& - the creator version
172 */
Matt Spinler06885452019-11-06 10:35:42 -0600173 const CreatorVersion& creatorVersion() const
Matt Spinlerd3335df2019-07-10 11:04:21 -0500174 {
175 return _creatorVersion;
176 }
177
178 /**
179 * @brief Returns the error log ID field
180 *
Matt Spinler97d19b42019-10-29 11:34:03 -0500181 * @return uint32_t - the error log ID
Matt Spinlerd3335df2019-07-10 11:04:21 -0500182 */
Matt Spinler97d19b42019-10-29 11:34:03 -0500183 uint32_t id() const
Matt Spinlerd3335df2019-07-10 11:04:21 -0500184 {
185 return _id;
186 }
187
188 /**
Matt Spinler97d19b42019-10-29 11:34:03 -0500189 * @brief Sets the ID field
190 *
191 * @param[in] id - the new ID
192 */
193 void setID(uint32_t id)
194 {
195 _id = id;
196 }
197
198 /**
Matt Spinlerd3335df2019-07-10 11:04:21 -0500199 * @brief Returns the platform log ID field
200 *
Matt Spinler97d19b42019-10-29 11:34:03 -0500201 * @return uint32_t - the platform log ID
Matt Spinlerd3335df2019-07-10 11:04:21 -0500202 */
Matt Spinler97d19b42019-10-29 11:34:03 -0500203 uint32_t plid() const
Matt Spinlerd3335df2019-07-10 11:04:21 -0500204 {
205 return _plid;
206 }
207
208 /**
209 * @brief Returns the size of this section when flattened into a PEL
210 *
211 * @return size_t - the size of the section
212 */
213 static constexpr size_t flattenedSize()
214 {
215 return Section::flattenedSize() + sizeof(_createTimestamp) +
216 sizeof(_commitTimestamp) + sizeof(_creatorID) +
217 sizeof(_logType) + sizeof(_reservedByte) +
218 sizeof(_sectionCount) + sizeof(_obmcLogID) +
219 sizeof(_creatorVersion) + sizeof(_plid) + sizeof(_id);
220 }
221
Aatirc92b4eb2019-11-18 13:44:51 -0600222 /**
223 * @brief Get section in JSON.
Matt Spinlerb832aa52023-03-21 15:32:34 -0500224 *
225 * @param[in] creatorID - The creator ID for the PEL
226 *
Aatirc92b4eb2019-11-18 13:44:51 -0600227 * @return std::optional<std::string> - Private header section's JSON
228 */
Matt Spinlerb832aa52023-03-21 15:32:34 -0500229 std::optional<std::string> getJSON(uint8_t creatorID) const override;
Aatirc92b4eb2019-11-18 13:44:51 -0600230
Matt Spinlerd3335df2019-07-10 11:04:21 -0500231 private:
232 /**
Matt Spinlercf5a8d02019-09-05 12:58:53 -0500233 * @brief Fills in the object from the stream data
234 *
235 * @param[in] stream - The stream to read from
236 */
237 void unflatten(Stream& stream);
238
239 /**
Matt Spinlerd3335df2019-07-10 11:04:21 -0500240 * @brief Validates the section contents
241 *
242 * Updates _valid (in Section) with the results.
243 */
244 void validate() override;
245
246 /**
247 * @brief The creation time timestamp
248 */
249 BCDTime _createTimestamp;
250
251 /**
252 * @brief The commit time timestamp
253 */
254 BCDTime _commitTimestamp;
255
256 /**
257 * @brief The creator ID field
258 */
259 uint8_t _creatorID;
260
261 /**
262 * @brief The log type field
263 */
264 uint8_t _logType;
265
266 /**
267 * @brief A reserved byte.
268 */
269 uint8_t _reservedByte;
270
271 /**
272 * @brief The section count field, which is the total number
273 * of sections in the PEL.
274 */
275 uint8_t _sectionCount;
276
277 /**
278 * @brief The OpenBMC event log ID that corresponds to this PEL.
279 */
280 uint32_t _obmcLogID;
281
282 /**
283 * @brief The creator subsystem version field
284 */
285 CreatorVersion _creatorVersion;
286
287 /**
288 * @brief The platform log ID field
289 */
290 uint32_t _plid;
291
292 /**
293 * @brief The log entry ID field
294 */
295 uint32_t _id;
296};
297
298/**
Matt Spinlerd3335df2019-07-10 11:04:21 -0500299 * @brief Stream extraction operator for the CreatorVersion
300 *
301 * @param[in] s - the stream
302 * @param[out] cv - the CreatorVersion object
303 */
304Stream& operator>>(Stream& s, CreatorVersion& cv);
305
306/**
307 * @brief Stream insertion operator for the CreatorVersion
308 *
309 * @param[out] s - the stream
310 * @param[in] cv - the CreatorVersion object
311 */
Matt Spinler06885452019-11-06 10:35:42 -0600312Stream& operator<<(Stream& s, const CreatorVersion& cv);
Matt Spinlerd3335df2019-07-10 11:04:21 -0500313
314} // namespace pels
315} // namespace openpower