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; |
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 | { |
Pavithra Barithaya | f5ad6c7 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 53 | |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 54 | public: |
| 55 | explicit CommandInterface(const char* type, const char* name, |
| 56 | CLI::App* app) : |
| 57 | pldmType(type), |
Pavithra Barithaya | ac3c45a | 2020-03-05 02:28:26 -0600 | [diff] [blame] | 58 | commandName(name), mctp_eid(PLDM_ENTITY_ID), instanceId(0) |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 59 | { |
Pavithra Barithaya | f5ad6c7 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 60 | app->add_option("-m,--mctp_eid", mctp_eid, "MCTP endpoint ID"); |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 61 | app->callback([&]() { exec(); }); |
| 62 | } |
| 63 | virtual ~CommandInterface() = default; |
| 64 | |
| 65 | virtual std::pair<int, std::vector<uint8_t>> createRequestMsg() = 0; |
| 66 | |
| 67 | virtual void parseResponseMsg(struct pldm_msg* responsePtr, |
| 68 | size_t payloadLength) = 0; |
| 69 | |
John Wang | b754eee | 2020-02-15 16:10:25 +0800 | [diff] [blame] | 70 | virtual void exec(); |
| 71 | |
| 72 | int pldmSendRecv(std::vector<uint8_t>& requestMsg, |
| 73 | std::vector<uint8_t>& responseMsg); |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 74 | |
| 75 | private: |
| 76 | const std::string pldmType; |
| 77 | const std::string commandName; |
Pavithra Barithaya | f5ad6c7 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 78 | uint8_t mctp_eid; |
Pavithra Barithaya | ac3c45a | 2020-03-05 02:28:26 -0600 | [diff] [blame] | 79 | |
| 80 | protected: |
| 81 | uint8_t instanceId; |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | } // namespace helper |
| 85 | } // namespace pldmtool |