blob: 437d75c8e59db3d82706004ad9f8dc140e31070c [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
42static int msc_tx(struct gsm_subscriber_connection *conn, struct msgb *msg)
43{
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),
53 ran_type_name(conn->via_ran));
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020054 switch (conn->via_ran) {
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020055 case RAN_GERAN_A:
56 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
59 case RAN_UTRAN_IU:
60 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
73int msc_tx_dtap(struct gsm_subscriber_connection *conn,
74 struct msgb *msg)
75{
76 return msc_tx(conn, msg);
77}
78
79
80/* 9.2.5 CM service accept */
81int msc_gsm48_tx_mm_serv_ack(struct gsm_subscriber_connection *conn)
82{
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 */
102int msc_gsm48_tx_mm_serv_rej(struct gsm_subscriber_connection *conn,
103 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 Hofmeyr84da6b12016-05-20 21:59:55 +0200110 conn->received_cm_service_request = false;
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200111
112 msg = gsm48_create_mm_serv_rej(value);
113 if (!msg) {
114 LOGP(DMM, LOGL_ERROR, "Failed to allocate CM Service Reject.\n");
115 return -1;
116 }
117
118 DEBUGP(DMM, "-> CM SERVICE Reject cause: %d\n", value);
119
120 return msc_tx_dtap(conn, msg);
121}
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200122
123int msc_tx_common_id(struct gsm_subscriber_connection *conn)
124{
Philipp Maierfbf66102017-04-09 12:32:51 +0200125 if (!conn)
126 return -EINVAL;
127
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200128 /* Common ID is only sent over IuCS */
129 if (conn->via_ran != RAN_UTRAN_IU) {
130 LOGP(DMM, LOGL_INFO,
131 "%s: Asked to transmit Common ID, but skipping"
132 " because this is not on UTRAN\n",
133 vlr_subscr_name(conn->vsub));
134 return 0;
135 }
136
137 DEBUGP(DIUCS, "%s: tx CommonID %s\n",
138 vlr_subscr_name(conn->vsub), conn->vsub->imsi);
Neels Hofmeyr00e82d62017-07-05 15:19:52 +0200139 return ranap_iu_tx_common_id(conn->iu.ue_ctx, conn->vsub->imsi);
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200140}