blob: 8d09b7ee3cc541b80f0b06b18c7283c525e67757 [file] [log] [blame]
Neels Hofmeyrc69ee852016-05-10 12:50:31 +02001/* 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 Hofmeyre78ae212016-05-14 00:46:29 +02004 * (C) 2008-2010 by Harald Welte <laforge@gnumonks.org>
5 * (C) 2014 by Holger Hans Peter Freyther
Neels Hofmeyrc69ee852016-05-10 12:50:31 +02006 * 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 Hofmeyre78ae212016-05-14 00:46:29 +020022
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 */
37struct 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}
Neels Hofmeyr28f637e2016-05-10 14:58:51 +020083
84struct msgb *gsm48_create_mm_serv_rej(enum gsm48_reject_value value)
85{
86 struct msgb *msg;
87 struct gsm48_hdr *gh;
88
89 msg = gsm48_msgb_alloc_name("GSM 04.08 SERV REJ");
90 if (!msg)
91 return NULL;
92
93 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
94 gh->proto_discr = GSM48_PDISC_MM;
95 gh->msg_type = GSM48_MT_MM_CM_SERV_REJ;
96 gh->data[0] = value;
97
98 return msg;
99}
100
101struct msgb *gsm48_create_loc_upd_rej(uint8_t cause)
102{
103 struct gsm48_hdr *gh;
104 struct msgb *msg;
105
106 msg = gsm48_msgb_alloc_name("GSM 04.08 LOC UPD REJ");
107 if (!msg)
108 return NULL;
109
110 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
111 gh->proto_discr = GSM48_PDISC_MM;
112 gh->msg_type = GSM48_MT_MM_LOC_UPD_REJECT;
113 gh->data[0] = cause;
114 return msg;
115}