blob: a162de47157d238f11a29ab87814545d1dd65875 [file] [log] [blame]
Lakshminarayana R. Kammath27693a42019-06-24 00:51:47 -05001#pragma once
2
Lakshminarayana R. Kammath27693a42019-06-24 00:51:47 -05003#include "libpldmresponder/utils.hpp"
4
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"
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -050017#include "libpldm/platform.h"
Lakshminarayana R. Kammath27693a42019-06-24 00:51:47 -050018
John Wang58a0e062019-11-08 15:38:15 +080019namespace pldmtool
20{
21
22namespace helper
23{
24
Lakshminarayana R. Kammath27693a42019-06-24 00:51:47 -050025using namespace pldm::responder::utils;
John Wang58a0e062019-11-08 15:38:15 +080026constexpr uint8_t PLDM_ENTITY_ID = 8;
27constexpr uint8_t MCTP_MSG_TYPE_PLDM = 1;
28constexpr uint8_t PLDM_LOCAL_INSTANCE_ID = 0;
Lakshminarayana R. Kammath27693a42019-06-24 00:51:47 -050029
30/** @brief Print the buffer
31 *
32 * @param[in] buffer - Buffer to print
33 *
34 * @return - None
35 */
36void printBuffer(const std::vector<uint8_t>& buffer);
37
38/** @brief MCTP socket read/recieve
39 *
40 * @param[in] requestMsg - Request message to compare against loopback
41 * message recieved from mctp socket
42 * @param[out] responseMsg - Response buffer recieved from mctp socket
43 *
44 * @return - 0 on success.
45 * -1 or -errno on failure.
46 */
47int mctpSockSendRecv(const std::vector<uint8_t>& requestMsg,
48 std::vector<uint8_t>& responseMsg);
49
John Wang58a0e062019-11-08 15:38:15 +080050class CommandInterface
51{
52 public:
53 explicit CommandInterface(const char* type, const char* name,
54 CLI::App* app) :
55 pldmType(type),
56 commandName(name)
57 {
58 app->callback([&]() { exec(); });
59 }
60 virtual ~CommandInterface() = default;
61
62 virtual std::pair<int, std::vector<uint8_t>> createRequestMsg() = 0;
63
64 virtual void parseResponseMsg(struct pldm_msg* responsePtr,
65 size_t payloadLength) = 0;
66
67 void exec();
68
69 private:
70 const std::string pldmType;
71 const std::string commandName;
72};
73
74} // namespace helper
75} // namespace pldmtool