blob: de818988614caec70f3c46c6b8dbcac97c7b7f16 [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
George Liu6492f522020-06-16 10:34:05 +08005#include "libpldm/platform.h"
6#include "libpldm/states.h"
George Liuc4ea6a92020-07-14 15:48:44 +08007#include "pdr.h"
George Liu6492f522020-06-16 10:34:05 +08008
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
George Liu1ec85d42020-02-12 16:05:32 +080030using namespace pldm::utils;
31using namespace pldm::responder::pdr_utils;
George Liucae18662020-05-15 09:32:57 +080032using namespace pldm::state_sensor;
George Liu1ec85d42020-02-12 16:05:32 +080033
George Liua2870722020-02-11 11:09:30 +080034using generatePDR =
George Liu36e81352020-07-01 14:40:30 +080035 std::function<void(const pldm::utils::DBusHandler& dBusIntf,
36 const Json& json, pdr_utils::RepoInterface& repo)>;
George Liua2870722020-02-11 11:09:30 +080037
George Liu1ec85d42020-02-12 16:05:32 +080038using EffecterId = uint16_t;
George Liua2870722020-02-11 11:09:30 +080039using DbusObjMaps =
40 std::map<EffecterId,
41 std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>>;
Tom Joseph56e45c52020-03-16 10:01:45 +053042using DbusPath = std::string;
43using EffecterObjs = std::vector<DbusPath>;
44using EventType = uint8_t;
45using EventHandler = std::function<int(
46 const pldm_msg* request, size_t payloadLength, uint8_t formatVersion,
47 uint8_t tid, size_t eventDataOffset)>;
48using EventHandlers = std::vector<EventHandler>;
49using EventMap = std::map<EventType, EventHandlers>;
George Liuc4ea6a92020-07-14 15:48:44 +080050using AssociatedEntityMap = std::map<DbusPath, pldm_entity>;
Deepak Kodihallic682fe22020-03-04 00:42:54 -060051
Deepak Kodihallibc669f12019-11-28 08:52:07 -060052class Handler : public CmdHandler
Sampa Misraa2fa0702019-05-31 01:28:55 -050053{
Deepak Kodihallibc669f12019-11-28 08:52:07 -060054 public:
Deepak Kodihallib5c227e2020-07-13 06:58:34 -050055 Handler(const pldm::utils::DBusHandler* dBusIntf,
Pavithra Barithaya3aec9972020-12-14 01:55:44 -060056 const std::string& pdrJsonsDir, pldm_pdr* repo,
57 HostPDRHandler* hostPDRHandler,
George Liucae18662020-05-15 09:32:57 +080058 DbusToPLDMEvent* dbusToPLDMEventHandler, fru::Handler* fruHandler,
Sampa Misraaea5dde2020-08-31 08:33:47 -050059 pldm::responder::oem_platform::Handler* oemPlatformHandler,
Sampa Misra5fb37d52021-03-06 07:26:00 -060060 sdeventplus::Event& event, bool buildPDRLazily = false,
Tom Joseph56e45c52020-03-16 10:01:45 +053061 const std::optional<EventMap>& addOnHandlersMap = std::nullopt) :
Pavithra Barithaya51efaf82020-04-02 02:42:27 -050062 pdrRepo(repo),
Pavithra Barithaya3aec9972020-12-14 01:55:44 -060063 hostPDRHandler(hostPDRHandler),
George Liucae18662020-05-15 09:32:57 +080064 dbusToPLDMEventHandler(dbusToPLDMEventHandler), fruHandler(fruHandler),
Sampa Misraaea5dde2020-08-31 08:33:47 -050065 dBusIntf(dBusIntf), oemPlatformHandler(oemPlatformHandler),
Sampa Misra5fb37d52021-03-06 07:26:00 -060066 event(event), pdrJsonsDir(pdrJsonsDir), 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
Deepak Kodihallibc669f12019-11-28 08:52:07 -060075 handlers.emplace(PLDM_GET_PDR,
76 [this](const pldm_msg* request, size_t payloadLength) {
77 return this->getPDR(request, payloadLength);
78 });
George Liueccb0c52020-01-14 11:09:56 +080079 handlers.emplace(PLDM_SET_NUMERIC_EFFECTER_VALUE,
80 [this](const pldm_msg* request, size_t payloadLength) {
81 return this->setNumericEffecterValue(
82 request, payloadLength);
83 });
Deepak Kodihallibc669f12019-11-28 08:52:07 -060084 handlers.emplace(PLDM_SET_STATE_EFFECTER_STATES,
85 [this](const pldm_msg* request, size_t payloadLength) {
86 return this->setStateEffecterStates(request,
87 payloadLength);
88 });
Tom Joseph56e45c52020-03-16 10:01:45 +053089 handlers.emplace(PLDM_PLATFORM_EVENT_MESSAGE,
90 [this](const pldm_msg* request, size_t payloadLength) {
91 return this->platformEventMessage(request,
92 payloadLength);
93 });
George Liu362c18d2020-05-14 09:46:36 +080094 handlers.emplace(PLDM_GET_STATE_SENSOR_READINGS,
95 [this](const pldm_msg* request, size_t payloadLength) {
96 return this->getStateSensorReadings(request,
97 payloadLength);
98 });
Tom Joseph56e45c52020-03-16 10:01:45 +053099
100 // Default handler for PLDM Events
101 eventHandlers[PLDM_SENSOR_EVENT].emplace_back(
102 [this](const pldm_msg* request, size_t payloadLength,
103 uint8_t formatVersion, uint8_t tid, size_t eventDataOffset) {
104 return this->sensorEvent(request, payloadLength, formatVersion,
105 tid, eventDataOffset);
106 });
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500107 eventHandlers[PLDM_PDR_REPOSITORY_CHG_EVENT].emplace_back(
108 [this](const pldm_msg* request, size_t payloadLength,
109 uint8_t formatVersion, uint8_t tid, size_t eventDataOffset) {
110 return this->pldmPDRRepositoryChgEvent(request, payloadLength,
111 formatVersion, tid,
112 eventDataOffset);
113 });
Tom Joseph56e45c52020-03-16 10:01:45 +0530114
115 // Additional OEM event handlers for PLDM events, append it to the
116 // standard handlers
117 if (addOnHandlersMap)
118 {
119 auto addOnHandlers = addOnHandlersMap.value();
120 for (EventMap::iterator iter = addOnHandlers.begin();
121 iter != addOnHandlers.end(); ++iter)
122 {
123 auto search = eventHandlers.find(iter->first);
124 if (search != eventHandlers.end())
125 {
126 search->second.insert(std::end(search->second),
127 std::begin(iter->second),
128 std::end(iter->second));
129 }
130 else
131 {
132 eventHandlers.emplace(iter->first, iter->second);
133 }
134 }
135 }
Sampa Misraa2fa0702019-05-31 01:28:55 -0500136 }
137
George Liu1ec85d42020-02-12 16:05:32 +0800138 pdr_utils::Repo& getRepo()
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600139 {
George Liu1ec85d42020-02-12 16:05:32 +0800140 return this->pdrRepo;
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600141 }
142
George Liu1ec85d42020-02-12 16:05:32 +0800143 /** @brief Add D-Bus mapping and value mapping(stateId to D-Bus) for the
George Liuadbe1722020-05-09 19:20:19 +0800144 * Id. If the same id is added, the previous dbusObjs will
George Liu1ec85d42020-02-12 16:05:32 +0800145 * be "over-written".
146 *
George Liuadbe1722020-05-09 19:20:19 +0800147 * @param[in] Id - effecter/sensor id
George Liu1ec85d42020-02-12 16:05:32 +0800148 * @param[in] dbusObj - list of D-Bus object structure and list of D-Bus
149 * property value to attribute value
George Liuadbe1722020-05-09 19:20:19 +0800150 * @param[in] typeId - the type id of enum
George Liu1ec85d42020-02-12 16:05:32 +0800151 */
George Liua2870722020-02-11 11:09:30 +0800152 void addDbusObjMaps(
George Liuadbe1722020-05-09 19:20:19 +0800153 uint16_t id,
154 std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> dbusObj,
155 TypeId typeId = TypeId::PLDM_EFFECTER_ID);
George Liu1ec85d42020-02-12 16:05:32 +0800156
George Liuadbe1722020-05-09 19:20:19 +0800157 /** @brief Retrieve an id -> D-Bus objects mapping
George Liu1ec85d42020-02-12 16:05:32 +0800158 *
George Liuadbe1722020-05-09 19:20:19 +0800159 * @param[in] Id - id
160 * @param[in] typeId - the type id of enum
George Liu1ec85d42020-02-12 16:05:32 +0800161 *
George Liua2870722020-02-11 11:09:30 +0800162 * @return std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> -
163 * list of D-Bus object structure and list of D-Bus property value
164 * to attribute value
George Liu1ec85d42020-02-12 16:05:32 +0800165 */
George Liua2870722020-02-11 11:09:30 +0800166 const std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>&
George Liuadbe1722020-05-09 19:20:19 +0800167 getDbusObjMaps(uint16_t id,
168 TypeId typeId = 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,
187 const std::string& dir, Repo& repo);
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600188
189 /** @brief Parse PDR JSONs and build state effecter PDR repository
190 *
191 * @param[in] json - platform specific PDR JSON files
192 * @param[in] repo - instance of state effecter implementation of Repo
193 */
194 void generateStateEffecterRepo(const Json& json, Repo& repo);
195
Tom Joseph56e45c52020-03-16 10:01:45 +0530196 /** @brief map of PLDM event type to EventHandlers
197 *
198 */
199 EventMap eventHandlers;
200
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600201 /** @brief Handler for GetPDR
202 *
203 * @param[in] request - Request message payload
204 * @param[in] payloadLength - Request payload length
205 * @param[out] Response - Response message written here
206 */
207 Response getPDR(const pldm_msg* request, size_t payloadLength);
Sampa Misraa2fa0702019-05-31 01:28:55 -0500208
George Liueccb0c52020-01-14 11:09:56 +0800209 /** @brief Handler for setNumericEffecterValue
210 *
211 * @param[in] request - Request message
212 * @param[in] payloadLength - Request payload length
213 * @return Response - PLDM Response message
214 */
215 Response setNumericEffecterValue(const pldm_msg* request,
216 size_t payloadLength);
217
George Liu362c18d2020-05-14 09:46:36 +0800218 /** @brief Handler for getStateSensorReadings
219 *
220 * @param[in] request - Request message
221 * @param[in] payloadLength - Request payload length
222 * @return Response - PLDM Response message
223 */
224 Response getStateSensorReadings(const pldm_msg* request,
225 size_t payloadLength);
226
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600227 /** @brief Handler for setStateEffecterStates
228 *
229 * @param[in] request - Request message
230 * @param[in] payloadLength - Request payload length
231 * @return Response - PLDM Response message
232 */
233 Response setStateEffecterStates(const pldm_msg* request,
234 size_t payloadLength);
235
Tom Joseph56e45c52020-03-16 10:01:45 +0530236 /** @brief Handler for PlatformEventMessage
237 *
238 * @param[in] request - Request message
239 * @param[in] payloadLength - Request payload length
240 * @return Response - PLDM Response message
241 */
242 Response platformEventMessage(const pldm_msg* request,
243 size_t payloadLength);
244
245 /** @brief Handler for event class Sensor event
246 *
247 * @param[in] request - Request message
248 * @param[in] payloadLength - Request payload length
249 * @param[in] formatVersion - Version of the event format
250 * @param[in] tid - Terminus ID of the event's originator
251 * @param[in] eventDataOffset - Offset of the event data in the request
252 * message
253 * @return PLDM completion code
254 */
255 int sensorEvent(const pldm_msg* request, size_t payloadLength,
256 uint8_t formatVersion, uint8_t tid, size_t eventDataOffset);
257
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500258 /** @brief Handler for pldmPDRRepositoryChgEvent
259 *
260 * @param[in] request - Request message
261 * @param[in] payloadLength - Request payload length
262 * @param[in] formatVersion - Version of the event format
263 * @param[in] tid - Terminus ID of the event's originator
264 * @param[in] eventDataOffset - Offset of the event data in the request
265 * message
266 * @return PLDM completion code
267 */
268 int pldmPDRRepositoryChgEvent(const pldm_msg* request, size_t payloadLength,
269 uint8_t formatVersion, uint8_t tid,
270 size_t eventDataOffset);
271
272 /** @brief Handler for extracting the PDR handles from changeEntries
273 *
274 * @param[in] changeEntryData - ChangeEntry data from changeRecord
275 * @param[in] changeEntryDataSize - total size of changeEntryData
276 * @param[in] numberOfChangeEntries - total number of changeEntries to
277 * extract
278 * @param[out] pdrRecordHandles - std::vector where the extracted PDR
279 * handles are placed
280 * @return PLDM completion code
281 */
282 int getPDRRecordHandles(const ChangeEntry* changeEntryData,
283 size_t changeEntryDataSize,
284 size_t numberOfChangeEntries,
285 PDRRecordHandles& pdrRecordHandles);
286
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600287 /** @brief Function to set the effecter requested by pldm requester
288 * @param[in] dBusIntf - The interface object
289 * @param[in] effecterId - Effecter ID sent by the requester to act on
290 * @param[in] stateField - The state field data for each of the states,
291 * equal to composite effecter count in number
292 * @return - Success or failure in setting the states. Returns failure in
293 * terms of PLDM completion codes if atleast one state fails to be set
294 */
295 template <class DBusInterface>
296 int setStateEffecterStatesHandler(
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600297 const DBusInterface& dBusIntf, uint16_t effecterId,
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600298 const std::vector<set_effecter_state_field>& stateField)
Sampa Misraa2fa0702019-05-31 01:28:55 -0500299 {
George Liue53193f2020-02-24 09:23:26 +0800300 using namespace pldm::responder::pdr;
George Liu1e44c732020-02-28 20:20:06 +0800301 using namespace pldm::utils;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600302 using StateSetNum = uint8_t;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600303
304 state_effecter_possible_states* states = nullptr;
305 pldm_state_effecter_pdr* pdr = nullptr;
306 uint8_t compEffecterCnt = stateField.size();
George Liu1ec85d42020-02-12 16:05:32 +0800307
308 std::unique_ptr<pldm_pdr, decltype(&pldm_pdr_destroy)>
309 stateEffecterPdrRepo(pldm_pdr_init(), pldm_pdr_destroy);
310 Repo stateEffecterPDRs(stateEffecterPdrRepo.get());
311 getRepoByType(pdrRepo, stateEffecterPDRs, PLDM_STATE_EFFECTER_PDR);
312 if (stateEffecterPDRs.empty())
313 {
314 std::cerr << "Failed to get record by PDR type\n";
315 return PLDM_PLATFORM_INVALID_EFFECTER_ID;
316 }
317
George Liue53193f2020-02-24 09:23:26 +0800318 PdrEntry pdrEntry{};
George Liu1ec85d42020-02-12 16:05:32 +0800319 auto pdrRecord = stateEffecterPDRs.getFirstRecord(pdrEntry);
George Liue53193f2020-02-24 09:23:26 +0800320 while (pdrRecord)
321 {
322 pdr = reinterpret_cast<pldm_state_effecter_pdr*>(pdrEntry.data);
323 if (pdr->effecter_id != effecterId)
Sampa Misraa2fa0702019-05-31 01:28:55 -0500324 {
George Liue53193f2020-02-24 09:23:26 +0800325 pdr = nullptr;
George Liu1ec85d42020-02-12 16:05:32 +0800326 pdrRecord =
327 stateEffecterPDRs.getNextRecord(pdrRecord, pdrEntry);
George Liue53193f2020-02-24 09:23:26 +0800328 continue;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600329 }
George Liue53193f2020-02-24 09:23:26 +0800330
331 states = reinterpret_cast<state_effecter_possible_states*>(
332 pdr->possible_states);
333 if (compEffecterCnt > pdr->composite_effecter_count)
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600334 {
George Liue53193f2020-02-24 09:23:26 +0800335 std::cerr << "The requester sent wrong composite effecter"
336 << " count for the effecter, EFFECTER_ID="
337 << effecterId << "COMP_EFF_CNT=" << compEffecterCnt
338 << "\n";
339 return PLDM_ERROR_INVALID_DATA;
Sampa Misraa2fa0702019-05-31 01:28:55 -0500340 }
George Liue53193f2020-02-24 09:23:26 +0800341 break;
342 }
343
344 if (!pdr)
345 {
346 return PLDM_PLATFORM_INVALID_EFFECTER_ID;
Sampa Misraa2fa0702019-05-31 01:28:55 -0500347 }
Sampa Misraa2fa0702019-05-31 01:28:55 -0500348
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600349 int rc = PLDM_SUCCESS;
George Liu1ec85d42020-02-12 16:05:32 +0800350 try
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600351 {
George Liu1ec85d42020-02-12 16:05:32 +0800352 const auto& [dbusMappings, dbusValMaps] =
George Liuadbe1722020-05-09 19:20:19 +0800353 effecterDbusObjMaps.at(effecterId);
George Liu1ec85d42020-02-12 16:05:32 +0800354 for (uint8_t currState = 0; currState < compEffecterCnt;
355 ++currState)
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600356 {
George Liu1ec85d42020-02-12 16:05:32 +0800357 std::vector<StateSetNum> allowed{};
358 // computation is based on table 79 from DSP0248 v1.1.1
359 uint8_t bitfieldIndex =
360 stateField[currState].effecter_state / 8;
361 uint8_t bit =
362 stateField[currState].effecter_state - (8 * bitfieldIndex);
363 if (states->possible_states_size < bitfieldIndex ||
364 !(states->states[bitfieldIndex].byte & (1 << bit)))
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600365 {
George Liu1ec85d42020-02-12 16:05:32 +0800366 std::cerr
367 << "Invalid state set value, EFFECTER_ID=" << effecterId
368 << " VALUE=" << stateField[currState].effecter_state
369 << " COMPOSITE_EFFECTER_ID=" << currState
370 << " DBUS_PATH=" << dbusMappings[currState].objectPath
371 << "\n";
372 rc = PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600373 break;
374 }
George Liu1ec85d42020-02-12 16:05:32 +0800375 const DBusMapping& dbusMapping = dbusMappings[currState];
376 const StatestoDbusVal& dbusValToMap = dbusValMaps[currState];
377
378 if (stateField[currState].set_request == PLDM_REQUEST_SET)
379 {
380 try
381 {
382 dBusIntf.setDbusProperty(
383 dbusMapping,
384 dbusValToMap.at(
385 stateField[currState].effecter_state));
386 }
387 catch (const std::exception& e)
388 {
389 std::cerr
390 << "Error setting property, ERROR=" << e.what()
391 << " PROPERTY=" << dbusMapping.propertyName
392 << " INTERFACE="
393 << dbusMapping.interface << " PATH="
394 << dbusMapping.objectPath << "\n";
395 return PLDM_ERROR;
396 }
397 }
398 uint8_t* nextState =
399 reinterpret_cast<uint8_t*>(states) +
400 sizeof(state_effecter_possible_states) -
401 sizeof(states->states) +
402 (states->possible_states_size * sizeof(states->states));
403 states = reinterpret_cast<state_effecter_possible_states*>(
404 nextState);
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600405 }
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600406 }
George Liu1ec85d42020-02-12 16:05:32 +0800407 catch (const std::out_of_range& e)
408 {
409 std::cerr << "the effecterId does not exist. effecter id: "
410 << effecterId << e.what() << '\n';
411 }
412
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600413 return rc;
414 }
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600415
Sampa Misra12afe112020-05-25 11:40:44 -0500416 /** @brief Build BMC Terminus Locator PDR
417 *
418 * @param[in] repo - instance of concrete implementation of Repo
419 */
420 void generateTerminusLocatorPDR(Repo& repo);
421
George Liuc4ea6a92020-07-14 15:48:44 +0800422 /** @brief Get std::map associated with the entity
423 * key: object path
424 * value: pldm_entity
425 *
426 * @return std::map<ObjectPath, pldm_entity>
427 */
428 inline const AssociatedEntityMap& getAssociateEntityMap() const
429 {
430 if (fruHandler == nullptr)
431 {
432 throw InternalFailure();
433 }
434 return fruHandler->getAssociateEntityMap();
435 }
436
Sampa Misra5fb37d52021-03-06 07:26:00 -0600437 /** @brief process the actions that needs to be performed after a GetPDR
438 * call is received
439 * @param[in] source - sdeventplus event source
440 */
441 void _processPostGetPDRActions(sdeventplus::source::EventBase& source);
442
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600443 private:
444 pdr_utils::Repo pdrRepo;
445 uint16_t nextEffecterId{};
George Liuadbe1722020-05-09 19:20:19 +0800446 uint16_t nextSensorId{};
447 DbusObjMaps effecterDbusObjMaps{};
448 DbusObjMaps sensorDbusObjMaps{};
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500449 HostPDRHandler* hostPDRHandler;
George Liucae18662020-05-15 09:32:57 +0800450 DbusToPLDMEvent* dbusToPLDMEventHandler;
Tom Joseph33e9c7e2020-06-11 22:09:52 +0530451 fru::Handler* fruHandler;
Deepak Kodihallib5c227e2020-07-13 06:58:34 -0500452 const pldm::utils::DBusHandler* dBusIntf;
Sampa Misraaea5dde2020-08-31 08:33:47 -0500453 pldm::responder::oem_platform::Handler* oemPlatformHandler;
Sampa Misra5fb37d52021-03-06 07:26:00 -0600454 sdeventplus::Event& event;
Deepak Kodihallib5c227e2020-07-13 06:58:34 -0500455 std::string pdrJsonsDir;
456 bool pdrCreated;
Sampa Misra5fb37d52021-03-06 07:26:00 -0600457 std::unique_ptr<sdeventplus::source::Defer> deferredGetPDREvent;
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600458};
459
Sampa Misraaea5dde2020-08-31 08:33:47 -0500460/** @brief Function to check if a sensor falls in OEM range
461 * A sensor is considered to be oem if either of entity
462 * type or state set or both falls in oem range
463 *
464 * @param[in] handler - the interface object
465 * @param[in] sensorId - sensor id
466 * @param[in] sensorRearmCount - sensor rearm count
467 * @param[out] compSensorCnt - composite sensor count
468 * @param[out] entityType - entity type
469 * @param[out] entityInstance - entity instance number
470 * @param[out] stateSetId - state set id
471 *
472 * @return true if the sensor is OEM. All out parameters are invalid
473 * for a non OEM sensor
474 */
475bool isOemStateSensor(Handler& handler, uint16_t sensorId,
476 uint8_t sensorRearmCount, uint8_t& compSensorCnt,
477 uint16_t& entityType, uint16_t& entityInstance,
478 uint16_t& stateSetId);
479
480/** @brief Function to check if an effecter falls in OEM range
481 * An effecter is considered to be oem if either of entity
482 * type or state set or both falls in oem range
483 *
484 * @param[in] handler - the interface object
485 * @param[in] effecterId - effecter id
486 * @param[in] compEffecterCnt - composite effecter count
487 * @param[out] entityType - entity type
488 * @param[out] entityInstance - entity instance number
489 * @param[out] stateSetId - state set id
490 *
491 * @return true if the effecter is OEM. All out parameters are invalid
492 * for a non OEM effecter
493 */
494bool isOemStateEffecter(Handler& handler, uint16_t effecterId,
495 uint8_t compEffecterCnt, uint16_t& entityType,
496 uint16_t& entityInstance, uint16_t& stateSetId);
497
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600498} // namespace platform
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530499} // namespace responder
500} // namespace pldm