blob: 80607510a4486c756491d727bf808e05280419b5 [file] [log] [blame]
Lakshminarayana R. Kammath27693a42019-06-24 00:51:47 -05001#pragma once
2
George Liu83409572019-12-24 18:42:54 +08003#include "utils.hpp"
Lakshminarayana R. Kammath27693a42019-06-24 00:51:47 -05004
5#include <err.h>
6#include <sys/socket.h>
7#include <sys/un.h>
8#include <unistd.h>
9
John Wang58a0e062019-11-08 15:38:15 +080010#include <CLI/CLI.hpp>
Lakshminarayana R. Kammath27693a42019-06-24 00:51:47 -050011#include <cstring>
12#include <iomanip>
13#include <iostream>
John Wang58a0e062019-11-08 15:38:15 +080014#include <utility>
Lakshminarayana R. Kammath27693a42019-06-24 00:51:47 -050015
16#include "libpldm/base.h"
Sridevi Ramesh98576432019-11-27 10:10:28 -060017#include "libpldm/bios.h"
Sridevi Rameshd4489752019-12-08 09:03:29 -060018#include "libpldm/fru.h"
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -050019#include "libpldm/platform.h"
Lakshminarayana R. Kammath27693a42019-06-24 00:51:47 -050020
John Wang58a0e062019-11-08 15:38:15 +080021namespace pldmtool
22{
23
24namespace helper
25{
26
George Liu83409572019-12-24 18:42:54 +080027using namespace pldm::utils;
John Wang58a0e062019-11-08 15:38:15 +080028constexpr uint8_t PLDM_ENTITY_ID = 8;
29constexpr uint8_t MCTP_MSG_TYPE_PLDM = 1;
30constexpr uint8_t PLDM_LOCAL_INSTANCE_ID = 0;
Lakshminarayana R. Kammath27693a42019-06-24 00:51:47 -050031
32/** @brief Print the buffer
33 *
34 * @param[in] buffer - Buffer to print
35 *
36 * @return - None
37 */
38void printBuffer(const std::vector<uint8_t>& buffer);
39
40/** @brief MCTP socket read/recieve
41 *
42 * @param[in] requestMsg - Request message to compare against loopback
43 * message recieved from mctp socket
44 * @param[out] responseMsg - Response buffer recieved from mctp socket
45 *
46 * @return - 0 on success.
47 * -1 or -errno on failure.
48 */
49int mctpSockSendRecv(const std::vector<uint8_t>& requestMsg,
50 std::vector<uint8_t>& responseMsg);
51
John Wang58a0e062019-11-08 15:38:15 +080052class CommandInterface
53{
54 public:
55 explicit CommandInterface(const char* type, const char* name,
56 CLI::App* app) :
57 pldmType(type),
58 commandName(name)
59 {
60 app->callback([&]() { exec(); });
61 }
62 virtual ~CommandInterface() = default;
63
64 virtual std::pair<int, std::vector<uint8_t>> createRequestMsg() = 0;
65
66 virtual void parseResponseMsg(struct pldm_msg* responsePtr,
67 size_t payloadLength) = 0;
68
John Wangb754eee2020-02-15 16:10:25 +080069 virtual void exec();
70
71 int pldmSendRecv(std::vector<uint8_t>& requestMsg,
72 std::vector<uint8_t>& responseMsg);
John Wang58a0e062019-11-08 15:38:15 +080073
74 private:
75 const std::string pldmType;
76 const std::string commandName;
77};
78
79} // namespace helper
80} // namespace pldmtool