Implementation of UE context release command JIRA ID = ODUHIGH-330 07/5907/3
authorsphoorthi <sphoorthi.dayanand@radisys.com>
Mon, 19 Apr 2021 14:52:06 +0000 (20:22 +0530)
committersphoorthi <sphoorthi.dayanand@radisys.com>
Thu, 22 Apr 2021 07:58:09 +0000 (13:28 +0530)
Change-Id: Ia89179ead427528d4703ee06b8031b952ab30cf0
Signed-off-by: sphoorthi <sphoorthi.dayanand@radisys.com>
Signed-off-by: lal.harshita <harshita.lal@radisys.com>
Signed-off-by: sphoorthi <sphoorthi.dayanand@radisys.com>
src/cu_stub/cu_f1ap_msg_hdl.c
src/cu_stub/cu_f1ap_msg_hdl.h
src/du_app/du_f1ap_msg_hdl.c
src/du_app/du_ue_mgr.c

index f7db5fb..ed7194f 100644 (file)
 #define DMRS_ADDITIONAL_POS  0          /* DMRS Additional poistion */
 #define RES_ALLOC_TYPE       1          /* Resource allocation type */
 #define FIVE_QI_VALUE 9  /*spec 23.501, Table 5.7.4-1*/
-
 /*******************************************************************
 *
 * @brief Sends F1 msg over SCTP
@@ -7356,6 +7355,247 @@ uint8_t BuildAndSendUeContextModificationReq()
 
    }
    FreeUeContextModicationRequest(f1apMsg);
+   return ret;
+}
+/*****************************************************************i
+*
+* @brief Free memory allocated for UE Context Release Command  
+*
+* @details
+*
+*    Function : FreeUeContextReleaseCommand
+*
+*    Functionality:
+*         - Free memory allocated for UE Context Release Command 
+*
+* @params[in] F1AP_PDU_t *f1apMsg
+* @return void
+*
+* *************************************************************/
+void FreeUeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
+{
+   uint8_t ieIdx;
+   UEContextReleaseCommand_t *ueReleaseCommand = NULLP;
+
+   if(f1apMsg)
+   {
+      if(f1apMsg->choice.initiatingMessage)
+      {
+         ueReleaseCommand =&f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
+         if(ueReleaseCommand->protocolIEs.list.array)
+         {
+            for(ieIdx=0 ; ieIdx<ueReleaseCommand->protocolIEs.list.count; ieIdx++)
+            {
+               CU_FREE(ueReleaseCommand->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseCommand_t));
+            }
+            CU_FREE(ueReleaseCommand->protocolIEs.list.array, ueReleaseCommand->protocolIEs.list.size);
+         }
+         CU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
+      }
+      CU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
+   }
+}
+/*******************************************************************
+ *
+ * @brief Builds the Ue Context Release Command 
+ *
+ * @details
+*
+*    Function : BuildAndSendUeContextReleaseCommand
+*
+*    Functionality: Constructs the Ue Context Release Command 
+*
+* @params[in]
+*
+* @return ROK     - success
+*         RFAILED - failure
+*
+* ****************************************************************/
+uint8_t BuildAndSendUeContextReleaseCommand(uint8_t cuUeF1apId, uint8_t duUeF1apId)
+{
+   bool       memAllocFailed = false;
+   uint8_t    ieIdx = 0,elementCnt = 0, ret = RFAILED, bufLen=0;
+   F1AP_PDU_t *f1apMsg = NULLP;
+   UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
+
+   asn_enc_rval_t         encRetVal;
+   DU_LOG("\nINFO  -->  F1AP : Building Ue context release command\n");
+
+   while(true)
+   {
+      CU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
+      if(f1apMsg == NULLP)
+      {
+         DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseCommand(): Memory allocation for F1AP-PDU");
+         break;
+      }
+
+      f1apMsg->present =  F1AP_PDU_PR_initiatingMessage;
+
+      CU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
+      if(f1apMsg->choice.initiatingMessage == NULLP)
+      {
+         DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseCommand(): Memory allocation for F1AP-PDU failed ");
+         break;
+      }
+      f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_UEContextRelease;
+      f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
+      f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_UEContextReleaseCommand;
+
+      ueContextReleaseCommand =&f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
+
+      elementCnt = 4;
+      ueContextReleaseCommand->protocolIEs.list.count = elementCnt;
+      ueContextReleaseCommand->protocolIEs.list.size = elementCnt*sizeof(UEContextReleaseCommand_t*);
+
+      /* Initialize the UE context modification members */
+      CU_ALLOC(ueContextReleaseCommand->protocolIEs.list.array, ueContextReleaseCommand->protocolIEs.list.size);
+      if(ueContextReleaseCommand->protocolIEs.list.array == NULLP)
+      {
+         DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseCommand():Memory allocation failed");
+         break;
+      }
+
+      for(ieIdx=0 ; ieIdx<elementCnt; ieIdx++)
+      {
+         CU_ALLOC(ueContextReleaseCommand->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseCommand_t));
+         if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx] == NULLP)
+         {
+            DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseCommand(): Memory allocation failed ");
+            memAllocFailed = true;  
+            break;
+         }
+      }
+      
+      if(memAllocFailed == true)
+      {
+         break;
+      }
+      ieIdx=0;
+      ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
+      ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
+      ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.present = \
+      UEContextReleaseCommandIEs__value_PR_GNB_CU_UE_F1AP_ID;
+      ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =cuUeF1apId;
+
+      ieIdx++;
+      ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
+      ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
+      ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.present=\
+      UEContextReleaseCommandIEs__value_PR_GNB_DU_UE_F1AP_ID;
+      ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =duUeF1apId;
+
+      ieIdx++;
+      ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_Cause;
+      ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->criticality = Criticality_ignore;
+      ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.present=\
+      UEContextReleaseCommandIEs__value_PR_Cause;
+      ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.Cause.present = Cause_PR_radioNetwork;
+      ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.Cause.choice.radioNetwork=\
+      CauseRadioNetwork_normal_release;
+     
+      /* RRC Container for RRC release */
+      ieIdx++;
+      ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_RRCContainer;
+      ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->criticality = Criticality_ignore;
+      ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.present = \
+      UEContextReleaseCommandIEs__value_PR_RRCContainer;
+      char secModeBuf[7]={ 0x00, 0x05, 0x13, 0x00, 0x00, 0x00, 0x00};
+      bufLen =7;
+      ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size = bufLen;
+      CU_ALLOC(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,
+      ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
+      if(!ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
+      {
+      DU_LOG("\nERROR  -->  F1AP : Memory allocation for BuildAndSendUeContextSetupReq failed");
+      break;
+      }
+      memset(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf, 0, bufLen);
+      memcpy(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf, secModeBuf, bufLen);
+      
+      xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
+
+      /* Encode the UE Context Release Command type as APER */
+      memset(encBuf, 0, ENC_BUF_MAX_LEN);
+      encBufSize = 0;
+      encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
+            encBuf);
+
+      /* Encode results */
+      if(encRetVal.encoded == ENCODE_FAIL)
+      {
+         DU_LOG("\nERROR  -->  F1AP : Could not encode Release Command structure (at %s)\n",\
+               encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
+         break;
+      }
+      else
+      {
+         DU_LOG("\nDEBUG  -->  F1AP : Created APER encoded buffer for Ue Context Release Command\n");
+         for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
+         {
+            DU_LOG("%x",encBuf[ieIdx]);
+         }
+      }
+
+      if(SendF1APMsg(CU_APP_MEM_REG, CU_POOL) != ROK)
+      {
+         DU_LOG("\nERROR  -->  F1AP : Sending Ue context Release Command failed");
+         break;
+      }
+
+      ret = ROK;
+      break;
+
+   }
+   FreeUeContextReleaseCommand(f1apMsg);
+   return ret;
+}
+/*******************************************************************
+*
+* @brief process Ue context release request 
+*
+* @details
+*
+*    Function : procUeContextReleaseReq 
+*
+*    Functionality:
+*         - process Ue context release request 
+*
+* @params[in] F1AP_PDU_t *f1apMsg
+* @return ROK     - success
+*         RFAILED - failure
+*
+* ****************************************************************/
+uint8_t procUeContextReleaseReq(F1AP_PDU_t *f1apMsg) 
+{
+   uint8_t ieIdx=0, duUeF1apId=0,cuUeF1apId=0;
+
+   UEContextReleaseRequest_t *ueReleaseReq = NULLP;
+   ueReleaseReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
+   
+   for(ieIdx=0; ieIdx < ueReleaseReq->protocolIEs.list.count; ieIdx++)
+   {
+      switch(ueReleaseReq->protocolIEs.list.array[ieIdx]->id)
+      {
+         case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
+            {
+               cuUeF1apId = ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
+               break;
+            }
+         case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
+            {
+               duUeF1apId = ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
+               break;
+            }
+         default:
+              break;
+      }
+   }
+   if(BuildAndSendUeContextReleaseCommand(cuUeF1apId, duUeF1apId) != ROK)
+   {
+      DU_LOG("\nERROR  -->  F1AP : procUeContextReleaseReq(): Failed to build Ue Context Release Command ");
+      return RFAILED;
+   }
    return ROK;
 }
 /*******************************************************************
@@ -7473,6 +7713,7 @@ void F1APMsgHdlr(Buffer *mBuf)
                case InitiatingMessage__value_PR_UEContextReleaseRequest:
                   {
                      DU_LOG("\nINFO  -->  F1AP : Received UE Context Release Request");
+                     procUeContextReleaseReq(f1apMsg);
                      break;
                   }
                default:
index 776a02b..002113e 100644 (file)
@@ -76,6 +76,7 @@ typedef struct f1apDb
 F1apMsgDb f1apMsgDb;
 void F1APMsgHdlr(Buffer *mBuf);
 uint8_t BuildAndSendUeContextModificationReq();
+uint8_t BuildAndSendUeContextReleaseCommand(uint8_t cuUeF1apId, uint8_t duUeF1apId);
 /**********************************************************************
          End of file
 **********************************************************************/
index 0ab9f3b..4975304 100644 (file)
@@ -9291,7 +9291,7 @@ uint8_t procUeReCfgCellInfo(MacUeCfg *macUeCfg, void *cellInfo)
  * ****************************************************************/
 void duFillModulationDetails(MacUeCfg *ueCfg, MacUeCfg *oldUeCfg, void *ueCap)
 {
-   UE_NR_Capability_t *ueNrCap;
+   UE_NR_Capability_t *ueNrCap=NULLP;
 
    if(ueCap)
       ueNrCap = (UE_NR_Capability_t *)ueCap;
@@ -12639,7 +12639,81 @@ uint8_t BuildAndSendUeContextReleaseComplete(uint32_t  gnbCuUeF1apId, uint32_t
    /*TODO: To add trigger for UE context release complete, once the operations of UE context
     * release command are done*/
 }
+/*******************************************************************
+*
+* @brief added free part for the memory allocated by aper_decoder 
+*
+* @details
+*
+*    Function : freeAperDecodeUeContextReleaseCommand 
+*
+*    Functionality: added free part for the memory allocated by aper_decoder
+*
+* @params[in] F1AP_PDU_t *f1apMsg
+* @return void
+*
+* ****************************************************************/
+void freeAperDecodeUeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
+{
+   uint8_t ieIdx=0;
+   UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
 
+   ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
+   
+   if(ueContextReleaseCommand->protocolIEs.list.array)
+   {
+      for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
+      {
+         if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
+         {
+            switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
+            {
+               case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
+                  break;
+               case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
+                  break;
+               case ProtocolIE_ID_id_Cause:
+                  break;
+               case ProtocolIE_ID_id_RRCContainer:
+               {
+                  if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
+                  {
+                     free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
+                  }
+                  break;
+               }
+               default :
+                  DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
+                       ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
+                  break;
+            }
+         }
+         free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]);
+      }
+      free(ueContextReleaseCommand->protocolIEs.list.array);
+   }
+}
+/*******************************************************************
+*
+* @brief processing of UE Context Release Command
+*
+* @details
+*
+*    Function : procF1UeContextReleaseCommand 
+*
+*    Functionality: processing of UE Context Release Command
+*
+* @params[in] F1AP_PDU_t *f1apMsg
+* @return void
+*
+* ****************************************************************/
+uint8_t procF1UeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
+{
+   /*TODO: processing of DL RRC Msg Transfer to RLC->SCH->MAC-LOWER-MAC->PHY, if RRC container is received */
+   
+   freeAperDecodeUeContextReleaseCommand(f1apMsg);
+   return ROK;
+}
 /**************************************************************
  *
  * @brief Handles received F1AP message and sends back response  
@@ -12764,6 +12838,11 @@ void F1APMsgHdlr(Buffer *mBuf)
                      procF1UeContextModificationReq(f1apMsg);
                      break;
                   }
+               case InitiatingMessage__value_PR_UEContextReleaseCommand:
+                  {
+                      procF1UeContextReleaseCommand(f1apMsg);
+                      break;
+                  }
                default:
                   {
                      DU_LOG("\nERROR  -->  F1AP : Invalid type of F1AP_PDU_PR_initiatingMessage [%d]",
index 53037ee..ae9f09f 100644 (file)
@@ -1144,8 +1144,10 @@ uint8_t fillMacUeCfg(uint16_t cellId, uint8_t ueIdx, uint16_t crnti, \
             }
          }
          ret = fillAmbr(&macUeCfg->ambrCfg, ueCfgDb->ambrCfg);
-
-         duFillModulationDetails(macUeCfg, duMacDb, ueCfgDb->ueNrCapability);
+         if(ueCfgDb->ueNrCapability != NULLP)
+         {
+            duFillModulationDetails(macUeCfg, duMacDb, ueCfgDb->ueNrCapability);
+         }
       }
 
       /* Filling LC Context */