blob: a33d0b2e2fbe76af7b7eae265751e15a7d4d8b6c [file] [log] [blame]
Vernon Mauerya3702c12019-05-22 13:20:59 -07001/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16
17#include <errno.h>
18#include <fcntl.h>
Vernon Mauerya3702c12019-05-22 13:20:59 -070019#include <limits.h>
20#include <sys/stat.h>
21#include <sys/types.h>
22#include <unistd.h>
23
24#include <commandutils.hpp>
25#include <cstdint>
26#include <fstream>
jayaprakash Mutyala853d8292019-05-31 18:17:42 +000027#include <ipmid/api.hpp>
Vernon Mauerya3702c12019-05-22 13:20:59 -070028#include <ipmid/utils.hpp>
Vernon Mauery98bbf692019-09-16 11:14:59 -070029#include <oemcommands.hpp>
Vernon Mauerya3702c12019-05-22 13:20:59 -070030#include <phosphor-logging/log.hpp>
Vernon Mauerya3702c12019-05-22 13:20:59 -070031#include <sdbusplus/message/types.hpp>
32#include <smbiosmdrv2handler.hpp>
33#include <string>
34#include <vector>
35#include <xyz/openbmc_project/Common/error.hpp>
Vernon Mauerya3702c12019-05-22 13:20:59 -070036
37std::unique_ptr<MDRV2> mdrv2 = nullptr;
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +000038static constexpr const uint8_t ccOemInvalidChecksum = 0x85;
jayaprakash Mutyala40fec612019-06-19 11:53:03 +000039static constexpr size_t dataInfoSize = 16;
jayaprakash Mutyala7cb59cc2019-06-19 19:17:43 +000040static constexpr const uint8_t ccStorageLeak = 0xC4;
Vernon Mauerya3702c12019-05-22 13:20:59 -070041
Vernon Mauerya3702c12019-05-22 13:20:59 -070042static void register_netfn_smbiosmdrv2_functions() __attribute__((constructor));
Vernon Mauerya3702c12019-05-22 13:20:59 -070043
44int MDRV2::agentLookup(const uint16_t &agentId)
45{
46 int agentIndex = -1;
47
48 if (lastAgentId == agentId)
49 {
50 return lastAgentIndex;
51 }
52
53 if (agentId == smbiosAgentId)
54 {
55 return firstAgentIndex;
56 }
57
58 return agentIndex;
59}
60
61int MDRV2::sdplusMdrv2GetProperty(const std::string &name,
Patrick Williams886a48a2020-05-13 17:44:37 -050062 std::variant<uint8_t> &value,
Vernon Mauerya3702c12019-05-22 13:20:59 -070063 const std::string &service)
64{
Vernon Mauery15419dd2019-05-24 09:40:30 -070065 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
Vernon Mauerya3702c12019-05-22 13:20:59 -070066 sdbusplus::message::message method =
Vernon Mauery15419dd2019-05-24 09:40:30 -070067 bus->new_method_call(service.c_str(), mdrv2Path, dbusProperties, "Get");
Vernon Mauerya3702c12019-05-22 13:20:59 -070068 method.append(mdrv2Interface, name);
69
Vernon Mauery15419dd2019-05-24 09:40:30 -070070 sdbusplus::message::message reply = bus->call(method);
Vernon Mauerya3702c12019-05-22 13:20:59 -070071
72 try
73 {
Vernon Mauery15419dd2019-05-24 09:40:30 -070074 sdbusplus::message::message reply = bus->call(method);
Vernon Mauerya3702c12019-05-22 13:20:59 -070075 reply.read(value);
76 }
Vernon Maueryc7d517e2019-06-18 14:27:00 -070077 catch (sdbusplus::exception_t &e)
Vernon Mauerya3702c12019-05-22 13:20:59 -070078 {
79 phosphor::logging::log<phosphor::logging::level::ERR>(
Vernon Maueryc7d517e2019-06-18 14:27:00 -070080 "Error get property, sdbusplus call failed",
81 phosphor::logging::entry("ERROR=%s", e.what()));
Vernon Mauerya3702c12019-05-22 13:20:59 -070082 return -1;
83 }
84
85 return 0;
86}
87
88int MDRV2::syncDirCommonData(uint8_t idIndex, uint32_t size,
89 const std::string &service)
90{
91 std::vector<uint32_t> commonData;
Vernon Mauery15419dd2019-05-24 09:40:30 -070092 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
Vernon Mauerya3702c12019-05-22 13:20:59 -070093 sdbusplus::message::message method =
Vernon Mauery15419dd2019-05-24 09:40:30 -070094 bus->new_method_call(service.c_str(), mdrv2Path, mdrv2Interface,
95 "SynchronizeDirectoryCommonData");
Vernon Mauerya3702c12019-05-22 13:20:59 -070096 method.append(idIndex, size);
97
98 try
99 {
Vernon Mauery15419dd2019-05-24 09:40:30 -0700100 sdbusplus::message::message reply = bus->call(method);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700101 reply.read(commonData);
102 }
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700103 catch (sdbusplus::exception_t &e)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700104 {
105 phosphor::logging::log<phosphor::logging::level::ERR>(
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700106 "Error sync dir common data with service",
107 phosphor::logging::entry("ERROR=%s", e.what()));
Vernon Mauerya3702c12019-05-22 13:20:59 -0700108 return -1;
109 }
110
111 if (commonData.size() < syncDirCommonSize)
112 {
113 phosphor::logging::log<phosphor::logging::level::ERR>(
114 "Error sync dir common data - data length invalid");
115 return -1;
116 }
117 smbiosDir.dir[idIndex].common.dataSetSize = commonData.at(0);
118 smbiosDir.dir[idIndex].common.dataVersion = commonData.at(1);
119 smbiosDir.dir[idIndex].common.timestamp = commonData.at(2);
120
121 return 0;
122}
123
124int MDRV2::findDataId(const uint8_t *dataInfo, const size_t &len,
125 const std::string &service)
126{
127 int idIndex = -1;
128
129 if (dataInfo == nullptr)
130 {
131 phosphor::logging::log<phosphor::logging::level::ERR>(
132 "Error dataInfo, input is null point");
133 return -1;
134 }
135
Vernon Mauery15419dd2019-05-24 09:40:30 -0700136 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
137 sdbusplus::message::message method = bus->new_method_call(
Vernon Mauerya3702c12019-05-22 13:20:59 -0700138 service.c_str(), mdrv2Path, mdrv2Interface, "FindIdIndex");
139 std::vector<uint8_t> info;
140 info.resize(len);
141 std::copy(dataInfo, dataInfo + len, info.data());
142 method.append(info);
143
144 try
145 {
Vernon Mauery15419dd2019-05-24 09:40:30 -0700146 sdbusplus::message::message reply = bus->call(method);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700147 reply.read(idIndex);
148 }
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700149 catch (sdbusplus::exception_t &e)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700150 {
151 phosphor::logging::log<phosphor::logging::level::ERR>(
152 "Error find id index",
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700153 phosphor::logging::entry("ERROR=%s", e.what()),
Vernon Mauerya3702c12019-05-22 13:20:59 -0700154 phosphor::logging::entry("SERVICE=%s", service.c_str()),
155 phosphor::logging::entry("PATH=%s", mdrv2Path));
156 return -1;
157 }
158
159 return idIndex;
160}
161
162uint16_t MDRV2::getSessionHandle(Mdr2DirStruct *dir)
163{
164 if (dir == NULL)
165 {
166 phosphor::logging::log<phosphor::logging::level::ERR>(
167 "Empty dir point");
168 return 0;
169 }
170 dir->sessionHandle++;
171 if (dir->sessionHandle == 0)
172 {
173 dir->sessionHandle = 1;
174 }
175
176 return dir->sessionHandle;
177}
178
179int MDRV2::findLockHandle(const uint16_t &lockHandle)
180{
181 int idIndex = -1;
182
183 for (int index = 0; index < smbiosDir.dirEntries; index++)
184 {
185 if (lockHandle == smbiosDir.dir[index].lockHandle)
186 {
187 return index;
188 }
189 }
190
191 return idIndex;
192}
193
194bool MDRV2::smbiosIsUpdating(uint8_t index)
195{
196 if (index > maxDirEntries)
197 {
198 return false;
199 }
200 if (smbiosDir.dir[index].stage == MDR2SMBIOSStatusEnum::mdr2Updating)
201 {
202 return true;
203 }
204
205 return false;
206}
207
208uint32_t MDRV2::calcChecksum32(uint8_t *buf, uint32_t len)
209{
210 uint32_t sum = 0;
211
212 if (buf == nullptr)
213 {
214 return invalidChecksum;
215 }
216
217 for (uint32_t index = 0; index < len; index++)
218 {
219 sum += buf[index];
220 }
221
222 return sum;
223}
224
jayaprakash Mutyala853d8292019-05-31 18:17:42 +0000225/** @brief implements mdr2 agent status command
226 * @param agentId
227 * @param dirVersion
228 *
229 * @returns IPMI completion code plus response data
230 * - mdrVersion
231 * - agentVersion
232 * - dirVersion
233 * - dirEntries
234 * - dataRequest
235 */
236ipmi::RspType<uint8_t, uint8_t, uint8_t, uint8_t, uint8_t>
237 mdr2AgentStatus(uint16_t agentId, uint8_t dirVersion)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700238{
Vernon Mauerya3702c12019-05-22 13:20:59 -0700239 if (mdrv2 == nullptr)
240 {
241 mdrv2 = std::make_unique<MDRV2>();
242 }
243
jayaprakash Mutyala853d8292019-05-31 18:17:42 +0000244 int agentIndex = mdrv2->agentLookup(agentId);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700245 if (agentIndex == -1)
246 {
247 phosphor::logging::log<phosphor::logging::level::ERR>(
jayaprakash Mutyala853d8292019-05-31 18:17:42 +0000248 "Unknown agent id", phosphor::logging::entry("ID=%x", agentId));
249 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700250 }
251
jayaprakash Mutyala853d8292019-05-31 18:17:42 +0000252 constexpr uint8_t mdrVersion = mdr2Version;
253 constexpr uint8_t agentVersion = smbiosAgentVersion;
254 uint8_t dirVersionResp = mdrv2->smbiosDir.dirVersion;
255 uint8_t dirEntries = mdrv2->smbiosDir.dirEntries;
256 uint8_t dataRequest;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700257
jayaprakash Mutyala853d8292019-05-31 18:17:42 +0000258 if (mdrv2->smbiosDir.remoteDirVersion != dirVersion)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700259 {
jayaprakash Mutyala853d8292019-05-31 18:17:42 +0000260 mdrv2->smbiosDir.remoteDirVersion = dirVersion;
261 dataRequest =
Vernon Mauerya3702c12019-05-22 13:20:59 -0700262 static_cast<uint8_t>(DirDataRequestEnum::dirDataRequested);
263 }
264 else
265 {
jayaprakash Mutyala853d8292019-05-31 18:17:42 +0000266 dataRequest =
Vernon Mauerya3702c12019-05-22 13:20:59 -0700267 static_cast<uint8_t>(DirDataRequestEnum::dirDataNotRequested);
268 }
269
jayaprakash Mutyala853d8292019-05-31 18:17:42 +0000270 return ipmi::responseSuccess(mdrVersion, agentVersion, dirVersionResp,
271 dirEntries, dataRequest);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700272}
273
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000274/** @brief implements mdr2 get directory command
275 * @param agentId
276 * @param dirIndex
277 * @returns IPMI completion code plus response data
278 * - dataOut
279 */
280ipmi::RspType<std::vector<uint8_t>> mdr2GetDir(uint16_t agentId,
281 uint8_t dirIndex)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700282{
Vernon Mauery15419dd2019-05-24 09:40:30 -0700283 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
284 std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700285
286 if (mdrv2 == nullptr)
287 {
288 mdrv2 = std::make_unique<MDRV2>();
289 }
290
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000291 int agentIndex = mdrv2->agentLookup(agentId);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700292 if (agentIndex == -1)
293 {
294 phosphor::logging::log<phosphor::logging::level::ERR>(
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000295 "Unknown agent id", phosphor::logging::entry("ID=%x", agentId));
296 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700297 }
298
James Feist5ee2d8d2020-05-27 11:20:35 -0700299 std::variant<uint8_t> value = static_cast<uint8_t>(0);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700300 if (0 != mdrv2->sdplusMdrv2GetProperty("DirectoryEntries", value, service))
301 {
302 phosphor::logging::log<phosphor::logging::level::ERR>(
303 "Error getting DirEnries");
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000304 return ipmi::responseUnspecifiedError();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700305 }
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000306 if (dirIndex > std::get<uint8_t>(value))
Vernon Mauerya3702c12019-05-22 13:20:59 -0700307 {
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000308 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700309 }
310
Vernon Mauery15419dd2019-05-24 09:40:30 -0700311 sdbusplus::message::message method = bus->new_method_call(
Vernon Mauerya3702c12019-05-22 13:20:59 -0700312 service.c_str(), mdrv2Path, mdrv2Interface, "GetDirectoryInformation");
313
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000314 method.append(dirIndex);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700315
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000316 std::vector<uint8_t> dataOut;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700317 try
318 {
Vernon Mauery15419dd2019-05-24 09:40:30 -0700319 sdbusplus::message::message reply = bus->call(method);
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000320 reply.read(dataOut);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700321 }
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700322 catch (sdbusplus::exception_t &e)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700323 {
324 phosphor::logging::log<phosphor::logging::level::ERR>(
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700325 "Error get dir", phosphor::logging::entry("ERROR=%s", e.what()),
Vernon Mauerya3702c12019-05-22 13:20:59 -0700326 phosphor::logging::entry("SERVICE=%s", service.c_str()),
327 phosphor::logging::entry("PATH=%s", mdrv2Path));
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000328 return ipmi::responseResponseError();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700329 }
330
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000331 constexpr size_t getDirRespSize = 6;
332 if (dataOut.size() < getDirRespSize)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700333 {
334 phosphor::logging::log<phosphor::logging::level::ERR>(
335 "Error get dir, response length invalid");
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000336 return ipmi::responseUnspecifiedError();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700337 }
338
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000339 if (dataOut.size() > MAX_IPMI_BUFFER) // length + completion code should no
340 // more than MAX_IPMI_BUFFER
Vernon Mauerya3702c12019-05-22 13:20:59 -0700341 {
342 phosphor::logging::log<phosphor::logging::level::ERR>(
343 "Data length send from service is invalid");
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000344 return ipmi::responseResponseError();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700345 }
346
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000347 return ipmi::responseSuccess(dataOut);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700348}
349
jayaprakash Mutyala7cb59cc2019-06-19 19:17:43 +0000350ipmi::RspType<bool> mdr2SendDir(uint16_t agentId, uint8_t dirVersion,
351 uint8_t dirIndex, uint8_t returnedEntries,
352 uint8_t remainingEntries,
353 std::array<uint8_t, 16> dataInfo, uint32_t size,
354 uint32_t dataSetSize, uint32_t dataVersion,
355 uint32_t timestamp)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700356{
Vernon Mauery15419dd2019-05-24 09:40:30 -0700357 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
358 std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700359
360 if (mdrv2 == nullptr)
361 {
362 mdrv2 = std::make_unique<MDRV2>();
363 }
364
jayaprakash Mutyala7cb59cc2019-06-19 19:17:43 +0000365 int agentIndex = mdrv2->agentLookup(agentId);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700366 if (agentIndex == -1)
367 {
368 phosphor::logging::log<phosphor::logging::level::ERR>(
jayaprakash Mutyala7cb59cc2019-06-19 19:17:43 +0000369 "Unknown agent id", phosphor::logging::entry("ID=%x", agentId));
370 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700371 }
372
jayaprakash Mutyala7cb59cc2019-06-19 19:17:43 +0000373 if ((dirIndex + returnedEntries) > maxDirEntries)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700374 {
375 phosphor::logging::log<phosphor::logging::level::ERR>(
376 "Too many directory entries");
jayaprakash Mutyala7cb59cc2019-06-19 19:17:43 +0000377 return ipmi::response(ccStorageLeak);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700378 }
379
Vernon Mauery15419dd2019-05-24 09:40:30 -0700380 sdbusplus::message::message method = bus->new_method_call(
Vernon Mauerya3702c12019-05-22 13:20:59 -0700381 service.c_str(), mdrv2Path, mdrv2Interface, "SendDirectoryInformation");
jayaprakash Mutyala7cb59cc2019-06-19 19:17:43 +0000382 method.append(dirVersion, dirIndex, returnedEntries, remainingEntries,
383 dataInfo, size, dataSetSize, dataVersion, timestamp);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700384
jayaprakash Mutyala7cb59cc2019-06-19 19:17:43 +0000385 bool terminate = false;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700386 try
387 {
Vernon Mauery15419dd2019-05-24 09:40:30 -0700388 sdbusplus::message::message reply = bus->call(method);
jayaprakash Mutyala7cb59cc2019-06-19 19:17:43 +0000389 reply.read(terminate);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700390 }
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700391 catch (sdbusplus::exception_t &e)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700392 {
393 phosphor::logging::log<phosphor::logging::level::ERR>(
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700394 "Error send dir", phosphor::logging::entry("ERROR=%s", e.what()),
Vernon Mauerya3702c12019-05-22 13:20:59 -0700395 phosphor::logging::entry("SERVICE=%s", service.c_str()),
396 phosphor::logging::entry("PATH=%s", mdrv2Path));
jayaprakash Mutyala7cb59cc2019-06-19 19:17:43 +0000397 return ipmi::responseResponseError();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700398 }
399
jayaprakash Mutyala7cb59cc2019-06-19 19:17:43 +0000400 return ipmi::responseSuccess(terminate);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700401}
402
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000403/** @brief implements mdr2 get data info command
404 * @param agentId
405 * @param dataInfo
406 *
407 * @returns IPMI completion code plus response data
408 * - response - mdrVersion, data info, validFlag,
409 * dataLength, dataVersion, timeStamp
410 */
411ipmi::RspType<std::vector<uint8_t>>
412 mdr2GetDataInfo(uint16_t agentId, std::vector<uint8_t> dataInfo)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700413{
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000414 constexpr size_t getDataInfoReqSize = 16;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700415
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000416 if (dataInfo.size() < getDataInfoReqSize)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700417 {
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000418 return ipmi::responseReqDataLenInvalid();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700419 }
420
Vernon Mauery15419dd2019-05-24 09:40:30 -0700421 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
422 std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700423
424 if (mdrv2 == nullptr)
425 {
426 mdrv2 = std::make_unique<MDRV2>();
427 }
428
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000429 int agentIndex = mdrv2->agentLookup(agentId);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700430 if (agentIndex == -1)
431 {
432 phosphor::logging::log<phosphor::logging::level::ERR>(
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000433 "Unknown agent id", phosphor::logging::entry("ID=%x", agentId));
434 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700435 }
436
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000437 int idIndex = mdrv2->findDataId(dataInfo.data(), dataInfo.size(), service);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700438
439 if ((idIndex < 0) || (idIndex >= maxDirEntries))
440 {
441 phosphor::logging::log<phosphor::logging::level::ERR>(
442 "Invalid Data ID", phosphor::logging::entry("IDINDEX=%x", idIndex));
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000443 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700444 }
445
Vernon Mauery15419dd2019-05-24 09:40:30 -0700446 sdbusplus::message::message method = bus->new_method_call(
Vernon Mauerya3702c12019-05-22 13:20:59 -0700447 service.c_str(), mdrv2Path, mdrv2Interface, "GetDataInformation");
448
449 method.append(idIndex);
450
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000451 std::vector<uint8_t> res;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700452 try
453 {
Vernon Mauery15419dd2019-05-24 09:40:30 -0700454 sdbusplus::message::message reply = bus->call(method);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700455 reply.read(res);
456 }
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700457 catch (sdbusplus::exception_t &e)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700458 {
459 phosphor::logging::log<phosphor::logging::level::ERR>(
460 "Error get data info",
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700461 phosphor::logging::entry("ERROR=%s", e.what()),
Vernon Mauerya3702c12019-05-22 13:20:59 -0700462 phosphor::logging::entry("SERVICE=%s", service.c_str()),
463 phosphor::logging::entry("PATH=%s", mdrv2Path));
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000464 return ipmi::responseResponseError();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700465 }
466
467 if (res.size() != sizeof(MDRiiGetDataInfoResponse))
468 {
469 phosphor::logging::log<phosphor::logging::level::ERR>(
470 "Get data info response length not invalid");
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000471 return ipmi::responseResponseError();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700472 }
Vernon Mauerya3702c12019-05-22 13:20:59 -0700473
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000474 return ipmi::responseSuccess(res);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700475}
476
jayaprakash Mutyala853d8292019-05-31 18:17:42 +0000477/** @brief implements mdr2 data info offer command
478 * @param agentId - Offer a agent ID to get the "Data Set ID"
479 *
480 * @returns IPMI completion code plus response data
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000481 * - dataOut - data Set Id
jayaprakash Mutyala853d8292019-05-31 18:17:42 +0000482 */
483ipmi::RspType<std::vector<uint8_t>> mdr2DataInfoOffer(uint16_t agentId)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700484{
Vernon Mauery15419dd2019-05-24 09:40:30 -0700485 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
486 std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700487
488 if (mdrv2 == nullptr)
489 {
490 mdrv2 = std::make_unique<MDRV2>();
491 }
492
jayaprakash Mutyala853d8292019-05-31 18:17:42 +0000493 int agentIndex = mdrv2->agentLookup(agentId);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700494 if (agentIndex == -1)
495 {
496 phosphor::logging::log<phosphor::logging::level::ERR>(
jayaprakash Mutyala853d8292019-05-31 18:17:42 +0000497 "Unknown agent id", phosphor::logging::entry("ID=%x", agentId));
498 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700499 }
500
Vernon Mauery15419dd2019-05-24 09:40:30 -0700501 sdbusplus::message::message method = bus->new_method_call(
Vernon Mauerya3702c12019-05-22 13:20:59 -0700502 service.c_str(), mdrv2Path, mdrv2Interface, "GetDataOffer");
503
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000504 std::vector<uint8_t> dataOut;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700505 try
506 {
Vernon Mauery15419dd2019-05-24 09:40:30 -0700507 sdbusplus::message::message reply = bus->call(method);
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000508 reply.read(dataOut);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700509 }
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700510 catch (sdbusplus::exception_t &e)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700511 {
512 phosphor::logging::log<phosphor::logging::level::ERR>(
513 "Error send data info offer",
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700514 phosphor::logging::entry("ERROR=%s", e.what()),
Vernon Mauerya3702c12019-05-22 13:20:59 -0700515 phosphor::logging::entry("SERVICE=%s", service.c_str()),
516 phosphor::logging::entry("PATH=%s", mdrv2Path));
jayaprakash Mutyala853d8292019-05-31 18:17:42 +0000517 return ipmi::responseResponseError();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700518 }
519
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000520 constexpr size_t respInfoSize = 16;
521 if (dataOut.size() != respInfoSize)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700522 {
523 phosphor::logging::log<phosphor::logging::level::ERR>(
524 "Error send data info offer, return length invalid");
jayaprakash Mutyala853d8292019-05-31 18:17:42 +0000525 return ipmi::responseUnspecifiedError();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700526 }
527
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000528 return ipmi::responseSuccess(dataOut);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700529}
530
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000531/** @brief implements mdr2 send data info command
532 * @param agentId
533 * @param dataInfo
534 * @param validFlag
535 * @param dataLength
536 * @param dataVersion
537 * @param timeStamp
538 *
539 * @returns IPMI completion code plus response data
540 * - bool
541 */
542ipmi::RspType<bool> mdr2SendDataInfo(uint16_t agentId,
543 std::array<uint8_t, dataInfoSize> dataInfo,
544 uint8_t validFlag, uint32_t dataLength,
545 uint32_t dataVersion, uint32_t timeStamp)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700546{
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000547 if (dataLength > smbiosTableStorageSize)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700548 {
549 phosphor::logging::log<phosphor::logging::level::ERR>(
550 "Requested data length is out of SMBIOS Table storage size.");
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000551 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700552 }
553
Vernon Mauery15419dd2019-05-24 09:40:30 -0700554 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
555 std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700556
557 if (mdrv2 == nullptr)
558 {
559 mdrv2 = std::make_unique<MDRV2>();
560 }
561
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000562 int agentIndex = mdrv2->agentLookup(agentId);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700563 if (agentIndex == -1)
564 {
565 phosphor::logging::log<phosphor::logging::level::ERR>(
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000566 "Unknown agent id", phosphor::logging::entry("ID=%x", agentId));
567 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700568 }
569
Patrick Venture6d765602019-09-25 17:11:07 -0700570 int idIndex = mdrv2->findDataId(dataInfo.data(), dataInfo.size(), service);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700571
572 if ((idIndex < 0) || (idIndex >= maxDirEntries))
573 {
574 phosphor::logging::log<phosphor::logging::level::ERR>(
575 "Invalid Data ID", phosphor::logging::entry("IDINDEX=%x", idIndex));
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000576 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700577 }
578
Vernon Mauery15419dd2019-05-24 09:40:30 -0700579 sdbusplus::message::message method = bus->new_method_call(
Vernon Mauerya3702c12019-05-22 13:20:59 -0700580 service.c_str(), mdrv2Path, mdrv2Interface, "SendDataInformation");
581
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000582 method.append((uint8_t)idIndex, validFlag, dataLength, dataVersion,
583 timeStamp);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700584
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000585 bool entryChanged = true;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700586 try
587 {
Vernon Mauery15419dd2019-05-24 09:40:30 -0700588 sdbusplus::message::message reply = bus->call(method);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700589 reply.read(entryChanged);
590 }
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700591 catch (sdbusplus::exception_t &e)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700592 {
593 phosphor::logging::log<phosphor::logging::level::ERR>(
594 "Error send data info",
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700595 phosphor::logging::entry("ERROR=%s", e.what()),
Vernon Mauerya3702c12019-05-22 13:20:59 -0700596 phosphor::logging::entry("SERVICE=%s", service.c_str()),
597 phosphor::logging::entry("PATH=%s", mdrv2Path));
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000598 return ipmi::responseResponseError();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700599 }
600
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000601 return ipmi::responseSuccess(entryChanged);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700602}
603
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000604/**
605@brief This command is MDR related get data block command.
606
607@param - agentId
608@param - lockHandle
609@param - xferOffset
610@param - xferLength
611
612@return on success
613 - xferLength
614 - checksum
615 - data
616**/
617ipmi::RspType<uint32_t, // xferLength
618 uint32_t, // Checksum
619 std::vector<uint8_t> // data
620 >
621 mdr2GetDataBlock(uint16_t agentId, uint16_t lockHandle, uint32_t xferOffset,
622 uint32_t xferLength)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700623{
Vernon Mauerya3702c12019-05-22 13:20:59 -0700624 if (mdrv2 == nullptr)
625 {
626 mdrv2 = std::make_unique<MDRV2>();
627 }
628
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000629 int agentIndex = mdrv2->agentLookup(agentId);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700630 if (agentIndex == -1)
631 {
632 phosphor::logging::log<phosphor::logging::level::ERR>(
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000633 "Unknown agent id", phosphor::logging::entry("ID=%x", agentId));
634 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700635 }
636
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000637 int idIndex = mdrv2->findLockHandle(lockHandle);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700638
639 if ((idIndex < 0) || (idIndex >= maxDirEntries))
640 {
641 phosphor::logging::log<phosphor::logging::level::ERR>(
642 "Invalid Data ID", phosphor::logging::entry("IDINDEX=%x", idIndex));
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000643 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700644 }
645
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000646 if (xferOffset >= mdrv2->smbiosDir.dir[idIndex].common.size)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700647 {
648 phosphor::logging::log<phosphor::logging::level::ERR>(
649 "Offset is outside of range.");
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000650 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700651 }
652
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000653 size_t outSize = (xferLength > mdrv2->smbiosDir.dir[idIndex].xferSize)
654 ? mdrv2->smbiosDir.dir[idIndex].xferSize
655 : xferLength;
656 if (outSize > UINT_MAX - xferOffset)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700657 {
658 phosphor::logging::log<phosphor::logging::level::ERR>(
659 "Out size and offset are out of range");
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000660 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700661 }
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000662 if ((xferOffset + outSize) > mdrv2->smbiosDir.dir[idIndex].common.size)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700663 {
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000664 outSize = mdrv2->smbiosDir.dir[idIndex].common.size - xferOffset;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700665 }
666
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000667 uint32_t respXferLength = outSize;
668
669 if (respXferLength > xferLength)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700670 {
671 phosphor::logging::log<phosphor::logging::level::ERR>(
672 "Get data block unexpected error.");
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000673 return ipmi::responseUnspecifiedError();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700674 }
675
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000676 if ((xferOffset + outSize) >
Vernon Mauerya3702c12019-05-22 13:20:59 -0700677 UINT_MAX -
678 reinterpret_cast<size_t>(mdrv2->smbiosDir.dir[idIndex].dataStorage))
679 {
680 phosphor::logging::log<phosphor::logging::level::ERR>(
681 "Input data to calculate checksum is out of range");
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000682 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700683 }
684
685 uint32_t u32Checksum = mdrv2->calcChecksum32(
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000686 mdrv2->smbiosDir.dir[idIndex].dataStorage + xferOffset, outSize);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700687 if (u32Checksum == invalidChecksum)
688 {
689 phosphor::logging::log<phosphor::logging::level::ERR>(
690 "Get data block failed - invalid checksum");
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000691 return ipmi::response(ccOemInvalidChecksum);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700692 }
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000693 std::vector<uint8_t> data(outSize);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700694
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000695 std::copy(&mdrv2->smbiosDir.dir[idIndex].dataStorage[xferOffset],
696 &mdrv2->smbiosDir.dir[idIndex].dataStorage[xferOffset + outSize],
697 data.begin());
Vernon Mauerya3702c12019-05-22 13:20:59 -0700698
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000699 return ipmi::responseSuccess(respXferLength, u32Checksum, data);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700700}
701
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000702/** @brief implements mdr2 send data block command
703 * @param agentId
704 * @param lockHandle
705 * @param xferOffset
706 * @param xferLength
707 * @param checksum
708 *
709 * @returns IPMI completion code
710 */
711ipmi::RspType<> mdr2SendDataBlock(uint16_t agentId, uint16_t lockHandle,
712 uint32_t xferOffset, uint32_t xferLength,
713 uint32_t checksum)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700714{
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000715
Vernon Mauerya3702c12019-05-22 13:20:59 -0700716 if (mdrv2 == nullptr)
717 {
718 mdrv2 = std::make_unique<MDRV2>();
719 }
720
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000721 int agentIndex = mdrv2->agentLookup(agentId);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700722 if (agentIndex == -1)
723 {
724 phosphor::logging::log<phosphor::logging::level::ERR>(
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000725 "Unknown agent id", phosphor::logging::entry("ID=%x", agentId));
726 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700727 }
728
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000729 int idIndex = mdrv2->findLockHandle(lockHandle);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700730
731 if ((idIndex < 0) || (idIndex >= maxDirEntries))
732 {
733 phosphor::logging::log<phosphor::logging::level::ERR>(
734 "Invalid Data ID", phosphor::logging::entry("IDINDEX=%x", idIndex));
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000735 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700736 }
737
738 if (mdrv2->smbiosIsUpdating(idIndex))
739 {
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000740 if (xferOffset > UINT_MAX - xferLength)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700741 {
742 phosphor::logging::log<phosphor::logging::level::ERR>(
743 "Offset and length are out of range");
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000744 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700745 }
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000746 if (((xferOffset + xferLength) >
Vernon Mauerya3702c12019-05-22 13:20:59 -0700747 mdrv2->smbiosDir.dir[idIndex].maxDataSize) ||
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000748 ((xferOffset + xferLength) >
Vernon Mauerya3702c12019-05-22 13:20:59 -0700749 mdrv2->smbiosDir.dir[idIndex].common.dataSetSize))
750 {
751 phosphor::logging::log<phosphor::logging::level::ERR>(
752 "Send data block Invalid offset/length");
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000753 return ipmi::responseReqDataLenExceeded();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700754 }
755 if (reinterpret_cast<size_t>(
756 mdrv2->smbiosDir.dir[idIndex].dataStorage) >
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000757 UINT_MAX - xferOffset)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700758 {
759 phosphor::logging::log<phosphor::logging::level::ERR>(
760 "Offset is out of range");
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000761 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700762 }
763 uint8_t *destAddr =
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000764 mdrv2->smbiosDir.dir[idIndex].dataStorage + xferOffset;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700765 uint8_t *sourceAddr = reinterpret_cast<uint8_t *>(mdrv2->area->vPtr);
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000766 uint32_t calcChecksum = mdrv2->calcChecksum32(sourceAddr, xferLength);
767 if (calcChecksum != checksum)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700768 {
769 phosphor::logging::log<phosphor::logging::level::ERR>(
770 "Send data block Invalid checksum");
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000771 return ipmi::response(ccOemInvalidChecksum);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700772 }
773 else
774 {
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000775 if (reinterpret_cast<size_t>(sourceAddr) > UINT_MAX - xferLength)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700776 {
777 phosphor::logging::log<phosphor::logging::level::ERR>(
778 "Length is out of range");
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000779 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700780 }
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000781 std::copy(sourceAddr, sourceAddr + xferLength, destAddr);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700782 }
783 }
784 else
785 {
786 phosphor::logging::log<phosphor::logging::level::ERR>(
787 "Send data block failed, other data is updating");
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000788 return ipmi::responseDestinationUnavailable();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700789 }
790
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000791 return ipmi::responseSuccess();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700792}
793
794bool MDRV2::storeDatatoFlash(MDRSMBIOSHeader *mdrHdr, uint8_t *data)
795{
796 std::ofstream smbiosFile(mdrType2File,
797 std::ios_base::binary | std::ios_base::trunc);
798 if (!smbiosFile.good())
799 {
800 phosphor::logging::log<phosphor::logging::level::ERR>(
801 "Write data from flash error - Open MDRV2 table file failure");
802 return false;
803 }
804
805 try
806 {
807 smbiosFile.write(reinterpret_cast<char *>(mdrHdr),
808 sizeof(MDRSMBIOSHeader));
809 smbiosFile.write(reinterpret_cast<char *>(data), mdrHdr->dataSize);
810 }
811 catch (std::ofstream::failure &e)
812 {
813 phosphor::logging::log<phosphor::logging::level::ERR>(
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700814 "Write data from flash error - write data error",
815 phosphor::logging::entry("ERROR=%s", e.what()));
Vernon Mauerya3702c12019-05-22 13:20:59 -0700816 return false;
817 }
818
819 return true;
820}
821
822void SharedMemoryArea::Initialize(uint32_t addr, uint32_t areaSize)
823{
824 int memDriver = 0;
825
826 // open mem driver for the system memory access
827 memDriver = open("/dev/vgasharedmem", O_RDONLY);
828 if (memDriver < 0)
829 {
830 phosphor::logging::log<phosphor::logging::level::ERR>(
831 "Cannot access mem driver");
832 throw std::system_error(EIO, std::generic_category());
833 }
834
835 // map the system memory
836 vPtr = mmap(NULL, // where to map to: don't mind
837 areaSize, // how many bytes ?
838 PROT_READ, // want to read and write
839 MAP_SHARED, // no copy on write
840 memDriver, // handle to /dev/mem
841 (physicalAddr & pageMask)); // hopefully the Text-buffer :-)
842
843 close(memDriver);
844 if (vPtr == MAP_FAILED)
845 {
846 phosphor::logging::log<phosphor::logging::level::ERR>(
847 "Failed to map share memory");
848 throw std::system_error(EIO, std::generic_category());
849 }
850 size = areaSize;
851 physicalAddr = addr;
852}
853
854bool MDRV2::smbiosUnlock(uint8_t index)
855{
856 bool ret;
857 switch (smbiosDir.dir[index].stage)
858 {
859 case MDR2SMBIOSStatusEnum::mdr2Updating:
860 smbiosDir.dir[index].stage = MDR2SMBIOSStatusEnum::mdr2Updated;
861 smbiosDir.dir[index].lock = MDR2DirLockEnum::mdr2DirUnlock;
862
863 timer->stop();
864 smbiosDir.dir[index].lockHandle = 0;
865 ret = true;
866 break;
867
868 case MDR2SMBIOSStatusEnum::mdr2Updated:
869 case MDR2SMBIOSStatusEnum::mdr2Loaded:
870 smbiosDir.dir[index].lock = MDR2DirLockEnum::mdr2DirUnlock;
871
872 timer->stop();
873
874 smbiosDir.dir[index].lockHandle = 0;
875 ret = true;
876 break;
877
878 default:
879 break;
880 }
881
882 return ret;
883}
884
885bool MDRV2::smbiosTryLock(uint8_t flag, uint8_t index, uint16_t *session,
886 uint16_t timeout)
887{
888 bool ret = false;
889 uint32_t u32Status = 0;
890
891 if (timeout == 0)
892 {
893 timeout = defaultTimeout;
894 }
895 std::chrono::microseconds usec(timeout * sysClock);
896
897 switch (smbiosDir.dir[index].stage)
898 {
899 case MDR2SMBIOSStatusEnum::mdr2Updating:
900 if (smbiosDir.dir[index].lock != MDR2DirLockEnum::mdr2DirLock)
901 {
902 smbiosDir.dir[index].lock = MDR2DirLockEnum::mdr2DirLock;
903 timer->start(usec);
904 lockIndex = index;
905
906 *session = getSessionHandle(&smbiosDir);
907 smbiosDir.dir[index].lockHandle = *session;
908 ret = true;
909 }
910 break;
911 case MDR2SMBIOSStatusEnum::mdr2Init:
912 if (flag)
913 {
914 smbiosDir.dir[index].stage = MDR2SMBIOSStatusEnum::mdr2Updating;
915 smbiosDir.dir[index].lock = MDR2DirLockEnum::mdr2DirUnlock;
916 timer->start(usec);
917 lockIndex = index;
918
919 *session = getSessionHandle(&smbiosDir);
920 smbiosDir.dir[index].lockHandle = *session;
921 ret = true;
922 }
923 break;
924
925 case MDR2SMBIOSStatusEnum::mdr2Updated:
926 case MDR2SMBIOSStatusEnum::mdr2Loaded:
927 if (smbiosDir.dir[index].lock != MDR2DirLockEnum::mdr2DirLock)
928 {
929 if (flag)
930 {
931 smbiosDir.dir[index].stage =
932 MDR2SMBIOSStatusEnum::mdr2Updating;
933 smbiosDir.dir[index].lock = MDR2DirLockEnum::mdr2DirUnlock;
934 }
935 else
936 {
937 smbiosDir.dir[index].lock = MDR2DirLockEnum::mdr2DirLock;
938 }
939
940 timer->start(usec);
941 lockIndex = index;
942
943 *session = getSessionHandle(&smbiosDir);
944 smbiosDir.dir[index].lockHandle = *session;
945 ret = true;
946 }
947 break;
948
949 default:
950 break;
951 }
952 return ret;
953}
954
955void MDRV2::timeoutHandler()
956{
957 smbiosUnlock(lockIndex);
958 mdrv2->area.reset(nullptr);
959}
960
jayaprakash Mutyala40fec612019-06-19 11:53:03 +0000961/** @brief implements mdr2 lock data command
962 * @param agentId
963 * @param dataInfo
964 * @param timeout
965 *
966 * @returns IPMI completion code plus response data
967 * - mdr2Version
968 * - session
969 * - dataLength
970 * - xferAddress
971 * - xferLength
972 */
973ipmi::RspType<uint8_t, // mdr2Version
974 uint16_t, // session
975 uint32_t, // dataLength
976 uint32_t, // xferAddress
977 uint32_t // xferLength
978 >
979 mdr2LockData(uint16_t agentId, std::array<uint8_t, dataInfoSize> dataInfo,
980 uint16_t timeout)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700981{
Vernon Mauerya3702c12019-05-22 13:20:59 -0700982 if (mdrv2 == nullptr)
983 {
984 mdrv2 = std::make_unique<MDRV2>();
985 }
986
jayaprakash Mutyala40fec612019-06-19 11:53:03 +0000987 int agentIndex = mdrv2->agentLookup(agentId);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700988 if (agentIndex == -1)
989 {
990 phosphor::logging::log<phosphor::logging::level::ERR>(
jayaprakash Mutyala40fec612019-06-19 11:53:03 +0000991 "Unknown agent id", phosphor::logging::entry("ID=%x", agentId));
992 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700993 }
994
Vernon Mauery15419dd2019-05-24 09:40:30 -0700995 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
996 std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700997
Patrick Venture6d765602019-09-25 17:11:07 -0700998 int idIndex = mdrv2->findDataId(dataInfo.data(), dataInfo.size(), service);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700999
1000 if ((idIndex < 0) || (idIndex >= maxDirEntries))
1001 {
1002 phosphor::logging::log<phosphor::logging::level::ERR>(
1003 "Invalid Data ID", phosphor::logging::entry("IDINDEX=%x", idIndex));
jayaprakash Mutyala40fec612019-06-19 11:53:03 +00001004 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001005 }
1006
jayaprakash Mutyala40fec612019-06-19 11:53:03 +00001007 uint16_t session = 0;
1008 if (!mdrv2->smbiosTryLock(0, idIndex, &session, timeout))
Vernon Mauerya3702c12019-05-22 13:20:59 -07001009 {
1010 phosphor::logging::log<phosphor::logging::level::ERR>(
1011 "Lock Data failed - cannot lock idIndex");
jayaprakash Mutyala40fec612019-06-19 11:53:03 +00001012 return ipmi::responseCommandNotAvailable();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001013 }
1014
jayaprakash Mutyala40fec612019-06-19 11:53:03 +00001015 uint32_t dataLength = mdrv2->smbiosDir.dir[idIndex].common.size;
1016 uint32_t xferAddress = mdrv2->smbiosDir.dir[idIndex].xferBuff;
1017 uint32_t xferLength = mdrv2->smbiosDir.dir[idIndex].xferSize;
Vernon Mauerya3702c12019-05-22 13:20:59 -07001018
jayaprakash Mutyala40fec612019-06-19 11:53:03 +00001019 return ipmi::responseSuccess(mdr2Version, session, dataLength, xferAddress,
1020 xferLength);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001021}
1022
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +00001023/** @brief implements mdr2 unlock data command
1024 * @param agentId
1025 * @param lockHandle
1026 *
1027 * @returns IPMI completion code
1028 */
1029ipmi::RspType<> mdr2UnlockData(uint16_t agentId, uint16_t lockHandle)
Vernon Mauerya3702c12019-05-22 13:20:59 -07001030{
1031 phosphor::logging::log<phosphor::logging::level::ERR>("unlock data");
Vernon Mauerya3702c12019-05-22 13:20:59 -07001032
Vernon Mauerya3702c12019-05-22 13:20:59 -07001033 if (mdrv2 == nullptr)
1034 {
1035 mdrv2 = std::make_unique<MDRV2>();
1036 }
1037
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +00001038 int agentIndex = mdrv2->agentLookup(agentId);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001039 if (agentIndex == -1)
1040 {
1041 phosphor::logging::log<phosphor::logging::level::ERR>(
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +00001042 "Unknown agent id", phosphor::logging::entry("ID=%x", agentId));
1043 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001044 }
1045
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +00001046 int idIndex = mdrv2->findLockHandle(lockHandle);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001047
1048 if ((idIndex < 0) || (idIndex >= maxDirEntries))
1049 {
1050 phosphor::logging::log<phosphor::logging::level::ERR>(
1051 "Invalid Data ID", phosphor::logging::entry("IDINDEX=%x", idIndex));
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +00001052 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001053 }
1054
1055 if (!mdrv2->smbiosUnlock(idIndex))
1056 {
1057 phosphor::logging::log<phosphor::logging::level::ERR>(
1058 "Unlock Data failed - cannot unlock idIndex");
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +00001059 return ipmi::responseCommandNotAvailable();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001060 }
1061
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +00001062 return ipmi::responseSuccess();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001063}
1064
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001065/**
1066@brief This command is executed after POST BIOS to get the session info.
1067
1068@param - agentId, dataInfo, dataLength, xferAddress, xferLength, timeout.
1069
1070@return xferStartAck and session on success.
1071**/
1072ipmi::RspType<uint8_t, uint16_t>
1073 cmd_mdr2_data_start(uint16_t agentId, std::array<uint8_t, 16> dataInfo,
1074 uint32_t dataLength, uint32_t xferAddress,
1075 uint32_t xferLength, uint16_t timeout)
Vernon Mauerya3702c12019-05-22 13:20:59 -07001076{
Vernon Mauerya3702c12019-05-22 13:20:59 -07001077 uint16_t session = 0;
1078
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001079 if (dataLength > smbiosTableStorageSize)
Vernon Mauerya3702c12019-05-22 13:20:59 -07001080 {
1081 phosphor::logging::log<phosphor::logging::level::ERR>(
1082 "Requested data length is out of SMBIOS Table storage size.");
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001083 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001084 }
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001085 if ((xferLength + xferAddress) > mdriiSMSize)
Vernon Mauerya3702c12019-05-22 13:20:59 -07001086 {
1087 phosphor::logging::log<phosphor::logging::level::ERR>(
1088 "Invalid data address and size");
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001089 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001090 }
1091
Vernon Mauery15419dd2019-05-24 09:40:30 -07001092 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
1093 std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001094
1095 if (mdrv2 == nullptr)
1096 {
1097 mdrv2 = std::make_unique<MDRV2>();
1098 }
1099
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001100 int agentIndex = mdrv2->agentLookup(agentId);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001101 if (agentIndex == -1)
1102 {
1103 phosphor::logging::log<phosphor::logging::level::ERR>(
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001104 "Unknown agent id", phosphor::logging::entry("ID=%x", agentId));
1105 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001106 }
1107
Patrick Venture6d765602019-09-25 17:11:07 -07001108 int idIndex = mdrv2->findDataId(dataInfo.data(), dataInfo.size(), service);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001109
1110 if ((idIndex < 0) || (idIndex >= maxDirEntries))
1111 {
1112 phosphor::logging::log<phosphor::logging::level::ERR>(
1113 "Invalid Data ID", phosphor::logging::entry("IDINDEX=%x", idIndex));
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001114 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001115 }
1116
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001117 if (mdrv2->smbiosTryLock(1, idIndex, &session, timeout))
Vernon Mauerya3702c12019-05-22 13:20:59 -07001118 {
1119 try
1120 {
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001121 mdrv2->area =
1122 std::make_unique<SharedMemoryArea>(xferAddress, xferLength);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001123 }
1124 catch (const std::system_error &e)
1125 {
1126 mdrv2->smbiosUnlock(idIndex);
1127 phosphor::logging::log<phosphor::logging::level::ERR>(
Vernon Maueryc7d517e2019-06-18 14:27:00 -07001128 "Unable to access share memory",
1129 phosphor::logging::entry("ERROR=%s", e.what()));
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001130 return ipmi::responseUnspecifiedError();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001131 }
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001132 mdrv2->smbiosDir.dir[idIndex].common.size = dataLength;
Vernon Mauerya3702c12019-05-22 13:20:59 -07001133 mdrv2->smbiosDir.dir[idIndex].lockHandle = session;
1134 if (-1 ==
1135 mdrv2->syncDirCommonData(
1136 idIndex, mdrv2->smbiosDir.dir[idIndex].common.size, service))
1137 {
1138 phosphor::logging::log<phosphor::logging::level::ERR>(
1139 "Unable to sync data to service");
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001140 return ipmi::responseResponseError();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001141 }
1142 }
1143 else
1144 {
1145 phosphor::logging::log<phosphor::logging::level::ERR>(
1146 "Canot lock smbios");
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001147 return ipmi::responseUnspecifiedError();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001148 }
1149
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001150 static constexpr uint8_t xferStartAck = 1;
Vernon Mauerya3702c12019-05-22 13:20:59 -07001151
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001152 return ipmi::responseSuccess(xferStartAck, session);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001153}
1154
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001155/**
1156@brief This command is executed to close the session.
1157
1158@param - agentId, lockHandle.
1159
1160@return completion code on success.
1161**/
1162ipmi::RspType<> cmd_mdr2_data_done(uint16_t agentId, uint16_t lockHandle)
Vernon Mauerya3702c12019-05-22 13:20:59 -07001163{
Vernon Mauerya3702c12019-05-22 13:20:59 -07001164
1165 if (mdrv2 == nullptr)
1166 {
1167 mdrv2 = std::make_unique<MDRV2>();
1168 }
1169
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001170 int agentIndex = mdrv2->agentLookup(agentId);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001171 if (agentIndex == -1)
1172 {
1173 phosphor::logging::log<phosphor::logging::level::ERR>(
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001174 "Unknown agent id", phosphor::logging::entry("ID=%x", agentId));
1175 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001176 }
1177
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001178 int idIndex = mdrv2->findLockHandle(lockHandle);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001179
1180 if ((idIndex < 0) || (idIndex >= maxDirEntries))
1181 {
1182 phosphor::logging::log<phosphor::logging::level::ERR>(
1183 "Invalid Data ID", phosphor::logging::entry("IDINDEX=%x", idIndex));
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001184 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001185 }
1186
1187 if (!mdrv2->smbiosUnlock(idIndex))
1188 {
1189 phosphor::logging::log<phosphor::logging::level::ERR>(
1190 "Send data done failed - cannot unlock idIndex");
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001191 return ipmi::responseDestinationUnavailable();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001192 }
1193
1194 mdrv2->area.reset(nullptr);
1195 MDRSMBIOSHeader mdr2Smbios;
1196 mdr2Smbios.mdrType = mdrTypeII;
1197 mdr2Smbios.dirVer = mdrv2->smbiosDir.dir[0].common.dataVersion;
1198 mdr2Smbios.timestamp = mdrv2->smbiosDir.dir[0].common.timestamp;
1199 mdr2Smbios.dataSize = mdrv2->smbiosDir.dir[0].common.size;
1200
1201 if (access(smbiosPath, 0) == -1)
1202 {
1203 int flag = mkdir(smbiosPath, S_IRWXU);
1204 if (flag != 0)
1205 {
1206 phosphor::logging::log<phosphor::logging::level::ERR>(
1207 "create folder failed for writting smbios file");
1208 }
1209 }
1210 if (!mdrv2->storeDatatoFlash(
1211 &mdr2Smbios, mdrv2->smbiosDir.dir[smbiosDirIndex].dataStorage))
1212 {
1213 phosphor::logging::log<phosphor::logging::level::ERR>(
1214 "MDR2 Store data to flash failed");
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001215 return ipmi::responseDestinationUnavailable();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001216 }
Vernon Mauerya3702c12019-05-22 13:20:59 -07001217 bool status = false;
Vernon Mauery15419dd2019-05-24 09:40:30 -07001218 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
1219 std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path);
1220 sdbusplus::message::message method = bus->new_method_call(
Vernon Mauerya3702c12019-05-22 13:20:59 -07001221 service.c_str(), mdrv2Path, mdrv2Interface, "AgentSynchronizeData");
1222
1223 try
1224 {
Vernon Mauery15419dd2019-05-24 09:40:30 -07001225 sdbusplus::message::message reply = bus->call(method);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001226 reply.read(status);
1227 }
Vernon Maueryc7d517e2019-06-18 14:27:00 -07001228 catch (sdbusplus::exception_t &e)
Vernon Mauerya3702c12019-05-22 13:20:59 -07001229 {
1230 phosphor::logging::log<phosphor::logging::level::ERR>(
1231 "Error Sync data with service",
Vernon Maueryc7d517e2019-06-18 14:27:00 -07001232 phosphor::logging::entry("ERROR=%s", e.what()),
Vernon Mauerya3702c12019-05-22 13:20:59 -07001233 phosphor::logging::entry("SERVICE=%s", service.c_str()),
1234 phosphor::logging::entry("PATH=%s", mdrv2Path));
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001235 return ipmi::responseResponseError();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001236 }
1237
1238 if (!status)
1239 {
1240 phosphor::logging::log<phosphor::logging::level::ERR>(
1241 "Sync data with service failure");
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001242 return ipmi::responseUnspecifiedError();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001243 }
1244
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001245 return ipmi::responseSuccess();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001246}
1247
1248static void register_netfn_smbiosmdrv2_functions(void)
1249{
1250 // MDR V2 Command
1251 // <Get MDRII Status Command>
Vernon Mauery98bbf692019-09-16 11:14:59 -07001252 ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnApp,
1253 ipmi::intel::app::cmdMdrIIAgentStatus,
jayaprakash Mutyala853d8292019-05-31 18:17:42 +00001254 ipmi::Privilege::Operator, mdr2AgentStatus);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001255
1256 // <Get MDRII Directory Command>
Vernon Mauery98bbf692019-09-16 11:14:59 -07001257 ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnApp,
1258 ipmi::intel::app::cmdMdrIIGetDir,
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +00001259 ipmi::Privilege::Operator, mdr2GetDir);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001260
1261 // <Send MDRII Directory Command>
Vernon Mauery98bbf692019-09-16 11:14:59 -07001262 ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnApp,
1263 ipmi::intel::app::cmdMdrIISendDir,
jayaprakash Mutyala7cb59cc2019-06-19 19:17:43 +00001264 ipmi::Privilege::Operator, mdr2SendDir);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001265
1266 // <Get MDRII Data Info Command>
Vernon Mauery98bbf692019-09-16 11:14:59 -07001267 ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnApp,
1268 ipmi::intel::app::cmdMdrIIGetDataInfo,
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +00001269 ipmi::Privilege::Operator, mdr2GetDataInfo);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001270
1271 // <Send MDRII Info Offer>
Vernon Mauery98bbf692019-09-16 11:14:59 -07001272 ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnApp,
1273 ipmi::intel::app::cmdMdrIISendDataInfoOffer,
1274 ipmi::Privilege::Operator, mdr2DataInfoOffer);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001275
1276 // <Send MDRII Data Info>
Vernon Mauery98bbf692019-09-16 11:14:59 -07001277 ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnApp,
1278 ipmi::intel::app::cmdMdrIISendDataInfo,
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +00001279 ipmi::Privilege::Operator, mdr2SendDataInfo);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001280
1281 // <Get MDRII Data Block Command>
Vernon Mauery98bbf692019-09-16 11:14:59 -07001282 ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnApp,
1283 ipmi::intel::app::cmdMdrIIGetDataBlock,
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +00001284 ipmi::Privilege::Operator, mdr2GetDataBlock);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001285
1286 // <Send MDRII Data Block>
Vernon Mauery98bbf692019-09-16 11:14:59 -07001287 ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnApp,
1288 ipmi::intel::app::cmdMdrIISendDataBlock,
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +00001289 ipmi::Privilege::Operator, mdr2SendDataBlock);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001290
1291 // <Lock MDRII Data Command>
Vernon Mauery98bbf692019-09-16 11:14:59 -07001292 ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnApp,
1293 ipmi::intel::app::cmdMdrIILockData,
jayaprakash Mutyala40fec612019-06-19 11:53:03 +00001294 ipmi::Privilege::Operator, mdr2LockData);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001295
1296 // <Unlock MDRII Data Command>
Vernon Mauery98bbf692019-09-16 11:14:59 -07001297 ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnApp,
1298 ipmi::intel::app::cmdMdrIIUnlockData,
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +00001299 ipmi::Privilege::Operator, mdr2UnlockData);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001300
1301 // <Send MDRII Data Start>
Vernon Mauery98bbf692019-09-16 11:14:59 -07001302 ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnApp,
1303 ipmi::intel::app::cmdMdrIIDataStart,
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001304 ipmi::Privilege::Operator, cmd_mdr2_data_start);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001305
1306 // <Send MDRII Data Done>
Vernon Mauery98bbf692019-09-16 11:14:59 -07001307 ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnApp,
1308 ipmi::intel::app::cmdMdrIIDataDone,
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001309 ipmi::Privilege::Operator, cmd_mdr2_data_done);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001310}