blob: eb01e5f8007bb716e4a00c01aee892cd9a0465b6 [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
Delphine CC Chiud2e48992023-12-05 16:29:51 +080072 handlers.emplace(
73 PLDM_GET_PDR,
74 [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
Patrick Williams6da4f912023-05-10 07:50:53 -050075 return this->getPDR(request, payloadLength);
76 });
Delphine CC Chiud2e48992023-12-05 16:29:51 +080077 handlers.emplace(
78 PLDM_SET_NUMERIC_EFFECTER_VALUE,
79 [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
Patrick Williams6da4f912023-05-10 07:50:53 -050080 return this->setNumericEffecterValue(request, payloadLength);
81 });
Delphine CC Chiud2e48992023-12-05 16:29:51 +080082 handlers.emplace(
83 PLDM_GET_NUMERIC_EFFECTER_VALUE,
84 [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
Archana Kakani6ece21fb2023-10-10 08:21:52 -050085 return this->getNumericEffecterValue(request, payloadLength);
86 });
Delphine CC Chiud2e48992023-12-05 16:29:51 +080087 handlers.emplace(
88 PLDM_SET_STATE_EFFECTER_STATES,
89 [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
Patrick Williams6da4f912023-05-10 07:50:53 -050090 return this->setStateEffecterStates(request, payloadLength);
91 });
Delphine CC Chiud2e48992023-12-05 16:29:51 +080092 handlers.emplace(
93 PLDM_PLATFORM_EVENT_MESSAGE,
94 [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
Patrick Williams6da4f912023-05-10 07:50:53 -050095 return this->platformEventMessage(request, payloadLength);
96 });
Delphine CC Chiud2e48992023-12-05 16:29:51 +080097 handlers.emplace(
98 PLDM_GET_STATE_SENSOR_READINGS,
99 [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
Patrick Williams6da4f912023-05-10 07:50:53 -0500100 return this->getStateSensorReadings(request, payloadLength);
101 });
Tom Joseph56e45c52020-03-16 10:01:45 +0530102
103 // Default handler for PLDM Events
104 eventHandlers[PLDM_SENSOR_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->sensorEvent(request, payloadLength, formatVersion, tid,
108 eventDataOffset);
109 });
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500110 eventHandlers[PLDM_PDR_REPOSITORY_CHG_EVENT].emplace_back(
111 [this](const pldm_msg* request, size_t payloadLength,
112 uint8_t formatVersion, uint8_t tid, size_t eventDataOffset) {
Patrick Williams6da4f912023-05-10 07:50:53 -0500113 return this->pldmPDRRepositoryChgEvent(
114 request, payloadLength, formatVersion, tid, eventDataOffset);
115 });
Tom Joseph56e45c52020-03-16 10:01:45 +0530116
117 // Additional OEM event handlers for PLDM events, append it to the
118 // standard handlers
119 if (addOnHandlersMap)
120 {
121 auto addOnHandlers = addOnHandlersMap.value();
122 for (EventMap::iterator iter = addOnHandlers.begin();
123 iter != addOnHandlers.end(); ++iter)
124 {
125 auto search = eventHandlers.find(iter->first);
126 if (search != eventHandlers.end())
127 {
128 search->second.insert(std::end(search->second),
129 std::begin(iter->second),
130 std::end(iter->second));
131 }
132 else
133 {
134 eventHandlers.emplace(iter->first, iter->second);
135 }
136 }
137 }
Sampa Misraa2fa0702019-05-31 01:28:55 -0500138 }
139
George Liu1ec85d42020-02-12 16:05:32 +0800140 pdr_utils::Repo& getRepo()
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600141 {
George Liu1ec85d42020-02-12 16:05:32 +0800142 return this->pdrRepo;
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600143 }
144
George Liu1ec85d42020-02-12 16:05:32 +0800145 /** @brief Add D-Bus mapping and value mapping(stateId to D-Bus) for the
George Liuadbe1722020-05-09 19:20:19 +0800146 * Id. If the same id is added, the previous dbusObjs will
George Liu1ec85d42020-02-12 16:05:32 +0800147 * be "over-written".
148 *
George Liuadbe1722020-05-09 19:20:19 +0800149 * @param[in] Id - effecter/sensor id
George Liu1ec85d42020-02-12 16:05:32 +0800150 * @param[in] dbusObj - list of D-Bus object structure and list of D-Bus
151 * property value to attribute value
George Liuadbe1722020-05-09 19:20:19 +0800152 * @param[in] typeId - the type id of enum
George Liu1ec85d42020-02-12 16:05:32 +0800153 */
George Liua2870722020-02-11 11:09:30 +0800154 void addDbusObjMaps(
George Liuadbe1722020-05-09 19:20:19 +0800155 uint16_t id,
156 std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> dbusObj,
Brad Bishop5079ac42021-08-19 18:35:06 -0400157 pldm::responder::pdr_utils::TypeId typeId =
158 pldm::responder::pdr_utils::TypeId::PLDM_EFFECTER_ID);
George Liu1ec85d42020-02-12 16:05:32 +0800159
George Liuadbe1722020-05-09 19:20:19 +0800160 /** @brief Retrieve an id -> D-Bus objects mapping
George Liu1ec85d42020-02-12 16:05:32 +0800161 *
George Liuadbe1722020-05-09 19:20:19 +0800162 * @param[in] Id - id
163 * @param[in] typeId - the type id of enum
George Liu1ec85d42020-02-12 16:05:32 +0800164 *
George Liua2870722020-02-11 11:09:30 +0800165 * @return std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> -
166 * list of D-Bus object structure and list of D-Bus property value
167 * to attribute value
George Liu1ec85d42020-02-12 16:05:32 +0800168 */
George Liua2870722020-02-11 11:09:30 +0800169 const std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>&
Brad Bishop5079ac42021-08-19 18:35:06 -0400170 getDbusObjMaps(
171 uint16_t id,
172 pldm::responder::pdr_utils::TypeId typeId =
173 pldm::responder::pdr_utils::TypeId::PLDM_EFFECTER_ID) const;
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600174
175 uint16_t getNextEffecterId()
176 {
177 return ++nextEffecterId;
178 }
179
George Liuadbe1722020-05-09 19:20:19 +0800180 uint16_t getNextSensorId()
181 {
182 return ++nextSensorId;
183 }
184
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600185 /** @brief Parse PDR JSONs and build PDR repository
186 *
George Liu36e81352020-07-01 14:40:30 +0800187 * @param[in] dBusIntf - The interface object
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600188 * @param[in] dir - directory housing platform specific PDR JSON files
189 * @param[in] repo - instance of concrete implementation of Repo
190 */
George Liu36e81352020-07-01 14:40:30 +0800191 void generate(const pldm::utils::DBusHandler& dBusIntf,
Brad Bishop5079ac42021-08-19 18:35:06 -0400192 const std::string& dir,
193 pldm::responder::pdr_utils::Repo& repo);
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600194
195 /** @brief Parse PDR JSONs and build state effecter PDR repository
196 *
197 * @param[in] json - platform specific PDR JSON files
198 * @param[in] repo - instance of state effecter implementation of Repo
199 */
Brad Bishop5079ac42021-08-19 18:35:06 -0400200 void generateStateEffecterRepo(const pldm::utils::Json& json,
201 pldm::responder::pdr_utils::Repo& repo);
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600202
Tom Joseph56e45c52020-03-16 10:01:45 +0530203 /** @brief map of PLDM event type to EventHandlers
204 *
205 */
206 EventMap eventHandlers;
207
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600208 /** @brief Handler for GetPDR
209 *
210 * @param[in] request - Request message payload
211 * @param[in] payloadLength - Request payload length
212 * @param[out] Response - Response message written here
213 */
214 Response getPDR(const pldm_msg* request, size_t payloadLength);
Sampa Misraa2fa0702019-05-31 01:28:55 -0500215
George Liueccb0c52020-01-14 11:09:56 +0800216 /** @brief Handler for setNumericEffecterValue
217 *
218 * @param[in] request - Request message
219 * @param[in] payloadLength - Request payload length
220 * @return Response - PLDM Response message
221 */
222 Response setNumericEffecterValue(const pldm_msg* request,
223 size_t payloadLength);
224
Archana Kakani6ece21fb2023-10-10 08:21:52 -0500225 /** @brief Handler for getNumericEffecterValue
226 *
227 * @param[in] request - Request message
228 * @param[in] payloadLength - Request payload length
229 * @return Response - PLDM Response message
230 */
231 Response getNumericEffecterValue(const pldm_msg* request,
232 size_t payloadLength);
233
George Liu362c18d2020-05-14 09:46:36 +0800234 /** @brief Handler for getStateSensorReadings
235 *
236 * @param[in] request - Request message
237 * @param[in] payloadLength - Request payload length
238 * @return Response - PLDM Response message
239 */
240 Response getStateSensorReadings(const pldm_msg* request,
241 size_t payloadLength);
242
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600243 /** @brief Handler for setStateEffecterStates
244 *
245 * @param[in] request - Request message
246 * @param[in] payloadLength - Request payload length
247 * @return Response - PLDM Response message
248 */
249 Response setStateEffecterStates(const pldm_msg* request,
250 size_t payloadLength);
251
Tom Joseph56e45c52020-03-16 10:01:45 +0530252 /** @brief Handler for PlatformEventMessage
253 *
254 * @param[in] request - Request message
255 * @param[in] payloadLength - Request payload length
256 * @return Response - PLDM Response message
257 */
258 Response platformEventMessage(const pldm_msg* request,
259 size_t payloadLength);
260
261 /** @brief Handler for event class Sensor event
262 *
263 * @param[in] request - Request message
264 * @param[in] payloadLength - Request payload length
265 * @param[in] formatVersion - Version of the event format
266 * @param[in] tid - Terminus ID of the event's originator
267 * @param[in] eventDataOffset - Offset of the event data in the request
268 * message
269 * @return PLDM completion code
270 */
271 int sensorEvent(const pldm_msg* request, size_t payloadLength,
272 uint8_t formatVersion, uint8_t tid, size_t eventDataOffset);
273
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500274 /** @brief Handler for pldmPDRRepositoryChgEvent
275 *
276 * @param[in] request - Request message
277 * @param[in] payloadLength - Request payload length
278 * @param[in] formatVersion - Version of the event format
279 * @param[in] tid - Terminus ID of the event's originator
280 * @param[in] eventDataOffset - Offset of the event data in the request
281 * message
282 * @return PLDM completion code
283 */
284 int pldmPDRRepositoryChgEvent(const pldm_msg* request, size_t payloadLength,
285 uint8_t formatVersion, uint8_t tid,
286 size_t eventDataOffset);
287
288 /** @brief Handler for extracting the PDR handles from changeEntries
289 *
290 * @param[in] changeEntryData - ChangeEntry data from changeRecord
291 * @param[in] changeEntryDataSize - total size of changeEntryData
292 * @param[in] numberOfChangeEntries - total number of changeEntries to
293 * extract
294 * @param[out] pdrRecordHandles - std::vector where the extracted PDR
295 * handles are placed
296 * @return PLDM completion code
297 */
298 int getPDRRecordHandles(const ChangeEntry* changeEntryData,
299 size_t changeEntryDataSize,
300 size_t numberOfChangeEntries,
301 PDRRecordHandles& pdrRecordHandles);
302
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600303 /** @brief Function to set the effecter requested by pldm requester
304 * @param[in] dBusIntf - The interface object
305 * @param[in] effecterId - Effecter ID sent by the requester to act on
306 * @param[in] stateField - The state field data for each of the states,
307 * equal to composite effecter count in number
308 * @return - Success or failure in setting the states. Returns failure in
309 * terms of PLDM completion codes if atleast one state fails to be set
310 */
311 template <class DBusInterface>
312 int setStateEffecterStatesHandler(
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600313 const DBusInterface& dBusIntf, uint16_t effecterId,
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600314 const std::vector<set_effecter_state_field>& stateField)
Sampa Misraa2fa0702019-05-31 01:28:55 -0500315 {
George Liue53193f2020-02-24 09:23:26 +0800316 using namespace pldm::responder::pdr;
George Liu1e44c732020-02-28 20:20:06 +0800317 using namespace pldm::utils;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600318 using StateSetNum = uint8_t;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600319
320 state_effecter_possible_states* states = nullptr;
321 pldm_state_effecter_pdr* pdr = nullptr;
322 uint8_t compEffecterCnt = stateField.size();
George Liu1ec85d42020-02-12 16:05:32 +0800323
324 std::unique_ptr<pldm_pdr, decltype(&pldm_pdr_destroy)>
325 stateEffecterPdrRepo(pldm_pdr_init(), pldm_pdr_destroy);
Andrew Jefferyacb20292023-06-30 11:47:44 +0930326 if (!stateEffecterPdrRepo)
327 {
328 throw std::runtime_error(
329 "Failed to instantiate state effecter PDR repository");
330 }
Brad Bishop5079ac42021-08-19 18:35:06 -0400331 pldm::responder::pdr_utils::Repo stateEffecterPDRs(
332 stateEffecterPdrRepo.get());
George Liu1ec85d42020-02-12 16:05:32 +0800333 getRepoByType(pdrRepo, stateEffecterPDRs, PLDM_STATE_EFFECTER_PDR);
334 if (stateEffecterPDRs.empty())
335 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600336 error("Failed to get record by PDR type");
George Liu1ec85d42020-02-12 16:05:32 +0800337 return PLDM_PLATFORM_INVALID_EFFECTER_ID;
338 }
339
Brad Bishop5079ac42021-08-19 18:35:06 -0400340 pldm::responder::pdr_utils::PdrEntry pdrEntry{};
George Liu1ec85d42020-02-12 16:05:32 +0800341 auto pdrRecord = stateEffecterPDRs.getFirstRecord(pdrEntry);
George Liue53193f2020-02-24 09:23:26 +0800342 while (pdrRecord)
343 {
344 pdr = reinterpret_cast<pldm_state_effecter_pdr*>(pdrEntry.data);
345 if (pdr->effecter_id != effecterId)
Sampa Misraa2fa0702019-05-31 01:28:55 -0500346 {
George Liue53193f2020-02-24 09:23:26 +0800347 pdr = nullptr;
Patrick Williams6da4f912023-05-10 07:50:53 -0500348 pdrRecord = stateEffecterPDRs.getNextRecord(pdrRecord,
349 pdrEntry);
George Liue53193f2020-02-24 09:23:26 +0800350 continue;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600351 }
George Liue53193f2020-02-24 09:23:26 +0800352
353 states = reinterpret_cast<state_effecter_possible_states*>(
354 pdr->possible_states);
355 if (compEffecterCnt > pdr->composite_effecter_count)
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600356 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600357 error(
358 "The requester sent wrong composite effecter count for the effecter, EFFECTER_ID={EFFECTER_ID} COMP_EFF_CNT={COMP_EFF_CNT}",
359 "EFFECTER_ID", (unsigned)effecterId, "COMP_EFF_CNT",
360 (unsigned)compEffecterCnt);
George Liue53193f2020-02-24 09:23:26 +0800361 return PLDM_ERROR_INVALID_DATA;
Sampa Misraa2fa0702019-05-31 01:28:55 -0500362 }
George Liue53193f2020-02-24 09:23:26 +0800363 break;
364 }
365
366 if (!pdr)
367 {
368 return PLDM_PLATFORM_INVALID_EFFECTER_ID;
Sampa Misraa2fa0702019-05-31 01:28:55 -0500369 }
Sampa Misraa2fa0702019-05-31 01:28:55 -0500370
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600371 int rc = PLDM_SUCCESS;
George Liu1ec85d42020-02-12 16:05:32 +0800372 try
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600373 {
Patrick Williams6da4f912023-05-10 07:50:53 -0500374 const auto& [dbusMappings,
375 dbusValMaps] = effecterDbusObjMaps.at(effecterId);
George Liu1ec85d42020-02-12 16:05:32 +0800376 for (uint8_t currState = 0; currState < compEffecterCnt;
377 ++currState)
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600378 {
George Liu1ec85d42020-02-12 16:05:32 +0800379 std::vector<StateSetNum> allowed{};
380 // computation is based on table 79 from DSP0248 v1.1.1
Patrick Williams6da4f912023-05-10 07:50:53 -0500381 uint8_t bitfieldIndex = stateField[currState].effecter_state /
382 8;
383 uint8_t bit = stateField[currState].effecter_state -
384 (8 * bitfieldIndex);
George Liu1ec85d42020-02-12 16:05:32 +0800385 if (states->possible_states_size < bitfieldIndex ||
386 !(states->states[bitfieldIndex].byte & (1 << bit)))
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600387 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600388 error(
389 "Invalid state set value, EFFECTER_ID={EFFECTER_ID} VALUE={EFFECTER_STATE} COMPOSITE_EFFECTER_ID={CURR_STATE} DBUS_PATH={DBUS_OBJ_PATH}",
390 "EFFECTER_ID", (unsigned)effecterId, "EFFECTER_STATE",
391 (unsigned)stateField[currState].effecter_state,
392 "CURR_STATE", (unsigned)currState, "DBUS_OBJ_PATH",
393 dbusMappings[currState].objectPath.c_str());
George Liu1ec85d42020-02-12 16:05:32 +0800394 rc = PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600395 break;
396 }
George Liu1ec85d42020-02-12 16:05:32 +0800397 const DBusMapping& dbusMapping = dbusMappings[currState];
Brad Bishop5079ac42021-08-19 18:35:06 -0400398 const pldm::responder::pdr_utils::StatestoDbusVal&
399 dbusValToMap = dbusValMaps[currState];
George Liu1ec85d42020-02-12 16:05:32 +0800400
401 if (stateField[currState].set_request == PLDM_REQUEST_SET)
402 {
403 try
404 {
405 dBusIntf.setDbusProperty(
406 dbusMapping,
407 dbusValToMap.at(
408 stateField[currState].effecter_state));
409 }
410 catch (const std::exception& e)
411 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600412 error(
413 "Error setting property, ERROR={ERR_EXCEP} PROPERTY={DBUS_PROP} INTERFACE={DBUS_INTF} PATH={DBUS_OBJ_PATH}",
414 "ERR_EXCEP", e.what(), "DBUS_PROP",
415 dbusMapping.propertyName, "DBUS_INTF",
416 dbusMapping.interface, "DBUS_OBJ_PATH",
417 dbusMapping.objectPath.c_str());
George Liu1ec85d42020-02-12 16:05:32 +0800418 return PLDM_ERROR;
419 }
420 }
421 uint8_t* nextState =
422 reinterpret_cast<uint8_t*>(states) +
423 sizeof(state_effecter_possible_states) -
424 sizeof(states->states) +
425 (states->possible_states_size * sizeof(states->states));
426 states = reinterpret_cast<state_effecter_possible_states*>(
427 nextState);
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600428 }
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600429 }
George Liu1ec85d42020-02-12 16:05:32 +0800430 catch (const std::out_of_range& e)
431 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600432 error(
433 "the effecterId does not exist. effecter id: {EFFECTER_ID} {ERR_EXCEP}",
434 "EFFECTER_ID", (unsigned)effecterId, "ERR_EXCEP", e.what());
George Liu1ec85d42020-02-12 16:05:32 +0800435 }
436
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600437 return rc;
438 }
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600439
Sampa Misra12afe112020-05-25 11:40:44 -0500440 /** @brief Build BMC Terminus Locator PDR
441 *
442 * @param[in] repo - instance of concrete implementation of Repo
443 */
Brad Bishop5079ac42021-08-19 18:35:06 -0400444 void generateTerminusLocatorPDR(pldm::responder::pdr_utils::Repo& repo);
Sampa Misra12afe112020-05-25 11:40:44 -0500445
George Liuc4ea6a92020-07-14 15:48:44 +0800446 /** @brief Get std::map associated with the entity
447 * key: object path
448 * value: pldm_entity
449 *
450 * @return std::map<ObjectPath, pldm_entity>
451 */
452 inline const AssociatedEntityMap& getAssociateEntityMap() const
453 {
454 if (fruHandler == nullptr)
455 {
456 throw InternalFailure();
457 }
458 return fruHandler->getAssociateEntityMap();
459 }
460
Sampa Misra5fb37d52021-03-06 07:26:00 -0600461 /** @brief process the actions that needs to be performed after a GetPDR
462 * call is received
463 * @param[in] source - sdeventplus event source
464 */
465 void _processPostGetPDRActions(sdeventplus::source::EventBase& source);
466
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600467 private:
468 pdr_utils::Repo pdrRepo;
469 uint16_t nextEffecterId{};
George Liuadbe1722020-05-09 19:20:19 +0800470 uint16_t nextSensorId{};
471 DbusObjMaps effecterDbusObjMaps{};
472 DbusObjMaps sensorDbusObjMaps{};
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500473 HostPDRHandler* hostPDRHandler;
Brad Bishop5079ac42021-08-19 18:35:06 -0400474 pldm::state_sensor::DbusToPLDMEvent* dbusToPLDMEventHandler;
Tom Joseph33e9c7e2020-06-11 22:09:52 +0530475 fru::Handler* fruHandler;
Deepak Kodihallib5c227e2020-07-13 06:58:34 -0500476 const pldm::utils::DBusHandler* dBusIntf;
Sampa Misraaea5dde2020-08-31 08:33:47 -0500477 pldm::responder::oem_platform::Handler* oemPlatformHandler;
Sampa Misra5fb37d52021-03-06 07:26:00 -0600478 sdeventplus::Event& event;
Deepak Kodihallib5c227e2020-07-13 06:58:34 -0500479 std::string pdrJsonsDir;
480 bool pdrCreated;
Sampa Misra5fb37d52021-03-06 07:26:00 -0600481 std::unique_ptr<sdeventplus::source::Defer> deferredGetPDREvent;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600482};
483
Sampa Misraaea5dde2020-08-31 08:33:47 -0500484/** @brief Function to check if a sensor falls in OEM range
485 * A sensor is considered to be oem if either of entity
486 * type or state set or both falls in oem range
487 *
488 * @param[in] handler - the interface object
489 * @param[in] sensorId - sensor id
490 * @param[in] sensorRearmCount - sensor rearm count
491 * @param[out] compSensorCnt - composite sensor count
492 * @param[out] entityType - entity type
493 * @param[out] entityInstance - entity instance number
494 * @param[out] stateSetId - state set id
495 *
496 * @return true if the sensor is OEM. All out parameters are invalid
497 * for a non OEM sensor
498 */
499bool isOemStateSensor(Handler& handler, uint16_t sensorId,
500 uint8_t sensorRearmCount, uint8_t& compSensorCnt,
501 uint16_t& entityType, uint16_t& entityInstance,
502 uint16_t& stateSetId);
503
504/** @brief Function to check if an effecter falls in OEM range
505 * An effecter is considered to be oem if either of entity
506 * type or state set or both falls in oem range
507 *
508 * @param[in] handler - the interface object
509 * @param[in] effecterId - effecter id
510 * @param[in] compEffecterCnt - composite effecter count
511 * @param[out] entityType - entity type
512 * @param[out] entityInstance - entity instance number
513 * @param[out] stateSetId - state set id
514 *
515 * @return true if the effecter is OEM. All out parameters are invalid
516 * for a non OEM effecter
517 */
518bool isOemStateEffecter(Handler& handler, uint16_t effecterId,
519 uint8_t compEffecterCnt, uint16_t& entityType,
520 uint16_t& entityInstance, uint16_t& stateSetId);
521
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600522} // namespace platform
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530523} // namespace responder
524} // namespace pldm