msl_verify: Add support for multiple MSL values

There are scenarios where the BMC can support multiple PNOR MSL
values, such as v1.2 and v.1.4.9. Support multiple values
separated by a space.

Change-Id: Id65c43872db33538e2f02f6f60b4571a5231717b
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/msl_verify.cpp b/msl_verify.cpp
index 1a6234c..36203db 100644
--- a/msl_verify.cpp
+++ b/msl_verify.cpp
@@ -111,18 +111,53 @@
         return true;
     }
 
-    Version minVersion = {0, 0, 0};
-    parse(minShipLevel, minVersion);
+    // Multiple min versions separated by a space can be specified, parse them
+    // into a vector, then sort them in ascending order
+    std::istringstream minStream(minShipLevel);
+    std::vector<std::string> mins(std::istream_iterator<std::string>{minStream},
+                                  std::istream_iterator<std::string>());
+    std::sort(mins.begin(), mins.end());
 
+    // In order to handle non-continuous multiple min versions, need to compare
+    // the major.minor section first, then if they're the same, compare the rev.
+    // Ex: the min versions specified are 2.0.10 and 2.2. We need to pass if
+    // actual is 2.0.11 but fail if it's 2.1.x.
+    // 1. Save off the rev number to compare later if needed.
+    // 2. Zero out the rev number to just compare major and minor.
     Version actualVersion = {0, 0, 0};
     parse(actual, actualVersion);
+    Version actualRev = {0, 0, actualVersion.rev};
+    actualVersion.rev = 0;
 
-    auto rc = compare(actualVersion, minVersion);
+    auto rc = 0;
+    std::string tmpMin{};
+
+    for (auto const& min : mins)
+    {
+        tmpMin = min;
+
+        Version minVersion = {0, 0, 0};
+        parse(min, minVersion);
+        Version minRev = {0, 0, minVersion.rev};
+        minVersion.rev = 0;
+
+        rc = compare(actualVersion, minVersion);
+        if (rc < 0)
+        {
+            break;
+        }
+        else if (rc == 0)
+        {
+            // Same major.minor version, compare the rev
+            rc = compare(actualRev, minRev);
+            break;
+        }
+    }
     if (rc < 0)
     {
         log<level::ERR>(
             "PNOR Mininum Ship Level NOT met",
-            entry("MIN_VERSION=%s", minShipLevel.c_str()),
+            entry("MIN_VERSION=%s", tmpMin.c_str()),
             entry("ACTUAL_VERSION=%s", actual.c_str()),
             entry("VERSION_PURPOSE=%s",
                   "xyz.openbmc_project.Software.Version.VersionPurpose.Host"));