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