Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 1 | /* MSC subscriber connection implementation */ |
| 2 | |
| 3 | /* |
| 4 | * (C) 2016 by sysmocom s.m.f.c. <info@sysmocom.de> |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * Author: Neels Hofmeyr |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 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 |
| 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 |
| 17 | * GNU Affero General Public License for more details. |
| 18 | * |
| 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/>. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <osmocom/core/logging.h> |
| 25 | #include <osmocom/core/fsm.h> |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 26 | #include <osmocom/core/signal.h> |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 27 | |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 28 | #include <osmocom/msc/osmo_msc.h> |
| 29 | #include <osmocom/msc/vlr.h> |
| 30 | #include <osmocom/msc/debug.h> |
| 31 | #include <osmocom/msc/transaction.h> |
| 32 | #include <osmocom/msc/signal.h> |
| 33 | #include <osmocom/msc/a_iface.h> |
Daniel Willmann | 4e825b6 | 2018-02-15 10:33:26 +0100 | [diff] [blame] | 34 | #include <osmocom/msc/iucs.h> |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 35 | |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 36 | #include "../../bscconfig.h" |
| 37 | #ifdef BUILD_IU |
| 38 | #include <osmocom/ranap/iu_client.h> |
| 39 | #else |
| 40 | #include <osmocom/msc/iu_dummy.h> |
| 41 | #endif |
| 42 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 43 | #define SUBSCR_CONN_TIMEOUT 5 /* seconds */ |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 44 | |
| 45 | static const struct value_string subscr_conn_fsm_event_names[] = { |
| 46 | OSMO_VALUE_STRING(SUBSCR_CONN_E_INVALID), |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 47 | OSMO_VALUE_STRING(SUBSCR_CONN_E_COMPLETE_LAYER_3), |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 48 | OSMO_VALUE_STRING(SUBSCR_CONN_E_ACCEPTED), |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 49 | OSMO_VALUE_STRING(SUBSCR_CONN_E_COMMUNICATING), |
Neels Hofmeyr | e9e2f5c | 2018-03-15 13:26:43 +0100 | [diff] [blame] | 50 | OSMO_VALUE_STRING(SUBSCR_CONN_E_RELEASE_WHEN_UNUSED), |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 51 | OSMO_VALUE_STRING(SUBSCR_CONN_E_MO_CLOSE), |
| 52 | OSMO_VALUE_STRING(SUBSCR_CONN_E_CN_CLOSE), |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 53 | OSMO_VALUE_STRING(SUBSCR_CONN_E_UNUSED), |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 54 | { 0, NULL } |
| 55 | }; |
| 56 | |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 57 | static void update_counters(struct osmo_fsm_inst *fi, bool conn_accepted) |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 58 | { |
| 59 | struct gsm_subscriber_connection *conn = fi->priv; |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 60 | switch (conn->complete_layer3_type) { |
| 61 | case COMPLETE_LAYER3_LU: |
| 62 | rate_ctr_inc(&conn->network->msc_ctrs->ctr[ |
| 63 | conn_accepted ? MSC_CTR_LOC_UPDATE_COMPLETED |
| 64 | : MSC_CTR_LOC_UPDATE_FAILED]); |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 65 | break; |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 66 | case COMPLETE_LAYER3_CM_SERVICE_REQ: |
| 67 | rate_ctr_inc(&conn->network->msc_ctrs->ctr[ |
| 68 | conn_accepted ? MSC_CTR_CM_SERVICE_REQUEST_ACCEPTED |
| 69 | : MSC_CTR_CM_SERVICE_REQUEST_REJECTED]); |
| 70 | break; |
| 71 | case COMPLETE_LAYER3_PAGING_RESP: |
| 72 | rate_ctr_inc(&conn->network->msc_ctrs->ctr[ |
| 73 | conn_accepted ? MSC_CTR_PAGING_RESP_ACCEPTED |
| 74 | : MSC_CTR_PAGING_RESP_REJECTED]); |
| 75 | break; |
| 76 | default: |
| 77 | break; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | static void evaluate_acceptance_outcome(struct osmo_fsm_inst *fi, bool conn_accepted) |
| 82 | { |
| 83 | struct gsm_subscriber_connection *conn = fi->priv; |
| 84 | |
| 85 | update_counters(fi, conn_accepted); |
| 86 | |
| 87 | /* Trigger transactions that we paged for */ |
| 88 | if (conn->complete_layer3_type == COMPLETE_LAYER3_PAGING_RESP) { |
| 89 | subscr_paging_dispatch(GSM_HOOK_RR_PAGING, |
| 90 | conn_accepted ? GSM_PAGING_SUCCEEDED : GSM_PAGING_EXPIRED, |
| 91 | NULL, conn, conn->vsub); |
| 92 | } |
| 93 | |
| 94 | if (conn->complete_layer3_type == COMPLETE_LAYER3_CM_SERVICE_REQ |
| 95 | && conn_accepted) { |
| 96 | conn->received_cm_service_request = true; |
| 97 | msc_subscr_conn_get(conn, MSC_CONN_USE_CM_SERVICE); |
| 98 | } |
| 99 | |
| 100 | if (conn_accepted) |
| 101 | osmo_signal_dispatch(SS_SUBSCR, S_SUBSCR_ATTACHED, conn->vsub); |
| 102 | } |
| 103 | |
| 104 | static void log_close_event(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
| 105 | { |
| 106 | if (data) |
| 107 | LOGPFSML(fi, LOGL_DEBUG, "Close event, cause %u\n", *(uint32_t*)data); |
| 108 | } |
| 109 | |
| 110 | static void subscr_conn_fsm_new(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
| 111 | { |
| 112 | switch (event) { |
| 113 | case SUBSCR_CONN_E_COMPLETE_LAYER_3: |
| 114 | osmo_fsm_inst_state_chg(fi, SUBSCR_CONN_S_AUTH_CIPH, SUBSCR_CONN_TIMEOUT, 0); |
| 115 | return; |
| 116 | |
| 117 | case SUBSCR_CONN_E_ACCEPTED: |
| 118 | evaluate_acceptance_outcome(fi, true); |
| 119 | osmo_fsm_inst_state_chg(fi, SUBSCR_CONN_S_ACCEPTED, SUBSCR_CONN_TIMEOUT, 0); |
| 120 | return; |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 121 | |
| 122 | case SUBSCR_CONN_E_MO_CLOSE: |
| 123 | case SUBSCR_CONN_E_CN_CLOSE: |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 124 | log_close_event(fi, event, data); |
| 125 | evaluate_acceptance_outcome(fi, false); |
| 126 | /* fall through */ |
| 127 | case SUBSCR_CONN_E_UNUSED: |
| 128 | osmo_fsm_inst_state_chg(fi, SUBSCR_CONN_S_RELEASING, SUBSCR_CONN_TIMEOUT, 0); |
| 129 | return; |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 130 | |
| 131 | default: |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 132 | OSMO_ASSERT(false); |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 133 | } |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 134 | } |
| 135 | |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 136 | void subscr_conn_fsm_auth_ciph(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
| 137 | { |
| 138 | /* If accepted, transition the state, all other cases mean failure. */ |
| 139 | switch (event) { |
| 140 | case SUBSCR_CONN_E_ACCEPTED: |
| 141 | evaluate_acceptance_outcome(fi, true); |
| 142 | osmo_fsm_inst_state_chg(fi, SUBSCR_CONN_S_ACCEPTED, SUBSCR_CONN_TIMEOUT, 0); |
| 143 | return; |
| 144 | |
| 145 | case SUBSCR_CONN_E_UNUSED: |
| 146 | LOGPFSML(fi, LOGL_DEBUG, "Awaiting results for Auth+Ciph, overruling event %s\n", |
| 147 | osmo_fsm_event_name(fi->fsm, event)); |
| 148 | return; |
| 149 | |
| 150 | case SUBSCR_CONN_E_MO_CLOSE: |
| 151 | case SUBSCR_CONN_E_CN_CLOSE: |
| 152 | log_close_event(fi, event, data); |
| 153 | evaluate_acceptance_outcome(fi, false); |
| 154 | osmo_fsm_inst_state_chg(fi, SUBSCR_CONN_S_RELEASING, SUBSCR_CONN_TIMEOUT, 0); |
| 155 | return; |
| 156 | |
| 157 | |
| 158 | default: |
| 159 | OSMO_ASSERT(false); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | static bool subscr_conn_fsm_has_active_transactions(struct osmo_fsm_inst *fi) |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 164 | { |
| 165 | struct gsm_subscriber_connection *conn = fi->priv; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 166 | struct gsm_trans *trans; |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 167 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 168 | if (conn->silent_call) { |
Neels Hofmeyr | e9e2f5c | 2018-03-15 13:26:43 +0100 | [diff] [blame] | 169 | LOGPFSML(fi, LOGL_DEBUG, "%s: silent call still active\n", __func__); |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 170 | return true; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 171 | } |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 172 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 173 | if (conn->received_cm_service_request) { |
Neels Hofmeyr | e9e2f5c | 2018-03-15 13:26:43 +0100 | [diff] [blame] | 174 | LOGPFSML(fi, LOGL_DEBUG, "%s: still awaiting first request after a CM Service Request\n", |
| 175 | __func__); |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 176 | return true; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 177 | } |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 178 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 179 | if (conn->vsub && !llist_empty(&conn->vsub->cs.requests)) { |
| 180 | struct subscr_request *sr; |
| 181 | if (!log_check_level(fi->fsm->log_subsys, LOGL_DEBUG)) { |
| 182 | llist_for_each_entry(sr, &conn->vsub->cs.requests, entry) { |
Neels Hofmeyr | e9e2f5c | 2018-03-15 13:26:43 +0100 | [diff] [blame] | 183 | LOGPFSML(fi, LOGL_DEBUG, "%s: still active: %s\n", |
| 184 | __func__, sr->label); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 185 | } |
| 186 | } |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 187 | return true; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 188 | } |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 189 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 190 | if ((trans = trans_has_conn(conn))) { |
| 191 | LOGPFSML(fi, LOGL_DEBUG, |
Neels Hofmeyr | e9e2f5c | 2018-03-15 13:26:43 +0100 | [diff] [blame] | 192 | "%s: connection still has active transaction: %s\n", |
| 193 | __func__, gsm48_pdisc_name(trans->protocol)); |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 194 | return true; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 195 | } |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 196 | |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 197 | return false; |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 198 | } |
| 199 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 200 | static void subscr_conn_fsm_accepted_enter(struct osmo_fsm_inst *fi, uint32_t prev_state) |
| 201 | { |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 202 | if (!subscr_conn_fsm_has_active_transactions(fi)) |
| 203 | osmo_fsm_inst_dispatch(fi, SUBSCR_CONN_E_UNUSED, NULL); |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 204 | } |
| 205 | |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 206 | static void subscr_conn_fsm_accepted(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
| 207 | { |
| 208 | switch (event) { |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 209 | case SUBSCR_CONN_E_COMMUNICATING: |
| 210 | osmo_fsm_inst_state_chg(fi, SUBSCR_CONN_S_COMMUNICATING, 0, 0); |
| 211 | return; |
| 212 | |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 213 | case SUBSCR_CONN_E_MO_CLOSE: |
| 214 | case SUBSCR_CONN_E_CN_CLOSE: |
| 215 | log_close_event(fi, event, data); |
| 216 | /* fall through */ |
| 217 | case SUBSCR_CONN_E_UNUSED: |
| 218 | osmo_fsm_inst_state_chg(fi, SUBSCR_CONN_S_RELEASING, SUBSCR_CONN_TIMEOUT, 0); |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 219 | return; |
| 220 | |
| 221 | default: |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 222 | OSMO_ASSERT(false); |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 223 | } |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 224 | } |
| 225 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 226 | static void subscr_conn_fsm_communicating(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
| 227 | { |
| 228 | switch (event) { |
| 229 | case SUBSCR_CONN_E_COMMUNICATING: |
| 230 | /* no-op */ |
| 231 | return; |
| 232 | |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 233 | case SUBSCR_CONN_E_MO_CLOSE: |
| 234 | case SUBSCR_CONN_E_CN_CLOSE: |
| 235 | log_close_event(fi, event, data); |
| 236 | /* fall through */ |
| 237 | case SUBSCR_CONN_E_UNUSED: |
| 238 | osmo_fsm_inst_state_chg(fi, SUBSCR_CONN_S_RELEASING, SUBSCR_CONN_TIMEOUT, 0); |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 239 | return; |
| 240 | |
| 241 | default: |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 242 | OSMO_ASSERT(false); |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 243 | } |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 244 | } |
| 245 | |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 246 | static int subscr_conn_fsm_timeout(struct osmo_fsm_inst *fi) |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 247 | { |
| 248 | struct gsm_subscriber_connection *conn = fi->priv; |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 249 | if (msc_subscr_conn_in_release(conn)) { |
| 250 | LOGPFSML(fi, LOGL_ERROR, "Timeout while releasing, discarding right now\n"); |
| 251 | osmo_fsm_inst_term(fi, OSMO_FSM_TERM_TIMEOUT, NULL); |
| 252 | } else { |
| 253 | uint32_t cause = GSM_CAUSE_NET_FAIL; |
| 254 | osmo_fsm_inst_dispatch(fi, SUBSCR_CONN_E_CN_CLOSE, &cause); |
| 255 | } |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 256 | return 0; |
| 257 | } |
| 258 | |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 259 | static void subscr_conn_fsm_releasing_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state) |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 260 | { |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 261 | struct gsm_subscriber_connection *conn = fi->priv; |
| 262 | |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 263 | /* Use count for either conn->a.waiting_for_clear_complete or |
| 264 | * conn->iu.waiting_for_release_complete. 'get' it early, so we don't deallocate after tearing |
| 265 | * down active transactions. Safeguard against double-get (though it shouldn't happen). */ |
| 266 | if (!msc_subscr_conn_used_by(conn, MSC_CONN_USE_RELEASE)) |
| 267 | msc_subscr_conn_get(conn, MSC_CONN_USE_RELEASE); |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 268 | |
| 269 | /* Cancel pending CM Service Requests */ |
| 270 | if (conn->received_cm_service_request) { |
| 271 | conn->received_cm_service_request = false; |
| 272 | msc_subscr_conn_put(conn, MSC_CONN_USE_CM_SERVICE); |
| 273 | } |
| 274 | |
| 275 | /* Cancel all VLR FSMs, if any */ |
| 276 | vlr_subscr_conn_timeout(conn->vsub); |
| 277 | |
| 278 | /* If we're closing in a middle of a trans, we need to clean up */ |
| 279 | trans_conn_closed(conn); |
| 280 | |
| 281 | switch (conn->via_ran) { |
| 282 | case RAN_GERAN_A: |
| 283 | a_iface_tx_clear_cmd(conn); |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 284 | if (conn->a.waiting_for_clear_complete) { |
| 285 | LOGPFSML(fi, LOGL_ERROR, |
| 286 | "Unexpected: conn is already waiting for BSSMAP Clear Complete\n"); |
| 287 | break; |
| 288 | } |
| 289 | conn->a.waiting_for_clear_complete = true; |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 290 | break; |
| 291 | case RAN_UTRAN_IU: |
| 292 | ranap_iu_tx_release(conn->iu.ue_ctx, NULL); |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 293 | if (conn->iu.waiting_for_release_complete) { |
| 294 | LOGPFSML(fi, LOGL_ERROR, |
| 295 | "Unexpected: conn is already waiting for Iu Release Complete\n"); |
| 296 | break; |
| 297 | } |
| 298 | conn->iu.waiting_for_release_complete = true; |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 299 | break; |
| 300 | default: |
| 301 | LOGP(DMM, LOGL_ERROR, "%s: Unknown RAN type, cannot tx release/clear\n", |
| 302 | vlr_subscr_name(conn->vsub)); |
| 303 | break; |
| 304 | } |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | static void subscr_conn_fsm_releasing(struct osmo_fsm_inst *fi, uint32_t event, void *data) |
| 308 | { |
| 309 | OSMO_ASSERT(event == SUBSCR_CONN_E_UNUSED); |
| 310 | osmo_fsm_inst_state_chg(fi, SUBSCR_CONN_S_RELEASED, 0, 0); |
| 311 | } |
| 312 | |
| 313 | static void subscr_conn_fsm_released(struct osmo_fsm_inst *fi, uint32_t prev_state) |
| 314 | { |
| 315 | /* Terminate, deallocate and also deallocate the gsm_subscriber_connection, which is allocated as |
| 316 | * a talloc child of fi. Also calls the cleanup function. */ |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 317 | osmo_fsm_inst_term(fi, OSMO_FSM_TERM_REGULAR, NULL); |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | #define S(x) (1 << (x)) |
| 321 | |
| 322 | static const struct osmo_fsm_state subscr_conn_fsm_states[] = { |
| 323 | [SUBSCR_CONN_S_NEW] = { |
| 324 | .name = OSMO_STRINGIFY(SUBSCR_CONN_S_NEW), |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 325 | .in_event_mask = S(SUBSCR_CONN_E_COMPLETE_LAYER_3) | |
| 326 | S(SUBSCR_CONN_E_ACCEPTED) | |
| 327 | S(SUBSCR_CONN_E_MO_CLOSE) | |
| 328 | S(SUBSCR_CONN_E_CN_CLOSE) | |
| 329 | S(SUBSCR_CONN_E_UNUSED), |
| 330 | .out_state_mask = S(SUBSCR_CONN_S_AUTH_CIPH) | |
| 331 | S(SUBSCR_CONN_S_ACCEPTED) | |
| 332 | S(SUBSCR_CONN_S_RELEASING), |
| 333 | .action = subscr_conn_fsm_new, |
| 334 | }, |
| 335 | [SUBSCR_CONN_S_AUTH_CIPH] = { |
| 336 | .name = OSMO_STRINGIFY(SUBSCR_CONN_S_AUTH_CIPH), |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 337 | .in_event_mask = S(SUBSCR_CONN_E_ACCEPTED) | |
| 338 | S(SUBSCR_CONN_E_MO_CLOSE) | |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 339 | S(SUBSCR_CONN_E_CN_CLOSE) | |
| 340 | S(SUBSCR_CONN_E_UNUSED), |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 341 | .out_state_mask = S(SUBSCR_CONN_S_ACCEPTED) | |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 342 | S(SUBSCR_CONN_S_RELEASING), |
| 343 | .action = subscr_conn_fsm_auth_ciph, |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 344 | }, |
| 345 | [SUBSCR_CONN_S_ACCEPTED] = { |
| 346 | .name = OSMO_STRINGIFY(SUBSCR_CONN_S_ACCEPTED), |
| 347 | /* allow everything to release for any odd behavior */ |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 348 | .in_event_mask = S(SUBSCR_CONN_E_COMMUNICATING) | |
Neels Hofmeyr | e9e2f5c | 2018-03-15 13:26:43 +0100 | [diff] [blame] | 349 | S(SUBSCR_CONN_E_RELEASE_WHEN_UNUSED) | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 350 | S(SUBSCR_CONN_E_ACCEPTED) | |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 351 | S(SUBSCR_CONN_E_MO_CLOSE) | |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 352 | S(SUBSCR_CONN_E_CN_CLOSE) | |
| 353 | S(SUBSCR_CONN_E_UNUSED), |
| 354 | .out_state_mask = S(SUBSCR_CONN_S_RELEASING) | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 355 | S(SUBSCR_CONN_S_COMMUNICATING), |
| 356 | .onenter = subscr_conn_fsm_accepted_enter, |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 357 | .action = subscr_conn_fsm_accepted, |
| 358 | }, |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 359 | [SUBSCR_CONN_S_COMMUNICATING] = { |
| 360 | .name = OSMO_STRINGIFY(SUBSCR_CONN_S_COMMUNICATING), |
| 361 | /* allow everything to release for any odd behavior */ |
Neels Hofmeyr | e9e2f5c | 2018-03-15 13:26:43 +0100 | [diff] [blame] | 362 | .in_event_mask = S(SUBSCR_CONN_E_RELEASE_WHEN_UNUSED) | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 363 | S(SUBSCR_CONN_E_ACCEPTED) | |
| 364 | S(SUBSCR_CONN_E_COMMUNICATING) | |
| 365 | S(SUBSCR_CONN_E_MO_CLOSE) | |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 366 | S(SUBSCR_CONN_E_CN_CLOSE) | |
| 367 | S(SUBSCR_CONN_E_UNUSED), |
| 368 | .out_state_mask = S(SUBSCR_CONN_S_RELEASING), |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 369 | .action = subscr_conn_fsm_communicating, |
| 370 | }, |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 371 | [SUBSCR_CONN_S_RELEASING] = { |
| 372 | .name = OSMO_STRINGIFY(SUBSCR_CONN_S_RELEASING), |
| 373 | .in_event_mask = S(SUBSCR_CONN_E_UNUSED), |
| 374 | .out_state_mask = S(SUBSCR_CONN_S_RELEASED), |
| 375 | .onenter = subscr_conn_fsm_releasing_onenter, |
| 376 | .action = subscr_conn_fsm_releasing, |
| 377 | }, |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 378 | [SUBSCR_CONN_S_RELEASED] = { |
| 379 | .name = OSMO_STRINGIFY(SUBSCR_CONN_S_RELEASED), |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 380 | .onenter = subscr_conn_fsm_released, |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 381 | }, |
| 382 | }; |
| 383 | |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 384 | static void subscr_conn_fsm_cleanup(struct osmo_fsm_inst *fi, enum osmo_fsm_term_cause cause); |
| 385 | |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 386 | static struct osmo_fsm subscr_conn_fsm = { |
| 387 | .name = "Subscr_Conn", |
| 388 | .states = subscr_conn_fsm_states, |
| 389 | .num_states = ARRAY_SIZE(subscr_conn_fsm_states), |
| 390 | .allstate_event_mask = 0, |
| 391 | .allstate_action = NULL, |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 392 | .log_subsys = DMM, |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 393 | .event_names = subscr_conn_fsm_event_names, |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 394 | .cleanup = subscr_conn_fsm_cleanup, |
| 395 | .timer_cb = subscr_conn_fsm_timeout, |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 396 | }; |
| 397 | |
Daniel Willmann | 4e825b6 | 2018-02-15 10:33:26 +0100 | [diff] [blame] | 398 | char *msc_subscr_conn_get_conn_id(struct gsm_subscriber_connection *conn) |
| 399 | { |
| 400 | char *id; |
| 401 | |
| 402 | switch (conn->via_ran) { |
| 403 | case RAN_GERAN_A: |
| 404 | id = talloc_asprintf(conn, "GERAN_A-%08x", conn->a.conn_id); |
| 405 | break; |
| 406 | case RAN_UTRAN_IU: |
| 407 | id = talloc_asprintf(conn, "UTRAN_IU-%08x", iu_get_conn_id(conn->iu.ue_ctx)); |
| 408 | break; |
| 409 | default: |
| 410 | LOGP(DMM, LOGL_ERROR, "RAN of conn %p unknown!\n", conn); |
| 411 | return NULL; |
| 412 | } |
| 413 | |
| 414 | return id; |
| 415 | } |
| 416 | |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 417 | /* Tidy up before the FSM deallocates */ |
| 418 | static void subscr_conn_fsm_cleanup(struct osmo_fsm_inst *fi, enum osmo_fsm_term_cause cause) |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 419 | { |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 420 | struct gsm_subscriber_connection *conn = fi->priv; |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 421 | |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 422 | if (subscr_conn_fsm_has_active_transactions(fi)) |
| 423 | LOGPFSML(fi, LOGL_ERROR, "Deallocating despite active transactions\n"); |
| 424 | |
| 425 | if (!conn) { |
| 426 | LOGP(DRLL, LOGL_ERROR, "Freeing NULL subscriber connection\n"); |
| 427 | return; |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 428 | } |
| 429 | |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 430 | if (conn->vsub) { |
| 431 | DEBUGP(DRLL, "%s: Freeing subscriber connection\n", vlr_subscr_name(conn->vsub)); |
| 432 | conn->vsub->lu_fsm = NULL; |
| 433 | conn->vsub->msc_conn_ref = NULL; |
| 434 | vlr_subscr_put(conn->vsub); |
| 435 | conn->vsub = NULL; |
| 436 | } else |
| 437 | DEBUGP(DRLL, "Freeing subscriber connection with NULL subscriber\n"); |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 438 | |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 439 | llist_del(&conn->entry); |
| 440 | } |
| 441 | |
| 442 | /* Signal success of Complete Layer 3. Allow to keep the conn open for Auth and Ciph. */ |
| 443 | void msc_subscr_conn_complete_layer_3(struct gsm_subscriber_connection *conn) |
| 444 | { |
| 445 | if (!conn) |
| 446 | return; |
| 447 | osmo_fsm_inst_dispatch(conn->fi, SUBSCR_CONN_E_COMPLETE_LAYER_3, NULL); |
| 448 | } |
| 449 | |
| 450 | void subscr_conn_release_when_unused(struct gsm_subscriber_connection *conn) |
| 451 | { |
| 452 | if (!conn) |
| 453 | return; |
| 454 | if (msc_subscr_conn_in_release(conn)) { |
| 455 | DEBUGP(DMM, "%s: %s: conn already in release (%s)\n", |
| 456 | vlr_subscr_name(conn->vsub), __func__, |
| 457 | osmo_fsm_inst_state_name(conn->fi)); |
| 458 | return; |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 459 | } |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 460 | if (conn->fi->state == SUBSCR_CONN_S_NEW) { |
| 461 | DEBUGP(DMM, "%s: %s: conn still being established (%s)\n", |
| 462 | vlr_subscr_name(conn->vsub), __func__, |
| 463 | osmo_fsm_inst_state_name(conn->fi)); |
| 464 | return; |
| 465 | } |
| 466 | osmo_fsm_inst_dispatch(conn->fi, SUBSCR_CONN_E_RELEASE_WHEN_UNUSED, NULL); |
| 467 | } |
| 468 | |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 469 | static void conn_close(struct gsm_subscriber_connection *conn, uint32_t cause, uint32_t event) |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 470 | { |
| 471 | if (!conn) { |
| 472 | LOGP(DMM, LOGL_ERROR, "Cannot release NULL connection\n"); |
| 473 | return; |
| 474 | } |
| 475 | if (msc_subscr_conn_in_release(conn)) { |
| 476 | DEBUGP(DMM, "%s(vsub=%s, cause=%u): already in release, ignore.\n", |
| 477 | __func__, vlr_subscr_name(conn->vsub), cause); |
| 478 | return; |
| 479 | } |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 480 | osmo_fsm_inst_dispatch(conn->fi, event, &cause); |
| 481 | } |
| 482 | |
| 483 | void msc_subscr_conn_close(struct gsm_subscriber_connection *conn, uint32_t cause) |
| 484 | { |
| 485 | return conn_close(conn, cause, SUBSCR_CONN_E_CN_CLOSE); |
| 486 | } |
| 487 | |
| 488 | void msc_subscr_conn_mo_close(struct gsm_subscriber_connection *conn, uint32_t cause) |
| 489 | { |
| 490 | return conn_close(conn, cause, SUBSCR_CONN_E_MO_CLOSE); |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | bool msc_subscr_conn_in_release(struct gsm_subscriber_connection *conn) |
| 494 | { |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 495 | if (!conn || !conn->fi) |
| 496 | return true; |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 497 | if (conn->fi->state == SUBSCR_CONN_S_RELEASING) |
| 498 | return true; |
| 499 | if (conn->fi->state == SUBSCR_CONN_S_RELEASED) |
| 500 | return true; |
| 501 | return false; |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 502 | } |
| 503 | |
Max | d83b17b | 2018-02-06 16:51:31 +0100 | [diff] [blame] | 504 | bool msc_subscr_conn_is_accepted(const struct gsm_subscriber_connection *conn) |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 505 | { |
| 506 | if (!conn) |
| 507 | return false; |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 508 | if (!conn->vsub) |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 509 | return false; |
Neels Hofmeyr | 4d3a66b | 2018-03-31 18:45:59 +0200 | [diff] [blame] | 510 | if (!(conn->fi->state == SUBSCR_CONN_S_ACCEPTED |
| 511 | || conn->fi->state == SUBSCR_CONN_S_COMMUNICATING)) |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 512 | return false; |
| 513 | return true; |
| 514 | } |
| 515 | |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 516 | /* Indicate that *some* communication is happening with the phone, so that the conn FSM no longer times |
| 517 | * out to release within a few seconds. */ |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 518 | void msc_subscr_conn_communicating(struct gsm_subscriber_connection *conn) |
| 519 | { |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 520 | osmo_fsm_inst_dispatch(conn->fi, SUBSCR_CONN_E_COMMUNICATING, NULL); |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 521 | } |
| 522 | |
Harald Welte | b8b85a1 | 2016-06-17 00:06:42 +0200 | [diff] [blame] | 523 | void msc_subscr_conn_init(void) |
| 524 | { |
| 525 | osmo_fsm_register(&subscr_conn_fsm); |
| 526 | } |
Neels Hofmeyr | 16c42b5 | 2018-04-02 12:26:16 +0200 | [diff] [blame] | 527 | |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 528 | /* Allocate a new subscriber conn and FSM. |
| 529 | * Deallocation is by msc_subscr_conn_put(): when the use count reaches zero, the |
| 530 | * SUBSCR_CONN_E_RELEASE_COMPLETE event is dispatched, the FSM terminates and deallocates both FSM and |
| 531 | * conn. As long as the FSM is waiting for responses from the subscriber, it will itself hold a use count |
| 532 | * on the conn. */ |
Neels Hofmeyr | 93c7463 | 2018-04-02 23:10:28 +0200 | [diff] [blame] | 533 | struct gsm_subscriber_connection *msc_subscr_conn_alloc(struct gsm_network *network, |
| 534 | enum ran_type via_ran, uint16_t lac) |
| 535 | { |
| 536 | struct gsm_subscriber_connection *conn; |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 537 | struct osmo_fsm_inst *fi; |
Neels Hofmeyr | 93c7463 | 2018-04-02 23:10:28 +0200 | [diff] [blame] | 538 | |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 539 | fi = osmo_fsm_inst_alloc(&subscr_conn_fsm, network, NULL, LOGL_DEBUG, NULL); |
| 540 | if (!fi) { |
| 541 | LOGP(DMM, LOGL_ERROR, "Failed to allocate conn FSM\n"); |
Neels Hofmeyr | 93c7463 | 2018-04-02 23:10:28 +0200 | [diff] [blame] | 542 | return NULL; |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | conn = talloc_zero(fi, struct gsm_subscriber_connection); |
| 546 | if (!conn) { |
| 547 | osmo_fsm_inst_free(fi); |
| 548 | return NULL; |
| 549 | } |
Neels Hofmeyr | 93c7463 | 2018-04-02 23:10:28 +0200 | [diff] [blame] | 550 | |
| 551 | *conn = (struct gsm_subscriber_connection){ |
| 552 | .network = network, |
| 553 | .via_ran = via_ran, |
| 554 | .lac = lac, |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 555 | .fi = fi, |
Neels Hofmeyr | 93c7463 | 2018-04-02 23:10:28 +0200 | [diff] [blame] | 556 | }; |
| 557 | |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 558 | fi->priv = conn; |
Neels Hofmeyr | 93c7463 | 2018-04-02 23:10:28 +0200 | [diff] [blame] | 559 | llist_add_tail(&conn->entry, &network->subscr_conns); |
| 560 | return conn; |
| 561 | } |
| 562 | |
Neels Hofmeyr | e3d3dc6 | 2018-03-31 00:02:14 +0200 | [diff] [blame] | 563 | bool msc_subscr_conn_is_establishing_auth_ciph(const struct gsm_subscriber_connection *conn) |
| 564 | { |
| 565 | if (!conn) |
| 566 | return false; |
| 567 | return conn->fi->state == SUBSCR_CONN_S_AUTH_CIPH; |
| 568 | } |
| 569 | |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 570 | |
Neels Hofmeyr | 16c42b5 | 2018-04-02 12:26:16 +0200 | [diff] [blame] | 571 | const struct value_string complete_layer3_type_names[] = { |
| 572 | { COMPLETE_LAYER3_NONE, "NONE" }, |
| 573 | { COMPLETE_LAYER3_LU, "LU" }, |
| 574 | { COMPLETE_LAYER3_CM_SERVICE_REQ, "CM_SERVICE_REQ" }, |
| 575 | { COMPLETE_LAYER3_PAGING_RESP, "PAGING_RESP" }, |
| 576 | { 0, NULL } |
| 577 | }; |
| 578 | |
| 579 | void msc_subscr_conn_update_id(struct gsm_subscriber_connection *conn, |
| 580 | enum complete_layer3_type from, const char *id) |
| 581 | { |
| 582 | conn->complete_layer3_type = from; |
Neels Hofmeyr | fe4ba7c | 2018-04-02 23:17:50 +0200 | [diff] [blame^] | 583 | osmo_fsm_inst_update_id_f(conn->fi, "%s:%s", complete_layer3_type_name(from), id); |
| 584 | LOGPFSML(conn->fi, LOGL_DEBUG, "Updated ID\n"); |
Neels Hofmeyr | 16c42b5 | 2018-04-02 12:26:16 +0200 | [diff] [blame] | 585 | } |
Neels Hofmeyr | 4068ab2 | 2018-04-01 20:55:54 +0200 | [diff] [blame] | 586 | |
| 587 | static void rx_close_complete(struct gsm_subscriber_connection *conn, const char *label, bool *flag) |
| 588 | { |
| 589 | if (!conn) |
| 590 | return; |
| 591 | if (!msc_subscr_conn_in_release(conn)) { |
| 592 | LOGPFSML(conn->fi, LOGL_ERROR, "Received unexpected %s, discarding right now\n", |
| 593 | label); |
| 594 | trans_conn_closed(conn); |
| 595 | osmo_fsm_inst_term(conn->fi, OSMO_FSM_TERM_ERROR, NULL); |
| 596 | return; |
| 597 | } |
| 598 | if (*flag) { |
| 599 | *flag = false; |
| 600 | msc_subscr_conn_put(conn, MSC_CONN_USE_RELEASE); |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | void msc_subscr_conn_rx_bssmap_clear_complete(struct gsm_subscriber_connection *conn) |
| 605 | { |
| 606 | rx_close_complete(conn, "BSSMAP Clear Complete", &conn->a.waiting_for_clear_complete); |
| 607 | } |
| 608 | |
| 609 | void msc_subscr_conn_rx_iu_release_complete(struct gsm_subscriber_connection *conn) |
| 610 | { |
| 611 | rx_close_complete(conn, "Iu Release Complete", &conn->iu.waiting_for_release_complete); |
| 612 | } |