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"
27 #include "du_app_mac_inf.h"
32 /* Global variable declaration */
35 /**************************************************************************
36 * @brief Task Initiation callback function.
40 * Function : egtpActvInit
43 * This function is supplied as one of parameters during EGTP's
44 * task registration. SSI will invoke this function once, after
45 * it creates and attaches this TAPA Task to a system task.
47 * @param[in] Ent entity, the entity ID of this task.
48 * @param[in] Inst inst, the instance ID of this task.
49 * @param[in] Region region, the region ID registered for memory
51 * @param[in] Reason reason.
52 * @return ROK - success
54 ***************************************************************************/
55 uint8_t egtpActvInit(Ent entity, Inst inst, Region region, Reason reason)
57 DU_LOG("\n\nDEBUG --> EGTP : Initializing");
59 memset (&egtpCb, 0, sizeof(EgtpGlobalCb));
60 protType = CM_INET_PROTO_UDP;
66 /**************************************************************************
67 * @brief Task Activation callback function.
71 * Function : egtpActvTsk
74 * This function handles all EGTP messages received
75 * This API is registered with SSI during the
76 * Task Registration of DU APP.
78 * @param[in] Pst *pst, Post structure of the primitive.
79 * @param[in] Buffer *mBuf, Packed primitive parameters in the
81 * @return ROK - success
84 ***************************************************************************/
85 uint8_t egtpActvTsk(Pst *pst, Buffer *mBuf)
97 ret = unpackEgtpCfgReq(egtpCfgReq, pst, mBuf);
102 ret = unpackEgtpSrvOpenReq(egtpSrvOpenReq, pst, mBuf);
107 ret = unpackEgtpTnlMgmtReq(egtpTnlMgmtReq, pst, mBuf);
112 DU_LOG("\nERROR --> EGTP : Invalid event %d", pst->event);
113 ODU_PUT_MSG_BUF(mBuf);
125 DU_LOG("\nDEBUG --> EGTP : Starting Socket Polling");
127 ODU_PUT_MSG_BUF(mBuf);
132 DU_LOG("\nERROR --> EGTP : Invalid event %d", pst->event);
133 ODU_PUT_MSG_BUF(mBuf);
150 DU_LOG("\nERROR --> EGTP : Invalid event %d", pst->event);
158 DU_LOG("\nERROR --> EGTP : Invalid source entity %d", pst->srcEnt);
166 /**************************************************************************
167 * @brief EGTP server configuration
171 * Function : egtpCfgReq
174 * This function handles EGTP configuration request.
176 * @return ROK - success
179 * ***********************************************************************/
180 uint8_t egtpCfgReq(Pst *pst, EgtpConfig egtpCfg)
182 uint8_t ret; /* Return value */
183 Pst rspPst; /* Response Pst structure */
184 CmStatus cfgCfm; /* Configuration Confirm */
186 memcpy(&egtpCb.egtpCfg, &egtpCfg, sizeof(EgtpConfig));
188 egtpCb.recvTptSrvr.addr.address = CM_INET_NTOH_UINT32(egtpCb.egtpCfg.localIp.ipV4Addr);
189 egtpCb.recvTptSrvr.addr.port = EGTP_DFLT_PORT;
191 egtpCb.dstCb.dstIp = CM_INET_NTOH_UINT32(egtpCb.egtpCfg.destIp.ipV4Addr);
192 egtpCb.dstCb.dstPort = egtpCb.egtpCfg.destPort;
193 egtpCb.dstCb.sendTptSrvr.addr.address = CM_INET_NTOH_UINT32(egtpCb.egtpCfg.localIp.ipV4Addr);
194 egtpCb.dstCb.sendTptSrvr.addr.port = egtpCb.egtpCfg.localPort;
195 egtpCb.dstCb.numTunn = 0;
197 ret = cmHashListInit(&(egtpCb.dstCb.teIdLst), 1024, sizeof(EgtpTeIdCb), FALSE, CM_HASH_KEYTYPE_UINT32_MOD, DU_APP_MEM_REGION, DU_POOL);
201 DU_LOG("\nERROR --> EGTP : TeId hash list initialization failed");
202 cfgCfm.status = LCM_PRIM_NOK;
203 cfgCfm.reason = LCM_REASON_HASHING_FAILED;
207 DU_LOG("\nDEBUG --> EGTP : EGTP configuration successful");
208 cfgCfm.status = LCM_PRIM_OK;
209 cfgCfm.reason = LCM_REASON_NOT_APPL;
212 /* Fill response Pst */
213 egtpFillRspPst(pst, &rspPst);
214 rspPst.event = EVTCFGCFM;
216 packEgtpCfgCfm(&rspPst, cfgCfm);
221 /**************************************************************************
222 * @brief Fills post structure to send response
226 * Function : egtpFillRspPst
229 * Fills post struture to send response
231 * @return ROK - success
235 * ***********************************************************************/
236 uint8_t egtpFillRspPst(Pst *pst, Pst *rspPst)
239 memset(rspPst, 0, sizeof(Pst));
240 rspPst->srcEnt = pst->dstEnt;
241 rspPst->srcInst = pst->dstInst;
242 rspPst->srcProcId = pst->dstProcId;
243 rspPst->dstEnt = pst->srcEnt;
244 rspPst->dstInst = pst->srcInst;
245 rspPst->dstProcId = pst->srcProcId;
246 rspPst->selector = ODU_SELECTOR_LC;
247 rspPst->pool= DU_POOL;
252 /**************************************************************************
253 * @brief EGTP server open request
257 * Function : egtpSrvOpenReq
260 * This function handles EGTP open server request.
261 * It opens udp socket to receive/send msgs.
263 * @param[in] Pst *pst, post structure
264 * @return ROK - success
267 ***************************************************************************/
269 uint8_t egtpSrvOpenReq(Pst *pst)
272 uint8_t ret; /* Return value */
273 Pst rspPst; /* Response Pst structure */
274 Pst egtpPst; /* Self post */
275 CmStatus cfm; /* Confirmation status */
276 uint8_t sockType; /* Socket type */
278 DU_LOG("\nDEBUG --> EGTP : Received EGTP open server request");
280 sockType = CM_INET_DGRAM;
281 ret = egtpSrvOpenPrc(sockType, &(egtpCb.recvTptSrvr));
282 /* Opening and Binding receiver socket */
285 DU_LOG("\nERROR --> EGTP : Failed while opening receiver transport server");
288 /* Opening and Binding sender socket */
289 ret = egtpSrvOpenPrc(sockType, &(egtpCb.dstCb.sendTptSrvr));
292 DU_LOG("\nERROR --> EGTP : Failed while opening sender transport server");
296 DU_LOG("\nDEBUG --> EGTP : Receiver socket[%d] and Sender socket[%d] open", egtpCb.recvTptSrvr.sockFd.fd,\
297 egtpCb.dstCb.sendTptSrvr.sockFd.fd);
299 /* Start Socket polling */
300 memset(&egtpPst, 0, sizeof(egtpPst));
301 egtpPst.srcEnt = (Ent)ENTEGTP;
302 egtpPst.srcInst = (Inst)EGTP_INST;
303 egtpPst.srcProcId = DU_PROC;
304 egtpPst.dstEnt = (Ent)ENTEGTP;
305 egtpPst.dstInst = (Inst)EGTP_INST;
306 egtpPst.dstProcId = DU_PROC;
307 egtpPst.event = EVTSTARTPOLL;
308 egtpPst.selector = ODU_SELECTOR_LC;
309 egtpPst.pool= DU_POOL;
310 packEgtpStartPollingReq(&egtpPst);
312 /* Filling and sending response */
313 cfm.status = LCM_PRIM_OK;
314 cfm.reason = LCM_REASON_NOT_APPL;
316 egtpFillRspPst(pst, &rspPst);
317 rspPst.event = EVTSRVOPENCFM;
318 packEgtpSrvOpenCfm(&rspPst, cfm);
323 /*******************************************************************
325 * @brief Processing Sever open request
329 * Function : egtpSrvOpenPrc
335 * @return ROK - success
338 * ****************************************************************/
340 uint8_t egtpSrvOpenPrc(uint8_t sockType, EgtpTptSrvr *server)
343 ret = cmInetSocket(sockType, &(server->sockFd), protType);
346 DU_LOG("\nERROR --> EGTP : Failed to open UDP socket");
349 ret = cmInetBind(&(server->sockFd), &(server->addr));
352 DU_LOG("\nERROR --> EGTP : Failed to bind socket");
359 /**************************************************************************
360 * @brief EGTP tunnel management request
364 * Function : egtpTnlMgmtReq
367 * This function handles EGTP tunnel managament request
369 * @param[in] Tunnel Eveny structure
370 * @return ROK - success
374 * ***************************************************************************/
375 uint8_t egtpTnlMgmtReq(Pst *pst, EgtpTnlEvt tnlEvt)
379 DU_LOG("\nDEBUG --> EGTP : Received tunnel management request");
380 switch(tnlEvt.action)
382 case EGTP_TNL_MGMT_ADD:
384 ret = egtpTnlAdd(tnlEvt);
387 case EGTP_TNL_MGMT_MOD:
389 ret = egtpTnlMod(tnlEvt);
392 case EGTP_TNL_MGMT_DEL:
394 ret = egtpTnlDel(tnlEvt);
399 DU_LOG("\nERROR --> EGTP : Invalid tunnel management action[%d]", tnlEvt.action);
400 ret = LCM_REASON_INVALID_ACTION;
406 tnlEvt.cfmStatus.status = LCM_PRIM_OK;
407 tnlEvt.cfmStatus.reason = LCM_REASON_NOT_APPL;
411 tnlEvt.cfmStatus.status = LCM_PRIM_NOK;
412 tnlEvt.cfmStatus.reason = ret;
415 DU_LOG("\nDEBUG --> EGTP : Sending Tunnel management confirmation");
416 duHdlEgtpTnlMgmtCfm(tnlEvt);
421 /**************************************************************************
422 * @brief EGTP tunnel addition
426 * Function : egtpTnlAdd
429 * This function handles EGTP tunnel addition
431 * @param[in] Tunnel Event structure
432 * @return ROK - success
435 * ***************************************************************************/
436 uint8_t egtpTnlAdd(EgtpTnlEvt tnlEvt)
439 EgtpTeIdCb *teidCb; /* Tunnel endpoint control block */
440 EgtpMsgHdr preDefHdr; /* pre-define header for this tunnel */
442 DU_LOG("\nINFO --> EGTP : Tunnel addition : LocalTeid[%d] Remote Teid[%d]", tnlEvt.lclTeid, tnlEvt.remTeid);
444 DU_ALLOC(teidCb, sizeof(EgtpTeIdCb));
447 DU_LOG("\nERROR --> EGTP : Memory allocation failed");
448 return LCM_REASON_MEM_NOAVAIL;
451 memset(teidCb, 0, sizeof(EgtpTeIdCb));
452 teidCb->teId = tnlEvt.lclTeid;
453 teidCb->remTeId = tnlEvt.remTeid;
455 ret = cmHashListInsert(&(egtpCb.dstCb.teIdLst), (PTR)teidCb, (uint8_t *)&(teidCb->teId), sizeof(uint32_t));
458 DU_LOG("\nERROR --> EGTP : Failed to insert in hash list");
459 DU_FREE(teidCb, sizeof(EgtpTeIdCb));
460 return LCM_REASON_HASHING_FAILED;
462 egtpCb.dstCb.numTunn++;
464 /* Encoding pre-defined header */
465 memset(&preDefHdr, 0, sizeof(EgtpMsgHdr));
466 preDefHdr.msgType = EGTPU_MSG_GPDU;
467 preDefHdr.teId = teidCb->remTeId;
468 preDefHdr.extHdr.pdcpNmb.pres = FALSE;
469 preDefHdr.extHdr.udpPort.pres = FALSE;
470 preDefHdr.nPdu.pres = FALSE;
472 egtpEncodeHdr((uint8_t *)teidCb->preEncodedHdr.hdr, &preDefHdr, &(teidCb->preEncodedHdr.cnt));
477 /**************************************************************************
478 * @brief EGTP tunnel modification
482 * Function : egtpTnlMod
485 * This function handles EGTP tunnel modification
487 * @param[in] Tunnel Event structure
488 * @return ROK - success
491 * ***************************************************************************/
492 uint8_t egtpTnlMod(EgtpTnlEvt tnlEvt)
496 EgtpTeIdCb *teidCb = NULLP;
498 DU_LOG("\nINFO --> Tunnel modification : LocalTeid[%d] Remote Teid[%d]", tnlEvt.lclTeid, tnlEvt.remTeid);
500 cmHashListFind(&(egtpCb.dstCb.teIdLst), (uint8_t *)&(tnlEvt.teId), sizeof(uint32_t), 0, (PTR *)&teidCb);
503 DU_LOG("\nERROR --> Tunnel id not found");
507 teidCb->teId = tnlEvt.lclTeid;
508 DU_LOG("\nINFO --> Tunnel id is" , teidCb->teId);
509 teidCb->remTeId = tnlEvt.remTeid;
514 /**************************************************************************
515 * @brief EGTP tunnel deletion
519 * Function : egtpTnlDel
522 * This function handles EGTP tunnel deletion
524 * @param[in] Tunnel Event structure
525 * @return ROK - success
528 * ***************************************************************************/
529 uint8_t egtpTnlDel(EgtpTnlEvt tnlEvt)
531 EgtpTeIdCb *teidCb = NULLP;
533 DU_LOG("\nINFO --> EGTP : Tunnel deletion : Local Teid[%d] Remote Teid[%d]", tnlEvt.lclTeid, tnlEvt.remTeid);
535 cmHashListFind(&(egtpCb.dstCb.teIdLst), (uint8_t *)&(tnlEvt.lclTeid), sizeof(uint32_t), 0, (PTR *)&teidCb);
538 DU_LOG("\nERROR --> EGTP : Tunnel id[%d] not configured", tnlEvt.lclTeid);
539 return LCM_REASON_INVALID_PAR_VAL;
542 cmHashListDelete(&(egtpCb.dstCb.teIdLst), (PTR)teidCb);
543 DU_FREE(teidCb, sizeof(EgtpTeIdCb));
544 egtpCb.dstCb.numTunn--;
549 /*******************************************************************
551 * @brief Handles data indication
555 * Function : EgtpHdlDatInd
558 * Handles incoming data from peer to be passed
562 * @return ROK - success
565 * ****************************************************************/
566 uint8_t egtpHdlDatInd(EgtpMsg egtpMsg)
568 EgtpTeIdCb *teidCb = NULLP;
574 DU_LOG("\nDEBUG --> EGTP : Received Data Indication");
576 cmHashListFind(&(egtpCb.dstCb.teIdLst), (uint8_t *)&(egtpMsg.msgHdr.teId), sizeof(uint32_t), 0, (PTR *)&teidCb);
579 DU_LOG("\nERROR --> EGTP : Tunnel id[%d] not configured", egtpMsg.msgHdr.teId);
580 return LCM_REASON_INVALID_PAR_VAL;
583 msgHdr = &(egtpMsg.msgHdr);
585 hdrLen = teidCb->preEncodedHdr.cnt;
587 if(msgHdr->extHdr.pdcpNmb.pres)
589 teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 1] |= EGTP_MASK_BIT3;
590 teidCb->preEncodedHdr.hdr[hdrLen] = EGTP_EXT_HDR_PDCP_TYPE;
591 teidCb->preEncodedHdr.hdr[--hdrLen] = 1;
592 teidCb->preEncodedHdr.hdr[--hdrLen] = GetHiByte(msgHdr->extHdr.pdcpNmb.val);
593 teidCb->preEncodedHdr.hdr[--hdrLen] = GetLoByte(msgHdr->extHdr.pdcpNmb.val);
594 teidCb->preEncodedHdr.hdr[--hdrLen] = 0;
598 teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 1] &= ~(EGTP_MASK_BIT3);
601 ODU_GET_MSG_LEN(egtpMsg.msg, (int16_t *)&tPduSize);
603 /*Adjust the header to fill the correct length*/
604 msgLen = tPduSize + (EGTP_MAX_HDR_LEN - hdrLen) - 0x08;
606 /***********************************************
607 * Fill the length field of the message header *
608 ***********************************************/
609 teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 3] = (uint8_t)GetHiByte(msgLen);
610 teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 4] = (uint8_t)GetLoByte(msgLen);
612 /*Update the sequence number*/
613 if(egtpMsg.msgHdr.seqNum.pres)
615 teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 1] |= (EGTP_MASK_BIT2);
616 teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 9] = (uint8_t)GetHiByte(egtpMsg.msgHdr.seqNum.val);
617 teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 10] = (uint8_t)GetLoByte(egtpMsg.msgHdr.seqNum.val);
621 teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 1] &= ~(EGTP_MASK_BIT2);
624 DU_LOG("\nDEBUG --> EGTP : UL Data buffer before encoding header");
625 ODU_PRINT_MSG(egtpMsg.msg, 0, 0);
627 ODU_ADD_PRE_MSG_MULT(&teidCb->preEncodedHdr.hdr[hdrLen], (EGTP_MAX_HDR_LEN - hdrLen), egtpMsg.msg);
630 DU_LOG("\nDEBUG --> EGTP : UL Data buffer after encoding header");
631 ODU_PRINT_MSG(egtpMsg.msg, 0, 0);
634 egtpSendMsg(egtpMsg.msg);
635 ODU_PUT_MSG_BUF(egtpMsg.msg);
640 /*******************************************************************
642 * @brief Encodes outgoing message
646 * Function : egtpEncodeMsg
649 * Encodes EGTP message to be sent
651 * @params[in] EGTP message
653 * @return ROK - success
656 * ****************************************************************/
657 uint8_t egtpEncodeHdr(uint8_t *preEncodedHdr, EgtpMsgHdr *preDefHdr, uint8_t *hdrIdx)
659 uint8_t tmpByte = 0; /* Stores one byte of data for enc */
660 uint8_t cnt = EGTP_MAX_HDR_LEN; /* Stores the position */
661 bool extPres = FALSE; /* Flag for indication of S, E or P presense flag */
664 /* Encoding header */
665 tmpByte |= EGTP_MASK_BIT6; /* Setting 6th LSB of 1st byte as version */
666 tmpByte |= EGTP_MASK_BIT5; /* Setting 5th LSB of 1st byte as protocol type */
668 if(preDefHdr->extHdr.udpPort.pres || preDefHdr->extHdr.pdcpNmb.pres)
670 tmpByte |= EGTP_MASK_BIT3; /* Setting 3rd LSB of 1st byte if Extension heaeder is present */
673 if(preDefHdr->seqNum.pres)
675 tmpByte |= EGTP_MASK_BIT2;
678 if(preDefHdr->nPdu.pres)
680 tmpByte |= EGTP_MASK_BIT1;
683 if((tmpByte & EGTP_MASK_BIT1) || (tmpByte & EGTP_MASK_BIT2)||(tmpByte & EGTP_MASK_BIT3))
688 preEncodedHdr[--cnt] = tmpByte;
689 preEncodedHdr[--cnt] = preDefHdr->msgType;
691 /* Encode Tunnel endpoint */
692 preEncodedHdr[--cnt] = 0;
693 preEncodedHdr[--cnt] = 0;
694 nwWord = (uint16_t)(GetHiWord(preDefHdr->teId));
695 preEncodedHdr[--cnt] = (uint8_t)(GetHiByte(nwWord));
696 preEncodedHdr[--cnt] = (uint8_t)(GetLoByte(nwWord));
697 nwWord = (uint16_t)(GetLoWord(preDefHdr->teId));
698 preEncodedHdr[--cnt] = (uint8_t)(GetHiByte(nwWord));
699 preEncodedHdr[--cnt] = (uint8_t)(GetLoByte(nwWord));
701 /* Encode sequence number */
702 if(preDefHdr->seqNum.pres)
704 preEncodedHdr[--cnt] = GetHiByte(preDefHdr->seqNum.val);
705 preEncodedHdr[--cnt] = GetLoByte(preDefHdr->seqNum.val);
709 preEncodedHdr[--cnt] = 0;
710 preEncodedHdr[--cnt] = 0;
713 /* Encode nPdu number */
714 if(preDefHdr->nPdu.pres)
716 preEncodedHdr[--cnt] = preDefHdr->nPdu.val;
720 preEncodedHdr[--cnt] = 0;
723 if(preDefHdr->extHdr.udpPort.pres)
725 preEncodedHdr[--cnt] = EGTP_EXT_HDR_UDP_TYPE;
726 preEncodedHdr[--cnt] = 1;
727 preEncodedHdr[--cnt] = GetHiByte(preDefHdr->extHdr.udpPort.val);
728 preEncodedHdr[--cnt] = GetLoByte(preDefHdr->extHdr.udpPort.val);
731 if(preDefHdr->extHdr.pdcpNmb.pres)
733 preEncodedHdr[--cnt] = EGTP_EXT_HDR_PDCP_TYPE;
734 preEncodedHdr[--cnt] = 1;
735 preEncodedHdr[--cnt] = GetHiByte(preDefHdr->extHdr.pdcpNmb.val);
736 preEncodedHdr[--cnt] = GetLoByte(preDefHdr->extHdr.pdcpNmb.val);
739 if(tmpByte & EGTP_MASK_BIT3)
741 preEncodedHdr[--cnt] = 0;
745 preEncodedHdr[--cnt] = 0;
750 } /* egtpEncodeHdr */
752 /*******************************************************************
754 * @brief Sends message over UDP
758 * Function : egtpSendMsg
761 * Sends message over UDP
763 * @params[in] Message Buffer
764 * @return ROK - success
767 * ****************************************************************/
768 uint8_t egtpSendMsg(Buffer *mBuf)
775 info.region = DU_APP_MEM_REGION;
778 dstAddr.port = EGTP_DFLT_PORT;
779 dstAddr.address = egtpCb.dstCb.dstIp;
781 ret = cmInetSendMsg(&(egtpCb.dstCb.sendTptSrvr.sockFd), &dstAddr, &info, \
782 mBuf, (int16_t *)&txLen, CM_INET_NO_FLAG);
783 if(ret != ROK && ret != RWOULDBLOCK)
785 DU_LOG("\nERROR --> EGTP : Failed sending the message");
789 DU_LOG("\nDEBUG --> EGTP : Message Sent");
794 /*******************************************************************
796 * @brief Receives EGTP message from UDP socket
800 * Function : egtpRecvMsg
803 * Receive incoming messages from UDP socket
806 * @return ROK - success
809 * ****************************************************************/
811 uint8_t egtpRecvMsg()
813 uint8_t ret; /* Return value */
814 uint8_t nMsg; /* Number of messages to read from UDP socked */
815 uint16_t bufLen; /* Length of received buffer */
816 Buffer *recvBuf; /* Received buffer */
817 CmInetAddr fromAddr; /* Egtp data sender address */
818 CmInetMemInfo memInfo; /* Buffer allocation info */
821 memInfo.region = DU_APP_MEM_REGION;
822 memInfo.pool = DU_POOL;
824 fromAddr.port = egtpCb.dstCb.dstPort;
825 fromAddr.address = egtpCb.dstCb.dstIp;
830 ret = cmInetRecvMsg(&(egtpCb.recvTptSrvr.sockFd), &fromAddr, &memInfo, \
831 &recvBuf, (int16_t *)&bufLen, CM_INET_NO_FLAG);
832 if(ret == ROK && recvBuf != NULLP)
834 DU_LOG("\nDEBUG --> EGTP : Received DL Message[%d]\n", nMsg+1);
835 ODU_PRINT_MSG(recvBuf, 0 ,0);
836 egtpHdlRecvData(recvBuf);
844 /*******************************************************************
846 * @brief Handles DL User data received from CU
850 * Function : egtpHdlRecvData
852 * Functionality: Handles DL User data received from CU
854 * @params[in] DL Usre data buffer
855 * @return ROK - success
858 * ****************************************************************/
859 uint8_t egtpHdlRecvData(Buffer *mBuf)
863 /* Decode EGTP header */
864 egtpDecodeHdr(mBuf, &egtpMsg);
866 /* TODO : Send received message to RLC */
867 duHdlEgtpDlData(&egtpMsg);
872 /*******************************************************************
874 * @brief Decodes EGTP header from DL User data
878 * Function : egtpDecodeHdr
880 * Functionality: Decodes EGTP header from DL User data
883 * @return ROK - success
886 * ****************************************************************/
887 uint8_t egtpDecodeHdr(Buffer *mBuf, EgtpMsg *egtpMsg)
889 uint8_t tmpByte[5]; /* Holds 5 byte of data after Decoding */
890 uint8_t version = 0; /* Holds the version type, decoded */
891 uint16_t msgLen = 0; /* Holds the msgLen from the Hdr */
892 uint16_t bufLen = 0; /* Holds the total buffer length */
893 uint8_t extHdrType = 0; /* Holds the Extension hdr type */
894 uint8_t extHdrLen = 0; /* Extension hdr length */
895 bool extPres = FALSE; /* Flag for indication of S, E or P presense flag */
897 ODU_GET_MSG_LEN(mBuf, (int16_t *)&bufLen);
899 /* Decode first byte and storing in temporary variable */
900 ODU_REM_PRE_MSG(&tmpByte[0], mBuf);
902 /* Extracting version fro 1st byte */
903 version = tmpByte[0] >> 5;
905 DU_LOG("\nDEBUG --> EGTP : Version %d", version);
907 /* Decode message type */
908 ODU_REM_PRE_MSG((Data*)&(egtpMsg->msgHdr.msgType), mBuf);
909 DU_LOG("\nDEBUG --> EGTP : msgType %d", egtpMsg->msgHdr.msgType);
911 /****************************************************************************
912 * Message length param is 2 bytes. So decode next 2 bytes from msg hdr and
913 * performing OR operation on these two bytes to calculate message length
914 ***************************************************************************/
915 ODU_REM_PRE_MSG(&tmpByte[1], mBuf);
916 ODU_REM_PRE_MSG(&tmpByte[2], mBuf);
917 msgLen = (tmpByte[1] << 8) | tmpByte[2];
918 DU_LOG("\nDEBUG --> EGTP : msgLen %d", msgLen);
921 /****************************************************************************
922 * Tunnel id param is 4 bytes. So decode next 4 bytes from msg hdr and
923 * perform OR operation on these 4 bytes to calculate tunnel id
924 ***************************************************************************/
925 ODU_REM_PRE_MSG(&tmpByte[1], mBuf);
926 ODU_REM_PRE_MSG(&tmpByte[2], mBuf);
927 ODU_REM_PRE_MSG(&tmpByte[3], mBuf);
928 ODU_REM_PRE_MSG(&tmpByte[4], mBuf);
929 egtpMsg->msgHdr.teId = (tmpByte[1] << 24) | (tmpByte[2] << 16) | (tmpByte[3] << 8) | tmpByte[4];
930 DU_LOG("\nDEBUG --> EGTP : teId %d",egtpMsg->msgHdr.teId);
933 /* If any one of S, E or PN flag is set, set extension present as true. */
934 if((tmpByte[0] & EGTP_MASK_BIT1) || (tmpByte[0] & EGTP_MASK_BIT2)||(tmpByte[0] & EGTP_MASK_BIT3))
939 /* Decode sequence number, if S flag is set in first byte */
940 if (tmpByte[0] & EGTP_MASK_BIT2)
942 /************************************************************************
943 * Sequence num is 2 bytes. So decode next 2 bytes from msg hdr and
944 * perform OR operation on them
945 ************************************************************************/
946 egtpMsg->msgHdr.seqNum.pres = TRUE;
947 ODU_REM_PRE_MSG(&tmpByte[1], mBuf);
948 ODU_REM_PRE_MSG(&tmpByte[2], mBuf);
949 egtpMsg->msgHdr.seqNum.val = (tmpByte[1] << 8) | tmpByte[2];
951 /****************************************************************************
952 * If extPres is true, but S bit is not set, implies, either of PN or E bit
953 * was set during Encode so accordingly extract Byte fields for seqNum anyway
954 ***************************************************************************/
957 /*************************************************************************
958 * Sequence num is 2 bytes. So decode next 2 bytes from msg hdr and
959 * perform OR operation on them
960 ************************************************************************/
961 egtpMsg->msgHdr.seqNum.pres = 0;
962 ODU_REM_PRE_MSG(&tmpByte[1], mBuf);
963 ODU_REM_PRE_MSG(&tmpByte[2], mBuf);
964 egtpMsg->msgHdr.seqNum.val = (tmpByte[1] << 8) | tmpByte[2];
967 /* Decode N-PDU number if present flag is set */
968 if (tmpByte[0] & EGTP_MASK_BIT1)
970 egtpMsg->msgHdr.nPdu.pres = TRUE;
971 ODU_REM_PRE_MSG(&(egtpMsg->msgHdr.nPdu.val), mBuf);
973 /****************************************************************************
974 * If extPres is true, but PN bit is not set, implies, either of S or E bit
975 * was set during Encode. Aaccordingly extract Byte fields of N-PDU num anyway
976 ***************************************************************************/
979 egtpMsg->msgHdr.nPdu.pres = TRUE;
980 ODU_REM_PRE_MSG(&(egtpMsg->msgHdr.nPdu.val), mBuf);
983 /* If E flag is set in first byte, decode extension header */
984 if(tmpByte[0] & EGTP_MASK_BIT3)
986 ODU_REM_PRE_MSG(&extHdrType, mBuf);
987 while( 0 != extHdrType)
991 case EGTP_EXT_HDR_UDP_TYPE:
993 ODU_REM_PRE_MSG(&extHdrLen, mBuf);
994 if(extHdrLen == 0x01)
996 /************************************************************
997 * UDP Port is 2 bytes. So decode next 2 bytes from msg hdr
998 * and perform OR operation on them
999 *************************************************************/
1000 egtpMsg->msgHdr.extHdr.udpPort.pres = TRUE;
1001 ODU_REM_PRE_MSG(&tmpByte[1], mBuf);
1002 ODU_REM_PRE_MSG(&tmpByte[2], mBuf);
1003 egtpMsg->msgHdr.extHdr.udpPort.val = (tmpByte[1] << 8) | tmpByte[2];
1008 case EGTP_EXT_HDR_PDCP_TYPE:
1010 ODU_REM_PRE_MSG(&extHdrLen, mBuf);
1011 if(extHdrLen == 0x01)
1013 /*************************************************************
1014 * PDCP num is 2 bytes. So decode next 2 bytes from msg hdr
1015 * and perform OR operation on them
1016 ************************************************************/
1017 egtpMsg->msgHdr.extHdr.pdcpNmb.pres = TRUE;
1018 ODU_REM_PRE_MSG(&tmpByte[1], mBuf);
1019 ODU_REM_PRE_MSG(&tmpByte[2], mBuf);
1020 egtpMsg->msgHdr.extHdr.pdcpNmb.val = (tmpByte[1] << 8) | tmpByte[2];
1024 } /* End of switch */
1026 ODU_REM_PRE_MSG(&extHdrType, mBuf);
1028 } /* End of while */
1030 /****************************************************************************
1031 * If extPres is true, but E bit is not set, implies, either of PN or S bit
1032 * was set during Encode so accordingly extract Byte fields for extension
1034 ***************************************************************************/
1037 ODU_REM_PRE_MSG(&extHdrType, mBuf);
1040 egtpMsg->msg = mBuf;
1042 DU_LOG("\nDEBUG --> EGTP : DL Data Buffer after decoding header ");
1043 ODU_PRINT_MSG(mBuf, 0, 0);
1045 /* Forward the data to duApp/RLC */
1050 /**********************************************************************
1052 **********************************************************************/