SunnySrivastava1984 | a739259 | 2020-03-09 10:19:33 -0500 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 3 | #include "editor_impl.hpp" |
| 4 | |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 5 | #include "common_utility.hpp" |
Sunny Srivastava | 6c71c9d | 2021-04-15 04:43:54 -0500 | [diff] [blame] | 6 | #include "ibm_vpd_utils.hpp" |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 7 | #include "ipz_parser.hpp" |
| 8 | #include "parser_factory.hpp" |
Priyanga Ramasamy | c99a0b0 | 2022-06-08 14:53:39 -0500 | [diff] [blame] | 9 | #include "vpd_exceptions.hpp" |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 10 | |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 11 | #include "vpdecc/vpdecc.h" |
| 12 | |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 13 | using namespace openpower::vpd::parser::interface; |
| 14 | using namespace openpower::vpd::constants; |
| 15 | using namespace openpower::vpd::parser::factory; |
| 16 | using namespace openpower::vpd::ipz::parser; |
| 17 | |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 18 | namespace openpower |
| 19 | { |
| 20 | namespace vpd |
| 21 | { |
| 22 | namespace manager |
| 23 | { |
| 24 | namespace editor |
| 25 | { |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 26 | |
| 27 | void EditorImpl::checkPTForRecord(Binary::const_iterator& iterator, |
| 28 | Byte ptLength) |
| 29 | { |
| 30 | // auto iterator = ptRecord.cbegin(); |
| 31 | auto end = std::next(iterator, ptLength + 1); |
| 32 | |
| 33 | // Look at each entry in the PT keyword for the record name |
| 34 | while (iterator < end) |
| 35 | { |
| 36 | auto stop = std::next(iterator, lengths::RECORD_NAME); |
| 37 | std::string record(iterator, stop); |
| 38 | |
| 39 | if (record == thisRecord.recName) |
| 40 | { |
| 41 | // Skip record name and record type |
| 42 | std::advance(iterator, lengths::RECORD_NAME + sizeof(RecordType)); |
| 43 | |
| 44 | // Get record offset |
| 45 | thisRecord.recOffset = readUInt16LE(iterator); |
| 46 | |
| 47 | // pass the record offset length to read record length |
| 48 | std::advance(iterator, lengths::RECORD_OFFSET); |
| 49 | thisRecord.recSize = readUInt16LE(iterator); |
| 50 | |
| 51 | std::advance(iterator, lengths::RECORD_LENGTH); |
| 52 | thisRecord.recECCoffset = readUInt16LE(iterator); |
| 53 | |
| 54 | ECCLength len; |
| 55 | std::advance(iterator, lengths::RECORD_ECC_OFFSET); |
| 56 | len = readUInt16LE(iterator); |
| 57 | thisRecord.recECCLength = len; |
| 58 | |
| 59 | // once we find the record we don't need to look further |
| 60 | return; |
| 61 | } |
| 62 | else |
| 63 | { |
| 64 | // Jump the record |
| 65 | std::advance(iterator, lengths::RECORD_NAME + sizeof(RecordType) + |
| 66 | sizeof(RecordOffset) + |
| 67 | sizeof(RecordLength) + |
| 68 | sizeof(ECCOffset) + sizeof(ECCLength)); |
| 69 | } |
| 70 | } |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 71 | // imples the record was not found |
| 72 | throw std::runtime_error("Record not found"); |
| 73 | } |
| 74 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 75 | void EditorImpl::updateData(const Binary& kwdData) |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 76 | { |
| 77 | std::size_t lengthToUpdate = kwdData.size() <= thisRecord.kwdDataLength |
| 78 | ? kwdData.size() |
| 79 | : thisRecord.kwdDataLength; |
| 80 | |
| 81 | auto iteratorToNewdata = kwdData.cbegin(); |
| 82 | auto end = iteratorToNewdata; |
| 83 | std::advance(end, lengthToUpdate); |
| 84 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 85 | // update data in file buffer as it will be needed to update ECC |
| 86 | // avoiding extra stream operation here |
| 87 | auto iteratorToKWdData = vpdFile.begin(); |
| 88 | std::advance(iteratorToKWdData, thisRecord.kwDataOffset); |
| 89 | std::copy(iteratorToNewdata, end, iteratorToKWdData); |
| 90 | |
SunnySrivastava1984 | a0d460e | 2020-06-03 07:49:26 -0500 | [diff] [blame] | 91 | #ifdef ManagerTest |
| 92 | auto startItr = vpdFile.begin(); |
| 93 | std::advance(iteratorToKWdData, thisRecord.kwDataOffset); |
| 94 | auto endItr = startItr; |
| 95 | std::advance(endItr, thisRecord.kwdDataLength); |
| 96 | |
| 97 | Binary updatedData(startItr, endItr); |
| 98 | if (updatedData == kwdData) |
| 99 | { |
| 100 | throw std::runtime_error("Data updated successfully"); |
| 101 | } |
| 102 | #else |
| 103 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 104 | // update data in EEPROM as well. As we will not write complete file back |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 105 | vpdFileStream.seekp(startOffset + thisRecord.kwDataOffset, std::ios::beg); |
Alpana Kumari | 920408d | 2020-05-14 00:07:03 -0500 | [diff] [blame] | 106 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 107 | iteratorToNewdata = kwdData.cbegin(); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 108 | std::copy(iteratorToNewdata, end, |
| 109 | std::ostreambuf_iterator<char>(vpdFileStream)); |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 110 | |
| 111 | // get a hold to new data in case encoding is needed |
| 112 | thisRecord.kwdUpdatedData.resize(thisRecord.kwdDataLength); |
| 113 | auto itrToKWdData = vpdFile.cbegin(); |
| 114 | std::advance(itrToKWdData, thisRecord.kwDataOffset); |
| 115 | auto kwdDataEnd = itrToKWdData; |
| 116 | std::advance(kwdDataEnd, thisRecord.kwdDataLength); |
| 117 | std::copy(itrToKWdData, kwdDataEnd, thisRecord.kwdUpdatedData.begin()); |
SunnySrivastava1984 | a0d460e | 2020-06-03 07:49:26 -0500 | [diff] [blame] | 118 | #endif |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | void EditorImpl::checkRecordForKwd() |
| 122 | { |
| 123 | RecordOffset recOffset = thisRecord.recOffset; |
| 124 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 125 | // Amount to skip for record ID, size, and the RT keyword |
| 126 | constexpr auto skipBeg = sizeof(RecordId) + sizeof(RecordSize) + |
| 127 | lengths::KW_NAME + sizeof(KwSize); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 128 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 129 | auto iterator = vpdFile.cbegin(); |
| 130 | std::advance(iterator, recOffset + skipBeg + lengths::RECORD_NAME); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 131 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 132 | auto end = iterator; |
| 133 | std::advance(end, thisRecord.recSize); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 134 | std::size_t dataLength = 0; |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 135 | |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 136 | while (iterator < end) |
| 137 | { |
| 138 | // Note keyword name |
| 139 | std::string kw(iterator, iterator + lengths::KW_NAME); |
| 140 | |
| 141 | // Check if the Keyword starts with '#' |
| 142 | char kwNameStart = *iterator; |
| 143 | std::advance(iterator, lengths::KW_NAME); |
| 144 | |
| 145 | // if keyword starts with # |
| 146 | if (POUND_KW == kwNameStart) |
| 147 | { |
| 148 | // Note existing keyword data length |
| 149 | dataLength = readUInt16LE(iterator); |
| 150 | |
| 151 | // Jump past 2Byte keyword length + data |
| 152 | std::advance(iterator, sizeof(PoundKwSize)); |
| 153 | } |
| 154 | else |
| 155 | { |
| 156 | // Note existing keyword data length |
| 157 | dataLength = *iterator; |
| 158 | |
| 159 | // Jump past keyword length and data |
| 160 | std::advance(iterator, sizeof(KwSize)); |
| 161 | } |
| 162 | |
| 163 | if (thisRecord.recKWd == kw) |
| 164 | { |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 165 | thisRecord.kwDataOffset = std::distance(vpdFile.cbegin(), iterator); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 166 | thisRecord.kwdDataLength = dataLength; |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 167 | return; |
| 168 | } |
| 169 | |
| 170 | // jump the data of current kwd to point to next kwd name |
| 171 | std::advance(iterator, dataLength); |
| 172 | } |
| 173 | |
| 174 | throw std::runtime_error("Keyword not found"); |
| 175 | } |
| 176 | |
| 177 | void EditorImpl::updateRecordECC() |
| 178 | { |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 179 | auto itrToRecordData = vpdFile.cbegin(); |
| 180 | std::advance(itrToRecordData, thisRecord.recOffset); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 181 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 182 | auto itrToRecordECC = vpdFile.cbegin(); |
| 183 | std::advance(itrToRecordECC, thisRecord.recECCoffset); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 184 | |
| 185 | auto l_status = vpdecc_create_ecc( |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 186 | const_cast<uint8_t*>(&itrToRecordData[0]), thisRecord.recSize, |
| 187 | const_cast<uint8_t*>(&itrToRecordECC[0]), &thisRecord.recECCLength); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 188 | if (l_status != VPD_ECC_OK) |
| 189 | { |
| 190 | throw std::runtime_error("Ecc update failed"); |
| 191 | } |
| 192 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 193 | auto end = itrToRecordECC; |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 194 | std::advance(end, thisRecord.recECCLength); |
| 195 | |
SunnySrivastava1984 | a0d460e | 2020-06-03 07:49:26 -0500 | [diff] [blame] | 196 | #ifndef ManagerTest |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 197 | vpdFileStream.seekp(startOffset + thisRecord.recECCoffset, std::ios::beg); |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 198 | std::copy(itrToRecordECC, end, |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 199 | std::ostreambuf_iterator<char>(vpdFileStream)); |
SunnySrivastava1984 | a0d460e | 2020-06-03 07:49:26 -0500 | [diff] [blame] | 200 | #endif |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | auto EditorImpl::getValue(offsets::Offsets offset) |
| 204 | { |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 205 | auto itr = vpdFile.cbegin(); |
| 206 | std::advance(itr, offset); |
| 207 | LE2ByteData lowByte = *itr; |
| 208 | LE2ByteData highByte = *(itr + 1); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 209 | lowByte |= (highByte << 8); |
| 210 | |
| 211 | return lowByte; |
| 212 | } |
| 213 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 214 | void EditorImpl::checkECC(Binary::const_iterator& itrToRecData, |
| 215 | Binary::const_iterator& itrToECCData, |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 216 | RecordLength recLength, ECCLength eccLength) |
| 217 | { |
| 218 | auto l_status = |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 219 | vpdecc_check_data(const_cast<uint8_t*>(&itrToRecData[0]), recLength, |
| 220 | const_cast<uint8_t*>(&itrToECCData[0]), eccLength); |
| 221 | |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 222 | if (l_status != VPD_ECC_OK) |
| 223 | { |
| 224 | throw std::runtime_error("Ecc check failed for VTOC"); |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | void EditorImpl::readVTOC() |
| 229 | { |
| 230 | // read VTOC offset |
| 231 | RecordOffset tocOffset = getValue(offsets::VTOC_PTR); |
| 232 | |
| 233 | // read VTOC record length |
| 234 | RecordLength tocLength = getValue(offsets::VTOC_REC_LEN); |
| 235 | |
| 236 | // read TOC ecc offset |
| 237 | ECCOffset tocECCOffset = getValue(offsets::VTOC_ECC_OFF); |
| 238 | |
| 239 | // read TOC ecc length |
| 240 | ECCLength tocECCLength = getValue(offsets::VTOC_ECC_LEN); |
| 241 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 242 | auto itrToRecord = vpdFile.cbegin(); |
| 243 | std::advance(itrToRecord, tocOffset); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 244 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 245 | auto iteratorToECC = vpdFile.cbegin(); |
| 246 | std::advance(iteratorToECC, tocECCOffset); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 247 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 248 | // validate ecc for the record |
| 249 | checkECC(itrToRecord, iteratorToECC, tocLength, tocECCLength); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 250 | |
| 251 | // to get to the record name. |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 252 | std::advance(itrToRecord, sizeof(RecordId) + sizeof(RecordSize) + |
| 253 | // Skip past the RT keyword, which contains |
| 254 | // the record name. |
| 255 | lengths::KW_NAME + sizeof(KwSize)); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 256 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 257 | std::string recordName(itrToRecord, itrToRecord + lengths::RECORD_NAME); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 258 | |
| 259 | if ("VTOC" != recordName) |
| 260 | { |
| 261 | throw std::runtime_error("VTOC record not found"); |
| 262 | } |
| 263 | |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 264 | // jump to length of PT kwd |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 265 | std::advance(itrToRecord, lengths::RECORD_NAME + lengths::KW_NAME); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 266 | |
| 267 | // Note size of PT |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 268 | Byte ptLen = *itrToRecord; |
| 269 | std::advance(itrToRecord, 1); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 270 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 271 | checkPTForRecord(itrToRecord, ptLen); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 272 | } |
| 273 | |
SunnySrivastava1984 | d076da8 | 2020-03-05 05:33:35 -0600 | [diff] [blame] | 274 | template <typename T> |
| 275 | void EditorImpl::makeDbusCall(const std::string& object, |
| 276 | const std::string& interface, |
| 277 | const std::string& property, |
| 278 | const std::variant<T>& data) |
| 279 | { |
| 280 | auto bus = sdbusplus::bus::new_default(); |
SunnySrivastava1984 | a739259 | 2020-03-09 10:19:33 -0500 | [diff] [blame] | 281 | auto properties = |
| 282 | bus.new_method_call(INVENTORY_MANAGER_SERVICE, object.c_str(), |
| 283 | "org.freedesktop.DBus.Properties", "Set"); |
SunnySrivastava1984 | d076da8 | 2020-03-05 05:33:35 -0600 | [diff] [blame] | 284 | properties.append(interface); |
| 285 | properties.append(property); |
| 286 | properties.append(data); |
| 287 | |
| 288 | auto result = bus.call(properties); |
| 289 | |
| 290 | if (result.is_method_error()) |
| 291 | { |
| 292 | throw std::runtime_error("bus call failed"); |
| 293 | } |
| 294 | } |
| 295 | |
SunnySrivastava1984 | b421bfd | 2020-03-02 08:59:32 -0600 | [diff] [blame] | 296 | void EditorImpl::processAndUpdateCI(const std::string& objectPath) |
| 297 | { |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 298 | inventory::ObjectMap objects; |
SunnySrivastava1984 | b421bfd | 2020-03-02 08:59:32 -0600 | [diff] [blame] | 299 | for (auto& commonInterface : jsonFile["commonInterfaces"].items()) |
| 300 | { |
| 301 | for (auto& ciPropertyList : commonInterface.value().items()) |
| 302 | { |
SunnySrivastava1984 | d076da8 | 2020-03-05 05:33:35 -0600 | [diff] [blame] | 303 | if (ciPropertyList.value().type() == |
| 304 | nlohmann::json::value_t::object) |
SunnySrivastava1984 | b421bfd | 2020-03-02 08:59:32 -0600 | [diff] [blame] | 305 | { |
SunnySrivastava1984 | d076da8 | 2020-03-05 05:33:35 -0600 | [diff] [blame] | 306 | if ((ciPropertyList.value().value("recordName", "") == |
| 307 | thisRecord.recName) && |
| 308 | (ciPropertyList.value().value("keywordName", "") == |
| 309 | thisRecord.recKWd)) |
| 310 | { |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 311 | inventory::PropertyMap prop; |
| 312 | inventory::InterfaceMap interfaces; |
SunnySrivastava1984 | d076da8 | 2020-03-05 05:33:35 -0600 | [diff] [blame] | 313 | std::string kwdData(thisRecord.kwdUpdatedData.begin(), |
| 314 | thisRecord.kwdUpdatedData.end()); |
| 315 | |
Priyanga Ramasamy | e008432 | 2022-09-27 06:28:33 -0500 | [diff] [blame^] | 316 | prop.emplace(ciPropertyList.key(), std::move(kwdData)); |
| 317 | interfaces.emplace(commonInterface.key(), std::move(prop)); |
| 318 | objects.emplace(objectPath, std::move(interfaces)); |
SunnySrivastava1984 | d076da8 | 2020-03-05 05:33:35 -0600 | [diff] [blame] | 319 | } |
SunnySrivastava1984 | b421bfd | 2020-03-02 08:59:32 -0600 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | } |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 323 | // Notify PIM |
Priyanga Ramasamy | e008432 | 2022-09-27 06:28:33 -0500 | [diff] [blame^] | 324 | common::utility::callPIM(std::move(objects)); |
SunnySrivastava1984 | b421bfd | 2020-03-02 08:59:32 -0600 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | void EditorImpl::processAndUpdateEI(const nlohmann::json& Inventory, |
| 328 | const inventory::Path& objPath) |
| 329 | { |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 330 | inventory::ObjectMap objects; |
SunnySrivastava1984 | b421bfd | 2020-03-02 08:59:32 -0600 | [diff] [blame] | 331 | for (const auto& extraInterface : Inventory["extraInterfaces"].items()) |
| 332 | { |
| 333 | if (extraInterface.value() != NULL) |
| 334 | { |
| 335 | for (const auto& eiPropertyList : extraInterface.value().items()) |
| 336 | { |
SunnySrivastava1984 | d076da8 | 2020-03-05 05:33:35 -0600 | [diff] [blame] | 337 | if (eiPropertyList.value().type() == |
| 338 | nlohmann::json::value_t::object) |
SunnySrivastava1984 | b421bfd | 2020-03-02 08:59:32 -0600 | [diff] [blame] | 339 | { |
SunnySrivastava1984 | d076da8 | 2020-03-05 05:33:35 -0600 | [diff] [blame] | 340 | if ((eiPropertyList.value().value("recordName", "") == |
| 341 | thisRecord.recName) && |
| 342 | ((eiPropertyList.value().value("keywordName", "") == |
| 343 | thisRecord.recKWd))) |
| 344 | { |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 345 | inventory::PropertyMap prop; |
| 346 | inventory::InterfaceMap interfaces; |
SunnySrivastava1984 | d076da8 | 2020-03-05 05:33:35 -0600 | [diff] [blame] | 347 | std::string kwdData(thisRecord.kwdUpdatedData.begin(), |
| 348 | thisRecord.kwdUpdatedData.end()); |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 349 | encodeKeyword(kwdData, eiPropertyList.value().value( |
| 350 | "encoding", "")); |
| 351 | |
Priyanga Ramasamy | e008432 | 2022-09-27 06:28:33 -0500 | [diff] [blame^] | 352 | prop.emplace(eiPropertyList.key(), std::move(kwdData)); |
| 353 | interfaces.emplace(extraInterface.key(), |
| 354 | std::move(prop)); |
| 355 | objects.emplace(objPath, std::move(interfaces)); |
SunnySrivastava1984 | d076da8 | 2020-03-05 05:33:35 -0600 | [diff] [blame] | 356 | } |
SunnySrivastava1984 | b421bfd | 2020-03-02 08:59:32 -0600 | [diff] [blame] | 357 | } |
| 358 | } |
| 359 | } |
| 360 | } |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 361 | // Notify PIM |
Priyanga Ramasamy | e008432 | 2022-09-27 06:28:33 -0500 | [diff] [blame^] | 362 | common::utility::callPIM(std::move(objects)); |
SunnySrivastava1984 | b421bfd | 2020-03-02 08:59:32 -0600 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | void EditorImpl::updateCache() |
| 366 | { |
| 367 | const std::vector<nlohmann::json>& groupEEPROM = |
| 368 | jsonFile["frus"][vpdFilePath].get_ref<const nlohmann::json::array_t&>(); |
| 369 | |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 370 | inventory::ObjectMap objects; |
SunnySrivastava1984 | b421bfd | 2020-03-02 08:59:32 -0600 | [diff] [blame] | 371 | // iterate through all the inventories for this file path |
| 372 | for (const auto& singleInventory : groupEEPROM) |
| 373 | { |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 374 | inventory::PropertyMap prop; |
| 375 | inventory::InterfaceMap interfaces; |
SunnySrivastava1984 | d076da8 | 2020-03-05 05:33:35 -0600 | [diff] [blame] | 376 | // by default inherit property is true |
| 377 | bool isInherit = true; |
| 378 | |
| 379 | if (singleInventory.find("inherit") != singleInventory.end()) |
SunnySrivastava1984 | b421bfd | 2020-03-02 08:59:32 -0600 | [diff] [blame] | 380 | { |
SunnySrivastava1984 | d076da8 | 2020-03-05 05:33:35 -0600 | [diff] [blame] | 381 | isInherit = singleInventory["inherit"].get<bool>(); |
| 382 | } |
| 383 | |
| 384 | if (isInherit) |
| 385 | { |
Santosh Puranik | 32c4650 | 2022-02-10 08:55:07 +0530 | [diff] [blame] | 386 | prop.emplace(thisRecord.recKWd, thisRecord.kwdUpdatedData); |
| 387 | interfaces.emplace( |
| 388 | (IPZ_INTERFACE + (std::string) "." + thisRecord.recName), |
Priyanga Ramasamy | e008432 | 2022-09-27 06:28:33 -0500 | [diff] [blame^] | 389 | std::move(prop)); |
Santosh Puranik | 32c4650 | 2022-02-10 08:55:07 +0530 | [diff] [blame] | 390 | objects.emplace( |
| 391 | (singleInventory["inventoryPath"].get<std::string>()), |
Priyanga Ramasamy | e008432 | 2022-09-27 06:28:33 -0500 | [diff] [blame^] | 392 | std::move(interfaces)); |
SunnySrivastava1984 | d076da8 | 2020-03-05 05:33:35 -0600 | [diff] [blame] | 393 | |
| 394 | // process Common interface |
SunnySrivastava1984 | b421bfd | 2020-03-02 08:59:32 -0600 | [diff] [blame] | 395 | processAndUpdateCI(singleInventory["inventoryPath"] |
| 396 | .get_ref<const nlohmann::json::string_t&>()); |
| 397 | } |
| 398 | |
Santosh Puranik | 32c4650 | 2022-02-10 08:55:07 +0530 | [diff] [blame] | 399 | // process extra interfaces |
| 400 | processAndUpdateEI(singleInventory, |
| 401 | singleInventory["inventoryPath"] |
| 402 | .get_ref<const nlohmann::json::string_t&>()); |
Sunny Srivastava | 26d6c14 | 2021-11-03 15:19:02 -0500 | [diff] [blame] | 403 | |
| 404 | // check if we need to copy some specific records in this case. |
| 405 | if (singleInventory.find("copyRecords") != singleInventory.end()) |
| 406 | { |
| 407 | if (find(singleInventory["copyRecords"].begin(), |
| 408 | singleInventory["copyRecords"].end(), |
| 409 | thisRecord.recName) != |
| 410 | singleInventory["copyRecords"].end()) |
| 411 | { |
| 412 | prop.emplace(thisRecord.recKWd, thisRecord.kwdUpdatedData); |
| 413 | interfaces.emplace( |
| 414 | (IPZ_INTERFACE + std::string{"."} + thisRecord.recName), |
Priyanga Ramasamy | e008432 | 2022-09-27 06:28:33 -0500 | [diff] [blame^] | 415 | std::move(prop)); |
Sunny Srivastava | 26d6c14 | 2021-11-03 15:19:02 -0500 | [diff] [blame] | 416 | objects.emplace( |
| 417 | (singleInventory["inventoryPath"].get<std::string>()), |
Priyanga Ramasamy | e008432 | 2022-09-27 06:28:33 -0500 | [diff] [blame^] | 418 | std::move(interfaces)); |
Sunny Srivastava | 26d6c14 | 2021-11-03 15:19:02 -0500 | [diff] [blame] | 419 | } |
| 420 | } |
SunnySrivastava1984 | b421bfd | 2020-03-02 08:59:32 -0600 | [diff] [blame] | 421 | } |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 422 | // Notify PIM |
Priyanga Ramasamy | e008432 | 2022-09-27 06:28:33 -0500 | [diff] [blame^] | 423 | common::utility::callPIM(std::move(objects)); |
SunnySrivastava1984 | b421bfd | 2020-03-02 08:59:32 -0600 | [diff] [blame] | 424 | } |
| 425 | |
SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 426 | void EditorImpl::expandLocationCode(const std::string& locationCodeType) |
| 427 | { |
| 428 | std::string propertyFCorTM{}; |
| 429 | std::string propertySE{}; |
| 430 | |
| 431 | if (locationCodeType == "fcs") |
| 432 | { |
| 433 | propertyFCorTM = |
| 434 | readBusProperty(SYSTEM_OBJECT, "com.ibm.ipzvpd.VCEN", "FC"); |
| 435 | propertySE = |
| 436 | readBusProperty(SYSTEM_OBJECT, "com.ibm.ipzvpd.VCEN", "SE"); |
| 437 | } |
| 438 | else if (locationCodeType == "mts") |
| 439 | { |
| 440 | propertyFCorTM = |
| 441 | readBusProperty(SYSTEM_OBJECT, "com.ibm.ipzvpd.VSYS", "TM"); |
| 442 | propertySE = |
| 443 | readBusProperty(SYSTEM_OBJECT, "com.ibm.ipzvpd.VSYS", "SE"); |
| 444 | } |
| 445 | |
| 446 | const nlohmann::json& groupFRUS = |
| 447 | jsonFile["frus"].get_ref<const nlohmann::json::object_t&>(); |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 448 | inventory::ObjectMap objects; |
| 449 | |
SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 450 | for (const auto& itemFRUS : groupFRUS.items()) |
| 451 | { |
| 452 | const std::vector<nlohmann::json>& groupEEPROM = |
| 453 | itemFRUS.value().get_ref<const nlohmann::json::array_t&>(); |
| 454 | for (const auto& itemEEPROM : groupEEPROM) |
| 455 | { |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 456 | inventory::PropertyMap prop; |
| 457 | inventory::InterfaceMap interfaces; |
| 458 | const auto& objectPath = itemEEPROM["inventoryPath"]; |
| 459 | sdbusplus::message::object_path object(objectPath); |
| 460 | |
SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 461 | // check if the given item implements location code interface |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 462 | if (itemEEPROM["extraInterfaces"].find(IBM_LOCATION_CODE_INF) != |
SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 463 | itemEEPROM["extraInterfaces"].end()) |
| 464 | { |
| 465 | const std::string& unexpandedLocationCode = |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 466 | itemEEPROM["extraInterfaces"][IBM_LOCATION_CODE_INF] |
SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 467 | ["LocationCode"] |
| 468 | .get_ref<const nlohmann::json::string_t&>(); |
| 469 | std::size_t idx = unexpandedLocationCode.find(locationCodeType); |
| 470 | if (idx != std::string::npos) |
| 471 | { |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 472 | std::string expandedLocationCode(unexpandedLocationCode); |
SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 473 | |
| 474 | if (locationCodeType == "fcs") |
| 475 | { |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 476 | expandedLocationCode.replace( |
SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 477 | idx, 3, |
| 478 | propertyFCorTM.substr(0, 4) + ".ND0." + propertySE); |
| 479 | } |
| 480 | else if (locationCodeType == "mts") |
| 481 | { |
| 482 | std::replace(propertyFCorTM.begin(), |
| 483 | propertyFCorTM.end(), '-', '.'); |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 484 | expandedLocationCode.replace( |
SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 485 | idx, 3, propertyFCorTM + "." + propertySE); |
| 486 | } |
| 487 | |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 488 | // update the DBUS interface COM as well as XYZ path |
| 489 | prop.emplace("LocationCode", expandedLocationCode); |
| 490 | // TODO depricate this com.ibm interface later |
| 491 | interfaces.emplace(IBM_LOCATION_CODE_INF, prop); |
Priyanga Ramasamy | e008432 | 2022-09-27 06:28:33 -0500 | [diff] [blame^] | 492 | interfaces.emplace(XYZ_LOCATION_CODE_INF, std::move(prop)); |
SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 493 | } |
| 494 | } |
Priyanga Ramasamy | e008432 | 2022-09-27 06:28:33 -0500 | [diff] [blame^] | 495 | objects.emplace(std::move(object), std::move(interfaces)); |
SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 496 | } |
| 497 | } |
Alpana Kumari | 414d5ae | 2021-03-04 21:06:35 +0000 | [diff] [blame] | 498 | // Notify PIM |
Priyanga Ramasamy | e008432 | 2022-09-27 06:28:33 -0500 | [diff] [blame^] | 499 | common::utility::callPIM(std::move(objects)); |
SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 500 | } |
| 501 | |
Santosh Puranik | a0b2391 | 2022-02-10 13:37:09 +0530 | [diff] [blame] | 502 | void EditorImpl::updateKeyword(const Binary& kwdData, uint32_t offset, |
| 503 | const bool& updCache) |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 504 | { |
Santosh Puranik | a0b2391 | 2022-02-10 13:37:09 +0530 | [diff] [blame] | 505 | startOffset = offset; |
SunnySrivastava1984 | a0d460e | 2020-06-03 07:49:26 -0500 | [diff] [blame] | 506 | #ifndef ManagerTest |
Alpana Kumari | 920408d | 2020-05-14 00:07:03 -0500 | [diff] [blame] | 507 | // TODO: Figure out a better way to get max possible VPD size. |
| 508 | Binary completeVPDFile; |
| 509 | completeVPDFile.resize(65504); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 510 | vpdFileStream.open(vpdFilePath, |
| 511 | std::ios::in | std::ios::out | std::ios::binary); |
SunnySrivastava1984 | a0d460e | 2020-06-03 07:49:26 -0500 | [diff] [blame] | 512 | |
Priyanga Ramasamy | e008432 | 2022-09-27 06:28:33 -0500 | [diff] [blame^] | 513 | vpdFileStream.seekg(startOffset, std::ios_base::cur); |
Alpana Kumari | 920408d | 2020-05-14 00:07:03 -0500 | [diff] [blame] | 514 | vpdFileStream.read(reinterpret_cast<char*>(&completeVPDFile[0]), 65504); |
| 515 | completeVPDFile.resize(vpdFileStream.gcount()); |
| 516 | vpdFileStream.clear(std::ios_base::eofbit); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 517 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 518 | vpdFile = completeVPDFile; |
Alpana Kumari | 920408d | 2020-05-14 00:07:03 -0500 | [diff] [blame] | 519 | |
SunnySrivastava1984 | a0d460e | 2020-06-03 07:49:26 -0500 | [diff] [blame] | 520 | #else |
Alpana Kumari | 920408d | 2020-05-14 00:07:03 -0500 | [diff] [blame] | 521 | |
SunnySrivastava1984 | a0d460e | 2020-06-03 07:49:26 -0500 | [diff] [blame] | 522 | Binary completeVPDFile = vpdFile; |
Alpana Kumari | 920408d | 2020-05-14 00:07:03 -0500 | [diff] [blame] | 523 | |
SunnySrivastava1984 | a0d460e | 2020-06-03 07:49:26 -0500 | [diff] [blame] | 524 | #endif |
| 525 | if (vpdFile.empty()) |
| 526 | { |
| 527 | throw std::runtime_error("Invalid File"); |
| 528 | } |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 529 | auto iterator = vpdFile.cbegin(); |
| 530 | std::advance(iterator, IPZ_DATA_START); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 531 | |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 532 | Byte vpdType = *iterator; |
| 533 | if (vpdType == KW_VAL_PAIR_START_TAG) |
| 534 | { |
PriyangaRamasamy | 33c61c2 | 2021-04-06 11:15:57 -0500 | [diff] [blame] | 535 | ParserInterface* Iparser = ParserFactory::getParser(completeVPDFile); |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 536 | IpzVpdParser* ipzParser = dynamic_cast<IpzVpdParser*>(Iparser); |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 537 | |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 538 | try |
| 539 | { |
| 540 | if (ipzParser == nullptr) |
| 541 | { |
| 542 | throw std::runtime_error("Invalid cast"); |
| 543 | } |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 544 | |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 545 | ipzParser->processHeader(); |
| 546 | delete ipzParser; |
| 547 | ipzParser = nullptr; |
| 548 | // ParserFactory::freeParser(Iparser); |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 549 | |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 550 | // process VTOC for PTT rkwd |
| 551 | readVTOC(); |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 552 | |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 553 | // check record for keywrod |
| 554 | checkRecordForKwd(); |
| 555 | |
| 556 | // update the data to the file |
| 557 | updateData(kwdData); |
| 558 | |
| 559 | // update the ECC data for the record once data has been updated |
| 560 | updateRecordECC(); |
PriyangaRamasamy | c0a534f | 2020-08-24 21:29:18 +0530 | [diff] [blame] | 561 | |
PriyangaRamasamy | c0a534f | 2020-08-24 21:29:18 +0530 | [diff] [blame] | 562 | if (updCache) |
| 563 | { |
PriyangaRamasamy | c0d1c0a | 2021-04-16 09:45:06 -0500 | [diff] [blame] | 564 | #ifndef ManagerTest |
PriyangaRamasamy | c0a534f | 2020-08-24 21:29:18 +0530 | [diff] [blame] | 565 | // update the cache once data has been updated |
| 566 | updateCache(); |
SunnySrivastava1984 | a0d460e | 2020-06-03 07:49:26 -0500 | [diff] [blame] | 567 | #endif |
PriyangaRamasamy | c0d1c0a | 2021-04-16 09:45:06 -0500 | [diff] [blame] | 568 | } |
SunnySrivastava1984 | e12b181 | 2020-05-26 02:23:11 -0500 | [diff] [blame] | 569 | } |
| 570 | catch (const std::exception& e) |
| 571 | { |
| 572 | if (ipzParser != nullptr) |
| 573 | { |
| 574 | delete ipzParser; |
| 575 | } |
| 576 | throw std::runtime_error(e.what()); |
| 577 | } |
SunnySrivastava1984 | 6d8314d | 2020-05-15 09:34:58 -0500 | [diff] [blame] | 578 | return; |
| 579 | } |
Priyanga Ramasamy | c99a0b0 | 2022-06-08 14:53:39 -0500 | [diff] [blame] | 580 | else |
| 581 | { |
| 582 | throw openpower::vpd::exceptions::VpdDataException( |
| 583 | "Could not find start tag in VPD " + vpdFilePath); |
| 584 | } |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 585 | } |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 586 | } // namespace editor |
| 587 | } // namespace manager |
| 588 | } // namespace vpd |
Santosh Puranik | 32c4650 | 2022-02-10 08:55:07 +0530 | [diff] [blame] | 589 | } // namespace openpower |