blob: b20cb22aeb7b958aca66f02343074297fa54893b [file] [log] [blame]
Deepak Kodihalli9d494bb2019-11-05 01:28:43 -06001#include <CLI/CLI.hpp>
2#include <array>
3#include <iostream>
4
5#include "libpldm/platform.h"
6#include "libpldm/requester/pldm.h"
7
8int 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
Sampa Misraaa8ae722019-12-12 03:20:40 -060032 << std::showbase << rc << "\n";
Deepak Kodihalli9d494bb2019-11-05 01:28:43 -060033 return -1;
34 }
35
36 // Open connection to MCTP socket
37 int fd = pldm_open();
38 if (-1 == fd)
39 {
Sampa Misraaa8ae722019-12-12 03:20:40 -060040 std::cerr << "Failed to init mctp"
41 << "\n";
Deepak Kodihalli9d494bb2019-11-05 01:28:43 -060042 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
Sampa Misraaa8ae722019-12-12 03:20:40 -060053 << ", errno = " << errno << "\n";
Deepak Kodihalli9d494bb2019-11-05 01:28:43 -060054 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}