blob: 43ace2532277f8b5eb774a5b54250d1f28a1e366 [file] [log] [blame]
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +08001/*
2 * Data for the true BSC
3 *
Holger Hans Peter Freyther32dd2f32015-04-01 18:15:48 +02004 * (C) 2010-2015 by Holger Hans Peter Freyther <zecke@selfish.org>
5 * (C) 2010-2015 by On-Waves
Harald Welte68e4be92018-05-26 22:42:29 +02006 * (C) 2018 by Harald Welte <laforge@gnumonks.org>
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +08007 * All Rights Reserved
8 *
9 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +010010 * 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
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +080012 * (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
Harald Welte9af6ddf2011-01-01 15:25:50 +010017 * GNU Affero General Public License for more details.
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +080018 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010019 * 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/>.
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +080021 *
22 */
23
Neels Hofmeyr9762b4c2017-02-23 21:41:20 +010024/*
25 * NOTE: This is about a *remote* MSC for OsmoBSC and is not part of libmsc.
26 */
27
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +080028#ifndef _OSMO_MSC_DATA_H
29#define _OSMO_MSC_DATA_H
30
Harald Welte584ab8e2018-05-25 17:35:54 +020031#include "debug.h"
Pau Espin Pedrol2cfd0002019-03-12 18:53:26 +010032#include "osmo_bsc_lcls.h"
Pau Espin Pedrol6c548dc2019-04-16 20:01:47 +020033#include "osmux.h"
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +080034
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010035#include <osmocom/core/timer.h>
Harald Welte1626f902018-05-26 22:56:59 +020036#include <osmocom/core/select.h>
Holger Hans Peter Freyther25aa7492011-08-06 07:00:52 +020037#include <osmocom/gsm/protocol/gsm_04_08.h>
Holger Hans Peter Freyther5832b3e2010-09-16 02:14:41 +080038
Philipp Maier39f62bb2017-04-09 12:32:51 +020039
40#include <osmocom/sigtran/osmo_ss7.h>
41#include <osmocom/sigtran/sccp_sap.h>
42#include <osmocom/sigtran/sccp_helpers.h>
43#include <osmocom/sigtran/protocol/sua.h>
44#include <osmocom/sigtran/protocol/m3ua.h>
45#include <osmocom/core/fsm.h>
Neels Hofmeyrf93970b2018-03-05 02:09:40 +010046#include <osmocom/gsm/gsm23003.h>
Philipp Maier39f62bb2017-04-09 12:32:51 +020047
Harald Welte584ab8e2018-05-25 17:35:54 +020048#include <errno.h>
Holger Hans Peter Freyther83d2d382011-06-09 17:37:04 +020049
Holger Hans Peter Freyther9a8b5ae2010-09-15 23:53:54 +080050struct osmo_bsc_rf;
Holger Hans Peter Freyther620c2e62010-11-14 20:38:06 +010051struct gsm_network;
Holger Hans Peter Freyther9a8b5ae2010-09-15 23:53:54 +080052
Alexander Chemerise26b1532020-05-08 02:37:47 +030053/* Constants for the MSC rate counters */
54enum {
Alexander Chemeris98824b82020-05-09 21:27:40 +030055 /* Rx message counters */
Alexander Chemerise26b1532020-05-08 02:37:47 +030056 MSC_CTR_BSSMAP_RX_UDT_RESET_ACKNOWLEDGE,
57 MSC_CTR_BSSMAP_RX_UDT_RESET,
58 MSC_CTR_BSSMAP_RX_UDT_PAGING,
59 MSC_CTR_BSSMAP_RX_UDT_UNKNOWN,
60 MSC_CTR_BSSMAP_RX_DT1_CLEAR_CMD,
61 MSC_CTR_BSSMAP_RX_DT1_CIPHER_MODE_CMD,
62 MSC_CTR_BSSMAP_RX_DT1_ASSIGMENT_RQST,
63 MSC_CTR_BSSMAP_RX_DT1_LCLS_CONNECT_CTRL,
64 MSC_CTR_BSSMAP_RX_DT1_HANDOVER_CMD,
65 MSC_CTR_BSSMAP_RX_DT1_CLASSMARK_RQST,
Alexander Chemeris3a656da2020-05-13 00:47:03 +030066 MSC_CTR_BSSMAP_RX_DT1_CONFUSION,
Harald Welte210aa952020-06-21 18:00:23 +020067 MSC_CTR_BSSMAP_RX_DT1_COMMON_ID,
Alexander Chemerise26b1532020-05-08 02:37:47 +030068 MSC_CTR_BSSMAP_RX_DT1_UNKNOWN,
Alexander Chemerisaac54232020-05-10 01:49:34 +030069 MSC_CTR_BSSMAP_RX_DT1_DTAP,
70 MSC_CTR_BSSMAP_RX_DT1_DTAP_ERROR,
Alexander Chemeris98824b82020-05-09 21:27:40 +030071
72 /* Tx message counters (per connection type) */
73 MSC_CTR_BSSMAP_TX_BSS_MANAGEMENT,
74 MSC_CTR_BSSMAP_TX_DTAP,
75 MSC_CTR_BSSMAP_TX_UNKNOWN,
76 MSC_CTR_BSSMAP_TX_SHORT,
77 MSC_CTR_BSSMAP_TX_ERR_CONN_NOT_READY,
78 MSC_CTR_BSSMAP_TX_ERR_SEND,
79 MSC_CTR_BSSMAP_TX_SUCCESS,
80
81 /* Tx message counters (per message type) */
82 MSC_CTR_BSSMAP_TX_UDT_RESET,
83 MSC_CTR_BSSMAP_TX_UDT_RESET_ACK,
84 MSC_CTR_BSSMAP_TX_DT1_CLEAR_RQST,
85 MSC_CTR_BSSMAP_TX_DT1_CLEAR_COMPLETE,
86 MSC_CTR_BSSMAP_TX_DT1_ASSIGMENT_FAILURE,
87 MSC_CTR_BSSMAP_TX_DT1_ASSIGMENT_COMPLETE,
88 MSC_CTR_BSSMAP_TX_DT1_SAPI_N_REJECT,
89 MSC_CTR_BSSMAP_TX_DT1_CIPHER_COMPLETE,
90 MSC_CTR_BSSMAP_TX_DT1_CIPHER_REJECT,
91 MSC_CTR_BSSMAP_TX_DT1_CLASSMARK_UPDATE,
92 MSC_CTR_BSSMAP_TX_DT1_LCLS_CONNECT_CTRL_ACK,
93 MSC_CTR_BSSMAP_TX_DT1_HANDOVER_REQUIRED,
94 MSC_CTR_BSSMAP_TX_DT1_HANDOVER_PERFORMED,
95 MSC_CTR_BSSMAP_TX_DT1_HANDOVER_RQST_ACKNOWLEDGE,
96 MSC_CTR_BSSMAP_TX_DT1_HANDOVER_DETECT,
97 MSC_CTR_BSSMAP_TX_DT1_HANDOVER_COMPLETE,
98 MSC_CTR_BSSMAP_TX_DT1_HANDOVER_FAILURE,
99 MSC_CTR_BSSMAP_TX_DT1_DTAP,
Neels Hofmeyr1c963eb2020-06-16 12:08:39 +0200100
101 MSC_CTR_MSCPOOL_SUBSCR_NEW,
102 MSC_CTR_MSCPOOL_SUBSCR_REATTACH,
103 MSC_CTR_MSCPOOL_SUBSCR_KNOWN,
104 MSC_CTR_MSCPOOL_SUBSCR_PAGED,
105 MSC_CTR_MSCPOOL_SUBSCR_ATTACH_LOST,
106 MSC_CTR_MSCPOOL_EMERG_FORWARDED,
Alexander Chemerise26b1532020-05-08 02:37:47 +0300107};
108
Alexander Chemeris5e893332020-05-07 16:41:26 +0300109/* Constants for the MSC stats */
110enum {
111 MSC_STAT_MSC_LINKS_ACTIVE,
112 MSC_STAT_MSC_LINKS_TOTAL,
113};
114
Neels Hofmeyr9762b4c2017-02-23 21:41:20 +0100115/*! /brief Information on a remote MSC for libbsc.
116 */
Neels Hofmeyra369e242017-02-23 21:57:23 +0100117struct bsc_msc_data {
Holger Hans Peter Freyther20fea242011-06-04 19:58:26 +0200118 struct llist_head entry;
119
Daniel Willmann163f6122011-03-03 13:48:28 +0100120 /* Back pointer */
121 struct gsm_network *network;
122
Holger Hans Peter Freyther18fa70a2011-06-08 19:25:38 +0200123 int allow_emerg;
Holger Hans Peter Freyther210565e2011-06-07 20:56:18 +0200124
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +0800125 /* Connection data */
Neels Hofmeyrf93970b2018-03-05 02:09:40 +0100126 struct osmo_plmn_id core_plmn;
Holger Hans Peter Freyther32dd2f32015-04-01 18:15:48 +0200127 int core_lac;
128 int core_ci;
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +0800129
Holger Hans Peter Freyther7bf66c52010-11-03 13:55:49 +0100130 /* audio codecs */
Holger Hans Peter Freyther25aa7492011-08-06 07:00:52 +0200131 struct gsm48_multi_rate_conf amr_conf;
Philipp Maier0d9a1a72019-03-07 16:50:34 +0100132 bool amr_octet_aligned;
Holger Hans Peter Freyther7bf66c52010-11-03 13:55:49 +0100133 struct gsm_audio_support **audio_support;
134 int audio_length;
Harald Welte1f1c56c2018-06-03 12:24:27 +0200135 enum bsc_lcls_mode lcls_mode;
Philipp Maier48338572018-07-10 09:32:27 +0200136 bool lcls_codec_mismatch_allow;
Holger Hans Peter Freyther7bf66c52010-11-03 13:55:49 +0100137
Holger Hans Peter Freyther20fea242011-06-04 19:58:26 +0200138 int nr;
Jacob Erlbeck1b894022013-08-28 10:16:54 +0200139
Alexander Chemeris5e893332020-05-07 16:41:26 +0300140 /* structures for keeping rate counters and gauge stats */
141 struct rate_ctr_group *msc_ctrs;
142 struct osmo_stat_item_group *msc_statg;
143
Philipp Maier39f62bb2017-04-09 12:32:51 +0200144 /* Sigtran connection data */
145 struct {
146 uint32_t cs7_instance;
147 bool cs7_instance_valid;
148 struct osmo_sccp_instance *sccp;
149 struct osmo_sccp_user *sccp_user;
150
Harald Welte3909d992018-05-25 15:51:05 +0200151 /* IPA or M3UA or SUA? */
152 enum osmo_ss7_asp_protocol asp_proto;
153
Philipp Maier39f62bb2017-04-09 12:32:51 +0200154 /* Holds a copy of the our local MSC address,
155 * this will be the sccp-address that is associated
156 * with the A interface of this particular BSC,
157 * this address is filled up by the VTY interface */
158 struct osmo_sccp_addr bsc_addr;
159 char *bsc_addr_name;
160
161 /* Holds a copy of the MSC address. This is the
162 * address of the MSC that handles the calls of
163 * this BSC. The address is configured via the
164 * VTY interface */
165 struct osmo_sccp_addr msc_addr;
166 char *msc_addr_name;
167
Philipp Maier0b103992018-05-07 12:43:28 +0200168 /* Pointer to the osmo-fsm that controls the
169 * BSSMAP RESET procedure */
170 struct osmo_fsm_inst *reset_fsm;
Philipp Maier39f62bb2017-04-09 12:32:51 +0200171 } a;
Neels Hofmeyrd8f46c02018-08-23 17:28:55 +0200172
173 uint32_t x_osmo_ign;
174 bool x_osmo_ign_configured;
Pau Espin Pedrol6c548dc2019-04-16 20:01:47 +0200175
176 /* Whether we want to use Osmux against this MSC. Controlled via VTY */
177 enum osmux_usage use_osmux;
Pau Espin Pedrola94907e2019-04-16 20:03:15 +0200178 /* Whether we detected the MSC supports Osmux (during BSSMAP_RESET) */
179 bool remote_supports_osmux;
Harald Welte1626f902018-05-26 22:56:59 +0200180
181 /* Proxy between IPA/SCCPlite encapsulated MGCP and UDP */
182 struct {
183 /* local (BSC) IP address to be used */
184 char *local_addr;
185 /* local (BSC) UDP port to be used to talk with MGW */
186 uint16_t local_port;
187 /* UDP socket for proxying MGCP via SCCPlite/IPA */
188 struct osmo_fd ofd;
189 } mgcp_ipa;
Neels Hofmeyr4099f1d2020-05-26 03:58:14 +0200190
191 struct osmo_nri_ranges *nri_ranges;
Neels Hofmeyrb69db822020-06-11 02:36:29 +0200192 bool allow_attach;
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +0200193};
194
Neels Hofmeyra369e242017-02-23 21:57:23 +0100195int osmo_bsc_msc_init(struct bsc_msc_data *msc);
Holger Hans Peter Freytherf3d1ae72010-11-03 16:40:03 +0100196int osmo_bsc_sccp_init(struct gsm_network *gsmnet);
Holger Hans Peter Freyther5832b3e2010-09-16 02:14:41 +0800197
Holger Hans Peter Freyther620c2e62010-11-14 20:38:06 +0100198int osmo_bsc_audio_init(struct gsm_network *network);
199
Neels Hofmeyra369e242017-02-23 21:57:23 +0100200struct bsc_msc_data *osmo_msc_data_find(struct gsm_network *, int);
201struct bsc_msc_data *osmo_msc_data_alloc(struct gsm_network *, int);
Holger Hans Peter Freyther20fea242011-06-04 19:58:26 +0200202
Pau Espin Pedrola1150522019-03-12 18:55:57 +0100203
204struct osmo_cell_global_id *cgi_for_msc(struct bsc_msc_data *msc, struct gsm_bts *bts);
205
Harald Welte584ab8e2018-05-25 17:35:54 +0200206/* Helper function to calculate the port number for a given
207 * timeslot/multiplex. This functionality is needed to support
208 * the sccp-lite scenario where the MGW is handled externally */
209static inline int mgcp_timeslot_to_port(int multiplex, int timeslot, int base)
210{
211 if (timeslot == 0) {
212 LOGP(DLMGCP, LOGL_ERROR, "Timeslot should not be 0\n");
213 timeslot = 255;
214 }
215
216 return base + (timeslot + (32 * multiplex)) * 2;
217}
218
219static inline int mgcp_port_to_cic(uint16_t port, uint16_t base)
220{
221 if (port < base)
222 return -EINVAL;
223 return (port - base) / 2;
224}
225
Pau Espin Pedroled41e8c2019-06-06 16:44:20 +0200226static inline bool msc_is_aoip(const struct bsc_msc_data *msc)
227{
228 switch (msc->a.asp_proto) {
229 case OSMO_SS7_ASP_PROT_SUA:
230 case OSMO_SS7_ASP_PROT_M3UA:
231 return true;
232 default:
233 return false;
234 }
235}
236
237static inline bool msc_is_sccplite(const struct bsc_msc_data *msc)
238{
239 switch (msc->a.asp_proto) {
240 case OSMO_SS7_ASP_PROT_IPA:
241 return true;
242 default:
243 return false;
244 }
245}
Holger Hans Peter Freyther20fea242011-06-04 19:58:26 +0200246
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +0800247#endif