summaryrefslogtreecommitdiffstats
path: root/extensions/openpower-pels/private_header.hpp
blob: dd0d5040ef580b0adfaa9a1ee0ca362519c8ed91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#pragma once

#include "bcd_time.hpp"
#include "section.hpp"
#include "stream.hpp"

namespace openpower
{
namespace pels
{

struct CreatorVersion
{
    uint8_t version[8];

    CreatorVersion()
    {
        memset(version, '\0', sizeof(version));
    }
};

static constexpr uint8_t privateHeaderVersion = 0x01;
static constexpr uint8_t minSectionCount = 2;

/**
 * @class PrivateHeader
 *
 * This represents the Private Header section in a PEL.  It is required,
 * and it is always the first section.
 *
 * The Section base class handles the section header structure that every
 * PEL section has at offset zero.
 *
 * The fields in this class directly correspond to the order and sizes of
 * the fields in the section.
 */
class PrivateHeader : public Section
{
  public:
    PrivateHeader() = delete;
    ~PrivateHeader() = default;
    PrivateHeader(const PrivateHeader&) = default;
    PrivateHeader& operator=(const PrivateHeader&) = default;
    PrivateHeader(PrivateHeader&&) = default;
    PrivateHeader& operator=(PrivateHeader&&) = default;

    /**
     * @brief Constructor
     *
     * Creates a valid PrivateHeader with the passed in data
     *
     * @param[in] componentID - the creator's component ID
     * @param[in] obmcLogID - the corresponding OpenBMC event log ID
     * @param[in] timestamp - the creation timestamp, in epoch milliseconds
     */
    PrivateHeader(uint16_t componentID, uint32_t obmcLogID, uint64_t timestamp);

    /**
     * @brief Constructor
     *
     * Fills in this class's data fields from the stream.
     *
     * @param[in] pel - the PEL data stream
     *
     */
    explicit PrivateHeader(Stream& pel);

    /**
     * @brief Flatten the section into the stream
     *
     * @param[in] stream - The stream to write to
     */
    void flatten(Stream& stream) const override;

    /**
     * @brief Returns the creation timestamp
     *
     * @return const BCDTime& - the timestamp
     */
    const BCDTime& createTimestamp() const
    {
        return _createTimestamp;
    }

    /**
     * @brief Returns the commit time timestamp
     *
     * @return const BCDTime& - the timestamp
     */
    const BCDTime& commitTimestamp() const
    {
        return _commitTimestamp;
    }

    /**
     * @brief Sets the commit timestamp
     *
     * @param[in] time - the new timestamp
     */
    void setCommitTimestamp(const BCDTime& time)
    {
        _commitTimestamp = time;
    }

    /**
     * @brief Returns the creator ID field
     *
     * @return uint8_t - the creator ID
     */
    uint8_t creatorID() const
    {
        return _creatorID;
    }

    /**
     * @brief Returns the log type field
     *
     * @return uint8_t - the log type
     */
    uint8_t logType() const
    {
        return _logType;
    }

    /**
     * @brief Returns the section count field
     *
     * @return uint8_t - the section count
     */
    uint8_t sectionCount() const
    {
        return _sectionCount;
    }

    /**
     * @brief Sets the section count field
     *
     * @param[in] count - the new section count
     */
    void setSectionCount(uint8_t count)
    {
        _sectionCount = count;
    }

    /**
     * @brief Returns the OpenBMC log ID field
     *
     * This is the ID the OpenBMC event log that corresponds
     * to this PEL.
     *
     * @return uint32_t - the OpenBMC event log ID
     */
    uint32_t obmcLogID() const
    {
        return _obmcLogID;
    }

    /**
     * @brief Sets the OpenBMC log ID field
     *
     * @param[in] id - the new ID
     */
    void setOBMCLogID(uint32_t id)
    {
        _obmcLogID = id;
    }

    /**
     * @brief Returns the Creator Version field
     *
     * @return CreatorVersion& - the creator version
     */
    const CreatorVersion& creatorVersion() const
    {
        return _creatorVersion;
    }

    /**
     * @brief Returns the error log ID field
     *
     * @return uint32_t - the error log ID
     */
    uint32_t id() const
    {
        return _id;
    }

    /**
     * @brief Sets the ID field
     *
     * @param[in] id - the new ID
     */
    void setID(uint32_t id)
    {
        _id = id;
    }

    /**
     * @brief Returns the platform log ID field
     *
     * @return uint32_t - the platform log ID
     */
    uint32_t plid() const
    {
        return _plid;
    }

    /**
     * @brief Returns the size of this section when flattened into a PEL
     *
     * @return size_t - the size of the section
     */
    static constexpr size_t flattenedSize()
    {
        return Section::flattenedSize() + sizeof(_createTimestamp) +
               sizeof(_commitTimestamp) + sizeof(_creatorID) +
               sizeof(_logType) + sizeof(_reservedByte) +
               sizeof(_sectionCount) + sizeof(_obmcLogID) +
               sizeof(_creatorVersion) + sizeof(_plid) + sizeof(_id);
    }

    /**
     * @brief Get section in JSON.
     * @return std::optional<std::string> - Private header section's JSON
     */
    std::optional<std::string> getJSON() const override;

  private:
    /**
     * @brief Fills in the object from the stream data
     *
     * @param[in] stream - The stream to read from
     */
    void unflatten(Stream& stream);

    /**
     * @brief Validates the section contents
     *
     * Updates _valid (in Section) with the results.
     */
    void validate() override;

    /**
     * @brief The creation time timestamp
     */
    BCDTime _createTimestamp;

    /**
     * @brief The commit time timestamp
     */
    BCDTime _commitTimestamp;

    /**
     * @brief The creator ID field
     */
    uint8_t _creatorID;

    /**
     * @brief The log type field
     */
    uint8_t _logType;

    /**
     * @brief A reserved byte.
     */
    uint8_t _reservedByte;

    /**
     * @brief The section count field, which is the total number
     * of sections in the PEL.
     */
    uint8_t _sectionCount;

    /**
     * @brief The OpenBMC event log ID that corresponds to this PEL.
     */
    uint32_t _obmcLogID;

    /**
     * @brief The creator subsystem version field
     */
    CreatorVersion _creatorVersion;

    /**
     * @brief The platform log ID field
     */
    uint32_t _plid;

    /**
     * @brief The log entry ID field
     */
    uint32_t _id;
};

/**
 * @brief Stream extraction operator for the CreatorVersion
 *
 * @param[in] s - the stream
 * @param[out] cv - the CreatorVersion object
 */
Stream& operator>>(Stream& s, CreatorVersion& cv);

/**
 * @brief Stream insertion operator for the CreatorVersion
 *
 * @param[out] s - the stream
 * @param[in] cv - the CreatorVersion object
 */
Stream& operator<<(Stream& s, const CreatorVersion& cv);

} // namespace pels
} // namespace openpower
OpenPOWER on IntegriCloud