1 #pragma once 2 3 #include "config.h" 4 5 #include "constants.hpp" 6 #include "event_logger.hpp" 7 #include "exceptions.hpp" 8 #include "logger.hpp" 9 #include "types.hpp" 10 11 #include <nlohmann/json.hpp> 12 #include <utility/common_utility.hpp> 13 #include <utility/dbus_utility.hpp> 14 15 #include <filesystem> 16 #include <fstream> 17 #include <regex> 18 #include <typeindex> 19 20 namespace vpd 21 { 22 namespace vpdSpecificUtility 23 { 24 /** 25 * @brief API to generate file name for bad VPD. 26 * 27 * For i2c eeproms - the pattern of the vpd-name will be 28 * i2c-<bus-number>-<eeprom-address>. 29 * For spi eeproms - the pattern of the vpd-name will be spi-<spi-number>. 30 * 31 * @param[in] i_vpdFilePath - file path of the vpd. 32 * 33 * @return On success, returns generated file name, otherwise returns empty 34 * string. 35 */ 36 inline std::string generateBadVPDFileName( 37 const std::string& i_vpdFilePath) noexcept 38 { 39 std::string l_badVpdFileName{constants::badVpdDir}; 40 try 41 { 42 if (i_vpdFilePath.find("i2c") != std::string::npos) 43 { 44 l_badVpdFileName += "i2c-"; 45 std::regex l_i2cPattern("(at24/)([0-9]+-[0-9]+)\\/"); 46 std::smatch l_match; 47 if (std::regex_search(i_vpdFilePath, l_match, l_i2cPattern)) 48 { 49 l_badVpdFileName += l_match.str(2); 50 } 51 } 52 else if (i_vpdFilePath.find("spi") != std::string::npos) 53 { 54 std::regex l_spiPattern("((spi)[0-9]+)(.0)"); 55 std::smatch l_match; 56 if (std::regex_search(i_vpdFilePath, l_match, l_spiPattern)) 57 { 58 l_badVpdFileName += l_match.str(1); 59 } 60 } 61 } 62 catch (const std::exception& l_ex) 63 { 64 l_badVpdFileName.clear(); 65 logging::logMessage("Failed to generate bad VPD file name for [" + 66 i_vpdFilePath + "]. Error: " + l_ex.what()); 67 } 68 return l_badVpdFileName; 69 } 70 71 /** 72 * @brief API which dumps the broken/bad vpd in a directory. 73 * When the vpd is bad, this API places the bad vpd file inside 74 * "/var/lib/vpd/dumps" in BMC, in order to collect bad VPD data as a part of 75 * user initiated BMC dump. 76 * 77 * 78 * @param[in] i_vpdFilePath - vpd file path 79 * @param[in] i_vpdVector - vpd vector 80 * 81 * @return On success returns 0, otherwise returns -1. 82 */ 83 inline int dumpBadVpd(const std::string& i_vpdFilePath, 84 const types::BinaryVector& i_vpdVector) noexcept 85 { 86 int l_rc{constants::FAILURE}; 87 try 88 { 89 std::filesystem::create_directory(constants::badVpdDir); 90 auto l_badVpdPath = generateBadVPDFileName(i_vpdFilePath); 91 92 if (l_badVpdPath.empty()) 93 { 94 throw std::runtime_error("Failed to generate bad VPD file name"); 95 } 96 97 if (std::filesystem::exists(l_badVpdPath)) 98 { 99 std::error_code l_ec; 100 std::filesystem::remove(l_badVpdPath, l_ec); 101 if (l_ec) // error code 102 { 103 const std::string l_errorMsg{ 104 "Error removing the existing broken vpd in " + 105 l_badVpdPath + 106 ". Error code : " + std::to_string(l_ec.value()) + 107 ". Error message : " + l_ec.message()}; 108 109 throw std::runtime_error(l_errorMsg); 110 } 111 } 112 113 std::ofstream l_badVpdFileStream(l_badVpdPath, std::ofstream::binary); 114 if (!l_badVpdFileStream.is_open()) 115 { 116 const std::string l_errorMsg{ 117 "Failed to open bad vpd file path [" + l_badVpdPath + 118 "]. Unable to dump the broken/bad vpd file."}; 119 120 throw std::runtime_error(l_errorMsg); 121 } 122 123 l_badVpdFileStream.write( 124 reinterpret_cast<const char*>(i_vpdVector.data()), 125 i_vpdVector.size()); 126 127 l_rc = constants::SUCCESS; 128 } 129 catch (const std::exception& l_ex) 130 { 131 logging::logMessage("Failed to dump bad VPD for [" + i_vpdFilePath + 132 "]. Error: " + l_ex.what()); 133 } 134 return l_rc; 135 } 136 137 /** 138 * @brief An API to read value of a keyword. 139 * 140 * 141 * @param[in] i_kwdValueMap - A map having Kwd value pair. 142 * @param[in] i_kwd - keyword name. 143 * 144 * @return On success returns value of the keyword read from map, otherwise 145 * returns empty string. 146 */ 147 inline std::string getKwVal(const types::IPZKwdValueMap& i_kwdValueMap, 148 const std::string& i_kwd) noexcept 149 { 150 std::string l_kwdValue; 151 try 152 { 153 if (i_kwd.empty()) 154 { 155 throw std::runtime_error("Invalid parameters"); 156 } 157 158 auto l_itrToKwd = i_kwdValueMap.find(i_kwd); 159 if (l_itrToKwd != i_kwdValueMap.end()) 160 { 161 l_kwdValue = l_itrToKwd->second; 162 } 163 else 164 { 165 throw std::runtime_error("Keyword not found"); 166 } 167 } 168 catch (const std::exception& l_ex) 169 { 170 logging::logMessage("Failed to get value for keyword [" + i_kwd + 171 "]. Error : " + l_ex.what()); 172 } 173 return l_kwdValue; 174 } 175 176 /** 177 * @brief An API to process encoding of a keyword. 178 * 179 * @param[in] i_keyword - Keyword to be processed. 180 * @param[in] i_encoding - Type of encoding. 181 * 182 * @return Value after being processed for encoded type. 183 */ 184 inline std::string encodeKeyword(const std::string& i_keyword, 185 const std::string& i_encoding) noexcept 186 { 187 // Default value is keyword value 188 std::string l_result(i_keyword.begin(), i_keyword.end()); 189 try 190 { 191 if (i_encoding == "MAC") 192 { 193 l_result.clear(); 194 size_t l_firstByte = i_keyword[0]; 195 l_result += commonUtility::toHex(l_firstByte >> 4); 196 l_result += commonUtility::toHex(l_firstByte & 0x0f); 197 for (size_t i = 1; i < i_keyword.size(); ++i) 198 { 199 l_result += ":"; 200 l_result += commonUtility::toHex(i_keyword[i] >> 4); 201 l_result += commonUtility::toHex(i_keyword[i] & 0x0f); 202 } 203 } 204 else if (i_encoding == "DATE") 205 { 206 // Date, represent as 207 // <year>-<month>-<day> <hour>:<min> 208 l_result.clear(); 209 static constexpr uint8_t skipPrefix = 3; 210 211 auto strItr = i_keyword.begin(); 212 advance(strItr, skipPrefix); 213 for_each(strItr, i_keyword.end(), 214 [&l_result](size_t c) { l_result += c; }); 215 216 l_result.insert(constants::BD_YEAR_END, 1, '-'); 217 l_result.insert(constants::BD_MONTH_END, 1, '-'); 218 l_result.insert(constants::BD_DAY_END, 1, ' '); 219 l_result.insert(constants::BD_HOUR_END, 1, ':'); 220 } 221 } 222 catch (const std::exception& l_ex) 223 { 224 l_result.clear(); 225 logging::logMessage("Failed to encode keyword [" + i_keyword + 226 "]. Error: " + l_ex.what()); 227 } 228 229 return l_result; 230 } 231 232 /** 233 * @brief Helper function to insert or merge in map. 234 * 235 * This method checks in an interface if the given interface exists. If the 236 * interface key already exists, property map is inserted corresponding to it. 237 * If the key does'nt exist then given interface and property map pair is newly 238 * created. If the property present in propertymap already exist in the 239 * InterfaceMap, then the new property value is ignored. 240 * 241 * @param[in,out] io_map - Interface map. 242 * @param[in] i_interface - Interface to be processed. 243 * @param[in] i_propertyMap - new property map that needs to be emplaced. 244 * 245 * @return On success returns 0, otherwise returns -1. 246 */ 247 inline int insertOrMerge(types::InterfaceMap& io_map, 248 const std::string& i_interface, 249 types::PropertyMap&& i_propertyMap) noexcept 250 { 251 int l_rc{constants::FAILURE}; 252 try 253 { 254 if (io_map.find(i_interface) != io_map.end()) 255 { 256 auto& l_prop = io_map.at(i_interface); 257 std::for_each(i_propertyMap.begin(), i_propertyMap.end(), 258 [&l_prop](auto l_keyValue) { 259 l_prop[l_keyValue.first] = l_keyValue.second; 260 }); 261 } 262 else 263 { 264 io_map.emplace(i_interface, i_propertyMap); 265 } 266 267 l_rc = constants::SUCCESS; 268 } 269 catch (const std::exception& l_ex) 270 { 271 // ToDo:: Log PEL 272 logging::logMessage( 273 "Inserting properties into interface[" + i_interface + 274 "] map failed, reason: " + std::string(l_ex.what())); 275 } 276 return l_rc; 277 } 278 279 /** 280 * @brief API to expand unpanded location code. 281 * 282 * Note: The API handles all the exception internally, in case of any error 283 * unexpanded location code will be returned as it is. 284 * 285 * @param[in] unexpandedLocationCode - Unexpanded location code. 286 * @param[in] parsedVpdMap - Parsed VPD map. 287 * @return Expanded location code. In case of any error, unexpanded is returned 288 * as it is. 289 */ 290 inline std::string getExpandedLocationCode( 291 const std::string& unexpandedLocationCode, 292 const types::VPDMapVariant& parsedVpdMap) 293 { 294 auto expanded{unexpandedLocationCode}; 295 296 try 297 { 298 // Expanded location code is formed by combining two keywords 299 // depending on type in unexpanded one. Second one is always "SE". 300 std::string kwd1, kwd2{constants::kwdSE}; 301 302 // interface to search for required keywords; 303 std::string kwdInterface; 304 305 // record which holds the required keywords. 306 std::string recordName; 307 308 auto pos = unexpandedLocationCode.find("fcs"); 309 if (pos != std::string::npos) 310 { 311 kwd1 = constants::kwdFC; 312 kwdInterface = constants::vcenInf; 313 recordName = constants::recVCEN; 314 } 315 else 316 { 317 pos = unexpandedLocationCode.find("mts"); 318 if (pos != std::string::npos) 319 { 320 kwd1 = constants::kwdTM; 321 kwdInterface = constants::vsysInf; 322 recordName = constants::recVSYS; 323 } 324 else 325 { 326 throw std::runtime_error( 327 "Error detecting type of unexpanded location code."); 328 } 329 } 330 331 std::string firstKwdValue, secondKwdValue; 332 333 if (auto ipzVpdMap = std::get_if<types::IPZVpdMap>(&parsedVpdMap); 334 ipzVpdMap && (*ipzVpdMap).find(recordName) != (*ipzVpdMap).end()) 335 { 336 auto itrToVCEN = (*ipzVpdMap).find(recordName); 337 firstKwdValue = getKwVal(itrToVCEN->second, kwd1); 338 if (firstKwdValue.empty()) 339 { 340 throw std::runtime_error( 341 "Failed to get value for keyword [" + kwd1 + "]"); 342 } 343 344 secondKwdValue = getKwVal(itrToVCEN->second, kwd2); 345 if (secondKwdValue.empty()) 346 { 347 throw std::runtime_error( 348 "Failed to get value for keyword [" + kwd2 + "]"); 349 } 350 } 351 else 352 { 353 std::array<const char*, 1> interfaceList = {kwdInterface.c_str()}; 354 355 types::MapperGetObject mapperRetValue = dbusUtility::getObjectMap( 356 std::string(constants::systemVpdInvPath), interfaceList); 357 358 if (mapperRetValue.empty()) 359 { 360 throw std::runtime_error("Mapper failed to get service"); 361 } 362 363 const std::string& serviceName = std::get<0>(mapperRetValue.at(0)); 364 365 auto retVal = dbusUtility::readDbusProperty( 366 serviceName, std::string(constants::systemVpdInvPath), 367 kwdInterface, kwd1); 368 369 if (auto kwdVal = std::get_if<types::BinaryVector>(&retVal)) 370 { 371 firstKwdValue.assign( 372 reinterpret_cast<const char*>(kwdVal->data()), 373 kwdVal->size()); 374 } 375 else 376 { 377 throw std::runtime_error( 378 "Failed to read value of " + kwd1 + " from Bus"); 379 } 380 381 retVal = dbusUtility::readDbusProperty( 382 serviceName, std::string(constants::systemVpdInvPath), 383 kwdInterface, kwd2); 384 385 if (auto kwdVal = std::get_if<types::BinaryVector>(&retVal)) 386 { 387 secondKwdValue.assign( 388 reinterpret_cast<const char*>(kwdVal->data()), 389 kwdVal->size()); 390 } 391 else 392 { 393 throw std::runtime_error( 394 "Failed to read value of " + kwd2 + " from Bus"); 395 } 396 } 397 398 if (unexpandedLocationCode.find("fcs") != std::string::npos) 399 { 400 // TODO: See if ND0 can be placed in the JSON 401 expanded.replace( 402 pos, 3, firstKwdValue.substr(0, 4) + ".ND0." + secondKwdValue); 403 } 404 else 405 { 406 replace(firstKwdValue.begin(), firstKwdValue.end(), '-', '.'); 407 expanded.replace(pos, 3, firstKwdValue + "." + secondKwdValue); 408 } 409 } 410 catch (const std::exception& ex) 411 { 412 logging::logMessage("Failed to expand location code with exception: " + 413 std::string(ex.what())); 414 } 415 416 return expanded; 417 } 418 419 /** 420 * @brief An API to get VPD in a vector. 421 * 422 * The vector is required by the respective parser to fill the VPD map. 423 * Note: API throws exception in case of failure. Caller needs to handle. 424 * 425 * @param[in] vpdFilePath - EEPROM path of the FRU. 426 * @param[out] vpdVector - VPD in vector form. 427 * @param[in] vpdStartOffset - Offset of VPD data in EEPROM. 428 */ 429 inline void getVpdDataInVector(const std::string& vpdFilePath, 430 types::BinaryVector& vpdVector, 431 size_t& vpdStartOffset) 432 { 433 try 434 { 435 std::fstream vpdFileStream; 436 vpdFileStream.exceptions( 437 std::ifstream::badbit | std::ifstream::failbit); 438 vpdFileStream.open(vpdFilePath, std::ios::in | std::ios::binary); 439 auto vpdSizeToRead = std::min(std::filesystem::file_size(vpdFilePath), 440 static_cast<uintmax_t>(65504)); 441 vpdVector.resize(vpdSizeToRead); 442 443 vpdFileStream.seekg(vpdStartOffset, std::ios_base::beg); 444 vpdFileStream.read(reinterpret_cast<char*>(&vpdVector[0]), 445 vpdSizeToRead); 446 447 vpdVector.resize(vpdFileStream.gcount()); 448 vpdFileStream.clear(std::ios_base::eofbit); 449 } 450 catch (const std::ifstream::failure& fail) 451 { 452 std::cerr << "Exception in file handling [" << vpdFilePath 453 << "] error : " << fail.what(); 454 throw; 455 } 456 } 457 458 /** 459 * @brief An API to get D-bus representation of given VPD keyword. 460 * 461 * @param[in] i_keywordName - VPD keyword name. 462 * 463 * @return D-bus representation of given keyword. 464 */ 465 inline std::string getDbusPropNameForGivenKw(const std::string& i_keywordName) 466 { 467 // Check for "#" prefixed VPD keyword. 468 if ((i_keywordName.size() == vpd::constants::TWO_BYTES) && 469 (i_keywordName.at(0) == constants::POUND_KW)) 470 { 471 // D-bus doesn't support "#". Replace "#" with "PD_" for those "#" 472 // prefixed keywords. 473 return (std::string(constants::POUND_KW_PREFIX) + 474 i_keywordName.substr(1)); 475 } 476 477 // Return the keyword name back, if D-bus representation is same as the VPD 478 // keyword name. 479 return i_keywordName; 480 } 481 482 /** 483 * @brief API to find CCIN in parsed VPD map. 484 * 485 * Few FRUs need some special handling. To identify those FRUs CCIN are used. 486 * The API will check from parsed VPD map if the FRU is the one with desired 487 * CCIN. 488 * 489 * @param[in] i_JsonObject - Any JSON which contains CCIN tag to match. 490 * @param[in] i_parsedVpdMap - Parsed VPD map. 491 * 492 * @return True if found, false otherwise. 493 */ 494 inline bool findCcinInVpd(const nlohmann::json& i_JsonObject, 495 const types::VPDMapVariant& i_parsedVpdMap) noexcept 496 { 497 bool l_rc{false}; 498 try 499 { 500 if (i_JsonObject.empty()) 501 { 502 throw std::runtime_error("Json object is empty. Can't find CCIN"); 503 } 504 505 if (auto l_ipzVPDMap = std::get_if<types::IPZVpdMap>(&i_parsedVpdMap)) 506 { 507 auto l_itrToRec = (*l_ipzVPDMap).find("VINI"); 508 if (l_itrToRec == (*l_ipzVPDMap).end()) 509 { 510 throw DataException( 511 "VINI record not found in parsed VPD. Can't find CCIN"); 512 } 513 514 std::string l_ccinFromVpd{ 515 vpdSpecificUtility::getKwVal(l_itrToRec->second, "CC")}; 516 if (l_ccinFromVpd.empty()) 517 { 518 throw DataException( 519 "Empty CCIN value in VPD map. Can't find CCIN"); 520 } 521 522 transform(l_ccinFromVpd.begin(), l_ccinFromVpd.end(), 523 l_ccinFromVpd.begin(), ::toupper); 524 525 for (std::string l_ccinValue : i_JsonObject["ccin"]) 526 { 527 transform(l_ccinValue.begin(), l_ccinValue.end(), 528 l_ccinValue.begin(), ::toupper); 529 530 if (l_ccinValue.compare(l_ccinFromVpd) == 531 constants::STR_CMP_SUCCESS) 532 { 533 // CCIN found 534 l_rc = true; 535 } 536 } 537 538 if (!l_rc) 539 { 540 logging::logMessage("No match found for CCIN"); 541 } 542 } 543 else 544 { 545 logging::logMessage("VPD type not supported. Can't find CCIN"); 546 } 547 } 548 catch (const std::exception& l_ex) 549 { 550 const std::string l_errMsg{ 551 "Failed to find CCIN in VPD. Error : " + std::string(l_ex.what())}; 552 553 if (typeid(l_ex) == std::type_index(typeid(DataException))) 554 { 555 EventLogger::createSyncPel( 556 types::ErrorType::InvalidVpdMessage, 557 types::SeverityType::Informational, __FILE__, __FUNCTION__, 0, 558 l_errMsg, std::nullopt, std::nullopt, std::nullopt, 559 std::nullopt); 560 } 561 562 logging::logMessage(l_errMsg); 563 } 564 return l_rc; 565 } 566 567 /** 568 * @brief API to reset data of a FRU populated under PIM. 569 * 570 * This API resets the data for particular interfaces of a FRU under PIM. 571 * 572 * @param[in] i_objectPath - DBus object path of the FRU. 573 * @param[in] io_interfaceMap - Interface and its properties map. 574 */ 575 inline void resetDataUnderPIM(const std::string& i_objectPath, 576 types::InterfaceMap& io_interfaceMap) 577 { 578 try 579 { 580 std::array<const char*, 0> l_interfaces; 581 const types::MapperGetObject& l_getObjectMap = 582 dbusUtility::getObjectMap(i_objectPath, l_interfaces); 583 584 const std::vector<std::string>& l_vpdRelatedInterfaces{ 585 constants::operationalStatusInf, constants::inventoryItemInf, 586 constants::assetInf}; 587 588 for (const auto& [l_service, l_interfaceList] : l_getObjectMap) 589 { 590 if (l_service.compare(constants::pimServiceName) != 591 constants::STR_CMP_SUCCESS) 592 { 593 continue; 594 } 595 596 for (const auto& l_interface : l_interfaceList) 597 { 598 if ((l_interface.find(constants::ipzVpdInf) != 599 std::string::npos) || 600 ((std::find(l_vpdRelatedInterfaces.begin(), 601 l_vpdRelatedInterfaces.end(), l_interface)) != 602 l_vpdRelatedInterfaces.end())) 603 { 604 const types::PropertyMap& l_propertyValueMap = 605 dbusUtility::getPropertyMap(l_service, i_objectPath, 606 l_interface); 607 608 types::PropertyMap l_propertyMap; 609 610 for (const auto& l_aProperty : l_propertyValueMap) 611 { 612 const std::string& l_propertyName = l_aProperty.first; 613 const auto& l_propertyValue = l_aProperty.second; 614 615 if (std::holds_alternative<types::BinaryVector>( 616 l_propertyValue)) 617 { 618 l_propertyMap.emplace(l_propertyName, 619 types::BinaryVector{}); 620 } 621 else if (std::holds_alternative<std::string>( 622 l_propertyValue)) 623 { 624 l_propertyMap.emplace(l_propertyName, 625 std::string{}); 626 } 627 else if (std::holds_alternative<bool>(l_propertyValue)) 628 { 629 // ToDo -- Update the functional status property 630 // to true. 631 if (l_propertyName.compare("Present") == 632 constants::STR_CMP_SUCCESS) 633 { 634 l_propertyMap.emplace(l_propertyName, false); 635 } 636 } 637 } 638 io_interfaceMap.emplace(l_interface, 639 std::move(l_propertyMap)); 640 } 641 } 642 } 643 } 644 catch (const std::exception& l_ex) 645 { 646 logging::logMessage("Failed to remove VPD for FRU: " + i_objectPath + 647 " with error: " + std::string(l_ex.what())); 648 } 649 } 650 651 /** 652 * @brief API to detect pass1 planar type. 653 * 654 * Based on HW version and IM keyword, This API detects is it is a pass1 planar 655 * or not. 656 * 657 * @return True if pass 1 planar, false otherwise. 658 */ 659 inline bool isPass1Planar() noexcept 660 { 661 bool l_rc{false}; 662 try 663 { 664 auto l_retVal = dbusUtility::readDbusProperty( 665 constants::pimServiceName, constants::systemVpdInvPath, 666 constants::viniInf, constants::kwdHW); 667 668 auto l_hwVer = std::get_if<types::BinaryVector>(&l_retVal); 669 670 l_retVal = dbusUtility::readDbusProperty( 671 constants::pimServiceName, constants::systemInvPath, 672 constants::vsbpInf, constants::kwdIM); 673 674 auto l_imValue = std::get_if<types::BinaryVector>(&l_retVal); 675 676 if (l_hwVer && l_imValue) 677 { 678 if (l_hwVer->size() != constants::VALUE_2) 679 { 680 throw std::runtime_error("Invalid HW keyword length."); 681 } 682 683 if (l_imValue->size() != constants::VALUE_4) 684 { 685 throw std::runtime_error("Invalid IM keyword length."); 686 } 687 688 const types::BinaryVector l_everest{80, 00, 48, 00}; 689 const types::BinaryVector l_fuji{96, 00, 32, 00}; 690 691 if (((*l_imValue) == l_everest) || ((*l_imValue) == l_fuji)) 692 { 693 if ((*l_hwVer).at(1) < constants::VALUE_21) 694 { 695 l_rc = true; 696 } 697 } 698 else if ((*l_hwVer).at(1) < constants::VALUE_2) 699 { 700 l_rc = true; 701 } 702 } 703 } 704 catch (const std::exception& l_ex) 705 { 706 logging::logMessage("Failed to check for pass 1 planar. Error: " + 707 std::string(l_ex.what())); 708 } 709 710 return l_rc; 711 } 712 713 /** 714 * @brief API to detect if system configuration is that of PowerVS system. 715 * 716 * @param[in] i_imValue - IM value of the system. 717 * @return true if it is PowerVS configuration, false otherwise. 718 */ 719 inline bool isPowerVsConfiguration(const types::BinaryVector& i_imValue) 720 { 721 if (i_imValue.empty() || i_imValue.size() != constants::VALUE_4) 722 { 723 return false; 724 } 725 726 // Should be a 0x5000XX series system. 727 if (i_imValue.at(0) == constants::HEX_VALUE_50 && 728 i_imValue.at(1) == constants::HEX_VALUE_00) 729 { 730 std::string l_imagePrefix = dbusUtility::getImagePrefix(); 731 732 // Check image for 0x500030XX series. 733 if ((i_imValue.at(2) == constants::HEX_VALUE_30) && 734 ((l_imagePrefix == constants::powerVsImagePrefix_MY) || 735 (l_imagePrefix == constants::powerVsImagePrefix_NY))) 736 { 737 logging::logMessage("PowerVS configuration"); 738 return true; 739 } 740 741 // Check image for 0X500010XX series. 742 if ((i_imValue.at(2) == constants::HEX_VALUE_10) && 743 ((l_imagePrefix == constants::powerVsImagePrefix_MZ) || 744 (l_imagePrefix == constants::powerVsImagePrefix_NZ))) 745 { 746 logging::logMessage("PowerVS configuration"); 747 return true; 748 } 749 } 750 return false; 751 } 752 753 /** 754 * @brief API to get CCIN for a given FRU from DBus. 755 * 756 * The API reads the CCIN for a FRU based on its inventory path. 757 * 758 * @param[in] i_invObjPath - Inventory path of the FRU. 759 * @return CCIN of the FRU on success, empty string otherwise. 760 */ 761 inline std::string getCcinFromDbus(const std::string& i_invObjPath) 762 { 763 try 764 { 765 if (i_invObjPath.empty()) 766 { 767 throw std::runtime_error("Empty EEPROM path, can't read CCIN"); 768 } 769 770 const auto& l_retValue = dbusUtility::readDbusProperty( 771 constants::pimServiceName, i_invObjPath, constants::viniInf, 772 constants::kwdCCIN); 773 774 auto l_ptrCcin = std::get_if<types::BinaryVector>(&l_retValue); 775 if (!l_ptrCcin || (*l_ptrCcin).size() != constants::VALUE_4) 776 { 777 throw DbusException("Invalid CCIN read from Dbus"); 778 } 779 780 return std::string((*l_ptrCcin).begin(), (*l_ptrCcin).end()); 781 } 782 catch (const std::exception& l_ex) 783 { 784 logging::logMessage(l_ex.what()); 785 return std::string{}; 786 } 787 } 788 789 /** 790 * @brief API to check if the current running image is a powerVS image. 791 * 792 * @return true if it is PowerVS image, false otherwise. 793 */ 794 inline bool isPowerVsImage() 795 { 796 std::string l_imagePrefix = dbusUtility::getImagePrefix(); 797 798 if ((l_imagePrefix == constants::powerVsImagePrefix_MY) || 799 (l_imagePrefix == constants::powerVsImagePrefix_NY) || 800 (l_imagePrefix == constants::powerVsImagePrefix_MZ) || 801 (l_imagePrefix == constants::powerVsImagePrefix_NZ)) 802 { 803 return true; 804 } 805 return false; 806 } 807 } // namespace vpdSpecificUtility 808 } // namespace vpd 809