Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 1 | #include <vector> |
| 2 | #include <stdlib.h> |
| 3 | #include <dlfcn.h> |
| 4 | #include <errno.h> |
| 5 | #include <stdio.h> |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 6 | #include <systemd/sd-bus.h> |
Chris Austen | b45c4cb | 2015-11-01 06:34:56 -0600 | [diff] [blame] | 7 | #include <unistd.h> |
vishwa | 13555bd | 2015-11-10 12:10:38 -0600 | [diff] [blame] | 8 | #include <host-ipmid/ipmid-api.h> |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 9 | #include <iostream> |
| 10 | #include <memory> |
| 11 | #include <algorithm> |
| 12 | #include <fstream> |
Yi Li | 75c2d46 | 2016-04-11 16:57:46 +0800 | [diff] [blame] | 13 | #include <sstream> |
Brad Bishop | de6a379 | 2016-07-25 17:09:12 -0400 | [diff] [blame] | 14 | #include <mapper.h> |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 15 | #include "frup.h" |
| 16 | #include "fru-area.H" |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 17 | |
| 18 | // OpenBMC System Manager dbus framework |
vishwa | 13555bd | 2015-11-10 12:10:38 -0600 | [diff] [blame] | 19 | const char *sys_object_name = "/org/openbmc/managers/System"; |
| 20 | const char *sys_intf_name = "org.openbmc.managers.System"; |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 21 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 22 | //---------------------------------------------------------------- |
| 23 | // Constructor |
| 24 | //---------------------------------------------------------------- |
| 25 | ipmi_fru::ipmi_fru(const uint8_t fruid, const ipmi_fru_area_type type, |
| 26 | sd_bus *bus_type, bool bmc_fru) |
| 27 | { |
| 28 | iv_fruid = fruid; |
| 29 | iv_type = type; |
| 30 | iv_bmc_fru = bmc_fru; |
| 31 | iv_bus_type = bus_type; |
| 32 | iv_valid = false; |
| 33 | iv_data = NULL; |
| 34 | iv_present = false; |
| 35 | |
| 36 | if(iv_type == IPMI_FRU_AREA_INTERNAL_USE) |
| 37 | { |
| 38 | iv_name = "INTERNAL_"; |
| 39 | } |
| 40 | else if(iv_type == IPMI_FRU_AREA_CHASSIS_INFO) |
| 41 | { |
| 42 | iv_name = "CHASSIS_"; |
| 43 | } |
| 44 | else if(iv_type == IPMI_FRU_AREA_BOARD_INFO) |
| 45 | { |
| 46 | iv_name = "BOARD_"; |
| 47 | } |
| 48 | else if(iv_type == IPMI_FRU_AREA_PRODUCT_INFO) |
| 49 | { |
| 50 | iv_name = "PRODUCT_"; |
| 51 | } |
| 52 | else if(iv_type == IPMI_FRU_AREA_MULTI_RECORD) |
| 53 | { |
| 54 | iv_name = "MULTI_"; |
| 55 | } |
| 56 | else |
| 57 | { |
| 58 | iv_name = IPMI_FRU_AREA_TYPE_MAX; |
| 59 | fprintf(stderr, "ERROR: Invalid Area type :[%d]\n",iv_type); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | //----------------------------------------------------- |
| 64 | // For a FRU area type, accepts the data and updates |
| 65 | // area specific data. |
| 66 | //----------------------------------------------------- |
| 67 | void ipmi_fru::set_data(const uint8_t *data, const size_t len) |
| 68 | { |
| 69 | iv_len = len; |
| 70 | iv_data = new uint8_t[len]; |
| 71 | memcpy(iv_data, data, len); |
| 72 | } |
| 73 | |
| 74 | //----------------------------------------------------- |
| 75 | // Sets the dbus parameters |
| 76 | //----------------------------------------------------- |
| 77 | void ipmi_fru::update_dbus_paths(const char *bus_name, |
| 78 | const char *obj_path, const char *intf_name) |
| 79 | { |
| 80 | iv_bus_name = bus_name; |
| 81 | iv_obj_path = obj_path; |
| 82 | iv_intf_name = intf_name; |
| 83 | } |
| 84 | |
| 85 | //------------------- |
| 86 | // Destructor |
| 87 | //------------------- |
| 88 | ipmi_fru::~ipmi_fru() |
| 89 | { |
| 90 | sd_bus_error bus_error = SD_BUS_ERROR_NULL; |
| 91 | sd_bus_message *response = NULL; |
| 92 | int rc = 0; |
| 93 | |
| 94 | if(iv_data != NULL) |
| 95 | { |
| 96 | delete [] iv_data; |
| 97 | iv_data = NULL; |
| 98 | } |
| 99 | |
| 100 | // If we have not been successful in doing some updates and we are a BMC |
| 101 | // fru, then need to set the fault bits. |
| 102 | bool valid_dbus = !(iv_bus_name.empty()) && |
| 103 | !(iv_obj_path.empty()) && |
| 104 | !(iv_intf_name.empty()); |
| 105 | |
| 106 | // Based on bmc_fru, success in updating the FRU inventory we need to set |
| 107 | // some special bits. |
| 108 | if(iv_bmc_fru && valid_dbus) |
| 109 | { |
| 110 | // Set the Fault bit if we did not successfully process the fru |
| 111 | const char *fault_bit = iv_valid ? "False" : "True"; |
| 112 | |
| 113 | rc = sd_bus_call_method(iv_bus_type, // On the System Bus |
| 114 | iv_bus_name.c_str(), // Service to contact |
| 115 | iv_obj_path.c_str(), // Object path |
| 116 | iv_intf_name.c_str(), // Interface name |
| 117 | "setFault", // Method to be called |
| 118 | &bus_error, // object to return error |
| 119 | &response, // Response message on success |
| 120 | "s", // input message (string) |
| 121 | fault_bit); // First argument to setFault |
| 122 | |
| 123 | if(rc <0) |
| 124 | { |
| 125 | fprintf(stderr,"Failed to set Fault bit, value:[%s] for fruid:[%d], path:[%s]\n", |
| 126 | fault_bit, iv_fruid, iv_obj_path.c_str()); |
| 127 | } |
| 128 | else |
| 129 | { |
| 130 | printf("Fault bit set to :[%s] for fruid:[%d], Path:[%s]\n", |
| 131 | fault_bit, iv_fruid,iv_obj_path.c_str()); |
| 132 | } |
| 133 | |
| 134 | sd_bus_error_free(&bus_error); |
| 135 | sd_bus_message_unref(response); |
| 136 | |
| 137 | // Set the Present bits |
| 138 | const char *present_bit = iv_present ? "True" : "False"; |
| 139 | |
| 140 | rc = sd_bus_call_method(iv_bus_type, // On the System Bus |
| 141 | iv_bus_name.c_str(), // Service to contact |
| 142 | iv_obj_path.c_str(), // Object path |
| 143 | iv_intf_name.c_str(), // Interface name |
| 144 | "setPresent", // Method to be called |
| 145 | &bus_error, // object to return error |
| 146 | &response, // Response message on success |
| 147 | "s", // input message (string) |
| 148 | present_bit); // First argument to setPresent |
| 149 | if(rc < 0) |
| 150 | { |
| 151 | fprintf(stderr,"Failed to set Present bit for fruid:[%d], path:[%s]\n", |
| 152 | iv_fruid, iv_obj_path.c_str()); |
| 153 | } |
| 154 | else |
| 155 | { |
Yi Li | 75c2d46 | 2016-04-11 16:57:46 +0800 | [diff] [blame] | 156 | printf("Present bit set to :[%s] for fruid:[%d], Path[%s]:\n", |
| 157 | present_bit, iv_fruid, iv_obj_path.c_str()); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | sd_bus_error_free(&bus_error); |
| 161 | sd_bus_message_unref(response); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | // Sets up the sd_bus structures for the given fru type |
| 166 | int ipmi_fru::setup_sd_bus_paths(void) |
| 167 | { |
| 168 | // Need this to get respective DBUS objects |
| 169 | sd_bus_error bus_error = SD_BUS_ERROR_NULL; |
| 170 | sd_bus_message *response = NULL; |
| 171 | int rc = 0; |
| 172 | |
| 173 | // What we need is BOARD_1, PRODUCT_1, CHASSIS_1 etc.. |
Patrick Williams | 804077d | 2016-07-29 15:26:18 -0500 | [diff] [blame^] | 174 | const char *inv_bus_name = NULL, *inv_obj_path = NULL, |
| 175 | *inv_intf_name = NULL; |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 176 | char fru_area_name[16] = {0}; |
Brad Bishop | de6a379 | 2016-07-25 17:09:12 -0400 | [diff] [blame] | 177 | char *sys_bus_name = NULL; |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 178 | sprintf(fru_area_name,"%s%d",iv_name.c_str(), iv_fruid); |
| 179 | |
| 180 | #ifdef __IPMI_DEBUG__ |
| 181 | printf("Getting sd_bus for :[%s]\n",fru_area_name); |
| 182 | #endif |
| 183 | |
Brad Bishop | de6a379 | 2016-07-25 17:09:12 -0400 | [diff] [blame] | 184 | rc = mapper_get_service(iv_bus_type, sys_object_name, &sys_bus_name); |
| 185 | if(rc < 0) |
| 186 | { |
| 187 | fprintf(stderr, "Failed to get system manager service:[%s]\n", |
| 188 | strerror(-rc)); |
| 189 | goto exit; |
| 190 | } |
| 191 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 192 | // We want to call a method "getObjectFromId" on System Bus that is |
| 193 | // made available over OpenBmc system services. |
Yi Li | 75c2d46 | 2016-04-11 16:57:46 +0800 | [diff] [blame] | 194 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 195 | rc = sd_bus_call_method(iv_bus_type, // On the System Bus |
| 196 | sys_bus_name, // Service to contact |
| 197 | sys_object_name, // Object path |
| 198 | sys_intf_name, // Interface name |
| 199 | "getObjectFromId", // Method to be called |
| 200 | &bus_error, // object to return error |
| 201 | &response, // Response message on success |
| 202 | "ss", // input message (string,string) |
| 203 | "FRU_STR", // First argument to getObjectFromId |
| 204 | fru_area_name); // Second Argument |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 205 | if(rc < 0) |
| 206 | { |
| 207 | fprintf(stderr, "Failed to resolve fruid:[%d] to dbus: [%s]\n", iv_fruid, bus_error.message); |
| 208 | } |
| 209 | else |
| 210 | { |
Brad Bishop | de6a379 | 2016-07-25 17:09:12 -0400 | [diff] [blame] | 211 | // Method getObjectFromId returns 2 parameters and all are strings, namely |
| 212 | // object_path and interface name for accessing that particular |
| 213 | // FRU over Inventory SDBUS manager. 'ss' here mentions that format. |
| 214 | rc = sd_bus_message_read(response, "(ss)", &inv_obj_path, &inv_intf_name); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 215 | if(rc < 0) |
| 216 | { |
| 217 | fprintf(stderr, "Failed to parse response message:[%s]\n", strerror(-rc)); |
| 218 | } |
| 219 | else |
| 220 | { |
Brad Bishop | de6a379 | 2016-07-25 17:09:12 -0400 | [diff] [blame] | 221 | rc = mapper_get_service(iv_bus_type, inv_obj_path, &inv_bus_name); |
| 222 | if(rc < 0) |
| 223 | { |
| 224 | fprintf(stderr, "Failed to get inventory item service:[%s]\n", |
| 225 | strerror(-rc)); |
| 226 | goto exit; |
| 227 | } |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 228 | // Update the paths in the area object |
| 229 | update_dbus_paths(inv_bus_name, inv_obj_path, inv_intf_name); |
| 230 | } |
| 231 | } |
| 232 | |
Brad Bishop | de6a379 | 2016-07-25 17:09:12 -0400 | [diff] [blame] | 233 | exit: |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 234 | #ifdef __IPMI_DEBUG__ |
| 235 | printf("fru_area=[%s], inv_bus_name=[%s], inv_obj_path=[%s], inv_intf_name=[%s]\n", |
| 236 | fru_area_name, inv_bus_name, inv_obj_path, inv_intf_name); |
| 237 | #endif |
| 238 | |
Brad Bishop | de6a379 | 2016-07-25 17:09:12 -0400 | [diff] [blame] | 239 | free(sys_bus_name); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 240 | sd_bus_error_free(&bus_error); |
| 241 | sd_bus_message_unref(response); |
| 242 | |
| 243 | return rc; |
| 244 | } |
| 245 | |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 246 | //------------------------------------------------ |
vishwa | f3ca352 | 2015-12-02 10:35:13 -0600 | [diff] [blame] | 247 | // Takes the pointer to stream of bytes and length |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 248 | // and returns the 8 bit checksum |
| 249 | // This algo is per IPMI V2.0 spec |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 250 | //------------------------------------------------- |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 251 | unsigned char calculate_crc(const unsigned char *data, size_t len) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 252 | { |
| 253 | char crc = 0; |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 254 | size_t byte = 0; |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 255 | |
| 256 | for(byte = 0; byte < len; byte++) |
| 257 | { |
| 258 | crc += *data++; |
| 259 | } |
vishwa | f3ca352 | 2015-12-02 10:35:13 -0600 | [diff] [blame] | 260 | |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 261 | return(-crc); |
| 262 | } |
| 263 | |
| 264 | //--------------------------------------------------------------------- |
| 265 | // Accepts a fru area offset in commom hdr and tells which area it is. |
| 266 | //--------------------------------------------------------------------- |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 267 | ipmi_fru_area_type get_fru_area_type(uint8_t area_offset) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 268 | { |
| 269 | ipmi_fru_area_type type = IPMI_FRU_AREA_TYPE_MAX; |
| 270 | |
| 271 | switch(area_offset) |
| 272 | { |
| 273 | case IPMI_FRU_INTERNAL_OFFSET: |
| 274 | type = IPMI_FRU_AREA_INTERNAL_USE; |
| 275 | break; |
| 276 | |
| 277 | case IPMI_FRU_CHASSIS_OFFSET: |
| 278 | type = IPMI_FRU_AREA_CHASSIS_INFO; |
| 279 | break; |
| 280 | |
| 281 | case IPMI_FRU_BOARD_OFFSET: |
| 282 | type = IPMI_FRU_AREA_BOARD_INFO; |
| 283 | break; |
| 284 | |
| 285 | case IPMI_FRU_PRODUCT_OFFSET: |
| 286 | type = IPMI_FRU_AREA_PRODUCT_INFO; |
| 287 | break; |
| 288 | |
| 289 | case IPMI_FRU_MULTI_OFFSET: |
| 290 | type = IPMI_FRU_AREA_MULTI_RECORD; |
| 291 | break; |
| 292 | |
| 293 | default: |
| 294 | type = IPMI_FRU_AREA_TYPE_MAX; |
| 295 | } |
| 296 | |
| 297 | return type; |
| 298 | } |
| 299 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 300 | ///----------------------------------------------- |
| 301 | // Validates the data for crc and mandatory fields |
| 302 | ///----------------------------------------------- |
| 303 | int verify_fru_data(const uint8_t *data, const size_t len) |
| 304 | { |
| 305 | uint8_t checksum = 0; |
| 306 | int rc = -1; |
| 307 | |
| 308 | // Validate for first byte to always have a value of [1] |
| 309 | if(data[0] != IPMI_FRU_HDR_BYTE_ZERO) |
| 310 | { |
| 311 | fprintf(stderr, "Invalid entry:[%d] in byte-0\n",data[0]); |
| 312 | return rc; |
| 313 | } |
| 314 | #ifdef __IPMI_DEBUG__ |
| 315 | else |
| 316 | { |
| 317 | printf("SUCCESS: Validated [0x%X] in entry_1 of fru_data\n",data[0]); |
| 318 | } |
| 319 | #endif |
| 320 | |
| 321 | // See if the calculated CRC matches with the embedded one. |
| 322 | // CRC to be calculated on all except the last one that is CRC itself. |
| 323 | checksum = calculate_crc(data, len - 1); |
| 324 | if(checksum != data[len-1]) |
| 325 | { |
| 326 | #ifdef __IPMI_DEBUG__ |
| 327 | fprintf(stderr, "Checksum mismatch." |
| 328 | " Calculated:[0x%X], Embedded:[0x%X]\n", |
| 329 | checksum, data[len]); |
| 330 | #endif |
| 331 | return rc; |
| 332 | } |
| 333 | #ifdef __IPMI_DEBUG__ |
| 334 | else |
| 335 | { |
| 336 | printf("SUCCESS: Checksum matches:[0x%X]\n",checksum); |
| 337 | } |
| 338 | #endif |
| 339 | |
| 340 | return EXIT_SUCCESS; |
| 341 | } |
| 342 | |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 343 | //------------------------------------------------------------------------ |
| 344 | // Takes FRU data, invokes Parser for each fru record area and updates |
| 345 | // Inventory |
| 346 | //------------------------------------------------------------------------ |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 347 | int ipmi_update_inventory(fru_area_vec_t & area_vec) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 348 | { |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 349 | // Generic error reporter |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 350 | int rc = 0; |
vishwa | f3ca352 | 2015-12-02 10:35:13 -0600 | [diff] [blame] | 351 | |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 352 | // Dictionary object to hold Name:Value pair |
| 353 | sd_bus_message *fru_dict = NULL; |
| 354 | |
| 355 | // SD Bus error report mechanism. |
| 356 | sd_bus_error bus_error = SD_BUS_ERROR_NULL; |
| 357 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 358 | // Response from sd bus calls |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 359 | sd_bus_message *response = NULL; |
| 360 | |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 361 | // For each FRU area, extract the needed data , get it parsed and update |
| 362 | // the Inventory. |
| 363 | for(auto& iter : area_vec) |
| 364 | { |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 365 | // Start fresh on each. |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 366 | sd_bus_error_free(&bus_error); |
| 367 | sd_bus_message_unref(response); |
| 368 | sd_bus_message_unref(fru_dict); |
vishwa | f3ca352 | 2015-12-02 10:35:13 -0600 | [diff] [blame] | 369 | |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 370 | // Constructor to allow further initializations and customization. |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 371 | rc = sd_bus_message_new_method_call((iter)->get_bus_type(), |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 372 | &fru_dict, |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 373 | (iter)->get_bus_name(), |
| 374 | (iter)->get_obj_path(), |
| 375 | (iter)->get_intf_name(), |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 376 | "update"); |
| 377 | if(rc < 0) |
| 378 | { |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 379 | fprintf(stderr,"ERROR: creating a update method call for bus_name:[%s]\n", |
| 380 | (iter)->get_bus_name()); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 381 | break; |
| 382 | } |
| 383 | |
| 384 | // A Dictionary ({}) having (string, variant) |
| 385 | rc = sd_bus_message_open_container(fru_dict, 'a', "{sv}"); |
| 386 | if(rc < 0) |
| 387 | { |
| 388 | fprintf(stderr,"ERROR:[%d] creating a dict container:\n",errno); |
| 389 | break; |
| 390 | } |
| 391 | |
| 392 | // Fill the container with information |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 393 | rc = parse_fru_area((iter)->get_type(), (void *)(iter)->get_data(), (iter)->get_len(), fru_dict); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 394 | if(rc < 0) |
| 395 | { |
| 396 | fprintf(stderr,"ERROR parsing FRU records\n"); |
| 397 | break; |
| 398 | } |
| 399 | |
| 400 | sd_bus_message_close_container(fru_dict); |
| 401 | |
| 402 | // Now, Make the actual call to update the FRU inventory database with the |
| 403 | // dictionary given by FRU Parser. There is no response message expected for |
| 404 | // this. |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 405 | rc = sd_bus_call((iter)->get_bus_type(), // On the System Bus |
| 406 | fru_dict, // With the Name:value dictionary array |
| 407 | 0, // |
| 408 | &bus_error, // Object to return error. |
| 409 | &response); // Response message if any. |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 410 | |
| 411 | if(rc < 0) |
| 412 | { |
| 413 | fprintf(stderr, "ERROR:[%s] updating FRU inventory for ID:[0x%X]\n", |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 414 | bus_error.message, (iter)->get_fruid()); |
| 415 | break; |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 416 | } |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 417 | else if((iter)->is_bmc_fru()) |
vishwa | f3ca352 | 2015-12-02 10:35:13 -0600 | [diff] [blame] | 418 | { |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 419 | // For FRUs that are accessible by HostBoot, host boot does all of |
| 420 | // these. |
| 421 | printf("SUCCESS: Updated:[%s_%d] successfully. Setting Valid bit\n", |
| 422 | (iter)->get_name(), (iter)->get_fruid()); |
vishwa | f3ca352 | 2015-12-02 10:35:13 -0600 | [diff] [blame] | 423 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 424 | (iter)->set_valid(true); |
vishwa | f3ca352 | 2015-12-02 10:35:13 -0600 | [diff] [blame] | 425 | } |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 426 | else |
| 427 | { |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 428 | printf("SUCCESS: Updated:[%s_%d] successfully\n", |
| 429 | (iter)->get_name(), (iter)->get_fruid()); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 430 | } |
| 431 | } // END walking the vector of areas and updating |
| 432 | |
| 433 | sd_bus_error_free(&bus_error); |
| 434 | sd_bus_message_unref(response); |
| 435 | sd_bus_message_unref(fru_dict); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 436 | |
| 437 | return rc; |
| 438 | } |
| 439 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 440 | ///---------------------------------------------------- |
| 441 | // Checks if a particular fru area is populated or not |
| 442 | ///---------------------------------------------------- |
| 443 | bool remove_invalid_area(const std::unique_ptr<ipmi_fru> &fru_area) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 444 | { |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 445 | // Filter the ones that do not have dbus reference. |
| 446 | if((strlen((fru_area)->get_bus_name()) == 0) || |
| 447 | (strlen((fru_area)->get_obj_path()) == 0) || |
| 448 | (strlen((fru_area)->get_intf_name()) == 0)) |
| 449 | { |
| 450 | return true; |
| 451 | } |
| 452 | return false; |
| 453 | } |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 454 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 455 | ///---------------------------------------------------------------------------------- |
| 456 | // Populates various FRU areas |
| 457 | // @prereq : This must be called only after validating common header. |
| 458 | ///---------------------------------------------------------------------------------- |
| 459 | int ipmi_populate_fru_areas(uint8_t *fru_data, const size_t data_len, |
| 460 | fru_area_vec_t & fru_area_vec) |
| 461 | { |
vishwa | 13555bd | 2015-11-10 12:10:38 -0600 | [diff] [blame] | 462 | size_t area_offset = 0; |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 463 | int rc = -1; |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 464 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 465 | // Now walk the common header and see if the file size has atleast the last |
| 466 | // offset mentioned by the common_hdr. If the file size is less than the |
| 467 | // offset of any if the fru areas mentioned in the common header, then we do |
| 468 | // not have a complete file. |
| 469 | for(uint8_t fru_entry = IPMI_FRU_INTERNAL_OFFSET; |
| 470 | fru_entry < (sizeof(struct common_header) -2); fru_entry++) |
| 471 | { |
Yi Li | 75c2d46 | 2016-04-11 16:57:46 +0800 | [diff] [blame] | 472 | rc = -1; |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 473 | // Actual offset in the payload is the offset mentioned in common header |
| 474 | // multipled by 8. Common header is always the first 8 bytes. |
| 475 | area_offset = fru_data[fru_entry] * IPMI_EIGHT_BYTES; |
| 476 | if(area_offset && (data_len < (area_offset + 2))) |
| 477 | { |
| 478 | // Our file size is less than what it needs to be. +2 because we are |
| 479 | // using area len that is at 2 byte off area_offset |
| 480 | fprintf(stderr, "fru file is incomplete. Size:[%d]\n",data_len); |
| 481 | return rc; |
| 482 | } |
| 483 | else if(area_offset) |
| 484 | { |
| 485 | // Read 2 bytes to know the actual size of area. |
| 486 | uint8_t area_hdr[2] = {0}; |
| 487 | memcpy(area_hdr, &((uint8_t *)fru_data)[area_offset], sizeof(area_hdr)); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 488 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 489 | // Size of this area will be the 2nd byte in the fru area header. |
| 490 | size_t area_len = area_hdr[1] * IPMI_EIGHT_BYTES; |
| 491 | uint8_t area_data[area_len] = {0}; |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 492 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 493 | printf("fru data size:[%d], area offset:[%d], area_size:[%d]\n", |
| 494 | data_len, area_offset, area_len); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 495 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 496 | // See if we really have that much buffer. We have area offset amd |
| 497 | // from there, the actual len. |
| 498 | if(data_len < (area_len + area_offset)) |
| 499 | { |
| 500 | fprintf(stderr, "Incomplete Fru file.. Size:[%d]\n",data_len); |
| 501 | return rc; |
| 502 | } |
| 503 | |
| 504 | // Save off the data. |
| 505 | memcpy(area_data, &((uint8_t *)fru_data)[area_offset], area_len); |
| 506 | |
| 507 | // Validate the crc |
| 508 | rc = verify_fru_data(area_data, area_len); |
| 509 | if(rc < 0) |
| 510 | { |
| 511 | fprintf(stderr, "Error validating fru area. offset:[%d]\n",area_offset); |
| 512 | return rc; |
| 513 | } |
| 514 | else |
| 515 | { |
| 516 | printf("Successfully verified area checksum. offset:[%d]\n",area_offset); |
| 517 | } |
| 518 | |
| 519 | // We already have a vector that is passed to us containing all |
| 520 | // of the fields populated. Update the data portion now. |
| 521 | for(auto& iter : fru_area_vec) |
| 522 | { |
| 523 | if((iter)->get_type() == get_fru_area_type(fru_entry)) |
| 524 | { |
| 525 | (iter)->set_data(area_data, area_len); |
| 526 | } |
| 527 | } |
| 528 | } // If we have fru data present |
| 529 | } // Walk common_hdr |
| 530 | |
| 531 | // Not all the fields will be populated in a fru data. Mostly all cases will |
| 532 | // not have more than 2 or 3. |
| 533 | fru_area_vec.erase(std::remove_if(fru_area_vec.begin(), fru_area_vec.end(), |
| 534 | remove_invalid_area), fru_area_vec.end()); |
| 535 | |
| 536 | return EXIT_SUCCESS; |
| 537 | } |
| 538 | |
| 539 | ///--------------------------------------------------------- |
| 540 | // Validates the fru data per ipmi common header constructs. |
| 541 | // Returns with updated common_hdr and also file_size |
| 542 | //---------------------------------------------------------- |
| 543 | int ipmi_validate_common_hdr(const uint8_t *fru_data, const size_t data_len) |
| 544 | { |
| 545 | int rc = -1; |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 546 | |
| 547 | uint8_t common_hdr[sizeof(struct common_header)] = {0}; |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 548 | if(data_len >= sizeof(common_hdr)) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 549 | { |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 550 | memcpy(common_hdr, fru_data, sizeof(common_hdr)); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 551 | } |
| 552 | else |
| 553 | { |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 554 | fprintf(stderr, "Incomplete fru data file. Size:[%d]\n", data_len); |
| 555 | return rc; |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 556 | } |
| 557 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 558 | // Verify the crc and size |
| 559 | rc = verify_fru_data(common_hdr, sizeof(common_hdr)); |
| 560 | if(rc < 0) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 561 | { |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 562 | fprintf(stderr, "Failed to validate common header\n"); |
| 563 | return rc; |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 564 | } |
| 565 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 566 | return EXIT_SUCCESS; |
| 567 | } |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 568 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 569 | //------------------------------------------------------------ |
| 570 | // Cleanup routine |
| 571 | //------------------------------------------------------------ |
| 572 | int cleanup_error(FILE *fru_fp, fru_area_vec_t & fru_area_vec) |
| 573 | { |
| 574 | if(fru_fp != NULL) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 575 | { |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 576 | fclose(fru_fp); |
| 577 | fru_fp = NULL; |
| 578 | } |
vishwa | f3ca352 | 2015-12-02 10:35:13 -0600 | [diff] [blame] | 579 | |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 580 | if(!(fru_area_vec.empty())) |
| 581 | { |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 582 | fru_area_vec.clear(); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 583 | } |
vishwa | f3ca352 | 2015-12-02 10:35:13 -0600 | [diff] [blame] | 584 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 585 | return -1; |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 586 | } |
| 587 | |
Yi Li | 75c2d46 | 2016-04-11 16:57:46 +0800 | [diff] [blame] | 588 | |
| 589 | ///----------------------------------------------------- |
| 590 | // Get the fru area names defined in BMC for a given @fruid. |
| 591 | //---------------------------------------------------- |
| 592 | int get_defined_fru_area(sd_bus *bus_type, const uint8_t fruid, |
| 593 | std::vector<std::string> &defined_fru_area) |
| 594 | { |
| 595 | // Need this to get respective DBUS objects |
| 596 | sd_bus_error bus_error = SD_BUS_ERROR_NULL; |
| 597 | sd_bus_message *response = NULL; |
| 598 | int rc = 0; |
Patrick Williams | 804077d | 2016-07-29 15:26:18 -0500 | [diff] [blame^] | 599 | const char *areas = NULL; |
Brad Bishop | de6a379 | 2016-07-25 17:09:12 -0400 | [diff] [blame] | 600 | char *sys_bus_name = NULL; |
Yi Li | 75c2d46 | 2016-04-11 16:57:46 +0800 | [diff] [blame] | 601 | |
| 602 | #ifdef __IPMI_DEBUG__ |
| 603 | printf("Getting fru areas defined in Skeleton for :[%d]\n", fruid); |
| 604 | #endif |
| 605 | |
Brad Bishop | de6a379 | 2016-07-25 17:09:12 -0400 | [diff] [blame] | 606 | rc = mapper_get_service(bus_type, sys_object_name, &sys_bus_name); |
| 607 | if(rc < 0) |
| 608 | { |
| 609 | fprintf(stderr, "Failed to get system manager service:[%s]\n", |
| 610 | strerror(-rc)); |
| 611 | goto exit; |
| 612 | } |
| 613 | |
Yi Li | 75c2d46 | 2016-04-11 16:57:46 +0800 | [diff] [blame] | 614 | // We want to call a method "getFRUArea" on System Bus that is |
| 615 | // made available over OpenBmc system services. |
| 616 | rc = sd_bus_call_method(bus_type, // On the System Bus |
| 617 | sys_bus_name, // Service to contact |
| 618 | sys_object_name, // Object path |
| 619 | sys_intf_name, // Interface name |
| 620 | "getFRUArea", // Method to be called |
| 621 | &bus_error, // object to return error |
| 622 | &response, // Response message on success |
| 623 | "y", // input message (integer) |
| 624 | fruid); // Argument |
| 625 | |
| 626 | if(rc < 0) |
| 627 | { |
| 628 | fprintf(stderr, "Failed to get fru area for fruid:[%d] to dbus: [%s]\n", |
| 629 | fruid, bus_error.message); |
| 630 | } |
| 631 | else |
| 632 | { |
| 633 | // if several fru area names are defined, the names are combined to |
| 634 | // a string seperated by ',' |
| 635 | rc = sd_bus_message_read(response, "s", &areas); |
| 636 | if(rc < 0) |
| 637 | { |
| 638 | fprintf(stderr, "Failed to parse response message from getFRUArea:[%s]\n", |
| 639 | strerror(-rc)); |
| 640 | } |
| 641 | else |
| 642 | { |
| 643 | #ifdef __IPMI_DEBUG__ |
| 644 | printf("get defined fru area: id: %d, areas: %s\n", fruid, areas); |
| 645 | #endif |
| 646 | std::string area_name; |
| 647 | std::stringstream ss(areas); |
| 648 | // fru area names string is seperated by ',', parse it into tokens |
| 649 | while (std::getline(ss, area_name, ',')) |
| 650 | { |
| 651 | if (!area_name.empty()) |
| 652 | defined_fru_area.emplace_back(area_name); |
| 653 | } |
| 654 | } |
| 655 | } |
| 656 | |
Brad Bishop | de6a379 | 2016-07-25 17:09:12 -0400 | [diff] [blame] | 657 | exit: |
| 658 | |
| 659 | free(sys_bus_name); |
Yi Li | 75c2d46 | 2016-04-11 16:57:46 +0800 | [diff] [blame] | 660 | sd_bus_error_free(&bus_error); |
| 661 | sd_bus_message_unref(response); |
| 662 | |
| 663 | return rc; |
| 664 | } |
| 665 | |
| 666 | |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 667 | ///----------------------------------------------------- |
| 668 | // Accepts the filename and validates per IPMI FRU spec |
| 669 | //---------------------------------------------------- |
vishwa | f3ca352 | 2015-12-02 10:35:13 -0600 | [diff] [blame] | 670 | int ipmi_validate_fru_area(const uint8_t fruid, const char *fru_file_name, |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 671 | sd_bus *bus_type, const bool bmc_fru) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 672 | { |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 673 | size_t data_len = 0; |
| 674 | size_t bytes_read = 0; |
| 675 | int rc = -1; |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 676 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 677 | // Vector that holds individual IPMI FRU AREAs. Although MULTI and INTERNAL |
| 678 | // are not used, keeping it here for completeness. |
| 679 | fru_area_vec_t fru_area_vec; |
Yi Li | 75c2d46 | 2016-04-11 16:57:46 +0800 | [diff] [blame] | 680 | std::vector<std::string> defined_fru_area; |
| 681 | |
| 682 | // BMC defines fru areas that should be present in Skeleton |
| 683 | rc = get_defined_fru_area(bus_type, fruid, defined_fru_area); |
| 684 | if(rc < 0) |
| 685 | { |
| 686 | fprintf(stderr, "ERROR: cannot get defined fru area\n"); |
| 687 | return rc; |
| 688 | } |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 689 | for(uint8_t fru_entry = IPMI_FRU_INTERNAL_OFFSET; |
| 690 | fru_entry < (sizeof(struct common_header) -2); fru_entry++) |
| 691 | { |
| 692 | // Create an object and push onto a vector. |
| 693 | std::unique_ptr<ipmi_fru> fru_area = std::make_unique<ipmi_fru> |
| 694 | (fruid, get_fru_area_type(fru_entry), bus_type, bmc_fru); |
| 695 | |
| 696 | // Physically being present |
vishwa | 2f5a3cf | 2016-05-30 02:25:21 -0500 | [diff] [blame] | 697 | bool present = access(fru_file_name, F_OK) == 0; |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 698 | fru_area->set_present(present); |
| 699 | |
Yi Li | 75c2d46 | 2016-04-11 16:57:46 +0800 | [diff] [blame] | 700 | // Only setup dbus path for areas defined in BMC. |
| 701 | // Otherwise Skeleton will report 'not found' error |
| 702 | std::string fru_area_name = fru_area->get_name() + std::to_string(fruid); |
| 703 | auto iter = std::find(defined_fru_area.begin(), defined_fru_area.end(), |
| 704 | fru_area_name); |
| 705 | if (iter != defined_fru_area.end()) |
| 706 | { |
| 707 | fru_area->setup_sd_bus_paths(); |
| 708 | } |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 709 | fru_area_vec.emplace_back(std::move(fru_area)); |
| 710 | } |
| 711 | |
| 712 | FILE *fru_fp = fopen(fru_file_name,"rb"); |
| 713 | if(fru_fp == NULL) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 714 | { |
| 715 | fprintf(stderr, "ERROR: opening:[%s]\n",fru_file_name); |
| 716 | perror("Error:"); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 717 | return cleanup_error(fru_fp, fru_area_vec); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 718 | } |
| 719 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 720 | // Get the size of the file to see if it meets minimum requirement |
| 721 | if(fseek(fru_fp, 0, SEEK_END)) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 722 | { |
| 723 | perror("Error:"); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 724 | return cleanup_error(fru_fp, fru_area_vec); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 725 | } |
| 726 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 727 | // Allocate a buffer to hold entire file content |
| 728 | data_len = ftell(fru_fp); |
| 729 | uint8_t fru_data[data_len] = {0}; |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 730 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 731 | rewind(fru_fp); |
| 732 | bytes_read = fread(fru_data, data_len, 1, fru_fp); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 733 | if(bytes_read != 1) |
| 734 | { |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 735 | fprintf(stderr, "Failed reading fru data. Bytes_read=[%d]\n",bytes_read); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 736 | perror("Error:"); |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 737 | return cleanup_error(fru_fp, fru_area_vec); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 738 | } |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 739 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 740 | // We are done reading. |
| 741 | fclose(fru_fp); |
| 742 | fru_fp = NULL; |
| 743 | |
| 744 | rc = ipmi_validate_common_hdr(fru_data, data_len); |
vishwa | f3ca352 | 2015-12-02 10:35:13 -0600 | [diff] [blame] | 745 | if(rc < 0) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 746 | { |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 747 | return cleanup_error(fru_fp, fru_area_vec); |
| 748 | } |
| 749 | |
| 750 | // Now that we validated the common header, populate various fru sections if we have them here. |
| 751 | rc = ipmi_populate_fru_areas(fru_data, data_len, fru_area_vec); |
| 752 | if(rc < 0) |
| 753 | { |
| 754 | fprintf(stderr,"Populating FRU areas failed for:[%d]\n",fruid); |
| 755 | return cleanup_error(fru_fp, fru_area_vec); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 756 | } |
| 757 | else |
| 758 | { |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 759 | printf("SUCCESS: Populated FRU areas for:[%s]\n",fru_file_name); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 760 | } |
| 761 | |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 762 | #ifdef __IPMI_DEBUG__ |
| 763 | for(auto& iter : fru_area_vec) |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 764 | { |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 765 | printf("FRU ID : [%d]\n",(iter)->get_fruid()); |
| 766 | printf("AREA NAME : [%s]\n",(iter)->get_name()); |
| 767 | printf("TYPE : [%d]\n",(iter)->get_type()); |
| 768 | printf("LEN : [%d]\n",(iter)->get_len()); |
| 769 | printf("BUS NAME : [%s]\n", (iter)->get_bus_name()); |
| 770 | printf("OBJ PATH : [%s]\n", (iter)->get_obj_path()); |
| 771 | printf("INTF NAME :[%s]\n", (iter)->get_intf_name()); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 772 | } |
vishwa | c93d6d4 | 2015-12-16 11:55:16 -0600 | [diff] [blame] | 773 | #endif |
| 774 | |
| 775 | // If the vector is populated with everything, then go ahead and update the |
| 776 | // inventory. |
| 777 | if(!(fru_area_vec.empty())) |
| 778 | { |
| 779 | |
| 780 | #ifdef __IPMI_DEBUG__ |
| 781 | printf("\n SIZE of vector is : [%d] \n",fru_area_vec.size()); |
| 782 | #endif |
| 783 | rc = ipmi_update_inventory(fru_area_vec); |
| 784 | if(rc <0) |
| 785 | { |
| 786 | fprintf(stderr, "Error updating inventory\n"); |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | // we are done with all that we wanted to do. This will do the job of |
| 791 | // calling any destructors too. |
| 792 | fru_area_vec.clear(); |
Vishwa | 4be4b7a | 2015-10-31 22:55:50 -0500 | [diff] [blame] | 793 | |
| 794 | return rc; |
| 795 | } |