blob: 63a10472cfa3b5204958ae879a96aec5a23e0a59 [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>
Harald Welte1ea6baf2018-07-31 19:40:52 +020049#include <osmocom/gsupclient/gsup_client.h>
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +070050#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 */
Harald Welte1ea6baf2018-07-31 19:40:52 +0200171 gsup_msgb = osmo_gsup_client_msgb_alloc();
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700172 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 */
Harald Welte1ea6baf2018-07-31 19:40:52 +0200186 rc = osmo_gsup_client_send(conn->network->vlr->gsup_client, gsup_msgb);
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700187 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;
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700240 gh = (struct gsm48_hdr *) msgb_push(ss_msg, sizeof(*gh));
241 gh->proto_discr = GSM48_PDISC_NC_SS;
242 gh->proto_discr |= transt->transaction_id << 4;
243 gh->msg_type = GSM0480_MTYPE_REGISTER;
244
245 /* Sent to the MS, give ownership of ss_msg */
246 msc_tx_dtap(transt->conn, ss_msg);
247 transt->ss.msg = NULL;
Vadim Yanitskiy8e25cc52018-06-23 03:32:20 +0700248
249 /* Count established network-initiated NC SS/USSD sessions */
250 rate_ctr_inc(&conn->network->msc_ctrs->ctr[MSC_CTR_NC_SS_MT_ESTABLISHED]);
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700251 break;
252 case GSM_PAGING_EXPIRED:
253 case GSM_PAGING_BUSY:
254 DEBUGP(DMM, "Paging subscr %s %s!\n",
255 vlr_subscr_msisdn_or_name(transt->vsub),
256 paging_event == GSM_PAGING_EXPIRED ? "expired" : "busy");
257
258 /* TODO: inform HLR about this failure */
259
260 msgb_free(transt->ss.msg);
261 transt->ss.msg = NULL;
262
263 transt->callref = 0;
264 transt->paging_request = NULL;
265 trans_free(transt);
266 break;
267 }
268
269 return 0;
270}
271
272static struct gsm_trans *establish_nc_ss_trans(struct gsm_network *net,
273 struct vlr_subscr *vsub, struct osmo_gsup_message *gsup_msg)
274{
275 struct gsm_subscriber_connection *conn;
276 struct gsm_trans *trans, *transt;
277 int tid;
278
279 if (gsup_msg->session_state != OSMO_GSUP_SESSION_STATE_BEGIN) {
280 LOGP(DMM, LOGL_ERROR, "Received non-BEGIN message "
281 "for non-existing transaction\n");
282 return NULL;
283 }
284
285 if (!gsup_msg->ss_info || gsup_msg->ss_info_len < 2) {
286 LOGP(DMM, LOGL_ERROR, "Missing mandatory Facility IE\n");
287 return NULL;
288 }
289
290 /* If subscriber is not "attached" */
291 if (!vsub->lac) {
292 LOGP(DMM, LOGL_ERROR, "Network-originated session "
293 "rejected - subscriber is not attached\n");
294 return NULL;
295 }
296
297 DEBUGP(DMM, "Establishing network-originated session\n");
298
299 /* Allocate a new transaction */
300 trans = trans_alloc(net, vsub, GSM48_PDISC_NC_SS,
301 0xff, gsup_msg->session_id);
302 if (!trans) {
303 DEBUGP(DMM, " -> No memory for trans\n");
304 return NULL;
305 }
306
Vadim Yanitskiyad64e2a2018-06-26 18:27:25 +0700307 /* Count active NC SS/USSD sessions */
308 osmo_counter_inc(net->active_nc_ss);
309
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700310 /* Assign transaction ID */
311 tid = trans_assign_trans_id(trans->net,
312 trans->vsub, GSM48_PDISC_NC_SS, 0);
313 if (tid < 0) {
314 LOGP(DMM, LOGL_ERROR, "No free transaction ID\n");
315 /* TODO: inform HLR about this */
316 /* TODO: release connection with subscriber */
317 trans->callref = 0;
318 trans_free(trans);
319 return NULL;
320 }
321 trans->transaction_id = tid;
322
323 /* Attempt to find connection */
324 conn = connection_for_subscr(vsub);
325 if (conn) {
326 /* Assign connection */
327 trans->conn = msc_subscr_conn_get(conn, MSC_CONN_USE_TRANS_NC_SS);
328 trans->dlci = 0x00; /* SAPI=0, not SACCH */
329 return trans;
330 }
331
332 DEBUGP(DMM, "Triggering Paging Request\n");
333
334 /* Find transaction with this subscriber already paging */
335 llist_for_each_entry(transt, &net->trans_list, entry) {
336 /* Transaction of our conn? */
337 if (transt == trans || transt->vsub != vsub)
338 continue;
339
340 LOGP(DMM, LOGL_ERROR, "Paging already started, "
341 "rejecting message...\n");
342 trans_free(trans);
343 return NULL;
344 }
345
346 /* Trigger Paging Request */
347 trans->paging_request = subscr_request_conn(vsub,
348 &handle_paging_event, trans, "GSM 09.11 SS/USSD");
349 if (!trans->paging_request) {
350 LOGP(DMM, LOGL_ERROR, "Failed to allocate paging token\n");
351 trans_free(trans);
352 return NULL;
353 }
354
355 /* Store the Facility IE to be sent */
356 OSMO_ASSERT(trans->ss.msg == NULL);
357 trans->ss.msg = gsm48_msgb_alloc_name("GSM 04.08 SS/USSD");
358 msgb_tlv_put(trans->ss.msg, GSM0480_IE_FACILITY,
359 gsup_msg->ss_info_len, gsup_msg->ss_info);
360
361 return NULL;
362}
363
364/* NC SS specific transaction release.
365 * Gets called by trans_free, DO NOT CALL YOURSELF! */
366void _gsm911_nc_ss_trans_free(struct gsm_trans *trans)
367{
368 /**
369 * TODO: if transaction wasn't properly terminated,
370 * we need to do it here by releasing the subscriber
371 * connection and sending notification via GSUP...
372 */
373 if (trans->ss.msg != NULL)
374 msgb_free(trans->ss.msg);
Vadim Yanitskiyad64e2a2018-06-26 18:27:25 +0700375
376 /* One session less */
377 osmo_counter_dec(trans->net->active_nc_ss);
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700378}
379
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700380int gsm0911_gsup_handler(struct vlr_subscr *vsub,
381 struct osmo_gsup_message *gsup_msg)
382{
383 struct vlr_instance *vlr;
384 struct gsm_network *net;
385 struct gsm_trans *trans;
386 struct gsm48_hdr *gh;
387 struct msgb *ss_msg;
388 bool trans_end;
389
390 /* Associate logging messages with this subscriber */
391 log_set_context(LOG_CTX_VLR_SUBSCR, vsub);
392
393 /* Obtain pointer to vlr_instance */
394 vlr = vsub->vlr;
395 OSMO_ASSERT(vlr);
396
397 /* Obtain pointer to gsm_network */
398 net = (struct gsm_network *) vlr->user_ctx;
399 OSMO_ASSERT(net);
400
401 /* Handle errors */
402 if (OSMO_GSUP_IS_MSGT_ERROR(gsup_msg->message_type)) {
403 /* FIXME: handle this error somehow! */
Harald Welte6307b852009-10-16 08:41:51 +0200404 return 0;
Holger Hans Peter Freyther5085e0b2016-07-12 17:53:26 +0200405 }
Harald Welte6eafe912009-10-16 08:32:58 +0200406
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700407 /* Attempt to find DTAP-transaction */
408 trans = trans_find_by_callref(net, gsup_msg->session_id);
409 if (!trans) {
Vadim Yanitskiy8e25cc52018-06-23 03:32:20 +0700410 /* Count network-initiated attempts to establish a NC SS/USSD session */
411 rate_ctr_inc(&net->msc_ctrs->ctr[MSC_CTR_NC_SS_MT_REQUESTS]);
412
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700413 /* Attempt to establish a new transaction */
414 trans = establish_nc_ss_trans(net, vsub, gsup_msg);
415 if (!trans) {
416 /* FIXME: send ERROR back to the HLR */
417 return -EINVAL;
418 }
419
420 /* Wait for Paging Response */
421 if (trans->paging_request)
422 return 0;
Harald Welte6eafe912009-10-16 08:32:58 +0200423 }
Holger Hans Peter Freyther24866632010-06-30 12:15:19 +0800424
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700425 /* Allocate and prepare a new MT message */
426 ss_msg = gsm48_msgb_alloc_name("GSM 04.08 SS/USSD");
427 gh = (struct gsm48_hdr *) msgb_push(ss_msg, sizeof(*gh));
428 gh->proto_discr = GSM48_PDISC_NC_SS;
429 gh->proto_discr |= trans->transaction_id << 4;
Vadim Yanitskiy10c64192018-04-17 19:17:11 +0700430
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700431 /**
432 * Perform GSUP-interface to A-interface mapping,
433 * according to GSM TS 09.11, table 4.1.
434 *
435 * TODO: see (note 3), both CONTINUE and END may
436 * be also mapped to REGISTER if a new transaction
437 * has to be established.
438 */
439 switch (gsup_msg->session_state) {
440 case OSMO_GSUP_SESSION_STATE_BEGIN:
441 gh->msg_type = GSM0480_MTYPE_REGISTER;
442 break;
443 case OSMO_GSUP_SESSION_STATE_CONTINUE:
444 gh->msg_type = GSM0480_MTYPE_FACILITY;
445 break;
446 case OSMO_GSUP_SESSION_STATE_END:
447 gh->msg_type = GSM0480_MTYPE_RELEASE_COMPLETE;
448 break;
449
450 /* Missing or incorrect session state */
451 case OSMO_GSUP_SESSION_STATE_NONE:
452 default:
453 LOGP(DMM, LOGL_ERROR, "Unexpected session state %d\n",
454 gsup_msg->session_state);
455 /* FIXME: send ERROR back to the HLR */
456 msgb_free(ss_msg);
457 return -EINVAL;
458 }
459
460 /* Facility IE is optional only for RELEASE COMPLETE */
461 if (gh->msg_type != GSM0480_MTYPE_RELEASE_COMPLETE) {
462 if (!gsup_msg->ss_info || gsup_msg->ss_info_len < 2) {
463 LOGP(DMM, LOGL_ERROR, "Missing mandatory Facility IE "
464 "for mapped 0x%02x message\n", gh->msg_type);
465 /* FIXME: send ERROR back to the HLR */
466 msgb_free(ss_msg);
467 return -EINVAL;
468 }
469 }
470
471 /* Append Facility IE if preset */
472 if (gsup_msg->ss_info && gsup_msg->ss_info_len > 2) {
473 /* Facility IE carries LV, others carry TLV */
474 if (gh->msg_type == GSM0480_MTYPE_FACILITY)
475 msgb_lv_put(ss_msg, gsup_msg->ss_info_len, gsup_msg->ss_info);
476 else
477 msgb_tlv_put(ss_msg, GSM0480_IE_FACILITY,
478 gsup_msg->ss_info_len, gsup_msg->ss_info);
479 }
480
481 /* Should we release the transaction? */
482 trans_end = (gh->msg_type == GSM0480_MTYPE_RELEASE_COMPLETE);
483
484 /* Sent to the MS, give ownership of ss_msg */
485 msc_tx_dtap(trans->conn, ss_msg);
486
487 /* Release transaction if required */
488 if (trans_end)
489 trans_free(trans);
490
Vadim Yanitskiy8e25cc52018-06-23 03:32:20 +0700491 /* Count established network-initiated NC SS/USSD sessions */
492 if (gsup_msg->session_state == OSMO_GSUP_SESSION_STATE_BEGIN)
493 rate_ctr_inc(&net->msc_ctrs->ctr[MSC_CTR_NC_SS_MT_ESTABLISHED]);
494
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700495 return 0;
Harald Welte6eafe912009-10-16 08:32:58 +0200496}