1 /*******************************************************************************
3 * Copyright (c) 2019 AT&T Intellectual Property.
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.
17 *******************************************************************************/
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_request_wrapper.h>
27 "github.com/pkg/errors"
32 ShortMacro_eNB_ID = 18
38 var PackedEndcX2setupRequest []byte
39 var PackedX2setupRequest []byte
40 var PackedEndcX2setupRequestAsString string
41 var PackedX2setupRequestAsString string
43 func PreparePackedEndcX2SetupRequest(maxAsn1PackedBufferSize int, maxAsn1CodecMessageBufferSize int, pLMNId []byte, eNB_Id []byte /*18, 20, 21, 28 bits length*/, bitqty uint, ricFlag []byte) ([]byte, string, error) {
44 packedBuf := make([]byte, maxAsn1PackedBufferSize)
45 errBuf := make([]C.char, maxAsn1CodecMessageBufferSize)
46 packedBufSize := C.ulong(len(packedBuf))
49 if !C.build_pack_endc_x2setup_request(
50 (*C.uchar)(unsafe.Pointer(&pLMNId[0])) /*pLMN_Identity*/,
51 (*C.uchar)(unsafe.Pointer(&eNB_Id[0])),
53 (*C.uchar)(unsafe.Pointer(&ricFlag[0])) /*pLMN_Identity*/,
55 (*C.uchar)(unsafe.Pointer(&packedBuf[0])),
58 return nil, "", errors.New(fmt.Sprintf("packing error: %s", C.GoString(&errBuf[0])))
61 pdu := C.new_pdu(C.size_t(1)) //TODO: change signature
62 defer C.delete_pdu(pdu)
63 if C.per_unpack_pdu(pdu, packedBufSize, (*C.uchar)(unsafe.Pointer(&packedBuf[0])), C.size_t(len(errBuf)), &errBuf[0]) {
64 C.asn1_pdu_printer(pdu, C.size_t(len(errBuf)), &errBuf[0])
65 pduAsString = C.GoString(&errBuf[0])
68 return packedBuf[:packedBufSize], pduAsString, nil
71 func PreparePackedX2SetupRequest(maxAsn1PackedBufferSize int, maxAsn1CodecMessageBufferSize int, pLMNId []byte, eNB_Id []byte /*18, 20, 21, 28 bits length*/, bitqty uint, ricFlag []byte) ([]byte, string, error) {
72 packedBuf := make([]byte, maxAsn1PackedBufferSize)
73 errBuf := make([]C.char, maxAsn1CodecMessageBufferSize)
74 packedBufSize := C.ulong(len(packedBuf))
77 if !C.build_pack_x2setup_request(
78 (*C.uchar)(unsafe.Pointer(&pLMNId[0])) /*pLMN_Identity*/,
79 (*C.uchar)(unsafe.Pointer(&eNB_Id[0])),
81 (*C.uchar)(unsafe.Pointer(&ricFlag[0])) /*pLMN_Identity*/,
83 (*C.uchar)(unsafe.Pointer(&packedBuf[0])),
86 return nil, "", errors.New(fmt.Sprintf("packing error: %s", C.GoString(&errBuf[0])))
89 pdu := C.new_pdu(C.size_t(1)) //TODO: change signature
90 defer C.delete_pdu(pdu)
91 if C.per_unpack_pdu(pdu, packedBufSize, (*C.uchar)(unsafe.Pointer(&packedBuf[0])), C.size_t(len(errBuf)), &errBuf[0]) {
92 C.asn1_pdu_printer(pdu, C.size_t(len(errBuf)), &errBuf[0])
93 pduAsString = C.GoString(&errBuf[0])
95 return packedBuf[:packedBufSize], pduAsString, nil