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 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 320 | /* Allocate transaction first, for log context */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 321 | trans = trans_alloc(net, vsub, TRANS_USSD, |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 322 | TRANS_ID_UNASSIGNED, gsup_msg->session_id); |
| 323 | |
| 324 | if (!trans) { |
| 325 | LOG_TRANS(trans, LOGL_ERROR, " -> No memory for trans\n"); |
| 326 | return NULL; |
| 327 | } |
| 328 | |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 329 | if (gsup_msg->session_state != OSMO_GSUP_SESSION_STATE_BEGIN) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 330 | LOG_TRANS(trans, LOGL_ERROR, "Received non-BEGIN message " |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 331 | "for non-existing transaction\n"); |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 332 | trans_free(trans); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 333 | return NULL; |
| 334 | } |
| 335 | |
| 336 | if (!gsup_msg->ss_info || gsup_msg->ss_info_len < 2) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 337 | LOG_TRANS(trans, LOGL_ERROR, "Missing mandatory Facility IE\n"); |
| 338 | trans_free(trans); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 339 | return NULL; |
| 340 | } |
| 341 | |
| 342 | /* If subscriber is not "attached" */ |
Max | 7d41d87 | 2018-12-19 11:48:33 +0100 | [diff] [blame] | 343 | if (!vsub->cgi.lai.lac) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 344 | LOG_TRANS(trans, LOGL_ERROR, "Network-originated session " |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 345 | "rejected - subscriber is not attached\n"); |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 346 | trans_free(trans); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 347 | return NULL; |
| 348 | } |
| 349 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 350 | LOG_TRANS(trans, LOGL_DEBUG, "Establishing network-originated session\n"); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 351 | |
Vadim Yanitskiy | ad64e2a | 2018-06-26 18:27:25 +0700 | [diff] [blame] | 352 | /* Count active NC SS/USSD sessions */ |
| 353 | osmo_counter_inc(net->active_nc_ss); |
| 354 | |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 355 | /* Assign transaction ID */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 356 | tid = trans_assign_trans_id(trans->net, trans->vsub, TRANS_USSD); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 357 | if (tid < 0) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 358 | LOG_TRANS(trans, LOGL_ERROR, "No free transaction ID\n"); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 359 | /* TODO: inform HLR about this */ |
| 360 | /* TODO: release connection with subscriber */ |
| 361 | trans->callref = 0; |
| 362 | trans_free(trans); |
| 363 | return NULL; |
| 364 | } |
| 365 | trans->transaction_id = tid; |
| 366 | |
Vadim Yanitskiy | 64623e1 | 2018-11-28 23:05:51 +0700 | [diff] [blame] | 367 | /* Init inactivity timer */ |
| 368 | osmo_timer_setup(&trans->ss.timer_guard, |
| 369 | ncss_session_timeout_handler, trans); |
| 370 | |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 371 | /* Attempt to find connection */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 372 | msc_a = msc_a_for_vsub(vsub, true); |
| 373 | if (msc_a) { |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 374 | /* Assign connection */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 375 | msc_a_get(msc_a, MSC_A_USE_NC_SS); |
| 376 | trans->msc_a = msc_a; |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 377 | trans->dlci = 0x00; /* SAPI=0, not SACCH */ |
| 378 | return trans; |
| 379 | } |
| 380 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 381 | LOG_TRANS(trans, LOGL_DEBUG, "Triggering Paging Request\n"); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 382 | |
| 383 | /* Find transaction with this subscriber already paging */ |
| 384 | llist_for_each_entry(transt, &net->trans_list, entry) { |
| 385 | /* Transaction of our conn? */ |
| 386 | if (transt == trans || transt->vsub != vsub) |
| 387 | continue; |
| 388 | |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 389 | LOG_TRANS(trans, LOGL_ERROR, "Paging already started, " |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 390 | "rejecting message...\n"); |
| 391 | trans_free(trans); |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 392 | /* FIXME: WTF IS THIS!? This is completely insane. Presence of a trans doesn't indicate Paging, and even |
| 393 | * if, why drop the current request??? */ |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 394 | return NULL; |
| 395 | } |
| 396 | |
| 397 | /* Trigger Paging Request */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 398 | trans->paging_request = paging_request_start(vsub, PAGING_CAUSE_SIGNALLING_HIGH_PRIO, |
| 399 | ss_paging_cb, trans, "GSM 09.11 SS/USSD"); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 400 | if (!trans->paging_request) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 401 | LOG_TRANS(trans, LOGL_ERROR, "Failed to allocate paging token\n"); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 402 | trans_free(trans); |
| 403 | return NULL; |
| 404 | } |
| 405 | |
| 406 | /* Store the Facility IE to be sent */ |
| 407 | OSMO_ASSERT(trans->ss.msg == NULL); |
| 408 | trans->ss.msg = gsm48_msgb_alloc_name("GSM 04.08 SS/USSD"); |
| 409 | msgb_tlv_put(trans->ss.msg, GSM0480_IE_FACILITY, |
| 410 | gsup_msg->ss_info_len, gsup_msg->ss_info); |
| 411 | |
| 412 | return NULL; |
| 413 | } |
| 414 | |
| 415 | /* NC SS specific transaction release. |
| 416 | * Gets called by trans_free, DO NOT CALL YOURSELF! */ |
| 417 | void _gsm911_nc_ss_trans_free(struct gsm_trans *trans) |
| 418 | { |
| 419 | /** |
| 420 | * TODO: if transaction wasn't properly terminated, |
| 421 | * we need to do it here by releasing the subscriber |
| 422 | * connection and sending notification via GSUP... |
| 423 | */ |
| 424 | if (trans->ss.msg != NULL) |
| 425 | msgb_free(trans->ss.msg); |
Vadim Yanitskiy | ad64e2a | 2018-06-26 18:27:25 +0700 | [diff] [blame] | 426 | |
Vadim Yanitskiy | 64623e1 | 2018-11-28 23:05:51 +0700 | [diff] [blame] | 427 | /* Stop inactivity timer */ |
| 428 | osmo_timer_del(&trans->ss.timer_guard); |
| 429 | |
Vadim Yanitskiy | ad64e2a | 2018-06-26 18:27:25 +0700 | [diff] [blame] | 430 | /* One session less */ |
| 431 | osmo_counter_dec(trans->net->active_nc_ss); |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 432 | } |
| 433 | |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 434 | 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] | 435 | { |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 436 | struct vlr_instance *vlr = data; |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 437 | struct gsm_network *net; |
| 438 | struct gsm_trans *trans; |
| 439 | struct gsm48_hdr *gh; |
| 440 | struct msgb *ss_msg; |
| 441 | bool trans_end; |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 442 | struct msc_a *msc_a; |
| 443 | struct vlr_subscr *vsub = vlr_subscr_find_by_imsi(vlr, gsup_msg->imsi, __func__); |
| 444 | |
| 445 | if (!vsub) { |
| 446 | gsup_client_mux_tx_error_reply(gcm, gsup_msg, GMM_CAUSE_IMSI_UNKNOWN); |
| 447 | return -GMM_CAUSE_IMSI_UNKNOWN; |
| 448 | } |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 449 | |
| 450 | /* Associate logging messages with this subscriber */ |
| 451 | log_set_context(LOG_CTX_VLR_SUBSCR, vsub); |
| 452 | |
| 453 | /* Obtain pointer to vlr_instance */ |
| 454 | vlr = vsub->vlr; |
| 455 | OSMO_ASSERT(vlr); |
| 456 | |
| 457 | /* Obtain pointer to gsm_network */ |
| 458 | net = (struct gsm_network *) vlr->user_ctx; |
| 459 | OSMO_ASSERT(net); |
| 460 | |
| 461 | /* Handle errors */ |
| 462 | if (OSMO_GSUP_IS_MSGT_ERROR(gsup_msg->message_type)) { |
| 463 | /* FIXME: handle this error somehow! */ |
Harald Welte | 6307b85 | 2009-10-16 08:41:51 +0200 | [diff] [blame] | 464 | return 0; |
Holger Hans Peter Freyther | 5085e0b | 2016-07-12 17:53:26 +0200 | [diff] [blame] | 465 | } |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 466 | |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 467 | /* Attempt to find DTAP-transaction */ |
| 468 | trans = trans_find_by_callref(net, gsup_msg->session_id); |
| 469 | if (!trans) { |
Vadim Yanitskiy | 8e25cc5 | 2018-06-23 03:32:20 +0700 | [diff] [blame] | 470 | /* Count network-initiated attempts to establish a NC SS/USSD session */ |
| 471 | rate_ctr_inc(&net->msc_ctrs->ctr[MSC_CTR_NC_SS_MT_REQUESTS]); |
| 472 | |
Vadim Yanitskiy | f2f83b0 | 2018-06-17 21:09:28 +0700 | [diff] [blame] | 473 | /* Attempt to establish a new transaction */ |
| 474 | trans = establish_nc_ss_trans(net, vsub, gsup_msg); |
| 475 | if (!trans) { |
| 476 | /* FIXME: send ERROR back to the HLR */ |
| 477 | return -EINVAL; |
| 478 | } |
| 479 | |
| 480 | /* Wait for Paging Response */ |
| 481 | if (trans->paging_request) |
| 482 | return 0; |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 483 | } |
Holger Hans Peter Freyther | 2486663 | 2010-06-30 12:15:19 +0800 | [diff] [blame] | 484 | |
Vadim Yanitskiy | 64623e1 | 2018-11-28 23:05:51 +0700 | [diff] [blame] | 485 | /* (Re)schedule the inactivity timer */ |
| 486 | if (net->ncss_guard_timeout > 0) { |
| 487 | osmo_timer_schedule(&trans->ss.timer_guard, |
| 488 | net->ncss_guard_timeout, 0); |
| 489 | } |
| 490 | |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 491 | /* Allocate and prepare a new MT message */ |
| 492 | ss_msg = gsm48_msgb_alloc_name("GSM 04.08 SS/USSD"); |
| 493 | gh = (struct gsm48_hdr *) msgb_push(ss_msg, sizeof(*gh)); |
| 494 | gh->proto_discr = GSM48_PDISC_NC_SS; |
| 495 | gh->proto_discr |= trans->transaction_id << 4; |
Vadim Yanitskiy | 10c6419 | 2018-04-17 19:17:11 +0700 | [diff] [blame] | 496 | |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 497 | /** |
| 498 | * Perform GSUP-interface to A-interface mapping, |
| 499 | * according to GSM TS 09.11, table 4.1. |
| 500 | * |
| 501 | * TODO: see (note 3), both CONTINUE and END may |
| 502 | * be also mapped to REGISTER if a new transaction |
| 503 | * has to be established. |
| 504 | */ |
| 505 | switch (gsup_msg->session_state) { |
| 506 | case OSMO_GSUP_SESSION_STATE_BEGIN: |
| 507 | gh->msg_type = GSM0480_MTYPE_REGISTER; |
| 508 | break; |
| 509 | case OSMO_GSUP_SESSION_STATE_CONTINUE: |
| 510 | gh->msg_type = GSM0480_MTYPE_FACILITY; |
| 511 | break; |
| 512 | case OSMO_GSUP_SESSION_STATE_END: |
| 513 | gh->msg_type = GSM0480_MTYPE_RELEASE_COMPLETE; |
| 514 | break; |
| 515 | |
| 516 | /* Missing or incorrect session state */ |
| 517 | case OSMO_GSUP_SESSION_STATE_NONE: |
| 518 | default: |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 519 | LOG_TRANS(trans, LOGL_ERROR, "Unexpected session state %d\n", |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 520 | gsup_msg->session_state); |
| 521 | /* FIXME: send ERROR back to the HLR */ |
| 522 | msgb_free(ss_msg); |
| 523 | return -EINVAL; |
| 524 | } |
| 525 | |
| 526 | /* Facility IE is optional only for RELEASE COMPLETE */ |
| 527 | if (gh->msg_type != GSM0480_MTYPE_RELEASE_COMPLETE) { |
| 528 | if (!gsup_msg->ss_info || gsup_msg->ss_info_len < 2) { |
Neels Hofmeyr | ff7074a | 2019-02-28 05:50:06 +0100 | [diff] [blame] | 529 | LOG_TRANS(trans, LOGL_ERROR, "Missing mandatory Facility IE " |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 530 | "for mapped 0x%02x message\n", gh->msg_type); |
| 531 | /* FIXME: send ERROR back to the HLR */ |
| 532 | msgb_free(ss_msg); |
| 533 | return -EINVAL; |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | /* Append Facility IE if preset */ |
| 538 | if (gsup_msg->ss_info && gsup_msg->ss_info_len > 2) { |
| 539 | /* Facility IE carries LV, others carry TLV */ |
| 540 | if (gh->msg_type == GSM0480_MTYPE_FACILITY) |
| 541 | msgb_lv_put(ss_msg, gsup_msg->ss_info_len, gsup_msg->ss_info); |
| 542 | else |
| 543 | msgb_tlv_put(ss_msg, GSM0480_IE_FACILITY, |
| 544 | gsup_msg->ss_info_len, gsup_msg->ss_info); |
| 545 | } |
| 546 | |
| 547 | /* Should we release the transaction? */ |
| 548 | trans_end = (gh->msg_type == GSM0480_MTYPE_RELEASE_COMPLETE); |
| 549 | |
| 550 | /* Sent to the MS, give ownership of ss_msg */ |
Neels Hofmeyr | c4628a3 | 2018-12-07 14:47:34 +0100 | [diff] [blame] | 551 | msc_a = trans->msc_a; |
| 552 | if (!msc_a) { |
| 553 | LOG_TRANS(trans, LOGL_ERROR, "Cannot send SS message, no local MSC-A role defined for subscriber\n"); |
| 554 | msgb_free(ss_msg); |
| 555 | return -EINVAL; |
| 556 | } |
| 557 | msc_a_tx_dtap_to_i(msc_a, ss_msg); |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 558 | |
| 559 | /* Release transaction if required */ |
| 560 | if (trans_end) |
| 561 | trans_free(trans); |
| 562 | |
Vadim Yanitskiy | 8e25cc5 | 2018-06-23 03:32:20 +0700 | [diff] [blame] | 563 | /* Count established network-initiated NC SS/USSD sessions */ |
| 564 | if (gsup_msg->session_state == OSMO_GSUP_SESSION_STATE_BEGIN) |
| 565 | rate_ctr_inc(&net->msc_ctrs->ctr[MSC_CTR_NC_SS_MT_ESTABLISHED]); |
| 566 | |
Vadim Yanitskiy | 8a6ef55 | 2018-06-12 08:21:20 +0700 | [diff] [blame] | 567 | return 0; |
Harald Welte | 6eafe91 | 2009-10-16 08:32:58 +0200 | [diff] [blame] | 568 | } |