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