1 #pragma once 2 3 #include "parser_interface.hpp" 4 #include "types.hpp" 5 6 namespace vpd 7 { 8 namespace keyword 9 { 10 namespace parser 11 { 12 13 using ParserInterface = openpower::vpd::parser::interface::ParserInterface; 14 using kwdVpdMap = openpower::vpd::inventory::KeywordVpdMap; 15 using store = openpower::vpd::Store; 16 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 */ 39 class KeywordVpdParser : public ParserInterface 40 { 41 public: 42 KeywordVpdParser() = delete; 43 KeywordVpdParser(const KeywordVpdParser&) = delete; 44 KeywordVpdParser(KeywordVpdParser&&) = delete; 45 ~KeywordVpdParser() = default; 46 47 /** 48 * @brief Constructor 49 * 50 * Move kwVpdVector to parser object's kwVpdVector 51 */ KeywordVpdParser(const openpower::vpd::Binary & kwVpdVector)52 KeywordVpdParser(const openpower::vpd::Binary& kwVpdVector) : 53 keywordVpdVector(kwVpdVector) 54 {} 55 56 /** 57 * @brief Parse the keyword VPD binary data. 58 * 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 */ 64 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; 73 74 private: 75 openpower::vpd::Binary::const_iterator 76 checkSumStart; //!< Pointer to the start byte from where 77 //!< the checksum need to be calculated 78 openpower::vpd::Binary::const_iterator 79 checkSumEnd; //!< Pointer to the end byte until which the 80 //!< checksum need to be calculated 81 openpower::vpd::Binary::const_iterator 82 kwVpdIterator; //!< Iterator to parse the vector 83 const openpower::vpd::Binary& 84 keywordVpdVector; //!< Vector which stores keyword VPD data 85 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 */ 103 openpower::vpd::inventory::KeywordVpdMap kwValParser(); 104 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 (beginning 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 144