blob: 938506bfa508ef874e959fe766b183c32d428b54 [file] [log] [blame]
irinab2e5e2b2019-09-03 13:42:05 +03001/*******************************************************************************
2 *
3 * Copyright (c) 2019 AT&T Intellectual Property.
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 *******************************************************************************/
rh362jce7bdb12019-08-28 15:13:48 +030018package e2pdus
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_request_wrapper.h>
24import "C"
25import (
26 "fmt"
27 "github.com/pkg/errors"
28 "unsafe"
29)
30
31const (
32 ShortMacro_eNB_ID = 18
33 Macro_eNB_ID = 20
34 LongMacro_eNB_ID = 21
35 Home_eNB_ID = 28
36)
37
38var PackedEndcX2setupRequest []byte
39var PackedX2setupRequest []byte
40var PackedEndcX2setupRequestAsString string
41var PackedX2setupRequestAsString string
42
irinab2e5e2b2019-09-03 13:42:05 +030043func PreparePackedEndcX2SetupRequest(maxAsn1PackedBufferSize int, maxAsn1CodecMessageBufferSize int, pLMNId []byte, eNB_Id []byte /*18, 20, 21, 28 bits length*/, bitqty uint, ricFlag []byte) ([]byte, string, error) {
rh362jce7bdb12019-08-28 15:13:48 +030044 packedBuf := make([]byte, maxAsn1PackedBufferSize)
45 errBuf := make([]C.char, maxAsn1CodecMessageBufferSize)
46 packedBufSize := C.ulong(len(packedBuf))
47 pduAsString := ""
48
49 if !C.build_pack_endc_x2setup_request(
irinab2e5e2b2019-09-03 13:42:05 +030050 (*C.uchar)(unsafe.Pointer(&pLMNId[0])) /*pLMN_Identity*/,
51 (*C.uchar)(unsafe.Pointer(&eNB_Id[0])),
52 C.uint(bitqty),
53 (*C.uchar)(unsafe.Pointer(&ricFlag[0])) /*pLMN_Identity*/,
54 &packedBufSize,
55 (*C.uchar)(unsafe.Pointer(&packedBuf[0])),
56 C.ulong(len(errBuf)),
57 &errBuf[0]) {
rh362jce7bdb12019-08-28 15:13:48 +030058 return nil, "", errors.New(fmt.Sprintf("packing error: %s", C.GoString(&errBuf[0])))
59 }
60
irinab2e5e2b2019-09-03 13:42:05 +030061 pdu := C.new_pdu(C.size_t(1)) //TODO: change signature
rh362jce7bdb12019-08-28 15:13:48 +030062 defer C.delete_pdu(pdu)
irinab2e5e2b2019-09-03 13:42:05 +030063 if C.per_unpack_pdu(pdu, packedBufSize, (*C.uchar)(unsafe.Pointer(&packedBuf[0])), C.size_t(len(errBuf)), &errBuf[0]) {
rh362jce7bdb12019-08-28 15:13:48 +030064 C.asn1_pdu_printer(pdu, C.size_t(len(errBuf)), &errBuf[0])
65 pduAsString = C.GoString(&errBuf[0])
66 }
67
68 return packedBuf[:packedBufSize], pduAsString, nil
69}
70
irinab2e5e2b2019-09-03 13:42:05 +030071func PreparePackedX2SetupRequest(maxAsn1PackedBufferSize int, maxAsn1CodecMessageBufferSize int, pLMNId []byte, eNB_Id []byte /*18, 20, 21, 28 bits length*/, bitqty uint, ricFlag []byte) ([]byte, string, error) {
rh362jce7bdb12019-08-28 15:13:48 +030072 packedBuf := make([]byte, maxAsn1PackedBufferSize)
73 errBuf := make([]C.char, maxAsn1CodecMessageBufferSize)
74 packedBufSize := C.ulong(len(packedBuf))
75 pduAsString := ""
76
77 if !C.build_pack_x2setup_request(
78 (*C.uchar)(unsafe.Pointer(&pLMNId[0])) /*pLMN_Identity*/,
79 (*C.uchar)(unsafe.Pointer(&eNB_Id[0])),
80 C.uint(bitqty),
81 (*C.uchar)(unsafe.Pointer(&ricFlag[0])) /*pLMN_Identity*/,
82 &packedBufSize,
83 (*C.uchar)(unsafe.Pointer(&packedBuf[0])),
84 C.ulong(len(errBuf)),
85 &errBuf[0]) {
86 return nil, "", errors.New(fmt.Sprintf("packing error: %s", C.GoString(&errBuf[0])))
87 }
88
irinab2e5e2b2019-09-03 13:42:05 +030089 pdu := C.new_pdu(C.size_t(1)) //TODO: change signature
rh362jce7bdb12019-08-28 15:13:48 +030090 defer C.delete_pdu(pdu)
irinab2e5e2b2019-09-03 13:42:05 +030091 if C.per_unpack_pdu(pdu, packedBufSize, (*C.uchar)(unsafe.Pointer(&packedBuf[0])), C.size_t(len(errBuf)), &errBuf[0]) {
rh362jce7bdb12019-08-28 15:13:48 +030092 C.asn1_pdu_printer(pdu, C.size_t(len(errBuf)), &errBuf[0])
93 pduAsString = C.GoString(&errBuf[0])
94 }
95 return packedBuf[:packedBufSize], pduAsString, nil
96}