blob: 8df96258e133d20f28c068041ca475b18afdea34 [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 });
Archana Kakani6ece21fb2023-10-10 08:21:52 -050080 handlers.emplace(PLDM_GET_NUMERIC_EFFECTER_VALUE,
81 [this](const pldm_msg* request, size_t payloadLength) {
82 return this->getNumericEffecterValue(request, payloadLength);
83 });
Deepak Kodihallibc669f12019-11-28 08:52:07 -060084 handlers.emplace(PLDM_SET_STATE_EFFECTER_STATES,
85 [this](const pldm_msg* request, size_t payloadLength) {
Patrick Williams6da4f912023-05-10 07:50:53 -050086 return this->setStateEffecterStates(request, 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) {
Patrick Williams6da4f912023-05-10 07:50:53 -050090 return this->platformEventMessage(request, payloadLength);
91 });
George Liu362c18d2020-05-14 09:46:36 +080092 handlers.emplace(PLDM_GET_STATE_SENSOR_READINGS,
93 [this](const pldm_msg* request, size_t payloadLength) {
Patrick Williams6da4f912023-05-10 07:50:53 -050094 return this->getStateSensorReadings(request, payloadLength);
95 });
Tom Joseph56e45c52020-03-16 10:01:45 +053096
97 // Default handler for PLDM Events
98 eventHandlers[PLDM_SENSOR_EVENT].emplace_back(
99 [this](const pldm_msg* request, size_t payloadLength,
100 uint8_t formatVersion, uint8_t tid, size_t eventDataOffset) {
Patrick Williams6da4f912023-05-10 07:50:53 -0500101 return this->sensorEvent(request, payloadLength, formatVersion, tid,
102 eventDataOffset);
103 });
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500104 eventHandlers[PLDM_PDR_REPOSITORY_CHG_EVENT].emplace_back(
105 [this](const pldm_msg* request, size_t payloadLength,
106 uint8_t formatVersion, uint8_t tid, size_t eventDataOffset) {
Patrick Williams6da4f912023-05-10 07:50:53 -0500107 return this->pldmPDRRepositoryChgEvent(
108 request, payloadLength, formatVersion, tid, eventDataOffset);
109 });
Tom Joseph56e45c52020-03-16 10:01:45 +0530110
111 // Additional OEM event handlers for PLDM events, append it to the
112 // standard handlers
113 if (addOnHandlersMap)
114 {
115 auto addOnHandlers = addOnHandlersMap.value();
116 for (EventMap::iterator iter = addOnHandlers.begin();
117 iter != addOnHandlers.end(); ++iter)
118 {
119 auto search = eventHandlers.find(iter->first);
120 if (search != eventHandlers.end())
121 {
122 search->second.insert(std::end(search->second),
123 std::begin(iter->second),
124 std::end(iter->second));
125 }
126 else
127 {
128 eventHandlers.emplace(iter->first, iter->second);
129 }
130 }
131 }
Sampa Misraa2fa0702019-05-31 01:28:55 -0500132 }
133
George Liu1ec85d42020-02-12 16:05:32 +0800134 pdr_utils::Repo& getRepo()
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600135 {
George Liu1ec85d42020-02-12 16:05:32 +0800136 return this->pdrRepo;
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600137 }
138
George Liu1ec85d42020-02-12 16:05:32 +0800139 /** @brief Add D-Bus mapping and value mapping(stateId to D-Bus) for the
George Liuadbe1722020-05-09 19:20:19 +0800140 * Id. If the same id is added, the previous dbusObjs will
George Liu1ec85d42020-02-12 16:05:32 +0800141 * be "over-written".
142 *
George Liuadbe1722020-05-09 19:20:19 +0800143 * @param[in] Id - effecter/sensor id
George Liu1ec85d42020-02-12 16:05:32 +0800144 * @param[in] dbusObj - list of D-Bus object structure and list of D-Bus
145 * property value to attribute value
George Liuadbe1722020-05-09 19:20:19 +0800146 * @param[in] typeId - the type id of enum
George Liu1ec85d42020-02-12 16:05:32 +0800147 */
George Liua2870722020-02-11 11:09:30 +0800148 void addDbusObjMaps(
George Liuadbe1722020-05-09 19:20:19 +0800149 uint16_t id,
150 std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> dbusObj,
Brad Bishop5079ac42021-08-19 18:35:06 -0400151 pldm::responder::pdr_utils::TypeId typeId =
152 pldm::responder::pdr_utils::TypeId::PLDM_EFFECTER_ID);
George Liu1ec85d42020-02-12 16:05:32 +0800153
George Liuadbe1722020-05-09 19:20:19 +0800154 /** @brief Retrieve an id -> D-Bus objects mapping
George Liu1ec85d42020-02-12 16:05:32 +0800155 *
George Liuadbe1722020-05-09 19:20:19 +0800156 * @param[in] Id - id
157 * @param[in] typeId - the type id of enum
George Liu1ec85d42020-02-12 16:05:32 +0800158 *
George Liua2870722020-02-11 11:09:30 +0800159 * @return std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> -
160 * list of D-Bus object structure and list of D-Bus property value
161 * to attribute value
George Liu1ec85d42020-02-12 16:05:32 +0800162 */
George Liua2870722020-02-11 11:09:30 +0800163 const std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>&
Brad Bishop5079ac42021-08-19 18:35:06 -0400164 getDbusObjMaps(
165 uint16_t id,
166 pldm::responder::pdr_utils::TypeId typeId =
167 pldm::responder::pdr_utils::TypeId::PLDM_EFFECTER_ID) const;
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600168
169 uint16_t getNextEffecterId()
170 {
171 return ++nextEffecterId;
172 }
173
George Liuadbe1722020-05-09 19:20:19 +0800174 uint16_t getNextSensorId()
175 {
176 return ++nextSensorId;
177 }
178
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600179 /** @brief Parse PDR JSONs and build PDR repository
180 *
George Liu36e81352020-07-01 14:40:30 +0800181 * @param[in] dBusIntf - The interface object
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600182 * @param[in] dir - directory housing platform specific PDR JSON files
183 * @param[in] repo - instance of concrete implementation of Repo
184 */
George Liu36e81352020-07-01 14:40:30 +0800185 void generate(const pldm::utils::DBusHandler& dBusIntf,
Brad Bishop5079ac42021-08-19 18:35:06 -0400186 const std::string& dir,
187 pldm::responder::pdr_utils::Repo& repo);
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600188
189 /** @brief Parse PDR JSONs and build state effecter PDR repository
190 *
191 * @param[in] json - platform specific PDR JSON files
192 * @param[in] repo - instance of state effecter implementation of Repo
193 */
Brad Bishop5079ac42021-08-19 18:35:06 -0400194 void generateStateEffecterRepo(const pldm::utils::Json& json,
195 pldm::responder::pdr_utils::Repo& repo);
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600196
Tom Joseph56e45c52020-03-16 10:01:45 +0530197 /** @brief map of PLDM event type to EventHandlers
198 *
199 */
200 EventMap eventHandlers;
201
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600202 /** @brief Handler for GetPDR
203 *
204 * @param[in] request - Request message payload
205 * @param[in] payloadLength - Request payload length
206 * @param[out] Response - Response message written here
207 */
208 Response getPDR(const pldm_msg* request, size_t payloadLength);
Sampa Misraa2fa0702019-05-31 01:28:55 -0500209
George Liueccb0c52020-01-14 11:09:56 +0800210 /** @brief Handler for setNumericEffecterValue
211 *
212 * @param[in] request - Request message
213 * @param[in] payloadLength - Request payload length
214 * @return Response - PLDM Response message
215 */
216 Response setNumericEffecterValue(const pldm_msg* request,
217 size_t payloadLength);
218
Archana Kakani6ece21fb2023-10-10 08:21:52 -0500219 /** @brief Handler for getNumericEffecterValue
220 *
221 * @param[in] request - Request message
222 * @param[in] payloadLength - Request payload length
223 * @return Response - PLDM Response message
224 */
225 Response getNumericEffecterValue(const pldm_msg* request,
226 size_t payloadLength);
227
George Liu362c18d2020-05-14 09:46:36 +0800228 /** @brief Handler for getStateSensorReadings
229 *
230 * @param[in] request - Request message
231 * @param[in] payloadLength - Request payload length
232 * @return Response - PLDM Response message
233 */
234 Response getStateSensorReadings(const pldm_msg* request,
235 size_t payloadLength);
236
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600237 /** @brief Handler for setStateEffecterStates
238 *
239 * @param[in] request - Request message
240 * @param[in] payloadLength - Request payload length
241 * @return Response - PLDM Response message
242 */
243 Response setStateEffecterStates(const pldm_msg* request,
244 size_t payloadLength);
245
Tom Joseph56e45c52020-03-16 10:01:45 +0530246 /** @brief Handler for PlatformEventMessage
247 *
248 * @param[in] request - Request message
249 * @param[in] payloadLength - Request payload length
250 * @return Response - PLDM Response message
251 */
252 Response platformEventMessage(const pldm_msg* request,
253 size_t payloadLength);
254
255 /** @brief Handler for event class Sensor event
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 sensorEvent(const pldm_msg* request, size_t payloadLength,
266 uint8_t formatVersion, uint8_t tid, size_t eventDataOffset);
267
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500268 /** @brief Handler for pldmPDRRepositoryChgEvent
269 *
270 * @param[in] request - Request message
271 * @param[in] payloadLength - Request payload length
272 * @param[in] formatVersion - Version of the event format
273 * @param[in] tid - Terminus ID of the event's originator
274 * @param[in] eventDataOffset - Offset of the event data in the request
275 * message
276 * @return PLDM completion code
277 */
278 int pldmPDRRepositoryChgEvent(const pldm_msg* request, size_t payloadLength,
279 uint8_t formatVersion, uint8_t tid,
280 size_t eventDataOffset);
281
282 /** @brief Handler for extracting the PDR handles from changeEntries
283 *
284 * @param[in] changeEntryData - ChangeEntry data from changeRecord
285 * @param[in] changeEntryDataSize - total size of changeEntryData
286 * @param[in] numberOfChangeEntries - total number of changeEntries to
287 * extract
288 * @param[out] pdrRecordHandles - std::vector where the extracted PDR
289 * handles are placed
290 * @return PLDM completion code
291 */
292 int getPDRRecordHandles(const ChangeEntry* changeEntryData,
293 size_t changeEntryDataSize,
294 size_t numberOfChangeEntries,
295 PDRRecordHandles& pdrRecordHandles);
296
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600297 /** @brief Function to set the effecter requested by pldm requester
298 * @param[in] dBusIntf - The interface object
299 * @param[in] effecterId - Effecter ID sent by the requester to act on
300 * @param[in] stateField - The state field data for each of the states,
301 * equal to composite effecter count in number
302 * @return - Success or failure in setting the states. Returns failure in
303 * terms of PLDM completion codes if atleast one state fails to be set
304 */
305 template <class DBusInterface>
306 int setStateEffecterStatesHandler(
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600307 const DBusInterface& dBusIntf, uint16_t effecterId,
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600308 const std::vector<set_effecter_state_field>& stateField)
Sampa Misraa2fa0702019-05-31 01:28:55 -0500309 {
George Liue53193f2020-02-24 09:23:26 +0800310 using namespace pldm::responder::pdr;
George Liu1e44c732020-02-28 20:20:06 +0800311 using namespace pldm::utils;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600312 using StateSetNum = uint8_t;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600313
314 state_effecter_possible_states* states = nullptr;
315 pldm_state_effecter_pdr* pdr = nullptr;
316 uint8_t compEffecterCnt = stateField.size();
George Liu1ec85d42020-02-12 16:05:32 +0800317
318 std::unique_ptr<pldm_pdr, decltype(&pldm_pdr_destroy)>
319 stateEffecterPdrRepo(pldm_pdr_init(), pldm_pdr_destroy);
Andrew Jefferyacb20292023-06-30 11:47:44 +0930320 if (!stateEffecterPdrRepo)
321 {
322 throw std::runtime_error(
323 "Failed to instantiate state effecter PDR repository");
324 }
Brad Bishop5079ac42021-08-19 18:35:06 -0400325 pldm::responder::pdr_utils::Repo stateEffecterPDRs(
326 stateEffecterPdrRepo.get());
George Liu1ec85d42020-02-12 16:05:32 +0800327 getRepoByType(pdrRepo, stateEffecterPDRs, PLDM_STATE_EFFECTER_PDR);
328 if (stateEffecterPDRs.empty())
329 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600330 error("Failed to get record by PDR type");
George Liu1ec85d42020-02-12 16:05:32 +0800331 return PLDM_PLATFORM_INVALID_EFFECTER_ID;
332 }
333
Brad Bishop5079ac42021-08-19 18:35:06 -0400334 pldm::responder::pdr_utils::PdrEntry pdrEntry{};
George Liu1ec85d42020-02-12 16:05:32 +0800335 auto pdrRecord = stateEffecterPDRs.getFirstRecord(pdrEntry);
George Liue53193f2020-02-24 09:23:26 +0800336 while (pdrRecord)
337 {
338 pdr = reinterpret_cast<pldm_state_effecter_pdr*>(pdrEntry.data);
339 if (pdr->effecter_id != effecterId)
Sampa Misraa2fa0702019-05-31 01:28:55 -0500340 {
George Liue53193f2020-02-24 09:23:26 +0800341 pdr = nullptr;
Patrick Williams6da4f912023-05-10 07:50:53 -0500342 pdrRecord = stateEffecterPDRs.getNextRecord(pdrRecord,
343 pdrEntry);
George Liue53193f2020-02-24 09:23:26 +0800344 continue;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600345 }
George Liue53193f2020-02-24 09:23:26 +0800346
347 states = reinterpret_cast<state_effecter_possible_states*>(
348 pdr->possible_states);
349 if (compEffecterCnt > pdr->composite_effecter_count)
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600350 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600351 error(
352 "The requester sent wrong composite effecter count for the effecter, EFFECTER_ID={EFFECTER_ID} COMP_EFF_CNT={COMP_EFF_CNT}",
353 "EFFECTER_ID", (unsigned)effecterId, "COMP_EFF_CNT",
354 (unsigned)compEffecterCnt);
George Liue53193f2020-02-24 09:23:26 +0800355 return PLDM_ERROR_INVALID_DATA;
Sampa Misraa2fa0702019-05-31 01:28:55 -0500356 }
George Liue53193f2020-02-24 09:23:26 +0800357 break;
358 }
359
360 if (!pdr)
361 {
362 return PLDM_PLATFORM_INVALID_EFFECTER_ID;
Sampa Misraa2fa0702019-05-31 01:28:55 -0500363 }
Sampa Misraa2fa0702019-05-31 01:28:55 -0500364
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600365 int rc = PLDM_SUCCESS;
George Liu1ec85d42020-02-12 16:05:32 +0800366 try
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600367 {
Patrick Williams6da4f912023-05-10 07:50:53 -0500368 const auto& [dbusMappings,
369 dbusValMaps] = effecterDbusObjMaps.at(effecterId);
George Liu1ec85d42020-02-12 16:05:32 +0800370 for (uint8_t currState = 0; currState < compEffecterCnt;
371 ++currState)
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600372 {
George Liu1ec85d42020-02-12 16:05:32 +0800373 std::vector<StateSetNum> allowed{};
374 // computation is based on table 79 from DSP0248 v1.1.1
Patrick Williams6da4f912023-05-10 07:50:53 -0500375 uint8_t bitfieldIndex = stateField[currState].effecter_state /
376 8;
377 uint8_t bit = stateField[currState].effecter_state -
378 (8 * bitfieldIndex);
George Liu1ec85d42020-02-12 16:05:32 +0800379 if (states->possible_states_size < bitfieldIndex ||
380 !(states->states[bitfieldIndex].byte & (1 << bit)))
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600381 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600382 error(
383 "Invalid state set value, EFFECTER_ID={EFFECTER_ID} VALUE={EFFECTER_STATE} COMPOSITE_EFFECTER_ID={CURR_STATE} DBUS_PATH={DBUS_OBJ_PATH}",
384 "EFFECTER_ID", (unsigned)effecterId, "EFFECTER_STATE",
385 (unsigned)stateField[currState].effecter_state,
386 "CURR_STATE", (unsigned)currState, "DBUS_OBJ_PATH",
387 dbusMappings[currState].objectPath.c_str());
George Liu1ec85d42020-02-12 16:05:32 +0800388 rc = PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600389 break;
390 }
George Liu1ec85d42020-02-12 16:05:32 +0800391 const DBusMapping& dbusMapping = dbusMappings[currState];
Brad Bishop5079ac42021-08-19 18:35:06 -0400392 const pldm::responder::pdr_utils::StatestoDbusVal&
393 dbusValToMap = dbusValMaps[currState];
George Liu1ec85d42020-02-12 16:05:32 +0800394
395 if (stateField[currState].set_request == PLDM_REQUEST_SET)
396 {
397 try
398 {
399 dBusIntf.setDbusProperty(
400 dbusMapping,
401 dbusValToMap.at(
402 stateField[currState].effecter_state));
403 }
404 catch (const std::exception& e)
405 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600406 error(
407 "Error setting property, ERROR={ERR_EXCEP} PROPERTY={DBUS_PROP} INTERFACE={DBUS_INTF} PATH={DBUS_OBJ_PATH}",
408 "ERR_EXCEP", e.what(), "DBUS_PROP",
409 dbusMapping.propertyName, "DBUS_INTF",
410 dbusMapping.interface, "DBUS_OBJ_PATH",
411 dbusMapping.objectPath.c_str());
George Liu1ec85d42020-02-12 16:05:32 +0800412 return PLDM_ERROR;
413 }
414 }
415 uint8_t* nextState =
416 reinterpret_cast<uint8_t*>(states) +
417 sizeof(state_effecter_possible_states) -
418 sizeof(states->states) +
419 (states->possible_states_size * sizeof(states->states));
420 states = reinterpret_cast<state_effecter_possible_states*>(
421 nextState);
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600422 }
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600423 }
George Liu1ec85d42020-02-12 16:05:32 +0800424 catch (const std::out_of_range& e)
425 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600426 error(
427 "the effecterId does not exist. effecter id: {EFFECTER_ID} {ERR_EXCEP}",
428 "EFFECTER_ID", (unsigned)effecterId, "ERR_EXCEP", e.what());
George Liu1ec85d42020-02-12 16:05:32 +0800429 }
430
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600431 return rc;
432 }
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600433
Sampa Misra12afe112020-05-25 11:40:44 -0500434 /** @brief Build BMC Terminus Locator PDR
435 *
436 * @param[in] repo - instance of concrete implementation of Repo
437 */
Brad Bishop5079ac42021-08-19 18:35:06 -0400438 void generateTerminusLocatorPDR(pldm::responder::pdr_utils::Repo& repo);
Sampa Misra12afe112020-05-25 11:40:44 -0500439
George Liuc4ea6a92020-07-14 15:48:44 +0800440 /** @brief Get std::map associated with the entity
441 * key: object path
442 * value: pldm_entity
443 *
444 * @return std::map<ObjectPath, pldm_entity>
445 */
446 inline const AssociatedEntityMap& getAssociateEntityMap() const
447 {
448 if (fruHandler == nullptr)
449 {
450 throw InternalFailure();
451 }
452 return fruHandler->getAssociateEntityMap();
453 }
454
Sampa Misra5fb37d52021-03-06 07:26:00 -0600455 /** @brief process the actions that needs to be performed after a GetPDR
456 * call is received
457 * @param[in] source - sdeventplus event source
458 */
459 void _processPostGetPDRActions(sdeventplus::source::EventBase& source);
460
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600461 private:
462 pdr_utils::Repo pdrRepo;
463 uint16_t nextEffecterId{};
George Liuadbe1722020-05-09 19:20:19 +0800464 uint16_t nextSensorId{};
465 DbusObjMaps effecterDbusObjMaps{};
466 DbusObjMaps sensorDbusObjMaps{};
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500467 HostPDRHandler* hostPDRHandler;
Brad Bishop5079ac42021-08-19 18:35:06 -0400468 pldm::state_sensor::DbusToPLDMEvent* dbusToPLDMEventHandler;
Tom Joseph33e9c7e2020-06-11 22:09:52 +0530469 fru::Handler* fruHandler;
Deepak Kodihallib5c227e2020-07-13 06:58:34 -0500470 const pldm::utils::DBusHandler* dBusIntf;
Sampa Misraaea5dde2020-08-31 08:33:47 -0500471 pldm::responder::oem_platform::Handler* oemPlatformHandler;
Sampa Misra5fb37d52021-03-06 07:26:00 -0600472 sdeventplus::Event& event;
Deepak Kodihallib5c227e2020-07-13 06:58:34 -0500473 std::string pdrJsonsDir;
474 bool pdrCreated;
Sampa Misra5fb37d52021-03-06 07:26:00 -0600475 std::unique_ptr<sdeventplus::source::Defer> deferredGetPDREvent;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600476};
477
Sampa Misraaea5dde2020-08-31 08:33:47 -0500478/** @brief Function to check if a sensor falls in OEM range
479 * A sensor is considered to be oem if either of entity
480 * type or state set or both falls in oem range
481 *
482 * @param[in] handler - the interface object
483 * @param[in] sensorId - sensor id
484 * @param[in] sensorRearmCount - sensor rearm count
485 * @param[out] compSensorCnt - composite sensor count
486 * @param[out] entityType - entity type
487 * @param[out] entityInstance - entity instance number
488 * @param[out] stateSetId - state set id
489 *
490 * @return true if the sensor is OEM. All out parameters are invalid
491 * for a non OEM sensor
492 */
493bool isOemStateSensor(Handler& handler, uint16_t sensorId,
494 uint8_t sensorRearmCount, uint8_t& compSensorCnt,
495 uint16_t& entityType, uint16_t& entityInstance,
496 uint16_t& stateSetId);
497
498/** @brief Function to check if an effecter falls in OEM range
499 * An effecter is considered to be oem if either of entity
500 * type or state set or both falls in oem range
501 *
502 * @param[in] handler - the interface object
503 * @param[in] effecterId - effecter id
504 * @param[in] compEffecterCnt - composite effecter count
505 * @param[out] entityType - entity type
506 * @param[out] entityInstance - entity instance number
507 * @param[out] stateSetId - state set id
508 *
509 * @return true if the effecter is OEM. All out parameters are invalid
510 * for a non OEM effecter
511 */
512bool isOemStateEffecter(Handler& handler, uint16_t effecterId,
513 uint8_t compEffecterCnt, uint16_t& entityType,
514 uint16_t& entityInstance, uint16_t& stateSetId);
515
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600516} // namespace platform
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530517} // namespace responder
518} // namespace pldm