Jacob Erlbeck | c91a576 | 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 | da8770b | 2014-12-03 09:28:24 +0100 | [diff] [blame] | 22 | #include <openbsc/gsm_subscriber.h> |
Jacob Erlbeck | c91a576 | 2014-11-10 11:21:32 +0100 | [diff] [blame] | 23 | |
Max | 5872641 | 2016-06-30 10:25:49 +0200 | [diff] [blame] | 24 | #include <stdbool.h> |
| 25 | |
Jacob Erlbeck | c91a576 | 2014-11-10 11:21:32 +0100 | [diff] [blame] | 26 | struct gsm_network *gsm_network_init(uint16_t country_code, uint16_t network_code, |
| 27 | int (*mncc_recv)(struct gsm_network *, struct msgb *)) |
| 28 | { |
| 29 | struct gsm_network *net; |
Max | 0101068 | 2016-07-27 12:06:36 +0200 | [diff] [blame] | 30 | const char *default_regexp = ".*"; |
Jacob Erlbeck | c91a576 | 2014-11-10 11:21:32 +0100 | [diff] [blame] | 31 | |
| 32 | net = talloc_zero(tall_bsc_ctx, struct gsm_network); |
| 33 | if (!net) |
| 34 | return NULL; |
| 35 | |
| 36 | net->bsc_data = talloc_zero(net, struct osmo_bsc_data); |
| 37 | if (!net->bsc_data) { |
| 38 | talloc_free(net); |
| 39 | return NULL; |
| 40 | } |
| 41 | |
Jacob Erlbeck | da8770b | 2014-12-03 09:28:24 +0100 | [diff] [blame] | 42 | net->subscr_group = talloc_zero(net, struct gsm_subscriber_group); |
| 43 | if (!net->subscr_group) { |
| 44 | talloc_free(net); |
| 45 | return NULL; |
| 46 | } |
| 47 | |
Max | 5872641 | 2016-06-30 10:25:49 +0200 | [diff] [blame] | 48 | if (gsm_parse_reg(net, &net->authorized_regexp, &net->authorized_reg_str, 1, |
| 49 | &default_regexp) != 0) |
| 50 | return NULL; |
| 51 | |
Jacob Erlbeck | c91a576 | 2014-11-10 11:21:32 +0100 | [diff] [blame] | 52 | /* Init back pointer */ |
| 53 | net->bsc_data->auto_off_timeout = -1; |
| 54 | net->bsc_data->network = net; |
| 55 | INIT_LLIST_HEAD(&net->bsc_data->mscs); |
Holger Hans Peter Freyther | d3af802 | 2015-01-27 10:27:53 +0100 | [diff] [blame] | 56 | |
Jacob Erlbeck | da8770b | 2014-12-03 09:28:24 +0100 | [diff] [blame] | 57 | net->subscr_group->net = net; |
Max | 5872641 | 2016-06-30 10:25:49 +0200 | [diff] [blame] | 58 | net->auto_create_subscr = true; |
| 59 | net->auto_assign_exten = true; |
Jacob Erlbeck | c91a576 | 2014-11-10 11:21:32 +0100 | [diff] [blame] | 60 | |
| 61 | net->country_code = country_code; |
| 62 | net->network_code = network_code; |
| 63 | net->num_bts = 0; |
| 64 | net->reject_cause = GSM48_REJECT_ROAMING_NOT_ALLOWED; |
| 65 | net->T3101 = GSM_T3101_DEFAULT; |
| 66 | net->T3105 = GSM_T3105_DEFAULT; |
| 67 | net->T3113 = GSM_T3113_DEFAULT; |
| 68 | net->T3122 = GSM_T3122_DEFAULT; |
| 69 | /* FIXME: initialize all other timers! */ |
| 70 | |
| 71 | /* default set of handover parameters */ |
| 72 | net->handover.win_rxlev_avg = 10; |
| 73 | net->handover.win_rxqual_avg = 1; |
| 74 | net->handover.win_rxlev_avg_neigh = 10; |
| 75 | net->handover.pwr_interval = 6; |
| 76 | net->handover.pwr_hysteresis = 3; |
| 77 | net->handover.max_distance = 9999; |
| 78 | |
| 79 | INIT_LLIST_HEAD(&net->trans_list); |
| 80 | INIT_LLIST_HEAD(&net->upqueue); |
| 81 | INIT_LLIST_HEAD(&net->bts_list); |
| 82 | |
| 83 | net->stats.chreq.total = osmo_counter_alloc("net.chreq.total"); |
| 84 | net->stats.chreq.no_channel = osmo_counter_alloc("net.chreq.no_channel"); |
| 85 | net->stats.handover.attempted = osmo_counter_alloc("net.handover.attempted"); |
| 86 | net->stats.handover.no_channel = osmo_counter_alloc("net.handover.no_channel"); |
| 87 | net->stats.handover.timeout = osmo_counter_alloc("net.handover.timeout"); |
| 88 | net->stats.handover.completed = osmo_counter_alloc("net.handover.completed"); |
| 89 | net->stats.handover.failed = osmo_counter_alloc("net.handover.failed"); |
| 90 | net->stats.loc_upd_type.attach = osmo_counter_alloc("net.loc_upd_type.attach"); |
| 91 | net->stats.loc_upd_type.normal = osmo_counter_alloc("net.loc_upd_type.normal"); |
| 92 | net->stats.loc_upd_type.periodic = osmo_counter_alloc("net.loc_upd_type.periodic"); |
| 93 | net->stats.loc_upd_type.detach = osmo_counter_alloc("net.imsi_detach.count"); |
| 94 | net->stats.loc_upd_resp.reject = osmo_counter_alloc("net.loc_upd_resp.reject"); |
| 95 | net->stats.loc_upd_resp.accept = osmo_counter_alloc("net.loc_upd_resp.accept"); |
| 96 | net->stats.paging.attempted = osmo_counter_alloc("net.paging.attempted"); |
| 97 | net->stats.paging.detached = osmo_counter_alloc("net.paging.detached"); |
| 98 | net->stats.paging.completed = osmo_counter_alloc("net.paging.completed"); |
| 99 | net->stats.paging.expired = osmo_counter_alloc("net.paging.expired"); |
| 100 | net->stats.sms.submitted = osmo_counter_alloc("net.sms.submitted"); |
| 101 | net->stats.sms.no_receiver = osmo_counter_alloc("net.sms.no_receiver"); |
| 102 | net->stats.sms.delivered = osmo_counter_alloc("net.sms.delivered"); |
| 103 | net->stats.sms.rp_err_mem = osmo_counter_alloc("net.sms.rp_err_mem"); |
| 104 | net->stats.sms.rp_err_other = osmo_counter_alloc("net.sms.rp_err_other"); |
| 105 | net->stats.call.mo_setup = osmo_counter_alloc("net.call.mo_setup"); |
| 106 | net->stats.call.mo_connect_ack = osmo_counter_alloc("net.call.mo_connect_ack"); |
| 107 | net->stats.call.mt_setup = osmo_counter_alloc("net.call.mt_setup"); |
| 108 | net->stats.call.mt_connect = osmo_counter_alloc("net.call.mt_connect"); |
| 109 | net->stats.chan.rf_fail = osmo_counter_alloc("net.chan.rf_fail"); |
| 110 | net->stats.chan.rll_err = osmo_counter_alloc("net.chan.rll_err"); |
| 111 | net->stats.bts.oml_fail = osmo_counter_alloc("net.bts.oml_fail"); |
| 112 | net->stats.bts.rsl_fail = osmo_counter_alloc("net.bts.rsl_fail"); |
| 113 | |
| 114 | net->mncc_recv = mncc_recv; |
Max | 3911533 | 2016-06-07 15:32:16 +0200 | [diff] [blame] | 115 | net->ext_min = GSM_MIN_EXTEN; |
| 116 | net->ext_max = GSM_MAX_EXTEN; |
Jacob Erlbeck | c91a576 | 2014-11-10 11:21:32 +0100 | [diff] [blame] | 117 | gsm_net_update_ctype(net); |
| 118 | |
Neels Hofmeyr | f8d6053 | 2016-07-23 20:15:28 +0200 | [diff] [blame] | 119 | net->dyn_ts_allow_tch_f = true; |
| 120 | |
Jacob Erlbeck | c91a576 | 2014-11-10 11:21:32 +0100 | [diff] [blame] | 121 | return net; |
| 122 | } |
| 123 | |