Fix IPMI SEL reservations and cancellations

Per the IPMI Spec, the SEL must be reserved to
   Delete an entry
   Clear the SEL
   Get a partial entry
   Add a partial entry

The current SEL reservation must be cancelled when
   A SEL entry is added
   A SEL entry is deleted
   The SEL is cleared
   The device is reset
   A new reservation is requested

This change adds a reservation status to track when a reservation
is active and a method to cancel the current reservation, and it
uses that to cancel the reservation in the Delete, Clear, and Add
SEL methods.

Change-Id: Ifd72e6d06ecc622855bd9ce8cc3928cbd0f2c34b
Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
diff --git a/ipmid.cpp b/ipmid.cpp
index bc6c522..be6b4d4 100644
--- a/ipmid.cpp
+++ b/ipmid.cpp
@@ -76,11 +76,29 @@
 std::map<ipmi_fn_cmd_t, ipmi_fn_context_t> g_ipmid_router_map;
 
 // IPMI Spec, shared Reservation ID.
-unsigned short g_sel_reserve = 0xFFFF;
+static unsigned short selReservationID = 0xFFFF;
+static bool selReservationValid = false;
 
-unsigned short get_sel_reserve_id(void)
+unsigned short reserveSel(void)
 {
-    return g_sel_reserve;
+    // IPMI spec, Reservation ID, the value simply increases against each
+    // execution of the Reserve SEL command.
+    if (++selReservationID == 0)
+    {
+        selReservationID = 1;
+    }
+    selReservationValid = true;
+    return selReservationID;
+}
+
+bool checkSELReservation(unsigned short id)
+{
+    return (selReservationValid && selReservationID == id);
+}
+
+void cancelSELReservation(void)
+{
+    selReservationValid = false;
 }
 
 namespace internal