Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Deepak Kodihalli | d130e1a | 2020-06-17 05:55:32 -0500 | [diff] [blame] | 3 | #include "common/utils.hpp" |
TOM JOSEPH | d4d97a5 | 2020-03-23 14:36:34 +0530 | [diff] [blame] | 4 | #include "event_parser.hpp" |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 5 | #include "fru.hpp" |
George Liu | cae1866 | 2020-05-15 09:32:57 +0800 | [diff] [blame] | 6 | #include "host-bmc/dbus_to_event_handler.hpp" |
Deepak Kodihalli | ac19bd6 | 2020-06-16 08:25:23 -0500 | [diff] [blame] | 7 | #include "host-bmc/host_pdr_handler.hpp" |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 8 | #include "libpldmresponder/pdr.hpp" |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 9 | #include "libpldmresponder/pdr_utils.hpp" |
Kamalkumar Patel | 3c50c82 | 2024-01-30 07:14:40 -0600 | [diff] [blame] | 10 | #include "libpldmresponder/platform_config.hpp" |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 11 | #include "oem_handler.hpp" |
Deepak Kodihalli | 1521f6d | 2020-06-16 08:51:02 -0500 | [diff] [blame] | 12 | #include "pldmd/handler.hpp" |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 13 | |
George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 14 | #include <libpldm/pdr.h> |
| 15 | #include <libpldm/platform.h> |
| 16 | #include <libpldm/states.h> |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 17 | #include <stdint.h> |
| 18 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 19 | #include <phosphor-logging/lg2.hpp> |
| 20 | |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 21 | #include <map> |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 22 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 23 | PHOSPHOR_LOG2_USING; |
| 24 | |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 25 | namespace pldm |
| 26 | { |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 27 | namespace responder |
| 28 | { |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 29 | namespace platform |
| 30 | { |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 31 | using generatePDR = std::function<void(const pldm::utils::DBusHandler& dBusIntf, |
| 32 | const pldm::utils::Json& json, |
| 33 | pdr_utils::RepoInterface& repo)>; |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 34 | |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 35 | using EffecterId = uint16_t; |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 36 | using DbusObjMaps = |
| 37 | std::map<EffecterId, |
| 38 | std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>>; |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 39 | using DbusPath = std::string; |
| 40 | using EffecterObjs = std::vector<DbusPath>; |
| 41 | using EventType = uint8_t; |
| 42 | using EventHandler = std::function<int( |
| 43 | const pldm_msg* request, size_t payloadLength, uint8_t formatVersion, |
| 44 | uint8_t tid, size_t eventDataOffset)>; |
| 45 | using EventHandlers = std::vector<EventHandler>; |
| 46 | using EventMap = std::map<EventType, EventHandlers>; |
George Liu | c4ea6a9 | 2020-07-14 15:48:44 +0800 | [diff] [blame] | 47 | using AssociatedEntityMap = std::map<DbusPath, pldm_entity>; |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 48 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 49 | class Handler : public CmdHandler |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 50 | { |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 51 | public: |
Sagar Srinivas | 90314a3 | 2023-10-17 10:38:03 -0500 | [diff] [blame] | 52 | Handler(const pldm::utils::DBusHandler* dBusIntf, uint8_t eid, |
Kamalkumar Patel | 3c50c82 | 2024-01-30 07:14:40 -0600 | [diff] [blame] | 53 | pldm::InstanceIdDb* instanceIdDb, const fs::path& pdrJsonDir, |
Sagar Srinivas | 90314a3 | 2023-10-17 10:38:03 -0500 | [diff] [blame] | 54 | pldm_pdr* repo, HostPDRHandler* hostPDRHandler, |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 55 | pldm::state_sensor::DbusToPLDMEvent* dbusToPLDMEventHandler, |
| 56 | fru::Handler* fruHandler, |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 57 | pldm::responder::oem_platform::Handler* oemPlatformHandler, |
Kamalkumar Patel | 3c50c82 | 2024-01-30 07:14:40 -0600 | [diff] [blame] | 58 | pldm::responder::platform_config::Handler* platformConfigHandler, |
Sagar Srinivas | 90314a3 | 2023-10-17 10:38:03 -0500 | [diff] [blame] | 59 | pldm::requester::Handler<pldm::requester::Request>* handler, |
Sampa Misra | 5fb37d5 | 2021-03-06 07:26:00 -0600 | [diff] [blame] | 60 | sdeventplus::Event& event, bool buildPDRLazily = false, |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 61 | const std::optional<EventMap>& addOnHandlersMap = std::nullopt) : |
Sagar Srinivas | 90314a3 | 2023-10-17 10:38:03 -0500 | [diff] [blame] | 62 | eid(eid), |
| 63 | instanceIdDb(instanceIdDb), pdrRepo(repo), |
Pavithra Barithaya | 3aec997 | 2020-12-14 01:55:44 -0600 | [diff] [blame] | 64 | hostPDRHandler(hostPDRHandler), |
George Liu | cae1866 | 2020-05-15 09:32:57 +0800 | [diff] [blame] | 65 | dbusToPLDMEventHandler(dbusToPLDMEventHandler), fruHandler(fruHandler), |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 66 | dBusIntf(dBusIntf), oemPlatformHandler(oemPlatformHandler), |
Kamalkumar Patel | 3c50c82 | 2024-01-30 07:14:40 -0600 | [diff] [blame] | 67 | platformConfigHandler(platformConfigHandler), handler(handler), |
| 68 | event(event), pdrJsonDir(pdrJsonDir), pdrCreated(false), |
| 69 | pdrJsonsDir({pdrJsonDir}) |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 70 | { |
Deepak Kodihalli | b5c227e | 2020-07-13 06:58:34 -0500 | [diff] [blame] | 71 | if (!buildPDRLazily) |
| 72 | { |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 73 | generateTerminusLocatorPDR(pdrRepo); |
Deepak Kodihalli | b5c227e | 2020-07-13 06:58:34 -0500 | [diff] [blame] | 74 | generate(*dBusIntf, pdrJsonsDir, pdrRepo); |
| 75 | pdrCreated = true; |
| 76 | } |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 77 | |
Delphine CC Chiu | d2e4899 | 2023-12-05 16:29:51 +0800 | [diff] [blame] | 78 | handlers.emplace( |
| 79 | PLDM_GET_PDR, |
| 80 | [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 81 | return this->getPDR(request, payloadLength); |
| 82 | }); |
Delphine CC Chiu | d2e4899 | 2023-12-05 16:29:51 +0800 | [diff] [blame] | 83 | handlers.emplace( |
| 84 | PLDM_SET_NUMERIC_EFFECTER_VALUE, |
| 85 | [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 86 | return this->setNumericEffecterValue(request, payloadLength); |
| 87 | }); |
Delphine CC Chiu | d2e4899 | 2023-12-05 16:29:51 +0800 | [diff] [blame] | 88 | handlers.emplace( |
| 89 | PLDM_GET_NUMERIC_EFFECTER_VALUE, |
| 90 | [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) { |
Archana Kakani | 6ece21fb | 2023-10-10 08:21:52 -0500 | [diff] [blame] | 91 | return this->getNumericEffecterValue(request, payloadLength); |
| 92 | }); |
Delphine CC Chiu | d2e4899 | 2023-12-05 16:29:51 +0800 | [diff] [blame] | 93 | handlers.emplace( |
| 94 | PLDM_SET_STATE_EFFECTER_STATES, |
| 95 | [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 96 | return this->setStateEffecterStates(request, payloadLength); |
| 97 | }); |
Delphine CC Chiu | d2e4899 | 2023-12-05 16:29:51 +0800 | [diff] [blame] | 98 | handlers.emplace( |
| 99 | PLDM_PLATFORM_EVENT_MESSAGE, |
| 100 | [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 101 | return this->platformEventMessage(request, payloadLength); |
| 102 | }); |
Delphine CC Chiu | d2e4899 | 2023-12-05 16:29:51 +0800 | [diff] [blame] | 103 | handlers.emplace( |
| 104 | PLDM_GET_STATE_SENSOR_READINGS, |
| 105 | [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 106 | return this->getStateSensorReadings(request, payloadLength); |
| 107 | }); |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 108 | |
| 109 | // Default handler for PLDM Events |
| 110 | eventHandlers[PLDM_SENSOR_EVENT].emplace_back( |
| 111 | [this](const pldm_msg* request, size_t payloadLength, |
| 112 | uint8_t formatVersion, uint8_t tid, size_t eventDataOffset) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 113 | return this->sensorEvent(request, payloadLength, formatVersion, tid, |
| 114 | eventDataOffset); |
| 115 | }); |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 116 | eventHandlers[PLDM_PDR_REPOSITORY_CHG_EVENT].emplace_back( |
| 117 | [this](const pldm_msg* request, size_t payloadLength, |
| 118 | uint8_t formatVersion, uint8_t tid, size_t eventDataOffset) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 119 | return this->pldmPDRRepositoryChgEvent( |
| 120 | request, payloadLength, formatVersion, tid, eventDataOffset); |
| 121 | }); |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 122 | |
| 123 | // Additional OEM event handlers for PLDM events, append it to the |
| 124 | // standard handlers |
| 125 | if (addOnHandlersMap) |
| 126 | { |
| 127 | auto addOnHandlers = addOnHandlersMap.value(); |
| 128 | for (EventMap::iterator iter = addOnHandlers.begin(); |
| 129 | iter != addOnHandlers.end(); ++iter) |
| 130 | { |
| 131 | auto search = eventHandlers.find(iter->first); |
| 132 | if (search != eventHandlers.end()) |
| 133 | { |
| 134 | search->second.insert(std::end(search->second), |
| 135 | std::begin(iter->second), |
| 136 | std::end(iter->second)); |
| 137 | } |
| 138 | else |
| 139 | { |
| 140 | eventHandlers.emplace(iter->first, iter->second); |
| 141 | } |
| 142 | } |
| 143 | } |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 144 | } |
| 145 | |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 146 | pdr_utils::Repo& getRepo() |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 147 | { |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 148 | return this->pdrRepo; |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 149 | } |
| 150 | |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 151 | /** @brief Add D-Bus mapping and value mapping(stateId to D-Bus) for the |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 152 | * Id. If the same id is added, the previous dbusObjs will |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 153 | * be "over-written". |
| 154 | * |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 155 | * @param[in] Id - effecter/sensor id |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 156 | * @param[in] dbusObj - list of D-Bus object structure and list of D-Bus |
| 157 | * property value to attribute value |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 158 | * @param[in] typeId - the type id of enum |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 159 | */ |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 160 | void addDbusObjMaps( |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 161 | uint16_t id, |
| 162 | std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> dbusObj, |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 163 | pldm::responder::pdr_utils::TypeId typeId = |
| 164 | pldm::responder::pdr_utils::TypeId::PLDM_EFFECTER_ID); |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 165 | |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 166 | /** @brief Retrieve an id -> D-Bus objects mapping |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 167 | * |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 168 | * @param[in] Id - id |
| 169 | * @param[in] typeId - the type id of enum |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 170 | * |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 171 | * @return std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> - |
| 172 | * list of D-Bus object structure and list of D-Bus property value |
| 173 | * to attribute value |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 174 | */ |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 175 | const std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>& |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 176 | getDbusObjMaps( |
| 177 | uint16_t id, |
| 178 | pldm::responder::pdr_utils::TypeId typeId = |
| 179 | pldm::responder::pdr_utils::TypeId::PLDM_EFFECTER_ID) const; |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 180 | |
| 181 | uint16_t getNextEffecterId() |
| 182 | { |
| 183 | return ++nextEffecterId; |
| 184 | } |
| 185 | |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 186 | uint16_t getNextSensorId() |
| 187 | { |
| 188 | return ++nextSensorId; |
| 189 | } |
| 190 | |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 191 | /** @brief Parse PDR JSONs and build PDR repository |
| 192 | * |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 193 | * @param[in] dBusIntf - The interface object |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 194 | * @param[in] dir - directory housing platform specific PDR JSON files |
| 195 | * @param[in] repo - instance of concrete implementation of Repo |
| 196 | */ |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 197 | void generate(const pldm::utils::DBusHandler& dBusIntf, |
Kamalkumar Patel | 3c50c82 | 2024-01-30 07:14:40 -0600 | [diff] [blame] | 198 | const std::vector<fs::path>& dir, |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 199 | pldm::responder::pdr_utils::Repo& repo); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 200 | |
| 201 | /** @brief Parse PDR JSONs and build state effecter PDR repository |
| 202 | * |
| 203 | * @param[in] json - platform specific PDR JSON files |
| 204 | * @param[in] repo - instance of state effecter implementation of Repo |
| 205 | */ |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 206 | void generateStateEffecterRepo(const pldm::utils::Json& json, |
| 207 | pldm::responder::pdr_utils::Repo& repo); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 208 | |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 209 | /** @brief map of PLDM event type to EventHandlers |
| 210 | * |
| 211 | */ |
| 212 | EventMap eventHandlers; |
| 213 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 214 | /** @brief Handler for GetPDR |
| 215 | * |
| 216 | * @param[in] request - Request message payload |
| 217 | * @param[in] payloadLength - Request payload length |
| 218 | * @param[out] Response - Response message written here |
| 219 | */ |
| 220 | Response getPDR(const pldm_msg* request, size_t payloadLength); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 221 | |
George Liu | eccb0c5 | 2020-01-14 11:09:56 +0800 | [diff] [blame] | 222 | /** @brief Handler for setNumericEffecterValue |
| 223 | * |
| 224 | * @param[in] request - Request message |
| 225 | * @param[in] payloadLength - Request payload length |
| 226 | * @return Response - PLDM Response message |
| 227 | */ |
| 228 | Response setNumericEffecterValue(const pldm_msg* request, |
| 229 | size_t payloadLength); |
| 230 | |
Archana Kakani | 6ece21fb | 2023-10-10 08:21:52 -0500 | [diff] [blame] | 231 | /** @brief Handler for getNumericEffecterValue |
| 232 | * |
| 233 | * @param[in] request - Request message |
| 234 | * @param[in] payloadLength - Request payload length |
| 235 | * @return Response - PLDM Response message |
| 236 | */ |
| 237 | Response getNumericEffecterValue(const pldm_msg* request, |
| 238 | size_t payloadLength); |
| 239 | |
George Liu | 362c18d | 2020-05-14 09:46:36 +0800 | [diff] [blame] | 240 | /** @brief Handler for getStateSensorReadings |
| 241 | * |
| 242 | * @param[in] request - Request message |
| 243 | * @param[in] payloadLength - Request payload length |
| 244 | * @return Response - PLDM Response message |
| 245 | */ |
| 246 | Response getStateSensorReadings(const pldm_msg* request, |
| 247 | size_t payloadLength); |
| 248 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 249 | /** @brief Handler for setStateEffecterStates |
| 250 | * |
| 251 | * @param[in] request - Request message |
| 252 | * @param[in] payloadLength - Request payload length |
| 253 | * @return Response - PLDM Response message |
| 254 | */ |
| 255 | Response setStateEffecterStates(const pldm_msg* request, |
| 256 | size_t payloadLength); |
| 257 | |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 258 | /** @brief Handler for PlatformEventMessage |
| 259 | * |
| 260 | * @param[in] request - Request message |
| 261 | * @param[in] payloadLength - Request payload length |
| 262 | * @return Response - PLDM Response message |
| 263 | */ |
| 264 | Response platformEventMessage(const pldm_msg* request, |
| 265 | size_t payloadLength); |
| 266 | |
| 267 | /** @brief Handler for event class Sensor event |
| 268 | * |
| 269 | * @param[in] request - Request message |
| 270 | * @param[in] payloadLength - Request payload length |
| 271 | * @param[in] formatVersion - Version of the event format |
| 272 | * @param[in] tid - Terminus ID of the event's originator |
| 273 | * @param[in] eventDataOffset - Offset of the event data in the request |
| 274 | * message |
| 275 | * @return PLDM completion code |
| 276 | */ |
| 277 | int sensorEvent(const pldm_msg* request, size_t payloadLength, |
| 278 | uint8_t formatVersion, uint8_t tid, size_t eventDataOffset); |
| 279 | |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 280 | /** @brief Handler for pldmPDRRepositoryChgEvent |
| 281 | * |
| 282 | * @param[in] request - Request message |
| 283 | * @param[in] payloadLength - Request payload length |
| 284 | * @param[in] formatVersion - Version of the event format |
| 285 | * @param[in] tid - Terminus ID of the event's originator |
| 286 | * @param[in] eventDataOffset - Offset of the event data in the request |
| 287 | * message |
| 288 | * @return PLDM completion code |
| 289 | */ |
| 290 | int pldmPDRRepositoryChgEvent(const pldm_msg* request, size_t payloadLength, |
| 291 | uint8_t formatVersion, uint8_t tid, |
| 292 | size_t eventDataOffset); |
| 293 | |
| 294 | /** @brief Handler for extracting the PDR handles from changeEntries |
| 295 | * |
| 296 | * @param[in] changeEntryData - ChangeEntry data from changeRecord |
| 297 | * @param[in] changeEntryDataSize - total size of changeEntryData |
| 298 | * @param[in] numberOfChangeEntries - total number of changeEntries to |
| 299 | * extract |
| 300 | * @param[out] pdrRecordHandles - std::vector where the extracted PDR |
| 301 | * handles are placed |
| 302 | * @return PLDM completion code |
| 303 | */ |
| 304 | int getPDRRecordHandles(const ChangeEntry* changeEntryData, |
| 305 | size_t changeEntryDataSize, |
| 306 | size_t numberOfChangeEntries, |
| 307 | PDRRecordHandles& pdrRecordHandles); |
| 308 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 309 | /** @brief Function to set the effecter requested by pldm requester |
| 310 | * @param[in] dBusIntf - The interface object |
| 311 | * @param[in] effecterId - Effecter ID sent by the requester to act on |
| 312 | * @param[in] stateField - The state field data for each of the states, |
| 313 | * equal to composite effecter count in number |
| 314 | * @return - Success or failure in setting the states. Returns failure in |
| 315 | * terms of PLDM completion codes if atleast one state fails to be set |
| 316 | */ |
| 317 | template <class DBusInterface> |
| 318 | int setStateEffecterStatesHandler( |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 319 | const DBusInterface& dBusIntf, uint16_t effecterId, |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 320 | const std::vector<set_effecter_state_field>& stateField) |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 321 | { |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 322 | using namespace pldm::responder::pdr; |
George Liu | 1e44c73 | 2020-02-28 20:20:06 +0800 | [diff] [blame] | 323 | using namespace pldm::utils; |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 324 | using StateSetNum = uint8_t; |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 325 | |
| 326 | state_effecter_possible_states* states = nullptr; |
| 327 | pldm_state_effecter_pdr* pdr = nullptr; |
| 328 | uint8_t compEffecterCnt = stateField.size(); |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 329 | |
| 330 | std::unique_ptr<pldm_pdr, decltype(&pldm_pdr_destroy)> |
| 331 | stateEffecterPdrRepo(pldm_pdr_init(), pldm_pdr_destroy); |
Andrew Jeffery | acb2029 | 2023-06-30 11:47:44 +0930 | [diff] [blame] | 332 | if (!stateEffecterPdrRepo) |
| 333 | { |
| 334 | throw std::runtime_error( |
| 335 | "Failed to instantiate state effecter PDR repository"); |
| 336 | } |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 337 | pldm::responder::pdr_utils::Repo stateEffecterPDRs( |
| 338 | stateEffecterPdrRepo.get()); |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 339 | getRepoByType(pdrRepo, stateEffecterPDRs, PLDM_STATE_EFFECTER_PDR); |
| 340 | if (stateEffecterPDRs.empty()) |
| 341 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 342 | error("Failed to get record by PDR type"); |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 343 | return PLDM_PLATFORM_INVALID_EFFECTER_ID; |
| 344 | } |
| 345 | |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 346 | pldm::responder::pdr_utils::PdrEntry pdrEntry{}; |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 347 | auto pdrRecord = stateEffecterPDRs.getFirstRecord(pdrEntry); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 348 | while (pdrRecord) |
| 349 | { |
| 350 | pdr = reinterpret_cast<pldm_state_effecter_pdr*>(pdrEntry.data); |
| 351 | if (pdr->effecter_id != effecterId) |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 352 | { |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 353 | pdr = nullptr; |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 354 | pdrRecord = stateEffecterPDRs.getNextRecord(pdrRecord, |
| 355 | pdrEntry); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 356 | continue; |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 357 | } |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 358 | |
| 359 | states = reinterpret_cast<state_effecter_possible_states*>( |
| 360 | pdr->possible_states); |
| 361 | if (compEffecterCnt > pdr->composite_effecter_count) |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 362 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 363 | error( |
| 364 | "The requester sent wrong composite effecter count for the effecter, EFFECTER_ID={EFFECTER_ID} COMP_EFF_CNT={COMP_EFF_CNT}", |
| 365 | "EFFECTER_ID", (unsigned)effecterId, "COMP_EFF_CNT", |
| 366 | (unsigned)compEffecterCnt); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 367 | return PLDM_ERROR_INVALID_DATA; |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 368 | } |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 369 | break; |
| 370 | } |
| 371 | |
| 372 | if (!pdr) |
| 373 | { |
| 374 | return PLDM_PLATFORM_INVALID_EFFECTER_ID; |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 375 | } |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 376 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 377 | int rc = PLDM_SUCCESS; |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 378 | try |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 379 | { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 380 | const auto& [dbusMappings, |
| 381 | dbusValMaps] = effecterDbusObjMaps.at(effecterId); |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 382 | for (uint8_t currState = 0; currState < compEffecterCnt; |
| 383 | ++currState) |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 384 | { |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 385 | std::vector<StateSetNum> allowed{}; |
| 386 | // computation is based on table 79 from DSP0248 v1.1.1 |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 387 | uint8_t bitfieldIndex = stateField[currState].effecter_state / |
| 388 | 8; |
| 389 | uint8_t bit = stateField[currState].effecter_state - |
| 390 | (8 * bitfieldIndex); |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 391 | if (states->possible_states_size < bitfieldIndex || |
| 392 | !(states->states[bitfieldIndex].byte & (1 << bit))) |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 393 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 394 | error( |
| 395 | "Invalid state set value, EFFECTER_ID={EFFECTER_ID} VALUE={EFFECTER_STATE} COMPOSITE_EFFECTER_ID={CURR_STATE} DBUS_PATH={DBUS_OBJ_PATH}", |
| 396 | "EFFECTER_ID", (unsigned)effecterId, "EFFECTER_STATE", |
| 397 | (unsigned)stateField[currState].effecter_state, |
| 398 | "CURR_STATE", (unsigned)currState, "DBUS_OBJ_PATH", |
| 399 | dbusMappings[currState].objectPath.c_str()); |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 400 | rc = PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE; |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 401 | break; |
| 402 | } |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 403 | const DBusMapping& dbusMapping = dbusMappings[currState]; |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 404 | const pldm::responder::pdr_utils::StatestoDbusVal& |
| 405 | dbusValToMap = dbusValMaps[currState]; |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 406 | |
| 407 | if (stateField[currState].set_request == PLDM_REQUEST_SET) |
| 408 | { |
| 409 | try |
| 410 | { |
| 411 | dBusIntf.setDbusProperty( |
| 412 | dbusMapping, |
| 413 | dbusValToMap.at( |
| 414 | stateField[currState].effecter_state)); |
| 415 | } |
| 416 | catch (const std::exception& e) |
| 417 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 418 | error( |
| 419 | "Error setting property, ERROR={ERR_EXCEP} PROPERTY={DBUS_PROP} INTERFACE={DBUS_INTF} PATH={DBUS_OBJ_PATH}", |
| 420 | "ERR_EXCEP", e.what(), "DBUS_PROP", |
| 421 | dbusMapping.propertyName, "DBUS_INTF", |
| 422 | dbusMapping.interface, "DBUS_OBJ_PATH", |
| 423 | dbusMapping.objectPath.c_str()); |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 424 | return PLDM_ERROR; |
| 425 | } |
| 426 | } |
| 427 | uint8_t* nextState = |
| 428 | reinterpret_cast<uint8_t*>(states) + |
| 429 | sizeof(state_effecter_possible_states) - |
| 430 | sizeof(states->states) + |
| 431 | (states->possible_states_size * sizeof(states->states)); |
| 432 | states = reinterpret_cast<state_effecter_possible_states*>( |
| 433 | nextState); |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 434 | } |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 435 | } |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 436 | catch (const std::out_of_range& e) |
| 437 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 438 | error( |
| 439 | "the effecterId does not exist. effecter id: {EFFECTER_ID} {ERR_EXCEP}", |
| 440 | "EFFECTER_ID", (unsigned)effecterId, "ERR_EXCEP", e.what()); |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 441 | } |
| 442 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 443 | return rc; |
| 444 | } |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 445 | |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 446 | /** @brief Build BMC Terminus Locator PDR |
| 447 | * |
| 448 | * @param[in] repo - instance of concrete implementation of Repo |
| 449 | */ |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 450 | void generateTerminusLocatorPDR(pldm::responder::pdr_utils::Repo& repo); |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 451 | |
George Liu | c4ea6a9 | 2020-07-14 15:48:44 +0800 | [diff] [blame] | 452 | /** @brief Get std::map associated with the entity |
| 453 | * key: object path |
| 454 | * value: pldm_entity |
| 455 | * |
| 456 | * @return std::map<ObjectPath, pldm_entity> |
| 457 | */ |
| 458 | inline const AssociatedEntityMap& getAssociateEntityMap() const |
| 459 | { |
| 460 | if (fruHandler == nullptr) |
| 461 | { |
| 462 | throw InternalFailure(); |
| 463 | } |
| 464 | return fruHandler->getAssociateEntityMap(); |
| 465 | } |
| 466 | |
Manojkiran Eda | ae933cc | 2024-02-21 17:19:21 +0530 | [diff] [blame] | 467 | /** @brief update the sensor cache map |
| 468 | * @param[in] sensorId - sensor id that needs an update |
| 469 | * @param[in] sensorRearm - rearm value within the sensor |
| 470 | * @param[in] value - value that needs to be cached |
| 471 | */ |
| 472 | |
| 473 | inline void updateSensorCache(pldm::pdr::SensorID sensorId, |
| 474 | size_t sensorRearm, uint8_t value) |
| 475 | { |
| 476 | if (dbusToPLDMEventHandler) |
| 477 | { |
| 478 | dbusToPLDMEventHandler->updateSensorCacheMaps(sensorId, sensorRearm, |
| 479 | value); |
| 480 | } |
| 481 | } |
| 482 | |
Sampa Misra | 5fb37d5 | 2021-03-06 07:26:00 -0600 | [diff] [blame] | 483 | /** @brief process the actions that needs to be performed after a GetPDR |
| 484 | * call is received |
| 485 | * @param[in] source - sdeventplus event source |
| 486 | */ |
| 487 | void _processPostGetPDRActions(sdeventplus::source::EventBase& source); |
| 488 | |
Sagar Srinivas | 90314a3 | 2023-10-17 10:38:03 -0500 | [diff] [blame] | 489 | /** @brief Method for setEventreceiver */ |
| 490 | void setEventReceiver(); |
| 491 | |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 492 | private: |
Sagar Srinivas | 90314a3 | 2023-10-17 10:38:03 -0500 | [diff] [blame] | 493 | uint8_t eid; |
| 494 | InstanceIdDb* instanceIdDb; |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 495 | pdr_utils::Repo pdrRepo; |
| 496 | uint16_t nextEffecterId{}; |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 497 | uint16_t nextSensorId{}; |
| 498 | DbusObjMaps effecterDbusObjMaps{}; |
| 499 | DbusObjMaps sensorDbusObjMaps{}; |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 500 | HostPDRHandler* hostPDRHandler; |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 501 | pldm::state_sensor::DbusToPLDMEvent* dbusToPLDMEventHandler; |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 502 | fru::Handler* fruHandler; |
Deepak Kodihalli | b5c227e | 2020-07-13 06:58:34 -0500 | [diff] [blame] | 503 | const pldm::utils::DBusHandler* dBusIntf; |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 504 | pldm::responder::oem_platform::Handler* oemPlatformHandler; |
Kamalkumar Patel | 3c50c82 | 2024-01-30 07:14:40 -0600 | [diff] [blame] | 505 | pldm::responder::platform_config::Handler* platformConfigHandler; |
Sagar Srinivas | 90314a3 | 2023-10-17 10:38:03 -0500 | [diff] [blame] | 506 | pldm::requester::Handler<pldm::requester::Request>* handler; |
Sampa Misra | 5fb37d5 | 2021-03-06 07:26:00 -0600 | [diff] [blame] | 507 | sdeventplus::Event& event; |
Kamalkumar Patel | 3c50c82 | 2024-01-30 07:14:40 -0600 | [diff] [blame] | 508 | fs::path pdrJsonDir; |
Deepak Kodihalli | b5c227e | 2020-07-13 06:58:34 -0500 | [diff] [blame] | 509 | bool pdrCreated; |
Kamalkumar Patel | 3c50c82 | 2024-01-30 07:14:40 -0600 | [diff] [blame] | 510 | std::vector<fs::path> pdrJsonsDir; |
Sampa Misra | 5fb37d5 | 2021-03-06 07:26:00 -0600 | [diff] [blame] | 511 | std::unique_ptr<sdeventplus::source::Defer> deferredGetPDREvent; |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 512 | }; |
| 513 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 514 | /** @brief Function to check if a sensor falls in OEM range |
| 515 | * A sensor is considered to be oem if either of entity |
| 516 | * type or state set or both falls in oem range |
| 517 | * |
| 518 | * @param[in] handler - the interface object |
| 519 | * @param[in] sensorId - sensor id |
| 520 | * @param[in] sensorRearmCount - sensor rearm count |
| 521 | * @param[out] compSensorCnt - composite sensor count |
| 522 | * @param[out] entityType - entity type |
| 523 | * @param[out] entityInstance - entity instance number |
| 524 | * @param[out] stateSetId - state set id |
| 525 | * |
| 526 | * @return true if the sensor is OEM. All out parameters are invalid |
| 527 | * for a non OEM sensor |
| 528 | */ |
| 529 | bool isOemStateSensor(Handler& handler, uint16_t sensorId, |
| 530 | uint8_t sensorRearmCount, uint8_t& compSensorCnt, |
| 531 | uint16_t& entityType, uint16_t& entityInstance, |
| 532 | uint16_t& stateSetId); |
| 533 | |
| 534 | /** @brief Function to check if an effecter falls in OEM range |
| 535 | * An effecter is considered to be oem if either of entity |
| 536 | * type or state set or both falls in oem range |
| 537 | * |
| 538 | * @param[in] handler - the interface object |
| 539 | * @param[in] effecterId - effecter id |
| 540 | * @param[in] compEffecterCnt - composite effecter count |
| 541 | * @param[out] entityType - entity type |
| 542 | * @param[out] entityInstance - entity instance number |
| 543 | * @param[out] stateSetId - state set id |
| 544 | * |
| 545 | * @return true if the effecter is OEM. All out parameters are invalid |
| 546 | * for a non OEM effecter |
| 547 | */ |
| 548 | bool isOemStateEffecter(Handler& handler, uint16_t effecterId, |
| 549 | uint8_t compEffecterCnt, uint16_t& entityType, |
| 550 | uint16_t& entityInstance, uint16_t& stateSetId); |
| 551 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 552 | } // namespace platform |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 553 | } // namespace responder |
| 554 | } // namespace pldm |