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