blob: 3a9266e2b9a43f088b188ba9d936a6f575ae66d2 [file] [log] [blame]
Deepak Kodihalli557dfb02019-05-12 13:11:17 +05301
2#include "platform.hpp"
3
Deepak Kodihallid130e1a2020-06-17 05:55:32 -05004#include "common/utils.hpp"
Tom Josephc4959c32020-04-20 19:50:16 +05305#include "event_parser.hpp"
Sampa Misra12afe112020-05-25 11:40:44 -05006#include "pdr.hpp"
George Liu456c9a22020-01-13 11:36:22 +08007#include "pdr_numeric_effecter.hpp"
George Liua2870722020-02-11 11:09:30 +08008#include "pdr_state_effecter.hpp"
George Liueccb0c52020-01-14 11:09:56 +08009#include "platform_numeric_effecter.hpp"
George Liu0d7aca82020-03-30 15:01:36 +080010#include "platform_state_effecter.hpp"
George Liu83409572019-12-24 18:42:54 +080011
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053012namespace pldm
13{
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053014namespace responder
15{
Sampa Misraa2fa0702019-05-31 01:28:55 -050016namespace platform
17{
18
Deepak Kodihallic682fe22020-03-04 00:42:54 -060019using InternalFailure =
20 sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
21
George Liu1ec85d42020-02-12 16:05:32 +080022static const Json empty{};
23
Zahed Hossain75330f32020-03-24 02:15:03 -050024using EventEntryMap = std::map<EventEntry, DBusInfo>;
25
26const EventEntryMap eventEntryMap = {
27 {
28 0x01010007, // SensorID for VMI Port 0 ipv4 = 7, SensorOffset for the
29 // State Set ID 15 = 1 & PLDM State Set Enumeration List = 1
30 // (Valid Configuration)
Tom Joseph15bff552020-06-30 15:57:08 +053031 {"/xyz/openbmc_project/network/hypervisor/eth0/ipv4/addr0",
Zahed Hossain75330f32020-03-24 02:15:03 -050032 "xyz.openbmc_project.Object.Enable", "Enabled", "bool", true},
33 },
34 {
35 0x02010007, // SensorID for VMI Port 0 ipv4 = 7, SensorOffset for the
36 // State Set ID 15 = 1 & PLDM State Set Enumeration List = 2
37 // (Invalid Configuration)
Tom Joseph15bff552020-06-30 15:57:08 +053038 {"/xyz/openbmc_project/network/hypervisor/eth0/ipv4/addr0",
Zahed Hossain75330f32020-03-24 02:15:03 -050039 "xyz.openbmc_project.Object.Enable", "Enabled", "bool", false},
40 },
41 {
42 0x01010008, // SensorID for VMI Port 1 ipv4 = 8, SensorOffset for the
43 // State Set ID 15 = 1 & PLDM State Set Enumeration List = 1
44 // (Valid Configuration)
Tom Joseph15bff552020-06-30 15:57:08 +053045 {"/xyz/openbmc_project/network/hypervisor/eth1/ipv4/addr0",
Zahed Hossain75330f32020-03-24 02:15:03 -050046 "xyz.openbmc_project.Object.Enable", "Enabled", "bool", true},
47 },
48 {
49 0x02010008, // SensorID for VMI Port 1 ipv4 = 8, SensorOffset for the
50 // State Set ID 15 = 1 & PLDM State Set Enumeration List = 2
51 // (Invalid Configuration)
Tom Joseph15bff552020-06-30 15:57:08 +053052 {"/xyz/openbmc_project/network/hypervisor/eth1/ipv4/addr0",
Zahed Hossain75330f32020-03-24 02:15:03 -050053 "xyz.openbmc_project.Object.Enable", "Enabled", "bool", false},
54 }};
55
George Liua2870722020-02-11 11:09:30 +080056void Handler::addDbusObjMaps(
57 uint16_t effecterId,
58 std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps> dbusObj)
George Liu1ec85d42020-02-12 16:05:32 +080059{
60 dbusObjMaps.emplace(effecterId, dbusObj);
61}
62
George Liua2870722020-02-11 11:09:30 +080063const std::tuple<pdr_utils::DbusMappings, pdr_utils::DbusValMaps>&
George Liu1ec85d42020-02-12 16:05:32 +080064 Handler::getDbusObjMaps(uint16_t effecterId) const
65{
66 return dbusObjMaps.at(effecterId);
67}
68
George Liu36e81352020-07-01 14:40:30 +080069void Handler::generate(const pldm::utils::DBusHandler& dBusIntf,
70 const std::string& dir, Repo& repo)
Deepak Kodihallic682fe22020-03-04 00:42:54 -060071{
Deepak Kodihallic6e49c42020-07-01 03:39:27 -050072 if (!fs::exists(dir))
73 {
74 return;
75 }
76
Deepak Kodihallic682fe22020-03-04 00:42:54 -060077 // A map of PDR type to a lambda that handles creation of that PDR type.
78 // The lambda essentially would parse the platform specific PDR JSONs to
79 // generate the PDR structures. This function iterates through the map to
80 // invoke all lambdas, so that all PDR types can be created.
George Liua2870722020-02-11 11:09:30 +080081
82 const std::map<Type, generatePDR> generateHandlers = {
83 {PLDM_STATE_EFFECTER_PDR,
George Liu36e81352020-07-01 14:40:30 +080084 [this](const DBusHandler& dBusIntf, const auto& json,
85 RepoInterface& repo) {
86 pdr_state_effecter::generateStateEffecterPDR<
87 pldm::utils::DBusHandler, Handler>(dBusIntf, json, *this,
88 repo);
George Liu456c9a22020-01-13 11:36:22 +080089 }},
90 {PLDM_NUMERIC_EFFECTER_PDR,
George Liu36e81352020-07-01 14:40:30 +080091 [this](const DBusHandler& dBusIntf, const auto& json,
92 RepoInterface& repo) {
93 pdr_numeric_effecter::generateNumericEffecterPDR<
94 pldm::utils::DBusHandler, Handler>(dBusIntf, json, *this,
95 repo);
George Liua2870722020-02-11 11:09:30 +080096 }}};
Deepak Kodihallic682fe22020-03-04 00:42:54 -060097
98 Type pdrType{};
99 for (const auto& dirEntry : fs::directory_iterator(dir))
100 {
101 try
102 {
103 auto json = readJson(dirEntry.path().string());
104 if (!json.empty())
105 {
George Liu1ec85d42020-02-12 16:05:32 +0800106 auto effecterPDRs = json.value("effecterPDRs", empty);
107 for (const auto& effecter : effecterPDRs)
108 {
109 pdrType = effecter.value("pdrType", 0);
George Liu36e81352020-07-01 14:40:30 +0800110 generateHandlers.at(pdrType)(dBusIntf, effecter, repo);
George Liu1ec85d42020-02-12 16:05:32 +0800111 }
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{
Deepak Kodihallib5c227e2020-07-13 06:58:34 -0500139 if (!pdrCreated)
140 {
Sampa Misra12afe112020-05-25 11:40:44 -0500141 generateTerminusLocatorPDR(pdrRepo);
Deepak Kodihallib5c227e2020-07-13 06:58:34 -0500142 generate(*dBusIntf, pdrJsonsDir, pdrRepo);
143 pdrCreated = true;
144 }
145
Tom Joseph33e9c7e2020-06-11 22:09:52 +0530146 // Build FRU table if not built, since entity association PDR's are built
147 // when the FRU table is constructed.
148 if (fruHandler)
149 {
150 fruHandler->buildFRUTable();
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 // Handle PLDM events for which PDR is not available, setSensorEventData
354 // will return PLDM_ERROR_INVALID_DATA if the sensorID is not found in
355 // the hardcoded sensor list.
Zahed Hossain75330f32020-03-24 02:15:03 -0500356 rc = setSensorEventData(sensorId, sensorOffset, eventState);
Tom Josephc4959c32020-04-20 19:50:16 +0530357 if (rc != PLDM_ERROR_INVALID_DATA)
Zahed Hossain75330f32020-03-24 02:15:03 -0500358 {
Tom Josephc4959c32020-04-20 19:50:16 +0530359 return rc;
360 }
361
362 // If there are no HOST PDR's, there is no further action
363 if (hostPDRHandler == NULL)
364 {
365 return PLDM_SUCCESS;
366 }
367
368 // Handle PLDM events for which PDR is available
369 SensorEntry sensorEntry{tid, sensorId};
370 try
371 {
372 const auto& [entityInfo, compositeSensorStates] =
373 hostPDRHandler->lookupSensorInfo(sensorEntry);
374 if (sensorOffset >= compositeSensorStates.size())
375 {
376 return PLDM_ERROR_INVALID_DATA;
377 }
378
379 const auto& possibleStates = compositeSensorStates[sensorOffset];
380 if (possibleStates.find(eventState) == possibleStates.end())
381 {
382 return PLDM_ERROR_INVALID_DATA;
383 }
384
385 const auto& [containerId, entityType, entityInstance] = entityInfo;
386 events::StateSensorEntry stateSensorEntry{
387 containerId, entityType, entityInstance, sensorOffset};
388 return stateSensorHandler.eventAction(stateSensorEntry, eventState);
389 }
390 // If there is no mapping for events return PLDM_SUCCESS
391 catch (const std::out_of_range& e)
392 {
393 return PLDM_SUCCESS;
Zahed Hossain75330f32020-03-24 02:15:03 -0500394 }
Tom Joseph56e45c52020-03-16 10:01:45 +0530395 }
396 else
397 {
398 return PLDM_ERROR_INVALID_DATA;
399 }
400
401 return PLDM_SUCCESS;
402}
403
Zahed Hossain75330f32020-03-24 02:15:03 -0500404int Handler::setSensorEventData(uint16_t sensorId, uint8_t sensorOffset,
405 uint8_t eventState)
406{
407 EventEntry eventEntry = ((static_cast<uint32_t>(eventState)) << 24) +
408 ((static_cast<uint32_t>(sensorOffset)) << 16) +
409 sensorId;
410 auto iter = eventEntryMap.find(eventEntry);
411 if (iter == eventEntryMap.end())
412 {
Tom Josephc4959c32020-04-20 19:50:16 +0530413 return PLDM_ERROR_INVALID_DATA;
Zahed Hossain75330f32020-03-24 02:15:03 -0500414 }
415
416 const auto& dBusInfo = iter->second;
417 try
418 {
419 pldm::utils::DBusMapping dbusMapping{
420 dBusInfo.dBusValues.objectPath, dBusInfo.dBusValues.interface,
421 dBusInfo.dBusValues.propertyName, dBusInfo.dBusValues.propertyType};
422 pldm::utils::DBusHandler().setDbusProperty(dbusMapping,
423 dBusInfo.dBusPropertyValue);
424 }
425 catch (std::exception& e)
426 {
Zahed Hossain75330f32020-03-24 02:15:03 -0500427 std::cerr
428 << "Error Setting dbus property,SensorID=" << eventEntry
429 << "DBusInfo=" << dBusInfo.dBusValues.objectPath
430 << dBusInfo.dBusValues.interface << dBusInfo.dBusValues.propertyName
431 << "ERROR=" << e.what() << "\n";
432 return PLDM_ERROR;
433 }
434 return PLDM_SUCCESS;
435}
436
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500437int Handler::pldmPDRRepositoryChgEvent(const pldm_msg* request,
438 size_t payloadLength,
439 uint8_t /*formatVersion*/,
440 uint8_t /*tid*/, size_t eventDataOffset)
441{
442 uint8_t eventDataFormat{};
443 uint8_t numberOfChangeRecords{};
444 size_t dataOffset{};
445
446 auto eventData =
447 reinterpret_cast<const uint8_t*>(request->payload) + eventDataOffset;
448 auto eventDataSize = payloadLength - eventDataOffset;
449
450 auto rc = decode_pldm_pdr_repository_chg_event_data(
451 eventData, eventDataSize, &eventDataFormat, &numberOfChangeRecords,
452 &dataOffset);
453 if (rc != PLDM_SUCCESS)
454 {
455 return rc;
456 }
457
458 PDRRecordHandles pdrRecordHandles;
Deepak Kodihalli7246e0c2020-07-08 06:40:18 -0500459
460 if (eventDataFormat == FORMAT_IS_PDR_TYPES)
461 {
462 return PLDM_ERROR_INVALID_DATA;
463 }
464
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500465 if (eventDataFormat == FORMAT_IS_PDR_HANDLES)
466 {
467 uint8_t eventDataOperation{};
468 uint8_t numberOfChangeEntries{};
469
470 auto changeRecordData = eventData + dataOffset;
471 auto changeRecordDataSize = eventDataSize - dataOffset;
472
473 while (changeRecordDataSize)
474 {
475 rc = decode_pldm_pdr_repository_change_record_data(
476 changeRecordData, changeRecordDataSize, &eventDataOperation,
477 &numberOfChangeEntries, &dataOffset);
478
479 if (rc != PLDM_SUCCESS)
480 {
481 return rc;
482 }
483
484 if (eventDataOperation == PLDM_RECORDS_ADDED)
485 {
486 rc = getPDRRecordHandles(
487 reinterpret_cast<const ChangeEntry*>(changeRecordData +
488 dataOffset),
489 changeRecordDataSize - dataOffset,
490 static_cast<size_t>(numberOfChangeEntries),
491 pdrRecordHandles);
492
493 if (rc != PLDM_SUCCESS)
494 {
495 return rc;
496 }
497 }
498
499 changeRecordData +=
500 dataOffset + (numberOfChangeEntries * sizeof(ChangeEntry));
501 changeRecordDataSize -=
502 dataOffset + (numberOfChangeEntries * sizeof(ChangeEntry));
503 }
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500504 }
Deepak Kodihalli7246e0c2020-07-08 06:40:18 -0500505 if (hostPDRHandler)
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500506 {
Deepak Kodihalli7246e0c2020-07-08 06:40:18 -0500507 hostPDRHandler->fetchPDR(std::move(pdrRecordHandles));
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500508 }
509
510 return PLDM_SUCCESS;
511}
512
513int Handler::getPDRRecordHandles(const ChangeEntry* changeEntryData,
514 size_t changeEntryDataSize,
515 size_t numberOfChangeEntries,
516 PDRRecordHandles& pdrRecordHandles)
517{
518 if (numberOfChangeEntries > (changeEntryDataSize / sizeof(ChangeEntry)))
519 {
520 return PLDM_ERROR_INVALID_DATA;
521 }
522 for (size_t i = 0; i < numberOfChangeEntries; i++)
523 {
524 pdrRecordHandles.push_back(changeEntryData[i]);
525 }
526 return PLDM_SUCCESS;
527}
528
George Liueccb0c52020-01-14 11:09:56 +0800529Response Handler::setNumericEffecterValue(const pldm_msg* request,
530 size_t payloadLength)
531{
532 Response response(sizeof(pldm_msg_hdr) +
533 PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES);
534 uint16_t effecterId{};
535 uint8_t effecterDataSize{};
536 uint8_t effecterValue[4] = {};
537
538 if ((payloadLength > sizeof(effecterId) + sizeof(effecterDataSize) +
539 sizeof(union_effecter_data_size)) ||
540 (payloadLength < sizeof(effecterId) + sizeof(effecterDataSize) + 1))
541 {
542 return ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH);
543 }
544
545 int rc = decode_set_numeric_effecter_value_req(
546 request, payloadLength, &effecterId, &effecterDataSize,
547 reinterpret_cast<uint8_t*>(&effecterValue));
548
549 if (rc == PLDM_SUCCESS)
550 {
551 const pldm::utils::DBusHandler dBusIntf;
552 rc = platform_numeric_effecter::setNumericEffecterValueHandler<
553 pldm::utils::DBusHandler, Handler>(dBusIntf, *this, effecterId,
554 effecterDataSize, effecterValue,
555 sizeof(effecterValue));
556 }
557
558 return ccOnlyResponse(request, rc);
559}
560
Sampa Misra12afe112020-05-25 11:40:44 -0500561void Handler::generateTerminusLocatorPDR(Repo& repo)
562{
563 std::vector<uint8_t> pdrBuffer(sizeof(pldm_terminus_locator_pdr));
564
565 auto pdr = reinterpret_cast<pldm_terminus_locator_pdr*>(pdrBuffer.data());
566
567 pdr->hdr.record_handle = 0;
568 pdr->hdr.version = 1;
569 pdr->hdr.type = PLDM_TERMINUS_LOCATOR_PDR;
570 pdr->hdr.record_change_num = 0;
571 pdr->hdr.length = sizeof(pldm_terminus_locator_pdr) - sizeof(pldm_pdr_hdr);
572 pdr->terminus_handle = BmcPldmTerminusHandle;
573 pdr->validity = PLDM_TL_PDR_VALID;
574 pdr->tid = BmcTerminusId;
575 pdr->container_id = 0x0;
576 pdr->terminus_locator_type = PLDM_TERMINUS_LOCATOR_TYPE_MCTP_EID;
577 pdr->terminus_locator_value_size =
578 sizeof(pldm_terminus_locator_type_mctp_eid);
579 auto locatorValue = reinterpret_cast<pldm_terminus_locator_type_mctp_eid*>(
580 pdr->terminus_locator_value);
581 locatorValue->eid = BmcMctpEid;
582
583 PdrEntry pdrEntry{};
584 pdrEntry.data = pdrBuffer.data();
585 pdrEntry.size = pdrBuffer.size();
586 repo.addRecord(pdrEntry);
587}
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600588} // namespace platform
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530589} // namespace responder
590} // namespace pldm