nas_main.c 4.22 KB
Newer Older
Cedric Roux's avatar
 
Cedric Roux committed
1 2 3 4 5 6 7
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>

#include "intertask_interface.h"
8
#include "mme_config.h"
Cedric Roux's avatar
 
Cedric Roux committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

#include "nas_defs.h"

#if !defined(DISABLE_USE_NAS)
# include "nas_proc.h"
# include "emm_main.h"
# include "nas_log.h"
#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)
{
24
    itti_mark_task_ready(TASK_NAS);
Cedric Roux's avatar
 
Cedric Roux committed
25 26 27 28 29

    while(1) {
        MessageDef *received_message_p;

next_message:
30
        itti_receive_msg(TASK_NAS, &received_message_p);
Cedric Roux's avatar
Cedric Roux committed
31 32
        switch (ITTI_MSG_ID(received_message_p))
        {
Cedric Roux's avatar
 
Cedric Roux committed
33 34 35 36 37 38 39 40
            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");

41
                message_p = itti_alloc_new_message(TASK_NAS, NAS_ATTACH_REQ);
Cedric Roux's avatar
 
Cedric Roux committed
42

43 44
                nas_req_p = &message_p->ittiMsg.nas_attach_req;
                transparent = &message_p->ittiMsg.nas_attach_req.transparent;
Cedric Roux's avatar
 
Cedric Roux committed
45 46 47 48

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

49
                memcpy(transparent, &received_message_p->ittiMsg.nas_conn_est_ind.transparent,
Cedric Roux's avatar
 
Cedric Roux committed
50 51
                       sizeof(s1ap_initial_ue_message_t));

52
                itti_send_msg_to_task(TASK_MME_APP, INSTANCE_DEFAULT, message_p);
Cedric Roux's avatar
 
Cedric Roux committed
53 54 55
#else
                nas_establish_ind_t *nas_est_ind_p;

56
                nas_est_ind_p = &received_message_p->ittiMsg.nas_conn_est_ind.nas;
Cedric Roux's avatar
 
Cedric Roux committed
57 58 59 60 61 62 63

                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;
64

Cedric Roux's avatar
 
Cedric Roux committed
65
            case NAS_ATTACH_ACCEPT: {
66
                itti_send_msg_to_task(TASK_S1AP, INSTANCE_DEFAULT, received_message_p);
Cedric Roux's avatar
 
Cedric Roux committed
67 68
                goto next_message;
            } break;
69

Cedric Roux's avatar
 
Cedric Roux committed
70 71 72 73 74 75
            case NAS_AUTHENTICATION_REQ: {
                MessageDef      *message_p;
                nas_auth_resp_t *nas_resp_p;

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

76
                message_p = itti_alloc_new_message(TASK_NAS, NAS_AUTHENTICATION_RESP);
Cedric Roux's avatar
 
Cedric Roux committed
77

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

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

82
                itti_send_msg_to_task(TASK_MME_APP, INSTANCE_DEFAULT, message_p);
Cedric Roux's avatar
 
Cedric Roux committed
83
            } break;
84 85 86 87 88 89 90 91 92 93 94

            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: {
                nas_proc_dl_transfer_cnf(NAS_DL_DATA_CNF(received_message_p).UEid);
            } break;

95 96 97
            case TERMINATE_MESSAGE: {
                itti_exit_task();
            } break;
98

Cedric Roux's avatar
 
Cedric Roux committed
99
            default: {
Cedric Roux's avatar
Cedric Roux committed
100 101 102
                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
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
            } break;
        }
        free(received_message_p);
        received_message_p = NULL;
    }
    return NULL;
}

int nas_init(const mme_config_t *mme_config_p)
{
    NAS_DEBUG("Initializing NAS task interface\n");
#if !defined(DISABLE_USE_NAS)
    nas_log_init(LOG_DEBUG);
    emm_main_initialize();
#endif

119
    if (itti_create_task(TASK_NAS, &nas_intertask_interface,
Cedric Roux's avatar
 
Cedric Roux committed
120 121 122 123 124 125 126 127
                                        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;
}