Added BootType property for Get/Set BootOrder

Added BootType property and interface in Get and Set Boot Order
handler to determine the BIOS boot options which supports both
Legacy and EFI.

TESTED : Tested on Facebook Yosemitev2 platform and verified
the results.

Signed-off-by: Jayashree Dhanapal <jayashree-d@hcl.com>
Change-Id: I7ce11a03a4b844de0d27ba7a105bc6b8912351d3
diff --git a/src/oemcommands.cpp b/src/oemcommands.cpp
index ea5da82..adb9d62 100644
--- a/src/oemcommands.cpp
+++ b/src/oemcommands.cpp
@@ -18,6 +18,7 @@
 #include "xyz/openbmc_project/Common/error.hpp"
 #include <xyz/openbmc_project/Control/Boot/Mode/server.hpp>
 #include <xyz/openbmc_project/Control/Boot/Source/server.hpp>
+#include <xyz/openbmc_project/Control/Boot/Type/server.hpp>
 
 #include <ipmid/api.hpp>
 #include <ipmid/utils.hpp>
@@ -160,6 +161,9 @@
 std::map<IpmiValue, Mode::Modes> modeIpmiToDbus = {
     {0x06, Mode::Modes::Setup}, {0x00, Mode::Modes::Regular}};
 
+std::map<IpmiValue, Type::Types> typeIpmiToDbus = {{0x00, Type::Types::Legacy},
+                                                   {0x01, Type::Types::EFI}};
+
 std::map<Source::Sources, IpmiValue> sourceDbusToIpmi = {
     {Source::Sources::Default, 0x0f},
     {Source::Sources::RemovableMedia, 0x00},
@@ -170,11 +174,16 @@
 std::map<Mode::Modes, IpmiValue> modeDbusToIpmi = {
     {Mode::Modes::Setup, 0x06}, {Mode::Modes::Regular, 0x00}};
 
+std::map<Type::Types, IpmiValue> typeDbusToIpmi = {{Type::Types::Legacy, 0x00},
+                                                   {Type::Types::EFI, 0x01}};
+
 static constexpr auto bootModeIntf = "xyz.openbmc_project.Control.Boot.Mode";
 static constexpr auto bootSourceIntf =
     "xyz.openbmc_project.Control.Boot.Source";
+static constexpr auto bootTypeIntf = "xyz.openbmc_project.Control.Boot.Type";
 static constexpr auto bootSourceProp = "BootSource";
 static constexpr auto bootModeProp = "BootMode";
+static constexpr auto bootTypeProp = "BootType";
 
 auto instances(std::string s)
 {
@@ -662,7 +671,9 @@
     std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
 
     // SETTING BOOT MODE PROPERTY
-    auto bootValue = ipmi::boot::modeIpmiToDbus.find((data[0]));
+    uint8_t bootModeBit = data[0] & 0x06;
+    auto bootValue = ipmi::boot::modeIpmiToDbus.find(bootModeBit);
+
     std::string bootOption =
         ipmi::boot::Mode::convertModesToString((bootValue->second));
 
@@ -680,6 +691,18 @@
     setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootSourceIntf,
                     ipmi::boot::bootSourceProp, bootSource);
 
+    // SETTING BOOT TYPE PROPERTY
+
+    uint8_t bootTypeBit = data[0] & 0x01;
+    auto bootTypeVal = ipmi::boot::typeIpmiToDbus.find(bootTypeBit);
+    std::string bootType =
+        ipmi::boot::Type::convertTypesToString((bootTypeVal->second));
+
+    service = getService(*dbus, ipmi::boot::bootTypeIntf, bootObjPath);
+
+    setDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootTypeIntf,
+                    ipmi::boot::bootTypeProp, bootType);
+
     nlohmann::json bootMode;
     uint8_t mode = data[0];
     int i;
@@ -742,7 +765,6 @@
 ipmi::RspType<uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t>
     ipmiOemGetBootOrder(ipmi::Context::ptr ctx)
 {
-    uint8_t bootOption, bootOrder;
     uint8_t bootSeq[SIZE_BOOT_ORDER];
     uint8_t mode = 0;
 
@@ -769,7 +791,7 @@
     auto bootMode = ipmi::boot::Mode::convertModesFromString(
         std::get<std::string>(variant));
 
-    bootOption = ipmi::boot::modeDbusToIpmi.at(bootMode);
+    uint8_t bootOption = ipmi::boot::modeDbusToIpmi.at(bootMode);
 
     // GETTING PROPERTY OF SOURCE INTERFACE
 
@@ -780,7 +802,20 @@
     auto bootSource = ipmi::boot::Source::convertSourcesFromString(
         std::get<std::string>(variant));
 
-    bootOrder = ipmi::boot::sourceDbusToIpmi.at(bootSource);
+    uint8_t bootOrder = ipmi::boot::sourceDbusToIpmi.at(bootSource);
+
+    // GETTING PROPERTY OF TYPE INTERFACE
+
+    service = getService(*dbus, ipmi::boot::bootTypeIntf, bootObjPath);
+    variant =
+        getDbusProperty(*dbus, service, bootObjPath, ipmi::boot::bootTypeIntf,
+                        ipmi::boot::bootTypeProp);
+    auto bootType = ipmi::boot::Type::convertTypesFromString(
+        std::get<std::string>(variant));
+
+    uint8_t bootTypeVal = ipmi::boot::typeDbusToIpmi.at(bootType);
+
+    uint8_t bootVal = bootOption | bootTypeVal;
 
     if (oemData.find(hostName) == oemData.end())
     {
@@ -816,7 +851,7 @@
         }
     }
 
-    return ipmi::responseSuccess(bootOption, bootOrder, bootSeq[2], bootSeq[3],
+    return ipmi::responseSuccess(bootVal, bootOrder, bootSeq[2], bootSeq[3],
                                  bootSeq[4], bootSeq[5]);
 }
 // Set Machine Config Info (CMD_OEM_SET_MACHINE_CONFIG_INFO)