s6a_task.c 5.27 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
40
41
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
/*******************************************************************************

  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

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

#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>

#if HAVE_CONFIG_H
# include "config.h"
#endif

#include <freeDiameter/freeDiameter-host.h>
#include <freeDiameter/libfdcore.h>

#include "intertask_interface.h"
#include "s6a_defs.h"
#include "s6a_messages.h"

#include "assertions.h"

#if defined(DISABLE_USE_HSS)
# error "Disabling HSS support is currently not supported   \
    Reconfigure with --enable-hss option to disable this error"
#endif

static int gnutls_debug = 0;
struct session_handler *ts_sess_hdl;

s6a_fd_cnf_t s6a_fd_cnf;

void *s6a_thread(void *args);
static void fd_gnutls_debug(int level, const char *str);

static void fd_gnutls_debug(int level, const char *str)
{
    S6A_DEBUG("[GTLS] %s", str);
}

void *s6a_thread(void *args)
{
70
    itti_mark_task_ready(TASK_S6A);
Cedric Roux's avatar
 
Cedric Roux committed
71
72
73
74
75
76
77

    while(1) {
        MessageDef *received_message_p = NULL;
        /* Trying to fetch a message from the message queue.
         * If the queue is empty, this function will block till a
         * message is sent to the task.
         */
78
        itti_receive_msg(TASK_S6A, &received_message_p);
Cedric Roux's avatar
 
Cedric Roux committed
79
        DevAssert(received_message_p != NULL);
Cedric Roux's avatar
Cedric Roux committed
80
81
82

        switch (ITTI_MSG_ID(received_message_p))
        {
Cedric Roux's avatar
 
Cedric Roux committed
83
            case S6A_UPDATE_LOCATION_REQ: {
84
                s6a_generate_update_location(&received_message_p->ittiMsg.s6a_update_location_req);
Cedric Roux's avatar
 
Cedric Roux committed
85
86
            } break;
            case S6A_AUTH_INFO_REQ: {
87
                s6a_generate_authentication_info_req(&received_message_p->ittiMsg.s6a_auth_info_req);
Cedric Roux's avatar
 
Cedric Roux committed
88
            } break;
89
90
91
            case TERMINATE_MESSAGE: {
                itti_exit_task();
            } break;
Cedric Roux's avatar
 
Cedric Roux committed
92
            default: {
Cedric Roux's avatar
Cedric Roux committed
93
94
                S6A_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
95
96
            } break;
        }
97
        itti_free(ITTI_MSG_ORIGIN_ID(received_message_p), received_message_p);
Cedric Roux's avatar
 
Cedric Roux committed
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
        received_message_p = NULL;
    }
    return NULL;
}

int s6a_init(const mme_config_t *mme_config_p)
{
    int ret;

    S6A_DEBUG("Initializing S6a interface\n");

    memset(&s6a_fd_cnf, 0, sizeof(s6a_fd_cnf_t));

    if (strcmp(fd_core_version(), FREE_DIAMETER_MINIMUM_VERSION) != 0) {
        S6A_ERROR("Freediameter version %s fount, expecting %s\n", fd_core_version(),
                  FREE_DIAMETER_MINIMUM_VERSION);
        return -1;
    } else {
        S6A_DEBUG("Freediameter version %s\n", fd_core_version());
    }

    /* Initializing freeDiameter core */
gauthier's avatar
traces    
gauthier committed
120
    S6A_DEBUG("Initializing freeDiameter core...\n");
Cedric Roux's avatar
 
Cedric Roux committed
121
122
123
124
    ret = fd_core_initialize();
    if (ret != 0) {
        S6A_ERROR("An error occurred during freeDiameter core library initialization\n");
        return ret;
gauthier's avatar
traces    
gauthier committed
125
126
    } else {
        S6A_DEBUG("Initializing freeDiameter core done\n");
Cedric Roux's avatar
 
Cedric Roux committed
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
    }

    /* Set gnutls debug level ? */
    if (gnutls_debug) {
        gnutls_global_set_log_function((gnutls_log_func)fd_gnutls_debug);
        gnutls_global_set_log_level (gnutls_debug);
        S6A_DEBUG("Enabled GNUTLS debug at level %d", gnutls_debug);
    }

    /* Starting freeDiameter core */
    ret = fd_core_start();
    if (ret != 0) {
        S6A_ERROR("An error occurred during freeDiameter core library start\n");
        return ret;
    }

    S6A_DEBUG("Default ext path: %s\n", DEFAULT_EXTENSIONS_PATH);

    ret = fd_core_parseconf(mme_config_p->s6a_config.conf_file);
    if (ret != 0) {
gauthier's avatar
gauthier committed
147
        S6A_ERROR("An error occurred during fd_core_parseconf file :%s.\n", mme_config_p->s6a_config.conf_file);
Cedric Roux's avatar
 
Cedric Roux committed
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
        return ret;
    }

    ret = fd_core_waitstartcomplete();
    if (ret != 0) {
        S6A_ERROR("An error occurred during fd_core_waitstartcomplete.\n");
        return ret;
    }

    ret = s6a_fd_init_dict_objs();
    if (ret != 0) {
        S6A_ERROR("An error occurred during s6a_fd_init_dict_objs.\n");
        return ret;
    }

    /* Trying to connect to peers */
    CHECK_FCT(s6a_fd_new_peer());

166
    if (itti_create_task(TASK_S6A, &s6a_thread, NULL) < 0) {
Cedric Roux's avatar
 
Cedric Roux committed
167
168
169
170
171
172
173
        S6A_ERROR("s6a create task\n");
        return -1;
    }
    S6A_DEBUG("Initializing S6a interface: DONE\n");

    return 0;
}