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