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