1 #include "common/transport.hpp" 2 3 #include <libpldm/platform.h> 4 5 #include <CLI/CLI.hpp> 6 #include <phosphor-logging/lg2.hpp> 7 8 #include <array> 9 #include <iostream> 10 11 PHOSPHOR_LOG2_USING; 12 13 int main(int argc, char** argv) 14 { 15 CLI::App app{"Send PLDM command SetStateEffecterStates"}; 16 uint8_t mctpEid{}; 17 app.add_option("-m,--mctp_eid", mctpEid, "MCTP EID")->required(); 18 uint16_t effecterId{}; 19 app.add_option("-e,--effecter", effecterId, "Effecter Id")->required(); 20 uint8_t state{}; 21 app.add_option("-s,--state", state, "New state value")->required(); 22 CLI11_PARSE(app, argc, argv); 23 24 // Encode PLDM Request message 25 uint8_t effecterCount = 1; 26 std::array<uint8_t, sizeof(pldm_msg_hdr) + sizeof(effecterId) + 27 sizeof(effecterCount) + 28 sizeof(set_effecter_state_field)> 29 requestMsg{}; 30 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); 31 set_effecter_state_field stateField{PLDM_REQUEST_SET, state}; 32 auto rc = encode_set_state_effecter_states_req(0, effecterId, effecterCount, 33 &stateField, request); 34 if (rc != PLDM_SUCCESS) 35 { 36 error("Message encode failure. PLDM error code = {RC}", "RC", lg2::hex, 37 rc); 38 return -1; 39 } 40 41 PldmTransport pldmTransport{}; 42 43 void* responseMsg = nullptr; 44 size_t responseMsgSize{}; 45 // Send PLDM request msg and wait for response 46 rc = pldmTransport.sendRecvMsg(static_cast<pldm_tid_t>(mctpEid), 47 requestMsg.data(), requestMsg.size(), 48 responseMsg, responseMsgSize); 49 if (0 > rc) 50 { 51 error( 52 "Failed to send message/receive response. RC = {RC}, errno = {ERR}", 53 "RC", rc, "ERR", errno); 54 return -1; 55 } 56 pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg); 57 info("Done. PLDM RC = {RC}", "RC", lg2::hex, 58 static_cast<uint16_t>(response->payload[0])); 59 free(responseMsg); 60 61 return 0; 62 } 63