2 ==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
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
10 http://www.apache.org/licenses/LICENSE-2.0
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 ==================================================================================
24 #include <e2ap/wrapper.h>
25 #cgo LDFLAGS: -le2apwrapper
26 #cgo CFLAGS: -I/usr/local/include/e2ap
38 /* RICsubscriptionRequest */
40 func (c *E2ap) GetSubscriptionRequestSequenceNumber(payload []byte) (subId uint16, err error) {
41 cptr := unsafe.Pointer(&payload[0])
42 cret := C.e2ap_get_ric_subscription_request_sequence_number(cptr, C.size_t(len(payload)))
44 return 0, errors.New("e2ap wrapper is unable to get Subscirption Request Sequence Number due to wrong or invalid payload")
50 func (c *E2ap) SetSubscriptionRequestSequenceNumber(payload []byte, newSubscriptionid uint16) (newPayload []byte, err error) {
51 cptr := unsafe.Pointer(&payload[0])
52 size := C.e2ap_set_ric_subscription_request_sequence_number(cptr, C.size_t(len(payload)), C.long(newSubscriptionid))
54 return make([]byte, 0), errors.New("e2ap wrapper is unable to set Subscription Request Sequence Number due to wrong or invalid payload")
56 newPayload = C.GoBytes(cptr, (C.int(size)+7)/8)
60 func (c *E2ap) SetSubscriptionRequestPayload(payload []byte, ricRequestorID uint16, ricRequestSequenceNumber uint16, ranFunctionID uint16, eventTriggerDefinition []byte, eventTriggerDefinitionSize int, actionCount int, actionIds []int64, actionTypes []int64, actionDefinitions []ActionDefinition, subsequentActions []SubsequentAction) (newPayload []byte, err error) {
61 cptr := unsafe.Pointer(&payload[0])
62 eventTrigger := unsafe.Pointer(&eventTriggerDefinition[0])
63 actIds := unsafe.Pointer(&actionIds[0])
64 actTypes := unsafe.Pointer(&actionTypes[0])
66 count := len(actionDefinitions)
67 actDefs := (*C.RICactionDefinition)(C.calloc(C.size_t(len(actionDefinitions)), C.sizeof_RICactionDefinition))
68 for index := 0; index < count; index++ {
69 ptr := *(*C.RICactionDefinition)(unsafe.Pointer((uintptr)(unsafe.Pointer(actDefs)) + (uintptr)(C.sizeof_RICactionDefinition*C.int(index))))
70 ptr.size = C.int(actionDefinitions[index].Size)
72 ptr.actionDefinition = (*C.uint8_t)(C.CBytes(actionDefinitions[index].Buf))
75 defer C.free(unsafe.Pointer(actDefs))
77 count = len(subsequentActions)
78 subActs := (*C.RICSubsequentAction)(C.calloc(C.size_t(len(subsequentActions)), C.sizeof_RICSubsequentAction))
79 for index := 0; index < count; index++ {
80 ptr := *(*C.RICSubsequentAction)(unsafe.Pointer((uintptr)(unsafe.Pointer(subActs)) + (uintptr)(C.sizeof_RICSubsequentAction*C.int(index))))
81 ptr.isValid = C.int(subsequentActions[index].IsValid)
82 ptr.subsequentActionType = C.long(subsequentActions[index].SubsequentActionType)
83 ptr.timeToWait = C.long(subsequentActions[index].TimeToWait)
85 defer C.free(unsafe.Pointer(subActs))
87 size := C.e2ap_encode_ric_subscription_request_message(cptr, C.size_t(len(payload)), C.long(ricRequestorID), C.long(ricRequestSequenceNumber), C.long(ranFunctionID), eventTrigger, C.size_t(eventTriggerDefinitionSize), C.int(actionCount), (*C.long)(actIds), (*C.long)(actTypes), actDefs, subActs)
89 return make([]byte, 0), errors.New("e2ap wrapper is unable to set Subscription Request Payload due to wrong or invalid payload")
91 newPayload = C.GoBytes(cptr, (C.int(size)+7)/8)
95 /* RICsubscriptionResponse */
97 func (c *E2ap) GetSubscriptionResponseSequenceNumber(payload []byte) (subId uint16, err error) {
98 cptr := unsafe.Pointer(&payload[0])
99 cret := C.e2ap_get_ric_subscription_response_sequence_number(cptr, C.size_t(len(payload)))
101 return 0, errors.New("e2ap wrapper is unable to get Subscirption Response Sequence Number due to wrong or invalid payload")
107 func (c *E2ap) SetSubscriptionResponseSequenceNumber(payload []byte, newSubscriptionid uint16) (newPayload []byte, err error) {
108 cptr := unsafe.Pointer(&payload[0])
109 size := C.e2ap_set_ric_subscription_response_sequence_number(cptr, C.size_t(len(payload)), C.long(newSubscriptionid))
111 return make([]byte, 0), errors.New("e2ap wrapper is unable to set Subscription Response Sequence Number due to wrong or invalid payload")
113 newPayload = C.GoBytes(cptr, (C.int(size)+7)/8)
117 func (c *E2ap) GetSubscriptionResponseMessage(payload []byte) (decodedMsg *DecodedSubscriptionResponseMessage, err error) {
118 cptr := unsafe.Pointer(&payload[0])
119 decodedMsg = &DecodedSubscriptionResponseMessage{}
120 decodedCMsg := C.e2ap_decode_ric_subscription_response_message(cptr, C.size_t(len(payload)))
121 defer C.free(unsafe.Pointer(decodedCMsg))
123 if decodedCMsg == nil {
124 return decodedMsg, errors.New("e2ap wrapper is unable to decode subscription response message due to wrong or invalid payload")
127 decodedMsg.RequestID = int32(decodedCMsg.requestorID)
128 decodedMsg.RequestSequenceNumber = int32(decodedCMsg.requestSequenceNumber)
129 decodedMsg.FuncID = int32(decodedCMsg.ranfunctionID)
131 admittedCount := int(decodedCMsg.ricActionAdmittedList.count)
132 for index := 0; index < admittedCount; index++ {
133 decodedMsg.ActionAdmittedList.ActionID[index] = int32(decodedCMsg.ricActionAdmittedList.ricActionID[index])
135 decodedMsg.ActionAdmittedList.Count = admittedCount
137 notAdmittedCount := int(decodedCMsg.ricActionNotAdmittedList.count)
138 for index := 0; index < notAdmittedCount; index++ {
139 decodedMsg.ActionNotAdmittedList.ActionID[index] = int32(decodedCMsg.ricActionNotAdmittedList.ricActionID[index])
140 decodedMsg.ActionNotAdmittedList.Cause[index].CauseType = int32(decodedCMsg.ricActionNotAdmittedList.ricCause[index].ricCauseType)
141 decodedMsg.ActionNotAdmittedList.Cause[index].CauseID = int32(decodedCMsg.ricActionNotAdmittedList.ricCause[index].ricCauseID)
143 decodedMsg.ActionNotAdmittedList.Count = notAdmittedCount
148 /* RICsubscriptionFailure */
150 func (c *E2ap) GetSubscriptionFailureSequenceNumber(payload []byte) (subId uint16, err error) {
151 cptr := unsafe.Pointer(&payload[0])
152 cret := C.e2ap_get_ric_subscription_failure_sequence_number(cptr, C.size_t(len(payload)))
154 return 0, errors.New("e2ap wrapper is unable to get Subscirption Failure Sequence Number due to wrong or invalid payload")
160 /* RICsubscriptionDeleteRequest */
162 func (c *E2ap) GetSubscriptionDeleteRequestSequenceNumber(payload []byte) (subId uint16, err error) {
163 cptr := unsafe.Pointer(&payload[0])
164 cret := C.e2ap_get_ric_subscription_delete_request_sequence_number(cptr, C.size_t(len(payload)))
166 return 0, errors.New("e2ap wrapper is unable to get Subscirption Delete Request Sequence Number due to wrong or invalid payload")
172 func (c *E2ap) SetSubscriptionDeleteRequestSequenceNumber(payload []byte, newSubscriptionid uint16) (newPayload []byte, err error) {
173 cptr := unsafe.Pointer(&payload[0])
174 size := C.e2ap_set_ric_subscription_delete_request_sequence_number(cptr, C.size_t(len(payload)), C.long(newSubscriptionid))
176 return make([]byte, 0), errors.New("e2ap wrapper is unable to set Subscription Delete Request Sequence Number due to wrong or invalid payload")
178 newPayload = C.GoBytes(cptr, (C.int(size)+7)/8)
182 func (c *E2ap) SetSubscriptionDeleteRequestPayload(payload []byte, ricRequestorID uint16, ricRequestSequenceNumber uint16, ranFunctionID uint16) (newPayload []byte, err error) {
183 cptr := unsafe.Pointer(&payload[0])
184 size := C.e2ap_encode_ric_subscription_delete_request_message(cptr, C.size_t(len(payload)), C.long(ricRequestorID), C.long(ricRequestSequenceNumber), C.long(ranFunctionID))
186 return make([]byte, 0), errors.New("e2ap wrapper is unable to set Subscription Delete Request Payload due to wrong or invalid payload")
188 newPayload = C.GoBytes(cptr, (C.int(size)+7)/8)
192 /* RICsubscriptionDeleteResponse */
194 func (c *E2ap) GetSubscriptionDeleteResponseSequenceNumber(payload []byte) (subId uint16, err error) {
195 cptr := unsafe.Pointer(&payload[0])
196 cret := C.e2ap_get_ric_subscription_delete_response_sequence_number(cptr, C.size_t(len(payload)))
198 return 0, errors.New("e2ap wrapper is unable to get Subscirption Delete Response Sequence Number due to wrong or invalid payload")
204 func (c *E2ap) SetSubscriptionDeleteResponseSequenceNumber(payload []byte, newSubscriptionid uint16) (newPayload []byte, err error) {
205 cptr := unsafe.Pointer(&payload[0])
206 size := C.e2ap_set_ric_subscription_delete_response_sequence_number(cptr, C.size_t(len(payload)), C.long(newSubscriptionid))
208 return make([]byte, 0), errors.New("e2ap wrapper is unable to set Subscription Delete Response Sequence Number due to wrong or invalid payload")
210 newPayload = C.GoBytes(cptr, (C.int(size)+7)/8)
214 /* RICsubscriptionDeleteFailure */
216 func (c *E2ap) GetSubscriptionDeleteFailureSequenceNumber(payload []byte) (subId uint16, err error) {
217 cptr := unsafe.Pointer(&payload[0])
218 cret := C.e2ap_get_ric_subscription_delete_failure_sequence_number(cptr, C.size_t(len(payload)))
220 return 0, errors.New("e2ap wrapper is unable to get Subscirption Failure Sequence Number due to wrong or invalid payload")
228 func (c *E2ap) GetIndicationMessage(payload []byte) (decodedMsg *DecodedIndicationMessage, err error) {
229 cptr := unsafe.Pointer(&payload[0])
230 decodedMsg = &DecodedIndicationMessage{}
231 decodedCMsg := C.e2ap_decode_ric_indication_message(cptr, C.size_t(len(payload)))
232 if decodedCMsg == nil {
233 return decodedMsg, errors.New("e2ap wrapper is unable to decode indication message due to wrong or invalid payload")
235 defer C.e2ap_free_decoded_ric_indication_message(decodedCMsg)
237 decodedMsg.RequestID = int32(decodedCMsg.requestorID)
238 decodedMsg.RequestSequenceNumber = int32(decodedCMsg.requestSequenceNumber)
239 decodedMsg.FuncID = int32(decodedCMsg.ranfunctionID)
240 decodedMsg.ActionID = int32(decodedCMsg.actionID)
241 decodedMsg.IndSN = int32(decodedCMsg.indicationSN)
242 decodedMsg.IndType = int32(decodedCMsg.indicationType)
243 indhdr := unsafe.Pointer(decodedCMsg.indicationHeader)
244 decodedMsg.IndHeader = C.GoBytes(indhdr, C.int(decodedCMsg.indicationHeaderSize))
245 decodedMsg.IndHeaderLength = int32(decodedCMsg.indicationHeaderSize)
246 indmsg := unsafe.Pointer(decodedCMsg.indicationMessage)
247 decodedMsg.IndMessage = C.GoBytes(indmsg, C.int(decodedCMsg.indicationMessageSize))
248 decodedMsg.IndMessageLength = int32(decodedCMsg.indicationMessageSize)
249 callproc := unsafe.Pointer(decodedCMsg.callProcessID)
250 decodedMsg.CallProcessID = C.GoBytes(callproc, C.int(decodedCMsg.callProcessIDSize))
251 decodedMsg.CallProcessIDLength = int32(decodedCMsg.callProcessIDSize)