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