Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 1 | /* 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 Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 23 | #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 Hofmeyr | 6c8afe1 | 2017-09-04 01:03:58 +0200 | [diff] [blame] | 28 | #include <osmocom/mgcp_client/mgcp_client.h> |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 29 | #include <osmocom/msc/vlr.h> |
| 30 | #include <osmocom/msc/a_iface.h> |
Max | 43b01b0 | 2017-09-15 11:22:30 +0200 | [diff] [blame] | 31 | #include <osmocom/msc/gsm_04_08.h> |
Philipp Maier | 621ba03 | 2017-11-07 17:19:25 +0100 | [diff] [blame] | 32 | #include <osmocom/msc/msc_mgcp.h> |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 33 | |
| 34 | #include "../../bscconfig.h" |
| 35 | |
| 36 | #ifdef BUILD_IU |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 37 | #include <osmocom/ranap/iu_client.h> |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 38 | #else |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 39 | #include <osmocom/msc/iu_dummy.h> |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 40 | #endif /* BUILD_IU */ |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 41 | |
Neels Hofmeyr | 9d74425 | 2018-03-22 16:09:50 +0100 | [diff] [blame] | 42 | const 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 Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 49 | static int msc_tx(struct ran_conn *conn, struct msgb *msg) |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 50 | { |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 51 | if (!msg) |
| 52 | return -EINVAL; |
Philipp Maier | 4502f5f | 2017-09-07 11:39:58 +0200 | [diff] [blame] | 53 | if (!conn) { |
| 54 | msgb_free(msg); |
| 55 | return -EINVAL; |
| 56 | } |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 57 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 58 | 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 Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 61 | switch (conn->via_ran) { |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 62 | case RAN_GERAN_A: |
| 63 | msg->dst = conn; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 64 | return a_iface_tx_dtap(msg); |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 65 | |
| 66 | case RAN_UTRAN_IU: |
| 67 | msg->dst = conn->iu.ue_ctx; |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 68 | return ranap_iu_tx(msg, 0); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 69 | |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 70 | default: |
| 71 | LOGP(DMSC, LOGL_ERROR, |
| 72 | "msc_tx(): conn->via_ran invalid (%d)\n", |
| 73 | conn->via_ran); |
Philipp Maier | 4502f5f | 2017-09-07 11:39:58 +0200 | [diff] [blame] | 74 | msgb_free(msg); |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 75 | return -1; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 80 | int msc_tx_dtap(struct ran_conn *conn, |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 81 | struct msgb *msg) |
| 82 | { |
| 83 | return msc_tx(conn, msg); |
| 84 | } |
| 85 | |
| 86 | |
| 87 | /* 9.2.5 CM service accept */ |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 88 | int msc_gsm48_tx_mm_serv_ack(struct ran_conn *conn) |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 89 | { |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 90 | struct msgb *msg; |
| 91 | struct gsm48_hdr *gh; |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 92 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 93 | 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 Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 99 | gh->proto_discr = GSM48_PDISC_MM; |
| 100 | gh->msg_type = GSM48_MT_MM_CM_SERV_ACC; |
| 101 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 102 | DEBUGP(DMM, "-> CM SERVICE ACCEPT %s\n", |
| 103 | vlr_subscr_name(conn->vsub)); |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 104 | |
| 105 | return msc_tx_dtap(conn, msg); |
| 106 | } |
| 107 | |
| 108 | /* 9.2.6 CM service reject */ |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 109 | int msc_gsm48_tx_mm_serv_rej(struct ran_conn *conn, |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 110 | enum gsm48_reject_value value) |
| 111 | { |
| 112 | struct msgb *msg; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 113 | |
| 114 | if (!conn) |
| 115 | return -EINVAL; |
| 116 | |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 117 | 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 Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 127 | |
Neels Hofmeyr | c036b79 | 2018-11-29 22:37:51 +0100 | [diff] [blame] | 128 | int msc_tx_common_id(struct ran_conn *conn) |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 129 | { |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 130 | if (!conn) |
| 131 | return -EINVAL; |
| 132 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 133 | /* 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 Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 144 | return ranap_iu_tx_common_id(conn->iu.ue_ctx, conn->vsub->imsi); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 145 | } |