blob: 8d2c74eae0e40419c18daa2109e2ae4e858d5962 [file] [log] [blame]
Deepak Kodihalli557dfb02019-05-12 13:11:17 +05301#pragma once
2
Deepak Kodihallid130e1a2020-06-17 05:55:32 -05003#include "common/utils.hpp"
TOM JOSEPHd4d97a52020-03-23 14:36:34 +05304#include "event_parser.hpp"
Tom Joseph33e9c7e2020-06-11 22:09:52 +05305#include "fru.hpp"
George Liucae18662020-05-15 09:32:57 +08006#include "host-bmc/dbus_to_event_handler.hpp"
Deepak Kodihalliac19bd62020-06-16 08:25:23 -05007#include "host-bmc/host_pdr_handler.hpp"
Sampa Misraa2fa0702019-05-31 01:28:55 -05008#include "libpldmresponder/pdr.hpp"
George Liue53193f2020-02-24 09:23:26 +08009#include "libpldmresponder/pdr_utils.hpp"
Sampa Misraaea5dde2020-08-31 08:33:47 -050010#include "oem_handler.hpp"
Deepak Kodihalli1521f6d2020-06-16 08:51:02 -050011#include "pldmd/handler.hpp"
Sampa Misraa2fa0702019-05-31 01:28:55 -050012
George Liuc453e162022-12-21 17:16:23 +080013#include <libpldm/pdr.h>
14#include <libpldm/platform.h>
15#include <libpldm/states.h>
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053016#include <stdint.h>
17
Riya Dixit49cfb132023-03-02 04:26:53 -060018#include <phosphor-logging/lg2.hpp>
19
Sampa Misraa2fa0702019-05-31 01:28:55 -050020#include <map>
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053021
Riya Dixit49cfb132023-03-02 04:26:53 -060022PHOSPHOR_LOG2_USING;
23
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053024namespace pldm
25{
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053026namespace responder
27{
Sampa Misraa2fa0702019-05-31 01:28:55 -050028namespace platform
29{
Brad Bishop5079ac42021-08-19 18:35:06 -040030using generatePDR = std::function<void(const pldm::utils::DBusHandler& dBusIntf,
31 const pldm::utils::Json& json,
32 pdr_utils::RepoInterface& repo)>;
George Liua2870722020-02-11 11:09:30 +080033
George Liu1ec85d42020-02-12 16:05:32 +080034using EffecterId = uint16_t;
George Liua2870722020-02-11 11:09:30 +080035using DbusObjMaps =
36 std::map<EffecterId,
37 std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>>;
Tom Joseph56e45c52020-03-16 10:01:45 +053038using DbusPath = std::string;
39using EffecterObjs = std::vector<DbusPath>;
40using EventType = uint8_t;
41using EventHandler = std::function<int(
42 const pldm_msg* request, size_t payloadLength, uint8_t formatVersion,
43 uint8_t tid, size_t eventDataOffset)>;
44using EventHandlers = std::vector<EventHandler>;
45using EventMap = std::map<EventType, EventHandlers>;
George Liuc4ea6a92020-07-14 15:48:44 +080046using AssociatedEntityMap = std::map<DbusPath, pldm_entity>;
Deepak Kodihallic682fe22020-03-04 00:42:54 -060047
Deepak Kodihallibc669f12019-11-28 08:52:07 -060048class Handler : public CmdHandler
Sampa Misraa2fa0702019-05-31 01:28:55 -050049{
Deepak Kodihallibc669f12019-11-28 08:52:07 -060050 public:
Deepak Kodihallib5c227e2020-07-13 06:58:34 -050051 Handler(const pldm::utils::DBusHandler* dBusIntf,
Pavithra Barithaya3aec9972020-12-14 01:55:44 -060052 const std::string& pdrJsonsDir, pldm_pdr* repo,
53 HostPDRHandler* hostPDRHandler,
Brad Bishop5079ac42021-08-19 18:35:06 -040054 pldm::state_sensor::DbusToPLDMEvent* dbusToPLDMEventHandler,
55 fru::Handler* fruHandler,
Sampa Misraaea5dde2020-08-31 08:33:47 -050056 pldm::responder::oem_platform::Handler* oemPlatformHandler,
Sampa Misra5fb37d52021-03-06 07:26:00 -060057 sdeventplus::Event& event, bool buildPDRLazily = false,
Tom Joseph56e45c52020-03-16 10:01:45 +053058 const std::optional<EventMap>& addOnHandlersMap = std::nullopt) :
Pavithra Barithaya51efaf82020-04-02 02:42:27 -050059 pdrRepo(repo),
Pavithra Barithaya3aec9972020-12-14 01:55:44 -060060 hostPDRHandler(hostPDRHandler),
George Liucae18662020-05-15 09:32:57 +080061 dbusToPLDMEventHandler(dbusToPLDMEventHandler), fruHandler(fruHandler),
Sampa Misraaea5dde2020-08-31 08:33:47 -050062 dBusIntf(dBusIntf), oemPlatformHandler(oemPlatformHandler),
Sampa Misra5fb37d52021-03-06 07:26:00 -060063 event(event), pdrJsonsDir(pdrJsonsDir), pdrCreated(false)
Sampa Misraa2fa0702019-05-31 01:28:55 -050064 {
Deepak Kodihallib5c227e2020-07-13 06:58:34 -050065 if (!buildPDRLazily)
66 {
Sampa Misra12afe112020-05-25 11:40:44 -050067 generateTerminusLocatorPDR(pdrRepo);
Deepak Kodihallib5c227e2020-07-13 06:58:34 -050068 generate(*dBusIntf, pdrJsonsDir, pdrRepo);
69 pdrCreated = true;
70 }
Deepak Kodihallic682fe22020-03-04 00:42:54 -060071
Deepak Kodihallibc669f12019-11-28 08:52:07 -060072 handlers.emplace(PLDM_GET_PDR,
73 [this](const pldm_msg* request, size_t payloadLength) {
Patrick Williams6da4f912023-05-10 07:50:53 -050074 return this->getPDR(request, payloadLength);
75 });
George Liueccb0c52020-01-14 11:09:56 +080076 handlers.emplace(PLDM_SET_NUMERIC_EFFECTER_VALUE,
77 [this](const pldm_msg* request, size_t payloadLength) {
Patrick Williams6da4f912023-05-10 07:50:53 -050078 return this->setNumericEffecterValue(request, payloadLength);
79 });
Deepak Kodihallibc669f12019-11-28 08:52:07 -060080 handlers.emplace(PLDM_SET_STATE_EFFECTER_STATES,
81 [this](const pldm_msg* request, size_t payloadLength) {
Patrick Williams6da4f912023-05-10 07:50:53 -050082 return this->setStateEffecterStates(request, payloadLength);
83 });
Tom Joseph56e45c52020-03-16 10:01:45 +053084 handlers.emplace(PLDM_PLATFORM_EVENT_MESSAGE,
85 [this](const pldm_msg* request, size_t payloadLength) {
Patrick Williams6da4f912023-05-10 07:50:53 -050086 return this->platformEventMessage(request, payloadLength);
87 });
George Liu362c18d2020-05-14 09:46:36 +080088 handlers.emplace(PLDM_GET_STATE_SENSOR_READINGS,
89 [this](const pldm_msg* request, size_t payloadLength) {
Patrick Williams6da4f912023-05-10 07:50:53 -050090 return this->getStateSensorReadings(request, payloadLength);
91 });
Tom Joseph56e45c52020-03-16 10:01:45 +053092
93 // Default handler for PLDM Events
94 eventHandlers[PLDM_SENSOR_EVENT].emplace_back(
95 [this](const pldm_msg* request, size_t payloadLength,
96 uint8_t formatVersion, uint8_t tid, size_t eventDataOffset) {
Patrick Williams6da4f912023-05-10 07:50:53 -050097 return this->sensorEvent(request, payloadLength, formatVersion, tid,
98 eventDataOffset);
99 });
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500100 eventHandlers[PLDM_PDR_REPOSITORY_CHG_EVENT].emplace_back(
101 [this](const pldm_msg* request, size_t payloadLength,
102 uint8_t formatVersion, uint8_t tid, size_t eventDataOffset) {
Patrick Williams6da4f912023-05-10 07:50:53 -0500103 return this->pldmPDRRepositoryChgEvent(
104 request, payloadLength, formatVersion, tid, eventDataOffset);
105 });
Tom Joseph56e45c52020-03-16 10:01:45 +0530106
107 // Additional OEM event handlers for PLDM events, append it to the
108 // standard handlers
109 if (addOnHandlersMap)
110 {
111 auto addOnHandlers = addOnHandlersMap.value();
112 for (EventMap::iterator iter = addOnHandlers.begin();
113 iter != addOnHandlers.end(); ++iter)
114 {
115 auto search = eventHandlers.find(iter->first);
116 if (search != eventHandlers.end())
117 {
118 search->second.insert(std::end(search->second),
119 std::begin(iter->second),
120 std::end(iter->second));
121 }
122 else
123 {
124 eventHandlers.emplace(iter->first, iter->second);
125 }
126 }
127 }
Sampa Misraa2fa0702019-05-31 01:28:55 -0500128 }
129
George Liu1ec85d42020-02-12 16:05:32 +0800130 pdr_utils::Repo& getRepo()
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600131 {
George Liu1ec85d42020-02-12 16:05:32 +0800132 return this->pdrRepo;
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600133 }
134
George Liu1ec85d42020-02-12 16:05:32 +0800135 /** @brief Add D-Bus mapping and value mapping(stateId to D-Bus) for the
George Liuadbe1722020-05-09 19:20:19 +0800136 * Id. If the same id is added, the previous dbusObjs will
George Liu1ec85d42020-02-12 16:05:32 +0800137 * be "over-written".
138 *
George Liuadbe1722020-05-09 19:20:19 +0800139 * @param[in] Id - effecter/sensor id
George Liu1ec85d42020-02-12 16:05:32 +0800140 * @param[in] dbusObj - list of D-Bus object structure and list of D-Bus
141 * property value to attribute value
George Liuadbe1722020-05-09 19:20:19 +0800142 * @param[in] typeId - the type id of enum
George Liu1ec85d42020-02-12 16:05:32 +0800143 */
George Liua2870722020-02-11 11:09:30 +0800144 void addDbusObjMaps(
George Liuadbe1722020-05-09 19:20:19 +0800145 uint16_t id,
146 std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> dbusObj,
Brad Bishop5079ac42021-08-19 18:35:06 -0400147 pldm::responder::pdr_utils::TypeId typeId =
148 pldm::responder::pdr_utils::TypeId::PLDM_EFFECTER_ID);
George Liu1ec85d42020-02-12 16:05:32 +0800149
George Liuadbe1722020-05-09 19:20:19 +0800150 /** @brief Retrieve an id -> D-Bus objects mapping
George Liu1ec85d42020-02-12 16:05:32 +0800151 *
George Liuadbe1722020-05-09 19:20:19 +0800152 * @param[in] Id - id
153 * @param[in] typeId - the type id of enum
George Liu1ec85d42020-02-12 16:05:32 +0800154 *
George Liua2870722020-02-11 11:09:30 +0800155 * @return std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> -
156 * list of D-Bus object structure and list of D-Bus property value
157 * to attribute value
George Liu1ec85d42020-02-12 16:05:32 +0800158 */
George Liua2870722020-02-11 11:09:30 +0800159 const std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>&
Brad Bishop5079ac42021-08-19 18:35:06 -0400160 getDbusObjMaps(
161 uint16_t id,
162 pldm::responder::pdr_utils::TypeId typeId =
163 pldm::responder::pdr_utils::TypeId::PLDM_EFFECTER_ID) const;
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600164
165 uint16_t getNextEffecterId()
166 {
167 return ++nextEffecterId;
168 }
169
George Liuadbe1722020-05-09 19:20:19 +0800170 uint16_t getNextSensorId()
171 {
172 return ++nextSensorId;
173 }
174
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600175 /** @brief Parse PDR JSONs and build PDR repository
176 *
George Liu36e81352020-07-01 14:40:30 +0800177 * @param[in] dBusIntf - The interface object
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600178 * @param[in] dir - directory housing platform specific PDR JSON files
179 * @param[in] repo - instance of concrete implementation of Repo
180 */
George Liu36e81352020-07-01 14:40:30 +0800181 void generate(const pldm::utils::DBusHandler& dBusIntf,
Brad Bishop5079ac42021-08-19 18:35:06 -0400182 const std::string& dir,
183 pldm::responder::pdr_utils::Repo& repo);
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600184
185 /** @brief Parse PDR JSONs and build state effecter PDR repository
186 *
187 * @param[in] json - platform specific PDR JSON files
188 * @param[in] repo - instance of state effecter implementation of Repo
189 */
Brad Bishop5079ac42021-08-19 18:35:06 -0400190 void generateStateEffecterRepo(const pldm::utils::Json& json,
191 pldm::responder::pdr_utils::Repo& repo);
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600192
Tom Joseph56e45c52020-03-16 10:01:45 +0530193 /** @brief map of PLDM event type to EventHandlers
194 *
195 */
196 EventMap eventHandlers;
197
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600198 /** @brief Handler for GetPDR
199 *
200 * @param[in] request - Request message payload
201 * @param[in] payloadLength - Request payload length
202 * @param[out] Response - Response message written here
203 */
204 Response getPDR(const pldm_msg* request, size_t payloadLength);
Sampa Misraa2fa0702019-05-31 01:28:55 -0500205
George Liueccb0c52020-01-14 11:09:56 +0800206 /** @brief Handler for setNumericEffecterValue
207 *
208 * @param[in] request - Request message
209 * @param[in] payloadLength - Request payload length
210 * @return Response - PLDM Response message
211 */
212 Response setNumericEffecterValue(const pldm_msg* request,
213 size_t payloadLength);
214
George Liu362c18d2020-05-14 09:46:36 +0800215 /** @brief Handler for getStateSensorReadings
216 *
217 * @param[in] request - Request message
218 * @param[in] payloadLength - Request payload length
219 * @return Response - PLDM Response message
220 */
221 Response getStateSensorReadings(const pldm_msg* request,
222 size_t payloadLength);
223
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600224 /** @brief Handler for setStateEffecterStates
225 *
226 * @param[in] request - Request message
227 * @param[in] payloadLength - Request payload length
228 * @return Response - PLDM Response message
229 */
230 Response setStateEffecterStates(const pldm_msg* request,
231 size_t payloadLength);
232
Tom Joseph56e45c52020-03-16 10:01:45 +0530233 /** @brief Handler for PlatformEventMessage
234 *
235 * @param[in] request - Request message
236 * @param[in] payloadLength - Request payload length
237 * @return Response - PLDM Response message
238 */
239 Response platformEventMessage(const pldm_msg* request,
240 size_t payloadLength);
241
242 /** @brief Handler for event class Sensor event
243 *
244 * @param[in] request - Request message
245 * @param[in] payloadLength - Request payload length
246 * @param[in] formatVersion - Version of the event format
247 * @param[in] tid - Terminus ID of the event's originator
248 * @param[in] eventDataOffset - Offset of the event data in the request
249 * message
250 * @return PLDM completion code
251 */
252 int sensorEvent(const pldm_msg* request, size_t payloadLength,
253 uint8_t formatVersion, uint8_t tid, size_t eventDataOffset);
254
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500255 /** @brief Handler for pldmPDRRepositoryChgEvent
256 *
257 * @param[in] request - Request message
258 * @param[in] payloadLength - Request payload length
259 * @param[in] formatVersion - Version of the event format
260 * @param[in] tid - Terminus ID of the event's originator
261 * @param[in] eventDataOffset - Offset of the event data in the request
262 * message
263 * @return PLDM completion code
264 */
265 int pldmPDRRepositoryChgEvent(const pldm_msg* request, size_t payloadLength,
266 uint8_t formatVersion, uint8_t tid,
267 size_t eventDataOffset);
268
269 /** @brief Handler for extracting the PDR handles from changeEntries
270 *
271 * @param[in] changeEntryData - ChangeEntry data from changeRecord
272 * @param[in] changeEntryDataSize - total size of changeEntryData
273 * @param[in] numberOfChangeEntries - total number of changeEntries to
274 * extract
275 * @param[out] pdrRecordHandles - std::vector where the extracted PDR
276 * handles are placed
277 * @return PLDM completion code
278 */
279 int getPDRRecordHandles(const ChangeEntry* changeEntryData,
280 size_t changeEntryDataSize,
281 size_t numberOfChangeEntries,
282 PDRRecordHandles& pdrRecordHandles);
283
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600284 /** @brief Function to set the effecter requested by pldm requester
285 * @param[in] dBusIntf - The interface object
286 * @param[in] effecterId - Effecter ID sent by the requester to act on
287 * @param[in] stateField - The state field data for each of the states,
288 * equal to composite effecter count in number
289 * @return - Success or failure in setting the states. Returns failure in
290 * terms of PLDM completion codes if atleast one state fails to be set
291 */
292 template <class DBusInterface>
293 int setStateEffecterStatesHandler(
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600294 const DBusInterface& dBusIntf, uint16_t effecterId,
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600295 const std::vector<set_effecter_state_field>& stateField)
Sampa Misraa2fa0702019-05-31 01:28:55 -0500296 {
George Liue53193f2020-02-24 09:23:26 +0800297 using namespace pldm::responder::pdr;
George Liu1e44c732020-02-28 20:20:06 +0800298 using namespace pldm::utils;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600299 using StateSetNum = uint8_t;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600300
301 state_effecter_possible_states* states = nullptr;
302 pldm_state_effecter_pdr* pdr = nullptr;
303 uint8_t compEffecterCnt = stateField.size();
George Liu1ec85d42020-02-12 16:05:32 +0800304
305 std::unique_ptr<pldm_pdr, decltype(&pldm_pdr_destroy)>
306 stateEffecterPdrRepo(pldm_pdr_init(), pldm_pdr_destroy);
Andrew Jefferyacb20292023-06-30 11:47:44 +0930307 if (!stateEffecterPdrRepo)
308 {
309 throw std::runtime_error(
310 "Failed to instantiate state effecter PDR repository");
311 }
Brad Bishop5079ac42021-08-19 18:35:06 -0400312 pldm::responder::pdr_utils::Repo stateEffecterPDRs(
313 stateEffecterPdrRepo.get());
George Liu1ec85d42020-02-12 16:05:32 +0800314 getRepoByType(pdrRepo, stateEffecterPDRs, PLDM_STATE_EFFECTER_PDR);
315 if (stateEffecterPDRs.empty())
316 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600317 error("Failed to get record by PDR type");
George Liu1ec85d42020-02-12 16:05:32 +0800318 return PLDM_PLATFORM_INVALID_EFFECTER_ID;
319 }
320
Brad Bishop5079ac42021-08-19 18:35:06 -0400321 pldm::responder::pdr_utils::PdrEntry pdrEntry{};
George Liu1ec85d42020-02-12 16:05:32 +0800322 auto pdrRecord = stateEffecterPDRs.getFirstRecord(pdrEntry);
George Liue53193f2020-02-24 09:23:26 +0800323 while (pdrRecord)
324 {
325 pdr = reinterpret_cast<pldm_state_effecter_pdr*>(pdrEntry.data);
326 if (pdr->effecter_id != effecterId)
Sampa Misraa2fa0702019-05-31 01:28:55 -0500327 {
George Liue53193f2020-02-24 09:23:26 +0800328 pdr = nullptr;
Patrick Williams6da4f912023-05-10 07:50:53 -0500329 pdrRecord = stateEffecterPDRs.getNextRecord(pdrRecord,
330 pdrEntry);
George Liue53193f2020-02-24 09:23:26 +0800331 continue;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600332 }
George Liue53193f2020-02-24 09:23:26 +0800333
334 states = reinterpret_cast<state_effecter_possible_states*>(
335 pdr->possible_states);
336 if (compEffecterCnt > pdr->composite_effecter_count)
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600337 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600338 error(
339 "The requester sent wrong composite effecter count for the effecter, EFFECTER_ID={EFFECTER_ID} COMP_EFF_CNT={COMP_EFF_CNT}",
340 "EFFECTER_ID", (unsigned)effecterId, "COMP_EFF_CNT",
341 (unsigned)compEffecterCnt);
George Liue53193f2020-02-24 09:23:26 +0800342 return PLDM_ERROR_INVALID_DATA;
Sampa Misraa2fa0702019-05-31 01:28:55 -0500343 }
George Liue53193f2020-02-24 09:23:26 +0800344 break;
345 }
346
347 if (!pdr)
348 {
349 return PLDM_PLATFORM_INVALID_EFFECTER_ID;
Sampa Misraa2fa0702019-05-31 01:28:55 -0500350 }
Sampa Misraa2fa0702019-05-31 01:28:55 -0500351
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600352 int rc = PLDM_SUCCESS;
George Liu1ec85d42020-02-12 16:05:32 +0800353 try
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600354 {
Patrick Williams6da4f912023-05-10 07:50:53 -0500355 const auto& [dbusMappings,
356 dbusValMaps] = effecterDbusObjMaps.at(effecterId);
George Liu1ec85d42020-02-12 16:05:32 +0800357 for (uint8_t currState = 0; currState < compEffecterCnt;
358 ++currState)
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600359 {
George Liu1ec85d42020-02-12 16:05:32 +0800360 std::vector<StateSetNum> allowed{};
361 // computation is based on table 79 from DSP0248 v1.1.1
Patrick Williams6da4f912023-05-10 07:50:53 -0500362 uint8_t bitfieldIndex = stateField[currState].effecter_state /
363 8;
364 uint8_t bit = stateField[currState].effecter_state -
365 (8 * bitfieldIndex);
George Liu1ec85d42020-02-12 16:05:32 +0800366 if (states->possible_states_size < bitfieldIndex ||
367 !(states->states[bitfieldIndex].byte & (1 << bit)))
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600368 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600369 error(
370 "Invalid state set value, EFFECTER_ID={EFFECTER_ID} VALUE={EFFECTER_STATE} COMPOSITE_EFFECTER_ID={CURR_STATE} DBUS_PATH={DBUS_OBJ_PATH}",
371 "EFFECTER_ID", (unsigned)effecterId, "EFFECTER_STATE",
372 (unsigned)stateField[currState].effecter_state,
373 "CURR_STATE", (unsigned)currState, "DBUS_OBJ_PATH",
374 dbusMappings[currState].objectPath.c_str());
George Liu1ec85d42020-02-12 16:05:32 +0800375 rc = PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600376 break;
377 }
George Liu1ec85d42020-02-12 16:05:32 +0800378 const DBusMapping& dbusMapping = dbusMappings[currState];
Brad Bishop5079ac42021-08-19 18:35:06 -0400379 const pldm::responder::pdr_utils::StatestoDbusVal&
380 dbusValToMap = dbusValMaps[currState];
George Liu1ec85d42020-02-12 16:05:32 +0800381
382 if (stateField[currState].set_request == PLDM_REQUEST_SET)
383 {
384 try
385 {
386 dBusIntf.setDbusProperty(
387 dbusMapping,
388 dbusValToMap.at(
389 stateField[currState].effecter_state));
390 }
391 catch (const std::exception& e)
392 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600393 error(
394 "Error setting property, ERROR={ERR_EXCEP} PROPERTY={DBUS_PROP} INTERFACE={DBUS_INTF} PATH={DBUS_OBJ_PATH}",
395 "ERR_EXCEP", e.what(), "DBUS_PROP",
396 dbusMapping.propertyName, "DBUS_INTF",
397 dbusMapping.interface, "DBUS_OBJ_PATH",
398 dbusMapping.objectPath.c_str());
George Liu1ec85d42020-02-12 16:05:32 +0800399 return PLDM_ERROR;
400 }
401 }
402 uint8_t* nextState =
403 reinterpret_cast<uint8_t*>(states) +
404 sizeof(state_effecter_possible_states) -
405 sizeof(states->states) +
406 (states->possible_states_size * sizeof(states->states));
407 states = reinterpret_cast<state_effecter_possible_states*>(
408 nextState);
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600409 }
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600410 }
George Liu1ec85d42020-02-12 16:05:32 +0800411 catch (const std::out_of_range& e)
412 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600413 error(
414 "the effecterId does not exist. effecter id: {EFFECTER_ID} {ERR_EXCEP}",
415 "EFFECTER_ID", (unsigned)effecterId, "ERR_EXCEP", e.what());
George Liu1ec85d42020-02-12 16:05:32 +0800416 }
417
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600418 return rc;
419 }
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600420
Sampa Misra12afe112020-05-25 11:40:44 -0500421 /** @brief Build BMC Terminus Locator PDR
422 *
423 * @param[in] repo - instance of concrete implementation of Repo
424 */
Brad Bishop5079ac42021-08-19 18:35:06 -0400425 void generateTerminusLocatorPDR(pldm::responder::pdr_utils::Repo& repo);
Sampa Misra12afe112020-05-25 11:40:44 -0500426
George Liuc4ea6a92020-07-14 15:48:44 +0800427 /** @brief Get std::map associated with the entity
428 * key: object path
429 * value: pldm_entity
430 *
431 * @return std::map<ObjectPath, pldm_entity>
432 */
433 inline const AssociatedEntityMap& getAssociateEntityMap() const
434 {
435 if (fruHandler == nullptr)
436 {
437 throw InternalFailure();
438 }
439 return fruHandler->getAssociateEntityMap();
440 }
441
Sampa Misra5fb37d52021-03-06 07:26:00 -0600442 /** @brief process the actions that needs to be performed after a GetPDR
443 * call is received
444 * @param[in] source - sdeventplus event source
445 */
446 void _processPostGetPDRActions(sdeventplus::source::EventBase& source);
447
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600448 private:
449 pdr_utils::Repo pdrRepo;
450 uint16_t nextEffecterId{};
George Liuadbe1722020-05-09 19:20:19 +0800451 uint16_t nextSensorId{};
452 DbusObjMaps effecterDbusObjMaps{};
453 DbusObjMaps sensorDbusObjMaps{};
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500454 HostPDRHandler* hostPDRHandler;
Brad Bishop5079ac42021-08-19 18:35:06 -0400455 pldm::state_sensor::DbusToPLDMEvent* dbusToPLDMEventHandler;
Tom Joseph33e9c7e2020-06-11 22:09:52 +0530456 fru::Handler* fruHandler;
Deepak Kodihallib5c227e2020-07-13 06:58:34 -0500457 const pldm::utils::DBusHandler* dBusIntf;
Sampa Misraaea5dde2020-08-31 08:33:47 -0500458 pldm::responder::oem_platform::Handler* oemPlatformHandler;
Sampa Misra5fb37d52021-03-06 07:26:00 -0600459 sdeventplus::Event& event;
Deepak Kodihallib5c227e2020-07-13 06:58:34 -0500460 std::string pdrJsonsDir;
461 bool pdrCreated;
Sampa Misra5fb37d52021-03-06 07:26:00 -0600462 std::unique_ptr<sdeventplus::source::Defer> deferredGetPDREvent;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600463};
464
Sampa Misraaea5dde2020-08-31 08:33:47 -0500465/** @brief Function to check if a sensor falls in OEM range
466 * A sensor is considered to be oem if either of entity
467 * type or state set or both falls in oem range
468 *
469 * @param[in] handler - the interface object
470 * @param[in] sensorId - sensor id
471 * @param[in] sensorRearmCount - sensor rearm count
472 * @param[out] compSensorCnt - composite sensor count
473 * @param[out] entityType - entity type
474 * @param[out] entityInstance - entity instance number
475 * @param[out] stateSetId - state set id
476 *
477 * @return true if the sensor is OEM. All out parameters are invalid
478 * for a non OEM sensor
479 */
480bool isOemStateSensor(Handler& handler, uint16_t sensorId,
481 uint8_t sensorRearmCount, uint8_t& compSensorCnt,
482 uint16_t& entityType, uint16_t& entityInstance,
483 uint16_t& stateSetId);
484
485/** @brief Function to check if an effecter falls in OEM range
486 * An effecter is considered to be oem if either of entity
487 * type or state set or both falls in oem range
488 *
489 * @param[in] handler - the interface object
490 * @param[in] effecterId - effecter id
491 * @param[in] compEffecterCnt - composite effecter count
492 * @param[out] entityType - entity type
493 * @param[out] entityInstance - entity instance number
494 * @param[out] stateSetId - state set id
495 *
496 * @return true if the effecter is OEM. All out parameters are invalid
497 * for a non OEM effecter
498 */
499bool isOemStateEffecter(Handler& handler, uint16_t effecterId,
500 uint8_t compEffecterCnt, uint16_t& entityType,
501 uint16_t& entityInstance, uint16_t& stateSetId);
502
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600503} // namespace platform
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530504} // namespace responder
505} // namespace pldm