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