X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fcu_stub%2Fcu_stub_egtp.c;h=dfdacbbb0edcc0b8d531a99f436e41735bde40d9;hb=5d74fef7c9fe6b65a965ceac6bfe812872dab323;hp=1db83d2e99b751368f3efb78b5fa86cc9079a741;hpb=be7e4e372cc1d6f12f7af9c6b6d09a7ecedca58c;p=o-du%2Fl2.git diff --git a/src/cu_stub/cu_stub_egtp.c b/src/cu_stub/cu_stub_egtp.c index 1db83d2e9..dfdacbbb0 100644 --- a/src/cu_stub/cu_stub_egtp.c +++ b/src/cu_stub/cu_stub_egtp.c @@ -18,8 +18,9 @@ /* This file contains all EGTP related functionality */ -#include +#include "common_def.h" #include "cu_stub_egtp.h" +#include "du_log.h" /* Global variable declaration */ EgtpGlobalCb egtpCb; @@ -47,9 +48,9 @@ EgtpGlobalCb egtpCb; S16 egtpActvInit() { DU_LOG("\n\nEGTP : Initializing"); - cmMemset ((U8 *)&egtpCb, 0, sizeof(EgtpGlobalCb)); + memset (&egtpCb, 0, sizeof(EgtpGlobalCb)); protType = CM_INET_PROTO_UDP; - RETVALUE(ROK); + return ROK; } @@ -72,23 +73,23 @@ S16 egtpActvInit() * RFAILED - failure * ***************************************************************************/ -S16 egtpInitReq() +uint8_t egtpInitReq() { - S16 ret = ROK; + uint8_t ret = ROK; EgtpTnlEvt tnlEvt; ret = cuEgtpCfgReq(); if(ret != ROK) { DU_LOG("\nEGTP : Configuration failed"); - RETVALUE(ret); + return (ret); } ret = cuEgtpSrvOpenReq(); if(ret != ROK) { DU_LOG("\nEGTP : Transport server open request failed"); - RETVALUE(ret); + return (ret); } tnlEvt.action = EGTP_TNL_MGMT_ADD; @@ -98,11 +99,10 @@ S16 egtpInitReq() if(ret != ROK) { DU_LOG("\n EGTP : Tunnel management request failed"); - RETVALUE(RFAILED); + return RFAILED; } - RETVALUE(ret); - + return ret; } /* egtpInitReq */ /************************************************************************** @@ -123,7 +123,7 @@ S16 cuEgtpCfgReq() { U8 ret; - cmMemcpy((U8 *)&egtpCb.egtpCfg, (U8 *)&cuCfgParams.egtpParams, (PTR)sizeof(EgtpParams)); + memcpy(&egtpCb.egtpCfg, &cuCfgParams.egtpParams, sizeof(EgtpParams)); egtpCb.recvTptSrvr.addr.address = CM_INET_NTOH_U32(egtpCb.egtpCfg.localIp.ipV4Addr); egtpCb.recvTptSrvr.addr.port = EGTP_DFLT_PORT; @@ -139,14 +139,14 @@ S16 cuEgtpCfgReq() if(ret != ROK) { DU_LOG("\nEGTP : TeId hash list initialization failed"); - RETVALUE(RFAILED); + return RFAILED; } else { DU_LOG("\nEGTP : Configuration successful"); } - RETVALUE(ROK); + return ROK; } /* cuEgtpCfgReq */ /************************************************************************** @@ -174,36 +174,36 @@ S16 cuEgtpSrvOpenReq(Pst *pst) DU_LOG("\nEGTP : Received open server request"); sockType = CM_INET_DGRAM; - if(ret = (cmInetSocket(sockType, &(egtpCb.recvTptSrvr.sockFd), protType)) != ROK) + if((ret = (cmInetSocket(sockType, &(egtpCb.recvTptSrvr.sockFd), protType))) != ROK) { DU_LOG("\nEGTP : Failed to open UDP socket"); - RETVALUE(RFAILED); + return RFAILED; } ret = cmInetBind(&(egtpCb.recvTptSrvr.sockFd), &(egtpCb.recvTptSrvr.addr)); if(ret != ROK) { DU_LOG("\nEGTP : Failed to bind socket"); - RETVALUE(RFAILED); + return RFAILED; } if(ret = (cmInetSocket(sockType, &(egtpCb.dstCb.sendTptSrvr.sockFd), protType)) != ROK) { DU_LOG("\nEGTP : Failed to open UDP socket"); - RETVALUE(RFAILED); + return RFAILED; } ret = cmInetBind(&(egtpCb.dstCb.sendTptSrvr.sockFd), &(egtpCb.dstCb.sendTptSrvr.addr)); if(ret != ROK) { DU_LOG("\nEGTP : Failed to bind socket"); - RETVALUE(RFAILED); + return RFAILED; } /* TODO: set socket options */ DU_LOG("\nEGTP : Receiver socket[%d] and Sender socket[%d] open", egtpCb.recvTptSrvr.sockFd.fd, egtpCb.dstCb.sendTptSrvr.sockFd.fd); - RETVALUE(ROK); + return ROK; } /* cuEgtpSrvOpenReq */ @@ -253,7 +253,7 @@ S16 cuEgtpTnlMgmtReq(EgtpTnlEvt tnlEvt) } } - RETVALUE(ret); + return (ret); } /************************************************************************** @@ -280,15 +280,16 @@ S16 cuEgtpTnlAdd(EgtpTnlEvt tnlEvt) DU_LOG("\nEGTP : Tunnel addition : LocalTeid[%d] Remote Teid[%d]", tnlEvt.lclTeid, tnlEvt.remTeid); - ret = SGetSBuf(CU_APP_MEM_REG, CU_POOL, (Data **)&teidCb, (Size)sizeof(EgtpTeIdCb)); - if(ret != ROK) + CU_ALLOC(teidCb, (Size)sizeof(EgtpTeIdCb)); + + if(teidCb == NULLP) { DU_LOG("\nEGTP : Memory allocation failed"); - RETVALUE(RFAILED); + return RFAILED; } - cmMemset((U8 *)teidCb, 0, sizeof(EgtpTeIdCb)); + memset(teidCb, 0, sizeof(EgtpTeIdCb)); teidCb->teId = tnlEvt.lclTeid; teidCb->remTeId = tnlEvt.remTeid; @@ -296,13 +297,13 @@ S16 cuEgtpTnlAdd(EgtpTnlEvt tnlEvt) if(ret != ROK) { DU_LOG("\nEGTP : Failed to insert in hash list"); - SPutSBuf(CU_APP_MEM_REG, CU_POOL, (Data *)teidCb, (Size)sizeof(EgtpTeIdCb)); - RETVALUE(RFAILED); + CU_FREE(teidCb, (Size)sizeof(EgtpTeIdCb)); + return RFAILED; } egtpCb.dstCb.numTunn++; /* Encoding pre-defined header */ - cmMemset((U8*)&preDefHdr, 0, sizeof(EgtpMsgHdr)); + memset(&preDefHdr, 0, sizeof(EgtpMsgHdr)); preDefHdr.msgType = EGTPU_MSG_GPDU; preDefHdr.teId = teidCb->remTeId; preDefHdr.extHdr.pdcpNmb.pres = FALSE; @@ -313,7 +314,7 @@ S16 cuEgtpTnlAdd(EgtpTnlEvt tnlEvt) /* SPutSBuf(CU_APP_MEM_REG, CU_POOL, (Data *)teidCb, (Size)sizeof(EgtpTeIdCb));*/ - RETVALUE(ROK); + return ROK; } /* cuEgtpTnlAdd */ /************************************************************************** @@ -343,13 +344,13 @@ S16 cuEgtpTnlMod(EgtpTnlEvt tnlEvt) if(teidCb == NULLP) { printf("\nTunnel id not found"); - RETVALUE(RFAILED); + return RFAILED; } teidCb->teId = tnlEvt.lclTeid; teidCb->remTeId = tnlEvt.remTeid; #endif - RETVALUE(ROK); + return ROK; } /************************************************************************** @@ -377,14 +378,14 @@ S16 cuEgtpTnlDel(EgtpTnlEvt tnlEvt) if(teidCb == NULLP) { DU_LOG("\nEGTP : Tunnel id[%d] not configured", tnlEvt.lclTeid); - RETVALUE(RFAILED); + return RFAILED; } cmHashListDelete(&(egtpCb.dstCb.teIdLst), (PTR)teidCb); - SPutSBuf(CU_APP_MEM_REG, CU_POOL, (Data *)teidCb, (Size)sizeof(EgtpTeIdCb)); + CU_FREE(teidCb, (Size)sizeof(EgtpTeIdCb)); egtpCb.dstCb.numTunn--; - RETVALUE(ROK); + return ROK; } /* cuEgtpTnlDel */ /******************************************************************* @@ -494,7 +495,7 @@ S16 cuEgtpEncodeHdr(U8 *preEncodedHdr, EgtpMsgHdr *preDefHdr, U8 *hdrIdx) } *hdrIdx = cnt; - RETVALUE(ROK); + return ROK; } /* egtpEncodeHdr */ @@ -504,14 +505,13 @@ S16 cuEgtpHdlRecvMsg(Buffer *mBuf) cuEgtpDecodeHdr(mBuf); /* Start Pumping data from CU to DU */ - RETVALUE(cuEgtpDatReq()); + return (cuEgtpDatReq()); } S16 cuEgtpDecodeHdr(Buffer *mBuf) { EgtpMsg egtpMsg; - S16 retVal = ROK; /* Holds the return value */ U8 tmpByte[5]; /* Holds one byte of data after Dec */ U8 version = 0; /* Holds the version type, decoded */ MsgLen msgLen = 0; /* Holds the msgLen from the Hdr */ @@ -520,25 +520,25 @@ S16 cuEgtpDecodeHdr(Buffer *mBuf) U8 extHdrLen = 0; /* Extension hdr length */ Bool extPres = FALSE; /* Flag for indication of S, E or P presense flag */ - SFndLenMsg(mBuf, &bufLen); + ODU_GET_MSG_LEN(mBuf, &bufLen); /* Decode version */ - SRemPreMsg(&tmpByte[0], mBuf); + ODU_REM_PRE_MSG(&tmpByte[0], mBuf); version = tmpByte[0] >> 5; /* Decode message type */ - SRemPreMsg((Data*)&(egtpMsg.msgHdr.msgType), mBuf); + ODU_REM_PRE_MSG((Data*)&(egtpMsg.msgHdr.msgType), mBuf); /* Decode message length */ - SRemPreMsg(&tmpByte[1], mBuf); - SRemPreMsg(&tmpByte[2], mBuf); + ODU_REM_PRE_MSG(&tmpByte[1], mBuf); + ODU_REM_PRE_MSG(&tmpByte[2], mBuf); msgLen = (tmpByte[1] << 8) | tmpByte[2]; /* Decode tunnel id */ - SRemPreMsg(&tmpByte[1], mBuf); - SRemPreMsg(&tmpByte[2], mBuf); - SRemPreMsg(&tmpByte[3], mBuf); - SRemPreMsg(&tmpByte[4], mBuf); + ODU_REM_PRE_MSG(&tmpByte[1], mBuf); + ODU_REM_PRE_MSG(&tmpByte[2], mBuf); + ODU_REM_PRE_MSG(&tmpByte[3], mBuf); + ODU_REM_PRE_MSG(&tmpByte[4], mBuf); egtpMsg.msgHdr.teId = (tmpByte[1] << 24) | (tmpByte[2] << 16) | (tmpByte[3] << 8) | tmpByte[4]; if((tmpByte[0] & EGTP_MASK_BIT1) || (tmpByte[0] & EGTP_MASK_BIT2)||(tmpByte[0] & EGTP_MASK_BIT3)) @@ -550,15 +550,15 @@ S16 cuEgtpDecodeHdr(Buffer *mBuf) if ( tmpByte[0] & EGTP_MASK_BIT2 ) { egtpMsg.msgHdr.seqNum.pres = TRUE; - SRemPreMsg(&tmpByte[1], mBuf); - SRemPreMsg(&tmpByte[2], mBuf); + ODU_REM_PRE_MSG(&tmpByte[1], mBuf); + ODU_REM_PRE_MSG(&tmpByte[2], mBuf); egtpMsg.msgHdr.seqNum.val = (tmpByte[1] << 8) | tmpByte[2]; } else if(extPres) { egtpMsg.msgHdr.seqNum.pres = 0; - SRemPreMsg(&tmpByte[1], mBuf); - SRemPreMsg(&tmpByte[2], mBuf); + ODU_REM_PRE_MSG(&tmpByte[1], mBuf); + ODU_REM_PRE_MSG(&tmpByte[2], mBuf); egtpMsg.msgHdr.seqNum.val = (tmpByte[1] << 8) | tmpByte[2]; } @@ -566,29 +566,29 @@ S16 cuEgtpDecodeHdr(Buffer *mBuf) if ( tmpByte[0] & EGTP_MASK_BIT1 ) { egtpMsg.msgHdr.nPdu.pres = TRUE; - SRemPreMsg(&(egtpMsg.msgHdr.nPdu.val), mBuf); + ODU_REM_PRE_MSG(&(egtpMsg.msgHdr.nPdu.val), mBuf); } else if(extPres) { egtpMsg.msgHdr.nPdu.pres = TRUE; - SRemPreMsg(&(egtpMsg.msgHdr.nPdu.val), mBuf); + ODU_REM_PRE_MSG(&(egtpMsg.msgHdr.nPdu.val), mBuf); } if(extPres & EGTP_MASK_BIT1) { - SRemPreMsg(&extHdrType, mBuf); + ODU_REM_PRE_MSG(&extHdrType, mBuf); while( 0 != extHdrType) { switch (extHdrType) { case EGTP_EXT_HDR_UDP_TYPE: { - SRemPreMsg(&extHdrLen, mBuf); + ODU_REM_PRE_MSG(&extHdrLen, mBuf); if(extHdrLen == 0x01) { egtpMsg.msgHdr.extHdr.udpPort.pres = TRUE; - SRemPreMsg(&tmpByte[1], mBuf); - SRemPreMsg(&tmpByte[2], mBuf); + ODU_REM_PRE_MSG(&tmpByte[1], mBuf); + ODU_REM_PRE_MSG(&tmpByte[2], mBuf); egtpMsg.msgHdr.extHdr.udpPort.val = (tmpByte[1] << 8) | tmpByte[2]; } break; @@ -596,31 +596,31 @@ S16 cuEgtpDecodeHdr(Buffer *mBuf) case EGTP_EXT_HDR_PDCP_TYPE: { - SRemPreMsg(&extHdrLen, mBuf); + ODU_REM_PRE_MSG(&extHdrLen, mBuf); if(extHdrLen == 0x01) { egtpMsg.msgHdr.extHdr.pdcpNmb.pres = TRUE; - SRemPreMsg(&tmpByte[1], mBuf); - SRemPreMsg(&tmpByte[2], mBuf); + ODU_REM_PRE_MSG(&tmpByte[1], mBuf); + ODU_REM_PRE_MSG(&tmpByte[2], mBuf); egtpMsg.msgHdr.extHdr.pdcpNmb.val = (tmpByte[1] << 8) | tmpByte[2]; } break; } } /* End of switch */ - SRemPreMsg(&extHdrType, mBuf); + ODU_REM_PRE_MSG(&extHdrType, mBuf); } /* End of while */ } /* End of if(extPres & EGTP_MASK_BIT1) */ else if(extPres) { - SRemPreMsg(&extHdrType, mBuf); + ODU_REM_PRE_MSG(&extHdrType, mBuf); } DU_LOG("\nEGTP : Message Buffer after decoding header "); - SPrntMsg(mBuf, 0, 0); + ODU_PRINT_MSG(mBuf, 0, 0); - RETVALUE(ROK); + return ROK; } /* End of cuEgtpDecodeHdr */ @@ -643,9 +643,9 @@ S16 cuEgtpDatReq() cnt++; } - SPutMsg(egtpMsg.msg); + ODU_PUT_MSG_BUF(egtpMsg.msg); - RETVALUE(ROK); + return ROK; } @@ -656,19 +656,19 @@ S16 BuildAppMsg(EgtpMsg *egtpMsg) Buffer *mBuf; - if(SGetMsg(CU_APP_MEM_REG, CU_POOL, &mBuf) == ROK) + if(ODU_GET_MSG_BUF(CU_APP_MEM_REG, CU_POOL, &mBuf) == ROK) { - if(SAddPstMsgMult((Data *)data, datSize, mBuf) != ROK) + if(ODU_ADD_POST_MSG_MULT((Data *)data, datSize, mBuf) != ROK) { - DU_LOG("\nEGTP : SAddPstMsgMult failed"); - SPutMsg(mBuf); - RETVALUE(RFAILED); + DU_LOG("\nEGTP : ODU_ADD_POST_MSG_MULT failed"); + ODU_PUT_MSG_BUF(mBuf); + return RFAILED; } } else { DU_LOG("\nEGTP : Failed to allocate memory"); - RETVALUE(RFAILED); + return RFAILED; } /* filling IPv4 header */ @@ -676,9 +676,9 @@ S16 BuildAppMsg(EgtpMsg *egtpMsg) MsgLen mLen; mLen = 0; - SFndLenMsg(mBuf, &mLen); + ODU_GET_MSG_LEN(mBuf, &mLen); - cmMemset((U8 *)&ipv4Hdr, 0, sizeof(CmIpv4Hdr)); + memset(&ipv4Hdr, 0, sizeof(CmIpv4Hdr)); ipv4Hdr.length = CM_IPV4_HDRLEN + mLen; ipv4Hdr.hdrVer = 0x45; ipv4Hdr.proto = 1; @@ -692,8 +692,8 @@ S16 BuildAppMsg(EgtpMsg *egtpMsg) /* initialize locals */ cnt = 0; - cmMemset(revPkArray, 0, CM_IPV4_HDRLEN); - cmMemset(pkArray, 0, CM_IPV4_HDRLEN); + memset(revPkArray, 0, CM_IPV4_HDRLEN); + memset(pkArray, 0, CM_IPV4_HDRLEN); /* Pack Header Version */ pkArray[cnt++] = ipv4Hdr.hdrVer; @@ -738,7 +738,7 @@ S16 BuildAppMsg(EgtpMsg *egtpMsg) revPkArray[idx] = pkArray[CM_IPV4_HDRLEN - idx -1]; /* this function automatically reverses revPkArray */ - ret = SAddPreMsgMult(revPkArray, (MsgLen)cnt, mBuf); + ret = ODU_ADD_PRE_MSG_MULT(revPkArray, (MsgLen)cnt, mBuf); egtpMsg->msgHdr.msgType = EGTPU_MSG_GPDU; egtpMsg->msgHdr.nPdu.pres = FALSE; @@ -748,7 +748,7 @@ S16 BuildAppMsg(EgtpMsg *egtpMsg) egtpMsg->msgHdr.teId = 10; egtpMsg->msg = mBuf; - RETVALUE(ROK); + return ret; } @@ -764,7 +764,7 @@ S16 BuildEgtpMsg(EgtpMsg *egtpMsg) if(teidCb == NULLP) { DU_LOG("\nEGTP : Tunnel id[%d] not configured", egtpMsg->msgHdr.teId); - RETVALUE(LCM_REASON_INVALID_PAR_VAL); + return (LCM_REASON_INVALID_PAR_VAL); } msgHdr = &(egtpMsg->msgHdr); @@ -785,7 +785,7 @@ S16 BuildEgtpMsg(EgtpMsg *egtpMsg) teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 1] &= ~(EGTP_MASK_BIT3); } - SFndLenMsg(egtpMsg->msg, &tPduSize); + ODU_GET_MSG_LEN(egtpMsg->msg, &tPduSize); /*Adjust the header to fill the correct length*/ msgLen = tPduSize + (EGTP_MAX_HDR_LEN - hdrLen) - 0x08; @@ -808,12 +808,12 @@ S16 BuildEgtpMsg(EgtpMsg *egtpMsg) teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 1] &= ~(EGTP_MASK_BIT2); } - SAddPreMsgMult(&teidCb->preEncodedHdr.hdr[hdrLen], (EGTP_MAX_HDR_LEN - hdrLen), egtpMsg->msg); + ODU_ADD_PRE_MSG_MULT(&teidCb->preEncodedHdr.hdr[hdrLen], (EGTP_MAX_HDR_LEN - hdrLen), egtpMsg->msg); DU_LOG("\nEGTP : Sending message buffer"); - SPrntMsg(egtpMsg->msg, 0, 0); + ODU_PRINT_MSG(egtpMsg->msg, 0, 0); - RETVALUE(ROK); + return ROK; } S16 cuEgtpSendMsg(Buffer *mBuf) @@ -833,10 +833,10 @@ S16 cuEgtpSendMsg(Buffer *mBuf) if(ret != ROK && ret != RWOULDBLOCK) { DU_LOG("\nEGTP : Message send failure"); - RETVALUE(RFAILED); + return RFAILED; } DU_LOG("\nEGTP : Message Sent"); - RETVALUE(ROK); + return ROK; }