blob: aa5b668d2519b909a567a2090dae1b0baa51451d [file] [log] [blame]
Lakshminarayana R. Kammath27693a42019-06-24 00:51:47 -05001#include "pldm_base_cmd.hpp"
2
3#include "pldm_cmd_helper.hpp"
4
5#include <string>
6
7constexpr uint8_t PLDM_ENTITY_ID = 8;
8constexpr uint8_t MCTP_MSG_TYPE_PLDM = 1;
9constexpr uint8_t PLDM_LOCAL_INSTANCE_ID = 0;
10
11using namespace std;
12
13/*
14 * Main function that handles the GetPLDMTypes response callback via mctp
15 *
16 */
17void getPLDMTypes(vector<std::string>&& args)
18{
19 // Create and encode the request message
20 vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) +
21 sizeof(MCTP_MSG_TYPE_PLDM) +
22 sizeof(PLDM_ENTITY_ID));
23 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
24
25 // Encode the get_types request message
26 uint8_t instanceId = PLDM_LOCAL_INSTANCE_ID;
27 auto returnCode = encode_get_types_req(instanceId, request);
28 if (returnCode)
29 {
30 cerr << "Failed to encode request msg for GetPLDMType : RC = "
31 << returnCode << endl;
32 return;
33 }
34 cout << "Encoded request succesfully : RC = " << returnCode << endl;
35
36 // Insert the PLDM message type and EID at the begining of the request msg.
37 requestMsg.insert(requestMsg.begin(), MCTP_MSG_TYPE_PLDM);
38 requestMsg.insert(requestMsg.begin(), PLDM_ENTITY_ID);
39
40 cout << "Request Message:" << endl;
41 printBuffer(requestMsg);
42
43 // Create the response message
44 vector<uint8_t> responseMsg;
45
46 // Compares the response with request packet on first socket recv() call.
47 // If above condition is qualified then, reads the actual response from
48 // the socket to output buffer responseMsg.
49 returnCode = mctpSockSendRecv(requestMsg, responseMsg);
50 if (!returnCode)
51 {
52 cout << "Socket recv() successful : RC = " << returnCode << endl;
53 cout << "Response Message : " << endl;
54 printBuffer(responseMsg);
55 }
56 else
57 {
58 cerr << "Failed to recieve from socket : RC = " << returnCode << endl;
59 return;
60 }
61}
62
63/*
64 * Main function that handles the GetPLDMVersion response callback via mctp
65 *
66 */
67void getPLDMVersion(vector<std::string>&& args)
68{
69 // Create a request packet
70 std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) +
71 PLDM_GET_VERSION_REQ_BYTES);
72 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
73 uint8_t pldmType = 0x0;
74
75 if (!args[1].c_str())
76 {
77 cout << "Mandatory argument PLDM Command Type not provided!" << endl;
78 cout << "Run pldmtool --help for more information" << endl;
79 return;
80 }
81
82 if (!strcasecmp(args[1].c_str(), "base"))
83 {
84 cout << "PLDM Type requested : " << args[1] << endl;
85 pldmType = PLDM_BASE;
86 }
87 else
88 {
89 cerr << "Unsupported pldm command type OR not supported yet : "
90 << args[1] << endl;
91 return;
92 }
93
94 uint8_t instanceId = PLDM_LOCAL_INSTANCE_ID;
95 uint32_t transferHandle = 0x0;
96 transfer_op_flag opFlag = PLDM_GET_FIRSTPART;
97
98 // encode the get_version request
99 auto returnCode = encode_get_version_req(instanceId, transferHandle, opFlag,
100 pldmType, request);
101 if (returnCode)
102 {
103 cerr << "Failed to encode request msg for GetPLDMVersion. RC = "
104 << returnCode << endl;
105 return;
106 }
107 cout << "Encoded request succesfully : RC = " << returnCode << endl;
108
109 // Insert the PLDM message type and EID at the begining of the request msg.
110 requestMsg.insert(requestMsg.begin(), MCTP_MSG_TYPE_PLDM);
111 requestMsg.insert(requestMsg.begin(), PLDM_ENTITY_ID);
112
113 cout << "Request Message:" << endl;
114 printBuffer(requestMsg);
115
116 // Create the response message
117 vector<uint8_t> responseMsg;
118
119 // Compares the response with request packet on first socket recv() call.
120 // If above condition is qualified then, reads the actual response from
121 // the socket to output buffer responseMsg.
122 returnCode = mctpSockSendRecv(requestMsg, responseMsg);
123 if (!returnCode)
124 {
125 cout << "Socket recv() successful : RC = " << returnCode << endl;
126 cout << "Response Message:" << endl;
127 printBuffer(responseMsg);
128 }
129 else
130 {
131 cerr << "Failed to recieve from socket : RC = " << returnCode << endl;
132 return;
133 }
134}