[GITLAB] - UPGRADE TO v12 on Wednesday the 18th of December at 11.30AM

NwGtpv1u.c 32.6 KB
Newer Older
Cedric Roux's avatar
Cedric Roux committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
/*----------------------------------------------------------------------------*
 *                                                                            *
 *                             n w - g t p v 2 u                              *
 *    G P R S    T u n n e l i n g    P r o t o c o l   v 2 u   S t a c k     *
 *                                                                            *
 *                                                                            *
 * Copyright (c) 2010-2011 Amit Chawre                                        *
 * All rights reserved.                                                       *
 *                                                                            *
 * Redistribution and use in source and binary forms, with or without         *
 * modification, are permitted provided that the following conditions         *
 * are met:                                                                   *
 *                                                                            *
 * 1. Redistributions of source code must retain the above copyright          *
 *    notice, this list of conditions and the following disclaimer.           *
 * 2. Redistributions in binary form must reproduce the above copyright       *
 *    notice, this list of conditions and the following disclaimer in the     *
 *    documentation and/or other materials provided with the distribution.    *
 * 3. The name of the author may not be used to endorse or promote products   *
 *    derived from this software without specific prior written permission.   *
 *                                                                            *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR       *
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES  *
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.    *
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,           *
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT   *
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  *
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY      *
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT        *
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF   *
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.          *
 *----------------------------------------------------------------------------*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "NwTypes.h"
#include "NwUtils.h"
#include "NwGtpv1uError.h"
#include "NwGtpv1uPrivate.h"
#include "NwGtpv1uTunnelEndPoint.h"
#include "NwGtpv1uTrxn.h"
#include "NwGtpv1u.h"
#include "NwGtpv1uIe.h"
#include "NwGtpv1uLog.h"

48
#include "assertions.h"
49
#include "intertask_interface.h"
gauthier's avatar
gauthier committed
50
#include "msc.h"
51

52
#include "gtpv1u.h"
gauthier's avatar
gauthier committed
53
#if defined(ENB_MODE)
gauthier's avatar
gauthier committed
54
#include "UTIL/LOG/log.h"
gauthier's avatar
gauthier committed
55
#include "UTIL/LOG/vcd_signal_dumper.h"
gauthier's avatar
gauthier committed
56
#endif
gauthier's avatar
gauthier committed
57

Cedric Roux's avatar
Cedric Roux committed
58 59 60 61 62 63 64 65
#ifdef __cplusplus
extern "C" {
#endif

/*--------------------------------------------------------------------------*
 *                    P R I V A T E    F U N C T I O N S                    *
 *--------------------------------------------------------------------------*/

66
#define NW_GTPV1U_EPC_SPECIFIC_HEADER_SIZE                             (12)   /**< Size of GTPv1u EPC specific header */
nikaeinn's avatar
nikaeinn committed
67 68 69
#define NW_GTPV1U_EPC_MIN_HEADER_SIZE                                  (8)


Cedric Roux's avatar
Cedric Roux committed
70 71 72
void
nwGtpv1uDisplayBanner(void)
{
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
  printf(" *----------------------------------------------------------------------------*\n");
  printf(" *                                                                            *\n");
  printf(" *                             n w - g t p v 2 u                              *\n");
  printf(" *    G P R S    T u n n e l i n g    P r o t o c o l   v 2 u   S t a c k     *\n");
  printf(" *                                                                            *\n");
  printf(" *                                                                            *\n");
  printf(" * Copyright (c) 2010-2011 Amit Chawre                                        *\n");
  printf(" * All rights reserved.                                                       *\n");
  printf(" *                                                                            *\n");
  printf(" * Redistribution and use in source and binary forms, with or without         *\n");
  printf(" * modification, are permitted provided that the following conditions         *\n");
  printf(" * are met:                                                                   *\n");
  printf(" *                                                                            *\n");
  printf(" * 1. Redistributions of source code must retain the above copyright          *\n");
  printf(" *    notice, this list of conditions and the following disclaimer.           *\n");
  printf(" * 2. Redistributions in binary form must reproduce the above copyright       *\n");
  printf(" *    notice, this list of conditions and the following disclaimer in the     *\n");
  printf(" *    documentation and/or other materials provided with the distribution.    *\n");
  printf(" * 3. The name of the author may not be used to endorse or promote products   *\n");
  printf(" *    derived from this software without specific prior written permission.   *\n");
  printf(" *                                                                            *\n");
  printf(" * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR       *\n");
  printf(" * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES  *\n");
  printf(" * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.    *\n");
  printf(" * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,           *\n");
  printf(" * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT   *\n");
  printf(" * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  *\n");
  printf(" * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY      *\n");
  printf(" * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT        *\n");
  printf(" * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF   *\n");
  printf(" * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.          *\n");
  printf(" *----------------------------------------------------------------------------*\n\n");
Cedric Roux's avatar
Cedric Roux committed
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148

}
/*---------------------------------------------------------------------------
 * RBTree Search Functions
 *--------------------------------------------------------------------------*/

static inline NwS32T
nwGtpv1uCompareTeid(struct NwGtpv1uTunnelEndPoint *a,
                    struct NwGtpv1uTunnelEndPoint *b);

static inline NwS32T
nwGtpv1uCompareSeqNum(struct NwGtpv1uTrxn *a, struct NwGtpv1uTrxn *b);

RB_PROTOTYPE(NwGtpv1uOutstandingTxSeqNumTrxnMap, NwGtpv1uTrxn,
             outstandingTxSeqNumMapRbtNode, nwGtpv1uCompareSeqNum)
RB_PROTOTYPE(NwGtpv1uOutstandingRxSeqNumTrxnMap, NwGtpv1uTrxn,
             outstandingRxSeqNumMapRbtNode, nwGtpv1uCompareSeqNum)
RB_PROTOTYPE(NwGtpv1uTunnelEndPointTMap, NwGtpv1uTunnelEndPoint,
             sessionMapRbtNode, nwGtpv1uCompareTeid)
RB_PROTOTYPE(NwGtpv1uTunnelEndPointIdentifierMap, NwGtpv1uTunnelEndPoint,
             sessionMapRbtNode, nwGtpv1uCompareTeid)

RB_GENERATE(NwGtpv1uOutstandingTxSeqNumTrxnMap, NwGtpv1uTrxn,
            outstandingTxSeqNumMapRbtNode, nwGtpv1uCompareSeqNum)
RB_GENERATE(NwGtpv1uOutstandingRxSeqNumTrxnMap, NwGtpv1uTrxn,
            outstandingRxSeqNumMapRbtNode, nwGtpv1uCompareSeqNum)
RB_GENERATE(NwGtpv1uTunnelEndPointTMap, NwGtpv1uTunnelEndPoint,
            sessionMapRbtNode, nwGtpv1uCompareTeid)
RB_GENERATE(NwGtpv1uTunnelEndPointIdentifierMap, NwGtpv1uTunnelEndPoint,
            sessionMapRbtNode, nwGtpv1uCompareTeid)

/**
  Comparator funtion for comparing two sessions.

  @param[in] a: Pointer to session a.
  @param[in] b: Pointer to session b.
  @return  An integer greater than, equal to or less than zero according to whether the
  object pointed to by a is greater than, equal to or less than the object pointed to by b.
 */

static inline NwS32T
nwGtpv1uCompareTeid(struct NwGtpv1uTunnelEndPoint *a,
                    struct NwGtpv1uTunnelEndPoint *b)
{
149 150 151 152 153 154 155 156 157
  if(a->teid > b->teid) {
    return 1;
  }

  if(a->teid < b->teid) {
    return -1;
  }

  return 0;
Cedric Roux's avatar
Cedric Roux committed
158 159 160 161 162 163 164 165 166 167 168 169 170 171
}

/**
  Comparator funtion for comparing two sequence number transactions.

  @param[in] a: Pointer to session a.
  @param[in] b: Pointer to session b.
  @return  An integer greater than, equal to or less than zero according to whether the
  object pointed to by a is greater than, equal to or less than the object pointed to by b.
 */

static inline NwS32T
nwGtpv1uCompareSeqNum(struct NwGtpv1uTrxn *a, struct NwGtpv1uTrxn *b)
{
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
  if(a->seqNum > b->seqNum) {
    return 1;
  }

  if(a->seqNum < b->seqNum) {
    return -1;
  }

  if(a->peerIp > b->peerIp) {
    return 1;
  }

  if(a->peerIp < b->peerIp) {
    return -1;
  }

  return 0;
Cedric Roux's avatar
Cedric Roux committed
189 190 191 192 193 194 195 196 197 198
}

/**
  Create and Send GTPU message.

  @param[in] thiz: Stack handle
  @return NW_GTPV1U_OK on success.
 */

static NwGtpv1uRcT
199
nwGtpv1uCreateAndSendMsg( NwGtpv1uStackT *thiz, uint32_t peerIp, uint16_t peerPort,
Cedric Roux's avatar
Cedric Roux committed
200 201
                          NwGtpv1uMsgT *pMsg)
{
202
  NwGtpv1uRcT rc = NW_GTPV1U_FAILURE;
203
  uint8_t *msgHdr;
Cedric Roux's avatar
Cedric Roux committed
204

205 206
  NW_ASSERT(thiz);
  NW_ASSERT(pMsg);
Cedric Roux's avatar
Cedric Roux committed
207

208
#if defined(LOG_GTPU) && LOG_GTPU > 0
209
  NW_ENTER(thiz);
210
#endif
Cedric Roux's avatar
Cedric Roux committed
211

212 213
  msgHdr = &pMsg->msgBuf[pMsg->msgBufOffset];
  NW_ASSERT(msgHdr != NULL);
Cedric Roux's avatar
Cedric Roux committed
214

215 216 217 218 219
  *(msgHdr++)         = (pMsg->version << 5)            |
                        (pMsg->protocolType << 4)       |
                        (pMsg->extHdrFlag << 2)         |
                        (pMsg->seqNumFlag << 1)         |
                        (pMsg->npduNumFlag);
Cedric Roux's avatar
Cedric Roux committed
220

221
  *(msgHdr++)         = (pMsg->msgType);
222
  *((uint16_t *) msgHdr) = htons(pMsg->msgLen);
223
  msgHdr += 2;
Cedric Roux's avatar
Cedric Roux committed
224

225
  *((uint32_t *) msgHdr) = htonl(pMsg->teid);
226
  msgHdr += 4;
227
#if defined(LOG_GTPU) && LOG_GTPU > 0
228 229 230 231
  GTPU_DEBUG("nwGtpv1uCreateAndSendMsg to teid %u length %d offset %d\n",
             pMsg->teid,
             pMsg->msgLen,
             pMsg->msgBufOffset);
232
#endif
Cedric Roux's avatar
Cedric Roux committed
233

234
  if(pMsg->seqNumFlag || pMsg->extHdrFlag || pMsg->npduNumFlag) {
235
    *((uint16_t *) msgHdr) = (pMsg->seqNumFlag ? htons(pMsg->seqNum) : 0x0000);
236
    msgHdr += 2;
Cedric Roux's avatar
Cedric Roux committed
237

238
    *((uint8_t *) msgHdr) = (pMsg->npduNumFlag ? htons(pMsg->npduNum) : 0x00);
239
    msgHdr++;
Cedric Roux's avatar
Cedric Roux committed
240

241
    *((uint8_t *) msgHdr) = (pMsg->extHdrFlag ? htons(pMsg->nextExtHdrType) : 0x00);
242 243
    msgHdr++;
  }
Cedric Roux's avatar
Cedric Roux committed
244

245 246 247 248 249 250
  rc = thiz->udp.udpDataReqCallback(thiz->udp.hUdp,
                                    pMsg->msgBuf,
                                    pMsg->msgBufLen,
                                    pMsg->msgBufOffset,
                                    peerIp,
                                    peerPort);
Cedric Roux's avatar
Cedric Roux committed
251

gauthier's avatar
gauthier committed
252
#if defined(LOG_GTPU) && LOG_GTPU > 0
253
  NW_LEAVE(thiz);
gauthier's avatar
gauthier committed
254
#endif
255
  return rc;
Cedric Roux's avatar
Cedric Roux committed
256 257 258 259 260 261 262 263 264 265 266
}

/**
 * Send GTPv1u Message Indication to ULP entity.
 *
 * @param[in] hGtpuStackHandle : Stack handle
 * @return NW_GTPV1U_OK on success.
 */

static NwGtpv1uRcT
nwGtpv1uSendUlpMessageIndication( NW_IN NwGtpv1uStackT *thiz,
267 268 269 270 271 272 273
                                  NW_IN uint32_t  hUlpTrxn,
                                  NW_IN uint32_t  apiType,
                                  NW_IN uint32_t  msgType,
                                  NW_IN uint32_t  peerIp,
                                  NW_IN uint16_t  peerPort,
                                  NW_IN uint8_t  *pMsgBuf,
                                  NW_IN uint16_t  msgLength)
Cedric Roux's avatar
Cedric Roux committed
274
{
275 276
  NwGtpv1uRcT rc = NW_GTPV1U_FAILURE;
  NwGtpv1uUlpApiT ulpApi;
Cedric Roux's avatar
Cedric Roux committed
277

278
#if defined(LOG_GTPU) && LOG_GTPU > 0
279
  NW_ENTER(thiz);
280
#endif
Cedric Roux's avatar
Cedric Roux committed
281

282 283 284 285 286
  ulpApi.apiType                        = apiType;
  ulpApi.apiInfo.recvMsgInfo.msgType    = msgType;
  ulpApi.apiInfo.recvMsgInfo.hUlpTrxn   = hUlpTrxn;
  ulpApi.apiInfo.recvMsgInfo.peerIp     = peerIp;
  ulpApi.apiInfo.recvMsgInfo.peerPort   = peerPort;
Cedric Roux's avatar
Cedric Roux committed
287

288 289 290
  if(pMsgBuf && msgLength) {
    rc = nwGtpv1uMsgFromBufferNew((NwGtpv1uStackHandleT)thiz, pMsgBuf, msgLength,
                                  &(ulpApi.apiInfo.recvMsgInfo.hMsg));
Cedric Roux's avatar
Cedric Roux committed
291
    NW_ASSERT(rc == NW_GTPV1U_OK);
292 293 294 295
  }

  rc = thiz->ulp.ulpReqCallback(thiz->ulp.hUlp, &ulpApi);
  NW_ASSERT(rc == NW_GTPV1U_OK);
Cedric Roux's avatar
Cedric Roux committed
296

297
#if defined(LOG_GTPU) && LOG_GTPU > 0
298
  NW_LEAVE(thiz);
299
#endif
Cedric Roux's avatar
Cedric Roux committed
300

301
  return rc;
Cedric Roux's avatar
Cedric Roux committed
302 303 304 305 306
}

NwGtpv1uRcT
nwGtpv1uPeerRspTimeout(void *arg)
{
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
  NwGtpv1uRcT rc = NW_GTPV1U_OK;
  NwGtpv1uTrxnT *thiz;
  NwGtpv1uTimeoutInfoT *timeoutInfo = arg;

  GTPU_WARNING( "Retransmission timer expired\n");

  thiz = ((NwGtpv1uTrxnT *)timeoutInfo->timeoutArg);
  rc = thiz->pStack->udp.udpDataReqCallback(thiz->pStack->udp.hUdp,
       thiz->pMsg->msgBuf,
       thiz->pMsg->msgLen,
       thiz->pMsg->msgBufOffset,
       thiz->peerIp,
       thiz->peerPort);

  if(thiz->maxRetries) {
    rc = thiz->pStack->tmrMgr.tmrStartCallback(thiz->pStack->tmrMgr.tmrMgrHandle,
         5, 0, NW_GTPV1U_TMR_TYPE_ONE_SHOT, (void *)timeoutInfo, &thiz->hRspTmr);
    thiz->maxRetries--;
  } else {
    /* Inform session layer about path fialure */
    GTPU_WARNING("Max retries over!\n");
  }

  return rc;
Cedric Roux's avatar
Cedric Roux committed
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
}

/*---------------------------------------------------------------------------
 * ULP API Processing Functions
 *--------------------------------------------------------------------------*/

/**
  Process NW_GTPV1U_ULP_API_CREATE_TUNNEL_ENDPOINT Request from ULP entity.

  @param[in] hGtpuStackHandle : Stack handle
  @param[in] pUlpReq : Pointer to Ulp Req.
  @return NW_GTPV1U_OK on success.
 */

static NwGtpv1uRcT
NwGtpv1uCreateTunnelEndPoint( NW_IN  NwGtpv1uStackT *thiz,
347
                              NW_IN  uint32_t teid,
Cedric Roux's avatar
Cedric Roux committed
348 349 350
                              NW_IN  NwGtpv1uUlpSessionHandleT hUlpSession,
                              NW_OUT NwGtpv1uStackSessionHandleT *phStackSession )
{
351 352 353
  NwGtpv1uRcT rc = NW_GTPV1U_OK;
  NwGtpv1uTunnelEndPointT *pTunnelEndPoint;
  NwGtpv1uTunnelEndPointT *pCollision;
Cedric Roux's avatar
Cedric Roux committed
354

355
#if defined(LOG_GTPU) && LOG_GTPU > 0
356
  NW_ENTER(thiz);
357
#endif
358 359 360 361 362 363 364 365 366 367
  pTunnelEndPoint = nwGtpTunnelEndPointNew(thiz);

  if(pTunnelEndPoint) {

    pTunnelEndPoint->teid           = teid;
    pTunnelEndPoint->pStack         = thiz;
    pTunnelEndPoint->hUlpSession    = hUlpSession;

    pCollision = RB_INSERT(NwGtpv1uTunnelEndPointIdentifierMap, &(thiz->teidMap),
                           pTunnelEndPoint);
Cedric Roux's avatar
Cedric Roux committed
368

369 370 371 372 373 374 375 376
    if(pCollision) {
      GTPU_ERROR("Tunnel end-point cannot be created for teid 0x%x. "
                 "Tunnel already exists", teid);
      rc = nwGtpTunnelEndPointDestroy(thiz, pTunnelEndPoint);
      NW_ASSERT(rc == NW_GTPV1U_OK);
      *phStackSession = (NwGtpv1uStackSessionHandleT) NULL;
      NW_ASSERT(0);
      rc = NW_GTPV1U_FAILURE;
Cedric Roux's avatar
Cedric Roux committed
377
    } else {
378 379 380 381
      *phStackSession = (NwGtpv1uStackSessionHandleT) pTunnelEndPoint;
      pTunnelEndPoint = RB_FIND(NwGtpv1uTunnelEndPointIdentifierMap,
                                &(thiz->teidMap), pTunnelEndPoint);
      NW_ASSERT(pTunnelEndPoint);
382 383
      GTPU_DEBUG("Tunnel end-point 0x%p creation successful for teid 0x%x %u(dec)",
                 pTunnelEndPoint, (unsigned int)teid, (unsigned int)teid);
Cedric Roux's avatar
Cedric Roux committed
384 385
    }

386
  } else {
387
    *phStackSession = (NwGtpv1uStackSessionHandleT) NULL;
388 389 390
    rc = NW_GTPV1U_FAILURE;
  }

391
#if defined(LOG_GTPU) && LOG_GTPU > 0
392
  NW_LEAVE(thiz);
393
#endif
394
  return rc;
Cedric Roux's avatar
Cedric Roux committed
395 396 397 398 399 400 401 402 403 404 405 406 407 408
}

/**
  Process NW_GTPV1U_ULP_API_DESTROY_TUNNEL_ENDPOINT Request from ULP entity.

  @param[in] hGtpuStackHandle : Stack handle
  @param[in] pUlpReq : Pointer to Ulp Req.
  @return NW_GTPV1U_OK on success.
 */

static NwGtpv1uRcT
nwGtpv1uDestroyTunnelEndPoint( NwGtpv1uStackT *thiz,
                               NW_IN NwGtpv1uUlpApiT *pUlpReq)
{
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
  NwGtpv1uRcT rc = NW_GTPV1U_OK;
  NwGtpv1uTunnelEndPointT *pRemovedTeid;

  if(pUlpReq->apiInfo.destroyTunnelEndPointInfo.hStackSessionHandle) {
    GTPU_DEBUG(  "Destroying Tunnel end-point '%x'",
                 pUlpReq->apiInfo.destroyTunnelEndPointInfo.hStackSessionHandle);
    pRemovedTeid = RB_REMOVE(NwGtpv1uTunnelEndPointIdentifierMap, &(thiz->teidMap),
                             (NwGtpv1uTunnelEndPointT *)(
                               pUlpReq->apiInfo.destroyTunnelEndPointInfo.hStackSessionHandle));

    NW_ASSERT(pRemovedTeid == (NwGtpv1uTunnelEndPointT *)(
                pUlpReq->apiInfo.destroyTunnelEndPointInfo.hStackSessionHandle));

    rc = nwGtpTunnelEndPointDestroy(thiz,
                                    (NwGtpv1uTunnelEndPointT *)
                                    pUlpReq->apiInfo.destroyTunnelEndPointInfo.hStackSessionHandle);
  } else {
    GTPU_WARNING("Non-existent Tunnel end-point handle '%x'",
                 pUlpReq->apiInfo.destroyTunnelEndPointInfo.hStackSessionHandle);
  }

  return rc;
Cedric Roux's avatar
Cedric Roux committed
431 432 433 434 435 436 437 438 439 440 441 442 443
}

/**
  Process NW_GTPV1U_ULP_API_INITIAL_REQ Request from ULP entity.

  @param[in] hGtpuStackHandle : Stack handle
  @param[in] pUlpReq : Pointer to Ulp Req.
  @return NW_GTPV1U_OK on success.
 */

static NwGtpv1uRcT
nwGtpv1uInitialReq( NW_IN NwGtpv1uStackT *thiz, NW_IN NwGtpv1uUlpApiT *pUlpReq)
{
444 445
  NwGtpv1uRcT rc = NW_GTPV1U_FAILURE;
  NwGtpv1uTrxnT *pTrxn;
Cedric Roux's avatar
Cedric Roux committed
446

447
#if defined(LOG_GTPU) && LOG_GTPU > 0
448
  NW_ENTER(thiz);
449
#endif
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
  /* Create New Transaction */
  rc = nwGtpv1uTrxnNew(thiz, &pTrxn);

  if(pTrxn) {
    rc = nwGtpv1uTrxnCreateAndSendMsg(thiz,
                                      pTrxn,
                                      pUlpReq->apiInfo.initialReqInfo.peerIp,
                                      pUlpReq->apiInfo.initialReqInfo.peerPort,
                                      (NwGtpv1uMsgT *) pUlpReq->hMsg);

    if(rc == NW_GTPV1U_OK) {
      /* Insert into search tree */
      RB_INSERT(NwGtpv1uOutstandingTxSeqNumTrxnMap, &(thiz->outstandingTxSeqNumMap),
                pTrxn);
    } else {
      rc = nwGtpv1uTrxnDelete(&pTrxn);
      NW_ASSERT(rc == NW_GTPV1U_OK);
Cedric Roux's avatar
Cedric Roux committed
467
    }
468
  }
Cedric Roux's avatar
Cedric Roux committed
469

470
#if defined(LOG_GTPU) && LOG_GTPU > 0
471
  NW_LEAVE(thiz);
472
#endif
473
  return rc;
Cedric Roux's avatar
Cedric Roux committed
474 475 476 477 478 479 480 481 482 483 484 485 486
}

/**
  Process NW_GTPV1U_ULP_API_SEND_TPDU Request from ULP entity.

  @param[in] thiz: Stack handle
  @param[in] pUlpReq : Pointer to Ulp Req.
  @return NW_GTPV1U_OK on success.
 */

static NwGtpv1uRcT
nwGtpv1uSendto( NwGtpv1uStackT *thiz,  NW_IN NwGtpv1uUlpApiT *pUlpReq)
{
487
  NwGtpv1uRcT rc = NW_GTPV1U_FAILURE;
Cedric Roux's avatar
Cedric Roux committed
488

489
  NW_ASSERT(thiz);
490
#if defined(LOG_GTPU) && LOG_GTPU > 0
491
  NW_ENTER(thiz);
492
#endif
Cedric Roux's avatar
Cedric Roux committed
493

494 495
  (void) nwGtpv1uMsgSetTeid(pUlpReq->apiInfo.sendtoInfo.hMsg,
                            pUlpReq->apiInfo.sendtoInfo.teid);
Cedric Roux's avatar
Cedric Roux committed
496

497 498 499 500
  rc = nwGtpv1uCreateAndSendMsg(thiz,
                                pUlpReq->apiInfo.sendtoInfo.ipAddr,
                                2152,
                                (NwGtpv1uMsgT *) (NwGtpv1uMsgT *) pUlpReq->apiInfo.sendtoInfo.hMsg);
Cedric Roux's avatar
Cedric Roux committed
501

502
#if defined(LOG_GTPU) && LOG_GTPU > 0
503
  NW_LEAVE(thiz);
504
#endif
505
  return rc;
Cedric Roux's avatar
Cedric Roux committed
506 507 508 509 510 511 512 513 514 515 516 517
}

/**
  Process GPDU from UDP entity.

  @param[in] thiz: Stack handle
  @param[in] pUlpReq : Pointer to Ulp Req.
  @return NW_GTPV1U_OK on success.
 */

static NwGtpv1uRcT
nwGtpv1uProcessGpdu( NwGtpv1uStackT *thiz,
518 519 520
                     NW_IN uint8_t *gpdu,
                     NW_IN uint32_t gpduLen,
                     NW_IN uint32_t peerIp)
Cedric Roux's avatar
Cedric Roux committed
521 522

{
523 524 525 526
  NwGtpv1uRcT              rc                = NW_GTPV1U_FAILURE;
  NwGtpv1uMsgHeaderT      *msgHdr            = NULL;
  NwGtpv1uTunnelEndPointT *pTunnelEndPoint   = NULL;
  NwGtpv1uTunnelEndPointT  tunnelEndPointKey;
527
  //    uint16_t                   hdr_len           = 0;
Cedric Roux's avatar
Cedric Roux committed
528

529
#if defined(LOG_GTPU) && LOG_GTPU > 0
530
  NW_ENTER(thiz);
531
#endif
Cedric Roux's avatar
Cedric Roux committed
532

533 534
  // no buffer offset
  msgHdr = (NwGtpv1uMsgHeaderT *) gpdu;
Cedric Roux's avatar
Cedric Roux committed
535

536
  tunnelEndPointKey.teid = ntohl(msgHdr->teid);
537

538 539
  pTunnelEndPoint = RB_FIND(NwGtpv1uTunnelEndPointIdentifierMap,
                            &(thiz->teidMap), &tunnelEndPointKey);
Cedric Roux's avatar
Cedric Roux committed
540

541 542
  if(pTunnelEndPoint) {
    NwGtpv1uMsgHandleT hMsg;
Cedric Roux's avatar
Cedric Roux committed
543

544
    rc = nwGtpv1uMsgFromBufferNew( (NwGtpv1uStackHandleT)thiz,
545
                                   (uint8_t *)gpdu,
546 547 548 549
                                   gpduLen,
                                   &hMsg);

    /*
550 551 552
      uint8_t*        msgBuf;
      uint32_t        msgBufLen;
      uint32_t        msgBufOffset;
553 554 555
     */
    if(NW_GTPV1U_OK == rc) {
      NwGtpv1uMsgT *pMsg = (NwGtpv1uMsgT *) hMsg;
556
#if defined(LOG_GTPU) && LOG_GTPU > 0
557 558
      GTPU_DEBUG("Received T-PDU over tunnel end-point '%x' of size %u (%u) (decapsulated %u)from "NW_IPV4_ADDR"\n",
                 ntohl(msgHdr->teid), gpduLen, pMsg->msgLen, pMsg->msgBufLen, NW_IPV4_ADDR_FORMAT((peerIp)));
559
#endif
560
      MSC_LOG_RX_MESSAGE(
gauthier's avatar
gauthier committed
561 562 563 564 565 566 567 568
        (thiz->stackType == GTPU_STACK_ENB) ? MSC_GTPU_ENB:MSC_GTPU_SGW,
        (thiz->stackType == GTPU_STACK_ENB) ? MSC_GTPU_SGW:MSC_GTPU_ENB,
        NULL,
        0,
        " G-PDU ltid %u size %u",
        tunnelEndPointKey.teid,
        gpduLen);

569
      rc = nwGtpSessionSendMsgApiToUlpEntity(pTunnelEndPoint, pMsg);
Cedric Roux's avatar
Cedric Roux committed
570
    }
571
  } else {
572 573 574 575 576 577 578 579
    MSC_LOG_RX_DISCARDED_MESSAGE(
      (thiz->stackType == GTPU_STACK_ENB) ? MSC_GTPU_ENB:MSC_GTPU_SGW,
      (thiz->stackType == GTPU_STACK_ENB) ? MSC_GTPU_SGW:MSC_GTPU_ENB,
      NULL,
      0,
      " G-PDU ltid %u size %u",
      tunnelEndPointKey.teid,
      gpduLen);
580
    GTPU_DEBUG("Received T-PDU over non-existent tunnel end-point '%x' from "NW_IPV4_ADDR"\n",
581 582 583
               ntohl(msgHdr->teid), NW_IPV4_ADDR_FORMAT((peerIp)));
  }

584
#if defined(LOG_GTPU) && LOG_GTPU > 0
585
  NW_LEAVE(thiz);
586
#endif
587
  return rc;
Cedric Roux's avatar
Cedric Roux committed
588 589 590 591 592 593 594 595 596 597 598
}

/**
  Handle Echo Request from Peer Entity.

  @param[in] thiz : Stack context
  @return NW_GTPV1U_OK on success.
 */

static NwGtpv1uRcT
nwGtpv1uHandleEchoReq(NW_IN NwGtpv1uStackT *thiz,
599 600 601 602
                      NW_IN uint8_t *msgBuf,
                      NW_IN uint32_t msgBufLen,
                      NW_IN uint16_t peerPort,
                      NW_IN uint32_t peerIp)
Cedric Roux's avatar
Cedric Roux committed
603
{
604
  NwGtpv1uRcT           rc     = NW_GTPV1U_FAILURE;
605
  uint16_t                seqNum = 0;
606 607 608
  NwGtpv1uMsgHandleT    hMsg   = 0;
  int                   bufLen = 0;

609
  seqNum = ntohs(*(uint16_t *) (msgBuf + (((*msgBuf) & 0x02) ? 8 : 4)));
610

gauthier's avatar
gauthier committed
611
  MSC_LOG_RX_MESSAGE(
612 613 614 615 616 617
    (thiz->stackType == GTPU_STACK_ENB) ? MSC_GTPU_ENB:MSC_GTPU_SGW,
    (thiz->stackType == GTPU_STACK_ENB) ? MSC_GTPU_SGW:MSC_GTPU_ENB,
    NULL,
    0,
    MSC_AS_TIME_FMT" ECHO-REQ seq %u size %u",
    0,0,seqNum, msgBufLen);
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632
  /* Send Echo Response */

  rc = nwGtpv1uMsgNew( (NwGtpv1uStackHandleT)thiz,
                       NW_TRUE,         /* SeqNum flag    */
                       NW_FALSE,
                       NW_FALSE,
                       NW_GTP_ECHO_RSP,  /* Msg Type             */
                       0x00000000U,      /* TEID                 */
                       seqNum,           /* Seq Number           */
                       0,
                       0,
                       (&hMsg));

  bufLen = sizeof(NwGtpv1uIeTv1T)+ ((NwGtpv1uMsgT*)hMsg)->msgLen;

633
//#warning CROUX DIRTY +16, TO BE FIXED!!!
634 635 636 637
  /* the +16 is there because by analyzing memory allocation with some external
   * tool, I saw that there were 6 bytes accessed after bufLen in nwGtpv1uCreateAndSendMsg
   * the value "16" has been chosen arbitrarily, just bigger than 6
   */
638 639 640
  ((NwGtpv1uMsgT*)hMsg)->msgBuf = itti_malloc(
                                    TASK_GTPV1_U,
                                    TASK_UDP,
641
                                    bufLen + 16 /* CROUX - dirty +16, to be fixed! */);
642 643 644 645 646 647 648 649 650
  ((NwGtpv1uMsgT*)hMsg)->msgBufLen    = bufLen;
  NW_ASSERT(NW_GTPV1U_OK == rc);

  /*
   * The Restart Counter value in the Recovery information element shall
   * not be used, i.e. it shall be set to zero by the sender and shall be
   * ignored by the receiver.
   */
  rc = nwGtpv1uMsgAddIeTV1(hMsg, NW_GTPV1U_IE_RECOVERY, 0x00);
Cedric Roux's avatar
Cedric Roux committed
651

652
#if defined(LOG_GTPU) && LOG_GTPU > 0
653 654 655 656
  GTPU_INFO("Sending NW_GTP_ECHO_RSP message to %x:%x with seq %u\n",
            peerIp,
            peerPort,
            seqNum);
657
#endif
gauthier's avatar
gauthier committed
658
  MSC_LOG_TX_MESSAGE(
659 660 661 662 663 664
    (thiz->stackType == GTPU_STACK_ENB) ? MSC_GTPU_ENB:MSC_GTPU_SGW,
    (thiz->stackType == GTPU_STACK_ENB) ? MSC_GTPU_SGW:MSC_GTPU_ENB,
    NULL,
    0,
    MSC_AS_TIME_FMT" ECHO-RSP seq %u",
    0,0,seqNum);
665 666 667 668 669
  rc = nwGtpv1uCreateAndSendMsg(
         thiz,
         peerIp,
         peerPort,
         (NwGtpv1uMsgT *) hMsg);
Cedric Roux's avatar
Cedric Roux committed
670

671 672
  rc = nwGtpv1uMsgDelete((NwGtpv1uStackHandleT)thiz, hMsg);
  NW_ASSERT(NW_GTPV1U_OK == rc);
Cedric Roux's avatar
Cedric Roux committed
673

674
  return rc;
Cedric Roux's avatar
Cedric Roux committed
675 676 677 678 679 680 681 682 683 684 685
}

/*--------------------------------------------------------------------------*
 *                     P U B L I C   F U N C T I O N S                      *
 *--------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------
 * Constructor
 *--------------------------------------------------------------------------*/

NwGtpv1uRcT
686
nwGtpv1uInitialize( NW_INOUT NwGtpv1uStackHandleT *hGtpuStackHandle, uint32_t stackType)
Cedric Roux's avatar
Cedric Roux committed
687
{
688 689 690 691 692 693 694
  NwGtpv1uRcT rc = NW_GTPV1U_FAILURE;
  NwGtpv1uStackT *thiz;

  thiz = (NwGtpv1uStackT *) malloc( sizeof(NwGtpv1uStackT));
  memset(thiz, 0, sizeof(NwGtpv1uStackT));

  if(thiz) {
695 696
    thiz->id    = (NwPtrT)thiz;
    thiz->stackType = stackType;
Cedric Roux's avatar
Cedric Roux committed
697
    thiz->seq   = (uint16_t) ((uintptr_t)thiz) ; // FIXME interesting casts... don't know what this is good for...
698 699 700 701 702 703 704
    RB_INIT(&(thiz->outstandingTxSeqNumMap));
    RB_INIT(&(thiz->outstandingRxSeqNumMap));
    RB_INIT(&(thiz->sessionMap));
    RB_INIT(&(thiz->teidMap));

    if (0 == 1) {
      nwGtpv1uDisplayBanner();
Cedric Roux's avatar
Cedric Roux committed
705 706
    }

707 708 709 710
    rc = NW_GTPV1U_OK;
  } else {
    rc = NW_GTPV1U_FAILURE;
  }
Cedric Roux's avatar
Cedric Roux committed
711

712 713 714

  *hGtpuStackHandle = (NwGtpv1uStackHandleT) thiz;
  return rc;
Cedric Roux's avatar
Cedric Roux committed
715 716 717 718 719 720 721 722 723 724
}


/*---------------------------------------------------------------------------
 * Destructor
 *--------------------------------------------------------------------------*/

NwGtpv1uRcT
nwGtpv1uFinalize( NW_IN  NwGtpv1uStackHandleT hGtpuStackHandle)
{
725 726 727 728 729 730 731 732 733 734
  NwGtpv1uRcT rc = NW_GTPV1U_FAILURE;

  if(hGtpuStackHandle) {
    free((void *)hGtpuStackHandle);
    rc = NW_GTPV1U_OK;
  } else {
    rc = NW_GTPV1U_FAILURE;
  }

  return rc;
Cedric Roux's avatar
Cedric Roux committed
735 736 737 738 739 740 741 742 743 744 745
}


/*---------------------------------------------------------------------------
 * Configuration Get/Set
 *--------------------------------------------------------------------------*/

NwGtpv1uRcT
nwGtpv1uSetUlpEntity( NW_IN NwGtpv1uStackHandleT hGtpuStackHandle,
                      NW_IN NwGtpv1uUlpEntityT *pUlpEntity)
{
746 747
  NwGtpv1uRcT rc = NW_GTPV1U_FAILURE;
  NwGtpv1uStackT *thiz = (NwGtpv1uStackT *) hGtpuStackHandle;
Cedric Roux's avatar
Cedric Roux committed
748

749 750 751 752 753 754
  if(pUlpEntity) {
    thiz->ulp = *(pUlpEntity);
    rc = NW_GTPV1U_OK;
  } else {
    rc = NW_GTPV1U_FAILURE;
  }
Cedric Roux's avatar
Cedric Roux committed
755

756
  return rc;
Cedric Roux's avatar
Cedric Roux committed
757 758 759 760 761 762 763
}


NwGtpv1uRcT
nwGtpv1uSetUdpEntity( NW_IN NwGtpv1uStackHandleT hGtpuStackHandle,
                      NW_IN NwGtpv1uUdpEntityT *pUdpEntity)
{
764 765
  NwGtpv1uRcT rc = NW_GTPV1U_FAILURE;
  NwGtpv1uStackT *thiz = (NwGtpv1uStackT *) hGtpuStackHandle;
Cedric Roux's avatar
Cedric Roux committed
766

767 768 769 770 771 772
  if(pUdpEntity) {
    thiz->udp = *(pUdpEntity);
    rc = NW_GTPV1U_OK;
  } else {
    rc = NW_GTPV1U_FAILURE;
  }
Cedric Roux's avatar
Cedric Roux committed
773

774
  return rc;
Cedric Roux's avatar
Cedric Roux committed
775 776 777 778 779 780
}

NwGtpv1uRcT
nwGtpv1uSetMemMgrEntity( NW_IN NwGtpv1uStackHandleT hGtpuStackHandle,
                         NW_IN NwGtpv1uMemMgrEntityT *pMemMgrEntity)
{
781 782
  NwGtpv1uRcT rc = NW_GTPV1U_FAILURE;
  NwGtpv1uStackT *thiz = (NwGtpv1uStackT *) hGtpuStackHandle;
Cedric Roux's avatar
Cedric Roux committed
783

784 785 786 787 788 789
  if(pMemMgrEntity) {
    thiz->memMgr = *(pMemMgrEntity);
    rc = NW_GTPV1U_OK;
  } else {
    rc = NW_GTPV1U_FAILURE;
  }
Cedric Roux's avatar
Cedric Roux committed
790

791
  return rc;
Cedric Roux's avatar
Cedric Roux committed
792 793 794 795 796 797 798
}


NwGtpv1uRcT
nwGtpv1uSetTimerMgrEntity( NW_IN NwGtpv1uStackHandleT hGtpuStackHandle,
                           NW_IN NwGtpv1uTimerMgrEntityT *pTmrMgrEntity)
{
799 800
  NwGtpv1uRcT rc = NW_GTPV1U_FAILURE;
  NwGtpv1uStackT *thiz = (NwGtpv1uStackT *) hGtpuStackHandle;
Cedric Roux's avatar
Cedric Roux committed
801

802 803 804 805 806 807
  if(pTmrMgrEntity) {
    thiz->tmrMgr = *(pTmrMgrEntity);
    rc = NW_GTPV1U_OK;
  } else {
    rc = NW_GTPV1U_FAILURE;
  }
Cedric Roux's avatar
Cedric Roux committed
808

809
  return rc;
Cedric Roux's avatar
Cedric Roux committed
810 811 812 813 814 815 816
}


NwGtpv1uRcT
nwGtpv1uSetLogMgrEntity( NW_IN NwGtpv1uStackHandleT hGtpuStackHandle,
                         NW_IN NwGtpv1uLogMgrEntityT *pLogMgrEntity)
{
817 818
  NwGtpv1uRcT rc = NW_GTPV1U_FAILURE;
  NwGtpv1uStackT *thiz = (NwGtpv1uStackT *) hGtpuStackHandle;
Cedric Roux's avatar
Cedric Roux committed
819

820 821 822 823 824 825 826 827
  if(pLogMgrEntity) {
    thiz->logMgr = *(pLogMgrEntity);
    rc = NW_GTPV1U_OK;
  } else {
    rc = NW_GTPV1U_FAILURE;
  }

  return rc;
Cedric Roux's avatar
Cedric Roux committed
828 829 830 831
}

NwGtpv1uRcT
nwGtpv1uSetLogLevel( NW_IN NwGtpv1uStackHandleT hGtpuStackHandle,
832
                     NW_IN uint32_t logLevel)
Cedric Roux's avatar
Cedric Roux committed
833
{
834 835 836
  NwGtpv1uStackT *thiz = (NwGtpv1uStackT *) hGtpuStackHandle;
  thiz->logLevel = logLevel;
  return NW_GTPV1U_OK;
Cedric Roux's avatar
Cedric Roux committed
837 838 839 840 841 842 843 844
}

/*---------------------------------------------------------------------------
 * Process Request from Udp Layer
 *--------------------------------------------------------------------------*/

NwGtpv1uRcT
nwGtpv1uProcessUdpReq( NW_IN NwGtpv1uStackHandleT hGtpuStackHandle,
845 846 847 848
                       NW_IN uint8_t *udpData,
                       NW_IN uint32_t udpDataLen,
                       NW_IN uint16_t peerPort,
                       NW_IN uint32_t peerIp)
Cedric Roux's avatar
Cedric Roux committed
849
{
850 851
  NwGtpv1uRcT           ret = NW_GTPV1U_FAILURE;
  NwGtpv1uStackT       *thiz;
852
  uint16_t                msgType;
Cedric Roux's avatar
Cedric Roux committed
853

gauthier's avatar
gauthier committed
854
#if defined(ENB_MODE)
gauthier's avatar
gauthier committed
855
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_GTPV1U_PROCESS_UDP_REQ, VCD_FUNCTION_IN);
gauthier's avatar
gauthier committed
856
#endif
857 858 859 860
  thiz = (NwGtpv1uStackT *) hGtpuStackHandle;

  NW_ASSERT(thiz);

861
  msgType = *((uint8_t *)(udpData + 1));
862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888

  switch(msgType) {
  case NW_GTP_ECHO_REQ:
    GTPU_DEBUG("NW_GTP_ECHO_REQ\n");
    ret = nwGtpv1uHandleEchoReq( thiz, udpData, udpDataLen, peerPort, peerIp);
    break;

  case NW_GTP_ERROR_INDICATION:
    GTPU_DEBUG("NW_GTP_ERROR_INDICATION\n");
    ret = nwGtpv1uSendUlpMessageIndication( thiz,
                                            0,
                                            NW_GTPV1U_ULP_API_RECV_MSG,
                                            msgType,
                                            peerIp,
                                            peerPort,
                                            udpData,
                                            udpDataLen);

    NW_ASSERT(ret == NW_GTPV1U_OK);
    break;

  case NW_GTP_ECHO_RSP:
    GTPU_DEBUG("NW_GTP_ECHO_RSP\n");
    ret = NW_GTPV1U_OK;
    break;

  case NW_GTP_GPDU:
889
#if defined(LOG_GTPU) && LOG_GTPU > 0
890
    GTPU_DEBUG("NW_GTP_GPDU: DATA COMING FROM UDP\n");
891
#endif
892 893
    ret = nwGtpv1uProcessGpdu(thiz, udpData, udpDataLen, peerIp);
    break;
Cedric Roux's avatar
Cedric Roux committed
894

895 896 897 898 899
  default:
    ret = NW_GTPV1U_FAILURE;
    NW_ASSERT(0);
    break;
  }
Cedric Roux's avatar
Cedric Roux committed
900

901
#if defined(LOG_GTPU) && LOG_GTPU > 0
902
  NW_LEAVE(thiz);
903
#endif
gauthier's avatar
gauthier committed
904
#if defined(ENB_MODE)
gauthier's avatar
gauthier committed
905
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_GTPV1U_PROCESS_UDP_REQ, VCD_FUNCTION_OUT);
gauthier's avatar
gauthier committed
906
#endif
907
  return ret;
Cedric Roux's avatar
Cedric Roux committed
908 909 910 911 912 913 914 915 916 917 918
}


/*---------------------------------------------------------------------------
 * Process Request from Upper Layer
 *--------------------------------------------------------------------------*/

NwGtpv1uRcT
nwGtpv1uProcessUlpReq( NW_IN NwGtpv1uStackHandleT hGtpuStackHandle,
                       NW_IN NwGtpv1uUlpApiT *pUlpReq)
{
919 920
  NwGtpv1uRcT rc = NW_GTPV1U_FAILURE;
  NwGtpv1uStackT *thiz = (NwGtpv1uStackT *) hGtpuStackHandle;
Cedric Roux's avatar
Cedric Roux committed
921

922 923
  NW_ASSERT(thiz);
  NW_ASSERT(pUlpReq != NULL);
Cedric Roux's avatar
Cedric Roux committed
924

925
#if defined(LOG_GTPU) && LOG_GTPU > 0
926
  NW_ENTER(thiz);
927
#endif
Cedric Roux's avatar
Cedric Roux committed
928

929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951
  switch(pUlpReq->apiType) {
  case NW_GTPV1U_ULP_API_CREATE_TUNNEL_ENDPOINT: {
    GTPU_DEBUG("Received NW_GTPV1U_ULP_API_CREATE_TUNNEL_ENDPOINT from ulp\n");
    rc = NwGtpv1uCreateTunnelEndPoint(thiz,
                                      pUlpReq->apiInfo.createTunnelEndPointInfo.teid,
                                      pUlpReq->apiInfo.createTunnelEndPointInfo.hUlpSession,
                                      &(pUlpReq->apiInfo.createTunnelEndPointInfo.hStackSession));
  }
  break;

  case NW_GTPV1U_ULP_API_DESTROY_TUNNEL_ENDPOINT: {
    GTPU_DEBUG("Received destroy session req from ulp\n");
    rc = nwGtpv1uDestroyTunnelEndPoint(thiz,  pUlpReq);
  }
  break;

  case NW_GTPV1U_ULP_API_INITIAL_REQ: {
    GTPU_DEBUG("Received initial req from ulp\n");
    rc = nwGtpv1uInitialReq(thiz, pUlpReq);
  }
  break;

  case NW_GTPV1U_ULP_API_SEND_TPDU: {
952
#if defined(LOG_GTPU) && LOG_GTPU > 0
953
    GTPU_DEBUG("Received send tpdu req from ulp\n");
954
#endif
955 956 957 958 959 960 961 962 963
    rc = nwGtpv1uSendto(thiz,  pUlpReq);
  }
  break;

  default:
    GTPU_DEBUG("Unsupported API received from ulp\n");
    rc = NW_GTPV1U_FAILURE;
    break;
  }
Cedric Roux's avatar
Cedric Roux committed
964

965
#if defined(LOG_GTPU) && LOG_GTPU > 0
966
  NW_LEAVE(thiz);
967
#endif
968
  return rc;
Cedric Roux's avatar
Cedric Roux committed
969 970 971 972 973 974 975 976 977
}

/*---------------------------------------------------------------------------
 * Process Timer timeout Request from Timer Manager
 *--------------------------------------------------------------------------*/

NwGtpv1uRcT
nwGtpv1uProcessTimeout(void *timeoutInfo)
{
978 979
  NwGtpv1uRcT rc = NW_GTPV1U_FAILURE;
  NwGtpv1uStackT *thiz;
Cedric Roux's avatar
Cedric Roux committed
980

981
  NW_ASSERT(timeoutInfo != NULL);
Cedric Roux's avatar
Cedric Roux committed
982

983
  thiz = (NwGtpv1uStackT *) (((NwGtpv1uTimeoutInfoT *) timeoutInfo)->hStack);
Cedric Roux's avatar
Cedric Roux committed
984

985
  NW_ASSERT(thiz != NULL);
Cedric Roux's avatar
Cedric Roux committed
986

987
#if defined(LOG_GTPU) && LOG_GTPU > 0
988
  NW_ENTER(thiz);
989
#endif
990 991
  GTPU_DEBUG("Received timeout event from ULP with timeoutInfo 0x%p!\n",
             timeoutInfo);
Cedric Roux's avatar
Cedric Roux committed
992

993
  rc = (((NwGtpv1uTimeoutInfoT *) timeoutInfo)->timeoutCallbackFunc) (timeoutInfo);
Cedric Roux's avatar
Cedric Roux committed
994

995
#if defined(LOG_GTPU) && LOG_GTPU > 0
996
  NW_LEAVE(thiz);
997
#endif
998
  return rc;
Cedric Roux's avatar
Cedric Roux committed
999 1000 1001 1002 1003 1004 1005 1006 1007 1008
}

#ifdef __cplusplus
}
#endif

/*--------------------------------------------------------------------------*
 *                      E N D     O F    F I L E                            *
 *--------------------------------------------------------------------------*/