Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 1 | /* 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 Hofmeyr | 4ac8009 | 2019-03-04 02:46:37 +0100 | [diff] [blame] | 24 | #include "config.h" |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 25 | |
| 26 | #include <osmocom/core/tdef.h> |
Alexander Couzens | 8b7d785 | 2021-11-05 01:52:05 +0100 | [diff] [blame] | 27 | #include <osmocom/crypt/utran_cipher.h> |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 28 | |
| 29 | #include <osmocom/msc/gsm_data.h> |
| 30 | #include <osmocom/msc/vlr.h> |
| 31 | #include <osmocom/msc/gsup_client_mux.h> |
| 32 | #include <osmocom/msc/gsm_04_11_gsup.h> |
| 33 | #include <osmocom/msc/gsm_09_11.h> |
| 34 | |
Vadim Yanitskiy | ffc7f39 | 2020-01-18 18:39:41 +0700 | [diff] [blame] | 35 | /* TODO: would be great to have all timer declarations in one place */ |
| 36 | #include <osmocom/msc/ran_infra.h> |
| 37 | #include <osmocom/msc/sccp_ran.h> |
| 38 | #include <osmocom/msc/call_leg.h> |
| 39 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 40 | struct osmo_tdef mncc_tdefs[] = { |
| 41 | {} |
| 42 | }; |
| 43 | |
Vadim Yanitskiy | ffc7f39 | 2020-01-18 18:39:41 +0700 | [diff] [blame] | 44 | struct osmo_tdef_group msc_tdef_group[] = { |
Vadim Yanitskiy | baf71a7 | 2020-01-25 10:49:14 +0700 | [diff] [blame] | 45 | { .name = "vlr", .tdefs = msc_tdefs_vlr, .desc = "VLR (Visitors Location Register)" }, |
Vadim Yanitskiy | ffc7f39 | 2020-01-18 18:39:41 +0700 | [diff] [blame] | 46 | { .name = "mgw", .tdefs = g_mgw_tdefs, .desc = "MGW (Media Gateway) interface" }, |
| 47 | { .name = "mncc", .tdefs = mncc_tdefs, .desc = "MNCC (Mobile Network Call Control) interface" }, |
| 48 | { .name = "sccp", .tdefs = g_sccp_tdefs, .desc = "SCCP (Signalling Connection Control Part)" }, |
| 49 | { .name = "geran", .tdefs = msc_tdefs_geran, .desc = "GERAN (GSM EDGE Radio Access Network)" }, |
| 50 | { .name = "utran", .tdefs = msc_tdefs_utran, .desc = "UTRAN (UMTS Terrestrial Radio Access Network)" }, |
| 51 | { .name = "sgs", .tdefs = msc_tdefs_sgs, .desc = "SGs interface towards MME" }, |
| 52 | { /* terminator */ } |
| 53 | }; |
| 54 | |
Alexander Couzens | efa7b97 | 2019-04-27 23:45:37 +0200 | [diff] [blame] | 55 | #include <osmocom/core/stat_item.h> |
| 56 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 57 | struct gsm_network *gsm_network_init(void *ctx, mncc_recv_cb_t mncc_recv) |
| 58 | { |
| 59 | struct gsm_network *net; |
| 60 | |
| 61 | net = talloc_zero(ctx, struct gsm_network); |
| 62 | if (!net) |
| 63 | return NULL; |
| 64 | |
| 65 | net->plmn = (struct osmo_plmn_id){ .mcc=1, .mnc=1 }; |
| 66 | |
| 67 | /* Permit a compile-time default of A5/3 and A5/1 */ |
| 68 | net->a5_encryption_mask = (1 << 3) | (1 << 1); |
Harald Welte | 505a94a | 2021-02-06 17:12:20 +0100 | [diff] [blame] | 69 | /* Permit a compile-time default of UEA2 and UEA1 */ |
Alexander Couzens | 8b7d785 | 2021-11-05 01:52:05 +0100 | [diff] [blame] | 70 | net->uea_encryption_mask = (1 << OSMO_UTRAN_UEA2) | (1 << OSMO_UTRAN_UEA1); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 71 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 72 | net->mncc_guard_timeout = 180; |
| 73 | net->ncss_guard_timeout = 30; |
| 74 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 75 | INIT_LLIST_HEAD(&net->trans_list); |
| 76 | INIT_LLIST_HEAD(&net->upqueue); |
| 77 | INIT_LLIST_HEAD(&net->neighbor_ident_list); |
Andreas Eversberg | cd605f3 | 2023-06-21 15:03:37 +0200 | [diff] [blame] | 78 | INIT_LLIST_HEAD(&net->asci.gcr_lists); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 79 | |
| 80 | /* init statistics */ |
| 81 | net->msc_ctrs = rate_ctr_group_alloc(net, &msc_ctrg_desc, 0); |
| 82 | if (!net->msc_ctrs) { |
| 83 | talloc_free(net); |
| 84 | return NULL; |
| 85 | } |
Alexander Couzens | efa7b97 | 2019-04-27 23:45:37 +0200 | [diff] [blame] | 86 | |
| 87 | net->statg = osmo_stat_item_group_alloc(net, &msc_statg_desc, 0); |
| 88 | if (!net->statg) { |
| 89 | rate_ctr_group_free(net->msc_ctrs); |
| 90 | talloc_free(net); |
| 91 | return NULL; |
| 92 | } |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 93 | |
| 94 | net->mncc_tdefs = mncc_tdefs; |
| 95 | net->mncc_recv = mncc_recv; |
| 96 | |
| 97 | return net; |
| 98 | } |
| 99 | |
| 100 | void gsm_network_set_mncc_sock_path(struct gsm_network *net, const char *mncc_sock_path) |
| 101 | { |
| 102 | if (net->mncc_sock_path) |
| 103 | talloc_free(net->mncc_sock_path); |
| 104 | net->mncc_sock_path = mncc_sock_path ? talloc_strdup(net, mncc_sock_path) : NULL; |
| 105 | } |
| 106 | |
| 107 | /* Allocate net->vlr so that the VTY may configure the VLR's data structures */ |
| 108 | int msc_vlr_alloc(struct gsm_network *net) |
| 109 | { |
| 110 | net->vlr = vlr_alloc(net, &msc_vlr_ops); |
| 111 | if (!net->vlr) |
| 112 | return -ENOMEM; |
| 113 | net->vlr->user_ctx = net; |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | /* Launch the VLR, i.e. its GSUP connection */ |
| 118 | int msc_vlr_start(struct gsm_network *net) |
| 119 | { |
| 120 | OSMO_ASSERT(net->vlr); |
| 121 | OSMO_ASSERT(net->gcm); |
| 122 | |
| 123 | return vlr_start(net->vlr, net->gcm); |
| 124 | } |
| 125 | |
| 126 | int msc_gsup_client_start(struct gsm_network *net) |
| 127 | { |
| 128 | struct ipaccess_unit *ipa_dev; |
| 129 | |
| 130 | net->gcm = gsup_client_mux_alloc(net); |
| 131 | OSMO_ASSERT(net->gcm); |
| 132 | |
| 133 | ipa_dev = talloc_zero(net->gcm, struct ipaccess_unit); |
| 134 | ipa_dev->unit_name = "MSC"; |
| 135 | ipa_dev->serno = net->msc_ipa_name; /* NULL unless configured via VTY */ |
| 136 | ipa_dev->swversion = PACKAGE_NAME "-" PACKAGE_VERSION; |
| 137 | |
| 138 | *net->gcm = (struct gsup_client_mux){ |
| 139 | .rx_cb = { |
| 140 | /* vlr.c sets up its own cb and data */ |
| 141 | /* MSC-A and MSC-B set up their own cb and data */ |
Vadim Yanitskiy | 805eca2 | 2019-06-15 17:30:23 +0700 | [diff] [blame] | 142 | [OSMO_GSUP_MESSAGE_CLASS_SMS] = { .func = gsm411_gsup_rx, .data = net }, |
| 143 | [OSMO_GSUP_MESSAGE_CLASS_USSD] = { .func = gsm0911_gsup_rx, .data = net }, |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 144 | }, |
| 145 | }; |
| 146 | |
| 147 | return gsup_client_mux_start(net->gcm, net->gsup_server_addr_str, net->gsup_server_port, ipa_dev); |
| 148 | } |