blob: 538c49c98cf19f5934caffd41f71f66b92a23d84 [file] [log] [blame]
Deepak Kodihalli557dfb02019-05-12 13:11:17 +05301
2#include "platform.hpp"
3
Sampa Misraa2fa0702019-05-31 01:28:55 -05004#include "registration.hpp"
Deepak Kodihalli557dfb02019-05-12 13:11:17 +05305
6namespace pldm
7{
8
9namespace responder
10{
11
Sampa Misraa2fa0702019-05-31 01:28:55 -050012namespace platform
13{
14
15void registerHandlers()
16{
17 registerHandler(PLDM_PLATFORM, PLDM_GET_PDR, std::move(getPDR));
18 registerHandler(PLDM_PLATFORM, PLDM_SET_STATE_EFFECTER_STATES,
19 std::move(setStateEffecterStates));
20}
21
22} // namespace platform
23
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053024using namespace phosphor::logging;
Sampa Misraa2fa0702019-05-31 01:28:55 -050025using namespace pldm::responder::effecter::dbus_mapping;
Deepak Kodihalli557dfb02019-05-12 13:11:17 +053026
27Response getPDR(const pldm_msg* request, size_t payloadLength)
28{
29 Response response(sizeof(pldm_msg_hdr) + PLDM_GET_PDR_MIN_RESP_BYTES, 0);
30 auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
31
32 if (payloadLength != PLDM_GET_PDR_REQ_BYTES)
33 {
34 encode_get_pdr_resp(request->hdr.instance_id, PLDM_ERROR_INVALID_LENGTH,
35 0, 0, 0, 0, nullptr, 0, responsePtr);
36 return response;
37 }
38
39 uint32_t recordHandle{};
40 uint32_t dataTransferHandle{};
41 uint8_t transferOpFlag{};
42 uint16_t reqSizeBytes{};
43 uint16_t recordChangeNum{};
44
45 decode_get_pdr_req(request, payloadLength, &recordHandle,
46 &dataTransferHandle, &transferOpFlag, &reqSizeBytes,
47 &recordChangeNum);
48
49 uint32_t nextRecordHandle{};
50 uint16_t respSizeBytes{};
51 uint8_t* recordData = nullptr;
52 try
53 {
54 pdr::Repo& pdrRepo = pdr::get(PDR_JSONS_DIR);
55 nextRecordHandle = pdrRepo.getNextRecordHandle(recordHandle);
56 pdr::Entry e;
57 if (reqSizeBytes)
58 {
59 e = pdrRepo.at(recordHandle);
60 respSizeBytes = e.size();
61 if (respSizeBytes > reqSizeBytes)
62 {
63 respSizeBytes = reqSizeBytes;
64 }
65 recordData = e.data();
66 }
67 response.resize(sizeof(pldm_msg_hdr) + PLDM_GET_PDR_MIN_RESP_BYTES +
68 respSizeBytes,
69 0);
70 responsePtr = reinterpret_cast<pldm_msg*>(response.data());
71 encode_get_pdr_resp(request->hdr.instance_id, PLDM_SUCCESS,
72 nextRecordHandle, 0, PLDM_START, respSizeBytes,
73 recordData, 0, responsePtr);
74 }
75 catch (const std::out_of_range& e)
76 {
77 encode_get_pdr_resp(request->hdr.instance_id,
78 PLDM_PLATFORM_INVALID_RECORD_HANDLE,
79 nextRecordHandle, 0, PLDM_START, respSizeBytes,
80 recordData, 0, responsePtr);
81 return response;
82 }
83 catch (const std::exception& e)
84 {
85 log<level::ERR>("Error accessing PDR", entry("HANDLE=%d", recordHandle),
86 entry("ERROR=%s", e.what()));
87 encode_get_pdr_resp(request->hdr.instance_id, PLDM_ERROR,
88 nextRecordHandle, 0, PLDM_START, respSizeBytes,
89 recordData, 0, responsePtr);
90 return response;
91 }
92 return response;
93}
94
Sampa Misraa2fa0702019-05-31 01:28:55 -050095Response setStateEffecterStates(const pldm_msg* request, size_t payloadLength)
96{
97 Response response(
98 sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES, 0);
99 auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
100 uint16_t effecterId;
101 uint8_t compEffecterCnt;
102 constexpr auto maxCompositeEffecterCnt = 8;
103 std::vector<set_effecter_state_field> stateField(maxCompositeEffecterCnt,
104 {0, 0});
105
106 if ((payloadLength > PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES) ||
107 (payloadLength < sizeof(effecterId) + sizeof(compEffecterCnt) +
108 sizeof(set_effecter_state_field)))
109 {
110 encode_set_state_effecter_states_resp(
111 request->hdr.instance_id, PLDM_ERROR_INVALID_LENGTH, responsePtr);
112 return response;
113 }
114
115 int rc = decode_set_state_effecter_states_req(request, payloadLength,
116 &effecterId, &compEffecterCnt,
117 stateField.data());
118
119 if (rc == PLDM_SUCCESS)
120 {
121 stateField.resize(compEffecterCnt);
122 const DBusHandler dBusIntf;
123 rc = setStateEffecterStatesHandler<DBusHandler>(dBusIntf, effecterId,
124 stateField);
125 }
126
127 encode_set_state_effecter_states_resp(request->hdr.instance_id, rc,
128 responsePtr);
129 return response;
130}
131
Deepak Kodihalli557dfb02019-05-12 13:11:17 +0530132} // namespace responder
133} // namespace pldm