blob: 2ace1786b9347df03337ffedeadd93f9fe1b788a [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
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +08006 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +01009 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +080011 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte9af6ddf2011-01-01 15:25:50 +010016 * GNU Affero General Public License for more details.
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +080017 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010018 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +080020 *
21 */
22
Neels Hofmeyr9762b4c2017-02-23 21:41:20 +010023/*
24 * NOTE: This is about a *remote* MSC for OsmoBSC and is not part of libmsc.
25 */
26
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +080027#ifndef _OSMO_MSC_DATA_H
28#define _OSMO_MSC_DATA_H
29
30#include "bsc_msc.h"
Harald Welte584ab8e2018-05-25 17:35:54 +020031#include "debug.h"
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +080032
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010033#include <osmocom/core/timer.h>
Holger Hans Peter Freyther25aa7492011-08-06 07:00:52 +020034#include <osmocom/gsm/protocol/gsm_04_08.h>
Holger Hans Peter Freyther5832b3e2010-09-16 02:14:41 +080035
Philipp Maier39f62bb2017-04-09 12:32:51 +020036
37#include <osmocom/sigtran/osmo_ss7.h>
38#include <osmocom/sigtran/sccp_sap.h>
39#include <osmocom/sigtran/sccp_helpers.h>
40#include <osmocom/sigtran/protocol/sua.h>
41#include <osmocom/sigtran/protocol/m3ua.h>
42#include <osmocom/core/fsm.h>
Neels Hofmeyrf93970b2018-03-05 02:09:40 +010043#include <osmocom/gsm/gsm23003.h>
Philipp Maier39f62bb2017-04-09 12:32:51 +020044
Holger Hans Peter Freyther83d2d382011-06-09 17:37:04 +020045#include <regex.h>
Harald Welte584ab8e2018-05-25 17:35:54 +020046#include <errno.h>
Holger Hans Peter Freyther83d2d382011-06-09 17:37:04 +020047
Holger Hans Peter Freyther9a8b5ae2010-09-15 23:53:54 +080048struct osmo_bsc_rf;
Holger Hans Peter Freyther620c2e62010-11-14 20:38:06 +010049struct gsm_network;
Holger Hans Peter Freyther9a8b5ae2010-09-15 23:53:54 +080050
Holger Hans Peter Freyther7bf66c52010-11-03 13:55:49 +010051struct gsm_audio_support {
Holger Hans Peter Freyther620c2e62010-11-14 20:38:06 +010052 uint8_t hr : 1,
53 ver : 7;
Holger Hans Peter Freyther7bf66c52010-11-03 13:55:49 +010054};
55
Holger Hans Peter Freyther210565e2011-06-07 20:56:18 +020056enum {
57 MSC_CON_TYPE_NORMAL,
58 MSC_CON_TYPE_LOCAL,
59};
60
Neels Hofmeyr9762b4c2017-02-23 21:41:20 +010061/*! /brief Information on a remote MSC for libbsc.
62 */
Neels Hofmeyra369e242017-02-23 21:57:23 +010063struct bsc_msc_data {
Holger Hans Peter Freyther20fea242011-06-04 19:58:26 +020064 struct llist_head entry;
65
Daniel Willmann163f6122011-03-03 13:48:28 +010066 /* Back pointer */
67 struct gsm_network *network;
68
Holger Hans Peter Freyther18fa70a2011-06-08 19:25:38 +020069 int allow_emerg;
Holger Hans Peter Freyther210565e2011-06-07 20:56:18 +020070 int type;
71
Holger Hans Peter Freyther83d2d382011-06-09 17:37:04 +020072 /* local call routing */
73 char *local_pref;
74 regex_t local_pref_reg;
75
76
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +080077 /* Connection data */
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +080078 struct bsc_msc_connection *msc_con;
Neels Hofmeyrf93970b2018-03-05 02:09:40 +010079 struct osmo_plmn_id core_plmn;
Holger Hans Peter Freyther32dd2f32015-04-01 18:15:48 +020080 int core_lac;
81 int core_ci;
Holger Hans Peter Freytherfe166222010-11-03 13:32:48 +010082 int rtp_base;
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +080083
Holger Hans Peter Freyther7bf66c52010-11-03 13:55:49 +010084 /* audio codecs */
Holger Hans Peter Freyther25aa7492011-08-06 07:00:52 +020085 struct gsm48_multi_rate_conf amr_conf;
Holger Hans Peter Freyther7bf66c52010-11-03 13:55:49 +010086 struct gsm_audio_support **audio_support;
87 int audio_length;
88
Holger Hans Peter Freythere1880102011-04-23 23:31:31 +020089 /* destinations */
90 struct llist_head dests;
91
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +020092 /* ussd welcome text */
93 char *ussd_welcome_txt;
Holger Hans Peter Freyther7bf66c52010-11-03 13:55:49 +010094
Holger Hans Peter Freyther5832b3e2010-09-16 02:14:41 +080095 /* mgcp agent */
Pablo Neira Ayusoe1273b12011-05-06 12:09:47 +020096 struct osmo_wqueue mgcp_agent;
Holger Hans Peter Freyther20fea242011-06-04 19:58:26 +020097
98 int nr;
Jacob Erlbeck1b894022013-08-28 10:16:54 +020099
100 /* ussd msc connection lost text */
101 char *ussd_msc_lost_txt;
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200102
103 /* ussd text when MSC has entered the grace period */
104 char *ussd_grace_txt;
Holger Hans Peter Freytherd6332802015-04-05 19:46:20 +0200105
106 char *acc_lst_name;
Philipp Maier39f62bb2017-04-09 12:32:51 +0200107
108 /* Sigtran connection data */
109 struct {
110 uint32_t cs7_instance;
111 bool cs7_instance_valid;
112 struct osmo_sccp_instance *sccp;
113 struct osmo_sccp_user *sccp_user;
114
Harald Welte3909d992018-05-25 15:51:05 +0200115 /* IPA or M3UA or SUA? */
116 enum osmo_ss7_asp_protocol asp_proto;
117
Philipp Maier39f62bb2017-04-09 12:32:51 +0200118 /* Holds a copy of the our local MSC address,
119 * this will be the sccp-address that is associated
120 * with the A interface of this particular BSC,
121 * this address is filled up by the VTY interface */
122 struct osmo_sccp_addr bsc_addr;
123 char *bsc_addr_name;
124
125 /* Holds a copy of the MSC address. This is the
126 * address of the MSC that handles the calls of
127 * this BSC. The address is configured via the
128 * VTY interface */
129 struct osmo_sccp_addr msc_addr;
130 char *msc_addr_name;
131
Philipp Maier0b103992018-05-07 12:43:28 +0200132 /* Pointer to the osmo-fsm that controls the
133 * BSSMAP RESET procedure */
134 struct osmo_fsm_inst *reset_fsm;
Philipp Maier39f62bb2017-04-09 12:32:51 +0200135 } a;
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +0200136};
137
138/*
139 * Per BSC data.
140 */
141struct osmo_bsc_data {
142 struct gsm_network *network;
143
144 /* msc configuration */
Holger Hans Peter Freyther20fea242011-06-04 19:58:26 +0200145 struct llist_head mscs;
Holger Hans Peter Freyther5832b3e2010-09-16 02:14:41 +0800146
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +0800147 /* rf ctl related bits */
Holger Hans Peter Freytherbb62b3f2010-11-22 18:30:21 +0100148 char *mid_call_txt;
149 int mid_call_timeout;
Holger Hans Peter Freyther55ef5fb2011-04-07 23:23:27 +0200150 char *rf_ctrl_name;
Holger Hans Peter Freyther5e3bbba2011-06-04 09:32:35 +0200151 struct osmo_bsc_rf *rf_ctrl;
Holger Hans Peter Freyther2a896072011-08-16 19:47:39 +0200152 int auto_off_timeout;
Jacob Erlbeck56595f82013-09-11 10:46:55 +0200153
154 /* ussd text when there is no MSC available */
155 char *ussd_no_msc_txt;
Holger Hans Peter Freytherd6332802015-04-05 19:46:20 +0200156
157 char *acc_lst_name;
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +0800158};
159
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +0200160
Neels Hofmeyra369e242017-02-23 21:57:23 +0100161int osmo_bsc_msc_init(struct bsc_msc_data *msc);
Holger Hans Peter Freytherf3d1ae72010-11-03 16:40:03 +0100162int osmo_bsc_sccp_init(struct gsm_network *gsmnet);
Holger Hans Peter Freyther5832b3e2010-09-16 02:14:41 +0800163
Holger Hans Peter Freyther620c2e62010-11-14 20:38:06 +0100164int osmo_bsc_audio_init(struct gsm_network *network);
165
Neels Hofmeyra369e242017-02-23 21:57:23 +0100166struct bsc_msc_data *osmo_msc_data_find(struct gsm_network *, int);
167struct bsc_msc_data *osmo_msc_data_alloc(struct gsm_network *, int);
Holger Hans Peter Freyther20fea242011-06-04 19:58:26 +0200168
Harald Welte584ab8e2018-05-25 17:35:54 +0200169/* Helper function to calculate the port number for a given
170 * timeslot/multiplex. This functionality is needed to support
171 * the sccp-lite scenario where the MGW is handled externally */
172static inline int mgcp_timeslot_to_port(int multiplex, int timeslot, int base)
173{
174 if (timeslot == 0) {
175 LOGP(DLMGCP, LOGL_ERROR, "Timeslot should not be 0\n");
176 timeslot = 255;
177 }
178
179 return base + (timeslot + (32 * multiplex)) * 2;
180}
181
182static inline int mgcp_port_to_cic(uint16_t port, uint16_t base)
183{
184 if (port < base)
185 return -EINVAL;
186 return (port - base) / 2;
187}
188
Holger Hans Peter Freyther20fea242011-06-04 19:58:26 +0200189
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +0800190#endif