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