Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 1 | #include "platform.hpp" |
| 2 | |
Tom Joseph | b70a196 | 2020-07-13 12:56:31 +0530 | [diff] [blame] | 3 | #include "common/types.hpp" |
Deepak Kodihalli | d130e1a | 2020-06-17 05:55:32 -0500 | [diff] [blame] | 4 | #include "common/utils.hpp" |
Tom Joseph | c4959c3 | 2020-04-20 19:50:16 +0530 | [diff] [blame] | 5 | #include "event_parser.hpp" |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 6 | #include "pdr.hpp" |
George Liu | 456c9a2 | 2020-01-13 11:36:22 +0800 | [diff] [blame] | 7 | #include "pdr_numeric_effecter.hpp" |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 8 | #include "pdr_state_effecter.hpp" |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 9 | #include "pdr_state_sensor.hpp" |
George Liu | 362c18d | 2020-05-14 09:46:36 +0800 | [diff] [blame] | 10 | #include "pdr_utils.hpp" |
George Liu | eccb0c5 | 2020-01-14 11:09:56 +0800 | [diff] [blame] | 11 | #include "platform_numeric_effecter.hpp" |
George Liu | 0d7aca8 | 2020-03-30 15:01:36 +0800 | [diff] [blame] | 12 | #include "platform_state_effecter.hpp" |
George Liu | 362c18d | 2020-05-14 09:46:36 +0800 | [diff] [blame] | 13 | #include "platform_state_sensor.hpp" |
Sagar Srinivas | 90314a3 | 2023-10-17 10:38:03 -0500 | [diff] [blame] | 14 | #include "pldmd/dbus_impl_requester.hpp" |
| 15 | #include "pldmd/handler.hpp" |
| 16 | #include "requester/handler.hpp" |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 17 | |
George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 18 | #include <libpldm/entity.h> |
| 19 | #include <libpldm/state_set.h> |
Manojkiran Eda | cc5f158 | 2021-09-29 17:03:06 +0530 | [diff] [blame] | 20 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 21 | #include <phosphor-logging/lg2.hpp> |
| 22 | |
| 23 | PHOSPHOR_LOG2_USING; |
| 24 | |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 25 | using namespace pldm::utils; |
| 26 | using namespace pldm::responder::pdr; |
| 27 | using namespace pldm::responder::pdr_utils; |
| 28 | |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 29 | namespace pldm |
| 30 | { |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 31 | namespace responder |
| 32 | { |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 33 | namespace platform |
| 34 | { |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 35 | using InternalFailure = |
| 36 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
| 37 | |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 38 | static const Json empty{}; |
| 39 | |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 40 | void Handler::addDbusObjMaps( |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 41 | uint16_t id, |
| 42 | std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> dbusObj, |
| 43 | TypeId typeId) |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 44 | { |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 45 | if (typeId == TypeId::PLDM_SENSOR_ID) |
| 46 | { |
| 47 | sensorDbusObjMaps.emplace(id, dbusObj); |
| 48 | } |
| 49 | else |
| 50 | { |
| 51 | effecterDbusObjMaps.emplace(id, dbusObj); |
| 52 | } |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 53 | } |
| 54 | |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 55 | const std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>& |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 56 | Handler::getDbusObjMaps(uint16_t id, TypeId typeId) const |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 57 | { |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 58 | if (typeId == TypeId::PLDM_SENSOR_ID) |
| 59 | { |
| 60 | return sensorDbusObjMaps.at(id); |
| 61 | } |
| 62 | else |
| 63 | { |
| 64 | return effecterDbusObjMaps.at(id); |
| 65 | } |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 66 | } |
| 67 | |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 68 | void Handler::generate(const pldm::utils::DBusHandler& dBusIntf, |
Kamalkumar Patel | 3c50c82 | 2024-01-30 07:14:40 -0600 | [diff] [blame] | 69 | const std::vector<fs::path>& dir, Repo& repo) |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 70 | { |
Kamalkumar Patel | 3c50c82 | 2024-01-30 07:14:40 -0600 | [diff] [blame] | 71 | for (const auto& directory : dir) |
Deepak Kodihalli | c6e49c4 | 2020-07-01 03:39:27 -0500 | [diff] [blame] | 72 | { |
Kamalkumar Patel | 3c50c82 | 2024-01-30 07:14:40 -0600 | [diff] [blame] | 73 | info("checking if : {DIR} exists", "DIR", directory); |
| 74 | if (!fs::exists(directory)) |
| 75 | { |
| 76 | return; |
| 77 | } |
Deepak Kodihalli | c6e49c4 | 2020-07-01 03:39:27 -0500 | [diff] [blame] | 78 | } |
| 79 | |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 80 | // A map of PDR type to a lambda that handles creation of that PDR type. |
| 81 | // The lambda essentially would parse the platform specific PDR JSONs to |
| 82 | // generate the PDR structures. This function iterates through the map to |
| 83 | // invoke all lambdas, so that all PDR types can be created. |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 84 | |
Patrick Williams | a675662 | 2023-10-20 11:19:15 -0500 | [diff] [blame] | 85 | const std::map<Type, generatePDR> generateHandlers = { |
| 86 | {PLDM_STATE_EFFECTER_PDR, |
| 87 | [this](const DBusHandler& dBusIntf, const auto& json, |
| 88 | RepoInterface& repo) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 89 | pdr_state_effecter::generateStateEffecterPDR<pldm::utils::DBusHandler, |
| 90 | Handler>(dBusIntf, json, |
| 91 | *this, repo); |
Patrick Williams | a675662 | 2023-10-20 11:19:15 -0500 | [diff] [blame] | 92 | }}, |
| 93 | {PLDM_NUMERIC_EFFECTER_PDR, |
| 94 | [this](const DBusHandler& dBusIntf, const auto& json, |
| 95 | RepoInterface& repo) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 96 | pdr_numeric_effecter::generateNumericEffecterPDR< |
| 97 | pldm::utils::DBusHandler, Handler>(dBusIntf, json, *this, repo); |
Patrick Williams | a675662 | 2023-10-20 11:19:15 -0500 | [diff] [blame] | 98 | }}, |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 99 | {PLDM_STATE_SENSOR_PDR, [this](const DBusHandler& dBusIntf, |
| 100 | const auto& json, RepoInterface& repo) { |
Patrick Williams | a675662 | 2023-10-20 11:19:15 -0500 | [diff] [blame] | 101 | pdr_state_sensor::generateStateSensorPDR<pldm::utils::DBusHandler, |
| 102 | Handler>(dBusIntf, json, *this, |
| 103 | repo); |
| 104 | }}}; |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 105 | |
| 106 | Type pdrType{}; |
Kamalkumar Patel | 3c50c82 | 2024-01-30 07:14:40 -0600 | [diff] [blame] | 107 | for (const auto& directory : dir) |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 108 | { |
Kamalkumar Patel | 3c50c82 | 2024-01-30 07:14:40 -0600 | [diff] [blame] | 109 | for (const auto& dirEntry : fs::directory_iterator(directory)) |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 110 | { |
Kamalkumar Patel | 3c50c82 | 2024-01-30 07:14:40 -0600 | [diff] [blame] | 111 | try |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 112 | { |
Kamalkumar Patel | 3c50c82 | 2024-01-30 07:14:40 -0600 | [diff] [blame] | 113 | if (fs::is_regular_file(dirEntry.path().string())) |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 114 | { |
Kamalkumar Patel | 3c50c82 | 2024-01-30 07:14:40 -0600 | [diff] [blame] | 115 | auto json = readJson(dirEntry.path().string()); |
| 116 | if (!json.empty()) |
| 117 | { |
| 118 | auto effecterPDRs = json.value("effecterPDRs", empty); |
| 119 | for (const auto& effecter : effecterPDRs) |
| 120 | { |
| 121 | pdrType = effecter.value("pdrType", 0); |
| 122 | generateHandlers.at(pdrType)(dBusIntf, effecter, |
| 123 | repo); |
| 124 | } |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 125 | |
Kamalkumar Patel | 3c50c82 | 2024-01-30 07:14:40 -0600 | [diff] [blame] | 126 | auto sensorPDRs = json.value("sensorPDRs", empty); |
| 127 | for (const auto& sensor : sensorPDRs) |
| 128 | { |
| 129 | pdrType = sensor.value("pdrType", 0); |
| 130 | generateHandlers.at(pdrType)(dBusIntf, sensor, |
| 131 | repo); |
| 132 | } |
| 133 | } |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 134 | } |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 135 | } |
Kamalkumar Patel | 3c50c82 | 2024-01-30 07:14:40 -0600 | [diff] [blame] | 136 | catch (const InternalFailure& e) |
| 137 | { |
| 138 | error( |
| 139 | "PDR config directory '{PATH}' does not exist or empty for '{TYPE}' pdr: {ERROR}", |
| 140 | "TYPE", pdrType, "PATH", dirEntry.path(), "ERROR", e); |
| 141 | } |
| 142 | catch (const Json::exception& e) |
| 143 | { |
| 144 | error("Failed parsing PDR JSON file for '{TYPE}' pdr: {ERROR}", |
| 145 | "TYPE", pdrType, "ERROR", e); |
| 146 | pldm::utils::reportError( |
| 147 | "xyz.openbmc_project.PLDM.Error.Generate.PDRJsonFileParseFail"); |
| 148 | } |
| 149 | catch (const std::exception& e) |
| 150 | { |
| 151 | error("Failed parsing PDR JSON file for '{TYPE}' pdr: {ERROR}", |
| 152 | "TYPE", pdrType, "ERROR", e); |
| 153 | pldm::utils::reportError( |
| 154 | "xyz.openbmc_project.PLDM.Error.Generate.PDRJsonFileParseFail"); |
| 155 | } |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 156 | } |
| 157 | } |
| 158 | } |
Manojkiran Eda | 92fb0b5 | 2024-04-17 10:48:17 +0530 | [diff] [blame] | 159 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 160 | Response Handler::getPDR(const pldm_msg* request, size_t payloadLength) |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 161 | { |
Pavithra Barithaya | 99854a7 | 2021-09-29 06:58:11 -0500 | [diff] [blame] | 162 | if (hostPDRHandler) |
| 163 | { |
| 164 | if (hostPDRHandler->isHostUp() && oemPlatformHandler != nullptr) |
| 165 | { |
| 166 | auto rc = oemPlatformHandler->checkBMCState(); |
| 167 | if (rc != PLDM_SUCCESS) |
| 168 | { |
| 169 | return ccOnlyResponse(request, PLDM_ERROR_NOT_READY); |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | // Build FRU table if not built, since entity association PDR's |
| 175 | // are built when the FRU table is constructed. |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 176 | if (fruHandler) |
| 177 | { |
| 178 | fruHandler->buildFRUTable(); |
| 179 | } |
| 180 | |
George Liu | d680ae0 | 2020-07-17 09:11:14 +0800 | [diff] [blame] | 181 | if (!pdrCreated) |
| 182 | { |
| 183 | generateTerminusLocatorPDR(pdrRepo); |
Kamalkumar Patel | 3c50c82 | 2024-01-30 07:14:40 -0600 | [diff] [blame] | 184 | if (platformConfigHandler) |
| 185 | { |
| 186 | auto systemType = platformConfigHandler->getPlatformName(); |
| 187 | if (systemType.has_value()) |
| 188 | { |
| 189 | // In case of normal poweron , the system type would have been |
| 190 | // already filled by entity manager when ever BMC reaches Ready |
| 191 | // state. If this is not filled by time we get a getpdr request |
| 192 | // we can assume that the entity manager service is not present |
| 193 | // on this system & continue to build the common PDR's. |
| 194 | pdrJsonsDir.push_back(pdrJsonDir / systemType.value()); |
| 195 | } |
| 196 | } |
| 197 | |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 198 | if (oemPlatformHandler != nullptr) |
| 199 | { |
| 200 | oemPlatformHandler->buildOEMPDR(pdrRepo); |
| 201 | } |
Kamalkumar Patel | 3c50c82 | 2024-01-30 07:14:40 -0600 | [diff] [blame] | 202 | generate(*dBusIntf, pdrJsonsDir, pdrRepo); |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 203 | |
George Liu | d680ae0 | 2020-07-17 09:11:14 +0800 | [diff] [blame] | 204 | pdrCreated = true; |
George Liu | 5eed8e5 | 2020-12-18 11:24:37 +0800 | [diff] [blame] | 205 | |
| 206 | if (dbusToPLDMEventHandler) |
| 207 | { |
Sampa Misra | 5fb37d5 | 2021-03-06 07:26:00 -0600 | [diff] [blame] | 208 | deferredGetPDREvent = std::make_unique<sdeventplus::source::Defer>( |
| 209 | event, |
| 210 | std::bind(std::mem_fn(&pldm::responder::platform::Handler:: |
| 211 | _processPostGetPDRActions), |
| 212 | this, std::placeholders::_1)); |
George Liu | 5eed8e5 | 2020-12-18 11:24:37 +0800 | [diff] [blame] | 213 | } |
George Liu | d680ae0 | 2020-07-17 09:11:14 +0800 | [diff] [blame] | 214 | } |
| 215 | |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 216 | Response response(sizeof(pldm_msg_hdr) + PLDM_GET_PDR_MIN_RESP_BYTES, 0); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 217 | |
| 218 | if (payloadLength != PLDM_GET_PDR_REQ_BYTES) |
| 219 | { |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 220 | return CmdHandler::ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | uint32_t recordHandle{}; |
| 224 | uint32_t dataTransferHandle{}; |
| 225 | uint8_t transferOpFlag{}; |
| 226 | uint16_t reqSizeBytes{}; |
| 227 | uint16_t recordChangeNum{}; |
| 228 | |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 229 | auto rc = decode_get_pdr_req(request, payloadLength, &recordHandle, |
| 230 | &dataTransferHandle, &transferOpFlag, |
| 231 | &reqSizeBytes, &recordChangeNum); |
| 232 | if (rc != PLDM_SUCCESS) |
| 233 | { |
| 234 | return CmdHandler::ccOnlyResponse(request, rc); |
| 235 | } |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 236 | |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 237 | uint16_t respSizeBytes{}; |
| 238 | uint8_t* recordData = nullptr; |
| 239 | try |
| 240 | { |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 241 | pdr_utils::PdrEntry e; |
| 242 | auto record = pdr::getRecordByHandle(pdrRepo, recordHandle, e); |
| 243 | if (record == NULL) |
| 244 | { |
| 245 | return CmdHandler::ccOnlyResponse( |
| 246 | request, PLDM_PLATFORM_INVALID_RECORD_HANDLE); |
| 247 | } |
| 248 | |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 249 | if (reqSizeBytes) |
| 250 | { |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 251 | respSizeBytes = e.size; |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 252 | if (respSizeBytes > reqSizeBytes) |
| 253 | { |
| 254 | respSizeBytes = reqSizeBytes; |
| 255 | } |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 256 | recordData = e.data; |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 257 | } |
| 258 | response.resize(sizeof(pldm_msg_hdr) + PLDM_GET_PDR_MIN_RESP_BYTES + |
| 259 | respSizeBytes, |
| 260 | 0); |
Manojkiran Eda | 31a7844 | 2021-09-12 15:18:25 +0530 | [diff] [blame] | 261 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
Deepak Kodihalli | 22b5a7d | 2020-03-17 23:28:41 -0500 | [diff] [blame] | 262 | rc = encode_get_pdr_resp( |
| 263 | request->hdr.instance_id, PLDM_SUCCESS, e.handle.nextRecordHandle, |
| 264 | 0, PLDM_START_AND_END, respSizeBytes, recordData, 0, responsePtr); |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 265 | if (rc != PLDM_SUCCESS) |
| 266 | { |
| 267 | return ccOnlyResponse(request, rc); |
| 268 | } |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 269 | } |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 270 | catch (const std::exception& e) |
| 271 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 272 | error("Error accessing PDR, HANDLE={REC_HANDLE} ERROR={ERR_EXCEP}", |
| 273 | "REC_HANDLE", recordHandle, "ERR_EXCEP", e.what()); |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 274 | return CmdHandler::ccOnlyResponse(request, PLDM_ERROR); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 275 | } |
| 276 | return response; |
| 277 | } |
| 278 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 279 | Response Handler::setStateEffecterStates(const pldm_msg* request, |
| 280 | size_t payloadLength) |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 281 | { |
| 282 | Response response( |
| 283 | sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES, 0); |
| 284 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
| 285 | uint16_t effecterId; |
| 286 | uint8_t compEffecterCnt; |
| 287 | constexpr auto maxCompositeEffecterCnt = 8; |
| 288 | std::vector<set_effecter_state_field> stateField(maxCompositeEffecterCnt, |
| 289 | {0, 0}); |
| 290 | |
| 291 | if ((payloadLength > PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES) || |
| 292 | (payloadLength < sizeof(effecterId) + sizeof(compEffecterCnt) + |
| 293 | sizeof(set_effecter_state_field))) |
| 294 | { |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 295 | return CmdHandler::ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | int rc = decode_set_state_effecter_states_req(request, payloadLength, |
| 299 | &effecterId, &compEffecterCnt, |
| 300 | stateField.data()); |
| 301 | |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 302 | if (rc != PLDM_SUCCESS) |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 303 | { |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 304 | return CmdHandler::ccOnlyResponse(request, rc); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 305 | } |
| 306 | |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 307 | stateField.resize(compEffecterCnt); |
| 308 | const pldm::utils::DBusHandler dBusIntf; |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 309 | uint16_t entityType{}; |
| 310 | uint16_t entityInstance{}; |
| 311 | uint16_t stateSetId{}; |
| 312 | |
| 313 | if (isOemStateEffecter(*this, effecterId, compEffecterCnt, entityType, |
| 314 | entityInstance, stateSetId) && |
Manojkiran Eda | 321804e | 2022-03-03 12:36:54 +0530 | [diff] [blame] | 315 | oemPlatformHandler != nullptr && |
| 316 | !effecterDbusObjMaps.contains(effecterId)) |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 317 | { |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 318 | rc = oemPlatformHandler->oemSetStateEffecterStatesHandler( |
Varsha Kaverappa | 3fbd39e | 2020-09-28 01:40:22 -0500 | [diff] [blame] | 319 | entityType, entityInstance, stateSetId, compEffecterCnt, stateField, |
| 320 | effecterId); |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 321 | } |
| 322 | else |
| 323 | { |
| 324 | rc = platform_state_effecter::setStateEffecterStatesHandler< |
| 325 | pldm::utils::DBusHandler, Handler>(dBusIntf, *this, effecterId, |
| 326 | stateField); |
| 327 | } |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 328 | if (rc != PLDM_SUCCESS) |
| 329 | { |
| 330 | return CmdHandler::ccOnlyResponse(request, rc); |
| 331 | } |
| 332 | |
| 333 | rc = encode_set_state_effecter_states_resp(request->hdr.instance_id, rc, |
| 334 | responsePtr); |
| 335 | if (rc != PLDM_SUCCESS) |
| 336 | { |
| 337 | return ccOnlyResponse(request, rc); |
| 338 | } |
| 339 | |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 340 | return response; |
| 341 | } |
| 342 | |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 343 | Response Handler::platformEventMessage(const pldm_msg* request, |
| 344 | size_t payloadLength) |
| 345 | { |
| 346 | uint8_t formatVersion{}; |
| 347 | uint8_t tid{}; |
| 348 | uint8_t eventClass{}; |
| 349 | size_t offset{}; |
| 350 | |
| 351 | auto rc = decode_platform_event_message_req( |
| 352 | request, payloadLength, &formatVersion, &tid, &eventClass, &offset); |
| 353 | if (rc != PLDM_SUCCESS) |
| 354 | { |
| 355 | return CmdHandler::ccOnlyResponse(request, rc); |
| 356 | } |
| 357 | |
Sagar Srinivas | a6a8ccd | 2021-04-01 07:58:33 -0500 | [diff] [blame] | 358 | if (eventClass == PLDM_HEARTBEAT_TIMER_ELAPSED_EVENT) |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 359 | { |
Sagar Srinivas | a6a8ccd | 2021-04-01 07:58:33 -0500 | [diff] [blame] | 360 | rc = PLDM_SUCCESS; |
Sagar Srinivas | 79669c9 | 2021-04-28 15:43:30 -0500 | [diff] [blame] | 361 | if (oemPlatformHandler) |
| 362 | { |
Sagar Srinivas | 18145f7 | 2022-04-11 07:38:26 -0500 | [diff] [blame] | 363 | if (oemPlatformHandler->watchDogRunning()) |
| 364 | { |
| 365 | oemPlatformHandler->resetWatchDogTimer(); |
| 366 | } |
| 367 | else |
| 368 | { |
| 369 | oemPlatformHandler->setSurvTimer(tid, true); |
| 370 | } |
Sagar Srinivas | 79669c9 | 2021-04-28 15:43:30 -0500 | [diff] [blame] | 371 | } |
Sagar Srinivas | a6a8ccd | 2021-04-01 07:58:33 -0500 | [diff] [blame] | 372 | } |
| 373 | else |
| 374 | { |
| 375 | try |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 376 | { |
Sagar Srinivas | a6a8ccd | 2021-04-01 07:58:33 -0500 | [diff] [blame] | 377 | const auto& handlers = eventHandlers.at(eventClass); |
| 378 | for (const auto& handler : handlers) |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 379 | { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 380 | auto rc = handler(request, payloadLength, formatVersion, tid, |
| 381 | offset); |
Sagar Srinivas | a6a8ccd | 2021-04-01 07:58:33 -0500 | [diff] [blame] | 382 | if (rc != PLDM_SUCCESS) |
| 383 | { |
| 384 | return CmdHandler::ccOnlyResponse(request, rc); |
| 385 | } |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 386 | } |
| 387 | } |
Sagar Srinivas | a6a8ccd | 2021-04-01 07:58:33 -0500 | [diff] [blame] | 388 | catch (const std::out_of_range& e) |
| 389 | { |
Kamalkumar Patel | 58cbcaf | 2023-10-06 03:48:25 -0500 | [diff] [blame] | 390 | error("Error in handling platform event msg: {ERROR}", "ERROR", e); |
Sagar Srinivas | a6a8ccd | 2021-04-01 07:58:33 -0500 | [diff] [blame] | 391 | return CmdHandler::ccOnlyResponse(request, PLDM_ERROR_INVALID_DATA); |
| 392 | } |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 393 | } |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 394 | Response response( |
| 395 | sizeof(pldm_msg_hdr) + PLDM_PLATFORM_EVENT_MESSAGE_RESP_BYTES, 0); |
| 396 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
| 397 | |
| 398 | rc = encode_platform_event_message_resp(request->hdr.instance_id, rc, |
| 399 | PLDM_EVENT_NO_LOGGING, responsePtr); |
| 400 | if (rc != PLDM_SUCCESS) |
| 401 | { |
| 402 | return ccOnlyResponse(request, rc); |
| 403 | } |
| 404 | |
| 405 | return response; |
| 406 | } |
| 407 | |
| 408 | int Handler::sensorEvent(const pldm_msg* request, size_t payloadLength, |
Tom Joseph | c4959c3 | 2020-04-20 19:50:16 +0530 | [diff] [blame] | 409 | uint8_t /*formatVersion*/, uint8_t tid, |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 410 | size_t eventDataOffset) |
| 411 | { |
| 412 | uint16_t sensorId{}; |
| 413 | uint8_t eventClass{}; |
| 414 | size_t eventClassDataOffset{}; |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 415 | auto eventData = reinterpret_cast<const uint8_t*>(request->payload) + |
| 416 | eventDataOffset; |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 417 | auto eventDataSize = payloadLength - eventDataOffset; |
| 418 | |
| 419 | auto rc = decode_sensor_event_data(eventData, eventDataSize, &sensorId, |
| 420 | &eventClass, &eventClassDataOffset); |
| 421 | if (rc != PLDM_SUCCESS) |
| 422 | { |
| 423 | return rc; |
| 424 | } |
| 425 | |
Zahed Hossain | 75330f3 | 2020-03-24 02:15:03 -0500 | [diff] [blame] | 426 | auto eventClassData = reinterpret_cast<const uint8_t*>(request->payload) + |
| 427 | eventDataOffset + eventClassDataOffset; |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 428 | auto eventClassDataSize = payloadLength - eventDataOffset - |
| 429 | eventClassDataOffset; |
Zahed Hossain | 75330f3 | 2020-03-24 02:15:03 -0500 | [diff] [blame] | 430 | |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 431 | if (eventClass == PLDM_STATE_SENSOR_STATE) |
| 432 | { |
| 433 | uint8_t sensorOffset{}; |
| 434 | uint8_t eventState{}; |
| 435 | uint8_t previousEventState{}; |
| 436 | |
Zahed Hossain | 75330f3 | 2020-03-24 02:15:03 -0500 | [diff] [blame] | 437 | rc = decode_state_sensor_data(eventClassData, eventClassDataSize, |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 438 | &sensorOffset, &eventState, |
| 439 | &previousEventState); |
Zahed Hossain | 75330f3 | 2020-03-24 02:15:03 -0500 | [diff] [blame] | 440 | if (rc != PLDM_SUCCESS) |
| 441 | { |
| 442 | return PLDM_ERROR; |
| 443 | } |
| 444 | |
Chicago Duan | fe4d88b | 2020-06-12 16:44:13 +0800 | [diff] [blame] | 445 | // Emitting state sensor event signal |
| 446 | emitStateSensorEventSignal(tid, sensorId, sensorOffset, eventState, |
| 447 | previousEventState); |
| 448 | |
Tom Joseph | c4959c3 | 2020-04-20 19:50:16 +0530 | [diff] [blame] | 449 | // If there are no HOST PDR's, there is no further action |
| 450 | if (hostPDRHandler == NULL) |
| 451 | { |
| 452 | return PLDM_SUCCESS; |
| 453 | } |
| 454 | |
| 455 | // Handle PLDM events for which PDR is available |
| 456 | SensorEntry sensorEntry{tid, sensorId}; |
Tom Joseph | b70a196 | 2020-07-13 12:56:31 +0530 | [diff] [blame] | 457 | |
| 458 | pldm::pdr::EntityInfo entityInfo{}; |
| 459 | pldm::pdr::CompositeSensorStates compositeSensorStates{}; |
Sagar Srinivas | e3607a3 | 2024-02-16 03:50:53 -0600 | [diff] [blame] | 460 | std::vector<pldm::pdr::StateSetId> stateSetIds{}; |
Tom Joseph | b70a196 | 2020-07-13 12:56:31 +0530 | [diff] [blame] | 461 | |
Tom Joseph | c4959c3 | 2020-04-20 19:50:16 +0530 | [diff] [blame] | 462 | try |
| 463 | { |
Sagar Srinivas | e3607a3 | 2024-02-16 03:50:53 -0600 | [diff] [blame] | 464 | std::tie(entityInfo, compositeSensorStates, stateSetIds) = |
Tom Joseph | c4959c3 | 2020-04-20 19:50:16 +0530 | [diff] [blame] | 465 | hostPDRHandler->lookupSensorInfo(sensorEntry); |
Tom Joseph | c4959c3 | 2020-04-20 19:50:16 +0530 | [diff] [blame] | 466 | } |
Kamalkumar Patel | 58cbcaf | 2023-10-06 03:48:25 -0500 | [diff] [blame] | 467 | catch (const std::out_of_range&) |
Tom Joseph | c4959c3 | 2020-04-20 19:50:16 +0530 | [diff] [blame] | 468 | { |
Tom Joseph | b70a196 | 2020-07-13 12:56:31 +0530 | [diff] [blame] | 469 | // If there is no mapping for tid, sensorId combination, try |
| 470 | // PLDM_TID_RESERVED, sensorId for terminus that is yet to |
| 471 | // implement TL PDR. |
| 472 | try |
| 473 | { |
| 474 | sensorEntry.terminusID = PLDM_TID_RESERVED; |
Sagar Srinivas | e3607a3 | 2024-02-16 03:50:53 -0600 | [diff] [blame] | 475 | std::tie(entityInfo, compositeSensorStates, stateSetIds) = |
Tom Joseph | b70a196 | 2020-07-13 12:56:31 +0530 | [diff] [blame] | 476 | hostPDRHandler->lookupSensorInfo(sensorEntry); |
| 477 | } |
| 478 | // If there is no mapping for events return PLDM_SUCCESS |
Kamalkumar Patel | 58cbcaf | 2023-10-06 03:48:25 -0500 | [diff] [blame] | 479 | catch (const std::out_of_range&) |
Tom Joseph | b70a196 | 2020-07-13 12:56:31 +0530 | [diff] [blame] | 480 | { |
| 481 | return PLDM_SUCCESS; |
| 482 | } |
Zahed Hossain | 75330f3 | 2020-03-24 02:15:03 -0500 | [diff] [blame] | 483 | } |
Tom Joseph | b70a196 | 2020-07-13 12:56:31 +0530 | [diff] [blame] | 484 | |
| 485 | if (sensorOffset >= compositeSensorStates.size()) |
| 486 | { |
| 487 | return PLDM_ERROR_INVALID_DATA; |
| 488 | } |
| 489 | |
| 490 | const auto& possibleStates = compositeSensorStates[sensorOffset]; |
Sagar Srinivas | 06f9b29 | 2024-03-31 11:35:28 -0500 | [diff] [blame] | 491 | if (!possibleStates.contains(eventState)) |
Tom Joseph | b70a196 | 2020-07-13 12:56:31 +0530 | [diff] [blame] | 492 | { |
| 493 | return PLDM_ERROR_INVALID_DATA; |
| 494 | } |
| 495 | |
| 496 | const auto& [containerId, entityType, entityInstance] = entityInfo; |
| 497 | events::StateSensorEntry stateSensorEntry{containerId, entityType, |
Sagar Srinivas | e3607a3 | 2024-02-16 03:50:53 -0600 | [diff] [blame] | 498 | entityInstance, sensorOffset, |
| 499 | stateSetIds[sensorOffset]}; |
Pavithra Barithaya | 3aec997 | 2020-12-14 01:55:44 -0600 | [diff] [blame] | 500 | return hostPDRHandler->handleStateSensorEvent(stateSensorEntry, |
| 501 | eventState); |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 502 | } |
| 503 | else |
| 504 | { |
| 505 | return PLDM_ERROR_INVALID_DATA; |
| 506 | } |
| 507 | |
| 508 | return PLDM_SUCCESS; |
| 509 | } |
| 510 | |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 511 | int Handler::pldmPDRRepositoryChgEvent(const pldm_msg* request, |
| 512 | size_t payloadLength, |
Manojkiran Eda | 3ca4045 | 2021-10-04 22:51:37 +0530 | [diff] [blame] | 513 | uint8_t /*formatVersion*/, uint8_t tid, |
| 514 | size_t eventDataOffset) |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 515 | { |
| 516 | uint8_t eventDataFormat{}; |
| 517 | uint8_t numberOfChangeRecords{}; |
| 518 | size_t dataOffset{}; |
| 519 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 520 | auto eventData = reinterpret_cast<const uint8_t*>(request->payload) + |
| 521 | eventDataOffset; |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 522 | auto eventDataSize = payloadLength - eventDataOffset; |
| 523 | |
| 524 | auto rc = decode_pldm_pdr_repository_chg_event_data( |
| 525 | eventData, eventDataSize, &eventDataFormat, &numberOfChangeRecords, |
| 526 | &dataOffset); |
| 527 | if (rc != PLDM_SUCCESS) |
| 528 | { |
| 529 | return rc; |
| 530 | } |
| 531 | |
| 532 | PDRRecordHandles pdrRecordHandles; |
Deepak Kodihalli | 7246e0c | 2020-07-08 06:40:18 -0500 | [diff] [blame] | 533 | |
| 534 | if (eventDataFormat == FORMAT_IS_PDR_TYPES) |
| 535 | { |
| 536 | return PLDM_ERROR_INVALID_DATA; |
| 537 | } |
| 538 | |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 539 | if (eventDataFormat == FORMAT_IS_PDR_HANDLES) |
| 540 | { |
| 541 | uint8_t eventDataOperation{}; |
| 542 | uint8_t numberOfChangeEntries{}; |
| 543 | |
| 544 | auto changeRecordData = eventData + dataOffset; |
| 545 | auto changeRecordDataSize = eventDataSize - dataOffset; |
| 546 | |
| 547 | while (changeRecordDataSize) |
| 548 | { |
| 549 | rc = decode_pldm_pdr_repository_change_record_data( |
| 550 | changeRecordData, changeRecordDataSize, &eventDataOperation, |
| 551 | &numberOfChangeEntries, &dataOffset); |
| 552 | |
| 553 | if (rc != PLDM_SUCCESS) |
| 554 | { |
| 555 | return rc; |
| 556 | } |
| 557 | |
Pavithra Barithaya | ae5c97e | 2022-08-29 02:57:59 -0500 | [diff] [blame] | 558 | if (eventDataOperation == PLDM_RECORDS_ADDED || |
| 559 | eventDataOperation == PLDM_RECORDS_MODIFIED) |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 560 | { |
Pavithra Barithaya | ae5c97e | 2022-08-29 02:57:59 -0500 | [diff] [blame] | 561 | if (eventDataOperation == PLDM_RECORDS_MODIFIED) |
| 562 | { |
| 563 | hostPDRHandler->isHostPdrModified = true; |
| 564 | } |
| 565 | |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 566 | rc = getPDRRecordHandles( |
| 567 | reinterpret_cast<const ChangeEntry*>(changeRecordData + |
| 568 | dataOffset), |
| 569 | changeRecordDataSize - dataOffset, |
| 570 | static_cast<size_t>(numberOfChangeEntries), |
| 571 | pdrRecordHandles); |
| 572 | |
| 573 | if (rc != PLDM_SUCCESS) |
| 574 | { |
| 575 | return rc; |
| 576 | } |
| 577 | } |
| 578 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 579 | changeRecordData += dataOffset + |
| 580 | (numberOfChangeEntries * sizeof(ChangeEntry)); |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 581 | changeRecordDataSize -= |
| 582 | dataOffset + (numberOfChangeEntries * sizeof(ChangeEntry)); |
| 583 | } |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 584 | } |
Deepak Kodihalli | 7246e0c | 2020-07-08 06:40:18 -0500 | [diff] [blame] | 585 | if (hostPDRHandler) |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 586 | { |
Manojkiran Eda | 3ca4045 | 2021-10-04 22:51:37 +0530 | [diff] [blame] | 587 | // if we get a Repository change event with the eventDataFormat |
| 588 | // as REFRESH_ENTIRE_REPOSITORY, then delete all the PDR's that |
| 589 | // have the matched Terminus handle |
| 590 | if (eventDataFormat == REFRESH_ENTIRE_REPOSITORY) |
| 591 | { |
| 592 | // We cannot get the Repo change event from the Terminus |
| 593 | // that is not already added to the BMC repository |
| 594 | |
Pavithra Barithaya | 52aad39 | 2022-08-02 04:18:52 -0500 | [diff] [blame] | 595 | for (auto it = hostPDRHandler->tlPDRInfo.cbegin(); |
| 596 | it != hostPDRHandler->tlPDRInfo.cend();) |
Manojkiran Eda | 3ca4045 | 2021-10-04 22:51:37 +0530 | [diff] [blame] | 597 | { |
Pavithra Barithaya | 52aad39 | 2022-08-02 04:18:52 -0500 | [diff] [blame] | 598 | if (std::get<0>(it->second) == tid) |
Manojkiran Eda | 3ca4045 | 2021-10-04 22:51:37 +0530 | [diff] [blame] | 599 | { |
| 600 | pldm_pdr_remove_pdrs_by_terminus_handle(pdrRepo.getPdr(), |
Pavithra Barithaya | 52aad39 | 2022-08-02 04:18:52 -0500 | [diff] [blame] | 601 | it->first); |
| 602 | hostPDRHandler->tlPDRInfo.erase(it++); |
| 603 | } |
| 604 | else |
| 605 | { |
| 606 | ++it; |
Manojkiran Eda | 3ca4045 | 2021-10-04 22:51:37 +0530 | [diff] [blame] | 607 | } |
| 608 | } |
| 609 | } |
Deepak Kodihalli | 7246e0c | 2020-07-08 06:40:18 -0500 | [diff] [blame] | 610 | hostPDRHandler->fetchPDR(std::move(pdrRecordHandles)); |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | return PLDM_SUCCESS; |
| 614 | } |
| 615 | |
| 616 | int Handler::getPDRRecordHandles(const ChangeEntry* changeEntryData, |
| 617 | size_t changeEntryDataSize, |
| 618 | size_t numberOfChangeEntries, |
| 619 | PDRRecordHandles& pdrRecordHandles) |
| 620 | { |
| 621 | if (numberOfChangeEntries > (changeEntryDataSize / sizeof(ChangeEntry))) |
| 622 | { |
| 623 | return PLDM_ERROR_INVALID_DATA; |
| 624 | } |
| 625 | for (size_t i = 0; i < numberOfChangeEntries; i++) |
| 626 | { |
| 627 | pdrRecordHandles.push_back(changeEntryData[i]); |
| 628 | } |
| 629 | return PLDM_SUCCESS; |
| 630 | } |
| 631 | |
Archana Kakani | 6ece21fb | 2023-10-10 08:21:52 -0500 | [diff] [blame] | 632 | Response Handler::getNumericEffecterValue(const pldm_msg* request, |
| 633 | size_t payloadLength) |
| 634 | { |
| 635 | if (payloadLength != PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES) |
| 636 | { |
| 637 | return ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH); |
| 638 | } |
| 639 | |
| 640 | uint16_t effecterId{}; |
| 641 | auto rc = decode_get_numeric_effecter_value_req(request, payloadLength, |
| 642 | &effecterId); |
| 643 | if (rc != PLDM_SUCCESS) |
| 644 | { |
| 645 | return ccOnlyResponse(request, rc); |
| 646 | } |
| 647 | |
| 648 | const pldm::utils::DBusHandler dBusIntf; |
| 649 | uint8_t effecterDataSize{}; |
| 650 | pldm::utils::PropertyValue dbusValue; |
| 651 | std::string propertyType; |
| 652 | using effecterOperationalState = uint8_t; |
| 653 | using completionCode = uint8_t; |
| 654 | |
| 655 | rc = platform_numeric_effecter::getNumericEffecterData< |
| 656 | pldm::utils::DBusHandler, Handler>( |
| 657 | dBusIntf, *this, effecterId, effecterDataSize, propertyType, dbusValue); |
| 658 | |
| 659 | if (rc != PLDM_SUCCESS) |
| 660 | { |
| 661 | return ccOnlyResponse(request, rc); |
| 662 | } |
| 663 | |
| 664 | // Refer DSP0248_1.2.0.pdf (section 22.3, Table 48) |
| 665 | // Completion Code (uint8), Effecter Data Size(uint8), Effecter Operational |
| 666 | // State(uint8), PendingValue (uint8|sint8|uint16|sint16|uint32|sint32 ) |
| 667 | // PresentValue (uint8|sint8|uint16|sint16|uint32|sint32 ) |
| 668 | // Size of PendingValue and PresentValue calculated based on size is |
| 669 | // provided in effecter data size |
| 670 | size_t responsePayloadLength = sizeof(completionCode) + |
| 671 | sizeof(effecterDataSize) + |
| 672 | sizeof(effecterOperationalState) + |
| 673 | getEffecterDataSize(effecterDataSize) + |
| 674 | getEffecterDataSize(effecterDataSize); |
| 675 | |
| 676 | Response response(responsePayloadLength + sizeof(pldm_msg_hdr)); |
| 677 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
| 678 | |
| 679 | rc = platform_numeric_effecter::getNumericEffecterValueHandler( |
| 680 | propertyType, dbusValue, effecterDataSize, responsePtr, |
| 681 | responsePayloadLength, request->hdr.instance_id); |
| 682 | |
| 683 | if (rc != PLDM_SUCCESS) |
| 684 | { |
| 685 | error( |
| 686 | "Reponse to GetNumericEffecterValue failed RC={RC} for EffectorId={EFFECTER_ID} ", |
| 687 | "RC", rc, "EFFECTER_ID", effecterId); |
| 688 | return ccOnlyResponse(request, rc); |
| 689 | } |
| 690 | return response; |
| 691 | } |
| 692 | |
George Liu | eccb0c5 | 2020-01-14 11:09:56 +0800 | [diff] [blame] | 693 | Response Handler::setNumericEffecterValue(const pldm_msg* request, |
| 694 | size_t payloadLength) |
| 695 | { |
| 696 | Response response(sizeof(pldm_msg_hdr) + |
| 697 | PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES); |
| 698 | uint16_t effecterId{}; |
| 699 | uint8_t effecterDataSize{}; |
| 700 | uint8_t effecterValue[4] = {}; |
| 701 | |
| 702 | if ((payloadLength > sizeof(effecterId) + sizeof(effecterDataSize) + |
| 703 | sizeof(union_effecter_data_size)) || |
| 704 | (payloadLength < sizeof(effecterId) + sizeof(effecterDataSize) + 1)) |
| 705 | { |
| 706 | return ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH); |
| 707 | } |
| 708 | |
| 709 | int rc = decode_set_numeric_effecter_value_req( |
Andrew Jeffery | 8fbf3cc | 2023-04-12 13:42:29 +0930 | [diff] [blame] | 710 | request, payloadLength, &effecterId, &effecterDataSize, effecterValue); |
George Liu | eccb0c5 | 2020-01-14 11:09:56 +0800 | [diff] [blame] | 711 | |
| 712 | if (rc == PLDM_SUCCESS) |
| 713 | { |
| 714 | const pldm::utils::DBusHandler dBusIntf; |
| 715 | rc = platform_numeric_effecter::setNumericEffecterValueHandler< |
| 716 | pldm::utils::DBusHandler, Handler>(dBusIntf, *this, effecterId, |
| 717 | effecterDataSize, effecterValue, |
| 718 | sizeof(effecterValue)); |
| 719 | } |
| 720 | |
| 721 | return ccOnlyResponse(request, rc); |
| 722 | } |
| 723 | |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 724 | void Handler::generateTerminusLocatorPDR(Repo& repo) |
| 725 | { |
| 726 | std::vector<uint8_t> pdrBuffer(sizeof(pldm_terminus_locator_pdr)); |
| 727 | |
| 728 | auto pdr = reinterpret_cast<pldm_terminus_locator_pdr*>(pdrBuffer.data()); |
| 729 | |
| 730 | pdr->hdr.record_handle = 0; |
| 731 | pdr->hdr.version = 1; |
| 732 | pdr->hdr.type = PLDM_TERMINUS_LOCATOR_PDR; |
| 733 | pdr->hdr.record_change_num = 0; |
| 734 | pdr->hdr.length = sizeof(pldm_terminus_locator_pdr) - sizeof(pldm_pdr_hdr); |
Manojkiran Eda | cc5f158 | 2021-09-29 17:03:06 +0530 | [diff] [blame] | 735 | pdr->terminus_handle = TERMINUS_HANDLE; |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 736 | pdr->validity = PLDM_TL_PDR_VALID; |
Manojkiran Eda | cc5f158 | 2021-09-29 17:03:06 +0530 | [diff] [blame] | 737 | pdr->tid = TERMINUS_ID; |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 738 | pdr->container_id = 0x0; |
| 739 | pdr->terminus_locator_type = PLDM_TERMINUS_LOCATOR_TYPE_MCTP_EID; |
| 740 | pdr->terminus_locator_value_size = |
| 741 | sizeof(pldm_terminus_locator_type_mctp_eid); |
| 742 | auto locatorValue = reinterpret_cast<pldm_terminus_locator_type_mctp_eid*>( |
| 743 | pdr->terminus_locator_value); |
| 744 | locatorValue->eid = BmcMctpEid; |
| 745 | |
| 746 | PdrEntry pdrEntry{}; |
| 747 | pdrEntry.data = pdrBuffer.data(); |
| 748 | pdrEntry.size = pdrBuffer.size(); |
| 749 | repo.addRecord(pdrEntry); |
Manojkiran Eda | 60e1fe9 | 2021-10-08 15:58:16 +0530 | [diff] [blame] | 750 | if (hostPDRHandler) |
| 751 | { |
| 752 | hostPDRHandler->tlPDRInfo.insert_or_assign( |
| 753 | pdr->terminus_handle, |
| 754 | std::make_tuple(pdr->tid, locatorValue->eid, pdr->validity)); |
| 755 | } |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 756 | } |
George Liu | 362c18d | 2020-05-14 09:46:36 +0800 | [diff] [blame] | 757 | |
| 758 | Response Handler::getStateSensorReadings(const pldm_msg* request, |
| 759 | size_t payloadLength) |
| 760 | { |
| 761 | uint16_t sensorId{}; |
| 762 | bitfield8_t sensorRearm{}; |
| 763 | uint8_t reserved{}; |
| 764 | |
Pavithra Barithaya | 87083f2 | 2023-04-17 01:27:49 -0500 | [diff] [blame] | 765 | if (payloadLength != PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES) |
George Liu | 362c18d | 2020-05-14 09:46:36 +0800 | [diff] [blame] | 766 | { |
| 767 | return ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH); |
| 768 | } |
| 769 | |
| 770 | int rc = decode_get_state_sensor_readings_req( |
| 771 | request, payloadLength, &sensorId, &sensorRearm, &reserved); |
| 772 | |
| 773 | if (rc != PLDM_SUCCESS) |
| 774 | { |
| 775 | return ccOnlyResponse(request, rc); |
| 776 | } |
| 777 | |
| 778 | // 0x01 to 0x08 |
George Liu | c1230ca | 2021-08-03 16:06:50 +0800 | [diff] [blame] | 779 | uint8_t sensorRearmCount = std::popcount(sensorRearm.byte); |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 780 | std::vector<get_sensor_state_field> stateField(sensorRearmCount); |
George Liu | 362c18d | 2020-05-14 09:46:36 +0800 | [diff] [blame] | 781 | uint8_t comSensorCnt{}; |
| 782 | const pldm::utils::DBusHandler dBusIntf; |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 783 | |
| 784 | uint16_t entityType{}; |
| 785 | uint16_t entityInstance{}; |
| 786 | uint16_t stateSetId{}; |
| 787 | |
| 788 | if (isOemStateSensor(*this, sensorId, sensorRearmCount, comSensorCnt, |
| 789 | entityType, entityInstance, stateSetId) && |
Manojkiran Eda | 321804e | 2022-03-03 12:36:54 +0530 | [diff] [blame] | 790 | oemPlatformHandler != nullptr && !sensorDbusObjMaps.contains(sensorId)) |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 791 | { |
| 792 | rc = oemPlatformHandler->getOemStateSensorReadingsHandler( |
| 793 | entityType, entityInstance, stateSetId, comSensorCnt, stateField); |
| 794 | } |
| 795 | else |
| 796 | { |
| 797 | rc = platform_state_sensor::getStateSensorReadingsHandler< |
Manojkiran Eda | ae933cc | 2024-02-21 17:19:21 +0530 | [diff] [blame] | 798 | pldm::utils::DBusHandler, Handler>( |
| 799 | dBusIntf, *this, sensorId, sensorRearmCount, comSensorCnt, |
| 800 | stateField, dbusToPLDMEventHandler->getSensorCache()); |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 801 | } |
George Liu | 362c18d | 2020-05-14 09:46:36 +0800 | [diff] [blame] | 802 | |
| 803 | if (rc != PLDM_SUCCESS) |
| 804 | { |
| 805 | return ccOnlyResponse(request, rc); |
| 806 | } |
| 807 | |
| 808 | Response response(sizeof(pldm_msg_hdr) + |
| 809 | PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES + |
| 810 | sizeof(get_sensor_state_field) * comSensorCnt); |
| 811 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
| 812 | rc = encode_get_state_sensor_readings_resp(request->hdr.instance_id, rc, |
| 813 | comSensorCnt, stateField.data(), |
| 814 | responsePtr); |
| 815 | if (rc != PLDM_SUCCESS) |
| 816 | { |
| 817 | return ccOnlyResponse(request, rc); |
| 818 | } |
| 819 | |
| 820 | return response; |
| 821 | } |
| 822 | |
Pavithra Barithaya | 99854a7 | 2021-09-29 06:58:11 -0500 | [diff] [blame] | 823 | void Handler::_processPostGetPDRActions(sdeventplus::source::EventBase& |
| 824 | /*source */) |
Sampa Misra | 5fb37d5 | 2021-03-06 07:26:00 -0600 | [diff] [blame] | 825 | { |
| 826 | deferredGetPDREvent.reset(); |
| 827 | dbusToPLDMEventHandler->listenSensorEvent(pdrRepo, sensorDbusObjMaps); |
| 828 | } |
| 829 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 830 | bool isOemStateSensor(Handler& handler, uint16_t sensorId, |
| 831 | uint8_t sensorRearmCount, uint8_t& compSensorCnt, |
| 832 | uint16_t& entityType, uint16_t& entityInstance, |
| 833 | uint16_t& stateSetId) |
| 834 | { |
| 835 | pldm_state_sensor_pdr* pdr = nullptr; |
| 836 | |
| 837 | std::unique_ptr<pldm_pdr, decltype(&pldm_pdr_destroy)> stateSensorPdrRepo( |
| 838 | pldm_pdr_init(), pldm_pdr_destroy); |
Andrew Jeffery | acb2029 | 2023-06-30 11:47:44 +0930 | [diff] [blame] | 839 | if (!stateSensorPdrRepo) |
| 840 | { |
| 841 | error("Failed to instantiate state sensor PDR repository"); |
| 842 | return false; |
| 843 | } |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 844 | Repo stateSensorPDRs(stateSensorPdrRepo.get()); |
| 845 | getRepoByType(handler.getRepo(), stateSensorPDRs, PLDM_STATE_SENSOR_PDR); |
| 846 | if (stateSensorPDRs.empty()) |
| 847 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 848 | error("Failed to get record by PDR type"); |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 849 | return false; |
| 850 | } |
| 851 | |
| 852 | PdrEntry pdrEntry{}; |
| 853 | auto pdrRecord = stateSensorPDRs.getFirstRecord(pdrEntry); |
| 854 | while (pdrRecord) |
| 855 | { |
| 856 | pdr = reinterpret_cast<pldm_state_sensor_pdr*>(pdrEntry.data); |
| 857 | assert(pdr != NULL); |
| 858 | if (pdr->sensor_id != sensorId) |
| 859 | { |
| 860 | pdr = nullptr; |
| 861 | pdrRecord = stateSensorPDRs.getNextRecord(pdrRecord, pdrEntry); |
| 862 | continue; |
| 863 | } |
| 864 | auto tmpEntityType = pdr->entity_type; |
| 865 | auto tmpEntityInstance = pdr->entity_instance; |
| 866 | auto tmpCompSensorCnt = pdr->composite_sensor_count; |
| 867 | auto tmpPossibleStates = |
| 868 | reinterpret_cast<state_sensor_possible_states*>( |
| 869 | pdr->possible_states); |
| 870 | auto tmpStateSetId = tmpPossibleStates->state_set_id; |
| 871 | |
| 872 | if (sensorRearmCount > tmpCompSensorCnt) |
| 873 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 874 | error( |
| 875 | "The requester sent wrong sensorRearm count for the sensor, SENSOR_ID={SENSOR_ID} SENSOR_REARM_COUNT={SENSOR_REARM_CNT}", |
| 876 | "SENSOR_ID", sensorId, "SENSOR_REARM_CNT", |
| 877 | (uint16_t)sensorRearmCount); |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 878 | break; |
| 879 | } |
| 880 | |
| 881 | if ((tmpEntityType >= PLDM_OEM_ENTITY_TYPE_START && |
| 882 | tmpEntityType <= PLDM_OEM_ENTITY_TYPE_END) || |
| 883 | (tmpStateSetId >= PLDM_OEM_STATE_SET_ID_START && |
| 884 | tmpStateSetId < PLDM_OEM_STATE_SET_ID_END)) |
| 885 | { |
| 886 | entityType = tmpEntityType; |
| 887 | entityInstance = tmpEntityInstance; |
| 888 | stateSetId = tmpStateSetId; |
| 889 | compSensorCnt = tmpCompSensorCnt; |
| 890 | return true; |
| 891 | } |
| 892 | else |
| 893 | { |
| 894 | return false; |
| 895 | } |
| 896 | } |
| 897 | return false; |
| 898 | } |
| 899 | |
| 900 | bool isOemStateEffecter(Handler& handler, uint16_t effecterId, |
| 901 | uint8_t compEffecterCnt, uint16_t& entityType, |
| 902 | uint16_t& entityInstance, uint16_t& stateSetId) |
| 903 | { |
| 904 | pldm_state_effecter_pdr* pdr = nullptr; |
| 905 | |
| 906 | std::unique_ptr<pldm_pdr, decltype(&pldm_pdr_destroy)> stateEffecterPdrRepo( |
| 907 | pldm_pdr_init(), pldm_pdr_destroy); |
Andrew Jeffery | acb2029 | 2023-06-30 11:47:44 +0930 | [diff] [blame] | 908 | if (!stateEffecterPdrRepo) |
| 909 | { |
| 910 | error("Failed to instantiate state effecter PDR repository"); |
| 911 | return false; |
| 912 | } |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 913 | Repo stateEffecterPDRs(stateEffecterPdrRepo.get()); |
| 914 | getRepoByType(handler.getRepo(), stateEffecterPDRs, |
| 915 | PLDM_STATE_EFFECTER_PDR); |
| 916 | if (stateEffecterPDRs.empty()) |
| 917 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 918 | error("Failed to get record by PDR type"); |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 919 | return false; |
| 920 | } |
| 921 | |
| 922 | PdrEntry pdrEntry{}; |
| 923 | auto pdrRecord = stateEffecterPDRs.getFirstRecord(pdrEntry); |
| 924 | while (pdrRecord) |
| 925 | { |
| 926 | pdr = reinterpret_cast<pldm_state_effecter_pdr*>(pdrEntry.data); |
| 927 | assert(pdr != NULL); |
| 928 | if (pdr->effecter_id != effecterId) |
| 929 | { |
| 930 | pdr = nullptr; |
| 931 | pdrRecord = stateEffecterPDRs.getNextRecord(pdrRecord, pdrEntry); |
| 932 | continue; |
| 933 | } |
| 934 | |
| 935 | auto tmpEntityType = pdr->entity_type; |
| 936 | auto tmpEntityInstance = pdr->entity_instance; |
| 937 | auto tmpPossibleStates = |
| 938 | reinterpret_cast<state_effecter_possible_states*>( |
| 939 | pdr->possible_states); |
| 940 | auto tmpStateSetId = tmpPossibleStates->state_set_id; |
| 941 | |
| 942 | if (compEffecterCnt > pdr->composite_effecter_count) |
| 943 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 944 | error( |
| 945 | "The requester sent wrong composite effecter count for the effecter, EFFECTER_ID={EFFECTER_ID} COMP_EFF_CNT={COMP_EFF_CNT}", |
| 946 | "EFFECTER_ID", effecterId, "COMP_EFF_CNT", |
| 947 | (uint16_t)compEffecterCnt); |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 948 | return false; |
| 949 | } |
| 950 | |
| 951 | if ((tmpEntityType >= PLDM_OEM_ENTITY_TYPE_START && |
| 952 | tmpEntityType <= PLDM_OEM_ENTITY_TYPE_END) || |
| 953 | (tmpStateSetId >= PLDM_OEM_STATE_SET_ID_START && |
| 954 | tmpStateSetId < PLDM_OEM_STATE_SET_ID_END)) |
| 955 | { |
| 956 | entityType = tmpEntityType; |
| 957 | entityInstance = tmpEntityInstance; |
| 958 | stateSetId = tmpStateSetId; |
| 959 | return true; |
| 960 | } |
| 961 | else |
| 962 | { |
| 963 | return false; |
| 964 | } |
| 965 | } |
| 966 | return false; |
| 967 | } |
| 968 | |
Sagar Srinivas | 90314a3 | 2023-10-17 10:38:03 -0500 | [diff] [blame] | 969 | void Handler::setEventReceiver() |
| 970 | { |
| 971 | std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) + |
| 972 | PLDM_SET_EVENT_RECEIVER_REQ_BYTES); |
| 973 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 974 | auto instanceId = instanceIdDb->next(eid); |
| 975 | uint8_t eventMessageGlobalEnable = |
| 976 | PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE; |
| 977 | uint8_t transportProtocolType = PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP; |
| 978 | uint8_t eventReceiverAddressInfo = pldm::responder::pdr::BmcMctpEid; |
| 979 | uint16_t heartbeatTimer = HEARTBEAT_TIMEOUT; |
| 980 | |
| 981 | auto rc = encode_set_event_receiver_req( |
| 982 | instanceId, eventMessageGlobalEnable, transportProtocolType, |
| 983 | eventReceiverAddressInfo, heartbeatTimer, request); |
| 984 | if (rc != PLDM_SUCCESS) |
| 985 | { |
| 986 | instanceIdDb->free(eid, instanceId); |
| 987 | error("Failed to encode_set_event_receiver_req, rc = {RC}", "RC", |
| 988 | lg2::hex, rc); |
| 989 | return; |
| 990 | } |
| 991 | |
| 992 | auto processSetEventReceiverResponse = |
| 993 | [](mctp_eid_t /*eid*/, const pldm_msg* response, size_t respMsgLen) { |
| 994 | if (response == nullptr || !respMsgLen) |
| 995 | { |
| 996 | error("Failed to receive response for setEventReceiver command"); |
| 997 | return; |
| 998 | } |
| 999 | |
| 1000 | uint8_t completionCode{}; |
| 1001 | auto rc = decode_set_event_receiver_resp(response, respMsgLen, |
| 1002 | &completionCode); |
| 1003 | if (rc || completionCode) |
| 1004 | { |
| 1005 | error( |
| 1006 | "Failed to decode setEventReceiver command response, rc = {RC}, cc = {CC}", |
| 1007 | "RC", rc, "CC", (unsigned)completionCode); |
| 1008 | pldm::utils::reportError( |
Manojkiran Eda | 92fb0b5 | 2024-04-17 10:48:17 +0530 | [diff] [blame] | 1009 | "xyz.openbmc_project.bmc.pldm.InternalFailure"); |
Sagar Srinivas | 90314a3 | 2023-10-17 10:38:03 -0500 | [diff] [blame] | 1010 | } |
| 1011 | }; |
| 1012 | rc = handler->registerRequest( |
| 1013 | eid, instanceId, PLDM_PLATFORM, PLDM_SET_EVENT_RECEIVER, |
| 1014 | std::move(requestMsg), std::move(processSetEventReceiverResponse)); |
| 1015 | |
| 1016 | if (rc != PLDM_SUCCESS) |
| 1017 | { |
| 1018 | error("Failed to send the setEventReceiver request"); |
| 1019 | } |
| 1020 | |
| 1021 | if (oemPlatformHandler) |
| 1022 | { |
| 1023 | oemPlatformHandler->countSetEventReceiver(); |
| 1024 | oemPlatformHandler->checkAndDisableWatchDog(); |
| 1025 | } |
| 1026 | } |
| 1027 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 1028 | } // namespace platform |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 1029 | } // namespace responder |
| 1030 | } // namespace pldm |