f1ap_decoder.c 6.38 KB
Newer Older
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
/*
 * 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
 */

/*! \file f1ap_decoder.c
 * \brief f1ap pdu decode procedures
 * \author EURECOM/NTUST
 * \date 2018
 * \version 0.1
 * \company Eurecom
 * \email: navid.nikaein@eurecom.fr, bing-kai.hong@eurecom.fr
 * \note
 * \warning
 */

#include "f1ap_common.h"
#include "f1ap_decoder.h"

36
int asn1_decoder_xer_print = 0;
37

38
static int f1ap_decode_initiating_message(F1AP_F1AP_PDU_t *pdu)
39
{
40 41 42
  //MessageDef *message_p;
  //MessagesIds message_id;
  //asn_encode_to_new_buffer_result_t res = { NULL, {0, NULL, NULL} };
Bing-Kai Hong's avatar
Bing-Kai Hong committed
43 44 45
  DevAssert(pdu != NULL);

  switch(pdu->choice.initiatingMessage->procedureCode) {
46
    
47
    case F1AP_ProcedureCode_id_F1Setup:
48
      //res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_F1AP_F1AP_PDU, pdu);
49
      LOG_I(F1AP, "%s(): F1AP_ProcedureCode_id_F1Setup\n", __func__);
50 51 52
      break;

    case F1AP_ProcedureCode_id_InitialULRRCMessageTransfer:
53
      //res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_F1AP_F1AP_PDU, pdu);
54
      LOG_I(F1AP, "%s(): F1AP_ProcedureCode_id_InitialULRRCMessageTransfer\n", __func__);
55 56 57
      break;

    case F1AP_ProcedureCode_id_DLRRCMessageTransfer:
58
      //res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_F1AP_F1AP_PDU, pdu);
59
      LOG_I(F1AP, "%s(): F1AP_ProcedureCode_id_DLRRCMessageTransfer\n", __func__);
60 61 62
      break;

    case F1AP_ProcedureCode_id_ULRRCMessageTransfer:
63
      //res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_F1AP_F1AP_PDU, pdu);
64
      LOG_I(F1AP, "%s(): F1AP_ProcedureCode_id_ULRRCMessageTransfer\n", __func__);
65
      break;
66 67 68
    case F1AP_ProcedureCode_id_UEContextRelease:
      LOG_I(F1AP, "%s(): F1AP_ProcedureCode_id_UEContextRelease\n", __func__);
      break;
69 70 71
    case F1AP_ProcedureCode_id_UEContextReleaseRequest:
      LOG_I(F1AP, "%s(): F1AP_ProcedureCode_id_UEContextReleaseRequest\n", __func__);
      break;
Bing-Kai Hong's avatar
Bing-Kai Hong committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85
    // case F1AP_ProcedureCode_id_InitialContextSetup:
    //   res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_F1AP_F1AP_PDU, pdu);
    //   message_id = F1AP_INITIAL_CONTEXT_SETUP_LOG;
    //   message_p = itti_alloc_new_message_sized(TASK_F1AP, message_id,
    //               res.result.encoded + sizeof (IttiMsgText));
    //   message_p->ittiMsg.f1ap_initial_context_setup_log.size = res.result.encoded;
    //   memcpy(&message_p->ittiMsg.f1ap_initial_context_setup_log.text, res.buffer, res.result.encoded);
    //   itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
    //   free(res.buffer);
    //   break;

    default:
      // F1AP_ERROR("Unknown procedure ID (%d) for initiating message\n",
      //            (int)pdu->choice.initiatingMessage->procedureCode);
86
      LOG_E(F1AP, "Unknown procedure ID (%d) for initiating message\n",
Bing-Kai Hong's avatar
Bing-Kai Hong committed
87 88 89 90
                  (int)pdu->choice.initiatingMessage->procedureCode);
      AssertFatal( 0, "Unknown procedure ID (%d) for initiating message\n",
                   (int)pdu->choice.initiatingMessage->procedureCode);
      return -1;
91 92
  }

Bing-Kai Hong's avatar
Bing-Kai Hong committed
93
  return 0;
94 95
}

96
static int f1ap_decode_successful_outcome(F1AP_F1AP_PDU_t *pdu)
97
{
Bing-Kai Hong's avatar
Bing-Kai Hong committed
98 99 100
  DevAssert(pdu != NULL);

  switch(pdu->choice.successfulOutcome->procedureCode) {
101
    case F1AP_ProcedureCode_id_F1Setup:
102 103 104 105 106
      LOG_I(F1AP, "%s(): F1AP_ProcedureCode_id_F1Setup\n", __func__);
      break;

    case F1AP_ProcedureCode_id_UEContextRelease:
      LOG_I(F1AP, "%s(): F1AP_ProcedureCode_id_UEContextRelease\n", __func__);
107
      break;
Bing-Kai Hong's avatar
Bing-Kai Hong committed
108 109

    default:
110
      LOG_E(F1AP,"Unknown procedure ID (%d) for successfull outcome message\n",
Bing-Kai Hong's avatar
Bing-Kai Hong committed
111 112
                 (int)pdu->choice.successfulOutcome->procedureCode);
      return -1;
113 114
  }

Bing-Kai Hong's avatar
Bing-Kai Hong committed
115
  return 0;
116 117
}

118
static int f1ap_decode_unsuccessful_outcome(F1AP_F1AP_PDU_t *pdu)
119
{
Bing-Kai Hong's avatar
Bing-Kai Hong committed
120 121 122
  DevAssert(pdu != NULL);

  switch(pdu->choice.unsuccessfulOutcome->procedureCode) {
123
    case F1AP_ProcedureCode_id_F1Setup:
124
    LOG_I(F1AP, "%s(): F1AP_ProcedureCode_id_F1Setup\n", __func__);
125
    break;
Bing-Kai Hong's avatar
Bing-Kai Hong committed
126 127 128 129

    default:
      // F1AP_ERROR("Unknown procedure ID (%d) for unsuccessfull outcome message\n",
      //            (int)pdu->choice.unsuccessfulOutcome->procedureCode);
130
      LOG_E(F1AP, "Unknown procedure ID (%d) for unsuccessfull outcome message\n",
Bing-Kai Hong's avatar
Bing-Kai Hong committed
131 132
                 (int)pdu->choice.unsuccessfulOutcome->procedureCode);
      return -1;
133 134
  }

Bing-Kai Hong's avatar
Bing-Kai Hong committed
135
  return 0;
136 137
}

138
int f1ap_decode_pdu(F1AP_F1AP_PDU_t *pdu, const uint8_t *const buffer, uint32_t length)
139 140 141 142 143 144
{
  asn_dec_rval_t dec_ret;

  DevAssert(buffer != NULL);

  dec_ret = aper_decode(NULL,
Bing-Kai Hong's avatar
Bing-Kai Hong committed
145 146
                        &asn_DEF_F1AP_F1AP_PDU,
                        (void **)&pdu,
147 148 149 150
                        buffer,
                        length,
                        0,
                        0);
151 152 153 154 155 156

  if (asn1_decoder_xer_print) {
    LOG_E(F1AP, "----------------- ASN1 DECODER PRINT START----------------- \n");
    xer_fprint(stdout, &asn_DEF_F1AP_F1AP_PDU, pdu);
    LOG_E(F1AP, "----------------- ASN1 DECODER PRINT END ----------------- \n");
  }
157
  //LOG_I(F1AP, "f1ap_decode_pdu.dec_ret.code = %d\n", dec_ret.code);
Bing-Kai Hong's avatar
Bing-Kai Hong committed
158

159
  if (dec_ret.code != RC_OK) {
160
    LOG_E(F1AP, "Failed to decode pdu\n");
161 162 163
    return -1;
  }

Bing-Kai Hong's avatar
Bing-Kai Hong committed
164 165
  switch(pdu->present) {
    case F1AP_F1AP_PDU_PR_initiatingMessage:
166
      return f1ap_decode_initiating_message(pdu);
167

Bing-Kai Hong's avatar
Bing-Kai Hong committed
168
    case F1AP_F1AP_PDU_PR_successfulOutcome:
169
      return f1ap_decode_successful_outcome(pdu);
170

Bing-Kai Hong's avatar
Bing-Kai Hong committed
171
    case F1AP_F1AP_PDU_PR_unsuccessfulOutcome:
172
      return f1ap_decode_unsuccessful_outcome(pdu);
173

Bing-Kai Hong's avatar
Bing-Kai Hong committed
174
    default:
175
      LOG_E(F1AP, "Unknown presence (%d) or not implemented\n", (int)pdu->present);
Bing-Kai Hong's avatar
Bing-Kai Hong committed
176
      break;
177 178
  }

Bing-Kai Hong's avatar
Bing-Kai Hong committed
179

180 181
  return -1;
}