blob: f72707c77d747e0fb3d21d2507065d07e1e9b63a [file] [log] [blame]
package control
/*
#include <e2sm/wrapper.h>
#cgo LDFLAGS: -le2smwrapper -lm
#cgo CFLAGS: -I/usr/local/include/e2sm
*/
import "C"
import (
"errors"
"gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
"unsafe"
_ "log"
_"encoding/binary"
"encoding/hex"
"strings"
"strconv"
)
type E2sm struct {
}
func (c *E2sm) SetRicControlHeader(buffer []byte, ueIdData *UEid, ricControlStyleType int64, ricControlActionID int64) (newBuffer []byte, err error) {
xapp.Logger.Info("SetRicControlHeader Enter \n")
cptr := unsafe.Pointer(&buffer[0])
//cptr_ueIDbuf := unsafe.Pointer(&ueIDbuf[0])
lplmnIdBuf := strings.Join(strings.Fields(ueIdData.pLMNIdentitybuf), "")
lIntvar, _ := strconv.Atoi(lplmnIdBuf)
xapp.Logger.Info("lIntvar = %d\n", lIntvar)
lIntegerByte := ConverIntegerToByte(lIntvar)
//ml.MavLog(ml.INFO, lTransId, " lIntegerByte = %v\n", lIntegerByte)
xapp.Logger.Info(" lIntegerByte = %v\n", lIntegerByte)
lOutByte := get_bytepack_plmnId(lIntegerByte)
xapp.Logger.Info("lOutByte Len:%d\n", len(lOutByte))
xapp.Logger.Info("lOutByte = %02X\n", lOutByte)
cptrRanParameterValue := unsafe.Pointer(&lOutByte[0])
pLMNIdentity := C.CString(ueIdData.pLMNIdentitybuf)
defer C.free(unsafe.Pointer(pLMNIdentity))
pLMNIdentity_size := C.size_t(len(ueIdData.pLMNIdentitybuf))
aMFRegionID := C.CString(ueIdData.aMFRegionIDbuf)
defer C.free(unsafe.Pointer(aMFRegionID))
aMFSetID := C.CString(ueIdData.aMFSetIDbuf)
defer C.free(unsafe.Pointer(aMFSetID))
aMFPointer := C.CString(ueIdData.aMFPointerbuf)
defer C.free(unsafe.Pointer(aMFPointer))
uEID_C := C.struct_uEID{
amf_UE_NGAP_Id: C.long(ueIdData.amf_UE_NGAP_Id),
pLMNIdentity : pLMNIdentity,
pLMNIdentity_size : pLMNIdentity_size,
aMFRegionID : aMFRegionID,
aMFRegionID_size : 1, //AMFRegionID ::= BIT STRING (SIZE(8))
aMFSetID : aMFSetID,
aMFSetID_size: 2, //BIT STRING (SIZE(10))
aMFPointer : aMFPointer,
aMFPointer_size : 1, //BIT STRING (SIZE(6))
}
xapp.Logger.Debug("uEID_C amf_UE_NGAP_Id = %l",uEID_C.amf_UE_NGAP_Id)
xapp.Logger.Debug("uEID_C pLMNIdentity = %s",uEID_C.pLMNIdentity)
xapp.Logger.Debug("uEID_C aMFRegionID %s = ",uEID_C.aMFRegionID)
xapp.Logger.Debug("uEID_C aMFSetID %s = ",uEID_C.aMFSetID)
xapp.Logger.Debug("uEID_C aMFPointer %s = ",uEID_C.aMFPointer)
size := C.e2sm_encode_ric_control_header(cptr, C.size_t(len(buffer)),&uEID_C ,(*C.long)(&ueIdData.F1AP_id[0]),C.size_t(len(ueIdData.F1AP_id)),(*C.long)(&ueIdData.E1AP_id[0]),C.size_t(len(ueIdData.E1AP_id)),(C.long)(ricControlStyleType), (C.long)(ricControlActionID), cptrRanParameterValue,C.size_t(len(lOutByte)))
//size := C.e2sm_encode_ric_control_header(cptr, C.size_t(len(buffer)),&uEID_C ,(*C.long)(&ueIdData.F1AP_id[0]),(*C.long)(&ueIdData.E1AP_id[0]),(C.long)(ricControlStyleType), (C.long)(ricControlActionID))
if size < 0 {
return make([]byte, 0), errors.New("e2sm wrapper is unable to set EventTriggerDefinition due to wrong or invalid input")
}
newBuffer = C.GoBytes(cptr, (C.int(size)+7)/8)
xapp.Logger.Info("E2sm SetRicControlHeader is success")
return
}
func (c *E2sm) SetRicControlMessage(buffer []byte, targetPrimaryCell int64, targetCell int64, nrCGIOrECGI int64, nrOrEUtraCell int64, ranParameterValue []byte) (newBuffer []byte, err error) {
xapp.Logger.Info("SetRicControlMessagei Enter ")
cptr := unsafe.Pointer(&buffer[0])
cptrRanParameterValue := unsafe.Pointer(&ranParameterValue[0])
/*
lIntvar, _ := strconv.Atoi(string(ranParameterValue))
xapp.Logger.Info("lIntvar %d\n", lIntvar)
lIntegerByte := ConverIntegerToByte(lIntvar)
xapp.Logger.Info("lIntegerByte %v\n", lIntegerByte)
lOutByte := get_bytepack_plmnId(lIntegerByte)
xapp.Logger.Info("lOutByte Len:%d\n", len(lOutByte))
xapp.Logger.Info("lOutByte %02X\n", lOutByte)
cptrRanParameterValue := unsafe.Pointer(&lOutByte[0])
xapp.Logger.Info("cptrRanParameterValue = %v\n ", cptrRanParameterValue)
*/
size := C.e2sm_encode_ric_control_message(cptr, C.size_t(len(buffer)), C.long(targetPrimaryCell),
C.long(targetCell), C.long(nrOrEUtraCell), C.long(nrCGIOrECGI), cptrRanParameterValue, C.size_t(len(ranParameterValue)))
if size < 0 {
return make([]byte, 0), errors.New("e2sm wrapper is unable to set RicControlMessage due to wrong or invalid input")
}
newBuffer = C.GoBytes(cptr, (C.int(size)+7)/8) //TOCHECK: if C.int(size) is returning bits not bytes to get correct size of the buffer.
xapp.Logger.Info("E2sm SetRicControlMessage is success")
return
}
func (c *E2sm) GetControlOutcome(buffer []byte) (controlOutcome *ControlOutcomeMsg, err error) {
cptr := unsafe.Pointer(&buffer[0])
controlOutcome = &ControlOutcomeMsg{}
//lTransId := gTransIdDefVal
//ml.MavLog(ml.INFO, lTransId, "Decode Control Outcome: ")
xapp.Logger.Info("Decode Control Outcome: ")
decodedMsg := C.e2sm_decode_ric_call_process_outcome(cptr, C.size_t(len(buffer)))
defer C.e2sm_free_ric_call_process_outcome(decodedMsg)
if decodedMsg == nil {
return controlOutcome, errors.New("e2sm wrapper is unable to get ControlOutcome due to wrong or invalid input")
}
//ml.MavLog(ml.INFO, lTransId, "Decoded Control Outcome: ")
controlOutcome.ControlOutcomeType = int32(decodedMsg.ric_controlOutcome_formats.present)
if controlOutcome.ControlOutcomeType == 1 {
controlOutcome := &ControlOutcomeFormat1{}
controlOutcomeFormat1_C := *(**C.E2SM_RC_ControlOutcome_Format1_t)(unsafe.Pointer(&decodedMsg.ric_controlOutcome_formats.choice[0]))
controlOutcome.ControlOutcomeFormat1ItemCount = int(controlOutcomeFormat1_C.ranP_List.list.count)
controlOutcome.ControlOutcomeFormat1Item = make([]ControlOutcomeFormat1ItemType, controlOutcome.ControlOutcomeFormat1ItemCount +1)
//ml.MavLog(ml.INFO, lTransId, "RIC Control Outcome Format1 Item Count = %d ", controlOutcome.ControlOutcomeFormat1ItemCount)
for i := 0; i < controlOutcome.ControlOutcomeFormat1ItemCount; i++ {
ControlOutcomeFormat1Item := &controlOutcome.ControlOutcomeFormat1Item[i]
var sizeof_E2SM_RC_ControlOutcome_Format1_Item_t *C.E2SM_RC_ControlOutcome_Format1_Item_t
ControlOutcomeFormat1Item_C := *(*(**C.E2SM_RC_ControlOutcome_Format1_Item_t)(unsafe.Pointer(uintptr(unsafe.Pointer(controlOutcomeFormat1_C.ranP_List.list.array)) + (uintptr)(i)*unsafe.Sizeof(sizeof_E2SM_RC_ControlOutcome_Format1_Item_t))))
ControlOutcomeFormat1Item.RanParameterID = int64(ControlOutcomeFormat1Item_C.ranParameter_ID)
ControlOutcomeFormat1Item.RANParameterValueType = int(ControlOutcomeFormat1Item_C.ranParameter_value.present)
ranParameterValue_C := (C.RANParameter_Value_t)(ControlOutcomeFormat1Item_C.ranParameter_value)
if ControlOutcomeFormat1Item.RANParameterValueType == 5 {
//ml.MavLog(ml.INFO, lTransId, "RANParameterValueType is RANParameter_Value_PR_valueOctS")
ranParameterValue := &OctetString{}
ranParameter_C := (*C.OCTET_STRING_t)(unsafe.Pointer(&ranParameterValue_C.choice[0]))
ranParameterValue.Size = int(ranParameter_C.size)
ranParameterValue.Buf = C.GoBytes(unsafe.Pointer(ranParameter_C.buf), C.int(ranParameter_C.size))
ControlOutcomeFormat1Item.RANParameterValue = ranParameterValue
//ml.MavLog(ml.INFO, lTransId, "RANParameterValue = ", ControlOutcomeFormat1Item.RANParameterValue)
}
}
} else {
return controlOutcome, errors.New("Unknown RIC Control Outcome type")
}
return controlOutcome , err
}
func (c *E2sm) get_plmn_from_mcc_mnc(plmnIdBuf []byte)(bytePackedPlmnId []uint8) {
//lTransId := gTransIdDefVal
hexResp, _ := hex.DecodeString(string(plmnIdBuf))
//ml.MavLog(ml.INFO, lTransId, "get_plmn_from_mcc_mnc plmnIdBuf and hexResp = ", plmnIdBuf,hexResp)
var mcc []uint8 = make([]uint8, 3)
var mnc []uint8 = make([]uint8, 3)
mcc[0] = hexResp[0] >> 4
mcc[1] = hexResp[0] & 0xf
mcc[2] = hexResp[1] >> 4
mnc[0] = hexResp[1] & 0xf
mnc[1] = hexResp[2] >> 4
mnc[2] = hexResp[2] & 0xf
var tmpPlmnId []uint8 = make([]uint8, 6)
tmpPlmnId[0] = mcc[0]
tmpPlmnId[1] = mcc[1]
tmpPlmnId[2] = mcc[2]
if len(mcc) == 2 {
tmpPlmnId[3] = 0x0f
tmpPlmnId[4] = mnc[0]
tmpPlmnId[5] = mnc[1]
} else {
tmpPlmnId[3] = mnc[0]
tmpPlmnId[4] = mnc[1]
tmpPlmnId[5] = mnc[2]
}
//ml.MavLog(ml.INFO, lTransId, "\n tmpPlmnId " , tmpPlmnId)
bytePackedPlmnId = make([]uint8,3)
bytePackedPlmnId[0] = ((tmpPlmnId[1] & 0x0F) << 4) | (tmpPlmnId[0] & 0x0F)
bytePackedPlmnId[1] = ((tmpPlmnId[3] & 0x0F) << 4) | (tmpPlmnId[2] & 0x0F)
bytePackedPlmnId[2] = ((tmpPlmnId[5] & 0x0F) << 4) | (tmpPlmnId[4] & 0x0F)
//ml.MavLog(ml.INFO, lTransId, "\n bytePackedPlmnId " , bytePackedPlmnId)
return
}