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