blob: 74153aca096933108518cabad35ede09633beafb [file] [log] [blame]
Deepak Kodihalli557dfb02019-05-12 13:11:17 +05301#pragma once
2
Sampa Misraa2fa0702019-05-31 01:28:55 -05003#include "config.h"
4
Deepak Kodihallid130e1a2020-06-17 05:55:32 -05005#include "common/utils.hpp"
TOM JOSEPHd4d97a52020-03-23 14:36:34 +05306#include "event_parser.hpp"
Tom Joseph33e9c7e2020-06-11 22:09:52 +05307#include "fru.hpp"
George Liucae18662020-05-15 09:32:57 +08008#include "host-bmc/dbus_to_event_handler.hpp"
Deepak Kodihalliac19bd62020-06-16 08:25:23 -05009#include "host-bmc/host_pdr_handler.hpp"
Sampa Misraa2fa0702019-05-31 01:28:55 -050010#include "libpldmresponder/pdr.hpp"
George Liue53193f2020-02-24 09:23:26 +080011#include "libpldmresponder/pdr_utils.hpp"
Sampa Misraaea5dde2020-08-31 08:33:47 -050012#include "oem_handler.hpp"
Deepak Kodihalli1521f6d2020-06-16 08:51:02 -050013#include "pldmd/handler.hpp"
Sampa Misraa2fa0702019-05-31 01:28:55 -050014
George Liuc453e162022-12-21 17:16:23 +080015#include <libpldm/pdr.h>
16#include <libpldm/platform.h>
17#include <libpldm/states.h>
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053018#include <stdint.h>
19
Riya Dixit49cfb132023-03-02 04:26:53 -060020#include <phosphor-logging/lg2.hpp>
21
Sampa Misraa2fa0702019-05-31 01:28:55 -050022#include <map>
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053023
Riya Dixit49cfb132023-03-02 04:26:53 -060024PHOSPHOR_LOG2_USING;
25
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053026namespace pldm
27{
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053028namespace responder
29{
Sampa Misraa2fa0702019-05-31 01:28:55 -050030namespace platform
31{
Brad Bishop5079ac42021-08-19 18:35:06 -040032using generatePDR = std::function<void(const pldm::utils::DBusHandler& dBusIntf,
33 const pldm::utils::Json& json,
34 pdr_utils::RepoInterface& repo)>;
George Liua2870722020-02-11 11:09:30 +080035
George Liu1ec85d42020-02-12 16:05:32 +080036using EffecterId = uint16_t;
George Liua2870722020-02-11 11:09:30 +080037using DbusObjMaps =
38 std::map<EffecterId,
39 std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>>;
Tom Joseph56e45c52020-03-16 10:01:45 +053040using DbusPath = std::string;
41using EffecterObjs = std::vector<DbusPath>;
42using EventType = uint8_t;
43using EventHandler = std::function<int(
44 const pldm_msg* request, size_t payloadLength, uint8_t formatVersion,
45 uint8_t tid, size_t eventDataOffset)>;
46using EventHandlers = std::vector<EventHandler>;
47using EventMap = std::map<EventType, EventHandlers>;
George Liuc4ea6a92020-07-14 15:48:44 +080048using AssociatedEntityMap = std::map<DbusPath, pldm_entity>;
Deepak Kodihallic682fe22020-03-04 00:42:54 -060049
Deepak Kodihallibc669f12019-11-28 08:52:07 -060050class Handler : public CmdHandler
Sampa Misraa2fa0702019-05-31 01:28:55 -050051{
Deepak Kodihallibc669f12019-11-28 08:52:07 -060052 public:
Deepak Kodihallib5c227e2020-07-13 06:58:34 -050053 Handler(const pldm::utils::DBusHandler* dBusIntf,
Pavithra Barithaya3aec9972020-12-14 01:55:44 -060054 const std::string& pdrJsonsDir, pldm_pdr* repo,
55 HostPDRHandler* hostPDRHandler,
Brad Bishop5079ac42021-08-19 18:35:06 -040056 pldm::state_sensor::DbusToPLDMEvent* dbusToPLDMEventHandler,
57 fru::Handler* fruHandler,
Sampa Misraaea5dde2020-08-31 08:33:47 -050058 pldm::responder::oem_platform::Handler* oemPlatformHandler,
Sampa Misra5fb37d52021-03-06 07:26:00 -060059 sdeventplus::Event& event, bool buildPDRLazily = false,
Tom Joseph56e45c52020-03-16 10:01:45 +053060 const std::optional<EventMap>& addOnHandlersMap = std::nullopt) :
Pavithra Barithaya51efaf82020-04-02 02:42:27 -050061 pdrRepo(repo),
Pavithra Barithaya3aec9972020-12-14 01:55:44 -060062 hostPDRHandler(hostPDRHandler),
George Liucae18662020-05-15 09:32:57 +080063 dbusToPLDMEventHandler(dbusToPLDMEventHandler), fruHandler(fruHandler),
Sampa Misraaea5dde2020-08-31 08:33:47 -050064 dBusIntf(dBusIntf), oemPlatformHandler(oemPlatformHandler),
Sampa Misra5fb37d52021-03-06 07:26:00 -060065 event(event), pdrJsonsDir(pdrJsonsDir), pdrCreated(false)
Sampa Misraa2fa0702019-05-31 01:28:55 -050066 {
Deepak Kodihallib5c227e2020-07-13 06:58:34 -050067 if (!buildPDRLazily)
68 {
Sampa Misra12afe112020-05-25 11:40:44 -050069 generateTerminusLocatorPDR(pdrRepo);
Deepak Kodihallib5c227e2020-07-13 06:58:34 -050070 generate(*dBusIntf, pdrJsonsDir, pdrRepo);
71 pdrCreated = true;
72 }
Deepak Kodihallic682fe22020-03-04 00:42:54 -060073
Deepak Kodihallibc669f12019-11-28 08:52:07 -060074 handlers.emplace(PLDM_GET_PDR,
75 [this](const pldm_msg* request, size_t payloadLength) {
76 return this->getPDR(request, payloadLength);
77 });
George Liueccb0c52020-01-14 11:09:56 +080078 handlers.emplace(PLDM_SET_NUMERIC_EFFECTER_VALUE,
79 [this](const pldm_msg* request, size_t payloadLength) {
80 return this->setNumericEffecterValue(
81 request, payloadLength);
82 });
Deepak Kodihallibc669f12019-11-28 08:52:07 -060083 handlers.emplace(PLDM_SET_STATE_EFFECTER_STATES,
84 [this](const pldm_msg* request, size_t payloadLength) {
85 return this->setStateEffecterStates(request,
86 payloadLength);
87 });
Tom Joseph56e45c52020-03-16 10:01:45 +053088 handlers.emplace(PLDM_PLATFORM_EVENT_MESSAGE,
89 [this](const pldm_msg* request, size_t payloadLength) {
90 return this->platformEventMessage(request,
91 payloadLength);
92 });
George Liu362c18d2020-05-14 09:46:36 +080093 handlers.emplace(PLDM_GET_STATE_SENSOR_READINGS,
94 [this](const pldm_msg* request, size_t payloadLength) {
95 return this->getStateSensorReadings(request,
96 payloadLength);
97 });
Tom Joseph56e45c52020-03-16 10:01:45 +053098
99 // Default handler for PLDM Events
100 eventHandlers[PLDM_SENSOR_EVENT].emplace_back(
101 [this](const pldm_msg* request, size_t payloadLength,
102 uint8_t formatVersion, uint8_t tid, size_t eventDataOffset) {
103 return this->sensorEvent(request, payloadLength, formatVersion,
104 tid, eventDataOffset);
105 });
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500106 eventHandlers[PLDM_PDR_REPOSITORY_CHG_EVENT].emplace_back(
107 [this](const pldm_msg* request, size_t payloadLength,
108 uint8_t formatVersion, uint8_t tid, size_t eventDataOffset) {
109 return this->pldmPDRRepositoryChgEvent(request, payloadLength,
110 formatVersion, tid,
111 eventDataOffset);
112 });
Tom Joseph56e45c52020-03-16 10:01:45 +0530113
114 // Additional OEM event handlers for PLDM events, append it to the
115 // standard handlers
116 if (addOnHandlersMap)
117 {
118 auto addOnHandlers = addOnHandlersMap.value();
119 for (EventMap::iterator iter = addOnHandlers.begin();
120 iter != addOnHandlers.end(); ++iter)
121 {
122 auto search = eventHandlers.find(iter->first);
123 if (search != eventHandlers.end())
124 {
125 search->second.insert(std::end(search->second),
126 std::begin(iter->second),
127 std::end(iter->second));
128 }
129 else
130 {
131 eventHandlers.emplace(iter->first, iter->second);
132 }
133 }
134 }
Sampa Misraa2fa0702019-05-31 01:28:55 -0500135 }
136
George Liu1ec85d42020-02-12 16:05:32 +0800137 pdr_utils::Repo& getRepo()
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600138 {
George Liu1ec85d42020-02-12 16:05:32 +0800139 return this->pdrRepo;
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600140 }
141
George Liu1ec85d42020-02-12 16:05:32 +0800142 /** @brief Add D-Bus mapping and value mapping(stateId to D-Bus) for the
George Liuadbe1722020-05-09 19:20:19 +0800143 * Id. If the same id is added, the previous dbusObjs will
George Liu1ec85d42020-02-12 16:05:32 +0800144 * be "over-written".
145 *
George Liuadbe1722020-05-09 19:20:19 +0800146 * @param[in] Id - effecter/sensor id
George Liu1ec85d42020-02-12 16:05:32 +0800147 * @param[in] dbusObj - list of D-Bus object structure and list of D-Bus
148 * property value to attribute value
George Liuadbe1722020-05-09 19:20:19 +0800149 * @param[in] typeId - the type id of enum
George Liu1ec85d42020-02-12 16:05:32 +0800150 */
George Liua2870722020-02-11 11:09:30 +0800151 void addDbusObjMaps(
George Liuadbe1722020-05-09 19:20:19 +0800152 uint16_t id,
153 std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> dbusObj,
Brad Bishop5079ac42021-08-19 18:35:06 -0400154 pldm::responder::pdr_utils::TypeId typeId =
155 pldm::responder::pdr_utils::TypeId::PLDM_EFFECTER_ID);
George Liu1ec85d42020-02-12 16:05:32 +0800156
George Liuadbe1722020-05-09 19:20:19 +0800157 /** @brief Retrieve an id -> D-Bus objects mapping
George Liu1ec85d42020-02-12 16:05:32 +0800158 *
George Liuadbe1722020-05-09 19:20:19 +0800159 * @param[in] Id - id
160 * @param[in] typeId - the type id of enum
George Liu1ec85d42020-02-12 16:05:32 +0800161 *
George Liua2870722020-02-11 11:09:30 +0800162 * @return std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> -
163 * list of D-Bus object structure and list of D-Bus property value
164 * to attribute value
George Liu1ec85d42020-02-12 16:05:32 +0800165 */
George Liua2870722020-02-11 11:09:30 +0800166 const std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>&
Brad Bishop5079ac42021-08-19 18:35:06 -0400167 getDbusObjMaps(
168 uint16_t id,
169 pldm::responder::pdr_utils::TypeId typeId =
170 pldm::responder::pdr_utils::TypeId::PLDM_EFFECTER_ID) const;
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600171
172 uint16_t getNextEffecterId()
173 {
174 return ++nextEffecterId;
175 }
176
George Liuadbe1722020-05-09 19:20:19 +0800177 uint16_t getNextSensorId()
178 {
179 return ++nextSensorId;
180 }
181
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600182 /** @brief Parse PDR JSONs and build PDR repository
183 *
George Liu36e81352020-07-01 14:40:30 +0800184 * @param[in] dBusIntf - The interface object
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600185 * @param[in] dir - directory housing platform specific PDR JSON files
186 * @param[in] repo - instance of concrete implementation of Repo
187 */
George Liu36e81352020-07-01 14:40:30 +0800188 void generate(const pldm::utils::DBusHandler& dBusIntf,
Brad Bishop5079ac42021-08-19 18:35:06 -0400189 const std::string& dir,
190 pldm::responder::pdr_utils::Repo& repo);
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600191
192 /** @brief Parse PDR JSONs and build state effecter PDR repository
193 *
194 * @param[in] json - platform specific PDR JSON files
195 * @param[in] repo - instance of state effecter implementation of Repo
196 */
Brad Bishop5079ac42021-08-19 18:35:06 -0400197 void generateStateEffecterRepo(const pldm::utils::Json& json,
198 pldm::responder::pdr_utils::Repo& repo);
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600199
Tom Joseph56e45c52020-03-16 10:01:45 +0530200 /** @brief map of PLDM event type to EventHandlers
201 *
202 */
203 EventMap eventHandlers;
204
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600205 /** @brief Handler for GetPDR
206 *
207 * @param[in] request - Request message payload
208 * @param[in] payloadLength - Request payload length
209 * @param[out] Response - Response message written here
210 */
211 Response getPDR(const pldm_msg* request, size_t payloadLength);
Sampa Misraa2fa0702019-05-31 01:28:55 -0500212
George Liueccb0c52020-01-14 11:09:56 +0800213 /** @brief Handler for setNumericEffecterValue
214 *
215 * @param[in] request - Request message
216 * @param[in] payloadLength - Request payload length
217 * @return Response - PLDM Response message
218 */
219 Response setNumericEffecterValue(const pldm_msg* request,
220 size_t payloadLength);
221
George Liu362c18d2020-05-14 09:46:36 +0800222 /** @brief Handler for getStateSensorReadings
223 *
224 * @param[in] request - Request message
225 * @param[in] payloadLength - Request payload length
226 * @return Response - PLDM Response message
227 */
228 Response getStateSensorReadings(const pldm_msg* request,
229 size_t payloadLength);
230
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600231 /** @brief Handler for setStateEffecterStates
232 *
233 * @param[in] request - Request message
234 * @param[in] payloadLength - Request payload length
235 * @return Response - PLDM Response message
236 */
237 Response setStateEffecterStates(const pldm_msg* request,
238 size_t payloadLength);
239
Tom Joseph56e45c52020-03-16 10:01:45 +0530240 /** @brief Handler for PlatformEventMessage
241 *
242 * @param[in] request - Request message
243 * @param[in] payloadLength - Request payload length
244 * @return Response - PLDM Response message
245 */
246 Response platformEventMessage(const pldm_msg* request,
247 size_t payloadLength);
248
249 /** @brief Handler for event class Sensor event
250 *
251 * @param[in] request - Request message
252 * @param[in] payloadLength - Request payload length
253 * @param[in] formatVersion - Version of the event format
254 * @param[in] tid - Terminus ID of the event's originator
255 * @param[in] eventDataOffset - Offset of the event data in the request
256 * message
257 * @return PLDM completion code
258 */
259 int sensorEvent(const pldm_msg* request, size_t payloadLength,
260 uint8_t formatVersion, uint8_t tid, size_t eventDataOffset);
261
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500262 /** @brief Handler for pldmPDRRepositoryChgEvent
263 *
264 * @param[in] request - Request message
265 * @param[in] payloadLength - Request payload length
266 * @param[in] formatVersion - Version of the event format
267 * @param[in] tid - Terminus ID of the event's originator
268 * @param[in] eventDataOffset - Offset of the event data in the request
269 * message
270 * @return PLDM completion code
271 */
272 int pldmPDRRepositoryChgEvent(const pldm_msg* request, size_t payloadLength,
273 uint8_t formatVersion, uint8_t tid,
274 size_t eventDataOffset);
275
276 /** @brief Handler for extracting the PDR handles from changeEntries
277 *
278 * @param[in] changeEntryData - ChangeEntry data from changeRecord
279 * @param[in] changeEntryDataSize - total size of changeEntryData
280 * @param[in] numberOfChangeEntries - total number of changeEntries to
281 * extract
282 * @param[out] pdrRecordHandles - std::vector where the extracted PDR
283 * handles are placed
284 * @return PLDM completion code
285 */
286 int getPDRRecordHandles(const ChangeEntry* changeEntryData,
287 size_t changeEntryDataSize,
288 size_t numberOfChangeEntries,
289 PDRRecordHandles& pdrRecordHandles);
290
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600291 /** @brief Function to set the effecter requested by pldm requester
292 * @param[in] dBusIntf - The interface object
293 * @param[in] effecterId - Effecter ID sent by the requester to act on
294 * @param[in] stateField - The state field data for each of the states,
295 * equal to composite effecter count in number
296 * @return - Success or failure in setting the states. Returns failure in
297 * terms of PLDM completion codes if atleast one state fails to be set
298 */
299 template <class DBusInterface>
300 int setStateEffecterStatesHandler(
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600301 const DBusInterface& dBusIntf, uint16_t effecterId,
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600302 const std::vector<set_effecter_state_field>& stateField)
Sampa Misraa2fa0702019-05-31 01:28:55 -0500303 {
George Liue53193f2020-02-24 09:23:26 +0800304 using namespace pldm::responder::pdr;
George Liu1e44c732020-02-28 20:20:06 +0800305 using namespace pldm::utils;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600306 using StateSetNum = uint8_t;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600307
308 state_effecter_possible_states* states = nullptr;
309 pldm_state_effecter_pdr* pdr = nullptr;
310 uint8_t compEffecterCnt = stateField.size();
George Liu1ec85d42020-02-12 16:05:32 +0800311
312 std::unique_ptr<pldm_pdr, decltype(&pldm_pdr_destroy)>
313 stateEffecterPdrRepo(pldm_pdr_init(), pldm_pdr_destroy);
Brad Bishop5079ac42021-08-19 18:35:06 -0400314 pldm::responder::pdr_utils::Repo stateEffecterPDRs(
315 stateEffecterPdrRepo.get());
George Liu1ec85d42020-02-12 16:05:32 +0800316 getRepoByType(pdrRepo, stateEffecterPDRs, PLDM_STATE_EFFECTER_PDR);
317 if (stateEffecterPDRs.empty())
318 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600319 error("Failed to get record by PDR type");
George Liu1ec85d42020-02-12 16:05:32 +0800320 return PLDM_PLATFORM_INVALID_EFFECTER_ID;
321 }
322
Brad Bishop5079ac42021-08-19 18:35:06 -0400323 pldm::responder::pdr_utils::PdrEntry pdrEntry{};
George Liu1ec85d42020-02-12 16:05:32 +0800324 auto pdrRecord = stateEffecterPDRs.getFirstRecord(pdrEntry);
George Liue53193f2020-02-24 09:23:26 +0800325 while (pdrRecord)
326 {
327 pdr = reinterpret_cast<pldm_state_effecter_pdr*>(pdrEntry.data);
328 if (pdr->effecter_id != effecterId)
Sampa Misraa2fa0702019-05-31 01:28:55 -0500329 {
George Liue53193f2020-02-24 09:23:26 +0800330 pdr = nullptr;
George Liu1ec85d42020-02-12 16:05:32 +0800331 pdrRecord =
332 stateEffecterPDRs.getNextRecord(pdrRecord, pdrEntry);
George Liue53193f2020-02-24 09:23:26 +0800333 continue;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600334 }
George Liue53193f2020-02-24 09:23:26 +0800335
336 states = reinterpret_cast<state_effecter_possible_states*>(
337 pdr->possible_states);
338 if (compEffecterCnt > pdr->composite_effecter_count)
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600339 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600340 error(
341 "The requester sent wrong composite effecter count for the effecter, EFFECTER_ID={EFFECTER_ID} COMP_EFF_CNT={COMP_EFF_CNT}",
342 "EFFECTER_ID", (unsigned)effecterId, "COMP_EFF_CNT",
343 (unsigned)compEffecterCnt);
George Liue53193f2020-02-24 09:23:26 +0800344 return PLDM_ERROR_INVALID_DATA;
Sampa Misraa2fa0702019-05-31 01:28:55 -0500345 }
George Liue53193f2020-02-24 09:23:26 +0800346 break;
347 }
348
349 if (!pdr)
350 {
351 return PLDM_PLATFORM_INVALID_EFFECTER_ID;
Sampa Misraa2fa0702019-05-31 01:28:55 -0500352 }
Sampa Misraa2fa0702019-05-31 01:28:55 -0500353
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600354 int rc = PLDM_SUCCESS;
George Liu1ec85d42020-02-12 16:05:32 +0800355 try
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600356 {
George Liu1ec85d42020-02-12 16:05:32 +0800357 const auto& [dbusMappings, dbusValMaps] =
George Liuadbe1722020-05-09 19:20:19 +0800358 effecterDbusObjMaps.at(effecterId);
George Liu1ec85d42020-02-12 16:05:32 +0800359 for (uint8_t currState = 0; currState < compEffecterCnt;
360 ++currState)
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600361 {
George Liu1ec85d42020-02-12 16:05:32 +0800362 std::vector<StateSetNum> allowed{};
363 // computation is based on table 79 from DSP0248 v1.1.1
364 uint8_t bitfieldIndex =
365 stateField[currState].effecter_state / 8;
366 uint8_t bit =
367 stateField[currState].effecter_state - (8 * bitfieldIndex);
368 if (states->possible_states_size < bitfieldIndex ||
369 !(states->states[bitfieldIndex].byte & (1 << bit)))
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600370 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600371 error(
372 "Invalid state set value, EFFECTER_ID={EFFECTER_ID} VALUE={EFFECTER_STATE} COMPOSITE_EFFECTER_ID={CURR_STATE} DBUS_PATH={DBUS_OBJ_PATH}",
373 "EFFECTER_ID", (unsigned)effecterId, "EFFECTER_STATE",
374 (unsigned)stateField[currState].effecter_state,
375 "CURR_STATE", (unsigned)currState, "DBUS_OBJ_PATH",
376 dbusMappings[currState].objectPath.c_str());
George Liu1ec85d42020-02-12 16:05:32 +0800377 rc = PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600378 break;
379 }
George Liu1ec85d42020-02-12 16:05:32 +0800380 const DBusMapping& dbusMapping = dbusMappings[currState];
Brad Bishop5079ac42021-08-19 18:35:06 -0400381 const pldm::responder::pdr_utils::StatestoDbusVal&
382 dbusValToMap = dbusValMaps[currState];
George Liu1ec85d42020-02-12 16:05:32 +0800383
384 if (stateField[currState].set_request == PLDM_REQUEST_SET)
385 {
386 try
387 {
388 dBusIntf.setDbusProperty(
389 dbusMapping,
390 dbusValToMap.at(
391 stateField[currState].effecter_state));
392 }
393 catch (const std::exception& e)
394 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600395 error(
396 "Error setting property, ERROR={ERR_EXCEP} PROPERTY={DBUS_PROP} INTERFACE={DBUS_INTF} PATH={DBUS_OBJ_PATH}",
397 "ERR_EXCEP", e.what(), "DBUS_PROP",
398 dbusMapping.propertyName, "DBUS_INTF",
399 dbusMapping.interface, "DBUS_OBJ_PATH",
400 dbusMapping.objectPath.c_str());
George Liu1ec85d42020-02-12 16:05:32 +0800401 return PLDM_ERROR;
402 }
403 }
404 uint8_t* nextState =
405 reinterpret_cast<uint8_t*>(states) +
406 sizeof(state_effecter_possible_states) -
407 sizeof(states->states) +
408 (states->possible_states_size * sizeof(states->states));
409 states = reinterpret_cast<state_effecter_possible_states*>(
410 nextState);
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600411 }
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600412 }
George Liu1ec85d42020-02-12 16:05:32 +0800413 catch (const std::out_of_range& e)
414 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600415 error(
416 "the effecterId does not exist. effecter id: {EFFECTER_ID} {ERR_EXCEP}",
417 "EFFECTER_ID", (unsigned)effecterId, "ERR_EXCEP", e.what());
George Liu1ec85d42020-02-12 16:05:32 +0800418 }
419
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600420 return rc;
421 }
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600422
Sampa Misra12afe112020-05-25 11:40:44 -0500423 /** @brief Build BMC Terminus Locator PDR
424 *
425 * @param[in] repo - instance of concrete implementation of Repo
426 */
Brad Bishop5079ac42021-08-19 18:35:06 -0400427 void generateTerminusLocatorPDR(pldm::responder::pdr_utils::Repo& repo);
Sampa Misra12afe112020-05-25 11:40:44 -0500428
George Liuc4ea6a92020-07-14 15:48:44 +0800429 /** @brief Get std::map associated with the entity
430 * key: object path
431 * value: pldm_entity
432 *
433 * @return std::map<ObjectPath, pldm_entity>
434 */
435 inline const AssociatedEntityMap& getAssociateEntityMap() const
436 {
437 if (fruHandler == nullptr)
438 {
439 throw InternalFailure();
440 }
441 return fruHandler->getAssociateEntityMap();
442 }
443
Sampa Misra5fb37d52021-03-06 07:26:00 -0600444 /** @brief process the actions that needs to be performed after a GetPDR
445 * call is received
446 * @param[in] source - sdeventplus event source
447 */
448 void _processPostGetPDRActions(sdeventplus::source::EventBase& source);
449
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600450 private:
451 pdr_utils::Repo pdrRepo;
452 uint16_t nextEffecterId{};
George Liuadbe1722020-05-09 19:20:19 +0800453 uint16_t nextSensorId{};
454 DbusObjMaps effecterDbusObjMaps{};
455 DbusObjMaps sensorDbusObjMaps{};
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500456 HostPDRHandler* hostPDRHandler;
Brad Bishop5079ac42021-08-19 18:35:06 -0400457 pldm::state_sensor::DbusToPLDMEvent* dbusToPLDMEventHandler;
Tom Joseph33e9c7e2020-06-11 22:09:52 +0530458 fru::Handler* fruHandler;
Deepak Kodihallib5c227e2020-07-13 06:58:34 -0500459 const pldm::utils::DBusHandler* dBusIntf;
Sampa Misraaea5dde2020-08-31 08:33:47 -0500460 pldm::responder::oem_platform::Handler* oemPlatformHandler;
Sampa Misra5fb37d52021-03-06 07:26:00 -0600461 sdeventplus::Event& event;
Deepak Kodihallib5c227e2020-07-13 06:58:34 -0500462 std::string pdrJsonsDir;
463 bool pdrCreated;
Sampa Misra5fb37d52021-03-06 07:26:00 -0600464 std::unique_ptr<sdeventplus::source::Defer> deferredGetPDREvent;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600465};
466
Sampa Misraaea5dde2020-08-31 08:33:47 -0500467/** @brief Function to check if a sensor falls in OEM range
468 * A sensor is considered to be oem if either of entity
469 * type or state set or both falls in oem range
470 *
471 * @param[in] handler - the interface object
472 * @param[in] sensorId - sensor id
473 * @param[in] sensorRearmCount - sensor rearm count
474 * @param[out] compSensorCnt - composite sensor count
475 * @param[out] entityType - entity type
476 * @param[out] entityInstance - entity instance number
477 * @param[out] stateSetId - state set id
478 *
479 * @return true if the sensor is OEM. All out parameters are invalid
480 * for a non OEM sensor
481 */
482bool isOemStateSensor(Handler& handler, uint16_t sensorId,
483 uint8_t sensorRearmCount, uint8_t& compSensorCnt,
484 uint16_t& entityType, uint16_t& entityInstance,
485 uint16_t& stateSetId);
486
487/** @brief Function to check if an effecter falls in OEM range
488 * An effecter is considered to be oem if either of entity
489 * type or state set or both falls in oem range
490 *
491 * @param[in] handler - the interface object
492 * @param[in] effecterId - effecter id
493 * @param[in] compEffecterCnt - composite effecter count
494 * @param[out] entityType - entity type
495 * @param[out] entityInstance - entity instance number
496 * @param[out] stateSetId - state set id
497 *
498 * @return true if the effecter is OEM. All out parameters are invalid
499 * for a non OEM effecter
500 */
501bool isOemStateEffecter(Handler& handler, uint16_t effecterId,
502 uint8_t compEffecterCnt, uint16_t& entityType,
503 uint16_t& entityInstance, uint16_t& stateSetId);
504
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600505} // namespace platform
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530506} // namespace responder
507} // namespace pldm