Holger Hans Peter Freyther | 43b0909 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 1 | /* main MSC management code... */ |
| 2 | |
| 3 | /* |
Holger Hans Peter Freyther | e7bd863 | 2013-06-30 15:30:47 +0200 | [diff] [blame] | 4 | * (C) 2010,2013 by Holger Hans Peter Freyther <zecke@selfish.org> |
Holger Hans Peter Freyther | 85531cc | 2010-10-06 20:37:09 +0800 | [diff] [blame] | 5 | * (C) 2010 by On-Waves |
Holger Hans Peter Freyther | 43b0909 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 6 | * |
| 7 | * All Rights Reserved |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 10 | * 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 Freyther | 43b0909 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 12 | * (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 Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 17 | * GNU Affero General Public License for more details. |
Holger Hans Peter Freyther | 43b0909 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 18 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 19 | * 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 Freyther | 43b0909 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 21 | * |
| 22 | */ |
| 23 | |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 24 | #include <osmocom/msc/debug.h> |
| 25 | #include <osmocom/msc/transaction.h> |
| 26 | #include <osmocom/msc/db.h> |
| 27 | #include <osmocom/msc/vlr.h> |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 28 | #include <osmocom/msc/a_iface.h> |
Max | 43b01b0 | 2017-09-15 11:22:30 +0200 | [diff] [blame] | 29 | #include <osmocom/msc/gsm_04_08.h> |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 30 | #include <osmocom/msc/gsm_04_11.h> |
Holger Hans Peter Freyther | 6a3d765 | 2010-06-15 12:03:10 +0800 | [diff] [blame] | 31 | |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 32 | #include "../../bscconfig.h" |
| 33 | #ifdef BUILD_IU |
| 34 | #include <osmocom/ranap/iu_client.h> |
| 35 | #else |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 36 | #include <osmocom/msc/iu_dummy.h> |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 37 | #endif |
| 38 | |
Neels Hofmeyr | 55014d0 | 2018-03-22 16:43:40 +0100 | [diff] [blame] | 39 | struct gsm_network *gsm_network_init(void *ctx, mncc_recv_cb_t mncc_recv) |
| 40 | { |
| 41 | struct gsm_network *net; |
| 42 | |
| 43 | net = talloc_zero(ctx, struct gsm_network); |
| 44 | if (!net) |
| 45 | return NULL; |
| 46 | |
| 47 | net->plmn = (struct osmo_plmn_id){ .mcc=1, .mnc=1 }; |
| 48 | |
| 49 | /* Permit a compile-time default of A5/3 and A5/1 */ |
| 50 | net->a5_encryption_mask = (1 << 3) | (1 << 1); |
| 51 | |
| 52 | /* Use 30 min periodic update interval as sane default */ |
| 53 | net->t3212 = 5; |
| 54 | |
Philipp Maier | 9ca7b31 | 2018-10-10 17:00:49 +0200 | [diff] [blame] | 55 | net->mncc_guard_timeout = 180; |
| 56 | |
Neels Hofmeyr | 55014d0 | 2018-03-22 16:43:40 +0100 | [diff] [blame] | 57 | net->paging_response_timer = MSC_PAGING_RESPONSE_TIMER_DEFAULT; |
| 58 | |
| 59 | INIT_LLIST_HEAD(&net->trans_list); |
| 60 | INIT_LLIST_HEAD(&net->upqueue); |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 61 | INIT_LLIST_HEAD(&net->ran_conns); |
Neels Hofmeyr | 55014d0 | 2018-03-22 16:43:40 +0100 | [diff] [blame] | 62 | |
| 63 | /* init statistics */ |
| 64 | net->msc_ctrs = rate_ctr_group_alloc(net, &msc_ctrg_desc, 0); |
| 65 | if (!net->msc_ctrs) { |
| 66 | talloc_free(net); |
| 67 | return NULL; |
| 68 | } |
| 69 | net->active_calls = osmo_counter_alloc("msc.active_calls"); |
Vadim Yanitskiy | ad64e2a | 2018-06-26 18:27:25 +0700 | [diff] [blame] | 70 | net->active_nc_ss = osmo_counter_alloc("msc.active_nc_ss"); |
Neels Hofmeyr | 55014d0 | 2018-03-22 16:43:40 +0100 | [diff] [blame] | 71 | |
| 72 | net->mncc_recv = mncc_recv; |
| 73 | |
| 74 | INIT_LLIST_HEAD(&net->a.bscs); |
| 75 | |
| 76 | return net; |
| 77 | } |
| 78 | |
Neels Hofmeyr | 80447eb | 2018-12-05 01:11:28 +0100 | [diff] [blame] | 79 | void gsm_network_set_mncc_sock_path(struct gsm_network *net, const char *mncc_sock_path) |
| 80 | { |
| 81 | if (net->mncc_sock_path) |
| 82 | talloc_free(net->mncc_sock_path); |
| 83 | net->mncc_sock_path = mncc_sock_path ? talloc_strdup(net, mncc_sock_path) : NULL; |
| 84 | } |
| 85 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 86 | /* Receive a SAPI-N-REJECT from BSC */ |
Neels Hofmeyr | 3c20a5e | 2018-11-30 01:08:36 +0100 | [diff] [blame] | 87 | void ran_conn_sapi_n_reject(struct ran_conn *conn, int dlci) |
Holger Hans Peter Freyther | 43b0909 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 88 | { |
Holger Hans Peter Freyther | 6a3d765 | 2010-06-15 12:03:10 +0800 | [diff] [blame] | 89 | int sapi = dlci & 0x7; |
| 90 | |
| 91 | if (sapi == UM_SAPI_SMS) |
| 92 | gsm411_sapi_n_reject(conn); |
Holger Hans Peter Freyther | 43b0909 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 93 | } |
| 94 | |
Neels Hofmeyr | d03e728 | 2018-11-30 01:20:32 +0100 | [diff] [blame] | 95 | /* receive a Level 3 Complete message. |
| 96 | * Ownership of the conn is completely passed to the conn FSM, i.e. for both acceptance and rejection, |
| 97 | * the conn FSM shall decide when to release this conn. It may already be discarded before this exits. */ |
Neels Hofmeyr | 3c20a5e | 2018-11-30 01:08:36 +0100 | [diff] [blame] | 98 | void ran_conn_compl_l3(struct ran_conn *conn, |
| 99 | struct msgb *msg, uint16_t chosen_channel) |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 100 | { |
Neels Hofmeyr | 3c20a5e | 2018-11-30 01:08:36 +0100 | [diff] [blame] | 101 | ran_conn_get(conn, RAN_CONN_USE_COMPL_L3); |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 102 | gsm0408_dispatch(conn, msg); |
Neels Hofmeyr | 3c20a5e | 2018-11-30 01:08:36 +0100 | [diff] [blame] | 103 | ran_conn_put(conn, RAN_CONN_USE_COMPL_L3); |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 104 | } |
| 105 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 106 | /* Receive a DTAP message from BSC */ |
Neels Hofmeyr | 3c20a5e | 2018-11-30 01:08:36 +0100 | [diff] [blame] | 107 | void ran_conn_dtap(struct ran_conn *conn, struct msgb *msg) |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 108 | { |
Neels Hofmeyr | 3c20a5e | 2018-11-30 01:08:36 +0100 | [diff] [blame] | 109 | ran_conn_get(conn, RAN_CONN_USE_DTAP); |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 110 | gsm0408_dispatch(conn, msg); |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 111 | |
Neels Hofmeyr | 3c20a5e | 2018-11-30 01:08:36 +0100 | [diff] [blame] | 112 | ran_conn_put(conn, RAN_CONN_USE_DTAP); |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 113 | } |
| 114 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 115 | /* Receive an ASSIGNMENT COMPLETE from BSC */ |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 116 | void msc_assign_compl(struct ran_conn *conn, |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 117 | uint8_t rr_cause, uint8_t chosen_channel, |
| 118 | uint8_t encr_alg_id, uint8_t speec) |
Holger Hans Peter Freyther | 40aac3f | 2011-12-27 12:31:02 +0100 | [diff] [blame] | 119 | { |
Jacob Erlbeck | 8e68b56 | 2014-01-30 21:01:12 +0100 | [diff] [blame] | 120 | LOGP(DRR, LOGL_DEBUG, "MSC assign complete (do nothing).\n"); |
Holger Hans Peter Freyther | 40aac3f | 2011-12-27 12:31:02 +0100 | [diff] [blame] | 121 | } |
| 122 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 123 | /* Receive an ASSIGNMENT FAILURE from BSC */ |
Neels Hofmeyr | 3c20a5e | 2018-11-30 01:08:36 +0100 | [diff] [blame] | 124 | void ran_conn_assign_fail(struct ran_conn *conn, uint8_t cause, uint8_t *rr_cause) |
Holger Hans Peter Freyther | 40aac3f | 2011-12-27 12:31:02 +0100 | [diff] [blame] | 125 | { |
Jacob Erlbeck | 8e68b56 | 2014-01-30 21:01:12 +0100 | [diff] [blame] | 126 | LOGP(DRR, LOGL_DEBUG, "MSC assign failure (do nothing).\n"); |
Holger Hans Peter Freyther | 40aac3f | 2011-12-27 12:31:02 +0100 | [diff] [blame] | 127 | } |
| 128 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 129 | /* Receive a CLASSMARK CHANGE from BSC */ |
Neels Hofmeyr | 3c20a5e | 2018-11-30 01:08:36 +0100 | [diff] [blame] | 130 | void ran_conn_classmark_chg(struct ran_conn *conn, |
| 131 | const uint8_t *cm2, uint8_t cm2_len, |
| 132 | const uint8_t *cm3, uint8_t cm3_len) |
Harald Welte | 95e862c | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 133 | { |
Neels Hofmeyr | 68cf957 | 2018-09-18 15:52:58 +0200 | [diff] [blame] | 134 | struct gsm_classmark *cm; |
| 135 | |
| 136 | if (!conn->vsub) |
| 137 | cm = &conn->temporary_classmark; |
| 138 | else |
| 139 | cm = &conn->vsub->classmark; |
Neels Hofmeyr | 986fe7e | 2018-09-13 03:05:52 +0200 | [diff] [blame] | 140 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 141 | if (cm2 && cm2_len) { |
Neels Hofmeyr | 986fe7e | 2018-09-13 03:05:52 +0200 | [diff] [blame] | 142 | if (cm2_len > sizeof(cm->classmark2)) { |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 143 | LOGP(DRR, LOGL_NOTICE, "%s: classmark2 is %u bytes, truncating at %zu bytes\n", |
Neels Hofmeyr | 986fe7e | 2018-09-13 03:05:52 +0200 | [diff] [blame] | 144 | vlr_subscr_name(conn->vsub), cm2_len, sizeof(cm->classmark2)); |
| 145 | cm2_len = sizeof(cm->classmark2); |
Harald Welte | 95e862c | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 146 | } |
Neels Hofmeyr | 986fe7e | 2018-09-13 03:05:52 +0200 | [diff] [blame] | 147 | cm->classmark2_len = cm2_len; |
| 148 | memcpy(cm->classmark2, cm2, cm2_len); |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 149 | } |
| 150 | if (cm3 && cm3_len) { |
Neels Hofmeyr | 986fe7e | 2018-09-13 03:05:52 +0200 | [diff] [blame] | 151 | if (cm3_len > sizeof(cm->classmark3)) { |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 152 | LOGP(DRR, LOGL_NOTICE, "%s: classmark3 is %u bytes, truncating at %zu bytes\n", |
Neels Hofmeyr | 986fe7e | 2018-09-13 03:05:52 +0200 | [diff] [blame] | 153 | vlr_subscr_name(conn->vsub), cm3_len, sizeof(cm->classmark3)); |
| 154 | cm3_len = sizeof(cm->classmark3); |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 155 | } |
Neels Hofmeyr | 986fe7e | 2018-09-13 03:05:52 +0200 | [diff] [blame] | 156 | cm->classmark3_len = cm3_len; |
| 157 | memcpy(cm->classmark3, cm3, cm3_len); |
Harald Welte | 95e862c | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 158 | } |
Neels Hofmeyr | 3117b70 | 2018-09-13 03:23:07 +0200 | [diff] [blame] | 159 | |
| 160 | /* bump subscr conn FSM in case it is waiting for a Classmark Update */ |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 161 | if (conn->fi->state == RAN_CONN_S_WAIT_CLASSMARK_UPDATE) |
| 162 | osmo_fsm_inst_dispatch(conn->fi, RAN_CONN_E_CLASSMARK_UPDATE, NULL); |
Harald Welte | 95e862c | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 163 | } |
| 164 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 165 | /* Receive a CIPHERING MODE COMPLETE from BSC */ |
Neels Hofmeyr | 3c20a5e | 2018-11-30 01:08:36 +0100 | [diff] [blame] | 166 | void ran_conn_cipher_mode_compl(struct ran_conn *conn, struct msgb *msg, uint8_t alg_id) |
Harald Welte | cf149ee | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 167 | { |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 168 | struct vlr_ciph_result ciph_res = { .cause = VLR_CIPH_REJECT }; |
Harald Welte | cf149ee | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 169 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 170 | if (!conn) { |
Harald Welte | 284c39a | 2018-01-24 22:38:06 +0100 | [diff] [blame] | 171 | LOGP(DRR, LOGL_ERROR, "invalid: rx Ciphering Mode Complete on NULL conn\n"); |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 172 | return; |
| 173 | } |
| 174 | if (!conn->vsub) { |
Harald Welte | 284c39a | 2018-01-24 22:38:06 +0100 | [diff] [blame] | 175 | LOGP(DRR, LOGL_ERROR, "invalid: rx Ciphering Mode Complete for NULL subscr\n"); |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 176 | return; |
Harald Welte | cf149ee | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 177 | } |
| 178 | |
Harald Welte | 284c39a | 2018-01-24 22:38:06 +0100 | [diff] [blame] | 179 | DEBUGP(DRR, "%s: CIPHERING MODE COMPLETE\n", vlr_subscr_name(conn->vsub)); |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 180 | |
Harald Welte | 284c39a | 2018-01-24 22:38:06 +0100 | [diff] [blame] | 181 | if (msg) { |
| 182 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 183 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 184 | struct tlv_parsed tp; |
| 185 | uint8_t mi_type; |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 186 | |
Harald Welte | 284c39a | 2018-01-24 22:38:06 +0100 | [diff] [blame] | 187 | if (!gh) { |
| 188 | LOGP(DRR, LOGL_ERROR, "invalid: msgb without l3 header\n"); |
| 189 | return; |
| 190 | } |
| 191 | |
| 192 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
| 193 | |
| 194 | /* bearer capability */ |
| 195 | if (TLVP_PRESENT(&tp, GSM48_IE_MOBILE_ID)) { |
| 196 | mi_type = TLVP_VAL(&tp, GSM48_IE_MOBILE_ID)[0] & GSM_MI_TYPE_MASK; |
| 197 | if (mi_type == GSM_MI_TYPE_IMEISV |
| 198 | && TLVP_LEN(&tp, GSM48_IE_MOBILE_ID) > 0) { |
Neels Hofmeyr | fa10eda | 2018-03-13 01:22:01 +0100 | [diff] [blame] | 199 | gsm48_mi_to_string(ciph_res.imeisv, sizeof(ciph_res.imeisv), |
Harald Welte | 284c39a | 2018-01-24 22:38:06 +0100 | [diff] [blame] | 200 | TLVP_VAL(&tp, GSM48_IE_MOBILE_ID), |
| 201 | TLVP_LEN(&tp, GSM48_IE_MOBILE_ID)); |
Harald Welte | 284c39a | 2018-01-24 22:38:06 +0100 | [diff] [blame] | 202 | } |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 203 | } |
| 204 | } |
| 205 | |
Neels Hofmeyr | f41658d | 2018-11-30 04:35:50 +0100 | [diff] [blame] | 206 | conn->geran_encr.alg_id = alg_id; |
Neels Hofmeyr | b0779bb | 2018-11-29 23:37:19 +0100 | [diff] [blame] | 207 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 208 | ciph_res.cause = VLR_CIPH_COMPL; |
| 209 | vlr_subscr_rx_ciph_res(conn->vsub, &ciph_res); |
Harald Welte | cf149ee | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 210 | } |
| 211 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 212 | /* Receive a CLEAR REQUEST from BSC */ |
Neels Hofmeyr | 3c20a5e | 2018-11-30 01:08:36 +0100 | [diff] [blame] | 213 | int ran_conn_clear_request(struct ran_conn *conn, uint32_t cause) |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 214 | { |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 215 | ran_conn_close(conn, cause); |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 216 | return 1; |
| 217 | } |
| 218 | |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 219 | static const char *used_ref_counts_str(struct ran_conn *conn) |
Neels Hofmeyr | 99a8d23 | 2018-04-09 20:44:56 +0200 | [diff] [blame] | 220 | { |
| 221 | static char buf[256]; |
| 222 | int bit_nr; |
| 223 | char *pos = buf; |
| 224 | *pos = '\0'; |
| 225 | |
| 226 | if (conn->use_tokens < 0) |
| 227 | return "invalid"; |
| 228 | |
| 229 | #define APPEND_STR(fmt, args...) do { \ |
| 230 | int remain = sizeof(buf) - (pos - buf) - 1; \ |
| 231 | int l = -1; \ |
| 232 | if (remain > 0) \ |
| 233 | l = snprintf(pos, remain, "%s" fmt, (pos == buf? "" : ","), ##args); \ |
| 234 | if (l < 0 || l > remain) { \ |
| 235 | buf[sizeof(buf) - 1] = '\0'; \ |
| 236 | return buf; \ |
| 237 | } \ |
| 238 | pos += l; \ |
| 239 | } while(0) |
| 240 | |
| 241 | for (bit_nr = 0; (1 << bit_nr) <= conn->use_tokens; bit_nr++) { |
| 242 | if (conn->use_tokens & (1 << bit_nr)) { |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 243 | APPEND_STR("%s", get_value_string(ran_conn_use_names, bit_nr)); |
Neels Hofmeyr | 99a8d23 | 2018-04-09 20:44:56 +0200 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | return buf; |
| 247 | #undef APPEND_STR |
| 248 | } |
| 249 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 250 | /* increment the ref-count. Needs to be called by every user */ |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 251 | struct ran_conn *_ran_conn_get(struct ran_conn *conn, enum ran_conn_use balance_token, |
| 252 | const char *file, int line) |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 253 | { |
| 254 | OSMO_ASSERT(conn); |
Holger Hans Peter Freyther | e7bd863 | 2013-06-30 15:30:47 +0200 | [diff] [blame] | 255 | |
Neels Hofmeyr | 3c20a5e | 2018-11-30 01:08:36 +0100 | [diff] [blame] | 256 | if (balance_token != RAN_CONN_USE_UNTRACKED) { |
Neels Hofmeyr | 6166f29 | 2017-11-22 14:33:12 +0100 | [diff] [blame] | 257 | uint32_t flag = 1 << balance_token; |
| 258 | OSMO_ASSERT(balance_token < 32); |
| 259 | if (conn->use_tokens & flag) |
| 260 | LOGPSRC(DREF, LOGL_ERROR, file, line, |
| 261 | "%s: MSC conn use error: using an already used token: %s\n", |
| 262 | vlr_subscr_name(conn->vsub), |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 263 | ran_conn_use_name(balance_token)); |
Neels Hofmeyr | 6166f29 | 2017-11-22 14:33:12 +0100 | [diff] [blame] | 264 | conn->use_tokens |= flag; |
| 265 | } |
| 266 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 267 | conn->use_count++; |
| 268 | LOGPSRC(DREF, LOGL_DEBUG, file, line, |
Neels Hofmeyr | 99a8d23 | 2018-04-09 20:44:56 +0200 | [diff] [blame] | 269 | "%s: MSC conn use + %s == %u (0x%x: %s)\n", |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 270 | vlr_subscr_name(conn->vsub), ran_conn_use_name(balance_token), |
Neels Hofmeyr | 99a8d23 | 2018-04-09 20:44:56 +0200 | [diff] [blame] | 271 | conn->use_count, conn->use_tokens, used_ref_counts_str(conn)); |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 272 | |
| 273 | return conn; |
| 274 | } |
| 275 | |
| 276 | /* decrement the ref-count. Once it reaches zero, we release */ |
Neels Hofmeyr | 3c20a5e | 2018-11-30 01:08:36 +0100 | [diff] [blame] | 277 | void _ran_conn_put(struct ran_conn *conn, enum ran_conn_use balance_token, |
| 278 | const char *file, int line) |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 279 | { |
| 280 | OSMO_ASSERT(conn); |
| 281 | |
Neels Hofmeyr | 3c20a5e | 2018-11-30 01:08:36 +0100 | [diff] [blame] | 282 | if (balance_token != RAN_CONN_USE_UNTRACKED) { |
Neels Hofmeyr | 6166f29 | 2017-11-22 14:33:12 +0100 | [diff] [blame] | 283 | uint32_t flag = 1 << balance_token; |
| 284 | OSMO_ASSERT(balance_token < 32); |
| 285 | if (!(conn->use_tokens & flag)) |
| 286 | LOGPSRC(DREF, LOGL_ERROR, file, line, |
| 287 | "%s: MSC conn use error: freeing an unused token: %s\n", |
| 288 | vlr_subscr_name(conn->vsub), |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 289 | ran_conn_use_name(balance_token)); |
Neels Hofmeyr | 6166f29 | 2017-11-22 14:33:12 +0100 | [diff] [blame] | 290 | conn->use_tokens &= ~flag; |
| 291 | } |
| 292 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 293 | if (conn->use_count == 0) { |
| 294 | LOGPSRC(DREF, LOGL_ERROR, file, line, |
Neels Hofmeyr | 6166f29 | 2017-11-22 14:33:12 +0100 | [diff] [blame] | 295 | "%s: MSC conn use - %s failed: is already 0\n", |
| 296 | vlr_subscr_name(conn->vsub), |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 297 | ran_conn_use_name(balance_token)); |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 298 | return; |
| 299 | } |
| 300 | |
| 301 | conn->use_count--; |
| 302 | LOGPSRC(DREF, LOGL_DEBUG, file, line, |
Neels Hofmeyr | 99a8d23 | 2018-04-09 20:44:56 +0200 | [diff] [blame] | 303 | "%s: MSC conn use - %s == %u (0x%x: %s)\n", |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 304 | vlr_subscr_name(conn->vsub), ran_conn_use_name(balance_token), |
Neels Hofmeyr | 99a8d23 | 2018-04-09 20:44:56 +0200 | [diff] [blame] | 305 | conn->use_count, conn->use_tokens, used_ref_counts_str(conn)); |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 306 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 307 | if (conn->use_count == 0) |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 308 | osmo_fsm_inst_dispatch(conn->fi, RAN_CONN_E_UNUSED, NULL); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 309 | } |
| 310 | |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 311 | bool ran_conn_used_by(struct ran_conn *conn, enum ran_conn_use token) |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 312 | { |
| 313 | return conn && (conn->use_tokens & (1 << token)); |
| 314 | } |
| 315 | |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 316 | const struct value_string ran_conn_use_names[] = { |
Neels Hofmeyr | 3c20a5e | 2018-11-30 01:08:36 +0100 | [diff] [blame] | 317 | {RAN_CONN_USE_UNTRACKED, "UNTRACKED"}, |
| 318 | {RAN_CONN_USE_COMPL_L3, "compl_l3"}, |
| 319 | {RAN_CONN_USE_DTAP, "dtap"}, |
| 320 | {RAN_CONN_USE_AUTH_CIPH, "auth+ciph"}, |
| 321 | {RAN_CONN_USE_CM_SERVICE, "cm_service"}, |
| 322 | {RAN_CONN_USE_TRANS_CC, "trans_cc"}, |
| 323 | {RAN_CONN_USE_TRANS_SMS, "trans_sms"}, |
| 324 | {RAN_CONN_USE_TRANS_NC_SS, "trans_nc_ss"}, |
| 325 | {RAN_CONN_USE_SILENT_CALL, "silent_call"}, |
| 326 | {RAN_CONN_USE_RELEASE, "release"}, |
Neels Hofmeyr | 6166f29 | 2017-11-22 14:33:12 +0100 | [diff] [blame] | 327 | {0, NULL}, |
| 328 | }; |
| 329 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 330 | void msc_stop_paging(struct vlr_subscr *vsub) |
| 331 | { |
| 332 | DEBUGP(DPAG, "Paging can stop for %s\n", vlr_subscr_name(vsub)); |
| 333 | /* tell BSCs and RNCs to stop paging? How? */ |
Holger Hans Peter Freyther | 4049455 | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 334 | } |