VOL-2508 Modify get all alarms to reflect uni alarm state

onu adapter periodically polls for all alarms and the
previously hardcoded get all alarms response would not
send the already sent autonomous alarm, effectivly
clearing the alarm before it was time

this change sets the autonomous link alarm to up or down
and sets a flag to indicate the onu is locked so alarm polling
gets the same results

this also has the side effect of fixing a class id 0 bug
that was being returned in get all alarms response that should not
have been given the response was valid "in time"

Change-Id: I103ce51a38755f6ae80db034706517744eecea40
diff --git a/VERSION b/VERSION
index bcab45a..81340c7 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.0.3
+0.0.4
diff --git a/omci_handlers.go b/omci_handlers.go
index de62498..5ba28f9 100644
--- a/omci_handlers.go
+++ b/omci_handlers.go
@@ -475,9 +475,10 @@
 func getAllAlarms(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
 	var pkt []byte
 
+	// Report number of commands as 1, basically there is always one alarm to get, the ONU/PPTP locked, link down or up
 	pkt = []byte{
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
-		0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -513,13 +514,31 @@
 func getAllAlarmsNext(class OmciClass, content OmciContent, key OnuKey) ([]byte, error) {
 	var pkt []byte
 
-	pkt = []byte{
-		0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
-		0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
-		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
+	OnuOmciStateMapLock.Lock()
+	if OnuOmciState, ok := OnuOmciStateMap[key]; ok {
+		// if we are locked then admin down was sent and PPTP 257 is in alarm/locked state, this ensures get alarm
+		// shows that
+		if OnuOmciState.state == LOCKED {
+			// alarm set, alarm spot 0, LAN LOS
+			pkt = []byte{
+				0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
+				0x00, 0x0b, 0x01, 0x01, 0x80, 0x00, 0x00, 0x00,
+				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
+		} else {
+			// alarm clear
+			pkt = []byte{
+				0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
+				0x00, 0x0b, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
+				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
+		}
+	}
+	OnuOmciStateMapLock.Unlock()
 
 	log.WithFields(log.Fields{
 		"IntfId": key.IntfId,
diff --git a/omci_sim.go b/omci_sim.go
index c971d54..6195168 100644
--- a/omci_sim.go
+++ b/omci_sim.go
@@ -135,6 +135,12 @@
 				Packet: linkMsgDown,
 			}
 			omciCh <- msg
+
+			OnuOmciStateMapLock.Lock()
+			if OnuOmciState, ok := OnuOmciStateMap[key]; ok {
+				OnuOmciState.state = LOCKED
+			}
+			OnuOmciStateMapLock.Unlock()
 		}
 
 		// attribute bit 5 (admin state) in the PPTP is being set, its value is 0, unlock
@@ -158,6 +164,12 @@
 				Packet: linkMsgUp,
 			}
 			omciCh <- msg
+
+			OnuOmciStateMapLock.Lock()
+			if OnuOmciState, ok := OnuOmciStateMap[key]; ok {
+				OnuOmciState.state = DONE
+			}
+			OnuOmciStateMapLock.Unlock()
 		}
 	}
 
diff --git a/omci_state.go b/omci_state.go
index eb923ba..ddb9921 100644
--- a/omci_state.go
+++ b/omci_state.go
@@ -41,6 +41,7 @@
 const (
 	INCOMPLETE istate = iota
 	DONE
+	LOCKED
 )
 
 var OnuOmciStateMap = map[OnuKey]*OnuOmciState{}