blob: bf64f6bf97b45c4322f594ef0799b3091e4d7ac8 [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
Manojkiran Edab941eeb2022-08-18 07:11:22 +05305#include "libpldm/pdr.h"
George Liu6492f522020-06-16 10:34:05 +08006#include "libpldm/platform.h"
7#include "libpldm/states.h"
8
Deepak Kodihallid130e1a2020-06-17 05:55:32 -05009#include "common/utils.hpp"
TOM JOSEPHd4d97a52020-03-23 14:36:34 +053010#include "event_parser.hpp"
Tom Joseph33e9c7e2020-06-11 22:09:52 +053011#include "fru.hpp"
George Liucae18662020-05-15 09:32:57 +080012#include "host-bmc/dbus_to_event_handler.hpp"
Deepak Kodihalliac19bd62020-06-16 08:25:23 -050013#include "host-bmc/host_pdr_handler.hpp"
Sampa Misraa2fa0702019-05-31 01:28:55 -050014#include "libpldmresponder/pdr.hpp"
George Liue53193f2020-02-24 09:23:26 +080015#include "libpldmresponder/pdr_utils.hpp"
Sampa Misraaea5dde2020-08-31 08:33:47 -050016#include "oem_handler.hpp"
Deepak Kodihalli1521f6d2020-06-16 08:51:02 -050017#include "pldmd/handler.hpp"
Sampa Misraa2fa0702019-05-31 01:28:55 -050018
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053019#include <stdint.h>
20
Sampa Misraa2fa0702019-05-31 01:28:55 -050021#include <map>
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053022
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053023namespace pldm
24{
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053025namespace responder
26{
Sampa Misraa2fa0702019-05-31 01:28:55 -050027namespace platform
28{
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) {
74 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) {
78 return this->setNumericEffecterValue(
79 request, payloadLength);
80 });
Deepak Kodihallibc669f12019-11-28 08:52:07 -060081 handlers.emplace(PLDM_SET_STATE_EFFECTER_STATES,
82 [this](const pldm_msg* request, size_t payloadLength) {
83 return this->setStateEffecterStates(request,
84 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) {
88 return this->platformEventMessage(request,
89 payloadLength);
90 });
George Liu362c18d2020-05-14 09:46:36 +080091 handlers.emplace(PLDM_GET_STATE_SENSOR_READINGS,
92 [this](const pldm_msg* request, size_t payloadLength) {
93 return this->getStateSensorReadings(request,
94 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) {
101 return this->sensorEvent(request, payloadLength, formatVersion,
102 tid, 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) {
107 return this->pldmPDRRepositoryChgEvent(request, payloadLength,
108 formatVersion, tid,
109 eventDataOffset);
110 });
Tom Joseph56e45c52020-03-16 10:01:45 +0530111
112 // Additional OEM event handlers for PLDM events, append it to the
113 // standard handlers
114 if (addOnHandlersMap)
115 {
116 auto addOnHandlers = addOnHandlersMap.value();
117 for (EventMap::iterator iter = addOnHandlers.begin();
118 iter != addOnHandlers.end(); ++iter)
119 {
120 auto search = eventHandlers.find(iter->first);
121 if (search != eventHandlers.end())
122 {
123 search->second.insert(std::end(search->second),
124 std::begin(iter->second),
125 std::end(iter->second));
126 }
127 else
128 {
129 eventHandlers.emplace(iter->first, iter->second);
130 }
131 }
132 }
Sampa Misraa2fa0702019-05-31 01:28:55 -0500133 }
134
George Liu1ec85d42020-02-12 16:05:32 +0800135 pdr_utils::Repo& getRepo()
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600136 {
George Liu1ec85d42020-02-12 16:05:32 +0800137 return this->pdrRepo;
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600138 }
139
George Liu1ec85d42020-02-12 16:05:32 +0800140 /** @brief Add D-Bus mapping and value mapping(stateId to D-Bus) for the
George Liuadbe1722020-05-09 19:20:19 +0800141 * Id. If the same id is added, the previous dbusObjs will
George Liu1ec85d42020-02-12 16:05:32 +0800142 * be "over-written".
143 *
George Liuadbe1722020-05-09 19:20:19 +0800144 * @param[in] Id - effecter/sensor id
George Liu1ec85d42020-02-12 16:05:32 +0800145 * @param[in] dbusObj - list of D-Bus object structure and list of D-Bus
146 * property value to attribute value
George Liuadbe1722020-05-09 19:20:19 +0800147 * @param[in] typeId - the type id of enum
George Liu1ec85d42020-02-12 16:05:32 +0800148 */
George Liua2870722020-02-11 11:09:30 +0800149 void addDbusObjMaps(
George Liuadbe1722020-05-09 19:20:19 +0800150 uint16_t id,
151 std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> dbusObj,
Brad Bishop5079ac42021-08-19 18:35:06 -0400152 pldm::responder::pdr_utils::TypeId typeId =
153 pldm::responder::pdr_utils::TypeId::PLDM_EFFECTER_ID);
George Liu1ec85d42020-02-12 16:05:32 +0800154
George Liuadbe1722020-05-09 19:20:19 +0800155 /** @brief Retrieve an id -> D-Bus objects mapping
George Liu1ec85d42020-02-12 16:05:32 +0800156 *
George Liuadbe1722020-05-09 19:20:19 +0800157 * @param[in] Id - id
158 * @param[in] typeId - the type id of enum
George Liu1ec85d42020-02-12 16:05:32 +0800159 *
George Liua2870722020-02-11 11:09:30 +0800160 * @return std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> -
161 * list of D-Bus object structure and list of D-Bus property value
162 * to attribute value
George Liu1ec85d42020-02-12 16:05:32 +0800163 */
George Liua2870722020-02-11 11:09:30 +0800164 const std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>&
Brad Bishop5079ac42021-08-19 18:35:06 -0400165 getDbusObjMaps(
166 uint16_t id,
167 pldm::responder::pdr_utils::TypeId typeId =
168 pldm::responder::pdr_utils::TypeId::PLDM_EFFECTER_ID) const;
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600169
170 uint16_t getNextEffecterId()
171 {
172 return ++nextEffecterId;
173 }
174
George Liuadbe1722020-05-09 19:20:19 +0800175 uint16_t getNextSensorId()
176 {
177 return ++nextSensorId;
178 }
179
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600180 /** @brief Parse PDR JSONs and build PDR repository
181 *
George Liu36e81352020-07-01 14:40:30 +0800182 * @param[in] dBusIntf - The interface object
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600183 * @param[in] dir - directory housing platform specific PDR JSON files
184 * @param[in] repo - instance of concrete implementation of Repo
185 */
George Liu36e81352020-07-01 14:40:30 +0800186 void generate(const pldm::utils::DBusHandler& dBusIntf,
Brad Bishop5079ac42021-08-19 18:35:06 -0400187 const std::string& dir,
188 pldm::responder::pdr_utils::Repo& repo);
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600189
190 /** @brief Parse PDR JSONs and build state effecter PDR repository
191 *
192 * @param[in] json - platform specific PDR JSON files
193 * @param[in] repo - instance of state effecter implementation of Repo
194 */
Brad Bishop5079ac42021-08-19 18:35:06 -0400195 void generateStateEffecterRepo(const pldm::utils::Json& json,
196 pldm::responder::pdr_utils::Repo& repo);
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600197
Tom Joseph56e45c52020-03-16 10:01:45 +0530198 /** @brief map of PLDM event type to EventHandlers
199 *
200 */
201 EventMap eventHandlers;
202
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600203 /** @brief Handler for GetPDR
204 *
205 * @param[in] request - Request message payload
206 * @param[in] payloadLength - Request payload length
207 * @param[out] Response - Response message written here
208 */
209 Response getPDR(const pldm_msg* request, size_t payloadLength);
Sampa Misraa2fa0702019-05-31 01:28:55 -0500210
George Liueccb0c52020-01-14 11:09:56 +0800211 /** @brief Handler for setNumericEffecterValue
212 *
213 * @param[in] request - Request message
214 * @param[in] payloadLength - Request payload length
215 * @return Response - PLDM Response message
216 */
217 Response setNumericEffecterValue(const pldm_msg* request,
218 size_t payloadLength);
219
George Liu362c18d2020-05-14 09:46:36 +0800220 /** @brief Handler for getStateSensorReadings
221 *
222 * @param[in] request - Request message
223 * @param[in] payloadLength - Request payload length
224 * @return Response - PLDM Response message
225 */
226 Response getStateSensorReadings(const pldm_msg* request,
227 size_t payloadLength);
228
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600229 /** @brief Handler for setStateEffecterStates
230 *
231 * @param[in] request - Request message
232 * @param[in] payloadLength - Request payload length
233 * @return Response - PLDM Response message
234 */
235 Response setStateEffecterStates(const pldm_msg* request,
236 size_t payloadLength);
237
Tom Joseph56e45c52020-03-16 10:01:45 +0530238 /** @brief Handler for PlatformEventMessage
239 *
240 * @param[in] request - Request message
241 * @param[in] payloadLength - Request payload length
242 * @return Response - PLDM Response message
243 */
244 Response platformEventMessage(const pldm_msg* request,
245 size_t payloadLength);
246
247 /** @brief Handler for event class Sensor event
248 *
249 * @param[in] request - Request message
250 * @param[in] payloadLength - Request payload length
251 * @param[in] formatVersion - Version of the event format
252 * @param[in] tid - Terminus ID of the event's originator
253 * @param[in] eventDataOffset - Offset of the event data in the request
254 * message
255 * @return PLDM completion code
256 */
257 int sensorEvent(const pldm_msg* request, size_t payloadLength,
258 uint8_t formatVersion, uint8_t tid, size_t eventDataOffset);
259
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500260 /** @brief Handler for pldmPDRRepositoryChgEvent
261 *
262 * @param[in] request - Request message
263 * @param[in] payloadLength - Request payload length
264 * @param[in] formatVersion - Version of the event format
265 * @param[in] tid - Terminus ID of the event's originator
266 * @param[in] eventDataOffset - Offset of the event data in the request
267 * message
268 * @return PLDM completion code
269 */
270 int pldmPDRRepositoryChgEvent(const pldm_msg* request, size_t payloadLength,
271 uint8_t formatVersion, uint8_t tid,
272 size_t eventDataOffset);
273
274 /** @brief Handler for extracting the PDR handles from changeEntries
275 *
276 * @param[in] changeEntryData - ChangeEntry data from changeRecord
277 * @param[in] changeEntryDataSize - total size of changeEntryData
278 * @param[in] numberOfChangeEntries - total number of changeEntries to
279 * extract
280 * @param[out] pdrRecordHandles - std::vector where the extracted PDR
281 * handles are placed
282 * @return PLDM completion code
283 */
284 int getPDRRecordHandles(const ChangeEntry* changeEntryData,
285 size_t changeEntryDataSize,
286 size_t numberOfChangeEntries,
287 PDRRecordHandles& pdrRecordHandles);
288
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600289 /** @brief Function to set the effecter requested by pldm requester
290 * @param[in] dBusIntf - The interface object
291 * @param[in] effecterId - Effecter ID sent by the requester to act on
292 * @param[in] stateField - The state field data for each of the states,
293 * equal to composite effecter count in number
294 * @return - Success or failure in setting the states. Returns failure in
295 * terms of PLDM completion codes if atleast one state fails to be set
296 */
297 template <class DBusInterface>
298 int setStateEffecterStatesHandler(
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600299 const DBusInterface& dBusIntf, uint16_t effecterId,
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600300 const std::vector<set_effecter_state_field>& stateField)
Sampa Misraa2fa0702019-05-31 01:28:55 -0500301 {
George Liue53193f2020-02-24 09:23:26 +0800302 using namespace pldm::responder::pdr;
George Liu1e44c732020-02-28 20:20:06 +0800303 using namespace pldm::utils;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600304 using StateSetNum = uint8_t;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600305
306 state_effecter_possible_states* states = nullptr;
307 pldm_state_effecter_pdr* pdr = nullptr;
308 uint8_t compEffecterCnt = stateField.size();
George Liu1ec85d42020-02-12 16:05:32 +0800309
310 std::unique_ptr<pldm_pdr, decltype(&pldm_pdr_destroy)>
311 stateEffecterPdrRepo(pldm_pdr_init(), pldm_pdr_destroy);
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 {
317 std::cerr << "Failed to get record by PDR type\n";
318 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;
George Liu1ec85d42020-02-12 16:05:32 +0800329 pdrRecord =
330 stateEffecterPDRs.getNextRecord(pdrRecord, 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 {
George Liue53193f2020-02-24 09:23:26 +0800338 std::cerr << "The requester sent wrong composite effecter"
339 << " count for the effecter, EFFECTER_ID="
Manojkiran Eda394fac62021-07-22 15:58:29 +0530340 << (unsigned)effecterId
341 << "COMP_EFF_CNT=" << (unsigned)compEffecterCnt
George Liue53193f2020-02-24 09:23:26 +0800342 << "\n";
343 return PLDM_ERROR_INVALID_DATA;
Sampa Misraa2fa0702019-05-31 01:28:55 -0500344 }
George Liue53193f2020-02-24 09:23:26 +0800345 break;
346 }
347
348 if (!pdr)
349 {
350 return PLDM_PLATFORM_INVALID_EFFECTER_ID;
Sampa Misraa2fa0702019-05-31 01:28:55 -0500351 }
Sampa Misraa2fa0702019-05-31 01:28:55 -0500352
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600353 int rc = PLDM_SUCCESS;
George Liu1ec85d42020-02-12 16:05:32 +0800354 try
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600355 {
George Liu1ec85d42020-02-12 16:05:32 +0800356 const auto& [dbusMappings, dbusValMaps] =
George Liuadbe1722020-05-09 19:20:19 +0800357 effecterDbusObjMaps.at(effecterId);
George Liu1ec85d42020-02-12 16:05:32 +0800358 for (uint8_t currState = 0; currState < compEffecterCnt;
359 ++currState)
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600360 {
George Liu1ec85d42020-02-12 16:05:32 +0800361 std::vector<StateSetNum> allowed{};
362 // computation is based on table 79 from DSP0248 v1.1.1
363 uint8_t bitfieldIndex =
364 stateField[currState].effecter_state / 8;
365 uint8_t bit =
366 stateField[currState].effecter_state - (8 * bitfieldIndex);
367 if (states->possible_states_size < bitfieldIndex ||
368 !(states->states[bitfieldIndex].byte & (1 << bit)))
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600369 {
George Liu1ec85d42020-02-12 16:05:32 +0800370 std::cerr
Manojkiran Eda394fac62021-07-22 15:58:29 +0530371 << "Invalid state set value, EFFECTER_ID="
372 << (unsigned)effecterId << " VALUE="
373 << (unsigned)stateField[currState].effecter_state
374 << " COMPOSITE_EFFECTER_ID=" << (unsigned)currState
George Liu1ec85d42020-02-12 16:05:32 +0800375 << " DBUS_PATH=" << dbusMappings[currState].objectPath
376 << "\n";
377 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 {
395 std::cerr
396 << "Error setting property, ERROR=" << e.what()
397 << " PROPERTY=" << dbusMapping.propertyName
398 << " INTERFACE="
399 << dbusMapping.interface << " PATH="
400 << dbusMapping.objectPath << "\n";
401 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 {
415 std::cerr << "the effecterId does not exist. effecter id: "
Manojkiran Eda394fac62021-07-22 15:58:29 +0530416 << (unsigned)effecterId << e.what() << '\n';
George Liu1ec85d42020-02-12 16:05:32 +0800417 }
418
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600419 return rc;
420 }
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600421
Sampa Misra12afe112020-05-25 11:40:44 -0500422 /** @brief Build BMC Terminus Locator PDR
423 *
424 * @param[in] repo - instance of concrete implementation of Repo
425 */
Brad Bishop5079ac42021-08-19 18:35:06 -0400426 void generateTerminusLocatorPDR(pldm::responder::pdr_utils::Repo& repo);
Sampa Misra12afe112020-05-25 11:40:44 -0500427
George Liuc4ea6a92020-07-14 15:48:44 +0800428 /** @brief Get std::map associated with the entity
429 * key: object path
430 * value: pldm_entity
431 *
432 * @return std::map<ObjectPath, pldm_entity>
433 */
434 inline const AssociatedEntityMap& getAssociateEntityMap() const
435 {
436 if (fruHandler == nullptr)
437 {
438 throw InternalFailure();
439 }
440 return fruHandler->getAssociateEntityMap();
441 }
442
Sampa Misra5fb37d52021-03-06 07:26:00 -0600443 /** @brief process the actions that needs to be performed after a GetPDR
444 * call is received
445 * @param[in] source - sdeventplus event source
446 */
447 void _processPostGetPDRActions(sdeventplus::source::EventBase& source);
448
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600449 private:
450 pdr_utils::Repo pdrRepo;
451 uint16_t nextEffecterId{};
George Liuadbe1722020-05-09 19:20:19 +0800452 uint16_t nextSensorId{};
453 DbusObjMaps effecterDbusObjMaps{};
454 DbusObjMaps sensorDbusObjMaps{};
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500455 HostPDRHandler* hostPDRHandler;
Brad Bishop5079ac42021-08-19 18:35:06 -0400456 pldm::state_sensor::DbusToPLDMEvent* dbusToPLDMEventHandler;
Tom Joseph33e9c7e2020-06-11 22:09:52 +0530457 fru::Handler* fruHandler;
Deepak Kodihallib5c227e2020-07-13 06:58:34 -0500458 const pldm::utils::DBusHandler* dBusIntf;
Sampa Misraaea5dde2020-08-31 08:33:47 -0500459 pldm::responder::oem_platform::Handler* oemPlatformHandler;
Sampa Misra5fb37d52021-03-06 07:26:00 -0600460 sdeventplus::Event& event;
Deepak Kodihallib5c227e2020-07-13 06:58:34 -0500461 std::string pdrJsonsDir;
462 bool pdrCreated;
Sampa Misra5fb37d52021-03-06 07:26:00 -0600463 std::unique_ptr<sdeventplus::source::Defer> deferredGetPDREvent;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600464};
465
Sampa Misraaea5dde2020-08-31 08:33:47 -0500466/** @brief Function to check if a sensor falls in OEM range
467 * A sensor is considered to be oem if either of entity
468 * type or state set or both falls in oem range
469 *
470 * @param[in] handler - the interface object
471 * @param[in] sensorId - sensor id
472 * @param[in] sensorRearmCount - sensor rearm count
473 * @param[out] compSensorCnt - composite sensor count
474 * @param[out] entityType - entity type
475 * @param[out] entityInstance - entity instance number
476 * @param[out] stateSetId - state set id
477 *
478 * @return true if the sensor is OEM. All out parameters are invalid
479 * for a non OEM sensor
480 */
481bool isOemStateSensor(Handler& handler, uint16_t sensorId,
482 uint8_t sensorRearmCount, uint8_t& compSensorCnt,
483 uint16_t& entityType, uint16_t& entityInstance,
484 uint16_t& stateSetId);
485
486/** @brief Function to check if an effecter falls in OEM range
487 * An effecter is considered to be oem if either of entity
488 * type or state set or both falls in oem range
489 *
490 * @param[in] handler - the interface object
491 * @param[in] effecterId - effecter id
492 * @param[in] compEffecterCnt - composite effecter count
493 * @param[out] entityType - entity type
494 * @param[out] entityInstance - entity instance number
495 * @param[out] stateSetId - state set id
496 *
497 * @return true if the effecter is OEM. All out parameters are invalid
498 * for a non OEM effecter
499 */
500bool isOemStateEffecter(Handler& handler, uint16_t effecterId,
501 uint8_t compEffecterCnt, uint16_t& entityType,
502 uint16_t& entityInstance, uint16_t& stateSetId);
503
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600504} // namespace platform
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530505} // namespace responder
506} // namespace pldm