Lakshminarayana R. Kammath | 27693a4 | 2019-06-24 00:51:47 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 3 | #include "utils.hpp" |
Lakshminarayana R. Kammath | 27693a4 | 2019-06-24 00:51:47 -0500 | [diff] [blame] | 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" |
Sridevi Ramesh | d448975 | 2019-12-08 09:03:29 -0600 | [diff] [blame] | 18 | #include "libpldm/fru.h" |
Lakshminarayana R. Kammath | 58229b2 | 2019-08-09 06:30:04 -0500 | [diff] [blame] | 19 | #include "libpldm/platform.h" |
Lakshminarayana R. Kammath | 27693a4 | 2019-06-24 00:51:47 -0500 | [diff] [blame] | 20 | |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 21 | namespace pldmtool |
| 22 | { |
| 23 | |
| 24 | namespace helper |
| 25 | { |
| 26 | |
George Liu | 8340957 | 2019-12-24 18:42:54 +0800 | [diff] [blame] | 27 | using namespace pldm::utils; |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 28 | constexpr uint8_t PLDM_ENTITY_ID = 8; |
| 29 | constexpr uint8_t MCTP_MSG_TYPE_PLDM = 1; |
| 30 | constexpr uint8_t PLDM_LOCAL_INSTANCE_ID = 0; |
Lakshminarayana R. Kammath | 27693a4 | 2019-06-24 00:51:47 -0500 | [diff] [blame] | 31 | |
| 32 | /** @brief Print the buffer |
| 33 | * |
| 34 | * @param[in] buffer - Buffer to print |
| 35 | * |
| 36 | * @return - None |
| 37 | */ |
| 38 | void 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 | */ |
| 49 | int mctpSockSendRecv(const std::vector<uint8_t>& requestMsg, |
| 50 | std::vector<uint8_t>& responseMsg); |
| 51 | |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 52 | class 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 | |
| 69 | void exec(); |
| 70 | |
| 71 | private: |
| 72 | const std::string pldmType; |
| 73 | const std::string commandName; |
| 74 | }; |
| 75 | |
| 76 | } // namespace helper |
| 77 | } // namespace pldmtool |