PLDMTOOL : Implement a PLDM requester tool.
Implemented a way for sending PLDM requests for specific PLDM commands.
This tool will interact with MCTP daemon using UNIX domain socket, The
response got from socket will be displayed on the console in raw format.
Tested following PLDM commands:
1) GetPLDMTypes
2) GetPLDMVersion
Tested : Verified the RAW response data.
./pldmtool -c GetPLDMTypes
Encoded request succesfully : RC = 0
Request Message:
08 01 9b 00 04 00 00
Success in creating the socket : RC = 3
Success in connecting to socket : RC = 0
Success in sending message type as pldm to mctp : RC = 0
Write to socket successful : RC = 7
Total length:7
Loopback response message:
08 01 9b 00 04 00 00
On first recv(),response == request : RC = 0
Total length: 14
Shutdown Socket successful : RC = 0
Socket recv() successful : RC = 0
Response Message :
08 01 00 00 04 00 01 00 00 00 00 00 00 00
./pldmtool -c GetPLDMVersion base
PLDM Type requested : base
Encoded request succesfully : RC = 0
Request Message:
08 01 9b 00 03 00 00 00 00 01 00
Success in creating the socket : RC = 3
Success in connecting to socket : RC = 0
Success in sending message type as pldm to mctp : RC = 0
Write to socket successful : RC = 11
Total length:11
Loopback response message:
08 01 9b 00 03 00 00 00 00 01 00
On first recv(),response == request : RC = 0
Total length: 15
Shutdown Socket successful : RC = 0
Socket recv() successful : RC = 0
Response Message:
08 01 00 00 03 00 00 00 00 00 05 f1 f0 f0 00
./pldmtool -h
PLDM requester tool for OpenBMC
Usage: ./pldmtool [OPTIONS] —command... [GetPLDMTypes] [GetPLDMVersion] SUBCOMMA ND
Positionals:
—command TEXT ... REQUIRED
PLDM request command
GetPLDMTypes TEXT Get PLDM Type
GetPLDMVersion TEXT Get PLDM Version
Options:
-h,--help Print this help message and exit
-c TEXT ... REQUIRED PLDM request command
Subcommands:
BASE PLDM Command Type = BASE
BIOS PLDM Command Type = BIOS
OEM PLDM Command Type = OEM
Signed-off-by: Lakshminarayana R. Kammath <lkammath@in.ibm.com>
Change-Id: I758b5f5cf03ad9b91ce47144fe46cd79b41381f3
diff --git a/tool/pldm_cmd_helper.hpp b/tool/pldm_cmd_helper.hpp
new file mode 100644
index 0000000..6a4f087
--- /dev/null
+++ b/tool/pldm_cmd_helper.hpp
@@ -0,0 +1,41 @@
+#pragma once
+
+#ifndef PLDM_CMD_HELPER_H
+#define PLDM_CMD_HELPER_H
+
+#include "libpldmresponder/utils.hpp"
+
+#include <err.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <unistd.h>
+
+#include <cstring>
+#include <iomanip>
+#include <iostream>
+
+#include "libpldm/base.h"
+
+using namespace pldm::responder::utils;
+
+/** @brief Print the buffer
+ *
+ * @param[in] buffer - Buffer to print
+ *
+ * @return - None
+ */
+void printBuffer(const std::vector<uint8_t>& buffer);
+
+/** @brief MCTP socket read/recieve
+ *
+ * @param[in] requestMsg - Request message to compare against loopback
+ * message recieved from mctp socket
+ * @param[out] responseMsg - Response buffer recieved from mctp socket
+ *
+ * @return - 0 on success.
+ * -1 or -errno on failure.
+ */
+int mctpSockSendRecv(const std::vector<uint8_t>& requestMsg,
+ std::vector<uint8_t>& responseMsg);
+
+#endif