73d121f78b717758cef8c16abf8ab43cf082a6c0
[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         if err := (&e2apEntryNotAdmittedList{entry: &e2apMsg.msgC.ricActionNotAdmittedList}).set(&e2apMsg.msgG.ActionNotAdmittedList); err != nil {
805                 return err, nil
806         }
807         e2apMsg.msgC.criticalityDiagnosticsPresent = false
808         if e2apMsg.msgG.CriticalityDiagnostics.Present {
809                 e2apMsg.msgC.criticalityDiagnosticsPresent = true
810                 if err := (&e2apEntryCriticalityDiagnostic{entry: &e2apMsg.msgC.criticalityDiagnostics}).set(&e2apMsg.msgG.CriticalityDiagnostics); err != nil {
811                         return err, nil
812                 }
813         }
814
815         errorNro := C.packRICSubscriptionFailure(&e2apMsg.plen, (*C.uchar)(e2apMsg.p), (*C.char)(unsafe.Pointer(&e2apMsg.lb[0])), e2apMsg.msgC)
816         if err := e2apMsg.checkerr(errorNro); err != nil {
817                 return err, nil
818         }
819         return nil, e2apMsg.packeddata()
820 }
821
822 func (e2apMsg *e2apMsgPackerSubscriptionFailure) UnPack(msg *e2ap.PackedData) (error, *e2ap.E2APSubscriptionFailure) {
823         e2apMsg.init()
824         defer e2apMsg.fini()
825
826         if err := e2apMsg.e2apMessagePacker.unpacktopdu(msg); err != nil {
827                 return err, e2apMsg.msgG
828         }
829         errorNro := C.getRICSubscriptionFailureData(e2apMsg.e2apMessagePacker.pdu, e2apMsg.msgC)
830         if err := e2apMsg.checkerr(errorNro); err != nil {
831                 return err, e2apMsg.msgG
832         }
833
834         e2apMsg.msgG.FunctionId = (e2ap.FunctionId)(e2apMsg.msgC.ranFunctionID)
835         if err := (&e2apEntryRequestID{entry: &e2apMsg.msgC.ricRequestID}).get(&e2apMsg.msgG.RequestId); err != nil {
836                 return err, e2apMsg.msgG
837         }
838         if err := (&e2apEntryNotAdmittedList{entry: &e2apMsg.msgC.ricActionNotAdmittedList}).get(&e2apMsg.msgG.ActionNotAdmittedList); err != nil {
839                 return err, e2apMsg.msgG
840         }
841         if e2apMsg.msgC.criticalityDiagnosticsPresent == true {
842                 e2apMsg.msgG.CriticalityDiagnostics.Present = true
843                 if err := (&e2apEntryCriticalityDiagnostic{entry: &e2apMsg.msgC.criticalityDiagnostics}).get(&e2apMsg.msgG.CriticalityDiagnostics); err != nil {
844                         return err, e2apMsg.msgG
845                 }
846         }
847         return nil, e2apMsg.msgG
848 }
849
850 func (e2apMsg *e2apMsgPackerSubscriptionFailure) String() string {
851         var b bytes.Buffer
852         fmt.Fprintln(&b, "ricSubscriptionFailure.")
853         fmt.Fprintln(&b, "  ricRequestID.")
854         fmt.Fprintln(&b, "    ricRequestorID =", e2apMsg.msgC.ricRequestID.ricRequestorID)
855         fmt.Fprintln(&b, "    ricInstanceID =", e2apMsg.msgC.ricRequestID.ricInstanceID)
856         fmt.Fprintln(&b, "  ranFunctionID =", e2apMsg.msgC.ranFunctionID)
857         fmt.Fprintln(&b, "  ricActionNotAdmittedList.")
858         fmt.Fprintln(&b, "    contentLength =", e2apMsg.msgC.ricActionNotAdmittedList.contentLength)
859         var index uint8
860         index = 0
861         for (C.uchar)(index) < e2apMsg.msgC.ricActionNotAdmittedList.contentLength {
862                 fmt.Fprintln(&b, "    RICActionNotAdmittedItem[index].ricActionID =", e2apMsg.msgC.ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricActionID)
863                 fmt.Fprintln(&b, "    RICActionNotAdmittedItem[index].cause.content =", e2apMsg.msgC.ricActionNotAdmittedList.RICActionNotAdmittedItem[index].cause.content)
864                 fmt.Fprintln(&b, "    RICActionNotAdmittedItem[index].cause.causeVal =", e2apMsg.msgC.ricActionNotAdmittedList.RICActionNotAdmittedItem[index].cause.causeVal)
865                 index++
866         }
867         /* NOT SUPPORTED
868         if e2apMsg.msgC.criticalityDiagnosticsPresent {
869                 fmt.Fprintln(&b, "  criticalityDiagnosticsPresent =", e2apMsg.msgC.criticalityDiagnosticsPresent)
870                 fmt.Fprintln(&b, "    criticalityDiagnostics.")
871                 fmt.Fprintln(&b, "    procedureCodePresent =", e2apMsg.msgC.criticalityDiagnostics.procedureCodePresent)
872                 fmt.Fprintln(&b, "      procedureCode =", e2apMsg.msgC.criticalityDiagnostics.procedureCode)
873                 fmt.Fprintln(&b, "    triggeringMessagePresent =", e2apMsg.msgC.criticalityDiagnostics.triggeringMessagePresent)
874                 fmt.Fprintln(&b, "      triggeringMessage =", e2apMsg.msgC.criticalityDiagnostics.triggeringMessage)
875                 fmt.Fprintln(&b, "    procedureCriticalityPresent=", e2apMsg.msgC.criticalityDiagnostics.procedureCriticalityPresent)
876                 fmt.Fprintln(&b, "      procedureCriticality =", e2apMsg.msgC.criticalityDiagnostics.procedureCriticality)
877                 fmt.Fprintln(&b, "    iEsCriticalityDiagnosticsPresent =", e2apMsg.msgC.criticalityDiagnostics.iEsCriticalityDiagnosticsPresent)
878                 fmt.Fprintln(&b, "      criticalityDiagnosticsIELength =", e2apMsg.msgC.criticalityDiagnostics.criticalityDiagnosticsIELength)
879                 var index2 uint16
880                 index2 = 0
881                 for (C.ushort)(index2) < e2apMsg.msgC.criticalityDiagnostics.criticalityDiagnosticsIELength {
882                         fmt.Fprintln(&b, "      criticalityDiagnosticsIEListItem[index2].iECriticality =", e2apMsg.msgC.criticalityDiagnostics.criticalityDiagnosticsIEListItem[index2].iECriticality)
883                         fmt.Fprintln(&b, "      criticalityDiagnosticsIEListItem[index2].iE_ID =", e2apMsg.msgC.criticalityDiagnostics.criticalityDiagnosticsIEListItem[index2].iE_ID)
884                         fmt.Fprintln(&b, "      criticalityDiagnosticsIEListItem[index2].typeOfError =", e2apMsg.msgC.criticalityDiagnostics.criticalityDiagnosticsIEListItem[index2].typeOfError)
885                         index2++
886                 }
887         }
888         */
889         return b.String()
890 }
891
892 //-----------------------------------------------------------------------------
893 //
894 //-----------------------------------------------------------------------------
895 type e2apMsgPackerSubscriptionDeleteRequest struct {
896         e2apMessagePacker
897         msgC *C.RICSubscriptionDeleteRequest_t
898         msgG *e2ap.E2APSubscriptionDeleteRequest
899 }
900
901 func (e2apMsg *e2apMsgPackerSubscriptionDeleteRequest) init() {
902         e2apMsg.e2apMessagePacker.init(C.E2MessageInfo_t{C.cE2InitiatingMessage, C.cRICSubscriptionDeleteRequest})
903         e2apMsg.msgC = &C.RICSubscriptionDeleteRequest_t{}
904         e2apMsg.msgG = &e2ap.E2APSubscriptionDeleteRequest{}
905         C.initSubsDeleteRequest(e2apMsg.msgC)
906 }
907
908 func (e2apMsg *e2apMsgPackerSubscriptionDeleteRequest) Pack(data *e2ap.E2APSubscriptionDeleteRequest) (error, *e2ap.PackedData) {
909         e2apMsg.init()
910         defer e2apMsg.fini()
911         e2apMsg.msgG = data
912
913         e2apMsg.msgC.ranFunctionID = (C.uint16_t)(e2apMsg.msgG.FunctionId)
914         if err := (&e2apEntryRequestID{entry: &e2apMsg.msgC.ricRequestID}).set(&e2apMsg.msgG.RequestId); err != nil {
915                 return err, nil
916         }
917
918         errorNro := C.packRICSubscriptionDeleteRequest(&e2apMsg.plen, (*C.uchar)(e2apMsg.p), (*C.char)(unsafe.Pointer(&e2apMsg.lb[0])), e2apMsg.msgC)
919         if err := e2apMsg.checkerr(errorNro); err != nil {
920                 return err, nil
921         }
922         return nil, e2apMsg.packeddata()
923 }
924
925 func (e2apMsg *e2apMsgPackerSubscriptionDeleteRequest) UnPack(msg *e2ap.PackedData) (error, *e2ap.E2APSubscriptionDeleteRequest) {
926         e2apMsg.init()
927         defer e2apMsg.fini()
928
929         if err := e2apMsg.e2apMessagePacker.unpacktopdu(msg); err != nil {
930                 return err, e2apMsg.msgG
931         }
932         errorNro := C.getRICSubscriptionDeleteRequestData(e2apMsg.e2apMessagePacker.pdu, e2apMsg.msgC)
933         if err := e2apMsg.checkerr(errorNro); err != nil {
934                 return err, e2apMsg.msgG
935         }
936
937         e2apMsg.msgG.FunctionId = (e2ap.FunctionId)(e2apMsg.msgC.ranFunctionID)
938         if err := (&e2apEntryRequestID{entry: &e2apMsg.msgC.ricRequestID}).get(&e2apMsg.msgG.RequestId); err != nil {
939                 return err, e2apMsg.msgG
940         }
941         return nil, e2apMsg.msgG
942
943 }
944
945 func (e2apMsg *e2apMsgPackerSubscriptionDeleteRequest) String() string {
946         var b bytes.Buffer
947         fmt.Fprintln(&b, "ricSubscriptionDeleteRequest.")
948         fmt.Fprintln(&b, "  ricRequestID.")
949         fmt.Fprintln(&b, "     ricRequestorID =", e2apMsg.msgC.ricRequestID.ricRequestorID)
950         fmt.Fprintln(&b, "     ricInstanceID =", e2apMsg.msgC.ricRequestID.ricInstanceID)
951         fmt.Fprintln(&b, "  ranFunctionID =", e2apMsg.msgC.ranFunctionID)
952         return b.String()
953 }
954
955 //-----------------------------------------------------------------------------
956 //
957 //-----------------------------------------------------------------------------
958 type e2apMsgPackerSubscriptionDeleteResponse struct {
959         e2apMessagePacker
960         msgC *C.RICSubscriptionDeleteResponse_t
961         msgG *e2ap.E2APSubscriptionDeleteResponse
962 }
963
964 func (e2apMsg *e2apMsgPackerSubscriptionDeleteResponse) init() {
965         e2apMsg.e2apMessagePacker.init(C.E2MessageInfo_t{C.cE2SuccessfulOutcome, C.cRICsubscriptionDeleteResponse})
966         e2apMsg.msgC = &C.RICSubscriptionDeleteResponse_t{}
967         e2apMsg.msgG = &e2ap.E2APSubscriptionDeleteResponse{}
968         C.initSubsDeleteResponse(e2apMsg.msgC)
969 }
970
971 func (e2apMsg *e2apMsgPackerSubscriptionDeleteResponse) Pack(data *e2ap.E2APSubscriptionDeleteResponse) (error, *e2ap.PackedData) {
972         e2apMsg.init()
973         defer e2apMsg.fini()
974         e2apMsg.msgG = data
975
976         e2apMsg.msgC.ranFunctionID = (C.uint16_t)(e2apMsg.msgG.FunctionId)
977         if err := (&e2apEntryRequestID{entry: &e2apMsg.msgC.ricRequestID}).set(&e2apMsg.msgG.RequestId); err != nil {
978                 return err, nil
979         }
980
981         errorNro := C.packRICSubscriptionDeleteResponse(&e2apMsg.plen, (*C.uchar)(e2apMsg.p), (*C.char)(unsafe.Pointer(&e2apMsg.lb[0])), e2apMsg.msgC)
982         if err := e2apMsg.checkerr(errorNro); err != nil {
983                 return err, nil
984         }
985         return nil, e2apMsg.packeddata()
986 }
987
988 func (e2apMsg *e2apMsgPackerSubscriptionDeleteResponse) UnPack(msg *e2ap.PackedData) (error, *e2ap.E2APSubscriptionDeleteResponse) {
989         e2apMsg.init()
990         defer e2apMsg.fini()
991
992         if err := e2apMsg.e2apMessagePacker.unpacktopdu(msg); err != nil {
993                 return err, e2apMsg.msgG
994         }
995         errorNro := C.getRICSubscriptionDeleteResponseData(e2apMsg.e2apMessagePacker.pdu, e2apMsg.msgC)
996         if err := e2apMsg.checkerr(errorNro); err != nil {
997                 return err, e2apMsg.msgG
998         }
999
1000         e2apMsg.msgG.FunctionId = (e2ap.FunctionId)(e2apMsg.msgC.ranFunctionID)
1001         if err := (&e2apEntryRequestID{entry: &e2apMsg.msgC.ricRequestID}).get(&e2apMsg.msgG.RequestId); err != nil {
1002                 return err, e2apMsg.msgG
1003         }
1004         return nil, e2apMsg.msgG
1005 }
1006
1007 func (e2apMsg *e2apMsgPackerSubscriptionDeleteResponse) String() string {
1008         var b bytes.Buffer
1009         fmt.Fprintln(&b, "ricSubscriptionDeleteResponse.")
1010         fmt.Fprintln(&b, "  ricRequestID.")
1011         fmt.Fprintln(&b, "    ricRequestorID =", e2apMsg.msgC.ricRequestID.ricRequestorID)
1012         fmt.Fprintln(&b, "    ricInstanceID =", e2apMsg.msgC.ricRequestID.ricInstanceID)
1013         fmt.Fprintln(&b, "  ranFunctionID =", e2apMsg.msgC.ranFunctionID)
1014         return b.String()
1015 }
1016
1017 //-----------------------------------------------------------------------------
1018 //
1019 //-----------------------------------------------------------------------------
1020 type e2apMsgPackerSubscriptionDeleteFailure struct {
1021         e2apMessagePacker
1022         msgC *C.RICSubscriptionDeleteFailure_t
1023         msgG *e2ap.E2APSubscriptionDeleteFailure
1024 }
1025
1026 func (e2apMsg *e2apMsgPackerSubscriptionDeleteFailure) init() {
1027         e2apMsg.e2apMessagePacker.init(C.E2MessageInfo_t{C.cE2UnsuccessfulOutcome, C.cRICsubscriptionDeleteFailure})
1028         e2apMsg.msgC = &C.RICSubscriptionDeleteFailure_t{}
1029         e2apMsg.msgG = &e2ap.E2APSubscriptionDeleteFailure{}
1030         C.initSubsDeleteFailure(e2apMsg.msgC)
1031 }
1032
1033 func (e2apMsg *e2apMsgPackerSubscriptionDeleteFailure) Pack(data *e2ap.E2APSubscriptionDeleteFailure) (error, *e2ap.PackedData) {
1034         e2apMsg.init()
1035         defer e2apMsg.fini()
1036         e2apMsg.msgG = data
1037
1038         e2apMsg.msgC.ranFunctionID = (C.uint16_t)(e2apMsg.msgG.FunctionId)
1039         if err := (&e2apEntryRequestID{entry: &e2apMsg.msgC.ricRequestID}).set(&e2apMsg.msgG.RequestId); err != nil {
1040                 return err, nil
1041         }
1042         e2apMsg.msgC.cause.content = (C.uchar)(e2apMsg.msgG.Cause.Content)
1043         e2apMsg.msgC.cause.causeVal = (C.uchar)(e2apMsg.msgG.Cause.Value)
1044         e2apMsg.msgC.criticalityDiagnosticsPresent = false
1045         if e2apMsg.msgG.CriticalityDiagnostics.Present {
1046                 e2apMsg.msgC.criticalityDiagnosticsPresent = true
1047                 if err := (&e2apEntryCriticalityDiagnostic{entry: &e2apMsg.msgC.criticalityDiagnostics}).set(&e2apMsg.msgG.CriticalityDiagnostics); err != nil {
1048                         return err, nil
1049                 }
1050         }
1051
1052         errorNro := C.packRICSubscriptionDeleteFailure(&e2apMsg.plen, (*C.uchar)(e2apMsg.p), (*C.char)(unsafe.Pointer(&e2apMsg.lb[0])), e2apMsg.msgC)
1053         if err := e2apMsg.checkerr(errorNro); err != nil {
1054                 return err, nil
1055         }
1056         return nil, e2apMsg.packeddata()
1057 }
1058
1059 func (e2apMsg *e2apMsgPackerSubscriptionDeleteFailure) UnPack(msg *e2ap.PackedData) (error, *e2ap.E2APSubscriptionDeleteFailure) {
1060         e2apMsg.init()
1061         defer e2apMsg.fini()
1062
1063         if err := e2apMsg.e2apMessagePacker.unpacktopdu(msg); err != nil {
1064                 return err, e2apMsg.msgG
1065         }
1066         errorNro := C.getRICSubscriptionDeleteFailureData(e2apMsg.e2apMessagePacker.pdu, e2apMsg.msgC)
1067         if err := e2apMsg.checkerr(errorNro); err != nil {
1068                 return err, e2apMsg.msgG
1069         }
1070
1071         e2apMsg.msgG.FunctionId = (e2ap.FunctionId)(e2apMsg.msgC.ranFunctionID)
1072         if err := (&e2apEntryRequestID{entry: &e2apMsg.msgC.ricRequestID}).get(&e2apMsg.msgG.RequestId); err != nil {
1073                 return err, e2apMsg.msgG
1074         }
1075         e2apMsg.msgG.Cause.Content = (uint8)(e2apMsg.msgC.cause.content)
1076         e2apMsg.msgG.Cause.Value = (uint8)(e2apMsg.msgC.cause.causeVal)
1077         if e2apMsg.msgC.criticalityDiagnosticsPresent == true {
1078                 e2apMsg.msgG.CriticalityDiagnostics.Present = true
1079                 if err := (&e2apEntryCriticalityDiagnostic{entry: &e2apMsg.msgC.criticalityDiagnostics}).get(&e2apMsg.msgG.CriticalityDiagnostics); err != nil {
1080                         return err, e2apMsg.msgG
1081                 }
1082         }
1083         return nil, e2apMsg.msgG
1084 }
1085
1086 func (e2apMsg *e2apMsgPackerSubscriptionDeleteFailure) String() string {
1087         var b bytes.Buffer
1088         fmt.Fprintln(&b, "ricSubscriptionDeleteFailure.")
1089         fmt.Fprintln(&b, "  ricRequestID.")
1090         fmt.Fprintln(&b, "    ricRequestorID =", e2apMsg.msgC.ricRequestID.ricRequestorID)
1091         fmt.Fprintln(&b, "    ricInstanceID =", e2apMsg.msgC.ricRequestID.ricInstanceID)
1092         fmt.Fprintln(&b, "  ranFunctionID =", e2apMsg.msgC.ranFunctionID)
1093         /*      NOT SUPPORTED
1094                 if e2apMsg.msgC.criticalityDiagnosticsPresent {
1095                         fmt.Fprintln(&b, "  criticalityDiagnosticsPresent =", e2apMsg.msgC.criticalityDiagnosticsPresent)
1096                         fmt.Fprintln(&b, "    criticalityDiagnostics.")
1097                         fmt.Fprintln(&b, "    procedureCodePresent =", e2apMsg.msgC.criticalityDiagnostics.procedureCodePresent)
1098                         fmt.Fprintln(&b, "      procedureCode =", e2apMsg.msgC.criticalityDiagnostics.procedureCode)
1099                         fmt.Fprintln(&b, "    triggeringMessagePresent =", e2apMsg.msgC.criticalityDiagnostics.triggeringMessagePresent)
1100                         fmt.Fprintln(&b, "      triggeringMessage =", e2apMsg.msgC.criticalityDiagnostics.triggeringMessage)
1101                         fmt.Fprintln(&b, "    procedureCriticalityPresent=", e2apMsg.msgC.criticalityDiagnostics.procedureCriticalityPresent)
1102                         fmt.Fprintln(&b, "      procedureCriticality =", e2apMsg.msgC.criticalityDiagnostics.procedureCriticality)
1103                         fmt.Fprintln(&b, "    iEsCriticalityDiagnosticsPresent =", e2apMsg.msgC.criticalityDiagnostics.iEsCriticalityDiagnosticsPresent)
1104                         fmt.Fprintln(&b, "      criticalityDiagnosticsIELength =", e2apMsg.msgC.criticalityDiagnostics.criticalityDiagnosticsIELength)
1105                         var index2 uint16
1106                         index2 = 0
1107                         for (C.ushort)(index2) < e2apMsg.msgC.criticalityDiagnostics.criticalityDiagnosticsIELength {
1108                                 fmt.Fprintln(&b, "      criticalityDiagnosticsIEListItem[index2].iECriticality =", e2apMsg.msgC.criticalityDiagnostics.criticalityDiagnosticsIEListItem[index2].iECriticality)
1109                                 fmt.Fprintln(&b, "      criticalityDiagnosticsIEListItem[index2].iE_ID =", e2apMsg.msgC.criticalityDiagnostics.criticalityDiagnosticsIEListItem[index2].iE_ID)
1110                                 fmt.Fprintln(&b, "      criticalityDiagnosticsIEListItem[index2].typeOfError =", e2apMsg.msgC.criticalityDiagnostics.criticalityDiagnosticsIEListItem[index2].typeOfError)
1111                                 index2++
1112                         }
1113                 }
1114         */
1115         return b.String()
1116 }
1117
1118 //-----------------------------------------------------------------------------
1119 //
1120 //-----------------------------------------------------------------------------
1121 func SetASN1DebugPrintStatus(logLevel int) {
1122         if logLevel >= 4 {
1123                 //fmt.Println("ASN1 debug prints ON")
1124                 C.allowASN1DebugPrints(true)
1125         } else {
1126                 //fmt.Println("ASN1 debug prints OFF")
1127                 C.allowASN1DebugPrints(false)
1128         }
1129 }
1130
1131 //-----------------------------------------------------------------------------
1132 // Public E2AP packer creators
1133 //-----------------------------------------------------------------------------
1134
1135 type cppasn1E2APPacker struct{}
1136
1137 func (*cppasn1E2APPacker) NewPackerSubscriptionRequest() e2ap.E2APMsgPackerSubscriptionRequestIf {
1138         return &e2apMsgPackerSubscriptionRequest{}
1139 }
1140
1141 func (*cppasn1E2APPacker) NewPackerSubscriptionResponse() e2ap.E2APMsgPackerSubscriptionResponseIf {
1142         return &e2apMsgPackerSubscriptionResponse{}
1143 }
1144
1145 func (*cppasn1E2APPacker) NewPackerSubscriptionFailure() e2ap.E2APMsgPackerSubscriptionFailureIf {
1146         return &e2apMsgPackerSubscriptionFailure{}
1147 }
1148
1149 func (*cppasn1E2APPacker) NewPackerSubscriptionDeleteRequest() e2ap.E2APMsgPackerSubscriptionDeleteRequestIf {
1150         return &e2apMsgPackerSubscriptionDeleteRequest{}
1151 }
1152
1153 func (*cppasn1E2APPacker) NewPackerSubscriptionDeleteResponse() e2ap.E2APMsgPackerSubscriptionDeleteResponseIf {
1154         return &e2apMsgPackerSubscriptionDeleteResponse{}
1155 }
1156
1157 func (*cppasn1E2APPacker) NewPackerSubscriptionDeleteFailure() e2ap.E2APMsgPackerSubscriptionDeleteFailureIf {
1158         return &e2apMsgPackerSubscriptionDeleteFailure{}
1159 }
1160
1161 func NewAsn1E2Packer() e2ap.E2APPackerIf {
1162         return &cppasn1E2APPacker{}
1163 }