blob: 43bf48c565f06575987b25ec78d56d4bab060b8e [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>
Neels Hofmeyr90843962017-09-04 15:04:35 +020045#include <osmocom/msc/vlr.h>
Max43b01b02017-09-15 11:22:30 +020046#include <osmocom/msc/gsm_04_08.h>
Vadim Yanitskiy10c64192018-04-17 19:17:11 +070047#include <osmocom/msc/transaction.h>
Harald Welte1ea6baf2018-07-31 19:40:52 +020048#include <osmocom/gsupclient/gsup_client.h>
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +070049#include <osmocom/msc/msc_ifaces.h>
Vadim Yanitskiy10c64192018-04-17 19:17:11 +070050
51/* FIXME: choose a proper range */
52static uint32_t new_callref = 0x20000001;
Harald Welte6eafe912009-10-16 08:32:58 +020053
Vadim Yanitskiy5b860fa2018-06-12 05:24:52 +070054/* Entry point for call independent MO SS messages */
Neels Hofmeyrc036b792018-11-29 22:37:51 +010055int gsm0911_rcv_nc_ss(struct ran_conn *conn, struct msgb *msg)
Harald Welte6eafe912009-10-16 08:32:58 +020056{
Vadim Yanitskiy10c64192018-04-17 19:17:11 +070057 struct gsm48_hdr *gh = msgb_l3(msg);
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +070058 struct osmo_gsup_message gsup_msg;
Vadim Yanitskiy10c64192018-04-17 19:17:11 +070059 struct gsm_trans *trans;
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +070060 struct msgb *gsup_msgb;
61 uint16_t facility_ie_len;
62 uint8_t *facility_ie;
Vadim Yanitskiy10c64192018-04-17 19:17:11 +070063 uint8_t pdisc, tid;
64 uint8_t msg_type;
65 int rc;
Harald Welte6eafe912009-10-16 08:32:58 +020066
Vadim Yanitskiy10c64192018-04-17 19:17:11 +070067 pdisc = gsm48_hdr_pdisc(gh);
68 msg_type = gsm48_hdr_msg_type(gh);
69 tid = gsm48_hdr_trans_id_flip_ti(gh);
Harald Welte2483f1b2016-06-19 18:06:02 +020070
Vadim Yanitskiy10c64192018-04-17 19:17:11 +070071 /* Associate logging messages with this subscriber */
72 log_set_context(LOG_CTX_VLR_SUBSCR, conn->vsub);
73
74 DEBUGP(DMM, "Received SS/USSD data (trans_id=%x, msg_type=%s)\n",
75 tid, gsm48_pdisc_msgtype_name(pdisc, msg_type));
76
77 /* Reuse existing transaction, or create a new one */
78 trans = trans_find_by_id(conn, pdisc, tid);
79 if (!trans) {
Vadim Yanitskiy8e25cc52018-06-23 03:32:20 +070080 /* Count MS-initiated attempts to establish a NC SS/USSD session */
81 rate_ctr_inc(&conn->network->msc_ctrs->ctr[MSC_CTR_NC_SS_MO_REQUESTS]);
82
Vadim Yanitskiy10c64192018-04-17 19:17:11 +070083 /**
84 * According to GSM TS 04.80, section 2.4.2 "Register
85 * (mobile station to network direction)", the REGISTER
86 * message is sent by the mobile station to the network
87 * to assign a new transaction identifier for call independent
88 * supplementary service control and to request or acknowledge
89 * a supplementary service.
90 */
91 if (msg_type != GSM0480_MTYPE_REGISTER) {
92 LOGP(DMM, LOGL_ERROR, "Unexpected message (msg_type=%s), "
93 "transaction is not allocated yet\n",
94 gsm48_pdisc_msgtype_name(pdisc, msg_type));
Vadim Yanitskiy9aec25e2018-06-12 06:26:28 +070095 gsm48_tx_simple(conn,
96 GSM48_PDISC_NC_SS | (tid << 4),
97 GSM0480_MTYPE_RELEASE_COMPLETE);
Vadim Yanitskiy10c64192018-04-17 19:17:11 +070098 return -EINVAL;
99 }
100
101 DEBUGP(DMM, " -> (new transaction)\n");
102 trans = trans_alloc(conn->network, conn->vsub,
103 pdisc, tid, new_callref++);
104 if (!trans) {
105 DEBUGP(DMM, " -> No memory for trans\n");
Vadim Yanitskiy9aec25e2018-06-12 06:26:28 +0700106 gsm48_tx_simple(conn,
107 GSM48_PDISC_NC_SS | (tid << 4),
108 GSM0480_MTYPE_RELEASE_COMPLETE);
Vadim Yanitskiy10c64192018-04-17 19:17:11 +0700109 return -ENOMEM;
110 }
111
Vadim Yanitskiyad64e2a2018-06-26 18:27:25 +0700112 /* Count active NC SS/USSD sessions */
113 osmo_counter_inc(conn->network->active_nc_ss);
114
Neels Hofmeyr3c20a5e2018-11-30 01:08:36 +0100115 trans->conn = ran_conn_get(conn, RAN_CONN_USE_TRANS_NC_SS);
Vadim Yanitskiy10c64192018-04-17 19:17:11 +0700116 trans->dlci = OMSC_LINKID_CB(msg);
117 cm_service_request_concludes(conn, msg);
118 }
Harald Welte2483f1b2016-06-19 18:06:02 +0200119
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700120 /* Attempt to extract Facility IE */
121 rc = gsm0480_extract_ie_by_tag(gh, msgb_l3len(msg),
122 &facility_ie, &facility_ie_len, GSM0480_IE_FACILITY);
123 if (rc) {
124 LOGP(DMM, LOGL_ERROR, "GSM 04.80 message parsing error, "
125 "couldn't extract Facility IE\n");
126 goto error;
Tobias Engelea730322013-12-28 17:03:14 +0100127 }
128
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700129 /* Facility IE is optional for RELEASE COMPLETE */
130 if (msg_type != GSM0480_MTYPE_RELEASE_COMPLETE) {
131 if (!facility_ie || facility_ie_len < 2) {
132 LOGP(DMM, LOGL_ERROR, "GSM 04.80 message parsing error, "
133 "missing mandatory Facility IE\n");
134 rc = -EINVAL;
135 goto error;
Holger Hans Peter Freyther5085e0b2016-07-12 17:53:26 +0200136 }
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700137 }
138
139 /* Compose a mew GSUP message */
140 memset(&gsup_msg, 0x00, sizeof(gsup_msg));
141 gsup_msg.message_type = OSMO_GSUP_MSGT_PROC_SS_REQUEST;
142 gsup_msg.session_id = trans->callref;
143
144 /**
145 * Perform A-interface to GSUP-interface mapping,
146 * according to GSM TS 09.11, table 4.2.
147 */
148 switch (msg_type) {
149 case GSM0480_MTYPE_REGISTER:
150 gsup_msg.session_state = OSMO_GSUP_SESSION_STATE_BEGIN;
151 break;
152 case GSM0480_MTYPE_FACILITY:
153 gsup_msg.session_state = OSMO_GSUP_SESSION_STATE_CONTINUE;
154 break;
155 case GSM0480_MTYPE_RELEASE_COMPLETE:
156 gsup_msg.session_state = OSMO_GSUP_SESSION_STATE_END;
157 break;
158 }
159
160 /* Fill in the (optional) message payload */
161 if (facility_ie) {
162 gsup_msg.ss_info_len = facility_ie_len;
163 gsup_msg.ss_info = facility_ie;
164 }
165
166 /* Fill in subscriber's IMSI */
167 OSMO_STRLCPY_ARRAY(gsup_msg.imsi, conn->vsub->imsi);
168
169 /* Allocate GSUP message buffer */
Harald Welte1ea6baf2018-07-31 19:40:52 +0200170 gsup_msgb = osmo_gsup_client_msgb_alloc();
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700171 if (!gsup_msgb) {
172 LOGP(DMM, LOGL_ERROR, "Couldn't allocate GSUP message\n");
173 rc = -ENOMEM;
174 goto error;
175 }
176
177 /* Encode GSUP message */
178 rc = osmo_gsup_encode(gsup_msgb, &gsup_msg);
179 if (rc) {
180 LOGP(DMM, LOGL_ERROR, "Couldn't encode GSUP message\n");
181 goto error;
182 }
183
184 /* Finally send */
Harald Welte1ea6baf2018-07-31 19:40:52 +0200185 rc = osmo_gsup_client_send(conn->network->vlr->gsup_client, gsup_msgb);
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700186 if (rc) {
187 LOGP(DMM, LOGL_ERROR, "Couldn't send GSUP message\n");
188 goto error;
189 }
190
Vadim Yanitskiyfcc24ed2018-06-21 17:55:56 +0700191 /* Should we release connection? Or wait for response? */
192 if (msg_type == GSM0480_MTYPE_RELEASE_COMPLETE)
193 trans_free(trans);
194 else
Neels Hofmeyrc036b792018-11-29 22:37:51 +0100195 ran_conn_communicating(conn);
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700196
Vadim Yanitskiy8e25cc52018-06-23 03:32:20 +0700197 /* Count established MS-initiated NC SS/USSD sessions */
198 if (msg_type == GSM0480_MTYPE_REGISTER)
199 rate_ctr_inc(&conn->network->msc_ctrs->ctr[MSC_CTR_NC_SS_MO_ESTABLISHED]);
200
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700201 return 0;
202
203error:
204 /* Abort transaction on DTAP-interface */
Vadim Yanitskiy0622ef52018-08-03 04:39:04 +0700205 msc_send_ussd_reject(conn, tid, -1,
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700206 GSM_0480_PROBLEM_CODE_TAG_GENERAL,
207 GSM_0480_GEN_PROB_CODE_UNRECOGNISED);
208 if (trans)
209 trans_free(trans);
210
211 /* TODO: abort transaction on GSUP interface if any */
212 return rc;
213}
214
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700215/* Call-back from paging the B-end of the connection */
216static int handle_paging_event(unsigned int hooknum, unsigned int event,
217 struct msgb *msg, void *_conn, void *_transt)
218{
Neels Hofmeyrc036b792018-11-29 22:37:51 +0100219 struct ran_conn *conn = _conn;
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700220 enum gsm_paging_event paging_event = event;
221 struct gsm_trans *transt = _transt;
222 struct gsm48_hdr *gh;
223 struct msgb *ss_msg;
224
225 OSMO_ASSERT(!transt->conn);
226 OSMO_ASSERT(transt->ss.msg);
227
228 switch (paging_event) {
229 case GSM_PAGING_SUCCEEDED:
230 DEBUGP(DMM, "Paging subscr %s succeeded!\n",
231 vlr_subscr_msisdn_or_name(transt->vsub));
232
233 /* Assign connection */
Neels Hofmeyr3c20a5e2018-11-30 01:08:36 +0100234 transt->conn = ran_conn_get(conn, RAN_CONN_USE_TRANS_NC_SS);
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700235 transt->paging_request = NULL;
236
237 /* Send stored message */
238 ss_msg = transt->ss.msg;
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700239 gh = (struct gsm48_hdr *) msgb_push(ss_msg, sizeof(*gh));
240 gh->proto_discr = GSM48_PDISC_NC_SS;
241 gh->proto_discr |= transt->transaction_id << 4;
242 gh->msg_type = GSM0480_MTYPE_REGISTER;
243
244 /* Sent to the MS, give ownership of ss_msg */
245 msc_tx_dtap(transt->conn, ss_msg);
246 transt->ss.msg = NULL;
Vadim Yanitskiy8e25cc52018-06-23 03:32:20 +0700247
248 /* Count established network-initiated NC SS/USSD sessions */
249 rate_ctr_inc(&conn->network->msc_ctrs->ctr[MSC_CTR_NC_SS_MT_ESTABLISHED]);
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700250 break;
251 case GSM_PAGING_EXPIRED:
252 case GSM_PAGING_BUSY:
253 DEBUGP(DMM, "Paging subscr %s %s!\n",
254 vlr_subscr_msisdn_or_name(transt->vsub),
255 paging_event == GSM_PAGING_EXPIRED ? "expired" : "busy");
256
257 /* TODO: inform HLR about this failure */
258
259 msgb_free(transt->ss.msg);
260 transt->ss.msg = NULL;
261
262 transt->callref = 0;
263 transt->paging_request = NULL;
264 trans_free(transt);
265 break;
266 }
267
268 return 0;
269}
270
271static struct gsm_trans *establish_nc_ss_trans(struct gsm_network *net,
272 struct vlr_subscr *vsub, struct osmo_gsup_message *gsup_msg)
273{
Neels Hofmeyrc036b792018-11-29 22:37:51 +0100274 struct ran_conn *conn;
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700275 struct gsm_trans *trans, *transt;
276 int tid;
277
278 if (gsup_msg->session_state != OSMO_GSUP_SESSION_STATE_BEGIN) {
279 LOGP(DMM, LOGL_ERROR, "Received non-BEGIN message "
280 "for non-existing transaction\n");
281 return NULL;
282 }
283
284 if (!gsup_msg->ss_info || gsup_msg->ss_info_len < 2) {
285 LOGP(DMM, LOGL_ERROR, "Missing mandatory Facility IE\n");
286 return NULL;
287 }
288
289 /* If subscriber is not "attached" */
290 if (!vsub->lac) {
291 LOGP(DMM, LOGL_ERROR, "Network-originated session "
292 "rejected - subscriber is not attached\n");
293 return NULL;
294 }
295
296 DEBUGP(DMM, "Establishing network-originated session\n");
297
298 /* Allocate a new transaction */
299 trans = trans_alloc(net, vsub, GSM48_PDISC_NC_SS,
300 0xff, gsup_msg->session_id);
301 if (!trans) {
302 DEBUGP(DMM, " -> No memory for trans\n");
303 return NULL;
304 }
305
Vadim Yanitskiyad64e2a2018-06-26 18:27:25 +0700306 /* Count active NC SS/USSD sessions */
307 osmo_counter_inc(net->active_nc_ss);
308
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700309 /* Assign transaction ID */
310 tid = trans_assign_trans_id(trans->net,
311 trans->vsub, GSM48_PDISC_NC_SS, 0);
312 if (tid < 0) {
313 LOGP(DMM, LOGL_ERROR, "No free transaction ID\n");
314 /* TODO: inform HLR about this */
315 /* TODO: release connection with subscriber */
316 trans->callref = 0;
317 trans_free(trans);
318 return NULL;
319 }
320 trans->transaction_id = tid;
321
322 /* Attempt to find connection */
323 conn = connection_for_subscr(vsub);
324 if (conn) {
325 /* Assign connection */
Neels Hofmeyr3c20a5e2018-11-30 01:08:36 +0100326 trans->conn = ran_conn_get(conn, RAN_CONN_USE_TRANS_NC_SS);
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700327 trans->dlci = 0x00; /* SAPI=0, not SACCH */
328 return trans;
329 }
330
331 DEBUGP(DMM, "Triggering Paging Request\n");
332
333 /* Find transaction with this subscriber already paging */
334 llist_for_each_entry(transt, &net->trans_list, entry) {
335 /* Transaction of our conn? */
336 if (transt == trans || transt->vsub != vsub)
337 continue;
338
339 LOGP(DMM, LOGL_ERROR, "Paging already started, "
340 "rejecting message...\n");
341 trans_free(trans);
342 return NULL;
343 }
344
345 /* Trigger Paging Request */
346 trans->paging_request = subscr_request_conn(vsub,
347 &handle_paging_event, trans, "GSM 09.11 SS/USSD");
348 if (!trans->paging_request) {
349 LOGP(DMM, LOGL_ERROR, "Failed to allocate paging token\n");
350 trans_free(trans);
351 return NULL;
352 }
353
354 /* Store the Facility IE to be sent */
355 OSMO_ASSERT(trans->ss.msg == NULL);
356 trans->ss.msg = gsm48_msgb_alloc_name("GSM 04.08 SS/USSD");
357 msgb_tlv_put(trans->ss.msg, GSM0480_IE_FACILITY,
358 gsup_msg->ss_info_len, gsup_msg->ss_info);
359
360 return NULL;
361}
362
363/* NC SS specific transaction release.
364 * Gets called by trans_free, DO NOT CALL YOURSELF! */
365void _gsm911_nc_ss_trans_free(struct gsm_trans *trans)
366{
367 /**
368 * TODO: if transaction wasn't properly terminated,
369 * we need to do it here by releasing the subscriber
370 * connection and sending notification via GSUP...
371 */
372 if (trans->ss.msg != NULL)
373 msgb_free(trans->ss.msg);
Vadim Yanitskiyad64e2a2018-06-26 18:27:25 +0700374
375 /* One session less */
376 osmo_counter_dec(trans->net->active_nc_ss);
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700377}
378
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700379int gsm0911_gsup_handler(struct vlr_subscr *vsub,
380 struct osmo_gsup_message *gsup_msg)
381{
382 struct vlr_instance *vlr;
383 struct gsm_network *net;
384 struct gsm_trans *trans;
385 struct gsm48_hdr *gh;
386 struct msgb *ss_msg;
387 bool trans_end;
388
389 /* Associate logging messages with this subscriber */
390 log_set_context(LOG_CTX_VLR_SUBSCR, vsub);
391
392 /* Obtain pointer to vlr_instance */
393 vlr = vsub->vlr;
394 OSMO_ASSERT(vlr);
395
396 /* Obtain pointer to gsm_network */
397 net = (struct gsm_network *) vlr->user_ctx;
398 OSMO_ASSERT(net);
399
400 /* Handle errors */
401 if (OSMO_GSUP_IS_MSGT_ERROR(gsup_msg->message_type)) {
402 /* FIXME: handle this error somehow! */
Harald Welte6307b852009-10-16 08:41:51 +0200403 return 0;
Holger Hans Peter Freyther5085e0b2016-07-12 17:53:26 +0200404 }
Harald Welte6eafe912009-10-16 08:32:58 +0200405
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700406 /* Attempt to find DTAP-transaction */
407 trans = trans_find_by_callref(net, gsup_msg->session_id);
408 if (!trans) {
Vadim Yanitskiy8e25cc52018-06-23 03:32:20 +0700409 /* Count network-initiated attempts to establish a NC SS/USSD session */
410 rate_ctr_inc(&net->msc_ctrs->ctr[MSC_CTR_NC_SS_MT_REQUESTS]);
411
Vadim Yanitskiyf2f83b02018-06-17 21:09:28 +0700412 /* Attempt to establish a new transaction */
413 trans = establish_nc_ss_trans(net, vsub, gsup_msg);
414 if (!trans) {
415 /* FIXME: send ERROR back to the HLR */
416 return -EINVAL;
417 }
418
419 /* Wait for Paging Response */
420 if (trans->paging_request)
421 return 0;
Harald Welte6eafe912009-10-16 08:32:58 +0200422 }
Holger Hans Peter Freyther24866632010-06-30 12:15:19 +0800423
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700424 /* Allocate and prepare a new MT message */
425 ss_msg = gsm48_msgb_alloc_name("GSM 04.08 SS/USSD");
426 gh = (struct gsm48_hdr *) msgb_push(ss_msg, sizeof(*gh));
427 gh->proto_discr = GSM48_PDISC_NC_SS;
428 gh->proto_discr |= trans->transaction_id << 4;
Vadim Yanitskiy10c64192018-04-17 19:17:11 +0700429
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700430 /**
431 * Perform GSUP-interface to A-interface mapping,
432 * according to GSM TS 09.11, table 4.1.
433 *
434 * TODO: see (note 3), both CONTINUE and END may
435 * be also mapped to REGISTER if a new transaction
436 * has to be established.
437 */
438 switch (gsup_msg->session_state) {
439 case OSMO_GSUP_SESSION_STATE_BEGIN:
440 gh->msg_type = GSM0480_MTYPE_REGISTER;
441 break;
442 case OSMO_GSUP_SESSION_STATE_CONTINUE:
443 gh->msg_type = GSM0480_MTYPE_FACILITY;
444 break;
445 case OSMO_GSUP_SESSION_STATE_END:
446 gh->msg_type = GSM0480_MTYPE_RELEASE_COMPLETE;
447 break;
448
449 /* Missing or incorrect session state */
450 case OSMO_GSUP_SESSION_STATE_NONE:
451 default:
452 LOGP(DMM, LOGL_ERROR, "Unexpected session state %d\n",
453 gsup_msg->session_state);
454 /* FIXME: send ERROR back to the HLR */
455 msgb_free(ss_msg);
456 return -EINVAL;
457 }
458
459 /* Facility IE is optional only for RELEASE COMPLETE */
460 if (gh->msg_type != GSM0480_MTYPE_RELEASE_COMPLETE) {
461 if (!gsup_msg->ss_info || gsup_msg->ss_info_len < 2) {
462 LOGP(DMM, LOGL_ERROR, "Missing mandatory Facility IE "
463 "for mapped 0x%02x message\n", gh->msg_type);
464 /* FIXME: send ERROR back to the HLR */
465 msgb_free(ss_msg);
466 return -EINVAL;
467 }
468 }
469
470 /* Append Facility IE if preset */
471 if (gsup_msg->ss_info && gsup_msg->ss_info_len > 2) {
472 /* Facility IE carries LV, others carry TLV */
473 if (gh->msg_type == GSM0480_MTYPE_FACILITY)
474 msgb_lv_put(ss_msg, gsup_msg->ss_info_len, gsup_msg->ss_info);
475 else
476 msgb_tlv_put(ss_msg, GSM0480_IE_FACILITY,
477 gsup_msg->ss_info_len, gsup_msg->ss_info);
478 }
479
480 /* Should we release the transaction? */
481 trans_end = (gh->msg_type == GSM0480_MTYPE_RELEASE_COMPLETE);
482
483 /* Sent to the MS, give ownership of ss_msg */
484 msc_tx_dtap(trans->conn, ss_msg);
485
486 /* Release transaction if required */
487 if (trans_end)
488 trans_free(trans);
489
Vadim Yanitskiy8e25cc52018-06-23 03:32:20 +0700490 /* Count established network-initiated NC SS/USSD sessions */
491 if (gsup_msg->session_state == OSMO_GSUP_SESSION_STATE_BEGIN)
492 rate_ctr_inc(&net->msc_ctrs->ctr[MSC_CTR_NC_SS_MT_ESTABLISHED]);
493
Vadim Yanitskiy8a6ef552018-06-12 08:21:20 +0700494 return 0;
Harald Welte6eafe912009-10-16 08:32:58 +0200495}