1cb6b059eSMatt Spinler #pragma once
2cb6b059eSMatt Spinler 
3b832363dSMatt Spinler #include "additional_data.hpp"
4aa659477SMatt Spinler #include "data_interface.hpp"
59d921096SMatt Spinler #include "journal.hpp"
6cb6b059eSMatt Spinler #include "private_header.hpp"
7b832363dSMatt Spinler #include "registry.hpp"
8bd716f00SMatt Spinler #include "src.hpp"
9afa857c7SMatt Spinler #include "user_data.hpp"
1056ad2a0eSMatt Spinler #include "user_data_formats.hpp"
11cb6b059eSMatt Spinler #include "user_header.hpp"
12cb6b059eSMatt Spinler 
13cb6b059eSMatt Spinler #include <memory>
14cb6b059eSMatt Spinler #include <vector>
15cb6b059eSMatt Spinler 
16cb6b059eSMatt Spinler namespace openpower
17cb6b059eSMatt Spinler {
18cb6b059eSMatt Spinler namespace pels
19cb6b059eSMatt Spinler {
20cb6b059eSMatt Spinler 
2156ad2a0eSMatt Spinler /**
2256ad2a0eSMatt Spinler  * @brief Contains information about an FFDC file.
2356ad2a0eSMatt Spinler  */
2456ad2a0eSMatt Spinler struct PelFFDCfile
2556ad2a0eSMatt Spinler {
2656ad2a0eSMatt Spinler     UserDataFormat format;
2756ad2a0eSMatt Spinler     uint8_t subType;
2856ad2a0eSMatt Spinler     uint8_t version;
2956ad2a0eSMatt Spinler     int fd;
3056ad2a0eSMatt Spinler };
3156ad2a0eSMatt Spinler 
3256ad2a0eSMatt Spinler using PelFFDC = std::vector<PelFFDCfile>;
33*d8ae618aSArya K Padman using DebugData = std::map<std::string, std::vector<std::string>>;
3456ad2a0eSMatt Spinler 
351ddf1e8eSJayanth Othayoth constexpr uint8_t jsonCalloutSubtype = 0xCA;
361ddf1e8eSJayanth Othayoth 
37cb6b059eSMatt Spinler /** @class PEL
38cb6b059eSMatt Spinler  *
39cb6b059eSMatt Spinler  * @brief This class represents a specific event log format referred to as a
40cb6b059eSMatt Spinler  * Platform Event Log.
41cb6b059eSMatt Spinler  *
42cb6b059eSMatt Spinler  * Every field in a PEL are in structures call sections, of which there are
43cb6b059eSMatt Spinler  * several types.  Some sections are required, and some are optional.  In some
44cb6b059eSMatt Spinler  * cases there may be more than one instance of a section type.
45cb6b059eSMatt Spinler  *
46cb6b059eSMatt Spinler  * The only two required sections for every type of PEL are the Private Header
47cb6b059eSMatt Spinler  * section and User Header section, which must be in the first and second
48cb6b059eSMatt Spinler  * positions, respectively.
49cb6b059eSMatt Spinler  *
50cb6b059eSMatt Spinler  * Every section starts with an 8 byte section header, which has the section
51cb6b059eSMatt Spinler  * size and type, among other things.
52cb6b059eSMatt Spinler  *
53cb6b059eSMatt Spinler  * This class represents all sections with objects.
54cb6b059eSMatt Spinler  *
55bd716f00SMatt Spinler  * The class can be constructed:
56bd716f00SMatt Spinler  * - From a full formed flattened PEL.
57bd716f00SMatt Spinler  * - From scratch based on an OpenBMC event and its corresponding PEL message
58bd716f00SMatt Spinler  *   registry entry.
59b832363dSMatt Spinler  *
60cb6b059eSMatt Spinler  * The data() method allows one to retrieve the PEL as a vector<uint8_t>.  This
61cb6b059eSMatt Spinler  * is the format in which it is stored and transmitted.
62cb6b059eSMatt Spinler  */
63cb6b059eSMatt Spinler class PEL
64cb6b059eSMatt Spinler {
65cb6b059eSMatt Spinler   public:
66cb6b059eSMatt Spinler     PEL() = delete;
67cb6b059eSMatt Spinler     ~PEL() = default;
68cb6b059eSMatt Spinler     PEL(const PEL&) = delete;
69cb6b059eSMatt Spinler     PEL& operator=(const PEL&) = delete;
70cb6b059eSMatt Spinler     PEL(PEL&&) = delete;
71cb6b059eSMatt Spinler     PEL& operator=(PEL&&) = delete;
72cb6b059eSMatt Spinler 
73cb6b059eSMatt Spinler     /**
74cb6b059eSMatt Spinler      * @brief Constructor
75cb6b059eSMatt Spinler      *
76cb6b059eSMatt Spinler      * Build a PEL from raw data.
77cb6b059eSMatt Spinler      *
7807eefc54SMatt Spinler      * Note: Neither this nor the following constructor can take a const vector&
7907eefc54SMatt Spinler      * because the Stream class that is used to read from the vector cannot take
8007eefc54SMatt Spinler      * a const.  The alternative is to make a copy of the data, but as PELs can
8107eefc54SMatt Spinler      * be up to 16KB that is undesireable.
8207eefc54SMatt Spinler      *
83cb6b059eSMatt Spinler      * @param[in] data - The PEL data
84cb6b059eSMatt Spinler      */
8545796e82SMatt Spinler     explicit PEL(std::vector<uint8_t>& data);
86cb6b059eSMatt Spinler 
87cb6b059eSMatt Spinler     /**
88cb6b059eSMatt Spinler      * @brief Constructor
89cb6b059eSMatt Spinler      *
90cb6b059eSMatt Spinler      * Build a PEL from the raw data.
91cb6b059eSMatt Spinler      *
92cb6b059eSMatt Spinler      * @param[in] data - the PEL data
93cb6b059eSMatt Spinler      * @param[in] obmcLogID - the corresponding OpenBMC event log ID
94cb6b059eSMatt Spinler      */
9507eefc54SMatt Spinler     PEL(std::vector<uint8_t>& data, uint32_t obmcLogID);
96cb6b059eSMatt Spinler 
97cb6b059eSMatt Spinler     /**
98b832363dSMatt Spinler      * @brief Constructor
99b832363dSMatt Spinler      *
100b832363dSMatt Spinler      * Creates a PEL from an OpenBMC event log and its message
101b832363dSMatt Spinler      * registry entry.
102b832363dSMatt Spinler      *
103b832363dSMatt Spinler      * @param[in] entry - The message registry entry for this error
104b832363dSMatt Spinler      * @param[in] obmcLogID - ID of corresponding OpenBMC event log
105b832363dSMatt Spinler      * @param[in] timestamp - Timestamp from the event log
106b832363dSMatt Spinler      * @param[in] severity - Severity from the event log
107bd716f00SMatt Spinler      * @param[in] additionalData - The AdditionalData contents
10856ad2a0eSMatt Spinler      * @param[in] ffdcFiles - FFCD files that go into UserData sections
109aa659477SMatt Spinler      * @param[in] dataIface - The data interface object
1109d921096SMatt Spinler      * @param[in] journal - The journal object
111b832363dSMatt Spinler      */
112b832363dSMatt Spinler     PEL(const openpower::pels::message::Entry& entry, uint32_t obmcLogID,
113bd716f00SMatt Spinler         uint64_t timestamp, phosphor::logging::Entry::Level severity,
11456ad2a0eSMatt Spinler         const AdditionalData& additionalData, const PelFFDC& ffdcFiles,
1159d921096SMatt Spinler         const DataInterfaceBase& dataIface, const JournalBase& journal);
116b832363dSMatt Spinler 
117b832363dSMatt Spinler     /**
118cb6b059eSMatt Spinler      * @brief Convenience function to return the log ID field from the
119cb6b059eSMatt Spinler      *        Private Header section.
120cb6b059eSMatt Spinler      *
121cb6b059eSMatt Spinler      * @return uint32_t - the ID
122cb6b059eSMatt Spinler      */
id() const123cb6b059eSMatt Spinler     uint32_t id() const
124cb6b059eSMatt Spinler     {
125cb6b059eSMatt Spinler         return _ph->id();
126cb6b059eSMatt Spinler     }
127cb6b059eSMatt Spinler 
128cb6b059eSMatt Spinler     /**
129cb6b059eSMatt Spinler      * @brief Convenience function to return the PLID field from the
130cb6b059eSMatt Spinler      *        Private Header section.
131cb6b059eSMatt Spinler      *
132cb6b059eSMatt Spinler      * @return uint32_t - the PLID
133cb6b059eSMatt Spinler      */
plid() const134cb6b059eSMatt Spinler     uint32_t plid() const
135cb6b059eSMatt Spinler     {
136cb6b059eSMatt Spinler         return _ph->plid();
137cb6b059eSMatt Spinler     }
138cb6b059eSMatt Spinler 
139cb6b059eSMatt Spinler     /**
140cb6b059eSMatt Spinler      * @brief Convenience function to return the OpenBMC event log ID field
141cb6b059eSMatt Spinler      * from the Private Header section.
142cb6b059eSMatt Spinler      *
143cb6b059eSMatt Spinler      * @return uint32_t - the OpenBMC event log ID
144cb6b059eSMatt Spinler      */
obmcLogID() const145cb6b059eSMatt Spinler     uint32_t obmcLogID() const
146cb6b059eSMatt Spinler     {
147cb6b059eSMatt Spinler         return _ph->obmcLogID();
148cb6b059eSMatt Spinler     }
149cb6b059eSMatt Spinler 
150cb6b059eSMatt Spinler     /**
151cb6b059eSMatt Spinler      * @brief Convenience function to return the commit time field from
152cb6b059eSMatt Spinler      *        the Private Header section.
153cb6b059eSMatt Spinler      *
154cb6b059eSMatt Spinler      * @return BCDTime - the timestamp
155cb6b059eSMatt Spinler      */
commitTime() const156cb6b059eSMatt Spinler     BCDTime commitTime() const
157cb6b059eSMatt Spinler     {
158cb6b059eSMatt Spinler         return _ph->commitTimestamp();
159cb6b059eSMatt Spinler     }
160cb6b059eSMatt Spinler 
161cb6b059eSMatt Spinler     /**
162cb6b059eSMatt Spinler      * @brief Convenience function to return the create time field from
163cb6b059eSMatt Spinler      *        the Private Header section.
164cb6b059eSMatt Spinler      *
165cb6b059eSMatt Spinler      * @return BCDTime - the timestamp
166cb6b059eSMatt Spinler      */
createTime() const167cb6b059eSMatt Spinler     BCDTime createTime() const
168cb6b059eSMatt Spinler     {
169cb6b059eSMatt Spinler         return _ph->createTimestamp();
170cb6b059eSMatt Spinler     }
171cb6b059eSMatt Spinler 
172cb6b059eSMatt Spinler     /**
173cb6b059eSMatt Spinler      * @brief Gives access to the Private Header section class
174cb6b059eSMatt Spinler      *
17597d19b48SMatt Spinler      * @return const PrivateHeader& - the private header
176cb6b059eSMatt Spinler      */
privateHeader() const17797d19b48SMatt Spinler     const PrivateHeader& privateHeader() const
178cb6b059eSMatt Spinler     {
17997d19b48SMatt Spinler         return *_ph;
180cb6b059eSMatt Spinler     }
181cb6b059eSMatt Spinler 
182cb6b059eSMatt Spinler     /**
183cb6b059eSMatt Spinler      * @brief Gives access to the User Header section class
184cb6b059eSMatt Spinler      *
18597d19b48SMatt Spinler      * @return const UserHeader& - the user header
186cb6b059eSMatt Spinler      */
userHeader() const18797d19b48SMatt Spinler     const UserHeader& userHeader() const
188cb6b059eSMatt Spinler     {
18997d19b48SMatt Spinler         return *_uh;
190cb6b059eSMatt Spinler     }
191cb6b059eSMatt Spinler 
192cb6b059eSMatt Spinler     /**
193bd716f00SMatt Spinler      * @brief Gives access to the primary SRC's section class
194bd716f00SMatt Spinler      *
195bd716f00SMatt Spinler      * This is technically an optional section, so the return
196bd716f00SMatt Spinler      * value is an std::optional<SRC*>.
197bd716f00SMatt Spinler      *
198bd716f00SMatt Spinler      * @return std::optional<SRC*> - the SRC section object
199bd716f00SMatt Spinler      */
200bd716f00SMatt Spinler     std::optional<SRC*> primarySRC() const;
201bd716f00SMatt Spinler 
202bd716f00SMatt Spinler     /**
203131870c7SMatt Spinler      * @brief Returns the optional sections, which is everything but
204131870c7SMatt Spinler      *        the Private and User Headers.
205131870c7SMatt Spinler      *
206131870c7SMatt Spinler      * @return const std::vector<std::unique_ptr<Section>>&
207131870c7SMatt Spinler      */
optionalSections() const208131870c7SMatt Spinler     const std::vector<std::unique_ptr<Section>>& optionalSections() const
209131870c7SMatt Spinler     {
210131870c7SMatt Spinler         return _optionalSections;
211131870c7SMatt Spinler     }
212131870c7SMatt Spinler 
213131870c7SMatt Spinler     /**
214cb6b059eSMatt Spinler      * @brief Returns the PEL data.
215cb6b059eSMatt Spinler      *
216cb6b059eSMatt Spinler      * @return std::vector<uint8_t> - the raw PEL data
217cb6b059eSMatt Spinler      */
2180688545bSMatt Spinler     std::vector<uint8_t> data() const;
219cb6b059eSMatt Spinler 
220cb6b059eSMatt Spinler     /**
221f1b46ff4SMatt Spinler      * @brief Returns the size of the PEL
222f1b46ff4SMatt Spinler      *
223f1b46ff4SMatt Spinler      * @return size_t The PEL size in bytes
224f1b46ff4SMatt Spinler      */
225f1b46ff4SMatt Spinler     size_t size() const;
226f1b46ff4SMatt Spinler 
227f1b46ff4SMatt Spinler     /**
228cb6b059eSMatt Spinler      * @brief Says if the PEL is valid (the sections are all valid)
229cb6b059eSMatt Spinler      *
230cb6b059eSMatt Spinler      * @return bool - if the PEL is valid
231cb6b059eSMatt Spinler      */
232cb6b059eSMatt Spinler     bool valid() const;
233cb6b059eSMatt Spinler 
234cb6b059eSMatt Spinler     /**
235cb6b059eSMatt Spinler      * @brief Sets the commit timestamp to the current time
236cb6b059eSMatt Spinler      */
237cb6b059eSMatt Spinler     void setCommitTime();
238cb6b059eSMatt Spinler 
239cb6b059eSMatt Spinler     /**
240cb6b059eSMatt Spinler      * @brief Sets the error log ID field to a unique ID.
241cb6b059eSMatt Spinler      */
242cb6b059eSMatt Spinler     void assignID();
243cb6b059eSMatt Spinler 
244186ce8c9SAatir     /**
245186ce8c9SAatir      * @brief Output a PEL in JSON.
246a214ed30SHarisuddin Mohamed Isa      * @param[in] registry - Registry object reference
247f67bafd0SHarisuddin Mohamed Isa      * @param[in] plugins - Vector of strings of plugins found in filesystem
248186ce8c9SAatir      */
249f67bafd0SHarisuddin Mohamed Isa     void toJSON(message::Registry& registry,
250f67bafd0SHarisuddin Mohamed Isa                 const std::vector<std::string>& plugins) const;
251186ce8c9SAatir 
252f38ce984SMatt Spinler     /**
253f38ce984SMatt Spinler      * @brief Sets the host transmission state in the User Header
254f38ce984SMatt Spinler      *
255f38ce984SMatt Spinler      * @param[in] state - The state value
256f38ce984SMatt Spinler      */
setHostTransmissionState(TransmissionState state)257f38ce984SMatt Spinler     void setHostTransmissionState(TransmissionState state)
258f38ce984SMatt Spinler     {
259f38ce984SMatt Spinler         _uh->setHostTransmissionState(static_cast<uint8_t>(state));
260f38ce984SMatt Spinler     }
261f38ce984SMatt Spinler 
262f38ce984SMatt Spinler     /**
263f38ce984SMatt Spinler      * @brief Returns the host transmission state
264f38ce984SMatt Spinler      *
265f38ce984SMatt Spinler      * @return HostTransmissionState - The state
266f38ce984SMatt Spinler      */
hostTransmissionState() const267f38ce984SMatt Spinler     TransmissionState hostTransmissionState() const
268f38ce984SMatt Spinler     {
269f38ce984SMatt Spinler         return static_cast<TransmissionState>(_uh->hostTransmissionState());
270f38ce984SMatt Spinler     }
271f38ce984SMatt Spinler 
272f38ce984SMatt Spinler     /**
273f38ce984SMatt Spinler      * @brief Sets the HMC transmission state in the User Header
274f38ce984SMatt Spinler      *
275f38ce984SMatt Spinler      * @param[in] state - The state value
276f38ce984SMatt Spinler      */
setHMCTransmissionState(TransmissionState state)277f38ce984SMatt Spinler     void setHMCTransmissionState(TransmissionState state)
278f38ce984SMatt Spinler     {
279f38ce984SMatt Spinler         _uh->setHMCTransmissionState(static_cast<uint8_t>(state));
280f38ce984SMatt Spinler     }
281f38ce984SMatt Spinler 
282f38ce984SMatt Spinler     /**
283f38ce984SMatt Spinler      * @brief Returns the HMC transmission state
284f38ce984SMatt Spinler      *
285f38ce984SMatt Spinler      * @return HMCTransmissionState - The state
286f38ce984SMatt Spinler      */
hmcTransmissionState() const287f38ce984SMatt Spinler     TransmissionState hmcTransmissionState() const
288f38ce984SMatt Spinler     {
289f38ce984SMatt Spinler         return static_cast<TransmissionState>(_uh->hmcTransmissionState());
290f38ce984SMatt Spinler     }
291f38ce984SMatt Spinler 
29244fc3168SAndrew Geissler     /**
293f8e750ddSAndrew Geissler      * @brief Returns true if a hardware callout is present in the primary SRC
29444fc3168SAndrew Geissler      *
295f8e750ddSAndrew Geissler      * @return true if hardware callout present, false otherwise
29644fc3168SAndrew Geissler      */
297f8e750ddSAndrew Geissler     bool isHwCalloutPresent() const;
29844fc3168SAndrew Geissler 
2993160a544SSumit Kumar     /**
3003160a544SSumit Kumar      * @brief Updates the system info data into HB extended user
3013160a544SSumit Kumar      *        data section to this PEL object
3023160a544SSumit Kumar      *
3033160a544SSumit Kumar      * @param[in] dataIface - The data interface object
3043160a544SSumit Kumar      */
3053160a544SSumit Kumar     void updateSysInfoInExtendedUserDataSection(
3063160a544SSumit Kumar         const DataInterfaceBase& dataIface);
3073160a544SSumit Kumar 
3088e65f4eaSMatt Spinler     /**
3098e65f4eaSMatt Spinler      * @brief Return the deconfig flag from hex data word 5 of BMC and
3108e65f4eaSMatt Spinler      *        hostboot PELs.
3118e65f4eaSMatt Spinler      *
3128e65f4eaSMatt Spinler      * This only applies to BMC and hostboot PELs because only those
3138e65f4eaSMatt Spinler      * SRC formats have this flag defined.
3148e65f4eaSMatt Spinler      *
3158e65f4eaSMatt Spinler      * @return bool - If the 'one or more resources are deconfigured'
3168e65f4eaSMatt Spinler      *                flag is set.
3178e65f4eaSMatt Spinler      */
3188e65f4eaSMatt Spinler     bool getDeconfigFlag() const;
3198e65f4eaSMatt Spinler 
3208e65f4eaSMatt Spinler     /**
3218e65f4eaSMatt Spinler      * @brief Return the guard flag from hex data word 5 of BMC and
3228e65f4eaSMatt Spinler      *        hostboot PELs.
3238e65f4eaSMatt Spinler      *
3248e65f4eaSMatt Spinler      * This only applies to BMC and hostboot PELs because only those
3258e65f4eaSMatt Spinler      * SRC formats have this flag defined.
3268e65f4eaSMatt Spinler      *
3278e65f4eaSMatt Spinler      * @return bool - If the 'one or more resources are guarded'
3288e65f4eaSMatt Spinler      *                flag is set.
3298e65f4eaSMatt Spinler      */
3308e65f4eaSMatt Spinler     bool getGuardFlag() const;
3318e65f4eaSMatt Spinler 
332cb6b059eSMatt Spinler   private:
333cb6b059eSMatt Spinler     /**
334cb6b059eSMatt Spinler      * @brief Builds the section objects from a PEL data buffer
335cb6b059eSMatt Spinler      *
33607eefc54SMatt Spinler      * Note: The data parameter cannot be const for the same reasons
33707eefc54SMatt Spinler      * as listed in the constructor.
33807eefc54SMatt Spinler      *
33907eefc54SMatt Spinler      * @param[in] data - The PEL data
340cb6b059eSMatt Spinler      * @param[in] obmcLogID - The OpenBMC event log ID to use for that
341cb6b059eSMatt Spinler      *                        field in the Private Header.
342cb6b059eSMatt Spinler      */
34307eefc54SMatt Spinler     void populateFromRawData(std::vector<uint8_t>& data, uint32_t obmcLogID);
344cb6b059eSMatt Spinler 
345cb6b059eSMatt Spinler     /**
346cb6b059eSMatt Spinler      * @brief Flattens the PEL objects into the buffer
347cb6b059eSMatt Spinler      *
348cb6b059eSMatt Spinler      * @param[out] pelBuffer - What the data will be written to
349cb6b059eSMatt Spinler      */
3500688545bSMatt Spinler     void flatten(std::vector<uint8_t>& pelBuffer) const;
351cb6b059eSMatt Spinler 
352cb6b059eSMatt Spinler     /**
353f1e85e20SMatt Spinler      * @brief Check that the PEL fields that need to be in agreement
354f1e85e20SMatt Spinler      *        with each other are, and fix them up if necessary.
355f1e85e20SMatt Spinler      */
356f1e85e20SMatt Spinler     void checkRulesAndFix();
357f1e85e20SMatt Spinler 
358f1e85e20SMatt Spinler     /**
359acb7c106SMatt Spinler      * @brief Returns a map of the section IDs that appear more than once
360acb7c106SMatt Spinler      *        in the PEL.  The data value for each entry will be set to 0.
361acb7c106SMatt Spinler      *
362acb7c106SMatt Spinler      * @return std::map<uint16_t, size_t>
363acb7c106SMatt Spinler      */
364acb7c106SMatt Spinler     std::map<uint16_t, size_t> getPluralSections() const;
365acb7c106SMatt Spinler 
366acb7c106SMatt Spinler     /**
36785f61a63SMatt Spinler      * @brief Adds the UserData section to this PEL object,
36885f61a63SMatt Spinler      *        shrinking it if necessary
36985f61a63SMatt Spinler      *
37085f61a63SMatt Spinler      * @param[in] userData - The section to add
37185f61a63SMatt Spinler      *
37285f61a63SMatt Spinler      * @return bool - If the section was added or not.
37385f61a63SMatt Spinler      */
37485f61a63SMatt Spinler     bool addUserDataSection(std::unique_ptr<UserData> userData);
37585f61a63SMatt Spinler 
37685f61a63SMatt Spinler     /**
37785f61a63SMatt Spinler      * @brief helper function for printing PELs.
37885f61a63SMatt Spinler      * @param[in] Section& - section object reference
37985f61a63SMatt Spinler      * @param[in] std::string - PEL string
38085f61a63SMatt Spinler      * @param[in|out] pluralSections - Map used to track sections counts for
38185f61a63SMatt Spinler      *                                 when there is more than 1.
38285f61a63SMatt Spinler      * @param[in] registry - Registry object reference
383f67bafd0SHarisuddin Mohamed Isa      * @param[in] plugins - Vector of strings of plugins found in filesystem
384f67bafd0SHarisuddin Mohamed Isa      * @param[in] creatorID - Creator Subsystem ID (only for UserData section)
38585f61a63SMatt Spinler      */
386075c7923SPatrick Williams     void printSectionInJSON(
387075c7923SPatrick Williams         const Section& section, std::string& buf,
388075c7923SPatrick Williams         std::map<uint16_t, size_t>& pluralSections, message::Registry& registry,
389075c7923SPatrick Williams         const std::vector<std::string>& plugins, uint8_t creatorID = 0) const;
39085f61a63SMatt Spinler 
39185f61a63SMatt Spinler     /**
3925a90a95bSMatt Spinler      * @brief Returns any callout JSON found in the FFDC files.
3935a90a95bSMatt Spinler      *
3945a90a95bSMatt Spinler      * Looks for an FFDC file that is JSON format and has the
3955a90a95bSMatt Spinler      * sub-type value set to 0xCA and returns its data as a JSON object.
3965a90a95bSMatt Spinler      *
3975a90a95bSMatt Spinler      * @param[in] ffdcFiles - FFCD files that go into UserData sections
3985a90a95bSMatt Spinler      *
3995a90a95bSMatt Spinler      * @return json - The callout JSON, or an empty object if not found
4005a90a95bSMatt Spinler      */
4015a90a95bSMatt Spinler     nlohmann::json getCalloutJSON(const PelFFDC& ffdcFiles);
4025a90a95bSMatt Spinler 
4035a90a95bSMatt Spinler     /**
4043e274432SSumit Kumar      * @brief Update terminate bit in primary SRC section to this PEL object is
4053e274432SSumit Kumar      * severity set to 0x51 = critical error, system termination
4063e274432SSumit Kumar      */
4073e274432SSumit Kumar     void updateTerminateBitInSRCSection();
4083e274432SSumit Kumar 
4093e274432SSumit Kumar     /**
4109d921096SMatt Spinler      * @brief Adds journal data to the PEL as UserData sections
4119d921096SMatt Spinler      *        if specified to in the message registry.
4129d921096SMatt Spinler      *
4139d921096SMatt Spinler      * @param regEntry - The registry entry
4149d921096SMatt Spinler      * @param journal - The journal object
4159d921096SMatt Spinler      */
4169d921096SMatt Spinler     void addJournalSections(const message::Entry& regEntry,
4179d921096SMatt Spinler                             const JournalBase& journal);
4189d921096SMatt Spinler 
4199d921096SMatt Spinler     /**
420*d8ae618aSArya K Padman      * @brief API to collect the addditional details of the DIMM callouts in
421*d8ae618aSArya K Padman      * the PEL as a JSON object in adSysInfoData.
422*d8ae618aSArya K Padman      *
423*d8ae618aSArya K Padman      * @param[in] src - Unique pointer to the SRC object
424*d8ae618aSArya K Padman      * @param[in] dataIface - The data interface object
425*d8ae618aSArya K Padman      * @param[out] adSysInfoData - The additional data to SysInfo in json format
426*d8ae618aSArya K Padman      * @param[out] debugData - The map of string and vector of string to store
427*d8ae618aSArya K Padman      * the debug data if any.
428*d8ae618aSArya K Padman      */
429*d8ae618aSArya K Padman     void addAdDetailsForDIMMsCallout(
430*d8ae618aSArya K Padman         const std::unique_ptr<SRC>& src, const DataInterfaceBase& dataIface,
431*d8ae618aSArya K Padman         nlohmann::json& adSysInfoData, DebugData& debugData);
432*d8ae618aSArya K Padman 
433*d8ae618aSArya K Padman     /**
434cb6b059eSMatt Spinler      * @brief The PEL Private Header section
435cb6b059eSMatt Spinler      */
436cb6b059eSMatt Spinler     std::unique_ptr<PrivateHeader> _ph;
437cb6b059eSMatt Spinler 
438cb6b059eSMatt Spinler     /**
439cb6b059eSMatt Spinler      * @brief The PEL User Header section
440cb6b059eSMatt Spinler      */
441cb6b059eSMatt Spinler     std::unique_ptr<UserHeader> _uh;
442cb6b059eSMatt Spinler 
443cb6b059eSMatt Spinler     /**
444131870c7SMatt Spinler      * @brief Holds all sections by the PH and UH.
445131870c7SMatt Spinler      */
446131870c7SMatt Spinler     std::vector<std::unique_ptr<Section>> _optionalSections;
447186ce8c9SAatir 
448186ce8c9SAatir     /**
4496d663820SMatt Spinler      * @brief The maximum size a PEL can be in bytes.
4506d663820SMatt Spinler      */
4516d663820SMatt Spinler     static constexpr size_t _maxPELSize = 16384;
452cb6b059eSMatt Spinler };
453cb6b059eSMatt Spinler 
454afa857c7SMatt Spinler namespace util
455afa857c7SMatt Spinler {
456afa857c7SMatt Spinler 
457afa857c7SMatt Spinler /**
45885f61a63SMatt Spinler  * @brief Creates a UserData section object that contains JSON.
45985f61a63SMatt Spinler  *
46085f61a63SMatt Spinler  * @param[in] json - The JSON contents
46185f61a63SMatt Spinler  *
46285f61a63SMatt Spinler  * @return std::unique_ptr<UserData> - The UserData object
46385f61a63SMatt Spinler  */
46485f61a63SMatt Spinler std::unique_ptr<UserData> makeJSONUserDataSection(const nlohmann::json& json);
46585f61a63SMatt Spinler 
46685f61a63SMatt Spinler /**
467afa857c7SMatt Spinler  * @brief Create a UserData section containing the AdditionalData
468afa857c7SMatt Spinler  *        contents as a JSON string.
469afa857c7SMatt Spinler  *
470afa857c7SMatt Spinler  * @param[in] ad - The AdditionalData contents
471afa857c7SMatt Spinler  *
472afa857c7SMatt Spinler  * @return std::unique_ptr<UserData> - The section
473afa857c7SMatt Spinler  */
474afa857c7SMatt Spinler std::unique_ptr<UserData> makeADUserDataSection(const AdditionalData& ad);
475afa857c7SMatt Spinler 
4764dcd3f46SMatt Spinler /**
4774dcd3f46SMatt Spinler  * @brief Create a UserData section containing various useful pieces
4784dcd3f46SMatt Spinler  *        of system information as a JSON string.
4794dcd3f46SMatt Spinler  *
4804dcd3f46SMatt Spinler  * @param[in] ad - The AdditionalData contents
4814dcd3f46SMatt Spinler  * @param[in] dataIface - The data interface object
4829ac0d9b8SGeorge Liu  * @param[in] addUptime - Whether to add the uptime attribute the default is
4839ac0d9b8SGeorge Liu  *                        true
484*d8ae618aSArya K Padman  * @param[in] adSysInfoData - The additional data to SysInfo in json format.
485*d8ae618aSArya K Padman  *                            Default value will be empty.
4864dcd3f46SMatt Spinler  *
4874dcd3f46SMatt Spinler  * @return std::unique_ptr<UserData> - The section
4884dcd3f46SMatt Spinler  */
489075c7923SPatrick Williams std::unique_ptr<UserData> makeSysInfoUserDataSection(
490075c7923SPatrick Williams     const AdditionalData& ad, const DataInterfaceBase& dataIface,
491*d8ae618aSArya K Padman     bool addUptime = true,
492*d8ae618aSArya K Padman     const nlohmann::json& adSysInfoData =
493*d8ae618aSArya K Padman         nlohmann::json(nlohmann::json::value_t::object));
49456ad2a0eSMatt Spinler 
49556ad2a0eSMatt Spinler /**
4965a90a95bSMatt Spinler  * @brief Reads data from an opened file descriptor.
4975a90a95bSMatt Spinler  *
4985a90a95bSMatt Spinler  * @param[in] fd - The FD to read from
4995a90a95bSMatt Spinler  *
5005a90a95bSMatt Spinler  * @return std::vector<uint8_t> - The data read
5015a90a95bSMatt Spinler  */
5025a90a95bSMatt Spinler std::vector<uint8_t> readFD(int fd);
5035a90a95bSMatt Spinler 
5045a90a95bSMatt Spinler /**
50556ad2a0eSMatt Spinler  * @brief Create a UserData section that contains the data in the file
50656ad2a0eSMatt Spinler  *        pointed to by the file descriptor passed in.
50756ad2a0eSMatt Spinler  *
50856ad2a0eSMatt Spinler  * @param[in] componentID - The component ID of the PEL creator
50956ad2a0eSMatt Spinler  * @param[in] file - The FFDC file information
51056ad2a0eSMatt Spinler  */
511075c7923SPatrick Williams std::unique_ptr<UserData>
512075c7923SPatrick Williams     makeFFDCuserDataSection(uint16_t componentID, const PelFFDCfile& file);
5139d921096SMatt Spinler 
5149d921096SMatt Spinler /**
515*d8ae618aSArya K Padman  * @brief To create JSON object with the given location code and the hex
516*d8ae618aSArya K Padman  * converted value of the given DI property.
517*d8ae618aSArya K Padman  *
518*d8ae618aSArya K Padman  * @param[in] locationCode - The location code of the DIMM
519*d8ae618aSArya K Padman  * @param[in] diPropVal - The DI property value of the DIMM
520*d8ae618aSArya K Padman  * @param[out] adSysInfoData - Holds the created JSON object
521*d8ae618aSArya K Padman  */
522*d8ae618aSArya K Padman 
523*d8ae618aSArya K Padman void addDIMMInfo(const std::string& locationCode,
524*d8ae618aSArya K Padman                  const std::vector<std::uint8_t>& diPropVal,
525*d8ae618aSArya K Padman                  nlohmann::json& adSysInfoData);
526*d8ae618aSArya K Padman 
527*d8ae618aSArya K Padman /**
5289d921096SMatt Spinler  * @brief Flattens a vector of strings into a vector of bytes suitable
5299d921096SMatt Spinler  *        for storing in a PEL section.
5309d921096SMatt Spinler  *
5319d921096SMatt Spinler  * Adds a newline character after each string.
5329d921096SMatt Spinler  *
5339d921096SMatt Spinler  * @param lines - The vector of strings to convert
5349d921096SMatt Spinler  *
5359d921096SMatt Spinler  * @return std::vector<uint8_t> - The flattened data
5369d921096SMatt Spinler  */
5379d921096SMatt Spinler std::vector<uint8_t> flattenLines(const std::vector<std::string>& lines);
5389d921096SMatt Spinler 
539afa857c7SMatt Spinler } // namespace util
540afa857c7SMatt Spinler 
541cb6b059eSMatt Spinler } // namespace pels
542cb6b059eSMatt Spinler } // namespace openpower
543