blob: 18aff5886cec63dbdfd78b9b8fdd0add4f0afe79 [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>
29#include <phosphor-logging/log.hpp>
Vernon Mauerya3702c12019-05-22 13:20:59 -070030#include <sdbusplus/message/types.hpp>
31#include <smbiosmdrv2handler.hpp>
32#include <string>
33#include <vector>
34#include <xyz/openbmc_project/Common/error.hpp>
Vernon Mauerya3702c12019-05-22 13:20:59 -070035
36std::unique_ptr<MDRV2> mdrv2 = nullptr;
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +000037static constexpr const uint8_t ccOemInvalidChecksum = 0x85;
jayaprakash Mutyala40fec612019-06-19 11:53:03 +000038static constexpr size_t dataInfoSize = 16;
jayaprakash Mutyala7cb59cc2019-06-19 19:17:43 +000039static constexpr const uint8_t ccStorageLeak = 0xC4;
Vernon Mauerya3702c12019-05-22 13:20:59 -070040
Vernon Mauerya3702c12019-05-22 13:20:59 -070041static void register_netfn_smbiosmdrv2_functions() __attribute__((constructor));
Vernon Mauerya3702c12019-05-22 13:20:59 -070042
43int MDRV2::agentLookup(const uint16_t &agentId)
44{
45 int agentIndex = -1;
46
47 if (lastAgentId == agentId)
48 {
49 return lastAgentIndex;
50 }
51
52 if (agentId == smbiosAgentId)
53 {
54 return firstAgentIndex;
55 }
56
57 return agentIndex;
58}
59
60int MDRV2::sdplusMdrv2GetProperty(const std::string &name,
61 sdbusplus::message::variant<uint8_t> &value,
62 const std::string &service)
63{
Vernon Mauery15419dd2019-05-24 09:40:30 -070064 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
Vernon Mauerya3702c12019-05-22 13:20:59 -070065 sdbusplus::message::message method =
Vernon Mauery15419dd2019-05-24 09:40:30 -070066 bus->new_method_call(service.c_str(), mdrv2Path, dbusProperties, "Get");
Vernon Mauerya3702c12019-05-22 13:20:59 -070067 method.append(mdrv2Interface, name);
68
Vernon Mauery15419dd2019-05-24 09:40:30 -070069 sdbusplus::message::message reply = bus->call(method);
Vernon Mauerya3702c12019-05-22 13:20:59 -070070
71 try
72 {
Vernon Mauery15419dd2019-05-24 09:40:30 -070073 sdbusplus::message::message reply = bus->call(method);
Vernon Mauerya3702c12019-05-22 13:20:59 -070074 reply.read(value);
75 }
Vernon Maueryc7d517e2019-06-18 14:27:00 -070076 catch (sdbusplus::exception_t &e)
Vernon Mauerya3702c12019-05-22 13:20:59 -070077 {
78 phosphor::logging::log<phosphor::logging::level::ERR>(
Vernon Maueryc7d517e2019-06-18 14:27:00 -070079 "Error get property, sdbusplus call failed",
80 phosphor::logging::entry("ERROR=%s", e.what()));
Vernon Mauerya3702c12019-05-22 13:20:59 -070081 return -1;
82 }
83
84 return 0;
85}
86
87int MDRV2::syncDirCommonData(uint8_t idIndex, uint32_t size,
88 const std::string &service)
89{
90 std::vector<uint32_t> commonData;
Vernon Mauery15419dd2019-05-24 09:40:30 -070091 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
Vernon Mauerya3702c12019-05-22 13:20:59 -070092 sdbusplus::message::message method =
Vernon Mauery15419dd2019-05-24 09:40:30 -070093 bus->new_method_call(service.c_str(), mdrv2Path, mdrv2Interface,
94 "SynchronizeDirectoryCommonData");
Vernon Mauerya3702c12019-05-22 13:20:59 -070095 method.append(idIndex, size);
96
97 try
98 {
Vernon Mauery15419dd2019-05-24 09:40:30 -070099 sdbusplus::message::message reply = bus->call(method);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700100 reply.read(commonData);
101 }
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700102 catch (sdbusplus::exception_t &e)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700103 {
104 phosphor::logging::log<phosphor::logging::level::ERR>(
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700105 "Error sync dir common data with service",
106 phosphor::logging::entry("ERROR=%s", e.what()));
Vernon Mauerya3702c12019-05-22 13:20:59 -0700107 return -1;
108 }
109
110 if (commonData.size() < syncDirCommonSize)
111 {
112 phosphor::logging::log<phosphor::logging::level::ERR>(
113 "Error sync dir common data - data length invalid");
114 return -1;
115 }
116 smbiosDir.dir[idIndex].common.dataSetSize = commonData.at(0);
117 smbiosDir.dir[idIndex].common.dataVersion = commonData.at(1);
118 smbiosDir.dir[idIndex].common.timestamp = commonData.at(2);
119
120 return 0;
121}
122
123int MDRV2::findDataId(const uint8_t *dataInfo, const size_t &len,
124 const std::string &service)
125{
126 int idIndex = -1;
127
128 if (dataInfo == nullptr)
129 {
130 phosphor::logging::log<phosphor::logging::level::ERR>(
131 "Error dataInfo, input is null point");
132 return -1;
133 }
134
Vernon Mauery15419dd2019-05-24 09:40:30 -0700135 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
136 sdbusplus::message::message method = bus->new_method_call(
Vernon Mauerya3702c12019-05-22 13:20:59 -0700137 service.c_str(), mdrv2Path, mdrv2Interface, "FindIdIndex");
138 std::vector<uint8_t> info;
139 info.resize(len);
140 std::copy(dataInfo, dataInfo + len, info.data());
141 method.append(info);
142
143 try
144 {
Vernon Mauery15419dd2019-05-24 09:40:30 -0700145 sdbusplus::message::message reply = bus->call(method);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700146 reply.read(idIndex);
147 }
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700148 catch (sdbusplus::exception_t &e)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700149 {
150 phosphor::logging::log<phosphor::logging::level::ERR>(
151 "Error find id index",
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700152 phosphor::logging::entry("ERROR=%s", e.what()),
Vernon Mauerya3702c12019-05-22 13:20:59 -0700153 phosphor::logging::entry("SERVICE=%s", service.c_str()),
154 phosphor::logging::entry("PATH=%s", mdrv2Path));
155 return -1;
156 }
157
158 return idIndex;
159}
160
161uint16_t MDRV2::getSessionHandle(Mdr2DirStruct *dir)
162{
163 if (dir == NULL)
164 {
165 phosphor::logging::log<phosphor::logging::level::ERR>(
166 "Empty dir point");
167 return 0;
168 }
169 dir->sessionHandle++;
170 if (dir->sessionHandle == 0)
171 {
172 dir->sessionHandle = 1;
173 }
174
175 return dir->sessionHandle;
176}
177
178int MDRV2::findLockHandle(const uint16_t &lockHandle)
179{
180 int idIndex = -1;
181
182 for (int index = 0; index < smbiosDir.dirEntries; index++)
183 {
184 if (lockHandle == smbiosDir.dir[index].lockHandle)
185 {
186 return index;
187 }
188 }
189
190 return idIndex;
191}
192
193bool MDRV2::smbiosIsUpdating(uint8_t index)
194{
195 if (index > maxDirEntries)
196 {
197 return false;
198 }
199 if (smbiosDir.dir[index].stage == MDR2SMBIOSStatusEnum::mdr2Updating)
200 {
201 return true;
202 }
203
204 return false;
205}
206
207uint32_t MDRV2::calcChecksum32(uint8_t *buf, uint32_t len)
208{
209 uint32_t sum = 0;
210
211 if (buf == nullptr)
212 {
213 return invalidChecksum;
214 }
215
216 for (uint32_t index = 0; index < len; index++)
217 {
218 sum += buf[index];
219 }
220
221 return sum;
222}
223
jayaprakash Mutyala853d8292019-05-31 18:17:42 +0000224/** @brief implements mdr2 agent status command
225 * @param agentId
226 * @param dirVersion
227 *
228 * @returns IPMI completion code plus response data
229 * - mdrVersion
230 * - agentVersion
231 * - dirVersion
232 * - dirEntries
233 * - dataRequest
234 */
235ipmi::RspType<uint8_t, uint8_t, uint8_t, uint8_t, uint8_t>
236 mdr2AgentStatus(uint16_t agentId, uint8_t dirVersion)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700237{
Vernon Mauerya3702c12019-05-22 13:20:59 -0700238 if (mdrv2 == nullptr)
239 {
240 mdrv2 = std::make_unique<MDRV2>();
241 }
242
jayaprakash Mutyala853d8292019-05-31 18:17:42 +0000243 int agentIndex = mdrv2->agentLookup(agentId);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700244 if (agentIndex == -1)
245 {
246 phosphor::logging::log<phosphor::logging::level::ERR>(
jayaprakash Mutyala853d8292019-05-31 18:17:42 +0000247 "Unknown agent id", phosphor::logging::entry("ID=%x", agentId));
248 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700249 }
250
jayaprakash Mutyala853d8292019-05-31 18:17:42 +0000251 constexpr uint8_t mdrVersion = mdr2Version;
252 constexpr uint8_t agentVersion = smbiosAgentVersion;
253 uint8_t dirVersionResp = mdrv2->smbiosDir.dirVersion;
254 uint8_t dirEntries = mdrv2->smbiosDir.dirEntries;
255 uint8_t dataRequest;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700256
jayaprakash Mutyala853d8292019-05-31 18:17:42 +0000257 if (mdrv2->smbiosDir.remoteDirVersion != dirVersion)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700258 {
jayaprakash Mutyala853d8292019-05-31 18:17:42 +0000259 mdrv2->smbiosDir.remoteDirVersion = dirVersion;
260 dataRequest =
Vernon Mauerya3702c12019-05-22 13:20:59 -0700261 static_cast<uint8_t>(DirDataRequestEnum::dirDataRequested);
262 }
263 else
264 {
jayaprakash Mutyala853d8292019-05-31 18:17:42 +0000265 dataRequest =
Vernon Mauerya3702c12019-05-22 13:20:59 -0700266 static_cast<uint8_t>(DirDataRequestEnum::dirDataNotRequested);
267 }
268
jayaprakash Mutyala853d8292019-05-31 18:17:42 +0000269 return ipmi::responseSuccess(mdrVersion, agentVersion, dirVersionResp,
270 dirEntries, dataRequest);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700271}
272
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000273/** @brief implements mdr2 get directory command
274 * @param agentId
275 * @param dirIndex
276 * @returns IPMI completion code plus response data
277 * - dataOut
278 */
279ipmi::RspType<std::vector<uint8_t>> mdr2GetDir(uint16_t agentId,
280 uint8_t dirIndex)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700281{
Vernon Mauery15419dd2019-05-24 09:40:30 -0700282 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
283 std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700284
285 if (mdrv2 == nullptr)
286 {
287 mdrv2 = std::make_unique<MDRV2>();
288 }
289
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000290 int agentIndex = mdrv2->agentLookup(agentId);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700291 if (agentIndex == -1)
292 {
293 phosphor::logging::log<phosphor::logging::level::ERR>(
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000294 "Unknown agent id", phosphor::logging::entry("ID=%x", agentId));
295 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700296 }
297
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000298 std::variant<uint8_t> value = 0;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700299 if (0 != mdrv2->sdplusMdrv2GetProperty("DirectoryEntries", value, service))
300 {
301 phosphor::logging::log<phosphor::logging::level::ERR>(
302 "Error getting DirEnries");
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000303 return ipmi::responseUnspecifiedError();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700304 }
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000305 if (dirIndex > std::get<uint8_t>(value))
Vernon Mauerya3702c12019-05-22 13:20:59 -0700306 {
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000307 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700308 }
309
Vernon Mauery15419dd2019-05-24 09:40:30 -0700310 sdbusplus::message::message method = bus->new_method_call(
Vernon Mauerya3702c12019-05-22 13:20:59 -0700311 service.c_str(), mdrv2Path, mdrv2Interface, "GetDirectoryInformation");
312
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000313 method.append(dirIndex);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700314
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000315 std::vector<uint8_t> dataOut;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700316 try
317 {
Vernon Mauery15419dd2019-05-24 09:40:30 -0700318 sdbusplus::message::message reply = bus->call(method);
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000319 reply.read(dataOut);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700320 }
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700321 catch (sdbusplus::exception_t &e)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700322 {
323 phosphor::logging::log<phosphor::logging::level::ERR>(
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700324 "Error get dir", phosphor::logging::entry("ERROR=%s", e.what()),
Vernon Mauerya3702c12019-05-22 13:20:59 -0700325 phosphor::logging::entry("SERVICE=%s", service.c_str()),
326 phosphor::logging::entry("PATH=%s", mdrv2Path));
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000327 return ipmi::responseResponseError();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700328 }
329
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000330 constexpr size_t getDirRespSize = 6;
331 if (dataOut.size() < getDirRespSize)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700332 {
333 phosphor::logging::log<phosphor::logging::level::ERR>(
334 "Error get dir, response length invalid");
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000335 return ipmi::responseUnspecifiedError();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700336 }
337
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000338 if (dataOut.size() > MAX_IPMI_BUFFER) // length + completion code should no
339 // more than MAX_IPMI_BUFFER
Vernon Mauerya3702c12019-05-22 13:20:59 -0700340 {
341 phosphor::logging::log<phosphor::logging::level::ERR>(
342 "Data length send from service is invalid");
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000343 return ipmi::responseResponseError();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700344 }
345
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +0000346 return ipmi::responseSuccess(dataOut);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700347}
348
jayaprakash Mutyala7cb59cc2019-06-19 19:17:43 +0000349ipmi::RspType<bool> mdr2SendDir(uint16_t agentId, uint8_t dirVersion,
350 uint8_t dirIndex, uint8_t returnedEntries,
351 uint8_t remainingEntries,
352 std::array<uint8_t, 16> dataInfo, uint32_t size,
353 uint32_t dataSetSize, uint32_t dataVersion,
354 uint32_t timestamp)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700355{
Vernon Mauery15419dd2019-05-24 09:40:30 -0700356 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
357 std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700358
359 if (mdrv2 == nullptr)
360 {
361 mdrv2 = std::make_unique<MDRV2>();
362 }
363
jayaprakash Mutyala7cb59cc2019-06-19 19:17:43 +0000364 int agentIndex = mdrv2->agentLookup(agentId);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700365 if (agentIndex == -1)
366 {
367 phosphor::logging::log<phosphor::logging::level::ERR>(
jayaprakash Mutyala7cb59cc2019-06-19 19:17:43 +0000368 "Unknown agent id", phosphor::logging::entry("ID=%x", agentId));
369 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700370 }
371
jayaprakash Mutyala7cb59cc2019-06-19 19:17:43 +0000372 if ((dirIndex + returnedEntries) > maxDirEntries)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700373 {
374 phosphor::logging::log<phosphor::logging::level::ERR>(
375 "Too many directory entries");
jayaprakash Mutyala7cb59cc2019-06-19 19:17:43 +0000376 return ipmi::response(ccStorageLeak);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700377 }
378
Vernon Mauery15419dd2019-05-24 09:40:30 -0700379 sdbusplus::message::message method = bus->new_method_call(
Vernon Mauerya3702c12019-05-22 13:20:59 -0700380 service.c_str(), mdrv2Path, mdrv2Interface, "SendDirectoryInformation");
jayaprakash Mutyala7cb59cc2019-06-19 19:17:43 +0000381 method.append(dirVersion, dirIndex, returnedEntries, remainingEntries,
382 dataInfo, size, dataSetSize, dataVersion, timestamp);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700383
jayaprakash Mutyala7cb59cc2019-06-19 19:17:43 +0000384 bool terminate = false;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700385 try
386 {
Vernon Mauery15419dd2019-05-24 09:40:30 -0700387 sdbusplus::message::message reply = bus->call(method);
jayaprakash Mutyala7cb59cc2019-06-19 19:17:43 +0000388 reply.read(terminate);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700389 }
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700390 catch (sdbusplus::exception_t &e)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700391 {
392 phosphor::logging::log<phosphor::logging::level::ERR>(
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700393 "Error send dir", phosphor::logging::entry("ERROR=%s", e.what()),
Vernon Mauerya3702c12019-05-22 13:20:59 -0700394 phosphor::logging::entry("SERVICE=%s", service.c_str()),
395 phosphor::logging::entry("PATH=%s", mdrv2Path));
jayaprakash Mutyala7cb59cc2019-06-19 19:17:43 +0000396 return ipmi::responseResponseError();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700397 }
398
jayaprakash Mutyala7cb59cc2019-06-19 19:17:43 +0000399 return ipmi::responseSuccess(terminate);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700400}
401
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000402/** @brief implements mdr2 get data info command
403 * @param agentId
404 * @param dataInfo
405 *
406 * @returns IPMI completion code plus response data
407 * - response - mdrVersion, data info, validFlag,
408 * dataLength, dataVersion, timeStamp
409 */
410ipmi::RspType<std::vector<uint8_t>>
411 mdr2GetDataInfo(uint16_t agentId, std::vector<uint8_t> dataInfo)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700412{
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000413 constexpr size_t getDataInfoReqSize = 16;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700414
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000415 if (dataInfo.size() < getDataInfoReqSize)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700416 {
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000417 return ipmi::responseReqDataLenInvalid();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700418 }
419
Vernon Mauery15419dd2019-05-24 09:40:30 -0700420 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
421 std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700422
423 if (mdrv2 == nullptr)
424 {
425 mdrv2 = std::make_unique<MDRV2>();
426 }
427
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000428 int agentIndex = mdrv2->agentLookup(agentId);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700429 if (agentIndex == -1)
430 {
431 phosphor::logging::log<phosphor::logging::level::ERR>(
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000432 "Unknown agent id", phosphor::logging::entry("ID=%x", agentId));
433 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700434 }
435
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000436 int idIndex = mdrv2->findDataId(dataInfo.data(), dataInfo.size(), service);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700437
438 if ((idIndex < 0) || (idIndex >= maxDirEntries))
439 {
440 phosphor::logging::log<phosphor::logging::level::ERR>(
441 "Invalid Data ID", phosphor::logging::entry("IDINDEX=%x", idIndex));
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000442 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700443 }
444
Vernon Mauery15419dd2019-05-24 09:40:30 -0700445 sdbusplus::message::message method = bus->new_method_call(
Vernon Mauerya3702c12019-05-22 13:20:59 -0700446 service.c_str(), mdrv2Path, mdrv2Interface, "GetDataInformation");
447
448 method.append(idIndex);
449
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000450 std::vector<uint8_t> res;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700451 try
452 {
Vernon Mauery15419dd2019-05-24 09:40:30 -0700453 sdbusplus::message::message reply = bus->call(method);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700454 reply.read(res);
455 }
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700456 catch (sdbusplus::exception_t &e)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700457 {
458 phosphor::logging::log<phosphor::logging::level::ERR>(
459 "Error get data info",
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700460 phosphor::logging::entry("ERROR=%s", e.what()),
Vernon Mauerya3702c12019-05-22 13:20:59 -0700461 phosphor::logging::entry("SERVICE=%s", service.c_str()),
462 phosphor::logging::entry("PATH=%s", mdrv2Path));
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000463 return ipmi::responseResponseError();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700464 }
465
466 if (res.size() != sizeof(MDRiiGetDataInfoResponse))
467 {
468 phosphor::logging::log<phosphor::logging::level::ERR>(
469 "Get data info response length not invalid");
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000470 return ipmi::responseResponseError();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700471 }
Vernon Mauerya3702c12019-05-22 13:20:59 -0700472
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000473 return ipmi::responseSuccess(res);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700474}
475
jayaprakash Mutyala853d8292019-05-31 18:17:42 +0000476/** @brief implements mdr2 data info offer command
477 * @param agentId - Offer a agent ID to get the "Data Set ID"
478 *
479 * @returns IPMI completion code plus response data
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000480 * - dataOut - data Set Id
jayaprakash Mutyala853d8292019-05-31 18:17:42 +0000481 */
482ipmi::RspType<std::vector<uint8_t>> mdr2DataInfoOffer(uint16_t agentId)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700483{
Vernon Mauery15419dd2019-05-24 09:40:30 -0700484 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
485 std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700486
487 if (mdrv2 == nullptr)
488 {
489 mdrv2 = std::make_unique<MDRV2>();
490 }
491
jayaprakash Mutyala853d8292019-05-31 18:17:42 +0000492 int agentIndex = mdrv2->agentLookup(agentId);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700493 if (agentIndex == -1)
494 {
495 phosphor::logging::log<phosphor::logging::level::ERR>(
jayaprakash Mutyala853d8292019-05-31 18:17:42 +0000496 "Unknown agent id", phosphor::logging::entry("ID=%x", agentId));
497 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700498 }
499
Vernon Mauery15419dd2019-05-24 09:40:30 -0700500 sdbusplus::message::message method = bus->new_method_call(
Vernon Mauerya3702c12019-05-22 13:20:59 -0700501 service.c_str(), mdrv2Path, mdrv2Interface, "GetDataOffer");
502
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000503 std::vector<uint8_t> dataOut;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700504 try
505 {
Vernon Mauery15419dd2019-05-24 09:40:30 -0700506 sdbusplus::message::message reply = bus->call(method);
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000507 reply.read(dataOut);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700508 }
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700509 catch (sdbusplus::exception_t &e)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700510 {
511 phosphor::logging::log<phosphor::logging::level::ERR>(
512 "Error send data info offer",
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700513 phosphor::logging::entry("ERROR=%s", e.what()),
Vernon Mauerya3702c12019-05-22 13:20:59 -0700514 phosphor::logging::entry("SERVICE=%s", service.c_str()),
515 phosphor::logging::entry("PATH=%s", mdrv2Path));
jayaprakash Mutyala853d8292019-05-31 18:17:42 +0000516 return ipmi::responseResponseError();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700517 }
518
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000519 constexpr size_t respInfoSize = 16;
520 if (dataOut.size() != respInfoSize)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700521 {
522 phosphor::logging::log<phosphor::logging::level::ERR>(
523 "Error send data info offer, return length invalid");
jayaprakash Mutyala853d8292019-05-31 18:17:42 +0000524 return ipmi::responseUnspecifiedError();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700525 }
526
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000527 return ipmi::responseSuccess(dataOut);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700528}
529
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000530/** @brief implements mdr2 send data info command
531 * @param agentId
532 * @param dataInfo
533 * @param validFlag
534 * @param dataLength
535 * @param dataVersion
536 * @param timeStamp
537 *
538 * @returns IPMI completion code plus response data
539 * - bool
540 */
541ipmi::RspType<bool> mdr2SendDataInfo(uint16_t agentId,
542 std::array<uint8_t, dataInfoSize> dataInfo,
543 uint8_t validFlag, uint32_t dataLength,
544 uint32_t dataVersion, uint32_t timeStamp)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700545{
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000546 if (dataLength > smbiosTableStorageSize)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700547 {
548 phosphor::logging::log<phosphor::logging::level::ERR>(
549 "Requested data length is out of SMBIOS Table storage size.");
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000550 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700551 }
552
Vernon Mauery15419dd2019-05-24 09:40:30 -0700553 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
554 std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700555
556 if (mdrv2 == nullptr)
557 {
558 mdrv2 = std::make_unique<MDRV2>();
559 }
560
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000561 int agentIndex = mdrv2->agentLookup(agentId);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700562 if (agentIndex == -1)
563 {
564 phosphor::logging::log<phosphor::logging::level::ERR>(
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000565 "Unknown agent id", phosphor::logging::entry("ID=%x", agentId));
566 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700567 }
568
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000569 int idIndex = mdrv2->findDataId(dataInfo.data(), sizeof(dataInfo), service);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700570
571 if ((idIndex < 0) || (idIndex >= maxDirEntries))
572 {
573 phosphor::logging::log<phosphor::logging::level::ERR>(
574 "Invalid Data ID", phosphor::logging::entry("IDINDEX=%x", idIndex));
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000575 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700576 }
577
Vernon Mauery15419dd2019-05-24 09:40:30 -0700578 sdbusplus::message::message method = bus->new_method_call(
Vernon Mauerya3702c12019-05-22 13:20:59 -0700579 service.c_str(), mdrv2Path, mdrv2Interface, "SendDataInformation");
580
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000581 method.append((uint8_t)idIndex, validFlag, dataLength, dataVersion,
582 timeStamp);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700583
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000584 bool entryChanged = true;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700585 try
586 {
Vernon Mauery15419dd2019-05-24 09:40:30 -0700587 sdbusplus::message::message reply = bus->call(method);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700588 reply.read(entryChanged);
589 }
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700590 catch (sdbusplus::exception_t &e)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700591 {
592 phosphor::logging::log<phosphor::logging::level::ERR>(
593 "Error send data info",
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700594 phosphor::logging::entry("ERROR=%s", e.what()),
Vernon Mauerya3702c12019-05-22 13:20:59 -0700595 phosphor::logging::entry("SERVICE=%s", service.c_str()),
596 phosphor::logging::entry("PATH=%s", mdrv2Path));
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000597 return ipmi::responseResponseError();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700598 }
599
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +0000600 return ipmi::responseSuccess(entryChanged);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700601}
602
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000603/**
604@brief This command is MDR related get data block command.
605
606@param - agentId
607@param - lockHandle
608@param - xferOffset
609@param - xferLength
610
611@return on success
612 - xferLength
613 - checksum
614 - data
615**/
616ipmi::RspType<uint32_t, // xferLength
617 uint32_t, // Checksum
618 std::vector<uint8_t> // data
619 >
620 mdr2GetDataBlock(uint16_t agentId, uint16_t lockHandle, uint32_t xferOffset,
621 uint32_t xferLength)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700622{
Vernon Mauerya3702c12019-05-22 13:20:59 -0700623 std::tuple<uint8_t, uint32_t, uint32_t, std::vector<uint8_t>> res;
624 std::vector<uint8_t> resData;
625 uint8_t status = 1;
626
Vernon Mauerya3702c12019-05-22 13:20:59 -0700627 if (mdrv2 == nullptr)
628 {
629 mdrv2 = std::make_unique<MDRV2>();
630 }
631
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000632 int agentIndex = mdrv2->agentLookup(agentId);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700633 if (agentIndex == -1)
634 {
635 phosphor::logging::log<phosphor::logging::level::ERR>(
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000636 "Unknown agent id", phosphor::logging::entry("ID=%x", agentId));
637 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700638 }
639
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000640 int idIndex = mdrv2->findLockHandle(lockHandle);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700641
642 if ((idIndex < 0) || (idIndex >= maxDirEntries))
643 {
644 phosphor::logging::log<phosphor::logging::level::ERR>(
645 "Invalid Data ID", phosphor::logging::entry("IDINDEX=%x", idIndex));
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000646 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700647 }
648
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000649 if (xferOffset >= mdrv2->smbiosDir.dir[idIndex].common.size)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700650 {
651 phosphor::logging::log<phosphor::logging::level::ERR>(
652 "Offset is outside of range.");
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000653 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700654 }
655
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000656 size_t outSize = (xferLength > mdrv2->smbiosDir.dir[idIndex].xferSize)
657 ? mdrv2->smbiosDir.dir[idIndex].xferSize
658 : xferLength;
659 if (outSize > UINT_MAX - xferOffset)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700660 {
661 phosphor::logging::log<phosphor::logging::level::ERR>(
662 "Out size and offset are out of range");
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000663 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700664 }
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000665 if ((xferOffset + outSize) > mdrv2->smbiosDir.dir[idIndex].common.size)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700666 {
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000667 outSize = mdrv2->smbiosDir.dir[idIndex].common.size - xferOffset;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700668 }
669
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000670 uint32_t respXferLength = outSize;
671
672 if (respXferLength > xferLength)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700673 {
674 phosphor::logging::log<phosphor::logging::level::ERR>(
675 "Get data block unexpected error.");
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000676 return ipmi::responseUnspecifiedError();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700677 }
678
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000679 if ((xferOffset + outSize) >
Vernon Mauerya3702c12019-05-22 13:20:59 -0700680 UINT_MAX -
681 reinterpret_cast<size_t>(mdrv2->smbiosDir.dir[idIndex].dataStorage))
682 {
683 phosphor::logging::log<phosphor::logging::level::ERR>(
684 "Input data to calculate checksum is out of range");
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000685 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700686 }
687
688 uint32_t u32Checksum = mdrv2->calcChecksum32(
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000689 mdrv2->smbiosDir.dir[idIndex].dataStorage + xferOffset, outSize);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700690 if (u32Checksum == invalidChecksum)
691 {
692 phosphor::logging::log<phosphor::logging::level::ERR>(
693 "Get data block failed - invalid checksum");
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000694 return ipmi::response(ccOemInvalidChecksum);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700695 }
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000696 std::vector<uint8_t> data(outSize);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700697
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000698 std::copy(&mdrv2->smbiosDir.dir[idIndex].dataStorage[xferOffset],
699 &mdrv2->smbiosDir.dir[idIndex].dataStorage[xferOffset + outSize],
700 data.begin());
Vernon Mauerya3702c12019-05-22 13:20:59 -0700701
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000702 return ipmi::responseSuccess(respXferLength, u32Checksum, data);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700703}
704
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000705/** @brief implements mdr2 send data block command
706 * @param agentId
707 * @param lockHandle
708 * @param xferOffset
709 * @param xferLength
710 * @param checksum
711 *
712 * @returns IPMI completion code
713 */
714ipmi::RspType<> mdr2SendDataBlock(uint16_t agentId, uint16_t lockHandle,
715 uint32_t xferOffset, uint32_t xferLength,
716 uint32_t checksum)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700717{
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +0000718
Vernon Mauerya3702c12019-05-22 13:20:59 -0700719 if (mdrv2 == nullptr)
720 {
721 mdrv2 = std::make_unique<MDRV2>();
722 }
723
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000724 int agentIndex = mdrv2->agentLookup(agentId);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700725 if (agentIndex == -1)
726 {
727 phosphor::logging::log<phosphor::logging::level::ERR>(
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000728 "Unknown agent id", phosphor::logging::entry("ID=%x", agentId));
729 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700730 }
731
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000732 int idIndex = mdrv2->findLockHandle(lockHandle);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700733
734 if ((idIndex < 0) || (idIndex >= maxDirEntries))
735 {
736 phosphor::logging::log<phosphor::logging::level::ERR>(
737 "Invalid Data ID", phosphor::logging::entry("IDINDEX=%x", idIndex));
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000738 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700739 }
740
741 if (mdrv2->smbiosIsUpdating(idIndex))
742 {
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000743 if (xferOffset > UINT_MAX - xferLength)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700744 {
745 phosphor::logging::log<phosphor::logging::level::ERR>(
746 "Offset and length are out of range");
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000747 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700748 }
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000749 if (((xferOffset + xferLength) >
Vernon Mauerya3702c12019-05-22 13:20:59 -0700750 mdrv2->smbiosDir.dir[idIndex].maxDataSize) ||
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000751 ((xferOffset + xferLength) >
Vernon Mauerya3702c12019-05-22 13:20:59 -0700752 mdrv2->smbiosDir.dir[idIndex].common.dataSetSize))
753 {
754 phosphor::logging::log<phosphor::logging::level::ERR>(
755 "Send data block Invalid offset/length");
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000756 return ipmi::responseReqDataLenExceeded();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700757 }
758 if (reinterpret_cast<size_t>(
759 mdrv2->smbiosDir.dir[idIndex].dataStorage) >
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000760 UINT_MAX - xferOffset)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700761 {
762 phosphor::logging::log<phosphor::logging::level::ERR>(
763 "Offset is out of range");
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000764 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700765 }
766 uint8_t *destAddr =
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000767 mdrv2->smbiosDir.dir[idIndex].dataStorage + xferOffset;
Vernon Mauerya3702c12019-05-22 13:20:59 -0700768 uint8_t *sourceAddr = reinterpret_cast<uint8_t *>(mdrv2->area->vPtr);
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000769 uint32_t calcChecksum = mdrv2->calcChecksum32(sourceAddr, xferLength);
770 if (calcChecksum != checksum)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700771 {
772 phosphor::logging::log<phosphor::logging::level::ERR>(
773 "Send data block Invalid checksum");
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000774 return ipmi::response(ccOemInvalidChecksum);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700775 }
776 else
777 {
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000778 if (reinterpret_cast<size_t>(sourceAddr) > UINT_MAX - xferLength)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700779 {
780 phosphor::logging::log<phosphor::logging::level::ERR>(
781 "Length is out of range");
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000782 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700783 }
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000784 std::copy(sourceAddr, sourceAddr + xferLength, destAddr);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700785 }
786 }
787 else
788 {
789 phosphor::logging::log<phosphor::logging::level::ERR>(
790 "Send data block failed, other data is updating");
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000791 return ipmi::responseDestinationUnavailable();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700792 }
793
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +0000794 return ipmi::responseSuccess();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700795}
796
797bool MDRV2::storeDatatoFlash(MDRSMBIOSHeader *mdrHdr, uint8_t *data)
798{
799 std::ofstream smbiosFile(mdrType2File,
800 std::ios_base::binary | std::ios_base::trunc);
801 if (!smbiosFile.good())
802 {
803 phosphor::logging::log<phosphor::logging::level::ERR>(
804 "Write data from flash error - Open MDRV2 table file failure");
805 return false;
806 }
807
808 try
809 {
810 smbiosFile.write(reinterpret_cast<char *>(mdrHdr),
811 sizeof(MDRSMBIOSHeader));
812 smbiosFile.write(reinterpret_cast<char *>(data), mdrHdr->dataSize);
813 }
814 catch (std::ofstream::failure &e)
815 {
816 phosphor::logging::log<phosphor::logging::level::ERR>(
Vernon Maueryc7d517e2019-06-18 14:27:00 -0700817 "Write data from flash error - write data error",
818 phosphor::logging::entry("ERROR=%s", e.what()));
Vernon Mauerya3702c12019-05-22 13:20:59 -0700819 return false;
820 }
821
822 return true;
823}
824
825void SharedMemoryArea::Initialize(uint32_t addr, uint32_t areaSize)
826{
827 int memDriver = 0;
828
829 // open mem driver for the system memory access
830 memDriver = open("/dev/vgasharedmem", O_RDONLY);
831 if (memDriver < 0)
832 {
833 phosphor::logging::log<phosphor::logging::level::ERR>(
834 "Cannot access mem driver");
835 throw std::system_error(EIO, std::generic_category());
836 }
837
838 // map the system memory
839 vPtr = mmap(NULL, // where to map to: don't mind
840 areaSize, // how many bytes ?
841 PROT_READ, // want to read and write
842 MAP_SHARED, // no copy on write
843 memDriver, // handle to /dev/mem
844 (physicalAddr & pageMask)); // hopefully the Text-buffer :-)
845
846 close(memDriver);
847 if (vPtr == MAP_FAILED)
848 {
849 phosphor::logging::log<phosphor::logging::level::ERR>(
850 "Failed to map share memory");
851 throw std::system_error(EIO, std::generic_category());
852 }
853 size = areaSize;
854 physicalAddr = addr;
855}
856
857bool MDRV2::smbiosUnlock(uint8_t index)
858{
859 bool ret;
860 switch (smbiosDir.dir[index].stage)
861 {
862 case MDR2SMBIOSStatusEnum::mdr2Updating:
863 smbiosDir.dir[index].stage = MDR2SMBIOSStatusEnum::mdr2Updated;
864 smbiosDir.dir[index].lock = MDR2DirLockEnum::mdr2DirUnlock;
865
866 timer->stop();
867 smbiosDir.dir[index].lockHandle = 0;
868 ret = true;
869 break;
870
871 case MDR2SMBIOSStatusEnum::mdr2Updated:
872 case MDR2SMBIOSStatusEnum::mdr2Loaded:
873 smbiosDir.dir[index].lock = MDR2DirLockEnum::mdr2DirUnlock;
874
875 timer->stop();
876
877 smbiosDir.dir[index].lockHandle = 0;
878 ret = true;
879 break;
880
881 default:
882 break;
883 }
884
885 return ret;
886}
887
888bool MDRV2::smbiosTryLock(uint8_t flag, uint8_t index, uint16_t *session,
889 uint16_t timeout)
890{
891 bool ret = false;
892 uint32_t u32Status = 0;
893
894 if (timeout == 0)
895 {
896 timeout = defaultTimeout;
897 }
898 std::chrono::microseconds usec(timeout * sysClock);
899
900 switch (smbiosDir.dir[index].stage)
901 {
902 case MDR2SMBIOSStatusEnum::mdr2Updating:
903 if (smbiosDir.dir[index].lock != MDR2DirLockEnum::mdr2DirLock)
904 {
905 smbiosDir.dir[index].lock = MDR2DirLockEnum::mdr2DirLock;
906 timer->start(usec);
907 lockIndex = index;
908
909 *session = getSessionHandle(&smbiosDir);
910 smbiosDir.dir[index].lockHandle = *session;
911 ret = true;
912 }
913 break;
914 case MDR2SMBIOSStatusEnum::mdr2Init:
915 if (flag)
916 {
917 smbiosDir.dir[index].stage = MDR2SMBIOSStatusEnum::mdr2Updating;
918 smbiosDir.dir[index].lock = MDR2DirLockEnum::mdr2DirUnlock;
919 timer->start(usec);
920 lockIndex = index;
921
922 *session = getSessionHandle(&smbiosDir);
923 smbiosDir.dir[index].lockHandle = *session;
924 ret = true;
925 }
926 break;
927
928 case MDR2SMBIOSStatusEnum::mdr2Updated:
929 case MDR2SMBIOSStatusEnum::mdr2Loaded:
930 if (smbiosDir.dir[index].lock != MDR2DirLockEnum::mdr2DirLock)
931 {
932 if (flag)
933 {
934 smbiosDir.dir[index].stage =
935 MDR2SMBIOSStatusEnum::mdr2Updating;
936 smbiosDir.dir[index].lock = MDR2DirLockEnum::mdr2DirUnlock;
937 }
938 else
939 {
940 smbiosDir.dir[index].lock = MDR2DirLockEnum::mdr2DirLock;
941 }
942
943 timer->start(usec);
944 lockIndex = index;
945
946 *session = getSessionHandle(&smbiosDir);
947 smbiosDir.dir[index].lockHandle = *session;
948 ret = true;
949 }
950 break;
951
952 default:
953 break;
954 }
955 return ret;
956}
957
958void MDRV2::timeoutHandler()
959{
960 smbiosUnlock(lockIndex);
961 mdrv2->area.reset(nullptr);
962}
963
jayaprakash Mutyala40fec612019-06-19 11:53:03 +0000964/** @brief implements mdr2 lock data command
965 * @param agentId
966 * @param dataInfo
967 * @param timeout
968 *
969 * @returns IPMI completion code plus response data
970 * - mdr2Version
971 * - session
972 * - dataLength
973 * - xferAddress
974 * - xferLength
975 */
976ipmi::RspType<uint8_t, // mdr2Version
977 uint16_t, // session
978 uint32_t, // dataLength
979 uint32_t, // xferAddress
980 uint32_t // xferLength
981 >
982 mdr2LockData(uint16_t agentId, std::array<uint8_t, dataInfoSize> dataInfo,
983 uint16_t timeout)
Vernon Mauerya3702c12019-05-22 13:20:59 -0700984{
Vernon Mauerya3702c12019-05-22 13:20:59 -0700985 if (mdrv2 == nullptr)
986 {
987 mdrv2 = std::make_unique<MDRV2>();
988 }
989
jayaprakash Mutyala40fec612019-06-19 11:53:03 +0000990 int agentIndex = mdrv2->agentLookup(agentId);
Vernon Mauerya3702c12019-05-22 13:20:59 -0700991 if (agentIndex == -1)
992 {
993 phosphor::logging::log<phosphor::logging::level::ERR>(
jayaprakash Mutyala40fec612019-06-19 11:53:03 +0000994 "Unknown agent id", phosphor::logging::entry("ID=%x", agentId));
995 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -0700996 }
997
Vernon Mauery15419dd2019-05-24 09:40:30 -0700998 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
999 std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001000
jayaprakash Mutyala40fec612019-06-19 11:53:03 +00001001 int idIndex = mdrv2->findDataId(dataInfo.data(), sizeof(dataInfo), service);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001002
1003 if ((idIndex < 0) || (idIndex >= maxDirEntries))
1004 {
1005 phosphor::logging::log<phosphor::logging::level::ERR>(
1006 "Invalid Data ID", phosphor::logging::entry("IDINDEX=%x", idIndex));
jayaprakash Mutyala40fec612019-06-19 11:53:03 +00001007 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001008 }
1009
jayaprakash Mutyala40fec612019-06-19 11:53:03 +00001010 uint16_t session = 0;
1011 if (!mdrv2->smbiosTryLock(0, idIndex, &session, timeout))
Vernon Mauerya3702c12019-05-22 13:20:59 -07001012 {
1013 phosphor::logging::log<phosphor::logging::level::ERR>(
1014 "Lock Data failed - cannot lock idIndex");
jayaprakash Mutyala40fec612019-06-19 11:53:03 +00001015 return ipmi::responseCommandNotAvailable();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001016 }
1017
jayaprakash Mutyala40fec612019-06-19 11:53:03 +00001018 uint32_t dataLength = mdrv2->smbiosDir.dir[idIndex].common.size;
1019 uint32_t xferAddress = mdrv2->smbiosDir.dir[idIndex].xferBuff;
1020 uint32_t xferLength = mdrv2->smbiosDir.dir[idIndex].xferSize;
Vernon Mauerya3702c12019-05-22 13:20:59 -07001021
jayaprakash Mutyala40fec612019-06-19 11:53:03 +00001022 return ipmi::responseSuccess(mdr2Version, session, dataLength, xferAddress,
1023 xferLength);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001024}
1025
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +00001026/** @brief implements mdr2 unlock data command
1027 * @param agentId
1028 * @param lockHandle
1029 *
1030 * @returns IPMI completion code
1031 */
1032ipmi::RspType<> mdr2UnlockData(uint16_t agentId, uint16_t lockHandle)
Vernon Mauerya3702c12019-05-22 13:20:59 -07001033{
1034 phosphor::logging::log<phosphor::logging::level::ERR>("unlock data");
Vernon Mauerya3702c12019-05-22 13:20:59 -07001035
Vernon Mauerya3702c12019-05-22 13:20:59 -07001036 if (mdrv2 == nullptr)
1037 {
1038 mdrv2 = std::make_unique<MDRV2>();
1039 }
1040
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +00001041 int agentIndex = mdrv2->agentLookup(agentId);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001042 if (agentIndex == -1)
1043 {
1044 phosphor::logging::log<phosphor::logging::level::ERR>(
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +00001045 "Unknown agent id", phosphor::logging::entry("ID=%x", agentId));
1046 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001047 }
1048
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +00001049 int idIndex = mdrv2->findLockHandle(lockHandle);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001050
1051 if ((idIndex < 0) || (idIndex >= maxDirEntries))
1052 {
1053 phosphor::logging::log<phosphor::logging::level::ERR>(
1054 "Invalid Data ID", phosphor::logging::entry("IDINDEX=%x", idIndex));
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +00001055 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001056 }
1057
1058 if (!mdrv2->smbiosUnlock(idIndex))
1059 {
1060 phosphor::logging::log<phosphor::logging::level::ERR>(
1061 "Unlock Data failed - cannot unlock idIndex");
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +00001062 return ipmi::responseCommandNotAvailable();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001063 }
1064
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +00001065 return ipmi::responseSuccess();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001066}
1067
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001068/**
1069@brief This command is executed after POST BIOS to get the session info.
1070
1071@param - agentId, dataInfo, dataLength, xferAddress, xferLength, timeout.
1072
1073@return xferStartAck and session on success.
1074**/
1075ipmi::RspType<uint8_t, uint16_t>
1076 cmd_mdr2_data_start(uint16_t agentId, std::array<uint8_t, 16> dataInfo,
1077 uint32_t dataLength, uint32_t xferAddress,
1078 uint32_t xferLength, uint16_t timeout)
Vernon Mauerya3702c12019-05-22 13:20:59 -07001079{
Vernon Mauerya3702c12019-05-22 13:20:59 -07001080 uint16_t session = 0;
1081
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001082 if (dataLength > smbiosTableStorageSize)
Vernon Mauerya3702c12019-05-22 13:20:59 -07001083 {
1084 phosphor::logging::log<phosphor::logging::level::ERR>(
1085 "Requested data length is out of SMBIOS Table storage size.");
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001086 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001087 }
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001088 if ((xferLength + xferAddress) > mdriiSMSize)
Vernon Mauerya3702c12019-05-22 13:20:59 -07001089 {
1090 phosphor::logging::log<phosphor::logging::level::ERR>(
1091 "Invalid data address and size");
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001092 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001093 }
1094
Vernon Mauery15419dd2019-05-24 09:40:30 -07001095 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
1096 std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001097
1098 if (mdrv2 == nullptr)
1099 {
1100 mdrv2 = std::make_unique<MDRV2>();
1101 }
1102
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001103 int agentIndex = mdrv2->agentLookup(agentId);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001104 if (agentIndex == -1)
1105 {
1106 phosphor::logging::log<phosphor::logging::level::ERR>(
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001107 "Unknown agent id", phosphor::logging::entry("ID=%x", agentId));
1108 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001109 }
1110
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001111 int idIndex = mdrv2->findDataId(dataInfo.data(), sizeof(dataInfo), service);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001112
1113 if ((idIndex < 0) || (idIndex >= maxDirEntries))
1114 {
1115 phosphor::logging::log<phosphor::logging::level::ERR>(
1116 "Invalid Data ID", phosphor::logging::entry("IDINDEX=%x", idIndex));
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001117 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001118 }
1119
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001120 if (mdrv2->smbiosTryLock(1, idIndex, &session, timeout))
Vernon Mauerya3702c12019-05-22 13:20:59 -07001121 {
1122 try
1123 {
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001124 mdrv2->area =
1125 std::make_unique<SharedMemoryArea>(xferAddress, xferLength);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001126 }
1127 catch (const std::system_error &e)
1128 {
1129 mdrv2->smbiosUnlock(idIndex);
1130 phosphor::logging::log<phosphor::logging::level::ERR>(
Vernon Maueryc7d517e2019-06-18 14:27:00 -07001131 "Unable to access share memory",
1132 phosphor::logging::entry("ERROR=%s", e.what()));
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001133 return ipmi::responseUnspecifiedError();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001134 }
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001135 mdrv2->smbiosDir.dir[idIndex].common.size = dataLength;
Vernon Mauerya3702c12019-05-22 13:20:59 -07001136 mdrv2->smbiosDir.dir[idIndex].lockHandle = session;
1137 if (-1 ==
1138 mdrv2->syncDirCommonData(
1139 idIndex, mdrv2->smbiosDir.dir[idIndex].common.size, service))
1140 {
1141 phosphor::logging::log<phosphor::logging::level::ERR>(
1142 "Unable to sync data to service");
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001143 return ipmi::responseResponseError();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001144 }
1145 }
1146 else
1147 {
1148 phosphor::logging::log<phosphor::logging::level::ERR>(
1149 "Canot lock smbios");
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001150 return ipmi::responseUnspecifiedError();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001151 }
1152
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001153 static constexpr uint8_t xferStartAck = 1;
Vernon Mauerya3702c12019-05-22 13:20:59 -07001154
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001155 return ipmi::responseSuccess(xferStartAck, session);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001156}
1157
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001158/**
1159@brief This command is executed to close the session.
1160
1161@param - agentId, lockHandle.
1162
1163@return completion code on success.
1164**/
1165ipmi::RspType<> cmd_mdr2_data_done(uint16_t agentId, uint16_t lockHandle)
Vernon Mauerya3702c12019-05-22 13:20:59 -07001166{
Vernon Mauerya3702c12019-05-22 13:20:59 -07001167
1168 if (mdrv2 == nullptr)
1169 {
1170 mdrv2 = std::make_unique<MDRV2>();
1171 }
1172
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001173 int agentIndex = mdrv2->agentLookup(agentId);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001174 if (agentIndex == -1)
1175 {
1176 phosphor::logging::log<phosphor::logging::level::ERR>(
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001177 "Unknown agent id", phosphor::logging::entry("ID=%x", agentId));
1178 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001179 }
1180
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001181 int idIndex = mdrv2->findLockHandle(lockHandle);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001182
1183 if ((idIndex < 0) || (idIndex >= maxDirEntries))
1184 {
1185 phosphor::logging::log<phosphor::logging::level::ERR>(
1186 "Invalid Data ID", phosphor::logging::entry("IDINDEX=%x", idIndex));
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001187 return ipmi::responseParmOutOfRange();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001188 }
1189
1190 if (!mdrv2->smbiosUnlock(idIndex))
1191 {
1192 phosphor::logging::log<phosphor::logging::level::ERR>(
1193 "Send data done failed - cannot unlock idIndex");
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001194 return ipmi::responseDestinationUnavailable();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001195 }
1196
1197 mdrv2->area.reset(nullptr);
1198 MDRSMBIOSHeader mdr2Smbios;
1199 mdr2Smbios.mdrType = mdrTypeII;
1200 mdr2Smbios.dirVer = mdrv2->smbiosDir.dir[0].common.dataVersion;
1201 mdr2Smbios.timestamp = mdrv2->smbiosDir.dir[0].common.timestamp;
1202 mdr2Smbios.dataSize = mdrv2->smbiosDir.dir[0].common.size;
1203
1204 if (access(smbiosPath, 0) == -1)
1205 {
1206 int flag = mkdir(smbiosPath, S_IRWXU);
1207 if (flag != 0)
1208 {
1209 phosphor::logging::log<phosphor::logging::level::ERR>(
1210 "create folder failed for writting smbios file");
1211 }
1212 }
1213 if (!mdrv2->storeDatatoFlash(
1214 &mdr2Smbios, mdrv2->smbiosDir.dir[smbiosDirIndex].dataStorage))
1215 {
1216 phosphor::logging::log<phosphor::logging::level::ERR>(
1217 "MDR2 Store data to flash failed");
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001218 return ipmi::responseDestinationUnavailable();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001219 }
Vernon Mauerya3702c12019-05-22 13:20:59 -07001220 bool status = false;
Vernon Mauery15419dd2019-05-24 09:40:30 -07001221 std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
1222 std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path);
1223 sdbusplus::message::message method = bus->new_method_call(
Vernon Mauerya3702c12019-05-22 13:20:59 -07001224 service.c_str(), mdrv2Path, mdrv2Interface, "AgentSynchronizeData");
1225
1226 try
1227 {
Vernon Mauery15419dd2019-05-24 09:40:30 -07001228 sdbusplus::message::message reply = bus->call(method);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001229 reply.read(status);
1230 }
Vernon Maueryc7d517e2019-06-18 14:27:00 -07001231 catch (sdbusplus::exception_t &e)
Vernon Mauerya3702c12019-05-22 13:20:59 -07001232 {
1233 phosphor::logging::log<phosphor::logging::level::ERR>(
1234 "Error Sync data with service",
Vernon Maueryc7d517e2019-06-18 14:27:00 -07001235 phosphor::logging::entry("ERROR=%s", e.what()),
Vernon Mauerya3702c12019-05-22 13:20:59 -07001236 phosphor::logging::entry("SERVICE=%s", service.c_str()),
1237 phosphor::logging::entry("PATH=%s", mdrv2Path));
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001238 return ipmi::responseResponseError();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001239 }
1240
1241 if (!status)
1242 {
1243 phosphor::logging::log<phosphor::logging::level::ERR>(
1244 "Sync data with service failure");
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001245 return ipmi::responseUnspecifiedError();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001246 }
1247
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001248 return ipmi::responseSuccess();
Vernon Mauerya3702c12019-05-22 13:20:59 -07001249}
1250
1251static void register_netfn_smbiosmdrv2_functions(void)
1252{
1253 // MDR V2 Command
1254 // <Get MDRII Status Command>
jayaprakash Mutyala853d8292019-05-31 18:17:42 +00001255 ipmi::registerHandler(ipmi::prioOemBase, NETFUN_INTEL_APP_OEM,
1256 IPMI_NETFN_INTEL_OEM_APP_CMD::MDRII_AGENT_STATUS,
1257 ipmi::Privilege::Operator, mdr2AgentStatus);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001258
1259 // <Get MDRII Directory Command>
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +00001260 ipmi::registerHandler(ipmi::prioOemBase, NETFUN_INTEL_APP_OEM,
1261 IPMI_NETFN_INTEL_OEM_APP_CMD::MDRII_GET_DIR,
1262 ipmi::Privilege::Operator, mdr2GetDir);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001263
1264 // <Send MDRII Directory Command>
jayaprakash Mutyala7cb59cc2019-06-19 19:17:43 +00001265 ipmi::registerHandler(ipmi::prioOemBase, NETFUN_INTEL_APP_OEM,
1266 IPMI_NETFN_INTEL_OEM_APP_CMD::MDRII_SEND_DIR,
1267 ipmi::Privilege::Operator, mdr2SendDir);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001268
1269 // <Get MDRII Data Info Command>
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +00001270 ipmi::registerHandler(ipmi::prioOemBase, NETFUN_INTEL_APP_OEM,
1271 IPMI_NETFN_INTEL_OEM_APP_CMD::MDRII_GET_DATA_INFO,
1272 ipmi::Privilege::Operator, mdr2GetDataInfo);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001273
1274 // <Send MDRII Info Offer>
jayaprakash Mutyala853d8292019-05-31 18:17:42 +00001275 ipmi::registerHandler(
1276 ipmi::prioOemBase, NETFUN_INTEL_APP_OEM,
1277 IPMI_NETFN_INTEL_OEM_APP_CMD::MDRII_SEND_DATA_INFO_OFFER,
1278 ipmi::Privilege::Operator, mdr2DataInfoOffer);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001279
1280 // <Send MDRII Data Info>
jayaprakash Mutyalaf5d49d62019-06-18 12:28:01 +00001281 ipmi::registerHandler(ipmi::prioOemBase, NETFUN_INTEL_APP_OEM,
1282 IPMI_NETFN_INTEL_OEM_APP_CMD::MDRII_SEND_DATA_INFO,
1283 ipmi::Privilege::Operator, mdr2SendDataInfo);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001284
1285 // <Get MDRII Data Block Command>
Deepak Kumar Sahuf4f5c162019-06-11 17:45:05 +00001286 ipmi::registerHandler(ipmi::prioOemBase, NETFUN_INTEL_APP_OEM,
1287 IPMI_NETFN_INTEL_OEM_APP_CMD::MDRII_GET_DATA_BLOCK,
1288 ipmi::Privilege::Operator, mdr2GetDataBlock);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001289
1290 // <Send MDRII Data Block>
jayaprakash Mutyala3104b3f2019-06-10 19:23:07 +00001291 ipmi::registerHandler(ipmi::prioOemBase, NETFUN_INTEL_APP_OEM,
1292 IPMI_NETFN_INTEL_OEM_APP_CMD::MDRII_SEND_DATA_BLOCK,
1293 ipmi::Privilege::Operator, mdr2SendDataBlock);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001294
1295 // <Lock MDRII Data Command>
jayaprakash Mutyala40fec612019-06-19 11:53:03 +00001296 ipmi::registerHandler(ipmi::prioOemBase, NETFUN_INTEL_APP_OEM,
1297 IPMI_NETFN_INTEL_OEM_APP_CMD::MDRII_LOCK_DATA,
1298 ipmi::Privilege::Operator, mdr2LockData);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001299
1300 // <Unlock MDRII Data Command>
jayaprakash Mutyaladad548b2019-06-12 15:29:39 +00001301 ipmi::registerHandler(ipmi::prioOemBase, NETFUN_INTEL_APP_OEM,
1302 IPMI_NETFN_INTEL_OEM_APP_CMD::MDRII_UNLOCK_DATA,
1303 ipmi::Privilege::Operator, mdr2UnlockData);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001304
1305 // <Send MDRII Data Start>
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001306 ipmi::registerHandler(ipmi::prioOemBase, NETFUN_INTEL_APP_OEM,
1307 IPMI_NETFN_INTEL_OEM_APP_CMD::MDRII_DATA_START,
1308 ipmi::Privilege::Operator, cmd_mdr2_data_start);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001309
1310 // <Send MDRII Data Done>
Deepak Kumar Sahu529d4152019-05-31 18:23:14 +00001311 ipmi::registerHandler(ipmi::prioOemBase, NETFUN_INTEL_APP_OEM,
1312 IPMI_NETFN_INTEL_OEM_APP_CMD::MDRII_DATA_DONE,
1313 ipmi::Privilege::Operator, cmd_mdr2_data_done);
Vernon Mauerya3702c12019-05-22 13:20:59 -07001314}