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> |
Alexander Couzens | eff28ab | 2024-09-12 00:55:25 +0200 | [diff] [blame^] | 46 | #include <osmocom/vlr/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 */ |
Pau Espin Pedrol | 2e21a68 | 2021-06-04 16:45:44 +0200 | [diff] [blame] | 128 | rate_ctr_inc(rate_ctr_group_get_ctr(net->msc_ctrs, 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); |
Andreas Eversberg | 5fb4a9e | 2024-09-27 11:22:48 +0200 | [diff] [blame] | 145 | /* Decrement use counter that has been incremented by CM Service Request (SS). |
| 146 | * If there is no other service request, the BSS connection will be released. */ |
| 147 | msc_a_put(msc_a, MSC_A_USE_CM_SERVICE_SS); |
Vadim Yanitskiy | 10c6419 | 2018-04-17 19:17:11 +0700 | [diff] [blame] | 148 | return -EINVAL; |
| 149 | } |
| 150 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 151 | trans = trans_alloc(net, vsub, TRANS_USSD, tid, new_callref++); |
Vadim Yanitskiy | 10c6419 | 2018-04-17 19:17:11 +0700 | [diff] [blame] | 152 | if (!trans) { |
Vadim Yanitskiy | 6632251 | 2019-06-17 22:12:54 +0700 | [diff] [blame] | 153 | LOGP(DSS, LOGL_ERROR, " -> No memory for trans\n"); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 154 | gsm48_tx_simple(msc_a, |
Vadim Yanitskiy | 9aec25e | 2018-06-12 06:26:28 +0700 | [diff] [blame] | 155 | GSM48_PDISC_NC_SS | (tid << 4), |
| 156 | GSM0480_MTYPE_RELEASE_COMPLETE); |
Andreas Eversberg | 5fb4a9e | 2024-09-27 11:22:48 +0200 | [diff] [blame] | 157 | /* Decrement use counter that has been incremented by CM Service Request (SS). |
| 158 | * If there is no other service request, the BSS connection will be released. */ |
| 159 | msc_a_put(msc_a, MSC_A_USE_CM_SERVICE_SS); |
Vadim Yanitskiy | 10c6419 | 2018-04-17 19:17:11 +0700 | [diff] [blame] | 160 | return -ENOMEM; |
| 161 | } |
| 162 | |
Vadim Yanitskiy | 64623e1 | 2018-11-28 23:05:51 +0700 | [diff] [blame] | 163 | /* Init inactivity timer */ |
| 164 | osmo_timer_setup(&trans->ss.timer_guard, |
| 165 | ncss_session_timeout_handler, trans); |
| 166 | |
Vadim Yanitskiy | ad64e2a | 2018-06-26 18:27:25 +0700 | [diff] [blame] | 167 | /* Count active NC SS/USSD sessions */ |
Pau Espin Pedrol | 2e21a68 | 2021-06-04 16:45:44 +0200 | [diff] [blame] | 168 | osmo_stat_item_inc(osmo_stat_item_group_get_item(net->statg, MSC_STAT_ACTIVE_NC_SS), 1); |
Vadim Yanitskiy | ad64e2a | 2018-06-26 18:27:25 +0700 | [diff] [blame] | 169 | |
Vadim Yanitskiy | 10c6419 | 2018-04-17 19:17:11 +0700 | [diff] [blame] | 170 | trans->dlci = OMSC_LINKID_CB(msg); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 171 | trans->msc_a = msc_a; |
| 172 | msc_a_get(msc_a, MSC_A_USE_NC_SS); |
| 173 | |
| 174 | osmo_fsm_inst_dispatch(msc_a->c.fi, MSC_A_EV_TRANSACTION_ACCEPTED, trans); |
| 175 | |
| 176 | /* An earlier CM Service Request for this SS message now has concluded */ |
| 177 | if (!osmo_use_count_by(&msc_a->use_count, MSC_A_USE_CM_SERVICE_SS)) |
| 178 | LOG_MSC_A(msc_a, LOGL_ERROR, |
| 179 | "Creating new MO SS transaction without prior CM Service Request\n"); |
| 180 | else |
| 181 | msc_a_put(msc_a, MSC_A_USE_CM_SERVICE_SS); |
Vadim Yanitskiy | 10c6419 | 2018-04-17 19:17:11 +0700 | [diff] [blame] | 182 | } |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 183 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 184 | LOG_TRANS(trans, LOGL_DEBUG, "Received SS/USSD msg %s\n", |
| 185 | gsm48_pdisc_msgtype_name(GSM48_PDISC_NC_SS, msg_type)); |
| 186 | |
Vadim Yanitskiy | 64623e1 | 2018-11-28 23:05:51 +0700 | [diff] [blame] | 187 | /* (Re)schedule the inactivity timer */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 188 | if (net->ncss_guard_timeout > 0) { |
| 189 | osmo_timer_schedule(&trans->ss.timer_guard, net->ncss_guard_timeout, 0); |
Vadim Yanitskiy | 64623e1 | 2018-11-28 23:05:51 +0700 | [diff] [blame] | 190 | } |
| 191 | |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 192 | /* Attempt to extract Facility IE */ |
| 193 | rc = gsm0480_extract_ie_by_tag(gh, msgb_l3len(msg), |
| 194 | &facility_ie, &facility_ie_len, GSM0480_IE_FACILITY); |
| 195 | if (rc) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 196 | 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] | 197 | goto error; |
Tobias Engel | ea73032 | 2013-12-28 17:03:14 +0100 | [diff] [blame] | 198 | } |
| 199 | |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 200 | /* Facility IE is optional for RELEASE COMPLETE */ |
| 201 | if (msg_type != GSM0480_MTYPE_RELEASE_COMPLETE) { |
| 202 | if (!facility_ie || facility_ie_len < 2) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 203 | LOG_TRANS(trans, LOGL_ERROR, "GSM 04.80 message parsing error," |
| 204 | " missing mandatory Facility IE\n"); |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 205 | rc = -EINVAL; |
| 206 | goto error; |
Holger Hans Peter Freyther | 5085e0b | 2016-07-12 17:53:26 +0200 | [diff] [blame] | 207 | } |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | /* Compose a mew GSUP message */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 211 | gsup_msg = (struct osmo_gsup_message){ |
| 212 | .message_type = OSMO_GSUP_MSGT_PROC_SS_REQUEST, |
| 213 | .session_id = trans->callref, |
| 214 | .message_class = OSMO_GSUP_MESSAGE_CLASS_USSD, |
| 215 | }; |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 216 | |
| 217 | /** |
| 218 | * Perform A-interface to GSUP-interface mapping, |
| 219 | * according to GSM TS 09.11, table 4.2. |
| 220 | */ |
| 221 | switch (msg_type) { |
| 222 | case GSM0480_MTYPE_REGISTER: |
| 223 | gsup_msg.session_state = OSMO_GSUP_SESSION_STATE_BEGIN; |
| 224 | break; |
| 225 | case GSM0480_MTYPE_FACILITY: |
| 226 | gsup_msg.session_state = OSMO_GSUP_SESSION_STATE_CONTINUE; |
| 227 | break; |
| 228 | case GSM0480_MTYPE_RELEASE_COMPLETE: |
| 229 | gsup_msg.session_state = OSMO_GSUP_SESSION_STATE_END; |
| 230 | break; |
| 231 | } |
| 232 | |
| 233 | /* Fill in the (optional) message payload */ |
| 234 | if (facility_ie) { |
| 235 | gsup_msg.ss_info_len = facility_ie_len; |
| 236 | gsup_msg.ss_info = facility_ie; |
| 237 | } |
| 238 | |
| 239 | /* Fill in subscriber's IMSI */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 240 | OSMO_STRLCPY_ARRAY(gsup_msg.imsi, vsub->imsi); |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 241 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 242 | rc = gsup_client_mux_tx(trans->net->gcm, &gsup_msg); |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 243 | |
Vadim Yanitskiy | fcc24ed | 2018-06-21 17:55:56 +0700 | [diff] [blame] | 244 | /* Should we release connection? Or wait for response? */ |
| 245 | if (msg_type == GSM0480_MTYPE_RELEASE_COMPLETE) |
| 246 | trans_free(trans); |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 247 | |
Vadim Yanitskiy | 8e25cc5 | 2018-06-23 03:32:20 +0700 | [diff] [blame] | 248 | /* Count established MS-initiated NC SS/USSD sessions */ |
| 249 | if (msg_type == GSM0480_MTYPE_REGISTER) |
Pau Espin Pedrol | 2e21a68 | 2021-06-04 16:45:44 +0200 | [diff] [blame] | 250 | rate_ctr_inc(rate_ctr_group_get_ctr(net->msc_ctrs, MSC_CTR_NC_SS_MO_ESTABLISHED)); |
Vadim Yanitskiy | 8e25cc5 | 2018-06-23 03:32:20 +0700 | [diff] [blame] | 251 | |
Vadim Yanitskiy | b3bdc76 | 2019-06-17 22:23:09 +0700 | [diff] [blame] | 252 | return rc; |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 253 | |
| 254 | error: |
| 255 | /* Abort transaction on DTAP-interface */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 256 | msc_send_ussd_reject(msc_a, tid, -1, |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 257 | GSM_0480_PROBLEM_CODE_TAG_GENERAL, |
| 258 | GSM_0480_GEN_PROB_CODE_UNRECOGNISED); |
| 259 | if (trans) |
| 260 | trans_free(trans); |
| 261 | |
| 262 | /* TODO: abort transaction on GSUP interface if any */ |
| 263 | return rc; |
| 264 | } |
| 265 | |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 266 | /* Call-back from paging the B-end of the connection */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 267 | 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] | 268 | { |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 269 | struct gsm48_hdr *gh; |
| 270 | struct msgb *ss_msg; |
| 271 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 272 | if (trans->msc_a) { |
| 273 | LOG_MSC_A_CAT(msc_a, DPAG, LOGL_ERROR, |
Martin Hauke | 3f07dac | 2019-11-14 17:49:08 +0100 | [diff] [blame] | 274 | "Handle paging error: transaction already associated with subscriber," |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 275 | " apparently it was already handled. Skip.\n"); |
| 276 | return; |
| 277 | } |
| 278 | OSMO_ASSERT(trans->ss.msg); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 279 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 280 | if (msc_a) { |
| 281 | struct gsm_network *net = msc_a_net(msc_a); |
Neels Hofmeyr | 979b057 | 2019-05-09 15:24:49 +0200 | [diff] [blame] | 282 | LOG_MSC_A_CAT(msc_a, DSS, LOGL_DEBUG, "Paging succeeded\n"); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 283 | |
| 284 | /* Assign connection */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 285 | msc_a_get(msc_a, MSC_A_USE_NC_SS); |
| 286 | trans->msc_a = msc_a; |
| 287 | trans->paging_request = NULL; |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 288 | |
Vadim Yanitskiy | 64623e1 | 2018-11-28 23:05:51 +0700 | [diff] [blame] | 289 | /* (Re)schedule the inactivity timer */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 290 | if (net->ncss_guard_timeout > 0) { |
| 291 | osmo_timer_schedule(&trans->ss.timer_guard, net->ncss_guard_timeout, 0); |
Vadim Yanitskiy | 64623e1 | 2018-11-28 23:05:51 +0700 | [diff] [blame] | 292 | } |
| 293 | |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 294 | /* Send stored message */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 295 | ss_msg = trans->ss.msg; |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 296 | gh = (struct gsm48_hdr *) msgb_push(ss_msg, sizeof(*gh)); |
| 297 | gh->proto_discr = GSM48_PDISC_NC_SS; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 298 | gh->proto_discr |= trans->transaction_id << 4; |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 299 | gh->msg_type = GSM0480_MTYPE_REGISTER; |
| 300 | |
| 301 | /* Sent to the MS, give ownership of ss_msg */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 302 | msc_a_tx_dtap_to_i(msc_a, ss_msg); |
| 303 | trans->ss.msg = NULL; |
Vadim Yanitskiy | 8e25cc5 | 2018-06-23 03:32:20 +0700 | [diff] [blame] | 304 | |
| 305 | /* Count established network-initiated NC SS/USSD sessions */ |
Pau Espin Pedrol | 2e21a68 | 2021-06-04 16:45:44 +0200 | [diff] [blame] | 306 | rate_ctr_inc(rate_ctr_group_get_ctr(net->msc_ctrs, MSC_CTR_NC_SS_MT_ESTABLISHED)); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 307 | } else { |
Vadim Yanitskiy | 7480852 | 2019-06-16 02:35:28 +0700 | [diff] [blame] | 308 | struct osmo_gsup_message gsup_msg; |
| 309 | |
Neels Hofmeyr | 979b057 | 2019-05-09 15:24:49 +0200 | [diff] [blame] | 310 | LOG_MSC_A_CAT(msc_a, DSS, LOGL_DEBUG, "Paging expired\n"); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 311 | |
Vadim Yanitskiy | 7480852 | 2019-06-16 02:35:28 +0700 | [diff] [blame] | 312 | gsup_msg = (struct osmo_gsup_message){ |
| 313 | .message_class = OSMO_GSUP_MESSAGE_CLASS_USSD, |
| 314 | .message_type = OSMO_GSUP_MSGT_PROC_SS_ERROR, |
| 315 | |
| 316 | .session_state = OSMO_GSUP_SESSION_STATE_END, |
| 317 | .session_id = trans->callref, |
| 318 | /* FIXME: we need message class specific cause values */ |
| 319 | .cause = GMM_CAUSE_IMPL_DETACHED, |
| 320 | }; |
| 321 | |
| 322 | /* Fill in subscriber's IMSI */ |
| 323 | OSMO_STRLCPY_ARRAY(gsup_msg.imsi, trans->vsub->imsi); |
| 324 | |
| 325 | /* Inform HLR/EUSE about the failure */ |
| 326 | gsup_client_mux_tx(trans->net->gcm, &gsup_msg); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 327 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 328 | msgb_free(trans->ss.msg); |
| 329 | trans->ss.msg = NULL; |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 330 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 331 | trans->callref = 0; |
| 332 | trans->paging_request = NULL; |
| 333 | trans_free(trans); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 334 | } |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | static struct gsm_trans *establish_nc_ss_trans(struct gsm_network *net, |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 338 | struct vlr_subscr *vsub, const struct osmo_gsup_message *gsup_msg) |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 339 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 340 | struct msc_a *msc_a; |
Vadim Yanitskiy | 95b040c | 2019-06-15 16:56:20 +0700 | [diff] [blame] | 341 | struct gsm_trans *trans; |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 342 | int tid; |
| 343 | |
| 344 | if (gsup_msg->session_state != OSMO_GSUP_SESSION_STATE_BEGIN) { |
Vadim Yanitskiy | 10c3ce5 | 2019-06-15 15:52:23 +0700 | [diff] [blame] | 345 | 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] | 346 | return NULL; |
| 347 | } |
| 348 | |
Vadim Yanitskiy | 10c3ce5 | 2019-06-15 15:52:23 +0700 | [diff] [blame] | 349 | LOGP(DSS, LOGL_DEBUG, "(%s) Establishing a network-originated session (id=0x%x)\n", |
| 350 | vlr_subscr_name(vsub), gsup_msg->session_id); |
| 351 | |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 352 | if (!gsup_msg->ss_info || gsup_msg->ss_info_len < 2) { |
Vadim Yanitskiy | 10c3ce5 | 2019-06-15 15:52:23 +0700 | [diff] [blame] | 353 | LOGP(DSS, LOGL_ERROR, "Missing mandatory Facility IE\n"); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 354 | return NULL; |
| 355 | } |
| 356 | |
Vadim Yanitskiy | 10c3ce5 | 2019-06-15 15:52:23 +0700 | [diff] [blame] | 357 | /* Obtain an unused transaction ID */ |
| 358 | tid = trans_assign_trans_id(net, vsub, TRANS_USSD); |
| 359 | if (tid < 0) { |
| 360 | LOGP(DSS, LOGL_ERROR, "No free transaction ID\n"); |
| 361 | return NULL; |
| 362 | } |
| 363 | |
| 364 | /* Allocate a new NCSS transaction */ |
| 365 | trans = trans_alloc(net, vsub, TRANS_USSD, tid, gsup_msg->session_id); |
| 366 | if (!trans) { |
| 367 | LOGP(DSS, LOGL_ERROR, " -> No memory for trans\n"); |
| 368 | return NULL; |
| 369 | } |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 370 | |
Vadim Yanitskiy | ad64e2a | 2018-06-26 18:27:25 +0700 | [diff] [blame] | 371 | /* Count active NC SS/USSD sessions */ |
Pau Espin Pedrol | 2e21a68 | 2021-06-04 16:45:44 +0200 | [diff] [blame] | 372 | osmo_stat_item_inc(osmo_stat_item_group_get_item(net->statg, MSC_STAT_ACTIVE_NC_SS), 1); |
Vadim Yanitskiy | ad64e2a | 2018-06-26 18:27:25 +0700 | [diff] [blame] | 373 | |
Vadim Yanitskiy | 64623e1 | 2018-11-28 23:05:51 +0700 | [diff] [blame] | 374 | /* Init inactivity timer */ |
| 375 | osmo_timer_setup(&trans->ss.timer_guard, |
| 376 | ncss_session_timeout_handler, trans); |
| 377 | |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 378 | /* Attempt to find connection */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 379 | msc_a = msc_a_for_vsub(vsub, true); |
| 380 | if (msc_a) { |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 381 | /* Assign connection */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 382 | msc_a_get(msc_a, MSC_A_USE_NC_SS); |
| 383 | trans->msc_a = msc_a; |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 384 | trans->dlci = 0x00; /* SAPI=0, not SACCH */ |
| 385 | return trans; |
| 386 | } |
| 387 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 388 | LOG_TRANS(trans, LOGL_DEBUG, "Triggering Paging Request\n"); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 389 | |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 390 | /* Trigger Paging Request */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 391 | trans->paging_request = paging_request_start(vsub, PAGING_CAUSE_SIGNALLING_HIGH_PRIO, |
| 392 | ss_paging_cb, trans, "GSM 09.11 SS/USSD"); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 393 | if (!trans->paging_request) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 394 | LOG_TRANS(trans, LOGL_ERROR, "Failed to allocate paging token\n"); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 395 | trans_free(trans); |
| 396 | return NULL; |
| 397 | } |
| 398 | |
| 399 | /* Store the Facility IE to be sent */ |
| 400 | OSMO_ASSERT(trans->ss.msg == NULL); |
| 401 | trans->ss.msg = gsm48_msgb_alloc_name("GSM 04.08 SS/USSD"); |
| 402 | msgb_tlv_put(trans->ss.msg, GSM0480_IE_FACILITY, |
| 403 | gsup_msg->ss_info_len, gsup_msg->ss_info); |
| 404 | |
Vadim Yanitskiy | 04bbfb8 | 2019-06-15 15:15:55 +0700 | [diff] [blame] | 405 | return trans; |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | /* NC SS specific transaction release. |
| 409 | * Gets called by trans_free, DO NOT CALL YOURSELF! */ |
| 410 | void _gsm911_nc_ss_trans_free(struct gsm_trans *trans) |
| 411 | { |
| 412 | /** |
| 413 | * TODO: if transaction wasn't properly terminated, |
| 414 | * we need to do it here by releasing the subscriber |
| 415 | * connection and sending notification via GSUP... |
| 416 | */ |
| 417 | if (trans->ss.msg != NULL) |
| 418 | msgb_free(trans->ss.msg); |
Vadim Yanitskiy | ad64e2a | 2018-06-26 18:27:25 +0700 | [diff] [blame] | 419 | |
Vadim Yanitskiy | 64623e1 | 2018-11-28 23:05:51 +0700 | [diff] [blame] | 420 | /* Stop inactivity timer */ |
| 421 | osmo_timer_del(&trans->ss.timer_guard); |
| 422 | |
Vadim Yanitskiy | ad64e2a | 2018-06-26 18:27:25 +0700 | [diff] [blame] | 423 | /* One session less */ |
Pau Espin Pedrol | 2e21a68 | 2021-06-04 16:45:44 +0200 | [diff] [blame] | 424 | osmo_stat_item_dec(osmo_stat_item_group_get_item(trans->net->statg, MSC_STAT_ACTIVE_NC_SS), |
| 425 | 1); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 426 | } |
| 427 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 428 | 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] | 429 | { |
Vadim Yanitskiy | 805eca2 | 2019-06-15 17:30:23 +0700 | [diff] [blame] | 430 | struct gsm_network *net = (struct gsm_network *) data; |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 431 | struct gsm_trans *trans; |
| 432 | struct gsm48_hdr *gh; |
| 433 | struct msgb *ss_msg; |
| 434 | bool trans_end; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 435 | struct msc_a *msc_a; |
Vadim Yanitskiy | e0da446 | 2019-06-17 21:51:12 +0700 | [diff] [blame] | 436 | struct vlr_subscr *vsub; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 437 | |
Vadim Yanitskiy | e0da446 | 2019-06-17 21:51:12 +0700 | [diff] [blame] | 438 | vsub = vlr_subscr_find_by_imsi(net->vlr, gsup_msg->imsi, __func__); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 439 | if (!vsub) { |
Vadim Yanitskiy | 3d60303 | 2019-06-15 00:54:30 +0700 | [diff] [blame] | 440 | LOGP(DSS, LOGL_ERROR, "Rx %s for unknown subscriber, rejecting\n", |
| 441 | osmo_gsup_message_type_name(gsup_msg->message_type)); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 442 | gsup_client_mux_tx_error_reply(gcm, gsup_msg, GMM_CAUSE_IMSI_UNKNOWN); |
| 443 | return -GMM_CAUSE_IMSI_UNKNOWN; |
| 444 | } |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 445 | |
| 446 | /* Associate logging messages with this subscriber */ |
| 447 | log_set_context(LOG_CTX_VLR_SUBSCR, vsub); |
| 448 | |
Vadim Yanitskiy | f177590 | 2019-06-16 15:34:28 +0700 | [diff] [blame] | 449 | /* Attempt to find DTAP-transaction */ |
Andreas Eversberg | 7e4b032 | 2023-04-23 11:43:13 +0200 | [diff] [blame] | 450 | trans = trans_find_by_callref(net, TRANS_USSD, gsup_msg->session_id); |
Vadim Yanitskiy | f177590 | 2019-06-16 15:34:28 +0700 | [diff] [blame] | 451 | |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 452 | /* Handle errors */ |
| 453 | if (OSMO_GSUP_IS_MSGT_ERROR(gsup_msg->message_type)) { |
Vadim Yanitskiy | f177590 | 2019-06-16 15:34:28 +0700 | [diff] [blame] | 454 | LOGP(DSS, LOGL_NOTICE, "Rx %s from HLR/EUSE (cause=0x%02x, sid=0x%x)\n", |
| 455 | osmo_gsup_message_type_name(gsup_msg->message_type), |
| 456 | gsup_msg->cause, gsup_msg->session_id); |
| 457 | |
Vadim Yanitskiy | e0da446 | 2019-06-17 21:51:12 +0700 | [diff] [blame] | 458 | /* We don't need subscriber info anymore */ |
| 459 | vlr_subscr_put(vsub, __func__); |
| 460 | |
Vadim Yanitskiy | f177590 | 2019-06-16 15:34:28 +0700 | [diff] [blame] | 461 | if (!trans) { |
| 462 | LOGP(DSS, LOGL_ERROR, "No transaction found for " |
| 463 | "sid=0x%x, nothing to abort\n", gsup_msg->session_id); |
| 464 | return -ENODEV; |
| 465 | } |
| 466 | |
| 467 | LOG_TRANS(trans, LOGL_NOTICE, "Aborting the session: sending RELEASE COMPLETE\n"); |
| 468 | |
| 469 | /* Indicate connection release to subscriber (if active) */ |
| 470 | if (trans->msc_a != NULL) { |
| 471 | /* TODO: implement GSUP - GSM 04.80 cause mapping */ |
| 472 | msc_send_ussd_release_complete_cause(trans->msc_a, trans->transaction_id, |
| 473 | GSM48_CAUSE_LOC_PUN_S_LU, GSM48_CC_CAUSE_TEMP_FAILURE); |
| 474 | } |
| 475 | |
| 476 | /* Terminate transaction */ |
| 477 | trans_free(trans); |
| 478 | |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 479 | return 0; |
Holger Hans Peter Freyther | 5085e0b | 2016-07-12 17:53:26 +0200 | [diff] [blame] | 480 | } |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 481 | |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 482 | if (!trans) { |
Vadim Yanitskiy | 8e25cc5 | 2018-06-23 03:32:20 +0700 | [diff] [blame] | 483 | /* Count network-initiated attempts to establish a NC SS/USSD session */ |
Pau Espin Pedrol | 2e21a68 | 2021-06-04 16:45:44 +0200 | [diff] [blame] | 484 | rate_ctr_inc(rate_ctr_group_get_ctr(net->msc_ctrs, MSC_CTR_NC_SS_MT_REQUESTS)); |
Vadim Yanitskiy | 8e25cc5 | 2018-06-23 03:32:20 +0700 | [diff] [blame] | 485 | |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 486 | /* Attempt to establish a new transaction */ |
| 487 | trans = establish_nc_ss_trans(net, vsub, gsup_msg); |
| 488 | if (!trans) { |
Vadim Yanitskiy | db5bc70 | 2019-06-15 16:13:08 +0700 | [diff] [blame] | 489 | LOGP(DSS, LOGL_ERROR, "Failed to establish a network-originated " |
| 490 | "SS/USSD transaction, rejecting %s\n", |
| 491 | osmo_gsup_message_type_name(gsup_msg->message_type)); |
Vadim Yanitskiy | efb1f60 | 2019-06-15 14:44:46 +0700 | [diff] [blame] | 492 | 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] | 493 | vlr_subscr_put(vsub, __func__); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 494 | return -EINVAL; |
| 495 | } |
| 496 | |
| 497 | /* Wait for Paging Response */ |
Vadim Yanitskiy | e0da446 | 2019-06-17 21:51:12 +0700 | [diff] [blame] | 498 | if (trans->paging_request) { |
| 499 | vlr_subscr_put(vsub, __func__); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 500 | return 0; |
Vadim Yanitskiy | e0da446 | 2019-06-17 21:51:12 +0700 | [diff] [blame] | 501 | } |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 502 | } |
Holger Hans Peter Freyther | 2486663 | 2010-06-30 12:15:19 +0800 | [diff] [blame] | 503 | |
Vadim Yanitskiy | e0da446 | 2019-06-17 21:51:12 +0700 | [diff] [blame] | 504 | /* We don't need subscriber info anymore */ |
| 505 | vlr_subscr_put(vsub, __func__); |
| 506 | |
Vadim Yanitskiy | 64623e1 | 2018-11-28 23:05:51 +0700 | [diff] [blame] | 507 | /* (Re)schedule the inactivity timer */ |
| 508 | if (net->ncss_guard_timeout > 0) { |
| 509 | osmo_timer_schedule(&trans->ss.timer_guard, |
| 510 | net->ncss_guard_timeout, 0); |
| 511 | } |
| 512 | |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 513 | /* Allocate and prepare a new MT message */ |
| 514 | ss_msg = gsm48_msgb_alloc_name("GSM 04.08 SS/USSD"); |
| 515 | gh = (struct gsm48_hdr *) msgb_push(ss_msg, sizeof(*gh)); |
| 516 | gh->proto_discr = GSM48_PDISC_NC_SS; |
| 517 | gh->proto_discr |= trans->transaction_id << 4; |
Vadim Yanitskiy | 10c6419 | 2018-04-17 19:17:11 +0700 | [diff] [blame] | 518 | |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 519 | /** |
| 520 | * Perform GSUP-interface to A-interface mapping, |
| 521 | * according to GSM TS 09.11, table 4.1. |
| 522 | * |
| 523 | * TODO: see (note 3), both CONTINUE and END may |
| 524 | * be also mapped to REGISTER if a new transaction |
| 525 | * has to be established. |
| 526 | */ |
| 527 | switch (gsup_msg->session_state) { |
| 528 | case OSMO_GSUP_SESSION_STATE_BEGIN: |
| 529 | gh->msg_type = GSM0480_MTYPE_REGISTER; |
| 530 | break; |
| 531 | case OSMO_GSUP_SESSION_STATE_CONTINUE: |
| 532 | gh->msg_type = GSM0480_MTYPE_FACILITY; |
| 533 | break; |
| 534 | case OSMO_GSUP_SESSION_STATE_END: |
| 535 | gh->msg_type = GSM0480_MTYPE_RELEASE_COMPLETE; |
| 536 | break; |
| 537 | |
| 538 | /* Missing or incorrect session state */ |
| 539 | case OSMO_GSUP_SESSION_STATE_NONE: |
| 540 | default: |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 541 | LOG_TRANS(trans, LOGL_ERROR, "Unexpected session state %d\n", |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 542 | gsup_msg->session_state); |
Vadim Yanitskiy | efb1f60 | 2019-06-15 14:44:46 +0700 | [diff] [blame] | 543 | 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] | 544 | msgb_free(ss_msg); |
| 545 | return -EINVAL; |
| 546 | } |
| 547 | |
| 548 | /* Facility IE is optional only for RELEASE COMPLETE */ |
| 549 | if (gh->msg_type != GSM0480_MTYPE_RELEASE_COMPLETE) { |
| 550 | if (!gsup_msg->ss_info || gsup_msg->ss_info_len < 2) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 551 | LOG_TRANS(trans, LOGL_ERROR, "Missing mandatory Facility IE " |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 552 | "for mapped 0x%02x message\n", gh->msg_type); |
Vadim Yanitskiy | efb1f60 | 2019-06-15 14:44:46 +0700 | [diff] [blame] | 553 | 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] | 554 | msgb_free(ss_msg); |
| 555 | return -EINVAL; |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | /* Append Facility IE if preset */ |
| 560 | if (gsup_msg->ss_info && gsup_msg->ss_info_len > 2) { |
| 561 | /* Facility IE carries LV, others carry TLV */ |
| 562 | if (gh->msg_type == GSM0480_MTYPE_FACILITY) |
| 563 | msgb_lv_put(ss_msg, gsup_msg->ss_info_len, gsup_msg->ss_info); |
| 564 | else |
| 565 | msgb_tlv_put(ss_msg, GSM0480_IE_FACILITY, |
| 566 | gsup_msg->ss_info_len, gsup_msg->ss_info); |
| 567 | } |
| 568 | |
| 569 | /* Should we release the transaction? */ |
| 570 | trans_end = (gh->msg_type == GSM0480_MTYPE_RELEASE_COMPLETE); |
| 571 | |
| 572 | /* Sent to the MS, give ownership of ss_msg */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 573 | msc_a = trans->msc_a; |
| 574 | if (!msc_a) { |
| 575 | 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] | 576 | 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] | 577 | msgb_free(ss_msg); |
| 578 | return -EINVAL; |
| 579 | } |
| 580 | msc_a_tx_dtap_to_i(msc_a, ss_msg); |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 581 | |
| 582 | /* Release transaction if required */ |
| 583 | if (trans_end) |
| 584 | trans_free(trans); |
| 585 | |
Vadim Yanitskiy | 8e25cc5 | 2018-06-23 03:32:20 +0700 | [diff] [blame] | 586 | /* Count established network-initiated NC SS/USSD sessions */ |
| 587 | if (gsup_msg->session_state == OSMO_GSUP_SESSION_STATE_BEGIN) |
Pau Espin Pedrol | 2e21a68 | 2021-06-04 16:45:44 +0200 | [diff] [blame] | 588 | rate_ctr_inc(rate_ctr_group_get_ctr(net->msc_ctrs, MSC_CTR_NC_SS_MT_ESTABLISHED)); |
Vadim Yanitskiy | 8e25cc5 | 2018-06-23 03:32:20 +0700 | [diff] [blame] | 589 | |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 590 | return 0; |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 591 | } |