blob: 9f2d7d8a344e8fdd2b93c5587f2e8c32e91e5fcf [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"
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +080033
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010034#include <osmocom/core/timer.h>
Holger Hans Peter Freyther25aa7492011-08-06 07:00:52 +020035#include <osmocom/gsm/protocol/gsm_04_08.h>
Holger Hans Peter Freyther5832b3e2010-09-16 02:14:41 +080036
Philipp Maier39f62bb2017-04-09 12:32:51 +020037
38#include <osmocom/sigtran/osmo_ss7.h>
39#include <osmocom/sigtran/sccp_sap.h>
40#include <osmocom/sigtran/sccp_helpers.h>
41#include <osmocom/sigtran/protocol/sua.h>
42#include <osmocom/sigtran/protocol/m3ua.h>
43#include <osmocom/core/fsm.h>
Neels Hofmeyrf93970b2018-03-05 02:09:40 +010044#include <osmocom/gsm/gsm23003.h>
Philipp Maier39f62bb2017-04-09 12:32:51 +020045
Holger Hans Peter Freyther83d2d382011-06-09 17:37:04 +020046#include <regex.h>
Harald Welte584ab8e2018-05-25 17:35:54 +020047#include <errno.h>
Holger Hans Peter Freyther83d2d382011-06-09 17:37:04 +020048
Holger Hans Peter Freyther9a8b5ae2010-09-15 23:53:54 +080049struct osmo_bsc_rf;
Holger Hans Peter Freyther620c2e62010-11-14 20:38:06 +010050struct gsm_network;
Holger Hans Peter Freyther9a8b5ae2010-09-15 23:53:54 +080051
Holger Hans Peter Freyther210565e2011-06-07 20:56:18 +020052enum {
53 MSC_CON_TYPE_NORMAL,
54 MSC_CON_TYPE_LOCAL,
55};
56
Neels Hofmeyr9762b4c2017-02-23 21:41:20 +010057/*! /brief Information on a remote MSC for libbsc.
58 */
Neels Hofmeyra369e242017-02-23 21:57:23 +010059struct bsc_msc_data {
Holger Hans Peter Freyther20fea242011-06-04 19:58:26 +020060 struct llist_head entry;
61
Daniel Willmann163f6122011-03-03 13:48:28 +010062 /* Back pointer */
63 struct gsm_network *network;
64
Holger Hans Peter Freyther18fa70a2011-06-08 19:25:38 +020065 int allow_emerg;
Holger Hans Peter Freyther210565e2011-06-07 20:56:18 +020066 int type;
67
Holger Hans Peter Freyther83d2d382011-06-09 17:37:04 +020068 /* local call routing */
69 char *local_pref;
70 regex_t local_pref_reg;
71
72
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +080073 /* Connection data */
Neels Hofmeyrf93970b2018-03-05 02:09:40 +010074 struct osmo_plmn_id core_plmn;
Holger Hans Peter Freyther32dd2f32015-04-01 18:15:48 +020075 int core_lac;
76 int core_ci;
Holger Hans Peter Freytherfe166222010-11-03 13:32:48 +010077 int rtp_base;
Harald Welte68e4be92018-05-26 22:42:29 +020078 bool is_authenticated;
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +080079
Holger Hans Peter Freyther7bf66c52010-11-03 13:55:49 +010080 /* audio codecs */
Holger Hans Peter Freyther25aa7492011-08-06 07:00:52 +020081 struct gsm48_multi_rate_conf amr_conf;
Holger Hans Peter Freyther7bf66c52010-11-03 13:55:49 +010082 struct gsm_audio_support **audio_support;
83 int audio_length;
Harald Welte1f1c56c2018-06-03 12:24:27 +020084 enum bsc_lcls_mode lcls_mode;
Philipp Maier48338572018-07-10 09:32:27 +020085 bool lcls_codec_mismatch_allow;
Holger Hans Peter Freyther7bf66c52010-11-03 13:55:49 +010086
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +020087 /* ussd welcome text */
88 char *ussd_welcome_txt;
Holger Hans Peter Freyther7bf66c52010-11-03 13:55:49 +010089
Holger Hans Peter Freyther20fea242011-06-04 19:58:26 +020090 int nr;
Jacob Erlbeck1b894022013-08-28 10:16:54 +020091
92 /* ussd msc connection lost text */
93 char *ussd_msc_lost_txt;
Jacob Erlbeck56595f82013-09-11 10:46:55 +020094
95 /* ussd text when MSC has entered the grace period */
96 char *ussd_grace_txt;
Holger Hans Peter Freytherd6332802015-04-05 19:46:20 +020097
98 char *acc_lst_name;
Philipp Maier39f62bb2017-04-09 12:32:51 +020099
100 /* Sigtran connection data */
101 struct {
102 uint32_t cs7_instance;
103 bool cs7_instance_valid;
104 struct osmo_sccp_instance *sccp;
105 struct osmo_sccp_user *sccp_user;
106
Harald Welte3909d992018-05-25 15:51:05 +0200107 /* IPA or M3UA or SUA? */
108 enum osmo_ss7_asp_protocol asp_proto;
109
Philipp Maier39f62bb2017-04-09 12:32:51 +0200110 /* Holds a copy of the our local MSC address,
111 * this will be the sccp-address that is associated
112 * with the A interface of this particular BSC,
113 * this address is filled up by the VTY interface */
114 struct osmo_sccp_addr bsc_addr;
115 char *bsc_addr_name;
116
117 /* Holds a copy of the MSC address. This is the
118 * address of the MSC that handles the calls of
119 * this BSC. The address is configured via the
120 * VTY interface */
121 struct osmo_sccp_addr msc_addr;
122 char *msc_addr_name;
123
Philipp Maier0b103992018-05-07 12:43:28 +0200124 /* Pointer to the osmo-fsm that controls the
125 * BSSMAP RESET procedure */
126 struct osmo_fsm_inst *reset_fsm;
Philipp Maier39f62bb2017-04-09 12:32:51 +0200127 } a;
Neels Hofmeyrd8f46c02018-08-23 17:28:55 +0200128
129 uint32_t x_osmo_ign;
130 bool x_osmo_ign_configured;
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +0200131};
132
133/*
134 * Per BSC data.
135 */
136struct osmo_bsc_data {
137 struct gsm_network *network;
138
139 /* msc configuration */
Holger Hans Peter Freyther20fea242011-06-04 19:58:26 +0200140 struct llist_head mscs;
Holger Hans Peter Freyther5832b3e2010-09-16 02:14:41 +0800141
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +0800142 /* rf ctl related bits */
Holger Hans Peter Freytherbb62b3f2010-11-22 18:30:21 +0100143 char *mid_call_txt;
144 int mid_call_timeout;
Holger Hans Peter Freyther55ef5fb2011-04-07 23:23:27 +0200145 char *rf_ctrl_name;
Holger Hans Peter Freyther5e3bbba2011-06-04 09:32:35 +0200146 struct osmo_bsc_rf *rf_ctrl;
Holger Hans Peter Freyther2a896072011-08-16 19:47:39 +0200147 int auto_off_timeout;
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200148
149 /* ussd text when there is no MSC available */
150 char *ussd_no_msc_txt;
Holger Hans Peter Freytherd6332802015-04-05 19:46:20 +0200151
152 char *acc_lst_name;
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +0800153};
154
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +0200155
Neels Hofmeyra369e242017-02-23 21:57:23 +0100156int osmo_bsc_msc_init(struct bsc_msc_data *msc);
Holger Hans Peter Freytherf3d1ae72010-11-03 16:40:03 +0100157int osmo_bsc_sccp_init(struct gsm_network *gsmnet);
Holger Hans Peter Freyther5832b3e2010-09-16 02:14:41 +0800158
Holger Hans Peter Freyther620c2e62010-11-14 20:38:06 +0100159int osmo_bsc_audio_init(struct gsm_network *network);
160
Neels Hofmeyra369e242017-02-23 21:57:23 +0100161struct bsc_msc_data *osmo_msc_data_find(struct gsm_network *, int);
162struct bsc_msc_data *osmo_msc_data_alloc(struct gsm_network *, int);
Holger Hans Peter Freyther20fea242011-06-04 19:58:26 +0200163
Harald Welte584ab8e2018-05-25 17:35:54 +0200164/* Helper function to calculate the port number for a given
165 * timeslot/multiplex. This functionality is needed to support
166 * the sccp-lite scenario where the MGW is handled externally */
167static inline int mgcp_timeslot_to_port(int multiplex, int timeslot, int base)
168{
169 if (timeslot == 0) {
170 LOGP(DLMGCP, LOGL_ERROR, "Timeslot should not be 0\n");
171 timeslot = 255;
172 }
173
174 return base + (timeslot + (32 * multiplex)) * 2;
175}
176
177static inline int mgcp_port_to_cic(uint16_t port, uint16_t base)
178{
179 if (port < base)
180 return -EINVAL;
181 return (port - base) / 2;
182}
183
Holger Hans Peter Freyther20fea242011-06-04 19:58:26 +0200184
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +0800185#endif