UPTransportLayerInformation.cpp 3.8 KB
Newer Older
1 2 3 4 5
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this
7 8
 * file except in compliance with the License. You may obtain a copy of the
 * License at
9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

dukl's avatar
dukl committed
22 23
#include "UPTransportLayerInformation.hpp"

24 25
extern "C" {
#include "Ngap_GTPTunnel.h"
26
#include "dynamic_memory_check.h"
dukl's avatar
dukl committed
27 28 29 30 31
}

#include <iostream>
using namespace std;

32 33 34 35 36
namespace ngap {

//------------------------------------------------------------------------------
UpTransportLayerInformation::UpTransportLayerInformation() {
  transportLayerAddress = NULL;
37
  gtpTeid               = NULL;
38 39 40
}

//------------------------------------------------------------------------------
41
UpTransportLayerInformation::~UpTransportLayerInformation() {}
42 43

//------------------------------------------------------------------------------
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
44
void UpTransportLayerInformation::setUpTransportLayerInformation(
45
    TransportLayerAddress* m_transportLayerAddress, GtpTeid* m_gtpTeid) {
46
  transportLayerAddress = m_transportLayerAddress;
47
  gtpTeid               = m_gtpTeid;
48 49 50
}

//------------------------------------------------------------------------------
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
51
bool UpTransportLayerInformation::getUpTransportLayerInformation(
52
    TransportLayerAddress*& m_transportLayerAddress, GtpTeid*& m_gtpTeid) {
53
  m_transportLayerAddress = transportLayerAddress;
54
  m_gtpTeid               = gtpTeid;
55 56 57 58 59

  return true;
}

//------------------------------------------------------------------------------
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
60
bool UpTransportLayerInformation::encode2UpTransportLayerInformation(
61
    Ngap_UPTransportLayerInformation_t& upTransportLayerInfo) {
62
  upTransportLayerInfo.present = Ngap_UPTransportLayerInformation_PR_gTPTunnel;
63 64 65
  Ngap_GTPTunnel_t* gtptunnel =
      (Ngap_GTPTunnel_t*) calloc(1, sizeof(Ngap_GTPTunnel_t));
  if (!gtptunnel) return false;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
66
  if (!transportLayerAddress->encode2TransportLayerAddress(
67 68
          gtptunnel->transportLayerAddress)) {
    free_wrapper((void**) &gtptunnel);
69
    return false;
70 71
  }

72 73 74 75
  if (!gtpTeid->encode2GtpTeid(gtptunnel->gTP_TEID)) {
    free_wrapper((void**) &gtptunnel);
    return false;
  }
76 77 78 79 80
  upTransportLayerInfo.choice.gTPTunnel = gtptunnel;
  return true;
}

//------------------------------------------------------------------------------
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
81
bool UpTransportLayerInformation::decodefromUpTransportLayerInformation(
82 83 84
    Ngap_UPTransportLayerInformation_t& upTransportLayerInfo) {
  if (upTransportLayerInfo.present !=
      Ngap_UPTransportLayerInformation_PR_gTPTunnel)
85
    return false;
86
  if (!upTransportLayerInfo.choice.gTPTunnel) return false;
87
  transportLayerAddress = new TransportLayerAddress();
88
  gtpTeid               = new GtpTeid();
89

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
90
  if (!transportLayerAddress->decodefromTransportLayerAddress(
91
          upTransportLayerInfo.choice.gTPTunnel->transportLayerAddress))
92
    return false;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
93
  if (!gtpTeid->decodefromGtpTeid(
94
          upTransportLayerInfo.choice.gTPTunnel->gTP_TEID))
95 96 97 98
    return false;

  return true;
}
dukl's avatar
dukl committed
99

100
}  // namespace ngap