Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 1 | |
| 2 | #include "platform.hpp" |
| 3 | |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 4 | #include "utils.hpp" |
| 5 | |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 6 | namespace pldm |
| 7 | { |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 8 | namespace responder |
| 9 | { |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 10 | namespace platform |
| 11 | { |
| 12 | |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 13 | using namespace pldm::responder::effecter::dbus_mapping; |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 14 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 15 | Response Handler::getPDR(const pldm_msg* request, size_t payloadLength) |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 16 | { |
| 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 | { |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 22 | return CmdHandler::ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | uint32_t recordHandle{}; |
| 26 | uint32_t dataTransferHandle{}; |
| 27 | uint8_t transferOpFlag{}; |
| 28 | uint16_t reqSizeBytes{}; |
| 29 | uint16_t recordChangeNum{}; |
| 30 | |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 31 | auto rc = decode_get_pdr_req(request, payloadLength, &recordHandle, |
| 32 | &dataTransferHandle, &transferOpFlag, |
| 33 | &reqSizeBytes, &recordChangeNum); |
| 34 | if (rc != PLDM_SUCCESS) |
| 35 | { |
| 36 | return CmdHandler::ccOnlyResponse(request, rc); |
| 37 | } |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 38 | |
| 39 | uint32_t nextRecordHandle{}; |
| 40 | uint16_t respSizeBytes{}; |
| 41 | uint8_t* recordData = nullptr; |
| 42 | try |
| 43 | { |
| 44 | pdr::Repo& pdrRepo = pdr::get(PDR_JSONS_DIR); |
| 45 | nextRecordHandle = pdrRepo.getNextRecordHandle(recordHandle); |
| 46 | pdr::Entry e; |
| 47 | if (reqSizeBytes) |
| 48 | { |
| 49 | e = pdrRepo.at(recordHandle); |
| 50 | respSizeBytes = e.size(); |
| 51 | if (respSizeBytes > reqSizeBytes) |
| 52 | { |
| 53 | respSizeBytes = reqSizeBytes; |
| 54 | } |
| 55 | recordData = e.data(); |
| 56 | } |
| 57 | response.resize(sizeof(pldm_msg_hdr) + PLDM_GET_PDR_MIN_RESP_BYTES + |
| 58 | respSizeBytes, |
| 59 | 0); |
| 60 | responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 61 | rc = encode_get_pdr_resp(request->hdr.instance_id, PLDM_SUCCESS, |
| 62 | nextRecordHandle, 0, PLDM_START, respSizeBytes, |
| 63 | recordData, 0, responsePtr); |
| 64 | if (rc != PLDM_SUCCESS) |
| 65 | { |
| 66 | return ccOnlyResponse(request, rc); |
| 67 | } |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 68 | } |
| 69 | catch (const std::out_of_range& e) |
| 70 | { |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 71 | return CmdHandler::ccOnlyResponse(request, |
| 72 | PLDM_PLATFORM_INVALID_RECORD_HANDLE); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 73 | } |
| 74 | catch (const std::exception& e) |
| 75 | { |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 76 | std::cerr << "Error accessing PDR, HANDLE=" << recordHandle |
| 77 | << " ERROR=" << e.what() << "\n"; |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 78 | return CmdHandler::ccOnlyResponse(request, PLDM_ERROR); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 79 | } |
| 80 | return response; |
| 81 | } |
| 82 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 83 | Response Handler::setStateEffecterStates(const pldm_msg* request, |
| 84 | size_t payloadLength) |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 85 | { |
| 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 | { |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 99 | return CmdHandler::ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | int rc = decode_set_state_effecter_states_req(request, payloadLength, |
| 103 | &effecterId, &compEffecterCnt, |
| 104 | stateField.data()); |
| 105 | |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 106 | if (rc != PLDM_SUCCESS) |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 107 | { |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 108 | return CmdHandler::ccOnlyResponse(request, rc); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 109 | } |
| 110 | |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 111 | stateField.resize(compEffecterCnt); |
| 112 | const pldm::utils::DBusHandler dBusIntf; |
| 113 | rc = setStateEffecterStatesHandler<pldm::utils::DBusHandler>( |
| 114 | dBusIntf, effecterId, stateField); |
| 115 | if (rc != PLDM_SUCCESS) |
| 116 | { |
| 117 | return CmdHandler::ccOnlyResponse(request, rc); |
| 118 | } |
| 119 | |
| 120 | rc = encode_set_state_effecter_states_resp(request->hdr.instance_id, rc, |
| 121 | responsePtr); |
| 122 | if (rc != PLDM_SUCCESS) |
| 123 | { |
| 124 | return ccOnlyResponse(request, rc); |
| 125 | } |
| 126 | |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 127 | return response; |
| 128 | } |
| 129 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 130 | } // namespace platform |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 131 | } // namespace responder |
| 132 | } // namespace pldm |