blob: 637ee74ea1fe1c9bfb25f29a08b3e334b52f4d3b [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
34struct osmo_tdef mncc_tdefs[] = {
35 {}
36};
37
38struct gsm_network *gsm_network_init(void *ctx, mncc_recv_cb_t mncc_recv)
39{
40 struct gsm_network *net;
41
42 net = talloc_zero(ctx, struct gsm_network);
43 if (!net)
44 return NULL;
45
46 net->plmn = (struct osmo_plmn_id){ .mcc=1, .mnc=1 };
47
48 /* Permit a compile-time default of A5/3 and A5/1 */
49 net->a5_encryption_mask = (1 << 3) | (1 << 1);
50
51 /* Use 30 min periodic update interval as sane default */
52 net->t3212 = 5;
53
54 net->mncc_guard_timeout = 180;
55 net->ncss_guard_timeout = 30;
56
57 net->paging_response_timer = MSC_PAGING_RESPONSE_TIMER_DEFAULT;
58
59 INIT_LLIST_HEAD(&net->trans_list);
60 INIT_LLIST_HEAD(&net->upqueue);
61 INIT_LLIST_HEAD(&net->neighbor_ident_list);
62
63 /* init statistics */
64 net->msc_ctrs = rate_ctr_group_alloc(net, &msc_ctrg_desc, 0);
65 if (!net->msc_ctrs) {
66 talloc_free(net);
67 return NULL;
68 }
69 net->active_calls = osmo_counter_alloc("msc.active_calls");
70 net->active_nc_ss = osmo_counter_alloc("msc.active_nc_ss");
71
72 net->mncc_tdefs = mncc_tdefs;
73 net->mncc_recv = mncc_recv;
74
75 return net;
76}
77
78void gsm_network_set_mncc_sock_path(struct gsm_network *net, const char *mncc_sock_path)
79{
80 if (net->mncc_sock_path)
81 talloc_free(net->mncc_sock_path);
82 net->mncc_sock_path = mncc_sock_path ? talloc_strdup(net, mncc_sock_path) : NULL;
83}
84
85/* Allocate net->vlr so that the VTY may configure the VLR's data structures */
86int msc_vlr_alloc(struct gsm_network *net)
87{
88 net->vlr = vlr_alloc(net, &msc_vlr_ops);
89 if (!net->vlr)
90 return -ENOMEM;
91 net->vlr->user_ctx = net;
92 return 0;
93}
94
95/* Launch the VLR, i.e. its GSUP connection */
96int msc_vlr_start(struct gsm_network *net)
97{
98 OSMO_ASSERT(net->vlr);
99 OSMO_ASSERT(net->gcm);
100
101 return vlr_start(net->vlr, net->gcm);
102}
103
104int msc_gsup_client_start(struct gsm_network *net)
105{
106 struct ipaccess_unit *ipa_dev;
107
108 net->gcm = gsup_client_mux_alloc(net);
109 OSMO_ASSERT(net->gcm);
110
111 ipa_dev = talloc_zero(net->gcm, struct ipaccess_unit);
112 ipa_dev->unit_name = "MSC";
113 ipa_dev->serno = net->msc_ipa_name; /* NULL unless configured via VTY */
114 ipa_dev->swversion = PACKAGE_NAME "-" PACKAGE_VERSION;
115
116 *net->gcm = (struct gsup_client_mux){
117 .rx_cb = {
118 /* vlr.c sets up its own cb and data */
119 /* MSC-A and MSC-B set up their own cb and data */
120 [OSMO_GSUP_MESSAGE_CLASS_SMS] = { .func = gsm411_gsup_rx, .data = net->vlr },
121 [OSMO_GSUP_MESSAGE_CLASS_USSD] = { .func = gsm0911_gsup_rx, .data = net->vlr },
122 },
123 };
124
125 return gsup_client_mux_start(net->gcm, net->gsup_server_addr_str, net->gsup_server_port, ipa_dev);
126}