blob: 19f2a78689db644fbc847d1f1683bf4186d8b90b [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) {
Patrick Williams6da4f912023-05-10 07:50:53 -050076 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) {
Patrick Williams6da4f912023-05-10 07:50:53 -050080 return this->setNumericEffecterValue(request, payloadLength);
81 });
Deepak Kodihallibc669f12019-11-28 08:52:07 -060082 handlers.emplace(PLDM_SET_STATE_EFFECTER_STATES,
83 [this](const pldm_msg* request, size_t payloadLength) {
Patrick Williams6da4f912023-05-10 07:50:53 -050084 return this->setStateEffecterStates(request, payloadLength);
85 });
Tom Joseph56e45c52020-03-16 10:01:45 +053086 handlers.emplace(PLDM_PLATFORM_EVENT_MESSAGE,
87 [this](const pldm_msg* request, size_t payloadLength) {
Patrick Williams6da4f912023-05-10 07:50:53 -050088 return this->platformEventMessage(request, payloadLength);
89 });
George Liu362c18d2020-05-14 09:46:36 +080090 handlers.emplace(PLDM_GET_STATE_SENSOR_READINGS,
91 [this](const pldm_msg* request, size_t payloadLength) {
Patrick Williams6da4f912023-05-10 07:50:53 -050092 return this->getStateSensorReadings(request, payloadLength);
93 });
Tom Joseph56e45c52020-03-16 10:01:45 +053094
95 // Default handler for PLDM Events
96 eventHandlers[PLDM_SENSOR_EVENT].emplace_back(
97 [this](const pldm_msg* request, size_t payloadLength,
98 uint8_t formatVersion, uint8_t tid, size_t eventDataOffset) {
Patrick Williams6da4f912023-05-10 07:50:53 -050099 return this->sensorEvent(request, payloadLength, formatVersion, tid,
100 eventDataOffset);
101 });
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500102 eventHandlers[PLDM_PDR_REPOSITORY_CHG_EVENT].emplace_back(
103 [this](const pldm_msg* request, size_t payloadLength,
104 uint8_t formatVersion, uint8_t tid, size_t eventDataOffset) {
Patrick Williams6da4f912023-05-10 07:50:53 -0500105 return this->pldmPDRRepositoryChgEvent(
106 request, payloadLength, formatVersion, tid, eventDataOffset);
107 });
Tom Joseph56e45c52020-03-16 10:01:45 +0530108
109 // Additional OEM event handlers for PLDM events, append it to the
110 // standard handlers
111 if (addOnHandlersMap)
112 {
113 auto addOnHandlers = addOnHandlersMap.value();
114 for (EventMap::iterator iter = addOnHandlers.begin();
115 iter != addOnHandlers.end(); ++iter)
116 {
117 auto search = eventHandlers.find(iter->first);
118 if (search != eventHandlers.end())
119 {
120 search->second.insert(std::end(search->second),
121 std::begin(iter->second),
122 std::end(iter->second));
123 }
124 else
125 {
126 eventHandlers.emplace(iter->first, iter->second);
127 }
128 }
129 }
Sampa Misraa2fa0702019-05-31 01:28:55 -0500130 }
131
George Liu1ec85d42020-02-12 16:05:32 +0800132 pdr_utils::Repo& getRepo()
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600133 {
George Liu1ec85d42020-02-12 16:05:32 +0800134 return this->pdrRepo;
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600135 }
136
George Liu1ec85d42020-02-12 16:05:32 +0800137 /** @brief Add D-Bus mapping and value mapping(stateId to D-Bus) for the
George Liuadbe1722020-05-09 19:20:19 +0800138 * Id. If the same id is added, the previous dbusObjs will
George Liu1ec85d42020-02-12 16:05:32 +0800139 * be "over-written".
140 *
George Liuadbe1722020-05-09 19:20:19 +0800141 * @param[in] Id - effecter/sensor id
George Liu1ec85d42020-02-12 16:05:32 +0800142 * @param[in] dbusObj - list of D-Bus object structure and list of D-Bus
143 * property value to attribute value
George Liuadbe1722020-05-09 19:20:19 +0800144 * @param[in] typeId - the type id of enum
George Liu1ec85d42020-02-12 16:05:32 +0800145 */
George Liua2870722020-02-11 11:09:30 +0800146 void addDbusObjMaps(
George Liuadbe1722020-05-09 19:20:19 +0800147 uint16_t id,
148 std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> dbusObj,
Brad Bishop5079ac42021-08-19 18:35:06 -0400149 pldm::responder::pdr_utils::TypeId typeId =
150 pldm::responder::pdr_utils::TypeId::PLDM_EFFECTER_ID);
George Liu1ec85d42020-02-12 16:05:32 +0800151
George Liuadbe1722020-05-09 19:20:19 +0800152 /** @brief Retrieve an id -> D-Bus objects mapping
George Liu1ec85d42020-02-12 16:05:32 +0800153 *
George Liuadbe1722020-05-09 19:20:19 +0800154 * @param[in] Id - id
155 * @param[in] typeId - the type id of enum
George Liu1ec85d42020-02-12 16:05:32 +0800156 *
George Liua2870722020-02-11 11:09:30 +0800157 * @return std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> -
158 * list of D-Bus object structure and list of D-Bus property value
159 * to attribute value
George Liu1ec85d42020-02-12 16:05:32 +0800160 */
George Liua2870722020-02-11 11:09:30 +0800161 const std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>&
Brad Bishop5079ac42021-08-19 18:35:06 -0400162 getDbusObjMaps(
163 uint16_t id,
164 pldm::responder::pdr_utils::TypeId typeId =
165 pldm::responder::pdr_utils::TypeId::PLDM_EFFECTER_ID) const;
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600166
167 uint16_t getNextEffecterId()
168 {
169 return ++nextEffecterId;
170 }
171
George Liuadbe1722020-05-09 19:20:19 +0800172 uint16_t getNextSensorId()
173 {
174 return ++nextSensorId;
175 }
176
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600177 /** @brief Parse PDR JSONs and build PDR repository
178 *
George Liu36e81352020-07-01 14:40:30 +0800179 * @param[in] dBusIntf - The interface object
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600180 * @param[in] dir - directory housing platform specific PDR JSON files
181 * @param[in] repo - instance of concrete implementation of Repo
182 */
George Liu36e81352020-07-01 14:40:30 +0800183 void generate(const pldm::utils::DBusHandler& dBusIntf,
Brad Bishop5079ac42021-08-19 18:35:06 -0400184 const std::string& dir,
185 pldm::responder::pdr_utils::Repo& repo);
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600186
187 /** @brief Parse PDR JSONs and build state effecter PDR repository
188 *
189 * @param[in] json - platform specific PDR JSON files
190 * @param[in] repo - instance of state effecter implementation of Repo
191 */
Brad Bishop5079ac42021-08-19 18:35:06 -0400192 void generateStateEffecterRepo(const pldm::utils::Json& json,
193 pldm::responder::pdr_utils::Repo& repo);
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600194
Tom Joseph56e45c52020-03-16 10:01:45 +0530195 /** @brief map of PLDM event type to EventHandlers
196 *
197 */
198 EventMap eventHandlers;
199
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600200 /** @brief Handler for GetPDR
201 *
202 * @param[in] request - Request message payload
203 * @param[in] payloadLength - Request payload length
204 * @param[out] Response - Response message written here
205 */
206 Response getPDR(const pldm_msg* request, size_t payloadLength);
Sampa Misraa2fa0702019-05-31 01:28:55 -0500207
George Liueccb0c52020-01-14 11:09:56 +0800208 /** @brief Handler for setNumericEffecterValue
209 *
210 * @param[in] request - Request message
211 * @param[in] payloadLength - Request payload length
212 * @return Response - PLDM Response message
213 */
214 Response setNumericEffecterValue(const pldm_msg* request,
215 size_t payloadLength);
216
George Liu362c18d2020-05-14 09:46:36 +0800217 /** @brief Handler for getStateSensorReadings
218 *
219 * @param[in] request - Request message
220 * @param[in] payloadLength - Request payload length
221 * @return Response - PLDM Response message
222 */
223 Response getStateSensorReadings(const pldm_msg* request,
224 size_t payloadLength);
225
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600226 /** @brief Handler for setStateEffecterStates
227 *
228 * @param[in] request - Request message
229 * @param[in] payloadLength - Request payload length
230 * @return Response - PLDM Response message
231 */
232 Response setStateEffecterStates(const pldm_msg* request,
233 size_t payloadLength);
234
Tom Joseph56e45c52020-03-16 10:01:45 +0530235 /** @brief Handler for PlatformEventMessage
236 *
237 * @param[in] request - Request message
238 * @param[in] payloadLength - Request payload length
239 * @return Response - PLDM Response message
240 */
241 Response platformEventMessage(const pldm_msg* request,
242 size_t payloadLength);
243
244 /** @brief Handler for event class Sensor event
245 *
246 * @param[in] request - Request message
247 * @param[in] payloadLength - Request payload length
248 * @param[in] formatVersion - Version of the event format
249 * @param[in] tid - Terminus ID of the event's originator
250 * @param[in] eventDataOffset - Offset of the event data in the request
251 * message
252 * @return PLDM completion code
253 */
254 int sensorEvent(const pldm_msg* request, size_t payloadLength,
255 uint8_t formatVersion, uint8_t tid, size_t eventDataOffset);
256
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500257 /** @brief Handler for pldmPDRRepositoryChgEvent
258 *
259 * @param[in] request - Request message
260 * @param[in] payloadLength - Request payload length
261 * @param[in] formatVersion - Version of the event format
262 * @param[in] tid - Terminus ID of the event's originator
263 * @param[in] eventDataOffset - Offset of the event data in the request
264 * message
265 * @return PLDM completion code
266 */
267 int pldmPDRRepositoryChgEvent(const pldm_msg* request, size_t payloadLength,
268 uint8_t formatVersion, uint8_t tid,
269 size_t eventDataOffset);
270
271 /** @brief Handler for extracting the PDR handles from changeEntries
272 *
273 * @param[in] changeEntryData - ChangeEntry data from changeRecord
274 * @param[in] changeEntryDataSize - total size of changeEntryData
275 * @param[in] numberOfChangeEntries - total number of changeEntries to
276 * extract
277 * @param[out] pdrRecordHandles - std::vector where the extracted PDR
278 * handles are placed
279 * @return PLDM completion code
280 */
281 int getPDRRecordHandles(const ChangeEntry* changeEntryData,
282 size_t changeEntryDataSize,
283 size_t numberOfChangeEntries,
284 PDRRecordHandles& pdrRecordHandles);
285
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600286 /** @brief Function to set the effecter requested by pldm requester
287 * @param[in] dBusIntf - The interface object
288 * @param[in] effecterId - Effecter ID sent by the requester to act on
289 * @param[in] stateField - The state field data for each of the states,
290 * equal to composite effecter count in number
291 * @return - Success or failure in setting the states. Returns failure in
292 * terms of PLDM completion codes if atleast one state fails to be set
293 */
294 template <class DBusInterface>
295 int setStateEffecterStatesHandler(
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600296 const DBusInterface& dBusIntf, uint16_t effecterId,
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600297 const std::vector<set_effecter_state_field>& stateField)
Sampa Misraa2fa0702019-05-31 01:28:55 -0500298 {
George Liue53193f2020-02-24 09:23:26 +0800299 using namespace pldm::responder::pdr;
George Liu1e44c732020-02-28 20:20:06 +0800300 using namespace pldm::utils;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600301 using StateSetNum = uint8_t;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600302
303 state_effecter_possible_states* states = nullptr;
304 pldm_state_effecter_pdr* pdr = nullptr;
305 uint8_t compEffecterCnt = stateField.size();
George Liu1ec85d42020-02-12 16:05:32 +0800306
307 std::unique_ptr<pldm_pdr, decltype(&pldm_pdr_destroy)>
308 stateEffecterPdrRepo(pldm_pdr_init(), pldm_pdr_destroy);
Brad Bishop5079ac42021-08-19 18:35:06 -0400309 pldm::responder::pdr_utils::Repo stateEffecterPDRs(
310 stateEffecterPdrRepo.get());
George Liu1ec85d42020-02-12 16:05:32 +0800311 getRepoByType(pdrRepo, stateEffecterPDRs, PLDM_STATE_EFFECTER_PDR);
312 if (stateEffecterPDRs.empty())
313 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600314 error("Failed to get record by PDR type");
George Liu1ec85d42020-02-12 16:05:32 +0800315 return PLDM_PLATFORM_INVALID_EFFECTER_ID;
316 }
317
Brad Bishop5079ac42021-08-19 18:35:06 -0400318 pldm::responder::pdr_utils::PdrEntry pdrEntry{};
George Liu1ec85d42020-02-12 16:05:32 +0800319 auto pdrRecord = stateEffecterPDRs.getFirstRecord(pdrEntry);
George Liue53193f2020-02-24 09:23:26 +0800320 while (pdrRecord)
321 {
322 pdr = reinterpret_cast<pldm_state_effecter_pdr*>(pdrEntry.data);
323 if (pdr->effecter_id != effecterId)
Sampa Misraa2fa0702019-05-31 01:28:55 -0500324 {
George Liue53193f2020-02-24 09:23:26 +0800325 pdr = nullptr;
Patrick Williams6da4f912023-05-10 07:50:53 -0500326 pdrRecord = stateEffecterPDRs.getNextRecord(pdrRecord,
327 pdrEntry);
George Liue53193f2020-02-24 09:23:26 +0800328 continue;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600329 }
George Liue53193f2020-02-24 09:23:26 +0800330
331 states = reinterpret_cast<state_effecter_possible_states*>(
332 pdr->possible_states);
333 if (compEffecterCnt > pdr->composite_effecter_count)
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600334 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600335 error(
336 "The requester sent wrong composite effecter count for the effecter, EFFECTER_ID={EFFECTER_ID} COMP_EFF_CNT={COMP_EFF_CNT}",
337 "EFFECTER_ID", (unsigned)effecterId, "COMP_EFF_CNT",
338 (unsigned)compEffecterCnt);
George Liue53193f2020-02-24 09:23:26 +0800339 return PLDM_ERROR_INVALID_DATA;
Sampa Misraa2fa0702019-05-31 01:28:55 -0500340 }
George Liue53193f2020-02-24 09:23:26 +0800341 break;
342 }
343
344 if (!pdr)
345 {
346 return PLDM_PLATFORM_INVALID_EFFECTER_ID;
Sampa Misraa2fa0702019-05-31 01:28:55 -0500347 }
Sampa Misraa2fa0702019-05-31 01:28:55 -0500348
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600349 int rc = PLDM_SUCCESS;
George Liu1ec85d42020-02-12 16:05:32 +0800350 try
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600351 {
Patrick Williams6da4f912023-05-10 07:50:53 -0500352 const auto& [dbusMappings,
353 dbusValMaps] = effecterDbusObjMaps.at(effecterId);
George Liu1ec85d42020-02-12 16:05:32 +0800354 for (uint8_t currState = 0; currState < compEffecterCnt;
355 ++currState)
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600356 {
George Liu1ec85d42020-02-12 16:05:32 +0800357 std::vector<StateSetNum> allowed{};
358 // computation is based on table 79 from DSP0248 v1.1.1
Patrick Williams6da4f912023-05-10 07:50:53 -0500359 uint8_t bitfieldIndex = stateField[currState].effecter_state /
360 8;
361 uint8_t bit = stateField[currState].effecter_state -
362 (8 * bitfieldIndex);
George Liu1ec85d42020-02-12 16:05:32 +0800363 if (states->possible_states_size < bitfieldIndex ||
364 !(states->states[bitfieldIndex].byte & (1 << bit)))
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600365 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600366 error(
367 "Invalid state set value, EFFECTER_ID={EFFECTER_ID} VALUE={EFFECTER_STATE} COMPOSITE_EFFECTER_ID={CURR_STATE} DBUS_PATH={DBUS_OBJ_PATH}",
368 "EFFECTER_ID", (unsigned)effecterId, "EFFECTER_STATE",
369 (unsigned)stateField[currState].effecter_state,
370 "CURR_STATE", (unsigned)currState, "DBUS_OBJ_PATH",
371 dbusMappings[currState].objectPath.c_str());
George Liu1ec85d42020-02-12 16:05:32 +0800372 rc = PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600373 break;
374 }
George Liu1ec85d42020-02-12 16:05:32 +0800375 const DBusMapping& dbusMapping = dbusMappings[currState];
Brad Bishop5079ac42021-08-19 18:35:06 -0400376 const pldm::responder::pdr_utils::StatestoDbusVal&
377 dbusValToMap = dbusValMaps[currState];
George Liu1ec85d42020-02-12 16:05:32 +0800378
379 if (stateField[currState].set_request == PLDM_REQUEST_SET)
380 {
381 try
382 {
383 dBusIntf.setDbusProperty(
384 dbusMapping,
385 dbusValToMap.at(
386 stateField[currState].effecter_state));
387 }
388 catch (const std::exception& e)
389 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600390 error(
391 "Error setting property, ERROR={ERR_EXCEP} PROPERTY={DBUS_PROP} INTERFACE={DBUS_INTF} PATH={DBUS_OBJ_PATH}",
392 "ERR_EXCEP", e.what(), "DBUS_PROP",
393 dbusMapping.propertyName, "DBUS_INTF",
394 dbusMapping.interface, "DBUS_OBJ_PATH",
395 dbusMapping.objectPath.c_str());
George Liu1ec85d42020-02-12 16:05:32 +0800396 return PLDM_ERROR;
397 }
398 }
399 uint8_t* nextState =
400 reinterpret_cast<uint8_t*>(states) +
401 sizeof(state_effecter_possible_states) -
402 sizeof(states->states) +
403 (states->possible_states_size * sizeof(states->states));
404 states = reinterpret_cast<state_effecter_possible_states*>(
405 nextState);
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600406 }
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600407 }
George Liu1ec85d42020-02-12 16:05:32 +0800408 catch (const std::out_of_range& e)
409 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600410 error(
411 "the effecterId does not exist. effecter id: {EFFECTER_ID} {ERR_EXCEP}",
412 "EFFECTER_ID", (unsigned)effecterId, "ERR_EXCEP", e.what());
George Liu1ec85d42020-02-12 16:05:32 +0800413 }
414
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600415 return rc;
416 }
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600417
Sampa Misra12afe112020-05-25 11:40:44 -0500418 /** @brief Build BMC Terminus Locator PDR
419 *
420 * @param[in] repo - instance of concrete implementation of Repo
421 */
Brad Bishop5079ac42021-08-19 18:35:06 -0400422 void generateTerminusLocatorPDR(pldm::responder::pdr_utils::Repo& repo);
Sampa Misra12afe112020-05-25 11:40:44 -0500423
George Liuc4ea6a92020-07-14 15:48:44 +0800424 /** @brief Get std::map associated with the entity
425 * key: object path
426 * value: pldm_entity
427 *
428 * @return std::map<ObjectPath, pldm_entity>
429 */
430 inline const AssociatedEntityMap& getAssociateEntityMap() const
431 {
432 if (fruHandler == nullptr)
433 {
434 throw InternalFailure();
435 }
436 return fruHandler->getAssociateEntityMap();
437 }
438
Sampa Misra5fb37d52021-03-06 07:26:00 -0600439 /** @brief process the actions that needs to be performed after a GetPDR
440 * call is received
441 * @param[in] source - sdeventplus event source
442 */
443 void _processPostGetPDRActions(sdeventplus::source::EventBase& source);
444
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600445 private:
446 pdr_utils::Repo pdrRepo;
447 uint16_t nextEffecterId{};
George Liuadbe1722020-05-09 19:20:19 +0800448 uint16_t nextSensorId{};
449 DbusObjMaps effecterDbusObjMaps{};
450 DbusObjMaps sensorDbusObjMaps{};
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500451 HostPDRHandler* hostPDRHandler;
Brad Bishop5079ac42021-08-19 18:35:06 -0400452 pldm::state_sensor::DbusToPLDMEvent* dbusToPLDMEventHandler;
Tom Joseph33e9c7e2020-06-11 22:09:52 +0530453 fru::Handler* fruHandler;
Deepak Kodihallib5c227e2020-07-13 06:58:34 -0500454 const pldm::utils::DBusHandler* dBusIntf;
Sampa Misraaea5dde2020-08-31 08:33:47 -0500455 pldm::responder::oem_platform::Handler* oemPlatformHandler;
Sampa Misra5fb37d52021-03-06 07:26:00 -0600456 sdeventplus::Event& event;
Deepak Kodihallib5c227e2020-07-13 06:58:34 -0500457 std::string pdrJsonsDir;
458 bool pdrCreated;
Sampa Misra5fb37d52021-03-06 07:26:00 -0600459 std::unique_ptr<sdeventplus::source::Defer> deferredGetPDREvent;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600460};
461
Sampa Misraaea5dde2020-08-31 08:33:47 -0500462/** @brief Function to check if a sensor falls in OEM range
463 * A sensor is considered to be oem if either of entity
464 * type or state set or both falls in oem range
465 *
466 * @param[in] handler - the interface object
467 * @param[in] sensorId - sensor id
468 * @param[in] sensorRearmCount - sensor rearm count
469 * @param[out] compSensorCnt - composite sensor count
470 * @param[out] entityType - entity type
471 * @param[out] entityInstance - entity instance number
472 * @param[out] stateSetId - state set id
473 *
474 * @return true if the sensor is OEM. All out parameters are invalid
475 * for a non OEM sensor
476 */
477bool isOemStateSensor(Handler& handler, uint16_t sensorId,
478 uint8_t sensorRearmCount, uint8_t& compSensorCnt,
479 uint16_t& entityType, uint16_t& entityInstance,
480 uint16_t& stateSetId);
481
482/** @brief Function to check if an effecter falls in OEM range
483 * An effecter is considered to be oem if either of entity
484 * type or state set or both falls in oem range
485 *
486 * @param[in] handler - the interface object
487 * @param[in] effecterId - effecter id
488 * @param[in] compEffecterCnt - composite effecter count
489 * @param[out] entityType - entity type
490 * @param[out] entityInstance - entity instance number
491 * @param[out] stateSetId - state set id
492 *
493 * @return true if the effecter is OEM. All out parameters are invalid
494 * for a non OEM effecter
495 */
496bool isOemStateEffecter(Handler& handler, uint16_t effecterId,
497 uint8_t compEffecterCnt, uint16_t& entityType,
498 uint16_t& entityInstance, uint16_t& stateSetId);
499
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600500} // namespace platform
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530501} // namespace responder
502} // namespace pldm