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 | |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 39 | uint16_t respSizeBytes{}; |
| 40 | uint8_t* recordData = nullptr; |
| 41 | try |
| 42 | { |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame^] | 43 | pdr_utils::RepoInterface& pdrRepo = pdr::getRepo(PDR_JSONS_DIR); |
| 44 | pdr_utils::PdrEntry e; |
| 45 | auto record = pdr::getRecordByHandle(pdrRepo, recordHandle, e); |
| 46 | if (record == NULL) |
| 47 | { |
| 48 | return CmdHandler::ccOnlyResponse( |
| 49 | request, PLDM_PLATFORM_INVALID_RECORD_HANDLE); |
| 50 | } |
| 51 | |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 52 | if (reqSizeBytes) |
| 53 | { |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame^] | 54 | respSizeBytes = e.size; |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 55 | if (respSizeBytes > reqSizeBytes) |
| 56 | { |
| 57 | respSizeBytes = reqSizeBytes; |
| 58 | } |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame^] | 59 | recordData = e.data; |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 60 | } |
| 61 | response.resize(sizeof(pldm_msg_hdr) + PLDM_GET_PDR_MIN_RESP_BYTES + |
| 62 | respSizeBytes, |
| 63 | 0); |
| 64 | responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 65 | rc = encode_get_pdr_resp(request->hdr.instance_id, PLDM_SUCCESS, |
George Liu | e53193f | 2020-02-24 09:23:26 +0800 | [diff] [blame^] | 66 | e.handle.nextRecordHandle, 0, PLDM_START, |
| 67 | respSizeBytes, recordData, 0, responsePtr); |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 68 | if (rc != PLDM_SUCCESS) |
| 69 | { |
| 70 | return ccOnlyResponse(request, rc); |
| 71 | } |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 72 | } |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 73 | catch (const std::exception& e) |
| 74 | { |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 75 | std::cerr << "Error accessing PDR, HANDLE=" << recordHandle |
| 76 | << " ERROR=" << e.what() << "\n"; |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 77 | return CmdHandler::ccOnlyResponse(request, PLDM_ERROR); |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 78 | } |
| 79 | return response; |
| 80 | } |
| 81 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 82 | Response Handler::setStateEffecterStates(const pldm_msg* request, |
| 83 | size_t payloadLength) |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 84 | { |
| 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 | { |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 98 | return CmdHandler::ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | int rc = decode_set_state_effecter_states_req(request, payloadLength, |
| 102 | &effecterId, &compEffecterCnt, |
| 103 | stateField.data()); |
| 104 | |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 105 | if (rc != PLDM_SUCCESS) |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 106 | { |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 107 | return CmdHandler::ccOnlyResponse(request, rc); |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 108 | } |
| 109 | |
George Liu | fb8611d | 2019-12-06 10:14:15 +0800 | [diff] [blame] | 110 | stateField.resize(compEffecterCnt); |
| 111 | const pldm::utils::DBusHandler dBusIntf; |
| 112 | rc = setStateEffecterStatesHandler<pldm::utils::DBusHandler>( |
| 113 | dBusIntf, effecterId, stateField); |
| 114 | if (rc != PLDM_SUCCESS) |
| 115 | { |
| 116 | return CmdHandler::ccOnlyResponse(request, rc); |
| 117 | } |
| 118 | |
| 119 | rc = encode_set_state_effecter_states_resp(request->hdr.instance_id, rc, |
| 120 | responsePtr); |
| 121 | if (rc != PLDM_SUCCESS) |
| 122 | { |
| 123 | return ccOnlyResponse(request, rc); |
| 124 | } |
| 125 | |
Sampa Misra | a2fa070 | 2019-05-31 01:28:55 -0500 | [diff] [blame] | 126 | return response; |
| 127 | } |
| 128 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 129 | } // namespace platform |
Deepak Kodihalli | 557dfb0 | 2019-05-12 13:11:17 +0530 | [diff] [blame] | 130 | } // namespace responder |
| 131 | } // namespace pldm |