BMCDump: dump subtype input parameter support

The BMC dump is not accepting any parameters to specify the type of
dump or level of data to be collected. It was always creating a default
user-requested dump.

This commit allows for the specification of the dump type during the
dump creation process. A new table has been added in a new header file
which stores the valid dump types. When a new dump is requested, the
specified dump type is verified against this table. If no dump type is
mentioned, a user-requested BMC dump is created for backward
compatibility. If an invalid dump type is mentioned, an Invalid
Argument exception is thrown.

Tested:
- Create BMC dump with no arguments
- Create BMC dump with type as user
- Create a error log dump and make sure other types of dumps
  which is using internal interface is not impacted.

Change-Id: I79f68be6ac6892ac7754b7221db64c22330b1822
Signed-off-by: Dhruvaraj Subhashchandran <dhruvaraj@in.ibm.com>
diff --git a/dump_utils.cpp b/dump_utils.cpp
index 792138c..68e5f8d 100644
--- a/dump_utils.cpp
+++ b/dump_utils.cpp
@@ -1,5 +1,7 @@
 #include "dump_utils.hpp"
 
+#include "dump_types.hpp"
+
 #include <phosphor-logging/lg2.hpp>
 
 namespace phosphor
@@ -44,5 +46,36 @@
     return response[0].first;
 }
 
+DumpTypes validateDumpType(const std::string& type, const std::string& category)
+{
+    using InvalidArgument =
+        sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument;
+    using Argument = xyz::openbmc_project::Common::InvalidArgument;
+    // Dump type user will be return if type is empty
+    DumpTypes dumpType = DumpTypes::USER;
+    if (type.empty())
+    {
+        return dumpType;
+    }
+
+    // Find any matching dump collection type for the category
+    auto it = std::find_if(dumpTypeTable.begin(), dumpTypeTable.end(),
+                           [&](const auto& pair) {
+        return pair.first == type && pair.second.second == category;
+    });
+
+    if (it != dumpTypeTable.end())
+    {
+        dumpType = it->second.first;
+    }
+    else
+    {
+        lg2::error("An invalid dump type: {TYPE} passed", "TYPE", type);
+        elog<InvalidArgument>(Argument::ARGUMENT_NAME("BMC_DUMP_TYPE"),
+                              Argument::ARGUMENT_VALUE(type.c_str()));
+    }
+    return dumpType;
+}
+
 } // namespace dump
 } // namespace phosphor