blob: 4d297f0b86ae8f39aa28f7977aa416d4b000999b [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
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053039 uint16_t respSizeBytes{};
40 uint8_t* recordData = nullptr;
41 try
42 {
George Liue53193f2020-02-24 09:23:26 +080043 pdr_utils::RepoInterface& pdrRepo = pdr::getRepo(PDR_JSONS_DIR);
44 pdr_utils::PdrEntry e;
45 auto record = pdr::getRecordByHandle(pdrRepo, recordHandle, e);
46 if (record == NULL)
47 {
48 return CmdHandler::ccOnlyResponse(
49 request, PLDM_PLATFORM_INVALID_RECORD_HANDLE);
50 }
51
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053052 if (reqSizeBytes)
53 {
George Liue53193f2020-02-24 09:23:26 +080054 respSizeBytes = e.size;
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053055 if (respSizeBytes > reqSizeBytes)
56 {
57 respSizeBytes = reqSizeBytes;
58 }
George Liue53193f2020-02-24 09:23:26 +080059 recordData = e.data;
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053060 }
61 response.resize(sizeof(pldm_msg_hdr) + PLDM_GET_PDR_MIN_RESP_BYTES +
62 respSizeBytes,
63 0);
64 responsePtr = reinterpret_cast<pldm_msg*>(response.data());
George Liufb8611d2019-12-06 10:14:15 +080065 rc = encode_get_pdr_resp(request->hdr.instance_id, PLDM_SUCCESS,
George Liue53193f2020-02-24 09:23:26 +080066 e.handle.nextRecordHandle, 0, PLDM_START,
67 respSizeBytes, recordData, 0, responsePtr);
George Liufb8611d2019-12-06 10:14:15 +080068 if (rc != PLDM_SUCCESS)
69 {
70 return ccOnlyResponse(request, rc);
71 }
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053072 }
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053073 catch (const std::exception& e)
74 {
Sampa Misraaa8ae722019-12-12 03:20:40 -060075 std::cerr << "Error accessing PDR, HANDLE=" << recordHandle
76 << " ERROR=" << e.what() << "\n";
George Liufb8611d2019-12-06 10:14:15 +080077 return CmdHandler::ccOnlyResponse(request, PLDM_ERROR);
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053078 }
79 return response;
80}
81
Deepak Kodihallibc669f12019-11-28 08:52:07 -060082Response Handler::setStateEffecterStates(const pldm_msg* request,
83 size_t payloadLength)
Sampa Misraa2fa0702019-05-31 01:28:55 -050084{
85 Response response(
86 sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES, 0);
87 auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
88 uint16_t effecterId;
89 uint8_t compEffecterCnt;
90 constexpr auto maxCompositeEffecterCnt = 8;
91 std::vector<set_effecter_state_field> stateField(maxCompositeEffecterCnt,
92 {0, 0});
93
94 if ((payloadLength > PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES) ||
95 (payloadLength < sizeof(effecterId) + sizeof(compEffecterCnt) +
96 sizeof(set_effecter_state_field)))
97 {
George Liufb8611d2019-12-06 10:14:15 +080098 return CmdHandler::ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH);
Sampa Misraa2fa0702019-05-31 01:28:55 -050099 }
100
101 int rc = decode_set_state_effecter_states_req(request, payloadLength,
102 &effecterId, &compEffecterCnt,
103 stateField.data());
104
George Liufb8611d2019-12-06 10:14:15 +0800105 if (rc != PLDM_SUCCESS)
Sampa Misraa2fa0702019-05-31 01:28:55 -0500106 {
George Liufb8611d2019-12-06 10:14:15 +0800107 return CmdHandler::ccOnlyResponse(request, rc);
Sampa Misraa2fa0702019-05-31 01:28:55 -0500108 }
109
George Liufb8611d2019-12-06 10:14:15 +0800110 stateField.resize(compEffecterCnt);
111 const pldm::utils::DBusHandler dBusIntf;
112 rc = setStateEffecterStatesHandler<pldm::utils::DBusHandler>(
113 dBusIntf, effecterId, stateField);
114 if (rc != PLDM_SUCCESS)
115 {
116 return CmdHandler::ccOnlyResponse(request, rc);
117 }
118
119 rc = encode_set_state_effecter_states_resp(request->hdr.instance_id, rc,
120 responsePtr);
121 if (rc != PLDM_SUCCESS)
122 {
123 return ccOnlyResponse(request, rc);
124 }
125
Sampa Misraa2fa0702019-05-31 01:28:55 -0500126 return response;
127}
128
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600129} // namespace platform
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530130} // namespace responder
131} // namespace pldm