blob: 4466c6bdfbabc4444fd9d3643b7e8ca9bdab9ae3 [file] [log] [blame]
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05301#pragma once
2
SunnySrivastava1984e12b1812020-05-26 02:23:11 -05003#include "parser_interface.hpp"
SunnySrivastava1984945a02d2020-05-06 01:55:41 -05004#include "types.hpp"
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +05305
6namespace vpd
7{
8namespace keyword
9{
10namespace parser
11{
12
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050013using ParserInterface = openpower::vpd::parser::interface::ParserInterface;
14using kwdVpdMap = openpower::vpd::inventory::KeywordVpdMap;
15using store = openpower::vpd::Store;
16
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053017/**
18 * @class KeywordVpdParser
19 * @brief Implements parser for Keyword VPD
20 *
21 * KeywordVpdParser object must be constructed by passing in
22 * Keyword VPD in binary format. To parse the VPD, call the
23 * kwVpdParser() method. The kwVpdParser() method returns
24 * a map of keyword-value pairs.
25 *
26 * Following is the algorithm used to parse Keyword VPD data:
27 * 1) Validate if the first byte is 'largeResourceIdentifierString'.
28 * 2) Validate the byte after the description is 'vendor defined large resource
29 * type tag'.
30 * 3) For each keyword-value pairs :
31 * 3.1) Parse the 2 byte length keyword and emplace it in the map as 'key'.
32 * 3.2) Parse over the value bytes corresponding to the keyword and
33 * emplace it in the map as 'value' for the key inserted in 3.1.
34 * 4) Validate the byte before checksum byte is 'small resource type end tag'.
35 * 5) Validate the checksum.
36 * 6) Validate the 'small resource type last end tag'.
37 * 7) Return the keyword-value map.
38 */
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050039class KeywordVpdParser : public ParserInterface
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053040{
41 public:
42 KeywordVpdParser() = delete;
43 KeywordVpdParser(const KeywordVpdParser&) = delete;
44 KeywordVpdParser(KeywordVpdParser&&) = delete;
45 ~KeywordVpdParser() = default;
46
47 /**
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050048 * @brief Constructor
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053049 *
50 * Move kwVpdVector to parser object's kwVpdVector
51 */
PriyangaRamasamy33c61c22021-04-06 11:15:57 -050052 KeywordVpdParser(const openpower::vpd::Binary& kwVpdVector) :
53 keywordVpdVector(kwVpdVector)
Patrick Williamsc78d8872023-05-10 07:50:56 -050054 {}
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053055
56 /**
57 * @brief Parse the keyword VPD binary data.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053058 * Calls the sub functions to emplace the
59 * keyword-value pairs in map and to validate
60 * certain tags and checksum data.
61 *
62 * @return map of keyword:value
63 */
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050064 std::variant<kwdVpdMap, store> parse();
65
66 /**
67 * @brief An api to return interface name with respect to
68 * the parser selected.
69 *
70 * @return - Interface name for that vpd type.
71 */
72 std::string getInterfaceName() const;
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053073
74 private:
PriyangaRamasamy33c61c22021-04-06 11:15:57 -050075 openpower::vpd::Binary::const_iterator
Patrick Williamsc78d8872023-05-10 07:50:56 -050076 checkSumStart; //!< Pointer to the start byte from where
77 //!< the checksum need to be calculated
PriyangaRamasamy33c61c22021-04-06 11:15:57 -050078 openpower::vpd::Binary::const_iterator
Patrick Williamsc78d8872023-05-10 07:50:56 -050079 checkSumEnd; //!< Pointer to the end byte until which the
80 //!< checksum need to be calculated
PriyangaRamasamy33c61c22021-04-06 11:15:57 -050081 openpower::vpd::Binary::const_iterator
Patrick Williamsc78d8872023-05-10 07:50:56 -050082 kwVpdIterator; //!< Iterator to parse the vector
PriyangaRamasamy33c61c22021-04-06 11:15:57 -050083 const openpower::vpd::Binary&
SunnySrivastava1984945a02d2020-05-06 01:55:41 -050084 keywordVpdVector; //!< Vector which stores keyword VPD data
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053085
86 /**
87 * @brief Validate the large resource identifier string
88 */
89 void validateLargeResourceIdentifierString();
90
91 /**
92 * @brief Validate the type of keyword VPD
93 *
94 * @return integer representing the type of kw VPD.
95 */
96 int validateTheTypeOfKwVpd();
97
98 /**
99 * @brief Parsing keyword-value pairs and emplace into Map.
100 *
101 * @return map of keyword:value
102 */
SunnySrivastava1984945a02d2020-05-06 01:55:41 -0500103 openpower::vpd::inventory::KeywordVpdMap kwValParser();
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530104
105 /**
106 * @brief Validate small resource type end tag
107 */
108 void validateSmallResourceTypeEnd();
109
110 /**
111 * @brief Validate checksum.
112 *
113 * Finding the 2's complement of sum of all the
114 * keywords,values and large resource identifier string.
115 */
116 void validateChecksum();
117
118 /**
119 * @brief Validate small resource type last end tag
120 */
121 void validateSmallResourceTypeLastEnd();
122
123 /**
124 * @brief Get the size of the keyword
125 *
126 * @return one byte length size data
127 */
128 size_t getKwDataSize();
129
130 /**
131 * @brief Check for iterator Out of Bound exception
132 *
133 * Check if no.of elements from (begining of the vector) to (iterator +
134 * incVar) is lesser than or equal to the total no.of elements in the
135 * vector. This check is performed before the advancement of the iterator.
136 *
137 * @param[incVar] - no.of positions the iterator is going to be iterated
138 */
139 void itrOutOfBoundCheck(uint8_t incVar);
140};
141} // namespace parser
142} // namespace keyword
143} // namespace vpd