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