Neels Hofmeyr | c69ee85 | 2016-05-10 12:50:31 +0200 | [diff] [blame] | 1 | /* Code used by both libbsc and libmsc (common_cs means "BSC or MSC"). |
| 2 | * |
| 3 | * (C) 2016 by sysmocom s.m.f.c. <info@sysmocom.de> |
Neels Hofmeyr | e78ae21 | 2016-05-14 00:46:29 +0200 | [diff] [blame^] | 4 | * (C) 2008-2010 by Harald Welte <laforge@gnumonks.org> |
| 5 | * (C) 2014 by Holger Hans Peter Freyther |
Neels Hofmeyr | c69ee85 | 2016-05-10 12:50:31 +0200 | [diff] [blame] | 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * 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 |
| 11 | * (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 |
| 16 | * GNU Affero General Public License for more details. |
| 17 | * |
| 18 | * 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/>. |
| 20 | * |
| 21 | */ |
Neels Hofmeyr | e78ae21 | 2016-05-14 00:46:29 +0200 | [diff] [blame^] | 22 | |
| 23 | #include <stdbool.h> |
| 24 | |
| 25 | #include <osmocom/gsm/gsm0480.h> |
| 26 | |
| 27 | #include <openbsc/common_cs.h> |
| 28 | #include <openbsc/gsm_data.h> |
| 29 | #include <openbsc/gsm_subscriber.h> |
| 30 | |
| 31 | /* Warning: if bsc_network_init() is not called, some of the members of |
| 32 | * gsm_network are not initialized properly and must not be used! (In |
| 33 | * particular the llist heads and stats counters.) |
| 34 | * The long term aim should be to have entirely separate structs for libbsc and |
| 35 | * libmsc with some common general items. |
| 36 | */ |
| 37 | struct gsm_network *gsm_network_init(void *ctx, |
| 38 | uint16_t country_code, |
| 39 | uint16_t network_code, |
| 40 | mncc_recv_cb_t mncc_recv) |
| 41 | { |
| 42 | struct gsm_network *net; |
| 43 | |
| 44 | const char *default_regexp = ".*"; |
| 45 | |
| 46 | net = talloc_zero(ctx, struct gsm_network); |
| 47 | if (!net) |
| 48 | return NULL; |
| 49 | |
| 50 | net->subscr_group = talloc_zero(net, struct gsm_subscriber_group); |
| 51 | if (!net->subscr_group) { |
| 52 | talloc_free(net); |
| 53 | return NULL; |
| 54 | } |
| 55 | |
| 56 | if (gsm_parse_reg(net, &net->authorized_regexp, &net->authorized_reg_str, 1, |
| 57 | &default_regexp) != 0) |
| 58 | return NULL; |
| 59 | |
| 60 | net->subscr_group->net = net; |
| 61 | net->auto_create_subscr = true; |
| 62 | net->auto_assign_exten = true; |
| 63 | |
| 64 | net->country_code = country_code; |
| 65 | net->network_code = network_code; |
| 66 | |
| 67 | INIT_LLIST_HEAD(&net->trans_list); |
| 68 | INIT_LLIST_HEAD(&net->upqueue); |
| 69 | INIT_LLIST_HEAD(&net->subscr_conns); |
| 70 | |
| 71 | /* init statistics */ |
| 72 | net->msc_ctrs = rate_ctr_group_alloc(net, &msc_ctrg_desc, 0); |
| 73 | net->active_calls = osmo_counter_alloc("msc.active_calls"); |
| 74 | |
| 75 | net->mncc_recv = mncc_recv; |
| 76 | net->ext_min = GSM_MIN_EXTEN; |
| 77 | net->ext_max = GSM_MAX_EXTEN; |
| 78 | |
| 79 | net->dyn_ts_allow_tch_f = true; |
| 80 | |
| 81 | return net; |
| 82 | } |