blob: ecbc121db2d855c6d48a91fa006b836d2d09d7f4 [file] [log] [blame]
Deepak Kodihalli557dfb02019-05-12 13:11:17 +05301
2#include "platform.hpp"
3
Tom Josephb70a1962020-07-13 12:56:31 +05304#include "common/types.hpp"
Deepak Kodihallid130e1a2020-06-17 05:55:32 -05005#include "common/utils.hpp"
Tom Josephc4959c32020-04-20 19:50:16 +05306#include "event_parser.hpp"
Sampa Misra12afe112020-05-25 11:40:44 -05007#include "pdr.hpp"
George Liu456c9a22020-01-13 11:36:22 +08008#include "pdr_numeric_effecter.hpp"
George Liua2870722020-02-11 11:09:30 +08009#include "pdr_state_effecter.hpp"
George Liuadbe1722020-05-09 19:20:19 +080010#include "pdr_state_sensor.hpp"
George Liu362c18d2020-05-14 09:46:36 +080011#include "pdr_utils.hpp"
George Liueccb0c52020-01-14 11:09:56 +080012#include "platform_numeric_effecter.hpp"
George Liu0d7aca82020-03-30 15:01:36 +080013#include "platform_state_effecter.hpp"
George Liu362c18d2020-05-14 09:46:36 +080014#include "platform_state_sensor.hpp"
George Liu83409572019-12-24 18:42:54 +080015
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053016namespace pldm
17{
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053018namespace responder
19{
Sampa Misraa2fa0702019-05-31 01:28:55 -050020namespace platform
21{
22
Deepak Kodihallic682fe22020-03-04 00:42:54 -060023using InternalFailure =
24 sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
25
George Liu1ec85d42020-02-12 16:05:32 +080026static const Json empty{};
27
George Liua2870722020-02-11 11:09:30 +080028void Handler::addDbusObjMaps(
George Liuadbe1722020-05-09 19:20:19 +080029 uint16_t id,
30 std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> dbusObj,
31 TypeId typeId)
George Liu1ec85d42020-02-12 16:05:32 +080032{
George Liuadbe1722020-05-09 19:20:19 +080033 if (typeId == TypeId::PLDM_SENSOR_ID)
34 {
35 sensorDbusObjMaps.emplace(id, dbusObj);
36 }
37 else
38 {
39 effecterDbusObjMaps.emplace(id, dbusObj);
40 }
George Liu1ec85d42020-02-12 16:05:32 +080041}
42
George Liua2870722020-02-11 11:09:30 +080043const std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>&
George Liuadbe1722020-05-09 19:20:19 +080044 Handler::getDbusObjMaps(uint16_t id, TypeId typeId) const
George Liu1ec85d42020-02-12 16:05:32 +080045{
George Liuadbe1722020-05-09 19:20:19 +080046 if (typeId == TypeId::PLDM_SENSOR_ID)
47 {
48 return sensorDbusObjMaps.at(id);
49 }
50 else
51 {
52 return effecterDbusObjMaps.at(id);
53 }
George Liu1ec85d42020-02-12 16:05:32 +080054}
55
George Liu36e81352020-07-01 14:40:30 +080056void Handler::generate(const pldm::utils::DBusHandler& dBusIntf,
57 const std::string& dir, Repo& repo)
Deepak Kodihallic682fe22020-03-04 00:42:54 -060058{
Deepak Kodihallic6e49c42020-07-01 03:39:27 -050059 if (!fs::exists(dir))
60 {
61 return;
62 }
63
Deepak Kodihallic682fe22020-03-04 00:42:54 -060064 // A map of PDR type to a lambda that handles creation of that PDR type.
65 // The lambda essentially would parse the platform specific PDR JSONs to
66 // generate the PDR structures. This function iterates through the map to
67 // invoke all lambdas, so that all PDR types can be created.
George Liua2870722020-02-11 11:09:30 +080068
69 const std::map<Type, generatePDR> generateHandlers = {
70 {PLDM_STATE_EFFECTER_PDR,
George Liu36e81352020-07-01 14:40:30 +080071 [this](const DBusHandler& dBusIntf, const auto& json,
72 RepoInterface& repo) {
73 pdr_state_effecter::generateStateEffecterPDR<
74 pldm::utils::DBusHandler, Handler>(dBusIntf, json, *this,
75 repo);
George Liu456c9a22020-01-13 11:36:22 +080076 }},
77 {PLDM_NUMERIC_EFFECTER_PDR,
George Liu36e81352020-07-01 14:40:30 +080078 [this](const DBusHandler& dBusIntf, const auto& json,
79 RepoInterface& repo) {
80 pdr_numeric_effecter::generateNumericEffecterPDR<
81 pldm::utils::DBusHandler, Handler>(dBusIntf, json, *this,
82 repo);
George Liuadbe1722020-05-09 19:20:19 +080083 }},
84 {PLDM_STATE_SENSOR_PDR, [this](const DBusHandler& dBusIntf,
85 const auto& json, RepoInterface& repo) {
86 pdr_state_sensor::generateStateSensorPDR<pldm::utils::DBusHandler,
87 Handler>(dBusIntf, json,
88 *this, repo);
George Liua2870722020-02-11 11:09:30 +080089 }}};
Deepak Kodihallic682fe22020-03-04 00:42:54 -060090
91 Type pdrType{};
92 for (const auto& dirEntry : fs::directory_iterator(dir))
93 {
94 try
95 {
96 auto json = readJson(dirEntry.path().string());
97 if (!json.empty())
98 {
George Liu1ec85d42020-02-12 16:05:32 +080099 auto effecterPDRs = json.value("effecterPDRs", empty);
100 for (const auto& effecter : effecterPDRs)
101 {
102 pdrType = effecter.value("pdrType", 0);
George Liu36e81352020-07-01 14:40:30 +0800103 generateHandlers.at(pdrType)(dBusIntf, effecter, repo);
George Liu1ec85d42020-02-12 16:05:32 +0800104 }
George Liuadbe1722020-05-09 19:20:19 +0800105
106 auto sensorPDRs = json.value("sensorPDRs", empty);
107 for (const auto& sensor : sensorPDRs)
108 {
109 pdrType = sensor.value("pdrType", 0);
110 generateHandlers.at(pdrType)(dBusIntf, sensor, repo);
111 }
Deepak Kodihallic682fe22020-03-04 00:42:54 -0600112 }
113 }
114 catch (const InternalFailure& e)
115 {
116 std::cerr << "PDR config directory does not exist or empty, TYPE= "
117 << pdrType << "PATH= " << dirEntry
118 << " ERROR=" << e.what() << "\n";
119 }
120 catch (const Json::exception& e)
121 {
122 std::cerr << "Failed parsing PDR JSON file, TYPE= " << pdrType
123 << " ERROR=" << e.what() << "\n";
124 pldm::utils::reportError(
125 "xyz.openbmc_project.bmc.pldm.InternalFailure");
126 }
127 catch (const std::exception& e)
128 {
129 std::cerr << "Failed parsing PDR JSON file, TYPE= " << pdrType
130 << " ERROR=" << e.what() << "\n";
131 pldm::utils::reportError(
132 "xyz.openbmc_project.bmc.pldm.InternalFailure");
133 }
134 }
135}
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530136
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600137Response Handler::getPDR(const pldm_msg* request, size_t payloadLength)
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530138{
Tom Joseph33e9c7e2020-06-11 22:09:52 +0530139 // Build FRU table if not built, since entity association PDR's are built
140 // when the FRU table is constructed.
141 if (fruHandler)
142 {
143 fruHandler->buildFRUTable();
144 }
145
George Liud680ae02020-07-17 09:11:14 +0800146 if (!pdrCreated)
147 {
148 generateTerminusLocatorPDR(pdrRepo);
149 generate(*dBusIntf, pdrJsonsDir, pdrRepo);
150 pdrCreated = true;
151 }
152
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530153 Response response(sizeof(pldm_msg_hdr) + PLDM_GET_PDR_MIN_RESP_BYTES, 0);
154 auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
155
156 if (payloadLength != PLDM_GET_PDR_REQ_BYTES)
157 {
George Liufb8611d2019-12-06 10:14:15 +0800158 return CmdHandler::ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH);
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530159 }
160
161 uint32_t recordHandle{};
162 uint32_t dataTransferHandle{};
163 uint8_t transferOpFlag{};
164 uint16_t reqSizeBytes{};
165 uint16_t recordChangeNum{};
166
George Liufb8611d2019-12-06 10:14:15 +0800167 auto rc = decode_get_pdr_req(request, payloadLength, &recordHandle,
168 &dataTransferHandle, &transferOpFlag,
169 &reqSizeBytes, &recordChangeNum);
170 if (rc != PLDM_SUCCESS)
171 {
172 return CmdHandler::ccOnlyResponse(request, rc);
173 }
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530174
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530175 uint16_t respSizeBytes{};
176 uint8_t* recordData = nullptr;
177 try
178 {
George Liue53193f2020-02-24 09:23:26 +0800179 pdr_utils::PdrEntry e;
180 auto record = pdr::getRecordByHandle(pdrRepo, recordHandle, e);
181 if (record == NULL)
182 {
183 return CmdHandler::ccOnlyResponse(
184 request, PLDM_PLATFORM_INVALID_RECORD_HANDLE);
185 }
186
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530187 if (reqSizeBytes)
188 {
George Liue53193f2020-02-24 09:23:26 +0800189 respSizeBytes = e.size;
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530190 if (respSizeBytes > reqSizeBytes)
191 {
192 respSizeBytes = reqSizeBytes;
193 }
George Liue53193f2020-02-24 09:23:26 +0800194 recordData = e.data;
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530195 }
196 response.resize(sizeof(pldm_msg_hdr) + PLDM_GET_PDR_MIN_RESP_BYTES +
197 respSizeBytes,
198 0);
199 responsePtr = reinterpret_cast<pldm_msg*>(response.data());
Deepak Kodihalli22b5a7d2020-03-17 23:28:41 -0500200 rc = encode_get_pdr_resp(
201 request->hdr.instance_id, PLDM_SUCCESS, e.handle.nextRecordHandle,
202 0, PLDM_START_AND_END, respSizeBytes, recordData, 0, responsePtr);
George Liufb8611d2019-12-06 10:14:15 +0800203 if (rc != PLDM_SUCCESS)
204 {
205 return ccOnlyResponse(request, rc);
206 }
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530207 }
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530208 catch (const std::exception& e)
209 {
Sampa Misraaa8ae722019-12-12 03:20:40 -0600210 std::cerr << "Error accessing PDR, HANDLE=" << recordHandle
211 << " ERROR=" << e.what() << "\n";
George Liufb8611d2019-12-06 10:14:15 +0800212 return CmdHandler::ccOnlyResponse(request, PLDM_ERROR);
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530213 }
214 return response;
215}
216
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600217Response Handler::setStateEffecterStates(const pldm_msg* request,
218 size_t payloadLength)
Sampa Misraa2fa0702019-05-31 01:28:55 -0500219{
220 Response response(
221 sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES, 0);
222 auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
223 uint16_t effecterId;
224 uint8_t compEffecterCnt;
225 constexpr auto maxCompositeEffecterCnt = 8;
226 std::vector<set_effecter_state_field> stateField(maxCompositeEffecterCnt,
227 {0, 0});
228
229 if ((payloadLength > PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES) ||
230 (payloadLength < sizeof(effecterId) + sizeof(compEffecterCnt) +
231 sizeof(set_effecter_state_field)))
232 {
George Liufb8611d2019-12-06 10:14:15 +0800233 return CmdHandler::ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH);
Sampa Misraa2fa0702019-05-31 01:28:55 -0500234 }
235
236 int rc = decode_set_state_effecter_states_req(request, payloadLength,
237 &effecterId, &compEffecterCnt,
238 stateField.data());
239
George Liufb8611d2019-12-06 10:14:15 +0800240 if (rc != PLDM_SUCCESS)
Sampa Misraa2fa0702019-05-31 01:28:55 -0500241 {
George Liufb8611d2019-12-06 10:14:15 +0800242 return CmdHandler::ccOnlyResponse(request, rc);
Sampa Misraa2fa0702019-05-31 01:28:55 -0500243 }
244
George Liufb8611d2019-12-06 10:14:15 +0800245 stateField.resize(compEffecterCnt);
246 const pldm::utils::DBusHandler dBusIntf;
George Liu0d7aca82020-03-30 15:01:36 +0800247 rc = platform_state_effecter::setStateEffecterStatesHandler<
248 pldm::utils::DBusHandler, Handler>(dBusIntf, *this, effecterId,
249 stateField);
George Liufb8611d2019-12-06 10:14:15 +0800250 if (rc != PLDM_SUCCESS)
251 {
252 return CmdHandler::ccOnlyResponse(request, rc);
253 }
254
255 rc = encode_set_state_effecter_states_resp(request->hdr.instance_id, rc,
256 responsePtr);
257 if (rc != PLDM_SUCCESS)
258 {
259 return ccOnlyResponse(request, rc);
260 }
261
Sampa Misraa2fa0702019-05-31 01:28:55 -0500262 return response;
263}
264
Tom Joseph56e45c52020-03-16 10:01:45 +0530265Response Handler::platformEventMessage(const pldm_msg* request,
266 size_t payloadLength)
267{
268 uint8_t formatVersion{};
269 uint8_t tid{};
270 uint8_t eventClass{};
271 size_t offset{};
272
273 auto rc = decode_platform_event_message_req(
274 request, payloadLength, &formatVersion, &tid, &eventClass, &offset);
275 if (rc != PLDM_SUCCESS)
276 {
277 return CmdHandler::ccOnlyResponse(request, rc);
278 }
279
280 try
281 {
282 const auto& handlers = eventHandlers.at(eventClass);
283 for (const auto& handler : handlers)
284 {
285 auto rc =
286 handler(request, payloadLength, formatVersion, tid, offset);
287 if (rc != PLDM_SUCCESS)
288 {
289 return CmdHandler::ccOnlyResponse(request, rc);
290 }
291 }
292 }
293 catch (const std::out_of_range& e)
294 {
295 return CmdHandler::ccOnlyResponse(request, PLDM_ERROR_INVALID_DATA);
296 }
297
298 Response response(
299 sizeof(pldm_msg_hdr) + PLDM_PLATFORM_EVENT_MESSAGE_RESP_BYTES, 0);
300 auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
301
302 rc = encode_platform_event_message_resp(request->hdr.instance_id, rc,
303 PLDM_EVENT_NO_LOGGING, responsePtr);
304 if (rc != PLDM_SUCCESS)
305 {
306 return ccOnlyResponse(request, rc);
307 }
308
309 return response;
310}
311
312int Handler::sensorEvent(const pldm_msg* request, size_t payloadLength,
Tom Josephc4959c32020-04-20 19:50:16 +0530313 uint8_t /*formatVersion*/, uint8_t tid,
Tom Joseph56e45c52020-03-16 10:01:45 +0530314 size_t eventDataOffset)
315{
316 uint16_t sensorId{};
317 uint8_t eventClass{};
318 size_t eventClassDataOffset{};
319 auto eventData =
320 reinterpret_cast<const uint8_t*>(request->payload) + eventDataOffset;
321 auto eventDataSize = payloadLength - eventDataOffset;
322
323 auto rc = decode_sensor_event_data(eventData, eventDataSize, &sensorId,
324 &eventClass, &eventClassDataOffset);
325 if (rc != PLDM_SUCCESS)
326 {
327 return rc;
328 }
329
Zahed Hossain75330f32020-03-24 02:15:03 -0500330 auto eventClassData = reinterpret_cast<const uint8_t*>(request->payload) +
331 eventDataOffset + eventClassDataOffset;
332 auto eventClassDataSize =
333 payloadLength - eventDataOffset - eventClassDataOffset;
334
Tom Joseph56e45c52020-03-16 10:01:45 +0530335 if (eventClass == PLDM_STATE_SENSOR_STATE)
336 {
337 uint8_t sensorOffset{};
338 uint8_t eventState{};
339 uint8_t previousEventState{};
340
Zahed Hossain75330f32020-03-24 02:15:03 -0500341 rc = decode_state_sensor_data(eventClassData, eventClassDataSize,
Tom Joseph56e45c52020-03-16 10:01:45 +0530342 &sensorOffset, &eventState,
343 &previousEventState);
Zahed Hossain75330f32020-03-24 02:15:03 -0500344 if (rc != PLDM_SUCCESS)
345 {
346 return PLDM_ERROR;
347 }
348
Chicago Duanfe4d88b2020-06-12 16:44:13 +0800349 // Emitting state sensor event signal
350 emitStateSensorEventSignal(tid, sensorId, sensorOffset, eventState,
351 previousEventState);
352
Tom Josephc4959c32020-04-20 19:50:16 +0530353 // If there are no HOST PDR's, there is no further action
354 if (hostPDRHandler == NULL)
355 {
356 return PLDM_SUCCESS;
357 }
358
359 // Handle PLDM events for which PDR is available
360 SensorEntry sensorEntry{tid, sensorId};
Tom Josephb70a1962020-07-13 12:56:31 +0530361
362 pldm::pdr::EntityInfo entityInfo{};
363 pldm::pdr::CompositeSensorStates compositeSensorStates{};
364
Tom Josephc4959c32020-04-20 19:50:16 +0530365 try
366 {
Tom Josephb70a1962020-07-13 12:56:31 +0530367 std::tie(entityInfo, compositeSensorStates) =
Tom Josephc4959c32020-04-20 19:50:16 +0530368 hostPDRHandler->lookupSensorInfo(sensorEntry);
Tom Josephc4959c32020-04-20 19:50:16 +0530369 }
Tom Josephc4959c32020-04-20 19:50:16 +0530370 catch (const std::out_of_range& e)
371 {
Tom Josephb70a1962020-07-13 12:56:31 +0530372 // If there is no mapping for tid, sensorId combination, try
373 // PLDM_TID_RESERVED, sensorId for terminus that is yet to
374 // implement TL PDR.
375 try
376 {
377 sensorEntry.terminusID = PLDM_TID_RESERVED;
378 std::tie(entityInfo, compositeSensorStates) =
379 hostPDRHandler->lookupSensorInfo(sensorEntry);
380 }
381 // If there is no mapping for events return PLDM_SUCCESS
382 catch (const std::out_of_range& e)
383 {
384 return PLDM_SUCCESS;
385 }
Zahed Hossain75330f32020-03-24 02:15:03 -0500386 }
Tom Josephb70a1962020-07-13 12:56:31 +0530387
388 if (sensorOffset >= compositeSensorStates.size())
389 {
390 return PLDM_ERROR_INVALID_DATA;
391 }
392
393 const auto& possibleStates = compositeSensorStates[sensorOffset];
394 if (possibleStates.find(eventState) == possibleStates.end())
395 {
396 return PLDM_ERROR_INVALID_DATA;
397 }
398
399 const auto& [containerId, entityType, entityInstance] = entityInfo;
400 events::StateSensorEntry stateSensorEntry{containerId, entityType,
401 entityInstance, sensorOffset};
402 return stateSensorHandler.eventAction(stateSensorEntry, eventState);
Tom Joseph56e45c52020-03-16 10:01:45 +0530403 }
404 else
405 {
406 return PLDM_ERROR_INVALID_DATA;
407 }
408
409 return PLDM_SUCCESS;
410}
411
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500412int Handler::pldmPDRRepositoryChgEvent(const pldm_msg* request,
413 size_t payloadLength,
414 uint8_t /*formatVersion*/,
415 uint8_t /*tid*/, size_t eventDataOffset)
416{
417 uint8_t eventDataFormat{};
418 uint8_t numberOfChangeRecords{};
419 size_t dataOffset{};
420
421 auto eventData =
422 reinterpret_cast<const uint8_t*>(request->payload) + eventDataOffset;
423 auto eventDataSize = payloadLength - eventDataOffset;
424
425 auto rc = decode_pldm_pdr_repository_chg_event_data(
426 eventData, eventDataSize, &eventDataFormat, &numberOfChangeRecords,
427 &dataOffset);
428 if (rc != PLDM_SUCCESS)
429 {
430 return rc;
431 }
432
433 PDRRecordHandles pdrRecordHandles;
Deepak Kodihalli7246e0c2020-07-08 06:40:18 -0500434
435 if (eventDataFormat == FORMAT_IS_PDR_TYPES)
436 {
437 return PLDM_ERROR_INVALID_DATA;
438 }
439
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500440 if (eventDataFormat == FORMAT_IS_PDR_HANDLES)
441 {
442 uint8_t eventDataOperation{};
443 uint8_t numberOfChangeEntries{};
444
445 auto changeRecordData = eventData + dataOffset;
446 auto changeRecordDataSize = eventDataSize - dataOffset;
447
448 while (changeRecordDataSize)
449 {
450 rc = decode_pldm_pdr_repository_change_record_data(
451 changeRecordData, changeRecordDataSize, &eventDataOperation,
452 &numberOfChangeEntries, &dataOffset);
453
454 if (rc != PLDM_SUCCESS)
455 {
456 return rc;
457 }
458
459 if (eventDataOperation == PLDM_RECORDS_ADDED)
460 {
461 rc = getPDRRecordHandles(
462 reinterpret_cast<const ChangeEntry*>(changeRecordData +
463 dataOffset),
464 changeRecordDataSize - dataOffset,
465 static_cast<size_t>(numberOfChangeEntries),
466 pdrRecordHandles);
467
468 if (rc != PLDM_SUCCESS)
469 {
470 return rc;
471 }
472 }
473
474 changeRecordData +=
475 dataOffset + (numberOfChangeEntries * sizeof(ChangeEntry));
476 changeRecordDataSize -=
477 dataOffset + (numberOfChangeEntries * sizeof(ChangeEntry));
478 }
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500479 }
Deepak Kodihalli7246e0c2020-07-08 06:40:18 -0500480 if (hostPDRHandler)
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500481 {
Deepak Kodihalli7246e0c2020-07-08 06:40:18 -0500482 hostPDRHandler->fetchPDR(std::move(pdrRecordHandles));
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500483 }
484
485 return PLDM_SUCCESS;
486}
487
488int Handler::getPDRRecordHandles(const ChangeEntry* changeEntryData,
489 size_t changeEntryDataSize,
490 size_t numberOfChangeEntries,
491 PDRRecordHandles& pdrRecordHandles)
492{
493 if (numberOfChangeEntries > (changeEntryDataSize / sizeof(ChangeEntry)))
494 {
495 return PLDM_ERROR_INVALID_DATA;
496 }
497 for (size_t i = 0; i < numberOfChangeEntries; i++)
498 {
499 pdrRecordHandles.push_back(changeEntryData[i]);
500 }
501 return PLDM_SUCCESS;
502}
503
George Liueccb0c52020-01-14 11:09:56 +0800504Response Handler::setNumericEffecterValue(const pldm_msg* request,
505 size_t payloadLength)
506{
507 Response response(sizeof(pldm_msg_hdr) +
508 PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES);
509 uint16_t effecterId{};
510 uint8_t effecterDataSize{};
511 uint8_t effecterValue[4] = {};
512
513 if ((payloadLength > sizeof(effecterId) + sizeof(effecterDataSize) +
514 sizeof(union_effecter_data_size)) ||
515 (payloadLength < sizeof(effecterId) + sizeof(effecterDataSize) + 1))
516 {
517 return ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH);
518 }
519
520 int rc = decode_set_numeric_effecter_value_req(
521 request, payloadLength, &effecterId, &effecterDataSize,
522 reinterpret_cast<uint8_t*>(&effecterValue));
523
524 if (rc == PLDM_SUCCESS)
525 {
526 const pldm::utils::DBusHandler dBusIntf;
527 rc = platform_numeric_effecter::setNumericEffecterValueHandler<
528 pldm::utils::DBusHandler, Handler>(dBusIntf, *this, effecterId,
529 effecterDataSize, effecterValue,
530 sizeof(effecterValue));
531 }
532
533 return ccOnlyResponse(request, rc);
534}
535
Sampa Misra12afe112020-05-25 11:40:44 -0500536void Handler::generateTerminusLocatorPDR(Repo& repo)
537{
538 std::vector<uint8_t> pdrBuffer(sizeof(pldm_terminus_locator_pdr));
539
540 auto pdr = reinterpret_cast<pldm_terminus_locator_pdr*>(pdrBuffer.data());
541
542 pdr->hdr.record_handle = 0;
543 pdr->hdr.version = 1;
544 pdr->hdr.type = PLDM_TERMINUS_LOCATOR_PDR;
545 pdr->hdr.record_change_num = 0;
546 pdr->hdr.length = sizeof(pldm_terminus_locator_pdr) - sizeof(pldm_pdr_hdr);
547 pdr->terminus_handle = BmcPldmTerminusHandle;
548 pdr->validity = PLDM_TL_PDR_VALID;
549 pdr->tid = BmcTerminusId;
550 pdr->container_id = 0x0;
551 pdr->terminus_locator_type = PLDM_TERMINUS_LOCATOR_TYPE_MCTP_EID;
552 pdr->terminus_locator_value_size =
553 sizeof(pldm_terminus_locator_type_mctp_eid);
554 auto locatorValue = reinterpret_cast<pldm_terminus_locator_type_mctp_eid*>(
555 pdr->terminus_locator_value);
556 locatorValue->eid = BmcMctpEid;
557
558 PdrEntry pdrEntry{};
559 pdrEntry.data = pdrBuffer.data();
560 pdrEntry.size = pdrBuffer.size();
561 repo.addRecord(pdrEntry);
562}
George Liu362c18d2020-05-14 09:46:36 +0800563
564Response Handler::getStateSensorReadings(const pldm_msg* request,
565 size_t payloadLength)
566{
567 uint16_t sensorId{};
568 bitfield8_t sensorRearm{};
569 uint8_t reserved{};
570
571 if (payloadLength != PLDM_GET_SENSOR_READING_REQ_BYTES)
572 {
573 return ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH);
574 }
575
576 int rc = decode_get_state_sensor_readings_req(
577 request, payloadLength, &sensorId, &sensorRearm, &reserved);
578
579 if (rc != PLDM_SUCCESS)
580 {
581 return ccOnlyResponse(request, rc);
582 }
583
584 // 0x01 to 0x08
585 uint8_t sensorRearmCout = getBitfieldCount(sensorRearm);
586 std::vector<get_sensor_state_field> stateField(sensorRearmCout);
587 uint8_t comSensorCnt{};
588 const pldm::utils::DBusHandler dBusIntf;
589 rc = platform_state_sensor::getStateSensorReadingsHandler<
590 pldm::utils::DBusHandler, Handler>(
591 dBusIntf, *this, sensorId, sensorRearmCout, comSensorCnt, stateField);
592
593 if (rc != PLDM_SUCCESS)
594 {
595 return ccOnlyResponse(request, rc);
596 }
597
598 Response response(sizeof(pldm_msg_hdr) +
599 PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES +
600 sizeof(get_sensor_state_field) * comSensorCnt);
601 auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
602 rc = encode_get_state_sensor_readings_resp(request->hdr.instance_id, rc,
603 comSensorCnt, stateField.data(),
604 responsePtr);
605 if (rc != PLDM_SUCCESS)
606 {
607 return ccOnlyResponse(request, rc);
608 }
609
610 return response;
611}
612
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600613} // namespace platform
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530614} // namespace responder
615} // namespace pldm