blob: a786ed409b8b5ba1c0c28f01b96058d27e2c1ec3 [file] [log] [blame]
Deepak Kodihalli87514cc2020-04-16 09:08:38 -05001#include "config.h"
2
Pavithra Barithaya51efaf82020-04-02 02:42:27 -05003#include "host_pdr_handler.hpp"
4
George Liu6492f522020-06-16 10:34:05 +08005#include "libpldm/requester/pldm.h"
6
Pavithra Barithayae8beb892020-04-14 23:24:25 -05007#include <assert.h>
8
Deepak Kodihalli87514cc2020-04-16 09:08:38 -05009#include <nlohmann/json.hpp>
sampmisr6decfc12021-03-02 11:07:36 +053010#include <sdeventplus/clock.hpp>
11#include <sdeventplus/exception.hpp>
12#include <sdeventplus/source/io.hpp>
13#include <sdeventplus/source/time.hpp>
Deepak Kodihalli87514cc2020-04-16 09:08:38 -050014
George Liu6492f522020-06-16 10:34:05 +080015#include <fstream>
Pavithra Barithaya51efaf82020-04-02 02:42:27 -050016
17namespace pldm
18{
19
Deepak Kodihalli6b1d1ca2020-04-27 07:24:51 -050020using namespace pldm::utils;
21using namespace sdbusplus::bus::match::rules;
Deepak Kodihalli87514cc2020-04-16 09:08:38 -050022using Json = nlohmann::json;
23namespace fs = std::filesystem;
24constexpr auto fruJson = "host_frus.json";
25const Json emptyJson{};
26const std::vector<Json> emptyJsonList{};
27
Tom Joseph74f27c72021-05-16 07:58:53 -070028HostPDRHandler::HostPDRHandler(
29 int mctp_fd, uint8_t mctp_eid, sdeventplus::Event& event, pldm_pdr* repo,
30 const std::string& eventsJsonsDir, pldm_entity_association_tree* entityTree,
31 pldm_entity_association_tree* bmcEntityTree, Requester& requester,
Sampa Misrac0c79482021-06-02 08:01:54 -050032 pldm::requester::Handler<pldm::requester::Request>* handler, bool verbose) :
Deepak Kodihalli87514cc2020-04-16 09:08:38 -050033 mctp_fd(mctp_fd),
Pavithra Barithaya3aec9972020-12-14 01:55:44 -060034 mctp_eid(mctp_eid), event(event), repo(repo),
35 stateSensorHandler(eventsJsonsDir), entityTree(entityTree),
Tom Joseph74f27c72021-05-16 07:58:53 -070036 bmcEntityTree(bmcEntityTree), requester(requester), handler(handler),
37 verbose(verbose)
Deepak Kodihalli87514cc2020-04-16 09:08:38 -050038{
39 fs::path hostFruJson(fs::path(HOST_JSONS_DIR) / fruJson);
40 if (fs::exists(hostFruJson))
41 {
Pavithra Barithayae8beb892020-04-14 23:24:25 -050042 // Note parent entities for entities sent down by the host firmware.
43 // This will enable a merge of entity associations.
Deepak Kodihalli87514cc2020-04-16 09:08:38 -050044 try
45 {
46 std::ifstream jsonFile(hostFruJson);
47 auto data = Json::parse(jsonFile, nullptr, false);
48 if (data.is_discarded())
49 {
50 std::cerr << "Parsing Host FRU json file failed" << std::endl;
51 }
52 else
53 {
54 auto entities = data.value("entities", emptyJsonList);
55 for (auto& entity : entities)
56 {
57 EntityType entityType = entity.value("entity_type", 0);
58 auto parent = entity.value("parent", emptyJson);
59 pldm_entity p{};
60 p.entity_type = parent.value("entity_type", 0);
61 p.entity_instance_num = parent.value("entity_instance", 0);
62 parents.emplace(entityType, std::move(p));
63 }
64 }
65 }
66 catch (const std::exception& e)
67 {
68 std::cerr << "Parsing Host FRU json file failed, exception = "
69 << e.what() << std::endl;
70 }
71 }
Deepak Kodihalli6b1d1ca2020-04-27 07:24:51 -050072
73 hostOffMatch = std::make_unique<sdbusplus::bus::match::match>(
74 pldm::utils::DBusHandler::getBus(),
75 propertiesChanged("/xyz/openbmc_project/state/host0",
76 "xyz.openbmc_project.State.Host"),
Sampa Misrac073a202021-05-08 10:56:05 -050077 [this, repo, entityTree,
78 bmcEntityTree](sdbusplus::message::message& msg) {
Deepak Kodihalli6b1d1ca2020-04-27 07:24:51 -050079 DbusChangedProps props{};
80 std::string intf;
81 msg.read(intf, props);
82 const auto itr = props.find("CurrentHostState");
83 if (itr != props.end())
84 {
85 PropertyValue value = itr->second;
86 auto propVal = std::get<std::string>(value);
87 if (propVal == "xyz.openbmc_project.State.Host.HostState.Off")
88 {
89 pldm_pdr_remove_remote_pdrs(repo);
Sampa Misrac073a202021-05-08 10:56:05 -050090 pldm_entity_association_tree_destroy_root(entityTree);
91 pldm_entity_association_tree_copy_root(bmcEntityTree,
92 entityTree);
Tom Josephb4268602020-04-17 17:20:45 +053093 this->sensorMap.clear();
Deepak Kodihalli6b1d1ca2020-04-27 07:24:51 -050094 }
95 }
96 });
Deepak Kodihalli87514cc2020-04-16 09:08:38 -050097}
98
Deepak Kodihalli7246e0c2020-07-08 06:40:18 -050099void HostPDRHandler::fetchPDR(PDRRecordHandles&& recordHandles)
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500100{
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500101 pdrRecordHandles.clear();
102 pdrRecordHandles = std::move(recordHandles);
103
104 // Defer the actual fetch of PDRs from the host (by queuing the call on the
105 // main event loop). That way, we can respond to the platform event msg from
106 // the host firmware.
107 pdrFetchEvent = std::make_unique<sdeventplus::source::Defer>(
108 event, std::bind(std::mem_fn(&HostPDRHandler::_fetchPDR), this,
109 std::placeholders::_1));
110}
111
112void HostPDRHandler::_fetchPDR(sdeventplus::source::EventBase& /*source*/)
113{
Sampa Misrac0c79482021-06-02 08:01:54 -0500114 getHostPDR();
115}
116
117void HostPDRHandler::getHostPDR(uint32_t nextRecordHandle)
118{
Deepak Kodihalli8cb6f662020-04-10 02:55:43 -0500119 pdrFetchEvent.reset();
120
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500121 std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) +
122 PLDM_GET_PDR_REQ_BYTES);
123 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
Deepak Kodihalli7246e0c2020-07-08 06:40:18 -0500124 uint32_t recordHandle{};
Sampa Misrac0c79482021-06-02 08:01:54 -0500125 if (!nextRecordHandle)
Deepak Kodihalli7246e0c2020-07-08 06:40:18 -0500126 {
Sampa Misrac0c79482021-06-02 08:01:54 -0500127 if (!pdrRecordHandles.empty())
128 {
129 recordHandle = pdrRecordHandles.front();
130 pdrRecordHandles.pop_front();
131 }
132 }
133 else
134 {
135 recordHandle = nextRecordHandle;
136 }
137 auto instanceId = requester.getInstanceId(mctp_eid);
138
139 auto rc =
140 encode_get_pdr_req(instanceId, recordHandle, 0, PLDM_GET_FIRSTPART,
141 UINT16_MAX, 0, request, PLDM_GET_PDR_REQ_BYTES);
142 if (rc != PLDM_SUCCESS)
143 {
144 requester.markFree(mctp_eid, instanceId);
145 std::cerr << "Failed to encode_get_pdr_req, rc = " << rc << std::endl;
146 return;
147 }
148 if (verbose)
149 {
150 std::cout << "Sending Msg:" << std::endl;
151 printBuffer(requestMsg, verbose);
Deepak Kodihalli7246e0c2020-07-08 06:40:18 -0500152 }
153
Sampa Misrac0c79482021-06-02 08:01:54 -0500154 rc = handler->registerRequest(
155 mctp_eid, instanceId, PLDM_PLATFORM, PLDM_GET_PDR,
156 std::move(requestMsg),
157 std::move(std::bind_front(&HostPDRHandler::processHostPDRs, this)));
158 if (rc)
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500159 {
Sampa Misrac0c79482021-06-02 08:01:54 -0500160 std::cerr << "Failed to send the GetPDR request to Host \n";
Pavithra Barithayae8beb892020-04-14 23:24:25 -0500161 }
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500162}
163
Pavithra Barithaya3aec9972020-12-14 01:55:44 -0600164int HostPDRHandler::handleStateSensorEvent(const StateSensorEntry& entry,
165 pdr::EventState state)
166{
167 auto rc = stateSensorHandler.eventAction(entry, state);
168 if (rc != PLDM_SUCCESS)
169 {
170 std::cerr << "Failed to fetch and update D-bus property, rc = " << rc
171 << std::endl;
172 return rc;
173 }
174 return PLDM_SUCCESS;
175}
Deepak Kodihalli87514cc2020-04-16 09:08:38 -0500176bool HostPDRHandler::getParent(EntityType type, pldm_entity& parent)
177{
178 auto found = parents.find(type);
179 if (found != parents.end())
180 {
181 parent.entity_type = found->second.entity_type;
182 parent.entity_instance_num = found->second.entity_instance_num;
183 return true;
184 }
185
186 return false;
187}
188
189void HostPDRHandler::mergeEntityAssociations(const std::vector<uint8_t>& pdr)
190{
191 size_t numEntities{};
192 pldm_entity* entities = nullptr;
193 bool merged = false;
194 auto entityPdr = reinterpret_cast<pldm_pdr_entity_association*>(
195 const_cast<uint8_t*>(pdr.data()) + sizeof(pldm_pdr_hdr));
196
197 pldm_entity_association_pdr_extract(pdr.data(), pdr.size(), &numEntities,
198 &entities);
199 for (size_t i = 0; i < numEntities; ++i)
200 {
201 pldm_entity parent{};
202 if (getParent(entities[i].entity_type, parent))
203 {
204 auto node = pldm_entity_association_tree_find(entityTree, &parent);
205 if (node)
206 {
George Liu64a8f0f2021-06-12 10:56:11 +0800207 pldm_entity_association_tree_add(entityTree, &entities[i],
208 0xFFFF, node,
Deepak Kodihalli87514cc2020-04-16 09:08:38 -0500209 entityPdr->association_type);
210 merged = true;
211 }
212 }
213 }
Deepak Kodihalli87514cc2020-04-16 09:08:38 -0500214
215 if (merged)
216 {
Pavithra Barithayae8beb892020-04-14 23:24:25 -0500217 // Update our PDR repo with the merged entity association PDRs
Sampa Misra719ed392021-06-04 05:15:13 -0500218 pldm_entity_node* node = nullptr;
219 pldm_find_entity_ref_in_tree(entityTree, entities[0], &node);
220 if (node == nullptr)
221 {
222 std::cerr
223 << "\ncould not find referrence of the entity in the tree \n";
224 }
225 else
226 {
227 pldm_entity_association_pdr_add_from_node(node, repo, &entities,
228 numEntities, true);
229 }
Deepak Kodihalli87514cc2020-04-16 09:08:38 -0500230 }
Sampa Misra719ed392021-06-04 05:15:13 -0500231 free(entities);
Deepak Kodihalli87514cc2020-04-16 09:08:38 -0500232}
233
Pavithra Barithayae8beb892020-04-14 23:24:25 -0500234void HostPDRHandler::sendPDRRepositoryChgEvent(std::vector<uint8_t>&& pdrTypes,
235 uint8_t eventDataFormat)
236{
237 assert(eventDataFormat == FORMAT_IS_PDR_HANDLES);
238
239 // Extract from the PDR repo record handles of PDRs we want the host
240 // to pull up.
241 std::vector<uint8_t> eventDataOps{PLDM_RECORDS_ADDED};
242 std::vector<uint8_t> numsOfChangeEntries(1);
243 std::vector<std::vector<ChangeEntry>> changeEntries(
244 numsOfChangeEntries.size());
245 for (auto pdrType : pdrTypes)
246 {
247 const pldm_pdr_record* record{};
248 do
249 {
250 record = pldm_pdr_find_record_by_type(repo, pdrType, record,
251 nullptr, nullptr);
252 if (record && pldm_pdr_record_is_remote(record))
253 {
254 changeEntries[0].push_back(
255 pldm_pdr_get_record_handle(repo, record));
256 }
257 } while (record);
258 }
259 if (changeEntries.empty())
260 {
261 return;
262 }
263 numsOfChangeEntries[0] = changeEntries[0].size();
264
265 // Encode PLDM platform event msg to indicate a PDR repo change.
266 size_t maxSize = PLDM_PDR_REPOSITORY_CHG_EVENT_MIN_LENGTH +
267 PLDM_PDR_REPOSITORY_CHANGE_RECORD_MIN_LENGTH +
268 changeEntries[0].size() * sizeof(uint32_t);
269 std::vector<uint8_t> eventDataVec{};
270 eventDataVec.resize(maxSize);
271 auto eventData =
272 reinterpret_cast<struct pldm_pdr_repository_chg_event_data*>(
273 eventDataVec.data());
274 size_t actualSize{};
275 auto firstEntry = changeEntries[0].data();
276 auto rc = encode_pldm_pdr_repository_chg_event_data(
277 eventDataFormat, 1, eventDataOps.data(), numsOfChangeEntries.data(),
278 &firstEntry, eventData, &actualSize, maxSize);
279 if (rc != PLDM_SUCCESS)
280 {
281 std::cerr
282 << "Failed to encode_pldm_pdr_repository_chg_event_data, rc = "
283 << rc << std::endl;
284 return;
285 }
286 auto instanceId = requester.getInstanceId(mctp_eid);
287 std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) +
288 PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES +
289 actualSize);
290 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
291 rc = encode_platform_event_message_req(
292 instanceId, 1, 0, PLDM_PDR_REPOSITORY_CHG_EVENT, eventDataVec.data(),
Christian Geddes3bdb3c22020-05-01 14:55:39 -0500293 actualSize, request,
294 actualSize + PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES);
Pavithra Barithayae8beb892020-04-14 23:24:25 -0500295 if (rc != PLDM_SUCCESS)
296 {
297 requester.markFree(mctp_eid, instanceId);
298 std::cerr << "Failed to encode_platform_event_message_req, rc = " << rc
299 << std::endl;
300 return;
301 }
302
Tom Joseph74f27c72021-05-16 07:58:53 -0700303 auto platformEventMessageResponseHandler = [](mctp_eid_t /*eid*/,
304 const pldm_msg* response,
305 size_t respMsgLen) {
306 if (response == nullptr || !respMsgLen)
307 {
308 std::cerr << "Failed to receive response for the PDR repository "
309 "changed event"
310 << "\n";
311 return;
312 }
313
314 uint8_t completionCode{};
315 uint8_t status{};
316 auto responsePtr = reinterpret_cast<const struct pldm_msg*>(response);
317 auto rc = decode_platform_event_message_resp(
318 responsePtr, respMsgLen - sizeof(pldm_msg_hdr), &completionCode,
319 &status);
Sampa Misrac0c79482021-06-02 08:01:54 -0500320 if (rc || completionCode)
Tom Joseph74f27c72021-05-16 07:58:53 -0700321 {
322 std::cerr << "Failed to decode_platform_event_message_resp: "
323 << "rc=" << rc
324 << ", cc=" << static_cast<unsigned>(completionCode)
325 << std::endl;
326 }
327 };
328
Sampa Misrac0c79482021-06-02 08:01:54 -0500329 rc = handler->registerRequest(
Tom Joseph74f27c72021-05-16 07:58:53 -0700330 mctp_eid, instanceId, PLDM_PLATFORM, PLDM_PDR_REPOSITORY_CHG_EVENT,
331 std::move(requestMsg), std::move(platformEventMessageResponseHandler));
Sampa Misrac0c79482021-06-02 08:01:54 -0500332 if (rc)
Pavithra Barithayae8beb892020-04-14 23:24:25 -0500333 {
Tom Joseph74f27c72021-05-16 07:58:53 -0700334 std::cerr << "Failed to send the PDR repository changed event request"
335 << "\n";
Pavithra Barithayae8beb892020-04-14 23:24:25 -0500336 }
337}
338
Sampa Misra868c8792020-05-26 03:12:13 -0500339void HostPDRHandler::parseStateSensorPDRs(const PDRList& stateSensorPDRs,
340 const TLPDRMap& tlpdrInfo)
341{
342 for (const auto& pdr : stateSensorPDRs)
343 {
344 SensorEntry sensorEntry{};
345 const auto& [terminusHandle, sensorID, sensorInfo] =
346 responder::pdr_utils::parseStateSensorPDR(pdr);
347 sensorEntry.sensorID = sensorID;
348 try
349 {
350 sensorEntry.terminusID = tlpdrInfo.at(terminusHandle);
351 }
352 // If there is no mapping for terminusHandle assign the reserved TID
353 // value of 0xFF to indicate that.
354 catch (const std::out_of_range& e)
355 {
356 sensorEntry.terminusID = PLDM_TID_RESERVED;
357 }
358 sensorMap.emplace(sensorEntry, std::move(sensorInfo));
359 }
360}
361
Sampa Misrac0c79482021-06-02 08:01:54 -0500362void HostPDRHandler::processHostPDRs(mctp_eid_t /*eid*/,
363 const pldm_msg* response,
364 size_t respMsgLen)
365{
366 static bool merged = false;
367 static PDRList stateSensorPDRs{};
368 static TLPDRMap tlpdrInfo{};
369 uint32_t nextRecordHandle{};
370 uint8_t completionCode{};
371 uint32_t nextDataTransferHandle{};
372 uint8_t transferFlag{};
373 uint16_t respCount{};
374 uint8_t transferCRC{};
375 if (response == nullptr || !respMsgLen)
376 {
377 std::cerr << "Failed to receive response for the GetPDR"
378 " command \n";
379 return;
380 }
381
382 auto rc = decode_get_pdr_resp(
383 response, respMsgLen /*- sizeof(pldm_msg_hdr)*/, &completionCode,
384 &nextRecordHandle, &nextDataTransferHandle, &transferFlag, &respCount,
385 nullptr, 0, &transferCRC);
386 std::vector<uint8_t> responsePDRMsg;
387 responsePDRMsg.resize(respMsgLen + sizeof(pldm_msg_hdr));
388 memcpy(responsePDRMsg.data(), response, respMsgLen + sizeof(pldm_msg_hdr));
389 if (verbose)
390 {
391 std::cout << "Receiving Msg:" << std::endl;
392 printBuffer(responsePDRMsg, verbose);
393 }
394 if (rc != PLDM_SUCCESS)
395 {
396 std::cerr << "Failed to decode_get_pdr_resp, rc = " << rc << std::endl;
397 return;
398 }
399 else
400 {
401 std::vector<uint8_t> pdr(respCount, 0);
402 rc = decode_get_pdr_resp(response, respMsgLen, &completionCode,
403 &nextRecordHandle, &nextDataTransferHandle,
404 &transferFlag, &respCount, pdr.data(),
405 respCount, &transferCRC);
406 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
407 {
408 std::cerr << "Failed to decode_get_pdr_resp: "
409 << "rc=" << rc
410 << ", cc=" << static_cast<unsigned>(completionCode)
411 << std::endl;
412 return;
413 }
414 else
415 {
416 auto pdrHdr = reinterpret_cast<pldm_pdr_hdr*>(pdr.data());
417 if (pdrHdr->type == PLDM_PDR_ENTITY_ASSOCIATION)
418 {
419 this->mergeEntityAssociations(pdr);
420 merged = true;
421 }
422 else
423 {
424 if (pdrHdr->type == PLDM_TERMINUS_LOCATOR_PDR)
425 {
426 auto tlpdr =
427 reinterpret_cast<const pldm_terminus_locator_pdr*>(
428 pdr.data());
429 tlpdrInfo.emplace(
430 static_cast<pldm::pdr::TerminusHandle>(
431 tlpdr->terminus_handle),
432 static_cast<pldm::pdr::TerminusID>(tlpdr->tid));
433 }
434 else if (pdrHdr->type == PLDM_STATE_SENSOR_PDR)
435 {
436 stateSensorPDRs.emplace_back(pdr);
437 }
438 pldm_pdr_add(repo, pdr.data(), respCount, 0, true);
439 }
440 }
441 }
442 if (!nextRecordHandle)
443 {
444 /*received last record*/
445 this->parseStateSensorPDRs(stateSensorPDRs, tlpdrInfo);
446 stateSensorPDRs.clear();
447 tlpdrInfo.clear();
448 if (merged)
449 {
450 merged = false;
451 deferredPDRRepoChgEvent =
452 std::make_unique<sdeventplus::source::Defer>(
453 event,
454 std::bind(
455 std::mem_fn((&HostPDRHandler::_processPDRRepoChgEvent)),
456 this, std::placeholders::_1));
457 }
458 }
459 else
460 {
461 deferredFetchPDREvent = std::make_unique<sdeventplus::source::Defer>(
462 event,
463 std::bind(std::mem_fn((&HostPDRHandler::_processFetchPDREvent)),
464 this, nextRecordHandle, std::placeholders::_1));
465 }
466}
467
468void HostPDRHandler::_processPDRRepoChgEvent(
469 sdeventplus::source::EventBase& /*source */)
470{
471 deferredPDRRepoChgEvent.reset();
472 this->sendPDRRepositoryChgEvent(
473 std::move(std::vector<uint8_t>(1, PLDM_PDR_ENTITY_ASSOCIATION)),
474 FORMAT_IS_PDR_HANDLES);
475}
476
477void HostPDRHandler::_processFetchPDREvent(
478 uint32_t nextRecordHandle, sdeventplus::source::EventBase& /*source */)
479{
480 deferredFetchPDREvent.reset();
481 if (!this->pdrRecordHandles.empty())
482 {
483 nextRecordHandle = this->pdrRecordHandles.front();
484 this->pdrRecordHandles.pop_front();
485 }
486 this->getHostPDR(nextRecordHandle);
487}
488
sampmisr6decfc12021-03-02 11:07:36 +0530489void HostPDRHandler::setHostState()
490{
491 using namespace sdeventplus;
492 using namespace sdeventplus::source;
493 constexpr auto clockId = sdeventplus::ClockId::RealTime;
494 using Clock = Clock<clockId>;
495 using Timer = Time<clockId>;
496
497 auto event1 = sdeventplus::Event::get_default();
498 auto& bus = pldm::utils::DBusHandler::getBus();
499 bus.attach_event(event1.get(), SD_EVENT_PRIORITY_NORMAL);
500
501 responseReceived = false;
502 timeOut = false;
503
504 int fd = pldm_open();
505 if (-1 == fd)
506 {
507 std::cerr << "Failed to connect to mctp demux daemon \n";
508 return;
509 }
510
511 auto timerCallback = [=, this](Timer& /*source*/,
512 Timer::TimePoint /*time*/) {
513 timeOut = true;
514 if (!responseReceived)
515 {
516 std::cout << "PLDM did not get a response from Host"
517 " Host seems to be off \n";
518 }
519 return;
520 };
521
522 Timer time(event1, (Clock(event1).now() + std::chrono::seconds{3}),
523 std::chrono::seconds{1}, std::move(timerCallback));
524
525 auto callback = [=, this](IO& /*io*/, int fd, uint32_t revents) {
526 if (!(revents & EPOLLIN))
527 {
528 return;
529 }
530 uint8_t* responseMsg = nullptr;
531 size_t responseMsgSize{};
532 auto rc =
533 pldm_recv(mctp_eid, fd, insId, &responseMsg, &responseMsgSize);
534 if (rc != PLDM_REQUESTER_SUCCESS)
535 {
536 return;
537 }
538 std::unique_ptr<uint8_t, decltype(std::free)*> responseMsgPtr{
539 responseMsg, std::free};
540 auto response = reinterpret_cast<pldm_msg*>(responseMsgPtr.get());
541 std::cout << "Getting the response. PLDM RC = " << std::hex
542 << std::showbase
543 << static_cast<uint16_t>(response->payload[0]) << "\n";
544 responseReceived = true;
545 return;
546 };
547 IO io(event1, fd, EPOLLIN, std::move(callback));
548 std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) +
549 PLDM_GET_PDR_REQ_BYTES);
550 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
551 uint32_t recordHandle{};
552 insId = requester.getInstanceId(mctp_eid);
553 auto rc =
554 encode_get_pdr_req(insId, recordHandle, 0, PLDM_GET_FIRSTPART,
555 UINT16_MAX, 0, request, PLDM_GET_PDR_REQ_BYTES);
556 if (rc != PLDM_SUCCESS)
557 {
558 requester.markFree(mctp_eid, insId);
559 std::cerr << "Failed to encode_get_pdr_req, rc = " << rc << std::endl;
560 return;
561 }
562 rc = pldm_send(mctp_eid, fd, requestMsg.data(), requestMsg.size());
563 if (0 > rc)
564 {
565 std::cerr << "Failed to send message RC = " << rc
566 << ", errno = " << errno << "\n";
567 return;
568 }
569 while (1)
570 {
571 if (responseReceived)
572 {
573 requester.markFree(mctp_eid, insId);
574 break;
575 }
576 if (timeOut)
577 {
578 requester.markFree(mctp_eid, insId);
579 break;
580 }
581 try
582 {
583 event1.run(std::nullopt);
584 }
585 catch (const sdeventplus::SdEventError& e)
586 {
587 std::cerr << "Failure in processing request.ERROR= " << e.what()
588 << "\n";
589 return;
590 }
591 }
592}
593
594bool HostPDRHandler::isHostUp()
595{
596 return responseReceived;
597}
598
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500599} // namespace pldm