RIC-851: Updated submgr to trigger Delete Subscription Procedure
[ric-plt/submgr.git] / e2ap / pkg / e2ap_wrapper / packer_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 e2ap_wrapper
21
22 // #cgo LDFLAGS: -le2ap_wrapper -le2ap  -lstdc++
23 // #include <stdlib.h>
24 // #include <c_types.h>
25 // #include <E2AP_if.h>
26 // #include <strings.h>
27 //
28 // void initSubsRequest(RICSubscriptionRequest_t *data){
29 //   bzero(data,sizeof(RICSubscriptionRequest_t));
30 // }
31 // void initSubsResponse(RICSubscriptionResponse_t *data){
32 //   bzero(data,sizeof(RICSubscriptionResponse_t));
33 // }
34 // void initSubsFailure(RICSubscriptionFailure_t *data){
35 //   bzero(data,sizeof(RICSubscriptionFailure_t));
36 // }
37 // void initSubsDeleteRequest(RICSubscriptionDeleteRequest_t *data){
38 //   bzero(data,sizeof(RICSubscriptionDeleteRequest_t));
39 // }
40 // void initSubsDeleteResponse(RICSubscriptionDeleteResponse_t *data){
41 //   bzero(data,sizeof(RICSubscriptionDeleteResponse_t));
42 // }
43 // void initSubsDeleteFailure(RICSubscriptionDeleteFailure_t *data){
44 //   bzero(data,sizeof(RICSubscriptionDeleteFailure_t));
45 // }
46 // void initSubsDeleteRequired(RICSubsDeleteRequired_t *data){
47 //       bzero(data,sizeof(RICSubsDeleteRequired_t));
48 // }
49 //
50 import "C"
51
52 import (
53         "bytes"
54         "fmt"
55         "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/conv"
56         "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap"
57         "strings"
58         "unsafe"
59 )
60
61 const cLogBufferMaxSize = 40960
62 const cMsgBufferMaxSize = 40960
63 const cMsgBufferExtra = 512
64
65 //-----------------------------------------------------------------------------
66 //
67 //-----------------------------------------------------------------------------
68 func cMessageInfoToMessageInfo(minfo *C.E2MessageInfo_t) *e2ap.MessageInfo {
69
70         msgInfo := &e2ap.MessageInfo{}
71
72         switch minfo.messageType {
73         case C.cE2InitiatingMessage:
74                 msgInfo.MsgType = e2ap.E2AP_InitiatingMessage
75                 switch minfo.messageId {
76                 case C.cRICSubscriptionRequest:
77                         msgInfo.MsgId = e2ap.E2AP_RICSubscriptionRequest
78                         return msgInfo
79                 case C.cRICSubscriptionDeleteRequest:
80                         msgInfo.MsgId = e2ap.E2AP_RICSubscriptionDeleteRequest
81                         return msgInfo
82                 }
83         case C.cE2SuccessfulOutcome:
84                 msgInfo.MsgType = e2ap.E2AP_SuccessfulOutcome
85                 switch minfo.messageId {
86                 case C.cRICSubscriptionResponse:
87                         msgInfo.MsgId = e2ap.E2AP_RICSubscriptionResponse
88                         return msgInfo
89                 case C.cRICsubscriptionDeleteResponse:
90                         msgInfo.MsgId = e2ap.E2AP_RICSubscriptionDeleteResponse
91                         return msgInfo
92                 }
93         case C.cE2UnsuccessfulOutcome:
94                 msgInfo.MsgType = e2ap.E2AP_UnsuccessfulOutcome
95                 switch minfo.messageId {
96                 case C.cRICSubscriptionFailure:
97                         msgInfo.MsgId = e2ap.E2AP_RICSubscriptionFailure
98                         return msgInfo
99                 case C.cRICsubscriptionDeleteFailure:
100                         msgInfo.MsgId = e2ap.E2AP_RICSubscriptionDeleteFailure
101                         return msgInfo
102                 }
103         }
104         return nil
105 }
106
107 //-----------------------------------------------------------------------------
108 //
109 //-----------------------------------------------------------------------------
110 type e2apEntryRequestID struct {
111         entry *C.RICRequestID_t
112 }
113
114 func (e2Item *e2apEntryRequestID) set(id *e2ap.RequestId) error {
115         e2Item.entry.ricRequestorID = (C.uint32_t)(id.Id)
116         e2Item.entry.ricInstanceID = (C.uint32_t)(id.InstanceId)
117         return nil
118 }
119
120 func (e2Item *e2apEntryRequestID) get(id *e2ap.RequestId) error {
121         id.Id = (uint32)(e2Item.entry.ricRequestorID)
122         id.InstanceId = (uint32)(e2Item.entry.ricInstanceID)
123         return nil
124 }
125
126 //-----------------------------------------------------------------------------
127 //
128 //-----------------------------------------------------------------------------
129 type e2apEntryActionToBeSetupItem struct {
130         entry *C.RICActionToBeSetupItem_t
131 }
132
133 func (e2Item *e2apEntryActionToBeSetupItem) set(id *e2ap.ActionToBeSetupItem) error {
134
135         e2Item.entry.ricActionID = (C.ulong)(id.ActionId)
136         e2Item.entry.ricActionType = (C.uint64_t)(id.ActionType)
137         if id.RicActionDefinitionPresent {
138                 e2Item.entry.ricActionDefinitionPresent = true
139                 if err := (&e2apEntryActionDefinitionChoice{entry: &e2Item.entry.ricActionDefinitionChoice}).set(&id.ActionDefinitionChoice); err != nil {
140                         return err
141                 }
142         }
143         if id.SubsequentAction.Present {
144                 e2Item.entry.ricSubsequentActionPresent = true
145                 e2Item.entry.ricSubsequentAction.ricSubsequentActionType = (C.uint64_t)(id.SubsequentAction.Type)
146                 e2Item.entry.ricSubsequentAction.ricTimeToWait = (C.uint64_t)(id.SubsequentAction.TimetoWait)
147         }
148         return nil
149 }
150
151 func (e2Item *e2apEntryActionToBeSetupItem) get(id *e2ap.ActionToBeSetupItem) error {
152
153         id.ActionId = (uint64)(e2Item.entry.ricActionID)
154         id.ActionType = (uint64)(e2Item.entry.ricActionType)
155         if e2Item.entry.ricActionDefinitionPresent {
156                 id.RicActionDefinitionPresent = true
157                 if err := (&e2apEntryActionDefinitionChoice{entry: &e2Item.entry.ricActionDefinitionChoice}).get(&id.ActionDefinitionChoice); err != nil {
158                         return err
159                 }
160         }
161         if e2Item.entry.ricSubsequentActionPresent {
162                 id.SubsequentAction.Present = true
163                 id.SubsequentAction.Type = (uint64)(e2Item.entry.ricSubsequentAction.ricSubsequentActionType)
164                 id.SubsequentAction.TimetoWait = (uint64)(e2Item.entry.ricSubsequentAction.ricTimeToWait)
165         }
166         return nil
167 }
168
169 //-----------------------------------------------------------------------------
170 //
171 //-----------------------------------------------------------------------------
172 type e2apEntryActionDefinitionChoice struct {
173         entry *C.RICActionDefinitionChoice_t
174 }
175
176 func (e2Item *e2apEntryActionDefinitionChoice) set(id *e2ap.ActionDefinitionChoice) error {
177         if id.Data.Length > 0 {
178                 e2Item.entry.octetString.contentLength = C.size_t(id.Data.Length)
179                 C.memcpy(unsafe.Pointer(&e2Item.entry.octetString.data[0]), unsafe.Pointer(&id.Data.Data[0]), C.size_t(e2Item.entry.octetString.contentLength))
180         }
181         return nil
182 }
183
184 func (e2Item *e2apEntryActionDefinitionChoice) get(id *e2ap.ActionDefinitionChoice) error {
185         id.Data.Length = (uint64)(e2Item.entry.octetString.contentLength)
186         if id.Data.Length > 0 {
187                 id.Data.Data = make([]uint8, id.Data.Length)
188                 C.memcpy(unsafe.Pointer(&id.Data.Data[0]), unsafe.Pointer(&e2Item.entry.octetString.data[0]), C.size_t(e2Item.entry.octetString.contentLength))
189         }
190         return nil
191 }
192
193 //-----------------------------------------------------------------------------
194 //
195 //-----------------------------------------------------------------------------
196 type e2apEntryPlmnIdentity struct {
197         entry *C.PLMNIdentity_t
198 }
199
200 func (plmnId *e2apEntryPlmnIdentity) set(id conv.PlmnIdentityIf) error {
201
202         buf := new(bytes.Buffer)
203         id.EncodeTo(buf)
204         data := buf.Bytes()
205         plmnId.entry.contentLength = (C.uint8_t)(len(data))
206         for i := 0; i < len(data); i++ {
207                 plmnId.entry.pLMNIdentityVal[i] = (C.uint8_t)(data[i])
208         }
209         return nil
210 }
211
212 func (plmnId *e2apEntryPlmnIdentity) get(id conv.PlmnIdentityIf) error {
213         conlen := (int)(plmnId.entry.contentLength)
214         bcdBuf := make([]uint8, conlen)
215         for i := 0; i < conlen; i++ {
216                 bcdBuf[i] = (uint8)(plmnId.entry.pLMNIdentityVal[i])
217         }
218         reader := bytes.NewReader(bcdBuf)
219         id.DecodeFrom(reader)
220         return nil
221 }
222
223 //-----------------------------------------------------------------------------
224 //
225 //-----------------------------------------------------------------------------
226 type e2apEntryGlobalEnbId struct {
227         entry *C.GlobalNodeID_t
228 }
229
230 func (enbId *e2apEntryGlobalEnbId) checkbits(bits uint8) error {
231         switch bits {
232         case e2ap.E2AP_ENBIDMacroPBits20:
233                 return nil
234         case e2ap.E2AP_ENBIDHomeBits28:
235                 return nil
236         case e2ap.E2AP_ENBIDShortMacroits18:
237                 return nil
238         case e2ap.E2AP_ENBIDlongMacroBits21:
239                 return nil
240         }
241         return fmt.Errorf("GlobalEnbId: given bits %d not match allowed: 20,28,18,21", bits)
242 }
243
244 func (enbId *e2apEntryGlobalEnbId) set(id *e2ap.GlobalNodeId) error {
245         if err := enbId.checkbits(id.NodeId.Bits); err != nil {
246                 return err
247         }
248         enbId.entry.nodeID.bits = (C.uchar)(id.NodeId.Bits)
249         enbId.entry.nodeID.nodeID = (C.uint32_t)(id.NodeId.Id)
250         return (&e2apEntryPlmnIdentity{entry: &enbId.entry.pLMNIdentity}).set(&id.PlmnIdentity)
251 }
252
253 func (enbId *e2apEntryGlobalEnbId) get(id *e2ap.GlobalNodeId) error {
254         if err := enbId.checkbits((uint8)(enbId.entry.nodeID.bits)); err != nil {
255                 return err
256         }
257         id.NodeId.Bits = (uint8)(enbId.entry.nodeID.bits)
258         id.NodeId.Id = (uint32)(enbId.entry.nodeID.nodeID)
259         return (&e2apEntryPlmnIdentity{entry: &enbId.entry.pLMNIdentity}).get(&id.PlmnIdentity)
260 }
261
262 //-----------------------------------------------------------------------------
263 //
264 //-----------------------------------------------------------------------------
265 type e2apEntryGlobalGnbId struct {
266         entry *C.GlobalNodeID_t
267 }
268
269 func (gnbId *e2apEntryGlobalGnbId) checkbits(bits uint8) error {
270         if bits < 22 || bits > 32 {
271                 return fmt.Errorf("GlobalGnbId: given bits %d not match allowed: 22-32", bits)
272         }
273         return nil
274 }
275
276 func (gnbId *e2apEntryGlobalGnbId) set(id *e2ap.GlobalNodeId) error {
277         if err := gnbId.checkbits(id.NodeId.Bits); err != nil {
278                 return err
279         }
280         gnbId.entry.nodeID.bits = (C.uchar)(id.NodeId.Bits)
281         gnbId.entry.nodeID.nodeID = (C.uint32_t)(id.NodeId.Id)
282         return (&e2apEntryPlmnIdentity{entry: &gnbId.entry.pLMNIdentity}).set(&id.PlmnIdentity)
283 }
284
285 func (gnbId *e2apEntryGlobalGnbId) get(id *e2ap.GlobalNodeId) error {
286         if err := gnbId.checkbits((uint8)(gnbId.entry.nodeID.bits)); err != nil {
287                 return err
288         }
289         id.NodeId.Bits = (uint8)(gnbId.entry.nodeID.bits)
290         id.NodeId.Id = (uint32)(gnbId.entry.nodeID.nodeID)
291         return (&e2apEntryPlmnIdentity{entry: &gnbId.entry.pLMNIdentity}).get(&id.PlmnIdentity)
292 }
293
294 //-----------------------------------------------------------------------------
295 //
296 //-----------------------------------------------------------------------------
297 type e2apEntryInterfaceId struct {
298         entry *C.InterfaceID_t
299 }
300
301 func (indId *e2apEntryInterfaceId) set(id *e2ap.InterfaceId) error {
302         if id.GlobalEnbId.Present {
303                 indId.entry.globalENBIDPresent = true
304                 if err := (&e2apEntryGlobalEnbId{entry: &indId.entry.globalENBID}).set(&id.GlobalEnbId); err != nil {
305                         return err
306                 }
307         }
308
309         if id.GlobalGnbId.Present {
310                 indId.entry.globalGNBIDPresent = true
311                 if err := (&e2apEntryGlobalGnbId{entry: &indId.entry.globalGNBID}).set(&id.GlobalGnbId); err != nil {
312                         return err
313                 }
314         }
315         return nil
316 }
317
318 func (indId *e2apEntryInterfaceId) get(id *e2ap.InterfaceId) error {
319         if indId.entry.globalENBIDPresent == true {
320                 id.GlobalEnbId.Present = true
321                 if err := (&e2apEntryGlobalEnbId{entry: &indId.entry.globalENBID}).get(&id.GlobalEnbId); err != nil {
322                         return err
323                 }
324         }
325
326         if indId.entry.globalGNBIDPresent == true {
327                 id.GlobalGnbId.Present = true
328                 if err := (&e2apEntryGlobalGnbId{entry: &indId.entry.globalGNBID}).get(&id.GlobalGnbId); err != nil {
329                         return err
330                 }
331         }
332         return nil
333 }
334
335 //-----------------------------------------------------------------------------
336 //
337 //-----------------------------------------------------------------------------
338 type e2apEntryEventTrigger struct {
339         entry *C.RICEventTriggerDefinition_t
340 }
341
342 func (evtTrig *e2apEntryEventTrigger) set(id *e2ap.EventTriggerDefinition) error {
343
344         if id.Data.Length > 0 {
345                 evtTrig.entry.octetString.contentLength = C.size_t(id.Data.Length)
346                 C.memcpy(unsafe.Pointer(&evtTrig.entry.octetString.data[0]), unsafe.Pointer(&id.Data.Data[0]), C.size_t(evtTrig.entry.octetString.contentLength))
347         }
348         return nil
349 }
350
351 func (evtTrig *e2apEntryEventTrigger) get(id *e2ap.EventTriggerDefinition) error {
352
353         id.Data.Length = (uint64)(evtTrig.entry.octetString.contentLength)
354         if id.Data.Length > 0 {
355                 id.Data.Data = make([]uint8, id.Data.Length)
356                 C.memcpy(unsafe.Pointer(&id.Data.Data[0]), unsafe.Pointer(&evtTrig.entry.octetString.data[0]), C.size_t(evtTrig.entry.octetString.contentLength))
357         }
358         return nil
359 }
360
361 //-----------------------------------------------------------------------------
362 //
363 //-----------------------------------------------------------------------------
364 type e2apEntryAdmittedList struct {
365         entry *C.RICActionAdmittedList_t
366 }
367
368 func (item *e2apEntryAdmittedList) set(data *e2ap.ActionAdmittedList) error {
369
370         if len(data.Items) > 16 {
371                 return fmt.Errorf("ActionAdmittedList: too long %d while allowed %d", len(data.Items), 16)
372         }
373
374         item.entry.contentLength = 0
375         for i := 0; i < len(data.Items); i++ {
376                 item.entry.ricActionID[item.entry.contentLength] = (C.ulong)(data.Items[i].ActionId)
377                 item.entry.contentLength++
378         }
379         return nil
380 }
381
382 func (item *e2apEntryAdmittedList) get(data *e2ap.ActionAdmittedList) error {
383         conlen := (int)(item.entry.contentLength)
384         data.Items = make([]e2ap.ActionAdmittedItem, conlen)
385         for i := 0; i < conlen; i++ {
386                 data.Items[i].ActionId = (uint64)(item.entry.ricActionID[i])
387         }
388         return nil
389 }
390
391 //-----------------------------------------------------------------------------
392 //
393 //-----------------------------------------------------------------------------
394 type e2apEntryNotAdmittedList struct {
395         entry *C.RICActionNotAdmittedList_t
396 }
397
398 func (item *e2apEntryNotAdmittedList) set(data *e2ap.ActionNotAdmittedList) error {
399
400         if len(data.Items) > 16 {
401                 return fmt.Errorf("e2apEntryNotAdmittedList: too long %d while allowed %d", len(data.Items), 16)
402         }
403
404         item.entry.contentLength = 0
405         for i := 0; i < len(data.Items); i++ {
406                 item.entry.RICActionNotAdmittedItem[item.entry.contentLength].ricActionID = (C.ulong)(data.Items[i].ActionId)
407                 item.entry.RICActionNotAdmittedItem[item.entry.contentLength].cause.content = (C.uchar)(data.Items[i].Cause.Content)
408                 item.entry.RICActionNotAdmittedItem[item.entry.contentLength].cause.causeVal = (C.uchar)(data.Items[i].Cause.Value)
409                 item.entry.contentLength++
410         }
411
412         return nil
413 }
414
415 func (item *e2apEntryNotAdmittedList) get(data *e2ap.ActionNotAdmittedList) error {
416         conlen := (int)(item.entry.contentLength)
417         data.Items = make([]e2ap.ActionNotAdmittedItem, conlen)
418         for i := 0; i < conlen; i++ {
419                 data.Items[i].ActionId = (uint64)(item.entry.RICActionNotAdmittedItem[i].ricActionID)
420                 data.Items[i].Cause.Content = (uint8)(item.entry.RICActionNotAdmittedItem[i].cause.content)
421                 data.Items[i].Cause.Value = (uint8)(item.entry.RICActionNotAdmittedItem[i].cause.causeVal)
422         }
423         return nil
424 }
425
426 //-----------------------------------------------------------------------------
427 //
428 //-----------------------------------------------------------------------------
429 type e2apEntryCriticalityDiagnostic struct {
430         entry *C.CriticalityDiagnostics__t
431 }
432
433 func (item *e2apEntryCriticalityDiagnostic) set(data *e2ap.CriticalityDiagnostics) error {
434
435         item.entry.procedureCodePresent = (C.bool)(data.ProcCodePresent)
436         item.entry.procedureCode = (C.uchar)(data.ProcCode)
437
438         item.entry.triggeringMessagePresent = (C.bool)(data.TrigMsgPresent)
439         item.entry.triggeringMessage = (C.uchar)(data.TrigMsg)
440
441         item.entry.procedureCriticalityPresent = (C.bool)(data.ProcCritPresent)
442         item.entry.procedureCriticality = (C.uchar)(data.ProcCrit)
443
444         item.entry.criticalityDiagnosticsIELength = 0
445         item.entry.iEsCriticalityDiagnosticsPresent = false
446         for i := 0; i < len(data.CriticalityDiagnosticsIEList.Items); i++ {
447                 item.entry.criticalityDiagnosticsIEListItem[i].iECriticality = (C.uint8_t)(data.CriticalityDiagnosticsIEList.Items[i].IeCriticality)
448                 item.entry.criticalityDiagnosticsIEListItem[i].iE_ID = (C.uint32_t)(data.CriticalityDiagnosticsIEList.Items[i].IeID)
449                 item.entry.criticalityDiagnosticsIEListItem[i].typeOfError = (C.uint8_t)(data.CriticalityDiagnosticsIEList.Items[i].TypeOfError)
450                 item.entry.criticalityDiagnosticsIELength++
451                 item.entry.iEsCriticalityDiagnosticsPresent = true
452         }
453         return nil
454 }
455
456 func (item *e2apEntryCriticalityDiagnostic) get(data *e2ap.CriticalityDiagnostics) error {
457
458         data.ProcCodePresent = (bool)(item.entry.procedureCodePresent)
459         data.ProcCode = (uint64)(item.entry.procedureCode)
460
461         data.TrigMsgPresent = (bool)(item.entry.triggeringMessagePresent)
462         data.TrigMsg = (uint64)(item.entry.triggeringMessage)
463
464         data.ProcCritPresent = (bool)(item.entry.procedureCriticalityPresent)
465         data.ProcCrit = (uint8)(item.entry.procedureCriticality)
466
467         if item.entry.iEsCriticalityDiagnosticsPresent == true {
468                 conlen := (int)(item.entry.criticalityDiagnosticsIELength)
469                 data.CriticalityDiagnosticsIEList.Items = make([]e2ap.CriticalityDiagnosticsIEListItem, conlen)
470                 for i := 0; i < conlen; i++ {
471                         data.CriticalityDiagnosticsIEList.Items[i].IeCriticality = (uint8)(item.entry.criticalityDiagnosticsIEListItem[i].iECriticality)
472                         data.CriticalityDiagnosticsIEList.Items[i].IeID = (uint32)(item.entry.criticalityDiagnosticsIEListItem[i].iE_ID)
473                         data.CriticalityDiagnosticsIEList.Items[i].TypeOfError = (uint8)(item.entry.criticalityDiagnosticsIEListItem[i].typeOfError)
474                 }
475         }
476         return nil
477 }
478
479 /*
480 //-----------------------------------------------------------------------------
481 //
482 //-----------------------------------------------------------------------------
483 type e2apEntryCallProcessId struct {
484         entry *C.RICCallProcessID_t
485 }
486
487 func (callProcId *e2apEntryCallProcessId) set(data *e2ap.CallProcessId) error {
488         callProcId.entry.ricCallProcessIDVal = (C.uint64_t)(data.CallProcessIDVal)
489         return nil
490 }
491
492 func (callProcId *e2apEntryCallProcessId) get(data *e2ap.CallProcessId) error {
493         data.CallProcessIDVal = (uint32)(callProcId.entry.ricCallProcessIDVal)
494         return nil
495 }
496 */
497
498 //-----------------------------------------------------------------------------
499 //
500 //-----------------------------------------------------------------------------
501
502 type e2apMessagePacker struct {
503         expectedInfo C.E2MessageInfo_t
504         pduMsgInfo   C.E2MessageInfo_t
505         pdu          *C.e2ap_pdu_ptr_t
506         lb           []byte
507         p            unsafe.Pointer
508         plen         C.size_t
509 }
510
511 func (e2apMsg *e2apMessagePacker) init(minfo C.E2MessageInfo_t) {
512         e2apMsg.expectedInfo = minfo
513         e2apMsg.lb = make([]byte, cLogBufferMaxSize)
514         e2apMsg.lb[0] = 0
515         e2apMsg.p = C.malloc(C.size_t(cMsgBufferMaxSize))
516         e2apMsg.plen = C.size_t(cMsgBufferMaxSize) - cMsgBufferExtra
517 }
518
519 func (e2apMsg *e2apMessagePacker) fini() {
520         C.free(e2apMsg.p)
521         e2apMsg.plen = 0
522         e2apMsg.p = nil
523 }
524
525 func (e2apMsg *e2apMessagePacker) lbString() string {
526         return "logbuffer(" + string(e2apMsg.lb[:strings.Index(string(e2apMsg.lb[:]), "\000")]) + ")"
527 }
528
529 func (e2apMsg *e2apMessagePacker) packeddata() *e2ap.PackedData {
530         return &e2ap.PackedData{C.GoBytes(e2apMsg.p, C.int(e2apMsg.plen))}
531 }
532
533 func (e2apMsg *e2apMessagePacker) checkerr(errorNro C.uint64_t) error {
534         if errorNro != C.e2err_OK {
535                 return fmt.Errorf("e2err(%s) %s", C.GoString(C.getE2ErrorString(errorNro)), e2apMsg.lbString())
536         }
537         return nil
538 }
539
540 func (e2apMsg *e2apMessagePacker) unpacktopdu(data *e2ap.PackedData) error {
541         e2apMsg.pdu = C.unpackE2AP_pdu((C.size_t)(len(data.Buf)), (*C.uchar)(unsafe.Pointer(&data.Buf[0])), (*C.char)(unsafe.Pointer(&e2apMsg.lb[0])), &e2apMsg.pduMsgInfo)
542         if e2apMsg.pduMsgInfo.messageType != e2apMsg.expectedInfo.messageType || e2apMsg.pduMsgInfo.messageId != e2apMsg.expectedInfo.messageId {
543                 return fmt.Errorf("unpack e2ap %s %s", e2apMsg.lbString(), e2apMsg.String())
544         }
545         return nil
546 }
547
548 func (e2apMsg *e2apMessagePacker) messageInfoPdu() *e2ap.MessageInfo {
549         return cMessageInfoToMessageInfo(&e2apMsg.pduMsgInfo)
550 }
551
552 func (e2apMsg *e2apMessagePacker) messageInfoExpected() *e2ap.MessageInfo {
553         return cMessageInfoToMessageInfo(&e2apMsg.expectedInfo)
554 }
555
556 func (e2apMsg *e2apMessagePacker) String() string {
557         var ret string
558         pduInfo := e2apMsg.messageInfoPdu()
559         if pduInfo != nil {
560                 ret += "pduinfo(" + pduInfo.String() + ")"
561         } else {
562                 ret += "pduinfo(N/A)"
563         }
564         expInfo := e2apMsg.messageInfoExpected()
565         if expInfo != nil {
566                 ret += " expinfo(" + expInfo.String() + ")"
567         } else {
568                 ret += " expinfo(N/A)"
569         }
570         return ret
571 }
572
573 //-----------------------------------------------------------------------------
574 //
575 //-----------------------------------------------------------------------------
576
577 type e2apMsgPackerSubscriptionRequest struct {
578         e2apMessagePacker
579         msgC *C.RICSubscriptionRequest_t
580         msgG *e2ap.E2APSubscriptionRequest
581 }
582
583 func (e2apMsg *e2apMsgPackerSubscriptionRequest) init() {
584         e2apMsg.e2apMessagePacker.init(C.E2MessageInfo_t{C.cE2InitiatingMessage, C.cRICSubscriptionRequest})
585         e2apMsg.msgC = &C.RICSubscriptionRequest_t{}
586         e2apMsg.msgG = &e2ap.E2APSubscriptionRequest{}
587         C.initSubsRequest(e2apMsg.msgC)
588 }
589
590 func (e2apMsg *e2apMsgPackerSubscriptionRequest) Pack(data *e2ap.E2APSubscriptionRequest) (error, *e2ap.PackedData) {
591
592         e2apMsg.init()
593
594         defer e2apMsg.fini()
595         e2apMsg.msgG = data
596
597         e2apMsg.msgC.ranFunctionID = (C.uint16_t)(e2apMsg.msgG.FunctionId)
598         if err := (&e2apEntryRequestID{entry: &e2apMsg.msgC.ricRequestID}).set(&e2apMsg.msgG.RequestId); err != nil {
599                 return err, nil
600         }
601         if err := (&e2apEntryEventTrigger{entry: &e2apMsg.msgC.ricSubscriptionDetails.ricEventTriggerDefinition}).set(&e2apMsg.msgG.EventTriggerDefinition); err != nil {
602                 return err, nil
603         }
604         if len(e2apMsg.msgG.ActionSetups) > 16 {
605                 return fmt.Errorf("IndicationMessage.InterfaceMessage: too long %d while allowed %d", len(e2apMsg.msgG.ActionSetups), 16), nil
606         }
607         e2apMsg.msgC.ricSubscriptionDetails.ricActionToBeSetupItemIEs.contentLength = 0
608         for i := 0; i < len(e2apMsg.msgG.ActionSetups); i++ {
609                 item := &e2apEntryActionToBeSetupItem{entry: &e2apMsg.msgC.ricSubscriptionDetails.ricActionToBeSetupItemIEs.ricActionToBeSetupItem[e2apMsg.msgC.ricSubscriptionDetails.ricActionToBeSetupItemIEs.contentLength]}
610                 e2apMsg.msgC.ricSubscriptionDetails.ricActionToBeSetupItemIEs.contentLength += 1
611                 if err := item.set(&e2apMsg.msgG.ActionSetups[i]); err != nil {
612                         return err, nil
613                 }
614         }
615         errorNro := C.packRICSubscriptionRequest(&e2apMsg.plen, (*C.uchar)(e2apMsg.p), (*C.char)(unsafe.Pointer(&e2apMsg.lb[0])), e2apMsg.msgC)
616         if err := e2apMsg.checkerr(errorNro); err != nil {
617                 return err, nil
618         }
619         return nil, e2apMsg.packeddata()
620 }
621
622 func (e2apMsg *e2apMsgPackerSubscriptionRequest) UnPack(msg *e2ap.PackedData) (error, *e2ap.E2APSubscriptionRequest) {
623
624         e2apMsg.init()
625         defer e2apMsg.fini()
626
627         if err := e2apMsg.e2apMessagePacker.unpacktopdu(msg); err != nil {
628                 return err, e2apMsg.msgG
629         }
630
631         errorNro := C.getRICSubscriptionRequestData(e2apMsg.e2apMessagePacker.pdu, e2apMsg.msgC)
632         if err := e2apMsg.checkerr(errorNro); err != nil {
633                 return err, e2apMsg.msgG
634         }
635
636         e2apMsg.msgG.FunctionId = (e2ap.FunctionId)(e2apMsg.msgC.ranFunctionID)
637         if err := (&e2apEntryRequestID{entry: &e2apMsg.msgC.ricRequestID}).get(&e2apMsg.msgG.RequestId); err != nil {
638                 return err, e2apMsg.msgG
639         }
640         if err := (&e2apEntryEventTrigger{entry: &e2apMsg.msgC.ricSubscriptionDetails.ricEventTriggerDefinition}).get(&e2apMsg.msgG.EventTriggerDefinition); err != nil {
641                 return err, e2apMsg.msgG
642         }
643         conlen := (int)(e2apMsg.msgC.ricSubscriptionDetails.ricActionToBeSetupItemIEs.contentLength)
644         e2apMsg.msgG.ActionSetups = make([]e2ap.ActionToBeSetupItem, conlen)
645         for i := 0; i < conlen; i++ {
646                 item := &e2apEntryActionToBeSetupItem{entry: &e2apMsg.msgC.ricSubscriptionDetails.ricActionToBeSetupItemIEs.ricActionToBeSetupItem[i]}
647                 if err := item.get(&e2apMsg.msgG.ActionSetups[i]); err != nil {
648                         return err, e2apMsg.msgG
649                 }
650         }
651         return nil, e2apMsg.msgG
652
653 }
654
655 func (e2apMsg *e2apMsgPackerSubscriptionRequest) String() string {
656         var b bytes.Buffer
657         fmt.Fprintln(&b, "ricSubscriptionRequest.")
658         fmt.Fprintln(&b, "  ricRequestID.")
659         fmt.Fprintln(&b, "     ricRequestorID =", e2apMsg.msgC.ricRequestID.ricRequestorID)
660         fmt.Fprintln(&b, "     ricInstanceID =", e2apMsg.msgC.ricRequestID.ricInstanceID)
661         fmt.Fprintln(&b, "  ranFunctionID =", e2apMsg.msgC.ranFunctionID)
662         fmt.Fprintln(&b, "  ricSubscriptionDetails.")
663         fmt.Fprintln(&b, "    ricActionToBeSetupItemIEs.")
664         fmt.Fprintln(&b, "      contentLength =", e2apMsg.msgC.ricSubscriptionDetails.ricActionToBeSetupItemIEs.contentLength)
665         var index uint8
666         index = 0
667         for (C.uchar)(index) < e2apMsg.msgC.ricSubscriptionDetails.ricActionToBeSetupItemIEs.contentLength {
668                 fmt.Fprintln(&b, "      ricActionToBeSetupItem[index].ricActionID =", e2apMsg.msgC.ricSubscriptionDetails.ricActionToBeSetupItemIEs.ricActionToBeSetupItem[index].ricActionID)
669                 fmt.Fprintln(&b, "      ricActionToBeSetupItem[index].ricActionType =", e2apMsg.msgC.ricSubscriptionDetails.ricActionToBeSetupItemIEs.ricActionToBeSetupItem[index].ricActionType)
670                 fmt.Fprintln(&b, "      ricActionToBeSetupItem[index].ricActionDefinitionPresent =", e2apMsg.msgC.ricSubscriptionDetails.ricActionToBeSetupItemIEs.ricActionToBeSetupItem[index].ricActionDefinitionPresent)
671                 fmt.Fprintln(&b, "      ricActionToBeSetupItem[index].ricSubsequentActionPresent =", e2apMsg.msgC.ricSubscriptionDetails.ricActionToBeSetupItemIEs.ricActionToBeSetupItem[index].ricSubsequentActionPresent)
672                 if e2apMsg.msgC.ricSubscriptionDetails.ricActionToBeSetupItemIEs.ricActionToBeSetupItem[index].ricSubsequentActionPresent {
673                         fmt.Fprintln(&b, "      ricActionToBeSetupItem[index].ricSubsequentAction.ricSubsequentActionType =", e2apMsg.msgC.ricSubscriptionDetails.ricActionToBeSetupItemIEs.ricActionToBeSetupItem[index].ricSubsequentAction.ricSubsequentActionType)
674                         fmt.Fprintln(&b, "      ricActionToBeSetupItem[index].ricSubsequentAction.ricTimeToWait =", e2apMsg.msgC.ricSubscriptionDetails.ricActionToBeSetupItemIEs.ricActionToBeSetupItem[index].ricSubsequentAction.ricTimeToWait)
675                 }
676                 index++
677         }
678         return b.String()
679 }
680
681 //-----------------------------------------------------------------------------
682 //
683 //-----------------------------------------------------------------------------
684 type e2apMsgPackerSubscriptionResponse struct {
685         e2apMessagePacker
686         msgC *C.RICSubscriptionResponse_t
687         msgG *e2ap.E2APSubscriptionResponse
688 }
689
690 func (e2apMsg *e2apMsgPackerSubscriptionResponse) init() {
691         e2apMsg.e2apMessagePacker.init(C.E2MessageInfo_t{C.cE2SuccessfulOutcome, C.cRICSubscriptionResponse})
692         e2apMsg.msgC = &C.RICSubscriptionResponse_t{}
693         e2apMsg.msgG = &e2ap.E2APSubscriptionResponse{}
694         C.initSubsResponse(e2apMsg.msgC)
695 }
696
697 func (e2apMsg *e2apMsgPackerSubscriptionResponse) Pack(data *e2ap.E2APSubscriptionResponse) (error, *e2ap.PackedData) {
698         e2apMsg.init()
699         defer e2apMsg.fini()
700         e2apMsg.msgG = data
701
702         e2apMsg.msgC.ranFunctionID = (C.uint16_t)(e2apMsg.msgG.FunctionId)
703         if err := (&e2apEntryRequestID{entry: &e2apMsg.msgC.ricRequestID}).set(&e2apMsg.msgG.RequestId); err != nil {
704                 return err, nil
705         }
706         if err := (&e2apEntryAdmittedList{entry: &e2apMsg.msgC.ricActionAdmittedList}).set(&e2apMsg.msgG.ActionAdmittedList); err != nil {
707                 return err, nil
708         }
709         e2apMsg.msgC.ricActionNotAdmittedListPresent = false
710         if len(e2apMsg.msgG.ActionNotAdmittedList.Items) > 0 {
711                 e2apMsg.msgC.ricActionNotAdmittedListPresent = true
712                 if err := (&e2apEntryNotAdmittedList{entry: &e2apMsg.msgC.ricActionNotAdmittedList}).set(&e2apMsg.msgG.ActionNotAdmittedList); err != nil {
713                         return err, nil
714                 }
715         }
716
717         errorNro := C.packRICSubscriptionResponse(&e2apMsg.plen, (*C.uchar)(e2apMsg.p), (*C.char)(unsafe.Pointer(&e2apMsg.lb[0])), e2apMsg.msgC)
718         if err := e2apMsg.checkerr(errorNro); err != nil {
719                 return err, nil
720         }
721         return nil, e2apMsg.packeddata()
722 }
723
724 func (e2apMsg *e2apMsgPackerSubscriptionResponse) UnPack(msg *e2ap.PackedData) (error, *e2ap.E2APSubscriptionResponse) {
725
726         e2apMsg.init()
727         defer e2apMsg.fini()
728
729         if err := e2apMsg.e2apMessagePacker.unpacktopdu(msg); err != nil {
730                 return err, e2apMsg.msgG
731         }
732         errorNro := C.getRICSubscriptionResponseData(e2apMsg.e2apMessagePacker.pdu, e2apMsg.msgC)
733         if err := e2apMsg.checkerr(errorNro); err != nil {
734                 return err, e2apMsg.msgG
735         }
736
737         e2apMsg.msgG.FunctionId = (e2ap.FunctionId)(e2apMsg.msgC.ranFunctionID)
738         if err := (&e2apEntryRequestID{entry: &e2apMsg.msgC.ricRequestID}).get(&e2apMsg.msgG.RequestId); err != nil {
739                 return err, e2apMsg.msgG
740         }
741         if err := (&e2apEntryAdmittedList{entry: &e2apMsg.msgC.ricActionAdmittedList}).get(&e2apMsg.msgG.ActionAdmittedList); err != nil {
742                 return err, e2apMsg.msgG
743         }
744         if e2apMsg.msgC.ricActionNotAdmittedListPresent == true {
745                 if err := (&e2apEntryNotAdmittedList{entry: &e2apMsg.msgC.ricActionNotAdmittedList}).get(&e2apMsg.msgG.ActionNotAdmittedList); err != nil {
746                         return err, e2apMsg.msgG
747                 }
748         }
749         return nil, e2apMsg.msgG
750 }
751
752 func (e2apMsg *e2apMsgPackerSubscriptionResponse) String() string {
753         var b bytes.Buffer
754         fmt.Fprintln(&b, "ricSubscriptionResponse.")
755         fmt.Fprintln(&b, "  ricRequestID.")
756         fmt.Fprintln(&b, "    ricRequestorID =", e2apMsg.msgC.ricRequestID.ricRequestorID)
757         fmt.Fprintln(&b, "    ricInstanceID =", e2apMsg.msgC.ricRequestID.ricInstanceID)
758         fmt.Fprintln(&b, "  ranFunctionID =", e2apMsg.msgC.ranFunctionID)
759         fmt.Fprintln(&b, "  ricActionAdmittedList.")
760         fmt.Fprintln(&b, "    contentLength =", e2apMsg.msgC.ricActionAdmittedList.contentLength)
761         var index uint8
762         index = 0
763         for (C.uchar)(index) < e2apMsg.msgC.ricActionAdmittedList.contentLength {
764                 fmt.Fprintln(&b, "    ricActionAdmittedList.ricActionID[index] =", e2apMsg.msgC.ricActionAdmittedList.ricActionID[index])
765                 index++
766         }
767         if e2apMsg.msgC.ricActionNotAdmittedListPresent {
768                 fmt.Fprintln(&b, "  ricActionNotAdmittedListPresent =", e2apMsg.msgC.ricActionNotAdmittedListPresent)
769                 fmt.Fprintln(&b, "    ricActionNotAdmittedList.")
770                 fmt.Fprintln(&b, "    contentLength =", e2apMsg.msgC.ricActionNotAdmittedList.contentLength)
771                 index = 0
772                 for (C.uchar)(index) < e2apMsg.msgC.ricActionNotAdmittedList.contentLength {
773                         fmt.Fprintln(&b, "      RICActionNotAdmittedItem[index].ricActionID =", e2apMsg.msgC.ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricActionID)
774                         fmt.Fprintln(&b, "      RICActionNotAdmittedItem[index].cause.content =", e2apMsg.msgC.ricActionNotAdmittedList.RICActionNotAdmittedItem[index].cause.content)
775                         fmt.Fprintln(&b, "      RICActionNotAdmittedItem[index].cause.causeVal =", e2apMsg.msgC.ricActionNotAdmittedList.RICActionNotAdmittedItem[index].cause.causeVal)
776                         index++
777                 }
778         }
779         return b.String()
780 }
781
782 //-----------------------------------------------------------------------------
783 //
784 //-----------------------------------------------------------------------------
785 type e2apMsgPackerSubscriptionFailure struct {
786         e2apMessagePacker
787         msgC *C.RICSubscriptionFailure_t
788         msgG *e2ap.E2APSubscriptionFailure
789 }
790
791 func (e2apMsg *e2apMsgPackerSubscriptionFailure) init() {
792         e2apMsg.e2apMessagePacker.init(C.E2MessageInfo_t{C.cE2UnsuccessfulOutcome, C.cRICSubscriptionFailure})
793         e2apMsg.msgC = &C.RICSubscriptionFailure_t{}
794         e2apMsg.msgG = &e2ap.E2APSubscriptionFailure{}
795         C.initSubsFailure(e2apMsg.msgC)
796 }
797
798 func (e2apMsg *e2apMsgPackerSubscriptionFailure) Pack(data *e2ap.E2APSubscriptionFailure) (error, *e2ap.PackedData) {
799         e2apMsg.init()
800         defer e2apMsg.fini()
801         e2apMsg.msgG = data
802
803         e2apMsg.msgC.ranFunctionID = (C.uint16_t)(e2apMsg.msgG.FunctionId)
804         if err := (&e2apEntryRequestID{entry: &e2apMsg.msgC.ricRequestID}).set(&e2apMsg.msgG.RequestId); err != nil {
805                 return err, nil
806         }
807         e2apMsg.msgC.cause.content = (C.uchar)(e2apMsg.msgG.Cause.Content)
808         e2apMsg.msgC.cause.causeVal = (C.uchar)(e2apMsg.msgG.Cause.Value)
809         e2apMsg.msgC.criticalityDiagnosticsPresent = false
810         if e2apMsg.msgG.CriticalityDiagnostics.Present {
811                 e2apMsg.msgC.criticalityDiagnosticsPresent = true
812                 if err := (&e2apEntryCriticalityDiagnostic{entry: &e2apMsg.msgC.criticalityDiagnostics}).set(&e2apMsg.msgG.CriticalityDiagnostics); err != nil {
813                         return err, nil
814                 }
815         }
816
817         errorNro := C.packRICSubscriptionFailure(&e2apMsg.plen, (*C.uchar)(e2apMsg.p), (*C.char)(unsafe.Pointer(&e2apMsg.lb[0])), e2apMsg.msgC)
818         if err := e2apMsg.checkerr(errorNro); err != nil {
819                 return err, nil
820         }
821         return nil, e2apMsg.packeddata()
822 }
823
824 func (e2apMsg *e2apMsgPackerSubscriptionFailure) UnPack(msg *e2ap.PackedData) (error, *e2ap.E2APSubscriptionFailure) {
825         e2apMsg.init()
826         defer e2apMsg.fini()
827
828         if err := e2apMsg.e2apMessagePacker.unpacktopdu(msg); err != nil {
829                 return err, e2apMsg.msgG
830         }
831         errorNro := C.getRICSubscriptionFailureData(e2apMsg.e2apMessagePacker.pdu, e2apMsg.msgC)
832         if err := e2apMsg.checkerr(errorNro); err != nil {
833                 return err, e2apMsg.msgG
834         }
835
836         e2apMsg.msgG.FunctionId = (e2ap.FunctionId)(e2apMsg.msgC.ranFunctionID)
837         if err := (&e2apEntryRequestID{entry: &e2apMsg.msgC.ricRequestID}).get(&e2apMsg.msgG.RequestId); err != nil {
838                 return err, e2apMsg.msgG
839         }
840         e2apMsg.msgG.Cause.Content = (uint8)(e2apMsg.msgC.cause.content)
841         e2apMsg.msgG.Cause.Value = (uint8)(e2apMsg.msgC.cause.causeVal)
842         if e2apMsg.msgC.criticalityDiagnosticsPresent == true {
843                 e2apMsg.msgG.CriticalityDiagnostics.Present = true
844                 if err := (&e2apEntryCriticalityDiagnostic{entry: &e2apMsg.msgC.criticalityDiagnostics}).get(&e2apMsg.msgG.CriticalityDiagnostics); err != nil {
845                         return err, e2apMsg.msgG
846                 }
847         }
848         return nil, e2apMsg.msgG
849 }
850
851 func (e2apMsg *e2apMsgPackerSubscriptionFailure) String() string {
852         var b bytes.Buffer
853         fmt.Fprintln(&b, "ricSubscriptionFailure.")
854         fmt.Fprintln(&b, "  ricRequestID.")
855         fmt.Fprintln(&b, "    ricRequestorID =", e2apMsg.msgC.ricRequestID.ricRequestorID)
856         fmt.Fprintln(&b, "    ricInstanceID =", e2apMsg.msgC.ricRequestID.ricInstanceID)
857         fmt.Fprintln(&b, "  ranFunctionID =", e2apMsg.msgC.ranFunctionID)
858         fmt.Fprintln(&b, "  ricActionNotAdmittedList.")
859         fmt.Fprintln(&b, "    cause.content =", e2apMsg.msgC.cause.content)
860         fmt.Fprintln(&b, "    cause.causeVal =", e2apMsg.msgC.cause.causeVal)
861
862         /* NOT SUPPORTED
863         if e2apMsg.msgC.criticalityDiagnosticsPresent {
864                 fmt.Fprintln(&b, "  criticalityDiagnosticsPresent =", e2apMsg.msgC.criticalityDiagnosticsPresent)
865                 fmt.Fprintln(&b, "    criticalityDiagnostics.")
866                 fmt.Fprintln(&b, "    procedureCodePresent =", e2apMsg.msgC.criticalityDiagnostics.procedureCodePresent)
867                 fmt.Fprintln(&b, "      procedureCode =", e2apMsg.msgC.criticalityDiagnostics.procedureCode)
868                 fmt.Fprintln(&b, "    triggeringMessagePresent =", e2apMsg.msgC.criticalityDiagnostics.triggeringMessagePresent)
869                 fmt.Fprintln(&b, "      triggeringMessage =", e2apMsg.msgC.criticalityDiagnostics.triggeringMessage)
870                 fmt.Fprintln(&b, "    procedureCriticalityPresent=", e2apMsg.msgC.criticalityDiagnostics.procedureCriticalityPresent)
871                 fmt.Fprintln(&b, "      procedureCriticality =", e2apMsg.msgC.criticalityDiagnostics.procedureCriticality)
872                 fmt.Fprintln(&b, "    iEsCriticalityDiagnosticsPresent =", e2apMsg.msgC.criticalityDiagnostics.iEsCriticalityDiagnosticsPresent)
873                 fmt.Fprintln(&b, "      criticalityDiagnosticsIELength =", e2apMsg.msgC.criticalityDiagnostics.criticalityDiagnosticsIELength)
874                 var index2 uint16
875                 index2 = 0
876                 for (C.ushort)(index2) < e2apMsg.msgC.criticalityDiagnostics.criticalityDiagnosticsIELength {
877                         fmt.Fprintln(&b, "      criticalityDiagnosticsIEListItem[index2].iECriticality =", e2apMsg.msgC.criticalityDiagnostics.criticalityDiagnosticsIEListItem[index2].iECriticality)
878                         fmt.Fprintln(&b, "      criticalityDiagnosticsIEListItem[index2].iE_ID =", e2apMsg.msgC.criticalityDiagnostics.criticalityDiagnosticsIEListItem[index2].iE_ID)
879                         fmt.Fprintln(&b, "      criticalityDiagnosticsIEListItem[index2].typeOfError =", e2apMsg.msgC.criticalityDiagnostics.criticalityDiagnosticsIEListItem[index2].typeOfError)
880                         index2++
881                 }
882         }
883         */
884         return b.String()
885 }
886
887 //-----------------------------------------------------------------------------
888 //
889 //-----------------------------------------------------------------------------
890 type e2apMsgPackerSubscriptionDeleteRequest struct {
891         e2apMessagePacker
892         msgC *C.RICSubscriptionDeleteRequest_t
893         msgG *e2ap.E2APSubscriptionDeleteRequest
894 }
895
896 func (e2apMsg *e2apMsgPackerSubscriptionDeleteRequest) init() {
897         e2apMsg.e2apMessagePacker.init(C.E2MessageInfo_t{C.cE2InitiatingMessage, C.cRICSubscriptionDeleteRequest})
898         e2apMsg.msgC = &C.RICSubscriptionDeleteRequest_t{}
899         e2apMsg.msgG = &e2ap.E2APSubscriptionDeleteRequest{}
900         C.initSubsDeleteRequest(e2apMsg.msgC)
901 }
902
903 func (e2apMsg *e2apMsgPackerSubscriptionDeleteRequest) Pack(data *e2ap.E2APSubscriptionDeleteRequest) (error, *e2ap.PackedData) {
904         e2apMsg.init()
905         defer e2apMsg.fini()
906         e2apMsg.msgG = data
907
908         e2apMsg.msgC.ranFunctionID = (C.uint16_t)(e2apMsg.msgG.FunctionId)
909         if err := (&e2apEntryRequestID{entry: &e2apMsg.msgC.ricRequestID}).set(&e2apMsg.msgG.RequestId); err != nil {
910                 return err, nil
911         }
912
913         errorNro := C.packRICSubscriptionDeleteRequest(&e2apMsg.plen, (*C.uchar)(e2apMsg.p), (*C.char)(unsafe.Pointer(&e2apMsg.lb[0])), e2apMsg.msgC)
914         if err := e2apMsg.checkerr(errorNro); err != nil {
915                 return err, nil
916         }
917         return nil, e2apMsg.packeddata()
918 }
919
920 func (e2apMsg *e2apMsgPackerSubscriptionDeleteRequest) UnPack(msg *e2ap.PackedData) (error, *e2ap.E2APSubscriptionDeleteRequest) {
921         e2apMsg.init()
922         defer e2apMsg.fini()
923
924         if err := e2apMsg.e2apMessagePacker.unpacktopdu(msg); err != nil {
925                 return err, e2apMsg.msgG
926         }
927         errorNro := C.getRICSubscriptionDeleteRequestData(e2apMsg.e2apMessagePacker.pdu, e2apMsg.msgC)
928         if err := e2apMsg.checkerr(errorNro); err != nil {
929                 return err, e2apMsg.msgG
930         }
931
932         e2apMsg.msgG.FunctionId = (e2ap.FunctionId)(e2apMsg.msgC.ranFunctionID)
933         if err := (&e2apEntryRequestID{entry: &e2apMsg.msgC.ricRequestID}).get(&e2apMsg.msgG.RequestId); err != nil {
934                 return err, e2apMsg.msgG
935         }
936         return nil, e2apMsg.msgG
937
938 }
939
940 func (e2apMsg *e2apMsgPackerSubscriptionDeleteRequest) String() string {
941         var b bytes.Buffer
942         fmt.Fprintln(&b, "ricSubscriptionDeleteRequest.")
943         fmt.Fprintln(&b, "  ricRequestID.")
944         fmt.Fprintln(&b, "     ricRequestorID =", e2apMsg.msgC.ricRequestID.ricRequestorID)
945         fmt.Fprintln(&b, "     ricInstanceID =", e2apMsg.msgC.ricRequestID.ricInstanceID)
946         fmt.Fprintln(&b, "  ranFunctionID =", e2apMsg.msgC.ranFunctionID)
947         return b.String()
948 }
949
950 //-----------------------------------------------------------------------------
951 //
952 //-----------------------------------------------------------------------------
953 type e2apMsgPackerSubscriptionDeleteResponse struct {
954         e2apMessagePacker
955         msgC *C.RICSubscriptionDeleteResponse_t
956         msgG *e2ap.E2APSubscriptionDeleteResponse
957 }
958
959 func (e2apMsg *e2apMsgPackerSubscriptionDeleteResponse) init() {
960         e2apMsg.e2apMessagePacker.init(C.E2MessageInfo_t{C.cE2SuccessfulOutcome, C.cRICsubscriptionDeleteResponse})
961         e2apMsg.msgC = &C.RICSubscriptionDeleteResponse_t{}
962         e2apMsg.msgG = &e2ap.E2APSubscriptionDeleteResponse{}
963         C.initSubsDeleteResponse(e2apMsg.msgC)
964 }
965
966 func (e2apMsg *e2apMsgPackerSubscriptionDeleteResponse) Pack(data *e2ap.E2APSubscriptionDeleteResponse) (error, *e2ap.PackedData) {
967         e2apMsg.init()
968         defer e2apMsg.fini()
969         e2apMsg.msgG = data
970
971         e2apMsg.msgC.ranFunctionID = (C.uint16_t)(e2apMsg.msgG.FunctionId)
972         if err := (&e2apEntryRequestID{entry: &e2apMsg.msgC.ricRequestID}).set(&e2apMsg.msgG.RequestId); err != nil {
973                 return err, nil
974         }
975
976         errorNro := C.packRICSubscriptionDeleteResponse(&e2apMsg.plen, (*C.uchar)(e2apMsg.p), (*C.char)(unsafe.Pointer(&e2apMsg.lb[0])), e2apMsg.msgC)
977         if err := e2apMsg.checkerr(errorNro); err != nil {
978                 return err, nil
979         }
980         return nil, e2apMsg.packeddata()
981 }
982
983 func (e2apMsg *e2apMsgPackerSubscriptionDeleteResponse) UnPack(msg *e2ap.PackedData) (error, *e2ap.E2APSubscriptionDeleteResponse) {
984         e2apMsg.init()
985         defer e2apMsg.fini()
986
987         if err := e2apMsg.e2apMessagePacker.unpacktopdu(msg); err != nil {
988                 return err, e2apMsg.msgG
989         }
990         errorNro := C.getRICSubscriptionDeleteResponseData(e2apMsg.e2apMessagePacker.pdu, e2apMsg.msgC)
991         if err := e2apMsg.checkerr(errorNro); err != nil {
992                 return err, e2apMsg.msgG
993         }
994
995         e2apMsg.msgG.FunctionId = (e2ap.FunctionId)(e2apMsg.msgC.ranFunctionID)
996         if err := (&e2apEntryRequestID{entry: &e2apMsg.msgC.ricRequestID}).get(&e2apMsg.msgG.RequestId); err != nil {
997                 return err, e2apMsg.msgG
998         }
999         return nil, e2apMsg.msgG
1000 }
1001
1002 func (e2apMsg *e2apMsgPackerSubscriptionDeleteResponse) String() string {
1003         var b bytes.Buffer
1004         fmt.Fprintln(&b, "ricSubscriptionDeleteResponse.")
1005         fmt.Fprintln(&b, "  ricRequestID.")
1006         fmt.Fprintln(&b, "    ricRequestorID =", e2apMsg.msgC.ricRequestID.ricRequestorID)
1007         fmt.Fprintln(&b, "    ricInstanceID =", e2apMsg.msgC.ricRequestID.ricInstanceID)
1008         fmt.Fprintln(&b, "  ranFunctionID =", e2apMsg.msgC.ranFunctionID)
1009         return b.String()
1010 }
1011
1012 //-----------------------------------------------------------------------------
1013 //
1014 //-----------------------------------------------------------------------------
1015 type e2apMsgPackerSubscriptionDeleteFailure struct {
1016         e2apMessagePacker
1017         msgC *C.RICSubscriptionDeleteFailure_t
1018         msgG *e2ap.E2APSubscriptionDeleteFailure
1019 }
1020
1021 func (e2apMsg *e2apMsgPackerSubscriptionDeleteFailure) init() {
1022         e2apMsg.e2apMessagePacker.init(C.E2MessageInfo_t{C.cE2UnsuccessfulOutcome, C.cRICsubscriptionDeleteFailure})
1023         e2apMsg.msgC = &C.RICSubscriptionDeleteFailure_t{}
1024         e2apMsg.msgG = &e2ap.E2APSubscriptionDeleteFailure{}
1025         C.initSubsDeleteFailure(e2apMsg.msgC)
1026 }
1027
1028 func (e2apMsg *e2apMsgPackerSubscriptionDeleteFailure) Pack(data *e2ap.E2APSubscriptionDeleteFailure) (error, *e2ap.PackedData) {
1029         e2apMsg.init()
1030         defer e2apMsg.fini()
1031         e2apMsg.msgG = data
1032
1033         e2apMsg.msgC.ranFunctionID = (C.uint16_t)(e2apMsg.msgG.FunctionId)
1034         if err := (&e2apEntryRequestID{entry: &e2apMsg.msgC.ricRequestID}).set(&e2apMsg.msgG.RequestId); err != nil {
1035                 return err, nil
1036         }
1037         e2apMsg.msgC.cause.content = (C.uchar)(e2apMsg.msgG.Cause.Content)
1038         e2apMsg.msgC.cause.causeVal = (C.uchar)(e2apMsg.msgG.Cause.Value)
1039         e2apMsg.msgC.criticalityDiagnosticsPresent = false
1040         if e2apMsg.msgG.CriticalityDiagnostics.Present {
1041                 e2apMsg.msgC.criticalityDiagnosticsPresent = true
1042                 if err := (&e2apEntryCriticalityDiagnostic{entry: &e2apMsg.msgC.criticalityDiagnostics}).set(&e2apMsg.msgG.CriticalityDiagnostics); err != nil {
1043                         return err, nil
1044                 }
1045         }
1046
1047         errorNro := C.packRICSubscriptionDeleteFailure(&e2apMsg.plen, (*C.uchar)(e2apMsg.p), (*C.char)(unsafe.Pointer(&e2apMsg.lb[0])), e2apMsg.msgC)
1048         if err := e2apMsg.checkerr(errorNro); err != nil {
1049                 return err, nil
1050         }
1051         return nil, e2apMsg.packeddata()
1052 }
1053
1054 func (e2apMsg *e2apMsgPackerSubscriptionDeleteFailure) UnPack(msg *e2ap.PackedData) (error, *e2ap.E2APSubscriptionDeleteFailure) {
1055         e2apMsg.init()
1056         defer e2apMsg.fini()
1057
1058         if err := e2apMsg.e2apMessagePacker.unpacktopdu(msg); err != nil {
1059                 return err, e2apMsg.msgG
1060         }
1061         errorNro := C.getRICSubscriptionDeleteFailureData(e2apMsg.e2apMessagePacker.pdu, e2apMsg.msgC)
1062         if err := e2apMsg.checkerr(errorNro); err != nil {
1063                 return err, e2apMsg.msgG
1064         }
1065
1066         e2apMsg.msgG.FunctionId = (e2ap.FunctionId)(e2apMsg.msgC.ranFunctionID)
1067         if err := (&e2apEntryRequestID{entry: &e2apMsg.msgC.ricRequestID}).get(&e2apMsg.msgG.RequestId); err != nil {
1068                 return err, e2apMsg.msgG
1069         }
1070         e2apMsg.msgG.Cause.Content = (uint8)(e2apMsg.msgC.cause.content)
1071         e2apMsg.msgG.Cause.Value = (uint8)(e2apMsg.msgC.cause.causeVal)
1072         if e2apMsg.msgC.criticalityDiagnosticsPresent == true {
1073                 e2apMsg.msgG.CriticalityDiagnostics.Present = true
1074                 if err := (&e2apEntryCriticalityDiagnostic{entry: &e2apMsg.msgC.criticalityDiagnostics}).get(&e2apMsg.msgG.CriticalityDiagnostics); err != nil {
1075                         return err, e2apMsg.msgG
1076                 }
1077         }
1078         return nil, e2apMsg.msgG
1079 }
1080
1081 func (e2apMsg *e2apMsgPackerSubscriptionDeleteFailure) String() string {
1082         var b bytes.Buffer
1083         fmt.Fprintln(&b, "ricSubscriptionDeleteFailure.")
1084         fmt.Fprintln(&b, "  ricRequestID.")
1085         fmt.Fprintln(&b, "    ricRequestorID =", e2apMsg.msgC.ricRequestID.ricRequestorID)
1086         fmt.Fprintln(&b, "    ricInstanceID =", e2apMsg.msgC.ricRequestID.ricInstanceID)
1087         fmt.Fprintln(&b, "  ranFunctionID =", e2apMsg.msgC.ranFunctionID)
1088         /*      NOT SUPPORTED
1089                 if e2apMsg.msgC.criticalityDiagnosticsPresent {
1090                         fmt.Fprintln(&b, "  criticalityDiagnosticsPresent =", e2apMsg.msgC.criticalityDiagnosticsPresent)
1091                         fmt.Fprintln(&b, "    criticalityDiagnostics.")
1092                         fmt.Fprintln(&b, "    procedureCodePresent =", e2apMsg.msgC.criticalityDiagnostics.procedureCodePresent)
1093                         fmt.Fprintln(&b, "      procedureCode =", e2apMsg.msgC.criticalityDiagnostics.procedureCode)
1094                         fmt.Fprintln(&b, "    triggeringMessagePresent =", e2apMsg.msgC.criticalityDiagnostics.triggeringMessagePresent)
1095                         fmt.Fprintln(&b, "      triggeringMessage =", e2apMsg.msgC.criticalityDiagnostics.triggeringMessage)
1096                         fmt.Fprintln(&b, "    procedureCriticalityPresent=", e2apMsg.msgC.criticalityDiagnostics.procedureCriticalityPresent)
1097                         fmt.Fprintln(&b, "      procedureCriticality =", e2apMsg.msgC.criticalityDiagnostics.procedureCriticality)
1098                         fmt.Fprintln(&b, "    iEsCriticalityDiagnosticsPresent =", e2apMsg.msgC.criticalityDiagnostics.iEsCriticalityDiagnosticsPresent)
1099                         fmt.Fprintln(&b, "      criticalityDiagnosticsIELength =", e2apMsg.msgC.criticalityDiagnostics.criticalityDiagnosticsIELength)
1100                         var index2 uint16
1101                         index2 = 0
1102                         for (C.ushort)(index2) < e2apMsg.msgC.criticalityDiagnostics.criticalityDiagnosticsIELength {
1103                                 fmt.Fprintln(&b, "      criticalityDiagnosticsIEListItem[index2].iECriticality =", e2apMsg.msgC.criticalityDiagnostics.criticalityDiagnosticsIEListItem[index2].iECriticality)
1104                                 fmt.Fprintln(&b, "      criticalityDiagnosticsIEListItem[index2].iE_ID =", e2apMsg.msgC.criticalityDiagnostics.criticalityDiagnosticsIEListItem[index2].iE_ID)
1105                                 fmt.Fprintln(&b, "      criticalityDiagnosticsIEListItem[index2].typeOfError =", e2apMsg.msgC.criticalityDiagnostics.criticalityDiagnosticsIEListItem[index2].typeOfError)
1106                                 index2++
1107                         }
1108                 }
1109         */
1110         return b.String()
1111 }
1112
1113 //-----------------------------------------------------------------------------
1114 // Changes to support "RIC_SUB_DEL_REQUIRED"
1115 //-----------------------------------------------------------------------------
1116 type e2apMsgPackerSubscriptionDeleteRequired struct {
1117         e2apMessagePacker
1118         msgC *C.RICSubsDeleteRequired_t
1119         msgG *e2ap.SubscriptionDeleteRequiredList
1120 }
1121
1122 func (e2apMsg *e2apMsgPackerSubscriptionDeleteRequired) init() {
1123         e2apMsg.e2apMessagePacker.init(C.E2MessageInfo_t{C.cE2InitiatingMessage, C.cRICSubscriptionDeleteRequired})
1124         e2apMsg.msgC = &C.RICSubsDeleteRequired_t{}
1125         e2apMsg.msgG = &e2ap.SubscriptionDeleteRequiredList{}
1126         C.initSubsDeleteRequired(e2apMsg.msgC)
1127 }
1128
1129 func (e2apMsg *e2apMsgPackerSubscriptionDeleteRequired) Pack(data *e2ap.SubscriptionDeleteRequiredList) (error, *e2ap.PackedData) {
1130         e2apMsg.init()
1131         defer e2apMsg.fini()
1132         e2apMsg.msgG = data
1133
1134         e2apMsg.msgC.noOfRanSubscriptions = C.int(len(e2apMsg.msgG.E2APSubscriptionDeleteRequiredRequests))
1135         for idx, subs := range e2apMsg.msgG.E2APSubscriptionDeleteRequiredRequests {
1136
1137                 // RIC Request ID
1138                 e2apMsg.msgC.ranSubscriptionsDelRequired[idx].ricRequestID.ricInstanceID = (C.uint32_t)(subs.RequestId.InstanceId)
1139                 e2apMsg.msgC.ranSubscriptionsDelRequired[idx].ricRequestID.ricRequestorID = (C.uint32_t)(subs.RequestId.Id)
1140
1141                 // RAN Function ID
1142                 e2apMsg.msgC.ranSubscriptionsDelRequired[idx].ranFunctionID = (C.uint16_t)(subs.FunctionId)
1143
1144                 // RIC Cause
1145                 e2apMsg.msgC.ranSubscriptionsDelRequired[idx].cause.content = (C.uint8_t)(subs.Cause.Content)
1146                 e2apMsg.msgC.ranSubscriptionsDelRequired[idx].cause.causeVal = (C.uint8_t)(subs.Cause.Value)
1147
1148         }
1149
1150         errorNro := C.packRICSubscriptionDeleteRequired(&e2apMsg.plen, (*C.uchar)(e2apMsg.p), (*C.char)(unsafe.Pointer(&e2apMsg.lb[0])), e2apMsg.msgC)
1151         if err := e2apMsg.checkerr(errorNro); err != nil {
1152                 fmt.Printf("ERROR: %s", err.Error())
1153                 return err, nil
1154         }
1155         return nil, e2apMsg.packeddata()
1156 }
1157
1158 func (e2apMsg *e2apMsgPackerSubscriptionDeleteRequired) UnPack(msg *e2ap.PackedData) (error, *e2ap.SubscriptionDeleteRequiredList) {
1159         e2apMsg.init()
1160         defer e2apMsg.fini()
1161
1162         if err := e2apMsg.e2apMessagePacker.unpacktopdu(msg); err != nil {
1163                 return err, e2apMsg.msgG
1164         }
1165         errorNro := C.getRICSubscriptionDeleteRequiredData(e2apMsg.e2apMessagePacker.pdu, e2apMsg.msgC)
1166         if err := e2apMsg.checkerr(errorNro); err != nil {
1167                 return err, e2apMsg.msgG
1168         }
1169
1170         //TODO: Fill List of RIC Subscriptions to be Removed
1171         for idx := 0; idx < int(e2apMsg.msgC.noOfRanSubscriptions); idx++ {
1172                 var ricSubsToBeRemove e2ap.E2APSubscriptionDeleteRequired
1173                 // RIC RequestID
1174                 if err := (&e2apEntryRequestID{entry: &e2apMsg.msgC.ranSubscriptionsDelRequired[idx].ricRequestID}).get(&ricSubsToBeRemove.RequestId); err != nil {
1175                         return err, e2apMsg.msgG
1176                 }
1177                 // RAN Function ID
1178                 ricSubsToBeRemove.FunctionId = (e2ap.FunctionId)(e2apMsg.msgC.ranSubscriptionsDelRequired[idx].ranFunctionID)
1179
1180                 // RIC Cause
1181                 ricSubsToBeRemove.Cause.Content = (uint8)(e2apMsg.msgC.ranSubscriptionsDelRequired[idx].cause.content)
1182                 ricSubsToBeRemove.Cause.Value = (uint8)(e2apMsg.msgC.ranSubscriptionsDelRequired[idx].cause.causeVal)
1183
1184                 e2apMsg.msgG.E2APSubscriptionDeleteRequiredRequests = append(e2apMsg.msgG.E2APSubscriptionDeleteRequiredRequests, ricSubsToBeRemove)
1185         }
1186
1187         return nil, e2apMsg.msgG
1188 }
1189
1190 func (e2apMsg *e2apMsgPackerSubscriptionDeleteRequired) String() string {
1191         var b bytes.Buffer
1192         for idx := 0; idx < int(e2apMsg.msgC.noOfRanSubscriptions); idx++ {
1193                 fmt.Fprintln(&b, "ricSubscriptionDeleteRequired.")
1194                 fmt.Fprintln(&b, "  ricRequestID.")
1195                 fmt.Fprintln(&b, "    ricRequestorID =", e2apMsg.msgC.ranSubscriptionsDelRequired[idx].ricRequestID.ricRequestorID)
1196                 fmt.Fprintln(&b, "    ricInstanceID =", e2apMsg.msgC.ranSubscriptionsDelRequired[idx].ricRequestID.ricInstanceID)
1197                 fmt.Fprintln(&b, "  ranFunctionID =", e2apMsg.msgC.ranSubscriptionsDelRequired[idx].ranFunctionID)
1198         }
1199
1200         return b.String()
1201 }
1202
1203 //-----------------------------------------------------------------------------
1204 //
1205 //-----------------------------------------------------------------------------
1206 func SetASN1DebugPrintStatus(logLevel int) {
1207         if logLevel >= 4 {
1208                 //fmt.Println("ASN1 debug prints ON")
1209                 C.allowASN1DebugPrints(true)
1210         } else {
1211                 //fmt.Println("ASN1 debug prints OFF")
1212                 C.allowASN1DebugPrints(false)
1213         }
1214 }
1215
1216 //-----------------------------------------------------------------------------
1217 // Public E2AP packer creators
1218 //-----------------------------------------------------------------------------
1219
1220 type cppasn1E2APPacker struct{}
1221
1222 func (*cppasn1E2APPacker) NewPackerSubscriptionRequest() e2ap.E2APMsgPackerSubscriptionRequestIf {
1223         return &e2apMsgPackerSubscriptionRequest{}
1224 }
1225
1226 func (*cppasn1E2APPacker) NewPackerSubscriptionResponse() e2ap.E2APMsgPackerSubscriptionResponseIf {
1227         return &e2apMsgPackerSubscriptionResponse{}
1228 }
1229
1230 func (*cppasn1E2APPacker) NewPackerSubscriptionFailure() e2ap.E2APMsgPackerSubscriptionFailureIf {
1231         return &e2apMsgPackerSubscriptionFailure{}
1232 }
1233
1234 func (*cppasn1E2APPacker) NewPackerSubscriptionDeleteRequest() e2ap.E2APMsgPackerSubscriptionDeleteRequestIf {
1235         return &e2apMsgPackerSubscriptionDeleteRequest{}
1236 }
1237
1238 func (*cppasn1E2APPacker) NewPackerSubscriptionDeleteResponse() e2ap.E2APMsgPackerSubscriptionDeleteResponseIf {
1239         return &e2apMsgPackerSubscriptionDeleteResponse{}
1240 }
1241
1242 func (*cppasn1E2APPacker) NewPackerSubscriptionDeleteFailure() e2ap.E2APMsgPackerSubscriptionDeleteFailureIf {
1243         return &e2apMsgPackerSubscriptionDeleteFailure{}
1244 }
1245
1246 // Changes to support "RIC_SUB_DEL_REQUIRED"
1247 func (*cppasn1E2APPacker) NewPackerSubscriptionDeleteRequired() e2ap.E2APMsgPackerSubscriptionDeleteRequiredIf {
1248         return &e2apMsgPackerSubscriptionDeleteRequired{}
1249 }
1250
1251 func NewAsn1E2Packer() e2ap.E2APPackerIf {
1252         return &cppasn1E2APPacker{}
1253 }