blob: 8ae34fcdd1fc4ed07f29e710b7a8407c686a25d3 [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 Hofmeyr9d744252018-03-22 16:09:50 +010042const struct value_string ran_type_names[] = {
43 OSMO_VALUE_STRING(RAN_UNKNOWN),
44 OSMO_VALUE_STRING(RAN_GERAN_A),
45 OSMO_VALUE_STRING(RAN_UTRAN_IU),
46 { 0, NULL }
47};
48
Neels Hofmeyrc036b792018-11-29 22:37:51 +010049static int msc_tx(struct ran_conn *conn, struct msgb *msg)
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020050{
Philipp Maierfbf66102017-04-09 12:32:51 +020051 if (!msg)
52 return -EINVAL;
Philipp Maier4502f5f2017-09-07 11:39:58 +020053 if (!conn) {
54 msgb_free(msg);
55 return -EINVAL;
56 }
Philipp Maierfbf66102017-04-09 12:32:51 +020057
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020058 DEBUGP(DMSC, "msc_tx %u bytes to %s via %s\n",
59 msg->len, vlr_subscr_name(conn->vsub),
60 ran_type_name(conn->via_ran));
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020061 switch (conn->via_ran) {
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020062 case RAN_GERAN_A:
63 msg->dst = conn;
Philipp Maierfbf66102017-04-09 12:32:51 +020064 return a_iface_tx_dtap(msg);
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020065
66 case RAN_UTRAN_IU:
67 msg->dst = conn->iu.ue_ctx;
Neels Hofmeyr00e82d62017-07-05 15:19:52 +020068 return ranap_iu_tx(msg, 0);
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020069
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020070 default:
71 LOGP(DMSC, LOGL_ERROR,
72 "msc_tx(): conn->via_ran invalid (%d)\n",
73 conn->via_ran);
Philipp Maier4502f5f2017-09-07 11:39:58 +020074 msgb_free(msg);
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020075 return -1;
76 }
77}
78
79
Neels Hofmeyrc036b792018-11-29 22:37:51 +010080int msc_tx_dtap(struct ran_conn *conn,
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020081 struct msgb *msg)
82{
83 return msc_tx(conn, msg);
84}
85
86
87/* 9.2.5 CM service accept */
Neels Hofmeyrc036b792018-11-29 22:37:51 +010088int msc_gsm48_tx_mm_serv_ack(struct ran_conn *conn)
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020089{
Philipp Maierfbf66102017-04-09 12:32:51 +020090 struct msgb *msg;
91 struct gsm48_hdr *gh;
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020092
Philipp Maierfbf66102017-04-09 12:32:51 +020093 if (!conn)
94 return -EINVAL;
95
96 msg = gsm48_msgb_alloc_name("GSM 04.08 SERV ACC");
97
98 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020099 gh->proto_discr = GSM48_PDISC_MM;
100 gh->msg_type = GSM48_MT_MM_CM_SERV_ACC;
101
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200102 DEBUGP(DMM, "-> CM SERVICE ACCEPT %s\n",
103 vlr_subscr_name(conn->vsub));
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200104
105 return msc_tx_dtap(conn, msg);
106}
107
108/* 9.2.6 CM service reject */
Neels Hofmeyrc036b792018-11-29 22:37:51 +0100109int msc_gsm48_tx_mm_serv_rej(struct ran_conn *conn,
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200110 enum gsm48_reject_value value)
111{
112 struct msgb *msg;
Philipp Maierfbf66102017-04-09 12:32:51 +0200113
114 if (!conn)
115 return -EINVAL;
116
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200117 msg = gsm48_create_mm_serv_rej(value);
118 if (!msg) {
119 LOGP(DMM, LOGL_ERROR, "Failed to allocate CM Service Reject.\n");
120 return -1;
121 }
122
123 DEBUGP(DMM, "-> CM SERVICE Reject cause: %d\n", value);
124
125 return msc_tx_dtap(conn, msg);
126}
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200127
Neels Hofmeyrc036b792018-11-29 22:37:51 +0100128int msc_tx_common_id(struct ran_conn *conn)
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200129{
Philipp Maierfbf66102017-04-09 12:32:51 +0200130 if (!conn)
131 return -EINVAL;
132
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200133 /* Common ID is only sent over IuCS */
134 if (conn->via_ran != RAN_UTRAN_IU) {
135 LOGP(DMM, LOGL_INFO,
136 "%s: Asked to transmit Common ID, but skipping"
137 " because this is not on UTRAN\n",
138 vlr_subscr_name(conn->vsub));
139 return 0;
140 }
141
142 DEBUGP(DIUCS, "%s: tx CommonID %s\n",
143 vlr_subscr_name(conn->vsub), conn->vsub->imsi);
Neels Hofmeyr00e82d62017-07-05 15:19:52 +0200144 return ranap_iu_tx_common_id(conn->iu.ue_ctx, conn->vsub->imsi);
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200145}