blob: e43058e168afa7bbf35ed65c836503c0294869e2 [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"
Kamalkumar Patel3c50c822024-01-30 07:14:40 -060010#include "libpldmresponder/platform_config.hpp"
Sampa Misraaea5dde2020-08-31 08:33:47 -050011#include "oem_handler.hpp"
Deepak Kodihalli1521f6d2020-06-16 08:51:02 -050012#include "pldmd/handler.hpp"
Sampa Misraa2fa0702019-05-31 01:28:55 -050013
George Liuc453e162022-12-21 17:16:23 +080014#include <libpldm/pdr.h>
15#include <libpldm/platform.h>
16#include <libpldm/states.h>
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053017#include <stdint.h>
18
Riya Dixit49cfb132023-03-02 04:26:53 -060019#include <phosphor-logging/lg2.hpp>
20
Sampa Misraa2fa0702019-05-31 01:28:55 -050021#include <map>
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053022
Riya Dixit49cfb132023-03-02 04:26:53 -060023PHOSPHOR_LOG2_USING;
24
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053025namespace pldm
26{
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053027namespace responder
28{
Sampa Misraa2fa0702019-05-31 01:28:55 -050029namespace platform
30{
Brad Bishop5079ac42021-08-19 18:35:06 -040031using generatePDR = std::function<void(const pldm::utils::DBusHandler& dBusIntf,
32 const pldm::utils::Json& json,
33 pdr_utils::RepoInterface& repo)>;
George Liua2870722020-02-11 11:09:30 +080034
George Liu1ec85d42020-02-12 16:05:32 +080035using EffecterId = uint16_t;
George Liua2870722020-02-11 11:09:30 +080036using DbusObjMaps =
37 std::map<EffecterId,
38 std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>>;
Tom Joseph56e45c52020-03-16 10:01:45 +053039using DbusPath = std::string;
40using EffecterObjs = std::vector<DbusPath>;
41using EventType = uint8_t;
42using EventHandler = std::function<int(
43 const pldm_msg* request, size_t payloadLength, uint8_t formatVersion,
44 uint8_t tid, size_t eventDataOffset)>;
45using EventHandlers = std::vector<EventHandler>;
46using EventMap = std::map<EventType, EventHandlers>;
George Liuc4ea6a92020-07-14 15:48:44 +080047using AssociatedEntityMap = std::map<DbusPath, pldm_entity>;
Deepak Kodihallic682fe22020-03-04 00:42:54 -060048
Deepak Kodihallibc669f12019-11-28 08:52:07 -060049class Handler : public CmdHandler
Sampa Misraa2fa0702019-05-31 01:28:55 -050050{
Deepak Kodihallibc669f12019-11-28 08:52:07 -060051 public:
Sagar Srinivas90314a32023-10-17 10:38:03 -050052 Handler(const pldm::utils::DBusHandler* dBusIntf, uint8_t eid,
Kamalkumar Patel3c50c822024-01-30 07:14:40 -060053 pldm::InstanceIdDb* instanceIdDb, const fs::path& pdrJsonDir,
Sagar Srinivas90314a32023-10-17 10:38:03 -050054 pldm_pdr* repo, HostPDRHandler* hostPDRHandler,
Brad Bishop5079ac42021-08-19 18:35:06 -040055 pldm::state_sensor::DbusToPLDMEvent* dbusToPLDMEventHandler,
56 fru::Handler* fruHandler,
Kamalkumar Patel3c50c822024-01-30 07:14:40 -060057 pldm::responder::platform_config::Handler* platformConfigHandler,
Sagar Srinivas90314a32023-10-17 10:38:03 -050058 pldm::requester::Handler<pldm::requester::Request>* handler,
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) :
Sagar Srinivas90314a32023-10-17 10:38:03 -050061 eid(eid),
62 instanceIdDb(instanceIdDb), pdrRepo(repo),
Pavithra Barithaya3aec9972020-12-14 01:55:44 -060063 hostPDRHandler(hostPDRHandler),
George Liucae18662020-05-15 09:32:57 +080064 dbusToPLDMEventHandler(dbusToPLDMEventHandler), fruHandler(fruHandler),
George Liua881c172021-06-21 18:28:11 +080065 dBusIntf(dBusIntf), platformConfigHandler(platformConfigHandler),
66 handler(handler), event(event), pdrJsonDir(pdrJsonDir),
67 pdrCreated(false), pdrJsonsDir({pdrJsonDir})
Sampa Misraa2fa0702019-05-31 01:28:55 -050068 {
Deepak Kodihallib5c227e2020-07-13 06:58:34 -050069 if (!buildPDRLazily)
70 {
Sampa Misra12afe112020-05-25 11:40:44 -050071 generateTerminusLocatorPDR(pdrRepo);
Deepak Kodihallib5c227e2020-07-13 06:58:34 -050072 generate(*dBusIntf, pdrJsonsDir, pdrRepo);
73 pdrCreated = true;
74 }
Deepak Kodihallic682fe22020-03-04 00:42:54 -060075
Delphine CC Chiud2e48992023-12-05 16:29:51 +080076 handlers.emplace(
77 PLDM_GET_PDR,
78 [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
Patrick Williams6da4f912023-05-10 07:50:53 -050079 return this->getPDR(request, payloadLength);
80 });
Delphine CC Chiud2e48992023-12-05 16:29:51 +080081 handlers.emplace(
82 PLDM_SET_NUMERIC_EFFECTER_VALUE,
83 [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
Patrick Williams6da4f912023-05-10 07:50:53 -050084 return this->setNumericEffecterValue(request, payloadLength);
85 });
Delphine CC Chiud2e48992023-12-05 16:29:51 +080086 handlers.emplace(
87 PLDM_GET_NUMERIC_EFFECTER_VALUE,
88 [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
Archana Kakani6ece21fb2023-10-10 08:21:52 -050089 return this->getNumericEffecterValue(request, payloadLength);
90 });
Delphine CC Chiud2e48992023-12-05 16:29:51 +080091 handlers.emplace(
92 PLDM_SET_STATE_EFFECTER_STATES,
93 [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
Patrick Williams6da4f912023-05-10 07:50:53 -050094 return this->setStateEffecterStates(request, payloadLength);
95 });
Delphine CC Chiud2e48992023-12-05 16:29:51 +080096 handlers.emplace(
97 PLDM_PLATFORM_EVENT_MESSAGE,
98 [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
Patrick Williams6da4f912023-05-10 07:50:53 -050099 return this->platformEventMessage(request, payloadLength);
100 });
Delphine CC Chiud2e48992023-12-05 16:29:51 +0800101 handlers.emplace(
102 PLDM_GET_STATE_SENSOR_READINGS,
103 [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
Patrick Williams6da4f912023-05-10 07:50:53 -0500104 return this->getStateSensorReadings(request, payloadLength);
105 });
Tom Joseph56e45c52020-03-16 10:01:45 +0530106
107 // Default handler for PLDM Events
108 eventHandlers[PLDM_SENSOR_EVENT].emplace_back(
109 [this](const pldm_msg* request, size_t payloadLength,
110 uint8_t formatVersion, uint8_t tid, size_t eventDataOffset) {
Patrick Williams6da4f912023-05-10 07:50:53 -0500111 return this->sensorEvent(request, payloadLength, formatVersion, tid,
112 eventDataOffset);
113 });
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500114 eventHandlers[PLDM_PDR_REPOSITORY_CHG_EVENT].emplace_back(
115 [this](const pldm_msg* request, size_t payloadLength,
116 uint8_t formatVersion, uint8_t tid, size_t eventDataOffset) {
Patrick Williams6da4f912023-05-10 07:50:53 -0500117 return this->pldmPDRRepositoryChgEvent(
118 request, payloadLength, formatVersion, tid, eventDataOffset);
119 });
Tom Joseph56e45c52020-03-16 10:01:45 +0530120
121 // Additional OEM event handlers for PLDM events, append it to the
122 // standard handlers
123 if (addOnHandlersMap)
124 {
125 auto addOnHandlers = addOnHandlersMap.value();
126 for (EventMap::iterator iter = addOnHandlers.begin();
127 iter != addOnHandlers.end(); ++iter)
128 {
129 auto search = eventHandlers.find(iter->first);
130 if (search != eventHandlers.end())
131 {
132 search->second.insert(std::end(search->second),
133 std::begin(iter->second),
134 std::end(iter->second));
135 }
136 else
137 {
138 eventHandlers.emplace(iter->first, iter->second);
139 }
140 }
141 }
Sampa Misraa2fa0702019-05-31 01:28:55 -0500142 }
143
George Liu1ec85d42020-02-12 16:05:32 +0800144 pdr_utils::Repo& getRepo()
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600145 {
George Liu1ec85d42020-02-12 16:05:32 +0800146 return this->pdrRepo;
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600147 }
148
George Liu1ec85d42020-02-12 16:05:32 +0800149 /** @brief Add D-Bus mapping and value mapping(stateId to D-Bus) for the
George Liuadbe1722020-05-09 19:20:19 +0800150 * Id. If the same id is added, the previous dbusObjs will
George Liu1ec85d42020-02-12 16:05:32 +0800151 * be "over-written".
152 *
George Liuadbe1722020-05-09 19:20:19 +0800153 * @param[in] Id - effecter/sensor id
George Liu1ec85d42020-02-12 16:05:32 +0800154 * @param[in] dbusObj - list of D-Bus object structure and list of D-Bus
155 * property value to attribute value
George Liuadbe1722020-05-09 19:20:19 +0800156 * @param[in] typeId - the type id of enum
George Liu1ec85d42020-02-12 16:05:32 +0800157 */
George Liua2870722020-02-11 11:09:30 +0800158 void addDbusObjMaps(
George Liuadbe1722020-05-09 19:20:19 +0800159 uint16_t id,
160 std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> dbusObj,
Brad Bishop5079ac42021-08-19 18:35:06 -0400161 pldm::responder::pdr_utils::TypeId typeId =
162 pldm::responder::pdr_utils::TypeId::PLDM_EFFECTER_ID);
George Liu1ec85d42020-02-12 16:05:32 +0800163
George Liuadbe1722020-05-09 19:20:19 +0800164 /** @brief Retrieve an id -> D-Bus objects mapping
George Liu1ec85d42020-02-12 16:05:32 +0800165 *
George Liuadbe1722020-05-09 19:20:19 +0800166 * @param[in] Id - id
167 * @param[in] typeId - the type id of enum
George Liu1ec85d42020-02-12 16:05:32 +0800168 *
George Liua2870722020-02-11 11:09:30 +0800169 * @return std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> -
170 * list of D-Bus object structure and list of D-Bus property value
171 * to attribute value
George Liu1ec85d42020-02-12 16:05:32 +0800172 */
George Liua2870722020-02-11 11:09:30 +0800173 const std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>&
Brad Bishop5079ac42021-08-19 18:35:06 -0400174 getDbusObjMaps(
175 uint16_t id,
176 pldm::responder::pdr_utils::TypeId typeId =
177 pldm::responder::pdr_utils::TypeId::PLDM_EFFECTER_ID) const;
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600178
179 uint16_t getNextEffecterId()
180 {
181 return ++nextEffecterId;
182 }
183
George Liuadbe1722020-05-09 19:20:19 +0800184 uint16_t getNextSensorId()
185 {
186 return ++nextSensorId;
187 }
188
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600189 /** @brief Parse PDR JSONs and build PDR repository
190 *
George Liu36e81352020-07-01 14:40:30 +0800191 * @param[in] dBusIntf - The interface object
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600192 * @param[in] dir - directory housing platform specific PDR JSON files
193 * @param[in] repo - instance of concrete implementation of Repo
194 */
George Liu36e81352020-07-01 14:40:30 +0800195 void generate(const pldm::utils::DBusHandler& dBusIntf,
Kamalkumar Patel3c50c822024-01-30 07:14:40 -0600196 const std::vector<fs::path>& dir,
Brad Bishop5079ac42021-08-19 18:35:06 -0400197 pldm::responder::pdr_utils::Repo& repo);
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600198
199 /** @brief Parse PDR JSONs and build state effecter PDR repository
200 *
201 * @param[in] json - platform specific PDR JSON files
202 * @param[in] repo - instance of state effecter implementation of Repo
203 */
Brad Bishop5079ac42021-08-19 18:35:06 -0400204 void generateStateEffecterRepo(const pldm::utils::Json& json,
205 pldm::responder::pdr_utils::Repo& repo);
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600206
Tom Joseph56e45c52020-03-16 10:01:45 +0530207 /** @brief map of PLDM event type to EventHandlers
208 *
209 */
210 EventMap eventHandlers;
211
George Liua881c172021-06-21 18:28:11 +0800212 /* @brief Method to set the oem platform handler in platform handler class
213 *
214 * @param[in] handler - oem platform handler
215 */
216 inline void
217 setOemPlatformHandler(pldm::responder::oem_platform::Handler* handler)
218 {
219 oemPlatformHandler = handler;
220 }
221
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600222 /** @brief Handler for GetPDR
223 *
224 * @param[in] request - Request message payload
225 * @param[in] payloadLength - Request payload length
226 * @param[out] Response - Response message written here
227 */
228 Response getPDR(const pldm_msg* request, size_t payloadLength);
Sampa Misraa2fa0702019-05-31 01:28:55 -0500229
George Liueccb0c52020-01-14 11:09:56 +0800230 /** @brief Handler for setNumericEffecterValue
231 *
232 * @param[in] request - Request message
233 * @param[in] payloadLength - Request payload length
234 * @return Response - PLDM Response message
235 */
236 Response setNumericEffecterValue(const pldm_msg* request,
237 size_t payloadLength);
238
Archana Kakani6ece21fb2023-10-10 08:21:52 -0500239 /** @brief Handler for getNumericEffecterValue
240 *
241 * @param[in] request - Request message
242 * @param[in] payloadLength - Request payload length
243 * @return Response - PLDM Response message
244 */
245 Response getNumericEffecterValue(const pldm_msg* request,
246 size_t payloadLength);
247
George Liu362c18d2020-05-14 09:46:36 +0800248 /** @brief Handler for getStateSensorReadings
249 *
250 * @param[in] request - Request message
251 * @param[in] payloadLength - Request payload length
252 * @return Response - PLDM Response message
253 */
254 Response getStateSensorReadings(const pldm_msg* request,
255 size_t payloadLength);
256
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600257 /** @brief Handler for setStateEffecterStates
258 *
259 * @param[in] request - Request message
260 * @param[in] payloadLength - Request payload length
261 * @return Response - PLDM Response message
262 */
263 Response setStateEffecterStates(const pldm_msg* request,
264 size_t payloadLength);
265
Tom Joseph56e45c52020-03-16 10:01:45 +0530266 /** @brief Handler for PlatformEventMessage
267 *
268 * @param[in] request - Request message
269 * @param[in] payloadLength - Request payload length
270 * @return Response - PLDM Response message
271 */
272 Response platformEventMessage(const pldm_msg* request,
273 size_t payloadLength);
274
275 /** @brief Handler for event class Sensor event
276 *
277 * @param[in] request - Request message
278 * @param[in] payloadLength - Request payload length
279 * @param[in] formatVersion - Version of the event format
280 * @param[in] tid - Terminus ID of the event's originator
281 * @param[in] eventDataOffset - Offset of the event data in the request
282 * message
283 * @return PLDM completion code
284 */
285 int sensorEvent(const pldm_msg* request, size_t payloadLength,
286 uint8_t formatVersion, uint8_t tid, size_t eventDataOffset);
287
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500288 /** @brief Handler for pldmPDRRepositoryChgEvent
289 *
290 * @param[in] request - Request message
291 * @param[in] payloadLength - Request payload length
292 * @param[in] formatVersion - Version of the event format
293 * @param[in] tid - Terminus ID of the event's originator
294 * @param[in] eventDataOffset - Offset of the event data in the request
295 * message
296 * @return PLDM completion code
297 */
298 int pldmPDRRepositoryChgEvent(const pldm_msg* request, size_t payloadLength,
299 uint8_t formatVersion, uint8_t tid,
300 size_t eventDataOffset);
301
302 /** @brief Handler for extracting the PDR handles from changeEntries
303 *
304 * @param[in] changeEntryData - ChangeEntry data from changeRecord
305 * @param[in] changeEntryDataSize - total size of changeEntryData
306 * @param[in] numberOfChangeEntries - total number of changeEntries to
307 * extract
308 * @param[out] pdrRecordHandles - std::vector where the extracted PDR
309 * handles are placed
310 * @return PLDM completion code
311 */
312 int getPDRRecordHandles(const ChangeEntry* changeEntryData,
313 size_t changeEntryDataSize,
314 size_t numberOfChangeEntries,
315 PDRRecordHandles& pdrRecordHandles);
316
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600317 /** @brief Function to set the effecter requested by pldm requester
318 * @param[in] dBusIntf - The interface object
319 * @param[in] effecterId - Effecter ID sent by the requester to act on
320 * @param[in] stateField - The state field data for each of the states,
321 * equal to composite effecter count in number
322 * @return - Success or failure in setting the states. Returns failure in
Manojkiran Eda2576aec2024-06-17 12:05:17 +0530323 * terms of PLDM completion codes if at least one state fails to be set
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600324 */
325 template <class DBusInterface>
326 int setStateEffecterStatesHandler(
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600327 const DBusInterface& dBusIntf, uint16_t effecterId,
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600328 const std::vector<set_effecter_state_field>& stateField)
Sampa Misraa2fa0702019-05-31 01:28:55 -0500329 {
George Liue53193f2020-02-24 09:23:26 +0800330 using namespace pldm::responder::pdr;
George Liu1e44c732020-02-28 20:20:06 +0800331 using namespace pldm::utils;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600332 using StateSetNum = uint8_t;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600333
334 state_effecter_possible_states* states = nullptr;
335 pldm_state_effecter_pdr* pdr = nullptr;
336 uint8_t compEffecterCnt = stateField.size();
George Liu1ec85d42020-02-12 16:05:32 +0800337
338 std::unique_ptr<pldm_pdr, decltype(&pldm_pdr_destroy)>
339 stateEffecterPdrRepo(pldm_pdr_init(), pldm_pdr_destroy);
Andrew Jefferyacb20292023-06-30 11:47:44 +0930340 if (!stateEffecterPdrRepo)
341 {
342 throw std::runtime_error(
343 "Failed to instantiate state effecter PDR repository");
344 }
Brad Bishop5079ac42021-08-19 18:35:06 -0400345 pldm::responder::pdr_utils::Repo stateEffecterPDRs(
346 stateEffecterPdrRepo.get());
George Liu1ec85d42020-02-12 16:05:32 +0800347 getRepoByType(pdrRepo, stateEffecterPDRs, PLDM_STATE_EFFECTER_PDR);
348 if (stateEffecterPDRs.empty())
349 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600350 error("Failed to get record by PDR type");
George Liu1ec85d42020-02-12 16:05:32 +0800351 return PLDM_PLATFORM_INVALID_EFFECTER_ID;
352 }
353
Brad Bishop5079ac42021-08-19 18:35:06 -0400354 pldm::responder::pdr_utils::PdrEntry pdrEntry{};
George Liu1ec85d42020-02-12 16:05:32 +0800355 auto pdrRecord = stateEffecterPDRs.getFirstRecord(pdrEntry);
George Liue53193f2020-02-24 09:23:26 +0800356 while (pdrRecord)
357 {
358 pdr = reinterpret_cast<pldm_state_effecter_pdr*>(pdrEntry.data);
359 if (pdr->effecter_id != effecterId)
Sampa Misraa2fa0702019-05-31 01:28:55 -0500360 {
George Liue53193f2020-02-24 09:23:26 +0800361 pdr = nullptr;
Patrick Williams6da4f912023-05-10 07:50:53 -0500362 pdrRecord = stateEffecterPDRs.getNextRecord(pdrRecord,
363 pdrEntry);
George Liue53193f2020-02-24 09:23:26 +0800364 continue;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600365 }
George Liue53193f2020-02-24 09:23:26 +0800366
367 states = reinterpret_cast<state_effecter_possible_states*>(
368 pdr->possible_states);
369 if (compEffecterCnt > pdr->composite_effecter_count)
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600370 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600371 error(
Riya Dixit89644442024-03-31 05:39:59 -0500372 "The requester sent wrong composite effecter count '{COMPOSITE_EFFECTER_COUNT}' for the effecter ID '{EFFECTERID}'.",
Riya Dixit1e5c81e2024-05-03 07:54:00 -0500373 "COMPOSITE_EFFECTER_COUNT", compEffecterCnt, "EFFECTERID",
374 effecterId);
George Liue53193f2020-02-24 09:23:26 +0800375 return PLDM_ERROR_INVALID_DATA;
Sampa Misraa2fa0702019-05-31 01:28:55 -0500376 }
George Liue53193f2020-02-24 09:23:26 +0800377 break;
378 }
379
380 if (!pdr)
381 {
382 return PLDM_PLATFORM_INVALID_EFFECTER_ID;
Sampa Misraa2fa0702019-05-31 01:28:55 -0500383 }
Sampa Misraa2fa0702019-05-31 01:28:55 -0500384
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600385 int rc = PLDM_SUCCESS;
George Liu1ec85d42020-02-12 16:05:32 +0800386 try
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600387 {
Patrick Williams6da4f912023-05-10 07:50:53 -0500388 const auto& [dbusMappings,
389 dbusValMaps] = effecterDbusObjMaps.at(effecterId);
George Liu1ec85d42020-02-12 16:05:32 +0800390 for (uint8_t currState = 0; currState < compEffecterCnt;
391 ++currState)
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600392 {
George Liu1ec85d42020-02-12 16:05:32 +0800393 std::vector<StateSetNum> allowed{};
394 // computation is based on table 79 from DSP0248 v1.1.1
Patrick Williams6da4f912023-05-10 07:50:53 -0500395 uint8_t bitfieldIndex = stateField[currState].effecter_state /
396 8;
397 uint8_t bit = stateField[currState].effecter_state -
398 (8 * bitfieldIndex);
George Liu1ec85d42020-02-12 16:05:32 +0800399 if (states->possible_states_size < bitfieldIndex ||
400 !(states->states[bitfieldIndex].byte & (1 << bit)))
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600401 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600402 error(
Riya Dixit89644442024-03-31 05:39:59 -0500403 "Invalid state set value for effecter ID '{EFFECTERID}', effecter state '{EFFECTER_STATE}', composite effecter ID '{COMPOSITE_EFFECTER_ID}' and path '{PATH}'.",
Riya Dixit1e5c81e2024-05-03 07:54:00 -0500404 "EFFECTERID", effecterId, "EFFECTER_STATE",
405 stateField[currState].effecter_state,
406 "COMPOSITE_EFFECTER_COUNT", currState, "PATH",
407 dbusMappings[currState].objectPath);
George Liu1ec85d42020-02-12 16:05:32 +0800408 rc = PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600409 break;
410 }
George Liu1ec85d42020-02-12 16:05:32 +0800411 const DBusMapping& dbusMapping = dbusMappings[currState];
Brad Bishop5079ac42021-08-19 18:35:06 -0400412 const pldm::responder::pdr_utils::StatestoDbusVal&
413 dbusValToMap = dbusValMaps[currState];
George Liu1ec85d42020-02-12 16:05:32 +0800414
415 if (stateField[currState].set_request == PLDM_REQUEST_SET)
416 {
417 try
418 {
419 dBusIntf.setDbusProperty(
420 dbusMapping,
421 dbusValToMap.at(
422 stateField[currState].effecter_state));
423 }
424 catch (const std::exception& e)
425 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600426 error(
Riya Dixit89644442024-03-31 05:39:59 -0500427 "Failed to set property '{PROPERTY}' of interface '{INTERFACE}' at path '{PATH}', error - {ERROR}",
428 "PROPERTY", dbusMapping.propertyName, "DBUS_INTF",
Riya Dixit49cfb132023-03-02 04:26:53 -0600429 dbusMapping.interface, "DBUS_OBJ_PATH",
Riya Dixit1e5c81e2024-05-03 07:54:00 -0500430 dbusMapping.objectPath, "ERROR", e);
George Liu1ec85d42020-02-12 16:05:32 +0800431 return PLDM_ERROR;
432 }
433 }
434 uint8_t* nextState =
435 reinterpret_cast<uint8_t*>(states) +
436 sizeof(state_effecter_possible_states) -
437 sizeof(states->states) +
438 (states->possible_states_size * sizeof(states->states));
439 states = reinterpret_cast<state_effecter_possible_states*>(
440 nextState);
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600441 }
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600442 }
George Liu1ec85d42020-02-12 16:05:32 +0800443 catch (const std::out_of_range& e)
444 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600445 error(
Riya Dixit89644442024-03-31 05:39:59 -0500446 "The effecter ID '{EFFECTERID}' does not exist, error - {ERROR}.",
Riya Dixit1e5c81e2024-05-03 07:54:00 -0500447 "EFFECTERID", effecterId, "ERROR", e);
George Liu1ec85d42020-02-12 16:05:32 +0800448 }
449
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600450 return rc;
451 }
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600452
Sampa Misra12afe112020-05-25 11:40:44 -0500453 /** @brief Build BMC Terminus Locator PDR
454 *
455 * @param[in] repo - instance of concrete implementation of Repo
456 */
Brad Bishop5079ac42021-08-19 18:35:06 -0400457 void generateTerminusLocatorPDR(pldm::responder::pdr_utils::Repo& repo);
Sampa Misra12afe112020-05-25 11:40:44 -0500458
George Liuc4ea6a92020-07-14 15:48:44 +0800459 /** @brief Get std::map associated with the entity
460 * key: object path
461 * value: pldm_entity
462 *
463 * @return std::map<ObjectPath, pldm_entity>
464 */
465 inline const AssociatedEntityMap& getAssociateEntityMap() const
466 {
467 if (fruHandler == nullptr)
468 {
469 throw InternalFailure();
470 }
471 return fruHandler->getAssociateEntityMap();
472 }
473
Manojkiran Edaae933cc2024-02-21 17:19:21 +0530474 /** @brief update the sensor cache map
475 * @param[in] sensorId - sensor id that needs an update
476 * @param[in] sensorRearm - rearm value within the sensor
477 * @param[in] value - value that needs to be cached
478 */
479
480 inline void updateSensorCache(pldm::pdr::SensorID sensorId,
481 size_t sensorRearm, uint8_t value)
482 {
483 if (dbusToPLDMEventHandler)
484 {
485 dbusToPLDMEventHandler->updateSensorCacheMaps(sensorId, sensorRearm,
486 value);
487 }
488 }
489
Sampa Misra5fb37d52021-03-06 07:26:00 -0600490 /** @brief process the actions that needs to be performed after a GetPDR
491 * call is received
492 * @param[in] source - sdeventplus event source
493 */
494 void _processPostGetPDRActions(sdeventplus::source::EventBase& source);
495
Sagar Srinivas90314a32023-10-17 10:38:03 -0500496 /** @brief Method for setEventreceiver */
497 void setEventReceiver();
498
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600499 private:
Sagar Srinivas90314a32023-10-17 10:38:03 -0500500 uint8_t eid;
501 InstanceIdDb* instanceIdDb;
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600502 pdr_utils::Repo pdrRepo;
503 uint16_t nextEffecterId{};
George Liuadbe1722020-05-09 19:20:19 +0800504 uint16_t nextSensorId{};
505 DbusObjMaps effecterDbusObjMaps{};
506 DbusObjMaps sensorDbusObjMaps{};
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500507 HostPDRHandler* hostPDRHandler;
Brad Bishop5079ac42021-08-19 18:35:06 -0400508 pldm::state_sensor::DbusToPLDMEvent* dbusToPLDMEventHandler;
Tom Joseph33e9c7e2020-06-11 22:09:52 +0530509 fru::Handler* fruHandler;
Deepak Kodihallib5c227e2020-07-13 06:58:34 -0500510 const pldm::utils::DBusHandler* dBusIntf;
George Liua881c172021-06-21 18:28:11 +0800511 pldm::responder::oem_platform::Handler* oemPlatformHandler = nullptr;
Kamalkumar Patel3c50c822024-01-30 07:14:40 -0600512 pldm::responder::platform_config::Handler* platformConfigHandler;
Sagar Srinivas90314a32023-10-17 10:38:03 -0500513 pldm::requester::Handler<pldm::requester::Request>* handler;
Sampa Misra5fb37d52021-03-06 07:26:00 -0600514 sdeventplus::Event& event;
Kamalkumar Patel3c50c822024-01-30 07:14:40 -0600515 fs::path pdrJsonDir;
Deepak Kodihallib5c227e2020-07-13 06:58:34 -0500516 bool pdrCreated;
Kamalkumar Patel3c50c822024-01-30 07:14:40 -0600517 std::vector<fs::path> pdrJsonsDir;
Sampa Misra5fb37d52021-03-06 07:26:00 -0600518 std::unique_ptr<sdeventplus::source::Defer> deferredGetPDREvent;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600519};
520
Sampa Misraaea5dde2020-08-31 08:33:47 -0500521/** @brief Function to check if a sensor falls in OEM range
522 * A sensor is considered to be oem if either of entity
523 * type or state set or both falls in oem range
524 *
525 * @param[in] handler - the interface object
526 * @param[in] sensorId - sensor id
527 * @param[in] sensorRearmCount - sensor rearm count
528 * @param[out] compSensorCnt - composite sensor count
529 * @param[out] entityType - entity type
530 * @param[out] entityInstance - entity instance number
531 * @param[out] stateSetId - state set id
532 *
533 * @return true if the sensor is OEM. All out parameters are invalid
534 * for a non OEM sensor
535 */
536bool isOemStateSensor(Handler& handler, uint16_t sensorId,
537 uint8_t sensorRearmCount, uint8_t& compSensorCnt,
538 uint16_t& entityType, uint16_t& entityInstance,
539 uint16_t& stateSetId);
540
541/** @brief Function to check if an effecter falls in OEM range
542 * An effecter is considered to be oem if either of entity
543 * type or state set or both falls in oem range
544 *
545 * @param[in] handler - the interface object
546 * @param[in] effecterId - effecter id
547 * @param[in] compEffecterCnt - composite effecter count
548 * @param[out] entityType - entity type
549 * @param[out] entityInstance - entity instance number
550 * @param[out] stateSetId - state set id
551 *
552 * @return true if the effecter is OEM. All out parameters are invalid
553 * for a non OEM effecter
554 */
555bool isOemStateEffecter(Handler& handler, uint16_t effecterId,
556 uint8_t compEffecterCnt, uint16_t& entityType,
557 uint16_t& entityInstance, uint16_t& stateSetId);
558
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600559} // namespace platform
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530560} // namespace responder
561} // namespace pldm