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