blob: 01e44f37f45abd8b99ab6f62407d7f7e8fd6c790 [file] [log] [blame]
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +08001/* main MSC management code... */
2
3/*
Holger Hans Peter Freythere7bd8632013-06-30 15:30:47 +02004 * (C) 2010,2013 by Holger Hans Peter Freyther <zecke@selfish.org>
Holger Hans Peter Freyther85531cc2010-10-06 20:37:09 +08005 * (C) 2010 by On-Waves
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +08006 *
7 * All Rights Reserved
8 *
9 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +010010 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +080012 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte9af6ddf2011-01-01 15:25:50 +010017 * GNU Affero General Public License for more details.
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +080018 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010019 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +080021 *
22 */
23
Neels Hofmeyr90843962017-09-04 15:04:35 +020024#include <osmocom/msc/osmo_msc.h>
Neels Hofmeyr90843962017-09-04 15:04:35 +020025#include <osmocom/msc/debug.h>
26#include <osmocom/msc/transaction.h>
27#include <osmocom/msc/db.h>
28#include <osmocom/msc/vlr.h>
29#include <osmocom/msc/osmo_msc.h>
30#include <osmocom/msc/a_iface.h>
Max43b01b02017-09-15 11:22:30 +020031#include <osmocom/msc/gsm_04_08.h>
Neels Hofmeyr90843962017-09-04 15:04:35 +020032#include <osmocom/msc/gsm_04_11.h>
Holger Hans Peter Freyther6a3d7652010-06-15 12:03:10 +080033
Neels Hofmeyr00e82d62017-07-05 15:19:52 +020034#include "../../bscconfig.h"
35#ifdef BUILD_IU
36#include <osmocom/ranap/iu_client.h>
37#else
Neels Hofmeyr90843962017-09-04 15:04:35 +020038#include <osmocom/msc/iu_dummy.h>
Neels Hofmeyr00e82d62017-07-05 15:19:52 +020039#endif
40
Harald Welte2483f1b2016-06-19 18:06:02 +020041/* Receive a SAPI-N-REJECT from BSC */
Philipp Maierfbf66102017-04-09 12:32:51 +020042void msc_sapi_n_reject(struct gsm_subscriber_connection *conn, int dlci)
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +080043{
Holger Hans Peter Freyther6a3d7652010-06-15 12:03:10 +080044 int sapi = dlci & 0x7;
45
46 if (sapi == UM_SAPI_SMS)
47 gsm411_sapi_n_reject(conn);
Holger Hans Peter Freyther43b09092010-06-15 11:52:51 +080048}
49
Neels Hofmeyre9e2f5c2018-03-15 13:26:43 +010050static void subscr_conn_release_when_unused(struct gsm_subscriber_connection *conn)
Harald Welte2483f1b2016-06-19 18:06:02 +020051{
52 if (!conn)
53 return;
54 if (!conn->conn_fsm)
55 return;
56 if (!(conn->conn_fsm->state == SUBSCR_CONN_S_ACCEPTED
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020057 || conn->conn_fsm->state == SUBSCR_CONN_S_COMMUNICATING)) {
Neels Hofmeyre9e2f5c2018-03-15 13:26:43 +010058 DEBUGP(DMM, "%s: %s: conn still being established (%s)\n",
59 vlr_subscr_name(conn->vsub), __func__,
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020060 osmo_fsm_inst_state_name(conn->conn_fsm));
Harald Welte2483f1b2016-06-19 18:06:02 +020061 return;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020062 }
Neels Hofmeyre9e2f5c2018-03-15 13:26:43 +010063 osmo_fsm_inst_dispatch(conn->conn_fsm, SUBSCR_CONN_E_RELEASE_WHEN_UNUSED, NULL);
Harald Welte2483f1b2016-06-19 18:06:02 +020064}
65
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020066/* receive a Level 3 Complete message and return MSC_CONN_ACCEPT or
67 * MSC_CONN_REJECT */
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020068int msc_compl_l3(struct gsm_subscriber_connection *conn,
69 struct msgb *msg, uint16_t chosen_channel)
Holger Hans Peter Freyther97643312010-06-17 16:41:25 +080070{
Neels Hofmeyr6166f292017-11-22 14:33:12 +010071 msc_subscr_conn_get(conn, MSC_CONN_USE_COMPL_L3);
Holger Hans Peter Freyther97643312010-06-17 16:41:25 +080072 gsm0408_dispatch(conn, msg);
73
Neels Hofmeyre9e2f5c2018-03-15 13:26:43 +010074 subscr_conn_release_when_unused(conn);
Harald Welte2483f1b2016-06-19 18:06:02 +020075
76 /* If this should be kept, the conn->conn_fsm has placed a use_count */
Neels Hofmeyr6166f292017-11-22 14:33:12 +010077 msc_subscr_conn_put(conn, MSC_CONN_USE_COMPL_L3);
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020078
79 /* Always return acceptance, because even if the conn was not accepted,
80 * we assumed ownership of it and the caller shall not interfere with
81 * that. We may even already have discarded the conn. */
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020082 return MSC_CONN_ACCEPT;
Harald Welte2483f1b2016-06-19 18:06:02 +020083
84#if 0
Holger Hans Peter Freythere9f420d2016-02-10 10:42:20 +010085 /*
86 * If this is a silent call we want the channel to remain open as long as
87 * possible and this is why we accept this connection regardless of any
88 * pending transaction or ongoing operation.
89 */
Holger Hans Peter Freyther70ae5d32012-11-23 21:33:15 +010090 if (conn->silent_call)
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020091 return MSC_CONN_ACCEPT;
92 if (conn->loc_operation || conn->sec_operation || conn->anch_operation)
93 return MSC_CONN_ACCEPT;
Holger Hans Peter Freyther70ae5d32012-11-23 21:33:15 +010094 if (trans_has_conn(conn))
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020095 return MSC_CONN_ACCEPT;
Jacob Erlbeck8e68b562014-01-30 21:01:12 +010096
97 LOGP(DRR, LOGL_INFO, "MSC Complete L3: Rejecting connection.\n");
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020098 return MSC_CONN_REJECT;
Harald Welte2483f1b2016-06-19 18:06:02 +020099#endif
Holger Hans Peter Freyther97643312010-06-17 16:41:25 +0800100}
101
Harald Welte2483f1b2016-06-19 18:06:02 +0200102/* Receive a DTAP message from BSC */
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200103void msc_dtap(struct gsm_subscriber_connection *conn, uint8_t link_id, struct msgb *msg)
Holger Hans Peter Freyther97643312010-06-17 16:41:25 +0800104{
Neels Hofmeyr6166f292017-11-22 14:33:12 +0100105 msc_subscr_conn_get(conn, MSC_CONN_USE_DTAP);
Holger Hans Peter Freyther97643312010-06-17 16:41:25 +0800106 gsm0408_dispatch(conn, msg);
Harald Welte2483f1b2016-06-19 18:06:02 +0200107
Neels Hofmeyre9e2f5c2018-03-15 13:26:43 +0100108 subscr_conn_release_when_unused(conn);
Neels Hofmeyr6166f292017-11-22 14:33:12 +0100109 msc_subscr_conn_put(conn, MSC_CONN_USE_DTAP);
Holger Hans Peter Freyther97643312010-06-17 16:41:25 +0800110}
111
Harald Welte2483f1b2016-06-19 18:06:02 +0200112/* Receive an ASSIGNMENT COMPLETE from BSC */
Philipp Maierfbf66102017-04-09 12:32:51 +0200113void msc_assign_compl(struct gsm_subscriber_connection *conn,
114 uint8_t rr_cause, uint8_t chosen_channel,
115 uint8_t encr_alg_id, uint8_t speec)
Holger Hans Peter Freyther40aac3f2011-12-27 12:31:02 +0100116{
Jacob Erlbeck8e68b562014-01-30 21:01:12 +0100117 LOGP(DRR, LOGL_DEBUG, "MSC assign complete (do nothing).\n");
Holger Hans Peter Freyther40aac3f2011-12-27 12:31:02 +0100118}
119
Harald Welte2483f1b2016-06-19 18:06:02 +0200120/* Receive an ASSIGNMENT FAILURE from BSC */
Philipp Maierfbf66102017-04-09 12:32:51 +0200121void msc_assign_fail(struct gsm_subscriber_connection *conn,
122 uint8_t cause, uint8_t *rr_cause)
Holger Hans Peter Freyther40aac3f2011-12-27 12:31:02 +0100123{
Jacob Erlbeck8e68b562014-01-30 21:01:12 +0100124 LOGP(DRR, LOGL_DEBUG, "MSC assign failure (do nothing).\n");
Holger Hans Peter Freyther40aac3f2011-12-27 12:31:02 +0100125}
126
Harald Welte2483f1b2016-06-19 18:06:02 +0200127/* Receive a CLASSMARK CHANGE from BSC */
Philipp Maierfbf66102017-04-09 12:32:51 +0200128void msc_classmark_chg(struct gsm_subscriber_connection *conn,
129 const uint8_t *cm2, uint8_t cm2_len,
130 const uint8_t *cm3, uint8_t cm3_len)
Harald Welte95e862c2012-01-23 10:28:35 +0100131{
Harald Welte2483f1b2016-06-19 18:06:02 +0200132 if (cm2 && cm2_len) {
133 if (cm2_len > sizeof(conn->classmark.classmark2)) {
134 LOGP(DRR, LOGL_NOTICE, "%s: classmark2 is %u bytes, truncating at %zu bytes\n",
135 vlr_subscr_name(conn->vsub), cm2_len, sizeof(conn->classmark.classmark2));
136 cm2_len = sizeof(conn->classmark.classmark2);
Harald Welte95e862c2012-01-23 10:28:35 +0100137 }
Harald Welte2483f1b2016-06-19 18:06:02 +0200138 conn->classmark.classmark2_len = cm2_len;
139 memcpy(conn->classmark.classmark2, cm2, cm2_len);
140 }
141 if (cm3 && cm3_len) {
142 if (cm3_len > sizeof(conn->classmark.classmark3)) {
143 LOGP(DRR, LOGL_NOTICE, "%s: classmark3 is %u bytes, truncating at %zu bytes\n",
144 vlr_subscr_name(conn->vsub), cm3_len, sizeof(conn->classmark.classmark3));
145 cm3_len = sizeof(conn->classmark.classmark3);
146 }
147 conn->classmark.classmark3_len = cm3_len;
148 memcpy(conn->classmark.classmark3, cm3, cm3_len);
Harald Welte95e862c2012-01-23 10:28:35 +0100149 }
150}
151
Harald Welte2483f1b2016-06-19 18:06:02 +0200152/* Receive a CIPHERING MODE COMPLETE from BSC */
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200153void msc_cipher_mode_compl(struct gsm_subscriber_connection *conn,
154 struct msgb *msg, uint8_t alg_id)
Harald Weltecf149ee2012-01-23 16:40:24 +0100155{
Harald Welte2483f1b2016-06-19 18:06:02 +0200156 struct vlr_ciph_result ciph_res = { .cause = VLR_CIPH_REJECT };
Harald Weltecf149ee2012-01-23 16:40:24 +0100157
Harald Welte2483f1b2016-06-19 18:06:02 +0200158 if (!conn) {
Harald Welte284c39a2018-01-24 22:38:06 +0100159 LOGP(DRR, LOGL_ERROR, "invalid: rx Ciphering Mode Complete on NULL conn\n");
Harald Welte2483f1b2016-06-19 18:06:02 +0200160 return;
161 }
162 if (!conn->vsub) {
Harald Welte284c39a2018-01-24 22:38:06 +0100163 LOGP(DRR, LOGL_ERROR, "invalid: rx Ciphering Mode Complete for NULL subscr\n");
Harald Welte2483f1b2016-06-19 18:06:02 +0200164 return;
Harald Weltecf149ee2012-01-23 16:40:24 +0100165 }
166
Harald Welte284c39a2018-01-24 22:38:06 +0100167 DEBUGP(DRR, "%s: CIPHERING MODE COMPLETE\n", vlr_subscr_name(conn->vsub));
Harald Welte2483f1b2016-06-19 18:06:02 +0200168
Harald Welte284c39a2018-01-24 22:38:06 +0100169 if (msg) {
170 struct gsm48_hdr *gh = msgb_l3(msg);
171 unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh);
172 struct tlv_parsed tp;
173 uint8_t mi_type;
Harald Welte2483f1b2016-06-19 18:06:02 +0200174
Harald Welte284c39a2018-01-24 22:38:06 +0100175 if (!gh) {
176 LOGP(DRR, LOGL_ERROR, "invalid: msgb without l3 header\n");
177 return;
178 }
179
180 tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0);
181
182 /* bearer capability */
183 if (TLVP_PRESENT(&tp, GSM48_IE_MOBILE_ID)) {
184 mi_type = TLVP_VAL(&tp, GSM48_IE_MOBILE_ID)[0] & GSM_MI_TYPE_MASK;
185 if (mi_type == GSM_MI_TYPE_IMEISV
186 && TLVP_LEN(&tp, GSM48_IE_MOBILE_ID) > 0) {
Neels Hofmeyrfa10eda2018-03-13 01:22:01 +0100187 gsm48_mi_to_string(ciph_res.imeisv, sizeof(ciph_res.imeisv),
Harald Welte284c39a2018-01-24 22:38:06 +0100188 TLVP_VAL(&tp, GSM48_IE_MOBILE_ID),
189 TLVP_LEN(&tp, GSM48_IE_MOBILE_ID));
Harald Welte284c39a2018-01-24 22:38:06 +0100190 }
Harald Welte2483f1b2016-06-19 18:06:02 +0200191 }
192 }
193
194 ciph_res.cause = VLR_CIPH_COMPL;
195 vlr_subscr_rx_ciph_res(conn->vsub, &ciph_res);
Harald Weltecf149ee2012-01-23 16:40:24 +0100196}
197
Harald Welte2483f1b2016-06-19 18:06:02 +0200198struct gsm_subscriber_connection *msc_subscr_con_allocate(struct gsm_network *network)
199{
200 struct gsm_subscriber_connection *conn;
Harald Welte95e862c2012-01-23 10:28:35 +0100201
Harald Welte2483f1b2016-06-19 18:06:02 +0200202 conn = talloc_zero(network, struct gsm_subscriber_connection);
203 if (!conn)
204 return NULL;
Harald Welte95e862c2012-01-23 10:28:35 +0100205
Harald Welte2483f1b2016-06-19 18:06:02 +0200206 conn->network = network;
207 llist_add_tail(&conn->entry, &network->subscr_conns);
208 return conn;
209}
210
211void msc_subscr_cleanup(struct vlr_subscr *vsub)
212{
213 if (!vsub)
214 return;
215 vsub->lu_fsm = NULL;
216}
217
218void msc_subscr_con_cleanup(struct gsm_subscriber_connection *conn)
219{
220 if (!conn)
221 return;
222
223 if (conn->vsub) {
224 DEBUGP(DRLL, "subscr %s: Freeing subscriber connection\n",
225 vlr_subscr_name(conn->vsub));
226 msc_subscr_cleanup(conn->vsub);
Neels Hofmeyr1db394f2018-03-09 17:04:53 +0100227 conn->vsub->msc_conn_ref = NULL;
Harald Welte2483f1b2016-06-19 18:06:02 +0200228 vlr_subscr_put(conn->vsub);
229 conn->vsub = NULL;
230 } else
231 DEBUGP(DRLL, "Freeing subscriber connection"
232 " with NULL subscriber\n");
233
234 if (!conn->conn_fsm)
235 return;
236
237 osmo_fsm_inst_term(conn->conn_fsm,
238 (conn->conn_fsm->state == SUBSCR_CONN_S_RELEASED)
239 ? OSMO_FSM_TERM_REGULAR
240 : OSMO_FSM_TERM_ERROR,
241 NULL);
242}
243
244void msc_subscr_con_free(struct gsm_subscriber_connection *conn)
245{
246 if (!conn)
247 return;
248
249 msc_subscr_con_cleanup(conn);
250
251 llist_del(&conn->entry);
252 talloc_free(conn);
253}
254
255/* Receive a CLEAR REQUEST from BSC */
Philipp Maierfbf66102017-04-09 12:32:51 +0200256int msc_clear_request(struct gsm_subscriber_connection *conn, uint32_t cause)
Harald Welte2483f1b2016-06-19 18:06:02 +0200257{
258 msc_subscr_conn_close(conn, cause);
259 return 1;
260}
261
Harald Welte2483f1b2016-06-19 18:06:02 +0200262static void msc_subscr_conn_release_all(struct gsm_subscriber_connection *conn, uint32_t cause)
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +0800263{
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +0800264 if (conn->in_release)
265 return;
Harald Welte2483f1b2016-06-19 18:06:02 +0200266 conn->in_release = true;
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +0800267
Harald Welte2483f1b2016-06-19 18:06:02 +0200268 /* If we're closing in a middle of a trans, we need to clean up */
269 trans_conn_closed(conn);
270
271 switch (conn->via_ran) {
272 case RAN_UTRAN_IU:
Neels Hofmeyr00e82d62017-07-05 15:19:52 +0200273 ranap_iu_tx_release(conn->iu.ue_ctx, NULL);
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200274 /* FIXME: keep the conn until the Iu Release Outcome is
275 * received from the UE, or a timeout expires. For now, the log
276 * says "unknown UE" for each release outcome. */
Harald Welte2483f1b2016-06-19 18:06:02 +0200277 break;
278 case RAN_GERAN_A:
Philipp Maierfbf66102017-04-09 12:32:51 +0200279 a_iface_tx_clear_cmd(conn);
Harald Welte2483f1b2016-06-19 18:06:02 +0200280 break;
281 default:
282 LOGP(DMM, LOGL_ERROR, "%s: Unknown RAN type, cannot tx release/clear\n",
283 vlr_subscr_name(conn->vsub));
284 break;
285 }
286}
287
288/* If the conn->conn_fsm is still present, dispatch SUBSCR_CONN_E_CN_CLOSE
289 * event to gracefully terminate the connection. If the conn_fsm is already
290 * cleared, call msc_subscr_conn_release_all() to take release actions.
291 * \param cause a GSM_CAUSE_* constant, e.g. GSM_CAUSE_AUTH_FAILED.
292 */
293void msc_subscr_conn_close(struct gsm_subscriber_connection *conn,
294 uint32_t cause)
295{
296 if (!conn)
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +0800297 return;
Harald Welte2483f1b2016-06-19 18:06:02 +0200298 if (conn->in_release) {
299 DEBUGP(DMM, "msc_subscr_conn_close(vsub=%s, cause=%u):"
300 " already dispatching release, ignore.\n",
301 vlr_subscr_name(conn->vsub), cause);
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +0800302 return;
Harald Welte2483f1b2016-06-19 18:06:02 +0200303 }
304 if (!conn->conn_fsm) {
305 DEBUGP(DMM, "msc_subscr_conn_close(vsub=%s, cause=%u): no conn fsm,"
306 " releasing directly without release event.\n",
307 vlr_subscr_name(conn->vsub), cause);
308 /* In case of an IMSI Detach, we don't have conn_fsm. Release
309 * anyway to ensure a timely Iu Release / BSSMAP Clear. */
310 msc_subscr_conn_release_all(conn, cause);
Holger Hans Peter Freyther70ae5d32012-11-23 21:33:15 +0100311 return;
Harald Welte2483f1b2016-06-19 18:06:02 +0200312 }
313 if (conn->conn_fsm->state == SUBSCR_CONN_S_RELEASED) {
314 DEBUGP(DMM, "msc_subscr_conn_close(vsub=%s, cause=%u):"
315 " conn fsm already releasing, ignore.\n",
316 vlr_subscr_name(conn->vsub), cause);
317 return;
318 }
319 osmo_fsm_inst_dispatch(conn->conn_fsm, SUBSCR_CONN_E_CN_CLOSE, &cause);
320}
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +0800321
Harald Welte2483f1b2016-06-19 18:06:02 +0200322/* increment the ref-count. Needs to be called by every user */
323struct gsm_subscriber_connection *
324_msc_subscr_conn_get(struct gsm_subscriber_connection *conn,
Neels Hofmeyr6166f292017-11-22 14:33:12 +0100325 enum msc_subscr_conn_use balance_token,
Harald Welte2483f1b2016-06-19 18:06:02 +0200326 const char *file, int line)
327{
328 OSMO_ASSERT(conn);
Holger Hans Peter Freythere7bd8632013-06-30 15:30:47 +0200329
Harald Welte2483f1b2016-06-19 18:06:02 +0200330 if (conn->in_release)
Neels Hofmeyr785fadc2017-11-22 14:44:35 +0100331 LOGPSRC(DREF, LOGL_ERROR, file, line,
332 "%s: MSC conn use error: using conn that is already in release (%s)\n",
333 vlr_subscr_name(conn->vsub),
334 msc_subscr_conn_use_name(balance_token));
Holger Hans Peter Freythere7bd8632013-06-30 15:30:47 +0200335
Neels Hofmeyr6166f292017-11-22 14:33:12 +0100336 if (balance_token != MSC_CONN_USE_UNTRACKED) {
337 uint32_t flag = 1 << balance_token;
338 OSMO_ASSERT(balance_token < 32);
339 if (conn->use_tokens & flag)
340 LOGPSRC(DREF, LOGL_ERROR, file, line,
341 "%s: MSC conn use error: using an already used token: %s\n",
342 vlr_subscr_name(conn->vsub),
343 msc_subscr_conn_use_name(balance_token));
344 conn->use_tokens |= flag;
345 }
346
Harald Welte2483f1b2016-06-19 18:06:02 +0200347 conn->use_count++;
348 LOGPSRC(DREF, LOGL_DEBUG, file, line,
Neels Hofmeyr6166f292017-11-22 14:33:12 +0100349 "%s: MSC conn use + %s == %u (0x%x)\n",
350 vlr_subscr_name(conn->vsub), msc_subscr_conn_use_name(balance_token),
351 conn->use_count, conn->use_tokens);
Harald Welte2483f1b2016-06-19 18:06:02 +0200352
353 return conn;
354}
355
356/* decrement the ref-count. Once it reaches zero, we release */
357void _msc_subscr_conn_put(struct gsm_subscriber_connection *conn,
Neels Hofmeyr6166f292017-11-22 14:33:12 +0100358 enum msc_subscr_conn_use balance_token,
Harald Welte2483f1b2016-06-19 18:06:02 +0200359 const char *file, int line)
360{
361 OSMO_ASSERT(conn);
362
Neels Hofmeyr6166f292017-11-22 14:33:12 +0100363 if (balance_token != MSC_CONN_USE_UNTRACKED) {
364 uint32_t flag = 1 << balance_token;
365 OSMO_ASSERT(balance_token < 32);
366 if (!(conn->use_tokens & flag))
367 LOGPSRC(DREF, LOGL_ERROR, file, line,
368 "%s: MSC conn use error: freeing an unused token: %s\n",
369 vlr_subscr_name(conn->vsub),
370 msc_subscr_conn_use_name(balance_token));
371 conn->use_tokens &= ~flag;
372 }
373
Harald Welte2483f1b2016-06-19 18:06:02 +0200374 if (conn->use_count == 0) {
375 LOGPSRC(DREF, LOGL_ERROR, file, line,
Neels Hofmeyr6166f292017-11-22 14:33:12 +0100376 "%s: MSC conn use - %s failed: is already 0\n",
377 vlr_subscr_name(conn->vsub),
378 msc_subscr_conn_use_name(balance_token));
Harald Welte2483f1b2016-06-19 18:06:02 +0200379 return;
380 }
381
382 conn->use_count--;
383 LOGPSRC(DREF, LOGL_DEBUG, file, line,
Neels Hofmeyr6166f292017-11-22 14:33:12 +0100384 "%s: MSC conn use - %s == %u (0x%x)\n",
385 vlr_subscr_name(conn->vsub), msc_subscr_conn_use_name(balance_token),
386 conn->use_count, conn->use_tokens);
Harald Welte2483f1b2016-06-19 18:06:02 +0200387
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200388 if (conn->use_count == 0)
389 msc_subscr_con_free(conn);
390}
391
Neels Hofmeyr6166f292017-11-22 14:33:12 +0100392const struct value_string msc_subscr_conn_use_names[] = {
393 {MSC_CONN_USE_UNTRACKED, "UNTRACKED"},
394 {MSC_CONN_USE_COMPL_L3, "compl_l3"},
395 {MSC_CONN_USE_DTAP, "dtap"},
396 {MSC_CONN_USE_FSM, "fsm"},
397 {MSC_CONN_USE_TRANS_CC, "trans_cc"},
398 {MSC_CONN_USE_TRANS_SMS, "trans_sms"},
399 {MSC_CONN_USE_TRANS_USSD, "trans_ussd"},
400 {MSC_CONN_USE_SILENT_CALL, "silent_call"},
401 {0, NULL},
402};
403
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200404void msc_stop_paging(struct vlr_subscr *vsub)
405{
406 DEBUGP(DPAG, "Paging can stop for %s\n", vlr_subscr_name(vsub));
407 /* tell BSCs and RNCs to stop paging? How? */
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +0800408}