s1ap_eNB_decoder.c 12.2 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
Cedric Roux's avatar
Cedric Roux committed
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
39
40
#include "s1ap_common.h"
#include "s1ap_ies_defs.h"
#include "s1ap_eNB_decoder.h"

static int s1ap_eNB_decode_initiating_message(s1ap_message *message,
41
    S1ap_InitiatingMessage_t *initiating_p)
Cedric Roux's avatar
 
Cedric Roux committed
42
{
43
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
  int         ret = -1;
  MessageDef *message_p;
  char       *message_string = NULL;
  size_t      message_string_size;
  MessagesIds message_id;

  DevAssert(initiating_p != NULL);

  message_string = calloc(10000, sizeof(char));

  s1ap_string_total_size = 0;

  message->procedureCode = initiating_p->procedureCode;
  message->criticality   = initiating_p->criticality;

  switch(initiating_p->procedureCode) {
  case S1ap_ProcedureCode_id_downlinkNASTransport:
    ret = s1ap_decode_s1ap_downlinknastransporties(
            &message->msg.s1ap_DownlinkNASTransportIEs,
            &initiating_p->value);
    s1ap_xer_print_s1ap_downlinknastransport(s1ap_xer__print2sp,
        message_string,
        message);
    message_id          = S1AP_DOWNLINK_NAS_LOG;
    message_string_size = strlen(message_string);
    message_p           = itti_alloc_new_message_sized(TASK_S1AP,
                          message_id,
                          message_string_size + sizeof (IttiMsgText));
    message_p->ittiMsg.s1ap_downlink_nas_log.size = message_string_size;
    memcpy(&message_p->ittiMsg.s1ap_downlink_nas_log.text, message_string, message_string_size);
    itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
    free(message_string);
    break;

  case S1ap_ProcedureCode_id_InitialContextSetup:
    ret = s1ap_decode_s1ap_initialcontextsetuprequesties(
            &message->msg.s1ap_InitialContextSetupRequestIEs, &initiating_p->value);
    s1ap_xer_print_s1ap_initialcontextsetuprequest(s1ap_xer__print2sp, message_string, message);
    message_id = S1AP_INITIAL_CONTEXT_SETUP_LOG;
    message_string_size = strlen(message_string);
    message_p           = itti_alloc_new_message_sized(TASK_S1AP,
                          message_id,
                          message_string_size + sizeof (IttiMsgText));
    message_p->ittiMsg.s1ap_initial_context_setup_log.size = message_string_size;
    memcpy(&message_p->ittiMsg.s1ap_initial_context_setup_log.text, message_string, message_string_size);
    itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
    free(message_string);
    break;

  case S1ap_ProcedureCode_id_UEContextRelease:
    ret = s1ap_decode_s1ap_uecontextreleasecommandies(
            &message->msg.s1ap_UEContextReleaseCommandIEs, &initiating_p->value);
    s1ap_xer_print_s1ap_uecontextreleasecommand(s1ap_xer__print2sp, message_string, message);
    message_id = S1AP_UE_CONTEXT_RELEASE_COMMAND_LOG;
    message_string_size = strlen(message_string);
    message_p           = itti_alloc_new_message_sized(TASK_S1AP,
                          message_id,
                          message_string_size + sizeof (IttiMsgText));
    message_p->ittiMsg.s1ap_ue_context_release_command_log.size = message_string_size;
    memcpy(&message_p->ittiMsg.s1ap_ue_context_release_command_log.text, message_string, message_string_size);
    itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
    free(message_string);
    break;

  case S1ap_ProcedureCode_id_Paging:
    ret = s1ap_decode_s1ap_pagingies(
            &message->msg.s1ap_PagingIEs, &initiating_p->value);
    s1ap_xer_print_s1ap_paging(s1ap_xer__print2sp, message_string, message);
111
112
113
114
115
116
117
118
119
    message_id = S1AP_PAGING_LOG;
    message_string_size = strlen(message_string);
    message_p           = itti_alloc_new_message_sized(TASK_S1AP,
                          message_id,
                          message_string_size + sizeof (IttiMsgText));
    message_p->ittiMsg.s1ap_paging_log.size = message_string_size;
    memcpy(&message_p->ittiMsg.s1ap_paging_log.text, message_string, message_string_size);
    itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
    S1AP_INFO("Paging initiating message\n");
120
121
122
123
    free(message_string);
    break;


124
125
126
  case S1ap_ProcedureCode_id_E_RABSetup:
    ret = s1ap_decode_s1ap_e_rabsetuprequesties(
						&message->msg.s1ap_E_RABSetupRequestIEs, &initiating_p->value);
127
    //s1ap_xer_print_s1ap_e_rabsetuprequest(s1ap_xer__print2sp, message_string, message);
128
129
130
131
132
133
134
135
    message_id = S1AP_E_RAB_SETUP_REQUEST_LOG;
    message_string_size = strlen(message_string);
    message_p           = itti_alloc_new_message_sized(TASK_S1AP,
                          message_id,
                          message_string_size + sizeof (IttiMsgText));
    message_p->ittiMsg.s1ap_e_rab_setup_request_log.size = message_string_size;
    memcpy(&message_p->ittiMsg.s1ap_e_rab_setup_request_log.text, message_string, message_string_size);
    itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
136
    free(message_string);
137
    S1AP_INFO("E_RABSetup initiating message\n");
138
    break;
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154

  case S1ap_ProcedureCode_id_E_RABModify:
    ret = s1ap_decode_s1ap_e_rabmodifyrequesties(
            &message->msg.s1ap_E_RABModifyRequestIEs, &initiating_p->value);
    message_id = S1AP_E_RAB_MODIFY_REQUEST_LOG;
    message_string_size = strlen(message_string);
    message_p           = itti_alloc_new_message_sized(TASK_S1AP,
                          message_id,
                          message_string_size + sizeof (IttiMsgText));
    message_p->ittiMsg.s1ap_e_rab_modify_request_log.size = message_string_size;
    memcpy(&message_p->ittiMsg.s1ap_e_rab_modify_request_log.text, message_string, message_string_size);
    itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
    free(message_string);
    S1AP_INFO("E_RABModify initiating message\n");
    break;

155
  case S1ap_ProcedureCode_id_E_RABRelease:
156
157
158
159
160
161
162
163
164
165
166
    ret = s1ap_decode_s1ap_e_rabreleasecommandies(
            &message->msg.s1ap_E_RABReleaseCommandIEs, &initiating_p->value);
    s1ap_xer_print_s1ap_e_rabreleasecommand(s1ap_xer__print2sp, message_string, message);
    message_id = S1AP_E_RAB_RELEASE_REQUEST_LOG;
    message_string_size = strlen(message_string);
    message_p           = itti_alloc_new_message_sized(TASK_S1AP,
                          message_id,
                          message_string_size + sizeof (IttiMsgText));
    message_p->ittiMsg.s1ap_e_rab_release_request_log.size = message_string_size;
    memcpy(&message_p->ittiMsg.s1ap_e_rab_release_request_log.text, message_string, message_string_size);
    itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
167
    free(message_string);
168
    S1AP_INFO("TODO  E_RABRelease nitiating message\n");    
169
170
    break;

171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
  case S1ap_ProcedureCode_id_ErrorIndication:
    ret = s1ap_decode_s1ap_errorindicationies(
            &message->msg.s1ap_ErrorIndicationIEs, &initiating_p->value);
    s1ap_xer_print_s1ap_errorindication(s1ap_xer__print2sp, message_string, message);
    message_id = S1AP_E_RAB_ERROR_INDICATION_LOG;
    message_string_size = strlen(message_string);
    message_p           = itti_alloc_new_message_sized(TASK_S1AP,
                          message_id,
                          message_string_size + sizeof (IttiMsgText));
    message_p->ittiMsg.s1ap_e_rab_release_request_log.size = message_string_size;
    memcpy(&message_p->ittiMsg.s1ap_error_indication_log.text, message_string, message_string_size);
    itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
    free(message_string);
    S1AP_INFO("ErrorIndication initiating message\n");
    break;

187
188
189
190
191
192
193
194
195
196
  default:
    S1AP_ERROR("Unknown procedure ID (%d) for initiating message\n",
               (int)initiating_p->procedureCode);
    AssertFatal( 0 , "Unknown procedure ID (%d) for initiating message\n",
                 (int)initiating_p->procedureCode);
    return -1;
  }


  return ret;
Cedric Roux's avatar
 
Cedric Roux committed
197
198
199
}

static int s1ap_eNB_decode_successful_outcome(s1ap_message *message,
200
    S1ap_SuccessfulOutcome_t *successfullOutcome_p)
Cedric Roux's avatar
 
Cedric Roux committed
201
{
202
203
204
205
206
  int ret = -1;
  MessageDef *message_p;
  char       *message_string = NULL;
  size_t      message_string_size;
  MessagesIds message_id;
Cedric Roux's avatar
Cedric Roux committed
207

208
  DevAssert(successfullOutcome_p != NULL);
Cedric Roux's avatar
 
Cedric Roux committed
209

210
  message_string = malloc(sizeof(char) * 10000);
211
  memset((void*)message_string,0,sizeof(char) * 10000);
212

213
  s1ap_string_total_size = 0;
214

215
216
  message->procedureCode = successfullOutcome_p->procedureCode;
  message->criticality   = successfullOutcome_p->criticality;
Cedric Roux's avatar
 
Cedric Roux committed
217

218
219
220
221
222
223
224
  switch(successfullOutcome_p->procedureCode) {
  case S1ap_ProcedureCode_id_S1Setup:
    ret = s1ap_decode_s1ap_s1setupresponseies(
            &message->msg.s1ap_S1SetupResponseIEs, &successfullOutcome_p->value);
    s1ap_xer_print_s1ap_s1setupresponse(s1ap_xer__print2sp, message_string, message);
    message_id = S1AP_S1_SETUP_LOG;
    break;
225

226
227
228
229
230
  default:
    S1AP_ERROR("Unknown procedure ID (%d) for successfull outcome message\n",
               (int)successfullOutcome_p->procedureCode);
    return -1;
  }
Cedric Roux's avatar
Cedric Roux committed
231

232
  message_string_size = strlen(message_string);
Cedric Roux's avatar
Cedric Roux committed
233

234
235
236
  message_p = itti_alloc_new_message_sized(TASK_S1AP, message_id, message_string_size + sizeof (IttiMsgText));
  message_p->ittiMsg.s1ap_s1_setup_log.size = message_string_size;
  memcpy(&message_p->ittiMsg.s1ap_s1_setup_log.text, message_string, message_string_size);
Cedric Roux's avatar
Cedric Roux committed
237

238
  itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p);
Cedric Roux's avatar
Cedric Roux committed
239

240
  free(message_string);
Cedric Roux's avatar
Cedric Roux committed
241

242
  return ret;
Cedric Roux's avatar
 
Cedric Roux committed
243
244
245
}

static int s1ap_eNB_decode_unsuccessful_outcome(s1ap_message *message,
246
    S1ap_UnsuccessfulOutcome_t *unSuccessfullOutcome_p)
Cedric Roux's avatar
 
Cedric Roux committed
247
{
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
  int ret = -1;
  DevAssert(unSuccessfullOutcome_p != NULL);

  message->procedureCode = unSuccessfullOutcome_p->procedureCode;
  message->criticality   = unSuccessfullOutcome_p->criticality;

  switch(unSuccessfullOutcome_p->procedureCode) {
  case S1ap_ProcedureCode_id_S1Setup:
    return s1ap_decode_s1ap_s1setupfailureies(
             &message->msg.s1ap_S1SetupFailureIEs, &unSuccessfullOutcome_p->value);

  default:
    S1AP_ERROR("Unknown procedure ID (%d) for unsuccessfull outcome message\n",
               (int)unSuccessfullOutcome_p->procedureCode);
    break;
  }

  return ret;
Cedric Roux's avatar
 
Cedric Roux committed
266
267
}

268
269
int s1ap_eNB_decode_pdu(s1ap_message *message, const uint8_t * const buffer,
                        const uint32_t length)
Cedric Roux's avatar
 
Cedric Roux committed
270
{
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
  S1AP_PDU_t  pdu;
  S1AP_PDU_t *pdu_p = &pdu;
  asn_dec_rval_t dec_ret;

  DevAssert(buffer != NULL);

  memset((void *)pdu_p, 0, sizeof(S1AP_PDU_t));

  dec_ret = aper_decode(NULL,
                        &asn_DEF_S1AP_PDU,
                        (void **)&pdu_p,
                        buffer,
                        length,
                        0,
                        0);

  if (dec_ret.code != RC_OK) {
    S1AP_ERROR("Failed to decode pdu\n");
Cedric Roux's avatar
 
Cedric Roux committed
289
    return -1;
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
  }

  message->direction = pdu_p->present;

  switch(pdu_p->present) {
  case S1AP_PDU_PR_initiatingMessage:
    return s1ap_eNB_decode_initiating_message(message,
           &pdu_p->choice.initiatingMessage);

  case S1AP_PDU_PR_successfulOutcome:
    return s1ap_eNB_decode_successful_outcome(message,
           &pdu_p->choice.successfulOutcome);

  case S1AP_PDU_PR_unsuccessfulOutcome:
    return s1ap_eNB_decode_unsuccessful_outcome(message,
           &pdu_p->choice.unsuccessfulOutcome);

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

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