s1ap_eNB_handlers.c 18.8 KB
Newer Older
Cedric Roux's avatar
 
Cedric Roux committed
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
36
37
38
39
/*******************************************************************************

  Eurecom OpenAirInterface
  Copyright(c) 1999 - 2012 Eurecom

  This program is free software; you can redistribute it and/or modify it
  under the terms and conditions of the GNU General Public License,
  version 2, as published by the Free Software Foundation.

  This program is distributed in the hope it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  more details.

  You should have received a copy of the GNU General Public License along with
  this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.

  The full GNU General Public License is included in this distribution in
  the file called "COPYING".

  Contact Information
  Openair Admin: openair_admin@eurecom.fr
  Openair Tech : openair_tech@eurecom.fr
  Forums       : http://forums.eurecom.fr/openairinterface
  Address      : EURECOM, Campus SophiaTech, 450 Route des Chappes
                 06410 Biot FRANCE

*******************************************************************************/

/*! \file s1ap_eNB_handlers.c
 * \brief s1ap messages handlers for eNB part
 * \author Sebastien ROUX <sebastien.roux@eurecom.fr>
 * \date 2013
 * \version 0.1
 */

#include <stdint.h>

40
41
#include "intertask_interface.h"

42
43
#include "asn1_conversions.h"

Cedric Roux's avatar
 
Cedric Roux committed
44
45
#include "s1ap_common.h"
#include "s1ap_ies_defs.h"
46
47
// #include "s1ap_eNB.h"
#include "s1ap_eNB_defs.h"
Cedric Roux's avatar
 
Cedric Roux committed
48
49
50
51
52
53
#include "s1ap_eNB_handlers.h"
#include "s1ap_eNB_decoder.h"

#include "s1ap_eNB_ue_context.h"
#include "s1ap_eNB_trace.h"
#include "s1ap_eNB_nas_procedures.h"
54
#include "s1ap_eNB_management_procedures.h"
Cedric Roux's avatar
 
Cedric Roux committed
55

56
#include "s1ap_eNB_default_values.h"
Cedric Roux's avatar
 
Cedric Roux committed
57
58
59

#include "conversions.h"

60
61
62
63
static
int s1ap_eNB_handle_s1_setup_response(uint32_t               assoc_id,
                                      uint32_t               stream,
                                      struct s1ap_message_s *message_p);
Cedric Roux's avatar
Cedric Roux committed
64
static
65
66
67
68
69
70
71
72
int s1ap_eNB_handle_s1_setup_failure(uint32_t               assoc_id,
                                     uint32_t               stream,
                                     struct s1ap_message_s *message_p);

static
int s1ap_eNB_handle_initial_context_request(uint32_t               assoc_id,
                                            uint32_t               stream,
                                            struct s1ap_message_s *message_p);
Cedric Roux's avatar
 
Cedric Roux committed
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

/* Handlers matrix. Only eNB related procedure present here */
s1ap_message_decoded_callback messages_callback[][3] = {
    { 0, 0, 0 }, /* HandoverPreparation */
    { 0, 0, 0 }, /* HandoverResourceAllocation */
    { 0, 0, 0 }, /* HandoverNotification */
    { 0, 0, 0 }, /* PathSwitchRequest */
    { 0, 0, 0 }, /* HandoverCancel */
    { 0, 0, 0 }, /* E_RABSetup */
    { 0, 0, 0 }, /* E_RABModify */
    { 0, 0, 0 }, /* E_RABRelease */
    { 0, 0, 0 }, /* E_RABReleaseIndication */
    { s1ap_eNB_handle_initial_context_request, 0, 0 }, /* InitialContextSetup */
    { 0, 0, 0 }, /* Paging */
    { s1ap_eNB_handle_nas_downlink, 0, 0 }, /* downlinkNASTransport */
    { 0, 0, 0 }, /* initialUEMessage */
    { 0, 0, 0 }, /* uplinkNASTransport */
    { 0, 0, 0 }, /* Reset */
    { 0, 0, 0 }, /* ErrorIndication */
    { 0, 0, 0 }, /* NASNonDeliveryIndication */
93
    { 0, s1ap_eNB_handle_s1_setup_response, s1ap_eNB_handle_s1_setup_failure }, /* S1Setup */
Cedric Roux's avatar
 
Cedric Roux committed
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
    { 0, 0, 0 }, /* UEContextReleaseRequest */
    { 0, 0, 0 }, /* DownlinkS1cdma2000tunneling */
    { 0, 0, 0 }, /* UplinkS1cdma2000tunneling */
    { 0, 0, 0 }, /* UEContextModification */
    { 0, 0, 0 }, /* UECapabilityInfoIndication */
    { 0, 0, 0 }, /* UEContextRelease */
    { 0, 0, 0 }, /* eNBStatusTransfer */
    { 0, 0, 0 }, /* MMEStatusTransfer */
    { s1ap_eNB_handle_deactivate_trace, 0, 0 }, /* DeactivateTrace */
    { s1ap_eNB_handle_trace_start, 0, 0 }, /* TraceStart */
    { 0, 0, 0 }, /* TraceFailureIndication */
    { 0, 0, 0 }, /* ENBConfigurationUpdate */
    { 0, 0, 0 }, /* MMEConfigurationUpdate */
    { 0, 0, 0 }, /* LocationReportingControl */
    { 0, 0, 0 }, /* LocationReportingFailureIndication */
    { 0, 0, 0 }, /* LocationReport */
    { 0, 0, 0 }, /* OverloadStart */
    { 0, 0, 0 }, /* OverloadStop */
    { 0, 0, 0 }, /* WriteReplaceWarning */
    { 0, 0, 0 }, /* eNBDirectInformationTransfer */
    { 0, 0, 0 }, /* MMEDirectInformationTransfer */
    { 0, 0, 0 }, /* PrivateMessage */
    { 0, 0, 0 }, /* eNBConfigurationTransfer */
    { 0, 0, 0 }, /* MMEConfigurationTransfer */
    { 0, 0, 0 }, /* CellTrafficTrace */
#if defined(UPDATE_RELEASE_9)
    { 0, 0, 0 }, /* Kill */
    { 0, 0, 0 }, /* DownlinkUEAssociatedLPPaTransport  */
    { 0, 0, 0 }, /* UplinkUEAssociatedLPPaTransport */
    { 0, 0, 0 }, /* DownlinkNonUEAssociatedLPPaTransport */
    { 0, 0, 0 }, /* UplinkNonUEAssociatedLPPaTransport */
#endif
};

static const char *direction2String[] = {
    "", /* Nothing */
    "Originating message", /* originating message */
    "Successfull outcome", /* successfull outcome */
    "UnSuccessfull outcome", /* successfull outcome */
};

135
136
int s1ap_eNB_handle_message(uint32_t assoc_id, int32_t stream,
                            const uint8_t * const data, const uint32_t data_length)
Cedric Roux's avatar
 
Cedric Roux committed
137
138
139
{
    struct s1ap_message_s message;

140
    DevAssert(data != NULL);
Cedric Roux's avatar
 
Cedric Roux committed
141
142
143

    memset(&message, 0, sizeof(struct s1ap_message_s));

144
    if (s1ap_eNB_decode_pdu(&message, data, data_length) < 0) {
Cedric Roux's avatar
 
Cedric Roux committed
145
146
147
148
149
150
151
152
        S1AP_ERROR("Failed to decode PDU\n");
        return -1;
    }
    /* Checking procedure Code and direction of message */
    if (message.procedureCode > sizeof(messages_callback) / (3 * sizeof(
                s1ap_message_decoded_callback))
            || (message.direction > S1AP_PDU_PR_unsuccessfulOutcome)) {
        S1AP_ERROR("[SCTP %d] Either procedureCode %d or direction %d exceed expected\n",
153
                   assoc_id, message.procedureCode, message.direction);
Cedric Roux's avatar
 
Cedric Roux committed
154
155
156
157
158
159
160
        return -1;
    }
    /* No handler present.
     * This can mean not implemented or no procedure for eNB (wrong direction).
     */
    if (messages_callback[message.procedureCode][message.direction-1] == NULL) {
        S1AP_ERROR("[SCTP %d] No handler for procedureCode %d in %s\n",
161
                   assoc_id, message.procedureCode,
Cedric Roux's avatar
 
Cedric Roux committed
162
163
164
165
166
                   direction2String[message.direction]);
        return -1;
    }

    /* Calling the right handler */
167
168
    return (*messages_callback[message.procedureCode][message.direction-1])
        (assoc_id, stream, &message);
Cedric Roux's avatar
 
Cedric Roux committed
169
170
}

Cedric Roux's avatar
Cedric Roux committed
171
static
172
173
174
175
176
177
178
179
180
int s1ap_eNB_handle_s1_setup_failure(uint32_t               assoc_id,
                                     uint32_t               stream,
                                     struct s1ap_message_s *message_p)
{
    /* S1 Setup Failure == Non UE-related procedure -> stream 0 */
    if (stream != 0) {
        S1AP_WARN("[SCTP %d] Received s1 setup failure on stream != 0 (%d)\n",
                  assoc_id, stream);
    }
Cedric Roux's avatar
Cedric Roux committed
181
    S1AP_ERROR("Received s1 setup failure for MME... please check your parameters\n");
182
183
184
185
186
187
188

    return 0;
}

static
int s1ap_eNB_handle_s1_setup_response(uint32_t               assoc_id,
                                      uint32_t               stream,
Cedric Roux's avatar
 
Cedric Roux committed
189
190
                                      struct s1ap_message_s *message_p)
{
191
192
    S1ap_S1SetupResponseIEs_t *s1SetupResponse_p;
    s1ap_eNB_mme_data_t       *mme_desc_p;
Cedric Roux's avatar
 
Cedric Roux committed
193
194
195
196
    int i;

    DevAssert(message_p != NULL);

197
    s1SetupResponse_p = &message_p->msg.s1ap_S1SetupResponseIEs;
Cedric Roux's avatar
 
Cedric Roux committed
198
199

    /* S1 Setup Response == Non UE-related procedure -> stream 0 */
200
    if (stream != 0) {
Cedric Roux's avatar
 
Cedric Roux committed
201
        S1AP_ERROR("[SCTP %d] Received s1 setup response on stream != 0 (%d)\n",
202
                   assoc_id, stream);
Cedric Roux's avatar
 
Cedric Roux committed
203
204
205
        return -1;
    }

206
    if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) {
Cedric Roux's avatar
 
Cedric Roux committed
207
        S1AP_ERROR("[SCTP %d] Received S1 setup response for non existing "
208
                   "MME context\n", assoc_id);
Cedric Roux's avatar
 
Cedric Roux committed
209
210
211
212
213
214
215
216
217
        return -1;
    }

    /* The list of served gummei can contain at most 8 elements.
     * LTE related gummei is the first element in the list, i.e with an id of 0.
     */
    DevAssert(s1SetupResponse_p->servedGUMMEIs.list.count == 1);

    for (i = 0; i < s1SetupResponse_p->servedGUMMEIs.list.count; i++) {
218
219
        struct S1ap_ServedGUMMEIsItem *gummei_item_p;
        struct served_gummei_s        *new_gummei_p;
Cedric Roux's avatar
 
Cedric Roux committed
220
221
        int j;

222
        gummei_item_p = (struct S1ap_ServedGUMMEIsItem *)
Cedric Roux's avatar
 
Cedric Roux committed
223
224
225
226
227
228
229
230
                        s1SetupResponse_p->servedGUMMEIs.list.array[i];
        new_gummei_p = calloc(1, sizeof(struct served_gummei_s));

        STAILQ_INIT(&new_gummei_p->served_plmns);
        STAILQ_INIT(&new_gummei_p->served_group_ids);
        STAILQ_INIT(&new_gummei_p->mme_codes);

        for (j = 0; j < gummei_item_p->servedPLMNs.list.count; j++) {
231
            S1ap_PLMNidentity_t *plmn_identity_p;
Cedric Roux's avatar
 
Cedric Roux committed
232
233
234
235
236
237
238
239
240
241
            struct plmn_identity_s *new_plmn_identity_p;

            plmn_identity_p = gummei_item_p->servedPLMNs.list.array[i];
            new_plmn_identity_p = calloc(1, sizeof(struct plmn_identity_s));
            TBCD_TO_MCC_MNC(plmn_identity_p, new_plmn_identity_p->mcc,
                            new_plmn_identity_p->mnc);
            STAILQ_INSERT_TAIL(&new_gummei_p->served_plmns, new_plmn_identity_p, next);
            new_gummei_p->nb_served_plmns++;
        }
        for (j = 0; j < gummei_item_p->servedGroupIDs.list.count; j++) {
242
            S1ap_MME_Group_ID_t           *mme_group_id_p;
Cedric Roux's avatar
 
Cedric Roux committed
243
244
245
246
247
248
249
250
251
            struct served_group_id_s *new_group_id_p;

            mme_group_id_p = gummei_item_p->servedGroupIDs.list.array[i];
            new_group_id_p = calloc(1, sizeof(struct served_group_id_s));
            OCTET_STRING_TO_INT16(mme_group_id_p, new_group_id_p->mme_group_id);
            STAILQ_INSERT_TAIL(&new_gummei_p->served_group_ids, new_group_id_p, next);
            new_gummei_p->nb_group_id++;
        }
        for (j = 0; j < gummei_item_p->servedMMECs.list.count; j++) {
252
            S1ap_MME_Code_t        *mme_code_p;
Cedric Roux's avatar
 
Cedric Roux committed
253
254
255
256
257
258
259
260
261
262
263
264
            struct mme_code_s *new_mme_code_p;

            mme_code_p = gummei_item_p->servedMMECs.list.array[i];
            new_mme_code_p = calloc(1, sizeof(struct mme_code_s));

            OCTET_STRING_TO_INT8(mme_code_p, new_mme_code_p->mme_code);
            STAILQ_INSERT_TAIL(&new_gummei_p->mme_codes, new_mme_code_p, next);
            new_gummei_p->nb_mme_code++;
        }
        STAILQ_INSERT_TAIL(&mme_desc_p->served_gummei, new_gummei_p, next);
    }
    /* Free contents of the list */
265
    ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1ap_ServedGUMMEIs,
Cedric Roux's avatar
 
Cedric Roux committed
266
267
268
269
                                  (void *)&s1SetupResponse_p->servedGUMMEIs);
    /* Set the capacity of this MME */
    mme_desc_p->relative_mme_capacity = s1SetupResponse_p->relativeMMECapacity;
    /* Optionaly set the mme name */
270
    if (s1SetupResponse_p->presenceMask & S1AP_S1SETUPRESPONSEIES_MMENAME_PRESENT) {
Cedric Roux's avatar
 
Cedric Roux committed
271
272
273
274
275
276
277
278
279
280
281
        mme_desc_p->mme_name = calloc(s1SetupResponse_p->mmEname.size + 1, sizeof(char));
        memcpy(mme_desc_p->mme_name, s1SetupResponse_p->mmEname.buf,
               s1SetupResponse_p->mmEname.size);
        /* Convert the mme name to a printable string */
        mme_desc_p->mme_name[s1SetupResponse_p->mmEname.size] = '\0';
    }
    /* The association is now ready as eNB and MME know parameters of each other.
     * Mark the association as UP to enable UE contexts creation.
     */
    mme_desc_p->state = S1AP_ENB_STATE_CONNECTED;

282
#if 0
Cedric Roux's avatar
Cedric Roux committed
283
284
285
286
287
288
289
290
291
292
    /* We call back our self
     * -> generate a dummy initial UE message
     */
    {
        s1ap_nas_first_req_t s1ap_nas_first_req;

        memset(&s1ap_nas_first_req, 0, sizeof(s1ap_nas_first_req_t));

        s1ap_nas_first_req.rnti = 0xC03A;
        s1ap_nas_first_req.establishment_cause = RRC_CAUSE_MO_DATA;
winckel's avatar
winckel committed
293
        s1ap_nas_first_req.ue_identity.presenceMask = UE_IDENTITIES_gummei;
Cedric Roux's avatar
Cedric Roux committed
294

winckel's avatar
winckel committed
295
296
297
298
        s1ap_nas_first_req.ue_identity.gummei.mcc = 208;
        s1ap_nas_first_req.ue_identity.gummei.mnc = 34;
        s1ap_nas_first_req.ue_identity.gummei.mme_code = 0;
        s1ap_nas_first_req.ue_identity.gummei.mme_group_id = 0;
Cedric Roux's avatar
Cedric Roux committed
299
300

        /* NAS Attach request with IMSI */
winckel's avatar
winckel committed
301
        static uint8_t nas_attach_req_imsi[] =
Cedric Roux's avatar
Cedric Roux committed
302
303
304
305
306
307
308
309
310
311
312
313
314
315
        {
            0x07, 0x41,
            /* EPS Mobile identity = IMSI */
            0x71, 0x08, 0x29, 0x80, 0x43, 0x21, 0x43, 0x65, 0x87,
            0xF9,
            /* End of EPS Mobile Identity */
            0x02, 0xE0, 0xE0, 0x00, 0x20, 0x02, 0x03,
            0xD0, 0x11, 0x27, 0x1A, 0x80, 0x80, 0x21, 0x10, 0x01, 0x00, 0x00,
            0x10, 0x81, 0x06, 0x00, 0x00, 0x00, 0x00, 0x83, 0x06, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x0A, 0x00, 0x52, 0x12, 0xF2,
            0x01, 0x27, 0x11,
        };

        /* NAS Attach request with GUTI */
winckel's avatar
winckel committed
316
        static uint8_t nas_attach_req_guti[] =
Cedric Roux's avatar
Cedric Roux committed
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
        {
            0x07, 0x41,
            /* EPS Mobile identity = IMSI */
            0x71, 0x0B, 0xF6, 0x12, 0xF2, 0x01, 0x80, 0x00, 0x01, 0xE0, 0x00,
            0xDA, 0x1F,
            /* End of EPS Mobile Identity */
            0x02, 0xE0, 0xE0, 0x00, 0x20, 0x02, 0x03,
            0xD0, 0x11, 0x27, 0x1A, 0x80, 0x80, 0x21, 0x10, 0x01, 0x00, 0x00,
            0x10, 0x81, 0x06, 0x00, 0x00, 0x00, 0x00, 0x83, 0x06, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x0A, 0x00, 0x52, 0x12, 0xF2,
            0x01, 0x27, 0x11,
        };

        s1ap_nas_first_req.nas_pdu.buffer = nas_attach_req_guti;
        s1ap_nas_first_req.nas_pdu.length = sizeof(nas_attach_req_guti);

333
334
        s1ap_eNB_handle_nas_first_req(mme_desc_p->s1ap_eNB_instance->instance,
                                      &s1ap_nas_first_req);
Cedric Roux's avatar
Cedric Roux committed
335
    }
336
#endif
Cedric Roux's avatar
 
Cedric Roux committed
337
338
339
340

    return 0;
}

341
342
343
static
int s1ap_eNB_handle_initial_context_request(uint32_t               assoc_id,
                                            uint32_t               stream,
344
                                            struct s1ap_message_s *s1ap_message_p)
Cedric Roux's avatar
 
Cedric Roux committed
345
{
346
347
    int i;

Cedric Roux's avatar
 
Cedric Roux committed
348
349
    s1ap_eNB_mme_data_t   *mme_desc_p;
    s1ap_eNB_ue_context_t *ue_desc_p;
350
    MessageDef            *message_p;
Cedric Roux's avatar
 
Cedric Roux committed
351

352
    S1ap_InitialContextSetupRequestIEs_t *initialContextSetupRequest_p;
353
    DevAssert(s1ap_message_p != NULL);
Cedric Roux's avatar
 
Cedric Roux committed
354

355
    initialContextSetupRequest_p = &s1ap_message_p->msg.s1ap_InitialContextSetupRequestIEs;
Cedric Roux's avatar
 
Cedric Roux committed
356

Cedric Roux's avatar
Cedric Roux committed
357
358
359
360
361
362
363
364
    if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) {
        S1AP_ERROR("[SCTP %d] Received initial context setup request for non "
                   "existing MME context\n", assoc_id);
        return -1;
    }
    if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_desc_p->s1ap_eNB_instance,
                     initialContextSetupRequest_p->eNB_UE_S1AP_ID)) == NULL) {
        S1AP_ERROR("[SCTP %d] Received initial context setup request for non "
365
        "existing UE context 0x%06x\n", assoc_id,
366
        initialContextSetupRequest_p->eNB_UE_S1AP_ID);
Cedric Roux's avatar
 
Cedric Roux committed
367
368
369
        return -1;
    }

Cedric Roux's avatar
Cedric Roux committed
370
371
372
373
374
375
    /* Initial context request = UE-related procedure -> stream != 0 */
    if (stream != ue_desc_p->stream) {
        S1AP_ERROR("[SCTP %d] Received UE-related procedure on stream (%d) whereas expecting (%d)\n",
                   assoc_id, stream, ue_desc_p->stream);
        return -1;
    }
Cedric Roux's avatar
 
Cedric Roux committed
376

377
    ue_desc_p->mme_ue_s1ap_id = initialContextSetupRequest_p->mme_ue_s1ap_id;
Cedric Roux's avatar
 
Cedric Roux committed
378

379
380
    message_p = itti_alloc_new_message(TASK_S1AP, S1AP_INITIAL_CONTEXT_SETUP_REQ);

381
    S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).ue_initial_id  = ue_desc_p->ue_initial_id;
382
383
    ue_desc_p->ue_initial_id = 0;

384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
    S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).eNB_ue_s1ap_id = ue_desc_p->eNB_ue_s1ap_id;
    S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).nb_of_e_rabs =
    initialContextSetupRequest_p->e_RABToBeSetupListCtxtSUReq.s1ap_E_RABToBeSetupItemCtxtSUReq.count;

    S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).ue_ambr.br_ul = initialContextSetupRequest_p->uEaggregateMaximumBitrate.uEaggregateMaximumBitRateUL;
    S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).ue_ambr.br_dl = initialContextSetupRequest_p->uEaggregateMaximumBitrate.uEaggregateMaximumBitRateDL;

    S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).security_capabilities.encryption_algorithms =
    BIT_STRING_to_uint16(&initialContextSetupRequest_p->ueSecurityCapabilities.encryptionAlgorithms);
    S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).security_capabilities.integrity_algorithms =
    BIT_STRING_to_uint16(&initialContextSetupRequest_p->ueSecurityCapabilities.integrityProtectionAlgorithms);

    /* Copy the security key */
    memcpy(&S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).security_key,
           initialContextSetupRequest_p->securityKey.buf, initialContextSetupRequest_p->securityKey.size);

    for (i = 0; i < initialContextSetupRequest_p->e_RABToBeSetupListCtxtSUReq.s1ap_E_RABToBeSetupItemCtxtSUReq.count; i++)
    {
        S1ap_E_RABToBeSetupItemCtxtSUReq_t *item_p;

        item_p = (S1ap_E_RABToBeSetupItemCtxtSUReq_t *)initialContextSetupRequest_p->e_RABToBeSetupListCtxtSUReq.s1ap_E_RABToBeSetupItemCtxtSUReq.array[i];

        S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].e_rab_id = item_p->e_RAB_ID;
        if (item_p->nAS_PDU != NULL) {
            /* Only copy NAS pdu if present */
            S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.length = item_p->nAS_PDU->size;

            S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.buffer =
            malloc(sizeof(uint8_t) * item_p->nAS_PDU->size);

            memcpy(&S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.buffer,
                   item_p->nAS_PDU->buf, item_p->nAS_PDU->size);
        } else {
            S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.length = 0;
            S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.buffer = NULL;
        }

421
422
423
424
425
426
427
428
429
        /* Set the transport layer address */
        memcpy(S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].sgw_addr.buffer,
               item_p->transportLayerAddress.buf, item_p->transportLayerAddress.size);
        S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].sgw_addr.length =
        item_p->transportLayerAddress.size * 8 - item_p->transportLayerAddress.bits_unused;

        /* GTP tunnel endpoint ID */
        OCTET_STRING_TO_INT32(&item_p->gTP_TEID, S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].gtp_teid);

430
431
432
433
434
435
436
437
438
439
440
441
        /* Set the QOS informations */
        S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].qos.qci = item_p->e_RABlevelQoSParameters.qCI;

        S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].qos.allocation_retention_priority.priority_level =
        item_p->e_RABlevelQoSParameters.allocationRetentionPriority.priorityLevel;
        S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].qos.allocation_retention_priority.pre_emp_capability =
        item_p->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionCapability;
        S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].qos.allocation_retention_priority.pre_emp_vulnerability =
        item_p->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionVulnerability;
    }

    itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p);
Cedric Roux's avatar
 
Cedric Roux committed
442
443
444

    return 0;
}