1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
19 /* This file contains E2AP message handler functions */
20 #include "common_def.h"
21 #include "OCTET_STRING.h"
22 #include "BIT_STRING.h"
23 #include "odu_common_codec.h"
24 #include "ric_stub_sctp.h"
26 #include "ric_e2ap_msg_hdl.h"
27 #include "GlobalE2node-gNB-ID.h"
28 #include "ProtocolIE-FieldE2.h"
29 #include "InitiatingMessageE2.h"
30 #include "SuccessfulOutcomeE2.h"
33 #include "E2nodeComponentInterfaceF1.h"
36 /*******************************************************************
38 * @brief Sends E2 msg over SCTP
42 * Function : SendE2APMsg
44 * Functionality: Sends E2 msg over SCTP
46 * @params[in] Region region
48 * @return ROK - success
51 * ****************************************************************/
53 uint8_t SendE2APMsg(Region region, Pool pool)
57 if(ODU_GET_MSG_BUF(region, pool, &mBuf) == ROK)
59 if(ODU_ADD_POST_MSG_MULT((Data *)encBuf, encBufSize, mBuf) == ROK)
61 ODU_PRINT_MSG(mBuf, 0,0);
63 if(sctpSend(mBuf) != ROK)
65 DU_LOG("\nERROR --> E2AP : SCTP Send for E2 failed");
66 ODU_PUT_MSG_BUF(mBuf);
72 DU_LOG("\nERROR --> E2AP : ODU_ADD_POST_MSG_MULT failed");
73 ODU_PUT_MSG_BUF(mBuf);
76 ODU_PUT_MSG_BUF(mBuf);
80 DU_LOG("\nERROR --> E2AP : Failed to allocate memory");
87 /*******************************************************************
89 * @brief Builds Global RIC Id Params
93 * Function : BuildGlobalRicId
95 * Functionality: Building the Plmn and ric id
97 * @params[in] GlobalRIC_ID_t *ricId
98 * @return ROK - success
101 * ****************************************************************/
103 uint8_t BuildGlobalRicId(GlobalRIC_ID_t *ricId)
106 uint8_t byteSize = 3;
110 ricId->pLMN_Identity.size = byteSize * sizeof(uint8_t);
111 RIC_ALLOC(ricId->pLMN_Identity.buf, ricId->pLMN_Identity.size);
112 buildPlmnId(ricCfgParams.plmn , ricId->pLMN_Identity.buf);
114 ricId->ric_ID.size = byteSize * sizeof(uint8_t);
115 RIC_ALLOC(ricId->ric_ID.buf, ricId->ric_ID.size);
116 fillBitString(&ricId->ric_ID, unused, byteSize, ricVal);
121 /*******************************************************************
123 * @brief deallocate the memory allocated in E2SetupResponse
127 * Function : FreeE2SetupRsp
129 * Functionality: deallocate the memory allocated in E2SetupResponse
131 * @params[in] E2AP_PDU_t *e2apMsg
134 * ****************************************************************/
135 void FreeE2SetupRsp(E2AP_PDU_t *e2apMsg)
138 E2setupResponse_t *e2SetupRsp;
142 if(e2apMsg->choice.successfulOutcome)
144 e2SetupRsp = &e2apMsg->choice.successfulOutcome->value.choice.E2setupResponse;
145 if(e2SetupRsp->protocolIEs.list.array)
147 for(arrIdx=0; arrIdx<e2SetupRsp->protocolIEs.list.count; arrIdx++)
149 RIC_FREE(e2SetupRsp->protocolIEs.list.array[arrIdx], sizeof(E2setupResponseIEs_t));
151 RIC_FREE(e2SetupRsp->protocolIEs.list.array, e2SetupRsp->protocolIEs.list.size);
153 RIC_FREE(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
155 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
159 /*******************************************************************
161 * @brief Build E2node Component config addition ack list
165 * Function : BuildE2nodeComponentConfigAdditionAck
167 * Functionality: deallocate the memory allocated in E2SetupResponse
169 * @params[in] E2nodeComponentConfigAdditionAck_List_t
170 * *e2NodeConfigAdditionAckList
172 * @return ROK - success
174 * ****************************************************************/
175 uint8_t BuildE2nodeComponentConfigAdditionAck(E2nodeComponentConfigAdditionAck_List_t *e2NodeConfigAdditionAckList, uint8_t duId)
178 E2nodeComponentConfigAdditionAck_ItemIEs_t *e2NodeAddAckItem;
180 e2NodeConfigAdditionAckList->list.count = 1;
181 e2NodeConfigAdditionAckList->list.size = e2NodeConfigAdditionAckList->list.count * sizeof(E2nodeComponentConfigAdditionAck_ItemIEs_t*);
182 RIC_ALLOC(e2NodeConfigAdditionAckList->list.array, e2NodeConfigAdditionAckList->list.size);
183 if(e2NodeConfigAdditionAckList->list.array == NULLP)
185 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2nodeComponentConfigAdditionAck %d",__LINE__);
189 for(arrIdx = 0; arrIdx< e2NodeConfigAdditionAckList->list.count; arrIdx++)
191 RIC_ALLOC(e2NodeConfigAdditionAckList->list.array[arrIdx], sizeof(E2nodeComponentConfigAdditionAck_ItemIEs_t));
192 if(e2NodeConfigAdditionAckList->list.array[arrIdx] == NULLP)
194 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2nodeComponentConfigAdditionAck %d",__LINE__);
198 e2NodeAddAckItem = (E2nodeComponentConfigAdditionAck_ItemIEs_t*) e2NodeConfigAdditionAckList->list.array[0];
199 e2NodeAddAckItem->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck_Item;
200 e2NodeAddAckItem->criticality = CriticalityE2_reject;
201 e2NodeAddAckItem->value.present = E2nodeComponentConfigAdditionAck_ItemIEs__value_PR_E2nodeComponentConfigAdditionAck_Item;
202 e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentInterfaceType = E2nodeComponentInterfaceType_f1;
204 /* >E2 Node Component ID */
205 e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.present = E2nodeComponentID_PR_e2nodeComponentInterfaceTypeF1;
206 RIC_ALLOC(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1,\
207 sizeof(E2nodeComponentInterfaceF1_t));
208 if(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1 == NULLP)
210 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2nodeComponentConfigAdditionAck %d",__LINE__);
213 e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size = sizeof(uint8_t);
214 RIC_ALLOC(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf,\
215 e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size);
217 if(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf == NULLP)
219 DU_LOG("\nERROR -->list. E2AP: Memory allocation failed for BuildE2nodeComponentConfigAdditionAck %d",__LINE__);
222 e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf[0] = duId;
224 /* >E2 Node Component Configuration Acknowledge*/
225 e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentConfigurationAck.updateOutcome = \
226 E2nodeComponentConfigurationAck__updateOutcome_success;
230 /*******************************************************************
232 * @brief Builds and sends the E2SetupResponse
236 * Function : BuildAndSendE2SetupRsp
238 * Functionality: Constructs the F1SetupResponse message and sends
239 * it back to the DU through SCTP.
241 * @params[in] void **buf,Buffer to which encoded pattern is written into
242 * @params[in] int *size,size of buffer
244 * @return ROK - success
247 * ****************************************************************/
248 uint8_t BuildAndSendE2SetupRsp(uint8_t duId)
250 E2AP_PDU_t *e2apMsg = NULL;
251 E2setupResponse_t *e2SetupRsp;
252 asn_enc_rval_t encRetVal;
255 bool memAllocFailed = false;
257 DU_LOG("\nINFO --> E2AP : Building E2 Setup Response\n");
260 RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
263 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
266 e2apMsg->present = E2AP_PDU_PR_successfulOutcome;
267 RIC_ALLOC(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
268 if(e2apMsg->choice.successfulOutcome == NULLP)
270 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
274 e2apMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_E2setup;
275 e2apMsg->choice.successfulOutcome->criticality = CriticalityE2_reject;
276 e2apMsg->choice.successfulOutcome->value.present = \
277 SuccessfulOutcomeE2__value_PR_E2setupResponse;
278 e2SetupRsp = &e2apMsg->choice.successfulOutcome->value.choice.E2setupResponse;
281 e2SetupRsp->protocolIEs.list.count = elementCnt;
282 e2SetupRsp->protocolIEs.list.size = elementCnt * sizeof(E2setupResponseIEs_t);
284 RIC_ALLOC(e2SetupRsp->protocolIEs.list.array, e2SetupRsp->protocolIEs.list.size);
285 if(e2SetupRsp->protocolIEs.list.array == NULLP)
287 DU_LOG("\nERROR --> E2AP : Memory allocation for E2ResponseIEs failed");
291 for(idx=0; idx<elementCnt; idx++)
293 RIC_ALLOC(e2SetupRsp->protocolIEs.list.array[idx], sizeof(E2setupResponseIEs_t));
294 if(e2SetupRsp->protocolIEs.list.array[idx] == NULLP)
296 DU_LOG("\nERROR --> E2AP : Memory allocation for E2ResponseIEs failed");
297 memAllocFailed = true;
302 if(memAllocFailed == true)
304 DU_LOG("\nERROR --> E2AP : Memory allocation for E2ResponseIEs failed");
309 e2SetupRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_TransactionID;
310 e2SetupRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
311 e2SetupRsp->protocolIEs.list.array[idx]->value.present = E2setupResponseIEs__value_PR_TransactionID;
312 e2SetupRsp->protocolIEs.list.array[idx]->value.choice.TransactionID = TRANS_ID;
316 e2SetupRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_GlobalRIC_ID;
317 e2SetupRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
318 e2SetupRsp->protocolIEs.list.array[idx]->value.present = \
319 E2setupResponseIEs__value_PR_GlobalRIC_ID;
321 if(BuildGlobalRicId(&(e2SetupRsp->protocolIEs.list.array[idx]->value.choice.GlobalRIC_ID))!=ROK)
323 DU_LOG("\nERROR --> E2AP : Failed to build Global Ric Id");
327 /* E2 Node Component Configuration Addition Acknowledge List*/
329 e2SetupRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck;
330 e2SetupRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
331 e2SetupRsp->protocolIEs.list.array[idx]->value.present = \
332 E2setupResponseIEs__value_PR_E2nodeComponentConfigAdditionAck_List;
333 if(BuildE2nodeComponentConfigAdditionAck(&e2SetupRsp->protocolIEs.list.array[idx]->value.choice.E2nodeComponentConfigAdditionAck_List, duId)!=ROK)
335 DU_LOG("\nERROR --> E2AP : Failed to build E2Node Component config addition ack list");
339 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
340 memset(encBuf, 0, ENC_BUF_MAX_LEN);
342 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
344 /* Check encode results */
345 if(encRetVal.encoded == ENCODE_FAIL)
347 DU_LOG("\nERROR --> E2AP : Could not encode E2SetupResponse structure (at %s)\n",\
348 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
353 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2SetupResponse\n");
354 for(int i=0; i< encBufSize; i++)
356 DU_LOG("%x",encBuf[i]);
360 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL) != ROK)
362 DU_LOG("\nERROR --> E2AP : Sending E2 Setup Response failed");
368 FreeE2SetupRsp(e2apMsg);
372 /*******************************************************************
374 * @brief Builds Ric Request Id
378 * Function : BuildRicRequestId
380 * Functionality: Building the Ric Request Id
382 * @params[in] RICrequestID_t *ricReqId
383 * @return ROK - success
386 * ****************************************************************/
388 uint8_t BuildRicRequestId(RICrequestID_t *ricReqId)
391 if(ricReqId != NULLP)
393 ricReqId->ricRequestorID = 1;
394 ricReqId->ricInstanceID = 1;
399 /*******************************************************************
401 * @brief Fills Ric Action To be Setup Item
405 * Function : fillSetupItems
407 * Functionality: Filling ricAction Id, RicActionType
409 * @params[in] RICaction_ToBeSetup_Item_t *setupItems
410 * @return pointer of type RICaction_ToBeSetup_Item_t
412 * ****************************************************************/
414 RICaction_ToBeSetup_Item_t* fillSetupItems(RICaction_ToBeSetup_Item_t *setupItems)
416 if(setupItems != NULLP)
418 setupItems->ricActionID = 0;
419 setupItems->ricActionType = RICactionType_report;
425 /*******************************************************************
427 * @brief Fills RIC Subscription Details Item List
431 * Function : fillSubsDetails
433 * Functionality: Fill the RIC Subscription Details Items List
435 * @params[in] RICaction_ToBeSetup_ItemIEs_t *items
436 * @return ROK - success
439 * ****************************************************************/
441 uint8_t fillSubsDetails(RICaction_ToBeSetup_ItemIEs_t *items)
445 items->id = ProtocolIE_IDE2_id_RICaction_ToBeSetup_Item;
446 items->criticality = CriticalityE2_ignore;
447 items->value.present = RICaction_ToBeSetup_ItemIEs__value_PR_RICaction_ToBeSetup_Item;
448 fillSetupItems(&(items->value.choice.RICaction_ToBeSetup_Item));
453 /*******************************************************************
455 * @brief builds RIC Subscription Details
459 * Function : BuildsRicSubsDetails
461 * Functionality: Builds the RIC Subscription Details
463 * @params[in] RICsubscriptionDetails_t *subsDetails
464 * @return ROK - success
467 * ****************************************************************/
469 uint8_t BuildRicSubsDetails(RICsubscriptionDetails_t *subsDetails)
474 if(subsDetails != NULLP)
476 /* Octet string to be build here */
477 /* Sending PLMN as Octect string */
478 uint8_t byteSize = 3;
479 subsDetails->ricEventTriggerDefinition.size = byteSize * sizeof(uint8_t);
480 RIC_ALLOC(subsDetails->ricEventTriggerDefinition.buf, subsDetails->ricEventTriggerDefinition.size);
481 buildPlmnId(ricCfgParams.plmn, subsDetails->ricEventTriggerDefinition.buf);
483 subsDetails->ricAction_ToBeSetup_List.list.count = elementCnt;
484 subsDetails->ricAction_ToBeSetup_List.list.size = \
485 elementCnt * sizeof(RICaction_ToBeSetup_ItemIEs_t);
486 RIC_ALLOC(subsDetails->ricAction_ToBeSetup_List.list.array, \
487 subsDetails->ricAction_ToBeSetup_List.list.size);
488 if(subsDetails->ricAction_ToBeSetup_List.list.array == NULLP)
490 DU_LOG("\nERROR --> E2AP : Memory allocation for RICactionToBeSetup Items failed");
493 RIC_ALLOC(subsDetails->ricAction_ToBeSetup_List.list.array[0],\
494 sizeof(RICaction_ToBeSetup_ItemIEs_t));
495 fillSubsDetails(subsDetails->ricAction_ToBeSetup_List.list.array[0]);
500 /*******************************************************************
502 * @brief Builds and Send the RicSubscriptionReq
506 * Function : BuildAndSendRicSubscriptionReq
508 * Functionality:Fills the RicSubscriptionReq
510 * @return ROK - success
513 ******************************************************************/
515 uint8_t BuildAndSendRicSubscriptionReq()
518 E2AP_PDU_t *e2apRicMsg = NULL;
519 RICsubscriptionRequest_t *ricSubscriptionReq;
524 asn_enc_rval_t encRetVal; /* Encoder return value */
525 ricCfgParams.ricSubsStatus = TRUE;
527 DU_LOG("\nINFO --> E2AP : Building RIC Subscription Request\n");
529 RIC_ALLOC(e2apRicMsg, sizeof(E2AP_PDU_t));
530 if(e2apRicMsg == NULLP)
532 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
536 e2apRicMsg->present = E2AP_PDU_PR_initiatingMessage;
537 RIC_ALLOC(e2apRicMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
538 if(e2apRicMsg->choice.initiatingMessage == NULLP)
540 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
541 RIC_FREE(e2apRicMsg, sizeof(E2AP_PDU_t));
544 e2apRicMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICsubscription;
545 e2apRicMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
546 e2apRicMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICsubscriptionRequest;
548 RIC_ALLOC(ricSubscriptionReq, sizeof(RICsubscriptionRequest_t));
549 ricSubscriptionReq = &e2apRicMsg->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
552 ricSubscriptionReq->protocolIEs.list.count = elementCnt;
553 ricSubscriptionReq->protocolIEs.list.size = elementCnt * sizeof(RICsubscriptionRequest_IEs_t);
555 /* Initialize the subscription members */
556 RIC_ALLOC(ricSubscriptionReq->protocolIEs.list.array, \
557 ricSubscriptionReq->protocolIEs.list.size);
558 if(ricSubscriptionReq->protocolIEs.list.array == NULLP)
560 DU_LOG("\nERROR --> E2AP : Memory allocation for RICSubscriptionRequestIEs failed");
561 RIC_FREE(e2apRicMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
562 RIC_FREE(e2apRicMsg, (Size)sizeof(E2AP_PDU_t));
566 for(idx=0; idx<elementCnt; idx++)
568 RIC_ALLOC(ricSubscriptionReq->protocolIEs.list.array[idx],\
569 sizeof(RICsubscriptionRequest_IEs_t));
570 if(ricSubscriptionReq->protocolIEs.list.array[idx] == NULLP)
572 for(ieId=0; ieId<idx; ieId++)
574 RIC_FREE(ricSubscriptionReq->protocolIEs.list.array[ieId],\
575 sizeof(RICsubscriptionRequest_IEs_t));
577 RIC_FREE(ricSubscriptionReq->protocolIEs.list.array,\
578 ricSubscriptionReq->protocolIEs.list.size);
579 RIC_FREE(e2apRicMsg->choice.initiatingMessage, \
580 sizeof(InitiatingMessageE2_t));
581 RIC_FREE(e2apRicMsg, sizeof(E2AP_PDU_t));
586 /* Filling RIC Request Id */
588 ricSubscriptionReq->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICrequestID;
589 ricSubscriptionReq->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
590 ricSubscriptionReq->protocolIEs.list.array[idx]->value.present =\
591 RICsubscriptionRequest_IEs__value_PR_RICrequestID;
593 BuildRicRequestId(&ricSubscriptionReq->protocolIEs.list.array[idx]->value.choice.RICrequestID);
596 /* Filling RAN Function Id */
598 ricSubscriptionReq->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RANfunctionID;
599 ricSubscriptionReq->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
600 ricSubscriptionReq->protocolIEs.list.array[idx]->value.present =\
601 RICsubscriptionRequest_IEs__value_PR_RANfunctionID;
602 ricSubscriptionReq->protocolIEs.list.array[idx]->value.choice.RANfunctionID = 1;
605 /* Filling RIC Subscription Details */
607 ricSubscriptionReq->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICsubscriptionDetails;
608 ricSubscriptionReq->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
609 ricSubscriptionReq->protocolIEs.list.array[idx]->value.present =\
610 RICsubscriptionRequest_IEs__value_PR_RICsubscriptionDetails;
612 BuildRicSubsDetails(&(ricSubscriptionReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails));
615 /* Prints the Msg formed */
616 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apRicMsg);
618 memset(encBuf, 0, ENC_BUF_MAX_LEN);
620 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apRicMsg, PrepFinalEncBuf,\
622 if(encRetVal.encoded == ENCODE_FAIL)
624 DU_LOG("\nERROR --> E2AP : Could not encode RicSubscriptionRequest structure (at %s)\n",\
625 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
630 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RicSubscriptionRequest\n");
631 for(int i=0; i< encBufSize; i++)
633 DU_LOG("%x",encBuf[i]);
639 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL) != ROK)
641 DU_LOG("\nERROR --> E2AP : Sending RIC subscription Request failed");
648 /*******************************************************************
650 * @brief process the e2setup request
654 * Function : ProcE2SetupReq
656 * Functionality: process the e2setup request
658 * @return ROK - success
661 ******************************************************************/
663 uint8_t ProcE2SetupReq(E2setupRequest_t *e2SetupReq)
665 uint8_t arrIdx = 0, e2NodeAddListIdx =0;;
666 E2nodeComponentConfigAddition_List_t *e2NodeAddList;
667 E2nodeComponentConfigAddition_ItemIEs_t *e2NodeAddItem;
671 if(e2SetupReq->protocolIEs.list.array)
673 for(arrIdx=0; arrIdx<e2SetupReq->protocolIEs.list.count; arrIdx++)
675 if(e2SetupReq->protocolIEs.list.array[arrIdx])
677 switch(e2SetupReq->protocolIEs.list.array[arrIdx]->id)
679 case ProtocolIE_IDE2_id_E2nodeComponentConfigAddition:
681 e2NodeAddList = &e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List;
682 if(e2NodeAddList->list.array)
684 for(e2NodeAddListIdx = 0; e2NodeAddListIdx< e2NodeAddList->list.count; e2NodeAddListIdx++)
686 if(e2NodeAddList->list.array[e2NodeAddListIdx])
688 e2NodeAddItem = (E2nodeComponentConfigAddition_ItemIEs_t *) e2NodeAddList->list.array[e2NodeAddListIdx];
689 if(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1)
691 if(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->\
694 if(BuildAndSendE2SetupRsp(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.\
695 e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf[0]) !=ROK)
697 DU_LOG("\nERROR --> E2AP : Failed to build and send E2 setup response");
717 /*******************************************************************
719 * @brief Deallocate the memory allocated for E2nodeConfigurationUpdate msg
723 * Function : FreeE2NodeConfigUpdate
726 * - freeing the memory allocated for E2nodeConfigurationUpdate
728 * @params[in] E2AP_PDU_t *e2apMsg
729 * @return ROK - success
732 * ****************************************************************/
733 void FreeE2NodeConfigUpdateAck(E2AP_PDU_t *e2apMsg)
736 E2nodeConfigurationUpdate_t *e2NodeConfigUpdateAck;
740 if(e2apMsg->choice.successfulOutcome != NULLP)
742 e2NodeConfigUpdateAck = &e2apMsg->choice.successfulOutcome->value.choice.E2nodeConfigurationUpdateAcknowledge;
743 if(e2NodeConfigUpdateAck->protocolIEs.list.array != NULLP)
745 for(arrIdx = 0; arrIdx < e2NodeConfigUpdateAck->protocolIEs.list.count; arrIdx++)
747 RIC_FREE(e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdate_t));
749 RIC_FREE(e2NodeConfigUpdateAck->protocolIEs.list.array, e2NodeConfigUpdateAck->protocolIEs.list.size);
751 RIC_FREE(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
753 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
757 /*******************************************************************
759 * @brief Buld and send the E2 node config update msg
763 * Function : BuildAndSendE2NodeConfigUpdate
766 * - Buld and send the E2 node config update msg
767 * @return ROK - success
770 * ****************************************************************/
772 uint8_t BuildAndSendE2NodeConfigUpdateAck()
774 uint8_t arrIdx = 0,elementCnt = 1;
776 E2AP_PDU_t *e2apMsg = NULLP;
777 E2nodeConfigurationUpdateAcknowledge_t *e2NodeConfigUpdateAck = NULLP;
778 asn_enc_rval_t encRetVal; /* Encoder return value */
780 DU_LOG("\nINFO --> E2AP : Building E2 Node config update Ack Message\n");
783 RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
786 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
789 e2apMsg->present = E2AP_PDU_PR_successfulOutcome;
790 RIC_ALLOC(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
791 if(e2apMsg->choice.successfulOutcome == NULLP)
793 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
794 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
798 e2apMsg->choice.successfulOutcome->criticality = CriticalityE2_reject;
799 e2apMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_E2nodeConfigurationUpdate;
800 e2apMsg->choice.successfulOutcome->value.present = SuccessfulOutcomeE2__value_PR_E2nodeConfigurationUpdateAcknowledge;
801 e2NodeConfigUpdateAck = &e2apMsg->choice.successfulOutcome->value.choice.E2nodeConfigurationUpdateAcknowledge;
803 e2NodeConfigUpdateAck->protocolIEs.list.count = elementCnt;
804 e2NodeConfigUpdateAck->protocolIEs.list.size = elementCnt * sizeof(E2nodeConfigurationUpdateAcknowledge_IEs_t*);
805 /* Initialize the Ric Indication members */
806 RIC_ALLOC(e2NodeConfigUpdateAck->protocolIEs.list.array, \
807 e2NodeConfigUpdateAck->protocolIEs.list.size);
808 if(e2NodeConfigUpdateAck->protocolIEs.list.array == NULLP)
810 DU_LOG("\nERROR --> E2AP : Memory allocation for e2NodeConfigUpdateAck failed");
814 for(arrIdx =0; arrIdx<elementCnt; arrIdx++)
816 RIC_ALLOC(e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdateAcknowledge_IEs_t));
817 if(e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx] == NULLP)
820 DU_LOG("\nERROR --> E2AP : Memory allocation for e2NodeConfigUpdateAck failed");
827 e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
828 e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
829 e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx]->value.present = E2nodeConfigurationUpdateAcknowledge_IEs__value_PR_TransactionID;
830 e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = TRANS_ID;
833 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
835 memset(encBuf, 0, ENC_BUF_MAX_LEN);
837 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
839 if(encRetVal.encoded == ENCODE_FAIL)
841 DU_LOG("\nERROR --> E2AP : Could not encode E2 Node config update ack structure (at %s)\n",\
842 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
847 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2 Node config update ack \n");
848 for(int i=0; i< encBufSize; i++)
850 DU_LOG("%x",encBuf[i]);
856 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL) != ROK)
858 DU_LOG("\nERROR --> E2AP : Failed to send E2 Node config update ack ");
865 FreeE2NodeConfigUpdateAck(e2apMsg);
869 /*******************************************************************
871 * @brief Handles received E2AP message and sends back response
875 * Function : E2APMsgHdlr
878 * - Decodes received E2AP control message
879 * - Prepares response message, encodes and sends to SCTP
882 * @return ROK - success
885 * ****************************************************************/
886 void E2APMsgHdlr(Buffer *mBuf)
893 asn_dec_rval_t rval; /* Decoder return value */
894 E2AP_PDU_t e2apasnmsg ;
896 DU_LOG("\nINFO --> E2AP : Received E2AP message buffer");
897 ODU_PRINT_MSG(mBuf, 0,0);
899 /* Copy mBuf into char array to decode it */
900 ODU_GET_MSG_LEN(mBuf, &recvBufLen);
901 RIC_ALLOC(recvBuf, (Size)recvBufLen);
905 DU_LOG("\nERROR --> E2AP : Memory allocation failed");
908 if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, ©Cnt) != ROK)
910 DU_LOG("\nERROR --> E2AP : Failed while copying %d", copyCnt);
914 DU_LOG("\nDEBUG --> E2AP : Received flat buffer to be decoded : ");
915 for(i=0; i< recvBufLen; i++)
917 DU_LOG("%x",recvBuf[i]);
920 /* Decoding flat buffer into E2AP messsage */
921 e2apMsg = &e2apasnmsg;
922 memset(e2apMsg, 0, sizeof(E2AP_PDU_t));
924 rval = aper_decode(0, &asn_DEF_E2AP_PDU, (void **)&e2apMsg, recvBuf, recvBufLen, 0, 0);
925 RIC_FREE(recvBuf, (Size)recvBufLen);
927 if(rval.code == RC_FAIL || rval.code == RC_WMORE)
929 DU_LOG("\nERROR --> E2AP : ASN decode failed");
933 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
935 switch(e2apMsg->present)
937 case E2AP_PDU_PR_initiatingMessage:
939 switch(e2apMsg->choice.initiatingMessage->value.present)
941 case InitiatingMessageE2__value_PR_E2setupRequest:
943 DU_LOG("\nINFO --> E2AP : E2 setup request received");
944 ProcE2SetupReq(&e2apMsg->choice.initiatingMessage->value.choice.E2setupRequest);
947 case InitiatingMessageE2__value_PR_E2nodeConfigurationUpdate:
949 DU_LOG("\nINFO --> E2AP : E2 node config update received");
950 BuildAndSendE2NodeConfigUpdateAck();
953 case InitiatingMessageE2__value_PR_RICindication:
955 DU_LOG("\nINFO --> E2AP : RIC Indication Acknowledged");
960 DU_LOG("\nERROR --> E2AP : Invalid type of intiating message [%d]",e2apMsg->choice.initiatingMessage->value.present);
963 }/* End of switch(initiatingMessage) */
966 case E2AP_PDU_PR_successfulOutcome:
968 switch(e2apMsg->choice.successfulOutcome->value.present)
970 case SuccessfulOutcomeE2__value_PR_RICsubscriptionResponse:
972 DU_LOG("\nINFO --> E2AP : RICsubscriptionResponse Msg Acknowledged");
977 DU_LOG("\nERROR --> E2AP : Invalid type of successfulOutcome message [%d]",e2apMsg->choice.successfulOutcome->value.present);
986 DU_LOG("\nERROR --> E2AP : Invalid type message type ");
990 }/* End of switch(e2apMsg->present) */
992 if(!ricCfgParams.ricSubsStatus)
993 BuildAndSendRicSubscriptionReq();
995 } /* End of E2APMsgHdlr */
998 /**********************************************************************
1000 **********************************************************************/