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