blob: 3f93ff422888381093045e2fb68e6d4dd654a8da [file] [log] [blame]
#include "platform.hpp"
#include "utils.hpp"
namespace pldm
{
namespace responder
{
namespace platform
{
using namespace pldm::responder::effecter::dbus_mapping;
Response Handler::getPDR(const pldm_msg* request, size_t payloadLength)
{
Response response(sizeof(pldm_msg_hdr) + PLDM_GET_PDR_MIN_RESP_BYTES, 0);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
if (payloadLength != PLDM_GET_PDR_REQ_BYTES)
{
return CmdHandler::ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH);
}
uint32_t recordHandle{};
uint32_t dataTransferHandle{};
uint8_t transferOpFlag{};
uint16_t reqSizeBytes{};
uint16_t recordChangeNum{};
auto rc = decode_get_pdr_req(request, payloadLength, &recordHandle,
&dataTransferHandle, &transferOpFlag,
&reqSizeBytes, &recordChangeNum);
if (rc != PLDM_SUCCESS)
{
return CmdHandler::ccOnlyResponse(request, rc);
}
uint32_t nextRecordHandle{};
uint16_t respSizeBytes{};
uint8_t* recordData = nullptr;
try
{
pdr::Repo& pdrRepo = pdr::get(PDR_JSONS_DIR);
nextRecordHandle = pdrRepo.getNextRecordHandle(recordHandle);
pdr::Entry e;
if (reqSizeBytes)
{
e = pdrRepo.at(recordHandle);
respSizeBytes = e.size();
if (respSizeBytes > reqSizeBytes)
{
respSizeBytes = reqSizeBytes;
}
recordData = e.data();
}
response.resize(sizeof(pldm_msg_hdr) + PLDM_GET_PDR_MIN_RESP_BYTES +
respSizeBytes,
0);
responsePtr = reinterpret_cast<pldm_msg*>(response.data());
rc = encode_get_pdr_resp(request->hdr.instance_id, PLDM_SUCCESS,
nextRecordHandle, 0, PLDM_START, respSizeBytes,
recordData, 0, responsePtr);
if (rc != PLDM_SUCCESS)
{
return ccOnlyResponse(request, rc);
}
}
catch (const std::out_of_range& e)
{
return CmdHandler::ccOnlyResponse(request,
PLDM_PLATFORM_INVALID_RECORD_HANDLE);
}
catch (const std::exception& e)
{
std::cerr << "Error accessing PDR, HANDLE=" << recordHandle
<< " ERROR=" << e.what() << "\n";
return CmdHandler::ccOnlyResponse(request, PLDM_ERROR);
}
return response;
}
Response Handler::setStateEffecterStates(const pldm_msg* request,
size_t payloadLength)
{
Response response(
sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES, 0);
auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
uint16_t effecterId;
uint8_t compEffecterCnt;
constexpr auto maxCompositeEffecterCnt = 8;
std::vector<set_effecter_state_field> stateField(maxCompositeEffecterCnt,
{0, 0});
if ((payloadLength > PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES) ||
(payloadLength < sizeof(effecterId) + sizeof(compEffecterCnt) +
sizeof(set_effecter_state_field)))
{
return CmdHandler::ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH);
}
int rc = decode_set_state_effecter_states_req(request, payloadLength,
&effecterId, &compEffecterCnt,
stateField.data());
if (rc != PLDM_SUCCESS)
{
return CmdHandler::ccOnlyResponse(request, rc);
}
stateField.resize(compEffecterCnt);
const pldm::utils::DBusHandler dBusIntf;
rc = setStateEffecterStatesHandler<pldm::utils::DBusHandler>(
dBusIntf, effecterId, stateField);
if (rc != PLDM_SUCCESS)
{
return CmdHandler::ccOnlyResponse(request, rc);
}
rc = encode_set_state_effecter_states_resp(request->hdr.instance_id, rc,
responsePtr);
if (rc != PLDM_SUCCESS)
{
return ccOnlyResponse(request, rc);
}
return response;
}
} // namespace platform
} // namespace responder
} // namespace pldm