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