1cb6b059eSMatt Spinler #pragma once
2cb6b059eSMatt Spinler 
3b832363dSMatt Spinler #include "additional_data.hpp"
4aa659477SMatt Spinler #include "data_interface.hpp"
5cb6b059eSMatt Spinler #include "private_header.hpp"
6b832363dSMatt Spinler #include "registry.hpp"
7bd716f00SMatt Spinler #include "src.hpp"
8afa857c7SMatt Spinler #include "user_data.hpp"
956ad2a0eSMatt Spinler #include "user_data_formats.hpp"
10cb6b059eSMatt Spinler #include "user_header.hpp"
11cb6b059eSMatt Spinler 
12cb6b059eSMatt Spinler #include <memory>
13cb6b059eSMatt Spinler #include <vector>
14cb6b059eSMatt Spinler 
15cb6b059eSMatt Spinler namespace openpower
16cb6b059eSMatt Spinler {
17cb6b059eSMatt Spinler namespace pels
18cb6b059eSMatt Spinler {
19cb6b059eSMatt Spinler 
2056ad2a0eSMatt Spinler /**
2156ad2a0eSMatt Spinler  * @brief Contains information about an FFDC file.
2256ad2a0eSMatt Spinler  */
2356ad2a0eSMatt Spinler struct PelFFDCfile
2456ad2a0eSMatt Spinler {
2556ad2a0eSMatt Spinler     UserDataFormat format;
2656ad2a0eSMatt Spinler     uint8_t subType;
2756ad2a0eSMatt Spinler     uint8_t version;
2856ad2a0eSMatt Spinler     int fd;
2956ad2a0eSMatt Spinler };
3056ad2a0eSMatt Spinler 
3156ad2a0eSMatt Spinler using PelFFDC = std::vector<PelFFDCfile>;
3256ad2a0eSMatt Spinler 
331ddf1e8eSJayanth Othayoth constexpr uint8_t jsonCalloutSubtype = 0xCA;
341ddf1e8eSJayanth Othayoth 
35cb6b059eSMatt Spinler /** @class PEL
36cb6b059eSMatt Spinler  *
37cb6b059eSMatt Spinler  * @brief This class represents a specific event log format referred to as a
38cb6b059eSMatt Spinler  * Platform Event Log.
39cb6b059eSMatt Spinler  *
40cb6b059eSMatt Spinler  * Every field in a PEL are in structures call sections, of which there are
41cb6b059eSMatt Spinler  * several types.  Some sections are required, and some are optional.  In some
42cb6b059eSMatt Spinler  * cases there may be more than one instance of a section type.
43cb6b059eSMatt Spinler  *
44cb6b059eSMatt Spinler  * The only two required sections for every type of PEL are the Private Header
45cb6b059eSMatt Spinler  * section and User Header section, which must be in the first and second
46cb6b059eSMatt Spinler  * positions, respectively.
47cb6b059eSMatt Spinler  *
48cb6b059eSMatt Spinler  * Every section starts with an 8 byte section header, which has the section
49cb6b059eSMatt Spinler  * size and type, among other things.
50cb6b059eSMatt Spinler  *
51cb6b059eSMatt Spinler  * This class represents all sections with objects.
52cb6b059eSMatt Spinler  *
53bd716f00SMatt Spinler  * The class can be constructed:
54bd716f00SMatt Spinler  * - From a full formed flattened PEL.
55bd716f00SMatt Spinler  * - From scratch based on an OpenBMC event and its corresponding PEL message
56bd716f00SMatt Spinler  *   registry entry.
57b832363dSMatt Spinler  *
58cb6b059eSMatt Spinler  * The data() method allows one to retrieve the PEL as a vector<uint8_t>.  This
59cb6b059eSMatt Spinler  * is the format in which it is stored and transmitted.
60cb6b059eSMatt Spinler  */
61cb6b059eSMatt Spinler class PEL
62cb6b059eSMatt Spinler {
63cb6b059eSMatt Spinler   public:
64cb6b059eSMatt Spinler     PEL() = delete;
65cb6b059eSMatt Spinler     ~PEL() = default;
66cb6b059eSMatt Spinler     PEL(const PEL&) = delete;
67cb6b059eSMatt Spinler     PEL& operator=(const PEL&) = delete;
68cb6b059eSMatt Spinler     PEL(PEL&&) = delete;
69cb6b059eSMatt Spinler     PEL& operator=(PEL&&) = delete;
70cb6b059eSMatt Spinler 
71cb6b059eSMatt Spinler     /**
72cb6b059eSMatt Spinler      * @brief Constructor
73cb6b059eSMatt Spinler      *
74cb6b059eSMatt Spinler      * Build a PEL from raw data.
75cb6b059eSMatt Spinler      *
7607eefc54SMatt Spinler      * Note: Neither this nor the following constructor can take a const vector&
7707eefc54SMatt Spinler      * because the Stream class that is used to read from the vector cannot take
7807eefc54SMatt Spinler      * a const.  The alternative is to make a copy of the data, but as PELs can
7907eefc54SMatt Spinler      * be up to 16KB that is undesireable.
8007eefc54SMatt Spinler      *
81cb6b059eSMatt Spinler      * @param[in] data - The PEL data
82cb6b059eSMatt Spinler      */
8307eefc54SMatt Spinler     PEL(std::vector<uint8_t>& data);
84cb6b059eSMatt Spinler 
85cb6b059eSMatt Spinler     /**
86cb6b059eSMatt Spinler      * @brief Constructor
87cb6b059eSMatt Spinler      *
88cb6b059eSMatt Spinler      * Build a PEL from the raw data.
89cb6b059eSMatt Spinler      *
90cb6b059eSMatt Spinler      * @param[in] data - the PEL data
91cb6b059eSMatt Spinler      * @param[in] obmcLogID - the corresponding OpenBMC event log ID
92cb6b059eSMatt Spinler      */
9307eefc54SMatt Spinler     PEL(std::vector<uint8_t>& data, uint32_t obmcLogID);
94cb6b059eSMatt Spinler 
95cb6b059eSMatt Spinler     /**
96b832363dSMatt Spinler      * @brief Constructor
97b832363dSMatt Spinler      *
98b832363dSMatt Spinler      * Creates a PEL from an OpenBMC event log and its message
99b832363dSMatt Spinler      * registry entry.
100b832363dSMatt Spinler      *
101b832363dSMatt Spinler      * @param[in] entry - The message registry entry for this error
102b832363dSMatt Spinler      * @param[in] obmcLogID - ID of corresponding OpenBMC event log
103b832363dSMatt Spinler      * @param[in] timestamp - Timestamp from the event log
104b832363dSMatt Spinler      * @param[in] severity - Severity from the event log
105bd716f00SMatt Spinler      * @param[in] additionalData - The AdditionalData contents
10656ad2a0eSMatt Spinler      * @param[in] ffdcFiles - FFCD files that go into UserData sections
107aa659477SMatt Spinler      * @param[in] dataIface - The data interface object
108b832363dSMatt Spinler      */
109b832363dSMatt Spinler     PEL(const openpower::pels::message::Entry& entry, uint32_t obmcLogID,
110bd716f00SMatt Spinler         uint64_t timestamp, phosphor::logging::Entry::Level severity,
11156ad2a0eSMatt Spinler         const AdditionalData& additionalData, const PelFFDC& ffdcFiles,
112aa659477SMatt Spinler         const DataInterfaceBase& dataIface);
113b832363dSMatt Spinler 
114b832363dSMatt Spinler     /**
115cb6b059eSMatt Spinler      * @brief Convenience function to return the log ID field from the
116cb6b059eSMatt Spinler      *        Private Header section.
117cb6b059eSMatt Spinler      *
118cb6b059eSMatt Spinler      * @return uint32_t - the ID
119cb6b059eSMatt Spinler      */
120cb6b059eSMatt Spinler     uint32_t id() const
121cb6b059eSMatt Spinler     {
122cb6b059eSMatt Spinler         return _ph->id();
123cb6b059eSMatt Spinler     }
124cb6b059eSMatt Spinler 
125cb6b059eSMatt Spinler     /**
126cb6b059eSMatt Spinler      * @brief Convenience function to return the PLID field from the
127cb6b059eSMatt Spinler      *        Private Header section.
128cb6b059eSMatt Spinler      *
129cb6b059eSMatt Spinler      * @return uint32_t - the PLID
130cb6b059eSMatt Spinler      */
131cb6b059eSMatt Spinler     uint32_t plid() const
132cb6b059eSMatt Spinler     {
133cb6b059eSMatt Spinler         return _ph->plid();
134cb6b059eSMatt Spinler     }
135cb6b059eSMatt Spinler 
136cb6b059eSMatt Spinler     /**
137cb6b059eSMatt Spinler      * @brief Convenience function to return the OpenBMC event log ID field
138cb6b059eSMatt Spinler      * from the Private Header section.
139cb6b059eSMatt Spinler      *
140cb6b059eSMatt Spinler      * @return uint32_t - the OpenBMC event log ID
141cb6b059eSMatt Spinler      */
142cb6b059eSMatt Spinler     uint32_t obmcLogID() const
143cb6b059eSMatt Spinler     {
144cb6b059eSMatt Spinler         return _ph->obmcLogID();
145cb6b059eSMatt Spinler     }
146cb6b059eSMatt Spinler 
147cb6b059eSMatt Spinler     /**
148cb6b059eSMatt Spinler      * @brief Convenience function to return the commit time field from
149cb6b059eSMatt Spinler      *        the Private Header section.
150cb6b059eSMatt Spinler      *
151cb6b059eSMatt Spinler      * @return BCDTime - the timestamp
152cb6b059eSMatt Spinler      */
153cb6b059eSMatt Spinler     BCDTime commitTime() const
154cb6b059eSMatt Spinler     {
155cb6b059eSMatt Spinler         return _ph->commitTimestamp();
156cb6b059eSMatt Spinler     }
157cb6b059eSMatt Spinler 
158cb6b059eSMatt Spinler     /**
159cb6b059eSMatt Spinler      * @brief Convenience function to return the create time field from
160cb6b059eSMatt Spinler      *        the Private Header section.
161cb6b059eSMatt Spinler      *
162cb6b059eSMatt Spinler      * @return BCDTime - the timestamp
163cb6b059eSMatt Spinler      */
164cb6b059eSMatt Spinler     BCDTime createTime() const
165cb6b059eSMatt Spinler     {
166cb6b059eSMatt Spinler         return _ph->createTimestamp();
167cb6b059eSMatt Spinler     }
168cb6b059eSMatt Spinler 
169cb6b059eSMatt Spinler     /**
170cb6b059eSMatt Spinler      * @brief Gives access to the Private Header section class
171cb6b059eSMatt Spinler      *
17297d19b48SMatt Spinler      * @return const PrivateHeader& - the private header
173cb6b059eSMatt Spinler      */
17497d19b48SMatt Spinler     const PrivateHeader& privateHeader() const
175cb6b059eSMatt Spinler     {
17697d19b48SMatt Spinler         return *_ph;
177cb6b059eSMatt Spinler     }
178cb6b059eSMatt Spinler 
179cb6b059eSMatt Spinler     /**
180cb6b059eSMatt Spinler      * @brief Gives access to the User Header section class
181cb6b059eSMatt Spinler      *
18297d19b48SMatt Spinler      * @return const UserHeader& - the user header
183cb6b059eSMatt Spinler      */
18497d19b48SMatt Spinler     const UserHeader& userHeader() const
185cb6b059eSMatt Spinler     {
18697d19b48SMatt Spinler         return *_uh;
187cb6b059eSMatt Spinler     }
188cb6b059eSMatt Spinler 
189cb6b059eSMatt Spinler     /**
190bd716f00SMatt Spinler      * @brief Gives access to the primary SRC's section class
191bd716f00SMatt Spinler      *
192bd716f00SMatt Spinler      * This is technically an optional section, so the return
193bd716f00SMatt Spinler      * value is an std::optional<SRC*>.
194bd716f00SMatt Spinler      *
195bd716f00SMatt Spinler      * @return std::optional<SRC*> - the SRC section object
196bd716f00SMatt Spinler      */
197bd716f00SMatt Spinler     std::optional<SRC*> primarySRC() const;
198bd716f00SMatt Spinler 
199bd716f00SMatt Spinler     /**
200131870c7SMatt Spinler      * @brief Returns the optional sections, which is everything but
201131870c7SMatt Spinler      *        the Private and User Headers.
202131870c7SMatt Spinler      *
203131870c7SMatt Spinler      * @return const std::vector<std::unique_ptr<Section>>&
204131870c7SMatt Spinler      */
205131870c7SMatt Spinler     const std::vector<std::unique_ptr<Section>>& optionalSections() const
206131870c7SMatt Spinler     {
207131870c7SMatt Spinler         return _optionalSections;
208131870c7SMatt Spinler     }
209131870c7SMatt Spinler 
210131870c7SMatt Spinler     /**
211cb6b059eSMatt Spinler      * @brief Returns the PEL data.
212cb6b059eSMatt Spinler      *
213cb6b059eSMatt Spinler      * @return std::vector<uint8_t> - the raw PEL data
214cb6b059eSMatt Spinler      */
2150688545bSMatt Spinler     std::vector<uint8_t> data() const;
216cb6b059eSMatt Spinler 
217cb6b059eSMatt Spinler     /**
218f1b46ff4SMatt Spinler      * @brief Returns the size of the PEL
219f1b46ff4SMatt Spinler      *
220f1b46ff4SMatt Spinler      * @return size_t The PEL size in bytes
221f1b46ff4SMatt Spinler      */
222f1b46ff4SMatt Spinler     size_t size() const;
223f1b46ff4SMatt Spinler 
224f1b46ff4SMatt Spinler     /**
225cb6b059eSMatt Spinler      * @brief Says if the PEL is valid (the sections are all valid)
226cb6b059eSMatt Spinler      *
227cb6b059eSMatt Spinler      * @return bool - if the PEL is valid
228cb6b059eSMatt Spinler      */
229cb6b059eSMatt Spinler     bool valid() const;
230cb6b059eSMatt Spinler 
231cb6b059eSMatt Spinler     /**
232cb6b059eSMatt Spinler      * @brief Sets the commit timestamp to the current time
233cb6b059eSMatt Spinler      */
234cb6b059eSMatt Spinler     void setCommitTime();
235cb6b059eSMatt Spinler 
236cb6b059eSMatt Spinler     /**
237cb6b059eSMatt Spinler      * @brief Sets the error log ID field to a unique ID.
238cb6b059eSMatt Spinler      */
239cb6b059eSMatt Spinler     void assignID();
240cb6b059eSMatt Spinler 
241186ce8c9SAatir     /**
242186ce8c9SAatir      * @brief Output a PEL in JSON.
243a214ed30SHarisuddin Mohamed Isa      * @param[in] registry - Registry object reference
244f67bafd0SHarisuddin Mohamed Isa      * @param[in] plugins - Vector of strings of plugins found in filesystem
245186ce8c9SAatir      */
246f67bafd0SHarisuddin Mohamed Isa     void toJSON(message::Registry& registry,
247f67bafd0SHarisuddin Mohamed Isa                 const std::vector<std::string>& plugins) const;
248186ce8c9SAatir 
249f38ce984SMatt Spinler     /**
250f38ce984SMatt Spinler      * @brief Sets the host transmission state in the User Header
251f38ce984SMatt Spinler      *
252f38ce984SMatt Spinler      * @param[in] state - The state value
253f38ce984SMatt Spinler      */
254f38ce984SMatt Spinler     void setHostTransmissionState(TransmissionState state)
255f38ce984SMatt Spinler     {
256f38ce984SMatt Spinler         _uh->setHostTransmissionState(static_cast<uint8_t>(state));
257f38ce984SMatt Spinler     }
258f38ce984SMatt Spinler 
259f38ce984SMatt Spinler     /**
260f38ce984SMatt Spinler      * @brief Returns the host transmission state
261f38ce984SMatt Spinler      *
262f38ce984SMatt Spinler      * @return HostTransmissionState - The state
263f38ce984SMatt Spinler      */
264f38ce984SMatt Spinler     TransmissionState hostTransmissionState() const
265f38ce984SMatt Spinler     {
266f38ce984SMatt Spinler         return static_cast<TransmissionState>(_uh->hostTransmissionState());
267f38ce984SMatt Spinler     }
268f38ce984SMatt Spinler 
269f38ce984SMatt Spinler     /**
270f38ce984SMatt Spinler      * @brief Sets the HMC transmission state in the User Header
271f38ce984SMatt Spinler      *
272f38ce984SMatt Spinler      * @param[in] state - The state value
273f38ce984SMatt Spinler      */
274f38ce984SMatt Spinler     void setHMCTransmissionState(TransmissionState state)
275f38ce984SMatt Spinler     {
276f38ce984SMatt Spinler         _uh->setHMCTransmissionState(static_cast<uint8_t>(state));
277f38ce984SMatt Spinler     }
278f38ce984SMatt Spinler 
279f38ce984SMatt Spinler     /**
280f38ce984SMatt Spinler      * @brief Returns the HMC transmission state
281f38ce984SMatt Spinler      *
282f38ce984SMatt Spinler      * @return HMCTransmissionState - The state
283f38ce984SMatt Spinler      */
284f38ce984SMatt Spinler     TransmissionState hmcTransmissionState() const
285f38ce984SMatt Spinler     {
286f38ce984SMatt Spinler         return static_cast<TransmissionState>(_uh->hmcTransmissionState());
287f38ce984SMatt Spinler     }
288f38ce984SMatt Spinler 
28944fc3168SAndrew Geissler     /**
29044fc3168SAndrew Geissler      * @brief Returns true if any callout is present in the primary SRC
29144fc3168SAndrew Geissler      *
29244fc3168SAndrew Geissler      * @return true if callout present, false otherwise
29344fc3168SAndrew Geissler      */
29444fc3168SAndrew Geissler     bool isCalloutPresent() const;
29544fc3168SAndrew Geissler 
2963160a544SSumit Kumar     /**
2973160a544SSumit Kumar      * @brief Updates the system info data into HB extended user
2983160a544SSumit Kumar      *        data section to this PEL object
2993160a544SSumit Kumar      *
3003160a544SSumit Kumar      * @param[in] dataIface - The data interface object
3013160a544SSumit Kumar      */
3023160a544SSumit Kumar     void updateSysInfoInExtendedUserDataSection(
3033160a544SSumit Kumar         const DataInterfaceBase& dataIface);
3043160a544SSumit Kumar 
305cb6b059eSMatt Spinler   private:
306cb6b059eSMatt Spinler     /**
307cb6b059eSMatt Spinler      * @brief Builds the section objects from a PEL data buffer
308cb6b059eSMatt Spinler      *
30907eefc54SMatt Spinler      * Note: The data parameter cannot be const for the same reasons
31007eefc54SMatt Spinler      * as listed in the constructor.
31107eefc54SMatt Spinler      *
31207eefc54SMatt Spinler      * @param[in] data - The PEL data
313cb6b059eSMatt Spinler      * @param[in] obmcLogID - The OpenBMC event log ID to use for that
314cb6b059eSMatt Spinler      *                        field in the Private Header.
315cb6b059eSMatt Spinler      */
31607eefc54SMatt Spinler     void populateFromRawData(std::vector<uint8_t>& data, uint32_t obmcLogID);
317cb6b059eSMatt Spinler 
318cb6b059eSMatt Spinler     /**
319cb6b059eSMatt Spinler      * @brief Flattens the PEL objects into the buffer
320cb6b059eSMatt Spinler      *
321cb6b059eSMatt Spinler      * @param[out] pelBuffer - What the data will be written to
322cb6b059eSMatt Spinler      */
3230688545bSMatt Spinler     void flatten(std::vector<uint8_t>& pelBuffer) const;
324cb6b059eSMatt Spinler 
325cb6b059eSMatt Spinler     /**
326f1e85e20SMatt Spinler      * @brief Check that the PEL fields that need to be in agreement
327f1e85e20SMatt Spinler      *        with each other are, and fix them up if necessary.
328f1e85e20SMatt Spinler      */
329f1e85e20SMatt Spinler     void checkRulesAndFix();
330f1e85e20SMatt Spinler 
331f1e85e20SMatt Spinler     /**
332acb7c106SMatt Spinler      * @brief Returns a map of the section IDs that appear more than once
333acb7c106SMatt Spinler      *        in the PEL.  The data value for each entry will be set to 0.
334acb7c106SMatt Spinler      *
335acb7c106SMatt Spinler      * @return std::map<uint16_t, size_t>
336acb7c106SMatt Spinler      */
337acb7c106SMatt Spinler     std::map<uint16_t, size_t> getPluralSections() const;
338acb7c106SMatt Spinler 
339acb7c106SMatt Spinler     /**
34085f61a63SMatt Spinler      * @brief Adds the UserData section to this PEL object,
34185f61a63SMatt Spinler      *        shrinking it if necessary
34285f61a63SMatt Spinler      *
34385f61a63SMatt Spinler      * @param[in] userData - The section to add
34485f61a63SMatt Spinler      *
34585f61a63SMatt Spinler      * @return bool - If the section was added or not.
34685f61a63SMatt Spinler      */
34785f61a63SMatt Spinler     bool addUserDataSection(std::unique_ptr<UserData> userData);
34885f61a63SMatt Spinler 
34985f61a63SMatt Spinler     /**
35085f61a63SMatt Spinler      * @brief helper function for printing PELs.
35185f61a63SMatt Spinler      * @param[in] Section& - section object reference
35285f61a63SMatt Spinler      * @param[in] std::string - PEL string
35385f61a63SMatt Spinler      * @param[in|out] pluralSections - Map used to track sections counts for
35485f61a63SMatt Spinler      *                                 when there is more than 1.
35585f61a63SMatt Spinler      * @param[in] registry - Registry object reference
356f67bafd0SHarisuddin Mohamed Isa      * @param[in] plugins - Vector of strings of plugins found in filesystem
357f67bafd0SHarisuddin Mohamed Isa      * @param[in] creatorID - Creator Subsystem ID (only for UserData section)
35885f61a63SMatt Spinler      */
35985f61a63SMatt Spinler     void printSectionInJSON(const Section& section, std::string& buf,
36085f61a63SMatt Spinler                             std::map<uint16_t, size_t>& pluralSections,
361f67bafd0SHarisuddin Mohamed Isa                             message::Registry& registry,
362f67bafd0SHarisuddin Mohamed Isa                             const std::vector<std::string>& plugins,
363f67bafd0SHarisuddin Mohamed Isa                             uint8_t creatorID = 0) const;
36485f61a63SMatt Spinler 
36585f61a63SMatt Spinler     /**
3665a90a95bSMatt Spinler      * @brief Returns any callout JSON found in the FFDC files.
3675a90a95bSMatt Spinler      *
3685a90a95bSMatt Spinler      * Looks for an FFDC file that is JSON format and has the
3695a90a95bSMatt Spinler      * sub-type value set to 0xCA and returns its data as a JSON object.
3705a90a95bSMatt Spinler      *
3715a90a95bSMatt Spinler      * @param[in] ffdcFiles - FFCD files that go into UserData sections
3725a90a95bSMatt Spinler      *
3735a90a95bSMatt Spinler      * @return json - The callout JSON, or an empty object if not found
3745a90a95bSMatt Spinler      */
3755a90a95bSMatt Spinler     nlohmann::json getCalloutJSON(const PelFFDC& ffdcFiles);
3765a90a95bSMatt Spinler 
3775a90a95bSMatt Spinler     /**
378*3e274432SSumit Kumar      * @brief Update terminate bit in primary SRC section to this PEL object is
379*3e274432SSumit Kumar      * severity set to 0x51 = critical error, system termination
380*3e274432SSumit Kumar      */
381*3e274432SSumit Kumar     void updateTerminateBitInSRCSection();
382*3e274432SSumit Kumar 
383*3e274432SSumit Kumar     /**
384cb6b059eSMatt Spinler      * @brief The PEL Private Header section
385cb6b059eSMatt Spinler      */
386cb6b059eSMatt Spinler     std::unique_ptr<PrivateHeader> _ph;
387cb6b059eSMatt Spinler 
388cb6b059eSMatt Spinler     /**
389cb6b059eSMatt Spinler      * @brief The PEL User Header section
390cb6b059eSMatt Spinler      */
391cb6b059eSMatt Spinler     std::unique_ptr<UserHeader> _uh;
392cb6b059eSMatt Spinler 
393cb6b059eSMatt Spinler     /**
394131870c7SMatt Spinler      * @brief Holds all sections by the PH and UH.
395131870c7SMatt Spinler      */
396131870c7SMatt Spinler     std::vector<std::unique_ptr<Section>> _optionalSections;
397186ce8c9SAatir 
398186ce8c9SAatir     /**
3996d663820SMatt Spinler      * @brief The maximum size a PEL can be in bytes.
4006d663820SMatt Spinler      */
4016d663820SMatt Spinler     static constexpr size_t _maxPELSize = 16384;
402cb6b059eSMatt Spinler };
403cb6b059eSMatt Spinler 
404afa857c7SMatt Spinler namespace util
405afa857c7SMatt Spinler {
406afa857c7SMatt Spinler 
407afa857c7SMatt Spinler /**
40885f61a63SMatt Spinler  * @brief Creates a UserData section object that contains JSON.
40985f61a63SMatt Spinler  *
41085f61a63SMatt Spinler  * @param[in] json - The JSON contents
41185f61a63SMatt Spinler  *
41285f61a63SMatt Spinler  * @return std::unique_ptr<UserData> - The UserData object
41385f61a63SMatt Spinler  */
41485f61a63SMatt Spinler std::unique_ptr<UserData> makeJSONUserDataSection(const nlohmann::json& json);
41585f61a63SMatt Spinler 
41685f61a63SMatt Spinler /**
417afa857c7SMatt Spinler  * @brief Create a UserData section containing the AdditionalData
418afa857c7SMatt Spinler  *        contents as a JSON string.
419afa857c7SMatt Spinler  *
420afa857c7SMatt Spinler  * @param[in] ad - The AdditionalData contents
421afa857c7SMatt Spinler  *
422afa857c7SMatt Spinler  * @return std::unique_ptr<UserData> - The section
423afa857c7SMatt Spinler  */
424afa857c7SMatt Spinler std::unique_ptr<UserData> makeADUserDataSection(const AdditionalData& ad);
425afa857c7SMatt Spinler 
4264dcd3f46SMatt Spinler /**
4274dcd3f46SMatt Spinler  * @brief Create a UserData section containing various useful pieces
4284dcd3f46SMatt Spinler  *        of system information as a JSON string.
4294dcd3f46SMatt Spinler  *
4304dcd3f46SMatt Spinler  * @param[in] ad - The AdditionalData contents
4314dcd3f46SMatt Spinler  * @param[in] dataIface - The data interface object
4324dcd3f46SMatt Spinler  *
4334dcd3f46SMatt Spinler  * @return std::unique_ptr<UserData> - The section
4344dcd3f46SMatt Spinler  */
4354dcd3f46SMatt Spinler std::unique_ptr<UserData>
4364dcd3f46SMatt Spinler     makeSysInfoUserDataSection(const AdditionalData& ad,
4374dcd3f46SMatt Spinler                                const DataInterfaceBase& dataIface);
43856ad2a0eSMatt Spinler 
43956ad2a0eSMatt Spinler /**
4405a90a95bSMatt Spinler  * @brief Reads data from an opened file descriptor.
4415a90a95bSMatt Spinler  *
4425a90a95bSMatt Spinler  * @param[in] fd - The FD to read from
4435a90a95bSMatt Spinler  *
4445a90a95bSMatt Spinler  * @return std::vector<uint8_t> - The data read
4455a90a95bSMatt Spinler  */
4465a90a95bSMatt Spinler std::vector<uint8_t> readFD(int fd);
4475a90a95bSMatt Spinler 
4485a90a95bSMatt Spinler /**
44956ad2a0eSMatt Spinler  * @brief Create a UserData section that contains the data in the file
45056ad2a0eSMatt Spinler  *        pointed to by the file descriptor passed in.
45156ad2a0eSMatt Spinler  *
45256ad2a0eSMatt Spinler  * @param[in] componentID - The component ID of the PEL creator
45356ad2a0eSMatt Spinler  * @param[in] file - The FFDC file information
45456ad2a0eSMatt Spinler  */
45556ad2a0eSMatt Spinler std::unique_ptr<UserData> makeFFDCuserDataSection(uint16_t componentID,
45656ad2a0eSMatt Spinler                                                   const PelFFDCfile& file);
457afa857c7SMatt Spinler } // namespace util
458afa857c7SMatt Spinler 
459cb6b059eSMatt Spinler } // namespace pels
460cb6b059eSMatt Spinler } // namespace openpower
461