blob: 3149580f0233fbc28dcdda24c4457b68154d3510 [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>
Neels Hofmeyr05667a02016-05-10 13:27:32 +020030#include <openbsc/gsm_data.h>
31#include <openbsc/gsm_04_11.h>
Neels Hofmeyre78ae212016-05-14 00:46:29 +020032
33/* Warning: if bsc_network_init() is not called, some of the members of
34 * gsm_network are not initialized properly and must not be used! (In
35 * particular the llist heads and stats counters.)
36 * The long term aim should be to have entirely separate structs for libbsc and
37 * libmsc with some common general items.
38 */
39struct gsm_network *gsm_network_init(void *ctx,
40 uint16_t country_code,
41 uint16_t network_code,
42 mncc_recv_cb_t mncc_recv)
43{
44 struct gsm_network *net;
45
46 const char *default_regexp = ".*";
47
48 net = talloc_zero(ctx, struct gsm_network);
49 if (!net)
50 return NULL;
51
52 net->subscr_group = talloc_zero(net, struct gsm_subscriber_group);
53 if (!net->subscr_group) {
54 talloc_free(net);
55 return NULL;
56 }
57
58 if (gsm_parse_reg(net, &net->authorized_regexp, &net->authorized_reg_str, 1,
59 &default_regexp) != 0)
60 return NULL;
61
62 net->subscr_group->net = net;
63 net->auto_create_subscr = true;
64 net->auto_assign_exten = true;
65
66 net->country_code = country_code;
67 net->network_code = network_code;
68
69 INIT_LLIST_HEAD(&net->trans_list);
70 INIT_LLIST_HEAD(&net->upqueue);
71 INIT_LLIST_HEAD(&net->subscr_conns);
72
73 /* init statistics */
74 net->msc_ctrs = rate_ctr_group_alloc(net, &msc_ctrg_desc, 0);
75 net->active_calls = osmo_counter_alloc("msc.active_calls");
76
77 net->mncc_recv = mncc_recv;
78 net->ext_min = GSM_MIN_EXTEN;
79 net->ext_max = GSM_MAX_EXTEN;
80
81 net->dyn_ts_allow_tch_f = true;
82
83 return net;
84}
Neels Hofmeyr28f637e2016-05-10 14:58:51 +020085
86struct msgb *gsm48_create_mm_serv_rej(enum gsm48_reject_value value)
87{
88 struct msgb *msg;
89 struct gsm48_hdr *gh;
90
91 msg = gsm48_msgb_alloc_name("GSM 04.08 SERV REJ");
92 if (!msg)
93 return NULL;
94
95 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
96 gh->proto_discr = GSM48_PDISC_MM;
97 gh->msg_type = GSM48_MT_MM_CM_SERV_REJ;
98 gh->data[0] = value;
99
100 return msg;
101}
102
103struct msgb *gsm48_create_loc_upd_rej(uint8_t cause)
104{
105 struct gsm48_hdr *gh;
106 struct msgb *msg;
107
108 msg = gsm48_msgb_alloc_name("GSM 04.08 LOC UPD REJ");
109 if (!msg)
110 return NULL;
111
112 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh) + 1);
113 gh->proto_discr = GSM48_PDISC_MM;
114 gh->msg_type = GSM48_MT_MM_LOC_UPD_REJECT;
115 gh->data[0] = cause;
116 return msg;
117}
Neels Hofmeyr05667a02016-05-10 13:27:32 +0200118
119uint8_t sms_next_rp_msg_ref(uint8_t *next_rp_ref)
120{
121 const uint8_t rp_msg_ref = *next_rp_ref;
122 /*
123 * This should wrap as the valid range is 0 to 255. We only
124 * transfer one SMS at a time so we don't need to check if
125 * the id has been already assigned.
126 */
127 *next_rp_ref += 1;
128
129 return rp_msg_ref;
130}