blob: 01389afb79058bdf22bc9fe36203927f9e38cd55 [file] [log] [blame]
Harald Welte6eafe912009-10-16 08:32:58 +02001/* (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 Yanitskiy8a6ef552018-06-12 08:21:20 +07004 * (C) 2018 by Vadim Yanitskiy <axilirator@gmail.com>
Harald Welte6eafe912009-10-16 08:32:58 +02005 *
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +01009 * 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 Welte6eafe912009-10-16 08:32:58 +020011 * (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 Welte9af6ddf2011-01-01 15:25:50 +010016 * GNU Affero General Public License for more details.
Harald Welte6eafe912009-10-16 08:32:58 +020017 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010018 * 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 Welte6eafe912009-10-16 08:32:58 +020020 *
21 */
22
Vadim Yanitskiy5b860fa2018-06-12 05:24:52 +070023/**
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 Welte6eafe912009-10-16 08:32:58 +020028
29#include <stdio.h>
Harald Welte6eafe912009-10-16 08:32:58 +020030#include <errno.h>
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +070031#include <stdbool.h>
32
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +070033#include <osmocom/core/linuxlist.h>
Vadim Yanitskiy8e25cc52018-06-23 03:32:20 +070034#include <osmocom/core/rate_ctr.h>
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +070035#include <osmocom/core/utils.h>
36#include <osmocom/core/msgb.h>
Vadim Yanitskiy0622ef52018-08-03 04:39:04 +070037
38#include <osmocom/gsm/protocol/gsm_04_80.h>
39#include <osmocom/gsm/gsm0480.h>
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +070040#include <osmocom/gsm/tlv.h>
Harald Welte6eafe912009-10-16 08:32:58 +020041
Neels Hofmeyr90843962017-09-04 15:04:35 +020042#include <osmocom/msc/gsm_04_80.h>
43#include <osmocom/msc/gsm_subscriber.h>
44#include <osmocom/msc/debug.h>
45#include <osmocom/msc/osmo_msc.h>
46#include <osmocom/msc/vlr.h>
Max43b01b02017-09-15 11:22:30 +020047#include <osmocom/msc/gsm_04_08.h>
Vadim Yanitskiy10c64192018-04-17 19:17:11 +070048#include <osmocom/msc/transaction.h>
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +070049#include <osmocom/msc/gsup_client.h>
50#include <osmocom/msc/msc_ifaces.h>
Vadim Yanitskiy10c64192018-04-17 19:17:11 +070051
52/* FIXME: choose a proper range */
53static uint32_t new_callref = 0x20000001;
Harald Welte6eafe912009-10-16 08:32:58 +020054
Vadim Yanitskiy5b860fa2018-06-12 05:24:52 +070055/* Entry point for call independent MO SS messages */
56int gsm0911_rcv_nc_ss(struct gsm_subscriber_connection *conn, struct msgb *msg)
Harald Welte6eafe912009-10-16 08:32:58 +020057{
Vadim Yanitskiy10c64192018-04-17 19:17:11 +070058 struct gsm48_hdr *gh = msgb_l3(msg);
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +070059 struct osmo_gsup_message gsup_msg;
Vadim Yanitskiy10c64192018-04-17 19:17:11 +070060 struct gsm_trans *trans;
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +070061 struct msgb *gsup_msgb;
62 uint16_t facility_ie_len;
63 uint8_t *facility_ie;
Vadim Yanitskiy10c64192018-04-17 19:17:11 +070064 uint8_t pdisc, tid;
65 uint8_t msg_type;
66 int rc;
Harald Welte6eafe912009-10-16 08:32:58 +020067
Vadim Yanitskiy10c64192018-04-17 19:17:11 +070068 pdisc = gsm48_hdr_pdisc(gh);
69 msg_type = gsm48_hdr_msg_type(gh);
70 tid = gsm48_hdr_trans_id_flip_ti(gh);
Harald Welte2483f1b2016-06-19 18:06:02 +020071
Vadim Yanitskiy10c64192018-04-17 19:17:11 +070072 /* Associate logging messages with this subscriber */
73 log_set_context(LOG_CTX_VLR_SUBSCR, conn->vsub);
74
75 DEBUGP(DMM, "Received SS/USSD data (trans_id=%x, msg_type=%s)\n",
76 tid, gsm48_pdisc_msgtype_name(pdisc, msg_type));
77
78 /* Reuse existing transaction, or create a new one */
79 trans = trans_find_by_id(conn, pdisc, tid);
80 if (!trans) {
Vadim Yanitskiy8e25cc52018-06-23 03:32:20 +070081 /* Count MS-initiated attempts to establish a NC SS/USSD session */
82 rate_ctr_inc(&conn->network->msc_ctrs->ctr[MSC_CTR_NC_SS_MO_REQUESTS]);
83
Vadim Yanitskiy10c64192018-04-17 19:17:11 +070084 /**
85 * According to GSM TS 04.80, section 2.4.2 "Register
86 * (mobile station to network direction)", the REGISTER
87 * message is sent by the mobile station to the network
88 * to assign a new transaction identifier for call independent
89 * supplementary service control and to request or acknowledge
90 * a supplementary service.
91 */
92 if (msg_type != GSM0480_MTYPE_REGISTER) {
93 LOGP(DMM, LOGL_ERROR, "Unexpected message (msg_type=%s), "
94 "transaction is not allocated yet\n",
95 gsm48_pdisc_msgtype_name(pdisc, msg_type));
Vadim Yanitskiy9aec25e2018-06-12 06:26:28 +070096 gsm48_tx_simple(conn,
97 GSM48_PDISC_NC_SS | (tid << 4),
98 GSM0480_MTYPE_RELEASE_COMPLETE);
Vadim Yanitskiy10c64192018-04-17 19:17:11 +070099 return -EINVAL;
100 }
101
102 DEBUGP(DMM, " -> (new transaction)\n");
103 trans = trans_alloc(conn->network, conn->vsub,
104 pdisc, tid, new_callref++);
105 if (!trans) {
106 DEBUGP(DMM, " -> No memory for trans\n");
Vadim Yanitskiy9aec25e2018-06-12 06:26:28 +0700107 gsm48_tx_simple(conn,
108 GSM48_PDISC_NC_SS | (tid << 4),
109 GSM0480_MTYPE_RELEASE_COMPLETE);
Vadim Yanitskiy10c64192018-04-17 19:17:11 +0700110 return -ENOMEM;
111 }
112
Vadim Yanitskiyad64e2a2018-06-26 18:27:25 +0700113 /* Count active NC SS/USSD sessions */
114 osmo_counter_inc(conn->network->active_nc_ss);
115
Vadim Yanitskiy10c64192018-04-17 19:17:11 +0700116 trans->conn = msc_subscr_conn_get(conn, MSC_CONN_USE_TRANS_NC_SS);
117 trans->dlci = OMSC_LINKID_CB(msg);
118 cm_service_request_concludes(conn, msg);
119 }
Harald Welte2483f1b2016-06-19 18:06:02 +0200120
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700121 /* Attempt to extract Facility IE */
122 rc = gsm0480_extract_ie_by_tag(gh, msgb_l3len(msg),
123 &facility_ie, &facility_ie_len, GSM0480_IE_FACILITY);
124 if (rc) {
125 LOGP(DMM, LOGL_ERROR, "GSM 04.80 message parsing error, "
126 "couldn't extract Facility IE\n");
127 goto error;
Tobias Engelea730322013-12-28 17:03:14 +0100128 }
129
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700130 /* Facility IE is optional for RELEASE COMPLETE */
131 if (msg_type != GSM0480_MTYPE_RELEASE_COMPLETE) {
132 if (!facility_ie || facility_ie_len < 2) {
133 LOGP(DMM, LOGL_ERROR, "GSM 04.80 message parsing error, "
134 "missing mandatory Facility IE\n");
135 rc = -EINVAL;
136 goto error;
Holger Hans Peter Freyther5085e0b2016-07-12 17:53:26 +0200137 }
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700138 }
139
140 /* Compose a mew GSUP message */
141 memset(&gsup_msg, 0x00, sizeof(gsup_msg));
142 gsup_msg.message_type = OSMO_GSUP_MSGT_PROC_SS_REQUEST;
143 gsup_msg.session_id = trans->callref;
144
145 /**
146 * Perform A-interface to GSUP-interface mapping,
147 * according to GSM TS 09.11, table 4.2.
148 */
149 switch (msg_type) {
150 case GSM0480_MTYPE_REGISTER:
151 gsup_msg.session_state = OSMO_GSUP_SESSION_STATE_BEGIN;
152 break;
153 case GSM0480_MTYPE_FACILITY:
154 gsup_msg.session_state = OSMO_GSUP_SESSION_STATE_CONTINUE;
155 break;
156 case GSM0480_MTYPE_RELEASE_COMPLETE:
157 gsup_msg.session_state = OSMO_GSUP_SESSION_STATE_END;
158 break;
159 }
160
161 /* Fill in the (optional) message payload */
162 if (facility_ie) {
163 gsup_msg.ss_info_len = facility_ie_len;
164 gsup_msg.ss_info = facility_ie;
165 }
166
167 /* Fill in subscriber's IMSI */
168 OSMO_STRLCPY_ARRAY(gsup_msg.imsi, conn->vsub->imsi);
169
170 /* Allocate GSUP message buffer */
171 gsup_msgb = gsup_client_msgb_alloc();
172 if (!gsup_msgb) {
173 LOGP(DMM, LOGL_ERROR, "Couldn't allocate GSUP message\n");
174 rc = -ENOMEM;
175 goto error;
176 }
177
178 /* Encode GSUP message */
179 rc = osmo_gsup_encode(gsup_msgb, &gsup_msg);
180 if (rc) {
181 LOGP(DMM, LOGL_ERROR, "Couldn't encode GSUP message\n");
182 goto error;
183 }
184
185 /* Finally send */
186 rc = gsup_client_send(conn->network->vlr->gsup_client, gsup_msgb);
187 if (rc) {
188 LOGP(DMM, LOGL_ERROR, "Couldn't send GSUP message\n");
189 goto error;
190 }
191
Vadim Yanitskiyfcc24ed2018-06-21 17:55:56 +0700192 /* Should we release connection? Or wait for response? */
193 if (msg_type == GSM0480_MTYPE_RELEASE_COMPLETE)
194 trans_free(trans);
195 else
196 msc_subscr_conn_communicating(conn);
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700197
Vadim Yanitskiy8e25cc52018-06-23 03:32:20 +0700198 /* Count established MS-initiated NC SS/USSD sessions */
199 if (msg_type == GSM0480_MTYPE_REGISTER)
200 rate_ctr_inc(&conn->network->msc_ctrs->ctr[MSC_CTR_NC_SS_MO_ESTABLISHED]);
201
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700202 return 0;
203
204error:
205 /* Abort transaction on DTAP-interface */
Vadim Yanitskiy0622ef52018-08-03 04:39:04 +0700206 msc_send_ussd_reject(conn, tid, -1,
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700207 GSM_0480_PROBLEM_CODE_TAG_GENERAL,
208 GSM_0480_GEN_PROB_CODE_UNRECOGNISED);
209 if (trans)
210 trans_free(trans);
211
212 /* TODO: abort transaction on GSUP interface if any */
213 return rc;
214}
215
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700216/* Call-back from paging the B-end of the connection */
217static int handle_paging_event(unsigned int hooknum, unsigned int event,
218 struct msgb *msg, void *_conn, void *_transt)
219{
220 struct gsm_subscriber_connection *conn = _conn;
221 enum gsm_paging_event paging_event = event;
222 struct gsm_trans *transt = _transt;
223 struct gsm48_hdr *gh;
224 struct msgb *ss_msg;
225
226 OSMO_ASSERT(!transt->conn);
227 OSMO_ASSERT(transt->ss.msg);
228
229 switch (paging_event) {
230 case GSM_PAGING_SUCCEEDED:
231 DEBUGP(DMM, "Paging subscr %s succeeded!\n",
232 vlr_subscr_msisdn_or_name(transt->vsub));
233
234 /* Assign connection */
235 transt->conn = msc_subscr_conn_get(conn, MSC_CONN_USE_TRANS_NC_SS);
236 transt->paging_request = NULL;
237
238 /* Send stored message */
239 ss_msg = transt->ss.msg;
240 OSMO_ASSERT(ss_msg);
241
242 gh = (struct gsm48_hdr *) msgb_push(ss_msg, sizeof(*gh));
243 gh->proto_discr = GSM48_PDISC_NC_SS;
244 gh->proto_discr |= transt->transaction_id << 4;
245 gh->msg_type = GSM0480_MTYPE_REGISTER;
246
247 /* Sent to the MS, give ownership of ss_msg */
248 msc_tx_dtap(transt->conn, ss_msg);
249 transt->ss.msg = NULL;
Vadim Yanitskiy8e25cc52018-06-23 03:32:20 +0700250
251 /* Count established network-initiated NC SS/USSD sessions */
252 rate_ctr_inc(&conn->network->msc_ctrs->ctr[MSC_CTR_NC_SS_MT_ESTABLISHED]);
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700253 break;
254 case GSM_PAGING_EXPIRED:
255 case GSM_PAGING_BUSY:
256 DEBUGP(DMM, "Paging subscr %s %s!\n",
257 vlr_subscr_msisdn_or_name(transt->vsub),
258 paging_event == GSM_PAGING_EXPIRED ? "expired" : "busy");
259
260 /* TODO: inform HLR about this failure */
261
262 msgb_free(transt->ss.msg);
263 transt->ss.msg = NULL;
264
265 transt->callref = 0;
266 transt->paging_request = NULL;
267 trans_free(transt);
268 break;
269 }
270
271 return 0;
272}
273
274static struct gsm_trans *establish_nc_ss_trans(struct gsm_network *net,
275 struct vlr_subscr *vsub, struct osmo_gsup_message *gsup_msg)
276{
277 struct gsm_subscriber_connection *conn;
278 struct gsm_trans *trans, *transt;
279 int tid;
280
281 if (gsup_msg->session_state != OSMO_GSUP_SESSION_STATE_BEGIN) {
282 LOGP(DMM, LOGL_ERROR, "Received non-BEGIN message "
283 "for non-existing transaction\n");
284 return NULL;
285 }
286
287 if (!gsup_msg->ss_info || gsup_msg->ss_info_len < 2) {
288 LOGP(DMM, LOGL_ERROR, "Missing mandatory Facility IE\n");
289 return NULL;
290 }
291
292 /* If subscriber is not "attached" */
293 if (!vsub->lac) {
294 LOGP(DMM, LOGL_ERROR, "Network-originated session "
295 "rejected - subscriber is not attached\n");
296 return NULL;
297 }
298
299 DEBUGP(DMM, "Establishing network-originated session\n");
300
301 /* Allocate a new transaction */
302 trans = trans_alloc(net, vsub, GSM48_PDISC_NC_SS,
303 0xff, gsup_msg->session_id);
304 if (!trans) {
305 DEBUGP(DMM, " -> No memory for trans\n");
306 return NULL;
307 }
308
Vadim Yanitskiyad64e2a2018-06-26 18:27:25 +0700309 /* Count active NC SS/USSD sessions */
310 osmo_counter_inc(net->active_nc_ss);
311
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700312 /* Assign transaction ID */
313 tid = trans_assign_trans_id(trans->net,
314 trans->vsub, GSM48_PDISC_NC_SS, 0);
315 if (tid < 0) {
316 LOGP(DMM, LOGL_ERROR, "No free transaction ID\n");
317 /* TODO: inform HLR about this */
318 /* TODO: release connection with subscriber */
319 trans->callref = 0;
320 trans_free(trans);
321 return NULL;
322 }
323 trans->transaction_id = tid;
324
325 /* Attempt to find connection */
326 conn = connection_for_subscr(vsub);
327 if (conn) {
328 /* Assign connection */
329 trans->conn = msc_subscr_conn_get(conn, MSC_CONN_USE_TRANS_NC_SS);
330 trans->dlci = 0x00; /* SAPI=0, not SACCH */
331 return trans;
332 }
333
334 DEBUGP(DMM, "Triggering Paging Request\n");
335
336 /* Find transaction with this subscriber already paging */
337 llist_for_each_entry(transt, &net->trans_list, entry) {
338 /* Transaction of our conn? */
339 if (transt == trans || transt->vsub != vsub)
340 continue;
341
342 LOGP(DMM, LOGL_ERROR, "Paging already started, "
343 "rejecting message...\n");
344 trans_free(trans);
345 return NULL;
346 }
347
348 /* Trigger Paging Request */
349 trans->paging_request = subscr_request_conn(vsub,
350 &handle_paging_event, trans, "GSM 09.11 SS/USSD");
351 if (!trans->paging_request) {
352 LOGP(DMM, LOGL_ERROR, "Failed to allocate paging token\n");
353 trans_free(trans);
354 return NULL;
355 }
356
357 /* Store the Facility IE to be sent */
358 OSMO_ASSERT(trans->ss.msg == NULL);
359 trans->ss.msg = gsm48_msgb_alloc_name("GSM 04.08 SS/USSD");
360 msgb_tlv_put(trans->ss.msg, GSM0480_IE_FACILITY,
361 gsup_msg->ss_info_len, gsup_msg->ss_info);
362
363 return NULL;
364}
365
366/* NC SS specific transaction release.
367 * Gets called by trans_free, DO NOT CALL YOURSELF! */
368void _gsm911_nc_ss_trans_free(struct gsm_trans *trans)
369{
370 /**
371 * TODO: if transaction wasn't properly terminated,
372 * we need to do it here by releasing the subscriber
373 * connection and sending notification via GSUP...
374 */
375 if (trans->ss.msg != NULL)
376 msgb_free(trans->ss.msg);
Vadim Yanitskiyad64e2a2018-06-26 18:27:25 +0700377
378 /* One session less */
379 osmo_counter_dec(trans->net->active_nc_ss);
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700380}
381
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700382int gsm0911_gsup_handler(struct vlr_subscr *vsub,
383 struct osmo_gsup_message *gsup_msg)
384{
385 struct vlr_instance *vlr;
386 struct gsm_network *net;
387 struct gsm_trans *trans;
388 struct gsm48_hdr *gh;
389 struct msgb *ss_msg;
390 bool trans_end;
391
392 /* Associate logging messages with this subscriber */
393 log_set_context(LOG_CTX_VLR_SUBSCR, vsub);
394
395 /* Obtain pointer to vlr_instance */
396 vlr = vsub->vlr;
397 OSMO_ASSERT(vlr);
398
399 /* Obtain pointer to gsm_network */
400 net = (struct gsm_network *) vlr->user_ctx;
401 OSMO_ASSERT(net);
402
403 /* Handle errors */
404 if (OSMO_GSUP_IS_MSGT_ERROR(gsup_msg->message_type)) {
405 /* FIXME: handle this error somehow! */
Harald Welte6307b852009-10-16 08:41:51 +0200406 return 0;
Holger Hans Peter Freyther5085e0b2016-07-12 17:53:26 +0200407 }
Harald Welte6eafe912009-10-16 08:32:58 +0200408
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700409 /* Attempt to find DTAP-transaction */
410 trans = trans_find_by_callref(net, gsup_msg->session_id);
411 if (!trans) {
Vadim Yanitskiy8e25cc52018-06-23 03:32:20 +0700412 /* Count network-initiated attempts to establish a NC SS/USSD session */
413 rate_ctr_inc(&net->msc_ctrs->ctr[MSC_CTR_NC_SS_MT_REQUESTS]);
414
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700415 /* Attempt to establish a new transaction */
416 trans = establish_nc_ss_trans(net, vsub, gsup_msg);
417 if (!trans) {
418 /* FIXME: send ERROR back to the HLR */
419 return -EINVAL;
420 }
421
422 /* Wait for Paging Response */
423 if (trans->paging_request)
424 return 0;
Harald Welte6eafe912009-10-16 08:32:58 +0200425 }
Holger Hans Peter Freyther24866632010-06-30 12:15:19 +0800426
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700427 /* Allocate and prepare a new MT message */
428 ss_msg = gsm48_msgb_alloc_name("GSM 04.08 SS/USSD");
429 gh = (struct gsm48_hdr *) msgb_push(ss_msg, sizeof(*gh));
430 gh->proto_discr = GSM48_PDISC_NC_SS;
431 gh->proto_discr |= trans->transaction_id << 4;
Vadim Yanitskiy10c64192018-04-17 19:17:11 +0700432
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700433 /**
434 * Perform GSUP-interface to A-interface mapping,
435 * according to GSM TS 09.11, table 4.1.
436 *
437 * TODO: see (note 3), both CONTINUE and END may
438 * be also mapped to REGISTER if a new transaction
439 * has to be established.
440 */
441 switch (gsup_msg->session_state) {
442 case OSMO_GSUP_SESSION_STATE_BEGIN:
443 gh->msg_type = GSM0480_MTYPE_REGISTER;
444 break;
445 case OSMO_GSUP_SESSION_STATE_CONTINUE:
446 gh->msg_type = GSM0480_MTYPE_FACILITY;
447 break;
448 case OSMO_GSUP_SESSION_STATE_END:
449 gh->msg_type = GSM0480_MTYPE_RELEASE_COMPLETE;
450 break;
451
452 /* Missing or incorrect session state */
453 case OSMO_GSUP_SESSION_STATE_NONE:
454 default:
455 LOGP(DMM, LOGL_ERROR, "Unexpected session state %d\n",
456 gsup_msg->session_state);
457 /* FIXME: send ERROR back to the HLR */
458 msgb_free(ss_msg);
459 return -EINVAL;
460 }
461
462 /* Facility IE is optional only for RELEASE COMPLETE */
463 if (gh->msg_type != GSM0480_MTYPE_RELEASE_COMPLETE) {
464 if (!gsup_msg->ss_info || gsup_msg->ss_info_len < 2) {
465 LOGP(DMM, LOGL_ERROR, "Missing mandatory Facility IE "
466 "for mapped 0x%02x message\n", gh->msg_type);
467 /* FIXME: send ERROR back to the HLR */
468 msgb_free(ss_msg);
469 return -EINVAL;
470 }
471 }
472
473 /* Append Facility IE if preset */
474 if (gsup_msg->ss_info && gsup_msg->ss_info_len > 2) {
475 /* Facility IE carries LV, others carry TLV */
476 if (gh->msg_type == GSM0480_MTYPE_FACILITY)
477 msgb_lv_put(ss_msg, gsup_msg->ss_info_len, gsup_msg->ss_info);
478 else
479 msgb_tlv_put(ss_msg, GSM0480_IE_FACILITY,
480 gsup_msg->ss_info_len, gsup_msg->ss_info);
481 }
482
483 /* Should we release the transaction? */
484 trans_end = (gh->msg_type == GSM0480_MTYPE_RELEASE_COMPLETE);
485
486 /* Sent to the MS, give ownership of ss_msg */
487 msc_tx_dtap(trans->conn, ss_msg);
488
489 /* Release transaction if required */
490 if (trans_end)
491 trans_free(trans);
492
Vadim Yanitskiy8e25cc52018-06-23 03:32:20 +0700493 /* Count established network-initiated NC SS/USSD sessions */
494 if (gsup_msg->session_state == OSMO_GSUP_SESSION_STATE_BEGIN)
495 rate_ctr_inc(&net->msc_ctrs->ctr[MSC_CTR_NC_SS_MT_ESTABLISHED]);
496
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700497 return 0;
Harald Welte6eafe912009-10-16 08:32:58 +0200498}