s1ap_eNB_decoder.c 9.28 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 file
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * 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
 */

Cedric Roux's avatar
 
Cedric Roux committed
22 23
/*! \file s1ap_eNB_decoder.c
 * \brief s1ap pdu decode procedures for eNB
24 25 26
 * \author Sebastien ROUX and Navid Nikaein
 * \email navid.nikaein@eurecom.fr
 * \date 2013 - 2015
Cedric Roux's avatar
 
Cedric Roux committed
27 28 29 30 31 32 33
 * \version 0.1
 */

#include <stdio.h>

#include "assertions.h"

Cedric Roux's avatar
Cedric Roux committed
34 35
#include "intertask_interface.h"

Cedric Roux's avatar
 
Cedric Roux committed
36 37 38
#include "s1ap_common.h"
#include "s1ap_eNB_decoder.h"

39 40

static int s1ap_eNB_decode_initiating_message(S1AP_S1AP_PDU_t *pdu)
Cedric Roux's avatar
 
Cedric Roux committed
41
{
42 43
  MessageDef *message_p;
  MessagesIds message_id;
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 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 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
  asn_encode_to_new_buffer_result_t res = { NULL, {0, NULL, NULL} };
  DevAssert(pdu != NULL);

  switch(pdu->choice.initiatingMessage.procedureCode) {
    case S1AP_ProcedureCode_id_downlinkNASTransport:
      res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
      message_id = S1AP_DOWNLINK_NAS_LOG;
      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id,
                  res.result.encoded + sizeof (IttiMsgText));
      message_p->ittiMsg.s1ap_downlink_nas_log.size = res.result.encoded;
      memcpy(&message_p->ittiMsg.s1ap_downlink_nas_log.text, res.buffer, res.result.encoded);
      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
      free(res.buffer);
      break;

    case S1AP_ProcedureCode_id_InitialContextSetup:
      res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
      message_id = S1AP_INITIAL_CONTEXT_SETUP_LOG;
      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id,
                  res.result.encoded + sizeof (IttiMsgText));
      message_p->ittiMsg.s1ap_initial_context_setup_log.size = res.result.encoded;
      memcpy(&message_p->ittiMsg.s1ap_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;

    case S1AP_ProcedureCode_id_UEContextRelease:
      res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
      message_id = S1AP_UE_CONTEXT_RELEASE_COMMAND_LOG;
      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id,
                  res.result.encoded + sizeof (IttiMsgText));
      message_p->ittiMsg.s1ap_ue_context_release_command_log.size = res.result.encoded;
      memcpy(&message_p->ittiMsg.s1ap_ue_context_release_command_log.text, res.buffer, res.result.encoded);
      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
      free(res.buffer);
      break;

    case S1AP_ProcedureCode_id_Paging:
      res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
      message_id = S1AP_PAGING_LOG;
      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id,
                  res.result.encoded + sizeof (IttiMsgText));
      message_p->ittiMsg.s1ap_paging_log.size = res.result.encoded;
      memcpy(&message_p->ittiMsg.s1ap_paging_log.text, res.buffer, res.result.encoded);
      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
      S1AP_INFO("Paging initiating message\n");
      free(res.buffer);
      break;

    case S1AP_ProcedureCode_id_E_RABSetup:
      res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
      message_id = S1AP_E_RAB_SETUP_REQUEST_LOG;
      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id,
                  res.result.encoded + sizeof (IttiMsgText));
      message_p->ittiMsg.s1ap_e_rab_setup_request_log.size = res.result.encoded;
      memcpy(&message_p->ittiMsg.s1ap_e_rab_setup_request_log.text, res.buffer, res.result.encoded);
      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
      free(res.buffer);
      S1AP_INFO("E_RABSetup initiating message\n");
      break;

    case S1AP_ProcedureCode_id_E_RABModify:
      res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
      message_id = S1AP_E_RAB_MODIFY_REQUEST_LOG;
      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id,
                  res.result.encoded + sizeof (IttiMsgText));
      message_p->ittiMsg.s1ap_e_rab_modify_request_log.size = res.result.encoded;
      memcpy(&message_p->ittiMsg.s1ap_e_rab_modify_request_log.text, res.buffer, res.result.encoded);
      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
      free(res.buffer);
      S1AP_INFO("E_RABModify initiating message\n");
      break;

    case S1AP_ProcedureCode_id_E_RABRelease:
      res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
      message_id = S1AP_E_RAB_RELEASE_REQUEST_LOG;
      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id,
                  res.result.encoded + sizeof (IttiMsgText));
      message_p->ittiMsg.s1ap_e_rab_release_request_log.size = res.result.encoded;
      memcpy(&message_p->ittiMsg.s1ap_e_rab_release_request_log.text, res.buffer, res.result.encoded);
      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
      free(res.buffer);
      S1AP_INFO("TODO  E_RABRelease nitiating message\n");
      break;

    default:
      S1AP_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;
135 136
  }

137
  return 0;
Cedric Roux's avatar
 
Cedric Roux committed
138 139
}

140
static int s1ap_eNB_decode_successful_outcome(S1AP_S1AP_PDU_t *pdu)
Cedric Roux's avatar
 
Cedric Roux committed
141
{
142 143
  MessageDef *message_p;
  MessagesIds message_id;
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
  asn_encode_to_new_buffer_result_t res = { NULL, {0, NULL, NULL} };
  DevAssert(pdu != NULL);

  switch(pdu->choice.successfulOutcome.procedureCode) {
    case S1AP_ProcedureCode_id_S1Setup:
      res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
      message_id = S1AP_S1_SETUP_LOG;
      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id, res.result.encoded + sizeof (IttiMsgText));
      message_p->ittiMsg.s1ap_s1_setup_log.size = res.result.encoded;
      memcpy(&message_p->ittiMsg.s1ap_s1_setup_log.text, res.buffer, res.result.encoded);
      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
      free(res.buffer);
      break;

    default:
      S1AP_ERROR("Unknown procedure ID (%d) for successfull outcome message\n",
                 (int)pdu->choice.successfulOutcome.procedureCode);
      return -1;
162
  }
Cedric Roux's avatar
Cedric Roux committed
163

164
  return 0;
Cedric Roux's avatar
 
Cedric Roux committed
165 166
}

167
static int s1ap_eNB_decode_unsuccessful_outcome(S1AP_S1AP_PDU_t *pdu)
Cedric Roux's avatar
 
Cedric Roux committed
168
{
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
  MessageDef *message_p;
  MessagesIds message_id;
  asn_encode_to_new_buffer_result_t res = { NULL, {0, NULL, NULL} };
  DevAssert(pdu != NULL);

  switch(pdu->choice.unsuccessfulOutcome.procedureCode) {
    case S1AP_ProcedureCode_id_S1Setup:
      res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
      message_id = S1AP_S1_SETUP_LOG;
      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id, res.result.encoded + sizeof (IttiMsgText));
      message_p->ittiMsg.s1ap_s1_setup_log.size = res.result.encoded;
      memcpy(&message_p->ittiMsg.s1ap_s1_setup_log.text, res.buffer, res.result.encoded);
      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
      free(res.buffer);
      break;

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

191
  return 0;
Cedric Roux's avatar
 
Cedric Roux committed
192 193
}

194
int s1ap_eNB_decode_pdu(S1AP_S1AP_PDU_t *pdu, const uint8_t *const buffer,
195
                        const uint32_t length)
Cedric Roux's avatar
 
Cedric Roux committed
196
{
197
  asn_dec_rval_t dec_ret;
198
  DevAssert(pdu != NULL);
199 200
  DevAssert(buffer != NULL);
  dec_ret = aper_decode(NULL,
201 202
                        &asn_DEF_S1AP_S1AP_PDU,
                        (void **)pdu,
203 204 205 206 207 208 209
                        buffer,
                        length,
                        0,
                        0);

  if (dec_ret.code != RC_OK) {
    S1AP_ERROR("Failed to decode pdu\n");
Cedric Roux's avatar
 
Cedric Roux committed
210
    return -1;
211 212
  }

213 214 215
  switch(pdu->present) {
    case S1AP_S1AP_PDU_PR_initiatingMessage:
      return s1ap_eNB_decode_initiating_message(pdu);
216

217 218
    case S1AP_S1AP_PDU_PR_successfulOutcome:
      return s1ap_eNB_decode_successful_outcome(pdu);
219

220 221
    case S1AP_S1AP_PDU_PR_unsuccessfulOutcome:
      return s1ap_eNB_decode_unsuccessful_outcome(pdu);
222

223 224 225
    default:
      S1AP_DEBUG("Unknown presence (%d) or not implemented\n", (int)pdu->present);
      break;
226 227 228
  }

  return -1;
Cedric Roux's avatar
 
Cedric Roux committed
229
}