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" |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 10 | #include "oem_handler.hpp" |
Deepak Kodihalli | 1521f6d | 2020-06-16 08:51:02 -0500 | [diff] [blame] | 11 | #include "pldmd/handler.hpp" |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 12 | |
George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 13 | #include <libpldm/pdr.h> |
| 14 | #include <libpldm/platform.h> |
| 15 | #include <libpldm/states.h> |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 16 | #include <stdint.h> |
| 17 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 18 | #include <phosphor-logging/lg2.hpp> |
| 19 | |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 20 | #include <map> |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 21 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 22 | PHOSPHOR_LOG2_USING; |
| 23 | |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 24 | namespace pldm |
| 25 | { |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 26 | namespace responder |
| 27 | { |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 28 | namespace platform |
| 29 | { |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 30 | using generatePDR = std::function<void(const pldm::utils::DBusHandler& dBusIntf, |
| 31 | const pldm::utils::Json& json, |
| 32 | pdr_utils::RepoInterface& repo)>; |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 33 | |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 34 | using EffecterId = uint16_t; |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 35 | using DbusObjMaps = |
| 36 | std::map<EffecterId, |
| 37 | std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>>; |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 38 | using DbusPath = std::string; |
| 39 | using EffecterObjs = std::vector<DbusPath>; |
| 40 | using EventType = uint8_t; |
| 41 | using EventHandler = std::function<int( |
| 42 | const pldm_msg* request, size_t payloadLength, uint8_t formatVersion, |
| 43 | uint8_t tid, size_t eventDataOffset)>; |
| 44 | using EventHandlers = std::vector<EventHandler>; |
| 45 | using EventMap = std::map<EventType, EventHandlers>; |
George Liu | c4ea6a9 | 2020-07-14 15:48:44 +0800 | [diff] [blame] | 46 | using AssociatedEntityMap = std::map<DbusPath, pldm_entity>; |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 47 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 48 | class Handler : public CmdHandler |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 49 | { |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 50 | public: |
Deepak Kodihalli | b5c227e | 2020-07-13 06:58:34 -0500 | [diff] [blame] | 51 | Handler(const pldm::utils::DBusHandler* dBusIntf, |
Pavithra Barithaya | 3aec997 | 2020-12-14 01:55:44 -0600 | [diff] [blame] | 52 | const std::string& pdrJsonsDir, pldm_pdr* repo, |
| 53 | HostPDRHandler* hostPDRHandler, |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 54 | pldm::state_sensor::DbusToPLDMEvent* dbusToPLDMEventHandler, |
| 55 | fru::Handler* fruHandler, |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 56 | pldm::responder::oem_platform::Handler* oemPlatformHandler, |
Sampa Misra | 5fb37d5 | 2021-03-06 07:26:00 -0600 | [diff] [blame] | 57 | sdeventplus::Event& event, bool buildPDRLazily = false, |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 58 | const std::optional<EventMap>& addOnHandlersMap = std::nullopt) : |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 59 | pdrRepo(repo), |
Pavithra Barithaya | 3aec997 | 2020-12-14 01:55:44 -0600 | [diff] [blame] | 60 | hostPDRHandler(hostPDRHandler), |
George Liu | cae1866 | 2020-05-15 09:32:57 +0800 | [diff] [blame] | 61 | dbusToPLDMEventHandler(dbusToPLDMEventHandler), fruHandler(fruHandler), |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 62 | dBusIntf(dBusIntf), oemPlatformHandler(oemPlatformHandler), |
Sampa Misra | 5fb37d5 | 2021-03-06 07:26:00 -0600 | [diff] [blame] | 63 | event(event), pdrJsonsDir(pdrJsonsDir), pdrCreated(false) |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 64 | { |
Deepak Kodihalli | b5c227e | 2020-07-13 06:58:34 -0500 | [diff] [blame] | 65 | if (!buildPDRLazily) |
| 66 | { |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 67 | generateTerminusLocatorPDR(pdrRepo); |
Deepak Kodihalli | b5c227e | 2020-07-13 06:58:34 -0500 | [diff] [blame] | 68 | generate(*dBusIntf, pdrJsonsDir, pdrRepo); |
| 69 | pdrCreated = true; |
| 70 | } |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 71 | |
Delphine CC Chiu | d2e4899 | 2023-12-05 16:29:51 +0800 | [diff] [blame^] | 72 | handlers.emplace( |
| 73 | PLDM_GET_PDR, |
| 74 | [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 75 | return this->getPDR(request, payloadLength); |
| 76 | }); |
Delphine CC Chiu | d2e4899 | 2023-12-05 16:29:51 +0800 | [diff] [blame^] | 77 | handlers.emplace( |
| 78 | PLDM_SET_NUMERIC_EFFECTER_VALUE, |
| 79 | [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 80 | return this->setNumericEffecterValue(request, payloadLength); |
| 81 | }); |
Delphine CC Chiu | d2e4899 | 2023-12-05 16:29:51 +0800 | [diff] [blame^] | 82 | handlers.emplace( |
| 83 | PLDM_GET_NUMERIC_EFFECTER_VALUE, |
| 84 | [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) { |
Archana Kakani | 6ece21fb | 2023-10-10 08:21:52 -0500 | [diff] [blame] | 85 | return this->getNumericEffecterValue(request, payloadLength); |
| 86 | }); |
Delphine CC Chiu | d2e4899 | 2023-12-05 16:29:51 +0800 | [diff] [blame^] | 87 | handlers.emplace( |
| 88 | PLDM_SET_STATE_EFFECTER_STATES, |
| 89 | [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 90 | return this->setStateEffecterStates(request, payloadLength); |
| 91 | }); |
Delphine CC Chiu | d2e4899 | 2023-12-05 16:29:51 +0800 | [diff] [blame^] | 92 | handlers.emplace( |
| 93 | PLDM_PLATFORM_EVENT_MESSAGE, |
| 94 | [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 95 | return this->platformEventMessage(request, payloadLength); |
| 96 | }); |
Delphine CC Chiu | d2e4899 | 2023-12-05 16:29:51 +0800 | [diff] [blame^] | 97 | handlers.emplace( |
| 98 | PLDM_GET_STATE_SENSOR_READINGS, |
| 99 | [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 100 | return this->getStateSensorReadings(request, payloadLength); |
| 101 | }); |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 102 | |
| 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 Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 107 | return this->sensorEvent(request, payloadLength, formatVersion, tid, |
| 108 | eventDataOffset); |
| 109 | }); |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 110 | 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 Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 113 | return this->pldmPDRRepositoryChgEvent( |
| 114 | request, payloadLength, formatVersion, tid, eventDataOffset); |
| 115 | }); |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 116 | |
| 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 Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 138 | } |
| 139 | |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 140 | pdr_utils::Repo& getRepo() |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 141 | { |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 142 | return this->pdrRepo; |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 143 | } |
| 144 | |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 145 | /** @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] | 146 | * Id. If the same id is added, the previous dbusObjs will |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 147 | * be "over-written". |
| 148 | * |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 149 | * @param[in] Id - effecter/sensor id |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 150 | * @param[in] dbusObj - list of D-Bus object structure and list of D-Bus |
| 151 | * property value to attribute value |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 152 | * @param[in] typeId - the type id of enum |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 153 | */ |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 154 | void addDbusObjMaps( |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 155 | uint16_t id, |
| 156 | std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> dbusObj, |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 157 | pldm::responder::pdr_utils::TypeId typeId = |
| 158 | pldm::responder::pdr_utils::TypeId::PLDM_EFFECTER_ID); |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 159 | |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 160 | /** @brief Retrieve an id -> D-Bus objects mapping |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 161 | * |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 162 | * @param[in] Id - id |
| 163 | * @param[in] typeId - the type id of enum |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 164 | * |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 165 | * @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 Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 168 | */ |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 169 | const std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>& |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 170 | getDbusObjMaps( |
| 171 | uint16_t id, |
| 172 | pldm::responder::pdr_utils::TypeId typeId = |
| 173 | pldm::responder::pdr_utils::TypeId::PLDM_EFFECTER_ID) const; |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 174 | |
| 175 | uint16_t getNextEffecterId() |
| 176 | { |
| 177 | return ++nextEffecterId; |
| 178 | } |
| 179 | |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 180 | uint16_t getNextSensorId() |
| 181 | { |
| 182 | return ++nextSensorId; |
| 183 | } |
| 184 | |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 185 | /** @brief Parse PDR JSONs and build PDR repository |
| 186 | * |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 187 | * @param[in] dBusIntf - The interface object |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 188 | * @param[in] dir - directory housing platform specific PDR JSON files |
| 189 | * @param[in] repo - instance of concrete implementation of Repo |
| 190 | */ |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 191 | void generate(const pldm::utils::DBusHandler& dBusIntf, |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 192 | const std::string& dir, |
| 193 | pldm::responder::pdr_utils::Repo& repo); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 194 | |
| 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 Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 200 | void generateStateEffecterRepo(const pldm::utils::Json& json, |
| 201 | pldm::responder::pdr_utils::Repo& repo); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 202 | |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 203 | /** @brief map of PLDM event type to EventHandlers |
| 204 | * |
| 205 | */ |
| 206 | EventMap eventHandlers; |
| 207 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 208 | /** @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 Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 215 | |
George Liu | eccb0c5 | 2020-01-14 11:09:56 +0800 | [diff] [blame] | 216 | /** @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 Kakani | 6ece21fb | 2023-10-10 08:21:52 -0500 | [diff] [blame] | 225 | /** @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 Liu | 362c18d | 2020-05-14 09:46:36 +0800 | [diff] [blame] | 234 | /** @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 Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 243 | /** @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 Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 252 | /** @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 Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 274 | /** @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 Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 303 | /** @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 Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 313 | const DBusInterface& dBusIntf, uint16_t effecterId, |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 314 | const std::vector<set_effecter_state_field>& stateField) |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 315 | { |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 316 | using namespace pldm::responder::pdr; |
George Liu | 1e44c73 | 2020-02-28 20:20:06 +0800 | [diff] [blame] | 317 | using namespace pldm::utils; |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 318 | using StateSetNum = uint8_t; |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 319 | |
| 320 | state_effecter_possible_states* states = nullptr; |
| 321 | pldm_state_effecter_pdr* pdr = nullptr; |
| 322 | uint8_t compEffecterCnt = stateField.size(); |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 323 | |
| 324 | std::unique_ptr<pldm_pdr, decltype(&pldm_pdr_destroy)> |
| 325 | stateEffecterPdrRepo(pldm_pdr_init(), pldm_pdr_destroy); |
Andrew Jeffery | acb2029 | 2023-06-30 11:47:44 +0930 | [diff] [blame] | 326 | if (!stateEffecterPdrRepo) |
| 327 | { |
| 328 | throw std::runtime_error( |
| 329 | "Failed to instantiate state effecter PDR repository"); |
| 330 | } |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 331 | pldm::responder::pdr_utils::Repo stateEffecterPDRs( |
| 332 | stateEffecterPdrRepo.get()); |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 333 | getRepoByType(pdrRepo, stateEffecterPDRs, PLDM_STATE_EFFECTER_PDR); |
| 334 | if (stateEffecterPDRs.empty()) |
| 335 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 336 | error("Failed to get record by PDR type"); |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 337 | return PLDM_PLATFORM_INVALID_EFFECTER_ID; |
| 338 | } |
| 339 | |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 340 | pldm::responder::pdr_utils::PdrEntry pdrEntry{}; |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 341 | auto pdrRecord = stateEffecterPDRs.getFirstRecord(pdrEntry); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 342 | while (pdrRecord) |
| 343 | { |
| 344 | pdr = reinterpret_cast<pldm_state_effecter_pdr*>(pdrEntry.data); |
| 345 | if (pdr->effecter_id != effecterId) |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 346 | { |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 347 | pdr = nullptr; |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 348 | pdrRecord = stateEffecterPDRs.getNextRecord(pdrRecord, |
| 349 | pdrEntry); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 350 | continue; |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 351 | } |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 352 | |
| 353 | states = reinterpret_cast<state_effecter_possible_states*>( |
| 354 | pdr->possible_states); |
| 355 | if (compEffecterCnt > pdr->composite_effecter_count) |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 356 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 357 | 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 Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 361 | return PLDM_ERROR_INVALID_DATA; |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 362 | } |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 363 | break; |
| 364 | } |
| 365 | |
| 366 | if (!pdr) |
| 367 | { |
| 368 | return PLDM_PLATFORM_INVALID_EFFECTER_ID; |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 369 | } |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 370 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 371 | int rc = PLDM_SUCCESS; |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 372 | try |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 373 | { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 374 | const auto& [dbusMappings, |
| 375 | dbusValMaps] = effecterDbusObjMaps.at(effecterId); |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 376 | for (uint8_t currState = 0; currState < compEffecterCnt; |
| 377 | ++currState) |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 378 | { |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 379 | std::vector<StateSetNum> allowed{}; |
| 380 | // computation is based on table 79 from DSP0248 v1.1.1 |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 381 | uint8_t bitfieldIndex = stateField[currState].effecter_state / |
| 382 | 8; |
| 383 | uint8_t bit = stateField[currState].effecter_state - |
| 384 | (8 * bitfieldIndex); |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 385 | if (states->possible_states_size < bitfieldIndex || |
| 386 | !(states->states[bitfieldIndex].byte & (1 << bit))) |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 387 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 388 | 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 Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 394 | rc = PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE; |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 395 | break; |
| 396 | } |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 397 | const DBusMapping& dbusMapping = dbusMappings[currState]; |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 398 | const pldm::responder::pdr_utils::StatestoDbusVal& |
| 399 | dbusValToMap = dbusValMaps[currState]; |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 400 | |
| 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 Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 412 | 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 Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 418 | 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 Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 428 | } |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 429 | } |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 430 | catch (const std::out_of_range& e) |
| 431 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 432 | error( |
| 433 | "the effecterId does not exist. effecter id: {EFFECTER_ID} {ERR_EXCEP}", |
| 434 | "EFFECTER_ID", (unsigned)effecterId, "ERR_EXCEP", e.what()); |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 435 | } |
| 436 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 437 | return rc; |
| 438 | } |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 439 | |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 440 | /** @brief Build BMC Terminus Locator PDR |
| 441 | * |
| 442 | * @param[in] repo - instance of concrete implementation of Repo |
| 443 | */ |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 444 | void generateTerminusLocatorPDR(pldm::responder::pdr_utils::Repo& repo); |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 445 | |
George Liu | c4ea6a9 | 2020-07-14 15:48:44 +0800 | [diff] [blame] | 446 | /** @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 Misra | 5fb37d5 | 2021-03-06 07:26:00 -0600 | [diff] [blame] | 461 | /** @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 Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 467 | private: |
| 468 | pdr_utils::Repo pdrRepo; |
| 469 | uint16_t nextEffecterId{}; |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 470 | uint16_t nextSensorId{}; |
| 471 | DbusObjMaps effecterDbusObjMaps{}; |
| 472 | DbusObjMaps sensorDbusObjMaps{}; |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 473 | HostPDRHandler* hostPDRHandler; |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 474 | pldm::state_sensor::DbusToPLDMEvent* dbusToPLDMEventHandler; |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 475 | fru::Handler* fruHandler; |
Deepak Kodihalli | b5c227e | 2020-07-13 06:58:34 -0500 | [diff] [blame] | 476 | const pldm::utils::DBusHandler* dBusIntf; |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 477 | pldm::responder::oem_platform::Handler* oemPlatformHandler; |
Sampa Misra | 5fb37d5 | 2021-03-06 07:26:00 -0600 | [diff] [blame] | 478 | sdeventplus::Event& event; |
Deepak Kodihalli | b5c227e | 2020-07-13 06:58:34 -0500 | [diff] [blame] | 479 | std::string pdrJsonsDir; |
| 480 | bool pdrCreated; |
Sampa Misra | 5fb37d5 | 2021-03-06 07:26:00 -0600 | [diff] [blame] | 481 | std::unique_ptr<sdeventplus::source::Defer> deferredGetPDREvent; |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 482 | }; |
| 483 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 484 | /** @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 | */ |
| 499 | bool 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 | */ |
| 518 | bool isOemStateEffecter(Handler& handler, uint16_t effecterId, |
| 519 | uint8_t compEffecterCnt, uint16_t& entityType, |
| 520 | uint16_t& entityInstance, uint16_t& stateSetId); |
| 521 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 522 | } // namespace platform |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 523 | } // namespace responder |
| 524 | } // namespace pldm |