[VOL-3623] Reporting the correct SerialNumber as part of the ONUG request

Change-Id: I2041de1a046092c7b3d70cd8b9f5f57c31ace9a6
diff --git a/VERSION b/VERSION
index 81340c7..bbdeab6 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.0.4
+0.0.5
diff --git a/omci_common.go b/omci_common.go
index a140141..3fa4408 100644
--- a/omci_common.go
+++ b/omci_common.go
@@ -30,6 +30,7 @@
 }
 
 type OnuKey struct {
+	OltId int
 	IntfId, OnuId uint32
 }
 
@@ -56,7 +57,7 @@
 
 	case ONUG:
 		pos := uint(11)
-		pkt, _ = GetOnuGAttributes(&pos, pkt, content)
+		pkt, _ = GetOnuGAttributes(&pos, pkt, content, key)
 		return pkt
 
 	case ONU2G:
diff --git a/omci_onug.go b/omci_onug.go
index 1cf6b0d..4a6d6f1 100644
--- a/omci_onug.go
+++ b/omci_onug.go
@@ -35,7 +35,7 @@
 	ExtendedTcLayerOptions   OnuGAttributes = 0x0008
 )
 
-type OnuGAttributeHandler func(*uint, []byte) ([]byte, error)
+type OnuGAttributeHandler func(*uint, []byte, OnuKey) ([]byte, error)
 
 var OnuGAttributeHandlers = map[OnuGAttributes]OnuGAttributeHandler{
 	VendorID:                 GetVendorID,
@@ -53,7 +53,7 @@
 	ExtendedTcLayerOptions:   GetExtendedTcLayerOptions,
 }
 
-func GetOnuGAttributes(pos *uint, pkt []byte, content OmciContent) ([]byte, error) {
+func GetOnuGAttributes(pos *uint, pkt []byte, content OmciContent, key OnuKey) ([]byte, error) {
 	AttributesMask := getAttributeMask(content)
 
 	for index := uint(16); index >= 1; index-- {
@@ -61,7 +61,7 @@
 		reqAttribute := Attribute & AttributesMask
 
 		if reqAttribute != 0 {
-			pkt, _ = OnuGAttributeHandlers[OnuGAttributes(reqAttribute)](pos, pkt)
+			pkt, _ = OnuGAttributeHandlers[OnuGAttributes(reqAttribute)](pos, pkt, key)
 		}
 	}
 
@@ -73,7 +73,7 @@
 
 }
 
-func GetVendorID(pos *uint, pkt []byte) ([]byte, error) {
+func GetVendorID(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) {
 	// 4 bytes
 	vendorid := []byte("BBSM")
 	for _, ch := range vendorid {
@@ -83,7 +83,7 @@
 	return pkt, nil
 }
 
-func GetVersion(pos *uint, pkt []byte) ([]byte, error) {
+func GetVersion(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) {
 	// 14 bytes
 	for i := 1; i <= 14; i++ {
 		b := byte(' ')
@@ -93,10 +93,10 @@
 	return pkt, nil
 }
 
-func GetSerialNumber(pos *uint, pkt []byte) ([]byte, error) {
+func GetSerialNumber(pos *uint, pkt []byte, key OnuKey) ([]byte, error) {
 	// 8 bytes
 	vendorid := []byte("BBSM")
-	serialhex := []byte{0x00, 0x00, 0x00, 0x01}
+	serialhex := []byte{0x00, byte(key.OltId % 256), byte(key.IntfId), byte(key.OnuId)}
 	serialnumber := append(vendorid, serialhex...)
 	for _, ch := range serialnumber {
 		pkt[*pos] = ch
@@ -105,49 +105,49 @@
 	return pkt, nil
 }
 
-func GetTrafficManagementOptions(pos *uint, pkt []byte) ([]byte, error) {
+func GetTrafficManagementOptions(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) {
 	// 1 byte
 	pkt[*pos] = 0x00
 	*pos++
 	return pkt, nil
 }
 
-func GetVpVcCrossConnectOptions(pos *uint, pkt []byte) ([]byte, error) {
+func GetVpVcCrossConnectOptions(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) {
 	// 1 byte
 	pkt[*pos] = 0x00
 	*pos++
 	return pkt, nil
 }
 
-func GetBatteryBackup(pos *uint, pkt []byte) ([]byte, error) {
+func GetBatteryBackup(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) {
 	// 1 byte
 	pkt[*pos] = 0x00
 	*pos++
 	return pkt, nil
 }
 
-func GetAdministrativeState(pos *uint, pkt []byte) ([]byte, error) {
+func GetAdministrativeState(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) {
 	// 1 byte
 	pkt[*pos] = 0x00
 	*pos++
 	return pkt, nil
 }
 
-func GetOperationalState(pos *uint, pkt []byte) ([]byte, error) {
+func GetOperationalState(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) {
 	// 1 byte
 	pkt[*pos] = 0x00
 	*pos++
 	return pkt, nil
 }
 
-func GetOntSurvivalTime(pos *uint, pkt []byte) ([]byte, error) {
+func GetOntSurvivalTime(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) {
 	// 1 byte
 	pkt[*pos] = 0x00
 	*pos++
 	return pkt, nil
 }
 
-func GetLogicalOnuID(pos *uint, pkt []byte) ([]byte, error) {
+func GetLogicalOnuID(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) {
 	// 24 bytes
 	for i := 1; i <= 24; i++ {
 		b := byte(' ')
@@ -157,7 +157,7 @@
 	return pkt, nil
 }
 
-func GetLogicalPassword(pos *uint, pkt []byte) ([]byte, error) {
+func GetLogicalPassword(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) {
 	// 24 bytes
 	for i := 1; i <= 24; i++ {
 		b := byte(' ')
@@ -167,14 +167,14 @@
 	return pkt, nil
 }
 
-func GetCredentialsStatus(pos *uint, pkt []byte) ([]byte, error) {
+func GetCredentialsStatus(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) {
 	// 1 byte
 	pkt[*pos] = 0x00
 	*pos++
 	return pkt, nil
 }
 
-func GetExtendedTcLayerOptions(pos *uint, pkt []byte) ([]byte, error) {
+func GetExtendedTcLayerOptions(pos *uint, pkt []byte, _ OnuKey) ([]byte, error) {
 	// 2 bytes
 	tcbits := []byte{0x00, 0x00}
 	for _, ch := range tcbits {
diff --git a/omci_sim.go b/omci_sim.go
index 6195168..e1ea77f 100644
--- a/omci_sim.go
+++ b/omci_sim.go
@@ -27,7 +27,7 @@
 	return omciCh
 }
 
-func OmciSim(intfId uint32, onuId uint32, request []byte) ([]byte, error) {
+func OmciSim(oltId int, intfId uint32, onuId uint32, request []byte) ([]byte, error) {
 	var resp []byte
 
 	transactionId, deviceId, msgType, class, instance, content, err := ParsePkt(request)
@@ -50,7 +50,7 @@
 		"omciMsg": fmt.Sprintf("%x", content),
 	}).Tracef("Processing OMCI packet")
 
-	key := OnuKey{intfId, onuId}
+	key := OnuKey{OltId: oltId, IntfId: intfId, OnuId: onuId}
 	OnuOmciStateMapLock.Lock()
 	if _, ok := OnuOmciStateMap[key]; !ok {
 		OnuOmciStateMap[key] = NewOnuOmciState()
diff --git a/omci_state.go b/omci_state.go
index ddb9921..d1b4332 100644
--- a/omci_state.go
+++ b/omci_state.go
@@ -19,7 +19,6 @@
 	"errors"
 	"fmt"
 	"sync"
-	log "github.com/sirupsen/logrus"
 )
 
 type OnuOmciState struct {
@@ -61,8 +60,8 @@
 	s.tcontPointer = 0
 	s.priorQPriority = 0
 }
-func GetOnuOmciState(intfId uint32, onuId uint32) istate {
-	key := OnuKey{intfId, onuId}
+func GetOnuOmciState(oltId int, intfId uint32, onuId uint32) istate {
+	key := OnuKey{oltId,intfId, onuId}
 	OnuOmciStateMapLock.RLock()
 	defer OnuOmciStateMapLock.RUnlock()
 	if onu, ok := OnuOmciStateMap[key]; ok {
@@ -72,8 +71,8 @@
 	}
 }
 
-func GetGemPortId(intfId uint32, onuId uint32) (uint16, error) {
-	key := OnuKey{intfId, onuId}
+func GetGemPortId(oltId int, intfId uint32, onuId uint32) (uint16, error) {
+	key := OnuKey{oltId, intfId, onuId}
 	OnuOmciStateMapLock.RLock()
 	defer OnuOmciStateMapLock.RUnlock()
 	if OnuOmciState, ok := OnuOmciStateMap[key]; ok {
@@ -86,8 +85,3 @@
 	errmsg := fmt.Sprintf("ONU {intfid:%d, onuid:%d} - Failed to find a key in OnuOmciStateMap", intfId, onuId)
 	return 0, errors.New(errmsg)
 }
-
-func CheckIsTeo() string {
-	log.Warn("It's TEO!")
-	return "It's TEO!"
-}