Cheng C Yang | b4651b9 | 2019-12-19 00:59:01 +0800 | [diff] [blame] | 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 | |
Kuiying Wang | 26de0d7 | 2020-11-18 19:31:46 +0800 | [diff] [blame] | 21 | #include <fstream> |
Cheng C Yang | b4651b9 | 2019-12-19 00:59:01 +0800 | [diff] [blame] | 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 | { |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 32 | uint8_t* dataIn = storage; |
Cheng C Yang | b4651b9 | 2019-12-19 00:59:01 +0800 | [diff] [blame] | 33 | dataIn = getSMBIOSTypePtr(dataIn, systemType); |
| 34 | if (dataIn != nullptr) |
| 35 | { |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 36 | auto systemInfo = reinterpret_cast<struct SystemInfo*>(dataIn); |
Cheng C Yang | b4651b9 | 2019-12-19 00:59:01 +0800 | [diff] [blame] | 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"; |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 68 | uint8_t* dataIn = storage; |
Cheng C Yang | b4651b9 | 2019-12-19 00:59:01 +0800 | [diff] [blame] | 69 | dataIn = getSMBIOSTypePtr(dataIn, biosType); |
| 70 | if (dataIn != nullptr) |
| 71 | { |
Cheng C Yang | 2ca7a0f | 2019-12-19 10:46:42 +0800 | [diff] [blame] | 72 | auto biosInfo = reinterpret_cast<struct BIOSInfo*>(dataIn); |
Cheng C Yang | b4651b9 | 2019-12-19 00:59:01 +0800 | [diff] [blame] | 73 | uint8_t biosVerByte = biosInfo->biosVersion; |
| 74 | std::string tempS = |
| 75 | positionToString(biosInfo->biosVersion, biosInfo->length, dataIn); |
Kuiying Wang | 26de0d7 | 2020-11-18 19:31:46 +0800 | [diff] [blame] | 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 | } |
Cheng C Yang | b4651b9 | 2019-12-19 00:59:01 +0800 | [diff] [blame] | 93 | result = tempS; |
| 94 | } |
| 95 | |
| 96 | return sdbusplus::xyz::openbmc_project::Inventory::Decorator::server:: |
| 97 | Revision::version(result); |
| 98 | } |
| 99 | |
| 100 | } // namespace smbios |
| 101 | } // namespace phosphor |