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 | |
| 42 | static int msc_tx(struct gsm_subscriber_connection *conn, struct msgb *msg) |
| 43 | { |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 44 | if (!msg) |
| 45 | return -EINVAL; |
Philipp Maier | 4502f5f | 2017-09-07 11:39:58 +0200 | [diff] [blame] | 46 | if (!conn) { |
| 47 | msgb_free(msg); |
| 48 | return -EINVAL; |
| 49 | } |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 50 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 51 | 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 Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 54 | switch (conn->via_ran) { |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 55 | case RAN_GERAN_A: |
| 56 | msg->dst = conn; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 57 | return a_iface_tx_dtap(msg); |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 58 | |
| 59 | case RAN_UTRAN_IU: |
| 60 | msg->dst = conn->iu.ue_ctx; |
Neels Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 61 | return ranap_iu_tx(msg, 0); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 62 | |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 63 | default: |
| 64 | LOGP(DMSC, LOGL_ERROR, |
| 65 | "msc_tx(): conn->via_ran invalid (%d)\n", |
| 66 | conn->via_ran); |
Philipp Maier | 4502f5f | 2017-09-07 11:39:58 +0200 | [diff] [blame] | 67 | msgb_free(msg); |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 68 | return -1; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | |
| 73 | int 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 */ |
| 81 | int msc_gsm48_tx_mm_serv_ack(struct gsm_subscriber_connection *conn) |
| 82 | { |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 83 | struct msgb *msg; |
| 84 | struct gsm48_hdr *gh; |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 85 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 86 | 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 Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 92 | gh->proto_discr = GSM48_PDISC_MM; |
| 93 | gh->msg_type = GSM48_MT_MM_CM_SERV_ACC; |
| 94 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 95 | DEBUGP(DMM, "-> CM SERVICE ACCEPT %s\n", |
| 96 | vlr_subscr_name(conn->vsub)); |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 97 | |
| 98 | return msc_tx_dtap(conn, msg); |
| 99 | } |
| 100 | |
| 101 | /* 9.2.6 CM service reject */ |
| 102 | int msc_gsm48_tx_mm_serv_rej(struct gsm_subscriber_connection *conn, |
| 103 | enum gsm48_reject_value value) |
| 104 | { |
| 105 | struct msgb *msg; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 106 | |
| 107 | if (!conn) |
| 108 | return -EINVAL; |
| 109 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 110 | conn->received_cm_service_request = false; |
Neels Hofmeyr | e2f24d5 | 2017-05-08 15:12:20 +0200 | [diff] [blame] | 111 | |
| 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 Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 122 | |
| 123 | int msc_tx_common_id(struct gsm_subscriber_connection *conn) |
| 124 | { |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 125 | if (!conn) |
| 126 | return -EINVAL; |
| 127 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 128 | /* 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 Hofmeyr | 00e82d6 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 139 | 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] | 140 | } |