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