BMC RR : Read and update the status for BMC reset

This commit reads the status of the host owned sensors by
sending a getStateSensorReading command and then
updates the D-Bus backend for BMC reset.

This commit also updates the TLPDR from the host
based on the valid bit in the TLPDR.

Earlier the PDR record handles where assigned in an incremental order
starting from 0, now the numbering has been decided
to be within the specified range as below
BMC: 0x00000001 to 0x00FFFFFF (0x00000000 is reserved per PLDM spec)
Hostboot: 0x01000000 to 0x01FFFFFF
PHYP: 0x02000000 to 0x02FFFFFF
Reserved: 0x03000000 to 0xFFFFFFFF

This commit handles the numbering of the PDR record handles.

Tested the following scenarios on a rainier system
1. restart pldmd when Host is not running
2. restart pldmd when Host is running
3. restart pldmd when Host is not running and then ipl

Using pldmtool the DBus backened is verified.

Signed-off-by: Pavithra Barithaya <pavithra.b@ibm.com>
Change-Id: Idb9eb642dbf766bb587a3a4075e4dce2c9da2de5
diff --git a/libpldm/pdr.c b/libpldm/pdr.c
index ec9ffee..a9132c7 100644
--- a/libpldm/pdr.c
+++ b/libpldm/pdr.c
@@ -250,7 +250,8 @@
 uint32_t pldm_pdr_add_fru_record_set(pldm_pdr *repo, uint16_t terminus_handle,
 				     uint16_t fru_rsi, uint16_t entity_type,
 				     uint16_t entity_instance_num,
-				     uint16_t container_id)
+				     uint16_t container_id,
+				     uint32_t bmc_record_handle)
 {
 	uint32_t size = sizeof(struct pldm_pdr_hdr) +
 			sizeof(struct pldm_pdr_fru_record_set);
@@ -258,7 +259,7 @@
 
 	struct pldm_pdr_hdr *hdr = (struct pldm_pdr_hdr *)&data;
 	hdr->version = 1;
-	hdr->record_handle = 0;
+	hdr->record_handle = bmc_record_handle;
 	hdr->type = PLDM_PDR_FRU_RECORD_SET;
 	hdr->record_change_num = 0;
 	hdr->length = htole16(sizeof(struct pldm_pdr_fru_record_set));
@@ -271,7 +272,7 @@
 	fru->entity_instance_num = htole16(entity_instance_num);
 	fru->container_id = htole16(container_id);
 
-	return pldm_pdr_add(repo, data, size, 0, false);
+	return pldm_pdr_add(repo, data, size, bmc_record_handle, false);
 }
 
 const pldm_pdr_record *pldm_pdr_fru_record_set_find_by_rsi(
@@ -313,6 +314,33 @@
 	return NULL;
 }
 
+void pldm_pdr_update_TL_pdr(const pldm_pdr *repo, uint16_t terminusHandle,
+			    uint8_t tid, uint8_t tlEid, bool validBit)
+{
+	uint8_t *outData = NULL;
+	uint32_t size = 0;
+	const pldm_pdr_record *record;
+	record = pldm_pdr_find_record_by_type(repo, PLDM_TERMINUS_LOCATOR_PDR,
+					      NULL, &outData, &size);
+
+	do {
+		if (record != NULL) {
+			struct pldm_terminus_locator_pdr *pdr =
+			    (struct pldm_terminus_locator_pdr *)outData;
+			struct pldm_terminus_locator_type_mctp_eid *value =
+			    (struct pldm_terminus_locator_type_mctp_eid *)
+				pdr->terminus_locator_value;
+			if (pdr->terminus_handle == terminusHandle &&
+			    pdr->tid == tid && value->eid == tlEid) {
+				pdr->validity = validBit;
+				break;
+			}
+		}
+		record = pldm_pdr_find_record_by_type(
+		    repo, PLDM_TERMINUS_LOCATOR_PDR, record, &outData, &size);
+	} while (record);
+}
+
 typedef struct pldm_entity_association_tree {
 	pldm_entity_node *root;
 	uint16_t last_used_container_id;