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