blob: 532d979c6b8271f277a9290e799320c7e9491b21 [file] [log] [blame]
Cheng C Yangb4651b92019-12-19 00:59:01 +08001/*
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 Wang26de0d72020-11-18 19:31:46 +080021#include <fstream>
Cheng C Yangb4651b92019-12-19 00:59:01 +080022#include <iomanip>
23#include <iostream>
24#include <sstream>
25namespace phosphor
26{
27namespace smbios
28{
29
Jason M. Billse7770992021-05-14 13:24:33 -070030std::string System::uuid(std::string value)
Cheng C Yangb4651b92019-12-19 00:59:01 +080031{
Cheng C Yang2ca7a0f2019-12-19 10:46:42 +080032 uint8_t* dataIn = storage;
Cheng C Yangb4651b92019-12-19 00:59:01 +080033 dataIn = getSMBIOSTypePtr(dataIn, systemType);
34 if (dataIn != nullptr)
35 {
Cheng C Yang2ca7a0f2019-12-19 10:46:42 +080036 auto systemInfo = reinterpret_cast<struct SystemInfo*>(dataIn);
Cheng C Yangb4651b92019-12-19 00:59:01 +080037 std::stringstream stream;
38 stream << std::setfill('0') << std::hex;
Jason M. Billse7770992021-05-14 13:24:33 -070039 stream << std::setw(8) << systemInfo->uuid.timeLow;
Cheng C Yangb4651b92019-12-19 00:59:01 +080040 stream << "-";
Jason M. Billse7770992021-05-14 13:24:33 -070041 stream << std::setw(4) << systemInfo->uuid.timeMid;
Cheng C Yangb4651b92019-12-19 00:59:01 +080042 stream << "-";
Jason M. Billse7770992021-05-14 13:24:33 -070043 stream << std::setw(4) << systemInfo->uuid.timeHiAndVer;
Cheng C Yangb4651b92019-12-19 00:59:01 +080044 stream << "-";
Jason M. Billse7770992021-05-14 13:24:33 -070045 stream << std::setw(2) << static_cast<int>(systemInfo->uuid.clockSeqHi);
Cheng C Yangb4651b92019-12-19 00:59:01 +080046 stream << std::setw(2)
Jason M. Billse7770992021-05-14 13:24:33 -070047 << static_cast<int>(systemInfo->uuid.clockSeqLow);
Cheng C Yangb4651b92019-12-19 00:59:01 +080048 stream << "-";
Jason M. Billse7770992021-05-14 13:24:33 -070049 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]);
Cheng C Yangb4651b92019-12-19 00:59:01 +080056
Jason M. Billse7770992021-05-14 13:24:33 -070057 return sdbusplus::xyz::openbmc_project::Common::server::UUID::uuid(
Cheng C Yangb4651b92019-12-19 00:59:01 +080058 stream.str());
59 }
60
Jason M. Billse7770992021-05-14 13:24:33 -070061 return sdbusplus::xyz::openbmc_project::Common::server::UUID::uuid(
Cheng C Yangb4651b92019-12-19 00:59:01 +080062 "00000000-0000-0000-0000-000000000000");
63}
64
65std::string System::version(std::string value)
66{
67 std::string result = "No BIOS Version";
Cheng C Yang2ca7a0f2019-12-19 10:46:42 +080068 uint8_t* dataIn = storage;
Cheng C Yangb4651b92019-12-19 00:59:01 +080069 dataIn = getSMBIOSTypePtr(dataIn, biosType);
70 if (dataIn != nullptr)
71 {
Cheng C Yang2ca7a0f2019-12-19 10:46:42 +080072 auto biosInfo = reinterpret_cast<struct BIOSInfo*>(dataIn);
Cheng C Yangb4651b92019-12-19 00:59:01 +080073 uint8_t biosVerByte = biosInfo->biosVersion;
74 std::string tempS =
75 positionToString(biosInfo->biosVersion, biosInfo->length, dataIn);
Kuiying Wang26de0d72020-11-18 19:31:46 +080076 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 Yangb4651b92019-12-19 00:59:01 +080093 result = tempS;
94 }
Alex Schendel5f2d6272021-09-22 10:35:40 -070095 lg2::info("VERSION INFO - BIOS - {VER}", "VER", result);
Cheng C Yangb4651b92019-12-19 00:59:01 +080096 return sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::
97 Revision::version(result);
98}
99
100} // namespace smbios
101} // namespace phosphor