1 /* 2 // Copyright (c) 2018 Intel Corporation 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 */ 16 17 #include "system.hpp" 18 19 #include "mdrv2.hpp" 20 21 #include <fstream> 22 #include <iomanip> 23 #include <iostream> 24 #include <sstream> 25 namespace phosphor 26 { 27 namespace smbios 28 { 29 30 std::string System::uuid(std::string value) 31 { 32 uint8_t* dataIn = storage; 33 dataIn = getSMBIOSTypePtr(dataIn, systemType); 34 if (dataIn != nullptr) 35 { 36 auto systemInfo = reinterpret_cast<struct SystemInfo*>(dataIn); 37 std::stringstream stream; 38 stream << std::setfill('0') << std::hex; 39 stream << std::setw(8) << systemInfo->uuid.timeLow; 40 stream << "-"; 41 stream << std::setw(4) << systemInfo->uuid.timeMid; 42 stream << "-"; 43 stream << std::setw(4) << systemInfo->uuid.timeHiAndVer; 44 stream << "-"; 45 stream << std::setw(2) << static_cast<int>(systemInfo->uuid.clockSeqHi); 46 stream << std::setw(2) 47 << static_cast<int>(systemInfo->uuid.clockSeqLow); 48 stream << "-"; 49 static_assert(sizeof(systemInfo->uuid.node) == 6); 50 stream << std::setw(2) << static_cast<int>(systemInfo->uuid.node[0]); 51 stream << std::setw(2) << static_cast<int>(systemInfo->uuid.node[1]); 52 stream << std::setw(2) << static_cast<int>(systemInfo->uuid.node[2]); 53 stream << std::setw(2) << static_cast<int>(systemInfo->uuid.node[3]); 54 stream << std::setw(2) << static_cast<int>(systemInfo->uuid.node[4]); 55 stream << std::setw(2) << static_cast<int>(systemInfo->uuid.node[5]); 56 57 return sdbusplus::xyz::openbmc_project::Common::server::UUID::uuid( 58 stream.str()); 59 } 60 61 return sdbusplus::xyz::openbmc_project::Common::server::UUID::uuid( 62 "00000000-0000-0000-0000-000000000000"); 63 } 64 65 std::string System::version(std::string value) 66 { 67 std::string result = "No BIOS Version"; 68 uint8_t* dataIn = storage; 69 dataIn = getSMBIOSTypePtr(dataIn, biosType); 70 if (dataIn != nullptr) 71 { 72 auto biosInfo = reinterpret_cast<struct BIOSInfo*>(dataIn); 73 uint8_t biosVerByte = biosInfo->biosVersion; 74 std::string tempS = 75 positionToString(biosInfo->biosVersion, biosInfo->length, dataIn); 76 if (std::find_if(tempS.begin(), tempS.end(), 77 [](char ch) { return !isprint(ch); }) != tempS.end()) 78 { 79 std::ofstream smbiosFile(mdrType2File, std::ios_base::trunc); 80 if (!smbiosFile.good()) 81 { 82 phosphor::logging::log<phosphor::logging::level::ERR>( 83 "Open MDRV2 table file failure"); 84 return result; 85 } 86 smbiosFile.clear(); 87 smbiosFile.close(); 88 phosphor::logging::log<phosphor::logging::level::ERR>( 89 "Find non-print char, delete the broken MDRV2 table file!"); 90 return sdbusplus::xyz::openbmc_project::Inventory::Decorator:: 91 server::Revision::version(result); 92 } 93 result = tempS; 94 } 95 lg2::info("VERSION INFO - BIOS - {VER}", "VER", result); 96 return sdbusplus::xyz::openbmc_project::Inventory::Decorator::server:: 97 Revision::version(result); 98 } 99 100 } // namespace smbios 101 } // namespace phosphor 102