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