libpldmresponder: enable DBus change notification

This commit enables libpldmresponder to subscribe to DBus
property change signal for the BIOS properties which are fetched from
DBus. The new DBus value is received and the relevant entry in the
attributeValueTable is updated.

test result:

root@rainier:/tmp# pldmtool bios GetBIOSTable -t 0
Parsed Response Msg:
PLDM StringTable:
BIOSStringHandle : BIOSString
0 : Allowed
1 : Disabled
2 : Enabled
3 : IPv4DHCP
4 : IPv4Static
5 : Not Allowed
6 : Perm
7 : Temp
8 : pvm-fw-boot-side
9 : pvm-inband-code-update
10 : pvm-os-boot-side
11 : pvm-pcie-error-inject
12 : pvm-surveillance
13 : pvm-system-name
14 : vmi-hostname
15 : vmi-if-count
16 : vmi-if0-ipv4-ipaddr
17 : vmi-if0-ipv4-method
18 : vmi-if0-ipv4-prefix-length
19 : vmi-if1-ipv4-ipaddr
20 : vmi-if1-ipv4-method
21 : vmi-if1-ipv4-prefix-length
22 : vmi-ipv4-gateway
root@rainier:/tmp#

root@rainier:/tmp# pldmtool bios GetBIOSTable -t 1
Parsed Response Msg:
PLDM AttributeTable:
AttributeHandle: 0, AttributeNameHandle: 13(pvm-system-name)
        AttributeType: BIOSStringReadOnly
        StringType: 0x01
        MinimumStringLength: 1
        MaximumStringLength: 100
        DefaultStringLength: 15
        DefaultString: witherspoon-128
AttributeHandle: 1, AttributeNameHandle: 14(vmi-hostname)
        AttributeType: BIOSString
        StringType: 0x01
        MinimumStringLength: 0
        MaximumStringLength: 255
        DefaultStringLength: 0
        DefaultString:
AttributeHandle: 2, AttributeNameHandle: 22(vmi-ipv4-gateway)
        AttributeType: BIOSString
        StringType: 0x01
        MinimumStringLength: 7
        MaximumStringLength: 15
        DefaultStringLength: 7
        DefaultString: 0.0.0.0
AttributeHandle: 3, AttributeNameHandle: 16(vmi-if0-ipv4-ipaddr)
        AttributeType: BIOSString
        StringType: 0x01
        MinimumStringLength: 7
        MaximumStringLength: 15
        DefaultStringLength: 7
        DefaultString: 0.0.0.0
AttributeHandle: 4, AttributeNameHandle: 19(vmi-if1-ipv4-ipaddr)
        AttributeType: BIOSString
        StringType: 0x01
        MinimumStringLength: 7
        MaximumStringLength: 15
        DefaultStringLength: 7
        DefaultString: 0.0.0.0
AttributeHandle: 5, AttributeNameHandle: 15(vmi-if-count)
        AttributeType: BIOSIntegerReadOnly
        LowerBound: 0
        UpperBound: 2
        ScalarIncrement: 1
        DefaultValue: 1
AttributeHandle: 6, AttributeNameHandle: 18(vmi-if0-ipv4-prefix-length)
        AttributeType: BIOSInteger
        LowerBound: 0
        UpperBound: 32
        ScalarIncrement: 1
        DefaultValue: 0
AttributeHandle: 7, AttributeNameHandle: 21(vmi-if1-ipv4-prefix-length)
        AttributeType: BIOSInteger
        LowerBound: 0
        UpperBound: 32
        ScalarIncrement: 1
        DefaultValue: 0
AttributeHandle: 8, AttributeNameHandle: 8(pvm-fw-boot-side)
        AttributeType: BIOSEnumerationReadOnly
        NumberOfPossibleValues: 2
                PossibleValueStringHandle[0] = 6(Perm)
                PossibleValueStringHandle[1] = 7(Temp)
        NumberOfDefaultValues: 1
                DefaultValueStringHandleIndex[0] = 0, StringHandle = 6(Perm)
AttributeHandle: 9, AttributeNameHandle: 10(pvm-os-boot-side)
        AttributeType: BIOSEnumerationReadOnly
        NumberOfPossibleValues: 2
                PossibleValueStringHandle[0] = 6(Perm)
                PossibleValueStringHandle[1] = 7(Temp)
        NumberOfDefaultValues: 1
                DefaultValueStringHandleIndex[0] = 0, StringHandle = 6(Perm)
AttributeHandle: 10, AttributeNameHandle: 9(pvm-inband-code-update)
        AttributeType: BIOSEnumerationReadOnly
        NumberOfPossibleValues: 2
                PossibleValueStringHandle[0] = 0(Allowed)
                PossibleValueStringHandle[1] = 5(Not Allowed)
        NumberOfDefaultValues: 1
                DefaultValueStringHandleIndex[0] = 0, StringHandle = 0(Allowed)
AttributeHandle: 11, AttributeNameHandle: 12(pvm-surveillance)
        AttributeType: BIOSEnumerationReadOnly
        NumberOfPossibleValues: 2
                PossibleValueStringHandle[0] = 1(Disabled)
                PossibleValueStringHandle[1] = 2(Enabled)
        NumberOfDefaultValues: 1
                DefaultValueStringHandleIndex[0] = 1, StringHandle = 2(Enabled)
AttributeHandle: 12, AttributeNameHandle: 11(pvm-pcie-error-inject)
        AttributeType: BIOSEnumerationReadOnly
        NumberOfPossibleValues: 2
                PossibleValueStringHandle[0] = 1(Disabled)
                PossibleValueStringHandle[1] = 2(Enabled)
        NumberOfDefaultValues: 1
                DefaultValueStringHandleIndex[0] = 1, StringHandle = 2(Enabled)
AttributeHandle: 13, AttributeNameHandle: 17(vmi-if0-ipv4-method)
        AttributeType: BIOSEnumeration
        NumberOfPossibleValues: 2
                PossibleValueStringHandle[0] = 4(IPv4Static)
                PossibleValueStringHandle[1] = 3(IPv4DHCP)
        NumberOfDefaultValues: 1
                DefaultValueStringHandleIndex[0] = 0, StringHandle = 4(IPv4Static)
AttributeHandle: 14, AttributeNameHandle: 20(vmi-if1-ipv4-method)
        AttributeType: BIOSEnumeration
        NumberOfPossibleValues: 2
                PossibleValueStringHandle[0] = 4(IPv4Static)
                PossibleValueStringHandle[1] = 3(IPv4DHCP)
        NumberOfDefaultValues: 1
                DefaultValueStringHandleIndex[0] = 0, StringHandle = 4(IPv4Static)
root@rainier:/tmp#

root@rainier:/tmp# pldmtool bios GetBIOSTable -t 2
Parsed Response Msg:
PLDM AttributeValueTable:
AttributeHandle: 0
        AttributeType: BIOSStringReadOnly
        CurrentStringLength: 15
        CurrentString: witherspoon-128
AttributeHandle: 1
        AttributeType: BIOSString
        CurrentStringLength: 0
        CurrentString:
AttributeHandle: 2
        AttributeType: BIOSString
        CurrentStringLength: 7
        CurrentString: 0.0.0.0
AttributeHandle: 3
        AttributeType: BIOSString
        CurrentStringLength: 7
        CurrentString: 0.0.0.0
AttributeHandle: 4
        AttributeType: BIOSString
        CurrentStringLength: 7
        CurrentString: 0.0.0.0
AttributeHandle: 5
        AttributeType: BIOSIntegerReadOnly
        CurrentValue: 1
AttributeHandle: 6
        AttributeType: BIOSInteger
        CurrentValue: 0
AttributeHandle: 7
        AttributeType: BIOSInteger
        CurrentValue: 0
AttributeHandle: 8
        AttributeType: BIOSEnumerationReadOnly
        NumberOfCurrentValues: 1
        CurrentValueStringHandleIndex[0] = 0, StringHandle = 6(Perm)
AttributeHandle: 9
        AttributeType: BIOSEnumerationReadOnly
        NumberOfCurrentValues: 1
        CurrentValueStringHandleIndex[0] = 0, StringHandle = 6(Perm)
AttributeHandle: 10
        AttributeType: BIOSEnumerationReadOnly
        NumberOfCurrentValues: 1
        CurrentValueStringHandleIndex[0] = 0, StringHandle = 0(Allowed)
AttributeHandle: 11
        AttributeType: BIOSEnumerationReadOnly
        NumberOfCurrentValues: 1
        CurrentValueStringHandleIndex[0] = 1, StringHandle = 2(Enabled)
AttributeHandle: 12
        AttributeType: BIOSEnumerationReadOnly
        NumberOfCurrentValues: 1
        CurrentValueStringHandleIndex[0] = 1, StringHandle = 2(Enabled)
AttributeHandle: 13
        AttributeType: BIOSEnumeration
        NumberOfCurrentValues: 1
        CurrentValueStringHandleIndex[0] = 0, StringHandle = 4(IPv4Static)
AttributeHandle: 14
        AttributeType: BIOSEnumeration
        NumberOfCurrentValues: 1
        CurrentValueStringHandleIndex[0] = 0, StringHandle = 4(IPv4Static)
root@rainier:/tmp#

root@rainier:/tmp# busctl get-property  xyz.openbmc_project.Settings
/xyz/openbmc_project/network/vmi/intf1/ipv4/addr0 xyz.openbmc_project.Network.IP
PrefixLength
y 0

root@rainier:/tmp# busctl set-property  xyz.openbmc_project.Settings
/xyz/openbmc_project/network/vmi/intf1/ipv4/addr0 xyz.openbmc_project.Network.IP
PrefixLength y 6

root@rainier:/tmp# busctl get-property  xyz.openbmc_project.Settings
/xyz/openbmc_project/network/vmi/intf1/ipv4/addr0 xyz.openbmc_project.Network.IP
Origin
s "xyz.openbmc_project.Network.IP.AddressOrigin.Static"

root@rainier:/tmp# busctl set-property  xyz.openbmc_project.Settings
/xyz/openbmc_project/network/vmi/intf1/ipv4/addr0 xyz.openbmc_project.Network.IP
Origin s "xyz.openbmc_project.Network.IP.AddressOrigin.DHCP"

root@rainier:/tmp# busctl get-property  xyz.openbmc_project.Settings
/xyz/openbmc_project/network/vmi/intf1/ipv4/addr0 xyz.openbmc_project.Network.IP
Address
s "0.0.0.0"

root@rainier:/tmp# busctl set-property  xyz.openbmc_project.Settings
/xyz/openbmc_project/network/vmi/intf1/ipv4/addr0 xyz.openbmc_project.Network.IP
Address s "1.2.3.4"

root@rainier:/tmp# pldmtool bios GetBIOSTable -t 2
Parsed Response Msg:
PLDM AttributeValueTable:
AttributeHandle: 0
        AttributeType: BIOSStringReadOnly
        CurrentStringLength: 15
        CurrentString: witherspoon-128
AttributeHandle: 1
        AttributeType: BIOSString
        CurrentStringLength: 0
        CurrentString:
AttributeHandle: 2
        AttributeType: BIOSString
        CurrentStringLength: 7
        CurrentString: 0.0.0.0
AttributeHandle: 3
        AttributeType: BIOSString
        CurrentStringLength: 7
        CurrentString: 0.0.0.0
AttributeHandle: 4
        AttributeType: BIOSString
        CurrentStringLength: 7
        CurrentString: 1.2.3.4
AttributeHandle: 5
        AttributeType: BIOSIntegerReadOnly
        CurrentValue: 1
AttributeHandle: 6
        AttributeType: BIOSInteger
        CurrentValue: 0
AttributeHandle: 7
        AttributeType: BIOSInteger
        CurrentValue: 6
AttributeHandle: 8
        AttributeType: BIOSEnumerationReadOnly
        NumberOfCurrentValues: 1
        CurrentValueStringHandleIndex[0] = 0, StringHandle = 6(Perm)
AttributeHandle: 9
        AttributeType: BIOSEnumerationReadOnly
        NumberOfCurrentValues: 1
        CurrentValueStringHandleIndex[0] = 0, StringHandle = 6(Perm)
AttributeHandle: 10
        AttributeType: BIOSEnumerationReadOnly
        NumberOfCurrentValues: 1
        CurrentValueStringHandleIndex[0] = 0, StringHandle = 0(Allowed)
AttributeHandle: 11
        AttributeType: BIOSEnumerationReadOnly
        NumberOfCurrentValues: 1
        CurrentValueStringHandleIndex[0] = 1, StringHandle = 2(Enabled)
AttributeHandle: 12
        AttributeType: BIOSEnumerationReadOnly
        NumberOfCurrentValues: 1
        CurrentValueStringHandleIndex[0] = 1, StringHandle = 2(Enabled)
AttributeHandle: 13
        AttributeType: BIOSEnumeration
        NumberOfCurrentValues: 1
        CurrentValueStringHandleIndex[0] = 0, StringHandle = 4(IPv4Static)
AttributeHandle: 14
        AttributeType: BIOSEnumeration
        NumberOfCurrentValues: 1
        CurrentValueStringHandleIndex[0] = 1, StringHandle = 3(IPv4DHCP)

Change-Id: I60e8f916a82bda0ef27c8c482fafb755b65210b4
Signed-off-by: Sampa Misra <sampmisr@in.ibm.com>
diff --git a/libpldmresponder/bios_config.hpp b/libpldmresponder/bios_config.hpp
index dd892b1..ae1794e 100644
--- a/libpldmresponder/bios_config.hpp
+++ b/libpldmresponder/bios_config.hpp
@@ -70,6 +70,22 @@
     using BIOSAttributes = std::vector<std::unique_ptr<BIOSAttribute>>;
     BIOSAttributes biosAttributes;
 
+    using propName = std::string;
+    using DbusChObjProperties = std::map<propName, PropertyValue>;
+
+    // vector to catch the D-Bus property change signals for BIOS attributes
+    std::vector<std::unique_ptr<sdbusplus::bus::match::match>> biosAttrMatch;
+
+    /** @brief Method to update a BIOS attribute when the corresponding Dbus
+     *  property is changed
+     *  @param[in] chProperties - list of properties which have changed
+     *  @param[in] biosAttrIndex - Index of BIOSAttribute pointer in
+     * biosAttributes
+     *  @return - none
+     */
+    void processBiosAttrChangeNotification(
+        const DbusChObjProperties& chProperties, uint32_t biosAttrIndex);
+
     /** @brief Construct an attribute and persist it
      *  @tparam T - attribute type
      *  @param[in] entry - json entry
@@ -80,6 +96,26 @@
         try
         {
             biosAttributes.push_back(std::make_unique<T>(entry, dbusHandler));
+            auto biosAttrIndex = biosAttributes.size() - 1;
+            auto dBusMap = biosAttributes[biosAttrIndex]->getDBusMap();
+
+            if (dBusMap.has_value())
+            {
+                using namespace sdbusplus::bus::match::rules;
+                biosAttrMatch.push_back(
+                    std::make_unique<sdbusplus::bus::match::match>(
+                        pldm::utils::DBusHandler::getBus(),
+                        propertiesChanged(dBusMap->objectPath,
+                                          dBusMap->interface),
+                        [this,
+                         biosAttrIndex](sdbusplus::message::message& msg) {
+                            DbusChObjProperties props;
+                            std::string iface;
+                            msg.read(iface, props);
+                            processBiosAttrChangeNotification(props,
+                                                              biosAttrIndex);
+                        }));
+            }
         }
         catch (const std::exception& e)
         {
@@ -124,4 +160,4 @@
 
 } // namespace bios
 } // namespace responder
-} // namespace pldm
\ No newline at end of file
+} // namespace pldm