9f3d3f8e38bff62cc13504670c62f027966d8551
[ric-plt/e2mgr.git] / E2Manager / e2pdus / x2_setup_requests.go
1 package e2pdus
2
3 // #cgo CFLAGS: -I../asn1codec/inc/ -I../asn1codec/e2ap_engine/
4 // #cgo LDFLAGS: -L ../asn1codec/lib/ -L../asn1codec/e2ap_engine/ -le2ap_codec -lasncodec
5 // #include <asn1codec_utils.h>
6 // #include <x2setup_request_wrapper.h>
7 import "C"
8 import (
9         "fmt"
10         "github.com/pkg/errors"
11         "unsafe"
12 )
13
14 const (
15         ShortMacro_eNB_ID = 18
16         Macro_eNB_ID      = 20
17         LongMacro_eNB_ID  = 21
18         Home_eNB_ID       = 28
19 )
20
21 var PackedEndcX2setupRequest []byte
22 var PackedX2setupRequest []byte
23 var PackedEndcX2setupRequestAsString string
24 var PackedX2setupRequestAsString string
25
26 func PreparePackedEndcX2SetupRequest(maxAsn1PackedBufferSize int, maxAsn1CodecMessageBufferSize int,pLMNId []byte, eNB_Id []byte /*18, 20, 21, 28 bits length*/, bitqty uint, ricFlag []byte) ([]byte, string, error) {
27         packedBuf := make([]byte, maxAsn1PackedBufferSize)
28         errBuf := make([]C.char, maxAsn1CodecMessageBufferSize)
29         packedBufSize := C.ulong(len(packedBuf))
30         pduAsString := ""
31
32         if !C.build_pack_endc_x2setup_request(
33                         (*C.uchar)(unsafe.Pointer(&pLMNId[0])) /*pLMN_Identity*/,
34                         (*C.uchar)(unsafe.Pointer(&eNB_Id[0])),
35                         C.uint(bitqty),
36                         (*C.uchar)(unsafe.Pointer(&ricFlag[0])) /*pLMN_Identity*/,
37                         &packedBufSize,
38                         (*C.uchar)(unsafe.Pointer(&packedBuf[0])),
39                         C.ulong(len(errBuf)),
40                         &errBuf[0]) {
41                 return nil, "", errors.New(fmt.Sprintf("packing error: %s", C.GoString(&errBuf[0])))
42         }
43
44         pdu:= C.new_pdu(C.size_t(1)) //TODO: change signature
45         defer C.delete_pdu(pdu)
46         if C.per_unpack_pdu(pdu, packedBufSize, (*C.uchar)(unsafe.Pointer(&packedBuf[0])),C.size_t(len(errBuf)), &errBuf[0]){
47                 C.asn1_pdu_printer(pdu, C.size_t(len(errBuf)), &errBuf[0])
48                 pduAsString = C.GoString(&errBuf[0])
49         }
50
51         return packedBuf[:packedBufSize], pduAsString, nil
52 }
53
54 func PreparePackedX2SetupRequest(maxAsn1PackedBufferSize int, maxAsn1CodecMessageBufferSize int,pLMNId []byte, eNB_Id []byte /*18, 20, 21, 28 bits length*/, bitqty uint, ricFlag []byte) ([]byte, string, error)  {
55         packedBuf := make([]byte, maxAsn1PackedBufferSize)
56         errBuf := make([]C.char, maxAsn1CodecMessageBufferSize)
57         packedBufSize := C.ulong(len(packedBuf))
58         pduAsString := ""
59
60         if !C.build_pack_x2setup_request(
61                 (*C.uchar)(unsafe.Pointer(&pLMNId[0])) /*pLMN_Identity*/,
62                 (*C.uchar)(unsafe.Pointer(&eNB_Id[0])),
63                 C.uint(bitqty),
64                 (*C.uchar)(unsafe.Pointer(&ricFlag[0])) /*pLMN_Identity*/,
65                 &packedBufSize,
66                 (*C.uchar)(unsafe.Pointer(&packedBuf[0])),
67                 C.ulong(len(errBuf)),
68                 &errBuf[0]) {
69                 return nil, "", errors.New(fmt.Sprintf("packing error: %s", C.GoString(&errBuf[0])))
70         }
71
72         pdu:= C.new_pdu(C.size_t(1)) //TODO: change signature
73         defer C.delete_pdu(pdu)
74         if C.per_unpack_pdu(pdu, packedBufSize, (*C.uchar)(unsafe.Pointer(&packedBuf[0])),C.size_t(len(errBuf)), &errBuf[0]){
75                 C.asn1_pdu_printer(pdu, C.size_t(len(errBuf)), &errBuf[0])
76                 pduAsString = C.GoString(&errBuf[0])
77         }
78         return packedBuf[:packedBufSize], pduAsString, nil
79 }
80