blob: e2c52dfda09d893f59e940e4acc488cc6a7aece2 [file] [log] [blame]
Neels Hofmeyre2f24d52017-05-08 15:12:20 +02001/* Implementation for MSC decisions which interface to send messages out on. */
2
3/* (C) 2016 by sysmocom s.m.f.c GmbH <info@sysmocom.de>
4 *
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <osmocom/core/logging.h>
22
Neels Hofmeyr90843962017-09-04 15:04:35 +020023#include <osmocom/msc/debug.h>
24#include <osmocom/msc/gsm_data.h>
25#include <osmocom/msc/msc_ifaces.h>
26#include <osmocom/msc/gsm_subscriber.h>
27#include <osmocom/msc/transaction.h>
Neels Hofmeyr6c8afe12017-09-04 01:03:58 +020028#include <osmocom/mgcp_client/mgcp_client.h>
Neels Hofmeyr90843962017-09-04 15:04:35 +020029#include <osmocom/msc/vlr.h>
30#include <osmocom/msc/a_iface.h>
Harald Welte0df904d2018-12-03 11:00:04 +010031#include <osmocom/msc/sgs_iface.h>
Max43b01b02017-09-15 11:22:30 +020032#include <osmocom/msc/gsm_04_08.h>
Philipp Maier621ba032017-11-07 17:19:25 +010033#include <osmocom/msc/msc_mgcp.h>
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020034
35#include "../../bscconfig.h"
36
37#ifdef BUILD_IU
Neels Hofmeyr00e82d62017-07-05 15:19:52 +020038#include <osmocom/ranap/iu_client.h>
Neels Hofmeyr00e82d62017-07-05 15:19:52 +020039#else
Neels Hofmeyr90843962017-09-04 15:04:35 +020040#include <osmocom/msc/iu_dummy.h>
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020041#endif /* BUILD_IU */
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020042
Neels Hofmeyrc036b792018-11-29 22:37:51 +010043static int msc_tx(struct ran_conn *conn, struct msgb *msg)
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020044{
Philipp Maierfbf66102017-04-09 12:32:51 +020045 if (!msg)
46 return -EINVAL;
Philipp Maier4502f5f2017-09-07 11:39:58 +020047 if (!conn) {
48 msgb_free(msg);
49 return -EINVAL;
50 }
Philipp Maierfbf66102017-04-09 12:32:51 +020051
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020052 DEBUGP(DMSC, "msc_tx %u bytes to %s via %s\n",
53 msg->len, vlr_subscr_name(conn->vsub),
Neels Hofmeyr7814a832018-12-26 00:40:18 +010054 osmo_rat_type_name(conn->via_ran));
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020055 switch (conn->via_ran) {
Neels Hofmeyr7814a832018-12-26 00:40:18 +010056 case OSMO_RAT_GERAN_A:
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020057 msg->dst = conn;
Philipp Maierfbf66102017-04-09 12:32:51 +020058 return a_iface_tx_dtap(msg);
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020059
Neels Hofmeyr7814a832018-12-26 00:40:18 +010060 case OSMO_RAT_UTRAN_IU:
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020061 msg->dst = conn->iu.ue_ctx;
Neels Hofmeyr00e82d62017-07-05 15:19:52 +020062 return ranap_iu_tx(msg, 0);
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020063
Harald Welte0df904d2018-12-03 11:00:04 +010064 case OSMO_RAT_EUTRAN_SGS:
65 msg->dst = conn;
66 return sgs_iface_tx_dtap_ud(msg);
67
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020068 default:
69 LOGP(DMSC, LOGL_ERROR,
70 "msc_tx(): conn->via_ran invalid (%d)\n",
71 conn->via_ran);
Philipp Maier4502f5f2017-09-07 11:39:58 +020072 msgb_free(msg);
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020073 return -1;
74 }
75}
76
77
Neels Hofmeyrc036b792018-11-29 22:37:51 +010078int msc_tx_dtap(struct ran_conn *conn,
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020079 struct msgb *msg)
80{
81 return msc_tx(conn, msg);
82}
83
84
85/* 9.2.5 CM service accept */
Neels Hofmeyrc036b792018-11-29 22:37:51 +010086int msc_gsm48_tx_mm_serv_ack(struct ran_conn *conn)
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020087{
Philipp Maierfbf66102017-04-09 12:32:51 +020088 struct msgb *msg;
89 struct gsm48_hdr *gh;
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020090
Philipp Maierfbf66102017-04-09 12:32:51 +020091 if (!conn)
92 return -EINVAL;
93
94 msg = gsm48_msgb_alloc_name("GSM 04.08 SERV ACC");
95
96 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020097 gh->proto_discr = GSM48_PDISC_MM;
98 gh->msg_type = GSM48_MT_MM_CM_SERV_ACC;
99
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200100 DEBUGP(DMM, "-> CM SERVICE ACCEPT %s\n",
101 vlr_subscr_name(conn->vsub));
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200102
103 return msc_tx_dtap(conn, msg);
104}
105
106/* 9.2.6 CM service reject */
Neels Hofmeyrc036b792018-11-29 22:37:51 +0100107int msc_gsm48_tx_mm_serv_rej(struct ran_conn *conn,
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200108 enum gsm48_reject_value value)
109{
110 struct msgb *msg;
Philipp Maierfbf66102017-04-09 12:32:51 +0200111
112 if (!conn)
113 return -EINVAL;
114
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200115 msg = gsm48_create_mm_serv_rej(value);
116 if (!msg) {
117 LOGP(DMM, LOGL_ERROR, "Failed to allocate CM Service Reject.\n");
118 return -1;
119 }
120
121 DEBUGP(DMM, "-> CM SERVICE Reject cause: %d\n", value);
122
123 return msc_tx_dtap(conn, msg);
124}
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200125
Neels Hofmeyrc036b792018-11-29 22:37:51 +0100126int msc_tx_common_id(struct ran_conn *conn)
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200127{
Philipp Maierfbf66102017-04-09 12:32:51 +0200128 if (!conn)
129 return -EINVAL;
130
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200131 /* Common ID is only sent over IuCS */
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100132 if (conn->via_ran != OSMO_RAT_UTRAN_IU) {
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200133 LOGP(DMM, LOGL_INFO,
134 "%s: Asked to transmit Common ID, but skipping"
135 " because this is not on UTRAN\n",
136 vlr_subscr_name(conn->vsub));
137 return 0;
138 }
139
140 DEBUGP(DIUCS, "%s: tx CommonID %s\n",
141 vlr_subscr_name(conn->vsub), conn->vsub->imsi);
Neels Hofmeyr00e82d62017-07-05 15:19:52 +0200142 return ranap_iu_tx_common_id(conn->iu.ue_ctx, conn->vsub->imsi);
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200143}