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