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, |
Sagar Srinivas | 11ce8d2 | 2022-07-28 11:32:34 -0500 | [diff] [blame] | 47 | pldm::requester::Handler<pldm::requester::Request>* handler, |
| 48 | pldm::responder::oem_bios::Handler* oemBiosHandler) : |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 49 | jsonDir(jsonDir), |
Tom Joseph | 7f839f9 | 2020-09-21 10:20:44 +0530 | [diff] [blame] | 50 | tableDir(tableDir), dbusHandler(dbusHandler), fd(fd), eid(eid), |
Sagar Srinivas | 11ce8d2 | 2022-07-28 11:32:34 -0500 | [diff] [blame] | 51 | instanceIdDb(instanceIdDb), handler(handler), oemBiosHandler(oemBiosHandler) |
Tom Joseph | 7f839f9 | 2020-09-21 10:20:44 +0530 | [diff] [blame] | 52 | |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 53 | { |
Sagar Srinivas | 11ce8d2 | 2022-07-28 11:32:34 -0500 | [diff] [blame] | 54 | if (oemBiosHandler) |
| 55 | { |
| 56 | auto systemType = oemBiosHandler->getPlatformName(); |
| 57 | if (systemType.has_value()) |
| 58 | { |
| 59 | sysType = systemType.value(); |
| 60 | } |
| 61 | } |
George Liu | 9d8921e | 2020-05-14 15:41:50 +0800 | [diff] [blame] | 62 | fs::create_directories(tableDir); |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 63 | constructAttributes(); |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 64 | listenPendingAttributes(); |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | void BIOSConfig::buildTables() |
| 68 | { |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 69 | auto stringTable = buildAndStoreStringTable(); |
| 70 | if (stringTable) |
| 71 | { |
| 72 | buildAndStoreAttrTables(*stringTable); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | std::optional<Table> BIOSConfig::getBIOSTable(pldm_bios_table_types tableType) |
| 77 | { |
| 78 | fs::path tablePath; |
| 79 | switch (tableType) |
| 80 | { |
| 81 | case PLDM_BIOS_STRING_TABLE: |
| 82 | tablePath = tableDir / stringTableFile; |
| 83 | break; |
| 84 | case PLDM_BIOS_ATTR_TABLE: |
| 85 | tablePath = tableDir / attrTableFile; |
| 86 | break; |
| 87 | case PLDM_BIOS_ATTR_VAL_TABLE: |
| 88 | tablePath = tableDir / attrValueTableFile; |
| 89 | break; |
| 90 | } |
| 91 | return loadTable(tablePath); |
| 92 | } |
| 93 | |
Tom Joseph | 7f839f9 | 2020-09-21 10:20:44 +0530 | [diff] [blame] | 94 | int BIOSConfig::setBIOSTable(uint8_t tableType, const Table& table, |
| 95 | bool updateBaseBIOSTable) |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 96 | { |
| 97 | fs::path stringTablePath(tableDir / stringTableFile); |
| 98 | fs::path attrTablePath(tableDir / attrTableFile); |
| 99 | fs::path attrValueTablePath(tableDir / attrValueTableFile); |
| 100 | |
| 101 | if (!pldm_bios_table_checksum(table.data(), table.size())) |
| 102 | { |
| 103 | return PLDM_INVALID_BIOS_TABLE_DATA_INTEGRITY_CHECK; |
| 104 | } |
| 105 | |
| 106 | if (tableType == PLDM_BIOS_STRING_TABLE) |
| 107 | { |
| 108 | storeTable(stringTablePath, table); |
| 109 | } |
| 110 | else if (tableType == PLDM_BIOS_ATTR_TABLE) |
| 111 | { |
| 112 | BIOSTable biosStringTable(stringTablePath.c_str()); |
| 113 | if (biosStringTable.isEmpty()) |
| 114 | { |
| 115 | return PLDM_INVALID_BIOS_TABLE_TYPE; |
| 116 | } |
| 117 | |
| 118 | auto rc = checkAttributeTable(table); |
| 119 | if (rc != PLDM_SUCCESS) |
| 120 | { |
| 121 | return rc; |
| 122 | } |
| 123 | |
| 124 | storeTable(attrTablePath, table); |
| 125 | } |
| 126 | else if (tableType == PLDM_BIOS_ATTR_VAL_TABLE) |
| 127 | { |
| 128 | BIOSTable biosStringTable(stringTablePath.c_str()); |
| 129 | BIOSTable biosStringValueTable(attrTablePath.c_str()); |
| 130 | if (biosStringTable.isEmpty() || biosStringValueTable.isEmpty()) |
| 131 | { |
| 132 | return PLDM_INVALID_BIOS_TABLE_TYPE; |
| 133 | } |
| 134 | |
| 135 | auto rc = checkAttributeValueTable(table); |
| 136 | if (rc != PLDM_SUCCESS) |
| 137 | { |
| 138 | return rc; |
| 139 | } |
| 140 | |
| 141 | storeTable(attrValueTablePath, table); |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 142 | } |
| 143 | else |
| 144 | { |
| 145 | return PLDM_INVALID_BIOS_TABLE_TYPE; |
| 146 | } |
| 147 | |
Tom Joseph | 7f839f9 | 2020-09-21 10:20:44 +0530 | [diff] [blame] | 148 | if ((tableType == PLDM_BIOS_ATTR_VAL_TABLE) && updateBaseBIOSTable) |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 149 | { |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 150 | updateBaseBIOSTableProperty(); |
| 151 | } |
| 152 | |
| 153 | return PLDM_SUCCESS; |
| 154 | } |
| 155 | |
| 156 | int BIOSConfig::checkAttributeTable(const Table& table) |
| 157 | { |
| 158 | using namespace pldm::bios::utils; |
| 159 | auto stringTable = getBIOSTable(PLDM_BIOS_STRING_TABLE); |
| 160 | for (auto entry : |
| 161 | BIOSTableIter<PLDM_BIOS_ATTR_TABLE>(table.data(), table.size())) |
| 162 | { |
| 163 | auto attrNameHandle = |
| 164 | pldm_bios_table_attr_entry_decode_string_handle(entry); |
| 165 | |
| 166 | auto stringEnty = pldm_bios_table_string_find_by_handle( |
| 167 | stringTable->data(), stringTable->size(), attrNameHandle); |
| 168 | if (stringEnty == nullptr) |
| 169 | { |
| 170 | return PLDM_INVALID_BIOS_ATTR_HANDLE; |
| 171 | } |
| 172 | |
| 173 | auto attrType = static_cast<pldm_bios_attribute_type>( |
| 174 | pldm_bios_table_attr_entry_decode_attribute_type(entry)); |
| 175 | |
| 176 | switch (attrType) |
| 177 | { |
| 178 | case PLDM_BIOS_ENUMERATION: |
| 179 | case PLDM_BIOS_ENUMERATION_READ_ONLY: |
| 180 | { |
Andrew Jeffery | 488f19d | 2023-06-13 20:43:39 +0930 | [diff] [blame] | 181 | uint8_t pvNum; |
| 182 | // Preconditions are upheld therefore no error check necessary |
| 183 | pldm_bios_table_attr_entry_enum_decode_pv_num_check(entry, |
| 184 | &pvNum); |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 185 | std::vector<uint16_t> pvHandls(pvNum); |
Andrew Jeffery | 488f19d | 2023-06-13 20:43:39 +0930 | [diff] [blame] | 186 | // Preconditions are upheld therefore no error check necessary |
| 187 | pldm_bios_table_attr_entry_enum_decode_pv_hdls_check( |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 188 | entry, pvHandls.data(), pvHandls.size()); |
Andrew Jeffery | 488f19d | 2023-06-13 20:43:39 +0930 | [diff] [blame] | 189 | uint8_t defNum; |
| 190 | pldm_bios_table_attr_entry_enum_decode_def_num_check(entry, |
| 191 | &defNum); |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 192 | std::vector<uint8_t> defIndices(defNum); |
| 193 | pldm_bios_table_attr_entry_enum_decode_def_indices( |
| 194 | entry, defIndices.data(), defIndices.size()); |
| 195 | |
| 196 | for (size_t i = 0; i < pvHandls.size(); i++) |
| 197 | { |
| 198 | auto stringEntry = pldm_bios_table_string_find_by_handle( |
| 199 | stringTable->data(), stringTable->size(), pvHandls[i]); |
| 200 | if (stringEntry == nullptr) |
| 201 | { |
| 202 | return PLDM_INVALID_BIOS_ATTR_HANDLE; |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | for (size_t i = 0; i < defIndices.size(); i++) |
| 207 | { |
| 208 | auto stringEntry = pldm_bios_table_string_find_by_handle( |
| 209 | stringTable->data(), stringTable->size(), |
| 210 | pvHandls[defIndices[i]]); |
| 211 | if (stringEntry == nullptr) |
| 212 | { |
| 213 | return PLDM_INVALID_BIOS_ATTR_HANDLE; |
| 214 | } |
| 215 | } |
| 216 | break; |
| 217 | } |
| 218 | case PLDM_BIOS_INTEGER: |
| 219 | case PLDM_BIOS_INTEGER_READ_ONLY: |
| 220 | case PLDM_BIOS_STRING: |
| 221 | case PLDM_BIOS_STRING_READ_ONLY: |
| 222 | case PLDM_BIOS_PASSWORD: |
| 223 | case PLDM_BIOS_PASSWORD_READ_ONLY: |
| 224 | break; |
| 225 | default: |
| 226 | return PLDM_INVALID_BIOS_ATTR_HANDLE; |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | return PLDM_SUCCESS; |
| 231 | } |
| 232 | |
| 233 | int BIOSConfig::checkAttributeValueTable(const Table& table) |
| 234 | { |
| 235 | using namespace pldm::bios::utils; |
| 236 | auto stringTable = getBIOSTable(PLDM_BIOS_STRING_TABLE); |
| 237 | auto attrTable = getBIOSTable(PLDM_BIOS_ATTR_TABLE); |
| 238 | |
| 239 | baseBIOSTableMaps.clear(); |
| 240 | |
| 241 | for (auto tableEntry : |
| 242 | BIOSTableIter<PLDM_BIOS_ATTR_VAL_TABLE>(table.data(), table.size())) |
| 243 | { |
| 244 | AttributeName attributeName{}; |
| 245 | AttributeType attributeType{}; |
| 246 | ReadonlyStatus readonlyStatus{}; |
| 247 | DisplayName displayName{}; |
| 248 | Description description{}; |
| 249 | MenuPath menuPath{}; |
| 250 | CurrentValue currentValue{}; |
| 251 | DefaultValue defaultValue{}; |
| 252 | Option options{}; |
| 253 | |
| 254 | auto attrValueHandle = |
| 255 | pldm_bios_table_attr_value_entry_decode_attribute_handle( |
| 256 | tableEntry); |
| 257 | auto attrType = static_cast<pldm_bios_attribute_type>( |
| 258 | pldm_bios_table_attr_value_entry_decode_attribute_type(tableEntry)); |
| 259 | |
| 260 | auto attrEntry = pldm_bios_table_attr_find_by_handle( |
| 261 | attrTable->data(), attrTable->size(), attrValueHandle); |
| 262 | if (attrEntry == nullptr) |
| 263 | { |
| 264 | return PLDM_INVALID_BIOS_ATTR_HANDLE; |
| 265 | } |
| 266 | auto attrHandle = |
| 267 | pldm_bios_table_attr_entry_decode_attribute_handle(attrEntry); |
| 268 | auto attrNameHandle = |
| 269 | pldm_bios_table_attr_entry_decode_string_handle(attrEntry); |
| 270 | |
| 271 | auto stringEntry = pldm_bios_table_string_find_by_handle( |
| 272 | stringTable->data(), stringTable->size(), attrNameHandle); |
| 273 | if (stringEntry == nullptr) |
| 274 | { |
| 275 | return PLDM_INVALID_BIOS_ATTR_HANDLE; |
| 276 | } |
| 277 | auto strLength = |
| 278 | pldm_bios_table_string_entry_decode_string_length(stringEntry); |
| 279 | std::vector<char> buffer(strLength + 1 /* sizeof '\0' */); |
Andrew Jeffery | 488f19d | 2023-06-13 20:43:39 +0930 | [diff] [blame] | 280 | // Preconditions are upheld therefore no error check necessary |
| 281 | pldm_bios_table_string_entry_decode_string_check( |
| 282 | stringEntry, buffer.data(), buffer.size()); |
| 283 | |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 284 | attributeName = std::string(buffer.data(), buffer.data() + strLength); |
| 285 | |
| 286 | if (!biosAttributes.empty()) |
| 287 | { |
| 288 | readonlyStatus = |
George Liu | b1fbeec | 2020-09-04 09:59:46 +0800 | [diff] [blame] | 289 | biosAttributes[attrHandle % biosAttributes.size()]->readOnly; |
George Liu | 92bb402 | 2020-09-03 14:58:24 +0800 | [diff] [blame] | 290 | description = |
| 291 | biosAttributes[attrHandle % biosAttributes.size()]->helpText; |
| 292 | displayName = |
| 293 | biosAttributes[attrHandle % biosAttributes.size()]->displayName; |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | switch (attrType) |
| 297 | { |
| 298 | case PLDM_BIOS_ENUMERATION: |
| 299 | case PLDM_BIOS_ENUMERATION_READ_ONLY: |
| 300 | { |
| 301 | auto getValue = [](uint16_t handle, |
| 302 | const Table& table) -> std::string { |
| 303 | auto stringEntry = pldm_bios_table_string_find_by_handle( |
| 304 | table.data(), table.size(), handle); |
| 305 | |
| 306 | auto strLength = |
| 307 | pldm_bios_table_string_entry_decode_string_length( |
| 308 | stringEntry); |
| 309 | std::vector<char> buffer(strLength + 1 /* sizeof '\0' */); |
Andrew Jeffery | 488f19d | 2023-06-13 20:43:39 +0930 | [diff] [blame] | 310 | // Preconditions are upheld therefore no error check |
| 311 | // necessary |
| 312 | pldm_bios_table_string_entry_decode_string_check( |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 313 | stringEntry, buffer.data(), buffer.size()); |
| 314 | |
| 315 | return std::string(buffer.data(), |
| 316 | buffer.data() + strLength); |
| 317 | }; |
| 318 | |
| 319 | attributeType = "xyz.openbmc_project.BIOSConfig.Manager." |
| 320 | "AttributeType.Enumeration"; |
| 321 | |
Andrew Jeffery | 488f19d | 2023-06-13 20:43:39 +0930 | [diff] [blame] | 322 | uint8_t pvNum; |
| 323 | // Preconditions are upheld therefore no error check necessary |
| 324 | pldm_bios_table_attr_entry_enum_decode_pv_num_check(attrEntry, |
| 325 | &pvNum); |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 326 | std::vector<uint16_t> pvHandls(pvNum); |
Andrew Jeffery | 488f19d | 2023-06-13 20:43:39 +0930 | [diff] [blame] | 327 | // Preconditions are upheld therefore no error check necessary |
| 328 | pldm_bios_table_attr_entry_enum_decode_pv_hdls_check( |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 329 | attrEntry, pvHandls.data(), pvHandls.size()); |
| 330 | |
| 331 | // get possible_value |
| 332 | for (size_t i = 0; i < pvHandls.size(); i++) |
| 333 | { |
| 334 | options.push_back( |
| 335 | std::make_tuple("xyz.openbmc_project.BIOSConfig." |
| 336 | "Manager.BoundType.OneOf", |
| 337 | getValue(pvHandls[i], *stringTable))); |
| 338 | } |
| 339 | |
| 340 | auto count = |
| 341 | pldm_bios_table_attr_value_entry_enum_decode_number( |
| 342 | tableEntry); |
| 343 | std::vector<uint8_t> handles(count); |
| 344 | pldm_bios_table_attr_value_entry_enum_decode_handles( |
| 345 | tableEntry, handles.data(), handles.size()); |
| 346 | |
| 347 | // get current_value |
| 348 | for (size_t i = 0; i < handles.size(); i++) |
| 349 | { |
| 350 | currentValue = getValue(pvHandls[handles[i]], *stringTable); |
| 351 | } |
| 352 | |
Andrew Jeffery | 488f19d | 2023-06-13 20:43:39 +0930 | [diff] [blame] | 353 | uint8_t defNum; |
| 354 | // Preconditions are upheld therefore no error check necessary |
| 355 | pldm_bios_table_attr_entry_enum_decode_def_num_check(attrEntry, |
| 356 | &defNum); |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 357 | std::vector<uint8_t> defIndices(defNum); |
| 358 | pldm_bios_table_attr_entry_enum_decode_def_indices( |
| 359 | attrEntry, defIndices.data(), defIndices.size()); |
| 360 | |
| 361 | // get default_value |
| 362 | for (size_t i = 0; i < defIndices.size(); i++) |
| 363 | { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 364 | defaultValue = getValue(pvHandls[defIndices[i]], |
| 365 | *stringTable); |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | break; |
| 369 | } |
| 370 | case PLDM_BIOS_INTEGER: |
| 371 | case PLDM_BIOS_INTEGER_READ_ONLY: |
| 372 | { |
| 373 | attributeType = "xyz.openbmc_project.BIOSConfig.Manager." |
| 374 | "AttributeType.Integer"; |
| 375 | currentValue = static_cast<int64_t>( |
| 376 | pldm_bios_table_attr_value_entry_integer_decode_cv( |
| 377 | tableEntry)); |
| 378 | |
| 379 | uint64_t lower, upper, def; |
| 380 | uint32_t scalar; |
| 381 | pldm_bios_table_attr_entry_integer_decode( |
| 382 | attrEntry, &lower, &upper, &scalar, &def); |
| 383 | options.push_back( |
| 384 | std::make_tuple("xyz.openbmc_project.BIOSConfig.Manager." |
| 385 | "BoundType.LowerBound", |
| 386 | static_cast<int64_t>(lower))); |
| 387 | options.push_back( |
| 388 | std::make_tuple("xyz.openbmc_project.BIOSConfig.Manager." |
| 389 | "BoundType.UpperBound", |
| 390 | static_cast<int64_t>(upper))); |
| 391 | options.push_back( |
| 392 | std::make_tuple("xyz.openbmc_project.BIOSConfig.Manager." |
| 393 | "BoundType.ScalarIncrement", |
| 394 | static_cast<int64_t>(scalar))); |
| 395 | defaultValue = static_cast<int64_t>(def); |
| 396 | break; |
| 397 | } |
| 398 | case PLDM_BIOS_STRING: |
| 399 | case PLDM_BIOS_STRING_READ_ONLY: |
| 400 | { |
| 401 | attributeType = "xyz.openbmc_project.BIOSConfig.Manager." |
| 402 | "AttributeType.String"; |
| 403 | variable_field currentString; |
| 404 | pldm_bios_table_attr_value_entry_string_decode_string( |
| 405 | tableEntry, ¤tString); |
| 406 | currentValue = std::string( |
| 407 | reinterpret_cast<const char*>(currentString.ptr), |
| 408 | currentString.length); |
| 409 | auto min = pldm_bios_table_attr_entry_string_decode_min_length( |
| 410 | attrEntry); |
| 411 | auto max = pldm_bios_table_attr_entry_string_decode_max_length( |
| 412 | attrEntry); |
Andrew Jeffery | 488f19d | 2023-06-13 20:43:39 +0930 | [diff] [blame] | 413 | uint16_t def; |
| 414 | // Preconditions are upheld therefore no error check necessary |
| 415 | pldm_bios_table_attr_entry_string_decode_def_string_length_check( |
| 416 | attrEntry, &def); |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 417 | std::vector<char> defString(def + 1); |
| 418 | pldm_bios_table_attr_entry_string_decode_def_string( |
| 419 | attrEntry, defString.data(), defString.size()); |
| 420 | options.push_back( |
| 421 | std::make_tuple("xyz.openbmc_project.BIOSConfig.Manager." |
| 422 | "BoundType.MinStringLength", |
| 423 | static_cast<int64_t>(min))); |
| 424 | options.push_back( |
| 425 | std::make_tuple("xyz.openbmc_project.BIOSConfig.Manager." |
| 426 | "BoundType.MaxStringLength", |
| 427 | static_cast<int64_t>(max))); |
| 428 | defaultValue = defString.data(); |
| 429 | break; |
| 430 | } |
| 431 | case PLDM_BIOS_PASSWORD: |
| 432 | case PLDM_BIOS_PASSWORD_READ_ONLY: |
| 433 | { |
| 434 | attributeType = "xyz.openbmc_project.BIOSConfig.Manager." |
| 435 | "AttributeType.Password"; |
| 436 | break; |
| 437 | } |
| 438 | default: |
| 439 | return PLDM_INVALID_BIOS_ATTR_HANDLE; |
| 440 | } |
| 441 | baseBIOSTableMaps.emplace( |
| 442 | std::move(attributeName), |
| 443 | std::make_tuple(attributeType, readonlyStatus, displayName, |
| 444 | description, menuPath, currentValue, defaultValue, |
| 445 | std::move(options))); |
| 446 | } |
| 447 | |
| 448 | return PLDM_SUCCESS; |
| 449 | } |
| 450 | |
| 451 | void BIOSConfig::updateBaseBIOSTableProperty() |
| 452 | { |
| 453 | constexpr static auto biosConfigPath = |
| 454 | "/xyz/openbmc_project/bios_config/manager"; |
| 455 | constexpr static auto biosConfigInterface = |
| 456 | "xyz.openbmc_project.BIOSConfig.Manager"; |
| 457 | constexpr static auto biosConfigPropertyName = "BaseBIOSTable"; |
| 458 | constexpr static auto dbusProperties = "org.freedesktop.DBus.Properties"; |
| 459 | |
| 460 | if (baseBIOSTableMaps.empty()) |
| 461 | { |
| 462 | return; |
| 463 | } |
| 464 | |
| 465 | try |
| 466 | { |
| 467 | auto& bus = dbusHandler->getBus(); |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 468 | auto service = dbusHandler->getService(biosConfigPath, |
| 469 | biosConfigInterface); |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 470 | auto method = bus.new_method_call(service.c_str(), biosConfigPath, |
| 471 | dbusProperties, "Set"); |
| 472 | std::variant<BaseBIOSTable> value = baseBIOSTableMaps; |
| 473 | method.append(biosConfigInterface, biosConfigPropertyName, value); |
vkaverap@in.ibm.com | 5b71b86 | 2023-08-21 05:19:04 +0000 | [diff] [blame] | 474 | bus.call_noreply(method, dbusTimeout); |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 475 | } |
| 476 | catch (const std::exception& e) |
| 477 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 478 | error("failed to update BaseBIOSTable property, ERROR={ERR_EXCEP}", |
| 479 | "ERR_EXCEP", e.what()); |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 480 | } |
| 481 | } |
| 482 | |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 483 | void BIOSConfig::constructAttributes() |
| 484 | { |
Sagar Srinivas | 11ce8d2 | 2022-07-28 11:32:34 -0500 | [diff] [blame] | 485 | load(jsonDir / sysType / stringJsonFile, [this](const Json& entry) { |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 486 | constructAttribute<BIOSStringAttribute>(entry); |
| 487 | }); |
Sagar Srinivas | 11ce8d2 | 2022-07-28 11:32:34 -0500 | [diff] [blame] | 488 | load(jsonDir / sysType / integerJsonFile, [this](const Json& entry) { |
John Wang | 95e6b3c | 2020-02-13 09:43:24 +0800 | [diff] [blame] | 489 | constructAttribute<BIOSIntegerAttribute>(entry); |
| 490 | }); |
Sagar Srinivas | 11ce8d2 | 2022-07-28 11:32:34 -0500 | [diff] [blame] | 491 | load(jsonDir / sysType / enumJsonFile, [this](const Json& entry) { |
John Wang | 3be7085 | 2020-02-13 15:59:04 +0800 | [diff] [blame] | 492 | constructAttribute<BIOSEnumAttribute>(entry); |
| 493 | }); |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | void BIOSConfig::buildAndStoreAttrTables(const Table& stringTable) |
| 497 | { |
| 498 | BIOSStringTable biosStringTable(stringTable); |
| 499 | |
| 500 | if (biosAttributes.empty()) |
| 501 | { |
| 502 | return; |
| 503 | } |
| 504 | |
Tom Joseph | ca7b252 | 2020-11-18 12:27:11 +0530 | [diff] [blame] | 505 | BaseBIOSTable biosTable{}; |
| 506 | constexpr auto biosObjPath = "/xyz/openbmc_project/bios_config/manager"; |
| 507 | constexpr auto biosInterface = "xyz.openbmc_project.BIOSConfig.Manager"; |
| 508 | |
| 509 | try |
| 510 | { |
| 511 | auto& bus = dbusHandler->getBus(); |
| 512 | auto service = dbusHandler->getService(biosObjPath, biosInterface); |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 513 | auto method = bus.new_method_call(service.c_str(), biosObjPath, |
| 514 | "org.freedesktop.DBus.Properties", |
| 515 | "Get"); |
Tom Joseph | ca7b252 | 2020-11-18 12:27:11 +0530 | [diff] [blame] | 516 | method.append(biosInterface, "BaseBIOSTable"); |
vkaverap@in.ibm.com | 91a092f | 2023-09-18 23:39:44 -0500 | [diff] [blame] | 517 | auto reply = bus.call(method, dbusTimeout); |
Tom Joseph | ca7b252 | 2020-11-18 12:27:11 +0530 | [diff] [blame] | 518 | std::variant<BaseBIOSTable> varBiosTable{}; |
| 519 | reply.read(varBiosTable); |
| 520 | biosTable = std::get<BaseBIOSTable>(varBiosTable); |
| 521 | } |
| 522 | // Failed to read the BaseBIOSTable, so update the BaseBIOSTable with the |
| 523 | // default values populated from the BIOS JSONs to keep PLDM and |
| 524 | // bios-settings-manager in sync |
| 525 | catch (const std::exception& e) |
| 526 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 527 | error("Failed to read BaseBIOSTable property, ERROR={ERR_EXCEP}", |
| 528 | "ERR_EXCEP", e.what()); |
Tom Joseph | ca7b252 | 2020-11-18 12:27:11 +0530 | [diff] [blame] | 529 | } |
| 530 | |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 531 | Table attrTable, attrValueTable; |
| 532 | |
| 533 | for (auto& attr : biosAttributes) |
| 534 | { |
| 535 | try |
| 536 | { |
Tom Joseph | ca7b252 | 2020-11-18 12:27:11 +0530 | [diff] [blame] | 537 | auto iter = biosTable.find(attr->name); |
| 538 | if (iter == biosTable.end()) |
| 539 | { |
| 540 | attr->constructEntry(biosStringTable, attrTable, attrValueTable, |
| 541 | std::nullopt); |
| 542 | } |
| 543 | else |
| 544 | { |
| 545 | attr->constructEntry( |
| 546 | biosStringTable, attrTable, attrValueTable, |
| 547 | std::get<static_cast<uint8_t>(Index::currentValue)>( |
| 548 | iter->second)); |
| 549 | } |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 550 | } |
| 551 | catch (const std::exception& e) |
| 552 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 553 | error("Construct Table Entry Error, AttributeName = {ATTR_NAME}", |
| 554 | "ATTR_NAME", attr->name); |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 555 | } |
| 556 | } |
| 557 | |
| 558 | table::appendPadAndChecksum(attrTable); |
| 559 | table::appendPadAndChecksum(attrValueTable); |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 560 | setBIOSTable(PLDM_BIOS_ATTR_TABLE, attrTable); |
| 561 | setBIOSTable(PLDM_BIOS_ATTR_VAL_TABLE, attrValueTable); |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | std::optional<Table> BIOSConfig::buildAndStoreStringTable() |
| 565 | { |
| 566 | std::set<std::string> strings; |
| 567 | auto handler = [&strings](const Json& entry) { |
| 568 | strings.emplace(entry.at("attribute_name")); |
| 569 | }; |
| 570 | |
Sagar Srinivas | 11ce8d2 | 2022-07-28 11:32:34 -0500 | [diff] [blame] | 571 | load(jsonDir / sysType / stringJsonFile, handler); |
| 572 | load(jsonDir / sysType / integerJsonFile, handler); |
| 573 | load(jsonDir / sysType / enumJsonFile, [&strings](const Json& entry) { |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 574 | strings.emplace(entry.at("attribute_name")); |
| 575 | auto possibleValues = entry.at("possible_values"); |
| 576 | for (auto& pv : possibleValues) |
| 577 | { |
| 578 | strings.emplace(pv); |
| 579 | } |
| 580 | }); |
| 581 | |
| 582 | if (strings.empty()) |
| 583 | { |
| 584 | return std::nullopt; |
| 585 | } |
| 586 | |
| 587 | Table table; |
| 588 | for (const auto& elem : strings) |
| 589 | { |
| 590 | table::string::constructEntry(table, elem); |
| 591 | } |
| 592 | |
| 593 | table::appendPadAndChecksum(table); |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 594 | setBIOSTable(PLDM_BIOS_STRING_TABLE, table); |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 595 | return table; |
| 596 | } |
| 597 | |
| 598 | void BIOSConfig::storeTable(const fs::path& path, const Table& table) |
| 599 | { |
| 600 | BIOSTable biosTable(path.c_str()); |
| 601 | biosTable.store(table); |
| 602 | } |
| 603 | |
| 604 | std::optional<Table> BIOSConfig::loadTable(const fs::path& path) |
| 605 | { |
| 606 | BIOSTable biosTable(path.c_str()); |
| 607 | if (biosTable.isEmpty()) |
| 608 | { |
| 609 | return std::nullopt; |
| 610 | } |
| 611 | |
| 612 | Table table; |
| 613 | biosTable.load(table); |
| 614 | return table; |
| 615 | } |
| 616 | |
| 617 | void BIOSConfig::load(const fs::path& filePath, ParseHandler handler) |
| 618 | { |
| 619 | std::ifstream file; |
| 620 | Json jsonConf; |
| 621 | if (fs::exists(filePath)) |
| 622 | { |
| 623 | try |
| 624 | { |
| 625 | file.open(filePath); |
| 626 | jsonConf = Json::parse(file); |
| 627 | auto entries = jsonConf.at("entries"); |
| 628 | for (auto& entry : entries) |
| 629 | { |
| 630 | try |
| 631 | { |
| 632 | handler(entry); |
| 633 | } |
| 634 | catch (const std::exception& e) |
| 635 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 636 | error( |
| 637 | "Failed to parse JSON config file(entry handler) : {JSON_PATH}, {ERR_EXCEP}", |
| 638 | "JSON_PATH", filePath.c_str(), "ERR_EXCEP", e.what()); |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 639 | } |
| 640 | } |
| 641 | } |
| 642 | catch (const std::exception& e) |
| 643 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 644 | error("Failed to parse JSON config file : {JSON_PATH}", "JSON_PATH", |
| 645 | filePath.c_str()); |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 646 | } |
| 647 | } |
| 648 | } |
| 649 | |
Sagar Srinivas | cac0ebb | 2021-11-23 07:50:28 -0600 | [diff] [blame] | 650 | std::string BIOSConfig::decodeStringFromStringEntry( |
| 651 | const pldm_bios_string_table_entry* stringEntry) |
| 652 | { |
| 653 | auto strLength = |
| 654 | pldm_bios_table_string_entry_decode_string_length(stringEntry); |
| 655 | std::vector<char> buffer(strLength + 1 /* sizeof '\0' */); |
Andrew Jeffery | 488f19d | 2023-06-13 20:43:39 +0930 | [diff] [blame] | 656 | // Preconditions are upheld therefore no error check necessary |
| 657 | pldm_bios_table_string_entry_decode_string_check(stringEntry, buffer.data(), |
| 658 | buffer.size()); |
Sagar Srinivas | cac0ebb | 2021-11-23 07:50:28 -0600 | [diff] [blame] | 659 | return std::string(buffer.data(), buffer.data() + strLength); |
| 660 | } |
| 661 | |
| 662 | std::string |
| 663 | BIOSConfig::displayStringHandle(uint16_t handle, uint8_t index, |
| 664 | const std::optional<Table>& attrTable, |
| 665 | const std::optional<Table>& stringTable) |
| 666 | { |
| 667 | auto attrEntry = pldm_bios_table_attr_find_by_handle( |
| 668 | attrTable->data(), attrTable->size(), handle); |
Andrew Jeffery | 488f19d | 2023-06-13 20:43:39 +0930 | [diff] [blame] | 669 | uint8_t pvNum; |
| 670 | int rc = pldm_bios_table_attr_entry_enum_decode_pv_num_check(attrEntry, |
| 671 | &pvNum); |
| 672 | if (rc != PLDM_SUCCESS) |
| 673 | { |
| 674 | error( |
| 675 | "Failed to decode BIOS table possible values for attribute entry: {LIPBLDM_ERROR}", |
| 676 | "LIBPLDM_ERROR", rc); |
| 677 | throw std::runtime_error( |
| 678 | "Failed to decode BIOS table possible values for attribute entry"); |
| 679 | } |
| 680 | |
Sagar Srinivas | cac0ebb | 2021-11-23 07:50:28 -0600 | [diff] [blame] | 681 | std::vector<uint16_t> pvHandls(pvNum); |
Andrew Jeffery | 488f19d | 2023-06-13 20:43:39 +0930 | [diff] [blame] | 682 | // Preconditions are upheld therefore no error check necessary |
| 683 | pldm_bios_table_attr_entry_enum_decode_pv_hdls_check( |
| 684 | attrEntry, pvHandls.data(), pvHandls.size()); |
Sagar Srinivas | cac0ebb | 2021-11-23 07:50:28 -0600 | [diff] [blame] | 685 | |
| 686 | std::string displayString = std::to_string(pvHandls[index]); |
| 687 | |
| 688 | auto stringEntry = pldm_bios_table_string_find_by_handle( |
| 689 | stringTable->data(), stringTable->size(), pvHandls[index]); |
| 690 | |
| 691 | auto decodedStr = decodeStringFromStringEntry(stringEntry); |
| 692 | |
| 693 | return decodedStr + "(" + displayString + ")"; |
| 694 | } |
| 695 | |
| 696 | void BIOSConfig::traceBIOSUpdate( |
| 697 | const pldm_bios_attr_val_table_entry* attrValueEntry, |
| 698 | const pldm_bios_attr_table_entry* attrEntry, bool isBMC) |
| 699 | { |
| 700 | auto stringTable = getBIOSTable(PLDM_BIOS_STRING_TABLE); |
| 701 | auto attrTable = getBIOSTable(PLDM_BIOS_ATTR_TABLE); |
| 702 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 703 | auto [attrHandle, |
| 704 | attrType] = table::attribute_value::decodeHeader(attrValueEntry); |
Sagar Srinivas | cac0ebb | 2021-11-23 07:50:28 -0600 | [diff] [blame] | 705 | |
| 706 | auto attrHeader = table::attribute::decodeHeader(attrEntry); |
| 707 | BIOSStringTable biosStringTable(*stringTable); |
| 708 | auto attrName = biosStringTable.findString(attrHeader.stringHandle); |
| 709 | |
| 710 | switch (attrType) |
| 711 | { |
| 712 | case PLDM_BIOS_ENUMERATION: |
| 713 | case PLDM_BIOS_ENUMERATION_READ_ONLY: |
| 714 | { |
| 715 | auto count = pldm_bios_table_attr_value_entry_enum_decode_number( |
| 716 | attrValueEntry); |
| 717 | std::vector<uint8_t> handles(count); |
| 718 | pldm_bios_table_attr_value_entry_enum_decode_handles( |
| 719 | attrValueEntry, handles.data(), handles.size()); |
| 720 | |
| 721 | for (uint8_t handle : handles) |
| 722 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 723 | auto nwVal = displayStringHandle(attrHandle, handle, attrTable, |
| 724 | stringTable); |
| 725 | auto chkBMC = isBMC ? "true" : "false"; |
| 726 | info( |
| 727 | "BIOS:{ATTR_NAME}, updated to value: {NEW_VAL}, by BMC: {CHK_BMC} ", |
| 728 | "ATTR_NAME", attrName, "NEW_VAL", nwVal, "CHK_BMC", chkBMC); |
Sagar Srinivas | cac0ebb | 2021-11-23 07:50:28 -0600 | [diff] [blame] | 729 | } |
| 730 | break; |
| 731 | } |
| 732 | case PLDM_BIOS_INTEGER: |
| 733 | case PLDM_BIOS_INTEGER_READ_ONLY: |
| 734 | { |
| 735 | auto value = |
| 736 | table::attribute_value::decodeIntegerEntry(attrValueEntry); |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 737 | auto chkBMC = isBMC ? "true" : "false"; |
| 738 | info( |
| 739 | "BIOS: {ATTR_NAME}, updated to value: {UPDATED_VAL}, by BMC: {CHK_BMC}", |
| 740 | "ATTR_NAME", attrName, "UPDATED_VAL", value, "CHK_BMC", chkBMC); |
Sagar Srinivas | cac0ebb | 2021-11-23 07:50:28 -0600 | [diff] [blame] | 741 | break; |
| 742 | } |
| 743 | case PLDM_BIOS_STRING: |
| 744 | case PLDM_BIOS_STRING_READ_ONLY: |
| 745 | { |
| 746 | auto value = |
| 747 | table::attribute_value::decodeStringEntry(attrValueEntry); |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 748 | auto chkBMC = isBMC ? "true" : "false"; |
| 749 | info( |
| 750 | "BIOS: {ATTR_NAME}, updated to value: {UPDATED_VAL}, by BMC: {CHK_BMC}", |
| 751 | "ATTR_NAME", attrName, "UPDATED_VAL", value, "CHK_BMC", chkBMC); |
Sagar Srinivas | cac0ebb | 2021-11-23 07:50:28 -0600 | [diff] [blame] | 752 | break; |
| 753 | } |
| 754 | default: |
| 755 | break; |
| 756 | }; |
| 757 | } |
| 758 | |
John Wang | 8241b34 | 2020-06-05 10:49:17 +0800 | [diff] [blame] | 759 | int BIOSConfig::checkAttrValueToUpdate( |
| 760 | const pldm_bios_attr_val_table_entry* attrValueEntry, |
| 761 | const pldm_bios_attr_table_entry* attrEntry, Table&) |
| 762 | |
| 763 | { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 764 | auto [attrHandle, |
| 765 | attrType] = table::attribute_value::decodeHeader(attrValueEntry); |
John Wang | 8241b34 | 2020-06-05 10:49:17 +0800 | [diff] [blame] | 766 | |
| 767 | switch (attrType) |
| 768 | { |
| 769 | case PLDM_BIOS_ENUMERATION: |
George Liu | 5bb9edb | 2021-08-05 20:10:32 +0800 | [diff] [blame] | 770 | case PLDM_BIOS_ENUMERATION_READ_ONLY: |
John Wang | 8241b34 | 2020-06-05 10:49:17 +0800 | [diff] [blame] | 771 | { |
| 772 | auto value = |
| 773 | table::attribute_value::decodeEnumEntry(attrValueEntry); |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 774 | auto [pvHdls, |
| 775 | defIndex] = table::attribute::decodeEnumEntry(attrEntry); |
Varsha Kaverappa | 6a4d1cf | 2021-11-24 21:15:42 -0600 | [diff] [blame] | 776 | if (!(value.size() == 1)) |
| 777 | { |
| 778 | return PLDM_ERROR_INVALID_LENGTH; |
| 779 | } |
John Wang | 8241b34 | 2020-06-05 10:49:17 +0800 | [diff] [blame] | 780 | if (value[0] >= pvHdls.size()) |
| 781 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 782 | error("Enum: Illgeal index, Index = {ATTR_INDEX}", "ATTR_INDEX", |
| 783 | (int)value[0]); |
John Wang | 8241b34 | 2020-06-05 10:49:17 +0800 | [diff] [blame] | 784 | return PLDM_ERROR_INVALID_DATA; |
| 785 | } |
John Wang | 8241b34 | 2020-06-05 10:49:17 +0800 | [diff] [blame] | 786 | return PLDM_SUCCESS; |
| 787 | } |
| 788 | case PLDM_BIOS_INTEGER: |
George Liu | 5bb9edb | 2021-08-05 20:10:32 +0800 | [diff] [blame] | 789 | case PLDM_BIOS_INTEGER_READ_ONLY: |
John Wang | 8241b34 | 2020-06-05 10:49:17 +0800 | [diff] [blame] | 790 | { |
| 791 | auto value = |
| 792 | table::attribute_value::decodeIntegerEntry(attrValueEntry); |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 793 | auto [lower, upper, scalar, |
| 794 | def] = table::attribute::decodeIntegerEntry(attrEntry); |
John Wang | 8241b34 | 2020-06-05 10:49:17 +0800 | [diff] [blame] | 795 | |
| 796 | if (value < lower || value > upper) |
| 797 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 798 | error("Integer: out of bound, value = {ATTR_VALUE}", |
| 799 | "ATTR_VALUE", value); |
John Wang | 8241b34 | 2020-06-05 10:49:17 +0800 | [diff] [blame] | 800 | return PLDM_ERROR_INVALID_DATA; |
| 801 | } |
| 802 | return PLDM_SUCCESS; |
| 803 | } |
| 804 | case PLDM_BIOS_STRING: |
George Liu | 5bb9edb | 2021-08-05 20:10:32 +0800 | [diff] [blame] | 805 | case PLDM_BIOS_STRING_READ_ONLY: |
John Wang | 8241b34 | 2020-06-05 10:49:17 +0800 | [diff] [blame] | 806 | { |
| 807 | auto stringConf = table::attribute::decodeStringEntry(attrEntry); |
| 808 | auto value = |
| 809 | table::attribute_value::decodeStringEntry(attrValueEntry); |
| 810 | if (value.size() < stringConf.minLength || |
| 811 | value.size() > stringConf.maxLength) |
| 812 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 813 | error( |
| 814 | "String: Length error, string = {ATTR_VALUE} length {LEN}", |
| 815 | "ATTR_VALUE", value, "LEN", value.size()); |
John Wang | 8241b34 | 2020-06-05 10:49:17 +0800 | [diff] [blame] | 816 | return PLDM_ERROR_INVALID_LENGTH; |
| 817 | } |
| 818 | return PLDM_SUCCESS; |
| 819 | } |
| 820 | default: |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 821 | error("ReadOnly or Unspported type, type = {ATTR_TYPE}", |
| 822 | "ATTR_TYPE", attrType); |
John Wang | 8241b34 | 2020-06-05 10:49:17 +0800 | [diff] [blame] | 823 | return PLDM_ERROR; |
| 824 | }; |
| 825 | } |
| 826 | |
Sagar Srinivas | cac0ebb | 2021-11-23 07:50:28 -0600 | [diff] [blame] | 827 | int BIOSConfig::setAttrValue(const void* entry, size_t size, bool isBMC, |
| 828 | bool updateDBus, bool updateBaseBIOSTable) |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 829 | { |
| 830 | auto attrValueTable = getBIOSTable(PLDM_BIOS_ATTR_VAL_TABLE); |
| 831 | auto attrTable = getBIOSTable(PLDM_BIOS_ATTR_TABLE); |
| 832 | auto stringTable = getBIOSTable(PLDM_BIOS_STRING_TABLE); |
| 833 | if (!attrValueTable || !attrTable || !stringTable) |
| 834 | { |
| 835 | return PLDM_BIOS_TABLE_UNAVAILABLE; |
| 836 | } |
| 837 | |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 838 | auto attrValueEntry = |
| 839 | reinterpret_cast<const pldm_bios_attr_val_table_entry*>(entry); |
| 840 | |
| 841 | auto attrValHeader = table::attribute_value::decodeHeader(attrValueEntry); |
| 842 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 843 | auto attrEntry = table::attribute::findByHandle(*attrTable, |
| 844 | attrValHeader.attrHandle); |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 845 | if (!attrEntry) |
| 846 | { |
| 847 | return PLDM_ERROR; |
| 848 | } |
| 849 | |
John Wang | 8241b34 | 2020-06-05 10:49:17 +0800 | [diff] [blame] | 850 | auto rc = checkAttrValueToUpdate(attrValueEntry, attrEntry, *stringTable); |
| 851 | if (rc != PLDM_SUCCESS) |
| 852 | { |
| 853 | return rc; |
| 854 | } |
| 855 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 856 | auto destTable = table::attribute_value::updateTable(*attrValueTable, entry, |
| 857 | size); |
John Wang | 8241b34 | 2020-06-05 10:49:17 +0800 | [diff] [blame] | 858 | |
| 859 | if (!destTable) |
| 860 | { |
| 861 | return PLDM_ERROR; |
| 862 | } |
| 863 | |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 864 | try |
| 865 | { |
| 866 | auto attrHeader = table::attribute::decodeHeader(attrEntry); |
| 867 | |
| 868 | BIOSStringTable biosStringTable(*stringTable); |
| 869 | auto attrName = biosStringTable.findString(attrHeader.stringHandle); |
Patrick Williams | a675662 | 2023-10-20 11:19:15 -0500 | [diff] [blame] | 870 | auto iter = std::find_if( |
| 871 | biosAttributes.begin(), biosAttributes.end(), |
| 872 | [&attrName](const auto& attr) { return attr->name == attrName; }); |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 873 | |
| 874 | if (iter == biosAttributes.end()) |
| 875 | { |
| 876 | return PLDM_ERROR; |
| 877 | } |
George Liu | 6d6d1e8 | 2021-02-16 11:08:55 +0800 | [diff] [blame] | 878 | if (updateDBus) |
| 879 | { |
| 880 | (*iter)->setAttrValueOnDbus(attrValueEntry, attrEntry, |
| 881 | biosStringTable); |
| 882 | } |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 883 | } |
| 884 | catch (const std::exception& e) |
| 885 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 886 | error("Set attribute value error: {ERR_EXCEP}", "ERR_EXCEP", e.what()); |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 887 | return PLDM_ERROR; |
| 888 | } |
| 889 | |
Tom Joseph | 7f839f9 | 2020-09-21 10:20:44 +0530 | [diff] [blame] | 890 | setBIOSTable(PLDM_BIOS_ATTR_VAL_TABLE, *destTable, updateBaseBIOSTable); |
George Liu | 5c3192b | 2020-08-13 17:35:43 +0800 | [diff] [blame] | 891 | |
Sagar Srinivas | cac0ebb | 2021-11-23 07:50:28 -0600 | [diff] [blame] | 892 | traceBIOSUpdate(attrValueEntry, attrEntry, isBMC); |
| 893 | |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 894 | return PLDM_SUCCESS; |
| 895 | } |
| 896 | |
| 897 | void BIOSConfig::removeTables() |
| 898 | { |
| 899 | try |
| 900 | { |
| 901 | fs::remove(tableDir / stringTableFile); |
| 902 | fs::remove(tableDir / attrTableFile); |
| 903 | fs::remove(tableDir / attrValueTableFile); |
| 904 | } |
| 905 | catch (const std::exception& e) |
| 906 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 907 | error("Remove the tables error: {ERR_EXCEP}", "ERR_EXCEP", e.what()); |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 908 | } |
| 909 | } |
| 910 | |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 911 | void BIOSConfig::processBiosAttrChangeNotification( |
| 912 | const DbusChObjProperties& chProperties, uint32_t biosAttrIndex) |
| 913 | { |
| 914 | const auto& dBusMap = biosAttributes[biosAttrIndex]->getDBusMap(); |
| 915 | const auto& propertyName = dBusMap->propertyName; |
| 916 | const auto& attrName = biosAttributes[biosAttrIndex]->name; |
| 917 | |
| 918 | const auto it = chProperties.find(propertyName); |
| 919 | if (it == chProperties.end()) |
| 920 | { |
| 921 | return; |
| 922 | } |
| 923 | |
| 924 | PropertyValue newPropVal = it->second; |
| 925 | auto stringTable = getBIOSTable(PLDM_BIOS_STRING_TABLE); |
| 926 | if (!stringTable.has_value()) |
| 927 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 928 | error("BIOS string table unavailable"); |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 929 | return; |
| 930 | } |
| 931 | BIOSStringTable biosStringTable(*stringTable); |
| 932 | uint16_t attrNameHdl{}; |
| 933 | try |
| 934 | { |
| 935 | attrNameHdl = biosStringTable.findHandle(attrName); |
| 936 | } |
Patrick Williams | 5133058 | 2021-10-06 12:48:56 -0500 | [diff] [blame] | 937 | catch (const std::invalid_argument& e) |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 938 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 939 | error("Could not find handle for BIOS string, ATTRIBUTE={ATTR_NAME}", |
| 940 | "ATTR_NAME", attrName.c_str()); |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 941 | return; |
| 942 | } |
| 943 | |
| 944 | auto attrTable = getBIOSTable(PLDM_BIOS_ATTR_TABLE); |
| 945 | if (!attrTable.has_value()) |
| 946 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 947 | error("Attribute table not present"); |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 948 | return; |
| 949 | } |
| 950 | const struct pldm_bios_attr_table_entry* tableEntry = |
| 951 | table::attribute::findByStringHandle(*attrTable, attrNameHdl); |
| 952 | if (tableEntry == nullptr) |
| 953 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 954 | error( |
| 955 | "Attribute not found in attribute table, name= {ATTR_NAME} name handle={ATTR_HANDLE}", |
| 956 | "ATTR_NAME", attrName.c_str(), "ATTR_HANDLE", attrNameHdl); |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 957 | return; |
| 958 | } |
| 959 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 960 | auto [attrHdl, attrType, |
| 961 | stringHdl] = table::attribute::decodeHeader(tableEntry); |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 962 | |
| 963 | auto attrValueSrcTable = getBIOSTable(PLDM_BIOS_ATTR_VAL_TABLE); |
| 964 | |
| 965 | if (!attrValueSrcTable.has_value()) |
| 966 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 967 | error("Attribute value table not present"); |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 968 | return; |
| 969 | } |
| 970 | |
| 971 | Table newValue; |
| 972 | auto rc = biosAttributes[biosAttrIndex]->updateAttrVal( |
| 973 | newValue, attrHdl, attrType, newPropVal); |
| 974 | if (rc != PLDM_SUCCESS) |
| 975 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 976 | error( |
| 977 | "Could not update the attribute value table for attribute handle={ATTR_HANDLE} and type={ATTR_TYPE}", |
| 978 | "ATTR_HANDLE", attrHdl, "ATTR_TYPE", (uint32_t)attrType); |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 979 | return; |
| 980 | } |
| 981 | auto destTable = table::attribute_value::updateTable( |
| 982 | *attrValueSrcTable, newValue.data(), newValue.size()); |
| 983 | if (destTable.has_value()) |
| 984 | { |
| 985 | storeTable(tableDir / attrValueTableFile, *destTable); |
| 986 | } |
Sampa Misra | 0f26233 | 2021-02-15 00:13:51 -0600 | [diff] [blame] | 987 | |
Sagar Srinivas | cac0ebb | 2021-11-23 07:50:28 -0600 | [diff] [blame] | 988 | rc = setAttrValue(newValue.data(), newValue.size(), true, false); |
Sampa Misra | 0f26233 | 2021-02-15 00:13:51 -0600 | [diff] [blame] | 989 | if (rc != PLDM_SUCCESS) |
| 990 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 991 | error("could not setAttrValue on base bios table and dbus, rc = {RC}", |
| 992 | "RC", rc); |
Sampa Misra | 0f26233 | 2021-02-15 00:13:51 -0600 | [diff] [blame] | 993 | } |
Sampa Misra | 46ece06 | 2020-03-18 07:17:44 -0500 | [diff] [blame] | 994 | } |
| 995 | |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 996 | uint16_t BIOSConfig::findAttrHandle(const std::string& attrName) |
| 997 | { |
| 998 | auto stringTable = getBIOSTable(PLDM_BIOS_STRING_TABLE); |
| 999 | auto attrTable = getBIOSTable(PLDM_BIOS_ATTR_TABLE); |
| 1000 | |
| 1001 | BIOSStringTable biosStringTable(*stringTable); |
| 1002 | pldm::bios::utils::BIOSTableIter<PLDM_BIOS_ATTR_TABLE> attrTableIter( |
| 1003 | attrTable->data(), attrTable->size()); |
| 1004 | auto stringHandle = biosStringTable.findHandle(attrName); |
| 1005 | |
| 1006 | for (auto entry : pldm::bios::utils::BIOSTableIter<PLDM_BIOS_ATTR_TABLE>( |
| 1007 | attrTable->data(), attrTable->size())) |
| 1008 | { |
| 1009 | auto header = table::attribute::decodeHeader(entry); |
| 1010 | if (header.stringHandle == stringHandle) |
| 1011 | { |
| 1012 | return header.attrHandle; |
| 1013 | } |
| 1014 | } |
| 1015 | |
| 1016 | throw std::invalid_argument("Unknow attribute Name"); |
| 1017 | } |
| 1018 | |
| 1019 | void BIOSConfig::constructPendingAttribute( |
| 1020 | const PendingAttributes& pendingAttributes) |
| 1021 | { |
Tom Joseph | 7f839f9 | 2020-09-21 10:20:44 +0530 | [diff] [blame] | 1022 | std::vector<uint16_t> listOfHandles{}; |
| 1023 | |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 1024 | for (auto& attribute : pendingAttributes) |
| 1025 | { |
| 1026 | std::string attributeName = attribute.first; |
| 1027 | auto& [attributeType, attributevalue] = attribute.second; |
| 1028 | |
| 1029 | auto iter = std::find_if(biosAttributes.begin(), biosAttributes.end(), |
| 1030 | [&attributeName](const auto& attr) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 1031 | return attr->name == attributeName; |
| 1032 | }); |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 1033 | |
| 1034 | if (iter == biosAttributes.end()) |
| 1035 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 1036 | error("Wrong attribute name, attributeName = {ATTR_NAME}", |
| 1037 | "ATTR_NAME", attributeName); |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 1038 | continue; |
| 1039 | } |
| 1040 | |
| 1041 | Table attrValueEntry(sizeof(pldm_bios_attr_val_table_entry), 0); |
| 1042 | auto entry = reinterpret_cast<pldm_bios_attr_val_table_entry*>( |
| 1043 | attrValueEntry.data()); |
| 1044 | |
| 1045 | auto handler = findAttrHandle(attributeName); |
| 1046 | auto type = |
| 1047 | BIOSConfigManager::convertAttributeTypeFromString(attributeType); |
| 1048 | |
| 1049 | if (type != BIOSConfigManager::AttributeType::Enumeration && |
| 1050 | type != BIOSConfigManager::AttributeType::String && |
| 1051 | type != BIOSConfigManager::AttributeType::Integer) |
| 1052 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 1053 | error("Attribute type not supported, attributeType = {ATTR_TYPE}", |
| 1054 | "ATTR_TYPE", attributeType); |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 1055 | continue; |
| 1056 | } |
| 1057 | |
George Liu | 4876c54 | 2022-06-08 15:59:54 +0800 | [diff] [blame] | 1058 | const auto [attrType, readonlyStatus, displayName, description, |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 1059 | menuPath, currentValue, defaultValue, |
| 1060 | option] = baseBIOSTableMaps.at(attributeName); |
George Liu | 4876c54 | 2022-06-08 15:59:54 +0800 | [diff] [blame] | 1061 | |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 1062 | entry->attr_handle = htole16(handler); |
George Liu | 4876c54 | 2022-06-08 15:59:54 +0800 | [diff] [blame] | 1063 | |
| 1064 | // Need to verify that the current value has really changed |
| 1065 | if (attributeType == attrType && attributevalue != currentValue) |
| 1066 | { |
| 1067 | listOfHandles.emplace_back(htole16(handler)); |
| 1068 | } |
Tom Joseph | 7f839f9 | 2020-09-21 10:20:44 +0530 | [diff] [blame] | 1069 | |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 1070 | (*iter)->generateAttributeEntry(attributevalue, attrValueEntry); |
| 1071 | |
Sagar Srinivas | cac0ebb | 2021-11-23 07:50:28 -0600 | [diff] [blame] | 1072 | setAttrValue(attrValueEntry.data(), attrValueEntry.size(), true); |
Tom Joseph | 7f839f9 | 2020-09-21 10:20:44 +0530 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | if (listOfHandles.size()) |
| 1076 | { |
| 1077 | #ifdef OEM_IBM |
| 1078 | auto rc = pldm::responder::platform::sendBiosAttributeUpdateEvent( |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 1079 | eid, instanceIdDb, listOfHandles, handler); |
Tom Joseph | 7f839f9 | 2020-09-21 10:20:44 +0530 | [diff] [blame] | 1080 | if (rc != PLDM_SUCCESS) |
| 1081 | { |
| 1082 | return; |
| 1083 | } |
| 1084 | #endif |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 1085 | } |
| 1086 | } |
| 1087 | |
| 1088 | void BIOSConfig::listenPendingAttributes() |
| 1089 | { |
| 1090 | constexpr auto objPath = "/xyz/openbmc_project/bios_config/manager"; |
| 1091 | constexpr auto objInterface = "xyz.openbmc_project.BIOSConfig.Manager"; |
| 1092 | |
| 1093 | using namespace sdbusplus::bus::match::rules; |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 1094 | auto updateBIOSMatch = std::make_unique<sdbusplus::bus::match_t>( |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 1095 | pldm::utils::DBusHandler::getBus(), |
| 1096 | propertiesChanged(objPath, objInterface), |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 1097 | [this](sdbusplus::message_t& msg) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 1098 | constexpr auto propertyName = "PendingAttributes"; |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 1099 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 1100 | using Value = |
| 1101 | std::variant<std::string, PendingAttributes, BaseBIOSTable>; |
| 1102 | using Properties = std::map<DbusProp, Value>; |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 1103 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 1104 | Properties props{}; |
| 1105 | std::string intf; |
| 1106 | msg.read(intf, props); |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 1107 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 1108 | auto valPropMap = props.find(propertyName); |
| 1109 | if (valPropMap == props.end()) |
| 1110 | { |
| 1111 | return; |
| 1112 | } |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 1113 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 1114 | PendingAttributes pendingAttributes = |
| 1115 | std::get<PendingAttributes>(valPropMap->second); |
| 1116 | this->constructPendingAttribute(pendingAttributes); |
Patrick Williams | a675662 | 2023-10-20 11:19:15 -0500 | [diff] [blame] | 1117 | }); |
George Liu | 1244acf | 2020-08-14 09:11:11 +0800 | [diff] [blame] | 1118 | |
| 1119 | biosAttrMatch.emplace_back(std::move(updateBIOSMatch)); |
| 1120 | } |
| 1121 | |
John Wang | d965934 | 2020-02-27 16:46:05 +0800 | [diff] [blame] | 1122 | } // namespace bios |
| 1123 | } // namespace responder |
| 1124 | } // namespace pldm |