Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 1 | /* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org> |
| 2 | * (C) 2008, 2009 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 3 | * (C) 2009 by Mike Haben <michael.haben@btinternet.com> |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 4 | * (C) 2018 by Vadim Yanitskiy <axilirator@gmail.com> |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 5 | * |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 9 | * it under the terms of the GNU Affero General Public License as published by |
| 10 | * the Free Software Foundation; either version 3 of the License, or |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 16 | * GNU Affero General Public License for more details. |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 17 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 18 | * You should have received a copy of the GNU Affero General Public License |
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 20 | * |
| 21 | */ |
| 22 | |
Vadim Yanitskiy | 5b860fa | 2018-06-12 05:24:52 +0700 | [diff] [blame] | 23 | /** |
| 24 | * MSC-specific handling of call independent Supplementary |
| 25 | * Services messages (NC_SS) according to GSM TS 09.11 |
| 26 | * "Signalling interworking for supplementary services". |
| 27 | */ |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 28 | |
| 29 | #include <stdio.h> |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 30 | #include <errno.h> |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 31 | #include <stdbool.h> |
| 32 | |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 33 | #include <osmocom/core/linuxlist.h> |
Vadim Yanitskiy | 8e25cc5 | 2018-06-23 03:32:20 +0700 | [diff] [blame] | 34 | #include <osmocom/core/rate_ctr.h> |
Alexander Couzens | efa7b97 | 2019-04-27 23:45:37 +0200 | [diff] [blame] | 35 | #include <osmocom/core/stat_item.h> |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 36 | #include <osmocom/core/utils.h> |
| 37 | #include <osmocom/core/msgb.h> |
Vadim Yanitskiy | 0622ef5 | 2018-08-03 04:39:04 +0700 | [diff] [blame] | 38 | |
| 39 | #include <osmocom/gsm/protocol/gsm_04_80.h> |
| 40 | #include <osmocom/gsm/gsm0480.h> |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 41 | #include <osmocom/gsm/tlv.h> |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 42 | |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 43 | #include <osmocom/msc/gsm_04_80.h> |
| 44 | #include <osmocom/msc/gsm_subscriber.h> |
| 45 | #include <osmocom/msc/debug.h> |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 46 | #include <osmocom/msc/vlr.h> |
Max | 43b01b0 | 2017-09-15 11:22:30 +0200 | [diff] [blame] | 47 | #include <osmocom/msc/gsm_04_08.h> |
Vadim Yanitskiy | 10c6419 | 2018-04-17 19:17:11 +0700 | [diff] [blame] | 48 | #include <osmocom/msc/transaction.h> |
Harald Welte | 1ea6baf | 2018-07-31 19:40:52 +0200 | [diff] [blame] | 49 | #include <osmocom/gsupclient/gsup_client.h> |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 50 | #include <osmocom/msc/msc_a.h> |
| 51 | #include <osmocom/msc/msub.h> |
| 52 | #include <osmocom/msc/paging.h> |
| 53 | #include <osmocom/msc/gsup_client_mux.h> |
Vadim Yanitskiy | 10c6419 | 2018-04-17 19:17:11 +0700 | [diff] [blame] | 54 | |
| 55 | /* FIXME: choose a proper range */ |
| 56 | static uint32_t new_callref = 0x20000001; |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 57 | |
Vadim Yanitskiy | 64623e1 | 2018-11-28 23:05:51 +0700 | [diff] [blame] | 58 | static void ncss_session_timeout_handler(void *_trans) |
| 59 | { |
| 60 | struct gsm_trans *trans = (struct gsm_trans *) _trans; |
Vadim Yanitskiy | 944d6a2 | 2019-06-17 21:57:08 +0700 | [diff] [blame] | 61 | struct osmo_gsup_message gsup_msg; |
Vadim Yanitskiy | 64623e1 | 2018-11-28 23:05:51 +0700 | [diff] [blame] | 62 | |
| 63 | /* The timeout might be disabled from the VTY */ |
| 64 | if (trans->net->ncss_guard_timeout == 0) |
| 65 | return; |
| 66 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 67 | LOG_TRANS(trans, LOGL_NOTICE, "SS/USSD session timeout, releasing\n"); |
Vadim Yanitskiy | 64623e1 | 2018-11-28 23:05:51 +0700 | [diff] [blame] | 68 | |
| 69 | /* Indicate connection release to subscriber (if active) */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 70 | if (trans->msc_a != NULL) { |
Vadim Yanitskiy | 64623e1 | 2018-11-28 23:05:51 +0700 | [diff] [blame] | 71 | /* This pair of cause location and value is used by commercial networks */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 72 | msc_send_ussd_release_complete_cause(trans->msc_a, trans->transaction_id, |
Vadim Yanitskiy | 64623e1 | 2018-11-28 23:05:51 +0700 | [diff] [blame] | 73 | GSM48_CAUSE_LOC_PUN_S_LU, GSM48_CC_CAUSE_NORMAL_UNSPEC); |
| 74 | } |
| 75 | |
| 76 | /* Terminate GSUP session with EUSE */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 77 | gsup_msg = (struct osmo_gsup_message){ |
| 78 | .message_type = OSMO_GSUP_MSGT_PROC_SS_ERROR, |
| 79 | |
| 80 | .session_state = OSMO_GSUP_SESSION_STATE_END, |
| 81 | .session_id = trans->callref, |
| 82 | .cause = GMM_CAUSE_NET_FAIL, |
| 83 | |
| 84 | .message_class = OSMO_GSUP_MESSAGE_CLASS_USSD, |
| 85 | }; |
| 86 | |
Vadim Yanitskiy | 64623e1 | 2018-11-28 23:05:51 +0700 | [diff] [blame] | 87 | OSMO_STRLCPY_ARRAY(gsup_msg.imsi, trans->vsub->imsi); |
| 88 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 89 | gsup_client_mux_tx(trans->net->gcm, &gsup_msg); |
Vadim Yanitskiy | 64623e1 | 2018-11-28 23:05:51 +0700 | [diff] [blame] | 90 | |
| 91 | /* Finally, release this transaction */ |
| 92 | trans_free(trans); |
| 93 | } |
| 94 | |
Vadim Yanitskiy | 5b860fa | 2018-06-12 05:24:52 +0700 | [diff] [blame] | 95 | /* Entry point for call independent MO SS messages */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 96 | int gsm0911_rcv_nc_ss(struct msc_a *msc_a, struct msgb *msg) |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 97 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 98 | struct gsm_network *net; |
| 99 | struct vlr_subscr *vsub; |
Vadim Yanitskiy | 10c6419 | 2018-04-17 19:17:11 +0700 | [diff] [blame] | 100 | struct gsm48_hdr *gh = msgb_l3(msg); |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 101 | struct osmo_gsup_message gsup_msg; |
Vadim Yanitskiy | 10c6419 | 2018-04-17 19:17:11 +0700 | [diff] [blame] | 102 | struct gsm_trans *trans; |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 103 | uint16_t facility_ie_len; |
| 104 | uint8_t *facility_ie; |
Max | 4a5cfa5 | 2019-01-10 17:41:05 +0100 | [diff] [blame] | 105 | uint8_t tid; |
Vadim Yanitskiy | 10c6419 | 2018-04-17 19:17:11 +0700 | [diff] [blame] | 106 | uint8_t msg_type; |
| 107 | int rc; |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 108 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 109 | net = msc_a_net(msc_a); |
| 110 | OSMO_ASSERT(net); |
| 111 | |
| 112 | vsub = msc_a_vsub(msc_a); |
| 113 | if (!vsub) { |
| 114 | LOG_MSC_A(msc_a, LOGL_ERROR, "No vlr_subscr set for this conn\n"); |
| 115 | return -EINVAL; |
| 116 | } |
| 117 | |
Vadim Yanitskiy | 10c6419 | 2018-04-17 19:17:11 +0700 | [diff] [blame] | 118 | msg_type = gsm48_hdr_msg_type(gh); |
| 119 | tid = gsm48_hdr_trans_id_flip_ti(gh); |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 120 | |
Vadim Yanitskiy | 10c6419 | 2018-04-17 19:17:11 +0700 | [diff] [blame] | 121 | /* Associate logging messages with this subscriber */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 122 | log_set_context(LOG_CTX_VLR_SUBSCR, vsub); |
Vadim Yanitskiy | 10c6419 | 2018-04-17 19:17:11 +0700 | [diff] [blame] | 123 | |
Vadim Yanitskiy | 10c6419 | 2018-04-17 19:17:11 +0700 | [diff] [blame] | 124 | /* Reuse existing transaction, or create a new one */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 125 | trans = trans_find_by_id(msc_a, TRANS_USSD, tid); |
Vadim Yanitskiy | 10c6419 | 2018-04-17 19:17:11 +0700 | [diff] [blame] | 126 | if (!trans) { |
Vadim Yanitskiy | 8e25cc5 | 2018-06-23 03:32:20 +0700 | [diff] [blame] | 127 | /* Count MS-initiated attempts to establish a NC SS/USSD session */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 128 | rate_ctr_inc(&net->msc_ctrs->ctr[MSC_CTR_NC_SS_MO_REQUESTS]); |
Vadim Yanitskiy | 8e25cc5 | 2018-06-23 03:32:20 +0700 | [diff] [blame] | 129 | |
Vadim Yanitskiy | 10c6419 | 2018-04-17 19:17:11 +0700 | [diff] [blame] | 130 | /** |
| 131 | * According to GSM TS 04.80, section 2.4.2 "Register |
| 132 | * (mobile station to network direction)", the REGISTER |
| 133 | * message is sent by the mobile station to the network |
| 134 | * to assign a new transaction identifier for call independent |
| 135 | * supplementary service control and to request or acknowledge |
| 136 | * a supplementary service. |
| 137 | */ |
| 138 | if (msg_type != GSM0480_MTYPE_REGISTER) { |
Vadim Yanitskiy | 6632251 | 2019-06-17 22:12:54 +0700 | [diff] [blame] | 139 | LOGP(DSS, LOGL_ERROR, "Rx %s message for non-existing transaction (tid-%u)\n", |
| 140 | gsm48_pdisc_msgtype_name(GSM48_PDISC_NC_SS, msg_type), |
| 141 | gsm48_hdr_trans_id(gh)); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 142 | gsm48_tx_simple(msc_a, |
Vadim Yanitskiy | 9aec25e | 2018-06-12 06:26:28 +0700 | [diff] [blame] | 143 | GSM48_PDISC_NC_SS | (tid << 4), |
| 144 | GSM0480_MTYPE_RELEASE_COMPLETE); |
Vadim Yanitskiy | 10c6419 | 2018-04-17 19:17:11 +0700 | [diff] [blame] | 145 | return -EINVAL; |
| 146 | } |
| 147 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 148 | trans = trans_alloc(net, vsub, TRANS_USSD, tid, new_callref++); |
Vadim Yanitskiy | 10c6419 | 2018-04-17 19:17:11 +0700 | [diff] [blame] | 149 | if (!trans) { |
Vadim Yanitskiy | 6632251 | 2019-06-17 22:12:54 +0700 | [diff] [blame] | 150 | LOGP(DSS, LOGL_ERROR, " -> No memory for trans\n"); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 151 | gsm48_tx_simple(msc_a, |
Vadim Yanitskiy | 9aec25e | 2018-06-12 06:26:28 +0700 | [diff] [blame] | 152 | GSM48_PDISC_NC_SS | (tid << 4), |
| 153 | GSM0480_MTYPE_RELEASE_COMPLETE); |
Vadim Yanitskiy | 10c6419 | 2018-04-17 19:17:11 +0700 | [diff] [blame] | 154 | return -ENOMEM; |
| 155 | } |
| 156 | |
Vadim Yanitskiy | 64623e1 | 2018-11-28 23:05:51 +0700 | [diff] [blame] | 157 | /* Init inactivity timer */ |
| 158 | osmo_timer_setup(&trans->ss.timer_guard, |
| 159 | ncss_session_timeout_handler, trans); |
| 160 | |
Vadim Yanitskiy | ad64e2a | 2018-06-26 18:27:25 +0700 | [diff] [blame] | 161 | /* Count active NC SS/USSD sessions */ |
Alexander Couzens | efa7b97 | 2019-04-27 23:45:37 +0200 | [diff] [blame] | 162 | osmo_stat_item_inc(net->statg->items[MSC_STAT_ACTIVE_NC_SS], 1); |
Vadim Yanitskiy | ad64e2a | 2018-06-26 18:27:25 +0700 | [diff] [blame] | 163 | |
Vadim Yanitskiy | 10c6419 | 2018-04-17 19:17:11 +0700 | [diff] [blame] | 164 | trans->dlci = OMSC_LINKID_CB(msg); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 165 | trans->msc_a = msc_a; |
| 166 | msc_a_get(msc_a, MSC_A_USE_NC_SS); |
| 167 | |
| 168 | osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_A_EV_TRANSACTION_ACCEPTED, trans); |
| 169 | |
| 170 | /* An earlier CM Service Request for this SS message now has concluded */ |
| 171 | if (!osmo_use_count_by(&msc_a->use_count, MSC_A_USE_CM_SERVICE_SS)) |
| 172 | LOG_MSC_A(msc_a, LOGL_ERROR, |
| 173 | "Creating new MO SS transaction without prior CM Service Request\n"); |
| 174 | else |
| 175 | msc_a_put(msc_a, MSC_A_USE_CM_SERVICE_SS); |
Vadim Yanitskiy | 10c6419 | 2018-04-17 19:17:11 +0700 | [diff] [blame] | 176 | } |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 177 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 178 | LOG_TRANS(trans, LOGL_DEBUG, "Received SS/USSD msg %s\n", |
| 179 | gsm48_pdisc_msgtype_name(GSM48_PDISC_NC_SS, msg_type)); |
| 180 | |
Vadim Yanitskiy | 64623e1 | 2018-11-28 23:05:51 +0700 | [diff] [blame] | 181 | /* (Re)schedule the inactivity timer */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 182 | if (net->ncss_guard_timeout > 0) { |
| 183 | osmo_timer_schedule(&trans->ss.timer_guard, net->ncss_guard_timeout, 0); |
Vadim Yanitskiy | 64623e1 | 2018-11-28 23:05:51 +0700 | [diff] [blame] | 184 | } |
| 185 | |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 186 | /* Attempt to extract Facility IE */ |
| 187 | rc = gsm0480_extract_ie_by_tag(gh, msgb_l3len(msg), |
| 188 | &facility_ie, &facility_ie_len, GSM0480_IE_FACILITY); |
| 189 | if (rc) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 190 | LOG_TRANS(trans, LOGL_ERROR, "GSM 04.80 message parsing error, couldn't extract Facility IE\n"); |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 191 | goto error; |
Tobias Engel | ea73032 | 2013-12-28 17:03:14 +0100 | [diff] [blame] | 192 | } |
| 193 | |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 194 | /* Facility IE is optional for RELEASE COMPLETE */ |
| 195 | if (msg_type != GSM0480_MTYPE_RELEASE_COMPLETE) { |
| 196 | if (!facility_ie || facility_ie_len < 2) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 197 | LOG_TRANS(trans, LOGL_ERROR, "GSM 04.80 message parsing error," |
| 198 | " missing mandatory Facility IE\n"); |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 199 | rc = -EINVAL; |
| 200 | goto error; |
Holger Hans Peter Freyther | 5085e0b | 2016-07-12 17:53:26 +0200 | [diff] [blame] | 201 | } |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | /* Compose a mew GSUP message */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 205 | gsup_msg = (struct osmo_gsup_message){ |
| 206 | .message_type = OSMO_GSUP_MSGT_PROC_SS_REQUEST, |
| 207 | .session_id = trans->callref, |
| 208 | .message_class = OSMO_GSUP_MESSAGE_CLASS_USSD, |
| 209 | }; |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 210 | |
| 211 | /** |
| 212 | * Perform A-interface to GSUP-interface mapping, |
| 213 | * according to GSM TS 09.11, table 4.2. |
| 214 | */ |
| 215 | switch (msg_type) { |
| 216 | case GSM0480_MTYPE_REGISTER: |
| 217 | gsup_msg.session_state = OSMO_GSUP_SESSION_STATE_BEGIN; |
| 218 | break; |
| 219 | case GSM0480_MTYPE_FACILITY: |
| 220 | gsup_msg.session_state = OSMO_GSUP_SESSION_STATE_CONTINUE; |
| 221 | break; |
| 222 | case GSM0480_MTYPE_RELEASE_COMPLETE: |
| 223 | gsup_msg.session_state = OSMO_GSUP_SESSION_STATE_END; |
| 224 | break; |
| 225 | } |
| 226 | |
| 227 | /* Fill in the (optional) message payload */ |
| 228 | if (facility_ie) { |
| 229 | gsup_msg.ss_info_len = facility_ie_len; |
| 230 | gsup_msg.ss_info = facility_ie; |
| 231 | } |
| 232 | |
| 233 | /* Fill in subscriber's IMSI */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 234 | OSMO_STRLCPY_ARRAY(gsup_msg.imsi, vsub->imsi); |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 235 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 236 | rc = gsup_client_mux_tx(trans->net->gcm, &gsup_msg); |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 237 | |
Vadim Yanitskiy | fcc24ed | 2018-06-21 17:55:56 +0700 | [diff] [blame] | 238 | /* Should we release connection? Or wait for response? */ |
| 239 | if (msg_type == GSM0480_MTYPE_RELEASE_COMPLETE) |
| 240 | trans_free(trans); |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 241 | |
Vadim Yanitskiy | 8e25cc5 | 2018-06-23 03:32:20 +0700 | [diff] [blame] | 242 | /* Count established MS-initiated NC SS/USSD sessions */ |
| 243 | if (msg_type == GSM0480_MTYPE_REGISTER) |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 244 | rate_ctr_inc(&net->msc_ctrs->ctr[MSC_CTR_NC_SS_MO_ESTABLISHED]); |
Vadim Yanitskiy | 8e25cc5 | 2018-06-23 03:32:20 +0700 | [diff] [blame] | 245 | |
Vadim Yanitskiy | b3bdc76 | 2019-06-17 22:23:09 +0700 | [diff] [blame] | 246 | return rc; |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 247 | |
| 248 | error: |
| 249 | /* Abort transaction on DTAP-interface */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 250 | msc_send_ussd_reject(msc_a, tid, -1, |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 251 | GSM_0480_PROBLEM_CODE_TAG_GENERAL, |
| 252 | GSM_0480_GEN_PROB_CODE_UNRECOGNISED); |
| 253 | if (trans) |
| 254 | trans_free(trans); |
| 255 | |
| 256 | /* TODO: abort transaction on GSUP interface if any */ |
| 257 | return rc; |
| 258 | } |
| 259 | |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 260 | /* Call-back from paging the B-end of the connection */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 261 | static void ss_paging_cb(struct msc_a *msc_a, struct gsm_trans *trans) |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 262 | { |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 263 | struct gsm48_hdr *gh; |
| 264 | struct msgb *ss_msg; |
| 265 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 266 | if (trans->msc_a) { |
| 267 | LOG_MSC_A_CAT(msc_a, DPAG, LOGL_ERROR, |
| 268 | "Handle paging error: transaction already associated with subsciber," |
| 269 | " apparently it was already handled. Skip.\n"); |
| 270 | return; |
| 271 | } |
| 272 | OSMO_ASSERT(trans->ss.msg); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 273 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 274 | if (msc_a) { |
| 275 | struct gsm_network *net = msc_a_net(msc_a); |
Neels Hofmeyr | 979b057 | 2019-05-09 15:24:49 +0200 | [diff] [blame] | 276 | LOG_MSC_A_CAT(msc_a, DSS, LOGL_DEBUG, "Paging succeeded\n"); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 277 | |
| 278 | /* Assign connection */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 279 | msc_a_get(msc_a, MSC_A_USE_NC_SS); |
| 280 | trans->msc_a = msc_a; |
| 281 | trans->paging_request = NULL; |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 282 | |
Vadim Yanitskiy | 64623e1 | 2018-11-28 23:05:51 +0700 | [diff] [blame] | 283 | /* (Re)schedule the inactivity timer */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 284 | if (net->ncss_guard_timeout > 0) { |
| 285 | osmo_timer_schedule(&trans->ss.timer_guard, net->ncss_guard_timeout, 0); |
Vadim Yanitskiy | 64623e1 | 2018-11-28 23:05:51 +0700 | [diff] [blame] | 286 | } |
| 287 | |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 288 | /* Send stored message */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 289 | ss_msg = trans->ss.msg; |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 290 | gh = (struct gsm48_hdr *) msgb_push(ss_msg, sizeof(*gh)); |
| 291 | gh->proto_discr = GSM48_PDISC_NC_SS; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 292 | gh->proto_discr |= trans->transaction_id << 4; |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 293 | gh->msg_type = GSM0480_MTYPE_REGISTER; |
| 294 | |
| 295 | /* Sent to the MS, give ownership of ss_msg */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 296 | msc_a_tx_dtap_to_i(msc_a, ss_msg); |
| 297 | trans->ss.msg = NULL; |
Vadim Yanitskiy | 8e25cc5 | 2018-06-23 03:32:20 +0700 | [diff] [blame] | 298 | |
| 299 | /* Count established network-initiated NC SS/USSD sessions */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 300 | rate_ctr_inc(&net->msc_ctrs->ctr[MSC_CTR_NC_SS_MT_ESTABLISHED]); |
| 301 | } else { |
Vadim Yanitskiy | 7480852 | 2019-06-16 02:35:28 +0700 | [diff] [blame] | 302 | struct osmo_gsup_message gsup_msg; |
| 303 | |
Neels Hofmeyr | 979b057 | 2019-05-09 15:24:49 +0200 | [diff] [blame] | 304 | LOG_MSC_A_CAT(msc_a, DSS, LOGL_DEBUG, "Paging expired\n"); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 305 | |
Vadim Yanitskiy | 7480852 | 2019-06-16 02:35:28 +0700 | [diff] [blame] | 306 | gsup_msg = (struct osmo_gsup_message){ |
| 307 | .message_class = OSMO_GSUP_MESSAGE_CLASS_USSD, |
| 308 | .message_type = OSMO_GSUP_MSGT_PROC_SS_ERROR, |
| 309 | |
| 310 | .session_state = OSMO_GSUP_SESSION_STATE_END, |
| 311 | .session_id = trans->callref, |
| 312 | /* FIXME: we need message class specific cause values */ |
| 313 | .cause = GMM_CAUSE_IMPL_DETACHED, |
| 314 | }; |
| 315 | |
| 316 | /* Fill in subscriber's IMSI */ |
| 317 | OSMO_STRLCPY_ARRAY(gsup_msg.imsi, trans->vsub->imsi); |
| 318 | |
| 319 | /* Inform HLR/EUSE about the failure */ |
| 320 | gsup_client_mux_tx(trans->net->gcm, &gsup_msg); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 321 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 322 | msgb_free(trans->ss.msg); |
| 323 | trans->ss.msg = NULL; |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 324 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 325 | trans->callref = 0; |
| 326 | trans->paging_request = NULL; |
| 327 | trans_free(trans); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 328 | } |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | static struct gsm_trans *establish_nc_ss_trans(struct gsm_network *net, |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 332 | struct vlr_subscr *vsub, const struct osmo_gsup_message *gsup_msg) |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 333 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 334 | struct msc_a *msc_a; |
Vadim Yanitskiy | 95b040c | 2019-06-15 16:56:20 +0700 | [diff] [blame] | 335 | struct gsm_trans *trans; |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 336 | int tid; |
| 337 | |
| 338 | if (gsup_msg->session_state != OSMO_GSUP_SESSION_STATE_BEGIN) { |
Vadim Yanitskiy | 10c3ce5 | 2019-06-15 15:52:23 +0700 | [diff] [blame] | 339 | LOGP(DSS, LOGL_ERROR, "Received non-BEGIN message for non-existing transaction\n"); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 340 | return NULL; |
| 341 | } |
| 342 | |
Vadim Yanitskiy | 10c3ce5 | 2019-06-15 15:52:23 +0700 | [diff] [blame] | 343 | LOGP(DSS, LOGL_DEBUG, "(%s) Establishing a network-originated session (id=0x%x)\n", |
| 344 | vlr_subscr_name(vsub), gsup_msg->session_id); |
| 345 | |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 346 | if (!gsup_msg->ss_info || gsup_msg->ss_info_len < 2) { |
Vadim Yanitskiy | 10c3ce5 | 2019-06-15 15:52:23 +0700 | [diff] [blame] | 347 | LOGP(DSS, LOGL_ERROR, "Missing mandatory Facility IE\n"); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 348 | return NULL; |
| 349 | } |
| 350 | |
Vadim Yanitskiy | 10c3ce5 | 2019-06-15 15:52:23 +0700 | [diff] [blame] | 351 | /* Obtain an unused transaction ID */ |
| 352 | tid = trans_assign_trans_id(net, vsub, TRANS_USSD); |
| 353 | if (tid < 0) { |
| 354 | LOGP(DSS, LOGL_ERROR, "No free transaction ID\n"); |
| 355 | return NULL; |
| 356 | } |
| 357 | |
| 358 | /* Allocate a new NCSS transaction */ |
| 359 | trans = trans_alloc(net, vsub, TRANS_USSD, tid, gsup_msg->session_id); |
| 360 | if (!trans) { |
| 361 | LOGP(DSS, LOGL_ERROR, " -> No memory for trans\n"); |
| 362 | return NULL; |
| 363 | } |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 364 | |
Vadim Yanitskiy | ad64e2a | 2018-06-26 18:27:25 +0700 | [diff] [blame] | 365 | /* Count active NC SS/USSD sessions */ |
Alexander Couzens | efa7b97 | 2019-04-27 23:45:37 +0200 | [diff] [blame] | 366 | osmo_stat_item_inc(net->statg->items[MSC_STAT_ACTIVE_NC_SS], 1); |
Vadim Yanitskiy | ad64e2a | 2018-06-26 18:27:25 +0700 | [diff] [blame] | 367 | |
Vadim Yanitskiy | 64623e1 | 2018-11-28 23:05:51 +0700 | [diff] [blame] | 368 | /* Init inactivity timer */ |
| 369 | osmo_timer_setup(&trans->ss.timer_guard, |
| 370 | ncss_session_timeout_handler, trans); |
| 371 | |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 372 | /* Attempt to find connection */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 373 | msc_a = msc_a_for_vsub(vsub, true); |
| 374 | if (msc_a) { |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 375 | /* Assign connection */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 376 | msc_a_get(msc_a, MSC_A_USE_NC_SS); |
| 377 | trans->msc_a = msc_a; |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 378 | trans->dlci = 0x00; /* SAPI=0, not SACCH */ |
| 379 | return trans; |
| 380 | } |
| 381 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 382 | LOG_TRANS(trans, LOGL_DEBUG, "Triggering Paging Request\n"); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 383 | |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 384 | /* Trigger Paging Request */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 385 | trans->paging_request = paging_request_start(vsub, PAGING_CAUSE_SIGNALLING_HIGH_PRIO, |
| 386 | ss_paging_cb, trans, "GSM 09.11 SS/USSD"); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 387 | if (!trans->paging_request) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 388 | LOG_TRANS(trans, LOGL_ERROR, "Failed to allocate paging token\n"); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 389 | trans_free(trans); |
| 390 | return NULL; |
| 391 | } |
| 392 | |
| 393 | /* Store the Facility IE to be sent */ |
| 394 | OSMO_ASSERT(trans->ss.msg == NULL); |
| 395 | trans->ss.msg = gsm48_msgb_alloc_name("GSM 04.08 SS/USSD"); |
| 396 | msgb_tlv_put(trans->ss.msg, GSM0480_IE_FACILITY, |
| 397 | gsup_msg->ss_info_len, gsup_msg->ss_info); |
| 398 | |
Vadim Yanitskiy | 04bbfb8 | 2019-06-15 15:15:55 +0700 | [diff] [blame] | 399 | return trans; |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | /* NC SS specific transaction release. |
| 403 | * Gets called by trans_free, DO NOT CALL YOURSELF! */ |
| 404 | void _gsm911_nc_ss_trans_free(struct gsm_trans *trans) |
| 405 | { |
| 406 | /** |
| 407 | * TODO: if transaction wasn't properly terminated, |
| 408 | * we need to do it here by releasing the subscriber |
| 409 | * connection and sending notification via GSUP... |
| 410 | */ |
| 411 | if (trans->ss.msg != NULL) |
| 412 | msgb_free(trans->ss.msg); |
Vadim Yanitskiy | ad64e2a | 2018-06-26 18:27:25 +0700 | [diff] [blame] | 413 | |
Vadim Yanitskiy | 64623e1 | 2018-11-28 23:05:51 +0700 | [diff] [blame] | 414 | /* Stop inactivity timer */ |
| 415 | osmo_timer_del(&trans->ss.timer_guard); |
| 416 | |
Vadim Yanitskiy | ad64e2a | 2018-06-26 18:27:25 +0700 | [diff] [blame] | 417 | /* One session less */ |
Alexander Couzens | efa7b97 | 2019-04-27 23:45:37 +0200 | [diff] [blame] | 418 | osmo_stat_item_dec(trans->net->statg->items[MSC_STAT_ACTIVE_NC_SS], 1); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 419 | } |
| 420 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 421 | int gsm0911_gsup_rx(struct gsup_client_mux *gcm, void *data, const struct osmo_gsup_message *gsup_msg) |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 422 | { |
Vadim Yanitskiy | 805eca2 | 2019-06-15 17:30:23 +0700 | [diff] [blame] | 423 | struct gsm_network *net = (struct gsm_network *) data; |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 424 | struct gsm_trans *trans; |
| 425 | struct gsm48_hdr *gh; |
| 426 | struct msgb *ss_msg; |
| 427 | bool trans_end; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 428 | struct msc_a *msc_a; |
Vadim Yanitskiy | e0da446 | 2019-06-17 21:51:12 +0700 | [diff] [blame] | 429 | struct vlr_subscr *vsub; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 430 | |
Vadim Yanitskiy | e0da446 | 2019-06-17 21:51:12 +0700 | [diff] [blame] | 431 | vsub = vlr_subscr_find_by_imsi(net->vlr, gsup_msg->imsi, __func__); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 432 | if (!vsub) { |
Vadim Yanitskiy | 3d60303 | 2019-06-15 00:54:30 +0700 | [diff] [blame] | 433 | LOGP(DSS, LOGL_ERROR, "Rx %s for unknown subscriber, rejecting\n", |
| 434 | osmo_gsup_message_type_name(gsup_msg->message_type)); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 435 | gsup_client_mux_tx_error_reply(gcm, gsup_msg, GMM_CAUSE_IMSI_UNKNOWN); |
| 436 | return -GMM_CAUSE_IMSI_UNKNOWN; |
| 437 | } |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 438 | |
| 439 | /* Associate logging messages with this subscriber */ |
| 440 | log_set_context(LOG_CTX_VLR_SUBSCR, vsub); |
| 441 | |
Vadim Yanitskiy | f177590 | 2019-06-16 15:34:28 +0700 | [diff] [blame] | 442 | /* Attempt to find DTAP-transaction */ |
| 443 | trans = trans_find_by_callref(net, gsup_msg->session_id); |
| 444 | |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 445 | /* Handle errors */ |
| 446 | if (OSMO_GSUP_IS_MSGT_ERROR(gsup_msg->message_type)) { |
Vadim Yanitskiy | f177590 | 2019-06-16 15:34:28 +0700 | [diff] [blame] | 447 | LOGP(DSS, LOGL_NOTICE, "Rx %s from HLR/EUSE (cause=0x%02x, sid=0x%x)\n", |
| 448 | osmo_gsup_message_type_name(gsup_msg->message_type), |
| 449 | gsup_msg->cause, gsup_msg->session_id); |
| 450 | |
Vadim Yanitskiy | e0da446 | 2019-06-17 21:51:12 +0700 | [diff] [blame] | 451 | /* We don't need subscriber info anymore */ |
| 452 | vlr_subscr_put(vsub, __func__); |
| 453 | |
Vadim Yanitskiy | f177590 | 2019-06-16 15:34:28 +0700 | [diff] [blame] | 454 | if (!trans) { |
| 455 | LOGP(DSS, LOGL_ERROR, "No transaction found for " |
| 456 | "sid=0x%x, nothing to abort\n", gsup_msg->session_id); |
| 457 | return -ENODEV; |
| 458 | } |
| 459 | |
| 460 | LOG_TRANS(trans, LOGL_NOTICE, "Aborting the session: sending RELEASE COMPLETE\n"); |
| 461 | |
| 462 | /* Indicate connection release to subscriber (if active) */ |
| 463 | if (trans->msc_a != NULL) { |
| 464 | /* TODO: implement GSUP - GSM 04.80 cause mapping */ |
| 465 | msc_send_ussd_release_complete_cause(trans->msc_a, trans->transaction_id, |
| 466 | GSM48_CAUSE_LOC_PUN_S_LU, GSM48_CC_CAUSE_TEMP_FAILURE); |
| 467 | } |
| 468 | |
| 469 | /* Terminate transaction */ |
| 470 | trans_free(trans); |
| 471 | |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 472 | return 0; |
Holger Hans Peter Freyther | 5085e0b | 2016-07-12 17:53:26 +0200 | [diff] [blame] | 473 | } |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 474 | |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 475 | if (!trans) { |
Vadim Yanitskiy | 8e25cc5 | 2018-06-23 03:32:20 +0700 | [diff] [blame] | 476 | /* Count network-initiated attempts to establish a NC SS/USSD session */ |
| 477 | rate_ctr_inc(&net->msc_ctrs->ctr[MSC_CTR_NC_SS_MT_REQUESTS]); |
| 478 | |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 479 | /* Attempt to establish a new transaction */ |
| 480 | trans = establish_nc_ss_trans(net, vsub, gsup_msg); |
| 481 | if (!trans) { |
Vadim Yanitskiy | db5bc70 | 2019-06-15 16:13:08 +0700 | [diff] [blame] | 482 | LOGP(DSS, LOGL_ERROR, "Failed to establish a network-originated " |
| 483 | "SS/USSD transaction, rejecting %s\n", |
| 484 | osmo_gsup_message_type_name(gsup_msg->message_type)); |
Vadim Yanitskiy | efb1f60 | 2019-06-15 14:44:46 +0700 | [diff] [blame] | 485 | gsup_client_mux_tx_error_reply(gcm, gsup_msg, GMM_CAUSE_NET_FAIL); |
Vadim Yanitskiy | e0da446 | 2019-06-17 21:51:12 +0700 | [diff] [blame] | 486 | vlr_subscr_put(vsub, __func__); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 487 | return -EINVAL; |
| 488 | } |
| 489 | |
| 490 | /* Wait for Paging Response */ |
Vadim Yanitskiy | e0da446 | 2019-06-17 21:51:12 +0700 | [diff] [blame] | 491 | if (trans->paging_request) { |
| 492 | vlr_subscr_put(vsub, __func__); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 493 | return 0; |
Vadim Yanitskiy | e0da446 | 2019-06-17 21:51:12 +0700 | [diff] [blame] | 494 | } |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 495 | } |
Holger Hans Peter Freyther | 2486663 | 2010-06-30 12:15:19 +0800 | [diff] [blame] | 496 | |
Vadim Yanitskiy | e0da446 | 2019-06-17 21:51:12 +0700 | [diff] [blame] | 497 | /* We don't need subscriber info anymore */ |
| 498 | vlr_subscr_put(vsub, __func__); |
| 499 | |
Vadim Yanitskiy | 64623e1 | 2018-11-28 23:05:51 +0700 | [diff] [blame] | 500 | /* (Re)schedule the inactivity timer */ |
| 501 | if (net->ncss_guard_timeout > 0) { |
| 502 | osmo_timer_schedule(&trans->ss.timer_guard, |
| 503 | net->ncss_guard_timeout, 0); |
| 504 | } |
| 505 | |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 506 | /* Allocate and prepare a new MT message */ |
| 507 | ss_msg = gsm48_msgb_alloc_name("GSM 04.08 SS/USSD"); |
| 508 | gh = (struct gsm48_hdr *) msgb_push(ss_msg, sizeof(*gh)); |
| 509 | gh->proto_discr = GSM48_PDISC_NC_SS; |
| 510 | gh->proto_discr |= trans->transaction_id << 4; |
Vadim Yanitskiy | 10c6419 | 2018-04-17 19:17:11 +0700 | [diff] [blame] | 511 | |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 512 | /** |
| 513 | * Perform GSUP-interface to A-interface mapping, |
| 514 | * according to GSM TS 09.11, table 4.1. |
| 515 | * |
| 516 | * TODO: see (note 3), both CONTINUE and END may |
| 517 | * be also mapped to REGISTER if a new transaction |
| 518 | * has to be established. |
| 519 | */ |
| 520 | switch (gsup_msg->session_state) { |
| 521 | case OSMO_GSUP_SESSION_STATE_BEGIN: |
| 522 | gh->msg_type = GSM0480_MTYPE_REGISTER; |
| 523 | break; |
| 524 | case OSMO_GSUP_SESSION_STATE_CONTINUE: |
| 525 | gh->msg_type = GSM0480_MTYPE_FACILITY; |
| 526 | break; |
| 527 | case OSMO_GSUP_SESSION_STATE_END: |
| 528 | gh->msg_type = GSM0480_MTYPE_RELEASE_COMPLETE; |
| 529 | break; |
| 530 | |
| 531 | /* Missing or incorrect session state */ |
| 532 | case OSMO_GSUP_SESSION_STATE_NONE: |
| 533 | default: |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 534 | LOG_TRANS(trans, LOGL_ERROR, "Unexpected session state %d\n", |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 535 | gsup_msg->session_state); |
Vadim Yanitskiy | efb1f60 | 2019-06-15 14:44:46 +0700 | [diff] [blame] | 536 | gsup_client_mux_tx_error_reply(gcm, gsup_msg, GMM_CAUSE_MSGT_INCOMP_P_STATE); |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 537 | msgb_free(ss_msg); |
| 538 | return -EINVAL; |
| 539 | } |
| 540 | |
| 541 | /* Facility IE is optional only for RELEASE COMPLETE */ |
| 542 | if (gh->msg_type != GSM0480_MTYPE_RELEASE_COMPLETE) { |
| 543 | if (!gsup_msg->ss_info || gsup_msg->ss_info_len < 2) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 544 | LOG_TRANS(trans, LOGL_ERROR, "Missing mandatory Facility IE " |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 545 | "for mapped 0x%02x message\n", gh->msg_type); |
Vadim Yanitskiy | efb1f60 | 2019-06-15 14:44:46 +0700 | [diff] [blame] | 546 | gsup_client_mux_tx_error_reply(gcm, gsup_msg, GMM_CAUSE_INV_MAND_INFO); |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 547 | msgb_free(ss_msg); |
| 548 | return -EINVAL; |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | /* Append Facility IE if preset */ |
| 553 | if (gsup_msg->ss_info && gsup_msg->ss_info_len > 2) { |
| 554 | /* Facility IE carries LV, others carry TLV */ |
| 555 | if (gh->msg_type == GSM0480_MTYPE_FACILITY) |
| 556 | msgb_lv_put(ss_msg, gsup_msg->ss_info_len, gsup_msg->ss_info); |
| 557 | else |
| 558 | msgb_tlv_put(ss_msg, GSM0480_IE_FACILITY, |
| 559 | gsup_msg->ss_info_len, gsup_msg->ss_info); |
| 560 | } |
| 561 | |
| 562 | /* Should we release the transaction? */ |
| 563 | trans_end = (gh->msg_type == GSM0480_MTYPE_RELEASE_COMPLETE); |
| 564 | |
| 565 | /* Sent to the MS, give ownership of ss_msg */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 566 | msc_a = trans->msc_a; |
| 567 | if (!msc_a) { |
| 568 | LOG_TRANS(trans, LOGL_ERROR, "Cannot send SS message, no local MSC-A role defined for subscriber\n"); |
Vadim Yanitskiy | efb1f60 | 2019-06-15 14:44:46 +0700 | [diff] [blame] | 569 | gsup_client_mux_tx_error_reply(gcm, gsup_msg, GMM_CAUSE_NET_FAIL); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 570 | msgb_free(ss_msg); |
| 571 | return -EINVAL; |
| 572 | } |
| 573 | msc_a_tx_dtap_to_i(msc_a, ss_msg); |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 574 | |
| 575 | /* Release transaction if required */ |
| 576 | if (trans_end) |
| 577 | trans_free(trans); |
| 578 | |
Vadim Yanitskiy | 8e25cc5 | 2018-06-23 03:32:20 +0700 | [diff] [blame] | 579 | /* Count established network-initiated NC SS/USSD sessions */ |
| 580 | if (gsup_msg->session_state == OSMO_GSUP_SESSION_STATE_BEGIN) |
| 581 | rate_ctr_inc(&net->msc_ctrs->ctr[MSC_CTR_NC_SS_MT_ESTABLISHED]); |
| 582 | |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 583 | return 0; |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 584 | } |