blob: e48e7d5b4ce83edbe1d9fbab8ba87ffb81d5c4e0 [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)
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053054 {
55 }
56
57 /**
58 * @brief Parse the keyword VPD binary data.
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053059 * Calls the sub functions to emplace the
60 * keyword-value pairs in map and to validate
61 * certain tags and checksum data.
62 *
63 * @return map of keyword:value
64 */
SunnySrivastava1984e12b1812020-05-26 02:23:11 -050065 std::variant<kwdVpdMap, store> parse();
66
67 /**
68 * @brief An api to return interface name with respect to
69 * the parser selected.
70 *
71 * @return - Interface name for that vpd type.
72 */
73 std::string getInterfaceName() const;
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053074
75 private:
PriyangaRamasamy33c61c22021-04-06 11:15:57 -050076 openpower::vpd::Binary::const_iterator
SunnySrivastava1984945a02d2020-05-06 01:55:41 -050077 checkSumStart; //!< Pointer to the start byte from where
78 //!< the checksum need to be calculated
PriyangaRamasamy33c61c22021-04-06 11:15:57 -050079 openpower::vpd::Binary::const_iterator
SunnySrivastava1984945a02d2020-05-06 01:55:41 -050080 checkSumEnd; //!< Pointer to the end byte until which the
81 //!< checksum need to be calculated
PriyangaRamasamy33c61c22021-04-06 11:15:57 -050082 openpower::vpd::Binary::const_iterator
SunnySrivastava1984945a02d2020-05-06 01:55:41 -050083 kwVpdIterator; //!< Iterator to parse the vector
PriyangaRamasamy33c61c22021-04-06 11:15:57 -050084 const openpower::vpd::Binary&
SunnySrivastava1984945a02d2020-05-06 01:55:41 -050085 keywordVpdVector; //!< Vector which stores keyword VPD data
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +053086
87 /**
88 * @brief Validate the large resource identifier string
89 */
90 void validateLargeResourceIdentifierString();
91
92 /**
93 * @brief Validate the type of keyword VPD
94 *
95 * @return integer representing the type of kw VPD.
96 */
97 int validateTheTypeOfKwVpd();
98
99 /**
100 * @brief Parsing keyword-value pairs and emplace into Map.
101 *
102 * @return map of keyword:value
103 */
SunnySrivastava1984945a02d2020-05-06 01:55:41 -0500104 openpower::vpd::inventory::KeywordVpdMap kwValParser();
PriyangaRamasamyabb87ed2019-11-19 17:25:35 +0530105
106 /**
107 * @brief Validate small resource type end tag
108 */
109 void validateSmallResourceTypeEnd();
110
111 /**
112 * @brief Validate checksum.
113 *
114 * Finding the 2's complement of sum of all the
115 * keywords,values and large resource identifier string.
116 */
117 void validateChecksum();
118
119 /**
120 * @brief Validate small resource type last end tag
121 */
122 void validateSmallResourceTypeLastEnd();
123
124 /**
125 * @brief Get the size of the keyword
126 *
127 * @return one byte length size data
128 */
129 size_t getKwDataSize();
130
131 /**
132 * @brief Check for iterator Out of Bound exception
133 *
134 * Check if no.of elements from (begining of the vector) to (iterator +
135 * incVar) is lesser than or equal to the total no.of elements in the
136 * vector. This check is performed before the advancement of the iterator.
137 *
138 * @param[incVar] - no.of positions the iterator is going to be iterated
139 */
140 void itrOutOfBoundCheck(uint8_t incVar);
141};
142} // namespace parser
143} // namespace keyword
144} // namespace vpd