ss412g | 07ef76d | 2019-08-12 17:26:40 +0300 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2019 AT&T Intellectual Property |
| 3 | // Copyright 2019 Nokia |
| 4 | // |
| 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 |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 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. |
| 16 | // |
| 17 | |
| 18 | package handlers |
| 19 | |
| 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> |
| 24 | import "C" |
| 25 | import ( |
| 26 | "e2mgr/logger" |
| 27 | "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" |
| 28 | "unsafe" |
| 29 | ) |
| 30 | |
| 31 | // Populate and return the EN-DC/X2 setup response failure structure with data from the pdu |
| 32 | func endcX2SetupFailureResponseToProtobuf(pdu *C.E2AP_PDU_t) (*entities.SetupFailure, error) { |
| 33 | setupFailure := entities.SetupFailure{} |
| 34 | |
| 35 | if pdu.present == C.E2AP_PDU_PR_unsuccessfulOutcome { |
| 36 | //dereference a union of pointers (C union is represented as a byte array with the size of the largest member) |
| 37 | unsuccessfulOutcome := *(**C.UnsuccessfulOutcome_t)(unsafe.Pointer(&pdu.choice[0])) |
| 38 | if unsuccessfulOutcome != nil && unsuccessfulOutcome.value.present == C.UnsuccessfulOutcome__value_PR_ENDCX2SetupFailure { |
| 39 | endcX2SetupFailure := (*C.ENDCX2SetupFailure_t)(unsafe.Pointer(&unsuccessfulOutcome.value.choice[0])) |
| 40 | if endcX2SetupFailure != nil && endcX2SetupFailure.protocolIEs.list.count > 0 { |
| 41 | count:=int(endcX2SetupFailure.protocolIEs.list.count) |
| 42 | endcX2SetupFailure_IEs_slice := (*[1 << 30]*C.ENDCX2SetupFailure_IEs_t)(unsafe.Pointer(endcX2SetupFailure.protocolIEs.list.array))[:count:count] |
| 43 | for _, endcX2SetupFailure_IE := range endcX2SetupFailure_IEs_slice { |
| 44 | if endcX2SetupFailure_IE != nil { |
| 45 | switch endcX2SetupFailure_IE.value.present { |
| 46 | case C.ENDCX2SetupFailure_IEs__value_PR_Cause: |
| 47 | causeIE := (*C.Cause_t)(unsafe.Pointer(&endcX2SetupFailure_IE.value.choice[0])) |
| 48 | err := getCause(causeIE, &setupFailure) |
| 49 | if err != nil { |
| 50 | return nil, err |
| 51 | } |
| 52 | case C.ENDCX2SetupFailure_IEs__value_PR_TimeToWait: |
| 53 | setupFailure.TimeToWait = entities.TimeToWait(1 + *((*C.TimeToWait_t)(unsafe.Pointer(&endcX2SetupFailure_IE.value.choice[0])))) |
| 54 | case C.ENDCX2SetupFailure_IEs__value_PR_CriticalityDiagnostics: |
| 55 | cdIE := (*C.CriticalityDiagnostics_t)(unsafe.Pointer(&endcX2SetupFailure_IE.value.choice[0])) |
| 56 | if cd, err := getCriticalityDiagnostics(cdIE); err == nil { |
| 57 | setupFailure.CriticalityDiagnostics = cd |
| 58 | } else { |
| 59 | return nil, err |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | return &setupFailure, nil |
| 69 | } |
| 70 | |
| 71 | func unpackEndcX2SetupFailureResponseAndExtract(logger *logger.Logger, allocationBufferSize int, packedBufferSize int, packedBuf []byte, maxMessageBufferSize int) (*entities.SetupFailure, error) { |
| 72 | pdu, err := unpackX2apPdu(logger, allocationBufferSize, packedBufferSize, packedBuf, maxMessageBufferSize) |
| 73 | if err != nil { |
| 74 | return nil, err |
| 75 | } |
| 76 | |
| 77 | defer C.delete_pdu(pdu) |
| 78 | |
| 79 | return endcX2SetupFailureResponseToProtobuf(pdu) |
| 80 | } |