memory leak issues fixed
[ric-app/rc.git] / e2sm / wrapper.c
1 #include <errno.h>
2 #include "wrapper.h"
3 #include "OCTET_STRING.h"
4
5 ssize_t e2sm_encode_ric_control_header(void *buffer, size_t buf_size,struct uEID *inUEID,long f1AP[],size_t f1AP_len,long e1AP[],size_t e1Ap_len,long ricControlStyleType, long ricControlActionID, void* plmnId, size_t  plmnIdSize)
6 {
7         fprintf(stderr,"e2SM wrapper function Entered\n");      
8         fprintf(stderr,"plmn Size = %ld and aMFRegionID Size = %ld and aMFSetID_size = %ld and aMFPointer_size = %ld \n", inUEID->pLMNIdentity_size,inUEID->aMFRegionID_size,inUEID->aMFSetID_size,inUEID->aMFPointer_size);
9
10         E2SM_RC_ControlHeader_t *controlHeaderIE = (E2SM_RC_ControlHeader_t *)calloc(1, sizeof(E2SM_RC_ControlHeader_t));
11         if(!controlHeaderIE)
12         {
13                 fprintf(stderr, "alloc E2SM_RC_ControlHeader failed\n");
14                    return -1;
15         }
16
17         controlHeaderIE->ric_controlHeader_formats.present = E2SM_RC_ControlHeader__ric_controlHeader_formats_PR_controlHeader_Format1;
18         //E2SM_RC_ControlHeader_Format1_t  *controlHeader_Fmt1 = (E2SM_RC_ControlHeader_Format1_t *)calloc(1, sizeof(E2SM_RC_ControlHeader_Format1_t));
19         E2SM_RC_ControlHeader_Format1_t  *controlHeader_Fmt1 = NULL;
20         controlHeaderIE->ric_controlHeader_formats.choice.controlHeader_Format1 = (E2SM_RC_ControlHeader_Format1_t *)calloc(1, sizeof(E2SM_RC_ControlHeader_Format1_t));
21         controlHeader_Fmt1 = controlHeaderIE->ric_controlHeader_formats.choice.controlHeader_Format1;
22         if(!controlHeader_Fmt1)
23         {
24                 fprintf(stderr, "alloc E2SM_RC_ControlHeader failed\n");
25                 ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlHeader, controlHeaderIE);
26                 return -1;
27         }
28        
29         controlHeader_Fmt1->ueID.present = UEID_PR_gNB_UEID;
30         controlHeader_Fmt1->ueID.choice.gNB_UEID = (UEID_GNB_t *)calloc(1,sizeof(UEID_GNB_t));
31         if(! controlHeader_Fmt1->ueID.choice.gNB_UEID)
32         {
33                 ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlHeader, controlHeaderIE);
34                 fprintf(stderr, "alloc gNB_UEID failed\n");
35                 return -1;
36         }
37
38         asn_long2INTEGER(&controlHeader_Fmt1->ueID.choice.gNB_UEID->amf_UE_NGAP_ID,inUEID->amf_UE_NGAP_Id);
39
40         fprintf(stderr, "e2sm_encode_ric_control_header amf_UE_NGAP_ID encoded \n");
41         
42         //OCTET_STRING_fromBuf(&controlHeader_Fmt1->ueID.choice.gNB_UEID->guami.pLMNIdentity,inUEID->pLMNIdentity, inUEID->pLMNIdentity_size);
43
44         OCTET_STRING_fromBuf(&controlHeader_Fmt1->ueID.choice.gNB_UEID->guami.pLMNIdentity, plmnId,plmnIdSize);
45         fprintf(stderr, "e2smrc_encode_ric_control_header pLMNIdentity encoded \n");
46
47         controlHeader_Fmt1->ueID.choice.gNB_UEID->guami.aMFRegionID.buf = (uint8_t*)calloc(1,inUEID->aMFRegionID_size);
48         if(!controlHeader_Fmt1->ueID.choice.gNB_UEID->guami.aMFRegionID.buf)
49         {
50                 ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlHeader, controlHeaderIE);
51                 fprintf(stderr, "alloc aMFRegionID Value failed\n");
52                 return -1;
53         }
54         controlHeader_Fmt1->ueID.choice.gNB_UEID->guami.aMFRegionID.size = inUEID->aMFRegionID_size;
55         //controlHeader_Fmt1->ueID.choice.gNB_UEID->guami.aMFRegionID.buf[0] = inUEID->aMFRegionID && 0XFF;
56         //controlHeader_Fmt1->ueID.choice.gNB_UEID->guami.aMFRegionID.buf[0] = *(inUEID->aMFRegionID ) & 0XFF;
57         memcpy(controlHeader_Fmt1->ueID.choice.gNB_UEID->guami.aMFRegionID.buf,inUEID->aMFRegionID,inUEID->aMFRegionID_size);
58
59         controlHeader_Fmt1->ueID.choice.gNB_UEID->guami.aMFSetID.buf = (uint8_t*)calloc(1, inUEID->aMFSetID_size);
60         if(!controlHeader_Fmt1->ueID.choice.gNB_UEID->guami.aMFSetID.buf)
61         {
62                 ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlHeader, controlHeaderIE);
63                 fprintf(stderr, "alloc aMFSetID Value failed\n");
64                 return -1;
65         }
66         controlHeader_Fmt1->ueID.choice.gNB_UEID->guami.aMFSetID.size = inUEID->aMFSetID_size;
67         //controlHeader_Fmt1->ueID.choice.gNB_UEID->guami.aMFSetID.buf[0] = (inUEID->aMFSetID && 0xFF00) >> 8;
68         //controlHeader_Fmt1->ueID.choice.gNB_UEID->guami.aMFSetID.buf[1] = inUEID->aMFSetID && 0XFF00 && 0X00FF;
69         controlHeader_Fmt1->ueID.choice.gNB_UEID->guami.aMFSetID.buf[0] = (*(inUEID->aMFSetID) & 0xFFC0) >> 8;
70         controlHeader_Fmt1->ueID.choice.gNB_UEID->guami.aMFSetID.bits_unused = 6;
71
72
73         controlHeader_Fmt1->ueID.choice.gNB_UEID->guami.aMFPointer.buf = (uint8_t*)calloc(1, inUEID->aMFPointer_size);
74         if(!controlHeader_Fmt1->ueID.choice.gNB_UEID->guami.aMFPointer.buf)
75         {
76                 ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlHeader, controlHeaderIE);
77                 fprintf(stderr, "alloc aMFPointer Value failed\n");
78                 return -1;
79         }
80
81         controlHeader_Fmt1->ueID.choice.gNB_UEID->guami.aMFPointer.size = inUEID->aMFPointer_size;
82         //controlHeader_Fmt1->ueID.choice.gNB_UEID->guami.aMFPointer.buf[0] = inUEID->aMFPointer && 0XFF;
83         controlHeader_Fmt1->ueID.choice.gNB_UEID->guami.aMFPointer.buf[0] = (*(inUEID->aMFPointer) & 0xFC) >> 2;
84         controlHeader_Fmt1->ueID.choice.gNB_UEID->guami.aMFPointer.bits_unused = 2;
85
86
87         controlHeader_Fmt1->ueID.choice.gNB_UEID->gNB_CU_UE_F1AP_ID_List = (UEID_GNB_CU_F1AP_ID_List_t *)calloc(1,sizeof(UEID_GNB_CU_F1AP_ID_List_t));
88         if(! controlHeader_Fmt1->ueID.choice.gNB_UEID->gNB_CU_UE_F1AP_ID_List)
89         {
90                 fprintf(stderr, "alloc gNB_CU_CP_UE_E1AP_ID_list failed\n");
91                 ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlHeader, controlHeaderIE);
92                 return -1;
93         }
94         //f1AP is an array of data
95         //int n = sizeof(f1AP)/sizeof(long int);
96
97         for(int i =0; i < f1AP_len; i++)
98         {
99                 UEID_GNB_CU_CP_F1AP_ID_Item_t *F1AP_ID_Item = (UEID_GNB_CU_CP_F1AP_ID_Item_t *)calloc (1, sizeof(UEID_GNB_CU_CP_F1AP_ID_Item_t ));
100                 if(! F1AP_ID_Item)
101                 {
102                         fprintf(stderr, "alloc UEID_GNB_CU_CP_F1AP_ID_Item failed\n");
103                         ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlHeader, controlHeaderIE);
104                         return -1;
105                 } 
106                 F1AP_ID_Item->gNB_CU_UE_F1AP_ID  = f1AP[i];
107                 fprintf(stderr, "F1AP_id %d =%lu\n",i,*((unsigned long *) F1AP_id +i ));
108                 ASN_SEQUENCE_ADD(&controlHeader_Fmt1->ueID.choice.gNB_UEID->gNB_CU_UE_F1AP_ID_List->list,F1AP_ID_Item);
109         }
110         //F1AP_ID_Item->gNB_CU_UE_F1AP_ID  = f1AP[0];
111         //ASN_SEQUENCE_ADD(&controlHeader_Fmt1->ueID.choice.gNB_UEID->gNB_CU_UE_F1AP_ID_List->list,F1AP_ID_Item);
112
113         
114         controlHeader_Fmt1->ueID.choice.gNB_UEID->gNB_CU_CP_UE_E1AP_ID_List = (UEID_GNB_CU_CP_E1AP_ID_List_t *)calloc(1,sizeof(UEID_GNB_CU_CP_E1AP_ID_List_t));
115
116         if(! controlHeader_Fmt1->ueID.choice.gNB_UEID->gNB_CU_CP_UE_E1AP_ID_List)
117         {
118                 fprintf(stderr, "alloc gNB_CU_CP_UE_E1AP_ID_list failed\n");
119                 ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlHeader, controlHeaderIE);
120                 return -1;
121         }
122
123         
124         //n = sizeof(e1AP)/sizeof(long int);
125         for(int i =0; i < e1Ap_len; i++)
126         {
127                 UEID_GNB_CU_CP_E1AP_ID_Item_t *E1AP_ID_Item = (UEID_GNB_CU_CP_E1AP_ID_Item_t *)calloc (1, sizeof(UEID_GNB_CU_CP_E1AP_ID_Item_t ));
128                 if(! E1AP_ID_Item)
129                 {
130                         fprintf(stderr, "alloc UEID_GNB_CU_CP_E1AP_ID_Item failed\n");
131                         ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlHeader, controlHeaderIE);
132                         return -1;
133
134                 }
135                 E1AP_ID_Item->gNB_CU_CP_UE_E1AP_ID = e1AP[i];
136                 ASN_SEQUENCE_ADD(&controlHeader_Fmt1->ueID.choice.gNB_UEID->gNB_CU_CP_UE_E1AP_ID_List->list,E1AP_ID_Item);
137         //E1AP_ID_Item->gNB_CU_CP_UE_E1AP_ID = (*(unsigned long *) E1AP_id) ;
138         //ASN_SEQUENCE_ADD(&controlHeader_Fmt1->ueID.choice.gNB_UEID->gNB_CU_CP_UE_E1AP_ID_List->list,E1AP_ID_Item);
139         }
140         
141
142         controlHeader_Fmt1->ric_Style_Type = ricControlStyleType;
143         controlHeader_Fmt1->ric_ControlAction_ID = ricControlActionID;
144
145         controlHeaderIE->ric_controlHeader_formats.choice.controlHeader_Format1 = controlHeader_Fmt1;
146
147
148         fprintf(stderr, "showing xer of asn_DEF_E2SM_RC_ControlHeader data\n");
149         xer_fprint(stderr, &asn_DEF_E2SM_RC_ControlHeader, controlHeaderIE);
150         fprintf(stderr, "\n");
151         fprintf(stderr, "After xer of asn_DEF_E2SM_RC_ControlHeader data\n");
152    
153         asn_enc_rval_t encode_result;
154         encode_result = aper_encode_to_buffer(&asn_DEF_E2SM_RC_ControlHeader, NULL, controlHeaderIE, buffer, buf_size);
155
156
157         ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlHeader, controlHeaderIE);
158         if(encode_result.encoded == -1)
159         {
160                 fprintf(stderr, "Cannot encode %s: %s\n", encode_result.failed_type->name, strerror(errno));
161                 return -1;
162         }
163         else
164         {
165                return encode_result.encoded;
166         }
167 }
168
169 ssize_t e2sm_encode_nrcgi(NR_CGI_t *nr_cgi, void* plmnIdValue, size_t  plmnId_size,ulong lNRCellId, uint8_t* buffer, size_t buf_size)
170 {
171         nr_cgi = (NR_CGI_t*)calloc(1, sizeof(NR_CGI_t));
172         if(!nr_cgi) {
173                 fprintf(stderr, "e2src_encode_nrcgi alloc nr_cgi failed \n");
174                 return -1;
175         }
176         OCTET_STRING_fromBuf(&nr_cgi->pLMNIdentity,plmnIdValue, plmnId_size);
177         //fprintf(stderr, "encodec Plmn Id = %s  plmnIdValue %s and lNRCellId = %lu \n", nr_cgi->pLMNIdentity, plmnIdValue,lNRCellId);
178         //fprintf(stderr, "encodec Plmn Id = %s  and lNRCellId = %d \n", nr_cgi->pLMNIdentity,plmnIdValue,lNRCellId);
179         BIT_STRING_t *nr_cell_id = &nr_cgi->nRCellIdentity ; 
180                nr_cell_id->buf = (uint8_t*)calloc(1,5);
181                if(nr_cell_id->buf)
182                {
183                    nr_cell_id->size = 5;
184                    nr_cell_id->buf[0] = ((lNRCellId & 0X0FF0000000) >> 28);
185                    nr_cell_id->buf[1] = ((lNRCellId & 0X000FF00000) >> 20);
186                    nr_cell_id->buf[2] = ((lNRCellId & 0X00000FF000) >> 12);
187                    nr_cell_id->buf[3] = ((lNRCellId & 0X0000000FF0) >> 4);
188                    nr_cell_id->buf[4] = (lNRCellId & 0X000000000F) << 4;
189                    nr_cell_id->bits_unused = 4;
190
191                }
192
193           fprintf(stderr, "showing xer of asn_DEF_NR_CGI NR_CGI_t data\n");
194           xer_fprint(stderr, &asn_DEF_NR_CGI, nr_cgi);
195
196            asn_enc_rval_t encode_result = aper_encode_to_buffer(&asn_DEF_NR_CGI, NULL, nr_cgi, buffer, buf_size);
197
198            if(encode_result.encoded != -1)
199            {
200                fprintf(stderr, "nr_cgi encodedi length = %zd \n", encode_result.encoded) ;
201                return encode_result.encoded;
202            }
203            else
204            {
205                fprintf(stderr, "nr_cgi encode failed =%zd \n", encode_result.encoded) ;
206                return -1 ;
207            }
208 }
209
210 ssize_t e2sm_encode_ric_control_message(void *buffer, size_t buf_size, long targetPrimaryCell,
211                         long targetCell, long nrOrEUtraCell, long nrCGIOrECGI, void* ranParameterValue, size_t  ranParameterValue_size)
212 {
213         fprintf(stderr, "e2sm_encode_ric_control_message \n") ;
214         //NR_CGI_t *nr_cgi = NULL;
215         //uint8_t nrcgiBuf[buf_size];
216         //ssize_t nrcgiBuf_size,nrcgiLen;
217
218
219         E2SM_RC_ControlMessage_t *e2smrcRcControlMsg = (E2SM_RC_ControlMessage_t*)calloc(1, sizeof(E2SM_RC_ControlMessage_t));
220         if(!e2smrcRcControlMsg) {
221             fprintf(stderr, "alloc E2SM_ControlMessage_t failed\n");
222         return -1;
223         }
224          e2smrcRcControlMsg->ric_controlMessage_formats.present = E2SM_RC_ControlMessage__ric_controlMessage_formats_PR_controlMessage_Format1;
225
226         E2SM_RC_ControlMessage_Format1_t *e2smrcRcControlFormat1 = (E2SM_RC_ControlMessage_Format1_t*)calloc(1, sizeof(E2SM_RC_ControlMessage_Format1_t));
227         if(!e2smrcRcControlFormat1) {
228                 ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smrcRcControlMsg);
229                 fprintf(stderr, "alloc E2SM_ControlMessage_Format1_t failed\n");
230                 return -1;
231         }
232         // Start Target Primary Cell
233         E2SM_RC_ControlMessage_Format1_Item_t *ranParameterItem1 = (E2SM_RC_ControlMessage_Format1_Item_t *) calloc(1,sizeof(
234                                                                                 E2SM_RC_ControlMessage_Format1_Item_t));
235         if(!ranParameterItem1) {
236                 fprintf(stderr, "alloc RANParameter_Item_t1 failed\n");
237                 ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smrcRcControlMsg);
238                 return -1;
239         }
240
241         ranParameterItem1->ranParameter_ID = targetPrimaryCell;     // Target Primary Cell ID value = 1
242         ranParameterItem1->ranParameter_valueType.present = RANParameter_ValueType_PR_ranP_Choice_Structure;
243
244         RANParameter_ValueType_Choice_Structure_t *ranParameterStructure1 = (RANParameter_ValueType_Choice_Structure_t*)calloc(1, sizeof(RANParameter_ValueType_Choice_Structure_t));
245         if(!ranParameterStructure1)
246         {
247                 fprintf(stderr, "alloc RANParameter_STRUCTURE_t1 failed\n");
248                 ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smrcRcControlMsg);
249                 return -1;
250         }
251
252         fprintf(stderr, "targetPrimaryCell encoded \n");
253
254          // Start Target Cell
255         RANParameter_STRUCTURE_Item_t *ranParameterItem2 = (RANParameter_STRUCTURE_Item_t *)calloc(1,sizeof(RANParameter_STRUCTURE_Item_t));
256
257         if(!ranParameterItem2)
258         {
259
260                 ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smrcRcControlMsg);
261                 fprintf(stderr, "alloc RANParameter_Item_t2 failed\n");
262                 return -1;
263         }
264
265         ranParameterItem2->ranParameter_ID = targetCell;    // Target Cell ID value = 2
266
267         RANParameter_ValueType_Choice_Structure_t *ranParameterStructure2 = (RANParameter_ValueType_Choice_Structure_t*)calloc(1, sizeof(struct RANParameter_ValueType_Choice_Structure));
268         if(!ranParameterStructure2)
269         {
270                 ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smrcRcControlMsg);
271                 fprintf(stderr, "alloc RANParameter_STRUCTURE_t2 failed\n");
272                 return -1;
273         }
274
275         fprintf(stderr, "targetPrimaryCellId Value encoded \n");
276
277         // Start NR Cell  (or E-UTRA Cell)
278          RANParameter_STRUCTURE_Item_t *ranParameterItem3 = (RANParameter_STRUCTURE_Item_t*)calloc(1,sizeof(RANParameter_STRUCTURE_Item_t));
279         if(!ranParameterItem3)
280         {
281                 ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smrcRcControlMsg);
282                 fprintf(stderr, "alloc RANParameter_Item_t3 failed\n");
283                 return -1;
284         }
285
286         ranParameterItem3->ranParameter_ID = nrOrEUtraCell; // NR Cell ID (or E-UTRA Cell ID) value =
287
288         RANParameter_ValueType_Choice_Structure_t *ranParameterStructure3 = (struct RANParameter_ValueType_Choice_Structure*)calloc(1, sizeof(struct RANParameter_ValueType_Choice_Structure));
289         if(!ranParameterStructure3)
290         {
291                 ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smrcRcControlMsg);
292                 fprintf(stderr, "alloc RANParameter_Item_t3 failed\n");
293                 return -1;
294         }
295         fprintf(stderr, " NR Cell ID  Value encoded \n");
296
297         // Start NR CGI (or ECGI)
298         RANParameter_STRUCTURE_Item_t *ranParameterItem4 = (RANParameter_STRUCTURE_Item_t *) calloc(1,sizeof(
299                                                                         RANParameter_STRUCTURE_Item_t));
300         if(!ranParameterItem4)
301         {
302                 ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smrcRcControlMsg);
303                 fprintf(stderr, "alloc RANParameter_Item_t4 failed\n");
304                 return -1;
305         }
306
307         ranParameterItem4->ranParameter_ID = nrCGIOrECGI;   // NR CGI ID (or ECGI ID) value =
308
309         ranParameterItem4->ranParameter_valueType = (RANParameter_ValueType_t*)calloc(1,sizeof(RANParameter_ValueType_t));
310         if(!ranParameterItem4->ranParameter_valueType)
311         {
312                 ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smrcRcControlMsg);
313                 fprintf(stderr, "alloc ranParameterItem4->ranParameter_valueType failed\n");
314                 return -1;
315         }
316
317         ranParameterItem4->ranParameter_valueType->present = RANParameter_ValueType_PR_ranP_Choice_ElementFalse;
318         ranParameterItem4->ranParameter_valueType->choice.ranP_Choice_ElementFalse = (RANParameter_ValueType_Choice_ElementFalse_t *)calloc(1, sizeof(RANParameter_ValueType_Choice_ElementFalse_t));
319         if(!ranParameterItem4->ranParameter_valueType->choice.ranP_Choice_ElementFalse)
320         {
321                 ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smrcRcControlMsg);
322                 fprintf(stderr, "alloc RANParameter_Item_t4 failed\n");
323                 return -1;
324         }
325
326         ranParameterItem4->ranParameter_valueType->choice.ranP_Choice_ElementFalse->ranParameter_value = (RANParameter_Value_t *)calloc(1, sizeof(RANParameter_Value_t));
327         if(!ranParameterItem4->ranParameter_valueType->choice.ranP_Choice_ElementFalse->ranParameter_value)
328         {
329                 ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smrcRcControlMsg);
330                 fprintf(stderr, "alloc ranParameter_value failed\n");
331                 return -1;
332         }
333         ranParameterItem4->ranParameter_valueType->choice.ranP_Choice_ElementFalse->ranParameter_value->present = RANParameter_Value_PR_valueOctS;
334         OCTET_STRING_fromBuf(&ranParameterItem4->ranParameter_valueType->choice.ranP_Choice_ElementFalse->ranParameter_value->choice.valueOctS,ranParameterValue, ranParameterValue_size);
335
336         /*
337         fprintf(stderr, "Target Plmn Id = %s ranParameterValue and lNRCellId = %lu \n", ranParameterValue,lNRCellId);
338         nrcgiLen = e2sm_encode_nrcgi(nr_cgi, ranParameterValue, ranParameterValue_size, lNRCellId,nrcgiBuf,nrcgiBuf_size);
339         if(nrcgiLen == -1 )
340         {
341                  fprintf(stderr,"e2srmc_encode_nrcgi failed \n");
342                 return nrcgiLen;
343         }
344         OCTET_STRING_fromBuf(&ranParameterItem4->ranParameter_valueType->choice.ranP_Choice_ElementFalse->ranParameter_value->choice.valueOctS,nrcgiBuf,nrcgiLen);
345         */
346         fprintf(stderr, " NR CGI encoded \n");
347
348         ranParameterStructure3->ranParameter_Structure = (RANParameter_STRUCTURE_t*)calloc(1,sizeof(RANParameter_STRUCTURE_t));
349         if(!ranParameterStructure3->ranParameter_Structure)
350         {
351                 ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smrcRcControlMsg);
352                 fprintf(stderr, "alloc ranParameterStructure3->ranParameter_Structure  failed\n");
353                 return -1;
354         }
355
356         ranParameterStructure3->ranParameter_Structure->sequence_of_ranParameters = (struct RANParameter_STRUCTURE__sequence_of_ranParameters*)calloc(1,sizeof(struct RANParameter_STRUCTURE__sequence_of_ranParameters));
357         if(!ranParameterStructure3->ranParameter_Structure->sequence_of_ranParameters)
358         {
359                 ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smrcRcControlMsg);
360                 fprintf(stderr, "alloc ranParameterStructure3->ranParameter_Structure->sequence_of_ranParameters failed\n");
361                 return -1;
362         }
363
364
365
366         ASN_SEQUENCE_ADD(&ranParameterStructure3->ranParameter_Structure->sequence_of_ranParameters->list, ranParameterItem4);   // NR CGI (or ECGI)
367         ranParameterItem3->ranParameter_valueType = (RANParameter_ValueType_t*)calloc(1,sizeof(RANParameter_ValueType_t));
368         if(!ranParameterItem3->ranParameter_valueType)
369         {
370                 ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smrcRcControlMsg);
371                 fprintf(stderr, "alloc ranParameterItem3->ranParameter_valueType failed\n");
372                 return -1;
373         }
374         ranParameterItem3->ranParameter_valueType->present = RANParameter_ValueType_PR_ranP_Choice_Structure;
375         ranParameterItem3->ranParameter_valueType->choice.ranP_Choice_Structure = ranParameterStructure3; // NR Cell  (or E-UTRA Cell)
376         fprintf(stderr, " ranParameterStructure3 encoded \n");
377
378         ranParameterStructure2->ranParameter_Structure = (RANParameter_STRUCTURE_t*)calloc(1,sizeof(RANParameter_STRUCTURE_t));
379         if(!ranParameterStructure2->ranParameter_Structure)
380         {
381                 ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smrcRcControlMsg);
382                 fprintf(stderr, "alloc ranParameterStructure2->ranParameter_Structure  failed\n");
383                 return -1;
384         }
385
386         ranParameterStructure2->ranParameter_Structure->sequence_of_ranParameters = (struct RANParameter_STRUCTURE__sequence_of_ranParameters*)calloc(1,sizeof(struct RANParameter_STRUCTURE__sequence_of_ranParameters));
387         if(!ranParameterStructure2->ranParameter_Structure->sequence_of_ranParameters)
388         {
389                 ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smrcRcControlMsg);
390                 fprintf(stderr, "alloc ranParameterStructure3->ranParameter_Structure->sequence_of_ranParameters failed\n");
391                 return -1;
392         }
393
394         ASN_SEQUENCE_ADD(&ranParameterStructure2->ranParameter_Structure->sequence_of_ranParameters->list, ranParameterItem3);   // NR Cell  (or E-UTRA Cell)
395         ranParameterItem2->ranParameter_valueType = (RANParameter_ValueType_t*)calloc(1,sizeof(RANParameter_ValueType_t));
396         if(!ranParameterItem2->ranParameter_valueType)
397         {
398                 ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smrcRcControlMsg);
399                 fprintf(stderr, "alloc ranParameterItem2->ranParameter_valueType failed\n");
400                 return -1;
401         }
402         ranParameterItem2->ranParameter_valueType->present = RANParameter_ValueType_PR_ranP_Choice_Structure;
403         ranParameterItem2->ranParameter_valueType->choice.ranP_Choice_Structure = ranParameterStructure2; // Target Cell
404         fprintf(stderr, " ranParameterStructure2 encoded \n");
405
406         ranParameterStructure1->ranParameter_Structure = (RANParameter_STRUCTURE_t*)calloc(1,sizeof(RANParameter_STRUCTURE_t));
407         if(!ranParameterStructure1->ranParameter_Structure)
408         {
409                 ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smrcRcControlMsg);
410                 fprintf(stderr, "alloc ranParameterStructure1->ranParameter_Structure  failed\n");
411                 return -1;
412         }
413
414         ranParameterStructure1->ranParameter_Structure->sequence_of_ranParameters = (struct RANParameter_STRUCTURE__sequence_of_ranParameters*)calloc(1,sizeof(struct RANParameter_STRUCTURE__sequence_of_ranParameters));
415         if(!ranParameterStructure1->ranParameter_Structure->sequence_of_ranParameters)
416         {
417                 ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smrcRcControlMsg);
418                 fprintf(stderr, "alloc ranParameterStructure1->ranParameter_Structure->sequence_of_ranParameters failed\n");
419                 return -1;
420         }
421         fprintf(stderr, " ranParameterStructure1 encoded \n");
422
423         ASN_SEQUENCE_ADD(&ranParameterStructure1->ranParameter_Structure->sequence_of_ranParameters->list, ranParameterItem2);   // Target Cell
424         ranParameterItem1->ranParameter_valueType.choice.ranP_Choice_Structure = ranParameterStructure1; // Target Primary Cell
425
426         ASN_SEQUENCE_ADD(&e2smrcRcControlFormat1->ranP_List.list, ranParameterItem1); // Target Primary Cell
427         e2smrcRcControlMsg->ric_controlMessage_formats.choice.controlMessage_Format1 = e2smrcRcControlFormat1;
428
429
430         fprintf(stderr, "showing xer of asn_DEF_E2SM_RC_ControlMessage data\n");
431         xer_fprint(stderr, &asn_DEF_E2SM_RC_ControlMessage, e2smrcRcControlMsg);
432         fprintf(stderr, "\n");
433         fprintf(stderr, "After xer of asn_DEF_E2SM_RC_ControlMessage data\n");
434
435         asn_enc_rval_t encode_result;
436         encode_result = aper_encode_to_buffer(&asn_DEF_E2SM_RC_ControlMessage, NULL, e2smrcRcControlMsg, buffer, buf_size);
437         ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlMessage, e2smrcRcControlMsg);
438         fprintf(stderr, "encoded length = %ld \n", encode_result.encoded);
439         if(encode_result.encoded == -1)
440         {
441                 fprintf(stderr, "Cannot encode %s: %s\n", encode_result.failed_type->name, strerror(errno));
442                 return -1;
443         }
444         else
445         {
446                 return encode_result.encoded;
447         }
448 }
449
450
451 E2SM_RC_ControlOutcome_t* e2sm_decode_ric_call_process_outcome(void *buffer, size_t buf_size)
452 {
453         fprintf(stderr, "e2sm_decode_ric_call_process_outcome Enter \n");
454         asn_dec_rval_t decode_result;
455         E2SM_RC_ControlOutcome_t* controlOutcome = NULL;
456         decode_result = aper_decode_complete(NULL, &asn_DEF_E2SM_RC_ControlOutcome, (void **)&controlOutcome, buffer, buf_size);
457         if(decode_result.code == RC_OK) {
458                 xer_fprint(stdout, &asn_DEF_E2SM_RC_ControlOutcome, controlOutcome);
459                 return controlOutcome;
460         }
461         else {
462         ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlOutcome, controlOutcome);
463         return NULL;
464         }
465 }
466
467 void e2sm_free_ric_call_process_outcome(E2SM_RC_ControlOutcome_t* controlOutcome) {
468         ASN_STRUCT_FREE(asn_DEF_E2SM_RC_ControlOutcome, controlOutcome);
469 }