s1ap_eNB_encoder.c 12 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_encoder.c
 * \brief s1ap pdu encode 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
 * \version 0.1
 */

#include <stdio.h>
#include <string.h>
32 33
#include <stdint.h>

34
#include "assertions.h"
35 36
#include "conversions.h"
#include "intertask_interface.h"
Cedric Roux's avatar
Cedric Roux committed
37 38 39
#include "s1ap_common.h"
#include "s1ap_eNB_encoder.h"

Wang Tsu-Han's avatar
Wang Tsu-Han committed
40
static inline int s1ap_eNB_encode_initiating(S1AP_S1AP_PDU_t *pdu,
41 42
    uint8_t **buffer,
    uint32_t *len);
43

Wang Tsu-Han's avatar
Wang Tsu-Han committed
44
static inline int s1ap_eNB_encode_successfull_outcome(S1AP_S1AP_PDU_t *pdu,
45
    uint8_t **buffer, uint32_t *len);
46

Wang Tsu-Han's avatar
Wang Tsu-Han committed
47
static inline int s1ap_eNB_encode_unsuccessfull_outcome(S1AP_S1AP_PDU_t *pdu,
48
    uint8_t **buffer, uint32_t *len);
49

Wang Tsu-Han's avatar
Wang Tsu-Han committed
50
int s1ap_eNB_encode_pdu(S1AP_S1AP_PDU_t *pdu, uint8_t **buffer, uint32_t *len)
Cedric Roux's avatar
Cedric Roux committed
51
{
Wang Tsu-Han's avatar
Wang Tsu-Han committed
52 53
  int ret = -1;
  DevAssert(pdu != NULL);
54 55 56
  DevAssert(buffer != NULL);
  DevAssert(len != NULL);

Wang Tsu-Han's avatar
Wang Tsu-Han committed
57 58 59 60
  switch(pdu->present) {
    case S1AP_S1AP_PDU_PR_initiatingMessage:
      ret = s1ap_eNB_encode_initiating(pdu, buffer, len);
      break;
61

Wang Tsu-Han's avatar
Wang Tsu-Han committed
62 63 64
    case S1AP_S1AP_PDU_PR_successfulOutcome:
      ret = s1ap_eNB_encode_successfull_outcome(pdu, buffer, len);
      break;
65

Wang Tsu-Han's avatar
Wang Tsu-Han committed
66 67 68
    case S1AP_S1AP_PDU_PR_unsuccessfulOutcome:
      ret = s1ap_eNB_encode_unsuccessfull_outcome(pdu, buffer, len);
      break;
69

Wang Tsu-Han's avatar
Wang Tsu-Han committed
70 71 72 73
    default:
      S1AP_DEBUG("Unknown message outcome (%d) or not implemented",
                 (int)pdu->present);
      return -1;
74 75
  }

Wang Tsu-Han's avatar
Wang Tsu-Han committed
76 77
  ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1AP_S1AP_PDU, pdu);
  return ret;
Cedric Roux's avatar
Cedric Roux committed
78 79 80
}

static inline
Wang Tsu-Han's avatar
Wang Tsu-Han committed
81
int s1ap_eNB_encode_initiating(S1AP_S1AP_PDU_t *pdu,
82
                               uint8_t **buffer, uint32_t *len)
Cedric Roux's avatar
Cedric Roux committed
83
{
84 85
  MessageDef *message_p;
  MessagesIds message_id;
Wang Tsu-Han's avatar
Wang Tsu-Han committed
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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
  asn_encode_to_new_buffer_result_t res = { NULL, {0, NULL, NULL} };
  DevAssert(pdu != NULL);

  switch(pdu->choice.initiatingMessage.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;

    case S1AP_ProcedureCode_id_uplinkNASTransport:
      res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
      message_id = S1AP_UPLINK_NAS_LOG;
      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id, res.result.encoded + sizeof (IttiMsgText));
      message_p->ittiMsg.s1ap_uplink_nas_log.size = res.result.encoded;
      memcpy(&message_p->ittiMsg.s1ap_uplink_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_UECapabilityInfoIndication:
      res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
      message_id = S1AP_UE_CAPABILITY_IND_LOG;
      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id, res.result.encoded + sizeof (IttiMsgText));
      message_p->ittiMsg.s1ap_ue_capability_ind_log.size = res.result.encoded;
      memcpy(&message_p->ittiMsg.s1ap_ue_capability_ind_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_initialUEMessage:
      res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
      message_id = S1AP_INITIAL_UE_MESSAGE_LOG;
      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id, res.result.encoded + sizeof (IttiMsgText));
      message_p->ittiMsg.s1ap_initial_ue_message_log.size = res.result.encoded;
      memcpy(&message_p->ittiMsg.s1ap_initial_ue_message_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_NASNonDeliveryIndication:
      res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
      message_id = S1AP_NAS_NON_DELIVERY_IND_LOG;
      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id, res.result.encoded + sizeof (IttiMsgText));
      message_p->ittiMsg.s1ap_nas_non_delivery_ind_log.size = res.result.encoded;
      memcpy(&message_p->ittiMsg.s1ap_nas_non_delivery_ind_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_UEContextReleaseRequest:
      res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
      message_id = S1AP_UE_CONTEXT_RELEASE_REQ_LOG;
      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id, res.result.encoded + sizeof (IttiMsgText));
      message_p->ittiMsg.s1ap_ue_context_release_req_log.size = res.result.encoded;
      memcpy(&message_p->ittiMsg.s1ap_ue_context_release_req_log.text, res.buffer, res.result.encoded);
      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
      free(res.buffer);
      break;

    default:
      S1AP_DEBUG("Unknown procedure ID (%d) for initiating message\n",
                 (int)pdu->choice.initiatingMessage.procedureCode);
      return -1;
154
  }
155

Wang Tsu-Han's avatar
Wang Tsu-Han committed
156 157 158
  if (asn1_xer_print) {
    xer_fprint(stdout, &asn_DEF_S1AP_S1AP_PDU, (void *)pdu);
  }
159

Wang Tsu-Han's avatar
Wang Tsu-Han committed
160 161 162 163 164
  memset(&res, 0, sizeof(res));
  res = asn_encode_to_new_buffer(NULL, ATS_ALIGNED_CANONICAL_PER, &asn_DEF_S1AP_S1AP_PDU, pdu);
  *buffer = res.buffer;
  *len = res.result.encoded;
  return 0;
Cedric Roux's avatar
Cedric Roux committed
165 166 167
}

static inline
Wang Tsu-Han's avatar
Wang Tsu-Han committed
168
int s1ap_eNB_encode_successfull_outcome(S1AP_S1AP_PDU_t *pdu,
169
                                        uint8_t **buffer, uint32_t *len)
Cedric Roux's avatar
Cedric Roux committed
170
{
171 172
  MessageDef *message_p;
  MessagesIds message_id;
Wang Tsu-Han's avatar
Wang Tsu-Han committed
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
  asn_encode_to_new_buffer_result_t res = { NULL, {0, NULL, NULL} };
  DevAssert(pdu != NULL);

  switch(pdu->choice.successfulOutcome.procedureCode) {
    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_COMPLETE_LOG;
      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id, res.result.encoded + sizeof (IttiMsgText));
      message_p->ittiMsg.s1ap_ue_context_release_complete_log.size = res.result.encoded;
      memcpy(&message_p->ittiMsg.s1ap_ue_context_release_complete_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_E_RABSetup:
      res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu);
      message_id = S1AP_E_RAB_SETUP_RESPONSE_LOG;
      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id, res.result.encoded + sizeof (IttiMsgText));
      message_p->ittiMsg.s1ap_e_rab_setup_response_log.size = res.result.encoded;
      memcpy(&message_p->ittiMsg.s1ap_e_rab_setup_response_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 successful 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_RESPONSE_LOG;
      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id, res.result.encoded + sizeof (IttiMsgText));
      message_p->ittiMsg.s1ap_e_rab_modify_response_log.size = res.result.encoded;
      memcpy(&message_p->ittiMsg.s1ap_e_rab_modify_response_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 successful 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_RESPONSE_LOG;
      message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id, res.result.encoded + sizeof (IttiMsgText));
      message_p->ittiMsg.s1ap_e_rab_release_response_log.size = res.result.encoded;
      memcpy(&message_p->ittiMsg.s1ap_e_rab_release_response_log.text, res.buffer, res.result.encoded);
      itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
      free(res.buffer);
      S1AP_INFO("E_RAB Release successful message\n");
      break;

    default:
      S1AP_WARN("Unknown procedure ID (%d) for successfull outcome message\n",
                (int)pdu->choice.successfulOutcome.procedureCode);
      return -1;
234 235
  }

Wang Tsu-Han's avatar
Wang Tsu-Han committed
236 237 238
  if (asn1_xer_print) {
    xer_fprint(stdout, &asn_DEF_S1AP_S1AP_PDU, (void *)pdu);
  }
239

Wang Tsu-Han's avatar
Wang Tsu-Han committed
240 241 242 243 244
  memset(&res, 0, sizeof(res));
  res = asn_encode_to_new_buffer(NULL, ATS_ALIGNED_CANONICAL_PER, &asn_DEF_S1AP_S1AP_PDU, pdu);
  *buffer = res.buffer;
  *len = res.result.encoded;
  return 0;
Cedric Roux's avatar
Cedric Roux committed
245 246 247
}

static inline
Wang Tsu-Han's avatar
Wang Tsu-Han committed
248
int s1ap_eNB_encode_unsuccessfull_outcome(S1AP_S1AP_PDU_t *pdu,
Cedric Roux's avatar
Cedric Roux committed
249 250
    uint8_t **buffer, uint32_t *len)
{
251 252
  MessageDef *message_p;
  MessagesIds message_id;
Wang Tsu-Han's avatar
Wang Tsu-Han committed
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
  asn_encode_to_new_buffer_result_t res = { NULL, {0, NULL, NULL} };
  DevAssert(pdu != NULL);

  switch(pdu->choice.unsuccessfulOutcome.procedureCode) {
    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;

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

Wang Tsu-Han's avatar
Wang Tsu-Han committed
273 274
  if (asn1_xer_print) {
    xer_fprint(stdout, &asn_DEF_S1AP_S1AP_PDU, (void *)pdu);
275 276
  }

Wang Tsu-Han's avatar
Wang Tsu-Han committed
277 278 279 280 281
  memset(&res, 0, sizeof(res));
  res = asn_encode_to_new_buffer(NULL, ATS_ALIGNED_CANONICAL_PER, &asn_DEF_S1AP_S1AP_PDU, pdu);
  *buffer = res.buffer;
  *len = res.result.encoded;
  return 0;
282
}