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