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 | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 5 | #include "handler.hpp" |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 6 | #include "host_pdr_handler.hpp" |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 7 | #include "libpldmresponder/pdr.hpp" |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 8 | #include "libpldmresponder/pdr_utils.hpp" |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 9 | #include "utils.hpp" |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 10 | |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 11 | #include <stdint.h> |
| 12 | |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 13 | #include <map> |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 14 | |
| 15 | #include "libpldm/platform.h" |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 16 | #include "libpldm/states.h" |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 17 | |
| 18 | namespace pldm |
| 19 | { |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 20 | namespace responder |
| 21 | { |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 22 | namespace platform |
| 23 | { |
| 24 | |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 25 | using namespace pldm::utils; |
| 26 | using namespace pldm::responder::pdr_utils; |
| 27 | |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 28 | using generatePDR = |
| 29 | std::function<void(const Json& json, pdr_utils::RepoInterface& repo)>; |
| 30 | |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 31 | using EffecterId = uint16_t; |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 32 | using DbusObjMaps = |
| 33 | std::map<EffecterId, |
| 34 | std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>>; |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 35 | using DbusPath = std::string; |
| 36 | using EffecterObjs = std::vector<DbusPath>; |
| 37 | using EventType = uint8_t; |
| 38 | using EventHandler = std::function<int( |
| 39 | const pldm_msg* request, size_t payloadLength, uint8_t formatVersion, |
| 40 | uint8_t tid, size_t eventDataOffset)>; |
| 41 | using EventHandlers = std::vector<EventHandler>; |
| 42 | using EventMap = std::map<EventType, EventHandlers>; |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 43 | |
Zahed Hossain | 75330f3 | 2020-03-24 02:15:03 -0500 | [diff] [blame] | 44 | // EventEntry = <uint8_t> - EventState <uint8_t> - SensorOffset <uint16_t> - |
| 45 | // SensorID |
| 46 | using EventEntry = uint32_t; |
| 47 | struct DBusInfo |
| 48 | { |
| 49 | pldm::utils::DBusMapping dBusValues; |
| 50 | pldm::utils::PropertyValue dBusPropertyValue; |
| 51 | }; |
| 52 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 53 | class Handler : public CmdHandler |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 54 | { |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 55 | public: |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 56 | Handler(const std::string& dir, pldm_pdr* repo, |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 57 | HostPDRHandler* hostPDRHandler, |
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), |
| 60 | hostPDRHandler(hostPDRHandler) |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 61 | { |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 62 | generate(dir, pdrRepo); |
| 63 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 64 | handlers.emplace(PLDM_GET_PDR, |
| 65 | [this](const pldm_msg* request, size_t payloadLength) { |
| 66 | return this->getPDR(request, payloadLength); |
| 67 | }); |
George Liu | eccb0c5 | 2020-01-14 11:09:56 +0800 | [diff] [blame] | 68 | handlers.emplace(PLDM_SET_NUMERIC_EFFECTER_VALUE, |
| 69 | [this](const pldm_msg* request, size_t payloadLength) { |
| 70 | return this->setNumericEffecterValue( |
| 71 | request, payloadLength); |
| 72 | }); |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 73 | handlers.emplace(PLDM_SET_STATE_EFFECTER_STATES, |
| 74 | [this](const pldm_msg* request, size_t payloadLength) { |
| 75 | return this->setStateEffecterStates(request, |
| 76 | payloadLength); |
| 77 | }); |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 78 | handlers.emplace(PLDM_PLATFORM_EVENT_MESSAGE, |
| 79 | [this](const pldm_msg* request, size_t payloadLength) { |
| 80 | return this->platformEventMessage(request, |
| 81 | payloadLength); |
| 82 | }); |
| 83 | |
| 84 | // Default handler for PLDM Events |
| 85 | eventHandlers[PLDM_SENSOR_EVENT].emplace_back( |
| 86 | [this](const pldm_msg* request, size_t payloadLength, |
| 87 | uint8_t formatVersion, uint8_t tid, size_t eventDataOffset) { |
| 88 | return this->sensorEvent(request, payloadLength, formatVersion, |
| 89 | tid, eventDataOffset); |
| 90 | }); |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 91 | eventHandlers[PLDM_PDR_REPOSITORY_CHG_EVENT].emplace_back( |
| 92 | [this](const pldm_msg* request, size_t payloadLength, |
| 93 | uint8_t formatVersion, uint8_t tid, size_t eventDataOffset) { |
| 94 | return this->pldmPDRRepositoryChgEvent(request, payloadLength, |
| 95 | formatVersion, tid, |
| 96 | eventDataOffset); |
| 97 | }); |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 98 | |
| 99 | // Additional OEM event handlers for PLDM events, append it to the |
| 100 | // standard handlers |
| 101 | if (addOnHandlersMap) |
| 102 | { |
| 103 | auto addOnHandlers = addOnHandlersMap.value(); |
| 104 | for (EventMap::iterator iter = addOnHandlers.begin(); |
| 105 | iter != addOnHandlers.end(); ++iter) |
| 106 | { |
| 107 | auto search = eventHandlers.find(iter->first); |
| 108 | if (search != eventHandlers.end()) |
| 109 | { |
| 110 | search->second.insert(std::end(search->second), |
| 111 | std::begin(iter->second), |
| 112 | std::end(iter->second)); |
| 113 | } |
| 114 | else |
| 115 | { |
| 116 | eventHandlers.emplace(iter->first, iter->second); |
| 117 | } |
| 118 | } |
| 119 | } |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 120 | } |
| 121 | |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 122 | pdr_utils::Repo& getRepo() |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 123 | { |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 124 | return this->pdrRepo; |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 125 | } |
| 126 | |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 127 | /** @brief Add D-Bus mapping and value mapping(stateId to D-Bus) for the |
| 128 | * effecterId. If the same id is added, the previous dbusObjs will |
| 129 | * be "over-written". |
| 130 | * |
| 131 | * @param[in] effecterId - effecter id |
| 132 | * @param[in] dbusObj - list of D-Bus object structure and list of D-Bus |
| 133 | * property value to attribute value |
| 134 | */ |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 135 | void addDbusObjMaps( |
| 136 | uint16_t effecterId, |
| 137 | std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> dbusObj); |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 138 | |
| 139 | /** @brief Retrieve an effecter id -> D-Bus objects mapping |
| 140 | * |
| 141 | * @param[in] effecterId - effecter id |
| 142 | * |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 143 | * @return std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> - |
| 144 | * list of D-Bus object structure and list of D-Bus property value |
| 145 | * to attribute value |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 146 | */ |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 147 | const std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>& |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 148 | getDbusObjMaps(uint16_t effecterId) const; |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 149 | |
| 150 | uint16_t getNextEffecterId() |
| 151 | { |
| 152 | return ++nextEffecterId; |
| 153 | } |
| 154 | |
| 155 | /** @brief Parse PDR JSONs and build PDR repository |
| 156 | * |
| 157 | * @param[in] dir - directory housing platform specific PDR JSON files |
| 158 | * @param[in] repo - instance of concrete implementation of Repo |
| 159 | */ |
| 160 | void generate(const std::string& dir, Repo& repo); |
| 161 | |
| 162 | /** @brief Parse PDR JSONs and build state effecter PDR repository |
| 163 | * |
| 164 | * @param[in] json - platform specific PDR JSON files |
| 165 | * @param[in] repo - instance of state effecter implementation of Repo |
| 166 | */ |
| 167 | void generateStateEffecterRepo(const Json& json, Repo& repo); |
| 168 | |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 169 | /** @brief map of PLDM event type to EventHandlers |
| 170 | * |
| 171 | */ |
| 172 | EventMap eventHandlers; |
| 173 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 174 | /** @brief Handler for GetPDR |
| 175 | * |
| 176 | * @param[in] request - Request message payload |
| 177 | * @param[in] payloadLength - Request payload length |
| 178 | * @param[out] Response - Response message written here |
| 179 | */ |
| 180 | Response getPDR(const pldm_msg* request, size_t payloadLength); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 181 | |
George Liu | eccb0c5 | 2020-01-14 11:09:56 +0800 | [diff] [blame] | 182 | /** @brief Handler for setNumericEffecterValue |
| 183 | * |
| 184 | * @param[in] request - Request message |
| 185 | * @param[in] payloadLength - Request payload length |
| 186 | * @return Response - PLDM Response message |
| 187 | */ |
| 188 | Response setNumericEffecterValue(const pldm_msg* request, |
| 189 | size_t payloadLength); |
| 190 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 191 | /** @brief Handler for setStateEffecterStates |
| 192 | * |
| 193 | * @param[in] request - Request message |
| 194 | * @param[in] payloadLength - Request payload length |
| 195 | * @return Response - PLDM Response message |
| 196 | */ |
| 197 | Response setStateEffecterStates(const pldm_msg* request, |
| 198 | size_t payloadLength); |
| 199 | |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 200 | /** @brief Handler for PlatformEventMessage |
| 201 | * |
| 202 | * @param[in] request - Request message |
| 203 | * @param[in] payloadLength - Request payload length |
| 204 | * @return Response - PLDM Response message |
| 205 | */ |
| 206 | Response platformEventMessage(const pldm_msg* request, |
| 207 | size_t payloadLength); |
| 208 | |
| 209 | /** @brief Handler for event class Sensor event |
| 210 | * |
| 211 | * @param[in] request - Request message |
| 212 | * @param[in] payloadLength - Request payload length |
| 213 | * @param[in] formatVersion - Version of the event format |
| 214 | * @param[in] tid - Terminus ID of the event's originator |
| 215 | * @param[in] eventDataOffset - Offset of the event data in the request |
| 216 | * message |
| 217 | * @return PLDM completion code |
| 218 | */ |
| 219 | int sensorEvent(const pldm_msg* request, size_t payloadLength, |
| 220 | uint8_t formatVersion, uint8_t tid, size_t eventDataOffset); |
| 221 | |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 222 | /** @brief Handler for pldmPDRRepositoryChgEvent |
| 223 | * |
| 224 | * @param[in] request - Request message |
| 225 | * @param[in] payloadLength - Request payload length |
| 226 | * @param[in] formatVersion - Version of the event format |
| 227 | * @param[in] tid - Terminus ID of the event's originator |
| 228 | * @param[in] eventDataOffset - Offset of the event data in the request |
| 229 | * message |
| 230 | * @return PLDM completion code |
| 231 | */ |
| 232 | int pldmPDRRepositoryChgEvent(const pldm_msg* request, size_t payloadLength, |
| 233 | uint8_t formatVersion, uint8_t tid, |
| 234 | size_t eventDataOffset); |
| 235 | |
| 236 | /** @brief Handler for extracting the PDR handles from changeEntries |
| 237 | * |
| 238 | * @param[in] changeEntryData - ChangeEntry data from changeRecord |
| 239 | * @param[in] changeEntryDataSize - total size of changeEntryData |
| 240 | * @param[in] numberOfChangeEntries - total number of changeEntries to |
| 241 | * extract |
| 242 | * @param[out] pdrRecordHandles - std::vector where the extracted PDR |
| 243 | * handles are placed |
| 244 | * @return PLDM completion code |
| 245 | */ |
| 246 | int getPDRRecordHandles(const ChangeEntry* changeEntryData, |
| 247 | size_t changeEntryDataSize, |
| 248 | size_t numberOfChangeEntries, |
| 249 | PDRRecordHandles& pdrRecordHandles); |
| 250 | |
Zahed Hossain | 75330f3 | 2020-03-24 02:15:03 -0500 | [diff] [blame] | 251 | /** @brief Handler for setting Sensor event data |
| 252 | * |
| 253 | * @param[in] sensorId - sensorID value of the sensor |
| 254 | * @param[in] sensorOffset - Identifies which state sensor within a |
| 255 | * composite state sensor the event is being returned for |
| 256 | * @param[in] eventState - The event state value from the state change that |
| 257 | * triggered the event message |
| 258 | * @return PLDM completion code |
| 259 | */ |
| 260 | int setSensorEventData(uint16_t sensorId, uint8_t sensorOffset, |
| 261 | uint8_t eventState); |
| 262 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 263 | /** @brief Function to set the effecter requested by pldm requester |
| 264 | * @param[in] dBusIntf - The interface object |
| 265 | * @param[in] effecterId - Effecter ID sent by the requester to act on |
| 266 | * @param[in] stateField - The state field data for each of the states, |
| 267 | * equal to composite effecter count in number |
| 268 | * @return - Success or failure in setting the states. Returns failure in |
| 269 | * terms of PLDM completion codes if atleast one state fails to be set |
| 270 | */ |
| 271 | template <class DBusInterface> |
| 272 | int setStateEffecterStatesHandler( |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 273 | const DBusInterface& dBusIntf, uint16_t effecterId, |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 274 | const std::vector<set_effecter_state_field>& stateField) |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 275 | { |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 276 | using namespace pldm::responder::pdr; |
George Liu | 1e44c73 | 2020-02-28 20:20:06 +0800 | [diff] [blame] | 277 | using namespace pldm::utils; |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 278 | using StateSetNum = uint8_t; |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 279 | |
| 280 | state_effecter_possible_states* states = nullptr; |
| 281 | pldm_state_effecter_pdr* pdr = nullptr; |
| 282 | uint8_t compEffecterCnt = stateField.size(); |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 283 | |
| 284 | std::unique_ptr<pldm_pdr, decltype(&pldm_pdr_destroy)> |
| 285 | stateEffecterPdrRepo(pldm_pdr_init(), pldm_pdr_destroy); |
| 286 | Repo stateEffecterPDRs(stateEffecterPdrRepo.get()); |
| 287 | getRepoByType(pdrRepo, stateEffecterPDRs, PLDM_STATE_EFFECTER_PDR); |
| 288 | if (stateEffecterPDRs.empty()) |
| 289 | { |
| 290 | std::cerr << "Failed to get record by PDR type\n"; |
| 291 | return PLDM_PLATFORM_INVALID_EFFECTER_ID; |
| 292 | } |
| 293 | |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 294 | PdrEntry pdrEntry{}; |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 295 | auto pdrRecord = stateEffecterPDRs.getFirstRecord(pdrEntry); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 296 | while (pdrRecord) |
| 297 | { |
| 298 | pdr = reinterpret_cast<pldm_state_effecter_pdr*>(pdrEntry.data); |
| 299 | if (pdr->effecter_id != effecterId) |
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 | pdr = nullptr; |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 302 | pdrRecord = |
| 303 | stateEffecterPDRs.getNextRecord(pdrRecord, pdrEntry); |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 304 | continue; |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 305 | } |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 306 | |
| 307 | states = reinterpret_cast<state_effecter_possible_states*>( |
| 308 | pdr->possible_states); |
| 309 | if (compEffecterCnt > pdr->composite_effecter_count) |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 310 | { |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 311 | std::cerr << "The requester sent wrong composite effecter" |
| 312 | << " count for the effecter, EFFECTER_ID=" |
| 313 | << effecterId << "COMP_EFF_CNT=" << compEffecterCnt |
| 314 | << "\n"; |
| 315 | return PLDM_ERROR_INVALID_DATA; |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 316 | } |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 317 | break; |
| 318 | } |
| 319 | |
| 320 | if (!pdr) |
| 321 | { |
| 322 | return PLDM_PLATFORM_INVALID_EFFECTER_ID; |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 323 | } |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 324 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 325 | int rc = PLDM_SUCCESS; |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 326 | try |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 327 | { |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 328 | const auto& [dbusMappings, dbusValMaps] = |
| 329 | dbusObjMaps.at(effecterId); |
| 330 | for (uint8_t currState = 0; currState < compEffecterCnt; |
| 331 | ++currState) |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 332 | { |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 333 | std::vector<StateSetNum> allowed{}; |
| 334 | // computation is based on table 79 from DSP0248 v1.1.1 |
| 335 | uint8_t bitfieldIndex = |
| 336 | stateField[currState].effecter_state / 8; |
| 337 | uint8_t bit = |
| 338 | stateField[currState].effecter_state - (8 * bitfieldIndex); |
| 339 | if (states->possible_states_size < bitfieldIndex || |
| 340 | !(states->states[bitfieldIndex].byte & (1 << bit))) |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 341 | { |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 342 | std::cerr |
| 343 | << "Invalid state set value, EFFECTER_ID=" << effecterId |
| 344 | << " VALUE=" << stateField[currState].effecter_state |
| 345 | << " COMPOSITE_EFFECTER_ID=" << currState |
| 346 | << " DBUS_PATH=" << dbusMappings[currState].objectPath |
| 347 | << "\n"; |
| 348 | rc = PLDM_PLATFORM_SET_EFFECTER_UNSUPPORTED_SENSORSTATE; |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 349 | break; |
| 350 | } |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 351 | const DBusMapping& dbusMapping = dbusMappings[currState]; |
| 352 | const StatestoDbusVal& dbusValToMap = dbusValMaps[currState]; |
| 353 | |
| 354 | if (stateField[currState].set_request == PLDM_REQUEST_SET) |
| 355 | { |
| 356 | try |
| 357 | { |
| 358 | dBusIntf.setDbusProperty( |
| 359 | dbusMapping, |
| 360 | dbusValToMap.at( |
| 361 | stateField[currState].effecter_state)); |
| 362 | } |
| 363 | catch (const std::exception& e) |
| 364 | { |
| 365 | std::cerr |
| 366 | << "Error setting property, ERROR=" << e.what() |
| 367 | << " PROPERTY=" << dbusMapping.propertyName |
| 368 | << " INTERFACE=" |
| 369 | << dbusMapping.interface << " PATH=" |
| 370 | << dbusMapping.objectPath << "\n"; |
| 371 | return PLDM_ERROR; |
| 372 | } |
| 373 | } |
| 374 | uint8_t* nextState = |
| 375 | reinterpret_cast<uint8_t*>(states) + |
| 376 | sizeof(state_effecter_possible_states) - |
| 377 | sizeof(states->states) + |
| 378 | (states->possible_states_size * sizeof(states->states)); |
| 379 | states = reinterpret_cast<state_effecter_possible_states*>( |
| 380 | nextState); |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 381 | } |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 382 | } |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 383 | catch (const std::out_of_range& e) |
| 384 | { |
| 385 | std::cerr << "the effecterId does not exist. effecter id: " |
| 386 | << effecterId << e.what() << '\n'; |
| 387 | } |
| 388 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 389 | return rc; |
| 390 | } |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 391 | |
| 392 | private: |
| 393 | pdr_utils::Repo pdrRepo; |
| 394 | uint16_t nextEffecterId{}; |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 395 | DbusObjMaps dbusObjMaps{}; |
Pavithra Barithaya | 51efaf8 | 2020-04-02 02:42:27 -0500 | [diff] [blame] | 396 | HostPDRHandler* hostPDRHandler; |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 397 | }; |
| 398 | |
| 399 | } // namespace platform |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 400 | } // namespace responder |
| 401 | } // namespace pldm |