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