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