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