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 <SuccessfulOutcome.h>
29 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
33 type X2ResetResponseExtractor struct {
37 func NewX2ResetResponseExtractor(logger *logger.Logger) *X2ResetResponseExtractor {
38 return &X2ResetResponseExtractor{
43 type IX2ResetResponseExtractor interface {
44 ExtractCriticalityDiagnosticsFromPdu(packedBuffer []byte) (*entities.CriticalityDiagnostics, error)
47 func (e *X2ResetResponseExtractor) ExtractCriticalityDiagnosticsFromPdu(packedBuffer []byte) (*entities.CriticalityDiagnostics, error) {
48 pdu, err := UnpackX2apPdu(e.logger, e2pdus.MaxAsn1CodecAllocationBufferSize, len(packedBuffer), packedBuffer, e2pdus.MaxAsn1CodecMessageBufferSize)
54 if pdu.present != C.E2AP_PDU_PR_successfulOutcome {
55 return nil, fmt.Errorf("Invalid E2AP_PDU value")
58 successfulOutcome := *(**C.SuccessfulOutcome_t)(unsafe.Pointer(&pdu.choice[0]))
60 if successfulOutcome == nil || successfulOutcome.value.present != C.SuccessfulOutcome__value_PR_ResetResponse {
61 return nil, fmt.Errorf("Unexpected SuccessfulOutcome value")
64 resetResponse := (*C.ResetResponse_t)(unsafe.Pointer(&successfulOutcome.value.choice[0]))
66 protocolIEsListCount := resetResponse.protocolIEs.list.count
68 if protocolIEsListCount == 0 {
72 if protocolIEsListCount != 1 {
73 return nil, fmt.Errorf("Invalid protocolIEs list count")
76 resetResponseIEs := (*[1 << 30]*C.ResetResponse_IEs_t)(unsafe.Pointer(resetResponse.protocolIEs.list.array))[:int(protocolIEsListCount):int(protocolIEsListCount)]
78 resetResponseIE := resetResponseIEs[0]
80 if resetResponseIE.value.present != C.ResetResponse_IEs__value_PR_CriticalityDiagnostics {
81 return nil, fmt.Errorf("Invalid protocolIEs value")
84 cd := (*C.CriticalityDiagnostics_t)(unsafe.Pointer(&resetResponseIE.value.choice[0]))
86 return getCriticalityDiagnostics(cd)