blob: e4ea038ab0199687198b4b98c8796bea17b42e7e [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>
Jayaprakash Mutyala7393e482022-09-19 18:18:59 +000025
26static constexpr const char* biosActiveObjPath =
27 "/xyz/openbmc_project/software/bios_active";
28static constexpr const char* biosVersionIntf =
29 "xyz.openbmc_project.Software.Version";
30static constexpr const char* biosVersionProp = "Version";
31
Cheng C Yangb4651b92019-12-19 00:59:01 +080032namespace phosphor
33{
34namespace smbios
35{
36
Jason M. Billse7770992021-05-14 13:24:33 -070037std::string System::uuid(std::string value)
Cheng C Yangb4651b92019-12-19 00:59:01 +080038{
Cheng C Yang2ca7a0f2019-12-19 10:46:42 +080039 uint8_t* dataIn = storage;
Cheng C Yangb4651b92019-12-19 00:59:01 +080040 dataIn = getSMBIOSTypePtr(dataIn, systemType);
41 if (dataIn != nullptr)
42 {
Cheng C Yang2ca7a0f2019-12-19 10:46:42 +080043 auto systemInfo = reinterpret_cast<struct SystemInfo*>(dataIn);
Cheng C Yangb4651b92019-12-19 00:59:01 +080044 std::stringstream stream;
45 stream << std::setfill('0') << std::hex;
Jason M. Billse7770992021-05-14 13:24:33 -070046 stream << std::setw(8) << systemInfo->uuid.timeLow;
Cheng C Yangb4651b92019-12-19 00:59:01 +080047 stream << "-";
Jason M. Billse7770992021-05-14 13:24:33 -070048 stream << std::setw(4) << systemInfo->uuid.timeMid;
Cheng C Yangb4651b92019-12-19 00:59:01 +080049 stream << "-";
Jason M. Billse7770992021-05-14 13:24:33 -070050 stream << std::setw(4) << systemInfo->uuid.timeHiAndVer;
Cheng C Yangb4651b92019-12-19 00:59:01 +080051 stream << "-";
Jason M. Billse7770992021-05-14 13:24:33 -070052 stream << std::setw(2) << static_cast<int>(systemInfo->uuid.clockSeqHi);
Cheng C Yangb4651b92019-12-19 00:59:01 +080053 stream << std::setw(2)
Jason M. Billse7770992021-05-14 13:24:33 -070054 << static_cast<int>(systemInfo->uuid.clockSeqLow);
Cheng C Yangb4651b92019-12-19 00:59:01 +080055 stream << "-";
Jason M. Billse7770992021-05-14 13:24:33 -070056 static_assert(sizeof(systemInfo->uuid.node) == 6);
57 stream << std::setw(2) << static_cast<int>(systemInfo->uuid.node[0]);
58 stream << std::setw(2) << static_cast<int>(systemInfo->uuid.node[1]);
59 stream << std::setw(2) << static_cast<int>(systemInfo->uuid.node[2]);
60 stream << std::setw(2) << static_cast<int>(systemInfo->uuid.node[3]);
61 stream << std::setw(2) << static_cast<int>(systemInfo->uuid.node[4]);
62 stream << std::setw(2) << static_cast<int>(systemInfo->uuid.node[5]);
Cheng C Yangb4651b92019-12-19 00:59:01 +080063
Jason M. Billse7770992021-05-14 13:24:33 -070064 return sdbusplus::xyz::openbmc_project::Common::server::UUID::uuid(
Cheng C Yangb4651b92019-12-19 00:59:01 +080065 stream.str());
66 }
67
Jason M. Billse7770992021-05-14 13:24:33 -070068 return sdbusplus::xyz::openbmc_project::Common::server::UUID::uuid(
Cheng C Yangb4651b92019-12-19 00:59:01 +080069 "00000000-0000-0000-0000-000000000000");
70}
71
Jayaprakash Mutyala7393e482022-09-19 18:18:59 +000072static std::string getService(sdbusplus::bus::bus& bus,
73 const std::string& objectPath,
74 const std::string& interface)
75{
76 auto method =
77 bus.new_method_call("xyz.openbmc_project.ObjectMapper",
78 "/xyz/openbmc_project/object_mapper",
79 "xyz.openbmc_project.ObjectMapper", "GetObject");
80
81 method.append(objectPath);
82 method.append(std::vector<std::string>({interface}));
83
84 std::vector<std::pair<std::string, std::vector<std::string>>> response;
85
86 try
87 {
88 auto reply = bus.call(method);
89 reply.read(response);
90 }
91 catch (const sdbusplus::exception_t& e)
92 {
93 lg2::error("Error in mapper method call - {ERROR}, SERVICE - "
94 "{SERVICE}, PATH - {PATH}",
95 "ERROR", e.what(), "SERVICE", objectPath.c_str(), "PATH",
96 interface.c_str());
97
98 return std::string{};
99 }
100
101 return response[0].first;
102}
103
104static void setProperty(sdbusplus::bus::bus& bus, const std::string& objectPath,
105 const std::string& interface,
106 const std::string& propertyName,
107 const std::string& value)
108{
109 auto service = getService(bus, objectPath, interface);
110 if (service.empty())
111 {
112 return;
113 }
114
115 auto method = bus.new_method_call(service.c_str(), objectPath.c_str(),
116 "org.freedesktop.DBus.Properties", "Set");
117 method.append(interface.c_str(), propertyName.c_str(),
118 std::variant<std::string>{value});
119
120 bus.call_noreply(method);
121}
122
Cheng C Yangb4651b92019-12-19 00:59:01 +0800123std::string System::version(std::string value)
124{
125 std::string result = "No BIOS Version";
Cheng C Yang2ca7a0f2019-12-19 10:46:42 +0800126 uint8_t* dataIn = storage;
Cheng C Yangb4651b92019-12-19 00:59:01 +0800127 dataIn = getSMBIOSTypePtr(dataIn, biosType);
128 if (dataIn != nullptr)
129 {
Cheng C Yang2ca7a0f2019-12-19 10:46:42 +0800130 auto biosInfo = reinterpret_cast<struct BIOSInfo*>(dataIn);
Cheng C Yangb4651b92019-12-19 00:59:01 +0800131 uint8_t biosVerByte = biosInfo->biosVersion;
132 std::string tempS =
133 positionToString(biosInfo->biosVersion, biosInfo->length, dataIn);
Kuiying Wang26de0d72020-11-18 19:31:46 +0800134 if (std::find_if(tempS.begin(), tempS.end(),
135 [](char ch) { return !isprint(ch); }) != tempS.end())
136 {
137 std::ofstream smbiosFile(mdrType2File, std::ios_base::trunc);
138 if (!smbiosFile.good())
139 {
140 phosphor::logging::log<phosphor::logging::level::ERR>(
141 "Open MDRV2 table file failure");
142 return result;
143 }
144 smbiosFile.clear();
145 smbiosFile.close();
146 phosphor::logging::log<phosphor::logging::level::ERR>(
147 "Find non-print char, delete the broken MDRV2 table file!");
148 return sdbusplus::xyz::openbmc_project::Inventory::Decorator::
149 server::Revision::version(result);
150 }
Cheng C Yangb4651b92019-12-19 00:59:01 +0800151 result = tempS;
Jayaprakash Mutyala7393e482022-09-19 18:18:59 +0000152
153 setProperty(bus, biosActiveObjPath, biosVersionIntf, biosVersionProp,
154 result);
Cheng C Yangb4651b92019-12-19 00:59:01 +0800155 }
Alex Schendel5f2d6272021-09-22 10:35:40 -0700156 lg2::info("VERSION INFO - BIOS - {VER}", "VER", result);
Jayaprakash Mutyala7393e482022-09-19 18:18:59 +0000157
Cheng C Yangb4651b92019-12-19 00:59:01 +0800158 return sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::
159 Revision::version(result);
160}
161
162} // namespace smbios
163} // namespace phosphor