blob: 9c5b6886a6e72e39834f82006e2b38703342fe5c [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 {
22 encode_get_pdr_resp(request->hdr.instance_id, PLDM_ERROR_INVALID_LENGTH,
23 0, 0, 0, 0, nullptr, 0, responsePtr);
24 return response;
25 }
26
27 uint32_t recordHandle{};
28 uint32_t dataTransferHandle{};
29 uint8_t transferOpFlag{};
30 uint16_t reqSizeBytes{};
31 uint16_t recordChangeNum{};
32
33 decode_get_pdr_req(request, payloadLength, &recordHandle,
34 &dataTransferHandle, &transferOpFlag, &reqSizeBytes,
35 &recordChangeNum);
36
37 uint32_t nextRecordHandle{};
38 uint16_t respSizeBytes{};
39 uint8_t* recordData = nullptr;
40 try
41 {
42 pdr::Repo& pdrRepo = pdr::get(PDR_JSONS_DIR);
43 nextRecordHandle = pdrRepo.getNextRecordHandle(recordHandle);
44 pdr::Entry e;
45 if (reqSizeBytes)
46 {
47 e = pdrRepo.at(recordHandle);
48 respSizeBytes = e.size();
49 if (respSizeBytes > reqSizeBytes)
50 {
51 respSizeBytes = reqSizeBytes;
52 }
53 recordData = e.data();
54 }
55 response.resize(sizeof(pldm_msg_hdr) + PLDM_GET_PDR_MIN_RESP_BYTES +
56 respSizeBytes,
57 0);
58 responsePtr = reinterpret_cast<pldm_msg*>(response.data());
59 encode_get_pdr_resp(request->hdr.instance_id, PLDM_SUCCESS,
60 nextRecordHandle, 0, PLDM_START, respSizeBytes,
61 recordData, 0, responsePtr);
62 }
63 catch (const std::out_of_range& e)
64 {
65 encode_get_pdr_resp(request->hdr.instance_id,
66 PLDM_PLATFORM_INVALID_RECORD_HANDLE,
67 nextRecordHandle, 0, PLDM_START, respSizeBytes,
68 recordData, 0, responsePtr);
69 return response;
70 }
71 catch (const std::exception& e)
72 {
Sampa Misraaa8ae722019-12-12 03:20:40 -060073 std::cerr << "Error accessing PDR, HANDLE=" << recordHandle
74 << " ERROR=" << e.what() << "\n";
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053075 encode_get_pdr_resp(request->hdr.instance_id, PLDM_ERROR,
76 nextRecordHandle, 0, PLDM_START, respSizeBytes,
77 recordData, 0, responsePtr);
78 return response;
79 }
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 {
99 encode_set_state_effecter_states_resp(
100 request->hdr.instance_id, PLDM_ERROR_INVALID_LENGTH, responsePtr);
101 return response;
102 }
103
104 int rc = decode_set_state_effecter_states_req(request, payloadLength,
105 &effecterId, &compEffecterCnt,
106 stateField.data());
107
108 if (rc == PLDM_SUCCESS)
109 {
110 stateField.resize(compEffecterCnt);
George Liu83409572019-12-24 18:42:54 +0800111
112 const pldm::utils::DBusHandler dBusIntf;
113 rc = setStateEffecterStatesHandler<pldm::utils::DBusHandler>(
114 dBusIntf, effecterId, stateField);
Sampa Misraa2fa0702019-05-31 01:28:55 -0500115 }
116
117 encode_set_state_effecter_states_resp(request->hdr.instance_id, rc,
118 responsePtr);
119 return response;
120}
121
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600122} // namespace platform
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530123} // namespace responder
124} // namespace pldm