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