blob: 8c8fb861a1655d0f45acda232a26f0c13f6e6cd1 [file] [log] [blame]
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001/* main MSC management code... */
2
3/*
4 * (C) 2010,2013 by Holger Hans Peter Freyther <zecke@selfish.org>
5 * (C) 2010 by On-Waves
6 *
7 * All Rights Reserved
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
18 *
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 *
22 */
23
Neels Hofmeyr4ac80092019-03-04 02:46:37 +010024#include "config.h"
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010025
26#include <osmocom/core/tdef.h>
27
28#include <osmocom/msc/gsm_data.h>
29#include <osmocom/msc/vlr.h>
30#include <osmocom/msc/gsup_client_mux.h>
31#include <osmocom/msc/gsm_04_11_gsup.h>
32#include <osmocom/msc/gsm_09_11.h>
33
Vadim Yanitskiyffc7f392020-01-18 18:39:41 +070034/* TODO: would be great to have all timer declarations in one place */
35#include <osmocom/msc/ran_infra.h>
36#include <osmocom/msc/sccp_ran.h>
37#include <osmocom/msc/call_leg.h>
38
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010039struct osmo_tdef mncc_tdefs[] = {
40 {}
41};
42
Vadim Yanitskiyffc7f392020-01-18 18:39:41 +070043struct osmo_tdef_group msc_tdef_group[] = {
Vadim Yanitskiybaf71a72020-01-25 10:49:14 +070044 { .name = "vlr", .tdefs = msc_tdefs_vlr, .desc = "VLR (Visitors Location Register)" },
Vadim Yanitskiyffc7f392020-01-18 18:39:41 +070045 { .name = "mgw", .tdefs = g_mgw_tdefs, .desc = "MGW (Media Gateway) interface" },
46 { .name = "mncc", .tdefs = mncc_tdefs, .desc = "MNCC (Mobile Network Call Control) interface" },
47 { .name = "sccp", .tdefs = g_sccp_tdefs, .desc = "SCCP (Signalling Connection Control Part)" },
48 { .name = "geran", .tdefs = msc_tdefs_geran, .desc = "GERAN (GSM EDGE Radio Access Network)" },
49 { .name = "utran", .tdefs = msc_tdefs_utran, .desc = "UTRAN (UMTS Terrestrial Radio Access Network)" },
50 { .name = "sgs", .tdefs = msc_tdefs_sgs, .desc = "SGs interface towards MME" },
51 { /* terminator */ }
52};
53
Alexander Couzensefa7b972019-04-27 23:45:37 +020054#include <osmocom/core/stat_item.h>
55
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010056struct gsm_network *gsm_network_init(void *ctx, mncc_recv_cb_t mncc_recv)
57{
58 struct gsm_network *net;
59
60 net = talloc_zero(ctx, struct gsm_network);
61 if (!net)
62 return NULL;
63
64 net->plmn = (struct osmo_plmn_id){ .mcc=1, .mnc=1 };
65
66 /* Permit a compile-time default of A5/3 and A5/1 */
67 net->a5_encryption_mask = (1 << 3) | (1 << 1);
Neels Hofmeyr4dfb2ba2019-08-13 16:00:37 +020068 net->uea_encryption = true;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010069
70 /* Use 30 min periodic update interval as sane default */
71 net->t3212 = 5;
72
73 net->mncc_guard_timeout = 180;
74 net->ncss_guard_timeout = 30;
75
76 net->paging_response_timer = MSC_PAGING_RESPONSE_TIMER_DEFAULT;
77
78 INIT_LLIST_HEAD(&net->trans_list);
79 INIT_LLIST_HEAD(&net->upqueue);
80 INIT_LLIST_HEAD(&net->neighbor_ident_list);
81
82 /* init statistics */
83 net->msc_ctrs = rate_ctr_group_alloc(net, &msc_ctrg_desc, 0);
84 if (!net->msc_ctrs) {
85 talloc_free(net);
86 return NULL;
87 }
Alexander Couzensefa7b972019-04-27 23:45:37 +020088
89 net->statg = osmo_stat_item_group_alloc(net, &msc_statg_desc, 0);
90 if (!net->statg) {
91 rate_ctr_group_free(net->msc_ctrs);
92 talloc_free(net);
93 return NULL;
94 }
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010095
96 net->mncc_tdefs = mncc_tdefs;
97 net->mncc_recv = mncc_recv;
98
99 return net;
100}
101
102void gsm_network_set_mncc_sock_path(struct gsm_network *net, const char *mncc_sock_path)
103{
104 if (net->mncc_sock_path)
105 talloc_free(net->mncc_sock_path);
106 net->mncc_sock_path = mncc_sock_path ? talloc_strdup(net, mncc_sock_path) : NULL;
107}
108
109/* Allocate net->vlr so that the VTY may configure the VLR's data structures */
110int msc_vlr_alloc(struct gsm_network *net)
111{
112 net->vlr = vlr_alloc(net, &msc_vlr_ops);
113 if (!net->vlr)
114 return -ENOMEM;
115 net->vlr->user_ctx = net;
116 return 0;
117}
118
119/* Launch the VLR, i.e. its GSUP connection */
120int msc_vlr_start(struct gsm_network *net)
121{
122 OSMO_ASSERT(net->vlr);
123 OSMO_ASSERT(net->gcm);
124
125 return vlr_start(net->vlr, net->gcm);
126}
127
128int msc_gsup_client_start(struct gsm_network *net)
129{
130 struct ipaccess_unit *ipa_dev;
131
132 net->gcm = gsup_client_mux_alloc(net);
133 OSMO_ASSERT(net->gcm);
134
135 ipa_dev = talloc_zero(net->gcm, struct ipaccess_unit);
136 ipa_dev->unit_name = "MSC";
137 ipa_dev->serno = net->msc_ipa_name; /* NULL unless configured via VTY */
138 ipa_dev->swversion = PACKAGE_NAME "-" PACKAGE_VERSION;
139
140 *net->gcm = (struct gsup_client_mux){
141 .rx_cb = {
142 /* vlr.c sets up its own cb and data */
143 /* MSC-A and MSC-B set up their own cb and data */
Vadim Yanitskiy805eca22019-06-15 17:30:23 +0700144 [OSMO_GSUP_MESSAGE_CLASS_SMS] = { .func = gsm411_gsup_rx, .data = net },
145 [OSMO_GSUP_MESSAGE_CLASS_USSD] = { .func = gsm0911_gsup_rx, .data = net },
Neels Hofmeyrc4628a32018-12-07 14:47:34 +0100146 },
147 };
148
149 return gsup_client_mux_start(net->gcm, net->gsup_server_addr_str, net->gsup_server_port, ipa_dev);
150}