blob: 1d6d0423ce7d5c66f4d1d1f68c74b24c114a9f4a [file] [log] [blame]
Deepak Kodihalli557dfb02019-05-12 13:11:17 +05301
2#include "platform.hpp"
3
Deepak Kodihalli557dfb02019-05-12 13:11:17 +05304namespace pldm
5{
Deepak Kodihalli557dfb02019-05-12 13:11:17 +05306namespace responder
7{
Sampa Misraa2fa0702019-05-31 01:28:55 -05008namespace platform
9{
10
Sampa Misraa2fa0702019-05-31 01:28:55 -050011using namespace pldm::responder::effecter::dbus_mapping;
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053012
Deepak Kodihallibc669f12019-11-28 08:52:07 -060013Response Handler::getPDR(const pldm_msg* request, size_t payloadLength)
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053014{
15 Response response(sizeof(pldm_msg_hdr) + PLDM_GET_PDR_MIN_RESP_BYTES, 0);
16 auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
17
18 if (payloadLength != PLDM_GET_PDR_REQ_BYTES)
19 {
20 encode_get_pdr_resp(request->hdr.instance_id, PLDM_ERROR_INVALID_LENGTH,
21 0, 0, 0, 0, nullptr, 0, responsePtr);
22 return response;
23 }
24
25 uint32_t recordHandle{};
26 uint32_t dataTransferHandle{};
27 uint8_t transferOpFlag{};
28 uint16_t reqSizeBytes{};
29 uint16_t recordChangeNum{};
30
31 decode_get_pdr_req(request, payloadLength, &recordHandle,
32 &dataTransferHandle, &transferOpFlag, &reqSizeBytes,
33 &recordChangeNum);
34
35 uint32_t nextRecordHandle{};
36 uint16_t respSizeBytes{};
37 uint8_t* recordData = nullptr;
38 try
39 {
40 pdr::Repo& pdrRepo = pdr::get(PDR_JSONS_DIR);
41 nextRecordHandle = pdrRepo.getNextRecordHandle(recordHandle);
42 pdr::Entry e;
43 if (reqSizeBytes)
44 {
45 e = pdrRepo.at(recordHandle);
46 respSizeBytes = e.size();
47 if (respSizeBytes > reqSizeBytes)
48 {
49 respSizeBytes = reqSizeBytes;
50 }
51 recordData = e.data();
52 }
53 response.resize(sizeof(pldm_msg_hdr) + PLDM_GET_PDR_MIN_RESP_BYTES +
54 respSizeBytes,
55 0);
56 responsePtr = reinterpret_cast<pldm_msg*>(response.data());
57 encode_get_pdr_resp(request->hdr.instance_id, PLDM_SUCCESS,
58 nextRecordHandle, 0, PLDM_START, respSizeBytes,
59 recordData, 0, responsePtr);
60 }
61 catch (const std::out_of_range& e)
62 {
63 encode_get_pdr_resp(request->hdr.instance_id,
64 PLDM_PLATFORM_INVALID_RECORD_HANDLE,
65 nextRecordHandle, 0, PLDM_START, respSizeBytes,
66 recordData, 0, responsePtr);
67 return response;
68 }
69 catch (const std::exception& e)
70 {
Sampa Misraaa8ae722019-12-12 03:20:40 -060071 std::cerr << "Error accessing PDR, HANDLE=" << recordHandle
72 << " ERROR=" << e.what() << "\n";
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053073 encode_get_pdr_resp(request->hdr.instance_id, PLDM_ERROR,
74 nextRecordHandle, 0, PLDM_START, respSizeBytes,
75 recordData, 0, responsePtr);
76 return response;
77 }
78 return response;
79}
80
Deepak Kodihallibc669f12019-11-28 08:52:07 -060081Response Handler::setStateEffecterStates(const pldm_msg* request,
82 size_t payloadLength)
Sampa Misraa2fa0702019-05-31 01:28:55 -050083{
84 Response response(
85 sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES, 0);
86 auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
87 uint16_t effecterId;
88 uint8_t compEffecterCnt;
89 constexpr auto maxCompositeEffecterCnt = 8;
90 std::vector<set_effecter_state_field> stateField(maxCompositeEffecterCnt,
91 {0, 0});
92
93 if ((payloadLength > PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES) ||
94 (payloadLength < sizeof(effecterId) + sizeof(compEffecterCnt) +
95 sizeof(set_effecter_state_field)))
96 {
97 encode_set_state_effecter_states_resp(
98 request->hdr.instance_id, PLDM_ERROR_INVALID_LENGTH, responsePtr);
99 return response;
100 }
101
102 int rc = decode_set_state_effecter_states_req(request, payloadLength,
103 &effecterId, &compEffecterCnt,
104 stateField.data());
105
106 if (rc == PLDM_SUCCESS)
107 {
108 stateField.resize(compEffecterCnt);
109 const DBusHandler dBusIntf;
110 rc = setStateEffecterStatesHandler<DBusHandler>(dBusIntf, effecterId,
111 stateField);
112 }
113
114 encode_set_state_effecter_states_resp(request->hdr.instance_id, rc,
115 responsePtr);
116 return response;
117}
118
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600119} // namespace platform
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530120} // namespace responder
121} // namespace pldm