s6a_peer.c 4.39 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
/*******************************************************************************

  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

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

/*! \file s6a_peers.c
 * \brief Add a new entity to the list of peers to connect
 * \author Sebastien ROUX <sebastien.roux@eurecom.fr>
 * \date 2013
 * \version 0.1
 */

#include <stdint.h>
#include <unistd.h>

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

#include "assertions.h"

void s6a_peer_connected_cb(struct peer_info *info, void *arg)
{
    if (info == NULL) {
        S6A_ERROR("Failed to connect to HSS entity\n");
    } else {
53
54
        MessageDef     *message_p;

Cedric Roux's avatar
 
Cedric Roux committed
55
56
        S6A_DEBUG("Peer %*s is now connected...\n",
                (int)info->pi_diamidlen, info->pi_diamid);
57
58
59
60
61

        /* Inform S1AP that connection to HSS is established */
        message_p = itti_alloc_new_message(TASK_S6A, ACTIVATE_MESSAGE);

        itti_send_msg_to_task(TASK_S1AP, INSTANCE_DEFAULT, message_p);
Cedric Roux's avatar
 
Cedric Roux committed
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
    }

    /* For test */
#if 0
    s6a_auth_info_req_t s6a_air;

    memset(&s6a_air, 0, sizeof(s6a_auth_info_req_t));
    sprintf(s6a_air.imsi, "%14llu", 20834123456789ULL);

    s6a_air.nb_of_vectors = 1;
    s6a_air.visited_plmn.MCCdigit2 = 0,
    s6a_air.visited_plmn.MCCdigit1 = 8,
    s6a_air.visited_plmn.MCCdigit3 = 2,
    s6a_air.visited_plmn.MNCdigit1 = 0,
    s6a_air.visited_plmn.MNCdigit2 = 3,
    s6a_air.visited_plmn.MNCdigit3 = 4,

    s6a_generate_authentication_info_req(&s6a_air);
// #else
//     s6a_update_location_req_t s6a_ulr;
// 
//     memset(&s6a_ulr, 0, sizeof(s6a_update_location_req_t));
// 
//     sprintf(s6a_ulr.imsi, "%14llu", 20834123456789ULL);
//     s6a_ulr.initial_attach = INITIAL_ATTACH;
//     s6a_ulr.rat_type = RAT_EUTRAN;
//     s6a_generate_update_location(&s6a_ulr);
#endif
}

int s6a_fd_new_peer(void)
{
    char host_name[100];
    size_t host_name_len;
    char *hss_name;

    int ret = 0;
    struct peer_info info;

    memset(&info, 0, sizeof(struct peer_info));

    if (config_read_lock(&mme_config) != 0) {
        S6A_ERROR("Failed to lock configuration for reading\n");
        return -1;
    }

    if(fd_g_config->cnf_diamid != NULL) {
        free(fd_g_config->cnf_diamid);
        fd_g_config->cnf_diamid_len = 0;
    }

    DevAssert(gethostname(host_name, 100) == 0);

    host_name_len = strlen(host_name);
    host_name[host_name_len]   = '.';
    host_name[host_name_len+1] = '\0';

    strcat(host_name, mme_config.realm);
    fd_g_config->cnf_diamid = strdup(host_name);
    fd_g_config->cnf_diamid_len = strlen(fd_g_config->cnf_diamid);

    S6A_DEBUG("Diameter identity of MME: %s with length: %zd\n",
              fd_g_config->cnf_diamid, fd_g_config->cnf_diamid_len);

gauthier's avatar
gauthier committed
126
127
    hss_name = calloc(1,100);
    strcat(hss_name, "hss.");
Cedric Roux's avatar
 
Cedric Roux committed
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
    strcat(hss_name, mme_config.realm);
    info.pi_diamid = hss_name;
    info.pi_diamidlen = strlen(info.pi_diamid);

    S6A_DEBUG("Diameter identity of HSS: %s with length: %zd\n",
              info.pi_diamid, info.pi_diamidlen);

    info.config.pic_flags.sec  = PI_SEC_NONE;
    info.config.pic_flags.pro4 = PI_P4_SCTP;

    info.config.pic_flags.persist = PI_PRST_NONE;

    CHECK_FCT(fd_peer_add(&info, "", s6a_peer_connected_cb, NULL));

    if (config_unlock(&mme_config) != 0) {
        S6A_ERROR("Failed to unlock configuration\n");
        return -1;
    }

    return ret;
}