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