456b6d03c7830cc32b9a12755dd24b3ac85dcc32
[ric-app/rc.git] / control / rcE2AP.go
1 /*
2 ==================================================================================
3   Copyright (c) 2019 AT&T Intellectual Property.
4   Copyright (c) 2019 Nokia
5
6    Licensed under the Apache License, Version 2.0 (the "License");
7    you may not use this file except in compliance with the License.
8    You may obtain a copy of the License at
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" BASIS,
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    See the License for the specific language governing permissions and
16    limitations under the License.
17 ==================================================================================
18 */
19
20 package control
21
22 /*
23 #include <stdlib.h>
24 #include <e2ap/wrapper.h>
25 #cgo LDFLAGS: -le2apwrapper
26 #cgo CFLAGS: -I/usr/local/include/e2ap
27 */
28 import "C"
29
30 import (
31         "errors"
32         "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
33         "unsafe"
34 )
35
36 type E2ap struct {
37 }
38
39 func (c *E2ap) SetRicControlRequestPayload(payload []byte, ricRequestorID uint16, ricRequestSequenceNumber uint16, ranFunctionID uint16,
40         ricControlHdr []byte, ricControlMsg []byte) (newPayload []byte, err error) {
41
42         cptr := unsafe.Pointer(&payload[0])
43         cptr_ricControlHdr := unsafe.Pointer(&ricControlHdr[0])
44         cptr_ricControlMsg := unsafe.Pointer(&ricControlMsg[0])
45
46         xapp.Logger.Debug("\n")
47         xapp.Logger.Debug("ricControlHdr\n", ricControlHdr)
48         xapp.Logger.Debug("\n")
49         xapp.Logger.Debug("ricControlMsg\n", ricControlMsg)
50         xapp.Logger.Debug("\n")
51
52         size := C.e2ap_encode_ric_control_request_message(cptr, C.size_t(len(payload)), C.long(ricRequestorID), C.long(ricRequestSequenceNumber),
53                 C.long(ranFunctionID), cptr_ricControlHdr, C.size_t(len(ricControlHdr)), cptr_ricControlMsg, C.size_t(len(ricControlMsg)))
54         if size < 0 {
55                 return make([]byte, 0), errors.New("e2ap wrapper is unable to set Subscription Request Payload due to wrong or invalid payload")
56         }
57         newPayload = C.GoBytes(cptr, (C.int(size)+7)/8)
58         xapp.Logger.Info("SetRicControlHeader is success")
59         return
60 }
61