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