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