xref: /openbmc/openpower-vpd-parser/vpd-manager/include/parser.hpp (revision fa5e4d325ef9cea3c841fe89d202c340f92bd8c6)
1*fa5e4d32SSunny Srivastava #pragma once
2*fa5e4d32SSunny Srivastava 
3*fa5e4d32SSunny Srivastava #include "parser_factory.hpp"
4*fa5e4d32SSunny Srivastava #include "parser_interface.hpp"
5*fa5e4d32SSunny Srivastava #include "types.hpp"
6*fa5e4d32SSunny Srivastava 
7*fa5e4d32SSunny Srivastava #include <string.h>
8*fa5e4d32SSunny Srivastava 
9*fa5e4d32SSunny Srivastava #include <nlohmann/json.hpp>
10*fa5e4d32SSunny Srivastava 
11*fa5e4d32SSunny Srivastava #include <iostream>
12*fa5e4d32SSunny Srivastava 
13*fa5e4d32SSunny Srivastava namespace vpd
14*fa5e4d32SSunny Srivastava {
15*fa5e4d32SSunny Srivastava /**
16*fa5e4d32SSunny Srivastava  * @brief Class to implement a wrapper around concrete parser class.
17*fa5e4d32SSunny Srivastava  * The class based on VPD file passed, selects the required parser and exposes
18*fa5e4d32SSunny Srivastava  * API to parse the VPD and return the parsed data in required format to the
19*fa5e4d32SSunny Srivastava  * caller.
20*fa5e4d32SSunny Srivastava  */
21*fa5e4d32SSunny Srivastava class Parser
22*fa5e4d32SSunny Srivastava {
23*fa5e4d32SSunny Srivastava   public:
24*fa5e4d32SSunny Srivastava     /**
25*fa5e4d32SSunny Srivastava      * @brief Constructor
26*fa5e4d32SSunny Srivastava      *
27*fa5e4d32SSunny Srivastava      * @param[in] vpdFilePath - Path to the VPD file.
28*fa5e4d32SSunny Srivastava      * @param[in] parsedJson - Parsed JSON.
29*fa5e4d32SSunny Srivastava      */
30*fa5e4d32SSunny Srivastava     Parser(const std::string& vpdFilePath, nlohmann::json parsedJson);
31*fa5e4d32SSunny Srivastava 
32*fa5e4d32SSunny Srivastava     /**
33*fa5e4d32SSunny Srivastava      * @brief API to implement a generic parsing logic.
34*fa5e4d32SSunny Srivastava      *
35*fa5e4d32SSunny Srivastava      * This API is called to select parser based on the vpd data extracted from
36*fa5e4d32SSunny Srivastava      * the VPD file path passed to the constructor of the class.
37*fa5e4d32SSunny Srivastava      * It further parses the data based on the parser selected and returned
38*fa5e4d32SSunny Srivastava      * parsed map to the caller.
39*fa5e4d32SSunny Srivastava      */
40*fa5e4d32SSunny Srivastava     types::VPDMapVariant parse();
41*fa5e4d32SSunny Srivastava 
42*fa5e4d32SSunny Srivastava     /**
43*fa5e4d32SSunny Srivastava      * @brief API to get parser instance based on VPD type.
44*fa5e4d32SSunny Srivastava      *
45*fa5e4d32SSunny Srivastava      * This API detects the VPD type based on the file path passed to the
46*fa5e4d32SSunny Srivastava      * constructor of the class and returns the respective parser instance.
47*fa5e4d32SSunny Srivastava      *
48*fa5e4d32SSunny Srivastava      * @return Parser instance.
49*fa5e4d32SSunny Srivastava      */
50*fa5e4d32SSunny Srivastava     std::shared_ptr<vpd::ParserInterface> getVpdParserInstance();
51*fa5e4d32SSunny Srivastava 
52*fa5e4d32SSunny Srivastava     /**
53*fa5e4d32SSunny Srivastava      * @brief Update keyword value.
54*fa5e4d32SSunny Srivastava      *
55*fa5e4d32SSunny Srivastava      * This API is used to update keyword value on the EEPROM path and its
56*fa5e4d32SSunny Srivastava      * redundant path(s) if any taken from system config JSON. And also updates
57*fa5e4d32SSunny Srivastava      * keyword value on DBus.
58*fa5e4d32SSunny Srivastava      *
59*fa5e4d32SSunny Srivastava      * To update IPZ type VPD, input parameter for writing should be in the form
60*fa5e4d32SSunny Srivastava      * of (Record, Keyword, Value). Eg: ("VINI", "SN", {0x01, 0x02, 0x03}).
61*fa5e4d32SSunny Srivastava      *
62*fa5e4d32SSunny Srivastava      * To update Keyword type VPD, input parameter for writing should be in the
63*fa5e4d32SSunny Srivastava      * form of (Keyword, Value). Eg: ("PE", {0x01, 0x02, 0x03}).
64*fa5e4d32SSunny Srivastava      *
65*fa5e4d32SSunny Srivastava      * @param[in] i_paramsToWriteData - Input details.
66*fa5e4d32SSunny Srivastava      *
67*fa5e4d32SSunny Srivastava      * @return On success returns number of bytes written, on failure returns
68*fa5e4d32SSunny Srivastava      * -1.
69*fa5e4d32SSunny Srivastava      */
70*fa5e4d32SSunny Srivastava     int updateVpdKeyword(const types::WriteVpdParams& i_paramsToWriteData);
71*fa5e4d32SSunny Srivastava 
72*fa5e4d32SSunny Srivastava     /**
73*fa5e4d32SSunny Srivastava      * @brief Update keyword value on hardware.
74*fa5e4d32SSunny Srivastava      *
75*fa5e4d32SSunny Srivastava      * This API is used to update keyword value on the hardware path.
76*fa5e4d32SSunny Srivastava      *
77*fa5e4d32SSunny Srivastava      * To update IPZ type VPD, input parameter for writing should be in the form
78*fa5e4d32SSunny Srivastava      * of (Record, Keyword, Value). Eg: ("VINI", "SN", {0x01, 0x02, 0x03}).
79*fa5e4d32SSunny Srivastava      *
80*fa5e4d32SSunny Srivastava      * To update Keyword type VPD, input parameter for writing should be in the
81*fa5e4d32SSunny Srivastava      * form of (Keyword, Value). Eg: ("PE", {0x01, 0x02, 0x03}).
82*fa5e4d32SSunny Srivastava      *
83*fa5e4d32SSunny Srivastava      * @param[in] i_paramsToWriteData - Input details.
84*fa5e4d32SSunny Srivastava      *
85*fa5e4d32SSunny Srivastava      * @return On success returns number of bytes written, on failure returns
86*fa5e4d32SSunny Srivastava      * -1.
87*fa5e4d32SSunny Srivastava      */
88*fa5e4d32SSunny Srivastava     int updateVpdKeywordOnHardware(
89*fa5e4d32SSunny Srivastava         const types::WriteVpdParams& i_paramsToWriteData);
90*fa5e4d32SSunny Srivastava 
91*fa5e4d32SSunny Srivastava   private:
92*fa5e4d32SSunny Srivastava     /**
93*fa5e4d32SSunny Srivastava      * @brief Update keyword value on redundant path.
94*fa5e4d32SSunny Srivastava      *
95*fa5e4d32SSunny Srivastava      * This API is used to update keyword value on the given redundant path(s).
96*fa5e4d32SSunny Srivastava      *
97*fa5e4d32SSunny Srivastava      * To update IPZ type VPD, input parameter for writing should be in the form
98*fa5e4d32SSunny Srivastava      * of (Record, Keyword, Value). Eg: ("VINI", "SN", {0x01, 0x02, 0x03}).
99*fa5e4d32SSunny Srivastava      *
100*fa5e4d32SSunny Srivastava      * To update Keyword type VPD, input parameter for writing should be in the
101*fa5e4d32SSunny Srivastava      * form of (Keyword, Value). Eg: ("PE", {0x01, 0x02, 0x03}).
102*fa5e4d32SSunny Srivastava      *
103*fa5e4d32SSunny Srivastava      * @param[in] i_fruPath - Redundant EEPROM path.
104*fa5e4d32SSunny Srivastava      * @param[in] i_paramsToWriteData - Input details.
105*fa5e4d32SSunny Srivastava      *
106*fa5e4d32SSunny Srivastava      * @return On success returns number of bytes written, on failure returns
107*fa5e4d32SSunny Srivastava      * -1.
108*fa5e4d32SSunny Srivastava      */
109*fa5e4d32SSunny Srivastava     int updateVpdKeywordOnRedundantPath(
110*fa5e4d32SSunny Srivastava         const std::string& i_fruPath,
111*fa5e4d32SSunny Srivastava         const types::WriteVpdParams& i_paramsToWriteData);
112*fa5e4d32SSunny Srivastava 
113*fa5e4d32SSunny Srivastava     // holds offfset to VPD if applicable.
114*fa5e4d32SSunny Srivastava     size_t m_vpdStartOffset = 0;
115*fa5e4d32SSunny Srivastava 
116*fa5e4d32SSunny Srivastava     // Path to the VPD file
117*fa5e4d32SSunny Srivastava     const std::string& m_vpdFilePath;
118*fa5e4d32SSunny Srivastava 
119*fa5e4d32SSunny Srivastava     // Path to configuration file, can be empty.
120*fa5e4d32SSunny Srivastava     nlohmann::json m_parsedJson;
121*fa5e4d32SSunny Srivastava 
122*fa5e4d32SSunny Srivastava     // Vector to hold VPD.
123*fa5e4d32SSunny Srivastava     types::BinaryVector m_vpdVector;
124*fa5e4d32SSunny Srivastava 
125*fa5e4d32SSunny Srivastava }; // parser
126*fa5e4d32SSunny Srivastava } // namespace vpd
127