3 /*****************************************************************************
5 # Copyright 2020 AT&T Intellectual Property *
6 # Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved. *
8 # Licensed under the Apache License, Version 2.0 (the "License"); *
9 # you may not use this file except in compliance with the License. *
10 # You may obtain a copy of the License at *
12 # http://www.apache.org/licenses/LICENSE-2.0 *
14 # Unless required by applicable law or agreed to in writing, software *
15 # distributed under the License is distributed on an "AS IS" BASIS, *
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
17 # See the License for the specific language governing permissions and *
18 # limitations under the License. *
20 ******************************************************************************/
31 #include "encode_e2apv1.hpp"
36 #include "e2ap_asn1c_codec.h"
37 #include "GlobalE2node-ID.h"
38 #include "GlobalE2node-gNB-ID.h"
39 #include "GlobalgNB-ID.h"
40 #include "OCTET_STRING.h"
41 #include "asn_application.h"
42 #include "GNB-ID-Choice.h"
43 #include "ProtocolIE-Field.h"
44 #include "E2setupRequest.h"
45 #include "RICaction-ToBeSetup-Item.h"
46 #include "RICactions-ToBeSetup-List.h"
47 #include "RICeventTriggerDefinition.h"
48 #include "RICsubscriptionRequest.h"
49 #include "RICsubscriptionResponse.h"
50 #include "ProtocolIE-SingleContainer.h"
51 #include "RANfunctions-List.h"
52 #include "RICindication.h"
53 #include "RICsubsequentActionType.h"
54 #include "RICsubsequentAction.h"
55 #include "RICtimeToWait.h"
59 long encoding::get_function_id_from_subscription(E2AP_PDU_t *e2ap_pdu) {
61 RICsubscriptionRequest_t orig_req =
62 e2ap_pdu->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
64 RICsubscriptionResponse_IEs_t *ricreqid =
65 (RICsubscriptionResponse_IEs_t*)calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
67 int count = orig_req.protocolIEs.list.count;
68 int size = orig_req.protocolIEs.list.size;
70 RICsubscriptionRequest_IEs_t **ies = (RICsubscriptionRequest_IEs_t**)orig_req.protocolIEs.list.array;
72 fprintf(stderr, "count%d\n", count);
73 fprintf(stderr, "size%d\n", size);
75 RICsubscriptionRequest_IEs__value_PR pres;
79 for (int i=0; i < count; i++) {
80 RICsubscriptionRequest_IEs_t *next_ie = ies[i];
81 pres = next_ie->value.present;
83 fprintf(stderr, "next present value %d\n", pres);
84 fprintf(stderr, "value of pres ranfuncid is %d\n", RICsubscriptionRequest_IEs__value_PR_RANfunctionID);
86 if (pres == RICsubscriptionRequest_IEs__value_PR_RANfunctionID) {
87 fprintf(stderr, "equal pres to ranfuncid\n");
88 func_id = next_ie->value.choice.RANfunctionID;
93 fprintf(stderr, "After loop, func_id is %d\n", func_id);
99 void encoding::generate_e2apv1_service_update(E2AP_PDU_t *e2ap_pdu, std::vector<encoding::ran_func_info> all_funcs) {
100 char* ran_function_op_type = getenv("RAN_FUNCTION_OP_TYPE");
101 LOG_D("Ran funciton : %s", ran_function_op_type);
102 ProtocolIE_ID_t prID;
103 if (ran_function_op_type != NULL)
105 if (strcmp(ran_function_op_type, "ADD") == 0)
107 prID = ProtocolIE_ID_id_RANfunctionsAdded;
109 else if (strcmp(ran_function_op_type, "DELETE"))
111 prID = ProtocolIE_ID_id_RANfunctionsDeleted;
116 prID = ProtocolIE_ID_id_RANfunctionsModified;
120 RICserviceUpdate_IEs_t *e2serviceUpdateList = (RICserviceUpdate_IEs_t *)calloc(1, sizeof(RICserviceUpdate_IEs_t));
121 e2serviceUpdateList->id = prID;
122 e2serviceUpdateList->criticality = Criticality_reject;
123 e2serviceUpdateList->value.present = RICserviceUpdate_IEs__value_PR_RANfunctions_List;
126 for (int i=0; i<all_funcs.size(); i++) {
128 encoding::ran_func_info nextRanFunc = all_funcs.at(i);
129 long nextRanFuncId = nextRanFunc.ranFunctionId;
130 OCTET_STRING_t *nextRanFuncDesc = nextRanFunc.ranFunctionDesc;
131 long nextRanFuncRev = nextRanFunc.ranFunctionRev;
133 auto *itemIes = (RANfunction_ItemIEs_t *)calloc(1, sizeof(RANfunction_ItemIEs_t));
134 itemIes->id = ProtocolIE_ID_id_RANfunction_Item;
135 itemIes->criticality = Criticality_reject;
136 itemIes->value.present = RANfunction_ItemIEs__value_PR_RANfunction_Item;
137 itemIes->value.choice.RANfunction_Item.ranFunctionID = 1;
139 itemIes->value.choice.RANfunction_Item.ranFunctionDefinition = *nextRanFuncDesc;
140 itemIes->value.choice.RANfunction_Item.ranFunctionRevision = nextRanFuncRev + 1;
142 ASN_SEQUENCE_ADD(&e2serviceUpdateList->value.choice.RANfunctions_List.list, itemIes);
145 RICserviceUpdate_t *ricServiceUpdate = (RICserviceUpdate_t *)calloc(1, sizeof(RICserviceUpdate_t));
146 ASN_SEQUENCE_ADD(&ricServiceUpdate->protocolIEs.list, e2serviceUpdateList);
148 InitiatingMessage_t *initiatingMessage = (InitiatingMessage_t *)calloc(1, sizeof(InitiatingMessage_t));
149 initiatingMessage->criticality = Criticality_reject;
150 initiatingMessage->procedureCode = ProcedureCode_id_RICserviceUpdate;
151 initiatingMessage->value.present = InitiatingMessage__value_PR_RICserviceUpdate;
152 initiatingMessage->value.choice.RICserviceUpdate = *ricServiceUpdate;
154 E2AP_PDU_PR pres6 = E2AP_PDU_PR_initiatingMessage;
155 e2ap_pdu->present = pres6;
156 e2ap_pdu->choice.initiatingMessage = initiatingMessage;
159 void encoding::generate_e2apv1_setup_request_parameterized(E2AP_PDU_t *e2ap_pdu, std::vector<ran_func_info> all_funcs) {
160 // long ranFunctionId, uint8_t *ranFuncDescEncoded, int ranFuncLength) {
162 // uint8_t *buf = (uint8_t *)"gnb1"
164 BIT_STRING_t *gnb_bstring = (BIT_STRING_t*)calloc(1, sizeof(BIT_STRING_t));;
165 gnb_bstring->buf = (uint8_t*)calloc(1,4);
166 gnb_bstring->size = 4;
167 gnb_bstring->buf[0] = 0xB5;
168 gnb_bstring->buf[1] = 0xC6;
169 gnb_bstring->buf[2] = 0x77;
170 gnb_bstring->buf[3] = 0x88;
172 gnb_bstring->bits_unused = 3;
174 uint8_t *buf2 = (uint8_t *)"747";
175 OCTET_STRING_t *plmn = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
176 plmn->buf = (uint8_t*)calloc(1,3);
177 memcpy(plmn->buf, buf2, 3);
180 GNB_ID_Choice_t *gnbchoice = (GNB_ID_Choice_t*)calloc(1,sizeof(GNB_ID_Choice_t));
181 GNB_ID_Choice_PR pres2 = GNB_ID_Choice_PR_gnb_ID;
182 gnbchoice->present = pres2;
183 gnbchoice->choice.gnb_ID = *gnb_bstring;
185 GlobalgNB_ID_t *gnb = (GlobalgNB_ID_t*)calloc(1, sizeof(GlobalgNB_ID_t));
186 gnb->plmn_id = *plmn;
187 gnb->gnb_id = *gnbchoice;
189 GlobalE2node_gNB_ID_t *e2gnb = (GlobalE2node_gNB_ID_t*)calloc(1, sizeof(GlobalE2node_gNB_ID_t));
190 e2gnb->global_gNB_ID = *gnb;
192 GlobalE2node_ID_t *globale2nodeid = (GlobalE2node_ID_t*)calloc(1, sizeof(GlobalE2node_ID_t));
193 GlobalE2node_ID_PR pres;
194 pres = GlobalE2node_ID_PR_gNB;
195 globale2nodeid->present = pres;
196 globale2nodeid->choice.gNB = e2gnb;
198 E2setupRequestIEs_t *e2setuprid = (E2setupRequestIEs_t*)calloc(1, sizeof(E2setupRequestIEs_t));
199 E2setupRequestIEs__value_PR pres3;
200 pres3 = E2setupRequestIEs__value_PR_GlobalE2node_ID;
202 e2setuprid->criticality = 0;
203 e2setuprid->value.choice.GlobalE2node_ID = *globale2nodeid;
204 e2setuprid->value.present = pres3;
207 auto *ranFlistIEs = (E2setupRequestIEs_t *)calloc(1, sizeof(E2setupRequestIEs_t));
208 ASN_STRUCT_RESET(asn_DEF_E2setupRequestIEs, ranFlistIEs);
209 ranFlistIEs->criticality = 0;
210 ranFlistIEs->id = ProtocolIE_ID_id_RANfunctionsAdded;
211 ranFlistIEs->value.present = E2setupRequestIEs__value_PR_RANfunctions_List;
214 for (int i = 0; i < all_funcs.size(); i++) {
216 ran_func_info nextRanFunc = all_funcs.at(i);
217 long nextRanFuncId = nextRanFunc.ranFunctionId;
218 OCTET_STRING_t *nextRanFuncDesc = nextRanFunc.ranFunctionDesc;
219 long nextRanFuncRev = nextRanFunc.ranFunctionRev;
221 auto *itemIes = (RANfunction_ItemIEs_t *)calloc(1, sizeof(RANfunction_ItemIEs_t));
222 itemIes->id = ProtocolIE_ID_id_RANfunction_Item;
223 itemIes->criticality = Criticality_reject;
224 itemIes->value.present = RANfunction_ItemIEs__value_PR_RANfunction_Item;
225 itemIes->value.choice.RANfunction_Item.ranFunctionID = nextRanFuncId;
227 int ranFuncLength = strlen((char*)nextRanFuncDesc);
229 itemIes->value.choice.RANfunction_Item.ranFunctionDefinition = *nextRanFuncDesc;
230 itemIes->value.choice.RANfunction_Item.ranFunctionRevision = nextRanFuncRev;
232 ASN_SEQUENCE_ADD(&ranFlistIEs->value.choice.RANfunctions_List.list, itemIes);
236 E2setupRequest_t *e2setupreq = (E2setupRequest_t*)calloc(1, sizeof(E2setupRequest_t));
237 ASN_SEQUENCE_ADD(&e2setupreq->protocolIEs.list, e2setuprid);
238 ASN_SEQUENCE_ADD(&e2setupreq->protocolIEs.list, ranFlistIEs);
240 InitiatingMessage__value_PR pres4;
241 pres4 = InitiatingMessage__value_PR_E2setupRequest;
242 InitiatingMessage_t *initmsg = (InitiatingMessage_t*)calloc(1, sizeof(InitiatingMessage_t));
244 initmsg->procedureCode = ProcedureCode_id_E2setup;
245 initmsg->criticality = Criticality_reject;
246 initmsg->value.present = pres4;
247 initmsg->value.choice.E2setupRequest = *e2setupreq;
250 pres5 = E2AP_PDU_PR_initiatingMessage;
253 e2ap_pdu->present = pres5;
254 e2ap_pdu->choice.initiatingMessage = initmsg;
260 void encoding::generate_e2apv1_setup_response(E2AP_PDU_t *e2ap_pdu) {
262 E2setupResponseIEs *resp_ies1 = (E2setupResponseIEs_t*)calloc(1, sizeof(E2setupResponseIEs_t));
263 E2setupResponseIEs *resp_ies2 = (E2setupResponseIEs_t*)calloc(1, sizeof(E2setupResponseIEs_t));
264 E2setupResponseIEs *resp_ies3 = (E2setupResponseIEs_t*)calloc(1, sizeof(E2setupResponseIEs_t));
266 uint8_t *buf = (uint8_t *)"gnb1";
268 BIT_STRING_t *ricid_bstring = (BIT_STRING_t*)calloc(1,sizeof(BIT_STRING_t));
269 ricid_bstring->buf = buf;
270 ricid_bstring->size = 4;
271 ricid_bstring->bits_unused = 0;
273 uint8_t *buf2 = (uint8_t *)"plmn3";
274 OCTET_STRING_t *plmn = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
278 GlobalRIC_ID_t *globalricid = (GlobalRIC_ID_t*)calloc(1,sizeof(GlobalRIC_ID_t));
279 globalricid->pLMN_Identity = *plmn;
280 globalricid->ric_ID = *ricid_bstring;
282 E2setupResponseIEs__value_PR pres1;
283 pres1 = E2setupResponseIEs__value_PR_GlobalRIC_ID;
285 resp_ies1->id = ProtocolIE_ID_id_GlobalRIC_ID;
286 resp_ies1->criticality = 0;
287 resp_ies1->value.present = pres1;
288 resp_ies1->value.choice.GlobalRIC_ID = *globalricid;
290 E2setupResponse_t *e2setupresp = (E2setupResponse_t*)calloc(1,sizeof(E2setupResponse_t));
291 int ret = ASN_SEQUENCE_ADD(&e2setupresp->protocolIEs.list, resp_ies1);
294 SuccessfulOutcome__value_PR pres;
295 pres = SuccessfulOutcome__value_PR_E2setupResponse;
296 SuccessfulOutcome_t *successoutcome = (SuccessfulOutcome_t*)calloc(1, sizeof(SuccessfulOutcome_t));
297 successoutcome->procedureCode = 1;
298 successoutcome->criticality = 0;
299 successoutcome->value.present = pres;
300 successoutcome->value.choice.E2setupResponse = *e2setupresp;
302 E2AP_PDU_PR pres5 = E2AP_PDU_PR_successfulOutcome;
304 e2ap_pdu->present = pres5;
305 e2ap_pdu->choice.successfulOutcome = successoutcome;
310 void encoding::generate_e2apv1_subscription_request(E2AP_PDU *e2ap_pdu) {
312 fprintf(stderr, "in sub 1\n");
313 RICsubscriptionRequest_IEs_t *ricreqid = (RICsubscriptionRequest_IEs_t*)calloc(1, sizeof(RICsubscriptionRequest_IEs_t));
314 fprintf(stderr, "in sub 2\n");
315 ASN_STRUCT_RESET(asn_DEF_RICsubscriptionRequest_IEs, ricreqid);
316 fprintf(stderr, "in sub 3\n");
317 auto *ricsubrid = (RICsubscriptionRequest_IEs_t*)calloc(1, sizeof(RICsubscriptionRequest_IEs_t));
318 fprintf(stderr, "in sub 4\n");
319 ASN_STRUCT_RESET(asn_DEF_RICsubscriptionRequest_IEs, ricsubrid);
321 fprintf(stderr, "in generate sub\n");
322 uint8_t *buf2 = (uint8_t *)"SubscriptionTriggers";
323 fprintf(stderr, "in gen sub 1\n");
324 OCTET_STRING_t *triggerdef = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
325 triggerdef->buf = (uint8_t *)calloc(1,20);
326 triggerdef->size = 20;
327 memcpy(triggerdef->buf, buf2, triggerdef->size);
330 fprintf(stderr, "sub1\n");
331 ProtocolIE_ID_t proto_id= ProtocolIE_ID_id_RICaction_ToBeSetup_Item;
333 RICaction_ToBeSetup_ItemIEs__value_PR pres6;
334 pres6 = RICaction_ToBeSetup_ItemIEs__value_PR_RICaction_ToBeSetup_Item;
338 uint8_t *buf5 = (uint8_t *)"ActionDef";
340 OCTET_STRING_t *actdef = (OCTET_STRING_t*)calloc(1, sizeof(OCTET_STRING_t));
341 actdef->buf = (uint8_t *)calloc(1,9);
343 memcpy(triggerdef->buf, buf5, 9);
345 auto *sa = (RICsubsequentAction_t *) calloc(1, sizeof(RICsubsequentAction_t));
346 ASN_STRUCT_RESET(asn_DEF_RICsubsequentAction, sa);
348 sa->ricTimeToWait = RICtimeToWait_w500ms;
349 sa->ricSubsequentActionType = RICsubsequentActionType_continue;
353 RICaction_ToBeSetup_ItemIEs_t *action_item_ies = (RICaction_ToBeSetup_ItemIEs_t *)calloc(1, sizeof(RICaction_ToBeSetup_Item_t));
354 action_item_ies->id = proto_id;
355 action_item_ies->criticality = 0;
357 action_item_ies->value.present = pres6;
358 action_item_ies->value.choice.RICaction_ToBeSetup_Item.ricActionID = 5;
359 action_item_ies->value.choice.RICaction_ToBeSetup_Item.ricActionType = RICactionType_report;
360 action_item_ies->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition = actdef;
361 action_item_ies->value.choice.RICaction_ToBeSetup_Item.ricSubsequentAction = sa;
367 RICsubscriptionRequest_IEs__value_PR pres3;
369 pres3 = RICsubscriptionRequest_IEs__value_PR_RICsubscriptionDetails;
370 ricsubrid->id = ProtocolIE_ID_id_RICsubscriptionDetails;
373 ricsubrid->criticality = 0;
374 ricsubrid->value.present = pres3;
377 ricsubrid->value.choice.RICsubscriptionDetails.ricEventTriggerDefinition = *triggerdef;
380 ASN_SEQUENCE_ADD(&ricsubrid->value.choice.RICsubscriptionDetails.ricAction_ToBeSetup_List.list, action_item_ies);
385 ricreqid->id = ProtocolIE_ID_id_RICrequestID;
386 ricreqid->criticality = 0;
387 ricreqid->value.present = RICsubscriptionRequest_IEs__value_PR_RICrequestID;
388 ricreqid->value.choice.RICrequestID.ricRequestorID = 22;
389 ricreqid->value.choice.RICrequestID.ricInstanceID = 6;
391 RICsubscriptionRequest_t *ricsubreq = (RICsubscriptionRequest_t*)calloc(1, sizeof(RICsubscriptionRequest_t));
393 ASN_SEQUENCE_ADD(&ricsubreq->protocolIEs.list,ricreqid);
394 ASN_SEQUENCE_ADD(&ricsubreq->protocolIEs.list,ricsubrid);
398 InitiatingMessage__value_PR pres4;
399 pres4 = InitiatingMessage__value_PR_RICsubscriptionRequest;
400 InitiatingMessage_t *initmsg = (InitiatingMessage_t*)calloc(1, sizeof(InitiatingMessage_t));
401 initmsg->procedureCode = ProcedureCode_id_RICsubscription;
402 initmsg->criticality = Criticality_reject;
403 initmsg->value.present = pres4;
404 initmsg->value.choice.RICsubscriptionRequest = *ricsubreq;
407 pres5 = E2AP_PDU_PR_initiatingMessage;
410 e2ap_pdu->present = pres5;
411 e2ap_pdu->choice.initiatingMessage = initmsg;
413 char *error_buf = (char*)calloc(300, sizeof(char));;
416 asn_check_constraints(&asn_DEF_E2AP_PDU, e2ap_pdu, error_buf, &errlen);
417 printf("error length %d\n", errlen);
418 printf("error buf %s\n", error_buf);
423 void encoding::generate_e2apv1_subscription_response_success(E2AP_PDU *e2ap_pdu, long reqActionIdsAccepted[],
424 long reqActionIdsRejected[], int accept_size, int reject_size,
425 long reqRequestorId, long reqInstanceId) {
427 RICsubscriptionResponse_IEs_t *respricreqid =
428 (RICsubscriptionResponse_IEs_t*)calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
430 respricreqid->id = ProtocolIE_ID_id_RICrequestID;
431 respricreqid->criticality = 0;
432 respricreqid->value.present = RICsubscriptionResponse_IEs__value_PR_RICrequestID;
433 respricreqid->value.choice.RICrequestID.ricRequestorID = reqRequestorId;
435 respricreqid->value.choice.RICrequestID.ricInstanceID = reqInstanceId;
437 RICsubscriptionResponse_IEs_t *respfuncid =
438 (RICsubscriptionResponse_IEs_t*)calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
439 respfuncid->id = ProtocolIE_ID_id_RANfunctionID;
440 respfuncid->criticality = 0;
441 respfuncid->value.present = RICsubscriptionResponse_IEs__value_PR_RANfunctionID;
442 respfuncid->value.choice.RANfunctionID = (long)0;
445 RICsubscriptionResponse_IEs_t *ricactionadmitted =
446 (RICsubscriptionResponse_IEs_t*)calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
447 ricactionadmitted->id = ProtocolIE_ID_id_RICactions_Admitted;
448 ricactionadmitted->criticality = 0;
449 ricactionadmitted->value.present = RICsubscriptionResponse_IEs__value_PR_RICaction_Admitted_List;
451 RICaction_Admitted_List_t* admlist =
452 (RICaction_Admitted_List_t*)calloc(1,sizeof(RICaction_Admitted_List_t));
453 ricactionadmitted->value.choice.RICaction_Admitted_List = *admlist;
456 int numAccept = accept_size;
457 int numReject = reject_size;
461 for (int i=0; i < numAccept ; i++) {
462 fprintf(stderr, "in for loop i = %d\n", i);
464 long aid = reqActionIdsAccepted[i];
466 RICaction_Admitted_ItemIEs_t *admitie = (RICaction_Admitted_ItemIEs_t*)calloc(1,sizeof(RICaction_Admitted_ItemIEs_t));
467 admitie->id = ProtocolIE_ID_id_RICaction_Admitted_Item;
468 admitie->criticality = 0;
469 admitie->value.present = RICaction_Admitted_ItemIEs__value_PR_RICaction_Admitted_Item;
470 admitie->value.choice.RICaction_Admitted_Item.ricActionID = aid;
472 ASN_SEQUENCE_ADD(&ricactionadmitted->value.choice.RICaction_Admitted_List.list, admitie);
476 RICsubscriptionResponse_t *ricsubresp = (RICsubscriptionResponse_t*)calloc(1,sizeof(RICsubscriptionResponse_t));
477 ASN_SEQUENCE_ADD(&ricsubresp->protocolIEs.list, respricreqid);
478 ASN_SEQUENCE_ADD(&ricsubresp->protocolIEs.list, respfuncid);
479 ASN_SEQUENCE_ADD(&ricsubresp->protocolIEs.list, ricactionadmitted);
484 RICsubscriptionResponse_IEs_t *ricactionrejected =
485 (RICsubscriptionResponse_IEs_t*)calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
486 ricactionrejected->id = ProtocolIE_ID_id_RICactions_NotAdmitted;
487 ricactionrejected->criticality = 0;
488 ricactionrejected->value.present = RICsubscriptionResponse_IEs__value_PR_RICaction_NotAdmitted_List;
490 RICaction_NotAdmitted_List_t* rejectlist =
491 (RICaction_NotAdmitted_List_t*)calloc(1,sizeof(RICaction_NotAdmitted_List_t));
492 ricactionadmitted->value.choice.RICaction_NotAdmitted_List = *rejectlist;
494 for (int i=0; i < numReject; i++) {
495 fprintf(stderr, "in for loop i = %d\n", i);
497 long aid = reqActionIdsRejected[i];
499 RICaction_NotAdmitted_ItemIEs_t *noadmitie = (RICaction_NotAdmitted_ItemIEs_t*)calloc(1,sizeof(RICaction_NotAdmitted_ItemIEs_t));
500 noadmitie->id = ProtocolIE_ID_id_RICaction_NotAdmitted_Item;
501 noadmitie->criticality = 0;
502 noadmitie->value.present = RICaction_NotAdmitted_ItemIEs__value_PR_RICaction_NotAdmitted_Item;
503 noadmitie->value.choice.RICaction_NotAdmitted_Item.ricActionID = aid;
505 ASN_SEQUENCE_ADD(&ricactionrejected->value.choice.RICaction_NotAdmitted_List.list, noadmitie);
506 ASN_SEQUENCE_ADD(&ricsubresp->protocolIEs.list, ricactionrejected);
511 SuccessfulOutcome__value_PR pres2;
512 pres2 = SuccessfulOutcome__value_PR_RICsubscriptionResponse;
513 SuccessfulOutcome_t *successoutcome = (SuccessfulOutcome_t*)calloc(1, sizeof(SuccessfulOutcome_t));
514 successoutcome->procedureCode = ProcedureCode_id_RICsubscription;
515 successoutcome->criticality = 0;
516 successoutcome->value.present = pres2;
517 successoutcome->value.choice.RICsubscriptionResponse = *ricsubresp;
519 E2AP_PDU_PR pres5 = E2AP_PDU_PR_successfulOutcome;
521 e2ap_pdu->present = pres5;
522 e2ap_pdu->choice.successfulOutcome = successoutcome;
524 char *error_buf = (char*)calloc(300, sizeof(char));
527 asn_check_constraints(&asn_DEF_E2AP_PDU, e2ap_pdu, error_buf, &errlen);
528 printf("error length %d\n", errlen);
529 printf("error buf %s\n", error_buf);
531 printf("now printing xer of subscription response\n");
532 xer_fprint(stderr, &asn_DEF_E2AP_PDU, e2ap_pdu);
533 printf("done printing xer of subscription response\n");
538 void encoding::generate_e2apv1_subscription_response(E2AP_PDU *e2ap_pdu, E2AP_PDU *sub_req_pdu) {
540 //Gather details of the request
542 RICsubscriptionRequest_t orig_req =
543 sub_req_pdu->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
545 RICsubscriptionResponse_IEs_t *ricreqid =
546 (RICsubscriptionResponse_IEs_t*)calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
548 int count = orig_req.protocolIEs.list.count;
549 int size = orig_req.protocolIEs.list.size;
551 RICsubscriptionRequest_IEs_t **ies = (RICsubscriptionRequest_IEs_t**)orig_req.protocolIEs.list.array;
553 fprintf(stderr, "count%d\n", count);
554 fprintf(stderr, "size%d\n", size);
556 RICsubscriptionRequest_IEs__value_PR pres;
558 long responseRequestorId;
559 long responseInstanceId;
560 long responseActionId;
562 std::vector<long> actionIds;
564 for (int i=0; i < count; i++) {
565 RICsubscriptionRequest_IEs_t *next_ie = ies[i];
566 pres = next_ie->value.present;
568 fprintf(stderr, "next present value %d\n", pres);
571 case RICsubscriptionRequest_IEs__value_PR_RICrequestID:
573 RICrequestID_t reqId = next_ie->value.choice.RICrequestID;
574 long requestorId = reqId.ricRequestorID;
575 long instanceId = reqId.ricInstanceID;
576 fprintf(stderr, "requestorId %d\n", requestorId);
577 fprintf(stderr, "instanceId %d\n", instanceId);
578 responseRequestorId = requestorId;
579 responseInstanceId = instanceId;
583 case RICsubscriptionRequest_IEs__value_PR_RANfunctionID:
585 case RICsubscriptionRequest_IEs__value_PR_RICsubscriptionDetails:
587 RICsubscriptionDetails_t subDetails = next_ie->value.choice.RICsubscriptionDetails;
588 RICeventTriggerDefinition_t triggerDef = subDetails.ricEventTriggerDefinition;
589 RICactions_ToBeSetup_List_t actionList = subDetails.ricAction_ToBeSetup_List;
591 int actionCount = actionList.list.count;
592 fprintf(stderr, "action count%d\n", actionCount);
594 auto **item_array = actionList.list.array;
596 for (int i=0; i < actionCount; i++) {
597 //RICaction_ToBeSetup_Item_t
598 auto *next_item = item_array[i];
599 RICactionID_t actionId = ((RICaction_ToBeSetup_ItemIEs*)next_item)->value.choice.RICaction_ToBeSetup_Item.ricActionID;
600 fprintf(stderr, "Next Action ID %ld\n", actionId);
601 responseActionId = actionId;
602 actionIds.push_back(responseActionId);
611 fprintf(stderr, "After Processing Subscription Request\n");
613 fprintf(stderr, "requestorId %d\n", responseRequestorId);
614 fprintf(stderr, "instanceId %d\n", responseInstanceId);
617 for (int i=0; i < actionIds.size(); i++) {
618 fprintf(stderr, "Action ID %d %ld\n", i, actionIds.at(i));
623 RICsubscriptionResponse_IEs_t *respricreqid =
624 (RICsubscriptionResponse_IEs_t*)calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
626 respricreqid->id = ProtocolIE_ID_id_RICrequestID;
627 respricreqid->criticality = 0;
628 respricreqid->value.present = RICsubscriptionResponse_IEs__value_PR_RICrequestID;
629 respricreqid->value.choice.RICrequestID.ricRequestorID = responseRequestorId;
631 respricreqid->value.choice.RICrequestID.ricInstanceID = responseInstanceId;
634 RICsubscriptionResponse_IEs_t *ricactionadmitted =
635 (RICsubscriptionResponse_IEs_t*)calloc(1, sizeof(RICsubscriptionResponse_IEs_t));
636 ricactionadmitted->id = ProtocolIE_ID_id_RICactions_Admitted;
637 ricactionadmitted->criticality = 0;
638 ricactionadmitted->value.present = RICsubscriptionResponse_IEs__value_PR_RICaction_Admitted_List;
640 RICaction_Admitted_List_t* admlist =
641 (RICaction_Admitted_List_t*)calloc(1,sizeof(RICaction_Admitted_List_t));
642 ricactionadmitted->value.choice.RICaction_Admitted_List = *admlist;
644 for (int i=0; i < actionIds.size(); i++) {
645 fprintf(stderr, "in for loop i = %d\n", i);
647 long aid = actionIds.at(i);
649 RICaction_Admitted_ItemIEs_t *admitie = (RICaction_Admitted_ItemIEs_t*)calloc(1,sizeof(RICaction_Admitted_ItemIEs_t));
650 admitie->id = ProtocolIE_ID_id_RICaction_Admitted_Item;
651 admitie->criticality = 0;
652 admitie->value.present = RICaction_Admitted_ItemIEs__value_PR_RICaction_Admitted_Item;
653 admitie->value.choice.RICaction_Admitted_Item.ricActionID = aid;
655 ASN_SEQUENCE_ADD(&ricactionadmitted->value.choice.RICaction_Admitted_List.list, admitie);
660 RICsubscriptionResponse_t *ricsubresp = (RICsubscriptionResponse_t*)calloc(1,sizeof(RICsubscriptionResponse_t));
662 ASN_SEQUENCE_ADD(&ricsubresp->protocolIEs.list, respricreqid);
663 ASN_SEQUENCE_ADD(&ricsubresp->protocolIEs.list, ricactionadmitted);
666 SuccessfulOutcome__value_PR pres2;
667 pres2 = SuccessfulOutcome__value_PR_RICsubscriptionResponse;
668 SuccessfulOutcome_t *successoutcome = (SuccessfulOutcome_t*)calloc(1, sizeof(SuccessfulOutcome_t));
669 successoutcome->procedureCode = ProcedureCode_id_RICsubscription;
670 successoutcome->criticality = 0;
671 successoutcome->value.present = pres2;
672 successoutcome->value.choice.RICsubscriptionResponse = *ricsubresp;
674 E2AP_PDU_PR pres5 = E2AP_PDU_PR_successfulOutcome;
676 e2ap_pdu->present = pres5;
677 e2ap_pdu->choice.successfulOutcome = successoutcome;
679 char *error_buf = (char*)calloc(300, sizeof(char));
682 asn_check_constraints(&asn_DEF_E2AP_PDU, e2ap_pdu, error_buf, &errlen);
683 printf("error length %d\n", errlen);
684 printf("error buf %s\n", error_buf);
690 void encoding::generate_e2apv1_indication_request_parameterized(E2AP_PDU *e2ap_pdu,
696 uint8_t *ind_header_buf,
698 uint8_t *ind_message_buf,
699 int message_length) {
701 fprintf(stderr, "ind1\n");
702 RICindication_IEs_t *ricind_ies = (RICindication_IEs_t*)calloc(1, sizeof(RICindication_IEs_t));
703 RICindication_IEs_t *ricind_ies2 = (RICindication_IEs_t*)calloc(1, sizeof(RICindication_IEs_t));
704 RICindication_IEs_t *ricind_ies3 = (RICindication_IEs_t*)calloc(1, sizeof(RICindication_IEs_t));
705 RICindication_IEs_t *ricind_ies4 = (RICindication_IEs_t*)calloc(1, sizeof(RICindication_IEs_t));
706 RICindication_IEs_t *ricind_ies5 = (RICindication_IEs_t*)calloc(1, sizeof(RICindication_IEs_t));
707 RICindication_IEs_t *ricind_ies6 = (RICindication_IEs_t*)calloc(1, sizeof(RICindication_IEs_t));
708 RICindication_IEs_t *ricind_ies7 = (RICindication_IEs_t*)calloc(1, sizeof(RICindication_IEs_t));
709 RICindication_IEs_t *ricind_ies8 = (RICindication_IEs_t*)calloc(1, sizeof(RICindication_IEs_t));
711 RICindication_IEs__value_PR pres3;
713 pres3 = RICindication_IEs__value_PR_RICrequestID;
714 ricind_ies->id = ProtocolIE_ID_id_RICrequestID;
715 ricind_ies->criticality = 0;
716 ricind_ies->value.present = pres3;
717 ricind_ies->value.choice.RICrequestID.ricRequestorID = requestorId;
718 ricind_ies->value.choice.RICrequestID.ricInstanceID = instanceId;
720 fprintf(stderr, "ind2\n");
722 pres3 = RICindication_IEs__value_PR_RANfunctionID;
723 ricind_ies2->id = ProtocolIE_ID_id_RANfunctionID;
724 ricind_ies2->criticality = 0;
725 ricind_ies2->value.present = pres3;
726 ricind_ies2->value.choice.RANfunctionID = ranFunctionId;
729 ricind_ies3->id = ProtocolIE_ID_id_RICactionID;
730 ricind_ies3->criticality = 0;
731 pres3 = RICindication_IEs__value_PR_RICactionID;
732 ricind_ies3->value.present = pres3;
733 ricind_ies3->value.choice.RICactionID = actionId;
736 pres3 = RICindication_IEs__value_PR_RICindicationSN;
737 ricind_ies4->id = ProtocolIE_ID_id_RICindicationSN;
738 ricind_ies4->criticality = 0;
739 ricind_ies4->value.present = pres3;
740 ricind_ies4->value.choice.RICindicationSN = seqNum;
742 //Indication type is REPORT
743 pres3 = RICindication_IEs__value_PR_RICindicationType;
744 ricind_ies5->id = ProtocolIE_ID_id_RICindicationType;
745 ricind_ies5->criticality = 0;
746 ricind_ies5->value.present = pres3;
747 ricind_ies5->value.choice.RICindicationType = 0;
750 uint8_t *buf2 = (uint8_t *)"reportheader";
751 OCTET_STRING_t *hdr_str = (OCTET_STRING_t*)calloc(1,sizeof(OCTET_STRING_t));
753 hdr_str->buf = (uint8_t*)calloc(1,header_length);
754 hdr_str->size = header_length;
755 memcpy(hdr_str->buf, ind_header_buf, header_length);
757 fprintf(stderr, "ind3\n");
759 ricind_ies6->value.choice.RICindicationHeader.buf = (uint8_t*)calloc(1,header_length);
761 pres3 = RICindication_IEs__value_PR_RICindicationHeader;
762 ricind_ies6->id = ProtocolIE_ID_id_RICindicationHeader;
763 ricind_ies6->criticality = 0;
764 ricind_ies6->value.present = pres3;
765 ricind_ies6->value.choice.RICindicationHeader.size = header_length;
766 memcpy(ricind_ies6->value.choice.RICindicationHeader.buf, ind_header_buf, header_length);
768 ricind_ies7->value.choice.RICindicationMessage.buf = (uint8_t*)calloc(1,8192);
773 pres3 = RICindication_IEs__value_PR_RICindicationMessage;
774 ricind_ies7->id = ProtocolIE_ID_id_RICindicationMessage;
775 fprintf(stderr, "after encoding message 1\n");
777 ricind_ies7->criticality = 0;
778 ricind_ies7->value.present = pres3;
780 fprintf(stderr, "after encoding message 2\n");
782 fprintf(stderr, "after encoding message 3\n");
783 ricind_ies7->value.choice.RICindicationMessage.size = message_length;
785 fprintf(stderr, "after encoding message 4\n");
786 memcpy(ricind_ies7->value.choice.RICindicationMessage.buf, ind_message_buf, message_length);
788 fprintf(stderr, "after encoding message 5\n");
790 uint8_t *cpid_buf = (uint8_t *)"cpid";
791 OCTET_STRING_t cpid_str;
795 int cpid_buf_len = strlen((char*)cpid_buf);
796 pres3 = RICindication_IEs__value_PR_RICcallProcessID;
797 ricind_ies8->id = ProtocolIE_ID_id_RICcallProcessID;
799 ricind_ies8->criticality = 0;
800 ricind_ies8->value.present = pres3;
802 ricind_ies8->value.choice.RICcallProcessID.buf = (uint8_t*)calloc(1,cpid_buf_len);
803 ricind_ies8->value.choice.RICcallProcessID.size = cpid_buf_len;
805 memcpy(ricind_ies8->value.choice.RICcallProcessID.buf, cpid_buf, cpid_buf_len);
809 RICindication_t *ricindication = (RICindication_t*)calloc(1, sizeof(RICindication_t));
814 ret = ASN_SEQUENCE_ADD(&ricindication->protocolIEs.list, ricind_ies);
816 ret = ASN_SEQUENCE_ADD(&ricindication->protocolIEs.list, ricind_ies2);
820 ret = ASN_SEQUENCE_ADD(&ricindication->protocolIEs.list, ricind_ies3);
824 ret = ASN_SEQUENCE_ADD(&ricindication->protocolIEs.list, ricind_ies4);
828 ret = ASN_SEQUENCE_ADD(&ricindication->protocolIEs.list, ricind_ies5);
832 ret = ASN_SEQUENCE_ADD(&ricindication->protocolIEs.list, ricind_ies6);
836 ret = ASN_SEQUENCE_ADD(&ricindication->protocolIEs.list, ricind_ies7);
838 ret = ASN_SEQUENCE_ADD(&ricindication->protocolIEs.list, ricind_ies8);
841 InitiatingMessage__value_PR pres4;
842 pres4 = InitiatingMessage__value_PR_RICindication;
843 InitiatingMessage_t *initmsg = (InitiatingMessage_t*)calloc(1, sizeof(InitiatingMessage_t));
844 initmsg->procedureCode = 5;
845 initmsg->criticality = 1;
846 initmsg->value.present = pres4;
847 initmsg->value.choice.RICindication = *ricindication;
850 pres5 = E2AP_PDU_PR_initiatingMessage;
852 e2ap_pdu->present = pres5;
853 e2ap_pdu->choice.initiatingMessage = initmsg;
855 char *error_buf = (char*)calloc(300, sizeof(char));
858 asn_check_constraints(&asn_DEF_E2AP_PDU, e2ap_pdu, error_buf, &errlen);
859 printf("error length %d\n", errlen);
860 printf("error buf %s\n", error_buf);
862 xer_fprint(stderr, &asn_DEF_E2AP_PDU, e2ap_pdu);