Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1 | /* |
| 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 Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 19 | #include <limits.h> |
| 20 | #include <sys/stat.h> |
| 21 | #include <sys/types.h> |
| 22 | #include <unistd.h> |
| 23 | |
| 24 | #include <commandutils.hpp> |
jayaprakash Mutyala | 853d829 | 2019-05-31 18:17:42 +0000 | [diff] [blame] | 25 | #include <ipmid/api.hpp> |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 26 | #include <ipmid/utils.hpp> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 27 | #include <oemcommands.hpp> |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 28 | #include <phosphor-logging/log.hpp> |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 29 | #include <sdbusplus/message/types.hpp> |
| 30 | #include <smbiosmdrv2handler.hpp> |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 31 | #include <xyz/openbmc_project/Common/error.hpp> |
| 32 | |
| 33 | #include <cstdint> |
| 34 | #include <fstream> |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 35 | #include <string> |
| 36 | #include <vector> |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 37 | |
| 38 | std::unique_ptr<MDRV2> mdrv2 = nullptr; |
jayaprakash Mutyala | 3104b3f | 2019-06-10 19:23:07 +0000 | [diff] [blame] | 39 | static constexpr const uint8_t ccOemInvalidChecksum = 0x85; |
jayaprakash Mutyala | 40fec61 | 2019-06-19 11:53:03 +0000 | [diff] [blame] | 40 | static constexpr size_t dataInfoSize = 16; |
jayaprakash Mutyala | 7cb59cc | 2019-06-19 19:17:43 +0000 | [diff] [blame] | 41 | static constexpr const uint8_t ccStorageLeak = 0xC4; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 42 | |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 43 | static void register_netfn_smbiosmdrv2_functions() __attribute__((constructor)); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 44 | |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 45 | int MDRV2::agentLookup(const uint16_t& agentId) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 46 | { |
| 47 | int agentIndex = -1; |
| 48 | |
| 49 | if (lastAgentId == agentId) |
| 50 | { |
| 51 | return lastAgentIndex; |
| 52 | } |
| 53 | |
| 54 | if (agentId == smbiosAgentId) |
| 55 | { |
| 56 | return firstAgentIndex; |
| 57 | } |
| 58 | |
| 59 | return agentIndex; |
| 60 | } |
| 61 | |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 62 | int MDRV2::sdplusMdrv2GetProperty(const std::string& name, |
Jason M. Bills | 0748c69 | 2022-09-08 15:34:08 -0700 | [diff] [blame] | 63 | ipmi::DbusVariant& value, |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 64 | const std::string& service) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 65 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 66 | std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus(); |
Patrick Williams | f944d2e | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 67 | sdbusplus::message_t method = |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 68 | bus->new_method_call(service.c_str(), mdrv2Path, dbusProperties, "Get"); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 69 | method.append(mdrv2Interface, name); |
| 70 | |
Patrick Williams | f944d2e | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 71 | sdbusplus::message_t reply = bus->call(method); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 72 | |
| 73 | try |
| 74 | { |
Patrick Williams | f944d2e | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 75 | sdbusplus::message_t reply = bus->call(method); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 76 | reply.read(value); |
| 77 | } |
Patrick Williams | bd51e6a | 2021-10-06 13:09:44 -0500 | [diff] [blame] | 78 | catch (const sdbusplus::exception_t& e) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 79 | { |
| 80 | phosphor::logging::log<phosphor::logging::level::ERR>( |
Vernon Mauery | c7d517e | 2019-06-18 14:27:00 -0700 | [diff] [blame] | 81 | "Error get property, sdbusplus call failed", |
| 82 | phosphor::logging::entry("ERROR=%s", e.what())); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 83 | return -1; |
| 84 | } |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | int MDRV2::syncDirCommonData(uint8_t idIndex, uint32_t size, |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 90 | const std::string& service) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 91 | { |
| 92 | std::vector<uint32_t> commonData; |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 93 | std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus(); |
Patrick Williams | f944d2e | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 94 | sdbusplus::message_t method = |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 95 | bus->new_method_call(service.c_str(), mdrv2Path, mdrv2Interface, |
| 96 | "SynchronizeDirectoryCommonData"); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 97 | method.append(idIndex, size); |
| 98 | |
| 99 | try |
| 100 | { |
Patrick Williams | f944d2e | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 101 | sdbusplus::message_t reply = bus->call(method); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 102 | reply.read(commonData); |
| 103 | } |
Patrick Williams | bd51e6a | 2021-10-06 13:09:44 -0500 | [diff] [blame] | 104 | catch (const sdbusplus::exception_t& e) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 105 | { |
| 106 | phosphor::logging::log<phosphor::logging::level::ERR>( |
Vernon Mauery | c7d517e | 2019-06-18 14:27:00 -0700 | [diff] [blame] | 107 | "Error sync dir common data with service", |
| 108 | phosphor::logging::entry("ERROR=%s", e.what())); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 109 | return -1; |
| 110 | } |
| 111 | |
| 112 | if (commonData.size() < syncDirCommonSize) |
| 113 | { |
| 114 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 115 | "Error sync dir common data - data length invalid"); |
| 116 | return -1; |
| 117 | } |
| 118 | smbiosDir.dir[idIndex].common.dataSetSize = commonData.at(0); |
| 119 | smbiosDir.dir[idIndex].common.dataVersion = commonData.at(1); |
| 120 | smbiosDir.dir[idIndex].common.timestamp = commonData.at(2); |
| 121 | |
| 122 | return 0; |
| 123 | } |
| 124 | |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 125 | int MDRV2::findDataId(const uint8_t* dataInfo, const size_t& len, |
| 126 | const std::string& service) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 127 | { |
| 128 | int idIndex = -1; |
| 129 | |
| 130 | if (dataInfo == nullptr) |
| 131 | { |
| 132 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 133 | "Error dataInfo, input is null point"); |
| 134 | return -1; |
| 135 | } |
| 136 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 137 | std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus(); |
Patrick Williams | f944d2e | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 138 | sdbusplus::message_t method = bus->new_method_call( |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 139 | service.c_str(), mdrv2Path, mdrv2Interface, "FindIdIndex"); |
| 140 | std::vector<uint8_t> info; |
| 141 | info.resize(len); |
| 142 | std::copy(dataInfo, dataInfo + len, info.data()); |
| 143 | method.append(info); |
| 144 | |
| 145 | try |
| 146 | { |
Patrick Williams | f944d2e | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 147 | sdbusplus::message_t reply = bus->call(method); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 148 | reply.read(idIndex); |
| 149 | } |
Patrick Williams | bd51e6a | 2021-10-06 13:09:44 -0500 | [diff] [blame] | 150 | catch (const sdbusplus::exception_t& e) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 151 | { |
| 152 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 153 | "Error find id index", |
Vernon Mauery | c7d517e | 2019-06-18 14:27:00 -0700 | [diff] [blame] | 154 | phosphor::logging::entry("ERROR=%s", e.what()), |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 155 | phosphor::logging::entry("SERVICE=%s", service.c_str()), |
| 156 | phosphor::logging::entry("PATH=%s", mdrv2Path)); |
| 157 | return -1; |
| 158 | } |
| 159 | |
| 160 | return idIndex; |
| 161 | } |
| 162 | |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 163 | uint16_t MDRV2::getSessionHandle(Mdr2DirStruct* dir) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 164 | { |
| 165 | if (dir == NULL) |
| 166 | { |
| 167 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 168 | "Empty dir point"); |
| 169 | return 0; |
| 170 | } |
| 171 | dir->sessionHandle++; |
| 172 | if (dir->sessionHandle == 0) |
| 173 | { |
| 174 | dir->sessionHandle = 1; |
| 175 | } |
| 176 | |
| 177 | return dir->sessionHandle; |
| 178 | } |
| 179 | |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 180 | int MDRV2::findLockHandle(const uint16_t& lockHandle) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 181 | { |
| 182 | int idIndex = -1; |
| 183 | |
| 184 | for (int index = 0; index < smbiosDir.dirEntries; index++) |
| 185 | { |
| 186 | if (lockHandle == smbiosDir.dir[index].lockHandle) |
| 187 | { |
| 188 | return index; |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | return idIndex; |
| 193 | } |
| 194 | |
| 195 | bool MDRV2::smbiosIsUpdating(uint8_t index) |
| 196 | { |
P Dheeraj Srujan Kumar | 9f8d027 | 2021-07-14 19:13:49 +0530 | [diff] [blame] | 197 | if (index >= maxDirEntries) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 198 | { |
| 199 | return false; |
| 200 | } |
| 201 | if (smbiosDir.dir[index].stage == MDR2SMBIOSStatusEnum::mdr2Updating) |
| 202 | { |
| 203 | return true; |
| 204 | } |
| 205 | |
| 206 | return false; |
| 207 | } |
| 208 | |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 209 | uint32_t MDRV2::calcChecksum32(uint8_t* buf, uint32_t len) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 210 | { |
| 211 | uint32_t sum = 0; |
| 212 | |
| 213 | if (buf == nullptr) |
| 214 | { |
| 215 | return invalidChecksum; |
| 216 | } |
| 217 | |
| 218 | for (uint32_t index = 0; index < len; index++) |
| 219 | { |
| 220 | sum += buf[index]; |
| 221 | } |
| 222 | |
| 223 | return sum; |
| 224 | } |
| 225 | |
jayaprakash Mutyala | 853d829 | 2019-05-31 18:17:42 +0000 | [diff] [blame] | 226 | /** @brief implements mdr2 agent status command |
| 227 | * @param agentId |
| 228 | * @param dirVersion |
| 229 | * |
| 230 | * @returns IPMI completion code plus response data |
| 231 | * - mdrVersion |
| 232 | * - agentVersion |
| 233 | * - dirVersion |
| 234 | * - dirEntries |
| 235 | * - dataRequest |
| 236 | */ |
| 237 | ipmi::RspType<uint8_t, uint8_t, uint8_t, uint8_t, uint8_t> |
| 238 | mdr2AgentStatus(uint16_t agentId, uint8_t dirVersion) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 239 | { |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 240 | if (mdrv2 == nullptr) |
| 241 | { |
| 242 | mdrv2 = std::make_unique<MDRV2>(); |
| 243 | } |
| 244 | |
jayaprakash Mutyala | 853d829 | 2019-05-31 18:17:42 +0000 | [diff] [blame] | 245 | int agentIndex = mdrv2->agentLookup(agentId); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 246 | if (agentIndex == -1) |
| 247 | { |
| 248 | phosphor::logging::log<phosphor::logging::level::ERR>( |
jayaprakash Mutyala | 853d829 | 2019-05-31 18:17:42 +0000 | [diff] [blame] | 249 | "Unknown agent id", phosphor::logging::entry("ID=%x", agentId)); |
| 250 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 251 | } |
| 252 | |
jayaprakash Mutyala | 853d829 | 2019-05-31 18:17:42 +0000 | [diff] [blame] | 253 | constexpr uint8_t mdrVersion = mdr2Version; |
| 254 | constexpr uint8_t agentVersion = smbiosAgentVersion; |
| 255 | uint8_t dirVersionResp = mdrv2->smbiosDir.dirVersion; |
| 256 | uint8_t dirEntries = mdrv2->smbiosDir.dirEntries; |
| 257 | uint8_t dataRequest; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 258 | |
jayaprakash Mutyala | 853d829 | 2019-05-31 18:17:42 +0000 | [diff] [blame] | 259 | if (mdrv2->smbiosDir.remoteDirVersion != dirVersion) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 260 | { |
jayaprakash Mutyala | 853d829 | 2019-05-31 18:17:42 +0000 | [diff] [blame] | 261 | mdrv2->smbiosDir.remoteDirVersion = dirVersion; |
| 262 | dataRequest = |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 263 | static_cast<uint8_t>(DirDataRequestEnum::dirDataRequested); |
| 264 | } |
| 265 | else |
| 266 | { |
jayaprakash Mutyala | 853d829 | 2019-05-31 18:17:42 +0000 | [diff] [blame] | 267 | dataRequest = |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 268 | static_cast<uint8_t>(DirDataRequestEnum::dirDataNotRequested); |
| 269 | } |
| 270 | |
jayaprakash Mutyala | 853d829 | 2019-05-31 18:17:42 +0000 | [diff] [blame] | 271 | return ipmi::responseSuccess(mdrVersion, agentVersion, dirVersionResp, |
| 272 | dirEntries, dataRequest); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 273 | } |
| 274 | |
jayaprakash Mutyala | dad548b | 2019-06-12 15:29:39 +0000 | [diff] [blame] | 275 | /** @brief implements mdr2 get directory command |
| 276 | * @param agentId |
| 277 | * @param dirIndex |
| 278 | * @returns IPMI completion code plus response data |
| 279 | * - dataOut |
| 280 | */ |
| 281 | ipmi::RspType<std::vector<uint8_t>> mdr2GetDir(uint16_t agentId, |
| 282 | uint8_t dirIndex) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 283 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 284 | std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus(); |
| 285 | std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 286 | |
| 287 | if (mdrv2 == nullptr) |
| 288 | { |
| 289 | mdrv2 = std::make_unique<MDRV2>(); |
| 290 | } |
| 291 | |
jayaprakash Mutyala | dad548b | 2019-06-12 15:29:39 +0000 | [diff] [blame] | 292 | int agentIndex = mdrv2->agentLookup(agentId); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 293 | if (agentIndex == -1) |
| 294 | { |
| 295 | phosphor::logging::log<phosphor::logging::level::ERR>( |
jayaprakash Mutyala | dad548b | 2019-06-12 15:29:39 +0000 | [diff] [blame] | 296 | "Unknown agent id", phosphor::logging::entry("ID=%x", agentId)); |
| 297 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 298 | } |
| 299 | |
Jason M. Bills | 0748c69 | 2022-09-08 15:34:08 -0700 | [diff] [blame] | 300 | ipmi::DbusVariant value = static_cast<uint8_t>(0); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 301 | if (0 != mdrv2->sdplusMdrv2GetProperty("DirectoryEntries", value, service)) |
| 302 | { |
| 303 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 304 | "Error getting DirEnries"); |
jayaprakash Mutyala | dad548b | 2019-06-12 15:29:39 +0000 | [diff] [blame] | 305 | return ipmi::responseUnspecifiedError(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 306 | } |
Prithvi A Pai | 0fac9bf | 2021-12-27 07:11:24 +0000 | [diff] [blame] | 307 | if (std::get<uint8_t>(value) == 0) |
| 308 | { |
| 309 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 310 | "Error getting directory entries", |
| 311 | phosphor::logging::entry("VALUE=%x", std::get<uint8_t>(value))); |
| 312 | return ipmi::responseUnspecifiedError(); |
| 313 | } |
jayaprakash Mutyala | dad548b | 2019-06-12 15:29:39 +0000 | [diff] [blame] | 314 | if (dirIndex > std::get<uint8_t>(value)) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 315 | { |
jayaprakash Mutyala | dad548b | 2019-06-12 15:29:39 +0000 | [diff] [blame] | 316 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Patrick Williams | f944d2e | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 319 | sdbusplus::message_t method = bus->new_method_call( |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 320 | service.c_str(), mdrv2Path, mdrv2Interface, "GetDirectoryInformation"); |
| 321 | |
jayaprakash Mutyala | dad548b | 2019-06-12 15:29:39 +0000 | [diff] [blame] | 322 | method.append(dirIndex); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 323 | |
jayaprakash Mutyala | dad548b | 2019-06-12 15:29:39 +0000 | [diff] [blame] | 324 | std::vector<uint8_t> dataOut; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 325 | try |
| 326 | { |
Patrick Williams | f944d2e | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 327 | sdbusplus::message_t reply = bus->call(method); |
jayaprakash Mutyala | dad548b | 2019-06-12 15:29:39 +0000 | [diff] [blame] | 328 | reply.read(dataOut); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 329 | } |
Patrick Williams | bd51e6a | 2021-10-06 13:09:44 -0500 | [diff] [blame] | 330 | catch (const sdbusplus::exception_t& e) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 331 | { |
| 332 | phosphor::logging::log<phosphor::logging::level::ERR>( |
Vernon Mauery | c7d517e | 2019-06-18 14:27:00 -0700 | [diff] [blame] | 333 | "Error get dir", phosphor::logging::entry("ERROR=%s", e.what()), |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 334 | phosphor::logging::entry("SERVICE=%s", service.c_str()), |
| 335 | phosphor::logging::entry("PATH=%s", mdrv2Path)); |
jayaprakash Mutyala | dad548b | 2019-06-12 15:29:39 +0000 | [diff] [blame] | 336 | return ipmi::responseResponseError(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 337 | } |
| 338 | |
jayaprakash Mutyala | dad548b | 2019-06-12 15:29:39 +0000 | [diff] [blame] | 339 | constexpr size_t getDirRespSize = 6; |
| 340 | if (dataOut.size() < getDirRespSize) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 341 | { |
| 342 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 343 | "Error get dir, response length invalid"); |
jayaprakash Mutyala | dad548b | 2019-06-12 15:29:39 +0000 | [diff] [blame] | 344 | return ipmi::responseUnspecifiedError(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 345 | } |
| 346 | |
jayaprakash Mutyala | dad548b | 2019-06-12 15:29:39 +0000 | [diff] [blame] | 347 | if (dataOut.size() > MAX_IPMI_BUFFER) // length + completion code should no |
| 348 | // more than MAX_IPMI_BUFFER |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 349 | { |
| 350 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 351 | "Data length send from service is invalid"); |
jayaprakash Mutyala | dad548b | 2019-06-12 15:29:39 +0000 | [diff] [blame] | 352 | return ipmi::responseResponseError(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 353 | } |
| 354 | |
jayaprakash Mutyala | dad548b | 2019-06-12 15:29:39 +0000 | [diff] [blame] | 355 | return ipmi::responseSuccess(dataOut); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Jayaprakash Mutyala | 5235ae9 | 2021-03-22 22:33:07 +0000 | [diff] [blame] | 358 | /** @brief implements mdr2 send directory info command |
| 359 | * @param agentId |
| 360 | * @param dirVersion |
| 361 | * @param dirIndex |
| 362 | * @param returnedEntries |
| 363 | * @param remainingEntries |
| 364 | * @param dataInfo |
| 365 | * dataInfo is 32 Bytes in size and contains below parameters |
| 366 | * - dataInfo, size, dataSetSize, dataVersion, timestamp |
| 367 | * |
| 368 | * @returns IPMI completion code plus response data |
| 369 | * - bool |
| 370 | */ |
| 371 | |
jayaprakash Mutyala | 7cb59cc | 2019-06-19 19:17:43 +0000 | [diff] [blame] | 372 | ipmi::RspType<bool> mdr2SendDir(uint16_t agentId, uint8_t dirVersion, |
| 373 | uint8_t dirIndex, uint8_t returnedEntries, |
| 374 | uint8_t remainingEntries, |
Jayaprakash Mutyala | 5235ae9 | 2021-03-22 22:33:07 +0000 | [diff] [blame] | 375 | std::vector<uint8_t> dataInfo) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 376 | { |
Jayaprakash Mutyala | 5235ae9 | 2021-03-22 22:33:07 +0000 | [diff] [blame] | 377 | if ((static_cast<size_t>(returnedEntries) * dataInfoSize) != |
| 378 | dataInfo.size()) |
| 379 | { |
| 380 | return ipmi::responseReqDataLenInvalid(); |
| 381 | } |
| 382 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 383 | std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus(); |
| 384 | std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 385 | |
| 386 | if (mdrv2 == nullptr) |
| 387 | { |
| 388 | mdrv2 = std::make_unique<MDRV2>(); |
| 389 | } |
| 390 | |
jayaprakash Mutyala | 7cb59cc | 2019-06-19 19:17:43 +0000 | [diff] [blame] | 391 | int agentIndex = mdrv2->agentLookup(agentId); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 392 | if (agentIndex == -1) |
| 393 | { |
| 394 | phosphor::logging::log<phosphor::logging::level::ERR>( |
jayaprakash Mutyala | 7cb59cc | 2019-06-19 19:17:43 +0000 | [diff] [blame] | 395 | "Unknown agent id", phosphor::logging::entry("ID=%x", agentId)); |
| 396 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 397 | } |
| 398 | |
jayaprakash Mutyala | 7cb59cc | 2019-06-19 19:17:43 +0000 | [diff] [blame] | 399 | if ((dirIndex + returnedEntries) > maxDirEntries) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 400 | { |
| 401 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 402 | "Too many directory entries"); |
jayaprakash Mutyala | 7cb59cc | 2019-06-19 19:17:43 +0000 | [diff] [blame] | 403 | return ipmi::response(ccStorageLeak); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Patrick Williams | f944d2e | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 406 | sdbusplus::message_t method = bus->new_method_call( |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 407 | service.c_str(), mdrv2Path, mdrv2Interface, "SendDirectoryInformation"); |
jayaprakash Mutyala | 7cb59cc | 2019-06-19 19:17:43 +0000 | [diff] [blame] | 408 | method.append(dirVersion, dirIndex, returnedEntries, remainingEntries, |
Jayaprakash Mutyala | 5235ae9 | 2021-03-22 22:33:07 +0000 | [diff] [blame] | 409 | dataInfo); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 410 | |
jayaprakash Mutyala | 7cb59cc | 2019-06-19 19:17:43 +0000 | [diff] [blame] | 411 | bool terminate = false; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 412 | try |
| 413 | { |
Patrick Williams | f944d2e | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 414 | sdbusplus::message_t reply = bus->call(method); |
jayaprakash Mutyala | 7cb59cc | 2019-06-19 19:17:43 +0000 | [diff] [blame] | 415 | reply.read(terminate); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 416 | } |
Patrick Williams | bd51e6a | 2021-10-06 13:09:44 -0500 | [diff] [blame] | 417 | catch (const sdbusplus::exception_t& e) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 418 | { |
| 419 | phosphor::logging::log<phosphor::logging::level::ERR>( |
Vernon Mauery | c7d517e | 2019-06-18 14:27:00 -0700 | [diff] [blame] | 420 | "Error send dir", phosphor::logging::entry("ERROR=%s", e.what()), |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 421 | phosphor::logging::entry("SERVICE=%s", service.c_str()), |
| 422 | phosphor::logging::entry("PATH=%s", mdrv2Path)); |
jayaprakash Mutyala | 7cb59cc | 2019-06-19 19:17:43 +0000 | [diff] [blame] | 423 | return ipmi::responseResponseError(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 424 | } |
| 425 | |
jayaprakash Mutyala | 7cb59cc | 2019-06-19 19:17:43 +0000 | [diff] [blame] | 426 | return ipmi::responseSuccess(terminate); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 427 | } |
| 428 | |
jayaprakash Mutyala | f5d49d6 | 2019-06-18 12:28:01 +0000 | [diff] [blame] | 429 | /** @brief implements mdr2 get data info command |
| 430 | * @param agentId |
| 431 | * @param dataInfo |
| 432 | * |
| 433 | * @returns IPMI completion code plus response data |
| 434 | * - response - mdrVersion, data info, validFlag, |
| 435 | * dataLength, dataVersion, timeStamp |
| 436 | */ |
| 437 | ipmi::RspType<std::vector<uint8_t>> |
| 438 | mdr2GetDataInfo(uint16_t agentId, std::vector<uint8_t> dataInfo) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 439 | { |
jayaprakash Mutyala | f5d49d6 | 2019-06-18 12:28:01 +0000 | [diff] [blame] | 440 | constexpr size_t getDataInfoReqSize = 16; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 441 | |
jayaprakash Mutyala | f5d49d6 | 2019-06-18 12:28:01 +0000 | [diff] [blame] | 442 | if (dataInfo.size() < getDataInfoReqSize) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 443 | { |
jayaprakash Mutyala | f5d49d6 | 2019-06-18 12:28:01 +0000 | [diff] [blame] | 444 | return ipmi::responseReqDataLenInvalid(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 445 | } |
| 446 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 447 | std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus(); |
| 448 | std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 449 | |
| 450 | if (mdrv2 == nullptr) |
| 451 | { |
| 452 | mdrv2 = std::make_unique<MDRV2>(); |
| 453 | } |
| 454 | |
jayaprakash Mutyala | f5d49d6 | 2019-06-18 12:28:01 +0000 | [diff] [blame] | 455 | int agentIndex = mdrv2->agentLookup(agentId); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 456 | if (agentIndex == -1) |
| 457 | { |
| 458 | phosphor::logging::log<phosphor::logging::level::ERR>( |
jayaprakash Mutyala | f5d49d6 | 2019-06-18 12:28:01 +0000 | [diff] [blame] | 459 | "Unknown agent id", phosphor::logging::entry("ID=%x", agentId)); |
| 460 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 461 | } |
| 462 | |
jayaprakash Mutyala | f5d49d6 | 2019-06-18 12:28:01 +0000 | [diff] [blame] | 463 | int idIndex = mdrv2->findDataId(dataInfo.data(), dataInfo.size(), service); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 464 | |
| 465 | if ((idIndex < 0) || (idIndex >= maxDirEntries)) |
| 466 | { |
| 467 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 468 | "Invalid Data ID", phosphor::logging::entry("IDINDEX=%x", idIndex)); |
jayaprakash Mutyala | f5d49d6 | 2019-06-18 12:28:01 +0000 | [diff] [blame] | 469 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 470 | } |
| 471 | |
Patrick Williams | f944d2e | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 472 | sdbusplus::message_t method = bus->new_method_call( |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 473 | service.c_str(), mdrv2Path, mdrv2Interface, "GetDataInformation"); |
| 474 | |
jayaprakash Mutyala | 04a38ed | 2020-05-29 01:42:26 +0000 | [diff] [blame] | 475 | method.append(static_cast<uint8_t>(idIndex)); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 476 | |
jayaprakash Mutyala | f5d49d6 | 2019-06-18 12:28:01 +0000 | [diff] [blame] | 477 | std::vector<uint8_t> res; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 478 | try |
| 479 | { |
Patrick Williams | f944d2e | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 480 | sdbusplus::message_t reply = bus->call(method); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 481 | reply.read(res); |
| 482 | } |
Patrick Williams | bd51e6a | 2021-10-06 13:09:44 -0500 | [diff] [blame] | 483 | catch (const sdbusplus::exception_t& e) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 484 | { |
| 485 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 486 | "Error get data info", |
Vernon Mauery | c7d517e | 2019-06-18 14:27:00 -0700 | [diff] [blame] | 487 | phosphor::logging::entry("ERROR=%s", e.what()), |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 488 | phosphor::logging::entry("SERVICE=%s", service.c_str()), |
| 489 | phosphor::logging::entry("PATH=%s", mdrv2Path)); |
jayaprakash Mutyala | f5d49d6 | 2019-06-18 12:28:01 +0000 | [diff] [blame] | 490 | return ipmi::responseResponseError(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | if (res.size() != sizeof(MDRiiGetDataInfoResponse)) |
| 494 | { |
| 495 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 496 | "Get data info response length not invalid"); |
jayaprakash Mutyala | f5d49d6 | 2019-06-18 12:28:01 +0000 | [diff] [blame] | 497 | return ipmi::responseResponseError(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 498 | } |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 499 | |
jayaprakash Mutyala | f5d49d6 | 2019-06-18 12:28:01 +0000 | [diff] [blame] | 500 | return ipmi::responseSuccess(res); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 501 | } |
| 502 | |
jayaprakash Mutyala | 853d829 | 2019-05-31 18:17:42 +0000 | [diff] [blame] | 503 | /** @brief implements mdr2 data info offer command |
| 504 | * @param agentId - Offer a agent ID to get the "Data Set ID" |
| 505 | * |
| 506 | * @returns IPMI completion code plus response data |
jayaprakash Mutyala | 3104b3f | 2019-06-10 19:23:07 +0000 | [diff] [blame] | 507 | * - dataOut - data Set Id |
jayaprakash Mutyala | 853d829 | 2019-05-31 18:17:42 +0000 | [diff] [blame] | 508 | */ |
| 509 | ipmi::RspType<std::vector<uint8_t>> mdr2DataInfoOffer(uint16_t agentId) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 510 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 511 | std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus(); |
| 512 | std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 513 | |
| 514 | if (mdrv2 == nullptr) |
| 515 | { |
| 516 | mdrv2 = std::make_unique<MDRV2>(); |
| 517 | } |
| 518 | |
jayaprakash Mutyala | 853d829 | 2019-05-31 18:17:42 +0000 | [diff] [blame] | 519 | int agentIndex = mdrv2->agentLookup(agentId); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 520 | if (agentIndex == -1) |
| 521 | { |
| 522 | phosphor::logging::log<phosphor::logging::level::ERR>( |
jayaprakash Mutyala | 853d829 | 2019-05-31 18:17:42 +0000 | [diff] [blame] | 523 | "Unknown agent id", phosphor::logging::entry("ID=%x", agentId)); |
| 524 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 525 | } |
| 526 | |
Patrick Williams | f944d2e | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 527 | sdbusplus::message_t method = bus->new_method_call( |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 528 | service.c_str(), mdrv2Path, mdrv2Interface, "GetDataOffer"); |
| 529 | |
jayaprakash Mutyala | 3104b3f | 2019-06-10 19:23:07 +0000 | [diff] [blame] | 530 | std::vector<uint8_t> dataOut; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 531 | try |
| 532 | { |
Patrick Williams | f944d2e | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 533 | sdbusplus::message_t reply = bus->call(method); |
jayaprakash Mutyala | 3104b3f | 2019-06-10 19:23:07 +0000 | [diff] [blame] | 534 | reply.read(dataOut); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 535 | } |
Patrick Williams | bd51e6a | 2021-10-06 13:09:44 -0500 | [diff] [blame] | 536 | catch (const sdbusplus::exception_t& e) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 537 | { |
| 538 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 539 | "Error send data info offer", |
Vernon Mauery | c7d517e | 2019-06-18 14:27:00 -0700 | [diff] [blame] | 540 | phosphor::logging::entry("ERROR=%s", e.what()), |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 541 | phosphor::logging::entry("SERVICE=%s", service.c_str()), |
| 542 | phosphor::logging::entry("PATH=%s", mdrv2Path)); |
jayaprakash Mutyala | 853d829 | 2019-05-31 18:17:42 +0000 | [diff] [blame] | 543 | return ipmi::responseResponseError(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 544 | } |
| 545 | |
jayaprakash Mutyala | 3104b3f | 2019-06-10 19:23:07 +0000 | [diff] [blame] | 546 | constexpr size_t respInfoSize = 16; |
| 547 | if (dataOut.size() != respInfoSize) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 548 | { |
| 549 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 550 | "Error send data info offer, return length invalid"); |
jayaprakash Mutyala | 853d829 | 2019-05-31 18:17:42 +0000 | [diff] [blame] | 551 | return ipmi::responseUnspecifiedError(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 552 | } |
| 553 | |
jayaprakash Mutyala | 3104b3f | 2019-06-10 19:23:07 +0000 | [diff] [blame] | 554 | return ipmi::responseSuccess(dataOut); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 555 | } |
| 556 | |
jayaprakash Mutyala | f5d49d6 | 2019-06-18 12:28:01 +0000 | [diff] [blame] | 557 | /** @brief implements mdr2 send data info command |
| 558 | * @param agentId |
| 559 | * @param dataInfo |
| 560 | * @param validFlag |
| 561 | * @param dataLength |
| 562 | * @param dataVersion |
| 563 | * @param timeStamp |
| 564 | * |
| 565 | * @returns IPMI completion code plus response data |
| 566 | * - bool |
| 567 | */ |
| 568 | ipmi::RspType<bool> mdr2SendDataInfo(uint16_t agentId, |
| 569 | std::array<uint8_t, dataInfoSize> dataInfo, |
| 570 | uint8_t validFlag, uint32_t dataLength, |
| 571 | uint32_t dataVersion, uint32_t timeStamp) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 572 | { |
jayaprakash Mutyala | f5d49d6 | 2019-06-18 12:28:01 +0000 | [diff] [blame] | 573 | if (dataLength > smbiosTableStorageSize) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 574 | { |
| 575 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 576 | "Requested data length is out of SMBIOS Table storage size."); |
jayaprakash Mutyala | f5d49d6 | 2019-06-18 12:28:01 +0000 | [diff] [blame] | 577 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 578 | } |
| 579 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 580 | std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus(); |
| 581 | std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 582 | |
| 583 | if (mdrv2 == nullptr) |
| 584 | { |
| 585 | mdrv2 = std::make_unique<MDRV2>(); |
| 586 | } |
| 587 | |
jayaprakash Mutyala | f5d49d6 | 2019-06-18 12:28:01 +0000 | [diff] [blame] | 588 | int agentIndex = mdrv2->agentLookup(agentId); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 589 | if (agentIndex == -1) |
| 590 | { |
| 591 | phosphor::logging::log<phosphor::logging::level::ERR>( |
jayaprakash Mutyala | f5d49d6 | 2019-06-18 12:28:01 +0000 | [diff] [blame] | 592 | "Unknown agent id", phosphor::logging::entry("ID=%x", agentId)); |
| 593 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 594 | } |
| 595 | |
Patrick Venture | 6d76560 | 2019-09-25 17:11:07 -0700 | [diff] [blame] | 596 | int idIndex = mdrv2->findDataId(dataInfo.data(), dataInfo.size(), service); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 597 | |
| 598 | if ((idIndex < 0) || (idIndex >= maxDirEntries)) |
| 599 | { |
| 600 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 601 | "Invalid Data ID", phosphor::logging::entry("IDINDEX=%x", idIndex)); |
jayaprakash Mutyala | f5d49d6 | 2019-06-18 12:28:01 +0000 | [diff] [blame] | 602 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 603 | } |
| 604 | |
Patrick Williams | f944d2e | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 605 | sdbusplus::message_t method = bus->new_method_call( |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 606 | service.c_str(), mdrv2Path, mdrv2Interface, "SendDataInformation"); |
| 607 | |
jayaprakash Mutyala | f5d49d6 | 2019-06-18 12:28:01 +0000 | [diff] [blame] | 608 | method.append((uint8_t)idIndex, validFlag, dataLength, dataVersion, |
| 609 | timeStamp); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 610 | |
jayaprakash Mutyala | f5d49d6 | 2019-06-18 12:28:01 +0000 | [diff] [blame] | 611 | bool entryChanged = true; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 612 | try |
| 613 | { |
Patrick Williams | f944d2e | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 614 | sdbusplus::message_t reply = bus->call(method); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 615 | reply.read(entryChanged); |
| 616 | } |
Patrick Williams | bd51e6a | 2021-10-06 13:09:44 -0500 | [diff] [blame] | 617 | catch (const sdbusplus::exception_t& e) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 618 | { |
| 619 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 620 | "Error send data info", |
Vernon Mauery | c7d517e | 2019-06-18 14:27:00 -0700 | [diff] [blame] | 621 | phosphor::logging::entry("ERROR=%s", e.what()), |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 622 | phosphor::logging::entry("SERVICE=%s", service.c_str()), |
| 623 | phosphor::logging::entry("PATH=%s", mdrv2Path)); |
jayaprakash Mutyala | f5d49d6 | 2019-06-18 12:28:01 +0000 | [diff] [blame] | 624 | return ipmi::responseResponseError(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 625 | } |
| 626 | |
jayaprakash Mutyala | f5d49d6 | 2019-06-18 12:28:01 +0000 | [diff] [blame] | 627 | return ipmi::responseSuccess(entryChanged); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 628 | } |
| 629 | |
Deepak Kumar Sahu | f4f5c16 | 2019-06-11 17:45:05 +0000 | [diff] [blame] | 630 | /** |
| 631 | @brief This command is MDR related get data block command. |
| 632 | |
| 633 | @param - agentId |
| 634 | @param - lockHandle |
| 635 | @param - xferOffset |
| 636 | @param - xferLength |
| 637 | |
| 638 | @return on success |
| 639 | - xferLength |
| 640 | - checksum |
| 641 | - data |
| 642 | **/ |
| 643 | ipmi::RspType<uint32_t, // xferLength |
| 644 | uint32_t, // Checksum |
| 645 | std::vector<uint8_t> // data |
| 646 | > |
| 647 | mdr2GetDataBlock(uint16_t agentId, uint16_t lockHandle, uint32_t xferOffset, |
| 648 | uint32_t xferLength) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 649 | { |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 650 | if (mdrv2 == nullptr) |
| 651 | { |
| 652 | mdrv2 = std::make_unique<MDRV2>(); |
| 653 | } |
| 654 | |
Deepak Kumar Sahu | f4f5c16 | 2019-06-11 17:45:05 +0000 | [diff] [blame] | 655 | int agentIndex = mdrv2->agentLookup(agentId); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 656 | if (agentIndex == -1) |
| 657 | { |
| 658 | phosphor::logging::log<phosphor::logging::level::ERR>( |
Deepak Kumar Sahu | f4f5c16 | 2019-06-11 17:45:05 +0000 | [diff] [blame] | 659 | "Unknown agent id", phosphor::logging::entry("ID=%x", agentId)); |
| 660 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 661 | } |
| 662 | |
Deepak Kumar Sahu | f4f5c16 | 2019-06-11 17:45:05 +0000 | [diff] [blame] | 663 | int idIndex = mdrv2->findLockHandle(lockHandle); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 664 | |
| 665 | if ((idIndex < 0) || (idIndex >= maxDirEntries)) |
| 666 | { |
| 667 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 668 | "Invalid Data ID", phosphor::logging::entry("IDINDEX=%x", idIndex)); |
Deepak Kumar Sahu | f4f5c16 | 2019-06-11 17:45:05 +0000 | [diff] [blame] | 669 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 670 | } |
| 671 | |
Deepak Kumar Sahu | f4f5c16 | 2019-06-11 17:45:05 +0000 | [diff] [blame] | 672 | if (xferOffset >= mdrv2->smbiosDir.dir[idIndex].common.size) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 673 | { |
| 674 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 675 | "Offset is outside of range."); |
Deepak Kumar Sahu | f4f5c16 | 2019-06-11 17:45:05 +0000 | [diff] [blame] | 676 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 677 | } |
| 678 | |
Deepak Kumar Sahu | f4f5c16 | 2019-06-11 17:45:05 +0000 | [diff] [blame] | 679 | size_t outSize = (xferLength > mdrv2->smbiosDir.dir[idIndex].xferSize) |
| 680 | ? mdrv2->smbiosDir.dir[idIndex].xferSize |
| 681 | : xferLength; |
| 682 | if (outSize > UINT_MAX - xferOffset) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 683 | { |
| 684 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 685 | "Out size and offset are out of range"); |
Deepak Kumar Sahu | f4f5c16 | 2019-06-11 17:45:05 +0000 | [diff] [blame] | 686 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 687 | } |
Deepak Kumar Sahu | f4f5c16 | 2019-06-11 17:45:05 +0000 | [diff] [blame] | 688 | if ((xferOffset + outSize) > mdrv2->smbiosDir.dir[idIndex].common.size) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 689 | { |
Deepak Kumar Sahu | f4f5c16 | 2019-06-11 17:45:05 +0000 | [diff] [blame] | 690 | outSize = mdrv2->smbiosDir.dir[idIndex].common.size - xferOffset; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 691 | } |
| 692 | |
Deepak Kumar Sahu | f4f5c16 | 2019-06-11 17:45:05 +0000 | [diff] [blame] | 693 | uint32_t respXferLength = outSize; |
| 694 | |
| 695 | if (respXferLength > xferLength) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 696 | { |
| 697 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 698 | "Get data block unexpected error."); |
Deepak Kumar Sahu | f4f5c16 | 2019-06-11 17:45:05 +0000 | [diff] [blame] | 699 | return ipmi::responseUnspecifiedError(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 700 | } |
| 701 | |
Deepak Kumar Sahu | f4f5c16 | 2019-06-11 17:45:05 +0000 | [diff] [blame] | 702 | if ((xferOffset + outSize) > |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 703 | UINT_MAX - |
| 704 | reinterpret_cast<size_t>(mdrv2->smbiosDir.dir[idIndex].dataStorage)) |
| 705 | { |
| 706 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 707 | "Input data to calculate checksum is out of range"); |
Deepak Kumar Sahu | f4f5c16 | 2019-06-11 17:45:05 +0000 | [diff] [blame] | 708 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | uint32_t u32Checksum = mdrv2->calcChecksum32( |
Deepak Kumar Sahu | f4f5c16 | 2019-06-11 17:45:05 +0000 | [diff] [blame] | 712 | mdrv2->smbiosDir.dir[idIndex].dataStorage + xferOffset, outSize); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 713 | if (u32Checksum == invalidChecksum) |
| 714 | { |
| 715 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 716 | "Get data block failed - invalid checksum"); |
Deepak Kumar Sahu | f4f5c16 | 2019-06-11 17:45:05 +0000 | [diff] [blame] | 717 | return ipmi::response(ccOemInvalidChecksum); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 718 | } |
Deepak Kumar Sahu | f4f5c16 | 2019-06-11 17:45:05 +0000 | [diff] [blame] | 719 | std::vector<uint8_t> data(outSize); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 720 | |
Deepak Kumar Sahu | f4f5c16 | 2019-06-11 17:45:05 +0000 | [diff] [blame] | 721 | std::copy(&mdrv2->smbiosDir.dir[idIndex].dataStorage[xferOffset], |
| 722 | &mdrv2->smbiosDir.dir[idIndex].dataStorage[xferOffset + outSize], |
| 723 | data.begin()); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 724 | |
Deepak Kumar Sahu | f4f5c16 | 2019-06-11 17:45:05 +0000 | [diff] [blame] | 725 | return ipmi::responseSuccess(respXferLength, u32Checksum, data); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 726 | } |
| 727 | |
jayaprakash Mutyala | 3104b3f | 2019-06-10 19:23:07 +0000 | [diff] [blame] | 728 | /** @brief implements mdr2 send data block command |
| 729 | * @param agentId |
| 730 | * @param lockHandle |
| 731 | * @param xferOffset |
| 732 | * @param xferLength |
| 733 | * @param checksum |
| 734 | * |
| 735 | * @returns IPMI completion code |
| 736 | */ |
| 737 | ipmi::RspType<> mdr2SendDataBlock(uint16_t agentId, uint16_t lockHandle, |
| 738 | uint32_t xferOffset, uint32_t xferLength, |
| 739 | uint32_t checksum) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 740 | { |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 741 | if (mdrv2 == nullptr) |
| 742 | { |
| 743 | mdrv2 = std::make_unique<MDRV2>(); |
| 744 | } |
| 745 | |
jayaprakash Mutyala | 3104b3f | 2019-06-10 19:23:07 +0000 | [diff] [blame] | 746 | int agentIndex = mdrv2->agentLookup(agentId); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 747 | if (agentIndex == -1) |
| 748 | { |
| 749 | phosphor::logging::log<phosphor::logging::level::ERR>( |
jayaprakash Mutyala | 3104b3f | 2019-06-10 19:23:07 +0000 | [diff] [blame] | 750 | "Unknown agent id", phosphor::logging::entry("ID=%x", agentId)); |
| 751 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 752 | } |
| 753 | |
jayaprakash Mutyala | 3104b3f | 2019-06-10 19:23:07 +0000 | [diff] [blame] | 754 | int idIndex = mdrv2->findLockHandle(lockHandle); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 755 | |
| 756 | if ((idIndex < 0) || (idIndex >= maxDirEntries)) |
| 757 | { |
| 758 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 759 | "Invalid Data ID", phosphor::logging::entry("IDINDEX=%x", idIndex)); |
jayaprakash Mutyala | 3104b3f | 2019-06-10 19:23:07 +0000 | [diff] [blame] | 760 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | if (mdrv2->smbiosIsUpdating(idIndex)) |
| 764 | { |
jayaprakash Mutyala | 3104b3f | 2019-06-10 19:23:07 +0000 | [diff] [blame] | 765 | if (xferOffset > UINT_MAX - xferLength) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 766 | { |
| 767 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 768 | "Offset and length are out of range"); |
jayaprakash Mutyala | 3104b3f | 2019-06-10 19:23:07 +0000 | [diff] [blame] | 769 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 770 | } |
jayaprakash Mutyala | 3104b3f | 2019-06-10 19:23:07 +0000 | [diff] [blame] | 771 | if (((xferOffset + xferLength) > |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 772 | mdrv2->smbiosDir.dir[idIndex].maxDataSize) || |
jayaprakash Mutyala | 3104b3f | 2019-06-10 19:23:07 +0000 | [diff] [blame] | 773 | ((xferOffset + xferLength) > |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 774 | mdrv2->smbiosDir.dir[idIndex].common.dataSetSize)) |
| 775 | { |
| 776 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 777 | "Send data block Invalid offset/length"); |
jayaprakash Mutyala | 3104b3f | 2019-06-10 19:23:07 +0000 | [diff] [blame] | 778 | return ipmi::responseReqDataLenExceeded(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 779 | } |
| 780 | if (reinterpret_cast<size_t>( |
| 781 | mdrv2->smbiosDir.dir[idIndex].dataStorage) > |
jayaprakash Mutyala | 3104b3f | 2019-06-10 19:23:07 +0000 | [diff] [blame] | 782 | UINT_MAX - xferOffset) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 783 | { |
| 784 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 785 | "Offset is out of range"); |
jayaprakash Mutyala | 3104b3f | 2019-06-10 19:23:07 +0000 | [diff] [blame] | 786 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 787 | } |
Patrick Williams | b37abfb | 2023-05-10 07:50:33 -0500 | [diff] [blame] | 788 | uint8_t* destAddr = mdrv2->smbiosDir.dir[idIndex].dataStorage + |
| 789 | xferOffset; |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 790 | uint8_t* sourceAddr = reinterpret_cast<uint8_t*>(mdrv2->area->vPtr); |
jayaprakash Mutyala | 3104b3f | 2019-06-10 19:23:07 +0000 | [diff] [blame] | 791 | uint32_t calcChecksum = mdrv2->calcChecksum32(sourceAddr, xferLength); |
| 792 | if (calcChecksum != checksum) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 793 | { |
| 794 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 795 | "Send data block Invalid checksum"); |
jayaprakash Mutyala | 3104b3f | 2019-06-10 19:23:07 +0000 | [diff] [blame] | 796 | return ipmi::response(ccOemInvalidChecksum); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 797 | } |
| 798 | else |
| 799 | { |
jayaprakash Mutyala | 3104b3f | 2019-06-10 19:23:07 +0000 | [diff] [blame] | 800 | if (reinterpret_cast<size_t>(sourceAddr) > UINT_MAX - xferLength) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 801 | { |
| 802 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 803 | "Length is out of range"); |
jayaprakash Mutyala | 3104b3f | 2019-06-10 19:23:07 +0000 | [diff] [blame] | 804 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 805 | } |
jayaprakash Mutyala | 3104b3f | 2019-06-10 19:23:07 +0000 | [diff] [blame] | 806 | std::copy(sourceAddr, sourceAddr + xferLength, destAddr); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 807 | } |
| 808 | } |
| 809 | else |
| 810 | { |
| 811 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 812 | "Send data block failed, other data is updating"); |
jayaprakash Mutyala | 3104b3f | 2019-06-10 19:23:07 +0000 | [diff] [blame] | 813 | return ipmi::responseDestinationUnavailable(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 814 | } |
| 815 | |
jayaprakash Mutyala | 3104b3f | 2019-06-10 19:23:07 +0000 | [diff] [blame] | 816 | return ipmi::responseSuccess(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 817 | } |
| 818 | |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 819 | bool MDRV2::storeDatatoFlash(MDRSMBIOSHeader* mdrHdr, uint8_t* data) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 820 | { |
| 821 | std::ofstream smbiosFile(mdrType2File, |
| 822 | std::ios_base::binary | std::ios_base::trunc); |
| 823 | if (!smbiosFile.good()) |
| 824 | { |
| 825 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 826 | "Write data from flash error - Open MDRV2 table file failure"); |
| 827 | return false; |
| 828 | } |
| 829 | |
| 830 | try |
| 831 | { |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 832 | smbiosFile.write(reinterpret_cast<char*>(mdrHdr), |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 833 | sizeof(MDRSMBIOSHeader)); |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 834 | smbiosFile.write(reinterpret_cast<char*>(data), mdrHdr->dataSize); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 835 | } |
Patrick Williams | bd51e6a | 2021-10-06 13:09:44 -0500 | [diff] [blame] | 836 | catch (const std::ofstream::failure& e) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 837 | { |
| 838 | phosphor::logging::log<phosphor::logging::level::ERR>( |
Vernon Mauery | c7d517e | 2019-06-18 14:27:00 -0700 | [diff] [blame] | 839 | "Write data from flash error - write data error", |
| 840 | phosphor::logging::entry("ERROR=%s", e.what())); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 841 | return false; |
| 842 | } |
| 843 | |
| 844 | return true; |
| 845 | } |
| 846 | |
| 847 | void SharedMemoryArea::Initialize(uint32_t addr, uint32_t areaSize) |
| 848 | { |
| 849 | int memDriver = 0; |
| 850 | |
| 851 | // open mem driver for the system memory access |
| 852 | memDriver = open("/dev/vgasharedmem", O_RDONLY); |
| 853 | if (memDriver < 0) |
| 854 | { |
| 855 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 856 | "Cannot access mem driver"); |
| 857 | throw std::system_error(EIO, std::generic_category()); |
| 858 | } |
| 859 | |
| 860 | // map the system memory |
| 861 | vPtr = mmap(NULL, // where to map to: don't mind |
| 862 | areaSize, // how many bytes ? |
| 863 | PROT_READ, // want to read and write |
| 864 | MAP_SHARED, // no copy on write |
| 865 | memDriver, // handle to /dev/mem |
| 866 | (physicalAddr & pageMask)); // hopefully the Text-buffer :-) |
| 867 | |
| 868 | close(memDriver); |
| 869 | if (vPtr == MAP_FAILED) |
| 870 | { |
| 871 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 872 | "Failed to map share memory"); |
| 873 | throw std::system_error(EIO, std::generic_category()); |
| 874 | } |
| 875 | size = areaSize; |
| 876 | physicalAddr = addr; |
| 877 | } |
| 878 | |
| 879 | bool MDRV2::smbiosUnlock(uint8_t index) |
| 880 | { |
P Dheeraj Srujan Kumar | 36ed8d2 | 2021-08-04 01:14:14 +0530 | [diff] [blame] | 881 | bool ret = false; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 882 | switch (smbiosDir.dir[index].stage) |
| 883 | { |
| 884 | case MDR2SMBIOSStatusEnum::mdr2Updating: |
| 885 | smbiosDir.dir[index].stage = MDR2SMBIOSStatusEnum::mdr2Updated; |
| 886 | smbiosDir.dir[index].lock = MDR2DirLockEnum::mdr2DirUnlock; |
| 887 | |
| 888 | timer->stop(); |
| 889 | smbiosDir.dir[index].lockHandle = 0; |
| 890 | ret = true; |
| 891 | break; |
| 892 | |
| 893 | case MDR2SMBIOSStatusEnum::mdr2Updated: |
| 894 | case MDR2SMBIOSStatusEnum::mdr2Loaded: |
| 895 | smbiosDir.dir[index].lock = MDR2DirLockEnum::mdr2DirUnlock; |
| 896 | |
| 897 | timer->stop(); |
| 898 | |
| 899 | smbiosDir.dir[index].lockHandle = 0; |
| 900 | ret = true; |
| 901 | break; |
| 902 | |
| 903 | default: |
| 904 | break; |
| 905 | } |
| 906 | |
| 907 | return ret; |
| 908 | } |
| 909 | |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 910 | bool MDRV2::smbiosTryLock(uint8_t flag, uint8_t index, uint16_t* session, |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 911 | uint16_t timeout) |
| 912 | { |
| 913 | bool ret = false; |
| 914 | uint32_t u32Status = 0; |
| 915 | |
| 916 | if (timeout == 0) |
| 917 | { |
| 918 | timeout = defaultTimeout; |
| 919 | } |
| 920 | std::chrono::microseconds usec(timeout * sysClock); |
| 921 | |
| 922 | switch (smbiosDir.dir[index].stage) |
| 923 | { |
| 924 | case MDR2SMBIOSStatusEnum::mdr2Updating: |
| 925 | if (smbiosDir.dir[index].lock != MDR2DirLockEnum::mdr2DirLock) |
| 926 | { |
| 927 | smbiosDir.dir[index].lock = MDR2DirLockEnum::mdr2DirLock; |
| 928 | timer->start(usec); |
| 929 | lockIndex = index; |
| 930 | |
| 931 | *session = getSessionHandle(&smbiosDir); |
| 932 | smbiosDir.dir[index].lockHandle = *session; |
| 933 | ret = true; |
| 934 | } |
| 935 | break; |
| 936 | case MDR2SMBIOSStatusEnum::mdr2Init: |
| 937 | if (flag) |
| 938 | { |
| 939 | smbiosDir.dir[index].stage = MDR2SMBIOSStatusEnum::mdr2Updating; |
| 940 | smbiosDir.dir[index].lock = MDR2DirLockEnum::mdr2DirUnlock; |
| 941 | timer->start(usec); |
| 942 | lockIndex = index; |
| 943 | |
| 944 | *session = getSessionHandle(&smbiosDir); |
| 945 | smbiosDir.dir[index].lockHandle = *session; |
| 946 | ret = true; |
| 947 | } |
| 948 | break; |
| 949 | |
| 950 | case MDR2SMBIOSStatusEnum::mdr2Updated: |
| 951 | case MDR2SMBIOSStatusEnum::mdr2Loaded: |
| 952 | if (smbiosDir.dir[index].lock != MDR2DirLockEnum::mdr2DirLock) |
| 953 | { |
| 954 | if (flag) |
| 955 | { |
| 956 | smbiosDir.dir[index].stage = |
| 957 | MDR2SMBIOSStatusEnum::mdr2Updating; |
| 958 | smbiosDir.dir[index].lock = MDR2DirLockEnum::mdr2DirUnlock; |
| 959 | } |
| 960 | else |
| 961 | { |
| 962 | smbiosDir.dir[index].lock = MDR2DirLockEnum::mdr2DirLock; |
| 963 | } |
| 964 | |
| 965 | timer->start(usec); |
| 966 | lockIndex = index; |
| 967 | |
| 968 | *session = getSessionHandle(&smbiosDir); |
| 969 | smbiosDir.dir[index].lockHandle = *session; |
| 970 | ret = true; |
| 971 | } |
| 972 | break; |
| 973 | |
| 974 | default: |
| 975 | break; |
| 976 | } |
| 977 | return ret; |
| 978 | } |
| 979 | |
| 980 | void MDRV2::timeoutHandler() |
| 981 | { |
| 982 | smbiosUnlock(lockIndex); |
| 983 | mdrv2->area.reset(nullptr); |
| 984 | } |
| 985 | |
jayaprakash Mutyala | 40fec61 | 2019-06-19 11:53:03 +0000 | [diff] [blame] | 986 | /** @brief implements mdr2 lock data command |
| 987 | * @param agentId |
| 988 | * @param dataInfo |
| 989 | * @param timeout |
| 990 | * |
| 991 | * @returns IPMI completion code plus response data |
| 992 | * - mdr2Version |
| 993 | * - session |
| 994 | * - dataLength |
| 995 | * - xferAddress |
| 996 | * - xferLength |
| 997 | */ |
| 998 | ipmi::RspType<uint8_t, // mdr2Version |
| 999 | uint16_t, // session |
| 1000 | uint32_t, // dataLength |
| 1001 | uint32_t, // xferAddress |
| 1002 | uint32_t // xferLength |
| 1003 | > |
| 1004 | mdr2LockData(uint16_t agentId, std::array<uint8_t, dataInfoSize> dataInfo, |
| 1005 | uint16_t timeout) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1006 | { |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1007 | if (mdrv2 == nullptr) |
| 1008 | { |
| 1009 | mdrv2 = std::make_unique<MDRV2>(); |
| 1010 | } |
| 1011 | |
jayaprakash Mutyala | 40fec61 | 2019-06-19 11:53:03 +0000 | [diff] [blame] | 1012 | int agentIndex = mdrv2->agentLookup(agentId); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1013 | if (agentIndex == -1) |
| 1014 | { |
| 1015 | phosphor::logging::log<phosphor::logging::level::ERR>( |
jayaprakash Mutyala | 40fec61 | 2019-06-19 11:53:03 +0000 | [diff] [blame] | 1016 | "Unknown agent id", phosphor::logging::entry("ID=%x", agentId)); |
| 1017 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1020 | std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus(); |
| 1021 | std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1022 | |
Patrick Venture | 6d76560 | 2019-09-25 17:11:07 -0700 | [diff] [blame] | 1023 | int idIndex = mdrv2->findDataId(dataInfo.data(), dataInfo.size(), service); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1024 | |
| 1025 | if ((idIndex < 0) || (idIndex >= maxDirEntries)) |
| 1026 | { |
| 1027 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1028 | "Invalid Data ID", phosphor::logging::entry("IDINDEX=%x", idIndex)); |
jayaprakash Mutyala | 40fec61 | 2019-06-19 11:53:03 +0000 | [diff] [blame] | 1029 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1030 | } |
| 1031 | |
jayaprakash Mutyala | 40fec61 | 2019-06-19 11:53:03 +0000 | [diff] [blame] | 1032 | uint16_t session = 0; |
| 1033 | if (!mdrv2->smbiosTryLock(0, idIndex, &session, timeout)) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1034 | { |
| 1035 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1036 | "Lock Data failed - cannot lock idIndex"); |
jayaprakash Mutyala | 40fec61 | 2019-06-19 11:53:03 +0000 | [diff] [blame] | 1037 | return ipmi::responseCommandNotAvailable(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1038 | } |
| 1039 | |
jayaprakash Mutyala | 40fec61 | 2019-06-19 11:53:03 +0000 | [diff] [blame] | 1040 | uint32_t dataLength = mdrv2->smbiosDir.dir[idIndex].common.size; |
| 1041 | uint32_t xferAddress = mdrv2->smbiosDir.dir[idIndex].xferBuff; |
| 1042 | uint32_t xferLength = mdrv2->smbiosDir.dir[idIndex].xferSize; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1043 | |
jayaprakash Mutyala | 40fec61 | 2019-06-19 11:53:03 +0000 | [diff] [blame] | 1044 | return ipmi::responseSuccess(mdr2Version, session, dataLength, xferAddress, |
| 1045 | xferLength); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
jayaprakash Mutyala | dad548b | 2019-06-12 15:29:39 +0000 | [diff] [blame] | 1048 | /** @brief implements mdr2 unlock data command |
| 1049 | * @param agentId |
| 1050 | * @param lockHandle |
| 1051 | * |
| 1052 | * @returns IPMI completion code |
| 1053 | */ |
| 1054 | ipmi::RspType<> mdr2UnlockData(uint16_t agentId, uint16_t lockHandle) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1055 | { |
| 1056 | phosphor::logging::log<phosphor::logging::level::ERR>("unlock data"); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1057 | |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1058 | if (mdrv2 == nullptr) |
| 1059 | { |
| 1060 | mdrv2 = std::make_unique<MDRV2>(); |
| 1061 | } |
| 1062 | |
jayaprakash Mutyala | dad548b | 2019-06-12 15:29:39 +0000 | [diff] [blame] | 1063 | int agentIndex = mdrv2->agentLookup(agentId); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1064 | if (agentIndex == -1) |
| 1065 | { |
| 1066 | phosphor::logging::log<phosphor::logging::level::ERR>( |
jayaprakash Mutyala | dad548b | 2019-06-12 15:29:39 +0000 | [diff] [blame] | 1067 | "Unknown agent id", phosphor::logging::entry("ID=%x", agentId)); |
| 1068 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1069 | } |
| 1070 | |
jayaprakash Mutyala | dad548b | 2019-06-12 15:29:39 +0000 | [diff] [blame] | 1071 | int idIndex = mdrv2->findLockHandle(lockHandle); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1072 | |
| 1073 | if ((idIndex < 0) || (idIndex >= maxDirEntries)) |
| 1074 | { |
| 1075 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1076 | "Invalid Data ID", phosphor::logging::entry("IDINDEX=%x", idIndex)); |
jayaprakash Mutyala | dad548b | 2019-06-12 15:29:39 +0000 | [diff] [blame] | 1077 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | if (!mdrv2->smbiosUnlock(idIndex)) |
| 1081 | { |
| 1082 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1083 | "Unlock Data failed - cannot unlock idIndex"); |
jayaprakash Mutyala | dad548b | 2019-06-12 15:29:39 +0000 | [diff] [blame] | 1084 | return ipmi::responseCommandNotAvailable(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1085 | } |
| 1086 | |
jayaprakash Mutyala | dad548b | 2019-06-12 15:29:39 +0000 | [diff] [blame] | 1087 | return ipmi::responseSuccess(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1088 | } |
| 1089 | |
Deepak Kumar Sahu | 529d415 | 2019-05-31 18:23:14 +0000 | [diff] [blame] | 1090 | /** |
| 1091 | @brief This command is executed after POST BIOS to get the session info. |
| 1092 | |
| 1093 | @param - agentId, dataInfo, dataLength, xferAddress, xferLength, timeout. |
| 1094 | |
| 1095 | @return xferStartAck and session on success. |
| 1096 | **/ |
| 1097 | ipmi::RspType<uint8_t, uint16_t> |
| 1098 | cmd_mdr2_data_start(uint16_t agentId, std::array<uint8_t, 16> dataInfo, |
| 1099 | uint32_t dataLength, uint32_t xferAddress, |
| 1100 | uint32_t xferLength, uint16_t timeout) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1101 | { |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1102 | uint16_t session = 0; |
| 1103 | |
Deepak Kumar Sahu | 529d415 | 2019-05-31 18:23:14 +0000 | [diff] [blame] | 1104 | if (dataLength > smbiosTableStorageSize) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1105 | { |
| 1106 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1107 | "Requested data length is out of SMBIOS Table storage size."); |
Deepak Kumar Sahu | 529d415 | 2019-05-31 18:23:14 +0000 | [diff] [blame] | 1108 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1109 | } |
Deepak Kumar Sahu | 529d415 | 2019-05-31 18:23:14 +0000 | [diff] [blame] | 1110 | if ((xferLength + xferAddress) > mdriiSMSize) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1111 | { |
| 1112 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1113 | "Invalid data address and size"); |
Deepak Kumar Sahu | 529d415 | 2019-05-31 18:23:14 +0000 | [diff] [blame] | 1114 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1115 | } |
| 1116 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1117 | std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus(); |
| 1118 | std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1119 | |
| 1120 | if (mdrv2 == nullptr) |
| 1121 | { |
| 1122 | mdrv2 = std::make_unique<MDRV2>(); |
| 1123 | } |
| 1124 | |
Deepak Kumar Sahu | 529d415 | 2019-05-31 18:23:14 +0000 | [diff] [blame] | 1125 | int agentIndex = mdrv2->agentLookup(agentId); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1126 | if (agentIndex == -1) |
| 1127 | { |
| 1128 | phosphor::logging::log<phosphor::logging::level::ERR>( |
Deepak Kumar Sahu | 529d415 | 2019-05-31 18:23:14 +0000 | [diff] [blame] | 1129 | "Unknown agent id", phosphor::logging::entry("ID=%x", agentId)); |
| 1130 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1131 | } |
| 1132 | |
Patrick Venture | 6d76560 | 2019-09-25 17:11:07 -0700 | [diff] [blame] | 1133 | int idIndex = mdrv2->findDataId(dataInfo.data(), dataInfo.size(), service); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1134 | |
| 1135 | if ((idIndex < 0) || (idIndex >= maxDirEntries)) |
| 1136 | { |
| 1137 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1138 | "Invalid Data ID", phosphor::logging::entry("IDINDEX=%x", idIndex)); |
Deepak Kumar Sahu | 529d415 | 2019-05-31 18:23:14 +0000 | [diff] [blame] | 1139 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1140 | } |
| 1141 | |
Deepak Kumar Sahu | 529d415 | 2019-05-31 18:23:14 +0000 | [diff] [blame] | 1142 | if (mdrv2->smbiosTryLock(1, idIndex, &session, timeout)) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1143 | { |
| 1144 | try |
| 1145 | { |
Patrick Williams | b37abfb | 2023-05-10 07:50:33 -0500 | [diff] [blame] | 1146 | mdrv2->area = std::make_unique<SharedMemoryArea>(xferAddress, |
| 1147 | xferLength); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1148 | } |
James Feist | fcd2d3a | 2020-05-28 10:38:15 -0700 | [diff] [blame] | 1149 | catch (const std::system_error& e) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1150 | { |
| 1151 | mdrv2->smbiosUnlock(idIndex); |
| 1152 | phosphor::logging::log<phosphor::logging::level::ERR>( |
Vernon Mauery | c7d517e | 2019-06-18 14:27:00 -0700 | [diff] [blame] | 1153 | "Unable to access share memory", |
| 1154 | phosphor::logging::entry("ERROR=%s", e.what())); |
Deepak Kumar Sahu | 529d415 | 2019-05-31 18:23:14 +0000 | [diff] [blame] | 1155 | return ipmi::responseUnspecifiedError(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1156 | } |
Deepak Kumar Sahu | 529d415 | 2019-05-31 18:23:14 +0000 | [diff] [blame] | 1157 | mdrv2->smbiosDir.dir[idIndex].common.size = dataLength; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1158 | mdrv2->smbiosDir.dir[idIndex].lockHandle = session; |
| 1159 | if (-1 == |
| 1160 | mdrv2->syncDirCommonData( |
| 1161 | idIndex, mdrv2->smbiosDir.dir[idIndex].common.size, service)) |
| 1162 | { |
| 1163 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1164 | "Unable to sync data to service"); |
Deepak Kumar Sahu | 529d415 | 2019-05-31 18:23:14 +0000 | [diff] [blame] | 1165 | return ipmi::responseResponseError(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1166 | } |
| 1167 | } |
| 1168 | else |
| 1169 | { |
| 1170 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1171 | "Canot lock smbios"); |
Deepak Kumar Sahu | 529d415 | 2019-05-31 18:23:14 +0000 | [diff] [blame] | 1172 | return ipmi::responseUnspecifiedError(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1173 | } |
| 1174 | |
Deepak Kumar Sahu | 529d415 | 2019-05-31 18:23:14 +0000 | [diff] [blame] | 1175 | static constexpr uint8_t xferStartAck = 1; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1176 | |
Deepak Kumar Sahu | 529d415 | 2019-05-31 18:23:14 +0000 | [diff] [blame] | 1177 | return ipmi::responseSuccess(xferStartAck, session); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1178 | } |
| 1179 | |
Deepak Kumar Sahu | 529d415 | 2019-05-31 18:23:14 +0000 | [diff] [blame] | 1180 | /** |
| 1181 | @brief This command is executed to close the session. |
| 1182 | |
| 1183 | @param - agentId, lockHandle. |
| 1184 | |
| 1185 | @return completion code on success. |
| 1186 | **/ |
| 1187 | ipmi::RspType<> cmd_mdr2_data_done(uint16_t agentId, uint16_t lockHandle) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1188 | { |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1189 | if (mdrv2 == nullptr) |
| 1190 | { |
| 1191 | mdrv2 = std::make_unique<MDRV2>(); |
| 1192 | } |
| 1193 | |
Deepak Kumar Sahu | 529d415 | 2019-05-31 18:23:14 +0000 | [diff] [blame] | 1194 | int agentIndex = mdrv2->agentLookup(agentId); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1195 | if (agentIndex == -1) |
| 1196 | { |
| 1197 | phosphor::logging::log<phosphor::logging::level::ERR>( |
Deepak Kumar Sahu | 529d415 | 2019-05-31 18:23:14 +0000 | [diff] [blame] | 1198 | "Unknown agent id", phosphor::logging::entry("ID=%x", agentId)); |
| 1199 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1200 | } |
| 1201 | |
Deepak Kumar Sahu | 529d415 | 2019-05-31 18:23:14 +0000 | [diff] [blame] | 1202 | int idIndex = mdrv2->findLockHandle(lockHandle); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1203 | |
| 1204 | if ((idIndex < 0) || (idIndex >= maxDirEntries)) |
| 1205 | { |
| 1206 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1207 | "Invalid Data ID", phosphor::logging::entry("IDINDEX=%x", idIndex)); |
Deepak Kumar Sahu | 529d415 | 2019-05-31 18:23:14 +0000 | [diff] [blame] | 1208 | return ipmi::responseParmOutOfRange(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | if (!mdrv2->smbiosUnlock(idIndex)) |
| 1212 | { |
| 1213 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1214 | "Send data done failed - cannot unlock idIndex"); |
Deepak Kumar Sahu | 529d415 | 2019-05-31 18:23:14 +0000 | [diff] [blame] | 1215 | return ipmi::responseDestinationUnavailable(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1216 | } |
| 1217 | |
| 1218 | mdrv2->area.reset(nullptr); |
| 1219 | MDRSMBIOSHeader mdr2Smbios; |
| 1220 | mdr2Smbios.mdrType = mdrTypeII; |
| 1221 | mdr2Smbios.dirVer = mdrv2->smbiosDir.dir[0].common.dataVersion; |
| 1222 | mdr2Smbios.timestamp = mdrv2->smbiosDir.dir[0].common.timestamp; |
| 1223 | mdr2Smbios.dataSize = mdrv2->smbiosDir.dir[0].common.size; |
| 1224 | |
| 1225 | if (access(smbiosPath, 0) == -1) |
| 1226 | { |
| 1227 | int flag = mkdir(smbiosPath, S_IRWXU); |
| 1228 | if (flag != 0) |
| 1229 | { |
| 1230 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1231 | "create folder failed for writting smbios file"); |
| 1232 | } |
| 1233 | } |
| 1234 | if (!mdrv2->storeDatatoFlash( |
| 1235 | &mdr2Smbios, mdrv2->smbiosDir.dir[smbiosDirIndex].dataStorage)) |
| 1236 | { |
| 1237 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1238 | "MDR2 Store data to flash failed"); |
Deepak Kumar Sahu | 529d415 | 2019-05-31 18:23:14 +0000 | [diff] [blame] | 1239 | return ipmi::responseDestinationUnavailable(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1240 | } |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1241 | bool status = false; |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 1242 | std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus(); |
| 1243 | std::string service = ipmi::getService(*bus, mdrv2Interface, mdrv2Path); |
Patrick Williams | f944d2e | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 1244 | sdbusplus::message_t method = bus->new_method_call( |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1245 | service.c_str(), mdrv2Path, mdrv2Interface, "AgentSynchronizeData"); |
| 1246 | |
| 1247 | try |
| 1248 | { |
Patrick Williams | f944d2e | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 1249 | sdbusplus::message_t reply = bus->call(method); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1250 | reply.read(status); |
| 1251 | } |
Patrick Williams | bd51e6a | 2021-10-06 13:09:44 -0500 | [diff] [blame] | 1252 | catch (const sdbusplus::exception_t& e) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1253 | { |
| 1254 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1255 | "Error Sync data with service", |
Vernon Mauery | c7d517e | 2019-06-18 14:27:00 -0700 | [diff] [blame] | 1256 | phosphor::logging::entry("ERROR=%s", e.what()), |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1257 | phosphor::logging::entry("SERVICE=%s", service.c_str()), |
| 1258 | phosphor::logging::entry("PATH=%s", mdrv2Path)); |
Deepak Kumar Sahu | 529d415 | 2019-05-31 18:23:14 +0000 | [diff] [blame] | 1259 | return ipmi::responseResponseError(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1260 | } |
| 1261 | |
| 1262 | if (!status) |
| 1263 | { |
| 1264 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 1265 | "Sync data with service failure"); |
Deepak Kumar Sahu | 529d415 | 2019-05-31 18:23:14 +0000 | [diff] [blame] | 1266 | return ipmi::responseUnspecifiedError(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1267 | } |
| 1268 | |
Deepak Kumar Sahu | 529d415 | 2019-05-31 18:23:14 +0000 | [diff] [blame] | 1269 | return ipmi::responseSuccess(); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | static void register_netfn_smbiosmdrv2_functions(void) |
| 1273 | { |
| 1274 | // MDR V2 Command |
| 1275 | // <Get MDRII Status Command> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1276 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnApp, |
| 1277 | ipmi::intel::app::cmdMdrIIAgentStatus, |
jayaprakash Mutyala | 853d829 | 2019-05-31 18:17:42 +0000 | [diff] [blame] | 1278 | ipmi::Privilege::Operator, mdr2AgentStatus); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1279 | |
| 1280 | // <Get MDRII Directory Command> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1281 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnApp, |
| 1282 | ipmi::intel::app::cmdMdrIIGetDir, |
jayaprakash Mutyala | dad548b | 2019-06-12 15:29:39 +0000 | [diff] [blame] | 1283 | ipmi::Privilege::Operator, mdr2GetDir); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1284 | |
| 1285 | // <Send MDRII Directory Command> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1286 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnApp, |
| 1287 | ipmi::intel::app::cmdMdrIISendDir, |
jayaprakash Mutyala | 7cb59cc | 2019-06-19 19:17:43 +0000 | [diff] [blame] | 1288 | ipmi::Privilege::Operator, mdr2SendDir); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1289 | |
| 1290 | // <Get MDRII Data Info Command> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1291 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnApp, |
| 1292 | ipmi::intel::app::cmdMdrIIGetDataInfo, |
jayaprakash Mutyala | f5d49d6 | 2019-06-18 12:28:01 +0000 | [diff] [blame] | 1293 | ipmi::Privilege::Operator, mdr2GetDataInfo); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1294 | |
| 1295 | // <Send MDRII Info Offer> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1296 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnApp, |
| 1297 | ipmi::intel::app::cmdMdrIISendDataInfoOffer, |
| 1298 | ipmi::Privilege::Operator, mdr2DataInfoOffer); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1299 | |
| 1300 | // <Send MDRII Data Info> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1301 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnApp, |
| 1302 | ipmi::intel::app::cmdMdrIISendDataInfo, |
jayaprakash Mutyala | f5d49d6 | 2019-06-18 12:28:01 +0000 | [diff] [blame] | 1303 | ipmi::Privilege::Operator, mdr2SendDataInfo); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1304 | |
| 1305 | // <Get MDRII Data Block Command> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1306 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnApp, |
| 1307 | ipmi::intel::app::cmdMdrIIGetDataBlock, |
Deepak Kumar Sahu | f4f5c16 | 2019-06-11 17:45:05 +0000 | [diff] [blame] | 1308 | ipmi::Privilege::Operator, mdr2GetDataBlock); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1309 | |
| 1310 | // <Send MDRII Data Block> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1311 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnApp, |
| 1312 | ipmi::intel::app::cmdMdrIISendDataBlock, |
jayaprakash Mutyala | 3104b3f | 2019-06-10 19:23:07 +0000 | [diff] [blame] | 1313 | ipmi::Privilege::Operator, mdr2SendDataBlock); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1314 | |
| 1315 | // <Lock MDRII Data Command> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1316 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnApp, |
| 1317 | ipmi::intel::app::cmdMdrIILockData, |
jayaprakash Mutyala | 40fec61 | 2019-06-19 11:53:03 +0000 | [diff] [blame] | 1318 | ipmi::Privilege::Operator, mdr2LockData); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1319 | |
| 1320 | // <Unlock MDRII Data Command> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1321 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnApp, |
| 1322 | ipmi::intel::app::cmdMdrIIUnlockData, |
jayaprakash Mutyala | dad548b | 2019-06-12 15:29:39 +0000 | [diff] [blame] | 1323 | ipmi::Privilege::Operator, mdr2UnlockData); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1324 | |
| 1325 | // <Send MDRII Data Start> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1326 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnApp, |
| 1327 | ipmi::intel::app::cmdMdrIIDataStart, |
Deepak Kumar Sahu | 529d415 | 2019-05-31 18:23:14 +0000 | [diff] [blame] | 1328 | ipmi::Privilege::Operator, cmd_mdr2_data_start); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1329 | |
| 1330 | // <Send MDRII Data Done> |
Vernon Mauery | 98bbf69 | 2019-09-16 11:14:59 -0700 | [diff] [blame] | 1331 | ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnApp, |
| 1332 | ipmi::intel::app::cmdMdrIIDataDone, |
Deepak Kumar Sahu | 529d415 | 2019-05-31 18:23:14 +0000 | [diff] [blame] | 1333 | ipmi::Privilege::Operator, cmd_mdr2_data_done); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 1334 | } |