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