<[Epic-ID: ODUHIGH-406][Task-ID: ODUHIGH-421]Paging Message: CU_STUB Trigger and...
[o-du/l2.git] / src / du_app / du_e2ap_msg_hdl.c
index edcaf15..c45ed3b 100644 (file)
@@ -57,7 +57,7 @@ uint8_t BuildGlobalgNBId(GlobalE2node_gNB_ID_t *gNbId)
 {
    uint8_t unused = 0;
    uint8_t byteSize = 4;
-   uint8_t val = 1;
+   uint8_t gnbId = 1;
    uint8_t ret = ROK;
 
    /* Allocate Buffer size */
@@ -72,22 +72,22 @@ uint8_t BuildGlobalgNBId(GlobalE2node_gNB_ID_t *gNbId)
    else
    {
       buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
-           gNbId->global_gNB_ID.plmn_id.buf);
+            gNbId->global_gNB_ID.plmn_id.buf);
       /* fill gND Id */
       gNbId->global_gNB_ID.gnb_id.present = GNB_ID_Choice_PR_gnb_ID;
       /* Allocate Buffer size */
       gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size = byteSize * sizeof(uint8_t);
       gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf = NULLP;
       DU_ALLOC(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf, \
-           gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size);
+            gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size);
       if(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf == NULLP)
       {
-        DU_LOG("\nERROR  -->  E2AP: Memory allocation failed for gnb buffer");
-        ret = RFAILED;
+         DU_LOG("\nERROR  -->  E2AP: Memory allocation failed for gnb buffer");
+         ret = RFAILED;
       }
       else
       {
-        fillBitString(&gNbId->global_gNB_ID.gnb_id.choice.gnb_ID, unused, byteSize, val);
+         fillBitString(&gNbId->global_gNB_ID.gnb_id.choice.gnb_ID, unused, byteSize, gnbId);
       }
    }
    return ret;
@@ -381,7 +381,7 @@ void FreeE2SetupReq(E2AP_PDU_t *e2apMsg)
                                 if(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1)
                                 {
                                     DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.\
-                                    e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf,\   
+                                    e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf,\
                                     e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.\
                                     e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size);
                                     DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1,\
@@ -991,6 +991,7 @@ uint8_t procE2SetupRsp(E2AP_PDU_t *e2apMsg)
       }
    }
    freeAperDecodingOfE2SetupRsp(e2SetRspMsg);
+   BuildAndSendE2NodeConfigUpdate();
    return ROK;
 }
 
@@ -1435,6 +1436,158 @@ uint8_t SendE2APMsg(Region region, Pool pool)
    return ROK;
 } /* SendE2APMsg */
 
+/*******************************************************************
+ *
+ * @brief Deallocate the memory allocated for E2nodeConfigurationUpdate msg 
+ *
+ * @details
+ *
+ *    Function : FreeE2NodeConfigUpdate 
+ *
+ *    Functionality:
+ *       - freeing the memory allocated for E2nodeConfigurationUpdate
+ *
+ * @params[in] E2AP_PDU_t *e2apMsg 
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+void FreeE2NodeConfigUpdate(E2AP_PDU_t *e2apMsg)
+{
+   uint8_t arrIdx =0;
+   E2nodeConfigurationUpdate_t *e2NodeConfigUpdate;
+
+   if(e2apMsg != NULLP)
+   {
+      if(e2apMsg->choice.initiatingMessage != NULLP)
+      {
+         e2NodeConfigUpdate = &e2apMsg->choice.initiatingMessage->value.choice.E2nodeConfigurationUpdate;
+         if(e2NodeConfigUpdate->protocolIEs.list.array != NULLP)
+         {
+            for(arrIdx = 0; arrIdx < e2NodeConfigUpdate->protocolIEs.list.count; arrIdx++)
+            {
+               DU_FREE(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdate_IEs_t));
+            }
+            DU_FREE(e2NodeConfigUpdate->protocolIEs.list.array, e2NodeConfigUpdate->protocolIEs.list.size);
+         }
+         DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
+      }
+      DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
+   }
+}
+
+/*******************************************************************
+ *
+ * @brief Buld and send the E2 node config update msg 
+ *
+ * @details
+ *
+ *    Function : BuildAndSendE2NodeConfigUpdate
+ *
+ *    Functionality:
+ *         - Buld and send the E2 node config update msg
+ *
+ * @params[in] 
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+
+uint8_t BuildAndSendE2NodeConfigUpdate()
+{
+   uint8_t arrIdx = 0,elementCnt = 1;
+   uint8_t ret = ROK;
+   E2AP_PDU_t        *e2apMsg = NULLP;
+   E2nodeConfigurationUpdate_t *e2NodeConfigUpdate = NULLP;
+   asn_enc_rval_t     encRetVal;       /* Encoder return value */
+
+   DU_LOG("\nINFO   -->  E2AP : Building E2 Node config update\n");
+   do
+   {
+      DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
+      if(e2apMsg == NULLP)
+      {
+         DU_LOG("\nERROR  -->  E2AP : Memory allocation for E2AP-PDU failed");
+         break;
+      }
+      e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
+      DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
+      if(e2apMsg->choice.initiatingMessage == NULLP)
+      {
+         DU_LOG("\nERROR  -->  E2AP : Memory allocation for E2AP-PDU failed");
+         DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
+         return RFAILED;
+      }
+      e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
+      e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_E2nodeConfigurationUpdate;
+      e2apMsg->choice.initiatingMessage->value.present = \
+      InitiatingMessageE2__value_PR_E2nodeConfigurationUpdate;
+      e2NodeConfigUpdate = &e2apMsg->choice.initiatingMessage->value.choice.E2nodeConfigurationUpdate;
+
+      e2NodeConfigUpdate->protocolIEs.list.count = elementCnt;
+      e2NodeConfigUpdate->protocolIEs.list.size  = elementCnt * sizeof(E2nodeConfigurationUpdate_IEs_t*);
+      /* Initialize the Ric Indication members */
+      DU_ALLOC(e2NodeConfigUpdate->protocolIEs.list.array, \
+            e2NodeConfigUpdate->protocolIEs.list.size);
+      if(e2NodeConfigUpdate->protocolIEs.list.array == NULLP)
+      {
+         DU_LOG("\nERROR  -->  E2AP : Memory allocation for e2NodeConfigUpdate failed");
+         break;
+      }
+      
+      for(arrIdx =0; arrIdx<elementCnt; arrIdx++)
+      {
+         DU_ALLOC(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdate_IEs_t));
+         if(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx] == NULLP)
+         {
+            
+            DU_LOG("\nERROR  -->  E2AP : Memory allocation for e2NodeConfigUpdate failed");
+            break;
+         }
+      }
+
+      arrIdx = 0;
+      /* TransactionID */
+      e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
+      e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
+      e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.present = E2nodeConfigurationUpdate_IEs__value_PR_TransactionID;
+      e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = TRANS_ID;
+
+
+      /* Prints the Msg formed */
+      xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
+
+      memset(encBuf, 0, ENC_BUF_MAX_LEN);
+      encBufSize = 0;
+      encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
+            encBuf);
+      if(encRetVal.encoded == ENCODE_FAIL)
+      {
+         DU_LOG("\nERROR  -->  E2AP : Could not encode E2nodeConfigurationUpdate structure (at %s)\n",\
+               encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
+         break;
+      }
+      else
+      {
+         DU_LOG("\nDEBUG   -->  E2AP : Created APER encoded buffer for E2nodeConfigurationUpdate\n");
+         for(int i=0; i< encBufSize; i++)
+         {
+            printf("%x",encBuf[i]);
+         }
+      }
+      if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL) != ROK)
+      {
+         DU_LOG("\nERROR  -->  E2AP : Sending E2 node config update failed");
+         return RFAILED;
+      }
+
+      break;
+   }while(true);
+   
+   FreeE2NodeConfigUpdate(e2apMsg);
+   return ret;
+}
+
 /*******************************************************************
  *
  * @brief Handles received E2AP message and sends back response  
@@ -1504,50 +1657,55 @@ void E2APMsgHdlr(Buffer *mBuf)
    switch(e2apMsg->present)
    {
       case E2AP_PDU_PR_successfulOutcome:
-        {
-           switch(e2apMsg->choice.successfulOutcome->value.present)
-           {
-              case SuccessfulOutcomeE2__value_PR_E2setupResponse:
-                 {
-                    if(!duCb.e2Status)
-                    {
-                       DU_LOG("\nDEBUG   -->  E2AP : Store E2 setup response Params");
-                       procE2SetupRsp(e2apMsg);
-                    }
-                    break;
-                 }
-              default:
-                 {
-                    DU_LOG("\nERROR  -->  E2AP : Invalid type of E2AP_PDU_PR_successfulOutcome  [%d]",\
-                    e2apMsg->choice.successfulOutcome->value.present);
-                    return;
-                 }
-           }/* End of switch(successfulOutcome) */
-           free(e2apMsg->choice.successfulOutcome);
-           break;
-        }
+         {
+            switch(e2apMsg->choice.successfulOutcome->value.present)
+            {
+               case SuccessfulOutcomeE2__value_PR_E2setupResponse:
+                  {
+                     if(!duCb.e2Status)
+                     {
+                        DU_LOG("\nDEBUG   -->  E2AP : Store E2 setup response Params");
+                        procE2SetupRsp(e2apMsg);
+                     }
+                     break;
+                  }
+               case SuccessfulOutcomeE2__value_PR_E2nodeConfigurationUpdateAcknowledge:
+                  {
+                     DU_LOG("\nDEBUG   -->  E2AP : E2 node Config update ack message recevied");
+                     break;
+                  }
+               default:
+                  {
+                     DU_LOG("\nERROR  -->  E2AP : Invalid type of E2AP_PDU_PR_successfulOutcome  [%d]",\
+                           e2apMsg->choice.successfulOutcome->value.present);
+                     return;
+                  }
+            }/* End of switch(successfulOutcome) */
+            free(e2apMsg->choice.successfulOutcome);
+            break;
+         }
       case E2AP_PDU_PR_initiatingMessage:
-        {
-           switch(e2apMsg->choice.initiatingMessage->value.present)
-           {
-              case InitiatingMessageE2__value_PR_RICsubscriptionRequest: 
-                 {
-                    if(procRicSubsReq(e2apMsg) == ROK)
-                    {
-                       BuildAndSendRicIndication();
-                    }
-                    break;
-                 }
-              default:
-                 {
-                    DU_LOG("\nERROR  -->  E2AP : Invalid type of E2AP_PDU_PR_initiatingMessage [%d]",\
-                    e2apMsg->choice.initiatingMessage->value.present);
-                    return;
-                 }
-           }/* End of switch(initiatingMessage) */
-           free(e2apMsg->choice.initiatingMessage);
-           break;
-        }
+         {
+            switch(e2apMsg->choice.initiatingMessage->value.present)
+            {
+               case InitiatingMessageE2__value_PR_RICsubscriptionRequest: 
+                  {
+                     if(procRicSubsReq(e2apMsg) == ROK)
+                     {
+                        BuildAndSendRicIndication();
+                     }
+                     break;
+                  }
+               default:
+                  {
+                     DU_LOG("\nERROR  -->  E2AP : Invalid type of E2AP_PDU_PR_initiatingMessage [%d]",\
+                           e2apMsg->choice.initiatingMessage->value.present);
+                     return;
+                  }
+            }/* End of switch(initiatingMessage) */
+            free(e2apMsg->choice.initiatingMessage);
+            break;
+         }
       default:
         {
            DU_LOG("\nERROR  -->  E2AP : Invalid type of e2apMsg->present [%d]",e2apMsg->present);