firmware_handler: handle the state transitions

There is a new state in the firmware handler.  Implement handling this
state which is between receiving data and verification running.
Implement the case properly where the verification blob is closed
properly after verification has completed.

Tested: Not yet tested.
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: Ib63ce1be1e435740739c02703b335897e26a512c
diff --git a/firmware_handler.cpp b/firmware_handler.cpp
index d8ddf8d..87116b2 100644
--- a/firmware_handler.cpp
+++ b/firmware_handler.cpp
@@ -491,6 +491,7 @@
         blobIDs.push_back(*active);
     }
 
+    state = UpdateState::uploadInProgress;
     fileOpen = true;
 
     return true;
@@ -640,14 +641,32 @@
     /* Are you closing the verify blob? */
     if (item->second->activePath == verifyBlobID)
     {
-        /* If they close this blob before verification finishes, that's an
-         * abort.
-         * TODO: implement this, for now just let them close the file.
-         */
         if (state == UpdateState::verificationStarted)
         {
+            /* TODO: If they close this blob before verification finishes,
+             * that's an abort.
+             */
             return false;
         }
+        else if (state == UpdateState::verificationCompleted)
+        {
+            /* TODO: Should this delete the verification artifact? */
+            state = UpdateState::notYetStarted;
+
+            /* A this point, delete the active blob IDs from the blob_list. */
+            blobIDs.erase(
+                std::remove(blobIDs.begin(), blobIDs.end(), activeImageBlobID));
+            blobIDs.erase(
+                std::remove(blobIDs.begin(), blobIDs.end(), activeHashBlobID));
+        }
+        /* Must be verificationPending... not yet started, they may re-open and
+         * trigger verification.
+         */
+    }
+    else
+    {
+        /* They are closing a data pathway (image, tarball, hash). */
+        state = UpdateState::verificationPending;
     }
 
     if (item->second->dataHandler)
@@ -668,9 +687,6 @@
 
     fileOpen = false;
 
-    /* TODO: implement other aspects of closing out a session, such as changing
-     * global firmware state.
-     */
     return true;
 }
 
diff --git a/firmware_handler.hpp b/firmware_handler.hpp
index 1af3d04..314516f 100644
--- a/firmware_handler.hpp
+++ b/firmware_handler.hpp
@@ -100,14 +100,14 @@
     {
         /** The initial state. */
         notYetStarted = 0,
-        /**
-         * The upload process has started, but verification has not started.
-         */
-        uploadInProgress = 1,
+        /** The BMC is expecting to receive bytes. */
+        uploadInProgress,
+        /** The BMC is ready for verification or more bytes. */
+        verificationPending,
         /** The verification process has started, no more writes allowed. */
-        verificationStarted = 2,
+        verificationStarted,
         /** The verification process has completed. */
-        verificationCompleted = 3,
+        verificationCompleted,
     };
 
     /** The return values for verification. */