blob: 07a4423566ef436dc226c565595d68a84d149134 [file] [log] [blame]
Jacob Erlbeckc91a5762014-11-10 11:21:32 +01001/* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org>
2 *
3 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
Neels Hofmeyr5494c272016-05-14 00:45:26 +020020#include <openbsc/osmo_bsc.h>
Jacob Erlbeckc91a5762014-11-10 11:21:32 +010021#include <openbsc/gsm_data.h>
22#include <openbsc/osmo_msc_data.h>
Jacob Erlbeckda8770b2014-12-03 09:28:24 +010023#include <openbsc/gsm_subscriber.h>
Jacob Erlbeckc91a5762014-11-10 11:21:32 +010024
Max58726412016-06-30 10:25:49 +020025#include <stdbool.h>
26
Neels Hofmeyr5494c272016-05-14 00:45:26 +020027struct gsm_network *bsc_network_init(void *ctx,
Neels Hofmeyrc1c4dc12016-05-09 19:12:44 +020028 uint16_t country_code,
29 uint16_t network_code,
Neels Hofmeyr2ba6b732016-05-11 14:28:25 +020030 mncc_recv_cb_t mncc_recv)
Jacob Erlbeckc91a5762014-11-10 11:21:32 +010031{
32 struct gsm_network *net;
Max01010682016-07-27 12:06:36 +020033 const char *default_regexp = ".*";
Jacob Erlbeckc91a5762014-11-10 11:21:32 +010034
Neels Hofmeyrc1c4dc12016-05-09 19:12:44 +020035 net = talloc_zero(ctx, struct gsm_network);
Jacob Erlbeckc91a5762014-11-10 11:21:32 +010036 if (!net)
37 return NULL;
38
39 net->bsc_data = talloc_zero(net, struct osmo_bsc_data);
40 if (!net->bsc_data) {
41 talloc_free(net);
42 return NULL;
43 }
44
Jacob Erlbeckda8770b2014-12-03 09:28:24 +010045 net->subscr_group = talloc_zero(net, struct gsm_subscriber_group);
46 if (!net->subscr_group) {
47 talloc_free(net);
48 return NULL;
49 }
50
Max58726412016-06-30 10:25:49 +020051 if (gsm_parse_reg(net, &net->authorized_regexp, &net->authorized_reg_str, 1,
52 &default_regexp) != 0)
53 return NULL;
54
Jacob Erlbeckc91a5762014-11-10 11:21:32 +010055 /* Init back pointer */
56 net->bsc_data->auto_off_timeout = -1;
57 net->bsc_data->network = net;
58 INIT_LLIST_HEAD(&net->bsc_data->mscs);
Holger Hans Peter Freytherd3af8022015-01-27 10:27:53 +010059
Jacob Erlbeckda8770b2014-12-03 09:28:24 +010060 net->subscr_group->net = net;
Max58726412016-06-30 10:25:49 +020061 net->auto_create_subscr = true;
62 net->auto_assign_exten = true;
Jacob Erlbeckc91a5762014-11-10 11:21:32 +010063
64 net->country_code = country_code;
65 net->network_code = network_code;
66 net->num_bts = 0;
67 net->reject_cause = GSM48_REJECT_ROAMING_NOT_ALLOWED;
68 net->T3101 = GSM_T3101_DEFAULT;
69 net->T3105 = GSM_T3105_DEFAULT;
70 net->T3113 = GSM_T3113_DEFAULT;
71 net->T3122 = GSM_T3122_DEFAULT;
72 /* FIXME: initialize all other timers! */
73
74 /* default set of handover parameters */
75 net->handover.win_rxlev_avg = 10;
76 net->handover.win_rxqual_avg = 1;
77 net->handover.win_rxlev_avg_neigh = 10;
78 net->handover.pwr_interval = 6;
79 net->handover.pwr_hysteresis = 3;
80 net->handover.max_distance = 9999;
81
82 INIT_LLIST_HEAD(&net->trans_list);
83 INIT_LLIST_HEAD(&net->upqueue);
84 INIT_LLIST_HEAD(&net->bts_list);
Neels Hofmeyrd3f52f72016-05-09 21:03:12 +020085 INIT_LLIST_HEAD(&net->subscr_conns);
Jacob Erlbeckc91a5762014-11-10 11:21:32 +010086
Alexander Couzens65bfd762016-07-12 15:42:02 +020087 /* init statistics */
Alexander Couzensd8aad3a2016-08-02 11:34:11 +020088 net->bsc_ctrs = rate_ctr_group_alloc(net, &bsc_ctrg_desc, 0);
Alexander Couzensbaf1b442016-08-30 14:34:36 +020089 net->msc_ctrs = rate_ctr_group_alloc(net, &msc_ctrg_desc, 0);
Alexander Couzens3913c4f2016-08-23 07:32:27 +020090 net->active_calls = osmo_counter_alloc("msc.active_calls");
Jacob Erlbeckc91a5762014-11-10 11:21:32 +010091
92 net->mncc_recv = mncc_recv;
Max39115332016-06-07 15:32:16 +020093 net->ext_min = GSM_MIN_EXTEN;
94 net->ext_max = GSM_MAX_EXTEN;
Jacob Erlbeckc91a5762014-11-10 11:21:32 +010095 gsm_net_update_ctype(net);
96
Neels Hofmeyrf8d60532016-07-23 20:15:28 +020097 net->dyn_ts_allow_tch_f = true;
98
Jacob Erlbeckc91a5762014-11-10 11:21:32 +010099 return net;
100}
101