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 | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 24 | #include <openbsc/osmo_msc.h> |
Holger Hans Peter Freyther | 43b0909 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 25 | #include <openbsc/bsc_api.h> |
| 26 | #include <openbsc/debug.h> |
Holger Hans Peter Freyther | 4049455 | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 27 | #include <openbsc/transaction.h> |
Harald Welte | 95e862c | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 28 | #include <openbsc/db.h> |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 29 | #include <openbsc/vlr.h> |
| 30 | #include <openbsc/osmo_msc.h> |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 31 | #include <openbsc/a_iface.h> |
Holger Hans Peter Freyther | 43b0909 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 32 | |
Holger Hans Peter Freyther | 6a3d765 | 2010-06-15 12:03:10 +0800 | [diff] [blame] | 33 | #include <openbsc/gsm_04_11.h> |
| 34 | |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 35 | #include "../../bscconfig.h" |
| 36 | #ifdef BUILD_IU |
| 37 | #include <osmocom/ranap/iu_client.h> |
| 38 | #else |
| 39 | #include <openbsc/iu_dummy.h> |
| 40 | #endif |
| 41 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 42 | /* Receive a SAPI-N-REJECT from BSC */ |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 43 | void msc_sapi_n_reject(struct gsm_subscriber_connection *conn, int dlci) |
Holger Hans Peter Freyther | 43b0909 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 44 | { |
Holger Hans Peter Freyther | 6a3d765 | 2010-06-15 12:03:10 +0800 | [diff] [blame] | 45 | int sapi = dlci & 0x7; |
| 46 | |
| 47 | if (sapi == UM_SAPI_SMS) |
| 48 | gsm411_sapi_n_reject(conn); |
Holger Hans Peter Freyther | 43b0909 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 49 | } |
| 50 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 51 | static void subscr_conn_bump(struct gsm_subscriber_connection *conn) |
| 52 | { |
| 53 | if (!conn) |
| 54 | return; |
| 55 | if (!conn->conn_fsm) |
| 56 | return; |
| 57 | if (!(conn->conn_fsm->state == SUBSCR_CONN_S_ACCEPTED |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 58 | || conn->conn_fsm->state == SUBSCR_CONN_S_COMMUNICATING)) { |
| 59 | DEBUGP(DMM, "%s: bump: conn still being established (%s)\n", |
| 60 | vlr_subscr_name(conn->vsub), |
| 61 | osmo_fsm_inst_state_name(conn->conn_fsm)); |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 62 | return; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 63 | } |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 64 | osmo_fsm_inst_dispatch(conn->conn_fsm, SUBSCR_CONN_E_BUMP, NULL); |
| 65 | } |
| 66 | |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 67 | /* receive a Level 3 Complete message and return MSC_CONN_ACCEPT or |
| 68 | * MSC_CONN_REJECT */ |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 69 | int msc_compl_l3(struct gsm_subscriber_connection *conn, |
| 70 | struct msgb *msg, uint16_t chosen_channel) |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 71 | { |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 72 | msc_subscr_conn_get(conn); |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 73 | gsm0408_dispatch(conn, msg); |
| 74 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 75 | /* Bump whether the conn wants to be closed */ |
| 76 | subscr_conn_bump(conn); |
| 77 | |
| 78 | /* If this should be kept, the conn->conn_fsm has placed a use_count */ |
| 79 | msc_subscr_conn_put(conn); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 80 | |
| 81 | /* Always return acceptance, because even if the conn was not accepted, |
| 82 | * we assumed ownership of it and the caller shall not interfere with |
| 83 | * that. We may even already have discarded the conn. */ |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 84 | return MSC_CONN_ACCEPT; |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 85 | |
| 86 | #if 0 |
Holger Hans Peter Freyther | e9f420d | 2016-02-10 10:42:20 +0100 | [diff] [blame] | 87 | /* |
| 88 | * If this is a silent call we want the channel to remain open as long as |
| 89 | * possible and this is why we accept this connection regardless of any |
| 90 | * pending transaction or ongoing operation. |
| 91 | */ |
Holger Hans Peter Freyther | 70ae5d3 | 2012-11-23 21:33:15 +0100 | [diff] [blame] | 92 | if (conn->silent_call) |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 93 | return MSC_CONN_ACCEPT; |
| 94 | if (conn->loc_operation || conn->sec_operation || conn->anch_operation) |
| 95 | return MSC_CONN_ACCEPT; |
Holger Hans Peter Freyther | 70ae5d3 | 2012-11-23 21:33:15 +0100 | [diff] [blame] | 96 | if (trans_has_conn(conn)) |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 97 | return MSC_CONN_ACCEPT; |
Jacob Erlbeck | 8e68b56 | 2014-01-30 21:01:12 +0100 | [diff] [blame] | 98 | |
| 99 | LOGP(DRR, LOGL_INFO, "MSC Complete L3: Rejecting connection.\n"); |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 100 | return MSC_CONN_REJECT; |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 101 | #endif |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 102 | } |
| 103 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 104 | /* Receive a DTAP message from BSC */ |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 105 | void msc_dtap(struct gsm_subscriber_connection *conn, uint8_t link_id, struct msgb *msg) |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 106 | { |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 107 | msc_subscr_conn_get(conn); |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 108 | gsm0408_dispatch(conn, msg); |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 109 | |
| 110 | /* Bump whether the conn wants to be closed */ |
| 111 | subscr_conn_bump(conn); |
| 112 | msc_subscr_conn_put(conn); |
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 */ |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 116 | void msc_assign_compl(struct gsm_subscriber_connection *conn, |
| 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 */ |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 124 | void msc_assign_fail(struct gsm_subscriber_connection *conn, |
| 125 | uint8_t cause, uint8_t *rr_cause) |
Holger Hans Peter Freyther | 40aac3f | 2011-12-27 12:31:02 +0100 | [diff] [blame] | 126 | { |
Jacob Erlbeck | 8e68b56 | 2014-01-30 21:01:12 +0100 | [diff] [blame] | 127 | LOGP(DRR, LOGL_DEBUG, "MSC assign failure (do nothing).\n"); |
Holger Hans Peter Freyther | 40aac3f | 2011-12-27 12:31:02 +0100 | [diff] [blame] | 128 | } |
| 129 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 130 | /* Receive a CLASSMARK CHANGE from BSC */ |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 131 | void msc_classmark_chg(struct gsm_subscriber_connection *conn, |
| 132 | const uint8_t *cm2, uint8_t cm2_len, |
| 133 | const uint8_t *cm3, uint8_t cm3_len) |
Harald Welte | 95e862c | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 134 | { |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 135 | if (cm2 && cm2_len) { |
| 136 | if (cm2_len > sizeof(conn->classmark.classmark2)) { |
| 137 | LOGP(DRR, LOGL_NOTICE, "%s: classmark2 is %u bytes, truncating at %zu bytes\n", |
| 138 | vlr_subscr_name(conn->vsub), cm2_len, sizeof(conn->classmark.classmark2)); |
| 139 | cm2_len = sizeof(conn->classmark.classmark2); |
Harald Welte | 95e862c | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 140 | } |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 141 | conn->classmark.classmark2_len = cm2_len; |
| 142 | memcpy(conn->classmark.classmark2, cm2, cm2_len); |
| 143 | } |
| 144 | if (cm3 && cm3_len) { |
| 145 | if (cm3_len > sizeof(conn->classmark.classmark3)) { |
| 146 | LOGP(DRR, LOGL_NOTICE, "%s: classmark3 is %u bytes, truncating at %zu bytes\n", |
| 147 | vlr_subscr_name(conn->vsub), cm3_len, sizeof(conn->classmark.classmark3)); |
| 148 | cm3_len = sizeof(conn->classmark.classmark3); |
| 149 | } |
| 150 | conn->classmark.classmark3_len = cm3_len; |
| 151 | memcpy(conn->classmark.classmark3, cm3, cm3_len); |
Harald Welte | 95e862c | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 155 | /* Receive a CIPHERING MODE COMPLETE from BSC */ |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 156 | void msc_cipher_mode_compl(struct gsm_subscriber_connection *conn, |
| 157 | struct msgb *msg, uint8_t alg_id) |
Harald Welte | cf149ee | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 158 | { |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 159 | struct gsm48_hdr *gh = msgb_l3(msg); |
| 160 | unsigned int payload_len = msgb_l3len(msg) - sizeof(*gh); |
| 161 | struct tlv_parsed tp; |
| 162 | uint8_t mi_type; |
| 163 | char imeisv[GSM48_MI_SIZE] = ""; |
| 164 | struct vlr_ciph_result ciph_res = { .cause = VLR_CIPH_REJECT }; |
Harald Welte | cf149ee | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 165 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 166 | if (!gh) { |
| 167 | LOGP(DRR, LOGL_ERROR, "invalid: msgb without l3 header\n"); |
Harald Welte | cf149ee | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 168 | return; |
| 169 | } |
| 170 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 171 | if (!conn) { |
| 172 | LOGP(DRR, LOGL_ERROR, |
| 173 | "invalid: rx Ciphering Mode Complete on NULL conn\n"); |
| 174 | return; |
| 175 | } |
| 176 | if (!conn->vsub) { |
| 177 | LOGP(DRR, LOGL_ERROR, |
| 178 | "invalid: rx Ciphering Mode Complete for NULL subscr\n"); |
| 179 | return; |
Harald Welte | cf149ee | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 180 | } |
| 181 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 182 | DEBUGP(DRR, "%s: CIPHERING MODE COMPLETE\n", |
| 183 | vlr_subscr_name(conn->vsub)); |
| 184 | |
| 185 | tlv_parse(&tp, &gsm48_att_tlvdef, gh->data, payload_len, 0, 0); |
| 186 | |
| 187 | /* bearer capability */ |
| 188 | if (TLVP_PRESENT(&tp, GSM48_IE_MOBILE_ID)) { |
| 189 | mi_type = TLVP_VAL(&tp, GSM48_IE_MOBILE_ID)[0] & GSM_MI_TYPE_MASK; |
| 190 | if (mi_type == GSM_MI_TYPE_IMEISV |
| 191 | && TLVP_LEN(&tp, GSM48_IE_MOBILE_ID) > 0) { |
| 192 | gsm48_mi_to_string(imeisv, sizeof(imeisv), |
| 193 | TLVP_VAL(&tp, GSM48_IE_MOBILE_ID), |
| 194 | TLVP_LEN(&tp, GSM48_IE_MOBILE_ID)); |
| 195 | ciph_res.imeisv = imeisv; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | ciph_res.cause = VLR_CIPH_COMPL; |
| 200 | vlr_subscr_rx_ciph_res(conn->vsub, &ciph_res); |
Harald Welte | cf149ee | 2012-01-23 16:40:24 +0100 | [diff] [blame] | 201 | } |
| 202 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 203 | struct gsm_subscriber_connection *msc_subscr_con_allocate(struct gsm_network *network) |
| 204 | { |
| 205 | struct gsm_subscriber_connection *conn; |
Harald Welte | 95e862c | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 206 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 207 | conn = talloc_zero(network, struct gsm_subscriber_connection); |
| 208 | if (!conn) |
| 209 | return NULL; |
Harald Welte | 95e862c | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 210 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 211 | conn->network = network; |
| 212 | llist_add_tail(&conn->entry, &network->subscr_conns); |
| 213 | return conn; |
| 214 | } |
| 215 | |
| 216 | void msc_subscr_cleanup(struct vlr_subscr *vsub) |
| 217 | { |
| 218 | if (!vsub) |
| 219 | return; |
| 220 | vsub->lu_fsm = NULL; |
| 221 | } |
| 222 | |
| 223 | void msc_subscr_con_cleanup(struct gsm_subscriber_connection *conn) |
| 224 | { |
| 225 | if (!conn) |
| 226 | return; |
| 227 | |
| 228 | if (conn->vsub) { |
| 229 | DEBUGP(DRLL, "subscr %s: Freeing subscriber connection\n", |
| 230 | vlr_subscr_name(conn->vsub)); |
| 231 | msc_subscr_cleanup(conn->vsub); |
| 232 | vlr_subscr_put(conn->vsub); |
| 233 | conn->vsub = NULL; |
| 234 | } else |
| 235 | DEBUGP(DRLL, "Freeing subscriber connection" |
| 236 | " with NULL subscriber\n"); |
| 237 | |
| 238 | if (!conn->conn_fsm) |
| 239 | return; |
| 240 | |
| 241 | osmo_fsm_inst_term(conn->conn_fsm, |
| 242 | (conn->conn_fsm->state == SUBSCR_CONN_S_RELEASED) |
| 243 | ? OSMO_FSM_TERM_REGULAR |
| 244 | : OSMO_FSM_TERM_ERROR, |
| 245 | NULL); |
| 246 | } |
| 247 | |
| 248 | void msc_subscr_con_free(struct gsm_subscriber_connection *conn) |
| 249 | { |
| 250 | if (!conn) |
| 251 | return; |
| 252 | |
| 253 | msc_subscr_con_cleanup(conn); |
| 254 | |
| 255 | llist_del(&conn->entry); |
| 256 | talloc_free(conn); |
| 257 | } |
| 258 | |
| 259 | /* Receive a CLEAR REQUEST from BSC */ |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 260 | int msc_clear_request(struct gsm_subscriber_connection *conn, uint32_t cause) |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 261 | { |
| 262 | msc_subscr_conn_close(conn, cause); |
| 263 | return 1; |
| 264 | } |
| 265 | |
| 266 | /* MSC-level operations to be called by libbsc in NITB */ |
Holger Hans Peter Freyther | 43b0909 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 267 | static struct bsc_api msc_handler = { |
| 268 | .sapi_n_reject = msc_sapi_n_reject, |
Holger Hans Peter Freyther | 9764331 | 2010-06-17 16:41:25 +0800 | [diff] [blame] | 269 | .compl_l3 = msc_compl_l3, |
Neels Hofmeyr | cc7db18 | 2016-12-18 23:52:38 +0100 | [diff] [blame] | 270 | .dtap = msc_dtap, |
Holger Hans Peter Freyther | 40aac3f | 2011-12-27 12:31:02 +0100 | [diff] [blame] | 271 | .clear_request = msc_clear_request, |
| 272 | .assign_compl = msc_assign_compl, |
| 273 | .assign_fail = msc_assign_fail, |
Harald Welte | 95e862c | 2012-01-23 10:28:35 +0100 | [diff] [blame] | 274 | .classmark_chg = msc_classmark_chg, |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 275 | .cipher_mode_compl = msc_cipher_mode_compl, |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 276 | .conn_cleanup = msc_subscr_con_cleanup, |
Holger Hans Peter Freyther | 43b0909 | 2010-06-15 11:52:51 +0800 | [diff] [blame] | 277 | }; |
| 278 | |
| 279 | struct bsc_api *msc_bsc_api() { |
| 280 | return &msc_handler; |
| 281 | } |
Holger Hans Peter Freyther | 4049455 | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 282 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 283 | static void msc_subscr_conn_release_all(struct gsm_subscriber_connection *conn, uint32_t cause) |
Holger Hans Peter Freyther | 4049455 | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 284 | { |
Holger Hans Peter Freyther | 4049455 | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 285 | if (conn->in_release) |
| 286 | return; |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 287 | conn->in_release = true; |
Holger Hans Peter Freyther | 4049455 | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 288 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 289 | /* If we're closing in a middle of a trans, we need to clean up */ |
| 290 | trans_conn_closed(conn); |
| 291 | |
| 292 | switch (conn->via_ran) { |
| 293 | case RAN_UTRAN_IU: |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 294 | ranap_iu_tx_release(conn->iu.ue_ctx, NULL); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 295 | /* FIXME: keep the conn until the Iu Release Outcome is |
| 296 | * received from the UE, or a timeout expires. For now, the log |
| 297 | * says "unknown UE" for each release outcome. */ |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 298 | break; |
| 299 | case RAN_GERAN_A: |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 300 | a_iface_tx_clear_cmd(conn); |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 301 | break; |
| 302 | default: |
| 303 | LOGP(DMM, LOGL_ERROR, "%s: Unknown RAN type, cannot tx release/clear\n", |
| 304 | vlr_subscr_name(conn->vsub)); |
| 305 | break; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | /* If the conn->conn_fsm is still present, dispatch SUBSCR_CONN_E_CN_CLOSE |
| 310 | * event to gracefully terminate the connection. If the conn_fsm is already |
| 311 | * cleared, call msc_subscr_conn_release_all() to take release actions. |
| 312 | * \param cause a GSM_CAUSE_* constant, e.g. GSM_CAUSE_AUTH_FAILED. |
| 313 | */ |
| 314 | void msc_subscr_conn_close(struct gsm_subscriber_connection *conn, |
| 315 | uint32_t cause) |
| 316 | { |
| 317 | if (!conn) |
Holger Hans Peter Freyther | 4049455 | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 318 | return; |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 319 | if (conn->in_release) { |
| 320 | DEBUGP(DMM, "msc_subscr_conn_close(vsub=%s, cause=%u):" |
| 321 | " already dispatching release, ignore.\n", |
| 322 | vlr_subscr_name(conn->vsub), cause); |
Holger Hans Peter Freyther | 4049455 | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 323 | return; |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 324 | } |
| 325 | if (!conn->conn_fsm) { |
| 326 | DEBUGP(DMM, "msc_subscr_conn_close(vsub=%s, cause=%u): no conn fsm," |
| 327 | " releasing directly without release event.\n", |
| 328 | vlr_subscr_name(conn->vsub), cause); |
| 329 | /* In case of an IMSI Detach, we don't have conn_fsm. Release |
| 330 | * anyway to ensure a timely Iu Release / BSSMAP Clear. */ |
| 331 | msc_subscr_conn_release_all(conn, cause); |
Holger Hans Peter Freyther | 70ae5d3 | 2012-11-23 21:33:15 +0100 | [diff] [blame] | 332 | return; |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 333 | } |
| 334 | if (conn->conn_fsm->state == SUBSCR_CONN_S_RELEASED) { |
| 335 | DEBUGP(DMM, "msc_subscr_conn_close(vsub=%s, cause=%u):" |
| 336 | " conn fsm already releasing, ignore.\n", |
| 337 | vlr_subscr_name(conn->vsub), cause); |
| 338 | return; |
| 339 | } |
| 340 | osmo_fsm_inst_dispatch(conn->conn_fsm, SUBSCR_CONN_E_CN_CLOSE, &cause); |
| 341 | } |
Holger Hans Peter Freyther | 4049455 | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 342 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 343 | /* increment the ref-count. Needs to be called by every user */ |
| 344 | struct gsm_subscriber_connection * |
| 345 | _msc_subscr_conn_get(struct gsm_subscriber_connection *conn, |
| 346 | const char *file, int line) |
| 347 | { |
| 348 | OSMO_ASSERT(conn); |
Holger Hans Peter Freyther | e7bd863 | 2013-06-30 15:30:47 +0200 | [diff] [blame] | 349 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 350 | if (conn->in_release) |
| 351 | return NULL; |
Holger Hans Peter Freyther | e7bd863 | 2013-06-30 15:30:47 +0200 | [diff] [blame] | 352 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 353 | conn->use_count++; |
| 354 | LOGPSRC(DREF, LOGL_DEBUG, file, line, |
| 355 | "%s: MSC conn use + 1 == %u\n", |
| 356 | vlr_subscr_name(conn->vsub), conn->use_count); |
| 357 | |
| 358 | return conn; |
| 359 | } |
| 360 | |
| 361 | /* decrement the ref-count. Once it reaches zero, we release */ |
| 362 | void _msc_subscr_conn_put(struct gsm_subscriber_connection *conn, |
| 363 | const char *file, int line) |
| 364 | { |
| 365 | OSMO_ASSERT(conn); |
| 366 | |
| 367 | if (conn->use_count == 0) { |
| 368 | LOGPSRC(DREF, LOGL_ERROR, file, line, |
| 369 | "%s: MSC conn use - 1 failed: is already 0\n", |
| 370 | vlr_subscr_name(conn->vsub)); |
| 371 | return; |
| 372 | } |
| 373 | |
| 374 | conn->use_count--; |
| 375 | LOGPSRC(DREF, LOGL_DEBUG, file, line, |
| 376 | "%s: MSC conn use - 1 == %u\n", |
| 377 | vlr_subscr_name(conn->vsub), conn->use_count); |
| 378 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 379 | if (conn->use_count == 0) |
| 380 | msc_subscr_con_free(conn); |
| 381 | } |
| 382 | |
| 383 | void msc_stop_paging(struct vlr_subscr *vsub) |
| 384 | { |
| 385 | DEBUGP(DPAG, "Paging can stop for %s\n", vlr_subscr_name(vsub)); |
| 386 | /* tell BSCs and RNCs to stop paging? How? */ |
Holger Hans Peter Freyther | 4049455 | 2010-06-28 17:09:29 +0800 | [diff] [blame] | 387 | } |