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