Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 1 | #include "common/transport.hpp" |
| 2 | |
George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 3 | #include <libpldm/platform.h> |
Deepak Kodihalli | 9d494bb | 2019-11-05 01:28:43 -0600 | [diff] [blame] | 4 | |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 5 | #include <CLI/CLI.hpp> |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 6 | #include <phosphor-logging/lg2.hpp> |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 7 | |
| 8 | #include <array> |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 9 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 10 | PHOSPHOR_LOG2_USING; |
| 11 | |
Deepak Kodihalli | 9d494bb | 2019-11-05 01:28:43 -0600 | [diff] [blame] | 12 | int 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 Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 35 | error("Message encode failure. PLDM error code = {RC}", "RC", lg2::hex, |
| 36 | rc); |
Deepak Kodihalli | 9d494bb | 2019-11-05 01:28:43 -0600 | [diff] [blame] | 37 | return -1; |
| 38 | } |
| 39 | |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 40 | PldmTransport pldmTransport{}; |
Deepak Kodihalli | 9d494bb | 2019-11-05 01:28:43 -0600 | [diff] [blame] | 41 | |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 42 | void* responseMsg = nullptr; |
Deepak Kodihalli | 9d494bb | 2019-11-05 01:28:43 -0600 | [diff] [blame] | 43 | size_t responseMsgSize{}; |
| 44 | // Send PLDM request msg and wait for response |
Rashmica Gupta | 1ed5f7a | 2023-05-22 13:56:42 +1000 | [diff] [blame] | 45 | rc = pldmTransport.sendRecvMsg(static_cast<pldm_tid_t>(mctpEid), |
| 46 | requestMsg.data(), requestMsg.size(), |
| 47 | responseMsg, responseMsgSize); |
Deepak Kodihalli | 9d494bb | 2019-11-05 01:28:43 -0600 | [diff] [blame] | 48 | if (0 > rc) |
| 49 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 50 | error( |
| 51 | "Failed to send message/receive response. RC = {RC}, errno = {ERR}", |
| 52 | "RC", rc, "ERR", errno); |
Deepak Kodihalli | 9d494bb | 2019-11-05 01:28:43 -0600 | [diff] [blame] | 53 | return -1; |
| 54 | } |
| 55 | pldm_msg* response = reinterpret_cast<pldm_msg*>(responseMsg); |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 56 | info("Done. PLDM RC = {RC}", "RC", lg2::hex, |
| 57 | static_cast<uint16_t>(response->payload[0])); |
Deepak Kodihalli | 9d494bb | 2019-11-05 01:28:43 -0600 | [diff] [blame] | 58 | free(responseMsg); |
| 59 | |
| 60 | return 0; |
| 61 | } |