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" |
Deepak Kodihalli | 1521f6d | 2020-06-16 08:51:02 -0500 | [diff] [blame] | 16 | #include "pldmd/handler.hpp" |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 17 | |
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 | |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 29 | using namespace pldm::utils; |
| 30 | using namespace pldm::responder::pdr_utils; |
George Liu | cae1866 | 2020-05-15 09:32:57 +0800 | [diff] [blame] | 31 | using namespace pldm::state_sensor; |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 32 | |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 33 | using generatePDR = |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 34 | std::function<void(const pldm::utils::DBusHandler& dBusIntf, |
| 35 | const Json& json, pdr_utils::RepoInterface& repo)>; |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 36 | |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 37 | using EffecterId = uint16_t; |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 38 | using DbusObjMaps = |
| 39 | std::map<EffecterId, |
| 40 | std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>>; |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 41 | using DbusPath = std::string; |
| 42 | using EffecterObjs = std::vector<DbusPath>; |
| 43 | using EventType = uint8_t; |
| 44 | using EventHandler = std::function<int( |
| 45 | const pldm_msg* request, size_t payloadLength, uint8_t formatVersion, |
| 46 | uint8_t tid, size_t eventDataOffset)>; |
| 47 | using EventHandlers = std::vector<EventHandler>; |
| 48 | using EventMap = std::map<EventType, EventHandlers>; |
George Liu | c4ea6a9 | 2020-07-14 15:48:44 +0800 | [diff] [blame] | 49 | using AssociatedEntityMap = std::map<DbusPath, pldm_entity>; |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 50 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 51 | class Handler : public CmdHandler |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 52 | { |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 53 | public: |
Deepak Kodihalli | b5c227e | 2020-07-13 06:58:34 -0500 | [diff] [blame] | 54 | Handler(const pldm::utils::DBusHandler* dBusIntf, |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 55 | const std::string& pdrJsonsDir, const std::string& eventsJsonsDir, |
TOM JOSEPH | d4d97a5 | 2020-03-23 14:36:34 +0530 | [diff] [blame] | 56 | pldm_pdr* repo, HostPDRHandler* hostPDRHandler, |
George Liu | cae1866 | 2020-05-15 09:32:57 +0800 | [diff] [blame] | 57 | DbusToPLDMEvent* dbusToPLDMEventHandler, fru::Handler* fruHandler, |
| 58 | bool buildPDRLazily = false, |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 59 | const std::optional<EventMap>& addOnHandlersMap = std::nullopt) : |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 60 | pdrRepo(repo), |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 61 | hostPDRHandler(hostPDRHandler), stateSensorHandler(eventsJsonsDir), |
George Liu | cae1866 | 2020-05-15 09:32:57 +0800 | [diff] [blame] | 62 | dbusToPLDMEventHandler(dbusToPLDMEventHandler), fruHandler(fruHandler), |
| 63 | dBusIntf(dBusIntf), 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, |
| 152 | TypeId typeId = 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>& |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 164 | getDbusObjMaps(uint16_t id, |
| 165 | TypeId typeId = TypeId::PLDM_EFFECTER_ID) const; |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 166 | |
| 167 | uint16_t getNextEffecterId() |
| 168 | { |
| 169 | return ++nextEffecterId; |
| 170 | } |
| 171 | |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 172 | uint16_t getNextSensorId() |
| 173 | { |
| 174 | return ++nextSensorId; |
| 175 | } |
| 176 | |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 177 | /** @brief Parse PDR JSONs and build PDR repository |
| 178 | * |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 179 | * @param[in] dBusIntf - The interface object |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 180 | * @param[in] dir - directory housing platform specific PDR JSON files |
| 181 | * @param[in] repo - instance of concrete implementation of Repo |
| 182 | */ |
George Liu | 36e8135 | 2020-07-01 14:40:30 +0800 | [diff] [blame] | 183 | void generate(const pldm::utils::DBusHandler& dBusIntf, |
| 184 | const std::string& dir, Repo& repo); |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 185 | |
| 186 | /** @brief Parse PDR JSONs and build state effecter PDR repository |
| 187 | * |
| 188 | * @param[in] json - platform specific PDR JSON files |
| 189 | * @param[in] repo - instance of state effecter implementation of Repo |
| 190 | */ |
| 191 | void generateStateEffecterRepo(const Json& json, Repo& repo); |
| 192 | |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 193 | /** @brief map of PLDM event type to EventHandlers |
| 194 | * |
| 195 | */ |
| 196 | EventMap eventHandlers; |
| 197 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 198 | /** @brief Handler for GetPDR |
| 199 | * |
| 200 | * @param[in] request - Request message payload |
| 201 | * @param[in] payloadLength - Request payload length |
| 202 | * @param[out] Response - Response message written here |
| 203 | */ |
| 204 | Response getPDR(const pldm_msg* request, size_t payloadLength); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 205 | |
George Liu | eccb0c5 | 2020-01-14 11:09:56 +0800 | [diff] [blame] | 206 | /** @brief Handler for setNumericEffecterValue |
| 207 | * |
| 208 | * @param[in] request - Request message |
| 209 | * @param[in] payloadLength - Request payload length |
| 210 | * @return Response - PLDM Response message |
| 211 | */ |
| 212 | Response setNumericEffecterValue(const pldm_msg* request, |
| 213 | size_t payloadLength); |
| 214 | |
George Liu | 362c18d | 2020-05-14 09:46:36 +0800 | [diff] [blame] | 215 | /** @brief Handler for getStateSensorReadings |
| 216 | * |
| 217 | * @param[in] request - Request message |
| 218 | * @param[in] payloadLength - Request payload length |
| 219 | * @return Response - PLDM Response message |
| 220 | */ |
| 221 | Response getStateSensorReadings(const pldm_msg* request, |
| 222 | size_t payloadLength); |
| 223 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 224 | /** @brief Handler for setStateEffecterStates |
| 225 | * |
| 226 | * @param[in] request - Request message |
| 227 | * @param[in] payloadLength - Request payload length |
| 228 | * @return Response - PLDM Response message |
| 229 | */ |
| 230 | Response setStateEffecterStates(const pldm_msg* request, |
| 231 | size_t payloadLength); |
| 232 | |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 233 | /** @brief Handler for PlatformEventMessage |
| 234 | * |
| 235 | * @param[in] request - Request message |
| 236 | * @param[in] payloadLength - Request payload length |
| 237 | * @return Response - PLDM Response message |
| 238 | */ |
| 239 | Response platformEventMessage(const pldm_msg* request, |
| 240 | size_t payloadLength); |
| 241 | |
| 242 | /** @brief Handler for event class Sensor event |
| 243 | * |
| 244 | * @param[in] request - Request message |
| 245 | * @param[in] payloadLength - Request payload length |
| 246 | * @param[in] formatVersion - Version of the event format |
| 247 | * @param[in] tid - Terminus ID of the event's originator |
| 248 | * @param[in] eventDataOffset - Offset of the event data in the request |
| 249 | * message |
| 250 | * @return PLDM completion code |
| 251 | */ |
| 252 | int sensorEvent(const pldm_msg* request, size_t payloadLength, |
| 253 | uint8_t formatVersion, uint8_t tid, size_t eventDataOffset); |
| 254 | |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 255 | /** @brief Handler for pldmPDRRepositoryChgEvent |
| 256 | * |
| 257 | * @param[in] request - Request message |
| 258 | * @param[in] payloadLength - Request payload length |
| 259 | * @param[in] formatVersion - Version of the event format |
| 260 | * @param[in] tid - Terminus ID of the event's originator |
| 261 | * @param[in] eventDataOffset - Offset of the event data in the request |
| 262 | * message |
| 263 | * @return PLDM completion code |
| 264 | */ |
| 265 | int pldmPDRRepositoryChgEvent(const pldm_msg* request, size_t payloadLength, |
| 266 | uint8_t formatVersion, uint8_t tid, |
| 267 | size_t eventDataOffset); |
| 268 | |
| 269 | /** @brief Handler for extracting the PDR handles from changeEntries |
| 270 | * |
| 271 | * @param[in] changeEntryData - ChangeEntry data from changeRecord |
| 272 | * @param[in] changeEntryDataSize - total size of changeEntryData |
| 273 | * @param[in] numberOfChangeEntries - total number of changeEntries to |
| 274 | * extract |
| 275 | * @param[out] pdrRecordHandles - std::vector where the extracted PDR |
| 276 | * handles are placed |
| 277 | * @return PLDM completion code |
| 278 | */ |
| 279 | int getPDRRecordHandles(const ChangeEntry* changeEntryData, |
| 280 | size_t changeEntryDataSize, |
| 281 | size_t numberOfChangeEntries, |
| 282 | PDRRecordHandles& pdrRecordHandles); |
| 283 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 284 | /** @brief Function to set the effecter requested by pldm requester |
| 285 | * @param[in] dBusIntf - The interface object |
| 286 | * @param[in] effecterId - Effecter ID sent by the requester to act on |
| 287 | * @param[in] stateField - The state field data for each of the states, |
| 288 | * equal to composite effecter count in number |
| 289 | * @return - Success or failure in setting the states. Returns failure in |
| 290 | * terms of PLDM completion codes if atleast one state fails to be set |
| 291 | */ |
| 292 | template <class DBusInterface> |
| 293 | int setStateEffecterStatesHandler( |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 294 | const DBusInterface& dBusIntf, uint16_t effecterId, |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 295 | const std::vector<set_effecter_state_field>& stateField) |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 296 | { |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 297 | using namespace pldm::responder::pdr; |
George Liu | 1e44c73 | 2020-02-28 20:20:06 +0800 | [diff] [blame] | 298 | using namespace pldm::utils; |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 299 | using StateSetNum = uint8_t; |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 300 | |
| 301 | state_effecter_possible_states* states = nullptr; |
| 302 | pldm_state_effecter_pdr* pdr = nullptr; |
| 303 | uint8_t compEffecterCnt = stateField.size(); |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 304 | |
| 305 | std::unique_ptr<pldm_pdr, decltype(&pldm_pdr_destroy)> |
| 306 | stateEffecterPdrRepo(pldm_pdr_init(), pldm_pdr_destroy); |
| 307 | Repo stateEffecterPDRs(stateEffecterPdrRepo.get()); |
| 308 | getRepoByType(pdrRepo, stateEffecterPDRs, PLDM_STATE_EFFECTER_PDR); |
| 309 | if (stateEffecterPDRs.empty()) |
| 310 | { |
| 311 | std::cerr << "Failed to get record by PDR type\n"; |
| 312 | return PLDM_PLATFORM_INVALID_EFFECTER_ID; |
| 313 | } |
| 314 | |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 315 | PdrEntry pdrEntry{}; |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 316 | auto pdrRecord = stateEffecterPDRs.getFirstRecord(pdrEntry); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 317 | while (pdrRecord) |
| 318 | { |
| 319 | pdr = reinterpret_cast<pldm_state_effecter_pdr*>(pdrEntry.data); |
| 320 | if (pdr->effecter_id != effecterId) |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 321 | { |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 322 | pdr = nullptr; |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 323 | pdrRecord = |
| 324 | stateEffecterPDRs.getNextRecord(pdrRecord, pdrEntry); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 325 | continue; |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 326 | } |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 327 | |
| 328 | states = reinterpret_cast<state_effecter_possible_states*>( |
| 329 | pdr->possible_states); |
| 330 | if (compEffecterCnt > pdr->composite_effecter_count) |
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 | std::cerr << "The requester sent wrong composite effecter" |
| 333 | << " count for the effecter, EFFECTER_ID=" |
| 334 | << effecterId << "COMP_EFF_CNT=" << compEffecterCnt |
| 335 | << "\n"; |
| 336 | return PLDM_ERROR_INVALID_DATA; |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 337 | } |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 338 | break; |
| 339 | } |
| 340 | |
| 341 | if (!pdr) |
| 342 | { |
| 343 | return PLDM_PLATFORM_INVALID_EFFECTER_ID; |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 344 | } |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 345 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 346 | int rc = PLDM_SUCCESS; |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 347 | try |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 348 | { |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 349 | const auto& [dbusMappings, dbusValMaps] = |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 350 | effecterDbusObjMaps.at(effecterId); |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 351 | for (uint8_t currState = 0; currState < compEffecterCnt; |
| 352 | ++currState) |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 353 | { |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 354 | std::vector<StateSetNum> allowed{}; |
| 355 | // computation is based on table 79 from DSP0248 v1.1.1 |
| 356 | uint8_t bitfieldIndex = |
| 357 | stateField[currState].effecter_state / 8; |
| 358 | uint8_t bit = |
| 359 | stateField[currState].effecter_state - (8 * bitfieldIndex); |
| 360 | if (states->possible_states_size < bitfieldIndex || |
| 361 | !(states->states[bitfieldIndex].byte & (1 << bit))) |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 362 | { |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 363 | std::cerr |
| 364 | << "Invalid state set value, EFFECTER_ID=" << effecterId |
| 365 | << " VALUE=" << stateField[currState].effecter_state |
| 366 | << " COMPOSITE_EFFECTER_ID=" << currState |
| 367 | << " DBUS_PATH=" << dbusMappings[currState].objectPath |
| 368 | << "\n"; |
| 369 | rc = PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE; |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 370 | break; |
| 371 | } |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 372 | const DBusMapping& dbusMapping = dbusMappings[currState]; |
| 373 | const StatestoDbusVal& dbusValToMap = dbusValMaps[currState]; |
| 374 | |
| 375 | if (stateField[currState].set_request == PLDM_REQUEST_SET) |
| 376 | { |
| 377 | try |
| 378 | { |
| 379 | dBusIntf.setDbusProperty( |
| 380 | dbusMapping, |
| 381 | dbusValToMap.at( |
| 382 | stateField[currState].effecter_state)); |
| 383 | } |
| 384 | catch (const std::exception& e) |
| 385 | { |
| 386 | std::cerr |
| 387 | << "Error setting property, ERROR=" << e.what() |
| 388 | << " PROPERTY=" << dbusMapping.propertyName |
| 389 | << " INTERFACE=" |
| 390 | << dbusMapping.interface << " PATH=" |
| 391 | << dbusMapping.objectPath << "\n"; |
| 392 | return PLDM_ERROR; |
| 393 | } |
| 394 | } |
| 395 | uint8_t* nextState = |
| 396 | reinterpret_cast<uint8_t*>(states) + |
| 397 | sizeof(state_effecter_possible_states) - |
| 398 | sizeof(states->states) + |
| 399 | (states->possible_states_size * sizeof(states->states)); |
| 400 | states = reinterpret_cast<state_effecter_possible_states*>( |
| 401 | nextState); |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 402 | } |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 403 | } |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 404 | catch (const std::out_of_range& e) |
| 405 | { |
| 406 | std::cerr << "the effecterId does not exist. effecter id: " |
| 407 | << effecterId << e.what() << '\n'; |
| 408 | } |
| 409 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 410 | return rc; |
| 411 | } |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 412 | |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 413 | /** @brief Build BMC Terminus Locator PDR |
| 414 | * |
| 415 | * @param[in] repo - instance of concrete implementation of Repo |
| 416 | */ |
| 417 | void generateTerminusLocatorPDR(Repo& repo); |
| 418 | |
George Liu | c4ea6a9 | 2020-07-14 15:48:44 +0800 | [diff] [blame] | 419 | /** @brief Get std::map associated with the entity |
| 420 | * key: object path |
| 421 | * value: pldm_entity |
| 422 | * |
| 423 | * @return std::map<ObjectPath, pldm_entity> |
| 424 | */ |
| 425 | inline const AssociatedEntityMap& getAssociateEntityMap() const |
| 426 | { |
| 427 | if (fruHandler == nullptr) |
| 428 | { |
| 429 | throw InternalFailure(); |
| 430 | } |
| 431 | return fruHandler->getAssociateEntityMap(); |
| 432 | } |
| 433 | |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 434 | private: |
| 435 | pdr_utils::Repo pdrRepo; |
| 436 | uint16_t nextEffecterId{}; |
George Liu | adbe172 | 2020-05-09 19:20:19 +0800 | [diff] [blame] | 437 | uint16_t nextSensorId{}; |
| 438 | DbusObjMaps effecterDbusObjMaps{}; |
| 439 | DbusObjMaps sensorDbusObjMaps{}; |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 440 | HostPDRHandler* hostPDRHandler; |
TOM JOSEPH | d4d97a5 | 2020-03-23 14:36:34 +0530 | [diff] [blame] | 441 | events::StateSensorHandler stateSensorHandler; |
George Liu | cae1866 | 2020-05-15 09:32:57 +0800 | [diff] [blame] | 442 | DbusToPLDMEvent* dbusToPLDMEventHandler; |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 443 | fru::Handler* fruHandler; |
Deepak Kodihalli | b5c227e | 2020-07-13 06:58:34 -0500 | [diff] [blame] | 444 | const pldm::utils::DBusHandler* dBusIntf; |
| 445 | std::string pdrJsonsDir; |
| 446 | bool pdrCreated; |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 447 | }; |
| 448 | |
| 449 | } // namespace platform |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 450 | } // namespace responder |
| 451 | } // namespace pldm |