c6b5e285f453fdaba19ab5b9160bceff45739539
[ric-plt/submgr.git] / pkg / control / e2ap.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 <wrapper.h>
24
25 #cgo LDFLAGS: -lwrapper
26 */
27 import "C"
28
29 import (
30         "errors"
31         "unsafe"
32 )
33
34 type E2ap struct {
35 }
36
37 func (c *E2ap) GetSubscriptionRequestSequenceNumber(payload []byte) (sub_id uint16, err error) {
38         cptr := unsafe.Pointer(&payload[0])
39         cret := C.e2ap_get_ric_subscription_request_sequence_number(cptr, C.size_t(len(payload)))
40         if cret < 0 {
41                 return 0, errors.New("e2ap wrapper is unable to get Subscirption Request Sequence Number due to wrong or invalid payload")
42         }
43         sub_id = uint16(cret)
44         return
45 }
46
47 func (c *E2ap) SetSubscriptionRequestSequenceNumber(payload []byte, newSubscriptionid uint16) (new_payload []byte, err error) {
48         cptr := unsafe.Pointer(&payload[0])
49         size := C.e2ap_set_ric_subscription_request_sequence_number(cptr, C.size_t(len(payload)), C.long(newSubscriptionid))
50         if size < 0 {
51                 return make([]byte, 0), errors.New("e2ap wrapper is unable to set Subscirption Request Sequence Number due to wrong or invalid payload")
52         }
53         new_payload = C.GoBytes(cptr, C.int(size))
54         return
55 }
56
57 func (c *E2ap) GetSubscriptionResponseSequenceNumber(payload []byte) (sub_id uint16, err error) {
58         cptr := unsafe.Pointer(&payload[0])
59         cret := C.e2ap_get_ric_subscription_response_sequence_number(cptr, C.size_t(len(payload)))
60         if cret < 0 {
61                 return 0, errors.New("e2ap wrapper is unable to get Subscirption Response Sequence Number due to wrong or invalid payload")
62         }
63         sub_id = uint16(cret)
64         return
65 }
66
67 func (c *E2ap) SetSubscriptionResponseSequenceNumber(payload []byte, newSubscriptionid uint16) (new_payload []byte, err error) {
68         cptr := unsafe.Pointer(&payload[0])
69         size := C.e2ap_set_ric_subscription_response_sequence_number(cptr, C.size_t(len(payload)), C.long(newSubscriptionid))
70         if size < 0 {
71                 return make([]byte, 0), errors.New("e2ap wrapper is unable to set Subscirption Reponse Sequence Number due to wrong or invalid payload")
72         }
73         new_payload = C.GoBytes(cptr, C.int(size))
74         return
75 }