blob: 7587a166eb26f7704165e27933b9b521d0db3833 [file] [log] [blame]
Deepak Kodihalli557dfb02019-05-12 13:11:17 +05301#include "platform.hpp"
2
Tom Josephb70a1962020-07-13 12:56:31 +05303#include "common/types.hpp"
Deepak Kodihallid130e1a2020-06-17 05:55:32 -05004#include "common/utils.hpp"
Tom Josephc4959c32020-04-20 19:50:16 +05305#include "event_parser.hpp"
Sampa Misra12afe112020-05-25 11:40:44 -05006#include "pdr.hpp"
George Liu456c9a22020-01-13 11:36:22 +08007#include "pdr_numeric_effecter.hpp"
George Liua2870722020-02-11 11:09:30 +08008#include "pdr_state_effecter.hpp"
George Liuadbe1722020-05-09 19:20:19 +08009#include "pdr_state_sensor.hpp"
George Liu362c18d2020-05-14 09:46:36 +080010#include "pdr_utils.hpp"
George Liueccb0c52020-01-14 11:09:56 +080011#include "platform_numeric_effecter.hpp"
George Liu0d7aca82020-03-30 15:01:36 +080012#include "platform_state_effecter.hpp"
George Liu362c18d2020-05-14 09:46:36 +080013#include "platform_state_sensor.hpp"
Sagar Srinivas90314a32023-10-17 10:38:03 -050014#include "pldmd/dbus_impl_requester.hpp"
15#include "pldmd/handler.hpp"
16#include "requester/handler.hpp"
George Liu83409572019-12-24 18:42:54 +080017
George Liuc453e162022-12-21 17:16:23 +080018#include <libpldm/entity.h>
19#include <libpldm/state_set.h>
Manojkiran Edacc5f1582021-09-29 17:03:06 +053020
Riya Dixit49cfb132023-03-02 04:26:53 -060021#include <phosphor-logging/lg2.hpp>
22
23PHOSPHOR_LOG2_USING;
24
Brad Bishop5079ac42021-08-19 18:35:06 -040025using namespace pldm::utils;
26using namespace pldm::responder::pdr;
27using namespace pldm::responder::pdr_utils;
28
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053029namespace pldm
30{
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053031namespace responder
32{
Sampa Misraa2fa0702019-05-31 01:28:55 -050033namespace platform
34{
Deepak Kodihallic682fe22020-03-04 00:42:54 -060035using InternalFailure =
36 sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
37
George Liu1ec85d42020-02-12 16:05:32 +080038static const Json empty{};
39
George Liua2870722020-02-11 11:09:30 +080040void Handler::addDbusObjMaps(
George Liuadbe1722020-05-09 19:20:19 +080041 uint16_t id,
42 std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> dbusObj,
43 TypeId typeId)
George Liu1ec85d42020-02-12 16:05:32 +080044{
George Liuadbe1722020-05-09 19:20:19 +080045 if (typeId == TypeId::PLDM_SENSOR_ID)
46 {
47 sensorDbusObjMaps.emplace(id, dbusObj);
48 }
49 else
50 {
51 effecterDbusObjMaps.emplace(id, dbusObj);
52 }
George Liu1ec85d42020-02-12 16:05:32 +080053}
54
George Liua2870722020-02-11 11:09:30 +080055const std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>&
George Liuadbe1722020-05-09 19:20:19 +080056 Handler::getDbusObjMaps(uint16_t id, TypeId typeId) const
George Liu1ec85d42020-02-12 16:05:32 +080057{
George Liuadbe1722020-05-09 19:20:19 +080058 if (typeId == TypeId::PLDM_SENSOR_ID)
59 {
60 return sensorDbusObjMaps.at(id);
61 }
62 else
63 {
64 return effecterDbusObjMaps.at(id);
65 }
George Liu1ec85d42020-02-12 16:05:32 +080066}
67
George Liu36e81352020-07-01 14:40:30 +080068void Handler::generate(const pldm::utils::DBusHandler& dBusIntf,
69 const std::string& dir, Repo& repo)
Deepak Kodihallic682fe22020-03-04 00:42:54 -060070{
Deepak Kodihallic6e49c42020-07-01 03:39:27 -050071 if (!fs::exists(dir))
72 {
73 return;
74 }
75
Deepak Kodihallic682fe22020-03-04 00:42:54 -060076 // A map of PDR type to a lambda that handles creation of that PDR type.
77 // The lambda essentially would parse the platform specific PDR JSONs to
78 // generate the PDR structures. This function iterates through the map to
79 // invoke all lambdas, so that all PDR types can be created.
George Liua2870722020-02-11 11:09:30 +080080
Patrick Williamsa6756622023-10-20 11:19:15 -050081 const std::map<Type, generatePDR> generateHandlers = {
82 {PLDM_STATE_EFFECTER_PDR,
83 [this](const DBusHandler& dBusIntf, const auto& json,
84 RepoInterface& repo) {
Patrick Williams6da4f912023-05-10 07:50:53 -050085 pdr_state_effecter::generateStateEffecterPDR<pldm::utils::DBusHandler,
86 Handler>(dBusIntf, json,
87 *this, repo);
Patrick Williamsa6756622023-10-20 11:19:15 -050088 }},
89 {PLDM_NUMERIC_EFFECTER_PDR,
90 [this](const DBusHandler& dBusIntf, const auto& json,
91 RepoInterface& repo) {
Patrick Williams6da4f912023-05-10 07:50:53 -050092 pdr_numeric_effecter::generateNumericEffecterPDR<
93 pldm::utils::DBusHandler, Handler>(dBusIntf, json, *this, repo);
Patrick Williamsa6756622023-10-20 11:19:15 -050094 }},
George Liuadbe1722020-05-09 19:20:19 +080095 {PLDM_STATE_SENSOR_PDR, [this](const DBusHandler& dBusIntf,
96 const auto& json, RepoInterface& repo) {
Patrick Williamsa6756622023-10-20 11:19:15 -050097 pdr_state_sensor::generateStateSensorPDR<pldm::utils::DBusHandler,
98 Handler>(dBusIntf, json, *this,
99 repo);
100 }}};
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600101
102 Type pdrType{};
103 for (const auto& dirEntry : fs::directory_iterator(dir))
104 {
105 try
106 {
107 auto json = readJson(dirEntry.path().string());
108 if (!json.empty())
109 {
George Liu1ec85d42020-02-12 16:05:32 +0800110 auto effecterPDRs = json.value("effecterPDRs", empty);
111 for (const auto& effecter : effecterPDRs)
112 {
113 pdrType = effecter.value("pdrType", 0);
George Liu36e81352020-07-01 14:40:30 +0800114 generateHandlers.at(pdrType)(dBusIntf, effecter, repo);
George Liu1ec85d42020-02-12 16:05:32 +0800115 }
George Liuadbe1722020-05-09 19:20:19 +0800116
117 auto sensorPDRs = json.value("sensorPDRs", empty);
118 for (const auto& sensor : sensorPDRs)
119 {
120 pdrType = sensor.value("pdrType", 0);
121 generateHandlers.at(pdrType)(dBusIntf, sensor, repo);
122 }
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600123 }
124 }
125 catch (const InternalFailure& e)
126 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600127 error(
128 "PDR config directory does not exist or empty, TYPE= {PDR_TYPE} PATH={DIR_PATH} ERROR={ERR_EXCEP}",
129 "PDR_TYPE", pdrType, "DIR_PATH", dirEntry.path().string(),
130 "ERR_EXCEP", e.what());
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600131 }
132 catch (const Json::exception& e)
133 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600134 error(
135 "Failed parsing PDR JSON file, TYPE={PDR_TYPE} ERROR={ERR_EXCEP}",
136 "PDR_TYPE", pdrType, "ERR_EXCEP", e.what());
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600137 pldm::utils::reportError(
138 "xyz.openbmc_project.bmc.pldm.InternalFailure");
139 }
140 catch (const std::exception& e)
141 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600142 error(
143 "Failed parsing PDR JSON file, TYPE= {PDR_TYPE} ERROR={ERR_EXCEP}",
144 "PDR_TYPE", pdrType, "ERR_EXCEP", e.what());
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600145 pldm::utils::reportError(
146 "xyz.openbmc_project.bmc.pldm.InternalFailure");
147 }
148 }
149}
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530150
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600151Response Handler::getPDR(const pldm_msg* request, size_t payloadLength)
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530152{
Pavithra Barithaya99854a72021-09-29 06:58:11 -0500153 if (hostPDRHandler)
154 {
155 if (hostPDRHandler->isHostUp() && oemPlatformHandler != nullptr)
156 {
157 auto rc = oemPlatformHandler->checkBMCState();
158 if (rc != PLDM_SUCCESS)
159 {
160 return ccOnlyResponse(request, PLDM_ERROR_NOT_READY);
161 }
162 }
163 }
164
165 // Build FRU table if not built, since entity association PDR's
166 // are built when the FRU table is constructed.
Tom Joseph33e9c7e2020-06-11 22:09:52 +0530167 if (fruHandler)
168 {
169 fruHandler->buildFRUTable();
170 }
171
George Liud680ae02020-07-17 09:11:14 +0800172 if (!pdrCreated)
173 {
174 generateTerminusLocatorPDR(pdrRepo);
175 generate(*dBusIntf, pdrJsonsDir, pdrRepo);
Sagar Srinivas78a225a2020-08-27 00:52:20 -0500176 if (oemPlatformHandler != nullptr)
177 {
178 oemPlatformHandler->buildOEMPDR(pdrRepo);
179 }
180
George Liud680ae02020-07-17 09:11:14 +0800181 pdrCreated = true;
George Liu5eed8e52020-12-18 11:24:37 +0800182
183 if (dbusToPLDMEventHandler)
184 {
Sampa Misra5fb37d52021-03-06 07:26:00 -0600185 deferredGetPDREvent = std::make_unique<sdeventplus::source::Defer>(
186 event,
187 std::bind(std::mem_fn(&pldm::responder::platform::Handler::
188 _processPostGetPDRActions),
189 this, std::placeholders::_1));
George Liu5eed8e52020-12-18 11:24:37 +0800190 }
George Liud680ae02020-07-17 09:11:14 +0800191 }
192
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530193 Response response(sizeof(pldm_msg_hdr) + PLDM_GET_PDR_MIN_RESP_BYTES, 0);
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530194
195 if (payloadLength != PLDM_GET_PDR_REQ_BYTES)
196 {
George Liufb8611d2019-12-06 10:14:15 +0800197 return CmdHandler::ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH);
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530198 }
199
200 uint32_t recordHandle{};
201 uint32_t dataTransferHandle{};
202 uint8_t transferOpFlag{};
203 uint16_t reqSizeBytes{};
204 uint16_t recordChangeNum{};
205
George Liufb8611d2019-12-06 10:14:15 +0800206 auto rc = decode_get_pdr_req(request, payloadLength, &recordHandle,
207 &dataTransferHandle, &transferOpFlag,
208 &reqSizeBytes, &recordChangeNum);
209 if (rc != PLDM_SUCCESS)
210 {
211 return CmdHandler::ccOnlyResponse(request, rc);
212 }
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530213
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530214 uint16_t respSizeBytes{};
215 uint8_t* recordData = nullptr;
216 try
217 {
George Liue53193f2020-02-24 09:23:26 +0800218 pdr_utils::PdrEntry e;
219 auto record = pdr::getRecordByHandle(pdrRepo, recordHandle, e);
220 if (record == NULL)
221 {
222 return CmdHandler::ccOnlyResponse(
223 request, PLDM_PLATFORM_INVALID_RECORD_HANDLE);
224 }
225
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530226 if (reqSizeBytes)
227 {
George Liue53193f2020-02-24 09:23:26 +0800228 respSizeBytes = e.size;
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530229 if (respSizeBytes > reqSizeBytes)
230 {
231 respSizeBytes = reqSizeBytes;
232 }
George Liue53193f2020-02-24 09:23:26 +0800233 recordData = e.data;
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530234 }
235 response.resize(sizeof(pldm_msg_hdr) + PLDM_GET_PDR_MIN_RESP_BYTES +
236 respSizeBytes,
237 0);
Manojkiran Eda31a78442021-09-12 15:18:25 +0530238 auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
Deepak Kodihalli22b5a7d2020-03-17 23:28:41 -0500239 rc = encode_get_pdr_resp(
240 request->hdr.instance_id, PLDM_SUCCESS, e.handle.nextRecordHandle,
241 0, PLDM_START_AND_END, respSizeBytes, recordData, 0, responsePtr);
George Liufb8611d2019-12-06 10:14:15 +0800242 if (rc != PLDM_SUCCESS)
243 {
244 return ccOnlyResponse(request, rc);
245 }
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530246 }
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530247 catch (const std::exception& e)
248 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600249 error("Error accessing PDR, HANDLE={REC_HANDLE} ERROR={ERR_EXCEP}",
250 "REC_HANDLE", recordHandle, "ERR_EXCEP", e.what());
George Liufb8611d2019-12-06 10:14:15 +0800251 return CmdHandler::ccOnlyResponse(request, PLDM_ERROR);
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530252 }
253 return response;
254}
255
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600256Response Handler::setStateEffecterStates(const pldm_msg* request,
257 size_t payloadLength)
Sampa Misraa2fa0702019-05-31 01:28:55 -0500258{
259 Response response(
260 sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES, 0);
261 auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
262 uint16_t effecterId;
263 uint8_t compEffecterCnt;
264 constexpr auto maxCompositeEffecterCnt = 8;
265 std::vector<set_effecter_state_field> stateField(maxCompositeEffecterCnt,
266 {0, 0});
267
268 if ((payloadLength > PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES) ||
269 (payloadLength < sizeof(effecterId) + sizeof(compEffecterCnt) +
270 sizeof(set_effecter_state_field)))
271 {
George Liufb8611d2019-12-06 10:14:15 +0800272 return CmdHandler::ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH);
Sampa Misraa2fa0702019-05-31 01:28:55 -0500273 }
274
275 int rc = decode_set_state_effecter_states_req(request, payloadLength,
276 &effecterId, &compEffecterCnt,
277 stateField.data());
278
George Liufb8611d2019-12-06 10:14:15 +0800279 if (rc != PLDM_SUCCESS)
Sampa Misraa2fa0702019-05-31 01:28:55 -0500280 {
George Liufb8611d2019-12-06 10:14:15 +0800281 return CmdHandler::ccOnlyResponse(request, rc);
Sampa Misraa2fa0702019-05-31 01:28:55 -0500282 }
283
George Liufb8611d2019-12-06 10:14:15 +0800284 stateField.resize(compEffecterCnt);
285 const pldm::utils::DBusHandler dBusIntf;
Sampa Misraaea5dde2020-08-31 08:33:47 -0500286 uint16_t entityType{};
287 uint16_t entityInstance{};
288 uint16_t stateSetId{};
289
290 if (isOemStateEffecter(*this, effecterId, compEffecterCnt, entityType,
291 entityInstance, stateSetId) &&
Manojkiran Eda321804e2022-03-03 12:36:54 +0530292 oemPlatformHandler != nullptr &&
293 !effecterDbusObjMaps.contains(effecterId))
Sampa Misraaea5dde2020-08-31 08:33:47 -0500294 {
Sampa Misra3a0e3b92020-10-21 05:58:00 -0500295 rc = oemPlatformHandler->oemSetStateEffecterStatesHandler(
Varsha Kaverappa3fbd39e2020-09-28 01:40:22 -0500296 entityType, entityInstance, stateSetId, compEffecterCnt, stateField,
297 effecterId);
Sampa Misraaea5dde2020-08-31 08:33:47 -0500298 }
299 else
300 {
301 rc = platform_state_effecter::setStateEffecterStatesHandler<
302 pldm::utils::DBusHandler, Handler>(dBusIntf, *this, effecterId,
303 stateField);
304 }
George Liufb8611d2019-12-06 10:14:15 +0800305 if (rc != PLDM_SUCCESS)
306 {
307 return CmdHandler::ccOnlyResponse(request, rc);
308 }
309
310 rc = encode_set_state_effecter_states_resp(request->hdr.instance_id, rc,
311 responsePtr);
312 if (rc != PLDM_SUCCESS)
313 {
314 return ccOnlyResponse(request, rc);
315 }
316
Sampa Misraa2fa0702019-05-31 01:28:55 -0500317 return response;
318}
319
Tom Joseph56e45c52020-03-16 10:01:45 +0530320Response Handler::platformEventMessage(const pldm_msg* request,
321 size_t payloadLength)
322{
323 uint8_t formatVersion{};
324 uint8_t tid{};
325 uint8_t eventClass{};
326 size_t offset{};
327
328 auto rc = decode_platform_event_message_req(
329 request, payloadLength, &formatVersion, &tid, &eventClass, &offset);
330 if (rc != PLDM_SUCCESS)
331 {
332 return CmdHandler::ccOnlyResponse(request, rc);
333 }
334
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -0500335 if (eventClass == PLDM_HEARTBEAT_TIMER_ELAPSED_EVENT)
Tom Joseph56e45c52020-03-16 10:01:45 +0530336 {
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -0500337 rc = PLDM_SUCCESS;
Sagar Srinivas79669c92021-04-28 15:43:30 -0500338 if (oemPlatformHandler)
339 {
340 oemPlatformHandler->resetWatchDogTimer();
341 }
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -0500342 }
343 else
344 {
345 try
Tom Joseph56e45c52020-03-16 10:01:45 +0530346 {
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -0500347 const auto& handlers = eventHandlers.at(eventClass);
348 for (const auto& handler : handlers)
Tom Joseph56e45c52020-03-16 10:01:45 +0530349 {
Patrick Williams6da4f912023-05-10 07:50:53 -0500350 auto rc = handler(request, payloadLength, formatVersion, tid,
351 offset);
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -0500352 if (rc != PLDM_SUCCESS)
353 {
354 return CmdHandler::ccOnlyResponse(request, rc);
355 }
Tom Joseph56e45c52020-03-16 10:01:45 +0530356 }
357 }
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -0500358 catch (const std::out_of_range& e)
359 {
Kamalkumar Patel58cbcaf2023-10-06 03:48:25 -0500360 error("Error in handling platform event msg: {ERROR}", "ERROR", e);
Sagar Srinivasa6a8ccd2021-04-01 07:58:33 -0500361 return CmdHandler::ccOnlyResponse(request, PLDM_ERROR_INVALID_DATA);
362 }
Tom Joseph56e45c52020-03-16 10:01:45 +0530363 }
Tom Joseph56e45c52020-03-16 10:01:45 +0530364 Response response(
365 sizeof(pldm_msg_hdr) + PLDM_PLATFORM_EVENT_MESSAGE_RESP_BYTES, 0);
366 auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
367
368 rc = encode_platform_event_message_resp(request->hdr.instance_id, rc,
369 PLDM_EVENT_NO_LOGGING, responsePtr);
370 if (rc != PLDM_SUCCESS)
371 {
372 return ccOnlyResponse(request, rc);
373 }
374
375 return response;
376}
377
378int Handler::sensorEvent(const pldm_msg* request, size_t payloadLength,
Tom Josephc4959c32020-04-20 19:50:16 +0530379 uint8_t /*formatVersion*/, uint8_t tid,
Tom Joseph56e45c52020-03-16 10:01:45 +0530380 size_t eventDataOffset)
381{
382 uint16_t sensorId{};
383 uint8_t eventClass{};
384 size_t eventClassDataOffset{};
Patrick Williams6da4f912023-05-10 07:50:53 -0500385 auto eventData = reinterpret_cast<const uint8_t*>(request->payload) +
386 eventDataOffset;
Tom Joseph56e45c52020-03-16 10:01:45 +0530387 auto eventDataSize = payloadLength - eventDataOffset;
388
389 auto rc = decode_sensor_event_data(eventData, eventDataSize, &sensorId,
390 &eventClass, &eventClassDataOffset);
391 if (rc != PLDM_SUCCESS)
392 {
393 return rc;
394 }
395
Zahed Hossain75330f32020-03-24 02:15:03 -0500396 auto eventClassData = reinterpret_cast<const uint8_t*>(request->payload) +
397 eventDataOffset + eventClassDataOffset;
Patrick Williams6da4f912023-05-10 07:50:53 -0500398 auto eventClassDataSize = payloadLength - eventDataOffset -
399 eventClassDataOffset;
Zahed Hossain75330f32020-03-24 02:15:03 -0500400
Tom Joseph56e45c52020-03-16 10:01:45 +0530401 if (eventClass == PLDM_STATE_SENSOR_STATE)
402 {
403 uint8_t sensorOffset{};
404 uint8_t eventState{};
405 uint8_t previousEventState{};
406
Zahed Hossain75330f32020-03-24 02:15:03 -0500407 rc = decode_state_sensor_data(eventClassData, eventClassDataSize,
Tom Joseph56e45c52020-03-16 10:01:45 +0530408 &sensorOffset, &eventState,
409 &previousEventState);
Zahed Hossain75330f32020-03-24 02:15:03 -0500410 if (rc != PLDM_SUCCESS)
411 {
412 return PLDM_ERROR;
413 }
414
Chicago Duanfe4d88b2020-06-12 16:44:13 +0800415 // Emitting state sensor event signal
416 emitStateSensorEventSignal(tid, sensorId, sensorOffset, eventState,
417 previousEventState);
418
Tom Josephc4959c32020-04-20 19:50:16 +0530419 // If there are no HOST PDR's, there is no further action
420 if (hostPDRHandler == NULL)
421 {
422 return PLDM_SUCCESS;
423 }
424
425 // Handle PLDM events for which PDR is available
426 SensorEntry sensorEntry{tid, sensorId};
Tom Josephb70a1962020-07-13 12:56:31 +0530427
428 pldm::pdr::EntityInfo entityInfo{};
429 pldm::pdr::CompositeSensorStates compositeSensorStates{};
430
Tom Josephc4959c32020-04-20 19:50:16 +0530431 try
432 {
Tom Josephb70a1962020-07-13 12:56:31 +0530433 std::tie(entityInfo, compositeSensorStates) =
Tom Josephc4959c32020-04-20 19:50:16 +0530434 hostPDRHandler->lookupSensorInfo(sensorEntry);
Tom Josephc4959c32020-04-20 19:50:16 +0530435 }
Kamalkumar Patel58cbcaf2023-10-06 03:48:25 -0500436 catch (const std::out_of_range&)
Tom Josephc4959c32020-04-20 19:50:16 +0530437 {
Tom Josephb70a1962020-07-13 12:56:31 +0530438 // If there is no mapping for tid, sensorId combination, try
439 // PLDM_TID_RESERVED, sensorId for terminus that is yet to
440 // implement TL PDR.
441 try
442 {
443 sensorEntry.terminusID = PLDM_TID_RESERVED;
444 std::tie(entityInfo, compositeSensorStates) =
445 hostPDRHandler->lookupSensorInfo(sensorEntry);
446 }
447 // If there is no mapping for events return PLDM_SUCCESS
Kamalkumar Patel58cbcaf2023-10-06 03:48:25 -0500448 catch (const std::out_of_range&)
Tom Josephb70a1962020-07-13 12:56:31 +0530449 {
450 return PLDM_SUCCESS;
451 }
Zahed Hossain75330f32020-03-24 02:15:03 -0500452 }
Tom Josephb70a1962020-07-13 12:56:31 +0530453
454 if (sensorOffset >= compositeSensorStates.size())
455 {
456 return PLDM_ERROR_INVALID_DATA;
457 }
458
459 const auto& possibleStates = compositeSensorStates[sensorOffset];
460 if (possibleStates.find(eventState) == possibleStates.end())
461 {
462 return PLDM_ERROR_INVALID_DATA;
463 }
464
465 const auto& [containerId, entityType, entityInstance] = entityInfo;
466 events::StateSensorEntry stateSensorEntry{containerId, entityType,
467 entityInstance, sensorOffset};
Pavithra Barithaya3aec9972020-12-14 01:55:44 -0600468 return hostPDRHandler->handleStateSensorEvent(stateSensorEntry,
469 eventState);
Tom Joseph56e45c52020-03-16 10:01:45 +0530470 }
471 else
472 {
473 return PLDM_ERROR_INVALID_DATA;
474 }
475
476 return PLDM_SUCCESS;
477}
478
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500479int Handler::pldmPDRRepositoryChgEvent(const pldm_msg* request,
480 size_t payloadLength,
Manojkiran Eda3ca40452021-10-04 22:51:37 +0530481 uint8_t /*formatVersion*/, uint8_t tid,
482 size_t eventDataOffset)
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500483{
484 uint8_t eventDataFormat{};
485 uint8_t numberOfChangeRecords{};
486 size_t dataOffset{};
487
Patrick Williams6da4f912023-05-10 07:50:53 -0500488 auto eventData = reinterpret_cast<const uint8_t*>(request->payload) +
489 eventDataOffset;
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500490 auto eventDataSize = payloadLength - eventDataOffset;
491
492 auto rc = decode_pldm_pdr_repository_chg_event_data(
493 eventData, eventDataSize, &eventDataFormat, &numberOfChangeRecords,
494 &dataOffset);
495 if (rc != PLDM_SUCCESS)
496 {
497 return rc;
498 }
499
500 PDRRecordHandles pdrRecordHandles;
Deepak Kodihalli7246e0c2020-07-08 06:40:18 -0500501
502 if (eventDataFormat == FORMAT_IS_PDR_TYPES)
503 {
504 return PLDM_ERROR_INVALID_DATA;
505 }
506
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500507 if (eventDataFormat == FORMAT_IS_PDR_HANDLES)
508 {
509 uint8_t eventDataOperation{};
510 uint8_t numberOfChangeEntries{};
511
512 auto changeRecordData = eventData + dataOffset;
513 auto changeRecordDataSize = eventDataSize - dataOffset;
514
515 while (changeRecordDataSize)
516 {
517 rc = decode_pldm_pdr_repository_change_record_data(
518 changeRecordData, changeRecordDataSize, &eventDataOperation,
519 &numberOfChangeEntries, &dataOffset);
520
521 if (rc != PLDM_SUCCESS)
522 {
523 return rc;
524 }
525
Pavithra Barithayaae5c97e2022-08-29 02:57:59 -0500526 if (eventDataOperation == PLDM_RECORDS_ADDED ||
527 eventDataOperation == PLDM_RECORDS_MODIFIED)
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500528 {
Pavithra Barithayaae5c97e2022-08-29 02:57:59 -0500529 if (eventDataOperation == PLDM_RECORDS_MODIFIED)
530 {
531 hostPDRHandler->isHostPdrModified = true;
532 }
533
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500534 rc = getPDRRecordHandles(
535 reinterpret_cast<const ChangeEntry*>(changeRecordData +
536 dataOffset),
537 changeRecordDataSize - dataOffset,
538 static_cast<size_t>(numberOfChangeEntries),
539 pdrRecordHandles);
540
541 if (rc != PLDM_SUCCESS)
542 {
543 return rc;
544 }
545 }
546
Patrick Williams6da4f912023-05-10 07:50:53 -0500547 changeRecordData += dataOffset +
548 (numberOfChangeEntries * sizeof(ChangeEntry));
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500549 changeRecordDataSize -=
550 dataOffset + (numberOfChangeEntries * sizeof(ChangeEntry));
551 }
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500552 }
Deepak Kodihalli7246e0c2020-07-08 06:40:18 -0500553 if (hostPDRHandler)
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500554 {
Manojkiran Eda3ca40452021-10-04 22:51:37 +0530555 // if we get a Repository change event with the eventDataFormat
556 // as REFRESH_ENTIRE_REPOSITORY, then delete all the PDR's that
557 // have the matched Terminus handle
558 if (eventDataFormat == REFRESH_ENTIRE_REPOSITORY)
559 {
560 // We cannot get the Repo change event from the Terminus
561 // that is not already added to the BMC repository
562
Pavithra Barithaya52aad392022-08-02 04:18:52 -0500563 for (auto it = hostPDRHandler->tlPDRInfo.cbegin();
564 it != hostPDRHandler->tlPDRInfo.cend();)
Manojkiran Eda3ca40452021-10-04 22:51:37 +0530565 {
Pavithra Barithaya52aad392022-08-02 04:18:52 -0500566 if (std::get<0>(it->second) == tid)
Manojkiran Eda3ca40452021-10-04 22:51:37 +0530567 {
568 pldm_pdr_remove_pdrs_by_terminus_handle(pdrRepo.getPdr(),
Pavithra Barithaya52aad392022-08-02 04:18:52 -0500569 it->first);
570 hostPDRHandler->tlPDRInfo.erase(it++);
571 }
572 else
573 {
574 ++it;
Manojkiran Eda3ca40452021-10-04 22:51:37 +0530575 }
576 }
577 }
Deepak Kodihalli7246e0c2020-07-08 06:40:18 -0500578 hostPDRHandler->fetchPDR(std::move(pdrRecordHandles));
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500579 }
580
581 return PLDM_SUCCESS;
582}
583
584int Handler::getPDRRecordHandles(const ChangeEntry* changeEntryData,
585 size_t changeEntryDataSize,
586 size_t numberOfChangeEntries,
587 PDRRecordHandles& pdrRecordHandles)
588{
589 if (numberOfChangeEntries > (changeEntryDataSize / sizeof(ChangeEntry)))
590 {
591 return PLDM_ERROR_INVALID_DATA;
592 }
593 for (size_t i = 0; i < numberOfChangeEntries; i++)
594 {
595 pdrRecordHandles.push_back(changeEntryData[i]);
596 }
597 return PLDM_SUCCESS;
598}
599
Archana Kakani6ece21fb2023-10-10 08:21:52 -0500600Response Handler::getNumericEffecterValue(const pldm_msg* request,
601 size_t payloadLength)
602{
603 if (payloadLength != PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES)
604 {
605 return ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH);
606 }
607
608 uint16_t effecterId{};
609 auto rc = decode_get_numeric_effecter_value_req(request, payloadLength,
610 &effecterId);
611 if (rc != PLDM_SUCCESS)
612 {
613 return ccOnlyResponse(request, rc);
614 }
615
616 const pldm::utils::DBusHandler dBusIntf;
617 uint8_t effecterDataSize{};
618 pldm::utils::PropertyValue dbusValue;
619 std::string propertyType;
620 using effecterOperationalState = uint8_t;
621 using completionCode = uint8_t;
622
623 rc = platform_numeric_effecter::getNumericEffecterData<
624 pldm::utils::DBusHandler, Handler>(
625 dBusIntf, *this, effecterId, effecterDataSize, propertyType, dbusValue);
626
627 if (rc != PLDM_SUCCESS)
628 {
629 return ccOnlyResponse(request, rc);
630 }
631
632 // Refer DSP0248_1.2.0.pdf (section 22.3, Table 48)
633 // Completion Code (uint8), Effecter Data Size(uint8), Effecter Operational
634 // State(uint8), PendingValue (uint8|sint8|uint16|sint16|uint32|sint32 )
635 // PresentValue (uint8|sint8|uint16|sint16|uint32|sint32 )
636 // Size of PendingValue and PresentValue calculated based on size is
637 // provided in effecter data size
638 size_t responsePayloadLength = sizeof(completionCode) +
639 sizeof(effecterDataSize) +
640 sizeof(effecterOperationalState) +
641 getEffecterDataSize(effecterDataSize) +
642 getEffecterDataSize(effecterDataSize);
643
644 Response response(responsePayloadLength + sizeof(pldm_msg_hdr));
645 auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
646
647 rc = platform_numeric_effecter::getNumericEffecterValueHandler(
648 propertyType, dbusValue, effecterDataSize, responsePtr,
649 responsePayloadLength, request->hdr.instance_id);
650
651 if (rc != PLDM_SUCCESS)
652 {
653 error(
654 "Reponse to GetNumericEffecterValue failed RC={RC} for EffectorId={EFFECTER_ID} ",
655 "RC", rc, "EFFECTER_ID", effecterId);
656 return ccOnlyResponse(request, rc);
657 }
658 return response;
659}
660
George Liueccb0c52020-01-14 11:09:56 +0800661Response Handler::setNumericEffecterValue(const pldm_msg* request,
662 size_t payloadLength)
663{
664 Response response(sizeof(pldm_msg_hdr) +
665 PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES);
666 uint16_t effecterId{};
667 uint8_t effecterDataSize{};
668 uint8_t effecterValue[4] = {};
669
670 if ((payloadLength > sizeof(effecterId) + sizeof(effecterDataSize) +
671 sizeof(union_effecter_data_size)) ||
672 (payloadLength < sizeof(effecterId) + sizeof(effecterDataSize) + 1))
673 {
674 return ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH);
675 }
676
677 int rc = decode_set_numeric_effecter_value_req(
Andrew Jeffery8fbf3cc2023-04-12 13:42:29 +0930678 request, payloadLength, &effecterId, &effecterDataSize, effecterValue);
George Liueccb0c52020-01-14 11:09:56 +0800679
680 if (rc == PLDM_SUCCESS)
681 {
682 const pldm::utils::DBusHandler dBusIntf;
683 rc = platform_numeric_effecter::setNumericEffecterValueHandler<
684 pldm::utils::DBusHandler, Handler>(dBusIntf, *this, effecterId,
685 effecterDataSize, effecterValue,
686 sizeof(effecterValue));
687 }
688
689 return ccOnlyResponse(request, rc);
690}
691
Sampa Misra12afe112020-05-25 11:40:44 -0500692void Handler::generateTerminusLocatorPDR(Repo& repo)
693{
694 std::vector<uint8_t> pdrBuffer(sizeof(pldm_terminus_locator_pdr));
695
696 auto pdr = reinterpret_cast<pldm_terminus_locator_pdr*>(pdrBuffer.data());
697
698 pdr->hdr.record_handle = 0;
699 pdr->hdr.version = 1;
700 pdr->hdr.type = PLDM_TERMINUS_LOCATOR_PDR;
701 pdr->hdr.record_change_num = 0;
702 pdr->hdr.length = sizeof(pldm_terminus_locator_pdr) - sizeof(pldm_pdr_hdr);
Manojkiran Edacc5f1582021-09-29 17:03:06 +0530703 pdr->terminus_handle = TERMINUS_HANDLE;
Sampa Misra12afe112020-05-25 11:40:44 -0500704 pdr->validity = PLDM_TL_PDR_VALID;
Manojkiran Edacc5f1582021-09-29 17:03:06 +0530705 pdr->tid = TERMINUS_ID;
Sampa Misra12afe112020-05-25 11:40:44 -0500706 pdr->container_id = 0x0;
707 pdr->terminus_locator_type = PLDM_TERMINUS_LOCATOR_TYPE_MCTP_EID;
708 pdr->terminus_locator_value_size =
709 sizeof(pldm_terminus_locator_type_mctp_eid);
710 auto locatorValue = reinterpret_cast<pldm_terminus_locator_type_mctp_eid*>(
711 pdr->terminus_locator_value);
712 locatorValue->eid = BmcMctpEid;
713
714 PdrEntry pdrEntry{};
715 pdrEntry.data = pdrBuffer.data();
716 pdrEntry.size = pdrBuffer.size();
717 repo.addRecord(pdrEntry);
Manojkiran Eda60e1fe92021-10-08 15:58:16 +0530718 if (hostPDRHandler)
719 {
720 hostPDRHandler->tlPDRInfo.insert_or_assign(
721 pdr->terminus_handle,
722 std::make_tuple(pdr->tid, locatorValue->eid, pdr->validity));
723 }
Sampa Misra12afe112020-05-25 11:40:44 -0500724}
George Liu362c18d2020-05-14 09:46:36 +0800725
726Response Handler::getStateSensorReadings(const pldm_msg* request,
727 size_t payloadLength)
728{
729 uint16_t sensorId{};
730 bitfield8_t sensorRearm{};
731 uint8_t reserved{};
732
Pavithra Barithaya87083f22023-04-17 01:27:49 -0500733 if (payloadLength != PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES)
George Liu362c18d2020-05-14 09:46:36 +0800734 {
735 return ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH);
736 }
737
738 int rc = decode_get_state_sensor_readings_req(
739 request, payloadLength, &sensorId, &sensorRearm, &reserved);
740
741 if (rc != PLDM_SUCCESS)
742 {
743 return ccOnlyResponse(request, rc);
744 }
745
746 // 0x01 to 0x08
George Liuc1230ca2021-08-03 16:06:50 +0800747 uint8_t sensorRearmCount = std::popcount(sensorRearm.byte);
Sampa Misraaea5dde2020-08-31 08:33:47 -0500748 std::vector<get_sensor_state_field> stateField(sensorRearmCount);
George Liu362c18d2020-05-14 09:46:36 +0800749 uint8_t comSensorCnt{};
750 const pldm::utils::DBusHandler dBusIntf;
Sampa Misraaea5dde2020-08-31 08:33:47 -0500751
752 uint16_t entityType{};
753 uint16_t entityInstance{};
754 uint16_t stateSetId{};
755
756 if (isOemStateSensor(*this, sensorId, sensorRearmCount, comSensorCnt,
757 entityType, entityInstance, stateSetId) &&
Manojkiran Eda321804e2022-03-03 12:36:54 +0530758 oemPlatformHandler != nullptr && !sensorDbusObjMaps.contains(sensorId))
Sampa Misraaea5dde2020-08-31 08:33:47 -0500759 {
760 rc = oemPlatformHandler->getOemStateSensorReadingsHandler(
761 entityType, entityInstance, stateSetId, comSensorCnt, stateField);
762 }
763 else
764 {
765 rc = platform_state_sensor::getStateSensorReadingsHandler<
766 pldm::utils::DBusHandler, Handler>(dBusIntf, *this, sensorId,
767 sensorRearmCount, comSensorCnt,
768 stateField);
769 }
George Liu362c18d2020-05-14 09:46:36 +0800770
771 if (rc != PLDM_SUCCESS)
772 {
773 return ccOnlyResponse(request, rc);
774 }
775
776 Response response(sizeof(pldm_msg_hdr) +
777 PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES +
778 sizeof(get_sensor_state_field) * comSensorCnt);
779 auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
780 rc = encode_get_state_sensor_readings_resp(request->hdr.instance_id, rc,
781 comSensorCnt, stateField.data(),
782 responsePtr);
783 if (rc != PLDM_SUCCESS)
784 {
785 return ccOnlyResponse(request, rc);
786 }
787
788 return response;
789}
790
Pavithra Barithaya99854a72021-09-29 06:58:11 -0500791void Handler::_processPostGetPDRActions(sdeventplus::source::EventBase&
792 /*source */)
Sampa Misra5fb37d52021-03-06 07:26:00 -0600793{
794 deferredGetPDREvent.reset();
795 dbusToPLDMEventHandler->listenSensorEvent(pdrRepo, sensorDbusObjMaps);
796}
797
Sampa Misraaea5dde2020-08-31 08:33:47 -0500798bool isOemStateSensor(Handler& handler, uint16_t sensorId,
799 uint8_t sensorRearmCount, uint8_t& compSensorCnt,
800 uint16_t& entityType, uint16_t& entityInstance,
801 uint16_t& stateSetId)
802{
803 pldm_state_sensor_pdr* pdr = nullptr;
804
805 std::unique_ptr<pldm_pdr, decltype(&pldm_pdr_destroy)> stateSensorPdrRepo(
806 pldm_pdr_init(), pldm_pdr_destroy);
Andrew Jefferyacb20292023-06-30 11:47:44 +0930807 if (!stateSensorPdrRepo)
808 {
809 error("Failed to instantiate state sensor PDR repository");
810 return false;
811 }
Sampa Misraaea5dde2020-08-31 08:33:47 -0500812 Repo stateSensorPDRs(stateSensorPdrRepo.get());
813 getRepoByType(handler.getRepo(), stateSensorPDRs, PLDM_STATE_SENSOR_PDR);
814 if (stateSensorPDRs.empty())
815 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600816 error("Failed to get record by PDR type");
Sampa Misraaea5dde2020-08-31 08:33:47 -0500817 return false;
818 }
819
820 PdrEntry pdrEntry{};
821 auto pdrRecord = stateSensorPDRs.getFirstRecord(pdrEntry);
822 while (pdrRecord)
823 {
824 pdr = reinterpret_cast<pldm_state_sensor_pdr*>(pdrEntry.data);
825 assert(pdr != NULL);
826 if (pdr->sensor_id != sensorId)
827 {
828 pdr = nullptr;
829 pdrRecord = stateSensorPDRs.getNextRecord(pdrRecord, pdrEntry);
830 continue;
831 }
832 auto tmpEntityType = pdr->entity_type;
833 auto tmpEntityInstance = pdr->entity_instance;
834 auto tmpCompSensorCnt = pdr->composite_sensor_count;
835 auto tmpPossibleStates =
836 reinterpret_cast<state_sensor_possible_states*>(
837 pdr->possible_states);
838 auto tmpStateSetId = tmpPossibleStates->state_set_id;
839
840 if (sensorRearmCount > tmpCompSensorCnt)
841 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600842 error(
843 "The requester sent wrong sensorRearm count for the sensor, SENSOR_ID={SENSOR_ID} SENSOR_REARM_COUNT={SENSOR_REARM_CNT}",
844 "SENSOR_ID", sensorId, "SENSOR_REARM_CNT",
845 (uint16_t)sensorRearmCount);
Sampa Misraaea5dde2020-08-31 08:33:47 -0500846 break;
847 }
848
849 if ((tmpEntityType >= PLDM_OEM_ENTITY_TYPE_START &&
850 tmpEntityType <= PLDM_OEM_ENTITY_TYPE_END) ||
851 (tmpStateSetId >= PLDM_OEM_STATE_SET_ID_START &&
852 tmpStateSetId < PLDM_OEM_STATE_SET_ID_END))
853 {
854 entityType = tmpEntityType;
855 entityInstance = tmpEntityInstance;
856 stateSetId = tmpStateSetId;
857 compSensorCnt = tmpCompSensorCnt;
858 return true;
859 }
860 else
861 {
862 return false;
863 }
864 }
865 return false;
866}
867
868bool isOemStateEffecter(Handler& handler, uint16_t effecterId,
869 uint8_t compEffecterCnt, uint16_t& entityType,
870 uint16_t& entityInstance, uint16_t& stateSetId)
871{
872 pldm_state_effecter_pdr* pdr = nullptr;
873
874 std::unique_ptr<pldm_pdr, decltype(&pldm_pdr_destroy)> stateEffecterPdrRepo(
875 pldm_pdr_init(), pldm_pdr_destroy);
Andrew Jefferyacb20292023-06-30 11:47:44 +0930876 if (!stateEffecterPdrRepo)
877 {
878 error("Failed to instantiate state effecter PDR repository");
879 return false;
880 }
Sampa Misraaea5dde2020-08-31 08:33:47 -0500881 Repo stateEffecterPDRs(stateEffecterPdrRepo.get());
882 getRepoByType(handler.getRepo(), stateEffecterPDRs,
883 PLDM_STATE_EFFECTER_PDR);
884 if (stateEffecterPDRs.empty())
885 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600886 error("Failed to get record by PDR type");
Sampa Misraaea5dde2020-08-31 08:33:47 -0500887 return false;
888 }
889
890 PdrEntry pdrEntry{};
891 auto pdrRecord = stateEffecterPDRs.getFirstRecord(pdrEntry);
892 while (pdrRecord)
893 {
894 pdr = reinterpret_cast<pldm_state_effecter_pdr*>(pdrEntry.data);
895 assert(pdr != NULL);
896 if (pdr->effecter_id != effecterId)
897 {
898 pdr = nullptr;
899 pdrRecord = stateEffecterPDRs.getNextRecord(pdrRecord, pdrEntry);
900 continue;
901 }
902
903 auto tmpEntityType = pdr->entity_type;
904 auto tmpEntityInstance = pdr->entity_instance;
905 auto tmpPossibleStates =
906 reinterpret_cast<state_effecter_possible_states*>(
907 pdr->possible_states);
908 auto tmpStateSetId = tmpPossibleStates->state_set_id;
909
910 if (compEffecterCnt > pdr->composite_effecter_count)
911 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600912 error(
913 "The requester sent wrong composite effecter count for the effecter, EFFECTER_ID={EFFECTER_ID} COMP_EFF_CNT={COMP_EFF_CNT}",
914 "EFFECTER_ID", effecterId, "COMP_EFF_CNT",
915 (uint16_t)compEffecterCnt);
Sampa Misraaea5dde2020-08-31 08:33:47 -0500916 return false;
917 }
918
919 if ((tmpEntityType >= PLDM_OEM_ENTITY_TYPE_START &&
920 tmpEntityType <= PLDM_OEM_ENTITY_TYPE_END) ||
921 (tmpStateSetId >= PLDM_OEM_STATE_SET_ID_START &&
922 tmpStateSetId < PLDM_OEM_STATE_SET_ID_END))
923 {
924 entityType = tmpEntityType;
925 entityInstance = tmpEntityInstance;
926 stateSetId = tmpStateSetId;
927 return true;
928 }
929 else
930 {
931 return false;
932 }
933 }
934 return false;
935}
936
Sagar Srinivas90314a32023-10-17 10:38:03 -0500937void Handler::setEventReceiver()
938{
939 std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) +
940 PLDM_SET_EVENT_RECEIVER_REQ_BYTES);
941 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
942 auto instanceId = instanceIdDb->next(eid);
943 uint8_t eventMessageGlobalEnable =
944 PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE;
945 uint8_t transportProtocolType = PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP;
946 uint8_t eventReceiverAddressInfo = pldm::responder::pdr::BmcMctpEid;
947 uint16_t heartbeatTimer = HEARTBEAT_TIMEOUT;
948
949 auto rc = encode_set_event_receiver_req(
950 instanceId, eventMessageGlobalEnable, transportProtocolType,
951 eventReceiverAddressInfo, heartbeatTimer, request);
952 if (rc != PLDM_SUCCESS)
953 {
954 instanceIdDb->free(eid, instanceId);
955 error("Failed to encode_set_event_receiver_req, rc = {RC}", "RC",
956 lg2::hex, rc);
957 return;
958 }
959
960 auto processSetEventReceiverResponse =
961 [](mctp_eid_t /*eid*/, const pldm_msg* response, size_t respMsgLen) {
962 if (response == nullptr || !respMsgLen)
963 {
964 error("Failed to receive response for setEventReceiver command");
965 return;
966 }
967
968 uint8_t completionCode{};
969 auto rc = decode_set_event_receiver_resp(response, respMsgLen,
970 &completionCode);
971 if (rc || completionCode)
972 {
973 error(
974 "Failed to decode setEventReceiver command response, rc = {RC}, cc = {CC}",
975 "RC", rc, "CC", (unsigned)completionCode);
976 pldm::utils::reportError(
977 "xyz.openbmc_project.bmc.pldm.InternalFailure");
978 }
979 };
980 rc = handler->registerRequest(
981 eid, instanceId, PLDM_PLATFORM, PLDM_SET_EVENT_RECEIVER,
982 std::move(requestMsg), std::move(processSetEventReceiverResponse));
983
984 if (rc != PLDM_SUCCESS)
985 {
986 error("Failed to send the setEventReceiver request");
987 }
988
989 if (oemPlatformHandler)
990 {
991 oemPlatformHandler->countSetEventReceiver();
992 oemPlatformHandler->checkAndDisableWatchDog();
993 }
994}
995
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600996} // namespace platform
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530997} // namespace responder
998} // namespace pldm