nas_main.c 6.77 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
/*******************************************************************************

  Eurecom OpenAirInterface
  Copyright(c) 1999 - 2013 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

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

Cedric Roux's avatar
 
Cedric Roux committed
31 32 33 34 35 36 37
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>

#include "intertask_interface.h"
38
#include "mme_config.h"
Cedric Roux's avatar
 
Cedric Roux committed
39 40 41 42

#include "nas_defs.h"

#if !defined(DISABLE_USE_NAS)
43
# include "nas_network.h"
Cedric Roux's avatar
 
Cedric Roux committed
44 45 46
# include "nas_proc.h"
# include "emm_main.h"
# include "nas_log.h"
47
# include "nas_timer.h"
Cedric Roux's avatar
 
Cedric Roux committed
48 49 50 51 52 53 54 55
#endif

#define NAS_ERROR(x, args...) do { fprintf(stderr, "[NAS] [E]"x, ##args); } while(0)
#define NAS_DEBUG(x, args...) do { fprintf(stdout, "[NAS] [D]"x, ##args); } while(0)
#define NAS_WARN(x, args...)  do { fprintf(stdout, "[NAS] [W]"x, ##args); } while(0)

static void *nas_intertask_interface(void *args_p)
{
56
    itti_mark_task_ready(TASK_NAS);
Cedric Roux's avatar
 
Cedric Roux committed
57 58 59 60 61

    while(1) {
        MessageDef *received_message_p;

next_message:
62
        itti_receive_msg(TASK_NAS, &received_message_p);
63

Cedric Roux's avatar
Cedric Roux committed
64 65
        switch (ITTI_MSG_ID(received_message_p))
        {
Cedric Roux's avatar
 
Cedric Roux committed
66 67 68 69 70 71 72 73
            case NAS_CONNECTION_ESTABLISHMENT_IND: {
#if defined(DISABLE_USE_NAS)
                MessageDef       *message_p;
                nas_attach_req_t *nas_req_p;
                s1ap_initial_ue_message_t *transparent;

                NAS_DEBUG("NAS abstraction: Generating NAS ATTACH REQ\n");

74
                message_p = itti_alloc_new_message(TASK_NAS, NAS_ATTACH_REQ);
Cedric Roux's avatar
 
Cedric Roux committed
75

76 77
                nas_req_p = &message_p->ittiMsg.nas_attach_req;
                transparent = &message_p->ittiMsg.nas_attach_req.transparent;
Cedric Roux's avatar
 
Cedric Roux committed
78 79 80 81

                nas_req_p->initial = INITIAL_REQUEST;
                sprintf(nas_req_p->imsi, "%14llu", 20834123456789ULL);

82
                memcpy(transparent, &received_message_p->ittiMsg.nas_conn_est_ind.transparent,
Cedric Roux's avatar
 
Cedric Roux committed
83 84
                       sizeof(s1ap_initial_ue_message_t));

85
                itti_send_msg_to_task(TASK_MME_APP, INSTANCE_DEFAULT, message_p);
Cedric Roux's avatar
 
Cedric Roux committed
86 87 88
#else
                nas_establish_ind_t *nas_est_ind_p;

89
                nas_est_ind_p = &received_message_p->ittiMsg.nas_conn_est_ind.nas;
Cedric Roux's avatar
 
Cedric Roux committed
90 91 92 93 94 95 96

                nas_proc_establish_ind(nas_est_ind_p->UEid,
                                       nas_est_ind_p->tac,
                                       nas_est_ind_p->initialNasMsg.data,
                                       nas_est_ind_p->initialNasMsg.length);
#endif
            } break;
97

98
#if defined(DISABLE_USE_NAS)
Cedric Roux's avatar
 
Cedric Roux committed
99
            case NAS_ATTACH_ACCEPT: {
100
                itti_send_msg_to_task(TASK_S1AP, INSTANCE_DEFAULT, received_message_p);
Cedric Roux's avatar
 
Cedric Roux committed
101 102
                goto next_message;
            } break;
103

Cedric Roux's avatar
 
Cedric Roux committed
104 105 106 107 108 109
            case NAS_AUTHENTICATION_REQ: {
                MessageDef      *message_p;
                nas_auth_resp_t *nas_resp_p;

                NAS_DEBUG("NAS abstraction: Generating NAS AUTHENTICATION RESPONSE\n");

110
                message_p = itti_alloc_new_message(TASK_NAS, NAS_AUTHENTICATION_RESP);
Cedric Roux's avatar
 
Cedric Roux committed
111

112
                nas_resp_p = &message_p->ittiMsg.nas_auth_resp;
Cedric Roux's avatar
 
Cedric Roux committed
113

114
                memcpy(nas_resp_p->imsi, received_message_p->ittiMsg.nas_auth_req.imsi, 16);
Cedric Roux's avatar
 
Cedric Roux committed
115

116
                itti_send_msg_to_task(TASK_MME_APP, INSTANCE_DEFAULT, message_p);
Cedric Roux's avatar
 
Cedric Roux committed
117
            } break;
118
#else
119 120 121 122 123 124 125
            case NAS_UPLINK_DATA_IND: {
                nas_proc_ul_transfer_ind(NAS_UL_DATA_IND(received_message_p).UEid,
                                         NAS_UL_DATA_IND(received_message_p).nasMsg.data,
                                         NAS_UL_DATA_IND(received_message_p).nasMsg.length);
            } break;

            case NAS_DOWNLINK_DATA_CNF: {
126
//                 nas_proc_dl_transfer_cnf(NAS_DL_DATA_CNF(received_message_p).UEid);
127
            } break;
128 129 130 131 132 133 134 135

            case NAS_AUTHENTICATION_PARAM_RSP: {
                nas_proc_auth_param_res(&NAS_AUTHENTICATION_PARAM_RSP(received_message_p));
            } break;

            case NAS_AUTHENTICATION_PARAM_FAIL: {
                nas_proc_auth_param_fail(&NAS_AUTHENTICATION_PARAM_FAIL(received_message_p));
            } break;
136
#endif
137

138 139 140 141 142 143 144 145
            case TIMER_HAS_EXPIRED: {
#if !defined(DISABLE_USE_NAS)
                /* Call the NAS timer api */
                nas_timer_handle_signal_expiry(TIMER_HAS_EXPIRED(received_message_p).timer_id,
                                               TIMER_HAS_EXPIRED(received_message_p).arg);
#endif
            } break;

146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
            case S1AP_ENB_DEREGISTERED_IND: {
#if !defined(DISABLE_USE_NAS)
                int i;
                for (i = 0; i < S1AP_ENB_DEREGISTERED_IND(received_message_p).nb_ue_to_deregister; i ++) {
                    nas_proc_deregister_ue(S1AP_ENB_DEREGISTERED_IND(received_message_p).mme_ue_s1ap_id[i]);
                }
#endif
            } break;

            case S1AP_DEREGISTER_UE_REQ: {
#if !defined(DISABLE_USE_NAS)
                nas_proc_deregister_ue(S1AP_DEREGISTER_UE_REQ(received_message_p).mme_ue_s1ap_id);
#endif
            } break;

161 162 163
            case TERMINATE_MESSAGE: {
                itti_exit_task();
            } break;
164

Cedric Roux's avatar
 
Cedric Roux committed
165
            default: {
Cedric Roux's avatar
Cedric Roux committed
166 167 168
                NAS_DEBUG("Unkwnon message ID %d:%s\n",
                          ITTI_MSG_ID(received_message_p),
                          ITTI_MSG_NAME(received_message_p));
Cedric Roux's avatar
 
Cedric Roux committed
169 170
            } break;
        }
171
        itti_free(ITTI_MSG_ORIGIN_ID(received_message_p), received_message_p);
Cedric Roux's avatar
 
Cedric Roux committed
172 173 174 175 176
        received_message_p = NULL;
    }
    return NULL;
}

177
int nas_init(mme_config_t *mme_config_p)
Cedric Roux's avatar
 
Cedric Roux committed
178 179
{
    NAS_DEBUG("Initializing NAS task interface\n");
180

Cedric Roux's avatar
 
Cedric Roux committed
181
#if !defined(DISABLE_USE_NAS)
182
    nas_log_init(0x2F);
183
    nas_network_initialize(mme_config_p);
Cedric Roux's avatar
 
Cedric Roux committed
184 185
#endif

186
    if (itti_create_task(TASK_NAS, &nas_intertask_interface,
Cedric Roux's avatar
 
Cedric Roux committed
187 188 189 190 191 192 193 194
                                        NULL) < 0) {
        NAS_ERROR("Create task failed");
        NAS_DEBUG("Initializing NAS task interface: FAILED\n");
        return -1;
    }
    NAS_DEBUG("Initializing NAS task interface: DONE\n");
    return 0;
}