Holger Hans Peter Freyther | 3e8e046 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Data for the true BSC |
| 3 | * |
Holger Hans Peter Freyther | 32dd2f3 | 2015-04-01 18:15:48 +0200 | [diff] [blame] | 4 | * (C) 2010-2015 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 5 | * (C) 2010-2015 by On-Waves |
Harald Welte | 68e4be9 | 2018-05-26 22:42:29 +0200 | [diff] [blame] | 6 | * (C) 2018 by Harald Welte <laforge@gnumonks.org> |
Holger Hans Peter Freyther | 3e8e046 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 7 | * All Rights Reserved |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 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 |
Holger Hans Peter Freyther | 3e8e046 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 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 |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 17 | * GNU Affero General Public License for more details. |
Holger Hans Peter Freyther | 3e8e046 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 18 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 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/>. |
Holger Hans Peter Freyther | 3e8e046 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 21 | * |
| 22 | */ |
| 23 | |
Neels Hofmeyr | 9762b4c | 2017-02-23 21:41:20 +0100 | [diff] [blame] | 24 | /* |
| 25 | * NOTE: This is about a *remote* MSC for OsmoBSC and is not part of libmsc. |
| 26 | */ |
| 27 | |
Holger Hans Peter Freyther | 3e8e046 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 28 | #ifndef _OSMO_MSC_DATA_H |
| 29 | #define _OSMO_MSC_DATA_H |
| 30 | |
Harald Welte | 584ab8e | 2018-05-25 17:35:54 +0200 | [diff] [blame] | 31 | #include "debug.h" |
Pau Espin Pedrol | 2cfd000 | 2019-03-12 18:53:26 +0100 | [diff] [blame] | 32 | #include "osmo_bsc_lcls.h" |
Pau Espin Pedrol | 6c548dc | 2019-04-16 20:01:47 +0200 | [diff] [blame] | 33 | #include "osmux.h" |
Holger Hans Peter Freyther | 3e8e046 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 34 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 35 | #include <osmocom/core/timer.h> |
Harald Welte | 1626f90 | 2018-05-26 22:56:59 +0200 | [diff] [blame] | 36 | #include <osmocom/core/select.h> |
Holger Hans Peter Freyther | 25aa749 | 2011-08-06 07:00:52 +0200 | [diff] [blame] | 37 | #include <osmocom/gsm/protocol/gsm_04_08.h> |
Holger Hans Peter Freyther | 5832b3e | 2010-09-16 02:14:41 +0800 | [diff] [blame] | 38 | |
Philipp Maier | 39f62bb | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 39 | |
| 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 Hofmeyr | f93970b | 2018-03-05 02:09:40 +0100 | [diff] [blame] | 46 | #include <osmocom/gsm/gsm23003.h> |
Philipp Maier | 39f62bb | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 47 | |
Holger Hans Peter Freyther | 83d2d38 | 2011-06-09 17:37:04 +0200 | [diff] [blame] | 48 | #include <regex.h> |
Harald Welte | 584ab8e | 2018-05-25 17:35:54 +0200 | [diff] [blame] | 49 | #include <errno.h> |
Holger Hans Peter Freyther | 83d2d38 | 2011-06-09 17:37:04 +0200 | [diff] [blame] | 50 | |
Holger Hans Peter Freyther | 9a8b5ae | 2010-09-15 23:53:54 +0800 | [diff] [blame] | 51 | struct osmo_bsc_rf; |
Holger Hans Peter Freyther | 620c2e6 | 2010-11-14 20:38:06 +0100 | [diff] [blame] | 52 | struct gsm_network; |
Holger Hans Peter Freyther | 9a8b5ae | 2010-09-15 23:53:54 +0800 | [diff] [blame] | 53 | |
Holger Hans Peter Freyther | 210565e | 2011-06-07 20:56:18 +0200 | [diff] [blame] | 54 | enum { |
| 55 | MSC_CON_TYPE_NORMAL, |
| 56 | MSC_CON_TYPE_LOCAL, |
| 57 | }; |
| 58 | |
Alexander Chemeris | e26b153 | 2020-05-08 02:37:47 +0300 | [diff] [blame^] | 59 | /* Constants for the MSC rate counters */ |
| 60 | enum { |
| 61 | MSC_CTR_BSSMAP_RX_UDT_RESET_ACKNOWLEDGE, |
| 62 | MSC_CTR_BSSMAP_RX_UDT_RESET, |
| 63 | MSC_CTR_BSSMAP_RX_UDT_PAGING, |
| 64 | MSC_CTR_BSSMAP_RX_UDT_UNKNOWN, |
| 65 | MSC_CTR_BSSMAP_RX_DT1_CLEAR_CMD, |
| 66 | MSC_CTR_BSSMAP_RX_DT1_CIPHER_MODE_CMD, |
| 67 | MSC_CTR_BSSMAP_RX_DT1_ASSIGMENT_RQST, |
| 68 | MSC_CTR_BSSMAP_RX_DT1_LCLS_CONNECT_CTRL, |
| 69 | MSC_CTR_BSSMAP_RX_DT1_HANDOVER_CMD, |
| 70 | MSC_CTR_BSSMAP_RX_DT1_CLASSMARK_RQST, |
| 71 | MSC_CTR_BSSMAP_RX_DT1_UNKNOWN, |
| 72 | MSC_CTR_BSSMAP_RX_DTAP_MSG, |
| 73 | MSC_CTR_BSSMAP_RX_DTAP_ERROR, |
| 74 | }; |
| 75 | |
Alexander Chemeris | 5e89333 | 2020-05-07 16:41:26 +0300 | [diff] [blame] | 76 | /* Constants for the MSC stats */ |
| 77 | enum { |
| 78 | MSC_STAT_MSC_LINKS_ACTIVE, |
| 79 | MSC_STAT_MSC_LINKS_TOTAL, |
| 80 | }; |
| 81 | |
Neels Hofmeyr | 9762b4c | 2017-02-23 21:41:20 +0100 | [diff] [blame] | 82 | /*! /brief Information on a remote MSC for libbsc. |
| 83 | */ |
Neels Hofmeyr | a369e24 | 2017-02-23 21:57:23 +0100 | [diff] [blame] | 84 | struct bsc_msc_data { |
Holger Hans Peter Freyther | 20fea24 | 2011-06-04 19:58:26 +0200 | [diff] [blame] | 85 | struct llist_head entry; |
| 86 | |
Daniel Willmann | 163f612 | 2011-03-03 13:48:28 +0100 | [diff] [blame] | 87 | /* Back pointer */ |
| 88 | struct gsm_network *network; |
| 89 | |
Holger Hans Peter Freyther | 18fa70a | 2011-06-08 19:25:38 +0200 | [diff] [blame] | 90 | int allow_emerg; |
Holger Hans Peter Freyther | 210565e | 2011-06-07 20:56:18 +0200 | [diff] [blame] | 91 | int type; |
| 92 | |
Holger Hans Peter Freyther | 83d2d38 | 2011-06-09 17:37:04 +0200 | [diff] [blame] | 93 | /* local call routing */ |
| 94 | char *local_pref; |
| 95 | regex_t local_pref_reg; |
| 96 | |
| 97 | |
Holger Hans Peter Freyther | 47b2601 | 2010-09-15 23:28:49 +0800 | [diff] [blame] | 98 | /* Connection data */ |
Neels Hofmeyr | f93970b | 2018-03-05 02:09:40 +0100 | [diff] [blame] | 99 | struct osmo_plmn_id core_plmn; |
Holger Hans Peter Freyther | 32dd2f3 | 2015-04-01 18:15:48 +0200 | [diff] [blame] | 100 | int core_lac; |
| 101 | int core_ci; |
Holger Hans Peter Freyther | fe16622 | 2010-11-03 13:32:48 +0100 | [diff] [blame] | 102 | int rtp_base; |
Holger Hans Peter Freyther | 47b2601 | 2010-09-15 23:28:49 +0800 | [diff] [blame] | 103 | |
Holger Hans Peter Freyther | 7bf66c5 | 2010-11-03 13:55:49 +0100 | [diff] [blame] | 104 | /* audio codecs */ |
Holger Hans Peter Freyther | 25aa749 | 2011-08-06 07:00:52 +0200 | [diff] [blame] | 105 | struct gsm48_multi_rate_conf amr_conf; |
Philipp Maier | 0d9a1a7 | 2019-03-07 16:50:34 +0100 | [diff] [blame] | 106 | bool amr_octet_aligned; |
Holger Hans Peter Freyther | 7bf66c5 | 2010-11-03 13:55:49 +0100 | [diff] [blame] | 107 | struct gsm_audio_support **audio_support; |
| 108 | int audio_length; |
Harald Welte | 1f1c56c | 2018-06-03 12:24:27 +0200 | [diff] [blame] | 109 | enum bsc_lcls_mode lcls_mode; |
Philipp Maier | 4833857 | 2018-07-10 09:32:27 +0200 | [diff] [blame] | 110 | bool lcls_codec_mismatch_allow; |
Holger Hans Peter Freyther | 7bf66c5 | 2010-11-03 13:55:49 +0100 | [diff] [blame] | 111 | |
Holger Hans Peter Freyther | 8ec4952 | 2011-08-15 15:53:00 +0200 | [diff] [blame] | 112 | /* ussd welcome text */ |
| 113 | char *ussd_welcome_txt; |
Holger Hans Peter Freyther | 7bf66c5 | 2010-11-03 13:55:49 +0100 | [diff] [blame] | 114 | |
Holger Hans Peter Freyther | 20fea24 | 2011-06-04 19:58:26 +0200 | [diff] [blame] | 115 | int nr; |
Jacob Erlbeck | 1b89402 | 2013-08-28 10:16:54 +0200 | [diff] [blame] | 116 | |
| 117 | /* ussd msc connection lost text */ |
| 118 | char *ussd_msc_lost_txt; |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 119 | |
| 120 | /* ussd text when MSC has entered the grace period */ |
| 121 | char *ussd_grace_txt; |
Holger Hans Peter Freyther | d633280 | 2015-04-05 19:46:20 +0200 | [diff] [blame] | 122 | |
| 123 | char *acc_lst_name; |
Philipp Maier | 39f62bb | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 124 | |
Alexander Chemeris | 5e89333 | 2020-05-07 16:41:26 +0300 | [diff] [blame] | 125 | /* structures for keeping rate counters and gauge stats */ |
| 126 | struct rate_ctr_group *msc_ctrs; |
| 127 | struct osmo_stat_item_group *msc_statg; |
| 128 | |
Philipp Maier | 39f62bb | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 129 | /* Sigtran connection data */ |
| 130 | struct { |
| 131 | uint32_t cs7_instance; |
| 132 | bool cs7_instance_valid; |
| 133 | struct osmo_sccp_instance *sccp; |
| 134 | struct osmo_sccp_user *sccp_user; |
| 135 | |
Harald Welte | 3909d99 | 2018-05-25 15:51:05 +0200 | [diff] [blame] | 136 | /* IPA or M3UA or SUA? */ |
| 137 | enum osmo_ss7_asp_protocol asp_proto; |
| 138 | |
Philipp Maier | 39f62bb | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 139 | /* Holds a copy of the our local MSC address, |
| 140 | * this will be the sccp-address that is associated |
| 141 | * with the A interface of this particular BSC, |
| 142 | * this address is filled up by the VTY interface */ |
| 143 | struct osmo_sccp_addr bsc_addr; |
| 144 | char *bsc_addr_name; |
| 145 | |
| 146 | /* Holds a copy of the MSC address. This is the |
| 147 | * address of the MSC that handles the calls of |
| 148 | * this BSC. The address is configured via the |
| 149 | * VTY interface */ |
| 150 | struct osmo_sccp_addr msc_addr; |
| 151 | char *msc_addr_name; |
| 152 | |
Philipp Maier | 0b10399 | 2018-05-07 12:43:28 +0200 | [diff] [blame] | 153 | /* Pointer to the osmo-fsm that controls the |
| 154 | * BSSMAP RESET procedure */ |
| 155 | struct osmo_fsm_inst *reset_fsm; |
Philipp Maier | 39f62bb | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 156 | } a; |
Neels Hofmeyr | d8f46c0 | 2018-08-23 17:28:55 +0200 | [diff] [blame] | 157 | |
| 158 | uint32_t x_osmo_ign; |
| 159 | bool x_osmo_ign_configured; |
Pau Espin Pedrol | 6c548dc | 2019-04-16 20:01:47 +0200 | [diff] [blame] | 160 | |
| 161 | /* Whether we want to use Osmux against this MSC. Controlled via VTY */ |
| 162 | enum osmux_usage use_osmux; |
Pau Espin Pedrol | a94907e | 2019-04-16 20:03:15 +0200 | [diff] [blame] | 163 | /* Whether we detected the MSC supports Osmux (during BSSMAP_RESET) */ |
| 164 | bool remote_supports_osmux; |
Harald Welte | 1626f90 | 2018-05-26 22:56:59 +0200 | [diff] [blame] | 165 | |
| 166 | /* Proxy between IPA/SCCPlite encapsulated MGCP and UDP */ |
| 167 | struct { |
| 168 | /* local (BSC) IP address to be used */ |
| 169 | char *local_addr; |
| 170 | /* local (BSC) UDP port to be used to talk with MGW */ |
| 171 | uint16_t local_port; |
| 172 | /* UDP socket for proxying MGCP via SCCPlite/IPA */ |
| 173 | struct osmo_fd ofd; |
| 174 | } mgcp_ipa; |
Holger Hans Peter Freyther | 8ec4952 | 2011-08-15 15:53:00 +0200 | [diff] [blame] | 175 | }; |
| 176 | |
| 177 | /* |
| 178 | * Per BSC data. |
| 179 | */ |
Harald Welte | d41b7c7 | 2019-06-13 09:41:58 +0200 | [diff] [blame] | 180 | struct bsc_cbc_link; |
Holger Hans Peter Freyther | 8ec4952 | 2011-08-15 15:53:00 +0200 | [diff] [blame] | 181 | struct osmo_bsc_data { |
| 182 | struct gsm_network *network; |
| 183 | |
| 184 | /* msc configuration */ |
Holger Hans Peter Freyther | 20fea24 | 2011-06-04 19:58:26 +0200 | [diff] [blame] | 185 | struct llist_head mscs; |
Holger Hans Peter Freyther | 5832b3e | 2010-09-16 02:14:41 +0800 | [diff] [blame] | 186 | |
Holger Hans Peter Freyther | 47b2601 | 2010-09-15 23:28:49 +0800 | [diff] [blame] | 187 | /* rf ctl related bits */ |
Holger Hans Peter Freyther | bb62b3f | 2010-11-22 18:30:21 +0100 | [diff] [blame] | 188 | char *mid_call_txt; |
| 189 | int mid_call_timeout; |
Holger Hans Peter Freyther | 55ef5fb | 2011-04-07 23:23:27 +0200 | [diff] [blame] | 190 | char *rf_ctrl_name; |
Holger Hans Peter Freyther | 5e3bbba | 2011-06-04 09:32:35 +0200 | [diff] [blame] | 191 | struct osmo_bsc_rf *rf_ctrl; |
Holger Hans Peter Freyther | 2a89607 | 2011-08-16 19:47:39 +0200 | [diff] [blame] | 192 | int auto_off_timeout; |
Jacob Erlbeck | 56595f8 | 2013-09-11 10:46:55 +0200 | [diff] [blame] | 193 | |
| 194 | /* ussd text when there is no MSC available */ |
| 195 | char *ussd_no_msc_txt; |
Holger Hans Peter Freyther | d633280 | 2015-04-05 19:46:20 +0200 | [diff] [blame] | 196 | |
| 197 | char *acc_lst_name; |
Harald Welte | d41b7c7 | 2019-06-13 09:41:58 +0200 | [diff] [blame] | 198 | |
| 199 | struct bsc_cbc_link *cbc; |
Holger Hans Peter Freyther | 3e8e046 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 200 | }; |
| 201 | |
Holger Hans Peter Freyther | 8ec4952 | 2011-08-15 15:53:00 +0200 | [diff] [blame] | 202 | |
Neels Hofmeyr | a369e24 | 2017-02-23 21:57:23 +0100 | [diff] [blame] | 203 | int osmo_bsc_msc_init(struct bsc_msc_data *msc); |
Holger Hans Peter Freyther | f3d1ae7 | 2010-11-03 16:40:03 +0100 | [diff] [blame] | 204 | int osmo_bsc_sccp_init(struct gsm_network *gsmnet); |
Holger Hans Peter Freyther | 5832b3e | 2010-09-16 02:14:41 +0800 | [diff] [blame] | 205 | |
Holger Hans Peter Freyther | 620c2e6 | 2010-11-14 20:38:06 +0100 | [diff] [blame] | 206 | int osmo_bsc_audio_init(struct gsm_network *network); |
| 207 | |
Neels Hofmeyr | a369e24 | 2017-02-23 21:57:23 +0100 | [diff] [blame] | 208 | struct bsc_msc_data *osmo_msc_data_find(struct gsm_network *, int); |
| 209 | struct bsc_msc_data *osmo_msc_data_alloc(struct gsm_network *, int); |
Holger Hans Peter Freyther | 20fea24 | 2011-06-04 19:58:26 +0200 | [diff] [blame] | 210 | |
Pau Espin Pedrol | a115052 | 2019-03-12 18:55:57 +0100 | [diff] [blame] | 211 | |
| 212 | struct osmo_cell_global_id *cgi_for_msc(struct bsc_msc_data *msc, struct gsm_bts *bts); |
| 213 | |
Harald Welte | 584ab8e | 2018-05-25 17:35:54 +0200 | [diff] [blame] | 214 | /* Helper function to calculate the port number for a given |
| 215 | * timeslot/multiplex. This functionality is needed to support |
| 216 | * the sccp-lite scenario where the MGW is handled externally */ |
| 217 | static inline int mgcp_timeslot_to_port(int multiplex, int timeslot, int base) |
| 218 | { |
| 219 | if (timeslot == 0) { |
| 220 | LOGP(DLMGCP, LOGL_ERROR, "Timeslot should not be 0\n"); |
| 221 | timeslot = 255; |
| 222 | } |
| 223 | |
| 224 | return base + (timeslot + (32 * multiplex)) * 2; |
| 225 | } |
| 226 | |
| 227 | static inline int mgcp_port_to_cic(uint16_t port, uint16_t base) |
| 228 | { |
| 229 | if (port < base) |
| 230 | return -EINVAL; |
| 231 | return (port - base) / 2; |
| 232 | } |
| 233 | |
Pau Espin Pedrol | ed41e8c | 2019-06-06 16:44:20 +0200 | [diff] [blame] | 234 | static inline bool msc_is_aoip(const struct bsc_msc_data *msc) |
| 235 | { |
| 236 | switch (msc->a.asp_proto) { |
| 237 | case OSMO_SS7_ASP_PROT_SUA: |
| 238 | case OSMO_SS7_ASP_PROT_M3UA: |
| 239 | return true; |
| 240 | default: |
| 241 | return false; |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | static inline bool msc_is_sccplite(const struct bsc_msc_data *msc) |
| 246 | { |
| 247 | switch (msc->a.asp_proto) { |
| 248 | case OSMO_SS7_ASP_PROT_IPA: |
| 249 | return true; |
| 250 | default: |
| 251 | return false; |
| 252 | } |
| 253 | } |
Holger Hans Peter Freyther | 20fea24 | 2011-06-04 19:58:26 +0200 | [diff] [blame] | 254 | |
Holger Hans Peter Freyther | 3e8e046 | 2010-09-15 22:29:25 +0800 | [diff] [blame] | 255 | #endif |