blob: 50237cf925987e04591c2474715002d049914ac3 [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
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053011using namespace phosphor::logging;
Sampa Misraa2fa0702019-05-31 01:28:55 -050012using namespace pldm::responder::effecter::dbus_mapping;
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053013
Deepak Kodihallibc669f12019-11-28 08:52:07 -060014Response Handler::getPDR(const pldm_msg* request, size_t payloadLength)
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053015{
16 Response response(sizeof(pldm_msg_hdr) + PLDM_GET_PDR_MIN_RESP_BYTES, 0);
17 auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
18
19 if (payloadLength != PLDM_GET_PDR_REQ_BYTES)
20 {
21 encode_get_pdr_resp(request->hdr.instance_id, PLDM_ERROR_INVALID_LENGTH,
22 0, 0, 0, 0, nullptr, 0, responsePtr);
23 return response;
24 }
25
26 uint32_t recordHandle{};
27 uint32_t dataTransferHandle{};
28 uint8_t transferOpFlag{};
29 uint16_t reqSizeBytes{};
30 uint16_t recordChangeNum{};
31
32 decode_get_pdr_req(request, payloadLength, &recordHandle,
33 &dataTransferHandle, &transferOpFlag, &reqSizeBytes,
34 &recordChangeNum);
35
36 uint32_t nextRecordHandle{};
37 uint16_t respSizeBytes{};
38 uint8_t* recordData = nullptr;
39 try
40 {
41 pdr::Repo& pdrRepo = pdr::get(PDR_JSONS_DIR);
42 nextRecordHandle = pdrRepo.getNextRecordHandle(recordHandle);
43 pdr::Entry e;
44 if (reqSizeBytes)
45 {
46 e = pdrRepo.at(recordHandle);
47 respSizeBytes = e.size();
48 if (respSizeBytes > reqSizeBytes)
49 {
50 respSizeBytes = reqSizeBytes;
51 }
52 recordData = e.data();
53 }
54 response.resize(sizeof(pldm_msg_hdr) + PLDM_GET_PDR_MIN_RESP_BYTES +
55 respSizeBytes,
56 0);
57 responsePtr = reinterpret_cast<pldm_msg*>(response.data());
58 encode_get_pdr_resp(request->hdr.instance_id, PLDM_SUCCESS,
59 nextRecordHandle, 0, PLDM_START, respSizeBytes,
60 recordData, 0, responsePtr);
61 }
62 catch (const std::out_of_range& e)
63 {
64 encode_get_pdr_resp(request->hdr.instance_id,
65 PLDM_PLATFORM_INVALID_RECORD_HANDLE,
66 nextRecordHandle, 0, PLDM_START, respSizeBytes,
67 recordData, 0, responsePtr);
68 return response;
69 }
70 catch (const std::exception& e)
71 {
72 log<level::ERR>("Error accessing PDR", entry("HANDLE=%d", recordHandle),
73 entry("ERROR=%s", e.what()));
74 encode_get_pdr_resp(request->hdr.instance_id, PLDM_ERROR,
75 nextRecordHandle, 0, PLDM_START, respSizeBytes,
76 recordData, 0, responsePtr);
77 return response;
78 }
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 {
98 encode_set_state_effecter_states_resp(
99 request->hdr.instance_id, PLDM_ERROR_INVALID_LENGTH, responsePtr);
100 return response;
101 }
102
103 int rc = decode_set_state_effecter_states_req(request, payloadLength,
104 &effecterId, &compEffecterCnt,
105 stateField.data());
106
107 if (rc == PLDM_SUCCESS)
108 {
109 stateField.resize(compEffecterCnt);
110 const DBusHandler dBusIntf;
111 rc = setStateEffecterStatesHandler<DBusHandler>(dBusIntf, effecterId,
112 stateField);
113 }
114
115 encode_set_state_effecter_states_resp(request->hdr.instance_id, rc,
116 responsePtr);
117 return response;
118}
119
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600120} // namespace platform
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530121} // namespace responder
122} // namespace pldm