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 all EGTP related functionality */
20 #include "common_def.h"
25 #include "du_app_mac_inf.h"
28 #include "du_ue_mgr.h"
31 /* Global variable declaration */
34 /**************************************************************************
35 * @brief Task Initiation callback function.
39 * Function : egtpActvInit
42 * This function is supplied as one of parameters during EGTP's
43 * task registration. SSI will invoke this function once, after
44 * it creates and attaches this TAPA Task to a system task.
46 * @param[in] Ent entity, the entity ID of this task.
47 * @param[in] Inst inst, the instance ID of this task.
48 * @param[in] Region region, the region ID registered for memory
50 * @param[in] Reason reason.
51 * @return ROK - success
53 ***************************************************************************/
54 S16 egtpActvInit(Ent entity, Inst inst, Region region, Reason reason)
56 DU_LOG("\n\nEGTP : Initializing");
58 cmMemset ((U8 *)&egtpCb, 0, sizeof(EgtpGlobalCb));
59 protType = CM_INET_PROTO_UDP;
65 /**************************************************************************
66 * @brief Task Activation callback function.
70 * Function : egtpActvTsk
73 * This function handles all EGTP messages received
74 * This API is registered with SSI during the
75 * Task Registration of DU APP.
77 * @param[in] Pst *pst, Post structure of the primitive.
78 * @param[in] Buffer *mBuf, Packed primitive parameters in the
80 * @return ROK - success
83 ***************************************************************************/
84 S16 egtpActvTsk(Pst *pst, Buffer *mBuf)
96 ret = unpackEgtpCfgReq(egtpCfgReq, pst, mBuf);
101 ret = unpackEgtpSrvOpenReq(egtpSrvOpenReq, pst, mBuf);
106 ret = unpackEgtpTnlMgmtReq(egtpTnlMgmtReq, pst, mBuf);
111 ret = unpackEgtpSlotInd(egtpSlotInd, pst, mBuf);
117 DU_LOG("\nEGTP : Invalid event %d", pst->event);
135 DU_LOG("\nEGTP : Invalid event %d", pst->event);
143 DU_LOG("\nEGTP : Invalid source entity %d", pst->srcEnt);
151 /**************************************************************************
152 * @brief EGTP server configuration
156 * Function : egtpCfgReq
159 * This function handles EGTP configuration request.
161 * @return ROK - success
164 * ***********************************************************************/
165 S16 egtpCfgReq(Pst *pst, EgtpConfig egtpCfg)
167 U8 ret; /* Return value */
168 Pst rspPst; /* Response Pst structure */
169 CmStatus cfgCfm; /* Configuration Confirm */
171 cmMemcpy((U8 *)&egtpCb.egtpCfg, (U8 *)&egtpCfg, (PTR)sizeof(EgtpConfig));
173 egtpCb.recvTptSrvr.addr.address = CM_INET_NTOH_U32(egtpCb.egtpCfg.localIp.ipV4Addr);
174 egtpCb.recvTptSrvr.addr.port = EGTP_DFLT_PORT;
176 egtpCb.dstCb.dstIp = CM_INET_NTOH_U32(egtpCb.egtpCfg.destIp.ipV4Addr);
177 egtpCb.dstCb.dstPort = egtpCb.egtpCfg.destPort;
178 egtpCb.dstCb.sendTptSrvr.addr.address = CM_INET_NTOH_U32(egtpCb.egtpCfg.localIp.ipV4Addr);
179 egtpCb.dstCb.sendTptSrvr.addr.port = egtpCb.egtpCfg.localPort;
180 egtpCb.dstCb.numTunn = 0;
182 ret = cmHashListInit(&(egtpCb.dstCb.teIdLst), 1024, sizeof(EgtpTeIdCb), FALSE, CM_HASH_KEYTYPE_U32MOD, DU_APP_MEM_REGION, DU_POOL);
186 DU_LOG("\nEGTP : TeId hash list initialization failed");
187 cfgCfm.status = LCM_PRIM_NOK;
188 cfgCfm.reason = LCM_REASON_HASHING_FAILED;
192 DU_LOG("\nEGTP : EGTP configuration successful");
193 cfgCfm.status = LCM_PRIM_OK;
194 cfgCfm.reason = LCM_REASON_NOT_APPL;
197 /* Fill response Pst */
198 egtpFillRspPst(pst, &rspPst);
199 rspPst.event = EVTCFGCFM;
201 packEgtpCfgCfm(&rspPst, cfgCfm);
206 /**************************************************************************
207 * @brief Fills post structure to send response
211 * Function : egtpFillRspPst
214 * Fills post struture to send response
216 * @return ROK - success
220 * ***********************************************************************/
221 S16 egtpFillRspPst(Pst *pst, Pst *rspPst)
224 cmMemset((U8 *)rspPst, 0, sizeof(Pst));
225 rspPst->srcEnt = pst->dstEnt;
226 rspPst->srcInst = pst->dstInst;
227 rspPst->srcProcId = pst->dstProcId;
228 rspPst->dstEnt = pst->srcEnt;
229 rspPst->dstInst = pst->srcInst;
230 rspPst->dstProcId = pst->srcProcId;
231 rspPst->selector = ODU_SELECTOR_LC;
232 rspPst->pool= DU_POOL;
237 /**************************************************************************
238 * @brief EGTP server open request
242 * Function : egtpSrvOpenReq
245 * This function handles EGTP open server request.
246 * It opens udp socket to receive/send msgs.
248 * @param[in] Pst *pst, post structure
249 * @return ROK - success
252 ***************************************************************************/
254 S16 egtpSrvOpenReq(Pst *pst)
257 U8 ret; /* Return value */
258 Pst rspPst; /* Response Pst structure */
259 CmStatus cfm; /* Confirmation status */
260 U8 sockType; /* Socket type */
262 DU_LOG("\nEGTP : Received EGTP open server request");
264 sockType = CM_INET_DGRAM;
265 ret = egtpSrvOpenPrc(sockType, &(egtpCb.recvTptSrvr));
266 /* Opening and Binding receiver socket */
269 DU_LOG("\nEGTP : Failed while opening receiver transport server");
272 /* Opening and Binding sender socket */
273 ret = egtpSrvOpenPrc(sockType, &(egtpCb.dstCb.sendTptSrvr));
276 DU_LOG("\nEGTP : Failed while opening sender transport server");
280 DU_LOG("\nEGTP : Receiver socket[%d] and Sender socket[%d] open", egtpCb.recvTptSrvr.sockFd.fd, egtpCb.dstCb.sendTptSrvr.sockFd.fd);
282 /* Filling and seing response */
283 cfm.status = LCM_PRIM_OK;
284 cfm.reason = LCM_REASON_NOT_APPL;
286 egtpFillRspPst(pst, &rspPst);
287 rspPst.event = EVTSRVOPENCFM;
288 packEgtpSrvOpenCfm(&rspPst, cfm);
293 /*******************************************************************
295 * @brief Processing Sever open request
299 * Function : egtpSrvOpenPrc
305 * @return ROK - success
308 * ****************************************************************/
310 S16 egtpSrvOpenPrc(U8 sockType, EgtpTptSrvr *server)
313 ret = cmInetSocket(sockType, &(server->sockFd), protType);
316 DU_LOG("\nEGTP : Failed to open UDP socket");
319 ret = cmInetBind(&(server->sockFd), &(server->addr));
322 DU_LOG("\nEGTP : Failed to bind socket");
329 /**************************************************************************
330 * @brief EGTP tunnel management request
334 * Function : egtpTnlMgmtReq
337 * This function handles EGTP tunnel managament request
339 * @param[in] Pst *pst, post structure
340 * Tunnel Eveny structure
341 * @return ROK - success
345 * ***************************************************************************/
346 S16 egtpTnlMgmtReq(Pst *pst, EgtpTnlEvt tnlEvt)
351 DU_LOG("\nEGTP : Received tunnel management request");
352 switch(tnlEvt.action)
354 case EGTP_TNL_MGMT_ADD:
356 ret = egtpTnlAdd(tnlEvt);
359 case EGTP_TNL_MGMT_MOD:
361 ret = egtpTnlMod(tnlEvt);
364 case EGTP_TNL_MGMT_DEL:
366 ret = egtpTnlDel(tnlEvt);
371 DU_LOG("\nEGTP : Invalid tunnel management action[%d]", tnlEvt.action);
372 ret = LCM_REASON_INVALID_ACTION;
378 tnlEvt.cfmStatus.status = LCM_PRIM_OK;
379 tnlEvt.cfmStatus.reason = LCM_REASON_NOT_APPL;
383 tnlEvt.cfmStatus.status = LCM_PRIM_NOK;
384 tnlEvt.cfmStatus.reason = ret;
387 DU_LOG("\nEGTP : Sending Tunnel management confirmation");
388 egtpFillRspPst(pst, &rspPst);
389 rspPst.event = EVTTNLMGMTCFM;
390 packEgtpTnlMgmtCfm(&rspPst, tnlEvt);
395 /**************************************************************************
396 * @brief EGTP tunnel addition
400 * Function : egtpTnlAdd
403 * This function handles EGTP tunnel addition
405 * @param[in] Tunnel Event structure
406 * @return ROK - success
409 * ***************************************************************************/
410 S16 egtpTnlAdd(EgtpTnlEvt tnlEvt)
413 EgtpTeIdCb *teidCb; /* Tunnel endpoint control block */
414 EgtpMsgHdr preDefHdr; /* pre-define header for this tunnel */
416 DU_LOG("\nEGTP : Tunnel addition : LocalTeid[%d] Remote Teid[%d]", tnlEvt.lclTeid, tnlEvt.remTeid);
418 DU_ALLOC(teidCb, sizeof(EgtpTeIdCb));
421 DU_LOG("\nEGTP : Memory allocation failed");
422 return LCM_REASON_MEM_NOAVAIL;
425 cmMemset((U8 *)teidCb, 0, sizeof(EgtpTeIdCb));
426 teidCb->teId = tnlEvt.lclTeid;
427 teidCb->remTeId = tnlEvt.remTeid;
429 ret = cmHashListInsert(&(egtpCb.dstCb.teIdLst), (PTR)teidCb, (U8 *)&(teidCb->teId), sizeof(U32));
432 DU_LOG("\nEGTP : Failed to insert in hash list");
433 DU_FREE(teidCb, sizeof(EgtpTeIdCb));
434 return LCM_REASON_HASHING_FAILED;
436 egtpCb.dstCb.numTunn++;
438 /* Encoding pre-defined header */
439 cmMemset((U8*)&preDefHdr, 0, sizeof(EgtpMsgHdr));
440 preDefHdr.msgType = EGTPU_MSG_GPDU;
441 preDefHdr.teId = teidCb->remTeId;
442 preDefHdr.extHdr.pdcpNmb.pres = FALSE;
443 preDefHdr.extHdr.udpPort.pres = FALSE;
444 preDefHdr.nPdu.pres = FALSE;
446 egtpEncodeHdr((U8 *)teidCb->preEncodedHdr.hdr, &preDefHdr, &(teidCb->preEncodedHdr.cnt));
451 /**************************************************************************
452 * @brief EGTP tunnel modification
456 * Function : egtpTnlMod
459 * This function handles EGTP tunnel modification
461 * @param[in] Tunnel Event structure
462 * @return ROK - success
465 * ***************************************************************************/
466 S16 egtpTnlMod(EgtpTnlEvt tnlEvt)
470 EgtpTeIdCb *teidCb = NULLP;
472 printf("\nTunnel modification : LocalTeid[%d] Remote Teid[%d]", tnlEvt.lclTeid, tnlEvt.remTeid);
474 cmHashListFind(&(egtpCb.dstCb.teIdLst), (U8 *)&(tnlEvt.teId), sizeof(U32), 0, (PTR *)&teidCb);
477 printf("\nTunnel id not found");
481 teidCb->teId = tnlEvt.lclTeid;
482 teidCb->remTeId = tnlEvt.remTeid;
487 /**************************************************************************
488 * @brief EGTP tunnel deletion
492 * Function : egtpTnlDel
495 * This function handles EGTP tunnel deletion
497 * @param[in] Tunnel Event structure
498 * @return ROK - success
501 * ***************************************************************************/
502 S16 egtpTnlDel(EgtpTnlEvt tnlEvt)
504 EgtpTeIdCb *teidCb = NULLP;
506 DU_LOG("\nEGTP : Tunnel deletion : Local Teid[%d] Remote Teid[%d]", tnlEvt.lclTeid, tnlEvt.remTeid);
508 cmHashListFind(&(egtpCb.dstCb.teIdLst), (U8 *)&(tnlEvt.lclTeid), sizeof(U32), 0, (PTR *)&teidCb);
511 DU_LOG("\nEGTP : Tunnel id[%d] not configured", tnlEvt.lclTeid);
512 return LCM_REASON_INVALID_PAR_VAL;
515 cmHashListDelete(&(egtpCb.dstCb.teIdLst), (PTR)teidCb);
516 DU_FREE(teidCb, sizeof(EgtpTeIdCb));
517 egtpCb.dstCb.numTunn--;
522 /*******************************************************************
524 * @brief Handles data indication
528 * Function : EgtpHdlDatInd
531 * Handles incoming data from peer to be passed
535 * @return ROK - success
538 * ****************************************************************/
539 S16 egtpHdlDatInd(EgtpMsg egtpMsg)
541 EgtpTeIdCb *teidCb = NULLP;
547 DU_LOG("\nEGTP : Received Data Indication");
549 cmHashListFind(&(egtpCb.dstCb.teIdLst), (U8 *)&(egtpMsg.msgHdr.teId), sizeof(U32), 0, (PTR *)&teidCb);
552 DU_LOG("\nEGTP : Tunnel id[%d] not configured", egtpMsg.msgHdr.teId);
553 return LCM_REASON_INVALID_PAR_VAL;
556 msgHdr = &(egtpMsg.msgHdr);
558 hdrLen = teidCb->preEncodedHdr.cnt;
560 if(msgHdr->extHdr.pdcpNmb.pres)
562 teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 1] |= EGTP_MASK_BIT3;
563 teidCb->preEncodedHdr.hdr[hdrLen] = EGTP_EXT_HDR_PDCP_TYPE;
564 teidCb->preEncodedHdr.hdr[--hdrLen] = 1;
565 teidCb->preEncodedHdr.hdr[--hdrLen] = GetHiByte(msgHdr->extHdr.pdcpNmb.val);
566 teidCb->preEncodedHdr.hdr[--hdrLen] = GetLoByte(msgHdr->extHdr.pdcpNmb.val);
567 teidCb->preEncodedHdr.hdr[--hdrLen] = 0;
571 teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 1] &= ~(EGTP_MASK_BIT3);
574 SFndLenMsg(egtpMsg.msg, &tPduSize);
576 /*Adjust the header to fill the correct length*/
577 msgLen = tPduSize + (EGTP_MAX_HDR_LEN - hdrLen) - 0x08;
579 /***********************************************
580 * Fill the length field of the message header *
581 ***********************************************/
582 teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 3] = (U8)GetHiByte(msgLen);
583 teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 4] = (U8)GetLoByte(msgLen);
585 /*Update the sequence number*/
586 if(egtpMsg.msgHdr.seqNum.pres)
588 teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 1] |= (EGTP_MASK_BIT2);
589 teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 9] = (U8)GetHiByte(egtpMsg.msgHdr.seqNum.val);
590 teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 10] = (U8)GetLoByte(egtpMsg.msgHdr.seqNum.val);
594 teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 1] &= ~(EGTP_MASK_BIT2);
597 DU_LOG("\nEGTP : UL Data buffer before encoding header");
598 SPrntMsg(egtpMsg.msg, 0, 0);
600 SAddPreMsgMult(&teidCb->preEncodedHdr.hdr[hdrLen], (EGTP_MAX_HDR_LEN - hdrLen), egtpMsg.msg);
603 DU_LOG("\nEGTP : UL Data buffer after encoding header");
604 SPrntMsg(egtpMsg.msg, 0, 0);
607 egtpSendMsg(egtpMsg.msg);
608 SPutMsg(egtpMsg.msg);
613 /*******************************************************************
615 * @brief Encodes outgoing message
619 * Function : egtpEncodeMsg
622 * Encodes EGTP message to be sent
624 * @params[in] EGTP message
626 * @return ROK - success
629 * ****************************************************************/
630 S16 egtpEncodeHdr(U8 *preEncodedHdr, EgtpMsgHdr *preDefHdr, U8 *hdrIdx)
632 U8 tmpByte = 0; /* Stores one byte of data for enc */
633 U8 cnt = EGTP_MAX_HDR_LEN; /* Stores the position */
634 Bool extPres = FALSE; /* Flag for indication of S, E or P presense flag */
637 /* Encoding header */
638 tmpByte |= EGTP_MASK_BIT6; /* Setting 6th LSB of 1st byte as version */
639 tmpByte |= EGTP_MASK_BIT5; /* Setting 5th LSB of 1st byte as protocol type */
641 if(preDefHdr->extHdr.udpPort.pres || preDefHdr->extHdr.pdcpNmb.pres)
643 tmpByte |= EGTP_MASK_BIT3; /* Setting 3rd LSB of 1st byte if Extension heaeder is present */
646 if(preDefHdr->seqNum.pres)
648 tmpByte |= EGTP_MASK_BIT2;
651 if(preDefHdr->nPdu.pres)
653 tmpByte |= EGTP_MASK_BIT1;
656 if((tmpByte & EGTP_MASK_BIT1) || (tmpByte & EGTP_MASK_BIT2)||(tmpByte & EGTP_MASK_BIT3))
661 preEncodedHdr[--cnt] = tmpByte;
662 preEncodedHdr[--cnt] = preDefHdr->msgType;
664 /* Encode Tunnel endpoint */
665 preEncodedHdr[--cnt] = 0;
666 preEncodedHdr[--cnt] = 0;
667 nwWord = (U16)(GetHiWord(preDefHdr->teId));
668 preEncodedHdr[--cnt] = (U8)(GetHiByte(nwWord));
669 preEncodedHdr[--cnt] = (U8)(GetLoByte(nwWord));
670 nwWord = (U16)(GetLoWord(preDefHdr->teId));
671 preEncodedHdr[--cnt] = (U8)(GetHiByte(nwWord));
672 preEncodedHdr[--cnt] = (U8)(GetLoByte(nwWord));
674 /* Encode sequence number */
675 if(preDefHdr->seqNum.pres)
677 preEncodedHdr[--cnt] = GetHiByte(preDefHdr->seqNum.val);
678 preEncodedHdr[--cnt] = GetLoByte(preDefHdr->seqNum.val);
682 preEncodedHdr[--cnt] = 0;
683 preEncodedHdr[--cnt] = 0;
686 /* Encode nPdu number */
687 if(preDefHdr->nPdu.pres)
689 preEncodedHdr[--cnt] = preDefHdr->nPdu.val;
693 preEncodedHdr[--cnt] = 0;
696 if(preDefHdr->extHdr.udpPort.pres)
698 preEncodedHdr[--cnt] = EGTP_EXT_HDR_UDP_TYPE;
699 preEncodedHdr[--cnt] = 1;
700 preEncodedHdr[--cnt] = GetHiByte(preDefHdr->extHdr.udpPort.val);
701 preEncodedHdr[--cnt] = GetLoByte(preDefHdr->extHdr.udpPort.val);
704 if(preDefHdr->extHdr.pdcpNmb.pres)
706 preEncodedHdr[--cnt] = EGTP_EXT_HDR_PDCP_TYPE;
707 preEncodedHdr[--cnt] = 1;
708 preEncodedHdr[--cnt] = GetHiByte(preDefHdr->extHdr.pdcpNmb.val);
709 preEncodedHdr[--cnt] = GetLoByte(preDefHdr->extHdr.pdcpNmb.val);
712 if(tmpByte & EGTP_MASK_BIT3)
714 preEncodedHdr[--cnt] = 0;
718 preEncodedHdr[--cnt] = 0;
723 } /* egtpEncodeHdr */
725 /*******************************************************************
727 * @brief Sends message over UDP
731 * Function : egtpSendMsg
734 * Sends message over UDP
736 * @params[in] Message Buffer
737 * @return ROK - success
740 * ****************************************************************/
741 S16 egtpSendMsg(Buffer *mBuf)
748 info.region = DU_APP_MEM_REGION;
751 dstAddr.port = EGTP_DFLT_PORT;
752 dstAddr.address = egtpCb.dstCb.dstIp;
754 ret = cmInetSendMsg(&(egtpCb.dstCb.sendTptSrvr.sockFd), &dstAddr, &info, mBuf, &txLen, CM_INET_NO_FLAG);
755 if(ret != ROK && ret != RWOULDBLOCK)
757 DU_LOG("\nEGTP : Failed sending the message");
761 DU_LOG("\nEGTP : Message Sent");
766 /*******************************************************************
768 * @brief Handles Slot Indication from PHY
772 * Function : egtpSlotInd
775 * Handles TTI Indication from PHY
778 * @return ROK - success
781 * ****************************************************************/
788 /*******************************************************************
790 * @brief Receives EGTP message from UDP socket
794 * Function : egtpRecvMsg
797 * Receive incoming messages from UDP socket
800 * @return ROK - success
803 * ****************************************************************/
807 U8 ret; /* Return value */
808 U8 nMsg; /* Number of messages to read from UDP socked */
809 MsgLen bufLen; /* Length of received buffer */
810 Buffer *recvBuf; /* Received buffer */
811 CmInetAddr fromAddr; /* Egtp data sender address */
812 CmInetMemInfo memInfo; /* Buffer allocation info */
815 DU_LOG("\nEGTP : Received Slot Indication");
818 memInfo.region = DU_APP_MEM_REGION;
819 memInfo.pool = DU_POOL;
821 fromAddr.port = egtpCb.dstCb.dstPort;
822 fromAddr.address = egtpCb.dstCb.dstIp;
824 while(nMsg < EGTP_MAX_MSG_RECV)
827 ret = cmInetRecvMsg(&(egtpCb.recvTptSrvr.sockFd), &fromAddr, &memInfo, &recvBuf, &bufLen, CM_INET_NO_FLAG);
828 if(ret == ROK && recvBuf != NULLP)
830 DU_LOG("\nEGTP : Received DL Message[%d]\n", nMsg+1);
831 SPrntMsg(recvBuf, 0 ,0);
832 egtpHdlRecvData(recvBuf);
840 S16 egtpHdlRecvData(Buffer *mBuf)
844 /* Decode EGTP header */
845 egtpDecodeHdr(mBuf, &egtpMsg);
847 /* TODO : Send received message to RLC */
848 duHdlEgtpDlData(&egtpMsg);
853 S16 egtpDecodeHdr(Buffer *mBuf, EgtpMsg *egtpMsg)
855 U8 tmpByte[5]; /* Holds 5 byte of data after Decoding */
856 U8 version = 0; /* Holds the version type, decoded */
857 MsgLen msgLen = 0; /* Holds the msgLen from the Hdr */
858 MsgLen bufLen = 0; /* Holds the total buffer length */
859 U8 extHdrType = 0; /* Holds the Extension hdr type */
860 U8 extHdrLen = 0; /* Extension hdr length */
861 Bool extPres = FALSE; /* Flag for indication of S, E or P presense flag */
863 SFndLenMsg(mBuf, &bufLen);
865 /* Decode first byte and storing in temporary variable */
866 SRemPreMsg(&tmpByte[0], mBuf);
868 /* Extracting version fro 1st byte */
869 version = tmpByte[0] >> 5;
871 DU_LOG("\nEGTP : Version %d", version);
873 /* Decode message type */
874 SRemPreMsg((Data*)&(egtpMsg->msgHdr.msgType), mBuf);
875 DU_LOG("\nEGTP : msgType %d", egtpMsg->msgHdr.msgType);
877 /****************************************************************************
878 * Message length param is 2 bytes. So decode next 2 bytes from msg hdr and
879 * performing OR operation on these two bytes to calculate message length
880 ***************************************************************************/
881 SRemPreMsg(&tmpByte[1], mBuf);
882 SRemPreMsg(&tmpByte[2], mBuf);
883 msgLen = (tmpByte[1] << 8) | tmpByte[2];
884 DU_LOG("\nEGTP : msgLen %d", msgLen);
887 /****************************************************************************
888 * Tunnel id param is 4 bytes. So decode next 4 bytes from msg hdr and
889 * perform OR operation on these 4 bytes to calculate tunnel id
890 ***************************************************************************/
891 SRemPreMsg(&tmpByte[1], mBuf);
892 SRemPreMsg(&tmpByte[2], mBuf);
893 SRemPreMsg(&tmpByte[3], mBuf);
894 SRemPreMsg(&tmpByte[4], mBuf);
895 egtpMsg->msgHdr.teId = (tmpByte[1] << 24) | (tmpByte[2] << 16) | (tmpByte[3] << 8) | tmpByte[4];
896 DU_LOG("\nEGTP : teId %d",egtpMsg->msgHdr.teId);
899 /* If any one of S, E or PN flag is set, set extension present as true. */
900 if((tmpByte[0] & EGTP_MASK_BIT1) || (tmpByte[0] & EGTP_MASK_BIT2)||(tmpByte[0] & EGTP_MASK_BIT3))
905 /* Decode sequence number, if S flag is set in first byte */
906 if (tmpByte[0] & EGTP_MASK_BIT2)
908 /************************************************************************
909 * Sequence num is 2 bytes. So decode next 2 bytes from msg hdr and
910 * perform OR operation on them
911 ************************************************************************/
912 egtpMsg->msgHdr.seqNum.pres = TRUE;
913 SRemPreMsg(&tmpByte[1], mBuf);
914 SRemPreMsg(&tmpByte[2], mBuf);
915 egtpMsg->msgHdr.seqNum.val = (tmpByte[1] << 8) | tmpByte[2];
917 /****************************************************************************
918 * If extPres is true, but S bit is not set, implies, either of PN or E bit
919 * was set during Encode so accordingly extract Byte fields for seqNum anyway
920 ***************************************************************************/
923 /*************************************************************************
924 * Sequence num is 2 bytes. So decode next 2 bytes from msg hdr and
925 * perform OR operation on them
926 ************************************************************************/
927 egtpMsg->msgHdr.seqNum.pres = 0;
928 SRemPreMsg(&tmpByte[1], mBuf);
929 SRemPreMsg(&tmpByte[2], mBuf);
930 egtpMsg->msgHdr.seqNum.val = (tmpByte[1] << 8) | tmpByte[2];
933 /* Decode N-PDU number if present flag is set */
934 if (tmpByte[0] & EGTP_MASK_BIT1)
936 egtpMsg->msgHdr.nPdu.pres = TRUE;
937 SRemPreMsg(&(egtpMsg->msgHdr.nPdu.val), mBuf);
939 /****************************************************************************
940 * If extPres is true, but PN bit is not set, implies, either of S or E bit
941 * was set during Encode. Aaccordingly extract Byte fields of N-PDU num anyway
942 ***************************************************************************/
945 egtpMsg->msgHdr.nPdu.pres = TRUE;
946 SRemPreMsg(&(egtpMsg->msgHdr.nPdu.val), mBuf);
949 /* If E flag is set in first byte, decode extension header */
950 if(tmpByte[0] & EGTP_MASK_BIT3)
952 SRemPreMsg(&extHdrType, mBuf);
953 while( 0 != extHdrType)
957 case EGTP_EXT_HDR_UDP_TYPE:
959 SRemPreMsg(&extHdrLen, mBuf);
960 if(extHdrLen == 0x01)
962 /************************************************************
963 * UDP Port is 2 bytes. So decode next 2 bytes from msg hdr
964 * and perform OR operation on them
965 *************************************************************/
966 egtpMsg->msgHdr.extHdr.udpPort.pres = TRUE;
967 SRemPreMsg(&tmpByte[1], mBuf);
968 SRemPreMsg(&tmpByte[2], mBuf);
969 egtpMsg->msgHdr.extHdr.udpPort.val = (tmpByte[1] << 8) | tmpByte[2];
974 case EGTP_EXT_HDR_PDCP_TYPE:
976 SRemPreMsg(&extHdrLen, mBuf);
977 if(extHdrLen == 0x01)
979 /*************************************************************
980 * PDCP num is 2 bytes. So decode next 2 bytes from msg hdr
981 * and perform OR operation on them
982 ************************************************************/
983 egtpMsg->msgHdr.extHdr.pdcpNmb.pres = TRUE;
984 SRemPreMsg(&tmpByte[1], mBuf);
985 SRemPreMsg(&tmpByte[2], mBuf);
986 egtpMsg->msgHdr.extHdr.pdcpNmb.val = (tmpByte[1] << 8) | tmpByte[2];
990 } /* End of switch */
992 SRemPreMsg(&extHdrType, mBuf);
996 /****************************************************************************
997 * If extPres is true, but E bit is not set, implies, either of PN or S bit
998 * was set during Encode so accordingly extract Byte fields for extension
1000 ***************************************************************************/
1003 SRemPreMsg(&extHdrType, mBuf);
1006 egtpMsg->msg = mBuf;
1008 DU_LOG("\nEGTP : DL Data Buffer after decoding header ");
1009 SPrntMsg(mBuf, 0, 0);
1011 /* Forward the data to duApp/RLC */