PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 3 | #include "parser_interface.hpp" |
SunnySrivastava1984 | 945a02d | 2020-05-06 01:55:41 -0500 | [diff] [blame] | 4 | #include "types.hpp" |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 5 | |
| 6 | namespace vpd |
| 7 | { |
| 8 | namespace keyword |
| 9 | { |
| 10 | namespace parser |
| 11 | { |
| 12 | |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 13 | using ParserInterface = openpower::vpd::parser::interface::ParserInterface; |
| 14 | using kwdVpdMap = openpower::vpd::inventory::KeywordVpdMap; |
| 15 | using store = openpower::vpd::Store; |
| 16 | |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 17 | /** |
| 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 | */ |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 39 | class KeywordVpdParser : public ParserInterface |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 40 | { |
| 41 | public: |
| 42 | KeywordVpdParser() = delete; |
| 43 | KeywordVpdParser(const KeywordVpdParser&) = delete; |
| 44 | KeywordVpdParser(KeywordVpdParser&&) = delete; |
| 45 | ~KeywordVpdParser() = default; |
| 46 | |
| 47 | /** |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 48 | * @brief Constructor |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 49 | * |
| 50 | * Move kwVpdVector to parser object's kwVpdVector |
| 51 | */ |
PriyangaRamasamy | 33c61c2 | 2021-04-06 11:15:57 -0500 | [diff] [blame] | 52 | KeywordVpdParser(const openpower::vpd::Binary& kwVpdVector) : |
| 53 | keywordVpdVector(kwVpdVector) |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 54 | { |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * @brief Parse the keyword VPD binary data. |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 59 | * 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 | */ |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 65 | 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; |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 74 | |
| 75 | private: |
PriyangaRamasamy | 33c61c2 | 2021-04-06 11:15:57 -0500 | [diff] [blame] | 76 | openpower::vpd::Binary::const_iterator |
SunnySrivastava1984 | 945a02d | 2020-05-06 01:55:41 -0500 | [diff] [blame] | 77 | checkSumStart; //!< Pointer to the start byte from where |
| 78 | //!< the checksum need to be calculated |
PriyangaRamasamy | 33c61c2 | 2021-04-06 11:15:57 -0500 | [diff] [blame] | 79 | openpower::vpd::Binary::const_iterator |
SunnySrivastava1984 | 945a02d | 2020-05-06 01:55:41 -0500 | [diff] [blame] | 80 | checkSumEnd; //!< Pointer to the end byte until which the |
| 81 | //!< checksum need to be calculated |
PriyangaRamasamy | 33c61c2 | 2021-04-06 11:15:57 -0500 | [diff] [blame] | 82 | openpower::vpd::Binary::const_iterator |
SunnySrivastava1984 | 945a02d | 2020-05-06 01:55:41 -0500 | [diff] [blame] | 83 | kwVpdIterator; //!< Iterator to parse the vector |
PriyangaRamasamy | 33c61c2 | 2021-04-06 11:15:57 -0500 | [diff] [blame] | 84 | const openpower::vpd::Binary& |
SunnySrivastava1984 | 945a02d | 2020-05-06 01:55:41 -0500 | [diff] [blame] | 85 | keywordVpdVector; //!< Vector which stores keyword VPD data |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 86 | |
| 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 | */ |
SunnySrivastava1984 | 945a02d | 2020-05-06 01:55:41 -0500 | [diff] [blame] | 104 | openpower::vpd::inventory::KeywordVpdMap kwValParser(); |
PriyangaRamasamy | abb87ed | 2019-11-19 17:25:35 +0530 | [diff] [blame] | 105 | |
| 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 |