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