2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
20 // #cgo CFLAGS: -I../asn1codec/inc/ -I../asn1codec/e2ap_engine/
21 // #cgo LDFLAGS: -L ../asn1codec/lib/ -L../asn1codec/e2ap_engine/ -le2ap_codec -lasncodec
22 // #include <asn1codec_utils.h>
23 // #include <x2setup_response_wrapper.h>
27 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
35 // The following are possible values of a choice field, find which the pdu contains.
36 func getCause(causeIE *C.Cause_t, setupFailure *entities.SetupFailure) error {
37 switch causeIE.present {
38 case C.Cause_PR_radioNetwork:
39 v := (*C.CauseRadioNetwork_t)(unsafe.Pointer(&causeIE.choice[0]))
40 setupFailure.CauseGroup = &entities.SetupFailure_NetworkLayerCause{NetworkLayerCause: entities.RadioNetworkLayer_Cause(1 + *v)}
41 case C.Cause_PR_transport:
42 v := (*C.CauseTransport_t)(unsafe.Pointer(&causeIE.choice[0]))
43 setupFailure.CauseGroup = &entities.SetupFailure_TransportLayerCause{TransportLayerCause: entities.TransportLayer_Cause(1 + *v)}
44 case C.Cause_PR_protocol:
45 v := (*C.CauseProtocol_t)(unsafe.Pointer(&causeIE.choice[0]))
46 setupFailure.CauseGroup = &entities.SetupFailure_ProtocolCause{ProtocolCause: entities.Protocol_Cause(1 + *v)}
48 v := (*C.CauseMisc_t)(unsafe.Pointer(&causeIE.choice[0]))
49 setupFailure.CauseGroup = &entities.SetupFailure_MiscellaneousCause{MiscellaneousCause: entities.Miscellaneous_Cause(1 + *v)}
54 func getCriticalityDiagnostics(critDiagIE *C.CriticalityDiagnostics_t) (*entities.CriticalityDiagnostics, error) {
55 var critDiag *entities.CriticalityDiagnostics
57 if critDiagIE.procedureCode != nil {
58 critDiag = &entities.CriticalityDiagnostics{}
59 critDiag.ProcedureCode = uint32(*critDiagIE.procedureCode)
63 if critDiagIE.triggeringMessage != nil {
65 critDiag = &entities.CriticalityDiagnostics{}
67 critDiag.TriggeringMessage = entities.TriggeringMessage(1 + *critDiagIE.triggeringMessage)
71 if critDiagIE.procedureCriticality != nil {
73 critDiag = &entities.CriticalityDiagnostics{}
75 critDiag.ProcedureCriticality = entities.Criticality(1 + *critDiagIE.procedureCriticality)
79 if critDiagIE.iEsCriticalityDiagnostics != nil && critDiagIE.iEsCriticalityDiagnostics.list.count > 0 && critDiagIE.iEsCriticalityDiagnostics.list.count < maxNrOfErrors {
81 critDiag = &entities.CriticalityDiagnostics{}
83 var infoElements []*entities.InformationElementCriticalityDiagnostic
84 iEsCriticalityDiagnostics := (*C.CriticalityDiagnostics_IE_List_t)(critDiagIE.iEsCriticalityDiagnostics)
85 count:=int(iEsCriticalityDiagnostics.list.count)
86 iEsCriticalityDiagnostics_slice := (*[1 << 30]*C.CriticalityDiagnostics_IE_List__Member)(unsafe.Pointer(iEsCriticalityDiagnostics.list.array))[:count:count]
87 for _, criticalityDiagnostics_IE_List__Member := range iEsCriticalityDiagnostics_slice {
88 infoElement := &entities.InformationElementCriticalityDiagnostic{IeCriticality: entities.Criticality(1 + criticalityDiagnostics_IE_List__Member.iECriticality)}
89 infoElement.IeId = uint32(criticalityDiagnostics_IE_List__Member.iE_ID)
90 infoElement.TypeOfError = entities.TypeOfError(1 + criticalityDiagnostics_IE_List__Member.typeOfError)
92 infoElements = append(infoElements, infoElement)
95 critDiag.InformationElementCriticalityDiagnostics = infoElements
101 // Populate and return the EN-DC/X2 setup response failure structure with data from the pdu
102 func x2SetupFailureResponseToProtobuf(pdu *C.E2AP_PDU_t) (*entities.SetupFailure, error) {
103 setupFailure := entities.SetupFailure{}
105 if pdu.present == C.E2AP_PDU_PR_unsuccessfulOutcome {
106 //dereference a union of pointers (C union is represented as a byte array with the size of the largest member)
107 unsuccessfulOutcome := *(**C.UnsuccessfulOutcome_t)(unsafe.Pointer(&pdu.choice[0]))
108 if unsuccessfulOutcome != nil && unsuccessfulOutcome.value.present == C.UnsuccessfulOutcome__value_PR_X2SetupFailure {
109 x2SetupFailure := (*C.X2SetupFailure_t)(unsafe.Pointer(&unsuccessfulOutcome.value.choice[0]))
110 if x2SetupFailure != nil && x2SetupFailure.protocolIEs.list.count > 0 {
111 count:=int(x2SetupFailure.protocolIEs.list.count)
112 x2SetupFailure_IEs_slice := (*[1 << 30]*C.X2SetupFailure_IEs_t)(unsafe.Pointer(x2SetupFailure.protocolIEs.list.array))[:count:count]
113 for _, x2SetupFailure_IE := range x2SetupFailure_IEs_slice {
114 if x2SetupFailure_IE != nil {
115 switch x2SetupFailure_IE.value.present {
116 case C.X2SetupFailure_IEs__value_PR_Cause:
117 causeIE := (*C.Cause_t)(unsafe.Pointer(&x2SetupFailure_IE.value.choice[0]))
118 err := getCause(causeIE, &setupFailure)
122 case C.X2SetupFailure_IEs__value_PR_TimeToWait:
123 setupFailure.TimeToWait = entities.TimeToWait(1 + *((*C.TimeToWait_t)(unsafe.Pointer(&x2SetupFailure_IE.value.choice[0]))))
124 case C.X2SetupFailure_IEs__value_PR_CriticalityDiagnostics:
125 cdIE := (*C.CriticalityDiagnostics_t)(unsafe.Pointer(&x2SetupFailure_IE.value.choice[0]))
126 if cd, err := getCriticalityDiagnostics(cdIE); err == nil {
127 setupFailure.CriticalityDiagnostics = cd
138 return &setupFailure, nil
141 func unpackX2SetupFailureResponseAndExtract(logger *logger.Logger, allocationBufferSize int, packedBufferSize int, packedBuf []byte, maxMessageBufferSize int) (*entities.SetupFailure, error) {
142 pdu, err := unpackX2apPdu(logger, allocationBufferSize, packedBufferSize, packedBuf, maxMessageBufferSize)
147 defer C.delete_pdu(pdu)
149 return x2SetupFailureResponseToProtobuf(pdu)