blob: 1e74081c016df8d56a9e43695ab0c35aced01e7c [file] [log] [blame]
John Wangd9659342020-02-27 16:46:05 +08001#include "bios_config.hpp"
2
John Wang3be70852020-02-13 15:59:04 +08003#include "bios_enum_attribute.hpp"
John Wang95e6b3c2020-02-13 09:43:24 +08004#include "bios_integer_attribute.hpp"
John Wangd9659342020-02-27 16:46:05 +08005#include "bios_string_attribute.hpp"
Sampa Misra46ece062020-03-18 07:17:44 -05006#include "bios_table.hpp"
George Liu1b180d82020-07-23 14:01:58 +08007#include "common/bios_utils.hpp"
John Wangd9659342020-02-27 16:46:05 +08008
Riya Dixit49cfb132023-03-02 04:26:53 -06009#include <phosphor-logging/lg2.hpp>
George Liu1244acf2020-08-14 09:11:11 +080010#include <xyz/openbmc_project/BIOSConfig/Manager/server.hpp>
11
John Wangd9659342020-02-27 16:46:05 +080012#include <fstream>
13#include <iostream>
14
Tom Joseph7f839f92020-09-21 10:20:44 +053015#ifdef OEM_IBM
16#include "oem/ibm/libpldmresponder/platform_oem_ibm.hpp"
17#endif
18
Riya Dixit49cfb132023-03-02 04:26:53 -060019PHOSPHOR_LOG2_USING;
20
Brad Bishop5079ac42021-08-19 18:35:06 -040021using namespace pldm::utils;
22
John Wangd9659342020-02-27 16:46:05 +080023namespace pldm
24{
25namespace responder
26{
27namespace bios
28{
29namespace
30{
George Liu1244acf2020-08-14 09:11:11 +080031using BIOSConfigManager =
32 sdbusplus::xyz::openbmc_project::BIOSConfig::server::Manager;
33
John Wangd9659342020-02-27 16:46:05 +080034constexpr auto enumJsonFile = "enum_attrs.json";
35constexpr auto stringJsonFile = "string_attrs.json";
36constexpr auto integerJsonFile = "integer_attrs.json";
37
38constexpr auto stringTableFile = "stringTable";
39constexpr auto attrTableFile = "attributeTable";
40constexpr auto attrValueTableFile = "attributeValueTable";
41
42} // namespace
43
Sampa Misrac0c79482021-06-02 08:01:54 -050044BIOSConfig::BIOSConfig(
45 const char* jsonDir, const char* tableDir, DBusHandler* const dbusHandler,
Andrew Jefferya330b2f2023-05-04 14:55:37 +093046 int fd, uint8_t eid, pldm::InstanceIdDb* instanceIdDb,
Sampa Misrac0c79482021-06-02 08:01:54 -050047 pldm::requester::Handler<pldm::requester::Request>* handler) :
John Wangd9659342020-02-27 16:46:05 +080048 jsonDir(jsonDir),
Tom Joseph7f839f92020-09-21 10:20:44 +053049 tableDir(tableDir), dbusHandler(dbusHandler), fd(fd), eid(eid),
Andrew Jefferya330b2f2023-05-04 14:55:37 +093050 instanceIdDb(instanceIdDb), handler(handler)
Tom Joseph7f839f92020-09-21 10:20:44 +053051
John Wangd9659342020-02-27 16:46:05 +080052{
George Liu9d8921e2020-05-14 15:41:50 +080053 fs::create_directories(tableDir);
John Wangd9659342020-02-27 16:46:05 +080054 constructAttributes();
George Liu1244acf2020-08-14 09:11:11 +080055 listenPendingAttributes();
John Wangd9659342020-02-27 16:46:05 +080056}
57
58void BIOSConfig::buildTables()
59{
John Wangd9659342020-02-27 16:46:05 +080060 auto stringTable = buildAndStoreStringTable();
61 if (stringTable)
62 {
63 buildAndStoreAttrTables(*stringTable);
64 }
65}
66
67std::optional<Table> BIOSConfig::getBIOSTable(pldm_bios_table_types tableType)
68{
69 fs::path tablePath;
70 switch (tableType)
71 {
72 case PLDM_BIOS_STRING_TABLE:
73 tablePath = tableDir / stringTableFile;
74 break;
75 case PLDM_BIOS_ATTR_TABLE:
76 tablePath = tableDir / attrTableFile;
77 break;
78 case PLDM_BIOS_ATTR_VAL_TABLE:
79 tablePath = tableDir / attrValueTableFile;
80 break;
81 }
82 return loadTable(tablePath);
83}
84
Tom Joseph7f839f92020-09-21 10:20:44 +053085int BIOSConfig::setBIOSTable(uint8_t tableType, const Table& table,
86 bool updateBaseBIOSTable)
George Liu1b180d82020-07-23 14:01:58 +080087{
88 fs::path stringTablePath(tableDir / stringTableFile);
89 fs::path attrTablePath(tableDir / attrTableFile);
90 fs::path attrValueTablePath(tableDir / attrValueTableFile);
91
92 if (!pldm_bios_table_checksum(table.data(), table.size()))
93 {
94 return PLDM_INVALID_BIOS_TABLE_DATA_INTEGRITY_CHECK;
95 }
96
97 if (tableType == PLDM_BIOS_STRING_TABLE)
98 {
99 storeTable(stringTablePath, table);
100 }
101 else if (tableType == PLDM_BIOS_ATTR_TABLE)
102 {
103 BIOSTable biosStringTable(stringTablePath.c_str());
104 if (biosStringTable.isEmpty())
105 {
106 return PLDM_INVALID_BIOS_TABLE_TYPE;
107 }
108
109 auto rc = checkAttributeTable(table);
110 if (rc != PLDM_SUCCESS)
111 {
112 return rc;
113 }
114
115 storeTable(attrTablePath, table);
116 }
117 else if (tableType == PLDM_BIOS_ATTR_VAL_TABLE)
118 {
119 BIOSTable biosStringTable(stringTablePath.c_str());
120 BIOSTable biosStringValueTable(attrTablePath.c_str());
121 if (biosStringTable.isEmpty() || biosStringValueTable.isEmpty())
122 {
123 return PLDM_INVALID_BIOS_TABLE_TYPE;
124 }
125
126 auto rc = checkAttributeValueTable(table);
127 if (rc != PLDM_SUCCESS)
128 {
129 return rc;
130 }
131
132 storeTable(attrValueTablePath, table);
George Liu1b180d82020-07-23 14:01:58 +0800133 }
134 else
135 {
136 return PLDM_INVALID_BIOS_TABLE_TYPE;
137 }
138
Tom Joseph7f839f92020-09-21 10:20:44 +0530139 if ((tableType == PLDM_BIOS_ATTR_VAL_TABLE) && updateBaseBIOSTable)
George Liu1b180d82020-07-23 14:01:58 +0800140 {
George Liu1b180d82020-07-23 14:01:58 +0800141 updateBaseBIOSTableProperty();
142 }
143
144 return PLDM_SUCCESS;
145}
146
147int BIOSConfig::checkAttributeTable(const Table& table)
148{
149 using namespace pldm::bios::utils;
150 auto stringTable = getBIOSTable(PLDM_BIOS_STRING_TABLE);
151 for (auto entry :
152 BIOSTableIter<PLDM_BIOS_ATTR_TABLE>(table.data(), table.size()))
153 {
154 auto attrNameHandle =
155 pldm_bios_table_attr_entry_decode_string_handle(entry);
156
157 auto stringEnty = pldm_bios_table_string_find_by_handle(
158 stringTable->data(), stringTable->size(), attrNameHandle);
159 if (stringEnty == nullptr)
160 {
161 return PLDM_INVALID_BIOS_ATTR_HANDLE;
162 }
163
164 auto attrType = static_cast<pldm_bios_attribute_type>(
165 pldm_bios_table_attr_entry_decode_attribute_type(entry));
166
167 switch (attrType)
168 {
169 case PLDM_BIOS_ENUMERATION:
170 case PLDM_BIOS_ENUMERATION_READ_ONLY:
171 {
172 auto pvNum =
173 pldm_bios_table_attr_entry_enum_decode_pv_num(entry);
174 std::vector<uint16_t> pvHandls(pvNum);
175 pldm_bios_table_attr_entry_enum_decode_pv_hdls(
176 entry, pvHandls.data(), pvHandls.size());
177 auto defNum =
178 pldm_bios_table_attr_entry_enum_decode_def_num(entry);
179 std::vector<uint8_t> defIndices(defNum);
180 pldm_bios_table_attr_entry_enum_decode_def_indices(
181 entry, defIndices.data(), defIndices.size());
182
183 for (size_t i = 0; i < pvHandls.size(); i++)
184 {
185 auto stringEntry = pldm_bios_table_string_find_by_handle(
186 stringTable->data(), stringTable->size(), pvHandls[i]);
187 if (stringEntry == nullptr)
188 {
189 return PLDM_INVALID_BIOS_ATTR_HANDLE;
190 }
191 }
192
193 for (size_t i = 0; i < defIndices.size(); i++)
194 {
195 auto stringEntry = pldm_bios_table_string_find_by_handle(
196 stringTable->data(), stringTable->size(),
197 pvHandls[defIndices[i]]);
198 if (stringEntry == nullptr)
199 {
200 return PLDM_INVALID_BIOS_ATTR_HANDLE;
201 }
202 }
203 break;
204 }
205 case PLDM_BIOS_INTEGER:
206 case PLDM_BIOS_INTEGER_READ_ONLY:
207 case PLDM_BIOS_STRING:
208 case PLDM_BIOS_STRING_READ_ONLY:
209 case PLDM_BIOS_PASSWORD:
210 case PLDM_BIOS_PASSWORD_READ_ONLY:
211 break;
212 default:
213 return PLDM_INVALID_BIOS_ATTR_HANDLE;
214 }
215 }
216
217 return PLDM_SUCCESS;
218}
219
220int BIOSConfig::checkAttributeValueTable(const Table& table)
221{
222 using namespace pldm::bios::utils;
223 auto stringTable = getBIOSTable(PLDM_BIOS_STRING_TABLE);
224 auto attrTable = getBIOSTable(PLDM_BIOS_ATTR_TABLE);
225
226 baseBIOSTableMaps.clear();
227
228 for (auto tableEntry :
229 BIOSTableIter<PLDM_BIOS_ATTR_VAL_TABLE>(table.data(), table.size()))
230 {
231 AttributeName attributeName{};
232 AttributeType attributeType{};
233 ReadonlyStatus readonlyStatus{};
234 DisplayName displayName{};
235 Description description{};
236 MenuPath menuPath{};
237 CurrentValue currentValue{};
238 DefaultValue defaultValue{};
239 Option options{};
240
241 auto attrValueHandle =
242 pldm_bios_table_attr_value_entry_decode_attribute_handle(
243 tableEntry);
244 auto attrType = static_cast<pldm_bios_attribute_type>(
245 pldm_bios_table_attr_value_entry_decode_attribute_type(tableEntry));
246
247 auto attrEntry = pldm_bios_table_attr_find_by_handle(
248 attrTable->data(), attrTable->size(), attrValueHandle);
249 if (attrEntry == nullptr)
250 {
251 return PLDM_INVALID_BIOS_ATTR_HANDLE;
252 }
253 auto attrHandle =
254 pldm_bios_table_attr_entry_decode_attribute_handle(attrEntry);
255 auto attrNameHandle =
256 pldm_bios_table_attr_entry_decode_string_handle(attrEntry);
257
258 auto stringEntry = pldm_bios_table_string_find_by_handle(
259 stringTable->data(), stringTable->size(), attrNameHandle);
260 if (stringEntry == nullptr)
261 {
262 return PLDM_INVALID_BIOS_ATTR_HANDLE;
263 }
264 auto strLength =
265 pldm_bios_table_string_entry_decode_string_length(stringEntry);
266 std::vector<char> buffer(strLength + 1 /* sizeof '\0' */);
267 pldm_bios_table_string_entry_decode_string(stringEntry, buffer.data(),
268 buffer.size());
269 attributeName = std::string(buffer.data(), buffer.data() + strLength);
270
271 if (!biosAttributes.empty())
272 {
273 readonlyStatus =
George Liub1fbeec2020-09-04 09:59:46 +0800274 biosAttributes[attrHandle % biosAttributes.size()]->readOnly;
George Liu92bb4022020-09-03 14:58:24 +0800275 description =
276 biosAttributes[attrHandle % biosAttributes.size()]->helpText;
277 displayName =
278 biosAttributes[attrHandle % biosAttributes.size()]->displayName;
George Liu1b180d82020-07-23 14:01:58 +0800279 }
280
281 switch (attrType)
282 {
283 case PLDM_BIOS_ENUMERATION:
284 case PLDM_BIOS_ENUMERATION_READ_ONLY:
285 {
286 auto getValue = [](uint16_t handle,
287 const Table& table) -> std::string {
288 auto stringEntry = pldm_bios_table_string_find_by_handle(
289 table.data(), table.size(), handle);
290
291 auto strLength =
292 pldm_bios_table_string_entry_decode_string_length(
293 stringEntry);
294 std::vector<char> buffer(strLength + 1 /* sizeof '\0' */);
295 pldm_bios_table_string_entry_decode_string(
296 stringEntry, buffer.data(), buffer.size());
297
298 return std::string(buffer.data(),
299 buffer.data() + strLength);
300 };
301
302 attributeType = "xyz.openbmc_project.BIOSConfig.Manager."
303 "AttributeType.Enumeration";
304
305 auto pvNum =
306 pldm_bios_table_attr_entry_enum_decode_pv_num(attrEntry);
307 std::vector<uint16_t> pvHandls(pvNum);
308 pldm_bios_table_attr_entry_enum_decode_pv_hdls(
309 attrEntry, pvHandls.data(), pvHandls.size());
310
311 // get possible_value
312 for (size_t i = 0; i < pvHandls.size(); i++)
313 {
314 options.push_back(
315 std::make_tuple("xyz.openbmc_project.BIOSConfig."
316 "Manager.BoundType.OneOf",
317 getValue(pvHandls[i], *stringTable)));
318 }
319
320 auto count =
321 pldm_bios_table_attr_value_entry_enum_decode_number(
322 tableEntry);
323 std::vector<uint8_t> handles(count);
324 pldm_bios_table_attr_value_entry_enum_decode_handles(
325 tableEntry, handles.data(), handles.size());
326
327 // get current_value
328 for (size_t i = 0; i < handles.size(); i++)
329 {
330 currentValue = getValue(pvHandls[handles[i]], *stringTable);
331 }
332
333 auto defNum =
334 pldm_bios_table_attr_entry_enum_decode_def_num(attrEntry);
335 std::vector<uint8_t> defIndices(defNum);
336 pldm_bios_table_attr_entry_enum_decode_def_indices(
337 attrEntry, defIndices.data(), defIndices.size());
338
339 // get default_value
340 for (size_t i = 0; i < defIndices.size(); i++)
341 {
Patrick Williams6da4f912023-05-10 07:50:53 -0500342 defaultValue = getValue(pvHandls[defIndices[i]],
343 *stringTable);
George Liu1b180d82020-07-23 14:01:58 +0800344 }
345
346 break;
347 }
348 case PLDM_BIOS_INTEGER:
349 case PLDM_BIOS_INTEGER_READ_ONLY:
350 {
351 attributeType = "xyz.openbmc_project.BIOSConfig.Manager."
352 "AttributeType.Integer";
353 currentValue = static_cast<int64_t>(
354 pldm_bios_table_attr_value_entry_integer_decode_cv(
355 tableEntry));
356
357 uint64_t lower, upper, def;
358 uint32_t scalar;
359 pldm_bios_table_attr_entry_integer_decode(
360 attrEntry, &lower, &upper, &scalar, &def);
361 options.push_back(
362 std::make_tuple("xyz.openbmc_project.BIOSConfig.Manager."
363 "BoundType.LowerBound",
364 static_cast<int64_t>(lower)));
365 options.push_back(
366 std::make_tuple("xyz.openbmc_project.BIOSConfig.Manager."
367 "BoundType.UpperBound",
368 static_cast<int64_t>(upper)));
369 options.push_back(
370 std::make_tuple("xyz.openbmc_project.BIOSConfig.Manager."
371 "BoundType.ScalarIncrement",
372 static_cast<int64_t>(scalar)));
373 defaultValue = static_cast<int64_t>(def);
374 break;
375 }
376 case PLDM_BIOS_STRING:
377 case PLDM_BIOS_STRING_READ_ONLY:
378 {
379 attributeType = "xyz.openbmc_project.BIOSConfig.Manager."
380 "AttributeType.String";
381 variable_field currentString;
382 pldm_bios_table_attr_value_entry_string_decode_string(
383 tableEntry, &currentString);
384 currentValue = std::string(
385 reinterpret_cast<const char*>(currentString.ptr),
386 currentString.length);
387 auto min = pldm_bios_table_attr_entry_string_decode_min_length(
388 attrEntry);
389 auto max = pldm_bios_table_attr_entry_string_decode_max_length(
390 attrEntry);
391 auto def =
392 pldm_bios_table_attr_entry_string_decode_def_string_length(
393 attrEntry);
394 std::vector<char> defString(def + 1);
395 pldm_bios_table_attr_entry_string_decode_def_string(
396 attrEntry, defString.data(), defString.size());
397 options.push_back(
398 std::make_tuple("xyz.openbmc_project.BIOSConfig.Manager."
399 "BoundType.MinStringLength",
400 static_cast<int64_t>(min)));
401 options.push_back(
402 std::make_tuple("xyz.openbmc_project.BIOSConfig.Manager."
403 "BoundType.MaxStringLength",
404 static_cast<int64_t>(max)));
405 defaultValue = defString.data();
406 break;
407 }
408 case PLDM_BIOS_PASSWORD:
409 case PLDM_BIOS_PASSWORD_READ_ONLY:
410 {
411 attributeType = "xyz.openbmc_project.BIOSConfig.Manager."
412 "AttributeType.Password";
413 break;
414 }
415 default:
416 return PLDM_INVALID_BIOS_ATTR_HANDLE;
417 }
418 baseBIOSTableMaps.emplace(
419 std::move(attributeName),
420 std::make_tuple(attributeType, readonlyStatus, displayName,
421 description, menuPath, currentValue, defaultValue,
422 std::move(options)));
423 }
424
425 return PLDM_SUCCESS;
426}
427
428void BIOSConfig::updateBaseBIOSTableProperty()
429{
430 constexpr static auto biosConfigPath =
431 "/xyz/openbmc_project/bios_config/manager";
432 constexpr static auto biosConfigInterface =
433 "xyz.openbmc_project.BIOSConfig.Manager";
434 constexpr static auto biosConfigPropertyName = "BaseBIOSTable";
435 constexpr static auto dbusProperties = "org.freedesktop.DBus.Properties";
436
437 if (baseBIOSTableMaps.empty())
438 {
439 return;
440 }
441
442 try
443 {
444 auto& bus = dbusHandler->getBus();
Patrick Williams6da4f912023-05-10 07:50:53 -0500445 auto service = dbusHandler->getService(biosConfigPath,
446 biosConfigInterface);
George Liu1b180d82020-07-23 14:01:58 +0800447 auto method = bus.new_method_call(service.c_str(), biosConfigPath,
448 dbusProperties, "Set");
449 std::variant<BaseBIOSTable> value = baseBIOSTableMaps;
450 method.append(biosConfigInterface, biosConfigPropertyName, value);
451 bus.call_noreply(method);
452 }
453 catch (const std::exception& e)
454 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600455 error("failed to update BaseBIOSTable property, ERROR={ERR_EXCEP}",
456 "ERR_EXCEP", e.what());
George Liu1b180d82020-07-23 14:01:58 +0800457 }
458}
459
John Wangd9659342020-02-27 16:46:05 +0800460void BIOSConfig::constructAttributes()
461{
462 load(jsonDir / stringJsonFile, [this](const Json& entry) {
463 constructAttribute<BIOSStringAttribute>(entry);
464 });
John Wang3be70852020-02-13 15:59:04 +0800465 load(jsonDir / integerJsonFile, [this](const Json& entry) {
John Wang95e6b3c2020-02-13 09:43:24 +0800466 constructAttribute<BIOSIntegerAttribute>(entry);
467 });
John Wang3be70852020-02-13 15:59:04 +0800468 load(jsonDir / enumJsonFile, [this](const Json& entry) {
469 constructAttribute<BIOSEnumAttribute>(entry);
470 });
John Wangd9659342020-02-27 16:46:05 +0800471}
472
473void BIOSConfig::buildAndStoreAttrTables(const Table& stringTable)
474{
475 BIOSStringTable biosStringTable(stringTable);
476
477 if (biosAttributes.empty())
478 {
479 return;
480 }
481
Tom Josephca7b2522020-11-18 12:27:11 +0530482 BaseBIOSTable biosTable{};
483 constexpr auto biosObjPath = "/xyz/openbmc_project/bios_config/manager";
484 constexpr auto biosInterface = "xyz.openbmc_project.BIOSConfig.Manager";
485
486 try
487 {
488 auto& bus = dbusHandler->getBus();
489 auto service = dbusHandler->getService(biosObjPath, biosInterface);
Patrick Williams6da4f912023-05-10 07:50:53 -0500490 auto method = bus.new_method_call(service.c_str(), biosObjPath,
491 "org.freedesktop.DBus.Properties",
492 "Get");
Tom Josephca7b2522020-11-18 12:27:11 +0530493 method.append(biosInterface, "BaseBIOSTable");
vkaverap@in.ibm.com9138c202023-05-19 07:50:47 -0500494 auto reply = bus.call(
495 method,
496 std::chrono::duration_cast<microsec>(sec(DBUS_TIMEOUT)).count());
Tom Josephca7b2522020-11-18 12:27:11 +0530497 std::variant<BaseBIOSTable> varBiosTable{};
498 reply.read(varBiosTable);
499 biosTable = std::get<BaseBIOSTable>(varBiosTable);
500 }
501 // Failed to read the BaseBIOSTable, so update the BaseBIOSTable with the
502 // default values populated from the BIOS JSONs to keep PLDM and
503 // bios-settings-manager in sync
504 catch (const std::exception& e)
505 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600506 error("Failed to read BaseBIOSTable property, ERROR={ERR_EXCEP}",
507 "ERR_EXCEP", e.what());
Tom Josephca7b2522020-11-18 12:27:11 +0530508 }
509
John Wangd9659342020-02-27 16:46:05 +0800510 Table attrTable, attrValueTable;
511
512 for (auto& attr : biosAttributes)
513 {
514 try
515 {
Tom Josephca7b2522020-11-18 12:27:11 +0530516 auto iter = biosTable.find(attr->name);
517 if (iter == biosTable.end())
518 {
519 attr->constructEntry(biosStringTable, attrTable, attrValueTable,
520 std::nullopt);
521 }
522 else
523 {
524 attr->constructEntry(
525 biosStringTable, attrTable, attrValueTable,
526 std::get<static_cast<uint8_t>(Index::currentValue)>(
527 iter->second));
528 }
John Wangd9659342020-02-27 16:46:05 +0800529 }
530 catch (const std::exception& e)
531 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600532 error("Construct Table Entry Error, AttributeName = {ATTR_NAME}",
533 "ATTR_NAME", attr->name);
John Wangd9659342020-02-27 16:46:05 +0800534 }
535 }
536
537 table::appendPadAndChecksum(attrTable);
538 table::appendPadAndChecksum(attrValueTable);
George Liu1b180d82020-07-23 14:01:58 +0800539 setBIOSTable(PLDM_BIOS_ATTR_TABLE, attrTable);
540 setBIOSTable(PLDM_BIOS_ATTR_VAL_TABLE, attrValueTable);
John Wangd9659342020-02-27 16:46:05 +0800541}
542
543std::optional<Table> BIOSConfig::buildAndStoreStringTable()
544{
545 std::set<std::string> strings;
546 auto handler = [&strings](const Json& entry) {
547 strings.emplace(entry.at("attribute_name"));
548 };
549
550 load(jsonDir / stringJsonFile, handler);
551 load(jsonDir / integerJsonFile, handler);
552 load(jsonDir / enumJsonFile, [&strings](const Json& entry) {
553 strings.emplace(entry.at("attribute_name"));
554 auto possibleValues = entry.at("possible_values");
555 for (auto& pv : possibleValues)
556 {
557 strings.emplace(pv);
558 }
559 });
560
561 if (strings.empty())
562 {
563 return std::nullopt;
564 }
565
566 Table table;
567 for (const auto& elem : strings)
568 {
569 table::string::constructEntry(table, elem);
570 }
571
572 table::appendPadAndChecksum(table);
George Liu1b180d82020-07-23 14:01:58 +0800573 setBIOSTable(PLDM_BIOS_STRING_TABLE, table);
John Wangd9659342020-02-27 16:46:05 +0800574 return table;
575}
576
577void BIOSConfig::storeTable(const fs::path& path, const Table& table)
578{
579 BIOSTable biosTable(path.c_str());
580 biosTable.store(table);
581}
582
583std::optional<Table> BIOSConfig::loadTable(const fs::path& path)
584{
585 BIOSTable biosTable(path.c_str());
586 if (biosTable.isEmpty())
587 {
588 return std::nullopt;
589 }
590
591 Table table;
592 biosTable.load(table);
593 return table;
594}
595
596void BIOSConfig::load(const fs::path& filePath, ParseHandler handler)
597{
598 std::ifstream file;
599 Json jsonConf;
600 if (fs::exists(filePath))
601 {
602 try
603 {
604 file.open(filePath);
605 jsonConf = Json::parse(file);
606 auto entries = jsonConf.at("entries");
607 for (auto& entry : entries)
608 {
609 try
610 {
611 handler(entry);
612 }
613 catch (const std::exception& e)
614 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600615 error(
616 "Failed to parse JSON config file(entry handler) : {JSON_PATH}, {ERR_EXCEP}",
617 "JSON_PATH", filePath.c_str(), "ERR_EXCEP", e.what());
John Wangd9659342020-02-27 16:46:05 +0800618 }
619 }
620 }
621 catch (const std::exception& e)
622 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600623 error("Failed to parse JSON config file : {JSON_PATH}", "JSON_PATH",
624 filePath.c_str());
John Wangd9659342020-02-27 16:46:05 +0800625 }
626 }
627}
628
Sagar Srinivascac0ebb2021-11-23 07:50:28 -0600629std::string BIOSConfig::decodeStringFromStringEntry(
630 const pldm_bios_string_table_entry* stringEntry)
631{
632 auto strLength =
633 pldm_bios_table_string_entry_decode_string_length(stringEntry);
634 std::vector<char> buffer(strLength + 1 /* sizeof '\0' */);
635 pldm_bios_table_string_entry_decode_string(stringEntry, buffer.data(),
636 buffer.size());
637 return std::string(buffer.data(), buffer.data() + strLength);
638}
639
640std::string
641 BIOSConfig::displayStringHandle(uint16_t handle, uint8_t index,
642 const std::optional<Table>& attrTable,
643 const std::optional<Table>& stringTable)
644{
645 auto attrEntry = pldm_bios_table_attr_find_by_handle(
646 attrTable->data(), attrTable->size(), handle);
647 auto pvNum = pldm_bios_table_attr_entry_enum_decode_pv_num(attrEntry);
648 std::vector<uint16_t> pvHandls(pvNum);
649 pldm_bios_table_attr_entry_enum_decode_pv_hdls(attrEntry, pvHandls.data(),
650 pvHandls.size());
651
652 std::string displayString = std::to_string(pvHandls[index]);
653
654 auto stringEntry = pldm_bios_table_string_find_by_handle(
655 stringTable->data(), stringTable->size(), pvHandls[index]);
656
657 auto decodedStr = decodeStringFromStringEntry(stringEntry);
658
659 return decodedStr + "(" + displayString + ")";
660}
661
662void BIOSConfig::traceBIOSUpdate(
663 const pldm_bios_attr_val_table_entry* attrValueEntry,
664 const pldm_bios_attr_table_entry* attrEntry, bool isBMC)
665{
666 auto stringTable = getBIOSTable(PLDM_BIOS_STRING_TABLE);
667 auto attrTable = getBIOSTable(PLDM_BIOS_ATTR_TABLE);
668
Patrick Williams6da4f912023-05-10 07:50:53 -0500669 auto [attrHandle,
670 attrType] = table::attribute_value::decodeHeader(attrValueEntry);
Sagar Srinivascac0ebb2021-11-23 07:50:28 -0600671
672 auto attrHeader = table::attribute::decodeHeader(attrEntry);
673 BIOSStringTable biosStringTable(*stringTable);
674 auto attrName = biosStringTable.findString(attrHeader.stringHandle);
675
676 switch (attrType)
677 {
678 case PLDM_BIOS_ENUMERATION:
679 case PLDM_BIOS_ENUMERATION_READ_ONLY:
680 {
681 auto count = pldm_bios_table_attr_value_entry_enum_decode_number(
682 attrValueEntry);
683 std::vector<uint8_t> handles(count);
684 pldm_bios_table_attr_value_entry_enum_decode_handles(
685 attrValueEntry, handles.data(), handles.size());
686
687 for (uint8_t handle : handles)
688 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600689 auto nwVal = displayStringHandle(attrHandle, handle, attrTable,
690 stringTable);
691 auto chkBMC = isBMC ? "true" : "false";
692 info(
693 "BIOS:{ATTR_NAME}, updated to value: {NEW_VAL}, by BMC: {CHK_BMC} ",
694 "ATTR_NAME", attrName, "NEW_VAL", nwVal, "CHK_BMC", chkBMC);
Sagar Srinivascac0ebb2021-11-23 07:50:28 -0600695 }
696 break;
697 }
698 case PLDM_BIOS_INTEGER:
699 case PLDM_BIOS_INTEGER_READ_ONLY:
700 {
701 auto value =
702 table::attribute_value::decodeIntegerEntry(attrValueEntry);
Riya Dixit49cfb132023-03-02 04:26:53 -0600703 auto chkBMC = isBMC ? "true" : "false";
704 info(
705 "BIOS: {ATTR_NAME}, updated to value: {UPDATED_VAL}, by BMC: {CHK_BMC}",
706 "ATTR_NAME", attrName, "UPDATED_VAL", value, "CHK_BMC", chkBMC);
Sagar Srinivascac0ebb2021-11-23 07:50:28 -0600707 break;
708 }
709 case PLDM_BIOS_STRING:
710 case PLDM_BIOS_STRING_READ_ONLY:
711 {
712 auto value =
713 table::attribute_value::decodeStringEntry(attrValueEntry);
Riya Dixit49cfb132023-03-02 04:26:53 -0600714 auto chkBMC = isBMC ? "true" : "false";
715 info(
716 "BIOS: {ATTR_NAME}, updated to value: {UPDATED_VAL}, by BMC: {CHK_BMC}",
717 "ATTR_NAME", attrName, "UPDATED_VAL", value, "CHK_BMC", chkBMC);
Sagar Srinivascac0ebb2021-11-23 07:50:28 -0600718 break;
719 }
720 default:
721 break;
722 };
723}
724
John Wang8241b342020-06-05 10:49:17 +0800725int BIOSConfig::checkAttrValueToUpdate(
726 const pldm_bios_attr_val_table_entry* attrValueEntry,
727 const pldm_bios_attr_table_entry* attrEntry, Table&)
728
729{
Patrick Williams6da4f912023-05-10 07:50:53 -0500730 auto [attrHandle,
731 attrType] = table::attribute_value::decodeHeader(attrValueEntry);
John Wang8241b342020-06-05 10:49:17 +0800732
733 switch (attrType)
734 {
735 case PLDM_BIOS_ENUMERATION:
George Liu5bb9edb2021-08-05 20:10:32 +0800736 case PLDM_BIOS_ENUMERATION_READ_ONLY:
John Wang8241b342020-06-05 10:49:17 +0800737 {
738 auto value =
739 table::attribute_value::decodeEnumEntry(attrValueEntry);
Patrick Williams6da4f912023-05-10 07:50:53 -0500740 auto [pvHdls,
741 defIndex] = table::attribute::decodeEnumEntry(attrEntry);
Varsha Kaverappa6a4d1cf2021-11-24 21:15:42 -0600742 if (!(value.size() == 1))
743 {
744 return PLDM_ERROR_INVALID_LENGTH;
745 }
John Wang8241b342020-06-05 10:49:17 +0800746 if (value[0] >= pvHdls.size())
747 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600748 error("Enum: Illgeal index, Index = {ATTR_INDEX}", "ATTR_INDEX",
749 (int)value[0]);
John Wang8241b342020-06-05 10:49:17 +0800750 return PLDM_ERROR_INVALID_DATA;
751 }
John Wang8241b342020-06-05 10:49:17 +0800752 return PLDM_SUCCESS;
753 }
754 case PLDM_BIOS_INTEGER:
George Liu5bb9edb2021-08-05 20:10:32 +0800755 case PLDM_BIOS_INTEGER_READ_ONLY:
John Wang8241b342020-06-05 10:49:17 +0800756 {
757 auto value =
758 table::attribute_value::decodeIntegerEntry(attrValueEntry);
Patrick Williams6da4f912023-05-10 07:50:53 -0500759 auto [lower, upper, scalar,
760 def] = table::attribute::decodeIntegerEntry(attrEntry);
John Wang8241b342020-06-05 10:49:17 +0800761
762 if (value < lower || value > upper)
763 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600764 error("Integer: out of bound, value = {ATTR_VALUE}",
765 "ATTR_VALUE", value);
John Wang8241b342020-06-05 10:49:17 +0800766 return PLDM_ERROR_INVALID_DATA;
767 }
768 return PLDM_SUCCESS;
769 }
770 case PLDM_BIOS_STRING:
George Liu5bb9edb2021-08-05 20:10:32 +0800771 case PLDM_BIOS_STRING_READ_ONLY:
John Wang8241b342020-06-05 10:49:17 +0800772 {
773 auto stringConf = table::attribute::decodeStringEntry(attrEntry);
774 auto value =
775 table::attribute_value::decodeStringEntry(attrValueEntry);
776 if (value.size() < stringConf.minLength ||
777 value.size() > stringConf.maxLength)
778 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600779 error(
780 "String: Length error, string = {ATTR_VALUE} length {LEN}",
781 "ATTR_VALUE", value, "LEN", value.size());
John Wang8241b342020-06-05 10:49:17 +0800782 return PLDM_ERROR_INVALID_LENGTH;
783 }
784 return PLDM_SUCCESS;
785 }
786 default:
Riya Dixit49cfb132023-03-02 04:26:53 -0600787 error("ReadOnly or Unspported type, type = {ATTR_TYPE}",
788 "ATTR_TYPE", attrType);
John Wang8241b342020-06-05 10:49:17 +0800789 return PLDM_ERROR;
790 };
791}
792
Sagar Srinivascac0ebb2021-11-23 07:50:28 -0600793int BIOSConfig::setAttrValue(const void* entry, size_t size, bool isBMC,
794 bool updateDBus, bool updateBaseBIOSTable)
John Wangd9659342020-02-27 16:46:05 +0800795{
796 auto attrValueTable = getBIOSTable(PLDM_BIOS_ATTR_VAL_TABLE);
797 auto attrTable = getBIOSTable(PLDM_BIOS_ATTR_TABLE);
798 auto stringTable = getBIOSTable(PLDM_BIOS_STRING_TABLE);
799 if (!attrValueTable || !attrTable || !stringTable)
800 {
801 return PLDM_BIOS_TABLE_UNAVAILABLE;
802 }
803
John Wangd9659342020-02-27 16:46:05 +0800804 auto attrValueEntry =
805 reinterpret_cast<const pldm_bios_attr_val_table_entry*>(entry);
806
807 auto attrValHeader = table::attribute_value::decodeHeader(attrValueEntry);
808
Patrick Williams6da4f912023-05-10 07:50:53 -0500809 auto attrEntry = table::attribute::findByHandle(*attrTable,
810 attrValHeader.attrHandle);
John Wangd9659342020-02-27 16:46:05 +0800811 if (!attrEntry)
812 {
813 return PLDM_ERROR;
814 }
815
John Wang8241b342020-06-05 10:49:17 +0800816 auto rc = checkAttrValueToUpdate(attrValueEntry, attrEntry, *stringTable);
817 if (rc != PLDM_SUCCESS)
818 {
819 return rc;
820 }
821
Patrick Williams6da4f912023-05-10 07:50:53 -0500822 auto destTable = table::attribute_value::updateTable(*attrValueTable, entry,
823 size);
John Wang8241b342020-06-05 10:49:17 +0800824
825 if (!destTable)
826 {
827 return PLDM_ERROR;
828 }
829
John Wangd9659342020-02-27 16:46:05 +0800830 try
831 {
832 auto attrHeader = table::attribute::decodeHeader(attrEntry);
833
834 BIOSStringTable biosStringTable(*stringTable);
835 auto attrName = biosStringTable.findString(attrHeader.stringHandle);
Patrick Williams6da4f912023-05-10 07:50:53 -0500836 auto iter = std::find_if(biosAttributes.begin(), biosAttributes.end(),
837 [&attrName](const auto& attr) {
838 return attr->name == attrName;
839 });
John Wangd9659342020-02-27 16:46:05 +0800840
841 if (iter == biosAttributes.end())
842 {
843 return PLDM_ERROR;
844 }
George Liu6d6d1e82021-02-16 11:08:55 +0800845 if (updateDBus)
846 {
847 (*iter)->setAttrValueOnDbus(attrValueEntry, attrEntry,
848 biosStringTable);
849 }
John Wangd9659342020-02-27 16:46:05 +0800850 }
851 catch (const std::exception& e)
852 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600853 error("Set attribute value error: {ERR_EXCEP}", "ERR_EXCEP", e.what());
John Wangd9659342020-02-27 16:46:05 +0800854 return PLDM_ERROR;
855 }
856
Tom Joseph7f839f92020-09-21 10:20:44 +0530857 setBIOSTable(PLDM_BIOS_ATTR_VAL_TABLE, *destTable, updateBaseBIOSTable);
George Liu5c3192b2020-08-13 17:35:43 +0800858
Sagar Srinivascac0ebb2021-11-23 07:50:28 -0600859 traceBIOSUpdate(attrValueEntry, attrEntry, isBMC);
860
John Wangd9659342020-02-27 16:46:05 +0800861 return PLDM_SUCCESS;
862}
863
864void BIOSConfig::removeTables()
865{
866 try
867 {
868 fs::remove(tableDir / stringTableFile);
869 fs::remove(tableDir / attrTableFile);
870 fs::remove(tableDir / attrValueTableFile);
871 }
872 catch (const std::exception& e)
873 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600874 error("Remove the tables error: {ERR_EXCEP}", "ERR_EXCEP", e.what());
John Wangd9659342020-02-27 16:46:05 +0800875 }
876}
877
Sampa Misra46ece062020-03-18 07:17:44 -0500878void BIOSConfig::processBiosAttrChangeNotification(
879 const DbusChObjProperties& chProperties, uint32_t biosAttrIndex)
880{
881 const auto& dBusMap = biosAttributes[biosAttrIndex]->getDBusMap();
882 const auto& propertyName = dBusMap->propertyName;
883 const auto& attrName = biosAttributes[biosAttrIndex]->name;
884
885 const auto it = chProperties.find(propertyName);
886 if (it == chProperties.end())
887 {
888 return;
889 }
890
891 PropertyValue newPropVal = it->second;
892 auto stringTable = getBIOSTable(PLDM_BIOS_STRING_TABLE);
893 if (!stringTable.has_value())
894 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600895 error("BIOS string table unavailable");
Sampa Misra46ece062020-03-18 07:17:44 -0500896 return;
897 }
898 BIOSStringTable biosStringTable(*stringTable);
899 uint16_t attrNameHdl{};
900 try
901 {
902 attrNameHdl = biosStringTable.findHandle(attrName);
903 }
Patrick Williams51330582021-10-06 12:48:56 -0500904 catch (const std::invalid_argument& e)
Sampa Misra46ece062020-03-18 07:17:44 -0500905 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600906 error("Could not find handle for BIOS string, ATTRIBUTE={ATTR_NAME}",
907 "ATTR_NAME", attrName.c_str());
Sampa Misra46ece062020-03-18 07:17:44 -0500908 return;
909 }
910
911 auto attrTable = getBIOSTable(PLDM_BIOS_ATTR_TABLE);
912 if (!attrTable.has_value())
913 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600914 error("Attribute table not present");
Sampa Misra46ece062020-03-18 07:17:44 -0500915 return;
916 }
917 const struct pldm_bios_attr_table_entry* tableEntry =
918 table::attribute::findByStringHandle(*attrTable, attrNameHdl);
919 if (tableEntry == nullptr)
920 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600921 error(
922 "Attribute not found in attribute table, name= {ATTR_NAME} name handle={ATTR_HANDLE}",
923 "ATTR_NAME", attrName.c_str(), "ATTR_HANDLE", attrNameHdl);
Sampa Misra46ece062020-03-18 07:17:44 -0500924 return;
925 }
926
Patrick Williams6da4f912023-05-10 07:50:53 -0500927 auto [attrHdl, attrType,
928 stringHdl] = table::attribute::decodeHeader(tableEntry);
Sampa Misra46ece062020-03-18 07:17:44 -0500929
930 auto attrValueSrcTable = getBIOSTable(PLDM_BIOS_ATTR_VAL_TABLE);
931
932 if (!attrValueSrcTable.has_value())
933 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600934 error("Attribute value table not present");
Sampa Misra46ece062020-03-18 07:17:44 -0500935 return;
936 }
937
938 Table newValue;
939 auto rc = biosAttributes[biosAttrIndex]->updateAttrVal(
940 newValue, attrHdl, attrType, newPropVal);
941 if (rc != PLDM_SUCCESS)
942 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600943 error(
944 "Could not update the attribute value table for attribute handle={ATTR_HANDLE} and type={ATTR_TYPE}",
945 "ATTR_HANDLE", attrHdl, "ATTR_TYPE", (uint32_t)attrType);
Sampa Misra46ece062020-03-18 07:17:44 -0500946 return;
947 }
948 auto destTable = table::attribute_value::updateTable(
949 *attrValueSrcTable, newValue.data(), newValue.size());
950 if (destTable.has_value())
951 {
952 storeTable(tableDir / attrValueTableFile, *destTable);
953 }
Sampa Misra0f262332021-02-15 00:13:51 -0600954
Sagar Srinivascac0ebb2021-11-23 07:50:28 -0600955 rc = setAttrValue(newValue.data(), newValue.size(), true, false);
Sampa Misra0f262332021-02-15 00:13:51 -0600956 if (rc != PLDM_SUCCESS)
957 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600958 error("could not setAttrValue on base bios table and dbus, rc = {RC}",
959 "RC", rc);
Sampa Misra0f262332021-02-15 00:13:51 -0600960 }
Sampa Misra46ece062020-03-18 07:17:44 -0500961}
962
George Liu1244acf2020-08-14 09:11:11 +0800963uint16_t BIOSConfig::findAttrHandle(const std::string& attrName)
964{
965 auto stringTable = getBIOSTable(PLDM_BIOS_STRING_TABLE);
966 auto attrTable = getBIOSTable(PLDM_BIOS_ATTR_TABLE);
967
968 BIOSStringTable biosStringTable(*stringTable);
969 pldm::bios::utils::BIOSTableIter<PLDM_BIOS_ATTR_TABLE> attrTableIter(
970 attrTable->data(), attrTable->size());
971 auto stringHandle = biosStringTable.findHandle(attrName);
972
973 for (auto entry : pldm::bios::utils::BIOSTableIter<PLDM_BIOS_ATTR_TABLE>(
974 attrTable->data(), attrTable->size()))
975 {
976 auto header = table::attribute::decodeHeader(entry);
977 if (header.stringHandle == stringHandle)
978 {
979 return header.attrHandle;
980 }
981 }
982
983 throw std::invalid_argument("Unknow attribute Name");
984}
985
986void BIOSConfig::constructPendingAttribute(
987 const PendingAttributes& pendingAttributes)
988{
Tom Joseph7f839f92020-09-21 10:20:44 +0530989 std::vector<uint16_t> listOfHandles{};
990
George Liu1244acf2020-08-14 09:11:11 +0800991 for (auto& attribute : pendingAttributes)
992 {
993 std::string attributeName = attribute.first;
994 auto& [attributeType, attributevalue] = attribute.second;
995
996 auto iter = std::find_if(biosAttributes.begin(), biosAttributes.end(),
997 [&attributeName](const auto& attr) {
Patrick Williams6da4f912023-05-10 07:50:53 -0500998 return attr->name == attributeName;
999 });
George Liu1244acf2020-08-14 09:11:11 +08001000
1001 if (iter == biosAttributes.end())
1002 {
Riya Dixit49cfb132023-03-02 04:26:53 -06001003 error("Wrong attribute name, attributeName = {ATTR_NAME}",
1004 "ATTR_NAME", attributeName);
George Liu1244acf2020-08-14 09:11:11 +08001005 continue;
1006 }
1007
1008 Table attrValueEntry(sizeof(pldm_bios_attr_val_table_entry), 0);
1009 auto entry = reinterpret_cast<pldm_bios_attr_val_table_entry*>(
1010 attrValueEntry.data());
1011
1012 auto handler = findAttrHandle(attributeName);
1013 auto type =
1014 BIOSConfigManager::convertAttributeTypeFromString(attributeType);
1015
1016 if (type != BIOSConfigManager::AttributeType::Enumeration &&
1017 type != BIOSConfigManager::AttributeType::String &&
1018 type != BIOSConfigManager::AttributeType::Integer)
1019 {
Riya Dixit49cfb132023-03-02 04:26:53 -06001020 error("Attribute type not supported, attributeType = {ATTR_TYPE}",
1021 "ATTR_TYPE", attributeType);
George Liu1244acf2020-08-14 09:11:11 +08001022 continue;
1023 }
1024
George Liu4876c542022-06-08 15:59:54 +08001025 const auto [attrType, readonlyStatus, displayName, description,
Patrick Williams6da4f912023-05-10 07:50:53 -05001026 menuPath, currentValue, defaultValue,
1027 option] = baseBIOSTableMaps.at(attributeName);
George Liu4876c542022-06-08 15:59:54 +08001028
George Liu1244acf2020-08-14 09:11:11 +08001029 entry->attr_handle = htole16(handler);
George Liu4876c542022-06-08 15:59:54 +08001030
1031 // Need to verify that the current value has really changed
1032 if (attributeType == attrType && attributevalue != currentValue)
1033 {
1034 listOfHandles.emplace_back(htole16(handler));
1035 }
Tom Joseph7f839f92020-09-21 10:20:44 +05301036
George Liu1244acf2020-08-14 09:11:11 +08001037 (*iter)->generateAttributeEntry(attributevalue, attrValueEntry);
1038
Sagar Srinivascac0ebb2021-11-23 07:50:28 -06001039 setAttrValue(attrValueEntry.data(), attrValueEntry.size(), true);
Tom Joseph7f839f92020-09-21 10:20:44 +05301040 }
1041
1042 if (listOfHandles.size())
1043 {
1044#ifdef OEM_IBM
1045 auto rc = pldm::responder::platform::sendBiosAttributeUpdateEvent(
Andrew Jefferya330b2f2023-05-04 14:55:37 +09301046 eid, instanceIdDb, listOfHandles, handler);
Tom Joseph7f839f92020-09-21 10:20:44 +05301047 if (rc != PLDM_SUCCESS)
1048 {
1049 return;
1050 }
1051#endif
George Liu1244acf2020-08-14 09:11:11 +08001052 }
1053}
1054
1055void BIOSConfig::listenPendingAttributes()
1056{
1057 constexpr auto objPath = "/xyz/openbmc_project/bios_config/manager";
1058 constexpr auto objInterface = "xyz.openbmc_project.BIOSConfig.Manager";
1059
1060 using namespace sdbusplus::bus::match::rules;
Patrick Williams84b790c2022-07-22 19:26:56 -05001061 auto updateBIOSMatch = std::make_unique<sdbusplus::bus::match_t>(
George Liu1244acf2020-08-14 09:11:11 +08001062 pldm::utils::DBusHandler::getBus(),
1063 propertiesChanged(objPath, objInterface),
Patrick Williams84b790c2022-07-22 19:26:56 -05001064 [this](sdbusplus::message_t& msg) {
Patrick Williams6da4f912023-05-10 07:50:53 -05001065 constexpr auto propertyName = "PendingAttributes";
George Liu1244acf2020-08-14 09:11:11 +08001066
Patrick Williams6da4f912023-05-10 07:50:53 -05001067 using Value =
1068 std::variant<std::string, PendingAttributes, BaseBIOSTable>;
1069 using Properties = std::map<DbusProp, Value>;
George Liu1244acf2020-08-14 09:11:11 +08001070
Patrick Williams6da4f912023-05-10 07:50:53 -05001071 Properties props{};
1072 std::string intf;
1073 msg.read(intf, props);
George Liu1244acf2020-08-14 09:11:11 +08001074
Patrick Williams6da4f912023-05-10 07:50:53 -05001075 auto valPropMap = props.find(propertyName);
1076 if (valPropMap == props.end())
1077 {
1078 return;
1079 }
George Liu1244acf2020-08-14 09:11:11 +08001080
Patrick Williams6da4f912023-05-10 07:50:53 -05001081 PendingAttributes pendingAttributes =
1082 std::get<PendingAttributes>(valPropMap->second);
1083 this->constructPendingAttribute(pendingAttributes);
George Liu1244acf2020-08-14 09:11:11 +08001084 });
1085
1086 biosAttrMatch.emplace_back(std::move(updateBIOSMatch));
1087}
1088
John Wangd9659342020-02-27 16:46:05 +08001089} // namespace bios
1090} // namespace responder
1091} // namespace pldm