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