set present status True after updating inventory
diff --git a/writefrudata.C b/writefrudata.C
index ae0d1eb..9b52da2 100644
--- a/writefrudata.C
+++ b/writefrudata.C
@@ -18,7 +18,7 @@
const char *sys_intf_name = "org.openbmc.managers.System";
//------------------------------------------------
-// Takes the pointer to stream of bytes and length
+// Takes the pointer to stream of bytes and length
// returns the 8 bit checksum per IPMI spec.
//-------------------------------------------------
unsigned char calculate_crc(unsigned char *data, int len)
@@ -30,7 +30,7 @@
{
crc += *data++;
}
-
+
return(-crc);
}
@@ -74,13 +74,13 @@
// Takes FRU data, invokes Parser for each fru record area and updates
// Inventory
//------------------------------------------------------------------------
-int ipmi_update_inventory(const uint8_t fruid, const uint8_t *fru_data,
- fru_area_vec_t & area_vec, sd_bus *bus_type)
+int ipmi_update_inventory(const uint8_t fruid, fru_area_vec_t & area_vec,
+ sd_bus *bus_type, const bool set_present)
{
// Now, use this fru dictionary object and connect with FRU Inventory Dbus
// and update the data for this FRU ID.
int rc = 0;
-
+
// Dictionary object to hold Name:Value pair
sd_bus_message *fru_dict = NULL;
@@ -123,7 +123,7 @@
fprintf(stderr, "ERROR: Invalid Area type :[%d]",area_type);
break;
}
-
+
// What we need is BOARD_1, PRODUCT_1, CHASSIS_1 etc..
char fru_area_name[16] = {0};
sprintf(fru_area_name,"%s%d",area_name, fruid);
@@ -131,16 +131,16 @@
#ifdef __IPMI_DEBUG__
printf("Updating Inventory with :[%s]\n",fru_area_name);
#endif
- // Each area needs a clean set.
+ // Each area needs a clean set.
sd_bus_error_free(&bus_error);
sd_bus_message_unref(response);
sd_bus_message_unref(fru_dict);
-
+
// We want to call a method "getObjectFromId" on System Bus that is
// made available over OpenBmc system services.
rc = sd_bus_call_method(bus_type, // On the System Bus
sys_bus_name, // Service to contact
- sys_object_name, // Object path
+ sys_object_name, // Object path
sys_intf_name, // Interface name
"getObjectFromId", // Method to be called
&bus_error, // object to return error
@@ -151,12 +151,12 @@
if(rc < 0)
{
- fprintf(stderr, "Failed to issue method call: %s\n", bus_error.message);
+ fprintf(stderr, "Failed to resolve fruid to dbus: %s\n", bus_error.message);
break;
}
// Method getObjectFromId returns 3 parameters and all are strings, namely
- // bus_name , object_path and interface name for accessing that particular
+ // bus_name , object_path and interface name for accessing that particular
// FRU over Inventory SDBUS manager. 'sss' here mentions that format.
char *inv_bus_name, *inv_obj_path, *inv_intf_name;
rc = sd_bus_message_read(response, "(sss)", &inv_bus_name, &inv_obj_path, &inv_intf_name);
@@ -207,7 +207,7 @@
// this.
rc = sd_bus_call(bus_type, // On the System Bus
fru_dict, // With the Name:value dictionary array
- 0, //
+ 0, //
&bus_error, // Object to return error.
&response); // Response message if any.
@@ -216,6 +216,31 @@
fprintf(stderr, "ERROR:[%s] updating FRU inventory for ID:[0x%X]\n",
bus_error.message, fruid);
}
+ else if(set_present)
+ {
+ printf("SUCCESS: Updated:[%s] successfully. Setting Present status now\n",fru_area_name);
+
+ // Clear any old residue
+ sd_bus_error_free(&bus_error);
+ sd_bus_message_unref(response);
+
+ // If we are asked to set the present status. do it.
+ rc = sd_bus_call_method(bus_type, // On the System Bus
+ inv_bus_name, // Service to contact
+ inv_obj_path, // Object path
+ inv_intf_name, // Interface name
+ "setPresent", // Method to be called
+ &bus_error, // object to return error
+ &response, // Response message on success
+ "s", // input message (string)
+ "True"); // First argument to getObjectFromId
+
+ if(rc < 0)
+ {
+ fprintf(stderr, "Failed to update Present status: %s\n", bus_error.message);
+ break;
+ }
+ }
else
{
printf("SUCCESS: Updated:[%s] successfully\n",fru_area_name);
@@ -232,10 +257,10 @@
//-------------------------------------------------------------------------
// Validates the CRC and if found good, calls fru areas parser and calls
-// Inventory Dbus with the dictionary of Name:Value for updating.
+// Inventory Dbus with the dictionary of Name:Value for updating.
//-------------------------------------------------------------------------
-int ipmi_validate_and_update_inventory(const uint8_t fruid, const uint8_t *fru_data,
- sd_bus *bus_type)
+int ipmi_validate_and_update_inventory(const uint8_t fruid, const uint8_t *fru_data,
+ sd_bus *bus_type, const bool set_present)
{
// Used for generic checksum calculation
uint8_t checksum = 0;
@@ -266,7 +291,7 @@
// Validate for first byte to always have a value of [1]
if(common_hdr[0] != IPMI_FRU_HDR_BYTE_ZERO)
{
- fprintf(stderr, "ERROR: Common Header entry_1:[0x%X] Invalid.\n",common_hdr[0]);
+ fprintf(stderr, "Invalid Common Header entry_1:[0x%X]\n",common_hdr[0]);
return -1;
}
else
@@ -279,10 +304,10 @@
if(checksum != common_hdr[IPMI_FRU_HDR_CRC_OFFSET])
{
#ifdef __IPMI__DEBUG__
- fprintf(stderr, "ERROR: Common Header checksum mismatch."
- " Calculated:[0x%X], Embedded:[0x%X]\n",
+ fprintf(stderr, "Common Header checksum mismatch."
+ " Calculated:[0x%X], Embedded:[0x%X]\n",
checksum, common_hdr[IPMI_FRU_HDR_CRC_OFFSET]);
-#endif
+#endif
return -1;
}
else
@@ -304,7 +329,7 @@
// product area set at the offset 01 * 8 --> 8 bytes from the START of
// common header. That means, soon after the header checksum.
area_offset = common_hdr[fru_entry] * IPMI_EIGHT_BYTES;
-
+
if(area_offset)
{
memset((void *)&fru_area, 0x0, sizeof(fru_area_t));
@@ -320,7 +345,7 @@
// area. err if first element in the record header is _not_ a [0x01].
if(fru_area_hdr[0] != IPMI_FRU_HDR_BYTE_ZERO)
{
- fprintf(stderr, "ERROR: Unexpected :[0x%X] found at Record header\n",
+ fprintf(stderr, "Unexpected :[0x%X] found at Record header\n",
fru_area_hdr[0]);
// This vector by now may have had some entries. Since this is a
@@ -354,8 +379,8 @@
if(checksum != fru_area_data[fru_area.len-1])
{
#ifdef __IPMI_DEBUG__
- fprintf(stderr, "ERROR: FRU Header checksum mismatch. "
- " Calculated:[0x%X], Embedded:[0x%X]\n",
+ fprintf(stderr, "FRU Header checksum mismatch. "
+ " Calculated:[0x%X], Embedded:[0x%X]\n",
checksum, fru_area_data[fru_area.len - 1]);
#endif
// This vector by now may have had some entries. Since this is a
@@ -375,19 +400,19 @@
// needed while handling each areas.
} // If the packet has data for a particular data record.
} // End walking all the fru records.
-
+
// If we reach here, then we have validated the crc for all the records and
// time to call FRU area parser to get a Name:Value pair dictionary.
// This will start iterating all over again on the buffer -BUT- now with the
// job of taking each areas, getting it parsed and then updating the
// DBUS.
-
+
if(!(fru_area_vec.empty()))
{
- rc = ipmi_update_inventory(fruid, fru_data, fru_area_vec, bus_type);
+ rc = ipmi_update_inventory(fruid, fru_area_vec, bus_type, set_present);
}
-
- // We are done with this FRU write packet.
+
+ // We are done with this FRU write packet.
fru_area_vec.clear();
return rc;
@@ -396,8 +421,8 @@
///-----------------------------------------------------
// Accepts the filename and validates per IPMI FRU spec
//----------------------------------------------------
-int ipmi_validate_fru_area(const uint8_t fruid, const char *fru_file_name,
- sd_bus *bus_type)
+int ipmi_validate_fru_area(const uint8_t fruid, const char *fru_file_name,
+ sd_bus *bus_type, const bool set_present)
{
int file_size = 0;
uint8_t *fru_data = NULL;
@@ -434,17 +459,17 @@
bytes_read = fread(fru_data, file_size, 1, fru_file);
if(bytes_read != 1)
{
- fprintf(stderr, "ERROR reading common header. Bytes read=:[%d]\n",bytes_read);
+ fprintf(stderr, "failed reading common header. Bytes read=:[%d]\n",bytes_read);
perror("Error:");
fclose(fru_file);
return -1;
}
fclose(fru_file);
- rc = ipmi_validate_and_update_inventory(fruid, fru_data, bus_type);
- if(rc == -1)
+ rc = ipmi_validate_and_update_inventory(fruid, fru_data, bus_type, set_present);
+ if(rc < 0)
{
- printf("ERROR: Validation failed for:[%d]\n",fruid);
+ fprintf(stderr,"Validation failed for:[%d]\n",fruid);
}
else
{