Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 1 | #include "bios.hpp" |
| 2 | |
Deepak Kodihalli | d130e1a | 2020-06-17 05:55:32 -0500 | [diff] [blame] | 3 | #include "common/utils.hpp" |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 4 | |
Xiaochao Ma | 60227a0 | 2019-12-04 09:00:12 +0800 | [diff] [blame] | 5 | #include <time.h> |
| 6 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 7 | #include <phosphor-logging/lg2.hpp> |
| 8 | |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 9 | #include <array> |
| 10 | #include <chrono> |
| 11 | #include <ctime> |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 12 | #include <iostream> |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 13 | #include <stdexcept> |
| 14 | #include <string> |
| 15 | #include <variant> |
| 16 | #include <vector> |
| 17 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 18 | PHOSPHOR_LOG2_USING; |
| 19 | |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 20 | using namespace pldm::utils; |
| 21 | |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 22 | namespace pldm |
| 23 | { |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 24 | namespace responder |
| 25 | { |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 26 | namespace utils |
| 27 | { |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 28 | void epochToBCDTime(uint64_t timeSec, uint8_t& seconds, uint8_t& minutes, |
| 29 | uint8_t& hours, uint8_t& day, uint8_t& month, |
| 30 | uint16_t& year) |
| 31 | { |
| 32 | auto t = time_t(timeSec); |
| 33 | auto time = localtime(&t); |
| 34 | |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 35 | seconds = pldm::utils::decimalToBcd(time->tm_sec); |
| 36 | minutes = pldm::utils::decimalToBcd(time->tm_min); |
| 37 | hours = pldm::utils::decimalToBcd(time->tm_hour); |
| 38 | day = pldm::utils::decimalToBcd(time->tm_mday); |
| 39 | month = pldm::utils::decimalToBcd(time->tm_mon + |
| 40 | 1); // The number of months in the range |
| 41 | // 0 to 11.PLDM expects range 1 to 12 |
| 42 | year = pldm::utils::decimalToBcd(time->tm_year + |
| 43 | 1900); // The number of years since 1900 |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 44 | } |
| 45 | |
Xiaochao Ma | 60227a0 | 2019-12-04 09:00:12 +0800 | [diff] [blame] | 46 | std::time_t timeToEpoch(uint8_t seconds, uint8_t minutes, uint8_t hours, |
| 47 | uint8_t day, uint8_t month, uint16_t year) |
| 48 | { |
| 49 | struct std::tm stm; |
| 50 | |
| 51 | stm.tm_year = year - 1900; |
| 52 | stm.tm_mon = month - 1; |
| 53 | stm.tm_mday = day; |
| 54 | stm.tm_hour = hours; |
| 55 | stm.tm_min = minutes; |
| 56 | stm.tm_sec = seconds; |
| 57 | stm.tm_isdst = -1; |
| 58 | |
| 59 | // It will get the time in seconds since |
| 60 | // Epoch, 1970.1.1 00:00:00 +0000,UTC. |
| 61 | return timegm(&stm); |
| 62 | } |
| 63 | |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 64 | } // namespace utils |
| 65 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 66 | namespace bios |
| 67 | { |
John Wang | 6080aae | 2020-02-14 09:34:25 +0800 | [diff] [blame] | 68 | using EpochTimeUS = uint64_t; |
| 69 | |
| 70 | DBusHandler dbusHandler; |
| 71 | |
Kamalkumar Patel | 3c50c82 | 2024-01-30 07:14:40 -0600 | [diff] [blame] | 72 | Handler::Handler( |
| 73 | int fd, uint8_t eid, pldm::InstanceIdDb* instanceIdDb, |
| 74 | pldm::requester::Handler<pldm::requester::Request>* handler, |
| 75 | pldm::responder::platform_config::Handler* platformConfigHandler) : |
Tom Joseph | 7f839f9 | 2020-09-21 10:20:44 +0530 | [diff] [blame] | 76 | biosConfig(BIOS_JSONS_DIR, BIOS_TABLES_DIR, &dbusHandler, fd, eid, |
Kamalkumar Patel | 3c50c82 | 2024-01-30 07:14:40 -0600 | [diff] [blame] | 77 | instanceIdDb, handler, platformConfigHandler) |
Deepak Kodihalli | d9fb152 | 2019-11-28 10:06:34 -0600 | [diff] [blame] | 78 | { |
John Wang | 6080aae | 2020-02-14 09:34:25 +0800 | [diff] [blame] | 79 | biosConfig.removeTables(); |
| 80 | biosConfig.buildTables(); |
| 81 | |
Delphine CC Chiu | d2e4899 | 2023-12-05 16:29:51 +0800 | [diff] [blame] | 82 | handlers.emplace( |
| 83 | PLDM_SET_DATE_TIME, |
| 84 | [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 85 | return this->setDateTime(request, payloadLength); |
| 86 | }); |
Delphine CC Chiu | d2e4899 | 2023-12-05 16:29:51 +0800 | [diff] [blame] | 87 | handlers.emplace( |
| 88 | PLDM_GET_DATE_TIME, |
| 89 | [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 90 | return this->getDateTime(request, payloadLength); |
| 91 | }); |
Delphine CC Chiu | d2e4899 | 2023-12-05 16:29:51 +0800 | [diff] [blame] | 92 | handlers.emplace( |
| 93 | PLDM_GET_BIOS_TABLE, |
| 94 | [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 95 | return this->getBIOSTable(request, payloadLength); |
| 96 | }); |
Delphine CC Chiu | d2e4899 | 2023-12-05 16:29:51 +0800 | [diff] [blame] | 97 | handlers.emplace( |
| 98 | PLDM_SET_BIOS_TABLE, |
| 99 | [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 100 | return this->setBIOSTable(request, payloadLength); |
| 101 | }); |
Delphine CC Chiu | d2e4899 | 2023-12-05 16:29:51 +0800 | [diff] [blame] | 102 | handlers.emplace( |
| 103 | PLDM_GET_BIOS_ATTRIBUTE_CURRENT_VALUE_BY_HANDLE, |
| 104 | [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 105 | return this->getBIOSAttributeCurrentValueByHandle(request, |
| 106 | payloadLength); |
| 107 | }); |
Delphine CC Chiu | d2e4899 | 2023-12-05 16:29:51 +0800 | [diff] [blame] | 108 | handlers.emplace( |
| 109 | PLDM_SET_BIOS_ATTRIBUTE_CURRENT_VALUE, |
| 110 | [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 111 | return this->setBIOSAttributeCurrentValue(request, payloadLength); |
| 112 | }); |
Deepak Kodihalli | d9fb152 | 2019-11-28 10:06:34 -0600 | [diff] [blame] | 113 | } |
| 114 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 115 | Response Handler::getDateTime(const pldm_msg* request, size_t /*payloadLength*/) |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 116 | { |
| 117 | uint8_t seconds = 0; |
| 118 | uint8_t minutes = 0; |
| 119 | uint8_t hours = 0; |
| 120 | uint8_t day = 0; |
| 121 | uint8_t month = 0; |
| 122 | uint16_t year = 0; |
| 123 | |
| 124 | constexpr auto timeInterface = "xyz.openbmc_project.Time.EpochTime"; |
George Liu | fd97264 | 2020-04-12 12:08:23 +0800 | [diff] [blame] | 125 | constexpr auto bmcTimePath = "/xyz/openbmc_project/time/bmc"; |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 126 | Response response(sizeof(pldm_msg_hdr) + PLDM_GET_DATE_TIME_RESP_BYTES, 0); |
| 127 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
George Liu | 782d37f | 2020-01-24 09:02:17 +0800 | [diff] [blame] | 128 | EpochTimeUS timeUsec; |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 129 | |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 130 | try |
| 131 | { |
George Liu | 782d37f | 2020-01-24 09:02:17 +0800 | [diff] [blame] | 132 | timeUsec = pldm::utils::DBusHandler().getDbusProperty<EpochTimeUS>( |
George Liu | fd97264 | 2020-04-12 12:08:23 +0800 | [diff] [blame] | 133 | bmcTimePath, "Elapsed", timeInterface); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 134 | } |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 135 | catch (const sdbusplus::exception_t& e) |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 136 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 137 | error( |
Kamalkumar Patel | 58cbcaf | 2023-10-06 03:48:25 -0500 | [diff] [blame] | 138 | "Error getting time from Elapsed property at '{PATH}' on '{INTERFACE}': {ERROR}", |
| 139 | "PATH", bmcTimePath, "INTERFACE", timeInterface, "ERROR", e); |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 140 | return CmdHandler::ccOnlyResponse(request, PLDM_ERROR); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 141 | } |
| 142 | |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 143 | uint64_t timeSec = std::chrono::duration_cast<std::chrono::seconds>( |
| 144 | std::chrono::microseconds(timeUsec)) |
| 145 | .count(); |
| 146 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 147 | pldm::responder::utils::epochToBCDTime(timeSec, seconds, minutes, hours, |
| 148 | day, month, year); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 149 | |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 150 | auto rc = encode_get_date_time_resp(request->hdr.instance_id, PLDM_SUCCESS, |
| 151 | seconds, minutes, hours, day, month, |
| 152 | year, responsePtr); |
| 153 | if (rc != PLDM_SUCCESS) |
| 154 | { |
| 155 | return ccOnlyResponse(request, rc); |
| 156 | } |
| 157 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 158 | return response; |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 159 | } |
| 160 | |
Xiaochao Ma | 60227a0 | 2019-12-04 09:00:12 +0800 | [diff] [blame] | 161 | Response Handler::setDateTime(const pldm_msg* request, size_t payloadLength) |
| 162 | { |
| 163 | uint8_t seconds = 0; |
| 164 | uint8_t minutes = 0; |
| 165 | uint8_t hours = 0; |
| 166 | uint8_t day = 0; |
| 167 | uint8_t month = 0; |
| 168 | uint16_t year = 0; |
| 169 | std::time_t timeSec; |
| 170 | |
Pavithra Barithaya | 297720a | 2022-09-12 05:50:38 -0500 | [diff] [blame] | 171 | constexpr auto timeSyncPath = "/xyz/openbmc_project/time/sync_method"; |
| 172 | constexpr auto timeSyncInterface = |
| 173 | "xyz.openbmc_project.Time.Synchronization"; |
| 174 | constexpr auto timeSyncProperty = "TimeSyncMethod"; |
| 175 | |
| 176 | // The time is correct on BMC when in NTP mode, so we do not want to |
| 177 | // try and set the time again and cause potential time drifts. |
| 178 | try |
| 179 | { |
| 180 | auto propVal = pldm::utils::DBusHandler().getDbusPropertyVariant( |
| 181 | timeSyncPath, timeSyncProperty, timeSyncInterface); |
| 182 | const auto& mode = std::get<std::string>(propVal); |
| 183 | |
| 184 | if (mode == "xyz.openbmc_project.Time.Synchronization.Method.NTP") |
| 185 | { |
| 186 | return ccOnlyResponse(request, PLDM_SUCCESS); |
| 187 | } |
| 188 | } |
| 189 | catch (const std::exception& e) |
| 190 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 191 | error( |
| 192 | "Error getting the time sync property, PATH={TIME_SYNC_PATH} INTERFACE={SYNC_INTERFACE} PROPERTY={SYNC_PROP} ERROR={ERR_EXCEP}", |
| 193 | "TIME_SYNC_PATH", timeSyncPath, "SYNC_INTERFACE", timeSyncInterface, |
| 194 | "SYNC_PROP", timeSyncProperty, "ERR_EXCEP", e.what()); |
Pavithra Barithaya | 297720a | 2022-09-12 05:50:38 -0500 | [diff] [blame] | 195 | } |
| 196 | |
Xiaochao Ma | 60227a0 | 2019-12-04 09:00:12 +0800 | [diff] [blame] | 197 | constexpr auto setTimeInterface = "xyz.openbmc_project.Time.EpochTime"; |
George Liu | fd97264 | 2020-04-12 12:08:23 +0800 | [diff] [blame] | 198 | constexpr auto setTimePath = "/xyz/openbmc_project/time/bmc"; |
Xiaochao Ma | 60227a0 | 2019-12-04 09:00:12 +0800 | [diff] [blame] | 199 | constexpr auto timeSetPro = "Elapsed"; |
| 200 | |
| 201 | auto rc = decode_set_date_time_req(request, payloadLength, &seconds, |
| 202 | &minutes, &hours, &day, &month, &year); |
| 203 | if (rc != PLDM_SUCCESS) |
| 204 | { |
| 205 | return ccOnlyResponse(request, rc); |
| 206 | } |
| 207 | timeSec = pldm::responder::utils::timeToEpoch(seconds, minutes, hours, day, |
| 208 | month, year); |
| 209 | uint64_t timeUsec = std::chrono::duration_cast<std::chrono::microseconds>( |
| 210 | std::chrono::seconds(timeSec)) |
| 211 | .count(); |
George Liu | 1e44c73 | 2020-02-28 20:20:06 +0800 | [diff] [blame] | 212 | PropertyValue value{timeUsec}; |
Xiaochao Ma | 60227a0 | 2019-12-04 09:00:12 +0800 | [diff] [blame] | 213 | try |
| 214 | { |
George Liu | 1e44c73 | 2020-02-28 20:20:06 +0800 | [diff] [blame] | 215 | DBusMapping dbusMapping{setTimePath, setTimeInterface, timeSetPro, |
| 216 | "uint64_t"}; |
| 217 | pldm::utils::DBusHandler().setDbusProperty(dbusMapping, value); |
Xiaochao Ma | 60227a0 | 2019-12-04 09:00:12 +0800 | [diff] [blame] | 218 | } |
Patrick Williams | 5133058 | 2021-10-06 12:48:56 -0500 | [diff] [blame] | 219 | catch (const std::exception& e) |
Xiaochao Ma | 60227a0 | 2019-12-04 09:00:12 +0800 | [diff] [blame] | 220 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 221 | error( |
| 222 | "Error Setting time,PATH={SET_TIME_PATH} TIME INTERFACE={TIME_INTERFACE} ERROR={ERR_EXCEP}", |
| 223 | "SET_TIME_PATH", setTimePath, "TIME_INTERFACE", setTimeInterface, |
| 224 | "ERR_EXCEP", e.what()); |
Xiaochao Ma | 60227a0 | 2019-12-04 09:00:12 +0800 | [diff] [blame] | 225 | return ccOnlyResponse(request, PLDM_ERROR); |
| 226 | } |
| 227 | |
| 228 | return ccOnlyResponse(request, PLDM_SUCCESS); |
| 229 | } |
| 230 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 231 | Response Handler::getBIOSTable(const pldm_msg* request, size_t payloadLength) |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 232 | { |
John Wang | 6080aae | 2020-02-14 09:34:25 +0800 | [diff] [blame] | 233 | uint32_t transferHandle{}; |
| 234 | uint8_t transferOpFlag{}; |
| 235 | uint8_t tableType{}; |
| 236 | |
| 237 | auto rc = decode_get_bios_table_req(request, payloadLength, &transferHandle, |
| 238 | &transferOpFlag, &tableType); |
| 239 | if (rc != PLDM_SUCCESS) |
| 240 | { |
| 241 | return ccOnlyResponse(request, rc); |
| 242 | } |
| 243 | |
| 244 | auto table = |
| 245 | biosConfig.getBIOSTable(static_cast<pldm_bios_table_types>(tableType)); |
| 246 | if (!table) |
| 247 | { |
| 248 | return ccOnlyResponse(request, PLDM_BIOS_TABLE_UNAVAILABLE); |
| 249 | } |
| 250 | |
| 251 | Response response(sizeof(pldm_msg_hdr) + |
| 252 | PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES + table->size()); |
| 253 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
| 254 | |
| 255 | rc = encode_get_bios_table_resp( |
| 256 | request->hdr.instance_id, PLDM_SUCCESS, 0 /* nxtTransferHandle */, |
| 257 | PLDM_START_AND_END, table->data(), response.size(), responsePtr); |
| 258 | if (rc != PLDM_SUCCESS) |
| 259 | { |
| 260 | return ccOnlyResponse(request, rc); |
| 261 | } |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 262 | |
| 263 | return response; |
| 264 | } |
| 265 | |
George Liu | 1b180d8 | 2020-07-23 14:01:58 +0800 | [diff] [blame] | 266 | Response Handler::setBIOSTable(const pldm_msg* request, size_t payloadLength) |
| 267 | { |
| 268 | uint32_t transferHandle{}; |
| 269 | uint8_t transferOpFlag{}; |
| 270 | uint8_t tableType{}; |
| 271 | struct variable_field field; |
| 272 | |
| 273 | auto rc = decode_set_bios_table_req(request, payloadLength, &transferHandle, |
| 274 | &transferOpFlag, &tableType, &field); |
| 275 | if (rc != PLDM_SUCCESS) |
| 276 | { |
| 277 | return ccOnlyResponse(request, rc); |
| 278 | } |
| 279 | |
| 280 | Table table(field.ptr, field.ptr + field.length); |
| 281 | rc = biosConfig.setBIOSTable(tableType, table); |
| 282 | if (rc != PLDM_SUCCESS) |
| 283 | { |
| 284 | return ccOnlyResponse(request, rc); |
| 285 | } |
| 286 | |
| 287 | Response response(sizeof(pldm_msg_hdr) + PLDM_SET_BIOS_TABLE_RESP_BYTES); |
| 288 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
| 289 | |
| 290 | rc = encode_set_bios_table_resp(request->hdr.instance_id, PLDM_SUCCESS, |
| 291 | 0 /* nxtTransferHandle */, responsePtr); |
| 292 | if (rc != PLDM_SUCCESS) |
| 293 | { |
| 294 | return ccOnlyResponse(request, rc); |
| 295 | } |
| 296 | |
| 297 | return response; |
| 298 | } |
| 299 | |
John Wang | 8721ed6 | 2019-12-05 14:44:43 +0800 | [diff] [blame] | 300 | Response Handler::getBIOSAttributeCurrentValueByHandle(const pldm_msg* request, |
| 301 | size_t payloadLength) |
| 302 | { |
| 303 | uint32_t transferHandle; |
| 304 | uint8_t transferOpFlag; |
| 305 | uint16_t attributeHandle; |
| 306 | |
| 307 | auto rc = decode_get_bios_attribute_current_value_by_handle_req( |
| 308 | request, payloadLength, &transferHandle, &transferOpFlag, |
| 309 | &attributeHandle); |
| 310 | if (rc != PLDM_SUCCESS) |
| 311 | { |
| 312 | return ccOnlyResponse(request, rc); |
| 313 | } |
| 314 | |
John Wang | 6080aae | 2020-02-14 09:34:25 +0800 | [diff] [blame] | 315 | auto table = biosConfig.getBIOSTable(PLDM_BIOS_ATTR_VAL_TABLE); |
| 316 | if (!table) |
Deepak Kodihalli | 4976a68 | 2020-01-07 05:48:29 -0600 | [diff] [blame] | 317 | { |
| 318 | return ccOnlyResponse(request, PLDM_BIOS_TABLE_UNAVAILABLE); |
| 319 | } |
| 320 | |
John Wang | 8721ed6 | 2019-12-05 14:44:43 +0800 | [diff] [blame] | 321 | auto entry = pldm_bios_table_attr_value_find_by_handle( |
John Wang | 6080aae | 2020-02-14 09:34:25 +0800 | [diff] [blame] | 322 | table->data(), table->size(), attributeHandle); |
John Wang | 8721ed6 | 2019-12-05 14:44:43 +0800 | [diff] [blame] | 323 | if (entry == nullptr) |
| 324 | { |
| 325 | return ccOnlyResponse(request, PLDM_INVALID_BIOS_ATTR_HANDLE); |
| 326 | } |
| 327 | |
John Wang | 8e877e0 | 2020-02-03 16:06:55 +0800 | [diff] [blame] | 328 | auto entryLength = pldm_bios_table_attr_value_entry_length(entry); |
John Wang | 8721ed6 | 2019-12-05 14:44:43 +0800 | [diff] [blame] | 329 | Response response(sizeof(pldm_msg_hdr) + |
| 330 | PLDM_GET_BIOS_ATTR_CURR_VAL_BY_HANDLE_MIN_RESP_BYTES + |
John Wang | 8e877e0 | 2020-02-03 16:06:55 +0800 | [diff] [blame] | 331 | entryLength, |
John Wang | 8721ed6 | 2019-12-05 14:44:43 +0800 | [diff] [blame] | 332 | 0); |
| 333 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 334 | rc = encode_get_bios_current_value_by_handle_resp( |
John Wang | 8e877e0 | 2020-02-03 16:06:55 +0800 | [diff] [blame] | 335 | request->hdr.instance_id, PLDM_SUCCESS, 0, PLDM_START_AND_END, |
| 336 | reinterpret_cast<const uint8_t*>(entry), entryLength, responsePtr); |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 337 | if (rc != PLDM_SUCCESS) |
| 338 | { |
| 339 | return ccOnlyResponse(request, rc); |
| 340 | } |
John Wang | 8721ed6 | 2019-12-05 14:44:43 +0800 | [diff] [blame] | 341 | |
| 342 | return response; |
| 343 | } |
| 344 | |
John Wang | 4217488 | 2019-12-20 14:56:59 +0800 | [diff] [blame] | 345 | Response Handler::setBIOSAttributeCurrentValue(const pldm_msg* request, |
| 346 | size_t payloadLength) |
| 347 | { |
| 348 | uint32_t transferHandle; |
| 349 | uint8_t transferOpFlag; |
| 350 | variable_field attributeField; |
| 351 | |
| 352 | auto rc = decode_set_bios_attribute_current_value_req( |
| 353 | request, payloadLength, &transferHandle, &transferOpFlag, |
| 354 | &attributeField); |
| 355 | if (rc != PLDM_SUCCESS) |
| 356 | { |
| 357 | return ccOnlyResponse(request, rc); |
| 358 | } |
| 359 | |
Sagar Srinivas | cac0ebb | 2021-11-23 07:50:28 -0600 | [diff] [blame] | 360 | rc = biosConfig.setAttrValue(attributeField.ptr, attributeField.length, |
| 361 | false); |
John Wang | 4217488 | 2019-12-20 14:56:59 +0800 | [diff] [blame] | 362 | |
Xiaochao Ma | 7a0d072 | 2020-05-29 09:07:33 +0800 | [diff] [blame] | 363 | Response response( |
| 364 | sizeof(pldm_msg_hdr) + PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES, 0); |
| 365 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
| 366 | |
| 367 | encode_set_bios_attribute_current_value_resp(request->hdr.instance_id, rc, |
| 368 | 0, responsePtr); |
| 369 | |
| 370 | return response; |
John Wang | 4217488 | 2019-12-20 14:56:59 +0800 | [diff] [blame] | 371 | } |
| 372 | |
John Wang | f719f3b | 2020-01-17 08:46:22 +0800 | [diff] [blame] | 373 | } // namespace bios |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 374 | } // namespace responder |
| 375 | } // namespace pldm |