blob: 395529b87494284f887a02883efdb2ece0c22c54 [file] [log] [blame]
Deepak Kodihalli1b24f972019-02-01 04:09:13 -06001#include "libpldm/base.h"
2
George Liu6492f522020-06-16 10:34:05 +08003#include "libpldm/bios.h"
4#include "libpldm/fru.h"
5#include "libpldm/platform.h"
6
Deepak Kodihalli1b24f972019-02-01 04:09:13 -06007#include "base.hpp"
8
9#include <array>
Sampa Misra432e1872019-02-13 03:49:43 -060010#include <cstring>
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060011#include <map>
12#include <stdexcept>
13#include <vector>
14
Sridevi Ramesh45e52542020-04-03 07:54:18 -050015#ifdef OEM_IBM
16#include "libpldm/file_io.h"
17#include "libpldm/host.h"
18#endif
19
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060020namespace pldm
21{
Deepak Kodihallibc669f12019-11-28 08:52:07 -060022
23using Type = uint8_t;
24
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060025namespace responder
26{
27
28using Cmd = std::vector<uint8_t>;
29
30static const std::map<Type, Cmd> capabilities{
Zahed Hossain5e4e3832019-07-05 03:43:18 -050031 {PLDM_BASE,
John Wang5c4f80d2019-07-29 11:12:18 +080032 {PLDM_GET_TID, PLDM_GET_PLDM_VERSION, PLDM_GET_PLDM_TYPES,
33 PLDM_GET_PLDM_COMMANDS}},
Sridevi Ramesh8fb11c92021-06-08 08:45:01 -050034 {PLDM_PLATFORM,
35 {PLDM_GET_PDR, PLDM_SET_STATE_EFFECTER_STATES, PLDM_SET_EVENT_RECEIVER,
36 PLDM_GET_SENSOR_READING, PLDM_GET_STATE_SENSOR_READINGS,
37 PLDM_SET_NUMERIC_EFFECTER_VALUE, PLDM_GET_NUMERIC_EFFECTER_VALUE,
38 PLDM_PLATFORM_EVENT_MESSAGE}},
John Wang8721ed62019-12-05 14:44:43 +080039 {PLDM_BIOS,
Sridevi Rameshf58d9a52020-02-14 00:30:58 -060040 {PLDM_GET_DATE_TIME, PLDM_SET_DATE_TIME, PLDM_GET_BIOS_TABLE,
Xiaochao Mad3cf57e2019-12-31 14:22:38 +080041 PLDM_GET_BIOS_ATTRIBUTE_CURRENT_VALUE_BY_HANDLE,
Sridevi Ramesh8fb11c92021-06-08 08:45:01 -050042 PLDM_SET_BIOS_ATTRIBUTE_CURRENT_VALUE, PLDM_SET_BIOS_TABLE}},
John Wang5bdde3a2020-06-16 15:02:33 +080043 {PLDM_FRU,
44 {PLDM_GET_FRU_RECORD_TABLE_METADATA, PLDM_GET_FRU_RECORD_TABLE,
45 PLDM_GET_FRU_RECORD_BY_OPTION}},
Sridevi Ramesh45e52542020-04-03 07:54:18 -050046#ifdef OEM_IBM
47 {PLDM_OEM,
48 {PLDM_HOST_GET_ALERT_STATUS, PLDM_GET_FILE_TABLE, PLDM_READ_FILE,
49 PLDM_WRITE_FILE, PLDM_READ_FILE_INTO_MEMORY, PLDM_WRITE_FILE_FROM_MEMORY,
50 PLDM_READ_FILE_BY_TYPE_INTO_MEMORY, PLDM_WRITE_FILE_BY_TYPE_FROM_MEMORY,
51 PLDM_NEW_FILE_AVAILABLE, PLDM_READ_FILE_BY_TYPE, PLDM_WRITE_FILE_BY_TYPE,
52 PLDM_FILE_ACK}},
53#endif
54};
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060055
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -060056static const std::map<Type, ver32_t> versions{
Sampa Misra432e1872019-02-13 03:49:43 -060057 {PLDM_BASE, {0xF1, 0xF0, 0xF0, 0x00}},
Tom Joseph0bead972020-01-28 10:54:03 +053058 {PLDM_PLATFORM, {0xF1, 0xF2, 0xF0, 0x00}},
Zahed Hossain74c1c1e2019-06-18 02:13:48 -050059 {PLDM_BIOS, {0xF1, 0xF0, 0xF0, 0x00}},
Deepak Kodihalliec482972019-11-26 07:57:10 -060060 {PLDM_FRU, {0xF1, 0xF0, 0xF0, 0x00}},
Sridevi Ramesh45e52542020-04-03 07:54:18 -050061#ifdef OEM_IBM
62 {PLDM_OEM, {0xF1, 0xF0, 0xF0, 0x00}},
63#endif
Sampa Misra432e1872019-02-13 03:49:43 -060064};
65
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050066namespace base
67{
68
Deepak Kodihallibc669f12019-11-28 08:52:07 -060069Response Handler::getPLDMTypes(const pldm_msg* request,
70 size_t /*payloadLength*/)
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060071{
72 // DSP0240 has this as a bitfield8[N], where N = 0 to 7
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -060073 std::array<bitfield8_t, 8> types{};
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060074 for (const auto& type : capabilities)
75 {
76 auto index = type.first / 8;
77 // <Type Number> = <Array Index> * 8 + <bit position>
78 auto bit = type.first - (index * 8);
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -060079 types[index].byte |= 1 << bit;
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060080 }
81
vkaverapa6575b82019-04-03 05:33:52 -050082 Response response(sizeof(pldm_msg_hdr) + PLDM_GET_TYPES_RESP_BYTES, 0);
83 auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
George Liufb8611d2019-12-06 10:14:15 +080084 auto rc = encode_get_types_resp(request->hdr.instance_id, PLDM_SUCCESS,
85 types.data(), responsePtr);
86 if (rc != PLDM_SUCCESS)
87 {
88 return CmdHandler::ccOnlyResponse(request, rc);
89 }
vkaverapa6575b82019-04-03 05:33:52 -050090
91 return response;
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060092}
93
Deepak Kodihallibc669f12019-11-28 08:52:07 -060094Response Handler::getPLDMCommands(const pldm_msg* request, size_t payloadLength)
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060095{
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -060096 ver32_t version{};
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060097 Type type;
98
vkaverapa6575b82019-04-03 05:33:52 -050099 Response response(sizeof(pldm_msg_hdr) + PLDM_GET_COMMANDS_RESP_BYTES, 0);
100 auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600101
Zahed Hossain223a73d2019-07-04 12:46:18 -0500102 auto rc = decode_get_commands_req(request, payloadLength, &type, &version);
vkaverapa6575b82019-04-03 05:33:52 -0500103
104 if (rc != PLDM_SUCCESS)
105 {
George Liufb8611d2019-12-06 10:14:15 +0800106 return CmdHandler::ccOnlyResponse(request, rc);
vkaverapa6575b82019-04-03 05:33:52 -0500107 }
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600108
109 // DSP0240 has this as a bitfield8[N], where N = 0 to 31
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600110 std::array<bitfield8_t, 32> cmds{};
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600111 if (capabilities.find(type) == capabilities.end())
112 {
George Liufb8611d2019-12-06 10:14:15 +0800113 return CmdHandler::ccOnlyResponse(request,
114 PLDM_ERROR_INVALID_PLDM_TYPE);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600115 }
116
117 for (const auto& cmd : capabilities.at(type))
118 {
119 auto index = cmd / 8;
120 // <Type Number> = <Array Index> * 8 + <bit position>
121 auto bit = cmd - (index * 8);
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600122 cmds[index].byte |= 1 << bit;
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600123 }
124
George Liufb8611d2019-12-06 10:14:15 +0800125 rc = encode_get_commands_resp(request->hdr.instance_id, PLDM_SUCCESS,
126 cmds.data(), responsePtr);
127 if (rc != PLDM_SUCCESS)
128 {
129 return ccOnlyResponse(request, rc);
130 }
vkaverapa6575b82019-04-03 05:33:52 -0500131
132 return response;
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600133}
134
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600135Response Handler::getPLDMVersion(const pldm_msg* request, size_t payloadLength)
Sampa Misra432e1872019-02-13 03:49:43 -0600136{
137 uint32_t transferHandle;
138 Type type;
139 uint8_t transferFlag;
140
vkaverapa6575b82019-04-03 05:33:52 -0500141 Response response(sizeof(pldm_msg_hdr) + PLDM_GET_VERSION_RESP_BYTES, 0);
142 auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
Sampa Misra432e1872019-02-13 03:49:43 -0600143
Zahed Hossain223a73d2019-07-04 12:46:18 -0500144 uint8_t rc = decode_get_version_req(request, payloadLength, &transferHandle,
145 &transferFlag, &type);
vkaverapa6575b82019-04-03 05:33:52 -0500146
147 if (rc != PLDM_SUCCESS)
148 {
George Liufb8611d2019-12-06 10:14:15 +0800149 return CmdHandler::ccOnlyResponse(request, rc);
vkaverapa6575b82019-04-03 05:33:52 -0500150 }
Sampa Misra432e1872019-02-13 03:49:43 -0600151
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600152 ver32_t version{};
Sampa Misra432e1872019-02-13 03:49:43 -0600153 auto search = versions.find(type);
154
155 if (search == versions.end())
156 {
George Liufb8611d2019-12-06 10:14:15 +0800157 return CmdHandler::ccOnlyResponse(request,
158 PLDM_ERROR_INVALID_PLDM_TYPE);
Sampa Misra432e1872019-02-13 03:49:43 -0600159 }
160
161 memcpy(&version, &(search->second), sizeof(version));
George Liufb8611d2019-12-06 10:14:15 +0800162 rc = encode_get_version_resp(request->hdr.instance_id, PLDM_SUCCESS, 0,
163 PLDM_START_AND_END, &version,
164 sizeof(pldm_version), responsePtr);
165 if (rc != PLDM_SUCCESS)
166 {
167 return ccOnlyResponse(request, rc);
168 }
vkaverapa6575b82019-04-03 05:33:52 -0500169
170 return response;
Sampa Misra432e1872019-02-13 03:49:43 -0600171}
172
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600173Response Handler::getTID(const pldm_msg* request, size_t /*payloadLength*/)
John Wang5c4f80d2019-07-29 11:12:18 +0800174{
175 // assigned 1 to the bmc as the PLDM terminus
176 uint8_t tid = 1;
177
178 Response response(sizeof(pldm_msg_hdr) + PLDM_GET_TID_RESP_BYTES, 0);
179 auto responsePtr = reinterpret_cast<pldm_msg*>(response.data());
George Liufb8611d2019-12-06 10:14:15 +0800180 auto rc = encode_get_tid_resp(request->hdr.instance_id, PLDM_SUCCESS, tid,
181 responsePtr);
182 if (rc != PLDM_SUCCESS)
183 {
184 return ccOnlyResponse(request, rc);
185 }
John Wang5c4f80d2019-07-29 11:12:18 +0800186
187 return response;
188}
189
Deepak Kodihallibc669f12019-11-28 08:52:07 -0600190} // namespace base
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600191} // namespace responder
192} // namespace pldm