Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [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 | |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 17 | #include "xyz/openbmc_project/Common/error.hpp" |
| 18 | |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 19 | #include <host-ipmid/ipmid-api.h> |
| 20 | |
| 21 | #include <array> |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 22 | #include <commandutils.hpp> |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 23 | #include <iostream> |
| 24 | #include <oemcommands.hpp> |
Jason M. Bills | 3f7c5e4 | 2018-10-03 14:00:41 -0700 | [diff] [blame] | 25 | #include <phosphor-ipmi-host/utils.hpp> |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 26 | #include <phosphor-logging/log.hpp> |
| 27 | #include <sdbusplus/bus.hpp> |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 28 | #include <string> |
| 29 | #include <vector> |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 30 | |
| 31 | namespace ipmi |
| 32 | { |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 33 | static void registerOEMFunctions() __attribute__((constructor)); |
| 34 | sdbusplus::bus::bus dbus(ipmid_get_sd_bus_connection()); // from ipmid-api.h |
| 35 | static constexpr size_t maxFRUStringLength = 0x3F; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 36 | |
| 37 | // return code: 0 successful |
| 38 | int8_t getChassisSerialNumber(sdbusplus::bus::bus& bus, std::string& serial) |
| 39 | { |
| 40 | std::string objpath = "/xyz/openbmc_project/FruDevice"; |
| 41 | std::string intf = "xyz.openbmc_project.FruDeviceManager"; |
| 42 | std::string service = getService(bus, intf, objpath); |
| 43 | ObjectValueTree valueTree = getManagedObjects(bus, service, "/"); |
| 44 | if (valueTree.empty()) |
| 45 | { |
| 46 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 47 | "No object implements interface", |
| 48 | phosphor::logging::entry("INTF=%s", intf.c_str())); |
| 49 | return -1; |
| 50 | } |
| 51 | |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 52 | for (const auto& item : valueTree) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 53 | { |
| 54 | auto interface = item.second.find("xyz.openbmc_project.FruDevice"); |
| 55 | if (interface == item.second.end()) |
| 56 | { |
| 57 | continue; |
| 58 | } |
| 59 | |
| 60 | auto property = interface->second.find("CHASSIS_SERIAL_NUMBER"); |
| 61 | if (property == interface->second.end()) |
| 62 | { |
| 63 | continue; |
| 64 | } |
| 65 | |
| 66 | try |
| 67 | { |
| 68 | Value variant = property->second; |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 69 | std::string& result = |
| 70 | sdbusplus::message::variant_ns::get<std::string>(variant); |
| 71 | if (result.size() > maxFRUStringLength) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 72 | { |
| 73 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 74 | "FRU serial number exceed maximum length"); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 75 | return -1; |
| 76 | } |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 77 | serial = result; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 78 | return 0; |
| 79 | } |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 80 | catch (sdbusplus::message::variant_ns::bad_variant_access& e) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 81 | { |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 82 | phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 83 | return -1; |
| 84 | } |
| 85 | } |
| 86 | return -1; |
| 87 | } |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 88 | |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 89 | ipmi_ret_t ipmiOEMWildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 90 | ipmi_request_t request, ipmi_response_t response, |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 91 | ipmi_data_len_t dataLen, ipmi_context_t context) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 92 | { |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 93 | printCommand(+netfn, +cmd); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 94 | // Status code. |
| 95 | ipmi_ret_t rc = IPMI_CC_INVALID; |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 96 | *dataLen = 0; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 97 | return rc; |
| 98 | } |
| 99 | |
| 100 | // Returns the Chassis Identifier (serial #) |
| 101 | ipmi_ret_t ipmiOEMGetChassisIdentifier(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 102 | ipmi_request_t request, |
| 103 | ipmi_response_t response, |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 104 | ipmi_data_len_t dataLen, |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 105 | ipmi_context_t context) |
| 106 | { |
| 107 | std::string serial; |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 108 | if (*dataLen != 0) // invalid request if there are extra parameters |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 109 | { |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 110 | *dataLen = 0; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 111 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 112 | } |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 113 | if (getChassisSerialNumber(dbus, serial) == 0) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 114 | { |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 115 | *dataLen = serial.size(); // length will never exceed response length |
| 116 | // as it is checked in getChassisSerialNumber |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 117 | char* resp = static_cast<char*>(response); |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 118 | serial.copy(resp, *dataLen); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 119 | return IPMI_CC_OK; |
| 120 | } |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 121 | *dataLen = 0; |
| 122 | return IPMI_CC_RESPONSE_ERROR; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | ipmi_ret_t ipmiOEMSetSystemGUID(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 126 | ipmi_request_t request, |
| 127 | ipmi_response_t response, |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 128 | ipmi_data_len_t dataLen, ipmi_context_t context) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 129 | { |
| 130 | static constexpr size_t safeBufferLength = 50; |
| 131 | char buf[safeBufferLength] = {0}; |
| 132 | GUIDData* Data = reinterpret_cast<GUIDData*>(request); |
| 133 | |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 134 | if (*dataLen != sizeof(GUIDData)) // 16bytes |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 135 | { |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 136 | *dataLen = 0; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 137 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 138 | } |
| 139 | |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 140 | *dataLen = 0; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 141 | |
| 142 | snprintf( |
| 143 | buf, safeBufferLength, |
| 144 | "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", |
| 145 | Data->timeLow4, Data->timeLow3, Data->timeLow2, Data->timeLow1, |
| 146 | Data->timeMid2, Data->timeMid1, Data->timeHigh2, Data->timeHigh1, |
| 147 | Data->clock2, Data->clock1, Data->node6, Data->node5, Data->node4, |
| 148 | Data->node3, Data->node2, Data->node1); |
| 149 | // UUID is in RFC4122 format. Ex: 61a39523-78f2-11e5-9862-e6402cfc3223 |
| 150 | std::string guid = buf; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 151 | |
| 152 | std::string objpath = "/xyz/openbmc_project/control/host0/systemGUID"; |
| 153 | std::string intf = "xyz.openbmc_project.Common.UUID"; |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 154 | std::string service = getService(dbus, intf, objpath); |
| 155 | setDbusProperty(dbus, service, objpath, intf, "UUID", guid); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 156 | return IPMI_CC_OK; |
| 157 | } |
| 158 | |
| 159 | ipmi_ret_t ipmiOEMSetBIOSID(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 160 | ipmi_request_t request, ipmi_response_t response, |
| 161 | ipmi_data_len_t dataLen, ipmi_context_t context) |
| 162 | { |
| 163 | DeviceInfo* data = reinterpret_cast<DeviceInfo*>(request); |
| 164 | |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 165 | if ((*dataLen < 2) || (*dataLen != (1 + data->biosIDLength))) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 166 | { |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 167 | *dataLen = 0; |
| 168 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 169 | } |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 170 | std::string idString((char*)data->biosId, data->biosIDLength); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 171 | |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 172 | std::string service = getService(dbus, biosIntf, biosObjPath); |
| 173 | setDbusProperty(dbus, service, biosObjPath, biosIntf, biosProp, idString); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 174 | uint8_t* bytesWritten = static_cast<uint8_t*>(response); |
| 175 | *bytesWritten = |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 176 | data->biosIDLength; // how many bytes are written into storage |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 177 | *dataLen = 1; |
| 178 | return IPMI_CC_OK; |
| 179 | } |
| 180 | |
| 181 | ipmi_ret_t ipmiOEMGetDeviceInfo(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 182 | ipmi_request_t request, |
| 183 | ipmi_response_t response, |
| 184 | ipmi_data_len_t dataLen, ipmi_context_t context) |
| 185 | { |
| 186 | GetOemDeviceInfoReq* req = reinterpret_cast<GetOemDeviceInfoReq*>(request); |
| 187 | GetOemDeviceInfoRes* res = reinterpret_cast<GetOemDeviceInfoRes*>(response); |
| 188 | |
| 189 | if (*dataLen == 0) |
| 190 | { |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 191 | *dataLen = 0; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 192 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 193 | } |
| 194 | |
| 195 | size_t reqDataLen = *dataLen; |
| 196 | *dataLen = 0; |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 197 | if (req->entityType > static_cast<uint8_t>(OEMDevEntityType::sdrVer)) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 198 | { |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 199 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 200 | } |
| 201 | |
| 202 | // handle OEM command items |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 203 | switch (OEMDevEntityType(req->entityType)) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 204 | { |
| 205 | case OEMDevEntityType::biosId: |
| 206 | { |
| 207 | if (sizeof(GetOemDeviceInfoReq) != reqDataLen) |
| 208 | { |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 209 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 210 | } |
| 211 | |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 212 | std::string service = getService(dbus, biosIntf, biosObjPath); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 213 | try |
| 214 | { |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 215 | Value variant = getDbusProperty(dbus, service, biosObjPath, |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 216 | biosIntf, biosProp); |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 217 | std::string& idString = |
| 218 | sdbusplus::message::variant_ns::get<std::string>(variant); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 219 | if (req->offset >= idString.size()) |
| 220 | { |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 221 | return IPMI_CC_PARM_OUT_OF_RANGE; |
| 222 | } |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 223 | size_t length = 0; |
| 224 | if (req->countToRead > (idString.size() - req->offset)) |
| 225 | { |
| 226 | length = idString.size() - req->offset; |
| 227 | } |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 228 | else |
| 229 | { |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 230 | length = req->countToRead; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 231 | } |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 232 | std::copy(idString.begin() + req->offset, idString.end(), |
| 233 | res->data); |
| 234 | res->resDatalen = length; |
| 235 | *dataLen = res->resDatalen + 1; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 236 | } |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 237 | catch (sdbusplus::message::variant_ns::bad_variant_access& e) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 238 | { |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 239 | phosphor::logging::log<phosphor::logging::level::ERR>(e.what()); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 240 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 241 | } |
| 242 | } |
| 243 | break; |
| 244 | |
| 245 | case OEMDevEntityType::devVer: |
| 246 | case OEMDevEntityType::sdrVer: |
| 247 | // TODO: |
| 248 | return IPMI_CC_ILLEGAL_COMMAND; |
| 249 | default: |
| 250 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 251 | } |
| 252 | return IPMI_CC_OK; |
| 253 | } |
| 254 | |
| 255 | ipmi_ret_t ipmiOEMGetAICFRU(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 256 | ipmi_request_t request, ipmi_response_t response, |
| 257 | ipmi_data_len_t dataLen, ipmi_context_t context) |
| 258 | { |
| 259 | if (*dataLen != 0) |
| 260 | { |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 261 | *dataLen = 0; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 262 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 263 | } |
| 264 | |
| 265 | *dataLen = 1; |
| 266 | uint8_t* res = reinterpret_cast<uint8_t*>(response); |
| 267 | // temporary fix. We don't support AIC FRU now. Just tell BIOS that no |
| 268 | // AIC is available so that BIOS will not timeout repeatly which leads to |
| 269 | // slow booting. |
| 270 | *res = 0; // Byte1=Count of SlotPosition/FruID records. |
| 271 | return IPMI_CC_OK; |
| 272 | } |
| 273 | |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 274 | ipmi_ret_t ipmiOEMGetPowerRestoreDelay(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 275 | ipmi_request_t request, |
| 276 | ipmi_response_t response, |
| 277 | ipmi_data_len_t dataLen, |
| 278 | ipmi_context_t context) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 279 | { |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 280 | GetPowerRestoreDelayRes* resp = |
| 281 | reinterpret_cast<GetPowerRestoreDelayRes*>(response); |
| 282 | |
| 283 | if (*dataLen != 0) |
| 284 | { |
| 285 | *dataLen = 0; |
| 286 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 287 | } |
| 288 | |
| 289 | std::string service = |
| 290 | getService(dbus, powerRestoreDelayIntf, powerRestoreDelayObjPath); |
| 291 | Value variant = |
| 292 | getDbusProperty(dbus, service, powerRestoreDelayObjPath, |
| 293 | powerRestoreDelayIntf, powerRestoreDelayProp); |
| 294 | |
| 295 | uint16_t delay = sdbusplus::message::variant_ns::get<uint16_t>(variant); |
| 296 | resp->byteLSB = delay; |
| 297 | resp->byteMSB = delay >> 8; |
| 298 | |
| 299 | *dataLen = sizeof(GetPowerRestoreDelayRes); |
| 300 | |
| 301 | return IPMI_CC_OK; |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 302 | } |
| 303 | |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 304 | ipmi_ret_t ipmiOEMSetPowerRestoreDelay(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 305 | ipmi_request_t request, |
| 306 | ipmi_response_t response, |
| 307 | ipmi_data_len_t dataLen, |
| 308 | ipmi_context_t context) |
| 309 | { |
| 310 | SetPowerRestoreDelayReq* data = |
| 311 | reinterpret_cast<SetPowerRestoreDelayReq*>(request); |
| 312 | uint16_t delay = 0; |
| 313 | |
| 314 | if (*dataLen != sizeof(SetPowerRestoreDelayReq)) |
| 315 | { |
| 316 | *dataLen = 0; |
| 317 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 318 | } |
| 319 | delay = data->byteMSB; |
| 320 | delay = (delay << 8) | data->byteLSB; |
| 321 | std::string service = |
| 322 | getService(dbus, powerRestoreDelayIntf, powerRestoreDelayObjPath); |
| 323 | setDbusProperty(dbus, service, powerRestoreDelayObjPath, |
| 324 | powerRestoreDelayIntf, powerRestoreDelayProp, delay); |
| 325 | *dataLen = 0; |
| 326 | |
| 327 | return IPMI_CC_OK; |
| 328 | } |
| 329 | |
| 330 | ipmi_ret_t ipmiOEMGetProcessorErrConfig(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 331 | ipmi_request_t request, |
| 332 | ipmi_response_t response, |
| 333 | ipmi_data_len_t dataLen, |
| 334 | ipmi_context_t context) |
| 335 | { |
| 336 | GetProcessorErrConfigRes* resp = |
| 337 | reinterpret_cast<GetProcessorErrConfigRes*>(response); |
| 338 | |
| 339 | if (*dataLen != 0) |
| 340 | { |
| 341 | *dataLen = 0; |
| 342 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 343 | } |
| 344 | |
| 345 | std::string service = |
| 346 | getService(dbus, processorErrConfigIntf, processorErrConfigObjPath); |
| 347 | Value variant = getDbusProperty(dbus, service, processorErrConfigObjPath, |
| 348 | processorErrConfigIntf, "ResetCfg"); |
| 349 | resp->resetCfg = sdbusplus::message::variant_ns::get<uint8_t>(variant); |
| 350 | |
| 351 | std::vector<uint8_t> caterrStatus; |
| 352 | |
| 353 | auto method = |
| 354 | dbus.new_method_call(service.c_str(), processorErrConfigObjPath, |
| 355 | "org.freedesktop.DBus.Properties", "Get"); |
| 356 | |
| 357 | method.append(processorErrConfigIntf, "CATERRStatus"); |
| 358 | |
| 359 | try |
| 360 | { |
| 361 | auto reply = dbus.call(method); |
| 362 | reply.read(caterrStatus); |
| 363 | } |
| 364 | catch (sdbusplus::exception_t&) |
| 365 | { |
| 366 | phosphor::logging::log<phosphor::logging::level::DEBUG>( |
| 367 | "ipmiOEMGetProcessorErrConfig: error on dbus", |
| 368 | phosphor::logging::entry("PRORPERTY=CATERRStatus"), |
| 369 | phosphor::logging::entry("PATH=%s", processorErrConfigObjPath), |
| 370 | phosphor::logging::entry("INTERFACE=%s", processorErrConfigIntf)); |
| 371 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 372 | } |
| 373 | |
| 374 | size_t len = |
| 375 | maxCPUNum <= caterrStatus.size() ? maxCPUNum : caterrStatus.size(); |
| 376 | caterrStatus.resize(len); |
| 377 | std::copy(caterrStatus.begin(), caterrStatus.end(), resp->caterrStatus); |
| 378 | *dataLen = sizeof(GetProcessorErrConfigRes); |
| 379 | |
| 380 | return IPMI_CC_OK; |
| 381 | } |
| 382 | |
| 383 | ipmi_ret_t ipmiOEMSetProcessorErrConfig(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 384 | ipmi_request_t request, |
| 385 | ipmi_response_t response, |
| 386 | ipmi_data_len_t dataLen, |
| 387 | ipmi_context_t context) |
| 388 | { |
| 389 | SetProcessorErrConfigReq* req = |
| 390 | reinterpret_cast<SetProcessorErrConfigReq*>(request); |
| 391 | |
| 392 | if (*dataLen != sizeof(SetProcessorErrConfigReq)) |
| 393 | { |
| 394 | *dataLen = 0; |
| 395 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 396 | } |
| 397 | std::string service = |
| 398 | getService(dbus, processorErrConfigIntf, processorErrConfigObjPath); |
| 399 | setDbusProperty(dbus, service, processorErrConfigObjPath, |
| 400 | processorErrConfigIntf, "ResetCfg", req->resetCfg); |
| 401 | |
| 402 | setDbusProperty(dbus, service, processorErrConfigObjPath, |
| 403 | processorErrConfigIntf, "ResetErrorOccurrenceCounts", |
| 404 | req->resetErrorOccurrenceCounts); |
| 405 | *dataLen = 0; |
| 406 | |
| 407 | return IPMI_CC_OK; |
| 408 | } |
| 409 | |
| 410 | static void registerOEMFunctions(void) |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 411 | { |
| 412 | phosphor::logging::log<phosphor::logging::level::INFO>( |
| 413 | "Registering OEM commands"); |
Jason M. Bills | 6479604 | 2018-10-03 16:51:55 -0700 | [diff] [blame^] | 414 | ipmiPrintAndRegister(netfnIntcOEMGeneral, IPMI_CMD_WILDCARD, NULL, |
| 415 | ipmiOEMWildcard, |
| 416 | PRIVILEGE_USER); // wildcard default handler |
| 417 | ipmiPrintAndRegister(netfunIntelAppOEM, IPMI_CMD_WILDCARD, NULL, |
| 418 | ipmiOEMWildcard, |
| 419 | PRIVILEGE_USER); // wildcard default handler |
| 420 | ipmiPrintAndRegister( |
| 421 | netfnIntcOEMGeneral, |
| 422 | static_cast<ipmi_cmd_t>( |
| 423 | IPMINetfnIntelOEMGeneralCmd::cmdGetChassisIdentifier), |
| 424 | NULL, ipmiOEMGetChassisIdentifier, |
| 425 | PRIVILEGE_USER); // get chassis identifier |
| 426 | ipmiPrintAndRegister( |
| 427 | netfnIntcOEMGeneral, |
| 428 | static_cast<ipmi_cmd_t>(IPMINetfnIntelOEMGeneralCmd::cmdSetSystemGUID), |
| 429 | NULL, ipmiOEMSetSystemGUID, |
| 430 | PRIVILEGE_ADMIN); // set system guid |
| 431 | ipmiPrintAndRegister( |
| 432 | netfnIntcOEMGeneral, |
| 433 | static_cast<ipmi_cmd_t>(IPMINetfnIntelOEMGeneralCmd::cmdSetBIOSID), |
| 434 | NULL, ipmiOEMSetBIOSID, PRIVILEGE_ADMIN); |
| 435 | ipmiPrintAndRegister(netfnIntcOEMGeneral, |
| 436 | static_cast<ipmi_cmd_t>( |
| 437 | IPMINetfnIntelOEMGeneralCmd::cmdGetOEMDeviceInfo), |
| 438 | NULL, ipmiOEMGetDeviceInfo, PRIVILEGE_USER); |
| 439 | ipmiPrintAndRegister( |
| 440 | netfnIntcOEMGeneral, |
| 441 | static_cast<ipmi_cmd_t>( |
| 442 | IPMINetfnIntelOEMGeneralCmd::cmdGetAICSlotFRUIDSlotPosRecords), |
| 443 | NULL, ipmiOEMGetAICFRU, PRIVILEGE_USER); |
| 444 | ipmiPrintAndRegister( |
| 445 | netfnIntcOEMGeneral, |
| 446 | static_cast<ipmi_cmd_t>( |
| 447 | IPMINetfnIntelOEMGeneralCmd::cmdSetPowerRestoreDelay), |
| 448 | NULL, ipmiOEMSetPowerRestoreDelay, PRIVILEGE_OPERATOR); |
| 449 | ipmiPrintAndRegister( |
| 450 | netfnIntcOEMGeneral, |
| 451 | static_cast<ipmi_cmd_t>( |
| 452 | IPMINetfnIntelOEMGeneralCmd::cmdGetPowerRestoreDelay), |
| 453 | NULL, ipmiOEMGetPowerRestoreDelay, PRIVILEGE_USER); |
| 454 | ipmiPrintAndRegister( |
| 455 | netfnIntcOEMGeneral, |
| 456 | static_cast<ipmi_cmd_t>( |
| 457 | IPMINetfnIntelOEMGeneralCmd::cmdGetProcessorErrConfig), |
| 458 | NULL, ipmiOEMGetProcessorErrConfig, PRIVILEGE_USER); |
| 459 | ipmiPrintAndRegister( |
| 460 | netfnIntcOEMGeneral, |
| 461 | static_cast<ipmi_cmd_t>( |
| 462 | IPMINetfnIntelOEMGeneralCmd::cmdSetProcessorErrConfig), |
| 463 | NULL, ipmiOEMSetProcessorErrConfig, PRIVILEGE_ADMIN); |
Jia, Chunhui | a835eaa | 2018-09-05 09:00:41 +0800 | [diff] [blame] | 464 | return; |
| 465 | } |
| 466 | |
| 467 | } // namespace ipmi |