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