[Epic-ID: ODUHIGH-405][Task-ID: ODUHIGH-414] F1 Setup from multiple DU to one CU
[o-du/l2.git] / src / cu_stub / cu_stub_egtp.c
index 2a0e79c..8657cb2 100644 (file)
 /* This file contains all EGTP related functionality */
 
 #include "common_def.h"
+#include "OCTET_STRING.h"
+#include "cu_stub_sctp.h"
+#include "cu_f1ap_msg_hdl.h"
 #include "cu_stub_egtp.h"
-#include "du_log.h"
-
-/* Global variable declaration */
-EgtpGlobalCb egtpCb;
+#include "cu_stub.h"
+#include "cm_inet.h"
+#include "cm_tpt.h"
+#include "cm_inet.x"
+#include "cm_tpt.x"
 
 /**************************************************************************
  * @brief Task Initiation callback function. 
@@ -49,6 +54,9 @@ S16 egtpActvInit()
 {
   DU_LOG("\n\nDEBUG  -->  EGTP : Initializing");
   memset (&egtpCb, 0, sizeof(EgtpGlobalCb));
+  
+  //Initializing with INVALID value
+  memset(egtpCb.gCntPdu, 0xFF , sizeof(uint8_t)*(MAX_TEID+1)); 
   protType = CM_INET_PROTO_UDP;
   return ROK;
 }
@@ -76,7 +84,6 @@ S16 egtpActvInit()
 uint8_t egtpInitReq()
 {
    uint8_t ret = ROK;
-   EgtpTnlEvt tnlEvt;
 
    ret = cuEgtpCfgReq();
    if(ret != ROK)
@@ -92,16 +99,6 @@ uint8_t egtpInitReq()
        return (ret);
    }
 
-   tnlEvt.action = EGTP_TNL_MGMT_ADD;
-   tnlEvt.lclTeid = 10;
-   tnlEvt.remTeid = 1;
-   ret = cuEgtpTnlMgmtReq(tnlEvt);
-   if(ret != ROK)
-   {
-      DU_LOG("\nERROR  -->  EGTP : Tunnel management request failed");
-      return RFAILED;
-   }
-
    return ret;
 } /* egtpInitReq */
 
@@ -123,7 +120,7 @@ S16 cuEgtpCfgReq()
 {
    uint8_t ret;
 
-   memcpy(&egtpCb.egtpCfg, &cuCfgParams.egtpParams, sizeof(EgtpParams));
+   memcpy(&egtpCb.egtpCfg, &cuCb.cuCfgParams.egtpParams, sizeof(EgtpParams));
 
    egtpCb.recvTptSrvr.addr.address = CM_INET_NTOH_UINT32(egtpCb.egtpCfg.localIp.ipV4Addr);
    egtpCb.recvTptSrvr.addr.port = EGTP_DFLT_PORT;
@@ -309,9 +306,11 @@ S16 cuEgtpTnlAdd(EgtpTnlEvt tnlEvt)
    preDefHdr.teId = teidCb->remTeId;
    preDefHdr.extHdr.pdcpNmb.pres = FALSE;
    preDefHdr.extHdr.udpPort.pres = FALSE;
-   preDefHdr.nPdu.pres = FALSE;
-   
+   preDefHdr.nPdu.pres = TRUE; //Including nPdu when sending data
+   preDefHdr.nPdu.val = 0;
+
    cuEgtpEncodeHdr((uint8_t *)teidCb->preEncodedHdr.hdr, &preDefHdr, &(teidCb->preEncodedHdr.cnt));
+   egtpCb.gCntPdu[teidCb->remTeId] = 0;//Resetting the Cnt Value for this DRB which indicates its creation
 
 /*   SPutSBuf(CU_APP_MEM_REG, CU_POOL, (Data *)teidCb, (Size)sizeof(EgtpTeIdCb));*/
 
@@ -503,8 +502,9 @@ S16 cuEgtpEncodeHdr(uint8_t *preEncodedHdr, EgtpMsgHdr *preDefHdr, uint8_t *hdrI
 S16 cuEgtpHdlRecvMsg(Buffer *mBuf)
 {
    /*Decoding of EGTP message header */
+   
    cuEgtpDecodeHdr(mBuf);
-
+   
    /* Start Pumping data from CU to DU */
    //return (cuEgtpDatReq());
 
@@ -618,32 +618,43 @@ S16 cuEgtpDecodeHdr(Buffer *mBuf)
       ODU_REM_PRE_MSG(&extHdrType, mBuf);
    }
 
-   DU_LOG("\nDEBUG  -->  EGTP : Message Buffer after decoding header ");
+   DU_LOG("\nDEBUG  -->  EGTP : Message Buffer after decoding header [TEID:%d]",egtpMsg.msgHdr.teId);
    ODU_PRINT_MSG(mBuf, 0, 0);
 
+   SPutMsg(mBuf);
+
    return ROK;
      
 } /* End of cuEgtpDecodeHdr */
 
-S16 cuEgtpDatReq()
+uint16_t cuEgtpDatReq(uint8_t teId)
 {
-   uint8_t cnt = 0;
+   uint8_t ret = ROK, cnt = 0;
    EgtpMsg  egtpMsg;
 
+   egtpMsg.msgHdr.teId = teId;
+   
+   if(egtpCb.gCntPdu[teId] == 0xFF) //DRB not created
+   {
+      DU_LOG("\nERROR  -->  EGTP : DRB  not created");
+      return RFAILED ;
+   }
    /* Build Application message that is supposed to come from app to egtp */
-   BuildAppMsg(&egtpMsg);
+   ret = BuildAppMsg(&egtpMsg);
+   if(ret != ROK)
+   {
+      DU_LOG("\nERROR  -->  EGTP : Failed to build App Msg");
+      return RFAILED;
+   }
 
    /* Encode EGTP header to build final EGTP message */
-   BuildEgtpMsg(&egtpMsg);
-
-   /* Send Message to peer */
-   while(cnt < 200)
+   ret = BuildEgtpMsg(&egtpMsg);
+   if(ret != ROK)
    {
-      DU_LOG("\nDEBUG  -->  EGTP : Sending message[%d]", cnt+1);
-      cuEgtpSendMsg(egtpMsg.msg);
-      cnt++;
+      DU_LOG("\nERROR  -->  EGTP : Failed to build EGTP Msg");
+      return RFAILED;
    }
-
+   cuEgtpSendMsg(egtpMsg.msg);
    ODU_PUT_MSG_BUF(egtpMsg.msg);
 
    return ROK;
@@ -652,8 +663,19 @@ S16 cuEgtpDatReq()
 
 S16 BuildAppMsg(EgtpMsg  *egtpMsg)
 {
-   char data[30] = "This is EGTP data from CU";
-   int datSize = 30;
+   char data[1215] = "In telecommunications, 5G is the fifth generation technology standard for broadband cellular"
+   " networks, which cellular phone companies began deploying worldwide in 2019, and is the planned successor to the 4G "
+   " networks which provide connectivity to most current cellphones. 5G networks are predicted to have more than 1.7"
+   " billion subscribers worldwide by 2025, according to the GSM Association.Like its predecessors, 5G networks are"
+   " cellular networks,in which the service area is divided into small geographical areas called cells.All 5G wireless"
+   " devices in a cell are connected to the Internet and telephone network by radio waves through local antenna in the"
+   " cell. The main advantage of the new networks is that they will have greater bandwidth, giving higher download"
+   " speeds, eventually up to 10 gigabits per second(Gbit/s). Due to the increased bandwidth, it is expected the"
+   " networks will not exclusively serve cellphones like existing cellular networks, but also be used as general"
+   " internet service providers for laptops and desktop computers, competing with existing ISPs such as cable"
+   " internet, and also will make possible new applications in internet of things (IoT) and machine to machine areas.";
+
+   int datSize = 1215;
  
    Buffer   *mBuf;
  
@@ -742,17 +764,22 @@ S16 BuildAppMsg(EgtpMsg  *egtpMsg)
    ret = ODU_ADD_PRE_MSG_MULT(revPkArray, (MsgLen)cnt, mBuf);
  
    egtpMsg->msgHdr.msgType = EGTPU_MSG_GPDU;
-   egtpMsg->msgHdr.nPdu.pres = FALSE;
+   egtpMsg->msgHdr.nPdu.pres = TRUE;
+
+   if(egtpCb.gCntPdu[egtpMsg->msgHdr.teId] != NUM_DL_PACKETS)
+     egtpCb.gCntPdu[egtpMsg->msgHdr.teId]++;
+   else
+     egtpCb.gCntPdu[egtpMsg->msgHdr.teId] = 1;
+
+   egtpMsg->msgHdr.nPdu.val = egtpCb.gCntPdu[egtpMsg->msgHdr.teId];
    egtpMsg->msgHdr.seqNum.pres = FALSE;
    egtpMsg->msgHdr.extHdr.udpPort.pres = FALSE;
    egtpMsg->msgHdr.extHdr.pdcpNmb.pres = FALSE;
-   egtpMsg->msgHdr.teId = 10;
    egtpMsg->msg = mBuf;
 
    return ret;
 }
 
-
 S16 BuildEgtpMsg(EgtpMsg *egtpMsg)
 {
    EgtpTeIdCb   *teidCb = NULLP;
@@ -809,11 +836,18 @@ S16 BuildEgtpMsg(EgtpMsg *egtpMsg)
       teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 1] &= ~(EGTP_MASK_BIT2);
    }
 
-   ODU_ADD_PRE_MSG_MULT(&teidCb->preEncodedHdr.hdr[hdrLen], (EGTP_MAX_HDR_LEN - hdrLen), egtpMsg->msg);
-
-   DU_LOG("\nDEBUG  -->  EGTP : Sending message buffer");
-   ODU_PRINT_MSG(egtpMsg->msg, 0, 0);
+   /*Update the nPdU number*/
+   if(egtpMsg->msgHdr.nPdu.pres)
+   {
+      teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 1] |= (EGTP_MASK_BIT1);
+      teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 11] = egtpMsg->msgHdr.nPdu.val;
+   }
+   else
+   {
+      teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 1] &= ~(EGTP_MASK_BIT1);
+   }
 
+   ODU_ADD_PRE_MSG_MULT(&teidCb->preEncodedHdr.hdr[hdrLen], (EGTP_MAX_HDR_LEN - hdrLen), egtpMsg->msg);
    return ROK;
 }