x2ap_eNB_decoder.c 5.25 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * 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
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      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
 */

22 23 24 25 26 27 28
/*! \file x2ap_eNB_decoder.c
 * \brief x2ap decoder procedures for eNB
 * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr>
 * \date 2018
 * \version 1.0
 */

29 30 31 32 33 34 35 36 37 38 39 40 41 42
#include <stdio.h>

#include "assertions.h"
#include "intertask_interface.h"
#include "x2ap_common.h"
#include "x2ap_eNB_decoder.h"

static int x2ap_eNB_decode_initiating_message(X2AP_X2AP_PDU_t *pdu)
{
  DevAssert(pdu != NULL);

  switch(pdu->choice.initiatingMessage.procedureCode) {

    case X2AP_ProcedureCode_id_x2Setup:
43 44 45 46 47 48
      //asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_X2AP_X2AP_PDU, pdu);
      X2AP_INFO("x2ap_eNB_decode_initiating_message!\n");
      break;

    case X2AP_ProcedureCode_id_handoverPreparation:
      //asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_X2AP_X2AP_PDU, pdu);
49 50
      X2AP_INFO("x2ap_eNB_decode_initiating_message!\n");
      break;
Cedric Roux's avatar
Cedric Roux committed
51

52 53 54 55
    case X2AP_ProcedureCode_id_uEContextRelease:
      //asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_X2AP_X2AP_PDU, pdu);
      X2AP_INFO("x2ap_eNB_decode_initiating_message!\n");
      break;
56

Cedric Roux's avatar
Cedric Roux committed
57 58 59 60 61
    case X2AP_ProcedureCode_id_handoverCancel:
      //asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_X2AP_X2AP_PDU, pdu);
      X2AP_INFO("x2ap_eNB_decode_initiating_message!\n");
      break;

62
    case X2AP_ProcedureCode_id_endcX2Setup:
63 64
      X2AP_INFO("X2AP_ProcedureCode_id_endcX2Setup message!\n");
      break;
65

66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
    default:
      X2AP_ERROR("Unknown procedure ID (%d) for initiating message\n",
                  (int)pdu->choice.initiatingMessage.procedureCode);
      AssertFatal( 0, "Unknown procedure ID (%d) for initiating message\n",
                   (int)pdu->choice.initiatingMessage.procedureCode);
      return -1;
  }

  return 0;
}

static int x2ap_eNB_decode_successful_outcome(X2AP_X2AP_PDU_t *pdu)
{
  DevAssert(pdu != NULL);

  switch(pdu->choice.successfulOutcome.procedureCode) {
    case X2AP_ProcedureCode_id_x2Setup:
83 84 85 86 87 88
      //asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_X2AP_X2AP_PDU, pdu);
      X2AP_INFO("x2ap_eNB_decode_successfuloutcome_message!\n");
      break;

    case X2AP_ProcedureCode_id_handoverPreparation:
      //asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_X2AP_X2AP_PDU, pdu);
89 90 91
      X2AP_INFO("x2ap_eNB_decode_successfuloutcome_message!\n");
      break;

92 93 94 95
    case X2AP_ProcedureCode_id_endcX2Setup:
    	X2AP_INFO("x2ap_eNB_decode_successfuloutcome_message!\n");
    	break;

96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
    default:
      X2AP_ERROR("Unknown procedure ID (%d) for successfull outcome message\n",
                  (int)pdu->choice.successfulOutcome.procedureCode);
      return -1;
  }

  return 0;
}

static int x2ap_eNB_decode_unsuccessful_outcome(X2AP_X2AP_PDU_t *pdu)
{
  DevAssert(pdu != NULL);

  switch(pdu->choice.unsuccessfulOutcome.procedureCode) {
    case X2AP_ProcedureCode_id_x2Setup:
111
      //asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_X2AP_X2AP_PDU, pdu);
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
      X2AP_INFO("x2ap_eNB_decode_unsuccessfuloutcome_message!\n");
      break;

    default:
       X2AP_ERROR("Unknown procedure ID (%d) for unsuccessfull outcome message\n",
                  (int)pdu->choice.unsuccessfulOutcome.procedureCode);
      return -1;
  }

  return 0;
}

int x2ap_eNB_decode_pdu(X2AP_X2AP_PDU_t *pdu, const uint8_t *const buffer, uint32_t length)
{
  asn_dec_rval_t dec_ret;

  DevAssert(buffer != NULL);

  dec_ret = aper_decode(NULL,
                        &asn_DEF_X2AP_X2AP_PDU,
                        (void **)&pdu,
                        buffer,
                        length,
                        0,
                        0);
137
  //if (asn1_xer_print) {
138
    xer_fprint(stdout, &asn_DEF_X2AP_X2AP_PDU, pdu);
139
  //}
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163

  if (dec_ret.code != RC_OK) {
    X2AP_ERROR("Failed to decode pdu\n");
    return -1;
  }

  switch(pdu->present) {
    case X2AP_X2AP_PDU_PR_initiatingMessage:
      return x2ap_eNB_decode_initiating_message(pdu);

    case X2AP_X2AP_PDU_PR_successfulOutcome:
      return x2ap_eNB_decode_successful_outcome(pdu);

    case X2AP_X2AP_PDU_PR_unsuccessfulOutcome:
      return x2ap_eNB_decode_unsuccessful_outcome(pdu);

    default:
      X2AP_DEBUG("Unknown presence (%d) or not implemented\n", (int)pdu->present);
      break;
  }


  return -1;
}