John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 1 | #include "bios_config.hpp" |
| 2 | |
John Wang | 3be7085 | 2020-02-13 15:59:04 +0800 | [diff] [blame] | 3 | #include "bios_enum_attribute.hpp" |
John Wang | 95e6b3c | 2020-02-13 09:43:24 +0800 | [diff] [blame] | 4 | #include "bios_integer_attribute.hpp" |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 5 | #include "bios_string_attribute.hpp" |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 6 | #include "bios_table.hpp" |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 7 | #include "common/bios_utils.hpp" |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 8 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 9 | #include <phosphor-logging/lg2.hpp> |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 10 | #include <xyz/openbmc_project/BIOSConfig/Manager/server.hpp> |
| 11 | |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 12 | #include <fstream> |
| 13 | #include <iostream> |
| 14 | |
Tom Joseph | 7f839f9 | 2020-09-21 10:20:44 +0530 | [diff] [blame] | 15 | #ifdef OEM_IBM |
| 16 | #include "oem/ibm/libpldmresponder/platform_oem_ibm.hpp" |
| 17 | #endif |
| 18 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 19 | PHOSPHOR_LOG2_USING; |
| 20 | |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 21 | using namespace pldm::utils; |
| 22 | |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 23 | namespace pldm |
| 24 | { |
| 25 | namespace responder |
| 26 | { |
| 27 | namespace bios |
| 28 | { |
| 29 | namespace |
| 30 | { |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 31 | using BIOSConfigManager = |
| 32 | sdbusplus::xyz::openbmc_project::BIOSConfig::server::Manager; |
| 33 | |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 34 | constexpr auto enumJsonFile = "enum_attrs.json"; |
| 35 | constexpr auto stringJsonFile = "string_attrs.json"; |
| 36 | constexpr auto integerJsonFile = "integer_attrs.json"; |
| 37 | |
| 38 | constexpr auto stringTableFile = "stringTable"; |
| 39 | constexpr auto attrTableFile = "attributeTable"; |
| 40 | constexpr auto attrValueTableFile = "attributeValueTable"; |
| 41 | |
| 42 | } // namespace |
| 43 | |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 44 | BIOSConfig::BIOSConfig( |
| 45 | const char* jsonDir, const char* tableDir, DBusHandler* const dbusHandler, |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 46 | int fd, uint8_t eid, pldm::InstanceIdDb* instanceIdDb, |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 47 | pldm::requester::Handler<pldm::requester::Request>* handler) : |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 48 | jsonDir(jsonDir), |
Tom Joseph | 7f839f9 | 2020-09-21 10:20:44 +0530 | [diff] [blame] | 49 | tableDir(tableDir), dbusHandler(dbusHandler), fd(fd), eid(eid), |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 50 | instanceIdDb(instanceIdDb), handler(handler) |
Tom Joseph | 7f839f9 | 2020-09-21 10:20:44 +0530 | [diff] [blame] | 51 | |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 52 | { |
George Liu | 9d8921e | 2020-05-14 15:41:50 +0800 | [diff] [blame] | 53 | fs::create_directories(tableDir); |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 54 | constructAttributes(); |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 55 | listenPendingAttributes(); |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | void BIOSConfig::buildTables() |
| 59 | { |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 60 | auto stringTable = buildAndStoreStringTable(); |
| 61 | if (stringTable) |
| 62 | { |
| 63 | buildAndStoreAttrTables(*stringTable); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | std::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 Joseph | 7f839f9 | 2020-09-21 10:20:44 +0530 | [diff] [blame] | 85 | int BIOSConfig::setBIOSTable(uint8_t tableType, const Table& table, |
| 86 | bool updateBaseBIOSTable) |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 87 | { |
| 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 Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 133 | } |
| 134 | else |
| 135 | { |
| 136 | return PLDM_INVALID_BIOS_TABLE_TYPE; |
| 137 | } |
| 138 | |
Tom Joseph | 7f839f9 | 2020-09-21 10:20:44 +0530 | [diff] [blame] | 139 | if ((tableType == PLDM_BIOS_ATTR_VAL_TABLE) && updateBaseBIOSTable) |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 140 | { |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 141 | updateBaseBIOSTableProperty(); |
| 142 | } |
| 143 | |
| 144 | return PLDM_SUCCESS; |
| 145 | } |
| 146 | |
| 147 | int 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 | |
| 220 | int 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 Liu | b1fbeec | 2020-09-04 09:59:46 +0800 | [diff] [blame] | 274 | biosAttributes[attrHandle % biosAttributes.size()]->readOnly; |
George Liu | 92bb402 | 2020-09-03 14:58:24 +0800 | [diff] [blame] | 275 | description = |
| 276 | biosAttributes[attrHandle % biosAttributes.size()]->helpText; |
| 277 | displayName = |
| 278 | biosAttributes[attrHandle % biosAttributes.size()]->displayName; |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 279 | } |
| 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 Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 342 | defaultValue = getValue(pvHandls[defIndices[i]], |
| 343 | *stringTable); |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 344 | } |
| 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, ¤tString); |
| 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 | |
| 428 | void 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 Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 445 | auto service = dbusHandler->getService(biosConfigPath, |
| 446 | biosConfigInterface); |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 447 | 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 Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 455 | error("failed to update BaseBIOSTable property, ERROR={ERR_EXCEP}", |
| 456 | "ERR_EXCEP", e.what()); |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 460 | void BIOSConfig::constructAttributes() |
| 461 | { |
| 462 | load(jsonDir / stringJsonFile, [this](const Json& entry) { |
| 463 | constructAttribute<BIOSStringAttribute>(entry); |
| 464 | }); |
John Wang | 3be7085 | 2020-02-13 15:59:04 +0800 | [diff] [blame] | 465 | load(jsonDir / integerJsonFile, [this](const Json& entry) { |
John Wang | 95e6b3c | 2020-02-13 09:43:24 +0800 | [diff] [blame] | 466 | constructAttribute<BIOSIntegerAttribute>(entry); |
| 467 | }); |
John Wang | 3be7085 | 2020-02-13 15:59:04 +0800 | [diff] [blame] | 468 | load(jsonDir / enumJsonFile, [this](const Json& entry) { |
| 469 | constructAttribute<BIOSEnumAttribute>(entry); |
| 470 | }); |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | void BIOSConfig::buildAndStoreAttrTables(const Table& stringTable) |
| 474 | { |
| 475 | BIOSStringTable biosStringTable(stringTable); |
| 476 | |
| 477 | if (biosAttributes.empty()) |
| 478 | { |
| 479 | return; |
| 480 | } |
| 481 | |
Tom Joseph | ca7b252 | 2020-11-18 12:27:11 +0530 | [diff] [blame] | 482 | 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 Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 490 | auto method = bus.new_method_call(service.c_str(), biosObjPath, |
| 491 | "org.freedesktop.DBus.Properties", |
| 492 | "Get"); |
Tom Joseph | ca7b252 | 2020-11-18 12:27:11 +0530 | [diff] [blame] | 493 | method.append(biosInterface, "BaseBIOSTable"); |
vkaverap@in.ibm.com | 9138c20 | 2023-05-19 07:50:47 -0500 | [diff] [blame^] | 494 | auto reply = bus.call( |
| 495 | method, |
| 496 | std::chrono::duration_cast<microsec>(sec(DBUS_TIMEOUT)).count()); |
Tom Joseph | ca7b252 | 2020-11-18 12:27:11 +0530 | [diff] [blame] | 497 | 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 Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 506 | error("Failed to read BaseBIOSTable property, ERROR={ERR_EXCEP}", |
| 507 | "ERR_EXCEP", e.what()); |
Tom Joseph | ca7b252 | 2020-11-18 12:27:11 +0530 | [diff] [blame] | 508 | } |
| 509 | |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 510 | Table attrTable, attrValueTable; |
| 511 | |
| 512 | for (auto& attr : biosAttributes) |
| 513 | { |
| 514 | try |
| 515 | { |
Tom Joseph | ca7b252 | 2020-11-18 12:27:11 +0530 | [diff] [blame] | 516 | 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 Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 529 | } |
| 530 | catch (const std::exception& e) |
| 531 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 532 | error("Construct Table Entry Error, AttributeName = {ATTR_NAME}", |
| 533 | "ATTR_NAME", attr->name); |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 534 | } |
| 535 | } |
| 536 | |
| 537 | table::appendPadAndChecksum(attrTable); |
| 538 | table::appendPadAndChecksum(attrValueTable); |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 539 | setBIOSTable(PLDM_BIOS_ATTR_TABLE, attrTable); |
| 540 | setBIOSTable(PLDM_BIOS_ATTR_VAL_TABLE, attrValueTable); |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | std::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 Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 573 | setBIOSTable(PLDM_BIOS_STRING_TABLE, table); |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 574 | return table; |
| 575 | } |
| 576 | |
| 577 | void BIOSConfig::storeTable(const fs::path& path, const Table& table) |
| 578 | { |
| 579 | BIOSTable biosTable(path.c_str()); |
| 580 | biosTable.store(table); |
| 581 | } |
| 582 | |
| 583 | std::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 | |
| 596 | void 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 Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 615 | 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 Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 618 | } |
| 619 | } |
| 620 | } |
| 621 | catch (const std::exception& e) |
| 622 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 623 | error("Failed to parse JSON config file : {JSON_PATH}", "JSON_PATH", |
| 624 | filePath.c_str()); |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 625 | } |
| 626 | } |
| 627 | } |
| 628 | |
Sagar Srinivas | cac0ebb | 2021-11-23 07:50:28 -0600 | [diff] [blame] | 629 | std::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 | |
| 640 | std::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 | |
| 662 | void 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 Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 669 | auto [attrHandle, |
| 670 | attrType] = table::attribute_value::decodeHeader(attrValueEntry); |
Sagar Srinivas | cac0ebb | 2021-11-23 07:50:28 -0600 | [diff] [blame] | 671 | |
| 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 Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 689 | 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 Srinivas | cac0ebb | 2021-11-23 07:50:28 -0600 | [diff] [blame] | 695 | } |
| 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 Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 703 | 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 Srinivas | cac0ebb | 2021-11-23 07:50:28 -0600 | [diff] [blame] | 707 | 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 Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 714 | 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 Srinivas | cac0ebb | 2021-11-23 07:50:28 -0600 | [diff] [blame] | 718 | break; |
| 719 | } |
| 720 | default: |
| 721 | break; |
| 722 | }; |
| 723 | } |
| 724 | |
John Wang | 8241b34 | 2020-06-05 10:49:17 +0800 | [diff] [blame] | 725 | int BIOSConfig::checkAttrValueToUpdate( |
| 726 | const pldm_bios_attr_val_table_entry* attrValueEntry, |
| 727 | const pldm_bios_attr_table_entry* attrEntry, Table&) |
| 728 | |
| 729 | { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 730 | auto [attrHandle, |
| 731 | attrType] = table::attribute_value::decodeHeader(attrValueEntry); |
John Wang | 8241b34 | 2020-06-05 10:49:17 +0800 | [diff] [blame] | 732 | |
| 733 | switch (attrType) |
| 734 | { |
| 735 | case PLDM_BIOS_ENUMERATION: |
George Liu | 5bb9edb | 2021-08-05 20:10:32 +0800 | [diff] [blame] | 736 | case PLDM_BIOS_ENUMERATION_READ_ONLY: |
John Wang | 8241b34 | 2020-06-05 10:49:17 +0800 | [diff] [blame] | 737 | { |
| 738 | auto value = |
| 739 | table::attribute_value::decodeEnumEntry(attrValueEntry); |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 740 | auto [pvHdls, |
| 741 | defIndex] = table::attribute::decodeEnumEntry(attrEntry); |
Varsha Kaverappa | 6a4d1cf | 2021-11-24 21:15:42 -0600 | [diff] [blame] | 742 | if (!(value.size() == 1)) |
| 743 | { |
| 744 | return PLDM_ERROR_INVALID_LENGTH; |
| 745 | } |
John Wang | 8241b34 | 2020-06-05 10:49:17 +0800 | [diff] [blame] | 746 | if (value[0] >= pvHdls.size()) |
| 747 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 748 | error("Enum: Illgeal index, Index = {ATTR_INDEX}", "ATTR_INDEX", |
| 749 | (int)value[0]); |
John Wang | 8241b34 | 2020-06-05 10:49:17 +0800 | [diff] [blame] | 750 | return PLDM_ERROR_INVALID_DATA; |
| 751 | } |
John Wang | 8241b34 | 2020-06-05 10:49:17 +0800 | [diff] [blame] | 752 | return PLDM_SUCCESS; |
| 753 | } |
| 754 | case PLDM_BIOS_INTEGER: |
George Liu | 5bb9edb | 2021-08-05 20:10:32 +0800 | [diff] [blame] | 755 | case PLDM_BIOS_INTEGER_READ_ONLY: |
John Wang | 8241b34 | 2020-06-05 10:49:17 +0800 | [diff] [blame] | 756 | { |
| 757 | auto value = |
| 758 | table::attribute_value::decodeIntegerEntry(attrValueEntry); |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 759 | auto [lower, upper, scalar, |
| 760 | def] = table::attribute::decodeIntegerEntry(attrEntry); |
John Wang | 8241b34 | 2020-06-05 10:49:17 +0800 | [diff] [blame] | 761 | |
| 762 | if (value < lower || value > upper) |
| 763 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 764 | error("Integer: out of bound, value = {ATTR_VALUE}", |
| 765 | "ATTR_VALUE", value); |
John Wang | 8241b34 | 2020-06-05 10:49:17 +0800 | [diff] [blame] | 766 | return PLDM_ERROR_INVALID_DATA; |
| 767 | } |
| 768 | return PLDM_SUCCESS; |
| 769 | } |
| 770 | case PLDM_BIOS_STRING: |
George Liu | 5bb9edb | 2021-08-05 20:10:32 +0800 | [diff] [blame] | 771 | case PLDM_BIOS_STRING_READ_ONLY: |
John Wang | 8241b34 | 2020-06-05 10:49:17 +0800 | [diff] [blame] | 772 | { |
| 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 Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 779 | error( |
| 780 | "String: Length error, string = {ATTR_VALUE} length {LEN}", |
| 781 | "ATTR_VALUE", value, "LEN", value.size()); |
John Wang | 8241b34 | 2020-06-05 10:49:17 +0800 | [diff] [blame] | 782 | return PLDM_ERROR_INVALID_LENGTH; |
| 783 | } |
| 784 | return PLDM_SUCCESS; |
| 785 | } |
| 786 | default: |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 787 | error("ReadOnly or Unspported type, type = {ATTR_TYPE}", |
| 788 | "ATTR_TYPE", attrType); |
John Wang | 8241b34 | 2020-06-05 10:49:17 +0800 | [diff] [blame] | 789 | return PLDM_ERROR; |
| 790 | }; |
| 791 | } |
| 792 | |
Sagar Srinivas | cac0ebb | 2021-11-23 07:50:28 -0600 | [diff] [blame] | 793 | int BIOSConfig::setAttrValue(const void* entry, size_t size, bool isBMC, |
| 794 | bool updateDBus, bool updateBaseBIOSTable) |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 795 | { |
| 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 Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 804 | auto attrValueEntry = |
| 805 | reinterpret_cast<const pldm_bios_attr_val_table_entry*>(entry); |
| 806 | |
| 807 | auto attrValHeader = table::attribute_value::decodeHeader(attrValueEntry); |
| 808 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 809 | auto attrEntry = table::attribute::findByHandle(*attrTable, |
| 810 | attrValHeader.attrHandle); |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 811 | if (!attrEntry) |
| 812 | { |
| 813 | return PLDM_ERROR; |
| 814 | } |
| 815 | |
John Wang | 8241b34 | 2020-06-05 10:49:17 +0800 | [diff] [blame] | 816 | auto rc = checkAttrValueToUpdate(attrValueEntry, attrEntry, *stringTable); |
| 817 | if (rc != PLDM_SUCCESS) |
| 818 | { |
| 819 | return rc; |
| 820 | } |
| 821 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 822 | auto destTable = table::attribute_value::updateTable(*attrValueTable, entry, |
| 823 | size); |
John Wang | 8241b34 | 2020-06-05 10:49:17 +0800 | [diff] [blame] | 824 | |
| 825 | if (!destTable) |
| 826 | { |
| 827 | return PLDM_ERROR; |
| 828 | } |
| 829 | |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 830 | try |
| 831 | { |
| 832 | auto attrHeader = table::attribute::decodeHeader(attrEntry); |
| 833 | |
| 834 | BIOSStringTable biosStringTable(*stringTable); |
| 835 | auto attrName = biosStringTable.findString(attrHeader.stringHandle); |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 836 | auto iter = std::find_if(biosAttributes.begin(), biosAttributes.end(), |
| 837 | [&attrName](const auto& attr) { |
| 838 | return attr->name == attrName; |
| 839 | }); |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 840 | |
| 841 | if (iter == biosAttributes.end()) |
| 842 | { |
| 843 | return PLDM_ERROR; |
| 844 | } |
George Liu | 6d6d1e8 | 2021-02-16 11:08:55 +0800 | [diff] [blame] | 845 | if (updateDBus) |
| 846 | { |
| 847 | (*iter)->setAttrValueOnDbus(attrValueEntry, attrEntry, |
| 848 | biosStringTable); |
| 849 | } |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 850 | } |
| 851 | catch (const std::exception& e) |
| 852 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 853 | error("Set attribute value error: {ERR_EXCEP}", "ERR_EXCEP", e.what()); |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 854 | return PLDM_ERROR; |
| 855 | } |
| 856 | |
Tom Joseph | 7f839f9 | 2020-09-21 10:20:44 +0530 | [diff] [blame] | 857 | setBIOSTable(PLDM_BIOS_ATTR_VAL_TABLE, *destTable, updateBaseBIOSTable); |
George Liu | 5c3192b | 2020-08-13 17:35:43 +0800 | [diff] [blame] | 858 | |
Sagar Srinivas | cac0ebb | 2021-11-23 07:50:28 -0600 | [diff] [blame] | 859 | traceBIOSUpdate(attrValueEntry, attrEntry, isBMC); |
| 860 | |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 861 | return PLDM_SUCCESS; |
| 862 | } |
| 863 | |
| 864 | void 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 Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 874 | error("Remove the tables error: {ERR_EXCEP}", "ERR_EXCEP", e.what()); |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 875 | } |
| 876 | } |
| 877 | |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 878 | void 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 Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 895 | error("BIOS string table unavailable"); |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 896 | return; |
| 897 | } |
| 898 | BIOSStringTable biosStringTable(*stringTable); |
| 899 | uint16_t attrNameHdl{}; |
| 900 | try |
| 901 | { |
| 902 | attrNameHdl = biosStringTable.findHandle(attrName); |
| 903 | } |
Patrick Williams | 5133058 | 2021-10-06 12:48:56 -0500 | [diff] [blame] | 904 | catch (const std::invalid_argument& e) |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 905 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 906 | error("Could not find handle for BIOS string, ATTRIBUTE={ATTR_NAME}", |
| 907 | "ATTR_NAME", attrName.c_str()); |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 908 | return; |
| 909 | } |
| 910 | |
| 911 | auto attrTable = getBIOSTable(PLDM_BIOS_ATTR_TABLE); |
| 912 | if (!attrTable.has_value()) |
| 913 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 914 | error("Attribute table not present"); |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 915 | return; |
| 916 | } |
| 917 | const struct pldm_bios_attr_table_entry* tableEntry = |
| 918 | table::attribute::findByStringHandle(*attrTable, attrNameHdl); |
| 919 | if (tableEntry == nullptr) |
| 920 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 921 | 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 Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 924 | return; |
| 925 | } |
| 926 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 927 | auto [attrHdl, attrType, |
| 928 | stringHdl] = table::attribute::decodeHeader(tableEntry); |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 929 | |
| 930 | auto attrValueSrcTable = getBIOSTable(PLDM_BIOS_ATTR_VAL_TABLE); |
| 931 | |
| 932 | if (!attrValueSrcTable.has_value()) |
| 933 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 934 | error("Attribute value table not present"); |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 935 | return; |
| 936 | } |
| 937 | |
| 938 | Table newValue; |
| 939 | auto rc = biosAttributes[biosAttrIndex]->updateAttrVal( |
| 940 | newValue, attrHdl, attrType, newPropVal); |
| 941 | if (rc != PLDM_SUCCESS) |
| 942 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 943 | 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 Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 946 | 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 Misra | 0f26233 | 2021-02-15 00:13:51 -0600 | [diff] [blame] | 954 | |
Sagar Srinivas | cac0ebb | 2021-11-23 07:50:28 -0600 | [diff] [blame] | 955 | rc = setAttrValue(newValue.data(), newValue.size(), true, false); |
Sampa Misra | 0f26233 | 2021-02-15 00:13:51 -0600 | [diff] [blame] | 956 | if (rc != PLDM_SUCCESS) |
| 957 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 958 | error("could not setAttrValue on base bios table and dbus, rc = {RC}", |
| 959 | "RC", rc); |
Sampa Misra | 0f26233 | 2021-02-15 00:13:51 -0600 | [diff] [blame] | 960 | } |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 961 | } |
| 962 | |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 963 | uint16_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 | |
| 986 | void BIOSConfig::constructPendingAttribute( |
| 987 | const PendingAttributes& pendingAttributes) |
| 988 | { |
Tom Joseph | 7f839f9 | 2020-09-21 10:20:44 +0530 | [diff] [blame] | 989 | std::vector<uint16_t> listOfHandles{}; |
| 990 | |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 991 | 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 Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 998 | return attr->name == attributeName; |
| 999 | }); |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 1000 | |
| 1001 | if (iter == biosAttributes.end()) |
| 1002 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 1003 | error("Wrong attribute name, attributeName = {ATTR_NAME}", |
| 1004 | "ATTR_NAME", attributeName); |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 1005 | 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 Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 1020 | error("Attribute type not supported, attributeType = {ATTR_TYPE}", |
| 1021 | "ATTR_TYPE", attributeType); |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 1022 | continue; |
| 1023 | } |
| 1024 | |
George Liu | 4876c54 | 2022-06-08 15:59:54 +0800 | [diff] [blame] | 1025 | const auto [attrType, readonlyStatus, displayName, description, |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 1026 | menuPath, currentValue, defaultValue, |
| 1027 | option] = baseBIOSTableMaps.at(attributeName); |
George Liu | 4876c54 | 2022-06-08 15:59:54 +0800 | [diff] [blame] | 1028 | |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 1029 | entry->attr_handle = htole16(handler); |
George Liu | 4876c54 | 2022-06-08 15:59:54 +0800 | [diff] [blame] | 1030 | |
| 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 Joseph | 7f839f9 | 2020-09-21 10:20:44 +0530 | [diff] [blame] | 1036 | |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 1037 | (*iter)->generateAttributeEntry(attributevalue, attrValueEntry); |
| 1038 | |
Sagar Srinivas | cac0ebb | 2021-11-23 07:50:28 -0600 | [diff] [blame] | 1039 | setAttrValue(attrValueEntry.data(), attrValueEntry.size(), true); |
Tom Joseph | 7f839f9 | 2020-09-21 10:20:44 +0530 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | if (listOfHandles.size()) |
| 1043 | { |
| 1044 | #ifdef OEM_IBM |
| 1045 | auto rc = pldm::responder::platform::sendBiosAttributeUpdateEvent( |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 1046 | eid, instanceIdDb, listOfHandles, handler); |
Tom Joseph | 7f839f9 | 2020-09-21 10:20:44 +0530 | [diff] [blame] | 1047 | if (rc != PLDM_SUCCESS) |
| 1048 | { |
| 1049 | return; |
| 1050 | } |
| 1051 | #endif |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | void 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 Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 1061 | auto updateBIOSMatch = std::make_unique<sdbusplus::bus::match_t>( |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 1062 | pldm::utils::DBusHandler::getBus(), |
| 1063 | propertiesChanged(objPath, objInterface), |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 1064 | [this](sdbusplus::message_t& msg) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 1065 | constexpr auto propertyName = "PendingAttributes"; |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 1066 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 1067 | using Value = |
| 1068 | std::variant<std::string, PendingAttributes, BaseBIOSTable>; |
| 1069 | using Properties = std::map<DbusProp, Value>; |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 1070 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 1071 | Properties props{}; |
| 1072 | std::string intf; |
| 1073 | msg.read(intf, props); |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 1074 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 1075 | auto valPropMap = props.find(propertyName); |
| 1076 | if (valPropMap == props.end()) |
| 1077 | { |
| 1078 | return; |
| 1079 | } |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 1080 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 1081 | PendingAttributes pendingAttributes = |
| 1082 | std::get<PendingAttributes>(valPropMap->second); |
| 1083 | this->constructPendingAttribute(pendingAttributes); |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 1084 | }); |
| 1085 | |
| 1086 | biosAttrMatch.emplace_back(std::move(updateBIOSMatch)); |
| 1087 | } |
| 1088 | |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 1089 | } // namespace bios |
| 1090 | } // namespace responder |
| 1091 | } // namespace pldm |