blob: a5dcc441c744c71692e755ed230816a664d8af14 [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:
Sagar Srinivas90314a32023-10-17 10:38:03 -050051 Handler(const pldm::utils::DBusHandler* dBusIntf, uint8_t eid,
52 pldm::InstanceIdDb* instanceIdDb, const std::string& pdrJsonsDir,
53 pldm_pdr* repo, 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,
Sagar Srinivas90314a32023-10-17 10:38:03 -050057 pldm::requester::Handler<pldm::requester::Request>* handler,
Sampa Misra5fb37d52021-03-06 07:26:00 -060058 sdeventplus::Event& event, bool buildPDRLazily = false,
Tom Joseph56e45c52020-03-16 10:01:45 +053059 const std::optional<EventMap>& addOnHandlersMap = std::nullopt) :
Sagar Srinivas90314a32023-10-17 10:38:03 -050060 eid(eid),
61 instanceIdDb(instanceIdDb), 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),
Sagar Srinivas90314a32023-10-17 10:38:03 -050065 handler(handler), event(event), pdrJsonsDir(pdrJsonsDir),
66 pdrCreated(false)
Sampa Misraa2fa0702019-05-31 01:28:55 -050067 {
Deepak Kodihallib5c227e2020-07-13 06:58:34 -050068 if (!buildPDRLazily)
69 {
Sampa Misra12afe112020-05-25 11:40:44 -050070 generateTerminusLocatorPDR(pdrRepo);
Deepak Kodihallib5c227e2020-07-13 06:58:34 -050071 generate(*dBusIntf, pdrJsonsDir, pdrRepo);
72 pdrCreated = true;
73 }
Deepak Kodihallic682fe22020-03-04 00:42:54 -060074
Delphine CC Chiud2e48992023-12-05 16:29:51 +080075 handlers.emplace(
76 PLDM_GET_PDR,
77 [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
Patrick Williams6da4f912023-05-10 07:50:53 -050078 return this->getPDR(request, payloadLength);
79 });
Delphine CC Chiud2e48992023-12-05 16:29:51 +080080 handlers.emplace(
81 PLDM_SET_NUMERIC_EFFECTER_VALUE,
82 [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
Patrick Williams6da4f912023-05-10 07:50:53 -050083 return this->setNumericEffecterValue(request, payloadLength);
84 });
Delphine CC Chiud2e48992023-12-05 16:29:51 +080085 handlers.emplace(
86 PLDM_GET_NUMERIC_EFFECTER_VALUE,
87 [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
Archana Kakani6ece21fb2023-10-10 08:21:52 -050088 return this->getNumericEffecterValue(request, payloadLength);
89 });
Delphine CC Chiud2e48992023-12-05 16:29:51 +080090 handlers.emplace(
91 PLDM_SET_STATE_EFFECTER_STATES,
92 [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
Patrick Williams6da4f912023-05-10 07:50:53 -050093 return this->setStateEffecterStates(request, payloadLength);
94 });
Delphine CC Chiud2e48992023-12-05 16:29:51 +080095 handlers.emplace(
96 PLDM_PLATFORM_EVENT_MESSAGE,
97 [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
Patrick Williams6da4f912023-05-10 07:50:53 -050098 return this->platformEventMessage(request, payloadLength);
99 });
Delphine CC Chiud2e48992023-12-05 16:29:51 +0800100 handlers.emplace(
101 PLDM_GET_STATE_SENSOR_READINGS,
102 [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
Patrick Williams6da4f912023-05-10 07:50:53 -0500103 return this->getStateSensorReadings(request, payloadLength);
104 });
Tom Joseph56e45c52020-03-16 10:01:45 +0530105
106 // Default handler for PLDM Events
107 eventHandlers[PLDM_SENSOR_EVENT].emplace_back(
108 [this](const pldm_msg* request, size_t payloadLength,
109 uint8_t formatVersion, uint8_t tid, size_t eventDataOffset) {
Patrick Williams6da4f912023-05-10 07:50:53 -0500110 return this->sensorEvent(request, payloadLength, formatVersion, tid,
111 eventDataOffset);
112 });
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500113 eventHandlers[PLDM_PDR_REPOSITORY_CHG_EVENT].emplace_back(
114 [this](const pldm_msg* request, size_t payloadLength,
115 uint8_t formatVersion, uint8_t tid, size_t eventDataOffset) {
Patrick Williams6da4f912023-05-10 07:50:53 -0500116 return this->pldmPDRRepositoryChgEvent(
117 request, payloadLength, formatVersion, tid, eventDataOffset);
118 });
Tom Joseph56e45c52020-03-16 10:01:45 +0530119
120 // Additional OEM event handlers for PLDM events, append it to the
121 // standard handlers
122 if (addOnHandlersMap)
123 {
124 auto addOnHandlers = addOnHandlersMap.value();
125 for (EventMap::iterator iter = addOnHandlers.begin();
126 iter != addOnHandlers.end(); ++iter)
127 {
128 auto search = eventHandlers.find(iter->first);
129 if (search != eventHandlers.end())
130 {
131 search->second.insert(std::end(search->second),
132 std::begin(iter->second),
133 std::end(iter->second));
134 }
135 else
136 {
137 eventHandlers.emplace(iter->first, iter->second);
138 }
139 }
140 }
Sampa Misraa2fa0702019-05-31 01:28:55 -0500141 }
142
George Liu1ec85d42020-02-12 16:05:32 +0800143 pdr_utils::Repo& getRepo()
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600144 {
George Liu1ec85d42020-02-12 16:05:32 +0800145 return this->pdrRepo;
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600146 }
147
George Liu1ec85d42020-02-12 16:05:32 +0800148 /** @brief Add D-Bus mapping and value mapping(stateId to D-Bus) for the
George Liuadbe1722020-05-09 19:20:19 +0800149 * Id. If the same id is added, the previous dbusObjs will
George Liu1ec85d42020-02-12 16:05:32 +0800150 * be "over-written".
151 *
George Liuadbe1722020-05-09 19:20:19 +0800152 * @param[in] Id - effecter/sensor id
George Liu1ec85d42020-02-12 16:05:32 +0800153 * @param[in] dbusObj - list of D-Bus object structure and list of D-Bus
154 * property value to attribute value
George Liuadbe1722020-05-09 19:20:19 +0800155 * @param[in] typeId - the type id of enum
George Liu1ec85d42020-02-12 16:05:32 +0800156 */
George Liua2870722020-02-11 11:09:30 +0800157 void addDbusObjMaps(
George Liuadbe1722020-05-09 19:20:19 +0800158 uint16_t id,
159 std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> dbusObj,
Brad Bishop5079ac42021-08-19 18:35:06 -0400160 pldm::responder::pdr_utils::TypeId typeId =
161 pldm::responder::pdr_utils::TypeId::PLDM_EFFECTER_ID);
George Liu1ec85d42020-02-12 16:05:32 +0800162
George Liuadbe1722020-05-09 19:20:19 +0800163 /** @brief Retrieve an id -> D-Bus objects mapping
George Liu1ec85d42020-02-12 16:05:32 +0800164 *
George Liuadbe1722020-05-09 19:20:19 +0800165 * @param[in] Id - id
166 * @param[in] typeId - the type id of enum
George Liu1ec85d42020-02-12 16:05:32 +0800167 *
George Liua2870722020-02-11 11:09:30 +0800168 * @return std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> -
169 * list of D-Bus object structure and list of D-Bus property value
170 * to attribute value
George Liu1ec85d42020-02-12 16:05:32 +0800171 */
George Liua2870722020-02-11 11:09:30 +0800172 const std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>&
Brad Bishop5079ac42021-08-19 18:35:06 -0400173 getDbusObjMaps(
174 uint16_t id,
175 pldm::responder::pdr_utils::TypeId typeId =
176 pldm::responder::pdr_utils::TypeId::PLDM_EFFECTER_ID) const;
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600177
178 uint16_t getNextEffecterId()
179 {
180 return ++nextEffecterId;
181 }
182
George Liuadbe1722020-05-09 19:20:19 +0800183 uint16_t getNextSensorId()
184 {
185 return ++nextSensorId;
186 }
187
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600188 /** @brief Parse PDR JSONs and build PDR repository
189 *
George Liu36e81352020-07-01 14:40:30 +0800190 * @param[in] dBusIntf - The interface object
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600191 * @param[in] dir - directory housing platform specific PDR JSON files
192 * @param[in] repo - instance of concrete implementation of Repo
193 */
George Liu36e81352020-07-01 14:40:30 +0800194 void generate(const pldm::utils::DBusHandler& dBusIntf,
Brad Bishop5079ac42021-08-19 18:35:06 -0400195 const std::string& dir,
196 pldm::responder::pdr_utils::Repo& repo);
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600197
198 /** @brief Parse PDR JSONs and build state effecter PDR repository
199 *
200 * @param[in] json - platform specific PDR JSON files
201 * @param[in] repo - instance of state effecter implementation of Repo
202 */
Brad Bishop5079ac42021-08-19 18:35:06 -0400203 void generateStateEffecterRepo(const pldm::utils::Json& json,
204 pldm::responder::pdr_utils::Repo& repo);
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600205
Tom Joseph56e45c52020-03-16 10:01:45 +0530206 /** @brief map of PLDM event type to EventHandlers
207 *
208 */
209 EventMap eventHandlers;
210
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600211 /** @brief Handler for GetPDR
212 *
213 * @param[in] request - Request message payload
214 * @param[in] payloadLength - Request payload length
215 * @param[out] Response - Response message written here
216 */
217 Response getPDR(const pldm_msg* request, size_t payloadLength);
Sampa Misraa2fa0702019-05-31 01:28:55 -0500218
George Liueccb0c52020-01-14 11:09:56 +0800219 /** @brief Handler for setNumericEffecterValue
220 *
221 * @param[in] request - Request message
222 * @param[in] payloadLength - Request payload length
223 * @return Response - PLDM Response message
224 */
225 Response setNumericEffecterValue(const pldm_msg* request,
226 size_t payloadLength);
227
Archana Kakani6ece21fb2023-10-10 08:21:52 -0500228 /** @brief Handler for getNumericEffecterValue
229 *
230 * @param[in] request - Request message
231 * @param[in] payloadLength - Request payload length
232 * @return Response - PLDM Response message
233 */
234 Response getNumericEffecterValue(const pldm_msg* request,
235 size_t payloadLength);
236
George Liu362c18d2020-05-14 09:46:36 +0800237 /** @brief Handler for getStateSensorReadings
238 *
239 * @param[in] request - Request message
240 * @param[in] payloadLength - Request payload length
241 * @return Response - PLDM Response message
242 */
243 Response getStateSensorReadings(const pldm_msg* request,
244 size_t payloadLength);
245
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600246 /** @brief Handler for setStateEffecterStates
247 *
248 * @param[in] request - Request message
249 * @param[in] payloadLength - Request payload length
250 * @return Response - PLDM Response message
251 */
252 Response setStateEffecterStates(const pldm_msg* request,
253 size_t payloadLength);
254
Tom Joseph56e45c52020-03-16 10:01:45 +0530255 /** @brief Handler for PlatformEventMessage
256 *
257 * @param[in] request - Request message
258 * @param[in] payloadLength - Request payload length
259 * @return Response - PLDM Response message
260 */
261 Response platformEventMessage(const pldm_msg* request,
262 size_t payloadLength);
263
264 /** @brief Handler for event class Sensor event
265 *
266 * @param[in] request - Request message
267 * @param[in] payloadLength - Request payload length
268 * @param[in] formatVersion - Version of the event format
269 * @param[in] tid - Terminus ID of the event's originator
270 * @param[in] eventDataOffset - Offset of the event data in the request
271 * message
272 * @return PLDM completion code
273 */
274 int sensorEvent(const pldm_msg* request, size_t payloadLength,
275 uint8_t formatVersion, uint8_t tid, size_t eventDataOffset);
276
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500277 /** @brief Handler for pldmPDRRepositoryChgEvent
278 *
279 * @param[in] request - Request message
280 * @param[in] payloadLength - Request payload length
281 * @param[in] formatVersion - Version of the event format
282 * @param[in] tid - Terminus ID of the event's originator
283 * @param[in] eventDataOffset - Offset of the event data in the request
284 * message
285 * @return PLDM completion code
286 */
287 int pldmPDRRepositoryChgEvent(const pldm_msg* request, size_t payloadLength,
288 uint8_t formatVersion, uint8_t tid,
289 size_t eventDataOffset);
290
291 /** @brief Handler for extracting the PDR handles from changeEntries
292 *
293 * @param[in] changeEntryData - ChangeEntry data from changeRecord
294 * @param[in] changeEntryDataSize - total size of changeEntryData
295 * @param[in] numberOfChangeEntries - total number of changeEntries to
296 * extract
297 * @param[out] pdrRecordHandles - std::vector where the extracted PDR
298 * handles are placed
299 * @return PLDM completion code
300 */
301 int getPDRRecordHandles(const ChangeEntry* changeEntryData,
302 size_t changeEntryDataSize,
303 size_t numberOfChangeEntries,
304 PDRRecordHandles& pdrRecordHandles);
305
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600306 /** @brief Function to set the effecter requested by pldm requester
307 * @param[in] dBusIntf - The interface object
308 * @param[in] effecterId - Effecter ID sent by the requester to act on
309 * @param[in] stateField - The state field data for each of the states,
310 * equal to composite effecter count in number
311 * @return - Success or failure in setting the states. Returns failure in
312 * terms of PLDM completion codes if atleast one state fails to be set
313 */
314 template <class DBusInterface>
315 int setStateEffecterStatesHandler(
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600316 const DBusInterface& dBusIntf, uint16_t effecterId,
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600317 const std::vector<set_effecter_state_field>& stateField)
Sampa Misraa2fa0702019-05-31 01:28:55 -0500318 {
George Liue53193f2020-02-24 09:23:26 +0800319 using namespace pldm::responder::pdr;
George Liu1e44c732020-02-28 20:20:06 +0800320 using namespace pldm::utils;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600321 using StateSetNum = uint8_t;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600322
323 state_effecter_possible_states* states = nullptr;
324 pldm_state_effecter_pdr* pdr = nullptr;
325 uint8_t compEffecterCnt = stateField.size();
George Liu1ec85d42020-02-12 16:05:32 +0800326
327 std::unique_ptr<pldm_pdr, decltype(&pldm_pdr_destroy)>
328 stateEffecterPdrRepo(pldm_pdr_init(), pldm_pdr_destroy);
Andrew Jefferyacb20292023-06-30 11:47:44 +0930329 if (!stateEffecterPdrRepo)
330 {
331 throw std::runtime_error(
332 "Failed to instantiate state effecter PDR repository");
333 }
Brad Bishop5079ac42021-08-19 18:35:06 -0400334 pldm::responder::pdr_utils::Repo stateEffecterPDRs(
335 stateEffecterPdrRepo.get());
George Liu1ec85d42020-02-12 16:05:32 +0800336 getRepoByType(pdrRepo, stateEffecterPDRs, PLDM_STATE_EFFECTER_PDR);
337 if (stateEffecterPDRs.empty())
338 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600339 error("Failed to get record by PDR type");
George Liu1ec85d42020-02-12 16:05:32 +0800340 return PLDM_PLATFORM_INVALID_EFFECTER_ID;
341 }
342
Brad Bishop5079ac42021-08-19 18:35:06 -0400343 pldm::responder::pdr_utils::PdrEntry pdrEntry{};
George Liu1ec85d42020-02-12 16:05:32 +0800344 auto pdrRecord = stateEffecterPDRs.getFirstRecord(pdrEntry);
George Liue53193f2020-02-24 09:23:26 +0800345 while (pdrRecord)
346 {
347 pdr = reinterpret_cast<pldm_state_effecter_pdr*>(pdrEntry.data);
348 if (pdr->effecter_id != effecterId)
Sampa Misraa2fa0702019-05-31 01:28:55 -0500349 {
George Liue53193f2020-02-24 09:23:26 +0800350 pdr = nullptr;
Patrick Williams6da4f912023-05-10 07:50:53 -0500351 pdrRecord = stateEffecterPDRs.getNextRecord(pdrRecord,
352 pdrEntry);
George Liue53193f2020-02-24 09:23:26 +0800353 continue;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600354 }
George Liue53193f2020-02-24 09:23:26 +0800355
356 states = reinterpret_cast<state_effecter_possible_states*>(
357 pdr->possible_states);
358 if (compEffecterCnt > pdr->composite_effecter_count)
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600359 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600360 error(
361 "The requester sent wrong composite effecter count for the effecter, EFFECTER_ID={EFFECTER_ID} COMP_EFF_CNT={COMP_EFF_CNT}",
362 "EFFECTER_ID", (unsigned)effecterId, "COMP_EFF_CNT",
363 (unsigned)compEffecterCnt);
George Liue53193f2020-02-24 09:23:26 +0800364 return PLDM_ERROR_INVALID_DATA;
Sampa Misraa2fa0702019-05-31 01:28:55 -0500365 }
George Liue53193f2020-02-24 09:23:26 +0800366 break;
367 }
368
369 if (!pdr)
370 {
371 return PLDM_PLATFORM_INVALID_EFFECTER_ID;
Sampa Misraa2fa0702019-05-31 01:28:55 -0500372 }
Sampa Misraa2fa0702019-05-31 01:28:55 -0500373
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600374 int rc = PLDM_SUCCESS;
George Liu1ec85d42020-02-12 16:05:32 +0800375 try
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600376 {
Patrick Williams6da4f912023-05-10 07:50:53 -0500377 const auto& [dbusMappings,
378 dbusValMaps] = effecterDbusObjMaps.at(effecterId);
George Liu1ec85d42020-02-12 16:05:32 +0800379 for (uint8_t currState = 0; currState < compEffecterCnt;
380 ++currState)
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600381 {
George Liu1ec85d42020-02-12 16:05:32 +0800382 std::vector<StateSetNum> allowed{};
383 // computation is based on table 79 from DSP0248 v1.1.1
Patrick Williams6da4f912023-05-10 07:50:53 -0500384 uint8_t bitfieldIndex = stateField[currState].effecter_state /
385 8;
386 uint8_t bit = stateField[currState].effecter_state -
387 (8 * bitfieldIndex);
George Liu1ec85d42020-02-12 16:05:32 +0800388 if (states->possible_states_size < bitfieldIndex ||
389 !(states->states[bitfieldIndex].byte & (1 << bit)))
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600390 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600391 error(
392 "Invalid state set value, EFFECTER_ID={EFFECTER_ID} VALUE={EFFECTER_STATE} COMPOSITE_EFFECTER_ID={CURR_STATE} DBUS_PATH={DBUS_OBJ_PATH}",
393 "EFFECTER_ID", (unsigned)effecterId, "EFFECTER_STATE",
394 (unsigned)stateField[currState].effecter_state,
395 "CURR_STATE", (unsigned)currState, "DBUS_OBJ_PATH",
396 dbusMappings[currState].objectPath.c_str());
George Liu1ec85d42020-02-12 16:05:32 +0800397 rc = PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600398 break;
399 }
George Liu1ec85d42020-02-12 16:05:32 +0800400 const DBusMapping& dbusMapping = dbusMappings[currState];
Brad Bishop5079ac42021-08-19 18:35:06 -0400401 const pldm::responder::pdr_utils::StatestoDbusVal&
402 dbusValToMap = dbusValMaps[currState];
George Liu1ec85d42020-02-12 16:05:32 +0800403
404 if (stateField[currState].set_request == PLDM_REQUEST_SET)
405 {
406 try
407 {
408 dBusIntf.setDbusProperty(
409 dbusMapping,
410 dbusValToMap.at(
411 stateField[currState].effecter_state));
412 }
413 catch (const std::exception& e)
414 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600415 error(
416 "Error setting property, ERROR={ERR_EXCEP} PROPERTY={DBUS_PROP} INTERFACE={DBUS_INTF} PATH={DBUS_OBJ_PATH}",
417 "ERR_EXCEP", e.what(), "DBUS_PROP",
418 dbusMapping.propertyName, "DBUS_INTF",
419 dbusMapping.interface, "DBUS_OBJ_PATH",
420 dbusMapping.objectPath.c_str());
George Liu1ec85d42020-02-12 16:05:32 +0800421 return PLDM_ERROR;
422 }
423 }
424 uint8_t* nextState =
425 reinterpret_cast<uint8_t*>(states) +
426 sizeof(state_effecter_possible_states) -
427 sizeof(states->states) +
428 (states->possible_states_size * sizeof(states->states));
429 states = reinterpret_cast<state_effecter_possible_states*>(
430 nextState);
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600431 }
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600432 }
George Liu1ec85d42020-02-12 16:05:32 +0800433 catch (const std::out_of_range& e)
434 {
Riya Dixit49cfb132023-03-02 04:26:53 -0600435 error(
436 "the effecterId does not exist. effecter id: {EFFECTER_ID} {ERR_EXCEP}",
437 "EFFECTER_ID", (unsigned)effecterId, "ERR_EXCEP", e.what());
George Liu1ec85d42020-02-12 16:05:32 +0800438 }
439
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600440 return rc;
441 }
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600442
Sampa Misra12afe112020-05-25 11:40:44 -0500443 /** @brief Build BMC Terminus Locator PDR
444 *
445 * @param[in] repo - instance of concrete implementation of Repo
446 */
Brad Bishop5079ac42021-08-19 18:35:06 -0400447 void generateTerminusLocatorPDR(pldm::responder::pdr_utils::Repo& repo);
Sampa Misra12afe112020-05-25 11:40:44 -0500448
George Liuc4ea6a92020-07-14 15:48:44 +0800449 /** @brief Get std::map associated with the entity
450 * key: object path
451 * value: pldm_entity
452 *
453 * @return std::map<ObjectPath, pldm_entity>
454 */
455 inline const AssociatedEntityMap& getAssociateEntityMap() const
456 {
457 if (fruHandler == nullptr)
458 {
459 throw InternalFailure();
460 }
461 return fruHandler->getAssociateEntityMap();
462 }
463
Sampa Misra5fb37d52021-03-06 07:26:00 -0600464 /** @brief process the actions that needs to be performed after a GetPDR
465 * call is received
466 * @param[in] source - sdeventplus event source
467 */
468 void _processPostGetPDRActions(sdeventplus::source::EventBase& source);
469
Sagar Srinivas90314a32023-10-17 10:38:03 -0500470 /** @brief Method for setEventreceiver */
471 void setEventReceiver();
472
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600473 private:
Sagar Srinivas90314a32023-10-17 10:38:03 -0500474 uint8_t eid;
475 InstanceIdDb* instanceIdDb;
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600476 pdr_utils::Repo pdrRepo;
477 uint16_t nextEffecterId{};
George Liuadbe1722020-05-09 19:20:19 +0800478 uint16_t nextSensorId{};
479 DbusObjMaps effecterDbusObjMaps{};
480 DbusObjMaps sensorDbusObjMaps{};
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500481 HostPDRHandler* hostPDRHandler;
Brad Bishop5079ac42021-08-19 18:35:06 -0400482 pldm::state_sensor::DbusToPLDMEvent* dbusToPLDMEventHandler;
Tom Joseph33e9c7e2020-06-11 22:09:52 +0530483 fru::Handler* fruHandler;
Deepak Kodihallib5c227e2020-07-13 06:58:34 -0500484 const pldm::utils::DBusHandler* dBusIntf;
Sampa Misraaea5dde2020-08-31 08:33:47 -0500485 pldm::responder::oem_platform::Handler* oemPlatformHandler;
Sagar Srinivas90314a32023-10-17 10:38:03 -0500486 pldm::requester::Handler<pldm::requester::Request>* handler;
Sampa Misra5fb37d52021-03-06 07:26:00 -0600487 sdeventplus::Event& event;
Deepak Kodihallib5c227e2020-07-13 06:58:34 -0500488 std::string pdrJsonsDir;
489 bool pdrCreated;
Sampa Misra5fb37d52021-03-06 07:26:00 -0600490 std::unique_ptr<sdeventplus::source::Defer> deferredGetPDREvent;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600491};
492
Sampa Misraaea5dde2020-08-31 08:33:47 -0500493/** @brief Function to check if a sensor falls in OEM range
494 * A sensor is considered to be oem if either of entity
495 * type or state set or both falls in oem range
496 *
497 * @param[in] handler - the interface object
498 * @param[in] sensorId - sensor id
499 * @param[in] sensorRearmCount - sensor rearm count
500 * @param[out] compSensorCnt - composite sensor count
501 * @param[out] entityType - entity type
502 * @param[out] entityInstance - entity instance number
503 * @param[out] stateSetId - state set id
504 *
505 * @return true if the sensor is OEM. All out parameters are invalid
506 * for a non OEM sensor
507 */
508bool isOemStateSensor(Handler& handler, uint16_t sensorId,
509 uint8_t sensorRearmCount, uint8_t& compSensorCnt,
510 uint16_t& entityType, uint16_t& entityInstance,
511 uint16_t& stateSetId);
512
513/** @brief Function to check if an effecter falls in OEM range
514 * An effecter is considered to be oem if either of entity
515 * type or state set or both falls in oem range
516 *
517 * @param[in] handler - the interface object
518 * @param[in] effecterId - effecter id
519 * @param[in] compEffecterCnt - composite effecter count
520 * @param[out] entityType - entity type
521 * @param[out] entityInstance - entity instance number
522 * @param[out] stateSetId - state set id
523 *
524 * @return true if the effecter is OEM. All out parameters are invalid
525 * for a non OEM effecter
526 */
527bool isOemStateEffecter(Handler& handler, uint16_t effecterId,
528 uint8_t compEffecterCnt, uint16_t& entityType,
529 uint16_t& entityInstance, uint16_t& stateSetId);
530
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600531} // namespace platform
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530532} // namespace responder
533} // namespace pldm