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 | |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 17 | #include <commandutils.hpp> |
| 18 | #include <cstdint> |
| 19 | #include <iostream> |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 20 | #include <ipmid/api.hpp> |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 21 | #include <ipmid/utils.hpp> |
| 22 | #include <phosphor-logging/elog-errors.hpp> |
| 23 | #include <phosphor-logging/log.hpp> |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 24 | #include <smbioshandler.hpp> |
| 25 | #include <string> |
| 26 | #include <vector> |
| 27 | #include <xyz/openbmc_project/Common/error.hpp> |
| 28 | |
| 29 | using InternalFailure = |
| 30 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
| 31 | |
| 32 | using level = phosphor::logging::level; |
| 33 | |
| 34 | constexpr const char* DBUS_PROPERTIES = "org.freedesktop.DBus.Properties"; |
| 35 | constexpr const char* MDRV1_PATH = "/xyz/openbmc_project/Smbios/MDR_V1"; |
| 36 | constexpr const char* MDRV1_INTERFACE = "xyz.openbmc_project.Smbios.MDR_V1"; |
| 37 | |
| 38 | static void register_netfn_smbios_functions() __attribute__((constructor)); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 39 | |
| 40 | ipmi_ret_t cmd_region_status(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 41 | ipmi_request_t request, ipmi_response_t response, |
| 42 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 43 | { |
| 44 | auto requestData = reinterpret_cast<const RegionStatusRequest*>(request); |
| 45 | std::vector<uint8_t> status; |
| 46 | |
| 47 | if (*data_len != sizeof(RegionStatusRequest)) |
| 48 | { |
| 49 | *data_len = 0; |
| 50 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 51 | } |
| 52 | |
| 53 | uint8_t regionId = requestData->regionId - 1; |
| 54 | *data_len = 0; |
| 55 | |
| 56 | if (regionId >= maxMDRId) |
| 57 | { |
| 58 | phosphor::logging::log<level::ERR>("Invalid region"); |
| 59 | return IPMI_CC_PARM_OUT_OF_RANGE; |
| 60 | } |
| 61 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 62 | std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus(); |
| 63 | std::string service = ipmi::getService(*bus, MDRV1_INTERFACE, MDRV1_PATH); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 64 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 65 | auto method = bus->new_method_call(service.c_str(), MDRV1_PATH, |
| 66 | MDRV1_INTERFACE, "RegionStatus"); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 67 | method.append(regionId); |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 68 | auto reply = bus->call(method); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 69 | if (reply.is_method_error()) |
| 70 | { |
| 71 | phosphor::logging::log<level::ERR>( |
| 72 | "Error get region status", |
| 73 | phosphor::logging::entry("SERVICE=%s", service.c_str()), |
| 74 | phosphor::logging::entry("PATH=%s", MDRV1_PATH)); |
| 75 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 76 | } |
| 77 | reply.read(status); |
| 78 | |
| 79 | if (status.size() != sizeof(MDRState)) |
| 80 | { |
| 81 | phosphor::logging::log<level::ERR>( |
| 82 | "Error get region status, return length invalid"); |
| 83 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 84 | } |
| 85 | *data_len = static_cast<size_t>(status.size()); |
| 86 | auto dataOut = reinterpret_cast<uint8_t*>(response); |
| 87 | std::copy(&status[0], &status[*data_len], dataOut); |
| 88 | return IPMI_CC_OK; |
| 89 | } |
| 90 | |
| 91 | int sdplus_mdrv1_get_property( |
| 92 | const std::string& name, |
| 93 | sdbusplus::message::variant<uint8_t, uint16_t>& value, std::string& service) |
| 94 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 95 | std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus(); |
| 96 | auto method = bus->new_method_call(service.c_str(), MDRV1_PATH, |
| 97 | DBUS_PROPERTIES, "Get"); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 98 | method.append(MDRV1_INTERFACE, name); |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 99 | auto reply = bus->call(method); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 100 | if (reply.is_method_error()) |
| 101 | { |
| 102 | phosphor::logging::log<level::ERR>( |
| 103 | "Error getting property, sdbusplus call failed"); |
| 104 | return -1; |
| 105 | } |
| 106 | reply.read(value); |
| 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | static int set_regionId(uint8_t regionId, std::string& service) |
| 112 | { |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 113 | std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus(); |
| 114 | auto method = bus->new_method_call(service.c_str(), MDRV1_PATH, |
| 115 | DBUS_PROPERTIES, "Set"); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 116 | sdbusplus::message::variant<uint8_t> value{regionId}; |
| 117 | method.append(MDRV1_INTERFACE, "RegionId", value); |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 118 | auto region = bus->call(method); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 119 | if (region.is_method_error()) |
| 120 | { |
| 121 | phosphor::logging::log<level::ERR>( |
| 122 | "Error setting regionID, sdbusplus call failed"); |
| 123 | return -1; |
| 124 | } |
| 125 | return 0; |
| 126 | } |
| 127 | |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 128 | ipmi_ret_t cmd_region_complete(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 129 | ipmi_request_t request, ipmi_response_t response, |
| 130 | ipmi_data_len_t data_len, ipmi_context_t context) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 131 | { |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 132 | auto requestData = reinterpret_cast<const RegionCompleteRequest*>(request); |
| 133 | uint8_t status; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 134 | |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 135 | sdbusplus::message::variant<uint8_t, uint16_t> value; |
| 136 | |
| 137 | if (*data_len != sizeof(RegionCompleteRequest)) |
| 138 | { |
| 139 | *data_len = 0; |
| 140 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 141 | } |
| 142 | |
| 143 | uint8_t regionId = requestData->regionId - 1; |
| 144 | *data_len = 0; |
| 145 | |
| 146 | if (regionId >= maxMDRId) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 147 | { |
| 148 | phosphor::logging::log<level::ERR>("Invalid region"); |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 149 | return IPMI_CC_PARM_OUT_OF_RANGE; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 152 | std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus(); |
| 153 | std::string service = ipmi::getService(*bus, MDRV1_INTERFACE, MDRV1_PATH); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 154 | |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 155 | if (set_regionId(regionId, service) < 0) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 156 | { |
| 157 | phosphor::logging::log<level::ERR>("Error setting regionId"); |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 158 | return IPMI_CC_UNSPECIFIED_ERROR; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | if (0 > sdplus_mdrv1_get_property("LockPolicy", value, service)) |
| 162 | { |
| 163 | phosphor::logging::log<level::ERR>("Error getting lockPolicy"); |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 164 | return IPMI_CC_UNSPECIFIED_ERROR; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 165 | } |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 166 | if (regionLockUnlocked == std::get<uint8_t>(value)) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 167 | { |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 168 | return IPMI_CC_PARAMETER_NOT_SUPPORT_IN_PRESENT_STATE; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | if (0 > sdplus_mdrv1_get_property("SessionId", value, service)) |
| 172 | { |
| 173 | phosphor::logging::log<level::ERR>("Error getting sessionId"); |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 174 | return IPMI_CC_UNSPECIFIED_ERROR; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 175 | } |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 176 | if (requestData->sessionId != std::get<uint8_t>(value)) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 177 | { |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 178 | return IPMI_CC_OEM_SET_IN_PROCESS; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 181 | auto method = bus->new_method_call(service.c_str(), MDRV1_PATH, |
| 182 | MDRV1_INTERFACE, "RegionComplete"); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 183 | |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 184 | method.append(regionId); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 185 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 186 | auto reply = bus->call(method); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 187 | if (reply.is_method_error()) |
| 188 | { |
| 189 | phosphor::logging::log<level::ERR>( |
| 190 | "Error set region complete", |
| 191 | phosphor::logging::entry("SERVICE=%s", service.c_str()), |
| 192 | phosphor::logging::entry("PATH=%s", MDRV1_PATH)); |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 193 | return IPMI_CC_UNSPECIFIED_ERROR; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 194 | } |
| 195 | reply.read(status); |
| 196 | |
| 197 | if (status != 0) |
| 198 | phosphor::logging::log<level::ERR>( |
| 199 | "Error set region complete, unexpected error"); |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 200 | return IPMI_CC_UNSPECIFIED_ERROR; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 201 | |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 202 | return IPMI_CC_OK; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | ipmi_ret_t cmd_region_read(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 206 | ipmi_request_t request, ipmi_response_t response, |
| 207 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 208 | { |
| 209 | auto requestData = reinterpret_cast<const RegionReadRequest*>(request); |
| 210 | auto responseData = reinterpret_cast<RegionReadResponse*>(response); |
| 211 | sdbusplus::message::variant<uint8_t, uint16_t> regUsedVal; |
| 212 | sdbusplus::message::variant<uint8_t, uint16_t> lockPolicyVal; |
| 213 | std::vector<uint8_t> res; |
| 214 | |
| 215 | if (*data_len < sizeof(RegionReadRequest)) |
| 216 | { |
| 217 | *data_len = 0; |
| 218 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 219 | } |
| 220 | |
| 221 | uint8_t regionId = requestData->regionId - 1; |
| 222 | |
| 223 | *data_len = 0; |
| 224 | |
| 225 | if (regionId >= maxMDRId) |
| 226 | { |
| 227 | phosphor::logging::log<level::ERR>("Invalid region"); |
| 228 | return IPMI_CC_PARM_OUT_OF_RANGE; |
| 229 | } |
| 230 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 231 | std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus(); |
| 232 | std::string service = ipmi::getService(*bus, MDRV1_INTERFACE, MDRV1_PATH); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 233 | // TODO to make sure the interface can get correct LockPolicy even |
| 234 | // regionId changed by another task. |
| 235 | if (set_regionId(regionId, service) < 0) |
| 236 | { |
| 237 | phosphor::logging::log<level::ERR>("Error setting regionId"); |
| 238 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 239 | } |
| 240 | if (0 > sdplus_mdrv1_get_property("RegionUsed", regUsedVal, service)) |
| 241 | { |
| 242 | phosphor::logging::log<level::ERR>("Error getting regionUsed"); |
| 243 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 244 | } |
| 245 | if (requestData->offset + requestData->length > |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 246 | std::get<uint16_t>(regUsedVal)) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 247 | { |
| 248 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 249 | } |
| 250 | |
| 251 | if (0 > sdplus_mdrv1_get_property("LockPolicy", lockPolicyVal, service)) |
| 252 | { |
| 253 | phosphor::logging::log<level::ERR>("Error getting lockPolicy"); |
| 254 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 255 | } |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 256 | if (regionLockUnlocked != std::get<uint8_t>(lockPolicyVal)) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 257 | { |
| 258 | return IPMI_CC_PARAMETER_NOT_SUPPORT_IN_PRESENT_STATE; |
| 259 | } |
| 260 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 261 | auto method = bus->new_method_call(service.c_str(), MDRV1_PATH, |
| 262 | MDRV1_INTERFACE, "RegionRead"); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 263 | |
| 264 | method.append(regionId, requestData->length, requestData->offset); |
| 265 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 266 | auto reply = bus->call(method); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 267 | if (reply.is_method_error()) |
| 268 | { |
| 269 | phosphor::logging::log<level::ERR>( |
| 270 | "Error read region data", |
| 271 | phosphor::logging::entry("SERVICE=%s", service.c_str()), |
| 272 | phosphor::logging::entry("PATH=%s", MDRV1_PATH)); |
| 273 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 274 | } |
| 275 | reply.read(res); |
| 276 | |
| 277 | *data_len = responseData->length = res[0]; |
| 278 | responseData->updateCount = res[1]; |
| 279 | |
| 280 | if ((*data_len == 0) || (*data_len >= 254)) |
| 281 | { |
| 282 | phosphor::logging::log<level::ERR>( |
| 283 | "Data length send from service is invalid"); |
| 284 | *data_len = 0; |
| 285 | return IPMI_CC_RESPONSE_ERROR; |
| 286 | } |
| 287 | |
| 288 | *data_len += 2 * sizeof(uint8_t); |
| 289 | std::copy(&res[2], &res[*data_len], responseData->data); |
| 290 | return IPMI_CC_OK; |
| 291 | } |
| 292 | |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 293 | ipmi_ret_t cmd_region_write(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 294 | ipmi_request_t request, ipmi_response_t response, |
| 295 | ipmi_data_len_t data_len, ipmi_context_t context) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 296 | { |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 297 | auto requestData = reinterpret_cast<const RegionWriteRequest*>(request); |
| 298 | uint8_t regionId = requestData->regionId - 1; |
| 299 | std::string res; |
| 300 | std::vector<uint8_t> writeData; |
| 301 | uint16_t index; |
| 302 | uint8_t tmp[255]; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 303 | |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 304 | size_t minInputLen = &requestData->data[0] - &requestData->sessionId + 1; |
| 305 | if (*data_len < minInputLen) |
| 306 | { // this command need at least 6 bytes input |
| 307 | *data_len = 0; |
| 308 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 309 | } |
| 310 | |
| 311 | sdbusplus::message::variant<uint8_t, uint16_t> value; |
| 312 | |
| 313 | *data_len = 0; |
| 314 | |
| 315 | if (regionId >= maxMDRId) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 316 | { |
| 317 | phosphor::logging::log<level::ERR>("Invalid region"); |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 318 | return IPMI_CC_PARM_OUT_OF_RANGE; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 321 | std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus(); |
| 322 | std::string service = ipmi::getService(*bus, MDRV1_INTERFACE, MDRV1_PATH); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 323 | |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 324 | if (set_regionId(regionId, service) < 0) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 325 | { |
| 326 | phosphor::logging::log<level::ERR>("Error setting regionId"); |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 327 | return IPMI_CC_UNSPECIFIED_ERROR; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | if (0 > sdplus_mdrv1_get_property("LockPolicy", value, service)) |
| 331 | { |
| 332 | phosphor::logging::log<level::ERR>("Error getting lockPolicy"); |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 333 | return IPMI_CC_UNSPECIFIED_ERROR; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 334 | } |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 335 | if (regionLockUnlocked == std::get<uint8_t>(value)) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 336 | { |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 337 | return IPMI_CC_PARAMETER_NOT_SUPPORT_IN_PRESENT_STATE; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | if (0 > sdplus_mdrv1_get_property("SessionId", value, service)) |
| 341 | { |
| 342 | phosphor::logging::log<level::ERR>("Error getting sessionId"); |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 343 | return IPMI_CC_UNSPECIFIED_ERROR; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 344 | } |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 345 | if (requestData->sessionId != std::get<uint8_t>(value)) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 346 | { |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 347 | return IPMI_CC_OEM_SET_IN_PROCESS; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 348 | } |
| 349 | |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 350 | std::copy(&(requestData->length), &(requestData->data[requestData->length]), |
| 351 | tmp); |
| 352 | writeData.push_back(regionId); |
| 353 | for (index = 0; index < minInputLen + requestData->length - 2; index++) |
| 354 | { |
| 355 | writeData.push_back(tmp[index]); |
| 356 | } |
| 357 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 358 | auto method = bus->new_method_call(service.c_str(), MDRV1_PATH, |
| 359 | MDRV1_INTERFACE, "RegionWrite"); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 360 | |
| 361 | method.append(writeData); |
| 362 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 363 | auto reply = bus->call(method); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 364 | if (reply.is_method_error()) |
| 365 | { |
| 366 | phosphor::logging::log<level::ERR>( |
| 367 | "Error write region data", |
| 368 | phosphor::logging::entry("SERVICE=%s", service.c_str()), |
| 369 | phosphor::logging::entry("PATH=%s", MDRV1_PATH)); |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 370 | return IPMI_CC_UNSPECIFIED_ERROR; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 371 | } |
| 372 | reply.read(res); |
| 373 | |
| 374 | if (res == "NoData") |
| 375 | { |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 376 | return IPMI_CC_PARM_OUT_OF_RANGE; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 377 | } |
| 378 | else if (res != "Success") |
| 379 | { |
| 380 | phosphor::logging::log<level::ERR>( |
| 381 | "Error write region data, unexpected error"); |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 382 | return IPMI_CC_UNSPECIFIED_ERROR; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 383 | } |
| 384 | |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 385 | return IPMI_CC_OK; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 386 | } |
| 387 | |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 388 | ipmi_ret_t cmd_region_lock(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 389 | ipmi_request_t request, ipmi_response_t response, |
| 390 | ipmi_data_len_t data_len, ipmi_context_t context) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 391 | { |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 392 | auto requestData = reinterpret_cast<const RegionLockRequest*>(request); |
| 393 | uint8_t regionId = requestData->regionId - 1; |
| 394 | sdbusplus::message::variant<uint8_t, uint16_t> value; |
| 395 | auto res = reinterpret_cast<uint8_t*>(response); |
| 396 | uint8_t lockResponse; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 397 | |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 398 | if (*data_len != sizeof(RegionLockRequest)) |
| 399 | { |
| 400 | *data_len = 0; |
| 401 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 402 | } |
| 403 | |
| 404 | *data_len = 0; |
| 405 | |
| 406 | if (regionId >= maxMDRId) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 407 | { |
| 408 | phosphor::logging::log<level::ERR>("Invalid region"); |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 409 | return IPMI_CC_PARM_OUT_OF_RANGE; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 412 | std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus(); |
| 413 | std::string service = ipmi::getService(*bus, MDRV1_INTERFACE, MDRV1_PATH); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 414 | |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 415 | if (set_regionId(regionId, service) < 0) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 416 | { |
| 417 | phosphor::logging::log<level::ERR>("Error setting regionId"); |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 418 | return IPMI_CC_UNSPECIFIED_ERROR; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | if (0 > sdplus_mdrv1_get_property("LockPolicy", value, service)) |
| 422 | { |
| 423 | phosphor::logging::log<level::ERR>("Error getting lockPolicy"); |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 424 | return IPMI_CC_UNSPECIFIED_ERROR; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 425 | } |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 426 | if (requestData->lockPolicy == regionLockUnlocked) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 427 | { |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 428 | if (regionLockUnlocked == std::get<uint8_t>(value)) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 429 | { |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 430 | return IPMI_CC_PARAMETER_NOT_SUPPORT_IN_PRESENT_STATE; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 431 | } |
| 432 | } |
Vernon Mauery | 8166c8d | 2019-05-23 11:22:30 -0700 | [diff] [blame] | 433 | if (regionLockUnlocked != std::get<uint8_t>(value)) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 434 | { |
| 435 | if (0 > sdplus_mdrv1_get_property("SessionId", value, service)) |
| 436 | { |
| 437 | phosphor::logging::log<level::ERR>("Error getting sessionId"); |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 438 | return IPMI_CC_UNSPECIFIED_ERROR; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 439 | } |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 440 | if (requestData->sessionId != std::get<uint8_t>(value)) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 441 | { |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 442 | if (requestData->lockPolicy != regionLockStrict) |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 443 | { |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 444 | return IPMI_CC_OEM_SET_IN_PROCESS; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 445 | } |
| 446 | } |
| 447 | } |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 448 | auto method = bus->new_method_call(service.c_str(), MDRV1_PATH, |
| 449 | MDRV1_INTERFACE, "RegionLock"); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 450 | |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 451 | method.append(requestData->sessionId, regionId, requestData->lockPolicy, |
| 452 | requestData->msTimeout); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 453 | |
Vernon Mauery | 15419dd | 2019-05-24 09:40:30 -0700 | [diff] [blame] | 454 | auto reply = bus->call(method); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 455 | if (reply.is_method_error()) |
| 456 | { |
| 457 | phosphor::logging::log<level::ERR>( |
| 458 | "Error lock region ", |
| 459 | phosphor::logging::entry("SERVICE=%s", service.c_str()), |
| 460 | phosphor::logging::entry("PATH=%s", MDRV1_PATH)); |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 461 | return IPMI_CC_UNSPECIFIED_ERROR; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 462 | } |
| 463 | reply.read(lockResponse); |
| 464 | |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 465 | *data_len = sizeof(lockResponse); |
| 466 | *res = lockResponse; |
| 467 | return IPMI_CC_OK; |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | static void register_netfn_smbios_functions(void) |
| 471 | { |
| 472 | // MDR V1 Command |
| 473 | // <Get MDR Status Command> |
| 474 | ipmi_register_callback(NETFUN_INTEL_APP_OEM, |
| 475 | IPMI_NETFN_INTEL_OEM_APP_CMD::MDR_STATUS, NULL, |
| 476 | cmd_region_status, PRIVILEGE_OPERATOR); |
| 477 | |
| 478 | // <Update Complete Status Command> |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 479 | ipmi_register_callback(NETFUN_INTEL_APP_OEM, |
| 480 | IPMI_NETFN_INTEL_OEM_APP_CMD::MDR_COMPLETE, NULL, |
| 481 | cmd_region_complete, PRIVILEGE_OPERATOR); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 482 | |
| 483 | // <Read MDR Command> |
| 484 | ipmi_register_callback(NETFUN_INTEL_APP_OEM, |
| 485 | IPMI_NETFN_INTEL_OEM_APP_CMD::MDR_READ, NULL, |
| 486 | cmd_region_read, PRIVILEGE_OPERATOR); |
| 487 | |
| 488 | // <Write MDR Command> |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 489 | ipmi_register_callback(NETFUN_INTEL_APP_OEM, |
| 490 | IPMI_NETFN_INTEL_OEM_APP_CMD::MDR_WRITE, NULL, |
| 491 | cmd_region_write, PRIVILEGE_OPERATOR); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 492 | |
| 493 | // <Lock MDR Command> |
James Feist | a73cb81 | 2019-08-14 10:17:02 -0700 | [diff] [blame] | 494 | ipmi_register_callback(NETFUN_INTEL_APP_OEM, |
| 495 | IPMI_NETFN_INTEL_OEM_APP_CMD::MDR_LOCK, NULL, |
| 496 | cmd_region_lock, PRIVILEGE_OPERATOR); |
Vernon Mauery | a3702c1 | 2019-05-22 13:20:59 -0700 | [diff] [blame] | 497 | } |