RICPLT-2910
[ric-plt/submgr.git] / e2ap / libe2ap_wrapper / E2AP_if.c
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 #include <stdio.h>
21 #include <stdlib.h>
22
23 #include "E2AP-PDU.h"
24 #include "ProtocolIE-Field.h"
25 #include "RICsubsequentAction.h"
26 #include "E2SM-gNB-X2-eventTriggerDefinition.h"
27 #include "E2SM-gNB-X2-indicationHeader.h"
28 #include "E2SM-gNB-X2-indicationMessage.h"
29 #include "asn_constant.h"
30 #include "E2AP_if.h"
31
32 #ifdef DEBUG
33     static const bool debug = true;
34 #else
35     static const bool debug = false;
36 #endif
37
38
39 const int64_t cMaxNrOfErrors = 256;
40
41 const uint64_t cMaxSizeOfOctetString = 1024;
42
43 const size_t cMacroENBIDP_20Bits = 20;
44 const size_t cHomeENBID_28Bits = 28;
45 const size_t cShortMacroENBID_18Bits = 18;
46 const size_t clongMacroENBIDP_21Bits = 21;
47
48 const int cRICCauseRadioNetwork = 1; // this is content of type RICCause_t
49 const int cRICCauseTransport = 2; // this is content of type RICCause_t
50 const int cRICCauseProtocol = 3; // this is content of type RICCause_t
51 const int cRICCauseMisc = 4; // this is content of type RICCause_t
52 const int cRICCauseRic = 5; // this is content of type RICCause_t
53
54 //////////////////////////////////////////////////////////////////////
55 // Message definitons
56
57 // Below constant values are same as in E2AP, E2SM and X2AP specs
58 const uint64_t cE2InitiatingMessage = 1;
59 const uint64_t cE2SuccessfulOutcome = 2;
60 const uint64_t cE2UnsuccessfulOutcome = 3;
61
62 // E2AP messages
63 // Initiating message
64 const uint64_t cRICSubscriptionRequest = 1;
65 const uint64_t cRICSubscriptionDeleteRequest = 2;
66 const uint64_t cRICIndication = 11;
67
68 // Successful outcome
69 const uint64_t cRICSubscriptionResponse = 1;
70 const uint64_t cRICsubscriptionDeleteResponse = 2;
71
72 // Unsuccessful outcome
73 const uint64_t cRICSubscriptionFailure = 1;
74 const uint64_t cRICsubscriptionDeleteFailure = 2;
75
76 typedef union {
77     uint32_t  nodeID;
78     uint8_t   octets[4];
79 } IdOctects_t;
80
81 //////////////////////////////////////////////////////////////////////
82 const char* getE2ErrorString(uint64_t errorCode) {
83
84     return E2ErrorStrings[errorCode];
85 }
86
87 /////////////////////////////////////////////////////////////////////
88 bool E2encode(E2AP_PDU_t* pE2AP_PDU, size_t* dataBufferSize, byte* dataBuffer, char* pLogBuffer) {
89
90     // Debug print
91     if (debug)
92         asn_fprint(stdout, &asn_DEF_E2AP_PDU, pE2AP_PDU);
93
94     asn_enc_rval_t rval;
95     rval = asn_encode_to_buffer(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, pE2AP_PDU, dataBuffer, *dataBufferSize);
96     if (rval.encoded == -1) {
97         sprintf(pLogBuffer,"\nSerialization of %s failed.\n", asn_DEF_E2AP_PDU.name);
98         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
99         return false;
100     }
101     else if (rval.encoded > *dataBufferSize) {
102         sprintf(pLogBuffer,"\nBuffer of size %zu is too small for %s, need %zu\n",*dataBufferSize, asn_DEF_E2AP_PDU.name, rval.encoded);
103         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
104         return false;
105     }
106     else {
107         if (debug)
108             sprintf(pLogBuffer,"\nSuccessfully encoded %s. Buffer size %zu, encoded size %zu\n\n",asn_DEF_E2AP_PDU.name, *dataBufferSize, rval.encoded);
109
110         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
111         *dataBufferSize = rval.encoded;
112         return true;
113     }
114 }
115
116 //////////////////////////////////////////////////////////////////////
117 uint64_t packRICSubscriptionRequest(size_t* pdataBufferSize, byte* pDataBuffer, char* pLogBuffer, RICSubscriptionRequest_t* pRICSubscriptionRequest) {
118
119     E2AP_PDU_t* pE2AP_PDU = calloc(1, sizeof(E2AP_PDU_t));
120     if(pE2AP_PDU)
121         {
122         pE2AP_PDU->present = E2AP_PDU_PR_initiatingMessage;
123         pE2AP_PDU->choice.initiatingMessage.procedureCode = ProcedureCode_id_ricSubscription;
124         pE2AP_PDU->choice.initiatingMessage.criticality = Criticality_ignore;
125         pE2AP_PDU->choice.initiatingMessage.value.present = RICInitiatingMessage__value_PR_RICsubscriptionRequest;
126
127         // RICrequestID
128         RICsubscriptionRequest_IEs_t* pRICsubscriptionRequest_IEs = calloc(1, sizeof(RICsubscriptionRequest_IEs_t));
129         if (pRICsubscriptionRequest_IEs) {
130             pRICsubscriptionRequest_IEs->id = ProtocolIE_ID_id_RICrequestID;
131             pRICsubscriptionRequest_IEs->criticality = Criticality_reject;
132             pRICsubscriptionRequest_IEs->value.present = RICsubscriptionRequest_IEs__value_PR_RICrequestID;
133             pRICsubscriptionRequest_IEs->value.choice.RICrequestID.ricRequestorID = pRICSubscriptionRequest->ricRequestID.ricRequestorID;
134             pRICsubscriptionRequest_IEs->value.choice.RICrequestID.ricRequestSequenceNumber = pRICSubscriptionRequest->ricRequestID.ricRequestSequenceNumber;
135             ASN_SEQUENCE_ADD(&pE2AP_PDU->choice.initiatingMessage.value.choice.RICsubscriptionRequest.protocolIEs.list, pRICsubscriptionRequest_IEs);
136         }
137         else
138             return e2err_RICSubscriptionRequestAllocRICrequestIDFail;
139
140         // RANfunctionID
141         pRICsubscriptionRequest_IEs = calloc(1, sizeof(RICsubscriptionRequest_IEs_t));
142         if (pRICsubscriptionRequest_IEs) {
143             pRICsubscriptionRequest_IEs->id = ProtocolIE_ID_id_RANfunctionID;
144             pRICsubscriptionRequest_IEs->criticality = Criticality_reject;
145             pRICsubscriptionRequest_IEs->value.present = RICsubscriptionRequest_IEs__value_PR_RANfunctionID;
146             pRICsubscriptionRequest_IEs->value.choice.RANfunctionID = pRICSubscriptionRequest->ranFunctionID;
147             ASN_SEQUENCE_ADD(&pE2AP_PDU->choice.initiatingMessage.value.choice.RICsubscriptionRequest.protocolIEs.list, pRICsubscriptionRequest_IEs);
148         }
149         else
150             return e2err_RICSubscriptionRequestAllocRANfunctionIDFail;
151
152         // RICsubscription
153         pRICsubscriptionRequest_IEs = calloc(1, sizeof(RICsubscriptionRequest_IEs_t));
154         if (pRICsubscriptionRequest_IEs) {
155             pRICsubscriptionRequest_IEs->id = ProtocolIE_ID_id_RICsubscription;
156             pRICsubscriptionRequest_IEs->criticality = Criticality_reject;
157             pRICsubscriptionRequest_IEs->value.present = RICsubscriptionRequest_IEs__value_PR_RICsubscription;
158
159             // RICeventTriggerDefinition
160             uint64_t returnCode;
161             if ((returnCode = packRICEventTriggerDefinition(pLogBuffer, &pRICSubscriptionRequest->ricSubscription.ricEventTriggerDefinition) != e2err_OK))
162                 return returnCode;
163
164             pRICsubscriptionRequest_IEs->value.choice.RICsubscription.ricEventTriggerDefinition.buf =
165               calloc(1, pRICSubscriptionRequest->ricSubscription.ricEventTriggerDefinition.octetString.contentLength);
166             if (pRICsubscriptionRequest_IEs->value.choice.RICsubscription.ricEventTriggerDefinition.buf) {
167                 pRICsubscriptionRequest_IEs->value.choice.RICsubscription.ricEventTriggerDefinition.size =
168                   pRICSubscriptionRequest->ricSubscription.ricEventTriggerDefinition.octetString.contentLength;
169                 memcpy(pRICsubscriptionRequest_IEs->value.choice.RICsubscription.ricEventTriggerDefinition.buf,
170                        pRICSubscriptionRequest->ricSubscription.ricEventTriggerDefinition.octetString.data,
171                        pRICSubscriptionRequest->ricSubscription.ricEventTriggerDefinition.octetString.contentLength);
172             }
173             else
174                 return e2err_RICSubscriptionRequestAllocRICeventTriggerDefinitionBufFail;
175
176             // RICactions-ToBeSetup-List
177             uint64_t index = 0;
178             while (index < pRICSubscriptionRequest->ricSubscription.ricActionToBeSetupItemIEs.contentLength && index < maxofRICactionID) {
179
180                 RICaction_ToBeSetup_ItemIEs_t* pRICaction_ToBeSetup_ItemIEs = calloc(1, sizeof(RICaction_ToBeSetup_ItemIEs_t));
181                 if (pRICaction_ToBeSetup_ItemIEs) {
182                     pRICaction_ToBeSetup_ItemIEs->id = ProtocolIE_ID_id_RICaction_ToBeSetup_Item;
183                     pRICaction_ToBeSetup_ItemIEs->criticality = Criticality_reject;
184                     pRICaction_ToBeSetup_ItemIEs->value.present = RICaction_ToBeSetup_ItemIEs__value_PR_RICaction_ToBeSetup_Item;
185                     // RICActionID
186                     pRICaction_ToBeSetup_ItemIEs->value.choice.RICaction_ToBeSetup_Item.ricActionID =
187                       pRICSubscriptionRequest->ricSubscription.ricActionToBeSetupItemIEs.ricActionToBeSetupItem[index].ricActionID;
188                     // RICActionType
189                     pRICaction_ToBeSetup_ItemIEs->value.choice.RICaction_ToBeSetup_Item.ricActionType =
190                       pRICSubscriptionRequest->ricSubscription.ricActionToBeSetupItemIEs.ricActionToBeSetupItem[index].ricActionType;
191                 }
192                 else
193                     return e2err_RICSubscriptionRequestAllocRICaction_ToBeSetup_ItemIEsFail;
194
195                 // RICactionDefinition, OPTIONAL
196                   // This is not used in RIC
197
198                 // RICsubsequentAction, OPTIONAL
199                 RICsubsequentAction_t* pRICsubsequentAction = calloc(1, sizeof(RICsubsequentAction_t));
200                 if (pRICsubsequentAction) {
201                     pRICsubsequentAction->ricSubsequentActionType =
202                       pRICSubscriptionRequest->ricSubscription.ricActionToBeSetupItemIEs.ricActionToBeSetupItem[index].ricSubsequentAction.ricSubsequentActionType;
203                     pRICsubsequentAction->ricTimeToWait =
204                       pRICSubscriptionRequest->ricSubscription.ricActionToBeSetupItemIEs.ricActionToBeSetupItem[index].ricSubsequentAction.ricTimeToWait;
205                     pRICaction_ToBeSetup_ItemIEs->value.choice.RICaction_ToBeSetup_Item.ricSubsequentAction = pRICsubsequentAction;
206                 }
207                 else
208                     return e2err_RICSubscriptionRequestAllocRICsubsequentActionFail;
209
210                 ASN_SEQUENCE_ADD(&pRICsubscriptionRequest_IEs->value.choice.RICsubscription.ricAction_ToBeSetup_List.list, pRICaction_ToBeSetup_ItemIEs);
211                 index++;
212             }
213             ASN_SEQUENCE_ADD(&pE2AP_PDU->choice.initiatingMessage.value.choice.RICsubscriptionRequest.protocolIEs.list, pRICsubscriptionRequest_IEs);
214         }
215         else
216             return e2err_RICSubscriptionRequestAllocRICsubscriptionRequest_IEsFail;
217
218         if (E2encode(pE2AP_PDU, pdataBufferSize, pDataBuffer, pLogBuffer))
219             return e2err_OK;
220         else
221             return e2err_RICSubscriptionRequestEncodeFail;
222     }
223     return e2err_RICSubscriptionRequestAllocE2AP_PDUFail;
224 }
225
226 //////////////////////////////////////////////////////////////////////
227 uint64_t packRICEventTriggerDefinition(char* pLogBuffer, RICEventTriggerDefinition_t* pRICEventTriggerDefinition) {
228
229     E2SM_gNB_X2_eventTriggerDefinition_t* pE2SM_gNB_X2_eventTriggerDefinition = calloc(1, sizeof(E2SM_gNB_X2_eventTriggerDefinition_t));
230     if(pE2SM_gNB_X2_eventTriggerDefinition)
231         {
232         // RICeventTriggerDefinition
233         // InterfaceID
234         if ((pRICEventTriggerDefinition->interfaceID.globalENBIDPresent == true && pRICEventTriggerDefinition->interfaceID.globalGNBIDPresent == true) ||
235             (pRICEventTriggerDefinition->interfaceID.globalENBIDPresent == false && pRICEventTriggerDefinition->interfaceID.globalGNBIDPresent == false))
236             return e2err_RICEventTriggerDefinitionIEValueFail_1;
237
238         // GlobalENB-ID or GlobalGNB-ID
239         if (pRICEventTriggerDefinition->interfaceID.globalENBIDPresent)
240         {
241             pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.present = Interface_ID_PR_global_eNB_ID;
242
243             // GlobalENB-ID
244             // PLMN-Identity
245             pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.pLMN_Identity.size =
246             pRICEventTriggerDefinition->interfaceID.globalENBID.pLMNIdentity.contentLength;
247             pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.pLMN_Identity.buf = calloc(1,3);
248             if (pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.pLMN_Identity.buf) {
249                 memcpy(pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.pLMN_Identity.buf,
250                        pRICEventTriggerDefinition->interfaceID.globalENBID.pLMNIdentity.pLMNIdentityVal,
251                        pRICEventTriggerDefinition->interfaceID.globalENBID.pLMNIdentity.contentLength);
252             }
253             else
254                 return e2err_RICIndicationAllocRICEventTriggerDefinitionglobal_eNB_IDpLMN_IdentityBufFail;
255
256             // Add ENB-ID
257             if (pRICEventTriggerDefinition->interfaceID.globalENBID.nodeID.bits == cMacroENBIDP_20Bits){
258                 // BIT STRING (SIZE (20)
259                 pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.present = ENB_ID_PR_macro_eNB_ID;
260                 pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.choice.macro_eNB_ID.buf = calloc(1,3);
261                 if (pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.choice.macro_eNB_ID.buf) {
262                     pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.choice.macro_eNB_ID.size = 3; // bytes
263                     pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.choice.macro_eNB_ID.bits_unused = 4; // trailing unused bits
264                     memcpy(pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.choice.macro_eNB_ID.buf,
265                            (void*)&pRICEventTriggerDefinition->interfaceID.globalENBID.nodeID.nodeID,3);
266                 }
267                 else
268                     return e2err_RICIndicationAllocRICEventTriggerDefinitionglobal_eNB_IDeNB_IDmacro_eNB_IDBufFail;
269             }
270             else if (pRICEventTriggerDefinition->interfaceID.globalENBID.nodeID.bits == cHomeENBID_28Bits) {
271                 // BIT STRING (SIZE (28)
272                 pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.present = ENB_ID_PR_home_eNB_ID;
273                 pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.choice.home_eNB_ID.buf = calloc(1,4);
274                 if (pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.choice.home_eNB_ID.buf) {
275                     pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.choice.home_eNB_ID.size = 4; // bytes
276                     pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.choice.home_eNB_ID.bits_unused = 4; // trailing unused bits
277                     memcpy(pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.choice.home_eNB_ID.buf,
278                            (void*)&pRICEventTriggerDefinition->interfaceID.globalENBID.nodeID.nodeID,4);
279                 }
280                 else
281                     return e2err_RICIndicationAllocRICEventTriggerDefinitionglobal_eNB_IDeNB_IDhome_eNB_IDBufFail;
282             }
283             else if (pRICEventTriggerDefinition->interfaceID.globalENBID.nodeID.bits == cShortMacroENBID_18Bits) {
284                 // BIT STRING (SIZE(18)
285                 pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.present = ENB_ID_PR_short_Macro_eNB_ID;
286                 pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.choice.short_Macro_eNB_ID.buf = calloc(1,3);
287                 if (pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.choice.short_Macro_eNB_ID.buf) {
288                     pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.choice.short_Macro_eNB_ID.size = 3;
289                     pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.choice.short_Macro_eNB_ID.bits_unused = 6; // trailing unused bits
290                     memcpy(pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.choice.short_Macro_eNB_ID.buf,
291                            (void*)&pRICEventTriggerDefinition->interfaceID.globalENBID.nodeID.nodeID,3);
292                 }
293                 else
294                     return e2err_RICIndicationAllocRICEventTriggerDefinitionglobal_eNB_IDeNB_IDshort_Macro_eNB_IDBufFail;
295             }
296             else if (pRICEventTriggerDefinition->interfaceID.globalENBID.nodeID.bits == clongMacroENBIDP_21Bits) {
297                 // BIT STRING (SIZE(21)
298                 pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.present = ENB_ID_PR_long_Macro_eNB_ID;
299                 pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.choice.long_Macro_eNB_ID.buf = calloc(1,3);
300                 if (pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.choice.long_Macro_eNB_ID.buf) {
301                     pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.choice.long_Macro_eNB_ID.size = 3; // bytes
302                     pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.choice.long_Macro_eNB_ID.bits_unused = 3; // trailing unused bits
303                     memcpy(pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.choice.long_Macro_eNB_ID.buf,
304                            (void*)&pRICEventTriggerDefinition->interfaceID.globalENBID.nodeID.nodeID,3);
305                 }
306                 else
307                     return e2err_RICIndicationAllocRICEventTriggerDefinitionglobal_eNB_IDeNB_IDlong_Macro_eNB_IDBufFail;
308             }
309             else
310                 return e2err_RICEventTriggerDefinitionIEValueFail_2;
311
312         }
313         else if (pRICEventTriggerDefinition->interfaceID.globalGNBIDPresent) {
314             // GlobalGNB-ID
315             pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.present = Interface_ID_PR_global_gNB_ID;
316
317             // PLMN-Identity
318             pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_gNB_ID.pLMN_Identity.size =
319               pRICEventTriggerDefinition->interfaceID.globalGNBID.pLMNIdentity.contentLength;
320             pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_gNB_ID.pLMN_Identity.buf =
321               calloc(1,pRICEventTriggerDefinition->interfaceID.globalGNBID.pLMNIdentity.contentLength);
322             if (pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_gNB_ID.pLMN_Identity.buf) {
323                 memcpy(pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_gNB_ID.pLMN_Identity.buf,
324                        (void*)&pRICEventTriggerDefinition->interfaceID.globalGNBID.pLMNIdentity.pLMNIdentityVal,
325                         pRICEventTriggerDefinition->interfaceID.globalGNBID.pLMNIdentity.contentLength);
326             }
327             else
328                 return e2err_RICIndicationAllocRICEventTriggerDefinitionglobal_gNB_IDpLMN_IdentityBufFail;
329
330             // GNB-ID, BIT STRING (SIZE (22..32)
331             pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_gNB_ID.gNB_ID.choice.gNB_ID.size = 4;  //32bits
332             pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_gNB_ID.gNB_ID.choice.gNB_ID.buf = calloc(1, 4);
333             if (pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_gNB_ID.gNB_ID.choice.gNB_ID.buf) {
334                 memcpy(pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_gNB_ID.gNB_ID.choice.gNB_ID.buf,
335                        (void*)&pRICEventTriggerDefinition->interfaceID.globalGNBID,4); //32bits
336             }
337             else
338                 return e2err_RICIndicationAllocRICEventTriggerDefinitionglobal_gNB_IDgNB_IDBufFail;
339         }
340         else
341             return e2err_RICEventTriggerDefinitionIEValueFail_3;
342
343         // InterfaceDirection
344         pE2SM_gNB_X2_eventTriggerDefinition->interfaceDirection = pRICEventTriggerDefinition->interfaceDirection;
345
346         // InterfaceMessageType
347         // ProcedureCode
348         pE2SM_gNB_X2_eventTriggerDefinition->interfaceMessageType.procedureCode = pRICEventTriggerDefinition->interfaceMessageType.procedureCode;
349
350         // TypeOfMessage
351         if(pRICEventTriggerDefinition->interfaceMessageType.typeOfMessage == cE2InitiatingMessage)
352             pE2SM_gNB_X2_eventTriggerDefinition->interfaceMessageType.typeOfMessage = TypeOfMessage_initiating_message;
353         else if(pRICEventTriggerDefinition->interfaceMessageType.typeOfMessage == cE2SuccessfulOutcome)
354             pE2SM_gNB_X2_eventTriggerDefinition->interfaceMessageType.typeOfMessage = TypeOfMessage_successful_outcome;
355         else if(pRICEventTriggerDefinition->interfaceMessageType.typeOfMessage == cE2UnsuccessfulOutcome)
356             pE2SM_gNB_X2_eventTriggerDefinition->interfaceMessageType.typeOfMessage = TypeOfMessage_unsuccessful_outcome;
357         else
358             return e2err_RICEventTriggerDefinitionIEValueFail_4;
359
360         // InterfaceProtocolIE-List, OPTIONAL
361
362         // Debug print
363         if (debug)
364             asn_fprint(stdout, &asn_DEF_E2SM_gNB_X2_eventTriggerDefinition, pE2SM_gNB_X2_eventTriggerDefinition);
365
366         // Encode
367         size_t bufferSize = sizeof(pRICEventTriggerDefinition->octetString.data);
368         asn_enc_rval_t rval;
369         rval = asn_encode_to_buffer(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_X2_eventTriggerDefinition, pE2SM_gNB_X2_eventTriggerDefinition,
370                                     pRICEventTriggerDefinition->octetString.data, bufferSize);
371         if(rval.encoded == -1)
372         {
373             sprintf(pLogBuffer,"\nSerialization of %s failed.\n", asn_DEF_E2SM_gNB_X2_eventTriggerDefinition.name);
374             return e2err_RICEventTriggerDefinitionPackFail_1;
375         }
376         else if(rval.encoded > bufferSize)
377         {
378            sprintf(pLogBuffer,"\nBuffer of size %zu is too small for %s, need %zu\n",bufferSize, asn_DEF_E2SM_gNB_X2_eventTriggerDefinition.name, rval.encoded);
379             return e2err_RICEventTriggerDefinitionPackFail_2;
380         }
381         else
382         if (debug)
383                sprintf(pLogBuffer,"\nSuccessfully encoded %s. Buffer size %zu, encoded size %zu\n\n",asn_DEF_E2SM_gNB_X2_eventTriggerDefinition.name, bufferSize, rval.encoded);
384
385         ASN_STRUCT_FREE(asn_DEF_E2SM_gNB_X2_eventTriggerDefinition, pE2SM_gNB_X2_eventTriggerDefinition);
386
387         pRICEventTriggerDefinition->octetString.contentLength = rval.encoded;
388         return e2err_OK;
389     }
390     return e2err_RICEventTriggerDefinitionAllocE2SM_gNB_X2_eventTriggerDefinitionFail;
391 }
392
393 //////////////////////////////////////////////////////////////////////
394 uint64_t packRICSubscriptionResponse(size_t* pDataBufferSize, byte* pDataBuffer, char* pLogBuffer, RICSubscriptionResponse_t* pRICSubscriptionResponse) {
395
396     E2AP_PDU_t* pE2AP_PDU = calloc(1, sizeof(E2AP_PDU_t));
397     if(pE2AP_PDU)
398         {
399         pE2AP_PDU->present = E2AP_PDU_PR_successfulOutcome;
400         pE2AP_PDU->choice.initiatingMessage.procedureCode = ProcedureCode_id_ricSubscription;
401         pE2AP_PDU->choice.initiatingMessage.criticality = Criticality_ignore;
402         pE2AP_PDU->choice.initiatingMessage.value.present = RICSuccessfulOutcome__value_PR_RICsubscriptionResponse;
403
404         // RICrequestID
405         RICsubscriptionResponse_IEs_t* pRICsubscriptionResponse_IEs = calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
406         if (pRICsubscriptionResponse_IEs) {
407             pRICsubscriptionResponse_IEs->id = ProtocolIE_ID_id_RICrequestID;
408             pRICsubscriptionResponse_IEs->criticality = Criticality_reject;
409             pRICsubscriptionResponse_IEs->value.present = RICsubscriptionResponse_IEs__value_PR_RICrequestID;
410             pRICsubscriptionResponse_IEs->value.choice.RICrequestID.ricRequestorID = pRICSubscriptionResponse->ricRequestID.ricRequestorID;
411             pRICsubscriptionResponse_IEs->value.choice.RICrequestID.ricRequestSequenceNumber = pRICSubscriptionResponse->ricRequestID.ricRequestSequenceNumber;
412             ASN_SEQUENCE_ADD(&pE2AP_PDU->choice.successfulOutcome.value.choice.RICsubscriptionResponse.protocolIEs.list, pRICsubscriptionResponse_IEs);
413         }
414         else
415             return e2err_RICSubscriptionResponseAllocRICrequestIDFail;
416
417         // RANfunctionID
418         pRICsubscriptionResponse_IEs = calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
419         if (pRICsubscriptionResponse_IEs) {
420             pRICsubscriptionResponse_IEs->id = ProtocolIE_ID_id_RANfunctionID;
421             pRICsubscriptionResponse_IEs->criticality = Criticality_reject;
422             pRICsubscriptionResponse_IEs->value.present = RICsubscriptionResponse_IEs__value_PR_RANfunctionID;
423             pRICsubscriptionResponse_IEs->value.choice.RANfunctionID = pRICSubscriptionResponse->ranFunctionID;
424             ASN_SEQUENCE_ADD(&pE2AP_PDU->choice.successfulOutcome.value.choice.RICsubscriptionResponse.protocolIEs.list, pRICsubscriptionResponse_IEs);
425         }
426         else
427             return e2err_RICSubscriptionResponseAllocRANfunctionIDFail;
428
429         // RICaction-Admitted list
430         pRICsubscriptionResponse_IEs = calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
431         if (pRICsubscriptionResponse_IEs) {
432             pRICsubscriptionResponse_IEs->id = ProtocolIE_ID_id_RICactions_Admitted;
433             pRICsubscriptionResponse_IEs->criticality = Criticality_reject;
434             pRICsubscriptionResponse_IEs->value.present = RICsubscriptionResponse_IEs__value_PR_RICaction_Admitted_List;
435
436             uint64_t index = 0;
437             while (index < pRICSubscriptionResponse->ricActionAdmittedList.contentLength && index < maxofRICactionID) {
438
439                 RICaction_Admitted_ItemIEs_t* pRICaction_Admitted_ItemIEs = calloc(1, sizeof (RICaction_Admitted_ItemIEs_t));
440                 if (pRICaction_Admitted_ItemIEs)
441                 {
442                     pRICaction_Admitted_ItemIEs->id = ProtocolIE_ID_id_RICaction_Admitted_Item;
443                     pRICaction_Admitted_ItemIEs->criticality = Criticality_reject;
444                     pRICaction_Admitted_ItemIEs->value.present = RICaction_Admitted_ItemIEs__value_PR_RICaction_Admitted_Item;
445
446                     // RICActionID
447                     pRICaction_Admitted_ItemIEs->value.choice.RICaction_Admitted_Item.ricActionID = pRICSubscriptionResponse->ricActionAdmittedList.ricActionID[index];
448                     ASN_SEQUENCE_ADD(&pRICsubscriptionResponse_IEs->value.choice.RICaction_Admitted_List.list, pRICaction_Admitted_ItemIEs);
449                 }
450                 else
451                     return e2err_RICSubscriptionResponseAllocRICaction_Admitted_ItemIEsFail;
452                 index++;
453             }
454         }
455         else
456             return e2err_RICSubscriptionResponseAllocRICActionAdmittedListFail;
457
458         ASN_SEQUENCE_ADD(&pE2AP_PDU->choice.successfulOutcome.value.choice.RICsubscriptionResponse.protocolIEs.list, pRICsubscriptionResponse_IEs);
459
460         // RICaction-NotAdmitted list
461         if (pRICSubscriptionResponse->ricActionNotAdmittedListPresent) {
462             pRICsubscriptionResponse_IEs = calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
463             if (pRICsubscriptionResponse_IEs) {
464                 pRICsubscriptionResponse_IEs->id = ProtocolIE_ID_id_RICactions_NotAdmitted;
465                 pRICsubscriptionResponse_IEs->criticality = Criticality_reject;
466                 pRICsubscriptionResponse_IEs->value.present = RICsubscriptionResponse_IEs__value_PR_RICaction_NotAdmitted_List;
467
468                 uint64_t index = 0;
469                 while (index < pRICSubscriptionResponse->ricActionNotAdmittedList.contentLength && index < maxofRICactionID) {
470
471                     RICaction_NotAdmitted_ItemIEs_t* pRICaction_NotAdmitted_ItemIEs = calloc(1, sizeof (RICaction_NotAdmitted_ItemIEs_t));
472                     if (pRICaction_NotAdmitted_ItemIEs)
473                     {
474                         pRICaction_NotAdmitted_ItemIEs->id = ProtocolIE_ID_id_RICaction_NotAdmitted_Item;
475                         pRICaction_NotAdmitted_ItemIEs->criticality = Criticality_reject;
476                         pRICaction_NotAdmitted_ItemIEs->value.present = RICaction_NotAdmitted_ItemIEs__value_PR_RICaction_NotAdmitted_Item;
477
478                         // RICActionID
479                         pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricActionID =
480                           pRICSubscriptionResponse->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricActionID;
481
482                         // RICCause
483                         if (pRICSubscriptionResponse->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.content == RICcause_PR_radioNetwork) {
484                             pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.present = RICcause_PR_radioNetwork;
485                             pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.radioNetwork =
486                               pRICSubscriptionResponse->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.cause;
487                         }
488                         else if (pRICSubscriptionResponse->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.content == RICcause_PR_transport) {
489                             pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.present = RICcause_PR_transport;
490                             pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.transport =
491                               pRICSubscriptionResponse->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.cause;
492                         }
493                         else if (pRICSubscriptionResponse->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.content == RICcause_PR_protocol) {
494                             pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.present = RICcause_PR_protocol;
495                             pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.protocol =
496                               pRICSubscriptionResponse->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.cause;
497                         }
498                         else if (pRICSubscriptionResponse->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.content == RICcause_PR_misc) {
499                             pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.present = RICcause_PR_misc;
500                             pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.misc =
501                               pRICSubscriptionResponse->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.cause;
502                         }
503                         else if (pRICSubscriptionResponse->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.content == RICcause_PR_ric) {
504                             pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.present = RICcause_PR_ric;
505                             pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.ric =
506                               pRICSubscriptionResponse->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.cause;
507                         }
508                         ASN_SEQUENCE_ADD(&pRICsubscriptionResponse_IEs->value.choice.RICaction_NotAdmitted_List.list, pRICaction_NotAdmitted_ItemIEs);
509                     }
510                     else
511                         return e2err_RICSubscriptionResponseAllocRICaction_NotAdmitted_ItemIEsFail;
512                     index++;
513                 }
514             }
515             ASN_SEQUENCE_ADD(&pE2AP_PDU->choice.successfulOutcome.value.choice.RICsubscriptionResponse.protocolIEs.list, pRICsubscriptionResponse_IEs);
516         }
517         else
518             return e2err_RICSubscriptionResponseAllocRICActionNotAdmittedListFail;
519
520         if (E2encode(pE2AP_PDU, pDataBufferSize, pDataBuffer, pLogBuffer))
521             return e2err_OK;
522         else
523             return e2err_RICSubscriptionResponseEncodeFail;
524     }
525     return e2err_RICSubscriptionResponseAllocE2AP_PDUFail;
526 }
527
528 //////////////////////////////////////////////////////////////////////
529 uint64_t packRICSubscriptionFailure(size_t* pDataBufferSize, byte* pDataBuffer, char* pLogBuffer, RICSubscriptionFailure_t* pRICSubscriptionFailure) {
530
531     E2AP_PDU_t* pE2AP_PDU = calloc(1, sizeof(E2AP_PDU_t));
532     if(pE2AP_PDU)
533         {
534         pE2AP_PDU->present = E2AP_PDU_PR_unsuccessfulOutcome;
535         pE2AP_PDU->choice.unsuccessfulOutcome.procedureCode = ProcedureCode_id_ricSubscription;
536         pE2AP_PDU->choice.unsuccessfulOutcome.criticality = Criticality_ignore;
537         pE2AP_PDU->choice.unsuccessfulOutcome.value.present = RICUnsuccessfulOutcome__value_PR_RICsubscriptionFailure;
538
539         // RICrequestID
540         RICsubscriptionFailure_IEs_t* pRICsubscriptionFailure_IEs = calloc(1, sizeof(RICsubscriptionFailure_IEs_t));
541         if (pRICsubscriptionFailure_IEs) {
542             pRICsubscriptionFailure_IEs->id = ProtocolIE_ID_id_RICrequestID;
543             pRICsubscriptionFailure_IEs->criticality = Criticality_reject;
544             pRICsubscriptionFailure_IEs->value.present = RICsubscriptionFailure_IEs__value_PR_RICrequestID;
545             pRICsubscriptionFailure_IEs->value.choice.RICrequestID.ricRequestorID = pRICSubscriptionFailure->ricRequestID.ricRequestorID;
546             pRICsubscriptionFailure_IEs->value.choice.RICrequestID.ricRequestSequenceNumber = pRICSubscriptionFailure->ricRequestID.ricRequestSequenceNumber;
547             ASN_SEQUENCE_ADD(&pE2AP_PDU->choice.unsuccessfulOutcome.value.choice.RICsubscriptionFailure.protocolIEs.list, pRICsubscriptionFailure_IEs);
548         }
549         else
550             return e2err_RICSubscriptionFailureAllocRICrequestIDFail;
551
552         // RANfunctionID
553         pRICsubscriptionFailure_IEs = calloc(1, sizeof(RICsubscriptionFailure_IEs_t));
554         if (pRICsubscriptionFailure_IEs) {
555             pRICsubscriptionFailure_IEs->id = ProtocolIE_ID_id_RANfunctionID;
556             pRICsubscriptionFailure_IEs->criticality = Criticality_reject;
557             pRICsubscriptionFailure_IEs->value.present = RICsubscriptionFailure_IEs__value_PR_RANfunctionID;
558             pRICsubscriptionFailure_IEs->value.choice.RANfunctionID = pRICSubscriptionFailure->ranFunctionID;
559             ASN_SEQUENCE_ADD(&pE2AP_PDU->choice.unsuccessfulOutcome.value.choice.RICsubscriptionFailure.protocolIEs.list, pRICsubscriptionFailure_IEs);
560         }
561         else
562             return e2err_RICSubscriptionFailureAllocRANfunctionIDFail;
563
564         // RICaction-NotAdmitted list
565         pRICsubscriptionFailure_IEs = calloc(1, sizeof(RICsubscriptionFailure_IEs_t));
566         if (pRICsubscriptionFailure_IEs) {
567             pRICsubscriptionFailure_IEs->id = ProtocolIE_ID_id_RICactions_NotAdmitted;
568             pRICsubscriptionFailure_IEs->criticality = Criticality_reject;
569             pRICsubscriptionFailure_IEs->value.present = RICsubscriptionFailure_IEs__value_PR_RICaction_NotAdmitted_List;
570
571             uint64_t index = 0;
572             while (index < pRICSubscriptionFailure->ricActionNotAdmittedList.contentLength && index < maxofRICactionID) {
573
574                 RICaction_NotAdmitted_ItemIEs_t* pRICaction_NotAdmitted_ItemIEs = calloc(1, sizeof (RICaction_NotAdmitted_ItemIEs_t));
575                 if (pRICaction_NotAdmitted_ItemIEs)
576                 {
577                     pRICaction_NotAdmitted_ItemIEs->id = ProtocolIE_ID_id_RICaction_NotAdmitted_Item;
578                     pRICaction_NotAdmitted_ItemIEs->criticality = Criticality_reject;
579                     pRICaction_NotAdmitted_ItemIEs->value.present = RICaction_NotAdmitted_ItemIEs__value_PR_RICaction_NotAdmitted_Item;
580
581                     // RICActionID
582                     pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricActionID =
583                       pRICSubscriptionFailure->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricActionID;
584
585                     // RICCause
586                     if (pRICSubscriptionFailure->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.content == RICcause_PR_radioNetwork) {
587                         pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.present = RICcause_PR_radioNetwork;
588                         pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.radioNetwork =
589                           pRICSubscriptionFailure->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.cause;
590                     }
591                     else if (pRICSubscriptionFailure->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.content == RICcause_PR_transport) {
592                         pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.present = RICcause_PR_transport;
593                         pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.transport =
594                           pRICSubscriptionFailure->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.cause;
595                     }
596                     else if (pRICSubscriptionFailure->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.content == RICcause_PR_protocol) {
597                         pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.present = RICcause_PR_protocol;
598                         pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.protocol =
599                           pRICSubscriptionFailure->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.cause;
600                     }
601                     else if (pRICSubscriptionFailure->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.content == RICcause_PR_misc) {
602                         pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.present = RICcause_PR_misc;
603                         pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.misc =
604                           pRICSubscriptionFailure->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.cause;
605                     }
606                     else if (pRICSubscriptionFailure->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.content == RICcause_PR_ric) {
607                         pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.present = RICcause_PR_ric;
608                         pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.ric =
609                           pRICSubscriptionFailure->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.cause;
610                     }
611                     ASN_SEQUENCE_ADD(&pRICsubscriptionFailure_IEs->value.choice.RICaction_NotAdmitted_List.list, pRICaction_NotAdmitted_ItemIEs);
612                 }
613                 else
614                     return e2err_RICSubscriptionFailureAllocRICaction_NotAdmitted_ItemIEsFail;
615                 index++;
616             }
617             ASN_SEQUENCE_ADD(&pE2AP_PDU->choice.unsuccessfulOutcome.value.choice.RICsubscriptionFailure.protocolIEs.list, pRICsubscriptionFailure_IEs);
618         }
619         else
620             return e2err_RICSubscriptionFailureAllocRICActionAdmittedListFail;
621
622         // CriticalityDiagnostics, OPTIONAL. Not used in RIC
623
624         if (E2encode(pE2AP_PDU, pDataBufferSize, pDataBuffer, pLogBuffer))
625             return e2err_OK;
626         else
627             return e2err_RICSubscriptionFailureEncodeFail;
628     }
629     else
630         return e2err_RICSubscriptionFailureAllocE2AP_PDUFail;
631 }
632
633 //////////////////////////////////////////////////////////////////////
634 uint64_t packRICIndication(size_t* pDataBufferSize, byte* pDataBuffer, char* pLogBuffer, RICIndication_t* pRICIndication) {
635
636     E2AP_PDU_t* pE2AP_PDU = calloc(1, sizeof(E2AP_PDU_t));
637     if(pE2AP_PDU)
638         {
639         pE2AP_PDU->present = E2AP_PDU_PR_initiatingMessage;
640         pE2AP_PDU->choice.initiatingMessage.procedureCode = ProcedureCode_id_ricIndication;
641         pE2AP_PDU->choice.initiatingMessage.criticality = Criticality_ignore;
642         pE2AP_PDU->choice.initiatingMessage.value.present = RICInitiatingMessage__value_PR_RICindication;
643
644         // RICrequestID
645         RICindication_IEs_t* pRICindication_IEs = calloc(1, sizeof(RICindication_IEs_t));
646         if (pRICindication_IEs) {
647             pRICindication_IEs->id = ProtocolIE_ID_id_RICrequestID;
648             pRICindication_IEs->criticality = Criticality_reject;
649             pRICindication_IEs->value.present = RICindication_IEs__value_PR_RICrequestID;
650             pRICindication_IEs->value.choice.RICrequestID.ricRequestorID = pRICIndication->ricRequestID.ricRequestorID;
651             pRICindication_IEs->value.choice.RICrequestID.ricRequestSequenceNumber = pRICIndication->ricRequestID.ricRequestSequenceNumber;
652             ASN_SEQUENCE_ADD(&pE2AP_PDU->choice.initiatingMessage.value.choice.RICindication.protocolIEs.list, pRICindication_IEs);
653         }
654         else
655             return e2err_RICIndicationRICrequestIDFail;
656
657         // RANfunctionID
658         pRICindication_IEs = calloc(1, sizeof(RICindication_IEs_t));
659         if (pRICindication_IEs) {
660             pRICindication_IEs->id = ProtocolIE_ID_id_RANfunctionID;
661             pRICindication_IEs->criticality = Criticality_reject;
662             pRICindication_IEs->value.present = RICindication_IEs__value_PR_RANfunctionID;
663             pRICindication_IEs->value.choice.RANfunctionID = pRICIndication->ranFunctionID;
664             ASN_SEQUENCE_ADD(&pE2AP_PDU->choice.initiatingMessage.value.choice.RICindication.protocolIEs.list, pRICindication_IEs);
665         }
666         else
667             return e2err_RICIndicationAllocRANfunctionIDFail;
668
669         // RICactionID
670         pRICindication_IEs = calloc(1, sizeof(RICindication_IEs_t));
671         if (pRICindication_IEs) {
672             pRICindication_IEs->id = ProtocolIE_ID_id_RICactionID;
673             pRICindication_IEs->criticality = Criticality_reject;
674             pRICindication_IEs->value.present = RICindication_IEs__value_PR_RICactionID;
675             pRICindication_IEs->value.choice.RICactionID = pRICIndication->ricActionID;
676             ASN_SEQUENCE_ADD(&pE2AP_PDU->choice.initiatingMessage.value.choice.RICindication.protocolIEs.list, pRICindication_IEs);
677         }
678         else
679             return e2err_RICIndicationAllocRICactionIDFail;
680
681         // RICindicationSN
682         pRICindication_IEs = calloc(1, sizeof(RICindication_IEs_t));
683         if (pRICindication_IEs) {
684             pRICindication_IEs->id = ProtocolIE_ID_id_RICindicationSN;
685             pRICindication_IEs->criticality = Criticality_reject;
686             pRICindication_IEs->value.present = RICindication_IEs__value_PR_RICindicationSN;
687             pRICindication_IEs->value.choice.RICindicationSN = pRICIndication->ricIndicationSN;
688             ASN_SEQUENCE_ADD(&pE2AP_PDU->choice.initiatingMessage.value.choice.RICindication.protocolIEs.list, pRICindication_IEs);
689         }
690         else
691             return e2err_RICIndicationAllocRICindicationSNFail;
692
693         // RICindicationType
694         pRICindication_IEs = calloc(1, sizeof(RICindication_IEs_t));
695         if (pRICindication_IEs) {
696             pRICindication_IEs->id = ProtocolIE_ID_id_RICindicationType;
697             pRICindication_IEs->criticality = Criticality_reject;
698             pRICindication_IEs->value.present = RICindication_IEs__value_PR_RICindicationType;
699             pRICindication_IEs->value.choice.RICindicationType = pRICIndication->ricIndicationType;
700             ASN_SEQUENCE_ADD(&pE2AP_PDU->choice.initiatingMessage.value.choice.RICindication.protocolIEs.list, pRICindication_IEs);
701         }
702         else
703             return e2err_RICIndicationAllocRICindicationTypeFail;
704
705         // RICindicationHeader
706         uint64_t returnCode;
707         uint64_t logBufferSize = 512;
708         char logBuffer[logBufferSize];
709         if ((returnCode = packRICIndicationHeader(logBuffer, &pRICIndication->ricIndicationHeader)) != e2err_OK) {
710             return returnCode;
711         }
712
713         pRICindication_IEs = calloc(1, sizeof(RICindication_IEs_t));
714         if (pRICindication_IEs) {
715             pRICindication_IEs->id = ProtocolIE_ID_id_RICindicationHeader;
716             pRICindication_IEs->criticality = Criticality_reject;
717             pRICindication_IEs->value.present = RICindication_IEs__value_PR_RICindicationHeader;
718             pRICindication_IEs->value.choice.RICindicationHeader.buf = calloc(1,pRICIndication->ricIndicationHeader.octetString.contentLength);
719             if (pRICindication_IEs->value.choice.RICindicationHeader.buf) {
720                 pRICindication_IEs->value.choice.RICindicationHeader.size = pRICIndication->ricIndicationHeader.octetString.contentLength;
721                 memcpy(pRICindication_IEs->value.choice.RICindicationHeader.buf,pRICIndication->ricIndicationHeader.octetString.data,
722                     pRICIndication->ricIndicationHeader.octetString.contentLength);
723                 ASN_SEQUENCE_ADD(&pE2AP_PDU->choice.initiatingMessage.value.choice.RICindication.protocolIEs.list, pRICindication_IEs);
724             }
725             else
726                 return e2err_RICIndicationAllocRRICindicationHeaderBufFail;
727         }
728         else
729             return e2err_RICIndicationAllocRICindicationHeaderFail;
730
731         // RICindicationMessage
732         if ((returnCode = packRICIndicationMessage(logBuffer, &pRICIndication->ricIndicationMessage)) != e2err_OK) {
733             return returnCode;
734         }
735
736         pRICindication_IEs = calloc(1, sizeof(RICindication_IEs_t));
737         if (pRICindication_IEs) {
738             pRICindication_IEs->id = ProtocolIE_ID_id_RICindicationMessage;
739             pRICindication_IEs->criticality = Criticality_reject;
740             pRICindication_IEs->value.present = RICindication_IEs__value_PR_RICindicationMessage;
741             pRICindication_IEs->value.choice.RICindicationMessage.buf = calloc(1,pRICIndication->ricIndicationMessage.octetString.contentLength);
742             if (pRICindication_IEs->value.choice.RICindicationMessage.buf) {
743                 pRICindication_IEs->value.choice.RICindicationMessage.size = pRICIndication->ricIndicationMessage.octetString.contentLength;
744                 memcpy(pRICindication_IEs->value.choice.RICindicationHeader.buf,pRICIndication->ricIndicationMessage.octetString.data,
745                        pRICIndication->ricIndicationMessage.octetString.contentLength);
746                 ASN_SEQUENCE_ADD(&pE2AP_PDU->choice.initiatingMessage.value.choice.RICindication.protocolIEs.list, pRICindication_IEs);
747             }
748             else
749                 return e2err_RICIndicationAllocRICindicationMessageBufFail;
750         }
751         else
752             return e2err_RICIndicationAllocRICindicationMessageFail;
753
754         // RICcallProcessID, OPTIONAL. Not used in RIC.
755
756         if (E2encode(pE2AP_PDU, pDataBufferSize, pDataBuffer, pLogBuffer))
757             return e2err_OK;
758         else
759             return e2err_RICIndicationEncodeFail;
760     }
761     else
762         return e2err_RICIndicationAllocE2AP_PDUFail;
763 }
764
765 //////////////////////////////////////////////////////////////////////
766 uint64_t packRICIndicationHeader(char* pLogBuffer, RICIndicationHeader_t* pRICIndicationHeader) {
767
768     E2SM_gNB_X2_indicationHeader_t* pE2SM_gNB_X2_indicationHeader = calloc(1, sizeof(E2SM_gNB_X2_indicationHeader_t));
769     if(pE2SM_gNB_X2_indicationHeader)
770         {
771         // InterfaceID
772         if ((pRICIndicationHeader->interfaceID.globalENBIDPresent == true && pRICIndicationHeader->interfaceID.globalGNBIDPresent == true) ||
773             (pRICIndicationHeader->interfaceID.globalENBIDPresent == false && pRICIndicationHeader->interfaceID.globalGNBIDPresent == false))
774             return e2err_RICindicationHeaderIEValueFail_1;
775
776         // GlobalENB-ID or GlobalGNB-ID
777         if (pRICIndicationHeader->interfaceID.globalENBIDPresent)
778         {
779             pE2SM_gNB_X2_indicationHeader->interface_ID.present = Interface_ID_PR_global_eNB_ID;
780
781             // GlobalENB-ID
782             // PLMN-Identity
783             pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.pLMN_Identity.size =
784             pRICIndicationHeader->interfaceID.globalENBID.pLMNIdentity.contentLength;
785             pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.pLMN_Identity.buf = calloc(1,3);
786             if (pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.pLMN_Identity.buf) {
787                 memcpy(pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.pLMN_Identity.buf,
788                        pRICIndicationHeader->interfaceID.globalENBID.pLMNIdentity.pLMNIdentityVal,
789                        pRICIndicationHeader->interfaceID.globalENBID.pLMNIdentity.contentLength);
790             }
791             else
792                 return e2err_RICIndicationAllocRICIndicationHeaderglobal_eNB_IDpLMN_IdentityBufFail;
793
794             // Add ENB-ID
795             if (pRICIndicationHeader->interfaceID.globalENBID.nodeID.bits == cMacroENBIDP_20Bits){
796                 // BIT STRING (SIZE (20)
797                 pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.present = ENB_ID_PR_macro_eNB_ID;
798
799                 pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.choice.macro_eNB_ID.buf = calloc(1,3);
800                 if (pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.choice.macro_eNB_ID.buf) {
801                     pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.choice.macro_eNB_ID.size = 3; // bytes
802                     pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.choice.macro_eNB_ID.bits_unused = 4; // trailing unused bits
803                     memcpy(pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.choice.macro_eNB_ID.buf,
804                            (void*)&pRICIndicationHeader->interfaceID.globalENBID.nodeID.nodeID,3);
805                 }
806                 else
807                     return e2err_RICIndicationAllocRICIndicationHeaderglobal_eNB_IDeNB_IDmacro_eNB_IDBufFail;
808             }
809             else if (pRICIndicationHeader->interfaceID.globalENBID.nodeID.bits == cHomeENBID_28Bits) {
810                 // BIT STRING (SIZE (28)
811                 pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.present = ENB_ID_PR_home_eNB_ID;
812
813                 pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.choice.home_eNB_ID.buf = calloc(1,4);
814                 if (pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.choice.home_eNB_ID.buf) {
815                     pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.choice.home_eNB_ID.size = 4; // bytes
816                     pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.choice.home_eNB_ID.bits_unused = 4; // trailing unused bits
817                     memcpy(pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.choice.home_eNB_ID.buf,
818                            (void*)&pRICIndicationHeader->interfaceID.globalENBID.nodeID.nodeID,4);
819                 }
820                 else
821                     return e2err_RICIndicationAllocRICIndicationHeaderglobal_eNB_IDeNB_IDhome_eNB_IDBufFail;
822             }
823             else if (pRICIndicationHeader->interfaceID.globalENBID.nodeID.bits == cShortMacroENBID_18Bits) {
824                 // BIT STRING (SIZE(18)
825                 pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.present = ENB_ID_PR_short_Macro_eNB_ID;
826
827                 pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.choice.short_Macro_eNB_ID.buf = calloc(1,3);
828                 if (pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.choice.short_Macro_eNB_ID.buf) {
829                     pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.choice.short_Macro_eNB_ID.size = 3;
830                     pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.choice.short_Macro_eNB_ID.bits_unused = 6; // trailing unused bits
831                      memcpy(pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.choice.short_Macro_eNB_ID.buf,
832                             (void*)&pRICIndicationHeader->interfaceID.globalENBID.nodeID.nodeID,3);
833                 }
834                 else
835                     return e2err_RICIndicationAllocRICIndicationHeaderglobal_eNB_IDeNB_IDshort_Macro_eNB_IDBufFail;
836             }
837             else if (pRICIndicationHeader->interfaceID.globalENBID.nodeID.bits == clongMacroENBIDP_21Bits) {
838                 // BIT STRING (SIZE(21)
839                 pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.present = ENB_ID_PR_long_Macro_eNB_ID;
840
841                 pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.choice.long_Macro_eNB_ID.buf = calloc(1,3);
842                 if (pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.choice.long_Macro_eNB_ID.buf) {
843                     pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.choice.long_Macro_eNB_ID.size = 3; // bytes
844                     pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.choice.long_Macro_eNB_ID.bits_unused = 3; // trailing unused bits
845                     memcpy(pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.choice.long_Macro_eNB_ID.buf,
846                            (void*)&pRICIndicationHeader->interfaceID.globalENBID.nodeID.nodeID,3);
847                 }
848                 else
849                     return e2err_RICIndicationAllocRICIndicationHeaderglobal_eNB_IDeNB_IDlong_Macro_eNB_IDBufFail;
850             }
851             else
852                 return e2err_RICindicationHeaderIEValueFail_2;
853
854         }
855         else if (pRICIndicationHeader->interfaceID.globalGNBIDPresent) {
856             // GlobalGNB-ID
857             pE2SM_gNB_X2_indicationHeader->interface_ID.present = Interface_ID_PR_global_gNB_ID;
858
859             // PLMN-Identity
860             pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_gNB_ID.pLMN_Identity.size =
861               pRICIndicationHeader->interfaceID.globalGNBID.pLMNIdentity.contentLength;
862             pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_gNB_ID.pLMN_Identity.buf =
863               calloc(1,pRICIndicationHeader->interfaceID.globalGNBID.pLMNIdentity.contentLength);
864             if (pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_gNB_ID.pLMN_Identity.buf) {
865                 memcpy(pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_gNB_ID.pLMN_Identity.buf,
866                        (void*)&pRICIndicationHeader->interfaceID.globalGNBID.pLMNIdentity.pLMNIdentityVal,
867                        pRICIndicationHeader->interfaceID.globalGNBID.pLMNIdentity.contentLength);
868             }
869             else
870                 return e2err_RICIndicationAllocRICIndicationHeaderglobal_gNB_IDpLMN_IdentityBufFail;
871
872             // GNB-ID, BIT STRING (SIZE (22..32)
873             pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_gNB_ID.gNB_ID.choice.gNB_ID.size = 4;  //32bits
874             pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_gNB_ID.gNB_ID.choice.gNB_ID.buf = calloc(1,4);
875             if (pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_gNB_ID.gNB_ID.choice.gNB_ID.buf) {
876                 memcpy(pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_gNB_ID.gNB_ID.choice.gNB_ID.buf,
877                        (void*)&pRICIndicationHeader->interfaceID.globalGNBID,4); //32bits
878                 }
879                 else
880                     return e2err_RICIndicationAllocRICIndicationHeaderglobal_gNB_IDgNB_IDgNB_IDBufFail;
881         }
882         else
883             return e2err_RICindicationHeaderIEValueFail_3;
884
885         // InterfaceDirection
886         pE2SM_gNB_X2_indicationHeader->interfaceDirection = pRICIndicationHeader->interfaceDirection;
887
888         // TimeStamp OPTIONAL. Not used in RIC.
889
890         // Debug print
891         if (debug)
892             asn_fprint(stdout, &asn_DEF_E2SM_gNB_X2_indicationHeader, pE2SM_gNB_X2_indicationHeader);
893
894         // Encode
895         size_t bufferSize = sizeof(pRICIndicationHeader->octetString.data);
896         asn_enc_rval_t rval;
897         rval = asn_encode_to_buffer(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_X2_indicationHeader, pE2SM_gNB_X2_indicationHeader,
898                                     pRICIndicationHeader->octetString.data, bufferSize);
899         if(rval.encoded == -1)
900         {
901             sprintf(pLogBuffer,"\nSerialization of %s failed.\n", asn_DEF_E2SM_gNB_X2_indicationHeader.name);
902             return e2err_RICindicationHeaderPackFail_1;
903         }
904         else if(rval.encoded > bufferSize)
905         {
906             sprintf(pLogBuffer,"\nBuffer of size %zu is too small for %s, need %zu\n",bufferSize, asn_DEF_E2SM_gNB_X2_indicationHeader.name, rval.encoded);
907             return e2err_RICindicationHeaderPackFail_2;
908         }
909         else
910             if (debug)
911                 sprintf(pLogBuffer,"\nSuccessfully encoded %s. Buffer size %zu, encoded size %zu\n\n",asn_DEF_E2SM_gNB_X2_indicationHeader.name, bufferSize, rval.encoded);
912
913         ASN_STRUCT_FREE(asn_DEF_E2SM_gNB_X2_indicationHeader, pE2SM_gNB_X2_indicationHeader);
914
915         pRICIndicationHeader->octetString.contentLength = rval.encoded;
916         return e2err_OK;
917     }
918     else
919         return e2err_RICIndicationHeaderAllocE2AP_PDUFail;
920 }
921
922 //////////////////////////////////////////////////////////////////////
923 uint64_t packRICIndicationMessage(char* pLogBuffer, RICIndicationMessage_t* pRICIndicationMessage) {
924
925     E2SM_gNB_X2_indicationMessage_t* pE2SM_gNB_X2_indicationMessage = calloc(1, sizeof(E2SM_gNB_X2_indicationMessage_t));
926     if(pE2SM_gNB_X2_indicationMessage)
927     {
928         pE2SM_gNB_X2_indicationMessage->interfaceMessage.buf = calloc(1, pRICIndicationMessage->interfaceMessage.contentLength);
929         if(pE2SM_gNB_X2_indicationMessage->interfaceMessage.buf)
930         {
931             pE2SM_gNB_X2_indicationMessage->interfaceMessage.size = pRICIndicationMessage->interfaceMessage.contentLength;
932             memcpy(pE2SM_gNB_X2_indicationMessage->interfaceMessage.buf,pRICIndicationMessage->interfaceMessage.data,pRICIndicationMessage->interfaceMessage.contentLength);
933         }
934         else
935             return e2err_RICIndicationMessageAllocinterfaceMessageFail;
936
937         // Debug print
938         if (debug)
939             asn_fprint(stdout, &asn_DEF_E2SM_gNB_X2_indicationMessage, pE2SM_gNB_X2_indicationMessage);
940
941         // Encode
942         size_t bufferSize = sizeof(pRICIndicationMessage->octetString.data);
943         asn_enc_rval_t rval;
944         rval = asn_encode_to_buffer(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_X2_indicationMessage, pE2SM_gNB_X2_indicationMessage,
945                                     pRICIndicationMessage->octetString.data, bufferSize);
946         if(rval.encoded == -1)
947         {
948             sprintf(pLogBuffer,"\nSerialization of %s failed.\n", asn_DEF_E2SM_gNB_X2_indicationMessage.name);
949             return e2err_RICindicationMessagePackFail_1;
950         }
951         else if(rval.encoded > bufferSize)
952         {
953             sprintf(pLogBuffer,"\nBuffer of size %zu is too small for %s, need %zu\n",bufferSize, asn_DEF_E2SM_gNB_X2_indicationMessage.name, rval.encoded);
954             return e2err_RICindicationMessagePackFail_2;
955         }
956         else
957             if (debug)
958                 sprintf(pLogBuffer,"\nSuccessfully encoded %s. Buffer size %zu, encoded size %zu\n\n",asn_DEF_E2SM_gNB_X2_indicationMessage.name, bufferSize, rval.encoded);
959
960         ASN_STRUCT_FREE(asn_DEF_E2SM_gNB_X2_indicationMessage, pE2SM_gNB_X2_indicationMessage);
961
962         pRICIndicationMessage->octetString.contentLength = rval.encoded;
963         return e2err_OK;
964     }
965     else
966         return e2err_E2SM_gNB_X2_indicationMessageAllocE2AP_PDUFail;
967 }
968
969 //////////////////////////////////////////////////////////////////////
970 uint64_t packRICSubscriptionDeleteRequest(size_t* pDataBufferSize, byte* pDataBuffer, char* pLogBuffer, RICSubscriptionDeleteRequest_t* pRICSubscriptionDeleteRequest) {
971
972     E2AP_PDU_t* pE2AP_PDU = calloc(1, sizeof(E2AP_PDU_t));
973     if(pE2AP_PDU)
974         {
975         pE2AP_PDU->present = E2AP_PDU_PR_initiatingMessage;
976         pE2AP_PDU->choice.initiatingMessage.procedureCode = ProcedureCode_id_ricSubscriptionDelete;
977         pE2AP_PDU->choice.initiatingMessage.criticality = Criticality_ignore;
978         pE2AP_PDU->choice.initiatingMessage.value.present = RICInitiatingMessage__value_PR_RICsubscriptionDeleteRequest;
979
980         // RICrequestID
981         RICsubscriptionDeleteRequest_IEs_t* pRICsubscriptionDeleteRequest_IEs = calloc(1, sizeof(RICsubscriptionDeleteRequest_IEs_t));
982         if (pRICsubscriptionDeleteRequest_IEs) {
983             pRICsubscriptionDeleteRequest_IEs->id = ProtocolIE_ID_id_RICrequestID;
984             pRICsubscriptionDeleteRequest_IEs->criticality = Criticality_reject;
985             pRICsubscriptionDeleteRequest_IEs->value.present = RICsubscriptionDeleteRequest_IEs__value_PR_RICrequestID;
986             pRICsubscriptionDeleteRequest_IEs->value.choice.RICrequestID.ricRequestorID = pRICSubscriptionDeleteRequest->ricRequestID.ricRequestorID;
987             pRICsubscriptionDeleteRequest_IEs->value.choice.RICrequestID.ricRequestSequenceNumber = pRICSubscriptionDeleteRequest->ricRequestID.ricRequestSequenceNumber;
988             ASN_SEQUENCE_ADD(&pE2AP_PDU->choice.initiatingMessage.value.choice.RICsubscriptionDeleteRequest.protocolIEs.list, pRICsubscriptionDeleteRequest_IEs);
989         }
990         else
991             return e2err_RICSubscriptionDeleteRequestAllocRICrequestIDFail;
992
993         // RANfunctionID
994         pRICsubscriptionDeleteRequest_IEs = calloc(1, sizeof(RICsubscriptionDeleteRequest_IEs_t));
995         if (pRICsubscriptionDeleteRequest_IEs) {
996             pRICsubscriptionDeleteRequest_IEs->id = ProtocolIE_ID_id_RANfunctionID;
997             pRICsubscriptionDeleteRequest_IEs->criticality = Criticality_reject;
998             pRICsubscriptionDeleteRequest_IEs->value.present = RICsubscriptionDeleteRequest_IEs__value_PR_RANfunctionID;
999             pRICsubscriptionDeleteRequest_IEs->value.choice.RANfunctionID = pRICSubscriptionDeleteRequest->ranFunctionID;
1000             ASN_SEQUENCE_ADD(&pE2AP_PDU->choice.initiatingMessage.value.choice.RICsubscriptionDeleteRequest.protocolIEs.list, pRICsubscriptionDeleteRequest_IEs);
1001         }
1002         else
1003             return e2err_RICSubscriptionDeleteRequestAllocRANfunctionIDFail;
1004
1005         if (E2encode(pE2AP_PDU, pDataBufferSize, pDataBuffer, pLogBuffer))
1006             return e2err_OK;
1007         else
1008             return e2err_RICSubscriptionDeleteRequestEncodeFail;
1009     }
1010     else
1011         return e2err_RICSubscriptionDeleteRequestAllocE2AP_PDUFail;
1012 }
1013
1014 //////////////////////////////////////////////////////////////////////
1015 uint64_t packRICSubscriptionDeleteResponse(size_t* pDataBufferSize, byte* pDataBuffer, char* pLogBuffer, RICSubscriptionDeleteResponse_t* pRICSubscriptionDeleteResponse) {
1016
1017     E2AP_PDU_t* pE2AP_PDU = calloc(1, sizeof(E2AP_PDU_t));
1018     if(pE2AP_PDU)
1019         {
1020         pE2AP_PDU->present = E2AP_PDU_PR_successfulOutcome;
1021         pE2AP_PDU->choice.successfulOutcome.procedureCode = ProcedureCode_id_ricSubscriptionDelete;
1022         pE2AP_PDU->choice.successfulOutcome.criticality = Criticality_ignore;
1023         pE2AP_PDU->choice.successfulOutcome.value.present = RICSuccessfulOutcome__value_PR_RICsubscriptionDeleteResponse;
1024
1025         // RICrequestID
1026         RICsubscriptionDeleteResponse_IEs_t* pRICsubscriptionDeleteResponse_IEs = calloc(1, sizeof(RICsubscriptionDeleteResponse_IEs_t));
1027         if (pRICsubscriptionDeleteResponse_IEs) {
1028             pRICsubscriptionDeleteResponse_IEs->id = ProtocolIE_ID_id_RICrequestID;
1029             pRICsubscriptionDeleteResponse_IEs->criticality = Criticality_reject;
1030             pRICsubscriptionDeleteResponse_IEs->value.present = RICsubscriptionDeleteResponse_IEs__value_PR_RICrequestID;
1031             pRICsubscriptionDeleteResponse_IEs->value.choice.RICrequestID.ricRequestorID = pRICSubscriptionDeleteResponse->ricRequestID.ricRequestorID;
1032             pRICsubscriptionDeleteResponse_IEs->value.choice.RICrequestID.ricRequestSequenceNumber = pRICSubscriptionDeleteResponse->ricRequestID.ricRequestSequenceNumber;
1033             ASN_SEQUENCE_ADD(&pE2AP_PDU->choice.successfulOutcome.value.choice.RICsubscriptionDeleteResponse.protocolIEs.list, pRICsubscriptionDeleteResponse_IEs);
1034         }
1035         else
1036             return e2err_RICSubscriptionDeleteResponseAllocRICrequestIDFail;
1037
1038         // RANfunctionID
1039         pRICsubscriptionDeleteResponse_IEs = calloc(1, sizeof(RICsubscriptionDeleteResponse_IEs_t));
1040         if (pRICsubscriptionDeleteResponse_IEs) {
1041             pRICsubscriptionDeleteResponse_IEs->id = ProtocolIE_ID_id_RANfunctionID;
1042             pRICsubscriptionDeleteResponse_IEs->criticality = Criticality_reject;
1043             pRICsubscriptionDeleteResponse_IEs->value.present = RICsubscriptionDeleteResponse_IEs__value_PR_RANfunctionID;
1044             pRICsubscriptionDeleteResponse_IEs->value.choice.RANfunctionID = pRICSubscriptionDeleteResponse->ranFunctionID;
1045             ASN_SEQUENCE_ADD(&pE2AP_PDU->choice.successfulOutcome.value.choice.RICsubscriptionDeleteResponse.protocolIEs.list, pRICsubscriptionDeleteResponse_IEs);
1046         }
1047         else
1048             return e2err_RICSubscriptionDeleteResponseAllocRANfunctionIDFail;
1049
1050         if (E2encode(pE2AP_PDU, pDataBufferSize, pDataBuffer, pLogBuffer))
1051             return e2err_OK;
1052         else
1053             return e2err_RICSubscriptionDeleteResponseEncodeFail;
1054     }
1055     else
1056         return e2err_RICSubscriptionDeleteResponseAllocE2AP_PDUFail;
1057 }
1058
1059 uint64_t packRICSubscriptionDeleteFailure(size_t* pDataBufferSize, byte* pDataBuffer, char* pLogBuffer, RICSubscriptionDeleteFailure_t* pRICSubscriptionDeleteFailure) {
1060
1061     E2AP_PDU_t* pE2AP_PDU = calloc(1, sizeof(E2AP_PDU_t));
1062     if(pE2AP_PDU)
1063         {
1064         pE2AP_PDU->present = E2AP_PDU_PR_unsuccessfulOutcome;
1065         pE2AP_PDU->choice.unsuccessfulOutcome.procedureCode = ProcedureCode_id_ricSubscriptionDelete;
1066         pE2AP_PDU->choice.unsuccessfulOutcome.criticality = Criticality_ignore;
1067         pE2AP_PDU->choice.unsuccessfulOutcome.value.present = RICUnsuccessfulOutcome__value_PR_RICsubscriptionDeleteFailure;
1068
1069         // RICrequestID
1070         RICsubscriptionDeleteFailure_IEs_t* pRICsubscriptionDeleteFailure_IEs = calloc(1, sizeof(RICsubscriptionDeleteFailure_IEs_t));
1071         if (pRICsubscriptionDeleteFailure_IEs) {
1072             pRICsubscriptionDeleteFailure_IEs->id = ProtocolIE_ID_id_RICrequestID;
1073             pRICsubscriptionDeleteFailure_IEs->criticality = Criticality_reject;
1074             pRICsubscriptionDeleteFailure_IEs->value.present = RICsubscriptionDeleteFailure_IEs__value_PR_RICrequestID;
1075             pRICsubscriptionDeleteFailure_IEs->value.choice.RICrequestID.ricRequestorID = pRICSubscriptionDeleteFailure->ricRequestID.ricRequestorID;
1076             pRICsubscriptionDeleteFailure_IEs->value.choice.RICrequestID.ricRequestSequenceNumber = pRICSubscriptionDeleteFailure->ricRequestID.ricRequestSequenceNumber;
1077             ASN_SEQUENCE_ADD(&pE2AP_PDU->choice.unsuccessfulOutcome.value.choice.RICsubscriptionDeleteFailure.protocolIEs.list, pRICsubscriptionDeleteFailure_IEs);
1078         }
1079         else
1080             return e2err_RICSubscriptionDeleteFailureAllocRICrequestIDFail;
1081
1082         // RANfunctionID
1083         pRICsubscriptionDeleteFailure_IEs = calloc(1, sizeof(RICsubscriptionDeleteFailure_IEs_t));
1084         if (pRICsubscriptionDeleteFailure_IEs) {
1085             pRICsubscriptionDeleteFailure_IEs->id = ProtocolIE_ID_id_RANfunctionID;
1086             pRICsubscriptionDeleteFailure_IEs->criticality = Criticality_reject;
1087             pRICsubscriptionDeleteFailure_IEs->value.present = RICsubscriptionDeleteFailure_IEs__value_PR_RANfunctionID;
1088             pRICsubscriptionDeleteFailure_IEs->value.choice.RANfunctionID = pRICSubscriptionDeleteFailure->ranFunctionID;
1089             ASN_SEQUENCE_ADD(&pE2AP_PDU->choice.unsuccessfulOutcome.value.choice.RICsubscriptionDeleteFailure.protocolIEs.list, pRICsubscriptionDeleteFailure_IEs);
1090         }
1091         else
1092             return e2err_RICSubscriptionDeleteFailureAllocRANfunctionIDFail;
1093
1094         // RICcause
1095         pRICsubscriptionDeleteFailure_IEs = calloc(1, sizeof(RICsubscriptionDeleteFailure_IEs_t));
1096         if (pRICsubscriptionDeleteFailure_IEs) {
1097             pRICsubscriptionDeleteFailure_IEs->id = ProtocolIE_ID_id_RICcause;
1098             pRICsubscriptionDeleteFailure_IEs->criticality = Criticality_reject;
1099             pRICsubscriptionDeleteFailure_IEs->value.present = RICsubscriptionDeleteFailure_IEs__value_PR_RICcause;
1100             if (pRICSubscriptionDeleteFailure->ricCause.content == RICcause_PR_radioNetwork) {
1101                 pRICsubscriptionDeleteFailure_IEs->value.choice.RICcause.present = RICcause_PR_radioNetwork;
1102                 pRICsubscriptionDeleteFailure_IEs->value.choice.RICcause.choice.radioNetwork =
1103                   pRICSubscriptionDeleteFailure->ricCause.cause;
1104             }
1105             else if (pRICSubscriptionDeleteFailure->ricCause.content == RICcause_PR_transport) {
1106                 pRICsubscriptionDeleteFailure_IEs->value.choice.RICcause.present = RICcause_PR_transport;
1107                 pRICsubscriptionDeleteFailure_IEs->value.choice.RICcause.choice.transport =
1108                   pRICSubscriptionDeleteFailure->ricCause.cause;
1109             }
1110             else if (pRICSubscriptionDeleteFailure->ricCause.content == RICcause_PR_protocol) {
1111                 pRICsubscriptionDeleteFailure_IEs->value.choice.RICcause.present = RICcause_PR_protocol;
1112                 pRICsubscriptionDeleteFailure_IEs->value.choice.RICcause.choice.protocol =
1113                   pRICSubscriptionDeleteFailure->ricCause.cause;
1114             }
1115             else if (pRICSubscriptionDeleteFailure->ricCause.content == RICcause_PR_misc) {
1116                 pRICsubscriptionDeleteFailure_IEs->value.choice.RICcause.present = RICcause_PR_misc;
1117                 pRICsubscriptionDeleteFailure_IEs->value.choice.RICcause.choice.misc =
1118                   pRICSubscriptionDeleteFailure->ricCause.cause;
1119             }
1120             else if (pRICSubscriptionDeleteFailure->ricCause.content == RICcause_PR_ric) {
1121                 pRICsubscriptionDeleteFailure_IEs->value.choice.RICcause.present = RICcause_PR_ric;
1122                 pRICsubscriptionDeleteFailure_IEs->value.choice.RICcause.choice.ric =
1123                   pRICSubscriptionDeleteFailure->ricCause.cause;
1124             }
1125             ASN_SEQUENCE_ADD(&pE2AP_PDU->choice.unsuccessfulOutcome.value.choice.RICsubscriptionDeleteFailure.protocolIEs.list, pRICsubscriptionDeleteFailure_IEs);
1126         }
1127         else
1128             return e2err_RICSubscriptionDeleteFailureAllocRICcauseFail;
1129
1130         // CriticalityDiagnostics, OPTIONAL
1131
1132         if (E2encode(pE2AP_PDU, pDataBufferSize, pDataBuffer, pLogBuffer))
1133             return e2err_OK;
1134         else
1135             return e2err_RICSubscriptionDeleteFailureEncodeFail;
1136     }
1137     else
1138         return e2err_RICSubscriptionDeleteFailureAllocE2AP_PDUFail;
1139 }
1140
1141 //////////////////////////////////////////////////////////////////////
1142 e2ap_pdu_ptr_t* unpackE2AP_pdu(const size_t dataBufferSize, const byte* dataBuffer, char* pLogBuffer, E2MessageInfo_t* pMessageInfo) {
1143
1144     E2AP_PDU_t* pE2AP_PDU = 0;
1145     asn_dec_rval_t rval;
1146     rval = asn_decode(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, (void **)&pE2AP_PDU, dataBuffer, dataBufferSize);
1147     switch (rval.code) {
1148     case RC_OK:
1149         // Debug print
1150         if (debug) {
1151             sprintf(pLogBuffer,"\nSuccessfully decoded E2AP-PDU\n\n");
1152             asn_fprint(stdout, &asn_DEF_E2AP_PDU, pE2AP_PDU);
1153         }
1154
1155         if (pE2AP_PDU->present == E2AP_PDU_PR_initiatingMessage) {
1156             if (pE2AP_PDU->choice.initiatingMessage.procedureCode == ProcedureCode_id_ricSubscription) {
1157                 if (pE2AP_PDU->choice.initiatingMessage.value.present == RICInitiatingMessage__value_PR_RICsubscriptionRequest) {
1158                     pMessageInfo->messageType = cE2InitiatingMessage;
1159                     pMessageInfo->messageId = cRICSubscriptionRequest;
1160                     return (e2ap_pdu_ptr_t*)pE2AP_PDU;
1161                 }
1162                 else {
1163                     sprintf(pLogBuffer,"\nError. Not supported initiatingMessage MessageId = %u\n\n",pE2AP_PDU->choice.initiatingMessage.value.present);
1164                     return 0;
1165                 }
1166             }
1167             else if (pE2AP_PDU->choice.initiatingMessage.procedureCode == ProcedureCode_id_ricIndication) {
1168                 if (pE2AP_PDU->choice.initiatingMessage.value.present == RICInitiatingMessage__value_PR_RICindication) {
1169                     pMessageInfo->messageType = cE2InitiatingMessage;
1170                     pMessageInfo->messageId = cRICIndication;
1171                     return (e2ap_pdu_ptr_t*)pE2AP_PDU;
1172                 }
1173                 else {
1174                     sprintf(pLogBuffer,"\nError. Not supported initiatingMessage MessageId = %u\n\n",pE2AP_PDU->choice.initiatingMessage.value.present);
1175                     return 0;
1176                 }
1177             }
1178             else if (pE2AP_PDU->choice.initiatingMessage.procedureCode == ProcedureCode_id_ricSubscriptionDelete) {
1179                 if (pE2AP_PDU->choice.initiatingMessage.value.present == RICInitiatingMessage__value_PR_RICsubscriptionDeleteRequest) {
1180                     pMessageInfo->messageType = cE2InitiatingMessage;
1181                     pMessageInfo->messageId = cRICSubscriptionDeleteRequest;
1182                     return (e2ap_pdu_ptr_t*)pE2AP_PDU;
1183                 }
1184                 else {
1185                     sprintf(pLogBuffer,"\nError. Not supported initiatingMessage MessageId = %u\n\n",pE2AP_PDU->choice.initiatingMessage.value.present);
1186                     return 0;
1187                 }
1188             }
1189             else {
1190                 sprintf(pLogBuffer,"\nError. Procedure not supported. ProcedureCode = %li\n\n",pE2AP_PDU->choice.initiatingMessage.procedureCode);
1191                 return 0;
1192             }
1193         }
1194         else if (pE2AP_PDU->present == E2AP_PDU_PR_successfulOutcome) {
1195             if (pE2AP_PDU->choice.successfulOutcome.procedureCode == ProcedureCode_id_ricSubscription) {
1196                 if (pE2AP_PDU->choice.successfulOutcome.value.present == RICSuccessfulOutcome__value_PR_RICsubscriptionResponse) {
1197                     pMessageInfo->messageType = cE2SuccessfulOutcome;
1198                     pMessageInfo->messageId = cRICSubscriptionResponse;
1199                     return (e2ap_pdu_ptr_t*)pE2AP_PDU;
1200                 }
1201                 else {
1202                     sprintf(pLogBuffer,"\nError. Not supported successfulOutcome MessageId = %u\n\n",pE2AP_PDU->choice.successfulOutcome.value.present);
1203                     return 0;
1204                 }
1205             }
1206             else if (pE2AP_PDU->choice.successfulOutcome.procedureCode == ProcedureCode_id_ricSubscriptionDelete) {
1207                 if (pE2AP_PDU->choice.successfulOutcome.value.present == RICSuccessfulOutcome__value_PR_RICsubscriptionDeleteResponse) {
1208                     pMessageInfo->messageType = cE2SuccessfulOutcome;
1209                     pMessageInfo->messageId = cRICsubscriptionDeleteResponse;
1210                     return (e2ap_pdu_ptr_t*)pE2AP_PDU;
1211                 }
1212                 else {
1213                     sprintf(pLogBuffer,"\nError. Not supported successfulOutcome MessageId = %u\n\n",pE2AP_PDU->choice.successfulOutcome.value.present);
1214                     return 0;
1215                 }
1216             }
1217             else {
1218                 sprintf(pLogBuffer,"\nError. Procedure not supported. ProcedureCode = %li\n\n",pE2AP_PDU->choice.successfulOutcome.procedureCode);
1219                 return 0;
1220             }
1221         }
1222         else if (pE2AP_PDU->present == E2AP_PDU_PR_unsuccessfulOutcome) {
1223             if (pE2AP_PDU->choice.unsuccessfulOutcome.procedureCode == ProcedureCode_id_ricSubscription) {
1224                 if (pE2AP_PDU->choice.unsuccessfulOutcome.value.present == RICUnsuccessfulOutcome__value_PR_RICsubscriptionFailure) {
1225                     pMessageInfo->messageType = cE2UnsuccessfulOutcome;
1226                     pMessageInfo->messageId = cRICSubscriptionFailure;
1227                     return (e2ap_pdu_ptr_t*)pE2AP_PDU;
1228                 }
1229                 else {
1230                     sprintf(pLogBuffer,"\nError. Not supported unsuccessfulOutcome MessageId = %u\n\n",pE2AP_PDU->choice.unsuccessfulOutcome.value.present);
1231                     return 0;
1232                 }
1233             }
1234             else if (pE2AP_PDU->choice.unsuccessfulOutcome.procedureCode == ProcedureCode_id_ricSubscriptionDelete) {
1235                 if (pE2AP_PDU->choice.unsuccessfulOutcome.value.present == RICUnsuccessfulOutcome__value_PR_RICsubscriptionDeleteFailure) {
1236                     pMessageInfo->messageType = cE2UnsuccessfulOutcome;
1237                     pMessageInfo->messageId = cRICsubscriptionDeleteFailure;
1238                     return (e2ap_pdu_ptr_t*)pE2AP_PDU;
1239                 }
1240                 else {
1241                     sprintf(pLogBuffer,"\nError. Not supported unsuccessfulOutcome MessageId = %u\n\n",pE2AP_PDU->choice.unsuccessfulOutcome.value.present);
1242                     return 0;
1243                 }
1244             }
1245         }
1246         else
1247             sprintf(pLogBuffer,"\nDecode failed. Invalid message type %u\n",pE2AP_PDU->present);
1248         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1249         return 0;
1250     case RC_WMORE:
1251         sprintf(pLogBuffer,"\nDecode failed. More data needed. Buffer size %zu, %s, consumed %zu\n",dataBufferSize, asn_DEF_E2AP_PDU.name, rval.consumed);
1252         return 0;
1253     case RC_FAIL:
1254         sprintf(pLogBuffer,"\nDecode failed. Buffer size %zu, %s, consumed %zu\n",dataBufferSize, asn_DEF_E2AP_PDU.name, rval.consumed);
1255         return 0;
1256     default:
1257         return 0;
1258     }
1259 }
1260
1261 //////////////////////////////////////////////////////////////////////
1262 uint64_t getRICSubscriptionRequestData(e2ap_pdu_ptr_t* pE2AP_PDU_pointer, RICSubscriptionRequest_t* pRICSubscriptionRequest) {
1263
1264     E2AP_PDU_t* pE2AP_PDU = (E2AP_PDU_t*)pE2AP_PDU_pointer;
1265     RICsubscriptionRequest_IEs_t* pRICsubscriptionRequest_IEs;
1266     // RICrequestID
1267     if (pE2AP_PDU->choice.initiatingMessage.value.choice.RICsubscriptionRequest.protocolIEs.list.count > 0) {
1268         pRICsubscriptionRequest_IEs = pE2AP_PDU->choice.initiatingMessage.value.choice.RICsubscriptionRequest.protocolIEs.list.array[0];
1269         pRICSubscriptionRequest->ricRequestID.ricRequestorID = pRICsubscriptionRequest_IEs->value.choice.RICrequestID.ricRequestorID;
1270         pRICSubscriptionRequest->ricRequestID.ricRequestSequenceNumber = pRICsubscriptionRequest_IEs->value.choice.RICrequestID.ricRequestSequenceNumber;
1271     }
1272     else {
1273         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1274         return e2err_RICsubscriptionRequestRICrequestIDMissing;
1275     }
1276
1277     // RANfunctionID
1278     if (pE2AP_PDU->choice.initiatingMessage.value.choice.RICsubscriptionRequest.protocolIEs.list.count > 1) {
1279         pRICsubscriptionRequest_IEs = pE2AP_PDU->choice.initiatingMessage.value.choice.RICsubscriptionRequest.protocolIEs.list.array[1];
1280         pRICSubscriptionRequest->ranFunctionID = pRICsubscriptionRequest_IEs->value.choice.RANfunctionID;
1281     }
1282     else {
1283         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1284         return e2err_RICsubscriptionRequestRANfunctionIDMissing;
1285     }
1286
1287     // RICsubscription
1288     if (pE2AP_PDU->choice.initiatingMessage.value.choice.RICsubscriptionRequest.protocolIEs.list.count > 2) {
1289         pRICsubscriptionRequest_IEs = pE2AP_PDU->choice.initiatingMessage.value.choice.RICsubscriptionRequest.protocolIEs.list.array[2];
1290
1291         // Unpack EventTriggerDefinition
1292         RICeventTriggerDefinition_t* pRICeventTriggerDefinition =
1293           (RICeventTriggerDefinition_t*)&pRICsubscriptionRequest_IEs->value.choice.RICsubscription.ricEventTriggerDefinition;
1294         pRICSubscriptionRequest->ricSubscription.ricEventTriggerDefinition.octetString.contentLength = pRICeventTriggerDefinition->size;
1295         memcpy(pRICSubscriptionRequest->ricSubscription.ricEventTriggerDefinition.octetString.data, pRICeventTriggerDefinition->buf, pRICeventTriggerDefinition->size); //octetstring
1296
1297         uint64_t returnCode;
1298         if ((returnCode = getRICEventTriggerDefinitionData(&pRICSubscriptionRequest->ricSubscription.ricEventTriggerDefinition) != e2err_OK)) {
1299             ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1300             return returnCode;
1301         }
1302
1303         // RICactions-ToBeSetup-List
1304         RICaction_ToBeSetup_ItemIEs_t* pRICaction_ToBeSetup_ItemIEs;
1305         uint64_t index = 0;
1306         while (index < pRICsubscriptionRequest_IEs->value.choice.RICsubscription.ricAction_ToBeSetup_List.list.count)
1307         {
1308             pRICaction_ToBeSetup_ItemIEs = (RICaction_ToBeSetup_ItemIEs_t*)pRICsubscriptionRequest_IEs->value.choice.RICsubscription.ricAction_ToBeSetup_List.list.array[index];
1309
1310             // RICActionID
1311             pRICSubscriptionRequest->ricSubscription.ricActionToBeSetupItemIEs.ricActionToBeSetupItem[index].ricActionID =
1312               pRICaction_ToBeSetup_ItemIEs->value.choice.RICaction_ToBeSetup_Item.ricActionID;
1313
1314             // RICActionType
1315             pRICSubscriptionRequest->ricSubscription.ricActionToBeSetupItemIEs.ricActionToBeSetupItem[index].ricActionType =
1316               pRICaction_ToBeSetup_ItemIEs->value.choice.RICaction_ToBeSetup_Item.ricActionType;
1317
1318             // RICactionDefinition, OPTIONAL
1319             if (pRICaction_ToBeSetup_ItemIEs->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition)
1320             {
1321                 pRICSubscriptionRequest->ricSubscription.ricActionToBeSetupItemIEs.ricActionToBeSetupItem[index].ricActionDefinitionPresent = false;
1322                 // not used in RIC
1323             }
1324             else
1325                 pRICSubscriptionRequest->ricSubscription.ricActionToBeSetupItemIEs.ricActionToBeSetupItem[index].ricActionDefinitionPresent = false;
1326
1327             // RICsubsequentAction, OPTIONAL
1328             RICsubsequentAction_t* pRICsubsequentAction;
1329             if (pRICaction_ToBeSetup_ItemIEs->value.choice.RICaction_ToBeSetup_Item.ricSubsequentAction)
1330             {
1331                 pRICsubsequentAction = pRICaction_ToBeSetup_ItemIEs->value.choice.RICaction_ToBeSetup_Item.ricSubsequentAction;
1332                 pRICSubscriptionRequest->ricSubscription.ricActionToBeSetupItemIEs.ricActionToBeSetupItem[index].ricSubsequentActionPresent = true;
1333                 pRICSubscriptionRequest->ricSubscription.ricActionToBeSetupItemIEs.ricActionToBeSetupItem[index].ricSubsequentAction.ricSubsequentActionType =
1334                   pRICsubsequentAction->ricSubsequentActionType;
1335                 pRICSubscriptionRequest->ricSubscription.ricActionToBeSetupItemIEs.ricActionToBeSetupItem[index].ricSubsequentAction.ricTimeToWait =
1336                   pRICsubsequentAction->ricTimeToWait;
1337             }
1338             else
1339                 pRICSubscriptionRequest->ricSubscription.ricActionToBeSetupItemIEs.ricActionToBeSetupItem[index].ricSubsequentActionPresent = false;
1340             index++;
1341         }
1342         pRICSubscriptionRequest->ricSubscription.ricActionToBeSetupItemIEs.contentLength = index;
1343     }
1344     else {
1345         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1346         return e2err_RICsubscriptionRequestICsubscriptionMissing;
1347     }
1348
1349     ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1350     return e2err_OK;
1351 }
1352
1353 //////////////////////////////////////////////////////////////////////
1354 uint64_t getRICEventTriggerDefinitionData(RICEventTriggerDefinition_t* pRICEventTriggerDefinition) {
1355
1356     E2SM_gNB_X2_eventTriggerDefinition_t* pE2SM_gNB_X2_eventTriggerDefinition = 0;
1357     asn_dec_rval_t rval;
1358     rval = asn_decode(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_X2_eventTriggerDefinition, (void **)&pE2SM_gNB_X2_eventTriggerDefinition,
1359                       pRICEventTriggerDefinition->octetString.data, pRICEventTriggerDefinition->octetString.contentLength);
1360     switch(rval.code) {
1361     case RC_OK:
1362         // Debug print
1363         if (debug) {
1364             printf("\nSuccessfully decoded E2SM_gNB_X2_eventTriggerDefinition\n\n");
1365             asn_fprint(stdout, &asn_DEF_E2SM_gNB_X2_eventTriggerDefinition, pE2SM_gNB_X2_eventTriggerDefinition);
1366         }
1367
1368         // InterfaceID, GlobalENB-ID or GlobalGNB-ID
1369         if (pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.present == Interface_ID_PR_global_eNB_ID) {
1370
1371             // GlobalENB-ID
1372             pRICEventTriggerDefinition->interfaceID.globalENBIDPresent = true;
1373
1374             // PLMN-Identity
1375             pRICEventTriggerDefinition->interfaceID.globalENBID.pLMNIdentity.contentLength =
1376               pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.pLMN_Identity.size;
1377             memcpy(pRICEventTriggerDefinition->interfaceID.globalENBID.pLMNIdentity.pLMNIdentityVal,
1378               pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.pLMN_Identity.buf,
1379               pRICEventTriggerDefinition->interfaceID.globalENBID.pLMNIdentity.contentLength);
1380
1381             //  ENB-ID
1382             IdOctects_t eNBOctects;
1383             memset(eNBOctects.octets, 0, sizeof(eNBOctects));
1384             if (pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.present == ENB_ID_PR_macro_eNB_ID) {
1385                 // BIT STRING (SIZE (20)
1386                 pRICEventTriggerDefinition->interfaceID.globalENBID.nodeID.bits = cMacroENBIDP_20Bits;
1387                 memcpy(eNBOctects.octets,pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.choice.macro_eNB_ID.buf,
1388                   pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.choice.macro_eNB_ID.size);
1389                 pRICEventTriggerDefinition->interfaceID.globalENBID.nodeID.nodeID = eNBOctects.nodeID;
1390             }
1391             else if (pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.present == ENB_ID_PR_home_eNB_ID) {
1392                 // BIT STRING (SIZE (28)
1393                 pRICEventTriggerDefinition->interfaceID.globalENBID.nodeID.bits = cHomeENBID_28Bits;
1394                 memcpy(eNBOctects.octets,pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.choice.home_eNB_ID.buf,
1395                   pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.choice.home_eNB_ID.size);
1396                 pRICEventTriggerDefinition->interfaceID.globalENBID.nodeID.nodeID = eNBOctects.nodeID;
1397             }
1398             else if (pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.present == ENB_ID_PR_short_Macro_eNB_ID) {
1399                 // BIT STRING (SIZE(18)
1400                 pRICEventTriggerDefinition->interfaceID.globalENBID.nodeID.bits = cShortMacroENBID_18Bits;
1401                 memcpy(eNBOctects.octets,pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.choice.short_Macro_eNB_ID.buf,
1402                   pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.choice.short_Macro_eNB_ID.size);
1403                 pRICEventTriggerDefinition->interfaceID.globalENBID.nodeID.nodeID = eNBOctects.nodeID;
1404             }
1405             else if (pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.present == ENB_ID_PR_long_Macro_eNB_ID) {
1406                 // BIT STRING (SIZE(21)
1407                 pRICEventTriggerDefinition->interfaceID.globalENBID.nodeID.bits =  clongMacroENBIDP_21Bits;
1408                 memcpy(eNBOctects.octets,pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.choice.long_Macro_eNB_ID.buf,
1409                   pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.eNB_ID.choice.long_Macro_eNB_ID.size);
1410                 pRICEventTriggerDefinition->interfaceID.globalENBID.nodeID.nodeID = eNBOctects.nodeID;
1411             }
1412             else {
1413                 pRICEventTriggerDefinition->interfaceID.globalENBIDPresent = false;
1414                 pRICEventTriggerDefinition->interfaceID.globalGNBIDPresent = false;
1415                 ASN_STRUCT_FREE(asn_DEF_E2SM_gNB_X2_eventTriggerDefinition, pE2SM_gNB_X2_eventTriggerDefinition);
1416                 return e2err_RICEventTriggerDefinitionIEValueFail_5;
1417             }
1418         }
1419         else if (pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.present == Interface_ID_PR_global_gNB_ID) {
1420             // GlobalGNB-ID
1421             pRICEventTriggerDefinition->interfaceID.globalGNBIDPresent = true;
1422
1423             // PLMN-Identity
1424             pRICEventTriggerDefinition->interfaceID.globalGNBID.pLMNIdentity.contentLength =
1425               pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.pLMN_Identity.size;
1426             memcpy(pRICEventTriggerDefinition->interfaceID.globalGNBID.pLMNIdentity.pLMNIdentityVal,
1427               pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_eNB_ID.pLMN_Identity.buf,
1428               pRICEventTriggerDefinition->interfaceID.globalGNBID.pLMNIdentity.contentLength);
1429
1430             // GNB-ID
1431             IdOctects_t gNBOctects;
1432             memset(gNBOctects.octets, 0, sizeof(gNBOctects));
1433             if (pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_gNB_ID.gNB_ID.present == GNB_ID_PR_gNB_ID) {
1434                 pRICEventTriggerDefinition->interfaceID.globalGNBID.nodeID.bits = pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_gNB_ID.gNB_ID.choice.gNB_ID.size;
1435                 memcpy(gNBOctects.octets, pE2SM_gNB_X2_eventTriggerDefinition->interface_ID.choice.global_gNB_ID.gNB_ID.choice.gNB_ID.buf,
1436                    pRICEventTriggerDefinition->interfaceID.globalGNBID.nodeID.bits);
1437                 pRICEventTriggerDefinition->interfaceID.globalGNBID.nodeID.nodeID = gNBOctects.nodeID;
1438             }
1439             else {
1440                 pRICEventTriggerDefinition->interfaceID.globalENBIDPresent = false;
1441                 pRICEventTriggerDefinition->interfaceID.globalGNBIDPresent = false;
1442                 ASN_STRUCT_FREE(asn_DEF_E2SM_gNB_X2_eventTriggerDefinition, pE2SM_gNB_X2_eventTriggerDefinition);
1443                 return e2err_RICEventTriggerDefinitionIEValueFail_6;
1444             }
1445         }
1446         else {
1447             pRICEventTriggerDefinition->interfaceID.globalENBIDPresent = false;
1448             pRICEventTriggerDefinition->interfaceID.globalGNBIDPresent = false;
1449             ASN_STRUCT_FREE(asn_DEF_E2SM_gNB_X2_eventTriggerDefinition, pE2SM_gNB_X2_eventTriggerDefinition);
1450             return e2err_RICEventTriggerDefinitionIEValueFail_7;
1451         }
1452
1453         // InterfaceDirection
1454         pRICEventTriggerDefinition->interfaceDirection = pE2SM_gNB_X2_eventTriggerDefinition->interfaceDirection;
1455
1456         // InterfaceMessageType
1457         pRICEventTriggerDefinition->interfaceMessageType.procedureCode = pE2SM_gNB_X2_eventTriggerDefinition->interfaceMessageType.procedureCode;
1458
1459         if (pE2SM_gNB_X2_eventTriggerDefinition->interfaceMessageType.typeOfMessage == TypeOfMessage_initiating_message)
1460             pRICEventTriggerDefinition->interfaceMessageType.typeOfMessage = cE2InitiatingMessage;
1461         else if (pE2SM_gNB_X2_eventTriggerDefinition->interfaceMessageType.typeOfMessage == TypeOfMessage_successful_outcome)
1462             pRICEventTriggerDefinition->interfaceMessageType.typeOfMessage = cE2SuccessfulOutcome;
1463         else if (pE2SM_gNB_X2_eventTriggerDefinition->interfaceMessageType.typeOfMessage == TypeOfMessage_unsuccessful_outcome)
1464             pRICEventTriggerDefinition->interfaceMessageType.typeOfMessage = cE2UnsuccessfulOutcome;
1465         else {
1466             ASN_STRUCT_FREE(asn_DEF_E2SM_gNB_X2_eventTriggerDefinition, pE2SM_gNB_X2_eventTriggerDefinition);
1467             return e2err_RICEventTriggerDefinitionIEValueFail_8;
1468         }
1469
1470         ASN_STRUCT_FREE(asn_DEF_E2SM_gNB_X2_eventTriggerDefinition, pE2SM_gNB_X2_eventTriggerDefinition);
1471         return e2err_OK;
1472     case RC_WMORE:
1473         if (debug)
1474             printf("\nDecode failed. More data needed. Buffer size %zu, %s, consumed %zu\n",pRICEventTriggerDefinition->octetString.contentLength,
1475                    asn_DEF_E2SM_gNB_X2_eventTriggerDefinition.name, rval.consumed);
1476
1477         return e2err_RICEventTriggerDefinitionDecodeWMOREFail;
1478     case RC_FAIL:
1479         if (debug)
1480             printf("\nDecode failed. Buffer size %zu, %s, consumed %zu\n",pRICEventTriggerDefinition->octetString.contentLength,
1481                    asn_DEF_E2SM_gNB_X2_eventTriggerDefinition.name, rval.consumed);
1482
1483         return e2err_RICEventTriggerDefinitionDecodeFAIL;
1484     default:
1485         return e2err_RICEventTriggerDefinitionDecodeDefaultFail;
1486     }
1487 }
1488
1489 //////////////////////////////////////////////////////////////////////
1490 uint64_t getRICSubscriptionResponseData(e2ap_pdu_ptr_t* pE2AP_PDU_pointer, RICSubscriptionResponse_t* pRICSubscriptionResponse) {
1491
1492     E2AP_PDU_t* pE2AP_PDU = (E2AP_PDU_t*)pE2AP_PDU_pointer;
1493
1494     // RICrequestID
1495     RICsubscriptionResponse_IEs_t* pRICsubscriptionResponse_IEs;
1496     if (pE2AP_PDU->choice.successfulOutcome.value.choice.RICsubscriptionResponse.protocolIEs.list.count > 0) {
1497         pRICsubscriptionResponse_IEs = pE2AP_PDU->choice.successfulOutcome.value.choice.RICsubscriptionResponse.protocolIEs.list.array[0];
1498         pRICSubscriptionResponse->ricRequestID.ricRequestorID = pRICsubscriptionResponse_IEs->value.choice.RICrequestID.ricRequestorID;
1499         pRICSubscriptionResponse->ricRequestID.ricRequestSequenceNumber = pRICsubscriptionResponse_IEs->value.choice.RICrequestID.ricRequestSequenceNumber;
1500     }
1501     else {
1502         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1503         return e2err_RICsubscriptionResponseRICrequestIDMissing;
1504     }
1505
1506     // RANfunctionID
1507     if (pE2AP_PDU->choice.successfulOutcome.value.choice.RICsubscriptionResponse.protocolIEs.list.count > 1) {
1508         pRICsubscriptionResponse_IEs = pE2AP_PDU->choice.successfulOutcome.value.choice.RICsubscriptionResponse.protocolIEs.list.array[1];
1509         pRICSubscriptionResponse->ranFunctionID = pRICsubscriptionResponse_IEs->value.choice.RANfunctionID;
1510     }
1511     else {
1512         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1513         return e2err_RICsubscriptionResponseRANfunctionIDMissing;
1514     }
1515
1516     // RICaction-Admitted-List
1517     if (pE2AP_PDU->choice.successfulOutcome.value.choice.RICsubscriptionResponse.protocolIEs.list.count > 2) {
1518         pRICsubscriptionResponse_IEs = pE2AP_PDU->choice.successfulOutcome.value.choice.RICsubscriptionResponse.protocolIEs.list.array[2];
1519         pRICSubscriptionResponse->ricActionAdmittedList.contentLength = 0;
1520         uint64_t index = 0;
1521         while ((index < maxofRICactionID) && (index < pRICsubscriptionResponse_IEs->value.choice.RICaction_Admitted_List.list.count)) {
1522             RICaction_Admitted_ItemIEs_t* pRICaction_Admitted_ItemIEs =
1523               (RICaction_Admitted_ItemIEs_t*)pRICsubscriptionResponse_IEs->value.choice.RICaction_Admitted_List.list.array[index];
1524
1525             // RICActionID
1526             pRICSubscriptionResponse->ricActionAdmittedList.ricActionID[index] =
1527               pRICaction_Admitted_ItemIEs->value.choice.RICaction_Admitted_Item.ricActionID;
1528             index++;
1529         }
1530         pRICSubscriptionResponse->ricActionAdmittedList.contentLength = index;
1531     }
1532     else {
1533         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1534         return e2err_RICsubscriptionResponseRICaction_Admitted_ListMissing;
1535     }
1536
1537     // RICaction-NotAdmitted-List, OPTIONAL
1538     if (pE2AP_PDU->choice.successfulOutcome.value.choice.RICsubscriptionResponse.protocolIEs.list.count > 3) {
1539         pRICsubscriptionResponse_IEs = pE2AP_PDU->choice.successfulOutcome.value.choice.RICsubscriptionResponse.protocolIEs.list.array[3];
1540         if (pRICsubscriptionResponse_IEs->value.present == RICsubscriptionResponse_IEs__value_PR_RICaction_NotAdmitted_List) {
1541             pRICSubscriptionResponse->ricActionNotAdmittedListPresent = true;
1542             pRICSubscriptionResponse->ricActionNotAdmittedList.contentLength = 0;
1543             uint64_t index = 0;
1544             while ((index < maxofRICactionID) && (index < pRICsubscriptionResponse_IEs->value.choice.RICaction_NotAdmitted_List.list.count)) {
1545                 RICaction_NotAdmitted_ItemIEs_t* pRICaction_NotAdmitted_ItemIEs =
1546                   (RICaction_NotAdmitted_ItemIEs_t*)pRICsubscriptionResponse_IEs->value.choice.RICaction_NotAdmitted_List.list.array[index];
1547
1548                 // RICActionID
1549                 pRICSubscriptionResponse->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricActionID =
1550                   pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricActionID;
1551
1552                 //  RICcause
1553                 if (pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.present == RICcause_PR_radioNetwork) {
1554                     pRICSubscriptionResponse->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.content = RICcause_PR_radioNetwork;
1555                     pRICSubscriptionResponse->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.cause =
1556                       pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.radioNetwork;
1557                 }
1558                 else if (pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.present == RICcause_PR_transport) {
1559                     pRICSubscriptionResponse->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.content = RICcause_PR_transport;
1560                     pRICSubscriptionResponse->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.cause =
1561                       pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.transport;
1562                 }
1563                 else if (pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.present == RICcause_PR_protocol) {
1564                     pRICSubscriptionResponse->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.content = RICcause_PR_protocol;
1565                     pRICSubscriptionResponse->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.cause =
1566                       pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.protocol;
1567                 }
1568                 else if(pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.present == RICcause_PR_misc) {
1569                     pRICSubscriptionResponse->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.content = RICcause_PR_misc;
1570                     pRICSubscriptionResponse->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.cause =
1571                       pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.misc;
1572                 }
1573                 else if (pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.present == RICcause_PR_ric) {
1574                     pRICSubscriptionResponse->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.content = RICcause_PR_ric;
1575                     pRICSubscriptionResponse->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.cause =
1576                       pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.ric;
1577                 }
1578                index++;
1579             }
1580             pRICSubscriptionResponse->ricActionNotAdmittedList.contentLength = index;
1581         }
1582     }
1583     else {
1584         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1585         return e2err_RICsubscriptionResponseRICaction_NotAdmitted_ListMissing;
1586     }
1587
1588     ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1589     return e2err_OK;
1590 }
1591
1592 //////////////////////////////////////////////////////////////////////
1593 uint64_t getRICSubscriptionFailureData(e2ap_pdu_ptr_t* pE2AP_PDU_pointer, RICSubscriptionFailure_t* pRICSubscriptionFailure) {
1594
1595     E2AP_PDU_t* pE2AP_PDU = (E2AP_PDU_t*)pE2AP_PDU_pointer;
1596
1597     // RICrequestID
1598     RICsubscriptionFailure_IEs_t* pRICsubscriptionFailure_IEs;
1599     if (pE2AP_PDU->choice.unsuccessfulOutcome.value.choice.RICsubscriptionFailure.protocolIEs.list.count > 0) {
1600         pRICsubscriptionFailure_IEs = pE2AP_PDU->choice.unsuccessfulOutcome.value.choice.RICsubscriptionFailure.protocolIEs.list.array[0];
1601         pRICSubscriptionFailure->ricRequestID.ricRequestorID = pRICsubscriptionFailure_IEs->value.choice.RICrequestID.ricRequestorID;
1602         pRICSubscriptionFailure->ricRequestID.ricRequestSequenceNumber = pRICsubscriptionFailure_IEs->value.choice.RICrequestID.ricRequestSequenceNumber;
1603     }
1604     else {
1605         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1606         return e2err_RICsubscriptionFailureRICrequestIDMissing;
1607     }
1608
1609     // RANfunctionID
1610     if (pE2AP_PDU->choice.unsuccessfulOutcome.value.choice.RICsubscriptionFailure.protocolIEs.list.count > 1) {
1611         pRICsubscriptionFailure_IEs = pE2AP_PDU->choice.unsuccessfulOutcome.value.choice.RICsubscriptionFailure.protocolIEs.list.array[1];
1612         pRICSubscriptionFailure->ranFunctionID = pRICsubscriptionFailure_IEs->value.choice.RANfunctionID;
1613     }
1614     else {
1615         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1616         return e2err_RICsubscriptionFailureRANfunctionIDMissing;
1617     }
1618
1619     // RICaction-NotAdmitted-List
1620     if (pE2AP_PDU->choice.unsuccessfulOutcome.value.choice.RICsubscriptionFailure.protocolIEs.list.count > 2) {
1621         pRICsubscriptionFailure_IEs = pE2AP_PDU->choice.unsuccessfulOutcome.value.choice.RICsubscriptionFailure.protocolIEs.list.array[2];
1622         uint64_t index = 0;
1623         while ((index < maxofRICactionID) && (index < pRICsubscriptionFailure_IEs->value.choice.RICaction_NotAdmitted_List.list.count)) {
1624             RICaction_NotAdmitted_ItemIEs_t* pRICaction_NotAdmitted_ItemIEs =
1625               (RICaction_NotAdmitted_ItemIEs_t*)pRICsubscriptionFailure_IEs->value.choice.RICaction_NotAdmitted_List.list.array[index];
1626
1627             // RICActionID
1628             pRICSubscriptionFailure->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricActionID =
1629               pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricActionID;
1630
1631             //  RICcause
1632             if (pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.present == RICcause_PR_radioNetwork) {
1633                 pRICSubscriptionFailure->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.content = RICcause_PR_radioNetwork;
1634                 pRICSubscriptionFailure->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.cause =
1635                   pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.radioNetwork;
1636             }
1637             else if (pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.present == RICcause_PR_transport) {
1638                 pRICSubscriptionFailure->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.content = RICcause_PR_transport;
1639                 pRICSubscriptionFailure->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.cause =
1640                   pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.transport;
1641             }
1642             else if (pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.present == RICcause_PR_protocol) {
1643                 pRICSubscriptionFailure->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.content = RICcause_PR_protocol;
1644                 pRICSubscriptionFailure->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.cause =
1645                   pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.protocol;
1646             }
1647             else if(pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.present == RICcause_PR_misc) {
1648                 pRICSubscriptionFailure->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.content = RICcause_PR_misc;
1649                 pRICSubscriptionFailure->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.cause =
1650                   pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.misc;
1651             }
1652             else if (pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.present == RICcause_PR_ric) {
1653                 pRICSubscriptionFailure->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.content = RICcause_PR_ric;
1654                 pRICSubscriptionFailure->ricActionNotAdmittedList.RICActionNotAdmittedItem[index].ricCause.cause =
1655                   pRICaction_NotAdmitted_ItemIEs->value.choice.RICaction_NotAdmitted_Item.ricCause.choice.ric;
1656             }
1657             index++;
1658         }
1659         pRICSubscriptionFailure->ricActionNotAdmittedList.contentLength = index;
1660
1661         // CriticalityDiagnostics. OPTIONAL
1662
1663     }
1664     else {
1665         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1666         return e2err_RICsubscriptionFailureRICaction_NotAdmitted_ListMissing;
1667     }
1668
1669     ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1670     return e2err_OK;
1671 }
1672
1673 //////////////////////////////////////////////////////////////////////
1674 uint64_t getRICIndicationData(e2ap_pdu_ptr_t* pE2AP_PDU_pointer, RICIndication_t* pRICIndication) {
1675
1676     E2AP_PDU_t* pE2AP_PDU = (E2AP_PDU_t*)pE2AP_PDU_pointer;
1677
1678     // RICrequestID
1679     RICindication_IEs_t* pRICindication_IEs;
1680     if (pE2AP_PDU->choice.initiatingMessage.value.choice.RICindication.protocolIEs.list.count > 0) {
1681         pRICindication_IEs = pE2AP_PDU->choice.initiatingMessage.value.choice.RICindication.protocolIEs.list.array[0];
1682         pRICIndication->ricRequestID.ricRequestorID = pRICindication_IEs->value.choice.RICrequestID.ricRequestorID;
1683         pRICIndication->ricRequestID.ricRequestSequenceNumber = pRICindication_IEs->value.choice.RICrequestID.ricRequestSequenceNumber;
1684     }
1685     else {
1686         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1687         return e2err_RICindicationRICrequestIDMissing;
1688     }
1689
1690     // RANfunctionID
1691     if (pE2AP_PDU->choice.initiatingMessage.value.choice.RICindication.protocolIEs.list.count > 1) {
1692         pRICindication_IEs = pE2AP_PDU->choice.initiatingMessage.value.choice.RICindication.protocolIEs.list.array[1];
1693         pRICIndication->ranFunctionID = pRICindication_IEs->value.choice.RANfunctionID;
1694     }
1695     else {
1696         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1697         return e2err_RICindicationRANfunctionIDMissing;
1698     }
1699
1700     // RICactionID
1701     if (pE2AP_PDU->choice.initiatingMessage.value.choice.RICindication.protocolIEs.list.count > 2) {
1702         pRICindication_IEs = pE2AP_PDU->choice.initiatingMessage.value.choice.RICindication.protocolIEs.list.array[2];
1703         pRICIndication->ricActionID = pRICindication_IEs->value.choice.RICactionID;
1704     }
1705     else {
1706         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1707         return e2err_RICindicationRICactionIDMissing;
1708     }
1709
1710     // RICindicationSN
1711     if (pE2AP_PDU->choice.initiatingMessage.value.choice.RICindication.protocolIEs.list.count > 3) {
1712         pRICindication_IEs = pE2AP_PDU->choice.initiatingMessage.value.choice.RICindication.protocolIEs.list.array[3];
1713         pRICIndication->ricIndicationSN = pRICindication_IEs->value.choice.RICindicationSN;
1714     }
1715     else {
1716         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1717         return e2err_RICindicationRICindicationSNMissing;
1718     }
1719
1720     // RICindicationType
1721     if (pE2AP_PDU->choice.initiatingMessage.value.choice.RICindication.protocolIEs.list.count > 4) {
1722         pRICindication_IEs = pE2AP_PDU->choice.initiatingMessage.value.choice.RICindication.protocolIEs.list.array[4];
1723         pRICIndication->ricIndicationType = pRICindication_IEs->value.choice.RICindicationType;
1724     }
1725     else {
1726         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1727         return e2err_RICindicationRICindicationTypeMissing;
1728     }
1729
1730     // RICindicationHeader
1731     if (pE2AP_PDU->choice.initiatingMessage.value.choice.RICindication.protocolIEs.list.count > 5) {
1732         pRICindication_IEs = pE2AP_PDU->choice.initiatingMessage.value.choice.RICindication.protocolIEs.list.array[5];
1733
1734         pRICIndication->ricIndicationHeader.octetString.contentLength = pRICindication_IEs->value.choice.RICindicationHeader.size;
1735         if (pRICIndication->ricIndicationHeader.octetString.contentLength < cMaxSizeOfOctetString) {
1736             memcpy(pRICIndication->ricIndicationHeader.octetString.data, pRICindication_IEs->value.choice.RICindicationHeader.buf,
1737               pRICIndication->ricIndicationHeader.octetString.contentLength);
1738
1739               uint64_t returnCode;
1740               if ((returnCode = getRICIndicationHeaderData(&pRICIndication->ricIndicationHeader) != e2err_OK)) {
1741                 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1742                 return returnCode;
1743               }
1744         }
1745         else {
1746             ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1747             return e2err_RICIndicationHeaderContentLengthFail;
1748         }
1749     }
1750     else {
1751         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1752         return e2err_RICindicationRICindicationHeaderMissing;
1753     }
1754
1755     // RICindicationMessage
1756     if (pE2AP_PDU->choice.initiatingMessage.value.choice.RICindication.protocolIEs.list.count > 6) {
1757         pRICindication_IEs = pE2AP_PDU->choice.initiatingMessage.value.choice.RICindication.protocolIEs.list.array[6];
1758
1759         pRICIndication->ricIndicationMessage.octetString.contentLength = pRICindication_IEs->value.choice.RICindicationMessage.size;
1760         if (pRICIndication->ricIndicationMessage.octetString.contentLength < cMaxSizeOfOctetString) {
1761             memcpy(pRICIndication->ricIndicationMessage.octetString.data, pRICindication_IEs->value.choice.RICindicationMessage.buf,
1762               pRICIndication->ricIndicationMessage.octetString.contentLength);
1763
1764               uint64_t returnCode;
1765               if ((returnCode = getRICIndicationMessageData(&pRICIndication->ricIndicationMessage) != e2err_OK)) {
1766                 ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1767                 return returnCode;
1768               }
1769         }
1770         else {
1771             ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1772             return e2err_RICIndicationMessageContentLengthFail;
1773         }
1774     }
1775     else {
1776         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1777         return e2err_RICindicationRICindicationMessageMissing;
1778     }
1779
1780     // RICcallProcessID, OPTIONAL. Not used in RIC.
1781
1782     ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1783     return e2err_OK;
1784 }
1785
1786 //////////////////////////////////////////////////////////////////////
1787 uint64_t getRICIndicationHeaderData(RICIndicationHeader_t* pRICIndicationHeader) {
1788
1789     E2SM_gNB_X2_indicationHeader_t* pE2SM_gNB_X2_indicationHeader = 0;
1790     asn_dec_rval_t rval;
1791     rval = asn_decode(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_X2_indicationHeader, (void **)&pE2SM_gNB_X2_indicationHeader,
1792                       pRICIndicationHeader->octetString.data, pRICIndicationHeader->octetString.contentLength);
1793     switch(rval.code) {
1794     case RC_OK:
1795         // Debug print
1796         if (debug) {
1797             printf("\nSuccessfully decoded E2SM_gNB_X2_indicationHeader\n\n");
1798             asn_fprint(stdout, &asn_DEF_E2SM_gNB_X2_indicationHeader, pE2SM_gNB_X2_indicationHeader);
1799         }
1800
1801         // InterfaceID, GlobalENB-ID or GlobalGNB-ID
1802         if (pE2SM_gNB_X2_indicationHeader->interface_ID.present == Interface_ID_PR_global_eNB_ID) {
1803
1804             // GlobalENB-ID
1805             pRICIndicationHeader->interfaceID.globalENBIDPresent = true;
1806
1807             // PLMN-Identity
1808             pRICIndicationHeader->interfaceID.globalENBID.pLMNIdentity.contentLength =
1809               pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.pLMN_Identity.size;
1810             memcpy(pRICIndicationHeader->interfaceID.globalENBID.pLMNIdentity.pLMNIdentityVal,
1811               pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.pLMN_Identity.buf,
1812               pRICIndicationHeader->interfaceID.globalENBID.pLMNIdentity.contentLength);
1813
1814             //  ENB-ID
1815             IdOctects_t eNBOctects;
1816             memset(eNBOctects.octets, 0, sizeof(eNBOctects));
1817             if (pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.present == ENB_ID_PR_macro_eNB_ID) {
1818                 // BIT STRING (SIZE (20)
1819                 pRICIndicationHeader->interfaceID.globalENBID.nodeID.bits = cMacroENBIDP_20Bits;
1820                 memcpy(eNBOctects.octets,pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.choice.macro_eNB_ID.buf,
1821                   pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.choice.macro_eNB_ID.size);
1822                 pRICIndicationHeader->interfaceID.globalENBID.nodeID.nodeID = eNBOctects.nodeID;
1823             }
1824             else if (pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.present == ENB_ID_PR_home_eNB_ID) {
1825                 // BIT STRING (SIZE (28)
1826                 pRICIndicationHeader->interfaceID.globalENBID.nodeID.bits = cHomeENBID_28Bits;
1827                 memcpy(eNBOctects.octets,pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.choice.home_eNB_ID.buf,
1828                   pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.choice.home_eNB_ID.size);
1829                 pRICIndicationHeader->interfaceID.globalENBID.nodeID.nodeID = eNBOctects.nodeID;
1830             }
1831             else if (pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.present == ENB_ID_PR_short_Macro_eNB_ID) {
1832                 // BIT STRING (SIZE(18)
1833                 pRICIndicationHeader->interfaceID.globalENBID.nodeID.bits = cShortMacroENBID_18Bits;
1834                 memcpy(eNBOctects.octets,pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.choice.short_Macro_eNB_ID.buf,
1835                   pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.choice.short_Macro_eNB_ID.size);
1836                 pRICIndicationHeader->interfaceID.globalENBID.nodeID.nodeID = eNBOctects.nodeID;
1837             }
1838             else if (pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.present == ENB_ID_PR_long_Macro_eNB_ID) {
1839                 // BIT STRING (SIZE(21)
1840                 pRICIndicationHeader->interfaceID.globalENBID.nodeID.bits =  clongMacroENBIDP_21Bits;
1841                 memcpy(eNBOctects.octets,pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.choice.long_Macro_eNB_ID.buf,
1842                   pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.eNB_ID.choice.long_Macro_eNB_ID.size);
1843                 pRICIndicationHeader->interfaceID.globalENBID.nodeID.nodeID = eNBOctects.nodeID;
1844             }
1845             else {
1846                 pRICIndicationHeader->interfaceID.globalENBIDPresent = false;
1847                 pRICIndicationHeader->interfaceID.globalGNBIDPresent = false;
1848                 ASN_STRUCT_FREE(asn_DEF_E2SM_gNB_X2_indicationHeader, pE2SM_gNB_X2_indicationHeader);
1849                 return e2err_RICEventTriggerDefinitionIEValueFail_9;
1850             }
1851         }
1852         else if (pE2SM_gNB_X2_indicationHeader->interface_ID.present == Interface_ID_PR_global_gNB_ID) {
1853             // GlobalGNB-ID
1854             pRICIndicationHeader->interfaceID.globalGNBIDPresent = true;
1855
1856             // PLMN-Identity
1857             pRICIndicationHeader->interfaceID.globalGNBID.pLMNIdentity.contentLength =
1858               pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.pLMN_Identity.size;
1859             memcpy(pRICIndicationHeader->interfaceID.globalGNBID.pLMNIdentity.pLMNIdentityVal,
1860               pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_eNB_ID.pLMN_Identity.buf,
1861               pRICIndicationHeader->interfaceID.globalGNBID.pLMNIdentity.contentLength);
1862
1863             // GNB-ID
1864             IdOctects_t gNBOctects;
1865             memset(gNBOctects.octets, 0, sizeof(gNBOctects));
1866             if (pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_gNB_ID.gNB_ID.present == GNB_ID_PR_gNB_ID) {
1867                 pRICIndicationHeader->interfaceID.globalGNBID.nodeID.bits = pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_gNB_ID.gNB_ID.choice.gNB_ID.size;
1868                 memcpy(gNBOctects.octets, pE2SM_gNB_X2_indicationHeader->interface_ID.choice.global_gNB_ID.gNB_ID.choice.gNB_ID.buf,
1869                    pRICIndicationHeader->interfaceID.globalGNBID.nodeID.bits);
1870                 pRICIndicationHeader->interfaceID.globalGNBID.nodeID.nodeID = gNBOctects.nodeID;
1871             }
1872             else {
1873                 pRICIndicationHeader->interfaceID.globalENBIDPresent = false;
1874                 pRICIndicationHeader->interfaceID.globalGNBIDPresent = false;
1875                 ASN_STRUCT_FREE(asn_DEF_E2SM_gNB_X2_indicationHeader, pE2SM_gNB_X2_indicationHeader);
1876                 return e2err_RICEventTriggerDefinitionIEValueFail_10;
1877             }
1878         }
1879         else {
1880             pRICIndicationHeader->interfaceID.globalENBIDPresent = false;
1881             pRICIndicationHeader->interfaceID.globalGNBIDPresent = false;
1882             ASN_STRUCT_FREE(asn_DEF_E2SM_gNB_X2_indicationHeader, pE2SM_gNB_X2_indicationHeader);
1883             return e2err_RICEventTriggerDefinitionIEValueFail_11;
1884         }
1885
1886         // InterfaceDirection
1887         pRICIndicationHeader->interfaceDirection = pE2SM_gNB_X2_indicationHeader->interfaceDirection;
1888
1889         // TimeStamp OPTIONAL. Not used in RIC.
1890
1891         ASN_STRUCT_FREE(asn_DEF_E2SM_gNB_X2_indicationHeader, pE2SM_gNB_X2_indicationHeader);
1892         return e2err_OK;
1893     case RC_WMORE:
1894         if (debug)
1895             printf("\nDecode failed. More data needed. Buffer size %zu, %s, consumed %zu\n",pRICIndicationHeader->octetString.contentLength,
1896                    asn_DEF_E2SM_gNB_X2_indicationHeader.name, rval.consumed);
1897         return e2err_RICIndicationHeaderDecodeWMOREFail;
1898     case RC_FAIL:
1899         if (debug)
1900             printf("\nDecode failed. Buffer size %zu, %s, consumed %zu\n",pRICIndicationHeader->octetString.contentLength,
1901                    asn_DEF_E2SM_gNB_X2_indicationHeader.name, rval.consumed);
1902
1903         return e2err_RICIndicationHeaderDecodeFAIL;
1904     default:
1905         return e2err_RICIndicationHeaderDecodeDefaultFail;
1906     }
1907 }
1908
1909 //////////////////////////////////////////////////////////////////////
1910 uint64_t getRICIndicationMessageData(RICIndicationMessage_t* pRICIndicationMessage) {
1911
1912     E2SM_gNB_X2_indicationMessage_t* pE2SM_gNB_X2_indicationMessage = 0;
1913     asn_dec_rval_t rval;
1914     rval = asn_decode(0, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2SM_gNB_X2_indicationMessage, (void **)&pE2SM_gNB_X2_indicationMessage,
1915                       pRICIndicationMessage->octetString.data, pRICIndicationMessage->octetString.contentLength);
1916     switch(rval.code) {
1917     case RC_OK:
1918         // Debug print
1919         if (debug) {
1920             printf("\nSuccessfully decoded E2SM_gNB_X2_indicationMessage\n\n");
1921             asn_fprint(stdout, &asn_DEF_E2SM_gNB_X2_indicationMessage, pE2SM_gNB_X2_indicationMessage);
1922         }
1923
1924         // InterfaceMessage
1925         pRICIndicationMessage->interfaceMessage.contentLength = pE2SM_gNB_X2_indicationMessage->interfaceMessage.size;
1926         if(pRICIndicationMessage->octetString.contentLength < cMaxSizeOfOctetString) {
1927             memcpy(pRICIndicationMessage->interfaceMessage.data,pE2SM_gNB_X2_indicationMessage->interfaceMessage.buf,
1928               pRICIndicationMessage->interfaceMessage.contentLength);
1929             ASN_STRUCT_FREE(asn_DEF_E2SM_gNB_X2_indicationMessage, pE2SM_gNB_X2_indicationMessage);
1930             return e2err_OK;
1931         }
1932         else {
1933             ASN_STRUCT_FREE(asn_DEF_E2SM_gNB_X2_indicationMessage, pE2SM_gNB_X2_indicationMessage);
1934             return e2err_RICIndicationMessageIEContentLengthFail;
1935         }
1936     case RC_WMORE:
1937         if (debug)
1938             printf("\nDecode failed. More data needed. Buffer size %zu, %s, consumed %zu\n",pRICIndicationMessage->octetString.contentLength,
1939                    asn_DEF_E2SM_gNB_X2_indicationMessage.name, rval.consumed);
1940
1941         return e2err_RICIndicationMessageDecodeWMOREFail;
1942     case RC_FAIL:
1943         if (debug)
1944             printf("\nDecode failed. Buffer size %zu, %s, consumed %zu\n",pRICIndicationMessage->octetString.contentLength,
1945                    asn_DEF_E2SM_gNB_X2_indicationMessage.name, rval.consumed);
1946
1947         return e2err_RICIndicationMessageDecodeFAIL;
1948     default:
1949         return e2err_RICIndicationMessageDecodeDefaultFail;
1950     }
1951 }
1952
1953 //////////////////////////////////////////////////////////////////////
1954 uint64_t getRICSubscriptionDeleteRequestData(e2ap_pdu_ptr_t* pE2AP_PDU_pointer, RICSubscriptionDeleteRequest_t* pRICSubscriptionDeleteRequest) {
1955
1956     E2AP_PDU_t* pE2AP_PDU = (E2AP_PDU_t*)pE2AP_PDU_pointer;
1957
1958     // RICrequestID
1959     RICsubscriptionDeleteRequest_IEs_t* pRICsubscriptionDeleteRequest_IEs;
1960     if (pE2AP_PDU->choice.initiatingMessage.value.choice.RICsubscriptionDeleteRequest.protocolIEs.list.count > 0) {
1961         pRICsubscriptionDeleteRequest_IEs = pE2AP_PDU->choice.initiatingMessage.value.choice.RICsubscriptionDeleteRequest.protocolIEs.list.array[0];
1962         pRICSubscriptionDeleteRequest->ricRequestID.ricRequestorID = pRICsubscriptionDeleteRequest_IEs->value.choice.RICrequestID.ricRequestorID;
1963         pRICSubscriptionDeleteRequest->ricRequestID.ricRequestSequenceNumber = pRICsubscriptionDeleteRequest_IEs->value.choice.RICrequestID.ricRequestSequenceNumber;
1964     }
1965     else {
1966         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1967         return e2err_RICsubscriptionDeleteRequestRICrequestIDMissing;
1968     }
1969
1970     // RANfunctionID
1971     if (pE2AP_PDU->choice.initiatingMessage.value.choice.RICsubscriptionDeleteRequest.protocolIEs.list.count > 1) {
1972         pRICsubscriptionDeleteRequest_IEs = pE2AP_PDU->choice.initiatingMessage.value.choice.RICsubscriptionDeleteRequest.protocolIEs.list.array[1];
1973         pRICSubscriptionDeleteRequest->ranFunctionID = pRICsubscriptionDeleteRequest_IEs->value.choice.RANfunctionID;
1974     }
1975     else {
1976         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1977         return e2err_RICsubscriptionDeleteRequestRANfunctionIDMissing;
1978     }
1979
1980     ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1981     return e2err_OK;
1982 }
1983
1984 //////////////////////////////////////////////////////////////////////
1985 uint64_t getRICSubscriptionDeleteResponseData(e2ap_pdu_ptr_t* pE2AP_PDU_pointer, RICSubscriptionDeleteResponse_t* pRICSubscriptionDeleteResponse) {
1986
1987     E2AP_PDU_t* pE2AP_PDU = (E2AP_PDU_t*)pE2AP_PDU_pointer;
1988
1989     // RICrequestID
1990     RICsubscriptionDeleteResponse_IEs_t* pRICsubscriptionDeleteResponse_IEs;
1991     if (pE2AP_PDU->choice.successfulOutcome.value.choice.RICsubscriptionDeleteResponse.protocolIEs.list.count > 0) {
1992         pRICsubscriptionDeleteResponse_IEs = pE2AP_PDU->choice.successfulOutcome.value.choice.RICsubscriptionDeleteResponse.protocolIEs.list.array[0];
1993         pRICSubscriptionDeleteResponse->ricRequestID.ricRequestorID = pRICsubscriptionDeleteResponse_IEs->value.choice.RICrequestID.ricRequestorID;
1994         pRICSubscriptionDeleteResponse->ricRequestID.ricRequestSequenceNumber = pRICsubscriptionDeleteResponse_IEs->value.choice.RICrequestID.ricRequestSequenceNumber;
1995     }
1996     else {
1997         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
1998         return e2err_RICsubscriptionDeleteResponseRICrequestIDMissing;
1999     }
2000
2001     // RANfunctionID
2002     if (pE2AP_PDU->choice.successfulOutcome.value.choice.RICsubscriptionDeleteResponse.protocolIEs.list.count > 1) {
2003         pRICsubscriptionDeleteResponse_IEs = pE2AP_PDU->choice.successfulOutcome.value.choice.RICsubscriptionDeleteResponse.protocolIEs.list.array[1];
2004         pRICSubscriptionDeleteResponse->ranFunctionID = pRICsubscriptionDeleteResponse_IEs->value.choice.RANfunctionID;
2005     }
2006     else {
2007         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
2008         return e2err_RICsubscriptionDeleteResponseRANfunctionIDMissing;
2009     }
2010
2011     ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
2012     return e2err_OK;
2013 }
2014
2015 //////////////////////////////////////////////////////////////////////
2016 uint64_t getRICSubscriptionDeleteFailureData(e2ap_pdu_ptr_t* pE2AP_PDU_pointer, RICSubscriptionDeleteFailure_t* pRICSubscriptionDeleteFailure) {
2017
2018     E2AP_PDU_t* pE2AP_PDU = (E2AP_PDU_t*)pE2AP_PDU_pointer;
2019
2020     // RICrequestID
2021     RICsubscriptionDeleteFailure_IEs_t* pRICsubscriptionDeleteFailure_IEs;
2022     if (pE2AP_PDU->choice.unsuccessfulOutcome.value.choice.RICsubscriptionDeleteFailure.protocolIEs.list.count > 0) {
2023         pRICsubscriptionDeleteFailure_IEs = pE2AP_PDU->choice.unsuccessfulOutcome.value.choice.RICsubscriptionDeleteFailure.protocolIEs.list.array[0];
2024         pRICSubscriptionDeleteFailure->ricRequestID.ricRequestorID = pRICsubscriptionDeleteFailure_IEs->value.choice.RICrequestID.ricRequestorID;
2025         pRICSubscriptionDeleteFailure->ricRequestID.ricRequestSequenceNumber = pRICsubscriptionDeleteFailure_IEs->value.choice.RICrequestID.ricRequestSequenceNumber;
2026     }
2027     else {
2028         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
2029         return e2err_RICsubscriptionDeleteFailureRICrequestIDMissing;
2030     }
2031
2032     // RANfunctionID
2033     if (pE2AP_PDU->choice.unsuccessfulOutcome.value.choice.RICsubscriptionDeleteFailure.protocolIEs.list.count > 1) {
2034         pRICsubscriptionDeleteFailure_IEs = pE2AP_PDU->choice.unsuccessfulOutcome.value.choice.RICsubscriptionDeleteFailure.protocolIEs.list.array[1];
2035         pRICSubscriptionDeleteFailure->ranFunctionID = pRICsubscriptionDeleteFailure_IEs->value.choice.RANfunctionID;
2036     }
2037     else {
2038         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
2039         return e2err_RICsubscriptionDeleteFailureRANfunctionIDMissing;
2040     }
2041
2042     // RICcause
2043     if (pE2AP_PDU->choice.unsuccessfulOutcome.value.choice.RICsubscriptionDeleteFailure.protocolIEs.list.count > 2) {
2044         pRICsubscriptionDeleteFailure_IEs = pE2AP_PDU->choice.unsuccessfulOutcome.value.choice.RICsubscriptionDeleteFailure.protocolIEs.list.array[2];
2045         if (pRICsubscriptionDeleteFailure_IEs->value.choice.RICcause.present == RICcause_PR_radioNetwork) {
2046             pRICSubscriptionDeleteFailure->ricCause.content = RICcause_PR_radioNetwork;
2047             pRICSubscriptionDeleteFailure->ricCause.cause =
2048               pRICsubscriptionDeleteFailure_IEs->value.choice.RICcause.choice.radioNetwork;
2049         }
2050         else if (pRICsubscriptionDeleteFailure_IEs->value.choice.RICcause.present == RICcause_PR_transport) {
2051             pRICSubscriptionDeleteFailure->ricCause.content = RICcause_PR_transport;
2052             pRICSubscriptionDeleteFailure->ricCause.cause =
2053               pRICsubscriptionDeleteFailure_IEs->value.choice.RICcause.choice.transport;
2054         }
2055         else if (pRICsubscriptionDeleteFailure_IEs->value.choice.RICcause.present == RICcause_PR_protocol) {
2056             pRICSubscriptionDeleteFailure->ricCause.content = RICcause_PR_protocol;
2057             pRICSubscriptionDeleteFailure->ricCause.cause =
2058               pRICsubscriptionDeleteFailure_IEs->value.choice.RICcause.choice.protocol;
2059         }
2060         else if(pRICsubscriptionDeleteFailure_IEs->value.choice.RICcause.present == RICcause_PR_misc) {
2061             pRICSubscriptionDeleteFailure->ricCause.content = RICcause_PR_misc;
2062             pRICSubscriptionDeleteFailure->ricCause.cause =
2063               pRICsubscriptionDeleteFailure_IEs->value.choice.RICcause.choice.misc;
2064         }
2065         else if (pRICsubscriptionDeleteFailure_IEs->value.choice.RICcause.present == RICcause_PR_ric) {
2066             pRICSubscriptionDeleteFailure->ricCause.content = RICcause_PR_ric;
2067             pRICSubscriptionDeleteFailure->ricCause.cause =
2068               pRICsubscriptionDeleteFailure_IEs->value.choice.RICcause.choice.ric;
2069         }
2070     }
2071     else {
2072         ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
2073         return e2err_RICsubscriptionDeleteFailureRICcauseMissing;
2074     }
2075     // CriticalityDiagnostics, OPTIONAL
2076
2077     ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pE2AP_PDU);
2078     return e2err_OK;
2079 }