Lakshminarayana R. Kammath | 27693a4 | 2019-06-24 00:51:47 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Lakshminarayana R. Kammath | 27693a4 | 2019-06-24 00:51:47 -0500 | [diff] [blame] | 3 | #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 Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 10 | #include <CLI/CLI.hpp> |
Lakshminarayana R. Kammath | 27693a4 | 2019-06-24 00:51:47 -0500 | [diff] [blame] | 11 | #include <cstring> |
| 12 | #include <iomanip> |
| 13 | #include <iostream> |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 14 | #include <utility> |
Lakshminarayana R. Kammath | 27693a4 | 2019-06-24 00:51:47 -0500 | [diff] [blame] | 15 | |
| 16 | #include "libpldm/base.h" |
Lakshminarayana R. Kammath | 58229b2 | 2019-08-09 06:30:04 -0500 | [diff] [blame] | 17 | #include "libpldm/platform.h" |
Lakshminarayana R. Kammath | 27693a4 | 2019-06-24 00:51:47 -0500 | [diff] [blame] | 18 | |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 19 | namespace pldmtool |
| 20 | { |
| 21 | |
| 22 | namespace helper |
| 23 | { |
| 24 | |
Lakshminarayana R. Kammath | 27693a4 | 2019-06-24 00:51:47 -0500 | [diff] [blame] | 25 | using namespace pldm::responder::utils; |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 26 | constexpr uint8_t PLDM_ENTITY_ID = 8; |
| 27 | constexpr uint8_t MCTP_MSG_TYPE_PLDM = 1; |
| 28 | constexpr uint8_t PLDM_LOCAL_INSTANCE_ID = 0; |
Lakshminarayana R. Kammath | 27693a4 | 2019-06-24 00:51:47 -0500 | [diff] [blame] | 29 | |
| 30 | /** @brief Print the buffer |
| 31 | * |
| 32 | * @param[in] buffer - Buffer to print |
| 33 | * |
| 34 | * @return - None |
| 35 | */ |
| 36 | void 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 | */ |
| 47 | int mctpSockSendRecv(const std::vector<uint8_t>& requestMsg, |
| 48 | std::vector<uint8_t>& responseMsg); |
| 49 | |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 50 | class 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 |