blob: 5384fa12b77de3f4e12274059ff46c26e791064b [file] [log] [blame]
Deepak Kodihalli9d494bb2019-11-05 01:28:43 -06001#include "libpldm/platform.h"
Andrew Jeffery27a022c2022-08-10 23:12:49 +09302#include "libpldm/pldm.h"
Deepak Kodihalli9d494bb2019-11-05 01:28:43 -06003
George Liu6492f522020-06-16 10:34:05 +08004#include <CLI/CLI.hpp>
5
6#include <array>
7#include <iostream>
8
Deepak Kodihalli9d494bb2019-11-05 01:28:43 -06009int 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
Sampa Misraaa8ae722019-12-12 03:20:40 -060033 << std::showbase << rc << "\n";
Deepak Kodihalli9d494bb2019-11-05 01:28:43 -060034 return -1;
35 }
36
37 // Open connection to MCTP socket
38 int fd = pldm_open();
39 if (-1 == fd)
40 {
Sampa Misraaa8ae722019-12-12 03:20:40 -060041 std::cerr << "Failed to init mctp"
42 << "\n";
Deepak Kodihalli9d494bb2019-11-05 01:28:43 -060043 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
Sampa Misraaa8ae722019-12-12 03:20:40 -060054 << ", errno = " << errno << "\n";
Deepak Kodihalli9d494bb2019-11-05 01:28:43 -060055 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}