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 */
21 #include "common_def.h"
22 #include "cu_stub_egtp.h"
25 /* Global variable declaration */
28 /**************************************************************************
29 * @brief Task Initiation callback function.
33 * Function : egtpActvInit
36 * This function is supplied as one of parameters during EGTP's
37 * task registration. SSI will invoke this function once, after
38 * it creates and attaches this TAPA Task to a system task.
40 * @param[in] Ent entity, the entity ID of this task.
41 * @param[in] Inst inst, the instance ID of this task.
42 * @param[in] Region region, the region ID registered for memory
44 * @param[in] Reason reason.
45 * @return ROK - success
47 ***************************************************************************/
50 DU_LOG("\n\nDEBUG --> EGTP : Initializing");
51 memset (&egtpCb, 0, sizeof(EgtpGlobalCb));
52 protType = CM_INET_PROTO_UDP;
57 /**************************************************************************
58 * @brief Task Activation callback function.
62 * Function : egtpActvTsk
65 * This function handles all EGTP messages received
66 * This API is registered with SSI during the
67 * Task Registration of DU APP.
69 * @param[in] Pst *pst, Post structure of the primitive.
70 * @param[in] Buffer *mBuf, Packed primitive parameters in the
72 * @return ROK - success
75 ***************************************************************************/
84 DU_LOG("\nERROR --> EGTP : Configuration failed");
88 ret = cuEgtpSrvOpenReq();
91 DU_LOG("\nERROR --> EGTP : Transport server open request failed");
95 tnlEvt.action = EGTP_TNL_MGMT_ADD;
98 ret = cuEgtpTnlMgmtReq(tnlEvt);
101 DU_LOG("\nERROR --> EGTP : Tunnel management request failed");
108 /**************************************************************************
109 * @brief EGTP server configuration
113 * Function : egtpCfgReq
116 * This function handles EGTP configuration request.
118 * @return ROK - success
121 * ***********************************************************************/
126 memcpy(&egtpCb.egtpCfg, &cuCfgParams.egtpParams, sizeof(EgtpParams));
128 egtpCb.recvTptSrvr.addr.address = CM_INET_NTOH_UINT32(egtpCb.egtpCfg.localIp.ipV4Addr);
129 egtpCb.recvTptSrvr.addr.port = EGTP_DFLT_PORT;
131 egtpCb.dstCb.dstIp = CM_INET_NTOH_UINT32(egtpCb.egtpCfg.destIp.ipV4Addr);
132 egtpCb.dstCb.dstPort = egtpCb.egtpCfg.destPort;
133 egtpCb.dstCb.sendTptSrvr.addr.address = CM_INET_NTOH_UINT32(egtpCb.egtpCfg.localIp.ipV4Addr);
134 egtpCb.dstCb.sendTptSrvr.addr.port = egtpCb.egtpCfg.localPort;
135 egtpCb.dstCb.numTunn = 0;
137 ret = cmHashListInit(&(egtpCb.dstCb.teIdLst), 1024, sizeof(EgtpTeIdCb), FALSE, CM_HASH_KEYTYPE_UINT32_MOD, CU_APP_MEM_REG, CU_POOL);
141 DU_LOG("\nERROR --> EGTP : TeId hash list initialization failed");
146 DU_LOG("\nINFO --> EGTP : Configuration successful");
152 /**************************************************************************
153 * @brief EGTP server open request
157 * Function : egtpSrvOpenReq
160 * This function handles EGTP open server request.
161 * It opens udp socket to receive/send msgs.
163 * @param[in] Pst *pst, post structure
164 * @return ROK - success
167 ***************************************************************************/
169 S16 cuEgtpSrvOpenReq(Pst *pst)
174 DU_LOG("\nINFO --> EGTP : Received open server request");
176 sockType = CM_INET_DGRAM;
177 if((ret = (cmInetSocket(sockType, &(egtpCb.recvTptSrvr.sockFd), protType))) != ROK)
179 DU_LOG("\nERROR --> EGTP : Failed to open UDP socket");
183 ret = cmInetBind(&(egtpCb.recvTptSrvr.sockFd), &(egtpCb.recvTptSrvr.addr));
186 DU_LOG("\nERROR --> EGTP : Failed to bind socket");
190 if(ret = (cmInetSocket(sockType, &(egtpCb.dstCb.sendTptSrvr.sockFd), protType)) != ROK)
192 DU_LOG("\nERROR --> EGTP : Failed to open UDP socket");
196 ret = cmInetBind(&(egtpCb.dstCb.sendTptSrvr.sockFd), &(egtpCb.dstCb.sendTptSrvr.addr));
199 DU_LOG("\nERROR --> EGTP : Failed to bind socket");
203 /* TODO: set socket options */
205 DU_LOG("\nINFO --> EGTP : Receiver socket[%d] and Sender socket[%d] open", egtpCb.recvTptSrvr.sockFd.fd,\
206 egtpCb.dstCb.sendTptSrvr.sockFd.fd);
208 } /* cuEgtpSrvOpenReq */
211 /**************************************************************************
212 * @brief EGTP tunnel management request
216 * Function : cuEgtpTnlMgmtReq
219 * This function handles EGTP tunnel managament request
221 * @param[in] Pst *pst, post structure
222 * Tunnel Eveny structure
223 * @return ROK - success
227 * ***************************************************************************/
228 S16 cuEgtpTnlMgmtReq(EgtpTnlEvt tnlEvt)
232 DU_LOG("\nINFO --> EGTP : Received tunnel management request");
233 switch(tnlEvt.action)
235 case EGTP_TNL_MGMT_ADD:
237 ret = cuEgtpTnlAdd(tnlEvt);
240 case EGTP_TNL_MGMT_MOD:
242 ret = cuEgtpTnlMod(tnlEvt);
245 case EGTP_TNL_MGMT_DEL:
247 ret = cuEgtpTnlDel(tnlEvt);
252 DU_LOG("\nERROR --> EGTP : Invalid tunnel management action[%d]", tnlEvt.action);
260 /**************************************************************************
261 * @brief EGTP tunnel addition
265 * Function : cuEgtpTnlAdd
268 * This function handles EGTP tunnel addition
270 * @param[in] Tunnel Event structure
271 * @return ROK - success
274 * ***************************************************************************/
275 S16 cuEgtpTnlAdd(EgtpTnlEvt tnlEvt)
279 EgtpMsgHdr preDefHdr; /* pre-define header for this tunnel */
282 DU_LOG("\nINFO --> EGTP : Tunnel addition : LocalTeid[%d] Remote Teid[%d]", tnlEvt.lclTeid, tnlEvt.remTeid);
284 CU_ALLOC(teidCb, (Size)sizeof(EgtpTeIdCb));
288 DU_LOG("\nERROR --> EGTP : Memory allocation failed");
293 memset(teidCb, 0, sizeof(EgtpTeIdCb));
294 teidCb->teId = tnlEvt.lclTeid;
295 teidCb->remTeId = tnlEvt.remTeid;
297 ret = cmHashListInsert(&(egtpCb.dstCb.teIdLst), (PTR)teidCb, (uint8_t *)&(teidCb->teId), sizeof(uint32_t));
300 DU_LOG("\nERROR --> EGTP : Failed to insert in hash list");
301 CU_FREE(teidCb, (Size)sizeof(EgtpTeIdCb));
304 egtpCb.dstCb.numTunn++;
306 /* Encoding pre-defined header */
307 memset(&preDefHdr, 0, sizeof(EgtpMsgHdr));
308 preDefHdr.msgType = EGTPU_MSG_GPDU;
309 preDefHdr.teId = teidCb->remTeId;
310 preDefHdr.extHdr.pdcpNmb.pres = FALSE;
311 preDefHdr.extHdr.udpPort.pres = FALSE;
312 preDefHdr.nPdu.pres = FALSE;
314 cuEgtpEncodeHdr((uint8_t *)teidCb->preEncodedHdr.hdr, &preDefHdr, &(teidCb->preEncodedHdr.cnt));
316 /* SPutSBuf(CU_APP_MEM_REG, CU_POOL, (Data *)teidCb, (Size)sizeof(EgtpTeIdCb));*/
321 /**************************************************************************
322 * @brief EGTP tunnel modification
326 * Function : cuEgtpTnlMod
329 * This function handles EGTP tunnel modification
331 * @param[in] Tunnel Event structure
332 * @return ROK - success
335 * ***************************************************************************/
336 S16 cuEgtpTnlMod(EgtpTnlEvt tnlEvt)
340 EgtpTeIdCb *teidCb = NULLP;
342 DU_LOG("\nDEBUG --> CU_STUB : Tunnel modification : LocalTeid[%d] Remote Teid[%d]", tnlEvt.lclTeid, tnlEvt.remTeid);
344 cmHashListFind(&(egtpCb.dstCb.teIdLst), (uint8_t *)&(tnlEvt.teId), sizeof(uint32_t), 0, (PTR *)&teidCb);
347 DU_LOG("\nDEBUG --> CU_STUBTunnel id not found");
351 teidCb->teId = tnlEvt.lclTeid;
352 teidCb->remTeId = tnlEvt.remTeid;
357 /**************************************************************************
358 * @brief EGTP tunnel deletion
362 * Function : cuEgtpTnlDel
365 * This function handles EGTP tunnel deletion
367 * @param[in] Tunnel Event structure
368 * @return ROK - success
371 * ***************************************************************************/
372 S16 cuEgtpTnlDel(EgtpTnlEvt tnlEvt)
374 EgtpTeIdCb *teidCb = NULLP;
376 DU_LOG("\nDEBUG --> EGTP : Tunnel deletion : Local Teid[%d] Remote Teid[%d]", tnlEvt.lclTeid, tnlEvt.remTeid);
378 cmHashListFind(&(egtpCb.dstCb.teIdLst), (uint8_t *)&(tnlEvt.lclTeid), sizeof(uint32_t), 0, (PTR *)&teidCb);
381 DU_LOG("\nERROR --> EGTP : Tunnel id[%d] not configured", tnlEvt.lclTeid);
385 cmHashListDelete(&(egtpCb.dstCb.teIdLst), (PTR)teidCb);
386 CU_FREE(teidCb, (Size)sizeof(EgtpTeIdCb));
387 egtpCb.dstCb.numTunn--;
392 /*******************************************************************
394 * @brief Encodes message header
398 * Function : cuEgtpEncodeHdr
401 * Encodes EGTP message haeder
403 * @params[in] EGTP message
405 * @return ROK - success
408 * ****************************************************************/
409 S16 cuEgtpEncodeHdr(uint8_t *preEncodedHdr, EgtpMsgHdr *preDefHdr, uint8_t *hdrIdx)
411 uint8_t tmpByte = 0; /* Stores one byte of data for enc */
412 uint8_t cnt = EGTP_MAX_HDR_LEN; /* Stores the position */
413 Bool extPres = FALSE; /* Flag for indication of S, E or P presense flag */
416 /* Encoding header */
417 tmpByte |= EGTP_MASK_BIT6; /* Setting 6th LSB of 1st byte as version */
418 tmpByte |= EGTP_MASK_BIT5; /* Setting 5th LSB of 1st byte as protocol type */
420 if(preDefHdr->extHdr.udpPort.pres || preDefHdr->extHdr.pdcpNmb.pres)
422 tmpByte |= EGTP_MASK_BIT3; /* Setting 3rd LSB of 1st byte if Extension heaeder is present */
425 if(preDefHdr->seqNum.pres)
427 tmpByte |= EGTP_MASK_BIT2;
430 if(preDefHdr->nPdu.pres)
432 tmpByte |= EGTP_MASK_BIT1;
435 if((tmpByte & EGTP_MASK_BIT1) || (tmpByte & EGTP_MASK_BIT2)||(tmpByte & EGTP_MASK_BIT3))
439 preEncodedHdr[--cnt] = tmpByte;
440 preEncodedHdr[--cnt] = preDefHdr->msgType;
442 /* Encode Tunnel endpoint */
443 preEncodedHdr[--cnt] = 0;
444 preEncodedHdr[--cnt] = 0;
445 nwWord = (uint16_t)(GetHiWord(preDefHdr->teId));
446 preEncodedHdr[--cnt] = (uint8_t)(GetHiByte(nwWord));
447 preEncodedHdr[--cnt] = (uint8_t)(GetLoByte(nwWord));
448 nwWord = (uint16_t)(GetLoWord(preDefHdr->teId));
449 preEncodedHdr[--cnt] = (uint8_t)(GetHiByte(nwWord));
450 preEncodedHdr[--cnt] = (uint8_t)(GetLoByte(nwWord));
452 /* Encode sequence number */
453 if(preDefHdr->seqNum.pres)
455 preEncodedHdr[--cnt] = GetHiByte(preDefHdr->seqNum.val);
456 preEncodedHdr[--cnt] = GetLoByte(preDefHdr->seqNum.val);
460 preEncodedHdr[--cnt] = 0;
461 preEncodedHdr[--cnt] = 0;
464 if(preDefHdr->nPdu.pres)
466 preEncodedHdr[--cnt] = preDefHdr->nPdu.val;
470 preEncodedHdr[--cnt] = 0;
473 if(preDefHdr->extHdr.udpPort.pres)
475 preEncodedHdr[--cnt] = EGTP_EXT_HDR_UDP_TYPE;
476 preEncodedHdr[--cnt] = 1;
477 preEncodedHdr[--cnt] = GetHiByte(preDefHdr->extHdr.udpPort.val);
478 preEncodedHdr[--cnt] = GetLoByte(preDefHdr->extHdr.udpPort.val);
481 if(preDefHdr->extHdr.pdcpNmb.pres)
483 preEncodedHdr[--cnt] = EGTP_EXT_HDR_PDCP_TYPE;
484 preEncodedHdr[--cnt] = 1;
485 preEncodedHdr[--cnt] = GetHiByte(preDefHdr->extHdr.pdcpNmb.val);
486 preEncodedHdr[--cnt] = GetLoByte(preDefHdr->extHdr.pdcpNmb.val);
489 if(tmpByte & EGTP_MASK_BIT3)
491 preEncodedHdr[--cnt] = 0;
495 preEncodedHdr[--cnt] = 0;
501 } /* egtpEncodeHdr */
503 S16 cuEgtpHdlRecvMsg(Buffer *mBuf)
505 /*Decoding of EGTP message header */
506 cuEgtpDecodeHdr(mBuf);
508 /* Start Pumping data from CU to DU */
509 //return (cuEgtpDatReq());
513 S16 cuEgtpDecodeHdr(Buffer *mBuf)
516 uint8_t tmpByte[5]; /* Holds one byte of data after Dec */
517 uint8_t version = 0; /* Holds the version type, decoded */
518 MsgLen msgLen = 0; /* Holds the msgLen from the Hdr */
519 MsgLen bufLen = 0; /* Holds the total buffer length */
520 uint8_t extHdrType = 0; /* Holds the Extension hdr type */
521 uint8_t extHdrLen = 0; /* Extension hdr length */
522 Bool extPres = FALSE; /* Flag for indication of S, E or P presense flag */
524 ODU_GET_MSG_LEN(mBuf, &bufLen);
527 ODU_REM_PRE_MSG(&tmpByte[0], mBuf);
528 version = tmpByte[0] >> 5;
530 /* Decode message type */
531 ODU_REM_PRE_MSG((Data*)&(egtpMsg.msgHdr.msgType), mBuf);
533 /* Decode message length */
534 ODU_REM_PRE_MSG(&tmpByte[1], mBuf);
535 ODU_REM_PRE_MSG(&tmpByte[2], mBuf);
536 msgLen = (tmpByte[1] << 8) | tmpByte[2];
538 /* Decode tunnel id */
539 ODU_REM_PRE_MSG(&tmpByte[1], mBuf);
540 ODU_REM_PRE_MSG(&tmpByte[2], mBuf);
541 ODU_REM_PRE_MSG(&tmpByte[3], mBuf);
542 ODU_REM_PRE_MSG(&tmpByte[4], mBuf);
543 egtpMsg.msgHdr.teId = (tmpByte[1] << 24) | (tmpByte[2] << 16) | (tmpByte[3] << 8) | tmpByte[4];
545 if((tmpByte[0] & EGTP_MASK_BIT1) || (tmpByte[0] & EGTP_MASK_BIT2)||(tmpByte[0] & EGTP_MASK_BIT3))
550 /* Decode sequence number */
551 if ( tmpByte[0] & EGTP_MASK_BIT2 )
553 egtpMsg.msgHdr.seqNum.pres = TRUE;
554 ODU_REM_PRE_MSG(&tmpByte[1], mBuf);
555 ODU_REM_PRE_MSG(&tmpByte[2], mBuf);
556 egtpMsg.msgHdr.seqNum.val = (tmpByte[1] << 8) | tmpByte[2];
560 egtpMsg.msgHdr.seqNum.pres = 0;
561 ODU_REM_PRE_MSG(&tmpByte[1], mBuf);
562 ODU_REM_PRE_MSG(&tmpByte[2], mBuf);
563 egtpMsg.msgHdr.seqNum.val = (tmpByte[1] << 8) | tmpByte[2];
566 /* Decode N-PDU number */
567 if ( tmpByte[0] & EGTP_MASK_BIT1 )
569 egtpMsg.msgHdr.nPdu.pres = TRUE;
570 ODU_REM_PRE_MSG(&(egtpMsg.msgHdr.nPdu.val), mBuf);
574 egtpMsg.msgHdr.nPdu.pres = TRUE;
575 ODU_REM_PRE_MSG(&(egtpMsg.msgHdr.nPdu.val), mBuf);
578 if(extPres & EGTP_MASK_BIT1)
580 ODU_REM_PRE_MSG(&extHdrType, mBuf);
581 while( 0 != extHdrType)
585 case EGTP_EXT_HDR_UDP_TYPE:
587 ODU_REM_PRE_MSG(&extHdrLen, mBuf);
588 if(extHdrLen == 0x01)
590 egtpMsg.msgHdr.extHdr.udpPort.pres = TRUE;
591 ODU_REM_PRE_MSG(&tmpByte[1], mBuf);
592 ODU_REM_PRE_MSG(&tmpByte[2], mBuf);
593 egtpMsg.msgHdr.extHdr.udpPort.val = (tmpByte[1] << 8) | tmpByte[2];
598 case EGTP_EXT_HDR_PDCP_TYPE:
600 ODU_REM_PRE_MSG(&extHdrLen, mBuf);
601 if(extHdrLen == 0x01)
603 egtpMsg.msgHdr.extHdr.pdcpNmb.pres = TRUE;
604 ODU_REM_PRE_MSG(&tmpByte[1], mBuf);
605 ODU_REM_PRE_MSG(&tmpByte[2], mBuf);
606 egtpMsg.msgHdr.extHdr.pdcpNmb.val = (tmpByte[1] << 8) | tmpByte[2];
610 } /* End of switch */
612 ODU_REM_PRE_MSG(&extHdrType, mBuf);
615 } /* End of if(extPres & EGTP_MASK_BIT1) */
618 ODU_REM_PRE_MSG(&extHdrType, mBuf);
621 DU_LOG("\nDEBUG --> EGTP : Message Buffer after decoding header ");
622 ODU_PRINT_MSG(mBuf, 0, 0);
626 } /* End of cuEgtpDecodeHdr */
630 uint8_t ret = ROK, cnt = 0;
633 /* Build Application message that is supposed to come from app to egtp */
634 ret = BuildAppMsg(&egtpMsg);
637 DU_LOG("\nERROR --> EGTP : Failed to build App Msg");
641 /* Encode EGTP header to build final EGTP message */
642 ret = BuildEgtpMsg(&egtpMsg);
645 DU_LOG("\nERROR --> EGTP : Failed to build EGTP Msg");
648 /* Send Message to peer */
651 DU_LOG("\nDEBUG --> EGTP : Sending message[%d]", cnt+1);
652 cuEgtpSendMsg(egtpMsg.msg);
657 ODU_PUT_MSG_BUF(egtpMsg.msg);
663 S16 BuildAppMsg(EgtpMsg *egtpMsg)
665 char data[1215] = "In telecommunications, 5G is the fifth generation technology standard for broadband cellular"
666 " networks, which cellular phone companies began deploying worldwide in 2019, and is the planned successor to the 4G "
667 " networks which provide connectivity to most current cellphones. 5G networks are predicted to have more than 1.7"
668 " billion subscribers worldwide by 2025, according to the GSM Association.Like its predecessors, 5G networks are"
669 " cellular networks,in which the service area is divided into small geographical areas called cells.All 5G wireless"
670 " devices in a cell are connected to the Internet and telephone network by radio waves through local antenna in the"
671 " cell. The main advantage of the new networks is that they will have greater bandwidth, giving higher download"
672 " speeds, eventually up to 10 gigabits per second(Gbit/s). Due to the increased bandwidth, it is expected the"
673 " networks will not exclusively serve cellphones like existing cellular networks, but also be used as general"
674 " internet service providers for laptops and desktop computers, competing with existing ISPs such as cable"
675 " internet, and also will make possible new applications in internet of things (IoT) and machine to machine areas.";
681 if(ODU_GET_MSG_BUF(CU_APP_MEM_REG, CU_POOL, &mBuf) == ROK)
683 if(ODU_ADD_POST_MSG_MULT((Data *)data, datSize, mBuf) != ROK)
685 DU_LOG("\nERROR --> EGTP : ODU_ADD_POST_MSG_MULT failed");
686 ODU_PUT_MSG_BUF(mBuf);
692 DU_LOG("\nERROR --> EGTP : Failed to allocate memory");
696 /* filling IPv4 header */
701 ODU_GET_MSG_LEN(mBuf, &mLen);
703 memset(&ipv4Hdr, 0, sizeof(CmIpv4Hdr));
704 ipv4Hdr.length = CM_IPV4_HDRLEN + mLen;
705 ipv4Hdr.hdrVer = 0x45;
707 ipv4Hdr.srcAddr = CM_INET_NTOH_UINT32(egtpCb.egtpCfg.localIp.ipV4Addr);
708 ipv4Hdr.destAddr = CM_INET_NTOH_UINT32(egtpCb.egtpCfg.destIp.ipV4Addr);
710 /* Packing IPv4 header into buffer */
712 Data revPkArray[CM_IPV4_HDRLEN];
713 Data pkArray[CM_IPV4_HDRLEN];
715 /* initialize locals */
717 memset(revPkArray, 0, CM_IPV4_HDRLEN);
718 memset(pkArray, 0, CM_IPV4_HDRLEN);
720 /* Pack Header Version */
721 pkArray[cnt++] = ipv4Hdr.hdrVer;
724 pkArray[cnt++] = ipv4Hdr.tos;
726 pkArray[cnt++] = (Data)GetHiByte(ipv4Hdr.length);
727 pkArray[cnt++] = (Data)GetLoByte(ipv4Hdr.length);
730 pkArray[cnt++] = (Data) GetHiByte(ipv4Hdr.id);
731 pkArray[cnt++] = (Data) GetLoByte(ipv4Hdr.id);
734 pkArray[cnt++] = (Data)GetHiByte(ipv4Hdr.off);
735 pkArray[cnt++] = (Data)GetLoByte(ipv4Hdr.off);
738 pkArray[cnt++] = ipv4Hdr.ttl;
741 pkArray[cnt++] = ipv4Hdr.proto;
744 pkArray[cnt++] = (Data)GetHiByte(ipv4Hdr.chkSum);
745 pkArray[cnt++] = (Data)GetLoByte(ipv4Hdr.chkSum);
747 /* Pack Source Address */
748 pkArray[cnt++] = (Data)GetHiByte(GetHiWord(ipv4Hdr.srcAddr));
749 pkArray[cnt++] = (Data)GetLoByte(GetHiWord(ipv4Hdr.srcAddr));
750 pkArray[cnt++] = (Data)GetHiByte(GetLoWord(ipv4Hdr.srcAddr));
751 pkArray[cnt++] = (Data)GetLoByte(GetLoWord(ipv4Hdr.srcAddr));
753 /* Pack Destination Address */
754 pkArray[cnt++] = (Data)GetHiByte(GetHiWord(ipv4Hdr.destAddr));
755 pkArray[cnt++] = (Data)GetLoByte(GetHiWord(ipv4Hdr.destAddr));
756 pkArray[cnt++] = (Data)GetHiByte(GetLoWord(ipv4Hdr.destAddr));
757 pkArray[cnt++] = (Data)GetLoByte(GetLoWord(ipv4Hdr.destAddr));
759 for (idx = 0; idx < CM_IPV4_HDRLEN; idx++)
760 revPkArray[idx] = pkArray[CM_IPV4_HDRLEN - idx -1];
762 /* this function automatically reverses revPkArray */
763 ret = ODU_ADD_PRE_MSG_MULT(revPkArray, (MsgLen)cnt, mBuf);
765 egtpMsg->msgHdr.msgType = EGTPU_MSG_GPDU;
766 egtpMsg->msgHdr.nPdu.pres = FALSE;
767 egtpMsg->msgHdr.seqNum.pres = FALSE;
768 egtpMsg->msgHdr.extHdr.udpPort.pres = FALSE;
769 egtpMsg->msgHdr.extHdr.pdcpNmb.pres = FALSE;
770 egtpMsg->msgHdr.teId = 1;
777 S16 BuildEgtpMsg(EgtpMsg *egtpMsg)
779 EgtpTeIdCb *teidCb = NULLP;
785 cmHashListFind(&(egtpCb.dstCb.teIdLst), (uint8_t *)&(egtpMsg->msgHdr.teId), sizeof(uint32_t), 0, (PTR *)&teidCb);
788 DU_LOG("\nERROR --> EGTP : Tunnel id[%d] not configured", egtpMsg->msgHdr.teId);
789 return (LCM_REASON_INVALID_PAR_VAL);
792 msgHdr = &(egtpMsg->msgHdr);
794 hdrLen = teidCb->preEncodedHdr.cnt;
796 if(msgHdr->extHdr.pdcpNmb.pres)
798 teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 1] |= EGTP_MASK_BIT3;
799 teidCb->preEncodedHdr.hdr[hdrLen] = EGTP_EXT_HDR_PDCP_TYPE;
800 teidCb->preEncodedHdr.hdr[--hdrLen] = 1;
801 teidCb->preEncodedHdr.hdr[--hdrLen] = GetHiByte(msgHdr->extHdr.pdcpNmb.val);
802 teidCb->preEncodedHdr.hdr[--hdrLen] = GetLoByte(msgHdr->extHdr.pdcpNmb.val);
803 teidCb->preEncodedHdr.hdr[--hdrLen] = 0;
807 teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 1] &= ~(EGTP_MASK_BIT3);
810 ODU_GET_MSG_LEN(egtpMsg->msg, &tPduSize);
812 /*Adjust the header to fill the correct length*/
813 msgLen = tPduSize + (EGTP_MAX_HDR_LEN - hdrLen) - 0x08;
815 /***********************************************
816 * Fill the length field of the message header *
817 ***********************************************/
818 teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 3] = (uint8_t)GetHiByte(msgLen);
819 teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 4] = (uint8_t)GetLoByte(msgLen);
821 /*Update the sequence number*/
822 if(egtpMsg->msgHdr.seqNum.pres)
824 teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 1] |= (EGTP_MASK_BIT2);
825 teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 9] = (uint8_t)GetHiByte(egtpMsg->msgHdr.seqNum.val);
826 teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 10] = (uint8_t)GetLoByte(egtpMsg->msgHdr.seqNum.val);
830 teidCb->preEncodedHdr.hdr[EGTP_MAX_HDR_LEN - 1] &= ~(EGTP_MASK_BIT2);
833 ODU_ADD_PRE_MSG_MULT(&teidCb->preEncodedHdr.hdr[hdrLen], (EGTP_MAX_HDR_LEN - hdrLen), egtpMsg->msg);
835 DU_LOG("\nDEBUG --> EGTP : Sending message buffer");
836 ODU_PRINT_MSG(egtpMsg->msg, 0, 0);
841 S16 cuEgtpSendMsg(Buffer *mBuf)
848 info.region = CU_APP_MEM_REG;
851 dstAddr.port = EGTP_DFLT_PORT;
852 dstAddr.address = egtpCb.dstCb.dstIp;
854 ret = cmInetSendMsg(&(egtpCb.dstCb.sendTptSrvr.sockFd), &dstAddr, &info, mBuf, &txLen, CM_INET_NO_FLAG);
855 if(ret != ROK && ret != RWOULDBLOCK)
857 DU_LOG("\nERROR --> EGTP : Message send failure");
861 DU_LOG("\nDEBUG --> EGTP : Message Sent");