blob: 3f93ff422888381093045e2fb68e6d4dd654a8da [file] [log] [blame]
Deepak Kodihalli557dfb02019-05-12 13:11:17 +05301
2#include "platform.hpp"
3
George Liu83409572019-12-24 18:42:54 +08004#include "utils.hpp"
5
Deepak Kodihalli557dfb02019-05-12 13:11:17 +05306namespace pldm
7{
Deepak Kodihalli557dfb02019-05-12 13:11:17 +05308namespace responder
9{
Sampa Misraa2fa0702019-05-31 01:28:55 -050010namespace platform
11{
12
Sampa Misraa2fa0702019-05-31 01:28:55 -050013using namespace pldm::responder::effecter::dbus_mapping;
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053014
Deepak Kodihallibc669f12019-11-28 08:52:07 -060015Response Handler::getPDR(const pldm_msg* request, size_t payloadLength)
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053016{
17 Response response(sizeof(pldm_msg_hdr) + PLDM_GET_PDR_MIN_RESP_BYTES, 0);
18 auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
19
20 if (payloadLength != PLDM_GET_PDR_REQ_BYTES)
21 {
George Liufb8611d2019-12-06 10:14:15 +080022 return CmdHandler::ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH);
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053023 }
24
25 uint32_t recordHandle{};
26 uint32_t dataTransferHandle{};
27 uint8_t transferOpFlag{};
28 uint16_t reqSizeBytes{};
29 uint16_t recordChangeNum{};
30
George Liufb8611d2019-12-06 10:14:15 +080031 auto rc = decode_get_pdr_req(request, payloadLength, &recordHandle,
32 &dataTransferHandle, &transferOpFlag,
33 &reqSizeBytes, &recordChangeNum);
34 if (rc != PLDM_SUCCESS)
35 {
36 return CmdHandler::ccOnlyResponse(request, rc);
37 }
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053038
39 uint32_t nextRecordHandle{};
40 uint16_t respSizeBytes{};
41 uint8_t* recordData = nullptr;
42 try
43 {
44 pdr::Repo& pdrRepo = pdr::get(PDR_JSONS_DIR);
45 nextRecordHandle = pdrRepo.getNextRecordHandle(recordHandle);
46 pdr::Entry e;
47 if (reqSizeBytes)
48 {
49 e = pdrRepo.at(recordHandle);
50 respSizeBytes = e.size();
51 if (respSizeBytes > reqSizeBytes)
52 {
53 respSizeBytes = reqSizeBytes;
54 }
55 recordData = e.data();
56 }
57 response.resize(sizeof(pldm_msg_hdr) + PLDM_GET_PDR_MIN_RESP_BYTES +
58 respSizeBytes,
59 0);
60 responsePtr = reinterpret_cast<pldm_msg*>(response.data());
George Liufb8611d2019-12-06 10:14:15 +080061 rc = encode_get_pdr_resp(request->hdr.instance_id, PLDM_SUCCESS,
62 nextRecordHandle, 0, PLDM_START, respSizeBytes,
63 recordData, 0, responsePtr);
64 if (rc != PLDM_SUCCESS)
65 {
66 return ccOnlyResponse(request, rc);
67 }
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053068 }
69 catch (const std::out_of_range& e)
70 {
George Liufb8611d2019-12-06 10:14:15 +080071 return CmdHandler::ccOnlyResponse(request,
72 PLDM_PLATFORM_INVALID_RECORD_HANDLE);
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053073 }
74 catch (const std::exception& e)
75 {
Sampa Misraaa8ae722019-12-12 03:20:40 -060076 std::cerr << "Error accessing PDR, HANDLE=" << recordHandle
77 << " ERROR=" << e.what() << "\n";
George Liufb8611d2019-12-06 10:14:15 +080078 return CmdHandler::ccOnlyResponse(request, PLDM_ERROR);
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053079 }
80 return response;
81}
82
Deepak Kodihallibc669f12019-11-28 08:52:07 -060083Response Handler::setStateEffecterStates(const pldm_msg* request,
84 size_t payloadLength)
Sampa Misraa2fa0702019-05-31 01:28:55 -050085{
86 Response response(
87 sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES, 0);
88 auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
89 uint16_t effecterId;
90 uint8_t compEffecterCnt;
91 constexpr auto maxCompositeEffecterCnt = 8;
92 std::vector<set_effecter_state_field> stateField(maxCompositeEffecterCnt,
93 {0, 0});
94
95 if ((payloadLength > PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES) ||
96 (payloadLength < sizeof(effecterId) + sizeof(compEffecterCnt) +
97 sizeof(set_effecter_state_field)))
98 {
George Liufb8611d2019-12-06 10:14:15 +080099 return CmdHandler::ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH);
Sampa Misraa2fa0702019-05-31 01:28:55 -0500100 }
101
102 int rc = decode_set_state_effecter_states_req(request, payloadLength,
103 &effecterId, &compEffecterCnt,
104 stateField.data());
105
George Liufb8611d2019-12-06 10:14:15 +0800106 if (rc != PLDM_SUCCESS)
Sampa Misraa2fa0702019-05-31 01:28:55 -0500107 {
George Liufb8611d2019-12-06 10:14:15 +0800108 return CmdHandler::ccOnlyResponse(request, rc);
Sampa Misraa2fa0702019-05-31 01:28:55 -0500109 }
110
George Liufb8611d2019-12-06 10:14:15 +0800111 stateField.resize(compEffecterCnt);
112 const pldm::utils::DBusHandler dBusIntf;
113 rc = setStateEffecterStatesHandler<pldm::utils::DBusHandler>(
114 dBusIntf, effecterId, stateField);
115 if (rc != PLDM_SUCCESS)
116 {
117 return CmdHandler::ccOnlyResponse(request, rc);
118 }
119
120 rc = encode_set_state_effecter_states_resp(request->hdr.instance_id, rc,
121 responsePtr);
122 if (rc != PLDM_SUCCESS)
123 {
124 return ccOnlyResponse(request, rc);
125 }
126
Sampa Misraa2fa0702019-05-31 01:28:55 -0500127 return response;
128}
129
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600130} // namespace platform
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530131} // namespace responder
132} // namespace pldm