blob: 2f6e3e4d258c684e2952529614a144f14afe9bdb [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
30std::string System::uUID(std::string value)
31{
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;
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
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 }
95
96 return sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::
97 Revision::version(result);
98}
99
100} // namespace smbios
101} // namespace phosphor