Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 1 | |
| 2 | #include "platform.hpp" |
| 3 | |
Deepak Kodihalli | d130e1a | 2020-06-17 05:55:32 -0500 | [diff] [blame] | 4 | #include "common/utils.hpp" |
Tom Joseph | c4959c3 | 2020-04-20 19:50:16 +0530 | [diff] [blame] | 5 | #include "event_parser.hpp" |
George Liu | 456c9a2 | 2020-01-13 11:36:22 +0800 | [diff] [blame] | 6 | #include "pdr_numeric_effecter.hpp" |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 7 | #include "pdr_state_effecter.hpp" |
George Liu | eccb0c5 | 2020-01-14 11:09:56 +0800 | [diff] [blame] | 8 | #include "platform_numeric_effecter.hpp" |
George Liu | 0d7aca8 | 2020-03-30 15:01:36 +0800 | [diff] [blame] | 9 | #include "platform_state_effecter.hpp" |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 10 | |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 11 | namespace pldm |
| 12 | { |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 13 | namespace responder |
| 14 | { |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 15 | namespace platform |
| 16 | { |
| 17 | |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 18 | using InternalFailure = |
| 19 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
| 20 | |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 21 | static const Json empty{}; |
| 22 | |
Zahed Hossain | 75330f3 | 2020-03-24 02:15:03 -0500 | [diff] [blame] | 23 | using EventEntryMap = std::map<EventEntry, DBusInfo>; |
| 24 | |
| 25 | const EventEntryMap eventEntryMap = { |
| 26 | { |
| 27 | 0x01010007, // SensorID for VMI Port 0 ipv4 = 7, SensorOffset for the |
| 28 | // State Set ID 15 = 1 & PLDM State Set Enumeration List = 1 |
| 29 | // (Valid Configuration) |
| 30 | {"/xyz/openbmc_project/network/vmi/intf0/ipv4/addr0", |
| 31 | "xyz.openbmc_project.Object.Enable", "Enabled", "bool", true}, |
| 32 | }, |
| 33 | { |
| 34 | 0x02010007, // SensorID for VMI Port 0 ipv4 = 7, SensorOffset for the |
| 35 | // State Set ID 15 = 1 & PLDM State Set Enumeration List = 2 |
| 36 | // (Invalid Configuration) |
| 37 | {"/xyz/openbmc_project/network/vmi/intf0/ipv4/addr0", |
| 38 | "xyz.openbmc_project.Object.Enable", "Enabled", "bool", false}, |
| 39 | }, |
| 40 | { |
| 41 | 0x01010008, // SensorID for VMI Port 1 ipv4 = 8, SensorOffset for the |
| 42 | // State Set ID 15 = 1 & PLDM State Set Enumeration List = 1 |
| 43 | // (Valid Configuration) |
| 44 | {"/xyz/openbmc_project/network/vmi/intf1/ipv4/addr0", |
| 45 | "xyz.openbmc_project.Object.Enable", "Enabled", "bool", true}, |
| 46 | }, |
| 47 | { |
| 48 | 0x02010008, // SensorID for VMI Port 1 ipv4 = 8, SensorOffset for the |
| 49 | // State Set ID 15 = 1 & PLDM State Set Enumeration List = 2 |
| 50 | // (Invalid Configuration) |
| 51 | {"/xyz/openbmc_project/network/vmi/intf1/ipv4/addr0", |
| 52 | "xyz.openbmc_project.Object.Enable", "Enabled", "bool", false}, |
| 53 | }}; |
| 54 | |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 55 | void Handler::addDbusObjMaps( |
| 56 | uint16_t effecterId, |
| 57 | std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> dbusObj) |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 58 | { |
| 59 | dbusObjMaps.emplace(effecterId, dbusObj); |
| 60 | } |
| 61 | |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 62 | const std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>& |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 63 | Handler::getDbusObjMaps(uint16_t effecterId) const |
| 64 | { |
| 65 | return dbusObjMaps.at(effecterId); |
| 66 | } |
| 67 | |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 68 | void Handler::generate(const std::string& dir, Repo& repo) |
| 69 | { |
| 70 | // A map of PDR type to a lambda that handles creation of that PDR type. |
| 71 | // The lambda essentially would parse the platform specific PDR JSONs to |
| 72 | // generate the PDR structures. This function iterates through the map to |
| 73 | // invoke all lambdas, so that all PDR types can be created. |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 74 | |
| 75 | const std::map<Type, generatePDR> generateHandlers = { |
| 76 | {PLDM_STATE_EFFECTER_PDR, |
| 77 | [this](const auto& json, RepoInterface& repo) { |
| 78 | pdr_state_effecter::generateStateEffecterPDR<Handler>(json, *this, |
| 79 | repo); |
George Liu | 456c9a2 | 2020-01-13 11:36:22 +0800 | [diff] [blame] | 80 | }}, |
| 81 | {PLDM_NUMERIC_EFFECTER_PDR, |
| 82 | [this](const auto& json, RepoInterface& repo) { |
| 83 | pdr_numeric_effecter::generateNumericEffecterPDR<Handler>( |
| 84 | json, *this, repo); |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 85 | }}}; |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 86 | |
| 87 | Type pdrType{}; |
| 88 | for (const auto& dirEntry : fs::directory_iterator(dir)) |
| 89 | { |
| 90 | try |
| 91 | { |
| 92 | auto json = readJson(dirEntry.path().string()); |
| 93 | if (!json.empty()) |
| 94 | { |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 95 | auto effecterPDRs = json.value("effecterPDRs", empty); |
| 96 | for (const auto& effecter : effecterPDRs) |
| 97 | { |
| 98 | pdrType = effecter.value("pdrType", 0); |
George Liu | a287072 | 2020-02-11 11:09:30 +0800 | [diff] [blame] | 99 | generateHandlers.at(pdrType)(effecter, repo); |
George Liu | 1ec85d4 | 2020-02-12 16:05:32 +0800 | [diff] [blame] | 100 | } |
Deepak Kodihalli | c682fe2 | 2020-03-04 00:42:54 -0600 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | catch (const InternalFailure& e) |
| 104 | { |
| 105 | std::cerr << "PDR config directory does not exist or empty, TYPE= " |
| 106 | << pdrType << "PATH= " << dirEntry |
| 107 | << " ERROR=" << e.what() << "\n"; |
| 108 | } |
| 109 | catch (const Json::exception& e) |
| 110 | { |
| 111 | std::cerr << "Failed parsing PDR JSON file, TYPE= " << pdrType |
| 112 | << " ERROR=" << e.what() << "\n"; |
| 113 | pldm::utils::reportError( |
| 114 | "xyz.openbmc_project.bmc.pldm.InternalFailure"); |
| 115 | } |
| 116 | catch (const std::exception& e) |
| 117 | { |
| 118 | std::cerr << "Failed parsing PDR JSON file, TYPE= " << pdrType |
| 119 | << " ERROR=" << e.what() << "\n"; |
| 120 | pldm::utils::reportError( |
| 121 | "xyz.openbmc_project.bmc.pldm.InternalFailure"); |
| 122 | } |
| 123 | } |
| 124 | } |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 125 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 126 | Response Handler::getPDR(const pldm_msg* request, size_t payloadLength) |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 127 | { |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 128 | // Build FRU table if not built, since entity association PDR's are built |
| 129 | // when the FRU table is constructed. |
| 130 | if (fruHandler) |
| 131 | { |
| 132 | fruHandler->buildFRUTable(); |
| 133 | } |
| 134 | |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 135 | Response response(sizeof(pldm_msg_hdr) + PLDM_GET_PDR_MIN_RESP_BYTES, 0); |
| 136 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
| 137 | |
| 138 | if (payloadLength != PLDM_GET_PDR_REQ_BYTES) |
| 139 | { |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 140 | return CmdHandler::ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | uint32_t recordHandle{}; |
| 144 | uint32_t dataTransferHandle{}; |
| 145 | uint8_t transferOpFlag{}; |
| 146 | uint16_t reqSizeBytes{}; |
| 147 | uint16_t recordChangeNum{}; |
| 148 | |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 149 | auto rc = decode_get_pdr_req(request, payloadLength, &recordHandle, |
| 150 | &dataTransferHandle, &transferOpFlag, |
| 151 | &reqSizeBytes, &recordChangeNum); |
| 152 | if (rc != PLDM_SUCCESS) |
| 153 | { |
| 154 | return CmdHandler::ccOnlyResponse(request, rc); |
| 155 | } |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 156 | |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 157 | uint16_t respSizeBytes{}; |
| 158 | uint8_t* recordData = nullptr; |
| 159 | try |
| 160 | { |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 161 | pdr_utils::PdrEntry e; |
| 162 | auto record = pdr::getRecordByHandle(pdrRepo, recordHandle, e); |
| 163 | if (record == NULL) |
| 164 | { |
| 165 | return CmdHandler::ccOnlyResponse( |
| 166 | request, PLDM_PLATFORM_INVALID_RECORD_HANDLE); |
| 167 | } |
| 168 | |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 169 | if (reqSizeBytes) |
| 170 | { |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 171 | respSizeBytes = e.size; |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 172 | if (respSizeBytes > reqSizeBytes) |
| 173 | { |
| 174 | respSizeBytes = reqSizeBytes; |
| 175 | } |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame] | 176 | recordData = e.data; |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 177 | } |
| 178 | response.resize(sizeof(pldm_msg_hdr) + PLDM_GET_PDR_MIN_RESP_BYTES + |
| 179 | respSizeBytes, |
| 180 | 0); |
| 181 | responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
Deepak Kodihalli | 22b5a7d | 2020-03-17 23:28:41 -0500 | [diff] [blame] | 182 | rc = encode_get_pdr_resp( |
| 183 | request->hdr.instance_id, PLDM_SUCCESS, e.handle.nextRecordHandle, |
| 184 | 0, PLDM_START_AND_END, respSizeBytes, recordData, 0, responsePtr); |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 185 | if (rc != PLDM_SUCCESS) |
| 186 | { |
| 187 | return ccOnlyResponse(request, rc); |
| 188 | } |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 189 | } |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 190 | catch (const std::exception& e) |
| 191 | { |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 192 | std::cerr << "Error accessing PDR, HANDLE=" << recordHandle |
| 193 | << " ERROR=" << e.what() << "\n"; |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 194 | return CmdHandler::ccOnlyResponse(request, PLDM_ERROR); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 195 | } |
| 196 | return response; |
| 197 | } |
| 198 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 199 | Response Handler::setStateEffecterStates(const pldm_msg* request, |
| 200 | size_t payloadLength) |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 201 | { |
| 202 | Response response( |
| 203 | sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES, 0); |
| 204 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
| 205 | uint16_t effecterId; |
| 206 | uint8_t compEffecterCnt; |
| 207 | constexpr auto maxCompositeEffecterCnt = 8; |
| 208 | std::vector<set_effecter_state_field> stateField(maxCompositeEffecterCnt, |
| 209 | {0, 0}); |
| 210 | |
| 211 | if ((payloadLength > PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES) || |
| 212 | (payloadLength < sizeof(effecterId) + sizeof(compEffecterCnt) + |
| 213 | sizeof(set_effecter_state_field))) |
| 214 | { |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 215 | return CmdHandler::ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | int rc = decode_set_state_effecter_states_req(request, payloadLength, |
| 219 | &effecterId, &compEffecterCnt, |
| 220 | stateField.data()); |
| 221 | |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 222 | if (rc != PLDM_SUCCESS) |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 223 | { |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 224 | return CmdHandler::ccOnlyResponse(request, rc); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 225 | } |
| 226 | |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 227 | stateField.resize(compEffecterCnt); |
| 228 | const pldm::utils::DBusHandler dBusIntf; |
George Liu | 0d7aca8 | 2020-03-30 15:01:36 +0800 | [diff] [blame] | 229 | rc = platform_state_effecter::setStateEffecterStatesHandler< |
| 230 | pldm::utils::DBusHandler, Handler>(dBusIntf, *this, effecterId, |
| 231 | stateField); |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 232 | if (rc != PLDM_SUCCESS) |
| 233 | { |
| 234 | return CmdHandler::ccOnlyResponse(request, rc); |
| 235 | } |
| 236 | |
| 237 | rc = encode_set_state_effecter_states_resp(request->hdr.instance_id, rc, |
| 238 | responsePtr); |
| 239 | if (rc != PLDM_SUCCESS) |
| 240 | { |
| 241 | return ccOnlyResponse(request, rc); |
| 242 | } |
| 243 | |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 244 | return response; |
| 245 | } |
| 246 | |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 247 | Response Handler::platformEventMessage(const pldm_msg* request, |
| 248 | size_t payloadLength) |
| 249 | { |
| 250 | uint8_t formatVersion{}; |
| 251 | uint8_t tid{}; |
| 252 | uint8_t eventClass{}; |
| 253 | size_t offset{}; |
| 254 | |
| 255 | auto rc = decode_platform_event_message_req( |
| 256 | request, payloadLength, &formatVersion, &tid, &eventClass, &offset); |
| 257 | if (rc != PLDM_SUCCESS) |
| 258 | { |
| 259 | return CmdHandler::ccOnlyResponse(request, rc); |
| 260 | } |
| 261 | |
| 262 | try |
| 263 | { |
| 264 | const auto& handlers = eventHandlers.at(eventClass); |
| 265 | for (const auto& handler : handlers) |
| 266 | { |
| 267 | auto rc = |
| 268 | handler(request, payloadLength, formatVersion, tid, offset); |
| 269 | if (rc != PLDM_SUCCESS) |
| 270 | { |
| 271 | return CmdHandler::ccOnlyResponse(request, rc); |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | catch (const std::out_of_range& e) |
| 276 | { |
| 277 | return CmdHandler::ccOnlyResponse(request, PLDM_ERROR_INVALID_DATA); |
| 278 | } |
| 279 | |
| 280 | Response response( |
| 281 | sizeof(pldm_msg_hdr) + PLDM_PLATFORM_EVENT_MESSAGE_RESP_BYTES, 0); |
| 282 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
| 283 | |
| 284 | rc = encode_platform_event_message_resp(request->hdr.instance_id, rc, |
| 285 | PLDM_EVENT_NO_LOGGING, responsePtr); |
| 286 | if (rc != PLDM_SUCCESS) |
| 287 | { |
| 288 | return ccOnlyResponse(request, rc); |
| 289 | } |
| 290 | |
| 291 | return response; |
| 292 | } |
| 293 | |
| 294 | int Handler::sensorEvent(const pldm_msg* request, size_t payloadLength, |
Tom Joseph | c4959c3 | 2020-04-20 19:50:16 +0530 | [diff] [blame] | 295 | uint8_t /*formatVersion*/, uint8_t tid, |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 296 | size_t eventDataOffset) |
| 297 | { |
| 298 | uint16_t sensorId{}; |
| 299 | uint8_t eventClass{}; |
| 300 | size_t eventClassDataOffset{}; |
| 301 | auto eventData = |
| 302 | reinterpret_cast<const uint8_t*>(request->payload) + eventDataOffset; |
| 303 | auto eventDataSize = payloadLength - eventDataOffset; |
| 304 | |
| 305 | auto rc = decode_sensor_event_data(eventData, eventDataSize, &sensorId, |
| 306 | &eventClass, &eventClassDataOffset); |
| 307 | if (rc != PLDM_SUCCESS) |
| 308 | { |
| 309 | return rc; |
| 310 | } |
| 311 | |
Zahed Hossain | 75330f3 | 2020-03-24 02:15:03 -0500 | [diff] [blame] | 312 | auto eventClassData = reinterpret_cast<const uint8_t*>(request->payload) + |
| 313 | eventDataOffset + eventClassDataOffset; |
| 314 | auto eventClassDataSize = |
| 315 | payloadLength - eventDataOffset - eventClassDataOffset; |
| 316 | |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 317 | if (eventClass == PLDM_STATE_SENSOR_STATE) |
| 318 | { |
| 319 | uint8_t sensorOffset{}; |
| 320 | uint8_t eventState{}; |
| 321 | uint8_t previousEventState{}; |
| 322 | |
Zahed Hossain | 75330f3 | 2020-03-24 02:15:03 -0500 | [diff] [blame] | 323 | rc = decode_state_sensor_data(eventClassData, eventClassDataSize, |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 324 | &sensorOffset, &eventState, |
| 325 | &previousEventState); |
Zahed Hossain | 75330f3 | 2020-03-24 02:15:03 -0500 | [diff] [blame] | 326 | if (rc != PLDM_SUCCESS) |
| 327 | { |
| 328 | return PLDM_ERROR; |
| 329 | } |
| 330 | |
Chicago Duan | fe4d88b | 2020-06-12 16:44:13 +0800 | [diff] [blame] | 331 | // Emitting state sensor event signal |
| 332 | emitStateSensorEventSignal(tid, sensorId, sensorOffset, eventState, |
| 333 | previousEventState); |
| 334 | |
Tom Joseph | c4959c3 | 2020-04-20 19:50:16 +0530 | [diff] [blame] | 335 | // Handle PLDM events for which PDR is not available, setSensorEventData |
| 336 | // will return PLDM_ERROR_INVALID_DATA if the sensorID is not found in |
| 337 | // the hardcoded sensor list. |
Zahed Hossain | 75330f3 | 2020-03-24 02:15:03 -0500 | [diff] [blame] | 338 | rc = setSensorEventData(sensorId, sensorOffset, eventState); |
Tom Joseph | c4959c3 | 2020-04-20 19:50:16 +0530 | [diff] [blame] | 339 | if (rc != PLDM_ERROR_INVALID_DATA) |
Zahed Hossain | 75330f3 | 2020-03-24 02:15:03 -0500 | [diff] [blame] | 340 | { |
Tom Joseph | c4959c3 | 2020-04-20 19:50:16 +0530 | [diff] [blame] | 341 | return rc; |
| 342 | } |
| 343 | |
| 344 | // If there are no HOST PDR's, there is no further action |
| 345 | if (hostPDRHandler == NULL) |
| 346 | { |
| 347 | return PLDM_SUCCESS; |
| 348 | } |
| 349 | |
| 350 | // Handle PLDM events for which PDR is available |
| 351 | SensorEntry sensorEntry{tid, sensorId}; |
| 352 | try |
| 353 | { |
| 354 | const auto& [entityInfo, compositeSensorStates] = |
| 355 | hostPDRHandler->lookupSensorInfo(sensorEntry); |
| 356 | if (sensorOffset >= compositeSensorStates.size()) |
| 357 | { |
| 358 | return PLDM_ERROR_INVALID_DATA; |
| 359 | } |
| 360 | |
| 361 | const auto& possibleStates = compositeSensorStates[sensorOffset]; |
| 362 | if (possibleStates.find(eventState) == possibleStates.end()) |
| 363 | { |
| 364 | return PLDM_ERROR_INVALID_DATA; |
| 365 | } |
| 366 | |
| 367 | const auto& [containerId, entityType, entityInstance] = entityInfo; |
| 368 | events::StateSensorEntry stateSensorEntry{ |
| 369 | containerId, entityType, entityInstance, sensorOffset}; |
| 370 | return stateSensorHandler.eventAction(stateSensorEntry, eventState); |
| 371 | } |
| 372 | // If there is no mapping for events return PLDM_SUCCESS |
| 373 | catch (const std::out_of_range& e) |
| 374 | { |
| 375 | return PLDM_SUCCESS; |
Zahed Hossain | 75330f3 | 2020-03-24 02:15:03 -0500 | [diff] [blame] | 376 | } |
Tom Joseph | 56e45c5 | 2020-03-16 10:01:45 +0530 | [diff] [blame] | 377 | } |
| 378 | else |
| 379 | { |
| 380 | return PLDM_ERROR_INVALID_DATA; |
| 381 | } |
| 382 | |
| 383 | return PLDM_SUCCESS; |
| 384 | } |
| 385 | |
Zahed Hossain | 75330f3 | 2020-03-24 02:15:03 -0500 | [diff] [blame] | 386 | int Handler::setSensorEventData(uint16_t sensorId, uint8_t sensorOffset, |
| 387 | uint8_t eventState) |
| 388 | { |
| 389 | EventEntry eventEntry = ((static_cast<uint32_t>(eventState)) << 24) + |
| 390 | ((static_cast<uint32_t>(sensorOffset)) << 16) + |
| 391 | sensorId; |
| 392 | auto iter = eventEntryMap.find(eventEntry); |
| 393 | if (iter == eventEntryMap.end()) |
| 394 | { |
Tom Joseph | c4959c3 | 2020-04-20 19:50:16 +0530 | [diff] [blame] | 395 | return PLDM_ERROR_INVALID_DATA; |
Zahed Hossain | 75330f3 | 2020-03-24 02:15:03 -0500 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | const auto& dBusInfo = iter->second; |
| 399 | try |
| 400 | { |
| 401 | pldm::utils::DBusMapping dbusMapping{ |
| 402 | dBusInfo.dBusValues.objectPath, dBusInfo.dBusValues.interface, |
| 403 | dBusInfo.dBusValues.propertyName, dBusInfo.dBusValues.propertyType}; |
| 404 | pldm::utils::DBusHandler().setDbusProperty(dbusMapping, |
| 405 | dBusInfo.dBusPropertyValue); |
| 406 | } |
| 407 | catch (std::exception& e) |
| 408 | { |
Zahed Hossain | 75330f3 | 2020-03-24 02:15:03 -0500 | [diff] [blame] | 409 | std::cerr |
| 410 | << "Error Setting dbus property,SensorID=" << eventEntry |
| 411 | << "DBusInfo=" << dBusInfo.dBusValues.objectPath |
| 412 | << dBusInfo.dBusValues.interface << dBusInfo.dBusValues.propertyName |
| 413 | << "ERROR=" << e.what() << "\n"; |
| 414 | return PLDM_ERROR; |
| 415 | } |
| 416 | return PLDM_SUCCESS; |
| 417 | } |
| 418 | |
Deepak Kodihalli | 8cb6f66 | 2020-04-10 02:55:43 -0500 | [diff] [blame] | 419 | int Handler::pldmPDRRepositoryChgEvent(const pldm_msg* request, |
| 420 | size_t payloadLength, |
| 421 | uint8_t /*formatVersion*/, |
| 422 | uint8_t /*tid*/, size_t eventDataOffset) |
| 423 | { |
| 424 | uint8_t eventDataFormat{}; |
| 425 | uint8_t numberOfChangeRecords{}; |
| 426 | size_t dataOffset{}; |
| 427 | |
| 428 | auto eventData = |
| 429 | reinterpret_cast<const uint8_t*>(request->payload) + eventDataOffset; |
| 430 | auto eventDataSize = payloadLength - eventDataOffset; |
| 431 | |
| 432 | auto rc = decode_pldm_pdr_repository_chg_event_data( |
| 433 | eventData, eventDataSize, &eventDataFormat, &numberOfChangeRecords, |
| 434 | &dataOffset); |
| 435 | if (rc != PLDM_SUCCESS) |
| 436 | { |
| 437 | return rc; |
| 438 | } |
| 439 | |
| 440 | PDRRecordHandles pdrRecordHandles; |
| 441 | if (eventDataFormat == FORMAT_IS_PDR_HANDLES) |
| 442 | { |
| 443 | uint8_t eventDataOperation{}; |
| 444 | uint8_t numberOfChangeEntries{}; |
| 445 | |
| 446 | auto changeRecordData = eventData + dataOffset; |
| 447 | auto changeRecordDataSize = eventDataSize - dataOffset; |
| 448 | |
| 449 | while (changeRecordDataSize) |
| 450 | { |
| 451 | rc = decode_pldm_pdr_repository_change_record_data( |
| 452 | changeRecordData, changeRecordDataSize, &eventDataOperation, |
| 453 | &numberOfChangeEntries, &dataOffset); |
| 454 | |
| 455 | if (rc != PLDM_SUCCESS) |
| 456 | { |
| 457 | return rc; |
| 458 | } |
| 459 | |
| 460 | if (eventDataOperation == PLDM_RECORDS_ADDED) |
| 461 | { |
| 462 | rc = getPDRRecordHandles( |
| 463 | reinterpret_cast<const ChangeEntry*>(changeRecordData + |
| 464 | dataOffset), |
| 465 | changeRecordDataSize - dataOffset, |
| 466 | static_cast<size_t>(numberOfChangeEntries), |
| 467 | pdrRecordHandles); |
| 468 | |
| 469 | if (rc != PLDM_SUCCESS) |
| 470 | { |
| 471 | return rc; |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | changeRecordData += |
| 476 | dataOffset + (numberOfChangeEntries * sizeof(ChangeEntry)); |
| 477 | changeRecordDataSize -= |
| 478 | dataOffset + (numberOfChangeEntries * sizeof(ChangeEntry)); |
| 479 | } |
| 480 | |
| 481 | if (hostPDRHandler && !pdrRecordHandles.empty()) |
| 482 | { |
| 483 | hostPDRHandler->fetchPDR(std::move(pdrRecordHandles)); |
| 484 | } |
| 485 | } |
| 486 | else |
| 487 | { |
| 488 | return PLDM_ERROR_INVALID_DATA; |
| 489 | } |
| 490 | |
| 491 | return PLDM_SUCCESS; |
| 492 | } |
| 493 | |
| 494 | int Handler::getPDRRecordHandles(const ChangeEntry* changeEntryData, |
| 495 | size_t changeEntryDataSize, |
| 496 | size_t numberOfChangeEntries, |
| 497 | PDRRecordHandles& pdrRecordHandles) |
| 498 | { |
| 499 | if (numberOfChangeEntries > (changeEntryDataSize / sizeof(ChangeEntry))) |
| 500 | { |
| 501 | return PLDM_ERROR_INVALID_DATA; |
| 502 | } |
| 503 | for (size_t i = 0; i < numberOfChangeEntries; i++) |
| 504 | { |
| 505 | pdrRecordHandles.push_back(changeEntryData[i]); |
| 506 | } |
| 507 | return PLDM_SUCCESS; |
| 508 | } |
| 509 | |
George Liu | eccb0c5 | 2020-01-14 11:09:56 +0800 | [diff] [blame] | 510 | Response Handler::setNumericEffecterValue(const pldm_msg* request, |
| 511 | size_t payloadLength) |
| 512 | { |
| 513 | Response response(sizeof(pldm_msg_hdr) + |
| 514 | PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES); |
| 515 | uint16_t effecterId{}; |
| 516 | uint8_t effecterDataSize{}; |
| 517 | uint8_t effecterValue[4] = {}; |
| 518 | |
| 519 | if ((payloadLength > sizeof(effecterId) + sizeof(effecterDataSize) + |
| 520 | sizeof(union_effecter_data_size)) || |
| 521 | (payloadLength < sizeof(effecterId) + sizeof(effecterDataSize) + 1)) |
| 522 | { |
| 523 | return ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH); |
| 524 | } |
| 525 | |
| 526 | int rc = decode_set_numeric_effecter_value_req( |
| 527 | request, payloadLength, &effecterId, &effecterDataSize, |
| 528 | reinterpret_cast<uint8_t*>(&effecterValue)); |
| 529 | |
| 530 | if (rc == PLDM_SUCCESS) |
| 531 | { |
| 532 | const pldm::utils::DBusHandler dBusIntf; |
| 533 | rc = platform_numeric_effecter::setNumericEffecterValueHandler< |
| 534 | pldm::utils::DBusHandler, Handler>(dBusIntf, *this, effecterId, |
| 535 | effecterDataSize, effecterValue, |
| 536 | sizeof(effecterValue)); |
| 537 | } |
| 538 | |
| 539 | return ccOnlyResponse(request, rc); |
| 540 | } |
| 541 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 542 | } // namespace platform |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 543 | } // namespace responder |
| 544 | } // namespace pldm |