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