blob: 3074d07a6dae8ccfb3f27fa1727ca39dc16f2822 [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>
Max43b01b02017-09-15 11:22:30 +020031#include <osmocom/msc/gsm_04_08.h>
Philipp Maier621ba032017-11-07 17:19:25 +010032#include <osmocom/msc/msc_mgcp.h>
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020033
34#include "../../bscconfig.h"
35
36#ifdef BUILD_IU
Neels Hofmeyr00e82d62017-07-05 15:19:52 +020037#include <osmocom/ranap/iu_client.h>
Neels Hofmeyr00e82d62017-07-05 15:19:52 +020038#else
Neels Hofmeyr90843962017-09-04 15:04:35 +020039#include <osmocom/msc/iu_dummy.h>
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020040#endif /* BUILD_IU */
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020041
Neels Hofmeyrc036b792018-11-29 22:37:51 +010042static int msc_tx(struct ran_conn *conn, struct msgb *msg)
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020043{
Philipp Maierfbf66102017-04-09 12:32:51 +020044 if (!msg)
45 return -EINVAL;
Philipp Maier4502f5f2017-09-07 11:39:58 +020046 if (!conn) {
47 msgb_free(msg);
48 return -EINVAL;
49 }
Philipp Maierfbf66102017-04-09 12:32:51 +020050
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020051 DEBUGP(DMSC, "msc_tx %u bytes to %s via %s\n",
52 msg->len, vlr_subscr_name(conn->vsub),
Neels Hofmeyr7814a832018-12-26 00:40:18 +010053 osmo_rat_type_name(conn->via_ran));
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020054 switch (conn->via_ran) {
Neels Hofmeyr7814a832018-12-26 00:40:18 +010055 case OSMO_RAT_GERAN_A:
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020056 msg->dst = conn;
Philipp Maierfbf66102017-04-09 12:32:51 +020057 return a_iface_tx_dtap(msg);
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020058
Neels Hofmeyr7814a832018-12-26 00:40:18 +010059 case OSMO_RAT_UTRAN_IU:
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020060 msg->dst = conn->iu.ue_ctx;
Neels Hofmeyr00e82d62017-07-05 15:19:52 +020061 return ranap_iu_tx(msg, 0);
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020062
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020063 default:
64 LOGP(DMSC, LOGL_ERROR,
65 "msc_tx(): conn->via_ran invalid (%d)\n",
66 conn->via_ran);
Philipp Maier4502f5f2017-09-07 11:39:58 +020067 msgb_free(msg);
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020068 return -1;
69 }
70}
71
72
Neels Hofmeyrc036b792018-11-29 22:37:51 +010073int msc_tx_dtap(struct ran_conn *conn,
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020074 struct msgb *msg)
75{
76 return msc_tx(conn, msg);
77}
78
79
80/* 9.2.5 CM service accept */
Neels Hofmeyrc036b792018-11-29 22:37:51 +010081int msc_gsm48_tx_mm_serv_ack(struct ran_conn *conn)
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020082{
Philipp Maierfbf66102017-04-09 12:32:51 +020083 struct msgb *msg;
84 struct gsm48_hdr *gh;
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020085
Philipp Maierfbf66102017-04-09 12:32:51 +020086 if (!conn)
87 return -EINVAL;
88
89 msg = gsm48_msgb_alloc_name("GSM 04.08 SERV ACC");
90
91 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020092 gh->proto_discr = GSM48_PDISC_MM;
93 gh->msg_type = GSM48_MT_MM_CM_SERV_ACC;
94
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020095 DEBUGP(DMM, "-> CM SERVICE ACCEPT %s\n",
96 vlr_subscr_name(conn->vsub));
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020097
98 return msc_tx_dtap(conn, msg);
99}
100
101/* 9.2.6 CM service reject */
Neels Hofmeyrc036b792018-11-29 22:37:51 +0100102int msc_gsm48_tx_mm_serv_rej(struct ran_conn *conn,
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200103 enum gsm48_reject_value value)
104{
105 struct msgb *msg;
Philipp Maierfbf66102017-04-09 12:32:51 +0200106
107 if (!conn)
108 return -EINVAL;
109
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200110 msg = gsm48_create_mm_serv_rej(value);
111 if (!msg) {
112 LOGP(DMM, LOGL_ERROR, "Failed to allocate CM Service Reject.\n");
113 return -1;
114 }
115
116 DEBUGP(DMM, "-> CM SERVICE Reject cause: %d\n", value);
117
118 return msc_tx_dtap(conn, msg);
119}
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200120
Neels Hofmeyrc036b792018-11-29 22:37:51 +0100121int msc_tx_common_id(struct ran_conn *conn)
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200122{
Philipp Maierfbf66102017-04-09 12:32:51 +0200123 if (!conn)
124 return -EINVAL;
125
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200126 /* Common ID is only sent over IuCS */
Neels Hofmeyr7814a832018-12-26 00:40:18 +0100127 if (conn->via_ran != OSMO_RAT_UTRAN_IU) {
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200128 LOGP(DMM, LOGL_INFO,
129 "%s: Asked to transmit Common ID, but skipping"
130 " because this is not on UTRAN\n",
131 vlr_subscr_name(conn->vsub));
132 return 0;
133 }
134
135 DEBUGP(DIUCS, "%s: tx CommonID %s\n",
136 vlr_subscr_name(conn->vsub), conn->vsub->imsi);
Neels Hofmeyr00e82d62017-07-05 15:19:52 +0200137 return ranap_iu_tx_common_id(conn->iu.ue_ctx, conn->vsub->imsi);
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200138}