-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathutils.cpp
More file actions
178 lines (148 loc) · 5.21 KB
/
utils.cpp
File metadata and controls
178 lines (148 loc) · 5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include "config.h"
#include "utils.hpp"
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
#include <phosphor-logging/log.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#if OPENSSL_VERSION_NUMBER < 0x10100000L
#include <string.h>
static void* OPENSSL_zalloc(size_t num)
{
void* ret = OPENSSL_malloc(num);
if (ret != NULL)
{
memset(ret, 0, num);
}
return ret;
}
EVP_MD_CTX* EVP_MD_CTX_new(void)
{
return (EVP_MD_CTX*)OPENSSL_zalloc(sizeof(EVP_MD_CTX));
}
void EVP_MD_CTX_free(EVP_MD_CTX* ctx)
{
EVP_MD_CTX_cleanup(ctx);
OPENSSL_free(ctx);
}
#endif // OPENSSL_VERSION_NUMBER < 0x10100000L
namespace utils
{
using namespace phosphor::logging;
constexpr auto HIOMAPD_PATH = "/xyz/openbmc_project/Hiomapd";
constexpr auto HIOMAPD_INTERFACE = "xyz.openbmc_project.Hiomapd.Control";
using InternalFailure =
sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
std::string getService(sdbusplus::bus_t& bus, const std::string& path,
const std::string& intf)
{
auto mapper = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
MAPPER_INTERFACE, "GetObject");
mapper.append(path, std::vector<std::string>({intf}));
try
{
auto mapperResponseMsg = bus.call(mapper);
std::vector<std::pair<std::string, std::vector<std::string>>>
mapperResponse;
mapperResponseMsg.read(mapperResponse);
if (mapperResponse.empty())
{
log<level::ERR>("Error reading mapper response");
throw std::runtime_error("Error reading mapper response");
}
return mapperResponse[0].first;
}
catch (const sdbusplus::exception_t& ex)
{
log<level::ERR>("Mapper call failed", entry("METHOD=%d", "GetObject"),
entry("PATH=%s", path.c_str()),
entry("INTERFACE=%s", intf.c_str()));
throw std::runtime_error("Mapper call failed");
}
}
void hiomapdSuspend(sdbusplus::bus_t& bus)
{
auto service = getService(bus, HIOMAPD_PATH, HIOMAPD_INTERFACE);
auto method = bus.new_method_call(service.c_str(), HIOMAPD_PATH,
HIOMAPD_INTERFACE, "Suspend");
try
{
bus.call_noreply(method);
}
catch (const sdbusplus::exception_t& e)
{
log<level::ERR>("Error in mboxd suspend call",
entry("ERROR=%s", e.what()));
}
}
void hiomapdResume(sdbusplus::bus_t& bus)
{
auto service = getService(bus, HIOMAPD_PATH, HIOMAPD_INTERFACE);
auto method = bus.new_method_call(service.c_str(), HIOMAPD_PATH,
HIOMAPD_INTERFACE, "Resume");
method.append(true); // Indicate PNOR is modified
try
{
bus.call_noreply(method);
}
catch (const sdbusplus::exception_t& e)
{
log<level::ERR>("Error in mboxd suspend call",
entry("ERROR=%s", e.what()));
}
}
void setPendingAttributes(sdbusplus::bus_t& bus, const std::string& attrName,
const std::string& attrValue)
{
constexpr auto biosConfigPath = "/xyz/openbmc_project/bios_config/manager";
constexpr auto biosConfigIntf = "xyz.openbmc_project.BIOSConfig.Manager";
constexpr auto dbusAttrType =
"xyz.openbmc_project.BIOSConfig.Manager.AttributeType.Enumeration";
using PendingAttributesType = std::vector<std::pair<
std::string, std::tuple<std::string, std::variant<std::string>>>>;
PendingAttributesType pendingAttributes;
pendingAttributes.emplace_back(
std::make_pair(attrName, std::make_tuple(dbusAttrType, attrValue)));
try
{
auto service = getService(bus, biosConfigPath, biosConfigIntf);
auto method = bus.new_method_call(service.c_str(), biosConfigPath,
SYSTEMD_PROPERTY_INTERFACE, "Set");
method.append(biosConfigIntf, "PendingAttributes",
std::variant<PendingAttributesType>(pendingAttributes));
bus.call(method);
}
catch (const sdbusplus::exception_t& e)
{
log<level::ERR>("Error setting the bios attribute",
entry("ERROR=%s", e.what()),
entry("ATTRIBUTE=%s", attrName.c_str()),
entry("ATTRIBUTE_VALUE=%s", attrValue.c_str()));
return;
}
}
void clearHMCManaged(sdbusplus::bus_t& bus)
{
setPendingAttributes(bus, "pvm_hmc_managed", "Disabled");
}
void setClearNvram(sdbusplus::bus_t& bus)
{
setPendingAttributes(bus, "pvm_clear_nvram", "Enabled");
}
void deleteAllErrorLogs(sdbusplus::bus_t& bus)
{
constexpr auto loggingPath = "/xyz/openbmc_project/logging";
constexpr auto deleteAllIntf = "xyz.openbmc_project.Collection.DeleteAll";
auto service = getService(bus, loggingPath, deleteAllIntf);
auto method = bus.new_method_call(service.c_str(), loggingPath,
deleteAllIntf, "DeleteAll");
try
{
bus.call_noreply(method);
}
catch (const sdbusplus::exception_t& e)
{
log<level::ERR>("Error deleting all error logs",
entry("ERROR=%s", e.what()));
}
}
} // namespace utils