BMC Minimum ship Level

This code compares the BMC_MSL defined at compile time,
It will parse the new fw (explicit at MANIFEST file) and use regex to
evaluate it  and compare BMC_MSL against version from MANIFEST.
If newer or equal  it will apply, otherwise it will fail,
preventing activation  operation.

Tested:
 regex-bmc-msl="([a-z]+[0-9]{2})+([0-9]+).([0-9]+).([0-9]+)"
 fw-package="version=fw1010.00-28.4-0-ge611abca21"
 bmc-msl="fw1010.00-27"  proceeds with activation...
 bmc-msl="fw1010.00-29"  returns:

Jul 15 20:35:45 tacoma1z-w81 phosphor-image-updater[766]:
BMC Minimum Ship Level NOT met

Jul 15 20:35:45 tacoma1z-w81 phosphor-image-updater[766]:
A system component has a software version that is incompatible as
determined by the implementation and needs to be updated....

Signed-off-by: Miguel Gomez <mgomez@mx1.ibm.com>
Change-Id: I0ab0eba7c7c89f38ca698aa3e369aa50797edb07
diff --git a/msl_verify.hpp b/msl_verify.hpp
new file mode 100644
index 0000000..9fd6695
--- /dev/null
+++ b/msl_verify.hpp
@@ -0,0 +1,40 @@
+#pragma once

+

+#include <string>

+

+namespace minimum_ship_level

+{

+

+/** @brief Version components */

+struct Version

+{

+    uint8_t major;

+    uint8_t minor;

+    uint8_t rev;

+};

+

+/** @brief Verify if the current BMC version meets the min ship level

+ *  @return true if the verification succeeded, false otherwise

+ */

+bool verify(const std::string& versionStr);

+

+/** @brief Parse the version components into a struct

+ *  @details User passes a version string in regex format (REGEX_BMC_MSL)

+ *  at compilation time, this value is break down by parse function to allocate

+ *  a struct so it can be compared position by position against the (BMC_MSL)

+ *  also defined at compile time.

+ * @param[in]  versionStr - The version string to be parsed

+ * @param[out] version    - The version struct to be populated

+ */

+void parse(const std::string& versionStr, Version& version);

+

+/** @brief Compare the versions provided

+ *  @param[in] a - The first version to compare

+ *  @param[in] b - The second version to compare

+ *  @return 1 if a > b

+ *          0 if a = b

+ *         -1 if a < b

+ */

+int compare(const Version& a, const Version& b);

+

+} // namespace minimum_ship_level