Patrick Venture | 02ba884 | 2018-10-20 13:37:54 -0700 | [diff] [blame^] | 1 | #include "writefrudata.hpp" |
| 2 | |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 3 | #include "fru-area.hpp" |
| 4 | #include "frup.hpp" |
| 5 | #include "types.hpp" |
| 6 | |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 7 | #include <dlfcn.h> |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 8 | #include <host-ipmid/ipmid-api.h> |
| 9 | #include <mapper.h> |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 10 | #include <systemd/sd-bus.h> |
Chris Austen | b45c4cb | 2015-11-01 06:34:56 -0600 | [diff] [blame] | 11 | #include <unistd.h> |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 12 | |
| 13 | #include <algorithm> |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 14 | #include <cstdio> |
| 15 | #include <cstring> |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 16 | #include <exception> |
| 17 | #include <fstream> |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 18 | #include <iostream> |
Patrick Venture | b390c0e | 2018-10-20 13:36:48 -0700 | [diff] [blame] | 19 | #include <map> |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 20 | #include <memory> |
Patrick Venture | 5739ac3 | 2018-10-16 19:17:41 -0700 | [diff] [blame] | 21 | #include <phosphor-logging/log.hpp> |
Ratan Gupta | 0b77cfa | 2017-01-31 17:32:31 +0530 | [diff] [blame] | 22 | #include <sdbusplus/server.hpp> |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 23 | #include <sstream> |
| 24 | #include <vector> |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 25 | |
Deepak Kodihalli | 788bd1f | 2017-02-20 01:21:59 -0600 | [diff] [blame] | 26 | using namespace ipmi::vpd; |
Patrick Venture | 5739ac3 | 2018-10-16 19:17:41 -0700 | [diff] [blame] | 27 | using namespace phosphor::logging; |
Deepak Kodihalli | 788bd1f | 2017-02-20 01:21:59 -0600 | [diff] [blame] | 28 | |
Ratan Gupta | cb0d4e5 | 2016-12-22 19:05:57 +0530 | [diff] [blame] | 29 | extern const FruMap frus; |
Deepak Kodihalli | 788bd1f | 2017-02-20 01:21:59 -0600 | [diff] [blame] | 30 | extern const std::map<Path, InterfaceMap> extras; |
Ratan Gupta | cb0d4e5 | 2016-12-22 19:05:57 +0530 | [diff] [blame] | 31 | |
Patrick Venture | 234b735 | 2018-10-20 09:37:09 -0700 | [diff] [blame] | 32 | namespace |
| 33 | { |
| 34 | |
| 35 | //------------------------------------------------------------ |
| 36 | // Cleanup routine |
| 37 | // Must always be called as last reference to fru_fp. |
| 38 | //------------------------------------------------------------ |
| 39 | int cleanupError(FILE* fru_fp, fru_area_vec_t& fru_area_vec) |
| 40 | { |
| 41 | if (fru_fp != NULL) |
| 42 | { |
| 43 | std::fclose(fru_fp); |
| 44 | } |
| 45 | |
| 46 | if (!(fru_area_vec.empty())) |
| 47 | { |
| 48 | fru_area_vec.clear(); |
| 49 | } |
| 50 | |
| 51 | return -1; |
| 52 | } |
| 53 | |
Patrick Venture | de8ea56 | 2018-10-20 09:44:19 -0700 | [diff] [blame] | 54 | //------------------------------------------------------------------------ |
| 55 | // Gets the value of the key from the fru dictionary of the given section. |
| 56 | // FRU dictionary is parsed fru data for all the sections. |
| 57 | //------------------------------------------------------------------------ |
| 58 | std::string getFRUValue(const std::string& section, const std::string& key, |
| 59 | const std::string& delimiter, IPMIFruInfo& fruData) |
| 60 | { |
| 61 | |
| 62 | auto minIndexValue = 0; |
| 63 | auto maxIndexValue = 0; |
| 64 | std::string fruValue = ""; |
| 65 | |
| 66 | if (section == "Board") |
| 67 | { |
| 68 | minIndexValue = OPENBMC_VPD_KEY_BOARD_MFG_DATE; |
| 69 | maxIndexValue = OPENBMC_VPD_KEY_BOARD_MAX; |
| 70 | } |
| 71 | else if (section == "Product") |
| 72 | { |
| 73 | minIndexValue = OPENBMC_VPD_KEY_PRODUCT_MFR; |
| 74 | maxIndexValue = OPENBMC_VPD_KEY_PRODUCT_MAX; |
| 75 | } |
| 76 | else if (section == "Chassis") |
| 77 | { |
| 78 | minIndexValue = OPENBMC_VPD_KEY_CHASSIS_TYPE; |
| 79 | maxIndexValue = OPENBMC_VPD_KEY_CHASSIS_MAX; |
| 80 | } |
| 81 | |
| 82 | auto first = fruData.cbegin() + minIndexValue; |
| 83 | auto last = first + (maxIndexValue - minIndexValue) + 1; |
| 84 | |
| 85 | auto itr = |
| 86 | std::find_if(first, last, [&key](auto& e) { return key == e.first; }); |
| 87 | |
| 88 | if (itr != last) |
| 89 | { |
| 90 | fruValue = itr->second; |
| 91 | } |
| 92 | |
| 93 | // if the key is custom property then the value could be in two formats. |
| 94 | // 1) custom field 2 = "value". |
| 95 | // 2) custom field 2 = "key:value". |
| 96 | // if delimiter length = 0 i.e custom field 2 = "value" |
| 97 | |
| 98 | constexpr auto customProp = "Custom Field"; |
| 99 | if (key.find(customProp) != std::string::npos) |
| 100 | { |
| 101 | if (delimiter.length() > 0) |
| 102 | { |
| 103 | size_t delimiterpos = fruValue.find(delimiter); |
| 104 | if (delimiterpos != std::string::npos) |
| 105 | fruValue = fruValue.substr(delimiterpos + 1); |
| 106 | } |
| 107 | } |
| 108 | return fruValue; |
| 109 | } |
| 110 | |
Patrick Venture | 17baa27 | 2018-10-20 09:48:08 -0700 | [diff] [blame] | 111 | // Get the inventory service from the mapper. |
| 112 | auto getService(sdbusplus::bus::bus& bus, const std::string& intf, |
| 113 | const std::string& path) |
| 114 | { |
| 115 | auto mapperCall = |
| 116 | bus.new_method_call("xyz.openbmc_project.ObjectMapper", |
| 117 | "/xyz/openbmc_project/object_mapper", |
| 118 | "xyz.openbmc_project.ObjectMapper", "GetObject"); |
| 119 | |
| 120 | mapperCall.append(path); |
| 121 | mapperCall.append(std::vector<std::string>({intf})); |
| 122 | std::map<std::string, std::vector<std::string>> mapperResponse; |
| 123 | |
| 124 | try |
| 125 | { |
| 126 | auto mapperResponseMsg = bus.call(mapperCall); |
| 127 | mapperResponseMsg.read(mapperResponse); |
| 128 | } |
| 129 | catch (const sdbusplus::exception::SdBusError& ex) |
| 130 | { |
| 131 | log<level::ERR>("Exception from sdbus call", |
| 132 | entry("WHAT=%s", ex.what())); |
| 133 | throw; |
| 134 | } |
| 135 | |
| 136 | if (mapperResponse.begin() == mapperResponse.end()) |
| 137 | { |
| 138 | throw std::runtime_error("ERROR in reading the mapper response"); |
| 139 | } |
| 140 | |
| 141 | return mapperResponse.begin()->first; |
| 142 | } |
| 143 | |
Patrick Venture | 44a957d | 2018-10-20 09:41:29 -0700 | [diff] [blame] | 144 | // Takes FRU data, invokes Parser for each fru record area and updates |
| 145 | // Inventory |
| 146 | //------------------------------------------------------------------------ |
| 147 | int updateInventory(fru_area_vec_t& area_vec, sd_bus* bus_sd) |
| 148 | { |
| 149 | // Generic error reporter |
| 150 | int rc = 0; |
| 151 | uint8_t fruid = 0; |
| 152 | IPMIFruInfo fruData; |
| 153 | |
| 154 | // For each FRU area, extract the needed data , get it parsed and update |
| 155 | // the Inventory. |
| 156 | for (const auto& fruArea : area_vec) |
| 157 | { |
| 158 | fruid = fruArea->get_fruid(); |
| 159 | // Fill the container with information |
| 160 | rc = parse_fru_area((fruArea)->get_type(), (void*)(fruArea)->get_data(), |
| 161 | (fruArea)->get_len(), fruData); |
| 162 | if (rc < 0) |
| 163 | { |
| 164 | log<level::ERR>("Error parsing FRU records"); |
| 165 | return rc; |
| 166 | } |
| 167 | } // END walking the vector of areas and updating |
| 168 | |
| 169 | // For each Fru we have the list of instances which needs to be updated. |
| 170 | // Each instance object implements certain interfaces. |
| 171 | // Each Interface is having Dbus properties. |
| 172 | // Each Dbus Property would be having metaData(eg section,VpdPropertyName). |
| 173 | |
| 174 | // Here we are just printing the object,interface and the properties. |
| 175 | // which needs to be called with the new inventory manager implementation. |
| 176 | sdbusplus::bus::bus bus{bus_sd}; |
| 177 | using namespace std::string_literals; |
| 178 | static const auto intf = "xyz.openbmc_project.Inventory.Manager"s; |
| 179 | static const auto path = "/xyz/openbmc_project/inventory"s; |
| 180 | std::string service; |
| 181 | try |
| 182 | { |
| 183 | service = getService(bus, intf, path); |
| 184 | } |
| 185 | catch (const std::exception& e) |
| 186 | { |
| 187 | std::cerr << e.what() << "\n"; |
| 188 | return -1; |
| 189 | } |
| 190 | |
| 191 | auto iter = frus.find(fruid); |
| 192 | if (iter == frus.end()) |
| 193 | { |
| 194 | log<level::ERR>("Unable to get the fru info", |
| 195 | entry("FRU=%d", static_cast<int>(fruid))); |
| 196 | return -1; |
| 197 | } |
| 198 | |
| 199 | auto& instanceList = iter->second; |
| 200 | if (instanceList.size() <= 0) |
| 201 | { |
| 202 | log<level::DEBUG>("Object list empty for this FRU", |
| 203 | entry("FRU=%d", static_cast<int>(fruid))); |
| 204 | } |
| 205 | |
| 206 | ObjectMap objects; |
| 207 | for (auto& instance : instanceList) |
| 208 | { |
| 209 | InterfaceMap interfaces; |
| 210 | const auto& extrasIter = extras.find(instance.path); |
| 211 | |
| 212 | for (auto& interfaceList : instance.interfaces) |
| 213 | { |
| 214 | PropertyMap props; // store all the properties |
| 215 | for (auto& properties : interfaceList.second) |
| 216 | { |
| 217 | std::string value; |
| 218 | decltype(auto) pdata = properties.second; |
| 219 | |
| 220 | if (!pdata.section.empty() && !pdata.property.empty()) |
| 221 | { |
| 222 | value = getFRUValue(pdata.section, pdata.property, |
| 223 | pdata.delimiter, fruData); |
| 224 | } |
| 225 | props.emplace(std::move(properties.first), std::move(value)); |
| 226 | } |
| 227 | // Check and update extra properties |
| 228 | if (extras.end() != extrasIter) |
| 229 | { |
| 230 | const auto& propsIter = |
| 231 | (extrasIter->second).find(interfaceList.first); |
| 232 | if ((extrasIter->second).end() != propsIter) |
| 233 | { |
| 234 | for (const auto& map : propsIter->second) |
| 235 | { |
| 236 | props.emplace(map.first, map.second); |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | interfaces.emplace(std::move(interfaceList.first), |
| 241 | std::move(props)); |
| 242 | } |
| 243 | |
| 244 | // Call the inventory manager |
Patrick Venture | 9a528f2 | 2018-10-20 13:31:28 -0700 | [diff] [blame] | 245 | sdbusplus::message::object_path objectPath = instance.path; |
Patrick Venture | 44a957d | 2018-10-20 09:41:29 -0700 | [diff] [blame] | 246 | // Check and update extra properties |
| 247 | if (extras.end() != extrasIter) |
| 248 | { |
| 249 | for (const auto& entry : extrasIter->second) |
| 250 | { |
| 251 | if (interfaces.end() == interfaces.find(entry.first)) |
| 252 | { |
| 253 | interfaces.emplace(entry.first, entry.second); |
| 254 | } |
| 255 | } |
| 256 | } |
Patrick Venture | 9a528f2 | 2018-10-20 13:31:28 -0700 | [diff] [blame] | 257 | objects.emplace(objectPath, interfaces); |
Patrick Venture | 44a957d | 2018-10-20 09:41:29 -0700 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | auto pimMsg = bus.new_method_call(service.c_str(), path.c_str(), |
| 261 | intf.c_str(), "Notify"); |
| 262 | pimMsg.append(std::move(objects)); |
| 263 | |
| 264 | try |
| 265 | { |
| 266 | auto inventoryMgrResponseMsg = bus.call(pimMsg); |
| 267 | } |
| 268 | catch (const sdbusplus::exception::SdBusError& ex) |
| 269 | { |
| 270 | log<level::ERR>("Error in notify call", entry("WHAT=%s", ex.what())); |
| 271 | return -1; |
| 272 | } |
| 273 | |
| 274 | return rc; |
| 275 | } |
| 276 | |
Patrick Venture | 234b735 | 2018-10-20 09:37:09 -0700 | [diff] [blame] | 277 | } // namespace |
| 278 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 279 | //---------------------------------------------------------------- |
| 280 | // Constructor |
| 281 | //---------------------------------------------------------------- |
| 282 | ipmi_fru::ipmi_fru(const uint8_t fruid, const ipmi_fru_area_type type, |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 283 | sd_bus* bus_type, bool bmc_fru) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 284 | { |
| 285 | iv_fruid = fruid; |
| 286 | iv_type = type; |
| 287 | iv_bmc_fru = bmc_fru; |
| 288 | iv_bus_type = bus_type; |
| 289 | iv_valid = false; |
| 290 | iv_data = NULL; |
| 291 | iv_present = false; |
| 292 | |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 293 | if (iv_type == IPMI_FRU_AREA_INTERNAL_USE) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 294 | { |
| 295 | iv_name = "INTERNAL_"; |
| 296 | } |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 297 | else if (iv_type == IPMI_FRU_AREA_CHASSIS_INFO) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 298 | { |
| 299 | iv_name = "CHASSIS_"; |
| 300 | } |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 301 | else if (iv_type == IPMI_FRU_AREA_BOARD_INFO) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 302 | { |
| 303 | iv_name = "BOARD_"; |
| 304 | } |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 305 | else if (iv_type == IPMI_FRU_AREA_PRODUCT_INFO) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 306 | { |
| 307 | iv_name = "PRODUCT_"; |
| 308 | } |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 309 | else if (iv_type == IPMI_FRU_AREA_MULTI_RECORD) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 310 | { |
| 311 | iv_name = "MULTI_"; |
| 312 | } |
| 313 | else |
| 314 | { |
| 315 | iv_name = IPMI_FRU_AREA_TYPE_MAX; |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 316 | log<level::ERR>("Invalid Area", entry("TYPE=%d", iv_type)); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | |
| 320 | //----------------------------------------------------- |
| 321 | // For a FRU area type, accepts the data and updates |
| 322 | // area specific data. |
| 323 | //----------------------------------------------------- |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 324 | void ipmi_fru::set_data(const uint8_t* data, const size_t len) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 325 | { |
| 326 | iv_len = len; |
| 327 | iv_data = new uint8_t[len]; |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 328 | std::memcpy(iv_data, data, len); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | //----------------------------------------------------- |
| 332 | // Sets the dbus parameters |
| 333 | //----------------------------------------------------- |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 334 | void ipmi_fru::update_dbus_paths(const char* bus_name, const char* obj_path, |
| 335 | const char* intf_name) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 336 | { |
| 337 | iv_bus_name = bus_name; |
| 338 | iv_obj_path = obj_path; |
| 339 | iv_intf_name = intf_name; |
| 340 | } |
| 341 | |
| 342 | //------------------- |
| 343 | // Destructor |
| 344 | //------------------- |
| 345 | ipmi_fru::~ipmi_fru() |
| 346 | { |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 347 | if (iv_data != NULL) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 348 | { |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 349 | delete[] iv_data; |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 350 | iv_data = NULL; |
| 351 | } |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 352 | } |
| 353 | |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 354 | //------------------------------------------------ |
vishwa | f3ca352 | 2015-12-02 10:35:13 -0600 | [diff] [blame] | 355 | // Takes the pointer to stream of bytes and length |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 356 | // and returns the 8 bit checksum |
| 357 | // This algo is per IPMI V2.0 spec |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 358 | //------------------------------------------------- |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 359 | unsigned char calculate_crc(const unsigned char* data, size_t len) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 360 | { |
| 361 | char crc = 0; |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 362 | size_t byte = 0; |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 363 | |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 364 | for (byte = 0; byte < len; byte++) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 365 | { |
| 366 | crc += *data++; |
| 367 | } |
vishwa | f3ca352 | 2015-12-02 10:35:13 -0600 | [diff] [blame] | 368 | |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 369 | return (-crc); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | //--------------------------------------------------------------------- |
| 373 | // Accepts a fru area offset in commom hdr and tells which area it is. |
| 374 | //--------------------------------------------------------------------- |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 375 | ipmi_fru_area_type get_fru_area_type(uint8_t area_offset) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 376 | { |
| 377 | ipmi_fru_area_type type = IPMI_FRU_AREA_TYPE_MAX; |
| 378 | |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 379 | switch (area_offset) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 380 | { |
| 381 | case IPMI_FRU_INTERNAL_OFFSET: |
| 382 | type = IPMI_FRU_AREA_INTERNAL_USE; |
| 383 | break; |
| 384 | |
| 385 | case IPMI_FRU_CHASSIS_OFFSET: |
| 386 | type = IPMI_FRU_AREA_CHASSIS_INFO; |
| 387 | break; |
| 388 | |
| 389 | case IPMI_FRU_BOARD_OFFSET: |
| 390 | type = IPMI_FRU_AREA_BOARD_INFO; |
| 391 | break; |
| 392 | |
| 393 | case IPMI_FRU_PRODUCT_OFFSET: |
| 394 | type = IPMI_FRU_AREA_PRODUCT_INFO; |
| 395 | break; |
| 396 | |
| 397 | case IPMI_FRU_MULTI_OFFSET: |
| 398 | type = IPMI_FRU_AREA_MULTI_RECORD; |
| 399 | break; |
| 400 | |
| 401 | default: |
| 402 | type = IPMI_FRU_AREA_TYPE_MAX; |
| 403 | } |
| 404 | |
| 405 | return type; |
| 406 | } |
| 407 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 408 | ///----------------------------------------------- |
| 409 | // Validates the data for crc and mandatory fields |
| 410 | ///----------------------------------------------- |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 411 | int verify_fru_data(const uint8_t* data, const size_t len) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 412 | { |
| 413 | uint8_t checksum = 0; |
| 414 | int rc = -1; |
| 415 | |
| 416 | // Validate for first byte to always have a value of [1] |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 417 | if (data[0] != IPMI_FRU_HDR_BYTE_ZERO) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 418 | { |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 419 | log<level::ERR>("Invalid entry in byte-0", |
| 420 | entry("ENTRY=0x%X", static_cast<uint32_t>(data[0]))); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 421 | return rc; |
| 422 | } |
| 423 | #ifdef __IPMI_DEBUG__ |
| 424 | else |
| 425 | { |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 426 | log<level::DEBUG>("Validated in entry_1 of fru_data", |
| 427 | entry("ENTRY=0x%X", static_cast<uint32_t>(data[0]))); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 428 | } |
| 429 | #endif |
| 430 | |
| 431 | // See if the calculated CRC matches with the embedded one. |
| 432 | // CRC to be calculated on all except the last one that is CRC itself. |
| 433 | checksum = calculate_crc(data, len - 1); |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 434 | if (checksum != data[len - 1]) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 435 | { |
| 436 | #ifdef __IPMI_DEBUG__ |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 437 | log<level::ERR>( |
| 438 | "Checksum mismatch", |
| 439 | entry("Calculated=0x%X", static_cast<uint32_t>(checksum)), |
| 440 | entry("Embedded=0x%X", static_cast<uint32_t>(data[len]))); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 441 | #endif |
| 442 | return rc; |
| 443 | } |
| 444 | #ifdef __IPMI_DEBUG__ |
| 445 | else |
| 446 | { |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 447 | log<level::DEBUG>("Checksum matches"); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 448 | } |
| 449 | #endif |
| 450 | |
| 451 | return EXIT_SUCCESS; |
| 452 | } |
| 453 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 454 | ///---------------------------------------------------- |
| 455 | // Checks if a particular fru area is populated or not |
| 456 | ///---------------------------------------------------- |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 457 | bool remove_invalid_area(const std::unique_ptr<ipmi_fru>& fru_area) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 458 | { |
Deepak Kodihalli | 89ededd | 2017-02-11 01:59:32 -0600 | [diff] [blame] | 459 | // Filter the ones that are empty |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 460 | if (!(fru_area->get_len())) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 461 | { |
| 462 | return true; |
| 463 | } |
| 464 | return false; |
| 465 | } |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 466 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 467 | ///---------------------------------------------------------------------------------- |
| 468 | // Populates various FRU areas |
| 469 | // @prereq : This must be called only after validating common header. |
| 470 | ///---------------------------------------------------------------------------------- |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 471 | int ipmi_populate_fru_areas(uint8_t* fru_data, const size_t data_len, |
| 472 | fru_area_vec_t& fru_area_vec) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 473 | { |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 474 | int rc = -1; |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 475 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 476 | // Now walk the common header and see if the file size has atleast the last |
| 477 | // offset mentioned by the common_hdr. If the file size is less than the |
| 478 | // offset of any if the fru areas mentioned in the common header, then we do |
| 479 | // not have a complete file. |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 480 | for (uint8_t fru_entry = IPMI_FRU_INTERNAL_OFFSET; |
| 481 | fru_entry < (sizeof(struct common_header) - 2); fru_entry++) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 482 | { |
Yi Li | 75c2d46 | 2016-04-11 16:57:46 +0800 | [diff] [blame] | 483 | rc = -1; |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 484 | // Actual offset in the payload is the offset mentioned in common header |
Gunnar Mills | c19b813 | 2018-06-14 08:56:17 -0500 | [diff] [blame] | 485 | // multiplied by 8. Common header is always the first 8 bytes. |
Patrick Venture | 50ddfe5 | 2018-10-16 17:16:32 -0700 | [diff] [blame] | 486 | size_t area_offset = fru_data[fru_entry] * IPMI_EIGHT_BYTES; |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 487 | if (area_offset && (data_len < (area_offset + 2))) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 488 | { |
| 489 | // Our file size is less than what it needs to be. +2 because we are |
| 490 | // using area len that is at 2 byte off area_offset |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 491 | log<level::ERR>("fru file is incomplete", |
| 492 | entry("SIZE=%d", data_len)); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 493 | return rc; |
| 494 | } |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 495 | else if (area_offset) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 496 | { |
| 497 | // Read 2 bytes to know the actual size of area. |
| 498 | uint8_t area_hdr[2] = {0}; |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 499 | std::memcpy(area_hdr, &((uint8_t*)fru_data)[area_offset], |
| 500 | sizeof(area_hdr)); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 501 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 502 | // Size of this area will be the 2nd byte in the fru area header. |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 503 | size_t area_len = area_hdr[1] * IPMI_EIGHT_BYTES; |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 504 | uint8_t area_data[area_len] = {0}; |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 505 | |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 506 | log<level::DEBUG>("Fru Data", entry("SIZE=%d", data_len), |
| 507 | entry("AREA OFFSET=%d", area_offset), |
| 508 | entry("AREA_SIZE=%d", area_len)); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 509 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 510 | // See if we really have that much buffer. We have area offset amd |
| 511 | // from there, the actual len. |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 512 | if (data_len < (area_len + area_offset)) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 513 | { |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 514 | log<level::ERR>("Incomplete Fru file", |
| 515 | entry("SIZE=%d", data_len)); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 516 | return rc; |
| 517 | } |
| 518 | |
| 519 | // Save off the data. |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 520 | std::memcpy(area_data, &((uint8_t*)fru_data)[area_offset], |
| 521 | area_len); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 522 | |
| 523 | // Validate the crc |
| 524 | rc = verify_fru_data(area_data, area_len); |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 525 | if (rc < 0) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 526 | { |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 527 | log<level::ERR>("Err validating fru area", |
| 528 | entry("OFFSET=%d", area_offset)); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 529 | return rc; |
| 530 | } |
| 531 | else |
| 532 | { |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 533 | log<level::DEBUG>("Successfully verified area checksum.", |
| 534 | entry("OFFSET=%d", area_offset)); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | // We already have a vector that is passed to us containing all |
| 538 | // of the fields populated. Update the data portion now. |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 539 | for (auto& iter : fru_area_vec) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 540 | { |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 541 | if ((iter)->get_type() == get_fru_area_type(fru_entry)) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 542 | { |
| 543 | (iter)->set_data(area_data, area_len); |
| 544 | } |
| 545 | } |
| 546 | } // If we have fru data present |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 547 | } // Walk common_hdr |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 548 | |
| 549 | // Not all the fields will be populated in a fru data. Mostly all cases will |
| 550 | // not have more than 2 or 3. |
| 551 | fru_area_vec.erase(std::remove_if(fru_area_vec.begin(), fru_area_vec.end(), |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 552 | remove_invalid_area), |
| 553 | fru_area_vec.end()); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 554 | |
| 555 | return EXIT_SUCCESS; |
| 556 | } |
| 557 | |
| 558 | ///--------------------------------------------------------- |
| 559 | // Validates the fru data per ipmi common header constructs. |
| 560 | // Returns with updated common_hdr and also file_size |
| 561 | //---------------------------------------------------------- |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 562 | int ipmi_validate_common_hdr(const uint8_t* fru_data, const size_t data_len) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 563 | { |
| 564 | int rc = -1; |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 565 | |
| 566 | uint8_t common_hdr[sizeof(struct common_header)] = {0}; |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 567 | if (data_len >= sizeof(common_hdr)) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 568 | { |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 569 | std::memcpy(common_hdr, fru_data, sizeof(common_hdr)); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 570 | } |
| 571 | else |
| 572 | { |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 573 | log<level::ERR>("Incomplete fru data file", entry("SIZE=%d", data_len)); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 574 | return rc; |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 575 | } |
| 576 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 577 | // Verify the crc and size |
| 578 | rc = verify_fru_data(common_hdr, sizeof(common_hdr)); |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 579 | if (rc < 0) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 580 | { |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 581 | log<level::ERR>("Failed to validate common header"); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 582 | return rc; |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 583 | } |
| 584 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 585 | return EXIT_SUCCESS; |
| 586 | } |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 587 | |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 588 | ///----------------------------------------------------- |
| 589 | // Accepts the filename and validates per IPMI FRU spec |
| 590 | //---------------------------------------------------- |
Patrick Venture | 98072dc | 2018-10-20 09:31:35 -0700 | [diff] [blame] | 591 | int validateFRUArea(const uint8_t fruid, const char* fru_file_name, |
| 592 | sd_bus* bus_type, const bool bmc_fru) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 593 | { |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 594 | size_t data_len = 0; |
| 595 | size_t bytes_read = 0; |
| 596 | int rc = -1; |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 597 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 598 | // Vector that holds individual IPMI FRU AREAs. Although MULTI and INTERNAL |
| 599 | // are not used, keeping it here for completeness. |
| 600 | fru_area_vec_t fru_area_vec; |
Yi Li | 75c2d46 | 2016-04-11 16:57:46 +0800 | [diff] [blame] | 601 | |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 602 | for (uint8_t fru_entry = IPMI_FRU_INTERNAL_OFFSET; |
| 603 | fru_entry < (sizeof(struct common_header) - 2); fru_entry++) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 604 | { |
| 605 | // Create an object and push onto a vector. |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 606 | std::unique_ptr<ipmi_fru> fru_area = std::make_unique<ipmi_fru>( |
| 607 | fruid, get_fru_area_type(fru_entry), bus_type, bmc_fru); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 608 | |
| 609 | // Physically being present |
vishwa | 2f5a3cf | 2016-05-30 02:25:21 -0500 | [diff] [blame] | 610 | bool present = access(fru_file_name, F_OK) == 0; |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 611 | fru_area->set_present(present); |
| 612 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 613 | fru_area_vec.emplace_back(std::move(fru_area)); |
| 614 | } |
| 615 | |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 616 | FILE* fru_fp = std::fopen(fru_file_name, "rb"); |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 617 | if (fru_fp == NULL) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 618 | { |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 619 | log<level::ERR>("Unable to open fru file", |
| 620 | entry("FILE=%s", fru_file_name), |
| 621 | entry("ERRNO=%s", std::strerror(errno))); |
Patrick Venture | 234b735 | 2018-10-20 09:37:09 -0700 | [diff] [blame] | 622 | return cleanupError(fru_fp, fru_area_vec); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 623 | } |
| 624 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 625 | // Get the size of the file to see if it meets minimum requirement |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 626 | if (std::fseek(fru_fp, 0, SEEK_END)) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 627 | { |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 628 | log<level::ERR>("Unable to seek fru file", |
| 629 | entry("FILE=%s", fru_file_name), |
| 630 | entry("ERRNO=%s", std::strerror(errno))); |
Patrick Venture | 234b735 | 2018-10-20 09:37:09 -0700 | [diff] [blame] | 631 | return cleanupError(fru_fp, fru_area_vec); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 632 | } |
| 633 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 634 | // Allocate a buffer to hold entire file content |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 635 | data_len = std::ftell(fru_fp); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 636 | uint8_t fru_data[data_len] = {0}; |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 637 | |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 638 | std::rewind(fru_fp); |
| 639 | bytes_read = std::fread(fru_data, data_len, 1, fru_fp); |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 640 | if (bytes_read != 1) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 641 | { |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 642 | log<level::ERR>("Failed reading fru data.", |
| 643 | entry("BYTESREAD=%d", bytes_read), |
| 644 | entry("ERRNO=%s", std::strerror(errno))); |
Patrick Venture | 234b735 | 2018-10-20 09:37:09 -0700 | [diff] [blame] | 645 | return cleanupError(fru_fp, fru_area_vec); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 646 | } |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 647 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 648 | // We are done reading. |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 649 | std::fclose(fru_fp); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 650 | fru_fp = NULL; |
| 651 | |
| 652 | rc = ipmi_validate_common_hdr(fru_data, data_len); |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 653 | if (rc < 0) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 654 | { |
Patrick Venture | 234b735 | 2018-10-20 09:37:09 -0700 | [diff] [blame] | 655 | return cleanupError(fru_fp, fru_area_vec); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 656 | } |
| 657 | |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 658 | // Now that we validated the common header, populate various fru sections if |
| 659 | // we have them here. |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 660 | rc = ipmi_populate_fru_areas(fru_data, data_len, fru_area_vec); |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 661 | if (rc < 0) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 662 | { |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 663 | log<level::ERR>("Populating FRU areas failed", entry("FRU=%d", fruid)); |
Patrick Venture | 234b735 | 2018-10-20 09:37:09 -0700 | [diff] [blame] | 664 | return cleanupError(fru_fp, fru_area_vec); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 665 | } |
| 666 | else |
| 667 | { |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 668 | log<level::DEBUG>("Populated FRU areas", |
| 669 | entry("FILE=%s", fru_file_name)); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 670 | } |
| 671 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 672 | #ifdef __IPMI_DEBUG__ |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 673 | for (auto& iter : fru_area_vec) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 674 | { |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 675 | std::printf("FRU ID : [%d]\n", (iter)->get_fruid()); |
| 676 | std::printf("AREA NAME : [%s]\n", (iter)->get_name()); |
| 677 | std::printf("TYPE : [%d]\n", (iter)->get_type()); |
| 678 | std::printf("LEN : [%d]\n", (iter)->get_len()); |
| 679 | std::printf("BUS NAME : [%s]\n", (iter)->get_bus_name()); |
| 680 | std::printf("OBJ PATH : [%s]\n", (iter)->get_obj_path()); |
| 681 | std::printf("INTF NAME :[%s]\n", (iter)->get_intf_name()); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 682 | } |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 683 | #endif |
| 684 | |
| 685 | // If the vector is populated with everything, then go ahead and update the |
| 686 | // inventory. |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 687 | if (!(fru_area_vec.empty())) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 688 | { |
| 689 | |
| 690 | #ifdef __IPMI_DEBUG__ |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 691 | std::printf("\n SIZE of vector is : [%d] \n", fru_area_vec.size()); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 692 | #endif |
Patrick Venture | 44a957d | 2018-10-20 09:41:29 -0700 | [diff] [blame] | 693 | rc = updateInventory(fru_area_vec, bus_type); |
Patrick Venture | c9508db | 2018-10-16 17:18:43 -0700 | [diff] [blame] | 694 | if (rc < 0) |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 695 | { |
Patrick Venture | 5c78721 | 2018-10-17 13:48:23 -0700 | [diff] [blame] | 696 | log<level::ERR>("Error updating inventory."); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 697 | } |
| 698 | } |
| 699 | |
| 700 | // we are done with all that we wanted to do. This will do the job of |
| 701 | // calling any destructors too. |
| 702 | fru_area_vec.clear(); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 703 | |
| 704 | return rc; |
| 705 | } |