Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 1 | |
| 2 | #include "platform.hpp" |
| 3 | |
Tom Joseph | b70a196 | 2020-07-13 12:56:31 +0530 | [diff] [blame] | 4 | #include "common/types.hpp" |
Deepak Kodihalli | d130e1a | 2020-06-17 05:55:32 -0500 | [diff] [blame] | 5 | #include "common/utils.hpp" |
Tom Joseph | c4959c3 | 2020-04-20 19:50:16 +0530 | [diff] [blame] | 6 | #include "event_parser.hpp" |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 7 | #include "pdr.hpp" |
George Liu | 456c9a2 | 2020-01-13 11:36:22 +0800 | [diff] [blame] | 8 | #include "pdr_numeric_effecter.hpp" |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 9 | #include "pdr_state_effecter.hpp" |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 10 | #include "pdr_state_sensor.hpp" |
George Liu | 362c18d | 2020-05-14 09:46:36 +0800 | [diff] [blame] | 11 | #include "pdr_utils.hpp" |
George Liu | eccb0c5 | 2020-01-14 11:09:56 +0800 | [diff] [blame] | 12 | #include "platform_numeric_effecter.hpp" |
George Liu | 0d7aca8 | 2020-03-30 15:01:36 +0800 | [diff] [blame] | 13 | #include "platform_state_effecter.hpp" |
George Liu | 362c18d | 2020-05-14 09:46:36 +0800 | [diff] [blame] | 14 | #include "platform_state_sensor.hpp" |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 15 | |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 16 | namespace pldm |
| 17 | { |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 18 | namespace responder |
| 19 | { |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 20 | namespace platform |
| 21 | { |
| 22 | |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 23 | using InternalFailure = |
| 24 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
| 25 | |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 26 | static const Json empty{}; |
| 27 | |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 28 | void Handler::addDbusObjMaps( |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 29 | uint16_t id, |
| 30 | std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> dbusObj, |
| 31 | TypeId typeId) |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 32 | { |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 33 | if (typeId == TypeId::PLDM_SENSOR_ID) |
| 34 | { |
| 35 | sensorDbusObjMaps.emplace(id, dbusObj); |
| 36 | } |
| 37 | else |
| 38 | { |
| 39 | effecterDbusObjMaps.emplace(id, dbusObj); |
| 40 | } |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 41 | } |
| 42 | |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 43 | const std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>& |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 44 | Handler::getDbusObjMaps(uint16_t id, TypeId typeId) const |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 45 | { |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 46 | if (typeId == TypeId::PLDM_SENSOR_ID) |
| 47 | { |
| 48 | return sensorDbusObjMaps.at(id); |
| 49 | } |
| 50 | else |
| 51 | { |
| 52 | return effecterDbusObjMaps.at(id); |
| 53 | } |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 54 | } |
| 55 | |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 56 | void Handler::generate(const pldm::utils::DBusHandler& dBusIntf, |
| 57 | const std::string& dir, Repo& repo) |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 58 | { |
Deepak Kodihalli | c6e49c4 | 2020-07-01 03:39:27 -0500 | [diff] [blame] | 59 | if (!fs::exists(dir)) |
| 60 | { |
| 61 | return; |
| 62 | } |
| 63 | |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 64 | // A map of PDR type to a lambda that handles creation of that PDR type. |
| 65 | // The lambda essentially would parse the platform specific PDR JSONs to |
| 66 | // generate the PDR structures. This function iterates through the map to |
| 67 | // invoke all lambdas, so that all PDR types can be created. |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 68 | |
| 69 | const std::map<Type, generatePDR> generateHandlers = { |
| 70 | {PLDM_STATE_EFFECTER_PDR, |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 71 | [this](const DBusHandler& dBusIntf, const auto& json, |
| 72 | RepoInterface& repo) { |
| 73 | pdr_state_effecter::generateStateEffecterPDR< |
| 74 | pldm::utils::DBusHandler, Handler>(dBusIntf, json, *this, |
| 75 | repo); |
George Liu | 456c9a2 | 2020-01-13 11:36:22 +0800 | [diff] [blame] | 76 | }}, |
| 77 | {PLDM_NUMERIC_EFFECTER_PDR, |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 78 | [this](const DBusHandler& dBusIntf, const auto& json, |
| 79 | RepoInterface& repo) { |
| 80 | pdr_numeric_effecter::generateNumericEffecterPDR< |
| 81 | pldm::utils::DBusHandler, Handler>(dBusIntf, json, *this, |
| 82 | repo); |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 83 | }}, |
| 84 | {PLDM_STATE_SENSOR_PDR, [this](const DBusHandler& dBusIntf, |
| 85 | const auto& json, RepoInterface& repo) { |
| 86 | pdr_state_sensor::generateStateSensorPDR<pldm::utils::DBusHandler, |
| 87 | Handler>(dBusIntf, json, |
| 88 | *this, repo); |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 89 | }}}; |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 90 | |
| 91 | Type pdrType{}; |
| 92 | for (const auto& dirEntry : fs::directory_iterator(dir)) |
| 93 | { |
| 94 | try |
| 95 | { |
| 96 | auto json = readJson(dirEntry.path().string()); |
| 97 | if (!json.empty()) |
| 98 | { |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 99 | auto effecterPDRs = json.value("effecterPDRs", empty); |
| 100 | for (const auto& effecter : effecterPDRs) |
| 101 | { |
| 102 | pdrType = effecter.value("pdrType", 0); |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 103 | generateHandlers.at(pdrType)(dBusIntf, effecter, repo); |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 104 | } |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 105 | |
| 106 | auto sensorPDRs = json.value("sensorPDRs", empty); |
| 107 | for (const auto& sensor : sensorPDRs) |
| 108 | { |
| 109 | pdrType = sensor.value("pdrType", 0); |
| 110 | generateHandlers.at(pdrType)(dBusIntf, sensor, repo); |
| 111 | } |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 112 | } |
| 113 | } |
| 114 | catch (const InternalFailure& e) |
| 115 | { |
| 116 | std::cerr << "PDR config directory does not exist or empty, TYPE= " |
| 117 | << pdrType << "PATH= " << dirEntry |
| 118 | << " ERROR=" << e.what() << "\n"; |
| 119 | } |
| 120 | catch (const Json::exception& e) |
| 121 | { |
| 122 | std::cerr << "Failed parsing PDR JSON file, TYPE= " << pdrType |
| 123 | << " ERROR=" << e.what() << "\n"; |
| 124 | pldm::utils::reportError( |
| 125 | "xyz.openbmc_project.bmc.pldm.InternalFailure"); |
| 126 | } |
| 127 | catch (const std::exception& e) |
| 128 | { |
| 129 | std::cerr << "Failed parsing PDR JSON file, TYPE= " << pdrType |
| 130 | << " ERROR=" << e.what() << "\n"; |
| 131 | pldm::utils::reportError( |
| 132 | "xyz.openbmc_project.bmc.pldm.InternalFailure"); |
| 133 | } |
| 134 | } |
| 135 | } |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 136 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 137 | Response Handler::getPDR(const pldm_msg* request, size_t payloadLength) |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 138 | { |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 139 | // Build FRU table if not built, since entity association PDR's are built |
| 140 | // when the FRU table is constructed. |
| 141 | if (fruHandler) |
| 142 | { |
| 143 | fruHandler->buildFRUTable(); |
| 144 | } |
| 145 | |
George Liu | d680ae0 | 2020-07-17 09:11:14 +0800 | [diff] [blame] | 146 | if (!pdrCreated) |
| 147 | { |
| 148 | generateTerminusLocatorPDR(pdrRepo); |
| 149 | generate(*dBusIntf, pdrJsonsDir, pdrRepo); |
| 150 | pdrCreated = true; |
| 151 | } |
| 152 | |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 153 | Response response(sizeof(pldm_msg_hdr) + PLDM_GET_PDR_MIN_RESP_BYTES, 0); |
| 154 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
| 155 | |
| 156 | if (payloadLength != PLDM_GET_PDR_REQ_BYTES) |
| 157 | { |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 158 | return CmdHandler::ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | uint32_t recordHandle{}; |
| 162 | uint32_t dataTransferHandle{}; |
| 163 | uint8_t transferOpFlag{}; |
| 164 | uint16_t reqSizeBytes{}; |
| 165 | uint16_t recordChangeNum{}; |
| 166 | |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 167 | auto rc = decode_get_pdr_req(request, payloadLength, &recordHandle, |
| 168 | &dataTransferHandle, &transferOpFlag, |
| 169 | &reqSizeBytes, &recordChangeNum); |
| 170 | if (rc != PLDM_SUCCESS) |
| 171 | { |
| 172 | return CmdHandler::ccOnlyResponse(request, rc); |
| 173 | } |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 174 | |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 175 | uint16_t respSizeBytes{}; |
| 176 | uint8_t* recordData = nullptr; |
| 177 | try |
| 178 | { |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 179 | pdr_utils::PdrEntry e; |
| 180 | auto record = pdr::getRecordByHandle(pdrRepo, recordHandle, e); |
| 181 | if (record == NULL) |
| 182 | { |
| 183 | return CmdHandler::ccOnlyResponse( |
| 184 | request, PLDM_PLATFORM_INVALID_RECORD_HANDLE); |
| 185 | } |
| 186 | |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 187 | if (reqSizeBytes) |
| 188 | { |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 189 | respSizeBytes = e.size; |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 190 | if (respSizeBytes > reqSizeBytes) |
| 191 | { |
| 192 | respSizeBytes = reqSizeBytes; |
| 193 | } |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 194 | recordData = e.data; |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 195 | } |
| 196 | response.resize(sizeof(pldm_msg_hdr) + PLDM_GET_PDR_MIN_RESP_BYTES + |
| 197 | respSizeBytes, |
| 198 | 0); |
| 199 | responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
Deepak Kodihalli | 22b5a7d | 2020-03-17 23:28:41 -0500 | [diff] [blame] | 200 | rc = encode_get_pdr_resp( |
| 201 | request->hdr.instance_id, PLDM_SUCCESS, e.handle.nextRecordHandle, |
| 202 | 0, PLDM_START_AND_END, respSizeBytes, recordData, 0, responsePtr); |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 203 | if (rc != PLDM_SUCCESS) |
| 204 | { |
| 205 | return ccOnlyResponse(request, rc); |
| 206 | } |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 207 | } |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 208 | catch (const std::exception& e) |
| 209 | { |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 210 | std::cerr << "Error accessing PDR, HANDLE=" << recordHandle |
| 211 | << " ERROR=" << e.what() << "\n"; |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 212 | return CmdHandler::ccOnlyResponse(request, PLDM_ERROR); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 213 | } |
| 214 | return response; |
| 215 | } |
| 216 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 217 | Response Handler::setStateEffecterStates(const pldm_msg* request, |
| 218 | size_t payloadLength) |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 219 | { |
| 220 | Response response( |
| 221 | sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES, 0); |
| 222 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
| 223 | uint16_t effecterId; |
| 224 | uint8_t compEffecterCnt; |
| 225 | constexpr auto maxCompositeEffecterCnt = 8; |
| 226 | std::vector<set_effecter_state_field> stateField(maxCompositeEffecterCnt, |
| 227 | {0, 0}); |
| 228 | |
| 229 | if ((payloadLength > PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES) || |
| 230 | (payloadLength < sizeof(effecterId) + sizeof(compEffecterCnt) + |
| 231 | sizeof(set_effecter_state_field))) |
| 232 | { |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 233 | return CmdHandler::ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | int rc = decode_set_state_effecter_states_req(request, payloadLength, |
| 237 | &effecterId, &compEffecterCnt, |
| 238 | stateField.data()); |
| 239 | |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 240 | if (rc != PLDM_SUCCESS) |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 241 | { |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 242 | return CmdHandler::ccOnlyResponse(request, rc); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 243 | } |
| 244 | |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 245 | stateField.resize(compEffecterCnt); |
| 246 | const pldm::utils::DBusHandler dBusIntf; |
George Liu | 0d7aca8 | 2020-03-30 15:01:36 +0800 | [diff] [blame] | 247 | rc = platform_state_effecter::setStateEffecterStatesHandler< |
| 248 | pldm::utils::DBusHandler, Handler>(dBusIntf, *this, effecterId, |
| 249 | stateField); |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 250 | if (rc != PLDM_SUCCESS) |
| 251 | { |
| 252 | return CmdHandler::ccOnlyResponse(request, rc); |
| 253 | } |
| 254 | |
| 255 | rc = encode_set_state_effecter_states_resp(request->hdr.instance_id, rc, |
| 256 | responsePtr); |
| 257 | if (rc != PLDM_SUCCESS) |
| 258 | { |
| 259 | return ccOnlyResponse(request, rc); |
| 260 | } |
| 261 | |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 262 | return response; |
| 263 | } |
| 264 | |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 265 | Response Handler::platformEventMessage(const pldm_msg* request, |
| 266 | size_t payloadLength) |
| 267 | { |
| 268 | uint8_t formatVersion{}; |
| 269 | uint8_t tid{}; |
| 270 | uint8_t eventClass{}; |
| 271 | size_t offset{}; |
| 272 | |
| 273 | auto rc = decode_platform_event_message_req( |
| 274 | request, payloadLength, &formatVersion, &tid, &eventClass, &offset); |
| 275 | if (rc != PLDM_SUCCESS) |
| 276 | { |
| 277 | return CmdHandler::ccOnlyResponse(request, rc); |
| 278 | } |
| 279 | |
| 280 | try |
| 281 | { |
| 282 | const auto& handlers = eventHandlers.at(eventClass); |
| 283 | for (const auto& handler : handlers) |
| 284 | { |
| 285 | auto rc = |
| 286 | handler(request, payloadLength, formatVersion, tid, offset); |
| 287 | if (rc != PLDM_SUCCESS) |
| 288 | { |
| 289 | return CmdHandler::ccOnlyResponse(request, rc); |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | catch (const std::out_of_range& e) |
| 294 | { |
| 295 | return CmdHandler::ccOnlyResponse(request, PLDM_ERROR_INVALID_DATA); |
| 296 | } |
| 297 | |
| 298 | Response response( |
| 299 | sizeof(pldm_msg_hdr) + PLDM_PLATFORM_EVENT_MESSAGE_RESP_BYTES, 0); |
| 300 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
| 301 | |
| 302 | rc = encode_platform_event_message_resp(request->hdr.instance_id, rc, |
| 303 | PLDM_EVENT_NO_LOGGING, responsePtr); |
| 304 | if (rc != PLDM_SUCCESS) |
| 305 | { |
| 306 | return ccOnlyResponse(request, rc); |
| 307 | } |
| 308 | |
| 309 | return response; |
| 310 | } |
| 311 | |
| 312 | int Handler::sensorEvent(const pldm_msg* request, size_t payloadLength, |
Tom Joseph | c4959c3 | 2020-04-20 19:50:16 +0530 | [diff] [blame] | 313 | uint8_t /*formatVersion*/, uint8_t tid, |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 314 | size_t eventDataOffset) |
| 315 | { |
| 316 | uint16_t sensorId{}; |
| 317 | uint8_t eventClass{}; |
| 318 | size_t eventClassDataOffset{}; |
| 319 | auto eventData = |
| 320 | reinterpret_cast<const uint8_t*>(request->payload) + eventDataOffset; |
| 321 | auto eventDataSize = payloadLength - eventDataOffset; |
| 322 | |
| 323 | auto rc = decode_sensor_event_data(eventData, eventDataSize, &sensorId, |
| 324 | &eventClass, &eventClassDataOffset); |
| 325 | if (rc != PLDM_SUCCESS) |
| 326 | { |
| 327 | return rc; |
| 328 | } |
| 329 | |
Zahed Hossain | 75330f3 | 2020-03-24 02:15:03 -0500 | [diff] [blame] | 330 | auto eventClassData = reinterpret_cast<const uint8_t*>(request->payload) + |
| 331 | eventDataOffset + eventClassDataOffset; |
| 332 | auto eventClassDataSize = |
| 333 | payloadLength - eventDataOffset - eventClassDataOffset; |
| 334 | |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 335 | if (eventClass == PLDM_STATE_SENSOR_STATE) |
| 336 | { |
| 337 | uint8_t sensorOffset{}; |
| 338 | uint8_t eventState{}; |
| 339 | uint8_t previousEventState{}; |
| 340 | |
Zahed Hossain | 75330f3 | 2020-03-24 02:15:03 -0500 | [diff] [blame] | 341 | rc = decode_state_sensor_data(eventClassData, eventClassDataSize, |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 342 | &sensorOffset, &eventState, |
| 343 | &previousEventState); |
Zahed Hossain | 75330f3 | 2020-03-24 02:15:03 -0500 | [diff] [blame] | 344 | if (rc != PLDM_SUCCESS) |
| 345 | { |
| 346 | return PLDM_ERROR; |
| 347 | } |
| 348 | |
Chicago Duan | fe4d88b | 2020-06-12 16:44:13 +0800 | [diff] [blame] | 349 | // Emitting state sensor event signal |
| 350 | emitStateSensorEventSignal(tid, sensorId, sensorOffset, eventState, |
| 351 | previousEventState); |
| 352 | |
Tom Joseph | c4959c3 | 2020-04-20 19:50:16 +0530 | [diff] [blame] | 353 | // If there are no HOST PDR's, there is no further action |
| 354 | if (hostPDRHandler == NULL) |
| 355 | { |
| 356 | return PLDM_SUCCESS; |
| 357 | } |
| 358 | |
| 359 | // Handle PLDM events for which PDR is available |
| 360 | SensorEntry sensorEntry{tid, sensorId}; |
Tom Joseph | b70a196 | 2020-07-13 12:56:31 +0530 | [diff] [blame] | 361 | |
| 362 | pldm::pdr::EntityInfo entityInfo{}; |
| 363 | pldm::pdr::CompositeSensorStates compositeSensorStates{}; |
| 364 | |
Tom Joseph | c4959c3 | 2020-04-20 19:50:16 +0530 | [diff] [blame] | 365 | try |
| 366 | { |
Tom Joseph | b70a196 | 2020-07-13 12:56:31 +0530 | [diff] [blame] | 367 | std::tie(entityInfo, compositeSensorStates) = |
Tom Joseph | c4959c3 | 2020-04-20 19:50:16 +0530 | [diff] [blame] | 368 | hostPDRHandler->lookupSensorInfo(sensorEntry); |
Tom Joseph | c4959c3 | 2020-04-20 19:50:16 +0530 | [diff] [blame] | 369 | } |
Tom Joseph | c4959c3 | 2020-04-20 19:50:16 +0530 | [diff] [blame] | 370 | catch (const std::out_of_range& e) |
| 371 | { |
Tom Joseph | b70a196 | 2020-07-13 12:56:31 +0530 | [diff] [blame] | 372 | // If there is no mapping for tid, sensorId combination, try |
| 373 | // PLDM_TID_RESERVED, sensorId for terminus that is yet to |
| 374 | // implement TL PDR. |
| 375 | try |
| 376 | { |
| 377 | sensorEntry.terminusID = PLDM_TID_RESERVED; |
| 378 | std::tie(entityInfo, compositeSensorStates) = |
| 379 | hostPDRHandler->lookupSensorInfo(sensorEntry); |
| 380 | } |
| 381 | // If there is no mapping for events return PLDM_SUCCESS |
| 382 | catch (const std::out_of_range& e) |
| 383 | { |
| 384 | return PLDM_SUCCESS; |
| 385 | } |
Zahed Hossain | 75330f3 | 2020-03-24 02:15:03 -0500 | [diff] [blame] | 386 | } |
Tom Joseph | b70a196 | 2020-07-13 12:56:31 +0530 | [diff] [blame] | 387 | |
| 388 | if (sensorOffset >= compositeSensorStates.size()) |
| 389 | { |
| 390 | return PLDM_ERROR_INVALID_DATA; |
| 391 | } |
| 392 | |
| 393 | const auto& possibleStates = compositeSensorStates[sensorOffset]; |
| 394 | if (possibleStates.find(eventState) == possibleStates.end()) |
| 395 | { |
| 396 | return PLDM_ERROR_INVALID_DATA; |
| 397 | } |
| 398 | |
| 399 | const auto& [containerId, entityType, entityInstance] = entityInfo; |
| 400 | events::StateSensorEntry stateSensorEntry{containerId, entityType, |
| 401 | entityInstance, sensorOffset}; |
Pavithra Barithaya | 3aec997 | 2020-12-14 01:55:44 -0600 | [diff] [blame^] | 402 | return hostPDRHandler->handleStateSensorEvent(stateSensorEntry, |
| 403 | eventState); |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 404 | } |
| 405 | else |
| 406 | { |
| 407 | return PLDM_ERROR_INVALID_DATA; |
| 408 | } |
| 409 | |
| 410 | return PLDM_SUCCESS; |
| 411 | } |
| 412 | |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 413 | int Handler::pldmPDRRepositoryChgEvent(const pldm_msg* request, |
| 414 | size_t payloadLength, |
| 415 | uint8_t /*formatVersion*/, |
| 416 | uint8_t /*tid*/, size_t eventDataOffset) |
| 417 | { |
| 418 | uint8_t eventDataFormat{}; |
| 419 | uint8_t numberOfChangeRecords{}; |
| 420 | size_t dataOffset{}; |
| 421 | |
| 422 | auto eventData = |
| 423 | reinterpret_cast<const uint8_t*>(request->payload) + eventDataOffset; |
| 424 | auto eventDataSize = payloadLength - eventDataOffset; |
| 425 | |
| 426 | auto rc = decode_pldm_pdr_repository_chg_event_data( |
| 427 | eventData, eventDataSize, &eventDataFormat, &numberOfChangeRecords, |
| 428 | &dataOffset); |
| 429 | if (rc != PLDM_SUCCESS) |
| 430 | { |
| 431 | return rc; |
| 432 | } |
| 433 | |
| 434 | PDRRecordHandles pdrRecordHandles; |
Deepak Kodihalli | 7246e0c | 2020-07-08 06:40:18 -0500 | [diff] [blame] | 435 | |
| 436 | if (eventDataFormat == FORMAT_IS_PDR_TYPES) |
| 437 | { |
| 438 | return PLDM_ERROR_INVALID_DATA; |
| 439 | } |
| 440 | |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 441 | if (eventDataFormat == FORMAT_IS_PDR_HANDLES) |
| 442 | { |
| 443 | uint8_t eventDataOperation{}; |
| 444 | uint8_t numberOfChangeEntries{}; |
| 445 | |
| 446 | auto changeRecordData = eventData + dataOffset; |
| 447 | auto changeRecordDataSize = eventDataSize - dataOffset; |
| 448 | |
| 449 | while (changeRecordDataSize) |
| 450 | { |
| 451 | rc = decode_pldm_pdr_repository_change_record_data( |
| 452 | changeRecordData, changeRecordDataSize, &eventDataOperation, |
| 453 | &numberOfChangeEntries, &dataOffset); |
| 454 | |
| 455 | if (rc != PLDM_SUCCESS) |
| 456 | { |
| 457 | return rc; |
| 458 | } |
| 459 | |
| 460 | if (eventDataOperation == PLDM_RECORDS_ADDED) |
| 461 | { |
| 462 | rc = getPDRRecordHandles( |
| 463 | reinterpret_cast<const ChangeEntry*>(changeRecordData + |
| 464 | dataOffset), |
| 465 | changeRecordDataSize - dataOffset, |
| 466 | static_cast<size_t>(numberOfChangeEntries), |
| 467 | pdrRecordHandles); |
| 468 | |
| 469 | if (rc != PLDM_SUCCESS) |
| 470 | { |
| 471 | return rc; |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | changeRecordData += |
| 476 | dataOffset + (numberOfChangeEntries * sizeof(ChangeEntry)); |
| 477 | changeRecordDataSize -= |
| 478 | dataOffset + (numberOfChangeEntries * sizeof(ChangeEntry)); |
| 479 | } |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 480 | } |
Deepak Kodihalli | 7246e0c | 2020-07-08 06:40:18 -0500 | [diff] [blame] | 481 | if (hostPDRHandler) |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 482 | { |
Deepak Kodihalli | 7246e0c | 2020-07-08 06:40:18 -0500 | [diff] [blame] | 483 | hostPDRHandler->fetchPDR(std::move(pdrRecordHandles)); |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | return PLDM_SUCCESS; |
| 487 | } |
| 488 | |
| 489 | int Handler::getPDRRecordHandles(const ChangeEntry* changeEntryData, |
| 490 | size_t changeEntryDataSize, |
| 491 | size_t numberOfChangeEntries, |
| 492 | PDRRecordHandles& pdrRecordHandles) |
| 493 | { |
| 494 | if (numberOfChangeEntries > (changeEntryDataSize / sizeof(ChangeEntry))) |
| 495 | { |
| 496 | return PLDM_ERROR_INVALID_DATA; |
| 497 | } |
| 498 | for (size_t i = 0; i < numberOfChangeEntries; i++) |
| 499 | { |
| 500 | pdrRecordHandles.push_back(changeEntryData[i]); |
| 501 | } |
| 502 | return PLDM_SUCCESS; |
| 503 | } |
| 504 | |
George Liu | eccb0c5 | 2020-01-14 11:09:56 +0800 | [diff] [blame] | 505 | Response Handler::setNumericEffecterValue(const pldm_msg* request, |
| 506 | size_t payloadLength) |
| 507 | { |
| 508 | Response response(sizeof(pldm_msg_hdr) + |
| 509 | PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES); |
| 510 | uint16_t effecterId{}; |
| 511 | uint8_t effecterDataSize{}; |
| 512 | uint8_t effecterValue[4] = {}; |
| 513 | |
| 514 | if ((payloadLength > sizeof(effecterId) + sizeof(effecterDataSize) + |
| 515 | sizeof(union_effecter_data_size)) || |
| 516 | (payloadLength < sizeof(effecterId) + sizeof(effecterDataSize) + 1)) |
| 517 | { |
| 518 | return ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH); |
| 519 | } |
| 520 | |
| 521 | int rc = decode_set_numeric_effecter_value_req( |
| 522 | request, payloadLength, &effecterId, &effecterDataSize, |
| 523 | reinterpret_cast<uint8_t*>(&effecterValue)); |
| 524 | |
| 525 | if (rc == PLDM_SUCCESS) |
| 526 | { |
| 527 | const pldm::utils::DBusHandler dBusIntf; |
| 528 | rc = platform_numeric_effecter::setNumericEffecterValueHandler< |
| 529 | pldm::utils::DBusHandler, Handler>(dBusIntf, *this, effecterId, |
| 530 | effecterDataSize, effecterValue, |
| 531 | sizeof(effecterValue)); |
| 532 | } |
| 533 | |
| 534 | return ccOnlyResponse(request, rc); |
| 535 | } |
| 536 | |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 537 | void Handler::generateTerminusLocatorPDR(Repo& repo) |
| 538 | { |
| 539 | std::vector<uint8_t> pdrBuffer(sizeof(pldm_terminus_locator_pdr)); |
| 540 | |
| 541 | auto pdr = reinterpret_cast<pldm_terminus_locator_pdr*>(pdrBuffer.data()); |
| 542 | |
| 543 | pdr->hdr.record_handle = 0; |
| 544 | pdr->hdr.version = 1; |
| 545 | pdr->hdr.type = PLDM_TERMINUS_LOCATOR_PDR; |
| 546 | pdr->hdr.record_change_num = 0; |
| 547 | pdr->hdr.length = sizeof(pldm_terminus_locator_pdr) - sizeof(pldm_pdr_hdr); |
| 548 | pdr->terminus_handle = BmcPldmTerminusHandle; |
| 549 | pdr->validity = PLDM_TL_PDR_VALID; |
| 550 | pdr->tid = BmcTerminusId; |
| 551 | pdr->container_id = 0x0; |
| 552 | pdr->terminus_locator_type = PLDM_TERMINUS_LOCATOR_TYPE_MCTP_EID; |
| 553 | pdr->terminus_locator_value_size = |
| 554 | sizeof(pldm_terminus_locator_type_mctp_eid); |
| 555 | auto locatorValue = reinterpret_cast<pldm_terminus_locator_type_mctp_eid*>( |
| 556 | pdr->terminus_locator_value); |
| 557 | locatorValue->eid = BmcMctpEid; |
| 558 | |
| 559 | PdrEntry pdrEntry{}; |
| 560 | pdrEntry.data = pdrBuffer.data(); |
| 561 | pdrEntry.size = pdrBuffer.size(); |
| 562 | repo.addRecord(pdrEntry); |
| 563 | } |
George Liu | 362c18d | 2020-05-14 09:46:36 +0800 | [diff] [blame] | 564 | |
| 565 | Response Handler::getStateSensorReadings(const pldm_msg* request, |
| 566 | size_t payloadLength) |
| 567 | { |
| 568 | uint16_t sensorId{}; |
| 569 | bitfield8_t sensorRearm{}; |
| 570 | uint8_t reserved{}; |
| 571 | |
| 572 | if (payloadLength != PLDM_GET_SENSOR_READING_REQ_BYTES) |
| 573 | { |
| 574 | return ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH); |
| 575 | } |
| 576 | |
| 577 | int rc = decode_get_state_sensor_readings_req( |
| 578 | request, payloadLength, &sensorId, &sensorRearm, &reserved); |
| 579 | |
| 580 | if (rc != PLDM_SUCCESS) |
| 581 | { |
| 582 | return ccOnlyResponse(request, rc); |
| 583 | } |
| 584 | |
| 585 | // 0x01 to 0x08 |
| 586 | uint8_t sensorRearmCout = getBitfieldCount(sensorRearm); |
| 587 | std::vector<get_sensor_state_field> stateField(sensorRearmCout); |
| 588 | uint8_t comSensorCnt{}; |
| 589 | const pldm::utils::DBusHandler dBusIntf; |
| 590 | rc = platform_state_sensor::getStateSensorReadingsHandler< |
| 591 | pldm::utils::DBusHandler, Handler>( |
| 592 | dBusIntf, *this, sensorId, sensorRearmCout, comSensorCnt, stateField); |
| 593 | |
| 594 | if (rc != PLDM_SUCCESS) |
| 595 | { |
| 596 | return ccOnlyResponse(request, rc); |
| 597 | } |
| 598 | |
| 599 | Response response(sizeof(pldm_msg_hdr) + |
| 600 | PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES + |
| 601 | sizeof(get_sensor_state_field) * comSensorCnt); |
| 602 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
| 603 | rc = encode_get_state_sensor_readings_resp(request->hdr.instance_id, rc, |
| 604 | comSensorCnt, stateField.data(), |
| 605 | responsePtr); |
| 606 | if (rc != PLDM_SUCCESS) |
| 607 | { |
| 608 | return ccOnlyResponse(request, rc); |
| 609 | } |
| 610 | |
| 611 | return response; |
| 612 | } |
| 613 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 614 | } // namespace platform |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 615 | } // namespace responder |
| 616 | } // namespace pldm |