1b4651b9cSCheng C Yang /* 2b4651b9cSCheng C Yang // Copyright (c) 2018 Intel Corporation 3b4651b9cSCheng C Yang // 4b4651b9cSCheng C Yang // Licensed under the Apache License, Version 2.0 (the "License"); 5b4651b9cSCheng C Yang // you may not use this file except in compliance with the License. 6b4651b9cSCheng C Yang // You may obtain a copy of the License at 7b4651b9cSCheng C Yang // 8b4651b9cSCheng C Yang // http://www.apache.org/licenses/LICENSE-2.0 9b4651b9cSCheng C Yang // 10b4651b9cSCheng C Yang // Unless required by applicable law or agreed to in writing, software 11b4651b9cSCheng C Yang // distributed under the License is distributed on an "AS IS" BASIS, 12b4651b9cSCheng C Yang // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13b4651b9cSCheng C Yang // See the License for the specific language governing permissions and 14b4651b9cSCheng C Yang // limitations under the License. 15b4651b9cSCheng C Yang */ 16b4651b9cSCheng C Yang 17b4651b9cSCheng C Yang #include "system.hpp" 18b4651b9cSCheng C Yang 19b4651b9cSCheng C Yang #include "mdrv2.hpp" 20b4651b9cSCheng C Yang 2126de0d73SKuiying Wang #include <fstream> 22b4651b9cSCheng C Yang #include <iomanip> 23b4651b9cSCheng C Yang #include <iostream> 24b4651b9cSCheng C Yang #include <sstream> 257393e48dSJayaprakash Mutyala 267393e48dSJayaprakash Mutyala static constexpr const char* biosActiveObjPath = 277393e48dSJayaprakash Mutyala "/xyz/openbmc_project/software/bios_active"; 287393e48dSJayaprakash Mutyala static constexpr const char* biosVersionIntf = 297393e48dSJayaprakash Mutyala "xyz.openbmc_project.Software.Version"; 307393e48dSJayaprakash Mutyala static constexpr const char* biosVersionProp = "Version"; 317393e48dSJayaprakash Mutyala 32b4651b9cSCheng C Yang namespace phosphor 33b4651b9cSCheng C Yang { 34b4651b9cSCheng C Yang namespace smbios 35b4651b9cSCheng C Yang { 36b4651b9cSCheng C Yang 37e7770991SJason M. Bills std::string System::uuid(std::string value) 38b4651b9cSCheng C Yang { 39b4651b9cSCheng C Yang uint8_t* dataIn = storage; 40b4651b9cSCheng C Yang dataIn = getSMBIOSTypePtr(dataIn, systemType); 41b4651b9cSCheng C Yang if (dataIn != nullptr) 42b4651b9cSCheng C Yang { 43b4651b9cSCheng C Yang auto systemInfo = reinterpret_cast<struct SystemInfo*>(dataIn); 44b4651b9cSCheng C Yang std::stringstream stream; 45b4651b9cSCheng C Yang stream << std::setfill('0') << std::hex; 46e7770991SJason M. Bills stream << std::setw(8) << systemInfo->uuid.timeLow; 47b4651b9cSCheng C Yang stream << "-"; 48e7770991SJason M. Bills stream << std::setw(4) << systemInfo->uuid.timeMid; 49b4651b9cSCheng C Yang stream << "-"; 50e7770991SJason M. Bills stream << std::setw(4) << systemInfo->uuid.timeHiAndVer; 51b4651b9cSCheng C Yang stream << "-"; 52e7770991SJason M. Bills stream << std::setw(2) << static_cast<int>(systemInfo->uuid.clockSeqHi); 53b4651b9cSCheng C Yang stream << std::setw(2) 54e7770991SJason M. Bills << static_cast<int>(systemInfo->uuid.clockSeqLow); 55b4651b9cSCheng C Yang stream << "-"; 56e7770991SJason M. Bills static_assert(sizeof(systemInfo->uuid.node) == 6); 57e7770991SJason M. Bills stream << std::setw(2) << static_cast<int>(systemInfo->uuid.node[0]); 58e7770991SJason M. Bills stream << std::setw(2) << static_cast<int>(systemInfo->uuid.node[1]); 59e7770991SJason M. Bills stream << std::setw(2) << static_cast<int>(systemInfo->uuid.node[2]); 60e7770991SJason M. Bills stream << std::setw(2) << static_cast<int>(systemInfo->uuid.node[3]); 61e7770991SJason M. Bills stream << std::setw(2) << static_cast<int>(systemInfo->uuid.node[4]); 62e7770991SJason M. Bills stream << std::setw(2) << static_cast<int>(systemInfo->uuid.node[5]); 63b4651b9cSCheng C Yang 64e7770991SJason M. Bills return sdbusplus::xyz::openbmc_project::Common::server::UUID::uuid( 65b4651b9cSCheng C Yang stream.str()); 66b4651b9cSCheng C Yang } 67b4651b9cSCheng C Yang 68e7770991SJason M. Bills return sdbusplus::xyz::openbmc_project::Common::server::UUID::uuid( 69b4651b9cSCheng C Yang "00000000-0000-0000-0000-000000000000"); 70b4651b9cSCheng C Yang } 71b4651b9cSCheng C Yang 72*966fcb10SPatrick Williams static std::string getService(sdbusplus::bus_t& bus, 737393e48dSJayaprakash Mutyala const std::string& objectPath, 747393e48dSJayaprakash Mutyala const std::string& interface) 757393e48dSJayaprakash Mutyala { 767393e48dSJayaprakash Mutyala auto method = 777393e48dSJayaprakash Mutyala bus.new_method_call("xyz.openbmc_project.ObjectMapper", 787393e48dSJayaprakash Mutyala "/xyz/openbmc_project/object_mapper", 797393e48dSJayaprakash Mutyala "xyz.openbmc_project.ObjectMapper", "GetObject"); 807393e48dSJayaprakash Mutyala 817393e48dSJayaprakash Mutyala method.append(objectPath); 827393e48dSJayaprakash Mutyala method.append(std::vector<std::string>({interface})); 837393e48dSJayaprakash Mutyala 847393e48dSJayaprakash Mutyala std::vector<std::pair<std::string, std::vector<std::string>>> response; 857393e48dSJayaprakash Mutyala 867393e48dSJayaprakash Mutyala try 877393e48dSJayaprakash Mutyala { 887393e48dSJayaprakash Mutyala auto reply = bus.call(method); 897393e48dSJayaprakash Mutyala reply.read(response); 907393e48dSJayaprakash Mutyala } 917393e48dSJayaprakash Mutyala catch (const sdbusplus::exception_t& e) 927393e48dSJayaprakash Mutyala { 937393e48dSJayaprakash Mutyala lg2::error("Error in mapper method call - {ERROR}, SERVICE - " 947393e48dSJayaprakash Mutyala "{SERVICE}, PATH - {PATH}", 957393e48dSJayaprakash Mutyala "ERROR", e.what(), "SERVICE", objectPath.c_str(), "PATH", 967393e48dSJayaprakash Mutyala interface.c_str()); 977393e48dSJayaprakash Mutyala 987393e48dSJayaprakash Mutyala return std::string{}; 997393e48dSJayaprakash Mutyala } 1007393e48dSJayaprakash Mutyala 1017393e48dSJayaprakash Mutyala return response[0].first; 1027393e48dSJayaprakash Mutyala } 1037393e48dSJayaprakash Mutyala 104*966fcb10SPatrick Williams static void setProperty(sdbusplus::bus_t& bus, const std::string& objectPath, 1057393e48dSJayaprakash Mutyala const std::string& interface, 1067393e48dSJayaprakash Mutyala const std::string& propertyName, 1077393e48dSJayaprakash Mutyala const std::string& value) 1087393e48dSJayaprakash Mutyala { 1097393e48dSJayaprakash Mutyala auto service = getService(bus, objectPath, interface); 1107393e48dSJayaprakash Mutyala if (service.empty()) 1117393e48dSJayaprakash Mutyala { 1127393e48dSJayaprakash Mutyala return; 1137393e48dSJayaprakash Mutyala } 1147393e48dSJayaprakash Mutyala 1157393e48dSJayaprakash Mutyala auto method = bus.new_method_call(service.c_str(), objectPath.c_str(), 1167393e48dSJayaprakash Mutyala "org.freedesktop.DBus.Properties", "Set"); 1177393e48dSJayaprakash Mutyala method.append(interface.c_str(), propertyName.c_str(), 1187393e48dSJayaprakash Mutyala std::variant<std::string>{value}); 1197393e48dSJayaprakash Mutyala 1207393e48dSJayaprakash Mutyala bus.call_noreply(method); 1217393e48dSJayaprakash Mutyala } 1227393e48dSJayaprakash Mutyala 123b4651b9cSCheng C Yang std::string System::version(std::string value) 124b4651b9cSCheng C Yang { 125b4651b9cSCheng C Yang std::string result = "No BIOS Version"; 126b4651b9cSCheng C Yang uint8_t* dataIn = storage; 127b4651b9cSCheng C Yang dataIn = getSMBIOSTypePtr(dataIn, biosType); 128b4651b9cSCheng C Yang if (dataIn != nullptr) 129b4651b9cSCheng C Yang { 130b4651b9cSCheng C Yang auto biosInfo = reinterpret_cast<struct BIOSInfo*>(dataIn); 131b4651b9cSCheng C Yang uint8_t biosVerByte = biosInfo->biosVersion; 132b4651b9cSCheng C Yang std::string tempS = 133b4651b9cSCheng C Yang positionToString(biosInfo->biosVersion, biosInfo->length, dataIn); 13426de0d73SKuiying Wang if (std::find_if(tempS.begin(), tempS.end(), 13526de0d73SKuiying Wang [](char ch) { return !isprint(ch); }) != tempS.end()) 13626de0d73SKuiying Wang { 13726de0d73SKuiying Wang std::ofstream smbiosFile(mdrType2File, std::ios_base::trunc); 13826de0d73SKuiying Wang if (!smbiosFile.good()) 13926de0d73SKuiying Wang { 14026de0d73SKuiying Wang phosphor::logging::log<phosphor::logging::level::ERR>( 14126de0d73SKuiying Wang "Open MDRV2 table file failure"); 14226de0d73SKuiying Wang return result; 14326de0d73SKuiying Wang } 14426de0d73SKuiying Wang smbiosFile.clear(); 14526de0d73SKuiying Wang smbiosFile.close(); 14626de0d73SKuiying Wang phosphor::logging::log<phosphor::logging::level::ERR>( 14726de0d73SKuiying Wang "Find non-print char, delete the broken MDRV2 table file!"); 14826de0d73SKuiying Wang return sdbusplus::xyz::openbmc_project::Inventory::Decorator:: 14926de0d73SKuiying Wang server::Revision::version(result); 15026de0d73SKuiying Wang } 151b4651b9cSCheng C Yang result = tempS; 1527393e48dSJayaprakash Mutyala 1537393e48dSJayaprakash Mutyala setProperty(bus, biosActiveObjPath, biosVersionIntf, biosVersionProp, 1547393e48dSJayaprakash Mutyala result); 155b4651b9cSCheng C Yang } 1565f2d6275SAlex Schendel lg2::info("VERSION INFO - BIOS - {VER}", "VER", result); 1577393e48dSJayaprakash Mutyala 158b4651b9cSCheng C Yang return sdbusplus::xyz::openbmc_project::Inventory::Decorator::server:: 159b4651b9cSCheng C Yang Revision::version(result); 160b4651b9cSCheng C Yang } 161b4651b9cSCheng C Yang 162b4651b9cSCheng C Yang } // namespace smbios 163b4651b9cSCheng C Yang } // namespace phosphor 164