blob: 19ffd7a38dea64aa0e43f98ec257865b6a6718e7 [file] [log] [blame]
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +10001#include "common/transport.hpp"
2
George Liuc453e162022-12-21 17:16:23 +08003#include <libpldm/platform.h>
Deepak Kodihalli9d494bb2019-11-05 01:28:43 -06004
George Liu6492f522020-06-16 10:34:05 +08005#include <CLI/CLI.hpp>
Riya Dixit49cfb132023-03-02 04:26:53 -06006#include <phosphor-logging/lg2.hpp>
George Liu6492f522020-06-16 10:34:05 +08007
8#include <array>
George Liu6492f522020-06-16 10:34:05 +08009
Riya Dixit49cfb132023-03-02 04:26:53 -060010PHOSPHOR_LOG2_USING;
11
Deepak Kodihalli9d494bb2019-11-05 01:28:43 -060012int main(int argc, char** argv)
13{
14 CLI::App app{"Send PLDM command SetStateEffecterStates"};
15 uint8_t mctpEid{};
16 app.add_option("-m,--mctp_eid", mctpEid, "MCTP EID")->required();
17 uint16_t effecterId{};
18 app.add_option("-e,--effecter", effecterId, "Effecter Id")->required();
19 uint8_t state{};
20 app.add_option("-s,--state", state, "New state value")->required();
21 CLI11_PARSE(app, argc, argv);
22
23 // Encode PLDM Request message
24 uint8_t effecterCount = 1;
25 std::array<uint8_t, sizeof(pldm_msg_hdr) + sizeof(effecterId) +
26 sizeof(effecterCount) +
27 sizeof(set_effecter_state_field)>
28 requestMsg{};
29 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
30 set_effecter_state_field stateField{PLDM_REQUEST_SET, state};
31 auto rc = encode_set_state_effecter_states_req(0, effecterId, effecterCount,
32 &stateField, request);
33 if (rc != PLDM_SUCCESS)
34 {
Riya Dixit087a7512024-04-06 14:28:08 -050035 error(
36 "Failed to encode set state effecter states request message, response code '{RC}'",
37 "RC", lg2::hex, rc);
Deepak Kodihalli9d494bb2019-11-05 01:28:43 -060038 return -1;
39 }
40
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +100041 PldmTransport pldmTransport{};
Deepak Kodihalli9d494bb2019-11-05 01:28:43 -060042
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +100043 void* responseMsg = nullptr;
Deepak Kodihalli9d494bb2019-11-05 01:28:43 -060044 size_t responseMsgSize{};
45 // Send PLDM request msg and wait for response
Rashmica Gupta1ed5f7a2023-05-22 13:56:42 +100046 rc = pldmTransport.sendRecvMsg(static_cast<pldm_tid_t>(mctpEid),
47 requestMsg.data(), requestMsg.size(),
48 responseMsg, responseMsgSize);
Deepak Kodihalli9d494bb2019-11-05 01:28:43 -060049 if (0 > rc)
50 {
Riya Dixit49cfb132023-03-02 04:26:53 -060051 error(
Riya Dixit087a7512024-04-06 14:28:08 -050052 "Failed to send message/receive response, response code '{RC}' and error - {ERROR}",
53 "RC", rc, "ERROR", errno);
Deepak Kodihalli9d494bb2019-11-05 01:28:43 -060054 return -1;
55 }
56 pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg);
Riya Dixit087a7512024-04-06 14:28:08 -050057 info(
58 "Done! Got the response for PLDM send receive message request, response code '{RC}'",
59 "RC", lg2::hex, static_cast<uint16_t>(response->payload[0]));
Deepak Kodihalli9d494bb2019-11-05 01:28:43 -060060 free(responseMsg);
61
62 return 0;
63}