Jacob Erlbeck | cdd4302 | 2014-11-10 11:21:32 +0100 | [diff] [blame] | 1 | /* (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 | |
| 20 | #include <openbsc/gsm_data.h> |
| 21 | #include <openbsc/osmo_msc_data.h> |
Jacob Erlbeck | 1e30a28 | 2014-12-03 09:28:24 +0100 | [diff] [blame] | 22 | #include <openbsc/gsm_subscriber.h> |
Jacob Erlbeck | cdd4302 | 2014-11-10 11:21:32 +0100 | [diff] [blame] | 23 | |
Max | e6052c4 | 2016-06-30 10:25:49 +0200 | [diff] [blame] | 24 | #include <stdbool.h> |
| 25 | |
Neels Hofmeyr | 77c8d5f | 2016-05-09 19:12:44 +0200 | [diff] [blame] | 26 | struct gsm_network *gsm_network_init(void *ctx, |
| 27 | uint16_t country_code, |
| 28 | uint16_t network_code, |
Jacob Erlbeck | cdd4302 | 2014-11-10 11:21:32 +0100 | [diff] [blame] | 29 | int (*mncc_recv)(struct gsm_network *, struct msgb *)) |
| 30 | { |
| 31 | struct gsm_network *net; |
Max | e443145 | 2016-07-27 12:06:36 +0200 | [diff] [blame] | 32 | const char *default_regexp = ".*"; |
Jacob Erlbeck | cdd4302 | 2014-11-10 11:21:32 +0100 | [diff] [blame] | 33 | |
Neels Hofmeyr | 77c8d5f | 2016-05-09 19:12:44 +0200 | [diff] [blame] | 34 | net = talloc_zero(ctx, struct gsm_network); |
Jacob Erlbeck | cdd4302 | 2014-11-10 11:21:32 +0100 | [diff] [blame] | 35 | if (!net) |
| 36 | return NULL; |
| 37 | |
| 38 | net->bsc_data = talloc_zero(net, struct osmo_bsc_data); |
| 39 | if (!net->bsc_data) { |
| 40 | talloc_free(net); |
| 41 | return NULL; |
| 42 | } |
| 43 | |
Jacob Erlbeck | 1e30a28 | 2014-12-03 09:28:24 +0100 | [diff] [blame] | 44 | net->subscr_group = talloc_zero(net, struct gsm_subscriber_group); |
| 45 | if (!net->subscr_group) { |
| 46 | talloc_free(net); |
| 47 | return NULL; |
| 48 | } |
| 49 | |
Max | e6052c4 | 2016-06-30 10:25:49 +0200 | [diff] [blame] | 50 | if (gsm_parse_reg(net, &net->authorized_regexp, &net->authorized_reg_str, 1, |
| 51 | &default_regexp) != 0) |
| 52 | return NULL; |
| 53 | |
Jacob Erlbeck | cdd4302 | 2014-11-10 11:21:32 +0100 | [diff] [blame] | 54 | /* Init back pointer */ |
| 55 | net->bsc_data->auto_off_timeout = -1; |
| 56 | net->bsc_data->network = net; |
| 57 | INIT_LLIST_HEAD(&net->bsc_data->mscs); |
Holger Hans Peter Freyther | 1ba0730 | 2015-01-27 10:27:53 +0100 | [diff] [blame] | 58 | |
Jacob Erlbeck | 1e30a28 | 2014-12-03 09:28:24 +0100 | [diff] [blame] | 59 | net->subscr_group->net = net; |
Max | e6052c4 | 2016-06-30 10:25:49 +0200 | [diff] [blame] | 60 | net->auto_create_subscr = true; |
| 61 | net->auto_assign_exten = true; |
Jacob Erlbeck | cdd4302 | 2014-11-10 11:21:32 +0100 | [diff] [blame] | 62 | |
| 63 | net->country_code = country_code; |
| 64 | net->network_code = network_code; |
| 65 | net->num_bts = 0; |
| 66 | net->reject_cause = GSM48_REJECT_ROAMING_NOT_ALLOWED; |
| 67 | net->T3101 = GSM_T3101_DEFAULT; |
| 68 | net->T3105 = GSM_T3105_DEFAULT; |
| 69 | net->T3113 = GSM_T3113_DEFAULT; |
| 70 | net->T3122 = GSM_T3122_DEFAULT; |
| 71 | /* FIXME: initialize all other timers! */ |
| 72 | |
| 73 | /* default set of handover parameters */ |
| 74 | net->handover.win_rxlev_avg = 10; |
| 75 | net->handover.win_rxqual_avg = 1; |
| 76 | net->handover.win_rxlev_avg_neigh = 10; |
| 77 | net->handover.pwr_interval = 6; |
| 78 | net->handover.pwr_hysteresis = 3; |
| 79 | net->handover.max_distance = 9999; |
| 80 | |
| 81 | INIT_LLIST_HEAD(&net->trans_list); |
| 82 | INIT_LLIST_HEAD(&net->upqueue); |
| 83 | INIT_LLIST_HEAD(&net->bts_list); |
Neels Hofmeyr | d90fa42 | 2016-05-09 21:03:12 +0200 | [diff] [blame] | 84 | INIT_LLIST_HEAD(&net->subscr_conns); |
Jacob Erlbeck | cdd4302 | 2014-11-10 11:21:32 +0100 | [diff] [blame] | 85 | |
Alexander Couzens | 20423ea | 2016-07-12 15:42:02 +0200 | [diff] [blame] | 86 | /* init statistics */ |
Alexander Couzens | b847a21 | 2016-08-02 11:34:11 +0200 | [diff] [blame] | 87 | net->bsc_ctrs = rate_ctr_group_alloc(net, &bsc_ctrg_desc, 0); |
Alexander Couzens | 4b95b54 | 2016-08-30 14:34:36 +0200 | [diff] [blame] | 88 | net->msc_ctrs = rate_ctr_group_alloc(net, &msc_ctrg_desc, 0); |
Jacob Erlbeck | cdd4302 | 2014-11-10 11:21:32 +0100 | [diff] [blame] | 89 | |
| 90 | net->mncc_recv = mncc_recv; |
Max | 0fcd2e2 | 2016-06-07 15:32:16 +0200 | [diff] [blame] | 91 | net->ext_min = GSM_MIN_EXTEN; |
| 92 | net->ext_max = GSM_MAX_EXTEN; |
Jacob Erlbeck | cdd4302 | 2014-11-10 11:21:32 +0100 | [diff] [blame] | 93 | gsm_net_update_ctype(net); |
| 94 | |
Neels Hofmeyr | 5f0c71b | 2016-07-23 20:15:28 +0200 | [diff] [blame] | 95 | net->dyn_ts_allow_tch_f = true; |
| 96 | |
Jacob Erlbeck | cdd4302 | 2014-11-10 11:21:32 +0100 | [diff] [blame] | 97 | return net; |
| 98 | } |
| 99 | |